Testing: Key iterator with skip

This commit is contained in:
Shahram Najm 2023-08-24 21:16:53 +01:00
parent 5b06296dce
commit 1ea5190f11
3 changed files with 86 additions and 0 deletions

View File

@ -21,6 +21,7 @@ list(APPEND test_c_bins
unit_tests unit_tests
bufr_keys_iter bufr_keys_iter
grib_keys_iter grib_keys_iter
grib_keys_iter_skip
grib_geo_iter grib_geo_iter
gauss_sub gauss_sub
grib_nearest_test grib_nearest_test
@ -187,6 +188,7 @@ if( HAVE_BUILD_TOOLS )
bufr_change_edition bufr_change_edition
bufr_keys_iter bufr_keys_iter
grib_keys_iter grib_keys_iter
grib_keys_iter_skip
grib_geo_iter grib_geo_iter
bufr_get_element bufr_get_element
bufr_wmo_tables bufr_wmo_tables

View File

@ -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 <stdlib.h>
#include <stdio.h>
#include <string.h>
#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<N; ++i) {
size_t count = 0;
grib_keys_iterator* kiter = grib_keys_iterator_new(h, flags[i], NULL);
Assert(kiter);
while (grib_keys_iterator_next(kiter)) {
const char* name = grib_keys_iterator_get_name(kiter);
Assert(name);
Assert(strlen(name) > 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;
}

25
tests/grib_keys_iter_skip.sh Executable file
View File

@ -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