diff --git a/ChangeLog b/ChangeLog index a469f8c1..46393cd9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2017-03-17 Markus Gans + * Added unit test for FObject + * Some minor bug fixes in FObject + 2017-03-13 Markus Gans * Added unit test for FRect diff --git a/src/fobject.cpp b/src/fobject.cpp index 2d520fdf..18edc005 100644 --- a/src/fobject.cpp +++ b/src/fobject.cpp @@ -274,7 +274,6 @@ int FObject::addTimer (int interval) if ( id <= 0 || id > int(timer_list->size() + 1) ) return 0; - time_interval.tv_sec = interval / 1000; time_interval.tv_usec = (interval % 1000) * 1000; getCurrentTime (¤tTime); diff --git a/src/test/fobject-test.cpp b/src/test/fobject-test.cpp index d409c06b..b822f2c7 100644 --- a/src/test/fobject-test.cpp +++ b/src/test/fobject-test.cpp @@ -347,11 +347,26 @@ void FObjectTest::timerTest() CPPUNIT_ASSERT ( t1.getTimerList()->size() == 1 ); id2 = t1.addTimer(900); CPPUNIT_ASSERT ( t1.getTimerList()->size() == 2 ); + CPPUNIT_ASSERT ( &t1 != &t2 ); + CPPUNIT_ASSERT ( id1 != id2 ); t1.delTimer (id1); CPPUNIT_ASSERT ( t1.getTimerList()->size() == 1 ); t1.delTimer (id2); CPPUNIT_ASSERT ( t1.getTimerList()->empty() ); CPPUNIT_ASSERT ( t1.getTimerList()->size() == 0 ); + + id1 = t1.addTimer(45); + id2 = t1.addTimer(95); + t1.delTimer (id2); + CPPUNIT_ASSERT ( t1.getTimerList()->size() == 1 ); + t1.delTimer (id1); + CPPUNIT_ASSERT ( t1.getTimerList()->empty() ); + CPPUNIT_ASSERT ( t1.getTimerList()->size() == 0 ); + + CPPUNIT_ASSERT ( ! t1.delTimer (id1) ); // id double delete + CPPUNIT_ASSERT ( ! t1.delAllTimer() ); + + t1.addTimer(250); t1.addTimer(500); t2.addTimer(750); @@ -373,6 +388,53 @@ void FObjectTest::timerTest() CPPUNIT_ASSERT ( t2.getTimerList()->empty() ); CPPUNIT_ASSERT ( t1.getTimerList()->size() == 0 ); CPPUNIT_ASSERT ( t2.getTimerList()->size() == 0 ); + + timeval tv1 = { 1321006271, 0 }; + timeval tv2 = { 27166271, 0 }; + timeval tv_sum = tv1 + tv2; + CPPUNIT_ASSERT ( tv_sum.tv_sec == 1348172542 ); + CPPUNIT_ASSERT ( tv_sum.tv_usec == 0 ); + + timeval tv_difference = tv1 - tv2; + CPPUNIT_ASSERT ( tv_difference.tv_sec == 1293840000 ); + CPPUNIT_ASSERT ( tv_difference.tv_usec == 0 ); + + tv_sum += tv2; + CPPUNIT_ASSERT ( tv_sum.tv_sec == 1375338813 ); + CPPUNIT_ASSERT ( tv_sum.tv_usec == 0 ); + + CPPUNIT_ASSERT ( tv2 < tv1 ); + CPPUNIT_ASSERT ( ! (tv1 < tv2) ); + CPPUNIT_ASSERT ( tv1 < tv_sum ); + CPPUNIT_ASSERT ( ! (tv_sum < tv1) ); + CPPUNIT_ASSERT ( tv2 < tv_sum ); + CPPUNIT_ASSERT ( ! (tv_sum < tv2) ); + CPPUNIT_ASSERT ( tv_difference < tv_sum ); + CPPUNIT_ASSERT ( ! (tv_sum < tv_difference) ); + + tv1.tv_usec = tv2.tv_usec = 600000; + tv_sum = tv1 + tv2; + CPPUNIT_ASSERT ( tv_sum.tv_sec == 1348172543 ); + CPPUNIT_ASSERT ( tv_sum.tv_usec == 200000 ); + + tv1.tv_usec = 654321; + tv2.tv_usec = 123456; + tv_difference = tv1 - tv2; + CPPUNIT_ASSERT ( tv_difference.tv_sec == 1293840000 ); + CPPUNIT_ASSERT ( tv_difference.tv_usec == 530865 ); + + tv2.tv_usec = 999888; + tv_sum += tv2; + CPPUNIT_ASSERT ( tv_sum.tv_sec == 1375338815 ); + CPPUNIT_ASSERT ( tv_sum.tv_usec == 199888 ); + + CPPUNIT_ASSERT ( tv2 < tv1 ); + CPPUNIT_ASSERT ( ! (tv1 < tv2) ); + CPPUNIT_ASSERT ( tv_difference < tv_sum ); + CPPUNIT_ASSERT ( ! (tv_sum < tv_difference) ); + + CPPUNIT_ASSERT ( ! t1.delTimer(0) ); + CPPUNIT_ASSERT ( ! t1.delTimer(-1) ); } // Put the test suite in the registry