Testing: codes_extract_offsets_sizes_malloc

This commit is contained in:
Shahram Najm 2024-02-02 17:31:25 +00:00
parent a3e8be20b4
commit b3594219a6
2 changed files with 42 additions and 8 deletions

View File

@ -12,25 +12,38 @@
#undef NDEBUG
#include <assert.h>
#include <unistd.h>
int main(int argc, char* argv[])
{
char *filename = NULL;
char *what = NULL; // offsets or sizes
int err = 0;
int num_messages = 0, i =0;
off_t* offsets = NULL;
size_t* sizes = NULL;
codes_context* c = codes_context_get_default();
const int strict_mode = 1;
int do_offsets = 0;
int do_sizes = 0;
int index = 0, oc = 0;
/* Usage: prog mode file */
assert(argc == 3);
/* Usage: prog option file */
assert(argc == 3 || argc == 4);
what = argv[1];
filename = argv[2];
while ((oc = getopt(argc, argv, "os")) != -1) {
switch (oc) {
case 'o':
do_offsets = 1;
break;
case 's':
do_sizes = 1;
break;
}
}
index = optind;
filename = argv[index];
if (strcmp(what, "-o")==0) {
if (do_offsets) {
err = codes_extract_offsets_malloc(c, filename, PRODUCT_ANY, &offsets, &num_messages, strict_mode);
if (err) return err;
@ -40,7 +53,7 @@ int main(int argc, char* argv[])
free(offsets);
}
if (strcmp(what, "-s")==0) {
if (do_sizes) {
// Version getting offsets as well as sizes of messages
err = codes_extract_offsets_sizes_malloc(c, filename, PRODUCT_ANY, &offsets, &sizes, &num_messages, strict_mode);
if (err) return err;

View File

@ -15,6 +15,7 @@ label="extract_offsets_test"
temp1="temp.${label}.1"
temp2="temp.${label}.2"
tempLog="temp.${label}.log"
tempRef="temp.${label}.ref"
echo "Multi-message BUFR..."
# ---------------------------
@ -35,8 +36,28 @@ for input in $inputs; do
$EXEC ${test_dir}/extract_offsets -o $input > $temp1
${tools_dir}/grib_get -p offset:i $input > $temp2
diff $temp1 $temp2
$EXEC ${test_dir}/extract_offsets -s $input > $temp1
${tools_dir}/grib_get -p totalLength $input > $temp2
diff $temp1 $temp2
done
echo "GTS headers and padding..."
# -------------------------------
input=${data_dir}/gts.grib
$EXEC ${test_dir}/extract_offsets -o -s $input > $temp1
cat > $tempRef << EOF
41
170
299
428
84
84
84
84
EOF
diff $tempRef $temp1
echo "Test with invalid inputs..."
# ---------------------------------
set +e
@ -62,4 +83,4 @@ grep -q "Unable to read file" $tempLog
# Clean up
rm -f $temp1 $temp2 $tempLog
rm -f $temp1 $temp2 $tempLog $tempRef