aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-09-13 13:12:04 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-09-13 13:12:04 -0500
commit5d753a34dcb898d1572f527a95b7ec9b58be1803 (patch)
tree36f78f3b6697784e68a20a031e61650e7f1155e2 /tests
parentf337a0fd3b8040d83b2433a8076f70fea345edad (diff)
downloadayatana-indicator-datetime-5d753a34dcb898d1572f527a95b7ec9b58be1803.tar.gz
ayatana-indicator-datetime-5d753a34dcb898d1572f527a95b7ec9b58be1803.tar.bz2
ayatana-indicator-datetime-5d753a34dcb898d1572f527a95b7ec9b58be1803.zip
hide Clock's implementation details into an Impl class.
Diffstat (limited to 'tests')
-rw-r--r--tests/test-clock.cpp50
1 files changed, 32 insertions, 18 deletions
diff --git a/tests/test-clock.cpp b/tests/test-clock.cpp
index a4924b3..82f8cb0 100644
--- a/tests/test-clock.cpp
+++ b/tests/test-clock.cpp
@@ -32,18 +32,6 @@ class ClockFixture: public TestDBusFixture
{
private:
typedef TestDBusFixture super;
-
- public:
- void emitPrepareForSleep()
- {
- g_dbus_connection_emit_signal(g_bus_get_sync(G_BUS_TYPE_SYSTEM, nullptr, nullptr),
- nullptr,
- "/org/freedesktop/login1", // object path
- "org.freedesktop.login1.Manager", // interface
- "PrepareForSleep", // signal name
- g_variant_new("(b)", FALSE),
- nullptr);
- }
};
TEST_F(ClockFixture, MinuteChangedSignalShouldTriggerOncePerMinute)
@@ -113,6 +101,27 @@ TEST_F(ClockFixture, TimezoneChangeTriggersSkew)
g_time_zone_unref(tz_la);
}
+/***
+****
+***/
+
+namespace
+{
+ void on_login1_name_acquired(GDBusConnection * connection,
+ const gchar * /*name*/,
+ gpointer /*user_data*/)
+ {
+ g_dbus_connection_emit_signal(connection,
+ nullptr,
+ "/org/freedesktop/login1", // object path
+ "org.freedesktop.login1.Manager", // interface
+ "PrepareForSleep", // signal name
+ g_variant_new("(b)", FALSE),
+ nullptr);
+ }
+}
+
+
/**
* Confirm that a "PrepareForSleep" event wil trigger a skew event
*/
@@ -121,7 +130,7 @@ TEST_F(ClockFixture, SleepTriggersSkew)
std::shared_ptr<Timezones> zones(new Timezones);
zones->timezone.set("America/New_York");
LiveClock clock(zones);
- wait_msec(500); // wait for the bus to set up
+ wait_msec(250); // wait for the bus to set up
bool skewed = false;
clock.minute_changed.connect([&skewed, this](){
@@ -130,11 +139,16 @@ TEST_F(ClockFixture, SleepTriggersSkew)
return G_SOURCE_REMOVE;
});
- g_idle_add([](gpointer gself){
- static_cast<ClockFixture*>(gself)->emitPrepareForSleep();
- return G_SOURCE_REMOVE;
- }, this);
-
+ auto name_tag = g_bus_own_name(G_BUS_TYPE_SYSTEM,
+ "org.freedesktop.login1",
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ nullptr /* bus acquired */,
+ on_login1_name_acquired,
+ nullptr /* name lost */,
+ nullptr /* user_data */,
+ nullptr /* user_data closure */);
g_main_loop_run(loop);
EXPECT_TRUE(skewed);
+
+ g_bus_unown_name(name_tag);
}