Patched from High Repo

This commit is contained in:
jakeg00dwin 2024-07-28 17:37:35 -07:00
parent 0eb4acc3f5
commit a118d621c8
5 changed files with 100 additions and 11 deletions

View File

@ -13,16 +13,30 @@
uint16_t fake_data[FAKESIZE]; uint16_t fake_data[FAKESIZE];
int fake_index = 0; 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) void ADC_Init(uint8_t pin_num)
{ {
mock_c()->actualCall("ADC_Init") mock_c()->actualCall("ADC_Init")
->withUnsignedIntParameters("pin_num", pin_num); ->withUnsignedIntParameters("pin_num", pin_num);
} }
void ADC_Enable(uint8_t pin_num) void ADC_Enable(void)
{ {
mock_c()->actualCall("ADC_Enable") mock_c()->actualCall("ADC_Enable");
->withUnsignedIntParameters("pin_num", pin_num);
} }
void ADC_Disable() void ADC_Disable()
@ -62,3 +76,9 @@ int MockADC_GetIndex(void)
{ {
return fake_index; return fake_index;
} }
bool MockADC_IsSetup(void)
{
return is_setup;
}

View File

@ -13,18 +13,18 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
/**
* A function that adds two to a number void ADC_Setup(void);
* @param a The first argument void ADC_SetPin(uint8_t pin_num);
*/
void ADC_Init(uint8_t pin_num); void ADC_Init(uint8_t pin_num);
void ADC_Enable(uint8_t pin_num); void ADC_Enable(void);
void ADC_Disable(); void ADC_Disable(void);
extern uint16_t (*ADC_ReadValue)(uint8_t pin_num); extern uint16_t (*ADC_ReadValue)(uint8_t pin_num);
void MockADC_PushValue(uint16_t value); void MockADC_PushValue(uint16_t value);
void MockADC_ZeroIndex(void); void MockADC_ZeroIndex(void);
int MockADC_GetIndex(void); int MockADC_GetIndex(void);
bool MockADC_IsSetup(void);
#endif //MOCKADC_H #endif //MOCKADC_H

View File

@ -19,8 +19,9 @@
void ZCD_Setup(void) void ZCD_Setup(void)
{ {
ADC_Init(7); ADC_Init(ZCD_PIN);
ADC_Enable(7); ADC_SetPin(ZCD_PIN);
ADC_Enable();
} }
bool ZCD_IsTriggered() bool ZCD_IsTriggered()

12
tests/load/CMakeLists.txt Normal file
View File

@ -0,0 +1,12 @@
# TEST_RUNNER
add_library(test_load
test_load.cpp
)
target_link_libraries(test_load
${CPPUTEST_LIBRARIES}/libCppUTest.a
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
load
MockADC
MockRegEdit
)

56
tests/load/test_load.cpp Normal file
View File

@ -0,0 +1,56 @@
/*
* Author: Jake G
* Date: 2024
* filename: test_load.cpp
* description:
*/
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTestExt/MockSupport.h"
#include <cstdint>
//This define allows us to dircetly include the device header without error.
#define _AVR_IO_H_
extern "C"
{
#include <iotn404.h> //ATtiny404 header fille.
#include "load.h"
#include "MockADC.h"
#include "MockADC.h"
}
TEST_GROUP(test_load)
{
void setup()
{
}
void teardown()
{
mock().checkExpectations();
mock().clear();
}
};
TEST(test_load, LoadPass)
{
CHECK_TRUE(true);
}
TEST(test_load, PortAHandlerSuccess)
{
mock().expectOneCall("ADC_Init")
.withUnsignedIntParameter("pin_num", 4);
mock().expectOneCall("ADC_Enable");
mock().expectOneCall("ADC_ReadValue_Impl")
.withUnsignedIntParameter("pin_num", 4);
mock().expectOneCall("ADC_Disable");
mock().expectOneCall("RegEdit_ClearBit")
.withPointerParameter("reg", (void *) &PORTA.OUT)
.withUnsignedIntParameter("bit_num", 7);
Load_HandleLoadPortA(4, 7);
}