aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2014-09-16 14:57:35 -0500
committerCharles Kerr <charles.kerr@canonical.com>2014-09-16 14:57:35 -0500
commit2c4bfbbfa53d62249f350dedbf19676f5003e632 (patch)
treeb59b4fedfe0b5fb24808ff7b4f95d0c27e08f1e4 /tests
parentdc501b4b28452b097da0703cc77867377340ed13 (diff)
parent790f43bcea23f926f6617e0fe41026a3adaee8cc (diff)
downloadayatana-indicator-datetime-2c4bfbbfa53d62249f350dedbf19676f5003e632.tar.gz
ayatana-indicator-datetime-2c4bfbbfa53d62249f350dedbf19676f5003e632.tar.bz2
ayatana-indicator-datetime-2c4bfbbfa53d62249f350dedbf19676f5003e632.zip
sync with trunk
Diffstat (limited to 'tests')
-rw-r--r--tests/manual7
-rw-r--r--tests/test-clock.cpp111
2 files changed, 100 insertions, 18 deletions
diff --git a/tests/manual b/tests/manual
index e9f858e..2b16841 100644
--- a/tests/manual
+++ b/tests/manual
@@ -22,6 +22,13 @@ Test-case indicator-datetime/unity8-items-check
<dd>The menu is populated with items</dd>
</dl>
+Test-case indicator-datetime/timestamp-wakeup
+<dl>
+ <dt>Unplug the phone from any USB connection and put it to sleep</dt>
+ <dd>Reawaken the device.</dt>
+ <dd>The indicator should be showing the correct time.</dd>
+</dl>
+
Test-case indicator-datetime/new-alarm-wakeup
<dl>
<dt>Create and save an upcoming alarm in ubuntu-clock-app</dt>
diff --git a/tests/test-clock.cpp b/tests/test-clock.cpp
index cbe13f3..5601d35 100644
--- a/tests/test-clock.cpp
+++ b/tests/test-clock.cpp
@@ -18,8 +18,11 @@
*/
#include <datetime/clock.h>
+#include <datetime/clock-mock.h>
#include <datetime/timezone.h>
+#include <notifications/dbus-shared.h>
+
#include "test-dbus-fixture.h"
#include "timezone-mock.h"
@@ -33,18 +36,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)
@@ -114,6 +105,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
*/
@@ -122,7 +134,7 @@ TEST_F(ClockFixture, SleepTriggersSkew)
auto timezone_ = std::make_shared<MockTimezone>();
timezone_->timezone.set("America/New_York");
LiveClock clock(timezone_);
- 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](){
@@ -131,11 +143,74 @@ 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);
+}
+
+namespace
+{
+ void on_powerd_name_acquired(GDBusConnection * /*connection*/,
+ const gchar * /*name*/,
+ gpointer is_owned)
+ {
+ *static_cast<bool*>(is_owned) = true;
+ }
+}
+
+/**
+ * Confirm that powerd's SysPowerStateChange triggers
+ * a timestamp change
+ */
+TEST_F(ClockFixture, SysPowerStateChange)
+{
+ // set up the mock clock
+ bool minute_changed = false;
+ auto clock = std::make_shared<MockClock>(DateTime::NowLocal());
+ clock->minute_changed.connect([&minute_changed]() {
+ minute_changed = true;
+ });
+
+ // control test -- minute_changed shouldn't get triggered
+ // when the clock is silently changed
+ gboolean is_owned = false;
+ auto tag = g_bus_own_name_on_connection(system_bus,
+ BUS_POWERD_NAME,
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ on_powerd_name_acquired,
+ nullptr,
+ &is_owned /* user_data */,
+ nullptr /* user_data closure */);
+ const DateTime not_now {DateTime::Local(1999, 12, 31, 23, 59, 59)};
+ clock->set_localtime_quietly(not_now);
+ wait_msec();
+ ASSERT_TRUE(is_owned);
+ ASSERT_FALSE(minute_changed);
+
+ // now for the actual test,
+ // confirm that SysPowerStateChange triggers a minute_changed() signal
+ GError * error = nullptr;
+ auto emitted = g_dbus_connection_emit_signal(system_bus,
+ nullptr,
+ BUS_POWERD_PATH,
+ BUS_POWERD_INTERFACE,
+ "SysPowerStateChange",
+ g_variant_new("(i)", 1),
+ &error);
+ wait_msec();
+ EXPECT_TRUE(emitted);
+ EXPECT_EQ(nullptr, error);
+ EXPECT_TRUE(minute_changed);
+
+ // cleanup
+ g_bus_unown_name(tag);
}