diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tests/integration/CMakeLists.txt | 31 | ||||
-rw-r--r-- | tests/integration/usb-manager-test.cpp | 241 | ||||
-rw-r--r-- | tests/unit/CMakeLists.txt | 40 | ||||
-rw-r--r-- | tests/unit/adbd-client-test.cpp | 96 | ||||
-rw-r--r-- | tests/unit/greeter-test.cpp | 159 | ||||
-rw-r--r-- | tests/unit/rotation-lock-test.cpp | 6 | ||||
-rw-r--r-- | tests/unit/usb-snap-test.cpp | 138 | ||||
-rw-r--r-- | tests/utils/CMakeLists.txt | 16 | ||||
-rw-r--r-- | tests/utils/adbd-server.h | 148 | ||||
-rw-r--r-- | tests/utils/dbus-types.h | 42 | ||||
-rw-r--r-- | tests/utils/glib-fixture.h | 2 | ||||
-rw-r--r-- | tests/utils/gtest-print-helpers.h | 18 | ||||
-rw-r--r-- | tests/utils/gtest-qt-print-helpers.h | 45 | ||||
-rw-r--r-- | tests/utils/mock-greeter.h | 32 | ||||
-rw-r--r-- | tests/utils/mock-greeter.py | 41 | ||||
-rw-r--r-- | tests/utils/mock-usb-monitor.h | 32 | ||||
-rw-r--r-- | tests/utils/qmain.cpp | 60 | ||||
-rw-r--r-- | tests/utils/qt-fixture.h | 74 | ||||
-rw-r--r-- | tests/utils/test-dbus-fixture.h | 2 |
20 files changed, 18 insertions, 1212 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4c1b9b8..bdc074f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,7 +1,6 @@ set(CMAKE_AUTOMOC ON) find_package(GMock REQUIRED) -find_package(Qt5Core REQUIRED) find_package(Qt5Test REQUIRED) find_package(Qt5DBus COMPONENTS Qt5DBusMacros REQUIRED) @@ -29,11 +28,9 @@ endif() add_compile_options(${CXX_WARNING_ARGS}) -add_test(cppcheck cppcheck --enable=all -USCHEMA_DIR --error-exitcode=2 --inline-suppr --library=qt -I${CMAKE_SOURCE_DIR} -i${CMAKE_SOURCE_DIR}/tests/utils/qmain.cpp -i${CMAKE_SOURCE_DIR}/tests/gmock ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/tests --suppress=missingIncludeSystem --suppress=uninitDerivedMemberVar --suppress=unmatchedSuppression --suppress=constParameter) +add_test(cppcheck cppcheck --enable=all -USCHEMA_DIR --check-level=exhaustive --error-exitcode=2 --inline-suppr --library=qt -I${CMAKE_SOURCE_DIR} -i${CMAKE_SOURCE_DIR}/tests/utils/qmain.cpp -i${CMAKE_SOURCE_DIR}/tests/gmock ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/tests --suppress=missingIncludeSystem --suppress=uninitDerivedMemberVar --suppress=unmatchedSuppression --suppress=constParameter --suppress=constParameterCallback --suppress=unusedFunction --suppress=uselessOverride) -add_subdirectory(integration) -add_subdirectory(unit) -add_subdirectory(utils) +add_subdirectory (unit) set(COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} diff --git a/tests/integration/CMakeLists.txt b/tests/integration/CMakeLists.txt deleted file mode 100644 index 9fea07d..0000000 --- a/tests/integration/CMakeLists.txt +++ /dev/null @@ -1,31 +0,0 @@ -set(SERVICE_LINK_LIBRARIES - ${SERVICE_LIB} - ${SERVICE_DEPS_LIBRARIES} -) -set(QT_LINK_LIBRARIES - test-utils - Qt5::Core - Qt5::Test - Qt5::DBus -) -set(TEST_LINK_LIBRARIES - ${TEST_DEPS_LIBRARIES} - ${GTEST_LIBRARIES} - ${GMOCK_LIBRARIES} -) - -function(add_qt_test_by_name name) - set(TEST_NAME ${name}) - set(COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} ${TEST_NAME} PARENT_SCOPE) - add_executable (${TEST_NAME} ${TEST_NAME}.cpp) - target_link_options(${TEST_NAME} PRIVATE -no-pie) - add_test(${TEST_NAME} ${TEST_NAME}) - set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT ${CTEST_ENVIRONMENT}) - target_link_libraries(${TEST_NAME} ${SERVICE_LINK_LIBRARIES} ${QT_LINK_LIBRARIES} ${TEST_LINK_LIBRARIES} ${THREAD_LINK_LIBRARIES}) -endfunction() -add_qt_test_by_name(usb-manager-test) - -set(COVERAGE_TEST_TARGETS - ${COVERAGE_TEST_TARGETS} - PARENT_SCOPE -) diff --git a/tests/integration/usb-manager-test.cpp b/tests/integration/usb-manager-test.cpp deleted file mode 100644 index c17e587..0000000 --- a/tests/integration/usb-manager-test.cpp +++ /dev/null @@ -1,241 +0,0 @@ -/* - * Copyright 2016 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Charles Kerr <charles.kerr@canonical.com> - */ - -#include <tests/utils/adbd-server.h> -#include <tests/utils/qt-fixture.h> -#include <tests/utils/mock-greeter.h> -#include <tests/utils/mock-usb-monitor.h> - -#include <src/dbus-names.h> -#include <src/usb-manager.h> - -#include <libqtdbustest/DBusTestRunner.h> -#include <libqtdbustest/QProcessDBusService.h> -#include <libqtdbusmock/DBusMock.h> - -#include <fstream> -#include <sstream> -#include <vector> - -/*** -**** -***/ - -class UsbManagerFixture: public QtFixture -{ - using super = QtFixture; - -public: - - UsbManagerFixture(): - dbusMock{dbusTestRunner} - { - dbusTestRunner.startServices(); - } - - ~UsbManagerFixture() =default; - -protected: - - static void file_deleter (std::string* s) - { - fprintf(stderr, "remove \"%s\"\n", s->c_str()); - g_remove(s->c_str()); - delete s; - } - - void SetUp() override - { - super::SetUp(); - - m_usb_monitor.reset(new MockUsbMonitor{}); - m_greeter.reset(new MockGreeter{}); - - char tmpl[] = {"usb-manager-test-XXXXXX"}; - m_tmpdir.reset(new std::string{g_mkdtemp(tmpl)}, file_deleter); - g_message("using tmpdir '%s'", m_tmpdir->c_str()); - - dbusMock.registerNotificationDaemon(); - dbusTestRunner.startServices(); - } - - OrgFreedesktopDBusMockInterface& notificationsMockInterface() - { - return dbusMock.mockInterface(DBusNames::Notify::NAME, - DBusNames::Notify::PATH, - DBusNames::Notify::INTERFACE, - QDBusConnection::SessionBus); - } - - QtDBusTest::DBusTestRunner dbusTestRunner; - QtDBusMock::DBusMock dbusMock; - std::shared_ptr<std::string> m_tmpdir; - std::shared_ptr<MockUsbMonitor> m_usb_monitor; - std::shared_ptr<MockGreeter> m_greeter; -}; - -TEST_F(UsbManagerFixture, Allow) -{ - const std::shared_ptr<std::string> socket_path {new std::string{*m_tmpdir+"/socket"}, file_deleter}; - const std::shared_ptr<std::string> public_keys_path {new std::string{*m_tmpdir+"/adb_keys"}, file_deleter}; - - // add a signal spy to listen to the notification daemon - QSignalSpy notificationsSpy( - ¬ificationsMockInterface(), - SIGNAL(MethodCalled(const QString &, const QVariantList &)) - ); - - // start a mock AdbdServer ready to submit a request - const std::string public_key {"qAAAALUHllFjEZjl5jbS9ivjpQpaTNpibl28Re71D/S8sV3usNJTkbpvZYoVPfxtmHSNdCgLkWN6qcDZsHZqE/4myzmx/8Y/RqBy1oirudugi3YUUcJh7aWkY8lKQe9shCLTcrT7cFLZIJIidTvfmWTm0UcU+xmdPALze11I3lGo1Ty5KpCe9oP+qYM8suHbxhm78LKLlo0QJ2QqM8T5isr1pvoPHDgRb+mSESElG+xDIfPWA2BTu77/xk4EnXmOYfcuCr5akF3N4fRo/ACnYgXWDZFX2XdklBXyDj78lVlinF37xdMk7BMQh166X7UNkpH1uG2y5F6lUzyLg8SsFtRnJkw7eVe/gnJj3feQaFQbF5oVDhWhLMtWLtejhX6umvroVBVA4rynG4xEgs00K4u4ly8DUIIJYDO22Ml4myFR5CUm3lOlyitNdzYGh0utLXPq9oc8EbMVxM3i+O7PRxQw5Ul04X6K8GLiGUDV98DB+xYUqfEveq1BRnXi/ZrdPDhQ8Lfkg5xnLccPTFamAqutPtZXV6s7dXJInBTZf0NtBaWL0RdR2cOJBrpeBYkrc9yIyeqFLFdxr66rjaehjaa4pS4S+CD6PkGiIpPWSQtwNC4RlT10qTQ0/K9lRux2p0D8Z8ubUTFuh4kBScGUkN1OV3Z+7d7B+ghmBtZrrgleXsbehjRuKgEAAQA= foo@bar"}; - const std::string fingerprint {"12:23:5f:2d:8c:40:ae:1d:05:7b:ae:bd:88:8a:f0:80"}; - - auto adbd_server = std::make_shared<GAdbdServer>(*socket_path, std::vector<std::string>{"PK"+public_key}); - - // set up a UsbManager to process the request - auto usb_manager = std::make_shared<UsbManager>(*socket_path, *public_keys_path, m_usb_monitor, m_greeter); - // cppcheck in Ubuntu 20.04 requires the unused attribute to be set here... - Q_UNUSED(usb_manager); - - // wait for the notification to show up, confirm it looks right - wait_for_signals(notificationsSpy, 1); - { - QVariantList const& call(notificationsSpy.at(0)); - EXPECT_EQ("Notify", call.at(0)); - - QVariantList const& args(call.at(1).toList()); - ASSERT_EQ(8, args.size()); - EXPECT_EQ("", args.at(0)); // app name - EXPECT_EQ(0, args.at(1)); // replaces-id - EXPECT_EQ("computer-symbolic", args.at(2)); // icon name - EXPECT_EQ("Allow USB Debugging?", args.at(3)); // summary - EXPECT_EQ(QString::fromUtf8("The computer's RSA key fingerprint is: ") + QString::fromUtf8(fingerprint.c_str()), args.at(4)); // body - EXPECT_EQ(QStringList({"allow", "Allow", "deny", "Don't Allow"}), args.at(5)); // actions - EXPECT_EQ(-1, args.at(7)); - - QVariantMap hints; - ASSERT_TRUE(qDBusArgumentToMap(args.at(6), hints)); - ASSERT_EQ(3, hints.size()); - ASSERT_TRUE(hints.contains("x-canonical-private-affirmative-tint")); - ASSERT_TRUE(hints.contains("x-canonical-non-shaped-icon")); - ASSERT_TRUE(hints.contains("x-canonical-snap-decisions")); - } - notificationsSpy.clear(); - - // click on allow in the notification - notificationsMockInterface().EmitSignal( - DBusNames::Notify::INTERFACE, - DBusNames::Notify::ActionInvoked::NAME, - "us", - QVariantList() << uint32_t(1) << "allow" - ); - - // confirm that the AdbdServer got the right response - wait_for([adbd_server](){return !adbd_server->m_responses.empty();}, 5000); - ASSERT_EQ(1, adbd_server->m_responses.size()); - EXPECT_EQ("OK", adbd_server->m_responses.front()); - - // confirm that the public_keys file got the public key appended to it - std::ifstream ifkeys {*public_keys_path}; - std::vector<std::string> lines; - std::string line; - while(getline(ifkeys, line)) - lines.emplace_back(std::move(line)); - ASSERT_EQ(1, lines.size()); - EXPECT_EQ(public_key, lines[0]); -} - -TEST_F(UsbManagerFixture, USBDisconnectedDuringPrompt) -{ - const std::shared_ptr<std::string> socket_path {new std::string{*m_tmpdir+"/socket"}, file_deleter}; - const std::shared_ptr<std::string> public_keys_path {new std::string{*m_tmpdir+"/adb_keys"}, file_deleter}; - - // start a mock AdbdServer ready to submit a request - const size_t N_TESTS {3}; - const std::string public_key {"public_key"}; - const std::vector<std::string> requests(N_TESTS, "PK"+public_key); - const std::vector<std::string> expected_responses(N_TESTS, "NO"); - auto adbd_server = std::make_shared<GAdbdServer>(*socket_path, requests); - - // set up a UsbManager to process the request - auto usb_manager = std::make_shared<UsbManager>(*socket_path, *public_keys_path, m_usb_monitor, m_greeter); - // cppcheck in Ubuntu 20.04 requires the unused attribute to be set here... - Q_UNUSED(usb_manager); - - for (std::remove_const<decltype(N_TESTS)>::type i=0; i<N_TESTS; ++i) - { - // add a signal spy to listen to the notification daemon - QSignalSpy notificationsSpy( - ¬ificationsMockInterface(), - SIGNAL(MethodCalled(const QString &, const QVariantList &)) - ); - - // wait for a notification to show up - wait_for_signals(notificationsSpy, 1); - EXPECT_EQ("Notify", notificationsSpy.at(0).at(0)); - notificationsSpy.clear(); - - // wait for UsbSnap to receive dbusmock's response to the Notify request. - // there's no event to key off of for this, so just wait for a moment - wait_msec(); - - // disconnect the USB before the user has a chance to allow/deny - m_usb_monitor->m_on_usb_disconnected("android0"); - - // confirm that we requested the notification to be pulled down - wait_for_signals(notificationsSpy, 1); - EXPECT_EQ("CloseNotification", notificationsSpy.at(0).at(0)); - notificationsSpy.clear(); - } - - EXPECT_TRUE(wait_for([adbd_server, N_TESTS](){return adbd_server->m_responses.size() == N_TESTS;}, 5000)); - EXPECT_EQ(expected_responses, adbd_server->m_responses); -} - -TEST_F(UsbManagerFixture, Greeter) -{ - const std::shared_ptr<std::string> socket_path {new std::string{*m_tmpdir+"/socket"}, file_deleter}; - const std::shared_ptr<std::string> public_keys_path {new std::string{*m_tmpdir+"/adb_keys"}, file_deleter}; - - // start a mock AdbdServer ready to submit a request - const std::string public_key {"public_key"}; - auto adbd_server = std::make_shared<GAdbdServer>(*socket_path, std::vector<std::string>{"PK"+public_key}); - // cppcheck in Ubuntu 20.04 requires the unused attribute to be set here... - Q_UNUSED(adbd_server); - - // set up a UsbManager to process the request - m_greeter->m_state.set(Greeter::State::ACTIVE); - auto usb_manager = std::make_shared<UsbManager>(*socket_path, *public_keys_path, m_usb_monitor, m_greeter); - // cppcheck in Ubuntu 20.04 requires the unused attribute to be set here... - Q_UNUSED(usb_manager); - - // add a signal spy to listen to the notification daemon - QSignalSpy notificationsSpy( - ¬ificationsMockInterface(), - SIGNAL(MethodCalled(const QString &, const QVariantList &)) - ); - - // the greeter is active, so the notification should not appear - EXPECT_FALSE(notificationsSpy.wait(2000)); - - // disable the greeter, the notification should appear - m_greeter->m_state.set(Greeter::State::INACTIVE); - wait_for_signals(notificationsSpy, 1); - EXPECT_EQ("Notify", notificationsSpy.at(0).at(0)); - notificationsSpy.clear(); -} diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 01592f3..d24aa70 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -12,64 +12,46 @@ set_source_files_properties (gschemas.compiled GENERATED) # and help the tests to find that file by setting -DSCHEMA_DIR set (XDG_DATA_DIRS "${CMAKE_CURRENT_BINARY_DIR}/gsettings-schemas") set (SCHEMA_DIR "${XDG_DATA_DIRS}/glib-2.0/schemas") -if (EXISTS /usr/share/glib-2.0/schemas/com.ubuntu.touch.system.gschema.xml) - set (DISPLAY_SCHEMA /usr/share/glib-2.0/schemas/com.ubuntu.touch.system.gschema.xml) -else() - set (DISPLAY_SCHEMA ${CMAKE_SOURCE_DIR}/data/org.ayatana.display.gschema.xml) -endif() +set (DISPLAY_SCHEMA ${CMAKE_BINARY_DIR}/data/org.ayatana.indicator.display.gschema.xml) add_definitions(-DSCHEMA_DIR="${SCHEMA_DIR}") execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} gio-2.0 --variable glib_compile_schemas OUTPUT_VARIABLE COMPILE_SCHEMA_EXECUTABLE OUTPUT_STRIP_TRAILING_WHITESPACE) +# Because gschemas.compiled will be referenced multiple times independently, a level of +# redirection is needed to prevent CMake from generating the rule for the file multiple +# times, causing a race condition. +# https://discourse.cmake.org/t/race-condition-when-multi-add-custom-target-deps-on-same-file-generated-by-add-custom-command/2358 +# https://bugs.debian.org/892091 (bug for ayatana-indicators-power, but applies here as well) add_custom_command (OUTPUT gschemas.compiled + DEPENDS ${CMAKE_BINARY_DIR}/data/org.ayatana.indicator.display.gschema.xml COMMAND mkdir -p ${SCHEMA_DIR} COMMAND cp -f ${DISPLAY_SCHEMA} ${SCHEMA_DIR} COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR}) +add_custom_target(gschemas-compiled DEPENDS gschemas.compiled) set(SERVICE_LINK_LIBRARIES ${SERVICE_LIB} ${SERVICE_DEPS_LIBRARIES} ) -set(QT_LINK_LIBRARIES - test-utils - Qt5::Core - Qt5::Test - Qt5::DBus -) set(TEST_LINK_LIBRARIES ${TEST_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES} ) -add_definitions( - -DGREETER_TEMPLATE="${CMAKE_SOURCE_DIR}/tests/utils/mock-greeter.py" -) - function(add_test_by_name name) set(TEST_NAME ${name}) set(COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} ${TEST_NAME} PARENT_SCOPE) - add_executable (${TEST_NAME} ${TEST_NAME}.cpp gschemas.compiled) + add_executable (${TEST_NAME} ${TEST_NAME}.cpp) target_link_options(${TEST_NAME} PRIVATE -no-pie) add_test(${TEST_NAME} ${TEST_NAME}) + add_dependencies(${TEST_NAME} gschemas-compiled) set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT ${CTEST_ENVIRONMENT}) + set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT "TEST_NAME=${TEST_NAME}") target_link_libraries(${TEST_NAME} ${SERVICE_LINK_LIBRARIES} ${TEST_LINK_LIBRARIES} ${THREAD_LINK_LIBRARIES}) endfunction() -add_test_by_name(adbd-client-test) add_test_by_name(rotation-lock-test) -function(add_qt_test_by_name name) - set(TEST_NAME ${name}) - set(COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} ${TEST_NAME} PARENT_SCOPE) - add_executable (${TEST_NAME} ${TEST_NAME}.cpp) - target_link_options(${TEST_NAME} PRIVATE -no-pie) - add_test(${TEST_NAME} ${TEST_NAME}) - set_property(TEST ${TEST_NAME} APPEND PROPERTY ENVIRONMENT ${CTEST_ENVIRONMENT}) - target_link_libraries(${TEST_NAME} ${SERVICE_LINK_LIBRARIES} ${QT_LINK_LIBRARIES} ${TEST_LINK_LIBRARIES} ${THREAD_LINK_LIBRARIES}) -endfunction() -add_qt_test_by_name(greeter-test) -add_qt_test_by_name(usb-snap-test) - set(COVERAGE_TEST_TARGETS ${COVERAGE_TEST_TARGETS} PARENT_SCOPE diff --git a/tests/unit/adbd-client-test.cpp b/tests/unit/adbd-client-test.cpp deleted file mode 100644 index b9e7a49..0000000 --- a/tests/unit/adbd-client-test.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Copyright 2016 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Charles Kerr <charles.kerr@canonical.com> - */ - -#include <tests/utils/test-dbus-fixture.h> -#include <tests/utils/adbd-server.h> - -#include <src/adbd-client.h> - -class AdbdClientFixture: public TestDBusFixture -{ -private: - typedef TestDBusFixture super; - -protected: - - static void file_deleter (std::string* s) - { - fprintf(stderr, "remove \"%s\"\n", s->c_str()); - g_remove(s->c_str()); - delete s; - } - - std::shared_ptr<std::string> m_tmpdir; - - void SetUp() override - { - super::SetUp(); - - char tmpl[] = {"adb-client-test-XXXXXX"}; - m_tmpdir.reset(new std::string{g_mkdtemp(tmpl)}, file_deleter); - g_message("using tmpdir '%s'", m_tmpdir->c_str()); - } -}; - - -TEST_F(AdbdClientFixture, SocketPlumbing) -{ - struct { - const std::string request; - const std::string expected_pk; - AdbdClient::PKResponse response; - const std::string expected_response; - } tests[] = { - { "PKHelloWorld", "HelloWorld", AdbdClient::PKResponse::ALLOW, "OK" }, - { "PKHelloWorld", "HelloWorld", AdbdClient::PKResponse::DENY, "NO" }, - { "PKFooBar", "FooBar", AdbdClient::PKResponse::ALLOW, "OK" }, - { "PK", "", AdbdClient::PKResponse::DENY, "NO" } - }; - - const auto main_thread = g_thread_self(); - - const auto socket_path = *m_tmpdir + "/test-socket-plumbing"; - g_message("socket_path is %s", socket_path.c_str()); - - for (const auto& test : tests) - { - // start an AdbdClient that listens for PKRequests - std::string pk; - auto adbd_client = std::make_shared<GAdbdClient>(socket_path); - auto connection = adbd_client->on_pk_request().connect([&pk, main_thread, test](const AdbdClient::PKRequest& req){ - EXPECT_EQ(main_thread, g_thread_self()); - g_message("in on_pk_request with %s", req.public_key.c_str()); - pk = req.public_key; - req.respond(test.response); - }); - - // start a mock AdbdServer with to fire test key requests and wait for a response - auto adbd_server = std::make_shared<GAdbdServer>(socket_path, std::vector<std::string>{test.request}); - wait_for([adbd_server](){return !adbd_server->m_responses.empty();}, 5000); - EXPECT_EQ(test.expected_pk, pk); - ASSERT_EQ(1, adbd_server->m_responses.size()); - EXPECT_EQ(test.expected_response, adbd_server->m_responses.front()); - - // cleanup - connection.disconnect(); - adbd_client.reset(); - adbd_server.reset(); - g_unlink(socket_path.c_str()); - } -} diff --git a/tests/unit/greeter-test.cpp b/tests/unit/greeter-test.cpp deleted file mode 100644 index 61880f6..0000000 --- a/tests/unit/greeter-test.cpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2016 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Charles Kerr <charles.kerr@canonical.com> - */ - -#include <tests/utils/qt-fixture.h> -#include <tests/utils/gtest-print-helpers.h> - -#include <src/dbus-names.h> -#include <src/greeter.h> - -#include <libqtdbustest/DBusTestRunner.h> -#include <libqtdbustest/QProcessDBusService.h> -#include <libqtdbusmock/DBusMock.h> - -class GreeterFixture: public QtFixture -{ -private: - - using super = QtFixture; - -public: - - GreeterFixture() =default; - ~GreeterFixture() =default; - -protected: - - std::shared_ptr<QtDBusTest::DBusTestRunner> m_dbus_runner; - std::shared_ptr<QtDBusMock::DBusMock> m_dbus_mock; - GDBusConnection* m_bus {}; - - void SetUp() override - { - super::SetUp(); - - // use a fresh bus for each test run - m_dbus_runner.reset(new QtDBusTest::DBusTestRunner()); - m_dbus_mock.reset(new QtDBusMock::DBusMock(*m_dbus_runner.get())); - - GError* error {}; - m_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, nullptr, &error); - g_assert_no_error(error); - g_dbus_connection_set_exit_on_close(m_bus, FALSE); - } - - void TearDown() override - { - g_clear_object(&m_bus); - - super::TearDown(); - } - - void start_greeter_service(bool is_active) - { - // set a watcher to look for our mock greeter to appear - bool owned {}; - QDBusServiceWatcher watcher( - DBusNames::Greeter::NAME, - m_dbus_runner->sessionConnection() - ); - QObject::connect( - &watcher, - &QDBusServiceWatcher::serviceRegistered, - [&owned](const QString&){owned = true;} - ); - - // start the mock greeter - QVariantMap parameters; - parameters["IsActive"] = QVariant(is_active); - m_dbus_mock->registerTemplate( - DBusNames::Greeter::NAME, - GREETER_TEMPLATE, - parameters, - QDBusConnection::SessionBus - ); - m_dbus_runner->startServices(); - - // wait for the watcher - ASSERT_TRUE(wait_for([&owned]{return owned;})); - } -}; - -#define ASSERT_PROPERTY_EQ_EVENTUALLY(expected_in, property_in) \ - do { \ - const auto& e = expected_in; \ - const auto& p = property_in; \ - ASSERT_TRUE(wait_for([e, &p](){return e == p.get();})) \ - << "expected " << e << " but got " << p.get(); \ - } while(0) - -/** - * Test startup timing by looking at four different cases: - * [unity greeter shows up on bus (before, after) we start listening] - * x [unity greeter is (active, inactive)] - */ - -TEST_F(GreeterFixture, ActiveServiceStartsBeforeWatcher) -{ - constexpr bool is_active {true}; - constexpr Greeter::State expected {Greeter::State::ACTIVE}; - - start_greeter_service(is_active); - - Greeter greeter; - - ASSERT_PROPERTY_EQ_EVENTUALLY(expected, greeter.state()); -} - -TEST_F(GreeterFixture, WatcherStartsBeforeActiveService) -{ - constexpr bool is_active {true}; - constexpr Greeter::State expected {Greeter::State::ACTIVE}; - - Greeter greeter; - - start_greeter_service(is_active); - - ASSERT_PROPERTY_EQ_EVENTUALLY(expected, greeter.state()); -} - -TEST_F(GreeterFixture, InactiveServiceStartsBeforeWatcher) -{ - constexpr bool is_active {false}; - constexpr Greeter::State expected {Greeter::State::INACTIVE}; - - start_greeter_service(is_active); - - Greeter greeter; - - ASSERT_PROPERTY_EQ_EVENTUALLY(expected, greeter.state()); -} - -TEST_F(GreeterFixture, WatcherStartsBeforeInactiveService) -{ - constexpr bool is_active {false}; - constexpr Greeter::State expected {Greeter::State::INACTIVE}; - - Greeter greeter; - - start_greeter_service(is_active); - - ASSERT_PROPERTY_EQ_EVENTUALLY(expected, greeter.state()); -} - diff --git a/tests/unit/rotation-lock-test.cpp b/tests/unit/rotation-lock-test.cpp index a4ce388..7bf2e45 100644 --- a/tests/unit/rotation-lock-test.cpp +++ b/tests/unit/rotation-lock-test.cpp @@ -19,7 +19,7 @@ #include <tests/utils/test-dbus-fixture.h> -#include <src/rotation-lock.h> +#include <src/service.h> class RotationLockFixture: public TestDBusFixture { @@ -45,9 +45,9 @@ protected: TEST_F(RotationLockFixture, CheckIndicator) { - RotationLockIndicator indicator; + DisplayIndicator indicator; - ASSERT_STREQ("rotation_lock", indicator.name()); + ASSERT_STREQ("display", indicator.name()); auto actions = indicator.action_group(); ASSERT_TRUE(actions != nullptr); ASSERT_TRUE(g_action_group_has_action(G_ACTION_GROUP(actions), "rotation-lock")); diff --git a/tests/unit/usb-snap-test.cpp b/tests/unit/usb-snap-test.cpp deleted file mode 100644 index 2be4b27..0000000 --- a/tests/unit/usb-snap-test.cpp +++ /dev/null @@ -1,138 +0,0 @@ -/* - * Copyright 2016 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Charles Kerr <charles.kerr@canonical.com> - */ - -#include <tests/utils/qt-fixture.h> - -#include <src/dbus-names.h> -#include <src/usb-snap.h> - -#include <libqtdbustest/DBusTestRunner.h> -#include <libqtdbustest/QProcessDBusService.h> -#include <libqtdbusmock/DBusMock.h> - -class UsbSnapFixture: public QtFixture -{ - using super = QtFixture; - -public: - - UsbSnapFixture(): - dbusMock{dbusTestRunner} - { - dbusTestRunner.startServices(); - } - - ~UsbSnapFixture() =default; - -protected: - - void SetUp() override - { - super::SetUp(); - - dbusMock.registerNotificationDaemon(); - dbusTestRunner.startServices(); - } - - OrgFreedesktopDBusMockInterface& notificationsMockInterface() - { - return dbusMock.mockInterface(DBusNames::Notify::NAME, - DBusNames::Notify::PATH, - DBusNames::Notify::INTERFACE, - QDBusConnection::SessionBus); - } - - QtDBusTest::DBusTestRunner dbusTestRunner; - QtDBusMock::DBusMock dbusMock; -}; - -TEST_F(UsbSnapFixture, TestRoundTrip) -{ - struct { - const char* fingerprint; - const char* action_to_invoke; - const AdbdClient::PKResponse expected_response; - } tests[] = { - { "Fingerprint", "allow", AdbdClient::PKResponse::ALLOW }, - { "Fingerprint", "deny", AdbdClient::PKResponse::DENY } - }; - - uint32_t next_id = 1; - for(const auto& test : tests) - { - // Minor wart: we don't have a way of getting the fdo notification id - // from dbusmock so instead we copy its (simple) id generation here - const auto id = next_id++; - - QSignalSpy notificationsSpy( - ¬ificationsMockInterface(), - SIGNAL(MethodCalled(const QString &, const QVariantList &))); - - // start up a UsbSnap to ask about a fingerprint - auto snap = std::make_shared<UsbSnap>(test.fingerprint); - AdbdClient::PKResponse user_response {}; - bool user_response_set = false; - auto connection = snap->on_user_response().connect([&user_response,&user_response_set](AdbdClient::PKResponse response, bool /*remember*/){ - user_response = response; - user_response_set = true; - }); - - // test that UsbSnap creates a fdo notification - wait_for_signals(notificationsSpy, 1); - { - QVariantList const& call(notificationsSpy.at(0)); - EXPECT_EQ("Notify", call.at(0)); - - QVariantList const& args(call.at(1).toList()); - ASSERT_EQ(8, args.size()); - EXPECT_EQ("", args.at(0)); // app name - EXPECT_EQ(0, args.at(1)); // replaces-id - EXPECT_EQ("computer-symbolic", args.at(2)); // icon name - EXPECT_EQ("Allow USB Debugging?", args.at(3)); // summary - EXPECT_EQ(QString::fromUtf8("The computer's RSA key fingerprint is: ") + test.fingerprint, args.at(4)); // body - EXPECT_EQ(QStringList({"allow", "Allow", "deny", "Don't Allow"}), args.at(5)); // actions - EXPECT_EQ(-1, args.at(7)); - - QVariantMap hints; - ASSERT_TRUE(qDBusArgumentToMap(args.at(6), hints)); - ASSERT_EQ(3, hints.size()); - ASSERT_TRUE(hints.contains("x-canonical-private-affirmative-tint")); - ASSERT_TRUE(hints.contains("x-canonical-non-shaped-icon")); - ASSERT_TRUE(hints.contains("x-canonical-snap-decisions")); - } - notificationsSpy.clear(); - - // fake a user interaction with the fdo notification - notificationsMockInterface().EmitSignal( - DBusNames::Notify::INTERFACE, - DBusNames::Notify::ActionInvoked::NAME, - "us", - QVariantList() << id << test.action_to_invoke); - - // test that UsbSnap emits on_user_response() as a result - wait_for([&user_response_set](){return user_response_set;}); - EXPECT_TRUE(user_response_set); - ASSERT_EQ(test.expected_response, user_response); - - // confirm that the snap dtor doesn't try to close - // the notification that's already been closed by user choice - snap.reset(); - EXPECT_FALSE(notificationsSpy.wait(1000)); - } -} diff --git a/tests/utils/CMakeLists.txt b/tests/utils/CMakeLists.txt deleted file mode 100644 index fd82b79..0000000 --- a/tests/utils/CMakeLists.txt +++ /dev/null @@ -1,16 +0,0 @@ -include_directories( - ${CMAKE_CURRENT_BINARY_DIR} - ${CMAKE_CURRENT_SOURCE_DIR} -) - -add_library( - test-utils - STATIC - qmain.cpp -) - -qt5_use_modules( - test-utils - Core - DBus -) diff --git a/tests/utils/adbd-server.h b/tests/utils/adbd-server.h deleted file mode 100644 index 585380f..0000000 --- a/tests/utils/adbd-server.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright 2016 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Charles Kerr <charles.kerr@canonical.com> - */ - -#include <gio/gio.h> -#include <gio/gunixsocketaddress.h> - -#include <string> -#include <thread> -#include <vector> - - -/** - * A Mock ADBD server. - * - * Binds to a local domain socket, sends public key requests across it, - * and reads back the client's responses. - */ -class GAdbdServer -{ -public: - - GAdbdServer(const std::string& socket_path, - const std::vector<std::string>& requests): - m_requests{requests}, - m_server_socket{create_server_socket(socket_path)}, - m_cancellable{g_cancellable_new()}, - m_worker_thread{&GAdbdServer::worker_func, this} - { - } - - ~GAdbdServer() - { - // tell the worker thread to stop whatever it's doing and exit. - g_cancellable_cancel(m_cancellable); - m_worker_thread.join(); - g_clear_object(&m_cancellable); - g_clear_object(&m_server_socket); - } - - const std::vector<std::string> m_requests; - std::vector<std::string> m_responses; - -private: - - void worker_func() // runs in worker thread - { - auto requests = m_requests; - - while (!g_cancellable_is_cancelled(m_cancellable) && !requests.empty()) - { - // wait for a client connection - g_message("GAdbdServer::Impl::worker_func() calling g_socket_accept()"); - GError* error {}; - auto client_socket = g_socket_accept(m_server_socket, m_cancellable, &error); - if (error != nullptr) { - if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_message("GAdbdServer: Error accepting socket connection: %s", error->message); - g_clear_error(&error); - break; - } - - // pop the next request off the stack - auto request = requests.front(); - - // send the request - g_message("GAdbdServer::Impl::worker_func() sending req [%s]", request.c_str()); - g_socket_send(client_socket, - request.c_str(), - request.size(), - m_cancellable, - &error); - if (error != nullptr) { - if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_message("GAdbdServer: Error sending request: %s", error->message); - g_clear_error(&error); - g_clear_object(&client_socket); - break; - } - - // read the response - g_message("GAdbdServer::Impl::worker_func() reading response"); - char buf[4096]; - const auto n_bytes = g_socket_receive(client_socket, - buf, - sizeof(buf), - m_cancellable, - &error); - if (error != nullptr) { - if (!g_error_matches(error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) - g_message("GAdbdServer: Error reading response: %s", error->message); - g_clear_error(&error); - g_clear_object(&client_socket); - continue; - } - const std::string response(buf, std::string::size_type(n_bytes)); - g_message("server read %d bytes, got response: '%s'", int(n_bytes), response.c_str()); - if (!response.empty()) { - m_responses.push_back(response); - requests.erase(requests.begin()); - } - - // cleanup - g_clear_object(&client_socket); - } - } - - // bind to a local domain socket - static GSocket* create_server_socket(const std::string& socket_path) - { - GError* error {}; - auto socket = g_socket_new(G_SOCKET_FAMILY_UNIX, - G_SOCKET_TYPE_STREAM, - G_SOCKET_PROTOCOL_DEFAULT, - &error); - g_assert_no_error(error); - auto address = g_unix_socket_address_new (socket_path.c_str()); - g_socket_bind (socket, address, false, &error); - g_assert_no_error (error); - g_clear_object (&address); - - g_socket_listen (socket, &error); - g_assert_no_error (error); - - return socket; - } - - GSocket* m_server_socket {}; - GCancellable* m_cancellable {}; - std::thread m_worker_thread; -}; - - diff --git a/tests/utils/dbus-types.h b/tests/utils/dbus-types.h deleted file mode 100644 index 3b3a02d..0000000 --- a/tests/utils/dbus-types.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2013-2016 Canonical, Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Author: Pete Woods <pete.woods@canonical.com> - */ - -#pragma once - -#include <QDBusMetaType> -#include <QtCore> -#include <QString> -#include <QVariantMap> - -typedef QMap<QString, QVariantMap> QVariantDictMap; -Q_DECLARE_METATYPE(QVariantDictMap) - -typedef QMap<QString, QString> QStringMap; -Q_DECLARE_METATYPE(QStringMap) - -namespace DBusTypes -{ - inline void registerMetaTypes() - { - qRegisterMetaType<QVariantDictMap>("QVariantDictMap"); - qRegisterMetaType<QStringMap>("QStringMap"); - - qDBusRegisterMetaType<QVariantDictMap>(); - qDBusRegisterMetaType<QStringMap>(); - } -} diff --git a/tests/utils/glib-fixture.h b/tests/utils/glib-fixture.h index ccdeccd..b56654b 100644 --- a/tests/utils/glib-fixture.h +++ b/tests/utils/glib-fixture.h @@ -35,7 +35,7 @@ class GlibFixture : public ::testing::Test { public: - virtual ~GlibFixture() =default; + virtual ~GlibFixture() override =default; protected: diff --git a/tests/utils/gtest-print-helpers.h b/tests/utils/gtest-print-helpers.h deleted file mode 100644 index 60f42b4..0000000 --- a/tests/utils/gtest-print-helpers.h +++ /dev/null @@ -1,18 +0,0 @@ - -#pragma once - -#include <src/greeter.h> - -inline void PrintTo(const Greeter::State& state, std::ostream* os) { - switch(state) { - case Greeter::State::ACTIVE: *os << "Active"; break; - case Greeter::State::INACTIVE: *os << "Inactive"; break; - case Greeter::State::UNAVAILABLE: *os << "Unavailable"; break; - } -} - -inline std::ostream& operator<<(std::ostream& os, const Greeter::State& state) { - PrintTo(state, &os); - return os; -} - diff --git a/tests/utils/gtest-qt-print-helpers.h b/tests/utils/gtest-qt-print-helpers.h deleted file mode 100644 index 7a0897e..0000000 --- a/tests/utils/gtest-qt-print-helpers.h +++ /dev/null @@ -1,45 +0,0 @@ - -#pragma once - -#include <QDBusObjectPath> -#include <QString> -#include <QStringList> -#include <QVariant> - -inline QString qVariantToString(const QVariant& variant) { - QString output; - QDebug dbg(&output); - dbg << variant; - return output; -} - -inline void PrintTo(const QVariant& variant, std::ostream* os) { - QString output; - QDebug dbg(&output); - dbg << variant; - - *os << "QVariant(" << output.toStdString() << ")"; -} - -inline void PrintTo(const QString& s, std::ostream* os) { - *os << "\"" << s.toStdString() << "\""; -} - -inline void PrintTo(const QStringList& list, std::ostream* os) { - QString output; - QDebug dbg(&output); - dbg << list; - - *os << "QStringList(" << output.toStdString() << ")"; -} - -inline void PrintTo(const QList<QDBusObjectPath>& list, std::ostream* os) { - QString output; - for (const auto& path: list) - { - output.append("\"" + path.path() + "\","); - } - - *os << "QList<QDBusObjectPath>(" << output.toStdString() << ")"; -} - diff --git a/tests/utils/mock-greeter.h b/tests/utils/mock-greeter.h deleted file mode 100644 index 5015087..0000000 --- a/tests/utils/mock-greeter.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2016 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Charles Kerr <charles.kerr@canonical.com> - */ - -#pragma once - -#include <src/greeter.h> - -class MockGreeter: public Greeter -{ -public: - MockGreeter() =default; - virtual ~MockGreeter() =default; - core::Property<Greeter::State>& state() override {return m_state;} - core::Property<Greeter::State> m_state {State::INACTIVE}; -}; - diff --git a/tests/utils/mock-greeter.py b/tests/utils/mock-greeter.py deleted file mode 100644 index dc48a6d..0000000 --- a/tests/utils/mock-greeter.py +++ /dev/null @@ -1,41 +0,0 @@ -'''desktop greeter mock template - -Very basic template that just mocks the greeter is-active flag -''' - -# This program is free software; you can redistribute it and/or modify it under -# the terms of the GNU Lesser General Public License as published by the Free -# Software Foundation; either version 3 of the License, or (at your option) any -# later version. See http://www.gnu.org/copyleft/lgpl.html for the full text -# of the license. - -__author__ = 'Charles Kerr' -__email__ = 'charles.kerr@canonical.com' -__copyright__ = '(c) 2016 Canonical Ltd.' -__license__ = 'LGPL 3+' - -import dbus -import os - -from dbusmock import MOCK_IFACE, mockobject - -BUS_NAME = 'org.ayatana.Greeter' -MAIN_OBJ = '/' -MAIN_IFACE = 'org.ayatana.Greeter' -SYSTEM_BUS = False - - -def load(mock, parameters): - mock.AddMethods( - MAIN_IFACE, [ - ('HideGreeter', '', '', 'self.Set("org.ayatana.Greeter", "IsActive", False)'), - ('ShowGreeter', '', '', 'self.Set("org.ayatana.Greeter", "IsActive", True)') - ] - ) - mock.AddProperties( - MAIN_IFACE, - dbus.Dictionary({ - 'IsActive': parameters.get('IsActive', False), - }, signature='sv') - ) - diff --git a/tests/utils/mock-usb-monitor.h b/tests/utils/mock-usb-monitor.h deleted file mode 100644 index 92b89db..0000000 --- a/tests/utils/mock-usb-monitor.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2016 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Charles Kerr <charles.kerr@canonical.com> - */ - -#pragma once - -#include <src/usb-monitor.h> - -class MockUsbMonitor: public UsbMonitor -{ -public: - MockUsbMonitor() =default; - virtual ~MockUsbMonitor() =default; - core::Signal<const std::string&>& on_usb_disconnected() override {return m_on_usb_disconnected;} - core::Signal<const std::string&> m_on_usb_disconnected; -}; - diff --git a/tests/utils/qmain.cpp b/tests/utils/qmain.cpp deleted file mode 100644 index 01a7892..0000000 --- a/tests/utils/qmain.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright © 2014 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU Lesser General Public License version 3, - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Pete Woods <pete.woods@canonical.com> - */ - -//#include <config.h> - -#include <QCoreApplication> -#include <QTimer> -#include <gtest/gtest.h> - -#include <libqtdbusmock/DBusMock.h> - -using namespace QtDBusMock; - -class Runner: public QObject -{ - Q_OBJECT -public Q_SLOTS: - void run() - { - QCoreApplication::exit(RUN_ALL_TESTS()); - } -}; - -int main(int argc, char **argv) -{ - qputenv("LANG", "C.UTF-8"); - unsetenv("LC_ALL"); - - // boilerplate i18n - setlocale(LC_ALL, ""); - bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); - textdomain(GETTEXT_PACKAGE); - - QCoreApplication application(argc, argv); - DBusMock::registerMetaTypes(); - ::testing::InitGoogleTest(&argc, argv); - - Runner runner; - QTimer::singleShot(0, &runner, SLOT(run())); - - return application.exec(); -} - -#include "qmain.moc" diff --git a/tests/utils/qt-fixture.h b/tests/utils/qt-fixture.h deleted file mode 100644 index 95b9b14..0000000 --- a/tests/utils/qt-fixture.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright 2016 Canonical Ltd. - * - * This program is free software: you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 3, as published - * by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, but - * WITHOUT ANY WARRANTY; without even the implied warranties of - * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program. If not, see <http://www.gnu.org/licenses/>. - * - * Authors: - * Charles Kerr <charles.kerr@canonical.com> - */ - -#pragma once - -#define QT_NO_KEYWORDS - -#include <tests/utils/dbus-types.h> -#include <tests/utils/glib-fixture.h> -#include <tests/utils/gtest-qt-print-helpers.h> - -#include <gtest/gtest.h> - -#include <QDBusArgument> -#include <QVariant> -#include <QSignalSpy> - -#define wait_for_signals(signalSpy,signalsExpected) \ -{ \ - while (signalSpy.size() < signalsExpected) \ - { \ - ASSERT_TRUE(signalSpy.wait()); \ - } \ - \ - ASSERT_EQ(signalsExpected, signalSpy.size()); \ -} - -class QtFixture: public GlibFixture -{ - using super = GlibFixture; - -public: - - QtFixture() - { - DBusTypes::registerMetaTypes(); - } - - ~QtFixture() =default; - -protected: - - bool qDBusArgumentToMap(QVariant const& variant, QVariantMap& map) - { - if (variant.canConvert<QDBusArgument>()) - { - QDBusArgument value(variant.value<QDBusArgument>()); - if (value.currentType() == QDBusArgument::MapType) - { - value >> map; - return true; - } - } - - return false; - } -}; - diff --git a/tests/utils/test-dbus-fixture.h b/tests/utils/test-dbus-fixture.h index b01405a..e98a002 100644 --- a/tests/utils/test-dbus-fixture.h +++ b/tests/utils/test-dbus-fixture.h @@ -30,7 +30,7 @@ class TestDBusFixture: public GlibFixture public: explicit TestDBusFixture() {}; - virtual ~TestDBusFixture() =default; + virtual ~TestDBusFixture() override =default; explicit TestDBusFixture(const std::vector<std::string>& service_dirs_in): service_dirs(service_dirs_in) {} |