summaryrefslogtreecommitdiff
path: root/FreeRTOS-Plus/Test/CMock/examples/temp_sensor/test/TestAdcConductor.c
blob: a15d7d1b4db7fe67eb6378bfc0245187220e3bfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
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());
//}