From 67356ce35669c714f4d805a05ea90363c4c609db Mon Sep 17 00:00:00 2001 From: Marek Bel Date: Mon, 11 Jun 2018 22:50:52 +0200 Subject: [PATCH] Incomplete Timer test. --- CMakeLists.txt | 3 +++ Tests/Arduino.h | 12 ++++++++++++ Tests/Timer_test.cpp | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) create mode 100644 Tests/Arduino.h create mode 100644 Tests/Timer_test.cpp 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); +}