56 #include "unity_fixture.h"
61 #include "smTestAct.h"
62 #include "MocksmTestAct.h"
63 #include "Mockrkhassert.h"
80 typedef struct StateMachine
86 typedef struct Composite
94 TEST_GROUP(trnWoutUnitrazer);
102 TEST_SETUP(trnWoutUnitrazer)
104 MocksmTestAct_Init();
108 TEST_TEAR_DOWN(trnWoutUnitrazer)
110 MocksmTestAct_Verify();
111 MocksmTestAct_Destroy();
121 TEST(trnWoutUnitrazer, firstStateAfterInit)
123 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
124 expectedState = RKH_STATE_CAST(&waiting);
128 TEST_ASSERT_TRUE(expectedState == getState(smTest));
131 TEST(trnWoutUnitrazer, simpleToSimpleAtEqualLevel)
133 expectedState = RKH_STATE_CAST(&s1);
135 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
136 smTest_xS0_Expect(
RKH_CAST(SmTest, smTest));
137 smTest_tr11_Expect(
RKH_CAST(SmTest, smTest), &evA);
138 smTest_nS1_Expect(
RKH_CAST(SmTest, smTest));
139 setProfileWoutUnitrazer(smTest,
147 TEST_ASSERT_TRUE(expectedState == getState(smTest));
151 TEST(trnWoutUnitrazer, simpleToSimpleFromHighToLowLevel)
153 expectedState = RKH_STATE_CAST(&s21);
155 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
156 smTest_xS0_Expect(
RKH_CAST(SmTest, smTest));
157 smTest_tr12_Expect(
RKH_CAST(SmTest, smTest), &evB);
158 smTest_nS2_Expect(
RKH_CAST(SmTest, smTest));
159 smTest_nS21_Expect(
RKH_CAST(SmTest, smTest));
160 setProfileWoutUnitrazer(smTest,
168 TEST_ASSERT_TRUE(expectedState == getState(smTest));
172 TEST(trnWoutUnitrazer, simpleToSimpleFromLowToHighLevel)
174 expectedState = RKH_STATE_CAST(&s0);
176 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
177 smTest_xS21_Expect(
RKH_CAST(SmTest, smTest));
178 smTest_xS2_Expect(
RKH_CAST(SmTest, smTest));
179 smTest_tr13_Expect(
RKH_CAST(SmTest, smTest), &evB);
180 smTest_nS0_Expect(
RKH_CAST(SmTest, smTest));
181 setProfileWoutUnitrazer(smTest,
182 RKH_STATE_CAST(&s21),
183 RKH_STATE_CAST(&s21),
189 TEST_ASSERT_TRUE(expectedState == getState(smTest));
193 TEST(trnWoutUnitrazer, simpleToCompositeAtEqualLevel)
195 expectedState = RKH_STATE_CAST(&s21);
197 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
198 smTest_xS0_Expect(
RKH_CAST(SmTest, smTest));
199 smTest_tr21_Expect(
RKH_CAST(SmTest, smTest), &evC);
200 smTest_nS2_Expect(
RKH_CAST(SmTest, smTest));
201 smTest_iS2_Expect(
RKH_CAST(SmTest, smTest));
202 smTest_nS21_Expect(
RKH_CAST(SmTest, smTest));
203 setProfileWoutUnitrazer(smTest,
211 TEST_ASSERT_TRUE(expectedState == getState(smTest));
215 TEST(trnWoutUnitrazer, simpleToCompositeFromHighToLowLevel)
217 expectedState = RKH_STATE_CAST(&s2211);
219 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
220 smTest_xS0_Expect(
RKH_CAST(SmTest, smTest));
221 smTest_tr22_Expect(
RKH_CAST(SmTest, smTest), &evD);
222 smTest_nS2_Expect(
RKH_CAST(SmTest, smTest));
223 smTest_nS22_Expect(
RKH_CAST(SmTest, smTest));
224 smTest_iS22_Expect(
RKH_CAST(SmTest, smTest));
225 smTest_nS221_Expect(
RKH_CAST(SmTest, smTest));
226 smTest_iS221_Expect(
RKH_CAST(SmTest, smTest));
227 smTest_nS2211_Expect(
RKH_CAST(SmTest, smTest));
228 setProfileWoutUnitrazer(smTest,
236 TEST_ASSERT_TRUE(expectedState == getState(smTest));
240 TEST(trnWoutUnitrazer, simpleToCompositeFromLowToHighLevel)
242 expectedState = RKH_STATE_CAST(&s21);
244 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
245 smTest_xS21_Expect(
RKH_CAST(SmTest, smTest));
246 smTest_tr23_Expect(
RKH_CAST(SmTest, smTest), &evC);
247 smTest_iS2_Expect(
RKH_CAST(SmTest, smTest));
248 smTest_nS21_Expect(
RKH_CAST(SmTest, smTest));
249 setProfileWoutUnitrazer(smTest,
250 RKH_STATE_CAST(&s21),
251 RKH_STATE_CAST(&s21),
257 TEST_ASSERT_TRUE(expectedState == getState(smTest));
261 TEST(trnWoutUnitrazer, compositeToSimpleAtEqualLevel)
263 expectedState = RKH_STATE_CAST(&s0);
265 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
266 smTest_xS21_Expect(
RKH_CAST(SmTest, smTest));
267 smTest_xS2_Expect(
RKH_CAST(SmTest, smTest));
268 smTest_tr31_Expect(
RKH_CAST(SmTest, smTest), &evA);
269 smTest_nS0_Expect(
RKH_CAST(SmTest, smTest));
270 setProfileWoutUnitrazer(smTest,
271 RKH_STATE_CAST(&s21),
278 TEST_ASSERT_TRUE(expectedState == getState(smTest));
282 TEST(trnWoutUnitrazer, compositeToSimpleFromHighToLowLevel)
284 expectedState = RKH_STATE_CAST(&s21);
286 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
287 smTest_xS21_Expect(
RKH_CAST(SmTest, smTest));
288 smTest_tr32_Expect(
RKH_CAST(SmTest, smTest), &evD);
289 smTest_nS21_Expect(
RKH_CAST(SmTest, smTest));
290 setProfileWoutUnitrazer(smTest,
291 RKH_STATE_CAST(&s21),
298 TEST_ASSERT_TRUE(expectedState == getState(smTest));
302 TEST(trnWoutUnitrazer, loopSimpleStateOnTop)
304 expectedState = RKH_STATE_CAST(&s1);
306 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
307 smTest_xS1_Expect(
RKH_CAST(SmTest, smTest));
308 smTest_tr53_Expect(
RKH_CAST(SmTest, smTest), &evA);
309 smTest_nS1_Expect(
RKH_CAST(SmTest, smTest));
310 setProfileWoutUnitrazer(smTest,
318 TEST_ASSERT_TRUE(expectedState == getState(smTest));
322 TEST(trnWoutUnitrazer, loopNestedSimpleState)
324 expectedState = RKH_STATE_CAST(&s31);
326 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
327 smTest_xS31_Expect(
RKH_CAST(SmTest, smTest));
328 smTest_tr52_Expect(
RKH_CAST(SmTest, smTest), &evD);
329 smTest_nS31_Expect(
RKH_CAST(SmTest, smTest));
330 setProfileWoutUnitrazer(smTest,
331 RKH_STATE_CAST(&s31),
332 RKH_STATE_CAST(&s31),
338 TEST_ASSERT_TRUE(expectedState == getState(smTest));
342 TEST(trnWoutUnitrazer, loopCompositeStateOnTop)
344 expectedState = RKH_STATE_CAST(&s31);
346 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
347 smTest_xS31_Expect(
RKH_CAST(SmTest, smTest));
348 smTest_tr51_Expect(
RKH_CAST(SmTest, smTest), &evA);
349 smTest_iS3_Expect(
RKH_CAST(SmTest, smTest));
350 smTest_nS31_Expect(
RKH_CAST(SmTest, smTest));
351 setProfileWoutUnitrazer(smTest,
352 RKH_STATE_CAST(&s31),
359 TEST_ASSERT_TRUE(expectedState == getState(smTest));
363 TEST(trnWoutUnitrazer, loopNestedCompositeState)
365 expectedState = RKH_STATE_CAST(&s2211);
367 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
368 smTest_xS2211_Expect(
RKH_CAST(SmTest, smTest));
369 smTest_xS221_Expect(
RKH_CAST(SmTest, smTest));
370 smTest_tr54_Expect(
RKH_CAST(SmTest, smTest), &evD);
371 smTest_iS22_Expect(
RKH_CAST(SmTest, smTest));
372 smTest_nS221_Expect(
RKH_CAST(SmTest, smTest));
373 smTest_iS221_Expect(
RKH_CAST(SmTest, smTest));
374 smTest_nS2211_Expect(
RKH_CAST(SmTest, smTest));
375 setProfileWoutUnitrazer(smTest,
376 RKH_STATE_CAST(&s2211),
377 RKH_STATE_CAST(&s22),
383 TEST_ASSERT_TRUE(expectedState == getState(smTest));
387 TEST(trnWoutUnitrazer, compositeToSimpleFromLowToHighLevel)
389 expectedState = RKH_STATE_CAST(&s0);
391 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
392 smTest_xS2211_Expect(
RKH_CAST(SmTest, smTest));
393 smTest_xS221_Expect(
RKH_CAST(SmTest, smTest));
394 smTest_xS22_Expect(
RKH_CAST(SmTest, smTest));
395 smTest_xS2_Expect(
RKH_CAST(SmTest, smTest));
396 smTest_tr33_Expect(
RKH_CAST(SmTest, smTest), &evB);
397 smTest_nS0_Expect(
RKH_CAST(SmTest, smTest));
398 setProfileWoutUnitrazer(smTest,
399 RKH_STATE_CAST(&s2211),
400 RKH_STATE_CAST(&s22),
406 TEST_ASSERT_TRUE(expectedState == getState(smTest));
410 TEST(trnWoutUnitrazer, compositeToCompositeAtEqualLevel)
412 expectedState = RKH_STATE_CAST(&s21);
414 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
415 smTest_xS31_Expect(
RKH_CAST(SmTest, smTest));
416 smTest_xS3_Expect(
RKH_CAST(SmTest, smTest));
417 smTest_tr41_Expect(
RKH_CAST(SmTest, smTest), &evB);
418 smTest_nS2_Expect(
RKH_CAST(SmTest, smTest));
419 smTest_iS2_Expect(
RKH_CAST(SmTest, smTest));
420 smTest_nS21_Expect(
RKH_CAST(SmTest, smTest));
421 setProfileWoutUnitrazer(smTest,
422 RKH_STATE_CAST(&s31),
429 TEST_ASSERT_TRUE(expectedState == getState(smTest));
433 TEST(trnWoutUnitrazer, compositeToCompositeFromHighToLowLevel)
435 expectedState = RKH_STATE_CAST(&s2211);
437 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
438 smTest_xS31_Expect(
RKH_CAST(SmTest, smTest));
439 smTest_xS3_Expect(
RKH_CAST(SmTest, smTest));
440 smTest_tr42_Expect(
RKH_CAST(SmTest, smTest), &evC);
441 smTest_nS2_Expect(
RKH_CAST(SmTest, smTest));
442 smTest_nS22_Expect(
RKH_CAST(SmTest, smTest));
443 smTest_iS22_Expect(
RKH_CAST(SmTest, smTest));
444 smTest_nS221_Expect(
RKH_CAST(SmTest, smTest));
445 smTest_iS221_Expect(
RKH_CAST(SmTest, smTest));
446 smTest_nS2211_Expect(
RKH_CAST(SmTest, smTest));
447 setProfileWoutUnitrazer(smTest,
448 RKH_STATE_CAST(&s31),
455 TEST_ASSERT_TRUE(expectedState == getState(smTest));
459 TEST(trnWoutUnitrazer, compositeToCompositeFromLowToHighLevel)
461 expectedState = RKH_STATE_CAST(&s31);
463 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
464 smTest_xS2211_Expect(
RKH_CAST(SmTest, smTest));
465 smTest_xS221_Expect(
RKH_CAST(SmTest, smTest));
466 smTest_xS22_Expect(
RKH_CAST(SmTest, smTest));
467 smTest_xS2_Expect(
RKH_CAST(SmTest, smTest));
468 smTest_tr43_Expect(
RKH_CAST(SmTest, smTest), &evC);
469 smTest_nS3_Expect(
RKH_CAST(SmTest, smTest));
470 smTest_iS3_Expect(
RKH_CAST(SmTest, smTest));
471 smTest_nS31_Expect(
RKH_CAST(SmTest, smTest));
472 setProfileWoutUnitrazer(smTest,
473 RKH_STATE_CAST(&s2211),
480 TEST_ASSERT_TRUE(expectedState == getState(smTest));
484 TEST(trnWoutUnitrazer, internalInSimpleState)
486 expectedState = RKH_STATE_CAST(&s1);
488 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
489 smTest_tr14_Expect(
RKH_CAST(SmTest, smTest), &evB);
490 setProfileWoutUnitrazer(smTest,
498 TEST_ASSERT_TRUE(expectedState == getState(smTest));
502 TEST(trnWoutUnitrazer, internalInCompositeState)
504 expectedState = RKH_STATE_CAST(&s31);
506 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
507 smTest_tr15_Expect(
RKH_CAST(SmTest, smTest), &evE);
508 setProfileWoutUnitrazer(smTest,
509 RKH_STATE_CAST(&s31),
516 TEST_ASSERT_TRUE(expectedState == getState(smTest));
519 TEST(trnWoutUnitrazer, fails_EventNotFound)
521 expectedState = RKH_STATE_CAST(&s1);
523 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
524 setProfileWoutUnitrazer(smTest,
532 TEST_ASSERT_TRUE(expectedState == getState(smTest));
536 TEST(trnWoutUnitrazer, fails_GuardFalseOnInternalTrn)
538 expectedState = RKH_STATE_CAST(&s1);
540 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
541 smTest_falseGuard_ExpectAndReturn(
RKH_CAST(SmTest, smTest), &evC,
543 setProfileWoutUnitrazer(smTest,
551 TEST_ASSERT_TRUE(expectedState == getState(smTest));
555 TEST(trnWoutUnitrazer, fails_GuardFalseOnExternalTrn)
557 expectedState = RKH_STATE_CAST(&s1);
559 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
560 smTest_falseGuard_ExpectAndReturn(
RKH_CAST(SmTest, smTest), &evD,
562 setProfileWoutUnitrazer(smTest,
570 TEST_ASSERT_TRUE(expectedState == getState(smTest));
574 TEST(trnWoutUnitrazer, fails_ExceededHierarchicalLevel)
576 expectedState = RKH_STATE_CAST(&s0);
578 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
579 setProfileWoutUnitrazer(smTest,
584 rkh_assert_Expect(
"rkhsm", 0);
585 rkh_assert_IgnoreArg_line();
589 TEST_ASSERT_TRUE(expectedState == getState(smTest));
593 TEST(trnWoutUnitrazer, multipleEnabledTrn_FiringFirstTrueGuard)
595 expectedState = RKH_STATE_CAST(&s4);
597 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
600 setProfileWoutUnitrazer(smTest,
608 TEST_ASSERT_TRUE(expectedState == getState(smTest));
612 TEST(trnWoutUnitrazer, multipleEnabledTrn_FiringFirstEmptyGuard)
614 expectedState = RKH_STATE_CAST(&s4);
616 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
619 setProfileWoutUnitrazer(smTest,
627 TEST_ASSERT_TRUE(expectedState == getState(smTest));
631 TEST(trnWoutUnitrazer, defaultTrnWithAssociatedEffect)
633 expectedState = RKH_STATE_CAST(&s31);
635 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
636 smTest_xS0_Expect(
RKH_CAST(SmTest, smTest));
637 smTest_tr55_Expect(
RKH_CAST(SmTest, smTest), &evF);
638 smTest_nS3_Expect(
RKH_CAST(SmTest, smTest));
639 smTest_iS3_Expect(
RKH_CAST(SmTest, smTest));
640 smTest_nS31_Expect(
RKH_CAST(SmTest, smTest));
641 setProfileWoutUnitrazer(smTest,
649 TEST_ASSERT_TRUE(expectedState == getState(smTest));
653 TEST(trnWoutUnitrazer, generatedCompletionEventBySimpleState)
655 expectedState = RKH_STATE_CAST(&s4);
658 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
659 smTest_xS21_Expect(
RKH_CAST(SmTest, smTest));
660 smTest_xS2_Expect(
RKH_CAST(SmTest, smTest));
661 smTest_nS5_Expect(
RKH_CAST(SmTest, smTest));
663 smTest_xS5_Expect(
RKH_CAST(SmTest, smTest));
664 smTest_tr61_Expect(
RKH_CAST(SmTest, smTest), &evCompletion);
665 setProfileWoutUnitrazer(smTest,
666 RKH_STATE_CAST(&s21),
673 TEST_ASSERT_TRUE(expectedState == getState(smTest));
677 TEST(trnWoutUnitrazer, generatedCompletionEventByFinalState)
679 expectedState = RKH_STATE_CAST(&s4);
682 smTest_init_Expect(
RKH_CAST(SmTest, smTest));
683 smTest_xS21_Expect(
RKH_CAST(SmTest, smTest));
685 smTest_xS2_Expect(
RKH_CAST(SmTest, smTest));
686 smTest_guardS2_ExpectAndReturn(
RKH_CAST(SmTest, smTest), &evCompletion,
688 smTest_tr60_Expect(
RKH_CAST(SmTest, smTest), &evCompletion);
689 setProfileWoutUnitrazer(smTest,
690 RKH_STATE_CAST(&s21),
691 RKH_STATE_CAST(&s21),
697 TEST_ASSERT_TRUE(expectedState == getState(smTest));
701 TEST(trnWoutUnitrazer, syncDispatchingToStateMachine)
#define RKH_COMPLETION_EVENT
This macro is used to indicate the completion event.
RKH_RCODE_T
Return codes from rkh_sm_dispatch() function.
Describes the SMA (active object in UML).
Interface of unit test with Trazer application.
#define RKH_FALSE
Standard define.
Describes the state machine.
void rkh_sm_init(RKH_SM_T *me)
Inits a previously created state machine calling its initializing action.
ruint rkh_sm_dispatch(RKH_SM_T *me, RKH_EVT_T *e)
Executes a state machine in a run-to-completation (RTC) model.
Describes the common properties of regular states (basic, composite, and submachine).
#define RKH_TRUE
Standard define.
#define RKH_CAST(_type, _obj)
Perform downcast of a reference of a base class to one of its derived classes.
#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...
Specifies the interface of dynamic event support.