Refactored Test dir layout
- Removed old cpputest include lines. + Added new cmake var include/link.
This commit is contained in:
parent
9e2358f9bf
commit
8e00f7406a
25 changed files with 432 additions and 21 deletions
|
|
@ -1,17 +1,28 @@
|
|||
# File: tests/ADC/CMakeLists.txt
|
||||
|
||||
add_subdirectory(mocks)
|
||||
add_subdirectory(fakes)
|
||||
add_subdirectory(stubs)
|
||||
|
||||
# TEST_RUNNER
|
||||
add_library(test_ADC
|
||||
test_ADC.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_ADC
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
ADC
|
||||
MockRegEdit
|
||||
)
|
||||
|
||||
#Needed for the tests to function
|
||||
include_directories(
|
||||
/usr/local/avr/include/avr
|
||||
#/usr/lib/avr/include/avr
|
||||
target_include_directories(test_ADC PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
#Next comes the shared and non-module specific test depencencies.
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/mocks/
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/fakes/
|
||||
${CMAKE_SOURCE_DIR}/tests/shared/stubs/
|
||||
|
||||
${CMAKE_SOURCE_DIR}/inc
|
||||
)
|
||||
|
|
|
|||
0
tests/ADC/fakes/CMakeLists.txt
Normal file
0
tests/ADC/fakes/CMakeLists.txt
Normal file
0
tests/ADC/mocks/CMakeLists.txt
Normal file
0
tests/ADC/mocks/CMakeLists.txt
Normal file
0
tests/ADC/stubs/CMakeLists.txt
Normal file
0
tests/ADC/stubs/CMakeLists.txt
Normal file
|
|
@ -8,7 +8,7 @@ add_subdirectory(simple_test)
|
|||
add_subdirectory(ADC)
|
||||
add_subdirectory(MockADC)
|
||||
|
||||
|
||||
add_subdirectory(shared)
|
||||
|
||||
|
||||
# TEST_RUNNER
|
||||
|
|
@ -17,8 +17,7 @@ add_executable(AllTests
|
|||
)
|
||||
|
||||
target_link_libraries(AllTests
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
# TEST_LINKS
|
||||
test_blink
|
||||
test_ADC
|
||||
|
|
@ -31,8 +30,7 @@ add_executable(Mock_Tests
|
|||
)
|
||||
|
||||
target_link_libraries(Mock_Tests
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
test_MockRegEdit
|
||||
test_MockADC
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ add_library(test_MockADC
|
|||
)
|
||||
|
||||
target_link_libraries(test_MockADC
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
MockADC
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@ add_library(test_MockRegEdit
|
|||
)
|
||||
|
||||
target_link_libraries(test_MockRegEdit
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
MockRegEdit
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ add_library(test_RegEdit
|
|||
)
|
||||
|
||||
target_link_libraries(test_RegEdit
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
RegEdit
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ add_library(test_blink
|
|||
)
|
||||
|
||||
target_link_libraries(test_blink
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
#${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
blink
|
||||
)
|
||||
|
|
|
|||
5
tests/shared/CMakeLists.txt
Normal file
5
tests/shared/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
# File: tests/shared/CMakeLists.txt
|
||||
|
||||
add_subdirectory(mocks)
|
||||
add_subdirectory(fakes)
|
||||
add_subdirectory(stubs)
|
||||
0
tests/shared/fakes/CMakeLists.txt
Normal file
0
tests/shared/fakes/CMakeLists.txt
Normal file
6
tests/shared/mocks/CMakeLists.txt
Normal file
6
tests/shared/mocks/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
add_subdirectory(MockRegEdit)
|
||||
add_subdirectory(MockADC)
|
||||
add_subdirectory(TimerMock)
|
||||
|
||||
|
||||
|
||||
11
tests/shared/mocks/MockADC/CMakeLists.txt
Normal file
11
tests/shared/mocks/MockADC/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
add_library(MockADC STATIC
|
||||
MockADC.c
|
||||
)
|
||||
|
||||
target_include_directories(MockADC PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(MockADC
|
||||
${CPPUTEST_LIBRARIES}
|
||||
)
|
||||
84
tests/shared/mocks/MockADC/MockADC.c
Normal file
84
tests/shared/mocks/MockADC/MockADC.c
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/*
|
||||
* Author: username
|
||||
* Date: 2024
|
||||
* filename: MockADC.c
|
||||
* description: module_purpose
|
||||
*/
|
||||
|
||||
#include "MockADC.h"
|
||||
#include "CppUTestExt/MockSupport_c.h"
|
||||
|
||||
#define FAKESIZE 256
|
||||
|
||||
uint16_t fake_data[FAKESIZE];
|
||||
int fake_index = 0;
|
||||
|
||||
static bool is_setup = false;
|
||||
|
||||
|
||||
|
||||
void ADC_SetPin(uint8_t pin_num)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void ADC_Setup(void)
|
||||
{
|
||||
is_setup = true;
|
||||
return;
|
||||
}
|
||||
|
||||
void ADC_Init(uint8_t pin_num)
|
||||
{
|
||||
mock_c()->actualCall("ADC_Init")
|
||||
->withUnsignedIntParameters("pin_num", pin_num);
|
||||
}
|
||||
|
||||
void ADC_Enable(void)
|
||||
{
|
||||
mock_c()->actualCall("ADC_Enable");
|
||||
}
|
||||
|
||||
void ADC_Disable(void)
|
||||
{
|
||||
mock_c()->actualCall("ADC_Disable");
|
||||
}
|
||||
|
||||
uint16_t ADC_ReadValue_Impl(uint8_t pin_num)
|
||||
{
|
||||
mock_c()->actualCall("ADC_ReadValue_Impl")
|
||||
->withUnsignedIntParameters("pin_num", pin_num);
|
||||
|
||||
if(fake_index == 0){
|
||||
return 0;
|
||||
}
|
||||
return fake_data[--fake_index];
|
||||
}
|
||||
|
||||
uint16_t (*ADC_ReadValue)(uint8_t pin_num) = ADC_ReadValue_Impl;
|
||||
|
||||
|
||||
void MockADC_PushValue(uint16_t value){
|
||||
if(fake_index >= FAKESIZE - 1){
|
||||
return;
|
||||
}
|
||||
fake_data[fake_index++] = value;
|
||||
}
|
||||
|
||||
|
||||
void MockADC_ZeroIndex(void)
|
||||
{
|
||||
fake_index = 0;
|
||||
}
|
||||
|
||||
|
||||
int MockADC_GetIndex(void)
|
||||
{
|
||||
return fake_index;
|
||||
}
|
||||
|
||||
|
||||
bool MockADC_IsSetup(void)
|
||||
{
|
||||
return is_setup;
|
||||
}
|
||||
30
tests/shared/mocks/MockADC/MockADC.h
Normal file
30
tests/shared/mocks/MockADC/MockADC.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* @brief PUT_TEXT_HERE
|
||||
* @details This file is...
|
||||
* @author username
|
||||
* @date todays_date
|
||||
* @copyright None
|
||||
* @file MOCKADC.h
|
||||
*/
|
||||
|
||||
#ifndef MOCKADC_H
|
||||
#define MOCKADC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
void ADC_Setup(void);
|
||||
void ADC_SetPin(uint8_t pin_num);
|
||||
void ADC_Init(uint8_t pin_num);
|
||||
void ADC_Enable(void);
|
||||
void ADC_Disable(void);
|
||||
|
||||
extern uint16_t (*ADC_ReadValue)(uint8_t pin_num);
|
||||
|
||||
void MockADC_PushValue(uint16_t value);
|
||||
void MockADC_ZeroIndex(void);
|
||||
int MockADC_GetIndex(void);
|
||||
bool MockADC_IsSetup(void);
|
||||
|
||||
#endif //MOCKADC_H
|
||||
11
tests/shared/mocks/MockRegEdit/CMakeLists.txt
Normal file
11
tests/shared/mocks/MockRegEdit/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
add_library(MockRegEdit STATIC
|
||||
MockRegEdit.c
|
||||
)
|
||||
|
||||
target_include_directories(MockRegEdit PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(MockRegEdit
|
||||
${CPPUTEST_LIBRARIES}
|
||||
)
|
||||
85
tests/shared/mocks/MockRegEdit/MockRegEdit.c
Normal file
85
tests/shared/mocks/MockRegEdit/MockRegEdit.c
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* Author: username
|
||||
* Date: 2024
|
||||
* filename: MockRegEdit.c
|
||||
* description: module_purpose
|
||||
*/
|
||||
|
||||
#include "MockRegEdit.h"
|
||||
#include "CppUTestExt/MockSupport_c.h"
|
||||
|
||||
|
||||
void RegEdit_SetRegister(void *reg)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_SetRegister")
|
||||
->withPointerParameters("reg", reg);
|
||||
}
|
||||
|
||||
void RegEdit_ClearRegister(void *reg)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_ClearRegister")
|
||||
->withPointerParameters("reg", reg);
|
||||
}
|
||||
|
||||
|
||||
void RegEdit_SetBit(void *reg, uint8_t bit_num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_SetBit")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("bit_num", bit_num);
|
||||
}
|
||||
|
||||
|
||||
void RegEdit_ClearBit(void *reg, uint8_t bit_num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_ClearBit")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("bit_num", bit_num);
|
||||
}
|
||||
|
||||
|
||||
bool RegEdit_IsBitSet(void *reg, uint8_t bit_num)
|
||||
{
|
||||
|
||||
return mock_c()->actualCall("RegEdit_IsBitSet")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("bit_num", bit_num)
|
||||
->returnBoolValueOrDefault(true);
|
||||
//return mock_c()->returnBoolValueOrDefault(true);
|
||||
}
|
||||
|
||||
void RegEdit_OR_Num(void *reg, uint32_t num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_OR_Num")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("num", num);
|
||||
}
|
||||
|
||||
|
||||
void RegEdit_AND_Num(void *reg, uint32_t num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_AND_Num")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("num", num);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RegEdit_SetNum(void *reg, uint32_t num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_SetNum")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("num", num);
|
||||
}
|
||||
|
||||
|
||||
uint8_t RegEdit_ReadReg(void *reg)
|
||||
{
|
||||
uint8_t value = *(uint8_t *)reg;
|
||||
|
||||
mock_c()->actualCall("RegEdit_ReadReg")
|
||||
->withPointerParameters("reg", reg)
|
||||
->returnUnsignedIntValueOrDefault(value);
|
||||
|
||||
return value;
|
||||
}
|
||||
30
tests/shared/mocks/MockRegEdit/MockRegEdit.h
Normal file
30
tests/shared/mocks/MockRegEdit/MockRegEdit.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* @brief PUT_TEXT_HERE
|
||||
* @details This file is...
|
||||
* @author username
|
||||
* @date todays_date
|
||||
* @copyright None
|
||||
* @file MockRegEdit.h
|
||||
*/
|
||||
|
||||
#ifndef MOCKREGEDIT_H
|
||||
#define MOCKREGEDIT_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
void RegEdit_SetRegister(void *reg);
|
||||
void RegEdit_ClearRegister(void *reg);
|
||||
void RegEdit_SetBit(void *reg, uint8_t bit_num);
|
||||
void RegEdit_ClearBit(void *reg, uint8_t bit_num);
|
||||
bool RegEdit_IsBitSet(void *reg, uint8_t bit_num);
|
||||
|
||||
void RegEdit_OR_Num(void *reg, uint32_t num);
|
||||
void RegEdit_AND_Num(void *reg, uint32_t num);
|
||||
|
||||
void RegEdit_SetNum(void *reg, uint32_t num);
|
||||
|
||||
uint8_t RegEdit_ReadReg(void *reg);
|
||||
|
||||
#endif //MOCKREGEDIT_H
|
||||
51
tests/shared/mocks/MockRegEdit/u8_comparator.cpp
Normal file
51
tests/shared/mocks/MockRegEdit/u8_comparator.cpp
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
#include "u8_comparator.hpp"
|
||||
#include "CppUTest/SimpleString.h"
|
||||
|
||||
/*
|
||||
class MyTypeComparator : public MockNamedValueComparator
|
||||
{
|
||||
public:
|
||||
virtual bool isEqual(const void* object1, const void* object2)
|
||||
{
|
||||
return object1 == object2;
|
||||
}
|
||||
virtual SimpleString valueToString(const void* object)
|
||||
{
|
||||
return StringFrom(object);
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
bool UInt8PointerComparator::isEqual(const void* object1, const void* object2) {
|
||||
const uint8_t* ptr1 = reinterpret_cast<const uint8_t*>(object1);
|
||||
const uint8_t* ptr2 = reinterpret_cast<const uint8_t*>(object2);
|
||||
return std::memcmp(ptr1, ptr2, sizeof(uint8_t)) == 0;
|
||||
}
|
||||
|
||||
SimpleString UInt8PointerComparator::valueToString(const void* object) {
|
||||
const uint8_t* ptr = reinterpret_cast<const uint8_t*>(object);
|
||||
return StringFromFormat("0x%02x", *ptr);
|
||||
}
|
||||
|
||||
/*
|
||||
bool UInt8PointerComparator::isEqual(const void* object1, const void* object2) const {
|
||||
const uint8_t* ptr1 = static_cast<const uint8_t*>(object1);
|
||||
const uint8_t* ptr2 = static_cast<const uint8_t*>(object2);
|
||||
return std::memcmp(ptr1, ptr2, sizeof(uint8_t)) == 0;
|
||||
}
|
||||
|
||||
SimpleString UInt8PointerComparator::valueToString(const void* object) const {
|
||||
const uint8_t* ptr = static_cast<const uint8_t*>(object);
|
||||
return StringFromFormat("0x%02x", *ptr);
|
||||
}
|
||||
*/
|
||||
|
||||
bool UInt8Comparator::isEqual(const void* object1, const void* object2) {
|
||||
return (uint8_t*)object1 == (uint8_t *)object2;
|
||||
}
|
||||
|
||||
SimpleString UInt8Comparator::valueToString(const void* object) {
|
||||
//uint8_t value = reinterpret_cast<uint8_t>(object);
|
||||
const uint8_t *ptr = reinterpret_cast<const uint8_t*>(object);
|
||||
return StringFromFormat("0x%02x", *ptr);
|
||||
}
|
||||
20
tests/shared/mocks/MockRegEdit/u8_comparator.hpp
Normal file
20
tests/shared/mocks/MockRegEdit/u8_comparator.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef U8_COMPARATOR_H
|
||||
#define U8_COMPARATOR_H
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <CppUTestExt/MockSupport.h>
|
||||
|
||||
class UInt8PointerComparator : public MockNamedValueComparator {
|
||||
public:
|
||||
virtual bool isEqual(const void* object1, const void* object2) override;
|
||||
SimpleString valueToString(const void* object) override;
|
||||
};
|
||||
|
||||
class UInt8Comparator : public MockNamedValueComparator {
|
||||
public:
|
||||
virtual bool isEqual(const void* object1, const void* object2) override;
|
||||
SimpleString valueToString(const void* object) override;
|
||||
};
|
||||
|
||||
#endif //U8_COMPARATOR_H
|
||||
11
tests/shared/mocks/TimerMock/CMakeLists.txt
Normal file
11
tests/shared/mocks/TimerMock/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
add_library(TimerMock STATIC
|
||||
TimerMock.c
|
||||
)
|
||||
|
||||
target_include_directories(TimerMock PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
|
||||
target_link_libraries(TimerMock
|
||||
${CPPUTEST_LIBRARIES}
|
||||
)
|
||||
31
tests/shared/mocks/TimerMock/TimerMock.c
Normal file
31
tests/shared/mocks/TimerMock/TimerMock.c
Normal 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);
|
||||
}
|
||||
26
tests/shared/mocks/TimerMock/TimerMock.h
Normal file
26
tests/shared/mocks/TimerMock/TimerMock.h
Normal 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
|
||||
0
tests/shared/stubs/CMakeLists.txt
Normal file
0
tests/shared/stubs/CMakeLists.txt
Normal file
|
|
@ -5,7 +5,6 @@ add_library(simple_test
|
|||
)
|
||||
|
||||
target_link_libraries(simple_test
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
${CPPUTEST_LIBRARIES}
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue