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
|
|
@ -11,22 +11,19 @@
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
@ -36,16 +33,13 @@ TEST(test_ADC, FirstTest)
|
||||||
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
|
||||||
|
|
@ -64,11 +58,8 @@ TEST(test_ADC, ADC_SetupSetsRegisters)
|
||||||
|
|
||||||
// Setup the ADC clock and divider. The internal HSI-XC is 24MHz.
|
// Setup the ADC clock and divider. The internal HSI-XC is 24MHz.
|
||||||
|
|
||||||
|
|
||||||
// Setup PORTD pin(s) as analog input.
|
// Setup PORTD pin(s) as analog input.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
//Clears control register A for ADC0
|
//Clears control register A for ADC0
|
||||||
mock().expectOneCall("RegEdit_SetNum")
|
mock().expectOneCall("RegEdit_SetNum")
|
||||||
|
|
@ -166,7 +157,6 @@ TEST(test_ADC, ADC_EnablePasses)
|
||||||
|
|
||||||
*/
|
*/
|
||||||
ADC_Enable();
|
ADC_Enable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_ADC, ADC_DisablePasses)
|
TEST(test_ADC, ADC_DisablePasses)
|
||||||
|
|
@ -195,30 +185,26 @@ TEST(test_ADC, ADC_SetPinSetsRightRegisters)
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
@ -226,4 +212,3 @@ TEST(test_ADCRead, FunctionPointerSwapWorks)
|
||||||
|
|
||||||
LONGS_EQUAL(512, value);
|
LONGS_EQUAL(512, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#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);
|
||||||
|
|
|
||||||
|
|
@ -14,23 +14,19 @@ 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");
|
||||||
|
|
@ -55,21 +50,17 @@ 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,7 +69,8 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,75 +14,55 @@ 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);
|
||||||
|
|
||||||
|
|
@ -94,26 +74,19 @@ 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));
|
||||||
|
|
||||||
|
|
@ -125,16 +98,11 @@ 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)
|
||||||
|
|
@ -142,10 +110,7 @@ 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);
|
||||||
|
|
||||||
|
|
@ -157,9 +122,7 @@ 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);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
#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);
|
||||||
|
|
|
||||||
|
|
@ -12,21 +12,15 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -22,19 +22,16 @@ void fake_delay(unsigned int ms)
|
||||||
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)
|
||||||
{
|
{
|
||||||
|
|
@ -57,5 +54,3 @@ TEST(test_blink, BlinkChangesReg)
|
||||||
// Unset function pointer
|
// Unset function pointer
|
||||||
delay_ms = 0;
|
delay_ms = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,6 @@ 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)
|
||||||
|
|
@ -46,10 +43,10 @@ void ADC_Disable(void)
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
||||||
|
|
@ -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")
|
|
||||||
->withPointerParameters("reg", reg)
|
|
||||||
->withUnsignedIntParameters("bit_num", bit_num)
|
|
||||||
->returnBoolValueOrDefault(true);
|
|
||||||
// return mock_c()->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")
|
mock_c()->actualCall("RegEdit_ReadReg")->withPointerParameters("reg", reg)->returnUnsignedIntValueOrDefault(value);
|
||||||
->withPointerParameters("reg", reg)
|
|
||||||
->returnUnsignedIntValueOrDefault(value);
|
|
||||||
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,9 +10,8 @@
|
||||||
#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);
|
||||||
|
|
|
||||||
|
|
@ -16,13 +16,15 @@ 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 *ptr1 = reinterpret_cast<const uint8_t *>(object1);
|
||||||
const uint8_t *ptr2 = reinterpret_cast<const uint8_t *>(object2);
|
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,11 +42,13 @@ 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);
|
// uint8_t value = reinterpret_cast<uint8_t>(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);
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#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;
|
||||||
|
|
||||||
|
|
@ -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);
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,5 +22,4 @@ void Timer_Stop(void);
|
||||||
|
|
||||||
uint16_t Timer_GetOverflowCount(void);
|
uint16_t Timer_GetOverflowCount(void);
|
||||||
|
|
||||||
|
|
||||||
#endif // TIMER_MOCK_H
|
#endif // TIMER_MOCK_H
|
||||||
|
|
|
||||||
|
|
@ -7,18 +7,12 @@ extern C
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
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