|
| 1 | +/************************************************************************* |
| 2 | +** |
| 3 | +** GSC-18128-1, "Core Flight Executive Version 6.7" |
| 4 | +** |
| 5 | +** Copyright (c) 2006-2019 United States Government as represented by |
| 6 | +** the Administrator of the National Aeronautics and Space Administration. |
| 7 | +** All Rights Reserved. |
| 8 | +** |
| 9 | +** Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | +** you may not use this file except in compliance with the License. |
| 11 | +** You may obtain a copy of the License at |
| 12 | +** |
| 13 | +** http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | +** |
| 15 | +** Unless required by applicable law or agreed to in writing, software |
| 16 | +** distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | +** See the License for the specific language governing permissions and |
| 19 | +** limitations under the License. |
| 20 | +** |
| 21 | +** File: es_resource_id_test.c |
| 22 | +** |
| 23 | +** Purpose: |
| 24 | +** Functional test of ES Resource ID APIs |
| 25 | +** |
| 26 | +** Demonstration of how to register and use the UT assert functions. |
| 27 | +** |
| 28 | +*************************************************************************/ |
| 29 | + |
| 30 | +/* |
| 31 | + * Includes |
| 32 | + */ |
| 33 | + |
| 34 | +#include "cfe_test.h" |
| 35 | + |
| 36 | +void TestAppIDToIndex(void) |
| 37 | +{ |
| 38 | + UtPrintf("Testing: CFE_ES_AppID_ToIndex"); |
| 39 | + CFE_ES_AppId_t TestAppId; |
| 40 | + uint32 TestAppIdx; |
| 41 | + uint32 idx; |
| 42 | + UtAssert_INT32_EQ(CFE_ES_GetAppID(&TestAppId), CFE_SUCCESS); |
| 43 | + UtAssert_INT32_EQ(CFE_ES_AppID_ToIndex(TestAppId, &TestAppIdx), CFE_SUCCESS); |
| 44 | + UtAssert_INT32_EQ(CFE_ES_AppID_ToIndex(TestAppId, &idx), CFE_SUCCESS); |
| 45 | + UtAssert_UINT32_EQ(idx, TestAppIdx); |
| 46 | + |
| 47 | + UtAssert_INT32_EQ(CFE_ES_AppID_ToIndex(TestAppId, NULL), CFE_ES_BAD_ARGUMENT); |
| 48 | + UtAssert_INT32_EQ(CFE_ES_AppID_ToIndex(CFE_ES_APPID_UNDEFINED, &TestAppIdx), CFE_ES_ERR_RESOURCEID_NOT_VALID); |
| 49 | +} |
| 50 | + |
| 51 | +void TestLibIDToIndex(void) |
| 52 | +{ |
| 53 | + UtPrintf("Testing: CFE_ES_LibID_ToIndex"); |
| 54 | + const char * LibName = "ASSERT_LIB"; |
| 55 | + CFE_ES_LibId_t LibId; |
| 56 | + uint32 LibIdx; |
| 57 | + uint32 idx; |
| 58 | + UtAssert_INT32_EQ(CFE_ES_GetLibIDByName(&LibId, LibName), CFE_SUCCESS); |
| 59 | + UtAssert_INT32_EQ(CFE_ES_LibID_ToIndex(LibId, &LibIdx), CFE_SUCCESS); |
| 60 | + UtAssert_INT32_EQ(CFE_ES_LibID_ToIndex(LibId, &idx), CFE_SUCCESS); |
| 61 | + UtAssert_UINT32_EQ(idx, LibIdx); |
| 62 | + |
| 63 | + UtAssert_INT32_EQ(CFE_ES_LibID_ToIndex(LibId, NULL), CFE_ES_BAD_ARGUMENT); |
| 64 | + UtAssert_INT32_EQ(CFE_ES_LibID_ToIndex(CFE_ES_LIBID_UNDEFINED, &LibIdx), CFE_ES_ERR_RESOURCEID_NOT_VALID); |
| 65 | +} |
| 66 | + |
| 67 | +void TestTaskIDToIndex(void) |
| 68 | +{ |
| 69 | + UtPrintf("Testing: CFE_ES_TaskID_ToIndex"); |
| 70 | + CFE_ES_TaskId_t TaskId; |
| 71 | + uint32 TaskIdx; |
| 72 | + uint32 idx; |
| 73 | + UtAssert_INT32_EQ(CFE_ES_GetTaskID(&TaskId), CFE_SUCCESS); |
| 74 | + UtAssert_INT32_EQ(CFE_ES_TaskID_ToIndex(TaskId, &TaskIdx), CFE_SUCCESS); |
| 75 | + UtAssert_INT32_EQ(CFE_ES_TaskID_ToIndex(TaskId, &idx), CFE_SUCCESS); |
| 76 | + UtAssert_UINT32_EQ(idx, TaskIdx); |
| 77 | + |
| 78 | + UtAssert_INT32_EQ(CFE_ES_TaskID_ToIndex(TaskId, NULL), CFE_ES_BAD_ARGUMENT); |
| 79 | + UtAssert_INT32_EQ(CFE_ES_TaskID_ToIndex(CFE_ES_TASKID_UNDEFINED, &TaskIdx), CFE_ES_ERR_RESOURCEID_NOT_VALID); |
| 80 | +} |
| 81 | + |
| 82 | +void TestCounterIDToIndex(void) |
| 83 | +{ |
| 84 | + UtPrintf("Testing: CFE_ES_CounterID_ToIndex"); |
| 85 | + const char * CounterName = "TEST_COUNTER"; |
| 86 | + CFE_ES_CounterId_t CounterId; |
| 87 | + uint32 CounterIdx; |
| 88 | + uint32 idx; |
| 89 | + UtAssert_UINT32_EQ(CFE_ES_RegisterGenCounter(&CounterId, CounterName), CFE_SUCCESS); |
| 90 | + UtAssert_INT32_EQ(CFE_ES_CounterID_ToIndex(CounterId, &CounterIdx), CFE_SUCCESS); |
| 91 | + UtAssert_INT32_EQ(CFE_ES_CounterID_ToIndex(CounterId, &idx), CFE_SUCCESS); |
| 92 | + UtAssert_UINT32_EQ(idx, CounterIdx); |
| 93 | + |
| 94 | + UtAssert_INT32_EQ(CFE_ES_CounterID_ToIndex(CounterId, NULL), CFE_ES_BAD_ARGUMENT); |
| 95 | + UtAssert_INT32_EQ(CFE_ES_CounterID_ToIndex(CFE_ES_COUNTERID_UNDEFINED, &CounterIdx), |
| 96 | + CFE_ES_ERR_RESOURCEID_NOT_VALID); |
| 97 | +} |
| 98 | + |
| 99 | +void ESResourceIDTestSetup(void) |
| 100 | +{ |
| 101 | + UtTest_Add(TestAppIDToIndex, NULL, NULL, "Test Obtaining indices from App ID"); |
| 102 | + UtTest_Add(TestLibIDToIndex, NULL, NULL, "Test Obtaining indices from Lib ID"); |
| 103 | + UtTest_Add(TestTaskIDToIndex, NULL, NULL, "Test Obtaining indices from Task ID"); |
| 104 | + UtTest_Add(TestCounterIDToIndex, NULL, NULL, "Test Obtaining indices from Counter ID"); |
| 105 | +} |
0 commit comments