From 3cbfde7d55f97ad293fffecb41f839c2efc649a7 Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Tue, 24 Sep 2019 15:43:27 +0100 Subject: [PATCH] ECC-991: testing --- tests/bufr_extract_headers.c | 92 +++++++++++++++++++++++++++++------ tests/bufr_extract_headers.sh | 17 +++++-- 2 files changed, 91 insertions(+), 18 deletions(-) diff --git a/tests/bufr_extract_headers.c b/tests/bufr_extract_headers.c index 61ac3490c..8a38f3db2 100644 --- a/tests/bufr_extract_headers.c +++ b/tests/bufr_extract_headers.c @@ -7,39 +7,101 @@ * 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 "grib_api_internal.h" + #include "eccodes.h" #include -int main(int argc,char* argv[]) +static const char* not_found = "not_found"; + +void print_rdb_key(int has_local, long value) { - char* filename; + if (has_local) + printf("%ld ", value); + else + printf("%s ", not_found); +} +void print_rdb_ident(int has_local, const char* value) +{ + if (value == NULL || strlen(value) == 0) + printf("%s ", not_found); + else + printf("%s ", value); +} + +int main(int argc, char* argv[]) +{ + char *filename, *keys; int i, err = 0; int num_messages = 0; codes_bufr_header* headers = NULL; codes_context* c = codes_context_get_default(); - assert(argc == 2); + if (argc != 3) return 1; + + keys = argv[1]; /* comma-separated like bufr_ls/bufr_get */ + filename = argv[2]; - filename = argv[1]; err = codes_bufr_extract_headers_malloc(c, filename, &headers, &num_messages); - assert(!err); + if (err) return 1; - for (i=0; i $temp1 - ${tools_dir}/bufr_get -f -p $KEYS $input > $temp2 + $EXEC ${test_dir}/bufr_extract_headers $KEYS $input > $temp1 + ${tools_dir}/bufr_get -f -p $KEYS $input > $temp2 + diff -w $temp1 $temp2 +done + +# Check for ident +files_with_ident="airc_142.bufr amda_144.bufr b004_145.bufr bssh_180.bufr temp_106.bufr profiler_european.bufr soil_7.bufr temp-land-with-substituted-values.bufr" +for bf in ${files_with_ident}; do + input=${data_dir}/bufr/$bf + # Have to remove the extra space at the end + $EXEC ${test_dir}/bufr_extract_headers ident $input |sed -e 's/ $//' > $temp1 + ${tools_dir}/bufr_get -f -p ident $input > $temp2 diff $temp1 $temp2 done + rm -f $temp1 $temp2