Merge lp:~larsu/indicator-datetime/remove-test-warnings into lp:indicator-datetime/15.10
- remove-test-warnings
- Merge into trunk.15.10
Status: | Superseded |
---|---|
Proposed branch: | lp:~larsu/indicator-datetime/remove-test-warnings |
Merge into: | lp:indicator-datetime/15.10 |
Diff against target: |
1348 lines (+548/-396) 12 files modified
include/datetime/timezone-timedated.h (+10/-8) include/datetime/timezones-live.h (+4/-4) src/CMakeLists.txt (+2/-3) src/main.cpp (+3/-3) src/timezone-timedated.cpp (+155/-63) src/timezones-live.cpp (+2/-3) tests/CMakeLists.txt (+2/-1) tests/glib-fixture.h (+9/-41) tests/test-live-actions.cpp (+21/-227) tests/test-timezone-timedated.cpp (+38/-42) tests/test-utils.cpp (+1/-1) tests/timedated-fixture.h (+301/-0) |
To merge this branch: | bzr merge lp:~larsu/indicator-datetime/remove-test-warnings |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
PS Jenkins bot (community) | continuous-integration | Needs Fixing | |
Indicator Applet Developers | Pending | ||
Review via email: mp+270062@code.launchpad.net |
This proposal has been superseded by a proposal from 2015-09-03.
Commit message
Description of the change
Remove warnings from test logs
Swallow the ones that are expected and fail the test if they don't show up. In addition, fail tests if unexpected warnings show up again.
Also remove some dead code that dealt with counting log emissions.
PS Jenkins bot (ps-jenkins) wrote : | # |
- 426. By Lars Karlitski
-
timezone-timedated: subscribe to PropertiesChanged directly
This avoids some unnecessary calls that GDBusProxy makes and the name
watching. - 427. By Lars Karlitski
-
test-utils: don't pass NULL as gsettings string value
NULL is not a valid string. Use the empty string instead.
- 428. By Lars Karlitski
-
glib-fixture: fail tests on unexpected warnings
This requires specifying which warnings are expected to be thrown (only
test-timezone-file needed this for now).However, only fail on warnings in the Indicator-Datetime log domain so
that we don't fail on gstreamer (or other library) warnings for now. - 429. By Lars Karlitski
-
state-fixture: use TestDBusFixture for system bus
Unmerged revisions
Preview Diff
1 | === renamed file 'include/datetime/timezone-file.h' => 'include/datetime/timezone-timedated.h' |
2 | --- include/datetime/timezone-file.h 2014-09-13 20:45:23 +0000 |
3 | +++ include/datetime/timezone-timedated.h 2015-09-03 14:15:27 +0000 |
4 | @@ -17,8 +17,10 @@ |
5 | * Charles Kerr <charles.kerr@canonical.com> |
6 | */ |
7 | |
8 | -#ifndef INDICATOR_DATETIME_FILE_TIMEZONE_H |
9 | -#define INDICATOR_DATETIME_FILE_TIMEZONE_H |
10 | +#ifndef INDICATOR_DATETIME_TIMEDATED_TIMEZONE_H |
11 | +#define INDICATOR_DATETIME_TIMEDATED_TIMEZONE_H |
12 | + |
13 | +#define DEFAULT_FILENAME "/etc/timezone" |
14 | |
15 | #include <datetime/timezone.h> // base class |
16 | |
17 | @@ -31,11 +33,11 @@ |
18 | /** |
19 | * \brief A #Timezone that gets its information from monitoring a file, such as /etc/timezone |
20 | */ |
21 | -class FileTimezone: public Timezone |
22 | +class TimedatedTimezone: public Timezone |
23 | { |
24 | public: |
25 | - FileTimezone(const std::string& filename); |
26 | - ~FileTimezone(); |
27 | + TimedatedTimezone(std::string filename = DEFAULT_FILENAME); |
28 | + ~TimedatedTimezone(); |
29 | |
30 | private: |
31 | class Impl; |
32 | @@ -43,12 +45,12 @@ |
33 | std::unique_ptr<Impl> impl; |
34 | |
35 | // we have pointers in here, so disable copying |
36 | - FileTimezone(const FileTimezone&) =delete; |
37 | - FileTimezone& operator=(const FileTimezone&) =delete; |
38 | + TimedatedTimezone(const TimedatedTimezone&) =delete; |
39 | + TimedatedTimezone& operator=(const TimedatedTimezone&) =delete; |
40 | }; |
41 | |
42 | } // namespace datetime |
43 | } // namespace indicator |
44 | } // namespace unity |
45 | |
46 | -#endif // INDICATOR_DATETIME_FILE_TIMEZONE_H |
47 | +#endif // INDICATOR_DATETIME_TIMEDATED_TIMEZONE_H |
48 | |
49 | === modified file 'include/datetime/timezones-live.h' |
50 | --- include/datetime/timezones-live.h 2014-01-30 19:44:12 +0000 |
51 | +++ include/datetime/timezones-live.h 2015-09-03 14:15:27 +0000 |
52 | @@ -22,8 +22,8 @@ |
53 | |
54 | #include <datetime/settings.h> |
55 | #include <datetime/timezones.h> |
56 | -#include <datetime/timezone-file.h> |
57 | #include <datetime/timezone-geoclue.h> |
58 | +#include <datetime/timezone-timedated.h> |
59 | |
60 | #include <memory> // shared_ptr<> |
61 | |
62 | @@ -32,19 +32,19 @@ |
63 | namespace datetime { |
64 | |
65 | /** |
66 | - * \brief #Timezones object that uses a #FileTimezone and #GeoclueTimezone |
67 | + * \brief #Timezones object that uses a #TimedatedTimezone and #GeoclueTimezone |
68 | * to detect what timezone we're in |
69 | */ |
70 | class LiveTimezones: public Timezones |
71 | { |
72 | public: |
73 | - LiveTimezones(const std::shared_ptr<const Settings>& settings, const std::string& filename); |
74 | + LiveTimezones(const std::shared_ptr<const Settings>& settings); |
75 | |
76 | private: |
77 | void update_geolocation(); |
78 | void update_timezones(); |
79 | |
80 | - FileTimezone m_file; |
81 | + TimedatedTimezone m_file; |
82 | std::shared_ptr<const Settings> m_settings; |
83 | std::shared_ptr<GeoclueTimezone> m_geo; |
84 | }; |
85 | |
86 | === modified file 'src/CMakeLists.txt' |
87 | --- src/CMakeLists.txt 2015-01-21 20:25:52 +0000 |
88 | +++ src/CMakeLists.txt 2015-09-03 14:15:27 +0000 |
89 | @@ -1,8 +1,7 @@ |
90 | set (SERVICE_LIB "indicatordatetimeservice") |
91 | set (SERVICE_EXEC "indicator-datetime-service") |
92 | |
93 | -add_definitions (-DTIMEZONE_FILE="/etc/timezone" |
94 | - -DG_LOG_DOMAIN="Indicator-Datetime") |
95 | +add_definitions (-DG_LOG_DOMAIN="Indicator-Datetime") |
96 | |
97 | # handwritten sources |
98 | set (SERVICE_C_SOURCES |
99 | @@ -34,9 +33,9 @@ |
100 | settings-live.cpp |
101 | snap.cpp |
102 | sound.cpp |
103 | - timezone-file.cpp |
104 | timezone-geoclue.cpp |
105 | timezones-live.cpp |
106 | + timezone-timedated.cpp |
107 | utils.c |
108 | wakeup-timer-mainloop.cpp |
109 | wakeup-timer-powerd.cpp) |
110 | |
111 | === modified file 'src/main.cpp' |
112 | --- src/main.cpp 2015-04-03 18:11:39 +0000 |
113 | +++ src/main.cpp 2015-09-03 14:15:27 +0000 |
114 | @@ -31,8 +31,8 @@ |
115 | #include <datetime/settings-live.h> |
116 | #include <datetime/snap.h> |
117 | #include <datetime/state.h> |
118 | -#include <datetime/timezone-file.h> |
119 | #include <datetime/timezones-live.h> |
120 | +#include <datetime/timezone-timedated.h> |
121 | #include <datetime/wakeup-timer-powerd.h> |
122 | #include <notifications/notifications.h> |
123 | |
124 | @@ -68,7 +68,7 @@ |
125 | { |
126 | // create the live objects |
127 | auto live_settings = std::make_shared<LiveSettings>(); |
128 | - auto live_timezones = std::make_shared<LiveTimezones>(live_settings, TIMEZONE_FILE); |
129 | + auto live_timezones = std::make_shared<LiveTimezones>(live_settings); |
130 | auto live_clock = std::make_shared<LiveClock>(timezone_); |
131 | |
132 | // create a full-month planner currently pointing to the current month |
133 | @@ -128,7 +128,7 @@ |
134 | textdomain(GETTEXT_PACKAGE); |
135 | |
136 | auto engine = create_engine(); |
137 | - auto timezone_ = std::make_shared<FileTimezone>(TIMEZONE_FILE); |
138 | + auto timezone_ = std::make_shared<TimedatedTimezone>(); |
139 | auto state = create_state(engine, timezone_); |
140 | auto actions = std::make_shared<LiveActions>(state); |
141 | MenuFactory factory(actions, state); |
142 | |
143 | === renamed file 'src/timezone-file.cpp' => 'src/timezone-timedated.cpp' |
144 | --- src/timezone-file.cpp 2014-09-13 20:45:23 +0000 |
145 | +++ src/timezone-timedated.cpp 2015-09-03 14:15:27 +0000 |
146 | @@ -17,7 +17,7 @@ |
147 | * Charles Kerr <charles.kerr@canonical.com> |
148 | */ |
149 | |
150 | -#include <datetime/timezone-file.h> |
151 | +#include <datetime/timezone-timedated.h> |
152 | |
153 | #include <gio/gio.h> |
154 | |
155 | @@ -32,14 +32,16 @@ |
156 | **** |
157 | ***/ |
158 | |
159 | -class FileTimezone::Impl |
160 | +class TimedatedTimezone::Impl |
161 | { |
162 | public: |
163 | |
164 | - Impl(FileTimezone& owner, const std::string& filename): |
165 | - m_owner(owner) |
166 | + Impl(TimedatedTimezone& owner, std::string filename): |
167 | + m_owner(owner), |
168 | + m_filename(filename) |
169 | { |
170 | - set_filename(filename); |
171 | + g_debug("Filename is '%s'", filename.c_str()); |
172 | + monitor_timezone_property(); |
173 | } |
174 | |
175 | ~Impl() |
176 | @@ -51,65 +53,152 @@ |
177 | |
178 | void clear() |
179 | { |
180 | - if (m_monitor_handler_id) |
181 | - g_signal_handler_disconnect(m_monitor, m_monitor_handler_id); |
182 | - |
183 | - g_clear_object (&m_monitor); |
184 | - |
185 | - m_filename.clear(); |
186 | - } |
187 | - |
188 | - void set_filename(const std::string& filename) |
189 | - { |
190 | - clear(); |
191 | - |
192 | - auto tmp = realpath(filename.c_str(), nullptr); |
193 | - if(tmp != nullptr) |
194 | - { |
195 | - m_filename = tmp; |
196 | - free(tmp); |
197 | - } |
198 | - else |
199 | - { |
200 | - g_warning("Unable to resolve path '%s': %s", filename.c_str(), g_strerror(errno)); |
201 | - m_filename = filename; // better than nothing? |
202 | - } |
203 | - |
204 | - auto file = g_file_new_for_path(m_filename.c_str()); |
205 | - GError * err = nullptr; |
206 | - m_monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, nullptr, &err); |
207 | - g_object_unref(file); |
208 | + if (m_bus_watch_id) |
209 | + { |
210 | + g_bus_unwatch_name (m_bus_watch_id); |
211 | + m_bus_watch_id = 0; |
212 | + } |
213 | + |
214 | + if (m_properties_changed_id) |
215 | + { |
216 | + g_signal_handler_disconnect(m_proxy, m_properties_changed_id); |
217 | + m_properties_changed_id = 0; |
218 | + } |
219 | + |
220 | + g_clear_object(&m_proxy); |
221 | + } |
222 | + |
223 | + static void on_properties_changed(GDBusProxy *proxy G_GNUC_UNUSED, |
224 | + GVariant *changed_properties /* a{sv} */, |
225 | + GStrv invalidated_properties G_GNUC_UNUSED, |
226 | + gpointer gself) |
227 | + { |
228 | + auto self = static_cast<Impl*>(gself); |
229 | + char *tz; |
230 | + |
231 | + if (g_variant_lookup(changed_properties, "Timezone", "s", &tz, NULL)) |
232 | + { |
233 | + g_debug("on_properties_changed: got timezone '%s'", tz); |
234 | + self->notify_timezone(tz); |
235 | + g_free (tz); |
236 | + } |
237 | + } |
238 | + |
239 | + static void on_proxy_ready(GObject *object G_GNUC_UNUSED, |
240 | + GAsyncResult *res, |
241 | + gpointer gself) |
242 | + { |
243 | + auto self = static_cast<Impl*>(gself); |
244 | + GError *error = nullptr; |
245 | + self->m_proxy = g_dbus_proxy_new_finish(res, &error); |
246 | + |
247 | + if (error) |
248 | + { |
249 | + g_warning ("Couldn't create proxy to read timezone: %s", error->message); |
250 | + goto out; |
251 | + } |
252 | + |
253 | + /* Read the property */ |
254 | + GVariant *prop; |
255 | + prop = g_dbus_proxy_get_cached_property(self->m_proxy, "Timezone"); |
256 | + |
257 | + if (!prop || !g_variant_is_of_type(prop, G_VARIANT_TYPE_STRING)) |
258 | + { |
259 | + g_warning("Couldn't read the Timezone property, defaulting to Etc/Utc"); |
260 | + self->notify_timezone("Etc/Utc"); |
261 | + goto out; |
262 | + } |
263 | + |
264 | + const gchar *tz; |
265 | + tz = g_variant_get_string(prop, nullptr); |
266 | + |
267 | + self->notify_timezone(tz); |
268 | + |
269 | + self->m_properties_changed_id = g_signal_connect(self->m_proxy, |
270 | + "g-properties-changed", |
271 | + (GCallback) on_properties_changed, |
272 | + gself); |
273 | + |
274 | +out: |
275 | + g_clear_pointer(&error, g_error_free); |
276 | + g_clear_pointer(&prop, g_variant_unref); |
277 | + } |
278 | + |
279 | + static void on_name_appeared(GDBusConnection *connection, |
280 | + const gchar *name, |
281 | + const gchar *name_owner G_GNUC_UNUSED, |
282 | + gpointer gself G_GNUC_UNUSED) |
283 | + { |
284 | + g_debug ("timedate1 appeared"); |
285 | + g_dbus_proxy_new(connection, |
286 | + G_DBUS_PROXY_FLAGS_NONE, |
287 | + NULL, |
288 | + name, |
289 | + "/org/freedesktop/timedate1", |
290 | + "org.freedesktop.timedate1", |
291 | + nullptr, |
292 | + on_proxy_ready, |
293 | + gself); |
294 | + } |
295 | + |
296 | + static void on_name_vanished(GDBusConnection *connection G_GNUC_UNUSED, |
297 | + const gchar *name G_GNUC_UNUSED, |
298 | + gpointer gself) |
299 | + { |
300 | + auto self = static_cast<Impl*>(gself); |
301 | + g_debug ("timedate1 vanished"); |
302 | + |
303 | + g_signal_handler_disconnect(self->m_proxy, |
304 | + self->m_properties_changed_id); |
305 | + self->m_properties_changed_id = 0; |
306 | + g_clear_object(&self->m_proxy); |
307 | + g_clear_pointer(&self->m_proxy, g_main_loop_unref); |
308 | + } |
309 | + |
310 | + void monitor_timezone_property() |
311 | + { |
312 | + GError *err = nullptr; |
313 | + GDBusConnection *conn; |
314 | + |
315 | + /* |
316 | + * There is an unlikely race which happens if there is an activation |
317 | + * and timezone change before our match rule is added. |
318 | + */ |
319 | + notify_timezone(get_timezone_from_file(m_filename)); |
320 | + |
321 | + /* |
322 | + * Make sure the bus is around at least until we add the match rules, |
323 | + * otherwise things (tests) are sad. |
324 | + */ |
325 | + conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, |
326 | + nullptr, |
327 | + &err); |
328 | + |
329 | if (err) |
330 | { |
331 | - g_warning("%s Unable to monitor timezone file '%s': %s", G_STRLOC, TIMEZONE_FILE, err->message); |
332 | + g_warning("Couldn't get bus connection: '%s'", err->message); |
333 | g_error_free(err); |
334 | - } |
335 | - else |
336 | - { |
337 | - m_monitor_handler_id = g_signal_connect_swapped(m_monitor, "changed", G_CALLBACK(on_file_changed), this); |
338 | - g_debug("%s Monitoring timezone file '%s'", G_STRLOC, m_filename.c_str()); |
339 | - } |
340 | - |
341 | - reload(); |
342 | - } |
343 | - |
344 | - static void on_file_changed(gpointer gself) |
345 | - { |
346 | - static_cast<Impl*>(gself)->reload(); |
347 | - } |
348 | - |
349 | - void reload() |
350 | - { |
351 | - const auto new_timezone = get_timezone_from_file(m_filename); |
352 | - |
353 | + return; |
354 | + } |
355 | + |
356 | + m_bus_watch_id = g_bus_watch_name_on_connection(conn, |
357 | + "org.freedesktop.timedate1", |
358 | + G_BUS_NAME_WATCHER_FLAGS_NONE, |
359 | + on_name_appeared, |
360 | + on_name_vanished, |
361 | + this, |
362 | + nullptr); |
363 | + |
364 | + g_object_unref (conn); |
365 | + } |
366 | + |
367 | + void notify_timezone(std::string new_timezone) |
368 | + { |
369 | + g_debug("notify_timezone '%s'", new_timezone.c_str()); |
370 | if (!new_timezone.empty()) |
371 | m_owner.timezone.set(new_timezone); |
372 | } |
373 | |
374 | - /*** |
375 | - **** |
376 | - ***/ |
377 | - |
378 | std::string get_timezone_from_file(const std::string& filename) |
379 | { |
380 | GError * error; |
381 | @@ -143,7 +232,9 @@ |
382 | } |
383 | |
384 | g_string_free(line, true); |
385 | - } |
386 | + } else |
387 | + /* Default to UTC */ |
388 | + ret = "Etc/Utc"; |
389 | |
390 | if (io_channel != nullptr) |
391 | { |
392 | @@ -164,22 +255,23 @@ |
393 | **** |
394 | ***/ |
395 | |
396 | - FileTimezone & m_owner; |
397 | + TimedatedTimezone & m_owner; |
398 | + unsigned long m_properties_changed_id = 0; |
399 | + unsigned long m_bus_watch_id = 0; |
400 | + GDBusProxy *m_proxy = nullptr; |
401 | std::string m_filename; |
402 | - GFileMonitor * m_monitor = nullptr; |
403 | - unsigned long m_monitor_handler_id = 0; |
404 | }; |
405 | |
406 | /*** |
407 | **** |
408 | ***/ |
409 | |
410 | -FileTimezone::FileTimezone(const std::string& filename): |
411 | +TimedatedTimezone::TimedatedTimezone(std::string filename): |
412 | impl(new Impl{*this, filename}) |
413 | { |
414 | } |
415 | |
416 | -FileTimezone::~FileTimezone() |
417 | +TimedatedTimezone::~TimedatedTimezone() |
418 | { |
419 | } |
420 | |
421 | |
422 | === modified file 'src/timezones-live.cpp' |
423 | --- src/timezones-live.cpp 2014-01-30 19:44:12 +0000 |
424 | +++ src/timezones-live.cpp 2015-09-03 14:15:27 +0000 |
425 | @@ -25,9 +25,8 @@ |
426 | namespace indicator { |
427 | namespace datetime { |
428 | |
429 | -LiveTimezones::LiveTimezones(const std::shared_ptr<const Settings>& settings, |
430 | - const std::string& filename): |
431 | - m_file(filename), |
432 | +LiveTimezones::LiveTimezones(const std::shared_ptr<const Settings>& settings): |
433 | + m_file(), |
434 | m_settings(settings) |
435 | { |
436 | m_file.timezone.changed().connect([this](const std::string&){update_timezones();}); |
437 | |
438 | === modified file 'tests/CMakeLists.txt' |
439 | --- tests/CMakeLists.txt 2015-07-22 12:00:11 +0000 |
440 | +++ tests/CMakeLists.txt 2015-09-03 14:15:27 +0000 |
441 | @@ -38,6 +38,7 @@ |
442 | |
443 | |
444 | add_definitions (-DSANDBOX="${CMAKE_CURRENT_BINARY_DIR}") |
445 | +add_definitions (-DG_LOG_DOMAIN="Indicator-Datetime") |
446 | |
447 | function(add_test_by_name name) |
448 | set (TEST_NAME ${name}) |
449 | @@ -58,7 +59,7 @@ |
450 | add_test_by_name(test-menus) |
451 | add_test_by_name(test-planner) |
452 | add_test_by_name(test-settings) |
453 | -add_test_by_name(test-timezone-file) |
454 | +add_test_by_name(test-timezone-timedated) |
455 | add_test_by_name(test-utils) |
456 | |
457 | set (TEST_NAME manual-test-snap) |
458 | |
459 | === modified file 'tests/glib-fixture.h' |
460 | --- tests/glib-fixture.h 2014-09-17 16:51:51 +0000 |
461 | +++ tests/glib-fixture.h 2015-09-03 14:15:27 +0000 |
462 | @@ -36,34 +36,6 @@ |
463 | |
464 | virtual ~GlibFixture() =default; |
465 | |
466 | - private: |
467 | - |
468 | - //GLogFunc realLogHandler; |
469 | - |
470 | - protected: |
471 | - |
472 | - std::map<GLogLevelFlags,int> logCounts; |
473 | - |
474 | - void testLogCount(GLogLevelFlags log_level, int /*expected*/) |
475 | - { |
476 | -#if 0 |
477 | - EXPECT_EQ(expected, logCounts[log_level]); |
478 | -#endif |
479 | - |
480 | - logCounts.erase(log_level); |
481 | - } |
482 | - |
483 | - private: |
484 | - |
485 | - static void default_log_handler(const gchar * log_domain, |
486 | - GLogLevelFlags log_level, |
487 | - const gchar * message, |
488 | - gpointer self) |
489 | - { |
490 | - g_print("%s - %d - %s\n", log_domain, (int)log_level, message); |
491 | - static_cast<GlibFixture*>(self)->logCounts[log_level]++; |
492 | - } |
493 | - |
494 | protected: |
495 | |
496 | virtual void SetUp() override |
497 | @@ -72,34 +44,30 @@ |
498 | |
499 | loop = g_main_loop_new(nullptr, false); |
500 | |
501 | - //g_log_set_default_handler(default_log_handler, this); |
502 | - |
503 | // only use local, temporary settings |
504 | g_assert(g_setenv("GSETTINGS_SCHEMA_DIR", SCHEMA_DIR, true)); |
505 | g_assert(g_setenv("GSETTINGS_BACKEND", "memory", true)); |
506 | g_debug("SCHEMA_DIR is %s", SCHEMA_DIR); |
507 | |
508 | + // fail on unexpected messages from this domain |
509 | + g_log_set_fatal_mask(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING); |
510 | + |
511 | g_unsetenv("DISPLAY"); |
512 | |
513 | } |
514 | |
515 | virtual void TearDown() override |
516 | { |
517 | -#if 0 |
518 | - // confirm there aren't any unexpected log messages |
519 | - EXPECT_EQ(0, logCounts[G_LOG_LEVEL_ERROR]); |
520 | - EXPECT_EQ(0, logCounts[G_LOG_LEVEL_CRITICAL]); |
521 | - EXPECT_EQ(0, logCounts[G_LOG_LEVEL_WARNING]); |
522 | - EXPECT_EQ(0, logCounts[G_LOG_LEVEL_MESSAGE]); |
523 | - EXPECT_EQ(0, logCounts[G_LOG_LEVEL_INFO]); |
524 | -#endif |
525 | - |
526 | - // revert to glib's log handler |
527 | - //g_log_set_default_handler(realLogHandler, this); |
528 | + g_test_assert_expected_messages (); |
529 | |
530 | g_clear_pointer(&loop, g_main_loop_unref); |
531 | } |
532 | |
533 | + void expectLogMessage (const gchar *domain, GLogLevelFlags level, const gchar *pattern) |
534 | + { |
535 | + g_test_expect_message (domain, level, pattern); |
536 | + } |
537 | + |
538 | private: |
539 | |
540 | static gboolean |
541 | |
542 | === modified file 'tests/test-live-actions.cpp' |
543 | --- tests/test-live-actions.cpp 2015-03-31 23:54:04 +0000 |
544 | +++ tests/test-live-actions.cpp 2015-09-03 14:15:27 +0000 |
545 | @@ -17,228 +17,18 @@ |
546 | * Charles Kerr <charles.kerr@canonical.com> |
547 | */ |
548 | |
549 | -#include <datetime/actions-live.h> |
550 | - |
551 | -#include "state-mock.h" |
552 | -#include "glib-fixture.h" |
553 | - |
554 | -/*** |
555 | -**** |
556 | -***/ |
557 | - |
558 | -using namespace unity::indicator::datetime; |
559 | - |
560 | -class MockLiveActions: public LiveActions |
561 | -{ |
562 | -public: |
563 | - std::string last_cmd; |
564 | - std::string last_url; |
565 | - explicit MockLiveActions(const std::shared_ptr<State>& state_in): LiveActions(state_in) {} |
566 | - ~MockLiveActions() {} |
567 | - |
568 | -protected: |
569 | - void dispatch_url(const std::string& url) override { last_url = url; } |
570 | - void execute_command(const std::string& cmd) override { last_cmd = cmd; } |
571 | -}; |
572 | - |
573 | -/*** |
574 | -**** |
575 | -***/ |
576 | - |
577 | -using namespace unity::indicator::datetime; |
578 | - |
579 | -class LiveActionsFixture: public GlibFixture |
580 | -{ |
581 | -private: |
582 | - |
583 | - typedef GlibFixture super; |
584 | - |
585 | - static void on_bus_acquired(GDBusConnection* conn, |
586 | - const gchar* name, |
587 | - gpointer gself) |
588 | - { |
589 | - auto self = static_cast<LiveActionsFixture*>(gself); |
590 | - g_debug("bus acquired: %s, connection is %p", name, conn); |
591 | - |
592 | - // Set up a mock GSD. |
593 | - // All it really does is wait for calls to GetDevice and |
594 | - // returns the get_devices_retval variant |
595 | - static const GDBusInterfaceVTable vtable = { |
596 | - timedate1_handle_method_call, |
597 | - nullptr, /* GetProperty */ |
598 | - nullptr, /* SetProperty */ |
599 | - }; |
600 | - |
601 | - self->connection = G_DBUS_CONNECTION(g_object_ref(G_OBJECT(conn))); |
602 | - |
603 | - GError* error = nullptr; |
604 | - self->object_register_id = g_dbus_connection_register_object( |
605 | - conn, |
606 | - "/org/freedesktop/timedate1", |
607 | - self->node_info->interfaces[0], |
608 | - &vtable, |
609 | - self, |
610 | - nullptr, |
611 | - &error); |
612 | - g_assert_no_error(error); |
613 | - } |
614 | - |
615 | - static void on_name_acquired(GDBusConnection* /*conn*/, |
616 | - const gchar* /*name*/, |
617 | - gpointer gself) |
618 | - { |
619 | - auto self = static_cast<LiveActionsFixture*>(gself); |
620 | - self->name_acquired = true; |
621 | - g_main_loop_quit(self->loop); |
622 | - } |
623 | - |
624 | - static void on_name_lost(GDBusConnection* /*conn*/, |
625 | - const gchar* /*name*/, |
626 | - gpointer gself) |
627 | - { |
628 | - auto self = static_cast<LiveActionsFixture*>(gself); |
629 | - self->name_acquired = false; |
630 | - } |
631 | - |
632 | - static void on_bus_closed(GObject* /*object*/, |
633 | - GAsyncResult* res, |
634 | - gpointer gself) |
635 | - { |
636 | - auto self = static_cast<LiveActionsFixture*>(gself); |
637 | - GError* err = nullptr; |
638 | - g_dbus_connection_close_finish(self->connection, res, &err); |
639 | - g_assert_no_error(err); |
640 | - g_main_loop_quit(self->loop); |
641 | - } |
642 | - |
643 | - static void |
644 | - timedate1_handle_method_call(GDBusConnection * /*connection*/, |
645 | - const gchar * /*sender*/, |
646 | - const gchar * /*object_path*/, |
647 | - const gchar * /*interface_name*/, |
648 | - const gchar * method_name, |
649 | - GVariant * parameters, |
650 | - GDBusMethodInvocation * invocation, |
651 | - gpointer gself) |
652 | - { |
653 | - g_assert(!g_strcmp0(method_name, "SetTimezone")); |
654 | - g_assert(g_variant_is_of_type(parameters, G_VARIANT_TYPE_TUPLE)); |
655 | - g_assert(2 == g_variant_n_children(parameters)); |
656 | - |
657 | - auto child = g_variant_get_child_value(parameters, 0); |
658 | - g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_STRING)); |
659 | - auto self = static_cast<LiveActionsFixture*>(gself); |
660 | - self->attempted_tzid = g_variant_get_string(child, nullptr); |
661 | - g_variant_unref(child); |
662 | - |
663 | - g_dbus_method_invocation_return_value(invocation, nullptr); |
664 | - g_main_loop_quit(self->loop); |
665 | - } |
666 | - |
667 | -protected: |
668 | - |
669 | - std::shared_ptr<MockState> m_mock_state; |
670 | - std::shared_ptr<State> m_state; |
671 | - std::shared_ptr<MockLiveActions> m_live_actions; |
672 | - std::shared_ptr<Actions> m_actions; |
673 | - |
674 | - bool name_acquired; |
675 | - std::string attempted_tzid; |
676 | - |
677 | - GTestDBus* bus; |
678 | - guint own_name; |
679 | - GDBusConnection* connection; |
680 | - GDBusNodeInfo* node_info; |
681 | - int object_register_id; |
682 | - |
683 | - void SetUp() |
684 | - { |
685 | - super::SetUp(); |
686 | - |
687 | - name_acquired = false; |
688 | - attempted_tzid.clear(); |
689 | - connection = nullptr; |
690 | - node_info = nullptr; |
691 | - object_register_id = 0; |
692 | - own_name = 0; |
693 | - |
694 | - // bring up the test bus |
695 | - bus = g_test_dbus_new(G_TEST_DBUS_NONE); |
696 | - g_test_dbus_up(bus); |
697 | - const auto address = g_test_dbus_get_bus_address(bus); |
698 | - g_setenv("DBUS_SYSTEM_BUS_ADDRESS", address, true); |
699 | - g_setenv("DBUS_SESSION_BUS_ADDRESS", address, true); |
700 | - g_debug("test_dbus's address is %s", address); |
701 | - |
702 | - // parse the org.freedesktop.timedate1 interface |
703 | - const gchar introspection_xml[] = |
704 | - "<node>" |
705 | - " <interface name='org.freedesktop.timedate1'>" |
706 | - " <method name='SetTimezone'>" |
707 | - " <arg name='timezone' type='s' direction='in'/>" |
708 | - " <arg name='user_interaction' type='b' direction='in'/>" |
709 | - " </method>" |
710 | - " </interface>" |
711 | - "</node>"; |
712 | - node_info = g_dbus_node_info_new_for_xml(introspection_xml, nullptr); |
713 | - ASSERT_TRUE(node_info != nullptr); |
714 | - ASSERT_TRUE(node_info->interfaces != nullptr); |
715 | - ASSERT_TRUE(node_info->interfaces[0] != nullptr); |
716 | - ASSERT_TRUE(node_info->interfaces[1] == nullptr); |
717 | - ASSERT_STREQ("org.freedesktop.timedate1", node_info->interfaces[0]->name); |
718 | - |
719 | - // own the bus |
720 | - own_name = g_bus_own_name(G_BUS_TYPE_SYSTEM, |
721 | - "org.freedesktop.timedate1", |
722 | - G_BUS_NAME_OWNER_FLAGS_NONE, |
723 | - on_bus_acquired, on_name_acquired, on_name_lost, |
724 | - this, nullptr); |
725 | - ASSERT_TRUE(object_register_id == 0); |
726 | - ASSERT_FALSE(name_acquired); |
727 | - ASSERT_TRUE(connection == nullptr); |
728 | - g_main_loop_run(loop); |
729 | - ASSERT_TRUE(object_register_id != 0); |
730 | - ASSERT_TRUE(name_acquired); |
731 | - ASSERT_TRUE(G_IS_DBUS_CONNECTION(connection)); |
732 | - |
733 | - // create the State and Actions |
734 | - m_mock_state.reset(new MockState); |
735 | - m_mock_state->settings.reset(new Settings); |
736 | - m_state = std::dynamic_pointer_cast<State>(m_mock_state); |
737 | - m_live_actions.reset(new MockLiveActions(m_state)); |
738 | - m_actions = std::dynamic_pointer_cast<Actions>(m_live_actions); |
739 | - } |
740 | - |
741 | - void TearDown() |
742 | - { |
743 | - m_actions.reset(); |
744 | - m_live_actions.reset(); |
745 | - m_state.reset(); |
746 | - m_mock_state.reset(); |
747 | - |
748 | - g_dbus_connection_unregister_object(connection, object_register_id); |
749 | - g_dbus_node_info_unref(node_info); |
750 | - g_bus_unown_name(own_name); |
751 | - g_dbus_connection_close(connection, nullptr, on_bus_closed, this); |
752 | - g_main_loop_run(loop); |
753 | - g_clear_object(&connection); |
754 | - g_test_dbus_down(bus); |
755 | - g_clear_object(&bus); |
756 | - |
757 | - super::TearDown(); |
758 | - } |
759 | -}; |
760 | - |
761 | -/*** |
762 | -**** |
763 | -***/ |
764 | - |
765 | -TEST_F(LiveActionsFixture, HelloWorld) |
766 | +#include "timedated-fixture.h" |
767 | + |
768 | +/*** |
769 | +**** |
770 | +***/ |
771 | + |
772 | +TEST_F(TimedateFixture, HelloWorld) |
773 | { |
774 | EXPECT_TRUE(true); |
775 | } |
776 | |
777 | -TEST_F(LiveActionsFixture, SetLocation) |
778 | +TEST_F(TimedateFixture, SetLocation) |
779 | { |
780 | const std::string tzid = "America/Chicago"; |
781 | const std::string name = "Oklahoma City"; |
782 | @@ -247,6 +37,10 @@ |
783 | EXPECT_NE(expected, m_state->settings->timezone_name.get()); |
784 | |
785 | m_actions->set_location(tzid, name); |
786 | + m_state->settings->timezone_name.changed().connect( |
787 | + [this](const std::string&){ |
788 | + g_main_loop_quit(loop); |
789 | + }); |
790 | g_main_loop_run(loop); |
791 | EXPECT_EQ(attempted_tzid, tzid); |
792 | wait_msec(); |
793 | @@ -258,14 +52,14 @@ |
794 | **** |
795 | ***/ |
796 | |
797 | -TEST_F(LiveActionsFixture, DesktopOpenAlarmApp) |
798 | +TEST_F(TimedateFixture, DesktopOpenAlarmApp) |
799 | { |
800 | m_actions->desktop_open_alarm_app(); |
801 | const std::string expected = "evolution -c calendar"; |
802 | EXPECT_EQ(expected, m_live_actions->last_cmd); |
803 | } |
804 | |
805 | -TEST_F(LiveActionsFixture, DesktopOpenAppointment) |
806 | +TEST_F(TimedateFixture, DesktopOpenAppointment) |
807 | { |
808 | Appointment a; |
809 | a.uid = "some-uid"; |
810 | @@ -275,14 +69,14 @@ |
811 | EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); |
812 | } |
813 | |
814 | -TEST_F(LiveActionsFixture, DesktopOpenCalendarApp) |
815 | +TEST_F(TimedateFixture, DesktopOpenCalendarApp) |
816 | { |
817 | m_actions->desktop_open_calendar_app(DateTime::NowLocal()); |
818 | const std::string expected_substr = "evolution \"calendar:///?startdate="; |
819 | EXPECT_NE(m_live_actions->last_cmd.find(expected_substr), std::string::npos); |
820 | } |
821 | |
822 | -TEST_F(LiveActionsFixture, DesktopOpenSettingsApp) |
823 | +TEST_F(TimedateFixture, DesktopOpenSettingsApp) |
824 | { |
825 | m_actions->desktop_open_settings_app(); |
826 | const std::string expected_substr = "control-center"; |
827 | @@ -300,13 +94,13 @@ |
828 | const std::string calendar_app_url = "appid://com.ubuntu.calendar/calendar/current-user-version"; |
829 | } |
830 | |
831 | -TEST_F(LiveActionsFixture, PhoneOpenAlarmApp) |
832 | +TEST_F(TimedateFixture, PhoneOpenAlarmApp) |
833 | { |
834 | m_actions->phone_open_alarm_app(); |
835 | EXPECT_EQ(clock_app_url, m_live_actions->last_url); |
836 | } |
837 | |
838 | -TEST_F(LiveActionsFixture, PhoneOpenAppointment) |
839 | +TEST_F(TimedateFixture, PhoneOpenAppointment) |
840 | { |
841 | Appointment a; |
842 | |
843 | @@ -321,14 +115,14 @@ |
844 | EXPECT_EQ(clock_app_url, m_live_actions->last_url); |
845 | } |
846 | |
847 | -TEST_F(LiveActionsFixture, PhoneOpenCalendarApp) |
848 | +TEST_F(TimedateFixture, PhoneOpenCalendarApp) |
849 | { |
850 | m_actions->phone_open_calendar_app(DateTime::NowLocal()); |
851 | const std::string expected = "appid://com.ubuntu.calendar/calendar/current-user-version"; |
852 | EXPECT_EQ(expected, m_live_actions->last_url); |
853 | } |
854 | |
855 | -TEST_F(LiveActionsFixture, PhoneOpenSettingsApp) |
856 | +TEST_F(TimedateFixture, PhoneOpenSettingsApp) |
857 | { |
858 | m_actions->phone_open_settings_app(); |
859 | const std::string expected = "settings:///system/time-date"; |
860 | @@ -339,7 +133,7 @@ |
861 | **** |
862 | ***/ |
863 | |
864 | -TEST_F(LiveActionsFixture, CalendarState) |
865 | +TEST_F(TimedateFixture, CalendarState) |
866 | { |
867 | // init the clock |
868 | auto now = DateTime::Local(2014, 1, 1, 0, 0, 0); |
869 | |
870 | === renamed file 'tests/test-timezone-file.cpp' => 'tests/test-timezone-timedated.cpp' |
871 | --- tests/test-timezone-file.cpp 2014-09-17 16:51:51 +0000 |
872 | +++ tests/test-timezone-timedated.cpp 2015-09-03 14:15:27 +0000 |
873 | @@ -18,25 +18,11 @@ |
874 | * with this program. If not, see <http://www.gnu.org/licenses/>. |
875 | */ |
876 | |
877 | -#include "glib-fixture.h" |
878 | - |
879 | -#include <datetime/timezone-file.h> |
880 | - |
881 | -//#include <condition_variable> |
882 | -//#include <mutex> |
883 | -//#include <queue> |
884 | -//#include <string> |
885 | -//#include <thread> |
886 | -//#include <iostream> |
887 | -//#include <istream> |
888 | -//#include <fstream> |
889 | - |
890 | -#include <cstdio> // fopen() |
891 | -//#include <sys/stat.h> // chmod() |
892 | -#include <unistd.h> // sync() |
893 | - |
894 | -using unity::indicator::datetime::FileTimezone; |
895 | - |
896 | +#include "timedated-fixture.h" |
897 | + |
898 | +#include <datetime/timezone-timedated.h> |
899 | + |
900 | +using unity::indicator::datetime::TimedatedTimezone; |
901 | |
902 | /*** |
903 | **** |
904 | @@ -44,11 +30,11 @@ |
905 | |
906 | #define TIMEZONE_FILE (SANDBOX"/timezone") |
907 | |
908 | -class TimezoneFixture: public GlibFixture |
909 | +class TimezoneFixture: public TimedateFixture |
910 | { |
911 | private: |
912 | |
913 | - typedef GlibFixture super; |
914 | + typedef TimedateFixture super; |
915 | |
916 | protected: |
917 | |
918 | @@ -67,6 +53,7 @@ |
919 | /* convenience func to set the timezone file */ |
920 | void set_file(const std::string& text) |
921 | { |
922 | + g_debug("set_file %s %s", TIMEZONE_FILE, text.c_str()); |
923 | auto fp = fopen(TIMEZONE_FILE, "w+"); |
924 | fprintf(fp, "%s\n", text.c_str()); |
925 | fclose(fp); |
926 | @@ -74,46 +61,57 @@ |
927 | } |
928 | }; |
929 | |
930 | - |
931 | /** |
932 | - * Test that timezone-file warns, but doesn't crash, if the timezone file doesn't exist |
933 | + * Test that timezone-timedated warns, but doesn't crash, if the timezone file doesn't exist |
934 | */ |
935 | TEST_F(TimezoneFixture, NoFile) |
936 | { |
937 | remove(TIMEZONE_FILE); |
938 | ASSERT_FALSE(g_file_test(TIMEZONE_FILE, G_FILE_TEST_EXISTS)); |
939 | |
940 | - FileTimezone tz(TIMEZONE_FILE); |
941 | - testLogCount(G_LOG_LEVEL_WARNING, 1); |
942 | -} |
943 | - |
944 | - |
945 | -/** |
946 | - * Test that timezone-file picks up the initial value |
947 | + expectLogMessage(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "*No such file or directory*"); |
948 | + TimedatedTimezone tz(TIMEZONE_FILE); |
949 | +} |
950 | + |
951 | +/** |
952 | + * Test that timezone-timedated gives a default of UTC if the file doesn't exist |
953 | + */ |
954 | +TEST_F(TimezoneFixture, DefaultValueNoFile) |
955 | +{ |
956 | + const std::string expected_timezone = "Etc/Utc"; |
957 | + remove(TIMEZONE_FILE); |
958 | + ASSERT_FALSE(g_file_test(TIMEZONE_FILE, G_FILE_TEST_EXISTS)); |
959 | + |
960 | + expectLogMessage(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "*No such file or directory*"); |
961 | + TimedatedTimezone tz(TIMEZONE_FILE); |
962 | + ASSERT_EQ(expected_timezone, tz.timezone.get()); |
963 | +} |
964 | + |
965 | +/** |
966 | + * Test that timezone-timedated picks up the initial value |
967 | */ |
968 | TEST_F(TimezoneFixture, InitialValue) |
969 | { |
970 | const std::string expected_timezone = "America/Chicago"; |
971 | set_file(expected_timezone); |
972 | - FileTimezone tz(TIMEZONE_FILE); |
973 | - ASSERT_EQ(expected_timezone, tz.timezone.get()); |
974 | + TimedatedTimezone tz(TIMEZONE_FILE); |
975 | } |
976 | |
977 | - |
978 | /** |
979 | - * Test that clearing the timezone results in an empty string |
980 | + * Test that changing the tz after we are running works. |
981 | */ |
982 | TEST_F(TimezoneFixture, ChangedValue) |
983 | { |
984 | const std::string initial_timezone = "America/Chicago"; |
985 | const std::string changed_timezone = "America/New_York"; |
986 | + |
987 | set_file(initial_timezone); |
988 | |
989 | - FileTimezone tz(TIMEZONE_FILE); |
990 | + TimedatedTimezone tz(TIMEZONE_FILE); |
991 | ASSERT_EQ(initial_timezone, tz.timezone.get()); |
992 | |
993 | bool changed = false; |
994 | - auto connection = tz.timezone.changed().connect( |
995 | + tz.timezone.changed().connect( |
996 | [&changed, this](const std::string& s){ |
997 | g_message("timezone changed to %s", s.c_str()); |
998 | changed = true; |
999 | @@ -121,10 +119,9 @@ |
1000 | }); |
1001 | |
1002 | g_idle_add([](gpointer gself){ |
1003 | - static_cast<TimezoneFixture*>(gself)->set_file("America/New_York"); |
1004 | - // static_cast<FileTimezone*>(gtz)->timezone.set("America/New_York"); |
1005 | + static_cast<TimedateFixture*>(gself)->set_timezone("America/New_York"); |
1006 | return G_SOURCE_REMOVE; |
1007 | - }, this);//&tz); |
1008 | + }, this); |
1009 | |
1010 | g_main_loop_run(loop); |
1011 | |
1012 | @@ -132,15 +129,14 @@ |
1013 | ASSERT_EQ(changed_timezone, tz.timezone.get()); |
1014 | } |
1015 | |
1016 | - |
1017 | /** |
1018 | - * Test that timezone-file picks up the initial value |
1019 | + * Test that timezone-timedated picks up the initial value |
1020 | */ |
1021 | TEST_F(TimezoneFixture, IgnoreComments) |
1022 | { |
1023 | const std::string comment = "# Created by cloud-init v. 0.7.5 on Thu, 24 Apr 2014 14:03:29 +0000"; |
1024 | const std::string expected_timezone = "Europe/Berlin"; |
1025 | set_file(comment + "\n" + expected_timezone); |
1026 | - FileTimezone tz(TIMEZONE_FILE); |
1027 | + TimedatedTimezone tz(TIMEZONE_FILE); |
1028 | ASSERT_EQ(expected_timezone, tz.timezone.get()); |
1029 | } |
1030 | |
1031 | === modified file 'tests/test-utils.cpp' |
1032 | --- tests/test-utils.cpp 2014-02-02 21:29:29 +0000 |
1033 | +++ tests/test-utils.cpp 2015-09-03 14:15:27 +0000 |
1034 | @@ -59,7 +59,7 @@ |
1035 | const char* location; |
1036 | const char* expected_name; |
1037 | } beautify_timezone_test_cases[] = { |
1038 | - { "America/Chicago", nullptr, "Chicago" }, |
1039 | + { "America/Chicago", "", "Chicago" }, |
1040 | { "America/Chicago", "America/Chicago", "Chicago" }, |
1041 | { "America/Chicago", "America/Chigago Chicago", "Chicago" }, |
1042 | { "America/Chicago", "America/Chicago Oklahoma City", "Oklahoma City" }, |
1043 | |
1044 | === added file 'tests/timedated-fixture.h' |
1045 | --- tests/timedated-fixture.h 1970-01-01 00:00:00 +0000 |
1046 | +++ tests/timedated-fixture.h 2015-09-03 14:15:27 +0000 |
1047 | @@ -0,0 +1,301 @@ |
1048 | +/* |
1049 | + * Copyright 2013 Canonical Ltd. |
1050 | + * |
1051 | + * This program is free software: you can redistribute it and/or modify it |
1052 | + * under the terms of the GNU General Public License version 3, as published |
1053 | + * by the Free Software Foundation. |
1054 | + * |
1055 | + * This program is distributed in the hope that it will be useful, but |
1056 | + * WITHOUT ANY WARRANTY; without even the implied warranties of |
1057 | + * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR |
1058 | + * PURPOSE. See the GNU General Public License for more details. |
1059 | + * |
1060 | + * You should have received a copy of the GNU General Public License along |
1061 | + * with this program. If not, see <http://www.gnu.org/licenses/>. |
1062 | + * |
1063 | + * Authors: |
1064 | + * Charles Kerr <charles.kerr@canonical.com> |
1065 | + */ |
1066 | + |
1067 | +#ifndef INDICATOR_DATETIME_TESTS_TIMEDATED_FIXTURE_H |
1068 | +#define INDICATOR_DATETIME_TESTS_TIMEDATED_FIXTURE_H |
1069 | + |
1070 | +#include <datetime/actions-live.h> |
1071 | + |
1072 | +#include "state-mock.h" |
1073 | +#include "glib-fixture.h" |
1074 | + |
1075 | +using namespace unity::indicator::datetime; |
1076 | + |
1077 | +class MockLiveActions: public LiveActions |
1078 | +{ |
1079 | +public: |
1080 | + std::string last_cmd; |
1081 | + std::string last_url; |
1082 | + explicit MockLiveActions(const std::shared_ptr<State>& state_in): LiveActions(state_in) {} |
1083 | + ~MockLiveActions() {} |
1084 | + |
1085 | +protected: |
1086 | + void dispatch_url(const std::string& url) override { last_url = url; } |
1087 | + void execute_command(const std::string& cmd) override { last_cmd = cmd; } |
1088 | +}; |
1089 | + |
1090 | +/*** |
1091 | +**** |
1092 | +***/ |
1093 | + |
1094 | +using namespace unity::indicator::datetime; |
1095 | + |
1096 | +class TimedateFixture: public GlibFixture |
1097 | +{ |
1098 | +private: |
1099 | + |
1100 | + typedef GlibFixture super; |
1101 | + |
1102 | + static GVariant * timedate1_get_properties (GDBusConnection * /*connection*/ , |
1103 | + const gchar * /*sender*/, |
1104 | + const gchar * /*object_path*/, |
1105 | + const gchar * /*interface_name*/, |
1106 | + const gchar *property_name, |
1107 | + GError ** /*error*/, |
1108 | + gpointer gself) |
1109 | + |
1110 | + { |
1111 | + auto self = static_cast<TimedateFixture*>(gself); |
1112 | + g_debug("get_properties called"); |
1113 | + if (g_strcmp0(property_name, "Timezone") == 0) |
1114 | + { |
1115 | + g_debug("timezone requested, giving '%s'", |
1116 | + self->attempted_tzid.c_str()); |
1117 | + return g_variant_new_string(self->attempted_tzid.c_str()); |
1118 | + } |
1119 | + return nullptr; |
1120 | + } |
1121 | + |
1122 | + |
1123 | + static void on_bus_acquired(GDBusConnection* conn, |
1124 | + const gchar* name, |
1125 | + gpointer gself) |
1126 | + { |
1127 | + auto self = static_cast<TimedateFixture*>(gself); |
1128 | + g_debug("bus acquired: %s, connection is %p", name, conn); |
1129 | + |
1130 | + /* Set up a fake timedated which handles setting and getting the |
1131 | + ** timezone |
1132 | + */ |
1133 | + static const GDBusInterfaceVTable vtable = { |
1134 | + timedate1_handle_method_call, |
1135 | + timedate1_get_properties, /* GetProperty */ |
1136 | + nullptr, /* SetProperty */ |
1137 | + }; |
1138 | + |
1139 | + self->connection = G_DBUS_CONNECTION(g_object_ref(G_OBJECT(conn))); |
1140 | + |
1141 | + GError* error = nullptr; |
1142 | + self->object_register_id = g_dbus_connection_register_object( |
1143 | + conn, |
1144 | + "/org/freedesktop/timedate1", |
1145 | + self->node_info->interfaces[0], |
1146 | + &vtable, |
1147 | + self, |
1148 | + nullptr, |
1149 | + &error); |
1150 | + g_assert_no_error(error); |
1151 | + } |
1152 | + |
1153 | + static void on_name_acquired(GDBusConnection* conn, |
1154 | + const gchar* name, |
1155 | + gpointer gself) |
1156 | + { |
1157 | + g_debug("on_name_acquired"); |
1158 | + auto self = static_cast<TimedateFixture*>(gself); |
1159 | + self->name_acquired = true; |
1160 | + self->proxy = g_dbus_proxy_new_sync(conn, |
1161 | + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, |
1162 | + nullptr, |
1163 | + name, |
1164 | + "/org/freedesktop/timedate1", |
1165 | + "org.freedesktop.timedate1", |
1166 | + nullptr, |
1167 | + nullptr); |
1168 | + g_main_loop_quit(self->loop); |
1169 | + } |
1170 | + |
1171 | + static void on_name_lost(GDBusConnection* /*conn*/, |
1172 | + const gchar* /*name*/, |
1173 | + gpointer gself) |
1174 | + { |
1175 | + g_debug("on_name_lost"); |
1176 | + auto self = static_cast<TimedateFixture*>(gself); |
1177 | + self->name_acquired = false; |
1178 | + } |
1179 | + |
1180 | + static void on_bus_closed(GObject* /*object*/, |
1181 | + GAsyncResult* res, |
1182 | + gpointer gself) |
1183 | + { |
1184 | + g_debug("on_bus_closed"); |
1185 | + auto self = static_cast<TimedateFixture*>(gself); |
1186 | + GError* err = nullptr; |
1187 | + g_dbus_connection_close_finish(self->connection, res, &err); |
1188 | + g_assert_no_error(err); |
1189 | + g_main_loop_quit(self->loop); |
1190 | + } |
1191 | + |
1192 | + static void |
1193 | + timedate1_handle_method_call(GDBusConnection * connection, |
1194 | + const gchar * /*sender*/, |
1195 | + const gchar * object_path, |
1196 | + const gchar * interface_name, |
1197 | + const gchar * method_name, |
1198 | + GVariant * parameters, |
1199 | + GDBusMethodInvocation * invocation, |
1200 | + gpointer gself) |
1201 | + { |
1202 | + g_assert(!g_strcmp0(method_name, "SetTimezone")); |
1203 | + g_assert(g_variant_is_of_type(parameters, G_VARIANT_TYPE_TUPLE)); |
1204 | + g_assert(2 == g_variant_n_children(parameters)); |
1205 | + |
1206 | + auto child = g_variant_get_child_value(parameters, 0); |
1207 | + g_assert(g_variant_is_of_type(child, G_VARIANT_TYPE_STRING)); |
1208 | + auto self = static_cast<TimedateFixture*>(gself); |
1209 | + self->attempted_tzid = g_variant_get_string(child, nullptr); |
1210 | + g_debug("set tz (dbus side): '%s'", self->attempted_tzid.c_str()); |
1211 | + g_dbus_method_invocation_return_value(invocation, nullptr); |
1212 | + |
1213 | + /* Send PropertiesChanged */ |
1214 | + GError * local_error = nullptr; |
1215 | + auto builder = g_variant_builder_new (G_VARIANT_TYPE_ARRAY); |
1216 | + g_variant_builder_add (builder, |
1217 | + "{sv}", |
1218 | + "Timezone", |
1219 | + g_variant_new_string( |
1220 | + self->attempted_tzid.c_str())); |
1221 | + g_dbus_connection_emit_signal (connection, |
1222 | + NULL, |
1223 | + object_path, |
1224 | + "org.freedesktop.DBus.Properties", |
1225 | + "PropertiesChanged", |
1226 | + g_variant_new ("(sa{sv}as)", |
1227 | + interface_name, |
1228 | + builder, |
1229 | + NULL), |
1230 | + &local_error); |
1231 | + g_assert_no_error (local_error); |
1232 | + g_variant_unref(child); |
1233 | + } |
1234 | + |
1235 | +protected: |
1236 | + |
1237 | + std::shared_ptr<MockState> m_mock_state; |
1238 | + std::shared_ptr<State> m_state; |
1239 | + std::shared_ptr<MockLiveActions> m_live_actions; |
1240 | + std::shared_ptr<Actions> m_actions; |
1241 | + |
1242 | + bool name_acquired; |
1243 | + std::string attempted_tzid; |
1244 | + |
1245 | + GTestDBus* bus; |
1246 | + guint own_name; |
1247 | + GDBusConnection* connection; |
1248 | + GDBusNodeInfo* node_info; |
1249 | + int object_register_id; |
1250 | + GDBusProxy *proxy; |
1251 | + |
1252 | + void SetUp() |
1253 | + { |
1254 | + super::SetUp(); |
1255 | + g_debug("SetUp"); |
1256 | + |
1257 | + name_acquired = false; |
1258 | + attempted_tzid.clear(); |
1259 | + connection = nullptr; |
1260 | + node_info = nullptr; |
1261 | + object_register_id = 0; |
1262 | + own_name = 0; |
1263 | + proxy = nullptr; |
1264 | + |
1265 | + // bring up the test bus |
1266 | + bus = g_test_dbus_new(G_TEST_DBUS_NONE); |
1267 | + g_test_dbus_up(bus); |
1268 | + const auto address = g_test_dbus_get_bus_address(bus); |
1269 | + g_setenv("DBUS_SYSTEM_BUS_ADDRESS", address, true); |
1270 | + g_setenv("DBUS_SESSION_BUS_ADDRESS", address, true); |
1271 | + g_debug("test_dbus's address is %s", address); |
1272 | + |
1273 | + // parse the org.freedesktop.timedate1 interface |
1274 | + const gchar introspection_xml[] = |
1275 | + "<node>" |
1276 | + " <interface name='org.freedesktop.timedate1'>" |
1277 | + " <property name='Timezone' type='s' access='read' />" |
1278 | + " <method name='SetTimezone'>" |
1279 | + " <arg name='timezone' type='s' direction='in'/>" |
1280 | + " <arg name='user_interaction' type='b' direction='in'/>" |
1281 | + " </method>" |
1282 | + " </interface>" |
1283 | + "</node>"; |
1284 | + node_info = g_dbus_node_info_new_for_xml(introspection_xml, nullptr); |
1285 | + ASSERT_TRUE(node_info != nullptr); |
1286 | + ASSERT_TRUE(node_info->interfaces != nullptr); |
1287 | + ASSERT_TRUE(node_info->interfaces[0] != nullptr); |
1288 | + ASSERT_TRUE(node_info->interfaces[1] == nullptr); |
1289 | + ASSERT_STREQ("org.freedesktop.timedate1", node_info->interfaces[0]->name); |
1290 | + |
1291 | + // own the bus |
1292 | + own_name = g_bus_own_name(G_BUS_TYPE_SYSTEM, |
1293 | + "org.freedesktop.timedate1", |
1294 | + G_BUS_NAME_OWNER_FLAGS_NONE, |
1295 | + on_bus_acquired, on_name_acquired, on_name_lost, |
1296 | + this, nullptr); |
1297 | + ASSERT_TRUE(object_register_id == 0); |
1298 | + ASSERT_FALSE(name_acquired); |
1299 | + ASSERT_TRUE(connection == nullptr); |
1300 | + g_main_loop_run(loop); |
1301 | + ASSERT_TRUE(object_register_id != 0); |
1302 | + ASSERT_TRUE(name_acquired); |
1303 | + ASSERT_TRUE(G_IS_DBUS_CONNECTION(connection)); |
1304 | + |
1305 | + // create the State and Actions |
1306 | + m_mock_state.reset(new MockState); |
1307 | + m_mock_state->settings.reset(new Settings); |
1308 | + m_state = std::dynamic_pointer_cast<State>(m_mock_state); |
1309 | + m_live_actions.reset(new MockLiveActions(m_state)); |
1310 | + m_actions = std::dynamic_pointer_cast<Actions>(m_live_actions); |
1311 | + } |
1312 | + |
1313 | + void TearDown() |
1314 | + { |
1315 | + g_debug("TearDown"); |
1316 | + m_actions.reset(); |
1317 | + m_live_actions.reset(); |
1318 | + m_state.reset(); |
1319 | + m_mock_state.reset(); |
1320 | + g_dbus_connection_unregister_object(connection, object_register_id); |
1321 | + g_object_unref(proxy); |
1322 | + g_dbus_node_info_unref(node_info); |
1323 | + g_bus_unown_name(own_name); |
1324 | + g_dbus_connection_close(connection, nullptr, on_bus_closed, this); |
1325 | + g_main_loop_run(loop); |
1326 | + g_clear_object(&connection); |
1327 | + g_test_dbus_down(bus); |
1328 | + g_clear_object(&bus); |
1329 | + |
1330 | + super::TearDown(); |
1331 | + } |
1332 | +public: |
1333 | + void set_timezone(std::string tz) |
1334 | + { |
1335 | + g_debug("set_timezone: '%s'", tz.c_str()); |
1336 | + g_dbus_proxy_call_sync(proxy, |
1337 | + "SetTimezone", |
1338 | + g_variant_new("(sb)", |
1339 | + tz.c_str(), |
1340 | + FALSE), |
1341 | + G_DBUS_CALL_FLAGS_NONE, |
1342 | + 500, |
1343 | + nullptr, |
1344 | + nullptr); |
1345 | + } |
1346 | +}; |
1347 | + |
1348 | +#endif |
FAILED: Continuous integration, rev:421 jenkins. qa.ubuntu. com/job/ indicator- datetime- ci/328/ jenkins. qa.ubuntu. com/job/ indicator- datetime- wily-amd64- ci/18/console jenkins. qa.ubuntu. com/job/ indicator- datetime- wily-armhf- ci/18/console
http://
Executed test runs:
FAILURE: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/indicator- datetime- ci/328/ rebuild
http://