From aad7e86a109aeec75b3772cda20478363f966745 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 22 Jan 2014 14:28:20 -0600 Subject: Alarms is going to need to know when the clock's minute changes. We already have a timer for that in Formatter, so move it from there to Clock and add a corresponding public signal Clock.minuteChanged that both Formatter and Alarms can use. Sync unit tests. --- tests/test-clock.cpp | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'tests') diff --git a/tests/test-clock.cpp b/tests/test-clock.cpp index 142ccad..4271374 100644 --- a/tests/test-clock.cpp +++ b/tests/test-clock.cpp @@ -46,28 +46,24 @@ class ClockFixture: public TestDBusFixture } }; -/** - * Confirm that normal time passing doesn't trigger a skew event. - * that idling changing the clock's time triggers a skew event - */ -TEST_F(ClockFixture, IdleDoesNotTriggerSkew) +TEST_F(ClockFixture, MinuteChangedSignalShouldTriggerOncePerMinute) { + // start up a live clock std::shared_ptr zones(new Timezones); zones->timezone.set("America/New_York"); LiveClock clock(zones); wait_msec(500); // wait for the bus to set up - bool skewed = false; - clock.skewDetected.connect([&skewed](){ - skewed = true; - g_warn_if_reached(); - return G_SOURCE_REMOVE; - }); - - const unsigned int intervalSec = 3; - clock.skewTestIntervalSec.set(intervalSec); - wait_msec(intervalSec * 2.5 * 1000); - EXPECT_FALSE(skewed); + // count how many times clock.minuteChanged() is emitted over the next minute + const DateTime now = clock.localtime(); + const auto gnow = now.get(); + auto gthen = g_date_time_add_minutes(gnow, 1); + int count = 0; + clock.minuteChanged.connect([&count](){count++;}); + const auto msec = g_date_time_difference(gthen,gnow) / 1000; + wait_msec(msec); + EXPECT_EQ(1, count); + g_date_time_unref(gthen); } /*** @@ -99,7 +95,7 @@ TEST_F(ClockFixture, TimezoneChangeTriggersSkew) g_time_zone_unref(tz_nyc); /// change the timezones! - clock.skewDetected.connect([this](){ + clock.minuteChanged.connect([this](){ g_main_loop_quit(loop); }); g_idle_add([](gpointer gs){ @@ -128,7 +124,7 @@ TEST_F(ClockFixture, SleepTriggersSkew) wait_msec(500); // wait for the bus to set up bool skewed = false; - clock.skewDetected.connect([&skewed, this](){ + clock.minuteChanged.connect([&skewed, this](){ skewed = true; g_main_loop_quit(loop); return G_SOURCE_REMOVE; -- cgit v1.2.3