Merge lp:~larsu/indicator-datetime/remove-test-warnings into lp:indicator-datetime/15.10

Proposed by Lars Karlitski
Status: Merged
Approved by: Charles Kerr
Approved revision: no longer in the source branch.
Merged at revision: 420
Proposed branch: lp:~larsu/indicator-datetime/remove-test-warnings
Merge into: lp:indicator-datetime/15.10
Diff against target: 1302 lines (+479/-399)
13 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 (+83/-63)
src/timezones-live.cpp (+2/-3)
tests/CMakeLists.txt (+2/-1)
tests/glib-fixture.h (+9/-41)
tests/state-fixture.h (+3/-3)
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
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+270076@code.launchpad.net

This proposal supersedes a proposal from 2015-09-03.

Commit message

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.

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.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
Lars Karlitski (larsu) wrote :

Sorry for all the resubmissions. I thought I'd base it on Iain's branch, but piping it through git-bzr threw launchpad off and it didn't recognize it as prerequisite branch.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Another nice refinement; I like replacing the custom log counter with g_test_assert_expected_messages() like this.

I must remember to steal this for a couple of other test harnesses.

review: Approve
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

Preview Diff

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

Subscribers

People subscribed via source and target branches