From: Thomas Jarosch Date: Thu, 29 Jan 2009 19:18:21 +0000 (+0100) Subject: Added heavy unit test for WeekCron. Triggers glibc bug? Needs test with new one. X-Git-Tag: v2.6~136^2~11 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=712a9d9ad839f2229f4b80877955cc94999d0cbe;p=libi2ncommon Added heavy unit test for WeekCron. Triggers glibc bug? Needs test with new one. --- diff --git a/test/test_cron.cpp b/test/test_cron.cpp index c89f408..d2e7db0 100644 --- a/test/test_cron.cpp +++ b/test/test_cron.cpp @@ -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(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);