Incomplete Timer test.

This commit is contained in:
Marek Bel 2018-06-11 22:50:52 +02:00
parent a1fdf1d31e
commit 67356ce356
3 changed files with 49 additions and 0 deletions

View File

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

12
Tests/Arduino.h Normal file
View File

@ -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
Tests/Timer_test.cpp Normal file
View File

@ -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);
}