aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt1
-rw-r--r--tests/manual-test-snap.cpp2
-rw-r--r--tests/test-alarm-queue.cpp4
-rw-r--r--tests/test-datetime.cpp143
-rw-r--r--tests/test-live-actions.cpp14
-rw-r--r--tests/test-snap.cpp7
6 files changed, 158 insertions, 13 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 94c1ded..22ef137 100644
--- a/tests/manual-test-snap.cpp
+++ b/tests/manual-test-snap.cpp
@@ -71,7 +71,7 @@ int main(int argc, const char* argv[])
a.uid = "D4B57D50247291478ED31DED17FF0A9838DED402";
a.type = Appointment::UBUNTU_ALARM;
a.begin = DateTime::Local(2014, 12, 25, 0, 0, 0);
- a.end = a.begin.add_full(0,0,1,0,0,-1);
+ 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-alarm-queue.cpp b/tests/test-alarm-queue.cpp
index 0492539..3fdf787 100644
--- a/tests/test-alarm-queue.cpp
+++ b/tests/test-alarm-queue.cpp
@@ -69,7 +69,7 @@ protected:
{
const auto now = m_state->clock->localtime();
const auto tomorrow_begin = now.add_days(1).start_of_day();
- const auto tomorrow_end = tomorrow_begin.add_full(0, 0, 1, 0, 0, -1);
+ const auto tomorrow_end = tomorrow_begin.end_of_day();
Appointment a1; // an alarm clock appointment
a1.color = "red";
@@ -81,7 +81,7 @@ protected:
a1.end = tomorrow_end;
const auto ubermorgen_begin = now.add_days(2).start_of_day();
- const auto ubermorgen_end = ubermorgen_begin.add_full(0, 0, 1, 0, 0, -1);
+ const auto ubermorgen_end = ubermorgen_begin.end_of_day();
Appointment a2; // a non-alarm appointment
a2.color = "green";
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-live-actions.cpp b/tests/test-live-actions.cpp
index 98e9c58..1a34511 100644
--- a/tests/test-live-actions.cpp
+++ b/tests/test-live-actions.cpp
@@ -386,8 +386,9 @@ TEST_F(LiveActionsFixture, CalendarState)
/// Now add appointments to the planner and confirm that the state keeps in sync
///
- auto tomorrow_begin = now.add_days(1).start_of_day();
- auto tomorrow_end = tomorrow_begin.add_full(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";
@@ -396,15 +397,16 @@ TEST_F(LiveActionsFixture, CalendarState)
a1.begin = tomorrow_begin;
a1.end = tomorrow_end;
- auto next_begin = now.add_days(2).start_of_day();
- auto next_end = next_begin.add_days(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}));
diff --git a/tests/test-snap.cpp b/tests/test-snap.cpp
index e7161d3..3dd4501 100644
--- a/tests/test-snap.cpp
+++ b/tests/test-snap.cpp
@@ -109,10 +109,9 @@ protected:
appt.url = "alarm:///hello-world";
appt.uid = "D4B57D50247291478ED31DED17FF0A9838DED402";
appt.type = Appointment::EVENT;
- auto begin = DateTime::Local(2014,12,25,0,0,0);
- auto end = begin.add_full(0,0,1,0,0,-1);
- appt.begin = begin;
- appt.end = end;
+ 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);