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/indicator-fixture.h | 115 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100644 tests/indicator-fixture.h (limited to 'tests/indicator-fixture.h') 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); + } + + +}; + -- 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(-) (limited to 'tests/indicator-fixture.h') 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 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'tests/indicator-fixture.h') 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) + -- 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 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) (limited to 'tests/indicator-fixture.h') 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) { -- 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(-) (limited to 'tests/indicator-fixture.h') 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(-) (limited to 'tests/indicator-fixture.h') 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(-) (limited to 'tests/indicator-fixture.h') 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(-) (limited to 'tests/indicator-fixture.h') 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(-) (limited to 'tests/indicator-fixture.h') 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(+) (limited to 'tests/indicator-fixture.h') 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(-) (limited to 'tests/indicator-fixture.h') 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(-) (limited to 'tests/indicator-fixture.h') 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 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 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 15 deletions(-) (limited to 'tests/indicator-fixture.h') 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) { } -- 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(-) (limited to 'tests/indicator-fixture.h') 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(-) (limited to 'tests/indicator-fixture.h') 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 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'tests/indicator-fixture.h') 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; } -- 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 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests/indicator-fixture.h') 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) { -- 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(-) (limited to 'tests/indicator-fixture.h') 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 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'tests/indicator-fixture.h') 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); -- 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/indicator-fixture.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/indicator-fixture.h') 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); } -- 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 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) (limited to 'tests/indicator-fixture.h') 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); -- 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 +++++++++++++++++++---------------------------- 1 file changed, 20 insertions(+), 29 deletions(-) (limited to 'tests/indicator-fixture.h') 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; -- 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 +++++++++++++++++++++++++++++------------------ 1 file changed, 56 insertions(+), 35 deletions(-) (limited to 'tests/indicator-fixture.h') 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) -- 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/indicator-fixture.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/indicator-fixture.h') 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); -- cgit v1.2.3