@@ -48,7 +48,7 @@ typedef struct
48
48
{
49
49
uint16 ExpectedEvent ;
50
50
uint32 MatchCount ;
51
- const char * ExpectedText ;
51
+ const char * ExpectedFormat ;
52
52
} UT_CheckEvent_t ;
53
53
54
54
/*
@@ -58,7 +58,6 @@ static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode, uint32 CallCou
58
58
va_list va )
59
59
{
60
60
UT_CheckEvent_t * State = UserObj ;
61
- char TestText [CFE_MISSION_EVS_MAX_MESSAGE_LENGTH ];
62
61
uint16 EventId ;
63
62
const char * Spec ;
64
63
@@ -71,24 +70,34 @@ static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode, uint32 CallCou
71
70
EventId = UT_Hook_GetArgValueByName (Context , "EventID" , uint16 );
72
71
if (EventId == State -> ExpectedEvent )
73
72
{
74
- /*
75
- * Example of how to validate the full argument set.
76
- * If reference text was supplied, also check against this.
77
- *
78
- * NOTE: While this can be done, use with discretion - This isn't really
79
- * verifying that the FSW code unit generated the correct event text,
80
- * rather it is validating what the system snprintf() library function
81
- * produces when passed the format string and args.
82
- *
83
- * __This derived string is not an actual output of the unit under test__
84
- */
85
- if (State -> ExpectedText != NULL )
73
+ if (State -> ExpectedFormat != NULL )
86
74
{
87
75
Spec = UT_Hook_GetArgValueByName (Context , "Spec" , const char * );
88
76
if (Spec != NULL )
89
77
{
90
- vsnprintf (TestText , sizeof (TestText ), Spec , va );
91
- if (strcmp (TestText , State -> ExpectedText ) == 0 )
78
+ /*
79
+ * Example of how to validate the full argument set.
80
+ * ------------------------------------------------
81
+ *
82
+ * If really desired one can call something like:
83
+ *
84
+ * char TestText[CFE_MISSION_EVS_MAX_MESSAGE_LENGTH];
85
+ * vsnprintf(TestText, sizeof(TestText), Spec, va);
86
+ *
87
+ * And then compare the output (TestText) to the expected fully-rendered string.
88
+ *
89
+ * NOTE: While this can be done, use with discretion - This isn't really
90
+ * verifying that the FSW code unit generated the correct event text,
91
+ * rather it is validating what the system snprintf() library function
92
+ * produces when passed the format string and args.
93
+ *
94
+ * This type of check has been demonstrated to make tests very fragile,
95
+ * because it is influenced by many factors outside the control of the
96
+ * test case.
97
+ *
98
+ * __This derived string is not an actual output of the unit under test__
99
+ */
100
+ if (strcmp (Spec , State -> ExpectedFormat ) == 0 )
92
101
{
93
102
++ State -> MatchCount ;
94
103
}
@@ -108,11 +117,11 @@ static int32 UT_CheckEvent_Hook(void *UserObj, int32 StubRetcode, uint32 CallCou
108
117
* Helper function to set up for event checking
109
118
* This attaches the hook function to CFE_EVS_SendEvent
110
119
*/
111
- static void UT_CheckEvent_Setup (UT_CheckEvent_t * Evt , uint16 ExpectedEvent , const char * ExpectedText )
120
+ static void UT_CheckEvent_Setup (UT_CheckEvent_t * Evt , uint16 ExpectedEvent , const char * ExpectedFormat )
112
121
{
113
122
memset (Evt , 0 , sizeof (* Evt ));
114
123
Evt -> ExpectedEvent = ExpectedEvent ;
115
- Evt -> ExpectedText = ExpectedText ;
124
+ Evt -> ExpectedFormat = ExpectedFormat ;
116
125
UT_SetVaHookFunction (UT_KEY (CFE_EVS_SendEvent ), UT_CheckEvent_Hook , Evt );
117
126
}
118
127
@@ -272,7 +281,7 @@ void Test_SAMPLE_ProcessCommandPacket(void)
272
281
UT_CheckEvent_t EventTest ;
273
282
274
283
memset (& TestMsg , 0 , sizeof (TestMsg ));
275
- UT_CheckEvent_Setup (& EventTest , SAMPLE_INVALID_MSGID_ERR_EID , "SAMPLE: invalid command packet,MID = 0xffff " );
284
+ UT_CheckEvent_Setup (& EventTest , SAMPLE_INVALID_MSGID_ERR_EID , "SAMPLE: invalid command packet,MID = 0x%x " );
276
285
277
286
/*
278
287
* The CFE_SB_GetMsgId() stub uses a data buffer to hold the
@@ -351,7 +360,7 @@ void Test_SAMPLE_ProcessGroundCommand(void)
351
360
SAMPLE_ProcessGroundCommand (& TestMsg .Base );
352
361
353
362
/* test an invalid CC */
354
- UT_CheckEvent_Setup (& EventTest , SAMPLE_COMMAND_ERR_EID , "Invalid ground command code: CC = 1000 " );
363
+ UT_CheckEvent_Setup (& EventTest , SAMPLE_COMMAND_ERR_EID , "Invalid ground command code: CC = %d " );
355
364
UT_SetDeferredRetcode (UT_KEY (CFE_SB_GetCmdCode ), 1 , 1000 );
356
365
SAMPLE_ProcessGroundCommand (& TestMsg .Base );
357
366
@@ -497,7 +506,7 @@ void Test_SAMPLE_VerifyCmdLength(void)
497
506
*/
498
507
UT_SetDeferredRetcode (UT_KEY (CFE_SB_GetTotalMsgLength ), 1 , sizeof (TestMsg ));
499
508
UT_CheckEvent_Setup (& EventTest , SAMPLE_LEN_ERR_EID ,
500
- "Invalid Msg length: ID = 0xFFFF , CC = 0 , Len = 18 , Expected = 8 " );
509
+ "Invalid Msg length: ID = 0x%X , CC = %d , Len = %d , Expected = %d " );
501
510
502
511
SAMPLE_VerifyCmdLength (& TestMsg , sizeof (TestMsg ));
503
512
0 commit comments