| 1 |
--- |
| 2 |
|
| 3 |
:cmock: |
| 4 |
:enforce_strict_ordering: 1 |
| 5 |
:treat_externs: :include |
| 6 |
:plugins: |
| 7 |
- :array |
| 8 |
- :cexception |
| 9 |
- :ignore |
| 10 |
- :callback |
| 11 |
- :return_thru_ptr |
| 12 |
- :ignore_arg |
| 13 |
- :expect_any_args |
| 14 |
|
| 15 |
:systest: |
| 16 |
:types: | |
| 17 |
typedef struct _POINT_T { |
| 18 |
int x; |
| 19 |
int y; |
| 20 |
} POINT_T; |
| 21 |
|
| 22 |
:mockable: | |
| 23 |
#include "CException.h" |
| 24 |
void foo(POINT_T* a); |
| 25 |
POINT_T* bar(void); |
| 26 |
void fooa(POINT_T a[]); |
| 27 |
void foos(const char * a); |
| 28 |
extern const char* bars(void); |
| 29 |
void no_pointers(int a, const char* b); |
| 30 |
int mixed(int a, int* b, int c); |
| 31 |
void no_args(void); |
| 32 |
|
| 33 |
:source: |
| 34 |
:header: | |
| 35 |
#include "CException.h" |
| 36 |
void function_a(void); |
| 37 |
void function_b(void); |
| 38 |
void function_c(void); |
| 39 |
int function_d(void); |
| 40 |
void function_e(void); |
| 41 |
|
| 42 |
:code: | |
| 43 |
void function_a(void) |
| 44 |
{ |
| 45 |
foo(bar()); |
| 46 |
} |
| 47 |
|
| 48 |
void function_b(void) { |
| 49 |
fooa(bar()); |
| 50 |
} |
| 51 |
|
| 52 |
void function_c(void) { |
| 53 |
CEXCEPTION_T e; |
| 54 |
Try { |
| 55 |
foos(bars()); |
| 56 |
} Catch(e) { foos("err"); } |
| 57 |
} |
| 58 |
|
| 59 |
int function_d(void) { |
| 60 |
int test_list[] = { 1, 2, 3, 4, 5 }; |
| 61 |
no_pointers(1, "silly"); |
| 62 |
return mixed(6, test_list, 7); |
| 63 |
} |
| 64 |
|
| 65 |
void function_e(void) { |
| 66 |
foos("Hello"); |
| 67 |
foos("Tuna"); |
| 68 |
foos("Oranges"); |
| 69 |
} |
| 70 |
|
| 71 |
:tests: |
| 72 |
:common: | |
| 73 |
#include "CException.h" |
| 74 |
void setUp(void) {} |
| 75 |
void tearDown(void) {} |
| 76 |
|
| 77 |
:units: |
| 78 |
- :pass: TRUE |
| 79 |
:should: 'handle the situation where we pass nulls to pointers' |
| 80 |
:code: | |
| 81 |
test() |
| 82 |
{ |
| 83 |
bar_ExpectAndReturn(NULL); |
| 84 |
foo_Expect(NULL); |
| 85 |
|
| 86 |
function_a(); |
| 87 |
} |
| 88 |
|
| 89 |
- :pass: FALSE |
| 90 |
:should: 'handle the situation where we expected nulls to pointers but did not get that' |
| 91 |
:code: | |
| 92 |
test() |
| 93 |
{ |
| 94 |
POINT_T pt = {1, 2}; |
| 95 |
bar_ExpectAndReturn(&pt); |
| 96 |
foo_Expect(NULL); |
| 97 |
|
| 98 |
function_a(); |
| 99 |
} |
| 100 |
|
| 101 |
- :pass: FALSE |
| 102 |
:should: 'handle the situation where we did not expect nulls to pointers but got null' |
| 103 |
:code: | |
| 104 |
test() |
| 105 |
{ |
| 106 |
POINT_T ex = {1, 2}; |
| 107 |
bar_ExpectAndReturn(NULL); |
| 108 |
foo_Expect(&ex); |
| 109 |
|
| 110 |
function_a(); |
| 111 |
} |
| 112 |
|
| 113 |
- :pass: FALSE |
| 114 |
:should: 'handle the situation where we pass single object with expect and it is wrong' |
| 115 |
:code: | |
| 116 |
test() |
| 117 |
{ |
| 118 |
POINT_T pt = {1, 2}; |
| 119 |
POINT_T ex = {1, 3}; |
| 120 |
bar_ExpectAndReturn(&pt); |
| 121 |
foo_Expect(&ex); |
| 122 |
|
| 123 |
function_a(); |
| 124 |
} |
| 125 |
|
| 126 |
- :pass: TRUE |
| 127 |
:should: 'handle the situation where we pass single object with expect and use array handler' |
| 128 |
:code: | |
| 129 |
test() |
| 130 |
{ |
| 131 |
POINT_T pt = {1, 2}; |
| 132 |
POINT_T ex = {1, 2}; |
| 133 |
bar_ExpectAndReturn(&pt); |
| 134 |
foo_ExpectWithArray(&ex, 1); |
| 135 |
|
| 136 |
function_a(); |
| 137 |
} |
| 138 |
|
| 139 |
- :pass: FALSE |
| 140 |
:should: 'handle the situation where we pass single object with expect and use array handler and it is wrong' |
| 141 |
:code: | |
| 142 |
test() |
| 143 |
{ |
| 144 |
POINT_T pt = {1, 2}; |
| 145 |
POINT_T ex = {1, 3}; |
| 146 |
bar_ExpectAndReturn(&pt); |
| 147 |
foo_ExpectWithArray(&ex, 1); |
| 148 |
|
| 149 |
function_a(); |
| 150 |
} |
| 151 |
|
| 152 |
- :pass: TRUE |
| 153 |
:should: 'handle the situation where we pass multiple objects with expect and use array handler' |
| 154 |
:code: | |
| 155 |
test() |
| 156 |
{ |
| 157 |
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}}; |
| 158 |
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 6}}; |
| 159 |
bar_ExpectAndReturn(pt); |
| 160 |
foo_ExpectWithArray(ex, 3); |
| 161 |
|
| 162 |
function_a(); |
| 163 |
} |
| 164 |
|
| 165 |
- :pass: FALSE |
| 166 |
:should: 'handle the situation where we pass multiple objects with expect and use array handler and it is wrong at end' |
| 167 |
:code: | |
| 168 |
test() |
| 169 |
{ |
| 170 |
POINT_T pt[] = {{1, 2}, {3, 4}, {5, 6}}; |
| 171 |
POINT_T ex[] = {{1, 2}, {3, 4}, {5, 9}}; |
| 172 |
bar_ExpectAndReturn(pt); |
| 173 |
foo_ExpectWithArray(ex, 3); |
| 174 |
|
| 175 |
function_a(); |
| 176 |
} |
| 177 |
|
| 178 |
- :pass: TRUE |
| 179 |
:should: 'handle the situation where we pass single array element with expect' |
| 180 |
:code: | |
| 181 |
test() |
| 182 |
{ |
| 183 |
POINT_T pt = {1, 2}; |
| 184 |
POINT_T ex = {1, 2}; |
| 185 |
bar_ExpectAndReturn(&pt); |
| 186 |
fooa_Expect(&ex); |
| 187 |
|
| 188 |
function_b(); |
| 189 |
} |
| 190 |
|
| 191 |
- :pass: TRUE |
| 192 |
:should: 'handle standard c string as null terminated and not do crappy memory compares of a byte, passing' |
| 193 |
:code: | |
| 194 |
test() |
| 195 |
{ |
| 196 |
const char* constretval = "This is a\0 silly string"; |
| 197 |
char* retval = (char*)constretval; |
| 198 |
bars_ExpectAndReturn(retval); |
| 199 |
foos_Expect("This is a\0 wacky string"); |
| 200 |
|
| 201 |
function_c(); |
| 202 |
} |
| 203 |
|
| 204 |
- :pass: FALSE |
| 205 |
:should: 'handle standard c string as null terminated and not do crappy memory compares of a byte, finding failures' |
| 206 |
:code: | |
| 207 |
test() |
| 208 |
{ |
| 209 |
const char* constretval = "This is a silly string"; |
| 210 |
char* retval = (char*)constretval; |
| 211 |
bars_ExpectAndReturn(retval); |
| 212 |
foos_Expect("This is a wacky string"); |
| 213 |
|
| 214 |
function_c(); |
| 215 |
} |
| 216 |
|
| 217 |
- :pass: TRUE |
| 218 |
:should: 'handle creating array expects when we have mixed arguments for single object' |
| 219 |
:code: | |
| 220 |
test() |
| 221 |
{ |
| 222 |
int expect_list[] = { 1, 9 }; |
| 223 |
no_pointers_Expect(1, "silly"); |
| 224 |
mixed_ExpectAndReturn(6, expect_list, 7, 13); |
| 225 |
|
| 226 |
TEST_ASSERT_EQUAL(13, function_d()); |
| 227 |
} |
| 228 |
|
| 229 |
- :pass: FALSE |
| 230 |
:should: 'handle creating array expects when we have mixed arguments and handle failures for single object' |
| 231 |
:code: | |
| 232 |
test() |
| 233 |
{ |
| 234 |
int expect_list[] = { 9, 1 }; |
| 235 |
no_pointers_Expect(1, "silly"); |
| 236 |
mixed_ExpectAndReturn(6, expect_list, 7, 13); |
| 237 |
|
| 238 |
TEST_ASSERT_EQUAL(13, function_d()); |
| 239 |
} |
| 240 |
|
| 241 |
- :pass: TRUE |
| 242 |
:should: 'handle creating array expects when we have mixed arguments for multiple objects' |
| 243 |
:code: | |
| 244 |
test() |
| 245 |
{ |
| 246 |
int expect_list[] = { 1, 2, 3, 4, 6 }; |
| 247 |
no_pointers_Expect(1, "silly"); |
| 248 |
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13); |
| 249 |
|
| 250 |
TEST_ASSERT_EQUAL(13, function_d()); |
| 251 |
} |
| 252 |
|
| 253 |
- :pass: FALSE |
| 254 |
:should: 'handle creating array expects when we have mixed arguments and handle failures for multiple objects' |
| 255 |
:code: | |
| 256 |
test() |
| 257 |
{ |
| 258 |
int expect_list[] = { 1, 2, 3, 4, 6 }; |
| 259 |
no_pointers_Expect(1, "silly"); |
| 260 |
mixed_ExpectWithArrayAndReturn(6, expect_list, 5, 7, 13); |
| 261 |
|
| 262 |
TEST_ASSERT_EQUAL(13, function_d()); |
| 263 |
} |
| 264 |
|
| 265 |
- :pass: TRUE |
| 266 |
:should: 'handle an exception being caught' |
| 267 |
:code: | |
| 268 |
test() |
| 269 |
{ |
| 270 |
const char* constretval = "This is a\0 silly string"; |
| 271 |
char* retval = (char*)constretval; |
| 272 |
bars_ExpectAndReturn(retval); |
| 273 |
foos_ExpectAndThrow("This is a\0 wacky string", 55); |
| 274 |
foos_Expect("err"); |
| 275 |
|
| 276 |
function_c(); |
| 277 |
} |
| 278 |
|
| 279 |
- :pass: FALSE |
| 280 |
:should: 'handle an exception being caught but still catch following errors' |
| 281 |
:code: | |
| 282 |
test() |
| 283 |
{ |
| 284 |
const char* constretval = "This is a\0 silly string"; |
| 285 |
char* retval = (char*)constretval; |
| 286 |
bars_ExpectAndReturn(retval); |
| 287 |
foos_ExpectAndThrow("This is a\0 wacky string", 55); |
| 288 |
foos_Expect("wrong error"); |
| 289 |
|
| 290 |
function_c(); |
| 291 |
} |
| 292 |
|
| 293 |
- :pass: FALSE |
| 294 |
:should: 'fail strict ordering problems even though we would otherwise have passed' |
| 295 |
:code: | |
| 296 |
test() |
| 297 |
{ |
| 298 |
int expect_list[] = { 1, 2, 3, 4, 6 }; |
| 299 |
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13); |
| 300 |
no_pointers_Expect(1, "silly"); |
| 301 |
|
| 302 |
TEST_ASSERT_EQUAL(13, function_d()); |
| 303 |
} |
| 304 |
|
| 305 |
- :pass: TRUE |
| 306 |
:should: 'properly ExpectAnyArgs first function but the other will work properly' |
| 307 |
:code: | |
| 308 |
test() |
| 309 |
{ |
| 310 |
int expect_list[] = { 1, 2, 3, 4, 6 }; |
| 311 |
no_pointers_ExpectAnyArgs(); |
| 312 |
mixed_ExpectWithArrayAndReturn(6, expect_list, 4, 7, 13); |
| 313 |
|
| 314 |
TEST_ASSERT_EQUAL(13, function_d()); |
| 315 |
} |
| 316 |
|
| 317 |
- :pass: TRUE |
| 318 |
:should: 'properly ExpectAnyArgs last function but the other will work properly' |
| 319 |
:code: | |
| 320 |
test() |
| 321 |
{ |
| 322 |
no_pointers_Expect(1, "silly"); |
| 323 |
mixed_ExpectAnyArgsAndReturn(13); |
| 324 |
|
| 325 |
TEST_ASSERT_EQUAL(13, function_d()); |
| 326 |
} |
| 327 |
|
| 328 |
- :pass: TRUE |
| 329 |
:should: 'be ok if we ExpectAnyArgs a call each because we are counting calls' |
| 330 |
:code: | |
| 331 |
test() |
| 332 |
{ |
| 333 |
foos_ExpectAnyArgs(); |
| 334 |
foos_ExpectAnyArgs(); |
| 335 |
foos_ExpectAnyArgs(); |
| 336 |
|
| 337 |
function_e(); |
| 338 |
} |
| 339 |
|
| 340 |
- :pass: TRUE |
| 341 |
:should: 'be ok if we ExpectAnyArgs and Expect intermixed because we are counting calls' |
| 342 |
:code: | |
| 343 |
test() |
| 344 |
{ |
| 345 |
foos_Expect("Hello"); |
| 346 |
foos_ExpectAnyArgs(); |
| 347 |
foos_ExpectAnyArgs(); |
| 348 |
|
| 349 |
function_e(); |
| 350 |
} |
| 351 |
|
| 352 |
- :pass: FALSE |
| 353 |
:should: 'be able to detect Expect problem if we ExpectAnyArgs and Expect intermixed' |
| 354 |
:code: | |
| 355 |
test() |
| 356 |
{ |
| 357 |
foos_Expect("Hello"); |
| 358 |
foos_ExpectAnyArgs(); |
| 359 |
foos_Expect("Wrong"); |
| 360 |
|
| 361 |
function_e(); |
| 362 |
} |
| 363 |
|
| 364 |
- :pass: FALSE |
| 365 |
:should: 'fail if we do not ExpectAnyArgs a call once because we are counting calls' |
| 366 |
:code: | |
| 367 |
test() |
| 368 |
{ |
| 369 |
foos_ExpectAnyArgs(); |
| 370 |
foos_ExpectAnyArgs(); |
| 371 |
|
| 372 |
function_e(); |
| 373 |
} |
| 374 |
|
| 375 |
... |