summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/codec.cpp60
1 files changed, 60 insertions, 0 deletions
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 <forstio/codec/data.h>
#include <forstio/codec/simple.h>
+#include <iostream>
+
namespace {
namespace schema {
using namespace saw::schema;
@@ -15,6 +17,11 @@ using TestStruct = Struct<
Member<TwoDimArray, "two_dim_array">,
Member<UInt64, "number">
>;
+
+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<schema::TestTuple,encode::Native> native;
+ data<schema::TestTuple,encode::KelSimple> 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<schema::TestTuple, encode::KelSimple> 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<schema::String,encode::Native> native;
+ data<schema::String,encode::KelSimple> simple;
+
+ std::string str = "FooBananaJoe";
+
+ native.set(str);
+
+ codec<schema::String, encode::KelSimple> 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");
+}
}