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