diff options
author | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-01-10 18:29:09 +0100 |
---|---|---|
committer | Claudius "keldu" Holeksa <mail@keldu.de> | 2024-01-10 18:29:09 +0100 |
commit | e49cf83b4e90a1edcd73c534749c1f6359cb1781 (patch) | |
tree | 7c526167e1c0c89c3b3da746c147f837a92723a8 /modules/codec-netcdf | |
parent | 9a0bd3f93dbb1babc3149e3ba6348810a909fd4f (diff) |
codec-netcdf: Fixing move of module to new test structure
Diffstat (limited to 'modules/codec-netcdf')
-rw-r--r-- | modules/codec-netcdf/.nix/derivation.nix | 6 | ||||
-rw-r--r-- | modules/codec-netcdf/SConstruct | 10 | ||||
-rw-r--r-- | modules/codec-netcdf/c++/SConscript (renamed from modules/codec-netcdf/SConscript) | 8 | ||||
-rw-r--r-- | modules/codec-netcdf/c++/netcdf.h (renamed from modules/codec-netcdf/netcdf.h) | 0 | ||||
-rw-r--r-- | modules/codec-netcdf/c++/netcdf.tmpl.h (renamed from modules/codec-netcdf/netcdf.tmpl.h) | 0 | ||||
-rw-r--r-- | modules/codec-netcdf/tests/SConscript | 31 | ||||
-rw-r--r-- | modules/codec-netcdf/tests/codec-netcdf.cpp | 105 |
7 files changed, 154 insertions, 6 deletions
diff --git a/modules/codec-netcdf/.nix/derivation.nix b/modules/codec-netcdf/.nix/derivation.nix index 770942e..67d1a6c 100644 --- a/modules/codec-netcdf/.nix/derivation.nix +++ b/modules/codec-netcdf/.nix/derivation.nix @@ -28,6 +28,12 @@ in stdenv.mkDerivation { forstio.codec netcdf ]; + + doCheck = true; + checkPhase = '' + scons test + ./bin/tests + ''; outputs = ["out" "dev"]; } diff --git a/modules/codec-netcdf/SConstruct b/modules/codec-netcdf/SConstruct index edd5f57..1f205d2 100644 --- a/modules/codec-netcdf/SConstruct +++ b/modules/codec-netcdf/SConstruct @@ -46,7 +46,12 @@ 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-codec']) + LIBS=[ + 'forstio-core', + 'forstio-codec', + 'netcdf' + ] +); env.__class__.add_source_files = add_kel_source_files env.Tool('compilation_db'); env.cdb = env.CompilationDatabase('compile_commands.json'); @@ -57,7 +62,8 @@ env.headers = []; env.targets = []; Export('env') -SConscript('SConscript') +SConscript('c++/SConscript') +SConscript('tests/SConscript') env.Alias('cdb', env.cdb); env.Alias('all', [env.targets]); diff --git a/modules/codec-netcdf/SConscript b/modules/codec-netcdf/c++/SConscript index a469f77..fd95267 100644 --- a/modules/codec-netcdf/SConscript +++ b/modules/codec-netcdf/c++/SConscript @@ -21,18 +21,18 @@ env.headers += codec_netcdf_env.headers; ## Shared lib objects_shared = [] codec_netcdf_env.add_source_files(objects_shared, codec_netcdf_env.sources, shared=True); -codec_netcdf_env.library_shared = codec_netcdf_env.SharedLibrary('#build/forstio-codec-netcdf', [objects_shared]); +env.library_shared = codec_netcdf_env.SharedLibrary('#build/forstio-codec-netcdf', [objects_shared]); ## Static lib objects_static = [] codec_netcdf_env.add_source_files(objects_static, codec_netcdf_env.sources, shared=False); -codec_netcdf_env.library_static = codec_netcdf_env.StaticLibrary('#build/forstio-codec-netcdf', [objects_static]); +env.library_static = codec_netcdf_env.StaticLibrary('#build/forstio-codec-netcdf', [objects_static]); # Set Alias -env.Alias('library_codec_netcdf', [codec_netcdf_env.library_shared, codec_netcdf_env.library_static]); +env.Alias('library_codec_netcdf', [env.library_shared, env.library_static]); env.targets += ['library_codec_netcdf']; # Install -env.Install('$prefix/lib/', [codec_netcdf_env.library_shared, codec_netcdf_env.library_static]); +env.Install('$prefix/lib/', [env.library_shared, env.library_static]); env.Install('$prefix/include/forstio/codec/netcdf/', [codec_netcdf_env.headers]); diff --git a/modules/codec-netcdf/netcdf.h b/modules/codec-netcdf/c++/netcdf.h index 52ad494..52ad494 100644 --- a/modules/codec-netcdf/netcdf.h +++ b/modules/codec-netcdf/c++/netcdf.h diff --git a/modules/codec-netcdf/netcdf.tmpl.h b/modules/codec-netcdf/c++/netcdf.tmpl.h index bf257e4..bf257e4 100644 --- a/modules/codec-netcdf/netcdf.tmpl.h +++ b/modules/codec-netcdf/c++/netcdf.tmpl.h diff --git a/modules/codec-netcdf/tests/SConscript b/modules/codec-netcdf/tests/SConscript new file mode 100644 index 0000000..608c2b7 --- /dev/null +++ b/modules/codec-netcdf/tests/SConscript @@ -0,0 +1,31 @@ +#!/bin/false + +import os +import os.path +import glob + + +Import('env') + +dir_path = Dir('.').abspath + +# Environment for base library +test_cases_env = env.Clone(); + +test_cases_env.Append(LIBS=['forstio-test']); + +test_cases_env.sources = sorted(glob.glob(dir_path + "/*.cpp")) +test_cases_env.headers = sorted(glob.glob(dir_path + "/*.h")) + +env.sources += test_cases_env.sources; +env.headers += test_cases_env.headers; + +objects_static = [] +test_cases_env.add_source_files(objects_static, test_cases_env.sources, shared=False); +test_cases_env.program = test_cases_env.Program('#bin/tests', [objects_static, env.library_static]); + +# Set Alias +env.Alias('test', test_cases_env.program); +env.Alias('check', test_cases_env.program); + +env.targets += ['test','check']; diff --git a/modules/codec-netcdf/tests/codec-netcdf.cpp b/modules/codec-netcdf/tests/codec-netcdf.cpp new file mode 100644 index 0000000..29ba4fa --- /dev/null +++ b/modules/codec-netcdf/tests/codec-netcdf.cpp @@ -0,0 +1,105 @@ +#include <forstio/test/suite.h> +#include "../c++/netcdf.h" + +namespace { +namespace schema { +using namespace saw::schema; +using TestStruct = Struct< + Member<Int32, "data">, + Member<Float64, "other"> +>; + +using TestArrayStruct = Struct< + Member<Array<Int32,2>, "data"> +>; +} + +std::array<uint8_t,112> tests_data_primitive_nc = { + 0x43, 0x44, 0x46, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x04, + 0x00, 0x00, 0x00, 0x64, 0x00, 0x00, 0x00, 0x05, 0x6f, 0x74, 0x68, 0x65, + 0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x68, 0x00, 0x00, 0x00, 0x05, 0x40, 0x40, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00 +}; + +std::array<uint8_t,156> tests_data_array_nc = { + 0x43, 0x44, 0x46, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0a, + 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x78, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x79, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x04, + 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, 0x60, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x02, + 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x05, + 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, 0x00, 0x08, + 0x00, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x0a, 0x00, 0x00, 0x00, 0x0b, + 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x0e +}; + +SAW_TEST("NetCDF Struct Primitive write"){ + using namespace saw; + + data<schema::TestStruct, encode::Native> native; + + native.get<"data">().set(5); + native.get<"other">().set(32.0); + + codec<schema::TestStruct, encode::Netcdf> codec; + + data<schema::TestStruct, encode::Netcdf> netcdf; + + auto eov = codec.encode(native, netcdf); + SAW_EXPECT(eov.is_value(), "Encoding failed"); + auto& nc_data = netcdf.get_data(); + SAW_EXPECT(nc_data.size() == tests_data_primitive_nc.size(), "Incorrect size"); + + for(std::size_t i = 0; i < nc_data.size(); ++i){ + SAW_EXPECT(nc_data.at(i) == tests_data_primitive_nc.at(i), "Incorrect Value"); + } +} + +SAW_TEST("NetCDF Struct Primitive read"){ + using namespace saw; + + data<schema::TestStruct, encode::Netcdf> netcdf{tests_data_primitive_nc}; + + data<schema::TestStruct, encode::Native> native; + + codec<schema::TestStruct, encode::Netcdf> codec; + + auto eov = codec.decode(netcdf, native); + SAW_EXPECT(eov.is_value(), "Decoding failed"); + 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{tests_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"); + } + } +} +} |