RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test_smTransitionWoutUnitrazer.c
Go to the documentation of this file.
1 /*
2  * --------------------------------------------------------------------------
3  *
4  * Framework RKH
5  * -------------
6  *
7  * State-machine framework for reactive embedded systems
8  *
9  * Copyright (C) 2010 Leandro Francucci.
10  * All rights reserved. Protected by international copyright laws.
11  *
12  *
13  * RKH is free software: you can redistribute it and/or modify it under the
14  * terms of the GNU General Public License as published by the Free Software
15  * Foundation, either version 3 of the License, or (at your option) any
16  * later version.
17  *
18  * RKH is distributed in the hope that it will be useful, but WITHOUT ANY
19  * WARRANTY; without even the implied warranty of MERCHANTABILITY or
20  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
21  * more details.
22  *
23  * You should have received a copy of the GNU General Public License along
24  * with RKH, see copying.txt file.
25  *
26  * Contact information:
27  * RKH web site: http://sourceforge.net/projects/rkh-reactivesys/
28  * e-mail: francuccilea@gmail.com
29  * ---------------------------------------------------------------------------
30  */
31 
44 /* -------------------------- Development history -------------------------- */
45 /*
46  * 2016.12.15 LeFr v2.4.05 ---
47  */
48 
49 /* -------------------------------- Authors -------------------------------- */
50 /*
51  * LeFr Leandro Francucci francuccilea@gmail.com
52  */
53 
54 /* --------------------------------- Notes --------------------------------- */
55 /* ----------------------------- Include files ----------------------------- */
56 #include "unity_fixture.h"
57 #include "unitrazer.h"
58 #include "rkhfwk_dynevt.h"
59 #include "common.h"
60 #include "smTest.h"
61 #include "smTestAct.h"
62 #include "MocksmTestAct.h"
63 #include "Mockrkhassert.h"
64 
65 /* ----------------------------- Local macros ------------------------------ */
66 /* ------------------------------- Constants ------------------------------- */
67 static RKH_STATIC_EVENT(evA, A);
68 static RKH_STATIC_EVENT(evB, B);
69 static RKH_STATIC_EVENT(evC, C);
70 static RKH_STATIC_EVENT(evD, D);
71 static RKH_STATIC_EVENT(evE, E);
72 static RKH_STATIC_EVENT(evF, F);
73 static RKH_STATIC_EVENT(evG, G);
74 static RKH_STATIC_EVENT(evH, H);
75 static RKH_STATIC_EVENT(evI, I);
76 static RKH_STATIC_EVENT(evCompletion, RKH_COMPLETION_EVENT);
77 static RKH_STATIC_EVENT(evTerminate, TERMINATE);
78 
79 /* ---------------------------- Local data types --------------------------- */
80 typedef struct StateMachine
81 {
82  RKH_SM_T sm;
83  int foo;
84 } StateMachine;
85 
86 typedef struct Composite
87 {
88  RKH_SMA_T ao;
89  int foo;
90  RKH_SM_T itsReactivePart;
91 } Composite;
92 
93 /* ---------------------------- Global variables --------------------------- */
94 TEST_GROUP(trnWoutUnitrazer);
95 static RKH_ST_T *expectedState;
96 static RKH_RCODE_T result;
97 
98 /* ---------------------------- Local variables ---------------------------- */
99 /* ----------------------- Local function prototypes ----------------------- */
100 /* ---------------------------- Local functions ---------------------------- */
101 /* ---------------------------- Global functions --------------------------- */
102 TEST_SETUP(trnWoutUnitrazer)
103 {
104  MocksmTestAct_Init();
105  sm_ignore();
106 }
107 
108 TEST_TEAR_DOWN(trnWoutUnitrazer)
109 {
110  MocksmTestAct_Verify();
111  MocksmTestAct_Destroy();
112 }
113 
121 TEST(trnWoutUnitrazer, firstStateAfterInit)
122 {
123  smTest_init_Expect(RKH_CAST(SmTest, smTest));
124  expectedState = RKH_STATE_CAST(&waiting);
125 
126  rkh_sm_init((RKH_SM_T *)smTest);
127 
128  TEST_ASSERT_TRUE(expectedState == getState(smTest));
129 }
130 
131 TEST(trnWoutUnitrazer, simpleToSimpleAtEqualLevel)
132 {
133  expectedState = RKH_STATE_CAST(&s1);
134 
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,
140  RKH_STATE_CAST(&s0),
141  RKH_STATE_CAST(&s0),
142  expectedState,
143  INIT_STATE_MACHINE);
144 
145  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evA);
146 
147  TEST_ASSERT_TRUE(expectedState == getState(smTest));
148  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
149 }
150 
151 TEST(trnWoutUnitrazer, simpleToSimpleFromHighToLowLevel)
152 {
153  expectedState = RKH_STATE_CAST(&s21);
154 
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,
161  RKH_STATE_CAST(&s0),
162  RKH_STATE_CAST(&s0),
163  expectedState,
164  INIT_STATE_MACHINE);
165 
166  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evB);
167 
168  TEST_ASSERT_TRUE(expectedState == getState(smTest));
169  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
170 }
171 
172 TEST(trnWoutUnitrazer, simpleToSimpleFromLowToHighLevel)
173 {
174  expectedState = RKH_STATE_CAST(&s0);
175 
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),
184  expectedState,
185  INIT_STATE_MACHINE);
186 
187  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evB);
188 
189  TEST_ASSERT_TRUE(expectedState == getState(smTest));
190  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
191 }
192 
193 TEST(trnWoutUnitrazer, simpleToCompositeAtEqualLevel)
194 {
195  expectedState = RKH_STATE_CAST(&s21);
196 
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,
204  RKH_STATE_CAST(&s0),
205  RKH_STATE_CAST(&s0),
206  expectedState,
207  INIT_STATE_MACHINE);
208 
209  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evC);
210 
211  TEST_ASSERT_TRUE(expectedState == getState(smTest));
212  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
213 }
214 
215 TEST(trnWoutUnitrazer, simpleToCompositeFromHighToLowLevel)
216 {
217  expectedState = RKH_STATE_CAST(&s2211);
218 
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,
229  RKH_STATE_CAST(&s0),
230  RKH_STATE_CAST(&s0),
231  expectedState,
232  INIT_STATE_MACHINE);
233 
234  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evD);
235 
236  TEST_ASSERT_TRUE(expectedState == getState(smTest));
237  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
238 }
239 
240 TEST(trnWoutUnitrazer, simpleToCompositeFromLowToHighLevel)
241 {
242  expectedState = RKH_STATE_CAST(&s21);
243 
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),
252  expectedState,
253  INIT_STATE_MACHINE);
254 
255  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evC);
256 
257  TEST_ASSERT_TRUE(expectedState == getState(smTest));
258  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
259 }
260 
261 TEST(trnWoutUnitrazer, compositeToSimpleAtEqualLevel)
262 {
263  expectedState = RKH_STATE_CAST(&s0);
264 
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),
272  RKH_STATE_CAST(&s2),
273  expectedState,
274  INIT_STATE_MACHINE);
275 
276  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evA);
277 
278  TEST_ASSERT_TRUE(expectedState == getState(smTest));
279  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
280 }
281 
282 TEST(trnWoutUnitrazer, compositeToSimpleFromHighToLowLevel)
283 {
284  expectedState = RKH_STATE_CAST(&s21);
285 
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),
292  RKH_STATE_CAST(&s2),
293  expectedState,
294  INIT_STATE_MACHINE);
295 
296  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evD);
297 
298  TEST_ASSERT_TRUE(expectedState == getState(smTest));
299  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
300 }
301 
302 TEST(trnWoutUnitrazer, loopSimpleStateOnTop)
303 {
304  expectedState = RKH_STATE_CAST(&s1);
305 
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,
311  RKH_STATE_CAST(&s1),
312  RKH_STATE_CAST(&s1),
313  expectedState,
314  INIT_STATE_MACHINE);
315 
316  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evA);
317 
318  TEST_ASSERT_TRUE(expectedState == getState(smTest));
319  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
320 }
321 
322 TEST(trnWoutUnitrazer, loopNestedSimpleState)
323 {
324  expectedState = RKH_STATE_CAST(&s31);
325 
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),
333  expectedState,
334  INIT_STATE_MACHINE);
335 
336  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evD);
337 
338  TEST_ASSERT_TRUE(expectedState == getState(smTest));
339  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
340 }
341 
342 TEST(trnWoutUnitrazer, loopCompositeStateOnTop)
343 {
344  expectedState = RKH_STATE_CAST(&s31);
345 
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),
353  RKH_STATE_CAST(&s3),
354  expectedState,
355  INIT_STATE_MACHINE);
356 
357  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evA);
358 
359  TEST_ASSERT_TRUE(expectedState == getState(smTest));
360  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
361 }
362 
363 TEST(trnWoutUnitrazer, loopNestedCompositeState)
364 {
365  expectedState = RKH_STATE_CAST(&s2211);
366 
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),
378  expectedState,
379  INIT_STATE_MACHINE);
380 
381  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evD);
382 
383  TEST_ASSERT_TRUE(expectedState == getState(smTest));
384  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
385 }
386 
387 TEST(trnWoutUnitrazer, compositeToSimpleFromLowToHighLevel)
388 {
389  expectedState = RKH_STATE_CAST(&s0);
390 
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),
401  expectedState,
402  INIT_STATE_MACHINE);
403 
404  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evB);
405 
406  TEST_ASSERT_TRUE(expectedState == getState(smTest));
407  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
408 }
409 
410 TEST(trnWoutUnitrazer, compositeToCompositeAtEqualLevel)
411 {
412  expectedState = RKH_STATE_CAST(&s21);
413 
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),
423  RKH_STATE_CAST(&s3),
424  expectedState,
425  INIT_STATE_MACHINE);
426 
427  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evB);
428 
429  TEST_ASSERT_TRUE(expectedState == getState(smTest));
430  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
431 }
432 
433 TEST(trnWoutUnitrazer, compositeToCompositeFromHighToLowLevel)
434 {
435  expectedState = RKH_STATE_CAST(&s2211);
436 
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),
449  RKH_STATE_CAST(&s3),
450  expectedState,
451  INIT_STATE_MACHINE);
452 
453  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evC);
454 
455  TEST_ASSERT_TRUE(expectedState == getState(smTest));
456  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
457 }
458 
459 TEST(trnWoutUnitrazer, compositeToCompositeFromLowToHighLevel)
460 {
461  expectedState = RKH_STATE_CAST(&s31);
462 
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),
474  RKH_STATE_CAST(&s3),
475  expectedState,
476  INIT_STATE_MACHINE);
477 
478  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evC);
479 
480  TEST_ASSERT_TRUE(expectedState == getState(smTest));
481  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
482 }
483 
484 TEST(trnWoutUnitrazer, internalInSimpleState)
485 {
486  expectedState = RKH_STATE_CAST(&s1);
487 
488  smTest_init_Expect(RKH_CAST(SmTest, smTest));
489  smTest_tr14_Expect(RKH_CAST(SmTest, smTest), &evB);
490  setProfileWoutUnitrazer(smTest,
491  RKH_STATE_CAST(&s1),
492  RKH_STATE_CAST(&s1),
493  expectedState,
494  INIT_STATE_MACHINE);
495 
496  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evB);
497 
498  TEST_ASSERT_TRUE(expectedState == getState(smTest));
499  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
500 }
501 
502 TEST(trnWoutUnitrazer, internalInCompositeState)
503 {
504  expectedState = RKH_STATE_CAST(&s31);
505 
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),
510  RKH_STATE_CAST(&s3),
511  expectedState,
512  INIT_STATE_MACHINE);
513 
514  rkh_sm_dispatch((RKH_SM_T *)smTest, &evE);
515 
516  TEST_ASSERT_TRUE(expectedState == getState(smTest));
517 }
518 
519 TEST(trnWoutUnitrazer, fails_EventNotFound)
520 {
521  expectedState = RKH_STATE_CAST(&s1);
522 
523  smTest_init_Expect(RKH_CAST(SmTest, smTest));
524  setProfileWoutUnitrazer(smTest,
525  RKH_STATE_CAST(&s1),
526  RKH_STATE_CAST(&s1),
527  expectedState,
528  INIT_STATE_MACHINE);
529 
530  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evE);
531 
532  TEST_ASSERT_TRUE(expectedState == getState(smTest));
533  TEST_ASSERT_EQUAL(RKH_EVT_NFOUND, result);
534 }
535 
536 TEST(trnWoutUnitrazer, fails_GuardFalseOnInternalTrn)
537 {
538  expectedState = RKH_STATE_CAST(&s1);
539 
540  smTest_init_Expect(RKH_CAST(SmTest, smTest));
541  smTest_falseGuard_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evC,
542  RKH_FALSE);
543  setProfileWoutUnitrazer(smTest,
544  RKH_STATE_CAST(&s1),
545  RKH_STATE_CAST(&s1),
546  expectedState,
547  INIT_STATE_MACHINE);
548 
549  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evC);
550 
551  TEST_ASSERT_TRUE(expectedState == getState(smTest));
552  TEST_ASSERT_EQUAL(RKH_EVT_NFOUND, result);
553 }
554 
555 TEST(trnWoutUnitrazer, fails_GuardFalseOnExternalTrn)
556 {
557  expectedState = RKH_STATE_CAST(&s1);
558 
559  smTest_init_Expect(RKH_CAST(SmTest, smTest));
560  smTest_falseGuard_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evD,
561  RKH_FALSE);
562  setProfileWoutUnitrazer(smTest,
563  RKH_STATE_CAST(&s1),
564  RKH_STATE_CAST(&s1),
565  expectedState,
566  INIT_STATE_MACHINE);
567 
568  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evD);
569 
570  TEST_ASSERT_TRUE(expectedState == getState(smTest));
571  TEST_ASSERT_EQUAL(RKH_EVT_NFOUND, result);
572 }
573 
574 TEST(trnWoutUnitrazer, fails_ExceededHierarchicalLevel)
575 {
576  expectedState = RKH_STATE_CAST(&s0);
577 
578  smTest_init_Expect(RKH_CAST(SmTest, smTest));
579  setProfileWoutUnitrazer(smTest,
580  RKH_STATE_CAST(&s0),
581  RKH_STATE_CAST(&s0),
582  expectedState,
583  INIT_STATE_MACHINE);
584  rkh_assert_Expect("rkhsm", 0);
585  rkh_assert_IgnoreArg_line();
586 
587  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evE);
588 
589  TEST_ASSERT_TRUE(expectedState == getState(smTest));
590  TEST_ASSERT_EQUAL(RKH_EX_HLEVEL, result);
591 }
592 
593 TEST(trnWoutUnitrazer, multipleEnabledTrn_FiringFirstTrueGuard)
594 {
595  expectedState = RKH_STATE_CAST(&s4);
596 
597  smTest_init_Expect(RKH_CAST(SmTest, smTest));
598  smTest_guard4a_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evA, RKH_FALSE);
599  smTest_guard4b_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evA, RKH_TRUE);
600  setProfileWoutUnitrazer(smTest,
601  RKH_STATE_CAST(&s4),
602  RKH_STATE_CAST(&s4),
603  expectedState,
604  INIT_STATE_MACHINE);
605 
606  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evA);
607 
608  TEST_ASSERT_TRUE(expectedState == getState(smTest));
609  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
610 }
611 
612 TEST(trnWoutUnitrazer, multipleEnabledTrn_FiringFirstEmptyGuard)
613 {
614  expectedState = RKH_STATE_CAST(&s4);
615 
616  smTest_init_Expect(RKH_CAST(SmTest, smTest));
617  smTest_guard4a_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evB, RKH_FALSE);
618  smTest_guard4b_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evB, RKH_FALSE);
619  setProfileWoutUnitrazer(smTest,
620  RKH_STATE_CAST(&s4),
621  RKH_STATE_CAST(&s4),
622  expectedState,
623  INIT_STATE_MACHINE);
624 
625  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evB);
626 
627  TEST_ASSERT_TRUE(expectedState == getState(smTest));
628  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
629 }
630 
631 TEST(trnWoutUnitrazer, defaultTrnWithAssociatedEffect)
632 {
633  expectedState = RKH_STATE_CAST(&s31);
634 
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,
642  RKH_STATE_CAST(&s0),
643  RKH_STATE_CAST(&s0),
644  expectedState,
645  INIT_STATE_MACHINE);
646 
647  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evF);
648 
649  TEST_ASSERT_TRUE(expectedState == getState(smTest));
650  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
651 }
652 
653 TEST(trnWoutUnitrazer, generatedCompletionEventBySimpleState)
654 {
655  expectedState = RKH_STATE_CAST(&s4);
656 
657  /* Expectations for transition to s5 */
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));
662  /* Expectations for completion transition */
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),
667  RKH_STATE_CAST(&s2),
668  expectedState,
669  INIT_STATE_MACHINE);
670 
671  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evE);
672 
673  TEST_ASSERT_TRUE(expectedState == getState(smTest));
674  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
675 }
676 
677 TEST(trnWoutUnitrazer, generatedCompletionEventByFinalState)
678 {
679  expectedState = RKH_STATE_CAST(&s4);
680 
681  /* Expectations for transition to S2's FinalState */
682  smTest_init_Expect(RKH_CAST(SmTest, smTest));
683  smTest_xS21_Expect(RKH_CAST(SmTest, smTest));
684  /* Expectations for completion transition */
685  smTest_xS2_Expect(RKH_CAST(SmTest, smTest));
686  smTest_guardS2_ExpectAndReturn(RKH_CAST(SmTest, smTest), &evCompletion,
687  RKH_TRUE);
688  smTest_tr60_Expect(RKH_CAST(SmTest, smTest), &evCompletion);
689  setProfileWoutUnitrazer(smTest,
690  RKH_STATE_CAST(&s21),
691  RKH_STATE_CAST(&s21),
692  expectedState,
693  INIT_STATE_MACHINE);
694 
695  result = rkh_sm_dispatch((RKH_SM_T *)smTest, &evF);
696 
697  TEST_ASSERT_TRUE(expectedState == getState(smTest));
698  TEST_ASSERT_EQUAL(RKH_EVT_PROC, result);
699 }
700 
701 TEST(trnWoutUnitrazer, syncDispatchingToStateMachine)
702 {
703  TEST_IGNORE();
704 }
705 
710 /* ------------------------------ End of file ------------------------------ */
#define RKH_COMPLETION_EVENT
This macro is used to indicate the completion event.
Definition: rkhitl.h:142
#define RKH_CAST(_type, _obj)
Perform downcast of a reference of a base class to one of its derived classes.
Definition: rkhfwk_cast.h:105
RKH_RCODE_T
Return codes from rkh_sm_dispatch() function.
Definition: rkhsm.h:1530
Describes the SMA (active object in UML).
Definition: rkhsma.h:748
Interface of unit test with Trazer application.
#define RKH_FALSE
Standard define.
Definition: rkhdef.h:254
Describes the state machine.
Definition: rkhsm.h:1712
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).
Definition: rkhsm.h:2062
#define RKH_TRUE
Standard define.
Definition: rkhdef.h:255
#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.