From 6b036cfc287f15c800d2e80440c0ba109b05c8d1 Mon Sep 17 00:00:00 2001 From: Ward Fisher Date: Wed, 29 Mar 2017 11:23:47 -0600 Subject: [PATCH] Adding test in support of https://github.com/Unidata/netcdf-c/issues/384 --- nc_test/CMakeLists.txt | 2 +- nc_test/Makefile.am | 4 ++-- nc_test/tst_elatefill.c | 43 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 nc_test/tst_elatefill.c diff --git a/nc_test/CMakeLists.txt b/nc_test/CMakeLists.txt index f46ac171f4..af76765479 100644 --- a/nc_test/CMakeLists.txt +++ b/nc_test/CMakeLists.txt @@ -22,7 +22,7 @@ TARGET_LINK_LIBRARIES(nc_test ) # Some extra stand-alone tests -SET(TESTS t_nc tst_small tst_misc tst_norm tst_names tst_nofill tst_nofill2 tst_nofill3 tst_meta tst_inq_type) +SET(TESTS t_nc tst_small tst_misc tst_norm tst_names tst_nofill tst_nofill2 tst_nofill3 tst_meta tst_inq_type tst_elatefill) IF(NOT HAVE_BASH) SET(TESTS ${TESTS} tst_atts3) diff --git a/nc_test/Makefile.am b/nc_test/Makefile.am index 2423829096..e8d77cdb69 100644 --- a/nc_test/Makefile.am +++ b/nc_test/Makefile.am @@ -14,7 +14,7 @@ tst_*.nc t_nc.nc large_files.nc quick_large_files.nc \ tst_diskless.nc tst_diskless2.nc \ tst_diskless3.nc tst_diskless3_file.cdl tst_diskless3_memory.cdl \ tst_diskless4.cdl tst_diskless4.nc tst_formatx.nc nc_test_cdf5.nc \ -unlim.nc tst_inq_type.nc +unlim.nc tst_inq_type.nc tst_elatefill.nc # These are the tests which are always run. TESTPROGRAMS = t_nc tst_small nc_test tst_misc tst_norm \ @@ -22,7 +22,7 @@ TESTPROGRAMS = t_nc tst_small nc_test tst_misc tst_norm \ tst_meta tst_inq_type tst_utf8_validate tst_utf8_phrases if USE_NETCDF4 -TESTPROGRAMS += tst_atts tst_put_vars +TESTPROGRAMS += tst_atts tst_put_vars tst_elatefill endif if USE_PNETCDF diff --git a/nc_test/tst_elatefill.c b/nc_test/tst_elatefill.c new file mode 100644 index 0000000000..4e9043ac2f --- /dev/null +++ b/nc_test/tst_elatefill.c @@ -0,0 +1,43 @@ +/* This is part of the netCDF package. Copyright 2017 University + Corporation for Atmospheric Research/Unidata See COPYRIGHT file for + conditions of use. See www.unidata.ucar.edu for more info. + + Test proper elatefill return when fillvalue is assigned outside of + the initial define. + + Contributed by wkliao, see the following for more information: + + * https://github.com/Unidata/netcdf-c/issues/384 + * https://github.com/Unidata/netcdf-c/pull/387 + * https://github.com/Unidata/netcdf-c/issues/390 +*/ + +#include "config.h" +#include +#include "err_macros.h" +#include +#include + +#define FILE_NAME "tst_elatefill.nc" + +int +main(int argc, char **argv) +{ + int ncid, dimid, varid, err; + int no_fill, fillv, buf[10]; + + err = nc_create(FILE_NAME, NC_NETCDF4, &ncid); ERR; + err = nc_def_dim(ncid, "dim", 10, &dimid); ERR; + err = nc_def_var(ncid, "var", NC_INT, 1, &dimid, &varid); ERR; + err = nc_enddef(ncid); ERR; + + err = nc_redef(ncid); ERR; + + /* try put attribute _FillValue and expect NC_ELATEFILL */ + fillv = 9; + err = nc_put_att_int(ncid, varid, _FillValue, NC_INT, 1, &fillv); + if (err != NC_ELATEFILL) + printf("line %d expecting NC_ELATEFILL but got %d\n",__LINE__,err); + err = nc_close(ncid); ERR; + return 0; +}