Added mocking module for timer

The mock of the timer module uses the cpputest mocking functions.
This commit is contained in:
Jake Goodwin 2024-09-02 13:33:08 -07:00
parent 255d54b90e
commit fc715011b8
7 changed files with 114 additions and 0 deletions

View File

@ -1,4 +1,5 @@
add_subdirectory(MockRegEdit)
add_subdirectory(TimerMock)

View File

@ -0,0 +1,7 @@
add_library(TimerMock STATIC
TimerMock.c
)
target_include_directories(TimerMock PUBLIC
${CMAKE_CURRENT_LIST_DIR}
)

View File

@ -0,0 +1,31 @@
/*
* Author: Jake G
* Date: 2024-09-02
* filename: TimerMock.c
* description: mocks timers
*/
#include "TimerMock.h"
#include <stdbool.h>
#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);
}

View File

@ -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 <stdint.h>
/**
* A function
* @param a The first argument
*/
void Timer_Start(void);
void Timer_Stop(void);
uint16_t Timer_GetOverflowCount(void);
#endif //TIMER_MOCK_H

View File

@ -57,3 +57,4 @@ add_subdirectory(timer)
add_subdirectory(SuperLoop)
add_subdirectory(Relays)
add_subdirectory(TimerMock)

View File

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

View File

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