aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2015-03-17 15:23:49 +0000
committerCI Train Bot <ci-train-bot@canonical.com>2015-03-17 15:23:49 +0000
commitddde67df581dea8c5a261e43d5b12a3821f06ed1 (patch)
treee3c2859c54b0bba9c72ad221ea41c95ed8f5a70f /tests
parent15ec7f61fa84a9a8b40c1c9fcfa6c2a268d3232b (diff)
parent273c3b3829c9a3e853d0b6b0a32ae87cc3c6852b (diff)
downloadayatana-indicator-datetime-ddde67df581dea8c5a261e43d5b12a3821f06ed1.tar.gz
ayatana-indicator-datetime-ddde67df581dea8c5a261e43d5b12a3821f06ed1.tar.bz2
ayatana-indicator-datetime-ddde67df581dea8c5a261e43d5b12a3821f06ed1.zip
Fix bug that prevented clicking on calendar days where DST sprang forward. Fixes: #1429388
Approved by: Ted Gould, PS Jenkins bot
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/manual-test-snap.cpp8
-rw-r--r--tests/test-actions.cpp33
-rw-r--r--tests/test-alarm-queue.cpp19
-rw-r--r--tests/test-datetime.cpp143
-rw-r--r--tests/test-formatter.cpp89
-rw-r--r--tests/test-live-actions.cpp33
-rw-r--r--tests/test-menus.cpp8
-rw-r--r--tests/test-planner.cpp20
-rw-r--r--tests/test-snap.cpp9
10 files changed, 230 insertions, 133 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 20e744a..25fe5dc 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -47,6 +47,7 @@ function(add_test_by_name name)
add_dependencies (${TEST_NAME} libindicatordatetimeservice)
target_link_libraries (${TEST_NAME} indicatordatetimeservice gtest ${DBUSTEST_LIBRARIES} ${SERVICE_DEPS_LIBRARIES} ${GTEST_LIBS})
endfunction()
+add_test_by_name(test-datetime)
add_test_by_name(test-snap)
add_test_by_name(test-actions)
add_test_by_name(test-alarm-queue)
diff --git a/tests/manual-test-snap.cpp b/tests/manual-test-snap.cpp
index e0aad89..22ef137 100644
--- a/tests/manual-test-snap.cpp
+++ b/tests/manual-test-snap.cpp
@@ -70,12 +70,8 @@ int main(int argc, const char* argv[])
a.url = "alarm:///hello-world";
a.uid = "D4B57D50247291478ED31DED17FF0A9838DED402";
a.type = Appointment::UBUNTU_ALARM;
- auto begin = g_date_time_new_local(2014,12,25,0,0,0);
- auto end = g_date_time_add_full(begin,0,0,1,0,0,-1);
- a.begin = begin;
- a.end = end;
- g_date_time_unref(end);
- g_date_time_unref(begin);
+ a.begin = DateTime::Local(2014, 12, 25, 0, 0, 0);
+ a.end = a.begin.end_of_day();
auto loop = g_main_loop_new(nullptr, false);
auto on_snooze = [loop](const Appointment& appt){
diff --git a/tests/test-actions.cpp b/tests/test-actions.cpp
index fc89426..2a8e370 100644
--- a/tests/test-actions.cpp
+++ b/tests/test-actions.cpp
@@ -30,9 +30,7 @@ class ActionsFixture: public StateFixture
std::vector<Appointment> build_some_appointments()
{
const auto now = m_state->clock->localtime();
- auto gdt_tomorrow = g_date_time_add_days(now.get(), 1);
- const auto tomorrow = DateTime(gdt_tomorrow);
- g_date_time_unref(gdt_tomorrow);
+ const auto tomorrow = now.add_days(1);
Appointment a1; // an alarm clock appointment
a1.color = "red";
@@ -255,9 +253,7 @@ TEST_F(ActionsFixture, SetCalendarDate)
EXPECT_TRUE(g_action_group_has_action(action_group, action_name));
// pick an arbitrary DateTime...
- auto tmp = g_date_time_new_local(2010, 1, 2, 3, 4, 5);
- const auto now = DateTime(tmp);
- g_date_time_unref(tmp);
+ auto now = DateTime::Local(2010, 1, 2, 3, 4, 5);
// confirm that Planner.time gets changed to that date when we
// activate the 'calendar' action with that date's time_t as the arg
@@ -265,6 +261,18 @@ TEST_F(ActionsFixture, SetCalendarDate)
auto v = g_variant_new_int64(now.to_unix());
g_action_group_activate_action (action_group, action_name, v);
EXPECT_TRUE(DateTime::is_same_day (now, m_state->calendar_month->month().get()));
+
+ // DST change in US
+ now = DateTime::Local(2015, 3, 8, 9, 0, 0);
+ v = g_variant_new_int64(now.to_unix());
+ g_action_group_activate_action (action_group, action_name, v);
+ EXPECT_TRUE(DateTime::is_same_day (now, m_state->calendar_month->month().get()));
+
+ // DST change in Europe
+ now = DateTime::Local(2015, 3, 29, 9, 0, 0);
+ v = g_variant_new_int64(now.to_unix());
+ g_action_group_activate_action (action_group, action_name, v);
+ EXPECT_TRUE(DateTime::is_same_day (now, m_state->calendar_month->month().get()));
}
TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate)
@@ -280,16 +288,14 @@ TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate)
// move calendar-date a week into the future...
const auto now = m_state->clock->localtime();
- auto next_week = g_date_time_add_weeks(now.get(), 1);
- const auto next_week_unix = g_date_time_to_unix(next_week);
+ const auto next_week = now.add_days(7);
+ const auto next_week_unix = next_week.to_unix();
g_action_group_activate_action (action_group, "calendar", g_variant_new_int64(next_week_unix));
// confirm the planner and calendar action state moved a week into the future
// but that m_state->clock is unchanged
- auto expected = g_date_time_add_full (next_week, 0, 0, 0, -g_date_time_get_hour(next_week),
- -g_date_time_get_minute(next_week),
- -g_date_time_get_seconds(next_week));
- const auto expected_unix = g_date_time_to_unix(expected);
+ auto expected = next_week.start_of_day();
+ const auto expected_unix = expected.to_unix();
EXPECT_EQ(expected_unix, m_state->calendar_month->month().get().to_unix());
EXPECT_EQ(now, m_state->clock->localtime());
auto calendar_state = g_action_group_get_action_state(action_group, "calendar");
@@ -301,9 +307,6 @@ TEST_F(ActionsFixture, ActivatingTheCalendarResetsItsDate)
g_clear_pointer(&v, g_variant_unref);
g_clear_pointer(&calendar_state, g_variant_unref);
- g_date_time_unref(expected);
- g_date_time_unref(next_week);
-
///
/// Now the actual test.
/// We set the state of 'calendar-active' to true, which should reset the calendar date.
diff --git a/tests/test-alarm-queue.cpp b/tests/test-alarm-queue.cpp
index 12ffe92..3fdf787 100644
--- a/tests/test-alarm-queue.cpp
+++ b/tests/test-alarm-queue.cpp
@@ -68,12 +68,8 @@ protected:
std::vector<Appointment> build_some_appointments()
{
const auto now = m_state->clock->localtime();
- auto tomorrow = g_date_time_add_days (now.get(), 1);
- auto tomorrow_begin = g_date_time_add_full (tomorrow, 0, 0, 0,
- -g_date_time_get_hour(tomorrow),
- -g_date_time_get_minute(tomorrow),
- -g_date_time_get_seconds(tomorrow));
- auto tomorrow_end = g_date_time_add_full (tomorrow_begin, 0, 0, 1, 0, 0, -1);
+ const auto tomorrow_begin = now.add_days(1).start_of_day();
+ const auto tomorrow_end = tomorrow_begin.end_of_day();
Appointment a1; // an alarm clock appointment
a1.color = "red";
@@ -84,8 +80,8 @@ protected:
a1.begin = tomorrow_begin;
a1.end = tomorrow_end;
- auto ubermorgen_begin = g_date_time_add_days (tomorrow, 1);
- auto ubermorgen_end = g_date_time_add_full (tomorrow_begin, 0, 0, 1, 0, 0, -1);
+ const auto ubermorgen_begin = now.add_days(2).start_of_day();
+ const auto ubermorgen_end = ubermorgen_begin.end_of_day();
Appointment a2; // a non-alarm appointment
a2.color = "green";
@@ -96,13 +92,6 @@ protected:
a2.begin = ubermorgen_begin;
a2.end = ubermorgen_end;
- // cleanup
- g_date_time_unref(ubermorgen_end);
- g_date_time_unref(ubermorgen_begin);
- g_date_time_unref(tomorrow_end);
- g_date_time_unref(tomorrow_begin);
- g_date_time_unref(tomorrow);
-
return std::vector<Appointment>({a1, a2});
}
};
diff --git a/tests/test-datetime.cpp b/tests/test-datetime.cpp
new file mode 100644
index 0000000..41f78fb
--- /dev/null
+++ b/tests/test-datetime.cpp
@@ -0,0 +1,143 @@
+/*
+ * Copyright 2015 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authors:
+ * Charles Kerr <charles.kerr@canonical.com>
+ */
+
+#include <datetime/date-time.h>
+
+#include "glib-fixture.h"
+
+using namespace unity::indicator::datetime;
+
+/***
+****
+***/
+
+class DateTimeFixture: public GlibFixture
+{
+ public:
+
+ DateTimeFixture() =default;
+ virtual ~DateTimeFixture() =default;
+
+ private:
+
+ typedef GlibFixture super;
+
+ protected:
+
+ GRand * m_rand = nullptr;
+
+ virtual void SetUp() override
+ {
+ super::SetUp();
+
+ m_rand = g_rand_new();
+ }
+
+ virtual void TearDown() override
+ {
+ g_clear_pointer(&m_rand, g_rand_free);
+
+ super::TearDown();
+ }
+
+ DateTime random_day()
+ {
+ return DateTime::Local(g_rand_int_range(m_rand, 1970, 3000),
+ g_rand_int_range(m_rand, 1, 13),
+ g_rand_int_range(m_rand, 1, 29),
+ g_rand_int_range(m_rand, 0, 24),
+ g_rand_int_range(m_rand, 0, 60),
+ g_rand_double_range(m_rand, 0, 60.0));
+ }
+};
+
+/***
+****
+***/
+
+TEST_F(DateTimeFixture, StartAndEnd)
+{
+ const int n_iterations{10000};
+
+ for (int i{0}; i<n_iterations; ++i)
+ {
+ const auto day = random_day();
+ int dayy{0}, daym{0}, dayd{0};
+ day.ymd(dayy, daym, dayd);
+
+ // test start-of-month
+ auto test = day.start_of_month();
+ int testy{0}, testm{0}, testd{0};
+ test.ymd(testy, testm, testd);
+ EXPECT_EQ(dayy, testy);
+ EXPECT_EQ(daym, testm);
+ EXPECT_EQ(1, testd);
+ EXPECT_EQ(0, test.hour());
+ EXPECT_EQ(0, test.minute());
+ EXPECT_EQ(0, (int)test.seconds());
+
+ // test start-of-day
+ test = day.start_of_day();
+ testy = -1;
+ testm = -1;
+ testd = -1;
+ test.ymd(testy, testm, testd);
+ EXPECT_EQ(dayy, testy);
+ EXPECT_EQ(daym, testm);
+ EXPECT_EQ(dayd, testd);
+ EXPECT_EQ(0, test.hour());
+ EXPECT_EQ(0, test.minute());
+ EXPECT_EQ(0, (int)test.seconds());
+
+ // test start-of-minute
+ test = day.start_of_minute();
+ testy = -1;
+ testm = -1;
+ testd = -1;
+ test.ymd(testy, testm, testd);
+ EXPECT_EQ(dayy, testy);
+ EXPECT_EQ(daym, testm);
+ EXPECT_EQ(dayd, testd);
+ EXPECT_EQ(day.hour(), test.hour());
+ EXPECT_EQ(day.minute(), test.minute());
+ EXPECT_EQ(0, (int)test.seconds());
+
+ // test end-of-day
+ test = day.end_of_day();
+ testy = -1;
+ testm = -1;
+ testd = -1;
+ test.ymd(testy, testm, testd);
+ EXPECT_EQ(dayy, testy);
+ EXPECT_EQ(daym, testm);
+ EXPECT_EQ(dayd, testd);
+ EXPECT_EQ(day.add_days(1).start_of_day(), test.add_full(0,0,0,0,0,1));
+
+ // test end-of-month
+ test = day.end_of_month();
+ testy = -1;
+ testm = -1;
+ testd = -1;
+ test.ymd(testy, testm, testd);
+ EXPECT_EQ(dayy, testy);
+ EXPECT_EQ(daym, testm);
+ EXPECT_EQ(day.add_days(31).start_of_month(), test.add_full(0,0,0,0,0,1));
+ }
+}
+
diff --git a/tests/test-formatter.cpp b/tests/test-formatter.cpp
index d011fea..75c5600 100644
--- a/tests/test-formatter.cpp
+++ b/tests/test-formatter.cpp
@@ -89,9 +89,8 @@ class FormatterFixture: public GlibFixture
*/
TEST_F(FormatterFixture, TestPhoneHeader)
{
- auto now = g_date_time_new_local(2020, 10, 31, 18, 30, 59);
- auto clock = std::make_shared<MockClock>(DateTime(now));
- g_date_time_unref(now);
+ auto now = DateTime::Local(2020, 10, 31, 18, 30, 59);
+ auto clock = std::make_shared<MockClock>(now);
// test the default value in a 24h locale
if(Set24hLocale())
@@ -142,9 +141,8 @@ TEST_F(FormatterFixture, TestDesktopHeader)
{ true, true, true, true, "%a %b %e %Y" EM_SPACE "%l:%M %p" }
};
- auto now = g_date_time_new_local(2020, 10, 31, 18, 30, 59);
- auto clock = std::make_shared<MockClock>(DateTime(now));
- g_date_time_unref(now);
+ auto now = DateTime::Local(2020, 10, 31, 18, 30, 59);
+ auto clock = std::make_shared<MockClock>(now);
for(const auto& test_case : test_cases)
{
@@ -166,45 +164,40 @@ TEST_F(FormatterFixture, TestDesktopHeader)
*/
TEST_F(FormatterFixture, TestUpcomingTimes)
{
- auto a = g_date_time_new_local(2020, 10, 31, 18, 30, 59);
+ auto a = DateTime::Local(2020, 10, 31, 18, 30, 59);
struct {
gboolean is_12h;
- GDateTime* now;
- GDateTime* then;
+ DateTime now;
+ DateTime then;
const char* expected_format_string;
} test_cases[] = {
- { true, g_date_time_ref(a), g_date_time_ref(a), "%l:%M %p" }, // identical time
- { true, g_date_time_ref(a), g_date_time_add_hours(a,1), "%l:%M %p" }, // later today
- { true, g_date_time_ref(a), g_date_time_add_days(a,1), "Tomorrow" EM_SPACE "%l:%M %p" }, // tomorrow
- { true, g_date_time_ref(a), g_date_time_add_days(a,2), "%a" EM_SPACE "%l:%M %p" },
- { true, g_date_time_ref(a), g_date_time_add_days(a,6), "%a" EM_SPACE "%l:%M %p" },
- { true, g_date_time_ref(a), g_date_time_add_days(a,7), "%a %d %b" EM_SPACE "%l:%M %p" }, // over one week away
-
- { false, g_date_time_ref(a), g_date_time_ref(a), "%H:%M" }, // identical time
- { false, g_date_time_ref(a), g_date_time_add_hours(a,1), "%H:%M" }, // later today
- { false, g_date_time_ref(a), g_date_time_add_days(a,1), "Tomorrow" EM_SPACE "%H:%M" }, // tomorrow
- { false, g_date_time_ref(a), g_date_time_add_days(a,2), "%a" EM_SPACE "%H:%M" },
- { false, g_date_time_ref(a), g_date_time_add_days(a,6), "%a" EM_SPACE "%H:%M" },
- { false, g_date_time_ref(a), g_date_time_add_days(a,7), "%a %d %b" EM_SPACE "%H:%M" } // over one week away
+ { true, a, a, "%l:%M %p" }, // identical time
+ { true, a, a.add_full(0,0,0,1,0,0), "%l:%M %p" }, // later today
+ { true, a, a.add_days(1), "Tomorrow" EM_SPACE "%l:%M %p" }, // tomorrow
+ { true, a, a.add_days(2), "%a" EM_SPACE "%l:%M %p" },
+ { true, a, a.add_days(6), "%a" EM_SPACE "%l:%M %p" },
+ { true, a, a.add_days(7), "%a %d %b" EM_SPACE "%l:%M %p" }, // over one week away
+
+ { false, a, a, "%H:%M" }, // identical time
+ { false, a, a.add_full(0,0,0,1,0,0), "%H:%M" }, // later today
+ { false, a, a.add_days(1), "Tomorrow" EM_SPACE "%H:%M" }, // tomorrow
+ { false, a, a.add_days(2), "%a" EM_SPACE "%H:%M" },
+ { false, a, a.add_days(6), "%a" EM_SPACE "%H:%M" },
+ { false, a, a.add_days(7), "%a %d %b" EM_SPACE "%H:%M" } // over one week away
};
for(const auto& test_case : test_cases)
{
if (test_case.is_12h ? Set12hLocale() : Set24hLocale())
{
- auto clock = std::make_shared<MockClock>(DateTime(test_case.now));
+ auto clock = std::make_shared<MockClock>(test_case.now);
DesktopFormatter f(clock, m_settings);
- const auto fmt = f.relative_format(test_case.then);
+ const auto fmt = f.relative_format(test_case.then.get());
ASSERT_EQ(test_case.expected_format_string, fmt);
-
- g_clear_pointer(&test_case.now, g_date_time_unref);
- g_clear_pointer(&test_case.then, g_date_time_unref);
}
}
-
- g_date_time_unref(a);
}
@@ -213,44 +206,34 @@ TEST_F(FormatterFixture, TestUpcomingTimes)
*/
TEST_F(FormatterFixture, TestEventTimes)
{
- auto day = g_date_time_new_local(2013, 1, 1, 13, 0, 0);
- auto day_begin = g_date_time_new_local(2013, 1, 1, 13, 0, 0);
- auto day_end = g_date_time_add_days(day_begin, 1);
- auto tomorrow_begin = g_date_time_add_days(day_begin, 1);
- auto tomorrow_end = g_date_time_add_days(tomorrow_begin, 1);
+ auto day = DateTime::Local(2013, 1, 1, 13, 0, 0);
+ auto day_begin = DateTime::Local(2013, 1, 1, 13, 0, 0);
+ auto day_end = day_begin.add_days(1);
+ auto tomorrow_begin = day_begin.add_days(1);
+ auto tomorrow_end = tomorrow_begin.add_days(1);
struct {
bool is_12h;
- GDateTime* now;
- GDateTime* then;
- GDateTime* then_end;
+ DateTime now;
+ DateTime then;
+ DateTime then_end;
const char* expected_format_string;
} test_cases[] = {
- { false, g_date_time_ref(day), g_date_time_ref(day_begin), g_date_time_ref(day_end), _("Today") },
- { true, g_date_time_ref(day), g_date_time_ref(day_begin), g_date_time_ref(day_end), _("Today") },
- { false, g_date_time_ref(day), g_date_time_ref(tomorrow_begin), g_date_time_ref(tomorrow_end), _("Tomorrow") },
- { true, g_date_time_ref(day), g_date_time_ref(tomorrow_begin), g_date_time_ref(tomorrow_end), _("Tomorrow") }
+ { false, day, day_begin, day_end, _("Today") },
+ { true, day, day_begin, day_end, _("Today") },
+ { false, day, tomorrow_begin, tomorrow_end, _("Tomorrow") },
+ { true, day, tomorrow_begin, tomorrow_end, _("Tomorrow") }
};
for(const auto& test_case : test_cases)
{
if (test_case.is_12h ? Set12hLocale() : Set24hLocale())
{
- auto clock = std::make_shared<MockClock>(DateTime(test_case.now));
+ auto clock = std::make_shared<MockClock>(test_case.now);
DesktopFormatter f(clock, m_settings);
- const auto fmt = f.relative_format(test_case.then, test_case.then_end);
+ const auto fmt = f.relative_format(test_case.then.get(), test_case.then_end.get());
ASSERT_STREQ(test_case.expected_format_string, fmt.c_str());
-
- g_clear_pointer(&test_case.now, g_date_time_unref);
- g_clear_pointer(&test_case.then, g_date_time_unref);
- g_clear_pointer(&test_case.then_end, g_date_time_unref);
}
}
-
- g_date_time_unref(tomorrow_end);
- g_date_time_unref(tomorrow_begin);
- g_date_time_unref(day_end);
- g_date_time_unref(day_begin);
- g_date_time_unref(day);
}
diff --git a/tests/test-live-actions.cpp b/tests/test-live-actions.cpp
index 1197e3e..1a34511 100644
--- a/tests/test-live-actions.cpp
+++ b/tests/test-live-actions.cpp
@@ -346,9 +346,7 @@ TEST_F(LiveActionsFixture, PhoneOpenSettingsApp)
TEST_F(LiveActionsFixture, CalendarState)
{
// init the clock
- auto tmp = g_date_time_new_local (2014, 1, 1, 0, 0, 0);
- const DateTime now (tmp);
- g_date_time_unref (tmp);
+ auto now = DateTime::Local(2014, 1, 1, 0, 0, 0);
m_mock_state->mock_clock->set_localtime (now);
m_state->calendar_month->month().set(now);
//m_state->planner->time.set(now);
@@ -388,12 +386,9 @@ TEST_F(LiveActionsFixture, CalendarState)
/// Now add appointments to the planner and confirm that the state keeps in sync
///
- auto tomorrow = g_date_time_add_days (now.get(), 1);
- auto tomorrow_begin = g_date_time_add_full (tomorrow, 0, 0, 0,
- -g_date_time_get_hour(tomorrow),
- -g_date_time_get_minute(tomorrow),
- -g_date_time_get_seconds(tomorrow));
- auto tomorrow_end = g_date_time_add_full (tomorrow_begin, 0, 0, 1, 0, 0, -1);
+ auto tomorrow = now.add_days(1);
+ auto tomorrow_begin = tomorrow.start_of_day();
+ auto tomorrow_end = tomorrow.end_of_day();
Appointment a1;
a1.color = "green";
a1.summary = "write unit tests";
@@ -402,15 +397,16 @@ TEST_F(LiveActionsFixture, CalendarState)
a1.begin = tomorrow_begin;
a1.end = tomorrow_end;
- auto next_begin = g_date_time_add_days (tomorrow_begin, 1);
- auto next_end = g_date_time_add_full (next_begin, 0, 0, 1, 0, 0, -1);
+ auto ubermorgen = now.add_days(2);
+ auto ubermorgen_begin = ubermorgen.start_of_day();
+ auto ubermorgen_end = ubermorgen.end_of_day();
Appointment a2;
a2.color = "orange";
a2.summary = "code review";
a2.url = "http://www.ubuntu.com/";
a2.uid = "2756ff7de3745bbffd65d2e4779c37c7ca60d843";
- a2.begin = next_begin;
- a2.end = next_end;
+ a2.begin = ubermorgen_begin;
+ a2.end = ubermorgen_end;
m_state->calendar_month->appointments().set(std::vector<Appointment>({a1, a2}));
@@ -424,19 +420,12 @@ TEST_F(LiveActionsFixture, CalendarState)
EXPECT_TRUE (v != nullptr);
int i;
g_variant_get_child (v, 0, "i", &i);
- EXPECT_EQ (g_date_time_get_day_of_month(a1.begin.get()), i);
+ EXPECT_EQ (a1.begin.day_of_month(), i);
g_variant_get_child (v, 1, "i", &i);
- EXPECT_EQ (g_date_time_get_day_of_month(a2.begin.get()), i);
+ EXPECT_EQ (a2.begin.day_of_month(), i);
g_clear_pointer(&v, g_variant_unref);
g_clear_pointer(&calendar_state, g_variant_unref);
- // cleanup this step
- g_date_time_unref (next_end);
- g_date_time_unref (next_begin);
- g_date_time_unref (tomorrow_end);
- g_date_time_unref (tomorrow_begin);
- g_date_time_unref (tomorrow);
-
///
/// Confirm that the action state's dictionary
/// keeps in sync with settings.show_week_numbers
diff --git a/tests/test-menus.cpp b/tests/test-menus.cpp
index e0e63ac..fb9c50a 100644
--- a/tests/test-menus.cpp
+++ b/tests/test-menus.cpp
@@ -151,9 +151,7 @@ protected:
// now change the clock and see if the date label changes appropriately
- auto gdt_tomorrow = g_date_time_add_days(now.get(), 1);
- auto tomorrow = DateTime(gdt_tomorrow);
- g_date_time_unref(gdt_tomorrow);
+ auto tomorrow = now.add_days(1).start_of_day();
m_mock_state->mock_clock->set_localtime(tomorrow);
wait_msec();
@@ -182,9 +180,7 @@ private:
std::vector<Appointment> build_some_appointments()
{
const auto now = m_state->clock->localtime();
- auto gdt_tomorrow = g_date_time_add_days(now.get(), 1);
- const auto tomorrow = DateTime(gdt_tomorrow);
- g_date_time_unref(gdt_tomorrow);
+ const auto tomorrow = now.add_days(1);
Appointment a1; // an alarm clock appointment
a1.color = "red";
diff --git a/tests/test-planner.cpp b/tests/test-planner.cpp
index 8f1590c..1e8ac66 100644
--- a/tests/test-planner.cpp
+++ b/tests/test-planner.cpp
@@ -39,30 +39,30 @@ typedef GlibFixture PlannerFixture;
TEST_F(PlannerFixture, HelloWorld)
{
- auto halloween = g_date_time_new_local(2020, 10, 31, 18, 30, 59);
- auto christmas = g_date_time_new_local(2020, 12, 25, 0, 0, 0);
+ auto halloween = DateTime::Local(2020, 10, 31, 18, 30, 59);
+ auto christmas = DateTime::Local(2020, 12, 25, 0, 0, 0);
Appointment a;
a.summary = "Test";
a.begin = halloween;
- a.end = g_date_time_add_hours(halloween, 1);
+ a.end = a.begin.add_full(0,0,0,1,0,0);
const Appointment b = a;
a.summary = "Foo";
EXPECT_EQ(a.summary, "Foo");
EXPECT_EQ(b.summary, "Test");
- EXPECT_EQ(0, g_date_time_compare(a.begin(), b.begin()));
- EXPECT_EQ(0, g_date_time_compare(a.end(), b.end()));
+ EXPECT_EQ(a.begin, b.begin);
+ EXPECT_EQ(a.end, b.end);
Appointment c;
c.begin = christmas;
- c.end = g_date_time_add_hours(christmas, 1);
+ c.end = c.begin.add_days(1);
Appointment d;
d = c;
- EXPECT_EQ(0, g_date_time_compare(c.begin(), d.begin()));
- EXPECT_EQ(0, g_date_time_compare(c.end(), d.end()));
+ EXPECT_EQ(c.begin, d.begin);
+ EXPECT_EQ(c.end, d.end);
a = d;
- EXPECT_EQ(0, g_date_time_compare(d.begin(), a.begin()));
- EXPECT_EQ(0, g_date_time_compare(d.end(), a.end()));
+ EXPECT_EQ(d.begin, a.begin);
+ EXPECT_EQ(d.end, a.end);
}
diff --git a/tests/test-snap.cpp b/tests/test-snap.cpp
index 972c493..3dd4501 100644
--- a/tests/test-snap.cpp
+++ b/tests/test-snap.cpp
@@ -109,12 +109,9 @@ protected:
appt.url = "alarm:///hello-world";
appt.uid = "D4B57D50247291478ED31DED17FF0A9838DED402";
appt.type = Appointment::EVENT;
- auto begin = g_date_time_new_local(2014,12,25,0,0,0);
- auto end = g_date_time_add_full(begin,0,0,1,0,0,-1);
- appt.begin = begin;
- appt.end = end;
- g_date_time_unref(end);
- g_date_time_unref(begin);
+ const auto christmas = DateTime::Local(2015,12,25,0,0,0);
+ appt.begin = christmas.start_of_day();
+ appt.end = christmas.end_of_day();
service = dbus_test_service_new(nullptr);