Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #97, Update UT to handle DS_SEQUENCE_DIGITS configuration #98

Merged
merged 1 commit into from
Mar 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions unit-test/ds_file_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,8 +591,12 @@ void DS_FileCreateDest_Test_ClosedFileHandle(void)

void DS_FileCreateName_Test_Nominal(void)
{
int32 FileIndex = 0;
char StrCompare[] = "path/base00000001.ext";
int32 FileIndex = 0;
char StrFormat[OS_MAX_PATH_LEN];
char StrCompare[OS_MAX_PATH_LEN];

snprintf(StrFormat, sizeof(StrFormat), "path/base%%0%uu.ext", DS_SEQUENCE_DIGITS);
snprintf(StrCompare, sizeof(StrCompare), StrFormat, 1);

DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = DS_BY_COUNT;
UT_DS_SetDestFileEntry(&DS_AppData.DestFileTblPtr->File[FileIndex]);
Expand All @@ -611,8 +615,12 @@ void DS_FileCreateName_Test_Nominal(void)

void DS_FileCreateName_Test_NominalWithSeparator(void)
{
int32 FileIndex = 0;
char StrCompare[] = "path/base00000001.ext";
int32 FileIndex = 0;
char StrFormat[OS_MAX_PATH_LEN];
char StrCompare[OS_MAX_PATH_LEN];

snprintf(StrFormat, sizeof(StrFormat), "path/base%%0%uu.ext", DS_SEQUENCE_DIGITS);
snprintf(StrCompare, sizeof(StrCompare), StrFormat, 1);

DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = DS_BY_COUNT;
UT_DS_SetDestFileEntry(&DS_AppData.DestFileTblPtr->File[FileIndex]);
Expand All @@ -633,8 +641,12 @@ void DS_FileCreateName_Test_NominalWithSeparator(void)

void DS_FileCreateName_Test_NominalWithPeriod(void)
{
int32 FileIndex = 0;
char StrCompare[] = "path/base00000001.ext";
int32 FileIndex = 0;
char StrFormat[OS_MAX_PATH_LEN];
char StrCompare[OS_MAX_PATH_LEN];

snprintf(StrFormat, sizeof(StrFormat), "path/base%%0%uu.ext", DS_SEQUENCE_DIGITS);
snprintf(StrCompare, sizeof(StrCompare), StrFormat, 1);

DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = DS_BY_COUNT;
UT_DS_SetDestFileEntry(&DS_AppData.DestFileTblPtr->File[FileIndex]);
Expand Down Expand Up @@ -746,8 +758,12 @@ void DS_FileCreateName_Test_PathBaseSeqExtTooLarge(void)

void DS_FileCreateName_Test_ExtensionZero(void)
{
int32 FileIndex = 0;
char StrCompare[] = "path/base00000001";
int32 FileIndex = 0;
char StrFormat[OS_MAX_PATH_LEN];
char StrCompare[OS_MAX_PATH_LEN];

snprintf(StrFormat, sizeof(StrFormat), "path/base%%0%uu", DS_SEQUENCE_DIGITS);
snprintf(StrCompare, sizeof(StrCompare), StrFormat, 1);

UT_DS_SetDestFileEntry(&DS_AppData.DestFileTblPtr->File[FileIndex]);

Expand All @@ -769,22 +785,21 @@ void DS_FileCreateName_Test_ExtensionZero(void)
#if DS_FILE_HEADER_TYPE == DS_FILE_HEADER_CFE
void DS_FileCreateSequence_Test_ByCount(void)
{
int32 FileIndex = 0;
const uint32 Count = 1;
char StrFormat[DS_TOTAL_FNAME_BUFSIZE];
char StrCompare[DS_TOTAL_FNAME_BUFSIZE];
char Sequence[DS_TOTAL_FNAME_BUFSIZE];

char Sequence[DS_TOTAL_FNAME_BUFSIZE];
snprintf(StrFormat, sizeof(StrFormat), "%%0%uu", DS_SEQUENCE_DIGITS);
snprintf(StrCompare, sizeof(StrCompare), StrFormat, Count);

memset(Sequence, 0, sizeof(Sequence));

DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType = DS_BY_COUNT;

DS_AppData.FileStatus[FileIndex].FileCount = 1;

/* Execute the function being tested */
DS_FileCreateSequence(Sequence, DS_AppData.DestFileTblPtr->File[FileIndex].FileNameType,
DS_AppData.FileStatus[FileIndex].FileCount);
DS_FileCreateSequence(Sequence, DS_BY_COUNT, Count);

/* Verify results */
UtAssert_UINT32_EQ(strncmp(Sequence, "00000001", DS_TOTAL_FNAME_BUFSIZE), 0);
UtAssert_STRINGBUF_EQ(Sequence, sizeof(Sequence), StrCompare, sizeof(StrCompare));
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 0);
}
#endif
Expand Down