some more unit-tests for time-points
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 28 Jan 2009 08:50:11 +0000 (09:50 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 28 Jan 2009 08:50:11 +0000 (09:50 +0100)
test/test_cron.cpp

index dbea5bb..532b1b3 100644 (file)
@@ -13,6 +13,7 @@
 
 #include <time.h>
 #include <stdlib.h>
+#include <stdexcept>
 
 #include <cron.hpp>
 
@@ -30,6 +31,10 @@ class TestCronFunc : public TestFixture
     CPPUNIT_TEST(Tomorrow);
     CPPUNIT_TEST(NextWeek);
     CPPUNIT_TEST(NextWeekFromToday);
+    CPPUNIT_TEST(StartMidnight);
+    CPPUNIT_TEST(StartMidnightTomorrow);
+    CPPUNIT_TEST(StartLastDaysec);
+    CPPUNIT_TEST(HalfOpenInterval);
 
     // Intervals
     CPPUNIT_TEST(IntervalBeginToday);
@@ -95,6 +100,30 @@ public:
         CPPUNIT_ASSERT_EQUAL( 1233532800, static_cast<int>(cron.get_next_run(1233100801)));
     }
 
+    void StartMidnight()
+    {
+        WeekCron cron("2345",0);
+        CPPUNIT_ASSERT_EQUAL( 1233097200, static_cast<int>(cron.get_next_run(1233097199)));
+    }
+
+    void StartMidnightTomorrow()
+    {
+        WeekCron cron("2345",0);
+        CPPUNIT_ASSERT_EQUAL( 1233183600, static_cast<int>(cron.get_next_run(1233097200)));
+    }
+
+    void StartLastDaysec()
+    {
+        WeekCron cron("2345",86399);
+        CPPUNIT_ASSERT_EQUAL( 1233183599, static_cast<int>(cron.get_next_run(1233097200)));
+    }
+
+    void HalfOpenInterval()
+    {
+        WeekCron cron("2345",86400);
+        CPPUNIT_ASSERT_THROW(static_cast<int>(cron.get_next_run(1233097200)),std::runtime_error);
+    }
+
     /////////////////////////////////////////////////////
     // Intervals
     /////////////////////////////////////////////////////