diff options
Diffstat (limited to 'modules/codec/tests')
-rw-r--r-- | modules/codec/tests/transport.cpp | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/modules/codec/tests/transport.cpp b/modules/codec/tests/transport.cpp new file mode 100644 index 0000000..cffee24 --- /dev/null +++ b/modules/codec/tests/transport.cpp @@ -0,0 +1,57 @@ +#include <forstio/test/suite.hpp> +#include "../c++/data.hpp" +#include "../c++/simple.hpp" + +#include <iostream> + +namespace { +namespace schema { +using namespace saw::schema; + +using ZeroDimArray = Array<Int32,0>; +using OneDimArray = Array<Int32,1>; +using TwoDimArray = Array<Int32,2>; +using ThreeDimArray = Array<Int32,3>; + +using TestStruct = Struct< + Member<TwoDimArray, "two_dim_array">, + Member<UInt64, "number"> +>; + +} + +SAW_TEST("KelSimple Struct write and read back"){ + using namespace saw; + + ring_buffer buffer{2048u}; + + data<schema::TestStruct,encode::Native> native; + + data<schema::TestStruct,encode::KelSimple> simple; + + auto& tda = native.template get<"two_dim_array">(); + tda = {1,2}; + + tda.at(0,0).set(5); + tda.at(0,1).set(3); + native.template get<"number">().set(410); + + codec<schema::TestStruct, 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<"two_dim_array">(); + + 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<"number">().get() == 410, "Incorrect Decoding in number"); +} + +} |