diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/.nix/derivation.nix | 2 | ||||
-rw-r--r-- | tests/SConstruct | 8 | ||||
-rw-r--r-- | tests/codec-netcdf.cpp | 43 | ||||
-rw-r--r-- | tests/data/array.nc | bin | 0 -> 156 bytes | |||
-rw-r--r-- | tests/data/primitive.nc | bin | 0 -> 112 bytes |
5 files changed, 45 insertions, 8 deletions
diff --git a/tests/.nix/derivation.nix b/tests/.nix/derivation.nix index e096e70..ea40920 100644 --- a/tests/.nix/derivation.nix +++ b/tests/.nix/derivation.nix @@ -4,6 +4,7 @@ , clang-tools , version , forstio +, netcdf }: stdenv.mkDerivation { @@ -24,6 +25,7 @@ stdenv.mkDerivation { forstio.io forstio.test forstio.window + netcdf ]; doCheck = true; diff --git a/tests/SConstruct b/tests/SConstruct index 4434d20..88477f7 100644 --- a/tests/SConstruct +++ b/tests/SConstruct @@ -46,7 +46,13 @@ env_vars.Add('prefix', env=Environment(ENV=os.environ, variables=env_vars, CPPPATH=[], CPPDEFINES=['SAW_UNIX'], CXXFLAGS=['-std=c++20','-g','-Wall','-Wextra'], - LIBS=['forstio-core', 'forstio-async', 'forstio-test']) + LIBS=[ + 'forstio-core', + 'forstio-async', + 'forstio-test', + 'netcdf' + ] +); env.__class__.add_source_files = add_kel_source_files env.Tool('compilation_db'); env.cdb = env.CompilationDatabase('compile_commands.json'); diff --git a/tests/codec-netcdf.cpp b/tests/codec-netcdf.cpp index df0037b..72fc5ea 100644 --- a/tests/codec-netcdf.cpp +++ b/tests/codec-netcdf.cpp @@ -5,21 +5,50 @@ namespace { namespace schema { using namespace saw::schema; using TestStruct = Struct< - Member<Int32, "rh"> + Member<Int32, "data">, + Member<Float64, "other"> +>; + +using TestArrayStruct = Struct< + Member<Array<Int32,2>, "data"> >; } -SAW_TEST("NetCDF read"){ +SAW_TEST("NetCDF Struct Primitive read"){ using namespace saw; - data<TestStruct, encode::Netcdf> net{"./data/simple.nc"}; + data<schema::TestStruct, encode::Netcdf> netcdf{"./data/primitive.nc"}; - data<TestStruct, encode::KelSimple> kel; + data<schema::TestStruct, encode::Native> native; - codec<TestStruct, encode::Netcdf> codec; + codec<schema::TestStruct, encode::Netcdf> codec; - auto eov = codec.decode(net, kel); + auto eov = codec.decode(netcdf, native); SAW_EXPECT(eov.is_value(), "Decoding failed"); - SAW_EXPECT(kel.get<"rh">.get() == 5, "Value incorrect"); + SAW_EXPECT(native.get<"data">().get() == 5, "Int Value incorrect"); + SAW_EXPECT(native.get<"other">().get() == 32.0, "Double Value incorrect"); +} + +SAW_TEST("NetCDF Struct Array read"){ + using namespace saw; + + data<schema::TestArrayStruct, encode::Netcdf> netcdf{"./data/array.nc"}; + + data<schema::TestArrayStruct, encode::Native> native; + + codec<schema::TestArrayStruct, encode::Netcdf> codec; + + auto eov = codec.decode(netcdf, native); + SAW_EXPECT(eov.is_value(), "Decoding failed"); + auto& arr = native.get<"data">(); + SAW_EXPECT(arr.get_dim_size(0) == 5, "Incorrect dimension 0"); + SAW_EXPECT(arr.get_dim_size(1) == 3, "Incorrect dimension 1"); + + for(std::size_t i = 0; i < 5; ++i){ + for(std::size_t j = 0; j < 3; ++j){ + int64_t exp_val = i * 3 + j; + SAW_EXPECT(arr.at(i,j).get() == exp_val, "Incorrect value"); + } + } } } diff --git a/tests/data/array.nc b/tests/data/array.nc Binary files differnew file mode 100644 index 0000000..2155846 --- /dev/null +++ b/tests/data/array.nc diff --git a/tests/data/primitive.nc b/tests/data/primitive.nc Binary files differnew file mode 100644 index 0000000..ab49e3b --- /dev/null +++ b/tests/data/primitive.nc |