summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-05-02 21:11:38 +0200
committerEike Rathke <erack@redhat.com>2017-05-02 21:12:11 +0200
commit4c6876582d864897c3ebd4d00bd9fb5c6334edc1 (patch)
treeaaa9167a8069731ce00f9d26d677a38259fbaca3 /tools
parent1edd4229904575ea103730ac15254b402eb86709 (diff)
Add more unit tests for Date::Normalize()
Change-Id: I013317bfa9dad02194177cca0907b0ffbb171ccd
Diffstat (limited to 'tools')
-rw-r--r--tools/qa/cppunit/test_date.cxx29
1 files changed, 29 insertions, 0 deletions
diff --git a/tools/qa/cppunit/test_date.cxx b/tools/qa/cppunit/test_date.cxx
index 2ea3673082a2..054b38b1a727 100644
--- a/tools/qa/cppunit/test_date.cxx
+++ b/tools/qa/cppunit/test_date.cxx
@@ -78,6 +78,35 @@ void DateTest::testDate()
aDate.Normalize();
CPPUNIT_ASSERT_EQUAL( Date(4,3,1999).GetDate(), aDate.GetDate());
+ // Empty date is not normalized and stays empty date.
+ aDate = Date( Date::EMPTY );
+ aDate.Normalize();
+ CPPUNIT_ASSERT_EQUAL( Date(Date::EMPTY).GetDate(), aDate.GetDate());
+ CPPUNIT_ASSERT( !aDate.IsValidDate()); // GetDate() also shall have no normalizing side effect
+
+ // 0000-01-00 normalized to -0001-12-31
+ // SetYear(0) asserts, use empty date to force.
+ aDate = Date( Date::EMPTY );
+ aDate.SetMonth(1);
+ aDate.SetDay(0);
+ aDate.Normalize();
+ CPPUNIT_ASSERT_EQUAL( Date(31,12,-1).GetDate(), aDate.GetDate());
+
+ // 1999-00-00 normalized to 1998-12-31 (not 1998-11-30, or otherwise
+ // also 0001-00-00 should be -0001-11-30 which it should not, should it?)
+ aDate.SetYear(1999);
+ aDate.SetMonth(0);
+ aDate.SetDay(0);
+ aDate.Normalize();
+ CPPUNIT_ASSERT_EQUAL( Date(31,12,1998).GetDate(), aDate.GetDate());
+
+ // 0001-00-00 normalized to -0001-12-31
+ aDate.SetYear(1);
+ aDate.SetMonth(0);
+ aDate.SetDay(0);
+ aDate.Normalize();
+ CPPUNIT_ASSERT_EQUAL( Date(31,12,-1).GetDate(), aDate.GetDate());
+
// Year -1 is a leap year.
aDate = Date(28,2,-1);
CPPUNIT_ASSERT_EQUAL( Date(29,2,-1).GetDate(), (aDate += 1).GetDate());