From 2200e58002dbce28f03de0e8c42a6c9d2f7916b5 Mon Sep 17 00:00:00 2001 From: jakeg00dwin Date: Tue, 24 Sep 2024 09:31:32 -0700 Subject: [PATCH] Changed the duplicated setup of expectations into the setup and teardown functions. --- tests/load/test_load.cpp | 54 ++++++++++++++++++++++++++++++++++------ 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/tests/load/test_load.cpp b/tests/load/test_load.cpp index 72fd3a9..828ded8 100644 --- a/tests/load/test_load.cpp +++ b/tests/load/test_load.cpp @@ -23,9 +23,14 @@ extern "C" TEST_GROUP(test_load) { + uint8_t adc_pin; + uint8_t load_pin; void setup() { - + adc_pin = 4; + load_pin = 7; + MockADC_ZeroIndex(); + Load_SoftResetDisabledLoads(); } void teardown() { @@ -39,18 +44,53 @@ TEST(test_load, LoadPass) CHECK_TRUE(true); } -TEST(test_load, PortAHandlerSuccess) +void setup_adc_expectations(uint8_t adc_pin) { mock().expectOneCall("ADC_Init") - .withUnsignedIntParameter("pin_num", 4); + .withUnsignedIntParameter("pin_num", adc_pin); mock().expectOneCall("ADC_Enable"); mock().expectOneCall("ADC_ReadValue_Impl") - .withUnsignedIntParameter("pin_num", 4); + .withUnsignedIntParameter("pin_num", adc_pin); mock().expectOneCall("ADC_Disable"); +} + +void expect_porta_disabled(uint8_t load_pin) +{ mock().expectOneCall("RegEdit_ClearBit") .withPointerParameter("reg", (void *) &PORTA.OUT) - .withUnsignedIntParameter("bit_num", 7); - - Load_HandleLoadPortA(4, 7); + .withUnsignedIntParameter("bit_num", load_pin); } + +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); +} + + +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); +} + + +