From 7668b8aceb42b5a46e1f9ca36d16dbfabe291748 Mon Sep 17 00:00:00 2001 From: Claudius Holeksa Date: Mon, 26 Jun 2023 18:19:15 +0200 Subject: c++,codec: Introduced Tuple and String as KelSimple Encoding --- tests/codec.cpp | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'tests/codec.cpp') diff --git a/tests/codec.cpp b/tests/codec.cpp index 5186df3..442ae57 100644 --- a/tests/codec.cpp +++ b/tests/codec.cpp @@ -2,6 +2,8 @@ #include #include +#include + namespace { namespace schema { using namespace saw::schema; @@ -15,6 +17,11 @@ using TestStruct = Struct< Member, Member >; + +using TestTuple = Tuple< + TwoDimArray, + UInt64 +>; } SAW_TEST("One Dimensional Array") { using namespace saw; @@ -189,4 +196,57 @@ SAW_TEST("KelSimple Struct write and read back"){ SAW_EXPECT(dec_tda.at(0,1).get() == 3, "Incorrect Decoding in array 0,1"); SAW_EXPECT(native.template get<"number">().get() == 410, "Incorrect Decoding in number"); } +SAW_TEST("KelSimple Tuple write and read back"){ + using namespace saw; + + data native; + data simple; + + auto& tda = native.template get<0>(); + tda = {1,2}; + + tda.at(0,0).set(5); + tda.at(0,1).set(3); + native.template get<1>().set(410); + + codec codec; + + auto eov = codec.encode(native, simple); + SAW_EXPECT(eov.is_value(), "Encoding error"); + + // Reset values + native = {}; + + eov = codec.decode(simple, native); + SAW_EXPECT(eov.is_value(), "Decoding error"); + + auto& dec_tda = native.template get<0>(); + + SAW_EXPECT(dec_tda.at(0,0).get() == 5, "Incorrect Decoding in array 0,0"); + SAW_EXPECT(dec_tda.at(0,1).get() == 3, "Incorrect Decoding in array 0,1"); + SAW_EXPECT(native.template get<1>().get() == 410, "Incorrect Decoding in number"); +} +SAW_TEST("KelSimple String write and read back"){ + using namespace saw; + + data native; + data simple; + + std::string str = "FooBananaJoe"; + + native.set(str); + + codec codec; + + auto eov = codec.encode(native, simple); + SAW_EXPECT(eov.is_value(), "Encoding error"); + + // Reset values + native = {}; + + eov = codec.decode(simple, native); + SAW_EXPECT(eov.is_value(), "Decoding error"); + + SAW_EXPECT(native == str, "String should've been decoded back correctly"); +} } -- cgit v1.2.3