summaryrefslogtreecommitdiff
path: root/FreeRTOS-Plus/Test/CMock/test/system/test_interactions/struct_union_enum_expect_and_return_with_plugins.yml
blob: a54826ca44c80d51424b116954c7d2b690a2bbcd (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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
---
:cmock:
  :plugins:
  - :array
  - :ignore
  - :callback
  - :return_thru_ptr

:systest:
  :types: |
    struct THING { int a; int b; };

    union STARS_AND_STRIPES { int a; char b; };

    enum HOKEY_POKEY { IN, OUT, SHAKE_IT_ALL_ABOUT };

  :mockable: |
    void foo_struct(struct THING*, struct THING);
    struct THING foobar_struct(void);

    void foo_union(union STARS_AND_STRIPES*, union STARS_AND_STRIPES);
    union STARS_AND_STRIPES foobar_union(void);

    void foo_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b);
    enum HOKEY_POKEY foobar_enum(void);

  :source:
    :header: |
      void exercise_struct(struct THING* a, struct THING b);
      struct THING return_struct(void);

      void exercise_union(union STARS_AND_STRIPES* a, union STARS_AND_STRIPES b);
      union STARS_AND_STRIPES return_union(void);

      void exercise_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b);
      enum HOKEY_POKEY return_enum(void);

    :code: |
      void exercise_struct(struct THING* a, struct THING b)
      {
        foo_struct(a, b);
      }

      struct THING return_struct(void)
      {
        return foobar_struct();
      }

      void exercise_union(union STARS_AND_STRIPES* a, union STARS_AND_STRIPES b)
      {
        foo_union(a, b);
      }

      union STARS_AND_STRIPES return_union(void)
      {
        return foobar_union();
      }

      void exercise_enum(enum HOKEY_POKEY a, enum HOKEY_POKEY * b)
      {
        foo_enum(a, b);
      }

      enum HOKEY_POKEY return_enum(void)
      {
        return foobar_enum();
      }


  :tests:
    :common: |
      struct THING struct1;
      struct THING struct2;
      struct THING struct3;
      struct THING struct4;
      struct THING struct5;
      struct THING struct6;

      union STARS_AND_STRIPES union1;
      union STARS_AND_STRIPES union2;
      union STARS_AND_STRIPES union3;
      union STARS_AND_STRIPES union4;
      union STARS_AND_STRIPES union5;
      union STARS_AND_STRIPES union6;

      enum HOKEY_POKEY enum1;
      enum HOKEY_POKEY enum2;

      void setUp(void)
      {
        struct1.a = 1;
        struct1.b = 2;

        struct2.a = 3;
        struct2.b = 4;

        struct3.a = 5;
        struct3.b = 6;

        struct4.a = 7;
        struct4.b = 8;

        struct5.a = 9;
        struct5.b = 10;

        struct6.a = 9;
        struct6.b = 10;

        union1.a = 1;
        union2.a = 2;
        union3.a = 3;
        union4.a = 4;
        union5.a = 5;
        union6.a = 5;

        enum1 = OUT;
        enum2 = IN;
      }

      void tearDown(void) {}

    :units:
    - :pass: TRUE
      :should: 'successfully compare structs'
      :code: |
        test()
        {
          foo_struct_Expect(&struct1, struct2);
          exercise_struct(&struct1, struct2);
        }

    - :pass: FALSE
      :should: 'blow up on bad struct pointer comparison'
      :code: |
        test()
        {
          foo_struct_Expect(&struct1, struct2);
          exercise_struct(&struct3, struct2);
        }

    - :pass: FALSE
      :should: 'blow up on bad structure comparison'
      :code: |
        test()
        {
          foo_struct_Expect(&struct1, struct2);
          exercise_struct(&struct1, struct4);
        }

    - :pass: TRUE
      :should: 'compare returned structs as equal'
      :code: |
        test()
        {
          foobar_struct_ExpectAndReturn(struct5);
          TEST_ASSERT_EQUAL_THING(struct6, return_struct());
        }

    - :pass: FALSE
      :should: 'compare returned structs as unequal'
      :code: |
        test()
        {
          foobar_struct_ExpectAndReturn(struct4);
          TEST_ASSERT_EQUAL_THING(struct5, return_struct());
        }

    - :pass: TRUE
      :should: 'successfully compare unions'
      :code: |
        test()
        {
          foo_union_Expect(&union1, union2);
          exercise_union(&union1, union2);
        }

    - :pass: FALSE
      :should: 'blow up on bad union pointer comparison'
      :code: |
        test()
        {
          foo_union_Expect(&union1, union2);
          exercise_union(&union3, union2);
        }

    - :pass: FALSE
      :should: 'blow up on bad union comparison'
      :code: |
        test()
        {
          foo_union_Expect(&union1, union2);
          exercise_union(&union1, union4);
        }

    - :pass: TRUE
      :should: 'compare returned unions as equal'
      :code: |
        test()
        {
          foobar_union_ExpectAndReturn(union5);
          TEST_ASSERT_EQUAL_STARS_AND_STRIPES(union6, return_union());
        }

    - :pass: FALSE
      :should: 'compare returned unions as unequal'
      :code: |
        test()
        {
          foobar_union_ExpectAndReturn(union4);
          TEST_ASSERT_EQUAL_STARS_AND_STRIPES(union5, return_union());
        }

    - :pass: TRUE
      :should: 'successfully pass enum values'
      :code: |
        test()
        {
          foo_enum_Expect(OUT, &enum1);
          exercise_enum(OUT, &enum1);
        }

    - :pass: FALSE
      :should: 'blow up on bad enum pointer comparison'
      :code: |
        test()
        {
          foo_enum_Expect(IN, &enum1);
          exercise_enum(IN, &enum2);
        }

    - :pass: FALSE
      :should: 'blow up on bad enum comparison'
      :code: |
        test()
        {
          foo_enum_Expect(IN, &enum1);
          exercise_enum(SHAKE_IT_ALL_ABOUT, &enum1);
        }

    - :pass: TRUE
      :should: 'compare returned enums as equal'
      :code: |
        test()
        {
          foobar_enum_ExpectAndReturn(OUT);
          TEST_ASSERT_EQUAL(OUT, return_enum());
        }

    - :pass: FALSE
      :should: 'compare returned unions as unequal'
      :code: |
        test()
        {
          foobar_enum_ExpectAndReturn(OUT);
          TEST_ASSERT_EQUAL(IN, return_enum());
        }


  :unity_helper:
    :header: |
      void AssertEqualTHINGStruct(struct THING expected, struct THING actual);
      void AssertEqualSTARS_AND_STRIPESUnion(union STARS_AND_STRIPES expected, union STARS_AND_STRIPES actual);

      #define TEST_ASSERT_EQUAL_THING(expected, actual) {AssertEqualTHINGStruct(expected, actual);}
      #define TEST_ASSERT_EQUAL_STARS_AND_STRIPES(expected, actual) {AssertEqualSTARS_AND_STRIPESUnion(expected, actual);}

    :code: |
      void AssertEqualTHINGStruct(struct THING expected, struct THING actual)
      {
        TEST_ASSERT_EQUAL_INT_MESSAGE(expected.a, actual.a, "actual struct member \"a\" does not equal expected");
        TEST_ASSERT_EQUAL_INT_MESSAGE(expected.b, actual.b, "actual struct member \"b\" does not equal expected");
      }

      void AssertEqualSTARS_AND_STRIPESUnion(union STARS_AND_STRIPES expected, union STARS_AND_STRIPES actual)
      {
        TEST_ASSERT_EQUAL_INT_MESSAGE(expected.a, actual.a, "actual union member \"a\" does not equal expected");
        TEST_ASSERT_EQUAL_MESSAGE(expected.b, actual.b, "actual union member \"b\" does not equal expected");
      }

...