Skip to content

Commit

Permalink
tests: Add some basic tests cases for `LegacyTimePeriod::IsInTimeRang…
Browse files Browse the repository at this point in the history
…e()`
  • Loading branch information
yhabteab authored and Al2Klimov committed Aug 21, 2024
1 parent 0de7337 commit f370315
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ add_boost_test(base
icinga_notification/type_filter
icinga_macros/simple
icinga_legacytimeperiod/simple
icinga_legacytimeperiod/is_in_range
icinga_legacytimeperiod/advanced
icinga_legacytimeperiod/dst
icinga_legacytimeperiod/dst_isinside
Expand Down
44 changes: 44 additions & 0 deletions test/icinga-legacytimeperiod.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,50 @@ BOOST_AUTO_TEST_CASE(simple)
BOOST_CHECK_EQUAL(end, expectedEnd);
}

BOOST_AUTO_TEST_CASE(is_in_range)
{
tm tm_beg = Utility::LocalTime(1706518800); // 2024-01-29 09:00:00 UTC
tm tm_end = Utility::LocalTime(1706520600); // 2024-01-29 09:30:00 UTC

tm reference = tm_beg; // 2024-01-29 09:00:00 UTC

// The start date of the range should ofcourse be inside.
BOOST_CHECK_EQUAL(true, LegacyTimePeriod::IsInTimeRange(&tm_beg, &tm_end, 1, &reference));

reference = Utility::LocalTime(1706519400); // 2024-01-29 09:10:00 UTC
// The reference time is only 10 minutes behind the start date, which should be covered by this range.
BOOST_CHECK_EQUAL(true, LegacyTimePeriod::IsInTimeRange(&tm_beg, &tm_end, 1, &reference));

reference = Utility::LocalTime(1706518799); // 2024-01-29 08:59:59 UTC

// The reference time is 1 second ahead of the range start date, which shouldn't be covered by this range.
BOOST_CHECK_EQUAL(false, LegacyTimePeriod::IsInTimeRange(&tm_beg, &tm_end, 1, &reference));

reference = Utility::LocalTime(1706520599); // 2024-01-29 09:29:59 UTC

// The reference time is 1 second before the specified end time, so this should be in the range.
BOOST_CHECK_EQUAL(true, LegacyTimePeriod::IsInTimeRange(&tm_beg, &tm_end, 1, &reference));

reference = tm_end; // 2024-01-29 09:30:00 UTC

// The reference time is exactly the same as the specified end time, so this should definitely not be in the range.
BOOST_CHECK_EQUAL(false, LegacyTimePeriod::IsInTimeRange(&tm_beg, &tm_end, 1, &reference));

tm_beg = Utility::LocalTime(1706518800); // 2024-01-29 09:00:00 UTC
tm_end = Utility::LocalTime(1706720400); // 2024-01-31 17:00:00 UTC

reference = Utility::LocalTime(1706612400); // 2024-01-30 12:00:00 UTC

// Even if the reference time is within the specified range, the stride guarantees that the reference
// should be 2 days after the range start date, which is not the case.
BOOST_CHECK_EQUAL(false, LegacyTimePeriod::IsInTimeRange(&tm_beg, &tm_end, 2, &reference));

reference = Utility::LocalTime(1706698800); // 2024-01-31 11:00:00 UTC

// The reference time is now within the specified range and 2 days after the range start date.
BOOST_CHECK_EQUAL(true, LegacyTimePeriod::IsInTimeRange(&tm_beg, &tm_end, 2, &reference));
}

struct DateTime
{
struct {
Expand Down

0 comments on commit f370315

Please sign in to comment.