Message offsets: Add test

This commit is contained in:
Shahram Najm 2020-11-30 21:08:16 +00:00
parent 664732b639
commit 10cddf8e96
3 changed files with 79 additions and 0 deletions

View File

@ -30,6 +30,7 @@ list(APPEND test_bins
bufr_ecc-517
bufr_get_element
bufr_extract_headers
extract_offsets
bufr_check_descriptors
grib_sh_ieee64
ieee
@ -116,6 +117,7 @@ if( HAVE_BUILD_TOOLS )
bufr_get_element
bufr_wmo_tables
bufr_extract_headers
extract_offsets
bufr_ecc-673
bufr_ecc-428
bufr_ecc-286

36
tests/extract_offsets.c Normal file
View File

@ -0,0 +1,36 @@
/*
* (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 "eccodes.h"
#include <assert.h>
int main(int argc, char* argv[])
{
char *filename;
int err = 0;
int num_messages = 0, i =0;
off_t* offsets = NULL;
codes_context* c = codes_context_get_default();
const int strict_mode = 1;
/* Usage: prog file */
assert(argc == 2);
filename = argv[1];
err = codes_extract_offsets_malloc(c, filename, PRODUCT_ANY, &offsets, &num_messages, strict_mode);
if (err) return err;
for (i = 0; i < num_messages; ++i) {
printf("%lu\n", offsets[i]);
}
free(offsets);
return 0;
}

41
tests/extract_offsets.sh Executable file
View File

@ -0,0 +1,41 @@
#!/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
# Define a common label for all the tmp files
label="bufr_extract_offsets_test"
temp1="temp.${label}.1"
temp2="temp.${label}.2"
echo "Multi-message BUFR..."
# ---------------------------
input=${data_dir}/bufr/aeolus_wmo_26.bufr
$EXEC ${test_dir}/extract_offsets $input > $temp1
${tools_dir}/bufr_get -p offset:i $input > $temp2
diff $temp1 $temp2
echo "Multi-message GRIB..."
# --------------------------
input=${data_dir}/mixed.grib
$EXEC ${test_dir}/extract_offsets $input > $temp1
${tools_dir}/grib_get -p offset:i $input > $temp2
diff $temp1 $temp2
echo "Test with invalid inputs..."
# ---------------------------------
set +e
$EXEC ${test_dir}/extract_offsets ${data_dir}
status=$?
set -e
[ $status -ne 0 ]
rm -f $temp1 $temp2