| 1 |
#include "unity.h" |
| 2 |
#include "UnityHelper.h" |
| 3 |
#include "Types.h" |
| 4 |
#include "Types.h" |
| 5 |
#include "AdcConductor.h" |
| 6 |
#include "MockAdcModel.h" |
| 7 |
#include "MockAdcHardware.h" |
| 8 |
|
| 9 |
void setUp(void) |
| 10 |
{ |
| 11 |
} |
| 12 |
|
| 13 |
void tearDown(void) |
| 14 |
{ |
| 15 |
} |
| 16 |
|
| 17 |
void testInitShouldCallHardwareInit(void) |
| 18 |
{ |
| 19 |
AdcHardware_Init_Expect(); |
| 20 |
AdcConductor_Init(); |
| 21 |
} |
| 22 |
|
| 23 |
void testRunShouldNotDoAnythingIfItIsNotTime(void) |
| 24 |
{ |
| 25 |
AdcModel_DoGetSample_ExpectAndReturn(FALSE); |
| 26 |
|
| 27 |
AdcConductor_Run(); |
| 28 |
} |
| 29 |
|
| 30 |
void testRunShouldNotPassAdcResultToModelIfSampleIsNotComplete(void) |
| 31 |
{ |
| 32 |
AdcModel_DoGetSample_ExpectAndReturn(TRUE); |
| 33 |
AdcHardware_GetSampleComplete_ExpectAndReturn(FALSE); |
| 34 |
|
| 35 |
AdcConductor_Run(); |
| 36 |
} |
| 37 |
|
| 38 |
void testRunShouldGetLatestSampleFromAdcAndPassItToModelAndStartNewConversionWhenItIsTime(void) |
| 39 |
{ |
| 40 |
AdcModel_DoGetSample_ExpectAndReturn(TRUE); |
| 41 |
AdcHardware_GetSampleComplete_ExpectAndReturn(TRUE); |
| 42 |
AdcHardware_GetSample_ExpectAndReturn(293U); |
| 43 |
AdcModel_ProcessInput_Expect(293U); |
| 44 |
AdcHardware_StartConversion_Expect(); |
| 45 |
|
| 46 |
AdcConductor_Run(); |
| 47 |
} |
| 48 |
|
| 49 |
void testJustHereToTest_Should_ProperlyPassAStructAndVerifyIt(void) |
| 50 |
{ |
| 51 |
EXAMPLE_STRUCT_T TestStruct; |
| 52 |
TestStruct.x = 5; |
| 53 |
TestStruct.y = 7; |
| 54 |
|
| 55 |
AdcModel_DoNothingExceptTestASpecialType_ExpectAndReturn(TestStruct, TRUE); |
| 56 |
|
| 57 |
TEST_ASSERT_TRUE(AdcConductor_JustHereToTest()); |
| 58 |
} |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
void test_AdcConductor_AlsoHereToTest_Should_ProperlyReturnAStructAsExpected1(void) |
| 83 |
{ |
| 84 |
EXAMPLE_STRUCT_T TestStruct; |
| 85 |
TestStruct.x = 99; |
| 86 |
TestStruct.y = 1; |
| 87 |
|
| 88 |
AdcModel_DoNothingExceptReturnASpecialType_ExpectAndReturn(TestStruct); |
| 89 |
|
| 90 |
TEST_ASSERT_TRUE(AdcConductor_AlsoHereToTest()); |
| 91 |
} |
| 92 |
|
| 93 |
void test_AdcConductor_AlsoHereToTest_Should_ProperlyReturnAStructAsExpected2(void) |
| 94 |
{ |
| 95 |
EXAMPLE_STRUCT_T TestStruct; |
| 96 |
TestStruct.x = 98; |
| 97 |
TestStruct.y = 1; |
| 98 |
|
| 99 |
AdcModel_DoNothingExceptReturnASpecialType_ExpectAndReturn(TestStruct); |
| 100 |
|
| 101 |
TEST_ASSERT_FALSE(AdcConductor_AlsoHereToTest()); |
| 102 |
} |
| 103 |
|
| 104 |
void test_AdcConductor_YetAnotherTest_Should_VerifyThatPointersToStructsAreTestable(void) |
| 105 |
{ |
| 106 |
uint32 TestNum = 3; |
| 107 |
|
| 108 |
AdModel_DoNothingExceptTestPointers_ExpectAndReturn(&TestNum, TRUE); |
| 109 |
|
| 110 |
TEST_ASSERT_TRUE(AdcConductor_YetAnotherTest()); |
| 111 |
} |
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|