From 7b36814d1136cbbe4e2157e4d2288da8f34f9cbd Mon Sep 17 00:00:00 2001 From: shahramn Date: Thu, 22 Feb 2024 17:36:39 +0000 Subject: [PATCH] Testing: codes_get_string for different products --- src/grib_accessor_class_message.cc | 2 +- tests/codes_get_string.cc | 13 +++++++++---- tests/codes_get_string.sh | 14 +++++++++----- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/grib_accessor_class_message.cc b/src/grib_accessor_class_message.cc index 8dd580d3e..6c5587b22 100644 --- a/src/grib_accessor_class_message.cc +++ b/src/grib_accessor_class_message.cc @@ -142,7 +142,7 @@ static int value_count(grib_accessor* a, long* count) static int unpack_string(grib_accessor* a, char* val, size_t* len) { long i = 0; - size_t l = a->length + 1; + size_t l = string_length(a) + 1; grib_handle* h = grib_handle_of_accessor(a); if (*len < l) { diff --git a/tests/codes_get_string.cc b/tests/codes_get_string.cc index d0cf15192..db98de25e 100644 --- a/tests/codes_get_string.cc +++ b/tests/codes_get_string.cc @@ -18,15 +18,20 @@ int main(int argc, char* argv[]) size_t len = 0; int err = 0; - assert(argc == 3); + assert(argc == 4); - const char* infile = argv[1]; + const char* prod = argv[1]; + const char* infile = argv[2]; FILE* in = fopen(infile, "rb"); assert(in); - char* key = argv[2]; + char* key = argv[3]; char kvalue[2] = {0,}; // deliberately short + ProductKind productKind = PRODUCT_GRIB; + if (strcmp(prod, "BUFR")==0) productKind = PRODUCT_BUFR; + if (strcmp(prod, "GTS")==0) productKind = PRODUCT_GTS; + if (strcmp(prod, "ANY")==0) productKind = PRODUCT_ANY; - h = codes_handle_new_from_file(NULL, in, PRODUCT_ANY, &err); + h = codes_handle_new_from_file(NULL, in, productKind, &err); assert(h); assert(!err); diff --git a/tests/codes_get_string.sh b/tests/codes_get_string.sh index 011224253..a42ef9f97 100755 --- a/tests/codes_get_string.sh +++ b/tests/codes_get_string.sh @@ -15,29 +15,33 @@ tempGrib=temp.$label.grib tempText=temp.$label.txt input=$ECCODES_SAMPLES_PATH/GRIB1.tmpl -$EXEC ${test_dir}/codes_get_string $input dataDate +$EXEC ${test_dir}/codes_get_string GRIB $input dataDate ${tools_dir}/grib_set -s marsType=s3,marsStream=mpic $input $tempGrib -$EXEC ${test_dir}/codes_get_string $tempGrib dayOfTheYearDate # 2> $tempText +$EXEC ${test_dir}/codes_get_string GRIB $tempGrib dayOfTheYearDate # 2> $tempText input=$data_dir/reduced_latlon_surface.grib2 keys="identifier projString bitmap class year gridDefinitionDescription time validityTime packingType md5Headers parameterUnits" for k in $keys; do - $EXEC ${test_dir}/codes_get_string $input $k 2> $tempText + $EXEC ${test_dir}/codes_get_string GRIB $input $k 2> $tempText grep -q "Buffer too small" $tempText done input=$ECCODES_SAMPLES_PATH/reduced_gg_ml_grib2.tmpl -$EXEC ${test_dir}/codes_get_string "$input" gridName 2> $tempText +$EXEC ${test_dir}/codes_get_string GRIB "$input" gridName 2> $tempText grep -q "Buffer too small" $tempText # shortName = swh input=$data_dir/reduced_latlon_surface.grib1 -$EXEC ${test_dir}/codes_get_string "$input" shortName 2> $tempText +$EXEC ${test_dir}/codes_get_string GRIB "$input" shortName 2> $tempText grep -q "Buffer too small" $tempText +input=$data_dir/gts/EGRR20150317121020_00493212.DAT +$EXEC ${test_dir}/codes_get_string GTS "$input" theMessage 2> $tempText +grep -q "Buffer too small" $tempText +# Clean up rm -f $tempText