Merge lp:~charlesk/indicator-datetime/lp-1560960-use-dbusmock-timedated-template into lp:indicator-datetime/15.10
- lp-1560960-use-dbusmock-timedated-template
- Merge into trunk.15.10
Proposed by
Charles Kerr
Status: | Merged |
---|---|
Approved by: | Renato Araujo Oliveira Filho |
Approved revision: | 448 |
Merged at revision: | 443 |
Proposed branch: | lp:~charlesk/indicator-datetime/lp-1560960-use-dbusmock-timedated-template |
Merge into: | lp:indicator-datetime/15.10 |
Prerequisite: | lp:~charlesk/indicator-datetime/always-get-initial-tzid-from-timedate1 |
Diff against target: |
847 lines (+212/-394) 6 files modified
include/datetime/dbus-shared.h (+0/-8) src/actions-live.cpp (+5/-4) tests/glib-fixture.h (+16/-13) tests/test-live-actions.cpp (+76/-18) tests/test-timezone-timedated.cpp (+7/-100) tests/timedated-fixture.h (+108/-251) |
To merge this branch: | bzr merge lp:~charlesk/indicator-datetime/lp-1560960-use-dbusmock-timedated-template |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Charles Kerr (community) | Approve | ||
Renato Araujo Oliveira Filho (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Review via email: mp+291446@code.launchpad.net |
Commit message
Use dbusmock's timedated template in our tests
Description of the change
Minor patch on top of https:/
That branch added a test fixture which uses dbusmock's timedated template. This branch promotes that up to a shared test header where it can be reused by test-live-actions, and removes test-live-actions' previous handrolled timedated mock.
To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : | # |
review:
Approve
(continuous-integration)
Revision history for this message
Renato Araujo Oliveira Filho (renatofilho) wrote : | # |
looks good.
review:
Approve
Revision history for this message
Charles Kerr (charlesk) wrote : | # |
re-approving because the r449 was already approved in prerequisite branch
Revision history for this message
Charles Kerr (charlesk) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'include/datetime/dbus-shared.h' | |||
2 | --- include/datetime/dbus-shared.h 2016-04-12 17:27:17 +0000 | |||
3 | +++ include/datetime/dbus-shared.h 2016-04-12 17:27:17 +0000 | |||
4 | @@ -28,10 +28,6 @@ | |||
5 | 28 | #define BUS_POWERD_PATH "/com/canonical/powerd" | 28 | #define BUS_POWERD_PATH "/com/canonical/powerd" |
6 | 29 | #define BUS_POWERD_INTERFACE "com.canonical.powerd" | 29 | #define BUS_POWERD_INTERFACE "com.canonical.powerd" |
7 | 30 | 30 | ||
8 | 31 | namespace unity { | ||
9 | 32 | namespace indicator { | ||
10 | 33 | namespace datetime { | ||
11 | 34 | |||
12 | 35 | namespace Bus | 31 | namespace Bus |
13 | 36 | { | 32 | { |
14 | 37 | namespace Timedate1 | 33 | namespace Timedate1 |
15 | @@ -67,8 +63,4 @@ | |||
16 | 67 | } | 63 | } |
17 | 68 | } | 64 | } |
18 | 69 | 65 | ||
19 | 70 | } // namespace datetime | ||
20 | 71 | } // namespace indicator | ||
21 | 72 | } // namespace unity | ||
22 | 73 | |||
23 | 74 | #endif /* INDICATOR_DATETIME_DBUS_SHARED_H */ | 66 | #endif /* INDICATOR_DATETIME_DBUS_SHARED_H */ |
24 | 75 | 67 | ||
25 | === modified file 'src/actions-live.cpp' | |||
26 | --- src/actions-live.cpp 2016-04-05 21:00:09 +0000 | |||
27 | +++ src/actions-live.cpp 2016-04-12 17:27:17 +0000 | |||
28 | @@ -17,6 +17,7 @@ | |||
29 | 17 | * Charles Kerr <charles.kerr@canonical.com> | 17 | * Charles Kerr <charles.kerr@canonical.com> |
30 | 18 | */ | 18 | */ |
31 | 19 | 19 | ||
32 | 20 | #include <datetime/dbus-shared.h> | ||
33 | 20 | #include <datetime/actions-live.h> | 21 | #include <datetime/actions-live.h> |
34 | 21 | 22 | ||
35 | 22 | #include <url-dispatcher.h> | 23 | #include <url-dispatcher.h> |
36 | @@ -252,7 +253,7 @@ | |||
37 | 252 | else | 253 | else |
38 | 253 | { | 254 | { |
39 | 254 | g_dbus_proxy_call(proxy, | 255 | g_dbus_proxy_call(proxy, |
41 | 255 | "SetTimezone", | 256 | Bus::Timedate1::Methods::SET_TIMEZONE, |
42 | 256 | g_variant_new ("(sb)", data->tzid.c_str(), TRUE), | 257 | g_variant_new ("(sb)", data->tzid.c_str(), TRUE), |
43 | 257 | G_DBUS_CALL_FLAGS_NONE, | 258 | G_DBUS_CALL_FLAGS_NONE, |
44 | 258 | -1, | 259 | -1, |
45 | @@ -280,9 +281,9 @@ | |||
46 | 280 | g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, | 281 | g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, |
47 | 281 | G_DBUS_PROXY_FLAGS_NONE, | 282 | G_DBUS_PROXY_FLAGS_NONE, |
48 | 282 | nullptr, | 283 | nullptr, |
52 | 283 | "org.freedesktop.timedate1", | 284 | Bus::Timedate1::BUSNAME, |
53 | 284 | "/org/freedesktop/timedate1", | 285 | Bus::Timedate1::ADDR, |
54 | 285 | "org.freedesktop.timedate1", | 286 | Bus::Timedate1::IFACE, |
55 | 286 | nullptr, | 287 | nullptr, |
56 | 287 | on_datetime1_proxy_ready, | 288 | on_datetime1_proxy_ready, |
57 | 288 | data); | 289 | data); |
58 | 289 | 290 | ||
59 | === modified file 'tests/glib-fixture.h' | |||
60 | --- tests/glib-fixture.h 2016-02-10 20:47:39 +0000 | |||
61 | +++ tests/glib-fixture.h 2016-04-12 17:27:17 +0000 | |||
62 | @@ -125,10 +125,11 @@ | |||
63 | 125 | } | 125 | } |
64 | 126 | } | 126 | } |
65 | 127 | 127 | ||
70 | 128 | bool wait_for_name_owned(GDBusConnection* connection, | 128 | bool wait_for_name_owned( |
71 | 129 | const gchar* name, | 129 | GDBusConnection* connection, |
72 | 130 | guint timeout_msec=1000, | 130 | const gchar* name, |
73 | 131 | GBusNameWatcherFlags flags=G_BUS_NAME_WATCHER_FLAGS_AUTO_START) | 131 | guint timeout_msec=1000, |
74 | 132 | GBusNameWatcherFlags flags=G_BUS_NAME_WATCHER_FLAGS_AUTO_START) | ||
75 | 132 | { | 133 | { |
76 | 133 | struct Data { | 134 | struct Data { |
77 | 134 | GMainLoop* loop = nullptr; | 135 | GMainLoop* loop = nullptr; |
78 | @@ -139,8 +140,7 @@ | |||
79 | 139 | auto on_name_appeared = [](GDBusConnection* /*connection*/, | 140 | auto on_name_appeared = [](GDBusConnection* /*connection*/, |
80 | 140 | const gchar* /*name_*/, | 141 | const gchar* /*name_*/, |
81 | 141 | const gchar* name_owner, | 142 | const gchar* name_owner, |
84 | 142 | gpointer gdata) | 143 | gpointer gdata){ |
83 | 143 | { | ||
85 | 144 | if (name_owner == nullptr) | 144 | if (name_owner == nullptr) |
86 | 145 | return; | 145 | return; |
87 | 146 | auto tmp = static_cast<Data*>(gdata); | 146 | auto tmp = static_cast<Data*>(gdata); |
88 | @@ -150,13 +150,16 @@ | |||
89 | 150 | 150 | ||
90 | 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, loop); |
91 | 152 | data.loop = loop; | 152 | data.loop = loop; |
99 | 153 | const auto watch_id = g_bus_watch_name_on_connection(connection, | 153 | const auto watch_id = g_bus_watch_name_on_connection( |
100 | 154 | name, | 154 | connection, |
101 | 155 | flags, | 155 | name, |
102 | 156 | on_name_appeared, | 156 | flags, |
103 | 157 | nullptr, /* name_vanished */ | 157 | on_name_appeared, |
104 | 158 | &data, | 158 | nullptr, // name_vanished |
105 | 159 | nullptr); /* user_data_free_func */ | 159 | &data, |
106 | 160 | nullptr // user_data_free_func | ||
107 | 161 | ); | ||
108 | 162 | |||
109 | 160 | g_main_loop_run(loop); | 163 | g_main_loop_run(loop); |
110 | 161 | 164 | ||
111 | 162 | g_bus_unwatch_name(watch_id); | 165 | g_bus_unwatch_name(watch_id); |
112 | 163 | 166 | ||
113 | === modified file 'tests/test-live-actions.cpp' | |||
114 | --- tests/test-live-actions.cpp 2016-03-21 17:32:39 +0000 | |||
115 | +++ tests/test-live-actions.cpp 2016-04-12 17:27:17 +0000 | |||
116 | @@ -17,18 +17,75 @@ | |||
117 | 17 | * Charles Kerr <charles.kerr@canonical.com> | 17 | * Charles Kerr <charles.kerr@canonical.com> |
118 | 18 | */ | 18 | */ |
119 | 19 | 19 | ||
120 | 20 | #include "state-mock.h" | ||
121 | 20 | #include "timedated-fixture.h" | 21 | #include "timedated-fixture.h" |
122 | 21 | 22 | ||
123 | 23 | #include <datetime/actions-live.h> | ||
124 | 24 | |||
125 | 25 | using namespace unity::indicator::datetime; | ||
126 | 26 | |||
127 | 27 | class MockLiveActions: public LiveActions | ||
128 | 28 | { | ||
129 | 29 | public: | ||
130 | 30 | std::string last_cmd; | ||
131 | 31 | std::string last_url; | ||
132 | 32 | explicit MockLiveActions(const std::shared_ptr<State>& state_in): LiveActions(state_in) {} | ||
133 | 33 | ~MockLiveActions() {} | ||
134 | 34 | |||
135 | 35 | protected: | ||
136 | 36 | void dispatch_url(const std::string& url) override { last_url = url; } | ||
137 | 37 | void execute_command(const std::string& cmd) override { last_cmd = cmd; } | ||
138 | 38 | }; | ||
139 | 39 | |||
140 | 40 | class TestLiveActionsFixture: public TimedatedFixture | ||
141 | 41 | { | ||
142 | 42 | private: | ||
143 | 43 | |||
144 | 44 | using super = TimedatedFixture; | ||
145 | 45 | |||
146 | 46 | protected: | ||
147 | 47 | |||
148 | 48 | std::shared_ptr<MockState> m_mock_state; | ||
149 | 49 | std::shared_ptr<State> m_state; | ||
150 | 50 | std::shared_ptr<MockLiveActions> m_live_actions; | ||
151 | 51 | std::shared_ptr<Actions> m_actions; | ||
152 | 52 | |||
153 | 53 | void SetUp() override | ||
154 | 54 | { | ||
155 | 55 | super::SetUp(); | ||
156 | 56 | |||
157 | 57 | // create the State and Actions | ||
158 | 58 | m_mock_state.reset(new MockState); | ||
159 | 59 | m_mock_state->settings.reset(new Settings); | ||
160 | 60 | m_state = std::dynamic_pointer_cast<State>(m_mock_state); | ||
161 | 61 | m_live_actions.reset(new MockLiveActions(m_state)); | ||
162 | 62 | m_actions = std::dynamic_pointer_cast<Actions>(m_live_actions); | ||
163 | 63 | |||
164 | 64 | // start the timedate1 dbusmock | ||
165 | 65 | start_timedate1("Etc/Utc"); | ||
166 | 66 | } | ||
167 | 67 | |||
168 | 68 | void TearDown() override | ||
169 | 69 | { | ||
170 | 70 | m_actions.reset(); | ||
171 | 71 | m_live_actions.reset(); | ||
172 | 72 | m_state.reset(); | ||
173 | 73 | m_mock_state.reset(); | ||
174 | 74 | |||
175 | 75 | super::TearDown(); | ||
176 | 76 | } | ||
177 | 77 | }; | ||
178 | 78 | |||
179 | 22 | /*** | 79 | /*** |
180 | 23 | **** | 80 | **** |
181 | 24 | ***/ | 81 | ***/ |
182 | 25 | 82 | ||
184 | 26 | TEST_F(TimedateFixture, HelloWorld) | 83 | TEST_F(TestLiveActionsFixture, HelloWorld) |
185 | 27 | { | 84 | { |
186 | 28 | EXPECT_TRUE(true); | 85 | EXPECT_TRUE(true); |
187 | 29 | } | 86 | } |
188 | 30 | 87 | ||
190 | 31 | TEST_F(TimedateFixture, SetLocation) | 88 | TEST_F(TestLiveActionsFixture, SetLocation) |
191 | 32 | { | 89 | { |
192 | 33 | const std::string tzid = "America/Chicago"; | 90 | const std::string tzid = "America/Chicago"; |
193 | 34 | const std::string name = "Oklahoma City"; | 91 | const std::string name = "Oklahoma City"; |
194 | @@ -36,30 +93,31 @@ | |||
195 | 36 | 93 | ||
196 | 37 | EXPECT_NE(expected, m_state->settings->timezone_name.get()); | 94 | EXPECT_NE(expected, m_state->settings->timezone_name.get()); |
197 | 38 | 95 | ||
198 | 96 | std::string new_name; | ||
199 | 97 | m_state->settings->timezone_name.changed().connect( | ||
200 | 98 | [&new_name](const std::string& n){new_name = n;} | ||
201 | 99 | ); | ||
202 | 100 | |||
203 | 39 | m_actions->set_location(tzid, name); | 101 | m_actions->set_location(tzid, name); |
204 | 40 | m_state->settings->timezone_name.changed().connect( | ||
205 | 41 | [this](const std::string&){ | ||
206 | 42 | g_main_loop_quit(loop); | ||
207 | 43 | }); | ||
208 | 44 | g_main_loop_run(loop); | ||
209 | 45 | EXPECT_EQ(attempted_tzid, tzid); | ||
210 | 46 | wait_msec(); | ||
211 | 47 | 102 | ||
212 | 103 | EXPECT_TRUE(wait_for([&new_name](){return !new_name.empty();})); | ||
213 | 104 | EXPECT_EQ(expected, new_name); | ||
214 | 48 | EXPECT_EQ(expected, m_state->settings->timezone_name.get()); | 105 | EXPECT_EQ(expected, m_state->settings->timezone_name.get()); |
215 | 106 | EXPECT_EQ(tzid, get_timedate1_timezone()); | ||
216 | 49 | } | 107 | } |
217 | 50 | 108 | ||
218 | 51 | /*** | 109 | /*** |
219 | 52 | **** | 110 | **** |
220 | 53 | ***/ | 111 | ***/ |
221 | 54 | 112 | ||
223 | 55 | TEST_F(TimedateFixture, DesktopOpenAlarmApp) | 113 | TEST_F(TestLiveActionsFixture, DesktopOpenAlarmApp) |
224 | 56 | { | 114 | { |
225 | 57 | m_actions->desktop_open_alarm_app(); | 115 | m_actions->desktop_open_alarm_app(); |
226 | 58 | const std::string expected = "evolution -c calendar"; | 116 | const std::string expected = "evolution -c calendar"; |
227 | 59 | EXPECT_EQ(expected, m_live_actions->last_cmd); | 117 | EXPECT_EQ(expected, m_live_actions->last_cmd); |
228 | 60 | } | 118 | } |
229 | 61 | 119 | ||
231 | 62 | TEST_F(TimedateFixture, DesktopOpenAppointment) | 120 | TEST_F(TestLiveActionsFixture, DesktopOpenAppointment) |
232 | 63 | { | 121 | { |
233 | 64 | Appointment a; | 122 | Appointment a; |
234 | 65 | a.uid = "some-uid"; | 123 | a.uid = "some-uid"; |
235 | @@ -69,14 +127,14 @@ | |||
236 | 69 | EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); | 127 | EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); |
237 | 70 | } | 128 | } |
238 | 71 | 129 | ||
240 | 72 | TEST_F(TimedateFixture, DesktopOpenCalendarApp) | 130 | TEST_F(TestLiveActionsFixture, DesktopOpenCalendarApp) |
241 | 73 | { | 131 | { |
242 | 74 | m_actions->desktop_open_calendar_app(DateTime::NowLocal()); | 132 | m_actions->desktop_open_calendar_app(DateTime::NowLocal()); |
243 | 75 | const std::string expected_substr = "evolution \"calendar:///?startdate="; | 133 | const std::string expected_substr = "evolution \"calendar:///?startdate="; |
244 | 76 | EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); | 134 | EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); |
245 | 77 | } | 135 | } |
246 | 78 | 136 | ||
248 | 79 | TEST_F(TimedateFixture, DesktopOpenSettingsApp) | 137 | TEST_F(TestLiveActionsFixture, DesktopOpenSettingsApp) |
249 | 80 | { | 138 | { |
250 | 81 | m_actions->desktop_open_settings_app(); | 139 | m_actions->desktop_open_settings_app(); |
251 | 82 | const std::string expected_substr = "control-center"; | 140 | const std::string expected_substr = "control-center"; |
252 | @@ -92,13 +150,13 @@ | |||
253 | 92 | const std::string clock_app_url = "appid://com.ubuntu.clock/clock/current-user-version"; | 150 | const std::string clock_app_url = "appid://com.ubuntu.clock/clock/current-user-version"; |
254 | 93 | } | 151 | } |
255 | 94 | 152 | ||
257 | 95 | TEST_F(TimedateFixture, PhoneOpenAlarmApp) | 153 | TEST_F(TestLiveActionsFixture, PhoneOpenAlarmApp) |
258 | 96 | { | 154 | { |
259 | 97 | m_actions->phone_open_alarm_app(); | 155 | m_actions->phone_open_alarm_app(); |
260 | 98 | EXPECT_EQ(clock_app_url, m_live_actions->last_url); | 156 | EXPECT_EQ(clock_app_url, m_live_actions->last_url); |
261 | 99 | } | 157 | } |
262 | 100 | 158 | ||
264 | 101 | TEST_F(TimedateFixture, PhoneOpenAppointment) | 159 | TEST_F(TestLiveActionsFixture, PhoneOpenAppointment) |
265 | 102 | { | 160 | { |
266 | 103 | Appointment a; | 161 | Appointment a; |
267 | 104 | 162 | ||
268 | @@ -116,7 +174,7 @@ | |||
269 | 116 | EXPECT_EQ(clock_app_url, m_live_actions->last_url); | 174 | EXPECT_EQ(clock_app_url, m_live_actions->last_url); |
270 | 117 | } | 175 | } |
271 | 118 | 176 | ||
273 | 119 | TEST_F(TimedateFixture, PhoneOpenCalendarApp) | 177 | TEST_F(TestLiveActionsFixture, PhoneOpenCalendarApp) |
274 | 120 | { | 178 | { |
275 | 121 | auto now = DateTime::NowLocal(); | 179 | auto now = DateTime::NowLocal(); |
276 | 122 | m_actions->phone_open_calendar_app(now); | 180 | m_actions->phone_open_calendar_app(now); |
277 | @@ -125,7 +183,7 @@ | |||
278 | 125 | } | 183 | } |
279 | 126 | 184 | ||
280 | 127 | 185 | ||
282 | 128 | TEST_F(TimedateFixture, PhoneOpenSettingsApp) | 186 | TEST_F(TestLiveActionsFixture, PhoneOpenSettingsApp) |
283 | 129 | { | 187 | { |
284 | 130 | m_actions->phone_open_settings_app(); | 188 | m_actions->phone_open_settings_app(); |
285 | 131 | const std::string expected = "settings:///system/time-date"; | 189 | const std::string expected = "settings:///system/time-date"; |
286 | @@ -136,7 +194,7 @@ | |||
287 | 136 | **** | 194 | **** |
288 | 137 | ***/ | 195 | ***/ |
289 | 138 | 196 | ||
291 | 139 | TEST_F(TimedateFixture, CalendarState) | 197 | TEST_F(TestLiveActionsFixture, CalendarState) |
292 | 140 | { | 198 | { |
293 | 141 | // init the clock | 199 | // init the clock |
294 | 142 | auto now = DateTime::Local(2014, 1, 1, 0, 0, 0); | 200 | auto now = DateTime::Local(2014, 1, 1, 0, 0, 0); |
295 | 143 | 201 | ||
296 | === modified file 'tests/test-timezone-timedated.cpp' | |||
297 | --- tests/test-timezone-timedated.cpp 2016-04-12 17:27:17 +0000 | |||
298 | +++ tests/test-timezone-timedated.cpp 2016-04-12 17:27:17 +0000 | |||
299 | @@ -18,119 +18,26 @@ | |||
300 | 18 | * Ted Gould <ted.gould@canonical.com> | 18 | * Ted Gould <ted.gould@canonical.com> |
301 | 19 | */ | 19 | */ |
302 | 20 | 20 | ||
304 | 21 | #include "glib-fixture.h" | 21 | #include "timedated-fixture.h" |
305 | 22 | 22 | ||
306 | 23 | #include <datetime/dbus-shared.h> | ||
307 | 24 | #include <datetime/timezone-timedated.h> | 23 | #include <datetime/timezone-timedated.h> |
308 | 25 | 24 | ||
309 | 26 | #include <gio/gio.h> | ||
310 | 27 | |||
311 | 28 | |||
312 | 29 | using namespace unity::indicator::datetime; | 25 | using namespace unity::indicator::datetime; |
313 | 30 | 26 | ||
404 | 31 | 27 | using TestTimedatedFixture = TimedatedFixture; | |
315 | 32 | struct Timedate1Fixture: public GlibFixture | ||
316 | 33 | { | ||
317 | 34 | private: | ||
318 | 35 | |||
319 | 36 | typedef GlibFixture super; | ||
320 | 37 | |||
321 | 38 | protected: | ||
322 | 39 | |||
323 | 40 | GDBusConnection* m_bus {}; | ||
324 | 41 | GTestDBus* m_test_bus {}; | ||
325 | 42 | |||
326 | 43 | void SetUp() override | ||
327 | 44 | { | ||
328 | 45 | super::SetUp(); | ||
329 | 46 | |||
330 | 47 | // use a fake bus | ||
331 | 48 | m_test_bus = g_test_dbus_new(G_TEST_DBUS_NONE); | ||
332 | 49 | g_test_dbus_up(m_test_bus); | ||
333 | 50 | const char * address = g_test_dbus_get_bus_address(m_test_bus); | ||
334 | 51 | g_setenv("DBUS_SYSTEM_BUS_ADDRESS", address, true); | ||
335 | 52 | g_setenv("DBUS_SESSION_BUS_ADDRESS", address, true); | ||
336 | 53 | g_debug("test_dbus's address is %s", address); | ||
337 | 54 | |||
338 | 55 | // get the bus | ||
339 | 56 | m_bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); | ||
340 | 57 | g_dbus_connection_set_exit_on_close(m_bus, FALSE); | ||
341 | 58 | } | ||
342 | 59 | |||
343 | 60 | void TearDown() override | ||
344 | 61 | { | ||
345 | 62 | // tear down the bus | ||
346 | 63 | bool bus_finished = false; | ||
347 | 64 | g_object_weak_ref( | ||
348 | 65 | G_OBJECT(m_bus), | ||
349 | 66 | [](gpointer gbus_finished, GObject*){*static_cast<bool*>(gbus_finished) = true;}, | ||
350 | 67 | &bus_finished | ||
351 | 68 | ); | ||
352 | 69 | g_clear_object(&m_bus); | ||
353 | 70 | EXPECT_TRUE(wait_for([&bus_finished](){return bus_finished;})); | ||
354 | 71 | |||
355 | 72 | // tear down test bus | ||
356 | 73 | g_clear_object(&m_test_bus); | ||
357 | 74 | |||
358 | 75 | super::TearDown(); | ||
359 | 76 | } | ||
360 | 77 | |||
361 | 78 | void start_timedate1(const std::string& tzid) | ||
362 | 79 | { | ||
363 | 80 | // start dbusmock with the timedated template | ||
364 | 81 | auto json_parameters = g_strdup_printf("{\"Timezone\": \"%s\"}", tzid.c_str()); | ||
365 | 82 | const gchar* child_argv[] = { "python3", "-m", "dbusmock", "--template", "timedated", "--parameters", json_parameters, nullptr }; | ||
366 | 83 | GError* error = nullptr; | ||
367 | 84 | g_spawn_async(nullptr, (gchar**)child_argv, nullptr, G_SPAWN_SEARCH_PATH, nullptr, nullptr, nullptr, &error); | ||
368 | 85 | g_assert_no_error(error); | ||
369 | 86 | g_free(json_parameters); | ||
370 | 87 | |||
371 | 88 | // wait for it to appear on the bus | ||
372 | 89 | wait_for_name_owned(m_bus, Bus::Timedate1::BUSNAME); | ||
373 | 90 | } | ||
374 | 91 | |||
375 | 92 | bool wait_for_tzid(const std::string& tzid, Timezone& tz) | ||
376 | 93 | { | ||
377 | 94 | return wait_for([&tzid, &tz](){return tzid == tz.timezone.get();}); | ||
378 | 95 | } | ||
379 | 96 | |||
380 | 97 | void set_timedate1_timezone(const std::string& tzid) | ||
381 | 98 | { | ||
382 | 99 | GError* error {}; | ||
383 | 100 | auto v = g_dbus_connection_call_sync( | ||
384 | 101 | m_bus, | ||
385 | 102 | Bus::Timedate1::BUSNAME, | ||
386 | 103 | Bus::Timedate1::ADDR, | ||
387 | 104 | Bus::Timedate1::IFACE, | ||
388 | 105 | Bus::Timedate1::Methods::SET_TIMEZONE, | ||
389 | 106 | g_variant_new("(sb)", tzid.c_str(), FALSE), | ||
390 | 107 | nullptr, | ||
391 | 108 | G_DBUS_CALL_FLAGS_NONE, | ||
392 | 109 | -1, | ||
393 | 110 | nullptr, | ||
394 | 111 | &error); | ||
395 | 112 | g_clear_pointer(&v, g_variant_unref); | ||
396 | 113 | g_assert_no_error(error); | ||
397 | 114 | } | ||
398 | 115 | }; | ||
399 | 116 | |||
400 | 117 | #define EXPECT_TZID(expected_tzid, tmp) \ | ||
401 | 118 | EXPECT_TRUE(wait_for_tzid(expected_tzid, tmp)) \ | ||
402 | 119 | << "expected " << expected_tzid \ | ||
403 | 120 | << " got " << tmp.timezone.get(); | ||
405 | 121 | 28 | ||
406 | 122 | /*** | 29 | /*** |
407 | 123 | **** | 30 | **** |
408 | 124 | ***/ | 31 | ***/ |
409 | 125 | 32 | ||
411 | 126 | TEST_F(Timedate1Fixture, HelloWorld) | 33 | TEST_F(TestTimedatedFixture, HelloWorld) |
412 | 127 | { | 34 | { |
413 | 128 | } | 35 | } |
414 | 129 | 36 | ||
415 | 130 | /** | 37 | /** |
416 | 131 | * Test that the tzid is right if timedated isn't available | 38 | * Test that the tzid is right if timedated isn't available |
417 | 132 | */ | 39 | */ |
419 | 133 | TEST_F(Timedate1Fixture, DefaultTimezone) | 40 | TEST_F(TestTimedatedFixture, DefaultTimezone) |
420 | 134 | { | 41 | { |
421 | 135 | const std::string expected_tzid{"Etc/Utc"}; | 42 | const std::string expected_tzid{"Etc/Utc"}; |
422 | 136 | 43 | ||
423 | @@ -141,7 +48,7 @@ | |||
424 | 141 | /** | 48 | /** |
425 | 142 | * Test that the tzid is right if timedated shows BEFORE we start | 49 | * Test that the tzid is right if timedated shows BEFORE we start |
426 | 143 | */ | 50 | */ |
428 | 144 | TEST_F(Timedate1Fixture, Timedate1First) | 51 | TEST_F(TestTimedatedFixture, Timedate1First) |
429 | 145 | { | 52 | { |
430 | 146 | const std::string expected_tzid{"America/Chicago"}; | 53 | const std::string expected_tzid{"America/Chicago"}; |
431 | 147 | 54 | ||
432 | @@ -153,7 +60,7 @@ | |||
433 | 153 | /** | 60 | /** |
434 | 154 | * Test that the tzid is right if timedated shows AFTER we start | 61 | * Test that the tzid is right if timedated shows AFTER we start |
435 | 155 | */ | 62 | */ |
437 | 156 | TEST_F(Timedate1Fixture, Timedate1Last) | 63 | TEST_F(TestTimedatedFixture, Timedate1Last) |
438 | 157 | { | 64 | { |
439 | 158 | const std::string expected_tzid("America/Los_Angeles"); | 65 | const std::string expected_tzid("America/Los_Angeles"); |
440 | 159 | 66 | ||
441 | @@ -165,7 +72,7 @@ | |||
442 | 165 | /** | 72 | /** |
443 | 166 | * Test that the tzid is right if timedated's property changes | 73 | * Test that the tzid is right if timedated's property changes |
444 | 167 | */ | 74 | */ |
446 | 168 | TEST_F(Timedate1Fixture, TimezoneChange) | 75 | TEST_F(TestTimedatedFixture, TimezoneChange) |
447 | 169 | { | 76 | { |
448 | 170 | const std::vector<std::string> expected_tzids{"America/Los_Angeles", "America/Chicago", "Etc/Utc"}; | 77 | const std::vector<std::string> expected_tzids{"America/Los_Angeles", "America/Chicago", "Etc/Utc"}; |
449 | 171 | 78 | ||
450 | 172 | 79 | ||
451 | === modified file 'tests/timedated-fixture.h' | |||
452 | --- tests/timedated-fixture.h 2015-09-03 09:54:20 +0000 | |||
453 | +++ tests/timedated-fixture.h 2016-04-12 17:27:17 +0000 | |||
454 | @@ -17,285 +17,142 @@ | |||
455 | 17 | * Charles Kerr <charles.kerr@canonical.com> | 17 | * Charles Kerr <charles.kerr@canonical.com> |
456 | 18 | */ | 18 | */ |
457 | 19 | 19 | ||
460 | 20 | #ifndef INDICATOR_DATETIME_TESTS_TIMEDATED_FIXTURE_H | 20 | #pragma once |
459 | 21 | #define INDICATOR_DATETIME_TESTS_TIMEDATED_FIXTURE_H | ||
461 | 22 | 21 | ||
462 | 23 | #include <datetime/actions-live.h> | 22 | #include <datetime/actions-live.h> |
463 | 24 | 23 | ||
464 | 25 | #include "state-mock.h" | ||
465 | 26 | #include "glib-fixture.h" | 24 | #include "glib-fixture.h" |
466 | 27 | 25 | ||
481 | 28 | using namespace unity::indicator::datetime; | 26 | #include <datetime/dbus-shared.h> |
482 | 29 | 27 | #include <datetime/timezone.h> | |
469 | 30 | class MockLiveActions: public LiveActions | ||
470 | 31 | { | ||
471 | 32 | public: | ||
472 | 33 | std::string last_cmd; | ||
473 | 34 | std::string last_url; | ||
474 | 35 | explicit MockLiveActions(const std::shared_ptr<State>& state_in): LiveActions(state_in) {} | ||
475 | 36 | ~MockLiveActions() {} | ||
476 | 37 | |||
477 | 38 | protected: | ||
478 | 39 | void dispatch_url(const std::string& url) override { last_url = url; } | ||
479 | 40 | void execute_command(const std::string& cmd) override { last_cmd = cmd; } | ||
480 | 41 | }; | ||
483 | 42 | 28 | ||
484 | 43 | /*** | 29 | /*** |
485 | 44 | **** | 30 | **** |
486 | 45 | ***/ | 31 | ***/ |
487 | 46 | 32 | ||
491 | 47 | using namespace unity::indicator::datetime; | 33 | struct TimedatedFixture: public GlibFixture |
489 | 48 | |||
490 | 49 | class TimedateFixture: public GlibFixture | ||
492 | 50 | { | 34 | { |
493 | 51 | private: | 35 | private: |
494 | 52 | 36 | ||
629 | 53 | typedef GlibFixture super; | 37 | using super = GlibFixture; |
496 | 54 | |||
497 | 55 | static GVariant * timedate1_get_properties (GDBusConnection * /*connection*/ , | ||
498 | 56 | const gchar * /*sender*/, | ||
499 | 57 | const gchar * /*object_path*/, | ||
500 | 58 | const gchar * /*interface_name*/, | ||
501 | 59 | const gchar *property_name, | ||
502 | 60 | GError ** /*error*/, | ||
503 | 61 | gpointer gself) | ||
504 | 62 | |||
505 | 63 | { | ||
506 | 64 | auto self = static_cast<TimedateFixture*>(gself); | ||
507 | 65 | g_debug("get_properties called"); | ||
508 | 66 | if (g_strcmp0(property_name, "Timezone") == 0) | ||
509 | 67 | { | ||
510 | 68 | g_debug("timezone requested, giving '%s'", | ||
511 | 69 | self->attempted_tzid.c_str()); | ||
512 | 70 | return g_variant_new_string(self->attempted_tzid.c_str()); | ||
513 | 71 | } | ||
514 | 72 | return nullptr; | ||
515 | 73 | } | ||
516 | 74 | |||
517 | 75 | |||
518 | 76 | static void on_bus_acquired(GDBusConnection* conn, | ||
519 | 77 | const gchar* name, | ||
520 | 78 | gpointer gself) | ||
521 | 79 | { | ||
522 | 80 | auto self = static_cast<TimedateFixture*>(gself); | ||
523 | 81 | g_debug("bus acquired: %s, connection is %p", name, conn); | ||
524 | 82 | |||
525 | 83 | /* Set up a fake timedated which handles setting and getting the | ||
526 | 84 | ** timezone | ||
527 | 85 | */ | ||
528 | 86 | static const GDBusInterfaceVTable vtable = { | ||
529 | 87 | timedate1_handle_method_call, | ||
530 | 88 | timedate1_get_properties, /* GetProperty */ | ||
531 | 89 | nullptr, /* SetProperty */ | ||
532 | 90 | }; | ||
533 | 91 | |||
534 | 92 | self->connection = G_DBUS_CONNECTION(g_object_ref(G_OBJECT(conn))); | ||
535 | 93 | |||
536 | 94 | GError* error = nullptr; | ||
537 | 95 | self->object_register_id = g_dbus_connection_register_object( | ||
538 | 96 | conn, | ||
539 | 97 | "/org/freedesktop/timedate1", | ||
540 | 98 | self->node_info->interfaces[0], | ||
541 | 99 | &vtable, | ||
542 | 100 | self, | ||
543 | 101 | nullptr, | ||
544 | 102 | &error); | ||
545 | 103 | g_assert_no_error(error); | ||
546 | 104 | } | ||
547 | 105 | |||
548 | 106 | static void on_name_acquired(GDBusConnection* conn, | ||
549 | 107 | const gchar* name, | ||
550 | 108 | gpointer gself) | ||
551 | 109 | { | ||
552 | 110 | g_debug("on_name_acquired"); | ||
553 | 111 | auto self = static_cast<TimedateFixture*>(gself); | ||
554 | 112 | self->name_acquired = true; | ||
555 | 113 | self->proxy = g_dbus_proxy_new_sync(conn, | ||
556 | 114 | G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, | ||
557 | 115 | nullptr, | ||
558 | 116 | name, | ||
559 | 117 | "/org/freedesktop/timedate1", | ||
560 | 118 | "org.freedesktop.timedate1", | ||
561 | 119 | nullptr, | ||
562 | 120 | nullptr); | ||
563 | 121 | g_main_loop_quit(self->loop); | ||
564 | 122 | } | ||
565 | 123 | |||
566 | 124 | static void on_name_lost(GDBusConnection* /*conn*/, | ||
567 | 125 | const gchar* /*name*/, | ||
568 | 126 | gpointer gself) | ||
569 | 127 | { | ||
570 | 128 | g_debug("on_name_lost"); | ||
571 | 129 | auto self = static_cast<TimedateFixture*>(gself); | ||
572 | 130 | self->name_acquired = false; | ||
573 | 131 | } | ||
574 | 132 | |||
575 | 133 | static void on_bus_closed(GObject* /*object*/, | ||
576 | 134 | GAsyncResult* res, | ||
577 | 135 | gpointer gself) | ||
578 | 136 | { | ||
579 | 137 | g_debug("on_bus_closed"); | ||
580 | 138 | auto self = static_cast<TimedateFixture*>(gself); | ||
581 | 139 | GError* err = nullptr; | ||
582 | 140 | g_dbus_connection_close_finish(self->connection, res, &err); | ||
583 | 141 | g_assert_no_error(err); | ||
584 | 142 | g_main_loop_quit(self->loop); | ||
585 | 143 | } | ||
586 | 144 | |||
587 | 145 | static void | ||
588 | 146 | timedate1_handle_method_call(GDBusConnection * connection, | ||
589 | 147 | const gchar * /*sender*/, | ||
590 | 148 | const gchar * object_path, | ||
591 | 149 | const gchar * interface_name, | ||
592 | 150 | const gchar * method_name, | ||
593 | 151 | GVariant * parameters, | ||
594 | 152 | GDBusMethodInvocation * invocation, | ||
595 | 153 | gpointer gself) | ||
596 | 154 | { | ||
597 | 155 | g_assert(!g_strcmp0(method_name, "SetTimezone")); | ||
598 | 156 | g_assert(g_variant_is_of_type(parameters, G_VARIANT_TYPE_TUPLE)); | ||
599 | 157 | g_assert(2 == g_variant_n_children(parameters)); | ||
600 | 158 | |||
601 | 159 | auto child = g_variant_get_child_value(parameters, 0); | ||
602 | 160 | g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_STRING)); | ||
603 | 161 | auto self = static_cast<TimedateFixture*>(gself); | ||
604 | 162 | self->attempted_tzid = g_variant_get_string(child, nullptr); | ||
605 | 163 | g_debug("set tz (dbus side): '%s'", self->attempted_tzid.c_str()); | ||
606 | 164 | g_dbus_method_invocation_return_value(invocation, nullptr); | ||
607 | 165 | |||
608 | 166 | /* Send PropertiesChanged */ | ||
609 | 167 | GError * local_error = nullptr; | ||
610 | 168 | auto builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY); | ||
611 | 169 | g_variant_builder_add (builder, | ||
612 | 170 | "{sv}", | ||
613 | 171 | "Timezone", | ||
614 | 172 | g_variant_new_string( | ||
615 | 173 | self->attempted_tzid.c_str())); | ||
616 | 174 | g_dbus_connection_emit_signal (connection, | ||
617 | 175 | NULL, | ||
618 | 176 | object_path, | ||
619 | 177 | "org.freedesktop.DBus.Properties", | ||
620 | 178 | "PropertiesChanged", | ||
621 | 179 | g_variant_new ("(sa{sv}as)", | ||
622 | 180 | interface_name, | ||
623 | 181 | builder, | ||
624 | 182 | NULL), | ||
625 | 183 | &local_error); | ||
626 | 184 | g_assert_no_error (local_error); | ||
627 | 185 | g_variant_unref(child); | ||
628 | 186 | } | ||
630 | 187 | 38 | ||
631 | 188 | protected: | 39 | protected: |
632 | 189 | 40 | ||
649 | 190 | std::shared_ptr<MockState> m_mock_state; | 41 | GDBusConnection* m_bus {}; |
650 | 191 | std::shared_ptr<State> m_state; | 42 | GTestDBus* m_test_bus {}; |
651 | 192 | std::shared_ptr<MockLiveActions> m_live_actions; | 43 | |
652 | 193 | std::shared_ptr<Actions> m_actions; | 44 | virtual void SetUp() override |
637 | 194 | |||
638 | 195 | bool name_acquired; | ||
639 | 196 | std::string attempted_tzid; | ||
640 | 197 | |||
641 | 198 | GTestDBus* bus; | ||
642 | 199 | guint own_name; | ||
643 | 200 | GDBusConnection* connection; | ||
644 | 201 | GDBusNodeInfo* node_info; | ||
645 | 202 | int object_register_id; | ||
646 | 203 | GDBusProxy *proxy; | ||
647 | 204 | |||
648 | 205 | void SetUp() | ||
653 | 206 | { | 45 | { |
654 | 207 | super::SetUp(); | 46 | super::SetUp(); |
669 | 208 | g_debug("SetUp"); | 47 | |
670 | 209 | 48 | // use a fake bus | |
671 | 210 | name_acquired = false; | 49 | m_test_bus = g_test_dbus_new(G_TEST_DBUS_NONE); |
672 | 211 | attempted_tzid.clear(); | 50 | g_test_dbus_up(m_test_bus); |
673 | 212 | connection = nullptr; | 51 | const char * address = g_test_dbus_get_bus_address(m_test_bus); |
660 | 213 | node_info = nullptr; | ||
661 | 214 | object_register_id = 0; | ||
662 | 215 | own_name = 0; | ||
663 | 216 | proxy = nullptr; | ||
664 | 217 | |||
665 | 218 | // bring up the test bus | ||
666 | 219 | bus = g_test_dbus_new(G_TEST_DBUS_NONE); | ||
667 | 220 | g_test_dbus_up(bus); | ||
668 | 221 | const auto address = g_test_dbus_get_bus_address(bus); | ||
674 | 222 | g_setenv("DBUS_SYSTEM_BUS_ADDRESS", address, true); | 52 | g_setenv("DBUS_SYSTEM_BUS_ADDRESS", address, true); |
675 | 223 | g_setenv("DBUS_SESSION_BUS_ADDRESS", address, true); | 53 | g_setenv("DBUS_SESSION_BUS_ADDRESS", address, true); |
676 | 224 | g_debug("test_dbus's address is %s", address); | 54 | g_debug("test_dbus's address is %s", address); |
677 | 225 | 55 | ||
716 | 226 | // parse the org.freedesktop.timedate1 interface | 56 | // get the bus |
717 | 227 | const gchar introspection_xml[] = | 57 | m_bus = g_bus_get_sync(G_BUS_TYPE_SESSION, nullptr, nullptr); |
718 | 228 | "<node>" | 58 | g_dbus_connection_set_exit_on_close(m_bus, FALSE); |
719 | 229 | " <interface name='org.freedesktop.timedate1'>" | 59 | g_object_add_weak_pointer(G_OBJECT(m_bus), (gpointer*)&m_bus); |
682 | 230 | " <property name='Timezone' type='s' access='read' />" | ||
683 | 231 | " <method name='SetTimezone'>" | ||
684 | 232 | " <arg name='timezone' type='s' direction='in'/>" | ||
685 | 233 | " <arg name='user_interaction' type='b' direction='in'/>" | ||
686 | 234 | " </method>" | ||
687 | 235 | " </interface>" | ||
688 | 236 | "</node>"; | ||
689 | 237 | node_info = g_dbus_node_info_new_for_xml(introspection_xml, nullptr); | ||
690 | 238 | ASSERT_TRUE(node_info != nullptr); | ||
691 | 239 | ASSERT_TRUE(node_info->interfaces != nullptr); | ||
692 | 240 | ASSERT_TRUE(node_info->interfaces[0] != nullptr); | ||
693 | 241 | ASSERT_TRUE(node_info->interfaces[1] == nullptr); | ||
694 | 242 | ASSERT_STREQ("org.freedesktop.timedate1", node_info->interfaces[0]->name); | ||
695 | 243 | |||
696 | 244 | // own the bus | ||
697 | 245 | own_name = g_bus_own_name(G_BUS_TYPE_SYSTEM, | ||
698 | 246 | "org.freedesktop.timedate1", | ||
699 | 247 | G_BUS_NAME_OWNER_FLAGS_NONE, | ||
700 | 248 | on_bus_acquired, on_name_acquired, on_name_lost, | ||
701 | 249 | this, nullptr); | ||
702 | 250 | ASSERT_TRUE(object_register_id == 0); | ||
703 | 251 | ASSERT_FALSE(name_acquired); | ||
704 | 252 | ASSERT_TRUE(connection == nullptr); | ||
705 | 253 | g_main_loop_run(loop); | ||
706 | 254 | ASSERT_TRUE(object_register_id != 0); | ||
707 | 255 | ASSERT_TRUE(name_acquired); | ||
708 | 256 | ASSERT_TRUE(G_IS_DBUS_CONNECTION(connection)); | ||
709 | 257 | |||
710 | 258 | // create the State and Actions | ||
711 | 259 | m_mock_state.reset(new MockState); | ||
712 | 260 | m_mock_state->settings.reset(new Settings); | ||
713 | 261 | m_state = std::dynamic_pointer_cast<State>(m_mock_state); | ||
714 | 262 | m_live_actions.reset(new MockLiveActions(m_state)); | ||
715 | 263 | m_actions = std::dynamic_pointer_cast<Actions>(m_live_actions); | ||
720 | 264 | } | 60 | } |
721 | 265 | 61 | ||
723 | 266 | void TearDown() | 62 | virtual void TearDown() override |
724 | 267 | { | 63 | { |
739 | 268 | g_debug("TearDown"); | 64 | // take down the bus |
740 | 269 | m_actions.reset(); | 65 | bool bus_finished = false; |
741 | 270 | m_live_actions.reset(); | 66 | g_object_weak_ref( |
742 | 271 | m_state.reset(); | 67 | G_OBJECT(m_bus), |
743 | 272 | m_mock_state.reset(); | 68 | [](gpointer gbus_finished, GObject*){*static_cast<bool*>(gbus_finished) = true;}, |
744 | 273 | g_dbus_connection_unregister_object(connection, object_register_id); | 69 | &bus_finished |
745 | 274 | g_object_unref(proxy); | 70 | ); |
746 | 275 | g_dbus_node_info_unref(node_info); | 71 | g_clear_object(&m_bus); |
747 | 276 | g_bus_unown_name(own_name); | 72 | EXPECT_TRUE(wait_for([&bus_finished](){return bus_finished;})); |
748 | 277 | g_dbus_connection_close(connection, nullptr, on_bus_closed, this); | 73 | |
749 | 278 | g_main_loop_run(loop); | 74 | // take down the GTestBus |
750 | 279 | g_clear_object(&connection); | 75 | g_clear_object(&m_test_bus); |
737 | 280 | g_test_dbus_down(bus); | ||
738 | 281 | g_clear_object(&bus); | ||
751 | 282 | 76 | ||
752 | 283 | super::TearDown(); | 77 | super::TearDown(); |
753 | 284 | } | 78 | } |
767 | 285 | public: | 79 | |
768 | 286 | void set_timezone(std::string tz) | 80 | void start_timedate1(const std::string& tzid) |
769 | 287 | { | 81 | { |
770 | 288 | g_debug("set_timezone: '%s'", tz.c_str()); | 82 | // start dbusmock with the timedated template |
771 | 289 | g_dbus_proxy_call_sync(proxy, | 83 | auto json_parameters = g_strdup_printf("{\"Timezone\": \"%s\"}", tzid.c_str()); |
772 | 290 | "SetTimezone", | 84 | const gchar* child_argv[] = { |
773 | 291 | g_variant_new("(sb)", | 85 | "python3", "-m", "dbusmock", |
774 | 292 | tz.c_str(), | 86 | "--template", "timedated", |
775 | 293 | FALSE), | 87 | "--parameters", json_parameters, |
776 | 294 | G_DBUS_CALL_FLAGS_NONE, | 88 | nullptr |
777 | 295 | 500, | 89 | }; |
778 | 296 | nullptr, | 90 | GError* error = nullptr; |
779 | 297 | nullptr); | 91 | g_spawn_async(nullptr, (gchar**)child_argv, nullptr, G_SPAWN_SEARCH_PATH, nullptr, nullptr, nullptr, &error); |
780 | 92 | g_assert_no_error(error); | ||
781 | 93 | g_free(json_parameters); | ||
782 | 94 | |||
783 | 95 | // wait for it to appear on the bus | ||
784 | 96 | wait_for_name_owned(m_bus, Bus::Timedate1::BUSNAME); | ||
785 | 97 | } | ||
786 | 98 | |||
787 | 99 | bool wait_for_tzid(const std::string& tzid, unity::indicator::datetime::Timezone& tz) | ||
788 | 100 | { | ||
789 | 101 | return wait_for([&tzid, &tz](){return tzid == tz.timezone.get();}); | ||
790 | 102 | } | ||
791 | 103 | |||
792 | 104 | void set_timedate1_timezone(const std::string& tzid) | ||
793 | 105 | { | ||
794 | 106 | GError* error {}; | ||
795 | 107 | auto v = g_dbus_connection_call_sync( | ||
796 | 108 | m_bus, | ||
797 | 109 | Bus::Timedate1::BUSNAME, | ||
798 | 110 | Bus::Timedate1::ADDR, | ||
799 | 111 | Bus::Timedate1::IFACE, | ||
800 | 112 | Bus::Timedate1::Methods::SET_TIMEZONE, | ||
801 | 113 | g_variant_new("(sb)", tzid.c_str(), FALSE), | ||
802 | 114 | nullptr, | ||
803 | 115 | G_DBUS_CALL_FLAGS_NONE, | ||
804 | 116 | -1, | ||
805 | 117 | nullptr, | ||
806 | 118 | &error); | ||
807 | 119 | g_assert_no_error(error); | ||
808 | 120 | |||
809 | 121 | g_clear_pointer(&v, g_variant_unref); | ||
810 | 122 | } | ||
811 | 123 | |||
812 | 124 | std::string get_timedate1_timezone() | ||
813 | 125 | { | ||
814 | 126 | GError* error {}; | ||
815 | 127 | auto v = g_dbus_connection_call_sync( | ||
816 | 128 | m_bus, | ||
817 | 129 | Bus::Timedate1::BUSNAME, | ||
818 | 130 | Bus::Timedate1::ADDR, | ||
819 | 131 | Bus::Properties::IFACE, | ||
820 | 132 | Bus::Properties::Methods::GET, | ||
821 | 133 | g_variant_new("(ss)", Bus::Timedate1::IFACE, Bus::Timedate1::Properties::TIMEZONE), | ||
822 | 134 | G_VARIANT_TYPE("(v)"), | ||
823 | 135 | G_DBUS_CALL_FLAGS_NONE, | ||
824 | 136 | -1, | ||
825 | 137 | nullptr, | ||
826 | 138 | &error); | ||
827 | 139 | g_assert_no_error(error); | ||
828 | 140 | |||
829 | 141 | GVariant* tzv {}; | ||
830 | 142 | g_variant_get(v, "(v)", &tzv); | ||
831 | 143 | std::string tzid; | ||
832 | 144 | const char* tz = g_variant_get_string(tzv, nullptr); | ||
833 | 145 | if (tz != nullptr) | ||
834 | 146 | tzid = tz; | ||
835 | 147 | |||
836 | 148 | g_clear_pointer(&tzv, g_variant_unref); | ||
837 | 149 | g_clear_pointer(&v, g_variant_unref); | ||
838 | 150 | return tzid; | ||
839 | 298 | } | 151 | } |
840 | 299 | }; | 152 | }; |
841 | 300 | 153 | ||
843 | 301 | #endif | 154 | #define EXPECT_TZID(expected_tzid, tmp) \ |
844 | 155 | EXPECT_TRUE(wait_for_tzid(expected_tzid, tmp)) \ | ||
845 | 156 | << "expected " << expected_tzid \ | ||
846 | 157 | << " got " << tmp.timezone.get(); | ||
847 | 158 |
PASSED: Continuous integration, rev:448 jenkins. qa.ubuntu. com/job/ indicator- datetime- ci/372/ jenkins. qa.ubuntu. com/job/ indicator- datetime- wily-amd64- ci/62 jenkins. qa.ubuntu. com/job/ indicator- datetime- wily-armhf- ci/62 jenkins. qa.ubuntu. com/job/ indicator- datetime- wily-armhf- ci/62/artifact/ work/output/ *zip*/output. zip
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
deb: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/indicator- datetime- ci/372/ rebuild
http://