diff options
author | Eike Rathke <erack@redhat.com> | 2023-06-23 12:42:29 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2023-06-23 18:32:17 +0200 |
commit | c968d8989004301b49d67a093a6eb8a629533837 (patch) | |
tree | 8db7e3cac3323908697f1ef445911f3056443b2e /tools/qa | |
parent | 759d414748bda99f29b04806f72d479e320c2f9f (diff) |
Introduce tools::Duration individual time values ctor
Change-Id: I516d3727cbcf6667b32dc963febbf4b753ef6a91
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153497
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Jenkins
Diffstat (limited to 'tools/qa')
-rw-r--r-- | tools/qa/cppunit/test_duration.cxx | 65 |
1 files changed, 63 insertions, 2 deletions
diff --git a/tools/qa/cppunit/test_duration.cxx b/tools/qa/cppunit/test_duration.cxx index c328db7cec38..c4032be83a03 100644 --- a/tools/qa/cppunit/test_duration.cxx +++ b/tools/qa/cppunit/test_duration.cxx @@ -114,12 +114,73 @@ void DurationTest::testDuration() } { // 235929599 seconds == SAL_MAX_UINT16 hours + 59 minutes + 59 seconds - const Duration aD(0, Time(0, 0, 235929599)); + const Duration aD(0, Time(0, 0, 235929599, Time::nanoSecPerSec - 1)); CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2730), aD.GetDays()); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(15), aD.GetTime().GetHour()); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(59), aD.GetTime().GetMin()); CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(59), aD.GetTime().GetSec()); - CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(0), aD.GetTime().GetNanoSec()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(999999999), aD.GetTime().GetNanoSec()); + } + { + // 235929599 seconds == SAL_MAX_UINT16 hours + 59 minutes + 59 seconds + const Duration aD(0, 0, 0, 235929599, Time::nanoSecPerSec - 1); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2730), aD.GetDays()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(15), aD.GetTime().GetHour()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(59), aD.GetTime().GetMin()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(59), aD.GetTime().GetSec()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(999999999), aD.GetTime().GetNanoSec()); + } + { + const Duration aD(1, 2, 3, 4, 5); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), aD.GetDays()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(2), aD.GetTime().GetHour()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(3), aD.GetTime().GetMin()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(4), aD.GetTime().GetSec()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(5), aD.GetTime().GetNanoSec()); + } + { + const Duration aD(-1, 2, 3, 4, 5); + CPPUNIT_ASSERT(aD.IsNegative()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-1), aD.GetDays()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(2), aD.GetTime().GetHour()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(3), aD.GetTime().GetMin()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(4), aD.GetTime().GetSec()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(5), aD.GetTime().GetNanoSec()); + } + { + const Duration aD(1, SAL_MAX_UINT32, SAL_MAX_UINT32, SAL_MAX_UINT32, SAL_MAX_UINT64); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(182202802), aD.GetDays()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), aD.GetTime().GetHour()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(17), aD.GetTime().GetMin()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(48), aD.GetTime().GetSec()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(709551615), aD.GetTime().GetNanoSec()); + } + { + const Duration aD(-1, SAL_MAX_UINT32, SAL_MAX_UINT32, SAL_MAX_UINT32, SAL_MAX_UINT64); + CPPUNIT_ASSERT(aD.IsNegative()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(-182202802), aD.GetDays()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), aD.GetTime().GetHour()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(17), aD.GetTime().GetMin()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(48), aD.GetTime().GetSec()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(709551615), aD.GetTime().GetNanoSec()); + } + { // Maximum days with all max possible. + const Duration aD(1965280846, SAL_MAX_UINT32, SAL_MAX_UINT32, SAL_MAX_UINT32, + SAL_MAX_UINT64); + CPPUNIT_ASSERT_EQUAL(SAL_MAX_INT32, aD.GetDays()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), aD.GetTime().GetHour()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(17), aD.GetTime().GetMin()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(48), aD.GetTime().GetSec()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(709551615), aD.GetTime().GetNanoSec()); + } + { // Maximum negative days with all max possible. + const Duration aD(-1965280847, SAL_MAX_UINT32, SAL_MAX_UINT32, SAL_MAX_UINT32, + SAL_MAX_UINT64); + CPPUNIT_ASSERT_EQUAL(SAL_MIN_INT32, aD.GetDays()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(1), aD.GetTime().GetHour()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(17), aD.GetTime().GetMin()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt16>(48), aD.GetTime().GetSec()); + CPPUNIT_ASSERT_EQUAL(static_cast<sal_uInt32>(709551615), aD.GetTime().GetNanoSec()); } { // Add() const DateTime aS(Date(23, 11, 1999), Time(0, 0, 0)); |