diff options
Diffstat (limited to 'modules/codec/tests')
-rw-r--r-- | modules/codec/tests/codec.cpp | 42 | ||||
-rw-r--r-- | modules/codec/tests/csv.cpp | 6 | ||||
-rw-r--r-- | modules/codec/tests/data.cpp | 32 | ||||
-rw-r--r-- | modules/codec/tests/transport.cpp | 16 |
4 files changed, 64 insertions, 32 deletions
diff --git a/modules/codec/tests/codec.cpp b/modules/codec/tests/codec.cpp index 7ad1c89..a1f37b8 100644 --- a/modules/codec/tests/codec.cpp +++ b/modules/codec/tests/codec.cpp @@ -58,13 +58,13 @@ SAW_TEST("One Dimensional Array") { int bar = 0; - for(size_t i = 0; i < arr.get_dim_size(0); ++i){ + for(data<schema::UInt64, encode::Native> i = 0; i < arr.size(); ++i){ arr.at(i).set(bar++); } int sum = 0; for(size_t i = 0; i < arr.get_dim_size(0); ++i){ - sum += arr.at(i).get(); + sum += arr.at(data<schema::UInt64>{i}).get(); } SAW_EXPECT(sum == 124750, std::to_string(sum) + " is not 124750. Expected that data stays correct"); @@ -76,7 +76,7 @@ SAW_TEST("One dim Array Default init"){ data<schema::OneDimArray, encode::Native> arr; SAW_EXPECT(arr.get_dim_size(0) == 0, "Dim should be size 0"); - SAW_EXPECT(arr.size() == 0, "Total size should also be zero"); + SAW_EXPECT(arr.size().get() == 0u, "Total size should also be zero"); } SAW_TEST("One dimensional Array Add"){ @@ -87,13 +87,13 @@ SAW_TEST("One dimensional Array Add"){ int bar = 0; for(size_t i = 0; i < arr.get_dim_size(0); ++i){ - arr.at(i).set(bar++); + arr.at(data<schema::UInt64>{i}).set(bar++); } arr.add(7); - SAW_EXPECT(arr.size() == 6u, "Array size is not 6u. Expected that data stays correct"); - SAW_EXPECT(arr.at(5u).get() == 7, "Array at 5u is not 7. Expected that data stays correct"); + SAW_EXPECT(arr.size().get() == 6u, "Array size is not 6u. Expected that data stays correct"); + SAW_EXPECT(arr.at(data<schema::UInt64>{5u}).get() == 7, "Array at 5u is not 7. Expected that data stays correct"); } SAW_TEST("Two Dimensional Array") { @@ -108,13 +108,13 @@ SAW_TEST("Two Dimensional Array") { for(size_t i = 0; i < arr.get_dim_size(0); ++i){ for(size_t j = 0; j < arr.get_dim_size(1); ++j){ ++bar; - arr.at(i,j).set(bar); + arr.at({i,j}).set(bar); } } int sum = 0; for(size_t i = 0; i < arr.get_dim_size(0); ++i){ for(size_t j = 0; j < arr.get_dim_size(1); ++j){ - sum += arr.at(i,j).get(); + sum += arr.at({i,j}).get(); } } SAW_EXPECT(sum == expected_sum, std::to_string(sum) + " is not "+ std::to_string(expected_sum) + ". Expected that data stays correct"); @@ -132,7 +132,7 @@ SAW_TEST("Three Dimensional Array") { for(size_t j = 0; j < arr.get_dim_size(1); ++j){ for(size_t k = 0; k < arr.get_dim_size(2); ++k){ ++bar; - arr.at(i,j,k).set(bar); + arr.at({i,j,k}).set(bar); } } } @@ -140,7 +140,7 @@ SAW_TEST("Three Dimensional Array") { for(size_t i = 0; i < arr.get_dim_size(0); ++i){ for(size_t j = 0; j < arr.get_dim_size(1); ++j){ for(size_t k = 0; k < arr.get_dim_size(2); ++k){ - sum += arr.at(i,j,k).get(); + sum += arr.at({i,j,k}).get(); } } } @@ -202,7 +202,7 @@ SAW_TEST("KelSimple Array write and read back"){ for(std::size_t i = 0; i < 2; ++i) { for(std::size_t j = 0; j < 3; ++j){ - native.at(i,j).set(i+2*j); + native.at({i,j}).set(i+2*j); } } @@ -211,7 +211,7 @@ SAW_TEST("KelSimple Array write and read back"){ for(std::size_t i = 0; i < 2; ++i) { for(std::size_t j = 0; j < 3; ++j){ - native.at(i,j).set(0); + native.at({i,j}).set(0); } } @@ -220,7 +220,7 @@ SAW_TEST("KelSimple Array write and read back"){ for(std::size_t i = 0; i < 2; ++i) { for(std::size_t j = 0; j < 3; ++j){ - SAW_EXPECT(native.at(i,j).get() == static_cast<int32_t>(i+2*j), "Values incorrectly decoded"); + SAW_EXPECT(native.at({i,j}).get() == static_cast<int32_t>(i+2*j), "Values incorrectly decoded"); } } } @@ -234,8 +234,8 @@ SAW_TEST("KelSimple Struct write and read back"){ auto& tda = native.template get<"two_dim_array">(); tda = {1,2}; - tda.at(0,0).set(5); - tda.at(0,1).set(3); + tda.at({0,0}).set(5); + tda.at({0,1}).set(3); native.template get<"number">().set(410); codec<schema::TestStruct, encode::KelSimple> codec; @@ -251,8 +251,8 @@ SAW_TEST("KelSimple Struct write and read back"){ 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(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"); } @@ -302,8 +302,8 @@ SAW_TEST("KelSimple Tuple write and read back"){ auto& tda = native.template get<0>(); tda = {1,2}; - tda.at(0,0).set(5); - tda.at(0,1).set(3); + tda.at({0,0}).set(5); + tda.at({0,1}).set(3); native.template get<1>().set(410); codec<schema::TestTuple, encode::KelSimple> codec; @@ -319,8 +319,8 @@ SAW_TEST("KelSimple Tuple write and read back"){ 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(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"); } diff --git a/modules/codec/tests/csv.cpp b/modules/codec/tests/csv.cpp index 417a547..5772e20 100644 --- a/modules/codec/tests/csv.cpp +++ b/modules/codec/tests/csv.cpp @@ -28,19 +28,19 @@ SAW_TEST("Codec Csv/Encode Basic"){ size_t n_size = 3u; data <TestArray, encode::Native> native_data{n_size}; { - auto& row = native_data.at(0); + auto& row = native_data.at(data<schema::UInt64>{0}); row.template get<"string">().set("foo"); row.template get<"number">().set(140u); row.template get<"signed">().set(1); } { - auto& row = native_data.at(1); + auto& row = native_data.at(data<schema::UInt64>{1}); row.template get<"string">().set("bar"); row.template get<"number">().set(245u); row.template get<"signed">().set(2); } { - auto& row = native_data.at(2); + auto& row = native_data.at(data<schema::UInt64>{2}); row.template get<"string">().set("ban and anna"); row.template get<"number">().set(42u); row.template get<"signed">().set(3); diff --git a/modules/codec/tests/data.cpp b/modules/codec/tests/data.cpp new file mode 100644 index 0000000..816aa1c --- /dev/null +++ b/modules/codec/tests/data.cpp @@ -0,0 +1,32 @@ +#include <forstio/test/suite.hpp> +#include "../c++/data.hpp" + +namespace { +namespace sch { +using namespace saw::schema; + +using Int32Array = Array< + Int32 +>; +} + +SAW_TEST("Data Native/Array Access with Data Native"){ + using namespace saw; + + data<sch::Int32Array,encode::Native> prim{2u}; + prim.at(1u).set(0); + + data<schema::UInt64, encode::Native> i{1u}; + + auto& a = prim.at({i}); + + a.set(5); + + auto b = prim.at({i}); + b.set(10); + // Check if it's a reference being manipulated + SAW_EXPECT(a.get() == 5, "'a' has unexpected value."); + SAW_EXPECT(b.get() == 10, "'b' has unexpected value."); +} + +} diff --git a/modules/codec/tests/transport.cpp b/modules/codec/tests/transport.cpp index 8c786e9..e0e105f 100644 --- a/modules/codec/tests/transport.cpp +++ b/modules/codec/tests/transport.cpp @@ -33,8 +33,8 @@ SAW_TEST("Transport FixedLen Struct write and slice"){ auto& tda = native.template get<"two_dim_array">(); tda = {1,2}; - tda.at(0,0).set(5); - tda.at(0,1).set(3); + tda.at({0,0}).set(5); + tda.at({0,1}).set(3); native.template get<"number">().set(410); } codec<schema::TestStruct, encode::KelSimple> codec; @@ -67,8 +67,8 @@ SAW_TEST("Transport FixedLen Struct write and slice"){ auto& tda = native.template get<"two_dim_array">(); tda = {1,2}; - tda.at(0,0).set(2); - tda.at(0,1).set(4); + tda.at({0,0}).set(2); + tda.at({0,1}).set(4); native.template get<"number">().set(709); } { @@ -118,8 +118,8 @@ SAW_TEST("Transport FixedLen Struct write and slice"){ { auto& tda = native.template get<"two_dim_array">(); - SAW_EXPECT(tda.at(0,0).get() == 5, "Decoded value (0,0) wrong."); - SAW_EXPECT(tda.at(0,1).get() == 3, "Decoded value (0,1) wrong."); + SAW_EXPECT(tda.at({0,0}).get() == 5, "Decoded value (0,0) wrong."); + SAW_EXPECT(tda.at({0,1}).get() == 3, "Decoded value (0,1) wrong."); SAW_EXPECT(native.template get<"number">().get() == 410, "Decoded value number wrong."); } } @@ -148,8 +148,8 @@ SAW_TEST("Transport FixedLen Struct write and slice"){ { auto& tda = native.template get<"two_dim_array">(); - SAW_EXPECT(tda.at(0,0).get() == 2, "Decoded value (0,0) wrong."); - SAW_EXPECT(tda.at(0,1).get() == 4, "Decoded value (0,1) wrong."); + SAW_EXPECT(tda.at({0,0}).get() == 2, "Decoded value (0,0) wrong."); + SAW_EXPECT(tda.at({0,1}).get() == 4, "Decoded value (0,1) wrong."); SAW_EXPECT(native.template get<"number">().get() == 709, "Decoded value number wrong."); } } |