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"
|
||||
{
|
||||
#include "ch32v003hw.h"
|
||||
#include "ADC.h"
|
||||
#include "ch32v003hw.h"
|
||||
}
|
||||
|
||||
TEST_GROUP(test_ADC)
|
||||
{
|
||||
void setup()
|
||||
{
|
||||
TEST_GROUP(test_ADC){
|
||||
void setup(){
|
||||
|
||||
}
|
||||
void teardown()
|
||||
{
|
||||
} void teardown(){
|
||||
mock().checkExpectations();
|
||||
mock().clear();
|
||||
}
|
||||
};
|
||||
mock().clear();
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TEST(test_ADC, FirstTest)
|
||||
{
|
||||
|
|
@ -36,38 +33,32 @@ TEST(test_ADC, FirstTest)
|
|||
TEST(test_ADC, ADC_PowerOnTest)
|
||||
{
|
||||
// The ADCON bit should be high in the ADC_CTRL2 register.
|
||||
mock().expectOneCall("RegEdit_SetBit")
|
||||
.withPointerParameter("reg", (void *) &ADC1->CTLR2)
|
||||
.withUnsignedIntParameter("bit_num", ADC_ADON);
|
||||
mock().expectOneCall("RegEdit_SetBit").withPointerParameter("reg", (void *)&ADC1->CTLR2).withUnsignedIntParameter("bit_num", ADC_ADON);
|
||||
|
||||
ADC_PowerOn();
|
||||
}
|
||||
|
||||
TEST(test_ADC, ADC_SetupSetsRegisters)
|
||||
{
|
||||
// R32_GPIOD_CFGLR --> 0x40011400
|
||||
// DESC: PD port configuration register low
|
||||
// RESET VALUE--> 0x44444444
|
||||
|
||||
//R32_GPIOD_CFGLR --> 0x40011400
|
||||
//DESC: PD port configuration register low
|
||||
//RESET VALUE--> 0x44444444
|
||||
// R32_GPIOD_INDR --> 0x40011408
|
||||
// DESC: PD port input data register
|
||||
|
||||
//R32_GPIOD_INDR --> 0x40011408
|
||||
//DESC: PD port input data register
|
||||
// R32_GPIOD_BSHR --> 0x40011410
|
||||
// DESC: PD port set/reset register
|
||||
|
||||
//R32_GPIOD_BSHR --> 0x40011410
|
||||
//DESC: PD port set/reset register
|
||||
// R32_GPIOD_BCR --> 0x40011414
|
||||
// DESC: PD port reset register
|
||||
|
||||
//R32_GPIOD_BCR --> 0x40011414
|
||||
//DESC: PD port reset register
|
||||
|
||||
//R32_GPIOD_LCKR --> 0x40011418
|
||||
//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.
|
||||
// R32_GPIOD_LCKR --> 0x40011418
|
||||
// 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
|
||||
|
|
@ -153,7 +144,7 @@ TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters)
|
|||
|
||||
TEST(test_ADC, ADC_InitDoesNothingOnHighPinNumbers)
|
||||
{
|
||||
//mock().expectNoCall("RegEdit_SetBit");
|
||||
// mock().expectNoCall("RegEdit_SetBit");
|
||||
ADC_Init(8);
|
||||
}
|
||||
|
||||
|
|
@ -166,7 +157,6 @@ TEST(test_ADC, ADC_EnablePasses)
|
|||
|
||||
*/
|
||||
ADC_Enable();
|
||||
|
||||
}
|
||||
|
||||
TEST(test_ADC, ADC_DisablePasses)
|
||||
|
|
@ -195,30 +185,26 @@ TEST(test_ADC, ADC_SetPinSetsRightRegisters)
|
|||
ADC_SetPin(4);
|
||||
}
|
||||
|
||||
|
||||
TEST(test_ADC, ADC_SetPinFailsOnInvalidPin)
|
||||
{
|
||||
ADC_SetPin(8);
|
||||
}
|
||||
|
||||
|
||||
static uint16_t ADC_ReadValueFake(uint8_t pin_num)
|
||||
{
|
||||
return 512;
|
||||
}
|
||||
|
||||
TEST_GROUP(test_ADCRead)
|
||||
{
|
||||
void setup()
|
||||
{
|
||||
TEST_GROUP(test_ADCRead){
|
||||
void setup(){
|
||||
UT_PTR_SET(ADC_ReadValue, ADC_ReadValueFake);
|
||||
}
|
||||
}
|
||||
|
||||
void teardown()
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
void teardown()
|
||||
{
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TEST(test_ADCRead, FunctionPointerSwapWorks)
|
||||
{
|
||||
|
|
@ -226,4 +212,3 @@ TEST(test_ADCRead, FunctionPointerSwapWorks)
|
|||
|
||||
LONGS_EQUAL(512, value);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,14 @@
|
|||
#include "CppUTest/CommandLineTestRunner.h"
|
||||
|
||||
|
||||
//ImportTestGroups
|
||||
// ImportTestGroups
|
||||
IMPORT_TEST_GROUP(simple_test);
|
||||
IMPORT_TEST_GROUP(test_ADC);
|
||||
IMPORT_TEST_GROUP(test_RegEdit);
|
||||
IMPORT_TEST_GROUP(test_blink);
|
||||
|
||||
//START: main
|
||||
int main(int argc, char** argv)
|
||||
// START: main
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return RUN_ALL_TESTS(argc, argv);
|
||||
}
|
||||
//END: main
|
||||
// END: main
|
||||
|
|
|
|||
|
|
@ -14,23 +14,19 @@ extern "C"
|
|||
#include "MockADC.h"
|
||||
}
|
||||
|
||||
TEST_GROUP(test_MockADC)
|
||||
{
|
||||
void setup()
|
||||
{
|
||||
TEST_GROUP(test_MockADC){
|
||||
void setup(){
|
||||
|
||||
}
|
||||
void teardown()
|
||||
{
|
||||
} void teardown(){
|
||||
mock().checkExpectations();
|
||||
mock().clear();
|
||||
}
|
||||
};
|
||||
mock().clear();
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TEST(test_MockADC, ADC_InitExpects)
|
||||
{
|
||||
mock().expectOneCall("ADC_Init")
|
||||
.withUnsignedIntParameter("pin_num", 7);
|
||||
mock().expectOneCall("ADC_Init").withUnsignedIntParameter("pin_num", 7);
|
||||
|
||||
ADC_Init(7);
|
||||
}
|
||||
|
|
@ -42,7 +38,6 @@ TEST(test_MockADC, ADC_EnableExpects)
|
|||
ADC_Enable();
|
||||
}
|
||||
|
||||
|
||||
TEST(test_MockADC, ADC_DisableExpect)
|
||||
{
|
||||
mock().expectOneCall("ADC_Disable");
|
||||
|
|
@ -55,21 +50,17 @@ TEST(test_MockADC, ADC_ReadValue)
|
|||
MockADC_ZeroIndex();
|
||||
MockADC_PushValue(512);
|
||||
|
||||
mock().expectOneCall("ADC_ReadValue_Impl")
|
||||
.withUnsignedIntParameter("pin_num", 0x2);
|
||||
mock().expectOneCall("ADC_ReadValue_Impl").withUnsignedIntParameter("pin_num", 0x2);
|
||||
|
||||
uint16_t val = ADC_ReadValue(0x2);
|
||||
LONGS_EQUAL(512, val);
|
||||
|
||||
}
|
||||
|
||||
TEST(test_MockADC, ADC_ReadValueReturnsZeroOnEmptyBuffer)
|
||||
{
|
||||
MockADC_ZeroIndex();
|
||||
|
||||
mock().expectOneCall("ADC_ReadValue_Impl")
|
||||
.withUnsignedIntParameter("pin_num", 0x2)
|
||||
.andReturnValue(0x0000);
|
||||
mock().expectOneCall("ADC_ReadValue_Impl").withUnsignedIntParameter("pin_num", 0x2).andReturnValue(0x0000);
|
||||
|
||||
uint16_t val = ADC_ReadValue(0x2);
|
||||
LONGS_EQUAL(0, val);
|
||||
|
|
@ -78,8 +69,9 @@ TEST(test_MockADC, ADC_ReadValueReturnsZeroOnEmptyBuffer)
|
|||
TEST(test_MockADC, MockADC_PushValueDoesntOverflowArray)
|
||||
{
|
||||
MockADC_ZeroIndex();
|
||||
for(int i = 0; i < 257; i++){
|
||||
MockADC_PushValue(512+i);
|
||||
for (int i = 0; i < 257; i++)
|
||||
{
|
||||
MockADC_PushValue(512 + i);
|
||||
CHECK_TRUE(MockADC_GetIndex() <= 255);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,75 +14,55 @@ extern "C"
|
|||
#include "MockRegEdit.h"
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TEST_GROUP(test_MockRegEdit)
|
||||
{
|
||||
void setup()
|
||||
{
|
||||
}
|
||||
void teardown()
|
||||
{
|
||||
TEST_GROUP(test_MockRegEdit){
|
||||
void setup(){} void teardown(){
|
||||
mock().clear();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TEST(test_MockRegEdit, RegEdit_ClearRegisterExpectedCallPasses)
|
||||
{
|
||||
uint8_t a;
|
||||
uint8_t *b = &a;
|
||||
|
||||
mock().expectOneCall("RegEdit_ClearRegister")
|
||||
.withPointerParameter("reg", b);
|
||||
mock().expectOneCall("RegEdit_ClearRegister").withPointerParameter("reg", b);
|
||||
|
||||
RegEdit_ClearRegister(b);
|
||||
|
||||
mock().checkExpectations();
|
||||
}
|
||||
|
||||
|
||||
TEST(test_MockRegEdit, RegEdit_SetRegisterExpectedCallPasses)
|
||||
{
|
||||
|
||||
uint8_t a;
|
||||
uint8_t *b = &a;
|
||||
|
||||
mock().expectOneCall("RegEdit_SetRegister")
|
||||
.withPointerParameter("reg", b);
|
||||
mock().expectOneCall("RegEdit_SetRegister").withPointerParameter("reg", b);
|
||||
|
||||
RegEdit_SetRegister(b);
|
||||
|
||||
mock().checkExpectations();
|
||||
}
|
||||
|
||||
|
||||
TEST(test_MockRegEdit, RegEdit_SetBitExpectedCallPasses)
|
||||
{
|
||||
|
||||
uint8_t a;
|
||||
uint8_t *b = &a;
|
||||
|
||||
mock().expectOneCall("RegEdit_SetBit")
|
||||
.withPointerParameter("reg", b)
|
||||
.withUnsignedIntParameter("bit_num", 5);
|
||||
mock().expectOneCall("RegEdit_SetBit").withPointerParameter("reg", b).withUnsignedIntParameter("bit_num", 5);
|
||||
|
||||
RegEdit_SetBit(b, 5);
|
||||
|
||||
mock().checkExpectations();
|
||||
}
|
||||
|
||||
|
||||
TEST(test_MockRegEdit, RegEdit_ClearBitExpectedCallPasses)
|
||||
{
|
||||
|
||||
uint8_t a;
|
||||
uint8_t *b = &a;
|
||||
|
||||
mock().expectOneCall("RegEdit_ClearBit")
|
||||
.withPointerParameter("reg", b)
|
||||
.withUnsignedIntParameter("bit_num", 5);
|
||||
mock().expectOneCall("RegEdit_ClearBit").withPointerParameter("reg", b).withUnsignedIntParameter("bit_num", 5);
|
||||
|
||||
RegEdit_ClearBit(b, 5);
|
||||
|
||||
|
|
@ -94,26 +74,19 @@ TEST(test_MockRegEdit, RegEdit_IsBitSetExpectedCallPasses)
|
|||
uint8_t a = 0xFF;
|
||||
uint8_t *b = &a;
|
||||
|
||||
mock().expectOneCall("RegEdit_IsBitSet")
|
||||
.withPointerParameter("reg", b)
|
||||
.withUnsignedIntParameter("bit_num", 5)
|
||||
.andReturnValue(true);
|
||||
mock().expectOneCall("RegEdit_IsBitSet").withPointerParameter("reg", b).withUnsignedIntParameter("bit_num", 5).andReturnValue(true);
|
||||
|
||||
CHECK_TRUE(RegEdit_IsBitSet(b, 5));
|
||||
|
||||
mock().checkExpectations();
|
||||
}
|
||||
|
||||
|
||||
TEST(test_MockRegEdit, RegEdit_IsBitSetExpectedCallPassesWithFalse)
|
||||
{
|
||||
uint8_t a = 0xFF;
|
||||
uint8_t *b = &a;
|
||||
|
||||
mock().expectOneCall("RegEdit_IsBitSet")
|
||||
.withPointerParameter("reg", b)
|
||||
.withUnsignedIntParameter("bit_num", 5)
|
||||
.andReturnValue(false);
|
||||
mock().expectOneCall("RegEdit_IsBitSet").withPointerParameter("reg", b).withUnsignedIntParameter("bit_num", 5).andReturnValue(false);
|
||||
|
||||
CHECK_FALSE(RegEdit_IsBitSet(b, 5));
|
||||
|
||||
|
|
@ -125,16 +98,11 @@ TEST(test_MockRegEdit, RegEdit_OR_NumExpectedWorks)
|
|||
uint8_t a = 0xFF;
|
||||
uint8_t *b = &a;
|
||||
|
||||
mock().expectOneCall("RegEdit_OR_Num")
|
||||
.withPointerParameter("reg", b)
|
||||
.withUnsignedIntParameter("num", 0x4)
|
||||
.andReturnValue(false);
|
||||
mock().expectOneCall("RegEdit_OR_Num").withPointerParameter("reg", b).withUnsignedIntParameter("num", 0x4).andReturnValue(false);
|
||||
|
||||
RegEdit_OR_Num(b, 0x4);
|
||||
|
||||
mock().checkExpectations();
|
||||
|
||||
|
||||
}
|
||||
|
||||
TEST(test_MockRegEdit, RegEdit_SetNumPasses)
|
||||
|
|
@ -142,10 +110,7 @@ TEST(test_MockRegEdit, RegEdit_SetNumPasses)
|
|||
uint32_t a = 0xFFFFFFFF;
|
||||
uint32_t *b = &a;
|
||||
|
||||
mock().expectOneCall("RegEdit_SetNum")
|
||||
.withPointerParameter("reg", b)
|
||||
.withUnsignedIntParameter("num", 0x4)
|
||||
.andReturnValue(false);
|
||||
mock().expectOneCall("RegEdit_SetNum").withPointerParameter("reg", b).withUnsignedIntParameter("num", 0x4).andReturnValue(false);
|
||||
|
||||
RegEdit_SetNum(b, 0x4);
|
||||
|
||||
|
|
@ -157,9 +122,7 @@ TEST(test_MockRegEdit, RegEdit_ReadRegPasses)
|
|||
uint8_t a = 0xFF;
|
||||
uint8_t *b = &a;
|
||||
|
||||
mock().expectOneCall("RegEdit_ReadReg")
|
||||
.withPointerParameter("reg", b)
|
||||
.andReturnValue(0xFF);
|
||||
mock().expectOneCall("RegEdit_ReadReg").withPointerParameter("reg", b).andReturnValue(0xFF);
|
||||
|
||||
uint8_t reg_val = RegEdit_ReadReg(b);
|
||||
LONGS_EQUAL(0xFF, reg_val);
|
||||
|
|
|
|||
|
|
@ -1,13 +1,12 @@
|
|||
#include "CppUTest/CommandLineTestRunner.h"
|
||||
|
||||
|
||||
//ImportTestGroups
|
||||
// ImportTestGroups
|
||||
IMPORT_TEST_GROUP(test_MockRegEdit);
|
||||
IMPORT_TEST_GROUP(test_MockADC);
|
||||
|
||||
//START: main
|
||||
int main(int argc, char** argv)
|
||||
// START: main
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
return RUN_ALL_TESTS(argc, argv);
|
||||
}
|
||||
//END: main
|
||||
// END: main
|
||||
|
|
|
|||
|
|
@ -12,21 +12,15 @@ extern "C"
|
|||
#include "RegEdit.h"
|
||||
}
|
||||
|
||||
TEST_GROUP(test_RegEdit)
|
||||
{
|
||||
void setup()
|
||||
{
|
||||
TEST_GROUP(test_RegEdit){
|
||||
void setup(){
|
||||
|
||||
}
|
||||
void teardown()
|
||||
{
|
||||
} void teardown(){
|
||||
|
||||
}
|
||||
};
|
||||
}};
|
||||
|
||||
TEST(test_RegEdit, FirstTest)
|
||||
{
|
||||
//FAIL("Fail me!");
|
||||
// FAIL("Fail me!");
|
||||
CHECK(true);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ extern "C"
|
|||
}
|
||||
|
||||
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;
|
||||
void fake_delay(unsigned int ms)
|
||||
|
|
@ -22,19 +22,16 @@ void fake_delay(unsigned int ms)
|
|||
return;
|
||||
}
|
||||
|
||||
TEST_GROUP(test_blink)
|
||||
{
|
||||
void setup()
|
||||
{
|
||||
TEST_GROUP(test_blink){
|
||||
void setup(){
|
||||
fake_bshr_reg = 0;
|
||||
called = 0;
|
||||
}
|
||||
void teardown()
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
called = 0;
|
||||
}
|
||||
void teardown()
|
||||
{
|
||||
}
|
||||
}
|
||||
;
|
||||
|
||||
TEST(test_blink, UninitializedFuncPointer)
|
||||
{
|
||||
|
|
@ -44,18 +41,16 @@ TEST(test_blink, UninitializedFuncPointer)
|
|||
|
||||
TEST(test_blink, BlinkChangesReg)
|
||||
{
|
||||
//Set the function pointer.
|
||||
// Set the function pointer.
|
||||
delay_ms = fake_delay;
|
||||
|
||||
blink_led(1);
|
||||
|
||||
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+16)));
|
||||
CHECK(fake_bshr_reg & (1 << 0));
|
||||
CHECK(fake_bshr_reg & (1 << (0 + 16)));
|
||||
|
||||
//Unset function pointer
|
||||
// Unset function pointer
|
||||
delay_ms = 0;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -15,8 +15,6 @@ int fake_index = 0;
|
|||
|
||||
static bool is_setup = false;
|
||||
|
||||
|
||||
|
||||
void ADC_SetPin(uint8_t pin_num)
|
||||
{
|
||||
return;
|
||||
|
|
@ -30,8 +28,7 @@ void ADC_Setup(void)
|
|||
|
||||
void ADC_Init(uint8_t pin_num)
|
||||
{
|
||||
mock_c()->actualCall("ADC_Init")
|
||||
->withUnsignedIntParameters("pin_num", pin_num);
|
||||
mock_c()->actualCall("ADC_Init")->withUnsignedIntParameters("pin_num", pin_num);
|
||||
}
|
||||
|
||||
void ADC_Enable(void)
|
||||
|
|
@ -46,10 +43,10 @@ void ADC_Disable(void)
|
|||
|
||||
uint16_t ADC_ReadValue_Impl(uint8_t pin_num)
|
||||
{
|
||||
mock_c()->actualCall("ADC_ReadValue_Impl")
|
||||
->withUnsignedIntParameters("pin_num", pin_num);
|
||||
mock_c()->actualCall("ADC_ReadValue_Impl")->withUnsignedIntParameters("pin_num", pin_num);
|
||||
|
||||
if(fake_index == 0){
|
||||
if (fake_index == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
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;
|
||||
|
||||
|
||||
void MockADC_PushValue(uint16_t value){
|
||||
if(fake_index >= FAKESIZE - 1){
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -10,9 +10,8 @@
|
|||
#ifndef MOCKADC_H
|
||||
#define MOCKADC_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
void ADC_Setup(void);
|
||||
void ADC_SetPin(uint8_t pin_num);
|
||||
|
|
@ -27,4 +26,4 @@ void MockADC_ZeroIndex(void);
|
|||
int MockADC_GetIndex(void);
|
||||
bool MockADC_IsSetup(void);
|
||||
|
||||
#endif //MOCKADC_H
|
||||
#endif // MOCKADC_H
|
||||
|
|
|
|||
|
|
@ -8,78 +8,52 @@
|
|||
#include "MockRegEdit.h"
|
||||
#include "CppUTestExt/MockSupport_c.h"
|
||||
|
||||
|
||||
void RegEdit_SetRegister(void *reg)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_SetRegister")
|
||||
->withPointerParameters("reg", reg);
|
||||
mock_c()->actualCall("RegEdit_SetRegister")->withPointerParameters("reg", reg);
|
||||
}
|
||||
|
||||
void RegEdit_ClearRegister(void *reg)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_ClearRegister")
|
||||
->withPointerParameters("reg", 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);
|
||||
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);
|
||||
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);
|
||||
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, uint32_t num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_OR_Num")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("num", num);
|
||||
mock_c()->actualCall("RegEdit_OR_Num")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||
}
|
||||
|
||||
|
||||
void RegEdit_AND_Num(void *reg, uint32_t num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_AND_Num")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("num", num);
|
||||
mock_c()->actualCall("RegEdit_AND_Num")->withPointerParameters("reg", reg)->withUnsignedIntParameters("num", num);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void RegEdit_SetNum(void *reg, uint32_t num)
|
||||
{
|
||||
mock_c()->actualCall("RegEdit_SetNum")
|
||||
->withPointerParameters("reg", reg)
|
||||
->withUnsignedIntParameters("num", 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);
|
||||
mock_c()->actualCall("RegEdit_ReadReg")->withPointerParameters("reg", reg)->returnUnsignedIntValueOrDefault(value);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,9 +10,8 @@
|
|||
#ifndef MOCKREGEDIT_H
|
||||
#define MOCKREGEDIT_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
void RegEdit_SetRegister(void *reg);
|
||||
void RegEdit_ClearRegister(void *reg);
|
||||
|
|
@ -27,4 +26,4 @@ void RegEdit_SetNum(void *reg, uint32_t num);
|
|||
|
||||
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) {
|
||||
const uint8_t* ptr1 = reinterpret_cast<const uint8_t*>(object1);
|
||||
const uint8_t* ptr2 = reinterpret_cast<const uint8_t*>(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);
|
||||
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);
|
||||
SimpleString UInt8PointerComparator::valueToString(const void *object)
|
||||
{
|
||||
const uint8_t *ptr = reinterpret_cast<const uint8_t *>(object);
|
||||
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) {
|
||||
return (uint8_t*)object1 == (uint8_t *)object2;
|
||||
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);
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
*/
|
||||
|
||||
#include "TimerMock.h"
|
||||
#include <stdbool.h>
|
||||
#include "CppUTestExt/MockSupport_c.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
static bool timer_started = false;
|
||||
|
||||
|
|
@ -26,6 +26,5 @@ void Timer_Stop(void)
|
|||
uint16_t Timer_GetOverflowCount(void)
|
||||
{
|
||||
uint16_t time = 0xAAAA;
|
||||
return mock_c()->actualCall("Timer_GetOverflowCount")
|
||||
->returnUnsignedIntValueOrDefault(time);
|
||||
return mock_c()->actualCall("Timer_GetOverflowCount")->returnUnsignedIntValueOrDefault(time);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,5 +22,4 @@ void Timer_Stop(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 setup()
|
||||
{
|
||||
} void teardown(){
|
||||
|
||||
}
|
||||
void teardown()
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
}};
|
||||
|
||||
TEST(simple_test, passing_test)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue