summaryrefslogtreecommitdiffstats
path: root/c++
diff options
context:
space:
mode:
Diffstat (limited to 'c++')
-rw-r--r--c++/test/dsets.cpp80
-rw-r--r--c++/test/th5s.cpp183
2 files changed, 158 insertions, 105 deletions
diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp
index d22cc77..c48cd7e 100644
--- a/c++/test/dsets.cpp
+++ b/c++/test/dsets.cpp
@@ -798,8 +798,29 @@ test_types(H5File& file)
unsigned char buf[32];
hsize_t nelmts = sizeof(buf);
DataType type;
- try { // block 1
+ try { // block of bitfield_1
+ // test copying a predefined type
type.copy (PredType::STD_B8LE);
+
+ // Test copying a user-defined type using DataType::copy
+ DataType copied_type;
+ copied_type.copy(type);
+ // Test copying a user-defined type using DataType::operator=
+ DataType another_copied_type;
+ another_copied_type = type;
+
+ // Test copying a user-defined int type using DataType::operator=
+ IntType orig_int(PredType::STD_B8LE);
+ DataType generic_type;
+ generic_type = orig_int;
+
+ // Test copying an integer predefined type
+ IntType new_int_type(PredType::STD_B8LE);
+
+ // Test copying an int predefined type using DataType::operator=
+ IntType another_int_type;
+ another_int_type = new_int_type;
+
DataSpace space (1, &nelmts);
DataSet* dset = new DataSet(grp.createDataSet("bitfield_1", type, space));
@@ -820,12 +841,15 @@ test_types(H5File& file)
} // end try block of bitfield_1
// catch exceptions thrown in try block of bitfield_1
- catch (Exception E) { goto error; }
+ catch (Exception E) {
+ cout << "Failure in " << E.getFuncName() << " - "
+ << E.getDetailMsg() << endl;
+ goto error;
+ }
/* bitfield_2 */
nelmts = sizeof(buf)/2;
try { // bitfield_2 block
-
type.copy (PredType::STD_B16LE);
DataSpace space (1, &nelmts);
DataSet* dset = new DataSet(grp.createDataSet("bitfield_2", type, space));
@@ -839,6 +863,8 @@ test_types(H5File& file)
try { dset->write (buf, type); }
catch(DataSetIException E)
{
+ cout << "Failure in " << E.getFuncName() << " - "
+ << E.getDetailMsg() << endl;
delete dset;
goto error;
}
@@ -846,7 +872,11 @@ test_types(H5File& file)
} // end try block of bitfield_2
// catch exceptions thrown in try block of bitfield_2
- catch (Exception E) { goto error; }
+ catch (Exception E) {
+ cout << "Failure in " << E.getFuncName() << " - "
+ << E.getDetailMsg() << endl;
+ goto error;
+ }
/* opaque_1 */
DataType* optype = new DataType(H5T_OPAQUE, 1);
@@ -873,8 +903,17 @@ test_types(H5File& file)
} // end try block of opaque_1
// catch exceptions thrown in try block of opaque_1
- catch (DataSetIException E) { delete optype; goto error; }
- catch (Exception E) { goto error; }
+ catch (DataSetIException E) {
+ delete optype;
+ cout << "Failure in " << E.getFuncName() << " - "
+ << E.getDetailMsg() << endl;
+ goto error;
+ }
+ catch (Exception E) {
+ cout << "Failure in " << E.getFuncName() << " - "
+ << E.getDetailMsg() << endl;
+ goto error;
+ }
/* opaque_2 */
try { // block opaque_2
@@ -899,13 +938,27 @@ test_types(H5File& file)
delete dset;
delete optype;
} //end try block of opaque_2
- catch (DataSetIException E) { delete optype; goto error; }
- catch (Exception E) { goto error; }
+ catch (DataSetIException E) {
+ delete optype;
+ cout << "Failure in " << E.getFuncName() << " - "
+ << E.getDetailMsg() << endl;
+ goto error;
+ }
+ catch (Exception E) {
+ cout << "Failure in " << E.getFuncName() << " - "
+ << E.getDetailMsg() << endl;
+ goto error;
+ }
PASSED();
return 0;
} // end top try block
- catch (Exception E) { goto error; } // Group and DataType exceptions
+
+ catch (Exception E) { // Group and DataType exceptions
+ cout << "Failure in " << E.getFuncName() << " - "
+ << E.getDetailMsg() << endl;
+ goto error;
+ }
error:
return -1;
@@ -966,15 +1019,20 @@ int test_report( int nerrors )
*
*-------------------------------------------------------------------------
*/
+static hid_t tempid = H5T_STD_B8LE;
+// the following statement caused seg. fault, need to check into - BMR
+//static PredType temp = PredType::STD_B8LE;
+// because PredType::STD_B8LE was not defined yet, so ref_counter is nil
+// and it'll fail when the ref_counter is being incremented
+// this can be a problem; must check ref_counter before increment or decrement
+
int
main(void)
{
-
h5_reset(); // in h5test.c, resets the library by closing it
hid_t fapl_id;
fapl_id = h5_fileaccess(); // in h5test.c, returns a file access template
- // should create an object from this id - BMR
#if 0
/* BMR: leave paralell stuff out! */
diff --git a/c++/test/th5s.cpp b/c++/test/th5s.cpp
index 268d264..065b51a 100644
--- a/c++/test/th5s.cpp
+++ b/c++/test/th5s.cpp
@@ -65,11 +65,20 @@ struct space4_struct {
char c2;
} space4_data={'v',987123,-3.14,'g'}; /* Test data for 4th dataspace */
-/****************************************************************
-**
-** test_h5s_basic(): Test basic H5S (dataspace) code.
-**
-****************************************************************/
+/*-------------------------------------------------------------------------
+ *
+ * Function: test_h5s_basic
+ *
+ * Purpose: Test basic H5S (dataspace) code
+ *
+ * Return: none
+ *
+ * Programmer: Binh-Minh Ribler (using C version)
+ * Mar 2001
+ *
+ * Modifications:
+ *-------------------------------------------------------------------------
+ */
static void
test_h5s_basic(void)
{
@@ -156,7 +165,6 @@ test_h5s_basic(void)
* If this test fails and the H5S_MAX_RANK variable has changed, follow
* the instructions in space_overflow.c for regenating the th5s.h5 file.
*/
- //{
char testfile[512]="";
char *srcdir = getenv("srcdir");
if (srcdir && ((strlen(srcdir) + strlen(TESTFILE) + 1) < sizeof(testfile))){
@@ -186,7 +194,7 @@ test_h5s_basic(void)
}
// CHECK_I(ret, "H5Fclose"); // leave this here, later, fake a failure
- // in the p_close see how this will handle it. ???
+ // in the p_close see how this will handle it. - BMR
/* Verify that incorrect dimensions don't work */
dims1[0] = 0;
@@ -209,11 +217,20 @@ test_h5s_basic(void)
}
} /* test_h5s_basic() */
-/****************************************************************
-**
-** test_h5s_scalar_write(): Test scalar H5S (dataspace) writing code.
-**
-****************************************************************/
+/*-------------------------------------------------------------------------
+ *
+ * Function: test_h5s_scalar_write
+ *
+ * Purpose: Test scalar H5S (dataspace) writing code
+ *
+ * Return: none
+ *
+ * Programmer: Binh-Minh Ribler (using C version)
+ * Mar 2001
+ *
+ * Modifications:
+ *-------------------------------------------------------------------------
+ */
static void
test_h5s_scalar_write(void)
{
@@ -225,39 +242,26 @@ test_h5s_scalar_write(void)
{
// Create file
H5File fid1(FILE, H5F_ACC_TRUNC);
- // CHECK(fid1, FAIL, "H5Fcreate");
/* Create scalar dataspace */
- //sid1 = H5Screate_simple(SPACE3_RANK, NULL, NULL);
DataSpace sid1(SPACE3_RANK, NULL);
//n = H5Sget_simple_extent_npoints(sid1);
hssize_t n; /* Number of dataspace elements */
n = sid1.getSimpleExtentNpoints();
VERIFY(n, 1, "DataSpace::getSimpleExtentNpoints");
- //VERIFY(n, 1, "H5Sget_simple_extent_npoints");
int rank; /* Logical rank of dataspace */
rank = sid1.getSimpleExtentNdims();
- //VERIFY(rank, SPACE3_RANK, "H5Sget_simple_extent_ndims");
VERIFY(rank, SPACE3_RANK, "DataSpace::getSimpleExtentNdims");
// Retrieves dimension size of dataspace sid1 and verify it
int ndims; /* Number of dimensions */
hsize_t tdims[4]; /* Dimension array to test with */
ndims = sid1.getSimpleExtentDims( tdims );
- //VERIFY(ndims, 0, "H5Sget_simple_extent_dims");
VERIFY(ndims, 0, "DataSpace::getSimpleExtentDims");
- // rank = H5Sget_simple_extent_ndims(sid1);
- //VERIFY(rank, SPACE3_RANK, "H5Sget_simple_extent_ndims");
-
- // ret = H5Sget_simple_extent_dims(sid1, tdims, NULL);
- // VERIFY(ret, 0, "H5Sget_simple_extent_dims");
-
/* Verify extent type */
- //ext_type = H5Sget_simple_extent_type(sid1);
- //VERIFY(ext_type, H5S_SCALAR, "H5Sget_simple_extent_type");
H5S_class_t ext_type; /* Extent type */
ext_type = sid1.getSimpleExtentType();
VERIFY(ext_type, H5S_SCALAR, "DataSpace::getSimpleExtentType");
@@ -273,11 +277,20 @@ test_h5s_scalar_write(void)
}
} /* test_h5s_scalar_write() */
-/****************************************************************
-**
-** test_h5s_scalar_read(): Test scalar H5S (dataspace) reading code.
-**
-****************************************************************/
+/*-------------------------------------------------------------------------
+ *
+ * Function: test_h5s_scalar_read
+ *
+ * Purpose: Test scalar H5S (dataspace) reading code
+ *
+ * Return: none
+ *
+ * Programmer: Binh-Minh Ribler (using C version)
+ * Mar 2001
+ *
+ * Modifications:
+ *-------------------------------------------------------------------------
+ */
static void
test_h5s_scalar_read(void)
{
@@ -290,33 +303,25 @@ test_h5s_scalar_read(void)
{
/* Create file */
H5File fid1(FILE, H5F_ACC_RDWR);
- //CHECK(fid1, FAIL, "H5Fopen");
/* Create a dataset */
DataSet dataset = fid1.openDataSet("Dataset1");
- //CHECK(dataset, FAIL, "H5Dopen");
DataSpace sid1 = dataset.getSpace();
- //CHECK(sid1, FAIL, "H5Dget_space");
// Get the number of dataspace elements
hssize_t n = sid1.getSimpleExtentNpoints();
- //hssize_t n = H5Sget_simple_extent_npoints(sid1);
- //CHECK(n, UFAIL, "H5Sget_simple_extent_npoints");
VERIFY(n, 1, "H5Sget_simple_extent_npoints");
// Get the logical rank of the dataspace
int ndims = sid1.getSimpleExtentNdims();
- //CHECK(rank, UFAIL, "H5Sget_simple_extent_ndims");
VERIFY(ndims, SPACE3_RANK, "H5Sget_simple_extent_ndims");
ndims = sid1.getSimpleExtentDims(tdims);
- //ret = H5Sget_simple_extent_dims(sid1, tdims, NULL);
VERIFY(ndims, 0, "H5Sget_simple_extent_dims");
unsigned rdata; /* Scalar data read in */
dataset.read(&rdata, PredType::NATIVE_UINT);
- //CHECK(ret, FAIL, "H5Dread");
VERIFY(rdata, space3_data, "H5Dread");
} // end of try block
catch (Exception error)
@@ -327,12 +332,21 @@ test_h5s_scalar_read(void)
} /* test_h5s_scalar_read() */
-/****************************************************************
-**
-** test_h5s_compound_scalar_write(): Test scalar H5S (dataspace) writing for
-** compound datatypes.
-**
-****************************************************************/
+/*-------------------------------------------------------------------------
+ *
+ * Function: test_h5s_compound_scalar_write
+ *
+ * Purpose: Test scalar H5S (dataspace) writing for compound
+ * datatypes
+ *
+ * Return: none
+ *
+ * Programmer: Binh-Minh Ribler (using C version)
+ * Mar 2001
+ *
+ * Modifications:
+ *-------------------------------------------------------------------------
+ */
static void
test_h5s_compound_scalar_write(void)
{
@@ -343,64 +357,42 @@ test_h5s_compound_scalar_write(void)
try
{
/* Create file */
- //fid1 = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
H5File fid1(FILE, H5F_ACC_TRUNC);
- //CHECK(fid1, FAIL, "H5Fcreate");
/* Create the compound datatype. */
CompType tid1(sizeof(struct space4_struct));
- //tid1 = H5Tcreate (H5T_COMPOUND, sizeof(struct space4_struct));
- //CHECK(tid1, FAIL, "H5Tcreate");
space4_field1_off=HOFFSET(struct space4_struct, c1);
- //ret = H5Tinsert(tid1, SPACE4_FIELDNAME1, space4_field1_off,
- //H5T_NATIVE_SCHAR);
tid1.insertMember(SPACE4_FIELDNAME1, space4_field1_off,
PredType::NATIVE_SCHAR);
- //CHECK(ret, FAIL, "H5Tinsert");
space4_field2_off=HOFFSET(struct space4_struct, u);
- //ret = H5Tinsert(tid1, SPACE4_FIELDNAME2, space4_field2_off,
- // H5T_NATIVE_UINT);
tid1.insertMember(SPACE4_FIELDNAME2, space4_field2_off,
PredType::NATIVE_UINT);
- //CHECK(ret, FAIL, "H5Tinsert");
space4_field3_off=HOFFSET(struct space4_struct, f);
tid1.insertMember(SPACE4_FIELDNAME3, space4_field3_off,
PredType::NATIVE_FLOAT);
- //CHECK(ret, FAIL, "H5Tinsert");
space4_field4_off=HOFFSET(struct space4_struct, c2);
tid1.insertMember(SPACE4_FIELDNAME4, space4_field4_off,
PredType::NATIVE_SCHAR);
- //CHECK(ret, FAIL, "H5Tinsert");
/* Create scalar dataspace */
DataSpace sid1(SPACE3_RANK, NULL);
- //sid1 = H5Screate_simple(SPACE3_RANK, NULL, NULL);
- //CHECK(sid1, FAIL, "H5Screate_simple");
// Get the number of dataspace elements
hssize_t n = sid1.getSimpleExtentNpoints();
- //hssize_t n = H5Sget_simple_extent_npoints(sid1);
- //CHECK(n, UFAIL, "H5Sget_simple_extent_npoints");
VERIFY(n, 1, "H5Sget_simple_extent_npoints");
// Get the logical rank of the dataspace
int ndims = sid1.getSimpleExtentNdims();
- //CHECK(rank, UFAIL, "H5Sget_simple_extent_ndims");
VERIFY(ndims, SPACE3_RANK, "H5Sget_simple_extent_ndims");
hsize_t tdims[4]; /* Dimension array to test with */
ndims = sid1.getSimpleExtentDims(tdims);
- //ret = H5Sget_simple_extent_dims(sid1, tdims, NULL);
VERIFY(ndims, 0, "H5Sget_simple_extent_dims");
/* Create a dataset */
DataSet dataset = fid1.createDataSet("Dataset1", tid1, sid1);
- //dataset=H5Dcreate(fid1,"Dataset1",tid1,sid1,H5P_DEFAULT);
- //CHECK(dataset, FAIL, "H5Dcreate");
dataset.write(&space4_data, tid1);
- //ret = H5Dwrite(dataset, tid1, H5S_ALL, H5S_ALL, H5P_DEFAULT, &space4_data);
- //CHECK(ret, FAIL, "H5Dwrite");
} // end of try block
catch (Exception error)
{
@@ -410,12 +402,21 @@ test_h5s_compound_scalar_write(void)
} /* test_h5s_compound_scalar_write() */
-/****************************************************************
-**
-** test_h5s_compound_scalar_read(): Test scalar H5S (dataspace) reading for
-** compound datatypes.
-**
-****************************************************************/
+/*-------------------------------------------------------------------------
+ *
+ * Function: test_h5s_compound_scalar_read
+ *
+ * Purpose: Test scalar H5S (dataspace) reading for compound
+ * datatypes
+ *
+ * Return: none
+ *
+ * Programmer: Binh-Minh Ribler (using C version)
+ * Mar 2001
+ *
+ * Modifications:
+ *-------------------------------------------------------------------------
+ */
static void
test_h5s_compound_scalar_read(void)
{
@@ -434,56 +435,41 @@ test_h5s_compound_scalar_read(void)
{
/* Create file */
H5File fid1(FILE, H5F_ACC_RDWR);
- //CHECK(fid1, FAIL, "H5Fopen");
/* Create a dataset */
DataSet dataset = fid1.openDataSet("Dataset1");
- //CHECK(dataset, FAIL, "H5Dopen");
DataSpace sid1 = dataset.getSpace();
- //CHECK(sid1, FAIL, "H5Dget_space");
// Get the number of dataspace elements
hssize_t n = sid1.getSimpleExtentNpoints();
- //hssize_t n = H5Sget_simple_extent_npoints(sid1);
- //CHECK(n, UFAIL, "H5Sget_simple_extent_npoints");
VERIFY(n, 1, "H5Sget_simple_extent_npoints");
// Get the logical rank of the dataspace
int ndims = sid1.getSimpleExtentNdims();
- //CHECK(rank, UFAIL, "H5Sget_simple_extent_ndims");
VERIFY(ndims, SPACE3_RANK, "H5Sget_simple_extent_ndims");
ndims = sid1.getSimpleExtentDims(tdims);
- //ret = H5Sget_simple_extent_dims(sid1, tdims, NULL);
VERIFY(ndims, 0, "H5Sget_simple_extent_dims");
// Get the datatype of this dataset.
CompType type(dataset);
- //type=H5Dget_type(dataset);
- //CHECK(type, FAIL, "H5Dget_type");
- struct space4_struct rdata; /* Scalar data read in */
+ struct space4_struct rdata; /* Scalar data read in */
dataset.read(&rdata, type);
- //CHECK(ret, FAIL, "H5Dread");
- //ret = H5Dread(dataset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata);
// Verify read data
if(HDmemcmp(&space4_data,&rdata,sizeof(struct space4_struct)))
{
cout << "scalar data different: space4_data.c1="
<< space4_data.c1 << ", read_data4.c1=" << rdata.c1 << endl;
- //printf("scalar data different: space4_data.c1=%c, read_data4.c1=%c\n",space4_data.c1,rdata.c1);
cout << "scalar data different: space4_data.u="
<< space4_data.u << ", read_data4.u=" << rdata.u << endl;
- //printf("scalar data different: space4_data.u=%u, read_data4.u=%u\n",space4_data.u,rdata.u);
cout << "scalar data different: space4_data.f="
<< space4_data.f << ", read_data4.f=" << rdata.f << endl;
- //printf("scalar data different: space4_data.f=%f, read_data4.f=%f\n",space4_data.f,rdata.f);
cout << "scalar data different: space4_data.c1="
<< space4_data.c1 << ", read_data4.c1=" << rdata.c2 << endl;
- //printf("scalar data different: space4_data.c1=%c, read_data4.c1=%c\n",space4_data.c1,rdata.c2);
- num_errs++;
+ num_errs++;
} /* end if */
} // end of try block
catch (Exception error)
@@ -493,11 +479,20 @@ test_h5s_compound_scalar_read(void)
}
} /* test_h5s_compound_scalar_read() */
-/****************************************************************
-**
-** test_h5s(): Main H5S (dataspace) testing routine.
-**
-****************************************************************/
+/*-------------------------------------------------------------------------
+ *
+ * Function: test_h5s
+ *
+ * Purpose: Main H5S (dataspace) testing routine
+ *
+ * Return: none
+ *
+ * Programmer: Binh-Minh Ribler (using C version)
+ * Mar 2001
+ *
+ * Modifications:
+ *-------------------------------------------------------------------------
+ */
void
test_h5s(void)
{