2 #include "ExampleCalls.h"
29 static RecordedCall * Mock_TakesTwoArgs(uint8_t b1, uint8_t b2)
31 char const *call_name =
"TakesTwoArgs";
32 RecordedCall *record_of_call = RecordedCall_new(call_name);
33 RecordedArg *record_of_arg1 = RecordedArg_new(SetupRecord_uint8_t);
34 *((uint8_t *)record_of_arg1->pArg) = b1;
35 RecordedArg *record_of_arg2 = RecordedArg_new(SetupRecord_uint8_t);
36 *((uint8_t *)record_of_arg2->pArg) = b2;
37 RecordArg(record_of_call, record_of_arg1);
38 RecordArg(record_of_call, record_of_arg2);
39 return record_of_call;
41 void SetUp_AssertCall(
void){
44 uint8_t call1_arg1 = 11; uint8_t call1_arg2 = 12;
45 uint8_t call2_arg1 = 21; uint8_t call2_arg2 = 22;
46 RecordActualCall(mock, Mock_TakesTwoArgs(call1_arg1, call1_arg2));
47 RecordActualCall(mock, Mock_TakesTwoArgs(call2_arg1, call2_arg2));
49 void TearDown_AssertCall(
void){
55 void AssertCall_returns_false_if_call_number_exceeds_call_list(
void){
57 TEST_ASSERT_FALSE(AssertCall(mock,100,
"TakesTwoArgs"));
59 void AssertCall_returns_false_if_call_n_does_not_match_name(
void)
62 TEST_ASSERT_FALSE(AssertCall(mock,1,
"WrongCallName"));
64 void AssertCall_returns_true_if_call_n_matches_name(
void)
67 TEST_ASSERT_TRUE(AssertCall(mock,1,
"TakesTwoArgs"));
69 void AssertArg_returns_false_if_call_number_exceeds_call_list(
void)
72 uint8_t arg_n = 1; uint8_t assert_val = 11;
73 TEST_ASSERT_FALSE(AssertArg(mock, 100, arg_n, &assert_val));
75 void AssertArg_returns_false_if_arg_number_exceeds_arg_list(
void)
78 uint8_t call_n = 1; uint8_t assert_val = 11;
79 TEST_ASSERT_FALSE(AssertArg(mock, call_n, 100, &assert_val));
81 void AssertArg_returns_true_if_arg_1_in_call_1_matches_uint8_arg_value(
void)
84 uint8_t call_n = 1; uint8_t arg_n = 1; uint8_t assert_val = 11;
85 TEST_ASSERT_TRUE(AssertArg(mock, call_n, arg_n, &assert_val));
87 void AssertArg_returns_true_if_arg_2_in_call_1_matches_uint8_arg_value(
void)
90 uint8_t call_n = 1; uint8_t arg_n = 2; uint8_t assert_val = 12;
91 TEST_ASSERT_TRUE(AssertArg(mock, call_n, arg_n, &assert_val));
93 void AssertArg_returns_true_if_arg_1_in_call_2_matches_uint8_arg_value(
void)
96 uint8_t call_n = 2; uint8_t arg_n = 1; uint8_t assert_val = 21;
97 TEST_ASSERT_TRUE(AssertArg(mock, call_n, arg_n, &assert_val));
99 void AssertArg_returns_true_if_arg_2_in_call_2_matches_uint8_arg_value(
void)
102 uint8_t call_n = 2; uint8_t arg_n = 2; uint8_t assert_val = 22;
104 TEST_ASSERT_TRUE(AssertArg(mock, call_n, arg_n, &assert_val));
106 void NumberOfActualCalls_returns_number_of_actual_calls_recorded_in_mock(
void)
109 TEST_ASSERT_EQUAL_UINT8(2, NumberOfActualCalls(mock));
112 void SetUp_libMock(
void){
116 void TearDown_libMock(
void){
122 void RanAsHoped_returns_true_if_call_lists_match(
void)
125 TakesNoArg_Stubbed();
126 TEST_ASSERT_TRUE_MESSAGE(
131 void RanAsHoped_returns_false_if_more_expected_calls_than_actual_calls(
void)
135 TEST_ASSERT_FALSE(RanAsHoped(mock));
137 void RanAsHoped_returns_false_if_more_actual_calls_than_expected_calls(
void)
139 SpanishInquisition_Stubbed();
140 TEST_ASSERT_FALSE(RanAsHoped(mock));
142 void RanAsHoped_returns_false_if_call_names_do_not_match(
void)
145 SpanishInquisition_Stubbed();
146 TEST_ASSERT_FALSE(RanAsHoped(mock));
148 void RanAsHoped_returns_false_if_a_call_expected_more_inputs(
void)
150 Expect_TakesTwoArgs(0xa1, 0xa2);
151 TakesOneArg_StubbedWithCallName_TakesTwoArgs(0xa1);
152 TEST_ASSERT_FALSE(RanAsHoped(mock));
154 void RanAsHoped_returns_false_if_a_call_expected_less_inputs(
void)
156 Expect_TakesOneArg(0xb1);
157 TakesTwoArgs_StubbedWithCallName_TakesOneArg(0xb1, 0xb2);
158 TEST_ASSERT_FALSE(RanAsHoped(mock));
160 void RanAsHoped_returns_false_if_a_call_has_the_wrong_input_value(
void)
162 Expect_TakesOneArg(0xAA);
163 TakesOneArg_Stubbed(0xFF);
164 TEST_ASSERT_FALSE(RanAsHoped(mock));
166 void WhyDidItFail_reports_unexpected_calls(
void)
169 SpanishInquisition_Stubbed();
170 TEST_ASSERT_FALSE(RanAsHoped(mock));
171 TEST_ASSERT_EQUAL_STRING(
172 " Call #1: expected 'TakesNoArg',"
173 " was 'SpanishInquisition'."
178 void WhyDidItFail_reports_when_calls_are_out_of_order(
void)
181 Expect_TakesOneArg(0x01);
182 Expect_TakesTwoArgs(0x02,0x03);
183 Expect_TakesOneArg(0xAA);
184 TakesNoArg_Stubbed();
185 TakesTwoArgs_Stubbed(0x02,0x03);
186 TakesOneArg_Stubbed(0x01);
187 TakesOneArg_Stubbed(0xAA);
188 TEST_ASSERT_FALSE(RanAsHoped(mock));
189 TEST_ASSERT_EQUAL_STRING(
190 " Wrong number of args in call #2 'TakesOneArg',"
191 " expected 1, was 2."
192 " Wrong number of args in call #3 'TakesTwoArgs',"
193 " expected 2, was 1."
194 " Call #2: expected 'TakesOneArg',"
195 " was 'TakesTwoArgs'."
196 " Call #2: 'TakesOneArg' expected input '(uint8_t)0x01',"
197 " but was '(uint8_t)0x02'."
198 " Call #3: expected 'TakesTwoArgs',"
199 " was 'TakesOneArg'."
200 " Call #3: 'TakesTwoArgs' expected input '(uint8_t)0x02',"
201 " but was '(uint8_t)0x01'."
206 void WhyDidItFail_reports_first_unexpected_call_after_last_expected_call(
void)
209 Expect_TakesOneArg(0x01);
210 TakesNoArg_Stubbed();
211 TakesOneArg_Stubbed(0x01);
212 TakesTwoArgs_Stubbed(0x02,0x03);
213 TEST_ASSERT_FALSE(RanAsHoped(mock));
214 TEST_ASSERT_EQUAL_STRING(
215 " Expected 2 calls, received 3 calls."
216 " First unexpected call: received #3:'TakesTwoArgs'."
221 void WhyDidItFail_reports_first_missed_call_after_last_actual_call(
void)
224 Expect_TakesOneArg(0x01);
225 Expect_TakesTwoArgs(0x02,0x03);
226 TakesNoArg_Stubbed();
227 TakesOneArg_Stubbed(0x01);
228 TEST_ASSERT_FALSE(RanAsHoped(mock));
229 TEST_ASSERT_EQUAL_STRING(
230 " Expected 3 calls, received 2 calls."
231 " First missed call: expected #3:'TakesTwoArgs'."