Added tests for the changed load module.
This commit is contained in:
parent
0287c67281
commit
004f8f3bb5
|
@ -9,6 +9,7 @@ add_subdirectory(RegEdit)
|
||||||
add_subdirectory(simple_test)
|
add_subdirectory(simple_test)
|
||||||
add_subdirectory(zero_cross_detection)
|
add_subdirectory(zero_cross_detection)
|
||||||
add_subdirectory(TriacOut)
|
add_subdirectory(TriacOut)
|
||||||
|
add_subdirectory(load)
|
||||||
|
|
||||||
|
|
||||||
# TEST_RUNNER
|
# TEST_RUNNER
|
||||||
|
@ -33,6 +34,7 @@ add_executable(Mock_Tests
|
||||||
target_link_libraries(Mock_Tests
|
target_link_libraries(Mock_Tests
|
||||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||||
|
test_load
|
||||||
test_MockRegEdit
|
test_MockRegEdit
|
||||||
test_MockADC
|
test_MockADC
|
||||||
test_zero_cross_detection
|
test_zero_cross_detection
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
|
|
||||||
//ImportTestGroups
|
//ImportTestGroups
|
||||||
|
IMPORT_TEST_GROUP(test_load);
|
||||||
IMPORT_TEST_GROUP(test_MockRegEdit);
|
IMPORT_TEST_GROUP(test_MockRegEdit);
|
||||||
IMPORT_TEST_GROUP(test_MockADC);
|
IMPORT_TEST_GROUP(test_MockADC);
|
||||||
IMPORT_TEST_GROUP(test_zero_cross_detection);
|
IMPORT_TEST_GROUP(test_zero_cross_detection);
|
||||||
|
|
|
@ -23,9 +23,14 @@ 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;
|
||||||
|
MockADC_ZeroIndex();
|
||||||
|
Load_SoftResetDisabledLoads();
|
||||||
}
|
}
|
||||||
void teardown()
|
void teardown()
|
||||||
{
|
{
|
||||||
|
@ -39,23 +44,143 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Need to setup a one-shot or way for it to only enable once.
|
void expect_portb_enabled(uint8_t load_pin)
|
||||||
|
{
|
||||||
|
mock().expectOneCall("RegEdit_SetBit")
|
||||||
|
.withPointerParameter("reg", (void *) &PORTB.DIR)
|
||||||
|
.withUnsignedIntParameter("bit_num", load_pin);
|
||||||
|
|
||||||
|
mock().expectOneCall("RegEdit_SetBit")
|
||||||
|
.withPointerParameter("reg", (void *) &PORTB.OUT)
|
||||||
|
.withUnsignedIntParameter("bit_num", load_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(test_load, PortAHandlerDisabledHigh)
|
||||||
|
{
|
||||||
|
MockADC_PushValue(HIGHTHRESH);
|
||||||
|
|
||||||
|
setup_adc_expectations(adc_pin);
|
||||||
|
expect_porta_disabled(load_pin);
|
||||||
|
|
||||||
|
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(test_load, PortAHandlerDisabledLow)
|
||||||
|
{
|
||||||
|
MockADC_PushValue(LOWTHRESH);
|
||||||
|
|
||||||
|
setup_adc_expectations(adc_pin);
|
||||||
|
expect_porta_disabled(load_pin);
|
||||||
|
|
||||||
|
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(test_load, PortAHandlerEnabledWhenValid)
|
||||||
|
{
|
||||||
|
MockADC_PushValue(HIGHTHRESH - 1);
|
||||||
|
|
||||||
|
setup_adc_expectations(adc_pin);
|
||||||
|
expect_porta_enabled(load_pin);
|
||||||
|
|
||||||
|
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(test_load, PortAHandlerDisblesUntilPowerReset)
|
||||||
|
{
|
||||||
|
MockADC_PushValue(HIGHTHRESH - 1);
|
||||||
|
MockADC_PushValue(HIGHTHRESH);
|
||||||
|
|
||||||
|
setup_adc_expectations(adc_pin);
|
||||||
|
expect_porta_disabled(load_pin);
|
||||||
|
|
||||||
|
setup_adc_expectations(adc_pin);
|
||||||
|
expect_porta_disabled(load_pin);
|
||||||
|
|
||||||
|
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||||
|
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TEST(test_load, PortBHandlerDisabledHigh)
|
||||||
|
{
|
||||||
|
MockADC_PushValue(HIGHTHRESH);
|
||||||
|
|
||||||
|
setup_adc_expectations(adc_pin);
|
||||||
|
expect_portb_disabled(load_pin);
|
||||||
|
|
||||||
|
Load_HandleLoadPortB(adc_pin, load_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(test_load, PortBHandlerDisabledLow)
|
||||||
|
{
|
||||||
|
MockADC_PushValue(LOWTHRESH);
|
||||||
|
|
||||||
|
setup_adc_expectations(adc_pin);
|
||||||
|
expect_portb_disabled(load_pin);
|
||||||
|
|
||||||
|
Load_HandleLoadPortB(adc_pin, load_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(test_load, PortBHandlerEnabledWhenValid)
|
||||||
|
{
|
||||||
|
MockADC_PushValue(HIGHTHRESH - 1);
|
||||||
|
|
||||||
|
setup_adc_expectations(adc_pin);
|
||||||
|
expect_portb_enabled(load_pin);
|
||||||
|
|
||||||
|
Load_HandleLoadPortB(adc_pin, load_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(test_load, PortBHandlerDisblesUntilPowerReset)
|
||||||
|
{
|
||||||
|
MockADC_PushValue(HIGHTHRESH - 1);
|
||||||
|
MockADC_PushValue(HIGHTHRESH);
|
||||||
|
|
||||||
|
setup_adc_expectations(adc_pin);
|
||||||
|
expect_portb_disabled(load_pin);
|
||||||
|
|
||||||
|
setup_adc_expectations(adc_pin);
|
||||||
|
expect_portb_disabled(load_pin);
|
||||||
|
|
||||||
|
Load_HandleLoadPortB(adc_pin, load_pin);
|
||||||
|
Load_HandleLoadPortB(adc_pin, load_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue