diff options
Diffstat (limited to 'libccnx-transport-rta/ccnx/transport/transport_rta/config/test')
13 files changed, 1714 insertions, 0 deletions
diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/CMakeLists.txt b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/CMakeLists.txt new file mode 100644 index 00000000..235ef4be --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/CMakeLists.txt @@ -0,0 +1,22 @@ +# Enable gcov output for the tests +add_definitions(--coverage) +set(CMAKE_EXE_LINKER_FLAGS ${CMAKE_EXE_LINKER_FLAGS} " --coverage") + +set(TestsExpectedToPass + test_config_ApiConnector + test_config_Codec_Tlv + test_config_FlowControl_Vegas + test_config_Forwarder_Local + test_config_Forwarder_Metis + test_config_InMemoryVerifier + test_config_ProtocolStack + test_config_PublicKeySigner + test_config_Signer + test_config_SymmetricKeySigner + test_config_TestingComponent +) + + +foreach(test ${TestsExpectedToPass}) + AddTest(${test}) +endforeach() diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_ApiConnector.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_ApiConnector.c new file mode 100644 index 00000000..10abcbd8 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_ApiConnector.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_ApiConnector.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_ApiConnector) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_ApiConnector) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_ApiConnector) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, apiConnector_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, apiConnector_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, apiConnector_GetName); + LONGBOW_RUN_TEST_CASE(Global, apiConnector_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, apiConnector_ProtocolStackConfig_ReturnValue); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, apiConnector_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = apiConnector_ConnectionConfig(data->connConfig); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, apiConnector_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(apiConnector_ConnectionConfig(data->connConfig), + apiConnector_GetName()); +} + +LONGBOW_TEST_CASE(Global, apiConnector_GetName) +{ + testRtaConfiguration_ComponentName(apiConnector_GetName, RtaComponentNames[API_CONNECTOR]); +} + +LONGBOW_TEST_CASE(Global, apiConnector_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(apiConnector_ProtocolStackConfig(data->stackConfig), + apiConnector_GetName()); +} + +LONGBOW_TEST_CASE(Global, apiConnector_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = apiConnector_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_ApiConnector); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Codec_Tlv.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Codec_Tlv.c new file mode 100644 index 00000000..d3159bb1 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Codec_Tlv.c @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_Codec_Tlv.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_Codec_Tlv) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_Codec_Tlv) +{ + parcMemory_SetInterface(&PARCSafeMemoryAsPARCMemory); + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_Codec_Tlv) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, Codec_Tlv_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, Codec_Tlv_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, Codec_Tlv_GetName); + LONGBOW_RUN_TEST_CASE(Global, Codec_Tlv_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, Codec_Tlv_ProtocolStackConfig_ReturnValue); + + LONGBOW_RUN_TEST_CASE(Global, tlvCodec_ConnectionConfig); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, Codec_Tlv_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = tlvCodec_ConnectionConfig(data->connConfig); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, Codec_Tlv_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(tlvCodec_ConnectionConfig(data->connConfig), + tlvCodec_GetName()); +} + +LONGBOW_TEST_CASE(Global, Codec_Tlv_GetName) +{ + testRtaConfiguration_ComponentName(tlvCodec_GetName, RtaComponentNames[CODEC_TLV]); +} + +LONGBOW_TEST_CASE(Global, Codec_Tlv_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(tlvCodec_ProtocolStackConfig(data->stackConfig), + tlvCodec_GetName()); +} + +LONGBOW_TEST_CASE(Global, Codec_Tlv_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = tlvCodec_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_CASE(Global, tlvCodec_ConnectionConfig) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(tlvCodec_ConnectionConfig(data->connConfig), + tlvCodec_GetName()); + + PARCJSON *json = ccnxConnectionConfig_GetJson(data->connConfig); + assertNotNull(json, "Expected a non-NULL connectionConfig."); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_Codec_Tlv); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_FlowControl_Vegas.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_FlowControl_Vegas.c new file mode 100644 index 00000000..84e8349d --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_FlowControl_Vegas.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_FlowControl_Vegas.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_FlowControl_Vegas) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_FlowControl_Vegas) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_FlowControl_Vegas) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, FlowControl_Vegas_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, FlowControl_Vegas_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, FlowControl_Vegas_GetName); + LONGBOW_RUN_TEST_CASE(Global, FlowControl_Vegas_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, FlowControl_Vegas_ProtocolStackConfig_ReturnValue); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, FlowControl_Vegas_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = vegasFlowController_ConnectionConfig(data->connConfig); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, FlowControl_Vegas_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(vegasFlowController_ConnectionConfig(data->connConfig), + vegasFlowController_GetName()); +} + +LONGBOW_TEST_CASE(Global, FlowControl_Vegas_GetName) +{ + testRtaConfiguration_ComponentName(vegasFlowController_GetName, RtaComponentNames[FC_VEGAS]); +} + +LONGBOW_TEST_CASE(Global, FlowControl_Vegas_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(vegasFlowController_ProtocolStackConfig(data->stackConfig), + vegasFlowController_GetName()); +} + +LONGBOW_TEST_CASE(Global, FlowControl_Vegas_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = vegasFlowController_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_FlowControl_Vegas); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Forwarder_Local.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Forwarder_Local.c new file mode 100644 index 00000000..39d82172 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Forwarder_Local.c @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_Forwarder_Local.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_Forwarder_Local) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_Forwarder_Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_Forwarder_Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Local_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Local_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Local_GetName); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Local_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Local_ProtocolStackConfig_ReturnValue); + + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Local_GetPath); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, Forwarder_Local_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = localForwarder_ConnectionConfig(data->connConfig, "/path/to/socket"); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Local_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(localForwarder_ConnectionConfig(data->connConfig, "/path/to/socket"), + localForwarder_GetName()); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Local_GetName) +{ + testRtaConfiguration_ComponentName(localForwarder_GetName, RtaComponentNames[FWD_LOCAL]); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Local_GetPath) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + const char *truth = "/path/to/socket"; + localForwarder_ConnectionConfig(data->connConfig, truth); + const char *test = localForwarder_GetPath(ccnxConnectionConfig_GetJson(data->connConfig)); + assertTrue(strcmp(truth, test) == 0, "Got wrong socket path, got %s expected %s", test, truth); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Local_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(localForwarder_ProtocolStackConfig(data->stackConfig), + localForwarder_GetName()); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Local_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = localForwarder_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_Forwarder_Local); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Forwarder_Metis.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Forwarder_Metis.c new file mode 100644 index 00000000..b4c2c8c4 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Forwarder_Metis.c @@ -0,0 +1,154 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_Forwarder_Metis.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_Forwarder_Metis) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Metis); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_Forwarder_Metis) +{ + parcMemory_SetInterface(&PARCSafeMemoryAsPARCMemory); + + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_Forwarder_Metis) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Metis_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Metis_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Metis_GetName); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Metis_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Metis_ProtocolStackConfig_ReturnValue); + + LONGBOW_RUN_TEST_CASE(Global, Forwarder_Metis_GetPath); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, Forwarder_Metis_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = metisForwarder_ConnectionConfig(data->connConfig, 9999); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Metis_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(metisForwarder_ConnectionConfig(data->connConfig, 9999), + metisForwarder_GetName()); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Metis_GetName) +{ + testRtaConfiguration_ComponentName(metisForwarder_GetName, RtaComponentNames[FWD_METIS]); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Metis_GetPath) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + int truth = 9999; + metisForwarder_ConnectionConfig(data->connConfig, truth); + int test = metisForwarder_GetPortFromConfig(ccnxConnectionConfig_GetJson(data->connConfig)); + assertTrue(truth == test, "Got wrong socket path, got %d expected %d", test, truth); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Metis_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(metisForwarder_ProtocolStackConfig(data->stackConfig), + metisForwarder_GetName()); +} + +LONGBOW_TEST_CASE(Global, Forwarder_Metis_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = metisForwarder_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_FIXTURE(Metis) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Metis) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Metis) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_Forwarder_Metis); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_InMemoryVerifier.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_InMemoryVerifier.c new file mode 100644 index 00000000..f4455b48 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_InMemoryVerifier.c @@ -0,0 +1,122 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_InMemoryVerifier.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_InMemoryVerifier) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_InMemoryVerifier) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_InMemoryVerifier) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, InMemoryVerifier_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, InMemoryVerifier_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, InMemoryVerifier_GetName); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, InMemoryVerifier_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = inMemoryVerifier_ConnectionConfig(data->connConfig); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, InMemoryVerifier_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(inMemoryVerifier_ConnectionConfig(data->connConfig), + inMemoryVerifier_GetName()); +} + +LONGBOW_TEST_CASE(Global, InMemoryVerifier_GetName) +{ + testRtaConfiguration_ComponentName(inMemoryVerifier_GetName, "InMemoryVerifier"); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_InMemoryVerifier); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_ProtocolStack.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_ProtocolStack.c new file mode 100644 index 00000000..d784b2be --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_ProtocolStack.c @@ -0,0 +1,167 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_ProtocolStack.c" +#include <LongBow/unit-test.h> + +#include <parc/algol/parc_SafeMemory.h> +#include "testrig_RtaConfigCommon.c" + +#include <ccnx/transport/common/ccnx_TransportConfig.h> + +LONGBOW_TEST_RUNNER(config_ProtocolStack) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_ProtocolStack) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_ProtocolStack) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, protocolStack_ComponentsConfigArgs); + LONGBOW_RUN_TEST_CASE(Global, protocolStack_ComponentsConfigArrayList); + LONGBOW_RUN_TEST_CASE(Global, protocolStack_GetComponentNameArray); + LONGBOW_RUN_TEST_CASE(Global, protocolStack_GetName); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, protocolStack_ComponentsConfigArgs) +{ + CCNxStackConfig *stackConfig = ccnxStackConfig_Create(); + + const char truth[] = "{\"STACK\":{\"COMPONENTS\":[\"Apple\",\"Bananna\",\"Cherry\"]}}"; + + protocolStack_ComponentsConfigArgs(stackConfig, "Apple", "Bananna", "Cherry", NULL); + PARCJSON *json = ccnxStackConfig_GetJson(stackConfig); + char *str = parcJSON_ToCompactString(json); + assertTrue(strcmp(truth, str) == 0, "Got wrong config, got %s expected %s", str, truth); + parcMemory_Deallocate((void **) &str); + ccnxStackConfig_Release(&stackConfig); +} + +LONGBOW_TEST_CASE(Global, protocolStack_ComponentsConfigArrayList) +{ + CCNxStackConfig *stackConfig = ccnxStackConfig_Create(); + PARCArrayList *names = parcArrayList_Create(NULL); + parcArrayList_Add(names, "Apple"); + parcArrayList_Add(names, "Bananna"); + parcArrayList_Add(names, "Cherry"); + + const char truth[] = "{\"STACK\":{\"COMPONENTS\":[\"Apple\",\"Bananna\",\"Cherry\"]}}"; + + protocolStack_ComponentsConfigArrayList(stackConfig, names); + PARCJSON *json = ccnxStackConfig_GetJson(stackConfig); + char *str = parcJSON_ToCompactString(json); + assertTrue(strcmp(truth, str) == 0, "Got wrong config, got %s expected %s", str, truth); + + parcMemory_Deallocate((void **) &str); + ccnxStackConfig_Release(&stackConfig); + parcArrayList_Destroy(&names); +} + +LONGBOW_TEST_CASE(Global, protocolStack_GetComponentNameArray) +{ + CCNxStackConfig *stackConfig = ccnxStackConfig_Create(); + PARCArrayList *names = parcArrayList_Create(NULL); + parcArrayList_Add(names, "Apple"); + parcArrayList_Add(names, "Bananna"); + parcArrayList_Add(names, "Cherry"); + + protocolStack_ComponentsConfigArrayList(stackConfig, names); + + char truth[] = "{\"STACK\":{\"COMPONENTS\":[\"Apple\",\"Bananna\",\"Cherry\"]}}"; + PARCJSON *json = parcJSON_ParseString(truth); + + PARCArrayList *test = protocolStack_GetComponentNameArray(json); + + assertTrue(parcArrayList_Size(test) == parcArrayList_Size(names), + "wrong array list size, got %zu expected %zu", + parcArrayList_Size(test), parcArrayList_Size(names)); + for (int i = 0; i < parcArrayList_Size(test); i++) { + char *a = parcArrayList_Get(test, i); + char *b = parcArrayList_Get(names, i); + assertTrue(strcmp(a, b) == 0, "mismatch elements %d, got %s expected %s", i, a, b); + } + + ccnxStackConfig_Release(&stackConfig); + parcArrayList_Destroy(&names); + parcJSON_Release(&json); + parcArrayList_Destroy(&test); +} + +LONGBOW_TEST_CASE(Global, protocolStack_GetName) +{ + const char *name = protocolStack_GetName(); + assertTrue(strcmp(name, param_STACK) == 0, "Got wrong name, got %s expected %s", name, param_STACK); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_ProtocolStack); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_PublicKeySigner.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_PublicKeySigner.c new file mode 100644 index 00000000..325d4b86 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_PublicKeySigner.c @@ -0,0 +1,133 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_PublicKeySigner.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> +#include "testrig_RtaConfigCommon.c" +#include <ccnx/transport/transport_rta/config/config_Signer.h> + +LONGBOW_TEST_RUNNER(config_PublicKeySignerPkcs12Store) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_PublicKeySignerPkcs12Store) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_PublicKeySignerPkcs12Store) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, publicKeySignerPkcs12Store_ConnectionConfig); + LONGBOW_RUN_TEST_CASE(Global, publicKeySignerPkcs12Store_GetConnectionParams); + LONGBOW_RUN_TEST_CASE(Global, publicKeySignerPkcs12Store_GetName); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, publicKeySignerPkcs12Store_ConnectionConfig) +{ + CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + const char *filename = "filename"; + const char *password = "password"; + publicKeySigner_ConnectionConfig(connConfig, filename, password); + + // make sure our stuff is in there + testRtaConfiguration_ConnectionJsonKey(connConfig, publicKeySigner_GetName()); + + // make sure the SIGNER parameter is in there + testRtaConfiguration_ConnectionJsonKey(connConfig, signer_GetName()); + + ccnxConnectionConfig_Destroy(&connConfig); +} + +LONGBOW_TEST_CASE(Global, publicKeySignerPkcs12Store_GetConnectionParams) +{ + CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + const char *filename = "filename"; + const char *password = "password"; + publicKeySigner_ConnectionConfig(connConfig, filename, password); + + PARCJSON *json = ccnxConnectionConfig_GetJson(connConfig); + struct publickeysigner_params params; + + publicKeySigner_GetConnectionParams(json, ¶ms); + + assertTrue(strncmp(params.filename, filename, strlen(filename)) == 0, "wrong filename, got %s expected %s", params.filename, filename); + assertTrue(strncmp(params.password, password, strlen(password)) == 0, "wrong password, got %s expected %s", params.password, password); + + ccnxConnectionConfig_Destroy(&connConfig); +} + +LONGBOW_TEST_CASE(Global, publicKeySignerPkcs12Store_GetName) +{ + testRtaConfiguration_ComponentName(&publicKeySigner_GetName, name); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_PublicKeySignerPkcs12Store); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Signer.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Signer.c new file mode 100644 index 00000000..cf8f3e98 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_Signer.c @@ -0,0 +1,141 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_Signer.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_Signer) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_Signer) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_Signer) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, signer_GetImplementationType_PublicKey); + LONGBOW_RUN_TEST_CASE(Global, signer_GetImplementationType_SymmetricKey); + LONGBOW_RUN_TEST_CASE(Global, signer_GetImplementationType_Unknown); + LONGBOW_RUN_TEST_CASE(Global, signer_GetName); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, signer_GetImplementationType_PublicKey) +{ + CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + const char *filename = "filename"; + const char *password = "password"; + publicKeySigner_ConnectionConfig(connConfig, filename, password); + + PARCJSON *json = ccnxConnectionConfig_GetJson(connConfig); + + SignerType type = signer_GetImplementationType(json); + assertTrue(type == SignerType_PublicKeySigner, "Got wrong signer type, got %d expected %d", type, SignerType_PublicKeySigner); + + ccnxConnectionConfig_Destroy(&connConfig); +} + +LONGBOW_TEST_CASE(Global, signer_GetImplementationType_SymmetricKey) +{ + CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + const char *filename = "filename"; + const char *password = "password"; + symmetricKeySigner_ConnectionConfig(connConfig, filename, password); + + PARCJSON *json = ccnxConnectionConfig_GetJson(connConfig); + + SignerType type = signer_GetImplementationType(json); + assertTrue(type == SignerType_SymmetricKeySigner, "Got wrong signer type, got %d expected %d", type, SignerType_SymmetricKeySigner); + + ccnxConnectionConfig_Destroy(&connConfig); +} + +LONGBOW_TEST_CASE(Global, signer_GetImplementationType_Unknown) +{ + char *bogusSignerString = "{\"SIGNER\":\"BogusSigner\",\"BogusSigner\":{}}"; + + PARCJSON *json = parcJSON_ParseString(bogusSignerString); + + SignerType type = signer_GetImplementationType(json); + assertTrue(type == SignerType_Unknown, "Got wrong signer type, got %d expected %d", type, SignerType_Unknown); + + parcJSON_Release(&json); +} + +LONGBOW_TEST_CASE(Global, signer_GetName) +{ + testRtaConfiguration_ComponentName(&signer_GetName, param_SIGNER); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_Signer); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_SymmetricKeySigner.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_SymmetricKeySigner.c new file mode 100644 index 00000000..4d6244e1 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_SymmetricKeySigner.c @@ -0,0 +1,135 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_SymmetricKeySigner.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> +#include "testrig_RtaConfigCommon.c" +#include <ccnx/transport/transport_rta/config/config_Signer.h> + +LONGBOW_TEST_RUNNER(config_SymmetricKeySignerFileStore) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_SymmetricKeySignerFileStore) +{ + parcMemory_SetInterface(&PARCSafeMemoryAsPARCMemory); + + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_SymmetricKeySignerFileStore) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, symmetricKeySignerFileStore_ConnectionConfig); + LONGBOW_RUN_TEST_CASE(Global, symmetricKeySignerFileStore_GetConnectionParams); + LONGBOW_RUN_TEST_CASE(Global, symmetricKeySignerFileStore_GetName); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, symmetricKeySignerFileStore_ConnectionConfig) +{ + CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + const char *filename = "filename"; + const char *password = "password"; + symmetricKeySigner_ConnectionConfig(connConfig, filename, password); + + // make sure our stuff is in there + testRtaConfiguration_ConnectionJsonKey(connConfig, symmetricKeySigner_GetName()); + + // make sure the SIGNER parameter is in there + testRtaConfiguration_ConnectionJsonKey(connConfig, signer_GetName()); + + ccnxConnectionConfig_Destroy(&connConfig); +} + +LONGBOW_TEST_CASE(Global, symmetricKeySignerFileStore_GetConnectionParams) +{ + CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); + const char *filename = "filename"; + const char *password = "password"; + symmetricKeySigner_ConnectionConfig(connConfig, filename, password); + + PARCJSON *json = ccnxConnectionConfig_GetJson(connConfig); + struct symmetrickeysigner_params params; + + symmetricKeySigner_GetConnectionParams(json, ¶ms); + + assertTrue(strncmp(params.filename, filename, strlen(filename)) == 0, "wrong filename, got %s expected %s", params.filename, filename); + assertTrue(strncmp(params.password, password, strlen(password)) == 0, "wrong password, got %s expected %s", params.password, password); + + ccnxConnectionConfig_Destroy(&connConfig); +} + +LONGBOW_TEST_CASE(Global, symmetricKeySignerFileStore_GetName) +{ + testRtaConfiguration_ComponentName(&symmetricKeySigner_GetName, name); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_SymmetricKeySignerFileStore); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_TestingComponent.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_TestingComponent.c new file mode 100644 index 00000000..ac8ba52e --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/test_config_TestingComponent.c @@ -0,0 +1,186 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Rta component configuration class unit test + * + */ + +// Include the file(s) containing the functions to be tested. +// This permits internal static functions to be visible to this Test Framework. +#include "../config_TestingComponent.c" +#include <parc/algol/parc_SafeMemory.h> +#include <LongBow/unit-test.h> + +#include "testrig_RtaConfigCommon.c" + +LONGBOW_TEST_RUNNER(config_TestingComponent) +{ + // The following Test Fixtures will run their corresponding Test Cases. + // Test Fixtures are run in the order specified, but all tests should be idempotent. + // Never rely on the execution order of tests or share state between them. + LONGBOW_RUN_TEST_FIXTURE(Global); + LONGBOW_RUN_TEST_FIXTURE(Local); +} + +// The Test Runner calls this function once before any Test Fixtures are run. +LONGBOW_TEST_RUNNER_SETUP(config_TestingComponent) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +// The Test Runner calls this function once after all the Test Fixtures are run. +LONGBOW_TEST_RUNNER_TEARDOWN(config_TestingComponent) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE(Global) +{ + LONGBOW_RUN_TEST_CASE(Global, testingUpper_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, testingUpper_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, testingUpper_GetName); + LONGBOW_RUN_TEST_CASE(Global, testingUpper_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, testingUpper_ProtocolStackConfig_ReturnValue); + + LONGBOW_RUN_TEST_CASE(Global, testingLower_ConnectionConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, testingLower_ConnectionConfig_ReturnValue); + LONGBOW_RUN_TEST_CASE(Global, testingLower_GetName); + LONGBOW_RUN_TEST_CASE(Global, testingLower_ProtocolStackConfig_JsonKey); + LONGBOW_RUN_TEST_CASE(Global, testingLower_ProtocolStackConfig_ReturnValue); +} + +LONGBOW_TEST_FIXTURE_SETUP(Global) +{ + longBowTestCase_SetClipBoardData(testCase, testRtaConfiguration_CommonSetup()); + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Global) +{ + testRtaConfiguration_CommonTeardown(longBowTestCase_GetClipBoardData(testCase)); + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_CASE(Global, testingUpper_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = testingUpper_ConnectionConfig(data->connConfig); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, testingUpper_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(testingUpper_ConnectionConfig(data->connConfig), + testingUpper_GetName()); +} + +LONGBOW_TEST_CASE(Global, testingUpper_GetName) +{ + testRtaConfiguration_ComponentName(testingUpper_GetName, RtaComponentNames[TESTING_UPPER]); +} + +LONGBOW_TEST_CASE(Global, testingUpper_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(testingUpper_ProtocolStackConfig(data->stackConfig), + testingUpper_GetName()); +} + +LONGBOW_TEST_CASE(Global, testingUpper_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = testingUpper_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_CASE(Global, testingLower_ConnectionConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxConnectionConfig *test = testingLower_ConnectionConfig(data->connConfig); + + assertTrue(test == data->connConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->connConfig); +} + +LONGBOW_TEST_CASE(Global, testingLower_ConnectionConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ConnectionJsonKey(testingUpper_ConnectionConfig(data->connConfig), + testingUpper_GetName()); +} + +LONGBOW_TEST_CASE(Global, testingLower_GetName) +{ + testRtaConfiguration_ComponentName(testingLower_GetName, RtaComponentNames[TESTING_LOWER]); +} + +LONGBOW_TEST_CASE(Global, testingLower_ProtocolStackConfig_JsonKey) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + testRtaConfiguration_ProtocolStackJsonKey(testingLower_ProtocolStackConfig(data->stackConfig), + testingLower_GetName()); +} + +LONGBOW_TEST_CASE(Global, testingLower_ProtocolStackConfig_ReturnValue) +{ + TestData *data = longBowTestCase_GetClipBoardData(testCase); + CCNxStackConfig *test = testingLower_ProtocolStackConfig(data->stackConfig); + + assertTrue(test == data->stackConfig, + "Did not return pointer to argument for chaining, got %p expected %p", + (void *) test, (void *) data->stackConfig); +} + +LONGBOW_TEST_FIXTURE(Local) +{ +} + +LONGBOW_TEST_FIXTURE_SETUP(Local) +{ + return LONGBOW_STATUS_SUCCEEDED; +} + +LONGBOW_TEST_FIXTURE_TEARDOWN(Local) +{ + uint32_t outstandingAllocations = parcSafeMemory_ReportAllocation(STDERR_FILENO); + if (outstandingAllocations != 0) { + printf("%s leaks memory by %d allocations\n", longBowTestCase_GetName(testCase), outstandingAllocations); + return LONGBOW_STATUS_MEMORYLEAK; + } + return LONGBOW_STATUS_SUCCEEDED; +} + +int +main(int argc, char *argv[]) +{ + LongBowRunner *testRunner = LONGBOW_TEST_RUNNER_CREATE(config_TestingComponent); + int exitStatus = longBowMain(argc, argv, testRunner, NULL); + longBowTestRunner_Destroy(&testRunner); + exit(exitStatus); +} diff --git a/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/testrig_RtaConfigCommon.c b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/testrig_RtaConfigCommon.c new file mode 100644 index 00000000..29f2da24 --- /dev/null +++ b/libccnx-transport-rta/ccnx/transport/transport_rta/config/test/testrig_RtaConfigCommon.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2017 Cisco and/or its affiliates. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Common test routines for the RTA component configuration functions + * + */ + +typedef struct test_data { + CCNxConnectionConfig *connConfig; + CCNxStackConfig *stackConfig; +} TestData; + +TestData * +testRtaConfiguration_CommonSetup(void) +{ + TestData *data = parcMemory_AllocateAndClear(sizeof(TestData)); + assertNotNull(data, "parcMemory_AllocateAndClear(%zu) returned NULL", sizeof(TestData)); + data->connConfig = ccnxConnectionConfig_Create(); + data->stackConfig = ccnxStackConfig_Create(); + return data; +} + +void +testRtaConfiguration_CommonTeardown(TestData *data) +{ + ccnxStackConfig_Release(&data->stackConfig); + ccnxConnectionConfig_Destroy(&data->connConfig); + parcMemory_Deallocate((void **) &data); +} + +void +testRtaConfiguration_ComponentName(const char * (*getname)(void), const char *truth) +{ + const char *name = getname(); + assertTrue(strcmp(name, truth) == 0, + "Got wrong name, got %s expected %s", name, truth); +} + +void +testRtaConfiguration_ConnectionJsonKey(CCNxConnectionConfig *configToTest, const char *key) +{ + PARCJSON *json = ccnxConnectionConfig_GetJson(configToTest); + PARCJSONValue *value = parcJSON_GetValueByName(json, key); + assertNotNull(value, "Could not find key %s in configuration json", key); +} + +void +testRtaConfiguration_ProtocolStackJsonKey(CCNxStackConfig *configToTest, const char *key) +{ + PARCJSON *json = ccnxStackConfig_GetJson(configToTest); + PARCJSONValue *value = parcJSON_GetValueByName(json, key); + assertNotNull(value, "Could not find key %s in configuration json", key); +} |