motorized_fader/tests/ADC/test_ADC.cpp

205 lines
4.6 KiB
C++

/*
* Author: Jake G
* Date: 2025
* filename: test_ADC.c
* description: module_purpose
*/
#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 "sfr_defs.h"
#include <iotn13a.h> //ATtiny13A header file.
#include "ADC.h"
}
TEST_GROUP(test_ADC)
{
void setup()
{
}
void teardown()
{
mock().checkExpectations();
mock().clear();
}
};
TEST(test_ADC, FirstTest)
{
CHECK(true);
}
TEST(test_ADC, ADC_SetupSetsRegisters)
{
/*
* ADC Channel Selection(MUX1, MUX0):
* 00 == ADC0/PB5
* 01 == ADC1/PB2
* 10 == ADC2/PB4
* 11 == ADC3/PB3
*/
/*Set the ADC Channel 0 (default) using ADMUX reg*/
/*Set the voltage reference to VCC.*/
/*Set ADC Left adjust result setting to off.*/
mock().expectOneCall("RegEdit_ClearRegister")
.withPointerParameter("reg", (void *) &ADMUX);
/*ADC0 Status and Control Register A*/
/*Set the Prescaler (F_CPU/8) for samping frequency.*/
mock().expectOneCall("RegEdit_SetNum")
.withPointerParameter("reg", (void *) &ADCSRA)
.withUnsignedIntParameter("num", 3);
/*ADC0 Status and Control Register B*/
/*Setup the auto-trigger source.*/
/*Using timer compare/match B for now.*/
mock().expectOneCall("RegEdit_AND_Num")
.withPointerParameter("reg", (void *) &ADCSRB)
.withUnsignedIntParameter("num", 5);
ADC_Setup();
}
TEST(test_ADC, ADC_InitPortbADC3UsesCorrectRegisters)
{
//PB3/ADC3
//Check it disables the pin's digital circuitry
//Check that the ADC pin is selected in ADMUX
//
/*
//Check for setting the direction to input.
mock().expectOneCall("RegEdit_ClearBit")
.withPointerParameter("reg", (void *) &PORTA.DIR)
.withUnsignedIntParameter("bit_num", 7);
//Check that the pullup is off
mock().expectOneCall("RegEdit_ClearBit")
.withPointerParameter("reg", (void *) &PORTA.OUT)
.withUnsignedIntParameter("bit_num", 7);
//Set the ISC(input sense config) to disable digital input
//buffering and reduce the noise on ADC usage.
mock().expectOneCall("RegEdit_SetBit")
.withPointerParameter("reg", (void *) &PORTA.PIN7CTRL)
.withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc);
*/
ADC_Init(7);
}
TEST(test_ADC, ADC_InitPortAPin0UsesCorrectRegisters)
{
/*
//Check for setting the direction to input.
mock().expectOneCall("RegEdit_ClearBit")
.withPointerParameter("reg", (void *) &PORTA.DIR)
.withUnsignedIntParameter("bit_num", 0);
//Check that the pullup is off
mock().expectOneCall("RegEdit_ClearBit")
.withPointerParameter("reg", (void *) &PORTA.OUT)
.withUnsignedIntParameter("bit_num", 0);
//Set the ISC(input sense config) to disable digital input
//buffering and reduce the noise on ADC usage.
mock().expectOneCall("RegEdit_SetBit")
.withPointerParameter("reg", (void *) &PORTA.PIN0CTRL)
.withUnsignedIntParameter("bit_num", PORT_ISC_INPUT_DISABLE_gc);
*/
//ADC_Init(0);
}
TEST(test_ADC, ADC_InitDoesNothingOnHighPinNumbers)
{
//mock().expectNoCall("RegEdit_SetBit");
//ADC_Init(8);
}
TEST(test_ADC, ADC_EnablePasses)
{
/*
mock().expectOneCall("RegEdit_SetBit")
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
.withUnsignedIntParameter("bit_num", 0);
*/
//ADC_Enable();
}
TEST(test_ADC, ADC_DisablePasses)
{
/*
mock().expectOneCall("RegEdit_ClearBit")
.withPointerParameter("reg", (void *) &ADC0.CTRLA)
.withUnsignedIntParameter("bit_num", 0);
*/
//ADC_Disable();
}
TEST(test_ADC, ADC_SetPinSetsRightRegisters)
{
/*
//It clears existing MUXPOS register values.
mock().expectOneCall("RegEdit_ClearRegister")
.withPointerParameter("reg", (void *) &ADC0.MUXPOS);
//It Correctly sets the pin number.
mock().expectOneCall("RegEdit_SetNum")
.withPointerParameter("reg", (void *) &ADC0.MUXPOS)
.withUnsignedIntParameter("num", 4);
*/
//ADC_SetPin(4);
}
TEST(test_ADC, ADC_SetPinFailsOnInvalidPin)
{
//ADC_SetPin(8);
}
static uint16_t ADC_ReadValueFake(uint8_t pin_num)
{
return 512;
}
TEST_GROUP(test_ADCRead)
{
void setup()
{
UT_PTR_SET(ADC_ReadValue, ADC_ReadValueFake);
}
void teardown()
{
}
};
TEST(test_ADCRead, FunctionPointerSwapWorks)
{
uint16_t value = ADC_ReadValue(0);
LONGS_EQUAL(512, value);
}