From 1ea5190f115f705695defc98e1819469bb7b832f Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Thu, 24 Aug 2023 21:16:53 +0100 Subject: [PATCH] Testing: Key iterator with skip --- tests/CMakeLists.txt | 2 ++ tests/grib_keys_iter_skip.cc | 59 ++++++++++++++++++++++++++++++++++++ tests/grib_keys_iter_skip.sh | 25 +++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 tests/grib_keys_iter_skip.cc create mode 100755 tests/grib_keys_iter_skip.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b75b0331a..dfa32c9dc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -21,6 +21,7 @@ list(APPEND test_c_bins unit_tests bufr_keys_iter grib_keys_iter + grib_keys_iter_skip grib_geo_iter gauss_sub grib_nearest_test @@ -187,6 +188,7 @@ if( HAVE_BUILD_TOOLS ) bufr_change_edition bufr_keys_iter grib_keys_iter + grib_keys_iter_skip grib_geo_iter bufr_get_element bufr_wmo_tables diff --git a/tests/grib_keys_iter_skip.cc b/tests/grib_keys_iter_skip.cc new file mode 100644 index 000000000..54d5d1c79 --- /dev/null +++ b/tests/grib_keys_iter_skip.cc @@ -0,0 +1,59 @@ +/* + * (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 +#include +#include + +#include "grib_api_internal.h" + +int main(int argc, char* argv[]) +{ + grib_handle* h = NULL; + int err = 0; + + Assert(argc == 2); + const char* fname = argv[1]; + FILE* f = fopen(fname, "rb"); + Assert(f); + + unsigned long flags[] = { + GRIB_KEYS_ITERATOR_SKIP_READ_ONLY, + GRIB_KEYS_ITERATOR_SKIP_OPTIONAL, + GRIB_KEYS_ITERATOR_SKIP_EDITION_SPECIFIC, + GRIB_KEYS_ITERATOR_SKIP_CODED, + GRIB_KEYS_ITERATOR_SKIP_COMPUTED, + GRIB_KEYS_ITERATOR_SKIP_DUPLICATES, + GRIB_KEYS_ITERATOR_SKIP_FUNCTION + }; + const unsigned long N = sizeof(flags)/sizeof(unsigned long); + + while ((h = grib_handle_new_from_file(0, f, &err)) != NULL) { + + for (unsigned long i=0; i 0); + ++count; + } + grib_keys_iterator_delete(kiter); + printf("File=%s: Flag=%lu, count=%zu\n", fname, flags[i], count); + } + + grib_handle_delete(h); + } + + fclose(f); + return 0; +} diff --git a/tests/grib_keys_iter_skip.sh b/tests/grib_keys_iter_skip.sh new file mode 100755 index 000000000..4b5e6fb28 --- /dev/null +++ b/tests/grib_keys_iter_skip.sh @@ -0,0 +1,25 @@ +#!/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="grib_keys_iter_skip_test" + +gribs=" + row.grib + grid_ieee.grib + reduced_gaussian_model_level.grib1 + sample.grib2 + gfs.c255.grib2 +" +for f in $gribs; do + g=$data_dir/$f + ${test_dir}/grib_keys_iter_skip $g +done