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

View File

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