(celix) 05/06: gh-685: Rename prop serialization sources to 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 77cd6b37e7bae39663b20dee7c6fb31593a00c89 Author: Pepijn Noltes AuthorDate: Tue Apr 9 20:05:33 2024 +0200 gh-685: Rename prop serialization sources to prop encoding --- libs/utils/CMakeLists.txt | 2 +- libs/utils/gtest/CMakeLists.txt | 2 +- ...opertiesSerializationTestSuite.cc => PropertiesEncodingTestSuite.cc} | 0 libs/utils/src/{properties_serialization.c => properties_encoding.c}| 0 4 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libs/utils/CMakeLists.txt b/libs/utils/CMakeLists.txt index 4180b48b..cec80f41 100644 --- a/libs/utils/CMakeLists.txt +++ b/libs/utils/CMakeLists.txt @@ -30,7 +30,7 @@ if (UTILS) src/version.c src/version_range.c src/properties.c -src/properties_serialization.c +src/properties_encoding.c src/utils.c src/filter.c src/celix_log_level.c diff --git a/libs/utils/gtest/CMakeLists.txt b/libs/utils/gtest/CMakeLists.txt index 62c1ac0c..11c6ec00 100644 --- a/libs/utils/gtest/CMakeLists.txt +++ b/libs/utils/gtest/CMakeLists.txt @@ -29,7 +29,7 @@ add_executable(test_utils src/CelixUtilsTestSuite.cc src/ConvertUtilsTestSuite.cc src/PropertiesTestSuite.cc -src/PropertiesSerializationTestSuite.cc +src/PropertiesEncodingTestSuite.cc src/VersionTestSuite.cc src/ErrTestSuite.cc src/ThreadsTestSuite.cc diff --git a/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc similarity index 100% rename from libs/utils/gtest/src/PropertiesSerializationTestSuite.cc rename to libs/utils/gtest/src/PropertiesEncodingTestSuite.cc diff --git a/libs/utils/src/properties_serialization.c b/libs/utils/src/properties_encoding.c similarity index 100% rename from libs/utils/src/properties_serialization.c rename to libs/utils/src/properties_encoding.c
(celix) 03/06: gh-685: Add json prop loading for primitive and initial arr.
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 de0725649450bcbcfbc8145d652b7fb0ea6f0716 Author: Pepijn Noltes AuthorDate: Mon Apr 8 23:03:03 2024 +0200 gh-685: Add json prop loading for primitive and initial arr. --- .../gtest/src/PropertiesSerializationTestSuite.cc | 311 ++- libs/utils/src/properties_serialization.c | 420 ++--- 2 files changed, 653 insertions(+), 78 deletions(-) diff --git a/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc b/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc index 99cbeceb..a5d6a1df 100644 --- a/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc +++ b/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc @@ -17,6 +17,7 @@ * under the License. */ +#include #include #include @@ -49,23 +50,7 @@ TEST_F(PropertiesSerializationTestSuite, SaveEmptyPropertiesTest) { EXPECT_STREQ("{}", buf); } -TEST_F(PropertiesSerializationTestSuite, LoadEmptyPropertiesTest) { -//Given an empty JSON object -const char* json = "{}"; -FILE* stream = fmemopen((void*)json, strlen(json), "r"); - -//When loading the properties from the stream -celix_autoptr(celix_properties_t) props = nullptr; -auto status = celix_properties_loadFromStream(stream, ); -EXPECT_EQ(CELIX_SUCCESS, status); - -//Then the properties object is empty -EXPECT_EQ(0, celix_properties_size(props)); - -fclose(stream); -} - -TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithSingelValuesTest) { +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"); @@ -102,14 +87,115 @@ TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithSingelValuesTest) { json_decref(root); } +TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithNaNAndInfValuesTest) { +//Given a NAN, INF and -INF value +auto keys = {"NAN", "INF", "-INF"}; +for (const auto& key : keys) { +//For every value + +//Given a properties object with a NAN, INF or -INF value +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 the stream fails, because JSON does not support NAN, INF and -INF +celix_err_resetErrors(); +auto status = celix_properties_saveToStream(props, stream); +EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); + +//And an error msg is added to celix_err +EXPECT_EQ(1, celix_err_getErrorCount()); +} +} + + TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithArrayListsTest) { -//Given a properties object with array list values +// 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); -//TODO long, double, bool, version +celix_array_list_t* list2 = celix_arrayList_createLongArray(); +celix_arrayList_addLong(list2, 1); +celix_arrayList_addLong(list2, 2); +celix_properties_assignArrayList(props, "key2", list2); +celix_array_list_t* list3 = celix_arrayList_createDoubleArray(); +celix_arrayList_addDouble(list3, 1.0); +celix_arrayList_addDouble(list3, 2.0); +celix_properties_assignArrayList(props, "key3", list3); +celix_array_list_t* list4 = celix_arrayList_createBoolArray(); +celix_arrayList_addBool(list4, true); +celix_arrayList_addBool(list4, false); +celix_properties_assignArrayList(props, "key4", list4); +celix_array_list_t* list5 = celix_arrayList_createVersionArray(); +celix_arrayList_addVersion(list5, celix_version_create(1, 2, 3, "qualifier")); +celix_arrayList_addVersion(list5, celix_version_create(4, 5, 6, "qualifier")); +celix_properties_assignArrayList(props, "key5", list5); + +// And an in-memory stream +celix_autofree char* buf = nullptr; +size_t bufLen = 0; +FILE* stream = open_memstream(, ); + +// When saving the properties to the stream +auto status = celix_properties_saveToStream(props, stream); +EXPECT_EQ(CELIX_SUCCESS, status); + +// Then the stream contains the JSON representation snippets of the properties +fclose(stream); +EXPECT_NE(nullptr,
(celix) 06/06: gh-685: Add initial setup for properties decode flags
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 72c785dfc706630c87322604b4363542ed9c0f5f Author: Pepijn Noltes AuthorDate: Tue Apr 9 23:16:02 2024 +0200 gh-685: Add initial setup for properties decode flags --- .../utils/gtest/src/PropertiesEncodingTestSuite.cc | 197 +++-- libs/utils/gtest/src/PropertiesTestSuite.cc| 7 + libs/utils/include/celix_properties.h | 14 +- libs/utils/src/properties_encoding.c | 81 ++--- 4 files changed, 217 insertions(+), 82 deletions(-) diff --git a/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc index 4aa2469d..d346f5f6 100644 --- a/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc +++ b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc @@ -252,6 +252,49 @@ TEST_F(PropertiesSerializationTestSuite, EncodeJPathKeysWithCollisionTest) { json_decref(root); } + +//TODO check desired behaviour, currently every "/" leads to a new object (except if an collision occurs) +//TEST_F(PropertiesSerializationTestSuite, EncodePropertiesWithSpecialKeyNamesTest) { +////Given a properties set with special key names (slashes) +//celix_autoptr(celix_properties_t) props = celix_properties_create(); +//celix_properties_set(props, "/", "value1"); +//celix_properties_set(props, "keyThatEndsWithSlash/", "value2"); +//celix_properties_set(props, "key//With//Double//Slash", "value3"); +//celix_properties_set(props, "object/", "value5"); +//celix_properties_set(props, "object//", "value4"); +//celix_properties_set(props, "object/keyThatEndsWithSlash/", "value6"); +//celix_properties_set(props, "object/key//With//Double//Slash", "value7"); +// +////And an in-memory stream +//celix_autofree char* buf = nullptr; +//size_t bufLen = 0; +//FILE* stream = open_memstream(, ); +// +////When encoding the properties to the stream +//auto status = celix_properties_encodeToStream(props, stream, 0); +//ASSERT_EQ(CELIX_SUCCESS, status); +// +//std::cout << buf << std::endl; +// +////Then the stream contains the JSON representation snippets of the properties +//fclose(stream); +//EXPECT_NE(nullptr, strstr(buf, R"("/":"value1")")) << "JSON: " << buf; +//EXPECT_NE(nullptr, strstr(buf, R"("keyThatEndsWithSlash/":"value2")")) << "JSON: " << buf; +//EXPECT_NE(nullptr, strstr(buf, R"("key//With//Double//Slash":"value3")")) << "JSON: " << buf; +//EXPECT_NE(nullptr, strstr(buf, R"("object/":"value5")")) << "JSON: " << buf; +//EXPECT_NE(nullptr, strstr(buf, R"("/":"value5")")) << "JSON: " << buf; //child of object +//EXPECT_NE(nullptr, strstr(buf, R"("keyThatEndsWithSlash/":"value6")")) << "JSON: " << buf; //child of object +//EXPECT_NE(nullptr, strstr(buf, R"("key//With//Double//Slash":"value7")")) << "JSON: " << buf; //child of object +// +// +////And the buf is a valid JSON object +//json_error_t error; +//json_t* root = json_loads(buf, 0, ); +//EXPECT_NE(nullptr, root) << "Unexpected JSON error: " << error.text; +//json_decref(root); +//} + + TEST_F(PropertiesSerializationTestSuite, DecodeEmptyPropertiesTest) { //Given an empty JSON object const char* json = "{}"; @@ -392,8 +435,6 @@ TEST_F(PropertiesSerializationTestSuite, DecodePropertiesWithInvalidInputTest) { R"({)",// invalid JSON (caught by jansson) R"([])", // unsupported JSON (top level array not supported) R"(42)", // invalid JSON (caught by jansson) -R"({"mixedArr":["string", true]})", // Mixed array, not supported -R"({"key1":null})", // Null value, not supported }; for (auto& invalidInput: invalidInputs) { //Given an invalid JSON object @@ -477,7 +518,9 @@ TEST_F(PropertiesSerializationTestSuite, DecodePropertiesWithNestedObjectsAndJPa "key1":true } }, -"object1/object2/key1":6 +"object1/object2/key1":6, +"key2":2, +"key2":3 })"; // And a stream with the JSON object @@ -487,7 +530,22 @@ TEST_F(PropertiesSerializationTestSuite, DecodePropertiesWithNestedObjectsAndJPa celix_autoptr(celix_properties_t) props = nullptr; auto status = celix_properties_decodeFromStream(stream, 0, ); -// Then loading fails +// Then loading succeeds +ASSERT_EQ(CELIX_SUCCESS, status); + +// And the properties object contains the last values of the jpath keys +EXPECT_EQ(2, celix_properties_size(props)); +EXPECT_EQ(6, celix_properties_getLong(props, "object1/object2/key1", 0)); +EXPECT_EQ(3, celix_properties_getLong(props, "key2", 0)); + +// When the stream is reset
(celix) 02/06: gh-685: Add jansson dep for simple properties save/load
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 9511610bb2c7379570c1bd3a9705202c0723a865 Author: Pepijn Noltes AuthorDate: Tue Apr 2 20:25:09 2024 +0200 gh-685: Add jansson dep for simple properties save/load --- libs/utils/CMakeLists.txt | 3 +- .../gtest/src/PropertiesSerializationTestSuite.cc | 70 - libs/utils/src/properties.c| 2 +- libs/utils/src/properties_serialization.c | 112 - 4 files changed, 180 insertions(+), 7 deletions(-) diff --git a/libs/utils/CMakeLists.txt b/libs/utils/CMakeLists.txt index 064c9683..4180b48b 100644 --- a/libs/utils/CMakeLists.txt +++ b/libs/utils/CMakeLists.txt @@ -18,6 +18,7 @@ celix_subproject(UTILS "Option to enable building the Utilities library" ON) if (UTILS) find_package(libzip REQUIRED) +find_package(jansson REQUIRED) #TODO add jansson dep info to build (conan) and documentation info set(MEMSTREAM_SOURCES ) set(MEMSTREAM_INCLUDES ) @@ -42,7 +43,7 @@ if (UTILS) src/celix_cleanup.c ${MEMSTREAM_SOURCES} ) -set(UTILS_PRIVATE_DEPS libzip::zip) +set(UTILS_PRIVATE_DEPS libzip::zip jansson::jansson) set(UTILS_PUBLIC_DEPS) add_library(utils SHARED ${UTILS_SRC}) diff --git a/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc b/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc index d3bf6aa0..99cbeceb 100644 --- a/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc +++ b/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc @@ -18,9 +18,11 @@ */ #include +#include #include "celix_err.h" #include "celix_properties.h" +#include "celix_stdlib_cleanup.h" using ::testing::MatchesRegex; @@ -34,7 +36,7 @@ TEST_F(PropertiesSerializationTestSuite, SaveEmptyPropertiesTest) { celix_autoptr(celix_properties_t) props = celix_properties_create(); //And an in-memory stream -char* buf = nullptr; +celix_autofree char* buf = nullptr; size_t bufLen = 0; FILE* stream = open_memstream(, ); @@ -62,3 +64,69 @@ TEST_F(PropertiesSerializationTestSuite, LoadEmptyPropertiesTest) { fclose(stream); } + +TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithSingelValuesTest) { +//Given a properties object with single values +celix_autoptr(celix_properties_t) props = celix_properties_create(); +celix_properties_set(props, "key1", "value1"); +celix_properties_set(props, "key2", "value2"); +celix_properties_setLong(props, "key3", 3); +celix_properties_setDouble(props, "key4", 4.0); +celix_properties_setBool(props, "key5", true); +celix_properties_assignVersion(props, "key6", celix_version_create(1, 2, 3, "qualifier")); + +//And an in-memory stream +celix_autofree char* buf = nullptr; +size_t bufLen = 0; +FILE* stream = open_memstream(, ); + +//When saving the properties to the stream +auto status = celix_properties_saveToStream(props, stream); +EXPECT_EQ(CELIX_SUCCESS, status); + +//Then the stream contains the JSON representation snippets of the properties +fclose(stream); +EXPECT_NE(nullptr, strstr(buf, R"("key1":"value1")")) << "JSON: " << buf; +EXPECT_NE(nullptr, strstr(buf, R"("key2":"value2")")) << "JSON: " << buf; +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; + +//TODO how are versions serialized? A string representation is needed to reconstruct the version from JSON +EXPECT_NE(nullptr, strstr(buf, R"("key6":"celix_version<1.2.3.qualifier>")")) << "JSON: " << buf; + +//And the buf is a valid JSON object +json_error_t error; +json_t* root = json_loads(buf, 0, ); +EXPECT_NE(nullptr, root) << "Unexpected JSON error: " << error.text; +json_decref(root); +} + +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); +//TODO long, double, bool, version + +//And an in-memory stream +celix_autofree char* buf = nullptr; +size_t bufLen = 0; +FILE* stream = open_memstream(, ); + +//When saving the properties to the stream +auto status = celix_properties_saveToStream(props, stream); +
(celix) 01/06: gh-685: Initial properties save/load setup
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 3acdb746e55738f45134a6412602f66fc9b80a39 Author: Pepijn Noltes AuthorDate: Mon Apr 1 20:28:02 2024 +0200 gh-685: Initial properties save/load setup --- libs/utils/CMakeLists.txt | 1 + libs/utils/gtest/CMakeLists.txt| 1 + .../gtest/src/PropertiesSerializationTestSuite.cc | 64 ++ libs/utils/include/celix_properties.h | 6 ++ libs/utils/src/properties_serialization.c | 35 5 files changed, 107 insertions(+) diff --git a/libs/utils/CMakeLists.txt b/libs/utils/CMakeLists.txt index e1b49835..064c9683 100644 --- a/libs/utils/CMakeLists.txt +++ b/libs/utils/CMakeLists.txt @@ -29,6 +29,7 @@ if (UTILS) src/version.c src/version_range.c src/properties.c +src/properties_serialization.c src/utils.c src/filter.c src/celix_log_level.c diff --git a/libs/utils/gtest/CMakeLists.txt b/libs/utils/gtest/CMakeLists.txt index d04f9e30..62c1ac0c 100644 --- a/libs/utils/gtest/CMakeLists.txt +++ b/libs/utils/gtest/CMakeLists.txt @@ -29,6 +29,7 @@ add_executable(test_utils src/CelixUtilsTestSuite.cc src/ConvertUtilsTestSuite.cc src/PropertiesTestSuite.cc +src/PropertiesSerializationTestSuite.cc src/VersionTestSuite.cc src/ErrTestSuite.cc src/ThreadsTestSuite.cc diff --git a/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc b/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc new file mode 100644 index ..d3bf6aa0 --- /dev/null +++ b/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc @@ -0,0 +1,64 @@ +/* + * 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. + */ + +#include + +#include "celix_err.h" +#include "celix_properties.h" + +using ::testing::MatchesRegex; + +class PropertiesSerializationTestSuite : public ::testing::Test { + public: +PropertiesSerializationTestSuite() { celix_err_resetErrors(); } +}; + +TEST_F(PropertiesSerializationTestSuite, SaveEmptyPropertiesTest) { +//Given an empty properties object +celix_autoptr(celix_properties_t) props = celix_properties_create(); + +//And an in-memory stream +char* buf = nullptr; +size_t bufLen = 0; +FILE* stream = open_memstream(, ); + +//When saving the properties to the stream +auto status = celix_properties_saveToStream(props, stream); +EXPECT_EQ(CELIX_SUCCESS, status); + +//Then the stream contains an empty JSON object +fclose(stream); +EXPECT_STREQ("{}", buf); +} + +TEST_F(PropertiesSerializationTestSuite, LoadEmptyPropertiesTest) { +//Given an empty JSON object +const char* json = "{}"; +FILE* stream = fmemopen((void*)json, strlen(json), "r"); + +//When loading the properties from the stream +celix_autoptr(celix_properties_t) props = nullptr; +auto status = celix_properties_loadFromStream(stream, ); +EXPECT_EQ(CELIX_SUCCESS, status); + +//Then the properties object is empty +EXPECT_EQ(0, celix_properties_size(props)); + +fclose(stream); +} diff --git a/libs/utils/include/celix_properties.h b/libs/utils/include/celix_properties.h index 39e87c66..5903ecaa 100644 --- a/libs/utils/include/celix_properties.h +++ b/libs/utils/include/celix_properties.h @@ -180,6 +180,12 @@ CELIX_UTILS_EXPORT celix_status_t celix_properties_store(celix_properties_t* pro const char* file, const char* header); +//TODO doc +CELIX_UTILS_EXPORT celix_status_t celix_properties_saveToStream(const celix_properties_t* properties, FILE* stream); + +//TODO doc +CELIX_UTILS_EXPORT celix_status_t celix_properties_loadFromStream(FILE* stream, celix_properties_t** out); + /** * @brief Get the entry for a given key in a property set. * diff --git a/libs/utils/src/properties_serialization.c b/libs/utils/src/properties_serialization.c new file mode
(celix) 04/06: gh-685: Add support for nested obj properties decoding
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 04bccbd3741e427b52790d4bfc3659f9e30c1583 Author: Pepijn Noltes AuthorDate: Tue Apr 9 20:03:50 2024 +0200 gh-685: Add support for nested obj properties decoding --- .../gtest/src/PropertiesSerializationTestSuite.cc | 246 - libs/utils/include/celix_properties.h | 21 +- libs/utils/src/properties_serialization.c | 72 -- 3 files changed, 262 insertions(+), 77 deletions(-) diff --git a/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc b/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc index a5d6a1df..4aa2469d 100644 --- a/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc +++ b/libs/utils/gtest/src/PropertiesSerializationTestSuite.cc @@ -32,7 +32,7 @@ class PropertiesSerializationTestSuite : public ::testing::Test { PropertiesSerializationTestSuite() { celix_err_resetErrors(); } }; -TEST_F(PropertiesSerializationTestSuite, SaveEmptyPropertiesTest) { +TEST_F(PropertiesSerializationTestSuite, EncodeEmptyPropertiesTest) { //Given an empty properties object celix_autoptr(celix_properties_t) props = celix_properties_create(); @@ -41,16 +41,16 @@ TEST_F(PropertiesSerializationTestSuite, SaveEmptyPropertiesTest) { size_t bufLen = 0; FILE* stream = open_memstream(, ); -//When saving the properties to the stream -auto status = celix_properties_saveToStream(props, stream); -EXPECT_EQ(CELIX_SUCCESS, status); +//When encoding the properties to the stream +auto status = celix_properties_encodeToStream(props, stream, 0); +ASSERT_EQ(CELIX_SUCCESS, status); //Then the stream contains an empty JSON object fclose(stream); EXPECT_STREQ("{}", buf); } -TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithSingleValuesTest) { +TEST_F(PropertiesSerializationTestSuite, EncodePropertiesWithSingleValuesTest) { //Given a properties object with single values celix_autoptr(celix_properties_t) props = celix_properties_create(); celix_properties_set(props, "key1", "value1"); @@ -65,9 +65,9 @@ TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithSingleValuesTest) { size_t bufLen = 0; FILE* stream = open_memstream(, ); -//When saving the properties to the stream -auto status = celix_properties_saveToStream(props, stream); -EXPECT_EQ(CELIX_SUCCESS, status); +//When encoding the properties to the stream +auto status = celix_properties_encodeToStream(props, stream, 0); +ASSERT_EQ(CELIX_SUCCESS, status); //Then the stream contains the JSON representation snippets of the properties fclose(stream); @@ -76,8 +76,6 @@ 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; - -//TODO how are versions serialized? A string representation is needed to reconstruct the version from JSON EXPECT_NE(nullptr, strstr(buf, R"("key6":"celix_version<1.2.3.qualifier>")")) << "JSON: " << buf; //And the buf is a valid JSON object @@ -87,7 +85,7 @@ TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithSingleValuesTest) { json_decref(root); } -TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithNaNAndInfValuesTest) { +TEST_F(PropertiesSerializationTestSuite, EncodePropertiesWithNaNAndInfValuesTest) { //Given a NAN, INF and -INF value auto keys = {"NAN", "INF", "-INF"}; for (const auto& key : keys) { @@ -104,7 +102,7 @@ TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithNaNAndInfValuesTest) //Then saving the properties to the stream fails, because JSON does not support NAN, INF and -INF celix_err_resetErrors(); -auto status = celix_properties_saveToStream(props, stream); +auto status = celix_properties_encodeToStream(props, stream, 0); EXPECT_EQ(CELIX_ILLEGAL_ARGUMENT, status); //And an error msg is added to celix_err @@ -113,7 +111,7 @@ TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithNaNAndInfValuesTest) } -TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithArrayListsTest) { +TEST_F(PropertiesSerializationTestSuite, EncodePropertiesWithArrayListsTest) { // 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(); @@ -143,8 +141,8 @@ TEST_F(PropertiesSerializationTestSuite, SavePropertiesWithArrayListsTest) { FILE* stream =
(celix) branch feature/685-properties-json-serialization created (now 72c785df)
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 at 72c785df gh-685: Add initial setup for properties decode flags This branch includes the following new commits: new 3acdb746 gh-685: Initial properties save/load setup new 9511610b gh-685: Add jansson dep for simple properties save/load new de072564 gh-685: Add json prop loading for primitive and initial arr. new 04bccbd3 gh-685: Add support for nested obj properties decoding new 77cd6b37 gh-685: Rename prop serialization sources to prop encoding new 72c785df gh-685: Add initial setup for properties decode flags The 6 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.