mirror of https://github.com/ecmwf/eccodes.git
ECC-1288: Add test
This commit is contained in:
parent
862897f46e
commit
bddded25b3
|
@ -30,6 +30,7 @@ list(APPEND test_bins
|
|||
grib_optimize_scaling_sh
|
||||
grib_ecc-386
|
||||
bufr_ecc-517
|
||||
bufr_ecc-1288
|
||||
bufr_get_element
|
||||
bufr_extract_headers
|
||||
extract_offsets
|
||||
|
@ -317,6 +318,12 @@ if( HAVE_BUILD_TOOLS )
|
|||
CONDITION NOT ECCODES_ON_WINDOWS AND ENABLE_EXTRA_TESTS
|
||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bufr_ecc-197.sh
|
||||
TEST_DEPENDS eccodes_download_bufrs )
|
||||
ecbuild_add_test( TARGET eccodes_t_bufr_ecc-1288
|
||||
TYPE SCRIPT
|
||||
CONDITION NOT ECCODES_ON_WINDOWS AND ENABLE_EXTRA_TESTS
|
||||
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/bufr_ecc-1288.sh
|
||||
TEST_DEPENDS eccodes_download_bufrs )
|
||||
|
||||
|
||||
if( ENABLE_EXTRA_TESTS AND HAVE_ECCODES_THREADS )
|
||||
ecbuild_add_executable( TARGET grib_encode_pthreads
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
#include "eccodes.h"
|
||||
#include <assert.h>
|
||||
|
||||
const char* KEY = "encryptedShipOrMobileLandStationIdentifier";
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
FILE* in = NULL;
|
||||
codes_handle* h = NULL;
|
||||
int err = 0;
|
||||
size_t slen = 0;
|
||||
char buf[256] = {0,};
|
||||
char** strArray = NULL; /* array of strings */
|
||||
|
||||
const char* infile = argv[1];
|
||||
const char* DEFS_PATH_LOCAL = argv[2];
|
||||
|
||||
assert(infile);
|
||||
in = fopen(infile, "rb");
|
||||
assert(in);
|
||||
|
||||
h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err);
|
||||
assert(h && !err);
|
||||
printf("Phase 1: unpacking...\n");
|
||||
codes_set_long(h, "unpack", 1); /* An error should be issued */
|
||||
assert ( !codes_is_defined(h, KEY) );
|
||||
codes_handle_delete(h);
|
||||
|
||||
printf("Wipe the cache and extend the definitions path...\n");
|
||||
sprintf(buf, "%s:%s", DEFS_PATH_LOCAL, codes_definition_path(NULL));
|
||||
codes_context_delete(NULL);
|
||||
codes_context_set_definitions_path(NULL, buf);
|
||||
printf("ECCODES_DEFINITION_PATH is now = |%s|\n", buf);
|
||||
|
||||
/* Now rewind and decode the BUFR again */
|
||||
fseeko(in, 0, SEEK_SET);
|
||||
h = codes_handle_new_from_file(NULL, in, PRODUCT_BUFR, &err); assert(h); assert(!err);
|
||||
printf("Phase 2: unpacking...\n");
|
||||
err = codes_set_long(h, "unpack", 1);
|
||||
|
||||
CODES_CHECK(codes_get_size(h, KEY, &slen), 0);
|
||||
assert( slen == 40 );
|
||||
strArray = (char**)malloc(slen * sizeof(char*));
|
||||
CODES_CHECK(codes_get_string_array(h, KEY, strArray, &slen), 0);
|
||||
assert( slen == 40 );
|
||||
assert( strcmp(strArray[0], "ABCDEFHIJ0123456789ABCDEFGHIJ0123456789ABCD ") == 0 );
|
||||
codes_handle_delete(h);
|
||||
|
||||
fclose(in);
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
#!/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.sh
|
||||
|
||||
# ---------------------------------------------------------
|
||||
# This is the test for the JIRA issue ECC-1288.
|
||||
# It tests decoding a BUFR file which cannot be done unless
|
||||
# we extend the definitions to include extra files
|
||||
# ---------------------------------------------------------
|
||||
label="bufr_ecc-1288-test"
|
||||
|
||||
TEMP=${label}.temp
|
||||
LOG=${label}.log
|
||||
set -u
|
||||
|
||||
# Create a temporary directory which holds the tables etc
|
||||
TEMP_DIR=${label}.temp-dir.$$
|
||||
rm -rf $TEMP_DIR
|
||||
mkdir -p $TEMP_DIR/definitions/bufr/tables/0/local/0/65535/0
|
||||
|
||||
# Copy the definition files needed to decode our BUFR file
|
||||
def_files="${proj_dir}/tests/ECC-197/*"
|
||||
for df in ${def_files}; do
|
||||
cp -f $df $TEMP_DIR/definitions/bufr/tables/0/local/0/65535/0
|
||||
done
|
||||
LOCAL_DEFS=`pwd`/$TEMP_DIR/definitions
|
||||
|
||||
input=${data_dir}/bufr/vos308014_v3_26.bufr
|
||||
$EXEC ${test_dir}/bufr_ecc-1288 $input "$LOCAL_DEFS" 2>$LOG
|
||||
|
||||
grep -q "ECCODES ERROR : hash_array: no match for sequences=308014" $LOG
|
||||
|
||||
# Clean up
|
||||
rm -rf $TEMP_DIR
|
||||
rm -f $TEMP $LOG
|
Loading…
Reference in New Issue