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 a4814f3f4955fe0b260e2fc416849ef1eb1d82a0
Author: Pepijn Noltes <pnol...@apache.org>
AuthorDate: Mon Apr 15 23:05:01 2024 +0200

    gh-685: Fix incorrect celix_autoptr usage
---
 .../utils/gtest/src/PropertiesEncodingTestSuite.cc | 23 ++++++++++------------
 1 file changed, 10 insertions(+), 13 deletions(-)

diff --git a/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc 
b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc
index 1b0035c0..3e03b77e 100644
--- a/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc
+++ b/libs/utils/gtest/src/PropertiesEncodingTestSuite.cc
@@ -210,27 +210,23 @@ TEST_F(PropertiesSerializationTestSuite, 
SaveJPathKeysTest) {
     celix_properties_set(props, "object3/object4/key6", "value6");
 
     //And an in-memory stream
-    celix_autofree char* buf = nullptr;
-    size_t bufLen = 0;
-    FILE* stream = open_memstream(&buf, &bufLen);
+    celix_autofree char* output;
 
     //When saving the properties to the stream
-    auto status = celix_properties_saveToStream(props, stream, 
CELIX_PROPERTIES_ENCODE_NESTED_STYLE);
+    auto status = celix_properties_saveToString(props, 
CELIX_PROPERTIES_ENCODE_NESTED_STYLE, &output);
     ASSERT_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"("object1":{"key3":"value3","key4":"value4"})")) << "JSON: " << buf;
-    EXPECT_NE(nullptr, strstr(buf, R"("object2":{"key5":"value5"})")) << 
"JSON: " << buf;
-    EXPECT_NE(nullptr, strstr(buf, 
R"("object3":{"object4":{"key6":"value6"}})")) << "JSON: " << buf;
+    EXPECT_NE(nullptr, strstr(output, R"("key1":"value1")")) << "JSON: " << 
output;
+    EXPECT_NE(nullptr, strstr(output, R"("key2":"value2")")) << "JSON: " << 
output;
+    EXPECT_NE(nullptr, strstr(output, 
R"("object1":{"key3":"value3","key4":"value4"})")) << "JSON: " << output;
+    EXPECT_NE(nullptr, strstr(output, R"("object2":{"key5":"value5"})")) << 
"JSON: " << output;
+    EXPECT_NE(nullptr, strstr(output, 
R"("object3":{"object4":{"key6":"value6"}})")) << "JSON: " << output;
 
     //And the buf is a valid JSON object
     json_error_t error;
-    json_t* root = json_loads(buf, 0, &error);
+    json_auto_t* root = json_loads(output, 0, &error);
     EXPECT_NE(nullptr, root) << "Unexpected JSON error: " << error.text;
-    json_decref(root);
 }
 
 TEST_F(PropertiesSerializationTestSuite, SaveJPathKeysWithCollisionTest) {
@@ -374,7 +370,8 @@ TEST_F(PropertiesSerializationTestSuite, 
SavePropertiesWithAndWithoutStrictFlagT
     ASSERT_EQ(CELIX_SUCCESS, status);
 
     //When saving the properties to a string with the strict flag
-    status = celix_properties_saveToString(props, 
CELIX_PROPERTIES_ENCODE_STRICT, &output);
+    char* output2;
+    status = celix_properties_saveToString(props, 
CELIX_PROPERTIES_ENCODE_STRICT, &output2);
 
     //Then the save fails, because the empty array generates an error
     ASSERT_EQ(CELIX_ILLEGAL_ARGUMENT, status);

Reply via email to