[svn-r6730]

Purpose: New tests added.

Description: test VL data for compact dataset; test compact dataset's
	     maximal size.


Platforms tested: h5committested
This commit is contained in:
Raymond Lu 2003-04-22 11:23:42 -05:00
parent 3f620fc1e1
commit 4447d4e5c7
2 changed files with 236 additions and 1 deletions

View File

@ -34,6 +34,7 @@ const char *FILENAME[] = {
"dataset", "dataset",
"compact_dataset", "compact_dataset",
"dset_offset", "dset_offset",
"max_compact_dataset",
NULL NULL
}; };
@ -45,6 +46,8 @@ const char *FILENAME[] = {
#define DSET_COMPACT_NAME "compact" #define DSET_COMPACT_NAME "compact"
#define DSET_SIMPLE_IO_NAME "simple_io" #define DSET_SIMPLE_IO_NAME "simple_io"
#define DSET_COMPACT_IO_NAME "compact_io" #define DSET_COMPACT_IO_NAME "compact_io"
#define DSET_COMPACT_MAX_NAME "max_compact"
#define DSET_COMPACT_MAX2_NAME "max_compact_2"
#define DSET_TCONV_NAME "tconv" #define DSET_TCONV_NAME "tconv"
#define DSET_DEFLATE_NAME "deflate" #define DSET_DEFLATE_NAME "deflate"
#define DSET_SZIP_NAME "szip" #define DSET_SZIP_NAME "szip"
@ -66,6 +69,7 @@ const char *FILENAME[] = {
#define DSET_ONEBYTE_SHUF_NAME "onebyte_shuffle" #define DSET_ONEBYTE_SHUF_NAME "onebyte_shuffle"
#define USER_BLOCK 1024 #define USER_BLOCK 1024
#define SIXTY_FOUR_KB 65536
/* Temporary filter IDs used for testing */ /* Temporary filter IDs used for testing */
#define H5Z_FILTER_BOGUS 305 #define H5Z_FILTER_BOGUS 305
@ -563,6 +567,139 @@ test_compact_io(hid_t fapl)
return -1; return -1;
} }
/*-------------------------------------------------------------------------
* Function: test_max_compact
*
* Purpose: Tests compact dataset of maximal size.
*
* Return: Success: 0
*
* Failure: -1
*
* Programmer: Raymond Lu
* August 8, 2002
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static herr_t
test_max_compact(hid_t fapl)
{
hid_t file, dataset, space, plist;
hsize_t dims[1];
hsize_t compact_size;
herr_t status;
int *wbuf, *rbuf;
char filename[1024];
int i, j, n;
TESTING("compact dataset of maximal size");
/* Test compact dataset of size 64KB-64 */
/* Initialize data */
compact_size = (SIXTY_FOUR_KB-64)/sizeof(int);
wbuf = (int*)HDmalloc(sizeof(int)*compact_size);
rbuf = (int*)HDmalloc(sizeof(int)*compact_size);
n=0;
for(i=0; i<compact_size; i++)
wbuf[i] = n++;
/* Create a small data space for compact dataset */
dims[0] = compact_size;
space = H5Screate_simple(1, dims, NULL);
assert(space>=0);
/* Create a file */
h5_fixname(FILENAME[3], fapl, filename, sizeof filename);
if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0)
goto error;
/* Create property list for compact dataset creation */
plist = H5Pcreate(H5P_DATASET_CREATE);
assert(plist >= 0);
status = H5Pset_layout(plist, H5D_COMPACT);
assert(status >= 0);
/* Create and write to a compact dataset */
if((dataset = H5Dcreate(file, DSET_COMPACT_MAX_NAME, H5T_NATIVE_INT, space,
plist))<0)
goto error;
if(H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf)<0)
goto error;
/* Close file */
H5Sclose(space);
H5Pclose(plist);
H5Dclose(dataset);
H5Fclose(file);
/*
* Open the file and check data
*/
if((file=H5Fopen(filename, H5F_ACC_RDONLY, fapl))<0)
goto error;
if((dataset = H5Dopen(file, DSET_COMPACT_MAX_NAME))<0)
goto error;
if(H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf)<0)
goto error;
/* Check that the values read are the same as the values written */
for (i = 0; i < compact_size; i++) {
if (rbuf[i] != wbuf[i]) {
H5_FAILED();
printf(" Read different values than written.\n");
printf(" At index %d,%d\n", i);
goto error;
}
}
H5Dclose(dataset);
H5Fclose(file);
HDfree(wbuf);
HDfree(rbuf);
/* Test compact dataset of size 64KB */
/* Create a data space for compact dataset */
compact_size = SIXTY_FOUR_KB/sizeof(int);
dims[0] = compact_size;
space = H5Screate_simple(1, dims, NULL);
assert(space>=0);
/* Open file */
if((file=H5Fopen(filename, H5F_ACC_RDWR, fapl))<0)
goto error;
/* Create property list for compact dataset creation */
plist = H5Pcreate(H5P_DATASET_CREATE);
assert(plist >= 0);
status = H5Pset_layout(plist, H5D_COMPACT);
assert(status >= 0);
/* Create and write to a compact dataset */
H5E_BEGIN_TRY {
H5Dcreate(file, DSET_COMPACT_MAX2_NAME, H5T_NATIVE_INT, space, plist);
} H5E_END_TRY;
/* Close file */
H5Sclose(space);
H5Pclose(plist);
H5Fclose(file);
PASSED();
return 0;
error:
return -1;
}
/*------------------------------------------------------------------------- /*-------------------------------------------------------------------------
* Function: test_tconv * Function: test_tconv
@ -2675,6 +2812,7 @@ main(void)
nerrors += test_create(file)<0 ?1:0; nerrors += test_create(file)<0 ?1:0;
nerrors += test_simple_io(file, filename)<0 ?1:0; nerrors += test_simple_io(file, filename)<0 ?1:0;
nerrors += test_compact_io(fapl)<0 ?1:0; nerrors += test_compact_io(fapl)<0 ?1:0;
nerrors += test_max_compact(fapl)<0 ?1:0;
nerrors += test_tconv(file)<0 ?1:0; nerrors += test_tconv(file)<0 ?1:0;
nerrors += test_filters(file)<0 ?1:0; nerrors += test_filters(file)<0 ?1:0;
nerrors += test_onebyte_shuffle(file)<0 ?1:0; nerrors += test_onebyte_shuffle(file)<0 ?1:0;

View File

@ -430,6 +430,102 @@ static void test_vlstring_type(void)
} /* end test_vlstring_type() */ } /* end test_vlstring_type() */
/****************************************************************
**
** test_vlstrings_special(): Test VL string code for special
** string cases, nil and zero-sized.
**
****************************************************************/
static void
test_compact_vlstring(void)
{
const char *wdata[SPACE1_DIM1] = {"one", "two", "three", "four"};
const char *wdata2[SPACE1_DIM1] = {NULL, NULL, NULL, NULL};
char *rdata[SPACE1_DIM1]; /* Information read in */
hid_t fid1; /* HDF5 File IDs */
hid_t dataset; /* Dataset ID */
hid_t sid1; /* Dataspace ID */
hid_t tid1; /* Datatype ID */
hid_t plist; /* Dataset creation property list */
hsize_t dims1[] = {SPACE1_DIM1};
unsigned i; /* counting variable */
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing VL Strings in compact dataset\n"));
/* Create file */
fid1 = H5Fcreate(DATAFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fcreate");
/* Create dataspace for datasets */
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
CHECK(sid1, FAIL, "H5Screate_simple");
/* Create a datatype to refer to */
tid1 = H5Tcopy (H5T_C_S1);
CHECK(tid1, FAIL, "H5Tcopy");
ret = H5Tset_size (tid1,H5T_VARIABLE);
CHECK(ret, FAIL, "H5Tset_size");
plist = H5Pcreate(H5P_DATASET_CREATE);
CHECK(plist, FAIL, "H5Pcreate");
ret = H5Pset_layout(plist, H5D_COMPACT);
CHECK(ret, FAIL, "H5Pset_layout");
/* Create a dataset */
dataset=H5Dcreate(fid1,"Dataset5",tid1,sid1,plist);
CHECK(dataset, FAIL, "H5Dcreate");
/* Write dataset to disk */
ret=H5Dwrite(dataset,tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,wdata);
CHECK(ret, FAIL, "H5Dwrite");
/* Read dataset from disk */
ret=H5Dread(dataset,tid1,H5S_ALL,H5S_ALL,H5P_DEFAULT,rdata);
CHECK(ret, FAIL, "H5Dread");
/* Compare data read in */
for(i=0; i<SPACE1_DIM1; i++) {
if(strlen(wdata[i])!=strlen(rdata[i])) {
num_errs++;
printf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",(int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i]));
continue;
} /* end if */
if( strcmp(wdata[i],rdata[i]) != 0 ) {
num_errs++;
printf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",(int)i,wdata[i],(int)i,rdata[i]);
continue;
} /* end if */
} /* end for */
/* Reclaim the read VL data */
ret=H5Dvlen_reclaim(tid1,sid1,H5P_DEFAULT,rdata);
CHECK(ret, FAIL, "H5Dvlen_reclaim");
/* Close Dataset */
ret = H5Dclose(dataset);
CHECK(ret, FAIL, "H5Dclose");
/* Close datatype */
ret = H5Tclose(tid1);
CHECK(ret, FAIL, "H5Tclose");
/* Close disk dataspace */
ret = H5Sclose(sid1);
CHECK(ret, FAIL, "H5Sclose");
/* Close dataset create property list */
ret = H5Pclose(plist);
CHECK(ret, FAIL, "H5Pclose");
/* Close file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
} /*test_compact_vlstrings*/
/**************************************************************** /****************************************************************
** **
** test_write_vl_string_attribute(): Test basic VL string code. ** test_write_vl_string_attribute(): Test basic VL string code.
@ -605,11 +701,12 @@ test_vlstrings(void)
/* Output message about test being performed */ /* Output message about test being performed */
MESSAGE(5, ("Testing Variable-Length Strings\n")); MESSAGE(5, ("Testing Variable-Length Strings\n"));
/* These next tests use the same file */ /* These tests use the same file */
/* Test basic VL string datatype */ /* Test basic VL string datatype */
test_vlstrings_basic(); test_vlstrings_basic();
test_vlstrings_special(); test_vlstrings_special();
test_vlstring_type(); test_vlstring_type();
test_compact_vlstring();
/* Test using VL strings in attributes */ /* Test using VL strings in attributes */
test_write_vl_string_attribute(); test_write_vl_string_attribute();