106 lines
2.2 KiB
C++
106 lines
2.2 KiB
C++
/*
|
|
* Author: Jake G
|
|
* Date: 2024
|
|
* filename: test_load.cpp
|
|
* description:
|
|
*/
|
|
|
|
#include "CppUTest/CommandLineTestRunner.h"
|
|
#include "CppUTestExt/MockSupport.h"
|
|
#include <cstdint>
|
|
|
|
|
|
//This define allows us to dircetly include the device header without error.
|
|
#define _AVR_IO_H_
|
|
|
|
extern "C"
|
|
{
|
|
#include <iotn404.h> //ATtiny404 header fille.
|
|
#include "load.h"
|
|
#include "MockADC.h"
|
|
#include "MockADC.h"
|
|
}
|
|
|
|
TEST_GROUP(test_load)
|
|
{
|
|
void setup()
|
|
{
|
|
|
|
}
|
|
void teardown()
|
|
{
|
|
mock().checkExpectations();
|
|
mock().clear();
|
|
}
|
|
};
|
|
|
|
TEST(test_load, LoadPass)
|
|
{
|
|
CHECK_TRUE(true);
|
|
}
|
|
|
|
TEST(test_load, PortAHandlerSuccess)
|
|
{
|
|
mock().expectOneCall("ADC_Init")
|
|
.withUnsignedIntParameter("pin_num", 4);
|
|
|
|
mock().expectOneCall("ADC_Enable");
|
|
mock().expectOneCall("ADC_ReadValue_Impl")
|
|
.withUnsignedIntParameter("pin_num", 4);
|
|
mock().expectOneCall("ADC_Disable");
|
|
mock().expectOneCall("RegEdit_ClearBit")
|
|
.withPointerParameter("reg", (void *) &PORTA.OUT)
|
|
.withUnsignedIntParameter("bit_num", 7);
|
|
|
|
Load_HandleLoadPortA(4, 7);
|
|
}
|
|
|
|
TEST(test_load, PortBHandlerSuccess)
|
|
{
|
|
mock().expectOneCall("ADC_Init")
|
|
.withUnsignedIntParameter("pin_num", 4);
|
|
|
|
mock().expectOneCall("ADC_Enable");
|
|
mock().expectOneCall("ADC_ReadValue_Impl")
|
|
.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);
|
|
}
|
|
|
|
TEST(test_load, HighThreshValid)
|
|
{
|
|
bool result = is_valid_load(HIGHTHRESH);
|
|
CHECK_TRUE(!result);
|
|
|
|
result = is_valid_load(HIGHTHRESH - 1);
|
|
CHECK_TRUE(result);
|
|
}
|
|
|
|
|
|
TEST(test_load, LowThreshValid)
|
|
{
|
|
bool result = is_valid_load(LOWTHRESH);
|
|
CHECK_TRUE(!result);
|
|
|
|
result = is_valid_load(LOWTHRESH + 1);
|
|
CHECK_TRUE(result);
|
|
}
|
|
|
|
|
|
TEST(test_load, BelowTargetValid)
|
|
{
|
|
bool result = is_below_target(HYSTERESIS - 1);
|
|
CHECK_TRUE(result);
|
|
|
|
result = is_below_target(HYSTERESIS);
|
|
CHECK_FALSE(result);
|
|
|
|
result = is_below_target(HYSTERESIS + 1);
|
|
CHECK_FALSE(result);
|
|
|
|
}
|