RKH
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
test_smPolymorphism.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 "rkh.h"
59 #include "common.h"
60 #include "smPolymorphism.h"
61 #include "MockrkhportTest.h"
62 
63 /* ----------------------------- Local macros ------------------------------ */
64 /* ------------------------------- Constants ------------------------------- */
65 /* ---------------------------- Local data types --------------------------- */
66 /* ---------------------------- Global variables --------------------------- */
67 TEST_GROUP(polymorphism);
68 
69 /* ---------------------------- Local variables ---------------------------- */
70 /* ----------------------- Local function prototypes ----------------------- */
71 /* ---------------------------- Local functions ---------------------------- */
72 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
73 static void
74 checkVtbl(RKH_SMA_T *me, RKHActivate activate, RKHTask task,
75  RKHPostFifo postFifo, RKHPostLifo postLifo)
76 {
77  TEST_ASSERT_EQUAL_PTR(activate, me->vptr->activate);
78  TEST_ASSERT_EQUAL_PTR(task, me->vptr->task);
79  TEST_ASSERT_EQUAL_PTR(postFifo, me->vptr->post_fifo);
80  TEST_ASSERT_EQUAL_PTR(postLifo, me->vptr->post_lifo);
81 }
82 
83 static void
84 testActivate(RKH_SMA_T *me, const RKH_EVT_T **qSto, RKH_RQNE_T qSize,
85  void *stkSto, rui32_t stkSize)
86 {
87  (void)me;
88  (void)qSto;
89  (void)qSize;
90  (void)stkSto;
91  (void)stkSize;
92 }
93 
94 static void
95 testTask(RKH_SMA_T *me, void *arg)
96 {
97  (void)me;
98  (void)arg;
99 }
100 
101 static void
102 testPostFifo(RKH_SMA_T *me, const RKH_EVT_T *e, const void *const sender)
103 {
104  (void)me;
105  (void)e;
106  (void)sender;
107 }
108 
109 static void
110 testPostLifo(RKH_SMA_T *me, const RKH_EVT_T *e, const void *const sender)
111 {
112  (void)me;
113  (void)e;
114  (void)sender;
115 }
116 #endif
117 
118 /* ---------------------------- Global functions --------------------------- */
119 TEST_SETUP(polymorphism)
120 {
121 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
122  sm_init();
123 
127 
128  /* Restore the default virtual table of RKH_SMA_T class */
129  singleton->vptr = &rkhSmaVtbl;
130 #endif
131 }
132 
133 TEST_TEAR_DOWN(polymorphism)
134 {
135 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
136  sm_verify(); /* Makes sure there are no unused expectations, if */
137  /* there are, this function causes the test to fail. */
138  sm_cleanup();
139 #endif
140 }
141 
149 TEST(polymorphism, defaultVirtualFunctions)
150 {
151 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
152  checkVtbl(singleton,
154 
155  TEST_ASSERT_EQUAL_PTR(&rkhSmaVtbl, singleton->vptr);
156 #endif
157 }
158 
159 TEST(polymorphism, callVirtualFunction)
160 {
161 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
162  rkh_sma_activate_Expect(singleton, NULL, 0, NULL, 0);
163  rkh_sma_post_fifo_Expect(singleton, NULL, NULL);
164  rkh_sma_post_lifo_Expect(singleton, NULL, NULL);
165 
166  RKH_SMA_ACTIVATE(singleton, NULL, 0, NULL, 0);
167  RKH_SMA_POST_FIFO(singleton, NULL, NULL);
168  RKH_SMA_POST_LIFO(singleton, NULL, NULL);
169 #endif
170 }
171 
172 TEST(polymorphism, setVirtualTable)
173 {
174 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
175  const RKHSmaVtbl *vptr;
176  static const RKHSmaVtbl vtbl =
177  {
178  testActivate, testTask, testPostFifo, testPostLifo
179  };
180 
181  vptr = singleton->vptr = &vtbl;
182 
183  checkVtbl(singleton,
184  testActivate, testTask, testPostFifo, testPostLifo);
185 #endif
186 }
187 
188 TEST(polymorphism, runtimeSingletonAOCtor)
189 {
190 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
191  Singleton_ctor(8);
192  TEST_ASSERT_EQUAL(8, Singleton_getFoo());
193 
194  RKH_SMA_ACTIVATE(singleton, NULL, 0, NULL, 0);
195  TEST_ASSERT_EQUAL(0, Singleton_getFoo());
196 #endif
197 }
198 
199 TEST(polymorphism, runtimeMultipleAOCtorWithVtblForObj)
200 {
201 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
202  Multiple_ctor(multA, 2, Multiple_postFifoA);
203  Multiple_ctor(multB, 4, Multiple_postFifoB);
204 
205  checkVtbl((RKH_SMA_T *)multA,
206  rkh_sma_activate, NULL, Multiple_postFifoA, rkh_sma_post_lifo);
207 
208  TEST_ASSERT_EQUAL(2, Multiple_getFoobar(multA));
209  TEST_ASSERT_EQUAL(4, Multiple_getFoobar(multB));
210 
211  RKH_SMA_POST_FIFO((RKH_SMA_T *)multA, NULL, NULL);
212  RKH_SMA_POST_FIFO((RKH_SMA_T *)multB, NULL, NULL);
213 
214  TEST_ASSERT_EQUAL(0, Multiple_getFoobar(multA));
215  TEST_ASSERT_EQUAL(8, Multiple_getFoobar(multB));
216 #endif
217 }
218 
219 TEST(polymorphism, runtimeMultipleAOCtorWithVtblForType)
220 {
221 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
222  Command_ctor(cmdSignal, 128);
223  Command_ctor(cmdRegister, 64);
224 
225  checkVtbl((RKH_SMA_T *)cmdSignal,
226  rkh_sma_activate, Command_task,
227  Command_postFifo, Command_postLifo);
228 
229  checkVtbl((RKH_SMA_T *)cmdRegister,
230  rkh_sma_activate, Command_task,
231  Command_postFifo, Command_postLifo);
232 #endif
233 }
234 
235 TEST(polymorphism, runtimeSubObjectCtorOfSMAAndSM)
236 {
237 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
238  CallControl_ctorA(16);
239 
240  TEST_ASSERT_EQUAL(16, CallControl_getFoo());
241  checkVtbl((RKH_SMA_T *)theCallControl,
242  CallControl_activate, CallControl_task,
244 #endif
245 }
246 
247 TEST(polymorphism, runtimeSubObjectCtorOfSMAAndSMWithDefaultVtbl)
248 {
249 #if RKH_CFG_SMA_VFUNCT_EN == RKH_ENABLED
250  CallControl_ctorB(8);
251 
252  TEST_ASSERT_EQUAL(8, CallControl_getFoo());
253  checkVtbl((RKH_SMA_T *)theCallControl,
254  rkh_sma_activate, NULL,
256 #endif
257 }
258 
263 /* ------------------------------ End of file ------------------------------ */
rui8_t RKH_RQNE_T
This data type defines the maximum number of elements that any queue can contain. ...
Definition: rkhrq.h:95
#define RKH_FILTER_OFF_GROUP_ALL_EVENTS(grp)
Emit (enable) all events in a specific group.
Definition: rkhtrc.h:179
#define sm_cleanup()
Return the system under test to its initial state after the test.
Definition: unitrazer.h:79
Describes the SMA (active object in UML).
Definition: rkhitl.h:2930
Represents events without parameters.
Definition: rkhevt.h:161
Interface of unit test with Trazer application.
State Machine group (SM)
Definition: rkhtrc.h:3103
void rkh_sma_post_lifo(RKH_SMA_T *me, const RKH_EVT_T *e, const void *const sender)
Send an event to a state machine application (SMA) as known as active object through a queue using th...
void(* RKHTask)(RKH_SMA_T *me, void *arg)
Definition: rkhitl.h:3020
Assertion expression was evaluated to false.
Definition: rkhtrc.h:3389
Virtual table for the RKH_SMA_T structure.
Definition: rkhitl.h:3042
void rkh_sma_activate(RKH_SMA_T *me, const RKH_EVT_T **qSto, RKH_RQNE_T qSize, void *stkSto, rui32_t stkSize)
Initializes and activates a previously created state machine application (SMA) as known as active obj...
#define sm_init()
Establish the preconditions to the tests.
Definition: unitrazer.h:73
#define sm_verify()
Makes sure there are no unused expectations, if there are, this function causes the test to fail...
Definition: unitrazer.h:86
void rkh_sma_post_fifo(RKH_SMA_T *me, const RKH_EVT_T *e, const void *const sender)
Send an event to a state machine application (SMA) as known as active object through a queue using th...
void(* RKHPostFifo)(RKH_SMA_T *me, const RKH_EVT_T *e, const void *const sender)
Definition: rkhitl.h:3024
#define RKH_SMA_POST_LIFO(me_, e_, sender_)
Invoke the direct event posting facility rkh_sma_post_lifo(). If RKH_CFG_SMA_VFUNCT_EN is set RKH_ENA...
Definition: rkh.h:2306
void(* RKHActivate)(RKH_SMA_T *me, const RKH_EVT_T **qSto, RKH_RQNE_T qSize, void *stkSto, rui32_t stkSize)
Definition: rkhitl.h:3015
RKH framwwork platform - independent interface.
const RKHSmaVtbl rkhSmaVtbl
#define RKH_SMA_POST_FIFO(me_, e_, sender_)
Invoke the direct event posting facility rkh_sma_post_fifo(). If RKH_CFG_SMA_VFUNCT_EN is set RKH_ENA...
Definition: rkh.h:2258
#define RKH_FILTER_OFF_EVENT(evt)
Emit (enable) one trace event. Use the RKH_TRC_ALL_EVENTS to enable all trace events.
Definition: rkhtrc.h:158
#define RKH_FILTER_OFF_ALL_SIGNALS()
Emmit all enabled trace events related to specified event signal.
Definition: rkhtrc.h:267
void(* RKHPostLifo)(RKH_SMA_T *me, const RKH_EVT_T *e, const void *const sender)
Definition: rkhitl.h:3032
#define RKH_SMA_ACTIVATE(me_, qSto_, qStoSize, stkSto_, stkSize_)
Invoke the active object activation function rkh_sma_activate(). If RKH_CFG_SMA_VFUNCT_EN is set RKH_...
Definition: rkh.h:1854