mirror of
https://github.com/ThrowTheSwitch/CMock.git
synced 2026-08-29 14:29:58 +00:00
fixed white space
This commit is contained in:
@@ -1,121 +1,121 @@
|
||||
#include "unity.h"
|
||||
#include "UnityHelper.h"
|
||||
#include "Types.h"
|
||||
#include "Types.h"
|
||||
#include "AdcConductor.h"
|
||||
#include "MockAdcModel.h"
|
||||
#include "MockAdcHardware.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallHardwareInit(void)
|
||||
{
|
||||
AdcHardware_Init_Expect();
|
||||
AdcConductor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldNotDoAnythingIfItIsNotTime(void)
|
||||
{
|
||||
AdcModel_DoGetSample_ExpectAndReturn(FALSE);
|
||||
|
||||
AdcConductor_Run();
|
||||
}
|
||||
|
||||
void testRunShouldNotPassAdcResultToModelIfSampleIsNotComplete(void)
|
||||
{
|
||||
AdcModel_DoGetSample_ExpectAndReturn(TRUE);
|
||||
AdcHardware_GetSampleComplete_ExpectAndReturn(FALSE);
|
||||
|
||||
AdcConductor_Run();
|
||||
}
|
||||
|
||||
void testRunShouldGetLatestSampleFromAdcAndPassItToModelAndStartNewConversionWhenItIsTime(void)
|
||||
{
|
||||
AdcModel_DoGetSample_ExpectAndReturn(TRUE);
|
||||
AdcHardware_GetSampleComplete_ExpectAndReturn(TRUE);
|
||||
AdcHardware_GetSample_ExpectAndReturn(293U);
|
||||
AdcModel_ProcessInput_Expect(293U);
|
||||
AdcHardware_StartConversion_Expect();
|
||||
|
||||
AdcConductor_Run();
|
||||
}
|
||||
|
||||
void testJustHereToTest_Should_ProperlyPassAStructAndVerifyIt(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T TestStruct;
|
||||
TestStruct.x = 5;
|
||||
TestStruct.y = 7;
|
||||
|
||||
AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE);
|
||||
|
||||
TEST_ASSERT_TRUE(AdcConductor_JustHereToTest());
|
||||
}
|
||||
|
||||
//void testJustHereToTest_Should_FailThisTestIfYouUncommentXIsBecauseItsWrong(void)
|
||||
//{
|
||||
// EXAMPLE_STRUCT_T TestStruct;
|
||||
// TestStruct.x = 6;
|
||||
// TestStruct.y = 7;
|
||||
//
|
||||
// AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE);
|
||||
//
|
||||
// TEST_ASSERT_TRUE(AdcConductor_JustHereToTest());
|
||||
//}
|
||||
//
|
||||
//void testJustHereToTest_Should_FailThisTestIfYouUncommentYIsBecauseItsWrong(void)
|
||||
//{
|
||||
// EXAMPLE_STRUCT_T TestStruct;
|
||||
// TestStruct.x = 5;
|
||||
// TestStruct.y = 8;
|
||||
//
|
||||
// AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE);
|
||||
//
|
||||
// TEST_ASSERT_TRUE(AdcConductor_JustHereToTest());
|
||||
//}
|
||||
|
||||
void test_AdcConductor_AlsoHereToTest_Should_ProperlyReturnAStructAsExpected1(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T TestStruct;
|
||||
TestStruct.x = 99;
|
||||
TestStruct.y = 1;
|
||||
|
||||
AdcModel_DoNothingExceptReturnASpecialType_ExpectAndReturn(TestStruct);
|
||||
|
||||
TEST_ASSERT_TRUE(AdcConductor_AlsoHereToTest());
|
||||
}
|
||||
|
||||
void test_AdcConductor_AlsoHereToTest_Should_ProperlyReturnAStructAsExpected2(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T TestStruct;
|
||||
TestStruct.x = 98;
|
||||
TestStruct.y = 1;
|
||||
|
||||
AdcModel_DoNothingExceptReturnASpecialType_ExpectAndReturn(TestStruct);
|
||||
|
||||
TEST_ASSERT_FALSE(AdcConductor_AlsoHereToTest());
|
||||
}
|
||||
|
||||
void test_AdcConductor_YetAnotherTest_Should_VerifyThatPointersToStructsAreTestable(void)
|
||||
{
|
||||
uint32 TestNum = 3;
|
||||
|
||||
AdModel_DoNothingExceptTestPointers_ExpectAndReturn(&TestNum, TRUE);
|
||||
|
||||
TEST_ASSERT_TRUE(AdcConductor_YetAnotherTest());
|
||||
}
|
||||
|
||||
//void test_AdcConductor_YetAnotherTest_Should_FailIfYouUncommentThisTestBecauseTheValuePointedToIsWrong(void)
|
||||
//{
|
||||
// uint32 TestNum = 7;
|
||||
//
|
||||
// AdModel_DoNothingExceptTestPointers_ExpectAndReturn(&TestNum, FALSE);
|
||||
//
|
||||
// TEST_ASSERT_FALSE(AdcConductor_YetAnotherTest());
|
||||
//}
|
||||
|
||||
#include "unity.h"
|
||||
#include "UnityHelper.h"
|
||||
#include "Types.h"
|
||||
#include "Types.h"
|
||||
#include "AdcConductor.h"
|
||||
#include "MockAdcModel.h"
|
||||
#include "MockAdcHardware.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallHardwareInit(void)
|
||||
{
|
||||
AdcHardware_Init_Expect();
|
||||
AdcConductor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldNotDoAnythingIfItIsNotTime(void)
|
||||
{
|
||||
AdcModel_DoGetSample_ExpectAndReturn(FALSE);
|
||||
|
||||
AdcConductor_Run();
|
||||
}
|
||||
|
||||
void testRunShouldNotPassAdcResultToModelIfSampleIsNotComplete(void)
|
||||
{
|
||||
AdcModel_DoGetSample_ExpectAndReturn(TRUE);
|
||||
AdcHardware_GetSampleComplete_ExpectAndReturn(FALSE);
|
||||
|
||||
AdcConductor_Run();
|
||||
}
|
||||
|
||||
void testRunShouldGetLatestSampleFromAdcAndPassItToModelAndStartNewConversionWhenItIsTime(void)
|
||||
{
|
||||
AdcModel_DoGetSample_ExpectAndReturn(TRUE);
|
||||
AdcHardware_GetSampleComplete_ExpectAndReturn(TRUE);
|
||||
AdcHardware_GetSample_ExpectAndReturn(293U);
|
||||
AdcModel_ProcessInput_Expect(293U);
|
||||
AdcHardware_StartConversion_Expect();
|
||||
|
||||
AdcConductor_Run();
|
||||
}
|
||||
|
||||
void testJustHereToTest_Should_ProperlyPassAStructAndVerifyIt(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T TestStruct;
|
||||
TestStruct.x = 5;
|
||||
TestStruct.y = 7;
|
||||
|
||||
AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE);
|
||||
|
||||
TEST_ASSERT_TRUE(AdcConductor_JustHereToTest());
|
||||
}
|
||||
|
||||
//void testJustHereToTest_Should_FailThisTestIfYouUncommentXIsBecauseItsWrong(void)
|
||||
//{
|
||||
// EXAMPLE_STRUCT_T TestStruct;
|
||||
// TestStruct.x = 6;
|
||||
// TestStruct.y = 7;
|
||||
//
|
||||
// AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE);
|
||||
//
|
||||
// TEST_ASSERT_TRUE(AdcConductor_JustHereToTest());
|
||||
//}
|
||||
//
|
||||
//void testJustHereToTest_Should_FailThisTestIfYouUncommentYIsBecauseItsWrong(void)
|
||||
//{
|
||||
// EXAMPLE_STRUCT_T TestStruct;
|
||||
// TestStruct.x = 5;
|
||||
// TestStruct.y = 8;
|
||||
//
|
||||
// AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE);
|
||||
//
|
||||
// TEST_ASSERT_TRUE(AdcConductor_JustHereToTest());
|
||||
//}
|
||||
|
||||
void test_AdcConductor_AlsoHereToTest_Should_ProperlyReturnAStructAsExpected1(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T TestStruct;
|
||||
TestStruct.x = 99;
|
||||
TestStruct.y = 1;
|
||||
|
||||
AdcModel_DoNothingExceptReturnASpecialType_ExpectAndReturn(TestStruct);
|
||||
|
||||
TEST_ASSERT_TRUE(AdcConductor_AlsoHereToTest());
|
||||
}
|
||||
|
||||
void test_AdcConductor_AlsoHereToTest_Should_ProperlyReturnAStructAsExpected2(void)
|
||||
{
|
||||
EXAMPLE_STRUCT_T TestStruct;
|
||||
TestStruct.x = 98;
|
||||
TestStruct.y = 1;
|
||||
|
||||
AdcModel_DoNothingExceptReturnASpecialType_ExpectAndReturn(TestStruct);
|
||||
|
||||
TEST_ASSERT_FALSE(AdcConductor_AlsoHereToTest());
|
||||
}
|
||||
|
||||
void test_AdcConductor_YetAnotherTest_Should_VerifyThatPointersToStructsAreTestable(void)
|
||||
{
|
||||
uint32 TestNum = 3;
|
||||
|
||||
AdModel_DoNothingExceptTestPointers_ExpectAndReturn(&TestNum, TRUE);
|
||||
|
||||
TEST_ASSERT_TRUE(AdcConductor_YetAnotherTest());
|
||||
}
|
||||
|
||||
//void test_AdcConductor_YetAnotherTest_Should_FailIfYouUncommentThisTestBecauseTheValuePointedToIsWrong(void)
|
||||
//{
|
||||
// uint32 TestNum = 7;
|
||||
//
|
||||
// AdModel_DoNothingExceptTestPointers_ExpectAndReturn(&TestNum, FALSE);
|
||||
//
|
||||
// TEST_ASSERT_FALSE(AdcConductor_YetAnotherTest());
|
||||
//}
|
||||
|
||||
|
||||
@@ -1,44 +1,44 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcHardware.h"
|
||||
#include "MockAdcHardwareConfigurator.h"
|
||||
#include "MockAdcTemperatureSensor.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldDelegateToConfiguratorAndTemperatureSensor(void)
|
||||
{
|
||||
Adc_Reset_Expect();
|
||||
Adc_ConfigureMode_Expect();
|
||||
Adc_EnableTemperatureChannel_Expect();
|
||||
Adc_StartTemperatureSensorConversion_Expect();
|
||||
|
||||
AdcHardware_Init();
|
||||
}
|
||||
|
||||
void testGetSampleCompleteShouldReturn_FALSE_WhenTemperatureSensorSampleReadyReturns_FALSE(void)
|
||||
{
|
||||
Adc_TemperatureSensorSampleReady_ExpectAndReturn(FALSE);
|
||||
TEST_ASSERT(!AdcHardware_GetSampleComplete());
|
||||
}
|
||||
|
||||
void testGetSampleCompleteShouldReturn_TRUE_WhenTemperatureSensorSampleReadyReturns_TRUE(void)
|
||||
{
|
||||
Adc_TemperatureSensorSampleReady_ExpectAndReturn(TRUE);
|
||||
TEST_ASSERT(AdcHardware_GetSampleComplete());
|
||||
}
|
||||
|
||||
void testGetSampleShouldDelegateToAdcTemperatureSensor(void)
|
||||
{
|
||||
uint16 sample;
|
||||
Adc_ReadTemperatureSensor_ExpectAndReturn(847);
|
||||
|
||||
sample = AdcHardware_GetSample();
|
||||
TEST_ASSERT_EQUAL(847, sample);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcHardware.h"
|
||||
#include "MockAdcHardwareConfigurator.h"
|
||||
#include "MockAdcTemperatureSensor.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldDelegateToConfiguratorAndTemperatureSensor(void)
|
||||
{
|
||||
Adc_Reset_Expect();
|
||||
Adc_ConfigureMode_Expect();
|
||||
Adc_EnableTemperatureChannel_Expect();
|
||||
Adc_StartTemperatureSensorConversion_Expect();
|
||||
|
||||
AdcHardware_Init();
|
||||
}
|
||||
|
||||
void testGetSampleCompleteShouldReturn_FALSE_WhenTemperatureSensorSampleReadyReturns_FALSE(void)
|
||||
{
|
||||
Adc_TemperatureSensorSampleReady_ExpectAndReturn(FALSE);
|
||||
TEST_ASSERT(!AdcHardware_GetSampleComplete());
|
||||
}
|
||||
|
||||
void testGetSampleCompleteShouldReturn_TRUE_WhenTemperatureSensorSampleReadyReturns_TRUE(void)
|
||||
{
|
||||
Adc_TemperatureSensorSampleReady_ExpectAndReturn(TRUE);
|
||||
TEST_ASSERT(AdcHardware_GetSampleComplete());
|
||||
}
|
||||
|
||||
void testGetSampleShouldDelegateToAdcTemperatureSensor(void)
|
||||
{
|
||||
uint16 sample;
|
||||
Adc_ReadTemperatureSensor_ExpectAndReturn(847);
|
||||
|
||||
sample = AdcHardware_GetSample();
|
||||
TEST_ASSERT_EQUAL(847, sample);
|
||||
}
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcHardwareConfigurator.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
#include "ModelConfig.h"
|
||||
|
||||
AT91S_ADC AdcPeripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testResetShouldResetTheAdcConverterPeripheral(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CR = 0;
|
||||
Adc_Reset();
|
||||
TEST_ASSERT_EQUAL(AT91C_ADC_SWRST, AT91C_BASE_ADC->ADC_CR);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldSetAdcModeRegisterAppropriately(void)
|
||||
{
|
||||
uint32 prescaler = (MASTER_CLOCK / (2 * 2000000)) - 1; // 5MHz ADC clock
|
||||
|
||||
AT91C_BASE_ADC->ADC_MR = 0;
|
||||
|
||||
Adc_ConfigureMode();
|
||||
|
||||
TEST_ASSERT_EQUAL(prescaler, (AT91C_BASE_ADC->ADC_MR & AT91C_ADC_PRESCAL) >> 8);
|
||||
}
|
||||
|
||||
void testEnableTemperatureChannelShouldEnableTheAppropriateAdcInput(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CHER = 0;
|
||||
|
||||
Adc_EnableTemperatureChannel();
|
||||
|
||||
TEST_ASSERT_EQUAL(0x1 << 4, AT91C_BASE_ADC->ADC_CHER);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcHardwareConfigurator.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
#include "ModelConfig.h"
|
||||
|
||||
AT91S_ADC AdcPeripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testResetShouldResetTheAdcConverterPeripheral(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CR = 0;
|
||||
Adc_Reset();
|
||||
TEST_ASSERT_EQUAL(AT91C_ADC_SWRST, AT91C_BASE_ADC->ADC_CR);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldSetAdcModeRegisterAppropriately(void)
|
||||
{
|
||||
uint32 prescaler = (MASTER_CLOCK / (2 * 2000000)) - 1; // 5MHz ADC clock
|
||||
|
||||
AT91C_BASE_ADC->ADC_MR = 0;
|
||||
|
||||
Adc_ConfigureMode();
|
||||
|
||||
TEST_ASSERT_EQUAL(prescaler, (AT91C_BASE_ADC->ADC_MR & AT91C_ADC_PRESCAL) >> 8);
|
||||
}
|
||||
|
||||
void testEnableTemperatureChannelShouldEnableTheAppropriateAdcInput(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CHER = 0;
|
||||
|
||||
Adc_EnableTemperatureChannel();
|
||||
|
||||
TEST_ASSERT_EQUAL(0x1 << 4, AT91C_BASE_ADC->ADC_CHER);
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcModel.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
#include "MockTemperatureCalculator.h"
|
||||
#include "MockTemperatureFilter.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testDoGetSampleShouldReturn_FALSE_WhenTaskSchedulerReturns_FALSE(void)
|
||||
{
|
||||
TaskScheduler_DoAdc_ExpectAndReturn(FALSE);
|
||||
TEST_ASSERT_EQUAL(FALSE, AdcModel_DoGetSample());
|
||||
}
|
||||
|
||||
void testDoGetSampleShouldReturn_TRUE_WhenTaskSchedulerReturns_TRUE(void)
|
||||
{
|
||||
TaskScheduler_DoAdc_ExpectAndReturn(TRUE);
|
||||
TEST_ASSERT_EQUAL(TRUE, AdcModel_DoGetSample());
|
||||
}
|
||||
|
||||
void testProcessInputShouldDelegateToTemperatureCalculatorAndPassResultToFilter(void)
|
||||
{
|
||||
TemperatureCalculator_Calculate_ExpectAndReturn(21473, 23.5f);
|
||||
TemperatureFilter_ProcessInput_Expect(23.5f);
|
||||
AdcModel_ProcessInput(21473);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcModel.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
#include "MockTemperatureCalculator.h"
|
||||
#include "MockTemperatureFilter.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testDoGetSampleShouldReturn_FALSE_WhenTaskSchedulerReturns_FALSE(void)
|
||||
{
|
||||
TaskScheduler_DoAdc_ExpectAndReturn(FALSE);
|
||||
TEST_ASSERT_EQUAL(FALSE, AdcModel_DoGetSample());
|
||||
}
|
||||
|
||||
void testDoGetSampleShouldReturn_TRUE_WhenTaskSchedulerReturns_TRUE(void)
|
||||
{
|
||||
TaskScheduler_DoAdc_ExpectAndReturn(TRUE);
|
||||
TEST_ASSERT_EQUAL(TRUE, AdcModel_DoGetSample());
|
||||
}
|
||||
|
||||
void testProcessInputShouldDelegateToTemperatureCalculatorAndPassResultToFilter(void)
|
||||
{
|
||||
TemperatureCalculator_Calculate_ExpectAndReturn(21473, 23.5f);
|
||||
TemperatureFilter_ProcessInput_Expect(23.5f);
|
||||
AdcModel_ProcessInput(21473);
|
||||
}
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcTemperatureSensor.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
|
||||
AT91S_ADC AdcPeripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldStartTemperatureSensorConversionWhenTriggered(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CR = 0;
|
||||
Adc_StartTemperatureSensorConversion();
|
||||
TEST_ASSERT_EQUAL(AT91C_ADC_START, AT91C_BASE_ADC->ADC_CR);
|
||||
}
|
||||
|
||||
void testTemperatureSensorSampleReadyShouldReturnChannelConversionCompletionStatus(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_SR = 0;
|
||||
TEST_ASSERT_EQUAL(FALSE, Adc_TemperatureSensorSampleReady());
|
||||
AT91C_BASE_ADC->ADC_SR = ~AT91C_ADC_EOC4;
|
||||
TEST_ASSERT_EQUAL(FALSE, Adc_TemperatureSensorSampleReady());
|
||||
AT91C_BASE_ADC->ADC_SR = AT91C_ADC_EOC4;
|
||||
TEST_ASSERT_EQUAL(TRUE, Adc_TemperatureSensorSampleReady());
|
||||
AT91C_BASE_ADC->ADC_SR = 0xffffffff;
|
||||
TEST_ASSERT_EQUAL(TRUE, Adc_TemperatureSensorSampleReady());
|
||||
}
|
||||
|
||||
void testReadTemperatureSensorShouldFetchAndTranslateLatestReadingToMillivolts(void)
|
||||
{
|
||||
uint16 result;
|
||||
|
||||
// ADC bit weight at 10-bit resolution with 3.0V reference = 2.9296875 mV/LSB
|
||||
AT91C_BASE_ADC->ADC_CDR4 = 138;
|
||||
result = Adc_ReadTemperatureSensor();
|
||||
TEST_ASSERT_EQUAL(404, result);
|
||||
|
||||
AT91C_BASE_ADC->ADC_CDR4 = 854;
|
||||
result = Adc_ReadTemperatureSensor();
|
||||
TEST_ASSERT_EQUAL(2502, result);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "AdcTemperatureSensor.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
|
||||
AT91S_ADC AdcPeripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldStartTemperatureSensorConversionWhenTriggered(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_CR = 0;
|
||||
Adc_StartTemperatureSensorConversion();
|
||||
TEST_ASSERT_EQUAL(AT91C_ADC_START, AT91C_BASE_ADC->ADC_CR);
|
||||
}
|
||||
|
||||
void testTemperatureSensorSampleReadyShouldReturnChannelConversionCompletionStatus(void)
|
||||
{
|
||||
AT91C_BASE_ADC->ADC_SR = 0;
|
||||
TEST_ASSERT_EQUAL(FALSE, Adc_TemperatureSensorSampleReady());
|
||||
AT91C_BASE_ADC->ADC_SR = ~AT91C_ADC_EOC4;
|
||||
TEST_ASSERT_EQUAL(FALSE, Adc_TemperatureSensorSampleReady());
|
||||
AT91C_BASE_ADC->ADC_SR = AT91C_ADC_EOC4;
|
||||
TEST_ASSERT_EQUAL(TRUE, Adc_TemperatureSensorSampleReady());
|
||||
AT91C_BASE_ADC->ADC_SR = 0xffffffff;
|
||||
TEST_ASSERT_EQUAL(TRUE, Adc_TemperatureSensorSampleReady());
|
||||
}
|
||||
|
||||
void testReadTemperatureSensorShouldFetchAndTranslateLatestReadingToMillivolts(void)
|
||||
{
|
||||
uint16 result;
|
||||
|
||||
// ADC bit weight at 10-bit resolution with 3.0V reference = 2.9296875 mV/LSB
|
||||
AT91C_BASE_ADC->ADC_CDR4 = 138;
|
||||
result = Adc_ReadTemperatureSensor();
|
||||
TEST_ASSERT_EQUAL(404, result);
|
||||
|
||||
AT91C_BASE_ADC->ADC_CDR4 = 854;
|
||||
result = Adc_ReadTemperatureSensor();
|
||||
TEST_ASSERT_EQUAL(2502, result);
|
||||
}
|
||||
|
||||
@@ -1,36 +1,36 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "Executor.h"
|
||||
#include "MockModel.h"
|
||||
#include "MockUsartConductor.h"
|
||||
#include "MockAdcConductor.h"
|
||||
#include "MockTimerConductor.h"
|
||||
#include "MockIntrinsicsWrapper.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallInitOfAllConductorsAndTheModel(void)
|
||||
{
|
||||
Model_Init_Expect();
|
||||
UsartConductor_Init_Expect();
|
||||
AdcConductor_Init_Expect();
|
||||
TimerConductor_Init_Expect();
|
||||
Interrupt_Enable_Expect();
|
||||
|
||||
Executor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldCallRunForEachConductorAndReturnTrueAlways(void)
|
||||
{
|
||||
UsartConductor_Run_Expect();
|
||||
TimerConductor_Run_Expect();
|
||||
AdcConductor_Run_Expect();
|
||||
|
||||
TEST_ASSERT_EQUAL(TRUE, Executor_Run());
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "Executor.h"
|
||||
#include "MockModel.h"
|
||||
#include "MockUsartConductor.h"
|
||||
#include "MockAdcConductor.h"
|
||||
#include "MockTimerConductor.h"
|
||||
#include "MockIntrinsicsWrapper.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallInitOfAllConductorsAndTheModel(void)
|
||||
{
|
||||
Model_Init_Expect();
|
||||
UsartConductor_Init_Expect();
|
||||
AdcConductor_Init_Expect();
|
||||
TimerConductor_Init_Expect();
|
||||
Interrupt_Enable_Expect();
|
||||
|
||||
Executor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldCallRunForEachConductorAndReturnTrueAlways(void)
|
||||
{
|
||||
UsartConductor_Run_Expect();
|
||||
TimerConductor_Run_Expect();
|
||||
AdcConductor_Run_Expect();
|
||||
|
||||
TEST_ASSERT_EQUAL(TRUE, Executor_Run());
|
||||
}
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "MockExecutor.h"
|
||||
#include "Main.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testMainShouldCallExecutorInitAndContinueToCallExecutorRunUntilHalted(void)
|
||||
{
|
||||
Executor_Init_Expect();
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(FALSE);
|
||||
|
||||
AppMain();
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "MockExecutor.h"
|
||||
#include "Main.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testMainShouldCallExecutorInitAndContinueToCallExecutorRunUntilHalted(void)
|
||||
{
|
||||
Executor_Init_Expect();
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(TRUE);
|
||||
Executor_Run_ExpectAndReturn(FALSE);
|
||||
|
||||
AppMain();
|
||||
}
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "Model.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
#include "MockTemperatureFilter.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallSchedulerAndTemperatureFilterInit(void)
|
||||
{
|
||||
TaskScheduler_Init_Expect();
|
||||
TemperatureFilter_Init_Expect();
|
||||
Model_Init();
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "Model.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
#include "MockTemperatureFilter.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallSchedulerAndTemperatureFilterInit(void)
|
||||
{
|
||||
TaskScheduler_Init_Expect();
|
||||
TemperatureFilter_Init_Expect();
|
||||
Model_Init();
|
||||
}
|
||||
|
||||
@@ -1,104 +1,104 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TaskScheduler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
TaskScheduler_Init();
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldScheduleUsartTaskAfter1000ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(999);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(1000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldClearUsartDoFlagAfterReported(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldScheduleUsartTaskEvery1000ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(1300);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(2000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(3100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldScheduleUsartTaskOnlyOncePerPeriod(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1001);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1999);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(2000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldScheduleAdcTaskAfter100ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(99);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
void testShouldClearAdcDoFlagAfterReported(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
void testShouldScheduleAdcTaskEvery100ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(121);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(200);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(356);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
void testShouldScheduleAdcTaskOnlyOncePerPeriod(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(101);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(199);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(200);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TaskScheduler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
TaskScheduler_Init();
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldScheduleUsartTaskAfter1000ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(999);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(1000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldClearUsartDoFlagAfterReported(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldScheduleUsartTaskEvery1000ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(1300);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(2000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
|
||||
TaskScheduler_Update(3100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldScheduleUsartTaskOnlyOncePerPeriod(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1001);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(1999);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoUsart());
|
||||
TaskScheduler_Update(2000);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoUsart());
|
||||
}
|
||||
|
||||
void testShouldScheduleAdcTaskAfter100ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(99);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
void testShouldClearAdcDoFlagAfterReported(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
void testShouldScheduleAdcTaskEvery100ms(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(121);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(200);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
|
||||
TaskScheduler_Update(356);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
void testShouldScheduleAdcTaskOnlyOncePerPeriod(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(100);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(101);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(199);
|
||||
TEST_ASSERT_EQUAL(FALSE, TaskScheduler_DoAdc());
|
||||
TaskScheduler_Update(200);
|
||||
TEST_ASSERT_EQUAL(TRUE, TaskScheduler_DoAdc());
|
||||
}
|
||||
|
||||
@@ -1,33 +1,33 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TemperatureCalculator.h"
|
||||
#include <math.h>
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testTemperatureCalculatorShouldCalculateTemperatureFromMillivolts(void)
|
||||
{
|
||||
float result;
|
||||
|
||||
// Series resistor is 5k Ohms; Reference voltage is 3.0V
|
||||
// R(t) = A * e^(B*t); R is resistance of thermisor; t is temperature in C
|
||||
result = TemperatureCalculator_Calculate(1000);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01f, 25.0f, result);
|
||||
|
||||
result = TemperatureCalculator_Calculate(2985);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01f, 68.317f, result);
|
||||
|
||||
result = TemperatureCalculator_Calculate(3);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01f, -19.96f, result);
|
||||
}
|
||||
|
||||
void testShouldReturnNegativeInfinityWhen_0_millivoltsInput(void)
|
||||
{
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0000001f, -INFINITY, TemperatureCalculator_Calculate(0));
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TemperatureCalculator.h"
|
||||
#include <math.h>
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testTemperatureCalculatorShouldCalculateTemperatureFromMillivolts(void)
|
||||
{
|
||||
float result;
|
||||
|
||||
// Series resistor is 5k Ohms; Reference voltage is 3.0V
|
||||
// R(t) = A * e^(B*t); R is resistance of thermisor; t is temperature in C
|
||||
result = TemperatureCalculator_Calculate(1000);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01f, 25.0f, result);
|
||||
|
||||
result = TemperatureCalculator_Calculate(2985);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01f, 68.317f, result);
|
||||
|
||||
result = TemperatureCalculator_Calculate(3);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.01f, -19.96f, result);
|
||||
}
|
||||
|
||||
void testShouldReturnNegativeInfinityWhen_0_millivoltsInput(void)
|
||||
{
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0000001f, -INFINITY, TemperatureCalculator_Calculate(0));
|
||||
}
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TemperatureFilter.h"
|
||||
#include <math.h>
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldInitializeTemeratureToInvalidValue(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, -INFINITY, TemperatureFilter_GetTemperatureInCelcius());
|
||||
}
|
||||
|
||||
void testShouldInitializeTemperatureAfterCallToInit(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
TemperatureFilter_ProcessInput(17.8f);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, 17.8f, TemperatureFilter_GetTemperatureInCelcius());
|
||||
|
||||
TemperatureFilter_Init();
|
||||
TemperatureFilter_ProcessInput(32.6f);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, 32.6f, TemperatureFilter_GetTemperatureInCelcius());
|
||||
}
|
||||
|
||||
void setValueAndVerifyResponse(float input, float response)
|
||||
{
|
||||
float actual;
|
||||
TemperatureFilter_ProcessInput(input);
|
||||
actual = TemperatureFilter_GetTemperatureInCelcius();
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, response, actual);
|
||||
}
|
||||
|
||||
void testShouldWeightEachSubsequentValueBy25PercentAfterInitialValue(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
setValueAndVerifyResponse(0.0f, 0.0f);
|
||||
setValueAndVerifyResponse(10.0f, 2.5f);
|
||||
setValueAndVerifyResponse(10.0f, 4.375f);
|
||||
setValueAndVerifyResponse(10.0f, 5.78125f);
|
||||
|
||||
TemperatureFilter_Init();
|
||||
setValueAndVerifyResponse(100.0f, 100.0f);
|
||||
setValueAndVerifyResponse(0.0f, 75.0f);
|
||||
setValueAndVerifyResponse(0.0f, 56.25f);
|
||||
setValueAndVerifyResponse(0.0f, 42.1875f);
|
||||
}
|
||||
|
||||
void setInvalidTemperatureAndVerifyReinitialized(float invalidTemperature)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
setValueAndVerifyResponse(100.0f, 100.0f);
|
||||
setValueAndVerifyResponse(invalidTemperature, -INFINITY);
|
||||
setValueAndVerifyResponse(14.3f, 14.3f);
|
||||
}
|
||||
|
||||
void testShouldResetAverageIfPassedInfinityOrInvalidValue(void)
|
||||
{
|
||||
setInvalidTemperatureAndVerifyReinitialized(-INFINITY);
|
||||
setInvalidTemperatureAndVerifyReinitialized(+INFINITY);
|
||||
setInvalidTemperatureAndVerifyReinitialized(+NAN);
|
||||
setInvalidTemperatureAndVerifyReinitialized(-NAN);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TemperatureFilter.h"
|
||||
#include <math.h>
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldInitializeTemeratureToInvalidValue(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, -INFINITY, TemperatureFilter_GetTemperatureInCelcius());
|
||||
}
|
||||
|
||||
void testShouldInitializeTemperatureAfterCallToInit(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
TemperatureFilter_ProcessInput(17.8f);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, 17.8f, TemperatureFilter_GetTemperatureInCelcius());
|
||||
|
||||
TemperatureFilter_Init();
|
||||
TemperatureFilter_ProcessInput(32.6f);
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, 32.6f, TemperatureFilter_GetTemperatureInCelcius());
|
||||
}
|
||||
|
||||
void setValueAndVerifyResponse(float input, float response)
|
||||
{
|
||||
float actual;
|
||||
TemperatureFilter_ProcessInput(input);
|
||||
actual = TemperatureFilter_GetTemperatureInCelcius();
|
||||
TEST_ASSERT_FLOAT_WITHIN(0.0001f, response, actual);
|
||||
}
|
||||
|
||||
void testShouldWeightEachSubsequentValueBy25PercentAfterInitialValue(void)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
setValueAndVerifyResponse(0.0f, 0.0f);
|
||||
setValueAndVerifyResponse(10.0f, 2.5f);
|
||||
setValueAndVerifyResponse(10.0f, 4.375f);
|
||||
setValueAndVerifyResponse(10.0f, 5.78125f);
|
||||
|
||||
TemperatureFilter_Init();
|
||||
setValueAndVerifyResponse(100.0f, 100.0f);
|
||||
setValueAndVerifyResponse(0.0f, 75.0f);
|
||||
setValueAndVerifyResponse(0.0f, 56.25f);
|
||||
setValueAndVerifyResponse(0.0f, 42.1875f);
|
||||
}
|
||||
|
||||
void setInvalidTemperatureAndVerifyReinitialized(float invalidTemperature)
|
||||
{
|
||||
TemperatureFilter_Init();
|
||||
setValueAndVerifyResponse(100.0f, 100.0f);
|
||||
setValueAndVerifyResponse(invalidTemperature, -INFINITY);
|
||||
setValueAndVerifyResponse(14.3f, 14.3f);
|
||||
}
|
||||
|
||||
void testShouldResetAverageIfPassedInfinityOrInvalidValue(void)
|
||||
{
|
||||
setInvalidTemperatureAndVerifyReinitialized(-INFINITY);
|
||||
setInvalidTemperatureAndVerifyReinitialized(+INFINITY);
|
||||
setInvalidTemperatureAndVerifyReinitialized(+NAN);
|
||||
setInvalidTemperatureAndVerifyReinitialized(-NAN);
|
||||
}
|
||||
|
||||
@@ -1,32 +1,32 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerConductor.h"
|
||||
#include "MockTimerHardware.h"
|
||||
#include "MockTimerModel.h"
|
||||
#include "MockTimerInterruptHandler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallHardwareInit(void)
|
||||
{
|
||||
TimerHardware_Init_Expect();
|
||||
|
||||
TimerConductor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldGetSystemTimeAndPassOnToModelForEventScheduling(void)
|
||||
{
|
||||
Timer_GetSystemTime_ExpectAndReturn(1230);
|
||||
TimerModel_UpdateTime_Expect(1230);
|
||||
TimerConductor_Run();
|
||||
|
||||
Timer_GetSystemTime_ExpectAndReturn(837460);
|
||||
TimerModel_UpdateTime_Expect(837460);
|
||||
TimerConductor_Run();
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerConductor.h"
|
||||
#include "MockTimerHardware.h"
|
||||
#include "MockTimerModel.h"
|
||||
#include "MockTimerInterruptHandler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldCallHardwareInit(void)
|
||||
{
|
||||
TimerHardware_Init_Expect();
|
||||
|
||||
TimerConductor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldGetSystemTimeAndPassOnToModelForEventScheduling(void)
|
||||
{
|
||||
Timer_GetSystemTime_ExpectAndReturn(1230);
|
||||
TimerModel_UpdateTime_Expect(1230);
|
||||
TimerConductor_Run();
|
||||
|
||||
Timer_GetSystemTime_ExpectAndReturn(837460);
|
||||
TimerModel_UpdateTime_Expect(837460);
|
||||
TimerConductor_Run();
|
||||
}
|
||||
|
||||
@@ -1,112 +1,112 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerConfigurator.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
#include "MockTimerInterruptConfigurator.h"
|
||||
|
||||
AT91S_PMC PmcPeripheral;
|
||||
AT91S_TC TimerCounter0Peripheral;
|
||||
AT91S_PIO PioBPeripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testEnablePeripheralClocksShouldEnableClockToTimer0Peripheral(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = 0;
|
||||
Timer_EnablePeripheralClocks();
|
||||
TEST_ASSERT_EQUAL(
|
||||
TIMER0_CLOCK_ENABLE,
|
||||
AT91C_BASE_PMC->PMC_PCER & TIMER0_CLOCK_ENABLE);
|
||||
}
|
||||
|
||||
void testEnablePeripheralClocksShouldEnableClockToPIOBPeripheral(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = 0;
|
||||
Timer_EnablePeripheralClocks();
|
||||
TEST_ASSERT_EQUAL(
|
||||
PIOB_CLOCK_ENABLE,
|
||||
AT91C_BASE_PMC->PMC_PCER & PIOB_CLOCK_ENABLE);
|
||||
}
|
||||
|
||||
void testResetShouldSetTimer0ClockDisableBit_DisableTimer0Interrupts_ClearStatusRegister(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = 0;
|
||||
AT91C_BASE_TC0->TC_IDR = 0;
|
||||
AT91C_BASE_TC0->TC_SR = 0xFFFFFFFF;
|
||||
Timer_Reset();
|
||||
TEST_ASSERT_EQUAL(0x00000002, AT91C_BASE_TC0->TC_CCR);
|
||||
TEST_ASSERT_EQUAL(0xffffffff, AT91C_BASE_TC0->TC_IDR);
|
||||
// CANNOT BE VERIFIED!! TEST_ASSERT_EQUAL(0X00000000, AT91C_BASE_TC0->TC_SR);
|
||||
}
|
||||
|
||||
void testEnableOutputPinShouldEnable_TIOA0_DigitalOutput(void)
|
||||
{
|
||||
AT91C_BASE_PIOB->PIO_PDR = 0;
|
||||
Timer_EnableOutputPin();
|
||||
TEST_ASSERT_EQUAL(TIOA0_PIN_MASK, AT91C_BASE_PIOB->PIO_PDR);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ClockSourceForMasterClockDividedBy1024(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x00000004, AT91C_BASE_TC0->TC_CMR & 0x00000007);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ForWaveGeneration(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x00008000, AT91C_BASE_TC0->TC_CMR & 0x00008000);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ForUpModeWithAutomaticTriggerOnRCCompare(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x00004000, AT91C_BASE_TC0->TC_CMR & 0x00006000);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ToToggleTIOAOnRCCompare(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x000C0000, AT91C_BASE_TC0->TC_CMR & 0x000C0000);
|
||||
}
|
||||
|
||||
void testConfigurePeriodShouldConfigureRegisterCFor10msInterval(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_RC = 0;
|
||||
Timer_ConfigurePeriod();
|
||||
TEST_ASSERT_EQUAL(469, AT91C_BASE_TC0->TC_RC);
|
||||
}
|
||||
|
||||
void testEnableShouldSetEnableFlagForTimer0(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = 0;
|
||||
Timer_Enable();
|
||||
TEST_ASSERT_EQUAL_INT(1, AT91C_BASE_TC0->TC_CCR);
|
||||
}
|
||||
|
||||
void testConfigureInterruptHandler(void)
|
||||
{
|
||||
Timer_DisableInterrupt_Expect();
|
||||
Timer_ResetSystemTime_Expect();
|
||||
Timer_ConfigureInterrupt_Expect();
|
||||
Timer_EnableInterrupt_Expect();
|
||||
|
||||
Timer_ConfigureInterruptHandler();
|
||||
}
|
||||
|
||||
void testStartShouldSetSoftwareTriggerFlag(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = 0;
|
||||
Timer_Start();
|
||||
TEST_ASSERT_EQUAL(0x04, AT91C_BASE_TC0->TC_CCR);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerConfigurator.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
#include "MockTimerInterruptConfigurator.h"
|
||||
|
||||
AT91S_PMC PmcPeripheral;
|
||||
AT91S_TC TimerCounter0Peripheral;
|
||||
AT91S_PIO PioBPeripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testEnablePeripheralClocksShouldEnableClockToTimer0Peripheral(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = 0;
|
||||
Timer_EnablePeripheralClocks();
|
||||
TEST_ASSERT_EQUAL(
|
||||
TIMER0_CLOCK_ENABLE,
|
||||
AT91C_BASE_PMC->PMC_PCER & TIMER0_CLOCK_ENABLE);
|
||||
}
|
||||
|
||||
void testEnablePeripheralClocksShouldEnableClockToPIOBPeripheral(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = 0;
|
||||
Timer_EnablePeripheralClocks();
|
||||
TEST_ASSERT_EQUAL(
|
||||
PIOB_CLOCK_ENABLE,
|
||||
AT91C_BASE_PMC->PMC_PCER & PIOB_CLOCK_ENABLE);
|
||||
}
|
||||
|
||||
void testResetShouldSetTimer0ClockDisableBit_DisableTimer0Interrupts_ClearStatusRegister(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = 0;
|
||||
AT91C_BASE_TC0->TC_IDR = 0;
|
||||
AT91C_BASE_TC0->TC_SR = 0xFFFFFFFF;
|
||||
Timer_Reset();
|
||||
TEST_ASSERT_EQUAL(0x00000002, AT91C_BASE_TC0->TC_CCR);
|
||||
TEST_ASSERT_EQUAL(0xffffffff, AT91C_BASE_TC0->TC_IDR);
|
||||
// CANNOT BE VERIFIED!! TEST_ASSERT_EQUAL(0X00000000, AT91C_BASE_TC0->TC_SR);
|
||||
}
|
||||
|
||||
void testEnableOutputPinShouldEnable_TIOA0_DigitalOutput(void)
|
||||
{
|
||||
AT91C_BASE_PIOB->PIO_PDR = 0;
|
||||
Timer_EnableOutputPin();
|
||||
TEST_ASSERT_EQUAL(TIOA0_PIN_MASK, AT91C_BASE_PIOB->PIO_PDR);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ClockSourceForMasterClockDividedBy1024(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x00000004, AT91C_BASE_TC0->TC_CMR & 0x00000007);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ForWaveGeneration(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x00008000, AT91C_BASE_TC0->TC_CMR & 0x00008000);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ForUpModeWithAutomaticTriggerOnRCCompare(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x00004000, AT91C_BASE_TC0->TC_CMR & 0x00006000);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldConfigureTimer0ToToggleTIOAOnRCCompare(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CMR = 0;
|
||||
Timer_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(0x000C0000, AT91C_BASE_TC0->TC_CMR & 0x000C0000);
|
||||
}
|
||||
|
||||
void testConfigurePeriodShouldConfigureRegisterCFor10msInterval(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_RC = 0;
|
||||
Timer_ConfigurePeriod();
|
||||
TEST_ASSERT_EQUAL(469, AT91C_BASE_TC0->TC_RC);
|
||||
}
|
||||
|
||||
void testEnableShouldSetEnableFlagForTimer0(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = 0;
|
||||
Timer_Enable();
|
||||
TEST_ASSERT_EQUAL_INT(1, AT91C_BASE_TC0->TC_CCR);
|
||||
}
|
||||
|
||||
void testConfigureInterruptHandler(void)
|
||||
{
|
||||
Timer_DisableInterrupt_Expect();
|
||||
Timer_ResetSystemTime_Expect();
|
||||
Timer_ConfigureInterrupt_Expect();
|
||||
Timer_EnableInterrupt_Expect();
|
||||
|
||||
Timer_ConfigureInterruptHandler();
|
||||
}
|
||||
|
||||
void testStartShouldSetSoftwareTriggerFlag(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_CCR = 0;
|
||||
Timer_Start();
|
||||
TEST_ASSERT_EQUAL(0x04, AT91C_BASE_TC0->TC_CCR);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerHardware.h"
|
||||
#include "MockTimerConfigurator.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldDelegateAppropriatelyToConfigurator(void)
|
||||
{
|
||||
Timer_EnablePeripheralClocks_Expect();
|
||||
Timer_Reset_Expect();
|
||||
Timer_ConfigureMode_Expect();
|
||||
Timer_ConfigurePeriod_Expect();
|
||||
Timer_EnableOutputPin_Expect();
|
||||
Timer_Enable_Expect();
|
||||
Timer_ConfigureInterruptHandler_Expect();
|
||||
Timer_Start_Expect();
|
||||
|
||||
TimerHardware_Init();
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerHardware.h"
|
||||
#include "MockTimerConfigurator.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldDelegateAppropriatelyToConfigurator(void)
|
||||
{
|
||||
Timer_EnablePeripheralClocks_Expect();
|
||||
Timer_Reset_Expect();
|
||||
Timer_ConfigureMode_Expect();
|
||||
Timer_ConfigurePeriod_Expect();
|
||||
Timer_EnableOutputPin_Expect();
|
||||
Timer_Enable_Expect();
|
||||
Timer_ConfigureInterruptHandler_Expect();
|
||||
Timer_Start_Expect();
|
||||
|
||||
TimerHardware_Init();
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerInterruptConfigurator.h"
|
||||
#include "MockTimerInterruptHandler.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
|
||||
AT91S_AIC AicPeripheral;
|
||||
AT91S_TC TimerCounter0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void test_TIMER0_ID_MASK_ShouldBeCorrect(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(((uint32)0x1) << AT91C_ID_TC0, TIMER0_ID_MASK);
|
||||
}
|
||||
|
||||
void testDisableInterruptDisablesTimer0InterruptInTheInterruptController(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IDCR = 0;
|
||||
Timer_DisableInterrupt();
|
||||
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_IDCR);
|
||||
}
|
||||
|
||||
void testResetSystemTimeDelegatesTo_Timer_SetSystemTime_Appropriately(void)
|
||||
{
|
||||
Timer_SetSystemTime_Expect(0);
|
||||
Timer_ResetSystemTime();
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldSetInterruptHandlerAppropriately(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (uint32)NULL;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL((uint32)Timer_InterruptHandler, AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0]);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldSetInterruptLevelInSourceModeRegisterAppropriately(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(
|
||||
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL,
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] & 0x00000060);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldSetInterruptPriorityInSourceModeRegisterAppropriately(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(1, AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] & 0x00000007);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldClearTimer0InterruptOnTheInterruptController(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_ICCR = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_ICCR);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldEnableCompareInterruptForRegisterC(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_IER = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(AT91C_TC_CPCS, AT91C_BASE_TC0->TC_IER);
|
||||
}
|
||||
|
||||
void testEnableInterruptShouldEnableTimer0InterruptsInInterruptCotroller(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IECR = 0;
|
||||
Timer_EnableInterrupt();
|
||||
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_IECR);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerInterruptConfigurator.h"
|
||||
#include "MockTimerInterruptHandler.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
|
||||
AT91S_AIC AicPeripheral;
|
||||
AT91S_TC TimerCounter0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void test_TIMER0_ID_MASK_ShouldBeCorrect(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL(((uint32)0x1) << AT91C_ID_TC0, TIMER0_ID_MASK);
|
||||
}
|
||||
|
||||
void testDisableInterruptDisablesTimer0InterruptInTheInterruptController(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IDCR = 0;
|
||||
Timer_DisableInterrupt();
|
||||
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_IDCR);
|
||||
}
|
||||
|
||||
void testResetSystemTimeDelegatesTo_Timer_SetSystemTime_Appropriately(void)
|
||||
{
|
||||
Timer_SetSystemTime_Expect(0);
|
||||
Timer_ResetSystemTime();
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldSetInterruptHandlerAppropriately(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0] = (uint32)NULL;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL((uint32)Timer_InterruptHandler, AT91C_BASE_AIC->AIC_SVR[AT91C_ID_TC0]);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldSetInterruptLevelInSourceModeRegisterAppropriately(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(
|
||||
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL,
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] & 0x00000060);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldSetInterruptPriorityInSourceModeRegisterAppropriately(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(1, AT91C_BASE_AIC->AIC_SMR[AT91C_ID_TC0] & 0x00000007);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldClearTimer0InterruptOnTheInterruptController(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_ICCR = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_ICCR);
|
||||
}
|
||||
|
||||
void testConfigureInterruptShouldEnableCompareInterruptForRegisterC(void)
|
||||
{
|
||||
AT91C_BASE_TC0->TC_IER = 0;
|
||||
Timer_ConfigureInterrupt();
|
||||
TEST_ASSERT_EQUAL(AT91C_TC_CPCS, AT91C_BASE_TC0->TC_IER);
|
||||
}
|
||||
|
||||
void testEnableInterruptShouldEnableTimer0InterruptsInInterruptCotroller(void)
|
||||
{
|
||||
AT91C_BASE_AIC->AIC_IECR = 0;
|
||||
Timer_EnableInterrupt();
|
||||
TEST_ASSERT_EQUAL(TIMER0_ID_MASK, AT91C_BASE_AIC->AIC_IECR);
|
||||
}
|
||||
|
||||
@@ -1,66 +1,66 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerInterruptHandler.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
|
||||
AT91S_TC TimerCounter0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testSetAndGetSystemTime(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(129837);
|
||||
TEST_ASSERT_EQUAL(129837, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(UINT32_MAX);
|
||||
TEST_ASSERT_EQUAL(UINT32_MAX, Timer_GetSystemTime());
|
||||
}
|
||||
|
||||
void testInterruptHandlerShouldIncrementSystemTimeOnlyIfStatusHasCompareRegisterCOverflowBitSet(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = 0;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = ~AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT(Timer_GetSystemTime() > 0);
|
||||
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = 0xffffffff;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT(Timer_GetSystemTime() > 0);
|
||||
}
|
||||
|
||||
void testInterruptHandlerShouldIncrementSystemTimerBy_10(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(10, Timer_GetSystemTime());
|
||||
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(20, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(39426857);
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(39426867, Timer_GetSystemTime());
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerInterruptHandler.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
|
||||
AT91S_TC TimerCounter0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testSetAndGetSystemTime(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(129837);
|
||||
TEST_ASSERT_EQUAL(129837, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(UINT32_MAX);
|
||||
TEST_ASSERT_EQUAL(UINT32_MAX, Timer_GetSystemTime());
|
||||
}
|
||||
|
||||
void testInterruptHandlerShouldIncrementSystemTimeOnlyIfStatusHasCompareRegisterCOverflowBitSet(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = 0;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = ~AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(0, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT(Timer_GetSystemTime() > 0);
|
||||
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = 0xffffffff;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT(Timer_GetSystemTime() > 0);
|
||||
}
|
||||
|
||||
void testInterruptHandlerShouldIncrementSystemTimerBy_10(void)
|
||||
{
|
||||
Timer_SetSystemTime(0);
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(10, Timer_GetSystemTime());
|
||||
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(20, Timer_GetSystemTime());
|
||||
|
||||
Timer_SetSystemTime(39426857);
|
||||
AT91C_BASE_TC0->TC_SR = AT91C_TC_CPCS;
|
||||
Timer_InterruptHandler();
|
||||
TEST_ASSERT_EQUAL(39426867, Timer_GetSystemTime());
|
||||
}
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerModel.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testUpdateTimeShouldDelegateToTaskScheduler(void)
|
||||
{
|
||||
TaskScheduler_Update_Expect(19387L);
|
||||
TimerModel_UpdateTime(19387L);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "TimerModel.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testUpdateTimeShouldDelegateToTaskScheduler(void)
|
||||
{
|
||||
TaskScheduler_Update_Expect(19387L);
|
||||
TimerModel_UpdateTime(19387L);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartBaudRateRegisterCalculator.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testCalculateBaudRateRegisterSettingShouldCalculateRegisterSettingAppropriately(void)
|
||||
{
|
||||
// BaudRate = MCK / (CD x 16) - per datasheet section 30.6.1.2 "Baud Rate Calculation Example"
|
||||
TEST_ASSERT_EQUAL(26, UsartModel_CalculateBaudRateRegisterSetting(48000000, 115200));
|
||||
TEST_ASSERT_EQUAL(6, UsartModel_CalculateBaudRateRegisterSetting(3686400, 38400));
|
||||
TEST_ASSERT_EQUAL(23, UsartModel_CalculateBaudRateRegisterSetting(14318180, 38400));
|
||||
TEST_ASSERT_EQUAL(20, UsartModel_CalculateBaudRateRegisterSetting(12000000, 38400));
|
||||
TEST_ASSERT_EQUAL(13, UsartModel_CalculateBaudRateRegisterSetting(12000000, 56800));
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartBaudRateRegisterCalculator.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testCalculateBaudRateRegisterSettingShouldCalculateRegisterSettingAppropriately(void)
|
||||
{
|
||||
// BaudRate = MCK / (CD x 16) - per datasheet section 30.6.1.2 "Baud Rate Calculation Example"
|
||||
TEST_ASSERT_EQUAL(26, UsartModel_CalculateBaudRateRegisterSetting(48000000, 115200));
|
||||
TEST_ASSERT_EQUAL(6, UsartModel_CalculateBaudRateRegisterSetting(3686400, 38400));
|
||||
TEST_ASSERT_EQUAL(23, UsartModel_CalculateBaudRateRegisterSetting(14318180, 38400));
|
||||
TEST_ASSERT_EQUAL(20, UsartModel_CalculateBaudRateRegisterSetting(12000000, 38400));
|
||||
TEST_ASSERT_EQUAL(13, UsartModel_CalculateBaudRateRegisterSetting(12000000, 56800));
|
||||
}
|
||||
|
||||
@@ -1,40 +1,40 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartConductor.h"
|
||||
#include "MockUsartModel.h"
|
||||
#include "MockUsartHardware.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldInitializeHardwareWhenInitCalled(void)
|
||||
{
|
||||
UsartModel_GetBaudRateRegisterSetting_ExpectAndReturn(4);
|
||||
UsartModel_GetWakeupMessage_ExpectAndReturn("Hey there!");
|
||||
UsartHardware_TransmitString_Expect("Hey there!");
|
||||
UsartHardware_Init_Expect(4);
|
||||
|
||||
UsartConductor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldNotDoAnythingIfSchedulerSaysItIsNotTimeYet(void)
|
||||
{
|
||||
TaskScheduler_DoUsart_ExpectAndReturn(FALSE);
|
||||
|
||||
UsartConductor_Run();
|
||||
}
|
||||
|
||||
void testRunShouldGetCurrentTemperatureAndTransmitIfSchedulerSaysItIsTime(void)
|
||||
{
|
||||
TaskScheduler_DoUsart_ExpectAndReturn(TRUE);
|
||||
UsartModel_GetFormattedTemperature_ExpectAndReturn("hey there");
|
||||
UsartHardware_TransmitString_Expect("hey there");
|
||||
|
||||
UsartConductor_Run();
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartConductor.h"
|
||||
#include "MockUsartModel.h"
|
||||
#include "MockUsartHardware.h"
|
||||
#include "MockTaskScheduler.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testShouldInitializeHardwareWhenInitCalled(void)
|
||||
{
|
||||
UsartModel_GetBaudRateRegisterSetting_ExpectAndReturn(4);
|
||||
UsartModel_GetWakeupMessage_ExpectAndReturn("Hey there!");
|
||||
UsartHardware_TransmitString_Expect("Hey there!");
|
||||
UsartHardware_Init_Expect(4);
|
||||
|
||||
UsartConductor_Init();
|
||||
}
|
||||
|
||||
void testRunShouldNotDoAnythingIfSchedulerSaysItIsNotTimeYet(void)
|
||||
{
|
||||
TaskScheduler_DoUsart_ExpectAndReturn(FALSE);
|
||||
|
||||
UsartConductor_Run();
|
||||
}
|
||||
|
||||
void testRunShouldGetCurrentTemperatureAndTransmitIfSchedulerSaysItIsTime(void)
|
||||
{
|
||||
TaskScheduler_DoUsart_ExpectAndReturn(TRUE);
|
||||
UsartModel_GetFormattedTemperature_ExpectAndReturn("hey there");
|
||||
UsartHardware_TransmitString_Expect("hey there");
|
||||
|
||||
UsartConductor_Run();
|
||||
}
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartConfigurator.h"
|
||||
|
||||
AT91S_PIO PioAPeripheral;
|
||||
AT91S_PMC PmcPeripheral;
|
||||
AT91S_USART Usart0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testConfigureUsartIOShouldConfigureUsartTxPinfForPeripheralIO(void)
|
||||
{
|
||||
AT91C_BASE_PIOA->PIO_ASR = 0;
|
||||
AT91C_BASE_PIOA->PIO_BSR = 0xffffffff;
|
||||
AT91C_BASE_PIOA->PIO_PDR = 0;
|
||||
Usart_ConfigureUsartIO();
|
||||
TEST_ASSERT_EQUAL(USART0_TX_PIN, AT91C_BASE_PIOA->PIO_ASR);
|
||||
TEST_ASSERT_EQUAL(0, AT91C_BASE_PIOA->PIO_BSR);
|
||||
TEST_ASSERT_EQUAL(USART0_TX_PIN, AT91C_BASE_PIOA->PIO_PDR);
|
||||
}
|
||||
|
||||
void testEnablePeripheralClockShouldEnableClockToUsartPeripheral(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = 0;
|
||||
Usart_EnablePeripheralClock();
|
||||
TEST_ASSERT_EQUAL(((uint32)1) << USART0_CLOCK_ENABLE, AT91C_BASE_PMC->PMC_PCER);
|
||||
}
|
||||
|
||||
void testResetShouldDisableAllUsartInterrupts(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_IDR = 0;
|
||||
Usart_Reset();
|
||||
TEST_ASSERT_EQUAL(0xffffffff, AT91C_BASE_US0->US_IDR);
|
||||
}
|
||||
|
||||
void testResetShouldResetUsartTransmitterAndReceiver(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CR = 0;
|
||||
Usart_Reset();
|
||||
TEST_ASSERT_EQUAL(AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS, AT91C_BASE_US0->US_CR);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldSetUsartModeToAsynchronous(void)
|
||||
{
|
||||
uint32 asyncMode = (AT91C_US_USMODE_NORMAL |
|
||||
AT91C_US_NBSTOP_1_BIT |
|
||||
AT91C_US_PAR_NONE |
|
||||
AT91C_US_CHRL_8_BITS |
|
||||
AT91C_US_CLKS_CLOCK);
|
||||
|
||||
AT91C_BASE_US0->US_MR = ~asyncMode;
|
||||
Usart_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(asyncMode, AT91C_BASE_US0->US_MR);
|
||||
}
|
||||
|
||||
void testSetBaudRateRegisterShouldSetUsartBaudRateRegisterToValuePassedAsParameter(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_BRGR = 0;
|
||||
Usart_SetBaudRateRegister(3);
|
||||
TEST_ASSERT_EQUAL(3, AT91C_BASE_US0->US_BRGR);
|
||||
Usart_SetBaudRateRegister(251);
|
||||
TEST_ASSERT_EQUAL(251, AT91C_BASE_US0->US_BRGR);
|
||||
}
|
||||
|
||||
|
||||
void testEnableShouldEnableUsart0Transmitter(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CR = 0;
|
||||
Usart_Enable();
|
||||
TEST_ASSERT_EQUAL(AT91C_US_TXEN, AT91C_BASE_US0->US_CR);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartConfigurator.h"
|
||||
|
||||
AT91S_PIO PioAPeripheral;
|
||||
AT91S_PMC PmcPeripheral;
|
||||
AT91S_USART Usart0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testConfigureUsartIOShouldConfigureUsartTxPinfForPeripheralIO(void)
|
||||
{
|
||||
AT91C_BASE_PIOA->PIO_ASR = 0;
|
||||
AT91C_BASE_PIOA->PIO_BSR = 0xffffffff;
|
||||
AT91C_BASE_PIOA->PIO_PDR = 0;
|
||||
Usart_ConfigureUsartIO();
|
||||
TEST_ASSERT_EQUAL(USART0_TX_PIN, AT91C_BASE_PIOA->PIO_ASR);
|
||||
TEST_ASSERT_EQUAL(0, AT91C_BASE_PIOA->PIO_BSR);
|
||||
TEST_ASSERT_EQUAL(USART0_TX_PIN, AT91C_BASE_PIOA->PIO_PDR);
|
||||
}
|
||||
|
||||
void testEnablePeripheralClockShouldEnableClockToUsartPeripheral(void)
|
||||
{
|
||||
AT91C_BASE_PMC->PMC_PCER = 0;
|
||||
Usart_EnablePeripheralClock();
|
||||
TEST_ASSERT_EQUAL(((uint32)1) << USART0_CLOCK_ENABLE, AT91C_BASE_PMC->PMC_PCER);
|
||||
}
|
||||
|
||||
void testResetShouldDisableAllUsartInterrupts(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_IDR = 0;
|
||||
Usart_Reset();
|
||||
TEST_ASSERT_EQUAL(0xffffffff, AT91C_BASE_US0->US_IDR);
|
||||
}
|
||||
|
||||
void testResetShouldResetUsartTransmitterAndReceiver(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CR = 0;
|
||||
Usart_Reset();
|
||||
TEST_ASSERT_EQUAL(AT91C_US_RSTRX | AT91C_US_RSTTX | AT91C_US_RXDIS | AT91C_US_TXDIS, AT91C_BASE_US0->US_CR);
|
||||
}
|
||||
|
||||
void testConfigureModeShouldSetUsartModeToAsynchronous(void)
|
||||
{
|
||||
uint32 asyncMode = (AT91C_US_USMODE_NORMAL |
|
||||
AT91C_US_NBSTOP_1_BIT |
|
||||
AT91C_US_PAR_NONE |
|
||||
AT91C_US_CHRL_8_BITS |
|
||||
AT91C_US_CLKS_CLOCK);
|
||||
|
||||
AT91C_BASE_US0->US_MR = ~asyncMode;
|
||||
Usart_ConfigureMode();
|
||||
TEST_ASSERT_EQUAL(asyncMode, AT91C_BASE_US0->US_MR);
|
||||
}
|
||||
|
||||
void testSetBaudRateRegisterShouldSetUsartBaudRateRegisterToValuePassedAsParameter(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_BRGR = 0;
|
||||
Usart_SetBaudRateRegister(3);
|
||||
TEST_ASSERT_EQUAL(3, AT91C_BASE_US0->US_BRGR);
|
||||
Usart_SetBaudRateRegister(251);
|
||||
TEST_ASSERT_EQUAL(251, AT91C_BASE_US0->US_BRGR);
|
||||
}
|
||||
|
||||
|
||||
void testEnableShouldEnableUsart0Transmitter(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CR = 0;
|
||||
Usart_Enable();
|
||||
TEST_ASSERT_EQUAL(AT91C_US_TXEN, AT91C_BASE_US0->US_CR);
|
||||
}
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartHardware.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
#include "MockUsartConfigurator.h"
|
||||
#include "MockUsartPutChar.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldConfigureUsartPeripheralByCallingConfiguratorAppropriately(void)
|
||||
{
|
||||
Usart_ConfigureUsartIO_Expect();
|
||||
Usart_EnablePeripheralClock_Expect();
|
||||
Usart_Reset_Expect();
|
||||
Usart_ConfigureMode_Expect();
|
||||
Usart_SetBaudRateRegister_Expect(73);
|
||||
Usart_Enable_Expect();
|
||||
|
||||
UsartHardware_Init(73);
|
||||
}
|
||||
|
||||
void testTransmitStringShouldSendDesiredStringOutUsingUsart(void)
|
||||
{
|
||||
Usart_PutChar_Expect('h');
|
||||
Usart_PutChar_Expect('e');
|
||||
Usart_PutChar_Expect('l');
|
||||
Usart_PutChar_Expect('l');
|
||||
Usart_PutChar_Expect('o');
|
||||
|
||||
UsartHardware_TransmitString("hello");
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartHardware.h"
|
||||
#include "AT91SAM7X256.h"
|
||||
#include "MockUsartConfigurator.h"
|
||||
#include "MockUsartPutChar.h"
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testInitShouldConfigureUsartPeripheralByCallingConfiguratorAppropriately(void)
|
||||
{
|
||||
Usart_ConfigureUsartIO_Expect();
|
||||
Usart_EnablePeripheralClock_Expect();
|
||||
Usart_Reset_Expect();
|
||||
Usart_ConfigureMode_Expect();
|
||||
Usart_SetBaudRateRegister_Expect(73);
|
||||
Usart_Enable_Expect();
|
||||
|
||||
UsartHardware_Init(73);
|
||||
}
|
||||
|
||||
void testTransmitStringShouldSendDesiredStringOutUsingUsart(void)
|
||||
{
|
||||
Usart_PutChar_Expect('h');
|
||||
Usart_PutChar_Expect('e');
|
||||
Usart_PutChar_Expect('l');
|
||||
Usart_PutChar_Expect('l');
|
||||
Usart_PutChar_Expect('o');
|
||||
|
||||
UsartHardware_TransmitString("hello");
|
||||
}
|
||||
|
||||
@@ -1,39 +1,39 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartModel.h"
|
||||
#include "ModelConfig.h"
|
||||
#include "MockTemperatureFilter.h"
|
||||
#include "MockUsartBaudRateRegisterCalculator.h"
|
||||
#include <math.h>
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testGetBaudRateRegisterSettingShouldReturnAppropriateBaudRateRegisterSetting(void)
|
||||
{
|
||||
uint8 dummyRegisterSetting = 17;
|
||||
UsartModel_CalculateBaudRateRegisterSetting_ExpectAndReturn(MASTER_CLOCK, USART0_BAUDRATE, dummyRegisterSetting);
|
||||
|
||||
TEST_ASSERT_EQUAL(dummyRegisterSetting, UsartModel_GetBaudRateRegisterSetting());
|
||||
}
|
||||
|
||||
void testGetFormattedTemperatureFormatsTemperatureFromCalculatorAppropriately(void)
|
||||
{
|
||||
TemperatureFilter_GetTemperatureInCelcius_ExpectAndReturn(25.0f);
|
||||
TEST_ASSERT_EQUAL_STRING("25.0 C\n", UsartModel_GetFormattedTemperature());
|
||||
}
|
||||
|
||||
void testShouldReturnErrorMessageUponInvalidTemperatureValue(void)
|
||||
{
|
||||
TemperatureFilter_GetTemperatureInCelcius_ExpectAndReturn(-INFINITY);
|
||||
TEST_ASSERT_EQUAL_STRING("Temperature sensor failure!\n", UsartModel_GetFormattedTemperature());
|
||||
}
|
||||
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartModel.h"
|
||||
#include "ModelConfig.h"
|
||||
#include "MockTemperatureFilter.h"
|
||||
#include "MockUsartBaudRateRegisterCalculator.h"
|
||||
#include <math.h>
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testGetBaudRateRegisterSettingShouldReturnAppropriateBaudRateRegisterSetting(void)
|
||||
{
|
||||
uint8 dummyRegisterSetting = 17;
|
||||
UsartModel_CalculateBaudRateRegisterSetting_ExpectAndReturn(MASTER_CLOCK, USART0_BAUDRATE, dummyRegisterSetting);
|
||||
|
||||
TEST_ASSERT_EQUAL(dummyRegisterSetting, UsartModel_GetBaudRateRegisterSetting());
|
||||
}
|
||||
|
||||
void testGetFormattedTemperatureFormatsTemperatureFromCalculatorAppropriately(void)
|
||||
{
|
||||
TemperatureFilter_GetTemperatureInCelcius_ExpectAndReturn(25.0f);
|
||||
TEST_ASSERT_EQUAL_STRING("25.0 C\n", UsartModel_GetFormattedTemperature());
|
||||
}
|
||||
|
||||
void testShouldReturnErrorMessageUponInvalidTemperatureValue(void)
|
||||
{
|
||||
TemperatureFilter_GetTemperatureInCelcius_ExpectAndReturn(-INFINITY);
|
||||
TEST_ASSERT_EQUAL_STRING("Temperature sensor failure!\n", UsartModel_GetFormattedTemperature());
|
||||
}
|
||||
|
||||
void testShouldReturnWakeupMessage(void)
|
||||
{
|
||||
TEST_ASSERT_EQUAL_STRING("It's Awesome Time!\n", UsartModel_GetWakeupMessage());
|
||||
|
||||
@@ -1,43 +1,43 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartPutChar.h"
|
||||
#include "MockUsartTransmitBufferStatus.h"
|
||||
|
||||
AT91S_USART Usart0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testPutCharShouldWriteDesiredCharacterToUsartTransmitBuffer(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_THR = 0;
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar('x');
|
||||
TEST_ASSERT_EQUAL('x', AT91C_BASE_US0->US_THR);
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar('1');
|
||||
TEST_ASSERT_EQUAL('1', AT91C_BASE_US0->US_THR);
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar(':');
|
||||
TEST_ASSERT_EQUAL(':', AT91C_BASE_US0->US_THR);
|
||||
}
|
||||
|
||||
void testPutCharShouldWaitUntilReadyToTransmitBeforeLoadingTransmitBufffer(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_THR = 0;
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar('x');
|
||||
TEST_ASSERT_EQUAL('x', AT91C_BASE_US0->US_THR);
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartPutChar.h"
|
||||
#include "MockUsartTransmitBufferStatus.h"
|
||||
|
||||
AT91S_USART Usart0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testPutCharShouldWriteDesiredCharacterToUsartTransmitBuffer(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_THR = 0;
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar('x');
|
||||
TEST_ASSERT_EQUAL('x', AT91C_BASE_US0->US_THR);
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar('1');
|
||||
TEST_ASSERT_EQUAL('1', AT91C_BASE_US0->US_THR);
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar(':');
|
||||
TEST_ASSERT_EQUAL(':', AT91C_BASE_US0->US_THR);
|
||||
}
|
||||
|
||||
void testPutCharShouldWaitUntilReadyToTransmitBeforeLoadingTransmitBufffer(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_THR = 0;
|
||||
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(FALSE);
|
||||
Usart_ReadyToTransmit_ExpectAndReturn(TRUE);
|
||||
Usart_PutChar('x');
|
||||
TEST_ASSERT_EQUAL('x', AT91C_BASE_US0->US_THR);
|
||||
}
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartTransmitBufferStatus.h"
|
||||
|
||||
AT91S_USART Usart0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testReadyToTransmitShouldReturnStatusPerTransmitBufferReadyStatus(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CSR = 0;
|
||||
TEST_ASSERT(!Usart_ReadyToTransmit());
|
||||
|
||||
AT91C_BASE_US0->US_CSR = AT91C_US_TXRDY;
|
||||
TEST_ASSERT(Usart_ReadyToTransmit());
|
||||
}
|
||||
#include "unity.h"
|
||||
#include "Types.h"
|
||||
#include "UsartTransmitBufferStatus.h"
|
||||
|
||||
AT91S_USART Usart0Peripheral;
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
}
|
||||
|
||||
void testReadyToTransmitShouldReturnStatusPerTransmitBufferReadyStatus(void)
|
||||
{
|
||||
AT91C_BASE_US0->US_CSR = 0;
|
||||
TEST_ASSERT(!Usart_ReadyToTransmit());
|
||||
|
||||
AT91C_BASE_US0->US_CSR = AT91C_US_TXRDY;
|
||||
TEST_ASSERT(Usart_ReadyToTransmit());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user