Add test case for bugfix of #1442

This commit is contained in:
Even Rouault 2019-07-18 02:23:43 +02:00
parent 77ffbce43b
commit 0c7be1d278
No known key found for this signature in database
GPG Key ID: 33EBBFC47B3DD87D
2 changed files with 74 additions and 1 deletions

View File

@ -20,7 +20,7 @@ SET(NC4_TESTS tst_dims tst_dims2 tst_dims3 tst_files tst_files4
tst_files6 tst_sync tst_h_strbug tst_h_refs tst_h_scalar tst_rename
tst_rename2 tst_rename3 tst_h5_endians tst_atts_string_rewrite tst_put_vars_two_unlim_dim
tst_hdf5_file_compat tst_fill_attr_vanish tst_rehash tst_types tst_bug324
tst_atts3 tst_put_vars tst_elatefill tst_udf)
tst_atts3 tst_put_vars tst_elatefill tst_udf tst_bug1442)
# Note, renamegroup needs to be compiled before run_grp_rename

73
nc_test4/tst_bug1442.c Normal file
View File

@ -0,0 +1,73 @@
/*! \file
Copyright 2019
University Corporation for Atmospheric Research/Unidata.
See \ref copyright file for more info.
*/
#include <nc_tests.h>
#include "err_macros.h"
#include <stdio.h>
#include <stdlib.h>
#include <netcdf.h>
#define FILENAME "tst_bug1442nc"
int
main(int argc, char **argv)
{
/* Test bugfix for https://github.com/Unidata/netcdf-c/pull/1442 */
/* that is using nc_get_vara_xxx() with a offset[] != 0 on a variable */
/* indexed by a unlimited dimension, and the size taken by that variable */
/* does not reach the actual size of that dimension */
int status;
int cdfid = -1;
int unlimited_dim;
int varid;
int other_var;
size_t start[1];
size_t count[1];
double three_zeros[3] = {0, 0, 0};
double* two_double = (double*)calloc(2, sizeof(double));
status = nc_create(FILENAME, NC_NETCDF4, &cdfid);
if( status ) ERR;
status = nc_def_dim(cdfid, "unlimited_dim", NC_UNLIMITED, &unlimited_dim);
if( status ) ERR;
status = nc_def_var(cdfid, "my_var", NC_DOUBLE, 1, &unlimited_dim, &varid);
if( status ) ERR;
status = nc_def_var(cdfid, "other_var", NC_DOUBLE, 1, &unlimited_dim, &other_var);
if( status ) ERR;
status = nc_enddef(cdfid);
if( status ) ERR;
/* Write 3 elements to set the size of the unlimited dim to 3 */
start[0] = 0;
count[0] = 3;
status = nc_put_vara_double(cdfid, other_var, start, count, three_zeros);
if( status ) ERR;
/* Read 2 elements starting with index=1 */
start[0] = 1;
count[0] = 2;
status = nc_get_vara_double(cdfid, varid, start, count, two_double);
if( status ) ERR;
if( two_double[0] != NC_FILL_DOUBLE ) ERR;
if( two_double[1] != NC_FILL_DOUBLE ) ERR;
status = nc_close(cdfid);
if( status ) ERR;
free(two_double);
SUMMARIZE_ERR;
FINAL_RESULTS;
return 0;
}