Merge lp:~charlesk/indicator-power/use-dbusmock-notify-template into lp:indicator-power

Proposed by Charles Kerr
Status: Approved
Approved by: Antti Kaijanmäki
Approved revision: 299
Proposed branch: lp:~charlesk/indicator-power/use-dbusmock-notify-template
Merge into: lp:indicator-power
Diff against target: 620 lines (+219/-217)
5 files modified
debian/control (+0/-2)
tests/CMakeLists.txt (+0/-5)
tests/glib-fixture.h (+11/-11)
tests/test-dbus-fixture.h (+108/-0)
tests/test-notify.cc (+100/-199)
To merge this branch: bzr merge lp:~charlesk/indicator-power/use-dbusmock-notify-template
Reviewer Review Type Date Requested Status
Antti Kaijanmäki (community) Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+295768@code.launchpad.net

Commit message

In tests, use python-dbusmock's notification_daemon mock

Description of the change

No changes to production -- only to test scaffolding.

Use python-dbusmock's notification_daemon mock instead of rolling our own.

To post a comment you must log in.
Revision history for this message
Antti Kaijanmäki (kaijanmaki) wrote :

LGTM.

review: Approve
300. By Charles Kerr

sync tests/CMakeLists.txt dependencies with debian/control

Unmerged revisions

300. By Charles Kerr

sync tests/CMakeLists.txt dependencies with debian/control

299. By Charles Kerr

remove the dbusmock startup script and instead invoke dbusmock ourselves

298. By Charles Kerr

reuse test-dbus-fixture.h from indicator-datetime/16.10

297. By Charles Kerr

sync with trunk/16.10

296. By Charles Kerr

in tests/test-notify, use dbusmock's notification_daemon template instead of rolling our own

295. By Charles Kerr

in tests/CMakeLists.txt, add SCRIPTS_DIR definition to so tests will know where to find start-mock-notifications.py

294. By Charles Kerr

add tests/start-mock-notifications.py, a simple dbusmock helper script that can be told to emulate unity7 or unity8 notification server capabilities

293. By Charles Kerr

add tests/dbus-fixture.h, a fixture that manages a dbus connection and has helper utils

292. By Charles Kerr

in tests/glib-fixture.h, rename the protected loop variable as 'm_loop' for naming consistency

291. By Charles Kerr

remove libdbustest, we're calling dbusmock directly so we can use templates with parameters

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/control'
--- debian/control 2016-05-16 18:09:57 +0000
+++ debian/control 2016-05-26 20:21:58 +0000
@@ -17,8 +17,6 @@
17# for tests17# for tests
18 libgtest-dev,18 libgtest-dev,
19 python3-dbusmock,19 python3-dbusmock,
20 dbus-test-runner,
21 libdbustest1-dev,
22Standards-Version: 3.9.520Standards-Version: 3.9.5
23Homepage: https://launchpad.net/indicator-power21Homepage: https://launchpad.net/indicator-power
24# If you aren't a member of ~indicator-applet-developers but need to upload22# If you aren't a member of ~indicator-applet-developers but need to upload
2523
=== modified file 'tests/CMakeLists.txt'
--- tests/CMakeLists.txt 2016-05-16 17:59:03 +0000
+++ tests/CMakeLists.txt 2016-05-26 20:21:58 +0000
@@ -5,11 +5,6 @@
5set_target_properties (gtest PROPERTIES INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} ${GTEST_INCLUDE_DIR})5set_target_properties (gtest PROPERTIES INCLUDE_DIRECTORIES ${INCLUDE_DIRECTORIES} ${GTEST_INCLUDE_DIR})
6set_target_properties (gtest PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS} -w)6set_target_properties (gtest PROPERTIES COMPILE_FLAGS ${COMPILE_FLAGS} -w)
77
8# dbustest
9pkg_check_modules(DBUSTEST REQUIRED
10 dbustest-1>=14.04.0)
11include_directories (SYSTEM ${DBUSTEST_INCLUDE_DIRS})
12
13# add warnings8# add warnings
14set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g ${C_WARNING_ARGS}")9set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -g ${C_WARNING_ARGS}")
15set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-vtables -Wno-global-constructors") # Google Test10set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-weak-vtables -Wno-global-constructors") # Google Test
1611
=== modified file 'tests/glib-fixture.h'
--- tests/glib-fixture.h 2016-05-16 21:28:14 +0000
+++ tests/glib-fixture.h 2016-05-26 20:21:58 +0000
@@ -44,7 +44,7 @@
44 {44 {
45 setlocale(LC_ALL, "C.UTF-8");45 setlocale(LC_ALL, "C.UTF-8");
4646
47 loop = g_main_loop_new(nullptr, false);47 m_loop = g_main_loop_new(nullptr, false);
4848
49 // only use local, temporary settings49 // only use local, temporary settings
50 g_assert(g_setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, true));50 g_assert(g_setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, true));
@@ -62,7 +62,7 @@
62 {62 {
63 g_test_assert_expected_messages ();63 g_test_assert_expected_messages ();
6464
65 g_clear_pointer(&loop, g_main_loop_unref);65 g_clear_pointer(&m_loop, g_main_loop_unref);
66 }66 }
6767
68 void expectLogMessage (const gchar *domain, GLogLevelFlags level, const gchar *pattern)68 void expectLogMessage (const gchar *domain, GLogLevelFlags level, const gchar *pattern)
@@ -94,11 +94,11 @@
94 // wait for the signal or for timeout, whichever comes first94 // wait for the signal or for timeout, whichever comes first
95 const auto handler_id = g_signal_connect_swapped(o, signal,95 const auto handler_id = g_signal_connect_swapped(o, signal,
96 G_CALLBACK(g_main_loop_quit),96 G_CALLBACK(g_main_loop_quit),
97 loop);97 m_loop);
98 const auto timeout_id = g_timeout_add_seconds(timeout_seconds,98 const auto timeout_id = g_timeout_add_seconds(timeout_seconds,
99 wait_for_signal__timeout,99 wait_for_signal__timeout,
100 loop);100 m_loop);
101 g_main_loop_run(loop);101 g_main_loop_run(m_loop);
102 g_source_remove(timeout_id);102 g_source_remove(timeout_id);
103 g_signal_handler_disconnect(o, handler_id);103 g_signal_handler_disconnect(o, handler_id);
104 }104 }
@@ -106,8 +106,8 @@
106 /* convenience func to loop for N msec */106 /* convenience func to loop for N msec */
107 void wait_msec(int msec=50)107 void wait_msec(int msec=50)
108 {108 {
109 const auto id = g_timeout_add(msec, wait_msec__timeout, loop);109 const auto id = g_timeout_add(msec, wait_msec__timeout, m_loop);
110 g_main_loop_run(loop);110 g_main_loop_run(m_loop);
111 g_source_remove(id);111 g_source_remove(id);
112 }112 }
113113
@@ -148,8 +148,8 @@
148 g_main_loop_quit(tmp->loop);148 g_main_loop_quit(tmp->loop);
149 };149 };
150150
151 const auto timeout_id = g_timeout_add(timeout_msec, wait_msec__timeout, loop);151 const auto timeout_id = g_timeout_add(timeout_msec, wait_msec__timeout, m_loop);
152 data.loop = loop;152 data.loop = m_loop;
153 const auto watch_id = g_bus_watch_name_on_connection(153 const auto watch_id = g_bus_watch_name_on_connection(
154 connection,154 connection,
155 name,155 name,
@@ -160,7 +160,7 @@
160 nullptr // user_data_free_func160 nullptr // user_data_free_func
161 );161 );
162162
163 g_main_loop_run(loop);163 g_main_loop_run(m_loop);
164164
165 g_bus_unwatch_name(watch_id);165 g_bus_unwatch_name(watch_id);
166 g_source_remove(timeout_id);166 g_source_remove(timeout_id);
@@ -223,6 +223,6 @@
223 );223 );
224 }224 }
225225
226 GMainLoop* loop {};226 GMainLoop* m_loop {};
227};227};
228228
229229
=== added file 'tests/test-dbus-fixture.h'
--- tests/test-dbus-fixture.h 1970-01-01 00:00:00 +0000
+++ tests/test-dbus-fixture.h 2016-05-26 20:21:58 +0000
@@ -0,0 +1,108 @@
1/*
2 * Copyright 2013-2016 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 3, as published
6 * by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranties of
10 * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
11 * PURPOSE. See the GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authors:
17 * Charles Kerr <charles.kerr@canonical.com>
18 */
19
20#pragma once
21
22#include "glib-fixture.h"
23
24/***
25****
26***/
27
28class TestDBusFixture: public GlibFixture
29{
30 public:
31
32 TestDBusFixture() =default;
33 virtual ~TestDBusFixture() =default;
34
35 explicit TestDBusFixture(const std::vector<std::string>& service_dirs_in):
36 service_dirs(service_dirs_in)
37 {
38 }
39
40 private:
41
42 typedef GlibFixture super;
43
44 static void
45 on_bus_opened (GObject* /*object*/, GAsyncResult * res, gpointer gself)
46 {
47 auto self = static_cast<TestDBusFixture*>(gself);
48
49 GError* err {};
50 self->m_bus = g_bus_get_finish (res, &err);
51 g_assert_no_error (err);
52
53 g_main_loop_quit (self->m_loop);
54 }
55
56 static void
57 on_bus_closed (GObject* /*object*/, GAsyncResult * res, gpointer gself)
58 {
59 auto self = static_cast<TestDBusFixture*>(gself);
60
61 GError* err {};
62 g_dbus_connection_close_finish (self->m_bus, res, &err);
63 g_assert_no_error (err);
64
65 g_main_loop_quit (self->m_loop);
66 }
67
68 protected:
69
70 GTestDBus * m_test_dbus {};
71 GDBusConnection * m_bus {};
72 const std::vector<std::string> service_dirs;
73
74 virtual void SetUp() override
75 {
76 super::SetUp ();
77
78 // pull up a test dbus
79 m_test_dbus = g_test_dbus_new (G_TEST_DBUS_NONE);
80 for (const auto& dir : service_dirs)
81 g_test_dbus_add_service_dir (m_test_dbus, dir.c_str());
82 g_test_dbus_up (m_test_dbus);
83 const char * address = g_test_dbus_get_bus_address (m_test_dbus);
84 g_setenv ("DBUS_SYSTEM_BUS_ADDRESS", address, true);
85 g_setenv ("DBUS_SESSION_BUS_ADDRESS", address, true);
86 g_debug ("test_dbus's address is %s", address);
87
88 // wait for the GDBusConnection before returning
89 g_bus_get (G_BUS_TYPE_SYSTEM, nullptr, on_bus_opened, this);
90 g_main_loop_run (m_loop);
91 }
92
93 virtual void TearDown() override
94 {
95 wait_msec();
96
97 // close the bus
98 g_dbus_connection_close(m_bus, nullptr, on_bus_closed, this);
99 g_main_loop_run(m_loop);
100 g_clear_object(&m_bus);
101
102 // tear down the test dbus
103 g_test_dbus_down(m_test_dbus);
104 g_clear_object(&m_test_dbus);
105
106 super::TearDown();
107 }
108};
0109
=== modified file 'tests/test-notify.cc'
--- tests/test-notify.cc 2016-05-16 17:59:03 +0000
+++ tests/test-notify.cc 2016-05-26 20:21:58 +0000
@@ -17,8 +17,7 @@
17 * Charles Kerr <charles.kerr@canonical.com>17 * Charles Kerr <charles.kerr@canonical.com>
18 */18 */
1919
2020#include "test-dbus-fixture.h"
21#include "glib-fixture.h"
2221
23#include "dbus-shared.h"22#include "dbus-shared.h"
24#include "device.h"23#include "device.h"
@@ -26,181 +25,107 @@
2625
27#include <gtest/gtest.h>26#include <gtest/gtest.h>
2827
29#include <libdbustest/dbus-test.h>
30
31#include <libnotify/notify.h>28#include <libnotify/notify.h>
3229
33#include <glib.h>
34#include <gio/gio.h>30#include <gio/gio.h>
3531
36/***32/***
37****33****
38***/34***/
3935
40class NotifyFixture: public GlibFixture36class NotifyFixture: public TestDBusFixture
41{37{
42private:38 typedef TestDBusFixture super;
4339
44 typedef GlibFixture super;40 void start_unity7_notifications()
4541 {
46 static constexpr char const * NOTIFY_BUSNAME {"org.freedesktop.Notifications"};42 start_notifications("{ \"capabilities\": \""
47 static constexpr char const * NOTIFY_INTERFACE {"org.freedesktop.Notifications"};43 "append "
48 static constexpr char const * NOTIFY_PATH {"/org/freedesktop/Notifications"};44 "body "
4945 "body-markup "
50protected:46 "icon-static "
5147 "image/svg+xml "
52 DbusTestService * service = nullptr;48 "private-icon-only "
53 DbusTestDbusMock * mock = nullptr;49 "private-synchronous "
54 DbusTestDbusMockObject * obj = nullptr;50 "truncation "
55 GDBusConnection * bus = nullptr;51 "x-canonical-append "
5652 "x-canonical-private-icon-only "
57 static constexpr int FIRST_NOTIFY_ID {1234};53 "x-canonical-private-synchronous "
5854 "x-canonical-truncation"
59 static constexpr int NOTIFICATION_CLOSED_EXPIRED {1};55 "\" }"
60 static constexpr int NOTIFICATION_CLOSED_DISMISSED {2};56 );
61 static constexpr int NOTIFICATION_CLOSED_API {3};57 }
62 static constexpr int NOTIFICATION_CLOSED_UNDEFINED {4};58
6359 void start_unity8_notifications()
64 static constexpr char const * METHOD_CLOSE {"CloseNotification"};60 {
65 static constexpr char const * METHOD_NOTIFY {"Notify"};61 start_notifications("{ \"capabilities\": \""
66 static constexpr char const * METHOD_GET_CAPS {"GetCapabilities"};62 "body "
67 static constexpr char const * METHOD_GET_INFO {"GetServerInformation"};63 "body-markup "
68 static constexpr char const * SIGNAL_CLOSED {"NotificationClosed"};64 "icon-static "
6965 "image/svg+xml "
70 static constexpr char const * HINT_TIMEOUT {"x-canonical-snap-decisions-timeout"};66 "sound-file "
7167 "suppress-sound "
72protected:68 "urgency "
7369 "value "
74 void SetUp()70 "x-canonical-non-shaped-icon "
75 {71 "x-canonical-private-affirmative-tint "
76 super::SetUp();72 "x-canonical-private-icon-only "
7773 "x-canonical-private-menu-model "
78 g_setenv ("XDG_DATA_HOME", XDG_DATA_HOME, TRUE);74 "x-canonical-private-rejection-tint "
7975 "x-canonical-private-synchronous "
80 // init DBusMock / dbus-test-runner76 "x-canonical-secondary-icon "
8177 "x-canonical-snap-decisions "
82 service = dbus_test_service_new(nullptr);78 "x-canonical-snap-decisions-swipe "
8379 "x-canonical-snap-decisions-timeout "
84 GError * error = nullptr;80 "x-canonical-switch-to-application "
85 mock = dbus_test_dbus_mock_new(NOTIFY_BUSNAME);81 "x-canonical-truncation "
86 obj = dbus_test_dbus_mock_get_object(mock,82 "x-canonical-value-bar-tint"
87 NOTIFY_PATH,83 "\" }"
88 NOTIFY_INTERFACE,84 );
89 &error);85 }
90 g_assert_no_error (error);86
91 87 void start_notifications(const char* parameters)
92 // METHOD_GET_INFO 88 {
93 dbus_test_dbus_mock_object_add_method(mock, obj, METHOD_GET_INFO,89 std::array<const char*,8> child_argv = {
94 nullptr,90 "python3", "-m", "dbusmock",
95 G_VARIANT_TYPE("(ssss)"),91 "--template", "notification_daemon",
96 "ret = ('mock-notify', 'test vendor', '1.0', '1.1')",92 "--parameters", parameters,
97 &error);93 nullptr
98 g_assert_no_error (error);94 };
9995 GError* error {};
100 // METHOD_NOTIFY96 g_spawn_async(
101 auto str = g_strdup_printf("try:\n"97 nullptr /*working directory*/,
102 " self.NextNotifyId\n"98 const_cast<char**>(child_argv.data()),
103 "except AttributeError:\n"99 nullptr /*envp*/,
104 " self.NextNotifyId = %d\n"100 G_SPAWN_SEARCH_PATH,
105 "ret = self.NextNotifyId\n"101 nullptr /*child_setup*/,
106 "self.NextNotifyId += 1\n",102 nullptr /*user_data*/,
107 FIRST_NOTIFY_ID);103 nullptr /*child_pid*/,
108 dbus_test_dbus_mock_object_add_method(mock, obj, METHOD_NOTIFY,104 &error
109 G_VARIANT_TYPE("(susssasa{sv}i)"),105 );
110 G_VARIANT_TYPE_UINT32,106 g_assert_no_error(error);
111 str,107
112 &error);108 wait_for_name_owned(m_bus, "org.freedesktop.Notifications");
113 g_assert_no_error (error);109 }
114 g_free (str);110
115111
116 // METHOD_CLOSE 112protected:
117 str = g_strdup_printf("self.EmitSignal('%s', '%s', 'uu', [ args[0], %d ])",113
118 NOTIFY_INTERFACE,114 void SetUp() override
119 SIGNAL_CLOSED,115 {
120 NOTIFICATION_CLOSED_API);116 super::SetUp();
121 dbus_test_dbus_mock_object_add_method(mock, obj, METHOD_CLOSE,117
122 G_VARIANT_TYPE("(u)"),118 start_unity8_notifications();
123 nullptr,119
124 str,120 notify_init(G_LOG_DOMAIN);
125 &error);121 }
126 g_assert_no_error (error);122
127 g_free (str);123 void TearDown() override
128124 {
129 dbus_test_service_add_task(service, DBUS_TEST_TASK(mock));125 notify_uninit();
130 dbus_test_service_start_tasks(service);126
131127 super::TearDown();
132 bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr);128 }
133 g_dbus_connection_set_exit_on_close(bus, FALSE);
134 g_object_add_weak_pointer(G_OBJECT(bus), reinterpret_cast<gpointer*>(&bus));
135
136 notify_init(SERVICE_EXEC);
137 }
138
139 virtual void TearDown()
140 {
141 notify_uninit();
142
143 g_clear_object(&mock);
144 g_clear_object(&service);
145 g_object_unref(bus);
146
147 // wait a little while for the scaffolding to shut down,
148 // but don't block on it forever...
149 unsigned int cleartry = 0;
150 while ((bus != nullptr) && (cleartry < 50))
151 {
152 g_usleep(100000);
153 while (g_main_pending())
154 g_main_iteration(true);
155 cleartry++;
156 }
157
158 super::TearDown();
159 }
160
161 /***
162 ****
163 ***/
164
165 int get_notify_call_count() const
166 {
167 guint len {0u};
168 GError* error {nullptr};
169 dbus_test_dbus_mock_object_get_method_calls(mock, obj, METHOD_NOTIFY, &len, &error);
170 g_assert_no_error(error);
171 return len;
172 }
173
174 std::string get_notify_call_sound_file(int call_number)
175 {
176 std::string ret;
177
178 guint len {0u};
179 GError* error {nullptr};
180 auto calls = dbus_test_dbus_mock_object_get_method_calls(mock, obj, METHOD_NOTIFY, &len, &error);
181 g_return_val_if_fail(int(len) > call_number, ret);
182 g_assert_no_error(error);
183
184 constexpr int HINTS_PARAM_POSITION {6};
185 const auto& call = calls[call_number];
186 g_return_val_if_fail(g_variant_n_children(call.params) > HINTS_PARAM_POSITION, ret);
187 auto hints = g_variant_get_child_value(call.params, HINTS_PARAM_POSITION);
188 const gchar* sound_file = nullptr;
189 auto success = g_variant_lookup(hints, "sound-file", "&s", &sound_file);
190 g_return_val_if_fail(success, ret);
191 if (sound_file != nullptr)
192 ret = sound_file;
193 g_clear_pointer(&hints, g_variant_unref);
194
195 return ret;
196 }
197
198 void clear_method_calls()
199 {
200 GError* error{nullptr};
201 ASSERT_TRUE(dbus_test_dbus_mock_object_clear_method_calls(mock, obj, &error));
202 g_assert_no_error(error);
203 }
204};129};
205130
206/***131/***
@@ -216,7 +141,6 @@
216****141****
217***/142***/
218143
219
220namespace144namespace
221{145{
222 static constexpr double percent_critical {2.0};146 static constexpr double percent_critical {2.0};
@@ -319,11 +243,11 @@
319 // charge should show up on the bus.243 // charge should show up on the bus.
320 auto notifier = indicator_power_notifier_new ();244 auto notifier = indicator_power_notifier_new ();
321 indicator_power_notifier_set_battery (notifier, battery);245 indicator_power_notifier_set_battery (notifier, battery);
322 indicator_power_notifier_set_bus (notifier, bus);246 indicator_power_notifier_set_bus (notifier, m_bus);
323 wait_msec();247 wait_msec();
324248
325 ChangedParams changed_params;249 ChangedParams changed_params;
326 auto sub_tag = g_dbus_connection_signal_subscribe (bus,250 auto sub_tag = g_dbus_connection_signal_subscribe (m_bus,
327 nullptr,251 nullptr,
328 "org.freedesktop.DBus.Properties",252 "org.freedesktop.DBus.Properties",
329 "PropertiesChanged",253 "PropertiesChanged",
@@ -358,9 +282,9 @@
358 }282 }
359283
360 // cleanup284 // cleanup
361 g_dbus_connection_signal_unsubscribe (bus, sub_tag);285 g_dbus_connection_signal_unsubscribe (m_bus, sub_tag);
286 g_object_unref (notifier);
362 g_object_unref (battery);287 g_object_unref (battery);
363 g_object_unref (notifier);
364}288}
365289
366/***290/***
@@ -369,18 +293,6 @@
369293
370TEST_F(NotifyFixture, EventsThatChangeNotifications)294TEST_F(NotifyFixture, EventsThatChangeNotifications)
371{295{
372 // GetCapabilities returns an array containing 'actions', so that we'll
373 // get snap decisions and the 'IsWarning' property
374 GError * error = nullptr;
375 dbus_test_dbus_mock_object_add_method (mock,
376 obj,
377 METHOD_GET_CAPS,
378 nullptr,
379 G_VARIANT_TYPE_STRING_ARRAY,
380 "ret = ['actions', 'body']",
381 &error);
382 g_assert_no_error (error);
383
384 auto battery = indicator_power_device_new ("/object/path",296 auto battery = indicator_power_device_new ("/object/path",
385 UP_DEVICE_KIND_BATTERY,297 UP_DEVICE_KIND_BATTERY,
386 percent_low + 1.0,298 percent_low + 1.0,
@@ -397,9 +309,9 @@
397 // charge should show up on the bus.309 // charge should show up on the bus.
398 auto notifier = indicator_power_notifier_new ();310 auto notifier = indicator_power_notifier_new ();
399 indicator_power_notifier_set_battery (notifier, battery);311 indicator_power_notifier_set_battery (notifier, battery);
400 indicator_power_notifier_set_bus (notifier, bus);312 indicator_power_notifier_set_bus (notifier, m_bus);
401 ChangedParams changed_params;313 ChangedParams changed_params;
402 auto sub_tag = g_dbus_connection_signal_subscribe (bus,314 auto sub_tag = g_dbus_connection_signal_subscribe (m_bus,
403 nullptr,315 nullptr,
404 "org.freedesktop.DBus.Properties",316 "org.freedesktop.DBus.Properties",
405 "PropertiesChanged",317 "PropertiesChanged",
@@ -423,9 +335,6 @@
423 EXPECT_EQ (FIELD_POWER_LEVEL|FIELD_IS_WARNING, changed_params.fields);335 EXPECT_EQ (FIELD_POWER_LEVEL|FIELD_IS_WARNING, changed_params.fields);
424 EXPECT_EQ (indicator_power_notifier_get_power_level(battery), changed_params.power_level);336 EXPECT_EQ (indicator_power_notifier_get_power_level(battery), changed_params.power_level);
425 EXPECT_TRUE (changed_params.is_warning);337 EXPECT_TRUE (changed_params.is_warning);
426 EXPECT_EQ (1, get_notify_call_count());
427 EXPECT_EQ (low_power_uri, get_notify_call_sound_file(0));
428 clear_method_calls();
429338
430 // now test that the warning changes if the level goes down even lower...339 // now test that the warning changes if the level goes down even lower...
431 changed_params = ChangedParams();340 changed_params = ChangedParams();
@@ -433,9 +342,6 @@
433 wait_msec();342 wait_msec();
434 EXPECT_EQ (FIELD_POWER_LEVEL, changed_params.fields);343 EXPECT_EQ (FIELD_POWER_LEVEL, changed_params.fields);
435 EXPECT_STREQ (POWER_LEVEL_STR_VERY_LOW, changed_params.power_level.c_str());344 EXPECT_STREQ (POWER_LEVEL_STR_VERY_LOW, changed_params.power_level.c_str());
436 EXPECT_EQ (1, get_notify_call_count());
437 EXPECT_EQ (low_power_uri, get_notify_call_sound_file(0));
438 clear_method_calls();
439345
440 // ...and that the warning is taken down if the battery is plugged back in...346 // ...and that the warning is taken down if the battery is plugged back in...
441 changed_params = ChangedParams();347 changed_params = ChangedParams();
@@ -443,7 +349,6 @@
443 wait_msec();349 wait_msec();
444 EXPECT_EQ (FIELD_IS_WARNING, changed_params.fields);350 EXPECT_EQ (FIELD_IS_WARNING, changed_params.fields);
445 EXPECT_FALSE (changed_params.is_warning);351 EXPECT_FALSE (changed_params.is_warning);
446 EXPECT_EQ (0, get_notify_call_count());
447352
448 // ...and that it comes back if we unplug again...353 // ...and that it comes back if we unplug again...
449 changed_params = ChangedParams();354 changed_params = ChangedParams();
@@ -451,9 +356,6 @@
451 wait_msec();356 wait_msec();
452 EXPECT_EQ (FIELD_IS_WARNING, changed_params.fields);357 EXPECT_EQ (FIELD_IS_WARNING, changed_params.fields);
453 EXPECT_TRUE (changed_params.is_warning);358 EXPECT_TRUE (changed_params.is_warning);
454 EXPECT_EQ (1, get_notify_call_count());
455 EXPECT_EQ (low_power_uri, get_notify_call_sound_file(0));
456 clear_method_calls();
457359
458 // ...and that it's taken down if the power level is OK360 // ...and that it's taken down if the power level is OK
459 changed_params = ChangedParams();361 changed_params = ChangedParams();
@@ -462,10 +364,9 @@
462 EXPECT_EQ (FIELD_POWER_LEVEL|FIELD_IS_WARNING, changed_params.fields);364 EXPECT_EQ (FIELD_POWER_LEVEL|FIELD_IS_WARNING, changed_params.fields);
463 EXPECT_STREQ (POWER_LEVEL_STR_OK, changed_params.power_level.c_str());365 EXPECT_STREQ (POWER_LEVEL_STR_OK, changed_params.power_level.c_str());
464 EXPECT_FALSE (changed_params.is_warning);366 EXPECT_FALSE (changed_params.is_warning);
465 EXPECT_EQ (0, get_notify_call_count());
466367
467 // cleanup368 // cleanup
468 g_dbus_connection_signal_unsubscribe (bus, sub_tag);369 g_dbus_connection_signal_unsubscribe (m_bus, sub_tag);
469 g_object_unref (notifier);370 g_object_unref (notifier);
470 g_object_unref (battery);371 g_object_unref (battery);
471}372}

Subscribers

People subscribed via source and target branches