cleaned up interfaces for mocking

This commit is contained in:
Jake Goodwin 2024-09-02 13:33:30 -07:00
parent fc715011b8
commit 34602643c2
4 changed files with 64 additions and 10 deletions

View File

@ -69,6 +69,7 @@ endif()
include_directories(
/usr/local/avr/include
/usr/local/avr/avr/include
./inc
)

View File

@ -57,4 +57,3 @@ add_subdirectory(timer)
add_subdirectory(SuperLoop)
add_subdirectory(Relays)
add_subdirectory(TimerMock)

View File

@ -14,14 +14,19 @@
#include "stdbool.h"
/**
*
* @param a The first argument
* Starts up the AVR timer using a 10KHz frequency
*/
void Timer_Start(void);
void Timer_Disable(void);
/**
* Stops the AVR timer.
*/
void Timer_Stop(void);
/**
* Get the number of times the timer's counter setup for 10kHz overflowed.
* @return A uint16_t holding the number of counter overflow events.
*/
uint16_t Timer_GetOverflowCount(void);
#endif // TIMER

View File

@ -6,10 +6,12 @@
*/
#include "CppUTest/CommandLineTestRunner.h"
#include "CppUTestExt/MockSupport.h"
extern "C"
{
#include "Relays.h"
#include "TimerMock.h"
}
void zero_relay_struct(Relay *relay)
@ -48,11 +50,6 @@ TEST(test_Relays, CreateRelayStruct)
CHECK(relay.input_port == &fake_input_port);
}
TEST(test_Relays, MeasureMakeTimeForRelay)
{
FAIL_TEST("Not currently ready for testing.");
}
TEST(test_Relays, DisabledForPowerCycleSetsDisabledBit)
{
Relay_DisableForPowerCycle(&relay);
@ -124,3 +121,55 @@ TEST(test_Relays, ReadStateOfEnabledRelayReadsTrue)
CHECK_FALSE(Relay_ReadState(&relay));
}
}
TEST_GROUP(test_RelaysTimer)
{
uint8_t fake_input_port;
uint8_t fake_ouput_port;
Relay relay;
void setup() {
relay.input_port = &fake_input_port;
relay.output_port = &fake_ouput_port;
zero_relay_struct(&relay);
}
void teardown() {
fake_input_port = 0x00;
fake_ouput_port = 0x00;
mock().clear();
}
};
TEST(test_RelaysTimer, MakeTimeCallsCorrectly)
{
uint16_t fake_return = 56;
mock().expectOneCall("Timer_Start");
mock().expectOneCall("Timer_Stop");
mock().expectOneCall("Timer_GetOverflowCount")
.andReturnValue(fake_return);
//Set the input hi
*(uint8_t *)relay.input_port |= (1 << relay.input_pin);
Relay_MeasureMakeTime(&relay);
CHECK_EQUAL(fake_return, relay.make_time);
mock().checkExpectations();
}
TEST(test_RelaysTimer, BreakTimeCallsCorrectly)
{
uint16_t fake_return = 56;
mock().expectOneCall("Timer_Start");
mock().expectOneCall("Timer_Stop");
mock().expectOneCall("Timer_GetOverflowCount")
.andReturnValue(fake_return);
Relay_MeasureBreakTime(&relay);
CHECK_EQUAL(fake_return, relay.break_time);
mock().checkExpectations();
}