]> git.localhorst.tv Git - blank.git/commitdiff
unit test for interval timer
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 12 Jun 2015 10:32:03 +0000 (12:32 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 12 Jun 2015 10:37:47 +0000 (12:37 +0200)
tst/app/TimerTest.cpp [new file with mode: 0644]
tst/app/TimerTest.hpp [new file with mode: 0644]

diff --git a/tst/app/TimerTest.cpp b/tst/app/TimerTest.cpp
new file mode 100644 (file)
index 0000000..6e20882
--- /dev/null
@@ -0,0 +1,135 @@
+#include "TimerTest.hpp"
+
+#include "app/IntervalTimer.hpp"
+
+CPPUNIT_TEST_SUITE_REGISTRATION(blank::test::TimerTest);
+
+
+namespace blank {
+namespace test {
+
+void TimerTest::setUp() {
+}
+
+void TimerTest::tearDown() {
+}
+
+
+void TimerTest::testIntervalTimer() {
+       IntervalTimer timer(50);
+       CPPUNIT_ASSERT_MESSAGE(
+               "fresh timer is running",
+               !timer.Running()
+       );
+       CPPUNIT_ASSERT_MESSAGE(
+               "fresh timer hit",
+               !timer.Hit()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "fresh timer with non-zero elapsed time",
+               0, timer.Elapsed()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "fresh timer at non-zero iteration",
+               0, timer.Iteration()
+       );
+
+       timer.Start();
+       CPPUNIT_ASSERT_MESSAGE(
+               "startet timer is not running",
+               timer.Running()
+       );
+       CPPUNIT_ASSERT_MESSAGE(
+               "started timer hit without update",
+               !timer.Hit()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "started, but not updated timer with non-zero elapsed time",
+               0, timer.Elapsed()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "started, but not updated timer at non-zero iteration",
+               0, timer.Iteration()
+       );
+
+       timer.Update(25);
+       CPPUNIT_ASSERT_MESSAGE(
+               "updated timer is not running",
+               timer.Running()
+       );
+       CPPUNIT_ASSERT_MESSAGE(
+               "timer hit after update, but before it should",
+               !timer.Hit()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "wrong elapsed time on updated timer",
+               25, timer.Elapsed()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "wrong iteration on updated timer",
+               0, timer.Iteration()
+       );
+
+       timer.Update(25);
+       CPPUNIT_ASSERT_MESSAGE(
+               "timer not hit after updating to its exact interval time",
+               timer.Hit()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "wrong elapsed time on updated timer",
+               50, timer.Elapsed()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "wrong iteration on updated timer at exact interval time",
+               1, timer.Iteration()
+       );
+
+       timer.Update(49);
+       CPPUNIT_ASSERT_MESSAGE(
+               "timer hit after updating from exact interval time to just before the next",
+               !timer.Hit()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "wrong elapsed time on updated timer",
+               99, timer.Elapsed()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "wrong iteration after updating timer from exact interval time to just before the next",
+               1, timer.Iteration()
+       );
+
+       timer.Update(2);
+       CPPUNIT_ASSERT_MESSAGE(
+               "timer not hit after updating across interval time boundary",
+               timer.Hit()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "wrong elapsed time on updated timer",
+               101, timer.Elapsed()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "wrong iteration after updating across interval time boundary",
+               2, timer.Iteration()
+       );
+
+       timer.Stop();
+       CPPUNIT_ASSERT_MESSAGE(
+               "stopped timer is running",
+               !timer.Running()
+       );
+       CPPUNIT_ASSERT_MESSAGE(
+               "stopped timer hit",
+               !timer.Hit()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "stopped timer has non-zero elapsed time",
+               0, timer.Elapsed()
+       );
+       CPPUNIT_ASSERT_EQUAL_MESSAGE(
+               "stopped timer at non-zero iteration",
+               0, timer.Iteration()
+       );
+}
+
+}
+}
diff --git a/tst/app/TimerTest.hpp b/tst/app/TimerTest.hpp
new file mode 100644 (file)
index 0000000..ead7d43
--- /dev/null
@@ -0,0 +1,30 @@
+#ifndef BLANK_TEST_APP_TIMERTEST_H_
+#define BLANK_TEST_APP_TIMERTEST_H_
+
+#include <cppunit/extensions/HelperMacros.h>
+
+
+namespace blank {
+namespace test {
+
+class TimerTest
+: public CppUnit::TestFixture {
+
+CPPUNIT_TEST_SUITE(TimerTest);
+
+CPPUNIT_TEST(testIntervalTimer);
+
+CPPUNIT_TEST_SUITE_END();
+
+public:
+       void setUp();
+       void tearDown();
+
+       void testIntervalTimer();
+
+};
+
+}
+}
+
+#endif