void test_arrayList_clear(void) { char * entry = "entry"; char * entry2 = "entry2"; arrayList_clear(list); arrayList_add(list, entry); arrayList_add(list, entry2); CU_ASSERT_EQUAL(arrayList_size(list), 2); arrayList_clear(list); CU_ASSERT_EQUAL(arrayList_size(list), 0); }
void test_arrayList_remove(void) { char * entry = "entry"; char * entry2 = "entry2"; char * entry3 = "entry3"; char * get; char * removed; arrayList_clear(list); arrayList_add(list, entry); arrayList_add(list, entry2); get = arrayList_get(list, 1); CU_ASSERT_EQUAL(entry2, get); // Remove first entry removed = arrayList_remove(list, 0); CU_ASSERT_EQUAL(entry, removed); // Check the new first element get = arrayList_get(list, 0); CU_ASSERT_EQUAL(entry2, get); // Add a new element arrayList_add(list, entry3); get = arrayList_get(list, 1); CU_ASSERT_EQUAL(entry3, get); }
celix_status_t serviceTracker_open(service_tracker_pt tracker) { service_listener_pt listener; array_list_pt initial = NULL; celix_status_t status = CELIX_SUCCESS; listener = (service_listener_pt) malloc(sizeof(*listener)); status = bundleContext_getServiceReferences(tracker->context, NULL, tracker->filter, &initial); if (status == CELIX_SUCCESS) { service_reference_pt initial_reference; unsigned int i; listener->handle = tracker; listener->serviceChanged = (void *) serviceTracker_serviceChanged; status = bundleContext_addServiceListener(tracker->context, listener, tracker->filter); if (status == CELIX_SUCCESS) { tracker->listener = listener; for (i = 0; i < arrayList_size(initial); i++) { initial_reference = (service_reference_pt) arrayList_get(initial, i); serviceTracker_track(tracker, initial_reference, NULL); } arrayList_clear(initial); arrayList_destroy(initial); initial = NULL; } } framework_logIfError(logger, status, NULL, "Cannot open tracker"); return status; }
void test_arrayList_addAll(void) { char * entry = "entry"; char * entry2 = "entry2"; char * entry3 = "entry3"; char * get; array_list_pt toAdd; bool changed; arrayList_clear(list); arrayList_create(&toAdd); arrayList_add(toAdd, entry); arrayList_add(toAdd, entry2); arrayList_add(list, entry3); get = arrayList_get(list, 0); CU_ASSERT_EQUAL(entry3, get); changed = arrayList_addAll(list, toAdd); CU_ASSERT_TRUE(changed); CU_ASSERT_EQUAL(arrayList_size(list), 3); get = arrayList_get(list, 1); CU_ASSERT_EQUAL(entry, get); get = arrayList_get(list, 2); CU_ASSERT_EQUAL(entry2, get); }
void test_arrayList_get(void) { char * entry = "entry"; char * entry2 = "entry2"; char * entry3 = NULL; char * get; arrayList_clear(list); arrayList_add(list, entry); arrayList_add(list, entry2); get = arrayList_get(list, 0); CU_ASSERT_EQUAL(entry, get); get = arrayList_get(list, 1); CU_ASSERT_EQUAL(entry2, get); arrayList_add(list, entry3); get = arrayList_get(list, 2); CU_ASSERT_PTR_NULL(get); get = arrayList_get(list, 42); CU_ASSERT_PTR_NULL(get); }
void test_arrayList_ensureCapacity(void) { int i; arrayList_create(&list); arrayList_clear(list); CU_ASSERT_EQUAL(list->capacity, 10); CU_ASSERT_EQUAL(list->size, 0); for (i = 0; i < 100; i++) { arrayList_add(list, "entry"); } CU_ASSERT_EQUAL(list->capacity, 133); CU_ASSERT_EQUAL(list->size, 100); arrayList_create(&list); }
void test_arrayList_trimToSize(void) { char * entry; arrayList_clear(list); entry = "entry"; arrayList_add(list, entry); CU_ASSERT_EQUAL(list->size, 1); CU_ASSERT_EQUAL(list->capacity, 10); arrayList_trimToSize(list); CU_ASSERT_EQUAL(list->size, 1); CU_ASSERT_EQUAL(list->capacity, 1); }
void test_arrayList_indexOf(void) { char * entry = "entry"; char * entry2 = "entry2"; arrayList_clear(list); arrayList_add(list, entry); arrayList_add(list, entry2); arrayList_add(list, entry2); arrayList_add(list, entry2); arrayList_add(list, entry2); CU_ASSERT_EQUAL(arrayList_indexOf(list, entry), 0); CU_ASSERT_EQUAL(arrayList_indexOf(list, entry2), 1); CU_ASSERT_EQUAL(arrayList_lastIndexOf(list, entry), 0); CU_ASSERT_EQUAL(arrayList_lastIndexOf(list, entry2), 4); }
void test_arrayList_size(void) { char * entry; char * entry2; char * entry3; arrayList_clear(list); CU_ASSERT_EQUAL(list->size, 0); entry = "entry"; arrayList_add(list, entry); CU_ASSERT_EQUAL(list->size, 1); entry2 = "entry"; arrayList_add(list, entry2); CU_ASSERT_EQUAL(list->size, 2); entry3 = "entry"; arrayList_add(list, entry3); CU_ASSERT_EQUAL(list->size, 3); }
void test_arrayList_set(void) { char * entry = "entry"; char * entry2 = "entry2"; char * entry3 = "entry3"; char * get; char * old; arrayList_clear(list); arrayList_add(list, entry); arrayList_add(list, entry2); get = arrayList_get(list, 1); CU_ASSERT_EQUAL(entry2, get); old = arrayList_set(list, 1, entry3); CU_ASSERT_EQUAL(entry2, old); get = arrayList_get(list, 1); CU_ASSERT_EQUAL(entry3, get); }
celix_status_t bundle_refresh(bundle_pt bundle) { celix_status_t status = CELIX_SUCCESS; module_pt module; status = bundle_closeModules(bundle); if (status == CELIX_SUCCESS) { arrayList_clear(bundle->modules); status = bundle_createModule(bundle, &module); if (status == CELIX_SUCCESS) { status = bundle_addModule(bundle, module); if (status == CELIX_SUCCESS) { bundle->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED; } } } framework_logIfError(bundle->framework->logger, status, NULL, "Failed to refresh bundle"); return status; }
celix_status_t pubsub_topicSubscriptionDestroy(topic_subscription_pt ts){ celix_status_t status = CELIX_SUCCESS; celixThreadMutex_lock(&ts->ts_lock); ts->running = false; free(ts->ifIpAddress); serviceTracker_destroy(ts->tracker); arrayList_clear(ts->sub_ep_list); arrayList_destroy(ts->sub_ep_list); hashMap_destroy(ts->servicesMap,false,false); celixThreadMutex_lock(&ts->socketMap_lock); hashMap_destroy(ts->socketMap,true,true); celixThreadMutex_unlock(&ts->socketMap_lock); celixThreadMutex_destroy(&ts->socketMap_lock); celixThreadMutex_lock(&ts->pendingConnections_lock); arrayList_destroy(ts->pendingConnections); celixThreadMutex_unlock(&ts->pendingConnections_lock); celixThreadMutex_destroy(&ts->pendingConnections_lock); celixThreadMutex_lock(&ts->pendingDisconnections_lock); arrayList_destroy(ts->pendingDisconnections); celixThreadMutex_unlock(&ts->pendingDisconnections_lock); celixThreadMutex_destroy(&ts->pendingDisconnections_lock); largeUdp_destroy(ts->largeUdpHandle); #if defined(__APPLE__) && defined(__MACH__) //TODO: Use kqueue for OSX #else close(ts->topicEpollFd); #endif celixThreadMutex_unlock(&ts->ts_lock); celixThreadMutex_destroy(&ts->ts_lock); free(ts); return status; }
void test_arrayList_contains(void) { char * entry = "entry"; char * entry2 = "entry2"; char * entry3 = NULL; bool contains; arrayList_clear(list); arrayList_add(list, entry); arrayList_add(list, entry2); CU_ASSERT_TRUE(arrayList_contains(list, entry)); CU_ASSERT_TRUE(arrayList_contains(list, entry2)); contains = arrayList_contains(list, NULL); CU_ASSERT_FALSE(contains); arrayList_add(list, entry3); CU_ASSERT_TRUE(arrayList_contains(list, entry3)); }
void test_arrayList_isEmpty(void) { arrayList_clear(list); CU_ASSERT_EQUAL(list->size, 0); CU_ASSERT_TRUE(arrayList_isEmpty(list)); }
static filter_pt filter_parseItem(char * filterString, int * pos) { char * attr = filter_parseAttr(filterString, pos); if(attr == NULL){ return NULL; } filter_skipWhiteSpace(filterString, pos); switch(filterString[*pos]) { case '~': { if (filterString[*pos + 1] == '=') { filter_pt filter = (filter_pt) malloc(sizeof(*filter)); *pos += 2; filter->operand = APPROX; filter->attribute = attr; filter->value = filter_parseValue(filterString, pos); return filter; } break; } case '>': { if (filterString[*pos + 1] == '=') { filter_pt filter = (filter_pt) malloc(sizeof(*filter)); *pos += 2; filter->operand = GREATEREQUAL; filter->attribute = attr; filter->value = filter_parseValue(filterString, pos); return filter; } else { filter_pt filter = (filter_pt) malloc(sizeof(*filter)); *pos += 1; filter->operand = GREATER; filter->attribute = attr; filter->value = filter_parseValue(filterString, pos); return filter; } break; } case '<': { if (filterString[*pos + 1] == '=') { filter_pt filter = (filter_pt) malloc(sizeof(*filter)); *pos += 2; filter->operand = LESSEQUAL; filter->attribute = attr; filter->value = filter_parseValue(filterString, pos); return filter; } else { filter_pt filter = (filter_pt) malloc(sizeof(*filter)); *pos += 1; filter->operand = LESS; filter->attribute = attr; filter->value = filter_parseValue(filterString, pos); return filter; } break; } case '=': { filter_pt filter = NULL; array_list_pt subs; if (filterString[*pos + 1] == '*') { int oldPos = *pos; *pos += 2; filter_skipWhiteSpace(filterString, pos); if (filterString[*pos] == ')') { filter_pt filter = (filter_pt) malloc(sizeof(*filter)); filter->operand = PRESENT; filter->attribute = attr; filter->value = NULL; return filter; } *pos = oldPos; } filter = (filter_pt) malloc(sizeof(*filter)); (*pos)++; subs = filter_parseSubstring(filterString, pos); if(subs!=NULL){ if (arrayList_size(subs) == 1) { char * string = (char *) arrayList_get(subs, 0); if (string != NULL) { filter->operand = EQUAL; filter->attribute = attr; filter->value = string; arrayList_clear(subs); arrayList_destroy(subs); return filter; } } } filter->operand = SUBSTRING; filter->attribute = attr; filter->value = subs; return filter; } } fw_log(logger, OSGI_FRAMEWORK_LOG_ERROR, "Invalid operator."); free(attr); return NULL; }
celix_status_t pubsubAdmin_addPublication(pubsub_admin_pt admin, pubsub_endpoint_pt pubEP) { celix_status_t status = CELIX_SUCCESS; printf("PSA_ZMQ: Received publication [FWUUID=%s bundleID=%ld scope=%s, topic=%s]\n", pubEP->frameworkUUID, pubEP->serviceID, pubEP->scope, pubEP->topic); const char* fwUUID = NULL; bundleContext_getProperty(admin->bundle_context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &fwUUID); if (fwUUID == NULL) { printf("PSA_ZMQ: Cannot retrieve fwUUID.\n"); return CELIX_INVALID_BUNDLE_CONTEXT; } char *scope_topic = createScopeTopicKey(pubEP->scope, pubEP->topic); if ((strcmp(pubEP->frameworkUUID, fwUUID) == 0) && (pubEP->endpoint == NULL)) { celixThreadMutex_lock(&admin->localPublicationsLock); service_factory_pt factory = (service_factory_pt) hashMap_get(admin->localPublications, scope_topic); if (factory == NULL) { topic_publication_pt pub = NULL; pubsub_serializer_service_t *best_serializer = NULL; if( (status=pubsubAdmin_getBestSerializer(admin, pubEP, &best_serializer)) == CELIX_SUCCESS){ status = pubsub_topicPublicationCreate(admin->bundle_context, pubEP, best_serializer, admin->ipAddress, admin->basePort, admin->maxPort, &pub); } else{ printf("PSA_ZMQ: Cannot find a serializer for publishing topic %s. Adding it to pending list.\n", pubEP->topic); celixThreadMutex_lock(&admin->noSerializerPendingsLock); arrayList_add(admin->noSerializerPublications,pubEP); celixThreadMutex_unlock(&admin->noSerializerPendingsLock); } if (status == CELIX_SUCCESS) { status = pubsub_topicPublicationStart(admin->bundle_context, pub, &factory); if (status == CELIX_SUCCESS && factory != NULL) { hashMap_put(admin->localPublications, strdup(scope_topic), factory); connectTopicPubSubToSerializer(admin, best_serializer, pub, true); } } else { printf("PSA_ZMQ: Cannot create a topicPublication for scope=%s, topic=%s (bundle %ld).\n", pubEP->scope, pubEP->topic, pubEP->serviceID); } } else { //just add the new EP to the list topic_publication_pt pub = (topic_publication_pt) factory->handle; pubsub_topicPublicationAddPublisherEP(pub, pubEP); } celixThreadMutex_unlock(&admin->localPublicationsLock); } else{ celixThreadMutex_lock(&admin->externalPublicationsLock); array_list_pt ext_pub_list = (array_list_pt) hashMap_get(admin->externalPublications, scope_topic); if (ext_pub_list == NULL) { arrayList_create(&ext_pub_list); hashMap_put(admin->externalPublications, strdup(scope_topic), ext_pub_list); } arrayList_add(ext_pub_list, pubEP); celixThreadMutex_unlock(&admin->externalPublicationsLock); } /* Re-evaluate the pending subscriptions */ celixThreadMutex_lock(&admin->pendingSubscriptionsLock); hash_map_entry_pt pendingSub = hashMap_getEntry(admin->pendingSubscriptions, scope_topic); if (pendingSub != NULL) { //There were pending subscription for the just published topic. Let's connect them. char* topic = (char*) hashMapEntry_getKey(pendingSub); array_list_pt pendingSubList = (array_list_pt) hashMapEntry_getValue(pendingSub); int i; for (i = 0; i < arrayList_size(pendingSubList); i++) { pubsub_endpoint_pt subEP = (pubsub_endpoint_pt) arrayList_get(pendingSubList, i); pubsubAdmin_addSubscription(admin, subEP); } hashMap_remove(admin->pendingSubscriptions, scope_topic); arrayList_clear(pendingSubList); arrayList_destroy(pendingSubList); free(topic); } celixThreadMutex_unlock(&admin->pendingSubscriptionsLock); /* Connect the new publisher to the subscription for his topic, if there is any */ celixThreadMutex_lock(&admin->subscriptionsLock); topic_subscription_pt sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, scope_topic); if (sub != NULL && pubEP->endpoint != NULL) { pubsub_topicSubscriptionAddConnectPublisherToPendingList(sub, pubEP->endpoint); } /* And check also for ANY subscription */ topic_subscription_pt any_sub = (topic_subscription_pt) hashMap_get(admin->subscriptions, PUBSUB_ANY_SUB_TOPIC); if (any_sub != NULL && pubEP->endpoint != NULL) { pubsub_topicSubscriptionAddConnectPublisherToPendingList(any_sub, pubEP->endpoint); } free(scope_topic); celixThreadMutex_unlock(&admin->subscriptionsLock); return status; }