Low/tests/MockADC/test_MockADC.cpp

95 lines
1.6 KiB
C++
Raw Normal View History

2024-07-27 18:50:15 +00:00
/*
* 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")
2024-07-29 00:31:27 +00:00
.withUnsignedIntParameter("pin_num", 7);
2024-07-27 18:50:15 +00:00
2024-07-29 00:31:27 +00:00
ADC_Init(7);
2024-07-27 18:50:15 +00:00
}
TEST(test_MockADC, ADC_EnableExpects)
{
2024-07-29 00:31:27 +00:00
mock().expectOneCall("ADC_Enable");
2024-07-27 18:50:15 +00:00
2024-07-29 00:31:27 +00:00
ADC_Enable();
2024-07-27 18:50:15 +00:00
}
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);
}
}
2024-07-29 00:31:27 +00:00
TEST(test_MockADC, MockADC_SetupSetsGlobal)
{
CHECK_FALSE(MockADC_IsSetup());
ADC_Setup();
CHECK_TRUE(MockADC_IsSetup());
}