[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

@@ -430,6 +430,102 @@ static void test_vlstring_type(void)
} /* 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.
@@ -605,11 +701,12 @@ test_vlstrings(void)
/* Output message about test being performed */
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_vlstrings_basic();
test_vlstrings_special();
test_vlstring_type();
test_compact_vlstring();
/* Test using VL strings in attributes */
test_write_vl_string_attribute();