| 1 |
--- |
| 2 |
:cmock: |
| 3 |
:plugins: |
| 4 |
- |
| 5 |
:treat_as: |
| 6 |
INT_PTR: INT* |
| 7 |
|
| 8 |
:systest: |
| 9 |
:types: | |
| 10 |
typedef struct _POINT_T { |
| 11 |
int x; |
| 12 |
int y; |
| 13 |
} POINT_T; |
| 14 |
typedef int* INT_PTR; |
| 15 |
|
| 16 |
:mockable: | |
| 17 |
void foo(POINT_T* a); |
| 18 |
POINT_T* bar(void); |
| 19 |
void fooa(POINT_T a[]); |
| 20 |
void foos(const char *a); |
| 21 |
const char* bars(void); |
| 22 |
INT_PTR zoink(INT_PTR a); |
| 23 |
|
| 24 |
:source: |
| 25 |
:header: | |
| 26 |
void function_a(void); |
| 27 |
void function_b(void); |
| 28 |
void function_c(void); |
| 29 |
int function_d(void); |
| 30 |
|
| 31 |
:code: | |
| 32 |
void function_a(void) |
| 33 |
{ |
| 34 |
foo(bar()); |
| 35 |
} |
| 36 |
|
| 37 |
void function_b(void) { |
| 38 |
fooa(bar()); |
| 39 |
} |
| 40 |
|
| 41 |
void function_c(void) { |
| 42 |
foos(bars()); |
| 43 |
} |
| 44 |
|
| 45 |
int function_d(void) { |
| 46 |
int i = 456; |
| 47 |
INT_PTR ptr = (INT_PTR)(&i); |
| 48 |
return (int)(*(zoink(ptr))); |
| 49 |
} |
| 50 |
|
| 51 |
:tests: |
| 52 |
:common: | |
| 53 |
void setUp(void) {} |
| 54 |
void tearDown(void) {} |
| 55 |
|
| 56 |
:units: |
| 57 |
- :pass: TRUE |
| 58 |
:should: 'handle the situation where we pass nulls to pointers' |
| 59 |
:code: | |
| 60 |
test() |
| 61 |
{ |
| 62 |
bar_ExpectAndReturn(NULL); |
| 63 |
foo_Expect(NULL); |
| 64 |
|
| 65 |
function_a(); |
| 66 |
} |
| 67 |
|
| 68 |
- :pass: TRUE |
| 69 |
:should: 'handle the situation where we pass single object with expect' |
| 70 |
:code: | |
| 71 |
test() |
| 72 |
{ |
| 73 |
POINT_T pt = {1, 2}; |
| 74 |
POINT_T ex = {1, 2}; |
| 75 |
bar_ExpectAndReturn(&pt); |
| 76 |
foo_Expect(&ex); |
| 77 |
|
| 78 |
function_a(); |
| 79 |
} |
| 80 |
|
| 81 |
- :pass: FALSE |
| 82 |
:should: 'handle the situation where we pass single object with expect and it is wrong' |
| 83 |
:code: | |
| 84 |
test() |
| 85 |
{ |
| 86 |
POINT_T pt = {1, 2}; |
| 87 |
POINT_T ex = {1, 3}; |
| 88 |
bar_ExpectAndReturn(&pt); |
| 89 |
foo_Expect(&ex); |
| 90 |
|
| 91 |
function_a(); |
| 92 |
} |
| 93 |
|
| 94 |
- :pass: FALSE |
| 95 |
:should: 'handle the situation where we pass nulls to pointers and fail' |
| 96 |
:code: | |
| 97 |
test() |
| 98 |
{ |
| 99 |
POINT_T pt = {1, 2}; |
| 100 |
bar_ExpectAndReturn(&pt); |
| 101 |
foo_Expect(NULL); |
| 102 |
|
| 103 |
function_a(); |
| 104 |
} |
| 105 |
|
| 106 |
- :pass: TRUE |
| 107 |
:should: 'handle the situation where we pass nulls to arrays' |
| 108 |
:code: | |
| 109 |
test() |
| 110 |
{ |
| 111 |
bar_ExpectAndReturn(NULL); |
| 112 |
fooa_Expect(NULL); |
| 113 |
|
| 114 |
function_b(); |
| 115 |
} |
| 116 |
|
| 117 |
- :pass: TRUE |
| 118 |
:should: 'handle the situation where we pass single array element with expect' |
| 119 |
:code: | |
| 120 |
test() |
| 121 |
{ |
| 122 |
POINT_T pt = {1, 2}; |
| 123 |
POINT_T ex = {1, 2}; |
| 124 |
bar_ExpectAndReturn(&pt); |
| 125 |
fooa_Expect(&ex); |
| 126 |
|
| 127 |
function_b(); |
| 128 |
} |
| 129 |
|
| 130 |
- :pass: FALSE |
| 131 |
:should: 'handle the situation where we pass single array element with expect and it is wrong' |
| 132 |
:code: | |
| 133 |
test() |
| 134 |
{ |
| 135 |
POINT_T pt = {1, 2}; |
| 136 |
POINT_T ex = {1, 3}; |
| 137 |
bar_ExpectAndReturn(&pt); |
| 138 |
fooa_Expect(&ex); |
| 139 |
|
| 140 |
function_b(); |
| 141 |
} |
| 142 |
|
| 143 |
- :pass: FALSE |
| 144 |
:should: 'handle the situation where we pass nulls to arrays and fail' |
| 145 |
:code: | |
| 146 |
test() |
| 147 |
{ |
| 148 |
POINT_T pt = {1, 2}; |
| 149 |
bar_ExpectAndReturn(&pt); |
| 150 |
fooa_Expect(NULL); |
| 151 |
|
| 152 |
function_b(); |
| 153 |
} |
| 154 |
|
| 155 |
- :pass: TRUE |
| 156 |
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, passing' |
| 157 |
:code: | |
| 158 |
test() |
| 159 |
{ |
| 160 |
const char* retval = "This is a\0 silly string"; |
| 161 |
bars_ExpectAndReturn((char*)retval); |
| 162 |
foos_Expect("This is a\0 wacky string"); |
| 163 |
|
| 164 |
function_c(); |
| 165 |
} |
| 166 |
|
| 167 |
- :pass: FALSE |
| 168 |
:should: 'handle standard c string as null terminated on not do crappy memory compares of a byte, finding failures' |
| 169 |
:code: | |
| 170 |
test() |
| 171 |
{ |
| 172 |
const char* retval = "This is a silly string"; |
| 173 |
bars_ExpectAndReturn((char*)retval); |
| 174 |
foos_Expect("This is a wacky string"); |
| 175 |
|
| 176 |
function_c(); |
| 177 |
} |
| 178 |
|
| 179 |
- :pass: TRUE |
| 180 |
:should: 'handle handle typedefs that ARE pointers by using treat_as' |
| 181 |
:code: | |
| 182 |
test() |
| 183 |
{ |
| 184 |
int e = 456; |
| 185 |
int r = 789; |
| 186 |
INT_PTR ptr_e = (INT_PTR)(&e); |
| 187 |
INT_PTR ptr_r = (INT_PTR)(&r); |
| 188 |
|
| 189 |
zoink_ExpectAndReturn(ptr_e, ptr_r); |
| 190 |
|
| 191 |
TEST_ASSERT_EQUAL(r, function_d()); |
| 192 |
} |
| 193 |
|
| 194 |
- :pass: FALSE |
| 195 |
:should: 'handle handle typedefs that ARE pointers by using treat_as and catch failures' |
| 196 |
:code: | |
| 197 |
test() |
| 198 |
{ |
| 199 |
int e = 457; |
| 200 |
int r = 789; |
| 201 |
INT_PTR ptr_e = (INT_PTR)(&e); |
| 202 |
INT_PTR ptr_r = (INT_PTR)(&r); |
| 203 |
|
| 204 |
zoink_ExpectAndReturn(ptr_e, ptr_r); |
| 205 |
|
| 206 |
TEST_ASSERT_EQUAL(r, function_d()); |
| 207 |
} |
| 208 |
|
| 209 |
|
| 210 |
... |