generated from TDD-Templates/cmake_cpputest_template_avr
parent
b96945a2a5
commit
22c191363e
|
@ -1,4 +1,6 @@
|
||||||
|
add_subdirectory(MockRegEdit)
|
||||||
|
add_subdirectory(MockADC)
|
||||||
|
add_subdirectory(TimerMock)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
add_library(MockADC STATIC
|
||||||
|
MockADC.c
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(MockADC PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
|
@ -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()
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
|
@ -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
|
|
@ -0,0 +1,12 @@
|
||||||
|
add_library(MockRegEdit STATIC
|
||||||
|
MockRegEdit.c
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(MockRegEdit PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(MockRegEdit
|
||||||
|
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||||
|
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||||
|
)
|
|
@ -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, uint8_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_OR_Num")
|
||||||
|
->withPointerParameters("reg", reg)
|
||||||
|
->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void RegEdit_AND_Num(void *reg, uint8_t num)
|
||||||
|
{
|
||||||
|
mock_c()->actualCall("RegEdit_AND_Num")
|
||||||
|
->withPointerParameters("reg", reg)
|
||||||
|
->withUnsignedIntParameters("num", num);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void RegEdit_SetNum(void *reg, uint8_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;
|
||||||
|
}
|
|
@ -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, uint8_t num);
|
||||||
|
void RegEdit_AND_Num(void *reg, uint8_t num);
|
||||||
|
|
||||||
|
void RegEdit_SetNum(void *reg, uint8_t num);
|
||||||
|
|
||||||
|
uint8_t RegEdit_ReadReg(void *reg);
|
||||||
|
|
||||||
|
#endif //MOCKREGEDIT_H
|
|
@ -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);
|
||||||
|
}
|
|
@ -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
|
|
@ -0,0 +1,7 @@
|
||||||
|
add_library(TimerMock STATIC
|
||||||
|
TimerMock.c
|
||||||
|
)
|
||||||
|
|
||||||
|
target_include_directories(TimerMock PUBLIC
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}
|
||||||
|
)
|
|
@ -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);
|
||||||
|
}
|
|
@ -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
|
Loading…
Reference in New Issue