ECC-401: More tests and fix output indentation

This commit is contained in:
Shahram Najm 2019-08-29 12:13:41 +01:00
parent bd51d020da
commit 0c928512b1
2 changed files with 37 additions and 15 deletions

View File

@ -11,7 +11,16 @@
. ./include.sh
tempLog=temp.grib_ls_json.log
rm -f $tempLog
tempOut=temp.grib_ls_json.txt
tempRef=temp.grib_ls_json.ref
rm -f $tempLog $tempOut $tempRef
# Decide if we have the JSON verifier commandline utility
JSON_VERIF="json_xs"
JSON_CHECK=""
if command -v $JSON_VERIF >/dev/null 2>&1; then
JSON_CHECK=$JSON_VERIF
fi
cd ${data_dir}
@ -31,15 +40,35 @@ if grep -q 'not_found' $tempLog; then
exit 1
fi
# Test ordering
# ----------------------------------------------------
input=high_level_api.grib2
${tools_dir}/grib_ls -j -B'step:i desc' $input > $tempLog
if test "x$JSON_CHECK" != "x"; then
json_xs -t none < $tempLog
fi
grep stepRange $tempLog > $tempOut
cat > $tempRef <<EOF
"stepRange": 24,
"stepRange": 18,
"stepRange": 12,
"stepRange": 6,
"stepRange": 0,
EOF
diff $tempRef $tempOut
# Test a MISSING key
# --------------------
# ----------------------------------------------------
input=sample.grib2
${tools_dir}/grib_ls -j -p scaledValueOfEarthMajorAxis $input > $tempLog
grep -q '"scaledValueOfEarthMajorAxis": "MISSING"' $tempLog
# Test decoding a given key as string and integer
# ---------------------------------------------
# ----------------------------------------------------
input=$ECCODES_SAMPLES_PATH/GRIB1.tmpl
${tools_dir}/grib_ls -j -p levelType,levelType:i $input > $tempLog
grep -q '"levelType": "pl"' $tempLog
@ -47,7 +76,7 @@ grep -q '"levelType": 100' $tempLog
# Test decoding floating point key with format
# ---------------------------------------------
# ----------------------------------------------------
input=$ECCODES_SAMPLES_PATH/reduced_gg_pl_128_grib2.tmpl
${tools_dir}/grib_ls -j -p latitudeOfLastGridPointInDegrees $input > $tempLog
grep -q '"latitudeOfLastGridPointInDegrees": -89.4628' $tempLog
@ -56,15 +85,8 @@ ${tools_dir}/grib_ls -F%.3f -j -p latitudeOfLastGridPointInDegrees $input > $tem
grep -q '"latitudeOfLastGridPointInDegrees": -89.463' $tempLog
# Check JSON validity
# --------------------
# Decide if we have the JSON verifier commandline utility
JSON_VERIF="json_xs"
JSON_CHECK=""
if command -v $JSON_VERIF >/dev/null 2>&1; then
JSON_CHECK=$JSON_VERIF
fi
# Check output from all our downloaded GRIBs
# ----------------------------------------------------
grib_files=`cat ${data_dir}/grib_data_files.txt`
for file in ${grib_files}
do
@ -77,4 +99,4 @@ done
# Clean up
rm -f $tempLog
rm -f $tempLog $tempOut $tempRef

View File

@ -973,7 +973,7 @@ void grib_print_key_values(grib_runtime_options* options, grib_handle* h)
/* fprintf(dump_file, "\"message %d\" : {\n", options->handle_count); */
fprintf(dump_file, " {\n");
for (i=0;i<options->print_keys_count;i++) {
fprintf(dump_file,"\t\"%s\": ", options->print_keys[i].name);
fprintf(dump_file," \"%s\": ", options->print_keys[i].name);
get_value_for_key(h, options->print_keys[i].name, options->print_keys[i].type, value, options->format);
if (is_valid_JSON_number(value))
fprintf(dump_file,"%s", value);