diff --git a/modules/cfe_testcase/src/es_cds_test.c b/modules/cfe_testcase/src/es_cds_test.c index a3309d1e8..c8537bdfc 100644 --- a/modules/cfe_testcase/src/es_cds_test.c +++ b/modules/cfe_testcase/src/es_cds_test.c @@ -37,21 +37,54 @@ void TestCDS(void) { CFE_ES_CDSHandle_t CDSHandlePtr; size_t BlockSize = 10; - const char * Name = "CDS_Testing"; + const char * Name = "CDS_Test"; + const char * CDSName = "TESTRUN_APP.CDS_Test"; CFE_ES_CDSHandle_t IdByName; - char CDSNameBuf[CFE_MISSION_ES_CDS_MAX_NAME_LENGTH]; + char CDSNameBuf[CFE_MISSION_ES_CDS_MAX_FULL_NAME_LEN]; + CFE_Status_t status; UtPrintf("Testing: CFE_ES_RegisterCDS, CFE_ES_GetCDSBlockIDByName, CFE_ES_GetCDSBlockName"); - UtAssert_INT32_EQ(CFE_ES_RegisterCDS(&CDSHandlePtr, BlockSize, Name), CFE_SUCCESS); - UtAssert_INT32_EQ(CFE_ES_GetCDSBlockIDByName(&IdByName, Name), CFE_SUCCESS); - UtAssert_INT32_EQ(CFE_ES_GetCDSBlockName(CDSNameBuf, IdByName, sizeof(CDSNameBuf)), CFE_SUCCESS); - UtAssert_StrCmp(CDSNameBuf, Name, "CFE_ES_GetCDSBlockName() = %s", CDSNameBuf); + status = CFE_ES_RegisterCDS(&CDSHandlePtr, BlockSize, Name); + + if (status == CFE_ES_CDS_ALREADY_EXISTS) + { + UtAssert_NA("CDS already exists. CFE_ES_RegisterCDS could not be tested"); + } + else + { + UtAssert_INT32_EQ(status, CFE_SUCCESS); + } + + UtAssert_INT32_EQ(CFE_ES_GetCDSBlockName(CDSNameBuf, CDSHandlePtr, sizeof(CDSNameBuf)), CFE_SUCCESS); + UtAssert_StrCmp(CDSNameBuf, CDSName, "CFE_ES_GetCDSBlockName() = %s", CDSNameBuf); + UtAssert_INT32_EQ(CFE_ES_GetCDSBlockIDByName(&IdByName, CDSNameBuf), CFE_SUCCESS); + UtAssert_ResourceID_EQ(CDSHandlePtr, IdByName); } -int32 ESCDSTestSetup(int32 LibId) +void TestCopyRestoreCDS(void) { - UtTest_Add(TestCDS, NULL, NULL, "Test CDS"); + CFE_ES_CDSHandle_t CDSHandlePtr; + size_t BlockSize = 10; + const char * Name = "CDS_Copy_Test"; + CFE_Status_t status; + char Data[BlockSize]; + char DataBuff[BlockSize]; + + UtPrintf("Testing: CFE_ES_CopyToCDS, CFE_ES_RestoreFromCDS"); - return CFE_SUCCESS; + snprintf(Data, BlockSize, "Test Data"); + status = CFE_ES_RegisterCDS(&CDSHandlePtr, BlockSize, Name); + + UtAssert_True(status == CFE_SUCCESS || status == CFE_ES_CDS_ALREADY_EXISTS, "Register CDS status = %d", + (int)status); + UtAssert_INT32_EQ(CFE_ES_CopyToCDS(CDSHandlePtr, Data), CFE_SUCCESS); + UtAssert_INT32_EQ(CFE_ES_RestoreFromCDS(DataBuff, CDSHandlePtr), CFE_SUCCESS); + UtAssert_StrCmp(Data, DataBuff, "RestoreFromCDS = %s", DataBuff); +} + +void ESCDSTestSetup(void) +{ + UtTest_Add(TestCDS, NULL, NULL, "Test CDS"); + UtTest_Add(TestCopyRestoreCDS, NULL, NULL, "Test Copy Restore CDS"); }