@@ -211,20 +211,80 @@ void unittest_Service_GetIndex(void)
211
211
}
212
212
}
213
213
214
+ void unittest_Service_AddAutoUpdateTarget (void )
215
+ {
216
+ NEW_TEST_CASE ("Test Service_AddAutoUpdateTarget assert conditions" );
217
+ {
218
+ TRY
219
+ {
220
+ Service_AddAutoUpdateTarget (NULL , 1 , 10 );
221
+ }
222
+ TEST_ASSERT_TRUE (IS_ASSERT ());
223
+ END_TRY ;
224
+
225
+ TRY
226
+ {
227
+ Service_AddAutoUpdateTarget (& service_ctx .list [0 ], 0 , 10 );
228
+ }
229
+ TEST_ASSERT_TRUE (IS_ASSERT ());
230
+ END_TRY ;
231
+
232
+ TRY
233
+ {
234
+ Service_AddAutoUpdateTarget (& service_ctx .list [0 ], 1 , 0 );
235
+ }
236
+ TEST_ASSERT_TRUE (IS_ASSERT ());
237
+ END_TRY ;
238
+ }
239
+ NEW_TEST_CASE ("Test Service_AddAutoUpdateTarget" );
240
+ {
241
+ TRY
242
+ {
243
+ Service_AddAutoUpdateTarget (& service_ctx .list [0 ], 2 , 20 );
244
+ TEST_ASSERT_EQUAL (2 , service_ctx .auto_refresh [0 ].target );
245
+ TEST_ASSERT_EQUAL (20 , service_ctx .auto_refresh [0 ].time_ms );
246
+ TEST_ASSERT_EQUAL (& service_ctx .list [0 ], service_ctx .auto_refresh [0 ].service );
247
+ Service_AddAutoUpdateTarget (& service_ctx .list [0 ], 3 , 10 );
248
+ TEST_ASSERT_EQUAL (2 , service_ctx .auto_refresh [0 ].target );
249
+ TEST_ASSERT_EQUAL (20 , service_ctx .auto_refresh [0 ].time_ms );
250
+ TEST_ASSERT_EQUAL (& service_ctx .list [0 ], service_ctx .auto_refresh [0 ].service );
251
+ TEST_ASSERT_EQUAL (3 , service_ctx .auto_refresh [1 ].target );
252
+ TEST_ASSERT_EQUAL (10 , service_ctx .auto_refresh [1 ].time_ms );
253
+ TEST_ASSERT_EQUAL (& service_ctx .list [0 ], service_ctx .auto_refresh [1 ].service );
254
+ Service_AddAutoUpdateTarget (& service_ctx .list [1 ], 1 , 5 );
255
+ TEST_ASSERT_EQUAL (2 , service_ctx .auto_refresh [0 ].target );
256
+ TEST_ASSERT_EQUAL (20 , service_ctx .auto_refresh [0 ].time_ms );
257
+ TEST_ASSERT_EQUAL (& service_ctx .list [0 ], service_ctx .auto_refresh [0 ].service );
258
+ TEST_ASSERT_EQUAL (3 , service_ctx .auto_refresh [1 ].target );
259
+ TEST_ASSERT_EQUAL (10 , service_ctx .auto_refresh [1 ].time_ms );
260
+ TEST_ASSERT_EQUAL (& service_ctx .list [0 ], service_ctx .auto_refresh [1 ].service );
261
+ TEST_ASSERT_EQUAL (1 , service_ctx .auto_refresh [2 ].target );
262
+ TEST_ASSERT_EQUAL (5 , service_ctx .auto_refresh [2 ].time_ms );
263
+ TEST_ASSERT_EQUAL (& service_ctx .list [1 ], service_ctx .auto_refresh [2 ].service );
264
+ }
265
+ CATCH
266
+ {
267
+ TEST_ASSERT_TRUE (false);
268
+ }
269
+ END_TRY ;
270
+ }
271
+ }
272
+
214
273
void unittest_Service_RmAutoUpdateTarget (void )
215
274
{
216
275
NEW_TEST_CASE ("Test Service_RmAutoUpdateTarget" );
217
276
{
218
277
TRY
219
278
{
220
- service_ctx .number = 10 ;
221
- service_ctx .list [2 ].auto_refresh .target = 2 ;
222
- service_ctx .list [2 ].auto_refresh .time_ms = 20 ;
223
- service_ctx .list [2 ].auto_refresh .last_update = 30 ;
279
+ service_ctx .number = 10 ;
280
+ service_ctx .auto_refresh [0 ].service = & service_ctx .list [0 ];
281
+ service_ctx .auto_refresh [0 ].target = 2 ;
282
+ service_ctx .auto_refresh [0 ].time_ms = 20 ;
283
+ service_ctx .auto_refresh [0 ].last_update = 30 ;
224
284
Service_RmAutoUpdateTarget (2 );
225
- TEST_ASSERT_EQUAL (0 , service_ctx .list [ 2 ]. auto_refresh .target );
226
- TEST_ASSERT_EQUAL (0 , service_ctx .list [ 2 ]. auto_refresh .time_ms );
227
- TEST_ASSERT_EQUAL (0 , service_ctx .list [ 2 ]. auto_refresh .last_update );
285
+ TEST_ASSERT_EQUAL (0 , service_ctx .auto_refresh [ 0 ] .target );
286
+ TEST_ASSERT_EQUAL (0 , service_ctx .auto_refresh [ 0 ] .time_ms );
287
+ TEST_ASSERT_EQUAL (0 , service_ctx .auto_refresh [ 0 ] .last_update );
228
288
}
229
289
CATCH
230
290
{
@@ -243,11 +303,12 @@ void unittest_Service_AutoUpdateManager(void)
243
303
// Init default scenario context
244
304
Init_Context ();
245
305
Luos_Loop ();
246
- service_ctx .list [2 ].auto_refresh .target = 1 ;
247
- service_ctx .list [2 ].auto_refresh .time_ms = 10 ;
248
- service_ctx .list [2 ].auto_refresh .last_update = 30 ;
306
+ service_ctx .auto_refresh [0 ].service = default_sc .App_3 .app ;
307
+ service_ctx .auto_refresh [0 ].target = 1 ;
308
+ service_ctx .auto_refresh [0 ].time_ms = 10 ;
309
+ service_ctx .auto_refresh [0 ].last_update = 30 ;
249
310
Service_AutoUpdateManager ();
250
- TEST_ASSERT_NOT_EQUAL (30 , service_ctx .list [ 2 ]. auto_refresh .last_update );
311
+ TEST_ASSERT_NOT_EQUAL (30 , service_ctx .auto_refresh [ 0 ] .last_update );
251
312
TEST_ASSERT_EQUAL (GET_CMD , default_sc .App_3 .last_rx_msg .header .cmd );
252
313
TEST_ASSERT_EQUAL (1 , default_sc .App_3 .last_rx_msg .header .source );
253
314
TEST_ASSERT_EQUAL (3 , default_sc .App_3 .last_rx_msg .header .target );
@@ -534,6 +595,7 @@ int main(int argc, char **argv)
534
595
UNIT_TEST_RUN (unittest_Service_GenerateId );
535
596
UNIT_TEST_RUN (unittest_Service_ClearId );
536
597
UNIT_TEST_RUN (unittest_Service_GetIndex );
598
+ UNIT_TEST_RUN (unittest_Service_AddAutoUpdateTarget );
537
599
UNIT_TEST_RUN (unittest_Service_RmAutoUpdateTarget );
538
600
UNIT_TEST_RUN (unittest_Service_AutoUpdateManager );
539
601
UNIT_TEST_RUN (unittest_Service_GetConcerned );
0 commit comments