diff --git a/CMakeLists.txt b/CMakeLists.txt index 2508a1bb..03ff80e3 100644 --- a/CMakeLists.txt +++ b/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) diff --git a/Tests/Arduino.h b/Tests/Arduino.h new file mode 100644 index 00000000..c6740d5e --- /dev/null +++ b/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_ */ diff --git a/Tests/Timer_test.cpp b/Tests/Timer_test.cpp new file mode 100644 index 00000000..9bcf1f99 --- /dev/null +++ b/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); +}