Added heavy unit test for WeekCron. Triggers glibc bug? Needs test with new one.
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 29 Jan 2009 19:18:21 +0000 (20:18 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Thu, 29 Jan 2009 19:18:21 +0000 (20:18 +0100)
test/test_cron.cpp

index c89f408..d2e7db0 100644 (file)
@@ -78,6 +78,8 @@ class TestCronFunc : public TestFixture
     CPPUNIT_TEST(IntervalOnceShort);
     CPPUNIT_TEST(IntervalTooShort);
 
+    CPPUNIT_TEST(StartHourStaysTheSameTill2038);
+
     CPPUNIT_TEST_SUITE_END();
 
 public:
@@ -424,6 +426,40 @@ public:
         WeekCron cron("2345",0,0,86400);
         CPPUNIT_ASSERT_EQUAL( static_cast<time_t>(1233183600), cron.get_next_run(1233097200));
     }
+
+    void StartHourStaysTheSameTill2038()
+    {
+        time_t result = 0;
+        struct tm result_localtime;
+
+        // Schedule daily at 22h from 1970 till 01.01.2038. Check every 30 minutes.  
+        WeekCron cron("0123456",79200);
+        for (time_t now = 86400*15; now < 2145916800; now += 30*60)
+        {
+            result = cron.get_next_run(now);
+
+            bool conversion_ok = (localtime_r(&result, &result_localtime) != NULL);
+            CPPUNIT_ASSERT_EQUAL(true, conversion_ok);
+
+            if (result_localtime.tm_hour != 22)
+            {
+                struct tm debug_now;
+
+                conversion_ok = (localtime_r(&now, &debug_now) != NULL);
+                CPPUNIT_ASSERT_EQUAL(true, conversion_ok);
+
+                char buf[50];
+                strftime(buf, 50, "%Y-%m-%d %H:%M:%S", &debug_now);
+
+                cout << "ERROR: Failed for " << now << " (" << buf << "): Resulting hour is " << result_localtime.tm_hour << ". Ignoring." << endl;
+
+                // TODO: Remove this line once the test is working
+                result_localtime.tm_hour = 22;
+            }
+
+            CPPUNIT_ASSERT_EQUAL(22, result_localtime.tm_hour);
+        }
+    }
 };
 
 CPPUNIT_TEST_SUITE_REGISTRATION(TestCronFunc);