Skip to content

Commit

Permalink
Fix #37, Send message with buffer provided
Browse files Browse the repository at this point in the history
  • Loading branch information
chillfig committed Jul 28, 2022
1 parent 199ed8e commit 26573f2
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
10 changes: 5 additions & 5 deletions fsw/src/ds_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -1044,18 +1044,18 @@ void DS_FileTestAge(uint32 ElapsedSeconds)

void DS_FileTransmit(DS_AppFileStatus_t *FileStatus)
{
typedef union
{
CFE_SB_Buffer_t SBBuf;
DS_FileCompletePkt_t Pkt;
} DS_FileCompletePktBuf_t;
DS_FileCompletePktBuf_t *PktBuf;

/*
** Get a Message block of memory and initialize it
*/
PktBuf = (DS_FileCompletePktBuf_t *)CFE_SB_AllocateMessageBuffer(sizeof(*PktBuf));

if (PktBuf == NULL)
{
return;
}

CFE_MSG_Init(&PktBuf->Pkt.TlmHeader.Msg, CFE_SB_ValueToMsgId(DS_COMP_TLM_MID), sizeof(*PktBuf));

/*
Expand Down
6 changes: 6 additions & 0 deletions fsw/src/ds_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,12 @@ typedef struct
DS_FileInfo_t FileInfo; /**< \brief Current state of destination file */
} DS_FileCompletePkt_t;

typedef union
{
CFE_SB_Buffer_t SBBuf;
DS_FileCompletePkt_t Pkt;
} DS_FileCompletePktBuf_t;

/**\}*/

#endif
22 changes: 21 additions & 1 deletion unit-test/ds_file_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -1741,16 +1741,35 @@ void DS_IsPacketFiltered_Test_TimeFilter3(void)

void DS_FileTransmit_Test_Nominal(void)
{
DS_FileCompletePktBuf_t PktBuf;
DS_FileCompletePktBuf_t *PktBufPtr = &PktBuf;

/* setup for a call to CFE_SB_AllocateMessageBuffer() */
memset(PktBufPtr, 0, sizeof(*PktBufPtr));
UT_SetDataBuffer(UT_KEY(CFE_SB_AllocateMessageBuffer), &PktBufPtr, sizeof(PktBufPtr), true);

/* Execute the function being tested */
UtAssert_VOIDCALL(DS_FileTransmit(&DS_AppData.FileStatus[0]));

/* Verify results */
UtAssert_STUB_COUNT(CFE_MSG_Init, 1);
UtAssert_STUB_COUNT(CFE_SB_AllocateMessageBuffer, 1);
UtAssert_STUB_COUNT(CFE_MSG_Init, 1);
UtAssert_STUB_COUNT(CFE_SB_TimeStampMsg, 1);
UtAssert_STUB_COUNT(CFE_SB_TransmitBuffer, 1);
}

void DS_FileTransmit_Test_NoBuf(void)
{
/* Execute the function being tested */
UtAssert_VOIDCALL(DS_FileTransmit(&DS_AppData.FileStatus[0]));

/* Verify results */
UtAssert_STUB_COUNT(CFE_SB_AllocateMessageBuffer, 1);
UtAssert_STUB_COUNT(CFE_MSG_Init, 0);
UtAssert_STUB_COUNT(CFE_SB_TimeStampMsg, 0);
UtAssert_STUB_COUNT(CFE_SB_TransmitBuffer, 0);
}

void UtTest_Setup(void)
{
UtTest_Add(DS_FileStorePacket_Test_Nominal, DS_Test_Setup, DS_Test_TearDown, "DS_FileStorePacket_Test_Nominal");
Expand Down Expand Up @@ -1868,6 +1887,7 @@ void UtTest_Setup(void)
"DS_IsPacketFiltered_Test_TimeFilter3");

UtTest_Add(DS_FileTransmit_Test_Nominal, DS_Test_Setup, DS_Test_TearDown, "DS_FileTransmit_Test_Nominal");
UtTest_Add(DS_FileTransmit_Test_NoBuf, DS_Test_Setup, DS_Test_TearDown, "DS_FileTransmit_Test_NoBuf");

} /* end DS_File_Test_AddTestCases */

Expand Down

0 comments on commit 26573f2

Please sign in to comment.