1 #include "tx_api.h"
2 #include "nx_api.h"
3
4 extern void test_control_return(UINT);
5
6 #if !defined(NX_DISABLE_ERROR_CHECKING) && defined(__PRODUCT_NETXDUO__)
7 #include "nx_cloud.h"
8
9 #define DEMO_STACK_SIZE 4096
10
11 static TX_THREAD test_thread;
12 static NX_CLOUD cloud;
13 static UCHAR cloud_stack[2048];
14 static NX_CLOUD_MODULE cloud_module;
15
16 /* Define module event. */
17 #define NX_CLOUD_MODULE_EVENT 0x10000000u
18
19 /* Define module own events. */
20 #define NX_CLOUD_MODULE_EVENT_1 0x00000001
21 #define NX_CLOUD_MODULE_EVENT_2 0x00000002
22 #define NX_CLOUD_MODULE_EVENT_3 0x00000004
23 #define NX_CLOUD_MODULE_EVENT_4 0x00000008
24
25 static void test_entry(ULONG thread_input);
26 static void cloud_module_event_process(VOID *module_ptr, ULONG common_events, ULONG module_own_events);
27
28
29 #ifdef CTEST
test_application_define(void * first_unused_memory)30 VOID test_application_define(void *first_unused_memory)
31 #else
32 void netx_cloud_api_test_application_define(void *first_unused_memory)
33 #endif
34 {
35
36 CHAR *pointer;
37
38
39 /* Setup the working pointer. */
40 pointer = (CHAR *) first_unused_memory;
41
42 /* Create a helper thread for the server. */
43 tx_thread_create(&test_thread, "Test thread", test_entry, 0,
44 pointer, DEMO_STACK_SIZE,
45 4, 4, TX_NO_TIME_SLICE, TX_AUTO_START);
46
47 pointer = pointer + DEMO_STACK_SIZE;
48
49 /* Initialize the NetX system. */
50 nx_system_initialize();
51 }
52
test_entry(ULONG thread_input)53 void test_entry(ULONG thread_input)
54 {
55
56 UINT status;
57
58
59 /* Print out test information banner. */
60 printf("NetX Test: Cloud API Test............................................");
61
62 /* nx_cloud_create. */
63 status = nx_cloud_create(NX_NULL, "Cloud", cloud_stack, 2048, 3);
64
65 /* Check status. */
66 if (status != NX_PTR_ERROR)
67 {
68 printf("ERROR!\n");
69 test_control_return(1);
70 }
71
72 status = nx_cloud_create(&cloud, "Cloud", NX_NULL, 2048, 3);
73
74 /* Check status. */
75 if (status != NX_PTR_ERROR)
76 {
77 printf("ERROR!\n");
78 test_control_return(1);
79 }
80
81 status = nx_cloud_create(&cloud, "Cloud", cloud_stack, 0, 3);
82
83 /* Check status. */
84 if (status != NX_SIZE_ERROR)
85 {
86 printf("ERROR!\n");
87 test_control_return(1);
88 }
89
90 status = nx_cloud_create(&cloud, "Cloud", cloud_stack, 2048, TX_MAX_PRIORITIES);
91
92 /* Check status. */
93 if (status != NX_OPTION_ERROR)
94 {
95 printf("ERROR!\n");
96 test_control_return(1);
97 }
98
99 status = nx_cloud_create(&cloud, "Cloud", cloud_stack, 2048, 3);
100
101 /* Check status. */
102 if (status)
103 {
104 printf("ERROR!\n");
105 test_control_return(1);
106 }
107
108
109 /* nx_cloud_module_register. */
110 status = nx_cloud_module_register(NX_NULL, &cloud_module, "Module 1", (NX_CLOUD_COMMON_PERIODIC_EVENT | NX_CLOUD_MODULE_EVENT), cloud_module_event_process, (void *)(&cloud_module));
111
112 /* Check status. */
113 if (status != NX_PTR_ERROR)
114 {
115 printf("ERROR!\n");
116 test_control_return(1);
117 }
118
119 status = nx_cloud_module_register(&cloud, NX_NULL, "Module 1", (NX_CLOUD_COMMON_PERIODIC_EVENT | NX_CLOUD_MODULE_EVENT), cloud_module_event_process, (void *)(&cloud_module));
120
121 /* Check status. */
122 if (status != NX_PTR_ERROR)
123 {
124 printf("ERROR!\n");
125 test_control_return(1);
126 }
127
128 status = nx_cloud_module_register(&cloud, &cloud_module, "Module 1", 0, cloud_module_event_process, (void *)(&cloud_module));
129
130 /* Check status. */
131 if (status != NX_CLOUD_MODULE_EVENT_INVALID)
132 {
133 printf("ERROR!\n");
134 test_control_return(1);
135 }
136
137 status = nx_cloud_module_register(&cloud, &cloud_module, "Module 1", (NX_CLOUD_COMMON_PERIODIC_EVENT | NX_CLOUD_MODULE_EVENT), NX_NULL, (void *)(&cloud_module));
138
139 /* Check status. */
140 if (status != NX_PTR_ERROR)
141 {
142 printf("ERROR!\n");
143 test_control_return(1);
144 }
145
146 status = nx_cloud_module_register(&cloud, &cloud_module, "Module 1", (NX_CLOUD_COMMON_PERIODIC_EVENT | NX_CLOUD_MODULE_EVENT), cloud_module_event_process, (void *)(&cloud_module));
147
148 /* Check status. */
149 if (status)
150 {
151 printf("ERROR!\n");
152 test_control_return(1);
153 }
154
155 /* nx_cloud_module_event_set. */
156 status = nx_cloud_module_event_set(NX_NULL, NX_CLOUD_MODULE_EVENT_1);
157
158 /* Check status. */
159 if (status != NX_PTR_ERROR)
160 {
161 printf("ERROR!\n");
162 test_control_return(1);
163 }
164
165 status = nx_cloud_module_event_set(&cloud_module, 0);
166
167 /* Check status. */
168 if (status != NX_CLOUD_MODULE_EVENT_INVALID)
169 {
170 printf("ERROR!\n");
171 test_control_return(1);
172 }
173
174 status = nx_cloud_module_event_set(&cloud_module, NX_CLOUD_MODULE_EVENT_1);
175
176 /* Check status. */
177 if (status)
178 {
179 printf("ERROR!\n");
180 test_control_return(1);
181 }
182
183
184 /* nx_cloud_module_event_clear. */
185 status = nx_cloud_module_event_clear(NX_NULL, NX_CLOUD_MODULE_EVENT_1);
186
187 /* Check status. */
188 if (status != NX_PTR_ERROR)
189 {
190 printf("ERROR!\n");
191 test_control_return(1);
192 }
193
194 status = nx_cloud_module_event_clear(&cloud_module, 0);
195
196 /* Check status. */
197 if (status != NX_CLOUD_MODULE_EVENT_INVALID)
198 {
199 printf("ERROR!\n");
200 test_control_return(1);
201 }
202
203 status = nx_cloud_module_event_clear(&cloud_module, NX_CLOUD_MODULE_EVENT_1);
204
205 /* Check status. */
206 if (status)
207 {
208 printf("ERROR!\n");
209 test_control_return(1);
210 }
211
212
213 /* nx_cloud_module_deregister. */
214 status = nx_cloud_module_deregister(NX_NULL, &cloud_module);
215
216 /* Check status. */
217 if (status != NX_PTR_ERROR)
218 {
219 printf("ERROR!\n");
220 test_control_return(1);
221 }
222
223 status = nx_cloud_module_deregister(&cloud, NX_NULL);
224
225 /* Check status. */
226 if (status != NX_PTR_ERROR)
227 {
228 printf("ERROR!\n");
229 test_control_return(1);
230 }
231
232 status = nx_cloud_module_deregister(&cloud, &cloud_module);
233
234 /* Check status. */
235 if (status)
236 {
237 printf("ERROR!\n");
238 test_control_return(1);
239 }
240
241
242 /* nx_cloud_delete. */
243 status = nx_cloud_delete(NX_NULL);
244
245 /* Check status. */
246 if (status != NX_PTR_ERROR)
247 {
248 printf("ERROR!\n");
249 test_control_return(1);
250 }
251
252 status = nx_cloud_delete(&cloud);
253
254 /* Check status. */
255 if (status)
256 {
257 printf("ERROR!\n");
258 test_control_return(1);
259 }
260
261 printf("SUCCESS!\n");
262 test_control_return(0);
263 }
264
cloud_module_event_process(VOID * module_ptr,ULONG common_events,ULONG module_own_events)265 static void cloud_module_event_process(VOID *module_ptr, ULONG common_events, ULONG module_own_events)
266 {
267 }
268
269 #else
270
271 #ifdef CTEST
test_application_define(void * first_unused_memory)272 VOID test_application_define(void *first_unused_memory)
273 #else
274 void netx_cloud_api_test_application_define(void *first_unused_memory)
275 #endif
276 {
277
278 /* Print out test information banner. */
279 printf("NetX Test: Cloud API Test............................................N/A\n");
280
281 test_control_return(3);
282 }
283 #endif
284
285