diff options
author | Eike Rathke <erack@redhat.com> | 2018-08-28 19:51:37 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2018-08-29 10:41:07 +0200 |
commit | 7cb6dc2652ce7e2e7d9ec7464bb1eed0d93306d7 (patch) | |
tree | e1f61635521697b04b9a2481d3ef9146ae8bc606 /tools/qa | |
parent | 3bd8316718fdfed454c01a9c4ae6af6beb34437d (diff) |
Add unit tests for tools::Time::GetClock()
Change-Id: I0ff755fca2ee193f0f7ad99499ea12000029e674
Reviewed-on: https://gerrit.libreoffice.org/59736
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'tools/qa')
-rw-r--r-- | tools/qa/cppunit/test_time.cxx | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/tools/qa/cppunit/test_time.cxx b/tools/qa/cppunit/test_time.cxx index f1915b71baa1..0de7190bf354 100644 --- a/tools/qa/cppunit/test_time.cxx +++ b/tools/qa/cppunit/test_time.cxx @@ -18,9 +18,11 @@ class TimeTest : public CppUnit::TestFixture { public: void testTime(); + void testClockValues(); CPPUNIT_TEST_SUITE(TimeTest); CPPUNIT_TEST(testTime); + CPPUNIT_TEST(testClockValues); CPPUNIT_TEST_SUITE_END(); }; @@ -35,6 +37,92 @@ void TimeTest::testTime() CPPUNIT_ASSERT(bool(aOrigTime == aNewTime)); } +void TimeTest::testClockValues() +{ + double fTime, fFractionOfSecond; + sal_uInt16 nHour, nMinute, nSecond; + + fTime = 0.0; + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(0), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(0), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(0), nSecond); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.0, fFractionOfSecond, 0.0); + + fTime = 1.0; + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(0), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(0), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(0), nSecond); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.0, fFractionOfSecond, 0.0); + + fTime = -1.0; + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(0), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(0), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(0), nSecond); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.0, fFractionOfSecond, 0.0); + + fTime = 1.5; + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(12), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(0), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(0), nSecond); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.0, fFractionOfSecond, 0.0); + + fTime = -1.5; + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(12), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(0), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(0), nSecond); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.0, fFractionOfSecond, 0.0); + + fTime = 0.75; + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(18), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(0), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(0), nSecond); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.0, fFractionOfSecond, 0.0); + + fTime = 0.0208333333333333; + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(0), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(30), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(0), nSecond); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.0, fFractionOfSecond, 0.0); + + fTime = 0.0000115740625; + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 3); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(0), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(0), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(0), nSecond); + // Last digit may differ. + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.999, fFractionOfSecond, 1.1e-3); + + fTime = 0.524268391203704; + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 3); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(12), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(34), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(56), nSecond); + // Last digit may differ. + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.789, fFractionOfSecond, 1.1e-3); + + fTime = -0.000001; + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 9); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(23), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(59), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(59), nSecond); + // Expect this to be exact within floating point accuracy. + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.913599999, fFractionOfSecond, 1e-15); + + fTime = -1e-24; // value insignificant for time + Time::GetClock(fTime, nHour, nMinute, nSecond, fFractionOfSecond, 0); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Hour value.", sal_uInt16(0), nHour); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Minute value.", sal_uInt16(0), nMinute); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Second value.", sal_uInt16(0), nSecond); + CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE("Fraction value.", 0.0, fFractionOfSecond, 0.0); +} + CPPUNIT_TEST_SUITE_REGISTRATION(TimeTest); } |