RKH
test_smInstance.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 "rkhsma.h"
58 #include "smTest.h"
59 #include "smInstance.h"
60 
61 /* ----------------------------- Local macros ------------------------------ */
62 /* ------------------------------- Constants ------------------------------- */
63 /* ---------------------------- Local data types --------------------------- */
64 /* ---------------------------- Global variables --------------------------- */
65 TEST_GROUP(instance);
66 
67 /* ---------------------------- Local variables ---------------------------- */
68 /* ----------------------- Local function prototypes ----------------------- */
69 /* ---------------------------- Local functions ---------------------------- */
70 /* ---------------------------- Global functions --------------------------- */
71 TEST_SETUP(instance)
72 {
73 }
74 
75 TEST_TEAR_DOWN(instance)
76 {
77 }
78 
86 TEST(instance, ctorOfStaticPrivateAO)
87 {
88  Single_ctor(4);
89 
90  TEST_ASSERT_EQUAL_STRING("single", RKH_SMA_ACCESS_CONST(single, name));
91  TEST_ASSERT_EQUAL(4, Single_getFoo());
92 }
93 
94 TEST(instance, staticPublicAOWithoutRuntimeCtor)
95 {
96  publicSingle->foo = 8;
97  TEST_ASSERT_EQUAL_STRING("publicSingle",
98  RKH_SMA_ACCESS_CONST(publicSingle, name));
99 }
100 
101 TEST(instance, ctorOfStaticPublicAO)
102 {
103  PublicSingle_ctor(8);
104 
105  TEST_ASSERT_EQUAL_STRING("publicSingle",
106  RKH_SMA_ACCESS_CONST(publicSingle, name));
107  TEST_ASSERT_EQUAL(8, publicSingle->foo);
108 }
109 
110 TEST(instance, ctorOfStaticOpaqueAO)
111 {
112  Opaque_ctor(opaque, 4);
113 
114  TEST_ASSERT_EQUAL(4, Opaque_getFoo(opaque));
115 }
116 
117 TEST(instance, ctorOfStaticMultipleAO)
118 {
119  MultiplePublicSingle_ctor(single0, 8);
120 
121  TEST_ASSERT_EQUAL_STRING("single0",
122  RKH_SMA_ACCESS_CONST(single0, name));
123  TEST_ASSERT_EQUAL(8, single0->foo);
124 }
125 
126 TEST(instance, ctorOfStaticArrayOfAO)
127 {
128  PublicSingle *pSingle = RKH_ARRAY_SMA(arrayOfSingles, 2);
129  MultiplePublicSingle_ctor(pSingle, 8);
130 
131  TEST_ASSERT_EQUAL_STRING("single2",
132  RKH_SMA_ACCESS_CONST(pSingle, name));
133  TEST_ASSERT_EQUAL(8, pSingle->foo);
134 }
135 
136 TEST(instance, staticPrivateSMWithoutRuntimeCtor)
137 {
138  TEST_ASSERT_EQUAL_STRING("stateMachine",
139  RKH_SMA_ACCESS_CONST(stateMachine, name));
140  TEST_ASSERT_EQUAL_PTR(NULL, stateMachine->state);
141 }
142 
143 TEST(instance, staticPublicSMWithoutRuntimeCtor)
144 {
145  TEST_ASSERT_EQUAL_STRING("publicStateMachine",
146  RKH_SMA_ACCESS_CONST(publicStateMachine, name));
147  TEST_ASSERT_EQUAL(8, publicSingle->foo);
148 }
149 
150 TEST(instance, ctorOfStaticCompositePrivateSingletonAO)
151 {
152  Composite_ctor(16);
153 
154  TEST_ASSERT_EQUAL_STRING("composite",
155  RKH_SMA_ACCESS_CONST(composite, name));
156  TEST_ASSERT_EQUAL_STRING("region",
157  RKH_SMA_ACCESS_CONST(Composite_getItsReactivePart(), name));
158  TEST_ASSERT_EQUAL(16, Composite_getFoo());
159 }
160 
161 TEST(instance, ctorOfStaticCompositePublicAO)
162 {
163  PublicComposite_ctor(publicComposite, 16);
164 
165  TEST_ASSERT_EQUAL_STRING("publicComposite",
166  RKH_SMA_ACCESS_CONST(publicComposite, name));
167  TEST_ASSERT_EQUAL_STRING("publicRegion",
168  RKH_SMA_ACCESS_CONST(&publicComposite->itsReactivePart, name));
169  TEST_ASSERT_EQUAL(16, publicComposite->foo);
170 }
171 
172 TEST(instance, ctorOfStaticCompositeAOWithDerivedPublicSM)
173 {
174  PublicCompositeA_ctor(publicCompositeA, 16, 8);
175 
176  TEST_ASSERT_EQUAL_STRING("publicCompositeA",
177  RKH_SMA_ACCESS_CONST(publicCompositeA, name));
178  TEST_ASSERT_EQUAL_STRING("publicRegionA",
179  RKH_SMA_ACCESS_CONST(&publicCompositeA->itsReactivePart, name));
180  TEST_ASSERT_EQUAL(16, publicCompositeA->foo);
181  TEST_ASSERT_EQUAL(8, publicCompositeA->itsReactivePart.foo);
182 }
183 
184 TEST(instance, ctorOfDynamicCompositeAO)
185 {
186  PublicSingle *actObj;
187 
188  actObj = PublicSingle_dynCtor(8);
189  TEST_ASSERT_NOT_NULL(actObj);
190  TEST_ASSERT_EQUAL(8, actObj->foo);
191 
192  TEST_ASSERT_EQUAL_STRING("publicSingleDyn",
193  RKH_SMA_ACCESS_CONST(actObj, name));
194 
195  PublicSingle_dynDtor(actObj);
196 }
197 
202 /* ------------------------------ End of file ------------------------------ */
#define RKH_ARRAY_SMA(_arr, _ix)
Retrieves the pointer to active object from a SMA's array.
Definition: rkhsma.h:656
#define RKH_SMA_ACCESS_CONST(me_, member_)
Macro for accessing to members of state machine structure.
Definition: rkhsma.h:96
Specifies the interface of the acive object (SMA state machine applications) manager.