diff --git a/mocks/CMakeLists.txt b/mocks/CMakeLists.txt index 7540514..fa73af7 100644 --- a/mocks/CMakeLists.txt +++ b/mocks/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory(MockRegEdit) +add_subdirectory(TimerMock) diff --git a/mocks/TimerMock/CMakeLists.txt b/mocks/TimerMock/CMakeLists.txt new file mode 100644 index 0000000..fe90a85 --- /dev/null +++ b/mocks/TimerMock/CMakeLists.txt @@ -0,0 +1,7 @@ +add_library(TimerMock STATIC + TimerMock.c +) + +target_include_directories(TimerMock PUBLIC + ${CMAKE_CURRENT_LIST_DIR} +) diff --git a/mocks/TimerMock/TimerMock.c b/mocks/TimerMock/TimerMock.c new file mode 100644 index 0000000..09880b4 --- /dev/null +++ b/mocks/TimerMock/TimerMock.c @@ -0,0 +1,31 @@ +/* + * Author: Jake G + * Date: 2024-09-02 + * filename: TimerMock.c + * description: mocks timers + */ + +#include "TimerMock.h" +#include +#include "CppUTestExt/MockSupport_c.h" + +static bool timer_started = false; + +void Timer_Start(void) +{ + mock_c()->actualCall("Timer_Start"); + timer_started = true; +} + +void Timer_Stop(void) +{ + mock_c()->actualCall("Timer_Stop"); + timer_started = false; +} + +uint16_t Timer_GetOverflowCount(void) +{ + uint16_t time = 0xAAAA; + return mock_c()->actualCall("Timer_GetOverflowCount") + ->returnUnsignedIntValueOrDefault(time); +} diff --git a/mocks/TimerMock/TimerMock.h b/mocks/TimerMock/TimerMock.h new file mode 100644 index 0000000..7e4e02b --- /dev/null +++ b/mocks/TimerMock/TimerMock.h @@ -0,0 +1,26 @@ +/** + * @brief A Mock of the timer module. + * @details This file is only used for testing. + * @author Jake G + * @date 2024-09-02 + * @copyright None + * @file TimerMock.h + */ + +#ifndef TIMER_MOCK_H +#define TIMER_MOCK_H + +#include + +/** + * A function + * @param a The first argument + */ +void Timer_Start(void); + +void Timer_Stop(void); + +uint16_t Timer_GetOverflowCount(void); + + +#endif //TIMER_MOCK_H diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 49ebd28..ed905b1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -57,3 +57,4 @@ add_subdirectory(timer) add_subdirectory(SuperLoop) add_subdirectory(Relays) +add_subdirectory(TimerMock) diff --git a/tests/TimerMock/CMakeLists.txt b/tests/TimerMock/CMakeLists.txt new file mode 100644 index 0000000..11e0612 --- /dev/null +++ b/tests/TimerMock/CMakeLists.txt @@ -0,0 +1,10 @@ +# TEST_RUNNER +add_library(test_TimerMock + test_TimerMock.cpp +) + +target_link_libraries(test_TimerMock + ${CPPUTEST_LIBRARIES}/libCppUTest.a + ${CPPUTEST_LIBRARIES}/libCppUTestExt.a + TimerMock +) diff --git a/tests/TimerMock/test_TimerMock.cpp b/tests/TimerMock/test_TimerMock.cpp new file mode 100644 index 0000000..ef2af1b --- /dev/null +++ b/tests/TimerMock/test_TimerMock.cpp @@ -0,0 +1,38 @@ +/* + * Author: username + * Date: todays_date + * filename: test_TimerMock.c + * description: module_purpose + */ + +#include "CppUTest/CommandLineTestRunner.h" + +extern "C" +{ +#include "TimerMock.h" +} + +TEST_GROUP(test_TimerMock) +{ + void setup() + { + + } + void teardown() + { + + } +}; + +TEST(test_TimerMock, FirstTest) +{ + FAIL("Fail me!"); +} + +TEST(test_TimerMock, SecondTest) +{ + STRCMP_EQUAL("hello", "world"); + LONGS_EQUAL(1, 2); + CHECK(false); +} +