@@ -90,21 +90,35 @@ void TestInputFile(void)
90
90
CFE_FS_INVALID_PATH );
91
91
UtAssert_INT32_EQ (CFE_FS_ParseInputFileNameEx (OutNameBuf , InNameBuf , sizeof (OutNameBuf ), 0 , NULL , Path , Ext ),
92
92
CFE_FS_INVALID_PATH );
93
+
94
+ /* A short output buffer that is too small to fit the result */
95
+ UtAssert_INT32_EQ (CFE_FS_ParseInputFileNameEx (OutNameBuf , InNameBuf , 8 , sizeof (InNameBuf ), Name , Path , Ext ),
96
+ CFE_FS_FNAME_TOO_LONG );
93
97
}
94
98
95
99
void TestFileName (void )
96
100
{
97
- const char Path [] = "/func/FileName.test" ;
101
+ char Path [OS_MAX_PATH_LEN + 4 ] ;
98
102
char Name [OS_MAX_FILE_NAME ];
99
103
const char ExpectedName [] = "FileName.test" ;
100
104
101
105
UtPrintf ("Testing: CFE_FS_ExtractFilenameFromPath" );
102
106
107
+ snprintf (Path , sizeof (Path ), "/func/FileName.test" );
103
108
UtAssert_INT32_EQ (CFE_FS_ExtractFilenameFromPath (Path , Name ), CFE_SUCCESS );
104
109
UtAssert_StrCmp (Name , ExpectedName , "Extract Filename: %s" , Name );
105
110
106
111
UtAssert_INT32_EQ (CFE_FS_ExtractFilenameFromPath (NULL , Name ), CFE_FS_BAD_ARGUMENT );
107
112
UtAssert_INT32_EQ (CFE_FS_ExtractFilenameFromPath (Path , NULL ), CFE_FS_BAD_ARGUMENT );
113
+
114
+ memset (Path , 'x' , sizeof (Path ) - 1 );
115
+ Path [sizeof (Path ) - 1 ] = 0 ;
116
+ Path [0 ] = '/' ;
117
+ UtAssert_INT32_EQ (CFE_FS_ExtractFilenameFromPath (Path , Name ), CFE_FS_FNAME_TOO_LONG );
118
+
119
+ Path [0 ] = 'x' ;
120
+ Path [OS_MAX_PATH_LEN - 1 ] = 0 ;
121
+ UtAssert_INT32_EQ (CFE_FS_ExtractFilenameFromPath (Path , Name ), CFE_FS_INVALID_PATH );
108
122
}
109
123
110
124
/* FT helper stub compatible with background file write DataGetter */
@@ -119,32 +133,54 @@ bool FS_DataGetter(void *Meta, uint32 RecordNum, void **Buffer, size_t *BufSize)
119
133
void FS_OnEvent (void * Meta , CFE_FS_FileWriteEvent_t Event , int32 Status , uint32 RecordNum , size_t BlockSize ,
120
134
size_t Position )
121
135
{
136
+ OS_TaskDelay (100 );
122
137
}
123
138
124
139
void TestFileDump (void )
125
140
{
141
+ int32 count ;
142
+ int32 MaxWait = 20 ;
143
+
126
144
memset (& CFE_FT_Global .FuncTestState , 0 , sizeof (CFE_FT_Global .FuncTestState ));
127
145
CFE_FT_Global .FuncTestState .FileSubType = 2 ;
128
- CFE_FT_Global .FuncTestState .GetData = FS_DataGetter ;
129
- CFE_FT_Global .FuncTestState .OnEvent = FS_OnEvent ;
130
- strncpy (CFE_FT_Global .FuncTestState .FileName , "/ram/FT.bin" , sizeof (CFE_FT_Global .FuncTestState .FileName ));
131
146
strncpy (CFE_FT_Global .FuncTestState .Description , "FT" , sizeof (CFE_FT_Global .FuncTestState .Description ));
132
- int count = 0 ;
133
- int MaxWait = 20 ;
134
147
135
148
UtPrintf ("Testing: CFE_FS_BackgroundFileDumpRequest, CFE_FS_BackgroundFileDumpIsPending" );
136
149
137
150
UtAssert_INT32_EQ (CFE_FS_BackgroundFileDumpIsPending (& CFE_FT_Global .FuncTestState ), false);
151
+
152
+ /* With an empty "FileName" field, it should fail path validation */
153
+ CFE_FT_Global .FuncTestState .GetData = FS_DataGetter ;
154
+ CFE_FT_Global .FuncTestState .OnEvent = FS_OnEvent ;
155
+ UtAssert_INT32_EQ (CFE_FS_BackgroundFileDumpRequest (& CFE_FT_Global .FuncTestState ), CFE_FS_INVALID_PATH );
156
+ strncpy (CFE_FT_Global .FuncTestState .FileName , "/ram/FT.bin" , sizeof (CFE_FT_Global .FuncTestState .FileName ));
157
+
158
+ /* With an empty "GetData" field, it should fail validation */
159
+ CFE_FT_Global .FuncTestState .GetData = NULL ;
160
+ UtAssert_INT32_EQ (CFE_FS_BackgroundFileDumpRequest (& CFE_FT_Global .FuncTestState ), CFE_FS_BAD_ARGUMENT );
161
+ CFE_FT_Global .FuncTestState .GetData = FS_DataGetter ;
162
+
163
+ /* With an empty "OnEvent" field, it should fail validation */
164
+ CFE_FT_Global .FuncTestState .OnEvent = NULL ;
165
+ UtAssert_INT32_EQ (CFE_FS_BackgroundFileDumpRequest (& CFE_FT_Global .FuncTestState ), CFE_FS_BAD_ARGUMENT );
166
+ CFE_FT_Global .FuncTestState .OnEvent = FS_OnEvent ;
167
+
168
+ /* This should work */
138
169
UtAssert_INT32_EQ (CFE_FS_BackgroundFileDumpRequest (& CFE_FT_Global .FuncTestState ), CFE_SUCCESS );
139
170
171
+ /* Duplicate request should get rejected */
172
+ UtAssert_INT32_EQ (CFE_FS_BackgroundFileDumpRequest (& CFE_FT_Global .FuncTestState ),
173
+ CFE_STATUS_REQUEST_ALREADY_PENDING );
174
+
140
175
/* Wait for background task to complete */
176
+ count = 0 ;
141
177
while (CFE_FS_BackgroundFileDumpIsPending (& CFE_FT_Global .FuncTestState ) && count < MaxWait )
142
178
{
143
179
OS_TaskDelay (100 );
144
180
count ++ ;
145
181
}
146
182
147
- UtAssert_True ( count < MaxWait , "count (%i) < MaxWait (%i)" , count , MaxWait );
183
+ UtAssert_INT32_LT ( count , MaxWait );
148
184
149
185
UtAssert_INT32_EQ (CFE_FS_BackgroundFileDumpRequest (NULL ), CFE_FS_BAD_ARGUMENT );
150
186
UtAssert_INT32_EQ (CFE_FS_BackgroundFileDumpIsPending (NULL ), false);
0 commit comments