From 547ea60f6f42dd3311abf3897756cb8e6f2afc3b Mon Sep 17 00:00:00 2001 From: Shahram Najm Date: Wed, 27 Dec 2023 18:31:59 +0000 Subject: [PATCH] Testing: tools error conditions --- tests/bufr_set.sh | 35 ++++++++++++++++++++++------------- tests/grib_dump.sh | 20 ++++++++++++++++++++ tools/bufr_set.cc | 13 ------------- 3 files changed, 42 insertions(+), 26 deletions(-) diff --git a/tests/bufr_set.sh b/tests/bufr_set.sh index f8d78aba5..f8224c0e1 100755 --- a/tests/bufr_set.sh +++ b/tests/bufr_set.sh @@ -10,8 +10,6 @@ . ./include.ctest.sh -#set -x - # Enter data dir cd ${data_dir}/bufr @@ -26,10 +24,9 @@ touch $fLog # Define tmp bufr file fBufrTmp=${label}".bufr.tmp" -#---------------------------------------------------- +#----------------------------------------------- # Test: setting header for single message file -#---------------------------------------------------- - +#----------------------------------------------- rm -f $fBufrTmp f="syno_1.bufr" @@ -43,7 +40,6 @@ centre=`${tools_dir}/bufr_get -p bufrHeaderCentre $fBufrTmp` #---------------------------------------------------- # Test: setting header for multi-message file #---------------------------------------------------- - rm -f $fBufrTmp f="syno_multi.bufr" @@ -60,7 +56,6 @@ done #----------------------------------------------------- # Test: setting data values for single message file #----------------------------------------------------- - # TODO: when ECC-37 is fixed we need to enable it. rm -f $fBufrTmp @@ -77,7 +72,6 @@ echo "file: $f" >> $fLog #---------------------------------------------------- # Test: setting header for multi-message file #---------------------------------------------------- - # TODO: when ECC-37 is fixed we need to enable it. rm -f $fBufrTmp @@ -93,13 +87,22 @@ echo "file: $f" >> $fLog #done #----------------------------------------------------------- -# Test: with nonexistent keys. +# Test: No keys set +#----------------------------------------------------------- +set +e +${tools_dir}/bufr_set $f $fBufrTmp > $fLog 2>&1 +status=$? +set -e +[ $status -ne 0 ] +grep -q "provide some keys to set" $fLog + +#----------------------------------------------------------- +# Test: with nonexistent keys #----------------------------------------------------------- # Key "center" does not exist!! # Invoke without -f i.e. should fail if error encountered set +e - f="syno_1.bufr" echo "Test: nonexistent keys" >> $fLog echo "file: $f" >> $fLog @@ -117,12 +120,10 @@ ${tools_dir}/bufr_set -f -s center=98 $f $fBufrTmp 2>>$fLog 1>>$fLog #----------------------------------------------------------- # Test: with not allowed key values #----------------------------------------------------------- - # Here 1024 is out of range for centre (it is 8-bit only for edition=3 files) # Invoke without -f i.e. should fail if error encountered set +e - f="syno_1.bufr" echo "Test: nonexistent keys" >> $fLog echo "file: $f" >> $fLog @@ -184,7 +185,6 @@ ${tools_dir}/bufr_set -s messageLength:s=333 $sample $fBufrTmp result=`${tools_dir}/bufr_get -p messageLength $fBufrTmp` [ "$result" = "333" ] - #----------------------------------------------------------- # Invalid masterTablesVersionNumber #----------------------------------------------------------- @@ -210,6 +210,15 @@ set -e grep -q "ECCODES ERROR.*unable to get hash value for sequences" $fLog +# Unreadable message +#----------------------------------------------------------- +echo BUFR > $fBufrTmp +set +e +${tools_dir}/bufr_set -s masterTablesVersionNumber=10 $fBufrTmp /dev/null > $fLog 2>&1 +status=$? +set -e +grep -q "unreadable message" $fLog + # Clean up rm -f $fLog diff --git a/tests/grib_dump.sh b/tests/grib_dump.sh index 472e11d6e..33655a60a 100755 --- a/tests/grib_dump.sh +++ b/tests/grib_dump.sh @@ -108,5 +108,25 @@ ${tools_dir}/grib_dump -w count=4 $file > $temp 2>&1 ECCODES_DEBUG=1 ${tools_dir}/grib_dump $data_dir/sample.grib2 + +# Unreadable message +#----------------------------------------------------------- +tempOut=temp.$label.out +echo GRIB > $temp + +set +e +${tools_dir}/grib_dump $temp > $tempOut 2>&1 +status=$? +set -e +grep -q "unreadable message" $tempOut + +set +e +${tools_dir}/grib_dump -j $temp > $tempOut 2>&1 +status=$? +set -e +grep -q "unreadable message" $tempOut + +rm -f $tempOut + # Clean up rm -f $temp diff --git a/tools/bufr_set.cc b/tools/bufr_set.cc index 4bb055fb9..687127987 100644 --- a/tools/bufr_set.cc +++ b/tools/bufr_set.cc @@ -13,9 +13,6 @@ grib_option grib_options[] = { /* {id, args, help}, on, command_line, value*/ { "s:", 0, 0, 1, 1, 0 }, - /* {"r",0,0,0,1,0}, */ - /* {"d:",0,0,0,1,0},*/ - /* {"n:","noise percentage","\n\t\tAdd noise to the data values. The noise added is the given percentage of the data value.\n",0,1,0},*/ { "p:", 0, 0, 1, 1, 0 }, { "P:", 0, 0, 0, 1, 0 }, { "w:", "key[:{s|d|i}]=value,key[:{s|d|i}]=value,...", @@ -32,7 +29,6 @@ grib_option grib_options[] = { { "U", 0, 0, 1, 0, 0 }, { "V", 0, 0, 0, 1, 0 }, { "g", 0, 0, 0, 1, 0 }, - /* {"G",0,0,0,1,0}, */ { "T:", 0, 0, 1, 0, "B" }, { "f", 0, 0, 0, 1, 0 }, { "v", 0, 0, 0, 1, 0 }, @@ -67,15 +63,6 @@ int grib_tool_init(grib_runtime_options* options) } if (options->verbose) options->print_header = 1; - /*if (grib_options_on("n:")) { - noise=atof(grib_options_get_option("n:")); - options->repack=1; - }*/ - - if (grib_options_on("n:") && grib_options_on("d:")) { - fprintf(stderr, "ERROR: -n and -d options are incompatible. Choose one of the two please.\n"); - exit(1); - } // if (options->outfile && options->outfile->name) { // options->outfile->file = fopen(options->outfile->name,"w");