From f0cbdfd3b367eb132212a9c39f5cde7f56c6d26e Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Mon, 24 Jul 2023 13:26:04 +0000 Subject: [PATCH] Comparison of accessors: Add test --- tests/CMakeLists.txt | 1 + tests/codes_compare_keys.cc | 11 +++++---- tests/codes_compare_keys.sh | 45 +++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 6 deletions(-) create mode 100755 tests/codes_compare_keys.sh diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 827d91ef8..fc4711efc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -282,6 +282,7 @@ if( HAVE_BUILD_TOOLS ) read_any codes_new_from_samples codes_set_samples_path + codes_compare_keys grib_dump grib_dump_debug grib_dump_json diff --git a/tests/codes_compare_keys.cc b/tests/codes_compare_keys.cc index 1bc8ad337..9a4027958 100644 --- a/tests/codes_compare_keys.cc +++ b/tests/codes_compare_keys.cc @@ -27,8 +27,8 @@ int main(int argc, char* argv[]) while ((h1 = grib_handle_new_from_file(0, f1, &err)) != NULL && (h2 = grib_handle_new_from_file(0, f2, &err)) != NULL) { grib_keys_iterator* kiter = NULL; - /* Use namespace of NULL to get ALL keys */ - /* Set flags to 0 to not filter any keys */ + // Use namespace of NULL to get ALL keys + // Set flags to 0 to not filter any keys //kiter = grib_keys_iterator_new(h1, /*flags=*/0, /*namespace=*/NULL); kiter = grib_keys_iterator_new(h1, /*flags=*/GRIB_KEYS_ITERATOR_SKIP_COMPUTED, /*namespace=*/NULL); Assert(kiter); @@ -36,10 +36,9 @@ int main(int argc, char* argv[]) while (grib_keys_iterator_next(kiter)) { const char* name = grib_keys_iterator_get_name(kiter); Assert(name); - //printf("Comparing key '%s' ...\n", name); err = codes_compare_key(h1, h2, name, 0); if (err) { - printf("key: %s (%s)\n", name, grib_get_error_message(err)); + fprintf(stderr, "key: %s (%s)\n", name, grib_get_error_message(err)); failed = 1; } } @@ -51,7 +50,7 @@ int main(int argc, char* argv[]) fclose(f1); fclose(f2); if (failed) { - fprintf(stderr, "\nComparison failed: One or more keys different\n"); + fprintf(stderr, "\nComparison failed: One or more keys are different\n"); } - return err; + return failed; } diff --git a/tests/codes_compare_keys.sh b/tests/codes_compare_keys.sh new file mode 100755 index 000000000..5337046ca --- /dev/null +++ b/tests/codes_compare_keys.sh @@ -0,0 +1,45 @@ +#!/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_compare_keys_test" +tempRef=temp.${label}.ref +tempLog=temp.$label.log + +file1=$ECCODES_SAMPLES_PATH/reduced_gg_pl_32_grib2.tmpl +file2=$ECCODES_SAMPLES_PATH/reduced_gg_pl_48_grib2.tmpl +set +e +$EXEC ${test_dir}/codes_compare_keys $file1 $file2 > $tempLog 2>&1 +status=$? +set -e +[ $status -ne 0 ] + +cat > $tempRef <