(celix) branch feature/685-properties-json-serialization updated: gh-685: Fix several memleaks in properties encoding
This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/685-properties-json-serialization in repository https://gitbox.apache.org/repos/asf/celix.git The following commit(s) were added to refs/heads/feature/685-properties-json-serialization by this push: new 0e589441 gh-685: Fix several memleaks in properties encoding 0e589441 is described below commit 0e5894419921ddbb5f4c4868cf6e7c99b463bfd2 Author: Pepijn Noltes AuthorDate: Sun Apr 14 23:03:53 2024 +0200 gh-685: Fix several memleaks in properties encoding --- .../PropertiesEncodingErrorInjectionTestSuite.cc | 8 +- .../utils/gtest/src/PropertiesEncodingTestSuite.cc | 107 - libs/utils/include/celix_properties.h | 52 +- libs/utils/src/properties_encoding.c | 23 +++-- 4 files changed, 126 insertions(+), 64 deletions(-) diff --git a/libs/utils/gtest/src/PropertiesEncodingErrorInjectionTestSuite.cc b/libs/utils/gtest/src/PropertiesEncodingErrorInjectionTestSuite.cc index 3bcc804e..2553e0e9 100644 --- a/libs/utils/gtest/src/PropertiesEncodingErrorInjectionTestSuite.cc +++ b/libs/utils/gtest/src/PropertiesEncodingErrorInjectionTestSuite.cc @@ -69,7 +69,7 @@ TEST_F(PropertiesEncodingErrorInjectionTestSuite, SaveErrorTest) { celix_ei_expect_open_memstream((void*)celix_properties_saveToString, 0, nullptr); //When I call celix_properties_saveToString -char* out = nullptr; +char* out; status = celix_properties_saveToString(props, 0, ); //Then I expect an error @@ -90,7 +90,7 @@ TEST_F(PropertiesEncodingErrorInjectionTestSuite, EncodeErrorTest) { celix_ei_expect_celix_utils_writeOrCreateString((void*)celix_properties_saveToString, 2, nullptr); // And I call celix_properties_saveToString using NESTED encoding (whitebox-knowledge) -char* out = nullptr; +char* out; auto status = celix_properties_saveToString(props, CELIX_PROPERTIES_ENCODE_NESTED_STYLE, ); // Then I expect an error @@ -149,7 +149,7 @@ TEST_F(PropertiesEncodingErrorInjectionTestSuite, EncodeArrayErrorTest) { celix_ei_expect_json_array((void*)celix_properties_saveToString, 4, nullptr); // And I call celix_properties_saveToString -char* out = nullptr; +char* out; auto status = celix_properties_saveToString(props, 0, ); // Then I expect an error @@ -189,7 +189,7 @@ TEST_F(PropertiesEncodingErrorInjectionTestSuite, EncodeVersionErrorTest) { celix_ei_expect_json_sprintf((void*)celix_properties_saveToString, 4, nullptr); // And I call celix_properties_saveToString -char* out = nullptr; +char* out; auto status = celix_properties_saveToString(props, 0, ); // Then I expect an error diff --git a/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc index d4ff8e17..0771aa3c 100644 --- a/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc +++ b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc @@ -93,14 +93,17 @@ TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithNaNAndInfValuesTest) celix_autoptr(celix_properties_t) props = celix_properties_create(); celix_properties_setDouble(props, key, strtod(key, nullptr)); -//And an in-memory stream -celix_autofree char* buf = nullptr; -size_t bufLen = 0; -FILE* stream = open_memstream(, ); +// Then saving the properties to a string succeeds, but value is not added to the JSON (because JSON does not +// support NAN, INF and -INF) +celix_autofree char* output; +auto status = celix_properties_saveToString(props, 0, ); +ASSERT_EQ(CELIX_SUCCESS, status); +EXPECT_STREQ("{}", output); -//Then saving the properties to the stream fails, because JSON does not support NAN, INF and -INF +//And saving the properties to a string with the flag CELIX_PROPERTIES_ENCODE_ERROR_ON_NAN_INF fails celix_err_resetErrors(); -auto status = celix_properties_saveToStream(props, stream, 0); +char* output2; +status = celix_properties_saveToString(props, CELIX_PROPERTIES_ENCODE_ERROR_ON_NAN_INF, ); EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); //And an error msg is added to celix_err @@ -112,25 +115,30 @@ TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithNaNAndInfValuesTest) TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithArrayListsTest) { // Given a properties object with array list values celix_autoptr(celix_properties_t) props = celix_properties_create(); + celix_array_list_t* list1 = celix_arrayList_createStringArray(); celix_arrayList_addString(list1, "value1"); celix_arrayList_addString(list1, "value2"); celix_properties_assignArrayList(props, "key1", list1); + celix_array_list_t* list2 = celix_arrayList_createLongArray();
(celix) branch feature/685-properties-json-serialization updated: gh-685: Refactor assert to prevent used var
This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/685-properties-json-serialization in repository https://gitbox.apache.org/repos/asf/celix.git The following commit(s) were added to refs/heads/feature/685-properties-json-serialization by this push: new ac2b1319 gh-685: Refactor assert to prevent used var ac2b1319 is described below commit ac2b13197f5cc863e4dd9e341a71c7188db2a533 Author: Pepijn Noltes AuthorDate: Sun Apr 14 19:48:16 2024 +0200 gh-685: Refactor assert to prevent used var Also: Rename the nested / flat encoding style flag. --- conanfile.py | 2 +- .../PropertiesEncodingErrorInjectionTestSuite.cc | 10 +- .../utils/gtest/src/PropertiesEncodingTestSuite.cc | 10 +- libs/utils/include/celix_properties.h | 295 +++-- libs/utils/src/properties_encoding.c | 11 +- 5 files changed, 283 insertions(+), 45 deletions(-) diff --git a/conanfile.py b/conanfile.py index 63d9ac00..d8b46d01 100644 --- a/conanfile.py +++ b/conanfile.py @@ -332,7 +332,7 @@ class CelixConan(ConanFile): self.requires("civetweb/1.16") if self.options.build_celix_dfi: self.requires("libffi/[>=3.2.1 <4.0.0]") -if self.option.build_utils or self.options.build_celix_dfi or self.options.build_celix_etcdlib: +if self.options.build_utils or self.options.build_celix_dfi or self.options.build_celix_etcdlib: self.requires("jansson/[>=2.12 <3.0.0]") if self.options.build_rsa_discovery_zeroconf: # TODO: To be replaced with mdnsresponder/1790.80.10, resolve some problems of mdnsresponder diff --git a/libs/utils/gtest/src/PropertiesEncodingErrorInjectionTestSuite.cc b/libs/utils/gtest/src/PropertiesEncodingErrorInjectionTestSuite.cc index 9e2d3bc3..3bcc804e 100644 --- a/libs/utils/gtest/src/PropertiesEncodingErrorInjectionTestSuite.cc +++ b/libs/utils/gtest/src/PropertiesEncodingErrorInjectionTestSuite.cc @@ -91,7 +91,7 @@ TEST_F(PropertiesEncodingErrorInjectionTestSuite, EncodeErrorTest) { // And I call celix_properties_saveToString using NESTED encoding (whitebox-knowledge) char* out = nullptr; -auto status = celix_properties_saveToString(props, CELIX_PROPERTIES_ENCODE_NESTED, ); +auto status = celix_properties_saveToString(props, CELIX_PROPERTIES_ENCODE_NESTED_STYLE, ); // Then I expect an error EXPECT_EQ(ENOMEM, status); @@ -100,7 +100,7 @@ TEST_F(PropertiesEncodingErrorInjectionTestSuite, EncodeErrorTest) { celix_ei_expect_json_object((void*)celix_properties_saveToString, 2, nullptr); // And I call celix_properties_saveToString using NESTED encoding (whitebox-knowledge) -status = celix_properties_saveToString(props, CELIX_PROPERTIES_ENCODE_NESTED, ); +status = celix_properties_saveToString(props, CELIX_PROPERTIES_ENCODE_NESTED_STYLE, ); // Then I expect an error EXPECT_EQ(ENOMEM, status); @@ -109,7 +109,7 @@ TEST_F(PropertiesEncodingErrorInjectionTestSuite, EncodeErrorTest) { celix_ei_expect_json_object_set_new((void*)celix_properties_saveToString, 2, -1); // And I call celix_properties_saveToString using NESTED encoding (whitebox-knowledge) -status = celix_properties_saveToString(props, CELIX_PROPERTIES_ENCODE_NESTED, ); +status = celix_properties_saveToString(props, CELIX_PROPERTIES_ENCODE_NESTED_STYLE, ); // Then I expect an error EXPECT_EQ(ENOMEM, status); @@ -118,7 +118,7 @@ TEST_F(PropertiesEncodingErrorInjectionTestSuite, EncodeErrorTest) { celix_ei_expect_json_string((void*)celix_properties_saveToString, 3, nullptr); // And I call celix_properties_saveToString using NESTED encoding (whitebox-knowledge) -status = celix_properties_saveToString(props, CELIX_PROPERTIES_ENCODE_NESTED, ); +status = celix_properties_saveToString(props, CELIX_PROPERTIES_ENCODE_NESTED_STYLE, ); // Then I expect an error EXPECT_EQ(ENOMEM, status); @@ -127,7 +127,7 @@ TEST_F(PropertiesEncodingErrorInjectionTestSuite, EncodeErrorTest) { celix_ei_expect_json_object_set_new((void*)celix_properties_saveToString, 3, -1); // And I call celix_properties_saveToString using FLAT encoding (whitebox-knowledge) -status = celix_properties_saveToString(props, CELIX_PROPERTIES_ENCODE_FLAT, ); +status = celix_properties_saveToString(props, CELIX_PROPERTIES_ENCODE_FLAT_STYLE, ); // Then I expect an error EXPECT_EQ(ENOMEM, status); diff --git a/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc index bece2147..d4ff8e17 100644 --- a/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc +++ b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc @@ -206,7 +206,7 @@ TEST_F(PropertiesSerializationTestSuite, SaveJPathKeysTest) { FILE* stream = open_memstream(, ); //When saving
(celix) branch feature/685-properties-json-serialization updated: gh-685: Separate version ei testing to prevent own ei code inteference
This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/685-properties-json-serialization in repository https://gitbox.apache.org/repos/asf/celix.git The following commit(s) were added to refs/heads/feature/685-properties-json-serialization by this push: new 56c67673 gh-685: Separate version ei testing to prevent own ei code inteference 56c67673 is described below commit 56c67673b6d4dc15ac710113719389656246241d Author: Pepijn Noltes AuthorDate: Sun Apr 14 19:34:09 2024 +0200 gh-685: Separate version ei testing to prevent own ei code inteference --- libs/utils/gtest/CMakeLists.txt | 14 +- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/libs/utils/gtest/CMakeLists.txt b/libs/utils/gtest/CMakeLists.txt index 08be2b58..48f820a6 100644 --- a/libs/utils/gtest/CMakeLists.txt +++ b/libs/utils/gtest/CMakeLists.txt @@ -105,6 +105,19 @@ if (EI_TESTS) add_test(NAME test_utils_celix_err_with_ei COMMAND test_utils_celix_err_with_ei) setup_target_for_coverage(test_utils_celix_err_with_ei SCAN_DIR ..) +#Note testing version seperated, otherwise version calls are already wrapped +add_executable(test_utils_version_with_ei +src/VersionErrorInjectionTestSuite.cc +) +target_link_libraries(test_utils_version_with_ei PRIVATE +utils_cut +Celix::malloc_ei +Celix::asprintf_ei +Celix::utils_ei +GTest::gtest GTest::gtest_main +) +add_test(NAME test_utils_version_with_ei COMMAND test_utils_version_with_ei) +setup_target_for_coverage(test_utils_version_with_ei SCAN_DIR ..) #Note testing array list seperated, otherwise array list calls are already wrapped add_executable(test_utils_array_list_with_ei @@ -124,7 +137,6 @@ if (EI_TESTS) src/FileUtilsErrorInjectionTestSuite.cc src/ConvertUtilsErrorInjectionTestSuite.cc src/PropertiesErrorInjectionTestSuite.cc -src/VersionErrorInjectionTestSuite.cc src/HashMapErrorInjectionTestSuite.cc src/FilterErrorInjectionTestSuite.cc src/PropertiesEncodingErrorInjectionTestSuite.cc
(celix) 03/03: gh-685: Add error injection test for properties encoding
This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/685-properties-json-serialization in repository https://gitbox.apache.org/repos/asf/celix.git commit 99e503aa62a02173818a7d518c102f7dd8edaa12 Author: Pepijn Noltes AuthorDate: Sun Apr 14 16:54:16 2024 +0200 gh-685: Add error injection test for properties encoding --- conanfile.py | 4 +- libs/error_injector/jansson/CMakeLists.txt | 2 + libs/error_injector/jansson/include/jansson_ei.h | 2 + libs/error_injector/jansson/src/jansson_ei.cc | 58 ++-- .../error_injector/celix_version/CMakeLists.txt| 1 + .../celix_version/include/celix_version_ei.h | 2 + .../celix_version/src/celix_version_ei.cc | 7 + libs/utils/gtest/CMakeLists.txt| 2 + .../PropertiesEncodingErrorInjectionTestSuite.cc | 305 + .../utils/gtest/src/PropertiesEncodingTestSuite.cc | 30 +- libs/utils/src/properties.c| 3 +- libs/utils/src/properties_encoding.c | 53 ++-- 12 files changed, 403 insertions(+), 66 deletions(-) diff --git a/conanfile.py b/conanfile.py index 609082c8..63d9ac00 100644 --- a/conanfile.py +++ b/conanfile.py @@ -309,7 +309,7 @@ class CelixConan(ConanFile): self.options['openssl'].shared = True if self.options.build_celix_dfi: self.options['libffi'].shared = True -if self.options.build_celix_dfi or self.options.build_celix_etcdlib: +if self.options.build_utils or self.options.build_celix_dfi or self.options.build_celix_etcdlib: self.options['jansson'].shared = True def requirements(self): @@ -332,7 +332,7 @@ class CelixConan(ConanFile): self.requires("civetweb/1.16") if self.options.build_celix_dfi: self.requires("libffi/[>=3.2.1 <4.0.0]") -if self.options.build_celix_dfi or self.options.build_celix_etcdlib: +if self.option.build_utils or self.options.build_celix_dfi or self.options.build_celix_etcdlib: self.requires("jansson/[>=2.12 <3.0.0]") if self.options.build_rsa_discovery_zeroconf: # TODO: To be replaced with mdnsresponder/1790.80.10, resolve some problems of mdnsresponder diff --git a/libs/error_injector/jansson/CMakeLists.txt b/libs/error_injector/jansson/CMakeLists.txt index b536956a..b093901d 100644 --- a/libs/error_injector/jansson/CMakeLists.txt +++ b/libs/error_injector/jansson/CMakeLists.txt @@ -35,5 +35,7 @@ target_link_options(jansson_ei INTERFACE LINKER:--wrap,json_integer LINKER:--wrap,json_string LINKER:--wrap,json_real +LINKER:--wrap,json_vsprintf +LINKER:--wrap,json_sprintf ) add_library(Celix::jansson_ei ALIAS jansson_ei) diff --git a/libs/error_injector/jansson/include/jansson_ei.h b/libs/error_injector/jansson/include/jansson_ei.h index 60f04e45..167ace85 100644 --- a/libs/error_injector/jansson/include/jansson_ei.h +++ b/libs/error_injector/jansson/include/jansson_ei.h @@ -34,6 +34,8 @@ CELIX_EI_DECLARE(json_array_append_new, int); CELIX_EI_DECLARE(json_integer, json_t*); CELIX_EI_DECLARE(json_string, json_t*); CELIX_EI_DECLARE(json_real, json_t*); +CELIX_EI_DECLARE(json_vsprintf,json_t*); +CELIX_EI_DECLARE(json_sprintf, json_t*); #ifdef __cplusplus } diff --git a/libs/error_injector/jansson/src/jansson_ei.cc b/libs/error_injector/jansson/src/jansson_ei.cc index 57033c0c..1d820629 100644 --- a/libs/error_injector/jansson/src/jansson_ei.cc +++ b/libs/error_injector/jansson/src/jansson_ei.cc @@ -23,69 +23,87 @@ extern "C" { -size_t __real_json_array_size(const json_t *array); +size_t __real_json_array_size(const json_t* array); CELIX_EI_DEFINE(json_array_size, size_t) -size_t __wrap_json_array_size(const json_t *array) { +size_t __wrap_json_array_size(const json_t* array) { CELIX_EI_IMPL(json_array_size); return __real_json_array_size(array); } -char *__real_json_dumps(const json_t *json, size_t flags); +char* __real_json_dumps(const json_t* json, size_t flags); CELIX_EI_DEFINE(json_dumps, char*) -char *__wrap_json_dumps(const json_t *json, size_t flags) { +char* __wrap_json_dumps(const json_t* json, size_t flags) { CELIX_EI_IMPL(json_dumps); return __real_json_dumps(json, flags); } -json_t *__real_json_object(void); +json_t* __real_json_object(void); CELIX_EI_DEFINE(json_object, json_t*) -json_t *__wrap_json_object(void) { +json_t* __wrap_json_object(void) { CELIX_EI_IMPL(json_object); return __real_json_object(); } -int __real_json_object_set_new(json_t *object, const char *key, json_t *value); +int __real_json_object_set_new(json_t* object, const char* key, json_t* value); CELIX_EI_DEFINE(json_object_set_new, int) -int __wrap_json_object_set_new(json_t *object, const char *key, json_t *value) { -json_auto_t *val = value; +int
(celix) 02/03: gh-685: Add additional prop encoding test based on test cov
This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/685-properties-json-serialization in repository https://gitbox.apache.org/repos/asf/celix.git commit 0ceaeb8f0f7eddf0e05b156e6c61f583db07ea4b Author: Pepijn Noltes AuthorDate: Sat Apr 13 19:59:35 2024 +0200 gh-685: Add additional prop encoding test based on test cov --- .../utils/gtest/src/PropertiesEncodingTestSuite.cc | 132 +++-- libs/utils/src/properties_encoding.c | 86 +++--- 2 files changed, 161 insertions(+), 57 deletions(-) diff --git a/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc index 84ed5d0a..b854e183 100644 --- a/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc +++ b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc @@ -76,7 +76,7 @@ TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithSingleValuesTest) { EXPECT_NE(nullptr, strstr(buf, R"("key3":3)")) << "JSON: " << buf; EXPECT_NE(nullptr, strstr(buf, R"("key4":4.0)")) << "JSON: " << buf; EXPECT_NE(nullptr, strstr(buf, R"("key5":true)")) << "JSON: " << buf; -EXPECT_NE(nullptr, strstr(buf, R"("key6":"celix_version<1.2.3.qualifier>")")) << "JSON: " << buf; +EXPECT_NE(nullptr, strstr(buf, R"("key6":"version<1.2.3.qualifier>")")) << "JSON: " << buf; //And the buf is a valid JSON object json_error_t error; @@ -150,7 +150,7 @@ TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithArrayListsTest) { EXPECT_NE(nullptr, strstr(buf, R"("key2":[1,2])")) << "JSON: " << buf; EXPECT_NE(nullptr, strstr(buf, R"("key3":[1.0,2.0])")) << "JSON: " << buf; EXPECT_NE(nullptr, strstr(buf, R"("key4":[true,false])")) << "JSON: " << buf; -EXPECT_NE(nullptr, strstr(buf, R"("key5":["celix_version<1.2.3.qualifier>","celix_version<4.5.6.qualifier>"])")) +EXPECT_NE(nullptr, strstr(buf, R"("key5":["version<1.2.3.qualifier>","version<4.5.6.qualifier>"])")) << "JSON: " << buf; // And the buf is a valid JSON object @@ -260,9 +260,7 @@ TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithKeyNamesWithSlashesTe //Given a properties set with key names with slashes celix_autoptr(celix_properties_t) props = celix_properties_create(); celix_properties_set(props, "a/key/name/with/slashes", "value1"); -//TODO test separately celix_properties_set(props, "/", "value2"); celix_properties_set(props, "/keyThatStartsWithSlash", "value3"); -//TODO test separately celix_properties_set(props, "//keyThatStartsWithDoubleSlashes", "value4"); celix_properties_set(props, "keyThatEndsWithSlash/", "value5"); celix_properties_set(props, "keyThatEndsWithDoubleSlashes//", "value6"); celix_properties_set(props, "key//With//Double//Slashes", "value7"); @@ -397,6 +395,24 @@ TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithPrettyPrintTest) { EXPECT_STREQ(expected, output); } +TEST_F(PropertiesSerializationTestSuite, SaveWithInvalidStreamTest) { +celix_autoptr(celix_properties_t) properties = celix_properties_create(); +celix_properties_set(properties, "key", "value"); + +// Saving properties with invalid stream will fail +auto status = celix_properties_save(properties, "/non-existing/no/rights/file.json", 0); +EXPECT_EQ(CELIX_FILE_IO_EXCEPTION, status); +EXPECT_EQ(1, celix_err_getErrorCount()); + +auto* readStream = fopen("/dev/null", "r"); +status = celix_properties_saveToStream(properties, readStream, 0); +EXPECT_EQ(CELIX_FILE_IO_EXCEPTION, status); +EXPECT_EQ(2, celix_err_getErrorCount()); +fclose(readStream); + +celix_err_printErrors(stderr, "Error: ", "\n"); +} + TEST_F(PropertiesSerializationTestSuite, LoadEmptyPropertiesTest) { //Given an empty JSON object const char* json = "{}"; @@ -420,7 +436,7 @@ TEST_F(PropertiesSerializationTestSuite, LoadPropertiesWithSingleValuesTest) { "longKey":42, "doubleKey":2.0, "boolKey":true, -"versionKey":"celix_version<1.2.3.qualifier>" +"versionKey":"version<1.2.3.qualifier>" })"; //And a stream with the JSON object @@ -450,7 +466,7 @@ TEST_F(PropertiesSerializationTestSuite, LoadPropertiesWithArrayListsTest) { "intArr":[1,2], "realArr":[1.0,2.0], "boolArr":[true,false], - "versionArr":["celix_version<1.2.3.qualifier>","celix_version<4.5.6.qualifier>"], +"versionArr":["version<1.2.3.qualifier>","version<4.5.6.qualifier>"], "mixedRealAndIntArr1":[1,2.0,2,3.0], "mixedRealAndIntArr2":[1.0,2,2.0,3] })"; @@ -714,6 +730,7 @@ TEST_F(PropertiesSerializationTestSuite, LoadPropertiesEscapedSlashesTest) { TEST_F(PropertiesSerializationTestSuite, LoadPropertiesWithAndWithoutStrictFlagTest) { auto invalidInputs = { R"({"mixedArr":["string", true]})", // Mixed array gives
(celix) 01/03: gh-685: Add support for a flat and nested flag for prop encoding
This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a commit to branch feature/685-properties-json-serialization in repository https://gitbox.apache.org/repos/asf/celix.git commit 8e03a828be1f707df23b3fe77b62d491a3adf527 Author: Pepijn Noltes AuthorDate: Wed Apr 10 23:27:59 2024 +0200 gh-685: Add support for a flat and nested flag for prop encoding --- libs/utils/gtest/src/CelixUtilsTestSuite.cc| 32 ++ .../utils/gtest/src/PropertiesEncodingTestSuite.cc | 435 ++--- libs/utils/include/celix_properties.h | 81 ++-- libs/utils/include/celix_utils.h | 56 +++ libs/utils/src/properties_encoding.c | 208 +++--- 5 files changed, 588 insertions(+), 224 deletions(-) diff --git a/libs/utils/gtest/src/CelixUtilsTestSuite.cc b/libs/utils/gtest/src/CelixUtilsTestSuite.cc index 26bef64b..95e143d4 100644 --- a/libs/utils/gtest/src/CelixUtilsTestSuite.cc +++ b/libs/utils/gtest/src/CelixUtilsTestSuite.cc @@ -315,6 +315,38 @@ TEST_F(UtilsTestSuite, WriteOrCreateStringTest) { celix_utils_freeStringIfNotEqual(buffer2, out2); } +TEST_F(UtilsTestSuite, WriteOrCreateStringGuardTest) { +// Given a small buffer +char buffer[16]; + +{ +// When writing a string that fits in the buffer +char* str = celix_utils_writeOrCreateString(buffer, sizeof(buffer), "abc"); + +// Then the str is equal to the buffer (in this case no malloc was needed) +EXPECT_EQ(buffer, str); + +// And using celix_auto with a string guard +celix_auto(celix_utils_string_guard_t) guard = celix_utils_stringGuard_init(buffer, str); + +// Then the guard will not free the string when going out of scope +} + +{ +// When writing a string that does not fit in the buffer +char* str = celix_utils_writeOrCreateString( +buffer, sizeof(buffer), "abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"); + +// Then the str is not equal to the buffer (in this case a malloc was needed) +EXPECT_NE(buffer, str); + +// And using celix_auto with a string guard +celix_auto(celix_utils_string_guard_t) guard = celix_utils_stringGuard_init(buffer, str); + +// Then the guard will free the string when going out of scope +} +} + TEST_F(UtilsTestSuite, StrDupAndStrLenTest) { celix_autofree char* str = celix_utils_strdup("abc"); ASSERT_NE(nullptr, str); diff --git a/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc index d346f5f6..84ed5d0a 100644 --- a/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc +++ b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc @@ -32,7 +32,7 @@ class PropertiesSerializationTestSuite : public ::testing::Test { PropertiesSerializationTestSuite() { celix_err_resetErrors(); } }; -TEST_F(PropertiesSerializationTestSuite, EncodeEmptyPropertiesTest) { +TEST_F(PropertiesSerializationTestSuite, SaveEmptyPropertiesTest) { //Given an empty properties object celix_autoptr(celix_properties_t) props = celix_properties_create(); @@ -41,8 +41,8 @@ TEST_F(PropertiesSerializationTestSuite, EncodeEmptyPropertiesTest) { size_t bufLen = 0; FILE* stream = open_memstream(, ); -//When encoding the properties to the stream -auto status = celix_properties_encodeToStream(props, stream, 0); +//When saving the properties to the stream +auto status = celix_properties_saveToStream(props, stream, 0); ASSERT_EQ(CELIX_SUCCESS, status); //Then the stream contains an empty JSON object @@ -50,7 +50,7 @@ TEST_F(PropertiesSerializationTestSuite, EncodeEmptyPropertiesTest) { EXPECT_STREQ("{}", buf); } -TEST_F(PropertiesSerializationTestSuite, EncodePropertiesWithSingleValuesTest) { +TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithSingleValuesTest) { //Given a properties object with single values celix_autoptr(celix_properties_t) props = celix_properties_create(); celix_properties_set(props, "key1", "value1"); @@ -65,8 +65,8 @@ TEST_F(PropertiesSerializationTestSuite, EncodePropertiesWithSingleValuesTest) { size_t bufLen = 0; FILE* stream = open_memstream(, ); -//When encoding the properties to the stream -auto status = celix_properties_encodeToStream(props, stream, 0); +//When saving the properties to the stream +auto status = celix_properties_saveToStream(props, stream, 0); ASSERT_EQ(CELIX_SUCCESS, status); //Then the stream contains the JSON representation snippets of the properties @@ -85,7 +85,7 @@ TEST_F(PropertiesSerializationTestSuite, EncodePropertiesWithSingleValuesTest) { json_decref(root); } -TEST_F(PropertiesSerializationTestSuite, EncodePropertiesWithNaNAndInfValuesTest) { +TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithNaNAndInfValuesTest)
(celix) branch feature/685-properties-json-serialization updated (72c785df -> 99e503aa)
This is an automated email from the ASF dual-hosted git repository. pnoltes pushed a change to branch feature/685-properties-json-serialization in repository https://gitbox.apache.org/repos/asf/celix.git from 72c785df gh-685: Add initial setup for properties decode flags new 8e03a828 gh-685: Add support for a flat and nested flag for prop encoding new 0ceaeb8f gh-685: Add additional prop encoding test based on test cov new 99e503aa gh-685: Add error injection test for properties encoding The 3 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "add" were already present in the repository and have only been added to this reference. Summary of changes: conanfile.py | 4 +- libs/error_injector/jansson/CMakeLists.txt | 2 + libs/error_injector/jansson/include/jansson_ei.h | 2 + libs/error_injector/jansson/src/jansson_ei.cc | 58 ++- .../error_injector/celix_version/CMakeLists.txt| 1 + .../celix_version/include/celix_version_ei.h | 2 + .../celix_version/src/celix_version_ei.cc | 7 + libs/utils/gtest/CMakeLists.txt| 2 + libs/utils/gtest/src/CelixUtilsTestSuite.cc| 32 ++ .../PropertiesEncodingErrorInjectionTestSuite.cc | 305 +++ .../utils/gtest/src/PropertiesEncodingTestSuite.cc | 571 +++-- libs/utils/include/celix_properties.h | 81 ++- libs/utils/include/celix_utils.h | 56 ++ libs/utils/src/properties.c| 3 +- libs/utils/src/properties_encoding.c | 301 +++ 15 files changed, 1116 insertions(+), 311 deletions(-) create mode 100644 libs/utils/gtest/src/PropertiesEncodingErrorInjectionTestSuite.cc