From 0f220e44fec77efe35cd968d50339db0a3c4044a Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Sun, 13 Aug 2023 13:52:07 +0100 Subject: [PATCH] Testing: dump in different modes --- tests/CMakeLists.txt | 2 ++ tests/codes_dump_content.cc | 35 +++++++++++++++++++++++++++++++++++ tests/codes_dump_content.sh | 24 ++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 tests/codes_dump_content.cc create mode 100755 tests/codes_dump_content.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index eafa1df4c..9b7110b9c 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -47,6 +47,7 @@ list(APPEND test_c_bins codes_dump_action_tree codes_set_samples_path codes_compare_keys + codes_dump_content grib_sh_ieee64 grib_ieee grib_set_bytes @@ -290,6 +291,7 @@ if( HAVE_BUILD_TOOLS ) codes_dump_action_tree codes_set_samples_path codes_compare_keys + codes_dump_content grib_dump grib_dump_debug grib_dump_json diff --git a/tests/codes_dump_content.cc b/tests/codes_dump_content.cc new file mode 100644 index 000000000..f2ab36430 --- /dev/null +++ b/tests/codes_dump_content.cc @@ -0,0 +1,35 @@ +/* + * (C) Copyright 2005- ECMWF. + * + * This software is licensed under the terms of the Apache Licence Version 2.0 + * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. + * + * In applying this licence, ECMWF does not waive the privileges and immunities granted to it by + * virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. + */ +#include +#undef NDEBUG +#include +#include "eccodes.h" + +int main(int argc, char* argv[]) +{ + int err = 0; + assert (argc == 3); + + char* mode = argv[1]; + char* filename = argv[2]; + + FILE* in = fopen(filename, "rb"); + assert(in); + + codes_handle* h = codes_handle_new_from_file(0, in, PRODUCT_ANY, &err); + assert(h); + + grib_dump_content(h, stdout, mode, 0, NULL); + + codes_handle_delete(h); + fclose(in); + + return 0; +} diff --git a/tests/codes_dump_content.sh b/tests/codes_dump_content.sh new file mode 100755 index 000000000..1cad7d169 --- /dev/null +++ b/tests/codes_dump_content.sh @@ -0,0 +1,24 @@ +#!/bin/sh +# (C) Copyright 2005- ECMWF. +# +# This software is licensed under the terms of the Apache Licence Version 2.0 +# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. +# +# In applying this licence, ECMWF does not waive the privileges and immunities granted to it by +# virtue of its status as an intergovernmental organisation nor does it submit to any jurisdiction. +# + +. ./include.ctest.sh + +label="codes_dump_content_test" +temp=temp.$label.grib + +infile=$data_dir/sample.grib2 + +modes="default wmo json serialize debug grib_encode_C" +for mode in $modes; do + $EXEC ${test_dir}/codes_dump_content $mode $infile +done + +# Clean up +rm -f $temp