From b0ac3df28f96e54d0adca7ba32a4993faffc44d2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 28 Oct 2014 18:01:35 -0500 Subject: Setup to getting something to compile and pass. Next steps needed. --- tests/CMakeLists.txt | 15 ++++++ tests/indicator-fixture.h | 115 ++++++++++++++++++++++++++++++++++++++++++++++ tests/indicator-test.cc | 38 +++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 tests/indicator-fixture.h create mode 100644 tests/indicator-test.cc diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ae68c45..1eec3fd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -181,3 +181,18 @@ add_test(greeter-list-test-iterator greeter-list-test --gtest_filter=GreeterListTest.BasicIterator ) +########################### +# Indicator Test +########################### + +add_executable (indicator-test indicator-test.cc) +target_link_libraries ( + indicator-test + gtest + ${SOUNDSERVICE_LIBRARIES} + ${TEST_LIBRARIES} +) + +# Split tests to work around libaccountservice sucking +add_test(indicator-test indicator-test) + diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h new file mode 100644 index 0000000..dfa83a1 --- /dev/null +++ b/tests/indicator-fixture.h @@ -0,0 +1,115 @@ +/* + * 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 as published by + * the Free Software Foundation; version 3. + * + * 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 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: + * Ted Gould + */ + + +#include +#include + +class IndicatorFixture : public ::testing::Test +{ + private: + std::string _indicatorPath; + std::string _indicatorAddress; + GMenu * _menu; + + public: + virtual ~IndicatorFixture() = default; + + IndicatorFixture (const std::string& path, + const std::string& addr) + : _indicatorPath(path) + , _indicatorAddress(addr) + , _menu(nullptr) + { + }; + + + protected: + virtual void SetUp() override + { + + + } + + virtual void TearDown() override + { + + + } + + void setMenu (const std::string& path) { + + } + + void expectActionExists (const std::string& name) { + + } + + void expectActionStateType (const std::string& name, const GVariantType * type) { + + } + + void expectActionStateIs (const std::string& name, const GVariant * value) { + + } + + void expectMenuAttributeVerify (int location, GMenuModel * menu, const std::string& attribute, GVariant * value) { + EXPECT_LT(location, g_menu_model_get_n_items(menu)); + if (location >= g_menu_model_get_n_items(menu)) + return; + + auto menuval = g_menu_model_get_item_attribute_value(menu, location, attribute.c_str(), NULL); + EXPECT_TRUE(g_variant_equal(value, menuval)); + g_variant_unref(menuval); + } + + void expectMenuAttributeRecurse (const std::vector menuLocation, const std::string& attribute, GVariant * value, unsigned int index, GMenuModel * menu) { + ASSERT_LT(menuLocation.size(), index); + + if (menuLocation.size() - 1 == index) + return expectMenuAttributeVerify(menuLocation[index], menu, attribute, value); + + auto submenu = g_menu_model_get_item_link(menu, menuLocation[index], G_MENU_LINK_SUBMENU); + EXPECT_NE(nullptr, submenu); + if (submenu == nullptr) + return; + + expectMenuAttributeRecurse(menuLocation, attribute, value, index++, submenu); + g_object_unref(submenu); + } + + void expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, GVariant * value) { + g_variant_ref_sink(value); + expectMenuAttributeRecurse(menuLocation, attribute, value, 0, G_MENU_MODEL(_menu)); + g_variant_unref(value); + } + + void expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, bool value) { + GVariant * var = g_variant_new_boolean(value); + expectMenuAttribute(menuLocation, attribute, var); + } + + void expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, std::string value) { + GVariant * var = g_variant_new_string(value.c_str()); + expectMenuAttribute(menuLocation, attribute, var); + } + + +}; + diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc new file mode 100644 index 0000000..52b131d --- /dev/null +++ b/tests/indicator-test.cc @@ -0,0 +1,38 @@ +/* + * 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 as published by + * the Free Software Foundation; version 3. + * + * 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 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: + * Ted Gould + */ + +#include +#include + +#include "indicator-fixture.h" + +class IndicatorTest : public IndicatorFixture +{ +protected: + IndicatorTest (void) : + IndicatorFixture("/test", "com.test") + { + } + +}; + + +TEST_F(IndicatorTest, StartStop) { + +} -- cgit v1.2.3 From 642c5d77b0d2fb42a6c9205e50592624542a813f Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 28 Oct 2014 18:10:50 -0500 Subject: Connect to binary and real name --- tests/CMakeLists.txt | 3 +++ tests/indicator-test.cc | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 1eec3fd..58ecd3a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -185,6 +185,9 @@ add_test(greeter-list-test-iterator # Indicator Test ########################### +add_definitions( + -DINDICATOR_SOUND_SERVICE_BINARY="${CMAKE_BINARY_DIR}/src/indicator-sound-service" +) add_executable (indicator-test indicator-test.cc) target_link_libraries ( indicator-test diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 52b131d..9ebb121 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -26,7 +26,7 @@ class IndicatorTest : public IndicatorFixture { protected: IndicatorTest (void) : - IndicatorFixture("/test", "com.test") + IndicatorFixture(INDICATOR_SOUND_SERVICE_BINARY, "com.canonical.indicator.sound") { } -- cgit v1.2.3 From dc8a919fa15ea03a53e359c60a4f73a3c80be8f4 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 28 Oct 2014 18:25:34 -0500 Subject: Building the DBus test integration --- tests/indicator-fixture.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index dfa83a1..4ab3046 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -20,6 +20,7 @@ #include #include +#include class IndicatorFixture : public ::testing::Test { @@ -27,6 +28,9 @@ class IndicatorFixture : public ::testing::Test std::string _indicatorPath; std::string _indicatorAddress; GMenu * _menu; + DbusTestService * _test_service; + DbusTestTask * _test_indicator; + DbusTestTask * _test_dummy; public: virtual ~IndicatorFixture() = default; @@ -43,14 +47,23 @@ class IndicatorFixture : public ::testing::Test protected: virtual void SetUp() override { + _test_service = dbus_test_service_new(nullptr); + _test_indicator = DBUS_TEST_TASK(dbus_test_process_new(_indicatorPath.c_str())); + dbus_test_service_add_task(_test_service, _test_indicator); + _test_dummy = dbus_test_task_new(); + dbus_test_task_set_wait_for(_test_dummy, _indicatorAddress.c_str()); + dbus_test_service_add_task(_test_service, _test_dummy); + + dbus_test_service_start_tasks(_test_service); } virtual void TearDown() override { - - + g_clear_object(&_test_dummy); + g_clear_object(&_test_indicator); + g_clear_object(&_test_service); } void setMenu (const std::string& path) { -- cgit v1.2.3 From 69a8fcaa1aacd2a43da2011ff5fb79e4ed2d8bbe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 28 Oct 2014 18:53:55 -0500 Subject: Getting menus --- tests/indicator-fixture.h | 47 +++++++++++++++++++++++++++++++++++++++++++---- tests/indicator-test.cc | 2 ++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 4ab3046..7f42246 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -27,10 +27,11 @@ class IndicatorFixture : public ::testing::Test private: std::string _indicatorPath; std::string _indicatorAddress; - GMenu * _menu; + GMenuModel * _menu; DbusTestService * _test_service; DbusTestTask * _test_indicator; DbusTestTask * _test_dummy; + GDBusConnection * _session; public: virtual ~IndicatorFixture() = default; @@ -40,6 +41,7 @@ class IndicatorFixture : public ::testing::Test : _indicatorPath(path) , _indicatorAddress(addr) , _menu(nullptr) + , _session(nullptr) { }; @@ -57,17 +59,53 @@ class IndicatorFixture : public ::testing::Test dbus_test_service_add_task(_test_service, _test_dummy); dbus_test_service_start_tasks(_test_service); + + _session = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); } virtual void TearDown() override { + /* Menu structures that could be allocated */ + g_clear_object(&_menu); + + /* D-Bus Test Stuff */ g_clear_object(&_test_dummy); g_clear_object(&_test_indicator); g_clear_object(&_test_service); + + /* Wait for D-Bus session bus to go */ + if (!g_dbus_connection_is_closed(_session)) { + g_dbus_connection_close_sync(_session, nullptr, nullptr); + } + g_clear_object(&_session); + } + + static void _changed_quit (GMenuModel * model, gint position, gint removed, gint added, GMainLoop * loop) { + g_main_loop_quit(loop); + } + + static gboolean _loop_quit (gpointer user_data) { + g_main_loop_quit((GMainLoop *)user_data); + return G_SOURCE_CONTINUE; } void setMenu (const std::string& path) { + g_clear_object(&_menu); + _menu = G_MENU_MODEL(g_dbus_menu_model_get(_session, _indicatorAddress.c_str(), path.c_str())); + + GMainLoop * temploop = g_main_loop_new(nullptr, FALSE); + + /* Our two exit criteria */ + gulong signal = g_signal_connect(G_OBJECT(_menu), "items-changed", G_CALLBACK(_changed_quit), temploop); + guint timer = g_timeout_add_seconds(1, _loop_quit, temploop); + /* Wait for sync */ + g_main_loop_run(temploop); + + /* Clean up */ + g_source_remove(timer); + g_signal_handler_disconnect(G_OBJECT(_menu), signal); + g_main_loop_unref(temploop); } void expectActionExists (const std::string& name) { @@ -93,7 +131,7 @@ class IndicatorFixture : public ::testing::Test } void expectMenuAttributeRecurse (const std::vector menuLocation, const std::string& attribute, GVariant * value, unsigned int index, GMenuModel * menu) { - ASSERT_LT(menuLocation.size(), index); + ASSERT_LT(index, menuLocation.size()); if (menuLocation.size() - 1 == index) return expectMenuAttributeVerify(menuLocation[index], menu, attribute, value); @@ -109,7 +147,7 @@ class IndicatorFixture : public ::testing::Test void expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, GVariant * value) { g_variant_ref_sink(value); - expectMenuAttributeRecurse(menuLocation, attribute, value, 0, G_MENU_MODEL(_menu)); + expectMenuAttributeRecurse(menuLocation, attribute, value, 0, _menu); g_variant_unref(value); } @@ -123,6 +161,7 @@ class IndicatorFixture : public ::testing::Test expectMenuAttribute(menuLocation, attribute, var); } - }; +#define EXPECT_MENU_ATTRIB(menu, attrib, value) expectMenuAttribute(menu, attrib, value) + diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 9ebb121..72546d6 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -34,5 +34,7 @@ protected: TEST_F(IndicatorTest, StartStop) { + setMenu("/com/canonical/indicator/sound/phone"); + EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); } -- cgit v1.2.3 From b62d0b2dd397ed513565c764a83018507e259790 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 28 Oct 2014 21:19:26 -0500 Subject: Get menus harder --- tests/indicator-fixture.h | 25 +++++++++++++++++++------ tests/indicator-test.cc | 6 ++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 7f42246..eae70b9 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -27,6 +27,7 @@ class IndicatorFixture : public ::testing::Test private: std::string _indicatorPath; std::string _indicatorAddress; + GMainLoop * _loop; GMenuModel * _menu; DbusTestService * _test_service; DbusTestTask * _test_indicator; @@ -40,6 +41,7 @@ class IndicatorFixture : public ::testing::Test const std::string& addr) : _indicatorPath(path) , _indicatorAddress(addr) + , _loop(nullptr) , _menu(nullptr) , _session(nullptr) { @@ -49,6 +51,8 @@ class IndicatorFixture : public ::testing::Test protected: virtual void SetUp() override { + _loop = g_main_loop_new(nullptr, FALSE); + _test_service = dbus_test_service_new(nullptr); _test_indicator = DBUS_TEST_TASK(dbus_test_process_new(_indicatorPath.c_str())); @@ -58,6 +62,10 @@ class IndicatorFixture : public ::testing::Test dbus_test_task_set_wait_for(_test_dummy, _indicatorAddress.c_str()); dbus_test_service_add_task(_test_service, _test_dummy); + DbusTestBustle * bustle = dbus_test_bustle_new("indicator-test.bustle"); + dbus_test_service_add_task(_test_service, DBUS_TEST_TASK(bustle)); + g_object_unref(bustle); + dbus_test_service_start_tasks(_test_service); _session = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); @@ -78,34 +86,39 @@ class IndicatorFixture : public ::testing::Test g_dbus_connection_close_sync(_session, nullptr, nullptr); } g_clear_object(&_session); + + /* Dropping temp loop */ + g_main_loop_unref(_loop); } static void _changed_quit (GMenuModel * model, gint position, gint removed, gint added, GMainLoop * loop) { + g_debug("Got Menus"); g_main_loop_quit(loop); } static gboolean _loop_quit (gpointer user_data) { + g_warning("Menu Timeout"); g_main_loop_quit((GMainLoop *)user_data); return G_SOURCE_CONTINUE; } void setMenu (const std::string& path) { g_clear_object(&_menu); + g_debug("Getting Menu: %s:%s", _indicatorAddress.c_str(), path.c_str()); _menu = G_MENU_MODEL(g_dbus_menu_model_get(_session, _indicatorAddress.c_str(), path.c_str())); - GMainLoop * temploop = g_main_loop_new(nullptr, FALSE); - /* Our two exit criteria */ - gulong signal = g_signal_connect(G_OBJECT(_menu), "items-changed", G_CALLBACK(_changed_quit), temploop); - guint timer = g_timeout_add_seconds(1, _loop_quit, temploop); + gulong signal = g_signal_connect(G_OBJECT(_menu), "items-changed", G_CALLBACK(_changed_quit), _loop); + guint timer = g_timeout_add_seconds(5, _loop_quit, _loop); + + g_menu_model_get_n_items(_menu); /* Wait for sync */ - g_main_loop_run(temploop); + g_main_loop_run(_loop); /* Clean up */ g_source_remove(timer); g_signal_handler_disconnect(G_OBJECT(_menu), signal); - g_main_loop_unref(temploop); } void expectActionExists (const std::string& name) { diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 72546d6..aac8cb0 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -37,4 +37,10 @@ TEST_F(IndicatorTest, StartStop) { setMenu("/com/canonical/indicator/sound/phone"); EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); + EXPECT_MENU_ATTRIB({0}, "x-canonical-type", "com.canonical.indicator.root"); + + // EXPECT_MENU_ATTRIB({0, 0, 0}, "action", "indicator.silent-mode"); + + setMenu("/com/canonical/indicator/sound/desktop"); + EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); } -- cgit v1.2.3 From 5b7a608243729d4f9133fe092b5093ed041ba9ff Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 28 Oct 2014 21:46:59 -0500 Subject: Enforce type and get the right one from our functions --- tests/indicator-fixture.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index eae70b9..7ae3dde 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -138,9 +138,12 @@ class IndicatorFixture : public ::testing::Test if (location >= g_menu_model_get_n_items(menu)) return; - auto menuval = g_menu_model_get_item_attribute_value(menu, location, attribute.c_str(), NULL); - EXPECT_TRUE(g_variant_equal(value, menuval)); - g_variant_unref(menuval); + auto menuval = g_menu_model_get_item_attribute_value(menu, location, attribute.c_str(), g_variant_get_type(value)); + EXPECT_NE(nullptr, menuval); + if (menuval != nullptr) { + EXPECT_TRUE(g_variant_equal(value, menuval)); + g_variant_unref(menuval); + } } void expectMenuAttributeRecurse (const std::vector menuLocation, const std::string& attribute, GVariant * value, unsigned int index, GMenuModel * menu) { @@ -174,6 +177,11 @@ class IndicatorFixture : public ::testing::Test expectMenuAttribute(menuLocation, attribute, var); } + void expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, const char * value) { + GVariant * var = g_variant_new_string(value); + expectMenuAttribute(menuLocation, attribute, var); + } + }; #define EXPECT_MENU_ATTRIB(menu, attrib, value) expectMenuAttribute(menu, attrib, value) -- cgit v1.2.3 From 3821fc9e1b07732fd1796103439b4c95b27a0138 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 29 Oct 2014 09:36:27 -0500 Subject: Make our ref/unrefs dependent on shared pointers --- tests/indicator-fixture.h | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 7ae3dde..99fd7d1 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -17,6 +17,7 @@ * Ted Gould */ +#include #include #include @@ -138,11 +139,14 @@ class IndicatorFixture : public ::testing::Test if (location >= g_menu_model_get_n_items(menu)) return; - auto menuval = g_menu_model_get_item_attribute_value(menu, location, attribute.c_str(), g_variant_get_type(value)); + auto menuval = std::shared_ptr(g_menu_model_get_item_attribute_value(menu, location, attribute.c_str(), g_variant_get_type(value)), [](GVariant * varptr) { + if (varptr != nullptr) + g_variant_unref(varptr); + }); + EXPECT_NE(nullptr, menuval); if (menuval != nullptr) { - EXPECT_TRUE(g_variant_equal(value, menuval)); - g_variant_unref(menuval); + EXPECT_TRUE(g_variant_equal(value, menuval.get())); } } @@ -152,19 +156,24 @@ class IndicatorFixture : public ::testing::Test if (menuLocation.size() - 1 == index) return expectMenuAttributeVerify(menuLocation[index], menu, attribute, value); - auto submenu = g_menu_model_get_item_link(menu, menuLocation[index], G_MENU_LINK_SUBMENU); + auto submenu = std::shared_ptr(g_menu_model_get_item_link(menu, menuLocation[index], G_MENU_LINK_SUBMENU), [](GMenuModel * modelptr) { + g_clear_object(&modelptr); + }); + EXPECT_NE(nullptr, submenu); if (submenu == nullptr) return; - expectMenuAttributeRecurse(menuLocation, attribute, value, index++, submenu); - g_object_unref(submenu); + expectMenuAttributeRecurse(menuLocation, attribute, value, index++, submenu.get()); } void expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, GVariant * value) { - g_variant_ref_sink(value); + auto varref = std::shared_ptr(g_variant_ref_sink(value), [](GVariant * varptr) { + if (varptr != nullptr) + g_variant_unref(varptr); + }); + expectMenuAttributeRecurse(menuLocation, attribute, value, 0, _menu); - g_variant_unref(value); } void expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, bool value) { -- cgit v1.2.3 From 448db5a2eac03cfba26bb6dad61e9929ef824b67 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 4 Nov 2014 16:07:45 -0600 Subject: Flipping around a bit to make it so that we can print out a nice error --- tests/indicator-fixture.h | 111 +++++++++++++++++++++++++++++++++------------- 1 file changed, 79 insertions(+), 32 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 99fd7d1..b8614a6 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -18,6 +18,8 @@ */ #include +#include +#include #include #include @@ -29,7 +31,7 @@ class IndicatorFixture : public ::testing::Test std::string _indicatorPath; std::string _indicatorAddress; GMainLoop * _loop; - GMenuModel * _menu; + std::shared_ptr _menu; DbusTestService * _test_service; DbusTestTask * _test_indicator; DbusTestTask * _test_dummy; @@ -74,8 +76,7 @@ class IndicatorFixture : public ::testing::Test virtual void TearDown() override { - /* Menu structures that could be allocated */ - g_clear_object(&_menu); + _menu.reset(); /* D-Bus Test Stuff */ g_clear_object(&_test_dummy); @@ -104,22 +105,25 @@ class IndicatorFixture : public ::testing::Test } void setMenu (const std::string& path) { - g_clear_object(&_menu); + _menu.reset(); + g_debug("Getting Menu: %s:%s", _indicatorAddress.c_str(), path.c_str()); - _menu = G_MENU_MODEL(g_dbus_menu_model_get(_session, _indicatorAddress.c_str(), path.c_str())); + _menu = std::shared_ptr(G_MENU_MODEL(g_dbus_menu_model_get(_session, _indicatorAddress.c_str(), path.c_str())), [](GMenuModel * modelptr) { + g_clear_object(&modelptr); + }); /* Our two exit criteria */ - gulong signal = g_signal_connect(G_OBJECT(_menu), "items-changed", G_CALLBACK(_changed_quit), _loop); + gulong signal = g_signal_connect(G_OBJECT(_menu.get()), "items-changed", G_CALLBACK(_changed_quit), _loop); guint timer = g_timeout_add_seconds(5, _loop_quit, _loop); - g_menu_model_get_n_items(_menu); + g_menu_model_get_n_items(_menu.get()); /* Wait for sync */ g_main_loop_run(_loop); /* Clean up */ g_source_remove(timer); - g_signal_handler_disconnect(G_OBJECT(_menu), signal); + g_signal_handler_disconnect(G_OBJECT(_menu.get()), signal); } void expectActionExists (const std::string& name) { @@ -134,64 +138,107 @@ class IndicatorFixture : public ::testing::Test } - void expectMenuAttributeVerify (int location, GMenuModel * menu, const std::string& attribute, GVariant * value) { - EXPECT_LT(location, g_menu_model_get_n_items(menu)); - if (location >= g_menu_model_get_n_items(menu)) - return; + std::shared_ptr getMenuAttributeVal (int location, std::shared_ptr& menu, const std::string& attribute, std::shared_ptr& value) { + if (!(location < g_menu_model_get_n_items(menu.get()))) { + return nullptr; + } + + if (location >= g_menu_model_get_n_items(menu.get())) + return nullptr; - auto menuval = std::shared_ptr(g_menu_model_get_item_attribute_value(menu, location, attribute.c_str(), g_variant_get_type(value)), [](GVariant * varptr) { + auto menuval = std::shared_ptr(g_menu_model_get_item_attribute_value(menu.get(), location, attribute.c_str(), g_variant_get_type(value.get())), [](GVariant * varptr) { if (varptr != nullptr) g_variant_unref(varptr); }); - EXPECT_NE(nullptr, menuval); - if (menuval != nullptr) { - EXPECT_TRUE(g_variant_equal(value, menuval.get())); - } + return menuval; } - void expectMenuAttributeRecurse (const std::vector menuLocation, const std::string& attribute, GVariant * value, unsigned int index, GMenuModel * menu) { - ASSERT_LT(index, menuLocation.size()); + std::shared_ptr getMenuAttributeRecurse (const std::vector menuLocation, const std::string& attribute, std::shared_ptr& value, unsigned int index, std::shared_ptr& menu) { + if (index >= menuLocation.size()) + return nullptr; if (menuLocation.size() - 1 == index) - return expectMenuAttributeVerify(menuLocation[index], menu, attribute, value); + return getMenuAttributeVal(menuLocation[index], menu, attribute, value); - auto submenu = std::shared_ptr(g_menu_model_get_item_link(menu, menuLocation[index], G_MENU_LINK_SUBMENU), [](GMenuModel * modelptr) { + auto submenu = std::shared_ptr(g_menu_model_get_item_link(menu.get(), menuLocation[index], G_MENU_LINK_SUBMENU), [](GMenuModel * modelptr) { g_clear_object(&modelptr); }); - EXPECT_NE(nullptr, submenu); if (submenu == nullptr) - return; + return nullptr; - expectMenuAttributeRecurse(menuLocation, attribute, value, index++, submenu.get()); + return getMenuAttributeRecurse(menuLocation, attribute, value, index++, submenu); } - void expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, GVariant * value) { + bool expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, GVariant * value) { auto varref = std::shared_ptr(g_variant_ref_sink(value), [](GVariant * varptr) { if (varptr != nullptr) g_variant_unref(varptr); }); - expectMenuAttributeRecurse(menuLocation, attribute, value, 0, _menu); + auto attrib = getMenuAttributeRecurse(menuLocation, attribute, varref, 0, _menu); + bool same = false; + + if (attrib != nullptr && varref != nullptr) { + same = g_variant_equal(attrib.get(), varref.get()); + } + + if (!same) { + gchar * valstr = nullptr; + gchar * attstr = nullptr; + + if (attrib != nullptr) { + attstr = g_variant_print(attrib.get(), TRUE); + } else { + attstr = g_strdup("nullptr"); + } + + if (varref != nullptr) { + valstr = g_variant_print(varref.get(), TRUE); + } else { + valstr = g_strdup("nullptr"); + } + + std::string menuprint("{ "); + std::for_each(menuLocation.begin(), menuLocation.end(), [&menuprint](int i) { + menuprint.append(std::to_string(i)); + menuprint.append(", "); + }); + menuprint += "}"; + + std::cout << + " Menu: " << menuprint << std::endl << + " Attribute: " << attribute << std::endl << + " Expected: " << valstr << std::endl << + " Actual: " << attstr << std::endl; + + g_free(valstr); + g_free(attstr); + } + + return same; } - void expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, bool value) { + bool expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, bool value) { GVariant * var = g_variant_new_boolean(value); - expectMenuAttribute(menuLocation, attribute, var); + return expectMenuAttribute(menuLocation, attribute, var); } - void expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, std::string value) { + bool expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, std::string value) { GVariant * var = g_variant_new_string(value.c_str()); - expectMenuAttribute(menuLocation, attribute, var); + return expectMenuAttribute(menuLocation, attribute, var); } - void expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, const char * value) { + bool expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, const char * value) { GVariant * var = g_variant_new_string(value); - expectMenuAttribute(menuLocation, attribute, var); + return expectMenuAttribute(menuLocation, attribute, var); } }; #define EXPECT_MENU_ATTRIB(menu, attrib, value) expectMenuAttribute(menu, attrib, value) +#define ASSERT_MENU_ATTRIB(menu, attrib, value) \ + if (!expectMenuAttribute(menu, attrib, value)) \ + return; -- cgit v1.2.3 From 8df46f8e642e28a696f12953641f9cfaf1f739a7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 4 Nov 2014 16:21:59 -0600 Subject: Adjusting to use iterators --- tests/indicator-fixture.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index b8614a6..4f08ab5 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -154,21 +154,21 @@ class IndicatorFixture : public ::testing::Test return menuval; } - std::shared_ptr getMenuAttributeRecurse (const std::vector menuLocation, const std::string& attribute, std::shared_ptr& value, unsigned int index, std::shared_ptr& menu) { - if (index >= menuLocation.size()) + std::shared_ptr getMenuAttributeRecurse (std::vector::const_iterator menuLocation, std::vector::const_iterator menuEnd, const std::string& attribute, std::shared_ptr& value, std::shared_ptr& menu) { + if (menuLocation == menuEnd) return nullptr; - if (menuLocation.size() - 1 == index) - return getMenuAttributeVal(menuLocation[index], menu, attribute, value); + if (menuLocation + 1 == menuEnd) + return getMenuAttributeVal(*menuLocation, menu, attribute, value); - auto submenu = std::shared_ptr(g_menu_model_get_item_link(menu.get(), menuLocation[index], G_MENU_LINK_SUBMENU), [](GMenuModel * modelptr) { + auto submenu = std::shared_ptr(g_menu_model_get_item_link(menu.get(), *menuLocation, G_MENU_LINK_SUBMENU), [](GMenuModel * modelptr) { g_clear_object(&modelptr); }); if (submenu == nullptr) return nullptr; - return getMenuAttributeRecurse(menuLocation, attribute, value, index++, submenu); + return getMenuAttributeRecurse(menuLocation + 1, menuEnd, attribute, value, submenu); } bool expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, GVariant * value) { @@ -177,7 +177,7 @@ class IndicatorFixture : public ::testing::Test g_variant_unref(varptr); }); - auto attrib = getMenuAttributeRecurse(menuLocation, attribute, varref, 0, _menu); + auto attrib = getMenuAttributeRecurse(menuLocation.cbegin(), menuLocation.cend(), attribute, varref, _menu); bool same = false; if (attrib != nullptr && varref != nullptr) { -- cgit v1.2.3 From 83f9f8e86cf85e7141cfc952ebff10714dcfe870 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 4 Nov 2014 16:47:35 -0600 Subject: Clean up the output a little bit --- tests/indicator-fixture.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 4f08ab5..2dcefa1 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -59,15 +59,20 @@ class IndicatorFixture : public ::testing::Test _test_service = dbus_test_service_new(nullptr); _test_indicator = DBUS_TEST_TASK(dbus_test_process_new(_indicatorPath.c_str())); + dbus_test_task_set_name(_test_indicator, "Indicator"); dbus_test_service_add_task(_test_service, _test_indicator); _test_dummy = dbus_test_task_new(); dbus_test_task_set_wait_for(_test_dummy, _indicatorAddress.c_str()); + dbus_test_task_set_name(_test_dummy, "Dummy"); dbus_test_service_add_task(_test_service, _test_dummy); - DbusTestBustle * bustle = dbus_test_bustle_new("indicator-test.bustle"); - dbus_test_service_add_task(_test_service, DBUS_TEST_TASK(bustle)); - g_object_unref(bustle); + if (true) { + DbusTestBustle * bustle = dbus_test_bustle_new("indicator-test.bustle"); + dbus_test_task_set_name(DBUS_TEST_TASK(bustle), "Bustle"); + dbus_test_service_add_task(_test_service, DBUS_TEST_TASK(bustle)); + g_object_unref(bustle); + } dbus_test_service_start_tasks(_test_service); -- cgit v1.2.3 From 1d95d42ff323a98d5f88f2897c93978511eaee46 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 4 Nov 2014 18:15:20 -0600 Subject: Lock out some functions --- tests/indicator-fixture.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 2dcefa1..75ad0f6 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -98,6 +98,7 @@ class IndicatorFixture : public ::testing::Test g_main_loop_unref(_loop); } + private: static void _changed_quit (GMenuModel * model, gint position, gint removed, gint added, GMainLoop * loop) { g_debug("Got Menus"); g_main_loop_quit(loop); @@ -109,6 +110,7 @@ class IndicatorFixture : public ::testing::Test return G_SOURCE_CONTINUE; } + protected: void setMenu (const std::string& path) { _menu.reset(); @@ -143,6 +145,7 @@ class IndicatorFixture : public ::testing::Test } + private: std::shared_ptr getMenuAttributeVal (int location, std::shared_ptr& menu, const std::string& attribute, std::shared_ptr& value) { if (!(location < g_menu_model_get_n_items(menu.get()))) { return nullptr; @@ -173,9 +176,12 @@ class IndicatorFixture : public ::testing::Test if (submenu == nullptr) return nullptr; + g_menu_model_get_n_items(submenu.get()); + return getMenuAttributeRecurse(menuLocation + 1, menuEnd, attribute, value, submenu); } + protected: bool expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, GVariant * value) { auto varref = std::shared_ptr(g_variant_ref_sink(value), [](GVariant * varptr) { if (varptr != nullptr) -- cgit v1.2.3 From c4530fde870f6c7838d3d5dee2a63a885d8f896a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 4 Nov 2014 18:21:05 -0600 Subject: Pulling out waiting for items into a helper function --- tests/indicator-fixture.h | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 75ad0f6..f2039f7 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -30,7 +30,6 @@ class IndicatorFixture : public ::testing::Test private: std::string _indicatorPath; std::string _indicatorAddress; - GMainLoop * _loop; std::shared_ptr _menu; DbusTestService * _test_service; DbusTestTask * _test_indicator; @@ -44,7 +43,6 @@ class IndicatorFixture : public ::testing::Test const std::string& addr) : _indicatorPath(path) , _indicatorAddress(addr) - , _loop(nullptr) , _menu(nullptr) , _session(nullptr) { @@ -54,7 +52,6 @@ class IndicatorFixture : public ::testing::Test protected: virtual void SetUp() override { - _loop = g_main_loop_new(nullptr, FALSE); _test_service = dbus_test_service_new(nullptr); @@ -93,9 +90,6 @@ class IndicatorFixture : public ::testing::Test g_dbus_connection_close_sync(_session, nullptr, nullptr); } g_clear_object(&_session); - - /* Dropping temp loop */ - g_main_loop_unref(_loop); } private: @@ -110,27 +104,40 @@ class IndicatorFixture : public ::testing::Test return G_SOURCE_CONTINUE; } - protected: - void setMenu (const std::string& path) { - _menu.reset(); + void menuWaitForItems (const std::shared_ptr& menu) { + auto count = g_menu_model_get_n_items(menu.get()); + + if (count != 0) + return; - g_debug("Getting Menu: %s:%s", _indicatorAddress.c_str(), path.c_str()); - _menu = std::shared_ptr(G_MENU_MODEL(g_dbus_menu_model_get(_session, _indicatorAddress.c_str(), path.c_str())), [](GMenuModel * modelptr) { - g_clear_object(&modelptr); - }); + auto loop = g_main_loop_new(nullptr, FALSE); /* Our two exit criteria */ - gulong signal = g_signal_connect(G_OBJECT(_menu.get()), "items-changed", G_CALLBACK(_changed_quit), _loop); - guint timer = g_timeout_add_seconds(5, _loop_quit, _loop); + gulong signal = g_signal_connect(G_OBJECT(menu.get()), "items-changed", G_CALLBACK(_changed_quit), loop); + guint timer = g_timeout_add_seconds(5, _loop_quit, loop); - g_menu_model_get_n_items(_menu.get()); + g_menu_model_get_n_items(menu.get()); /* Wait for sync */ - g_main_loop_run(_loop); + g_main_loop_run(loop); /* Clean up */ g_source_remove(timer); - g_signal_handler_disconnect(G_OBJECT(_menu.get()), signal); + g_signal_handler_disconnect(G_OBJECT(menu.get()), signal); + + g_main_loop_unref(loop); + } + + protected: + void setMenu (const std::string& path) { + _menu.reset(); + + g_debug("Getting Menu: %s:%s", _indicatorAddress.c_str(), path.c_str()); + _menu = std::shared_ptr(G_MENU_MODEL(g_dbus_menu_model_get(_session, _indicatorAddress.c_str(), path.c_str())), [](GMenuModel * modelptr) { + g_clear_object(&modelptr); + }); + + menuWaitForItems(_menu); } void expectActionExists (const std::string& name) { @@ -176,7 +183,7 @@ class IndicatorFixture : public ::testing::Test if (submenu == nullptr) return nullptr; - g_menu_model_get_n_items(submenu.get()); + menuWaitForItems(submenu); return getMenuAttributeRecurse(menuLocation + 1, menuEnd, attribute, value, submenu); } -- cgit v1.2.3 From d40397906cb1e04cb225598ae0faacb8019ebf90 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 4 Nov 2014 18:27:35 -0600 Subject: Parse through sections as well --- tests/indicator-fixture.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index f2039f7..4b510a0 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -176,9 +176,14 @@ class IndicatorFixture : public ::testing::Test if (menuLocation + 1 == menuEnd) return getMenuAttributeVal(*menuLocation, menu, attribute, value); - auto submenu = std::shared_ptr(g_menu_model_get_item_link(menu.get(), *menuLocation, G_MENU_LINK_SUBMENU), [](GMenuModel * modelptr) { + auto clearfunc = [](GMenuModel * modelptr) { g_clear_object(&modelptr); - }); + }; + + auto submenu = std::shared_ptr(g_menu_model_get_item_link(menu.get(), *menuLocation, G_MENU_LINK_SUBMENU), clearfunc); + + if (submenu == nullptr) + submenu = std::shared_ptr(g_menu_model_get_item_link(menu.get(), *menuLocation, G_MENU_LINK_SECTION), clearfunc); if (submenu == nullptr) return nullptr; -- cgit v1.2.3 From 210837e348e2e154dcd28d2f170f8291a18b3c71 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 4 Nov 2014 18:28:06 -0600 Subject: Add a test that goes further down the tree --- tests/indicator-test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index aac8cb0..6bc16cb 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -39,7 +39,7 @@ TEST_F(IndicatorTest, StartStop) { EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); EXPECT_MENU_ATTRIB({0}, "x-canonical-type", "com.canonical.indicator.root"); - // EXPECT_MENU_ATTRIB({0, 0, 0}, "action", "indicator.silent-mode"); + expectMenuAttribute({0, 0, 0}, "action", "indicator.silent-mode"); setMenu("/com/canonical/indicator/sound/desktop"); EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); -- cgit v1.2.3 From 5d1c2bc58614939a64a5d023f3b86d59fd8fb2a8 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 4 Nov 2014 18:30:19 -0600 Subject: Dividing up the tests to make them look nice --- tests/indicator-test.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 6bc16cb..fd2819e 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -33,14 +33,17 @@ protected: }; -TEST_F(IndicatorTest, StartStop) { +TEST_F(IndicatorTest, PhoneMenu) { setMenu("/com/canonical/indicator/sound/phone"); EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); EXPECT_MENU_ATTRIB({0}, "x-canonical-type", "com.canonical.indicator.root"); expectMenuAttribute({0, 0, 0}, "action", "indicator.silent-mode"); +} +TEST_F(IndicatorTest, DesktopMenu) { setMenu("/com/canonical/indicator/sound/desktop"); + EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); } -- cgit v1.2.3 From 730b3c7005e53e7f76db15b39499b62ccd4c49d2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 4 Nov 2014 18:53:39 -0600 Subject: Setup actions to get the action groups --- tests/indicator-fixture.h | 60 +++++++++++++++++++++++++++++++++++------------ tests/indicator-test.cc | 6 +++++ 2 files changed, 51 insertions(+), 15 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 4b510a0..063a966 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -25,12 +25,23 @@ #include #include +extern "C" { + +/* Super useful function that GLib has hidden from us :-( */ +gboolean +g_dbus_action_group_sync (GDBusActionGroup *group, + GCancellable *cancellable, + GError **error); + +} + class IndicatorFixture : public ::testing::Test { private: std::string _indicatorPath; std::string _indicatorAddress; std::shared_ptr _menu; + std::shared_ptr _actions; DbusTestService * _test_service; DbusTestTask * _test_indicator; DbusTestTask * _test_dummy; @@ -79,6 +90,7 @@ class IndicatorFixture : public ::testing::Test virtual void TearDown() override { _menu.reset(); + _actions.reset(); /* D-Bus Test Stuff */ g_clear_object(&_test_dummy); @@ -93,41 +105,49 @@ class IndicatorFixture : public ::testing::Test } private: - static void _changed_quit (GMenuModel * model, gint position, gint removed, gint added, GMainLoop * loop) { - g_debug("Got Menus"); - g_main_loop_quit(loop); - } - static gboolean _loop_quit (gpointer user_data) { g_warning("Menu Timeout"); g_main_loop_quit((GMainLoop *)user_data); return G_SOURCE_CONTINUE; } - void menuWaitForItems (const std::shared_ptr& menu) { - auto count = g_menu_model_get_n_items(menu.get()); - - if (count != 0) - return; - + void waitForCore (GObject * obj, const gchar * signalname) { auto loop = g_main_loop_new(nullptr, FALSE); /* Our two exit criteria */ - gulong signal = g_signal_connect(G_OBJECT(menu.get()), "items-changed", G_CALLBACK(_changed_quit), loop); + gulong signal = g_signal_connect_swapped(obj, signalname, G_CALLBACK(g_main_loop_quit), loop); guint timer = g_timeout_add_seconds(5, _loop_quit, loop); - g_menu_model_get_n_items(menu.get()); - /* Wait for sync */ g_main_loop_run(loop); /* Clean up */ g_source_remove(timer); - g_signal_handler_disconnect(G_OBJECT(menu.get()), signal); + g_signal_handler_disconnect(obj, signal); g_main_loop_unref(loop); } + void menuWaitForItems (const std::shared_ptr& menu) { + auto count = g_menu_model_get_n_items(menu.get()); + + if (count != 0) + return; + + waitForCore(G_OBJECT(menu.get()), "items-changed"); + } + + void agWaitForActions (const std::shared_ptr& group) { + auto list = g_action_group_list_actions(group.get()); + + if (list != nullptr) { + g_strfreev(list); + return; + } + + waitForCore(G_OBJECT(group.get()), "action-added"); + } + protected: void setMenu (const std::string& path) { _menu.reset(); @@ -140,6 +160,16 @@ class IndicatorFixture : public ::testing::Test menuWaitForItems(_menu); } + void setActions (const std::string& path) { + _actions.reset(); + + _actions = std::shared_ptr(G_ACTION_GROUP(g_dbus_action_group_get(_session, _indicatorAddress.c_str(), path.c_str())), [](GActionGroup * groupptr) { + g_clear_object(&groupptr); + }); + + agWaitForActions(_actions); + } + void expectActionExists (const std::string& name) { } diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index fd2819e..c919e31 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -47,3 +47,9 @@ TEST_F(IndicatorTest, DesktopMenu) { EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); } + +TEST_F(IndicatorTest, SilentActions) { + setActions("/com/canonical/indicator/sound"); + + expectActionExists("indicator.root"); +} -- cgit v1.2.3 From ad16588f7734f0086d8cfa8ee10aaaa4961de23d Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 4 Nov 2014 20:40:11 -0600 Subject: Making the timer callback anonymous --- tests/indicator-fixture.h | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 063a966..6b3963a 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -105,18 +105,16 @@ class IndicatorFixture : public ::testing::Test } private: - static gboolean _loop_quit (gpointer user_data) { - g_warning("Menu Timeout"); - g_main_loop_quit((GMainLoop *)user_data); - return G_SOURCE_CONTINUE; - } - void waitForCore (GObject * obj, const gchar * signalname) { auto loop = g_main_loop_new(nullptr, FALSE); /* Our two exit criteria */ gulong signal = g_signal_connect_swapped(obj, signalname, G_CALLBACK(g_main_loop_quit), loop); - guint timer = g_timeout_add_seconds(5, _loop_quit, loop); + guint timer = g_timeout_add_seconds(5, [](gpointer user_data) -> gboolean { + g_warning("Menu Timeout"); + g_main_loop_quit((GMainLoop *)user_data); + return G_SOURCE_CONTINUE; + }, loop); /* Wait for sync */ g_main_loop_run(loop); -- cgit v1.2.3 From 629fb9872de0626e957489b177f36e025f996abe Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 5 Nov 2014 09:29:40 -0600 Subject: Flesh out the action functions --- tests/indicator-fixture.h | 84 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 3 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 6b3963a..02dd885 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -168,18 +168,96 @@ class IndicatorFixture : public ::testing::Test agWaitForActions(_actions); } - void expectActionExists (const std::string& name) { + bool expectActionExists (const std::string& name) { + bool hasit = g_action_group_has_action(_actions.get(), name.c_str()); + if (!hasit) { + std::cout << + " Action: " << name << std::endl << + " Expected: " << "Exists" << std::endl << + " Actual: " << "No action found" << std::endl; + } + + return hasit; } - void expectActionStateType (const std::string& name, const GVariantType * type) { + bool expectActionStateType (const std::string& name, const GVariantType * type) { + auto atype = g_action_group_get_action_state_type(_actions.get(), name.c_str()); + bool same = false; + if (atype != nullptr) { + same = g_variant_type_equal(atype, type); + } + + if (!same) { + std::cout << + " Action: " << name << std::endl << + " Expected: " << g_variant_type_peek_string(type) << std::endl << + " Actual: " << g_variant_type_peek_string(atype) << std::endl; + } + + return same; } - void expectActionStateIs (const std::string& name, const GVariant * value) { + bool expectActionStateIs (const std::string& name, GVariant * value) { + auto varref = std::shared_ptr(g_variant_ref_sink(value), [](GVariant * varptr) { + if (varptr != nullptr) + g_variant_unref(varptr); + }); + auto aval = std::shared_ptr(g_action_group_get_action_state(_actions.get(), name.c_str()), [] (GVariant * varptr) { + if (varptr != nullptr) + g_variant_unref(varptr); + }); + bool match = false; + + if (aval != nullptr) { + match = g_variant_equal(aval.get(), varref.get()); + } + if (!match) { + gchar * valstr = nullptr; + gchar * attstr = nullptr; + + if (aval != nullptr) { + attstr = g_variant_print(aval.get(), TRUE); + } else { + attstr = g_strdup("nullptr"); + } + + if (varref != nullptr) { + valstr = g_variant_print(varref.get(), TRUE); + } else { + valstr = g_strdup("nullptr"); + } + + std::cout << + " Action: " << name << std::endl << + " Expected: " << valstr << std::endl << + " Actual: " << attstr << std::endl; + + g_free(valstr); + g_free(attstr); + } + + return match; + } + + bool expectActionStateIs (const std::string& name, bool value) { + GVariant * var = g_variant_new_boolean(value); + return expectActionStateIs(name, var); + } + + bool expectActionStateIs (const std::string& name, std::string value) { + GVariant * var = g_variant_new_string(value.c_str()); + return expectActionStateIs(name, var); + } + + bool expectActionStateIs (const std::string& name, const char * value) { + GVariant * var = g_variant_new_string(value); + return expectActionStateIs(name, var); } + private: std::shared_ptr getMenuAttributeVal (int location, std::shared_ptr& menu, const std::string& attribute, std::shared_ptr& value) { if (!(location < g_menu_model_get_n_items(menu.get()))) { -- cgit v1.2.3 From 292c19d6e75ee4fa83b71cea3820d0efa6ecc5b0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 5 Nov 2014 10:59:25 -0600 Subject: Fix waiting on actions to count the number of actions --- tests/indicator-fixture.h | 9 ++++++--- tests/indicator-test.cc | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 02dd885..987c7b7 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -136,10 +136,13 @@ class IndicatorFixture : public ::testing::Test } void agWaitForActions (const std::shared_ptr& group) { - auto list = g_action_group_list_actions(group.get()); + auto list = std::shared_ptr( + g_action_group_list_actions(group.get()), + [](gchar ** list) { + g_strfreev(list); + }); - if (list != nullptr) { - g_strfreev(list); + if (g_strv_length(list.get()) != 0) { return; } diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index c919e31..7d122ee 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -51,5 +51,5 @@ TEST_F(IndicatorTest, DesktopMenu) { TEST_F(IndicatorTest, SilentActions) { setActions("/com/canonical/indicator/sound"); - expectActionExists("indicator.root"); + expectActionExists("root"); } -- cgit v1.2.3 From c68f6432e5d53cbe6770da889f5a92c791977a67 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 5 Nov 2014 16:27:14 -0600 Subject: Some more action tests --- tests/indicator-fixture.h | 10 ++++++++++ tests/indicator-test.cc | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 987c7b7..67cacf3 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -260,6 +260,16 @@ class IndicatorFixture : public ::testing::Test return expectActionStateIs(name, var); } + bool expectActionStateIs (const std::string& name, double value) { + GVariant * var = g_variant_new_double(value); + return expectActionStateIs(name, var); + } + + bool expectActionStateIs (const std::string& name, float value) { + GVariant * var = g_variant_new_double(value); + return expectActionStateIs(name, var); + } + private: std::shared_ptr getMenuAttributeVal (int location, std::shared_ptr& menu, const std::string& attribute, std::shared_ptr& value) { diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 7d122ee..47a95f3 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -51,5 +51,11 @@ TEST_F(IndicatorTest, DesktopMenu) { TEST_F(IndicatorTest, SilentActions) { setActions("/com/canonical/indicator/sound"); - expectActionExists("root"); + expectActionExists("scroll"); + + expectActionExists("silent-mode"); + expectActionStateIs("silent-mode", false); + + expectActionExists("mute"); + expectActionStateIs("mute", false); } -- cgit v1.2.3 From 9de0d60aee6e92700650ecd843345dd4964fbb06 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 6 Nov 2014 09:14:51 -0600 Subject: Make the lifecycle of the items in the run more clear --- tests/indicator-fixture.h | 130 ++++++++++++++++++++++++---------------------- 1 file changed, 67 insertions(+), 63 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 67cacf3..74dc0b4 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -25,27 +25,66 @@ #include #include -extern "C" { - -/* Super useful function that GLib has hidden from us :-( */ -gboolean -g_dbus_action_group_sync (GDBusActionGroup *group, - GCancellable *cancellable, - GError **error); - -} - class IndicatorFixture : public ::testing::Test { private: std::string _indicatorPath; std::string _indicatorAddress; - std::shared_ptr _menu; - std::shared_ptr _actions; - DbusTestService * _test_service; - DbusTestTask * _test_indicator; - DbusTestTask * _test_dummy; - GDBusConnection * _session; + + class PerRunData { + public: /* We're private in the fixture but other than that we don't care, we don't leak out */ + std::shared_ptr _menu; + std::shared_ptr _actions; + DbusTestService * _test_service; + DbusTestTask * _test_indicator; + DbusTestTask * _test_dummy; + GDBusConnection * _session; + + PerRunData (const std::string& indicatorPath, const std::string& indicatorAddress) + : _menu(nullptr) + , _session(nullptr) + { + _test_service = dbus_test_service_new(nullptr); + + _test_indicator = DBUS_TEST_TASK(dbus_test_process_new(indicatorPath.c_str())); + dbus_test_task_set_name(_test_indicator, "Indicator"); + dbus_test_service_add_task(_test_service, _test_indicator); + + _test_dummy = dbus_test_task_new(); + dbus_test_task_set_wait_for(_test_dummy, indicatorAddress.c_str()); + dbus_test_task_set_name(_test_dummy, "Dummy"); + dbus_test_service_add_task(_test_service, _test_dummy); + + if (true) { + DbusTestBustle * bustle = dbus_test_bustle_new("indicator-test.bustle"); + dbus_test_task_set_name(DBUS_TEST_TASK(bustle), "Bustle"); + dbus_test_service_add_task(_test_service, DBUS_TEST_TASK(bustle)); + g_object_unref(bustle); + } + + dbus_test_service_start_tasks(_test_service); + + _session = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); + } + + virtual ~PerRunData (void) { + _menu.reset(); + _actions.reset(); + + /* D-Bus Test Stuff */ + g_clear_object(&_test_dummy); + g_clear_object(&_test_indicator); + g_clear_object(&_test_service); + + /* Wait for D-Bus session bus to go */ + if (!g_dbus_connection_is_closed(_session)) { + g_dbus_connection_close_sync(_session, nullptr, nullptr); + } + g_clear_object(&_session); + } + }; + + std::shared_ptr run; public: virtual ~IndicatorFixture() = default; @@ -54,8 +93,6 @@ class IndicatorFixture : public ::testing::Test const std::string& addr) : _indicatorPath(path) , _indicatorAddress(addr) - , _menu(nullptr) - , _session(nullptr) { }; @@ -63,45 +100,12 @@ class IndicatorFixture : public ::testing::Test protected: virtual void SetUp() override { - - _test_service = dbus_test_service_new(nullptr); - - _test_indicator = DBUS_TEST_TASK(dbus_test_process_new(_indicatorPath.c_str())); - dbus_test_task_set_name(_test_indicator, "Indicator"); - dbus_test_service_add_task(_test_service, _test_indicator); - - _test_dummy = dbus_test_task_new(); - dbus_test_task_set_wait_for(_test_dummy, _indicatorAddress.c_str()); - dbus_test_task_set_name(_test_dummy, "Dummy"); - dbus_test_service_add_task(_test_service, _test_dummy); - - if (true) { - DbusTestBustle * bustle = dbus_test_bustle_new("indicator-test.bustle"); - dbus_test_task_set_name(DBUS_TEST_TASK(bustle), "Bustle"); - dbus_test_service_add_task(_test_service, DBUS_TEST_TASK(bustle)); - g_object_unref(bustle); - } - - dbus_test_service_start_tasks(_test_service); - - _session = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); + run = std::make_shared(_indicatorPath, _indicatorAddress); } virtual void TearDown() override { - _menu.reset(); - _actions.reset(); - - /* D-Bus Test Stuff */ - g_clear_object(&_test_dummy); - g_clear_object(&_test_indicator); - g_clear_object(&_test_service); - - /* Wait for D-Bus session bus to go */ - if (!g_dbus_connection_is_closed(_session)) { - g_dbus_connection_close_sync(_session, nullptr, nullptr); - } - g_clear_object(&_session); + run.reset(); } private: @@ -151,28 +155,28 @@ class IndicatorFixture : public ::testing::Test protected: void setMenu (const std::string& path) { - _menu.reset(); + run->_menu.reset(); g_debug("Getting Menu: %s:%s", _indicatorAddress.c_str(), path.c_str()); - _menu = std::shared_ptr(G_MENU_MODEL(g_dbus_menu_model_get(_session, _indicatorAddress.c_str(), path.c_str())), [](GMenuModel * modelptr) { + run->_menu = std::shared_ptr(G_MENU_MODEL(g_dbus_menu_model_get(run->_session, _indicatorAddress.c_str(), path.c_str())), [](GMenuModel * modelptr) { g_clear_object(&modelptr); }); - menuWaitForItems(_menu); + menuWaitForItems(run->_menu); } void setActions (const std::string& path) { - _actions.reset(); + run->_actions.reset(); - _actions = std::shared_ptr(G_ACTION_GROUP(g_dbus_action_group_get(_session, _indicatorAddress.c_str(), path.c_str())), [](GActionGroup * groupptr) { + run->_actions = std::shared_ptr(G_ACTION_GROUP(g_dbus_action_group_get(run->_session, _indicatorAddress.c_str(), path.c_str())), [](GActionGroup * groupptr) { g_clear_object(&groupptr); }); - agWaitForActions(_actions); + agWaitForActions(run->_actions); } bool expectActionExists (const std::string& name) { - bool hasit = g_action_group_has_action(_actions.get(), name.c_str()); + bool hasit = g_action_group_has_action(run->_actions.get(), name.c_str()); if (!hasit) { std::cout << @@ -185,7 +189,7 @@ class IndicatorFixture : public ::testing::Test } bool expectActionStateType (const std::string& name, const GVariantType * type) { - auto atype = g_action_group_get_action_state_type(_actions.get(), name.c_str()); + auto atype = g_action_group_get_action_state_type(run->_actions.get(), name.c_str()); bool same = false; if (atype != nullptr) { @@ -207,7 +211,7 @@ class IndicatorFixture : public ::testing::Test if (varptr != nullptr) g_variant_unref(varptr); }); - auto aval = std::shared_ptr(g_action_group_get_action_state(_actions.get(), name.c_str()), [] (GVariant * varptr) { + auto aval = std::shared_ptr(g_action_group_get_action_state(run->_actions.get(), name.c_str()), [] (GVariant * varptr) { if (varptr != nullptr) g_variant_unref(varptr); }); @@ -319,7 +323,7 @@ class IndicatorFixture : public ::testing::Test g_variant_unref(varptr); }); - auto attrib = getMenuAttributeRecurse(menuLocation.cbegin(), menuLocation.cend(), attribute, varref, _menu); + auto attrib = getMenuAttributeRecurse(menuLocation.cbegin(), menuLocation.cend(), attribute, varref, run->_menu); bool same = false; if (attrib != nullptr && varref != nullptr) { -- cgit v1.2.3 From f4e23c3e41558406a2b9bb724dc533bb217410da Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 6 Nov 2014 09:39:56 -0600 Subject: Shuffling around so that we can add additional mocks easily --- tests/indicator-fixture.h | 37 ++++++++++++++++++++++++++++--------- tests/indicator-test.cc | 8 ++++++++ 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 74dc0b4..0c07159 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -30,9 +30,13 @@ class IndicatorFixture : public ::testing::Test private: std::string _indicatorPath; std::string _indicatorAddress; + std::vector> _mocks; class PerRunData { - public: /* We're private in the fixture but other than that we don't care, we don't leak out */ + public: + /* We're private in the fixture but other than that we don't care, + we don't leak out. This object's purpose isn't to hide data it is + to make the lifecycle of the items more clear. */ std::shared_ptr _menu; std::shared_ptr _actions; DbusTestService * _test_service; @@ -40,7 +44,7 @@ class IndicatorFixture : public ::testing::Test DbusTestTask * _test_dummy; GDBusConnection * _session; - PerRunData (const std::string& indicatorPath, const std::string& indicatorAddress) + PerRunData (const std::string& indicatorPath, const std::string& indicatorAddress, std::vector>& mocks) : _menu(nullptr) , _session(nullptr) { @@ -55,12 +59,9 @@ class IndicatorFixture : public ::testing::Test dbus_test_task_set_name(_test_dummy, "Dummy"); dbus_test_service_add_task(_test_service, _test_dummy); - if (true) { - DbusTestBustle * bustle = dbus_test_bustle_new("indicator-test.bustle"); - dbus_test_task_set_name(DBUS_TEST_TASK(bustle), "Bustle"); - dbus_test_service_add_task(_test_service, DBUS_TEST_TASK(bustle)); - g_object_unref(bustle); - } + std::for_each(mocks.begin(), mocks.end(), [this](std::shared_ptr task) { + dbus_test_service_add_task(_test_service, task.get()); + }); dbus_test_service_start_tasks(_test_service); @@ -100,7 +101,9 @@ class IndicatorFixture : public ::testing::Test protected: virtual void SetUp() override { - run = std::make_shared(_indicatorPath, _indicatorAddress); + run = std::make_shared(_indicatorPath, _indicatorAddress, _mocks); + + _mocks.clear(); } virtual void TearDown() override @@ -108,6 +111,22 @@ class IndicatorFixture : public ::testing::Test run.reset(); } + void addMock (std::shared_ptr& mock) + { + _mocks.push_back(mock); + } + + std::shared_ptr buildBustleMock (const std::string& filename) + { + return std::shared_ptr([filename]() { + DbusTestTask * bustle = DBUS_TEST_TASK(dbus_test_bustle_new(filename.c_str())); + dbus_test_task_set_name(bustle, "Bustle"); + return bustle; + }(), [](DbusTestTask * bustle) { + g_clear_object(&bustle); + }); + } + private: void waitForCore (GObject * obj, const gchar * signalname) { auto loop = g_main_loop_new(nullptr, FALSE); diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 47a95f3..5066558 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -30,6 +30,14 @@ protected: { } + virtual void SetUp() override + { + auto bustle = buildBustleMock("indicator-test.bustle"); + addMock(bustle); + + IndicatorFixture::SetUp(); + } + }; -- cgit v1.2.3 From 36f7456285da6f55126396e004776b4da3290443 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 6 Nov 2014 09:48:22 -0600 Subject: Adding in an accounts services mock --- tests/accounts-service-mock.h | 7 +++++++ tests/indicator-fixture.h | 2 +- tests/indicator-test.cc | 4 ++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/accounts-service-mock.h b/tests/accounts-service-mock.h index d4dae7e..9507c5f 100644 --- a/tests/accounts-service-mock.h +++ b/tests/accounts-service-mock.h @@ -17,6 +17,7 @@ * Ted Gould */ +#include #include class AccountsServiceMock @@ -87,6 +88,12 @@ class AccountsServiceMock g_clear_object(&mock); } + operator std::shared_ptr () { + return std::shared_ptr( + DBUS_TEST_TASK(g_object_ref(mock)), + [](DbusTestTask * task) { g_clear_object(&task); }); + } + operator DbusTestTask* () { return DBUS_TEST_TASK(mock); } diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 0c07159..97028e3 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -111,7 +111,7 @@ class IndicatorFixture : public ::testing::Test run.reset(); } - void addMock (std::shared_ptr& mock) + void addMock (std::shared_ptr mock) { _mocks.push_back(mock); } diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 5066558..6e3c6de 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -21,6 +21,7 @@ #include #include "indicator-fixture.h" +#include "accounts-service-mock.h" class IndicatorTest : public IndicatorFixture { @@ -35,6 +36,9 @@ protected: auto bustle = buildBustleMock("indicator-test.bustle"); addMock(bustle); + AccountsServiceMock as; + addMock(as); + IndicatorFixture::SetUp(); } -- cgit v1.2.3 From b70244a3e24cc666a640445dbc190db8a44f556c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Nov 2014 18:18:08 -0600 Subject: Splitting out the tests --- tests/CMakeLists.txt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 58ecd3a..f588d12 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -197,5 +197,12 @@ target_link_libraries ( ) # Split tests to work around libaccountservice sucking -add_test(indicator-test indicator-test) - +add_test(indcator-test-phone-menu + indicator-test --gtest_filter=IndicatorTest.PhoneMenu +) +add_test(indcator-test-desktop-menu + indicator-test --gtest_filter=IndicatorTest.DesktopMenu +) +add_test(indcator-test-silent-actions + indicator-test --gtest_filter=IndicatorTest.SilentActions +) -- cgit v1.2.3 From bb6126b670654941f717b0b12c5cf94a2ba1b56e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Nov 2014 18:37:59 -0600 Subject: Putting the accounts service mock onto the system bus --- tests/accounts-service-mock.h | 2 ++ tests/accounts-service-user.cc | 3 +-- tests/media-player-user.cc | 4 +--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/accounts-service-mock.h b/tests/accounts-service-mock.h index 9507c5f..7a6972d 100644 --- a/tests/accounts-service-mock.h +++ b/tests/accounts-service-mock.h @@ -30,6 +30,8 @@ class AccountsServiceMock AccountsServiceMock () { mock = dbus_test_dbus_mock_new("org.freedesktop.Accounts"); + dbus_test_task_set_bus(DBUS_TEST_TASK(mock), DBUS_TEST_SERVICE_BUS_SYSTEM); + DbusTestDbusMockObject * baseobj = dbus_test_dbus_mock_get_object(mock, "/org/freedesktop/Accounts", "org.freedesktop.Accounts", NULL); dbus_test_dbus_mock_object_add_method(mock, baseobj, diff --git a/tests/accounts-service-user.cc b/tests/accounts-service-user.cc index b39b546..7110fb3 100644 --- a/tests/accounts-service-user.cc +++ b/tests/accounts-service-user.cc @@ -42,14 +42,13 @@ class AccountsServiceUserTest : public ::testing::Test virtual void SetUp() { service = dbus_test_service_new(NULL); + dbus_test_service_set_bus(service, DBUS_TEST_SERVICE_BUS_BOTH); AccountsServiceMock service_mock; dbus_test_service_add_task(service, (DbusTestTask*)service_mock); dbus_test_service_start_tasks(service); - g_setenv("DBUS_SYSTEM_BUS_ADDRESS", g_getenv("DBUS_SESSION_BUS_ADDRESS"), TRUE); - session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); ASSERT_NE(nullptr, session); g_dbus_connection_set_exit_on_close(session, FALSE); diff --git a/tests/media-player-user.cc b/tests/media-player-user.cc index 32c1181..9214961 100644 --- a/tests/media-player-user.cc +++ b/tests/media-player-user.cc @@ -40,13 +40,11 @@ class MediaPlayerUserTest : public ::testing::Test virtual void SetUp() { service = dbus_test_service_new(NULL); - + dbus_test_service_set_bus(service, DBUS_TEST_SERVICE_BUS_BOTH); dbus_test_service_add_task(service, (DbusTestTask*)service_mock); dbus_test_service_start_tasks(service); - g_setenv("DBUS_SYSTEM_BUS_ADDRESS", g_getenv("DBUS_SESSION_BUS_ADDRESS"), TRUE); - session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); ASSERT_NE(nullptr, session); g_dbus_connection_set_exit_on_close(session, FALSE); -- cgit v1.2.3 From 7a4321c81fc4eef57b9759aae9ce47b56797dccd Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Tue, 11 Nov 2014 18:38:15 -0600 Subject: Handle both a system and session bus --- tests/indicator-fixture.h | 39 ++++++++++++++++++++++++++++++--------- tests/indicator-test.cc | 4 ++-- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 97028e3..3115fae 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -39,33 +39,47 @@ class IndicatorFixture : public ::testing::Test to make the lifecycle of the items more clear. */ std::shared_ptr _menu; std::shared_ptr _actions; - DbusTestService * _test_service; + DbusTestService * _session_service; + DbusTestService * _system_service; DbusTestTask * _test_indicator; DbusTestTask * _test_dummy; GDBusConnection * _session; + GDBusConnection * _system; PerRunData (const std::string& indicatorPath, const std::string& indicatorAddress, std::vector>& mocks) : _menu(nullptr) , _session(nullptr) { - _test_service = dbus_test_service_new(nullptr); + _session_service = dbus_test_service_new(nullptr); + dbus_test_service_set_bus(_session_service, DBUS_TEST_SERVICE_BUS_SESSION); + + _system_service = dbus_test_service_new(nullptr); + dbus_test_service_set_bus(_system_service, DBUS_TEST_SERVICE_BUS_SYSTEM); _test_indicator = DBUS_TEST_TASK(dbus_test_process_new(indicatorPath.c_str())); dbus_test_task_set_name(_test_indicator, "Indicator"); - dbus_test_service_add_task(_test_service, _test_indicator); + dbus_test_service_add_task(_session_service, _test_indicator); _test_dummy = dbus_test_task_new(); dbus_test_task_set_wait_for(_test_dummy, indicatorAddress.c_str()); dbus_test_task_set_name(_test_dummy, "Dummy"); - dbus_test_service_add_task(_test_service, _test_dummy); + dbus_test_service_add_task(_session_service, _test_dummy); std::for_each(mocks.begin(), mocks.end(), [this](std::shared_ptr task) { - dbus_test_service_add_task(_test_service, task.get()); + if (dbus_test_task_get_bus(task.get()) == DBUS_TEST_SERVICE_BUS_SYSTEM) { + dbus_test_service_add_task(_system_service, task.get()); + } else { + dbus_test_service_add_task(_session_service, task.get()); + } }); - dbus_test_service_start_tasks(_test_service); + dbus_test_service_start_tasks(_system_service); + _system = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, nullptr); + g_dbus_connection_set_exit_on_close(_system, FALSE); + dbus_test_service_start_tasks(_session_service); _session = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); + g_dbus_connection_set_exit_on_close(_session, FALSE); } virtual ~PerRunData (void) { @@ -75,13 +89,19 @@ class IndicatorFixture : public ::testing::Test /* D-Bus Test Stuff */ g_clear_object(&_test_dummy); g_clear_object(&_test_indicator); - g_clear_object(&_test_service); + g_clear_object(&_session_service); + g_clear_object(&_system_service); /* Wait for D-Bus session bus to go */ if (!g_dbus_connection_is_closed(_session)) { g_dbus_connection_close_sync(_session, nullptr, nullptr); } g_clear_object(&_session); + + if (!g_dbus_connection_is_closed(_system)) { + g_dbus_connection_close_sync(_system, nullptr, nullptr); + } + g_clear_object(&_system); } }; @@ -116,11 +136,12 @@ class IndicatorFixture : public ::testing::Test _mocks.push_back(mock); } - std::shared_ptr buildBustleMock (const std::string& filename) + std::shared_ptr buildBustleMock (const std::string& filename, DbusTestServiceBus bus = DBUS_TEST_SERVICE_BUS_BOTH) { - return std::shared_ptr([filename]() { + return std::shared_ptr([filename, bus]() { DbusTestTask * bustle = DBUS_TEST_TASK(dbus_test_bustle_new(filename.c_str())); dbus_test_task_set_name(bustle, "Bustle"); + dbus_test_task_set_bus(bustle, bus); return bustle; }(), [](DbusTestTask * bustle) { g_clear_object(&bustle); diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 6e3c6de..725a5c8 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -33,8 +33,8 @@ protected: virtual void SetUp() override { - auto bustle = buildBustleMock("indicator-test.bustle"); - addMock(bustle); + addMock(buildBustleMock("indicator-test-session.bustle", DBUS_TEST_SERVICE_BUS_SESSION)); + addMock(buildBustleMock("indicator-test-system.bustle", DBUS_TEST_SERVICE_BUS_SYSTEM)); AccountsServiceMock as; addMock(as); -- cgit v1.2.3 From 5b061aac08bfb1931b1a52eb8439937ff66d8d80 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 17 Nov 2014 15:00:12 -0600 Subject: Increasing dbustest requirement to 15.04.0 --- CMakeLists.txt | 2 +- debian/control | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c8d69c..c1fbb8d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,7 +49,7 @@ include_directories(${SOUNDSERVICE_INCLUDE_DIRS}) pkg_check_modules( TEST REQUIRED - dbustest-1 + dbustest-1>=15.04.0 ) include_directories(${TEST_INCLUDE_DIRS}) diff --git a/debian/control b/debian/control index d6c52bf..eb9edff 100644 --- a/debian/control +++ b/debian/control @@ -13,7 +13,7 @@ Build-Depends: debhelper (>= 9.0), autotools-dev, valac (>= 0.20), libaccountsservice-dev, - libdbustest1-dev (>= 14.04.1), + libdbustest1-dev (>= 15.04.0), libgirepository1.0-dev, libglib2.0-dev (>= 2.22.3), libgtest-dev, -- cgit v1.2.3 From 12bcb367c0fe067b2b3475d09a08e09e63757a48 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 24 Nov 2014 10:16:40 -0600 Subject: Switching to using a results object for the menu attribute checking --- tests/indicator-fixture.h | 49 +++++++++++++++++++---------------------------- tests/indicator-test.cc | 2 +- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index 3115fae..a05f7bb 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -357,7 +357,7 @@ class IndicatorFixture : public ::testing::Test } protected: - bool expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, GVariant * value) { + testing::AssertionResult expectMenuAttribute (const char * menuLocationStr, const gchar * attributeStr, const char * valueStr, const std::vector menuLocation, const std::string& attribute, GVariant * value) { auto varref = std::shared_ptr(g_variant_ref_sink(value), [](GVariant * varptr) { if (varptr != nullptr) g_variant_unref(varptr); @@ -371,7 +371,6 @@ class IndicatorFixture : public ::testing::Test } if (!same) { - gchar * valstr = nullptr; gchar * attstr = nullptr; if (attrib != nullptr) { @@ -380,50 +379,42 @@ class IndicatorFixture : public ::testing::Test attstr = g_strdup("nullptr"); } - if (varref != nullptr) { - valstr = g_variant_print(varref.get(), TRUE); - } else { - valstr = g_strdup("nullptr"); - } - - std::string menuprint("{ "); - std::for_each(menuLocation.begin(), menuLocation.end(), [&menuprint](int i) { - menuprint.append(std::to_string(i)); - menuprint.append(", "); - }); - menuprint += "}"; - - std::cout << - " Menu: " << menuprint << std::endl << - " Attribute: " << attribute << std::endl << - " Expected: " << valstr << std::endl << + auto result = testing::AssertionFailure(); + result << + " Menu: " << menuLocationStr << std::endl << + " Attribute: " << attributeStr << std::endl << + " Expected: " << valueStr << std::endl << " Actual: " << attstr << std::endl; - g_free(valstr); g_free(attstr); - } - return same; + return result; + } else { + auto result = testing::AssertionSuccess(); + return result; + } } - bool expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, bool value) { + testing::AssertionResult expectMenuAttribute (const char * menuLocationStr, const gchar * attributeStr, const char * valueStr, const std::vector menuLocation, const std::string& attribute, bool value) { GVariant * var = g_variant_new_boolean(value); - return expectMenuAttribute(menuLocation, attribute, var); + return expectMenuAttribute(menuLocationStr, attributeStr, valueStr, menuLocation, attribute, var); } - bool expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, std::string value) { + testing::AssertionResult expectMenuAttribute (const char * menuLocationStr, const gchar * attributeStr, const char * valueStr, const std::vector menuLocation, const std::string& attribute, std::string value) { GVariant * var = g_variant_new_string(value.c_str()); - return expectMenuAttribute(menuLocation, attribute, var); + return expectMenuAttribute(menuLocationStr, attributeStr, valueStr, menuLocation, attribute, var); } - bool expectMenuAttribute (const std::vector menuLocation, const std::string& attribute, const char * value) { + testing::AssertionResult expectMenuAttribute (const char * menuLocationStr, const gchar * attributeStr, const char * valueStr, const std::vector menuLocation, const std::string& attribute, const char * value) { GVariant * var = g_variant_new_string(value); - return expectMenuAttribute(menuLocation, attribute, var); + return expectMenuAttribute(menuLocationStr, attributeStr, valueStr, menuLocation, attribute, var); } }; -#define EXPECT_MENU_ATTRIB(menu, attrib, value) expectMenuAttribute(menu, attrib, value) +#define EXPECT_MENU_ATTRIB(menu, attrib, value) \ + EXPECT_PRED_FORMAT3(IndicatorFixture::expectMenuAttribute, menu, attrib, value) + #define ASSERT_MENU_ATTRIB(menu, attrib, value) \ if (!expectMenuAttribute(menu, attrib, value)) \ return; diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 725a5c8..ee9a722 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -51,7 +51,7 @@ TEST_F(IndicatorTest, PhoneMenu) { EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); EXPECT_MENU_ATTRIB({0}, "x-canonical-type", "com.canonical.indicator.root"); - expectMenuAttribute({0, 0, 0}, "action", "indicator.silent-mode"); + //expectMenuAttribute({0, 0, 0}, "action", "indicator.silent-mode"); } TEST_F(IndicatorTest, DesktopMenu) { -- cgit v1.2.3 From 70e1a5b010c26562168a08c16fee3bb56ba90eb2 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 24 Nov 2014 10:19:51 -0600 Subject: Put back to a full initializer --- tests/indicator-test.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index ee9a722..8599239 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -51,7 +51,7 @@ TEST_F(IndicatorTest, PhoneMenu) { EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); EXPECT_MENU_ATTRIB({0}, "x-canonical-type", "com.canonical.indicator.root"); - //expectMenuAttribute({0, 0, 0}, "action", "indicator.silent-mode"); + EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "action", "indicator.silent-mode"); } TEST_F(IndicatorTest, DesktopMenu) { -- cgit v1.2.3 From 01de4ffbc6f8cf2c5bc58d41f57eac01a91d89a9 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 24 Nov 2014 11:07:11 -0600 Subject: Change the other checks to use the assertion return --- tests/indicator-fixture.h | 91 +++++++++++++++++++++++++++++------------------ tests/indicator-test.cc | 10 +++--- 2 files changed, 61 insertions(+), 40 deletions(-) diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index a05f7bb..b4893b5 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -215,20 +215,24 @@ class IndicatorFixture : public ::testing::Test agWaitForActions(run->_actions); } - bool expectActionExists (const std::string& name) { + testing::AssertionResult expectActionExists (const gchar * nameStr, const std::string& name) { bool hasit = g_action_group_has_action(run->_actions.get(), name.c_str()); if (!hasit) { - std::cout << - " Action: " << name << std::endl << + auto result = testing::AssertionFailure(); + result << + " Action: " << nameStr << std::endl << " Expected: " << "Exists" << std::endl << " Actual: " << "No action found" << std::endl; + + return result; } - return hasit; + auto result = testing::AssertionSuccess(); + return result; } - bool expectActionStateType (const std::string& name, const GVariantType * type) { + testing::AssertionResult expectActionStateType (const char * nameStr, const char * typeStr, const std::string& name, const GVariantType * type) { auto atype = g_action_group_get_action_state_type(run->_actions.get(), name.c_str()); bool same = false; @@ -237,16 +241,20 @@ class IndicatorFixture : public ::testing::Test } if (!same) { - std::cout << - " Action: " << name << std::endl << - " Expected: " << g_variant_type_peek_string(type) << std::endl << + auto result = testing::AssertionFailure(); + result << + " Action: " << nameStr << std::endl << + " Expected: " << typeStr << std::endl << " Actual: " << g_variant_type_peek_string(atype) << std::endl; + + return result; } - return same; + auto result = testing::AssertionSuccess(); + return result; } - bool expectActionStateIs (const std::string& name, GVariant * value) { + testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, GVariant * value) { auto varref = std::shared_ptr(g_variant_ref_sink(value), [](GVariant * varptr) { if (varptr != nullptr) g_variant_unref(varptr); @@ -262,7 +270,6 @@ class IndicatorFixture : public ::testing::Test } if (!match) { - gchar * valstr = nullptr; gchar * attstr = nullptr; if (aval != nullptr) { @@ -271,47 +278,44 @@ class IndicatorFixture : public ::testing::Test attstr = g_strdup("nullptr"); } - if (varref != nullptr) { - valstr = g_variant_print(varref.get(), TRUE); - } else { - valstr = g_strdup("nullptr"); - } - - std::cout << - " Action: " << name << std::endl << - " Expected: " << valstr << std::endl << + auto result = testing::AssertionFailure(); + result << + " Action: " << nameStr << std::endl << + " Expected: " << valueStr << std::endl << " Actual: " << attstr << std::endl; - g_free(valstr); g_free(attstr); - } - return match; + return result; + } else { + auto result = testing::AssertionSuccess(); + return result; + } } - bool expectActionStateIs (const std::string& name, bool value) { + testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, bool value) { GVariant * var = g_variant_new_boolean(value); - return expectActionStateIs(name, var); + return expectActionStateIs(nameStr, valueStr, name, var); } - bool expectActionStateIs (const std::string& name, std::string value) { + testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, std::string value) { GVariant * var = g_variant_new_string(value.c_str()); - return expectActionStateIs(name, var); + return expectActionStateIs(nameStr, valueStr, name, var); } - bool expectActionStateIs (const std::string& name, const char * value) { + testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, const char * value) { GVariant * var = g_variant_new_string(value); - return expectActionStateIs(name, var); + return expectActionStateIs(nameStr, valueStr, name, var); } - bool expectActionStateIs (const std::string& name, double value) { + testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, double value) { GVariant * var = g_variant_new_double(value); - return expectActionStateIs(name, var); + return expectActionStateIs(nameStr, valueStr, name, var); } - bool expectActionStateIs (const std::string& name, float value) { + testing::AssertionResult expectActionStateIs (const char * nameStr, const char * valueStr, const std::string& name, float value) { GVariant * var = g_variant_new_double(value); - return expectActionStateIs(name, var); + return expectActionStateIs(nameStr, valueStr, name, var); } @@ -416,6 +420,23 @@ class IndicatorFixture : public ::testing::Test EXPECT_PRED_FORMAT3(IndicatorFixture::expectMenuAttribute, menu, attrib, value) #define ASSERT_MENU_ATTRIB(menu, attrib, value) \ - if (!expectMenuAttribute(menu, attrib, value)) \ - return; + ASSERT_PRED_FORMAT3(IndicatorFixture::expectMenuAttribute, menu, attrib, value) + +#define ASSERT_ACTION_EXISTS(action) \ + ASSERT_PRED_FORMAT1(IndicatorFixture::expectActionExists, action) + +#define EXPECT_ACTION_EXISTS(action) \ + EXPECT_PRED_FORMAT1(IndicatorFixture::expectActionExists, action) + +#define EXPECT_ACTION_STATE(action, value) \ + EXPECT_PRED_FORMAT2(IndicatorFixture::expectActionStateIs, action, value) + +#define ASSERT_ACTION_STATE(action, value) \ + ASSERT_PRED_FORMAT2(IndicatorFixture::expectActionStateIs, action, value) + +#define EXPECT_ACTION_STATE_TYPE(action, type) \ + EXPECT_PRED_FORMAT2(IndicatorFixture::expectActionStateType, action, type) + +#define ASSERT_ACTION_STATE_TYPE(action, type) \ + ASSERT_PRED_FORMAT2(IndicatorFixture::expectActionStateType, action, type) diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 8599239..59daa35 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -63,11 +63,11 @@ TEST_F(IndicatorTest, DesktopMenu) { TEST_F(IndicatorTest, SilentActions) { setActions("/com/canonical/indicator/sound"); - expectActionExists("scroll"); + EXPECT_ACTION_EXISTS("scroll"); - expectActionExists("silent-mode"); - expectActionStateIs("silent-mode", false); + EXPECT_ACTION_EXISTS("silent-mode"); + EXPECT_ACTION_STATE("silent-mode", false); - expectActionExists("mute"); - expectActionStateIs("mute", false); + EXPECT_ACTION_EXISTS("mute"); + EXPECT_ACTION_STATE("mute", false); } -- cgit v1.2.3 From 7ecd6e0f9364c72e25ce6c3263229f3e34fa9296 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 24 Nov 2014 11:27:23 -0600 Subject: Filling out the tests some --- tests/indicator-test.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 59daa35..9e54c46 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -58,16 +58,20 @@ TEST_F(IndicatorTest, DesktopMenu) { setMenu("/com/canonical/indicator/sound/desktop"); EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); + + EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "action", "indicator.mute"); } TEST_F(IndicatorTest, SilentActions) { setActions("/com/canonical/indicator/sound"); - EXPECT_ACTION_EXISTS("scroll"); + ASSERT_ACTION_EXISTS("scroll"); - EXPECT_ACTION_EXISTS("silent-mode"); + ASSERT_ACTION_EXISTS("silent-mode"); + ASSERT_ACTION_STATE_TYPE("silent-mode", G_VARIANT_TYPE_BOOLEAN); EXPECT_ACTION_STATE("silent-mode", false); - EXPECT_ACTION_EXISTS("mute"); + ASSERT_ACTION_EXISTS("mute"); + ASSERT_ACTION_STATE_TYPE("mute", G_VARIANT_TYPE_BOOLEAN); EXPECT_ACTION_STATE("mute", false); } -- cgit v1.2.3 From b8a464bcc19809a4d60b444e0280e550912fc59c Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 24 Nov 2014 16:50:32 -0600 Subject: Turn off the debugging mocks --- tests/indicator-test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 9e54c46..073e037 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -33,8 +33,8 @@ protected: virtual void SetUp() override { - addMock(buildBustleMock("indicator-test-session.bustle", DBUS_TEST_SERVICE_BUS_SESSION)); - addMock(buildBustleMock("indicator-test-system.bustle", DBUS_TEST_SERVICE_BUS_SYSTEM)); + //addMock(buildBustleMock("indicator-test-session.bustle", DBUS_TEST_SERVICE_BUS_SESSION)); + //addMock(buildBustleMock("indicator-test-system.bustle", DBUS_TEST_SERVICE_BUS_SYSTEM)); AccountsServiceMock as; addMock(as); -- cgit v1.2.3 From 40a32cacb2520cced6ce75acd31efb4f4b519e96 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 24 Nov 2014 16:55:50 -0600 Subject: Fleshing out all the actions --- tests/indicator-test.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 073e037..336cfdb 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -62,9 +62,12 @@ TEST_F(IndicatorTest, DesktopMenu) { EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "action", "indicator.mute"); } -TEST_F(IndicatorTest, SilentActions) { +TEST_F(IndicatorTest, BaseActions) { setActions("/com/canonical/indicator/sound"); + ASSERT_ACTION_EXISTS("root"); + ASSERT_ACTION_STATE_TYPE("root", G_VARIANT_TYPE("a{sv}")); + ASSERT_ACTION_EXISTS("scroll"); ASSERT_ACTION_EXISTS("silent-mode"); @@ -74,4 +77,10 @@ TEST_F(IndicatorTest, SilentActions) { ASSERT_ACTION_EXISTS("mute"); ASSERT_ACTION_STATE_TYPE("mute", G_VARIANT_TYPE_BOOLEAN); EXPECT_ACTION_STATE("mute", false); + + ASSERT_ACTION_EXISTS("mic-volume"); + ASSERT_ACTION_STATE_TYPE("mic-volume", G_VARIANT_TYPE_DOUBLE); + + ASSERT_ACTION_EXISTS("volume"); + ASSERT_ACTION_STATE_TYPE("volume", G_VARIANT_TYPE_DOUBLE); } -- cgit v1.2.3 From 1188fa25abc4b23650888f8745837df8549b73af Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 24 Nov 2014 20:50:05 -0600 Subject: Flesh out the menu tests --- tests/indicator-test.cc | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 336cfdb..a21209c 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -50,16 +50,29 @@ TEST_F(IndicatorTest, PhoneMenu) { EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); EXPECT_MENU_ATTRIB({0}, "x-canonical-type", "com.canonical.indicator.root"); + EXPECT_MENU_ATTRIB({0}, "x-canonical-scroll-action", "indicator.scroll"); + EXPECT_MENU_ATTRIB({0}, "x-canonical-secondary-action", "indicator.mute"); EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "action", "indicator.silent-mode"); + EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "label", "Silent Mode"); + + EXPECT_MENU_ATTRIB(std::vector({0, 2}), "action", "indicator.phone-settings"); + EXPECT_MENU_ATTRIB(std::vector({0, 2}), "label", "Sound Settings…"); } TEST_F(IndicatorTest, DesktopMenu) { setMenu("/com/canonical/indicator/sound/desktop"); EXPECT_MENU_ATTRIB({0}, "action", "indicator.root"); + EXPECT_MENU_ATTRIB({0}, "x-canonical-type", "com.canonical.indicator.root"); + EXPECT_MENU_ATTRIB({0}, "x-canonical-scroll-action", "indicator.scroll"); + EXPECT_MENU_ATTRIB({0}, "x-canonical-secondary-action", "indicator.mute"); EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "action", "indicator.mute"); + EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "label", "Mute"); + + EXPECT_MENU_ATTRIB(std::vector({0, 2}), "action", "indicator.desktop-settings"); + EXPECT_MENU_ATTRIB(std::vector({0, 2}), "label", "Sound Settings…"); } TEST_F(IndicatorTest, BaseActions) { -- cgit v1.2.3 From 008b823ccc75dc3fe23a785a535243d3aea38009 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Nov 2014 08:36:24 -0600 Subject: Make the account service accessible --- tests/indicator-test.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index a21209c..40755e3 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -31,17 +31,26 @@ protected: { } + std::shared_ptr as; + virtual void SetUp() override { //addMock(buildBustleMock("indicator-test-session.bustle", DBUS_TEST_SERVICE_BUS_SESSION)); //addMock(buildBustleMock("indicator-test-system.bustle", DBUS_TEST_SERVICE_BUS_SYSTEM)); - AccountsServiceMock as; - addMock(as); + as = std::make_shared(); + addMock(*as); IndicatorFixture::SetUp(); } + virtual void TearDown() override + { + as.reset(); + + IndicatorFixture::TearDown(); + } + }; @@ -97,3 +106,4 @@ TEST_F(IndicatorTest, BaseActions) { ASSERT_ACTION_EXISTS("volume"); ASSERT_ACTION_STATE_TYPE("volume", G_VARIANT_TYPE_DOUBLE); } + -- cgit v1.2.3 From 8210778317cd8f8be803f4afa0200bd9cad0f68e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 26 Nov 2014 08:37:39 -0600 Subject: Add in silent mode support to the AS mock --- tests/accounts-service-mock.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/accounts-service-mock.h b/tests/accounts-service-mock.h index 7a6972d..1d0c1fe 100644 --- a/tests/accounts-service-mock.h +++ b/tests/accounts-service-mock.h @@ -25,6 +25,7 @@ class AccountsServiceMock DbusTestDbusMock * mock = nullptr; DbusTestDbusMockObject * soundobj = nullptr; DbusTestDbusMockObject * userobj = nullptr; + DbusTestDbusMockObject * syssoundobj = nullptr; public: AccountsServiceMock () { @@ -83,6 +84,11 @@ class AccountsServiceMock dbus_test_dbus_mock_object_add_property(mock, soundobj, "ArtUrl", G_VARIANT_TYPE_STRING, g_variant_new_string(""), NULL); + + syssoundobj = dbus_test_dbus_mock_get_object(mock, "/user", "com.ubuntu.touch.AccountsService.Sound", NULL); + dbus_test_dbus_mock_object_add_property(mock, syssoundobj, + "SilentMode", G_VARIANT_TYPE_BOOLEAN, + g_variant_new_boolean(FALSE), NULL); } ~AccountsServiceMock () { @@ -90,6 +96,12 @@ class AccountsServiceMock g_clear_object(&mock); } + void setSilentMode (bool modeValue) { + dbus_test_dbus_mock_object_update_property(mock, syssoundobj, + "SilentMode", g_variant_new_boolean(modeValue ? TRUE : FALSE), + NULL); + } + operator std::shared_ptr () { return std::shared_ptr( DBUS_TEST_TASK(g_object_ref(mock)), -- cgit v1.2.3 From e4ee5134da0cf9656db9ea201f2b7b53e92ac1b7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Thu, 29 Jan 2015 20:57:16 -0600 Subject: Setup the PA mock as part of the indicator test --- tests/CMakeLists.txt | 3 +++ tests/indicator-fixture.h | 2 ++ tests/indicator-test.cc | 1 + 3 files changed, 6 insertions(+) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c1b4afc..d18e2dd 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -92,6 +92,8 @@ add_library( pa-mock.cpp ) +target_link_libraries (pulse-mock ${PULSEAUDIO_LIBRARIES}) + ########################### # Name Watch Test ########################### @@ -213,6 +215,7 @@ add_test(greeter-list-test-iterator add_definitions( -DINDICATOR_SOUND_SERVICE_BINARY="${CMAKE_BINARY_DIR}/src/indicator-sound-service" + -DPA_MOCK_LIB="${CMAKE_CURRENT_BINARY_DIR}/libpulse-mock.so" ) add_executable (indicator-test indicator-test.cc) target_link_libraries ( diff --git a/tests/indicator-fixture.h b/tests/indicator-fixture.h index b4893b5..a26f61d 100644 --- a/tests/indicator-fixture.h +++ b/tests/indicator-fixture.h @@ -73,10 +73,12 @@ class IndicatorFixture : public ::testing::Test } }); + g_debug("Starting System Bus"); dbus_test_service_start_tasks(_system_service); _system = g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, nullptr); g_dbus_connection_set_exit_on_close(_system, FALSE); + g_debug("Starting Session Bus"); dbus_test_service_start_tasks(_session_service); _session = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); g_dbus_connection_set_exit_on_close(_session, FALSE); diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 40755e3..37bf719 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -37,6 +37,7 @@ protected: { //addMock(buildBustleMock("indicator-test-session.bustle", DBUS_TEST_SERVICE_BUS_SESSION)); //addMock(buildBustleMock("indicator-test-system.bustle", DBUS_TEST_SERVICE_BUS_SYSTEM)); + g_setenv("LD_PRELOAD", PA_MOCK_LIB, TRUE); as = std::make_shared(); addMock(*as); -- cgit v1.2.3 From 7746f13ca38f67ea1b0c81fdb2ff43b764f0efa0 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Jan 2015 10:02:45 -0600 Subject: Making the account service testing all system bus, becuase well, it should be. --- tests/media-player-user.cc | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/tests/media-player-user.cc b/tests/media-player-user.cc index 9214961..a402f90 100644 --- a/tests/media-player-user.cc +++ b/tests/media-player-user.cc @@ -34,28 +34,22 @@ class MediaPlayerUserTest : public ::testing::Test DbusTestService * service = NULL; AccountsServiceMock service_mock; - GDBusConnection * session = NULL; GDBusConnection * system = NULL; GDBusProxy * proxy = NULL; virtual void SetUp() { service = dbus_test_service_new(NULL); - dbus_test_service_set_bus(service, DBUS_TEST_SERVICE_BUS_BOTH); + dbus_test_service_set_bus(service, DBUS_TEST_SERVICE_BUS_SYSTEM); dbus_test_service_add_task(service, (DbusTestTask*)service_mock); dbus_test_service_start_tasks(service); - session = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); - ASSERT_NE(nullptr, session); - g_dbus_connection_set_exit_on_close(session, FALSE); - g_object_add_weak_pointer(G_OBJECT(session), (gpointer *)&session); - system = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, NULL); ASSERT_NE(nullptr, system); g_dbus_connection_set_exit_on_close(system, FALSE); g_object_add_weak_pointer(G_OBJECT(system), (gpointer *)&system); - proxy = g_dbus_proxy_new_sync(session, + proxy = g_dbus_proxy_new_sync(system, G_DBUS_PROXY_FLAGS_NONE, NULL, "org.freedesktop.Accounts", @@ -69,7 +63,6 @@ class MediaPlayerUserTest : public ::testing::Test g_clear_object(&proxy); g_clear_object(&service); - g_object_unref(session); g_object_unref(system); #if 0 -- cgit v1.2.3 From bc90929adb5637cc0f77dfeba64082b26c435fc7 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Jan 2015 10:05:10 -0600 Subject: Ensure the properties get set, there's some intermitant failures here. --- tests/media-player-user.cc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/media-player-user.cc b/tests/media-player-user.cc index a402f90..8d2fcb1 100644 --- a/tests/media-player-user.cc +++ b/tests/media-player-user.cc @@ -180,6 +180,9 @@ TEST_F(MediaPlayerUserTest, TimeoutTest) { set_property("Album", g_variant_new_string("Vinyl is dead")); set_property("ArtUrl", g_variant_new_string("http://art.url")); + /* Ensure the properties get set before we pull them */ + loop(100); + /* Build our media player */ MediaPlayerUser * player = media_player_user_new("user"); ASSERT_NE(nullptr, player); -- cgit v1.2.3 From c37ce8ed28766e8ece0da617b6255054d7947752 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Jan 2015 10:45:51 -0600 Subject: No media player because using an appropriate account service mock --- tests/indicator-test.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 37bf719..31494d4 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -66,8 +66,8 @@ TEST_F(IndicatorTest, PhoneMenu) { EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "action", "indicator.silent-mode"); EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "label", "Silent Mode"); - EXPECT_MENU_ATTRIB(std::vector({0, 2}), "action", "indicator.phone-settings"); - EXPECT_MENU_ATTRIB(std::vector({0, 2}), "label", "Sound Settings…"); + EXPECT_MENU_ATTRIB(std::vector({0, 1}), "action", "indicator.phone-settings"); + EXPECT_MENU_ATTRIB(std::vector({0, 1}), "label", "Sound Settings…"); } TEST_F(IndicatorTest, DesktopMenu) { -- cgit v1.2.3 From 7e93bd7292a2570aa8625da07b03f0256722eb26 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Fri, 30 Jan 2015 10:54:33 -0600 Subject: Make sure we have the system bus fixes in dbus-test-runner --- debian/control | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/debian/control b/debian/control index eb9edff..15b47f1 100644 --- a/debian/control +++ b/debian/control @@ -6,7 +6,7 @@ XSBC-Original-Maintainer: Conor Curran Build-Depends: debhelper (>= 9.0), cmake, dbus, - dbus-test-runner (>= 14.04.0+14.04.20140226), + dbus-test-runner (>> 14.04.0+14.04.20150120.1), dh-translations, gir1.2-accountsservice-1.0, gnome-common, -- cgit v1.2.3 From 91f42ea2266bd4201c1a9f0a9d7e47d431c601c3 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Mon, 2 Feb 2015 08:13:10 -0600 Subject: We're not using libaccountservice on this side of things, so we don't need to split --- tests/CMakeLists.txt | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d18e2dd..bc2df0d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -226,12 +226,6 @@ target_link_libraries ( ) # Split tests to work around libaccountservice sucking -add_test(indcator-test-phone-menu - indicator-test --gtest_filter=IndicatorTest.PhoneMenu -) -add_test(indcator-test-desktop-menu - indicator-test --gtest_filter=IndicatorTest.DesktopMenu -) -add_test(indcator-test-silent-actions - indicator-test --gtest_filter=IndicatorTest.SilentActions +add_test(indcator-test + indicator-test ) -- cgit v1.2.3 From 8838bd8e4e95f1da3bcc85324e924e782a434c4e Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 4 Feb 2015 08:29:43 -0600 Subject: Make the testing verbose --- debian/rules | 2 ++ 1 file changed, 2 insertions(+) diff --git a/debian/rules b/debian/rules index 8fb0f91..8ef6c72 100755 --- a/debian/rules +++ b/debian/rules @@ -17,3 +17,5 @@ override_dh_install: install -m 644 debian/indicator-sound-crashdb.conf debian/indicator-sound/etc/apport/crashdb.conf.d/ dh_install --fail-missing +override_dh_auto_test: + ARGS=-V dh_auto_test -- cgit v1.2.3 From 363a5d1ae24d58d294d8806930cf788879a6f73a Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 4 Feb 2015 11:43:08 -0600 Subject: Compile GSettings schema and use the memory backend --- tests/CMakeLists.txt | 22 ++++++++++++++++++++++ tests/indicator-test.cc | 8 +++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index bc2df0d..d9bfe0b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -10,6 +10,28 @@ add_library (gtest STATIC ${GTEST_SOURCE_DIR}/gtest_main.cc) target_link_libraries(gtest ${GTEST_LIBS}) +########################### +# GSettings Schema +########################### + +# build the necessary schemas +set_directory_properties (PROPERTIES + ADDITIONAL_MAKE_CLEAN_FILES gschemas.compiled) +set_source_files_properties (gschemas.compiled GENERATED) + +# GSettings: +# compile the indicator-sound schema into a gschemas.compiled file in this directory, +# and help the tests to find that file by setting -DSCHEMA_DIR +set (SCHEMA_DIR ${CMAKE_CURRENT_BINARY_DIR}) +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) +add_custom_command (OUTPUT gschemas.compiled + DEPENDS ${CMAKE_BINARY_DIR}/data/com.canonical.indicator.sound.gschema.xml + COMMAND cp -f ${CMAKE_BINARY_DIR}/data/*gschema.xml ${SCHEMA_DIR} + COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR}) + ########################### # Vala Mocks ########################### diff --git a/tests/indicator-test.cc b/tests/indicator-test.cc index 31494d4..636db1d 100644 --- a/tests/indicator-test.cc +++ b/tests/indicator-test.cc @@ -39,6 +39,9 @@ protected: //addMock(buildBustleMock("indicator-test-system.bustle", DBUS_TEST_SERVICE_BUS_SYSTEM)); g_setenv("LD_PRELOAD", PA_MOCK_LIB, TRUE); + g_setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, TRUE); + g_setenv("GSETTINGS_BACKEND", "memory", TRUE); + as = std::make_shared(); addMock(*as); @@ -81,8 +84,8 @@ TEST_F(IndicatorTest, DesktopMenu) { EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "action", "indicator.mute"); EXPECT_MENU_ATTRIB(std::vector({0, 0, 0}), "label", "Mute"); - EXPECT_MENU_ATTRIB(std::vector({0, 2}), "action", "indicator.desktop-settings"); - EXPECT_MENU_ATTRIB(std::vector({0, 2}), "label", "Sound Settings…"); + EXPECT_MENU_ATTRIB(std::vector({0, 1}), "action", "indicator.desktop-settings"); + EXPECT_MENU_ATTRIB(std::vector({0, 1}), "label", "Sound Settings…"); } TEST_F(IndicatorTest, BaseActions) { @@ -99,7 +102,6 @@ TEST_F(IndicatorTest, BaseActions) { ASSERT_ACTION_EXISTS("mute"); ASSERT_ACTION_STATE_TYPE("mute", G_VARIANT_TYPE_BOOLEAN); - EXPECT_ACTION_STATE("mute", false); ASSERT_ACTION_EXISTS("mic-volume"); ASSERT_ACTION_STATE_TYPE("mic-volume", G_VARIANT_TYPE_DOUBLE); -- cgit v1.2.3 From 23bdec1dd9169e8dda04ec0587db909472acc6c1 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 4 Feb 2015 13:36:53 -0600 Subject: Set build dependencies to compile the schemas --- tests/CMakeLists.txt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index d9bfe0b..38a76ae 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -22,14 +22,15 @@ set_source_files_properties (gschemas.compiled GENERATED) # GSettings: # compile the indicator-sound schema into a gschemas.compiled file in this directory, # and help the tests to find that file by setting -DSCHEMA_DIR -set (SCHEMA_DIR ${CMAKE_CURRENT_BINARY_DIR}) +set (SCHEMA_DIR "${CMAKE_CURRENT_BINARY_DIR}/gsettings-schemas") 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) add_custom_command (OUTPUT gschemas.compiled - DEPENDS ${CMAKE_BINARY_DIR}/data/com.canonical.indicator.sound.gschema.xml - COMMAND cp -f ${CMAKE_BINARY_DIR}/data/*gschema.xml ${SCHEMA_DIR} + DEPENDS ${CMAKE_SOURCE_DIR}/data/com.canonical.indicator.sound.gschema.xml + COMMAND mkdir -p ${SCHEMA_DIR} + COMMAND cp -f ${CMAKE_SOURCE_DIR}/data/*gschema.xml ${SCHEMA_DIR} COMMAND ${COMPILE_SCHEMA_EXECUTABLE} ${SCHEMA_DIR}) ########################### @@ -239,7 +240,7 @@ add_definitions( -DINDICATOR_SOUND_SERVICE_BINARY="${CMAKE_BINARY_DIR}/src/indicator-sound-service" -DPA_MOCK_LIB="${CMAKE_CURRENT_BINARY_DIR}/libpulse-mock.so" ) -add_executable (indicator-test indicator-test.cc) +add_executable (indicator-test indicator-test.cc gschemas.compiled) target_link_libraries ( indicator-test gtest -- cgit v1.2.3 From 34f0c7f82246fb16be2e3de0e1bee68dd31c83a6 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 4 Feb 2015 14:25:00 -0600 Subject: Make sure that we have the com.ubuntu.sound settings --- debian/control | 1 + 1 file changed, 1 insertion(+) diff --git a/debian/control b/debian/control index 15b47f1..cdb1267 100644 --- a/debian/control +++ b/debian/control @@ -10,6 +10,7 @@ Build-Depends: debhelper (>= 9.0), dh-translations, gir1.2-accountsservice-1.0, gnome-common, + gsettings-ubuntu-schemas, autotools-dev, valac (>= 0.20), libaccountsservice-dev, -- cgit v1.2.3 From ed66db9f090b5f98338e1a47103b0106cc02d980 Mon Sep 17 00:00:00 2001 From: Ted Gould Date: Wed, 4 Feb 2015 14:43:51 -0600 Subject: Stop overriding in the rules --- debian/rules | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/debian/rules b/debian/rules index 8ef6c72..7e4e4ef 100755 --- a/debian/rules +++ b/debian/rules @@ -17,5 +17,6 @@ override_dh_install: install -m 644 debian/indicator-sound-crashdb.conf debian/indicator-sound/etc/apport/crashdb.conf.d/ dh_install --fail-missing -override_dh_auto_test: - ARGS=-V dh_auto_test +# For live test logs: +#override_dh_auto_test: +# ARGS=-V dh_auto_test -- cgit v1.2.3