Added mocks module for the ADC

This commit is contained in:
jakeg00dwin 2024-09-02 13:52:56 -07:00
parent 5231d55d8e
commit 5db0f3209a
4 changed files with 122 additions and 0 deletions

View File

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

View File

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

84
mocks/MockADC/MockADC.c Normal file
View 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()
{
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
mocks/MockADC/MockADC.h Normal file
View 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