From e4b86dcb8ec2a490079321f3fcdf1440a1883d07 Mon Sep 17 00:00:00 2001 From: Rutuja-Patil-Bosch Date: Tue, 24 Mar 2026 14:04:49 +0530 Subject: [PATCH 1/3] Added UT test cases for baselib datetime_converter dateTimeToEpoch_false_isValidDateTimeFormat EpochToDateTime_Before1970_LeapYear_January_AdjustsDaysSum invalid_day_values invalid_month_values --- .../datetime_converter_test.cpp | 89 +++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/score/datetime_converter/datetime_converter_test.cpp b/score/datetime_converter/datetime_converter_test.cpp index 9ea21212b..ee505c283 100644 --- a/score/datetime_converter/datetime_converter_test.cpp +++ b/score/datetime_converter/datetime_converter_test.cpp @@ -453,6 +453,95 @@ TEST_F(DateTimeConverterTest, test_yearIsLeap) ASSERT_FALSE(score::common::yearIsLeap(2100)); } +TEST_F(DateTimeConverterTest, invalid_month_values) +{ + auto dtt = std::make_shared(2020, 0, 10, 3, 4, 5); + ASSERT_FALSE(score::common::isValidDateTimeFormat(dtt)); + + dtt->m_month = -1; + ASSERT_FALSE(score::common::isValidDateTimeFormat(dtt)); +} + +TEST_F(DateTimeConverterTest, invalid_day_values) +{ + auto dtt = std::make_shared(2020, 12, 34, 3, 4, 5); + ASSERT_FALSE(score::common::isValidDateTimeFormat(dtt)); + + dtt->m_day = -1; + ASSERT_FALSE(score::common::isValidDateTimeFormat(dtt)); +} + +TEST_F(DateTimeConverterTest, dateTimeToEpoch_false_isValidDateTimeFormat) +{ + time_t epoch = 0; + + // Invalid: month = 13 -> isValidDateTimeFormat returns false + auto d = std::make_shared(2024, 13, 10, 12, 30, 45); + + ASSERT_FALSE(score::common::dateTimeToEpoch(d, &epoch)); + +} + +TEST_F(DateTimeConverterTest, EpochToDateTime_Before1970_LeapYear_January_AdjustsDaysSum) +{ + // ------------------------------------------------------------------ + // Loop A: Your original sweep across 1968 (pre-1970 leap year). + // This is enough to hit the January leap-window decrement (line 144) + // for some dates (e.g., epoch around -31622399). + // ------------------------------------------------------------------ + for (int month = 1; month <= 12; ++month) + { + for (int day = 1; day <= 31; ++day) + { + // Skip invalid days + if ((month == 2 && day > 29) || + (month == 4 && day > 30) || + (month == 6 && day > 30) || + (month == 9 && day > 30) || + (month == 11 && day > 30)) + continue; + + time_t epoch{}; + auto d = std::make_shared(1968, month, day, 0, 0, 1); + + if (!score::common::dateTimeToEpoch(d, &epoch)) + continue; + + (void)score::common::epochToDateTime(epoch); + + // Optional trace (keep if useful) + std::cout << "DATE=1968-" << month << "-" << day << " epoch=" << epoch << std::endl; + } + } + + // ------------------------------------------------------------------ + // Loop B: Simple sweep in 1972 (post-1970 leap year) to execute the + // else branch (lines 192-195) and its leap adjustment (line 156). + // ------------------------------------------------------------------ + for (int month = 1; month <= 12; ++month) + { + for (int day = 1; day <= 31; ++day) + { + if ((month == 2 && day > 29) || + (month == 4 && day > 30) || + (month == 6 && day > 30) || + (month == 9 && day > 30) || + (month == 11 && day > 30)) + continue; + + time_t epoch{}; + auto d = std::make_shared(1972, month, day, 0, 0, 1); + + if (!score::common::dateTimeToEpoch(d, &epoch)) + continue; + + (void)score::common::epochToDateTime(epoch); + // std::cout << "DATE=1972-" << month << "-" << day << " epoch=" << epoch << std::endl; + } + + } +} + } // namespace testing } // namespace platform } // namespace score From d6572d930260cb8d1feb377be786a1db56a435ec Mon Sep 17 00:00:00 2001 From: Rutuja-Patil-Bosch Date: Tue, 31 Mar 2026 18:16:20 +0530 Subject: [PATCH 2/3] Updated the review findings: Removed cout statements removed redundnat checks --- .../datetime_converter_test.cpp | 40 ++++++++++++++----- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/score/datetime_converter/datetime_converter_test.cpp b/score/datetime_converter/datetime_converter_test.cpp index ee505c283..bb40a60a6 100644 --- a/score/datetime_converter/datetime_converter_test.cpp +++ b/score/datetime_converter/datetime_converter_test.cpp @@ -458,6 +458,9 @@ TEST_F(DateTimeConverterTest, invalid_month_values) auto dtt = std::make_shared(2020, 0, 10, 3, 4, 5); ASSERT_FALSE(score::common::isValidDateTimeFormat(dtt)); + dtt->m_month = 13; + ASSERT_FALSE(score::common::isValidDateTimeFormat(dtt)); + dtt->m_month = -1; ASSERT_FALSE(score::common::isValidDateTimeFormat(dtt)); } @@ -473,21 +476,21 @@ TEST_F(DateTimeConverterTest, invalid_day_values) TEST_F(DateTimeConverterTest, dateTimeToEpoch_false_isValidDateTimeFormat) { - time_t epoch = 0; + time_t epoch = static_cast(0x7F7F7F7F); // Invalid: month = 13 -> isValidDateTimeFormat returns false auto d = std::make_shared(2024, 13, 10, 12, 30, 45); ASSERT_FALSE(score::common::dateTimeToEpoch(d, &epoch)); + ASSERT_EQ(epoch, static_cast(0x7F7F7F7F)); } -TEST_F(DateTimeConverterTest, EpochToDateTime_Before1970_LeapYear_January_AdjustsDaysSum) +TEST_F(DateTimeConverterTest, EpochToDateTime_Pre1970_LeapYear_DaysSumDecrementedInJanuary) { // ------------------------------------------------------------------ - // Loop A: Your original sweep across 1968 (pre-1970 leap year). - // This is enough to hit the January leap-window decrement (line 144) - // for some dates (e.g., epoch around -31622399). + // Loop A: Sweep across 1968 (pre-1970 leap year). + // Validate: epoch -> dt -> epoch round-trip remains stable. // ------------------------------------------------------------------ for (int month = 1; month <= 12; ++month) { @@ -507,12 +510,20 @@ TEST_F(DateTimeConverterTest, EpochToDateTime_Before1970_LeapYear_January_Adjust if (!score::common::dateTimeToEpoch(d, &epoch)) continue; - (void)score::common::epochToDateTime(epoch); - - // Optional trace (keep if useful) - std::cout << "DATE=1968-" << month << "-" << day << " epoch=" << epoch << std::endl; + auto dt = score::common::epochToDateTime(epoch); + if (dt == nullptr) + continue; + time_t epoch_roundtrip = static_cast(-1); + + ASSERT_TRUE(score::common::dateTimeToEpoch(dt, &epoch_roundtrip)) + << "dateTimeToEpoch failed for round-trip. epoch=" << epoch + << " (DATE=1968-" << month << "-" << day << ")"; } } +} + +TEST_F(DateTimeConverterTest, EpochToDateTime_Post1970_LeapYear_DaysSumDecremented) +{ // ------------------------------------------------------------------ // Loop B: Simple sweep in 1972 (post-1970 leap year) to execute the @@ -535,8 +546,15 @@ TEST_F(DateTimeConverterTest, EpochToDateTime_Before1970_LeapYear_January_Adjust if (!score::common::dateTimeToEpoch(d, &epoch)) continue; - (void)score::common::epochToDateTime(epoch); - // std::cout << "DATE=1972-" << month << "-" << day << " epoch=" << epoch << std::endl; + auto dt = score::common::epochToDateTime(epoch); + ASSERT_NE(dt, nullptr) << "epochToDateTime returned nullptr for epoch=" << epoch + << " (DATE=1972-" << month << "-" << day << ")"; + + time_t epoch_roundtrip = static_cast(-1); + ASSERT_TRUE(score::common::dateTimeToEpoch(dt, &epoch_roundtrip)) + << "dateTimeToEpoch failed for round-trip. epoch=" << epoch + << " (DATE=1972-" << month << "-" << day << ")"; + } } From 4203c2f2e6dfead4f675f19e54eecade74ccdf6b Mon Sep 17 00:00:00 2001 From: Rutuja-Patil-Bosch Date: Wed, 8 Apr 2026 15:23:39 +0530 Subject: [PATCH 3/3] Updates for datetime_converter unit tests SCORE-compliant - Added RecordProperty annotations (Description, TestType, Requirement, Coverage) to all test cases - Standardized requirement and coverage tags across tests - Improved test metadata for better traceability and reporting - No changes to test logic or behavior --- .../datetime_converter_test.cpp | 49 +++++++++++-------- 1 file changed, 29 insertions(+), 20 deletions(-) diff --git a/score/datetime_converter/datetime_converter_test.cpp b/score/datetime_converter/datetime_converter_test.cpp index bb40a60a6..b5c66e81c 100644 --- a/score/datetime_converter/datetime_converter_test.cpp +++ b/score/datetime_converter/datetime_converter_test.cpp @@ -455,6 +455,11 @@ TEST_F(DateTimeConverterTest, test_yearIsLeap) TEST_F(DateTimeConverterTest, invalid_month_values) { + RecordProperty("Description", "Verify invalid month values are rejected."); + RecordProperty("TestType", "Negative"); + RecordProperty("Requirement", "DatetimeValidation"); + RecordProperty("Coverage", "MonthValidation"); + auto dtt = std::make_shared(2020, 0, 10, 3, 4, 5); ASSERT_FALSE(score::common::isValidDateTimeFormat(dtt)); @@ -467,15 +472,25 @@ TEST_F(DateTimeConverterTest, invalid_month_values) TEST_F(DateTimeConverterTest, invalid_day_values) { + RecordProperty("Description", "Verify invalid day values are rejected."); + RecordProperty("TestType", "Negative"); + RecordProperty("Requirement", "DatetimeValidation"); + RecordProperty("Coverage", "DayValidation"); + auto dtt = std::make_shared(2020, 12, 34, 3, 4, 5); ASSERT_FALSE(score::common::isValidDateTimeFormat(dtt)); - + dtt->m_day = -1; ASSERT_FALSE(score::common::isValidDateTimeFormat(dtt)); } TEST_F(DateTimeConverterTest, dateTimeToEpoch_false_isValidDateTimeFormat) { + RecordProperty("Description", "Verify dateTimeToEpoch returns false for invalid DateTime input."); + RecordProperty("TestType", "Negative"); + RecordProperty("Requirement", "DatetimeValidation"); + RecordProperty("Coverage", "ErrorHandling"); + time_t epoch = static_cast(0x7F7F7F7F); // Invalid: month = 13 -> isValidDateTimeFormat returns false @@ -488,15 +503,15 @@ TEST_F(DateTimeConverterTest, dateTimeToEpoch_false_isValidDateTimeFormat) TEST_F(DateTimeConverterTest, EpochToDateTime_Pre1970_LeapYear_DaysSumDecrementedInJanuary) { - // ------------------------------------------------------------------ - // Loop A: Sweep across 1968 (pre-1970 leap year). - // Validate: epoch -> dt -> epoch round-trip remains stable. - // ------------------------------------------------------------------ + RecordProperty("Description", "Verify pre-1970 leap year round-trip stability."); + RecordProperty("TestType", "Boundary"); + RecordProperty("Requirement", "DatetimeConversion_Pre1970_LeapYear"); + RecordProperty("Coverage", "LeapYearHandling_RoundTrip"); + for (int month = 1; month <= 12; ++month) { for (int day = 1; day <= 31; ++day) { - // Skip invalid days if ((month == 2 && day > 29) || (month == 4 && day > 30) || (month == 6 && day > 30) || @@ -514,21 +529,19 @@ TEST_F(DateTimeConverterTest, EpochToDateTime_Pre1970_LeapYear_DaysSumDecremente if (dt == nullptr) continue; time_t epoch_roundtrip = static_cast(-1); - - ASSERT_TRUE(score::common::dateTimeToEpoch(dt, &epoch_roundtrip)) - << "dateTimeToEpoch failed for round-trip. epoch=" << epoch - << " (DATE=1968-" << month << "-" << day << ")"; + ASSERT_TRUE(score::common::dateTimeToEpoch(dt, &epoch_roundtrip)); } } } TEST_F(DateTimeConverterTest, EpochToDateTime_Post1970_LeapYear_DaysSumDecremented) { + RecordProperty("Description", + "Sweep across 1972 leap year (post-1970) to verify leap adjustment and round-trip stability."); + RecordProperty("TestType", "Boundary"); + RecordProperty("Requirement", "DatetimeConversion_Post1970_LeapYear"); + RecordProperty("Coverage", "LeapYearHandling_RoundTrip"); - // ------------------------------------------------------------------ - // Loop B: Simple sweep in 1972 (post-1970 leap year) to execute the - // else branch (lines 192-195) and its leap adjustment (line 156). - // ------------------------------------------------------------------ for (int month = 1; month <= 12; ++month) { for (int day = 1; day <= 31; ++day) @@ -547,14 +560,10 @@ TEST_F(DateTimeConverterTest, EpochToDateTime_Post1970_LeapYear_DaysSumDecrement continue; auto dt = score::common::epochToDateTime(epoch); - ASSERT_NE(dt, nullptr) << "epochToDateTime returned nullptr for epoch=" << epoch - << " (DATE=1972-" << month << "-" << day << ")"; + ASSERT_NE(dt, nullptr); time_t epoch_roundtrip = static_cast(-1); - ASSERT_TRUE(score::common::dateTimeToEpoch(dt, &epoch_roundtrip)) - << "dateTimeToEpoch failed for round-trip. epoch=" << epoch - << " (DATE=1972-" << month << "-" << day << ")"; - + ASSERT_TRUE(score::common::dateTimeToEpoch(dt, &epoch_roundtrip)); } }