From 41ef58955239d873b1c4db850f781eaff5748169 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 19 Aug 2014 22:17:59 -0500 Subject: initial pass at tests/ directory, skeleton only --- tests/CMakeLists.txt | 36 ++++++++++++ tests/glib-fixture.h | 141 +++++++++++++++++++++++++++++++++++++++++++++ tests/manual | 26 +++++++++ tests/test-hello-world.cpp | 48 +++++++++++++++ 4 files changed, 251 insertions(+) create mode 100644 tests/CMakeLists.txt create mode 100644 tests/glib-fixture.h create mode 100644 tests/manual create mode 100644 tests/test-hello-world.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..a2491b6 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,36 @@ +include(FindGMock) +include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +include_directories(${GMOCK_INCLUDE_DIRS}) +include_directories(${GTEST_INCLUDE_DIRS}) + +# build libgtest +#add_library (gtest STATIC +# ${GTEST_SOURCE_DIR}/gtest-all.cc +# ${GTEST_SOURCE_DIR}/gtest_main.cc) +#set_target_properties (gtest PROPERTIES INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} ${GTEST_INCLUDE_DIR}) +#set_target_properties (gtest PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS} -w) + +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + # turn off the warnings that break Google Test + set (CXX_WARNING_ARGS "${CXX_WARNING_ARGS} -Wno-global-constructors -Wno-weak-vtables -Wno-undef -Wno-c++98-compat-pedantic -Wno-missing-noreturn -Wno-used-but-marked-unused -Wno-padded -Wno-deprecated -Wno-sign-compare -Wno-shift-sign-overflow") +endif() + +SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g ${CXX_WARNING_ARGS}") + +# look for headers in our src dir, and also in the directories where we autogenerate files... +include_directories (${CMAKE_SOURCE_DIR}/src) +include_directories (${CMAKE_CURRENT_BINARY_DIR}) +include_directories (${DBUSTEST_INCLUDE_DIRS}) + +function(add_test_by_name name) + set (TEST_NAME ${name}) + add_executable (${TEST_NAME} ${TEST_NAME}.cpp) + add_test (${TEST_NAME} ${TEST_NAME}) + add_dependencies (${TEST_NAME} libindicatortransferservice) + #target_link_libraries (${TEST_NAME} indicatortransferservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS}) + target_link_libraries (${TEST_NAME} indicatortransferservice ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES}) +endfunction() +add_test_by_name(test-hello-world) + +add_test (cppcheck cppcheck --enable=all -q --error-exitcode=2 --inline-suppr -I${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/tests) + diff --git a/tests/glib-fixture.h b/tests/glib-fixture.h new file mode 100644 index 0000000..4c53244 --- /dev/null +++ b/tests/glib-fixture.h @@ -0,0 +1,141 @@ +/* + * Copyright 2014 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 . + * + * Authors: + * Charles Kerr + */ + +#include + +#include +#include +#include + +#include + +#include // setlocale() + +class GlibFixture : public ::testing::Test +{ + private: + + GLogFunc realLogHandler; + + std::map expected_log; + std::map> log; + + void test_log_counts() + { + const GLogLevelFlags levels_to_test[] = { G_LOG_LEVEL_ERROR, + G_LOG_LEVEL_CRITICAL, + G_LOG_LEVEL_MESSAGE, + G_LOG_LEVEL_WARNING }; + + for(const auto& level : levels_to_test) + { + const auto& v = log[level]; + const auto n = v.size(); + + EXPECT_EQ(expected_log[level], n); + + if (expected_log[level] != n) + for (size_t i=0; i(self)->log[log_level].push_back(tmp); + g_free(tmp); + } + + protected: + + void increment_expected_errors(GLogLevelFlags level, size_t n=1) + { + expected_log[level] += n; + } + + virtual void SetUp() + { + setlocale(LC_ALL, "C.UTF-8"); + + loop = g_main_loop_new(nullptr, false); + + g_log_set_default_handler(default_log_handler, this); + + g_unsetenv("DISPLAY"); + } + + virtual void TearDown() + { + test_log_counts(); + + g_log_set_default_handler(realLogHandler, this); + + g_clear_pointer(&loop, g_main_loop_unref); + } + + private: + + static gboolean + wait_for_signal__timeout(gpointer name) + { + g_error("%s: timed out waiting for signal '%s'", G_STRLOC, (char*)name); + return G_SOURCE_REMOVE; + } + + static gboolean + wait_msec__timeout(gpointer loop) + { + g_main_loop_quit(static_cast(loop)); + return G_SOURCE_CONTINUE; + } + + protected: + + /* convenience func to loop while waiting for a GObject's signal */ + void wait_for_signal(gpointer o, const gchar * signal, const guint timeout_seconds=5) + { + // wait for the signal or for timeout, whichever comes first + const auto handler_id = g_signal_connect_swapped(o, signal, + G_CALLBACK(g_main_loop_quit), + loop); + const auto timeout_id = g_timeout_add_seconds(timeout_seconds, + wait_for_signal__timeout, + loop); + g_main_loop_run(loop); + g_source_remove(timeout_id); + g_signal_handler_disconnect(o, handler_id); + } + + /* convenience func to loop for N msec */ + void wait_msec(guint msec=50) + { + const auto id = g_timeout_add(msec, wait_msec__timeout, loop); + g_main_loop_run(loop); + g_source_remove(id); + } + + GMainLoop * loop; +}; diff --git a/tests/manual b/tests/manual new file mode 100644 index 0000000..fc81e6e --- /dev/null +++ b/tests/manual @@ -0,0 +1,26 @@ + +Test-case indicator-transfer/simple-download-check +
+
Ensure indicator-transfer-service is running
+
The indicator should be visible in the panel
+ +
Run the script tests/simple-download.py and, immediately afterwards, + click or pull down on the indicator so that its menu is visible + and its menuitems can be observed while the downloads run.
+
In the 'Ongoing Transfers' section, the transfers should appear
+
In the 'Ongoing Transfers' section, a 'Pause all' button should appear
+
While transfers are active, the indicator's icon should indicate activity
+
As each transfer finishes, its menuitem should move from the 'Ongoing' to 'Successful' section
+
As the first transfer is moved to the 'Successful' section, a 'Clear all' button should appear
+
As the last transfer finishes, the indicator's icon should change to indicate an idle state
+
As the last transfer finishes, the 'Pause all' button should disappear
+ +
After all the transfers finish, press the 'Clear all' button.
+
All three transfers should be cleared from the menu.
+
The 'Clear all' button should disappear
+ + + + If all actions produce the expected results listed, please submit a 'passed' result. + If an action fails, or produces an unexpected result, please submit a 'failed' result and file a bug. Please be sure to include the bug number when you submit your result. + diff --git a/tests/test-hello-world.cpp b/tests/test-hello-world.cpp new file mode 100644 index 0000000..53d2ec3 --- /dev/null +++ b/tests/test-hello-world.cpp @@ -0,0 +1,48 @@ +/* + * Copyright 2014 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 . + * + * Authors: + * Charles Kerr + */ + +#include "glib-fixture.h" + +class HelloWorldFixture: public GlibFixture +{ +private: + typedef GlibFixture super; + +protected: + + void SetUp() + { + super::SetUp(); + } + + void TearDown() + { + super::TearDown(); + } +}; + +/*** +**** +***/ + +TEST_F(HelloWorldFixture, HelloWorld) +{ + EXPECT_TRUE(true) +} + -- cgit v1.2.3 From ec2c7ec58b192e0b907239ad1ff840fe69b4da56 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 19 Aug 2014 22:25:45 -0500 Subject: get skeletal service and tests building --- tests/CMakeLists.txt | 5 ++--- tests/test-hello-world.cpp | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index a2491b6..38c315c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -26,9 +26,8 @@ function(add_test_by_name name) set (TEST_NAME ${name}) add_executable (${TEST_NAME} ${TEST_NAME}.cpp) add_test (${TEST_NAME} ${TEST_NAME}) - add_dependencies (${TEST_NAME} libindicatortransferservice) - #target_link_libraries (${TEST_NAME} indicatortransferservice gtest ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS}) - target_link_libraries (${TEST_NAME} indicatortransferservice ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES}) + add_dependencies (${TEST_NAME} libindicatordisplayservice) + target_link_libraries (${TEST_NAME} indicatordisplayservice ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES}) endfunction() add_test_by_name(test-hello-world) diff --git a/tests/test-hello-world.cpp b/tests/test-hello-world.cpp index 53d2ec3..5d9c308 100644 --- a/tests/test-hello-world.cpp +++ b/tests/test-hello-world.cpp @@ -43,6 +43,6 @@ protected: TEST_F(HelloWorldFixture, HelloWorld) { - EXPECT_TRUE(true) + EXPECT_TRUE(true); } -- cgit v1.2.3 From 1b90575c67de3cf6459785cc18e3d661a826bece Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 20 Aug 2014 22:35:16 -0500 Subject: add rotation lock indicator --- tests/CMakeLists.txt | 4 +- tests/glib-fixture.h | 2 + tests/gtestdbus-fixture.h | 102 +++++++++++++++++++++++++++++++++++++++++++ tests/manual | 24 +++------- tests/test-hello-world.cpp | 48 -------------------- tests/test-rotation-lock.cpp | 61 ++++++++++++++++++++++++++ 6 files changed, 174 insertions(+), 67 deletions(-) create mode 100644 tests/gtestdbus-fixture.h delete mode 100644 tests/test-hello-world.cpp create mode 100644 tests/test-rotation-lock.cpp (limited to 'tests') diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 38c315c..054a676 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -29,7 +29,7 @@ function(add_test_by_name name) add_dependencies (${TEST_NAME} libindicatordisplayservice) target_link_libraries (${TEST_NAME} indicatordisplayservice ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBRARIES} ${GMOCK_LIBRARIES}) endfunction() -add_test_by_name(test-hello-world) +add_test_by_name(test-rotation-lock) -add_test (cppcheck cppcheck --enable=all -q --error-exitcode=2 --inline-suppr -I${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/tests) +add_test (cppcheck cppcheck --enable=all -q --error-exitcode=2 --inline-suppr -I${CMAKE_SOURCE_DIR} ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/tests) diff --git a/tests/glib-fixture.h b/tests/glib-fixture.h index 4c53244..a8f3a76 100644 --- a/tests/glib-fixture.h +++ b/tests/glib-fixture.h @@ -84,6 +84,8 @@ class GlibFixture : public ::testing::Test g_log_set_default_handler(default_log_handler, this); + g_assert(g_setenv("GSETTINGS_BACKEND", "memory", true)); + g_unsetenv("DISPLAY"); } diff --git a/tests/gtestdbus-fixture.h b/tests/gtestdbus-fixture.h new file mode 100644 index 0000000..541050e --- /dev/null +++ b/tests/gtestdbus-fixture.h @@ -0,0 +1,102 @@ +/* + * Copyright 2013 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 . + * + * Authors: + * Charles Kerr + */ + +#include "glib-fixture.h" + +/*** +**** +***/ + +class GTestDBusFixture: public GlibFixture +{ + public: + + GTestDBusFixture() {} + + GTestDBusFixture(const std::vector& service_dirs_in): service_dirs(service_dirs_in) {} + + private: + + typedef GlibFixture super; + + static void + on_bus_opened (GObject* /*object*/, GAsyncResult * res, gpointer gself) + { + auto self = static_cast(gself); + + GError * err = 0; + self->bus = g_bus_get_finish (res, &err); + g_assert_no_error (err); + + g_main_loop_quit (self->loop); + } + + static void + on_bus_closed (GObject* /*object*/, GAsyncResult * res, gpointer gself) + { + auto self = static_cast(gself); + + GError * err = 0; + g_dbus_connection_close_finish (self->bus, res, &err); + g_assert_no_error (err); + + g_main_loop_quit (self->loop); + } + + protected: + + GTestDBus * test_dbus = nullptr; + GDBusConnection * bus = nullptr; + const std::vector service_dirs; + + virtual void SetUp () + { + super::SetUp (); + + // pull up a test dbus + test_dbus = g_test_dbus_new (G_TEST_DBUS_NONE); + for (const auto& dir : service_dirs) + g_test_dbus_add_service_dir (test_dbus, dir.c_str()); + g_test_dbus_up (test_dbus); + const char * address = g_test_dbus_get_bus_address (test_dbus); + g_setenv ("DBUS_SYSTEM_BUS_ADDRESS", address, true); + g_setenv ("DBUS_SESSION_BUS_ADDRESS", address, true); + g_debug ("test_dbus's address is %s", address); + + // wait for the GDBusConnection before returning + g_bus_get (G_BUS_TYPE_SYSTEM, nullptr, on_bus_opened, this); + g_main_loop_run (loop); + } + + virtual void TearDown () + { + wait_msec(); + + // close the system bus + g_dbus_connection_close(bus, nullptr, on_bus_closed, this); + g_main_loop_run(loop); + g_clear_object(&bus); + + // tear down the test dbus + g_test_dbus_down(test_dbus); + g_clear_object(&test_dbus); + + super::TearDown(); + } +}; diff --git a/tests/manual b/tests/manual index fc81e6e..a0e5264 100644 --- a/tests/manual +++ b/tests/manual @@ -1,24 +1,14 @@ -Test-case indicator-transfer/simple-download-check +Test-case indicator-datetime/rotation-indicator
-
Ensure indicator-transfer-service is running
-
The indicator should be visible in the panel
+
On the phone, enable the orientation lock in ubuntu-system-settings.
+
The rotation lock indicator should appear, and its switch menuitem should be set to 'true'.
-
Run the script tests/simple-download.py and, immediately afterwards, - click or pull down on the indicator so that its menu is visible - and its menuitems can be observed while the downloads run.
-
In the 'Ongoing Transfers' section, the transfers should appear
-
In the 'Ongoing Transfers' section, a 'Pause all' button should appear
-
While transfers are active, the indicator's icon should indicate activity
-
As each transfer finishes, its menuitem should move from the 'Ongoing' to 'Successful' section
-
As the first transfer is moved to the 'Successful' section, a 'Clear all' button should appear
-
As the last transfer finishes, the indicator's icon should change to indicate an idle state
-
As the last transfer finishes, the 'Pause all' button should disappear
+
With the orientation locked, click on the indicator's switch menuitem to toggle from locked to unlocked. +
The rotation lock indicator should disappear
+
In ubuntu-system-settings, the orientation lock control should change to 'none'.
+
-
After all the transfers finish, press the 'Clear all' button.
-
All three transfers should be cleared from the menu.
-
The 'Clear all' button should disappear
- If all actions produce the expected results listed, please submit a 'passed' result. diff --git a/tests/test-hello-world.cpp b/tests/test-hello-world.cpp deleted file mode 100644 index 5d9c308..0000000 --- a/tests/test-hello-world.cpp +++ /dev/null @@ -1,48 +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 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 . - * - * Authors: - * Charles Kerr - */ - -#include "glib-fixture.h" - -class HelloWorldFixture: public GlibFixture -{ -private: - typedef GlibFixture super; - -protected: - - void SetUp() - { - super::SetUp(); - } - - void TearDown() - { - super::TearDown(); - } -}; - -/*** -**** -***/ - -TEST_F(HelloWorldFixture, HelloWorld) -{ - EXPECT_TRUE(true); -} - diff --git a/tests/test-rotation-lock.cpp b/tests/test-rotation-lock.cpp new file mode 100644 index 0000000..946b1dd --- /dev/null +++ b/tests/test-rotation-lock.cpp @@ -0,0 +1,61 @@ +/* + * Copyright 2014 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 . + * + * Authors: + * Charles Kerr + */ + +#include "gtestdbus-fixture.h" + +#include + +class RotationLockFixture: public GTestDBusFixture +{ +private: + typedef GTestDBusFixture super; + +protected: + + void SetUp() + { + super::SetUp(); + } + + void TearDown() + { + super::TearDown(); + } +}; + +/*** +**** +***/ + +TEST_F(RotationLockFixture, CheckIndicator) +{ + RotationLockIndicator indicator; + + ASSERT_STREQ("rotation_lock", indicator.name()); + auto actions = indicator.action_group(); + ASSERT_TRUE(actions != nullptr); + ASSERT_TRUE(g_action_group_has_action(G_ACTION_GROUP(actions), "rotation-lock")); + + std::vector> profiles = indicator.profiles(); + ASSERT_EQ(1, profiles.size()); + std::shared_ptr phone = profiles[0]; + ASSERT_EQ(std::string("phone"), phone->name()); + ASSERT_FALSE(phone->header()->is_visible); +} + -- cgit v1.2.3 From ce4b2f4c185105db22e1d6519c2b4d1ce0884008 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 21 Aug 2014 11:58:23 -0500 Subject: fix copy-paste error --- tests/manual | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/manual b/tests/manual index a0e5264..f175b22 100644 --- a/tests/manual +++ b/tests/manual @@ -1,5 +1,5 @@ -Test-case indicator-datetime/rotation-indicator +Test-case indicator-display/rotation-indicator
On the phone, enable the orientation lock in ubuntu-system-settings.
The rotation lock indicator should appear, and its switch menuitem should be set to 'true'.
-- cgit v1.2.3