Skip to content

Commit

Permalink
gh-685: Fix incorrect celix_autoptr usage
Browse files Browse the repository at this point in the history
  • Loading branch information
pnoltes committed Apr 15, 2024
1 parent ae4464c commit a4814f3
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions libs/utils/gtest/src/PropertiesEncodingTestSuite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a4814f3

Please sign in to comment.