incubator-celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1528394 [4/4] - in /incubator/celix/trunk: cmake/ framework/ framework/private/mock/ framework/private/resources-test/ framework/private/test/ framework/public/include/
Date Wed, 02 Oct 2013 09:16:55 GMT
Added: incubator/celix/trunk/framework/private/test/service_tracker_test.cpp
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/service_tracker_test.cpp?rev=1528394&view=auto
==============================================================================
--- incubator/celix/trunk/framework/private/test/service_tracker_test.cpp (added)
+++ incubator/celix/trunk/framework/private/test/service_tracker_test.cpp Wed Oct  2 09:16:54
2013
@@ -0,0 +1,832 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you 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.
+ */
+/*
+ * service_tracker_test.cpp
+ *
+ *  \date       Feb 6, 2013
+ *  \author     <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project
Team</a>
+ *  \copyright  Apache License, Version 2.0
+ */
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "CppUTest/TestHarness.h"
+#include "CppUTest/TestHarness_c.h"
+#include "CppUTest/CommandLineTestRunner.h"
+#include "CppUTestExt/MockSupport.h"
+
+extern "C"
+{
+#include "service_tracker_private.h"
+#include "service_reference_private.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(service_tracker) {
+	apr_pool_t *pool;
+
+	void setup(void) {
+		apr_initialize();
+		apr_pool_create(&pool, NULL);
+	}
+
+	void teardown() {
+		apr_pool_destroy(pool);
+		mock().checkExpectations();
+		mock().clear();
+	}
+};
+
+TEST(service_tracker, create) {
+	celix_status_t status;
+	service_tracker_pt tracker = NULL;
+	bundle_context_pt ctx = (bundle_context_pt) 0x123;
+	std::string service = "service";
+	status = serviceTracker_create(pool, ctx, (char *) service.c_str(), NULL, &tracker);
+
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(ctx, tracker->context);
+	POINTERS_EQUAL(NULL, tracker->customizer);
+	POINTERS_EQUAL(NULL, tracker->listener);
+	POINTERS_EQUAL(pool, tracker->pool);
+	POINTERS_EQUAL(tracker, tracker->tracker);
+	STRCMP_EQUAL("(objectClass=service)", tracker->filter);
+}
+
+TEST(service_tracker, createWithFilter) {
+	celix_status_t status;
+	service_tracker_pt tracker = NULL;
+	bundle_context_pt ctx = (bundle_context_pt) 0x123;
+	std::string filter = "(objectClass=test)";
+	status = serviceTracker_createWithFilter(pool, ctx, (char *) filter.c_str(), NULL, &tracker);
+
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(ctx, tracker->context);
+	POINTERS_EQUAL(NULL, tracker->customizer);
+	POINTERS_EQUAL(NULL, tracker->listener);
+	POINTERS_EQUAL(pool, tracker->pool);
+	POINTERS_EQUAL(tracker, tracker->tracker);
+	STRCMP_EQUAL("(objectClass=test)", tracker->filter);
+}
+
+TEST(service_tracker, destroy) {
+	celix_status_t status;
+	service_tracker_pt tracker = NULL;
+	bundle_context_pt ctx = (bundle_context_pt) 0x123;
+	std::string filter = "(objectClass=test)";
+	status = serviceTracker_createWithFilter(pool, ctx, (char *) filter.c_str(), NULL, &tracker);
+	service_listener_pt listener = (service_listener_pt) 0x20;
+	tracker->listener = listener;
+
+	mock()
+		.expectOneCall("bundleContext_removeServiceListener")
+		.withParameter("context", ctx)
+		.withParameter("listener", listener)
+		.andReturnValue(CELIX_SUCCESS);
+}
+
+TEST(service_tracker, open) {
+	// Without initial services and no customizer
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	tracker->pool = pool;
+	bundle_context_pt ctx = (bundle_context_pt) 0x10;
+	tracker->context = ctx;
+	std::string filter = "(objectClass=service)";
+	tracker->filter = (char *) filter.c_str();
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+
+	array_list_pt refs = NULL;
+	arrayList_create(pool, &refs);
+
+	mock().strictOrder();
+	mock()
+		.expectOneCall("bundleContext_getServiceReferences")
+		.withParameter("context", ctx)
+		.withParameter("serviceName", (char *) NULL)
+		.withParameter("filter", "(objectClass=service)")
+		.andOutputParameter("service_references", refs)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("bundleContext_addServiceListener")
+		.withParameter("context", ctx)
+		.withParameter("filter", "(objectClass=service)")
+		.ignoreOtherParameters()
+		.andReturnValue(CELIX_SUCCESS);
+	serviceTracker_open(tracker);
+	CHECK(tracker->listener != NULL);
+
+	// No services should be found
+	LONGS_EQUAL(0, arrayList_size(tracker->tracked));
+}
+
+TEST(service_tracker, open_withRefs) {
+	// With one initial service
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	tracker->pool = pool;
+	tracker->customizer = NULL;
+	bundle_context_pt ctx = (bundle_context_pt) 0x10;
+	tracker->context = ctx;
+	std::string filter = "(objectClass=service)";
+	tracker->filter = (char *) filter.c_str();
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+//	// add tracked to tracker->tracked
+//	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+//	entry->service = (void *) 0x31;
+//	service_reference_pt ref = (service_reference_pt) 0x51;
+//	entry->reference = ref;
+//	arrayList_add(tracked, entry);
+//	tracked_pt entry2 = (tracked_pt) malloc(sizeof(*entry));
+//	entry2->service = (void *) 0x32;
+//	service_reference_pt ref2 = (service_reference_pt) 0x52;
+//	entry2->reference = ref2;
+//	arrayList_add(tracked, entry2);
+
+	array_list_pt refs = NULL;
+	arrayList_create(pool, &refs);
+	service_reference_pt ref = (service_reference_pt) apr_palloc(pool, sizeof(*ref));
+	arrayList_add(refs, ref);
+	void *src = (void *) 0x345;
+
+//	mock().strictOrder();
+	mock()
+		.expectOneCall("bundleContext_getServiceReferences")
+		.withParameter("context", ctx)
+		.withParameter("serviceName", (char *) NULL)
+		.withParameter("filter", "(objectClass=service)")
+		.andOutputParameter("service_references", refs)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("bundleContext_addServiceListener")
+		.withParameter("context", ctx)
+		.withParameter("filter", "(objectClass=service)")
+		.ignoreOtherParameters()
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("bundleContext_getService")
+		.withParameter("context", ctx)
+		.withParameter("reference", ref)
+		.andOutputParameter("service_instance", src)
+		.andReturnValue(CELIX_SUCCESS);
+	serviceTracker_open(tracker);
+	CHECK(tracker->listener != NULL);
+
+	// One service should be found
+	LONGS_EQUAL(1, arrayList_size(tracker->tracked));
+}
+
+TEST(service_tracker, open_withRefsAndTracked) {
+	// With one initial service
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	tracker->pool = pool;
+	tracker->customizer = NULL;
+	bundle_context_pt ctx = (bundle_context_pt) 0x10;
+	tracker->context = ctx;
+	std::string filter = "(objectClass=service)";
+	tracker->filter = (char *) filter.c_str();
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+
+	array_list_pt refs = NULL;
+	arrayList_create(pool, &refs);
+	arrayList_add(refs, ref);
+	void *src = (void *) 0x345;
+
+//	mock().strictOrder();
+	mock()
+		.expectOneCall("bundleContext_getServiceReferences")
+		.withParameter("context", ctx)
+		.withParameter("serviceName", (char *) NULL)
+		.withParameter("filter", "(objectClass=service)")
+		.andOutputParameter("service_references", refs)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("bundleContext_addServiceListener")
+		.withParameter("context", ctx)
+		.withParameter("filter", "(objectClass=service)")
+		.ignoreOtherParameters()
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceReference_equals")
+		.withParameter("reference", ref)
+		.andOutputParameter("equal", true)
+		.ignoreOtherParameters()
+		.andReturnValue(CELIX_SUCCESS);
+	serviceTracker_open(tracker);
+	CHECK(tracker->listener != NULL);
+
+	// One service should be found
+	LONGS_EQUAL(1, arrayList_size(tracker->tracked));
+}
+
+TEST(service_tracker, close) {
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	tracker->customizer = NULL;
+	bundle_context_pt ctx = (bundle_context_pt) 0x345;
+	tracker->context = ctx;
+	// new tracker->listener
+	service_listener_pt listener = (service_listener_pt) 0x42;
+	tracker->listener = (service_listener_pt) listener;
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+
+	mock()
+		.expectOneCall("bundleContext_removeServiceListener")
+		.withParameter("context", ctx)
+		.withParameter("listener", listener)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceReference_equals")
+		.withParameter("reference", ref)
+		.withParameter("compareTo", ref)
+		.andOutputParameter("equal", true)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("bundleContext_ungetService")
+		.withParameter("context", ctx)
+		.withParameter("reference", ref)
+		.andOutputParameter("result", true)
+		.andReturnValue(CELIX_SUCCESS);
+
+	serviceTracker_close(tracker);
+}
+
+TEST(service_tracker, getServiceReference) {
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+	tracked_pt entry2 = (tracked_pt) malloc(sizeof(*entry));
+	entry2->service = (void *) 0x32;
+	service_reference_pt ref2 = (service_reference_pt) 0x52;
+	entry2->reference = ref2;
+	arrayList_add(tracked, entry2);
+
+	service_reference_pt reference = serviceTracker_getServiceReference(tracker);
+	POINTERS_EQUAL(ref, reference);
+}
+
+TEST(service_tracker, getServiceReferenceNull) {
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+
+	service_reference_pt reference = serviceTracker_getServiceReference(tracker);
+	POINTERS_EQUAL(NULL, reference);
+}
+
+TEST(service_tracker, getServiceReferences) {
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+	tracked_pt entry2 = (tracked_pt) malloc(sizeof(*entry));
+	entry2->service = (void *) 0x32;
+	service_reference_pt ref2 = (service_reference_pt) 0x52;
+	entry2->reference = ref2;
+	arrayList_add(tracked, entry2);
+
+	array_list_pt references = serviceTracker_getServiceReferences(tracker);
+	LONGS_EQUAL(2, arrayList_size(references));
+	POINTERS_EQUAL(ref, arrayList_get(references, 0));
+	POINTERS_EQUAL(ref2, arrayList_get(references, 1));
+}
+
+TEST(service_tracker, getService) {
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+	tracked_pt entry2 = (tracked_pt) malloc(sizeof(*entry));
+	entry2->service = (void *) 0x32;
+	service_reference_pt ref2 = (service_reference_pt) 0x52;
+	entry2->reference = ref2;
+	arrayList_add(tracked, entry2);
+
+	void *service = serviceTracker_getService(tracker);
+	POINTERS_EQUAL(0x31, service);
+}
+
+TEST(service_tracker, getServiceNull) {
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+
+	void *service = serviceTracker_getService(tracker);
+	POINTERS_EQUAL(NULL, service);
+}
+
+TEST(service_tracker, getServices) {
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+	tracked_pt entry2 = (tracked_pt) malloc(sizeof(*entry));
+	entry2->service = (void *) 0x32;
+	service_reference_pt ref2 = (service_reference_pt) 0x52;
+	entry2->reference = ref2;
+	arrayList_add(tracked, entry2);
+
+	array_list_pt services = serviceTracker_getServices(tracker);
+	LONGS_EQUAL(2, arrayList_size(services));
+	POINTERS_EQUAL(0x31, arrayList_get(services, 0));
+	POINTERS_EQUAL(0x32, arrayList_get(services, 1));
+}
+
+TEST(service_tracker, getServiceByReference) {
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+
+	mock()
+		.expectOneCall("serviceReference_equals")
+		.withParameter("reference", ref)
+		.andOutputParameter("equal", true)
+		.ignoreOtherParameters()
+		.andReturnValue(4)
+		.withCallOrder(1);
+	void *service = serviceTracker_getServiceByReference(tracker, ref);
+	POINTERS_EQUAL(0x31, service);
+}
+
+TEST(service_tracker, getServiceByReferenceNull) {
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+
+	mock()
+		.expectOneCall("serviceReference_equals")
+		.withParameter("reference", ref)
+		.andOutputParameter("equal", false)
+		.ignoreOtherParameters()
+		.andReturnValue(CELIX_SUCCESS)
+		.withCallOrder(1);
+	void *service = serviceTracker_getServiceByReference(tracker, ref);
+	POINTERS_EQUAL(NULL, service);
+}
+
+TEST(service_tracker, serviceChangedRegistered) {
+	// With one initial service
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	tracker->pool = pool;
+	tracker->customizer = NULL;
+	bundle_context_pt ctx = (bundle_context_pt) 0x10;
+	tracker->context = ctx;
+	service_listener_pt listener = (service_listener_pt) apr_palloc(pool, sizeof(*listener));
+	tracker->listener = listener;
+	listener->handle = tracker;
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	void *src = (void *) 0x345;
+
+	service_event_pt event = (service_event_pt) apr_palloc(pool, sizeof(*event));
+	event->type = SERVICE_EVENT_REGISTERED;
+	event->reference = ref;
+
+	mock()
+		.expectOneCall("bundleContext_getService")
+		.withParameter("context", ctx)
+		.withParameter("reference", ref)
+		.andOutputParameter("service_instance", src)
+		.andReturnValue(CELIX_SUCCESS);
+	serviceTracker_serviceChanged(listener, event);
+}
+
+TEST(service_tracker, serviceChangedModified) {
+	// With one initial service
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	tracker->pool = pool;
+	tracker->customizer = NULL;
+	bundle_context_pt ctx = (bundle_context_pt) 0x10;
+	tracker->context = ctx;
+	service_listener_pt listener = (service_listener_pt) apr_palloc(pool, sizeof(*listener));
+	tracker->listener = listener;
+	listener->handle = tracker;
+
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+//	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+
+	service_event_pt event = (service_event_pt) apr_palloc(pool, sizeof(*event));
+	event->type = SERVICE_EVENT_MODIFIED;
+	event->reference = ref;
+
+	mock()
+		.expectOneCall("serviceReference_equals")
+		.withParameter("reference", ref)
+		.andOutputParameter("equal", true)
+		.ignoreOtherParameters()
+		.andReturnValue(CELIX_SUCCESS);
+	serviceTracker_serviceChanged(listener, event);
+}
+
+TEST(service_tracker, serviceChangedUnregistering) {
+	// With one initial service
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	tracker->pool = pool;
+	tracker->customizer = NULL;
+	bundle_context_pt ctx = (bundle_context_pt) 0x10;
+	tracker->context = ctx;
+	service_listener_pt listener = (service_listener_pt) apr_palloc(pool, sizeof(*listener));
+	tracker->listener = listener;
+	listener->handle = tracker;
+
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+//	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+
+	service_event_pt event = (service_event_pt) apr_palloc(pool, sizeof(*event));
+	event->type = SERVICE_EVENT_UNREGISTERING;
+	event->reference = ref;
+
+	mock()
+		.expectOneCall("serviceReference_equals")
+		.withParameter("reference", ref)
+		.withParameter("compareTo", ref)
+		.andOutputParameter("equal", true)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("bundleContext_ungetService")
+		.withParameter("context", ctx)
+		.withParameter("reference", ref)
+		.andOutputParameter("result", true)
+		.andReturnValue(CELIX_SUCCESS);
+	serviceTracker_serviceChanged(listener, event);
+}
+
+TEST(service_tracker, serviceChangedModifiedEndmatch) {
+	// With one initial service
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	tracker->pool = pool;
+	bundle_context_pt ctx = (bundle_context_pt) 0x10;
+	tracker->context = ctx;
+	service_listener_pt listener = (service_listener_pt) apr_palloc(pool, sizeof(*listener));
+	tracker->listener = listener;
+	listener->handle = tracker;
+
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+//	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+
+	service_event_pt event = (service_event_pt) apr_palloc(pool, sizeof(*event));
+	event->type = SERVICE_EVENT_MODIFIED_ENDMATCH;
+	event->reference = ref;
+
+	serviceTracker_serviceChanged(listener, event);
+}
+
+extern "C" {
+	celix_status_t serviceDependency_addingService(void * handle, service_reference_pt reference,
void **service) {
+		*service = (void*) 0x45;
+		return CELIX_SUCCESS;
+	}
+
+	celix_status_t serviceDependency_addedService(void * handle, service_reference_pt reference,
void *service) {
+		return CELIX_SUCCESS;
+	}
+}
+
+TEST(service_tracker, serviceChangedRegisteredCustomizer) {
+	// With one initial service
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	tracker->pool = pool;
+	bundle_context_pt ctx = (bundle_context_pt) 0x10;
+	tracker->context = ctx;
+	service_listener_pt listener = (service_listener_pt) apr_palloc(pool, sizeof(*listener));
+	tracker->listener = listener;
+	listener->handle = tracker;
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+	service_tracker_customizer_pt customizer = (service_tracker_customizer_pt) 0x20;
+	tracker->customizer = customizer;
+
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	void *src = (void *) 0x345;
+
+	void * handle = (void*) 0x60;
+
+	service_event_pt event = (service_event_pt) apr_palloc(pool, sizeof(*event));
+	event->type = SERVICE_EVENT_REGISTERED;
+	event->reference = ref;
+
+	mock()
+		.expectOneCall("serviceTrackerCustomizer_getHandle")
+		.withParameter("customizer", customizer)
+		.andOutputParameter("handle", handle)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceTrackerCustomizer_getAddingFunction")
+		.withParameter("customizer", customizer)
+		.andOutputParameter("function", (void *) serviceDependency_addingService)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceTrackerCustomizer_getHandle")
+		.withParameter("customizer", customizer)
+		.andOutputParameter("handle", handle)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceTrackerCustomizer_getAddedFunction")
+		.withParameter("customizer", customizer)
+		.andOutputParameter("function", (void *) serviceDependency_addedService)
+		.andReturnValue(CELIX_SUCCESS);
+	serviceTracker_serviceChanged(listener, event);
+}
+
+
+extern "C" {
+	celix_status_t serviceDependency_modifiedService(void * handle, service_reference_pt reference,
void * service) {
+		return CELIX_SUCCESS;
+	}
+}
+
+TEST(service_tracker, serviceChangedModifiedCustomizer) {
+	// With one initial service
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	tracker->pool = pool;
+	bundle_context_pt ctx = (bundle_context_pt) 0x10;
+	tracker->context = ctx;
+	service_listener_pt listener = (service_listener_pt) apr_palloc(pool, sizeof(*listener));
+	tracker->listener = listener;
+	listener->handle = tracker;
+	service_tracker_customizer_pt customizer = (service_tracker_customizer_pt) 0x20;
+	tracker->customizer = customizer;
+
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+//	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+
+	service_event_pt event = (service_event_pt) apr_palloc(pool, sizeof(*event));
+	event->type = SERVICE_EVENT_MODIFIED;
+	event->reference = ref;
+
+	void * handle = (void*) 0x60;
+
+	mock()
+		.expectOneCall("serviceReference_equals")
+		.withParameter("reference", ref)
+		.andOutputParameter("equal", true)
+		.ignoreOtherParameters()
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceTrackerCustomizer_getHandle")
+		.withParameter("customizer", customizer)
+		.andOutputParameter("handle", handle)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceTrackerCustomizer_getModifiedFunction")
+		.withParameter("customizer", customizer)
+		.andOutputParameter("function", (void *) serviceDependency_modifiedService)
+		.andReturnValue(CELIX_SUCCESS);
+	serviceTracker_serviceChanged(listener, event);
+}
+
+extern "C" {
+	celix_status_t serviceDependency_removedService(void * handle, service_reference_pt reference,
void * service) {
+		return CELIX_SUCCESS;
+	}
+}
+
+TEST(service_tracker, serviceChangedUnregisteringCustomizer) {
+	// With one initial service
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	tracker->pool = pool;
+	bundle_context_pt ctx = (bundle_context_pt) 0x10;
+	tracker->context = ctx;
+	service_listener_pt listener = (service_listener_pt) apr_palloc(pool, sizeof(*listener));
+	tracker->listener = listener;
+	listener->handle = tracker;
+	service_tracker_customizer_pt customizer = (service_tracker_customizer_pt) 0x20;
+	tracker->customizer = customizer;
+
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+//	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+
+	service_event_pt event = (service_event_pt) apr_palloc(pool, sizeof(*event));
+	event->type = SERVICE_EVENT_UNREGISTERING;
+	event->reference = ref;
+
+	void * handle = (void*) 0x60;
+
+	mock()
+		.expectOneCall("serviceReference_equals")
+		.withParameter("reference", ref)
+		.withParameter("compareTo", ref)
+		.andOutputParameter("equal", true)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceTrackerCustomizer_getHandle")
+		.withParameter("customizer", customizer)
+		.andOutputParameter("handle", handle)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceTrackerCustomizer_getRemovedFunction")
+		.withParameter("customizer", customizer)
+		.andOutputParameter("function", (void *) serviceDependency_removedService)
+		.andReturnValue(CELIX_SUCCESS);
+	serviceTracker_serviceChanged(listener, event);
+}
+
+TEST(service_tracker, serviceChangedUnregisteringCustomizerNoFunc) {
+	// With one initial service
+	// new tracker
+	service_tracker_pt tracker = (service_tracker_pt) apr_palloc(pool, sizeof(*tracker));
+	tracker->pool = pool;
+	bundle_context_pt ctx = (bundle_context_pt) 0x10;
+	tracker->context = ctx;
+	service_listener_pt listener = (service_listener_pt) apr_palloc(pool, sizeof(*listener));
+	tracker->listener = listener;
+	listener->handle = tracker;
+	service_tracker_customizer_pt customizer = (service_tracker_customizer_pt) 0x20;
+	tracker->customizer = customizer;
+
+	// new tracker->tracked
+	array_list_pt tracked = NULL;
+	arrayList_create(pool, &tracked);
+	tracker->tracked = tracked;
+//	// add tracked to tracker->tracked
+	tracked_pt entry = (tracked_pt) malloc(sizeof(*entry));
+	entry->service = (void *) 0x31;
+	service_reference_pt ref = (service_reference_pt) 0x51;
+	entry->reference = ref;
+	arrayList_add(tracked, entry);
+
+	service_event_pt event = (service_event_pt) apr_palloc(pool, sizeof(*event));
+	event->type = SERVICE_EVENT_UNREGISTERING;
+	event->reference = ref;
+
+	void * handle = (void*) 0x60;
+
+	mock()
+		.expectOneCall("serviceReference_equals")
+		.withParameter("reference", ref)
+		.withParameter("compareTo", ref)
+		.andOutputParameter("equal", true)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceTrackerCustomizer_getHandle")
+		.withParameter("customizer", customizer)
+		.andOutputParameter("handle", handle)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceTrackerCustomizer_getRemovedFunction")
+		.withParameter("customizer", customizer)
+		.andOutputParameter("function", (void *) NULL)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("bundleContext_ungetService")
+		.withParameter("context", ctx)
+		.withParameter("reference", ref)
+		.andOutputParameter("result", true)
+		.andReturnValue(CELIX_SUCCESS);
+	serviceTracker_serviceChanged(listener, event);
+}
+
+
+

Added: incubator/celix/trunk/framework/private/test/utils_test.cpp
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/utils_test.cpp?rev=1528394&view=auto
==============================================================================
--- incubator/celix/trunk/framework/private/test/utils_test.cpp (added)
+++ incubator/celix/trunk/framework/private/test/utils_test.cpp Wed Oct  2 09:16:54 2013
@@ -0,0 +1,203 @@
+/**
+ *Licensed to the Apache Software Foundation (ASF) under one
+ *or more contributor license agreements.  See the NOTICE file
+ *distributed with this work for additional information
+ *regarding copyright ownership.  The ASF licenses this file
+ *to you 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.
+ */
+/*
+ * utils_test.cpp
+ *
+ *  \date       Feb 6, 2013
+ *  \author     <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project
Team</a>
+ *  \copyright  Apache License, Version 2.0
+ */
+#include "CppUTest/TestHarness.h"
+#include "CppUTest/TestHarness_c.h"
+#include "CppUTest/CommandLineTestRunner.h"
+
+extern "C"
+{
+#include "utils.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(utils) {
+
+	void setup(void) {
+	}
+
+	void teardown() {
+	}
+};
+
+TEST(utils, stringHash) {
+	std::string toHash = "abc";
+	unsigned int hash;
+	hash = utils_stringHash((void *) toHash.c_str());
+	LONGS_EQUAL(446371745, hash);
+
+	toHash = "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz";
+	hash = utils_stringHash((void *) toHash.c_str());
+	LONGS_EQUAL(1508668412, hash);
+
+	toHash = "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz";
+	hash = utils_stringHash((void *) toHash.c_str());
+	LONGS_EQUAL(829630780, hash);
+}
+
+TEST(utils, stringEquals) {
+	// Compare with equal strings
+	std::string org = "abc";
+	std::string cmp = "abc";
+
+	int result = utils_stringEquals((void *) org.c_str(), (void *) cmp.c_str());
+	CHECK(result);
+
+	// Compare with no equal strings
+	cmp = "abcd";
+
+	result = utils_stringEquals((void *) org.c_str(), (void *) cmp.c_str());
+	CHECK(!result);
+
+	// Compare with numeric strings
+	org = "123";
+	cmp = "123";
+
+	result = utils_stringEquals((void *) org.c_str(), (void *) cmp.c_str());
+	CHECK(result);
+
+	// Compare with long strings
+	org = "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz";
+	cmp = "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
+			"abc123def456ghi789jkl012mno345pqr678stu901vwx234yz";
+
+	result = utils_stringEquals((void *) org.c_str(), (void *) cmp.c_str());
+	CHECK(result);
+}
+
+TEST(utils, stringTrim) {
+	// Multiple whitespaces, before, after and in between
+	std::string toTrim = " a b c ";
+	char *result = utils_stringTrim((char*) toTrim.c_str());
+
+	STRCMP_EQUAL("a b c", result);
+
+	// No whitespaces
+	toTrim = "abc";
+	result = utils_stringTrim((char*) toTrim.c_str());
+
+	STRCMP_EQUAL("abc", result);
+
+	// Only whitespace before
+	toTrim = "               abc";
+	result = utils_stringTrim((char*) toTrim.c_str());
+
+	STRCMP_EQUAL("abc", result);
+
+	// Only whitespace after
+	toTrim = "abc         ";
+	result = utils_stringTrim((char*) toTrim.c_str());
+
+	STRCMP_EQUAL("abc", result);
+
+	// Whitespace other then space (tab, cr..).
+	toTrim = "\tabc  \n asdf  \n";
+	result = utils_stringTrim((char*) toTrim.c_str());
+
+	STRCMP_EQUAL("abc  \n asdf", result);
+}
+
+TEST(utils, isNumeric) {
+	// Check numeric string
+	std::string toCheck = "42";
+
+	bool result;
+	celix_status_t status = utils_isNumeric((char *) toCheck.c_str(), &result);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	CHECK_C(result);
+
+	// Check non numeric string
+	toCheck = "42b";
+	status = utils_isNumeric((char *) toCheck.c_str(), &result);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	CHECK_C(!result);
+}
+
+

Modified: incubator/celix/trunk/framework/private/test/version_range_test.cpp
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/version_range_test.cpp?rev=1528394&r1=1528393&r2=1528394&view=diff
==============================================================================
--- incubator/celix/trunk/framework/private/test/version_range_test.cpp (original)
+++ incubator/celix/trunk/framework/private/test/version_range_test.cpp Wed Oct  2 09:16:54
2013
@@ -64,7 +64,8 @@ extern "C"
 }
 
 int main(int argc, char** argv) {
-	return RUN_ALL_TESTS(argc, argv);
+	RUN_ALL_TESTS(argc, argv);
+	return 0;
 }
 
 TEST_GROUP(version_range) {
@@ -180,7 +181,8 @@ TEST(version_range, parse) {
 		.withParameter("versionStr", "7.8.9")
 		.andOutputParameter("version", high);
 
-	status = versionRange_parse(pool, "[1.2.3, 7.8.9]", &range);
+	std::string version = "[1.2.3, 7.8.9]";
+	status = versionRange_parse(pool, (char *) version.c_str(), &range);
 	LONGS_EQUAL(CELIX_SUCCESS, status);
 }
 

Modified: incubator/celix/trunk/framework/public/include/service_event.h
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/public/include/service_event.h?rev=1528394&r1=1528393&r2=1528394&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/service_event.h (original)
+++ incubator/celix/trunk/framework/public/include/service_event.h Wed Oct  2 09:16:54 2013
@@ -29,11 +29,6 @@
 #ifndef SERVICE_EVENT_H_
 #define SERVICE_EVENT_H_
 
-typedef enum serviceEventType service_event_type_e;
-typedef struct serviceEvent *service_event_pt;
-
-#include "service_reference.h"
-
 enum serviceEventType
 {
 	SERVICE_EVENT_REGISTERED = 0x00000001,
@@ -42,6 +37,12 @@ enum serviceEventType
 	SERVICE_EVENT_MODIFIED_ENDMATCH = 0x00000008,
 };
 
+typedef enum serviceEventType service_event_type_e;
+
+typedef struct serviceEvent *service_event_pt;
+
+#include "service_reference.h"
+
 #include "service_reference.h"
 
 struct serviceEvent {



Mime
View raw message