This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/509-remove-deprecated-version in repository https://gitbox.apache.org/repos/asf/celix.git
commit 63fa8b1a62ffa8ca6af0c08d6553ff13666f0090 Author: Pepijn Noltes <[email protected]> AuthorDate: Thu Jan 4 15:49:44 2024 +0100 Remove deprecated version.h and version_range.h --- .../src/import_registration_dfi.c | 26 +- libs/dfi/gtest/src/dyn_interface_tests.cpp | 11 +- libs/dfi/gtest/src/dyn_message_tests.cpp | 12 +- libs/framework/include_deprecated/module.h | 3 +- libs/framework/src/manifest_parser.c | 15 +- libs/framework/src/manifest_parser.h | 4 +- libs/framework/src/module.c | 48 ++-- libs/framework/src/service_registry.c | 2 +- libs/utils/gtest/src/VersionRangeTestSuite.cc | 264 +++++++++------------ libs/utils/gtest/src/VersionTestSuite.cc | 189 ++++----------- libs/utils/include_deprecated/celix_utils_api.h | 4 +- libs/utils/include_deprecated/version.h | 181 -------------- libs/utils/include_deprecated/version_range.h | 174 -------------- libs/utils/src/version.c | 69 ------ libs/utils/src/version_range.c | 103 +------- 15 files changed, 227 insertions(+), 878 deletions(-) diff --git a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c index 5cc0327e..d45ea961 100644 --- a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c +++ b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c @@ -20,7 +20,7 @@ #include <stdlib.h> #include <json_rpc.h> #include <assert.h> -#include "version.h" +#include "celix_version.h" #include "dyn_interface.h" #include "import_registration.h" #include "import_registration_dfi.h" @@ -32,7 +32,7 @@ struct import_registration { celix_bundle_context_t *context; endpoint_description_t * endpoint; //TODO owner? -> free when destroyed const char *classObject; //NOTE owned by endpoint - version_pt version; + celix_version_t* version; send_func_type send; void *sendHandle; @@ -75,7 +75,6 @@ celix_status_t importRegistration_create( void* sendFnHandle, FILE *logFile, import_registration_t **out) { - celix_status_t status = CELIX_SUCCESS; import_registration_t *reg = calloc(1, sizeof(*reg)); reg->context = context; reg->endpoint = endpoint; @@ -87,7 +86,7 @@ celix_status_t importRegistration_create( remoteInterceptorsHandler_create(context, ®->interceptorsHandler); celixThreadMutex_create(®->proxiesMutex, NULL); - status = version_createVersionFromString((char*)serviceVersion,&(reg->version)); + reg->version = celix_version_createVersionFromString((char*)serviceVersion); reg->factorySvcId = -1; reg->factory.handle = reg; @@ -96,14 +95,15 @@ celix_status_t importRegistration_create( reg->logFile = logFile; - if (status == CELIX_SUCCESS) { + if (reg && reg->version && reg->proxies && reg->interceptorsHandler) { //printf("IMPORT REGISTRATION IS %p\n", reg); *out = reg; + return CELIX_ENOMEM; } else { importRegistration_destroy(reg); } - return status; + return CELIX_SUCCESS; } static void importRegistration_clearProxies(import_registration_t *import) { @@ -134,9 +134,7 @@ static void importRegistration_destroyCallback(void* data) { pthread_mutex_destroy(&import->proxiesMutex); - if (import->version != NULL) { - version_destroy(import->version); - } + celix_version_destroy(import->version); free(import); } @@ -230,16 +228,14 @@ static celix_status_t importRegistration_createProxy(import_registration_t *impo } /* Check if the imported service version is compatible with the one in the consumer descriptor */ - version_pt consumerVersion = NULL; + celix_version_t* consumerVersion = NULL; bool isCompatible = false; dynInterface_getVersion(intf,&consumerVersion); - version_isCompatible(consumerVersion,import->version,&isCompatible); + isCompatible = celix_version_isCompatible(consumerVersion, import->version); if(!isCompatible){ - char* cVerString = NULL; - char* pVerString = NULL; - version_toString(consumerVersion,&cVerString); - version_toString(import->version,&pVerString); + char* cVerString = celix_version_toString(consumerVersion); + char* pVerString = celix_version_toString(import->version); printf("Service version mismatch: consumer has %s, provider has %s. NOT creating proxy.\n",cVerString,pVerString); dynInterface_destroy(intf); free(cVerString); diff --git a/libs/dfi/gtest/src/dyn_interface_tests.cpp b/libs/dfi/gtest/src/dyn_interface_tests.cpp index 2ddaa147..40e9c732 100644 --- a/libs/dfi/gtest/src/dyn_interface_tests.cpp +++ b/libs/dfi/gtest/src/dyn_interface_tests.cpp @@ -33,7 +33,7 @@ extern "C" { #include "dyn_common.h" #include "dyn_interface.h" -#include "version.h" +#include "celix_version.h" #if NO_MEMSTREAM_AVAILABLE #include "open_memstream.h" @@ -57,14 +57,13 @@ extern "C" { status = dynInterface_getVersionString(dynIntf, &version); ASSERT_EQ(0, status); ASSERT_STREQ(v, version); - version_pt msgVersion = NULL, localMsgVersion = NULL; - int cmpVersion = -1; - version_createVersionFromString(version, &localMsgVersion); + celix_version_t* msgVersion = nullptr; + celix_version_t* localMsgVersion = localMsgVersion = celix_version_createVersionFromString(version); status = dynInterface_getVersion(dynIntf, &msgVersion); ASSERT_EQ(0, status); - version_compareTo(msgVersion, localMsgVersion, &cmpVersion); + int cmpVersion = celix_version_compareTo(msgVersion, localMsgVersion); ASSERT_EQ(cmpVersion, 0); - version_destroy(localMsgVersion); + celix_version_destroy(localMsgVersion); } static void test1(void) { diff --git a/libs/dfi/gtest/src/dyn_message_tests.cpp b/libs/dfi/gtest/src/dyn_message_tests.cpp index 4c1d242d..72d153a0 100644 --- a/libs/dfi/gtest/src/dyn_message_tests.cpp +++ b/libs/dfi/gtest/src/dyn_message_tests.cpp @@ -20,7 +20,7 @@ #include "gtest/gtest.h" #include <stdarg.h> -#include "version.h" +#include "celix_version.h" extern "C" { @@ -57,15 +57,13 @@ static void checkMessageVersion(dyn_message_type* dynMsg, const char* v){ status = dynMessage_getVersionString(dynMsg, &version); ASSERT_EQ(0, status); ASSERT_STREQ(v, version); - version_pt msgVersion = NULL, localMsgVersion = NULL; - int cmpVersion = -1; - version_createVersionFromString(version,&localMsgVersion); + celix_version_t* msgVersion = nullptr; + celix_version_t* localMsgVersion = celix_version_createVersionFromString(version); status = dynMessage_getVersion(dynMsg,&msgVersion); ASSERT_EQ(0, status); - version_compareTo(msgVersion,localMsgVersion,&cmpVersion); + int cmpVersion = celix_version_compareTo(msgVersion, localMsgVersion); ASSERT_EQ(cmpVersion,0); - version_destroy(localMsgVersion); - + celix_version_destroy(localMsgVersion); } diff --git a/libs/framework/include_deprecated/module.h b/libs/framework/include_deprecated/module.h index 3c09f666..b0185bf2 100644 --- a/libs/framework/include_deprecated/module.h +++ b/libs/framework/include_deprecated/module.h @@ -34,7 +34,6 @@ typedef struct module celix_module_t; #include "linked_list.h" #include "manifest.h" -#include "version.h" #include "array_list.h" #include "bundle.h" #include "celix_framework_export.h" @@ -53,7 +52,7 @@ CELIX_FRAMEWORK_DEPRECATED_EXPORT unsigned int module_hash(void *module); CELIX_FRAMEWORK_DEPRECATED_EXPORT int module_equals(void *module, void *compare); -CELIX_FRAMEWORK_DEPRECATED_EXPORT version_pt module_getVersion(module_pt module); +CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_version_t* module_getVersion(module_pt module); CELIX_FRAMEWORK_DEPRECATED_EXPORT celix_status_t module_getSymbolicName(module_pt module, const char **symbolicName); diff --git a/libs/framework/src/manifest_parser.c b/libs/framework/src/manifest_parser.c index cef149be..5733a02f 100644 --- a/libs/framework/src/manifest_parser.c +++ b/libs/framework/src/manifest_parser.c @@ -37,7 +37,7 @@ struct manifestParser { module_pt owner; manifest_pt manifest; - version_pt bundleVersion; + celix_version_t* bundleVersion; //TODO: Implement Requirement-Capability-Model using RCM library }; @@ -54,11 +54,9 @@ celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, mani bundleVersion = manifest_getValue(manifest, CELIX_FRAMEWORK_BUNDLE_VERSION); if (bundleVersion != NULL) { - parser->bundleVersion = NULL; - version_createVersionFromString(bundleVersion, &parser->bundleVersion); + parser->bundleVersion = celix_version_createVersionFromString(bundleVersion); } else { - parser->bundleVersion = NULL; - version_createEmptyVersion(&parser->bundleVersion); + parser->bundleVersion = celix_version_createEmptyVersion(); } *manifest_parser = parser; @@ -74,7 +72,7 @@ celix_status_t manifestParser_create(module_pt owner, manifest_pt manifest, mani } celix_status_t manifestParser_destroy(manifest_parser_pt mp) { - version_destroy(mp->bundleVersion); + celix_version_destroy(mp->bundleVersion); mp->bundleVersion = NULL; mp->manifest = NULL; mp->owner = NULL; @@ -110,6 +108,7 @@ celix_status_t manifestParser_getAndDuplicateDescription(manifest_parser_pt pars return manifestParser_getDuplicateEntry(parser, CELIX_FRAMEWORK_BUNDLE_DESCRIPTION, description); } -celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, version_pt *version) { - return version_clone(parser->bundleVersion, version); +celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, celix_version_t **version) { + *version = celix_version_copy(parser->bundleVersion); + return *version == NULL ? CELIX_ENOMEM : CELIX_SUCCESS; } \ No newline at end of file diff --git a/libs/framework/src/manifest_parser.h b/libs/framework/src/manifest_parser.h index f19de356..0557285a 100644 --- a/libs/framework/src/manifest_parser.h +++ b/libs/framework/src/manifest_parser.h @@ -28,7 +28,7 @@ #define MANIFEST_PARSER_H_ #include "module.h" -#include "version.h" +#include "celix_version.h" #include "manifest.h" #include "linked_list.h" @@ -40,7 +40,7 @@ celix_status_t manifestParser_destroy(manifest_parser_pt mp); celix_status_t manifestParser_getAndDuplicateSymbolicName(manifest_parser_pt parser, char **symbolicName); celix_status_t manifestParser_getAndDuplicateName(manifest_parser_pt parser, char **name); celix_status_t manifestParser_getAndDuplicateDescription(manifest_parser_pt parser, char **description); -celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, version_pt *version); +celix_status_t manifestParser_getBundleVersion(manifest_parser_pt parser, celix_version_t **version); celix_status_t manifestParser_getAndDuplicateGroup(manifest_parser_pt parser, char **group); #endif /* MANIFEST_PARSER_H_ */ diff --git a/libs/framework/src/module.c b/libs/framework/src/module.c index 0ff49057..810cd112 100644 --- a/libs/framework/src/module.c +++ b/libs/framework/src/module.c @@ -48,18 +48,18 @@ struct module { celix_framework_t* fw; - version_pt version; - char* symbolicName; - char* group; + celix_version_t* version; + char* symbolicName; + char* group; char* name; char* description; - bool resolved; + bool resolved; - char * id; + char* id; - celix_bundle_t *bundle; + celix_bundle_t* bundle; - celix_thread_mutex_t handlesLock; //protects libraryHandles and bundleActivatorHandle + celix_thread_mutex_t handlesLock; // protects libraryHandles and bundleActivatorHandle celix_array_list_t* libraryHandles; void* bundleActivatorHandle; }; @@ -106,42 +106,38 @@ module_pt module_create(manifest_pt headerMap, const char * moduleId, bundle_pt module_pt module_createFrameworkModule(celix_framework_t* fw, bundle_pt bundle) { module_pt module; - module = (module_pt) calloc(1, sizeof(*module)); + module = (module_pt)calloc(1, sizeof(*module)); char modId[2]; snprintf(modId, 2, "%li", CELIX_FRAMEWORK_BUNDLE_ID); - if (module) { + if (module) { module->fw = fw; module->id = celix_utils_strdup(modId); module->symbolicName = celix_utils_strdup("celix_framework"); module->group = celix_utils_strdup("Celix/Framework"); module->name = celix_utils_strdup("Celix Framework"); module->description = celix_utils_strdup("The Celix Framework System Bundle"); - module->version = NULL; - version_createVersion(1, 0, 0, "", &module->version); + module->version = celix_version_create(1, 0, 0, ""); module->resolved = false; module->bundle = bundle; celixThreadMutex_create(&module->handlesLock, NULL); module->libraryHandles = celix_arrayList_create(); - } - return module; + } + return module; } void module_destroy(module_pt module) { - - version_destroy(module->version); - free(module->id); - free(module->symbolicName); - free(module->name); - free(module->group); - free(module->description); - celix_arrayList_destroy(module->libraryHandles); - celixThreadMutex_destroy(&module->handlesLock); - free(module); + celix_version_destroy(module->version); + free(module->id); + free(module->symbolicName); + free(module->name); + free(module->group); + free(module->description); + celix_arrayList_destroy(module->libraryHandles); + celixThreadMutex_destroy(&module->handlesLock); + free(module); } -version_pt module_getVersion(module_pt module) { - return module->version; -} +celix_version_t* module_getVersion(module_pt module) { return module->version; } celix_status_t module_getSymbolicName(module_pt module, const char **symbolicName) { celix_status_t status = CELIX_SUCCESS; diff --git a/libs/framework/src/service_registry.c b/libs/framework/src/service_registry.c index c84fe27c..b95e481e 100644 --- a/libs/framework/src/service_registry.c +++ b/libs/framework/src/service_registry.c @@ -830,7 +830,7 @@ char* celix_serviceRegistry_createFilterFor(celix_service_registry_t* registry, "Error incorrect version range."); return NULL; } - versionRange = versionRange_createLDAPFilter(range, CELIX_FRAMEWORK_SERVICE_VERSION); + versionRange = celix_versionRange_createLDAPFilter(range, CELIX_FRAMEWORK_SERVICE_VERSION); if (versionRange == NULL) { celix_framework_log(registry->framework->logger, CELIX_LOG_LEVEL_ERROR, __FUNCTION__, __BASE_FILE__, __LINE__, "Error creating LDAP filter."); diff --git a/libs/utils/gtest/src/VersionRangeTestSuite.cc b/libs/utils/gtest/src/VersionRangeTestSuite.cc index 2c44a79f..857f3c6e 100644 --- a/libs/utils/gtest/src/VersionRangeTestSuite.cc +++ b/libs/utils/gtest/src/VersionRangeTestSuite.cc @@ -19,42 +19,35 @@ #include <gtest/gtest.h> -#include "version.h" -#include "version_range.h" //NOTE testing celix_version_range through the deprecated version_range api. +#include "celix_version.h" +#include "celix_version_range.h" #include "celix_stdlib_cleanup.h" #include "celix_version_range.h" #include "version_private.h" class VersionRangeTestSuite : public ::testing::Test {}; -TEST_F(VersionRangeTestSuite, create) { - celix_status_t status = CELIX_SUCCESS; - version_range_pt range = nullptr; - version_pt low = celix_version_createEmptyVersion(); - version_pt high = celix_version_createEmptyVersion(); - - status = versionRange_createVersionRange(low, false, high, true, &range); - EXPECT_EQ(CELIX_SUCCESS, status); +TEST_F(VersionRangeTestSuite, CreateTest) { + celix_version_range_t* range = nullptr; + celix_version_t* low = celix_version_createEmptyVersion(); + celix_version_t* high = celix_version_createEmptyVersion(); + range = celix_versionRange_createVersionRange(low, false, high, true); EXPECT_TRUE((range != nullptr)); EXPECT_EQ(true, celix_versionRange_isHighInclusive(range)); EXPECT_EQ(false, celix_versionRange_isLowInclusive(range)); EXPECT_EQ(low, celix_versionRange_getLowVersion(range)); EXPECT_EQ(high, celix_versionRange_getHighVersion(range)); - versionRange_destroy(range); + celix_versionRange_destroy(range); } -TEST_F(VersionRangeTestSuite, cleanup) { +TEST_F(VersionRangeTestSuite, CleanupTest) { celix_autoptr(celix_version_range_t) range = celix_versionRange_createInfiniteVersionRange(); } -TEST_F(VersionRangeTestSuite, createInfinite) { - celix_status_t status = CELIX_SUCCESS; - version_range_pt range = nullptr; - version_pt version = celix_version_create(1,2, 3, nullptr); - - status = versionRange_createInfiniteVersionRange(&range); - EXPECT_EQ(CELIX_SUCCESS, status); +TEST_F(VersionRangeTestSuite, CreateInfiniteTest) { + celix_version_t* version = celix_version_create(1,2, 3, nullptr); + celix_version_range_t* range = celix_versionRange_createInfiniteVersionRange(); EXPECT_TRUE(range != nullptr); EXPECT_EQ(true, celix_versionRange_isHighInclusive(range)); EXPECT_EQ(true, celix_versionRange_isLowInclusive(range)); @@ -64,360 +57,339 @@ TEST_F(VersionRangeTestSuite, createInfinite) { EXPECT_EQ(std::string{celix_version_getQualifier(celix_versionRange_getLowVersion(range))}, std::string{""}); EXPECT_EQ(nullptr, celix_versionRange_getHighVersion(range)); - versionRange_destroy(range); + celix_versionRange_destroy(range); celix_version_destroy(version); } -TEST_F(VersionRangeTestSuite, isInRange) { - bool result; - version_pt version = celix_version_create(1, 2, 3, nullptr); +TEST_F(VersionRangeTestSuite, IsInRangeTest) { + celix_version_t* version = celix_version_create(1, 2, 3, nullptr); { - version_range_pt range = nullptr; - - version_pt low = (version_pt) calloc(1, sizeof(*low)); + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; low->qualifier = nullptr; - version_pt high = (version_pt) calloc(1, sizeof(*high)); + celix_version_t* high = (celix_version_t*) calloc(1, sizeof(*high)); high->major = 1; high->minor = 2; high->micro = 3; high->qualifier = nullptr; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, true, high, true, &range)); - EXPECT_EQ(CELIX_SUCCESS, versionRange_isInRange(range, version, &result)); - EXPECT_EQ(true, result); - - versionRange_destroy(range); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, true, high, true); + EXPECT_TRUE(range != nullptr); + EXPECT_TRUE(celix_versionRange_isInRange(range, version)); + celix_versionRange_destroy(range); } { - version_range_pt range = nullptr; - - version_pt low = (version_pt) calloc(1, sizeof(*low)); + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, true, nullptr, true, &range)); - EXPECT_EQ(CELIX_SUCCESS, versionRange_isInRange(range, version, &result)); - EXPECT_EQ(true, result); - - versionRange_destroy(range); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, true, nullptr, true); + EXPECT_TRUE(range != nullptr); + EXPECT_TRUE(celix_versionRange_isInRange(range, version)); + celix_versionRange_destroy(range); } { - version_range_pt range = nullptr; - - version_pt low = (version_pt) calloc(1, sizeof(*low)); + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; - version_pt high = (version_pt) calloc(1, sizeof(*high)); + celix_version_t* high = (celix_version_t*) calloc(1, sizeof(*high)); high->major = 1; high->minor = 2; high->micro = 3; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, false, high, true, &range)); - EXPECT_EQ(CELIX_SUCCESS, versionRange_isInRange(range, version, &result)); - EXPECT_EQ(false, result); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, false, high, true); + EXPECT_TRUE(range != nullptr); + EXPECT_FALSE(celix_versionRange_isInRange(range, version)); - versionRange_destroy(range); + celix_versionRange_destroy(range); } { - version_range_pt range = nullptr; - - version_pt low = (version_pt) calloc(1, sizeof(*low)); + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; - version_pt high = (version_pt) calloc(1, sizeof(*high)); + celix_version_t* high = (celix_version_t*) calloc(1, sizeof(*high)); high->major = 1; high->minor = 2; high->micro = 3; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, true, high, false, &range)); - EXPECT_EQ(CELIX_SUCCESS, versionRange_isInRange(range, version, &result)); - EXPECT_EQ(false, result); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, true, high, false); + EXPECT_TRUE(range != nullptr); + EXPECT_FALSE(celix_versionRange_isInRange(range, version)); - versionRange_destroy(range); + celix_versionRange_destroy(range); } { - version_range_pt range = nullptr; - - version_pt low = (version_pt) calloc(1, sizeof(*low)); + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; - version_pt high = (version_pt) calloc(1, sizeof(*high)); + celix_version_t* high = (celix_version_t*) calloc(1, sizeof(*high)); high->major = 1; high->minor = 2; high->micro = 3; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, false, high, false, &range)); - EXPECT_EQ(CELIX_SUCCESS, versionRange_isInRange(range, version, &result)); - EXPECT_EQ(false, result); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, false, high, false); + EXPECT_TRUE(range != nullptr); + EXPECT_FALSE(celix_versionRange_isInRange(range, version)); - versionRange_destroy(range); + celix_versionRange_destroy(range); } celix_version_destroy(version); } -TEST_F(VersionRangeTestSuite, parse) { - version_range_pt range = nullptr; - char * version = strdup("[1.2.3,7.8.9]"); - - EXPECT_EQ(CELIX_SUCCESS, versionRange_parse(version, &range)); - - versionRange_destroy(range); - free(version); - version = strdup("[1.2.3"); - - EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, versionRange_parse(version, &range)); +TEST_F(VersionRangeTestSuite, ParseTest) { + const char* version = "[1.2.3,7.8.9]"; + celix_version_range_t* range = celix_versionRange_parse(version); + EXPECT_TRUE(range != nullptr); + celix_versionRange_destroy(range); - free(version); + version = "[1.2.3"; + EXPECT_TRUE(celix_versionRange_parse(version) == nullptr); - EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, versionRange_parse("[2.2.3,a.b.c)", &range)); + EXPECT_TRUE(celix_versionRange_parse("[2.2.3,a.b.c)") == nullptr); } -TEST_F(VersionRangeTestSuite, createLdapFilterInclusiveBoth) { - version_pt low = (version_pt) calloc(1, sizeof(*low)); +TEST_F(VersionRangeTestSuite, CreateLdapFilterInclusiveBothTest) { + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; low->qualifier = nullptr; - version_pt high = (version_pt) calloc(1, sizeof(*high)); + celix_version_t* high = (celix_version_t*) calloc(1, sizeof(*high)); high->major = 1; high->minor = 2; high->micro = 3; high->qualifier = nullptr; - version_range_pt range = nullptr; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, true, high, true, &range)); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, true, high, true); + EXPECT_TRUE(range != nullptr); - auto filter = versionRange_createLDAPFilter(range, "service.version"); + auto filter = celix_versionRange_createLDAPFilter(range, "service.version"); EXPECT_EQ(std::string{filter}, std::string{"(&(service.version>=1.2.3)(service.version<=1.2.3))"}); - versionRange_destroy(range); + celix_versionRange_destroy(range); free(filter); } -TEST_F(VersionRangeTestSuite, createLdapFilterInclusiveLow) { - version_pt low = (version_pt) calloc(1, sizeof(*low)); +TEST_F(VersionRangeTestSuite, CreateLdapFilterInclusiveLowTest) { + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; low->qualifier = nullptr; - version_pt high = (version_pt) calloc(1, sizeof(*high)); + celix_version_t* high = (celix_version_t*) calloc(1, sizeof(*high)); high->major = 1; high->minor = 2; high->micro = 3; high->qualifier = nullptr; - version_range_pt range = nullptr; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, false, high, true, &range)); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, false, high, true); + EXPECT_TRUE(range != nullptr); - auto filter = versionRange_createLDAPFilter(range, "service.version"); + auto filter = celix_versionRange_createLDAPFilter(range, "service.version"); EXPECT_STREQ(filter, "(&(service.version>1.2.3)(service.version<=1.2.3))"); - versionRange_destroy(range); + celix_versionRange_destroy(range); free(filter); } -TEST_F(VersionRangeTestSuite, createLdapFilterInclusiveHigh) { - version_pt low = (version_pt) calloc(1, sizeof(*low)); +TEST_F(VersionRangeTestSuite, CreateLdapFilterInclusiveHighTest) { + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; low->qualifier = nullptr; - version_pt high = (version_pt) calloc(1, sizeof(*high)); + celix_version_t* high = (celix_version_t*) calloc(1, sizeof(*high)); high->major = 1; high->minor = 2; high->micro = 3; high->qualifier = nullptr; - version_range_pt range = nullptr; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, true, high, false, &range)); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, true, high, false); + EXPECT_TRUE(range != nullptr); - auto filter = versionRange_createLDAPFilter(range, "service.version"); + auto filter = celix_versionRange_createLDAPFilter(range, "service.version"); EXPECT_STREQ(filter, "(&(service.version>=1.2.3)(service.version<1.2.3))"); - versionRange_destroy(range); + celix_versionRange_destroy(range); free(filter); } -TEST_F(VersionRangeTestSuite, createLdapFilterExclusiveBoth) { - version_pt low = (version_pt) calloc(1, sizeof(*low)); +TEST_F(VersionRangeTestSuite, CreateLdapFilterExclusiveBothTest) { + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; low->qualifier = nullptr; - version_pt high = (version_pt) calloc(1, sizeof(*high)); + celix_version_t* high = (celix_version_t*) calloc(1, sizeof(*high)); high->major = 1; high->minor = 2; high->micro = 3; high->qualifier = nullptr; - version_range_pt range = nullptr; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, false, high, false, &range)); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, false, high, false); + EXPECT_TRUE(range != nullptr); - auto filter = versionRange_createLDAPFilter(range, "service.version"); + auto filter = celix_versionRange_createLDAPFilter(range, "service.version"); EXPECT_STREQ(filter, "(&(service.version>1.2.3)(service.version<1.2.3))"); - versionRange_destroy(range); + celix_versionRange_destroy(range); free(filter); } -TEST_F(VersionRangeTestSuite, createLdapFilterInfinite) { - version_pt low = (version_pt) calloc(1, sizeof(*low)); +TEST_F(VersionRangeTestSuite, CreateLdapFilterInfiniteTest) { + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; low->qualifier = nullptr; - version_range_pt range = nullptr; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, true, nullptr, true, &range)); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, true, nullptr, true); - auto filter = versionRange_createLDAPFilter(range, "service.version"); + auto filter = celix_versionRange_createLDAPFilter(range, "service.version"); EXPECT_STREQ(filter, "(&(service.version>=1.2.3))"); - versionRange_destroy(range); + celix_versionRange_destroy(range); free(filter); } -TEST_F(VersionRangeTestSuite, createLdapFilterInPlaceInclusiveBoth) { - version_pt low = (version_pt) calloc(1, sizeof(*low)); +TEST_F(VersionRangeTestSuite, CreateLdapFilterInPlaceInclusiveBothTest) { + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; low->qualifier = nullptr; - version_pt high = (version_pt) calloc(1, sizeof(*high)); + celix_version_t* high = (celix_version_t*) calloc(1, sizeof(*high)); high->major = 1; high->minor = 2; high->micro = 3; high->qualifier = nullptr; - version_range_pt range = nullptr; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, true, high, true, &range)); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, true, high, true); char buffer[100]; int bufferLen = sizeof(buffer) / sizeof(buffer[0]); - EXPECT_EQ(1, versionRange_createLDAPFilterInPlace(range, "service.version", buffer, bufferLen)); + EXPECT_EQ(1, celix_versionRange_createLDAPFilterInPlace(range, "service.version", buffer, bufferLen)); EXPECT_STREQ(buffer, "(&(service.version>=1.2.3)(service.version<=1.2.3))"); - versionRange_destroy(range); + celix_versionRange_destroy(range); } -TEST_F(VersionRangeTestSuite, createLdapFilterInPlaceInclusiveLow) { - version_pt low = (version_pt) calloc(1, sizeof(*low)); +TEST_F(VersionRangeTestSuite, CreateLdapFilterInPlaceInclusiveLowTest) { + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; low->qualifier = nullptr; - version_pt high = (version_pt) calloc(1, sizeof(*high)); + celix_version_t* high = (celix_version_t*) calloc(1, sizeof(*high)); high->major = 1; high->minor = 2; high->micro = 3; high->qualifier = nullptr; - version_range_pt range = nullptr; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, true, high, false, &range)); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, true, high, false); + EXPECT_TRUE(range != nullptr); char buffer[100]; int bufferLen = sizeof(buffer) / sizeof(buffer[0]); - EXPECT_EQ(1, versionRange_createLDAPFilterInPlace(range, "service.version", buffer, bufferLen)); + EXPECT_EQ(1, celix_versionRange_createLDAPFilterInPlace(range, "service.version", buffer, bufferLen)); EXPECT_STREQ(buffer, "(&(service.version>=1.2.3)(service.version<1.2.3))"); - versionRange_destroy(range); + celix_versionRange_destroy(range); } -TEST_F(VersionRangeTestSuite, createLdapFilterInPlaceInclusiveHigh) { - version_pt low = (version_pt) calloc(1, sizeof(*low)); +TEST_F(VersionRangeTestSuite, CreateLdapFilterInPlaceInclusiveHighTest) { + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; low->qualifier = nullptr; - version_pt high = (version_pt) calloc(1, sizeof(*high)); + celix_version_t* high = (celix_version_t*) calloc(1, sizeof(*high)); high->major = 1; high->minor = 2; high->micro = 3; high->qualifier = nullptr; - version_range_pt range = nullptr; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, false, high, true, &range)); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, false, high, true); + EXPECT_TRUE(range != nullptr); char buffer[100]; int bufferLen = sizeof(buffer) / sizeof(buffer[0]); - EXPECT_EQ(1, versionRange_createLDAPFilterInPlace(range, "service.version", buffer, bufferLen)); + EXPECT_EQ(1, celix_versionRange_createLDAPFilterInPlace(range, "service.version", buffer, bufferLen)); EXPECT_STREQ(buffer, "(&(service.version>1.2.3)(service.version<=1.2.3))"); - versionRange_destroy(range); + celix_versionRange_destroy(range); } -TEST_F(VersionRangeTestSuite, createLdapFilterInPlaceExclusiveBoth) { - version_pt low = (version_pt) calloc(1, sizeof(*low)); +TEST_F(VersionRangeTestSuite, CreateLdapFilterInPlaceExclusiveBothTest) { + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; low->qualifier = nullptr; - version_pt high = (version_pt) calloc(1, sizeof(*high)); + celix_version_t* high = (celix_version_t*) calloc(1, sizeof(*high)); high->major = 1; high->minor = 2; high->micro = 3; high->qualifier = nullptr; - version_range_pt range = nullptr; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, false, high, false, &range)); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, false, high, false); + EXPECT_TRUE(range != nullptr); char buffer[100]; int bufferLen = sizeof(buffer) / sizeof(buffer[0]); - EXPECT_EQ(1, versionRange_createLDAPFilterInPlace(range, "service.version", buffer, bufferLen)); + EXPECT_EQ(1, celix_versionRange_createLDAPFilterInPlace(range, "service.version", buffer, bufferLen)); EXPECT_STREQ(buffer, "(&(service.version>1.2.3)(service.version<1.2.3))"); - versionRange_destroy(range); + celix_versionRange_destroy(range); } -TEST_F(VersionRangeTestSuite, createLdapFilterInPlaceInfiniteHigh) { - version_pt low = (version_pt) calloc(1, sizeof(*low)); +TEST_F(VersionRangeTestSuite, CreateLdapFilterInPlaceInfiniteHighTest) { + celix_version_t* low = (celix_version_t*) calloc(1, sizeof(*low)); low->major = 1; low->minor = 2; low->micro = 3; low->qualifier = nullptr; - version_range_pt range = nullptr; - EXPECT_EQ(CELIX_SUCCESS, versionRange_createVersionRange(low, false, nullptr, false, &range)); + celix_version_range_t* range = celix_versionRange_createVersionRange(low, false, nullptr, false); char buffer[100]; int bufferLen = sizeof(buffer) / sizeof(buffer[0]); - EXPECT_EQ(1, versionRange_createLDAPFilterInPlace(range, "service.version", buffer, bufferLen)); + EXPECT_EQ(1, celix_versionRange_createLDAPFilterInPlace(range, "service.version", buffer, bufferLen)); EXPECT_STREQ(buffer, "(&(service.version>1.2.3))"); - versionRange_destroy(range); + celix_versionRange_destroy(range); } -TEST_F(VersionRangeTestSuite, createLdapFilterWithQualifier) { +TEST_F(VersionRangeTestSuite, CreateLdapFilterWithQualifierTest) { celix_autoptr(celix_version_t) low = celix_version_create(1, 2, 2, "0"); celix_autoptr(celix_version_t) high = celix_version_create(1, 2, 2, "0"); diff --git a/libs/utils/gtest/src/VersionTestSuite.cc b/libs/utils/gtest/src/VersionTestSuite.cc index 5e908fd8..7daa7495 100644 --- a/libs/utils/gtest/src/VersionTestSuite.cc +++ b/libs/utils/gtest/src/VersionTestSuite.cc @@ -19,10 +19,7 @@ #include <gtest/gtest.h> -#include "celix_errno.h" #include "celix_version.h" -#include "celix_utils.h" -#include "version.h" class VersionTestSuite : public ::testing::Test { public: @@ -46,29 +43,6 @@ TEST_F(VersionTestSuite, CreateTest) { EXPECT_EQ(nullptr, celix_version_create(-1, -2, -3, "abc")); EXPECT_EQ(nullptr, celix_version_create(-1, -2, -3, "abc|xyz")); - - - //Testing deprecated api - version = nullptr; - EXPECT_EQ(CELIX_SUCCESS, version_createVersion(1, 2, 3, nullptr, &version)); - EXPECT_TRUE(version != nullptr); - int major; - int minor; - int micro; - const char* q; - EXPECT_EQ(CELIX_SUCCESS, version_getMajor(version, &major)); - EXPECT_EQ(CELIX_SUCCESS, version_getMinor(version, &minor)); - EXPECT_EQ(CELIX_SUCCESS, version_getMicro(version, µ)); - EXPECT_EQ(CELIX_SUCCESS, version_getQualifier(version, &q)); - EXPECT_EQ(1, major); - EXPECT_EQ(2, minor); - EXPECT_EQ(3, micro); - EXPECT_STREQ("", q); - version_destroy(version); - - version = nullptr; - EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, version_createVersion(-1, -2, -3, "abc", &version)); - EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, version_createVersion(1, 2, 3, "abc|xyz", &version)); } TEST_F(VersionTestSuite, CopyTest) { @@ -90,7 +64,7 @@ TEST_F(VersionTestSuite, CreateFromStringTest) { auto* version = celix_version_createVersionFromString("1"); EXPECT_TRUE(version != nullptr); expectVersion(version, 1, 0, 0); - version_destroy(version); + celix_version_destroy(version); EXPECT_EQ(nullptr, celix_version_createVersionFromString("a")); EXPECT_EQ(nullptr, celix_version_createVersionFromString("1.a")); @@ -101,105 +75,65 @@ TEST_F(VersionTestSuite, CreateFromStringTest) { version = celix_version_createVersionFromString("1.2"); EXPECT_TRUE(version != nullptr); expectVersion(version, 1, 2, 0); - version_destroy(version); + celix_version_destroy(version); version = celix_version_createVersionFromString("1.2.3"); EXPECT_TRUE(version != nullptr); expectVersion(version, 1, 2, 3); - version_destroy(version); + celix_version_destroy(version); version = celix_version_createVersionFromString("1.2.3.abc"); EXPECT_TRUE(version != nullptr); expectVersion(version, 1, 2, 3, "abc"); - version_destroy(version); + celix_version_destroy(version); version = celix_version_createVersionFromString("1.2.3.abc_xyz"); EXPECT_TRUE(version != nullptr); expectVersion(version, 1, 2, 3, "abc_xyz"); - version_destroy(version); + celix_version_destroy(version); version = celix_version_createVersionFromString("1.2.3.abc-xyz"); EXPECT_TRUE(version != nullptr); expectVersion(version, 1, 2, 3, "abc-xyz"); - version_destroy(version); - - - //Testing deprecated api - version = nullptr; - EXPECT_EQ(CELIX_SUCCESS, version_createVersionFromString("1", &version)); - EXPECT_TRUE(version != nullptr); - expectVersion(version, 1, 0, 0); - version_destroy(version); - - EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, version_createVersionFromString("a", &version)); + celix_version_destroy(version); } TEST_F(VersionTestSuite, CreateEmptyVersionTest) { auto* version = celix_version_createEmptyVersion(); EXPECT_TRUE(version != nullptr); expectVersion(version, 0, 0, 0, ""); - version_destroy(version); - - //Testing deprecated api - version = nullptr; - EXPECT_EQ(CELIX_SUCCESS, version_createEmptyVersion(&version)); - EXPECT_TRUE(version != nullptr); - expectVersion(version, 0, 0, 0, ""); - version_destroy(version); + celix_version_destroy(version); } TEST_F(VersionTestSuite, CompareTest) { - celix_version_t* version = nullptr; - celix_version_t* compare = nullptr; - celix_status_t status = CELIX_SUCCESS; - char * str; - int result; - // Base version to compare - str = celix_utils_strdup("abc"); - status = version_createVersion(1, 2, 3, str, &version); - EXPECT_EQ(CELIX_SUCCESS, status); + const char* str = "abc"; + celix_version_t* version = celix_version_create(1, 2, 3, str); EXPECT_TRUE(version != nullptr); // Compare equality - free(str); - str = celix_utils_strdup("abc"); - compare = nullptr; - status = version_createVersion(1, 2, 3, str, &compare); - EXPECT_EQ(CELIX_SUCCESS, status); - EXPECT_TRUE(version != nullptr); - status = version_compareTo(version, compare, &result); - EXPECT_EQ(CELIX_SUCCESS, status); + celix_version_t* compare = celix_version_create(1, 2, 3, str); + EXPECT_TRUE(compare != nullptr); + int result = celix_version_compareTo(version, compare); EXPECT_EQ(0, result); + celix_version_destroy(compare); // Compare against a higher version - free(str); - str = celix_utils_strdup("bcd"); - version_destroy(compare); - compare = nullptr; - status = version_createVersion(1, 2, 3, str, &compare); - EXPECT_EQ(CELIX_SUCCESS, status); - EXPECT_TRUE(version != nullptr); - status = version_compareTo(version, compare, &result); - EXPECT_EQ(CELIX_SUCCESS, status); + compare = celix_version_create(1, 2, 3, "bcd"); + EXPECT_TRUE(compare != nullptr); + result = celix_version_compareTo(version, compare); EXPECT_TRUE(result < 0); + celix_version_destroy(compare); // Compare against a lower version - free(str); - str = celix_utils_strdup("abc"); - version_destroy(compare); - compare = nullptr; - status = version_createVersion(1, 1, 3, str, &compare); - EXPECT_EQ(CELIX_SUCCESS, status); - EXPECT_TRUE(version != nullptr); - status = version_compareTo(version, compare, &result); - EXPECT_EQ(CELIX_SUCCESS, status); + compare = celix_version_create(1, 1, 3, str); + EXPECT_TRUE(compare != nullptr); + result = celix_version_compareTo(version, compare); EXPECT_TRUE(result > 0); + celix_version_destroy(compare); - version_destroy(compare); - version_destroy(version); - free(str); + celix_version_destroy(version); } TEST_F(VersionTestSuite, CompareToMajorMinorTest) { @@ -225,70 +159,49 @@ TEST_F(VersionTestSuite, CompareToMajorMinorTest) { } TEST_F(VersionTestSuite, ToStringTest) { - celix_version_t* version = nullptr; - celix_status_t status = CELIX_SUCCESS; - char * str; - char *result = nullptr; - - str = celix_utils_strdup("abc"); - status = version_createVersion(1, 2, 3, str, &version); - EXPECT_EQ(CELIX_SUCCESS, status); + celix_version_t* version = celix_version_create(1, 2, 3, "abc"); EXPECT_TRUE(version != nullptr); - - status = version_toString(version, &result); - EXPECT_EQ(CELIX_SUCCESS, status); + char* result = celix_version_toString(version); EXPECT_TRUE(result != nullptr); EXPECT_STREQ("1.2.3.abc", result); free(result); + celix_version_destroy(version); - version_destroy(version); - version = nullptr; - status = version_createVersion(1, 2, 3, nullptr, &version); - EXPECT_EQ(CELIX_SUCCESS, status); + version = celix_version_create(1, 2, 3, nullptr); EXPECT_TRUE(version != nullptr); - - status = version_toString(version, &result); - EXPECT_EQ(CELIX_SUCCESS, status); + result = celix_version_toString(version); EXPECT_TRUE(result != nullptr); EXPECT_STREQ("1.2.3", result); - - version_destroy(version); + celix_version_destroy(version); free(result); - free(str); } TEST_F(VersionTestSuite, SemanticCompatibilityTest) { celix_version_t* provider = nullptr; celix_version_t* compatible_user = nullptr; - celix_version_t* incompatible_user_by_major = nullptr; - celix_version_t* incompatible_user_by_minor = nullptr; - celix_status_t status = CELIX_SUCCESS; - bool isCompatible = false; - - status = version_isCompatible(compatible_user, provider, &isCompatible); - EXPECT_EQ(CELIX_SUCCESS, status); - - version_createVersion(2, 3, 5, nullptr, &provider); - version_createVersion(2, 1, 9, nullptr, &compatible_user); - version_createVersion(1, 3, 5, nullptr, &incompatible_user_by_major); - version_createVersion(2, 5, 7, nullptr, &incompatible_user_by_minor); - - status = version_isCompatible(compatible_user, provider, &isCompatible); - EXPECT_TRUE(isCompatible == true); - EXPECT_EQ(CELIX_SUCCESS, status); - - status = version_isCompatible(incompatible_user_by_major, provider, &isCompatible); - EXPECT_TRUE(isCompatible == false); - EXPECT_EQ(CELIX_SUCCESS, status); - - status = version_isCompatible(incompatible_user_by_minor, provider, &isCompatible); - EXPECT_TRUE(isCompatible == false); - EXPECT_EQ(CELIX_SUCCESS, status); - - version_destroy(provider); - version_destroy(compatible_user); - version_destroy(incompatible_user_by_major); - version_destroy(incompatible_user_by_minor); + bool isCompatible = celix_version_isCompatible(compatible_user, provider); + EXPECT_TRUE(isCompatible); + + provider = celix_version_create(2, 3, 5, nullptr); + EXPECT_FALSE(celix_version_isCompatible(compatible_user, provider)); + + compatible_user = celix_version_create(2, 1, 9, nullptr); + celix_version_t* incompatible_user_by_major = celix_version_create(1, 3, 5, nullptr); + celix_version_t* incompatible_user_by_minor = celix_version_create(2, 5, 7, nullptr); + + isCompatible = celix_version_isCompatible(compatible_user, provider); + EXPECT_TRUE(isCompatible); + + isCompatible = celix_version_isCompatible(incompatible_user_by_major, provider); + EXPECT_FALSE(isCompatible); + + isCompatible = celix_version_isCompatible(incompatible_user_by_minor, provider); + EXPECT_FALSE(isCompatible); + + celix_version_destroy(provider); + celix_version_destroy(compatible_user); + celix_version_destroy(incompatible_user_by_major); + celix_version_destroy(incompatible_user_by_minor); } TEST_F(VersionTestSuite, CompareEmptyAndNullQualifierTest) { diff --git a/libs/utils/include_deprecated/celix_utils_api.h b/libs/utils/include_deprecated/celix_utils_api.h index 61c2df4f..e0b199e4 100644 --- a/libs/utils/include_deprecated/celix_utils_api.h +++ b/libs/utils/include_deprecated/celix_utils_api.h @@ -29,8 +29,8 @@ #include "celix_properties.h" #include "utils.h" #include "celix_utils.h" -#include "version.h" -#include "version_range.h" +#include "celix_version.h" +#include "celix_version_range.h" #if defined(NO_MEMSTREAM_AVAILABLE) #include "memstream/open_memstream.h" diff --git a/libs/utils/include_deprecated/version.h b/libs/utils/include_deprecated/version.h deleted file mode 100644 index 9f3be9d6..00000000 --- a/libs/utils/include_deprecated/version.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -#ifndef VERSION_H_ -#define VERSION_H_ - -#include <stdbool.h> - -#include "celix_errno.h" -#include "celix_utils_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * The definition of the version_pt abstract data type. - */ -typedef struct celix_version *version_pt __attribute__((deprecated("version is deprecated use celix_version instead")));; - -/** - * Creates a new version_pt using the supplied arguments. - * - * @param major Major component of the version identifier. - * @param minor Minor component of the version identifier. - * @param micro Micro component of the version identifier. - * @param qualifier Qualifier component of the version identifier. If - * <code>null</code> is specified, then the qualifier will be set to - * the empty string. - * @param version The created version_pt - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ENOMEM If allocating memory for <code>version</code> failed. - * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative - * or the qualifier string is invalid. - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t version_createVersion(int major, int minor, int micro, const char *qualifier, version_pt *version); - -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t version_destroy(version_pt version); - -/** - * Creates a clone of <code>version</code>. - * - * @param version The version to clone - * @param clone The cloned version - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ENOMEM If allocating memory for <code>version</code> failed. - * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative - * or the qualifier string is invalid. - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t version_clone(version_pt version, version_pt *clone); - -/** - * Creates a version identifier from the specified string. - * - * <p> - * Here is the grammar for version strings. - * - * <pre> - * version ::= major('.'minor('.'micro('.'qualifier)?)?)? - * major ::= digit+ - * minor ::= digit+ - * micro ::= digit+ - * qualifier ::= (alpha|digit|'_'|'-')+ - * digit ::= [0..9] - * alpha ::= [a..zA..Z] - * </pre> - * - * There must be no whitespace in version. - * - * @param versionStr String representation of the version identifier. - * @param version The created version_pt - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ENOMEM If allocating memory for <code>version</code> failed. - * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative, - * the qualifier string is invalid or <code>versionStr</code> is improperly formatted. - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t version_createVersionFromString(const char *versionStr, version_pt *version); - -/** - * The empty version "0.0.0". - * - * @param version The created version_pt - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ENOMEM If allocating memory for <code>version</code> failed. - * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative, - * the qualifier string is invalid or <code>versionStr</code> is improperly formatted. - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t version_createEmptyVersion(version_pt *version); - -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t version_getMajor(version_pt version, int *major); - -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t version_getMinor(version_pt version, int *minor); - -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t version_getMicro(version_pt version, int *micro); - -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t version_getQualifier(version_pt version, const char **qualifier); - -/** - * Compares this <code>Version</code> object to another object. - * - * <p> - * A version is considered to be <b>less than </b> another version if its - * major component is less than the other version's major component, or the - * major components are equal and its minor component is less than the other - * version's minor component, or the major and minor components are equal - * and its micro component is less than the other version's micro component, - * or the major, minor and micro components are equal and it's qualifier - * component is less than the other version's qualifier component (using - * <code>String.compareTo</code>). - * - * <p> - * A version is considered to be <b>equal to</b> another version if the - * major, minor and micro components are equal and the qualifier component - * is equal (using <code>String.compareTo</code>). - * - * @param version The <code>version_pt</code> to be compared with <code>compare</code>. - * @param compare The <code>version_pt</code> to be compared with <code>version</code>. - * @param result A negative integer, zero, or a positive integer if <code>version</code> is - * less than, equal to, or greater than the <code>compare</code>. - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t version_compareTo(version_pt version, version_pt compare, int *result); - -/** - * Returns the string representation of <code>version</code> identifier. - * - * <p> - * The format of the version string will be <code>major.minor.micro</code> - * if qualifier is the empty string or - * <code>major.minor.micro.qualifier</code> otherwise. - * - * @return The string representation of this version identifier. - * @param version The <code>version_pt</code> to get the string representation from. - * @param string Pointer to the string (char *) in which the result will be placed. - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t version_toString(version_pt version, char **string); - -/** - * Check if two versions are semantically compatible. - * - * <p> - * The user version is compatible with the provider version if the provider version is in the range - * [user_version, next_macro_from_user_version) - * - * @return Boolean indicating if the versions are compatible - * @param version The user <code>version_pt</code> . - * @param version The reference provider <code>version_pt</code> . - * @param Boolean indicating if the versions are compatible - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t version_isCompatible(version_pt user, version_pt provider, bool *isCompatible); - -#ifdef __cplusplus -} -#endif - -#endif /* VERSION_H_ */ diff --git a/libs/utils/include_deprecated/version_range.h b/libs/utils/include_deprecated/version_range.h deleted file mode 100644 index 1f6853da..00000000 --- a/libs/utils/include_deprecated/version_range.h +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - - -#ifndef VERSION_RANGE_H_ -#define VERSION_RANGE_H_ - -/** - * @defgroup VersionRange Version Range functions - * @ingroup framework - * @{ - */ - -#include <stdbool.h> -#include "celix_errno.h" -#include "version.h" -#include "celix_utils_export.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Type definition for the version_range_pt abstract data type. - */ -typedef struct celix_version_range *version_range_pt __attribute__((deprecated("version_range is deprecated use celix_version_range instead"))); - -/** - * Creates a new <code>version_range_pt</code>. - * - * @param low Lower bound version - * @param isLowInclusive True if lower bound should be included in the range - * @param high Upper bound version - * @param isHighInclusive True if upper bound should be included in the range - * @param versionRange The created range - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ENOMEM If allocating memory for <code>versionRange</code> failed. - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t -versionRange_createVersionRange(version_pt low, bool isLowInclusive, version_pt high, bool isHighInclusive, - version_range_pt *versionRange); - -/** - * Creates an infinite version range using ::version_createEmptyVersion for the low version, - * NULL for the high version and high and low inclusive set to true. - * - * @param range The created range - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ENOMEM If allocating memory for <code>range</code> failed. - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t versionRange_createInfiniteVersionRange(version_range_pt *range); - -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t versionRange_destroy(version_range_pt range); - -/** - * Determine if the specified version is part of the version range or not. - * - * @param versionRange The range to check <code>version</code> against. - * @param version The version to check. - * @param inRange True if the specified version is included in this version range, false otherwise. - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t versionRange_isInRange(version_range_pt versionRange, version_pt version, bool *inRange); - -/** - * Determines whether the lower bound is included in the given range - * - * @param versionRange The range to check - * @param isLowInclusive is set to true in case, the lower bound the lower bound is included, otherwise false - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ILLEGAL_ARGUMENT in case the versionRange is NULL - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t versionRange_isLowInclusive(version_range_pt versionRange, bool *isLowInclusive); - -/** - * Determines whether the higher bound is included in the given range - * - * @param versionRange The range to check - * @param isHighInclusive is set to true in case, the lower bound the higher bound is included, otherwise false - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ILLEGAL_ARGUMENT in case the versionRange is NULL - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t versionRange_isHighInclusive(version_range_pt versionRange, bool *isHighInclusive); - -/** - * Retrieves whether the lower bound version from the given range - * - * @param versionRange The range - * @param highVersion is set to the lower bound version - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ILLEGAL_ARGUMENT in case the versionRange is NULL - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t versionRange_getLowVersion(version_range_pt versionRange, version_pt *lowVersion); - -/** - * Retrieves whether the upper bound version from the given range - * - * @param versionRange The range - * @param highVersion is set to the upper bound version - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ILLEGAL_ARGUMENT in case the versionRange is NULL - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t versionRange_getHighVersion(version_range_pt versionRange, version_pt *highVersion); - -/** - * Parses a version range from the specified string. - * - * <p> - * Here is the grammar for version range strings. - * - * <pre> - * version-range ::= interval | atleast - * interval ::= ( '[' | '(' ) floor ',' ceiling ( ']' | ')' ) - * atleast ::= version - * floor ::= version - * ceiling ::= version - * </pre> - * - * @param rangeStr String representation of the version range. - * @param range The created version_range_pt. - * @return Status code indication failure or success: - * - CELIX_SUCCESS when no errors are encountered. - * - CELIX_ENOMEM If allocating memory for <code>versionRange</code> failed. - * - CELIX_ILLEGAL_ARGUMENT If the numerical components are negative, - * the qualifier string is invalid or <code>versionStr</code> is impropertly formatted. - */ -CELIX_UTILS_DEPRECATED_EXPORT celix_status_t versionRange_parse(const char *rangeStr, version_range_pt *range); - -/** - * Returns the LDAP filter for a version range. Caller is owner of the returned string. - * - * @param range The version range used as input for the LDAP filer - * @param serviceVersionPropertyName The service version name to be used in the filter (i.e. service.version) - * @return LDAP filter string if valid, NULL otherwise - */ -CELIX_UTILS_DEPRECATED_EXPORT char* versionRange_createLDAPFilter(version_range_pt range, const char *serviceVersionAttributeName); - -/** - * construct a LDAP filter for the provided version range. - * The string will be created in the provided buffer, if the buffer is big enough. - * - * @return True if parse successful, False otherwise. - */ -CELIX_UTILS_DEPRECATED_EXPORT bool versionRange_createLDAPFilterInPlace(version_range_pt range, const char *serviceVersionAttributeName, char* buffer, size_t bufferLength); - - -#ifdef __cplusplus -} -#endif - -#endif /* VERSION_RANGE_H_ */ diff --git a/libs/utils/src/version.c b/libs/utils/src/version.c index 07652a00..693166d0 100644 --- a/libs/utils/src/version.c +++ b/libs/utils/src/version.c @@ -23,81 +23,12 @@ #include <celix_utils.h> #include "celix_version.h" -#include "version.h" #include "celix_errno.h" #include "version_private.h" #include "celix_err.h" static const char* const CELIX_VERSION_EMPTY_QUALIFIER = ""; -celix_status_t version_createVersion(int major, int minor, int micro, const char * qualifier, version_pt *version) { - *version = celix_version_create(major, minor, micro, qualifier); - return *version == NULL ? CELIX_ILLEGAL_ARGUMENT : CELIX_SUCCESS; -} - -celix_status_t version_clone(version_pt version, version_pt *clone) { - *clone = celix_version_copy(version); - return CELIX_SUCCESS; -} - -celix_status_t version_destroy(version_pt version) { - celix_version_destroy(version); - return CELIX_SUCCESS; -} - -celix_status_t version_createVersionFromString(const char * versionStr, version_pt *version) { - if (versionStr == NULL) { - *version = NULL; - return CELIX_SUCCESS; - } - *version = celix_version_createVersionFromString(versionStr); - return *version == NULL ? CELIX_ILLEGAL_ARGUMENT : CELIX_SUCCESS; -} - -celix_status_t version_createEmptyVersion(version_pt *version) { - *version = celix_version_createEmptyVersion(); - return *version == NULL ? CELIX_ILLEGAL_ARGUMENT : CELIX_SUCCESS; -} - -celix_status_t version_getMajor(version_pt version, int *major) { - celix_status_t status = CELIX_SUCCESS; - *major = version->major; - return status; -} - -celix_status_t version_getMinor(version_pt version, int *minor) { - celix_status_t status = CELIX_SUCCESS; - *minor = version->minor; - return status; -} - -celix_status_t version_getMicro(version_pt version, int *micro) { - celix_status_t status = CELIX_SUCCESS; - *micro = version->micro; - return status; -} - -celix_status_t version_getQualifier(version_pt version, const char **qualifier) { - celix_status_t status = CELIX_SUCCESS; - *qualifier = version->qualifier; - return status; -} - -celix_status_t version_compareTo(version_pt version, version_pt compare, int *result) { - *result = celix_version_compareTo(version, compare); - return CELIX_SUCCESS; -} - -celix_status_t version_toString(version_pt version, char **string) { - *string = celix_version_toString(version); - return CELIX_SUCCESS; -} - -celix_status_t version_isCompatible(version_pt user, version_pt provider, bool* isCompatible) { - *isCompatible = celix_version_isCompatible(user, provider); - return CELIX_SUCCESS; -} - celix_version_t* celix_version_create(int major, int minor, int micro, const char* qualifier) { if (major < 0 || minor < 0 || micro < 0) { celix_err_push("Invalid version number. Major, minor and micro must be >= 0"); diff --git a/libs/utils/src/version_range.c b/libs/utils/src/version_range.c index ca661291..08e5d9c5 100644 --- a/libs/utils/src/version_range.c +++ b/libs/utils/src/version_range.c @@ -17,6 +17,8 @@ * under the License. */ +#include "celix_version_range.h" +#include "version_range_private.h" #include <stdlib.h> #include <string.h> @@ -24,107 +26,6 @@ #include <assert.h> #include "version_private.h" -#include "version_range.h" -#include "celix_version_range.h" -#include "version_range_private.h" -#include "celix_version_range.h" - -celix_status_t versionRange_createVersionRange(version_pt low, bool isLowInclusive, - version_pt high, bool isHighInclusive, version_range_pt *range) { - *range = celix_versionRange_createVersionRange(low, isLowInclusive, high, isHighInclusive); - return CELIX_SUCCESS; -} - -celix_status_t versionRange_destroy(version_range_pt range) { - celix_versionRange_destroy(range); - return CELIX_SUCCESS; -} - -celix_status_t versionRange_createInfiniteVersionRange(version_range_pt *range) { - *range = celix_versionRange_createInfiniteVersionRange(); - return CELIX_SUCCESS; -} - -celix_status_t versionRange_isInRange(version_range_pt versionRange, version_pt version, bool *inRange) { - if (versionRange != NULL && version != NULL) { - *inRange = celix_versionRange_isInRange(versionRange, version); - return CELIX_SUCCESS; - } else { - return CELIX_ILLEGAL_ARGUMENT; - } -} - -celix_status_t versionRange_getLowVersion(version_range_pt versionRange, version_pt *lowVersion) { - celix_status_t status = CELIX_SUCCESS; - - if (versionRange == NULL) { - status = CELIX_ILLEGAL_ARGUMENT; - } - else { - *lowVersion = versionRange->low; - } - - return status; -} - -celix_status_t versionRange_isLowInclusive(version_range_pt versionRange, bool *isLowInclusive) { - celix_status_t status = CELIX_SUCCESS; - - if (versionRange == NULL) { - status = CELIX_ILLEGAL_ARGUMENT; - } - else { - *isLowInclusive = versionRange->isLowInclusive; - } - - return status; -} - -celix_status_t versionRange_getHighVersion(version_range_pt versionRange, version_pt *highVersion) { - celix_status_t status = CELIX_SUCCESS; - - if (versionRange == NULL) { - status = CELIX_ILLEGAL_ARGUMENT; - } - else { - *highVersion = versionRange->high; - } - - return status; -} - -celix_status_t versionRange_isHighInclusive(version_range_pt versionRange, bool *isHighInclusive) { - celix_status_t status = CELIX_SUCCESS; - - if (versionRange == NULL) { - status = CELIX_ILLEGAL_ARGUMENT; - } - else { - *isHighInclusive = versionRange->isHighInclusive; - } - - return status; -} - - -celix_status_t versionRange_parse(const char * rangeStr, version_range_pt *range) { - *range = celix_versionRange_parse(rangeStr); - if (*range == NULL) { - return CELIX_ILLEGAL_ARGUMENT; - } else { - return CELIX_SUCCESS; - } -} - -char* versionRange_createLDAPFilter(version_range_pt range, const char *serviceVersionAttributeName) { - return celix_versionRange_createLDAPFilter(range, serviceVersionAttributeName); -} - - - -bool versionRange_createLDAPFilterInPlace(version_range_pt range, const char *serviceVersionAttributeName, char* buffer, size_t bufferLength) { - return celix_versionRange_createLDAPFilterInPlace(range, serviceVersionAttributeName, buffer, bufferLength); -} celix_version_range_t* celix_versionRange_createVersionRange(celix_version_t* low, bool isLowInclusive, celix_version_t* high, bool isHighInclusive) { assert(low != high);
