summaryrefslogtreecommitdiff
path: root/FreeRTOS-Plus/Test/CMock/test/system/test_interactions/fancy_pointer_handling.yml
blob: 2a47d23f7aba3ceb444959a1d57b749d89fdd580 (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
---
:cmock:
  :plugins:
  - # none
  :treat_as:
    INT_PTR: INT*

:systest:
  :types: |
    typedef struct _POINT_T {
      int x;
      int y;
    } POINT_T;
    typedef int* INT_PTR;

  :mockable: |
    void foo(POINT_T* a);
    POINT_T* bar(void);
    void fooa(POINT_T a[]);
    void foos(const char *a);
    const char* bars(void);
    INT_PTR zoink(INT_PTR a);

  :source:
    :header: |
      void function_a(void);
      void function_b(void);
      void function_c(void);
      int  function_d(void);

    :code: |
      void function_a(void)
      {
        foo(bar());
      }

      void function_b(void) {
        fooa(bar());
      }

      void function_c(void) {
        foos(bars());
      }

      int function_d(void) {
        int i = 456;
        INT_PTR ptr = (INT_PTR)(&i);
        return (int)(*(zoink(ptr)));
      }

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

    :units:
    - :pass: TRUE
      :should: 'handle the situation where we pass nulls to pointers'
      :code: |
        test()
        {
          bar_ExpectAndReturn(NULL);
          foo_Expect(NULL);

          function_a();
        }

    - :pass: TRUE
      :should: 'handle the situation where we pass single object with expect'
      :code: |
        test()
        {
          POINT_T pt = {1, 2};
          POINT_T ex = {1, 2};
          bar_ExpectAndReturn(&pt);
          foo_Expect(&ex);

          function_a();
        }

    - :pass: FALSE
      :should: 'handle the situation where we pass single object with expect and it is wrong'
      :code: |
        test()
        {
          POINT_T pt = {1, 2};
          POINT_T ex = {1, 3};
          bar_ExpectAndReturn(&pt);
          foo_Expect(&ex);

          function_a();
        }

    - :pass: FALSE
      :should: 'handle the situation where we pass nulls to pointers and fail'
      :code: |
        test()
        {
          POINT_T pt = {1, 2};
          bar_ExpectAndReturn(&pt);
          foo_Expect(NULL);

          function_a();
        }

    - :pass: TRUE
      :should: 'handle the situation where we pass nulls to arrays'
      :code: |
        test()
        {
          bar_ExpectAndReturn(NULL);
          fooa_Expect(NULL);

          function_b();
        }

    - :pass: TRUE
      :should: 'handle the situation where we pass single array element with expect'
      :code: |
        test()
        {
          POINT_T pt = {1, 2};
          POINT_T ex = {1, 2};
          bar_ExpectAndReturn(&pt);
          fooa_Expect(&ex);

          function_b();
        }

    - :pass: FALSE
      :should: 'handle the situation where we pass single array element with expect and it is wrong'
      :code: |
        test()
        {
          POINT_T pt = {1, 2};
          POINT_T ex = {1, 3};
          bar_ExpectAndReturn(&pt);
          fooa_Expect(&ex);

          function_b();
        }

    - :pass: FALSE
      :should: 'handle the situation where we pass nulls to arrays and fail'
      :code: |
        test()
        {
          POINT_T pt = {1, 2};
          bar_ExpectAndReturn(&pt);
          fooa_Expect(NULL);

          function_b();
        }

    - :pass: TRUE
      :should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, passing'
      :code: |
        test()
        {
          const char* retval = "This is a\0 silly string";
          bars_ExpectAndReturn((char*)retval);
          foos_Expect("This is a\0 wacky string");

          function_c();
        }

    - :pass: FALSE
      :should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, finding failures'
      :code: |
        test()
        {
          const char* retval = "This is a silly string";
          bars_ExpectAndReturn((char*)retval);
          foos_Expect("This is a wacky string");

          function_c();
        }

    - :pass: TRUE
      :should: 'handle handle typedefs that ARE pointers by using treat_as'
      :code: |
        test()
        {
          int e = 456;
          int r = 789;
          INT_PTR ptr_e = (INT_PTR)(&e);
          INT_PTR ptr_r = (INT_PTR)(&r);

          zoink_ExpectAndReturn(ptr_e, ptr_r);

          TEST_ASSERT_EQUAL(r, function_d());
        }

    - :pass: FALSE
      :should: 'handle handle typedefs that ARE pointers by using treat_as and catch failures'
      :code: |
        test()
        {
          int e = 457;
          int r = 789;
          INT_PTR ptr_e = (INT_PTR)(&e);
          INT_PTR ptr_r = (INT_PTR)(&r);

          zoink_ExpectAndReturn(ptr_e, ptr_r);

          TEST_ASSERT_EQUAL(r, function_d());
        }


...