From 056ab6893ca18c33c7fb01d24498f9149fba4e8a Mon Sep 17 00:00:00 2001 From: Claudius Holeksa Date: Tue, 20 Jun 2023 17:00:38 +0200 Subject: c++, codec-json: Minor progress on arrays for json decoding --- tests/codec-json.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/codec-json.cpp b/tests/codec-json.cpp index 030b1e4..fec82b0 100644 --- a/tests/codec-json.cpp +++ b/tests/codec-json.cpp @@ -292,12 +292,13 @@ SAW_TEST("Struct write"){ SAW_TEST("Int8 read"){ using namespace saw; data native_int; - data json_int; + data json_int{"43"}; codec json_codec; error_or eov = json_codec.decode(json_int, native_int); - SAW_EXPECT(eov.is_value(), "Encoding error"); + std::string enc_val = convert_to_string(json_int.get_buffer()); + SAW_EXPECT(eov.is_value(), std::string{"Encoding error: "} + enc_val); /** * Currently doing this manually. Technically I should convert to std::string for tests @@ -305,4 +306,22 @@ SAW_TEST("Int8 read"){ typename native_data_type::type dec_val = 43; SAW_EXPECT( dec_val == native_int.get(), std::string{"Value is not being encoded correctly. Encoded: "} + std::to_string(static_cast(native_int.get()))); } + +SAW_TEST("Int64 read"){ + using namespace saw; + data native_int; + data json_int{"-453"}; + + codec json_codec; + + error_or eov = json_codec.decode(json_int, native_int); + std::string enc_val = convert_to_string(json_int.get_buffer()); + SAW_EXPECT(eov.is_value(), std::string{"Encoding error: "} + enc_val); + + /** + * Currently doing this manually. Technically I should convert to std::string for tests + */ + typename native_data_type::type dec_val = -453; + SAW_EXPECT( dec_val == native_int.get(), std::string{"Value is not being encoded correctly. Encoded: "} + std::to_string(static_cast(native_int.get()))); +} } -- cgit v1.2.3