Browse Source

Incomplete Timer test.

Marek Bel 5 years ago
parent
commit
67356ce356
3 changed files with 49 additions and 0 deletions
  1. 3 0
      CMakeLists.txt
  2. 12 0
      Tests/Arduino.h
  3. 34 0
      Tests/Timer_test.cpp

+ 3 - 0
CMakeLists.txt

@@ -11,6 +11,9 @@ target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR})
 set(TEST_SOURCES 
 	Tests/tests.cpp
 	Tests/Example_test.cpp
+	Tests/Timer_test.cpp
+	Firmware/Timer.cpp
 )
 add_executable(tests ${TEST_SOURCES})
+target_include_directories(tests PRIVATE Tests)
 target_link_libraries(tests Catch)

+ 12 - 0
Tests/Arduino.h

@@ -0,0 +1,12 @@
+/**
+ * @file
+ * @brief Mock file to allow test compilation.
+ * @author  Marek Bel
+ */
+
+#ifndef TESTS_ARDUINO_H_
+#define TESTS_ARDUINO_H_
+
+extern unsigned long millis();
+
+#endif /* TESTS_ARDUINO_H_ */

+ 34 - 0
Tests/Timer_test.cpp

@@ -0,0 +1,34 @@
+/**
+ * @file
+ * @author Marek Bel
+ */
+
+
+#include "catch.hpp"
+#include "../Firmware/Timer.h"
+
+unsigned long millis()
+{
+    return 1;
+}
+
+TEST_CASE( "LongTimer tested.", "[timer]" )
+{
+    LongTimer timer;
+    REQUIRE( timer.running() == false);
+
+    timer.start();
+    REQUIRE( timer.running() == true);
+
+    timer.stop();
+    REQUIRE( timer.running() == false);
+
+    timer.start();
+    REQUIRE( timer.expired(0) == true );
+    REQUIRE( timer.expired(0) == false );
+    REQUIRE( timer.running() == false);
+
+    timer.start();
+    REQUIRE( timer.expired(1) == false );
+    REQUIRE( timer.running() == true);
+}