Skip to content

Commit

Permalink
Adds CF_strnlen handler
Browse files Browse the repository at this point in the history
  • Loading branch information
jdfiguer authored and jdfiguer committed Jun 17, 2024
1 parent 9ae8065 commit 6cad3bc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions unit-test/cf_cfdp_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,8 @@ void Test_CF_CFDP_SendMd(void)
strncpy(history->fnames.src_filename, "src1", sizeof(history->fnames.src_filename));
txn->state = CF_TxnState_S1;
txn->fsize = 1234;
UT_SetDefaultReturnValue(UT_KEY(CF_strnlen), strlen(history->fnames.src_filename));
UT_SetDeferredRetcode(UT_KEY(CF_strnlen), 1, strlen(history->fnames.dst_filename));
UtAssert_INT32_EQ(CF_CFDP_SendMd(txn), CFE_SUCCESS);
UtAssert_UINT32_EQ(md->size, txn->fsize);
UtAssert_STRINGBUF_EQ(md->dest_filename.data_ptr, md->dest_filename.length, history->fnames.dst_filename,
Expand All @@ -625,6 +627,8 @@ void Test_CF_CFDP_SendMd(void)
strncpy(history->fnames.src_filename, "src2", sizeof(history->fnames.src_filename));
txn->state = CF_TxnState_S2;
txn->fsize = 5678;
UT_SetDefaultReturnValue(UT_KEY(CF_strnlen), strlen(history->fnames.src_filename));
UT_SetDeferredRetcode(UT_KEY(CF_strnlen), 2, strlen(history->fnames.dst_filename));
UtAssert_INT32_EQ(CF_CFDP_SendMd(txn), CFE_SUCCESS);
UtAssert_UINT32_EQ(md->size, txn->fsize);
UtAssert_UINT32_EQ(md->dest_filename.length, sizeof(history->fnames.dst_filename));
Expand Down
18 changes: 18 additions & 0 deletions unit-test/stubs/cf_utils_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,3 +214,21 @@ void UT_DefaultHandler_CF_TxnStatus_IsError(void *UserObj, UT_EntryKey_t FuncKey

UT_Stub_SetReturnValue(FuncKey, result);
}


void UT_DefaultHandler_CF_strnlen(void *UserObj, UT_EntryKey_t FuncKey, const UT_StubContext_t *Context)
{
CF_strnlen_context_t *ctxt = UT_CF_GetContextBuffer(FuncKey, CF_strnlen_context_t);
uint8 retval;
const char * ptr;


if (ctxt)
{
ptr = UT_Hook_GetArgValueByName(Context, "str", const char *);
strncpy(ctxt->str, ptr, sizeof(ctxt->str));
}
retval = strlen(ctxt->str);

UT_Stub_SetReturnValue(FuncKey, retval);
}
2 changes: 2 additions & 0 deletions unit-test/stubs/cf_utils_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ void UT_DefaultHandler_CF_TxnStatus_IsError(void *, UT_EntryKey_t, const UT_Stub
void UT_DefaultHandler_CF_WrappedOpenCreate(void *, UT_EntryKey_t, const UT_StubContext_t *);
void UT_DefaultHandler_CF_WriteHistoryQueueDataToFile(void *, UT_EntryKey_t, const UT_StubContext_t *);
void UT_DefaultHandler_CF_WriteTxnQueueDataToFile(void *, UT_EntryKey_t, const UT_StubContext_t *);
void UT_DefaultHandler_CF_strnlen(void *, UT_EntryKey_t, const UT_StubContext_t *);

/*
* ----------------------------------------------------
Expand Down Expand Up @@ -430,6 +431,7 @@ size_t CF_strnlen(const char *str, size_t maxlen)
UT_GenStub_AddParam(CF_strnlen, size_t, maxlen);

UT_GenStub_Execute(CF_strnlen, Basic, NULL);
// UT_GenStub_Execute(CF_strnlen, Basic, UT_DefaultHandler_CF_strnlen);

return UT_GenStub_GetReturnValue(CF_strnlen, size_t);
}
5 changes: 5 additions & 0 deletions unit-test/utilities/cf_test_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,11 @@ typedef struct
CF_Transaction_t *context_t;
} CF_CList_Traverse_R_context_t;

typedef struct
{
char str[CF_FILENAME_MAX_LEN];
} CF_strnlen_context_t;

void *UT_CF_GetContextBufferImpl(UT_EntryKey_t FuncKey, size_t ReqSize);
#define UT_CF_GetContextBuffer(key, type) ((type *)UT_CF_GetContextBufferImpl(key, sizeof(type)))

Expand Down

0 comments on commit 6cad3bc

Please sign in to comment.