]> granicus.if.org Git - icinga2/commitdiff
Tests: Add cases for LegacyTimePeriod::ProcessTimeRangeRaw()
authorMichael Friedrich <michael.friedrich@icinga.com>
Tue, 7 May 2019 15:23:16 +0000 (17:23 +0200)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 6 Jun 2019 11:11:34 +0000 (13:11 +0200)
test/CMakeLists.txt
test/icinga-legacytimeperiod.cpp

index b973a4361c90850ed581bfa726a8385569822499..f9eb12dc5eb576ee6472a21843716f5f7653dda7 100644 (file)
@@ -128,6 +128,7 @@ add_boost_test(base
     icinga_notification/type_filter
     icinga_macros/simple
     icinga_legacytimeperiod/simple
+    icinga_legacytimeperiod/advanced
     icinga_perfdata/empty
     icinga_perfdata/simple
     icinga_perfdata/quotes
index 695a2a1cc80dcf3136acdf1986eebdb868422e1c..1c3e0fd1b43c3c6d0dfaa21313dbe70d5ec145f1 100644 (file)
@@ -1,5 +1,6 @@
 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
 
+#include "base/utility.hpp"
 #include "icinga/legacytimeperiod.hpp"
 #include <BoostTestTargetConfig.h>
 
@@ -86,4 +87,62 @@ BOOST_AUTO_TEST_CASE(simple)
        BOOST_CHECK_EQUAL(mktime(&end), (time_t) 1456790400); // 2016-03-01
 }
 
+BOOST_AUTO_TEST_CASE(advanced) {
+       tm beg, end, ref;
+       time_t ts_beg, ts_end, ts_beg_exp, ts_end_exp;
+
+       //2019-05-06 where Icinga celebrates 10 years #monitoringlove
+       String timestamp = "22:00-06:00";
+       ref.tm_year = 2019 - 1900;
+       ref.tm_mon = 5 - 1;
+       ref.tm_mday = 6;
+
+       LegacyTimePeriod::ProcessTimeRangeRaw(timestamp, &ref, &beg, &end);
+       ts_beg = mktime(&beg);
+       ts_end = mktime(&end);
+       ts_beg_exp = 1557180000; // 2019-05-06 22:00:00
+       ts_end_exp = 1557208800; // 2019-05-07 06:00:00
+
+       BOOST_CHECK_EQUAL(ts_beg, ts_beg_exp);
+       BOOST_TEST_MESSAGE("Begin date: " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", ts_beg) << " expected " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", ts_beg_exp));
+       BOOST_CHECK_EQUAL(ts_end, ts_end_exp);
+       BOOST_TEST_MESSAGE("End date: " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", ts_end) << " expected " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", ts_end_exp));
+
+
+       //2019-05-06 Icinga is unleashed.
+       timestamp = "09:00-17:00";
+       ref.tm_year = 2009 - 1900;
+       ref.tm_mon = 5 - 1;
+       ref.tm_mday = 6;
+
+       LegacyTimePeriod::ProcessTimeRangeRaw(timestamp, &ref, &beg, &end);
+       ts_beg = mktime(&beg);
+       ts_end = mktime(&end);
+       ts_beg_exp = 1241600400; // 2009-05-06 09:00:00
+       ts_end_exp = 1241629200; // 2009-05-06 17:00:00
+
+       BOOST_CHECK_EQUAL(ts_beg, ts_beg_exp);
+       BOOST_TEST_MESSAGE("Begin date: " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", ts_beg) << " expected " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", ts_beg_exp));
+       BOOST_CHECK_EQUAL(ts_end, ts_end_exp);
+       BOOST_TEST_MESSAGE("End date: " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", ts_end) << " expected " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", ts_end_exp));
+
+       //At our first Icinga Camp in SFO 2014 at GitHub HQ, we partied all night long with an overflow.
+       timestamp = "09:00-30:00";
+       ref.tm_year = 2014 - 1900;
+       ref.tm_mon = 9 - 1;
+       ref.tm_mday = 25;
+
+       LegacyTimePeriod::ProcessTimeRangeRaw(timestamp, &ref, &beg, &end);
+       ts_beg = mktime(&beg);
+       ts_end = mktime(&end);
+       ts_beg_exp = 1411549200; // 2014-09-24 09:00:00
+       ts_end_exp = 1411624800; // 2014-09-25 06:00:00
+
+       BOOST_CHECK_EQUAL(ts_beg, ts_beg_exp);
+       BOOST_TEST_MESSAGE("Begin date: " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", ts_beg) << " expected " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", ts_beg_exp));
+       BOOST_CHECK_EQUAL(ts_end, ts_end_exp);
+       BOOST_TEST_MESSAGE("End date: " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", ts_end) << " expected " << Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", ts_end_exp));
+
+ }
+
 BOOST_AUTO_TEST_SUITE_END()