diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 21640b8bb..092d9ea83 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -45,6 +45,7 @@ list(APPEND test_c_bins grib_ecc-1467 grib_ecc-1431 grib_ecc-1433 + grib_ecc-1764 bufr_ecc-517 bufr_ecc-1288 bufr_get_element @@ -259,6 +260,7 @@ if( HAVE_BUILD_TOOLS ) grib_ecc-1397 grib_ecc-1425 grib_ecc-1467 + grib_ecc-1764 grib_sub_hourly grib_set_bytes grib_set_force diff --git a/tests/grib_ecc-1764.cc b/tests/grib_ecc-1764.cc new file mode 100644 index 000000000..a2d884a18 --- /dev/null +++ b/tests/grib_ecc-1764.cc @@ -0,0 +1,44 @@ +/* + * (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 "grib_api.h" +#undef NDEBUG +#include "assert.h" + +int main(int argc, char* argv[]) +{ + int ret = GRIB_SUCCESS; + + if (argc != 2) return 1; + + const char* infile = argv[1]; + grib_index* index = grib_index_new(0, "shortName,level", &ret); + assert(ret == GRIB_SUCCESS); + + ret = grib_index_add_file(index, infile); + assert(ret == GRIB_SUCCESS); + + printf("Select nonexistent entries...\n"); + grib_index_select_string(index, "shortName", "frost"); + grib_index_select_long(index, "level", 666); + + grib_handle* h = grib_handle_new_from_index(index, &ret); + assert(!h); + assert(ret == GRIB_END_OF_INDEX); + + // Call it again. Should not crash + h = grib_handle_new_from_index(index, &ret); + assert(!h); + assert(ret == GRIB_END_OF_INDEX); + + grib_index_delete(index); + grib_context_delete(grib_context_get_default()); + + return 0; +} diff --git a/tests/grib_ecc-1764.sh b/tests/grib_ecc-1764.sh new file mode 100755 index 000000000..81891ec74 --- /dev/null +++ b/tests/grib_ecc-1764.sh @@ -0,0 +1,20 @@ +#!/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="grib_ecc-1764_test" +temp=temp.$label.txt + +infile=${data_dir}/tigge_cf_ecmwf.grib2 +$EXEC ${test_dir}/grib_ecc-1764 $infile # > $temp + +# Clean up +rm -f $temp