From cef01ef33e339690628e0cd29c126203d51d1b2d Mon Sep 17 00:00:00 2001 From: PengZheng Date: Fri, 25 Aug 2023 17:18:56 +0800 Subject: [PATCH] Take qualifier into account when create LDAP filter for version range. --- libs/utils/gtest/src/VersionRangeTestSuite.cc | 11 +++++++++++ libs/utils/src/version_range.c | 14 ++++++++++---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/libs/utils/gtest/src/VersionRangeTestSuite.cc b/libs/utils/gtest/src/VersionRangeTestSuite.cc index 4ae747726..e51a53481 100644 --- a/libs/utils/gtest/src/VersionRangeTestSuite.cc +++ b/libs/utils/gtest/src/VersionRangeTestSuite.cc @@ -21,6 +21,7 @@ #include "version.h" #include "version_range.h" //NOTE testing celix_version_range through the deprecated version_range api. +#include "celix_stdlib_cleanup.h" #include "celix_version_range.h" #include "version_private.h" @@ -415,3 +416,13 @@ TEST_F(VersionRangeTestSuite, createLdapFilterInPlaceInfiniteHigh) { versionRange_destroy(range); } + +TEST_F(VersionRangeTestSuite, createLdapFilterWithQualifier) { + celix_autoptr(celix_version_t) low = celix_version_createVersion(1, 2, 2, "0"); + celix_autoptr(celix_version_t) high = celix_version_createVersion(1, 2, 2, "0"); + + celix_autoptr(celix_version_range_t) range = celix_versionRange_createVersionRange(celix_steal_ptr(low), true, + celix_steal_ptr(high), true); + celix_autofree char* filter = celix_versionRange_createLDAPFilter(range, "service.version"); + EXPECT_STREQ(filter, "(&(service.version>=1.2.2.0)(service.version<=1.2.2.0))"); +} diff --git a/libs/utils/src/version_range.c b/libs/utils/src/version_range.c index f03fee94d..ca6612918 100644 --- a/libs/utils/src/version_range.c +++ b/libs/utils/src/version_range.c @@ -246,15 +246,21 @@ char* celix_versionRange_createLDAPFilter(const celix_version_range_t* range, co int ret = -1; if(range->high == NULL) { - ret = asprintf(&output, "(&(%s%s%i.%i.%i))", + ret = asprintf(&output, "(&(%s%s%i.%i.%i%s%s))", serviceVersionAttributeName, range->isLowInclusive ? ">=" : ">", range->low->major, - range->low->minor, range->low->micro); + range->low->minor, range->low->micro, + range->low->qualifier ? "." : "", + range->low->qualifier ? range->low->qualifier : ""); } else { - ret = asprintf(&output, "(&(%s%s%i.%i.%i)(%s%s%i.%i.%i))", + ret = asprintf(&output, "(&(%s%s%i.%i.%i%s%s)(%s%s%i.%i.%i%s%s))", serviceVersionAttributeName, range->isLowInclusive ? ">=" : ">", range->low->major, range->low->minor, range->low->micro, + range->low->qualifier ? "." : "", + range->low->qualifier ? range->low->qualifier : "", serviceVersionAttributeName, range->isHighInclusive ? "<=" : "<", range->high->major, - range->high->minor, range->high->micro); + range->high->minor, range->high->micro, + range->high->qualifier ? "." : "", + range->high->qualifier ? range->high->qualifier : ""); } if (ret < 0) {