Updated tests for the the port a handler function.
This commit is contained in:
parent
3caa74f642
commit
0e7deea6e7
|
@ -18,7 +18,6 @@ extern "C"
|
||||||
#include <iotn404.h> //ATtiny404 header fille.
|
#include <iotn404.h> //ATtiny404 header fille.
|
||||||
#include "load.h"
|
#include "load.h"
|
||||||
#include "MockADC.h"
|
#include "MockADC.h"
|
||||||
#include "MockADC.h"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_GROUP(test_load)
|
TEST_GROUP(test_load)
|
||||||
|
@ -55,15 +54,25 @@ void setup_adc_expectations(uint8_t adc_pin)
|
||||||
mock().expectOneCall("ADC_Disable");
|
mock().expectOneCall("ADC_Disable");
|
||||||
}
|
}
|
||||||
|
|
||||||
void expect_porta_disabled(uint8_t load_pin)
|
void expect_porta_disabled(uint8_t load_pin, bool output_level)
|
||||||
{
|
{
|
||||||
|
mock().expectOneCall("RegEdit_IsBitSet")
|
||||||
|
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
||||||
|
.withUnsignedIntParameter("bit_num", load_pin)
|
||||||
|
.andReturnValue(output_level);
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_ClearBit")
|
mock().expectOneCall("RegEdit_ClearBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
||||||
.withUnsignedIntParameter("bit_num", load_pin);
|
.withUnsignedIntParameter("bit_num", load_pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
void expect_porta_enabled(uint8_t load_pin)
|
void expect_porta_enabled(uint8_t load_pin, bool output_level)
|
||||||
{
|
{
|
||||||
|
mock().expectOneCall("RegEdit_IsBitSet")
|
||||||
|
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
||||||
|
.withUnsignedIntParameter("bit_num", load_pin)
|
||||||
|
.andReturnValue(output_level);
|
||||||
|
|
||||||
mock().expectOneCall("RegEdit_SetBit")
|
mock().expectOneCall("RegEdit_SetBit")
|
||||||
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
.withPointerParameter("reg", (void *) &PORTA.DIR)
|
||||||
.withUnsignedIntParameter("bit_num", load_pin);
|
.withUnsignedIntParameter("bit_num", load_pin);
|
||||||
|
@ -97,7 +106,7 @@ TEST(test_load, PortAHandlerDisabledHigh)
|
||||||
MockADC_PushValue(HIGHTHRESH);
|
MockADC_PushValue(HIGHTHRESH);
|
||||||
|
|
||||||
setup_adc_expectations(adc_pin);
|
setup_adc_expectations(adc_pin);
|
||||||
expect_porta_disabled(load_pin);
|
expect_porta_disabled(load_pin, true);
|
||||||
|
|
||||||
Load_HandleLoadPortA(adc_pin, load_pin);
|
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||||
}
|
}
|
||||||
|
@ -107,41 +116,54 @@ TEST(test_load, PortAHandlerDisabledLow)
|
||||||
MockADC_PushValue(LOWTHRESH);
|
MockADC_PushValue(LOWTHRESH);
|
||||||
|
|
||||||
setup_adc_expectations(adc_pin);
|
setup_adc_expectations(adc_pin);
|
||||||
expect_porta_disabled(load_pin);
|
expect_porta_disabled(load_pin, false);
|
||||||
|
|
||||||
Load_HandleLoadPortA(adc_pin, load_pin);
|
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_load, PortAHandlerEnabledBelowTarget)
|
TEST(test_load, PortAHandlerEnabledRisingEdgeLO)
|
||||||
{
|
{
|
||||||
MockADC_PushValue(HYSTERESIS - 1);
|
//Start from the rising edge.
|
||||||
|
MockADC_PushValue(HYSTERESIS_LO - 1);
|
||||||
|
|
||||||
setup_adc_expectations(adc_pin);
|
setup_adc_expectations(adc_pin);
|
||||||
expect_porta_enabled(load_pin);
|
|
||||||
|
expect_porta_enabled(load_pin, false);
|
||||||
|
|
||||||
|
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(test_load, PortAHandlerEnabledRisingEdgeHI)
|
||||||
|
{
|
||||||
|
//Start from the rising edge above lo.
|
||||||
|
MockADC_PushValue(HYSTERESIS_HI - 1);
|
||||||
|
|
||||||
|
setup_adc_expectations(adc_pin);
|
||||||
|
expect_porta_enabled(load_pin, true);
|
||||||
|
|
||||||
Load_HandleLoadPortA(adc_pin, load_pin);
|
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_load, PortAHandlerDisabledAboveTarget)
|
TEST(test_load, PortAHandlerDisabledAboveTarget)
|
||||||
{
|
{
|
||||||
MockADC_PushValue(HYSTERESIS);
|
MockADC_PushValue(HYSTERESIS_HI + 1);
|
||||||
|
|
||||||
setup_adc_expectations(adc_pin);
|
setup_adc_expectations(adc_pin);
|
||||||
expect_porta_disabled(load_pin);
|
expect_porta_disabled(load_pin, true);
|
||||||
|
|
||||||
Load_HandleLoadPortA(adc_pin, load_pin);
|
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(test_load, PortAHandlerDisablesUntilPoweReset)
|
TEST(test_load, PortAHandlerDisablesUntilPoweReset)
|
||||||
{
|
{
|
||||||
MockADC_PushValue(HYSTERESIS - 1);
|
MockADC_PushValue(HYSTERESIS_HI - 1);
|
||||||
MockADC_PushValue(HIGHTHRESH);
|
MockADC_PushValue(HIGHTHRESH);
|
||||||
|
|
||||||
setup_adc_expectations(adc_pin);
|
setup_adc_expectations(adc_pin);
|
||||||
expect_porta_disabled(load_pin);
|
expect_porta_disabled(load_pin, true);
|
||||||
|
|
||||||
setup_adc_expectations(adc_pin);
|
setup_adc_expectations(adc_pin);
|
||||||
expect_porta_disabled(load_pin);
|
expect_porta_disabled(load_pin, false);
|
||||||
|
|
||||||
Load_HandleLoadPortA(adc_pin, load_pin);
|
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||||
Load_HandleLoadPortA(adc_pin, load_pin);
|
Load_HandleLoadPortA(adc_pin, load_pin);
|
||||||
|
@ -171,7 +193,7 @@ TEST(test_load, PortBHandlerDisabledLow)
|
||||||
|
|
||||||
TEST(test_load, PortBHandlerEnabledBelowTarget)
|
TEST(test_load, PortBHandlerEnabledBelowTarget)
|
||||||
{
|
{
|
||||||
MockADC_PushValue(HYSTERESIS - 1);
|
MockADC_PushValue(HYSTERESIS_HI - 1);
|
||||||
|
|
||||||
setup_adc_expectations(adc_pin);
|
setup_adc_expectations(adc_pin);
|
||||||
expect_portb_enabled(load_pin);
|
expect_portb_enabled(load_pin);
|
||||||
|
@ -182,7 +204,7 @@ TEST(test_load, PortBHandlerEnabledBelowTarget)
|
||||||
|
|
||||||
TEST(test_load, PortBHandlerDisabledAboveTarget)
|
TEST(test_load, PortBHandlerDisabledAboveTarget)
|
||||||
{
|
{
|
||||||
MockADC_PushValue(HYSTERESIS);
|
MockADC_PushValue(HYSTERESIS_HI);
|
||||||
|
|
||||||
setup_adc_expectations(adc_pin);
|
setup_adc_expectations(adc_pin);
|
||||||
expect_portb_disabled(load_pin);
|
expect_portb_disabled(load_pin);
|
||||||
|
@ -192,7 +214,7 @@ TEST(test_load, PortBHandlerDisabledAboveTarget)
|
||||||
|
|
||||||
TEST(test_load, PortBHandlerDisablesUntilPoweReset)
|
TEST(test_load, PortBHandlerDisablesUntilPoweReset)
|
||||||
{
|
{
|
||||||
MockADC_PushValue(HYSTERESIS - 1);
|
MockADC_PushValue(HYSTERESIS_HI - 1);
|
||||||
MockADC_PushValue(HIGHTHRESH);
|
MockADC_PushValue(HIGHTHRESH);
|
||||||
|
|
||||||
setup_adc_expectations(adc_pin);
|
setup_adc_expectations(adc_pin);
|
||||||
|
|
Loading…
Reference in New Issue