Automatic formatting standard applied to tests dir.
This commit is contained in:
parent
4b9298f321
commit
9402cd779d
15 changed files with 215 additions and 325 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Author: Jake G
|
* Author: Jake G
|
||||||
* Date: 2024
|
* Date: 2024
|
||||||
* filename: test_ADC.c
|
* filename: test_ADC.c
|
||||||
* description: module_purpose
|
* description: module_purpose
|
||||||
*/
|
*/
|
||||||
|
|
@ -9,65 +9,56 @@
|
||||||
#include "CppUTestExt/MockSupport.h"
|
#include "CppUTestExt/MockSupport.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#include "ch32v003hw.h"
|
|
||||||
#include "ADC.h"
|
#include "ADC.h"
|
||||||
|
#include "ch32v003hw.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_GROUP(test_ADC)
|
TEST_GROUP(test_ADC){
|
||||||
{
|
void setup(){
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
} void teardown(){
|
||||||
void teardown()
|
|
||||||
{
|
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
mock().clear();
|
mock().clear();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
TEST(test_ADC, FirstTest)
|
TEST(test_ADC, FirstTest)
|
||||||
{
|
{
|
||||||
CHECK(true);
|
CHECK(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_PowerOnTest)
|
TEST(test_ADC, ADC_PowerOnTest)
|
||||||
{
|
{
|
||||||
// The ADCON bit should be high in the ADC_CTRL2 register.
|
// The ADCON bit should be high in the ADC_CTRL2 register.
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_SetBit").withPointerParameter("reg", (void *)&ADC1->CTLR2).withUnsignedIntParameter("bit_num", ADC_ADON);
|
||||||
.withPointerParameter("reg", (void *) &ADC1->CTLR2)
|
|
||||||
.withUnsignedIntParameter("bit_num", ADC_ADON);
|
|
||||||
|
|
||||||
ADC_PowerOn();
|
ADC_PowerOn();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_SetupSetsRegisters)
|
TEST(test_ADC, ADC_SetupSetsRegisters)
|
||||||
{
|
{
|
||||||
|
// R32_GPIOD_CFGLR --> 0x40011400
|
||||||
//R32_GPIOD_CFGLR --> 0x40011400
|
// DESC: PD port configuration register low
|
||||||
//DESC: PD port configuration register low
|
// RESET VALUE--> 0x44444444
|
||||||
//RESET VALUE--> 0x44444444
|
|
||||||
|
|
||||||
//R32_GPIOD_INDR --> 0x40011408
|
|
||||||
//DESC: PD port input data register
|
|
||||||
|
|
||||||
//R32_GPIOD_BSHR --> 0x40011410
|
// R32_GPIOD_INDR --> 0x40011408
|
||||||
//DESC: PD port set/reset register
|
// DESC: PD port input data register
|
||||||
|
|
||||||
//R32_GPIOD_BCR --> 0x40011414
|
// R32_GPIOD_BSHR --> 0x40011410
|
||||||
//DESC: PD port reset register
|
// DESC: PD port set/reset register
|
||||||
|
|
||||||
//R32_GPIOD_LCKR --> 0x40011418
|
|
||||||
//DESC: PD port configuration lock register
|
|
||||||
|
|
||||||
//Setup the ADC clock and divider. The internal HSI-XC is 24MHz.
|
// R32_GPIOD_BCR --> 0x40011414
|
||||||
|
// DESC: PD port reset register
|
||||||
|
|
||||||
|
// R32_GPIOD_LCKR --> 0x40011418
|
||||||
//Setup PORTD pin(s) as analog input.
|
// DESC: PD port configuration lock register
|
||||||
|
|
||||||
|
// Setup the ADC clock and divider. The internal HSI-XC is 24MHz.
|
||||||
|
|
||||||
|
// Setup PORTD pin(s) as analog input.
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//Clears control register A for ADC0
|
//Clears control register A for ADC0
|
||||||
|
|
@ -99,9 +90,9 @@ TEST(test_ADC, ADC_SetupSetsRegisters)
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_SetBit")
|
||||||
.withPointerParameter("reg", (void *) &ADC0.CTRLD)
|
.withPointerParameter("reg", (void *) &ADC0.CTRLD)
|
||||||
.withUnsignedIntParameter("bit_num", 4);
|
.withUnsignedIntParameter("bit_num", 4);
|
||||||
|
|
||||||
*/
|
*/
|
||||||
ADC_Setup();
|
ADC_Setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_InitPortAPin7UsesCorrectRegisters)
|
TEST(test_ADC, ADC_InitPortAPin7UsesCorrectRegisters)
|
||||||
|
|
@ -111,8 +102,8 @@ TEST(test_ADC, ADC_InitPortAPin7UsesCorrectRegisters)
|
||||||
mock().expectOneCall("RegEdit_ClearBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
||||||
.withUnsignedIntParameter("bit_num", 7);
|
.withUnsignedIntParameter("bit_num", 7);
|
||||||
|
|
||||||
//Check that the pullup is off
|
//Check that the pullup is off
|
||||||
mock().expectOneCall("RegEdit_ClearBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
||||||
.withUnsignedIntParameter("bit_num", 7);
|
.withUnsignedIntParameter("bit_num", 7);
|
||||||
|
|
@ -134,8 +125,8 @@ TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters)
|
||||||
mock().expectOneCall("RegEdit_ClearBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
||||||
.withUnsignedIntParameter("bit_num", 0);
|
.withUnsignedIntParameter("bit_num", 0);
|
||||||
|
|
||||||
//Check that the pullup is off
|
//Check that the pullup is off
|
||||||
mock().expectOneCall("RegEdit_ClearBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
||||||
.withUnsignedIntParameter("bit_num", 0);
|
.withUnsignedIntParameter("bit_num", 0);
|
||||||
|
|
@ -145,7 +136,7 @@ TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters)
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_SetBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.PIN0CTRL)
|
.withPointerParameter("reg", (void *) &PORTA.PIN0CTRL)
|
||||||
.withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc);
|
.withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc);
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ADC_Init(0);
|
ADC_Init(0);
|
||||||
|
|
@ -153,7 +144,7 @@ TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters)
|
||||||
|
|
||||||
TEST(test_ADC, ADC_InitDoesNothingOnHighPinNumbers)
|
TEST(test_ADC, ADC_InitDoesNothingOnHighPinNumbers)
|
||||||
{
|
{
|
||||||
//mock().expectNoCall("RegEdit_SetBit");
|
// mock().expectNoCall("RegEdit_SetBit");
|
||||||
ADC_Init(8);
|
ADC_Init(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -166,7 +157,6 @@ TEST(test_ADC, ADC_EnablePasses)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
ADC_Enable();
|
ADC_Enable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_DisablePasses)
|
TEST(test_ADC, ADC_DisablePasses)
|
||||||
|
|
@ -190,40 +180,35 @@ TEST(test_ADC, ADC_SetPinSetsRightRegisters)
|
||||||
mock().expectOneCall("RegEdit_SetNum")
|
mock().expectOneCall("RegEdit_SetNum")
|
||||||
.withPointerParameter("reg", (void *) &ADC0.MUXPOS)
|
.withPointerParameter("reg", (void *) &ADC0.MUXPOS)
|
||||||
.withUnsignedIntParameter("num", 4);
|
.withUnsignedIntParameter("num", 4);
|
||||||
|
|
||||||
*/
|
*/
|
||||||
ADC_SetPin(4);
|
ADC_SetPin(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(test_ADC, ADC_SetPinFailsOnInvalidPin)
|
TEST(test_ADC, ADC_SetPinFailsOnInvalidPin)
|
||||||
{
|
{
|
||||||
ADC_SetPin(8);
|
ADC_SetPin(8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static uint16_t ADC_ReadValueFake(uint8_t pin_num)
|
static uint16_t ADC_ReadValueFake(uint8_t pin_num)
|
||||||
{
|
{
|
||||||
return 512;
|
return 512;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_GROUP(test_ADCRead)
|
TEST_GROUP(test_ADCRead){
|
||||||
{
|
void setup(){
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
UT_PTR_SET(ADC_ReadValue, ADC_ReadValueFake);
|
UT_PTR_SET(ADC_ReadValue, ADC_ReadValueFake);
|
||||||
}
|
}
|
||||||
|
|
||||||
void teardown()
|
void teardown()
|
||||||
{
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
;
|
||||||
|
|
||||||
TEST(test_ADCRead, FunctionPointerSwapWorks)
|
TEST(test_ADCRead, FunctionPointerSwapWorks)
|
||||||
{
|
{
|
||||||
uint16_t value = ADC_ReadValue(0);
|
uint16_t value = ADC_ReadValue(0);
|
||||||
|
|
||||||
LONGS_EQUAL(512, value);
|
LONGS_EQUAL(512, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,14 @@
|
||||||
#include "CppUTest/CommandLineTestRunner.h"
|
#include "CppUTest/CommandLineTestRunner.h"
|
||||||
|
|
||||||
|
// ImportTestGroups
|
||||||
//ImportTestGroups
|
|
||||||
IMPORT_TEST_GROUP(simple_test);
|
IMPORT_TEST_GROUP(simple_test);
|
||||||
IMPORT_TEST_GROUP(test_ADC);
|
IMPORT_TEST_GROUP(test_ADC);
|
||||||
IMPORT_TEST_GROUP(test_RegEdit);
|
IMPORT_TEST_GROUP(test_RegEdit);
|
||||||
IMPORT_TEST_GROUP(test_blink);
|
IMPORT_TEST_GROUP(test_blink);
|
||||||
|
|
||||||
//START: main
|
// START: main
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
return RUN_ALL_TESTS(argc, argv);
|
return RUN_ALL_TESTS(argc, argv);
|
||||||
}
|
}
|
||||||
//END: main
|
// END: main
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,32 @@
|
||||||
/*
|
/*
|
||||||
* Author: Jake G
|
* Author: Jake G
|
||||||
* Date: 2024
|
* Date: 2024
|
||||||
* filename: test_MockADC.c
|
* filename: test_MockADC.c
|
||||||
* description:
|
* description:
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CppUTest/CommandLineTestRunner.h"
|
#include "CppUTest/CommandLineTestRunner.h"
|
||||||
#include "CppUTestExt/MockSupport.h"
|
#include "CppUTestExt/MockSupport.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#include "MockADC.h"
|
#include "MockADC.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_GROUP(test_MockADC)
|
TEST_GROUP(test_MockADC){
|
||||||
{
|
void setup(){
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
} void teardown(){
|
||||||
void teardown()
|
|
||||||
{
|
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
mock().clear();
|
mock().clear();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
TEST(test_MockADC, ADC_InitExpects)
|
TEST(test_MockADC, ADC_InitExpects)
|
||||||
{
|
{
|
||||||
mock().expectOneCall("ADC_Init")
|
mock().expectOneCall("ADC_Init").withUnsignedIntParameter("pin_num", 7);
|
||||||
.withUnsignedIntParameter("pin_num", 7);
|
|
||||||
|
|
||||||
ADC_Init(7);
|
ADC_Init(7);
|
||||||
}
|
}
|
||||||
|
|
@ -42,7 +38,6 @@ TEST(test_MockADC, ADC_EnableExpects)
|
||||||
ADC_Enable();
|
ADC_Enable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(test_MockADC, ADC_DisableExpect)
|
TEST(test_MockADC, ADC_DisableExpect)
|
||||||
{
|
{
|
||||||
mock().expectOneCall("ADC_Disable");
|
mock().expectOneCall("ADC_Disable");
|
||||||
|
|
@ -54,22 +49,18 @@ TEST(test_MockADC, ADC_ReadValue)
|
||||||
{
|
{
|
||||||
MockADC_ZeroIndex();
|
MockADC_ZeroIndex();
|
||||||
MockADC_PushValue(512);
|
MockADC_PushValue(512);
|
||||||
|
|
||||||
mock().expectOneCall("ADC_ReadValue_Impl")
|
mock().expectOneCall("ADC_ReadValue_Impl").withUnsignedIntParameter("pin_num", 0x2);
|
||||||
.withUnsignedIntParameter("pin_num", 0x2);
|
|
||||||
|
|
||||||
uint16_t val = ADC_ReadValue(0x2);
|
uint16_t val = ADC_ReadValue(0x2);
|
||||||
LONGS_EQUAL(512, val);
|
LONGS_EQUAL(512, val);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_MockADC, ADC_ReadValueReturnsZeroOnEmptyBuffer)
|
TEST(test_MockADC, ADC_ReadValueReturnsZeroOnEmptyBuffer)
|
||||||
{
|
{
|
||||||
MockADC_ZeroIndex();
|
MockADC_ZeroIndex();
|
||||||
|
|
||||||
mock().expectOneCall("ADC_ReadValue_Impl")
|
mock().expectOneCall("ADC_ReadValue_Impl").withUnsignedIntParameter("pin_num", 0x2).andReturnValue(0x0000);
|
||||||
.withUnsignedIntParameter("pin_num", 0x2)
|
|
||||||
.andReturnValue(0x0000);
|
|
||||||
|
|
||||||
uint16_t val = ADC_ReadValue(0x2);
|
uint16_t val = ADC_ReadValue(0x2);
|
||||||
LONGS_EQUAL(0, val);
|
LONGS_EQUAL(0, val);
|
||||||
|
|
@ -78,8 +69,9 @@ TEST(test_MockADC, ADC_ReadValueReturnsZeroOnEmptyBuffer)
|
||||||
TEST(test_MockADC, MockADC_PushValueDoesntOverflowArray)
|
TEST(test_MockADC, MockADC_PushValueDoesntOverflowArray)
|
||||||
{
|
{
|
||||||
MockADC_ZeroIndex();
|
MockADC_ZeroIndex();
|
||||||
for(int i = 0; i < 257; i++){
|
for (int i = 0; i < 257; i++)
|
||||||
MockADC_PushValue(512+i);
|
{
|
||||||
|
MockADC_PushValue(512 + i);
|
||||||
CHECK_TRUE(MockADC_GetIndex() <= 255);
|
CHECK_TRUE(MockADC_GetIndex() <= 255);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -87,7 +79,7 @@ TEST(test_MockADC, MockADC_PushValueDoesntOverflowArray)
|
||||||
TEST(test_MockADC, MockADC_SetupSetsGlobal)
|
TEST(test_MockADC, MockADC_SetupSetsGlobal)
|
||||||
{
|
{
|
||||||
CHECK_FALSE(MockADC_IsSetup());
|
CHECK_FALSE(MockADC_IsSetup());
|
||||||
|
|
||||||
ADC_Setup();
|
ADC_Setup();
|
||||||
|
|
||||||
CHECK_TRUE(MockADC_IsSetup());
|
CHECK_TRUE(MockADC_IsSetup());
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Author: username
|
* Author: username
|
||||||
* Date: todays_date
|
* Date: todays_date
|
||||||
* filename: test_MockRegEdit.c
|
* filename: test_MockRegEdit.c
|
||||||
* description: module_purpose
|
* description: module_purpose
|
||||||
*/
|
*/
|
||||||
|
|
@ -9,160 +9,123 @@
|
||||||
#include "CppUTestExt/MockSupport.h"
|
#include "CppUTestExt/MockSupport.h"
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#include "MockRegEdit.h"
|
#include "MockRegEdit.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_GROUP(test_MockRegEdit){
|
||||||
|
void setup(){} void teardown(){
|
||||||
|
|
||||||
TEST_GROUP(test_MockRegEdit)
|
|
||||||
{
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
void teardown()
|
|
||||||
{
|
|
||||||
mock().clear();
|
mock().clear();
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
;
|
||||||
|
|
||||||
TEST(test_MockRegEdit, RegEdit_ClearRegisterExpectedCallPasses)
|
TEST(test_MockRegEdit, RegEdit_ClearRegisterExpectedCallPasses)
|
||||||
{
|
{
|
||||||
uint8_t a;
|
uint8_t a;
|
||||||
uint8_t *b = &a;
|
uint8_t *b = &a;
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_ClearRegister")
|
mock().expectOneCall("RegEdit_ClearRegister").withPointerParameter("reg", b);
|
||||||
.withPointerParameter("reg", b);
|
|
||||||
|
|
||||||
RegEdit_ClearRegister(b);
|
RegEdit_ClearRegister(b);
|
||||||
|
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(test_MockRegEdit, RegEdit_SetRegisterExpectedCallPasses)
|
TEST(test_MockRegEdit, RegEdit_SetRegisterExpectedCallPasses)
|
||||||
{
|
{
|
||||||
|
uint8_t a;
|
||||||
uint8_t a;
|
|
||||||
uint8_t *b = &a;
|
uint8_t *b = &a;
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_SetRegister")
|
mock().expectOneCall("RegEdit_SetRegister").withPointerParameter("reg", b);
|
||||||
.withPointerParameter("reg", b);
|
|
||||||
|
|
||||||
RegEdit_SetRegister(b);
|
RegEdit_SetRegister(b);
|
||||||
|
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(test_MockRegEdit, RegEdit_SetBitExpectedCallPasses)
|
TEST(test_MockRegEdit, RegEdit_SetBitExpectedCallPasses)
|
||||||
{
|
{
|
||||||
|
uint8_t a;
|
||||||
uint8_t a;
|
|
||||||
uint8_t *b = &a;
|
uint8_t *b = &a;
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_SetBit").withPointerParameter("reg", b).withUnsignedIntParameter("bit_num", 5);
|
||||||
.withPointerParameter("reg", b)
|
|
||||||
.withUnsignedIntParameter("bit_num", 5);
|
|
||||||
|
|
||||||
RegEdit_SetBit(b, 5);
|
RegEdit_SetBit(b, 5);
|
||||||
|
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(test_MockRegEdit, RegEdit_ClearBitExpectedCallPasses)
|
TEST(test_MockRegEdit, RegEdit_ClearBitExpectedCallPasses)
|
||||||
{
|
{
|
||||||
|
uint8_t a;
|
||||||
uint8_t a;
|
|
||||||
uint8_t *b = &a;
|
uint8_t *b = &a;
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_ClearBit")
|
mock().expectOneCall("RegEdit_ClearBit").withPointerParameter("reg", b).withUnsignedIntParameter("bit_num", 5);
|
||||||
.withPointerParameter("reg", b)
|
|
||||||
.withUnsignedIntParameter("bit_num", 5);
|
|
||||||
|
|
||||||
RegEdit_ClearBit(b, 5);
|
RegEdit_ClearBit(b, 5);
|
||||||
|
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_MockRegEdit, RegEdit_IsBitSetExpectedCallPasses)
|
TEST(test_MockRegEdit, RegEdit_IsBitSetExpectedCallPasses)
|
||||||
{
|
{
|
||||||
uint8_t a = 0xFF;
|
uint8_t a = 0xFF;
|
||||||
uint8_t *b = &a;
|
uint8_t *b = &a;
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_IsBitSet")
|
mock().expectOneCall("RegEdit_IsBitSet").withPointerParameter("reg", b).withUnsignedIntParameter("bit_num", 5).andReturnValue(true);
|
||||||
.withPointerParameter("reg", b)
|
|
||||||
.withUnsignedIntParameter("bit_num", 5)
|
|
||||||
.andReturnValue(true);
|
|
||||||
|
|
||||||
CHECK_TRUE(RegEdit_IsBitSet(b, 5));
|
CHECK_TRUE(RegEdit_IsBitSet(b, 5));
|
||||||
|
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
TEST(test_MockRegEdit, RegEdit_IsBitSetExpectedCallPassesWithFalse)
|
TEST(test_MockRegEdit, RegEdit_IsBitSetExpectedCallPassesWithFalse)
|
||||||
{
|
{
|
||||||
uint8_t a = 0xFF;
|
uint8_t a = 0xFF;
|
||||||
uint8_t *b = &a;
|
uint8_t *b = &a;
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_IsBitSet")
|
mock().expectOneCall("RegEdit_IsBitSet").withPointerParameter("reg", b).withUnsignedIntParameter("bit_num", 5).andReturnValue(false);
|
||||||
.withPointerParameter("reg", b)
|
|
||||||
.withUnsignedIntParameter("bit_num", 5)
|
|
||||||
.andReturnValue(false);
|
|
||||||
|
|
||||||
CHECK_FALSE(RegEdit_IsBitSet(b, 5));
|
CHECK_FALSE(RegEdit_IsBitSet(b, 5));
|
||||||
|
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_MockRegEdit, RegEdit_OR_NumExpectedWorks)
|
TEST(test_MockRegEdit, RegEdit_OR_NumExpectedWorks)
|
||||||
{
|
{
|
||||||
uint8_t a = 0xFF;
|
uint8_t a = 0xFF;
|
||||||
uint8_t *b = &a;
|
uint8_t *b = &a;
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_OR_Num")
|
mock().expectOneCall("RegEdit_OR_Num").withPointerParameter("reg", b).withUnsignedIntParameter("num", 0x4).andReturnValue(false);
|
||||||
.withPointerParameter("reg", b)
|
|
||||||
.withUnsignedIntParameter("num", 0x4)
|
|
||||||
.andReturnValue(false);
|
|
||||||
|
|
||||||
RegEdit_OR_Num(b, 0x4);
|
RegEdit_OR_Num(b, 0x4);
|
||||||
|
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_MockRegEdit, RegEdit_SetNumPasses)
|
TEST(test_MockRegEdit, RegEdit_SetNumPasses)
|
||||||
{
|
{
|
||||||
uint32_t a = 0xFFFFFFFF;
|
uint32_t a = 0xFFFFFFFF;
|
||||||
uint32_t *b = &a;
|
uint32_t *b = &a;
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_SetNum")
|
mock().expectOneCall("RegEdit_SetNum").withPointerParameter("reg", b).withUnsignedIntParameter("num", 0x4).andReturnValue(false);
|
||||||
.withPointerParameter("reg", b)
|
|
||||||
.withUnsignedIntParameter("num", 0x4)
|
|
||||||
.andReturnValue(false);
|
|
||||||
|
|
||||||
RegEdit_SetNum(b, 0x4);
|
RegEdit_SetNum(b, 0x4);
|
||||||
|
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_MockRegEdit, RegEdit_ReadRegPasses)
|
TEST(test_MockRegEdit, RegEdit_ReadRegPasses)
|
||||||
{
|
{
|
||||||
uint8_t a = 0xFF;
|
uint8_t a = 0xFF;
|
||||||
uint8_t *b = &a;
|
uint8_t *b = &a;
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_ReadReg")
|
mock().expectOneCall("RegEdit_ReadReg").withPointerParameter("reg", b).andReturnValue(0xFF);
|
||||||
.withPointerParameter("reg", b)
|
|
||||||
.andReturnValue(0xFF);
|
|
||||||
|
|
||||||
uint8_t reg_val = RegEdit_ReadReg(b);
|
uint8_t reg_val = RegEdit_ReadReg(b);
|
||||||
LONGS_EQUAL(0xFF, reg_val);
|
LONGS_EQUAL(0xFF, reg_val);
|
||||||
|
|
||||||
mock().checkExpectations();
|
mock().checkExpectations();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,12 @@
|
||||||
#include "CppUTest/CommandLineTestRunner.h"
|
#include "CppUTest/CommandLineTestRunner.h"
|
||||||
|
|
||||||
|
// ImportTestGroups
|
||||||
//ImportTestGroups
|
|
||||||
IMPORT_TEST_GROUP(test_MockRegEdit);
|
IMPORT_TEST_GROUP(test_MockRegEdit);
|
||||||
IMPORT_TEST_GROUP(test_MockADC);
|
IMPORT_TEST_GROUP(test_MockADC);
|
||||||
|
|
||||||
//START: main
|
// START: main
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
return RUN_ALL_TESTS(argc, argv);
|
return RUN_ALL_TESTS(argc, argv);
|
||||||
}
|
}
|
||||||
//END: main
|
// END: main
|
||||||
|
|
|
||||||
|
|
@ -1,32 +1,26 @@
|
||||||
/*
|
/*
|
||||||
* Author: username
|
* Author: username
|
||||||
* Date: todays_date
|
* Date: todays_date
|
||||||
* filename: test_RegEdit.c
|
* filename: test_RegEdit.c
|
||||||
* description: module_purpose
|
* description: module_purpose
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CppUTest/CommandLineTestRunner.h"
|
#include "CppUTest/CommandLineTestRunner.h"
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#include "RegEdit.h"
|
#include "RegEdit.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_GROUP(test_RegEdit)
|
TEST_GROUP(test_RegEdit){
|
||||||
{
|
void setup(){
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
} void teardown(){
|
||||||
void teardown()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}};
|
||||||
};
|
|
||||||
|
|
||||||
TEST(test_RegEdit, FirstTest)
|
TEST(test_RegEdit, FirstTest)
|
||||||
{
|
{
|
||||||
//FAIL("Fail me!");
|
// FAIL("Fail me!");
|
||||||
CHECK(true);
|
CHECK(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,37 @@
|
||||||
/*
|
/*
|
||||||
* Author: username
|
* Author: username
|
||||||
* Date: todays_date
|
* Date: todays_date
|
||||||
* filename: test_blink.c
|
* filename: test_blink.c
|
||||||
* description: module_purpose
|
* description: module_purpose
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "CppUTest/CommandLineTestRunner.h"
|
#include "CppUTest/CommandLineTestRunner.h"
|
||||||
|
|
||||||
extern "C"
|
extern "C"
|
||||||
{
|
{
|
||||||
#include "blink.h"
|
#include "blink.h"
|
||||||
}
|
}
|
||||||
|
|
||||||
volatile uint32_t fake_bshr_reg = 0;
|
volatile uint32_t fake_bshr_reg = 0;
|
||||||
volatile uint32_t* GPIO_PORT_BSHR = &fake_bshr_reg;
|
volatile uint32_t *GPIO_PORT_BSHR = &fake_bshr_reg;
|
||||||
|
|
||||||
unsigned int called;
|
unsigned int called;
|
||||||
void fake_delay(unsigned int ms)
|
void fake_delay(unsigned int ms)
|
||||||
{
|
{
|
||||||
called += 1;
|
called += 1;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_GROUP(test_blink)
|
TEST_GROUP(test_blink){
|
||||||
{
|
void setup(){
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
fake_bshr_reg = 0;
|
fake_bshr_reg = 0;
|
||||||
called = 0;
|
called = 0;
|
||||||
}
|
}
|
||||||
void teardown()
|
void teardown()
|
||||||
{
|
{
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
;
|
||||||
|
|
||||||
|
|
||||||
TEST(test_blink, UninitializedFuncPointer)
|
TEST(test_blink, UninitializedFuncPointer)
|
||||||
{
|
{
|
||||||
|
|
@ -44,18 +41,16 @@ TEST(test_blink, UninitializedFuncPointer)
|
||||||
|
|
||||||
TEST(test_blink, BlinkChangesReg)
|
TEST(test_blink, BlinkChangesReg)
|
||||||
{
|
{
|
||||||
//Set the function pointer.
|
// Set the function pointer.
|
||||||
delay_ms = fake_delay;
|
delay_ms = fake_delay;
|
||||||
|
|
||||||
blink_led(1);
|
blink_led(1);
|
||||||
|
|
||||||
CHECK_EQUAL_TEXT(2, called, "Delay function not called expeced number of times");
|
CHECK_EQUAL_TEXT(2, called, "Delay function not called expeced number of times");
|
||||||
|
|
||||||
CHECK(fake_bshr_reg & (1<<0));
|
CHECK(fake_bshr_reg & (1 << 0));
|
||||||
CHECK(fake_bshr_reg & (1<<(0+16)));
|
CHECK(fake_bshr_reg & (1 << (0 + 16)));
|
||||||
|
|
||||||
//Unset function pointer
|
// Unset function pointer
|
||||||
delay_ms = 0;
|
delay_ms = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Author: username
|
* Author: username
|
||||||
* Date: 2024
|
* Date: 2024
|
||||||
* filename: MockADC.c
|
* filename: MockADC.c
|
||||||
* description: module_purpose
|
* description: module_purpose
|
||||||
*/
|
*/
|
||||||
|
|
@ -10,14 +10,12 @@
|
||||||
|
|
||||||
#define FAKESIZE 256
|
#define FAKESIZE 256
|
||||||
|
|
||||||
uint16_t fake_data[FAKESIZE];
|
uint16_t fake_data[FAKESIZE];
|
||||||
int fake_index = 0;
|
int fake_index = 0;
|
||||||
|
|
||||||
static bool is_setup = false;
|
static bool is_setup = false;
|
||||||
|
|
||||||
|
void ADC_SetPin(uint8_t pin_num)
|
||||||
|
|
||||||
void ADC_SetPin(uint8_t pin_num)
|
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -30,8 +28,7 @@ void ADC_Setup(void)
|
||||||
|
|
||||||
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(void)
|
void ADC_Enable(void)
|
||||||
|
|
@ -41,15 +38,15 @@ void ADC_Enable(void)
|
||||||
|
|
||||||
void ADC_Disable(void)
|
void ADC_Disable(void)
|
||||||
{
|
{
|
||||||
mock_c()->actualCall("ADC_Disable");
|
mock_c()->actualCall("ADC_Disable");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t ADC_ReadValue_Impl(uint8_t pin_num)
|
uint16_t ADC_ReadValue_Impl(uint8_t pin_num)
|
||||||
{
|
{
|
||||||
mock_c()->actualCall("ADC_ReadValue_Impl")
|
mock_c()->actualCall("ADC_ReadValue_Impl")->withUnsignedIntParameters("pin_num", pin_num);
|
||||||
->withUnsignedIntParameters("pin_num", pin_num);
|
|
||||||
|
|
||||||
if(fake_index == 0){
|
if (fake_index == 0)
|
||||||
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return fake_data[--fake_index];
|
return fake_data[--fake_index];
|
||||||
|
|
@ -57,27 +54,25 @@ uint16_t ADC_ReadValue_Impl(uint8_t pin_num)
|
||||||
|
|
||||||
uint16_t (*ADC_ReadValue)(uint8_t pin_num) = ADC_ReadValue_Impl;
|
uint16_t (*ADC_ReadValue)(uint8_t pin_num) = ADC_ReadValue_Impl;
|
||||||
|
|
||||||
|
void MockADC_PushValue(uint16_t value)
|
||||||
void MockADC_PushValue(uint16_t value){
|
{
|
||||||
if(fake_index >= FAKESIZE - 1){
|
if (fake_index >= FAKESIZE - 1)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fake_data[fake_index++] = value;
|
fake_data[fake_index++] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void MockADC_ZeroIndex(void)
|
void MockADC_ZeroIndex(void)
|
||||||
{
|
{
|
||||||
fake_index = 0;
|
fake_index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int MockADC_GetIndex(void)
|
int MockADC_GetIndex(void)
|
||||||
{
|
{
|
||||||
return fake_index;
|
return fake_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool MockADC_IsSetup(void)
|
bool MockADC_IsSetup(void)
|
||||||
{
|
{
|
||||||
return is_setup;
|
return is_setup;
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,8 @@
|
||||||
#ifndef MOCKADC_H
|
#ifndef MOCKADC_H
|
||||||
#define MOCKADC_H
|
#define MOCKADC_H
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void ADC_Setup(void);
|
void ADC_Setup(void);
|
||||||
void ADC_SetPin(uint8_t pin_num);
|
void ADC_SetPin(uint8_t pin_num);
|
||||||
|
|
@ -24,7 +23,7 @@ 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);
|
bool MockADC_IsSetup(void);
|
||||||
|
|
||||||
#endif //MOCKADC_H
|
#endif // MOCKADC_H
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Author: username
|
* Author: username
|
||||||
* Date: 2024
|
* Date: 2024
|
||||||
* filename: MockRegEdit.c
|
* filename: MockRegEdit.c
|
||||||
* description: module_purpose
|
* description: module_purpose
|
||||||
*/
|
*/
|
||||||
|
|
@ -8,78 +8,52 @@
|
||||||
#include "MockRegEdit.h"
|
#include "MockRegEdit.h"
|
||||||
#include "CppUTestExt/MockSupport_c.h"
|
#include "CppUTestExt/MockSupport_c.h"
|
||||||
|
|
||||||
|
|
||||||
void RegEdit_SetRegister(void *reg)
|
void RegEdit_SetRegister(void *reg)
|
||||||
{
|
{
|
||||||
mock_c()->actualCall("RegEdit_SetRegister")
|
mock_c()->actualCall("RegEdit_SetRegister")->withPointerParameters("reg", reg);
|
||||||
->withPointerParameters("reg", reg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegEdit_ClearRegister(void *reg)
|
void RegEdit_ClearRegister(void *reg)
|
||||||
{
|
{
|
||||||
mock_c()->actualCall("RegEdit_ClearRegister")
|
mock_c()->actualCall("RegEdit_ClearRegister")->withPointerParameters("reg", reg);
|
||||||
->withPointerParameters("reg", reg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RegEdit_SetBit(void *reg, uint8_t bit_num)
|
void RegEdit_SetBit(void *reg, uint8_t bit_num)
|
||||||
{
|
{
|
||||||
mock_c()->actualCall("RegEdit_SetBit")
|
mock_c()->actualCall("RegEdit_SetBit")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num);
|
||||||
->withPointerParameters("reg", reg)
|
|
||||||
->withUnsignedIntParameters("bit_num", bit_num);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RegEdit_ClearBit(void *reg, uint8_t bit_num)
|
void RegEdit_ClearBit(void *reg, uint8_t bit_num)
|
||||||
{
|
{
|
||||||
mock_c()->actualCall("RegEdit_ClearBit")
|
mock_c()->actualCall("RegEdit_ClearBit")->withPointerParameters("reg", reg)->withUnsignedIntParameters("bit_num", bit_num);
|
||||||
->withPointerParameters("reg", reg)
|
|
||||||
->withUnsignedIntParameters("bit_num", bit_num);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool RegEdit_IsBitSet(void *reg, uint8_t 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()->actualCall("RegEdit_IsBitSet")
|
// return mock_c()->returnBoolValueOrDefault(true);
|
||||||
->withPointerParameters("reg", reg)
|
|
||||||
->withUnsignedIntParameters("bit_num", bit_num)
|
|
||||||
->returnBoolValueOrDefault(true);
|
|
||||||
//return mock_c()->returnBoolValueOrDefault(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RegEdit_OR_Num(void *reg, uint32_t num)
|
void RegEdit_OR_Num(void *reg, uint32_t num)
|
||||||
{
|
{
|
||||||
mock_c()->actualCall("RegEdit_OR_Num")
|
mock_c()->actualCall("RegEdit_OR_Num")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
->withPointerParameters("reg", reg)
|
|
||||||
->withUnsignedIntParameters("num", num);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RegEdit_AND_Num(void *reg, uint32_t num)
|
void RegEdit_AND_Num(void *reg, uint32_t num)
|
||||||
{
|
{
|
||||||
mock_c()->actualCall("RegEdit_AND_Num")
|
mock_c()->actualCall("RegEdit_AND_Num")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
->withPointerParameters("reg", reg)
|
|
||||||
->withUnsignedIntParameters("num", num);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void RegEdit_SetNum(void *reg, uint32_t num)
|
void RegEdit_SetNum(void *reg, uint32_t num)
|
||||||
{
|
{
|
||||||
mock_c()->actualCall("RegEdit_SetNum")
|
mock_c()->actualCall("RegEdit_SetNum")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||||
->withPointerParameters("reg", reg)
|
|
||||||
->withUnsignedIntParameters("num", num);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
uint8_t RegEdit_ReadReg(void *reg)
|
uint8_t RegEdit_ReadReg(void *reg)
|
||||||
{
|
{
|
||||||
uint8_t value = *(uint8_t *)reg;
|
uint8_t value = *(uint8_t *)reg;
|
||||||
|
|
||||||
|
mock_c()->actualCall("RegEdit_ReadReg")->withPointerParameters("reg", reg)->returnUnsignedIntValueOrDefault(value);
|
||||||
|
|
||||||
mock_c()->actualCall("RegEdit_ReadReg")
|
|
||||||
->withPointerParameters("reg", reg)
|
|
||||||
->returnUnsignedIntValueOrDefault(value);
|
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,21 +10,20 @@
|
||||||
#ifndef MOCKREGEDIT_H
|
#ifndef MOCKREGEDIT_H
|
||||||
#define MOCKREGEDIT_H
|
#define MOCKREGEDIT_H
|
||||||
|
|
||||||
|
|
||||||
#include <stdint.h>
|
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void RegEdit_SetRegister(void *reg);
|
void RegEdit_SetRegister(void *reg);
|
||||||
void RegEdit_ClearRegister(void *reg);
|
void RegEdit_ClearRegister(void *reg);
|
||||||
void RegEdit_SetBit(void *reg, uint8_t bit_num);
|
void RegEdit_SetBit(void *reg, uint8_t bit_num);
|
||||||
void RegEdit_ClearBit(void *reg, uint8_t bit_num);
|
void RegEdit_ClearBit(void *reg, uint8_t bit_num);
|
||||||
bool RegEdit_IsBitSet(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_OR_Num(void *reg, uint32_t num);
|
||||||
void RegEdit_AND_Num(void *reg, uint32_t num);
|
void RegEdit_AND_Num(void *reg, uint32_t num);
|
||||||
|
|
||||||
void RegEdit_SetNum(void *reg, uint32_t num);
|
void RegEdit_SetNum(void *reg, uint32_t num);
|
||||||
|
|
||||||
uint8_t RegEdit_ReadReg(void *reg);
|
uint8_t RegEdit_ReadReg(void *reg);
|
||||||
|
|
||||||
#endif //MOCKREGEDIT_H
|
#endif // MOCKREGEDIT_H
|
||||||
|
|
|
||||||
|
|
@ -16,14 +16,16 @@ public:
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool UInt8PointerComparator::isEqual(const void* object1, const void* object2) {
|
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);
|
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;
|
return std::memcmp(ptr1, ptr2, sizeof(uint8_t)) == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleString UInt8PointerComparator::valueToString(const void* object) {
|
SimpleString UInt8PointerComparator::valueToString(const void *object)
|
||||||
const uint8_t* ptr = reinterpret_cast<const uint8_t*>(object);
|
{
|
||||||
|
const uint8_t *ptr = reinterpret_cast<const uint8_t *>(object);
|
||||||
return StringFromFormat("0x%02x", *ptr);
|
return StringFromFormat("0x%02x", *ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,12 +42,14 @@ SimpleString UInt8PointerComparator::valueToString(const void* object) const {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bool UInt8Comparator::isEqual(const void* object1, const void* object2) {
|
bool UInt8Comparator::isEqual(const void *object1, const void *object2)
|
||||||
return (uint8_t*)object1 == (uint8_t *)object2;
|
{
|
||||||
|
return (uint8_t *)object1 == (uint8_t *)object2;
|
||||||
}
|
}
|
||||||
|
|
||||||
SimpleString UInt8Comparator::valueToString(const void* object) {
|
SimpleString UInt8Comparator::valueToString(const void *object)
|
||||||
//uint8_t value = reinterpret_cast<uint8_t>(object);
|
{
|
||||||
const uint8_t *ptr = reinterpret_cast<const uint8_t*>(object);
|
// uint8_t value = reinterpret_cast<uint8_t>(object);
|
||||||
|
const uint8_t *ptr = reinterpret_cast<const uint8_t *>(object);
|
||||||
return StringFromFormat("0x%02x", *ptr);
|
return StringFromFormat("0x%02x", *ptr);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
/*
|
/*
|
||||||
* Author: Jake G
|
* Author: Jake G
|
||||||
* Date: 2024-09-02
|
* Date: 2024-09-02
|
||||||
* filename: TimerMock.c
|
* filename: TimerMock.c
|
||||||
* description: mocks timers
|
* description: mocks timers
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "TimerMock.h"
|
#include "TimerMock.h"
|
||||||
#include <stdbool.h>
|
|
||||||
#include "CppUTestExt/MockSupport_c.h"
|
#include "CppUTestExt/MockSupport_c.h"
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
static bool timer_started = false;
|
static bool timer_started = false;
|
||||||
|
|
||||||
void Timer_Start(void)
|
void Timer_Start(void)
|
||||||
{
|
{
|
||||||
mock_c()->actualCall("Timer_Start");
|
mock_c()->actualCall("Timer_Start");
|
||||||
timer_started = true;
|
timer_started = true;
|
||||||
|
|
@ -26,6 +26,5 @@ void Timer_Stop(void)
|
||||||
uint16_t Timer_GetOverflowCount(void)
|
uint16_t Timer_GetOverflowCount(void)
|
||||||
{
|
{
|
||||||
uint16_t time = 0xAAAA;
|
uint16_t time = 0xAAAA;
|
||||||
return mock_c()->actualCall("Timer_GetOverflowCount")
|
return mock_c()->actualCall("Timer_GetOverflowCount")->returnUnsignedIntValueOrDefault(time);
|
||||||
->returnUnsignedIntValueOrDefault(time);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,25 @@
|
||||||
/**
|
/**
|
||||||
* @brief A Mock of the timer module.
|
* @brief A Mock of the timer module.
|
||||||
* @details This file is only used for testing.
|
* @details This file is only used for testing.
|
||||||
* @author Jake G
|
* @author Jake G
|
||||||
* @date 2024-09-02
|
* @date 2024-09-02
|
||||||
* @copyright None
|
* @copyright None
|
||||||
* @file TimerMock.h
|
* @file TimerMock.h
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef TIMER_MOCK_H
|
#ifndef TIMER_MOCK_H
|
||||||
#define TIMER_MOCK_H
|
#define TIMER_MOCK_H
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A function
|
* A function
|
||||||
* @param a The first argument
|
* @param a The first argument
|
||||||
*/
|
*/
|
||||||
void Timer_Start(void);
|
void Timer_Start(void);
|
||||||
|
|
||||||
void Timer_Stop(void);
|
void Timer_Stop(void);
|
||||||
|
|
||||||
uint16_t Timer_GetOverflowCount(void);
|
uint16_t Timer_GetOverflowCount(void);
|
||||||
|
|
||||||
|
#endif // TIMER_MOCK_H
|
||||||
#endif //TIMER_MOCK_H
|
|
||||||
|
|
|
||||||
|
|
@ -1,24 +1,18 @@
|
||||||
#include "CppUTest/TestHarness.h"
|
#include "CppUTest/TestHarness.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
extern C
|
extern C
|
||||||
{
|
{
|
||||||
#include "simple.h"
|
#include "simple.h"
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
TEST_GROUP(simple_test){
|
||||||
|
void setup(){
|
||||||
|
|
||||||
TEST_GROUP(simple_test)
|
} void teardown(){
|
||||||
{
|
|
||||||
void setup()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
}};
|
||||||
void teardown()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
TEST(simple_test, passing_test)
|
TEST(simple_test, passing_test)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue