You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2015/10/07 14:45:41 UTC
[01/20] celix git commit: CELIX-257: refactored to allow endpoint
poll when adding a new url
Repository: celix
Updated Branches:
refs/heads/feature/CELIX-237_rsa-ffi a13465a78 -> 119bb9504
CELIX-257: refactored to allow endpoint poll when adding a new url
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/fad8ca25
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/fad8ca25
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/fad8ca25
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: fad8ca259b62ebaf7baa45103c8f418ab179f7d8
Parents: 1094446
Author: Bjoern Petri <bp...@apache.org>
Authored: Tue Sep 15 09:21:59 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Tue Sep 15 09:21:59 2015 +0200
----------------------------------------------------------------------
.../private/src/endpoint_discovery_poller.c | 114 ++++++++++---------
1 file changed, 63 insertions(+), 51 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/fad8ca25/remote_services/discovery/private/src/endpoint_discovery_poller.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/endpoint_discovery_poller.c b/remote_services/discovery/private/src/endpoint_discovery_poller.c
index ae269cf..ac819c5 100644
--- a/remote_services/discovery/private/src/endpoint_discovery_poller.c
+++ b/remote_services/discovery/private/src/endpoint_discovery_poller.c
@@ -43,7 +43,9 @@
#define DISCOVERY_POLL_INTERVAL "DISCOVERY_CFG_POLL_INTERVAL"
#define DEFAULT_POLL_INTERVAL "10"
-static void *endpointDiscoveryPoller_poll(void *data);
+
+static void *endpointDiscoveryPoller_performPeriodicPoll(void *data);
+celix_status_t endpointDiscoveryPoller_poll(endpoint_discovery_poller_pt poller, char *url, array_list_pt currentEndpoints);
static celix_status_t endpointDiscoveryPoller_getEndpoints(endpoint_discovery_poller_pt poller, char *url, array_list_pt *updatedEndpoints);
static celix_status_t endpointDiscoveryPoller_endpointDescriptionEquals(void *endpointPtr, void *comparePtr, bool *equals);
@@ -99,7 +101,7 @@ celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_con
return CELIX_BUNDLE_EXCEPTION;
}
- status = celixThread_create(&(*poller)->pollerThread, NULL, endpointDiscoveryPoller_poll, *poller);
+ status = celixThread_create(&(*poller)->pollerThread, NULL, endpointDiscoveryPoller_performPeriodicPoll, *poller);
if (status != CELIX_SUCCESS) {
return status;
}
@@ -187,6 +189,7 @@ celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_p
if (status == CELIX_SUCCESS) {
logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_DEBUG, "ENDPOINT_POLLER: add new discovery endpoint with url %s", url);
hashMap_put(poller->entries, strdup(url), endpoints);
+ endpointDiscoveryPoller_poll(poller, url, endpoints);
}
}
@@ -234,80 +237,89 @@ celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discover
return status;
}
-static void *endpointDiscoveryPoller_poll(void *data) {
- endpoint_discovery_poller_pt poller = (endpoint_discovery_poller_pt) data;
- useconds_t interval = (useconds_t) (poller->poll_interval * 1000000L);
- while (poller->running) {
- usleep(interval);
- celix_status_t status = celixThreadMutex_lock(&poller->pollerLock);
- if (status != CELIX_SUCCESS) {
- logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to obtain lock; retrying...");
- continue;
- }
+celix_status_t endpointDiscoveryPoller_poll(endpoint_discovery_poller_pt poller, char *url, array_list_pt currentEndpoints) {
+ celix_status_t status = NULL;
+ array_list_pt updatedEndpoints = NULL;
- hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);
+ // create an arraylist with a custom equality test to ensure we can find endpoints properly...
+ arrayList_createWithEquals(endpointDiscoveryPoller_endpointDescriptionEquals, &updatedEndpoints);
+ status = endpointDiscoveryPoller_getEndpoints(poller, url, &updatedEndpoints);
- while (hashMapIterator_hasNext(iterator)) {
- hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
+ if (status != CELIX_SUCCESS) {
+ status = celixThreadMutex_unlock(&poller->pollerLock);
+ } else {
+ if (updatedEndpoints) {
+ for (unsigned int i = arrayList_size(currentEndpoints); i > 0; i--) {
+ endpoint_description_pt endpoint = arrayList_get(currentEndpoints, i - 1);
+
+ if (!arrayList_contains(updatedEndpoints, endpoint)) {
+ status = discovery_removeDiscoveredEndpoint(poller->discovery, endpoint);
+ arrayList_remove(currentEndpoints, i - 1);
+ endpointDescription_destroy(endpoint);
+ }
+ }
- char *url = hashMapEntry_getKey(entry);
- array_list_pt currentEndpoints = hashMapEntry_getValue(entry);
+ for (int i = arrayList_size(updatedEndpoints); i > 0; i--) {
+ endpoint_description_pt endpoint = arrayList_remove(updatedEndpoints, 0);
- array_list_pt updatedEndpoints = NULL;
- // create an arraylist with a custom equality test to ensure we can find endpoints properly...
- arrayList_createWithEquals(endpointDiscoveryPoller_endpointDescriptionEquals, &updatedEndpoints);
- status = endpointDiscoveryPoller_getEndpoints(poller, url, &updatedEndpoints);
+ if (!arrayList_contains(currentEndpoints, endpoint)) {
+ arrayList_add(currentEndpoints, endpoint);
+ status = discovery_addDiscoveredEndpoint(poller->discovery, endpoint);
+ } else {
+ endpointDescription_destroy(endpoint);
- if (status != CELIX_SUCCESS) {
- status = celixThreadMutex_unlock(&poller->pollerLock);
- continue;
+ }
}
+ }
- if (updatedEndpoints) {
- for (unsigned int i = arrayList_size(currentEndpoints); i > 0 ; i--) {
- endpoint_description_pt endpoint = arrayList_get(currentEndpoints, i-1);
+ if (updatedEndpoints) {
+ arrayList_destroy(updatedEndpoints);
+ }
+ }
- if (!arrayList_contains(updatedEndpoints, endpoint)) {
- status = discovery_removeDiscoveredEndpoint(poller->discovery, endpoint);
- arrayList_remove(currentEndpoints, i-1);
- endpointDescription_destroy(endpoint);
- }
- }
+ return status;
+}
- for (int i = arrayList_size(updatedEndpoints); i > 0 ; i--) {
- endpoint_description_pt endpoint = arrayList_remove(updatedEndpoints, 0);
+static void *endpointDiscoveryPoller_performPeriodicPoll(void *data) {
+ endpoint_discovery_poller_pt poller = (endpoint_discovery_poller_pt) data;
- if (!arrayList_contains(currentEndpoints, endpoint)) {
- arrayList_add(currentEndpoints, endpoint);
- status = discovery_addDiscoveredEndpoint(poller->discovery, endpoint);
- }
- else {
- endpointDescription_destroy(endpoint);
+ useconds_t interval = (useconds_t) (poller->poll_interval * 1000000L);
- }
- }
- }
+ while (poller->running) {
+ usleep(interval);
+ celix_status_t status = celixThreadMutex_lock(&poller->pollerLock);
+
+ if (status != CELIX_SUCCESS) {
+ logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to obtain lock; retrying...");
+ } else {
+ hash_map_iterator_pt iterator = hashMapIterator_create(poller->entries);
+
+ while (hashMapIterator_hasNext(iterator)) {
+ hash_map_entry_pt entry = hashMapIterator_nextEntry(iterator);
+
+ char *url = hashMapEntry_getKey(entry);
+ array_list_pt currentEndpoints = hashMapEntry_getValue(entry);
- if (updatedEndpoints) {
- arrayList_destroy(updatedEndpoints);
+ endpointDiscoveryPoller_poll(poller, url, currentEndpoints);
}
+ hashMapIterator_destroy(iterator);
}
- hashMapIterator_destroy(iterator);
-
status = celixThreadMutex_unlock(&poller->pollerLock);
if (status != CELIX_SUCCESS) {
logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_WARNING, "ENDPOINT_POLLER: failed to release lock; retrying...");
}
- }
+ }
- return NULL;
+ return NULL;
}
+
+
struct MemoryStruct {
char *memory;
size_t size;
@@ -366,7 +378,7 @@ static celix_status_t endpointDiscoveryPoller_getEndpoints(endpoint_discovery_po
endpointDescriptorReader_destroy(reader);
}
} else {
- logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_ERROR, "ENDPOINT_POLLER: unable to read endpoints, reason: %s", curl_easy_strerror(res));
+ logHelper_log(*poller->loghelper, OSGI_LOGSERVICE_ERROR, "ENDPOINT_POLLER: unable to read endpoints from %s, reason: %s", url, curl_easy_strerror(res));
}
// clean up endpoints file
[18/20] celix git commit: CELIX-267: add additional check whether
endpoint is available
Posted by pn...@apache.org.
CELIX-267: add additional check whether endpoint is available
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/39751029
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/39751029
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/39751029
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 39751029394b81caafe0395a4b5aea75dd07da7b
Parents: 7215825
Author: Bjoern Petri <bp...@apache.org>
Authored: Wed Oct 7 09:51:02 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Wed Oct 7 09:51:02 2015 +0200
----------------------------------------------------------------------
.../private/src/remote_service_admin_impl.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/39751029/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
index 023d8fb..d6aee31 100644
--- a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
+++ b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
@@ -322,7 +322,7 @@ static int remoteServiceAdmin_callback(struct mg_connection *conn) {
for (expIt = 0; expIt < arrayList_size(exports); expIt++) {
export_registration_pt export = arrayList_get(exports, expIt);
long serviceId = atol(service);
- if (serviceId == export->endpointDescription->serviceId) {
+ if (serviceId == export->endpointDescription->serviceId && export->endpoint != NULL) {
uint64_t datalength = request_info->content_length;
char* data = malloc(datalength + 1);
mg_read(conn, data, datalength);
@@ -447,6 +447,7 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_pt admin, c
exportRegistration_open(registration);
exportRegistration_startTracking(registration);
}
+
celixThreadMutex_lock(&admin->exportedServicesLock);
hashMap_put(admin->exportedServices, reference, *registrations);
celixThreadMutex_unlock(&admin->exportedServicesLock);
[02/20] celix git commit: CELIX-238: replace dlopen/dlsym with direct
function pointer assignment
Posted by pn...@apache.org.
CELIX-238: replace dlopen/dlsym with direct function pointer assignment
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/e59dea5f
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/e59dea5f
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/e59dea5f
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: e59dea5ff0ee58205e3ab098adcdbf9d1e3dbc20
Parents: fad8ca2
Author: Bjoern Petri <bp...@apache.org>
Authored: Fri Sep 25 18:59:14 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Fri Sep 25 18:59:14 2015 +0200
----------------------------------------------------------------------
framework/private/src/framework.c | 26 +++++++-------------------
1 file changed, 7 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/e59dea5f/framework/private/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/private/src/framework.c b/framework/private/src/framework.c
index f493318..6aad985 100644
--- a/framework/private/src/framework.c
+++ b/framework/private/src/framework.c
@@ -162,7 +162,6 @@ framework_logger_pt logger;
#ifdef _WIN32
#define handle_t HMODULE
- #define fw_getSystemLibrary() fw_getCurrentModule()
#define fw_openLibrary(path) LoadLibrary(path)
#define fw_closeLibrary(handle) FreeLibrary(handle)
@@ -177,7 +176,6 @@ framework_logger_pt logger;
}
#else
#define handle_t void *
- #define fw_getSystemLibrary() dlopen(NULL, RTLD_LAZY|RTLD_LOCAL)
#define fw_openLibrary(path) dlopen(path, RTLD_LAZY|RTLD_LOCAL)
#define fw_closeLibrary(handle) dlclose(handle)
#define fw_getSymbol(handle, name) dlsym(handle, name)
@@ -426,16 +424,6 @@ celix_status_t fw_init(framework_pt framework) {
status = CELIX_DO_IF(status, serviceRegistry_create(framework, fw_serviceChanged, &framework->registry));
status = CELIX_DO_IF(status, framework_setBundleStateAndNotify(framework, framework->bundle, OSGI_FRAMEWORK_BUNDLE_STARTING));
status = CELIX_DO_IF(status, celixThreadCondition_init(&framework->shutdownGate, NULL));
- if (status == CELIX_SUCCESS) {
- handle_t handle = NULL;
- handle = fw_getSystemLibrary();
- if (handle != NULL) {
- bundle_setHandle(framework->bundle, handle);
- } else {
- status = CELIX_FRAMEWORK_EXCEPTION;
- fw_logCode(framework->logger, OSGI_FRAMEWORK_LOG_ERROR, status, "Could not get handle to framework library");
- }
- }
bundle_context_pt context = NULL;
#ifdef WITH_APR
@@ -453,10 +441,10 @@ celix_status_t fw_init(framework_pt framework) {
bundle_context_pt context = NULL;
void * userData = NULL;
- create_function_pt create = (create_function_pt) fw_getSymbol((handle_t) bundle_getHandle(framework->bundle), OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_CREATE);
- start_function_pt start = (start_function_pt) fw_getSymbol((handle_t) bundle_getHandle(framework->bundle), OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_START);
- stop_function_pt stop = (stop_function_pt) fw_getSymbol((handle_t) bundle_getHandle(framework->bundle), OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_STOP);
- destroy_function_pt destroy = (destroy_function_pt) fw_getSymbol((handle_t) bundle_getHandle(framework->bundle), OSGI_FRAMEWORK_BUNDLE_ACTIVATOR_DESTROY);
+ create_function_pt create = NULL;
+ start_function_pt start = (start_function_pt) frameworkActivator_start;
+ stop_function_pt stop = (stop_function_pt) frameworkActivator_stop;
+ destroy_function_pt destroy = (destroy_function_pt) frameworkActivator_destroy;
activator->start = start;
activator->stop = stop;
@@ -2315,12 +2303,12 @@ celix_status_t fw_invokeFrameworkListener(framework_pt framework, framework_list
return ret;
}
-celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
+celix_status_t frameworkActivator_start(void * userData, bundle_context_pt context) {
// nothing to do
return CELIX_SUCCESS;
}
-celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) {
+celix_status_t frameworkActivator_stop(void * userData, bundle_context_pt context) {
celix_status_t status = CELIX_SUCCESS;
celix_thread_t shutdownThread;
@@ -2345,7 +2333,7 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context)
return status;
}
-celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) {
+celix_status_t frameworkActivator_destroy(void * userData, bundle_context_pt context) {
return CELIX_SUCCESS;
}
[05/20] celix git commit: CELIX-260: added missing uuid includes
Posted by pn...@apache.org.
CELIX-260: added missing uuid includes
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/a72cd6f5
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/a72cd6f5
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/a72cd6f5
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: a72cd6f5b9716aef7f0b032b60a29d0479a2e4ff
Parents: 268ab02
Author: Bjoern Petri <bp...@apache.org>
Authored: Mon Sep 28 11:39:13 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Mon Sep 28 11:39:13 2015 +0200
----------------------------------------------------------------------
deployment_admin/CMakeLists.txt | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/a72cd6f5/deployment_admin/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/deployment_admin/CMakeLists.txt b/deployment_admin/CMakeLists.txt
index cff425d..1f18ae2 100644
--- a/deployment_admin/CMakeLists.txt
+++ b/deployment_admin/CMakeLists.txt
@@ -18,7 +18,8 @@
celix_subproject(DEPLOYMENT_ADMIN "Option to enable building the Deployment Admin Service bundles" ON DEPS framework launcher shell_tui log_writer)
if (DEPLOYMENT_ADMIN)
- find_package(CURL REQUIRED)
+ find_package(CURL REQUIRED)
+ find_package(UUID REQUIRED)
add_definitions(-DUSE_FILE32API)
@@ -27,6 +28,7 @@ if (DEPLOYMENT_ADMIN)
SET_HEADERS("Bundle-Name: Apache Celix Deployment Admin")
include_directories("${CURL_INCLUDE_DIR}")
+ include_directories("${UUID_INCLUDE_DIR}")
include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
include_directories("${PROJECT_SOURCE_DIR}/deployment_admin/private/include")
include_directories("${PROJECT_SOURCE_DIR}/deployment_admin/public/include")
@@ -58,5 +60,5 @@ if (DEPLOYMENT_ADMIN)
public/include/resource_processor.h
)
- target_link_libraries(deployment_admin celix_framework ${CURL_LIBRARIES})
+ target_link_libraries(deployment_admin celix_framework ${CURL_LIBRARIES} ${UUID_LIBRARY})
endif (DEPLOYMENT_ADMIN)
[06/20] celix git commit: CELIX-261: Fix memory leaks in shell
Posted by pn...@apache.org.
CELIX-261: Fix memory leaks in shell
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/a29205ab
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/a29205ab
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/a29205ab
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: a29205ab44a8f498dac49d704afea50caa8190b6
Parents: a72cd6f
Author: Bjoern Petri <bp...@apache.org>
Authored: Sat Oct 3 11:22:53 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Sat Oct 3 11:22:53 2015 +0200
----------------------------------------------------------------------
shell/private/src/help_command.c | 2 ++
shell/private/src/inspect_command.c | 6 +++++-
shell/private/src/update_command.c | 2 +-
3 files changed, 8 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/a29205ab/shell/private/src/help_command.c
----------------------------------------------------------------------
diff --git a/shell/private/src/help_command.c b/shell/private/src/help_command.c
index b2ed30a..0a11ba9 100644
--- a/shell/private/src/help_command.c
+++ b/shell/private/src/help_command.c
@@ -75,6 +75,7 @@ void helpCommand_execute(command_pt command, char * line, void (*out)(char *), v
out(outString);
}
out("\nUse 'help <command-name>' for more information.\n");
+ arrayList_destroy(commands);
} else {
bool found = false;
while (sub != NULL) {
@@ -99,6 +100,7 @@ void helpCommand_execute(command_pt command, char * line, void (*out)(char *), v
}
}
sub = strtok_r(NULL, delims, &save_ptr);
+ arrayList_destroy(commands);
}
}
}
http://git-wip-us.apache.org/repos/asf/celix/blob/a29205ab/shell/private/src/inspect_command.c
----------------------------------------------------------------------
diff --git a/shell/private/src/inspect_command.c b/shell/private/src/inspect_command.c
index bac1ed9..15bcf3e 100644
--- a/shell/private/src/inspect_command.c
+++ b/shell/private/src/inspect_command.c
@@ -98,6 +98,7 @@ void inspectCommand_execute(command_pt command, char * commandline, void (*out)(
sprintf(outString, "%s\n", command->usage);
out(outString);
}
+ arrayList_destroy(ids);
} else {
out("INSPECT: Too few arguments\n");
sprintf(outString, "%s\n", command->usage);
@@ -133,6 +134,7 @@ celix_status_t inspectCommand_printExportedServices(command_pt command, array_li
out(line);
}
}
+ arrayList_destroy(bundles);
}
if (status == CELIX_SUCCESS) {
@@ -192,7 +194,6 @@ celix_status_t inspectCommand_printExportedServices(command_pt command, array_li
}
}
-
return status;
}
@@ -277,6 +278,7 @@ celix_status_t inspectCommand_printImportedServices(command_pt command, array_li
sprintf(line, "%s = %s\n", key, value);
out(line);
}
+ free(keys);
// objectClass = properties_get(props, (char *) OSGI_FRAMEWORK_OBJECTCLASS);
// sprintf(line, "ObjectClass = %s\n", objectClass);
@@ -292,6 +294,8 @@ celix_status_t inspectCommand_printImportedServices(command_pt command, array_li
}
}
+ arrayList_destroy(bundles);
+
return status;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/a29205ab/shell/private/src/update_command.c
----------------------------------------------------------------------
diff --git a/shell/private/src/update_command.c b/shell/private/src/update_command.c
index 9ddfba0..711798d 100644
--- a/shell/private/src/update_command.c
+++ b/shell/private/src/update_command.c
@@ -102,7 +102,7 @@ celix_status_t updateCommand_download(command_pt command, char * url, char **inp
curl = curl_easy_init();
if (curl) {
FILE *fp = NULL;
- *inputFile = "updateXXXXXX";
+ snprintf(*inputFile, 13,"updateXXXXXX");
int fd = mkstemp(*inputFile);
if (fd) {
fp = fopen(*inputFile, "wb+");
[11/20] celix git commit: CELIX-263: replaced utils cunit tests w/
cpputests
Posted by pn...@apache.org.
CELIX-263: replaced utils cunit tests w/ cpputests
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/c6d2d59f
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/c6d2d59f
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/c6d2d59f
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: c6d2d59f1bcd4443caeb7b0133e1cd2abf54b0aa
Parents: 5ff51e8
Author: Bjoern Petri <bp...@apache.org>
Authored: Tue Oct 6 05:45:58 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Tue Oct 6 05:45:58 2015 +0200
----------------------------------------------------------------------
.travis.yml | 11 +-
utils/CMakeLists.txt | 42 +-
utils/private/test/array_list_test.c | 357 ------
utils/private/test/array_list_test.cpp | 498 +++++++-
utils/private/test/celix_threads_test.cpp | 344 ++++++
utils/private/test/hash_map_test.c | 478 --------
utils/private/test/hash_map_test.cpp | 1492 ++++++++++++++++++++++++
utils/private/test/hash_map_test_hash.c | 359 ------
utils/private/test/linked_list_test.c | 96 --
utils/private/test/linked_list_test.cpp | 794 +++++++++++++
10 files changed, 3142 insertions(+), 1329 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/c6d2d59f/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index bb53363..df0f48b 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,5 +1,7 @@
language: c
+env
+
before_install:
- sudo apt-get update -qq
- sudo apt-get install -y uuid-dev libjansson-dev libxml2-dev
@@ -12,7 +14,12 @@ matrix:
before_script:
- mkdir build install
- cd build
- - cmake -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=ON -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DBUILD_DEVICE_ACCESS=ON -DBUILD_DEVICE_ACCESS_EXAMPLE=ON -DCMAKE_INSTALL_PREFIX=../install ..
+ - cmake -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=ON -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DBUILD_DEVICE_ACCESS=ON -DBUILD_DEVICE_ACCESS_EXAMPLE=ON -DBUILD_UTILS_TEST=ON -DCMAKE_INSTALL_PREFIX=../install ..
script:
- - make all && make deploy && make install
+ - make all && make deploy && make install-all
+
+after_script:
+ - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/utils
+ - ./utils/array_list_test && ./utils/celix_threads_test && ./utils/linked_list_test && ./utils/hash_map_test
+
http://git-wip-us.apache.org/repos/asf/celix/blob/c6d2d59f/utils/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index bb27a0c..c786e96 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -41,6 +41,7 @@ if (UTILS)
public/include/exports.h
private/src/celix_threads.c
+ public/include/celix_threads.h
)
IF(UNIX)
@@ -53,6 +54,7 @@ if (UTILS)
celix_subproject(UTILS-TESTS "Option to build the utilities library tests" "OFF")
if (UTILS-TESTS)
+
find_package(CppUTest REQUIRED)
include_directories(${CUNIT_INCLUDE_DIRS})
@@ -60,27 +62,33 @@ if (UTILS)
include_directories("${PROJECT_SOURCE_DIR}/utils/public/include")
include_directories("${PROJECT_SOURCE_DIR}/utils/private/include")
- add_executable(hash_map_test private/test/hash_map_test.c)
- target_link_libraries(hash_map_test celix_utils ${CUNIT_LIBRARIES})
-
- add_executable(hash_map_test_hash private/test/hash_map_test_hash.c)
- target_link_libraries(hash_map_test_hash celix_utils ${CUNIT_LIBRARIES})
-
- add_executable(array_list_test2 private/test/array_list_test.c)
- target_link_libraries(array_list_test2 celix_utils ${CUNIT_LIBRARIES})
+ add_executable(hash_map_test private/test/hash_map_test.cpp)
+ target_link_libraries(hash_map_test celix_utils ${CPPUTEST_LIBRARY} pthread)
add_executable(array_list_test private/test/array_list_test.cpp)
- target_link_libraries(array_list_test celix_utils ${CPPUTEST_LIBRARY})
+ target_link_libraries(array_list_test celix_utils ${CPPUTEST_LIBRARY} pthread)
+
+ add_executable(celix_threads_test private/test/celix_threads_test.cpp)
+ target_link_libraries(celix_threads_test celix_utils ${CPPUTEST_LIBRARY} pthread)
- add_executable(linked_list_test private/test/linked_list_test.c)
- target_link_libraries(linked_list_test celix_utils ${CUNIT_LIBRARIES})
+ add_executable(linked_list_test private/test/linked_list_test.cpp)
+ target_link_libraries(linked_list_test celix_utils ${CPPUTEST_LIBRARY} pthread)
- run_test(array_list_test2)
- run_test(hash_map_test)
- run_test(hash_map_test_hash)
- run_test(linked_list_test)
+ #run_test(array_list_test)
+ #run_test(hash_map_test)
+ #run_test(linked_list_test)
ADD_TARGET_FOR_TEST(array_list_test)
- SETUP_TARGET_FOR_COVERAGE(array_list_test_c array_list_test ${CMAKE_BINARY_DIR}/coverage/array_list_test)
- endif(UTILS-TESTS)
+ SETUP_TARGET_FOR_COVERAGE(array_list array_list_test ${CMAKE_BINARY_DIR}/coverage/array_list_test/array_list_test)
+
+ ADD_TARGET_FOR_TEST(hash_map_test)
+ SETUP_TARGET_FOR_COVERAGE(hash_map hash_map_test ${CMAKE_BINARY_DIR}/coverage/hash_map_test/hash_map_test)
+
+ ADD_TARGET_FOR_TEST(celix_threads_test)
+ SETUP_TARGET_FOR_COVERAGE(celix_threads celix_threads_test ${CMAKE_BINARY_DIR}/coverage/celix_threads_test/celix_threads_test)
+
+ ADD_TARGET_FOR_TEST(linked_list_test)
+ SETUP_TARGET_FOR_COVERAGE(linked_list linked_list_test ${CMAKE_BINARY_DIR}/coverage/linked_list_test/linked_list_test)
+
+ endif(UTILS-TESTS)
endif (UTILS)
http://git-wip-us.apache.org/repos/asf/celix/blob/c6d2d59f/utils/private/test/array_list_test.c
----------------------------------------------------------------------
diff --git a/utils/private/test/array_list_test.c b/utils/private/test/array_list_test.c
deleted file mode 100644
index ba881c1..0000000
--- a/utils/private/test/array_list_test.c
+++ /dev/null
@@ -1,357 +0,0 @@
-/**
- *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.
- */
-/*
- * array_list_test.c
- *
- * \date Aug 4, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <CUnit/Automated.h>
-
-#include "celixbool.h"
-
-#include "array_list.h"
-#include "array_list_private.h"
-
-array_list_pt list;
-
-int setup(void) {
- arrayList_create(&list);
- if (list == NULL) {
- return 1;
- }
- return 0;
-}
-
-void test_arrayList_create(void) {
- CU_ASSERT_PTR_NOT_NULL_FATAL(list);
- CU_ASSERT_EQUAL(list->size, 0);
-}
-
-void test_arrayList_trimToSize(void) {
- char * entry;
- arrayList_clear(list);
-
- entry = "entry";
- arrayList_add(list, entry);
- CU_ASSERT_EQUAL(list->size, 1);
- CU_ASSERT_EQUAL(list->capacity, 10);
-
- arrayList_trimToSize(list);
- CU_ASSERT_EQUAL(list->size, 1);
- CU_ASSERT_EQUAL(list->capacity, 1);
-}
-
-void test_arrayList_ensureCapacity(void) {
- int i;
- arrayList_create(&list);
- arrayList_clear(list);
- CU_ASSERT_EQUAL(list->capacity, 10);
- CU_ASSERT_EQUAL(list->size, 0);
- for (i = 0; i < 100; i++) {
- arrayList_add(list, "entry");
- }
- CU_ASSERT_EQUAL(list->capacity, 133);
- CU_ASSERT_EQUAL(list->size, 100);
- arrayList_create(&list);
-}
-
-void test_arrayList_size(void) {
- char * entry;
- char * entry2;
- char * entry3;
- arrayList_clear(list);
- CU_ASSERT_EQUAL(list->size, 0);
-
- entry = "entry";
- arrayList_add(list, entry);
- CU_ASSERT_EQUAL(list->size, 1);
-
- entry2 = "entry";
- arrayList_add(list, entry2);
- CU_ASSERT_EQUAL(list->size, 2);
-
- entry3 = "entry";
- arrayList_add(list, entry3);
- CU_ASSERT_EQUAL(list->size, 3);
-}
-
-void test_arrayList_isEmpty(void) {
- arrayList_clear(list);
- CU_ASSERT_EQUAL(list->size, 0);
- CU_ASSERT_TRUE(arrayList_isEmpty(list));
-}
-
-void test_arrayList_contains(void) {
- char * entry = "entry";
- char * entry2 = "entry2";
- char * entry3 = NULL;
- bool contains;
-
- arrayList_clear(list);
-
- arrayList_add(list, entry);
-
- arrayList_add(list, entry2);
-
- CU_ASSERT_TRUE(arrayList_contains(list, entry));
- CU_ASSERT_TRUE(arrayList_contains(list, entry2));
- contains = arrayList_contains(list, NULL);
- CU_ASSERT_FALSE(contains);
-
- arrayList_add(list, entry3);
-
- CU_ASSERT_TRUE(arrayList_contains(list, entry3));
-}
-
-void test_arrayList_indexOf(void) {
- char * entry = "entry";
- char * entry2 = "entry2";
-
- arrayList_clear(list);
-
- arrayList_add(list, entry);
-
- arrayList_add(list, entry2);
- arrayList_add(list, entry2);
- arrayList_add(list, entry2);
- arrayList_add(list, entry2);
-
- CU_ASSERT_EQUAL(arrayList_indexOf(list, entry), 0);
- CU_ASSERT_EQUAL(arrayList_indexOf(list, entry2), 1);
- CU_ASSERT_EQUAL(arrayList_lastIndexOf(list, entry), 0);
- CU_ASSERT_EQUAL(arrayList_lastIndexOf(list, entry2), 4);
-}
-
-void test_arrayList_get(void) {
- char * entry = "entry";
- char * entry2 = "entry2";
- char * entry3 = NULL;
- char * get;
-
- arrayList_clear(list);
-
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
-
- get = arrayList_get(list, 0);
- CU_ASSERT_EQUAL(entry, get);
-
- get = arrayList_get(list, 1);
- CU_ASSERT_EQUAL(entry2, get);
-
- arrayList_add(list, entry3);
-
- get = arrayList_get(list, 2);
- CU_ASSERT_PTR_NULL(get);
-
- get = arrayList_get(list, 42);
- CU_ASSERT_PTR_NULL(get);
-}
-
-void test_arrayList_set(void) {
- char * entry = "entry";
- char * entry2 = "entry2";
- char * entry3 = "entry3";
- char * get;
- char * old;
-
- arrayList_clear(list);
-
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
-
- get = arrayList_get(list, 1);
- CU_ASSERT_EQUAL(entry2, get);
-
- old = arrayList_set(list, 1, entry3);
- CU_ASSERT_EQUAL(entry2, old);
- get = arrayList_get(list, 1);
- CU_ASSERT_EQUAL(entry3, get);
-}
-
-void test_arrayList_add(void) {
- char * entry = "entry";
- char * entry2 = "entry2";
- char * entry3 = "entry3";
- char * get;
-
- arrayList_clear(list);
-
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
-
- get = arrayList_get(list, 1);
- CU_ASSERT_EQUAL(entry2, get);
-
- arrayList_addIndex(list, 1, entry3);
-
- get = arrayList_get(list, 1);
- CU_ASSERT_EQUAL(entry3, get);
-
- get = arrayList_get(list, 2);
- CU_ASSERT_EQUAL(entry2, get);
-}
-
-void test_arrayList_addAll(void) {
- char * entry = "entry";
- char * entry2 = "entry2";
- char * entry3 = "entry3";
- char * get;
- array_list_pt toAdd;
- bool changed;
-
- arrayList_clear(list);
-
- arrayList_create(&toAdd);
- arrayList_add(toAdd, entry);
- arrayList_add(toAdd, entry2);
-
- arrayList_add(list, entry3);
-
- get = arrayList_get(list, 0);
- CU_ASSERT_EQUAL(entry3, get);
-
- changed = arrayList_addAll(list, toAdd);
- CU_ASSERT_TRUE(changed);
- CU_ASSERT_EQUAL(arrayList_size(list), 3);
-
- get = arrayList_get(list, 1);
- CU_ASSERT_EQUAL(entry, get);
-
- get = arrayList_get(list, 2);
- CU_ASSERT_EQUAL(entry2, get);
-}
-
-void test_arrayList_remove(void) {
- char * entry = "entry";
- char * entry2 = "entry2";
- char * entry3 = "entry3";
- char * get;
- char * removed;
-
- arrayList_clear(list);
-
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
-
- get = arrayList_get(list, 1);
- CU_ASSERT_EQUAL(entry2, get);
-
- // Remove first entry
- removed = arrayList_remove(list, 0);
- CU_ASSERT_EQUAL(entry, removed);
-
- // Check the new first element
- get = arrayList_get(list, 0);
- CU_ASSERT_EQUAL(entry2, get);
-
- // Add a new element
- arrayList_add(list, entry3);
-
- get = arrayList_get(list, 1);
- CU_ASSERT_EQUAL(entry3, get);
-}
-
-void test_arrayList_removeElement(void) {
- char * entry = "entry";
- char * entry2 = "entry2";
- char * entry3 = "entry3";
- char * get;
-
- arrayList_clear(list);
-
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
-
- // Remove entry
- CU_ASSERT_TRUE(arrayList_removeElement(list, entry));
-
- // Check the new first element
- get = arrayList_get(list, 0);
- CU_ASSERT_EQUAL(entry2, get);
-
- // Add a new element
- arrayList_add(list, entry3);
-
- get = arrayList_get(list, 1);
- CU_ASSERT_EQUAL(entry3, get);
-}
-
-void test_arrayList_clear(void) {
- char * entry = "entry";
- char * entry2 = "entry2";
-
- arrayList_clear(list);
-
- arrayList_add(list, entry);
- arrayList_add(list, entry2);
-
- CU_ASSERT_EQUAL(arrayList_size(list), 2);
- arrayList_clear(list);
- CU_ASSERT_EQUAL(arrayList_size(list), 0);
-}
-
-
-
-int main (int argc, char** argv) {
- CU_pSuite pSuite = NULL;
-
- /* initialize the CUnit test registry */
- if (CUE_SUCCESS != CU_initialize_registry())
- return CU_get_error();
-
- /* add a suite to the registry */
- pSuite = CU_add_suite("Suite_1", setup, NULL);
- if (NULL == pSuite) {
- CU_cleanup_registry();
- return CU_get_error();
- }
-
- /* add the tests to the suite */
- if (NULL == CU_add_test(pSuite, "Array List Creation Test", test_arrayList_create)
- || NULL == CU_add_test(pSuite, "Array List Trim Test", test_arrayList_trimToSize)
- || NULL == CU_add_test(pSuite, "Array List Capacity Test", test_arrayList_ensureCapacity)
- || NULL == CU_add_test(pSuite, "Array List Size Test", test_arrayList_size)
- || NULL == CU_add_test(pSuite, "Array List Is Empty Test", test_arrayList_isEmpty)
- || NULL == CU_add_test(pSuite, "Array List Contains Test", test_arrayList_contains)
- || NULL == CU_add_test(pSuite, "Array List Index Of Test", test_arrayList_indexOf)
- || NULL == CU_add_test(pSuite, "Array List Get Test", test_arrayList_get)
- || NULL == CU_add_test(pSuite, "Array List Set Test", test_arrayList_set)
- || NULL == CU_add_test(pSuite, "Array List Add Test", test_arrayList_add)
- || NULL == CU_add_test(pSuite, "Array List Remove Test", test_arrayList_remove)
- || NULL == CU_add_test(pSuite, "Array List Remove Element Test", test_arrayList_removeElement)
- || NULL == CU_add_test(pSuite, "Array List Clear Test", test_arrayList_clear)
- || NULL == CU_add_test(pSuite, "Array List Add All", test_arrayList_addAll)
- )
- {
- CU_cleanup_registry();
- return CU_get_error();
- }
-
- CU_set_output_filename(argv[1]);
- CU_list_tests_to_file();
- CU_automated_run_tests();
- CU_cleanup_registry();
- return CU_get_error();
-}
-
http://git-wip-us.apache.org/repos/asf/celix/blob/c6d2d59f/utils/private/test/array_list_test.cpp
----------------------------------------------------------------------
diff --git a/utils/private/test/array_list_test.cpp b/utils/private/test/array_list_test.cpp
index 3787bfe..fbf09a9 100644
--- a/utils/private/test/array_list_test.cpp
+++ b/utils/private/test/array_list_test.cpp
@@ -19,11 +19,13 @@
/*
* array_list_test.cpp
*
- * Created on: Jun 6, 2012
- * Author: alexander
+ * \date Sep 15, 2015
+ * \author Menno van der Graaf & Alexander
+ * \copyright Apache License, Version 2.0
*/
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "CppUTest/TestHarness.h"
#include "CppUTest/TestHarness_c.h"
@@ -39,10 +41,19 @@ int main(int argc, char** argv) {
return RUN_ALL_TESTS(argc, argv);
}
+static char* my_strdup(const char* s){
+ char *d = (char*) malloc (strlen (s) + 1);
+ if (d == NULL) return NULL;
+ strcpy (d,s);
+ return d;
+}
+
+//----------------------TESTS GROUP DEFINES----------------------
+
TEST_GROUP(array_list) {
array_list_pt list;
- void setup(void) {
+ void setup(){
arrayList_create(&list);
}
void teardown() {
@@ -50,55 +61,73 @@ TEST_GROUP(array_list) {
}
};
+TEST_GROUP(array_list_iterator) {
+ array_list_pt list;
+
+ void setup(){
+ arrayList_create(&list);
+ }
+ void teardown() {
+ arrayList_destroy(list);
+ }
+};
+
+//----------------------ARRAY LIST TESTS----------------------
TEST(array_list, create) {
CHECK_C(list != NULL);
- LONGS_EQUAL(0, list->size);
+ LONGS_EQUAL(0, list->size);
}
TEST(array_list, trimToSize) {
bool added;
- std::string entry;
+ char * entry = my_strdup("entry");
arrayList_clear(list);
- entry = "entry";
- added = arrayList_add(list, (char *) entry.c_str());
- LONGS_EQUAL(list->size, 1);
- LONGS_EQUAL(list->capacity, 10);
+ added = arrayList_add(list, entry);
+ LONGS_EQUAL(1, list->size);
+ LONGS_EQUAL(10, list->capacity);
arrayList_trimToSize(list);
- LONGS_EQUAL(list->size, 1);
- LONGS_EQUAL(list->capacity, 1);
+ LONGS_EQUAL(1, list->size);
+ LONGS_EQUAL(1, list->capacity);
+
+ free(entry);
}
TEST(array_list, ensureCapacity) {
int i;
arrayList_clear(list);
- LONGS_EQUAL(list->capacity, 10);
- LONGS_EQUAL(list->size, 0);
+ LONGS_EQUAL(10, list->capacity);
+ LONGS_EQUAL(0, list->size);
for (i = 0; i < 100; i++) {
bool added;
- std::string entry = "entry";
- added = arrayList_add(list, (char *) entry.c_str());
+ char * entry = my_strdup("entry");
+ added = arrayList_add(list, entry);
+ }
+ LONGS_EQUAL(133, list->capacity);
+ LONGS_EQUAL(100, list->size);
+
+ for (i = 99; i >= 0; i--) {
+ free(arrayList_remove(list, i));
}
- LONGS_EQUAL(list->capacity, 133);
- LONGS_EQUAL(list->size, 100);
}
TEST(array_list, clone) {
int i;
arrayList_clear(list);
- LONGS_EQUAL(list->capacity, 10);
- LONGS_EQUAL(list->size, 0);
+ LONGS_EQUAL(10, list->capacity);
+ LONGS_EQUAL(0, list->size);
for (i = 0; i < 12; i++) {
bool added;
char entry[11];
sprintf(entry, "|%s|%d|", "entry", i);
- added = arrayList_add(list, entry);
+ added = arrayList_add(list, my_strdup(entry));
+ CHECK(added);
}
LONGS_EQUAL(16, list->capacity);
LONGS_EQUAL(12, list->size);
@@ -119,5 +148,434 @@ TEST(array_list, clone) {
STRCMP_EQUAL((char *) entry, entrys);
}
+ for (i = 11; i >= 0; i--) {
+ free(arrayList_remove(list, i));
+ }
arrayList_destroy(clone);
}
+
+TEST(array_list, size){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry");
+ char * entry3 = my_strdup("entry");
+ arrayList_clear(list);
+ LONGS_EQUAL(0, list->size);
+
+ arrayList_add(list, entry);
+ LONGS_EQUAL(1, list->size);
+
+ arrayList_add(list, entry2);
+ LONGS_EQUAL(2, list->size);
+
+ arrayList_add(list, entry3);
+ LONGS_EQUAL(3, list->size);
+
+ free(entry);
+ free(entry2);
+ free(entry3);
+}
+
+TEST(array_list, isEmpty){
+ arrayList_clear(list);
+ LONGS_EQUAL(0, list->size);
+ CHECK(arrayList_isEmpty(list));
+}
+
+TEST(array_list, contains){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = NULL;
+ bool contains;
+
+ arrayList_clear(list);
+
+ arrayList_add(list, entry);
+
+ arrayList_add(list, entry2);
+
+ CHECK(arrayList_contains(list, entry));
+ CHECK(arrayList_contains(list, entry2));
+ contains = arrayList_contains(list, NULL);
+ CHECK(!contains);
+
+ arrayList_add(list, entry3);
+
+ CHECK(arrayList_contains(list, entry3));
+
+ free(entry);
+ free(entry2);
+}
+
+TEST(array_list, indexOf){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+
+ arrayList_clear(list);
+
+ arrayList_add(list, entry);
+
+ arrayList_add(list, entry2);
+ arrayList_add(list, entry2);
+ arrayList_add(list, entry2);
+ arrayList_add(list, entry2);
+
+ LONGS_EQUAL(0, arrayList_indexOf(list, entry));
+ LONGS_EQUAL(1, arrayList_indexOf(list, entry2));
+ LONGS_EQUAL(0, arrayList_lastIndexOf(list, entry));
+ LONGS_EQUAL(4, arrayList_lastIndexOf(list, entry2));
+
+ free(entry);
+ free(entry2);
+}
+
+TEST(array_list, get){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = NULL;
+ char * get;
+
+ arrayList_clear(list);
+
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
+
+ get = (char*) arrayList_get(list, 0);
+ STRCMP_EQUAL(entry, get);
+
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry2, get);
+
+ arrayList_add(list, entry3);
+
+ get = (char*) arrayList_get(list, 2);
+ CHECK(get == NULL);
+
+ get = (char*) arrayList_get(list, 42);
+ CHECK(get == NULL);
+
+ free(entry);
+ free(entry2);
+}
+
+TEST(array_list, set){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ char * get;
+ char * old;
+
+ arrayList_clear(list);
+
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
+
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry2, get);
+
+ old = (char*) arrayList_set(list, 1, entry3);
+ STRCMP_EQUAL(entry2, old);
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry3, get);
+
+ free(entry);
+ free(entry2);
+ free(entry3);
+}
+
+TEST(array_list, add){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ char * get;
+
+ arrayList_clear(list);
+
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
+
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry2, get);
+
+ arrayList_addIndex(list, 1, entry3);
+
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry3, get);
+
+ get = (char*) arrayList_get(list, 2);
+ STRCMP_EQUAL(entry2, get);
+
+ free(entry);
+ free(entry2);
+ free(entry3);
+}
+
+TEST(array_list, addAll){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ char * get;
+ array_list_pt toAdd;
+ bool changed;
+
+ arrayList_clear(list);
+
+ arrayList_create(&toAdd);
+ arrayList_add(toAdd, entry);
+ arrayList_add(toAdd, entry2);
+
+ arrayList_add(list, entry3);
+
+ get = (char*) arrayList_get(list, 0);
+ STRCMP_EQUAL(entry3, get);
+
+ changed = arrayList_addAll(list, toAdd);
+ CHECK(changed);
+ LONGS_EQUAL(3, arrayList_size(list));
+
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry, get);
+
+ get = (char*) arrayList_get(list, 2);
+ STRCMP_EQUAL(entry2, get);
+
+ free(entry);
+ free(entry2);
+ free(entry3);
+ arrayList_destroy(toAdd);
+}
+
+TEST(array_list, remove){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ char * get;
+ char * removed;
+
+ arrayList_clear(list);
+
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
+
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry2, get);
+
+ // Remove first entry
+ removed = (char*) arrayList_remove(list, 0);
+ STRCMP_EQUAL(entry, removed);
+
+ // Check the new first entry
+ get = (char*) arrayList_get(list, 0);
+ STRCMP_EQUAL(entry2, get);
+
+ // Add a new entry
+ arrayList_add(list, entry3);
+
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry3, get);
+
+ free(entry);
+ free(entry2);
+ free(entry3);
+}
+
+TEST(array_list, removeElement){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ char * get;
+
+ arrayList_clear(list);
+
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
+
+ // Remove entry
+ CHECK(arrayList_removeElement(list, entry));
+
+ // Check the new first element
+ get = (char*) arrayList_get(list, 0);
+ STRCMP_EQUAL(entry2, get);
+
+ // Add a new entry
+ arrayList_add(list, entry3);
+
+ get = (char*) arrayList_get(list, 1);
+ STRCMP_EQUAL(entry3, get);
+
+ free(entry);
+ free(entry2);
+ free(entry3);
+}
+
+TEST(array_list, clear){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+
+ arrayList_clear(list);
+
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
+
+ LONGS_EQUAL(2, arrayList_size(list));
+ arrayList_clear(list);
+ LONGS_EQUAL(0, arrayList_size(list));
+
+ free(entry);
+ free(entry2);
+}
+
+//----------------------ARRAY LIST ITERATOR TESTS----------------------
+
+TEST(array_list_iterator, create){
+ array_list_iterator_pt it_list = arrayListIterator_create(list);
+ CHECK(it_list != NULL);
+ POINTERS_EQUAL(list, it_list->list);
+ arrayListIterator_destroy(it_list);
+}
+
+TEST(array_list_iterator, hasNext){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ array_list_iterator_pt it_list;
+
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
+ arrayList_add(list, entry3);
+ it_list = arrayListIterator_create(list);
+ CHECK(arrayListIterator_hasNext(it_list));
+
+ arrayListIterator_next(it_list);
+ CHECK(arrayListIterator_hasNext(it_list));
+
+ arrayListIterator_next(it_list);
+ CHECK(arrayListIterator_hasNext(it_list));
+
+ arrayListIterator_next(it_list);
+ CHECK(!arrayListIterator_hasNext(it_list));
+
+ free(entry);
+ free(entry2);
+ free(entry3);
+ arrayListIterator_destroy(it_list);
+}
+
+TEST(array_list_iterator, hasPrevious){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ array_list_iterator_pt it_list;
+
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
+ arrayList_add(list, entry3);
+
+ it_list = arrayListIterator_create(list);
+ arrayListIterator_next(it_list);
+ arrayListIterator_next(it_list);
+ arrayListIterator_next(it_list);
+ CHECK(arrayListIterator_hasPrevious(it_list));
+
+ arrayListIterator_previous(it_list);
+ CHECK(arrayListIterator_hasPrevious(it_list));
+
+ arrayListIterator_previous(it_list);
+ CHECK(arrayListIterator_hasPrevious(it_list));
+
+ arrayListIterator_previous(it_list);
+ CHECK(!arrayListIterator_hasPrevious(it_list));
+
+ free(entry);
+ free(entry2);
+ free(entry3);
+ arrayListIterator_destroy(it_list);
+}
+
+TEST(array_list_iterator, next){
+ char * entry = my_strdup("entry");
+ char * entry2 = my_strdup("entry2");
+ char * entry3 = my_strdup("entry3");
+ array_list_iterator_pt it_list;
+
+ arrayList_add(list, entry);
+ arrayList_add(list, entry2);
+ arrayList_add(list, entry3);
+ it_list = arrayListIterator_create(list);
+ STRCMP_EQUAL(entry, (char*) arrayListIterator_next(it_list));
+ STRCMP_EQUAL(entry2, (char*) arrayListIterator_next(it_list));
+ STRCMP_EQUAL(entry3, (char*) arrayListIterator_next(it_list));
+ POINTERS_EQUAL(NULL, arrayListIterator_next(it_list));
+
+ //mess up the expected and real changecount, code should check and handle
+ arrayList_add(list, entry);
+ arrayListIterator_next(it_list);
+
+ free(entry);
+ free(entry2);
+ free(entry3);
+ arrayListIterator_destroy(it_list);
+}
+
+TEST(array_list_iterator, previous){
+ char * value = my_strdup("entry");
+ char * value2 = my_strdup("entry2");
+ char * value3 = my_strdup("entry3");
+ array_list_iterator_pt it_list;
+
+ arrayList_add(list, value);
+ arrayList_add(list, value2);
+ arrayList_add(list, value3);
+ it_list = arrayListIterator_create(list);
+
+ arrayListIterator_next(it_list);
+ arrayListIterator_next(it_list);
+ arrayListIterator_next(it_list);
+ STRCMP_EQUAL(value3, (char*) arrayListIterator_previous(it_list));
+ STRCMP_EQUAL(value2, (char*) arrayListIterator_previous(it_list));
+ STRCMP_EQUAL(value, (char*) arrayListIterator_previous(it_list));
+ POINTERS_EQUAL(NULL, arrayListIterator_previous(it_list));
+
+ //mess up the expected and real changecount, code should check and handle
+ arrayListIterator_destroy(it_list);
+ it_list = arrayListIterator_create(list);
+ arrayList_add(list, value);
+ arrayListIterator_previous(it_list);
+
+ free(value);
+ free(value2);
+ free(value3);
+ arrayListIterator_destroy(it_list);
+}
+
+TEST(array_list_iterator, remove){
+ char * value = my_strdup("entry");
+ char * value2 = my_strdup("entry2");
+ char * value3 = my_strdup("entry3");
+ array_list_iterator_pt it_list;
+
+ arrayList_add(list, value);
+ arrayList_add(list, value2);
+ arrayList_add(list, value3);
+ it_list = arrayListIterator_create(list);
+
+ LONGS_EQUAL(3, list->size);
+ STRCMP_EQUAL(value, (char*) arrayList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) arrayList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) arrayList_get(list, 2));
+
+ arrayListIterator_next(it_list);
+ arrayListIterator_next(it_list);
+ arrayListIterator_remove(it_list);
+ LONGS_EQUAL(2, list->size);
+ STRCMP_EQUAL(value, (char*) arrayList_get(list, 0));
+ STRCMP_EQUAL(value3, (char*) arrayList_get(list, 1));
+
+ //mess up the expected and real changecount, code should check and handle
+ arrayList_add(list, value);
+ arrayListIterator_remove(it_list);
+
+ free(value);
+ free(value2);
+ free(value3);
+ arrayListIterator_destroy(it_list);
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/c6d2d59f/utils/private/test/celix_threads_test.cpp
----------------------------------------------------------------------
diff --git a/utils/private/test/celix_threads_test.cpp b/utils/private/test/celix_threads_test.cpp
new file mode 100644
index 0000000..b0ddd83
--- /dev/null
+++ b/utils/private/test/celix_threads_test.cpp
@@ -0,0 +1,344 @@
+/**
+ *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.
+ */
+/*
+ * array_list_test.cpp
+ *
+ * \date Sep 15, 2015
+ * \author Menno van der Graaf & Alexander
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+
+#include "CppUTest/TestHarness.h"
+#include "CppUTest/TestHarness_c.h"
+#include "CppUTest/CommandLineTestRunner.h"
+
+extern "C" {
+#include "celix_threads.h"
+}
+
+int main(int argc, char** argv) {
+ return RUN_ALL_TESTS(argc, argv);
+}
+
+static char* my_strdup(const char* s) {
+ char *d = (char*) malloc(strlen(s) + 1);
+ if (d == NULL)
+ return NULL;
+ strcpy(d, s);
+ return d;
+}
+
+//----------------------TEST THREAD FUNCTION DECLARATIONS----------------------
+
+static void * thread_test_func_create(void *);
+static void * thread_test_func_exit(void *);
+static void * thread_test_func_detach(void *);
+static void * thread_test_func_self(void *);
+static void * thread_test_func_lock(void *);
+static void * thread_test_func_cond_wait(void *arg);
+static void * thread_test_func_cond_broadcast(void *arg);
+static int thread_test_func_recur_lock(celix_thread_mutex_t*, int);
+struct func_param{
+ int i, i2;
+ celix_thread_mutex_t mu, mu2;
+ celix_thread_cond_t cond, cond2;
+};
+//----------------------TESTGROUP DEFINES----------------------
+
+TEST_GROUP(celix_thread) {
+ celix_thread thread;
+
+ void setup(void) {
+ }
+
+ void teardown(void) {
+ }
+};
+
+TEST_GROUP(celix_thread_mutex) {
+ celix_thread thread;
+ celix_thread_mutex_t mu;
+
+ void setup(void) {
+ }
+
+ void teardown(void) {
+ }
+};
+
+TEST_GROUP(celix_thread_condition) {
+ celix_thread thread;
+ celix_thread_mutex_t mu;
+ celix_thread_cond_t cond;
+
+ void setup(void) {
+ }
+
+ void teardown(void) {
+ }
+};
+
+//----------------------CELIX THREADS TESTS----------------------
+
+TEST(celix_thread, create) {
+ int ret;
+ char * test_str;
+
+ ret = celixThread_create(&thread, NULL, &thread_test_func_create,
+ &test_str);
+ LONGS_EQUAL(CELIX_SUCCESS, ret);
+ celixThread_join(thread, NULL);
+
+ CHECK(test_str != NULL);
+ STRCMP_EQUAL("SUCCESS", test_str);
+
+ free(test_str);
+}
+
+TEST(celix_thread, exit) {
+ int ret, *status;
+
+ ret = celixThread_create(&thread, NULL, &thread_test_func_exit, NULL);
+ LONGS_EQUAL(CELIX_SUCCESS, ret);
+ celixThread_join(thread, (void**) &status);
+ LONGS_EQUAL(666, *status);
+ free(status);
+}
+
+//HORIBLE TEST
+TEST(celix_thread, detach) {
+ int ret;
+
+ celixThread_create(&thread, NULL, thread_test_func_detach, NULL);
+ ret = celixThread_detach(thread);
+ LONGS_EQUAL(CELIX_SUCCESS, ret);
+}
+
+TEST(celix_thread, self) {
+ celix_thread thread2;
+
+ celixThread_create(&thread, NULL, thread_test_func_self, &thread2);
+ celixThread_join(thread, NULL);
+ CHECK(celixThread_equals(thread, thread2));
+}
+
+TEST(celix_thread, initalized) {
+ CHECK(!celixThread_initalized(thread));
+ celixThread_create(&thread, NULL, thread_test_func_detach, NULL);
+ CHECK(celixThread_initalized(thread));
+ celixThread_detach(thread);
+}
+
+//----------------------CELIX THREADS MUTEX TESTS----------------------
+
+TEST(celix_thread_mutex, create) {
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutex_create(&mu, NULL));
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutex_destroy(&mu));
+}
+
+//check normal lock behaviour
+TEST(celix_thread_mutex, lock) {
+ struct func_param * params = (struct func_param*) calloc(1,
+ sizeof(struct func_param));
+
+ celixThreadMutex_create(¶ms->mu, NULL);
+
+ celixThreadMutex_lock(¶ms->mu);
+ celixThread_create(&thread, NULL, thread_test_func_lock, params);
+
+ sleep(2);
+
+ LONGS_EQUAL(0, params->i);
+
+ //possible race condition, not perfect test
+ celixThreadMutex_unlock(¶ms->mu);
+ celixThreadMutex_lock(¶ms->mu2);
+ LONGS_EQUAL(666, params->i);
+ celixThreadMutex_unlock(¶ms->mu2);
+ celixThread_join(thread, NULL);
+ free(params);
+}
+
+TEST(celix_thread_mutex, attrCreate) {
+ celix_thread_mutexattr_t mu_attr;
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutexAttr_create(&mu_attr));
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutexAttr_destroy(&mu_attr));
+}
+
+TEST(celix_thread_mutex, attrSettype) {
+ celix_thread_mutex_t mu;
+ celix_thread_mutexattr_t mu_attr;
+ celixThreadMutexAttr_create(&mu_attr);
+
+ //test recursive mutex
+ celixThreadMutexAttr_settype(&mu_attr, PTHREAD_MUTEX_RECURSIVE);
+ celixThreadMutex_create(&mu, &mu_attr);
+ //if program doesnt deadlock: succes! also check factorial of 10, for reasons unknown
+ LONGS_EQUAL(3628800, thread_test_func_recur_lock(&mu, 10));
+ celixThreadMutex_destroy(&mu);
+
+ //test deadlock check mutex
+ celixThreadMutexAttr_settype(&mu_attr, PTHREAD_MUTEX_ERRORCHECK);
+ celixThreadMutex_create(&mu, &mu_attr);
+ //get deadlock error
+ celixThreadMutex_lock(&mu);
+ CHECK(celixThreadMutex_lock(&mu) != CELIX_SUCCESS);
+ //do not get deadlock error
+ celixThreadMutex_unlock(&mu);
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadMutex_lock(&mu));
+ //get unlock error
+ celixThreadMutex_unlock(&mu);
+ CHECK(celixThreadMutex_unlock(&mu) != CELIX_SUCCESS);
+
+ celixThreadMutex_destroy(&mu);
+ celixThreadMutexAttr_destroy(&mu_attr);
+}
+
+//----------------------CELIX THREAD CONDITIONS TESTS----------------------
+
+TEST(celix_thread_condition, init) {
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadCondition_init(&cond, NULL));
+ LONGS_EQUAL(CELIX_SUCCESS, celixThreadCondition_destroy(&cond));
+}
+
+//test wait and signal
+TEST(celix_thread_condition, wait) {
+ struct func_param * param = (struct func_param*) calloc(1,
+ sizeof(struct func_param));
+ celixThreadMutex_create(¶m->mu, NULL);
+ celixThreadCondition_init(¶m->cond, NULL);
+
+ celixThreadMutex_lock(¶m->mu);
+
+ sleep(2);
+
+ celixThread_create(&thread, NULL, thread_test_func_cond_wait, param);
+ LONGS_EQUAL(0, param->i);
+
+ celixThreadCondition_wait(¶m->cond, ¶m->mu);
+ LONGS_EQUAL(666, param->i);
+
+ celixThread_join(thread, NULL);
+ free(param);
+}
+
+//test wait and broadcast on multiple threads
+TEST(celix_thread_condition, broadcast) {
+ celix_thread_t thread2;
+ struct func_param * param = (struct func_param*) calloc(1,sizeof(struct func_param));
+ celixThreadMutex_create(¶m->mu, NULL);
+ celixThreadMutex_create(¶m->mu2, NULL);
+ celixThreadCondition_init(¶m->cond, NULL);
+
+ celixThread_create(&thread, NULL, thread_test_func_cond_broadcast, param);
+ celixThread_create(&thread2, NULL, thread_test_func_cond_broadcast, param);
+
+ sleep(1);
+ celixThreadMutex_lock(¶m->mu2);
+ LONGS_EQUAL(0, param->i);
+ celixThreadMutex_unlock(¶m->mu2);
+
+ celixThreadMutex_lock(¶m->mu);
+ celixThreadCondition_broadcast(¶m->cond);
+ celixThreadMutex_unlock(¶m->mu);
+ sleep(1);
+ celixThreadMutex_lock(¶m->mu2);
+ LONGS_EQUAL(2, param->i);
+ celixThreadMutex_unlock(¶m->mu2);
+
+ celixThread_join(thread, NULL);
+ celixThread_join(thread2, NULL);
+ free(param);
+}
+
+//----------------------TEST THREAD FUNCTION DEFINES----------------------
+
+static void * thread_test_func_create(void * arg) {
+ char ** test_str = (char**) arg;
+ *test_str = my_strdup("SUCCESS");
+ celixThread_exit(NULL);
+}
+
+static void * thread_test_func_exit(void *) {
+ int *pi = (int*) calloc(1, sizeof(int));
+ *pi = 666;
+ celixThread_exit(pi);
+}
+
+static void * thread_test_func_detach(void *) {
+ celixThread_exit(NULL);
+}
+
+static void * thread_test_func_self(void * arg) {
+ *((celix_thread*) arg) = celixThread_self();
+ celixThread_exit(NULL);
+}
+
+static void * thread_test_func_lock(void *arg) {
+ struct func_param *param = (struct func_param *) arg;
+
+ celixThreadMutex_lock(¶m->mu2);
+ celixThreadMutex_lock(¶m->mu);
+ param->i = 666;
+ celixThreadMutex_unlock(¶m->mu);
+ celixThreadMutex_unlock(¶m->mu2);
+
+ celixThread_exit(NULL);
+}
+
+static void * thread_test_func_cond_wait(void *arg) {
+ struct func_param *param = (struct func_param *) arg;
+
+ celixThreadMutex_lock(¶m->mu);
+
+ param->i = 666;
+
+ celixThreadCondition_signal(¶m->cond);
+ celixThreadMutex_unlock(¶m->mu);
+ celixThread_exit(NULL);
+}
+
+static void * thread_test_func_cond_broadcast(void *arg) {
+ struct func_param *param = (struct func_param *) arg;
+
+ celixThreadMutex_lock(¶m->mu);
+ celixThreadCondition_wait(¶m->cond, ¶m->mu);
+ celixThreadMutex_unlock(¶m->mu);
+ celixThreadMutex_lock(¶m->mu2);
+ param->i++;
+ celixThreadMutex_unlock(¶m->mu2);
+ celixThread_exit(NULL);
+}
+
+static int thread_test_func_recur_lock(celix_thread_mutex_t *mu, int i) {
+ int temp;
+ if (i == 1) {
+ return 1;
+ } else {
+ celixThreadMutex_lock(mu);
+ temp = thread_test_func_recur_lock(mu, i - 1);
+ temp *= i;
+ celixThreadMutex_unlock(mu);
+ return temp;
+ }
+}
http://git-wip-us.apache.org/repos/asf/celix/blob/c6d2d59f/utils/private/test/hash_map_test.c
----------------------------------------------------------------------
diff --git a/utils/private/test/hash_map_test.c b/utils/private/test/hash_map_test.c
deleted file mode 100644
index f92ea40..0000000
--- a/utils/private/test/hash_map_test.c
+++ /dev/null
@@ -1,478 +0,0 @@
-/**
- *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.
- */
-/*
- * hash_map_test.c
- *
- * \date Jul 25, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stdlib.h>
-#include <CUnit/Automated.h>
-#include <stddef.h>
-
-#include "celixbool.h"
-
-#include "hash_map.h"
-#include "hash_map_private.h"
-
-hash_map_pt map;
-
-int setup(void) {
- printf("test\n");
- map = hashMap_create(NULL, NULL, NULL, NULL);
- if(map == NULL) {
- return 1;
- }
- return 0;
-}
-
-void test_hashMap_create(void) {
- CU_ASSERT_PTR_NOT_NULL_FATAL(map);
- CU_ASSERT_EQUAL(map->size, 0);
- // This fails on windows due to dllimport providing a proxy for exported functions.
- CU_ASSERT_EQUAL(map->equalsKey, hashMap_equals);
- CU_ASSERT_EQUAL(map->equalsValue, hashMap_equals);
- CU_ASSERT_EQUAL(map->hashKey, hashMap_hashCode);
- CU_ASSERT_EQUAL(map->hashValue, hashMap_hashCode);
-}
-
-void test_hashMap_size(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char * key3 = strdup("key2");
- char * value3 = "value3";
-
- CU_ASSERT_EQUAL(map->size, 0);
-
- // Add one entry
- hashMap_put(map, key, value);
- CU_ASSERT_EQUAL(map->size, 1);
-
- // Add second entry
- hashMap_put(map, key2, value2);
- CU_ASSERT_EQUAL(map->size, 2);
-
- // Add entry using the same key, this does not overwrite an existing entry
- hashMap_put(map, key3, value3);
- CU_ASSERT_EQUAL(map->size, 3);
-
- // Clear map
- hashMap_clear(map, false, false);
- CU_ASSERT_EQUAL(map->size, 0);
-}
-
-void test_hashMap_isEmpty(void) {
- char * key = "key";
- char * value = "value";
-
- hashMap_clear(map, false, false);
- CU_ASSERT_EQUAL(map->size, 0);
- CU_ASSERT_TRUE(hashMap_isEmpty(map));
-
- // Add one entry
- hashMap_put(map, key, value);
- CU_ASSERT_EQUAL(map->size, 1);
- CU_ASSERT_FALSE(hashMap_isEmpty(map));
-
- // Remove entry
- hashMap_remove(map, key);
- CU_ASSERT_EQUAL(map->size, 0);
- CU_ASSERT_TRUE(hashMap_isEmpty(map));
-}
-
-void test_hashMap_get(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char * neKey = "notExisting";
- char * key3 = NULL;
- char * value3 = "value3";
- char * get;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- get = hashMap_get(map, key);
- CU_ASSERT_STRING_EQUAL(get, value);
-
- get = hashMap_get(map, key2);
- CU_ASSERT_STRING_EQUAL(get, value2);
-
- get = hashMap_get(map, neKey);
- CU_ASSERT_EQUAL(get, NULL);
-
- get = hashMap_get(map, NULL);
- CU_ASSERT_EQUAL(get, NULL);
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- get = hashMap_get(map, NULL);
- CU_ASSERT_STRING_EQUAL(get, value3);
-}
-
-void test_hashMap_containsKey(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char * neKey = "notExisting";
- char * key3 = NULL;
- char * value3 = "value3";
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- CU_ASSERT_TRUE(hashMap_containsKey(map, key));
- CU_ASSERT_TRUE(hashMap_containsKey(map, key2));
- CU_ASSERT_FALSE(hashMap_containsKey(map, neKey));
- CU_ASSERT_FALSE(hashMap_containsKey(map, NULL));
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- CU_ASSERT_TRUE(hashMap_containsKey(map, key3));
-}
-
-void test_hashMap_getEntry(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char * neKey = "notExisting";
- char * key3 = NULL;
- char * value3 = "value3";
- hash_map_entry_pt entry;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
- entry = hashMap_getEntry(map, key);
- CU_ASSERT_STRING_EQUAL(entry->key, key);
- CU_ASSERT_STRING_EQUAL(entry->value, value);
-
- entry = hashMap_getEntry(map, key2);
- CU_ASSERT_STRING_EQUAL(entry->key, key2);
- CU_ASSERT_STRING_EQUAL(entry->value, value2);
-
- entry = hashMap_getEntry(map, neKey);
- CU_ASSERT_EQUAL(entry, NULL);
-
- entry = hashMap_getEntry(map, NULL);
- CU_ASSERT_EQUAL(entry, NULL);
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- entry = hashMap_getEntry(map, key3);
- CU_ASSERT_EQUAL(entry->key, key3);
- CU_ASSERT_STRING_EQUAL(entry->value, value3);
-}
-
-void test_hashMap_put(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char * nkey2 = strdup("key2");
- char * nvalue2 = "value3";
- char * key3 = NULL;
- char * value3 = "value3";
- char * key4 = "key4";
- char * value4 = NULL;
- char * old;
- char * get;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- get = hashMap_get(map, key);
- CU_ASSERT_STRING_EQUAL(get, value);
-
- get = hashMap_get(map, key2);
- CU_ASSERT_STRING_EQUAL(get, value2);
-
- // Try to add an entry with the same key, since no explicit hash function is used,
- // this will not overwrite an existing entry.
- old = (char *) hashMap_put(map, nkey2, nvalue2);
- CU_ASSERT_PTR_NULL_FATAL(old);
-
- // Retrieving the values will return the correct values
- get = hashMap_get(map, key2);
- CU_ASSERT_STRING_EQUAL(get, value2);
- get = hashMap_get(map, nkey2);
- CU_ASSERT_STRING_EQUAL(get, nvalue2);
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- get = hashMap_get(map, key3);
- CU_ASSERT_STRING_EQUAL(get, value3);
-
- // Add fourth entry with NULL value
- hashMap_put(map, key4, value4);
-
- get = hashMap_get(map, key4);
- CU_ASSERT_EQUAL(get, value4);
-}
-
-void test_hashMap_resize(void) {
- int i;
- char * k;
- char key[6];
-
- hashMap_clear(map, false, false);
-
- CU_ASSERT_EQUAL(map->size, 0);
- CU_ASSERT_EQUAL(map->tablelength, 16);
- CU_ASSERT_EQUAL(map->treshold, 12);
- for (i = 0; i < 12; i++) {
- char key[6];
- sprintf(key, "key%d", i);
- k = strdup(key);
- hashMap_put(map, k, k);
- }
- CU_ASSERT_EQUAL(map->size, 12);
- CU_ASSERT_EQUAL(map->tablelength, 16);
- CU_ASSERT_EQUAL(map->treshold, 12);
-
- sprintf(key, "key%d", i);
- hashMap_put(map, strdup(key), strdup(key));
- CU_ASSERT_EQUAL(map->size, 13);
- CU_ASSERT_EQUAL(map->tablelength, 32);
- CU_ASSERT_EQUAL(map->treshold, 24);
-}
-
-void test_hashMap_remove(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = NULL;
- char * value2 = "value2";
- char * removeKey;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry with null key
- hashMap_put(map, key2, value2);
-
- // Remove unexisting entry for map
- removeKey = "unexisting";
- hashMap_remove(map, removeKey);
- CU_ASSERT_EQUAL(map->size, 2);
- CU_ASSERT_FALSE(hashMap_isEmpty(map));
-
- hashMap_remove(map, key);
- CU_ASSERT_EQUAL(map->size, 1);
-
- hashMap_remove(map, key2);
- CU_ASSERT_EQUAL(map->size, 0);
- CU_ASSERT_TRUE(hashMap_isEmpty(map));
-
- // Remove unexisting entry for empty map
- removeKey = "unexisting";
- hashMap_remove(map, removeKey);
- CU_ASSERT_EQUAL(map->size, 0);
- CU_ASSERT_TRUE(hashMap_isEmpty(map));
-}
-
-void test_hashMap_removeMapping(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = NULL;
- char * value2 = "value2";
- hash_map_entry_pt entry1;
- hash_map_entry_pt entry2;
- hash_map_entry_pt removed;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry with null key
- hashMap_put(map, key2, value2);
-
- entry1 = hashMap_getEntry(map, key);
- entry2 = hashMap_getEntry(map, key2);
-
- CU_ASSERT_PTR_NOT_NULL_FATAL(entry1);
- CU_ASSERT_PTR_NOT_NULL_FATAL(entry2);
-
- removed = hashMap_removeMapping(map, entry1);
- CU_ASSERT_PTR_EQUAL(entry1, removed);
- CU_ASSERT_EQUAL(map->size, 1);
-
- removed = hashMap_removeMapping(map, entry2);
- CU_ASSERT_PTR_EQUAL(entry2, removed);
- CU_ASSERT_EQUAL(map->size, 0);
-
- // Remove unexisting entry for empty map
- hashMap_removeMapping(map, NULL);
- CU_ASSERT_EQUAL(map->size, 0);
- CU_ASSERT_TRUE(hashMap_isEmpty(map));
-}
-
-void test_hashMap_clear(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char * key3 = NULL;
- char * value3 = "value3";
- char * key4 = "key4";
- char * value4 = NULL;
-
- hashMap_clear(map, false, false);
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- // Add fourth entry with NULL value
- hashMap_put(map, key4, value4);
-
- hashMap_clear(map, false, false);
- CU_ASSERT_EQUAL(map->size, 0);
-}
-
-void test_hashMap_containsValue(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char * neValue = "notExisting";
- char * key3 = "key3";
- char * value3 = NULL;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- CU_ASSERT_TRUE(hashMap_containsValue(map, value));
- CU_ASSERT_TRUE(hashMap_containsValue(map, value2));
- CU_ASSERT_FALSE(hashMap_containsValue(map, neValue));
- CU_ASSERT_FALSE(hashMap_containsValue(map, NULL));
-
- // Add third entry with NULL value
- hashMap_put(map, key3, value3);
-
- CU_ASSERT_TRUE(hashMap_containsValue(map, value3));
-}
-
-void test_hashMapValues_toArray(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char **array;
- unsigned int size;
- hash_map_values_pt values;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- values = hashMapValues_create(map);
- hashMapValues_toArray(values, (void*)&array, &size);
- CU_ASSERT_EQUAL(size, 2);
- CU_ASSERT_TRUE(hashMapValues_contains(values, array[0]));
- CU_ASSERT_TRUE(hashMapValues_contains(values, array[1]));
-}
-
-int main (int argc, char** argv) {
- CU_pSuite pSuite = NULL;
-
- /* initialize the CUnit test registry */
- if (CUE_SUCCESS != CU_initialize_registry())
- return CU_get_error();
-
- /* add a suite to the registry */
- pSuite = CU_add_suite("Suite_1", setup, NULL);
- if (NULL == pSuite) {
- CU_cleanup_registry();
- return CU_get_error();
- }
-
- /* add the tests to the suite */
- if (NULL == CU_add_test(pSuite, "Map Creation Test", test_hashMap_create)
- || NULL == CU_add_test(pSuite, "Map Size Test", test_hashMap_size)
- || NULL == CU_add_test(pSuite, "Map Is Empty Test", test_hashMap_isEmpty)
- || NULL == CU_add_test(pSuite, "Map Get Test", test_hashMap_get)
- || NULL == CU_add_test(pSuite, "Map Contains Key Test", test_hashMap_containsKey)
- || NULL == CU_add_test(pSuite, "Map Get Entry Test", test_hashMap_getEntry)
- || NULL == CU_add_test(pSuite, "Map Put Test", test_hashMap_put)
- || NULL == CU_add_test(pSuite, "Map Resize Test", test_hashMap_resize)
- || NULL == CU_add_test(pSuite, "Map Remove Test", test_hashMap_remove)
- || NULL == CU_add_test(pSuite, "Map Remove Mapping Test", test_hashMap_removeMapping)
- || NULL == CU_add_test(pSuite, "Map Clear Test", test_hashMap_clear)
- || NULL == CU_add_test(pSuite, "Map Contains Value Test", test_hashMap_containsValue)
- || NULL == CU_add_test(pSuite, "Map To Array Test", test_hashMapValues_toArray)
-
-
- )
- {
- CU_cleanup_registry();
- return CU_get_error();
- }
-
- CU_set_output_filename(argv[1]);
- CU_list_tests_to_file();
- CU_automated_run_tests();
- CU_cleanup_registry();
- return CU_get_error();
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/c6d2d59f/utils/private/test/hash_map_test.cpp
----------------------------------------------------------------------
diff --git a/utils/private/test/hash_map_test.cpp b/utils/private/test/hash_map_test.cpp
new file mode 100644
index 0000000..1ef9337
--- /dev/null
+++ b/utils/private/test/hash_map_test.cpp
@@ -0,0 +1,1492 @@
+/**
+ *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.
+ */
+/*
+ * hash_map_test.cpp
+ *
+ * \date Sep 15, 2015
+ * \author Menno van der Graaf & Alexander
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include <stddef.h>
+#include <string.h>
+#include "celixbool.h"
+
+#include "CppUTest/TestHarness.h"
+#include "CppUTest/TestHarness_c.h"
+#include "CppUTest/CommandLineTestRunner.h"
+
+extern "C"
+{
+#include "hash_map.h"
+#include "hash_map_private.h"
+}
+
+int main(int argc, char** argv) {
+ return RUN_ALL_TESTS(argc, argv);
+}
+
+static char* my_strdup(const char* s){
+ if(s==NULL){
+ return NULL;
+ }
+
+ size_t len = strlen(s);
+
+ char *d = (char*) calloc (len + 1,sizeof(char));
+
+ if (d == NULL){
+ return NULL;
+ }
+
+ strncpy (d,s,len);
+ return d;
+}
+
+//Callback functions
+unsigned int test_hashKeyChar(void * k) {
+ char * str = (char *) k;
+
+ unsigned int hash = 1315423911;
+ unsigned int i = 0;
+ int len = strlen(str);
+
+ for(i = 0; i < len; str++, i++)
+ {
+ hash ^= ((hash << 5) + (*str) + (hash >> 2));
+ }
+
+ return hash;
+}
+
+unsigned int test_hashValueChar(void * v) {
+ return 0;
+}
+
+int test_equalsKeyChar(void * k, void * o) {
+ return strcmp((char *)k, (char *) o) == 0;
+}
+
+int test_equalsValueChar(void * v, void * o) {
+ return strcmp((char *)v, (char *) o) == 0;
+}
+
+//Tests group defines
+
+TEST_GROUP(hash_map){
+ hash_map_pt map;
+
+ void setup() {
+ map = hashMap_create(NULL, NULL, NULL, NULL);
+ }
+ void teardown() {
+ hashMap_destroy(map, false, false);
+ }
+};
+
+TEST_GROUP(hash_map_iterator){
+ hash_map_pt map;
+ hash_map_iterator_pt it_map;
+
+ void setup() {
+ map = hashMap_create(NULL, NULL, NULL, NULL);
+ }
+ void teardown() {
+ hashMap_destroy(map, false, false);
+ }
+};
+
+TEST_GROUP(hash_map_values){
+ hash_map_pt map;
+ hash_map_values_pt values;
+
+ void setup() {
+ map = hashMap_create(NULL, NULL, NULL, NULL);
+ }
+ void teardown() {
+ hashMap_destroy(map, false, false);
+ }
+};
+
+TEST_GROUP(hash_map_keySet){
+ hash_map_pt map;
+ hash_map_key_set_pt key_set;
+
+ void setup() {
+ map = hashMap_create(NULL, NULL, NULL, NULL);
+ }
+ void teardown() {
+ hashMap_destroy(map, false, false);
+ }
+};
+
+TEST_GROUP(hash_map_entrySet){
+ hash_map_pt map;
+ hash_map_entry_set_pt entry_set;
+
+ void setup() {
+ map = hashMap_create(NULL, NULL, NULL, NULL);
+ }
+ void teardown() {
+ hashMap_destroy(map, false, false);
+ }
+};
+
+TEST_GROUP(hash_map_hash) {
+ hash_map_pt map;
+
+ void setup(void) {
+ map = hashMap_create(test_hashKeyChar, test_hashValueChar, test_equalsKeyChar, test_equalsValueChar);
+ }
+ void teardown() {
+ hashMap_destroy(map, false, false);
+ }
+};
+
+//----------------------HASH MAP DATA MANAGEMENT TEST----------------------
+
+TEST(hash_map, create){
+ CHECK(map != NULL);
+ LONGS_EQUAL(0, map->size);
+ // This fails on windows due to dllimport providing a proxy for exported functions.
+ CHECK_EQUAL(hashMap_equals, map->equalsKey);
+ CHECK_EQUAL(hashMap_equals, map->equalsValue);
+ CHECK_EQUAL(hashMap_hashCode, map->hashKey);
+ CHECK_EQUAL(hashMap_hashCode, map->hashValue);
+}
+
+TEST(hash_map, size){
+ char* key = my_strdup("key");
+ char* value = my_strdup("value");
+ char* key2 = my_strdup("key2");
+ char* value2 = my_strdup("value2");
+ char* key3 = my_strdup("key2");
+ char* value3 = my_strdup("value3");
+
+ LONGS_EQUAL(0, map->size);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+ LONGS_EQUAL(1, map->size);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+ LONGS_EQUAL(2, map->size);
+
+ // Add entry using the same key, this does not overwrite an existing entry
+ hashMap_put(map, key3, value3);
+ LONGS_EQUAL(3, map->size);
+
+ // Clear map
+ hashMap_clear(map, true, true);
+ LONGS_EQUAL(0, map->size);
+}
+
+TEST(hash_map, isEmpty){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
+
+ // Add one entry
+ hashMap_put(map, key, value);
+ LONGS_EQUAL(1, map->size);
+ CHECK(!hashMap_isEmpty(map));
+
+ // Remove entry
+ hashMap_remove(map, key);
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
+
+ free(key);
+ free(value);
+}
+
+TEST(hash_map, get){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * neKey = my_strdup("notExisting");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ char * get;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ get = (char*) (char*) hashMap_get(map, key);
+ STRCMP_EQUAL(value, get);
+
+ get = (char*) hashMap_get(map, key2);
+ STRCMP_EQUAL(value2, get);
+
+ get = (char*) hashMap_get(map, neKey);
+ POINTERS_EQUAL(NULL, get);
+
+ get = (char*) hashMap_get(map, NULL);
+ POINTERS_EQUAL(NULL, get);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ get = (char*) hashMap_get(map, NULL);
+ STRCMP_EQUAL(value3, get);
+
+ free(neKey);
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map, containsKey){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * neKey = my_strdup("notExisting");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ CHECK(hashMap_containsKey(map, key));
+ CHECK(hashMap_containsKey(map, key2));
+ CHECK(!hashMap_containsKey(map, neKey));
+ CHECK(!hashMap_containsKey(map, NULL));
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ CHECK(hashMap_containsKey(map, key3));
+
+ free(neKey);
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map, getEntry){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * neKey = my_strdup("notExisting");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ hash_map_entry_pt entry;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+ entry = hashMap_getEntry(map, key);
+ STRCMP_EQUAL(key, (char*) entry->key);
+ STRCMP_EQUAL(value, (char*)entry->value);
+
+ entry = hashMap_getEntry(map, key2);
+ STRCMP_EQUAL(key2, (char*) entry->key);
+ STRCMP_EQUAL(value2, (char*) entry->value);
+
+ entry = hashMap_getEntry(map, neKey);
+ POINTERS_EQUAL(NULL, entry);
+
+ entry = hashMap_getEntry(map, NULL);
+ POINTERS_EQUAL(NULL, entry);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ entry = hashMap_getEntry(map, key3);
+ CHECK_EQUAL(key3, entry->key);
+ STRCMP_EQUAL(value3, (char*) entry->value);
+
+ free(neKey);
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map, put){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * nkey2 = my_strdup("key2");
+ char * nvalue2 = my_strdup("value3");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ char * key4 = my_strdup("key4");
+ char * value4 = NULL;
+ char * old;
+ char * get;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ get = (char*) hashMap_get(map, key);
+ STRCMP_EQUAL(value, get);
+
+ get = (char*) hashMap_get(map, key2);
+ STRCMP_EQUAL(value2, get);
+
+ // Try to add an entry with the same key, since no explicit hash function is used,
+ // this will not overwrite an existing entry.
+ old = (char *) hashMap_put(map, nkey2, nvalue2);
+ POINTERS_EQUAL(NULL, old);
+
+ // Retrieving the values will return the correct values
+ get = (char*) hashMap_get(map, (void*)key2);
+ STRCMP_EQUAL(value2, get);
+ get = (char*) hashMap_get(map, nkey2);
+ STRCMP_EQUAL(nvalue2, get);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ get = (char*) hashMap_get(map, key3);
+ STRCMP_EQUAL(value3, get);
+
+ // Add fourth entry with NULL value
+ hashMap_put(map, key4, value4);
+
+ get =(char*)hashMap_get(map, key4);
+ CHECK_EQUAL(value4, get);
+
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map, resize){
+ int i;
+ char * k;
+ char key[6];
+
+ LONGS_EQUAL(0, map->size);
+ LONGS_EQUAL(16, map->tablelength);
+ LONGS_EQUAL(12, map->treshold);
+ for (i = 0; i < 12; i++) {
+ char key[6];
+ sprintf(key, "key%d", i);
+ hashMap_put(map, my_strdup(key), my_strdup(key));
+ }
+ LONGS_EQUAL(12, map->size);
+ LONGS_EQUAL(16, map->tablelength);
+ LONGS_EQUAL(12, map->treshold);
+
+ sprintf(key, "key%d", i);
+ hashMap_put(map, my_strdup(key), my_strdup(key));
+ LONGS_EQUAL(13, map->size);
+ LONGS_EQUAL(32, map->tablelength);
+ LONGS_EQUAL(24, map->treshold);
+
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map, remove){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = NULL;
+ char * value2 = my_strdup("value2");
+ char * removeKey;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry with null key
+ hashMap_put(map, key2, value2);
+
+ // Remove unexisting entry for map
+ removeKey = my_strdup("unexisting");
+ hashMap_remove(map, removeKey);
+ LONGS_EQUAL(2, map->size);
+ CHECK(!hashMap_isEmpty(map));
+
+ hashMap_remove(map, key);
+ LONGS_EQUAL(1, map->size);
+
+ hashMap_remove(map, key2);
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
+
+ // Remove unexisting entry for empty map
+ hashMap_remove(map, removeKey);
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ free(removeKey);
+}
+
+TEST(hash_map, removeMapping){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = NULL;
+ char * value2 = my_strdup("value2");
+ hash_map_entry_pt entry1;
+ hash_map_entry_pt entry2;
+ hash_map_entry_pt removed;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry with null key
+ hashMap_put(map, key2, value2);
+
+ entry1 = hashMap_getEntry(map, key);
+ entry2 = hashMap_getEntry(map, key2);
+
+ CHECK(entry1 != NULL);
+ CHECK(entry2 != NULL);
+
+ removed = hashMap_removeMapping(map, entry1);
+ POINTERS_EQUAL(removed, entry1);
+ LONGS_EQUAL(1, map->size);
+
+ removed = hashMap_removeMapping(map, entry2);
+ POINTERS_EQUAL(removed, entry2);
+ LONGS_EQUAL(0, map->size);
+
+ // Remove unexisting entry for empty map
+ hashMap_removeMapping(map, NULL);
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ free(entry1);
+ free(entry2);
+}
+
+TEST(hash_map, clear){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ char * key4 = my_strdup("key4");
+ char * value4 = NULL;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ // Add fourth entry with NULL value
+ hashMap_put(map, key4, value4);
+
+ // Clear but leave keys and values intact
+ hashMap_clear(map, false, false);
+ LONGS_EQUAL(0, map->size);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ // Add fourth entry with NULL value
+ hashMap_put(map, key4, value4);
+ // Clear and clean up keys and values
+ hashMap_clear(map, true, true);
+ LONGS_EQUAL(0, map->size);
+}
+
+TEST(hash_map, containsValue){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * neValue = my_strdup("notExisting");
+ char * key3 = my_strdup("key3");
+ char * value3 = NULL;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ CHECK(hashMap_containsValue(map, value));
+ CHECK(hashMap_containsValue(map, value2));
+ CHECK(!hashMap_containsValue(map, neValue));
+ CHECK(!hashMap_containsValue(map, NULL));
+
+ // Add third entry with NULL value
+ hashMap_put(map, key3, value3);
+
+ CHECK(hashMap_containsValue(map, value3));
+
+ free(neValue);
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map, ValuestoArray){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char **array;
+ unsigned int size;
+ hash_map_values_pt values;
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ values = hashMapValues_create(map);
+ hashMapValues_toArray(values, (void***)&array, &size);
+ LONGS_EQUAL(2, size);
+ CHECK(hashMapValues_contains(values, array[0]));
+ CHECK(hashMapValues_contains(values, array[1]));
+
+ free(array);
+ hashMapValues_destroy(values);
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map, entryGetKey){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ char * get;
+ hash_map_entry_pt entry;
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+ hashMap_put(map, key3, value3);
+
+ entry = hashMap_getEntry(map, key);
+ get = (char*) hashMapEntry_getKey(entry);
+ STRCMP_EQUAL(key, get);
+
+ entry = hashMap_getEntry(map, key2);
+ get = (char*) hashMapEntry_getKey(entry);
+ STRCMP_EQUAL(key2, get);
+
+ entry = hashMap_getEntry(map, key3);
+ get = (char*) hashMapEntry_getKey(entry);
+ POINTERS_EQUAL(key3, get);
+
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map, entryGetValue){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ char * get;
+ hash_map_entry_pt entry;
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+ hashMap_put(map, key3, value3);
+
+ entry = hashMap_getEntry(map, key);
+ get = (char*) hashMapEntry_getValue(entry);
+ STRCMP_EQUAL(value, get);
+
+ entry = hashMap_getEntry(map, key2);
+ get = (char*) hashMapEntry_getValue(entry);
+ STRCMP_EQUAL(value2, get);
+
+ entry = hashMap_getEntry(map, key3);
+ get = (char*) hashMapEntry_getValue(entry);
+ POINTERS_EQUAL(value3, get);
+
+ hashMap_clear(map, true, true);
+}
+
+//----------------------HASH MAP ITERATOR TEST----------------------
+
+TEST(hash_map_iterator, create){
+ it_map = hashMapIterator_create(map);
+ CHECK(it_map != NULL);
+ POINTERS_EQUAL(map, it_map->map);
+ POINTERS_EQUAL(it_map->current, NULL);
+ LONGS_EQUAL(map->modificationCount, it_map->expectedModCount);
+
+ hashMapIterator_destroy(it_map);
+}
+
+TEST(hash_map_iterator, hasNext){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * key3 = my_strdup("key3");
+ char * value3 = my_strdup("value3");
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ // Add third entry
+ hashMap_put(map, key3, value3);
+
+ //create it_map from map
+ it_map = hashMapIterator_create(map);
+
+ //check hasNext
+ CHECK(hashMapIterator_hasNext(it_map));
+
+ hashMapIterator_nextEntry(it_map);
+ CHECK(hashMapIterator_hasNext(it_map));
+
+ hashMapIterator_nextEntry(it_map);
+ CHECK(hashMapIterator_hasNext(it_map));
+
+ //third entry next points to NULL
+ hashMapIterator_nextEntry(it_map);
+ CHECK(!hashMapIterator_hasNext(it_map));
+
+ hashMapIterator_destroy(it_map);
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map_iterator, remove){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * key3 = my_strdup("key3");
+ char * value3 = my_strdup("value3");
+
+ // Add 3 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+ hashMap_put(map, key3, value3);
+
+ //create it_map from map
+ it_map = hashMapIterator_create(map);
+
+ //try to remove current (NULL)
+ hashMapIterator_remove(it_map);
+ LONGS_EQUAL(3, map->size);
+
+ //delete the first and second entry
+ hashMapIterator_nextEntry(it_map);
+ hashMapIterator_remove(it_map);
+ hashMapIterator_nextEntry(it_map);
+ hashMapIterator_remove(it_map);
+ LONGS_EQUAL(1, map->size);
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ free(key3);
+ free(value3);
+ hashMapIterator_destroy(it_map);
+}
+
+TEST(hash_map_iterator, nextValue){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * getValue;
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ //create it_map from map
+ it_map = hashMapIterator_create(map);
+
+ getValue = (char*) hashMapIterator_nextValue(it_map);
+ CHECK(hashMap_containsValue(map, getValue));
+
+ getValue = (char*) hashMapIterator_nextValue(it_map);
+ CHECK(hashMap_containsValue(map, getValue));
+
+ getValue = (char*) hashMapIterator_nextValue(it_map);
+ POINTERS_EQUAL(NULL, getValue);
+
+ hashMapIterator_destroy(it_map);
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map_iterator, nextKey){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * getKey;
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ //create it_map from map
+ it_map = hashMapIterator_create(map);
+
+ getKey = (char*) hashMapIterator_nextKey(it_map);
+ CHECK(hashMap_containsKey(map, getKey));
+
+ getKey = (char*) hashMapIterator_nextKey(it_map);
+ CHECK(hashMap_containsKey(map, getKey));
+
+ getKey = (char*) hashMapIterator_nextKey(it_map);
+ POINTERS_EQUAL(NULL, getKey);
+
+ hashMapIterator_destroy(it_map);
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map_iterator, nextEntry){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * getValue;
+ hash_map_entry_pt get;
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ //create it_map from map
+ it_map = hashMapIterator_create(map);
+
+ get = (hash_map_entry_pt) hashMapIterator_nextEntry(it_map);
+ getValue = (char*) hashMap_get(map, get->key);
+ STRCMP_EQUAL((char*)get->value, (char*)getValue);
+
+ get = (hash_map_entry_pt) hashMapIterator_nextEntry(it_map);
+ getValue = (char*) hashMap_get(map, get->key);
+ STRCMP_EQUAL((char*)get->value, (char*)getValue);
+
+ get = (hash_map_entry_pt) hashMapIterator_nextEntry(it_map);
+ POINTERS_EQUAL(NULL, get);
+
+ hashMapIterator_destroy(it_map);
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map_iterator, valuesIterator){
+ hash_map_values_pt values;
+ hash_map_iterator_pt it_val;
+
+ values = hashMapValues_create(map);
+ it_val = hashMapValues_iterator(values);
+
+ POINTERS_EQUAL(map, it_val->map);
+
+ hashMapIterator_destroy(it_val);
+ hashMapValues_destroy(values);
+}
+
+//----------------------HASH MAP VALUES TEST----------------------
+
+TEST(hash_map_values, create){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ //create Values from map
+ values = hashMapValues_create(map);
+
+ CHECK(hashMapValues_contains(values, value));
+ CHECK(hashMapValues_contains(values, value2));
+
+ hashMap_clear(map, true, true);
+ hashMapValues_destroy(values);
+}
+
+TEST(hash_map_values, size){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ //create Values from map
+ values = hashMapValues_create(map);
+
+ LONGS_EQUAL(2, hashMapValues_size(values));
+
+ hashMap_clear(map, true, true);
+ hashMapValues_destroy(values);
+}
+
+TEST(hash_map_values, remove){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ //create Values from map
+ values = hashMapValues_create(map);
+ CHECK(hashMapValues_contains(values, value));
+ CHECK(hashMapValues_contains(values, value2));
+
+ hashMapValues_remove(values, value);
+ CHECK(!hashMapValues_contains(values, value));
+ CHECK(hashMapValues_contains(values, value2));
+
+ hashMapValues_remove(values, value2);
+ CHECK(!hashMapValues_contains(values, value));
+ CHECK(!hashMapValues_contains(values, value2));
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ hashMap_clear(map, true, true);
+ hashMapValues_destroy(values);
+}
+
+TEST(hash_map_values, clear){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ //create Values from map
+ values = hashMapValues_create(map);
+
+ CHECK(hashMapValues_contains(values, value));
+ CHECK(hashMapValues_contains(values, value2));
+ LONGS_EQUAL(2, values->map->size);
+
+ hashMapValues_clear(values);
+
+ CHECK(!hashMapValues_contains(values, value));
+ CHECK(!hashMapValues_contains(values, value2));
+ LONGS_EQUAL(0, values->map->size);
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ hashMapValues_destroy(values);
+}
+
+TEST(hash_map_values, isEmpty){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ //create Values from map
+ values = hashMapValues_create(map);
+
+ CHECK(!hashMapValues_isEmpty(values));
+
+ hashMapValues_clear(values);
+
+ CHECK(hashMapValues_isEmpty(values));
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ hashMapValues_destroy(values);
+}
+
+//----------------------HASH MAP KEYSET TEST----------------------
+
+TEST(hash_map_keySet, create){
+ key_set = hashMapKeySet_create(map);
+
+ POINTERS_EQUAL(map, key_set->map);
+
+ hashMapKeySet_destroy(key_set);
+}
+
+TEST(hash_map_keySet, size){
+ char * key = my_strdup("key");
+ char * key2 = my_strdup("key2");
+
+ key_set = hashMapKeySet_create(map);
+
+ LONGS_EQUAL(0, hashMapKeySet_size(key_set));
+
+ // Add 2 entrys
+ hashMap_put(map, key, NULL);
+ hashMap_put(map, key2, NULL);
+
+
+ LONGS_EQUAL(2, hashMapKeySet_size(key_set));
+
+ hashMap_clear(map, true, true);
+ hashMapKeySet_destroy(key_set);
+}
+
+TEST(hash_map_keySet, contains){
+ char * key = my_strdup("key");
+ char * key2 = my_strdup("key2");
+
+ key_set = hashMapKeySet_create(map);
+
+ CHECK(!hashMapKeySet_contains(key_set, key));
+ CHECK(!hashMapKeySet_contains(key_set, key2));
+
+ // Add 2 entrys
+ hashMap_put(map, key, NULL);
+
+ CHECK(hashMapKeySet_contains(key_set, key));
+ CHECK(!hashMapKeySet_contains(key_set, key2));
+
+ hashMap_put(map, key2, NULL);
+
+ CHECK(hashMapKeySet_contains(key_set, key));
+ CHECK(hashMapKeySet_contains(key_set, key2));
+
+ hashMap_clear(map, true, true);
+ hashMapKeySet_destroy(key_set);
+}
+
+TEST(hash_map_keySet, remove){
+ char * key = my_strdup("key");
+ char * key2 = my_strdup("key2");
+
+ key_set = hashMapKeySet_create(map);
+
+ // Add 2 entrys
+ hashMap_put(map, key, NULL);
+ hashMap_put(map, key2, NULL);
+
+ LONGS_EQUAL(2, key_set->map->size);
+
+ hashMapKeySet_remove(key_set, key);
+
+ LONGS_EQUAL(1, key_set->map->size);
+
+ hashMapKeySet_remove(key_set, key2);
+
+ LONGS_EQUAL(0, key_set->map->size);
+
+ free(key);
+ free(key2);
+ hashMapKeySet_destroy(key_set);
+}
+
+TEST(hash_map_keySet, clear){
+ char * key = my_strdup("key");
+ char * key2 = my_strdup("key2");
+
+ key_set = hashMapKeySet_create(map);
+
+ // Add 2 entrys
+ hashMap_put(map, key, NULL);
+ hashMap_put(map, key2, NULL);
+
+ LONGS_EQUAL(2, key_set->map->size);
+
+ hashMapKeySet_clear(key_set);
+
+ LONGS_EQUAL(0, key_set->map->size);
+
+ free(key);
+ free(key2);
+ hashMapKeySet_destroy(key_set);
+}
+
+TEST(hash_map_keySet, isEmpty){
+ char * key = my_strdup("key");
+ char * key2 = my_strdup("key2");
+
+ key_set = hashMapKeySet_create(map);
+
+ CHECK(hashMapKeySet_isEmpty(key_set));
+
+ // Add 2 entrys
+ hashMap_put(map, key, NULL);
+ hashMap_put(map, key2, NULL);
+
+ CHECK(!hashMapKeySet_isEmpty(key_set));
+
+ hashMapKeySet_clear(key_set);
+
+ CHECK(hashMapKeySet_isEmpty(key_set));
+
+ free(key);
+ free(key2);
+ hashMapKeySet_destroy(key_set);
+}
+
+//----------------------HASH MAP ENTRYSET TEST----------------------
+
+TEST(hash_map_entrySet, create){
+ entry_set = hashMapEntrySet_create(map);
+
+ POINTERS_EQUAL(map, entry_set->map);
+
+ hashMapEntrySet_destroy(entry_set);
+}
+
+TEST(hash_map_entrySet, size){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+
+
+ entry_set = hashMapEntrySet_create(map);
+
+ LONGS_EQUAL(0, hashMapEntrySet_size(entry_set));
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+
+ LONGS_EQUAL(2, hashMapEntrySet_size(entry_set));
+
+ hashMap_clear(map, true, true);
+ hashMapEntrySet_destroy(entry_set);
+}
+
+TEST(hash_map_entrySet, contains){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+
+ entry_set = hashMapEntrySet_create(map);
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ CHECK(!hashMapEntrySet_contains(entry_set, NULL));
+ CHECK(!hashMapEntrySet_contains(entry_set, hashMap_getEntry(map, key)));
+ CHECK(!hashMapEntrySet_contains(entry_set, hashMap_getEntry(map, key2)));
+
+ hashMap_clear(map, true, true);
+ hashMapEntrySet_destroy(entry_set);
+}
+
+TEST(hash_map_entrySet, remove){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+
+ entry_set = hashMapEntrySet_create(map);
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ CHECK(!hashMapEntrySet_remove(entry_set, (hash_map_entry_pt) NULL));
+ LONGS_EQUAL(2, entry_set->map->size);
+
+ CHECK(hashMapEntrySet_remove(entry_set, hashMap_getEntry(map, key)));
+ LONGS_EQUAL(1, entry_set->map->size);
+
+ CHECK(hashMapEntrySet_remove(entry_set, hashMap_getEntry(map, key2)));
+ LONGS_EQUAL(0, entry_set->map->size);
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ hashMap_clear(map, false, false);
+ hashMapEntrySet_destroy(entry_set);
+}
+
+TEST(hash_map_entrySet, clear){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+
+ entry_set = hashMapEntrySet_create(map);
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ LONGS_EQUAL(2, entry_set->map->size);
+
+ hashMapEntrySet_clear(entry_set);
+
+ LONGS_EQUAL(0, entry_set->map->size);
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ hashMapEntrySet_destroy(entry_set);
+}
+
+TEST(hash_map_entrySet, isEmpty){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+
+ entry_set = hashMapEntrySet_create(map);
+
+ CHECK(hashMapEntrySet_isEmpty(entry_set));
+
+ // Add 2 entrys
+ hashMap_put(map, key, value);
+ hashMap_put(map, key2, value2);
+
+ CHECK(!hashMapEntrySet_isEmpty(entry_set));
+
+ hashMapEntrySet_clear(entry_set);
+
+ CHECK(hashMapEntrySet_isEmpty(entry_set));
+
+ free(key);
+ free(value);
+ free(key2);
+ free(value2);
+ hashMapEntrySet_destroy(entry_set);
+}
+
+//----------------------HASH MAP HASH TEST----------------------
+
+TEST(hash_map_hash, get){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * getKey = my_strdup("key");
+ char * get;
+ char * neKey = my_strdup("notExisting");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+
+ hashMap_clear(map, false, false);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ // Get with new created key
+ get = (char*) (char*) hashMap_get(map, getKey);
+ CHECK_C(get != NULL);
+ STRCMP_EQUAL(value, get);
+
+ free(getKey);
+ getKey = my_strdup("key2");
+ get = (char*) hashMap_get(map, getKey);
+ CHECK_C(get != NULL);
+ STRCMP_EQUAL(value2, get);
+
+ get = (char*) hashMap_get(map, neKey);
+ POINTERS_EQUAL(NULL, get);
+
+ get = (char*) hashMap_get(map, NULL);
+ POINTERS_EQUAL(NULL,get);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ get = (char*) hashMap_get(map, NULL);
+ STRCMP_EQUAL(get, value3);
+
+ free(getKey);
+ free(neKey);
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map_hash, containsKey) {
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * containsKey = my_strdup("key");
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+
+ hashMap_clear(map, false, false);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ CHECK(hashMap_containsKey(map, containsKey));
+ free(containsKey);
+ containsKey = my_strdup("key2");
+ CHECK(hashMap_containsKey(map, containsKey));
+ free(containsKey);
+ containsKey = my_strdup("notExisting");
+ CHECK(!hashMap_containsKey(map, containsKey));
+ free(containsKey);
+ containsKey = NULL;
+ CHECK(!hashMap_containsKey(map, containsKey));
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ containsKey = NULL;
+ CHECK(hashMap_containsKey(map, containsKey));
+
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map_hash, getEntry){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * getEntryKey;
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ hash_map_entry_pt entry;
+
+ hashMap_clear(map, false, false);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ // Get with new created key
+ getEntryKey = my_strdup("key");
+ entry = hashMap_getEntry(map, getEntryKey);
+ CHECK(entry != NULL);
+ STRCMP_EQUAL(key, (char*) entry->key);
+ STRCMP_EQUAL(value, (char*) entry->value);
+
+ free(getEntryKey);
+ getEntryKey = my_strdup("key2");
+ entry = hashMap_getEntry(map, getEntryKey);
+ CHECK(entry != NULL);
+ STRCMP_EQUAL(key2, (char*) entry->key);
+ STRCMP_EQUAL(value2, (char*) entry->value);
+
+ free(getEntryKey);
+ getEntryKey = my_strdup("notExisting");
+ entry = hashMap_getEntry(map, getEntryKey);
+ POINTERS_EQUAL(NULL, entry);
+
+ free(getEntryKey);
+ getEntryKey = NULL;
+ entry = hashMap_getEntry(map, getEntryKey);
+ POINTERS_EQUAL(NULL, entry);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ getEntryKey = NULL;
+ entry = hashMap_getEntry(map, getEntryKey);
+ CHECK_EQUAL(key3, entry->key);
+ STRCMP_EQUAL(value3, (char*) entry->value);
+
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map_hash, put){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * getKey = my_strdup("key");
+ char * get;
+ char * nkey2 = my_strdup("key2");
+ char * nvalue2 = my_strdup("value3");
+ char * old;
+ char * key3 = NULL;
+ char * value3 = my_strdup("value3");
+ char * key4 = my_strdup("key4");
+ char * value4 = NULL;
+
+ hashMap_clear(map, false, false);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ // Get with new key
+ get = (char*) hashMap_get(map, getKey);
+ STRCMP_EQUAL(value, get);
+
+ free(getKey);
+ getKey = my_strdup("key2");
+ get = (char*) hashMap_get(map, getKey);
+ STRCMP_EQUAL(value2, get);
+
+ // Overwrite existing entry
+ old = (char *) hashMap_put(map, nkey2, nvalue2);
+ CHECK(old != NULL);
+ STRCMP_EQUAL(value2, old);
+
+ free(getKey);
+ getKey = my_strdup("key2");
+ get = (char*) hashMap_get(map, key2);
+ STRCMP_EQUAL(nvalue2, get);
+
+ // Add third entry with NULL key
+ hashMap_put(map, key3, value3);
+
+ free(getKey);
+ getKey = NULL;
+ get = (char*) hashMap_get(map, key3);
+ STRCMP_EQUAL(value3, get);
+
+ // Add fourth entry with NULL value
+ hashMap_put(map, key4, value4);
+
+ getKey = my_strdup("key4");
+ get = (char*) hashMap_get(map, key4);
+ CHECK_EQUAL(value4, get);
+
+ free(getKey);
+ free(value2);
+ free(nkey2);
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map_hash, remove){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = NULL;
+ char * value2 = my_strdup("value2");
+ char * removeKey = my_strdup("unexisting");
+
+ hashMap_clear(map, false, false);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry with null key
+ hashMap_put(map, key2, value2);
+
+ // Remove unexisting entry for map
+ hashMap_remove(map, removeKey);
+ LONGS_EQUAL(2, map->size);
+ CHECK(!hashMap_isEmpty(map));
+
+ // Remove entry with new key
+ free(removeKey);
+ removeKey = my_strdup("key");
+ hashMap_remove(map, removeKey);
+ LONGS_EQUAL(1, map->size);
+
+ free(removeKey);
+ removeKey = NULL;
+ hashMap_remove(map, removeKey);
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
+
+ // Remove unexisting entry for empty map
+ removeKey = my_strdup("unexisting");
+ hashMap_remove(map, removeKey);
+ LONGS_EQUAL(0, map->size);
+ CHECK(hashMap_isEmpty(map));
+
+ free(removeKey);
+ free(key);
+ free(value);
+ free(value2);
+ hashMap_clear(map, true, true);
+}
+
+TEST(hash_map_hash, containsValue){
+ char * key = my_strdup("key");
+ char * value = my_strdup("value");
+ char * key2 = my_strdup("key2");
+ char * value2 = my_strdup("value2");
+ char * containsValue = my_strdup("value");
+ char * key3 = my_strdup("key3");
+ char * value3 = NULL;
+
+ hashMap_clear(map, false, false);
+
+ // Add one entry
+ hashMap_put(map, key, value);
+
+ // Add second entry
+ hashMap_put(map, key2, value2);
+
+ CHECK(hashMap_containsValue(map, containsValue));
+ free(containsValue);
+ containsValue = my_strdup("value2");
+ CHECK(hashMap_containsValue(map, containsValue));
+ free(containsValue);
+ containsValue = my_strdup("notExisting");
+ CHECK(!hashMap_containsValue(map, containsValue));
+ free(containsValue);
+ containsValue = NULL;
+ CHECK(!hashMap_containsValue(map, containsValue));
+
+ // Add third entry with NULL value
+ hashMap_put(map, key3, value3);
+
+ containsValue = NULL;
+ CHECK(hashMap_containsValue(map, containsValue));
+
+ hashMap_clear(map, true, true);
+}
[16/20] celix git commit: CELIX-180: Fixed some framework tests
Posted by pn...@apache.org.
CELIX-180: Fixed some framework tests
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/86e6094e
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/86e6094e
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/86e6094e
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 86e6094e263f9a22a78b7cbd6191448a2705229e
Parents: 673b5c7
Author: Bjoern Petri <bp...@apache.org>
Authored: Tue Oct 6 14:30:40 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Tue Oct 6 14:30:40 2015 +0200
----------------------------------------------------------------------
framework/CMakeLists.txt | 82 ++++++++++-----------
framework/private/mock/bundle_context_mock.c | 25 ++-----
framework/private/mock/bundle_mock.c | 13 +---
framework/private/mock/framework_mock.c | 6 +-
framework/private/test/bundle_context_test.cpp | 75 ++++++++-----------
5 files changed, 85 insertions(+), 116 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/86e6094e/framework/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt
index 337c82d..0a7452d 100644
--- a/framework/CMakeLists.txt
+++ b/framework/CMakeLists.txt
@@ -92,7 +92,7 @@ if (FRAMEWORK)
private/src/attribute.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(attribute_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
+ target_link_libraries(attribute_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
add_executable(bundle_archive_test
private/test/bundle_archive_test.cpp
@@ -100,7 +100,7 @@ if (FRAMEWORK)
private/src/bundle_archive.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(bundle_archive_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
+ target_link_libraries(bundle_archive_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
add_executable(bundle_cache_test
private/test/bundle_cache_test.cpp
@@ -109,8 +109,8 @@ if (FRAMEWORK)
private/src/bundle_cache.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(bundle_cache_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(bundle_cache_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(bundle_context_test
private/test/bundle_context_test.cpp
private/mock/bundle_mock.c
@@ -118,8 +118,8 @@ if (FRAMEWORK)
private/src/bundle_context.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(bundle_context_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(bundle_context_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(bundle_revision_test
private/test/bundle_revision_test.cpp
private/mock/miniunz_mock.c
@@ -127,8 +127,8 @@ if (FRAMEWORK)
private/src/bundle_revision.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(bundle_revision_test ${ZLIB_LIBRARY} ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(bundle_revision_test ${ZLIB_LIBRARY} ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(bundle_test
private/test/bundle_test.cpp
private/mock/framework_mock.c
@@ -141,8 +141,8 @@ if (FRAMEWORK)
private/src/bundle.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(bundle_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(bundle_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(capability_test
private/test/capability_test.cpp
private/mock/attribute_mock.c
@@ -150,16 +150,16 @@ if (FRAMEWORK)
private/src/capability.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(capability_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(capability_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(filter_test
private/test/filter_test.cpp
private/mock/properties_mock.c
private/src/filter.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(filter_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(filter_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(framework_test
private/test/framework_test.cpp
private/mock/properties_mock.c
@@ -179,7 +179,7 @@ if (FRAMEWORK)
private/src/celix_errorcodes.c
private/src/celix_log.c
private/src/framework.c)
- target_link_libraries(framework_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} ${UUID} celix_utils)
+ target_link_libraries(framework_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} ${UUID} celix_utils pthread dl)
add_executable(manifest_parser_test
private/test/manifest_parser_test.cpp
@@ -192,8 +192,8 @@ if (FRAMEWORK)
private/src/manifest_parser.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(manifest_parser_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(manifest_parser_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(manifest_test
private/test/manifest_test.cpp
private/mock/properties_mock.c
@@ -201,8 +201,8 @@ if (FRAMEWORK)
private/src/manifest.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(manifest_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(manifest_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(module_test
private/test/module_test.cpp
private/mock/bundle_mock.c
@@ -213,15 +213,15 @@ if (FRAMEWORK)
private/mock/requirement_mock.c
private/mock/wire_mock.c
private/src/module.c)
- target_link_libraries(module_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(module_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(properties_test
private/test/properties_test.cpp
private/src/utils.c
private/src/properties.c)
- target_link_libraries(properties_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
-
+ target_link_libraries(properties_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
+
add_executable(requirement_test
private/test/requirement_test.cpp
private/mock/attribute_mock.c
@@ -230,8 +230,8 @@ if (FRAMEWORK)
private/src/requirement.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(requirement_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(requirement_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(resolver_test
private/test/resolver_test.cpp
private/mock/bundle_mock.c
@@ -242,8 +242,8 @@ if (FRAMEWORK)
private/src/resolver.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(resolver_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(resolver_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(service_reference_test
private/test/service_reference_test.cpp
private/mock/properties_mock.c
@@ -252,18 +252,18 @@ if (FRAMEWORK)
private/src/service_reference.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(service_reference_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
- add_executable(service_registration_test
+ target_link_libraries(service_reference_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
+ add_executable(service_registration_test
private/test/service_registration_test.cpp
private/mock/properties_mock.c
private/mock/service_registry_mock.c
private/src/service_registration.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(service_registration_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
-
+ target_link_libraries(service_registration_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
+
add_executable(service_registry_test
private/test/service_registry_test.cpp
private/mock/framework_mock.c
@@ -275,16 +275,16 @@ if (FRAMEWORK)
private/src/service_registry.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(service_registry_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(service_registry_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(service_tracker_customizer_test
private/test/service_tracker_customizer_test.cpp
private/mock/service_reference_mock.c
private/src/service_tracker_customizer.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(service_tracker_customizer_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(service_tracker_customizer_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(service_tracker_test
private/test/service_tracker_test.cpp
private/mock/bundle_context_mock.c
@@ -293,12 +293,12 @@ if (FRAMEWORK)
private/src/service_tracker.c
private/src/celix_errorcodes.c
private/src/celix_log.c)
- target_link_libraries(service_tracker_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
+ target_link_libraries(service_tracker_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
add_executable(utils_test
private/test/utils_test.cpp private/src/utils.c)
- target_link_libraries(utils_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils)
-
+ target_link_libraries(utils_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread)
+
add_executable(version_range_test
private/test/version_range_test.cpp
private/src/version_range.c
http://git-wip-us.apache.org/repos/asf/celix/blob/86e6094e/framework/private/mock/bundle_context_mock.c
----------------------------------------------------------------------
diff --git a/framework/private/mock/bundle_context_mock.c b/framework/private/mock/bundle_context_mock.c
index c5bdbdb..9d3d79a 100644
--- a/framework/private/mock/bundle_context_mock.c
+++ b/framework/private/mock/bundle_context_mock.c
@@ -27,12 +27,11 @@
#include "bundle_context.h"
-celix_status_t bundleContext_create(apr_pool_t *pool, framework_pt framework, framework_logger_pt logger, bundle_pt bundle, bundle_context_pt *bundle_context) {
- mock_c()->actualCall("bundleContext_create")
- ->withPointerParameters("pool", pool)
- ->withPointerParameters("framework", framework)
- ->withPointerParameters("logger", logger)
- ->withPointerParameters("bundle", bundle)
+celix_status_t bundleContext_create(framework_pt framework, framework_logger_pt logger, bundle_pt bundle, bundle_context_pt *bundle_context) {
+ mock_c()->actualCall("bundleContext_create")
+ ->withPointerParameters("framework", framework)
+ ->withPointerParameters("logger", logger)
+ ->withPointerParameters("bundle", bundle)
->withOutputParameter("bundle_context", (void **) bundle_context);
return mock_c()->returnValue().value.intValue;
}
@@ -51,20 +50,12 @@ celix_status_t bundleContext_getFramework(bundle_context_pt context, framework_p
mock_c()->actualCall("bundleContext_getFramework")
->withPointerParameters("context", context)
->withOutputParameter("framework", (void **) framework);
- return mock_c()->returnValue().value.intValue;
+ return mock_c()->returnValue().value.intValue;
}
-celix_status_t bundleContext_getMemoryPool(bundle_context_pt context, apr_pool_t **memory_pool) {
- mock_c()->actualCall("bundleContext_getMemoryPool")
- ->withPointerParameters("context", context)
- ->withOutputParameter("memory_pool", (void **) memory_pool);
- return mock_c()->returnValue().value.intValue;
-}
-
-
celix_status_t bundleContext_installBundle(bundle_context_pt context, char * location, bundle_pt *bundle) {
- mock_c()->actualCall("bundleContext_installBundle")
- ->withPointerParameters("context", context)
+ mock_c()->actualCall("bundleContext_installBundle")
+ ->withPointerParameters("context", context)
->withStringParameters("location", location)
->withOutputParameter("bundle", (void **) bundle);
return mock_c()->returnValue().value.intValue;
http://git-wip-us.apache.org/repos/asf/celix/blob/86e6094e/framework/private/mock/bundle_mock.c
----------------------------------------------------------------------
diff --git a/framework/private/mock/bundle_mock.c b/framework/private/mock/bundle_mock.c
index d82e78e..7b304c3 100644
--- a/framework/private/mock/bundle_mock.c
+++ b/framework/private/mock/bundle_mock.c
@@ -196,20 +196,11 @@ celix_status_t bundle_getRegisteredServices(bundle_pt bundle, array_list_pt *lis
}
celix_status_t bundle_getServicesInUse(bundle_pt bundle, array_list_pt *list) {
- return mock_c()->returnValue().value.intValue;
+ return mock_c()->returnValue().value.intValue;
}
-
-celix_status_t bundle_getMemoryPool(bundle_pt bundle, apr_pool_t **pool) {
- mock_c()->actualCall("bundle_getMemoryPool")
- ->withPointerParameters("bundle", bundle)
- ->withOutputParameter("pool", (void **) pool);
- return mock_c()->returnValue().value.intValue;
-}
-
-
celix_status_t bundle_setFramework(bundle_pt bundle, framework_pt framework) {
- return mock_c()->returnValue().value.intValue;
+ return mock_c()->returnValue().value.intValue;
}
celix_status_t bundle_getFramework(bundle_pt bundle, framework_pt *framework) {
http://git-wip-us.apache.org/repos/asf/celix/blob/86e6094e/framework/private/mock/framework_mock.c
----------------------------------------------------------------------
diff --git a/framework/private/mock/framework_mock.c b/framework/private/mock/framework_mock.c
index 41db4c8..d027df9 100644
--- a/framework/private/mock/framework_mock.c
+++ b/framework/private/mock/framework_mock.c
@@ -27,9 +27,9 @@
#include "framework_private.h"
-celix_status_t framework_create(framework_pt *framework, apr_pool_t *memoryPool, properties_pt config) {
- mock_c()->actualCall("framework_create");
- return mock_c()->returnValue().value.intValue;
+celix_status_t framework_create(framework_pt *framework, properties_pt config) {
+ mock_c()->actualCall("framework_create");
+ return mock_c()->returnValue().value.intValue;
}
celix_status_t framework_destroy(framework_pt framework) {
http://git-wip-us.apache.org/repos/asf/celix/blob/86e6094e/framework/private/test/bundle_context_test.cpp
----------------------------------------------------------------------
diff --git a/framework/private/test/bundle_context_test.cpp b/framework/private/test/bundle_context_test.cpp
index 8b9ed51..db2792d 100644
--- a/framework/private/test/bundle_context_test.cpp
+++ b/framework/private/test/bundle_context_test.cpp
@@ -19,7 +19,7 @@
/*
* bundle_context_test.cpp
*
- * \date Feb 11, 2013
+ * \date Sep 14, 2015
* \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
* \copyright Apache License, Version 2.0
*/
@@ -56,13 +56,13 @@ TEST_GROUP(bundle_context) {
TEST(bundle_context, create) {
framework_pt framework = (framework_pt) 0x10;
- bundle_pt bundle = (bundle_pt) 0x20;
+ bundle_pt bundle = (bundle_pt) 0x20;
- bundle_context_pt context = NULL;
- bundleContext_create(NULL, framework, logger, bundle, &context);
- POINTERS_EQUAL(framework, context->framework)
- POINTERS_EQUAL(bundle, context->bundle)
-// CHECK(context->pool);
+ bundle_context_pt context = NULL;
+ bundleContext_create(framework, logger, bundle, &context);
+ POINTERS_EQUAL(framework, context->framework)
+ POINTERS_EQUAL(bundle, context->bundle)
+// CHECK(context->pool);
}
TEST(bundle_context, destroy) {
@@ -80,54 +80,41 @@ TEST(bundle_context, destroy) {
}
TEST(bundle_context, getBundle) {
- bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context));
- framework_pt framework = (framework_pt) 0x10;
- bundle_pt bundle = (bundle_pt) 0x20;
- apr_pool_t *pool = (apr_pool_t *) 0x30;
- context->framework = framework;
- context->bundle = bundle;
- context->pool = pool;
-
- celix_status_t status;
- bundle_pt actualBundle = NULL;
+ bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context));
+ framework_pt framework = (framework_pt) 0x10;
+ bundle_pt bundle = (bundle_pt) 0x20;
+ context->framework = framework;
+ context->bundle = bundle;
+
+ celix_status_t status;
+ bundle_pt actualBundle = NULL;
status = bundleContext_getBundle(context, &actualBundle);
LONGS_EQUAL(CELIX_SUCCESS, status);
POINTERS_EQUAL(bundle, actualBundle);
framework_pt actualFramework = NULL;
status = bundleContext_getFramework(context, &actualFramework);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- POINTERS_EQUAL(framework, actualFramework);
-
- apr_pool_t *actualPool = NULL;
- status = bundleContext_getMemoryPool(context, &actualPool);
- LONGS_EQUAL(CELIX_SUCCESS, status);
- POINTERS_EQUAL(pool, actualPool);
-
- actualBundle = NULL;
- status = bundleContext_getBundle(NULL, &actualBundle);
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
+ LONGS_EQUAL(CELIX_SUCCESS, status);
+ POINTERS_EQUAL(framework, actualFramework);
- actualFramework = NULL;
- status = bundleContext_getFramework(NULL, &actualFramework);
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
+ actualBundle = NULL;
+ status = bundleContext_getBundle(NULL, &actualBundle);
+ LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
- actualPool = NULL;
- status = bundleContext_getMemoryPool(NULL, &actualPool);
- LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
+ actualFramework = NULL;
+ status = bundleContext_getFramework(NULL, &actualFramework);
+ LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status);
}
TEST(bundle_context, installBundle) {
- bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context));
- framework_pt framework = (framework_pt) 0x10;
- bundle_pt bundle = (bundle_pt) 0x20;
- apr_pool_t *pool = (apr_pool_t *) 0x30;
- context->framework = framework;
- context->bundle = bundle;
- context->pool = pool;
-
- char location[] = "test.zip";
- bundle_pt installedBundle = (bundle_pt) 0x40;
+ bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context));
+ framework_pt framework = (framework_pt) 0x10;
+ bundle_pt bundle = (bundle_pt) 0x20;
+ context->framework = framework;
+ context->bundle = bundle;
+
+ char location[] = "test.zip";
+ bundle_pt installedBundle = (bundle_pt) 0x40;
mock().expectOneCall("fw_installBundle")
.withParameter("framework", framework)
.withParameter("location", location)
[13/20] celix git commit: CELIX-263: Fixed travis setup
Posted by pn...@apache.org.
CELIX-263: Fixed travis setup
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/80b9ec14
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/80b9ec14
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/80b9ec14
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 80b9ec144cdad1e013742c011eb79c0e7c9b99a1
Parents: bb62be8
Author: Bjoern Petri <bp...@apache.org>
Authored: Tue Oct 6 08:35:06 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Tue Oct 6 08:35:06 2015 +0200
----------------------------------------------------------------------
.travis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/80b9ec14/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index 8d3b6bc..5d0a676 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -17,7 +17,7 @@ before_script:
script:
- cd build
- - cmake -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=ON -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DBUILD_DEVICE_ACCESS=ON -DBUILD_DEVICE_ACCESS_EXAMPLE=ON -DBUILD_UTILS-TESTS=ON -DCPPUTEST_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_LIBRARY=$HOME/cpputest/libCppUTest.a -DCPPUTEST_EXT_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_EXT_LIBRARY=$HOME/cpputest/libCppUTestExt.a -DCMAKE_INSTALL_PREFIX=../install ..
+ - cmake -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=ON -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DBUILD_DEVICE_ACCESS=ON -DBUILD_DEVICE_ACCESS_EXAMPLE=ON -DBUILD_UTILS-TESTS=ON -DCPPUTEST_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_LIBRARY=$HOME/cpputest/lib/libCppUTest.a -DCPPUTEST_EXT_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_EXT_LIBRARY=$HOME/cpputest/lib/libCppUTestExt.a -DCMAKE_INSTALL_PREFIX=../install ..
- make all && make deploy && make install-all
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/utils && ./utils/array_list_test && ./utils/celix_threads_test && ./utils/linked_list_test && ./utils/hash_map_test
[08/20] celix git commit: CELIX-264: Added missing strdup
Posted by pn...@apache.org.
CELIX-264: Added missing strdup
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/d632500e
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/d632500e
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/d632500e
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: d632500e7f764da5cd887d2ae788044d2c105a4f
Parents: 5498452
Author: Bjoern Petri <bp...@apache.org>
Authored: Sat Oct 3 12:48:14 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Sat Oct 3 12:48:14 2015 +0200
----------------------------------------------------------------------
remote_services/discovery/private/src/endpoint_discovery_server.c | 3 +--
.../private/src/remote_service_admin_impl.c | 2 +-
2 files changed, 2 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/d632500e/remote_services/discovery/private/src/endpoint_discovery_server.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/endpoint_discovery_server.c b/remote_services/discovery/private/src/endpoint_discovery_server.c
index 930be59..9c41a4d 100644
--- a/remote_services/discovery/private/src/endpoint_discovery_server.c
+++ b/remote_services/discovery/private/src/endpoint_discovery_server.c
@@ -86,7 +86,6 @@ celix_status_t endpointDiscoveryServer_create(discovery_pt discovery, bundle_con
}
(*server)->loghelper = &discovery->loghelper;
-
(*server)->entries = hashMap_create(&utils_stringHash, NULL, &utils_stringEquals, NULL);
if (!(*server)->entries) {
return CELIX_ENOMEM;
@@ -121,7 +120,7 @@ celix_status_t endpointDiscoveryServer_create(discovery_pt discovery, bundle_con
}
else {
logHelper_log(*(*server)->loghelper, OSGI_LOGSERVICE_WARNING, "No IP address for service annunciation set. Using %s", DEFAULT_SERVER_IP);
- (*server)->ip = (char*) DEFAULT_SERVER_IP;
+ (*server)->ip = strdup((char*) DEFAULT_SERVER_IP);
}
if (detectedIp != NULL) {
http://git-wip-us.apache.org/repos/asf/celix/blob/d632500e/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
index 01b2abb..023d8fb 100644
--- a/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
+++ b/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
@@ -150,7 +150,7 @@ celix_status_t remoteServiceAdmin_create(bundle_context_pt context, remote_servi
}
else {
logHelper_log((*admin)->loghelper, OSGI_LOGSERVICE_WARNING, "RSA: No IP address for service annunciation set. Using %s", DEFAULT_IP);
- (*admin)->ip = (char*) DEFAULT_IP;
+ (*admin)->ip = strdup((char*) DEFAULT_IP);
}
if (detectedIp != NULL) {
[03/20] celix git commit: CELIX-258: rename framework bundleActivator
to frameworkActivator
Posted by pn...@apache.org.
CELIX-258: rename framework bundleActivator to frameworkActivator
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/7e3b33f6
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/7e3b33f6
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/7e3b33f6
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 7e3b33f625e6f00b285d5ce9db3020ece4bccc1f
Parents: e59dea5
Author: Bjoern Petri <bp...@apache.org>
Authored: Fri Sep 25 19:12:03 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Fri Sep 25 19:12:03 2015 +0200
----------------------------------------------------------------------
framework/private/src/framework.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/7e3b33f6/framework/private/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/private/src/framework.c b/framework/private/src/framework.c
index 6aad985..e0391e7 100644
--- a/framework/private/src/framework.c
+++ b/framework/private/src/framework.c
@@ -104,6 +104,11 @@ static celix_status_t framework_loadBundleLibraries(framework_pt framework, bund
static celix_status_t framework_loadLibraries(framework_pt framework, char *libraries, char *activator, bundle_archive_pt archive, void **activatorHandle);
static celix_status_t framework_loadLibrary(framework_pt framework, char *library, bundle_archive_pt archive, void **handle);
+static celix_status_t frameworkActivator_start(void * userData, bundle_context_pt context);
+static celix_status_t frameworkActivator_stop(void * userData, bundle_context_pt context);
+static celix_status_t frameworkActivator_destroy(void * userData, bundle_context_pt context);
+
+
struct fw_refreshHelper {
framework_pt framework;
bundle_pt bundle;
@@ -2303,12 +2308,12 @@ celix_status_t fw_invokeFrameworkListener(framework_pt framework, framework_list
return ret;
}
-celix_status_t frameworkActivator_start(void * userData, bundle_context_pt context) {
+static celix_status_t frameworkActivator_start(void * userData, bundle_context_pt context) {
// nothing to do
return CELIX_SUCCESS;
}
-celix_status_t frameworkActivator_stop(void * userData, bundle_context_pt context) {
+static celix_status_t frameworkActivator_stop(void * userData, bundle_context_pt context) {
celix_status_t status = CELIX_SUCCESS;
celix_thread_t shutdownThread;
@@ -2333,7 +2338,7 @@ celix_status_t frameworkActivator_stop(void * userData, bundle_context_pt contex
return status;
}
-celix_status_t frameworkActivator_destroy(void * userData, bundle_context_pt context) {
+static celix_status_t frameworkActivator_destroy(void * userData, bundle_context_pt context) {
return CELIX_SUCCESS;
}
[17/20] celix git commit: CELIX-180: enable build of framework tests
Posted by pn...@apache.org.
CELIX-180: enable build of framework tests
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/7215825e
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/7215825e
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/7215825e
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 7215825e428ef20390f82c86eea1a160df4b388a
Parents: 86e6094
Author: Bjoern Petri <bp...@apache.org>
Authored: Wed Oct 7 09:41:52 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Wed Oct 7 09:41:52 2015 +0200
----------------------------------------------------------------------
.travis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/7215825e/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index a898cb2..1814464 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -17,7 +17,7 @@ before_script:
script:
- cd build
- - cmake -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=ON -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DBUILD_DEVICE_ACCESS=ON -DBUILD_DEVICE_ACCESS_EXAMPLE=ON -DBUILD_UTILS-TESTS=ON -DCPPUTEST_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_LIBRARY=$HOME/cpputest/lib/libCppUTest.a -DCPPUTEST_EXT_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_EXT_LIBRARY=$HOME/cpputest/lib/libCppUTestExt.a -DCMAKE_INSTALL_PREFIX=../install ..
+ - cmake -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=ON -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DBUILD_DEVICE_ACCESS=ON -DBUILD_DEVICE_ACCESS_EXAMPLE=ON -DBUILD_FRAMEWORK_TESTS=ON -DBUILD_UTILS-TESTS=ON -DCPPUTEST_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_LIBRARY=$HOME/cpputest/lib/libCppUTest.a -DCPPUTEST_EXT_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_EXT_LIBRARY=$HOME/cpputest/lib/libCppUTestExt.a -DCMAKE_INSTALL_PREFIX=../install ..
- make all && make deploy && make install-all
- export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/utils && ./utils/array_list_test && ./utils/celix_threads_test && ./utils/linked_list_test && ./utils/hash_map_test
[14/20] celix git commit: CELIX-236: fixed some minor issues in test
implementation, converted thread initialization to be compatible with ISO C++
Posted by pn...@apache.org.
CELIX-236: fixed some minor issues in test implementation, converted thread initialization to be compatible with ISO C++
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/ebbe2023
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/ebbe2023
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/ebbe2023
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: ebbe2023dcfff7e31429307fec0f619495d6a685
Parents: 80b9ec1
Author: Bjoern Petri <bp...@apache.org>
Authored: Tue Oct 6 09:20:19 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Tue Oct 6 09:20:19 2015 +0200
----------------------------------------------------------------------
utils/private/test/array_list_test.cpp | 6 ++----
utils/private/test/celix_threads_test.cpp | 16 +++++++++-------
utils/private/test/hash_map_test.cpp | 4 ++--
utils/public/include/celix_threads.h | 2 +-
4 files changed, 14 insertions(+), 14 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/ebbe2023/utils/private/test/array_list_test.cpp
----------------------------------------------------------------------
diff --git a/utils/private/test/array_list_test.cpp b/utils/private/test/array_list_test.cpp
index fbf09a9..8a2a04e 100644
--- a/utils/private/test/array_list_test.cpp
+++ b/utils/private/test/array_list_test.cpp
@@ -80,11 +80,10 @@ TEST(array_list, create) {
}
TEST(array_list, trimToSize) {
- bool added;
char * entry = my_strdup("entry");
arrayList_clear(list);
- added = arrayList_add(list, entry);
+ arrayList_add(list, entry);
LONGS_EQUAL(1, list->size);
LONGS_EQUAL(10, list->capacity);
@@ -103,9 +102,8 @@ TEST(array_list, ensureCapacity) {
LONGS_EQUAL(0, list->size);
for (i = 0; i < 100; i++) {
- bool added;
char * entry = my_strdup("entry");
- added = arrayList_add(list, entry);
+ arrayList_add(list, entry);
}
LONGS_EQUAL(133, list->capacity);
LONGS_EQUAL(100, list->size);
http://git-wip-us.apache.org/repos/asf/celix/blob/ebbe2023/utils/private/test/celix_threads_test.cpp
----------------------------------------------------------------------
diff --git a/utils/private/test/celix_threads_test.cpp b/utils/private/test/celix_threads_test.cpp
index b0ddd83..d5a01b4 100644
--- a/utils/private/test/celix_threads_test.cpp
+++ b/utils/private/test/celix_threads_test.cpp
@@ -276,22 +276,24 @@ TEST(celix_thread_condition, broadcast) {
static void * thread_test_func_create(void * arg) {
char ** test_str = (char**) arg;
*test_str = my_strdup("SUCCESS");
- celixThread_exit(NULL);
+
+ return NULL;
}
static void * thread_test_func_exit(void *) {
int *pi = (int*) calloc(1, sizeof(int));
*pi = 666;
- celixThread_exit(pi);
+
+ return pi;
}
static void * thread_test_func_detach(void *) {
- celixThread_exit(NULL);
+ return NULL;
}
static void * thread_test_func_self(void * arg) {
*((celix_thread*) arg) = celixThread_self();
- celixThread_exit(NULL);
+ return NULL;
}
static void * thread_test_func_lock(void *arg) {
@@ -303,7 +305,7 @@ static void * thread_test_func_lock(void *arg) {
celixThreadMutex_unlock(¶m->mu);
celixThreadMutex_unlock(¶m->mu2);
- celixThread_exit(NULL);
+ return NULL;
}
static void * thread_test_func_cond_wait(void *arg) {
@@ -315,7 +317,7 @@ static void * thread_test_func_cond_wait(void *arg) {
celixThreadCondition_signal(¶m->cond);
celixThreadMutex_unlock(¶m->mu);
- celixThread_exit(NULL);
+ return NULL;
}
static void * thread_test_func_cond_broadcast(void *arg) {
@@ -327,7 +329,7 @@ static void * thread_test_func_cond_broadcast(void *arg) {
celixThreadMutex_lock(¶m->mu2);
param->i++;
celixThreadMutex_unlock(¶m->mu2);
- celixThread_exit(NULL);
+ return NULL;
}
static int thread_test_func_recur_lock(celix_thread_mutex_t *mu, int i) {
http://git-wip-us.apache.org/repos/asf/celix/blob/ebbe2023/utils/private/test/hash_map_test.cpp
----------------------------------------------------------------------
diff --git a/utils/private/test/hash_map_test.cpp b/utils/private/test/hash_map_test.cpp
index 1ef9337..024655d 100644
--- a/utils/private/test/hash_map_test.cpp
+++ b/utils/private/test/hash_map_test.cpp
@@ -66,7 +66,7 @@ unsigned int test_hashKeyChar(void * k) {
unsigned int hash = 1315423911;
unsigned int i = 0;
- int len = strlen(str);
+ unsigned int len = strlen(str);
for(i = 0; i < len; str++, i++)
{
@@ -77,6 +77,7 @@ unsigned int test_hashKeyChar(void * k) {
}
unsigned int test_hashValueChar(void * v) {
+ (void)(v);
return 0;
}
@@ -381,7 +382,6 @@ TEST(hash_map, put){
TEST(hash_map, resize){
int i;
- char * k;
char key[6];
LONGS_EQUAL(0, map->size);
http://git-wip-us.apache.org/repos/asf/celix/blob/ebbe2023/utils/public/include/celix_threads.h
----------------------------------------------------------------------
diff --git a/utils/public/include/celix_threads.h b/utils/public/include/celix_threads.h
index 242842b..253ebf8 100644
--- a/utils/public/include/celix_threads.h
+++ b/utils/public/include/celix_threads.h
@@ -44,7 +44,7 @@ typedef pthread_attr_t celix_thread_attr_t;
typedef void *(*celix_thread_start_t)(void*);
-static const celix_thread_t celix_thread_default = { .threadInitialized = false };
+static const celix_thread_t celix_thread_default = { 0, 0 };
celix_status_t celixThread_create(celix_thread_t *new_thread, celix_thread_attr_t *attr, celix_thread_start_t func, void *data);
[10/20] celix git commit: CELIX-263: replaced utils cunit tests w/
cpputests
Posted by pn...@apache.org.
http://git-wip-us.apache.org/repos/asf/celix/blob/c6d2d59f/utils/private/test/hash_map_test_hash.c
----------------------------------------------------------------------
diff --git a/utils/private/test/hash_map_test_hash.c b/utils/private/test/hash_map_test_hash.c
deleted file mode 100644
index 5c74f03..0000000
--- a/utils/private/test/hash_map_test_hash.c
+++ /dev/null
@@ -1,359 +0,0 @@
-/**
- *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.
- */
-/*
- * hash_map_test_hash.c
- *
- * \date Jul 25, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <string.h>
-#include <stddef.h>
-
-#include <CUnit/Automated.h>
-
-#include "hash_map.h"
-#include "hash_map_private.h"
-
-hash_map_pt map;
-
-unsigned int test_hashKeyChar(void * k) {
- char * str = (char *) k;
-
- unsigned int hash = 1315423911;
- unsigned int i = 0;
- int len = strlen(str);
-
- for(i = 0; i < len; str++, i++)
- {
- hash ^= ((hash << 5) + (*str) + (hash >> 2));
- }
-
- return hash;
-}
-
-unsigned int test_hashValueChar(void * v) {
- return 0;
-}
-
-int test_equalsKeyChar(void * k, void * o) {
- return strcmp((char *)k, (char *) o) == 0;
-}
-
-int test_equalsValueChar(void * v, void * o) {
- return strcmp((char *)v, (char *) o) == 0;
-}
-
-int setup(void) {
- printf("test\n");
- map = hashMap_create(test_hashKeyChar, test_hashValueChar, test_equalsKeyChar, test_equalsValueChar);
- if(map == NULL) {
- return 1;
- }
- return 0;
-}
-
-void test_hashMap_get(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char * getKey = strdup("key");
- char * get;
- char * neKey;
- char * key3 = NULL;
- char * value3 = "value3";
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- // Get with new created key
- getKey = strdup("key");
- get = hashMap_get(map, getKey);
- CU_ASSERT_PTR_NOT_NULL_FATAL(get);
- CU_ASSERT_STRING_EQUAL(get, value);
-
- getKey = strdup("key2");
- get = hashMap_get(map, getKey);
- CU_ASSERT_PTR_NOT_NULL_FATAL(get);
- CU_ASSERT_STRING_EQUAL(get, value2);
-
- neKey = strdup("notExisting");
- get = hashMap_get(map, neKey);
- CU_ASSERT_EQUAL(get, NULL);
-
- get = hashMap_get(map, NULL);
- CU_ASSERT_EQUAL(get, NULL);
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- get = hashMap_get(map, NULL);
- CU_ASSERT_STRING_EQUAL(get, value3);
-}
-
-void test_hashMap_containsKey(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char * containsKey;
- char * key3 = NULL;
- char * value3 = "value3";
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- containsKey = strdup("key");
- CU_ASSERT_TRUE(hashMap_containsKey(map, containsKey));
- containsKey = strdup("key2");
- CU_ASSERT_TRUE(hashMap_containsKey(map, containsKey));
- containsKey = strdup("notExisting");
- CU_ASSERT_FALSE(hashMap_containsKey(map, containsKey));
- containsKey = NULL;
- CU_ASSERT_FALSE(hashMap_containsKey(map, containsKey));
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- containsKey = NULL;
- CU_ASSERT_TRUE(hashMap_containsKey(map, containsKey));
-}
-
-void test_hashMap_getEntry(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char * getEntryKey;
- char * key3 = NULL;
- char * value3 = "value3";
- hash_map_entry_pt entry;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- // Get with new created key
- getEntryKey = strdup("key");
- entry = hashMap_getEntry(map, getEntryKey);
- CU_ASSERT_PTR_NOT_NULL_FATAL(entry);
- CU_ASSERT_STRING_EQUAL(entry->key, key);
- CU_ASSERT_STRING_EQUAL(entry->value, value);
-
- getEntryKey = strdup("key2");
- entry = hashMap_getEntry(map, getEntryKey);
- CU_ASSERT_PTR_NOT_NULL(entry);
- CU_ASSERT_STRING_EQUAL(entry->key, key2);
- CU_ASSERT_STRING_EQUAL(entry->value, value2);
-
- getEntryKey = strdup("notExisting");
- entry = hashMap_getEntry(map, getEntryKey);
- CU_ASSERT_EQUAL(entry, NULL);
-
- getEntryKey = NULL;
- entry = hashMap_getEntry(map, getEntryKey);
- CU_ASSERT_EQUAL(entry, NULL);
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- getEntryKey = NULL;
- entry = hashMap_getEntry(map, getEntryKey);
- CU_ASSERT_EQUAL(entry->key, key3);
- CU_ASSERT_STRING_EQUAL(entry->value, value3);
-}
-
-void test_hashMap_put(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char * getKey;
- char * get;
- char * nkey2 = strdup("key2");
- char * nvalue2 = "value3";
- char * old;
- char * key3 = NULL;
- char * value3 = "value3";
- char * key4 = "key4";
- char * value4 = NULL;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- // Get with new key
- getKey = strdup("key");
- get = hashMap_get(map, getKey);
- CU_ASSERT_STRING_EQUAL(get, value);
-
- getKey = strdup("key2");
- get = hashMap_get(map, getKey);
- CU_ASSERT_STRING_EQUAL(get, value2);
-
- // Overwrite existing entry
- old = (char *) hashMap_put(map, nkey2, nvalue2);
- CU_ASSERT_PTR_NOT_NULL_FATAL(old);
- CU_ASSERT_STRING_EQUAL(old, value2)
-
- getKey = strdup("key2");
- get = hashMap_get(map, key2);
- CU_ASSERT_STRING_EQUAL(get, nvalue2);
-
- // Add third entry with NULL key
- hashMap_put(map, key3, value3);
-
- getKey = NULL;
- get = hashMap_get(map, key3);
- CU_ASSERT_STRING_EQUAL(get, value3);
-
- // Add fourth entry with NULL value
- hashMap_put(map, key4, value4);
-
- getKey = strdup("key4");
- get = hashMap_get(map, key4);
- CU_ASSERT_EQUAL(get, value4);
-}
-
-void test_hashMap_remove(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = NULL;
- char * value2 = "value2";
- char * removeKey;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry with null key
- hashMap_put(map, key2, value2);
-
- // Remove unexisting entry for map
- removeKey = strdup("unexisting");
- hashMap_remove(map, removeKey);
- CU_ASSERT_EQUAL(map->size, 2);
- CU_ASSERT_FALSE(hashMap_isEmpty(map));
-
- // Remove entry with new key
- removeKey = strdup("key");
- hashMap_remove(map, removeKey);
- CU_ASSERT_EQUAL(map->size, 1);
-
- removeKey = NULL;
- hashMap_remove(map, removeKey);
- CU_ASSERT_EQUAL(map->size, 0);
- CU_ASSERT_TRUE(hashMap_isEmpty(map));
-
- // Remove unexisting entry for empty map
- removeKey = strdup("unexisting");
- hashMap_remove(map, removeKey);
- CU_ASSERT_EQUAL(map->size, 0);
- CU_ASSERT_TRUE(hashMap_isEmpty(map));
-}
-
-void test_hashMap_containsValue(void) {
- char * key = "key";
- char * value = "value";
- char * key2 = "key2";
- char * value2 = "value2";
- char * containsValue;
- char * key3 = "key3";
- char * value3 = NULL;
-
- hashMap_clear(map, false, false);
-
- // Add one entry
- hashMap_put(map, key, value);
-
- // Add second entry
- hashMap_put(map, key2, value2);
-
- containsValue = strdup("value");
- CU_ASSERT_TRUE(hashMap_containsValue(map, containsValue));
- containsValue = strdup("value2");
- CU_ASSERT_TRUE(hashMap_containsValue(map, containsValue));
- containsValue = strdup("notExisting");
- CU_ASSERT_FALSE(hashMap_containsValue(map, containsValue));
- containsValue = NULL;
- CU_ASSERT_FALSE(hashMap_containsValue(map, containsValue));
-
- // Add third entry with NULL value
- hashMap_put(map, key3, value3);
-
- containsValue = NULL;
- CU_ASSERT_TRUE(hashMap_containsValue(map, containsValue));
-}
-
-int main (int argc, char** argv) {
- CU_pSuite pSuite = NULL;
-
- /* initialize the CUnit test registry */
- if (CUE_SUCCESS != CU_initialize_registry())
- return CU_get_error();
-
- /* add a suite to the registry */
- pSuite = CU_add_suite("Suite_1", setup, NULL);
- if (NULL == pSuite) {
- CU_cleanup_registry();
- return CU_get_error();
- }
-
- /* add the tests to the suite */
- if (NULL == CU_add_test(pSuite, "Map Get Test", test_hashMap_get)
- || NULL == CU_add_test(pSuite, "Map Contains Key Test", test_hashMap_containsKey)
- || NULL == CU_add_test(pSuite, "Map Get Entry Test", test_hashMap_getEntry)
- || NULL == CU_add_test(pSuite, "Map Put Test", test_hashMap_put)
- || NULL == CU_add_test(pSuite, "Map Remove Test", test_hashMap_remove)
- || NULL == CU_add_test(pSuite, "Map Contains Value Test", test_hashMap_containsValue)
-
-
- )
- {
- CU_cleanup_registry();
- return CU_get_error();
- }
-
- CU_set_output_filename(argv[1]);
- CU_list_tests_to_file();
- CU_automated_run_tests();
- CU_cleanup_registry();
- return CU_get_error();
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/c6d2d59f/utils/private/test/linked_list_test.c
----------------------------------------------------------------------
diff --git a/utils/private/test/linked_list_test.c b/utils/private/test/linked_list_test.c
deleted file mode 100644
index 2635e88..0000000
--- a/utils/private/test/linked_list_test.c
+++ /dev/null
@@ -1,96 +0,0 @@
-/**
- *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.
- */
-/*
- * linked_list_test.c
- *
- * \date Jul 16, 2010
- * \author <a href="mailto:dev@celix.apache.org">Apache Celix Project Team</a>
- * \copyright Apache License, Version 2.0
- */
-#include <stdio.h>
-#include <stddef.h>
-
-#include <CUnit/Automated.h>
-#include "linked_list.h"
-
-linked_list_pt list;
-
-int setup(void) {
- linkedList_create(&list);
- if (list) {
- return 0;
- } else {
- // failure during setup
- return 1;
- }
-}
-
-int teardown(void) {
- return 0;
-}
-
-void test_linkedList_create(void) {
- CU_ASSERT_PTR_NOT_NULL_FATAL(list);
- CU_ASSERT_EQUAL(linkedList_size(list), 0);
-}
-
-void test_linkedList_add(void) {
- CU_ASSERT_EQUAL(linkedList_size(list), 0);
- linkedList_addElement(list, "element");
- CU_ASSERT_EQUAL(linkedList_size(list), 1);
-}
-
-void test_linkedList_remove(void) {
- CU_ASSERT_EQUAL(linkedList_size(list), 0);
- linkedList_addElement(list, "element");
- CU_ASSERT_EQUAL(linkedList_size(list), 1);
-
- linkedList_removeElement(list, "element");
- CU_ASSERT_EQUAL(linkedList_size(list), 0);
-}
-
-int main (int argc, char** argv) {
- CU_pSuite pSuite = NULL;
-
- /* initialize the CUnit test registry */
- if (CUE_SUCCESS != CU_initialize_registry())
- return CU_get_error();
-
- /* add a suite to the registry */
- pSuite = CU_add_suite("Suite_1", setup, teardown);
- if (NULL == pSuite) {
- CU_cleanup_registry();
- return CU_get_error();
- }
-
- /* add the tests to the suite */
- if (NULL == CU_add_test(pSuite, "List Creation Test", test_linkedList_create) ||
- NULL == CU_add_test(pSuite, "List Add Test", test_linkedList_add) ||
- NULL == CU_add_test(pSuite, "List Remove Test", test_linkedList_remove))
- {
- CU_cleanup_registry();
- return CU_get_error();
- }
-
- CU_set_output_filename(argv[1]);
- CU_list_tests_to_file();
- CU_automated_run_tests();
- CU_cleanup_registry();
- return CU_get_error();
-}
http://git-wip-us.apache.org/repos/asf/celix/blob/c6d2d59f/utils/private/test/linked_list_test.cpp
----------------------------------------------------------------------
diff --git a/utils/private/test/linked_list_test.cpp b/utils/private/test/linked_list_test.cpp
new file mode 100644
index 0000000..6a9e589
--- /dev/null
+++ b/utils/private/test/linked_list_test.cpp
@@ -0,0 +1,794 @@
+/**
+ *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.
+ */
+/*
+ * linked_list_test.cpp
+ *
+ * \date Sep 15, 2015
+ * \author Menno van der Graaf
+ * \copyright Apache License, Version 2.0
+ */
+#include <stdio.h>
+#include <stddef.h>
+#include <string.h>
+
+#include "CppUTest/TestHarness.h"
+#include "CppUTest/TestHarness_c.h"
+#include "CppUTest/CommandLineTestRunner.h"
+
+extern "C"
+{
+#include "linked_list.h"
+#include "linked_list_private.h"
+#include "linked_list_iterator.h"
+}
+
+int main(int argc, char** argv) {
+ return RUN_ALL_TESTS(argc, argv);
+}
+
+static char* my_strdup(const char* s){
+ char *d = (char*) malloc (strlen (s) + 1);
+ if (d == NULL) return NULL;
+ strcpy (d,s);
+ return d;
+}
+
+//----------------------TESTGROUP DEFINES----------------------
+
+TEST_GROUP(linked_list){
+ linked_list_pt list;
+
+ void setup(void) {
+ linkedList_create(&list);
+ }
+
+ void teardown(void) {
+ linkedList_destroy(list);
+ }
+};
+
+TEST_GROUP(linked_list_iterator){
+ linked_list_pt list;
+
+ void setup(void) {
+ linkedList_create(&list);
+ }
+
+ void teardown(void) {
+ linkedList_destroy(list);
+ }
+};
+
+//----------------------LINKED LIST TESTS----------------------
+
+TEST(linked_list, create){
+ CHECK(list != NULL);
+ LONGS_EQUAL(0, linkedList_size(list));
+}
+
+TEST(linked_list, add){
+ char * value = my_strdup("element");
+
+ LONGS_EQUAL(0, linkedList_size(list));
+ linkedList_addElement(list, value);
+ LONGS_EQUAL(1, linkedList_size(list));
+
+ free(value);
+}
+
+TEST(linked_list, addFirst){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+
+ STRCMP_EQUAL(value, (char*) linkedList_getFirst(list));
+
+ linkedList_addFirst(list, value3);
+
+ STRCMP_EQUAL(value3, (char*) linkedList_getFirst(list));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, addLast){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+
+ STRCMP_EQUAL(value2, (char*) linkedList_getLast(list));
+
+ linkedList_addLast(list, value3);
+
+ STRCMP_EQUAL(value3, (char*) linkedList_getLast(list));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, addIndex){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ char * value4 = my_strdup("element4");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+
+ linkedList_addIndex(list, 2, value4);
+
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value4, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 3));
+
+ free(value);
+ free(value2);
+ free(value3);
+ free(value4);
+}
+
+TEST(linked_list, addBefore){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ char * value4 = my_strdup("element4");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+
+ linkedList_addBefore(list, value4, linkedList_entry(list, 2));
+
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value4, (char*) linkedList_get(list, 2));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 3));
+
+ free(value);
+ free(value2);
+ free(value3);
+ free(value4);
+}
+
+TEST(linked_list, remove){
+ char * value = strdup("element");
+
+ LONGS_EQUAL(0, linkedList_size(list));
+ linkedList_addElement(list, value);
+ LONGS_EQUAL(1, linkedList_size(list));
+
+ linkedList_removeElement(list, value);
+ LONGS_EQUAL(0, linkedList_size(list));
+
+ free(value);
+}
+
+TEST(linked_list, removeFirst){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ STRCMP_EQUAL(value, (char*) linkedList_getFirst(list));
+
+ linkedList_removeFirst(list);
+
+ STRCMP_EQUAL(value2, (char*) linkedList_getFirst(list));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, removeLast){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ STRCMP_EQUAL(value3, (char*) linkedList_getLast(list));
+
+ linkedList_removeLast(list);
+
+ STRCMP_EQUAL(value2, (char*) linkedList_getLast(list));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, removeElement){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ //add 6 elemets
+ linkedList_addElement(list, NULL);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, NULL);
+ linkedList_addElement(list, value3);
+ LONGS_EQUAL(6, list->size);
+
+ linkedList_removeElement(list, NULL);
+ linkedList_removeElement(list, NULL);
+ LONGS_EQUAL(4, list->size);
+
+ linkedList_removeElement(list, value2);
+ LONGS_EQUAL(3, list->size);
+
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, removeIndex){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+
+ linkedList_removeIndex(list, 1);
+
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, removeEntry){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ linkedList_removeEntry(list, list->header);
+ LONGS_EQUAL(3, list->size);
+
+ linkedList_removeEntry(list, linkedList_entry(list, 0));
+ LONGS_EQUAL(2, list->size);
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, clone){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_pt list2;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ linkedList_clone(list, &list2);
+ LONGS_EQUAL(list->size, list2->size);
+ STRCMP_EQUAL( (char*) linkedList_getFirst(list), (char*) linkedList_getFirst(list2));
+ STRCMP_EQUAL( (char*) linkedList_getLast(list), (char*) linkedList_getLast(list2));
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedList_destroy(list2);
+}
+
+TEST(linked_list, clear){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ LONGS_EQUAL(3, list->size);
+
+ linkedList_clear(list);
+ LONGS_EQUAL(0, list->size);
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, get){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, getFirst){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ STRCMP_EQUAL(value, (char*) linkedList_getFirst(list));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, getLast){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ STRCMP_EQUAL(value3, (char*) linkedList_getLast(list));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, set){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+
+ linkedList_set(list, 1, value3);
+
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, contains){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ linkedList_addElement(list, value);
+ CHECK(linkedList_contains(list, value));
+ CHECK(!linkedList_contains(list, value2));
+ CHECK(!linkedList_contains(list, value3));
+
+ linkedList_addElement(list, value2);
+ CHECK(linkedList_contains(list, value));
+ CHECK(linkedList_contains(list, value2));
+ CHECK(!linkedList_contains(list, value3));
+
+ linkedList_addElement(list, value3);
+ CHECK(linkedList_contains(list, value));
+ CHECK(linkedList_contains(list, value2));
+ CHECK(linkedList_contains(list, value3));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, size){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ LONGS_EQUAL(0, linkedList_size(list));
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ LONGS_EQUAL(3, linkedList_size(list));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, isEmpty){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ CHECK(linkedList_isEmpty(list));
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ CHECK(!linkedList_isEmpty(list));
+
+ linkedList_clear(list);
+ CHECK(linkedList_isEmpty(list));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+TEST(linked_list, entry){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ char * value4 = my_strdup("element4");
+ char * value5 = my_strdup("element5");
+
+ POINTERS_EQUAL(NULL, linkedList_entry(list, 666));
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ linkedList_addElement(list, value4);
+ linkedList_addElement(list, value5);
+
+ STRCMP_EQUAL(value2, (char*) linkedList_entry(list, 1)->element);
+ STRCMP_EQUAL(value4, (char*) linkedList_entry(list, 3)->element);
+
+ free(value);
+ free(value2);
+ free(value3);
+ free(value4);
+ free(value5);
+}
+
+TEST(linked_list, indexOf){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+
+ LONGS_EQUAL(-1, linkedList_indexOf(list, value));
+ LONGS_EQUAL(-1, linkedList_indexOf(list, value2));
+ LONGS_EQUAL(-1, linkedList_indexOf(list, value3));
+ LONGS_EQUAL(-1, linkedList_indexOf(list, NULL));
+
+ linkedList_addElement(list, value);
+ LONGS_EQUAL(0, linkedList_indexOf(list, value));
+
+ linkedList_addElement(list, value2);
+ LONGS_EQUAL(1, linkedList_indexOf(list, value2));
+
+ linkedList_addElement(list, value3);
+ LONGS_EQUAL(2, linkedList_indexOf(list, value3));
+
+ linkedList_addElement(list, NULL);
+ LONGS_EQUAL(3, linkedList_indexOf(list, NULL));
+
+ free(value);
+ free(value2);
+ free(value3);
+}
+
+//----------------------LINKED LIST ITERATOR TESTS----------------------
+
+TEST(linked_list_iterator, create){
+ linked_list_iterator_pt it_list = linkedListIterator_create(list,0);
+ CHECK(it_list != NULL);
+ linkedListIterator_destroy(it_list);
+
+ it_list = linkedListIterator_create(list,666);
+ POINTERS_EQUAL(NULL, it_list);
+}
+
+TEST(linked_list_iterator, hasNext){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ it_list = linkedListIterator_create(list, 0);
+ CHECK(linkedListIterator_hasNext(it_list));
+
+ linkedListIterator_next(it_list);
+ CHECK(linkedListIterator_hasNext(it_list));
+
+ linkedListIterator_next(it_list);
+ CHECK(linkedListIterator_hasNext(it_list));
+
+ linkedListIterator_next(it_list);
+ CHECK(!linkedListIterator_hasNext(it_list));
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
+}
+
+TEST(linked_list_iterator, hasPrevious){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+
+ it_list = linkedListIterator_create(list, 3);
+ CHECK(linkedListIterator_hasPrevious(it_list));
+
+ linkedListIterator_previous(it_list);
+ CHECK(linkedListIterator_hasPrevious(it_list));
+
+ linkedListIterator_previous(it_list);
+ CHECK(linkedListIterator_hasPrevious(it_list));
+
+ linkedListIterator_previous(it_list);
+ CHECK(!linkedListIterator_hasPrevious(it_list));
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
+}
+
+TEST(linked_list_iterator, next){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 0);
+ STRCMP_EQUAL(value, (char*) linkedListIterator_next(it_list));
+ STRCMP_EQUAL(value2, (char*) linkedListIterator_next(it_list));
+ STRCMP_EQUAL(value3, (char*) linkedListIterator_next(it_list));
+ POINTERS_EQUAL(NULL, linkedListIterator_next(it_list));
+
+ //mess up the expected and real changecount, code should check and handle
+ linkedList_addElement(list, value);
+ linkedListIterator_next(it_list);
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
+}
+
+TEST(linked_list_iterator, previous){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 3);
+ STRCMP_EQUAL(value3, (char*) linkedListIterator_previous(it_list));
+ STRCMP_EQUAL(value2, (char*) linkedListIterator_previous(it_list));
+ STRCMP_EQUAL(value, (char*) linkedListIterator_previous(it_list));
+ POINTERS_EQUAL(NULL, linkedListIterator_previous(it_list));
+
+ //mess up the expected and real changecount, code should check and handle
+ linkedListIterator_destroy(it_list);
+ it_list = linkedListIterator_create(list, 3);
+ linkedList_addElement(list, value);
+ linkedListIterator_previous(it_list);
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
+}
+
+TEST(linked_list_iterator, nextIndex){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 0);
+ LONGS_EQUAL(0, linkedListIterator_nextIndex(it_list));
+ linkedListIterator_next(it_list);
+ LONGS_EQUAL(1, linkedListIterator_nextIndex(it_list));
+ linkedListIterator_next(it_list);
+ LONGS_EQUAL(2, linkedListIterator_nextIndex(it_list));
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
+}
+
+TEST(linked_list_iterator, previousIndex){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 3);
+ LONGS_EQUAL(2, linkedListIterator_previousIndex(it_list));
+ linkedListIterator_previous(it_list);
+ LONGS_EQUAL(1, linkedListIterator_previousIndex(it_list));
+ linkedListIterator_previous(it_list);
+ LONGS_EQUAL(0, linkedListIterator_previousIndex(it_list));
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
+}
+
+TEST(linked_list_iterator, set){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 0);
+
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+
+ linkedListIterator_set(it_list, NULL);
+ linkedListIterator_next(it_list);
+ linkedListIterator_next(it_list);
+ linkedListIterator_set(it_list, value3);
+ linkedListIterator_next(it_list);
+ linkedListIterator_set(it_list, value2);
+
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 2));
+
+ //mess up the expected and real changecount, code should check and handle
+ linkedList_addElement(list, value);
+ linkedListIterator_set(it_list, value);
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
+}
+
+TEST(linked_list_iterator, add){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 0);
+
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
+
+ linkedListIterator_next(it_list);
+ linkedListIterator_add(it_list, value2);
+
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+
+ //mess up the expected and real changecount, code should check and handle
+ linkedList_addElement(list, value);
+ linkedListIterator_add(it_list, value2);
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
+}
+
+TEST(linked_list_iterator, remove){
+ char * value = my_strdup("element");
+ char * value2 = my_strdup("element2");
+ char * value3 = my_strdup("element3");
+ linked_list_iterator_pt it_list;
+
+ linkedList_addElement(list, value);
+ linkedList_addElement(list, value2);
+ linkedList_addElement(list, value3);
+ it_list = linkedListIterator_create(list, 0);
+
+ LONGS_EQUAL(3, list->size);
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value2, (char*) linkedList_get(list, 1));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 2));
+
+ linkedListIterator_next(it_list);
+ linkedListIterator_next(it_list);
+ linkedListIterator_remove(it_list);
+ LONGS_EQUAL(2, list->size);
+ STRCMP_EQUAL(value, (char*) linkedList_get(list, 0));
+ STRCMP_EQUAL(value3, (char*) linkedList_get(list, 1));
+
+ //mess up the expected and real changecount, code should check and handle
+ linkedList_addElement(list, value);
+ linkedListIterator_remove(it_list);
+
+ free(value);
+ free(value2);
+ free(value3);
+ linkedListIterator_destroy(it_list);
+}
[19/20] celix git commit: CELIX-190: fixed some remote services
leaks/race-conditions
Posted by pn...@apache.org.
CELIX-190: fixed some remote services leaks/race-conditions
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/cec955da
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/cec955da
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/cec955da
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: cec955da8b17d6c0f9ae9353223e34dda7fa50fe
Parents: 3975102
Author: Bjoern Petri <bp...@apache.org>
Authored: Wed Oct 7 12:49:34 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Wed Oct 7 12:49:34 2015 +0200
----------------------------------------------------------------------
framework/private/src/service_registration.c | 6 +++++-
launcher/private/src/launcher.c | 5 ++++-
.../discovery/private/src/endpoint_discovery_poller.c | 2 +-
.../discovery_etcd/private/src/discovery_impl.c | 1 -
.../discovery_etcd/private/src/etcd_watcher.c | 11 +++++++++--
.../private/src/import_registration_impl.c | 4 +++-
.../private/src/remote_proxy_factory_impl.c | 6 ++++++
remote_services/topology_manager/private/src/activator.c | 8 ++++----
8 files changed, 32 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/cec955da/framework/private/src/service_registration.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_registration.c b/framework/private/src/service_registration.c
index 8e84d1a..cac87ee 100644
--- a/framework/private/src/service_registration.c
+++ b/framework/private/src/service_registration.c
@@ -109,7 +109,11 @@ static celix_status_t serviceRegistration_initializeProperties(service_registrat
sprintf(sId, "%ld", registration->serviceId);
properties_set(dictionary, (char *) OSGI_FRAMEWORK_SERVICE_ID, sId);
- properties_set(dictionary, (char *) OSGI_FRAMEWORK_OBJECTCLASS, registration->className);
+
+ if (properties_get(dictionary, (char *) OSGI_FRAMEWORK_OBJECTCLASS) == NULL) {
+ properties_set(dictionary, (char *) OSGI_FRAMEWORK_OBJECTCLASS, registration->className);
+ }
+
free(sId);
return CELIX_SUCCESS;
http://git-wip-us.apache.org/repos/asf/celix/blob/cec955da/launcher/private/src/launcher.c
----------------------------------------------------------------------
diff --git a/launcher/private/src/launcher.c b/launcher/private/src/launcher.c
index f334057..2da85bd 100644
--- a/launcher/private/src/launcher.c
+++ b/launcher/private/src/launcher.c
@@ -165,10 +165,13 @@ int main(int argc, char *argv[]) {
framework_waitForStop(framework);
framework_destroy(framework);
- properties_destroy(config);
}
}
+ if (config != NULL) {
+ properties_destroy(config);
+ }
+
if (status != CELIX_SUCCESS) {
printf("Problem creating framework\n");
}
http://git-wip-us.apache.org/repos/asf/celix/blob/cec955da/remote_services/discovery/private/src/endpoint_discovery_poller.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/endpoint_discovery_poller.c b/remote_services/discovery/private/src/endpoint_discovery_poller.c
index ac819c5..631f063 100644
--- a/remote_services/discovery/private/src/endpoint_discovery_poller.c
+++ b/remote_services/discovery/private/src/endpoint_discovery_poller.c
@@ -90,7 +90,7 @@ celix_status_t endpointDiscoveryPoller_create(discovery_pt discovery, bundle_con
char *save_ptr = NULL;
char* tok = strtok_r(endpoints, sep, &save_ptr);
while (tok) {
- endpointDiscoveryPoller_addDiscoveryEndpoint(*poller, strdup(utils_stringTrim(tok)));
+ endpointDiscoveryPoller_addDiscoveryEndpoint(*poller, utils_stringTrim(tok));
tok = strtok_r(NULL, sep, &save_ptr);
}
// Clean up after ourselves...
http://git-wip-us.apache.org/repos/asf/celix/blob/cec955da/remote_services/discovery_etcd/private/src/discovery_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/private/src/discovery_impl.c b/remote_services/discovery_etcd/private/src/discovery_impl.c
index b8d7d5c..00ab9a6 100644
--- a/remote_services/discovery_etcd/private/src/discovery_impl.c
+++ b/remote_services/discovery_etcd/private/src/discovery_impl.c
@@ -159,7 +159,6 @@ celix_status_t discovery_stop(discovery_pt discovery) {
if (status != CELIX_SUCCESS) {
return CELIX_BUNDLE_EXCEPTION;
}
-
hash_map_iterator_pt iter;
celixThreadMutex_lock(&discovery->discoveredServicesMutex);
http://git-wip-us.apache.org/repos/asf/celix/blob/cec955da/remote_services/discovery_etcd/private/src/etcd_watcher.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_etcd/private/src/etcd_watcher.c b/remote_services/discovery_etcd/private/src/etcd_watcher.c
index c54fcdc..b9b3ef8 100644
--- a/remote_services/discovery_etcd/private/src/etcd_watcher.c
+++ b/remote_services/discovery_etcd/private/src/etcd_watcher.c
@@ -224,9 +224,14 @@ static celix_status_t etcdWatcher_removeEntry(etcd_watcher_pt watcher, char* key
celix_status_t status = CELIX_BUNDLE_EXCEPTION;
endpoint_discovery_poller_pt poller = watcher->discovery->poller;
- if (hashMap_containsKey(watcher->entries, key)) {
+ hash_map_entry_pt entry = hashMap_getEntry(watcher->entries, key);
- hashMap_remove(watcher->entries, key);
+ if (entry != NULL) {
+ hashMap_removeEntryForKey(watcher->entries, key);
+
+ free(hashMapEntry_getKey(entry));
+ free(hashMapEntry_getValue(entry));
+ free(entry);
// check if there is another entry with the same value
hash_map_iterator_pt iter = hashMapIterator_create(watcher->entries);
@@ -237,6 +242,8 @@ static celix_status_t etcdWatcher_removeEntry(etcd_watcher_pt watcher, char* key
valueFound++;
}
+ hashMapIterator_destroy(iter);
+
if (valueFound == 0)
status = endpointDiscoveryPoller_removeDiscoveryEndpoint(poller, value);
http://git-wip-us.apache.org/repos/asf/celix/blob/cec955da/remote_services/remote_service_admin/private/src/import_registration_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/src/import_registration_impl.c b/remote_services/remote_service_admin/private/src/import_registration_impl.c
index ecf6e09..606b897 100644
--- a/remote_services/remote_service_admin/private/src/import_registration_impl.c
+++ b/remote_services/remote_service_admin/private/src/import_registration_impl.c
@@ -40,7 +40,7 @@ celix_status_t importRegistration_proxyFactoryAdded(void * handle, service_refer
celix_status_t importRegistration_proxyFactoryModified(void * handle, service_reference_pt reference, void *service);
celix_status_t importRegistration_proxyFactoryRemoved(void * handle, service_reference_pt reference, void *service);
-celix_status_t importRegistration_create(endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle sendToCallback, bundle_context_pt context, import_registration_pt *registration) {
+celix_status_t importRegistration_create(endpoint_description_pt endpoint, remote_service_admin_pt rsa, sendToHandle sendToCallback, bundle_context_pt context, import_registration_pt *registration) {
celix_status_t status = CELIX_SUCCESS;
*registration = calloc(1, sizeof(**registration));
@@ -61,6 +61,8 @@ celix_status_t importRegistration_create(endpoint_description_pt endpoint, remot
celix_status_t importRegistration_destroy(import_registration_pt registration)
{
+ free(registration);
+
return CELIX_SUCCESS;
}
http://git-wip-us.apache.org/repos/asf/celix/blob/cec955da/remote_services/remote_service_admin/private/src/remote_proxy_factory_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin/private/src/remote_proxy_factory_impl.c b/remote_services/remote_service_admin/private/src/remote_proxy_factory_impl.c
index 96e7557..54d7704 100644
--- a/remote_services/remote_service_admin/private/src/remote_proxy_factory_impl.c
+++ b/remote_services/remote_service_admin/private/src/remote_proxy_factory_impl.c
@@ -173,13 +173,19 @@ static celix_status_t remoteProxyFactory_registerProxyService(remote_proxy_facto
if (status == CELIX_SUCCESS) {
properties_set(proxy_instance_ptr->properties, "proxy.interface", remote_proxy_factory_ptr->service);
+
+
+
+
hash_map_iterator_pt iter = hashMapIterator_create(endpointDescription->properties);
while (hashMapIterator_hasNext(iter)) {
hash_map_entry_pt entry = hashMapIterator_nextEntry(iter);
char *key = hashMapEntry_getKey(entry);
char *value = hashMapEntry_getValue(entry);
+
properties_set(proxy_instance_ptr->properties, key, value);
}
+ hashMapIterator_destroy(iter);
}
if (status == CELIX_SUCCESS) {
http://git-wip-us.apache.org/repos/asf/celix/blob/cec955da/remote_services/topology_manager/private/src/activator.c
----------------------------------------------------------------------
diff --git a/remote_services/topology_manager/private/src/activator.c b/remote_services/topology_manager/private/src/activator.c
index 5d7f8b0..b83c060 100644
--- a/remote_services/topology_manager/private/src/activator.c
+++ b/remote_services/topology_manager/private/src/activator.c
@@ -215,14 +215,14 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context)
celix_status_t status = CELIX_SUCCESS;
struct activator *activator = userData;
- if (serviceTracker_close(activator->endpointListenerTracker) == CELIX_SUCCESS) {
- serviceTracker_destroy(activator->endpointListenerTracker);
- }
-
if (serviceTracker_close(activator->remoteServiceAdminTracker) == CELIX_SUCCESS) {
serviceTracker_destroy(activator->remoteServiceAdminTracker);
}
+ if (serviceTracker_close(activator->endpointListenerTracker) == CELIX_SUCCESS) {
+ serviceTracker_destroy(activator->endpointListenerTracker);
+ }
+
bundleContext_removeServiceListener(context, activator->serviceListener);
free(activator->serviceListener);
[09/20] celix git commit: CELIX-267: Fix filename
Posted by pn...@apache.org.
CELIX-267: Fix filename
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/5ff51e8e
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/5ff51e8e
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/5ff51e8e
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 5ff51e8e8aa0cbe40d84d9a5228e8ba29c2c58f8
Parents: d632500
Author: Bjoern Petri <bp...@apache.org>
Authored: Mon Oct 5 10:50:30 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Mon Oct 5 10:50:30 2015 +0200
----------------------------------------------------------------------
framework/private/src/bundle_archive.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/5ff51e8e/framework/private/src/bundle_archive.c
----------------------------------------------------------------------
diff --git a/framework/private/src/bundle_archive.c b/framework/private/src/bundle_archive.c
index 6a9407a..a676d6a 100644
--- a/framework/private/src/bundle_archive.c
+++ b/framework/private/src/bundle_archive.c
@@ -408,7 +408,7 @@ celix_status_t bundleArchive_setRefreshCount(bundle_archive_pt archive) {
celix_status_t status = CELIX_SUCCESS;
char refreshCounter[512];
- snprintf(refreshCounter, sizeof(refreshCounter), "%s/bundle.state", archive->archiveRoot);
+ snprintf(refreshCounter, sizeof(refreshCounter), "%s/refresh.counter", archive->archiveRoot);
refreshCounterFile = fopen(refreshCounter, "w");
if (refreshCounterFile == NULL) {
[04/20] celix git commit: CELIX-259: added dispatcherThread shutdown
Posted by pn...@apache.org.
CELIX-259: added dispatcherThread shutdown
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/268ab022
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/268ab022
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/268ab022
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 268ab022e08adaa6011785a9cac6b36c958f670a
Parents: 7e3b33f
Author: Bjoern Petri <bp...@apache.org>
Authored: Fri Sep 25 19:48:27 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Fri Sep 25 19:48:27 2015 +0200
----------------------------------------------------------------------
framework/private/src/framework.c | 22 +++++++++++++++++-----
1 file changed, 17 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/268ab022/framework/private/src/framework.c
----------------------------------------------------------------------
diff --git a/framework/private/src/framework.c b/framework/private/src/framework.c
index e0391e7..529a712 100644
--- a/framework/private/src/framework.c
+++ b/framework/private/src/framework.c
@@ -2066,10 +2066,23 @@ static void *framework_shutdown(void *framework) {
bundle_close(bundle);
}
hashMapIterator_destroy(iter);
-#ifndef ANDROID
- pthread_cancel(fw->dispatcherThread.thread);
-#endif
- celixThread_join(fw->dispatcherThread, NULL);
+
+ if (celixThreadMutex_lock(&fw->dispatcherLock) != CELIX_SUCCESS) {
+ fw_log(fw->logger, OSGI_FRAMEWORK_LOG_ERROR, "Error locking the dispatcherThread.");
+ }
+ else {
+ fw->shutdown = true;
+
+ if (celixThreadCondition_broadcast(&fw->dispatcher)) {
+ fw_log(fw->logger, OSGI_FRAMEWORK_LOG_ERROR, "Error broadcasting .");
+ }
+
+ if (celixThreadMutex_unlock(&fw->dispatcherLock)) {
+ fw_log(fw->logger, OSGI_FRAMEWORK_LOG_ERROR, "Error unlocking the dispatcherThread.");
+ }
+
+ celixThread_join(fw->dispatcherThread, NULL);
+ }
err = celixThreadMutex_lock(&fw->mutex);
if (err != 0) {
@@ -2077,7 +2090,6 @@ static void *framework_shutdown(void *framework) {
celixThread_exit(NULL);
return NULL;
}
- fw->shutdown = true;
err = celixThreadCondition_broadcast(&fw->shutdownGate);
if (err != 0) {
fw_log(fw->logger, OSGI_FRAMEWORK_LOG_ERROR, "Error waking the shutdown gate, cannot exit clean.");
[12/20] celix git commit: CELIX-263: Fixed travis setup
Posted by pn...@apache.org.
CELIX-263: Fixed travis setup
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/bb62be8e
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/bb62be8e
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/bb62be8e
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: bb62be8e11c4f585de4dd146f8073863ca22153c
Parents: c6d2d59
Author: Bjoern Petri <bp...@apache.org>
Authored: Tue Oct 6 08:30:15 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Tue Oct 6 08:30:15 2015 +0200
----------------------------------------------------------------------
.travis.yml | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/bb62be8e/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index df0f48b..8d3b6bc 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,7 +1,5 @@
language: c
-env
-
before_install:
- sudo apt-get update -qq
- sudo apt-get install -y uuid-dev libjansson-dev libxml2-dev
@@ -11,15 +9,15 @@ matrix:
- compiler: gcc
- compiler: clang
-before_script:
+before_script:
+ - wget https://github.com/cpputest/cpputest.github.io/blob/master/releases/cpputest-3.7.1.tar.gz?raw=true -O /tmp/cpputest.tar.gz
+ - tar -xzvf /tmp/cpputest.tar.gz -C /tmp
+ - cd /tmp/cpputest-3.7.1 && ./configure --prefix=$HOME/cpputest && make && make install && cd -
- mkdir build install
- - cd build
- - cmake -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=ON -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DBUILD_DEVICE_ACCESS=ON -DBUILD_DEVICE_ACCESS_EXAMPLE=ON -DBUILD_UTILS_TEST=ON -DCMAKE_INSTALL_PREFIX=../install ..
script:
+ - cd build
+ - cmake -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=ON -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DBUILD_DEVICE_ACCESS=ON -DBUILD_DEVICE_ACCESS_EXAMPLE=ON -DBUILD_UTILS-TESTS=ON -DCPPUTEST_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_LIBRARY=$HOME/cpputest/libCppUTest.a -DCPPUTEST_EXT_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_EXT_LIBRARY=$HOME/cpputest/libCppUTestExt.a -DCMAKE_INSTALL_PREFIX=../install ..
- make all && make deploy && make install-all
-
-after_script:
- - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/utils
- - ./utils/array_list_test && ./utils/celix_threads_test && ./utils/linked_list_test && ./utils/hash_map_test
+ - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/utils && ./utils/array_list_test && ./utils/celix_threads_test && ./utils/linked_list_test && ./utils/hash_map_test
[07/20] celix git commit: CELIX-262: Fix minor issues in
hashMap/linkedList
Posted by pn...@apache.org.
CELIX-262: Fix minor issues in hashMap/linkedList
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/5498452e
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/5498452e
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/5498452e
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 5498452e2786f2b034058819c6e83f758d75bedf
Parents: a29205a
Author: Bjoern Petri <bp...@apache.org>
Authored: Sat Oct 3 11:39:50 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Sat Oct 3 11:39:50 2015 +0200
----------------------------------------------------------------------
utils/private/src/hash_map.c | 57 ++++++++++++++++++++++-----------
utils/private/src/linked_list.c | 2 +-
utils/public/include/hash_map.h | 4 ++-
utils/public/include/linked_list.h | 2 +-
4 files changed, 43 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/5498452e/utils/private/src/hash_map.c
----------------------------------------------------------------------
diff --git a/utils/private/src/hash_map.c b/utils/private/src/hash_map.c
index dc082a4..177cf0d 100644
--- a/utils/private/src/hash_map.c
+++ b/utils/private/src/hash_map.c
@@ -122,7 +122,7 @@ void * hashMap_get(hash_map_pt map, void * key) {
}
hash = hashMap_hash(map->hashKey(key));
- hash_map_entry_pt entry = NULL;
+ hash_map_entry_pt entry = NULL;
for (entry = map->table[hashMap_indexFor(hash, map->tablelength)]; entry != NULL; entry = entry->next) {
if (entry->hash == hash && (entry->key == key || map->equalsKey(key, entry->key))) {
return entry->value;
@@ -166,7 +166,7 @@ void * hashMap_put(hash_map_pt map, void * key, void * value) {
hash = hashMap_hash(map->hashKey(key));
i = hashMap_indexFor(hash, map->tablelength);
- hash_map_entry_pt entry;
+ hash_map_entry_pt entry;
for (entry = map->table[i]; entry != NULL; entry = entry->next) {
if (entry->hash == hash && (entry->key == key || map->equalsKey(key, entry->key))) {
void * oldValue = entry->value;
@@ -214,7 +214,7 @@ void * hashMap_remove(hash_map_pt map, void * key) {
entry->key = NULL;
entry->value = NULL;
free(entry);
- }
+ }
return value;
}
@@ -247,12 +247,12 @@ hash_map_entry_pt hashMap_removeMapping(hash_map_pt map, hash_map_entry_pt entry
unsigned int hash;
hash_map_entry_pt prev;
hash_map_entry_pt e;
- int i;
+ int i;
if (entry == NULL) {
return NULL;
}
hash = (entry->key == NULL) ? 0 : hashMap_hash(map->hashKey(entry->key));
- i = hashMap_indexFor(hash, map->tablelength);
+ i = hashMap_indexFor(hash, map->tablelength);
prev = map->table[i];
e = prev;
@@ -267,7 +267,7 @@ hash_map_entry_pt hashMap_removeMapping(hash_map_pt map, hash_map_entry_pt entry
prev->next = next;
}
return e;
- }
+ }
prev = e;
e = next;
}
@@ -435,6 +435,11 @@ hash_map_key_set_pt hashMapKeySet_create(hash_map_pt map) {
return keySet;
}
+void hashMapKeySet_destroy(hash_map_key_set_pt keySet){
+ keySet->map = NULL;
+ free(keySet);
+}
+
int hashMapKeySet_size(hash_map_key_set_pt keySet) {
return keySet->map->size;
}
@@ -485,17 +490,17 @@ bool hashMapValues_contains(hash_map_values_pt values, void * value) {
void hashMapValues_toArray(hash_map_values_pt values, void* *array[], unsigned int *size) {
hash_map_iterator_pt it;
int i;
- int vsize = hashMapValues_size(values);
- *size = vsize;
- *array = malloc(vsize * sizeof(*array));
- it = hashMapValues_iterator(values);
- for (i = 0; i < vsize; i++) {
- if (!hashMapIterator_hasNext(it)) {
- return;
- }
- (*array)[i] = hashMapIterator_nextValue(it);
- }
- hashMapIterator_destroy(it);
+ int vsize = hashMapValues_size(values);
+ *size = vsize;
+ *array = malloc(vsize * sizeof(*array));
+ it = hashMapValues_iterator(values);
+ for (i = 0; i < vsize; i++) {
+ if (!hashMapIterator_hasNext(it)) {
+ return;
+ }
+ (*array)[i] = hashMapIterator_nextValue(it);
+ }
+ hashMapIterator_destroy(it);
}
bool hashMapValues_remove(hash_map_values_pt values, void * value) {
@@ -504,6 +509,7 @@ bool hashMapValues_remove(hash_map_values_pt values, void * value) {
while (hashMapIterator_hasNext(iterator)) {
if (hashMapIterator_nextValue(iterator) == NULL) {
hashMapIterator_remove(iterator);
+ hashMapIterator_destroy(iterator);
return true;
}
}
@@ -511,10 +517,12 @@ bool hashMapValues_remove(hash_map_values_pt values, void * value) {
while (hashMapIterator_hasNext(iterator)) {
if (values->map->equalsValue(value, hashMapIterator_nextValue(iterator))) {
hashMapIterator_remove(iterator);
+ hashMapIterator_destroy(iterator);
return true;
}
}
}
+ hashMapIterator_destroy(iterator);
return false;
}
@@ -533,6 +541,11 @@ hash_map_entry_set_pt hashMapEntrySet_create(hash_map_pt map) {
return entrySet;
}
+void hashMapEntrySet_destroy(hash_map_entry_set_pt entrySet){
+ entrySet->map = NULL;
+ free(entrySet);
+}
+
int hashMapEntrySet_size(hash_map_entry_set_pt entrySet) {
return entrySet->map->size;
}
@@ -541,8 +554,14 @@ bool hashMapEntrySet_contains(hash_map_entry_set_pt entrySet, hash_map_entry_pt
return hashMap_containsValue(entrySet->map, entry);
}
-bool hashMapEntrySet_remove(hash_map_values_pt entrySet, hash_map_entry_pt entry) {
- return hashMap_removeMapping(entrySet->map, entry) != NULL;
+bool hashMapEntrySet_remove(hash_map_entry_set_pt entrySet, hash_map_entry_pt entry) {
+ hash_map_entry_pt temp = hashMap_removeMapping(entrySet->map, entry);
+ if (temp != NULL) {
+ free(temp);
+ return true;
+ } else {
+ return false;
+ }
}
void hashMapEntrySet_clear(hash_map_entry_set_pt entrySet) {
http://git-wip-us.apache.org/repos/asf/celix/blob/5498452e/utils/private/src/linked_list.c
----------------------------------------------------------------------
diff --git a/utils/private/src/linked_list.c b/utils/private/src/linked_list.c
index f949007..235c3e7 100644
--- a/utils/private/src/linked_list.c
+++ b/utils/private/src/linked_list.c
@@ -115,7 +115,7 @@ void linkedList_addLast(linked_list_pt list, void * element) {
}
bool linkedList_contains(linked_list_pt list, void * element) {
- return linkedList_indexOf(list, element) != 0;
+ return linkedList_indexOf(list, element) != -1;
}
int linkedList_size(linked_list_pt list) {
http://git-wip-us.apache.org/repos/asf/celix/blob/5498452e/utils/public/include/hash_map.h
----------------------------------------------------------------------
diff --git a/utils/public/include/hash_map.h b/utils/public/include/hash_map.h
index 5565cb7..f4f0acd 100644
--- a/utils/public/include/hash_map.h
+++ b/utils/public/include/hash_map.h
@@ -61,6 +61,7 @@ UTILS_EXPORT void * hashMapIterator_nextKey(hash_map_iterator_pt iterator);
UTILS_EXPORT hash_map_entry_pt hashMapIterator_nextEntry(hash_map_iterator_pt iterator);
UTILS_EXPORT hash_map_key_set_pt hashMapKeySet_create(hash_map_pt map);
+UTILS_EXPORT void hashMapKeySet_destroy(hash_map_key_set_pt keySet);
UTILS_EXPORT int hashMapKeySet_size(hash_map_key_set_pt keySet);
UTILS_EXPORT bool hashMapKeySet_contains(hash_map_key_set_pt keySet, void * key);
UTILS_EXPORT bool hashMapKeySet_remove(hash_map_key_set_pt keySet, void * key);
@@ -78,9 +79,10 @@ UTILS_EXPORT void hashMapValues_clear(hash_map_values_pt values);
UTILS_EXPORT bool hashMapValues_isEmpty(hash_map_values_pt values);
UTILS_EXPORT hash_map_entry_set_pt hashMapEntrySet_create(hash_map_pt map);
+UTILS_EXPORT void hashMapEntrySet_destroy(hash_map_entry_set_pt entrySet);
UTILS_EXPORT int hashMapEntrySet_size(hash_map_entry_set_pt entrySet);
UTILS_EXPORT bool hashMapEntrySet_contains(hash_map_entry_set_pt entrySet, hash_map_entry_pt entry);
-UTILS_EXPORT bool hashMapEntrySet_remove(hash_map_values_pt entrySet, hash_map_entry_pt entry);
+UTILS_EXPORT bool hashMapEntrySet_remove(hash_map_entry_set_pt entrySet, hash_map_entry_pt entry);
UTILS_EXPORT void hashMapEntrySet_clear(hash_map_entry_set_pt entrySet);
UTILS_EXPORT bool hashMapEntrySet_isEmpty(hash_map_entry_set_pt entrySet);
http://git-wip-us.apache.org/repos/asf/celix/blob/5498452e/utils/public/include/linked_list.h
----------------------------------------------------------------------
diff --git a/utils/public/include/linked_list.h b/utils/public/include/linked_list.h
index 22caabb..6321c5a 100644
--- a/utils/public/include/linked_list.h
+++ b/utils/public/include/linked_list.h
@@ -49,7 +49,7 @@ UTILS_EXPORT int linkedList_size(linked_list_pt list);
UTILS_EXPORT bool linkedList_isEmpty(linked_list_pt list);
UTILS_EXPORT bool linkedList_addElement(linked_list_pt list, void * element);
UTILS_EXPORT bool linkedList_removeElement(linked_list_pt list, void * element);
-UTILS_EXPORT void linkedlist_clear(linked_list_pt list);
+UTILS_EXPORT void linkedList_clear(linked_list_pt list);
UTILS_EXPORT void * linkedList_get(linked_list_pt list, int index);
UTILS_EXPORT void * linkedList_set(linked_list_pt list, int index, void * element);
UTILS_EXPORT void linkedList_addIndex(linked_list_pt list, int index, void * element);
[15/20] celix git commit: CELIX-263: Fix travis clang setup
Posted by pn...@apache.org.
CELIX-263: Fix travis clang setup
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/673b5c7b
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/673b5c7b
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/673b5c7b
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 673b5c7ba9a2dd6dbc2ca62f1d588bc6868e1f1b
Parents: ebbe202
Author: Bjoern Petri <bp...@apache.org>
Authored: Tue Oct 6 09:37:58 2015 +0200
Committer: Bjoern Petri <bp...@apache.org>
Committed: Tue Oct 6 09:37:58 2015 +0200
----------------------------------------------------------------------
.travis.yml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/673b5c7b/.travis.yml
----------------------------------------------------------------------
diff --git a/.travis.yml b/.travis.yml
index 5d0a676..a898cb2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -12,7 +12,7 @@ matrix:
before_script:
- wget https://github.com/cpputest/cpputest.github.io/blob/master/releases/cpputest-3.7.1.tar.gz?raw=true -O /tmp/cpputest.tar.gz
- tar -xzvf /tmp/cpputest.tar.gz -C /tmp
- - cd /tmp/cpputest-3.7.1 && ./configure --prefix=$HOME/cpputest && make && make install && cd -
+ - if [ "$CC" = "clang" ]; then export CXX="clang++"; fi && cd /tmp/cpputest-3.7.1 && ./configure --prefix=$HOME/cpputest && make && make install && cd -
- mkdir build install
script:
[20/20] celix git commit: CELIX-237: Merge branch 'develop' into ffi
Posted by pn...@apache.org.
CELIX-237: Merge branch 'develop' into ffi
Conflicts:
.travis.yml
launcher/private/src/launcher.c
remote_services/discovery/private/src/endpoint_discovery_poller.c
utils/CMakeLists.txt
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/119bb950
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/119bb950
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/119bb950
Branch: refs/heads/feature/CELIX-237_rsa-ffi
Commit: 119bb95046bf338613f7d7c6439af328ced2172f
Parents: a13465a cec955d
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Wed Oct 7 14:43:09 2015 +0200
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Wed Oct 7 14:43:09 2015 +0200
----------------------------------------------------------------------
.travis.yml | 2 +-
deployment_admin/CMakeLists.txt | 6 +-
framework/CMakeLists.txt | 82 +-
framework/private/mock/bundle_context_mock.c | 25 +-
framework/private/mock/bundle_mock.c | 13 +-
framework/private/mock/framework_mock.c | 6 +-
framework/private/src/bundle_archive.c | 2 +-
framework/private/src/framework.c | 53 +-
framework/private/src/service_registration.c | 6 +-
framework/private/test/bundle_context_test.cpp | 75 +-
.../private/src/endpoint_discovery_poller.c | 116 +-
.../private/src/endpoint_discovery_server.c | 3 +-
.../discovery_etcd/private/src/discovery_impl.c | 1 -
.../discovery_etcd/private/src/etcd_watcher.c | 11 +-
.../private/src/import_registration_impl.c | 4 +-
.../private/src/remote_proxy_factory_impl.c | 6 +
.../private/src/remote_service_admin_impl.c | 5 +-
.../topology_manager/private/src/activator.c | 8 +-
shell/private/src/help_command.c | 2 +
shell/private/src/inspect_command.c | 6 +-
shell/private/src/update_command.c | 2 +-
utils/CMakeLists.txt | 44 +-
utils/private/src/hash_map.c | 57 +-
utils/private/src/linked_list.c | 2 +-
utils/private/test/array_list_test.c | 357 -----
utils/private/test/array_list_test.cpp | 500 +++++-
utils/private/test/celix_threads_test.cpp | 346 ++++
utils/private/test/hash_map_test.c | 478 ------
utils/private/test/hash_map_test.cpp | 1492 ++++++++++++++++++
utils/private/test/hash_map_test_hash.c | 359 -----
utils/private/test/linked_list_test.c | 96 --
utils/private/test/linked_list_test.cpp | 794 ++++++++++
utils/public/include/celix_threads.h | 2 +-
utils/public/include/hash_map.h | 4 +-
utils/public/include/linked_list.h | 2 +-
35 files changed, 3403 insertions(+), 1564 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/.travis.yml
----------------------------------------------------------------------
diff --cc .travis.yml
index 3a3cfb7,1814464..3ecdf5c
--- a/.travis.yml
+++ b/.travis.yml
@@@ -9,21 -9,15 +9,21 @@@ matrix
- compiler: gcc
- compiler: clang
-before_script:
- - wget https://github.com/cpputest/cpputest.github.io/blob/master/releases/cpputest-3.7.1.tar.gz?raw=true -O /tmp/cpputest.tar.gz
- - tar -xzvf /tmp/cpputest.tar.gz -C /tmp
- - if [ "$CC" = "clang" ]; then export CXX="clang++"; fi && cd /tmp/cpputest-3.7.1 && ./configure --prefix=$HOME/cpputest && make && make install && cd -
+before_script:
+ - git clone -b 3.7.2 --single-branch https://github.com/cpputest/cpputest.git cpputest-build
+ - cd cpputest-build
+ - cmake . && make
+ - sudo make install
+ - cd ..
+ - git clone -b 2.7 --single-branch https://github.com/akheron/jansson.git jansson-build
+ - cd jansson-build
+ - cmake -DJANSSON_BUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr . && make
+ - sudo make install
+ - cd ..
- mkdir build install
-
-script:
- cd build
- - cmake -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=ON -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DBUILD_DEVICE_ACCESS=ON -DBUILD_DEVICE_ACCESS_EXAMPLE=ON -DBUILD_FRAMEWORK_TESTS=ON -DBUILD_UTILS-TESTS=ON -DCPPUTEST_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_LIBRARY=$HOME/cpputest/lib/libCppUTest.a -DCPPUTEST_EXT_INCLUDE_DIR=$HOME/cpputest/include -DCPPUTEST_EXT_LIBRARY=$HOME/cpputest/lib/libCppUTestExt.a -DCMAKE_INSTALL_PREFIX=../install ..
- - make all && make deploy && make install-all
- - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/utils && ./utils/array_list_test && ./utils/celix_threads_test && ./utils/linked_list_test && ./utils/hash_map_test
+ - cmake -DENABLE_TESTING=ON -DCMAKE_SKIP_BUILD_RPATH=TRUE -DBUILD_DEPLOYMENT_ADMIN=ON -DBUILD_EXAMPLES=ON -DBUILD_LOG_SERVICE=ON -DBUILD_LOG_WRITER=ON -DBUILD_REMOTE_SERVICE_ADMIN=ON -DBUILD_RSA_DISCOVERY_CONFIGURED=ON -DBUILD_RSA_DISCOVERY_ETCD=ON -DBUILD_RSA_DISCOVERY_SHM=ON -DBUILD_RSA_EXAMPLES=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_SHM=ON -DBUILD_RSA_REMOTE_SERVICE_ADMIN_HTTP=ON -DBUILD_REMOTE_SHELL=ON -DBUILD_SHELL=ON -DBUILD_SHELL_TUI=ON -DCMAKE_INSTALL_PREFIX=../install ..
+script:
+ - make all
- - make test ARGS="-V"
++ - export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:`pwd`/utils && make test ARGS="-V"
http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/framework/CMakeLists.txt
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/framework/private/src/framework.c
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/framework/private/src/service_registration.c
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/remote_services/discovery/private/src/endpoint_discovery_poller.c
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/remote_services/remote_service_admin/private/src/import_registration_impl.c
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/remote_services/remote_service_admin_http/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/119bb950/utils/CMakeLists.txt
----------------------------------------------------------------------
diff --cc utils/CMakeLists.txt
index 859e8a5,c786e96..ce0811e
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@@ -52,7 -53,8 +53,8 @@@ if (UTILS
INSTALL(FILES ${files} DESTINATION include/celix COMPONENT framework)
celix_subproject(UTILS-TESTS "Option to build the utilities library tests" "OFF")
++
if (UTILS-TESTS)
-
find_package(CppUTest REQUIRED)
include_directories(${CUNIT_INCLUDE_DIRS})