RKH
test_utrzexpect.c
Go to the documentation of this file.
1 
13 /* -------------------------- Development history -------------------------- */
14 /*
15  * 2015.11.11 LeFr v1.0.00 Initial version
16  */
17 
18 /* -------------------------------- Authors -------------------------------- */
19 /*
20  * LeFr Leandro Francucci francuccilea@gmail.com
21  */
22 
23 /* --------------------------------- Notes --------------------------------- */
24 /* ----------------------------- Include files ----------------------------- */
25 
26 #include "unity_fixture.h"
27 #include "unitrazer.h"
28 #include "rkh.h"
29 #include "aotest.h"
30 #include "aotest_act.h"
31 #include "test_common.h"
32 
33 /* ----------------------------- Local macros ------------------------------ */
34 #define str(a) #a
35 
36 #define utrzExpect_Ok_check() \
37  { \
38  UtrzProcessOut *p; \
39  p = unitrazer_getLastOut(); \
40  TEST_ASSERT_EQUAL(UT_PROC_SUCCESS, p->status); \
41  }
42 
43 #define utrzExpect_OutOfSequence_check(ex, rc) \
44  { \
45  UtrzProcessOut *p; \
46  p = unitrazer_getLastOut(); \
47  TEST_ASSERT_EQUAL(UT_PROC_FAIL, p->status); \
48  TEST_ASSERT_EQUAL_STRING("Out of order Trace event." \
49  " occurred: '"rc"' expected: '"ex"'.", p->msg); \
50  }
51 
52 #define utrzExpect_WithUnexpectedArg_check( ev, an, e, r ) \
53  { \
54  UtrzProcessOut *p; \
55  p = unitrazer_getLastOut(); \
56  TEST_ASSERT_EQUAL(UT_PROC_FAIL, p->status); \
57  TEST_ASSERT_EQUAL_STRING("Event '"ev"' occurred with unexpected " \
58  "value for argument '"an"="r"' expected " \
59  "value='"e"'.", p->msg); \
60  }
61 
62 #define utrzExpect_WithUnexpectedArgNoName_check( ev, e, r ) \
63  { \
64  UtrzProcessOut *p; \
65  p = unitrazer_getLastOut(); \
66  TEST_ASSERT_EQUAL(UT_PROC_FAIL, p->status); \
67  TEST_ASSERT_EQUAL_STRING("Event '"ev"' occurred with unexpected " \
68  "value for argument '"r"' expected " \
69  "value='"e"'.", p->msg); \
70  }
71 
72 /* ------------------------------- Constants ------------------------------- */
73 /* ---------------------------- Local data types --------------------------- */
74 /* ---------------------------- Global variables --------------------------- */
75 
76 TEST_GROUP(utrzExpect);
77 
78 /* ---------------------------- Local variables ---------------------------- */
79 /* ----------------------- Local function prototypes ----------------------- */
80 /* ---------------------------- Local functions ---------------------------- */
81 /* ---------------------------- Global functions --------------------------- */
82 
83 TEST_SETUP(utrzExpect)
84 {
85  /* -------- Setup ---------------
86  * Establish the preconditions to the test
87  */
88  common_test_setup();
89 }
90 
91 TEST_TEAR_DOWN(utrzExpect)
92 {
93  /* -------- Cleanup -------------
94  * Return the system under test to its initial state after the test
95  */
96  common_tear_down();
97 }
98 
106 TEST(utrzExpect, sm_init_Ok)
107 {
108  sm_init_expect(CST(&s21));
109 
110  RKH_TR_SM_INIT(aotest, &s21);
111 
112  utrzExpect_Ok_check();
113 }
114 
115 TEST(utrzExpect, sm_init_OutOfSequence)
116 {
117  sm_init_expect(CST(&s21));
118 
119  RKH_TR_SM_ENSTATE(aotest, CST(&s21));
120 
121  utrzExpect_OutOfSequence_check( "INIT", "ENSTATE" );
122 }
123 
124 TEST(utrzExpect, sm_init_WithUnexpectedArg)
125 {
126  sm_init_expect(CST(&s21));
127 
128  RKH_TR_SM_INIT(aotest, &s211);
129 
130  utrzExpect_WithUnexpectedArg_check( "INIT", "ist", str(s21), str(s211) );
131 }
132 
133 TEST(utrzExpect, sm_clrh_Ok)
134 {
135  sm_clrh_expect(CST(&s21));
136 
137  RKH_TR_SM_CLRH(aotest, &s21);
138 
139  utrzExpect_Ok_check();
140 }
141 
142 TEST(utrzExpect, sm_clrh_OutOfSequence)
143 {
144  sm_clrh_expect(CST(&s21));
145 
146  RKH_TR_SM_ENSTATE(aotest, CST(&s21));
147 
148  utrzExpect_OutOfSequence_check( "CLRH", "ENSTATE" );
149 }
150 
151 TEST(utrzExpect, sm_clrh_WithUnexpectedArg)
152 {
153  sm_clrh_expect(CST(&s21));
154 
155  RKH_TR_SM_CLRH(aotest, &s211);
156 
157  utrzExpect_WithUnexpectedArg_check( "CLRH", "h", str(s21), str(s211) );
158 }
159 
160 TEST(utrzExpect, sm_trn_Ok)
161 {
162  sm_trn_expect(CST(&s21), CST(&s211));
163 
164  RKH_TR_SM_TRN(aotest, &s21, &s211);
165 
166  utrzExpect_Ok_check();
167 }
168 
169 TEST(utrzExpect, sm_trn_OutOfSequence)
170 {
171  sm_trn_expect(CST(&s21), CST(&s211));
172 
173  RKH_TR_SM_ENSTATE(aotest, CST(&s21));
174 
175  utrzExpect_OutOfSequence_check( "TRN", "ENSTATE" );
176 }
177 
178 TEST(utrzExpect, sm_trn_WithUnexpectedArg)
179 {
180  sm_trn_expect(CST(&s21), CST(&s211));
181 
182  RKH_TR_SM_TRN(aotest, &s21, &s21);
183 
184  utrzExpect_WithUnexpectedArg_check( "TRN", "tst", str(s211), str(s21) );
185 
186  sm_trn_expect(CST(&s21), CST(&s211));
187 
188  RKH_TR_SM_TRN(aotest, &s211, &s211);
189 
190  utrzExpect_WithUnexpectedArg_check( "TRN", "sst", str(s21), str(s211) );
191 }
192 
193 
194 TEST(utrzExpect, sm_trn_WithAnyArgs)
195 {
196  sm_trn_expectAnyArgs();
197 
198  RKH_TR_SM_TRN(aotest, &s211, &s211);
199 
200  utrzExpect_Ok_check();
201 }
202 
203 TEST(utrzExpect, sm_state_Ok)
204 {
205  sm_state_expect(CST(&s21));
206 
207  RKH_TR_SM_STATE(aotest, &s21);
208 
209  utrzExpect_Ok_check();
210 }
211 
212 TEST(utrzExpect, sm_state_OutOfSequence)
213 {
214  sm_state_expect(CST(&s21));
215 
216  RKH_TR_SM_ENSTATE(aotest, CST(&s21));
217 
218  utrzExpect_OutOfSequence_check( "STATE", "ENSTATE" );
219 }
220 
221 TEST(utrzExpect, sm_state_WithUnexpectedArg)
222 {
223  sm_state_expect(CST(&s21));
224 
225  RKH_TR_SM_STATE(aotest, &s211);
226 
227  utrzExpect_WithUnexpectedArg_check( "STATE", "nxtst", str(s21), str(s211) );
228 }
229 
230 TEST(utrzExpect, sm_enstate_Ok)
231 {
232  sm_enstate_expect(CST(&s21));
233 
234  RKH_TR_SM_ENSTATE(aotest, &s21);
235 
236  utrzExpect_Ok_check();
237 }
238 
239 TEST(utrzExpect, sm_enstate_OutOfSequence)
240 {
241  sm_enstate_expect(CST(&s21));
242 
243  RKH_TR_SM_STATE(aotest, &s21);
244 
245  utrzExpect_OutOfSequence_check( "ENSTATE", "STATE" );
246 }
247 
248 TEST(utrzExpect, sm_enstate_WithUnexpectedArg)
249 {
250  sm_enstate_expect(CST(&s21));
251 
252  RKH_TR_SM_ENSTATE(aotest, &s211);
253 
254  utrzExpect_WithUnexpectedArg_check( "ENSTATE", "st", str(s21), str(s211) );
255 }
256 
257 TEST(utrzExpect, sm_exstate_Ok)
258 {
259  sm_exstate_expect(CST(&s21));
260 
261  RKH_TR_SM_EXSTATE(aotest, &s21);
262 
263  utrzExpect_Ok_check();
264 }
265 
266 TEST(utrzExpect, sm_exstate_OutOfSequence)
267 {
268  sm_exstate_expect(CST(&s21));
269 
270  RKH_TR_SM_STATE(aotest, &s21);
271 
272  utrzExpect_OutOfSequence_check( "EXSTATE", "STATE" );
273 }
274 
275 TEST(utrzExpect, sm_exstate_WithUnexpectedArg)
276 {
277  sm_exstate_expect(CST(&s21));
278 
279  RKH_TR_SM_EXSTATE(aotest, &s211);
280 
281  utrzExpect_WithUnexpectedArg_check( "EXSTATE", "st", str(s21), str(s211) );
282 }
283 
284 TEST(utrzExpect, sm_nenex_Ok)
285 {
286  sm_nenex_expect(2,3);
287 
288  RKH_TR_SM_NENEX(aotest, 2, 3);
289 
290  utrzExpect_Ok_check();
291 }
292 
293 TEST(utrzExpect, sm_nenex_OutOfSequence)
294 {
295  sm_nenex_expect(2,3);
296 
297  RKH_TR_SM_STATE(aotest, &s21);
298 
299  utrzExpect_OutOfSequence_check( "NENEX", "STATE" );
300 }
301 
302 TEST(utrzExpect, sm_nenex_WithUnexpectedArg)
303 {
304  sm_nenex_expect(2,3);
305 
306  RKH_TR_SM_NENEX(aotest, 3, 3);
307 
308  utrzExpect_WithUnexpectedArg_check("NENEX", "nen", "2", "3");
309 
310  sm_nenex_expect(2,3);
311 
312  RKH_TR_SM_NENEX(aotest, 2, 2);
313 
314  utrzExpect_WithUnexpectedArg_check("NENEX", "nex", "3", "2");
315 }
316 
317 TEST(utrzExpect, sm_ntrnact_Ok)
318 {
319  sm_ntrnact_expect(2,3);
320 
321  RKH_TR_SM_NTRNACT(aotest, 2, 3);
322 
323  utrzExpect_Ok_check();
324 }
325 
326 TEST(utrzExpect, sm_ntrnact_OutOfSequence)
327 {
328  sm_ntrnact_expect(2,3);
329 
330  RKH_TR_SM_STATE(aotest, &s21);
331 
332  utrzExpect_OutOfSequence_check( "NTRNACT", "STATE" );
333 }
334 
335 TEST(utrzExpect, sm_ntrnact_WithUnexpectedArg)
336 {
337  sm_ntrnact_expect(2,3);
338 
339  RKH_TR_SM_NTRNACT(aotest, 3, 3);
340 
341  utrzExpect_WithUnexpectedArg_check("NTRNACT", "nta", "2", "3");
342 
343  sm_ntrnact_expect(2,3);
344 
345  RKH_TR_SM_NTRNACT(aotest, 2, 2);
346 
347  utrzExpect_WithUnexpectedArg_check("NTRNACT", "nts", "3", "2");
348 }
349 
350 TEST(utrzExpect, sm_tsstate_Ok)
351 {
352  sm_tsState_expect(CST(&s21));
353 
354  RKH_TR_SM_TS_STATE(aotest, &s21);
355 
356  utrzExpect_Ok_check();
357 }
358 
359 TEST(utrzExpect, sm_tsstate_OutOfSequence)
360 {
361  sm_tsState_expect(CST(&s21));
362 
363  RKH_TR_SM_STATE(aotest, &s21);
364 
365  utrzExpect_OutOfSequence_check( "TS_STATE", "STATE" );
366 }
367 
368 TEST(utrzExpect, sm_tsstate_WithUnexpectedArg)
369 {
370  sm_tsState_expect(CST(&s21));
371 
372  RKH_TR_SM_TS_STATE(aotest, &s211);
373 
374  utrzExpect_WithUnexpectedArg_check("TS_STATE", "st", str(s21), str(s211) );
375 }
376 
377 TEST(utrzExpect, sm_evtproc_Ok)
378 {
379  sm_evtProc_expect();
380 
381  RKH_TR_SM_EVT_PROC(aotest);
382 
383  utrzExpect_Ok_check();
384 }
385 
386 TEST(utrzExpect, sm_evtproc_OutOfSequence)
387 {
388  sm_evtProc_expect();
389 
390  RKH_TR_SM_STATE(aotest, &s21);
391 
392  utrzExpect_OutOfSequence_check( "EVT_PROC", "STATE" );
393 }
394 
395 TEST(utrzExpect, sm_evtnfound_Ok)
396 {
397  RKH_STATIC_EVENT(e, A);
398 
399  sm_evtNotFound_expect(A);
400 
401  RKH_TR_SM_EVT_NFOUND(aotest, (&e));
402 
403  utrzExpect_Ok_check();
404 }
405 
406 TEST(utrzExpect, sm_evtnfound_OutOfSequence)
407 {
408  sm_evtNotFound_expect(A);
409 
410  RKH_TR_SM_STATE(aotest, &s21);
411 
412  utrzExpect_OutOfSequence_check( "EVT_NFOUND", "STATE" );
413 }
414 
415 TEST(utrzExpect, sm_evtnfound_WithUnexpectedArg)
416 {
417  RKH_STATIC_EVENT(ev, B);
418 
419  sm_evtNotFound_expect(A);
420 
421  RKH_TR_SM_EVT_NFOUND(aotest, (&ev));
422 
423  utrzExpect_WithUnexpectedArg_check("EVT_NFOUND", "sig", str(A), str(B));
424 }
425 
426 TEST(utrzExpect, sm_grdfalse_Ok)
427 {
428  sm_grdFalse_expect();
429 
430  RKH_TR_SM_GRD_FALSE(aotest);
431 
432  utrzExpect_Ok_check();
433 }
434 
435 TEST(utrzExpect, sm_grdfalse_OutOfSequence)
436 {
437  sm_grdFalse_expect();
438 
439  RKH_TR_SM_STATE(aotest, &s21);
440 
441  utrzExpect_OutOfSequence_check( "GRD_FALSE", "STATE" );
442 }
443 
444 TEST(utrzExpect, sm_cndnfound_Ok)
445 {
446  sm_cndNotFound_expect();
447 
448  RKH_TR_SM_CND_NFOUND(aotest);
449 
450  utrzExpect_Ok_check();
451 }
452 
453 TEST(utrzExpect, sm_cndnfound_OutOfSequence)
454 {
455  sm_cndNotFound_expect();
456 
457  RKH_TR_SM_STATE(aotest, &s21);
458 
459  utrzExpect_OutOfSequence_check( "CND_NFOUND", "STATE" );
460 }
461 
462 TEST(utrzExpect, sm_unkstate_Ok)
463 {
464  sm_unknState_expect();
465 
466  RKH_TR_SM_UNKN_STATE(aotest);
467 
468  utrzExpect_Ok_check();
469 }
470 
471 TEST(utrzExpect, sm_unkstate_OutOfSequence)
472 {
473  sm_unknState_expect();
474 
475  RKH_TR_SM_STATE(aotest, &s21);
476 
477  utrzExpect_OutOfSequence_check( "UNKN_STATE", "STATE" );
478 }
479 
480 TEST(utrzExpect, sm_exhlevel_Ok)
481 {
482  sm_exHLevel_expect();
483 
484  RKH_TR_SM_EX_HLEVEL(aotest);
485 
486  utrzExpect_Ok_check();
487 }
488 
489 TEST(utrzExpect, sm_exhlevel_OutOfSequence)
490 {
491  sm_exHLevel_expect();
492 
493  RKH_TR_SM_STATE(aotest, &s21);
494 
495  utrzExpect_OutOfSequence_check( "EX_HLEVEL", "STATE" );
496 }
497 
498 TEST(utrzExpect, sm_extseg_Ok)
499 {
500  sm_exTSeg_expect();
501 
502  RKH_TR_SM_EX_TSEG(aotest);
503 
504  utrzExpect_Ok_check();
505 }
506 
507 TEST(utrzExpect, sm_extseg_OutOfSequence)
508 {
509  sm_exTSeg_expect();
510 
511  RKH_TR_SM_STATE(aotest, &s21);
512 
513  utrzExpect_OutOfSequence_check( "EX_TSEG", "STATE" );
514 }
515 
516 TEST(utrzExpect, sm_exeAct_Ok)
517 {
518  sm_exeAct_expect(RKH_SUBTE_SM_EXE_ACT_EN,
519  CST(&s21), foo_set2zero );
520 
521  RKH_TR_SM_EXE_ACT( RKH_SUBTE_SM_EXE_ACT_EN, aotest, &s21, foo_set2zero );
522 
523  utrzExpect_Ok_check();
524 }
525 
526 TEST(utrzExpect, sm_exeAct_OutOfSequence)
527 {
528  sm_exeAct_expect(RKH_SUBTE_SM_EXE_ACT_EN,
529  CST(&s21), foo_set2zero );
530 
531  RKH_TR_SM_ENSTATE(aotest, CST(&s21));
532 
533  utrzExpect_OutOfSequence_check( "EXE_ACT", "ENSTATE" );
534 }
535 
536 TEST(utrzExpect, sm_exeAct_WithUnexpectedArg)
537 {
538  sm_exeAct_expect(RKH_SUBTE_SM_EXE_ACT_EN,
539  CST(&s21), foo_set2zero );
540 
541  RKH_TR_SM_EXE_ACT( RKH_SUBTE_SM_EXE_ACT_EN, aotest, &s211, foo_set2zero );
542 
543  utrzExpect_WithUnexpectedArg_check("EXE_ACT", "st", str(s21), str(s211));
544 
545  sm_exeAct_expect(RKH_SUBTE_SM_EXE_ACT_EN,
546  CST(&s21), foo_set2zero );
547 
548  RKH_TR_SM_EXE_ACT( RKH_SUBTE_SM_EXE_ACT_EN, aotest, &s21, foo_set2one );
549 
550  utrzExpect_WithUnexpectedArg_check("EXE_ACT", "fn",
551  str(foo_set2zero), str(foo_set2one));
552 
553  sm_exeAct_expect(RKH_SUBTE_SM_EXE_ACT_EN,
554  CST(&s21), foo_set2zero );
555 
556  RKH_TR_SM_EXE_ACT( RKH_SUBTE_SM_EXE_ACT_EX, aotest, &s21, foo_set2one );
557 
558  utrzExpect_WithUnexpectedArgNoName_check("EXE_ACT", "Entry", "Exit");
559 }
560 
561 TEST(utrzExpect, sm_exeAct_WithAnyArgs)
562 {
563  sm_exeAct_expectAnyArgs();
564 
565  RKH_TR_SM_EXE_ACT( RKH_SUBTE_SM_EXE_ACT_INI, aotest, &s211, foo_set2one );
566 
567  utrzExpect_Ok_check();
568 }
569 
574 /* ------------------------------ End of file ------------------------------ */
#define RKH_TR_SM_EXE_ACT(actionType_, actObj_, state_, action_)
Executes a behavior (action) of state machine, it could be an entry, exit, effect, init, preprocessor or guard.
#define RKH_TR_SM_EVT_PROC(actObj_)
The arrived event was succesfully processed and HSM resides in an allowed state.
Executes a behavior (action) of state machine, it could be an entry, exit, effect, init, preprocessor or guard.
#define RKH_TR_SM_STATE(actObj_, state_)
Legal, stable and final state of transition.
#define RKH_TR_SM_EX_TSEG(actObj_)
The transition exceeded the allowed number of segments within a compound transtion.
#define RKH_TR_SM_NENEX(actObj_, nEnState_, nExState_)
Number of entry and exit states in transition.
#define RKH_TR_SM_TS_STATE(actObj_, state_)
Destination state or pseudostate of a transition segment.
#define RKH_TR_SM_INIT(actObj_, initState_)
Inits a previously created state machine calling its initializing action.
Interface of unit test with Trazer application.
#define RKH_TR_SM_UNKN_STATE(actObj_)
Unknown state.
#define RKH_TR_SM_CLRH(actObj_, history_)
Erase the history of a state. It can be a shallow or deep history.
#define RKH_TR_SM_EVT_NFOUND(actObj_, evt_)
The arrived event was't founded in the transition table.
#define RKH_TR_SM_CND_NFOUND(actObj_)
The branch function returned a value not founded in the branch table.
#define RKH_TR_SM_NTRNACT(actObj_, nta, nts)
Number of executed actions and segments of the transition.
RKH framwwork platform - independent interface.
Executes a behavior (action) of state machine, it could be an entry, exit, effect, init, preprocessor or guard.
Executes a behavior (action) of state machine, it could be an entry, exit, effect, init, preprocessor or guard.
#define RKH_STATIC_EVENT(ev_obj, ev_sig)
This macro declares and initializes the event structure ev_ob with ev_sig signal number and establish...
#define RKH_TR_SM_EXSTATE(actObj_, state_)
Exited state.
#define RKH_TR_SM_EX_HLEVEL(actObj_)
The transition exceeded the allowed hierarchical level.
#define RKH_TR_SM_TRN(actObj_, sourceState_, targetState_)
Source and target state of the transition. The target could be either basic state, composite state or pseudostate.
#define RKH_TR_SM_ENSTATE(actObj_, state_)
Entered state.
#define RKH_TR_SM_GRD_FALSE(actObj_)
The transition was cancelled by guard function.