summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorCarl Hetherington <cth@carlh.net>2019-12-23 01:05:49 +0100
committerCarl Hetherington <cth@carlh.net>2019-12-23 01:05:49 +0100
commit64e72c622be986c7272e938c2d3235c61abef402 (patch)
tree6cece3eee55fd26a79b2aa3c7e618f55258bcefc /test
parent2b5af718d2a1f5da548303c8531afe86fa82d2d8 (diff)
Add struct tm constructor for LocalTime, use it to tidy up
day_{greater,less}_than_or_equal and add add_months() method.
Diffstat (limited to 'test')
-rw-r--r--test/util_test.cc132
1 files changed, 36 insertions, 96 deletions
diff --git a/test/util_test.cc b/test/util_test.cc
index 24aa5e72..a537909d 100644
--- a/test/util_test.cc
+++ b/test/util_test.cc
@@ -143,99 +143,56 @@ BOOST_AUTO_TEST_CASE (day_less_than_or_equal_test)
{
{
/* equal */
- struct tm a;
- a.tm_mday = 5;
- a.tm_mon = 3;
- a.tm_year = 78;
-
+ dcp::LocalTime a ("1978-04-05T00:00:00");
dcp::LocalTime b ("1978-04-05T00:00:00");
BOOST_CHECK (day_less_than_or_equal(a, b));
}
{
/* every part of a less than b */
- struct tm a;
- a.tm_mday = 4;
- a.tm_mon = 2;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-02-04T00:00:00");
dcp::LocalTime b ("1985-05-23T00:00:00");
BOOST_CHECK (day_less_than_or_equal(a, b));
}
{
/* years equal, other parts less */
- struct tm a;
- a.tm_mday = 4;
- a.tm_mon = 2;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-03-02T00:00:00");
dcp::LocalTime b ("1981-05-10T00:00:00");
BOOST_CHECK (day_less_than_or_equal(a, b));
}
{
/* year and month equal, day less */
- struct tm a;
- a.tm_mday = 4;
- a.tm_mon = 2;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-03-09T00:00:00");
dcp::LocalTime b ("1981-03-12T00:00:00");
BOOST_CHECK (day_less_than_or_equal(a, b));
}
{
- /* year and month equal, day less */
- struct tm a;
- a.tm_mday = 1;
- a.tm_mon = 2;
- a.tm_year = 81;
-
- dcp::LocalTime b ("1981-03-04T00:00:00");
- BOOST_CHECK (day_less_than_or_equal(a, b));
- }
-
- {
/* a one day later than b */
- struct tm a;
- a.tm_mday = 5;
- a.tm_mon = 2;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-03-05T00:00:00");
dcp::LocalTime b ("1981-03-04T00:00:00");
BOOST_CHECK (!day_less_than_or_equal(a, b));
}
{
/* year and month same, day much later */
- struct tm a;
- a.tm_mday = 22;
- a.tm_mon = 2;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-03-22T00:00:00");
dcp::LocalTime b ("1981-03-04T00:00:00");
BOOST_CHECK (!day_less_than_or_equal(a, b));
}
{
/* year same, month and day later */
- struct tm a;
- a.tm_mday = 22;
- a.tm_mon = 5;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-06-22T00:00:00");
dcp::LocalTime b ("1981-02-04T00:00:00");
BOOST_CHECK (!day_less_than_or_equal(a, b));
}
{
/* all later */
- struct tm a;
- a.tm_mday = 22;
- a.tm_mon = 5;
- a.tm_year = 99;
-
+ dcp::LocalTime a ("1999-06-22T00:00:00");
dcp::LocalTime b ("1981-02-04T00:00:00");
BOOST_CHECK (!day_less_than_or_equal(a, b));
}
@@ -245,99 +202,63 @@ BOOST_AUTO_TEST_CASE (day_greater_than_or_equal_test)
{
{
/* equal */
- struct tm a;
- a.tm_mday = 5;
- a.tm_mon = 3;
- a.tm_year = 78;
-
+ dcp::LocalTime a ("1978-04-05T00:00:00");
dcp::LocalTime b ("1978-04-05T00:00:00");
BOOST_CHECK (day_greater_than_or_equal(a, b));
}
{
/* every part of a less than b */
- struct tm a;
- a.tm_mday = 4;
- a.tm_mon = 2;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-03-04T00:00:00");
dcp::LocalTime b ("1985-05-23T00:00:00");
BOOST_CHECK (!day_greater_than_or_equal(a, b));
}
{
/* years equal, other parts less */
- struct tm a;
- a.tm_mday = 4;
- a.tm_mon = 2;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-02-05T00:00:00");
dcp::LocalTime b ("1981-05-10T00:00:00");
BOOST_CHECK (!day_greater_than_or_equal(a, b));
}
{
/* year and month equal, day less */
- struct tm a;
- a.tm_mday = 4;
- a.tm_mon = 2;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-03-04T00:00:00");
dcp::LocalTime b ("1981-03-12T00:00:00");
BOOST_CHECK (!day_greater_than_or_equal(a, b));
}
{
/* year and month equal, day less */
- struct tm a;
- a.tm_mday = 1;
- a.tm_mon = 2;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-03-01T00:00:00");
dcp::LocalTime b ("1981-03-04T00:00:00");
BOOST_CHECK (!day_greater_than_or_equal(a, b));
}
{
/* a one day later than b */
- struct tm a;
- a.tm_mday = 5;
- a.tm_mon = 2;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-03-05T00:00:00");
dcp::LocalTime b ("1981-03-04T00:00:00");
BOOST_CHECK (day_greater_than_or_equal(a, b));
}
{
/* year and month same, day much later */
- struct tm a;
- a.tm_mday = 22;
- a.tm_mon = 2;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-03-22T00:00:00");
dcp::LocalTime b ("1981-03-04T00:00:00");
BOOST_CHECK (day_greater_than_or_equal(a, b));
}
{
/* year same, month and day later */
- struct tm a;
- a.tm_mday = 22;
- a.tm_mon = 5;
- a.tm_year = 81;
-
+ dcp::LocalTime a ("1981-05-22T00:00:00");
dcp::LocalTime b ("1981-02-04T00:00:00");
BOOST_CHECK (day_greater_than_or_equal(a, b));
}
{
/* all later */
- struct tm a;
- a.tm_mday = 22;
- a.tm_mon = 5;
- a.tm_year = 99;
-
+ dcp::LocalTime a ("1999-06-22T00:00:00");
dcp::LocalTime b ("1981-02-04T00:00:00");
BOOST_CHECK (day_greater_than_or_equal(a, b));
}
@@ -353,3 +274,22 @@ BOOST_AUTO_TEST_CASE (unique_string_test)
existing.push_back (s);
}
}
+
+BOOST_AUTO_TEST_CASE (local_time_add_months_test)
+{
+ dcp::LocalTime t("2013-06-23T18:06:59.123");
+ t.add_months(-1);
+ BOOST_CHECK_EQUAL (t, dcp::LocalTime("2013-05-23T18:06:59.123"));
+ t.add_months(1);
+ BOOST_CHECK_EQUAL (t, dcp::LocalTime("2013-06-23T18:06:59.123"));
+ t.add_months(1);
+ BOOST_CHECK_EQUAL (t, dcp::LocalTime("2013-07-23T18:06:59.123"));
+ t.add_months(4);
+ BOOST_CHECK_EQUAL (t, dcp::LocalTime("2013-11-23T18:06:59.123"));
+ t.add_months(2);
+ BOOST_CHECK_EQUAL (t, dcp::LocalTime("2014-01-23T18:06:59.123"));
+ t.add_months(-14);
+ BOOST_CHECK_EQUAL (t, dcp::LocalTime("2012-11-23T18:06:59.123"));
+ t.add_months(14);
+ BOOST_CHECK_EQUAL (t, dcp::LocalTime("2014-01-23T18:06:59.123"));
+}