LONGBOW_TEST_CASE(Global, PARC_TreeRedBlack_Values) { PARCTreeRedBlack *tree1; PARCArrayList *list; tree1 = parcTreeRedBlack_Create(pointerComp, NULL, NULL, NULL, NULL, NULL); list = parcArrayList_Create(NULL); // Insert in tree out of order for (long i = 10; i < 20; i++) { // Add some elements to the tree parcTreeRedBlack_Insert(tree1, (void *) i, (void *) (i << 8)); } for (long i = 1; i < 10; i++) { // Add some elements to the tree parcTreeRedBlack_Insert(tree1, (void *) i, (void *) (i << 8)); } // Insert in list in order for (long i = 1; i < 20; i++) { // Add some elements to the tree parcArrayList_Add(list, (void *) (i << 8)); } PARCArrayList *values = parcTreeRedBlack_Values(tree1); assertTrue(parcArrayList_Equals(list, values), "Key list doesnt' match"); parcArrayList_Destroy(&values); parcArrayList_Destroy(&list); parcTreeRedBlack_Destroy(&tree1); }
void athenaTransportLinkAdapter_Destroy(AthenaTransportLinkAdapter **athenaTransportLinkAdapter) { // release listener instances if ((*athenaTransportLinkAdapter)->listenerList) { for (int index = 0; index < parcArrayList_Size((*athenaTransportLinkAdapter)->listenerList); index++) { AthenaTransportLink *athenaTransportLink = parcArrayList_Get((*athenaTransportLinkAdapter)->listenerList, index); athenaTransportLink_Close(athenaTransportLink); } } // release live instances if ((*athenaTransportLinkAdapter)->instanceList) { for (int index = 0; index < parcArrayList_Size((*athenaTransportLinkAdapter)->instanceList); index++) { AthenaTransportLink *athenaTransportLink = parcArrayList_Get((*athenaTransportLinkAdapter)->instanceList, index); if (athenaTransportLink) { athenaTransportLink_Close(athenaTransportLink); } } } parcArrayList_Destroy(&((*athenaTransportLinkAdapter)->moduleList)); parcArrayList_Destroy(&((*athenaTransportLinkAdapter)->instanceList)); parcArrayList_Destroy(&((*athenaTransportLinkAdapter)->listenerList)); if ((*athenaTransportLinkAdapter)->pollfdReceiveList) { parcMemory_Deallocate(&((*athenaTransportLinkAdapter)->pollfdReceiveList)); parcMemory_Deallocate(&((*athenaTransportLinkAdapter)->pollfdSendList)); parcMemory_Deallocate(&((*athenaTransportLinkAdapter)->pollfdTransportLink)); } parcLog_Release(&((*athenaTransportLinkAdapter)->log)); parcMemory_Deallocate(athenaTransportLinkAdapter); }
LONGBOW_TEST_CASE(Global, PARCList_Equals_Empty) { PARCArrayList *a = parcArrayList_Create(parcArrayList_StdlibFreeFunction); PARCArrayList *b = parcArrayList_Create(parcArrayList_StdlibFreeFunction); assertTrue(parcArrayList_Equals(a, b), "Equal values were expected to be equal"); parcArrayList_Destroy(&a); parcArrayList_Destroy(&b); }
static MetisNumberSet * _metisStandardPIT_SatisfyInterest(MetisPIT *generic, const MetisMessage *objectMessage) { assertNotNull(generic, "Parameter pit must be non-null"); assertNotNull(objectMessage, "Parameter objectMessage must be non-null"); MetisStandardPIT *pit = metisPIT_Closure(generic); // we need to look in all three tables to see if there's anything // to satisy in each of them and take the union of the reverse path sets. MetisNumberSet *ingressSetUnion = metisNumberSet_Create(); PARCArrayList *list = metisMatchingRulesTable_GetUnion(pit->table, objectMessage); for (size_t i = 0; i < parcArrayList_Size(list); i++) { MetisPitEntry *pitEntry = (MetisPitEntry *) parcArrayList_Get(list, i); // this is a reference counted return const MetisNumberSet *ingressSet = metisPitEntry_GetIngressSet(pitEntry); metisNumberSet_AddSet(ingressSetUnion, ingressSet); // and remove it from the PIT. Key is a reference counted copy of the pit entry message MetisMessage *key = metisPitEntry_GetMessage(pitEntry); metisMatchingRulesTable_RemoveFromBest(pit->table, key); metisMessage_Release(&key); } parcArrayList_Destroy(&list); return ingressSetUnion; }
LONGBOW_TEST_CASE(Global, PARCList_Equals_Same) { PARCArrayList *a = parcArrayList_Create(parcArrayList_StdlibFreeFunction); assertTrue(parcArrayList_Equals(a, a), "Expected the same array list to be equal to itself."); parcArrayList_Destroy(&a); }
static AthenaTransportLinkModule * _LoadModule(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, const char *moduleName) { PARCArrayList *newModuleList = NULL; // XXX need to dynamically load these, they're all hardwired for now if (strcasecmp(moduleName, "TCP") == 0) { newModuleList = athenaTransportLinkModuleTCP_Init(); } if (strcasecmp(moduleName, "UDP") == 0) { newModuleList = athenaTransportLinkModuleUDP_Init(); } if (strcasecmp(moduleName, "ETH") == 0) { newModuleList = athenaTransportLinkModuleETH_Init(); } if (newModuleList) { for (int index = 0; index < parcArrayList_Size(newModuleList); index++) { AthenaTransportLinkModule *athenaTransportLinkModule = parcArrayList_Get(newModuleList, index); _AddModule(athenaTransportLinkAdapter, athenaTransportLinkModule); } parcArrayList_Destroy(&newModuleList); } return _LookupModule(athenaTransportLinkAdapter, moduleName); }
LONGBOW_TEST_CASE(Global, PARCList_InsertAtIndex_Last) { PARCArrayList *array = parcArrayList_Create(NULL); parcArrayList_Add(array, (void *) 1); parcArrayList_Add(array, (void *) 2); size_t actual = parcArrayList_Size(array); assertTrue(2 == actual, "Expected=%d, actual=%zu", 2, actual); parcArrayList_InsertAtIndex(array, 2, (void *) 3); actual = parcArrayList_Size(array); assertTrue(3 == actual, "Expected=%d, actual=%zu", 3, actual); void *element0 = parcArrayList_Get(array, 0); assertTrue(element0 == (void *) 1, "Element 1 moved?"); void *element1 = parcArrayList_Get(array, 1); assertTrue(element1 == (void *) 2, "Element 1 moved?"); void *element2 = parcArrayList_Get(array, 2); assertTrue(element2 == (void *) 3, "Element 1 moved?"); parcArrayList_Destroy(&array); }
LONGBOW_TEST_CASE(Global, PARCList_New) { PARCArrayList *array = parcArrayList_Create(parcArrayList_StdlibFreeFunction); size_t size = parcArrayList_Size(array); assertTrue(0 == size, "Expected %d actual=%zd", 0, size); parcArrayList_Destroy(&array); }
/** * This composes a CCNxTransportConfig instance that describes a complete transport stack assembly. */ static const CCNxTransportConfig * _createTransportConfig(const CCNxPortalFactory *factory, _CCNxPortalType type, _CCNxPortalProtocol protocol) { if (type == ccnxPortalTypeChunked) { // Good. } else if (type == ccnxPortalTypeMessage) { // Good. } else { return NULL; } // TODO: This is in need of some narrative of what's going on here. CCNxConnectionConfig *connConfig = ccnxConnectionConfig_Create(); CCNxStackConfig *stackConfig = ccnxStackConfig_Create(); PARCArrayList *listOfComponentNames = parcArrayList_Create_Capacity(NULL, NULL, 8); parcArrayList_Add(listOfComponentNames, (char *) apiConnector_GetName()); apiConnector_ProtocolStackConfig(stackConfig); apiConnector_ConnectionConfig(connConfig); if (type == ccnxPortalTypeChunked) { parcArrayList_Add(listOfComponentNames, (char *) vegasFlowController_GetName()); vegasFlowController_ProtocolStackConfig(stackConfig); vegasFlowController_ConnectionConfig(connConfig); } switch (protocol) { case CCNxPortalProtocol_RTALoopback: _ccnxPortalProtocol_RTALoopback(connConfig, stackConfig, listOfComponentNames); break; case ccnxPortalProtocol_RTA: _ccnxPortalProtocol_RTAMetis(connConfig, stackConfig, listOfComponentNames); break; default: errno = EPROTOTYPE; assertTrue(0, "Unknown protocol type: %d", protocol); } protocolStack_ComponentsConfigArrayList(stackConfig, listOfComponentNames); parcArrayList_Destroy(&listOfComponentNames); const PARCIdentity *identity = ccnxPortalFactory_GetIdentity(factory); configPublicKeySigner_SetIdentity(connConfig, identity); CCNxTransportConfig *result = ccnxTransportConfig_Create(stackConfig, connConfig); ccnxStackConfig_Release(&stackConfig); return result; }
LONGBOW_TEST_CASE(Global, PARCList_Length) { PARCArrayList *array = parcArrayList_Create(NULL); parcArrayList_Add(array, 0); size_t size = parcArrayList_Size(array); assertTrue(1 == size, "Expected %d actual=%zd", 1, size); parcArrayList_Destroy(&array); }
LONGBOW_TEST_CASE(Global, PARCList_FromInitialCapacity) { PARCArrayList *array = parcArrayList_Create_Capacity(NULL, parcArrayList_StdlibFreeFunction, 10); size_t actual = parcArrayList_Size(array); assertTrue(0 == actual, "Expected=%d, actual=%zu", 0, actual); parcArrayList_Destroy(&array); }
static void _parcURIPath_Finalize(PARCURIPath **pathPtr) { assertNotNull(pathPtr, "Parameter must be a non-null pointer to a pointer to a PARCURIPath instance."); PARCURIPath *path = *pathPtr; if (path != NULL) { parcArrayList_Destroy(&path->segments); } }
void cpiConnectionList_Destroy(CPIConnectionList **listPtr) { assertNotNull(listPtr, "Parameter must be non-null double pointer"); assertNotNull(*listPtr, "Parameter must dereference to non-null pointer"); CPIConnectionList *list = *listPtr; parcArrayList_Destroy(&list->listOfConnections); parcMemory_Deallocate((void **) &list); *listPtr = NULL; }
LONGBOW_TEST_CASE(Global, PARCList_IsEmpty) { PARCArrayList *array = parcArrayList_Create(NULL); assertTrue(parcArrayList_IsEmpty(array), "Expected a new array to be empty."); parcArrayList_Add(array, 0); assertFalse(parcArrayList_IsEmpty(array), "Expected an array with more than zero elements to be empty."); parcArrayList_Destroy(&array); }
void metisListenerSet_Destroy(MetisListenerSet **setPtr) { assertNotNull(setPtr, "Parameter must be non-null double pointer"); assertNotNull(*setPtr, "Parameter must dereference to non-null pointer"); MetisListenerSet *set = *setPtr; parcArrayList_Destroy(&set->listOfListeners); parcMemory_Deallocate((void **) &set); *setPtr = NULL; }
void cpiInterfaceSet_Destroy(CPIInterfaceSet **setPtr) { assertNotNull(setPtr, "Parameter must be non-null double pointer"); assertNotNull(*setPtr, "Parameter must dereference to non-null pointer"); CPIInterfaceSet *set = *setPtr; parcArrayList_Destroy(&set->listOfInterfaces); parcMemory_Deallocate((void **) &set); *setPtr = NULL; }
LONGBOW_TEST_CASE(Global, PARCList_InsertAtIndex_Empty) { PARCArrayList *array = parcArrayList_Create(NULL); parcArrayList_InsertAtIndex(array, 0, (void *) 3); size_t actual = parcArrayList_Size(array); assertTrue(1 == actual, "Expected=%d, actual=%zu", 1, actual); parcArrayList_Destroy(&array); }
LONGBOW_TEST_CASE(Global, PARCList_Get) { PARCArrayList *array = parcArrayList_Create(parcArrayList_StdlibFreeFunction); char *expected = strdup("Hello World"); parcArrayList_Add(array, expected); char *actual = parcArrayList_Get(array, 0); assertTrue(expected == actual, "Expected=%p, actual=%p", (void *) expected, (void *) actual); parcArrayList_Destroy(&array); }
LONGBOW_TEST_CASE(Global, PARCList_RemoveAndDestroy_AtIndex_Last) { char a[] = "apple"; char b[] = "bananna"; char c[] = "cherry"; PARCArrayList *array = parcArrayList_Create(NULL); parcArrayList_Add(array, a); parcArrayList_Add(array, b); parcArrayList_Add(array, c); PARCArrayList *expected = parcArrayList_Create(NULL); parcArrayList_Add(expected, a); parcArrayList_Add(expected, b); parcArrayList_RemoveAndDestroyAtIndex(array, 2); assertTrue(parcArrayList_Equals(expected, array), "Expected "); parcArrayList_Destroy(&expected); parcArrayList_Destroy(&array); }
LONGBOW_TEST_CASE(Global, PARCList_Remove_AtIndex) { char a[] = "apple"; char b[] = "bananna"; char c[] = "cherry"; PARCArrayList *array = parcArrayList_Create(NULL); parcArrayList_Add(array, a); parcArrayList_Add(array, b); parcArrayList_Add(array, c); PARCArrayList *expected = parcArrayList_Create(NULL); parcArrayList_Add(expected, a); parcArrayList_Add(expected, c); void *removedElement = parcArrayList_RemoveAtIndex(array, 1); assertTrue(removedElement == b, "Expected "); assertTrue(parcArrayList_Equals(expected, array), "Expected "); parcArrayList_Destroy(&expected); parcArrayList_Destroy(&array); }
void athenaTransportLinkModule_Destroy(AthenaTransportLinkModule **athenaTransportLinkModule) { int index = (int) parcArrayList_Size((*athenaTransportLinkModule)->instanceList); while (index-- > 0) { AthenaTransportLink *transportLink; transportLink = parcArrayList_Get((*athenaTransportLinkModule)->instanceList, 0); athenaTransportLink_Close(transportLink); } parcArrayList_Destroy(&((*athenaTransportLinkModule)->instanceList)); parcMemory_Deallocate(&((*athenaTransportLinkModule)->name)); parcLog_Release(&((*athenaTransportLinkModule)->log)); parcMemory_Deallocate(athenaTransportLinkModule); }
void metisCommandLineInterface_Destroy(MetisCommandLineInterface **cliPtr) { assertNotNull(cliPtr, "Parameter must be non-null double pointer"); assertNotNull(*cliPtr, "Parameter must dereference to non-null pointer"); MetisCommandLineInterface *cli = *cliPtr; parcArrayList_Destroy(&cli->openSessions); if (cli->listener) { MetisDispatcher *dispatcher = metisForwarder_GetDispatcher(cli->metis); metisDispatcher_DestroyListener(dispatcher, &(cli->listener)); } parcMemory_Deallocate((void **) &cli); *cliPtr = NULL; }
LONGBOW_TEST_CASE(Global, PARCList_Equals_Contract_Deep) { char a[] = "apple"; char b[] = "bananna"; char c[] = "cherry"; char d[] = "potato"; PARCArrayList *x = parcArrayList_Create_Capacity(stringEquals, NULL, 0); parcArrayList_Add(x, a); parcArrayList_Add(x, b); parcArrayList_Add(x, c); PARCArrayList *y = parcArrayList_Create_Capacity(stringEquals, NULL, 0); parcArrayList_Add(y, a); parcArrayList_Add(y, b); parcArrayList_Add(y, c); PARCArrayList *z = parcArrayList_Create_Capacity(stringEquals, NULL, 0); parcArrayList_Add(z, a); parcArrayList_Add(z, b); parcArrayList_Add(z, c); PARCArrayList *u1 = parcArrayList_Create_Capacity(stringEquals, NULL, 0); parcArrayList_Add(u1, a); parcArrayList_Add(u1, b); PARCArrayList *u2 = parcArrayList_Create_Capacity(stringEquals, NULL, 0); parcArrayList_Add(u2, a); parcArrayList_Add(u2, b); parcArrayList_Add(u2, c); parcArrayList_Add(u2, c); PARCArrayList *u3 = parcArrayList_Create_Capacity(stringEquals, NULL, 0); parcArrayList_Add(u3, a); parcArrayList_Add(u3, b); parcArrayList_Add(u3, d); parcObjectTesting_AssertEqualsFunction(parcArrayList_Equals, x, y, z, u1, u2, u3); parcArrayList_Destroy(&x); parcArrayList_Destroy(&y); parcArrayList_Destroy(&z); parcArrayList_Destroy(&u1); parcArrayList_Destroy(&u2); parcArrayList_Destroy(&u3); }
/** * Calls the confguration routine for each component in the stack * * Builds an array list of everything in the JSON configuration, then * calls its configuation routine. * * The connecting event queues are disabled at this point. * * @param [in,out] stack The Protocol Stack to operate on * * Example: * @code * <#example#> * @endcode */ static void rtaProtocolStack_ConfigureComponents(RtaProtocolStack *stack) { PARCArrayList *componentNameList; componentNameList = protocolStack_GetComponentNameArray(stack->params); assertTrue(parcArrayList_Size(componentNameList) < MAX_STACK_DEPTH, "Too many components in a stack size %zu\n", parcArrayList_Size(componentNameList)); for (int i = 0; i < parcArrayList_Size(componentNameList); i++) { // match it to a component type const char *comp_name = parcArrayList_Get(componentNameList, i); RtaComponents comp_type = getComponentTypeFromName(comp_name); // this could be sped up slightly by putting the ops structures // in an array switch (comp_type) { case API_CONNECTOR: configure_ApiConnector(stack, comp_type, api_ops); break; case FC_NONE: trapIllegalValue(comp_type, "Null flowcontroller no longer supported"); break; case FC_VEGAS: configure_Component(stack, comp_type, flow_vegas_ops); break; case FC_PIPELINE: abort(); break; case CODEC_NONE: trapIllegalValue(comp_type, "Null codec no longer supported"); break; case CODEC_TLV: configure_Component(stack, comp_type, codec_tlv_ops); break; case FWD_NONE: abort(); break; case FWD_LOCAL: configure_FwdConnector(stack, comp_type, fwd_local_ops); break; case FWD_METIS: configure_FwdConnector(stack, comp_type, fwd_metis_ops); break; case TESTING_UPPER: // fallthrough case TESTING_LOWER: configure_Component(stack, comp_type, testing_null_ops); break; default: fprintf(stderr, "%s unsupported component type %s\n", __func__, comp_name); abort(); } } parcArrayList_Destroy(&componentNameList); }
static AthenaTransportLinkModule * _LoadModule(AthenaTransportLinkAdapter *athenaTransportLinkAdapter, const char *moduleName) { assertTrue(_LookupModule(athenaTransportLinkAdapter, moduleName) == NULL, "attempt to load an already loaded module"); // Derive the entry initialization name from the provided module name const char *moduleEntry; moduleEntry = _moduleNameToInitMethod(moduleName); // Check to see if the module was statically linked in. void *linkModule = RTLD_DEFAULT; ModuleInit _init = dlsym(linkModule, moduleEntry); // If not statically linked in, look for a shared library and load it from there if (_init == NULL) { // Derive the library name from the provided module name const char *moduleLibrary; moduleLibrary = _moduleNameToLibrary(moduleName); void *linkModule = dlopen(moduleLibrary, RTLD_NOW | RTLD_GLOBAL); parcMemory_Deallocate(&moduleLibrary); // If the shared library wasn't found, look for the symbol in our existing image. This // allows a link module to be linked directly into Athena without modifying the forwarder. if (linkModule == NULL) { parcLog_Error(athenaTransportLinkAdapter_GetLogger(athenaTransportLinkAdapter), "Unable to dlopen %s: %s", moduleName, dlerror()); parcMemory_Deallocate(&moduleEntry); errno = ENOENT; return NULL; } _init = dlsym(linkModule, moduleEntry); if (_init == NULL) { parcLog_Error(athenaTransportLinkAdapter_GetLogger(athenaTransportLinkAdapter), "Unable to find %s module _init method: %s", moduleName, dlerror()); parcMemory_Deallocate(&moduleEntry); dlclose(linkModule); errno = ENOENT; return NULL; } } parcMemory_Deallocate(&moduleEntry); // Call the initialization method. PARCArrayList *moduleList = _init(); if (moduleList == NULL) { // if the init method fails, unload the module if it was loaded parcLog_Error(athenaTransportLinkAdapter_GetLogger(athenaTransportLinkAdapter), "Empty module list returned from %s module", moduleName); if (linkModule != RTLD_DEFAULT) { dlclose(linkModule); } errno = ENOENT; return NULL; } // Process each link module instance (typically only one) for (int index = 0; index < parcArrayList_Size(moduleList); index++) { AthenaTransportLinkModule *athenaTransportLinkModule = parcArrayList_Get(moduleList, index); _AddModule(athenaTransportLinkAdapter, athenaTransportLinkModule); } parcArrayList_Destroy(&moduleList); return _LookupModule(athenaTransportLinkAdapter, moduleName); }