mirror of
https://github.com/Unidata/netcdf-c.git
synced 2024-11-27 07:30:33 +08:00
Add test cases
This commit is contained in:
parent
aa3a9f033a
commit
9e016b85aa
@ -12,7 +12,9 @@ include $(top_srcdir)/lib_flags.am
|
||||
|
||||
# Un comment to use a more verbose test driver
|
||||
#SH_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
|
||||
#sh_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
|
||||
#LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
|
||||
#TESTS_ENVIRONMENT = export SETX=1;
|
||||
|
||||
TEST_EXTENSIONS = .sh
|
||||
|
||||
|
@ -48,8 +48,6 @@ main() {/* create bzip2.nc */
|
||||
/* enter define mode */
|
||||
stat = nc_create("bzip2.nc", NC_CLOBBER|NC_NETCDF4, &ncid);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
stat = nc_put_att_text(ncid, NC_GLOBAL, "_Format", 1, "netCDF-4");
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
bzip2_grp = ncid;
|
||||
|
||||
/* define dimensions */
|
||||
|
@ -3,6 +3,8 @@
|
||||
if test "x$srcdir" = x ; then srcdir=`pwd`; fi
|
||||
. ../test_common.sh
|
||||
|
||||
set -x
|
||||
|
||||
# Which test cases to exercise
|
||||
API=1
|
||||
NG=1
|
||||
|
@ -264,6 +264,9 @@ ENDIF(MSVC)
|
||||
ENDIF(USE_NETCDF4)
|
||||
|
||||
add_sh_test(ncdump test_radix)
|
||||
|
||||
add_sh_test(ncdump tst_ctests)
|
||||
|
||||
ENDIF()
|
||||
|
||||
ENDIF()
|
||||
@ -296,7 +299,7 @@ SET(MAN_FILES nccopy.1 ncdump.1)
|
||||
# Note, the L512.bin file is file containing exactly 512 bytes each of value 0.
|
||||
# It is used for creating hdf5 files with varying offsets for testing.
|
||||
|
||||
FILE(GLOB COPY_FILES ${CMAKE_BINARY_DIR}/ncgen/*.nc ${CMAKE_BINARY_DIR}/nc_test4/*.nc ${CMAKE_CURRENT_SOURCE_DIR}/*.ncml ${CMAKE_CURRENT_SOURCE_DIR}/*.nc ${CMAKE_CURRENT_SOURCE_DIR}/*.cdl ${CMAKE_CURRENT_SOURCE_DIR}/*.sh ${CMAKE_CURRENT_SOURCE_DIR}/*.1 ${CMAKE_CURRENT_SOURCE_DIR}/L512.bin)
|
||||
FILE(GLOB COPY_FILES ${CMAKE_BINARY_DIR}/ncgen/*.nc ${CMAKE_BINARY_DIR}/nc_test4/*.nc ${CMAKE_CURRENT_SOURCE_DIR}/*.ncml ${CMAKE_CURRENT_SOURCE_DIR}/*.nc ${CMAKE_CURRENT_SOURCE_DIR}/*.cdl ${CMAKE_CURRENT_SOURCE_DIR}/*.sh ${CMAKE_CURRENT_SOURCE_DIR}/*.1 ${CMAKE_CURRENT_SOURCE_DIR}/L512.bin ${CMAKE_CURRENT_SOURCE_DIR}/ref_ctest*.c)
|
||||
FILE(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/ FILE_PERMISSIONS OWNER_WRITE OWNER_READ OWNER_EXECUTE)
|
||||
|
||||
ADD_SUBDIRECTORY(cdl)
|
||||
|
@ -109,7 +109,7 @@ endif
|
||||
|
||||
if USE_HDF5
|
||||
# Re-activate the ncgen -lc tests
|
||||
TESTS += ctests.sh
|
||||
TESTS += tst_ctests.sh
|
||||
endif
|
||||
|
||||
endif BUILD_TESTSETS
|
||||
@ -156,7 +156,7 @@ ref_nccopy_w.cdl tst_nccopy_w3.sh tst_nccopy_w4.sh ref_no_ncproperty.nc
|
||||
EXTRA_DIST += L512.bin
|
||||
|
||||
EXTRA_DIST += ref_ctest_small_3.c ref_ctest_small_4.c \
|
||||
ref_ctest_tst_special_atts_4.c
|
||||
ref_ctest_special_atts_4.c
|
||||
|
||||
# CDL files and Expected results
|
||||
SUBDIRS = cdl expected
|
||||
|
@ -13,26 +13,53 @@ check_err(const int stat, const int line, const char *file) {
|
||||
}
|
||||
|
||||
int
|
||||
main() {/* create small.nc */
|
||||
main() {/* create ref_tst_small.nc */
|
||||
|
||||
int stat; /* return status */
|
||||
int ncid; /* netCDF id */
|
||||
|
||||
/* dimension ids */
|
||||
int Time_dim;
|
||||
int DateStrLen_dim;
|
||||
|
||||
/* dimension lengths */
|
||||
size_t Time_len = NC_UNLIMITED;
|
||||
size_t DateStrLen_len = 19;
|
||||
|
||||
/* variable ids */
|
||||
int t_id;
|
||||
int Times_id;
|
||||
|
||||
/* rank (number of dimensions) for each variable */
|
||||
# define RANK_t 0
|
||||
# define RANK_Times 2
|
||||
|
||||
/* variable shapes */
|
||||
int Times_dims[RANK_Times];
|
||||
|
||||
/* enter define mode */
|
||||
stat = nc_create("small.nc", NC_CLOBBER, &ncid);
|
||||
stat = nc_create("ref_tst_small.nc", NC_CLOBBER, &ncid);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
|
||||
/* define dimensions */
|
||||
stat = nc_def_dim(ncid, "Time", Time_len, &Time_dim);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
stat = nc_def_dim(ncid, "DateStrLen", DateStrLen_len, &DateStrLen_dim);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
|
||||
/* define variables */
|
||||
|
||||
stat = nc_def_var(ncid, "t", NC_BYTE, RANK_t, 0, &t_id);
|
||||
Times_dims[0] = Time_dim;
|
||||
Times_dims[1] = DateStrLen_dim;
|
||||
stat = nc_def_var(ncid, "Times", NC_CHAR, RANK_Times, Times_dims, &Times_id);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
|
||||
/* assign global attributes */
|
||||
|
||||
{
|
||||
stat = nc_put_att_text(ncid, NC_GLOBAL, "TITLE", 31, " OUTPUT FROM WRF V2.0.3.1 MODEL");
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
|
||||
/* leave define mode */
|
||||
stat = nc_enddef (ncid);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
@ -40,9 +67,10 @@ main() {/* create small.nc */
|
||||
/* assign variable data */
|
||||
|
||||
{
|
||||
size_t count = 0;
|
||||
static signed char t_data[1] = {1};
|
||||
stat = nc_put_var1(ncid, t_id, &count, t_data);
|
||||
char* Times_data = "2005-04-11_12:00:002005-04-11_13:00:00" ;
|
||||
size_t Times_startset[2] = {0, 0} ;
|
||||
size_t Times_countset[2] = {2, 19};
|
||||
stat = nc_put_vara(ncid, Times_id, Times_startset, Times_countset, Times_data);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
|
@ -14,45 +14,73 @@ check_err(const int stat, const int line, const char *file) {
|
||||
}
|
||||
|
||||
int
|
||||
main() {/* create small.nc */
|
||||
main() {/* create ref_tst_small.nc */
|
||||
|
||||
int stat; /* return status */
|
||||
int ncid; /* netCDF id */
|
||||
|
||||
/* group ids */
|
||||
int small_grp;
|
||||
int tst_small_grp;
|
||||
|
||||
/* dimension ids */
|
||||
int Time_dim;
|
||||
int DateStrLen_dim;
|
||||
|
||||
/* dimension lengths */
|
||||
size_t Time_len = NC_UNLIMITED;
|
||||
size_t DateStrLen_len = 19;
|
||||
|
||||
/* variable ids */
|
||||
int t_id;
|
||||
int Times_id;
|
||||
|
||||
/* rank (number of dimensions) for each variable */
|
||||
# define RANK_t 0
|
||||
# define RANK_Times 2
|
||||
|
||||
/* variable shapes */
|
||||
int Times_dims[RANK_Times];
|
||||
|
||||
/* enter define mode */
|
||||
stat = nc_create("small.nc", NC_CLOBBER|NC_NETCDF4, &ncid);
|
||||
stat = nc_create("ref_tst_small.nc", NC_CLOBBER|NC_NETCDF4, &ncid);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
tst_small_grp = ncid;
|
||||
|
||||
/* define dimensions */
|
||||
stat = nc_def_dim(tst_small_grp, "Time", Time_len, &Time_dim);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
stat = nc_def_dim(tst_small_grp, "DateStrLen", DateStrLen_len, &DateStrLen_dim);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
small_grp = ncid;
|
||||
|
||||
/* define variables */
|
||||
|
||||
stat = nc_def_var(small_grp, "t", NC_BYTE, RANK_t, 0, &t_id);
|
||||
Times_dims[0] = Time_dim;
|
||||
Times_dims[1] = DateStrLen_dim;
|
||||
stat = nc_def_var(tst_small_grp, "Times", NC_CHAR, RANK_Times, Times_dims, &Times_id);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
|
||||
/* assign global attributes */
|
||||
|
||||
{
|
||||
stat = nc_put_att_text(tst_small_grp, NC_GLOBAL, "TITLE", 31, " OUTPUT FROM WRF V2.0.3.1 MODEL");
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
|
||||
/* leave define mode */
|
||||
stat = nc_enddef (small_grp);
|
||||
stat = nc_enddef (tst_small_grp);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
|
||||
/* assign variable data */
|
||||
|
||||
{
|
||||
size_t count = 0;
|
||||
static signed char t_data[1] = {1};
|
||||
stat = nc_put_var1(small_grp, t_id, &count, t_data);
|
||||
char* Times_data = "2005-04-11_12:00:002005-04-11_13:00:00" ;
|
||||
size_t Times_startset[2] = {0, 0} ;
|
||||
size_t Times_countset[2] = {2, 19};
|
||||
stat = nc_put_vara(tst_small_grp, Times_id, Times_startset, Times_countset, Times_data);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
}
|
||||
|
||||
|
||||
stat = nc_close(small_grp);
|
||||
stat = nc_close(tst_small_grp);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
return 0;
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ check_err(const int stat, const int line, const char *file) {
|
||||
}
|
||||
|
||||
int
|
||||
main() {/* create tst_special_atts.nc */
|
||||
main() {/* create ref_tst_special_atts.nc */
|
||||
|
||||
int stat; /* return status */
|
||||
int ncid; /* netCDF id */
|
||||
@ -73,7 +73,7 @@ main() {/* create tst_special_atts.nc */
|
||||
int var5_dims[RANK_var5];
|
||||
|
||||
/* enter define mode */
|
||||
stat = nc_create("tst_special_atts.nc", NC_CLOBBER|NC_NETCDF4, &ncid);
|
||||
stat = nc_create("ref_tst_special_atts.nc", NC_CLOBBER|NC_NETCDF4, &ncid);
|
||||
check_err(stat,__LINE__,__FILE__);
|
||||
tst_special_atts_grp = ncid;
|
||||
|
@ -26,12 +26,13 @@ for f in $2 ; do
|
||||
echo "Testing ${f}"
|
||||
F="${f}${SF}"
|
||||
rm -f ./ctest_${F}.c
|
||||
${NCGEN} -$K -lc ${srcdir}/${f}.cdl > ./ctest_${F}.c
|
||||
${NCGEN} -$K -lc ${srcdir}/ref_tst_${f}.cdl > ./ctest_${F}.c
|
||||
diff -w ./ctest_${F}.c ${srcdir}/ref_ctest_${F}.c
|
||||
done
|
||||
}
|
||||
|
||||
dotest 3 "small"
|
||||
#dotest 3 "small"
|
||||
if test "x$NETCDF4" = x1 ; then
|
||||
dotest 4 "small tst_special_atts"
|
||||
# dotest 4 "small special_atts"
|
||||
dotest 4 "special_atts"
|
||||
fi
|
Loading…
Reference in New Issue
Block a user