You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ab...@apache.org on 2013/10/02 11:16:55 UTC

svn commit: r1528394 [3/4] - in /incubator/celix/trunk: cmake/ framework/ framework/private/mock/ framework/private/resources-test/ framework/private/test/ framework/public/include/

Copied: incubator/celix/trunk/framework/private/test/filter_test.cpp (from r1528390, incubator/celix/trunk/framework/public/include/service_event.h)
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/filter_test.cpp?p2=incubator/celix/trunk/framework/private/test/filter_test.cpp&p1=incubator/celix/trunk/framework/public/include/service_event.h&r1=1528390&r2=1528394&rev=1528394&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/service_event.h (original)
+++ incubator/celix/trunk/framework/private/test/filter_test.cpp Wed Oct  2 09:16:54 2013
@@ -1,4 +1,4 @@
-/*
+/**
  *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
@@ -16,41 +16,51 @@
  *specific language governing permissions and limitations
  *under the License.
  */
-/**
- *
- * @defgroup ServiceListener Service Listener
- * @ingroup framework
- * @{
+/*
+ * filter_test.cpp
  *
- *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
- *  \date      	January 11, 2012
- *  \copyright	Apache License, Version 2.0
+ *  \date       Feb 11, 2013
+ *  \author     <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ *  \copyright  Apache License, Version 2.0
  */
-#ifndef SERVICE_EVENT_H_
-#define SERVICE_EVENT_H_
+#include <stdlib.h>
+#include <stdio.h>
 
-typedef enum serviceEventType service_event_type_e;
-typedef struct serviceEvent *service_event_pt;
+#include "CppUTest/TestHarness.h"
+#include "CppUTest/TestHarness_c.h"
+#include "CppUTest/CommandLineTestRunner.h"
+#include "CppUTestExt/MockSupport.h"
+
+extern "C" {
+#include "filter_private.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(filter) {
+	apr_pool_t *pool;
+
+	void setup(void) {
+		apr_initialize();
+		apr_pool_create(&pool, NULL);
+	}
+
+	void teardown() {
+		apr_pool_destroy(pool);
+		mock().checkExpectations();
+		mock().clear();
+	}
+};
 
-#include "service_reference.h"
+TEST(filter, create) {
+	char filterStr[] = "(key=value)";
+	filter_pt filter = filter_create(filterStr, pool);
 
-enum serviceEventType
-{
-	SERVICE_EVENT_REGISTERED = 0x00000001,
-	SERVICE_EVENT_MODIFIED = 0x00000002,
-	SERVICE_EVENT_UNREGISTERING = 0x00000004,
-	SERVICE_EVENT_MODIFIED_ENDMATCH = 0x00000008,
-};
+	STRCMP_EQUAL(filterStr, filter->filterStr);
+}
 
-#include "service_reference.h"
 
-struct serviceEvent {
-	service_reference_pt reference;
-	service_event_type_e type;
-};
 
-#endif /* SERVICE_EVENT_H_ */
 
-/**
- * @}
- */

Copied: incubator/celix/trunk/framework/private/test/framework_test.cpp (from r1528390, incubator/celix/trunk/framework/public/include/service_event.h)
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/framework_test.cpp?p2=incubator/celix/trunk/framework/private/test/framework_test.cpp&p1=incubator/celix/trunk/framework/public/include/service_event.h&r1=1528390&r2=1528394&rev=1528394&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/service_event.h (original)
+++ incubator/celix/trunk/framework/private/test/framework_test.cpp Wed Oct  2 09:16:54 2013
@@ -1,4 +1,4 @@
-/*
+/**
  *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
@@ -16,41 +16,44 @@
  *specific language governing permissions and limitations
  *under the License.
  */
-/**
- *
- * @defgroup ServiceListener Service Listener
- * @ingroup framework
- * @{
+/*
+ * framework_test.cpp
  *
- *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
- *  \date      	January 11, 2012
- *  \copyright	Apache License, Version 2.0
+ *  \date       Feb 11, 2013
+ *  \author     <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ *  \copyright  Apache License, Version 2.0
  */
-#ifndef SERVICE_EVENT_H_
-#define SERVICE_EVENT_H_
+#include <stdlib.h>
+#include <stdio.h>
 
-typedef enum serviceEventType service_event_type_e;
-typedef struct serviceEvent *service_event_pt;
-
-#include "service_reference.h"
-
-enum serviceEventType
-{
-	SERVICE_EVENT_REGISTERED = 0x00000001,
-	SERVICE_EVENT_MODIFIED = 0x00000002,
-	SERVICE_EVENT_UNREGISTERING = 0x00000004,
-	SERVICE_EVENT_MODIFIED_ENDMATCH = 0x00000008,
+#include "CppUTest/TestHarness.h"
+#include "CppUTest/TestHarness_c.h"
+#include "CppUTest/CommandLineTestRunner.h"
+#include "CppUTestExt/MockSupport.h"
+
+extern "C" {
+#include "framework.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(framework) {
+	apr_pool_t *pool;
+
+	void setup(void) {
+		apr_initialize();
+		apr_pool_create(&pool, NULL);
+	}
+
+	void teardown() {
+		apr_pool_destroy(pool);
+		mock().checkExpectations();
+		mock().clear();
+	}
 };
 
-#include "service_reference.h"
 
-struct serviceEvent {
-	service_reference_pt reference;
-	service_event_type_e type;
-};
 
-#endif /* SERVICE_EVENT_H_ */
 
-/**
- * @}
- */

Copied: incubator/celix/trunk/framework/private/test/manifest_parser_test.cpp (from r1528390, incubator/celix/trunk/framework/public/include/service_event.h)
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/manifest_parser_test.cpp?p2=incubator/celix/trunk/framework/private/test/manifest_parser_test.cpp&p1=incubator/celix/trunk/framework/public/include/service_event.h&r1=1528390&r2=1528394&rev=1528394&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/service_event.h (original)
+++ incubator/celix/trunk/framework/private/test/manifest_parser_test.cpp Wed Oct  2 09:16:54 2013
@@ -1,4 +1,4 @@
-/*
+/**
  *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
@@ -16,41 +16,44 @@
  *specific language governing permissions and limitations
  *under the License.
  */
-/**
- *
- * @defgroup ServiceListener Service Listener
- * @ingroup framework
- * @{
+/*
+ * manifest_parser_test.cpp
  *
- *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
- *  \date      	January 11, 2012
- *  \copyright	Apache License, Version 2.0
+ *  \date       Feb 11, 2013
+ *  \author     <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ *  \copyright  Apache License, Version 2.0
  */
-#ifndef SERVICE_EVENT_H_
-#define SERVICE_EVENT_H_
+#include <stdlib.h>
+#include <stdio.h>
 
-typedef enum serviceEventType service_event_type_e;
-typedef struct serviceEvent *service_event_pt;
-
-#include "service_reference.h"
-
-enum serviceEventType
-{
-	SERVICE_EVENT_REGISTERED = 0x00000001,
-	SERVICE_EVENT_MODIFIED = 0x00000002,
-	SERVICE_EVENT_UNREGISTERING = 0x00000004,
-	SERVICE_EVENT_MODIFIED_ENDMATCH = 0x00000008,
+#include "CppUTest/TestHarness.h"
+#include "CppUTest/TestHarness_c.h"
+#include "CppUTest/CommandLineTestRunner.h"
+#include "CppUTestExt/MockSupport.h"
+
+extern "C" {
+#include "manifest_parser.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(manifest_parser) {
+	apr_pool_t *pool;
+
+	void setup(void) {
+		apr_initialize();
+		apr_pool_create(&pool, NULL);
+	}
+
+	void teardown() {
+		apr_pool_destroy(pool);
+		mock().checkExpectations();
+		mock().clear();
+	}
 };
 
-#include "service_reference.h"
 
-struct serviceEvent {
-	service_reference_pt reference;
-	service_event_type_e type;
-};
 
-#endif /* SERVICE_EVENT_H_ */
 
-/**
- * @}
- */

Copied: incubator/celix/trunk/framework/private/test/manifest_test.cpp (from r1528390, incubator/celix/trunk/framework/public/include/service_event.h)
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/manifest_test.cpp?p2=incubator/celix/trunk/framework/private/test/manifest_test.cpp&p1=incubator/celix/trunk/framework/public/include/service_event.h&r1=1528390&r2=1528394&rev=1528394&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/service_event.h (original)
+++ incubator/celix/trunk/framework/private/test/manifest_test.cpp Wed Oct  2 09:16:54 2013
@@ -1,4 +1,4 @@
-/*
+/**
  *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
@@ -16,41 +16,43 @@
  *specific language governing permissions and limitations
  *under the License.
  */
-/**
- *
- * @defgroup ServiceListener Service Listener
- * @ingroup framework
- * @{
+/*
+ * manifest_test.cpp
  *
- *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
- *  \date      	January 11, 2012
- *  \copyright	Apache License, Version 2.0
+ *  \date       Feb 11, 2013
+ *  \author     <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ *  \copyright  Apache License, Version 2.0
  */
-#ifndef SERVICE_EVENT_H_
-#define SERVICE_EVENT_H_
-
-typedef enum serviceEventType service_event_type_e;
-typedef struct serviceEvent *service_event_pt;
+#include <stdlib.h>
+#include <stdio.h>
 
-#include "service_reference.h"
-
-enum serviceEventType
-{
-	SERVICE_EVENT_REGISTERED = 0x00000001,
-	SERVICE_EVENT_MODIFIED = 0x00000002,
-	SERVICE_EVENT_UNREGISTERING = 0x00000004,
-	SERVICE_EVENT_MODIFIED_ENDMATCH = 0x00000008,
+#include "CppUTest/TestHarness.h"
+#include "CppUTest/TestHarness_c.h"
+#include "CppUTest/CommandLineTestRunner.h"
+#include "CppUTestExt/MockSupport.h"
+
+extern "C" {
+#include "manifest.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(manifest) {
+	apr_pool_t *pool;
+
+	void setup(void) {
+		apr_initialize();
+		apr_pool_create(&pool, NULL);
+	}
+
+	void teardown() {
+		apr_pool_destroy(pool);
+		mock().checkExpectations();
+		mock().clear();
+	}
 };
 
-#include "service_reference.h"
-
-struct serviceEvent {
-	service_reference_pt reference;
-	service_event_type_e type;
-};
 
-#endif /* SERVICE_EVENT_H_ */
 
-/**
- * @}
- */

Copied: incubator/celix/trunk/framework/private/test/module_test.cpp (from r1528390, incubator/celix/trunk/framework/public/include/service_event.h)
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/module_test.cpp?p2=incubator/celix/trunk/framework/private/test/module_test.cpp&p1=incubator/celix/trunk/framework/public/include/service_event.h&r1=1528390&r2=1528394&rev=1528394&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/service_event.h (original)
+++ incubator/celix/trunk/framework/private/test/module_test.cpp Wed Oct  2 09:16:54 2013
@@ -1,4 +1,4 @@
-/*
+/**
  *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
@@ -16,41 +16,44 @@
  *specific language governing permissions and limitations
  *under the License.
  */
-/**
- *
- * @defgroup ServiceListener Service Listener
- * @ingroup framework
- * @{
+/*
+ * module_test.cpp
  *
- *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
- *  \date      	January 11, 2012
- *  \copyright	Apache License, Version 2.0
+ *  \date       Feb 11, 2013
+ *  \author     <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ *  \copyright  Apache License, Version 2.0
  */
-#ifndef SERVICE_EVENT_H_
-#define SERVICE_EVENT_H_
+#include <stdlib.h>
+#include <stdio.h>
 
-typedef enum serviceEventType service_event_type_e;
-typedef struct serviceEvent *service_event_pt;
-
-#include "service_reference.h"
-
-enum serviceEventType
-{
-	SERVICE_EVENT_REGISTERED = 0x00000001,
-	SERVICE_EVENT_MODIFIED = 0x00000002,
-	SERVICE_EVENT_UNREGISTERING = 0x00000004,
-	SERVICE_EVENT_MODIFIED_ENDMATCH = 0x00000008,
+#include "CppUTest/TestHarness.h"
+#include "CppUTest/TestHarness_c.h"
+#include "CppUTest/CommandLineTestRunner.h"
+#include "CppUTestExt/MockSupport.h"
+
+extern "C" {
+#include "module.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(module) {
+	apr_pool_t *pool;
+
+	void setup(void) {
+		apr_initialize();
+		apr_pool_create(&pool, NULL);
+	}
+
+	void teardown() {
+		apr_pool_destroy(pool);
+		mock().checkExpectations();
+		mock().clear();
+	}
 };
 
-#include "service_reference.h"
 
-struct serviceEvent {
-	service_reference_pt reference;
-	service_event_type_e type;
-};
 
-#endif /* SERVICE_EVENT_H_ */
 
-/**
- * @}
- */

Added: incubator/celix/trunk/framework/private/test/properties_test.cpp
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/properties_test.cpp?rev=1528394&view=auto
==============================================================================
--- incubator/celix/trunk/framework/private/test/properties_test.cpp (added)
+++ incubator/celix/trunk/framework/private/test/properties_test.cpp Wed Oct  2 09:16:54 2013
@@ -0,0 +1,102 @@
+/**
+ *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.
+ */
+/*
+ * properties_test.cpp
+ *
+ *  \date       Feb 11, 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 <apr_general.h>
+#include "properties.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(properties) {
+	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(properties, create) {
+	properties_pt properties = properties_create();
+	CHECK(properties);
+}
+
+TEST(properties, load) {
+	char propertiesFile[] = "properties.txt";
+	properties_pt properties = properties_load(propertiesFile);
+	LONGS_EQUAL(2, hashMap_size(properties));
+
+	char keyA[] = "a";
+	char *valueA = properties_get(properties, keyA);
+	STRCMP_EQUAL("b", valueA);
+	char keyB[] = "b";
+	STRCMP_EQUAL("c", properties_get(properties, keyB));
+}
+
+TEST(properties, store) {
+	char propertiesFile[] = "properties_out.txt";
+	properties_pt properties = properties_create();
+	char keyA[] = "x";
+	char keyB[] = "y";
+	char valueA[] = "1";
+	char valueB[] = "2";
+	properties_set(properties, keyA, valueA);
+	properties_set(properties, keyB, valueB);
+	properties_store(properties, propertiesFile, NULL);
+}
+
+TEST(properties, getSet) {
+	properties_pt properties = properties_create();
+	char keyA[] = "x";
+	char keyB[] = "y";
+	char keyC[] = "z";
+	char valueA[] = "1";
+	char valueB[] = "2";
+	char valueC[] = "3";
+	properties_set(properties, keyA, valueA);
+	properties_set(properties, keyB, valueB);
+
+	STRCMP_EQUAL(valueA, properties_get(properties, keyA));
+	STRCMP_EQUAL(valueB, properties_get(properties, keyB));
+	STRCMP_EQUAL(valueC, properties_getWithDefault(properties, keyC, valueC));
+}
+

Added: incubator/celix/trunk/framework/private/test/requirement_test.cpp
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/requirement_test.cpp?rev=1528394&view=auto
==============================================================================
--- incubator/celix/trunk/framework/private/test/requirement_test.cpp (added)
+++ incubator/celix/trunk/framework/private/test/requirement_test.cpp Wed Oct  2 09:16:54 2013
@@ -0,0 +1,110 @@
+/**
+ *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.
+ */
+/*
+ * requirement_test.cpp
+ *
+ *  \date       Feb 11, 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 "requirement_private.h"
+}
+
+int main(int argc, char** argv) {
+	RUN_ALL_TESTS(argc, argv);
+	return 0;
+}
+
+TEST_GROUP(requirement) {
+	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(requirement, create) {
+	hash_map_pt directives = hashMap_create(NULL, NULL, NULL, NULL);
+	hash_map_pt attributes = hashMap_create(NULL, NULL, NULL, NULL);
+
+	mock().expectOneCall("attribute_getValue")
+			// .withParameter("attribute", (void *) 0x0)
+			// .andOutputParameter("value", (char *) 0x0)
+			.andReturnValue(CELIX_SUCCESS);
+
+	requirement_pt requirement = NULL;
+	requirement_create(pool, directives, attributes, &requirement);
+}
+
+TEST(requirement, getVersionRange) {
+	requirement_pt requirement = (requirement_pt) apr_palloc(pool, sizeof(*requirement));
+	version_range_pt versionRange = (version_range_pt) 0x10;
+	requirement->versionRange = versionRange;
+
+	version_range_pt actual = NULL;
+	requirement_getVersionRange(requirement, &actual);
+	POINTERS_EQUAL(versionRange, actual);
+}
+
+TEST(requirement, getTargetName) {
+	requirement_pt requirement = (requirement_pt) apr_palloc(pool, sizeof(*requirement));
+	char targetName[] = "target";
+	requirement->targetName = targetName;
+
+	char *actual = NULL;
+	requirement_getTargetName(requirement, &actual);
+	STRCMP_EQUAL(targetName, actual);
+}
+
+TEST(requirement, isSatisfied) {
+	requirement_pt requirement = (requirement_pt) apr_palloc(pool, sizeof(*requirement));
+	version_range_pt versionRange = (version_range_pt) 0x10;
+	requirement->versionRange = versionRange;
+
+	capability_pt capability = (capability_pt) 0x20;
+	version_pt version = (version_pt) 0x30;
+
+	mock().expectOneCall("capability_getVersion")
+			.withParameter("capability", capability)
+			.andOutputParameter("version", version);
+	mock().expectOneCall("versionRange_isInRange")
+		.withParameter("versionRange", versionRange)
+		.withParameter("version", version)
+		.andOutputParameter("inRange", true);
+
+	bool inRange = false;
+	requirement_isSatisfied(requirement, capability, &inRange);
+	CHECK(inRange);
+}

Copied: incubator/celix/trunk/framework/private/test/resolver_test.cpp (from r1528390, incubator/celix/trunk/framework/public/include/service_event.h)
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/resolver_test.cpp?p2=incubator/celix/trunk/framework/private/test/resolver_test.cpp&p1=incubator/celix/trunk/framework/public/include/service_event.h&r1=1528390&r2=1528394&rev=1528394&view=diff
==============================================================================
--- incubator/celix/trunk/framework/public/include/service_event.h (original)
+++ incubator/celix/trunk/framework/private/test/resolver_test.cpp Wed Oct  2 09:16:54 2013
@@ -1,4 +1,4 @@
-/*
+/**
  *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
@@ -16,41 +16,44 @@
  *specific language governing permissions and limitations
  *under the License.
  */
-/**
- *
- * @defgroup ServiceListener Service Listener
- * @ingroup framework
- * @{
+/*
+ * resolver_test.cpp
  *
- *  \author    	<a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
- *  \date      	January 11, 2012
- *  \copyright	Apache License, Version 2.0
+ *  \date       Feb 11, 2013
+ *  \author     <a href="mailto:celix-dev@incubator.apache.org">Apache Celix Project Team</a>
+ *  \copyright  Apache License, Version 2.0
  */
-#ifndef SERVICE_EVENT_H_
-#define SERVICE_EVENT_H_
+#include <stdlib.h>
+#include <stdio.h>
 
-typedef enum serviceEventType service_event_type_e;
-typedef struct serviceEvent *service_event_pt;
-
-#include "service_reference.h"
-
-enum serviceEventType
-{
-	SERVICE_EVENT_REGISTERED = 0x00000001,
-	SERVICE_EVENT_MODIFIED = 0x00000002,
-	SERVICE_EVENT_UNREGISTERING = 0x00000004,
-	SERVICE_EVENT_MODIFIED_ENDMATCH = 0x00000008,
+#include "CppUTest/TestHarness.h"
+#include "CppUTest/TestHarness_c.h"
+#include "CppUTest/CommandLineTestRunner.h"
+#include "CppUTestExt/MockSupport.h"
+
+extern "C" {
+#include "resolver.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(resolver) {
+	apr_pool_t *pool;
+
+	void setup(void) {
+		apr_initialize();
+		apr_pool_create(&pool, NULL);
+	}
+
+	void teardown() {
+		apr_pool_destroy(pool);
+		mock().checkExpectations();
+		mock().clear();
+	}
 };
 
-#include "service_reference.h"
 
-struct serviceEvent {
-	service_reference_pt reference;
-	service_event_type_e type;
-};
 
-#endif /* SERVICE_EVENT_H_ */
 
-/**
- * @}
- */

Added: incubator/celix/trunk/framework/private/test/service_reference_test.cpp
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/service_reference_test.cpp?rev=1528394&view=auto
==============================================================================
--- incubator/celix/trunk/framework/private/test/service_reference_test.cpp (added)
+++ incubator/celix/trunk/framework/private/test/service_reference_test.cpp Wed Oct  2 09:16:54 2013
@@ -0,0 +1,193 @@
+/**
+ *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_reference_test.cpp
+ *
+ *  \date       Feb 11, 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_reference_private.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(service_reference) {
+	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_reference, create) {
+	bundle_pt bundle = (bundle_pt) 0x10;
+	service_registration_pt registration = (service_registration_pt) 0x20;
+
+	service_reference_pt reference = NULL;
+	serviceReference_create(pool, bundle, registration, &reference);
+
+	POINTERS_EQUAL(bundle, reference->bundle);
+	POINTERS_EQUAL(registration, reference->registration);
+}
+
+TEST(service_reference, getBundle) {
+	service_reference_pt reference = (service_reference_pt) apr_palloc(pool, sizeof(*reference));
+	bundle_pt bundle = (bundle_pt) 0x10;
+	reference->bundle = bundle;
+
+	bundle_pt actual = NULL;
+	celix_status_t status = serviceReference_getBundle(reference, &actual);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(bundle, actual);
+}
+
+TEST(service_reference, getServiceRegistration) {
+	service_reference_pt reference = (service_reference_pt) apr_palloc(pool, sizeof(*reference));
+	service_registration_pt registration = (service_registration_pt) 0x10;
+	reference->registration = registration;
+
+	service_registration_pt actual = NULL;
+	celix_status_t status = serviceReference_getServiceRegistration(reference, &actual);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(registration, actual);
+}
+
+TEST(service_reference, invalidate) {
+	service_reference_pt reference = (service_reference_pt) apr_palloc(pool, sizeof(*reference));
+	service_registration_pt registration = (service_registration_pt) 0x10;
+	reference->registration = registration;
+
+	celix_status_t status = serviceReference_invalidate(reference);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(NULL, reference->registration);
+}
+
+TEST(service_reference, getUsingBundle) {
+	service_reference_pt reference = (service_reference_pt) apr_palloc(pool, sizeof(*reference));
+	service_registration_pt registration = (service_registration_pt) 0x10;
+	reference->registration = registration;
+
+	service_registry_pt registry = (service_registry_pt) 0x20;
+
+	array_list_pt bundles = NULL;
+	arrayList_create(pool, &bundles);
+	bundle_pt bundle = (bundle_pt) 0x30;
+	arrayList_add(bundles, bundle);
+
+	mock().expectOneCall("serviceRegistration_getRegistry")
+		.withParameter("registration", registration)
+		.andOutputParameter("registry", registry);
+	mock().expectOneCall("serviceRegistry_getUsingBundles")
+		.withParameter("registry", registry)
+		.withParameter("pool", pool)
+		.withParameter("reference", reference)
+		.andReturnValue(bundles);
+
+	array_list_pt actual = NULL;
+	celix_status_t status = serviceReference_getUsingBundles(reference, pool, &actual);
+	POINTERS_EQUAL(bundles, actual);
+	LONGS_EQUAL(1, arrayList_size(actual));
+	POINTERS_EQUAL(bundle, arrayList_get(actual, 0));
+}
+
+TEST(service_reference, equals) {
+	service_reference_pt reference = (service_reference_pt) apr_palloc(pool, sizeof(*reference));
+	service_registration_pt registration = (service_registration_pt) 0x10;
+	reference->registration = registration;
+	bundle_pt bundle = (bundle_pt) 0x20;
+	reference->bundle = bundle;
+
+	service_reference_pt toCompare = (service_reference_pt) apr_palloc(pool, sizeof(*reference));
+	registration = (service_registration_pt) 0x10;
+	toCompare->registration = registration;
+	bundle = (bundle_pt) 0x30;
+	toCompare->bundle = bundle;
+
+	bool equal = false;
+	celix_status_t status = serviceReference_equals(reference, toCompare, &equal);
+	LONGS_EQUAL(CELIX_SUCCESS, status)
+	LONGS_EQUAL(true, equal);
+
+	toCompare = (service_reference_pt) apr_palloc(pool, sizeof(*reference));
+	registration = (service_registration_pt) 0x11;
+	toCompare->registration = registration;
+	bundle = (bundle_pt) 0x30;
+	toCompare->bundle = bundle;
+
+	equal = true;
+	status = serviceReference_equals(reference, toCompare, &equal);
+	LONGS_EQUAL(CELIX_SUCCESS, status)
+	LONGS_EQUAL(false, equal);
+}
+
+TEST(service_reference, equals2) {
+	service_reference_pt reference = (service_reference_pt) apr_palloc(pool, sizeof(*reference));
+	service_registration_pt registration = (service_registration_pt) 0x10;
+	reference->registration = registration;
+	bundle_pt bundle = (bundle_pt) 0x20;
+	reference->bundle = bundle;
+
+	service_reference_pt toCompare = (service_reference_pt) apr_palloc(pool, sizeof(*reference));
+	registration = (service_registration_pt) 0x10;
+	toCompare->registration = registration;
+	bundle = (bundle_pt) 0x30;
+	toCompare->bundle = bundle;
+
+	bool equal = serviceReference_equals2(reference, toCompare);
+	LONGS_EQUAL(true, equal);
+
+	toCompare = (service_reference_pt) apr_palloc(pool, sizeof(*reference));
+	registration = (service_registration_pt) 0x11;
+	toCompare->registration = registration;
+	bundle = (bundle_pt) 0x30;
+	toCompare->bundle = bundle;
+
+	equal = serviceReference_equals2(reference, toCompare);
+	LONGS_EQUAL(false, equal);
+}
+
+TEST(service_reference, hashCode) {
+	service_reference_pt reference = (service_reference_pt) apr_palloc(pool, sizeof(*reference));
+	service_registration_pt registration = (service_registration_pt) 0x10;
+	reference->registration = registration;
+	bundle_pt bundle = (bundle_pt) 0x20;
+	reference->bundle = bundle;
+
+	unsigned int hash = serviceReference_hashCode(reference);
+	LONGS_EQUAL(79, hash);
+}

Added: incubator/celix/trunk/framework/private/test/service_registration_test.cpp
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/service_registration_test.cpp?rev=1528394&view=auto
==============================================================================
--- incubator/celix/trunk/framework/private/test/service_registration_test.cpp (added)
+++ incubator/celix/trunk/framework/private/test/service_registration_test.cpp Wed Oct  2 09:16:54 2013
@@ -0,0 +1,332 @@
+/**
+ *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_registration_test.cpp
+ *
+ *  \date       Feb 8, 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_registration_private.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(service_registration) {
+	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_registration, create) {
+	service_registry_pt registry = (service_registry_pt) 0x10;
+	bundle_pt bundle = (bundle_pt) 0x20;
+	std::string serviceName = "service";
+	long serviceId = 1l;
+	void *service = (void *) 0x30;
+	properties_pt properties = (properties_pt) 0x40;
+
+	mock().expectOneCall("properties_create")
+		.andReturnValue(properties);
+	mock().expectOneCall("properties_set")
+		.withParameter("properties", properties)
+		.withParameter("key", "service.id")
+		.withParameter("value", "1")
+		.andReturnValue((char *) NULL);
+	mock().expectOneCall("properties_set")
+		.withParameter("properties", properties)
+		.withParameter("key", "objectClass")
+		.withParameter("value", "service")
+		.andReturnValue((char *) NULL);
+
+	service_registration_pt registration = serviceRegistration_create(pool, registry, bundle, (char *) serviceName.c_str(), serviceId, service, NULL);
+
+	POINTERS_EQUAL(registry, registration->registry);
+	STRCMP_EQUAL("service", registration->className);
+	CHECK(registration->references);
+	LONGS_EQUAL(0, arrayList_size(registration->references));
+	POINTERS_EQUAL(bundle, registration->bundle);
+	POINTERS_EQUAL(properties, registration->properties);
+	POINTERS_EQUAL(service, registration->svcObj);
+	LONGS_EQUAL(serviceId, registration->serviceId);
+	CHECK(registration->mutex);
+	LONGS_EQUAL(0, registration->isUnregistering);
+	LONGS_EQUAL(0, registration->isServiceFactory);
+	POINTERS_EQUAL(NULL, registration->serviceFactory);
+	POINTERS_EQUAL(NULL, registration->services);
+	LONGS_EQUAL(0, registration->nrOfServices);
+}
+
+TEST(service_registration, createServiceFactory) {
+	service_registry_pt registry = (service_registry_pt) 0x10;
+	bundle_pt bundle = (bundle_pt) 0x20;
+	std::string serviceName = "service";
+	long serviceId = 1l;
+	void *service = (void *) 0x30;
+	properties_pt properties = (properties_pt) 0x40;
+
+	mock().expectOneCall("properties_create")
+		.andReturnValue(properties);
+	mock().expectOneCall("properties_set")
+		.withParameter("properties", properties)
+		.withParameter("key", "service.id")
+		.withParameter("value", "1")
+		.andReturnValue((char *) NULL);
+	mock().expectOneCall("properties_set")
+		.withParameter("properties", properties)
+		.withParameter("key", "objectClass")
+		.withParameter("value", "service")
+		.andReturnValue((char *) NULL);
+
+	service_registration_pt registration = serviceRegistration_createServiceFactory(pool, registry, bundle, (char *) serviceName.c_str(), serviceId, service, NULL);
+
+	POINTERS_EQUAL(registry, registration->registry);
+	STRCMP_EQUAL("service", registration->className);
+	CHECK(registration->references);
+	LONGS_EQUAL(0, arrayList_size(registration->references));
+	POINTERS_EQUAL(bundle, registration->bundle);
+	POINTERS_EQUAL(properties, registration->properties);
+	POINTERS_EQUAL(service, registration->svcObj);
+	LONGS_EQUAL(serviceId, registration->serviceId);
+	CHECK(registration->mutex);
+	LONGS_EQUAL(0, registration->isUnregistering);
+	LONGS_EQUAL(1, registration->isServiceFactory);
+	POINTERS_EQUAL(service, registration->serviceFactory);
+	POINTERS_EQUAL(NULL, registration->services);
+	LONGS_EQUAL(0, registration->nrOfServices);
+}
+
+TEST(service_registration, isValidTrue) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	void *service = (void *) 0x30;
+	registration->svcObj = service;
+
+	bool valid = serviceRegistration_isValid(registration);
+
+	LONGS_EQUAL(1, valid);
+}
+
+TEST(service_registration, isValidFalse) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	registration->svcObj = NULL;
+
+	bool valid = serviceRegistration_isValid(registration);
+
+	LONGS_EQUAL(0, valid);
+}
+
+TEST(service_registration, invalidate) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	apr_thread_mutex_create(&registration->mutex, 0, pool);
+	void *service = (void *) 0x30;
+	registration->svcObj = service;
+
+	serviceRegistration_invalidate(registration);
+
+	POINTERS_EQUAL(NULL, registration->svcObj);
+}
+
+TEST(service_registration, unregisterValid) {
+	service_registry_pt registry = (service_registry_pt) 0x10;
+	bundle_pt bundle = (bundle_pt) 0x20;
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	registration->registry = registry;
+	registration->bundle = bundle;
+	apr_thread_mutex_create(&registration->mutex, 0, pool);
+	void *service = (void *) 0x30;
+	registration->svcObj = service;
+
+	mock().expectOneCall("serviceRegistry_unregisterService")
+		.withParameter("registry", registry)
+		.withParameter("bundle", bundle)
+		.withParameter("registration", registration);
+
+	celix_status_t status = serviceRegistration_unregister(registration);
+
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	LONGS_EQUAL(1, registration->isUnregistering);
+}
+
+TEST(service_registration, unregisterInvalid) {
+	service_registry_pt registry = (service_registry_pt) 0x10;
+	bundle_pt bundle = (bundle_pt) 0x20;
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	registration->registry = registry;
+	registration->bundle = bundle;
+	apr_thread_mutex_create(&registration->mutex, 0, pool);
+	registration->svcObj = NULL;
+
+	celix_status_t status = serviceRegistration_unregister(registration);
+	LONGS_EQUAL(CELIX_ILLEGAL_STATE, status);
+}
+
+TEST(service_registration, getService) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	bundle_pt bundle = (bundle_pt) 0x10;
+	registration->bundle = bundle;
+	void *service = (void *) 0x20;
+	registration->svcObj = service;
+	registration->isServiceFactory = false;
+
+	void *actual = NULL;
+	celix_status_t status = serviceRegistration_getService(registration, bundle, &actual);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(service, actual);
+}
+
+celix_status_t serviceRegistrationTest_getService(void *factory, bundle_pt bundle, service_registration_pt registration, void **service) {
+	*service = (void *) 0x20;
+	return CELIX_SUCCESS;
+}
+
+TEST(service_registration, getServiceFromFactory) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	bundle_pt bundle = (bundle_pt) 0x10;
+	registration->bundle = bundle;
+	service_factory_pt factory = (service_factory_pt) apr_palloc(pool, sizeof(*factory));
+	factory->getService = serviceRegistrationTest_getService;
+	registration->svcObj = factory;
+	registration->serviceFactory = factory;
+	registration->isServiceFactory = true;
+
+	void *actual = NULL;
+	celix_status_t status = serviceRegistration_getService(registration, bundle, &actual);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(0x20, actual);
+}
+
+TEST(service_registration, getProperties) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	properties_pt properties = (properties_pt) 0x10;
+	registration->properties = properties;
+
+	properties_pt actual = NULL;
+	celix_status_t status = serviceRegistration_getProperties(registration, &actual);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(properties, actual);
+}
+
+TEST(service_registration, getPropertiesIllegalArgument) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	registration->properties = NULL;
+
+	properties_pt actual = (properties_pt) 0x01;
+	celix_status_t status = serviceRegistration_getProperties(registration, &actual);
+	LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
+}
+
+TEST(service_registration, getRegistry) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	service_registry_pt registry = (service_registry_pt) 0x10;
+	registration->registry = registry;
+
+	service_registry_pt actual = NULL;
+	celix_status_t status = serviceRegistration_getRegistry(registration, &actual);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(registry, actual);
+}
+
+TEST(service_registration, getRegistryIllegalArgument) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	registration->registry = NULL;
+
+	service_registry_pt actual = (service_registry_pt) 0x01;
+	celix_status_t status = serviceRegistration_getRegistry(registration, &actual);
+	LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
+}
+
+TEST(service_registration, getServiceReferences) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	array_list_pt references = (array_list_pt) 0x10;
+	registration->references = references;
+
+	array_list_pt actual = NULL;
+	celix_status_t status = serviceRegistration_getServiceReferences(registration, &actual);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(references, actual);
+}
+
+TEST(service_registration, getServiceReferencesIllegalArgument) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	registration->registry = NULL;
+
+	array_list_pt actual = (array_list_pt) 0x01;
+	celix_status_t status = serviceRegistration_getServiceReferences(registration, &actual);
+	LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
+}
+
+TEST(service_registration, getServiceName) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	std::string serviceName = "service";
+	registration->className = (char *) serviceName.c_str();
+
+	char *actual = NULL;
+	celix_status_t status = serviceRegistration_getServiceName(registration, &actual);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	STRCMP_EQUAL("service", actual);
+}
+
+TEST(service_registration, getServiceNameIllegalArgument) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	registration->className = NULL;
+
+	char *actual = (char *) 0x01;
+	celix_status_t status = serviceRegistration_getServiceName(registration, &actual);
+	LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
+}
+
+TEST(service_registration, getBundle) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	bundle_pt bundle = (bundle_pt) 0x10;
+	registration->bundle = bundle;
+
+	bundle_pt actual = NULL;
+	celix_status_t status = serviceRegistration_getBundle(registration, &actual);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(bundle, actual);
+}
+
+TEST(service_registration, getBundleIllegalArgument) {
+	service_registration_pt registration = (service_registration_pt) apr_palloc(pool, sizeof(*registration));
+	registration->bundle = NULL;
+
+	bundle_pt actual = (bundle_pt) 0x01;
+	celix_status_t status = serviceRegistration_getBundle(registration, &actual);
+	LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
+}

Added: incubator/celix/trunk/framework/private/test/service_registry_test.cpp
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/service_registry_test.cpp?rev=1528394&view=auto
==============================================================================
--- incubator/celix/trunk/framework/private/test/service_registry_test.cpp (added)
+++ incubator/celix/trunk/framework/private/test/service_registry_test.cpp Wed Oct  2 09:16:54 2013
@@ -0,0 +1,681 @@
+/**
+ *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_registry_test.c
+ *
+ *  \date       Feb 7, 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_registry_private.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(service_registry) {
+	apr_pool_t *pool;
+
+	void setup(void) {
+		apr_initialize();
+		apr_pool_create(&pool, NULL);
+	}
+
+	void teardown() {
+		apr_pool_destroy(pool);
+		mock().checkExpectations();
+		mock().clear();
+	}
+};
+
+extern "C" {
+void serviceRegistryTest_serviceChanged(framework_pt framework, service_event_type_e eventType, service_registration_pt registration, properties_pt oldprops) {
+}
+}
+
+TEST(service_registry, create) {
+	framework_pt framework = (framework_pt) 0x10;
+	service_registry_pt registry = NULL;
+
+	mock()
+		.expectOneCall("framework_getMemoryPool")
+		.withParameter("framework", framework)
+		.andOutputParameter("pool", pool)
+		.andReturnValue(CELIX_SUCCESS);
+
+	serviceRegistry_create(pool, framework, serviceRegistryTest_serviceChanged, &registry);
+
+	POINTERS_EQUAL(framework, registry->framework);
+	POINTERS_EQUAL(serviceRegistryTest_serviceChanged, registry->serviceChanged);
+	LONGS_EQUAL(1l, registry->currentServiceId);
+	CHECK(registry->inUseMap != NULL);
+	CHECK(registry->listenerHooks != NULL);
+	CHECK(registry->mutex != NULL);
+	CHECK(registry->serviceReferences == NULL);
+	CHECK(registry->serviceRegistrations != NULL);
+}
+
+TEST(service_registry, getRegisteredServices) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
+
+	array_list_pt registrations = NULL;
+	arrayList_create(pool, &registrations);
+	service_registration_pt reg = (service_registration_pt) 0x10;
+	arrayList_add(registrations, reg);
+	bundle_pt bundle = (bundle_pt) 0x20;
+	hashMap_put(registry->serviceRegistrations, bundle, registrations);
+
+	service_reference_pt ref = (service_reference_pt) 0x30;
+
+	array_list_pt refs = NULL;
+	arrayList_create(pool, &refs);
+
+	mock()
+		.expectOneCall("serviceRegistration_isValid")
+		.withParameter("registration", reg)
+		.andReturnValue(true);
+	mock()
+		.expectOneCall("serviceRegistration_getBundle")
+		.withParameter("registration", reg)
+		.andOutputParameter("bundle", bundle)
+		.andReturnValue(CELIX_SUCCESS)
+		.ignoreOtherParameters();
+	mock()
+		.expectOneCall("serviceReference_create")
+		.withParameter("bundle", bundle)
+		.withParameter("registration", reg)
+		.andOutputParameter("reference", ref)
+		.andReturnValue(CELIX_SUCCESS)
+		.ignoreOtherParameters();
+	mock()
+		.expectOneCall("serviceRegistration_getServiceReferences")
+		.withParameter("registration", reg)
+		.andOutputParameter("references", refs)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceReference_getServiceRegistration")
+		.withParameter("reference", ref)
+		.andOutputParameter("registration", reg)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_getServiceReferences")
+		.withParameter("registration", reg)
+		.andOutputParameter("references", refs)
+		.andReturnValue(CELIX_SUCCESS);
+
+	array_list_pt services = NULL;
+	serviceRegistry_getRegisteredServices(registry, pool, bundle, &services);
+	LONGS_EQUAL(1, arrayList_size(services));
+	POINTERS_EQUAL(ref, arrayList_get(services, 0));
+}
+
+TEST(service_registry, getServicesInUse) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+
+	array_list_pt usages = NULL;
+	arrayList_create(pool, &usages);
+	bundle_pt bundle = (bundle_pt) 0x10;
+	service_reference_pt ref = (service_reference_pt) 0x20;
+	usage_count_pt usage = (usage_count_pt) apr_palloc(pool, sizeof(*usage));
+	usage->reference = ref;
+	arrayList_add(usages, usage);
+	hashMap_put(registry->inUseMap, bundle, usages);
+
+	mock()
+		.expectOneCall("bundle_getMemoryPool")
+		.withParameter("bundle", bundle)
+		.andOutputParameter("pool", pool)
+		.andReturnValue(CELIX_SUCCESS);
+
+	array_list_pt inUse = NULL;
+	serviceRegistry_getServicesInUse(registry, bundle, &inUse);
+	LONGS_EQUAL(1, arrayList_size(inUse));
+	POINTERS_EQUAL(ref, arrayList_get(inUse, 0));
+}
+
+TEST(service_registry, registerServiceNoProps) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+	apr_thread_mutex_create(&registry->mutex, APR_THREAD_MUTEX_NESTED, pool);
+	registry->currentServiceId = 1l;
+	registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
+
+	bundle_pt bundle = (bundle_pt) 0x10;
+	std::string serviceName = "service";
+	void *service = (void *) 0x20;
+	service_registration_pt reg = (service_registration_pt) 0x30;
+
+	mock()
+		.expectOneCall("bundle_getMemoryPool")
+		.withParameter("bundle", bundle)
+		.andOutputParameter("pool", pool)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_create")
+		.withParameter("pool", pool)
+		.withParameter("registry", registry)
+		.withParameter("bundle", bundle)
+		.withParameter("serviceName", (char *) serviceName.c_str())
+		.withParameter("serviceId", 2)
+		.withParameter("serviceObject", service)
+		.withParameter("dictionary", (void *) NULL)
+		.andReturnValue(reg);
+
+	service_registration_pt registration = NULL;
+	serviceRegistry_registerService(registry, bundle, (char *) serviceName.c_str(), service, NULL, &registration);
+	POINTERS_EQUAL(reg, registration);
+}
+
+TEST(service_registry, registerServiceFactoryNoProps) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+	apr_thread_mutex_create(&registry->mutex, APR_THREAD_MUTEX_NESTED, pool);
+	registry->currentServiceId = 1l;
+	registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
+
+	bundle_pt bundle = (bundle_pt) 0x10;
+	std::string serviceName = "service";
+	service_factory_pt factory = (service_factory_pt) 0x20;
+	service_registration_pt reg = (service_registration_pt) 0x30;
+
+	mock()
+		.expectOneCall("bundle_getMemoryPool")
+		.withParameter("bundle", bundle)
+		.andOutputParameter("pool", pool)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_createServiceFactory")
+		.withParameter("pool", pool)
+		.withParameter("registry", registry)
+		.withParameter("bundle", bundle)
+		.withParameter("serviceName", (char *) serviceName.c_str())
+		.withParameter("serviceId", 2)
+		.withParameter("serviceObject", factory)
+		.withParameter("dictionary", (void *) NULL)
+		.andReturnValue(reg);
+
+	service_registration_pt registration = NULL;
+	serviceRegistry_registerServiceFactory(registry, bundle, (char *) serviceName.c_str(), factory, NULL, &registration);
+	POINTERS_EQUAL(reg, registration);
+}
+
+TEST(service_registry, unregisterService) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+	apr_thread_mutex_create(&registry->mutex, APR_THREAD_MUTEX_NESTED, pool);
+	registry->currentServiceId = 1l;
+	registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
+
+	bundle_pt bundle = (bundle_pt) 0x10;
+	service_registration_pt registration = (service_registration_pt) 0x20;
+	array_list_pt registrations = NULL;
+	arrayList_create(pool, &registrations);
+	arrayList_add(registrations, registration);
+
+	hashMap_put(registry->serviceRegistrations, bundle, registrations);
+
+	properties_pt properties = (properties_pt) 0x30;
+
+	array_list_pt references = NULL;
+	arrayList_create(pool, &references);
+	service_reference_pt reference = (service_reference_pt) 0x40;
+	arrayList_add(references, reference);
+
+	framework_pt framework = (framework_pt) 0x50;
+	registry->framework = framework;
+
+	mock()
+		.expectOneCall("serviceRegistration_getProperties")
+		.withParameter("registration", registration)
+		.andOutputParameter("properties", properties)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("properties_get")
+		.withParameter("properties", properties)
+		.withParameter("key", "objectClass")
+		.andReturnValue("test");
+	mock()
+		.expectOneCall("serviceRegistration_getServiceReferences")
+		.withParameter("registration", registration)
+		.andOutputParameter("references", references)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("framework_getMemoryPool")
+		.withParameter("framework", framework)
+		.andOutputParameter("pool", pool)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceReference_invalidate")
+		.withParameter("reference", reference)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_invalidate")
+		.withParameter("registration", registration)
+		.andReturnValue(CELIX_SUCCESS);
+
+	serviceRegistry_unregisterService(registry, bundle, registration);
+}
+
+TEST(service_registry, unregisterServices) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+	apr_thread_mutex_create(&registry->mutex, APR_THREAD_MUTEX_NESTED, pool);
+	registry->currentServiceId = 1l;
+	registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
+
+	bundle_pt bundle = (bundle_pt) 0x10;
+	service_registration_pt registration = (service_registration_pt) 0x20;
+	array_list_pt registrations = NULL;
+	arrayList_create(pool, &registrations);
+	arrayList_add(registrations, registration);
+
+	hashMap_put(registry->serviceRegistrations, bundle, registrations);
+
+	mock()
+		.expectOneCall("serviceRegistration_isValid")
+		.withParameter("registration", registration)
+		.andReturnValue(true);
+	mock()
+		.expectOneCall("serviceRegistration_unregister")
+		.withParameter("registration", registration)
+		.andReturnValue(CELIX_SUCCESS);
+	serviceRegistry_unregisterServices(registry, bundle);
+	LONGS_EQUAL(0, hashMap_size(registry->serviceRegistrations));
+}
+
+TEST(service_registry, getServiceReferences) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+	apr_thread_mutex_create(&registry->mutex, APR_THREAD_MUTEX_NESTED, pool);
+	registry->currentServiceId = 1l;
+	registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
+
+	bundle_pt bundle = (bundle_pt) 0x10;
+	service_registration_pt registration = (service_registration_pt) 0x20;
+	array_list_pt registrations = NULL;
+	arrayList_create(pool, &registrations);
+	arrayList_add(registrations, registration);
+
+	hashMap_put(registry->serviceRegistrations, bundle, registrations);
+
+	properties_pt properties = (properties_pt) 0x30;
+	array_list_pt references = NULL;
+	arrayList_create(pool, &references);
+	service_reference_pt reference = (service_reference_pt) 0x40;
+	arrayList_add(references, reference);
+
+	mock()
+		.expectOneCall("serviceRegistration_getProperties")
+		.withParameter("registration", registration)
+		.andOutputParameter("properties", properties)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_getServiceName")
+		.withParameter("registration", registration)
+		.andOutputParameter("serviceName", "test")
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_isValid")
+		.withParameter("registration", registration)
+		.andReturnValue(true);
+	mock()
+		.expectOneCall("serviceRegistration_getBundle")
+		.withParameter("registration", registration)
+		.andOutputParameter("bundle", bundle)
+		.andReturnValue(CELIX_SUCCESS)
+		.ignoreOtherParameters();
+	mock()
+		.expectOneCall("serviceReference_create")
+		.withParameter("bundle", bundle)
+		.withParameter("registration", registration)
+		.andOutputParameter("reference", reference)
+		.andReturnValue(CELIX_SUCCESS)
+		.ignoreOtherParameters();
+	mock()
+		.expectOneCall("serviceRegistration_getServiceReferences")
+		.withParameter("registration", registration)
+		.andOutputParameter("references", references)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceReference_getServiceRegistration")
+		.withParameter("reference", reference)
+		.andOutputParameter("registration", registration)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_getServiceReferences")
+		.withParameter("registration", registration)
+		.andOutputParameter("references", references)
+		.andReturnValue(CELIX_SUCCESS);
+
+	array_list_pt actual  = NULL;
+	serviceRegistry_getServiceReferences(registry, pool, "test", NULL, &actual);
+	LONGS_EQUAL(1, arrayList_size(actual));
+	POINTERS_EQUAL(reference, arrayList_get(actual, 0));
+}
+
+TEST(service_registry, getService) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+	apr_thread_mutex_create(&registry->mutex, APR_THREAD_MUTEX_NESTED, pool);
+	registry->currentServiceId = 1l;
+	registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
+
+	bundle_pt bundle = (bundle_pt) 0x10;
+	service_registration_pt registration = (service_registration_pt) 0x20;
+	array_list_pt registrations = NULL;
+	arrayList_create(pool, &registrations);
+	arrayList_add(registrations, registration);
+
+	hashMap_put(registry->serviceRegistrations, bundle, registrations);
+
+	properties_pt properties = (properties_pt) 0x30;
+	array_list_pt references = NULL;
+	arrayList_create(pool, &references);
+	service_reference_pt reference = (service_reference_pt) 0x40;
+	arrayList_add(references, reference);
+
+	module_pt module = (module_pt) 0x50;
+
+	void * service = (void *) 0x60;
+
+	mock()
+		.expectOneCall("serviceReference_getServiceRegistration")
+		.withParameter("reference", reference)
+		.andOutputParameter("registration", registration)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_isValid")
+		.withParameter("registration", registration)
+		.andReturnValue(true);
+	mock()
+		.expectOneCall("bundle_getMemoryPool")
+		.withParameter("bundle", bundle)
+		.andOutputParameter("pool", pool)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("bundle_getCurrentModule")
+		.withParameter("bundle", bundle)
+		.andOutputParameter("module", module)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_getService")
+		.withParameter("registration", registration)
+		.withParameter("bundle", bundle)
+		.andOutputParameter("service", service)
+		.andReturnValue(true);
+	mock()
+		.expectOneCall("serviceRegistration_isValid")
+		.withParameter("registration", registration)
+		.andReturnValue(true);
+
+	void *actual = NULL;
+	serviceRegistry_getService(registry, bundle, reference, &actual);
+	POINTERS_EQUAL(service, actual);
+}
+
+TEST(service_registry, ungetService) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+	apr_thread_mutex_create(&registry->mutex, APR_THREAD_MUTEX_NESTED, pool);
+	registry->currentServiceId = 1l;
+	registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
+
+	bundle_pt bundle = (bundle_pt) 0x10;
+	service_registration_pt registration = (service_registration_pt) 0x20;
+	array_list_pt registrations = NULL;
+	arrayList_create(pool, &registrations);
+	arrayList_add(registrations, registration);
+
+	hashMap_put(registry->serviceRegistrations, bundle, registrations);
+
+	properties_pt properties = (properties_pt) 0x30;
+	array_list_pt references = NULL;
+	arrayList_create(pool, &references);
+	service_reference_pt reference = (service_reference_pt) 0x40;
+	arrayList_add(references, reference);
+
+	array_list_pt usages = NULL;
+	arrayList_create(pool, &usages);
+	usage_count_pt usage = (usage_count_pt) malloc(sizeof(*usage));
+	usage->reference = reference;
+	arrayList_add(usages, usage);
+	hashMap_put(registry->inUseMap, bundle, usages);
+
+	mock()
+		.expectOneCall("serviceReference_getServiceRegistration")
+		.withParameter("reference", reference)
+		.andOutputParameter("registration", registration)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_isValid")
+		.withParameter("registration", registration)
+		.andReturnValue(true);
+
+	bool result = false;
+	serviceRegistry_ungetService(registry, bundle, reference, &result);
+	LONGS_EQUAL(1, result);
+}
+
+TEST(service_registry, ungetServivces) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+	apr_thread_mutex_create(&registry->mutex, APR_THREAD_MUTEX_NESTED, pool);
+	registry->currentServiceId = 1l;
+	registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
+
+	bundle_pt bundle = (bundle_pt) 0x10;
+	service_registration_pt registration = (service_registration_pt) 0x20;
+	array_list_pt registrations = NULL;
+	arrayList_create(pool, &registrations);
+	arrayList_add(registrations, registration);
+
+	hashMap_put(registry->serviceRegistrations, bundle, registrations);
+
+	properties_pt properties = (properties_pt) 0x30;
+	array_list_pt references = NULL;
+	arrayList_create(pool, &references);
+	service_reference_pt reference = (service_reference_pt) 0x40;
+	arrayList_add(references, reference);
+
+	array_list_pt usages = NULL;
+	arrayList_create(pool, &usages);
+	usage_count_pt usage = (usage_count_pt) malloc(sizeof(*usage));
+	usage->reference = reference;
+	arrayList_add(usages, usage);
+	hashMap_put(registry->inUseMap, bundle, usages);
+
+	mock()
+		.expectOneCall("bundle_getMemoryPool")
+		.withParameter("bundle", bundle)
+		.andOutputParameter("pool", pool)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceReference_getServiceRegistration")
+		.withParameter("reference", reference)
+		.andOutputParameter("registration", registration)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_isValid")
+		.withParameter("registration", registration)
+		.andReturnValue(true);
+	mock()
+		.expectOneCall("serviceReference_getServiceRegistration")
+		.withParameter("reference", reference)
+		.andOutputParameter("registration", registration)
+		.andReturnValue(CELIX_SUCCESS);
+
+	serviceRegistry_ungetServices(registry, bundle);
+}
+
+TEST(service_registry, getUsingBundles) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+	apr_thread_mutex_create(&registry->mutex, APR_THREAD_MUTEX_NESTED, pool);
+	registry->currentServiceId = 1l;
+	registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
+
+	bundle_pt bundle = (bundle_pt) 0x10;
+	service_registration_pt registration = (service_registration_pt) 0x20;
+	array_list_pt registrations = NULL;
+	arrayList_create(pool, &registrations);
+	arrayList_add(registrations, registration);
+
+	hashMap_put(registry->serviceRegistrations, bundle, registrations);
+
+	properties_pt properties = (properties_pt) 0x30;
+	array_list_pt references = NULL;
+	arrayList_create(pool, &references);
+	service_reference_pt reference = (service_reference_pt) 0x40;
+	arrayList_add(references, reference);
+
+	array_list_pt usages = NULL;
+	arrayList_create(pool, &usages);
+	usage_count_pt usage = (usage_count_pt) malloc(sizeof(*usage));
+	usage->reference = reference;
+	arrayList_add(usages, usage);
+	hashMap_put(registry->inUseMap, bundle, usages);
+
+	array_list_pt actual = serviceRegistry_getUsingBundles(registry, pool, reference);
+	LONGS_EQUAL(1, arrayList_size(actual));
+	POINTERS_EQUAL(bundle, arrayList_get(actual, 0));
+}
+
+TEST(service_registry, createServiceReference) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL);
+	apr_thread_mutex_create(&registry->mutex, APR_THREAD_MUTEX_NESTED, pool);
+	registry->currentServiceId = 1l;
+	registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL);
+
+	bundle_pt bundle = (bundle_pt) 0x10;
+	service_registration_pt registration = (service_registration_pt) 0x20;
+//	array_list_pt registrations = NULL;
+//	arrayList_create(pool, &registrations);
+//	arrayList_add(registrations, registration);
+//
+//	hashMap_put(registry->serviceRegistrations, bundle, registrations);
+
+	array_list_pt references = NULL;
+	arrayList_create(pool, &references);
+	service_reference_pt reference = (service_reference_pt) 0x40;
+	arrayList_add(references, reference);
+
+	mock()
+		.expectOneCall("serviceRegistration_getBundle")
+		.withParameter("registration", registration)
+		.andOutputParameter("bundle", bundle)
+		.andReturnValue(CELIX_SUCCESS)
+		.ignoreOtherParameters();
+	mock()
+		.expectOneCall("serviceReference_create")
+		.withParameter("bundle", bundle)
+		.withParameter("registration", registration)
+		.andOutputParameter("reference", reference)
+		.andReturnValue(CELIX_SUCCESS)
+		.ignoreOtherParameters();
+	mock()
+		.expectOneCall("serviceRegistration_getServiceReferences")
+		.withParameter("registration", registration)
+		.andOutputParameter("references", references)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceReference_getServiceRegistration")
+		.withParameter("reference", reference)
+		.andOutputParameter("registration", registration)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_getServiceReferences")
+		.withParameter("registration", registration)
+		.andOutputParameter("references", references)
+		.andReturnValue(CELIX_SUCCESS);
+
+	service_reference_pt actual  = NULL;
+	serviceRegistry_createServiceReference(registry, pool, registration, &actual);
+	POINTERS_EQUAL(reference, actual);
+}
+
+TEST(service_registry, getListenerHooks) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	registry->listenerHooks = NULL;
+	arrayList_create(pool, &registry->listenerHooks);
+
+	bundle_pt bundle = (bundle_pt) 0x10;
+	service_registration_pt registration = (service_registration_pt) 0x20;
+	arrayList_add(registry->listenerHooks, registration);
+
+	array_list_pt references = NULL;
+	arrayList_create(pool, &references);
+	service_reference_pt reference = (service_reference_pt) 0x40;
+	arrayList_add(references, reference);
+
+	mock()
+		.expectOneCall("serviceRegistration_getBundle")
+		.withParameter("registration", registration)
+		.andOutputParameter("bundle", bundle)
+		.andReturnValue(CELIX_SUCCESS)
+		.ignoreOtherParameters();
+	mock()
+		.expectOneCall("serviceReference_create")
+		.withParameter("bundle", bundle)
+		.withParameter("registration", registration)
+		.andOutputParameter("reference", reference)
+		.andReturnValue(CELIX_SUCCESS)
+		.ignoreOtherParameters();
+	mock()
+		.expectOneCall("serviceRegistration_getServiceReferences")
+		.withParameter("registration", registration)
+		.andOutputParameter("references", references)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceReference_getServiceRegistration")
+		.withParameter("reference", reference)
+		.andOutputParameter("registration", registration)
+		.andReturnValue(CELIX_SUCCESS);
+	mock()
+		.expectOneCall("serviceRegistration_getServiceReferences")
+		.withParameter("registration", registration)
+		.andOutputParameter("references", references)
+		.andReturnValue(CELIX_SUCCESS);
+
+	array_list_pt hooks = NULL;
+	celix_status_t status = serviceRegistry_getListenerHooks(registry, pool, &hooks);
+	LONGS_EQUAL(1, arrayList_size(hooks));
+	POINTERS_EQUAL(reference, arrayList_get(hooks, 0));
+}
+
+TEST(service_registry, servicePropertiesModified) {
+	service_registry_pt registry = (service_registry_pt) apr_palloc(pool, sizeof(*registry));
+	service_registration_pt registration = (service_registration_pt) 0x10;
+	properties_pt properties = (properties_pt) 0x20;
+
+	serviceRegistry_servicePropertiesModified(registry, registration, properties);
+}
+

Added: incubator/celix/trunk/framework/private/test/service_tracker_customizer_test.cpp
URL: http://svn.apache.org/viewvc/incubator/celix/trunk/framework/private/test/service_tracker_customizer_test.cpp?rev=1528394&view=auto
==============================================================================
--- incubator/celix/trunk/framework/private/test/service_tracker_customizer_test.cpp (added)
+++ incubator/celix/trunk/framework/private/test/service_tracker_customizer_test.cpp Wed Oct  2 09:16:54 2013
@@ -0,0 +1,160 @@
+/**
+ *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_customizer_test.cpp
+ *
+ *  \date       Feb 7, 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_customizer_private.h"
+#include "service_reference.h"
+}
+
+int main(int argc, char** argv) {
+	return RUN_ALL_TESTS(argc, argv);
+}
+
+TEST_GROUP(service_tracker_customizer) {
+	apr_pool_t *pool;
+
+	void setup(void) {
+		apr_initialize();
+		apr_pool_create(&pool, NULL);
+	}
+
+	void teardown() {
+		apr_pool_destroy(pool);
+//		mock().checkExpectations();
+//		mock().clear();
+	}
+};
+
+extern "C" {
+	celix_status_t serviceTrackerCustomizerTest_addingService(void * handle, service_reference_pt reference, void **service) {
+		return CELIX_SUCCESS;
+	}
+	celix_status_t serviceTrackerCustomizerTest_addedService(void * handle, service_reference_pt reference, void * service) {
+		return CELIX_SUCCESS;
+	}
+	celix_status_t serviceTrackerCustomizerTest_modifiedService(void * handle, service_reference_pt reference, void * service) {
+		return CELIX_SUCCESS;
+	}
+	celix_status_t serviceTrackerCustomizerTest_removedService(void * handle, service_reference_pt reference, void * service) {
+		return CELIX_SUCCESS;
+	}
+}
+
+TEST(service_tracker_customizer, create) {
+	void *handle = (void *) 0x10;
+	service_tracker_customizer_pt customizer = NULL;
+	celix_status_t status = serviceTrackerCustomizer_create(pool,
+			handle,
+			serviceTrackerCustomizerTest_addingService,
+			serviceTrackerCustomizerTest_addedService,
+			serviceTrackerCustomizerTest_modifiedService,
+			serviceTrackerCustomizerTest_removedService, &customizer);
+
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(handle, customizer->handle);
+	POINTERS_EQUAL(serviceTrackerCustomizerTest_addingService, customizer->addingService);
+	POINTERS_EQUAL(serviceTrackerCustomizerTest_addedService, customizer->addedService);
+	POINTERS_EQUAL(serviceTrackerCustomizerTest_modifiedService, customizer->modifiedService);
+	POINTERS_EQUAL(serviceTrackerCustomizerTest_removedService, customizer->removedService);
+}
+
+TEST(service_tracker_customizer, createIllegalArgument) {
+	void *handle = (void *) 0x10;
+	service_tracker_customizer_pt customizer = NULL;
+	celix_status_t status = serviceTrackerCustomizer_create(pool,
+			NULL,
+			serviceTrackerCustomizerTest_addingService,
+			serviceTrackerCustomizerTest_addedService,
+			serviceTrackerCustomizerTest_modifiedService,
+			serviceTrackerCustomizerTest_removedService, &customizer);
+
+	LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
+}
+
+TEST(service_tracker_customizer, getHandle) {
+	service_tracker_customizer_pt customizer = (service_tracker_customizer_pt) apr_palloc(pool, sizeof(*customizer));
+	void *handle = (void *) 0x10;
+	customizer->handle = handle;
+
+	void *getHandle = NULL;
+	celix_status_t status = serviceTrackerCustomizer_getHandle(customizer, &getHandle);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(handle, getHandle);
+}
+
+TEST(service_tracker_customizer, getAddingFunction) {
+	service_tracker_customizer_pt customizer = (service_tracker_customizer_pt) apr_palloc(pool, sizeof(*customizer));
+	adding_callback_pt adding = (adding_callback_pt) 0x11;
+	customizer->addingService = adding;
+
+	adding_callback_pt getAdding = NULL;
+	celix_status_t status = serviceTrackerCustomizer_getAddingFunction(customizer, &getAdding);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(adding, getAdding);
+}
+
+TEST(service_tracker_customizer, getAddedFunction) {
+	service_tracker_customizer_pt customizer = (service_tracker_customizer_pt) apr_palloc(pool, sizeof(*customizer));
+	added_callback_pt added = (added_callback_pt) 0x11;
+	customizer->addedService = added;
+
+	added_callback_pt getAdded = NULL;
+	celix_status_t status = serviceTrackerCustomizer_getAddedFunction(customizer, &getAdded);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(added, getAdded);
+}
+
+TEST(service_tracker_customizer, getModifiedFunction) {
+	service_tracker_customizer_pt customizer = (service_tracker_customizer_pt) apr_palloc(pool, sizeof(*customizer));
+	modified_callback_pt modified = (modified_callback_pt) 0x11;
+	customizer->modifiedService = modified;
+
+	modified_callback_pt getModified = NULL;
+	celix_status_t status = serviceTrackerCustomizer_getModifiedFunction(customizer, &getModified);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(modified, getModified);
+}
+
+TEST(service_tracker_customizer, getRemovedFunction) {
+	service_tracker_customizer_pt customizer = (service_tracker_customizer_pt) apr_palloc(pool, sizeof(*customizer));
+	removed_callback_pt removed = (removed_callback_pt) 0x11;
+	customizer->removedService = removed;
+
+	removed_callback_pt getRemoved = NULL;
+	celix_status_t status = serviceTrackerCustomizer_getRemovedFunction(customizer, &getRemoved);
+	LONGS_EQUAL(CELIX_SUCCESS, status);
+	POINTERS_EQUAL(removed, getRemoved);
+}
+