summaryrefslogtreecommitdiffstats
path: root/c++/test/th5s.cpp
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2004-12-20 20:01:46 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2004-12-20 20:01:46 (GMT)
commit625e6ad9aa105bdcc50e6d42559a56582b867e37 (patch)
tree470e5d4efbd7e68f2c52535ada2c2c19d07c0af5 /c++/test/th5s.cpp
parente793077523917ba58eb138b5369ae7dc19d84ba1 (diff)
downloadhdf5-625e6ad9aa105bdcc50e6d42559a56582b867e37.zip
hdf5-625e6ad9aa105bdcc50e6d42559a56582b867e37.tar.gz
hdf5-625e6ad9aa105bdcc50e6d42559a56582b867e37.tar.bz2
[svn-r9696] Purpose: Clean up tests
Description: Replaced cout's with cerr's. Replaced macro VERIFY with template function verify_val to verify read data/info. Cleanup various places in the tests to make them more consistent. Platforms tested: SunOS 5.7 (arabica) Linux 2.4 (eirene)
Diffstat (limited to 'c++/test/th5s.cpp')
-rw-r--r--c++/test/th5s.cpp159
1 files changed, 80 insertions, 79 deletions
diff --git a/c++/test/th5s.cpp b/c++/test/th5s.cpp
index eac6703..dacd1ef 100644
--- a/c++/test/th5s.cpp
+++ b/c++/test/th5s.cpp
@@ -29,45 +29,46 @@
#include "H5Cpp.h"
#include "testhdf5.h"
+#include "h5cpputil.h"
#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif /* !H5_NO_NAMESPACE */
-#define TESTFILE "th5s.h5"
-#define DATAFILE "th5s1.h5"
+const string TESTFILE("th5s.h5");
+const string DATAFILE("th5s1.h5");
/* 3-D dataset with fixed dimensions */
-#define SPACE1_NAME "Space1"
-#define SPACE1_RANK 3
-#define SPACE1_DIM1 3
-#define SPACE1_DIM2 15
-#define SPACE1_DIM3 13
+const string SPACE1_NAME("Space1");
+const int SPACE1_RANK = 3;
+const int SPACE1_DIM1 = 3;
+const int SPACE1_DIM2 = 15;
+const int SPACE1_DIM3 = 13;
/* 4-D dataset with one unlimited dimension */
-#define SPACE2_NAME "Space2"
-#define SPACE2_RANK 4
-#define SPACE2_DIM1 0
-#define SPACE2_DIM2 15
-#define SPACE2_DIM3 13
-#define SPACE2_DIM4 23
-#define SPACE2_MAX1 H5S_UNLIMITED
-#define SPACE2_MAX2 15
-#define SPACE2_MAX3 13
-#define SPACE2_MAX4 23
+const string SPACE2_NAME("Space2");
+const int SPACE2_RANK = 4;
+const int SPACE2_DIM1 = 0;
+const int SPACE2_DIM2 = 15;
+const int SPACE2_DIM3 = 13;
+const int SPACE2_DIM4 = 23;
+const hsize_t SPACE2_MAX1 = H5S_UNLIMITED;
+const hsize_t SPACE2_MAX2 = 15;
+const hsize_t SPACE2_MAX3 = 13;
+const hsize_t SPACE2_MAX4 = 23;
/* Scalar dataset with simple datatype */
-#define SPACE3_NAME "Scalar1"
-#define SPACE3_RANK 0
+const string SPACE3_NAME("Scalar1");
+const int SPACE3_RANK = 0;
unsigned space3_data=65;
/* Scalar dataset with compound datatype */
-#define SPACE4_NAME "Scalar2"
-#define SPACE4_RANK 0
-#define SPACE4_FIELDNAME1 "c1"
-#define SPACE4_FIELDNAME2 "u"
-#define SPACE4_FIELDNAME3 "f"
-#define SPACE4_FIELDNAME4 "c2"
+const string SPACE4_NAME("Scalar2");
+const int SPACE4_RANK = 0;
+const string SPACE4_FIELDNAME1("c1");
+const string SPACE4_FIELDNAME2("u");
+const string SPACE4_FIELDNAME3("f");
+const string SPACE4_FIELDNAME4("c2");
size_t space4_field1_off=0;
size_t space4_field2_off=0;
size_t space4_field3_off=0;
@@ -120,20 +121,20 @@ test_h5s_basic(void)
// Get simple extent npoints of the dataspace sid1 and verify it
hssize_t n; /* Number of dataspace elements */
n = sid1.getSimpleExtentNpoints();
- VERIFY(n, SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3,
- "H5Sget_simple_extent_npoints");
+ verify_val(n, SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3,
+ "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
// Get the logical rank of dataspace sid1 and verify it
int rank; /* Logical rank of dataspace */
rank = sid1.getSimpleExtentNdims();
- VERIFY(rank, SPACE1_RANK, "H5Sget_simple_extent_ndims");
+ verify_val(rank, SPACE1_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__);
// 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(HDmemcmp(tdims, dims1, SPACE1_RANK * sizeof(unsigned)), 0,
- "H5Sget_simple_extent_dims");
+ verify_val(HDmemcmp(tdims, dims1, SPACE1_RANK * sizeof(unsigned)), 0,
+ "DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
// Create simple dataspace sid2
hsize_t max2[] = {SPACE2_MAX1, SPACE2_MAX2, SPACE2_MAX3, SPACE2_MAX4};
@@ -141,24 +142,24 @@ test_h5s_basic(void)
// Get simple extent npoints of dataspace sid2 and verify it
n = sid2.getSimpleExtentNpoints();
- VERIFY(n, SPACE2_DIM1 * SPACE2_DIM2 * SPACE2_DIM3 * SPACE2_DIM4,
- "H5Sget_simple_extent_npoints");
+ verify_val(n, SPACE2_DIM1 * SPACE2_DIM2 * SPACE2_DIM3 * SPACE2_DIM4,
+ "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
// Get the logical rank of dataspace sid2 and verify it
rank = sid2.getSimpleExtentNdims();
- VERIFY(rank, SPACE2_RANK, "H5Sget_simple_extent_ndims");
+ verify_val(rank, SPACE2_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__);
// Retrieves dimension size and max size of dataspace sid2 and
// verify them
ndims = sid2.getSimpleExtentDims( tdims, tmax );
- VERIFY(HDmemcmp(tdims, dims2, SPACE2_RANK * sizeof(unsigned)), 0,
- "H5Sget_simple_extent_dims");
- VERIFY(HDmemcmp(tmax, max2, SPACE2_RANK * sizeof(unsigned)), 0,
- "H5Sget_simple_extent_dims");
+ verify_val(HDmemcmp(tdims, dims2, SPACE2_RANK * sizeof(unsigned)), 0,
+ "DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
+ verify_val(HDmemcmp(tmax, max2, SPACE2_RANK * sizeof(unsigned)), 0,
+ "DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
} // end of first try block
catch( DataSpaceIException error )
{
- CHECK(FAIL, FAIL, error.getCFuncName());
+ issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__);
}
/*
@@ -168,10 +169,8 @@ test_h5s_basic(void)
try {
DataSpace manydims_ds(H5S_MAX_RANK+1, dims3, NULL);
- // Should FAIL but didn't - BMR (Note 1): a new macro that skips
- // the comparison b/w the 1st & 2nd args would be more appropriate,
- // but VERIFY will still do - Mar 12, 01
- VERIFY(manydims_ds.getId(), FAIL, "DataSpace constructor");
+ // Should FAIL but didn't, so issue an error message
+ issue_fail_msg("DataSpace constructor", __LINE__, __FILE__);
}
catch( DataSpaceIException error ) {} // do nothing, FAIL expected
@@ -184,11 +183,11 @@ test_h5s_basic(void)
*/
char testfile[512]="";
char *srcdir = getenv("srcdir");
- if (srcdir && ((strlen(srcdir) + strlen(TESTFILE) + 1) < sizeof(testfile))){
+ if (srcdir && ((strlen(srcdir) + strlen(TESTFILE.c_str()) + 1) < sizeof(testfile))){
strcpy(testfile, srcdir);
strcat(testfile, "/");
}
- strcat(testfile, TESTFILE);
+ strcat(testfile, TESTFILE.c_str());
try { // try block for testing higher dimensionality
// Create file
@@ -198,15 +197,17 @@ test_h5s_basic(void)
// what the library can handle and this operation should fail.
try {
DataSet dset1 = fid1.openDataSet( "dset" );
- VERIFY( dset1.getId(), FAIL, "H5File::openDataSet");
+
+ // but didn't, issue an error message
+ issue_fail_msg("H5File::openDataSet", __LINE__, __FILE__);
}
catch( FileIException error ) { } // do nothing, FAIL expected
} // end of try block for testing higher dimensionality
// catch exception thrown by H5File constructor
catch( FileIException error ) {
- CHECK_I(FAIL, error.getCFuncName());
- cout << "***cannot open the pre-created H5S_MAX_RANK test file" <<
+ issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__);
+ cerr << "***cannot open the pre-created H5S_MAX_RANK test file" <<
testfile << endl;
}
@@ -217,7 +218,7 @@ test_h5s_basic(void)
dims1[0] = 0;
try {
DataSpace wrongdim_ds (SPACE1_RANK, dims1);
- VERIFY(wrongdim_ds.getId(), FAIL, "DataSpace constructor");
+ verify_val(wrongdim_ds.getId(), FAIL, "DataSpace constructor", __LINE__, __FILE__);
}
catch( DataSpaceIException error ) {} // do nothing; FAIL expected
@@ -225,13 +226,13 @@ test_h5s_basic(void)
DataSpace sid3 (H5S_SIMPLE);
// Attempts to use incorrect dimensions, should fail
- try { sid3.setExtentSimple( SPACE1_RANK, dims1 ); }
- catch( DataSpaceIException error )
- {
- // ret value is already < 0 for an exception to be thrown;
- // also see Note 1 above
- VERIFY(FAIL, FAIL, error.getCFuncName());
+ try {
+ sid3.setExtentSimple( SPACE1_RANK, dims1 );
+
+ // but didn't, issue an error message
+ issue_fail_msg("DataSpace::setExtentSimple", __LINE__, __FILE__);
}
+ catch (DataSpaceIException error) {} // do nothing, FAIL expected
} /* test_h5s_basic() */
/*-------------------------------------------------------------------------
@@ -266,22 +267,22 @@ test_h5s_scalar_write(void)
//n = H5Sget_simple_extent_npoints(sid1);
hssize_t n; /* Number of dataspace elements */
n = sid1.getSimpleExtentNpoints();
- VERIFY(n, 1, "DataSpace::getSimpleExtentNpoints");
+ verify_val(n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
int rank; /* Logical rank of dataspace */
rank = sid1.getSimpleExtentNdims();
- VERIFY(rank, SPACE3_RANK, "DataSpace::getSimpleExtentNdims");
+ verify_val(rank, SPACE3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__);
// 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, "DataSpace::getSimpleExtentDims");
+ verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
/* Verify extent type */
H5S_class_t ext_type; /* Extent type */
ext_type = sid1.getSimpleExtentType();
- VERIFY(ext_type, H5S_SCALAR, "DataSpace::getSimpleExtentType");
+ verify_val(ext_type, H5S_SCALAR, "DataSpace::getSimpleExtentType", __LINE__, __FILE__);
/* Create a dataset */
DataSet dataset = fid1.createDataSet("Dataset1", PredType::NATIVE_UINT,sid1);
@@ -290,7 +291,7 @@ test_h5s_scalar_write(void)
} // end of try block
catch (Exception error)
{
- CHECK(FAIL, FAIL, error.getCFuncName());
+ issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__);
}
} /* test_h5s_scalar_write() */
@@ -328,23 +329,23 @@ test_h5s_scalar_read(void)
// Get the number of dataspace elements
hssize_t n = sid1.getSimpleExtentNpoints();
- VERIFY(n, 1, "H5Sget_simple_extent_npoints");
+ verify_val(n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
// Get the logical rank of the dataspace
int ndims = sid1.getSimpleExtentNdims();
- VERIFY(ndims, SPACE3_RANK, "H5Sget_simple_extent_ndims");
+ verify_val(ndims, SPACE3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__);
ndims = sid1.getSimpleExtentDims(tdims);
- VERIFY(ndims, 0, "H5Sget_simple_extent_dims");
+ verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
unsigned rdata; /* Scalar data read in */
dataset.read(&rdata, PredType::NATIVE_UINT);
- VERIFY(rdata, space3_data, "H5Dread");
+ verify_val(rdata, space3_data, "DataSet::read", __LINE__, __FILE__);
} // end of try block
catch (Exception error)
{
// all the exceptions caused by negative returned values by C APIs
- CHECK(FAIL, FAIL, error.getCFuncName());
+ issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__);
}
} /* test_h5s_scalar_read() */
@@ -381,7 +382,7 @@ test_h5s_null(void)
//n = H5Sget_simple_extent_npoints(sid1);
hssize_t n; /* Number of dataspace elements */
n = sid1.getSimpleExtentNpoints();
- VERIFY(n, 0, "DataSpace::getSimpleExtentNpoints");
+ verify_val(n, 0, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
// Create a dataset
DataSet dataset = fid1.createDataSet("Dataset1", PredType::NATIVE_UINT,sid1);
@@ -391,11 +392,11 @@ test_h5s_null(void)
// Read the data. Make sure no change to the buffer
dataset.read(&space5_data, PredType::NATIVE_INT);
- VERIFY(space5_data, 7, "H5Dread");
+ verify_val(space5_data, 7, "DataSet::read", __LINE__, __FILE__);
} // end of try block
catch (Exception error)
{
- CHECK(FAIL, FAIL, error.getCFuncName());
+ issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__);
}
} /* test_h5s_null() */
@@ -446,15 +447,15 @@ test_h5s_compound_scalar_write(void)
// Get the number of dataspace elements
hssize_t n = sid1.getSimpleExtentNpoints();
- VERIFY(n, 1, "H5Sget_simple_extent_npoints");
+ verify_val(n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
// Get the logical rank of the dataspace
int ndims = sid1.getSimpleExtentNdims();
- VERIFY(ndims, SPACE3_RANK, "H5Sget_simple_extent_ndims");
+ verify_val(ndims, SPACE3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__);
hsize_t tdims[4]; /* Dimension array to test with */
ndims = sid1.getSimpleExtentDims(tdims);
- VERIFY(ndims, 0, "H5Sget_simple_extent_dims");
+ verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
/* Create a dataset */
DataSet dataset = fid1.createDataSet("Dataset1", tid1, sid1);
@@ -464,7 +465,7 @@ test_h5s_compound_scalar_write(void)
catch (Exception error)
{
// all the exceptions caused by negative returned values by C APIs
- CHECK(FAIL, FAIL, error.getCFuncName());
+ issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__);
}
} /* test_h5s_compound_scalar_write() */
@@ -503,14 +504,14 @@ test_h5s_compound_scalar_read(void)
// Get the number of dataspace elements
hssize_t n = sid1.getSimpleExtentNpoints();
- VERIFY(n, 1, "H5Sget_simple_extent_npoints");
+ verify_val(n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__);
// Get the logical rank of the dataspace
int ndims = sid1.getSimpleExtentNdims();
- VERIFY(ndims, SPACE3_RANK, "H5Sget_simple_extent_ndims");
+ verify_val(ndims, SPACE3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__);
ndims = sid1.getSimpleExtentDims(tdims);
- VERIFY(ndims, 0, "H5Sget_simple_extent_dims");
+ verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__);
// Get the datatype of this dataset.
CompType type(dataset);
@@ -521,11 +522,11 @@ test_h5s_compound_scalar_read(void)
// Verify read data
if(HDmemcmp(&space4_data,&rdata,sizeof(struct space4_struct)))
{
- cout << "scalar data different: space4_data.c1="
+ cerr << "scalar data different: space4_data.c1="
<< space4_data.c1 << ", read_data4.c1=" << rdata.c1 << endl;
- cout << "scalar data different: space4_data.u="
+ cerr << "scalar data different: space4_data.u="
<< space4_data.u << ", read_data4.u=" << rdata.u << endl;
- cout << "scalar data different: space4_data.f="
+ cerr << "scalar data different: space4_data.f="
<< space4_data.f << ", read_data4.f=" << rdata.f << endl;
TestErrPrintf("scalar data different: space4_data.c1=%c, read_data4.c1=%c\n",
space4_data.c1, rdata.c2);
@@ -534,7 +535,7 @@ test_h5s_compound_scalar_read(void)
catch (Exception error)
{
// all the exceptions caused by negative returned values by C APIs
- CHECK(FAIL, FAIL, error.getCFuncName());
+ issue_fail_msg(error.getCFuncName(), __LINE__, __FILE__);
}
} /* test_h5s_compound_scalar_read() */
@@ -584,6 +585,6 @@ test_h5s(void)
void
cleanup_h5s(void)
{
- remove(DATAFILE);
+ remove(DATAFILE.c_str());
}