From 4ac5d2c8039a4fc957b1453b8f38322f5d8e0f02 Mon Sep 17 00:00:00 2001 From: LinZhihao-723 Date: Fri, 28 Jun 2024 17:20:46 -0400 Subject: [PATCH] Add escaped test --- components/core/tests/test-ffi_utils.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/components/core/tests/test-ffi_utils.cpp b/components/core/tests/test-ffi_utils.cpp index 8d39adffb..9a43ec7ae 100644 --- a/components/core/tests/test-ffi_utils.cpp +++ b/components/core/tests/test-ffi_utils.cpp @@ -38,6 +38,7 @@ auto serialize_msgpack_bytes_to_json_str(vector const& msgpack_by clp::size_checked_pointer_cast(msgpack_bytes.data()), msgpack_bytes.size() ); + optional ret_val; auto const& msgpack_obj{msgpack_oh.get()}; if (msgpack::type::ARRAY == msgpack_obj.type) { @@ -58,10 +59,20 @@ auto serialize_msgpack_bytes_to_json_str(vector const& msgpack_by TEST_CASE("test_msgpack_to_json", "[ffi][utils]") { optional result; + constexpr string_view cStringWithEscape{"String with\\\"escaped\"\\ characters\n\t"}; // Test array with primitive values only json const array_with_primitive_values_only - = {1, -1, 1.01, -1.01, true, false, "short_string", "This is a long string", nullptr}; + = {1, + -1, + 1.01, + -1.01, + true, + false, + "short_string", + "This is a long string", + cStringWithEscape, + nullptr}; result = serialize_msgpack_bytes_to_json_str(json::to_msgpack(array_with_primitive_values_only) ); REQUIRE((result.has_value() && array_with_primitive_values_only == json::parse(result.value())) @@ -76,6 +87,7 @@ TEST_CASE("test_msgpack_to_json", "[ffi][utils]") { {"bool_key_true", false}, {"bool_key_false", true}, {"str_key", "Test string"}, + {"str_with_\"escaped\"_key", cStringWithEscape}, {"null_key", nullptr}}; result = serialize_msgpack_bytes_to_json_str(json::to_msgpack(map_with_primitive_values_only)); REQUIRE((result.has_value() && map_with_primitive_values_only == json::parse(result.value())));