summaryrefslogtreecommitdiff
path: root/FreeRTOS-Plus/Test/CMock/test/system/test_interactions/expect_and_return_treat_as.yml
blob: 2c24f35d82ac9a8cffc866dc92409eead533da96 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
---
:cmock:
  :plugins:
  - # none
  :treat_as:
    MY_STRING: STRING
    MY_INT: INT
    PTR_INT: INT*
    MY_HEX: HEX32

:systest:
  :types: |
    typedef const char* MY_STRING;
    typedef int MY_INT;
    typedef unsigned int MY_HEX;
    typedef int* PTR_INT;

  :mockable: |
    MY_INT foo(MY_HEX a);
    MY_INT bar(MY_HEX b);
    MY_STRING foo_char_strings(MY_STRING a, MY_STRING b);
    float float_adder(float a, float b);
    MY_INT* pointer_foo(MY_HEX* a);
    void pointer_bar(PTR_INT a);

  :source:
    :header: |
      MY_INT function_a(MY_INT a, MY_INT b);
      MY_STRING function_b(MY_STRING a, MY_STRING b);
      float function_c(float a, float b);
      MY_INT function_d(MY_HEX a);
      void function_e(PTR_INT a);

    :code: |
      MY_INT function_a(MY_INT a, MY_INT b)
      {
        return foo((MY_HEX)a) + bar((MY_HEX)b);
      }

      MY_STRING function_b(MY_STRING a, MY_STRING b)
      {
        return foo_char_strings(a, b);
      }

      float function_c(float a, float b)
      {
        return float_adder(b, a);
      }

      MY_INT function_d(MY_HEX a)
      {
        MY_HEX b = a;
        MY_INT* c = pointer_foo(&b);
        return *c;
      }

      void function_e(PTR_INT a)
      {
        pointer_bar(a);
      }

  :tests:
    :common: |
      void setUp(void) {}
      void tearDown(void) {}

    :units:
    - :pass: TRUE
      :should: 'successfully exercise two simple ExpectAndReturn mock calls'
      :code: |
        test()
        {
          foo_ExpectAndReturn((MY_HEX)1, 10);
          bar_ExpectAndReturn((MY_HEX)2, 20);
          TEST_ASSERT_EQUAL(30, function_a(1, 2));
        }

    - :pass: FALSE
      :should: 'fail because bar() is expected but not called'
      :code: |
        test()
        {
          foo_ExpectAndReturn((MY_HEX)1, 10);
          TEST_ASSERT_EQUAL(30, function_a(1, 2));
        }

    - :pass: FALSE
      :should: 'fail because foo_char_strings() is called but is not expected'
      :code: |
        test()
        {
          foo_char_strings_ExpectAndReturn((MY_STRING)"jello", (MY_STRING)"jiggle", (MY_STRING)"boing!");
          function_a(1,2);
        }

    - :pass: TRUE
      :should: 'handle char strings'
      :code: |
        test()
        {
          foo_char_strings_ExpectAndReturn((MY_STRING)"jello", (MY_STRING)"jiggle", (MY_STRING)"boing!");
          TEST_ASSERT_EQUAL_STRING("boing!", function_b((MY_STRING)"jello", (MY_STRING)"jiggle"));
        }

    - :pass: TRUE
      :should: 'handle floating point numbers with Unity support: pass'
      :code: |
        test()
        {
          float_adder_ExpectAndReturn(1.2345f, 6.7890f, 8.0235f);
          TEST_ASSERT_EQUAL_FLOAT(8.0235f, function_c(6.7890f, 1.2345f));
        }

    - :pass: FALSE
      :should: 'handle floating point numbers with Unity support: fail'
      :code: |
        test()
        {
          float_adder_ExpectAndReturn(1.2345f, 6.7892f, 8.0235f);
          TEST_ASSERT_EQUAL_FLOAT(8.0235f, function_c(6.7890f, 1.2345f));
        }

    - :pass: TRUE
      :should: 'handle pointers to treat_as values just as cleanly as the treat_as itself for passes'
      :code: |
        test()
        {
          MY_HEX TestHex = (MY_HEX)45;
          MY_INT TestInt = (MY_INT)33;
          pointer_foo_ExpectAndReturn(&TestHex, &TestInt);
          TEST_ASSERT_EQUAL_INT(33, function_d(45));
        }

    - :pass: FALSE
      :should: 'handle pointers to treat_as values just as cleanly as the treat_as itself for failures'
      :verify_error: 'Element 0 Expected 0x0000002D Was 0x0000002B'
      :code: |
        test()
        {
          MY_HEX TestHex = (MY_HEX)45;
          MY_INT TestInt = (MY_INT)33;
          pointer_foo_ExpectAndReturn(&TestHex, &TestInt);
          TEST_ASSERT_EQUAL_INT(33, function_d(43));
        }

    - :pass: TRUE
      :should: 'handle treat_as values containing pointers for passes'
      :code: |
        test()
        {
          MY_INT ExpInt = (MY_INT)33;
          PTR_INT ExpPtr = (PTR_INT)(&ExpInt);
          MY_INT ActInt = (MY_INT)33;
          PTR_INT ActPtr = (PTR_INT)(&ActInt);
          pointer_bar_Expect(ExpPtr);
          function_e(ActPtr);
        }

    - :pass: FALSE
      :should: 'handle treat_as values containing pointers for failures'
      :verify_error: 'Element 0 Expected 33 Was 45'
      :code: |
        test()
        {
          MY_INT ExpInt = (MY_INT)33;
          PTR_INT ExpPtr = (PTR_INT)(&ExpInt);
          MY_INT ActInt = (MY_INT)45;
          PTR_INT ActPtr = (PTR_INT)(&ActInt);
          pointer_bar_Expect(ExpPtr);
          function_e(ActPtr);
        }

...