CPPUNIT_TEST(IntervalOnceShort);
CPPUNIT_TEST(IntervalTooShort);
+ CPPUNIT_TEST(StartHourStaysTheSameTill2038);
+
CPPUNIT_TEST_SUITE_END();
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);