Esempio n. 1
0
/*-------------------------------------------------------------------------
 * Function:	test_compact_vlstring
 *
 * Purpose:	Test storing VL strings in compact datasets.
 *
 * Return:	None
 *
 * Programmer:	Binh-Minh Ribler (use C version)
 *		January, 2007
 *
 *-------------------------------------------------------------------------
 */
static void test_compact_vlstring()
{
    // Output message about test being performed
    SUBTEST("VL Strings on Compact Dataset");

    try {
	// Create file
	H5File file1(FILENAME, H5F_ACC_TRUNC);

	// Create dataspace for datasets
        hsize_t dims1[] = {SPACE1_DIM1};
        DataSpace sid1(SPACE1_RANK, dims1);

	// Create a datatype to refer to
	StrType vlst(0, H5T_VARIABLE);

	// Create dataset create property list and set layout
	DSetCreatPropList plist;
	plist.setLayout(H5D_COMPACT);

	// Create a dataset
	DataSet dataset(file1.createDataSet("Dataset5", vlst, sid1, plist));

	// Write dataset to disk
	const char *wdata[SPACE1_DIM1] = {"one", "two", "three", "four"};
	dataset.write(wdata, vlst);

	// Read dataset from disk
	char *rdata[SPACE1_DIM1];   // Information read in
	dataset.read(rdata, vlst);

	// Compare data read in
	hsize_t i;
	for (i=0; i<SPACE1_DIM1; i++) {
	    if (HDstrlen(wdata[i])!=strlen(rdata[i])) {
		TestErrPrintf("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 (HDstrcmp(wdata[i],rdata[i]) != 0) {
		TestErrPrintf("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
	DataSet::vlenReclaim((void *)rdata, vlst, sid1);

	// Close objects and file
	dataset.close();
	vlst.close();
	sid1.close();
	plist.close();
	file1.close();

	PASSED();
    } // end try

    // Catch all exceptions.
    catch (Exception E)
    {
        issue_fail_msg("test_compact_vlstrings()", __LINE__, __FILE__, E.getCDetailMsg());
    }
}   // test_compact_vlstrings