-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathcoveragetest_sample_app.c
594 lines (504 loc) · 19.6 KB
/
coveragetest_sample_app.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 United States Government as represented by
** the Administrator of the National Aeronautics and Space Administration.
** All Rights Reserved.
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
/*
** File: coveragetest_sample_app.c
**
** Purpose:
** Coverage Unit Test cases for the SAMPLE Application
**
** Notes:
** This implements various test cases to exercise all code
** paths through all functions defined in the SAMPLE application.
**
** It is primarily focused at providing examples of the various
** stub configurations, hook functions, and wrapper calls that
** are often needed when coercing certain code paths through
** complex functions.
*/
/*
* Includes
*/
#include "sample_lib.h"
#include "sample_app_coveragetest_common.h"
#include "ut_sample_app.h"
/* to get the SAMPLE_Function() declaration */
typedef struct
{
uint16 ExpectedEvent;
uint32 MatchCount;
const char *ExpectedText;
} UT_CheckEvent_t;
/*
* An example hook function to check for a specific event.
*/
static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode, uint32 CallCount, const UT_StubContext_t *Context,
va_list va)
{
UT_CheckEvent_t *State = UserObj;
char TestText[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
uint16 EventId;
const char * Spec;
/*
* The CFE_EVS_SendEvent stub passes the EventID as the
* first context argument.
*/
if (Context->ArgCount > 0)
{
EventId = UT_Hook_GetArgValueByName(Context, "EventID", uint16);
if (EventId == State->ExpectedEvent)
{
/*
* Example of how to validate the full argument set.
* If reference text was supplied, also check against this.
*
* NOTE: While this can be done, use with discretion - This isn't really
* verifying that the FSW code unit generated the correct event text,
* rather it is validating what the system snprintf() library function
* produces when passed the format string and args.
*
* __This derived string is not an actual output of the unit under test__
*/
if (State->ExpectedText != NULL)
{
Spec = UT_Hook_GetArgValueByName(Context, "Spec", const char *);
if (Spec != NULL)
{
vsnprintf(TestText, sizeof(TestText), Spec, va);
if (strcmp(TestText, State->ExpectedText) == 0)
{
++State->MatchCount;
}
}
}
else
{
++State->MatchCount;
}
}
}
return 0;
}
/*
* Helper function to set up for event checking
* This attaches the hook function to CFE_EVS_SendEvent
*/
static void UT_CheckEvent_Setup(UT_CheckEvent_t *Evt, uint16 ExpectedEvent, const char *ExpectedText)
{
memset(Evt, 0, sizeof(*Evt));
Evt->ExpectedEvent = ExpectedEvent;
Evt->ExpectedText = ExpectedText;
UT_SetVaHookFunction(UT_KEY(CFE_EVS_SendEvent), UT_CheckEvent_Hook, Evt);
}
/*
**********************************************************************************
** TEST CASE FUNCTIONS
**********************************************************************************
*/
void Test_SAMPLE_AppMain(void)
{
/*
* Test Case For:
* void SAMPLE_AppMain( void )
*/
UT_CheckEvent_t EventTest;
/*
* SAMPLE_AppMain does not return a value,
* but it has several internal decision points
* that need to be exercised here.
*
* First call it in "nominal" mode where all
* dependent calls should be successful by default.
*/
SAMPLE_AppMain();
/*
* Confirm that CFE_ES_ExitApp() was called at the end of execution
*/
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_ExitApp)) == 1, "CFE_ES_ExitApp() called");
/*
* Now set up individual cases for each of the error paths.
* The first is for SAMPLE_AppInit(). As this is in the same
* code unit, it is not a stub where the return code can be
* easily set. In order to get this to fail, an underlying
* call needs to fail, and the error gets propagated through.
* The call to CFE_EVS_Register is the first opportunity.
* Any identifiable (non-success) return code should work.
*/
UT_SetDeferredRetcode(UT_KEY(CFE_EVS_Register), 1, CFE_EVS_INVALID_PARAMETER);
/*
* Just call the function again. It does not return
* the value, so there is nothing to test for here directly.
* However, it should show up in the coverage report that
* the SAMPLE_AppInit() failure path was taken.
*/
SAMPLE_AppMain();
/*
* This can validate that the internal "RunStatus" was
* set to CFE_ES_RunStatus_APP_ERROR, by querying the struct directly.
*
* It is always advisable to include the _actual_ values
* when asserting on conditions, so if/when it fails, the
* log will show what the incorrect value was.
*/
UtAssert_True(SAMPLE_AppData.RunStatus == CFE_ES_RunStatus_APP_ERROR,
"SAMPLE_AppData.RunStatus (%lu) == CFE_ES_RunStatus_APP_ERROR",
(unsigned long)SAMPLE_AppData.RunStatus);
/*
* Note that CFE_ES_RunLoop returns a boolean value,
* so in order to exercise the internal "while" loop,
* it needs to return TRUE. But this also needs to return
* FALSE in order to get out of the loop, otherwise
* it will stay there infinitely.
*
* The deferred retcode will accomplish this.
*/
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);
/*
* Invoke again
*/
SAMPLE_AppMain();
/*
* Confirm that CFE_SB_RcvMsg() (inside the loop) was called
*/
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_SB_RcvMsg)) == 1, "CFE_SB_RcvMsg() called");
/*
* Now also make the CFE_SB_RcvMsg call fail,
* to exercise that error path. This sends an
* event which can be checked with a hook function.
*/
UT_SetDeferredRetcode(UT_KEY(CFE_ES_RunLoop), 1, true);
UT_SetDeferredRetcode(UT_KEY(CFE_SB_RcvMsg), 1, CFE_SB_PIPE_RD_ERR);
UT_CheckEvent_Setup(&EventTest, SAMPLE_PIPE_ERR_EID, "SAMPLE APP: SB Pipe Read Error, App Will Exit");
/*
* Invoke again
*/
SAMPLE_AppMain();
/*
* Confirm that the event was generated
*/
UtAssert_True(EventTest.MatchCount == 1, "SAMPLE_PIPE_ERR_EID generated (%u)", (unsigned int)EventTest.MatchCount);
}
void Test_SAMPLE_AppInit(void)
{
/*
* Test Case For:
* int32 SAMPLE_AppInit( void )
*/
/* nominal case should return CFE_SUCCESS */
UT_TEST_FUNCTION_RC(SAMPLE_AppInit(), CFE_SUCCESS);
/* trigger a failure for each of the sub-calls,
* and confirm a write to syslog for each.
* Note that this count accumulates, because the status
* is _not_ reset between these test cases. */
UT_SetDeferredRetcode(UT_KEY(CFE_EVS_Register), 1, CFE_EVS_INVALID_PARAMETER);
UT_TEST_FUNCTION_RC(SAMPLE_AppInit(), CFE_EVS_INVALID_PARAMETER);
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 1, "CFE_ES_WriteToSysLog() called");
UT_SetDeferredRetcode(UT_KEY(CFE_SB_CreatePipe), 1, CFE_SB_BAD_ARGUMENT);
UT_TEST_FUNCTION_RC(SAMPLE_AppInit(), CFE_SB_BAD_ARGUMENT);
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 2, "CFE_ES_WriteToSysLog() called");
UT_SetDeferredRetcode(UT_KEY(CFE_SB_Subscribe), 1, CFE_SB_BAD_ARGUMENT);
UT_TEST_FUNCTION_RC(SAMPLE_AppInit(), CFE_SB_BAD_ARGUMENT);
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 3, "CFE_ES_WriteToSysLog() called");
UT_SetDeferredRetcode(UT_KEY(CFE_SB_Subscribe), 2, CFE_SB_BAD_ARGUMENT);
UT_TEST_FUNCTION_RC(SAMPLE_AppInit(), CFE_SB_BAD_ARGUMENT);
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 4, "CFE_ES_WriteToSysLog() called");
UT_SetDeferredRetcode(UT_KEY(CFE_TBL_Register), 1, CFE_TBL_ERR_INVALID_OPTIONS);
UT_TEST_FUNCTION_RC(SAMPLE_AppInit(), CFE_TBL_ERR_INVALID_OPTIONS);
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 5, "CFE_ES_WriteToSysLog() called");
}
void Test_SAMPLE_ProcessCommandPacket(void)
{
/*
* Test Case For:
* void SAMPLE_ProcessCommandPacket( CFE_SB_MsgPtr_t Msg )
*/
/* a buffer large enough for any command message */
union
{
CFE_SB_Msg_t Base;
CFE_SB_CmdHdr_t Cmd;
SAMPLE_Noop_t Noop;
SAMPLE_ResetCounters_t Reset;
SAMPLE_Process_t Process;
} TestMsg;
CFE_SB_MsgId_t TestMsgId;
UT_CheckEvent_t EventTest;
memset(&TestMsg, 0, sizeof(TestMsg));
UT_CheckEvent_Setup(&EventTest, SAMPLE_INVALID_MSGID_ERR_EID, "SAMPLE: invalid command packet,MID = 0xffff");
/*
* The CFE_SB_GetMsgId() stub uses a data buffer to hold the
* message ID values to return.
*/
TestMsgId = SAMPLE_APP_CMD_MID;
UT_SetDataBuffer(UT_KEY(CFE_SB_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
SAMPLE_ProcessCommandPacket(&TestMsg.Base);
TestMsgId = SAMPLE_APP_SEND_HK_MID;
UT_SetDataBuffer(UT_KEY(CFE_SB_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
SAMPLE_ProcessCommandPacket(&TestMsg.Base);
/* invalid message id */
TestMsgId = CFE_SB_INVALID_MSG_ID;
UT_SetDataBuffer(UT_KEY(CFE_SB_GetMsgId), &TestMsgId, sizeof(TestMsgId), false);
SAMPLE_ProcessCommandPacket(&TestMsg.Base);
/*
* Confirm that the event was generated only _once_
*/
UtAssert_True(EventTest.MatchCount == 1, "SAMPLE_COMMAND_ERR_EID generated (%u)",
(unsigned int)EventTest.MatchCount);
}
void Test_SAMPLE_ProcessGroundCommand(void)
{
/*
* Test Case For:
* void SAMPLE_ProcessGroundCommand( CFE_SB_MsgPtr_t Msg )
*/
/* a buffer large enough for any command message */
union
{
CFE_SB_Msg_t Base;
CFE_SB_CmdHdr_t Cmd;
SAMPLE_Noop_t Noop;
SAMPLE_ResetCounters_t Reset;
SAMPLE_Process_t Process;
} TestMsg;
UT_CheckEvent_t EventTest;
memset(&TestMsg, 0, sizeof(TestMsg));
/*
* call with each of the supported command codes
* The CFE_SB_GetCmdCode stub allows the code to be
* set to whatever is needed. There is no return
* value here and the actual implementation of these
* commands have separate test cases, so this just
* needs to exercise the "switch" statement.
*/
/* test dispatch of NOOP */
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetCmdCode), 1, SAMPLE_APP_NOOP_CC);
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg.Noop));
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID, NULL);
SAMPLE_ProcessGroundCommand(&TestMsg.Base);
/* test dispatch of RESET */
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetCmdCode), 1, SAMPLE_APP_RESET_COUNTERS_CC);
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg.Reset));
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID, NULL);
SAMPLE_ProcessGroundCommand(&TestMsg.Base);
/* test dispatch of PROCESS */
/* note this will end up calling SAMPLE_Process(), and as such it needs to
* avoid dereferencing a table which does not exist. */
UT_SetForceFail(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_ERR_UNREGISTERED);
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetCmdCode), 1, SAMPLE_APP_PROCESS_CC);
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg.Process));
SAMPLE_ProcessGroundCommand(&TestMsg.Base);
/* test an invalid CC */
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMAND_ERR_EID, "Invalid ground command code: CC = 1000");
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetCmdCode), 1, 1000);
SAMPLE_ProcessGroundCommand(&TestMsg.Base);
/*
* Confirm that the event was generated only _once_
*/
UtAssert_True(EventTest.MatchCount == 1, "SAMPLE_COMMAND_ERR_EID generated (%u)",
(unsigned int)EventTest.MatchCount);
}
void Test_SAMPLE_ReportHousekeeping(void)
{
/*
* Test Case For:
* void SAMPLE_ReportHousekeeping( const CFE_SB_CmdHdr_t *Msg )
*/
CFE_SB_Msg_t * MsgSend;
CFE_SB_Msg_t * MsgTimestamp;
CFE_SB_MsgId_t MsgId = CFE_SB_ValueToMsgId(SAMPLE_APP_SEND_HK_MID);
/* Set message id to return so SAMPLE_Housekeeping will be called */
UT_SetDataBuffer(UT_KEY(CFE_SB_GetMsgId), &MsgId, sizeof(MsgId), false);
/* Set up to capture send message address */
UT_SetDataBuffer(UT_KEY(CFE_SB_SendMsg), &MsgSend, sizeof(MsgSend), false);
/* Set up to capture timestamp message address */
UT_SetDataBuffer(UT_KEY(CFE_SB_TimeStampMsg), &MsgTimestamp, sizeof(MsgTimestamp), false);
/* Call unit under test, NULL pointer confirms command access is through APIs */
SAMPLE_ProcessCommandPacket((CFE_SB_Msg_t *)NULL);
/* Confirm message sent*/
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_SB_SendMsg)) == 1, "CFE_SB_SendMsg() called once");
UtAssert_True(MsgSend == &SAMPLE_AppData.HkBuf.MsgHdr, "CFE_SB_SendMsg() address matches expected");
/* Confirm timestamp msg address */
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_SB_TimeStampMsg)) == 1, "CFE_SB_TimeStampMsg() called once");
UtAssert_True(MsgTimestamp == &SAMPLE_AppData.HkBuf.MsgHdr, "CFE_SB_TimeStampMsg() adress matches expected");
/*
* Confirm that the CFE_TBL_Manage() call was done
*/
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_TBL_Manage)) == 1, "CFE_TBL_Manage() called");
}
void Test_SAMPLE_NoopCmd(void)
{
/*
* Test Case For:
* void SAMPLE_NoopCmd( const SAMPLE_Noop_t *Msg )
*/
SAMPLE_Noop_t TestMsg;
UT_CheckEvent_t EventTest;
memset(&TestMsg, 0, sizeof(TestMsg));
/* test dispatch of NOOP */
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDNOP_INF_EID, NULL);
UT_TEST_FUNCTION_RC(SAMPLE_Noop(&TestMsg), CFE_SUCCESS);
/*
* Confirm that the event was generated
*/
UtAssert_True(EventTest.MatchCount == 1, "SAMPLE_COMMANDNOP_INF_EID generated (%u)",
(unsigned int)EventTest.MatchCount);
}
void Test_SAMPLE_ResetCounters(void)
{
/*
* Test Case For:
* void SAMPLE_ResetCounters( const SAMPLE_ResetCounters_t *Msg )
*/
SAMPLE_ResetCounters_t TestMsg;
UT_CheckEvent_t EventTest;
memset(&TestMsg, 0, sizeof(TestMsg));
UT_CheckEvent_Setup(&EventTest, SAMPLE_COMMANDRST_INF_EID, "SAMPLE: RESET command");
UT_TEST_FUNCTION_RC(SAMPLE_ResetCounters(&TestMsg), CFE_SUCCESS);
/*
* Confirm that the event was generated
*/
UtAssert_True(EventTest.MatchCount == 1, "SAMPLE_COMMANDRST_INF_EID generated (%u)",
(unsigned int)EventTest.MatchCount);
}
void Test_SAMPLE_ProcessCC(void)
{
/*
* Test Case For:
* void SAMPLE_ProcessCC( const SAMPLE_Process_t *Msg )
*/
SAMPLE_Process_t TestMsg;
SAMPLE_APP_Table_t TestTblData;
void * TblPtr = &TestTblData;
memset(&TestTblData, 0, sizeof(TestTblData));
memset(&TestMsg, 0, sizeof(TestMsg));
/* Provide some table data for the SAMPLE_Process() function to use */
TestTblData.Int1 = 40;
TestTblData.Int2 = 50;
UT_SetDataBuffer(UT_KEY(CFE_TBL_GetAddress), &TblPtr, sizeof(TblPtr), false);
UT_TEST_FUNCTION_RC(SAMPLE_Process(&TestMsg), CFE_SUCCESS);
/*
* Confirm that the CFE_TBL_GetAddress() call was done
*/
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_TBL_GetAddress)) == 1, "CFE_TBL_GetAddress() called");
/*
* Confirm that the SAMPLE_Function() call was done
* NOTE: This stub is provided by the sample_lib library
*/
UtAssert_True(UT_GetStubCount(UT_KEY(SAMPLE_Function)) == 1, "SAMPLE_Function() called");
/*
* Configure the CFE_TBL_GetAddress function to return an error
* Exercise the error return path
*/
UT_SetForceFail(UT_KEY(CFE_TBL_GetAddress), CFE_TBL_ERR_UNREGISTERED);
UT_TEST_FUNCTION_RC(SAMPLE_Process(&TestMsg), CFE_TBL_ERR_UNREGISTERED);
}
void Test_SAMPLE_VerifyCmdLength(void)
{
/*
* Test Case For:
* bool SAMPLE_VerifyCmdLength( CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength )
*/
CFE_SB_Msg_t TestMsg;
UT_CheckEvent_t EventTest;
memset(&TestMsg, 0, sizeof(TestMsg));
/*
* test a match case
*/
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, sizeof(TestMsg));
UT_CheckEvent_Setup(&EventTest, SAMPLE_LEN_ERR_EID,
"Invalid Msg length: ID = 0xFFFF, CC = 0, Len = 18, Expected = 8");
SAMPLE_VerifyCmdLength(&TestMsg, sizeof(TestMsg));
/*
* Confirm that the event was NOT generated
*/
UtAssert_True(EventTest.MatchCount == 0, "SAMPLE_LEN_ERR_EID NOT generated (%u)",
(unsigned int)EventTest.MatchCount);
/*
* test a mismatch case
*/
UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetTotalMsgLength), 1, 10 + sizeof(TestMsg));
SAMPLE_VerifyCmdLength(&TestMsg, sizeof(TestMsg));
/*
* Confirm that the event WAS generated
*/
UtAssert_True(EventTest.MatchCount == 1, "SAMPLE_LEN_ERR_EID generated (%u)", (unsigned int)EventTest.MatchCount);
}
void Test_SAMPLE_TblValidationFunc(void)
{
/*
* Test Case For:
* int32 SAMPLE_TblValidationFunc( void *TblData )
*/
SAMPLE_APP_Table_t TestTblData;
memset(&TestTblData, 0, sizeof(TestTblData));
/* nominal case (0) should succeed */
UT_TEST_FUNCTION_RC(SAMPLE_TblValidationFunc(&TestTblData), CFE_SUCCESS);
/* error case should return SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE */
TestTblData.Int1 = 1 + SAMPLE_APP_TBL_ELEMENT_1_MAX;
UT_TEST_FUNCTION_RC(SAMPLE_TblValidationFunc(&TestTblData), SAMPLE_APP_TABLE_OUT_OF_RANGE_ERR_CODE);
}
void Test_SAMPLE_GetCrc(void)
{
/*
* Test Case For:
* void SAMPLE_GetCrc( const char *TableName )
*/
/*
* The only branch point here is CFE_TBL_GetInfo()
*
* Either way this function just does a write to syslog,
* and it is the same in both cases, just with
* a different message. This could actually verify
* the message using a hook function, if desired.
*/
UT_SetForceFail(UT_KEY(CFE_TBL_GetInfo), CFE_TBL_ERR_INVALID_NAME);
SAMPLE_GetCrc("UT");
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 1, "CFE_ES_WriteToSysLog() called");
UT_ClearForceFail(UT_KEY(CFE_TBL_GetInfo));
SAMPLE_GetCrc("UT");
UtAssert_True(UT_GetStubCount(UT_KEY(CFE_ES_WriteToSysLog)) == 2, "CFE_ES_WriteToSysLog() called");
}
/*
* Setup function prior to every test
*/
void Sample_UT_Setup(void)
{
UT_ResetState(0);
}
/*
* Teardown function after every test
*/
void Sample_UT_TearDown(void) {}
/*
* Register the test cases to execute with the unit test tool
*/
void UtTest_Setup(void)
{
ADD_TEST(SAMPLE_AppMain);
ADD_TEST(SAMPLE_AppInit);
ADD_TEST(SAMPLE_ProcessCommandPacket);
ADD_TEST(SAMPLE_ProcessGroundCommand);
ADD_TEST(SAMPLE_ReportHousekeeping);
ADD_TEST(SAMPLE_NoopCmd);
ADD_TEST(SAMPLE_ResetCounters);
ADD_TEST(SAMPLE_ProcessCC);
ADD_TEST(SAMPLE_VerifyCmdLength);
ADD_TEST(SAMPLE_TblValidationFunc);
ADD_TEST(SAMPLE_GetCrc);
}