mirror of
https://github.com/Unidata/netcdf-c.git
synced 2025-01-30 16:10:44 +08:00
add a test program to read a CDF-5 file with a corrupted header
This commit is contained in:
parent
294c734f64
commit
f00c43fc04
@ -105,6 +105,12 @@ test_read.m4 test_write.m4
|
||||
# ref_tst_diskless2.cdl is for diff comparison and to produce tst_diskless2.c
|
||||
EXTRA_DIST += ref_tst_diskless2.cdl tst_diskless5.cdl CMakeLists.txt
|
||||
|
||||
# bad_cdf5_begin.nc is a CDF-5 file with bad variable starting file offsets.
|
||||
# It is to be used by tst_open_cdf5.c to see if it can report NC_ENOTNC.
|
||||
EXTRA_DIST += bad_cdf5_begin.nc
|
||||
TESTS += run_cdf5.sh
|
||||
check_PROGRAMS += tst_open_cdf5
|
||||
|
||||
# Only clean these on maintainer-clean, because they require m4 to
|
||||
# regenerate.
|
||||
#MAINTAINERCLEANFILES = test_get.c test_put.c
|
||||
|
BIN
nc_test/bad_cdf5_begin.nc
Normal file
BIN
nc_test/bad_cdf5_begin.nc
Normal file
Binary file not shown.
25
nc_test/tst_open_cdf5.c
Normal file
25
nc_test/tst_open_cdf5.c
Normal file
@ -0,0 +1,25 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <netcdf.h>
|
||||
|
||||
#define FILE_NAME "bad_cdf5_begin.nc"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *fname=FILE_NAME;
|
||||
int err, nerrs=0, ncid;
|
||||
|
||||
if (argc == 2) fname = argv[1];
|
||||
|
||||
err = nc_open(fname, NC_NOWRITE, &ncid);
|
||||
if (err != NC_ENOTNC) {
|
||||
printf("Error: nc_open() expect NC_ENOTNC but got (%s)\n",
|
||||
nc_strerror(err));
|
||||
nerrs++;
|
||||
}
|
||||
else if (err == NC_NOERR) /* close file */
|
||||
nc_close(ncid);
|
||||
|
||||
return (nerrs > 0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user