Added detailed tests for the behavior of the porta load handler function.

This commit is contained in:
jakeg00dwin 2024-09-23 12:43:24 -07:00
parent 28ac695a26
commit b39e1f3de8
1 changed files with 82 additions and 16 deletions

View File

@ -23,9 +23,12 @@ extern "C"
TEST_GROUP(test_load) TEST_GROUP(test_load)
{ {
uint8_t adc_pin;
uint8_t load_pin;
void setup() void setup()
{ {
adc_pin = 4;
load_pin = 7;
} }
void teardown() void teardown()
{ {
@ -39,36 +42,99 @@ TEST(test_load, LoadPass)
CHECK_TRUE(true); CHECK_TRUE(true);
} }
TEST(test_load, PortAHandlerSuccess) void setup_adc_expectations(uint8_t adc_pin)
{ {
mock().expectOneCall("ADC_Init") mock().expectOneCall("ADC_Init")
.withUnsignedIntParameter("pin_num", 4); .withUnsignedIntParameter("pin_num", adc_pin);
mock().expectOneCall("ADC_Enable"); mock().expectOneCall("ADC_Enable");
mock().expectOneCall("ADC_ReadValue_Impl") mock().expectOneCall("ADC_ReadValue_Impl")
.withUnsignedIntParameter("pin_num", 4); .withUnsignedIntParameter("pin_num", adc_pin);
mock().expectOneCall("ADC_Disable"); mock().expectOneCall("ADC_Disable");
}
void expect_porta_disabled(uint8_t load_pin)
{
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", load_pin);
}
Load_HandleLoadPortA(4, 7); void expect_porta_enabled(uint8_t load_pin)
{
mock().expectOneCall("RegEdit_SetBit")
.withPointerParameter("reg", (void *) &PORTA.DIR)
.withUnsignedIntParameter("bit_num", load_pin);
mock().expectOneCall("RegEdit_SetBit")
.withPointerParameter("reg", (void *) &PORTA.OUT)
.withUnsignedIntParameter("bit_num", load_pin);
}
void expect_portb_disabled(uint8_t load_pin)
{
mock().expectOneCall("RegEdit_ClearBit")
.withPointerParameter("reg", (void *) &PORTB.OUT)
.withUnsignedIntParameter("bit_num", load_pin);
}
TEST(test_load, PortAHandlerDisabledHigh)
{
MockADC_ZeroIndex();
MockADC_PushValue(HIGHTHRESH);
setup_adc_expectations(adc_pin);
expect_porta_disabled(load_pin);
Load_HandleLoadPortA(adc_pin, load_pin);
}
TEST(test_load, PortAHandlerDisabledLow)
{
MockADC_ZeroIndex();
MockADC_PushValue(LOWTHRESH);
setup_adc_expectations(adc_pin);
expect_porta_disabled(load_pin);
Load_HandleLoadPortA(adc_pin, load_pin);
}
TEST(test_load, PortAHandlerEnabledBelowTarget)
{
MockADC_ZeroIndex();
MockADC_PushValue(HYSTERESIS - 1);
setup_adc_expectations(adc_pin);
expect_porta_enabled(load_pin);
Load_HandleLoadPortA(adc_pin, load_pin);
}
TEST(test_load, PortAHandlerDisabledAboveTarget)
{
MockADC_ZeroIndex();
MockADC_PushValue(HYSTERESIS);
setup_adc_expectations(adc_pin);
expect_porta_disabled(load_pin);
Load_HandleLoadPortA(adc_pin, load_pin);
} }
TEST(test_load, PortBHandlerSuccess) TEST(test_load, PortBHandlerSuccess)
{ {
mock().expectOneCall("ADC_Init") /*
.withUnsignedIntParameter("pin_num", 4); MockADC_ZeroIndex();
MockADC_PushValue(LOWTHRESH + 1);
MockADC_PushValue(HIGHTHRESH - 1);
MockADC_PushValue(HYSTERESIS - 1);
*/
mock().expectOneCall("ADC_Enable"); setup_adc_expectations(adc_pin);
mock().expectOneCall("ADC_ReadValue_Impl") expect_portb_disabled(load_pin);
.withUnsignedIntParameter("pin_num", 4);
mock().expectOneCall("ADC_Disable");
mock().expectOneCall("RegEdit_ClearBit")
.withPointerParameter("reg", (void *) &PORTB.OUT)
.withUnsignedIntParameter("bit_num", 7);
Load_HandleLoadPortB(4, 7); Load_HandleLoadPortB(adc_pin, load_pin);
} }
TEST(test_load, HighThreshValid) TEST(test_load, HighThreshValid)