Added zcd module's tests
This commit is contained in:
parent
32b2096ab8
commit
8bec415466
|
@ -0,0 +1,11 @@
|
|||
# TEST_RUNNER
|
||||
add_library(test_zero_cross_detection
|
||||
test_zero_cross_detection.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_zero_cross_detection
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
zero_cross_detection
|
||||
MockADC
|
||||
)
|
|
@ -0,0 +1,111 @@
|
|||
/*
|
||||
* Author: username
|
||||
* Date: todays_date
|
||||
* filename: test_zero_cross_detection.c
|
||||
* description: module_purpose
|
||||
*/
|
||||
|
||||
#include "CppUTest/CommandLineTestRunner.h"
|
||||
#include "CppUTest/TestFailure.h"
|
||||
#include "CppUTest/TestPlugin.h"
|
||||
#include "CppUTest/UtestMacros.h"
|
||||
#include "CppUTestExt/MockSupport.h"
|
||||
#include <cstdint>
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "MockADC.h"
|
||||
#include "zero_cross_detection.h"
|
||||
}
|
||||
|
||||
TEST_GROUP(test_zero_cross_detection)
|
||||
{
|
||||
|
||||
void setup()
|
||||
{
|
||||
|
||||
}
|
||||
void teardown()
|
||||
{
|
||||
mock().checkExpectations();
|
||||
mock().clear();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
static void ZCDSetupExpectations(void)
|
||||
{
|
||||
mock().expectOneCall("ADC_Init")
|
||||
.withUnsignedIntParameter("pin_num", 7);
|
||||
|
||||
mock().expectOneCall("ADC_Enable");
|
||||
}
|
||||
|
||||
|
||||
static void PollIterationExpectations(void)
|
||||
{
|
||||
ZCDSetupExpectations();
|
||||
|
||||
mock().expectOneCall("ADC_ReadValue_Impl")
|
||||
.withUnsignedIntParameter("pin_num", 7)
|
||||
.ignoreOtherParameters();
|
||||
|
||||
mock().expectOneCall("ADC_Disable");
|
||||
|
||||
ZCDSetupExpectations();
|
||||
|
||||
mock().expectOneCall("ADC_ReadValue_Impl")
|
||||
.withUnsignedIntParameter("pin_num", 7)
|
||||
.ignoreOtherParameters();
|
||||
|
||||
mock().expectOneCall("ADC_Disable");
|
||||
}
|
||||
|
||||
|
||||
TEST(test_zero_cross_detection, ZCD_SetupCallsCorrectFuncs)
|
||||
{
|
||||
ZCDSetupExpectations();
|
||||
|
||||
ZCD_Setup();
|
||||
}
|
||||
|
||||
|
||||
TEST(test_zero_cross_detection, ZCD_IsTriggeredCallsCorrectFunctions)
|
||||
{
|
||||
MockADC_ZeroIndex();
|
||||
|
||||
PollIterationExpectations();
|
||||
|
||||
CHECK_FALSE(ZCD_IsTriggered());
|
||||
}
|
||||
|
||||
|
||||
TEST(test_zero_cross_detection, ZCD_IsTriggerdTrueWhenRising)
|
||||
{
|
||||
MockADC_ZeroIndex();
|
||||
|
||||
MockADC_PushValue(512);
|
||||
MockADC_PushValue(450);
|
||||
|
||||
PollIterationExpectations();
|
||||
|
||||
CHECK_TRUE(ZCD_IsTriggered());
|
||||
}
|
||||
|
||||
|
||||
TEST(test_zero_cross_detection, ZCD_PollWorksAfterCalls)
|
||||
{
|
||||
MockADC_ZeroIndex();
|
||||
|
||||
MockADC_PushValue(512);
|
||||
MockADC_PushValue(450);
|
||||
MockADC_PushValue(50);
|
||||
MockADC_PushValue(50);
|
||||
|
||||
PollIterationExpectations();
|
||||
PollIterationExpectations();
|
||||
|
||||
ZCD_Poll();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue