87 lines
1.5 KiB
C++
87 lines
1.5 KiB
C++
|
/*
|
||
|
* Author: Jake G
|
||
|
* Date: 2024
|
||
|
* filename: test_MockADC.c
|
||
|
* description:
|
||
|
*/
|
||
|
|
||
|
#include "CppUTest/CommandLineTestRunner.h"
|
||
|
#include "CppUTestExt/MockSupport.h"
|
||
|
#include <cstdint>
|
||
|
|
||
|
extern "C"
|
||
|
{
|
||
|
#include "MockADC.h"
|
||
|
}
|
||
|
|
||
|
TEST_GROUP(test_MockADC)
|
||
|
{
|
||
|
void setup()
|
||
|
{
|
||
|
|
||
|
}
|
||
|
void teardown()
|
||
|
{
|
||
|
mock().checkExpectations();
|
||
|
mock().clear();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
TEST(test_MockADC, ADC_InitExpects)
|
||
|
{
|
||
|
mock().expectOneCall("ADC_Init")
|
||
|
.withUnsignedIntParameter("pin_num", 0x2);
|
||
|
|
||
|
ADC_Init(0x2);
|
||
|
}
|
||
|
|
||
|
TEST(test_MockADC, ADC_EnableExpects)
|
||
|
{
|
||
|
mock().expectOneCall("ADC_Enable")
|
||
|
.withUnsignedIntParameter("pin_num", 0x2);
|
||
|
|
||
|
ADC_Enable(0x2);
|
||
|
}
|
||
|
|
||
|
|
||
|
TEST(test_MockADC, ADC_DisableExpect)
|
||
|
{
|
||
|
mock().expectOneCall("ADC_Disable");
|
||
|
|
||
|
ADC_Disable();
|
||
|
}
|
||
|
|
||
|
TEST(test_MockADC, ADC_ReadValue)
|
||
|
{
|
||
|
MockADC_ZeroIndex();
|
||
|
MockADC_PushValue(512);
|
||
|
|
||
|
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);
|
||
|
|
||
|
uint16_t val = ADC_ReadValue(0x2);
|
||
|
LONGS_EQUAL(0, val);
|
||
|
}
|
||
|
|
||
|
TEST(test_MockADC, MockADC_PushValueDoesntOverflowArray)
|
||
|
{
|
||
|
MockADC_ZeroIndex();
|
||
|
for(int i = 0; i < 257; i++){
|
||
|
MockADC_PushValue(512+i);
|
||
|
CHECK_TRUE(MockADC_GetIndex() <= 255);
|
||
|
}
|
||
|
}
|