From aec12cd9014aa0677599d01fd9e611d81eb563a9 Mon Sep 17 00:00:00 2001 From: Pepijn Noltes Date: Mon, 9 Nov 2015 13:47:27 +0100 Subject: [PATCH] CELIX-289: Fixes for mocking issues and bugs --- .../private/src/deployment_admin_activator.c | 2 +- deployment_admin/private/src/log.c | 2 +- examples/mongoose/private/src/mongoose.c | 5 +- framework/CMakeLists.txt | 213 +++-- framework/private/include/bundle_cache.h | 2 +- .../private/include/bundle_cache_private.h | 1 - .../private/include/bundle_context_private.h | 1 - .../private/include/bundle_revision_private.h | 1 - .../include/service_reference_private.h | 2 - .../include/service_registration_private.h | 2 +- .../test_bundle1/src/activator.c | 28 +- framework/private/mock/attribute_mock.c | 3 +- framework/private/mock/bundle_archive_mock.c | 9 +- framework/private/mock/bundle_cache_mock.c | 10 +- framework/private/mock/bundle_mock.c | 52 +- framework/private/mock/bundle_revision_mock.c | 2 +- framework/private/mock/capability_mock.c | 8 +- framework/private/mock/celix_log_mock.c | 41 + framework/private/mock/filter_mock.c | 5 +- framework/private/mock/framework_mock.c | 14 +- framework/private/mock/manifest_mock.c | 4 +- framework/private/mock/manifest_parser_mock.c | 12 +- framework/private/mock/module_mock.c | 32 +- framework/private/mock/requirement_mock.c | 16 +- .../private/mock/service_registration_mock.c | 4 +- framework/private/mock/version_mock.c | 44 +- framework/private/mock/version_range_mock.c | 10 +- framework/private/mock/wire_mock.c | 26 +- framework/private/src/bundle.c | 79 +- framework/private/src/bundle_archive.c | 13 +- framework/private/src/bundle_cache.c | 12 +- framework/private/src/bundle_context.c | 1 - framework/private/src/bundle_revision.c | 3 +- framework/private/src/celix_errorcodes.c | 2 +- framework/private/src/framework.c | 4 +- framework/private/src/module.c | 13 + framework/private/src/service_tracker.c | 4 +- framework/private/src/version_range.c | 7 +- framework/private/test/attribute_test.cpp | 39 +- .../private/test/bundle_archive_test.cpp | 326 ++++++- framework/private/test/bundle_cache_test.cpp | 43 +- .../private/test/bundle_context_test.cpp | 166 +++- .../private/test/bundle_revision_test.cpp | 61 +- framework/private/test/bundle_test.cpp | 808 +++++++++++++++--- framework/private/test/capability_test.cpp | 19 +- .../private/test/celix_errorcodes_test.cpp | 87 ++ framework/private/test/framework_test.cpp | 65 +- framework/private/test/manifest_test.cpp | 4 +- framework/private/test/module_test.cpp | 282 ++++++ framework/private/test/properties_test.cpp | 23 +- framework/private/test/requirement_test.cpp | 18 +- framework/private/test/resolver_test.cpp | 140 ++- .../private/test/service_reference_test.cpp | 1 + .../test/service_registration_test.cpp | 4 +- .../private/test/service_registry_test.cpp | 206 +++-- .../test/service_tracker_customizer_test.cpp | 22 +- .../private/test/service_tracker_test.cpp | 197 ++++- framework/private/test/utils_test.cpp | 142 ++- framework/private/test/version_range_test.cpp | 168 ++-- framework/private/test/version_test.cpp | 199 +++-- framework/private/test/wire_test.cpp | 42 +- framework/public/include/bundle.h | 2 +- framework/public/include/bundle_archive.h | 4 +- framework/public/include/bundle_revision.h | 2 +- framework/public/include/service_reference.h | 2 + .../public/include/service_registration.h | 2 +- framework/tst/CMakeLists.txt | 2 +- log_service/private/src/log.c | 10 +- log_service/public/src/log_helper.c | 4 +- .../include/endpoint_discovery_poller.h | 1 + .../private/src/endpoint_discovery_poller.c | 2 +- .../discovery_etcd/private/src/etcd_watcher.c | 2 +- .../dynamic_function_interface/CMakeLists.txt | 6 +- .../private/src/topology_manager.c | 3 + utils/CMakeLists.txt | 6 +- utils/public/include/celix_threads.h | 2 +- 76 files changed, 3053 insertions(+), 748 deletions(-) create mode 100644 framework/private/mock/celix_log_mock.c create mode 100644 framework/private/test/celix_errorcodes_test.cpp diff --git a/deployment_admin/private/src/deployment_admin_activator.c b/deployment_admin/private/src/deployment_admin_activator.c index 93fd6b55c..9a3ce5f97 100644 --- a/deployment_admin/private/src/deployment_admin_activator.c +++ b/deployment_admin/private/src/deployment_admin_activator.c @@ -64,7 +64,7 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) } celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) { - celix_status_t status; + celix_status_t status = CELIX_SUCCESS; bundle_activator_pt activator = (bundle_activator_pt) userData; diff --git a/deployment_admin/private/src/log.c b/deployment_admin/private/src/log.c index 98e757d12..a5227ca9d 100644 --- a/deployment_admin/private/src/log.c +++ b/deployment_admin/private/src/log.c @@ -55,7 +55,7 @@ celix_status_t log_destroy(log_pt *log) { } celix_status_t log_log(log_pt log, unsigned int type, properties_pt properties) { - celix_status_t status; + celix_status_t status = CELIX_SUCCESS; log_event_pt event = NULL; diff --git a/examples/mongoose/private/src/mongoose.c b/examples/mongoose/private/src/mongoose.c index 045cd09ea..34eb2c662 100644 --- a/examples/mongoose/private/src/mongoose.c +++ b/examples/mongoose/private/src/mongoose.c @@ -41,6 +41,7 @@ #include #include #include +#include #if defined(_WIN32) // Windows specific #includes and #defines #define _WIN32_WINNT 0x0400 // To make it link in VS2005 @@ -3622,10 +3623,10 @@ static void close_connection(struct mg_connection *conn) { } static void discard_current_request_from_buffer(struct mg_connection *conn) { - char *buffered; + //char *buffered; int buffered_len, body_len; - buffered = conn->buf + conn->request_len; + //buffered = conn->buf + conn->request_len; buffered_len = conn->data_len - conn->request_len; assert(buffered_len >= 0); diff --git a/framework/CMakeLists.txt b/framework/CMakeLists.txt index 8af958602..bf60b9ea6 100644 --- a/framework/CMakeLists.txt +++ b/framework/CMakeLists.txt @@ -98,16 +98,23 @@ if (FRAMEWORK) private/test/attribute_test.cpp private/src/attribute.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) target_link_libraries(attribute_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread) add_executable(bundle_archive_test + private/mock/celix_log_mock.c private/test/bundle_archive_test.cpp - private/mock/bundle_revision_mock.c + private/src/bundle_revision.c + private/src/manifest.c + private/src/miniunz.c + private/src/unzip.c + private/src/ioapi.c + private/src/properties.c 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 pthread) + private/src/utils.c) + target_link_libraries(bundle_archive_test celix_utils ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} ${ZLIB_LIBRARY} pthread) + add_executable(bundle_cache_test private/test/bundle_cache_test.cpp @@ -115,27 +122,27 @@ if (FRAMEWORK) private/mock/properties_mock.c private/src/bundle_cache.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) 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 private/mock/framework_mock.c private/src/bundle_context.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) 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 private/mock/manifest_mock.c private/src/bundle_revision.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) 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 @@ -147,29 +154,35 @@ if (FRAMEWORK) private/src/utils.c private/src/bundle.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) 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 private/mock/version_mock.c + private/src/utils.c private/src/capability.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) target_link_libraries(capability_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread) - + + add_executable(celix_errorcodes_test + private/test/celix_errorcodes_test.cpp + private/src/celix_errorcodes.c) + target_link_libraries(celix_errorcodes_test ${CPPUTEST_LIBRARY}) + 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) + private/mock/celix_log_mock.c) 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 + #private/mock/properties_mock.c private/mock/resolver_mock.c private/mock/service_reference_mock.c private/mock/service_registry_mock.c @@ -183,8 +196,9 @@ if (FRAMEWORK) private/mock/bundle_cache_mock.c private/mock/manifest_mock.c private/src/utils.c + private/src/properties.c private/src/celix_errorcodes.c - private/src/celix_log.c + private/mock/celix_log_mock.c private/src/framework.c) target_link_libraries(framework_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} ${UUID} celix_utils pthread dl) @@ -198,18 +212,18 @@ if (FRAMEWORK) private/src/utils.c private/src/manifest_parser.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) 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 private/src/utils.c private/src/manifest.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) 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 @@ -221,56 +235,59 @@ if (FRAMEWORK) private/mock/wire_mock.c private/src/module.c) 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 pthread) - - + add_executable(requirement_test private/test/requirement_test.cpp private/mock/attribute_mock.c private/mock/capability_mock.c private/mock/version_range_mock.c private/src/requirement.c + private/src/utils.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) 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 private/mock/requirement_mock.c private/mock/capability_mock.c - private/mock/module_mock.c + private/mock/manifest_parser_mock.c private/mock/wire_mock.c + private/mock/version_mock.c + private/src/module.c private/src/resolver.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) 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 private/mock/service_registration_mock.c private/mock/service_registry_mock.c private/src/service_reference.c + private/src/utils.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) target_link_libraries(service_reference_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY} celix_utils pthread) - - add_executable(service_registration_test + + 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) + private/mock/celix_log_mock.c) 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 @@ -281,17 +298,17 @@ if (FRAMEWORK) private/mock/properties_mock.c private/src/service_registry.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) 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) + private/mock/celix_log_mock.c) 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 @@ -299,87 +316,95 @@ if (FRAMEWORK) private/mock/service_tracker_customizer_mock.c private/src/service_tracker.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) 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 pthread) - + add_executable(version_range_test private/test/version_range_test.cpp private/src/version_range.c private/mock/version_mock.c private/src/celix_errorcodes.c - private/src/celix_log.c) + private/mock/celix_log_mock.c) target_link_libraries(version_range_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY}) add_executable(version_test private/test/version_test.cpp private/src/version.c private/src/celix_errorcodes.c - private/src/celix_log.c) - target_link_libraries(version_test ${CPPUTEST_LIBRARY}) + private/mock/celix_log_mock.c) + target_link_libraries(version_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY}) add_executable(wire_test private/mock/requirement_mock.c private/mock/capability_mock.c private/mock/module_mock.c private/src/celix_errorcodes.c - private/src/celix_log.c + private/mock/celix_log_mock.c private/src/wire.c private/test/wire_test.cpp) target_link_libraries(wire_test ${CPPUTEST_LIBRARY} ${CPPUTEST_EXT_LIBRARY}) - set_target_properties(wire_test PROPERTIES COMPILE_FLAGS "-include ${CPPUTEST_INCLUDE_DIR}/CppUTest/MemoryLeakDetectorMallocMacros.h -include ${CPPUTEST_INCLUDE_DIR}/CppUTest/MemoryLeakDetectorNewMacros.h") - - add_test(NAME framework_test_1 COMMAND attribute_test) - add_test(NAME framework_test_2 COMMAND bundle_archive_test) - #ADD_TARGET_FOR_TEST(bundle_cache_test) - add_test(NAME framework_test_3 COMMAND bundle_context_test) - add_test(NAME framework_test_4 COMMAND bundle_revision_test) - add_test(NAME framework_test_5 COMMAND bundle_test) - add_test(NAME framework_test_6 COMMAND capability_test) - add_test(NAME framework_test_7 COMMAND filter_test) - add_test(NAME framework_test_8 COMMAND framework_test) - add_test(NAME framework_test_9 COMMAND manifest_parser_test) - add_test(NAME framework_test_10 COMMAND manifest_test) - add_test(NAME framework_test_11 COMMAND module_test) - add_test(NAME framework_test_12 COMMAND properties_test) - add_test(NAME framework_test_13 COMMAND requirement_test) - add_test(NAME framework_test_14 COMMAND resolver_test) - add_test(NAME framework_test_15 COMMAND service_reference_test) - add_test(NAME framework_test_16 COMMAND service_registration_test) - add_test(NAME framework_test_17 COMMAND service_registry_test) - add_test(NAME framework_test_18 COMMAND service_tracker_customizer_test) - add_test(NAME framework_test_19 COMMAND service_tracker_test) - add_test(NAME framework_test_20 COMMAND version_range_test) - add_test(NAME framework_test_21 COMMAND version_test) - add_test(NAME framework_test_22 COMMAND wire_test) + configure_file(private/resources-test/manifest_sections.txt ${CMAKE_BINARY_DIR}/framework/resources-test/manifest_sections.txt [COPYONLY]) + configure_file(private/resources-test/manifest.txt ${CMAKE_BINARY_DIR}/framework/resources-test/manifest.txt [COPYONLY]) + configure_file(private/resources-test/properties.txt ${CMAKE_BINARY_DIR}/framework/resources-test/properties.txt [COPYONLY]) + + #set_target_properties(wire_test PROPERTIES COMPILE_FLAGS "-include ${CPPUTEST_INCLUDE_DIR}/CppUTest/MemoryLeakDetectorMallocMacros.h -include ${CPPUTEST_INCLUDE_DIR}/CppUTest/MemoryLeakDetectorNewMacros.h") + + add_test(NAME attribute_test COMMAND attribute_test) + add_test(NAME bundle_archive_test COMMAND bundle_archive_test) + add_test(NAME bundle_cache_test COMMAND bundle_cache_test) + add_test(NAME bundle_context_test COMMAND bundle_context_test) + add_test(NAME bundle_revision_test COMMAND bundle_revision_test) + add_test(NAME bundle_test COMMAND bundle_test) + add_test(NAME capability_test COMMAND capability_test) + add_test(NAME celix_errorcodes_test COMMAND celix_errorcodes_test) + add_test(NAME filter_test COMMAND filter_test) + add_test(NAME framework_test COMMAND framework_test) + add_test(NAME manifest_parser_test COMMAND manifest_parser_test) + add_test(NAME manifest_test COMMAND manifest_test) + add_test(NAME module_test COMMAND module_test) + add_test(NAME properties_test COMMAND properties_test) + add_test(NAME requirement_test COMMAND requirement_test) + add_test(NAME resolver_test COMMAND resolver_test) + add_test(NAME service_reference_test COMMAND service_reference_test) + add_test(NAME service_registration_test COMMAND service_registration_test) + add_test(NAME service_registry_test COMMAND service_registry_test) + add_test(NAME service_tracker_customizer_test COMMAND service_tracker_customizer_test) + add_test(NAME service_tracker_test COMMAND service_tracker_test) + add_test(NAME utils_test COMMAND utils_test) + add_test(NAME version_range_test COMMAND version_range_test) + add_test(NAME version_test COMMAND version_test) + add_test(NAME wire_test COMMAND wire_test) - SETUP_TARGET_FOR_COVERAGE(version_test_c version_test ${CMAKE_BINARY_DIR}/coverage/version_test) - SETUP_TARGET_FOR_COVERAGE(version_range_test_c version_range_test ${CMAKE_BINARY_DIR}/coverage/version_range_test) - SETUP_TARGET_FOR_COVERAGE(service_tracker_test_c service_tracker_test ${CMAKE_BINARY_DIR}/coverage/service_tracker_test) - SETUP_TARGET_FOR_COVERAGE(service_tracker_customizer_test_c service_tracker_customizer_test ${CMAKE_BINARY_DIR}/coverage/service_tracker_customizer_test) - SETUP_TARGET_FOR_COVERAGE(service_registry_test_c service_registry_test ${CMAKE_BINARY_DIR}/coverage/service_registry_test) - SETUP_TARGET_FOR_COVERAGE(service_registration_test_c service_registration_test ${CMAKE_BINARY_DIR}/coverage/service_registration_test) - SETUP_TARGET_FOR_COVERAGE(service_reference_test_c service_reference_test ${CMAKE_BINARY_DIR}/coverage/service_reference_test) - SETUP_TARGET_FOR_COVERAGE(resolver_test_c resolver_test ${CMAKE_BINARY_DIR}/coverage/resolver_test) - SETUP_TARGET_FOR_COVERAGE(requirement_test_c requirement_test ${CMAKE_BINARY_DIR}/coverage/requirement_test) - SETUP_TARGET_FOR_COVERAGE(properties_test_c properties_test ${CMAKE_BINARY_DIR}/coverage/properties_test) - SETUP_TARGET_FOR_COVERAGE(module_test_c module_test ${CMAKE_BINARY_DIR}/coverage/module_test) - SETUP_TARGET_FOR_COVERAGE(manifest_test_c manifest_test ${CMAKE_BINARY_DIR}/coverage/manifest_test) - SETUP_TARGET_FOR_COVERAGE(manifest_parser_test_c manifest_parser_test ${CMAKE_BINARY_DIR}/coverage/manifest_parser_test) - SETUP_TARGET_FOR_COVERAGE(framework_test_c framework_test ${CMAKE_BINARY_DIR}/coverage/framework_test) - SETUP_TARGET_FOR_COVERAGE(filter_test_c filter_test ${CMAKE_BINARY_DIR}/coverage/filter_test) - SETUP_TARGET_FOR_COVERAGE(capability_test_c capability_test ${CMAKE_BINARY_DIR}/coverage/capability_test) - SETUP_TARGET_FOR_COVERAGE(bundle_test_c bundle_test ${CMAKE_BINARY_DIR}/coverage/bundle_test) - SETUP_TARGET_FOR_COVERAGE(bundle_revision_test_c bundle_revision_test ${CMAKE_BINARY_DIR}/coverage/bundle_revision_test) - SETUP_TARGET_FOR_COVERAGE(bundle_context_test_c bundle_context_test ${CMAKE_BINARY_DIR}/coverage/bundle_context_test) - SETUP_TARGET_FOR_COVERAGE(bundle_cache_test_c bundle_cache_test ${CMAKE_BINARY_DIR}/coverage/bundle_cache_test) - SETUP_TARGET_FOR_COVERAGE(bundle_archive_test_c bundle_archive_test ${CMAKE_BINARY_DIR}/coverage/bundle_archive_test) - SETUP_TARGET_FOR_COVERAGE(attribute_test_c attribute_test ${CMAKE_BINARY_DIR}/coverage/attribute_test) - SETUP_TARGET_FOR_COVERAGE(wire_test_c wire_test ${CMAKE_BINARY_DIR}/coverage/wire_test) + SETUP_TARGET_FOR_COVERAGE(attribute_test attribute_test ${CMAKE_BINARY_DIR}/coverage/attribute_test/attribute_test) + SETUP_TARGET_FOR_COVERAGE(bundle_archive_test bundle_archive_test ${CMAKE_BINARY_DIR}/coverage/bundle_archive/bundle_archive_test) + SETUP_TARGET_FOR_COVERAGE(bundle_cache_test bundle_cache_test ${CMAKE_BINARY_DIR}/coverage/bundle_cache_test/bundle_cache_test) + SETUP_TARGET_FOR_COVERAGE(bundle_context_test bundle_context_test ${CMAKE_BINARY_DIR}/coverage/bundle_context_test/bundle_context_test) + SETUP_TARGET_FOR_COVERAGE(bundle_revision_test bundle_revision_test ${CMAKE_BINARY_DIR}/coverage/bundle_revision_test/bundle_revision_test) + SETUP_TARGET_FOR_COVERAGE(bundle_test bundle_test ${CMAKE_BINARY_DIR}/coverage/bundle_test/bundle_test) + SETUP_TARGET_FOR_COVERAGE(capability_test capability_test ${CMAKE_BINARY_DIR}/coverage/capability_test/capability_test) + SETUP_TARGET_FOR_COVERAGE(celix_errorcodes_test celix_errorcodes_test ${CMAKE_BINARY_DIR}/coverage/celix_errorcodes_test/celix_errorcodes_test) + SETUP_TARGET_FOR_COVERAGE(filter_test filter_test ${CMAKE_BINARY_DIR}/coverage/filter_test/filter_test) + SETUP_TARGET_FOR_COVERAGE(framework_test framework_test ${CMAKE_BINARY_DIR}/coverage/framework_test/framework_test) + SETUP_TARGET_FOR_COVERAGE(manifest_parser_test manifest_parser_test ${CMAKE_BINARY_DIR}/coverage/manifest_parser_test/manifest_parser_test) + SETUP_TARGET_FOR_COVERAGE(manifest_test manifest_test ${CMAKE_BINARY_DIR}/coverage/manifest_test/manifest_test) + SETUP_TARGET_FOR_COVERAGE(module_test module_test ${CMAKE_BINARY_DIR}/coverage/module_test/module_test) + SETUP_TARGET_FOR_COVERAGE(properties_test properties_test ${CMAKE_BINARY_DIR}/coverage/properties_test/properties_test) + SETUP_TARGET_FOR_COVERAGE(requirement_test requirement_test ${CMAKE_BINARY_DIR}/coverage/requirement_test/requirement_test) + SETUP_TARGET_FOR_COVERAGE(resolver_test resolver_test ${CMAKE_BINARY_DIR}/coverage/resolver_test/resolver_test) + SETUP_TARGET_FOR_COVERAGE(service_reference_test service_reference_test ${CMAKE_BINARY_DIR}/coverage/service_reference_test/service_reference_test) + SETUP_TARGET_FOR_COVERAGE(service_registration_test service_registration_test ${CMAKE_BINARY_DIR}/coverage/service_registration_test/service_registration_test) + SETUP_TARGET_FOR_COVERAGE(service_registry_test service_registry_test ${CMAKE_BINARY_DIR}/coverage/service_registry_test/service_registry_test) + SETUP_TARGET_FOR_COVERAGE(service_tracker_customizer_test service_tracker_customizer_test ${CMAKE_BINARY_DIR}/coverage/service_tracker_customizer_test/service_tracker_customizer_test) + SETUP_TARGET_FOR_COVERAGE(service_tracker_test service_tracker_test ${CMAKE_BINARY_DIR}/coverage/service_tracker_test/service_tracker_test) + SETUP_TARGET_FOR_COVERAGE(utils_test utils_test ${CMAKE_BINARY_DIR}/coverage/utils_test/utils_test) + SETUP_TARGET_FOR_COVERAGE(version_range_test version_range_test ${CMAKE_BINARY_DIR}/coverage/version_range_test/version_range_test) + SETUP_TARGET_FOR_COVERAGE(version_test version_test ${CMAKE_BINARY_DIR}/coverage/version_test/version_test) + SETUP_TARGET_FOR_COVERAGE(wire_test wire_test ${CMAKE_BINARY_DIR}/coverage/wire_test/wire_test) endif (ENABLE_TESTING AND FRAMEWORK_TESTS) endif (FRAMEWORK) diff --git a/framework/private/include/bundle_cache.h b/framework/private/include/bundle_cache.h index 6a04ff8a2..0deab4078 100644 --- a/framework/private/include/bundle_cache.h +++ b/framework/private/include/bundle_cache.h @@ -54,7 +54,7 @@ typedef struct bundleCache *bundle_cache_pt; * - CELIX_ILLEGAL_ARGUMENT If bundle_cache not is null. * - CELIX_ENOMEM If allocating memory for bundle_cache failed. */ -celix_status_t bundleCache_create(properties_pt configurationMap, framework_logger_pt logger, bundle_cache_pt *bundle_cache); +celix_status_t bundleCache_create(properties_pt configurationMap, bundle_cache_pt *bundle_cache); /** * Frees the bundle_cache memory allocated in bundleCache_create diff --git a/framework/private/include/bundle_cache_private.h b/framework/private/include/bundle_cache_private.h index 635f1942f..69e26ee27 100644 --- a/framework/private/include/bundle_cache_private.h +++ b/framework/private/include/bundle_cache_private.h @@ -33,7 +33,6 @@ struct bundleCache { properties_pt configurationMap; char * cacheDir; - framework_logger_pt logger; }; diff --git a/framework/private/include/bundle_context_private.h b/framework/private/include/bundle_context_private.h index b4ed8422f..3810cd0b6 100644 --- a/framework/private/include/bundle_context_private.h +++ b/framework/private/include/bundle_context_private.h @@ -37,7 +37,6 @@ struct bundleContext { #endif struct framework * framework; struct bundle * bundle; - framework_logger_pt logger; }; diff --git a/framework/private/include/bundle_revision_private.h b/framework/private/include/bundle_revision_private.h index d52980b83..cb1dcd80d 100644 --- a/framework/private/include/bundle_revision_private.h +++ b/framework/private/include/bundle_revision_private.h @@ -35,7 +35,6 @@ struct bundleRevision { char *root; char *location; manifest_pt manifest; - framework_logger_pt logger; array_list_pt libraryHandles; }; diff --git a/framework/private/include/service_reference_private.h b/framework/private/include/service_reference_private.h index 002fd879f..b297c14ea 100644 --- a/framework/private/include/service_reference_private.h +++ b/framework/private/include/service_reference_private.h @@ -41,6 +41,4 @@ celix_status_t serviceReference_destroy(service_reference_pt *reference); celix_status_t serviceReference_invalidate(service_reference_pt reference); celix_status_t serviceRefernce_isValid(service_reference_pt reference, bool *result); -celix_status_t serviceReference_getServiceRegistration(service_reference_pt reference, service_registration_pt *registration); - #endif /* SERVICE_REFERENCE_PRIVATE_H_ */ diff --git a/framework/private/include/service_registration_private.h b/framework/private/include/service_registration_private.h index 4c3e33380..8f31a1460 100644 --- a/framework/private/include/service_registration_private.h +++ b/framework/private/include/service_registration_private.h @@ -62,7 +62,7 @@ void serviceRegistration_invalidate(service_registration_pt registration); celix_status_t serviceRegistration_getService(service_registration_pt registration, bundle_pt bundle, void **service); celix_status_t serviceRegistration_ungetService(service_registration_pt registration, bundle_pt bundle, void **service); -celix_status_t serviceRegistration_getProperties(service_registration_pt registration, properties_pt *properties); + celix_status_t serviceRegistration_getRegistry(service_registration_pt registration, service_registry_pt *registry); celix_status_t serviceRegistration_getBundle(service_registration_pt registration, bundle_pt *bundle); celix_status_t serviceRegistration_getServiceName(service_registration_pt registration, char **serviceName); diff --git a/framework/private/integration-test/test_bundle1/src/activator.c b/framework/private/integration-test/test_bundle1/src/activator.c index 8e1005baf..4d5261fd7 100644 --- a/framework/private/integration-test/test_bundle1/src/activator.c +++ b/framework/private/integration-test/test_bundle1/src/activator.c @@ -25,7 +25,6 @@ */ #include #include -#include #include "bundle_activator.h" #include "bundle_context.h" @@ -38,27 +37,20 @@ struct userData { celix_status_t test_frameworkEvent(void *listener, framework_event_pt event); celix_status_t bundleActivator_create(bundle_context_pt context, void **userData) { - apr_pool_t *pool; - celix_status_t status = bundleContext_getMemoryPool(context, &pool); - if (status == CELIX_SUCCESS) { - *userData = apr_palloc(pool, sizeof(struct userData)); - ((struct userData *)(*userData))->listener = NULL; - } else { - status = CELIX_START_ERROR; + *userData = calloc(1, sizeof(struct userData)); + if(*userData == NULL){ + return CELIX_ENOMEM; } return CELIX_SUCCESS; } celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) { struct userData * activator = (struct userData *) userData; - apr_pool_t *pool; - bundleContext_getMemoryPool(context, &pool); - - activator->listener = apr_palloc(pool, sizeof(*activator->listener)); - activator->listener->handle = activator; - activator->listener->frameworkEvent = test_frameworkEvent; - bundleContext_addFrameworkListener(context, activator->listener); + activator->listener = calloc(1, sizeof(*activator->listener)); + activator->listener->handle = activator; + activator->listener->frameworkEvent = test_frameworkEvent; + bundleContext_addFrameworkListener(context, activator->listener); return CELIX_SUCCESS; } @@ -72,6 +64,12 @@ celix_status_t bundleActivator_stop(void * userData, bundle_context_pt context) } celix_status_t bundleActivator_destroy(void * userData, bundle_context_pt context) { + struct userData * activator = (struct userData *) userData; + if(activator->listener != NULL){ + free(activator->listener); + } + + free(activator); return CELIX_SUCCESS; } diff --git a/framework/private/mock/attribute_mock.c b/framework/private/mock/attribute_mock.c index 74c905a25..c71d8da08 100644 --- a/framework/private/mock/attribute_mock.c +++ b/framework/private/mock/attribute_mock.c @@ -36,7 +36,8 @@ celix_status_t attribute_create(char * key, char * value, attribute_pt *attribut } celix_status_t attribute_destroy(attribute_pt attribute) { - mock_c()->actualCall("attribute_destroy"); + mock_c()->actualCall("attribute_destroy") + ->withPointerParameters("attribute", attribute); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/bundle_archive_mock.c b/framework/private/mock/bundle_archive_mock.c index 83e7ccf34..d9b416c3f 100644 --- a/framework/private/mock/bundle_archive_mock.c +++ b/framework/private/mock/bundle_archive_mock.c @@ -27,9 +27,8 @@ #include "bundle_archive.h" -celix_status_t bundleArchive_create(framework_logger_pt logger, char * archiveRoot, long id, char * location, char *inputFile, bundle_archive_pt *bundle_archive) { +celix_status_t bundleArchive_create(char * archiveRoot, long id, char * location, char *inputFile, bundle_archive_pt *bundle_archive) { mock_c()->actualCall("bundleArchive_create") - ->withPointerParameters("logger", logger) ->withStringParameters("archiveRoot", archiveRoot) ->withIntParameters("id", id) ->withStringParameters("location", location) @@ -38,9 +37,8 @@ celix_status_t bundleArchive_create(framework_logger_pt logger, char * archiveRo return mock_c()->returnValue().value.intValue; } -celix_status_t bundleArchive_createSystemBundleArchive(framework_logger_pt logger, bundle_archive_pt *bundle_archive) { +celix_status_t bundleArchive_createSystemBundleArchive(bundle_archive_pt *bundle_archive) { mock_c()->actualCall("bundleArchive_createSystemBundleArchive") - ->withPointerParameters("logger", logger) ->withOutputParameter("bundle_archive", (void **) bundle_archive); return mock_c()->returnValue().value.intValue; } @@ -112,7 +110,8 @@ celix_status_t bundleArchive_setRefreshCount(bundle_archive_pt archive) { } celix_status_t bundleArchive_close(bundle_archive_pt archive) { - mock_c()->actualCall("bundleArchive_close"); + mock_c()->actualCall("bundleArchive_close") + ->withPointerParameters("archive", archive); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/bundle_cache_mock.c b/framework/private/mock/bundle_cache_mock.c index 606dd4bbe..925245d43 100644 --- a/framework/private/mock/bundle_cache_mock.c +++ b/framework/private/mock/bundle_cache_mock.c @@ -27,8 +27,8 @@ #include "bundle_cache.h" -celix_status_t bundleCache_create(properties_pt configurationMap, framework_logger_pt logger, bundle_cache_pt *bundle_cache) { - mock_c()->actualCall("bundle_getCurrentModule"); +celix_status_t bundleCache_create(properties_pt configurationMap, bundle_cache_pt *bundle_cache) { + mock_c()->actualCall("bundleCache_create"); return mock_c()->returnValue().value.intValue; } @@ -38,17 +38,17 @@ celix_status_t bundleCache_destroy(bundle_cache_pt *cache) { } celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *archives) { - mock_c()->actualCall("bundle_getCurrentModule"); + mock_c()->actualCall("bundleCache_getArchives"); return mock_c()->returnValue().value.intValue; } celix_status_t bundleCache_createArchive(bundle_cache_pt cache, long id, char * location, char *inputFile, bundle_archive_pt *archive) { - mock_c()->actualCall("bundle_getCurrentModule"); + mock_c()->actualCall("bundleCache_createArchive"); return mock_c()->returnValue().value.intValue; } celix_status_t bundleCache_delete(bundle_cache_pt cache) { - mock_c()->actualCall("bundle_getCurrentModule"); + mock_c()->actualCall("bundleCache_delete"); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/bundle_mock.c b/framework/private/mock/bundle_mock.c index 7b304c3f3..9802f51e0 100644 --- a/framework/private/mock/bundle_mock.c +++ b/framework/private/mock/bundle_mock.c @@ -27,24 +27,34 @@ #include "bundle_private.h" -celix_status_t bundle_create(bundle_pt * bundle, framework_logger_pt logger) { +celix_status_t bundle_create(bundle_pt * bundle) { + mock_c()->actualCall("bundle_create"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_createFromArchive(bundle_pt * bundle, framework_pt framework, bundle_archive_pt archive) { + mock_c()->actualCall("bundle_createFromArchive") + ->withPointerParameters("bundle", bundle) + ->withPointerParameters("framework", framework) + ->withPointerParameters("archive", archive); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_destroy(bundle_pt bundle) { + mock_c()->actualCall("destroy"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_isSystemBundle(bundle_pt bundle, bool *systemBundle) { + mock_c()->actualCall("bundle_isSystembundle") + ->withPointerParameters("bundle", bundle) + ->withOutputParameter("systemBundle", systemBundle); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_getArchive(bundle_pt bundle, bundle_archive_pt *archive) { + mock_c()->actualCall("bundle_getArchive"); return mock_c()->returnValue().value.intValue; } @@ -56,154 +66,190 @@ celix_status_t bundle_getCurrentModule(bundle_pt bundle, module_pt *module) { } array_list_pt bundle_getModules(bundle_pt bundle) { + mock_c()->actualCall("bundle_getModules"); return mock_c()->returnValue().value.pointerValue; } void * bundle_getHandle(bundle_pt bundle) { + mock_c()->actualCall("bundle_getHandle"); return mock_c()->returnValue().value.pointerValue; } void bundle_setHandle(bundle_pt bundle, void * handle) { + mock_c()->actualCall("bundle_setHandle"); } activator_pt bundle_getActivator(bundle_pt bundle) { + mock_c()->actualCall("bundle_getActivator"); return mock_c()->returnValue().value.pointerValue; } celix_status_t bundle_setActivator(bundle_pt bundle, activator_pt activator) { + mock_c()->actualCall("bundle_setActivator"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_getContext(bundle_pt bundle, bundle_context_pt *context) { + mock_c()->actualCall("bundle_getContext"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_setContext(bundle_pt bundle, bundle_context_pt context) { + mock_c()->actualCall("bundle_setContext"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_getEntry(bundle_pt bundle, char * name, char **entry) { + mock_c()->actualCall("bundle_getEntry"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_start(bundle_pt bundle) { + mock_c()->actualCall("bundle_start"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_startWithOptions(bundle_pt bundle, int options) { + mock_c()->actualCall("bundle_startWithOptions"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_update(bundle_pt bundle, char *inputFile) { + mock_c()->actualCall("bundle_update"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_stop(bundle_pt bundle) { + mock_c()->actualCall("bundle_stop"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_stopWithOptions(bundle_pt bundle, int options) { + mock_c()->actualCall("bundle_stopWithOptions"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_uninstall(bundle_pt bundle) { + mock_c()->actualCall("bundle_uninstall"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_setState(bundle_pt bundle, bundle_state_e state) { + mock_c()->actualCall("bundle_setState"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_setPersistentStateInactive(bundle_pt bundle) { + mock_c()->actualCall("bundle_setPersistentStateInactive"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_setPersistentStateUninstalled(bundle_pt bundle) { + mock_c()->actualCall("bundle_setPersistentStateUninstalled"); return mock_c()->returnValue().value.intValue; } void uninstallBundle(bundle_pt bundle) { + mock_c()->actualCall("uninstallBundle"); } celix_status_t bundle_revise(bundle_pt bundle, char * location, char *inputFile) { + mock_c()->actualCall("bundle_revise"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_addModule(bundle_pt bundle, module_pt module) { + mock_c()->actualCall("bundle_addModule"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_closeModules(bundle_pt bundle) { + mock_c()->actualCall("bundle_closeModules"); return mock_c()->returnValue().value.intValue; } // Service Reference Functions array_list_pt getUsingBundles(service_reference_pt reference) { + mock_c()->actualCall("getUsingBundles"); return mock_c()->returnValue().value.pointerValue; } int compareTo(service_reference_pt a, service_reference_pt b) { + mock_c()->actualCall("service_reference_pt"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_getState(bundle_pt bundle, bundle_state_e *state) { + mock_c()->actualCall("bundle_getState"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_isLockable(bundle_pt bundle, bool *lockable) { + mock_c()->actualCall("bundle_isLockable"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_getLockingThread(bundle_pt bundle, celix_thread_t *thread) { + mock_c()->actualCall("bundle_getLockingThread"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_lock(bundle_pt bundle, bool *locked) { + mock_c()->actualCall("bundle_lock"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_unlock(bundle_pt bundle, bool *unlocked) { + mock_c()->actualCall("bundle_unlock"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_closeAndDelete(bundle_pt bundle) { + mock_c()->actualCall("bundle_closeAndDelete"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_close(bundle_pt bundle) { + mock_c()->actualCall("bundle_close"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_refresh(bundle_pt bundle) { + mock_c()->actualCall("bundle_refresh"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_getBundleId(bundle_pt bundle, long *id) { + mock_c()->actualCall("bundle_getBundleId"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_getRegisteredServices(bundle_pt bundle, array_list_pt *list) { + mock_c()->actualCall("bundle_getRegisteredServices"); return mock_c()->returnValue().value.intValue; } celix_status_t bundle_getServicesInUse(bundle_pt bundle, array_list_pt *list) { - return mock_c()->returnValue().value.intValue; + mock_c()->actualCall("bundle_getServicesInUse"); + return mock_c()->returnValue().value.intValue; } celix_status_t bundle_setFramework(bundle_pt bundle, framework_pt framework) { - return mock_c()->returnValue().value.intValue; + mock_c()->actualCall("bundle_setFramework"); + return mock_c()->returnValue().value.intValue; } celix_status_t bundle_getFramework(bundle_pt bundle, framework_pt *framework) { + mock_c()->actualCall("bundle_getFramework"); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/bundle_revision_mock.c b/framework/private/mock/bundle_revision_mock.c index bbc62d7e5..847467cf9 100644 --- a/framework/private/mock/bundle_revision_mock.c +++ b/framework/private/mock/bundle_revision_mock.c @@ -27,7 +27,7 @@ #include "bundle_revision.h" -celix_status_t bundleRevision_create(framework_logger_pt logger, char *root, char *location, long revisionNr, char *inputFile, bundle_revision_pt *bundle_revision) { +celix_status_t bundleRevision_create(char *root, char *location, long revisionNr, char *inputFile, bundle_revision_pt *bundle_revision) { mock_c()->actualCall("bundleRevision_create"); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/capability_mock.c b/framework/private/mock/capability_mock.c index c305e1f91..83bd39b02 100644 --- a/framework/private/mock/capability_mock.c +++ b/framework/private/mock/capability_mock.c @@ -38,7 +38,9 @@ celix_status_t capability_destroy(capability_pt capability) { } celix_status_t capability_getServiceName(capability_pt capability, char **serviceName) { - mock_c()->actualCall("capability_getServiceName"); + mock_c()->actualCall("capability_getServiceName") + ->withPointerParameters("capability", capability) + ->withOutputParameter("serviceName", serviceName); return mock_c()->returnValue().value.intValue; } @@ -50,7 +52,9 @@ celix_status_t capability_getVersion(capability_pt capability, version_pt *versi } celix_status_t capability_getModule(capability_pt capability, module_pt *module) { - mock_c()->actualCall("capability_getModule"); + mock_c()->actualCall("capability_getModule") + ->withPointerParameters("capability", capability) + ->withOutputParameter("module", module); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/celix_log_mock.c b/framework/private/mock/celix_log_mock.c new file mode 100644 index 000000000..066077d90 --- /dev/null +++ b/framework/private/mock/celix_log_mock.c @@ -0,0 +1,41 @@ +/** + *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. + */ +/* + * celix_log_mock.c + * + * \date Oct, 5 2015 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ +#include "CppUTestExt/MockSupport_c.h" + +#include "celix_log.h" + +void framework_log(framework_logger_pt logger, framework_log_level_t level, const char *func, const char *file, int line, char *fmsg, ...) { + mock_c()->actualCall("framework_log"); +} + +void framework_logCode(framework_logger_pt logger, framework_log_level_t level, const char *func, const char *file, int line, celix_status_t code, char *fmsg, ...) { + mock_c()->actualCall("framework_logCode")->withIntParameters("code", code); +} + +celix_status_t frameworkLogger_log(framework_log_level_t level, const char *func, const char *file, int line, char *msg) { + mock_c()->actualCall("frameworkLogger_log"); + return mock_c()->returnValue().value.intValue; +} diff --git a/framework/private/mock/filter_mock.c b/framework/private/mock/filter_mock.c index 590693230..8242b99ff 100644 --- a/framework/private/mock/filter_mock.c +++ b/framework/private/mock/filter_mock.c @@ -28,17 +28,20 @@ #include "filter.h" filter_pt filter_create(char * filterString) { + mock_c()->actualCall("filter_create"); return mock_c()->returnValue().value.pointerValue; } void filter_destroy(filter_pt filter) { - + mock_c()->actualCall("filter_destroy"); } celix_status_t filter_match(filter_pt filter, properties_pt properties, bool *result) { + mock_c()->actualCall("filter_match"); return mock_c()->returnValue().value.intValue; } celix_status_t filter_getString(filter_pt filter, char **filterStr) { + mock_c()->actualCall("filter_getString"); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/framework_mock.c b/framework/private/mock/framework_mock.c index d027df911..c6fb2e90a 100644 --- a/framework/private/mock/framework_mock.c +++ b/framework/private/mock/framework_mock.c @@ -28,8 +28,8 @@ #include "framework_private.h" celix_status_t framework_create(framework_pt *framework, properties_pt config) { - mock_c()->actualCall("framework_create"); - return mock_c()->returnValue().value.intValue; + mock_c()->actualCall("framework_create"); + return mock_c()->returnValue().value.intValue; } celix_status_t framework_destroy(framework_pt framework) { @@ -174,12 +174,18 @@ celix_status_t framework_ungetService(framework_pt framework, bundle_pt bundle, } celix_status_t fw_getBundleRegisteredServices(framework_pt framework, bundle_pt bundle, array_list_pt *services) { - mock_c()->actualCall("fw_getBundleRegisteredServices"); + mock_c()->actualCall("fw_getBundleRegisteredServices") + ->withPointerParameters("framework", framework) + ->withPointerParameters("bundle", bundle) + ->withOutputParameter("services", (void **) services); return mock_c()->returnValue().value.intValue; } celix_status_t fw_getBundleServicesInUse(framework_pt framework, bundle_pt bundle, array_list_pt *services) { - mock_c()->actualCall("fw_getBundleServicesInUse"); + mock_c()->actualCall("fw_getBundleServicesInUse") + ->withPointerParameters("framework", framework) + ->withPointerParameters("bundle", bundle) + ->withOutputParameter("services", (void **) services); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/manifest_mock.c b/framework/private/mock/manifest_mock.c index 9e783daaf..a74601ccd 100644 --- a/framework/private/mock/manifest_mock.c +++ b/framework/private/mock/manifest_mock.c @@ -65,11 +65,11 @@ celix_status_t manifest_read(manifest_pt manifest, char *filename) { } void manifest_write(manifest_pt manifest, char * filename) { - mock_c()->actualCall("bundle_getCurrentModule"); + mock_c()->actualCall("manifest_write"); } char * manifest_getValue(manifest_pt manifest, const char * name) { - mock_c()->actualCall("bundle_getCurrentModule"); + mock_c()->actualCall("manifest_getValue"); return (char *) mock_c()->returnValue().value.stringValue; } diff --git a/framework/private/mock/manifest_parser_mock.c b/framework/private/mock/manifest_parser_mock.c index 32d5cf6b9..dd5502008 100644 --- a/framework/private/mock/manifest_parser_mock.c +++ b/framework/private/mock/manifest_parser_mock.c @@ -38,22 +38,26 @@ celix_status_t manifestParser_destroy(manifest_parser_pt manifest_parser) { } celix_status_t manifestParser_getSymbolicName(manifest_parser_pt parser, char **symbolicName) { - mock_c()->actualCall("manifestParser_getSymbolicName"); + mock_c()->actualCall("manifestParser_getSymbolicName") + ->withOutputParameter("symbolicName", (void**) symbolicName); return mock_c()->returnValue().value.intValue; } celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, version_pt *version) { - mock_c()->actualCall("manifestParser_getBundleVersion"); + mock_c()->actualCall("manifestParser_getBundleVersion") + ->withOutputParameter("version", (void**) version); return mock_c()->returnValue().value.intValue; } celix_status_t manifestParser_getCapabilities(manifest_parser_pt parser, linked_list_pt *capabilities) { - mock_c()->actualCall("manifestParser_getCapabilities"); + mock_c()->actualCall("manifestParser_getCapabilities") + ->withOutputParameter("capabilities", (void**) capabilities); return mock_c()->returnValue().value.intValue; } celix_status_t manifestParser_getRequirements(manifest_parser_pt parser, linked_list_pt *requirements) { - mock_c()->actualCall("bundle_getCurrentModule"); + mock_c()->actualCall("manifestParser_getCurrentRequirements") + ->withOutputParameter("requirements", (void**) requirements); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/module_mock.c b/framework/private/mock/module_mock.c index 189713fba..36c70ca88 100644 --- a/framework/private/mock/module_mock.c +++ b/framework/private/mock/module_mock.c @@ -56,7 +56,7 @@ int module_equals(void * module, void * compare) { } wire_pt module_getWire(module_pt module, char * serviceName) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_getwire"); return mock_c()->returnValue().value.pointerValue; } @@ -74,71 +74,71 @@ celix_status_t module_getSymbolicName(module_pt module, char **symbolicName) { } char * module_getId(module_pt module) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_getId"); return (char *) mock_c()->returnValue().value.stringValue; } linked_list_pt module_getWires(module_pt module) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_getWires"); return mock_c()->returnValue().value.pointerValue; } void module_setWires(module_pt module, linked_list_pt wires) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_setWires"); } bool module_isResolved(module_pt module) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_isResolved"); return mock_c()->returnValue().value.intValue; } void module_setResolved(module_pt module) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_setResolved"); } bundle_pt module_getBundle(module_pt module) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_getBundle"); return mock_c()->returnValue().value.pointerValue; } linked_list_pt module_getRequirements(module_pt module) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_getRequirements"); return mock_c()->returnValue().value.pointerValue; } linked_list_pt module_getCapabilities(module_pt module) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_getCapabilities"); return mock_c()->returnValue().value.pointerValue; } array_list_pt module_getDependentImporters(module_pt module) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_getDependentImporters"); return mock_c()->returnValue().value.pointerValue; } void module_addDependentImporter(module_pt module, module_pt importer) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_addDependentImporter"); } void module_removeDependentImporter(module_pt module, module_pt importer) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_removeDependentImporter"); } array_list_pt module_getDependentRequirers(module_pt module) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_getDependentRequirers"); return mock_c()->returnValue().value.pointerValue; } void module_addDependentRequirer(module_pt module, module_pt requirer) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_addDependentRequirer"); } void module_removeDependentRequirer(module_pt module, module_pt requirer) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_removeDependentRequirer"); } array_list_pt module_getDependents(module_pt module) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("module_getDependents"); return mock_c()->returnValue().value.pointerValue; } diff --git a/framework/private/mock/requirement_mock.c b/framework/private/mock/requirement_mock.c index 4a12203f6..38de0799e 100644 --- a/framework/private/mock/requirement_mock.c +++ b/framework/private/mock/requirement_mock.c @@ -37,22 +37,30 @@ celix_status_t requirement_create(hash_map_pt directives, hash_map_pt attributes } celix_status_t requirement_destroy(requirement_pt requirement) { - mock_c()->actualCall("requirement_destroy"); + mock_c()->actualCall("requirement_destroy") + ->withPointerParameters("requirement", requirement); return mock_c()->returnValue().value.intValue; } celix_status_t requirement_getVersionRange(requirement_pt requirement, version_range_pt *range) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("requirement_getVersionRange") + ->withPointerParameters("requirement", requirement) + ->withOutputParameter("range", range); return mock_c()->returnValue().value.intValue; } celix_status_t requirement_getTargetName(requirement_pt requirement, char **targetName) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("requirement_getTargetName") + ->withPointerParameters("requirement", requirement) + ->withOutputParameter("targetName", targetName); return mock_c()->returnValue().value.intValue; } celix_status_t requirement_isSatisfied(requirement_pt requirement, capability_pt capability, bool *inRange) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("requirement_isSatisfied") + ->withPointerParameters("requirement", requirement) + ->withPointerParameters("capability", capability) + ->withOutputParameter("inRange", inRange); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/service_registration_mock.c b/framework/private/mock/service_registration_mock.c index 88de18480..e54be41bd 100644 --- a/framework/private/mock/service_registration_mock.c +++ b/framework/private/mock/service_registration_mock.c @@ -50,6 +50,8 @@ service_registration_pt serviceRegistration_createServiceFactory(service_registr } celix_status_t serviceRegistration_destroy(service_registration_pt registration) { + mock_c()->actualCall("serviceRegistration_destroy") + ->withPointerParameters("registration", registration); return mock_c()->returnValue().value.intValue; } @@ -84,7 +86,7 @@ celix_status_t serviceRegistration_ungetService(service_registration_pt registra mock_c()->actualCall("serviceRegistration_ungetService") ->withPointerParameters("registration", registration) ->withPointerParameters("bundle", bundle) - ->withPointerParameters("service", *service); + ->withOutputParameter("service", service); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/version_mock.c b/framework/private/mock/version_mock.c index ac83cd68b..c965d4fbf 100644 --- a/framework/private/mock/version_mock.c +++ b/framework/private/mock/version_mock.c @@ -28,24 +28,32 @@ #include "version.h" celix_status_t version_createVersion(int major, int minor, int micro, char * qualifier, version_pt *version) { - mock_c()->actualCall("version_createVersion"); + mock_c()->actualCall("version_createVersion") + ->withIntParameters("major", major) + ->withIntParameters("minor", minor) + ->withIntParameters("micro", micro) + ->withStringParameters("qualifier", qualifier) + ->withOutputParameter("version", version); return mock_c()->returnValue().value.intValue; } celix_status_t version_destroy(version_pt version) { - mock_c()->actualCall("version_destroy"); + mock_c()->actualCall("version_destroy") + ->withPointerParameters("version", version); return mock_c()->returnValue().value.intValue; } celix_status_t version_clone(version_pt version, version_pt *clone) { - mock_c()->actualCall("version_clone"); + mock_c()->actualCall("version_clone") + ->withPointerParameters("version", version) + ->withOutputParameter("clone", clone); return mock_c()->returnValue().value.intValue; } celix_status_t version_createVersionFromString(char * versionStr, version_pt *version) { mock_c()->actualCall("version_createVersionFromString") - ->withStringParameters("versionStr", versionStr) - ->withOutputParameter("version", (void **) version); + ->withStringParameters("versionStr", versionStr) + ->withOutputParameter("version", (void **) version); return mock_c()->returnValue().value.intValue; } @@ -56,36 +64,46 @@ celix_status_t version_createEmptyVersion(version_pt *version) { } celix_status_t version_getMajor(version_pt version, int *major) { - mock_c()->actualCall("version_getMajor"); + mock_c()->actualCall("version_getMajor") + ->withPointerParameters("version", version) + ->withOutputParameter("major", major); return mock_c()->returnValue().value.intValue; } celix_status_t version_getMinor(version_pt version, int *minor) { - mock_c()->actualCall("version_getMinor"); + mock_c()->actualCall("version_getMinor") + ->withPointerParameters("version", version) + ->withOutputParameter("minor", minor); return mock_c()->returnValue().value.intValue; } celix_status_t version_getMicro(version_pt version, int *micro) { - mock_c()->actualCall("version_getMicro"); + mock_c()->actualCall("version_getMicro") + ->withPointerParameters("version", version) + ->withOutputParameter("micro", micro); return mock_c()->returnValue().value.intValue; } celix_status_t version_getQualifier(version_pt version, char **qualifier) { - mock_c()->actualCall("version_getQualifier"); + mock_c()->actualCall("version_getQualifier") + ->withPointerParameters("version", version) + ->withOutputParameter("qualifier", qualifier); return mock_c()->returnValue().value.intValue; } celix_status_t version_compareTo(version_pt version, version_pt compare, int *result) { mock_c()->actualCall("version_compareTo") - ->withPointerParameters("version", version) - ->withPointerParameters("compare", compare) - ->withOutputParameter("result", result); + ->withPointerParameters("version", version) + ->withPointerParameters("compare", compare) + ->withOutputParameter("result", result); return CELIX_SUCCESS; } celix_status_t version_toString(version_pt version, char **string) { - mock_c()->actualCall("version_toString"); + mock_c()->actualCall("version_toString") + ->withPointerParameters("version", version) + ->withOutputParameter("string", string); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/version_range_mock.c b/framework/private/mock/version_range_mock.c index b8762fa15..14788d4f4 100644 --- a/framework/private/mock/version_range_mock.c +++ b/framework/private/mock/version_range_mock.c @@ -28,12 +28,18 @@ #include "version_range.h" celix_status_t versionRange_createVersionRange(version_pt low, bool isLowInclusive, version_pt high, bool isHighInclusive, version_range_pt *versionRange) { - mock_c()->actualCall("versionRange_createVersionRange"); + mock_c()->actualCall("versionRange_createVersionRange") + ->withPointerParameters("low", low) + ->withIntParameters("isLowInclusive", isLowInclusive) + ->withPointerParameters("high", high) + ->withIntParameters("isHighInclusive", isHighInclusive) + ->withOutputParameter("versionRange", versionRange); return mock_c()->returnValue().value.intValue; } celix_status_t versionRange_destroy(version_range_pt range) { - mock_c()->actualCall("versionRange_destroy"); + mock_c()->actualCall("versionRange_destroy") + ->withPointerParameters("range", range); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/mock/wire_mock.c b/framework/private/mock/wire_mock.c index 21561549e..017f86187 100644 --- a/framework/private/mock/wire_mock.c +++ b/framework/private/mock/wire_mock.c @@ -29,32 +29,46 @@ celix_status_t wire_create(module_pt importer, requirement_pt requirement, module_pt exporter, capability_pt capability, wire_pt *wire) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("wire_create") + ->withPointerParameters("importer", importer) + ->withPointerParameters("requirement", requirement) + ->withPointerParameters("exporter", exporter) + ->withPointerParameters("capability", capability) + ->withOutputParameter("wire", wire); return mock_c()->returnValue().value.intValue; } celix_status_t wire_destroy(wire_pt wire) { - mock_c()->actualCall("wire_destroy"); + mock_c()->actualCall("wire_destroy") + ->withPointerParameters("wire", wire); return mock_c()->returnValue().value.intValue; } celix_status_t wire_getCapability(wire_pt wire, capability_pt *capability) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("wire_getCapability") + ->withPointerParameters("wire", wire) + ->withOutputParameter("capability", (void**) capability); return mock_c()->returnValue().value.intValue; } celix_status_t wire_getRequirement(wire_pt wire, requirement_pt *requirement) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("wire_getRequirement") + ->withPointerParameters("wire", wire) + ->withOutputParameter("requirement", (void**) requirement); return mock_c()->returnValue().value.intValue; } celix_status_t wire_getImporter(wire_pt wire, module_pt *importer) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("wire_getImporter") + ->withPointerParameters("wire", wire) + ->withOutputParameter("importer", (void**) importer); return mock_c()->returnValue().value.intValue; } celix_status_t wire_getExporter(wire_pt wire, module_pt *exporter) { - mock_c()->actualCall("requirement_create"); + mock_c()->actualCall("wire_getExporter") + ->withPointerParameters("wire", wire) + ->withOutputParameter("exporter", (void**) exporter); return mock_c()->returnValue().value.intValue; } diff --git a/framework/private/src/bundle.c b/framework/private/src/bundle.c index dacd9c5a8..366363c3a 100644 --- a/framework/private/src/bundle.c +++ b/framework/private/src/bundle.c @@ -34,7 +34,7 @@ celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module); celix_status_t bundle_closeRevisions(bundle_pt bundle); -celix_status_t bundle_create(bundle_pt * bundle, framework_logger_pt logger) { +celix_status_t bundle_create(bundle_pt * bundle) { celix_status_t status; bundle_archive_pt archive = NULL; @@ -42,7 +42,7 @@ celix_status_t bundle_create(bundle_pt * bundle, framework_logger_pt logger) { if (*bundle == NULL) { return CELIX_ENOMEM; } - status = bundleArchive_createSystemBundleArchive(logger, &archive); + status = bundleArchive_createSystemBundleArchive(&archive); if (status == CELIX_SUCCESS) { module_pt module; @@ -85,6 +85,8 @@ celix_status_t bundle_createFromArchive(bundle_pt * bundle, framework_pt framewo (*bundle)->archive = archive; (*bundle)->activator = NULL; (*bundle)->context = NULL; + (*bundle)->handle = NULL; + (*bundle)->manifest = NULL; (*bundle)->framework = framework; (*bundle)->state = OSGI_FRAMEWORK_BUNDLE_INSTALLED; (*bundle)->modules = NULL; @@ -104,7 +106,7 @@ celix_status_t bundle_createFromArchive(bundle_pt * bundle, framework_pt framewo status = CELIX_FILE_IO_EXCEPTION; } - framework_logIfError(framework->logger, status, NULL, "Failed to create bundle"); + framework_logIfError(logger, status, NULL, "Failed to create bundle"); return status; } @@ -210,17 +212,14 @@ celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module) { status = CELIX_DO_IF(status, bundleArchive_getCurrentRevision(archive, &revision)); status = CELIX_DO_IF(status, bundleRevision_getManifest(revision, &headerMap)); if (status == CELIX_SUCCESS) { - long bundleId; + long bundleId = 0; status = bundleArchive_getId(bundle->archive, &bundleId); if (status == CELIX_SUCCESS) { int revision = 0; char moduleId[512]; - char *mId; snprintf(moduleId, sizeof(moduleId), "%ld.%d", bundleId, revision); - mId = strdup(moduleId); - *module = module_create(headerMap, mId, bundle); - free(mId); + *module = module_create(headerMap, moduleId, bundle); if (*module != NULL) { version_pt bundleVersion = module_getVersion(*module); @@ -262,7 +261,7 @@ celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module) { } } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to create module"); + framework_logIfError(logger, status, NULL, "Failed to create module"); return status; } @@ -285,7 +284,7 @@ celix_status_t bundle_startWithOptions(bundle_pt bundle, int options) { } } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to start bundle"); + framework_logIfError(logger, status, NULL, "Failed to start bundle"); return status; } @@ -305,7 +304,7 @@ celix_status_t bundle_update(bundle_pt bundle, char *inputFile) { } } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to update bundle"); + framework_logIfError(logger, status, NULL, "Failed to update bundle"); return status; } @@ -328,7 +327,7 @@ celix_status_t bundle_stopWithOptions(bundle_pt bundle, int options) { } } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to stop bundle"); + framework_logIfError(logger, status, NULL, "Failed to stop bundle"); return status; } @@ -347,7 +346,7 @@ celix_status_t bundle_uninstall(bundle_pt bundle) { } } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to uninstall bundle"); + framework_logIfError(logger, status, NULL, "Failed to uninstall bundle"); return status; } @@ -363,7 +362,7 @@ celix_status_t bundle_setPersistentStateInactive(bundle_pt bundle) { } } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to set persistent state to inactive"); + framework_logIfError(logger, status, NULL, "Failed to set persistent state to inactive"); return status; } @@ -379,7 +378,7 @@ celix_status_t bundle_setPersistentStateUninstalled(bundle_pt bundle) { } } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to set persistent state to uninstalled"); + framework_logIfError(logger, status, NULL, "Failed to set persistent state to uninstalled"); return status; } @@ -406,7 +405,7 @@ celix_status_t bundle_revise(bundle_pt bundle, char * location, char *inputFile) } } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to revise bundle"); + framework_logIfError(logger, status, NULL, "Failed to revise bundle"); return status; } @@ -435,7 +434,7 @@ celix_status_t bundle_isSystemBundle(bundle_pt bundle, bool *systemBundle) { } } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to check if bundle is the systembundle"); + framework_logIfError(logger, status, NULL, "Failed to check if bundle is the systembundle"); return status; } @@ -444,7 +443,7 @@ celix_status_t bundle_isLockable(bundle_pt bundle, bool *lockable) { celix_status_t status; status = celixThreadMutex_lock(&bundle->lock); - if (status != 0) { + if (status != CELIX_SUCCESS) { status = CELIX_BUNDLE_EXCEPTION; } else { bool equals; @@ -454,12 +453,12 @@ celix_status_t bundle_isLockable(bundle_pt bundle, bool *lockable) { } status = celixThreadMutex_unlock(&bundle->lock); - if (status != 0) { + if (status != CELIX_SUCCESS) { status = CELIX_BUNDLE_EXCEPTION; } } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to check if bundle is lockable"); + framework_logIfError(logger, status, NULL, "Failed to check if bundle is lockable"); return status; } @@ -468,18 +467,18 @@ celix_status_t bundle_getLockingThread(bundle_pt bundle, celix_thread_t *thread) celix_status_t status; status = celixThreadMutex_lock(&bundle->lock); - if (status != 0) { + if (status != CELIX_SUCCESS) { status = CELIX_BUNDLE_EXCEPTION; } else { *thread = bundle->lockThread; status = celixThreadMutex_unlock(&bundle->lock); - if (status != 0) { + if (status != CELIX_SUCCESS) { status = CELIX_BUNDLE_EXCEPTION; } } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to get locking thread"); + framework_logIfError(logger, status, NULL, "Failed to get locking thread"); return status; } @@ -503,7 +502,7 @@ celix_status_t bundle_lock(bundle_pt bundle, bool *locked) { celixThreadMutex_unlock(&bundle->lock); - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to lock bundle"); + framework_logIfError(logger, status, NULL, "Failed to lock bundle"); return status; } @@ -521,19 +520,21 @@ celix_status_t bundle_unlock(bundle_pt bundle, bool *unlocked) { status = thread_equalsSelf(bundle->lockThread, &equals); if (status == CELIX_SUCCESS) { if ((bundle->lockCount > 0) && !equals) { - return false; - } - bundle->lockCount--; - if (bundle->lockCount == 0) { - bundle->lockThread = celix_thread_default; + *unlocked = false; } - *unlocked = true; - } + else{ + bundle->lockCount--; + if (bundle->lockCount == 0) { + bundle->lockThread = celix_thread_default; + } + *unlocked = true; + } + } } celixThreadMutex_unlock(&bundle->lock); - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to unlock bundle"); + framework_logIfError(logger, status, NULL, "Failed to unlock bundle"); return status; } @@ -550,7 +551,7 @@ celix_status_t bundle_close(bundle_pt bundle) { bundleArchive_close(archive); } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to close bundle"); + framework_logIfError(logger, status, NULL, "Failed to close bundle"); return status; } @@ -567,7 +568,7 @@ celix_status_t bundle_closeAndDelete(bundle_pt bundle) { bundleArchive_closeAndDelete(archive); } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to close and delete bundle"); + framework_logIfError(logger, status, NULL, "Failed to close and delete bundle"); return status; } @@ -608,7 +609,7 @@ celix_status_t bundle_refresh(bundle_pt bundle) { } } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to refresh bundle"); + framework_logIfError(logger, status, NULL, "Failed to refresh bundle"); return status; } @@ -621,7 +622,7 @@ celix_status_t bundle_getBundleId(bundle_pt bundle, long *id) { status = bundleArchive_getId(archive, id); } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to get bundle id"); + framework_logIfError(logger, status, NULL, "Failed to get bundle id"); return status; } @@ -641,7 +642,7 @@ celix_status_t bundle_getServicesInUse(bundle_pt bundle, array_list_pt *list) { status = fw_getBundleServicesInUse(bundle->framework, bundle, list); - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to get in use services"); + framework_logIfError(logger, status, NULL, "Failed to get in use services"); return status; } @@ -655,7 +656,7 @@ celix_status_t bundle_setFramework(bundle_pt bundle, framework_pt framework) { status = CELIX_ILLEGAL_ARGUMENT; } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to set framework"); + framework_logIfError(logger, status, NULL, "Failed to set framework"); return status; } @@ -669,7 +670,7 @@ celix_status_t bundle_getFramework(bundle_pt bundle, framework_pt *framework) { status = CELIX_ILLEGAL_ARGUMENT; } - framework_logIfError(bundle->framework->logger, status, NULL, "Failed to get framework"); + framework_logIfError(logger, status, NULL, "Failed to get framework"); return status; } diff --git a/framework/private/src/bundle_archive.c b/framework/private/src/bundle_archive.c index a676d6a25..c1a23aa65 100644 --- a/framework/private/src/bundle_archive.c +++ b/framework/private/src/bundle_archive.c @@ -45,7 +45,6 @@ struct bundleArchive { linked_list_pt revisions; long refreshCount; time_t lastModified; - framework_logger_pt logger; bundle_state_e persistentState; }; @@ -63,7 +62,7 @@ static celix_status_t bundleArchive_reviseInternal(bundle_archive_pt archive, bo static celix_status_t bundleArchive_readLastModified(bundle_archive_pt archive, time_t *time); static celix_status_t bundleArchive_writeLastModified(bundle_archive_pt archive); -celix_status_t bundleArchive_createSystemBundleArchive(framework_logger_pt logger, bundle_archive_pt *bundle_archive) { +celix_status_t bundleArchive_createSystemBundleArchive(bundle_archive_pt *bundle_archive) { celix_status_t status = CELIX_SUCCESS; char *error = NULL; bundle_archive_pt archive; @@ -84,7 +83,6 @@ celix_status_t bundleArchive_createSystemBundleArchive(framework_logger_pt logge archive->archiveRootDir = NULL; archive->refreshCount = -1; archive->persistentState = OSGI_FRAMEWORK_BUNDLE_UNKNOWN; - archive->logger = logger; time(&archive->lastModified); *bundle_archive = archive; @@ -97,7 +95,7 @@ celix_status_t bundleArchive_createSystemBundleArchive(framework_logger_pt logge return status; } -celix_status_t bundleArchive_create(framework_logger_pt logger, char * archiveRoot, long id, char * location, char *inputFile, bundle_archive_pt *bundle_archive) { +celix_status_t bundleArchive_create(char * archiveRoot, long id, char * location, char *inputFile, bundle_archive_pt *bundle_archive) { celix_status_t status = CELIX_SUCCESS; char *error = NULL; bundle_archive_pt archive; @@ -115,9 +113,8 @@ celix_status_t bundleArchive_create(framework_logger_pt logger, char * archiveRo archive->id = id; archive->location = strdup(location); archive->archiveRootDir = NULL; - archive->archiveRoot = archiveRoot; + archive->archiveRoot = strdup(archiveRoot); archive->refreshCount = -1; - archive->logger = logger; time(&archive->lastModified); status = bundleArchive_initialize(archive); @@ -177,7 +174,7 @@ celix_status_t bundleArchive_recreate(char * archiveRoot, bundle_archive_pt *bun } else { status = linkedList_create(&archive->revisions); if (status == CELIX_SUCCESS) { - archive->archiveRoot = archiveRoot; + archive->archiveRoot = strdup(archiveRoot); archive->archiveRootDir = NULL; archive->id = -1; archive->persistentState = -1; @@ -565,7 +562,7 @@ static celix_status_t bundleArchive_createRevisionFromLocation(bundle_archive_pt bundle_revision_pt revision = NULL; sprintf(root, "%s/version%ld.%ld", archive->archiveRoot, refreshCount, revNr); - status = bundleRevision_create(logger, root, location, revNr, inputFile, &revision); + status = bundleRevision_create(root, location, revNr, inputFile, &revision); if (status == CELIX_SUCCESS) { *bundle_revision = revision; diff --git a/framework/private/src/bundle_cache.c b/framework/private/src/bundle_cache.c index 0f1da80cc..6eaf5d090 100644 --- a/framework/private/src/bundle_cache.c +++ b/framework/private/src/bundle_cache.c @@ -37,7 +37,7 @@ static celix_status_t bundleCache_deleteTree(bundle_cache_pt cache, char * directory); -celix_status_t bundleCache_create(properties_pt configurationMap, framework_logger_pt logger, bundle_cache_pt *bundle_cache) { +celix_status_t bundleCache_create(properties_pt configurationMap, bundle_cache_pt *bundle_cache) { celix_status_t status; bundle_cache_pt cache; @@ -52,17 +52,15 @@ celix_status_t bundleCache_create(properties_pt configurationMap, framework_logg cacheDir = ".cache"; } cache->cacheDir = cacheDir; - cache->logger = logger; *bundle_cache = cache; status = CELIX_SUCCESS; } else { status = CELIX_ILLEGAL_ARGUMENT; } - - framework_logIfError(cache->logger, status, NULL, "Failed to create bundle cache"); } + framework_logIfError(logger, status, NULL, "Failed to create bundle cache"); return status; } @@ -123,7 +121,7 @@ celix_status_t bundleCache_getArchives(bundle_cache_pt cache, array_list_pt *arc status = CELIX_FILE_IO_EXCEPTION; } - framework_logIfError(cache->logger, status, NULL, "Failed to get bundle archives"); + framework_logIfError(logger, status, NULL, "Failed to get bundle archives"); return status; } @@ -134,10 +132,10 @@ celix_status_t bundleCache_createArchive(bundle_cache_pt cache, long id, char * if (cache && location) { snprintf(archiveRoot, sizeof(archiveRoot), "%s/bundle%ld", cache->cacheDir, id); - status = bundleArchive_create(cache->logger, strdup(archiveRoot), id, location, inputFile, bundle_archive); + status = bundleArchive_create(archiveRoot, id, location, inputFile, bundle_archive); } - framework_logIfError(cache->logger, status, NULL, "Failed to create archive"); + framework_logIfError(logger, status, NULL, "Failed to create archive"); return status; } diff --git a/framework/private/src/bundle_context.c b/framework/private/src/bundle_context.c index 8a5279048..35d27ce27 100644 --- a/framework/private/src/bundle_context.c +++ b/framework/private/src/bundle_context.c @@ -45,7 +45,6 @@ celix_status_t bundleContext_create(framework_pt framework, framework_logger_pt } else { context->framework = framework; context->bundle = bundle; - context->logger = logger; *bundle_context = context; } diff --git a/framework/private/src/bundle_revision.c b/framework/private/src/bundle_revision.c index c91976cea..6c538f9c8 100644 --- a/framework/private/src/bundle_revision.c +++ b/framework/private/src/bundle_revision.c @@ -34,7 +34,7 @@ #include "archive.h" #include "celix_log.h" -celix_status_t bundleRevision_create(framework_logger_pt loggera, char *root, char *location, long revisionNr, char *inputFile, bundle_revision_pt *bundle_revision) { +celix_status_t bundleRevision_create(char *root, char *location, long revisionNr, char *inputFile, bundle_revision_pt *bundle_revision) { celix_status_t status = CELIX_SUCCESS; bundle_revision_pt revision = NULL; @@ -61,7 +61,6 @@ celix_status_t bundleRevision_create(framework_logger_pt loggera, char *root, ch revision->revisionNr = revisionNr; revision->root = strdup(root); revision->location = strdup(location); - revision->logger = loggera; *bundle_revision = revision; diff --git a/framework/private/src/celix_errorcodes.c b/framework/private/src/celix_errorcodes.c index ac24c1027..ec25cffd7 100644 --- a/framework/private/src/celix_errorcodes.c +++ b/framework/private/src/celix_errorcodes.c @@ -48,7 +48,7 @@ static char *celix_error_string(celix_status_t statcode) { case CELIX_SERVICE_EXCEPTION: return "Service exception"; } - return "Unkown code"; + return "Unknown code"; } char *celix_strerror(celix_status_t errorcode, char *buffer, size_t bufferSize) { diff --git a/framework/private/src/framework.c b/framework/private/src/framework.c index 5ca35a532..47aabb374 100644 --- a/framework/private/src/framework.c +++ b/framework/private/src/framework.c @@ -234,7 +234,7 @@ celix_status_t framework_create(framework_pt *framework, properties_pt config) { (*framework)->logger = logger; - status = CELIX_DO_IF(status, bundle_create(&(*framework)->bundle, (*framework)->logger)); + status = CELIX_DO_IF(status, bundle_create(&(*framework)->bundle)); status = CELIX_DO_IF(status, arrayList_create(&(*framework)->globalLockWaitersList)); status = CELIX_DO_IF(status, bundle_setFramework((*framework)->bundle, (*framework))); if (status == CELIX_SUCCESS) { @@ -372,7 +372,7 @@ celix_status_t fw_init(framework_pt framework) { if (status == CELIX_SUCCESS) { if ((state == OSGI_FRAMEWORK_BUNDLE_INSTALLED) || (state == OSGI_FRAMEWORK_BUNDLE_RESOLVED)) { bundle_state_e state; - status = CELIX_DO_IF(status, bundleCache_create(framework->configurationMap, framework->logger, &framework->cache)); + status = CELIX_DO_IF(status, bundleCache_create(framework->configurationMap,&framework->cache)); status = CELIX_DO_IF(status, bundle_getState(framework->bundle, &state)); if (status == CELIX_SUCCESS) { if (state == OSGI_FRAMEWORK_BUNDLE_INSTALLED) { diff --git a/framework/private/src/module.c b/framework/private/src/module.c index 15d5c0e49..17fea5cbf 100644 --- a/framework/private/src/module.c +++ b/framework/private/src/module.c @@ -258,6 +258,19 @@ void module_removeDependentImporter(module_pt module, module_pt importer) { arrayList_removeElement(module->dependentImporters, importer); } +//---------------------------------------------------- +//TODO add implementation (functions not implemented but already exported) +array_list_pt module_getDependentRequirers(module_pt module) { + return NULL; +} + +void module_addDependentRequirer(module_pt module, module_pt requirer) { +} + +void module_removeDependentRequirer(module_pt module, module_pt requirer) { +} +//---------------------------------------------------- + array_list_pt module_getDependents(module_pt module) { array_list_pt dependents = NULL; arrayList_create(&dependents); diff --git a/framework/private/src/service_tracker.c b/framework/private/src/service_tracker.c index 1221e0c39..b81b4d04b 100644 --- a/framework/private/src/service_tracker.c +++ b/framework/private/src/service_tracker.c @@ -200,7 +200,7 @@ void *serviceTracker_getServiceByReference(service_tracker_pt tracker, service_r tracked_pt tracked; unsigned int i; for (i = 0; i < arrayList_size(tracker->tracked); i++) { - bool equals; + bool equals = false; tracked = (tracked_pt) arrayList_get(tracker->tracked, i); serviceReference_equals(reference, tracked->reference, &equals); if (equals) { @@ -232,7 +232,7 @@ static celix_status_t serviceTracker_track(service_tracker_pt tracker, service_r int found = -1; unsigned int i; for (i = 0; i < arrayList_size(tracker->tracked); i++) { - bool equals; + bool equals = false; tracked = (tracked_pt) arrayList_get(tracker->tracked, i); serviceReference_equals(reference, tracked->reference, &equals); if (equals) { diff --git a/framework/private/src/version_range.c b/framework/private/src/version_range.c index 6f4b598aa..cc53691f7 100644 --- a/framework/private/src/version_range.c +++ b/framework/private/src/version_range.c @@ -135,7 +135,7 @@ celix_status_t versionRange_parse(char * rangeStr, version_range_pt *range) { celix_status_t status; if (strchr(rangeStr, ',') != NULL) { int vlowL = strcspn(rangeStr+1, ","); - char * vlow = (char *) malloc(sizeof(*vlow * (vlowL + 1))); + char * vlow = (char *) malloc(sizeof(char) * (vlowL + 1)); if (!vlow) { status = CELIX_ENOMEM; } else { @@ -144,7 +144,7 @@ celix_status_t versionRange_parse(char * rangeStr, version_range_pt *range) { vlow = strncpy(vlow, rangeStr+1, vlowL); vlow[vlowL] = '\0'; vhighL = strlen(rangeStr+1) - vlowL - 2; - vhigh = (char *) malloc(sizeof(*vhigh * (vhighL+1))); + vhigh = (char *) malloc(sizeof(char) * (vhighL+1)); if (!vhigh) { status = CELIX_ENOMEM; } else { @@ -169,7 +169,10 @@ celix_status_t versionRange_parse(char * rangeStr, version_range_pt *range) { ); } } + free(vhigh); } + free(vlow); + } } else { version_pt version = NULL; diff --git a/framework/private/test/attribute_test.cpp b/framework/private/test/attribute_test.cpp index 5847c0246..c378b3a78 100644 --- a/framework/private/test/attribute_test.cpp +++ b/framework/private/test/attribute_test.cpp @@ -25,6 +25,7 @@ */ #include #include +#include #include "CppUTest/TestHarness.h" #include "CppUTest/TestHarness_c.h" @@ -35,17 +36,32 @@ extern "C" { #include "attribute_private.h" #include "celix_log.h" -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x42; } 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; +} + TEST_GROUP(attribute) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } void teardown() { @@ -55,13 +71,22 @@ TEST_GROUP(attribute) { }; TEST(attribute, create) { - char key[] = "key"; - char value[] = "value"; + char * key = (char*) my_strdup("key"); + char * value = (char*) my_strdup("value"); attribute_pt attribute = NULL; celix_status_t status = attribute_create(key, value, &attribute); STRCMP_EQUAL(key, attribute->key); STRCMP_EQUAL(value, attribute->value); + LONGS_EQUAL(CELIX_SUCCESS, status); + + mock().expectOneCall("framework_logCode") + .withParameter("code", CELIX_ILLEGAL_ARGUMENT); + + status = attribute_create(NULL, NULL, NULL); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + + attribute_destroy(attribute); } TEST(attribute, getKey) { @@ -75,6 +100,8 @@ TEST(attribute, getKey) { char *actual = NULL; celix_status_t status = attribute_getKey(attribute, &actual); STRCMP_EQUAL(key, actual); + + free(attribute); } TEST(attribute, getValue) { @@ -88,4 +115,6 @@ TEST(attribute, getValue) { char *actual = NULL; celix_status_t status = attribute_getValue(attribute, &actual); STRCMP_EQUAL(value, actual); + + free(attribute); } diff --git a/framework/private/test/bundle_archive_test.cpp b/framework/private/test/bundle_archive_test.cpp index e8f5f60f9..f5baa2d87 100644 --- a/framework/private/test/bundle_archive_test.cpp +++ b/framework/private/test/bundle_archive_test.cpp @@ -25,6 +25,10 @@ */ #include #include +#include +#include +#include +#include #include "CppUTest/TestHarness.h" #include "CppUTest/TestHarness_c.h" @@ -33,18 +37,100 @@ extern "C" { #include "bundle_archive.h" - -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x42; } 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; +} + +static int remove_directory_recursive(const char *path) { + DIR *d = opendir(path); + size_t path_len = strlen(path); + int r = -1; + + if (d) { + struct dirent *p; + + r = 0; + + while (!r && (p = readdir(d))) { + int r2 = -1; + char *buf; + size_t len; + + /* Skip the names "." and ".." as we don't want to recurse on them. */ + if (!strcmp(p->d_name, ".") || !strcmp(p->d_name, "..")) { + continue; + } + + len = path_len + strlen(p->d_name) + 2; + buf = (char*) malloc(len); + + if (buf) { + struct stat statbuf; + snprintf(buf, len, "%s/%s", path, p->d_name); + + if (!stat(buf, &statbuf)) { + if (S_ISDIR(statbuf.st_mode)) { + r2 = remove_directory_recursive(buf); + } else { + r2 = unlink(buf); + } + } + + free(buf); + } + r = r2; + } + closedir(d); + } + if (!r) { + r = rmdir(path); + } + return r; +} + +//----------------------TESTGROUP DEFINES---------------------- + TEST_GROUP(bundle_archive) { + bundle_archive_pt bundle_archive; + char * bundle_path; //uses the default build shell bundle + char * alternate_bundle_path;//alternative bundle, if shell bundle not found + char cache_path[512]; //a local cache folder + void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; + char cwd[512]; + bundle_archive = NULL; + bundle_path = (char*) "../shell/shell.zip"; //uses the default build shell bundle + alternate_bundle_path = (char*) "../log_service/log_service.zip"; //alternative bundle, if shell bundle not found + snprintf(cache_path, sizeof(cache_path), "%s/.cache", getcwd(cwd, sizeof(cwd))); //a local cache folder + struct stat file_stat; + + if (stat(bundle_path, &file_stat) < 0) { + if (stat(alternate_bundle_path, &file_stat) < 0) { + FAIL("failed to find needed test bundle"); + } else { + bundle_path = alternate_bundle_path; + } + } } void teardown() { @@ -53,6 +139,238 @@ TEST_GROUP(bundle_archive) { } }; +//----------------------TEST DEFINES---------------------- +//WARNING: if one test fails, it does not clean up properly, +//causing most if not all of the subsequent tests to also fail + +TEST(bundle_archive, create) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + + bundle_archive = (bundle_archive_pt) 0x42; + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundleArchive_create(cache_path, 5, bundle_path, NULL, &bundle_archive)); + + bundle_archive = NULL; + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, 5, bundle_path, NULL, &bundle_archive)); + CHECK(bundle_archive != NULL); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); +} + +TEST(bundle_archive, createSystemBundleArchive) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + + bundle_archive = (bundle_archive_pt) 0x42; + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundleArchive_createSystemBundleArchive(&bundle_archive )); + + bundle_archive = NULL; + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_createSystemBundleArchive(&bundle_archive)); + CHECK(bundle_archive != NULL); + + //LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); +} + +TEST(bundle_archive, recreate) { + char * get_root; + char * get_location; + bundle_archive_pt recr_archive = NULL; + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, 5, bundle_path, NULL, &bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_recreate(cache_path, &recr_archive)); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getArchiveRoot(recr_archive, &get_root)); + STRCMP_EQUAL(cache_path, get_root); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getLocation(recr_archive, &get_location)); + STRCMP_EQUAL(bundle_path, get_location); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(recr_archive)); +} + +TEST(bundle_archive, getId) { + long get_id; + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, -42, bundle_path, NULL, &bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getId(bundle_archive, &get_id)); + LONGS_EQUAL(-42, get_id); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); + bundle_archive = NULL; + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, 666, bundle_path, NULL, &bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getId(bundle_archive, &get_id)); + LONGS_EQUAL(666, get_id); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); +} + +TEST(bundle_archive, getLocation) { + char * get_loc; + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, 1, bundle_path, NULL, &bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getLocation(bundle_archive, &get_loc)); + STRCMP_EQUAL(bundle_path, get_loc); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); +} +TEST(bundle_archive, getArchiveRoot) { + char * get_root; + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, 1, bundle_path, NULL, &bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getArchiveRoot(bundle_archive, &get_root)); + STRCMP_EQUAL(cache_path, get_root); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); +} + +TEST(bundle_archive, getCurrentRevisionNumber) { + long get_rev_num; + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, 1, bundle_path, NULL, &bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getCurrentRevisionNumber(bundle_archive, &get_rev_num)); + LONGS_EQUAL(0, get_rev_num); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_revise(bundle_archive, bundle_path, NULL)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getCurrentRevisionNumber(bundle_archive, + &get_rev_num)); + LONGS_EQUAL(1, get_rev_num); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_revise(bundle_archive, bundle_path, NULL)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getCurrentRevisionNumber(bundle_archive, &get_rev_num)); + LONGS_EQUAL(2, get_rev_num); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); +} + +TEST(bundle_archive, getCurrentRevision) { + long get_rev_num; + bundle_revision_pt get_rev; + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, 1, bundle_path, NULL, &bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getCurrentRevision(bundle_archive, &get_rev)); + bundleRevision_getNumber(get_rev, &get_rev_num); + LONGS_EQUAL(0, get_rev_num); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_revise(bundle_archive, bundle_path, NULL)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getCurrentRevision(bundle_archive, &get_rev)); + bundleRevision_getNumber(get_rev, &get_rev_num); + LONGS_EQUAL(1, get_rev_num); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); +} + +TEST(bundle_archive, getRevision) { + long get_rev_num; + bundle_revision_pt get_rev; + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, 1, bundle_path, NULL, &bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_revise(bundle_archive, bundle_path, NULL)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_revise(bundle_archive, bundle_path, NULL)); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getRevision(bundle_archive, 0, &get_rev)); + bundleRevision_getNumber(get_rev, &get_rev_num); + LONGS_EQUAL(0, get_rev_num); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getRevision(bundle_archive, 2, &get_rev)); + bundleRevision_getNumber(get_rev, &get_rev_num); + LONGS_EQUAL(2, get_rev_num); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getRevision(bundle_archive, 1, &get_rev)); + bundleRevision_getNumber(get_rev, &get_rev_num); + LONGS_EQUAL(1, get_rev_num); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); +} + +TEST(bundle_archive, set_getPersistentState) { + bundle_state_e get; + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, 1, bundle_path, NULL, &bundle_archive)); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_setPersistentState(bundle_archive, OSGI_FRAMEWORK_BUNDLE_UNKNOWN)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getPersistentState(bundle_archive, &get)); + LONGS_EQUAL(OSGI_FRAMEWORK_BUNDLE_INSTALLED, get); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_setPersistentState(bundle_archive, OSGI_FRAMEWORK_BUNDLE_ACTIVE)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getPersistentState(bundle_archive, &get)); + LONGS_EQUAL(OSGI_FRAMEWORK_BUNDLE_ACTIVE, get); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_setPersistentState(bundle_archive, OSGI_FRAMEWORK_BUNDLE_STARTING)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getPersistentState(bundle_archive, &get)); + LONGS_EQUAL(OSGI_FRAMEWORK_BUNDLE_STARTING, get); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_setPersistentState(bundle_archive, OSGI_FRAMEWORK_BUNDLE_UNINSTALLED)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getPersistentState(bundle_archive, &get)); + LONGS_EQUAL(OSGI_FRAMEWORK_BUNDLE_UNINSTALLED, get); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); +} + +TEST(bundle_archive, set_getRefreshCount) { + long get_refresh_num; + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, 1, bundle_path, NULL, &bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getRefreshCount(bundle_archive, &get_refresh_num)); + LONGS_EQUAL(0, get_refresh_num); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_setRefreshCount(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getRefreshCount(bundle_archive, &get_refresh_num)); + LONGS_EQUAL(0, get_refresh_num); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); +} + +TEST(bundle_archive, get_setLastModified) { + time_t set_time; + time_t get_time; + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, 1, bundle_path, NULL, &bundle_archive)); + + time(&set_time); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_setLastModified(bundle_archive, set_time)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getLastModified(bundle_archive, &get_time)); + CHECK(set_time == get_time); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); +} + +//CANT seem to find a way to test this static function +/*TEST(bundle_archive, readLastModified) { + mock().expectOneCall("framework_logCode"); + + time_t set_time; + time_t get_time; + bundle_archive_pt recr_archive = NULL; + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_create(cache_path, 1, bundle_path, NULL, &bundle_archive)); + + time(&set_time); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_setLastModified(bundle_archive, set_time)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_recreate(cache_path, &recr_archive)); + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_getLastModified(recr_archive, &get_time)); + LONGS_EQUAL(set_time, get_time); + + LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_closeAndDelete(bundle_archive)); + //LONGS_EQUAL(CELIX_SUCCESS, bundleArchive_destroy(bundle_archive)); +}*/ + +TEST(bundle_archive, rollbackRevise) { + bool get; + bundleArchive_rollbackRevise(NULL, &get); + + LONGS_EQUAL(true, get); + +} diff --git a/framework/private/test/bundle_cache_test.cpp b/framework/private/test/bundle_cache_test.cpp index 9043727b5..71174fe90 100644 --- a/framework/private/test/bundle_cache_test.cpp +++ b/framework/private/test/bundle_cache_test.cpp @@ -26,6 +26,7 @@ #include #include #include +#include #include #include "CppUTest/TestHarness.h" @@ -37,17 +38,32 @@ extern "C" { #include "bundle_cache_private.h" #include "celix_log.h" -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x42; } 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; +} + TEST_GROUP(bundle_cache) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } void teardown() { @@ -65,23 +81,23 @@ TEST(bundle_cache, create) { .andReturnValue((char *) NULL); bundle_cache_pt cache = NULL; - celix_status_t status = bundleCache_create(configuration, logger, &cache); - LONGS_EQUAL(CELIX_SUCCESS, status); + LONGS_EQUAL(CELIX_SUCCESS, bundleCache_create(configuration, &cache)); + + LONGS_EQUAL(CELIX_SUCCESS, bundleCache_destroy(&cache)); } TEST(bundle_cache, deleteTree) { bundle_cache_pt cache = (bundle_cache_pt) malloc(sizeof(*cache)); char cacheDir[] = "bundle_cache_test_directory"; - char cacheFile[] = "bundle_cache_test_directory/temp"; + char cacheDir2[] = "bundle_cache_test_directory/testdir"; + char cacheFile[] = "bundle_cache_test_directory/tempXXXXXX"; cache->cacheDir = cacheDir; mkdir(cacheDir, S_IRWXU); + mkdir(cacheDir2, S_IRWXU); mktemp(cacheFile); - celix_status_t status = bundleCache_delete(cache); - - LONGS_EQUAL(CELIX_SUCCESS, status); - + LONGS_EQUAL(CELIX_SUCCESS, bundleCache_delete(cache)); } TEST(bundle_cache, getArchive) { @@ -102,9 +118,8 @@ TEST(bundle_cache, getArchive) { .andReturnValue(CELIX_SUCCESS); array_list_pt archives = NULL; - celix_status_t status = bundleCache_getArchives(cache, &archives); + LONGS_EQUAL(CELIX_SUCCESS, bundleCache_getArchives(cache, &archives)); - LONGS_EQUAL(CELIX_SUCCESS, status); CHECK(archives); LONGS_EQUAL(1, arrayList_size(archives)); POINTERS_EQUAL(archive, arrayList_get(archives, 0)); @@ -112,6 +127,9 @@ TEST(bundle_cache, getArchive) { rmdir(bundle0); rmdir(bundle1); rmdir(cacheDir); + + LONGS_EQUAL(CELIX_SUCCESS, bundleCache_getArchives(cache, &archives)); + rmdir(cacheDir); } TEST(bundle_cache, createArchive) { @@ -124,7 +142,6 @@ TEST(bundle_cache, createArchive) { char location[] = "test.zip"; bundle_archive_pt archive = (bundle_archive_pt) 0x10; mock().expectOneCall("bundleArchive_create") - .withParameter("logger", (void *) NULL) .withParameter("archiveRoot", archiveRoot) .withParameter("id", id) .withParameter("location", location) diff --git a/framework/private/test/bundle_context_test.cpp b/framework/private/test/bundle_context_test.cpp index db2792df0..fcd6dfa5b 100644 --- a/framework/private/test/bundle_context_test.cpp +++ b/framework/private/test/bundle_context_test.cpp @@ -35,7 +35,7 @@ extern "C" { #include "bundle_context_private.h" #include "celix_log.h" -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x42; } int main(int argc, char** argv) { @@ -44,8 +44,6 @@ int main(int argc, char** argv) { TEST_GROUP(bundle_context) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } void teardown() { @@ -55,17 +53,21 @@ TEST_GROUP(bundle_context) { }; TEST(bundle_context, create) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + 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(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) + + bundleContext_create(NULL, logger, NULL, &context); } TEST(bundle_context, destroy) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -80,41 +82,43 @@ 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; - context->framework = framework; - context->bundle = bundle; - - celix_status_t status; - bundle_pt actualBundle = NULL; + mock().expectNCalls(2, "framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + + 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); + LONGS_EQUAL(CELIX_SUCCESS, status); + POINTERS_EQUAL(framework, actualFramework); - actualBundle = NULL; - status = bundleContext_getBundle(NULL, &actualBundle); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + actualBundle = NULL; + status = bundleContext_getBundle(NULL, &actualBundle); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); - actualFramework = NULL; - status = bundleContext_getFramework(NULL, &actualFramework); - 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; - context->framework = framework; - context->bundle = bundle; - - 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) @@ -129,6 +133,8 @@ TEST(bundle_context, installBundle) { } TEST(bundle_context, installBundle2) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -156,6 +162,8 @@ TEST(bundle_context, installBundle2) { } TEST(bundle_context, registerService) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -187,6 +195,8 @@ TEST(bundle_context, registerService) { } TEST(bundle_context, registerServiceFactory) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -218,6 +228,8 @@ TEST(bundle_context, registerServiceFactory) { } TEST(bundle_context, getServiceReferences) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -247,6 +259,8 @@ TEST(bundle_context, getServiceReferences) { } TEST(bundle_context, getServiceReference) { + mock().expectNCalls(3, "framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -268,16 +282,38 @@ TEST(bundle_context, getServiceReference) { .andReturnValue(CELIX_SUCCESS); service_reference_pt actualReference = NULL; - celix_status_t status = bundleContext_getServiceReference(context, serviceName, &actualReference); - LONGS_EQUAL(CELIX_SUCCESS, status); + LONGS_EQUAL(CELIX_SUCCESS, bundleContext_getServiceReference(context, serviceName, &actualReference)); POINTERS_EQUAL(reference, actualReference); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundleContext_getServiceReference(NULL, serviceName, &actualReference)); actualReference = NULL; - status = bundleContext_getServiceReference(context, NULL, &actualReference); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundleContext_getServiceReference(context, NULL, &actualReference)); +} + +TEST(bundle_context, ungetServiceReference) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + + 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; + service_reference_pt reference = (service_reference_pt) 0x30; + + mock().expectOneCall("framework_ungetServiceReference") + .withParameter("framework", framework) + .withParameter("bundle", bundle) + .withParameter("reference", reference); + + service_reference_pt actualReference = NULL; + LONGS_EQUAL(CELIX_SUCCESS, bundleContext_ungetServiceReference(context, reference)); + + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundleContext_ungetServiceReference(context, NULL)); } TEST(bundle_context, getService) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -306,6 +342,8 @@ TEST(bundle_context, getService) { } TEST(bundle_context, ungetService) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -334,6 +372,8 @@ TEST(bundle_context, ungetService) { } TEST(bundle_context, getBundles) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -357,6 +397,8 @@ TEST(bundle_context, getBundles) { } TEST(bundle_context, getBundleById) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -382,6 +424,8 @@ TEST(bundle_context, getBundleById) { } TEST(bundle_context, addServiceListener) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -407,6 +451,8 @@ TEST(bundle_context, addServiceListener) { } TEST(bundle_context, removeServiceListener) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -430,6 +476,8 @@ TEST(bundle_context, removeServiceListener) { } TEST(bundle_context, addBundleListener) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -453,6 +501,8 @@ TEST(bundle_context, addBundleListener) { } TEST(bundle_context, removeBundleListener) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; @@ -475,7 +525,49 @@ TEST(bundle_context, removeBundleListener) { LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); } +TEST(bundle_context, addFrameworkListener){ + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + + 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; + framework_listener_pt listener = (framework_listener_pt) 0x30; + + mock().expectOneCall("fw_addframeworkListener") + .withParameter("framework", framework) + .withParameter("bundle", bundle) + .withParameter("listener", listener); + + LONGS_EQUAL(CELIX_SUCCESS, bundleContext_addFrameworkListener(context, listener)); + + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundleContext_addFrameworkListener(context, NULL)); +} + +TEST(bundle_context, removeFrameworkListener){ + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + + 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; + framework_listener_pt listener = (framework_listener_pt) 0x30; + + mock().expectOneCall("fw_removeframeworkListener") + .withParameter("framework", framework) + .withParameter("bundle", bundle) + .withParameter("listener", listener); + + LONGS_EQUAL(CELIX_SUCCESS, bundleContext_removeFrameworkListener(context, listener)); + + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundleContext_removeFrameworkListener(context, NULL)); +} + TEST(bundle_context, getProperty) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_context_pt context = (bundle_context_pt) malloc(sizeof(*context)); framework_pt framework = (framework_pt) 0x10; bundle_pt bundle = (bundle_pt) 0x20; diff --git a/framework/private/test/bundle_revision_test.cpp b/framework/private/test/bundle_revision_test.cpp index a71b8df1c..c9fb5676a 100644 --- a/framework/private/test/bundle_revision_test.cpp +++ b/framework/private/test/bundle_revision_test.cpp @@ -35,7 +35,7 @@ extern "C" { #include "bundle_revision_private.h" #include "celix_log.h" -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x10; } int main(int argc, char** argv) { @@ -44,8 +44,6 @@ int main(int argc, char** argv) { TEST_GROUP(bundle_revision) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } void teardown() { @@ -71,11 +69,13 @@ TEST(bundle_revision, create) { .andReturnValue(CELIX_SUCCESS); bundle_revision_pt revision = NULL; - celix_status_t status = bundleRevision_create(logger, root, location, revisionNr, inputFile, &revision); - LONGS_EQUAL(CELIX_SUCCESS, status); + LONGS_EQUAL(CELIX_SUCCESS, bundleRevision_create(root, location, revisionNr, inputFile, &revision)); LONGS_EQUAL(revisionNr, revision->revisionNr); STRCMP_EQUAL(root, revision->root); STRCMP_EQUAL(location, revision->location); + + mock().expectOneCall("manifest_destroy"); + LONGS_EQUAL(CELIX_SUCCESS, bundleRevision_destroy(revision)); } TEST(bundle_revision, createWithInput) { @@ -96,55 +96,62 @@ TEST(bundle_revision, createWithInput) { .andReturnValue(CELIX_SUCCESS); bundle_revision_pt revision = NULL; - celix_status_t status = bundleRevision_create(logger, root, location, revisionNr, inputFile, &revision); - LONGS_EQUAL(CELIX_SUCCESS, status); + LONGS_EQUAL(CELIX_SUCCESS, bundleRevision_create(root, location, revisionNr, inputFile, &revision)); LONGS_EQUAL(revisionNr, revision->revisionNr); STRCMP_EQUAL(root, revision->root); STRCMP_EQUAL(location, revision->location); + + mock().expectOneCall("manifest_destroy"); + LONGS_EQUAL(CELIX_SUCCESS, bundleRevision_destroy(revision)); } TEST(bundle_revision, getters) { + mock().expectNCalls(5, "framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + bundle_revision_pt revision = (bundle_revision_pt) malloc(sizeof(*revision)); char root[] = "bundle_revision_test"; char location[] = "test_bundle.zip"; long revisionNr = 1l; - manifest_pt expected = (manifest_pt) 0x42; + manifest_pt expectedManifest = (manifest_pt) 0x42; + array_list_pt handles = NULL; + arrayList_create(&handles); revision->root = root; revision->location = location; revision->revisionNr = revisionNr; - revision->manifest = expected; + revision->manifest = expectedManifest; + revision->libraryHandles = handles; char *actualRoot = NULL; char *actualLocation = NULL; long actualRevisionNr = 0l; manifest_pt actualManifest = NULL; - celix_status_t status = CELIX_SUCCESS; + array_list_pt actualHandles = NULL; - status = bundleRevision_getNumber(revision, &actualRevisionNr); - LONGS_EQUAL(CELIX_SUCCESS, status); + LONGS_EQUAL(CELIX_SUCCESS, bundleRevision_getNumber(revision, &actualRevisionNr)); LONGS_EQUAL(revisionNr, actualRevisionNr); - status = bundleRevision_getLocation(revision, &actualLocation); - LONGS_EQUAL(CELIX_SUCCESS, status); + LONGS_EQUAL(CELIX_SUCCESS, bundleRevision_getLocation(revision, &actualLocation)); STRCMP_EQUAL(location, actualLocation); - status = bundleRevision_getRoot(revision, &actualRoot); - LONGS_EQUAL(CELIX_SUCCESS, status); + LONGS_EQUAL(CELIX_SUCCESS, bundleRevision_getRoot(revision, &actualRoot)); STRCMP_EQUAL(root, actualRoot); - status = bundleRevision_getManifest(revision, &actualManifest); - LONGS_EQUAL(CELIX_SUCCESS, status); - POINTERS_EQUAL(expected, actualManifest); + LONGS_EQUAL(CELIX_SUCCESS, bundleRevision_getManifest(revision, &actualManifest)); + POINTERS_EQUAL(expectedManifest, actualManifest); + + LONGS_EQUAL(CELIX_SUCCESS, bundleRevision_getHandles(revision, &actualHandles)); + POINTERS_EQUAL(handles, actualHandles); + + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundleRevision_getNumber(NULL, &actualRevisionNr)); + + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundleRevision_getLocation(NULL, &actualLocation)); - status = bundleRevision_getNumber(NULL, &actualRevisionNr); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundleRevision_getRoot(NULL, &actualRoot)); - status = bundleRevision_getLocation(NULL, &actualLocation); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundleRevision_getManifest(NULL, &actualManifest)); - status = bundleRevision_getRoot(NULL, &actualRoot); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundleRevision_getHandles(NULL, &actualHandles)); - status = bundleRevision_getManifest(NULL, &actualManifest); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + arrayList_destroy(handles); + free(revision); } diff --git a/framework/private/test/bundle_test.cpp b/framework/private/test/bundle_test.cpp index 58608ecfd..29fe5e838 100644 --- a/framework/private/test/bundle_test.cpp +++ b/framework/private/test/bundle_test.cpp @@ -30,12 +30,15 @@ #include "CppUTest/TestHarness_c.h" #include "CppUTest/CommandLineTestRunner.h" #include "CppUTestExt/MockSupport.h" +#include "string.h" extern "C" { +#include "bundle_revision_private.h" #include "bundle_private.h" +#include "utils.h" #include "celix_log.h" -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x42; } int main(int argc, char** argv) { @@ -44,35 +47,48 @@ int main(int argc, char** argv) { TEST_GROUP(bundle) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } - void teardown() { + void teardown(void) { mock().checkExpectations(); mock().clear(); } }; +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; +} + + TEST(bundle, create) { bundle_archive_pt archive = (bundle_archive_pt) 0x10; mock().expectOneCall("bundleArchive_createSystemBundleArchive") - .withParameter("logger", logger) - .withOutputParameterReturning("bundle_archive", &archive, sizeof(archive)) - .andReturnValue(CELIX_SUCCESS); + .withOutputParameterReturning("bundle_archive", &archive, sizeof(archive)) + .andReturnValue(CELIX_SUCCESS); module_pt module = (module_pt) 0x20; mock().expectOneCall("module_createFrameworkModule") - .ignoreOtherParameters() - .andReturnValue(module); + .ignoreOtherParameters() + .andReturnValue(module); mock().expectOneCall("resolver_addModule") - .withParameter("module", module); - mock().expectOneCall("resolver_addModule") - .withParameter("module", module); + .withParameter("module", module); bundle_pt actual = NULL; - celix_status_t status = bundle_create(&actual, logger); + celix_status_t status = bundle_create(&actual); LONGS_EQUAL(CELIX_SUCCESS, status); POINTERS_EQUAL(NULL, actual->context); POINTERS_EQUAL(NULL, actual->activator); @@ -81,10 +97,13 @@ TEST(bundle, create) { POINTERS_EQUAL(archive, actual->archive); CHECK(actual->modules); POINTERS_EQUAL(NULL, actual->manifest); -// CHECK(actual->lock) + // CHECK(actual->lock) LONGS_EQUAL(0, actual->lockCount); POINTERS_EQUAL(NULL, actual->lockThread.thread); POINTERS_EQUAL(NULL, actual->framework); + + mock().expectOneCall("module_destroy"); + bundle_destroy(actual); } TEST(bundle, createFromArchive) { @@ -94,52 +113,48 @@ TEST(bundle, createFromArchive) { manifest_pt manifest = (manifest_pt) 0x30; mock().expectOneCall("bundleArchive_getCurrentRevision") - .withParameter("archive", archive) - .withOutputParameterReturning("revision", &revision, sizeof(revision)) - .andReturnValue(CELIX_SUCCESS); + .withParameter("archive", archive) + .withOutputParameterReturning("revision", &revision, sizeof(revision)) + .andReturnValue(CELIX_SUCCESS); mock().expectOneCall("bundleRevision_getManifest") - .withParameter("revision", revision) - .withOutputParameterReturning("manifest", &manifest, sizeof(manifest)) - .andReturnValue(CELIX_SUCCESS); + .withParameter("revision", revision) + .withOutputParameterReturning("manifest", &manifest, sizeof(manifest)) + .andReturnValue(CELIX_SUCCESS); - // CPPUTest has no build in support for longs, which breaks this test. long id = 1; mock().expectOneCall("bundleArchive_getId") - .withParameter("archive", archive) - .withOutputParameterReturning("id", &id, sizeof(id)) - .andReturnValue(CELIX_SUCCESS); + .withParameter("archive", archive) + .withOutputParameterReturning("id", &id, sizeof(id)) + .andReturnValue(CELIX_SUCCESS); module_pt module = (module_pt) 0x40; mock().expectOneCall("module_create") - .withParameter("headerMap", manifest) -// .withParameter("moduleId", "1.0") -// .withParameter("bundle", (void *) 0x40) - .ignoreOtherParameters() - .andReturnValue(module); + .withParameter("headerMap", manifest) + // .withParameter("moduleId", "1.0") + // .withParameter("bundle", (void *) 0x40) + .ignoreOtherParameters() + .andReturnValue(module); version_pt version = (version_pt) 0x50; mock().expectOneCall("module_getVersion") - .withParameter("module", module) - .andReturnValue(version); + .withParameter("module", module) + .andReturnValue(version); char symbolicName[] = "name"; mock().expectOneCall("module_getSymbolicName") - .withParameter("module", module) - .withOutputParameterReturning("symbolicName", &symbolicName, sizeof(symbolicName)) - .andReturnValue(CELIX_SUCCESS); + .withParameter("module", module) + .withOutputParameterReturning("symbolicName", &symbolicName, sizeof(symbolicName)) + .andReturnValue(CELIX_SUCCESS); array_list_pt bundles = NULL; arrayList_create(&bundles); mock().expectOneCall("framework_getBundles") - .withParameter("framework", framework) - .andReturnValue(bundles); - - mock().expectOneCall("resolver_addModule") - .withParameter("module", module); + .withParameter("framework", framework) + .andReturnValue(bundles); mock().expectOneCall("resolver_addModule") - .withParameter("module", module); + .withParameter("module", module); bundle_pt actual = NULL; celix_status_t status = bundle_createFromArchive(&actual, framework, archive); @@ -151,10 +166,16 @@ TEST(bundle, createFromArchive) { POINTERS_EQUAL(archive, actual->archive); CHECK(actual->modules); POINTERS_EQUAL(NULL, actual->manifest); -// CHECK(actual->lock) + // CHECK(actual->lock) LONGS_EQUAL(0, actual->lockCount); POINTERS_EQUAL(NULL, actual->lockThread.thread); POINTERS_EQUAL(framework, actual->framework); + + arrayList_destroy(actual->modules); + free(actual); + + + mock().clear(); } TEST(bundle, getArchive) { @@ -163,13 +184,19 @@ TEST(bundle, getArchive) { bundle->archive = archive; bundle_archive_pt actual = NULL; - celix_status_t status = bundle_getArchive(bundle, &actual); - LONGS_EQUAL(CELIX_SUCCESS, status); + LONGS_EQUAL(CELIX_SUCCESS, bundle_getArchive(bundle, &actual)); POINTERS_EQUAL(archive, actual); + mock().expectOneCall("framework_logCode") + .withParameter("code", CELIX_ILLEGAL_ARGUMENT); + actual = NULL; - status = bundle_getArchive(NULL, &actual); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundle_getArchive(NULL, &actual)); + + free(bundle); + + + mock().clear(); } TEST(bundle, getCurrentModule) { @@ -192,6 +219,9 @@ TEST(bundle, getCurrentModule) { actual = NULL; status = bundle_getCurrentModule(NULL, &actual); LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + + arrayList_destroy(bundle->modules); + free(bundle); } TEST(bundle, getModules) { @@ -201,6 +231,8 @@ TEST(bundle, getModules) { array_list_pt actual = bundle_getModules(bundle); POINTERS_EQUAL(modules, actual); + + free(bundle); } TEST(bundle, getHandle) { @@ -210,6 +242,8 @@ TEST(bundle, getHandle) { void *actual = bundle_getHandle(bundle); POINTERS_EQUAL(expected, actual); + + free(bundle); } TEST(bundle, setHandle) { @@ -218,6 +252,8 @@ TEST(bundle, setHandle) { bundle_setHandle(bundle, expected); POINTERS_EQUAL(expected, bundle->handle); + + free(bundle); } TEST(bundle, getActivator) { @@ -227,6 +263,8 @@ TEST(bundle, getActivator) { activator_pt actual = bundle_getActivator(bundle); POINTERS_EQUAL(expected, actual); + + free(bundle); } TEST(bundle, setActivator) { @@ -236,6 +274,8 @@ TEST(bundle, setActivator) { celix_status_t status = bundle_setActivator(bundle, expected); LONGS_EQUAL(CELIX_SUCCESS, status); POINTERS_EQUAL(expected, bundle->activator); + + free(bundle); } TEST(bundle, getContext) { @@ -247,6 +287,8 @@ TEST(bundle, getContext) { celix_status_t status = bundle_getContext(bundle, &actual); LONGS_EQUAL(CELIX_SUCCESS, status); POINTERS_EQUAL(expected, actual); + + free(bundle); } TEST(bundle, setContext) { @@ -256,6 +298,8 @@ TEST(bundle, setContext) { celix_status_t status = bundle_setContext(bundle, expected); LONGS_EQUAL(CELIX_SUCCESS, status); POINTERS_EQUAL(expected, bundle->context); + + free(bundle); } TEST(bundle, getEntry) { @@ -266,16 +310,18 @@ TEST(bundle, getEntry) { char name[] = "name"; char *expected = (char *) 0x20; mock().expectOneCall("framework_getBundleEntry") - .withParameter("framework", framework) - .withParameter("bundle", bundle) - .withParameter("name", name) - .withOutputParameterReturning("entry", &expected, sizeof(expected)) - .andReturnValue(CELIX_SUCCESS); + .withParameter("framework", framework) + .withParameter("bundle", bundle) + .withParameter("name", name) + .withOutputParameterReturning("entry", &expected, sizeof(expected)) + .andReturnValue(CELIX_SUCCESS); char *actual = NULL; celix_status_t status = bundle_getEntry(bundle, name, &actual); LONGS_EQUAL(CELIX_SUCCESS, status); POINTERS_EQUAL(expected, actual); + + free(bundle); } TEST(bundle, getState) { @@ -283,9 +329,14 @@ TEST(bundle, getState) { bundle->state = OSGI_FRAMEWORK_BUNDLE_ACTIVE; bundle_state_e actual = OSGI_FRAMEWORK_BUNDLE_UNKNOWN; - celix_status_t status = bundle_getState(bundle, &actual); - LONGS_EQUAL(CELIX_SUCCESS, status); + LONGS_EQUAL(CELIX_SUCCESS, bundle_getState(bundle, &actual)); POINTERS_EQUAL(OSGI_FRAMEWORK_BUNDLE_ACTIVE, actual); + + //get unknown bundle's state + LONGS_EQUAL(CELIX_BUNDLE_EXCEPTION, bundle_getState((bundle_pt)NULL, &actual)); + POINTERS_EQUAL(OSGI_FRAMEWORK_BUNDLE_UNKNOWN, actual); + + free(bundle); } TEST(bundle, setState) { @@ -295,8 +346,115 @@ TEST(bundle, setState) { celix_status_t status = bundle_setState(bundle, OSGI_FRAMEWORK_BUNDLE_INSTALLED); LONGS_EQUAL(CELIX_SUCCESS, status); POINTERS_EQUAL(OSGI_FRAMEWORK_BUNDLE_INSTALLED, bundle->state); + + free(bundle); } +/*//declared here, since its non-static, but not actually exported by bundle.h or bundle_private.h +extern celix_status_t bundle_createModule(bundle_pt bundle, module_pt *module); + +TEST(bundle, createModule){ + bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); + + module_pt module = (module_pt) 0x01; + module_pt module2 = (module_pt) 0x02; + module_pt module3 = (module_pt) 0x03; + arrayList_create(&bundle->modules); + arrayList_add(bundle->modules, module); + arrayList_add(bundle->modules, module2); + arrayList_add(bundle->modules, module3); + + framework_pt framework = (framework_pt) 0x04; + bundle->framework = framework; + + bundle_archive_pt archive = (bundle_archive_pt) 0x05; + bundle->archive = archive; + + module_pt module_new = (module_pt) 0x06; + bundle_revision_pt revision = (bundle_revision_pt) 0x07; + version_pt version = (version_pt) 0x08; + manifest_pt manifest = (manifest_pt) 0x09; + + long id = 666; + char * symbolicName = my_strdup("name"); + + bundle_pt bundle2 = (bundle_pt) malloc(sizeof(*bundle)); + module_pt module4 = (module_pt) 0x0A; + arrayList_create(&bundle2->modules); + arrayList_add(bundle2->modules, module4); + bundle2->framework = framework; + + bundle_archive_pt archive2 = (bundle_archive_pt) 0x0B; + bundle2->archive = archive2; + + version_pt version2 = (version_pt) 0x0C; + long id2 = 667; + + array_list_pt bundles; + arrayList_create(&bundles); + arrayList_add(bundles, bundle2); + + //expected calls from bundle_createModule + mock().expectOneCall("bundleArchive_getCurrentRevision") + .withParameter("archive", archive) + .withOutputParameterReturning("revision", &revision, sizeof(revision)); + + mock().expectOneCall("bundleRevision_getManifest") + .withParameter("revision", revision) + .withOutputParameterReturning("manifest", &manifest, sizeof(manifest)); + + mock().expectOneCall("bundleArchive_getId") + .withParameter("archive", archive) + .withOutputParameterReturning("id", &id, sizeof(id)); + + mock().expectOneCall("module_create") + .withParameter("headerMap", manifest) + .withParameter("moduleId", "666.0") + .withParameter("bundle", bundle) + .andReturnValue(module_new); + + mock().expectOneCall("module_getVersion") + .withParameter("module", module_new) + .andReturnValue(version); + + mock().expectOneCall("module_getSymbolicName") + .withParameter("module", module_new) + .withOutputParameterReturning("symbolicName", &symbolicName, sizeof(char*)); + + mock().expectOneCall("framework_getBundles") + .withParameter("framework", framework) + .andReturnValue(bundles); + + mock().expectOneCall("bundleArchive_getId") + .withParameter("archive", archive2) + .withOutputParameterReturning("id", &id2, sizeof(id2)); + + //returning same symbolic name for module_new as for module4 + mock().expectOneCall("module_getSymbolicName") + .withParameter("module", module4) + .withOutputParameterReturning("symbolicName", &symbolicName, sizeof(char*)); + + //returning different version for module_new as for module4 + mock().expectOneCall("module_getVersion") + .withParameter("module", module4) + .andReturnValue(version2); + + int result = 1; //1 means not equal + mock().expectOneCall("version_compareTo") + .withParameter("version", version) + .withParameter("compare", version2) + .withOutputParameterReturning("result", &result,sizeof(result)); + + LONGS_EQUAL(CELIX_SUCCESS, bundle_createModule(bundle, &module_new)); + + arrayList_destroy(bundle->modules); + arrayList_destroy(bundle2->modules); + + free(bundle); + free(bundle2); + free(symbolicName); +}*/ + TEST(bundle, start) { bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); framework_pt framework = (framework_pt) 0x10; @@ -307,19 +465,30 @@ TEST(bundle, start) { int options = 42; long id = 1; - mock().expectOneCall("bundleArchive_getId") - .withParameter("archive", archive) - .withOutputParameterReturning("id", &id, sizeof(id)) - .andReturnValue(CELIX_SUCCESS); + mock().expectNCalls(2, "bundleArchive_getId") + .withParameter("archive", archive) + .withOutputParameterReturning("id", &id, sizeof(id)) + .andReturnValue(CELIX_SUCCESS); mock().expectOneCall("fw_startBundle") - .withParameter("framework", framework) - .withParameter("bundle", bundle) - .withParameter("options", options) - .andReturnValue(CELIX_SUCCESS); + .withParameter("framework", framework) + .withParameter("bundle", bundle) + .withParameter("options", options) + .andReturnValue(CELIX_SUCCESS); celix_status_t status = bundle_startWithOptions(bundle, options); LONGS_EQUAL(CELIX_SUCCESS, status); + + mock().expectOneCall("fw_startBundle") + .withParameter("framework", framework) + .withParameter("bundle", bundle) + .withParameter("options", 0) + .andReturnValue(CELIX_SUCCESS); + + status = bundle_start(bundle); + LONGS_EQUAL(CELIX_SUCCESS, status); + + free(bundle); } TEST(bundle, update) { @@ -331,19 +500,21 @@ TEST(bundle, update) { long id = 1; mock().expectOneCall("bundleArchive_getId") - .withParameter("archive", archive) - .withOutputParameterReturning("id", &id, sizeof(id)) - .andReturnValue(CELIX_SUCCESS); + .withParameter("archive", archive) + .withOutputParameterReturning("id", &id, sizeof(id)) + .andReturnValue(CELIX_SUCCESS); char input[] = "input"; mock().expectOneCall("framework_updateBundle") - .withParameter("framework", framework) - .withParameter("bundle", bundle) - .withParameter("inputFile", input) - .andReturnValue(CELIX_SUCCESS); + .withParameter("framework", framework) + .withParameter("bundle", bundle) + .withParameter("inputFile", input) + .andReturnValue(CELIX_SUCCESS); celix_status_t status = bundle_update(bundle, input); LONGS_EQUAL(CELIX_SUCCESS, status); + + free(bundle); } TEST(bundle, stop) { @@ -354,43 +525,67 @@ TEST(bundle, stop) { bundle->archive = archive; long id = 1; - mock().expectOneCall("bundleArchive_getId") - .withParameter("archive", archive) - .withOutputParameterReturning("id", &id, sizeof(id)) - .andReturnValue(CELIX_SUCCESS); + mock().expectNCalls(2, "bundleArchive_getId") + .withParameter("archive", archive) + .withOutputParameterReturning("id", &id, sizeof(id)) + .andReturnValue(CELIX_SUCCESS); int options = 1; mock().expectOneCall("fw_stopBundle") - .withParameter("framework", framework) - .withParameter("bundle", bundle) - .withParameter("record", 1) - .andReturnValue(CELIX_SUCCESS); + .withParameter("framework", framework) + .withParameter("bundle", bundle) + .withParameter("record", 1) + .andReturnValue(CELIX_SUCCESS); celix_status_t status = bundle_stopWithOptions(bundle, options); LONGS_EQUAL(CELIX_SUCCESS, status); + + mock().expectOneCall("fw_stopBundle") + .withParameter("framework", framework) + .withParameter("bundle", bundle) + .withParameter("record", 0) + .andReturnValue(CELIX_SUCCESS); + + status = bundle_stop(bundle); + LONGS_EQUAL(CELIX_SUCCESS, status); + + free(bundle); } -//TEST(bundle, uninstall) { -// bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); -// framework_pt framework = (framework_pt) 0x10; -// bundle_archive_pt archive = (bundle_archive_pt) 0x20; -// bundle->framework = framework; -// bundle->archive = archive; -// -// long id = 0; -// mock().expectOneCall("bundleArchive_getId") -// .withParameter("archive", archive) -// .withOutputParameterReturning("id", &id, sizeof(id)) -// .andReturnValue(CELIX_SUCCESS); -// -// mock().expectOneCall("fw_uninstallBundle") -// .withParameter("framework", framework) -// .withParameter("bundle", bundle) -// .andReturnValue(CELIX_SUCCESS); -// -// celix_status_t status = bundle_uninstall(bundle); -// LONGS_EQUAL(CELIX_SUCCESS, status); -//} +TEST(bundle, uninstall) { + bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); + framework_pt framework = (framework_pt) 0x10; + bundle_archive_pt archive = (bundle_archive_pt) 0x20; + bundle->framework = framework; + bundle->archive = archive; + + long id = 666; + mock().expectOneCall("bundleArchive_getId") + .withParameter("archive", archive) + .withOutputParameterReturning("id", &id, sizeof(id)) + .andReturnValue(CELIX_SUCCESS); + + mock().expectOneCall("fw_uninstallBundle") + .withParameter("framework", framework) + .withParameter("bundle", bundle) + .andReturnValue(CELIX_SUCCESS); + + LONGS_EQUAL(CELIX_SUCCESS, bundle_uninstall(bundle)); + + //attempt to uninstall framework bundle + id = 0; + mock().expectOneCall("bundleArchive_getId") + .withParameter("archive", archive) + .withOutputParameterReturning("id", &id, sizeof(id)) + .andReturnValue(CELIX_SUCCESS); + + mock().expectOneCall("framework_logCode") + .withParameter("code", CELIX_BUNDLE_EXCEPTION); + + LONGS_EQUAL(CELIX_BUNDLE_EXCEPTION, bundle_uninstall(bundle)); + + free(bundle); +} TEST(bundle, setPersistentStateInactive) { bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); @@ -399,17 +594,18 @@ TEST(bundle, setPersistentStateInactive) { long id = 1; mock().expectOneCall("bundleArchive_getId") - .withParameter("archive", archive) - .withOutputParameterReturning("id", &id, sizeof(id)) - .andReturnValue(CELIX_SUCCESS); + .withParameter("archive", archive) + .withOutputParameterReturning("id", &id, sizeof(id)) + .andReturnValue(CELIX_SUCCESS); mock().expectOneCall("bundleArchive_setPersistentState") - .withParameter("archive", archive) - .withParameter("state", OSGI_FRAMEWORK_BUNDLE_INSTALLED) - .andReturnValue(CELIX_SUCCESS); + .withParameter("archive", archive) + .withParameter("state", OSGI_FRAMEWORK_BUNDLE_INSTALLED) + .andReturnValue(CELIX_SUCCESS); - celix_status_t status = bundle_setPersistentStateInactive(bundle); - LONGS_EQUAL(CELIX_SUCCESS, status); + LONGS_EQUAL(CELIX_SUCCESS, bundle_setPersistentStateInactive(bundle)); + + free(bundle); } TEST(bundle, setPersistentStateUninstalled) { @@ -419,84 +615,430 @@ TEST(bundle, setPersistentStateUninstalled) { long id = 1; mock().expectOneCall("bundleArchive_getId") - .withParameter("archive", archive) - .withOutputParameterReturning("id", &id, sizeof(id)) - .andReturnValue(CELIX_SUCCESS); + .withParameter("archive", archive) + .withOutputParameterReturning("id", &id, sizeof(id)) + .andReturnValue(CELIX_SUCCESS); mock().expectOneCall("bundleArchive_setPersistentState") - .withParameter("archive", archive) - .withParameter("state", OSGI_FRAMEWORK_BUNDLE_UNINSTALLED) - .andReturnValue(CELIX_SUCCESS); + .withParameter("archive", archive) + .withParameter("state", OSGI_FRAMEWORK_BUNDLE_UNINSTALLED) + .andReturnValue(CELIX_SUCCESS); celix_status_t status = bundle_setPersistentStateUninstalled(bundle); LONGS_EQUAL(CELIX_SUCCESS, status); + + free(bundle); } TEST(bundle, revise) { bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); - + arrayList_create(&bundle->modules); + bundle_archive_pt actual_archive = (bundle_archive_pt) 0x02; + bundle_revision_pt actual_revision = (bundle_revision_pt) malloc(sizeof(actual_revision)); + manifest_pt actual_manifest = (manifest_pt) malloc(sizeof(*actual_manifest)); + int actual_id = 666; + const char * actual_module_id = "666.0"; + bundle->archive = actual_archive; + char * symbolic_name = NULL; char location[] = "location"; char inputFile[] = "inputFile"; -// celix_status_t status = bundle_revise(bundle, location, inputFile); + + mock().expectNCalls(2, "bundleArchive_revise"); + + mock().expectNCalls(2, "bundleArchive_getCurrentRevision") + .withParameter("archive", bundle->archive) + .withOutputParameterReturning("revision", &actual_revision, sizeof(actual_revision)); + + mock().expectNCalls(2, "bundleRevision_getManifest") + .withParameter("revision", actual_revision) + .withOutputParameterReturning("manifest", &actual_manifest, sizeof(actual_manifest)); + + mock().expectNCalls(2, "bundleArchive_getId") + .withParameter("archive", actual_archive) + .withOutputParameterReturning("id", &actual_id, sizeof(actual_id)); + + mock().expectOneCall("module_create") + .withParameter("headerMap", actual_manifest) + .withParameter("moduleId", actual_module_id) + .withParameter("bundle", bundle); + + //module create returns NULL during test + mock().expectOneCall("resolver_addModule") + .withParameter("module", (void*)NULL); + + LONGS_EQUAL(CELIX_SUCCESS, bundle_revise(bundle, location, inputFile)); + + mock().expectOneCall("module_create") + .withParameter("headerMap", actual_manifest) + .withParameter("moduleId", actual_module_id) + .withParameter("bundle", bundle) + .andReturnValue((void*)0x01); + + mock().expectOneCall("module_getVersion") + .withParameter("module", (void*)0x01); + + mock().expectOneCall("module_getSymbolicName") + .withParameter("module", (void*)0x01) + .withOutputParameterReturning("symbolicName", &symbolic_name,sizeof(symbolic_name)) + .andReturnValue(CELIX_ILLEGAL_ARGUMENT); + + mock().expectOneCall("bundleArchive_rollbackRevise"); + + mock().expectOneCall("framework_logCode") + .withParameter("code", CELIX_ILLEGAL_ARGUMENT); + + mock().expectOneCall("framework_logCode") + .withParameter("code", CELIX_BUNDLE_EXCEPTION); + + LONGS_EQUAL(CELIX_BUNDLE_EXCEPTION, bundle_revise(bundle, location, inputFile)); + + arrayList_destroy(bundle->modules); + free(bundle); + free(actual_revision); + free(actual_manifest); } TEST(bundle, isLockable) { bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); celixThreadMutex_create(&bundle->lock, NULL); + bundle->lockCount = 0; bool lockable = false; celix_status_t status = bundle_isLockable(bundle, &lockable); -// FAIL("Test not fully implemented"); -} + // FAIL("Test not fully implemented"); -TEST(bundle, getLockingThread) { -// FAIL("Test not fully implemented"); + free(bundle); } -TEST(bundle, lock) { -// FAIL("Test not fully implemented"); -} -TEST(bundle, unlock) { -// FAIL("Test not fully implemented"); +TEST(bundle, lockingThread) { + bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); + celixThreadMutex_create(&bundle->lock, NULL); + celix_thread_t thread; + + bundle->lockCount = 0; + + bool locked = false; + LONGS_EQUAL(CELIX_SUCCESS, bundle_lock(bundle, &locked)); + CHECK(locked); + LONGS_EQUAL(1, bundle->lockCount); + + LONGS_EQUAL(CELIX_SUCCESS, bundle_getLockingThread(bundle, &thread)); + bool equals; + thread_equalsSelf(thread, &equals); + CHECK(equals); + + bool unlocked; + bundle->lockCount = 1; + LONGS_EQUAL(CELIX_SUCCESS, bundle_unlock(bundle, &unlocked)); + CHECK(unlocked); + LONGS_EQUAL(0, bundle->lockCount); + + //try to unlock unlocked lock + LONGS_EQUAL(CELIX_SUCCESS, bundle_unlock(bundle, &unlocked)); + CHECK_FALSE(unlocked); + LONGS_EQUAL(0, bundle->lockCount); + + celixThreadMutex_destroy(&bundle->lock); + free(bundle); } TEST(bundle, close) { -// FAIL("Test not fully implemented"); + bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); + + module_pt module = (module_pt) 0x01; + module_pt module2 = (module_pt) 0x02; + module_pt module3 = (module_pt) 0x03; + arrayList_create(&bundle->modules); + arrayList_add(bundle->modules, module); + arrayList_add(bundle->modules, module2); + arrayList_add(bundle->modules, module3); + + bundle_archive_pt archive = (bundle_archive_pt) 0x05; + bundle->archive = archive; + + mock().expectOneCall("resolver_removeModule") + .withParameter("module", module); + + mock().expectOneCall("resolver_removeModule") + .withParameter("module", module2); + + mock().expectOneCall("resolver_removeModule") + .withParameter("module", module3); + + mock().expectNCalls(3, "module_setWires"); + + mock().expectOneCall("bundleArchive_close") + .withParameter("archive", archive); + + LONGS_EQUAL(CELIX_SUCCESS, bundle_close(bundle)); + + arrayList_destroy(bundle->modules); + free(bundle); } TEST(bundle, closeAndDelete) { -// FAIL("Test not fully implemented"); + bundle_archive_pt archive = (bundle_archive_pt) 0x10; + mock().expectOneCall("bundleArchive_createSystemBundleArchive") + .withOutputParameterReturning("bundle_archive", &archive, sizeof(archive)) + .andReturnValue(CELIX_SUCCESS); + + module_pt module = (module_pt) 0x20; + mock().expectOneCall("module_createFrameworkModule") + .ignoreOtherParameters() + .andReturnValue(module); + + mock().expectOneCall("resolver_addModule") + .withParameter("module", module); + + bundle_pt actual = NULL; + celix_status_t status = bundle_create(&actual); + LONGS_EQUAL(CELIX_SUCCESS, status); + + mock().expectOneCall("resolver_removeModule") + .withParameter("module", module); + + mock().expectOneCall("module_setWires"); + + mock().expectOneCall("bundleArchive_closeAndDelete"); + + status = bundle_closeAndDelete(actual); + LONGS_EQUAL(CELIX_SUCCESS, status); + + arrayList_destroy(actual->modules); + free(actual); } TEST(bundle, closeModules) { -// FAIL("Test not fully implemented"); + bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); + module_pt module = (module_pt) 0x01; + module_pt module2 = (module_pt) 0x02; + module_pt module3 = (module_pt) 0x03; + + arrayList_create(&bundle->modules); + arrayList_add(bundle->modules, module); + arrayList_add(bundle->modules, module2); + arrayList_add(bundle->modules, module3); + + mock().expectOneCall("resolver_removeModule") + .withParameter("module", module); + + mock().expectOneCall("resolver_removeModule") + .withParameter("module", module2); + + mock().expectOneCall("resolver_removeModule") + .withParameter("module", module3); + + mock().expectNCalls(3, "module_setWires"); + + bundle_closeModules(bundle); + + arrayList_destroy(bundle->modules); + free(bundle); } TEST(bundle, refresh) { -// FAIL("Test not fully implemented"); + bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); + + module_pt module = (module_pt) 0x01; + module_pt module2 = (module_pt) 0x02; + module_pt module3 = (module_pt) 0x03; + arrayList_create(&bundle->modules); + arrayList_add(bundle->modules, module); + arrayList_add(bundle->modules, module2); + arrayList_add(bundle->modules, module3); + + framework_pt framework = (framework_pt) 0x04; + bundle->framework = framework; + + bundle_archive_pt archive = (bundle_archive_pt) 0x05; + bundle->archive = archive; + + module_pt module_new = (module_pt) 0x06; + bundle_revision_pt revision = (bundle_revision_pt) 0x07; + version_pt version = (version_pt) 0x08; + manifest_pt manifest = (manifest_pt) 0x09; + + long id = 666; + char * symbolicName = my_strdup("name"); + + bundle_pt bundle2 = (bundle_pt) malloc(sizeof(*bundle)); + module_pt module4 = (module_pt) 0x0A; + arrayList_create(&bundle2->modules); + arrayList_add(bundle2->modules, module4); + bundle2->framework = framework; + + bundle_archive_pt archive2 = (bundle_archive_pt) 0x0B; + bundle2->archive = archive2; + + version_pt version2 = (version_pt) 0x0C; + long id2 = 667; + + array_list_pt bundles; + arrayList_create(&bundles); + arrayList_add(bundles, bundle2); + + //expected calls from bundle_refresh + mock().expectOneCall("resolver_removeModule") + .withParameter("module", module); + + mock().expectOneCall("resolver_removeModule") + .withParameter("module", module2); + + mock().expectOneCall("resolver_removeModule") + .withParameter("module", module3); + + mock().expectNCalls(3, "module_setWires"); + + //expected calls from bundle_createModule + mock().expectOneCall("bundleArchive_getCurrentRevision") + .withParameter("archive", archive) + .withOutputParameterReturning("revision", &revision, sizeof(revision)); + + mock().expectOneCall("bundleRevision_getManifest") + .withParameter("revision", revision) + .withOutputParameterReturning("manifest", &manifest, sizeof(manifest)); + + mock().expectOneCall("bundleArchive_getId") + .withParameter("archive", archive) + .withOutputParameterReturning("id", &id, sizeof(id)); + + mock().expectOneCall("module_create") + .withParameter("headerMap", manifest) + .withParameter("moduleId", "666.0") + .withParameter("bundle", bundle) + .andReturnValue(module_new); + + mock().expectOneCall("module_getVersion") + .withParameter("module", module_new) + .andReturnValue(version); + + mock().expectOneCall("module_getSymbolicName") + .withParameter("module", module_new) + .withOutputParameterReturning("symbolicName", &symbolicName, sizeof(char*)); + + mock().expectOneCall("framework_getBundles") + .withParameter("framework", framework) + .andReturnValue(bundles); + + mock().expectOneCall("bundleArchive_getId") + .withParameter("archive", archive2) + .withOutputParameterReturning("id", &id2, sizeof(id2)); + + //returning same symbolic name for module_new as for module4 + mock().expectOneCall("module_getSymbolicName") + .withParameter("module", module4) + .withOutputParameterReturning("symbolicName", &symbolicName, sizeof(char*)); + + //returning different version for module_new as for module4 + mock().expectOneCall("module_getVersion") + .withParameter("module", module4) + .andReturnValue(version2); + + int result = 1; //1 means not equal + mock().expectOneCall("version_compareTo") + .withParameter("version", version) + .withParameter("compare", version2) + .withOutputParameterReturning("result", &result,sizeof(result)); + + //expected calls from bundle_addModule + mock().expectOneCall("resolver_addModule") + .withParameter("module", module_new); + + LONGS_EQUAL(CELIX_SUCCESS, bundle_refresh(bundle)); + + arrayList_destroy(bundle->modules); + arrayList_destroy(bundle2->modules); + + free(bundle); + free(bundle2); + free(symbolicName); } TEST(bundle, getBundleId) { -// FAIL("Test not fully implemented"); + bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); + bundle_archive_pt actual_archive = (bundle_archive_pt) 0x42; + bundle->archive = actual_archive; + long actual_id = 666; + long get_id = 0; + + mock().expectOneCall("bundleArchive_getId") + .withParameter("archive", actual_archive) + .withOutputParameterReturning("id", &actual_id, sizeof(actual_id)); + + LONGS_EQUAL(CELIX_SUCCESS, bundle_getBundleId(bundle, &get_id)); + LONGS_EQUAL(actual_id, get_id); + + free(bundle); } TEST(bundle, getRegisteredServices) { -// FAIL("Test not fully implemented"); + bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); + framework_pt framework = (framework_pt) 0x10; + bundle->framework = framework; + array_list_pt list = (array_list_pt) 0x20; + array_list_pt get = NULL; + + mock().expectOneCall("fw_getBundleRegisteredServices") + .withParameter("framework", framework) + .withParameter("bundle", bundle) + .withOutputParameterReturning("services", &list, sizeof(list)); + + LONGS_EQUAL(CELIX_SUCCESS, bundle_getRegisteredServices(bundle, &get)); + POINTERS_EQUAL(list, get); + + free(bundle); } TEST(bundle, getServicesInUse) { -// FAIL("Test not fully implemented"); -} + bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); + framework_pt framework = (framework_pt) 0x10; + bundle->framework = framework; + array_list_pt list = (array_list_pt) 0x20; + array_list_pt get = NULL; + + mock().expectOneCall("fw_getBundleServicesInUse") + .withParameter("framework", framework) + .withParameter("bundle", bundle) + .withOutputParameterReturning("services", &list, sizeof(list)); + + LONGS_EQUAL(CELIX_SUCCESS, bundle_getServicesInUse(bundle, &get)); + POINTERS_EQUAL(list, get); -TEST(bundle, getMemoryPool) { -// FAIL("Test not fully implemented"); + free(bundle); } TEST(bundle, setFramework) { -// FAIL("Test not fully implemented"); + framework_pt framework = (framework_pt) 0x666; + bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); + + LONGS_EQUAL(CELIX_SUCCESS, bundle_setFramework(bundle, framework)); + POINTERS_EQUAL(framework, bundle->framework); + + mock().expectOneCall("framework_logCode") + .withParameter("code", CELIX_ILLEGAL_ARGUMENT); + + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundle_setFramework(bundle, NULL)); + + free(bundle); } TEST(bundle, getFramework) { -// FAIL("Test not fully implemented"); + framework_pt get = NULL; + framework_pt actual = (framework_pt) 0x666; + bundle_pt bundle = (bundle_pt) malloc(sizeof(*bundle)); + + bundle->framework = actual; + + LONGS_EQUAL(CELIX_SUCCESS, bundle_getFramework(bundle, &get)); + + free(bundle); + bundle = NULL; + + mock().expectOneCall("framework_logCode") + .withParameter("code", CELIX_ILLEGAL_ARGUMENT); + + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, bundle_getFramework(bundle, &get)); + + free(bundle); } diff --git a/framework/private/test/capability_test.cpp b/framework/private/test/capability_test.cpp index 1874dd926..4d9f2eb9e 100644 --- a/framework/private/test/capability_test.cpp +++ b/framework/private/test/capability_test.cpp @@ -33,10 +33,11 @@ extern "C" { #include "capability_private.h" +#include "utils.h" #include "attribute.h" #include "celix_log.h" -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x42; } int main(int argc, char** argv) { @@ -45,8 +46,6 @@ int main(int argc, char** argv) { TEST_GROUP(capability) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } void teardown() { @@ -57,8 +56,8 @@ TEST_GROUP(capability) { TEST(capability, create) { module_pt module = (module_pt) 0x10; - hash_map_pt directives = hashMap_create(NULL, NULL, NULL, NULL); - hash_map_pt attributes = hashMap_create(NULL, NULL, NULL, NULL); + hash_map_pt directives = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); + hash_map_pt attributes = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); attribute_pt serviceAttribute = (attribute_pt) 0x01; hashMap_put(attributes, (void*) "service", serviceAttribute); @@ -90,6 +89,10 @@ TEST(capability, create) { capability_pt capability = NULL; celix_status_t status = capability_create(module, directives, attributes, &capability); + + mock().expectNCalls(2, "attribute_destroy"); + mock().expectOneCall("version_destroy"); + capability_destroy(capability); } TEST(capability, getServiceName) { @@ -100,6 +103,8 @@ TEST(capability, getServiceName) { char *actual = NULL; capability_getServiceName(capability, &actual); STRCMP_EQUAL(serviceName, actual); + + free(capability); } TEST(capability, getVersion) { @@ -110,6 +115,8 @@ TEST(capability, getVersion) { version_pt actual = NULL; capability_getVersion(capability, &actual); POINTERS_EQUAL(version, actual); + + free(capability); } TEST(capability, getModule) { @@ -120,4 +127,6 @@ TEST(capability, getModule) { module_pt actual = NULL; capability_getModule(capability, &actual); POINTERS_EQUAL(module, actual); + + free(capability); } diff --git a/framework/private/test/celix_errorcodes_test.cpp b/framework/private/test/celix_errorcodes_test.cpp new file mode 100644 index 000000000..99ed360e6 --- /dev/null +++ b/framework/private/test/celix_errorcodes_test.cpp @@ -0,0 +1,87 @@ +/** + *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. + */ +/* + * celix_errorcodes_test.cpp + * + * \date Oct 16, 2015 + * \author Apache Celix Project Team + * \copyright Apache License, Version 2.0 + */ + +#include +#include + +#include "CppUTest/TestHarness.h" +#include "CppUTest/TestHarness_c.h" +#include "CppUTest/CommandLineTestRunner.h" +#include "CppUTestExt/MockSupport.h" + +extern "C" { +#include "celix_errno.h" +} + +int main(int argc, char** argv) { + return CommandLineTestRunner::RunAllTests(argc, argv); +} + +TEST_GROUP(celix_errorcodes) { + void setup(void){ + } + + void teardown(void){ + } +}; + +TEST(celix_errorcodes, test_entire_file){ + char ret_str[100]; + + celix_strerror(CELIX_BUNDLE_EXCEPTION, ret_str, 100); + STRCMP_EQUAL("Bundle exception", ret_str); + + celix_strerror(CELIX_INVALID_BUNDLE_CONTEXT, ret_str, 100); + STRCMP_EQUAL("Invalid bundle context", ret_str); + + celix_strerror(CELIX_ILLEGAL_ARGUMENT, ret_str, 100); + STRCMP_EQUAL("Illegal argument", ret_str); + + celix_strerror(CELIX_INVALID_SYNTAX, ret_str, 100); + STRCMP_EQUAL("Invalid syntax", ret_str); + + celix_strerror(CELIX_FRAMEWORK_SHUTDOWN, ret_str, 100); + STRCMP_EQUAL("Framework shutdown", ret_str); + + celix_strerror(CELIX_ILLEGAL_STATE, ret_str, 100); + STRCMP_EQUAL("Illegal state", ret_str); + + celix_strerror(CELIX_FRAMEWORK_EXCEPTION, ret_str, 100); + STRCMP_EQUAL("Framework exception", ret_str); + + celix_strerror(CELIX_FILE_IO_EXCEPTION, ret_str, 100); + STRCMP_EQUAL("File I/O exception", ret_str); + + celix_strerror(CELIX_SERVICE_EXCEPTION, ret_str, 100); + STRCMP_EQUAL("Service exception", ret_str); + + celix_strerror(CELIX_START_ERROR, ret_str, 100); + STRCMP_EQUAL("Unknown code", ret_str); + + //test non celix error code + STRCMP_EQUAL("Cannot allocate memory", + celix_strerror(ENOMEM, ret_str, 100)); +} diff --git a/framework/private/test/framework_test.cpp b/framework/private/test/framework_test.cpp index e1085f7fc..81dabf56c 100644 --- a/framework/private/test/framework_test.cpp +++ b/framework/private/test/framework_test.cpp @@ -19,7 +19,7 @@ /* * framework_test.cpp * - * \date Feb 11, 2013 + * \date Sep 28, 2015 * \author Apache Celix Project Team * \copyright Apache License, Version 2.0 */ @@ -33,22 +33,79 @@ extern "C" { #include "framework.h" +#include "framework_private.h" } int main(int argc, char** argv) { - return RUN_ALL_TESTS(argc, argv); + return CommandLineTestRunner::RUN_ALL_TESTS(argc, argv); } TEST_GROUP(framework) { + properties_pt properties; + void setup(void) { + properties = properties_create(); } void teardown() { - mock().checkExpectations(); - mock().clear(); + properties_destroy(properties); } }; +TEST(framework, create){ + framework_pt framework = NULL; + + mock().expectOneCall("bundle_create"); + + framework_create(&framework, properties); + + + CHECK(framework != NULL); + POINTERS_EQUAL(&properties, framework->configurationMap); + + mock().checkExpectations(); + mock().clear(); +} + +/*TEST(framework, startFw){ + framework_pt framework = NULL; + + mock().expectOneCall("bundle_create"); + mock().expectOneCall("framework_logCode") + .withParameter("code", CELIX_ILLEGAL_ARGUMENT); + + LONGS_EQUAL(CELIX_SUCCESS,framework_create(&framework, properties)); + + LONGS_EQUAL(CELIX_SUCCESS,fw_init(framework)); + + LONGS_EQUAL(CELIX_SUCCESS,framework_start(framework)); + + framework_stop(framework); + framework_destroy(framework); + +} + +TEST(framework, installBundle){ + framework_pt framework = NULL; + + mock().expectOneCall("bundle_create"); + mock().expectOneCall("framework_logCode") + .withParameter("code", CELIX_ILLEGAL_ARGUMENT); + + LONGS_EQUAL(CELIX_SUCCESS, framework_create(&framework, properties)); + + LONGS_EQUAL(CELIX_SUCCESS,fw_init(framework)); + + LONGS_EQUAL(CELIX_SUCCESS,framework_start(framework)); + + // fw_installBundle(); // Needs a fake bundle.. + + framework_stop(framework); + framework_destroy(framework); + +}*/ + + diff --git a/framework/private/test/manifest_test.cpp b/framework/private/test/manifest_test.cpp index c90cc9079..02422aa1e 100644 --- a/framework/private/test/manifest_test.cpp +++ b/framework/private/test/manifest_test.cpp @@ -56,7 +56,7 @@ TEST_GROUP(manifest) { }; TEST(manifest, createFromFile) { - char manifestFile[] = "../../celix/framework/private/resources-test/manifest.txt"; + char manifestFile[] = "resources-test/manifest.txt"; manifest_pt manifest = NULL; // properties_pt properties = properties_create(); properties_pt properties = (properties_pt) 0x40; @@ -98,7 +98,7 @@ TEST(manifest, createFromFile) { } TEST(manifest, createFromFileWithSections) { - char manifestFile[] = "../../celix/framework/private/resources-test/manifest_sections.txt"; + char manifestFile[] = "resources-test/manifest_sections.txt"; manifest_pt manifest = NULL; // properties_pt properties = properties_create(); properties_pt properties = (properties_pt) 0x40; diff --git a/framework/private/test/module_test.cpp b/framework/private/test/module_test.cpp index 3a1c78078..7936d9603 100644 --- a/framework/private/test/module_test.cpp +++ b/framework/private/test/module_test.cpp @@ -25,6 +25,7 @@ */ #include #include +#include #include "CppUTest/TestHarness.h" #include "CppUTest/TestHarness_c.h" @@ -39,6 +40,23 @@ 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; +} + TEST_GROUP(module) { void setup(void) { } @@ -49,6 +67,270 @@ TEST_GROUP(module) { } }; +TEST(module, create){ + module_pt module = NULL; + manifest_pt actual_manifest = (manifest_pt) 0x01; + bundle_pt actual_bundle = (bundle_pt) 0x02; + version_pt actual_version = (version_pt) 0x03; + linked_list_pt actual_capabilities = NULL; + linked_list_pt actual_requirements= NULL; + char * actual_name = my_strdup("module"); + char * actual_id = my_strdup("42"); + + linkedList_create(&actual_capabilities); + linkedList_create(&actual_requirements); + mock().expectOneCall("manifestParser_create"); + mock().expectOneCall("manifestParser_getSymbolicName") + .withOutputParameterReturning("symbolicName", &actual_name, sizeof(actual_name) ); + mock().expectOneCall("manifestParser_getBundleVersion") + .withOutputParameterReturning("version", &actual_version, sizeof(version_pt) ); + mock().expectOneCall("manifestParser_getCapabilities") + .withOutputParameterReturning("capabilities", &actual_capabilities, sizeof(linked_list_pt) ); + mock().expectOneCall("manifestParser_getCurrentRequirements") + .withOutputParameterReturning("requirements", &actual_requirements, sizeof(linked_list_pt) ); + mock().expectOneCall("manifestParser_destroy"); + + module = module_create(actual_manifest, actual_id, actual_bundle); + CHECK(module != NULL); + + mock().expectOneCall("version_destroy"); + module_destroy(module); + + free(actual_id); +} + +TEST(module, createFrameworkModule){ + module_pt module = NULL; + bundle_pt actual_bundle = (bundle_pt) 0x01; + + mock().expectOneCall("version_createVersion"); + + module = module_createFrameworkModule(actual_bundle); + + CHECK(module != NULL); + + mock().expectOneCall("version_destroy"); + + module_destroy(module); +} + +TEST(module, resolved){ + module_pt module = NULL; + manifest_pt actual_manifest = (manifest_pt) 0x01; + bundle_pt actual_bundle = (bundle_pt) 0x02; + version_pt actual_version = (version_pt) 0x03; + linked_list_pt actual_capabilities = NULL; + linked_list_pt actual_requirements= NULL; + char * actual_name = my_strdup("module"); + char * actual_id = my_strdup("42"); + + linkedList_create(&actual_capabilities); + linkedList_create(&actual_requirements); + mock().expectOneCall("manifestParser_create"); + mock().expectOneCall("manifestParser_getSymbolicName") + .withOutputParameterReturning("symbolicName", &actual_name, sizeof(actual_name) ); + mock().expectOneCall("manifestParser_getBundleVersion") + .withOutputParameterReturning("version", &actual_version, sizeof(version_pt) ); + mock().expectOneCall("manifestParser_getCapabilities") + .withOutputParameterReturning("capabilities", &actual_capabilities, sizeof(linked_list_pt) ); + mock().expectOneCall("manifestParser_getCurrentRequirements") + .withOutputParameterReturning("requirements", &actual_requirements, sizeof(linked_list_pt) ); + mock().expectOneCall("manifestParser_destroy"); + module = module_create(actual_manifest, actual_id, actual_bundle); + + CHECK_FALSE(module_isResolved(module)); + module_setResolved(module); + CHECK(module_isResolved(module)); + + mock().expectOneCall("version_destroy"); + module_destroy(module); + + free(actual_id); +} + +TEST(module, wires){ + manifest_pt manifest = (manifest_pt) 0x01; + bundle_pt bundle = (bundle_pt) 0x02; + version_pt version = (version_pt) 0x03; + wire_pt wire = (wire_pt) 0x04; + wire_pt wire_new = (wire_pt) 0x05; + capability_pt cap = (capability_pt) 0x06; + requirement_pt req = (requirement_pt) 0x07; + char * service_name = my_strdup("foobar"); + + //test var declarations + array_list_pt get_list = NULL; + + //module related declares + module_pt module = NULL; + char * name = my_strdup("module_1"); + char * id = my_strdup("42"); + linked_list_pt capabilities = NULL; + linked_list_pt requirements = NULL; + linked_list_pt wires = NULL; + linked_list_pt wires_new = NULL; + + //module2 related declares + module_pt module2 = NULL; + char * name2 = my_strdup("module_2"); + char * id2 = my_strdup("43"); + linked_list_pt capabilities2 = NULL; + linked_list_pt requirements2 = NULL; + linked_list_pt wires2 = NULL; + + //create module + linkedList_create(&capabilities); + linkedList_create(&requirements); + linkedList_create(&wires); + linkedList_addElement(capabilities, cap); + linkedList_addElement(requirements, req); + linkedList_addElement(wires, wire); + + mock().expectOneCall("manifestParser_create"); + mock().expectOneCall("manifestParser_getSymbolicName") + .withOutputParameterReturning("symbolicName", &name, sizeof(name)); + mock().expectOneCall("manifestParser_getBundleVersion") + .withOutputParameterReturning("version", &version, sizeof(version)); + mock().expectOneCall("manifestParser_getCapabilities") + .withOutputParameterReturning("capabilities", &capabilities, sizeof(capabilities)); + mock().expectOneCall("manifestParser_getCurrentRequirements") + .withOutputParameterReturning("requirements", &requirements, sizeof(requirements)); + mock().expectOneCall("manifestParser_destroy"); + module = module_create(manifest, id, bundle); + + //create module2 + linkedList_create(&capabilities2); + linkedList_create(&requirements2); + linkedList_create(&wires_new); + linkedList_addElement(wires_new, wire_new); + mock().expectOneCall("manifestParser_create"); + mock().expectOneCall("manifestParser_getSymbolicName") + .withOutputParameterReturning("symbolicName", &name2, sizeof(name2)); + mock().expectOneCall("manifestParser_getBundleVersion") + .withOutputParameterReturning("version", &version, sizeof(version)); + mock().expectOneCall("manifestParser_getCapabilities") + .withOutputParameterReturning("capabilities", &capabilities2, sizeof(capabilities2)); + mock().expectOneCall("manifestParser_getCurrentRequirements") + .withOutputParameterReturning("requirements", &requirements2, sizeof(requirements2)); + mock().expectOneCall("manifestParser_destroy"); + module2 = module_create(manifest, id, bundle); + //test empty wires handling + POINTERS_EQUAL(NULL, module_getWire(module, service_name)); + //expect the adding of wire + mock().expectOneCall("wire_getExporter") + .withParameter("wire", wire) + .withOutputParameterReturning("exporter", &module2, sizeof(module2)); + //set modules->wires = actual_wires, and register module dependent at module2 + module_setWires(module, wires); + + //expect getting of wire vars + mock().expectOneCall("wire_getCapability") + .withParameter("wire", wire) + .withOutputParameterReturning("capability", &cap, sizeof(cap)); + + mock().expectOneCall("capability_getServiceName") + .withParameter("capability", cap) + .withOutputParameterReturning("serviceName", &service_name, sizeof(service_name)); + + //test for added wire + POINTERS_EQUAL(wire, module_getWire(module, service_name)); + + //test added dependent module (method 1 of 2) + get_list = module_getDependents(module2); + CHECK(arrayList_contains(get_list, module)); + + //expect the re-adding of wire + //expect the adding of wire + mock().expectOneCall("wire_getExporter") + .withParameter("wire", wire) + .withOutputParameterReturning("exporter", &module2, sizeof(module2)); + + mock().expectOneCall("wire_destroy"); + + mock().expectOneCall("wire_getExporter") + .withParameter("wire", wire_new) + .withOutputParameterReturning("exporter", &module2, sizeof(module2)); + + //test clearing of the wires before adding back wire + module_setWires(module, wires_new); + + //test added dependent module (method 2 of 2) + CHECK(arrayList_contains(module_getDependentImporters(module2),module)); + + //check getwires + POINTERS_EQUAL(wires_new, module_getWires(module)); + + //TODO make tests for possible implementations of the following functions + module_addDependentRequirer(module, module2); + module_getDependentRequirers(module); + module_removeDependentRequirer(module, module2); + + //clean up + mock().expectNCalls(2, "version_destroy"); + mock().expectOneCall("wire_destroy"); + mock().expectOneCall("capability_destroy"); + mock().expectOneCall("requirement_destroy"); + module_destroy(module); + module_destroy(module2); + + arrayList_destroy(get_list); + free(id); + free(id2); + free(service_name); +} + +TEST(module, get){ + module_pt module = NULL; + manifest_pt actual_manifest = (manifest_pt) 0x01; + bundle_pt actual_bundle = (bundle_pt) 0x02; + version_pt actual_version = (version_pt) 0x03; + linked_list_pt actual_capabilities = NULL; + linked_list_pt actual_requirements= NULL; + char * actual_name = my_strdup("module"); + char * actual_id = my_strdup("42"); + char * get = NULL; + + linkedList_create(&actual_capabilities); + linkedList_create(&actual_requirements); + + mock().expectOneCall("manifestParser_create"); + mock().expectOneCall("manifestParser_getSymbolicName") + .withOutputParameterReturning("symbolicName", &actual_name, sizeof(actual_name) ); + + mock().expectOneCall("manifestParser_getBundleVersion") + .withOutputParameterReturning("version", &actual_version, sizeof(version_pt) ); + + mock().expectOneCall("manifestParser_getCapabilities") + .withOutputParameterReturning("capabilities", &actual_capabilities, sizeof(linked_list_pt) ); + + mock().expectOneCall("manifestParser_getCurrentRequirements") + .withOutputParameterReturning("requirements", &actual_requirements, sizeof(linked_list_pt) ); + + mock().expectOneCall("manifestParser_destroy"); + + + module = module_create(actual_manifest, actual_id, actual_bundle); + + CHECK(module != NULL); + + POINTERS_EQUAL(actual_bundle, module_getBundle(module)); + POINTERS_EQUAL(actual_requirements, module_getRequirements(module)); + POINTERS_EQUAL(actual_capabilities, module_getCapabilities(module)); + POINTERS_EQUAL(actual_version, module_getVersion(module)); + + STRCMP_EQUAL(actual_id, module_getId(module)); + + LONGS_EQUAL(CELIX_SUCCESS, module_getSymbolicName(module, &get)); + STRCMP_EQUAL(actual_name, get); + + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, module_getSymbolicName(NULL, &get)); + + mock().expectOneCall("version_destroy"); + + module_destroy(module); + + free(actual_id); +} diff --git a/framework/private/test/properties_test.cpp b/framework/private/test/properties_test.cpp index c06393e1b..2be5092b3 100644 --- a/framework/private/test/properties_test.cpp +++ b/framework/private/test/properties_test.cpp @@ -40,6 +40,7 @@ int main(int argc, char** argv) { } TEST_GROUP(properties) { + properties_pt properties; void setup(void) { } @@ -51,25 +52,29 @@ TEST_GROUP(properties) { }; TEST(properties, create) { - properties_pt properties = properties_create(); + properties = properties_create(); CHECK(properties); + + properties_destroy(properties); } TEST(properties, load) { - char propertiesFile[] = "../../celix/framework/private/resources-test/properties.txt"; - properties_pt properties = properties_load(propertiesFile); - LONGS_EQUAL(2, hashMap_size(properties)); + char propertiesFile[] = "resources-test/properties.txt"; + properties = properties_load(propertiesFile); + LONGS_EQUAL(3, hashMap_size(properties)); char keyA[] = "a"; char *valueA = properties_get(properties, keyA); STRCMP_EQUAL("b", valueA); char keyB[] = "b"; STRCMP_EQUAL("c", properties_get(properties, keyB)); + + properties_destroy(properties); } TEST(properties, store) { - char propertiesFile[] = "properties_out.txt"; - properties_pt properties = properties_create(); + char propertiesFile[] = "resources-test/properties_out.txt"; + properties = properties_create(); char keyA[] = "x"; char keyB[] = "y"; char valueA[] = "1"; @@ -77,10 +82,12 @@ TEST(properties, store) { properties_set(properties, keyA, valueA); properties_set(properties, keyB, valueB); properties_store(properties, propertiesFile, NULL); + + properties_destroy(properties); } TEST(properties, getSet) { - properties_pt properties = properties_create(); + properties = properties_create(); char keyA[] = "x"; char keyB[] = "y"; char keyC[] = "z"; @@ -93,5 +100,7 @@ TEST(properties, getSet) { STRCMP_EQUAL(valueA, properties_get(properties, keyA)); STRCMP_EQUAL(valueB, properties_get(properties, keyB)); STRCMP_EQUAL(valueC, properties_getWithDefault(properties, keyC, valueC)); + + properties_destroy(properties); } diff --git a/framework/private/test/requirement_test.cpp b/framework/private/test/requirement_test.cpp index fc08a84f7..b45f8449f 100644 --- a/framework/private/test/requirement_test.cpp +++ b/framework/private/test/requirement_test.cpp @@ -36,8 +36,9 @@ extern "C" { #include "attribute.h" #include "version_range.h" #include "celix_log.h" +#include "utils.h" -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x42; } int main(int argc, char** argv) { @@ -46,8 +47,6 @@ int main(int argc, char** argv) { TEST_GROUP(requirement) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } void teardown() { @@ -58,7 +57,7 @@ TEST_GROUP(requirement) { TEST(requirement, create) { hash_map_pt directives = hashMap_create(NULL, NULL, NULL, NULL); - hash_map_pt attributes = hashMap_create(NULL, NULL, NULL, NULL); + hash_map_pt attributes = hashMap_create(utils_stringHash, NULL, utils_stringEquals, NULL); attribute_pt serviceAttribute = (attribute_pt) 0x01; hashMap_put(attributes, (void*) "service", serviceAttribute); @@ -88,6 +87,11 @@ TEST(requirement, create) { requirement_pt requirement = NULL; requirement_create(directives, attributes, &requirement); + + mock().expectNCalls(2, "attribute_destroy"); + mock().expectOneCall("versionRange_destroy"); + + requirement_destroy(requirement); } TEST(requirement, getVersionRange) { @@ -98,6 +102,8 @@ TEST(requirement, getVersionRange) { version_range_pt actual = NULL; requirement_getVersionRange(requirement, &actual); POINTERS_EQUAL(versionRange, actual); + + free(requirement); } TEST(requirement, getTargetName) { @@ -108,6 +114,8 @@ TEST(requirement, getTargetName) { char *actual = NULL; requirement_getTargetName(requirement, &actual); STRCMP_EQUAL(targetName, actual); + + free(requirement); } TEST(requirement, isSatisfied) { @@ -130,4 +138,6 @@ TEST(requirement, isSatisfied) { bool inRange2 = false; requirement_isSatisfied(requirement, capability, &inRange2); CHECK(inRange2); + + free(requirement); } diff --git a/framework/private/test/resolver_test.cpp b/framework/private/test/resolver_test.cpp index bf864b20b..df8e6085e 100644 --- a/framework/private/test/resolver_test.cpp +++ b/framework/private/test/resolver_test.cpp @@ -25,6 +25,7 @@ */ #include #include +#include #include "CppUTest/TestHarness.h" #include "CppUTest/TestHarness_c.h" @@ -35,25 +36,154 @@ extern "C" { #include "resolver.h" #include "celix_log.h" -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x42; } 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; +} + TEST_GROUP(resolver) { - void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; + void setup(void){ } - void teardown() { + void teardown(){ mock().checkExpectations(); mock().clear(); } }; +TEST(resolver, resolve){ + module_pt module; + module_pt module2; + manifest_pt actual_manifest = (manifest_pt) 0x01; + bundle_pt actual_bundle = (bundle_pt) 0x02; + version_pt actual_version = (version_pt) 0x03; + linked_list_pt actual_capabilities = NULL; + linked_list_pt actual_requirements= NULL; + char * actual_name = my_strdup("module"); + char * actual_id = my_strdup("42"); + char * actual_service_name = my_strdup("test_service_foo"); + char * actual_service_name2 = my_strdup("test_service_bar"); + requirement_pt req = (requirement_pt) 0x04; + requirement_pt req2= (requirement_pt) 0x05; + capability_pt cap = (capability_pt) 0x06; + capability_pt cap2= (capability_pt) 0x07; + linked_list_pt get; + + //creating module + linkedList_create(&actual_capabilities); + linkedList_create(&actual_requirements); + + linkedList_addElement(actual_requirements, req); + linkedList_addElement(actual_requirements, req2); + linkedList_addElement(actual_capabilities, cap); + linkedList_addElement(actual_capabilities, cap2); + + + mock().expectNCalls(2, "manifestParser_create"); + mock().expectNCalls(2,"manifestParser_getSymbolicName") + .withOutputParameterReturning("symbolicName", &actual_name, sizeof(actual_name) ); + mock().expectNCalls(2, "manifestParser_getBundleVersion") + .withOutputParameterReturning("version", &actual_version, sizeof(version_pt) ); + mock().expectNCalls(2, "manifestParser_getCapabilities") + .withOutputParameterReturning("capabilities", &actual_capabilities, sizeof(linked_list_pt) ); + mock().expectNCalls(2, "manifestParser_getCurrentRequirements") + .withOutputParameterReturning("requirements", &actual_requirements, sizeof(linked_list_pt) ); + mock().expectNCalls(2, "manifestParser_destroy"); + + module = module_create(actual_manifest, actual_id, actual_bundle); + module2 = module_create(actual_manifest, actual_id, actual_bundle); + + mock().expectOneCall("capability_getServiceName") + .withParameter("capability", cap) + .withOutputParameterReturning("serviceName", &actual_service_name, sizeof(actual_service_name)); + + mock().expectOneCall("capability_getServiceName") + .withParameter("capability", cap2) + .withOutputParameterReturning("serviceName", &actual_service_name2, sizeof(actual_service_name2)); + + resolver_addModule(module2); + + mock().expectOneCall("requirement_getTargetName") + .withParameter("requirement", req) + .withOutputParameterReturning("targetName", &actual_service_name, sizeof(actual_service_name)); + + mock().expectOneCall("requirement_getTargetName") + .withParameter("requirement", req2) + .withOutputParameterReturning("targetName", &actual_service_name2, sizeof(actual_service_name2)); + + bool out = true; + mock().expectOneCall("requirement_isSatisfied") + .withParameter("requirement", req) + .withParameter("capability", cap) + .withOutputParameterReturning("inRange", &out, sizeof(out)); + + mock().expectOneCall("requirement_isSatisfied") + .withParameter("requirement", req2) + .withParameter("capability", cap2) + .withOutputParameterReturning("inRange", &out, sizeof(out)); + + mock().expectOneCall("capability_getModule") + .withParameter("capability", cap) + .withOutputParameterReturning("module", &module, sizeof(module)); + + /*mock().expectOneCall("capability_getModule") + .withParameter("capability", cap) + .withOutputParameterReturning("module", &module, sizeof(module));*/ + + get = resolver_resolve(module); + //CHECK(linkedList_contains(get, wire)); + + //test resolved module checking + + POINTERS_EQUAL(NULL, resolver_resolve(module)); + + mock().expectOneCall("version_destroy"); + module_destroy(module); + module_destroy(module2); + + + free(actual_id); + free(actual_name); +} +/* +TEST(resolver, moduleResolved){ + module_pt module; + resolver_moduleResolved(module); +} + +TEST(resolver, addModule){ + module_pt module; + resolver_addModule(module); +} + +TEST(resolver, removeModule){ + module_pt module ; + + module = module_create(actual_manifest, actual_id, actual_bundle); + + resolver_removeModule(module); +} +*/ + diff --git a/framework/private/test/service_reference_test.cpp b/framework/private/test/service_reference_test.cpp index 5d8213a5c..1c383ec0c 100644 --- a/framework/private/test/service_reference_test.cpp +++ b/framework/private/test/service_reference_test.cpp @@ -34,6 +34,7 @@ extern "C" { #include "service_reference_private.h" #include "celix_log.h" +#include "utils.h" framework_logger_pt logger; } diff --git a/framework/private/test/service_registration_test.cpp b/framework/private/test/service_registration_test.cpp index cec1374cf..cec62ef36 100644 --- a/framework/private/test/service_registration_test.cpp +++ b/framework/private/test/service_registration_test.cpp @@ -270,7 +270,9 @@ TEST(service_registration, getRegistryIllegalArgument) { TEST(service_registration, getServiceReferences) { service_registration_pt registration = (service_registration_pt) malloc(sizeof(*registration)); array_list_pt references = NULL; - service_registry_pt registry = (service_registry_pt) 0x10; + //service_registry_pt registry = (service_registry_pt) 0x10; + //service_registry_pt registry = (service_registry_pt) 0x0; + service_registry_pt registry = registration->registry; bundle_pt bundle = (bundle_pt) 0x20; mock().expectOneCall("serviceRegistry_getServiceReferencesForRegistration") diff --git a/framework/private/test/service_registry_test.cpp b/framework/private/test/service_registry_test.cpp index 10a649dbc..0175f45f4 100644 --- a/framework/private/test/service_registry_test.cpp +++ b/framework/private/test/service_registry_test.cpp @@ -30,12 +30,21 @@ #include "CppUTest/TestHarness_c.h" #include "CppUTest/CommandLineTestRunner.h" #include "CppUTestExt/MockSupport.h" +#include "CppUTestExt/MockSupport_c.h" extern "C" { #include "service_registry_private.h" #include "celix_log.h" -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x42; + +void serviceRegistryTest_serviceChanged(framework_pt framework, service_event_type_e eventType, service_registration_pt registration, properties_pt oldprops) { + mock_c()->actualCall("serviceRegistryTest_serviceChanged") + ->withPointerParameters("framework", framework) + ->withIntParameters("eventType", eventType) + ->withPointerParameters("registration", registration) + ->withPointerParameters("oldprops", oldprops); +} } int main(int argc, char** argv) { @@ -44,8 +53,6 @@ int main(int argc, char** argv) { TEST_GROUP(service_registry) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } void teardown() { @@ -54,11 +61,6 @@ TEST_GROUP(service_registry) { } }; -extern "C" { -void serviceRegistryTest_serviceChanged(framework_pt framework, service_event_type_e eventType, service_registration_pt registration, properties_pt oldprops) { -} -} - TEST(service_registry, create) { framework_pt framework = (framework_pt) 0x10; service_registry_pt registry = NULL; @@ -71,14 +73,20 @@ TEST(service_registry, create) { CHECK(registry->inUseMap != NULL); CHECK(registry->listenerHooks != NULL); //CHECK(registry->mutex != NULL); - CHECK(registry->serviceReferences == NULL); + CHECK(registry->serviceReferences != NULL); CHECK(registry->serviceRegistrations != NULL); + + serviceRegistry_destroy(registry); } TEST(service_registry, getRegisteredServices) { service_registry_pt registry = (service_registry_pt) malloc(sizeof(*registry)); registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL); - + registry->serviceReferences = hashMap_create(NULL, NULL, NULL, NULL); + celixThreadMutexAttr_create(®istry->mutexAttr); + celixThreadMutexAttr_settype(®istry->mutexAttr, CELIX_THREAD_MUTEX_RECURSIVE); + celixThreadMutex_create(®istry->mutex, ®istry->mutexAttr); + celixThreadMutex_create(®istry->referencesMapMutex, NULL); array_list_pt registrations = NULL; arrayList_create(®istrations); service_registration_pt reg = (service_registration_pt) 0x10; @@ -108,21 +116,28 @@ TEST(service_registry, getRegisteredServices) { .withOutputParameterReturning("reference", &ref, sizeof(ref)) .andReturnValue(CELIX_SUCCESS) .ignoreOtherParameters(); - mock() + /*mock() .expectOneCall("serviceRegistration_getServiceReferences") .withParameter("registration", reg) .withOutputParameterReturning("references", &refs, sizeof(refs)) - .andReturnValue(CELIX_SUCCESS); + .andReturnValue(CELIX_SUCCESS);*/ array_list_pt services = NULL; serviceRegistry_getRegisteredServices(registry, bundle, &services); LONGS_EQUAL(1, arrayList_size(services)); POINTERS_EQUAL(ref, arrayList_get(services, 0)); + + free(registry); } TEST(service_registry, getServicesInUse) { service_registry_pt registry = (service_registry_pt) malloc(sizeof(*registry)); registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL); + celixThreadMutexAttr_create(®istry->mutexAttr); + celixThreadMutexAttr_settype(®istry->mutexAttr, CELIX_THREAD_MUTEX_RECURSIVE); + celixThreadMutex_create(®istry->mutex, ®istry->mutexAttr); + + celixThreadMutex_create(®istry->referencesMapMutex, NULL); array_list_pt usages = NULL; arrayList_create(&usages); @@ -137,6 +152,8 @@ TEST(service_registry, getServicesInUse) { serviceRegistry_getServicesInUse(registry, bundle, &inUse); LONGS_EQUAL(1, arrayList_size(inUse)); POINTERS_EQUAL(ref, arrayList_get(inUse, 0)); + + free(registry); } TEST(service_registry, registerServiceNoProps) { @@ -167,6 +184,8 @@ TEST(service_registry, registerServiceNoProps) { service_registration_pt registration = NULL; serviceRegistry_registerService(registry, bundle, (char *) serviceName.c_str(), service, NULL, ®istration); POINTERS_EQUAL(reg, registration); + + free(registry); } TEST(service_registry, registerServiceFactoryNoProps) { @@ -197,6 +216,8 @@ TEST(service_registry, registerServiceFactoryNoProps) { service_registration_pt registration = NULL; serviceRegistry_registerServiceFactory(registry, bundle, (char *) serviceName.c_str(), factory, NULL, ®istration); POINTERS_EQUAL(reg, registration); + + free(registry); } TEST(service_registry, unregisterService) { @@ -242,12 +263,19 @@ TEST(service_registry, unregisterService) { .withParameter("registration", registration) .withOutputParameterReturning("references", &references, sizeof(references)) .andReturnValue(CELIX_SUCCESS); + mock() + .expectOneCall("serviceReference_invalidate") + .withParameter("reference", reference) + .andReturnValue(CELIX_SUCCESS); + mock() .expectOneCall("serviceRegistration_invalidate") .withParameter("registration", registration) .andReturnValue(CELIX_SUCCESS); serviceRegistry_unregisterService(registry, bundle, registration); + + free(registry); } TEST(service_registry, unregisterServices) { @@ -277,14 +305,18 @@ TEST(service_registry, unregisterServices) { .andReturnValue(CELIX_SUCCESS); serviceRegistry_unregisterServices(registry, bundle); LONGS_EQUAL(0, hashMap_size(registry->serviceRegistrations)); + + free(registry); } -TEST(service_registry, getServiceReferences) { +TEST(service_registry, getServiceReferencesForRegistration){ +#warning implement this service_registry_pt registry = (service_registry_pt) malloc(sizeof(*registry)); registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL); celixThreadMutexAttr_create(®istry->mutexAttr); celixThreadMutexAttr_settype(®istry->mutexAttr, CELIX_THREAD_MUTEX_RECURSIVE); celixThreadMutex_create(®istry->mutex, ®istry->mutexAttr); + celixThreadMutex_create(®istry->referencesMapMutex, NULL); registry->currentServiceId = 1l; registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL); @@ -293,7 +325,34 @@ TEST(service_registry, getServiceReferences) { array_list_pt registrations = NULL; arrayList_create(®istrations); arrayList_add(registrations, registration); + registry->serviceReferences = hashMap_create(NULL, NULL, NULL, NULL); + hashMap_put(registry->serviceRegistrations, bundle, registrations); + properties_pt properties = (properties_pt) 0x30; + array_list_pt references = NULL; + arrayList_create(&references); + service_reference_pt reference = (service_reference_pt) 0x40; + arrayList_add(references, reference); + + serviceRegistry_getServiceReferencesForRegistration(registry, registration, &references); +} + +TEST(service_registry, getServiceReferences) { + service_registry_pt registry = (service_registry_pt) malloc(sizeof(*registry)); + registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL); + celixThreadMutexAttr_create(®istry->mutexAttr); + celixThreadMutexAttr_settype(®istry->mutexAttr, CELIX_THREAD_MUTEX_RECURSIVE); + celixThreadMutex_create(®istry->mutex, ®istry->mutexAttr); + celixThreadMutex_create(®istry->referencesMapMutex, NULL); + registry->currentServiceId = 1l; + registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL); + + bundle_pt bundle = (bundle_pt) 0x10; + service_registration_pt registration = (service_registration_pt) 0x20; + array_list_pt registrations = NULL; + arrayList_create(®istrations); + arrayList_add(registrations, registration); + registry->serviceReferences = hashMap_create(NULL, NULL, NULL, NULL); hashMap_put(registry->serviceRegistrations, bundle, registrations); properties_pt properties = (properties_pt) 0x30; @@ -330,17 +389,19 @@ TEST(service_registry, getServiceReferences) { .withOutputParameterReturning("reference", &reference, sizeof(reference)) .andReturnValue(CELIX_SUCCESS) .ignoreOtherParameters(); - mock() + /*mock() .expectOneCall("serviceRegistration_getServiceReferences") .withParameter("registration", registration) .withOutputParameterReturning("references", &references, sizeof(references)) - .andReturnValue(CELIX_SUCCESS); + .andReturnValue(CELIX_SUCCESS);*/ array_list_pt actual = NULL; serviceRegistry_getServiceReferences(registry, NULL, "test", NULL, &actual); LONGS_EQUAL(1, arrayList_size(actual)); POINTERS_EQUAL(reference, arrayList_get(actual, 0)); + + free(registry); } TEST(service_registry, getService) { @@ -379,11 +440,11 @@ TEST(service_registry, getService) { .expectOneCall("serviceRegistration_isValid") .withParameter("registration", registration) .andReturnValue(true); - mock() + /*mock() .expectOneCall("bundle_getCurrentModule") .withParameter("bundle", bundle) .withOutputParameterReturning("module", &module, sizeof(module)) - .andReturnValue(CELIX_SUCCESS); + .andReturnValue(CELIX_SUCCESS);*/ mock() .expectOneCall("serviceRegistration_getService") .withParameter("registration", registration) @@ -398,10 +459,12 @@ TEST(service_registry, getService) { void *actual = NULL; serviceRegistry_getService(registry, bundle, reference, &actual); POINTERS_EQUAL(service, actual); + + free(registry); } TEST(service_registry, ungetService) { - service_registry_pt registry = (service_registry_pt) malloc(sizeof(*registry)); + service_registry_pt registry = (service_registry_pt) calloc(1,sizeof(*registry)); registry->inUseMap = hashMap_create(NULL, NULL, NULL, NULL); celixThreadMutexAttr_create(®istry->mutexAttr); celixThreadMutexAttr_settype(®istry->mutexAttr, CELIX_THREAD_MUTEX_RECURSIVE); @@ -425,7 +488,7 @@ TEST(service_registry, ungetService) { array_list_pt usages = NULL; arrayList_create(&usages); - usage_count_pt usage = (usage_count_pt) malloc(sizeof(*usage)); + usage_count_pt usage = (usage_count_pt) calloc(1,sizeof(*usage)); usage->reference = reference; arrayList_add(usages, usage); hashMap_put(registry->inUseMap, bundle, usages); @@ -435,18 +498,25 @@ TEST(service_registry, ungetService) { .withParameter("reference", reference) .withOutputParameterReturning("registration", ®istration, sizeof(registration)) .andReturnValue(CELIX_SUCCESS); + + bool out = true; + mock() + .expectOneCall("serviceReference_equals") + .withParameter("reference", reference) + .withParameter("compareTo", reference) + .withOutputParameterReturning("equal", &out, sizeof(out)) + .andReturnValue(CELIX_SUCCESS); + mock() .expectOneCall("serviceRegistration_isValid") .withParameter("registration", registration) .andReturnValue(true); - mock() - .expectOneCall("serviceReference_destroy") - .withParameter("reference", reference) - .andReturnValue(CELIX_SUCCESS); bool result = false; serviceRegistry_ungetService(registry, bundle, reference, &result); LONGS_EQUAL(1, result); + + free(registry); } TEST(service_registry, ungetServivces) { @@ -485,27 +555,42 @@ TEST(service_registry, ungetServivces) { .withParameter("reference", reference) .withOutputParameterReturning("registration", ®istration, sizeof(registration)) .andReturnValue(CELIX_SUCCESS); -// mock() -// .expectOneCall("serviceReference_equals") -// .withParameter("reference", reference) -// .withParameter("compareTo", reference) -// .withOutputParameterReturning("equal", true) -// .andReturnValue(CELIX_SUCCESS); + + bool out = true; + mock() + .expectOneCall("serviceReference_equals") + .withParameter("reference", reference) + .withParameter("compareTo", reference) + .withOutputParameterReturning("equal", &out, sizeof(out)) + .andReturnValue(CELIX_SUCCESS); + + out = true; + mock() + .expectOneCall("serviceReference_equals") + .withParameter("reference", reference) + .withParameter("compareTo", reference) + .withOutputParameterReturning("equal", &out, sizeof(out)) + .andReturnValue(CELIX_SUCCESS); + + mock().expectOneCall("serviceRegistration_ungetService") + .withParameter("registration", registration) + .withParameter("bundle", bundle) + .withOutputParameterReturning("service", &reference, sizeof(reference)); + mock() .expectOneCall("serviceRegistration_isValid") .withParameter("registration", registration) .andReturnValue(true); + mock() .expectOneCall("serviceReference_getServiceRegistration") .withParameter("reference", reference) .withOutputParameterReturning("registration", ®istration, sizeof(registration)) .andReturnValue(CELIX_SUCCESS); - mock() - .expectOneCall("serviceReference_destroy") - .withParameter("reference", reference) - .andReturnValue(CELIX_SUCCESS); serviceRegistry_ungetServices(registry, bundle); + + free(registry); } TEST(service_registry, getUsingBundles) { @@ -538,9 +623,19 @@ TEST(service_registry, getUsingBundles) { arrayList_add(usages, usage); hashMap_put(registry->inUseMap, bundle, usages); + bool out = true; + mock() + .expectOneCall("serviceReference_equals") + .withParameter("reference", reference) + .withParameter("compareTo", reference) + .withOutputParameterReturning("equal", &out, sizeof(out)) + .andReturnValue(CELIX_SUCCESS); + array_list_pt actual = serviceRegistry_getUsingBundles(registry, reference); LONGS_EQUAL(1, arrayList_size(actual)); POINTERS_EQUAL(bundle, arrayList_get(actual, 0)); + + free(registry); } TEST(service_registry, createServiceReference) { @@ -549,16 +644,17 @@ TEST(service_registry, createServiceReference) { celixThreadMutexAttr_create(®istry->mutexAttr); celixThreadMutexAttr_settype(®istry->mutexAttr, CELIX_THREAD_MUTEX_RECURSIVE); celixThreadMutex_create(®istry->mutex, ®istry->mutexAttr); + celixThreadMutex_create(®istry->referencesMapMutex, NULL); registry->currentServiceId = 1l; - registry->serviceRegistrations = hashMap_create(NULL, NULL, NULL, NULL); + registry->serviceReferences = hashMap_create(NULL, NULL, NULL, NULL); bundle_pt bundle = (bundle_pt) 0x10; service_registration_pt registration = (service_registration_pt) 0x20; -// array_list_pt registrations = NULL; -// arrayList_create(®istrations); -// arrayList_add(registrations, registration); -// -// hashMap_put(registry->serviceRegistrations, bundle, registrations); + /*array_list_pt registrations = NULL; + arrayList_create(®istrations); + arrayList_add(registrations, registration); + + hashMap_put(registry->serviceRegistrations, bundle, registrations);*/ array_list_pt references = NULL; arrayList_create(&references); @@ -578,22 +674,23 @@ TEST(service_registry, createServiceReference) { .withOutputParameterReturning("reference", &reference, sizeof(reference)) .andReturnValue(CELIX_SUCCESS) .ignoreOtherParameters(); - mock() - .expectOneCall("serviceRegistration_getServiceReferences") - .withParameter("registration", registration) - .withOutputParameterReturning("references", &references, sizeof(references)) - .andReturnValue(CELIX_SUCCESS); service_reference_pt actual = NULL; serviceRegistry_createServiceReference(registry, NULL, registration, &actual); POINTERS_EQUAL(reference, actual); + + free(registry); } TEST(service_registry, getListenerHooks) { service_registry_pt registry = (service_registry_pt) malloc(sizeof(*registry)); registry->listenerHooks = NULL; arrayList_create(®istry->listenerHooks); - + celixThreadMutexAttr_create(®istry->mutexAttr); + celixThreadMutexAttr_settype(®istry->mutexAttr, CELIX_THREAD_MUTEX_RECURSIVE); + celixThreadMutex_create(®istry->mutex, ®istry->mutexAttr); + celixThreadMutex_create(®istry->referencesMapMutex, NULL); + registry->serviceReferences = hashMap_create(NULL, NULL, NULL, NULL); bundle_pt bundle = (bundle_pt) 0x10; service_registration_pt registration = (service_registration_pt) 0x20; arrayList_add(registry->listenerHooks, registration); @@ -616,23 +713,30 @@ TEST(service_registry, getListenerHooks) { .withOutputParameterReturning("reference", &reference, sizeof(reference)) .andReturnValue(CELIX_SUCCESS) .ignoreOtherParameters(); - mock() - .expectOneCall("serviceRegistration_getServiceReferences") - .withParameter("registration", registration) - .withOutputParameterReturning("references", &references, sizeof(registration)) - .andReturnValue(CELIX_SUCCESS); array_list_pt hooks = NULL; celix_status_t status = serviceRegistry_getListenerHooks(registry, NULL, &hooks); LONGS_EQUAL(1, arrayList_size(hooks)); POINTERS_EQUAL(reference, arrayList_get(hooks, 0)); + + free(registry); } TEST(service_registry, servicePropertiesModified) { service_registry_pt registry = (service_registry_pt) malloc(sizeof(*registry)); service_registration_pt registration = (service_registration_pt) 0x10; properties_pt properties = (properties_pt) 0x20; + //test function, defined at top of this test file + registry->serviceChanged = serviceRegistryTest_serviceChanged; + registry->framework = (framework_pt) 0x30; + + mock().expectOneCall("serviceRegistryTest_serviceChanged") + .withParameter("framework", registry->framework) + .withParameter("eventType", OSGI_FRAMEWORK_SERVICE_EVENT_MODIFIED) + .withParameter("registration", registration) + .withParameter("oldprops", properties); serviceRegistry_servicePropertiesModified(registry, registration, properties); -} + free(registry); +} diff --git a/framework/private/test/service_tracker_customizer_test.cpp b/framework/private/test/service_tracker_customizer_test.cpp index be33867c5..70421824b 100644 --- a/framework/private/test/service_tracker_customizer_test.cpp +++ b/framework/private/test/service_tracker_customizer_test.cpp @@ -30,7 +30,7 @@ #include "CppUTest/TestHarness.h" #include "CppUTest/TestHarness_c.h" #include "CppUTest/CommandLineTestRunner.h" -//#include "CppUTestExt/MockSupport.h" +#include "CppUTestExt/MockSupport.h" extern "C" { @@ -47,13 +47,11 @@ int main(int argc, char** argv) { TEST_GROUP(service_tracker_customizer) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } void teardown() { -// mock().checkExpectations(); -// mock().clear(); + mock().checkExpectations(); + mock().clear(); } }; @@ -88,9 +86,13 @@ TEST(service_tracker_customizer, create) { POINTERS_EQUAL(serviceTrackerCustomizerTest_addedService, customizer->addedService); POINTERS_EQUAL(serviceTrackerCustomizerTest_modifiedService, customizer->modifiedService); POINTERS_EQUAL(serviceTrackerCustomizerTest_removedService, customizer->removedService); + + serviceTrackerCustomizer_destroy(customizer); } TEST(service_tracker_customizer, createIllegalArgument) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + void *handle = (void *) 0x10; service_tracker_customizer_pt customizer = NULL; celix_status_t status = serviceTrackerCustomizer_create( @@ -112,6 +114,8 @@ TEST(service_tracker_customizer, getHandle) { celix_status_t status = serviceTrackerCustomizer_getHandle(customizer, &getHandle); LONGS_EQUAL(CELIX_SUCCESS, status); POINTERS_EQUAL(handle, getHandle); + + free(customizer); } TEST(service_tracker_customizer, getAddingFunction) { @@ -123,6 +127,8 @@ TEST(service_tracker_customizer, getAddingFunction) { celix_status_t status = serviceTrackerCustomizer_getAddingFunction(customizer, &getAdding); LONGS_EQUAL(CELIX_SUCCESS, status); POINTERS_EQUAL(adding, getAdding); + + free(customizer); } TEST(service_tracker_customizer, getAddedFunction) { @@ -134,6 +140,8 @@ TEST(service_tracker_customizer, getAddedFunction) { celix_status_t status = serviceTrackerCustomizer_getAddedFunction(customizer, &getAdded); LONGS_EQUAL(CELIX_SUCCESS, status); POINTERS_EQUAL(added, getAdded); + + free(customizer); } TEST(service_tracker_customizer, getModifiedFunction) { @@ -145,6 +153,8 @@ TEST(service_tracker_customizer, getModifiedFunction) { celix_status_t status = serviceTrackerCustomizer_getModifiedFunction(customizer, &getModified); LONGS_EQUAL(CELIX_SUCCESS, status); POINTERS_EQUAL(modified, getModified); + + free(customizer); } TEST(service_tracker_customizer, getRemovedFunction) { @@ -156,5 +166,7 @@ TEST(service_tracker_customizer, getRemovedFunction) { celix_status_t status = serviceTrackerCustomizer_getRemovedFunction(customizer, &getRemoved); LONGS_EQUAL(CELIX_SUCCESS, status); POINTERS_EQUAL(removed, getRemoved); + + free(customizer); } diff --git a/framework/private/test/service_tracker_test.cpp b/framework/private/test/service_tracker_test.cpp index e3a7911a7..06c268eec 100644 --- a/framework/private/test/service_tracker_test.cpp +++ b/framework/private/test/service_tracker_test.cpp @@ -37,7 +37,7 @@ extern "C" #include "service_reference_private.h" #include "celix_log.h" -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x42; } int main(int argc, char** argv) { @@ -46,8 +46,6 @@ int main(int argc, char** argv) { TEST_GROUP(service_tracker) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } void teardown() { @@ -69,6 +67,8 @@ TEST(service_tracker, create) { POINTERS_EQUAL(NULL, tracker->listener); POINTERS_EQUAL(tracker, tracker->tracker); STRCMP_EQUAL("(objectClass=service)", tracker->filter); + + serviceTracker_destroy(tracker); } TEST(service_tracker, createWithFilter) { @@ -84,6 +84,8 @@ TEST(service_tracker, createWithFilter) { POINTERS_EQUAL(NULL, tracker->listener); POINTERS_EQUAL(tracker, tracker->tracker); STRCMP_EQUAL("(objectClass=test)", tracker->filter); + + serviceTracker_destroy(tracker); } TEST(service_tracker, destroy) { @@ -92,7 +94,7 @@ TEST(service_tracker, destroy) { bundle_context_pt ctx = (bundle_context_pt) 0x123; std::string filter = "(objectClass=test)"; status = serviceTracker_createWithFilter(ctx, (char *) filter.c_str(), NULL, &tracker); - service_listener_pt listener = (service_listener_pt) 0x20; + service_listener_pt listener = (service_listener_pt) calloc(1, sizeof(serviceListener)); tracker->listener = listener; mock() @@ -139,6 +141,11 @@ TEST(service_tracker, open) { // No services should be found LONGS_EQUAL(0, arrayList_size(tracker->tracked)); + + arrayList_destroy(tracked); + + free(tracker->listener); + free(tracker); } TEST(service_tracker, open_withRefs) { @@ -197,6 +204,13 @@ TEST(service_tracker, open_withRefs) { // One service should be found LONGS_EQUAL(1, arrayList_size(tracker->tracked)); + + free(arrayList_get(tracked, 0)); + arrayList_destroy(tracked); + + free(tracker->listener); + free(tracker); + free(ref); } TEST(service_tracker, open_withRefsAndTracked) { @@ -238,18 +252,27 @@ TEST(service_tracker, open_withRefsAndTracked) { .withParameter("filter", "(objectClass=service)") .ignoreOtherParameters() .andReturnValue(CELIX_SUCCESS); + bool equal = true; mock() .expectOneCall("serviceReference_equals") .withParameter("reference", ref) + .withParameter("compareTo", ref) .withOutputParameterReturning("equal", &equal, sizeof(equal)) - .ignoreOtherParameters() + //.ignoreOtherParameters() .andReturnValue(CELIX_SUCCESS); + serviceTracker_open(tracker); CHECK(tracker->listener != NULL); // One service should be found LONGS_EQUAL(1, arrayList_size(tracker->tracked)); + + arrayList_destroy(tracked); + + free(tracker->listener); + free(tracker); + free(entry); } TEST(service_tracker, close) { @@ -292,7 +315,16 @@ TEST(service_tracker, close) { .withOutputParameterReturning("result", &result, sizeof(result)) .andReturnValue(CELIX_SUCCESS); + mock() + .expectOneCall("bundleContext_ungetServiceReference") + .withParameter("context", ctx) + .withParameter("reference", ref) + .andReturnValue(CELIX_SUCCESS); + serviceTracker_close(tracker); + + arrayList_destroy(tracked); + free(tracker); } TEST(service_tracker, getServiceReference) { @@ -316,6 +348,12 @@ TEST(service_tracker, getServiceReference) { service_reference_pt reference = serviceTracker_getServiceReference(tracker); POINTERS_EQUAL(ref, reference); + + arrayList_destroy(tracked); + + free(tracker); + free(entry); + free(entry2); } TEST(service_tracker, getServiceReferenceNull) { @@ -328,6 +366,9 @@ TEST(service_tracker, getServiceReferenceNull) { service_reference_pt reference = serviceTracker_getServiceReference(tracker); POINTERS_EQUAL(NULL, reference); + + arrayList_destroy(tracked); + free(tracker); } TEST(service_tracker, getServiceReferences) { @@ -353,6 +394,13 @@ TEST(service_tracker, getServiceReferences) { LONGS_EQUAL(2, arrayList_size(references)); POINTERS_EQUAL(ref, arrayList_get(references, 0)); POINTERS_EQUAL(ref2, arrayList_get(references, 1)); + + arrayList_destroy(references); + arrayList_destroy(tracked); + + free(tracker); + free(entry); + free(entry2); } TEST(service_tracker, getService) { @@ -376,6 +424,12 @@ TEST(service_tracker, getService) { void *service = serviceTracker_getService(tracker); POINTERS_EQUAL(0x31, service); + + arrayList_destroy(tracked); + + free(entry); + free(entry2); + free(tracker); } TEST(service_tracker, getServiceNull) { @@ -388,6 +442,9 @@ TEST(service_tracker, getServiceNull) { void *service = serviceTracker_getService(tracker); POINTERS_EQUAL(NULL, service); + + arrayList_destroy(tracked); + free(tracker); } TEST(service_tracker, getServices) { @@ -413,6 +470,13 @@ TEST(service_tracker, getServices) { LONGS_EQUAL(2, arrayList_size(services)); POINTERS_EQUAL(0x31, arrayList_get(services, 0)); POINTERS_EQUAL(0x32, arrayList_get(services, 1)); + + arrayList_destroy(services); + arrayList_destroy(tracked); + + free(entry); + free(entry2); + free(tracker); } TEST(service_tracker, getServiceByReference) { @@ -433,12 +497,17 @@ TEST(service_tracker, getServiceByReference) { mock() .expectOneCall("serviceReference_equals") .withParameter("reference", ref) + .withParameter("compareTo", ref) .withOutputParameterReturning("equal", &equal, sizeof(equal)) - .ignoreOtherParameters() - .andReturnValue(4) - .withCallOrder(1); + .andReturnValue(4); + //.ignoreOtherParameters(); void *service = serviceTracker_getServiceByReference(tracker, ref); POINTERS_EQUAL(0x31, service); + + arrayList_destroy(tracked); + + free(tracker); + free(entry); } TEST(service_tracker, getServiceByReferenceNull) { @@ -465,6 +534,11 @@ TEST(service_tracker, getServiceByReferenceNull) { .withCallOrder(1); void *service = serviceTracker_getServiceByReference(tracker, ref); POINTERS_EQUAL(NULL, service); + + arrayList_destroy(tracked); + + free(tracker); + free(entry); } TEST(service_tracker, serviceChangedRegistered) { @@ -495,6 +569,13 @@ TEST(service_tracker, serviceChangedRegistered) { .withOutputParameterReturning("service_instance", &src, sizeof(src)) .andReturnValue(CELIX_SUCCESS); serviceTracker_serviceChanged(listener, event); + + free(arrayList_get(tracked, 0)); + arrayList_destroy(tracked); + + free(event); + free(tracker); + free(listener); } TEST(service_tracker, serviceChangedModified) { @@ -530,7 +611,22 @@ TEST(service_tracker, serviceChangedModified) { .withOutputParameterReturning("equal", &equal, sizeof(equal)) .ignoreOtherParameters() .andReturnValue(CELIX_SUCCESS); + + mock() + .expectOneCall("bundleContext_getService") + .withParameter("context", ctx) + .withParameter("reference", ref) + .withOutputParameterReturning("service_instance", &entry->service, sizeof(entry->service)); + serviceTracker_serviceChanged(listener, event); + + free(arrayList_get(tracked, 0)); + free(arrayList_get(tracked, 1)); + arrayList_destroy(tracked); + + free(event); + free(listener); + free(tracker); } TEST(service_tracker, serviceChangedUnregistering) { @@ -573,7 +669,20 @@ TEST(service_tracker, serviceChangedUnregistering) { .withParameter("reference", ref) .withOutputParameterReturning("result", &result, sizeof(result)) .andReturnValue(CELIX_SUCCESS); + + mock() + .expectOneCall("bundleContext_ungetServiceReference") + .withParameter("context", ctx) + .withParameter("reference", ref) + .andReturnValue(CELIX_SUCCESS); + serviceTracker_serviceChanged(listener, event); + + arrayList_destroy(tracked); + + free(listener); + free(event); + free(tracker); } TEST(service_tracker, serviceChangedModifiedEndmatch) { @@ -602,6 +711,13 @@ TEST(service_tracker, serviceChangedModifiedEndmatch) { event->reference = ref; serviceTracker_serviceChanged(listener, event); + + arrayList_destroy(tracked); + + free(entry); + free(listener); + free(tracker); + free(event); } extern "C" { @@ -661,6 +777,13 @@ TEST(service_tracker, serviceChangedRegisteredCustomizer) { .withOutputParameterReturning("function", &function2, sizeof(function)) .andReturnValue(CELIX_SUCCESS); serviceTracker_serviceChanged(listener, event); + + free(arrayList_get(tracked, 0)); + arrayList_destroy(tracked); + + free(event); + free(tracker); + free(listener); } @@ -681,6 +804,8 @@ TEST(service_tracker, serviceChangedModifiedCustomizer) { listener->handle = tracker; service_tracker_customizer_pt customizer = (service_tracker_customizer_pt) 0x20; tracker->customizer = customizer; + adding_callback_pt adding_func = NULL; + added_callback_pt added_func = NULL; // new tracker->tracked array_list_pt tracked = NULL; @@ -706,17 +831,45 @@ TEST(service_tracker, serviceChangedModifiedCustomizer) { .andReturnValue(CELIX_SUCCESS); void * handle = (void*) 0x60; mock() - .expectOneCall("serviceTrackerCustomizer_getHandle") + .expectNCalls(2, "serviceTrackerCustomizer_getHandle") .withParameter("customizer", customizer) .withOutputParameterReturning("handle", &handle, sizeof(handle)) .andReturnValue(CELIX_SUCCESS); void *function = (void *) serviceDependency_modifiedService; - mock() +/* mock() .expectOneCall("serviceTrackerCustomizer_getModifiedFunction") .withParameter("customizer", customizer) .withOutputParameterReturning("function", &function, sizeof(function)) .andReturnValue(CELIX_SUCCESS); +*/ + mock() + .expectOneCall("serviceTrackerCustomizer_getAddingFunction") + .withParameter("customizer", customizer) + .withOutputParameterReturning("function", &adding_func, sizeof(adding_func)) + .andReturnValue(CELIX_SUCCESS); + + mock() + .expectOneCall("serviceTrackerCustomizer_getAddedFunction") + .withParameter("customizer", customizer) + .withOutputParameterReturning("function", &added_func, sizeof(added_func)); + + + mock() + .expectOneCall("bundleContext_getService") + .withParameter("context", ctx) + .withParameter("reference", ref) + .withOutputParameterReturning("service_instance", &entry->service, sizeof(entry->service)); + + serviceTracker_serviceChanged(listener, event); + + free(arrayList_get(tracked, 0)); + free(arrayList_get(tracked, 1)); + arrayList_destroy(tracked); + + free(event); + free(listener); + free(tracker); } extern "C" { @@ -771,7 +924,19 @@ TEST(service_tracker, serviceChangedUnregisteringCustomizer) { .withParameter("customizer", customizer) .withOutputParameterReturning("function", &function , sizeof(function)) .andReturnValue(CELIX_SUCCESS); + + mock() + .expectOneCall("bundleContext_ungetServiceReference") + .withParameter("context", ctx) + .withParameter("reference", ref) + .andReturnValue(CELIX_SUCCESS); serviceTracker_serviceChanged(listener, event); + + arrayList_destroy(tracked); + + free(listener); + free(event); + free(tracker); } TEST(service_tracker, serviceChangedUnregisteringCustomizerNoFunc) { @@ -827,7 +992,19 @@ TEST(service_tracker, serviceChangedUnregisteringCustomizerNoFunc) { .withParameter("reference", ref) .withOutputParameterReturning("result", &result, sizeof(result)) .andReturnValue(CELIX_SUCCESS); + + mock() + .expectOneCall("bundleContext_ungetServiceReference") + .withParameter("context", ctx) + .withParameter("reference", ref) + .andReturnValue(CELIX_SUCCESS); + serviceTracker_serviceChanged(listener, event); + + arrayList_destroy(tracked); + free(listener); + free(tracker); + free(event); } diff --git a/framework/private/test/utils_test.cpp b/framework/private/test/utils_test.cpp index 1dfbe9b48..27d4a2230 100644 --- a/framework/private/test/utils_test.cpp +++ b/framework/private/test/utils_test.cpp @@ -23,6 +23,10 @@ * \author Apache Celix Project Team * \copyright Apache License, Version 2.0 */ +#include "string.h" +#include +#include + #include "CppUTest/TestHarness.h" #include "CppUTest/TestHarness_c.h" #include "CppUTest/CommandLineTestRunner.h" @@ -45,17 +49,36 @@ TEST_GROUP(utils) { } }; +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; +} + TEST(utils, stringHash) { - std::string toHash = "abc"; + char * toHash = my_strdup("abc"); unsigned int hash; - hash = utils_stringHash((void *) toHash.c_str()); + hash = utils_stringHash((void *) toHash); LONGS_EQUAL(446371745, hash); - toHash = "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"; - hash = utils_stringHash((void *) toHash.c_str()); + free(toHash); + toHash = my_strdup("abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"); + hash = utils_stringHash((void *) toHash); LONGS_EQUAL(1508668412, hash); - toHash = "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" + free(toHash); + toHash = my_strdup("abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" @@ -76,34 +99,40 @@ TEST(utils, stringHash) { "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" - "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"; - hash = utils_stringHash((void *) toHash.c_str()); + "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"); + hash = utils_stringHash((void *) toHash); LONGS_EQUAL(829630780, hash); + free(toHash); } TEST(utils, stringEquals) { // Compare with equal strings - std::string org = "abc"; - std::string cmp = "abc"; + char * org = my_strdup("abc"); + char * cmp = my_strdup("abc"); - int result = utils_stringEquals((void *) org.c_str(), (void *) cmp.c_str()); + int result = utils_stringEquals((void *) org, (void *) cmp); CHECK(result); // Compare with no equal strings - cmp = "abcd"; + free(cmp); + cmp = my_strdup("abcd"); - result = utils_stringEquals((void *) org.c_str(), (void *) cmp.c_str()); - CHECK(!result); + result = utils_stringEquals((void *) org, (void *) cmp); + CHECK_FALSE(result); // Compare with numeric strings - org = "123"; - cmp = "123"; + free(org); + free(cmp); + org = my_strdup("123"); + cmp = my_strdup("123"); - result = utils_stringEquals((void *) org.c_str(), (void *) cmp.c_str()); + result = utils_stringEquals((void *) org, (void *) cmp); CHECK(result); // Compare with long strings - org = "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" + free(org); + free(cmp); + org = my_strdup("abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" @@ -124,8 +153,8 @@ TEST(utils, stringEquals) { "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" - "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"; - cmp = "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" + "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"); + cmp = my_strdup("abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" @@ -146,58 +175,101 @@ TEST(utils, stringEquals) { "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz" - "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"; + "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"); - result = utils_stringEquals((void *) org.c_str(), (void *) cmp.c_str()); + result = utils_stringEquals((void *) org, (void *) cmp); CHECK(result); + + free(org); + free(cmp); +} + +TEST(utils, string_ndup){ + // Compare with equal strings + const char * org = "abc"; + char * cmp = NULL; + + cmp = string_ndup(org, 3); + STRCMP_EQUAL(org, cmp); + free(cmp); + + org = "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"; + cmp = string_ndup(org, 50); + STRCMP_EQUAL(org, cmp); + free(cmp); + + cmp = string_ndup(org, 25); + LONGS_EQUAL(25, strlen(cmp)); + free(cmp); } TEST(utils, stringTrim) { // Multiple whitespaces, before, after and in between - std::string toTrim = " a b c "; - char *result = utils_stringTrim((char*) toTrim.c_str()); + char * toTrim = my_strdup(" a b c "); + char * result = utils_stringTrim(toTrim); STRCMP_EQUAL("a b c", result); // No whitespaces - toTrim = "abc"; - result = utils_stringTrim((char*) toTrim.c_str()); + free(toTrim); + toTrim = my_strdup("abc"); + result = utils_stringTrim(toTrim); STRCMP_EQUAL("abc", result); // Only whitespace before - toTrim = " abc"; - result = utils_stringTrim((char*) toTrim.c_str()); + free(toTrim); + toTrim = my_strdup(" abc"); + result = utils_stringTrim(toTrim); STRCMP_EQUAL("abc", result); // Only whitespace after - toTrim = "abc "; - result = utils_stringTrim((char*) toTrim.c_str()); + free(toTrim); + toTrim = my_strdup("abc "); + result = utils_stringTrim(toTrim); STRCMP_EQUAL("abc", result); // Whitespace other then space (tab, cr..). - toTrim = "\tabc \n asdf \n"; - result = utils_stringTrim((char*) toTrim.c_str()); + free(toTrim); + toTrim = my_strdup("\tabc \n asdf \n"); + result = utils_stringTrim(toTrim); STRCMP_EQUAL("abc \n asdf", result); + + free(toTrim); +} + +TEST(utils, thread_equalsSelf){ + celix_thread thread = celixThread_self(); + bool get; + + LONGS_EQUAL(CELIX_SUCCESS, thread_equalsSelf(thread, &get)); + CHECK(get); + + thread.thread = (pthread_t) 0x42; + LONGS_EQUAL(CELIX_SUCCESS, thread_equalsSelf(thread, &get)); + CHECK_FALSE(get); } TEST(utils, isNumeric) { // Check numeric string - std::string toCheck = "42"; + char * toCheck = my_strdup("42"); bool result; - celix_status_t status = utils_isNumeric((char *) toCheck.c_str(), &result); + celix_status_t status = utils_isNumeric(toCheck, &result); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(result); // Check non numeric string - toCheck = "42b"; - status = utils_isNumeric((char *) toCheck.c_str(), &result); + free(toCheck); + toCheck = my_strdup("42b"); + status = utils_isNumeric(toCheck, &result); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(!result); + + free(toCheck); } diff --git a/framework/private/test/version_range_test.cpp b/framework/private/test/version_range_test.cpp index 5970d6d80..95bf1b16d 100644 --- a/framework/private/test/version_range_test.cpp +++ b/framework/private/test/version_range_test.cpp @@ -28,26 +28,44 @@ #include "CppUTest/TestHarness_c.h" #include "CppUTest/CommandLineTestRunner.h" #include "CppUTestExt/MockSupport.h" +#include "string.h" extern "C" { - #include "version_range_private.h" - #include "version_private.h" +#include "version_range_private.h" +#include "version_private.h" - #include "celix_log.h" +#include "celix_log.h" - framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x42; } 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; +} + +//----------------------TESTGROUP DEFINES---------------------- + TEST_GROUP(version_range) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } void teardown() { @@ -68,6 +86,11 @@ TEST(version_range, create) { LONGS_EQUAL(false, range->isLowInclusive); POINTERS_EQUAL(version, range->low); POINTERS_EQUAL(version, range->high); + + mock().expectNCalls(2, "version_destroy"); + + versionRange_destroy(range); + free(version); } TEST(version_range, createInfinite) { @@ -79,8 +102,8 @@ TEST(version_range, createInfinite) { version->micro = 3; mock() - .expectOneCall("version_createEmptyVersion") - .withOutputParameterReturning("version", &version, sizeof("version")); + .expectOneCall("version_createEmptyVersion") + .withOutputParameterReturning("version", &version, sizeof("version")); status = versionRange_createInfiniteVersionRange(&range); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(range != NULL); @@ -88,10 +111,16 @@ TEST(version_range, createInfinite) { LONGS_EQUAL(true, range->isLowInclusive); POINTERS_EQUAL(version, range->low); POINTERS_EQUAL(NULL, range->high); + + mock().expectOneCall("version_destroy"); + + versionRange_destroy(range); + free(version); } TEST(version_range, isInRange) { celix_status_t status = CELIX_SUCCESS; + bool result; version_range_pt range = NULL; version_pt version = (version_pt) malloc(sizeof(*version)); version->major = 1; @@ -108,56 +137,95 @@ TEST(version_range, isInRange) { high->minor = 2; high->micro = 3; - versionRange_createVersionRange(low, true, high, true, &range); - int stat = 1; mock() - .expectOneCall("version_compareTo") - .withParameter("version", version) - .withParameter("compare", low) - .withOutputParameterReturning("result", &stat, sizeof(int)); + .expectNCalls(5, "version_compareTo") + .withParameter("version", version) + .withParameter("compare", low) + .withOutputParameterReturning("result", &stat, sizeof(int)); int stat2 = -1; mock() - .expectOneCall("version_compareTo") - .withParameter("version", version) - .withParameter("compare", high) - .withOutputParameterReturning("result", &stat2, sizeof(int)); + .expectNCalls(4, "version_compareTo") + .withParameter("version", version) + .withParameter("compare", high) + .withOutputParameterReturning("result", &stat2, sizeof(int)); - bool result; - status = versionRange_isInRange(range, version, &result); - LONGS_EQUAL(CELIX_SUCCESS, status); + versionRange_createVersionRange(low, true, high, true, &range); + LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result)); + LONGS_EQUAL(true, result); + mock().expectNCalls(2, "version_destroy"); + versionRange_destroy(range); + + versionRange_createVersionRange(low, true, NULL, true, &range); + LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result)); + LONGS_EQUAL(true, result); + mock().expectOneCall("version_destroy"); + versionRange_destroy(range); + + versionRange_createVersionRange(low, false, high, true, &range); + LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result)); LONGS_EQUAL(true, result); + mock().expectNCalls(2, "version_destroy"); + versionRange_destroy(range); + + versionRange_createVersionRange(low, true, high, false, &range); + LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result)); + LONGS_EQUAL(true, result); + mock().expectNCalls(2, "version_destroy"); + versionRange_destroy(range); + + versionRange_createVersionRange(low, false, high, false, &range); + LONGS_EQUAL(CELIX_SUCCESS, versionRange_isInRange(range, version, &result)); + LONGS_EQUAL(true, result); + mock().expectNCalls(2, "version_destroy"); + versionRange_destroy(range); + + free(version); + free(high); + free(low); } -// This test fails due to ordering of expected calls. -//TEST(version_range, parse) { -// celix_status_t status = CELIX_SUCCESS; -// version_range_pt range = NULL; -// version_pt low = (version_pt) malloc(sizeof(*low)); -// version_pt high = (version_pt) malloc(sizeof(*high)); -// -// low->major = 1; -// low->minor = 2; -// low->micro = 3; -// -// high->major = 7; -// high->minor = 8; -// high->micro = 9; -// -// mock().strictOrder(); -// mock() -// .expectOneCall("version_createVersionFromString") -// .withParameter("versionStr", "7.8.9") -// .withOutputParameterReturning("version", &high, sizeof(high)); -// mock() -// .expectOneCall("version_createVersionFromString") -// .withParameter("versionStr", "1.2.3") -// .withOutputParameterReturning("version", &low, sizeof(low)); -// -// std::string version = "[1.2.3, 7.8.9]"; -// status = versionRange_parse((char *) version.c_str(), &range); -// LONGS_EQUAL(CELIX_SUCCESS, status); -//} +TEST(version_range, parse) { + celix_status_t status = CELIX_SUCCESS; + version_range_pt range = NULL; + version_pt low = (version_pt) malloc(sizeof(*low)); + version_pt high = (version_pt) malloc(sizeof(*high)); + char * version = my_strdup("[1.2.3,7.8.9]"); + low->major = 1; + low->minor = 2; + low->micro = 3; + + high->major = 7; + high->minor = 8; + high->micro = 9; + + mock().expectNCalls(3, "version_destroy"); + + mock().expectOneCall("version_createVersionFromString") + .withParameter("versionStr", "1.2.3") + .withOutputParameterReturning("version", &low, sizeof(low)); + + mock().expectOneCall("version_createVersionFromString") + .withParameter("versionStr", "7.8.9") + .withOutputParameterReturning("version", &high, sizeof(high)); + + LONGS_EQUAL(CELIX_SUCCESS, versionRange_parse(version, &range)); + + versionRange_destroy(range); + free(version); + version = my_strdup("[1.2.3"); + + mock().expectOneCall("version_createVersionFromString") + .withParameter("versionStr", "[1.2.3") + .withOutputParameterReturning("version", &low, sizeof(low)); + + LONGS_EQUAL(CELIX_SUCCESS, versionRange_parse(version, &range)); + + versionRange_destroy(range); + free(version); + free(high); + free(low); +} diff --git a/framework/private/test/version_test.cpp b/framework/private/test/version_test.cpp index 4740f287e..51d734db4 100644 --- a/framework/private/test/version_test.cpp +++ b/framework/private/test/version_test.cpp @@ -28,132 +28,169 @@ #include "CppUTest/TestHarness.h" #include "CppUTest/TestHarness_c.h" #include "CppUTest/CommandLineTestRunner.h" +#include "CppUTestExt/MockSupport.h" extern "C" { #include "version_private.h" #include "celix_log.h" -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x666; } 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; +} + TEST_GROUP(version) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } void teardown() { + mock().checkExpectations(); + mock().clear(); } }; TEST(version, create) { + mock().expectNCalls(2, "framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); version_pt version = NULL; celix_status_t status = CELIX_SUCCESS; - std::string str; + char * str; -// str = "abc"; -// status = version_createVersion(1, 2, 3, strdup((const char *) str.c_str()), &version); +// str = my_strdup("abc"); +// status = version_createVersion(1, 2, 3, str, &version); // LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); - str = "abc"; - status = version_createVersion(1, 2, 3, strdup((const char *) str.c_str()), &version); - LONGS_EQUAL(CELIX_SUCCESS, status); + str = my_strdup("abc"); + LONGS_EQUAL(CELIX_SUCCESS, version_createVersion(1, 2, 3, str, &version)); CHECK_C(version != NULL); LONGS_EQUAL(1, version->major); LONGS_EQUAL(2, version->minor); LONGS_EQUAL(3, version->micro); STRCMP_EQUAL("abc", version->qualifier); + version_destroy(version); version = NULL; - status = version_createVersion(1, 2, 3, NULL, &version); - LONGS_EQUAL(CELIX_SUCCESS, status); + LONGS_EQUAL(CELIX_SUCCESS, version_createVersion(1, 2, 3, NULL, &version)); CHECK_C(version != NULL); LONGS_EQUAL(1, version->major); LONGS_EQUAL(2, version->minor); LONGS_EQUAL(3, version->micro); STRCMP_EQUAL("", version->qualifier); - str = "abc"; - status = version_createVersion(1, -2, 3, strdup((const char *) str.c_str()), &version); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + mock().expectNCalls(4, "framework_log").ignoreOtherParameters(); - str = "abc|xyz"; - status = version_createVersion(1, 2, 3, strdup((const char *) str.c_str()), &version); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + version_destroy(version); + version = NULL; + free(str); + str = my_strdup("abc"); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersion(-1, -2, -3, str, &version)); + + version_destroy(version); + version = NULL; + free(str); + str = my_strdup("abc|xyz"); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersion(1, 2, 3, str, &version)); + + version_destroy(version); + free(str); } TEST(version, clone) { version_pt version = NULL, clone = NULL; celix_status_t status = CELIX_SUCCESS; - std::string str; + char * str; - str = "abc"; - status = version_createVersion(1, 2, 3, strdup((const char *) str.c_str()), &version); - LONGS_EQUAL(CELIX_SUCCESS, status); - status = version_clone(version, &clone); - LONGS_EQUAL(CELIX_SUCCESS, status); + str = my_strdup("abc"); + LONGS_EQUAL(CELIX_SUCCESS, version_createVersion(1, 2, 3, str, &version)); + LONGS_EQUAL(CELIX_SUCCESS, version_clone(version, &clone)); CHECK_C(version != NULL); LONGS_EQUAL(1, clone->major); LONGS_EQUAL(2, clone->minor); LONGS_EQUAL(3, clone->micro); STRCMP_EQUAL("abc", clone->qualifier); + + version_destroy(clone); + version_destroy(version); + free(str); } TEST(version, createFromString) { + mock().expectNCalls(6, "framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); version_pt version = NULL; celix_status_t status = CELIX_SUCCESS; - std::string str; + char * str; - str = "1"; - status = version_createVersionFromString(strdup((const char *) str.c_str()), &version); - LONGS_EQUAL(CELIX_SUCCESS, status); + str = my_strdup("1"); + LONGS_EQUAL(CELIX_SUCCESS, version_createVersionFromString(str, &version)); CHECK_C(version != NULL); LONGS_EQUAL(1, version->major); - str = "a"; - status = version_createVersionFromString(strdup((const char *) str.c_str()), &version); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + version_destroy(version); + mock().expectNCalls(4, "framework_log"); - str = "1.a"; - status = version_createVersionFromString(strdup((const char *) str.c_str()), &version); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + free(str); + str = my_strdup("a"); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString(str, &version)); - str = "1.1.a"; - status = version_createVersionFromString(strdup((const char *) str.c_str()), &version); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + free(str); + str = my_strdup("1.a"); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString(str, &version)); - str = "-1"; - status = version_createVersionFromString(strdup((const char *) str.c_str()), &version); - LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + free(str); + str = my_strdup("1.1.a"); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString(str, &version)); - str = "1.2"; + free(str); + str = my_strdup("-1"); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString(str, &version)); + + free(str); + str = my_strdup("1.2"); version = NULL; - status = version_createVersionFromString(strdup((const char *) str.c_str()), &version); - LONGS_EQUAL(CELIX_SUCCESS, status); + LONGS_EQUAL(CELIX_SUCCESS, version_createVersionFromString(str, &version)); CHECK_C(version != NULL); LONGS_EQUAL(1, version->major); LONGS_EQUAL(2, version->minor); - str = "1.2.3"; + version_destroy(version); + + free(str); + str = my_strdup("1.2.3"); version = NULL; - status = version_createVersionFromString(strdup((const char *) str.c_str()), &version); + status = version_createVersionFromString(str, &version); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(version != NULL); LONGS_EQUAL(1, version->major); LONGS_EQUAL(2, version->minor); LONGS_EQUAL(3, version->micro); - str = "1.2.3.abc"; + version_destroy(version); + free(str); + str = my_strdup("1.2.3.abc"); version = NULL; - status = version_createVersionFromString(strdup((const char *) str.c_str()), &version); + status = version_createVersionFromString(str, &version); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(version != NULL); LONGS_EQUAL(1, version->major); @@ -161,9 +198,11 @@ TEST(version, createFromString) { LONGS_EQUAL(3, version->micro); STRCMP_EQUAL("abc", version->qualifier); - str = "1.2.3.abc_xyz"; + version_destroy(version); + free(str); + str = my_strdup("1.2.3.abc_xyz"); version = NULL; - status = version_createVersionFromString(strdup((const char *) str.c_str()), &version); + status = version_createVersionFromString(str, &version); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(version != NULL); LONGS_EQUAL(1, version->major); @@ -171,9 +210,11 @@ TEST(version, createFromString) { LONGS_EQUAL(3, version->micro); STRCMP_EQUAL("abc_xyz", version->qualifier); - str = "1.2.3.abc-xyz"; + version_destroy(version); + free(str); + str = my_strdup("1.2.3.abc-xyz"); version = NULL; - status = version_createVersionFromString(strdup((const char *) str.c_str()), &version); + status = version_createVersionFromString(str, &version); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(version != NULL); LONGS_EQUAL(1, version->major); @@ -181,9 +222,13 @@ TEST(version, createFromString) { LONGS_EQUAL(3, version->micro); STRCMP_EQUAL("abc-xyz", version->qualifier); - str = "1.2.3.abc|xyz"; - status = version_createVersionFromString(strdup((const char *) str.c_str()), &version); + version_destroy(version); + free(str); + str = my_strdup("1.2.3.abc|xyz"); + status = version_createVersionFromString(str, &version); LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, status); + + free(str); } TEST(version, createEmptyVersion) { @@ -197,17 +242,19 @@ TEST(version, createEmptyVersion) { LONGS_EQUAL(0, version->minor); LONGS_EQUAL(0, version->micro); STRCMP_EQUAL("", version->qualifier); + + version_destroy(version); } TEST(version, getters) { version_pt version = NULL; celix_status_t status = CELIX_SUCCESS; - std::string str; + char * str; int major, minor, micro; char *qualifier; - str = "abc"; - status = version_createVersion(1, 2, 3, strdup((const char *) str.c_str()), &version); + str = my_strdup("abc"); + status = version_createVersion(1, 2, 3, str, &version); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(version != NULL); @@ -222,24 +269,28 @@ TEST(version, getters) { version_getQualifier(version, &qualifier); STRCMP_EQUAL("abc", qualifier); + + version_destroy(version); + free(str); } TEST(version, compare) { version_pt version = NULL, compare = NULL; celix_status_t status = CELIX_SUCCESS; - std::string str; + char * str; int result; // Base version to compare - str = "abc"; - status = version_createVersion(1, 2, 3, strdup((const char *) str.c_str()), &version); + str = my_strdup("abc"); + status = version_createVersion(1, 2, 3, str, &version); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(version != NULL); // Compare equality - str = "abc"; + free(str); + str = my_strdup("abc"); compare = NULL; - status = version_createVersion(1, 2, 3, strdup((const char *) str.c_str()), &compare); + status = version_createVersion(1, 2, 3, str, &compare); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(version != NULL); status = version_compareTo(version, compare, &result); @@ -247,9 +298,11 @@ TEST(version, compare) { LONGS_EQUAL(0, result); // Compare against a higher version - str = "bcd"; + free(str); + str = my_strdup("bcd"); + version_destroy(compare); compare = NULL; - status = version_createVersion(1, 2, 3, strdup((const char *) str.c_str()), &compare); + status = version_createVersion(1, 2, 3, str, &compare); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(version != NULL); status = version_compareTo(version, compare, &result); @@ -257,24 +310,30 @@ TEST(version, compare) { CHECK(result < 0); // Compare againts a lower version - str = "abc"; + free(str); + str = my_strdup("abc"); + version_destroy(compare); compare = NULL; - status = version_createVersion(1, 1, 3, strdup((const char *) str.c_str()), &compare); + status = version_createVersion(1, 1, 3, str, &compare); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(version != NULL); status = version_compareTo(version, compare, &result); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK(result > 0); + + version_destroy(compare); + version_destroy(version); + free(str); } TEST(version, toString) { version_pt version = NULL, compare = NULL; celix_status_t status = CELIX_SUCCESS; - std::string str; + char * str; char *result = NULL; - str = "abc"; - status = version_createVersion(1, 2, 3, strdup((const char *) str.c_str()), &version); + str = my_strdup("abc"); + status = version_createVersion(1, 2, 3, str, &version); LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(version != NULL); @@ -282,7 +341,9 @@ TEST(version, toString) { LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(result != NULL); STRCMP_EQUAL("1.2.3.abc", result); + free(result); + version_destroy(version); version = NULL; status = version_createVersion(1, 2, 3, NULL, &version); LONGS_EQUAL(CELIX_SUCCESS, status); @@ -292,6 +353,10 @@ TEST(version, toString) { LONGS_EQUAL(CELIX_SUCCESS, status); CHECK_C(result != NULL); STRCMP_EQUAL("1.2.3", result); + + version_destroy(version); + free(result); + free(str); } diff --git a/framework/private/test/wire_test.cpp b/framework/private/test/wire_test.cpp index 7ddfc0447..6af4d0112 100644 --- a/framework/private/test/wire_test.cpp +++ b/framework/private/test/wire_test.cpp @@ -19,13 +19,14 @@ /* * wire_test.cpp * - * \date Dec 18, 2012 + * \date Sep 25, 2015 * \author Apache Celix Project Team * \copyright Apache License, Version 2.0 */ #include "CppUTest/TestHarness.h" #include "CppUTest/TestHarness_c.h" #include "CppUTest/CommandLineTestRunner.h" +#include "CppUTestExt/MockSupport.h" extern "C" { @@ -37,7 +38,7 @@ extern "C" #include "requirement.h" #include "capability.h" -framework_logger_pt logger; +framework_logger_pt logger = (framework_logger_pt) 0x42; } int main(int argc, char** argv) { @@ -47,30 +48,53 @@ int main(int argc, char** argv) { TEST_GROUP(wire) { void setup(void) { - logger = (framework_logger_pt) malloc(sizeof(*logger)); - logger->logFunction = frameworkLogger_log; } void teardown() { - free(logger); + mock().checkExpectations(); + mock().clear(); } }; TEST(wire, create) { + mock().expectOneCall("framework_logCode").withParameter("code", CELIX_ILLEGAL_ARGUMENT); + module_pt module = (module_pt) 0x01; capability_pt cap = (capability_pt) 0x02; requirement_pt req = (requirement_pt) 0x03; - + celix_status_t status; wire_pt wire = NULL; - wire_create(module, req, module, cap, &wire); + LONGS_EQUAL(CELIX_SUCCESS, wire_create(module, req, module, cap, &wire)); - LONGS_EQUAL(1, 1); + LONGS_EQUAL(CELIX_ILLEGAL_ARGUMENT, wire_create(module, req, module, cap, &wire)); - wire_destroy(wire); + LONGS_EQUAL(CELIX_SUCCESS, wire_destroy(wire)); } +TEST(wire, get){ + module_pt importer = (module_pt) 0x01; + module_pt exporter = (module_pt) 0x02; + capability_pt cap = (capability_pt) 0x03; + requirement_pt req = (requirement_pt) 0x04; + void * get; + + wire_pt wire = NULL; + + wire_create(importer, req, exporter, cap, &wire); + + wire_getImporter(wire, (module_pt*)&get); + POINTERS_EQUAL(importer, get); + + wire_getExporter(wire, (module_pt*)&get); + POINTERS_EQUAL(exporter, get); + wire_getCapability(wire, (capability_pt*)&get); + POINTERS_EQUAL(cap, get); + wire_getRequirement(wire, (requirement_pt*)&get); + POINTERS_EQUAL(req, get); + wire_destroy(wire); +} diff --git a/framework/public/include/bundle.h b/framework/public/include/bundle.h index 0fb4c3572..44501ccd2 100644 --- a/framework/public/include/bundle.h +++ b/framework/public/include/bundle.h @@ -40,7 +40,7 @@ typedef struct bundle * bundle_pt; #include "celix_log.h" #include "celix_threads.h" -FRAMEWORK_EXPORT celix_status_t bundle_create(bundle_pt * bundle, framework_logger_pt logger); +FRAMEWORK_EXPORT celix_status_t bundle_create(bundle_pt * bundle); FRAMEWORK_EXPORT celix_status_t bundle_createFromArchive(bundle_pt * bundle, framework_pt framework, bundle_archive_pt archive); FRAMEWORK_EXPORT celix_status_t bundle_destroy(bundle_pt bundle); diff --git a/framework/public/include/bundle_archive.h b/framework/public/include/bundle_archive.h index 2ac43c656..e5f22b334 100644 --- a/framework/public/include/bundle_archive.h +++ b/framework/public/include/bundle_archive.h @@ -38,8 +38,8 @@ typedef struct bundleArchive * bundle_archive_pt; -celix_status_t bundleArchive_create(framework_logger_pt logger, char * archiveRoot, long id, char * location, char *inputFile, bundle_archive_pt *bundle_archive); -celix_status_t bundleArchive_createSystemBundleArchive(framework_logger_pt logger, bundle_archive_pt *bundle_archive); +celix_status_t bundleArchive_create(char * archiveRoot, long id, char * location, char *inputFile, bundle_archive_pt *bundle_archive); +celix_status_t bundleArchive_createSystemBundleArchive(bundle_archive_pt *bundle_archive); celix_status_t bundleArchive_recreate(char * archiveRoot, bundle_archive_pt *bundle_archive); celix_status_t bundleArchive_destroy(bundle_archive_pt archive); diff --git a/framework/public/include/bundle_revision.h b/framework/public/include/bundle_revision.h index 3bc019987..6537f64b0 100644 --- a/framework/public/include/bundle_revision.h +++ b/framework/public/include/bundle_revision.h @@ -62,7 +62,7 @@ typedef struct bundleRevision * bundle_revision_pt; * - CELIX_SUCCESS when no errors are encountered. * - CELIX_ENOMEM If allocating memory for bundle_revision failed. */ -celix_status_t bundleRevision_create(framework_logger_pt logger, char *root, char *location, long revisionNr, char *inputFile, bundle_revision_pt *bundle_revision); +celix_status_t bundleRevision_create(char *root, char *location, long revisionNr, char *inputFile, bundle_revision_pt *bundle_revision); celix_status_t bundleRevision_destroy(bundle_revision_pt revision); diff --git a/framework/public/include/service_reference.h b/framework/public/include/service_reference.h index 5eedc30f4..f1e142745 100644 --- a/framework/public/include/service_reference.h +++ b/framework/public/include/service_reference.h @@ -44,6 +44,8 @@ FRAMEWORK_EXPORT celix_status_t serviceReference_getUsingBundles(service_referen FRAMEWORK_EXPORT celix_status_t serviceReference_getProperty(service_reference_pt reference, char *key, char **value); FRAMEWORK_EXPORT celix_status_t serviceReference_getPropertyKeys(service_reference_pt reference, char **keys[], unsigned int *size); +FRAMEWORK_EXPORT celix_status_t serviceReference_getServiceRegistration(service_reference_pt reference, service_registration_pt *registration); + FRAMEWORK_EXPORT celix_status_t serviceReference_equals(service_reference_pt reference, service_reference_pt compareTo, bool *equal); FRAMEWORK_EXPORT unsigned int serviceReference_hashCode(void *referenceP); FRAMEWORK_EXPORT int serviceReference_equals2(void *reference1, void *reference2); diff --git a/framework/public/include/service_registration.h b/framework/public/include/service_registration.h index d2e2c116a..57751549f 100644 --- a/framework/public/include/service_registration.h +++ b/framework/public/include/service_registration.h @@ -38,7 +38,7 @@ typedef struct serviceRegistration * service_registration_pt; FRAMEWORK_EXPORT celix_status_t serviceRegistration_unregister(service_registration_pt registration); - +FRAMEWORK_EXPORT celix_status_t serviceRegistration_getProperties(service_registration_pt registration, properties_pt *properties); FRAMEWORK_EXPORT celix_status_t serviceRegistration_setProperties(service_registration_pt registration, properties_pt properties); FRAMEWORK_EXPORT celix_status_t serviceRegistration_getServiceReferences(service_registration_pt registration, array_list_pt *references); diff --git a/framework/tst/CMakeLists.txt b/framework/tst/CMakeLists.txt index a786b4149..98cfb34ba 100644 --- a/framework/tst/CMakeLists.txt +++ b/framework/tst/CMakeLists.txt @@ -38,5 +38,5 @@ configure_file(framework1.properties.in framework1.properties @ONLY) configure_file(framework2.properties.in framework2.properties @ONLY) add_test(NAME run_test_framework COMMAND test_framework) -SETUP_TARGET_FOR_COVERAGE(test_framework_cov test_framework ${CMAKE_BINARY_DIR}/coverage/framework) +SETUP_TARGET_FOR_COVERAGE(test_framework_cov test_framework ${CMAKE_BINARY_DIR}/coverage/framework/framework) diff --git a/log_service/private/src/log.c b/log_service/private/src/log.c index a6c3887f6..201c29dff 100644 --- a/log_service/private/src/log.c +++ b/log_service/private/src/log.c @@ -222,7 +222,7 @@ celix_status_t log_bundleChanged(void *listener, bundle_event_pt event) { } celix_status_t log_frameworkEvent(void *listener, framework_event_pt event) { - celix_status_t status; + celix_status_t status = CELIX_SUCCESS; log_pt logger = ((framework_listener_pt) listener)->handle; log_entry_pt entry = NULL; @@ -235,7 +235,7 @@ celix_status_t log_frameworkEvent(void *listener, framework_event_pt event) { } celix_status_t log_addLogListener(log_pt logger, log_listener_pt listener) { - celix_status_t status; + celix_status_t status = CELIX_SUCCESS; status = celixThreadMutex_lock(&logger->listenerLock); @@ -280,7 +280,7 @@ celix_status_t log_removeLogListener(log_pt logger, log_listener_pt listener) { } celix_status_t log_removeAllLogListener(log_pt logger) { - celix_status_t status; + celix_status_t status = CELIX_SUCCESS; status = celixThreadMutex_lock(&logger->listenerLock); @@ -294,7 +294,7 @@ celix_status_t log_removeAllLogListener(log_pt logger) { } static celix_status_t log_startListenerThread(log_pt logger) { - celix_status_t status; + celix_status_t status = CELIX_SUCCESS; logger->running = true; logger->running = true; @@ -304,7 +304,7 @@ static celix_status_t log_startListenerThread(log_pt logger) { } static celix_status_t log_stopListenerThread(log_pt logger) { - celix_status_t status; + celix_status_t status = CELIX_SUCCESS; logger->running = false; diff --git a/log_service/public/src/log_helper.c b/log_service/public/src/log_helper.c index 69ea3eb4d..0b17a3634 100644 --- a/log_service/public/src/log_helper.c +++ b/log_service/public/src/log_helper.c @@ -84,7 +84,7 @@ celix_status_t logHelper_create(bundle_context_pt context, log_helper_pt* loghel celix_status_t logHelper_start(log_helper_pt loghelper) { - celix_status_t status; + celix_status_t status = CELIX_SUCCESS; service_tracker_customizer_pt logTrackerCustomizer = NULL; status = serviceTrackerCustomizer_create(loghelper, NULL, logHelper_logServiceAdded, NULL, logHelper_logServiceRemoved, &logTrackerCustomizer); @@ -126,7 +126,7 @@ celix_status_t logHelper_logServiceRemoved(void *handle, service_reference_pt re celix_status_t logHelper_stop(log_helper_pt loghelper) { - celix_status_t status; + celix_status_t status = CELIX_SUCCESS; status = serviceTracker_close(loghelper->logServiceTracker); diff --git a/remote_services/discovery/private/include/endpoint_discovery_poller.h b/remote_services/discovery/private/include/endpoint_discovery_poller.h index 1bb667915..d344e5544 100644 --- a/remote_services/discovery/private/include/endpoint_discovery_poller.h +++ b/remote_services/discovery/private/include/endpoint_discovery_poller.h @@ -51,5 +51,6 @@ celix_status_t endpointDiscoveryPoller_destroy(endpoint_discovery_poller_pt poll celix_status_t endpointDiscoveryPoller_addDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url); celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discovery_poller_pt poller, char *url); +celix_status_t endpointDiscoveryPoller_getDiscoveryEndpoints(endpoint_discovery_poller_pt poller, array_list_pt urls); #endif /* ENDPOINT_DISCOVERY_POLLER_H_ */ diff --git a/remote_services/discovery/private/src/endpoint_discovery_poller.c b/remote_services/discovery/private/src/endpoint_discovery_poller.c index ec0a1b39b..60a923643 100644 --- a/remote_services/discovery/private/src/endpoint_discovery_poller.c +++ b/remote_services/discovery/private/src/endpoint_discovery_poller.c @@ -242,7 +242,7 @@ celix_status_t endpointDiscoveryPoller_removeDiscoveryEndpoint(endpoint_discover celix_status_t endpointDiscoveryPoller_poll(endpoint_discovery_poller_pt poller, char *url, array_list_pt currentEndpoints) { - celix_status_t status; + celix_status_t status = NULL; array_list_pt updatedEndpoints = NULL; // create an arraylist with a custom equality test to ensure we can find endpoints properly... diff --git a/remote_services/discovery_etcd/private/src/etcd_watcher.c b/remote_services/discovery_etcd/private/src/etcd_watcher.c index b9b3ef8e7..2166a3eed 100644 --- a/remote_services/discovery_etcd/private/src/etcd_watcher.c +++ b/remote_services/discovery_etcd/private/src/etcd_watcher.c @@ -227,7 +227,7 @@ static celix_status_t etcdWatcher_removeEntry(etcd_watcher_pt watcher, char* key hash_map_entry_pt entry = hashMap_getEntry(watcher->entries, key); if (entry != NULL) { - hashMap_removeEntryForKey(watcher->entries, key); + hashMap_remove(watcher->entries, key); free(hashMapEntry_getKey(entry)); free(hashMapEntry_getValue(entry)); diff --git a/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt b/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt index ea797680c..aed134caa 100644 --- a/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt +++ b/remote_services/remote_service_admin_dfi/dynamic_function_interface/CMakeLists.txt @@ -34,4 +34,8 @@ add_library(dfi STATIC json_rpc.c ${MEMSTREAM_SOURCES} ) -target_link_libraries(dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY}) \ No newline at end of file +target_link_libraries(dfi ${FFI_LIBRARIES} ${JANSSON_LIBRARY}) + +install(TARGETS dfi DESTINATION lib) +FILE(GLOB files "*.h") +INSTALL(FILES ${files} DESTINATION include/celix/dfi) diff --git a/remote_services/topology_manager/private/src/topology_manager.c b/remote_services/topology_manager/private/src/topology_manager.c index acc694120..7711d53ea 100644 --- a/remote_services/topology_manager/private/src/topology_manager.c +++ b/remote_services/topology_manager/private/src/topology_manager.c @@ -287,6 +287,9 @@ celix_status_t topologyManager_rsaRemoved(void * handle, service_reference_pt re topologyManager_notifyListenersEndpointRemoved(manager, rsa, export); rsa->exportRegistration_close(export); } + + arrayList_destroy(exports_list); + exports_list = NULL; } hashMap_remove(exports, rsa); diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 4d4b013b8..095c9e846 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -80,7 +80,7 @@ if (UTILS) #ADD_TARGET_FOR_TEST(array_list_test) add_test(NAME run_array_list_test COMMAND array_list_test) - SETUP_TARGET_FOR_COVERAGE(array_list array_list_test ${CMAKE_BINARY_DIR}/coverage/array_list_test/array_list_test) + SETUP_TARGET_FOR_COVERAGE(array_list_test array_list_test ${CMAKE_BINARY_DIR}/coverage/array_list_test/array_list_test) #ADD_TARGET_FOR_TEST(hash_map_test) add_test(NAME run_hash_map_test COMMAND hash_map_test) @@ -88,11 +88,11 @@ if (UTILS) #ADD_TARGET_FOR_TEST(celix_threads_test) add_test(NAME run_celix_threads_test COMMAND celix_threads_test) - SETUP_TARGET_FOR_COVERAGE(celix_threads celix_threads_test ${CMAKE_BINARY_DIR}/coverage/celix_threads_test/celix_threads_test) + SETUP_TARGET_FOR_COVERAGE(celix_threads_test celix_threads_test ${CMAKE_BINARY_DIR}/coverage/celix_threads_test/celix_threads_test) #ADD_TARGET_FOR_TEST(linked_list_test) add_test(NAME run_linked_list_test COMMAND linked_list_test) - SETUP_TARGET_FOR_COVERAGE(linked_list linked_list_test ${CMAKE_BINARY_DIR}/coverage/linked_list_test/linked_list_test) + SETUP_TARGET_FOR_COVERAGE(linked_list_test linked_list_test ${CMAKE_BINARY_DIR}/coverage/linked_list_test/linked_list_test) endif(ENABLE_TESTING) endif (UTILS) diff --git a/utils/public/include/celix_threads.h b/utils/public/include/celix_threads.h index 2eed5df46..c59edef04 100644 --- a/utils/public/include/celix_threads.h +++ b/utils/public/include/celix_threads.h @@ -52,7 +52,7 @@ void celixThread_exit(void *exitStatus); celix_status_t celixThread_detach(celix_thread_t thread); celix_status_t celixThread_join(celix_thread_t thread, void **status); celix_status_t celixThread_kill(celix_thread_t thread, int sig); -celix_thread_t celixThread_self(); +celix_thread_t celixThread_self(void); int celixThread_equals(celix_thread_t thread1, celix_thread_t thread2); bool celixThread_initalized(celix_thread_t thread);