| 1 | --- |
| 2 | :cmock: |
| 3 | :when_ptr: :smart |
| 4 | :plugins: |
| 5 | - :array |
| 6 | |
| 7 | :systest: |
| 8 | :types: | |
| 9 | typedef struct _POINT_T { |
| 10 | int x; |
| 11 | int y; |
| 12 | } POINT_T; |
| 13 | #define ARRAY_A_SIZE (5) |
| 14 | |
| 15 | :mockable: | |
| 16 | void foo(POINT_T* a); |
| 17 | POINT_T* bar(void); |
| 18 | void fooa(POINT_T a[ARRAY_A_SIZE+1-1]); |
| 19 | void foos(const char * a); |
| 20 | const char * bars(void); |
| 21 | void no_pointers(int a, const char* b); |
| 22 | int mixed(int a, int* b, int c); |
| 23 | void potential_packing_problem(short *a); |
| 24 | void voidpointerfunc(void* a); |
| 25 | |
| 26 | :source: |
| 27 | :header: | |
| 28 | void function_a(void); |
| 29 | void function_b(void); |
| 30 | void function_c(void); |
| 31 | int function_d(void); |
| 32 | void function_e(void); |
| 33 | void function_f(void); |
| 34 | |
| 35 | :code: | |
| 36 | void function_a(void) |
| 37 | { |
| 38 | foo(bar()); |
| 39 | } |
| 40 | |
| 41 | void function_b(void) { |
| 42 | fooa(bar()); |
| 43 | } |
| 44 | |
| 45 | void function_c(void) { |
| 46 | foos(bars()); |
| 47 | } |
| 48 | |
| 49 | int function_d(void) { |
| 50 | int test_list[] = { 1, 2, 3, 4, 5 }; |
| 51 | no_pointers(1, "silly"); |
| 52 | return mixed(6, test_list, 7); |
| 53 | } |
| 54 | |
| 55 | void function_e(void) { |
| 56 | short test_list[] = {-1, -2, -3, -4}; |
| 57 | potential_packing_problem(&test_list[1]); |
| 58 | } |
| 59 | |
| 60 | void function_f(void) { |
| 61 | char arg[6] = "hello"; |
| 62 | voidpointerfunc(arg); |
| 63 | } |
| 64 | |
| 65 | :tests: |
| 66 | :common: | |
| 67 | void setUp(void) {} |
| 68 | void tearDown(void) {} |
| 69 | |
| 70 | :units: |
| 71 | - :pass: TRUE |
| 72 | :should: 'handle the situation where we pass nulls to pointers' |
| 73 | :code: | |
| 74 | test() |
| 75 | { |
| 76 | bar_ExpectAndReturn(NULL); |
| 77 | foo_Expect(NULL); |
| 78 | |
| 79 | function_a(); |
| 80 | } |
| 81 | |
| 82 | - :pass: FALSE |
| 83 | :should: 'handle the situation where we expected nulls to pointers but did not get that' |
| 84 | :code: | |
| 85 | test() |
| 86 | { |
| 87 | POINT_T pt = {1, 2}; |
| 88 | bar_ExpectAndReturn(&pt); |
| 89 | foo_Expect(NULL); |
| 90 | |
| 91 | function_a(); |
| 92 | } |
| 93 | |
| 94 | - :pass: FALSE |
| 95 | :should: 'handle the situation where we did not expect nulls to pointers but got null' |
| 96 | :code: | |
| 97 | test() |
| 98 | { |
| 99 | POINT_T ex = {1, 2}; |
| 100 | bar_ExpectAndReturn(NULL); |
| 101 | foo_Expect(&ex); |
| 102 | |
| 103 | function_a(); |
| 104 | } |
| 105 | |
| 106 | - :pass: TRUE |
| 107 | :should: 'handle the situation where it falls back to pointers because you asked it to compare 0 elements' |
| 108 | :code: | |
| 109 | test() |
| 110 | { |
| 111 | POINT_T ex = {1, 2}; |
| 112 | bar_ExpectAndReturn(&ex); |
| 113 | foo_ExpectWithArray(&ex, 0); |
| 114 | |
| 115 | function_a(); |
| 116 | } |
| 117 | |
| 118 | - :pass: FALSE |
| 119 | :should: 'handle the situation where it fails because you asked it to compare zero elements and the pointers do not match' |
| 120 | :code: | |
| 121 | test() |
| 122 | { |
| 123 | POINT_T ex = {1, 2}; |
| 124 | POINT_T pt = {1, 2}; |
| 125 | bar_ExpectAndReturn(&pt); |
| 126 | foo_ExpectWithArray(&ex, 0); |
| 127 | |
| 128 | function_a(); |
| 129 | } |
| 130 | |
| 131 | - :pass: TRUE |
| 132 | :should: 'handle the situation where we pass single object with expect' |
| 133 | :code: | |
| 134 | test() |
| 135 | { |
| 136 | POINT_T pt = {1, 2}; |
| 137 | POINT_T ex = {1, 2}; |
| 138 | bar_ExpectAndReturn(&pt); |
| 139 | foo_Expect(&ex); |
| 140 | |
| 141 | function_a(); |
| 142 | } |
| 143 | |
| 144 | - :pass: FALSE |
| 145 | :should: 'handle the situation where we pass single object with expect and it is wrong' |
| 146 | :code: | |
| 147 | test() |
| 148 | { |
| 149 | POINT_T pt = {1, 2}; |
| 150 | POINT_T ex = {1, 3}; |
| 151 | bar_ExpectAndReturn(&pt); |
| 152 | foo_Expect(&ex); |
| 153 | |
| 154 | function_a(); |
| 155 | } |
| 156 | |
| 157 | - :pass: TRUE |
| 158 | :should: 'handle the situation where we pass single object with expect and use array handler' |
| 159 | :code: | |
| 160 | test() |
| 161 | { |
| 162 | POINT_T pt = {1, 2}; |
| 163 | POINT_T ex = {1, 2}; |
| 164 | bar_ExpectAndReturn(&pt); |
| 165 | foo_ExpectWithArray(&ex, 1); |
| 166 | |
| 167 | function_a(); |
| 168 | } |
| 169 | |
| 170 | - :pass: FALSE |
| 171 | :should: 'handle the situation where we pass single object with expect and use array handler and it is wrong' |
| 172 | :code: | |
| 173 | test() |
| 174 | { |
| 175 | POINT_T pt = {1, 2}; |
| 176 | POINT_T ex = {1, 3}; |
| 177 | bar_ExpectAndReturn(&pt); |
| 178 | foo_ExpectWithArray(&ex, 1); |
| 179 | |
| 180 | function_a(); |
| 181 | } |
| 182 | |
| 183 | - :pass: TRUE |
| 184 | :should: 'handle the situation where we pass multiple objects with expect and use array handler' |
| 185 | :code: | |
| 186 | test() |
| 187 | { |
| 188 | POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}}; |
| 189 | POINT_T ex[] = {{1, 2}, {3, 4}, {5, 6}}; |
| 190 | bar_ExpectAndReturn(pt); |
| 191 | foo_ExpectWithArray(ex, 3); |
| 192 | |
| 193 | function_a(); |
| 194 | } |
| 195 | |
| 196 | - :pass: FALSE |
| 197 | :should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at start' |
| 198 | :code: | |
| 199 | test() |
| 200 | { |
| 201 | POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}}; |
| 202 | POINT_T ex[] = {{9, 2}, {3, 4}, {5, 6}}; |
| 203 | bar_ExpectAndReturn(pt); |
| 204 | foo_ExpectWithArray(ex, 3); |
| 205 | |
| 206 | function_a(); |
| 207 | } |
| 208 | |
| 209 | - :pass: FALSE |
| 210 | :should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at end' |
| 211 | :code: | |
| 212 | test() |
| 213 | { |
| 214 | POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}}; |
| 215 | POINT_T ex[] = {{1, 2}, {3, 4}, {5, 9}}; |
| 216 | bar_ExpectAndReturn(pt); |
| 217 | foo_ExpectWithArray(ex, 3); |
| 218 | |
| 219 | function_a(); |
| 220 | } |
| 221 | |
| 222 | - :pass: FALSE |
| 223 | :should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong in middle' |
| 224 | :code: | |
| 225 | test() |
| 226 | { |
| 227 | POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}}; |
| 228 | POINT_T ex[] = {{1, 2}, {3, 9}, {5, 6}}; |
| 229 | bar_ExpectAndReturn(pt); |
| 230 | foo_ExpectWithArray(ex, 3); |
| 231 | |
| 232 | function_a(); |
| 233 | } |
| 234 | |
| 235 | - :pass: FALSE |
| 236 | :should: 'handle the situation where we pass nulls to pointers and fail' |
| 237 | :code: | |
| 238 | test() |
| 239 | { |
| 240 | POINT_T pt = {1, 2}; |
| 241 | bar_ExpectAndReturn(&pt); |
| 242 | foo_Expect(NULL); |
| 243 | |
| 244 | function_a(); |
| 245 | } |
| 246 | |
| 247 | - :pass: TRUE |
| 248 | :should: 'handle the situation where we pass nulls to arrays' |
| 249 | :code: | |
| 250 | test() |
| 251 | { |
| 252 | bar_ExpectAndReturn(NULL); |
| 253 | fooa_Expect(NULL); |
| 254 | |
| 255 | function_b(); |
| 256 | } |
| 257 | |
| 258 | - :pass: TRUE |
| 259 | :should: 'handle the situation where we pass single array element with expect' |
| 260 | :code: | |
| 261 | test() |
| 262 | { |
| 263 | POINT_T pt = {1, 2}; |
| 264 | POINT_T ex = {1, 2}; |
| 265 | bar_ExpectAndReturn(&pt); |
| 266 | fooa_Expect(&ex); |
| 267 | |
| 268 | function_b(); |
| 269 | } |
| 270 | |
| 271 | - :pass: FALSE |
| 272 | :should: 'handle the situation where we pass single array element with expect and it is wrong' |
| 273 | :code: | |
| 274 | test() |
| 275 | { |
| 276 | POINT_T pt = {1, 2}; |
| 277 | POINT_T ex = {1, 3}; |
| 278 | bar_ExpectAndReturn(&pt); |
| 279 | fooa_Expect(&ex); |
| 280 | |
| 281 | function_b(); |
| 282 | } |
| 283 | |
| 284 | - :pass: FALSE |
| 285 | :should: 'handle the situation where we pass nulls to arrays and fail' |
| 286 | :code: | |
| 287 | test() |
| 288 | { |
| 289 | POINT_T pt = {1, 2}; |
| 290 | bar_ExpectAndReturn(&pt); |
| 291 | fooa_Expect(NULL); |
| 292 | |
| 293 | function_b(); |
| 294 | } |
| 295 | |
| 296 | - :pass: TRUE |
| 297 | :should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, passing' |
| 298 | :code: | |
| 299 | test() |
| 300 | { |
| 301 | const char* retval = "This is a\0 silly string"; |
| 302 | bars_ExpectAndReturn((char*)retval); |
| 303 | foos_Expect("This is a\0 wacky string"); |
| 304 | |
| 305 | function_c(); |
| 306 | } |
| 307 | |
| 308 | - :pass: FALSE |
| 309 | :should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, finding failures' |
| 310 | :code: | |
| 311 | test() |
| 312 | { |
| 313 | const char* retval = "This is a silly string"; |
| 314 | bars_ExpectAndReturn((char*)retval); |
| 315 | foos_Expect("This is a wacky string"); |
| 316 | |
| 317 | function_c(); |
| 318 | } |
| 319 | |
| 320 | - :pass: TRUE |
| 321 | :should: 'handle creating array expects when we have mixed arguments for single object' |
| 322 | :code: | |
| 323 | test() |
| 324 | { |
| 325 | int expect_list[] = { 1, 9 }; |
| 326 | no_pointers_Expect(1, "silly"); |
| 327 | mixed_ExpectAndReturn(6, expect_list, 7, 13); |
| 328 | |
| 329 | TEST_ASSERT_EQUAL(13, function_d()); |
| 330 | } |
| 331 | |
| 332 | - :pass: FALSE |
| 333 | :should: 'handle creating array expects when we have mixed arguments and handle failures for single object' |
| 334 | :code: | |
| 335 | test() |
| 336 | { |
| 337 | int expect_list[] = { 9, 1 }; |
| 338 | no_pointers_Expect(1, "silly"); |
| 339 | mixed_ExpectAndReturn(6, expect_list, 7, 13); |
| 340 | |
| 341 | TEST_ASSERT_EQUAL(13, function_d()); |
| 342 | } |
| 343 | |
| 344 | - :pass: TRUE |
| 345 | :should: 'handle creating array expects when we have mixed arguments for multiple objects' |
| 346 | :code: | |
| 347 | test() |
| 348 | { |
| 349 | int expect_list[] = { 1, 2, 3, 4, 6 }; |
| 350 | no_pointers_Expect(1, "silly"); |
| 351 | mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13); |
| 352 | |
| 353 | TEST_ASSERT_EQUAL(13, function_d()); |
| 354 | } |
| 355 | |
| 356 | - :pass: FALSE |
| 357 | :should: 'handle creating array expects when we have mixed arguments and handle failures for multiple objects' |
| 358 | :code: | |
| 359 | test() |
| 360 | { |
| 361 | int expect_list[] = { 1, 2, 3, 4, 6 }; |
| 362 | no_pointers_Expect(1, "silly"); |
| 363 | mixed_ExpectWithArrayAndReturn(6, expect_list, 5, 7, 13); |
| 364 | |
| 365 | TEST_ASSERT_EQUAL(13, function_d()); |
| 366 | } |
| 367 | |
| 368 | - :pass: TRUE |
| 369 | :should: 'handle a passing version of a potential packing problem (particularly try with ARM simulators)' |
| 370 | :code: | |
| 371 | test() |
| 372 | { |
| 373 | short expect_list[] = { -2, -3, -4 }; |
| 374 | potential_packing_problem_ExpectWithArray(expect_list, 3); |
| 375 | |
| 376 | function_e(); |
| 377 | } |
| 378 | |
| 379 | - :pass: FALSE |
| 380 | :should: 'handle a failing version of a potential packing problem (particularly try with ARM simulators)' |
| 381 | :code: | |
| 382 | test() |
| 383 | { |
| 384 | short expect_list[] = { -2, -3, 4 }; |
| 385 | potential_packing_problem_ExpectWithArray(expect_list, 3); |
| 386 | |
| 387 | function_e(); |
| 388 | } |
| 389 | |
| 390 | - :pass: TRUE |
| 391 | :should: 'handle a void pointers as arguments and still be able to use the array plugin' |
| 392 | :code: | |
| 393 | test() |
| 394 | { |
| 395 | char expect_list[6] = "hello"; |
| 396 | voidpointerfunc_ExpectWithArray(expect_list, 5); |
| 397 | |
| 398 | function_f(); |
| 399 | } |
| 400 | |
| 401 | - :pass: TRUE |
| 402 | :should: 'handle a void pointers as arguments and still be able to use the array plugin (short)' |
| 403 | :code: | |
| 404 | test() |
| 405 | { |
| 406 | char expect_list[6] = "help!"; |
| 407 | voidpointerfunc_ExpectWithArray(expect_list, 3); |
| 408 | |
| 409 | function_f(); |
| 410 | } |
| 411 | |
| 412 | - :pass: FALSE |
| 413 | :should: 'handle a void pointers as arguments and still be able to use the array plugin (fail)' |
| 414 | :code: | |
| 415 | test() |
| 416 | { |
| 417 | char expect_list[6] = "help!"; |
| 418 | voidpointerfunc_ExpectWithArray(expect_list, 4); |
| 419 | |
| 420 | function_f(); |
| 421 | } |
| 422 | |
| 423 | - :pass: TRUE |
| 424 | :should: 'handle a void pointer with a standard expectation (pass)' |
| 425 | :code: | |
| 426 | test() |
| 427 | { |
| 428 | char expect_list[2] = "h"; |
| 429 | voidpointerfunc_Expect(expect_list); |
| 430 | |
| 431 | function_f(); |
| 432 | } |
| 433 | |
| 434 | - :pass: FALSE |
| 435 | :should: 'handle a void pointer with a standard expectation (fail)' |
| 436 | :code: | |
| 437 | test() |
| 438 | { |
| 439 | char expect_list[2] = "g"; |
| 440 | voidpointerfunc_Expect(expect_list); |
| 441 | |
| 442 | function_f(); |
| 443 | } |
| 444 | |
| 445 | |
| 446 | ... |