diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2007-03-17 16:26:53 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2007-03-17 16:26:53 (GMT) |
commit | 1c4e6d163f781003ce1151781b3d403dc9b52e66 (patch) | |
tree | b07834021d14510d51e90736877fd938c1a9d904 /c++ | |
parent | c4bbce8be19cd60e7ffd0180194c0e0e92091381 (diff) | |
download | hdf5-1c4e6d163f781003ce1151781b3d403dc9b52e66.zip hdf5-1c4e6d163f781003ce1151781b3d403dc9b52e66.tar.gz hdf5-1c4e6d163f781003ce1151781b3d403dc9b52e66.tar.bz2 |
[svn-r13524] Purpose: Cleanup tests
Description:
Added extern "C" to cleanup functions as well, forgot last time.
Cleaned up/Added comments to some of the newly added tests.
Platforms tested
AIX 5.1 (copper)
Linux 2.6 (kagiso)
SunOS 5.8 64-bit (sol)
Diffstat (limited to 'c++')
-rw-r--r-- | c++/test/dsets.cpp | 13 | ||||
-rw-r--r-- | c++/test/h5cpputil.cpp | 24 | ||||
-rw-r--r-- | c++/test/h5cpputil.h | 30 | ||||
-rw-r--r-- | c++/test/tattr.cpp | 155 | ||||
-rw-r--r-- | c++/test/tcompound.cpp | 87 | ||||
-rw-r--r-- | c++/test/tfile.cpp | 54 | ||||
-rw-r--r-- | c++/test/tfilter.cpp | 27 | ||||
-rw-r--r-- | c++/test/th5s.cpp | 95 | ||||
-rw-r--r-- | c++/test/trefer.cpp | 19 | ||||
-rw-r--r-- | c++/test/ttypes.cpp | 419 | ||||
-rw-r--r-- | c++/test/tvlstr.cpp | 396 |
11 files changed, 583 insertions, 736 deletions
diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp index 398b5e4..652149e 100644 --- a/c++/test/dsets.cpp +++ b/c++/test/dsets.cpp @@ -61,7 +61,6 @@ const int H5Z_FILTER_BOGUS = 305; // Local prototypes static size_t filter_bogus(unsigned int flags, size_t cd_nelmts, const unsigned int *cd_values, size_t nbytes, size_t *buf_size, void **buf); -void cleanup_dsets(void); /*------------------------------------------------------------------------- @@ -173,7 +172,7 @@ test_create( H5File& file) // catch all other exceptions catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__); + issue_fail_msg("test_create", __LINE__, __FILE__); // clean up and return with failure if (dataset != NULL) @@ -972,7 +971,7 @@ test_types(H5File& file) *------------------------------------------------------------------------- */ int -main(void) +main() { hid_t fapl_id; fapl_id = h5_fileaccess(); // in h5test.c, returns a file access template @@ -1028,9 +1027,11 @@ main(void) * *------------------------------------------------------------------------- */ -void -cleanup_dsets(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_dsets() { - remove(FILE1.c_str()); + HDremove(FILE1.c_str()); } // cleanup_dsets diff --git a/c++/test/h5cpputil.cpp b/c++/test/h5cpputil.cpp index 0cd6e3c..4afde22 100644 --- a/c++/test/h5cpputil.cpp +++ b/c++/test/h5cpputil.cpp @@ -100,7 +100,7 @@ void issue_fail_msg(const char* where, int line, const char* file_name, { //if (GetTestVerbosity()>=VERBO_HI) { - cerr << "ERROR>>> From " << where << " at line " << line + cerr << ">>> FAILED in " << where << " at line " << line << " in " << file_name << " - " << message << endl << endl; } } @@ -160,3 +160,25 @@ InvalidActionException::InvalidActionException(const H5std_string func_name, con //-------------------------------------------------------------------------- InvalidActionException::~InvalidActionException() {} +//-------------------------------------------------------------------------- +// Function: TestFailedException default constructor +//-------------------------------------------------------------------------- +TestFailedException::TestFailedException():Exception(){} + +//-------------------------------------------------------------------------- +// Function: TestFailedException overloaded constructor +// +// Purpose: Creates an TestFailedException with the name of the function, +// which the failure should have occurred but didn't, and a +// message explaining why it should fail. +// Parameters +// func_name - IN: Name of the function where failure should occur +// message - IN: Message +//-------------------------------------------------------------------------- +TestFailedException::TestFailedException(const H5std_string func_name, const H5std_string message) : Exception(func_name, message) {} + +//-------------------------------------------------------------------------- +// Function: TestFailedException destructor +//-------------------------------------------------------------------------- +TestFailedException::~TestFailedException() {} + diff --git a/c++/test/h5cpputil.h b/c++/test/h5cpputil.h index bb08f45..d22a4d3 100644 --- a/c++/test/h5cpputil.h +++ b/c++/test/h5cpputil.h @@ -42,20 +42,37 @@ int test_report (int, const H5std_string&); void issue_fail_msg(const char* where, int line, const char* file_name, const char* message=""); +class InvalidActionException : public Exception { + public: + InvalidActionException(const H5std_string func_name, const H5std_string message = DEFAULT_MSG); + InvalidActionException(); + virtual ~InvalidActionException(); +}; + +class TestFailedException : public Exception { + public: + TestFailedException(const H5std_string func_name, const H5std_string message = DEFAULT_MSG); + TestFailedException(); + virtual ~TestFailedException(); +}; + template <class Type1, class Type2> void verify_val(Type1 x, Type2 value, const char* where, int line, const char* file_name) { if (GetTestVerbosity()>=VERBO_HI) { + cerr << endl; cerr << " Call to routine: " << where << " at line " << line << " in " << file_name << " had value " << x << endl; } if (x != value) { + cerr << endl; cerr << "*** UNEXPECTED VALUE from " << where << " should be " << value << ", but is " << x << " at line " << line << " in " << file_name << endl; IncTestNumErrs(); + throw TestFailedException(where, ""); } } @@ -64,10 +81,12 @@ template <class Type1, class Type2> { if (x != value) { + cerr << endl; cerr << "*** UNEXPECTED VALUE: " << file_name << ":line " << line << ":" << msg << " different: " << x << ", should be " << value << endl; IncTestNumErrs(); + throw TestFailedException(file_name, msg); } } @@ -76,24 +95,20 @@ template <class Type1, class Type2> { if (GetTestVerbosity()>=VERBO_HI) { + cerr << endl; cerr << " Call to routine: " << where << " at line " << line << " in " << file_name << " had value " << x << endl; } if (x == value) { + cerr << endl; cerr << "*** UNEXPECTED VALUE from " << where << " should not be " << value << " at line " << line << " in " << file_name << endl; IncTestNumErrs(); + throw TestFailedException(where, ""); } } -class InvalidActionException : public Exception { - public: - InvalidActionException(const H5std_string func_name, const H5std_string message = DEFAULT_MSG); - InvalidActionException(); - virtual ~InvalidActionException(); -}; - /* Prototypes for the test routines */ #ifdef __cplusplus extern "C" { @@ -110,6 +125,7 @@ void test_vlstrings(void); /* Prototypes for the cleanup routines */ void cleanup_attr(void); void cleanup_compound(void); +void cleanup_dsets(void); void cleanup_file(void); void cleanup_filters(void); void cleanup_h5s(void); diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index ede7e31..c6225229 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -44,24 +44,18 @@ #include "h5cpputil.h" // C++ utilility header file const H5std_string FILENAME("tattr.h5"); -const size_t ATTR_MAX_DIMS = 7; const H5std_string ATTR_TMP_NAME("temp_name"); +const size_t ATTR_MAX_DIMS = 7; /* 3-D dataset with fixed dimensions */ -const H5std_string SPACE1_NAME("Space1"); const int SPACE1_RANK = 3; const int SPACE1_DIM1 = 3; const int SPACE1_DIM2 = 15; const int SPACE1_DIM3 = 13; -/* Dataset Information */ +/* Object names */ const H5std_string DSET1_NAME("Dataset1"); -const H5std_string DSET2_NAME("Dataset2"); - -/* Group Information */ const H5std_string GROUP1_NAME("/Group1"); - -/* Named Datatype Information */ const H5std_string TYPE1_NAME("/Type"); /* Attribute Rank & Dimensions */ @@ -115,8 +109,7 @@ int attr_data1a[ATTR1_DIM1]={256,11945,-22107}; ** Tests integer attributes on both datasets and groups ** ****************************************************************/ -static void -test_attr_basic_write(void) +static void test_attr_basic_write() { hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; hsize_t dims2[] = {ATTR1_DIM1}; @@ -125,7 +118,7 @@ test_attr_basic_write(void) int i; // Output message about test being performed - MESSAGE(5, ("Testing Basic Attribute Writing Functions\n")); + SUBTEST("Testing Basic Attribute Writing Functions"); try { // Create file @@ -134,6 +127,10 @@ test_attr_basic_write(void) // Create dataspace for dataset DataSpace ds_space (SPACE1_RANK, dims1); + /* + * Test attribute with dataset + */ + // Create a dataset DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space); @@ -220,26 +217,27 @@ test_attr_basic_write(void) attr_size = gr_attr.getStorageSize(); verify_val((long)attr_size, (long)(ATTR2_DIM1*ATTR2_DIM2*sizeof(int)), "Attribute::getStorageSize", __LINE__, __FILE__); + + PASSED(); } // end try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_basic_write()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_attr_basic_write() */ +} // test_attr_basic_write() /**************************************************************** ** ** test_attr_rename(): Test renaming attribute function. ** ****************************************************************/ -static void -test_attr_rename(void) +static void test_attr_rename() { int read_data1[ATTR1_DIM1]={0}; // Buffer for reading the attribute int i; // Output message about test being performed - MESSAGE(5, ("Testing Rename Attribute Function\n")); + SUBTEST("Testing Rename Attribute Function"); try { // Open file @@ -291,25 +289,26 @@ test_attr_rename(void) // Change first attribute back to the original name dataset.renameAttr(ATTR_TMP_NAME, ATTR1_NAME); + + PASSED(); } // end try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_rename()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_attr_rename() */ +} // test_attr_rename() /******************************************************************** ** ** test_attr_basic_read(): Test basic read attribute. ** ********************************************************************/ -static void -test_attr_basic_read(void) +static void test_attr_basic_read() { int i, j; // Output message about test being performed - MESSAGE(5, ("Testing Basic Attribute Reading Functions\n")); + SUBTEST("Testing Basic Attribute Reading Functions"); try { // Open file @@ -359,24 +358,24 @@ test_attr_basic_read(void) if(attr_data2[i][j]!=read_data2[i][j]) { TestErrPrintf("%d: attribute data different: attr_data2[%d][%d]=%d, read_data2[%d][%d]=%d\n",__LINE__, i,j,attr_data2[i][j],i,j,read_data1[i]); } + PASSED(); } // end try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_basic_read()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_attr_basic_read() */ +} // test_attr_basic_read() /**************************************************************** ** ** test_attr_compound_write(): Tests compound datatype attributes ** ****************************************************************/ -static void -test_attr_compound_write(void) +static void test_attr_compound_write() { // Output message about test being performed - MESSAGE(5, ("Testing Multiple Attribute Functions\n")); + SUBTEST("Testing Multiple Attribute Functions"); try { // Create file @@ -418,20 +417,20 @@ test_attr_compound_write(void) // Write complex attribute data attr.write(comp_type, attr_data4); + PASSED(); } // end try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_compound_write()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_attr_compound_write() */ +} // test_attr_compound_write() /**************************************************************** ** ** test_attr_compound_read(): Test basic H5A (attribute) code. ** ****************************************************************/ -static void -test_attr_compound_read(void) +static void test_attr_compound_read() { hsize_t dims[ATTR_MAX_DIMS]; // Attribute dimensions size_t size; // Attribute datatype size as stored in file @@ -440,7 +439,7 @@ test_attr_compound_read(void) int i,j; // Output message about test being performed - MESSAGE(5, ("Testing Basic Attribute Functions\n")); + SUBTEST("Testing Basic Attribute Functions"); try { // Open file @@ -553,23 +552,23 @@ test_attr_compound_read(void) // Verify name H5std_string attr_name = attr.getName(); verify_val(attr_name, ATTR4_NAME, "Attribute::getName", __LINE__, __FILE__); + PASSED(); } // end try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_compound_read()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_attr_compound_read() */ +} // test_attr_compound_read() /**************************************************************** ** ** test_attr_scalar_write(): Test scalar attribute writing functionality. ** ****************************************************************/ -static void -test_attr_scalar_write(void) +static void test_attr_scalar_write() { // Output message about test being performed - MESSAGE(5, ("Testing Basic Scalar Attribute Writing Functions\n")); + SUBTEST("Testing Basic Scalar Attribute Writing Functions"); try { // Create file @@ -606,23 +605,24 @@ test_attr_scalar_write(void) // Write attribute information ds_attr.write (PredType::NATIVE_FLOAT, &attr_data5); + + PASSED(); } // end try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_scalar_write()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_attr_scalar_write() */ +} // test_attr_scalar_write() /**************************************************************** ** ** test_attr_scalar_read(): Test scalar attribute reading functionality. ** ****************************************************************/ -static void -test_attr_scalar_read(void) +static void test_attr_scalar_read() { // Output message about test being performed - MESSAGE(5, ("Testing Basic Scalar Attribute Reading Functions\n")); + SUBTEST("Testing Basic Scalar Attribute Reading Functions"); try { // Open file @@ -649,23 +649,24 @@ test_attr_scalar_read(void) // Make certain the dataspace is scalar H5S_class_t space_type = att_space.getSimpleExtentType(); verify_val(space_type, H5S_SCALAR, "DataSpace::getSimpleExtentType", __LINE__, __FILE__); + + PASSED(); } // end try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_scalar_read()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_attr_scalar_read() */ +} // test_attr_scalar_read() /**************************************************************** ** ** test_attr_mult_write(): Test multiple attributes ** ****************************************************************/ -static void -test_attr_mult_write(void) +static void test_attr_mult_write() { // Output message about test being performed - MESSAGE(5, ("Testing Multiple Attribute Writing Functions\n")); + SUBTEST("Testing Multiple Attribute Writing Functions"); try { // Create file @@ -720,20 +721,21 @@ test_attr_mult_write(void) // Write 3rd attribute information ds_attr3.write (PredType::NATIVE_DOUBLE, attr_data3); + + PASSED(); } // end try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_mult_write()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_attr_mult_write() */ +} // test_attr_mult_write() /**************************************************************** ** ** test_attr_mult_read(): Test reading multiple attributes. ** ****************************************************************/ -static void -test_attr_mult_read(void) +static void test_attr_mult_read() { int read_data1[ATTR1_DIM1]={0}; // Buffer for reading 1st attribute int read_data2[ATTR2_DIM1][ATTR2_DIM2]={{0}}; // Buffer for reading 2nd attribute @@ -741,7 +743,7 @@ test_attr_mult_read(void) int i,j,k; // Output message about test being performed - MESSAGE(5, ("Testing Multiple Attribute Reading Functions\n")); + SUBTEST("Testing Multiple Attribute Reading Functions"); try { // Open file @@ -910,12 +912,14 @@ test_attr_mult_read(void) // Verify Name attr_name = attr.getName(); verify_val(attr_name, ATTR3_NAME, "DataType::getName", __LINE__, __FILE__); + + PASSED(); } // end try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_mult_read()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_attr_mult_read() */ +} // test_attr_mult_read() /**************************************************************** ** @@ -923,13 +927,12 @@ test_attr_mult_read(void) ** hdf5 objects. ** ****************************************************************/ -static void -test_attr_delete(void) +static void test_attr_delete() { H5std_string attr_name; // Buffer for attribute names // Output message about test being performed - MESSAGE(5, ("Testing Removing Attribute Function\n")); + SUBTEST("Testing Removing Attribute Function"); try { // Open file @@ -1004,12 +1007,14 @@ test_attr_delete(void) // Verify the correct number of attributes num_attrs = dataset.getNumAttrs(); verify_val(num_attrs, 0, "H5Object::getNumAttrs", __LINE__, __FILE__); + + PASSED(); } // end try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_delete()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_attr_delete() */ +} // test_attr_delete() /**************************************************************** ** @@ -1017,8 +1022,7 @@ test_attr_delete(void) ** in attributes. ** ****************************************************************/ -static void -test_attr_dtype_shared(void) +static void test_attr_dtype_shared() { int data=8; /* Data to write */ int rdata=0; /* Read read in */ @@ -1026,7 +1030,7 @@ test_attr_dtype_shared(void) h5_stat_size_t filesize; /* Size of file after modifications */ // Output message about test being performed - MESSAGE(5, ("Testing Shared Datatypes with Attributes\n")); + SUBTEST("Testing Shared Datatypes with Attributes"); try { // Create a file @@ -1135,12 +1139,14 @@ test_attr_dtype_shared(void) // Check size of file filesize=h5_get_file_size(FILENAME.c_str()); verify_val((long)filesize, (long)empty_filesize, "Checking file size", __LINE__, __FILE__); + + PASSED(); } // end try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_dtype_shared()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_attr_dtype_shared() */ +} // test_attr_dtype_shared() /**************************************************************** ** @@ -1152,11 +1158,10 @@ test_attr_dtype_shared(void) const H5std_string ATTRSTR_NAME("String_attr"); const H5std_string ATTRSTR_DATA("String Attribute"); -static void -test_string_attr(void) +static void test_string_attr() { // Output message about test being performed - MESSAGE(5, ("Testing Basic Attribute Writing Functions\n")); + SUBTEST("Testing Basic Attribute Writing Functions"); try { // Create file @@ -1188,12 +1193,14 @@ test_string_attr(void) gr_attr.read(type, read_str); if (read_str != ATTRSTR_DATA) TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_str=%s\n",__LINE__, ATTRSTR_DATA.c_str(), read_str.c_str()); + + PASSED(); } // end try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_string_attr()", __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_string_attr() */ +} // test_string_attr() /**************************************************************** ** @@ -1203,7 +1210,7 @@ test_string_attr(void) #ifdef __cplusplus extern "C" #endif -void test_attr(void) +void test_attr() { // Output message about test being performed MESSAGE(5, ("Testing Attributes\n")); @@ -1226,7 +1233,7 @@ void test_attr(void) test_string_attr(); // Test read/write string attribute -} /* test_attr() */ +} // test_attr() /*------------------------------------------------------------------------- * Function: cleanup_attr @@ -1242,9 +1249,11 @@ void test_attr(void) * *------------------------------------------------------------------------- */ -void -cleanup_attr(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_attr() { - remove(FILENAME.c_str()); + HDremove(FILENAME.c_str()); } diff --git a/c++/test/tcompound.cpp b/c++/test/tcompound.cpp index f6571b1..9532dd6 100644 --- a/c++/test/tcompound.cpp +++ b/c++/test/tcompound.cpp @@ -65,23 +65,22 @@ typedef struct complex_t { * *------------------------------------------------------------------------- */ -static void test_compound_1(void) +static void test_compound_1() { // Output message about test being performed SUBTEST("Compound Data Types"); - try - { + try { // Create an empty compound datatype CompType complex_type(sizeof(complex_t)); // Add a couple of fields complex_type.insertMember("real", HOFFSET(complex_t, re), PredType::NATIVE_DOUBLE); complex_type.insertMember("imaginary", HOFFSET(complex_t, im), PredType::NATIVE_DOUBLE); - PASSED(); } // end of try block catch (Exception E) { +cerr << "test_compound_1 in catch" << endl; issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_1() @@ -103,7 +102,7 @@ static void test_compound_1(void) * *------------------------------------------------------------------------- */ -static void test_compound_2(void) +static void test_compound_2() { typedef struct { int a, b, c[4], d, e; @@ -121,9 +120,8 @@ static void test_compound_2(void) // Output message about test being performed SUBTEST("Compound Element Reordering"); - try - { - /* Sizes should be the same, but be careful just in case */ + try { + // Sizes should be the same, but be careful just in case buf = (unsigned char*)malloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); bkg = (unsigned char*)malloc(nelmts * sizeof(dst_typ_t)); orig = (unsigned char*)malloc(nelmts * sizeof(src_typ_t)); @@ -140,7 +138,7 @@ static void test_compound_2(void) } memcpy(buf, orig, nelmts*sizeof(src_typ_t)); - /* Build hdf5 datatypes */ + // Build hdf5 datatypes ArrayType* array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); // Create an empty compound datatype @@ -163,10 +161,10 @@ static void test_compound_2(void) dt.insertMember("e", HOFFSET(dst_typ_t, e), PredType::NATIVE_INT); array_dt->close(); - /* Perform the conversion */ + // Perform the conversion st.convert(dt, (size_t)nelmts, buf, bkg); - /* Compare results */ + // Compare results for (i=0; i<nelmts; i++) { s_ptr = ((src_typ_t*)orig) + i; d_ptr = ((dst_typ_t*)buf) + i; @@ -188,22 +186,21 @@ static void test_compound_2(void) << "c=[" << s_ptr->c[0] << "," << s_ptr->c[1] << "," << s_ptr->c[2] << "," << s_ptr->c[3] << ", d=" << s_ptr->d << ", e=" << s_ptr->e << "}" << endl; - } - } - - /* Release resources */ - free(buf); - free(bkg); - free(orig); - s_ptr = NULL; - d_ptr = NULL; - st.close(); - dt.close(); - - PASSED(); + } + } + // Release resources + free(buf); + free(bkg); + free(orig); + s_ptr = NULL; + d_ptr = NULL; + st.close(); + dt.close(); + PASSED(); } // end of try block catch (Exception E) { +cerr << "test_compound_2 in catch" << endl; issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_2() @@ -225,7 +222,7 @@ static void test_compound_2(void) * *------------------------------------------------------------------------- */ -static void test_compound_3(void) +static void test_compound_3() { typedef struct { int a, b, c[4], d, e; @@ -243,8 +240,7 @@ static void test_compound_3(void) // Output message about test being performed SUBTEST("Compound Datatype Subset Conversions"); - try - { + try { /* Initialize */ buf = (unsigned char*)malloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); bkg = (unsigned char*)malloc(nelmts * sizeof(dst_typ_t)); @@ -317,11 +313,11 @@ static void test_compound_3(void) d_ptr = NULL; st.close(); dt.close(); - PASSED(); } // end of try block catch (Exception E) { +cerr << "test_compound_3 in catch" << endl; issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_3() @@ -343,7 +339,7 @@ static void test_compound_3(void) * *------------------------------------------------------------------------- */ -static void test_compound_4(void) +static void test_compound_4() { typedef struct { @@ -366,8 +362,7 @@ static void test_compound_4(void) // Output message about test being performed SUBTEST("Compound Element Shrinking & Reordering"); - try - { + try { /* Sizes should be the same, but be careful just in case */ buf = (unsigned char*)malloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); bkg = (unsigned char*)malloc(nelmts * sizeof(dst_typ_t)); @@ -445,11 +440,11 @@ static void test_compound_4(void) d_ptr = NULL; st.close(); dt.close(); - PASSED(); } // end of try block catch (Exception E) { +cerr << "test_compound_4 in catch" << endl; issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_4() @@ -472,7 +467,7 @@ static void test_compound_4(void) * *------------------------------------------------------------------------- */ -static void test_compound_5(void) +static void test_compound_5() { typedef struct { char name[16]; @@ -495,8 +490,7 @@ static void test_compound_5(void) // Output message about test being performed SUBTEST("Optimized Struct Converter"); - try - { + try { /* Build datatypes */ ArrayType* array_dt = new ArrayType(PredType::NATIVE_SHORT, 1, dims); @@ -549,6 +543,7 @@ static void test_compound_5(void) } // end of try block catch (Exception E) { +cerr << "test_compound_5 in catch" << endl; issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_5() @@ -570,7 +565,7 @@ static void test_compound_5(void) * *------------------------------------------------------------------------- */ -static void test_compound_6(void) +static void test_compound_6() { typedef struct { short b; @@ -590,8 +585,7 @@ static void test_compound_6(void) // Output message about test being performed SUBTEST("Compound Element Growing"); - try - { + try { /* Sizes should be the same, but be careful just in case */ buf = (unsigned char*)malloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); bkg = (unsigned char*)malloc(nelmts * sizeof(dst_typ_t)); @@ -639,11 +633,11 @@ static void test_compound_6(void) d_ptr = NULL; st.close(); dt.close(); - PASSED(); } // end of try block catch (Exception E) { +cerr << "test_compound_6 in catch" << endl; issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_6() @@ -663,7 +657,7 @@ static void test_compound_6(void) * *------------------------------------------------------------------------- */ -static void test_compound_7(void) +static void test_compound_7() { typedef struct { int a; @@ -680,8 +674,7 @@ static void test_compound_7(void) // Output message about test being performed SUBTEST("Compound Element Insertion"); - try - { + try { CompType tid1(sizeof(s1_typ_t)); tid1.insertMember("a", HOFFSET(s1_typ_t,a),PredType::NATIVE_INT); @@ -707,11 +700,11 @@ static void test_compound_7(void) /* Release resources */ tid1.close(); tid2.close(); - PASSED(); } // end of try block catch (Exception E) { +cerr << "test_compound_7 in catch" << endl; issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_7() @@ -734,7 +727,7 @@ static void test_compound_7(void) #ifdef __cplusplus extern "C" #endif -void test_compound(void) +void test_compound() { // Output message about test being performed MESSAGE(5, ("Testing Compound Data Type operations\n")); @@ -760,7 +753,9 @@ void test_compound(void) * *------------------------------------------------------------------------- */ -void -cleanup_compound(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_compound() { } // cleanup_file diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp index f3d9574..71f0a60 100644 --- a/c++/test/tfile.cpp +++ b/c++/test/tfile.cpp @@ -91,11 +91,10 @@ const H5std_string FILE4("tfile4.h5"); * *------------------------------------------------------------------------- */ -static void -test_file_create(void) +static void test_file_create() { // Output message about test being performed - MESSAGE(5, ("Testing File Creation I/O\n")); + SUBTEST("Testing File Creation I/O"); // Test create with various sequences of H5F_ACC_EXCL and // H5F_ACC_TRUNC flags @@ -186,7 +185,7 @@ test_file_create(void) } catch (InvalidActionException E) { - cerr << " FAILED" << endl; + cerr << " *FAILED*" << endl; cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; if (file1 != NULL) // clean up delete file1; @@ -194,7 +193,7 @@ test_file_create(void) // catch all other exceptions catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_file_create()", __LINE__, __FILE__, E.getCDetailMsg()); if (file1 != NULL) // clean up delete file1; } @@ -268,11 +267,12 @@ test_file_create(void) // Release file-creation template delete tmpl1; + PASSED(); } // catch all exceptions catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_file_create()", __LINE__, __FILE__, E.getCDetailMsg()); if (tmpl1 != NULL) // clean up delete tmpl1; } @@ -299,11 +299,10 @@ test_file_create(void) * *------------------------------------------------------------------------- */ -static void -test_file_open(void) +static void test_file_open() { // Output message about test being performed - MESSAGE(5, ("Testing File Opening I/O\n")); + SUBTEST("Testing File Opening I/O"); try { @@ -326,10 +325,11 @@ test_file_open(void) tmpl1.getSymk( iparm1, iparm2); verify_val(iparm1, F2_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); verify_val(iparm2, F2_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); + PASSED(); } // end of try block catch( Exception E ) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_file_open()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_file_open() @@ -348,11 +348,10 @@ test_file_open(void) * *------------------------------------------------------------------------- */ -static void -test_file_size(void) +static void test_file_size() { // Output message about test being performed - MESSAGE(5, ("Testing File Size\n")); + SUBTEST("Testing File Size"); hid_t fapl_id; fapl_id = h5_fileaccess(); // in h5test.c, returns a file access template @@ -375,11 +374,12 @@ test_file_size(void) // Check if file size is reasonable. It's supposed to be 2KB now. if(file_size<1*KB || file_size>4*KB) - issue_fail_msg("H5File::getFileSize", __LINE__, __FILE__); + issue_fail_msg("test_file_size()", __LINE__, __FILE__); + PASSED(); } // end of try block catch( Exception E ) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_file_size()", __LINE__, __FILE__, E.getCDetailMsg()); } // use C test utility routine to close property list. @@ -416,11 +416,10 @@ typedef struct s1_t { float b; } s1_t; -static void -test_file_name() +static void test_file_name() { // Output message about test being performed - MESSAGE(5, ("Testing File Name\n")); + SUBTEST("Testing File Name"); H5std_string file_name; try { @@ -469,10 +468,11 @@ test_file_name() // Get and verify file name comp_type.getFileName(); verify_val(file_name, FILE4, "CompType::getFileName", __LINE__, __FILE__); + PASSED(); } // end of try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_file_name()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_file_name() @@ -495,7 +495,7 @@ test_file_name() #ifdef __cplusplus extern "C" #endif -void test_file(void) +void test_file() { // Output message about test being performed MESSAGE(5, ("Testing File I/O operations\n")); @@ -520,11 +520,13 @@ void test_file(void) * *------------------------------------------------------------------------- */ -void -cleanup_file(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_file() { - remove(FILE1.c_str()); - remove(FILE2.c_str()); - remove(FILE3.c_str()); - remove(FILE4.c_str()); + HDremove(FILE1.c_str()); + HDremove(FILE2.c_str()); + HDremove(FILE3.c_str()); + HDremove(FILE4.c_str()); } // cleanup_file diff --git a/c++/test/tfilter.cpp b/c++/test/tfilter.cpp index 2a9503a..1774cf2 100644 --- a/c++/test/tfilter.cpp +++ b/c++/test/tfilter.cpp @@ -113,13 +113,11 @@ filter_bogus(unsigned int UNUSED flags, size_t UNUSED cd_nelmts, // Chunk dimensions const hsize_t chunk_size[2] = {FILTER_CHUNK_DIM1, FILTER_CHUNK_DIM2}; -static void test_null_filter(void) +static void test_null_filter() { // Output message about test being performed SUBTEST("'Null' filter"); - - try - { + try { hsize_t null_size; // Size of dataset with null filter // Prepare dataset create property list @@ -144,7 +142,7 @@ static void test_null_filter(void) // catch all other exceptions catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_null_filter()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_null_filter @@ -176,10 +174,10 @@ void test_szip_filter(H5File& file1) // Output message about test being performed SUBTEST("szip filter (with encoder)"); + if ( h5_szip_can_encode() == 1) { char* tconv_buf = new char [1000]; - try - { + try { const hsize_t size[2] = {DSET_DIM1, DSET_DIM2}; // Create the data space @@ -222,14 +220,15 @@ void test_szip_filter(H5File& file1) throw Exception("test_szip_filter", "Failed in testing szip method"); } dsplist.close(); + PASSED(); } // end of try // catch all other exceptions catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_szip_filter()", __LINE__, __FILE__, E.getCDetailMsg()); } - } + } // if szip presents else { SKIPPED(); } @@ -251,7 +250,7 @@ const H5std_string FILE1("tfilters.h5"); #ifdef __cplusplus extern "C" #endif -void test_filters(void) +void test_filters() { // Output message about test being performed MESSAGE(5, ("Testing Various Filters\n")); @@ -273,7 +272,7 @@ void test_filters(void) } catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_filters()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_filters() @@ -291,8 +290,10 @@ void test_filters(void) * *------------------------------------------------------------------------- */ -void -cleanup_filters(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_filters() { HDremove(FILE1.c_str()); } diff --git a/c++/test/th5s.cpp b/c++/test/th5s.cpp index 9c49105..5a7c678 100644 --- a/c++/test/th5s.cpp +++ b/c++/test/th5s.cpp @@ -112,8 +112,7 @@ int space5_data = 7; * with a special routine. *------------------------------------------------------------------------- */ -static void -test_h5s_basic(void) +static void test_h5s_basic() { hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; hsize_t dims2[] = {SPACE2_DIM1, SPACE2_DIM2, SPACE2_DIM3, @@ -122,11 +121,9 @@ test_h5s_basic(void) hsize_t tmax[4]; // Output message about test being performed - MESSAGE(5, ("Testing Dataspace Manipulation\n")); - - try - { // beginning of first try block + SUBTEST("Testing Dataspace Manipulation"); + try { // Create simple dataspace sid1 DataSpace sid1 (SPACE1_RANK, dims1 ); @@ -213,7 +210,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. - BMR - // Verify that incorrect dimensions don't work + // Verify that incorrect dimensions don't work dims1[0] = 0; try { DataSpace wrongdim_ds (SPACE1_RANK, dims1); @@ -234,7 +231,9 @@ test_h5s_basic(void) } catch (DataSpaceIException E) // catching use of incorrect dimensions {} // do nothing, exception expected - } // end of outer try block + + PASSED(); + } // end of try block catch (InvalidActionException E) { @@ -244,7 +243,7 @@ test_h5s_basic(void) // catch all other exceptions catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_h5s_basic()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_h5s_basic() @@ -268,14 +267,12 @@ test_h5s_basic(void) * with a special routine. *------------------------------------------------------------------------- */ -static void -test_h5s_scalar_write(void) +static void test_h5s_scalar_write() { // Output message about test being performed - MESSAGE(5, ("Testing Scalar Dataspace Writing\n")); + SUBTEST("Testing Scalar Dataspace Writing"); - try - { + try { // Create file H5File fid1(DATAFILE, H5F_ACC_TRUNC); @@ -302,14 +299,15 @@ test_h5s_scalar_write(void) ext_type = sid1.getSimpleExtentType(); verify_val(ext_type, H5S_SCALAR, "DataSpace::getSimpleExtentType", __LINE__, __FILE__); - // Create a dataset - DataSet dataset = fid1.createDataSet("Dataset1", PredType::NATIVE_UINT,sid1); - + // Create and write a dataset + DataSet dataset = fid1.createDataSet("Dataset1", PredType::NATIVE_UINT,sid1); dataset.write(&space3_data, PredType::NATIVE_UINT); + + PASSED(); } // end of try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_h5s_scalar_write()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_h5s_scalar_write() @@ -333,16 +331,14 @@ test_h5s_scalar_write(void) * with a special routine. *------------------------------------------------------------------------- */ -static void -test_h5s_scalar_read(void) +static void test_h5s_scalar_read() { hsize_t tdims[4]; // Dimension array to test with // Output message about test being performed - MESSAGE(5, ("Testing Scalar Dataspace Reading\n")); + SUBTEST("Testing Scalar Dataspace Reading"); - try - { + try { // Create file H5File fid1(DATAFILE, H5F_ACC_RDWR); @@ -362,14 +358,17 @@ test_h5s_scalar_read(void) ndims = sid1.getSimpleExtentDims(tdims); verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); + // Read data back and verify it unsigned rdata; // Scalar data read in dataset.read(&rdata, PredType::NATIVE_UINT); verify_val(rdata, space3_data, "DataSet::read", __LINE__, __FILE__); + + PASSED(); } // end of try block catch (Exception E) { // all the exceptions caused by negative returned values by C APIs - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_h5s_scalar_read()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_h5s_scalar_read() @@ -394,14 +393,12 @@ test_h5s_scalar_read(void) * with a special routine. *------------------------------------------------------------------------- */ -static void -test_h5s_null(void) +static void test_h5s_null() { // Output message about test being performed - MESSAGE(5, ("Testing Null Dataspace Writing\n")); + SUBTEST("Testing Null Dataspace Writing"); - try - { + try { // Create file H5File fid1(DATAFILE, H5F_ACC_TRUNC); @@ -421,10 +418,12 @@ test_h5s_null(void) // Read the data. Make sure no change to the buffer dataset.read(&space5_data, PredType::NATIVE_INT); verify_val(space5_data, 7, "DataSet::read", __LINE__, __FILE__); + + PASSED(); } // end of try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_h5s_null()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_h5s_null() @@ -449,14 +448,12 @@ test_h5s_null(void) * with a special routine. *------------------------------------------------------------------------- */ -static void -test_h5s_compound_scalar_write(void) +static void test_h5s_compound_scalar_write() { // Output message about test being performed - MESSAGE(5, ("Testing Compound Dataspace Writing\n")); + SUBTEST("Testing Compound Dataspace Writing"); - try - { + try { // Create file H5File fid1(DATAFILE, H5F_ACC_TRUNC); @@ -490,15 +487,16 @@ test_h5s_compound_scalar_write(void) ndims = sid1.getSimpleExtentDims(tdims); verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); - // Create a dataset + // Create and write a dataset DataSet dataset = fid1.createDataSet("Dataset1", tid1, sid1); - dataset.write(&space4_data, tid1); + + PASSED(); } // end of try block catch (Exception E) { // all the exceptions caused by negative returned values by C APIs - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_h5s_compound_scalar_write()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_h5s_compound_scalar_write() @@ -523,15 +521,13 @@ test_h5s_compound_scalar_write(void) * with a special routine. *------------------------------------------------------------------------- */ -static void -test_h5s_compound_scalar_read(void) +static void test_h5s_compound_scalar_read() { hsize_t tdims[4]; // Dimension array to test with // Output message about test being performed - MESSAGE(5, ("Testing Compound Dataspace Reading\n")); - try - { + SUBTEST("Testing Compound Dataspace Reading"); + try { // Create file H5File fid1(DATAFILE, H5F_ACC_RDWR); @@ -569,11 +565,12 @@ test_h5s_compound_scalar_read(void) TestErrPrintf("scalar data different: space4_data.c1=%c, read_data4.c1=%c\n", space4_data.c1, rdata.c2); } // end if + PASSED(); } // end of try block catch (Exception E) { // all the exceptions caused by negative returned values by C APIs - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_h5s_compound_scalar_read()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_h5s_compound_scalar_read() @@ -594,7 +591,7 @@ test_h5s_compound_scalar_read(void) #ifdef __cplusplus extern "C" #endif -void test_h5s(void) +void test_h5s() { // Output message about test being performed MESSAGE(5, ("Testing Dataspaces\n")); @@ -622,9 +619,11 @@ void test_h5s(void) * *------------------------------------------------------------------------- */ -void -cleanup_h5s(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_h5s() { - remove(DATAFILE.c_str()); + HDremove(DATAFILE.c_str()); } // cleanup_h5s diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp index edcd968..71498ce 100644 --- a/c++/test/trefer.cpp +++ b/c++/test/trefer.cpp @@ -84,14 +84,13 @@ typedef struct s1_t { ** Tests references to various kinds of objects ** ****************************************************************/ -static void -test_reference_obj(void) +static void test_reference_obj() { int i; // counting variables const H5std_string write_comment="Foo!"; // Comments for group // Output message about test being performed - MESSAGE(5, ("Testing Object Reference Functions\n")); + SUBTEST("Testing Object Reference Functions"); H5File* file1 = NULL; try { @@ -266,9 +265,11 @@ test_reference_obj(void) free(wbuf); free(rbuf); free(tbuf); + + PASSED(); } // end try catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_reference_obj()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_reference_obj() @@ -280,7 +281,7 @@ test_reference_obj(void) #ifdef __cplusplus extern "C" #endif -void test_reference(void) +void test_reference() { // Output message about test being performed MESSAGE(5, ("Testing References\n")); @@ -295,9 +296,11 @@ void test_reference(void) ** Purpose: Cleanup temporary test files ** Return: none ****************************************************************/ -void -cleanup_reference(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_reference() { - remove(FILE1.c_str()); + HDremove(FILE1.c_str()); } diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp index 4e9faae..bdebcf7 100644 --- a/c++/test/ttypes.cpp +++ b/c++/test/ttypes.cpp @@ -15,7 +15,7 @@ /***************************************************************************** FILE - ttypes.cpp - HDF5 C++ testing the general data type functionality + ttypes.cpp - HDF5 C++ testing the general datatype functionality ***************************************************************************/ @@ -42,16 +42,6 @@ #include "h5cpputil.h" // C++ utilility header file -const H5std_string DATAFILE("ttypes.h5"); - -#define NTESTS 1 - -/* Number of elements in each test */ -#define NTESTELEM 100000 - -/* Define if you want to see a count of overflows */ -#undef SHOW_OVERFLOWS - /* * Offset from alinged memory returned by malloc(). This can be used to test * that type conversions handle non-aligned buffers correctly. @@ -60,7 +50,7 @@ const H5std_string DATAFILE("ttypes.h5"); /* * Define if you want to test alignment code on a machine that doesn't - * normally require alignment. When set, all native data types must be aligned + * normally require alignment. When set, all native datatypes must be aligned * on a byte boundary equal to the data size. */ #define TEST_ALIGNMENT @@ -97,98 +87,13 @@ typedef enum int_t { INT_LONG, INT_ULONG, INT_LLONG, INT_ULLONG, INT_OTHER } int_t; -/* Count the number of overflows */ -#ifdef SHOW_OVERFLOWS -static int noverflows_g = 0; -#endif - -/* Skip overflow tests if non-zero */ -static int skip_overflow_tests_g = 0; - -/* Don't use hardware conversions if set */ -static int without_hardware_g = 0; - -/* Count opaque conversions */ -static int num_opaque_conversions_g = 0; - -/* - * Although we check whether a floating point overflow generates a SIGFPE and - * turn off overflow tests in that case, it might still be possible for an - * overflow condition to occur. Once a SIGFPE is raised the program cannot - * be allowed to continue (cf. Posix signals) so in order to recover from a - * SIGFPE we run tests that might generate one in a child process. - */ -#if defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID) -# define HANDLE_SIGFPE -#endif - -/* Allocates memory aligned on a certain boundary. */ -#define aligned_malloc(Z) ((void*)((char*)malloc(ALIGNMENT+Z)+ALIGNMENT)) -#define aligned_free(M) free((char*)(M)-ALIGNMENT) - - -/*------------------------------------------------------------------------- - * Function: fpe_handler - * - * Purpose: Exit with 255 - * - * Return: void - * - * Programmer: Robb Matzke - * Monday, July 6, 1998 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -static void -fpe_handler(int UNUSED signo) -{ - SKIPPED(); - puts(" Test skipped due to SIGFPE."); -#ifndef HANDLE_SIGFPE - puts(" Remaining tests could not be run."); - puts(" Please turn off SIGFPE on overflows and try again."); -#endif - exit(255); -} - - -/*------------------------------------------------------------------------- - * Function: overflow_handler - * - * Purpose: Gets called for all data type conversion overflows. - * - * Return: Success: 0 - * - * Failure: -1 - * - * Programmer: Robb Matzke - * Tuesday, July 7, 1998 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -#ifdef SHOW_OVERFLOWS -static herr_t -overflow_handler(hid_t UNUSED src_id, hid_t UNUSED dst_id, - void UNUSED *src_buf, void UNUSED *dst_buf) -{ - noverflows_g++; - return -1; -} -#endif - /*------------------------------------------------------------------------- * Function: test_classes * * Purpose: Test type classes * - * Return: Success: 0 - * - * Failure: number of errors + * Return: None. * * Programmer: Binh-Minh Ribler (using C version) * January, 2007 @@ -197,27 +102,27 @@ overflow_handler(hid_t UNUSED src_id, hid_t UNUSED dst_id, * *------------------------------------------------------------------------- */ -static void test_classes(void) +static void test_classes() { SUBTEST("PredType::getClass()"); try { + int curr_nerrors = GetTestNumErrs(); + // PredType::NATIVE_INT should be in H5T_INTEGER class H5T_class_t tcls = PredType::NATIVE_INT.getClass(); if (H5T_INTEGER!=tcls) { - H5_FAILED(); puts(" Invalid type class for H5T_NATIVE_INT"); } // PredType::NATIVE_DOUBLE should be in H5T_FLOAT class tcls = PredType::NATIVE_DOUBLE.getClass(); if (H5T_FLOAT!=tcls) { - H5_FAILED(); - puts(" Invalid type class for H5T_NATIVE_DOUBLE"); + verify_val(tcls, H5T_FLOAT, "test_class: invalid type class for NATIVE_DOUBLE -", __LINE__, __FILE__); } PASSED(); } // end of try block - catch (DataTypeIException E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + catch (Exception E) { + issue_fail_msg("test_classes", __LINE__, __FILE__, E.getCDetailMsg()); } } @@ -237,12 +142,11 @@ static void test_classes(void) * *------------------------------------------------------------------------- */ -static void test_copy(void) +static void test_copy() { hid_t a_copy; herr_t status; - //MESSAGE(5, ("DataType::copy() and DataType::operator=")); SUBTEST("DataType::copy() and DataType::operator="); try { // Test copying from a predefined datatype using DataType::operator= @@ -275,8 +179,8 @@ static void test_copy(void) PASSED(); } - catch (DataTypeIException E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + catch (Exception E) { + issue_fail_msg("test_copy", __LINE__, __FILE__, E.getCDetailMsg()); } } @@ -301,7 +205,7 @@ static void test_copy(void) const H5std_string CompT_NAME("Compound_type"); const H5std_string EnumT_NAME("Enum_type"); -static void test_query(void) +static void test_query() { typedef struct { int a; @@ -316,10 +220,10 @@ static void test_query(void) SUBTEST("Query functions of compound and enumeration types"); try { - /* Create File */ + // Create File H5File file(FILENAME[2], H5F_ACC_TRUNC); - /* Create a compound datatype */ + // Create a compound datatype CompType tid1(sizeof(s_type_t)); tid1.insertMember("a", HOFFSET(s_type_t, a), PredType::NATIVE_INT); @@ -327,7 +231,7 @@ static void test_query(void) tid1.insertMember("c", HOFFSET(s_type_t, c), PredType::NATIVE_LONG); tid1.insertMember("d", HOFFSET(s_type_t, d), PredType::NATIVE_DOUBLE); - /* Create a enumerate datatype */ + // Create a enumerate datatype EnumType tid2(sizeof(short)); tid2.insert("RED", (enum_val=0,&enum_val)); @@ -336,56 +240,53 @@ static void test_query(void) tid2.insert("ORANGE", (enum_val=3,&enum_val)); tid2.insert("YELLOW", (enum_val=4,&enum_val)); - /* Query member number and member index by name, for compound type */ + // Query member number and member index by name, for compound type int nmembs = tid1.getNmembers(); verify_val(nmembs, 4, "CompType::getNmembers()", __LINE__, __FILE__); int index = tid1.getMemberIndex("c"); verify_val(index, 2, "CompType::getMemberIndex()", __LINE__, __FILE__); - /* Query member number and member index by name, for enumeration type. */ + // Query member number and member index by name, for enumeration type. nmembs = tid2.getNmembers(); verify_val(nmembs, 5, "EnumType::getNmembers()", __LINE__, __FILE__); index = tid2.getMemberIndex("ORANGE"); verify_val(index, 3, "EnumType::getMemberIndex()", __LINE__, __FILE__); - /* Commit compound datatype and close it */ + // Commit compound datatype and close it tid1.commit(file, CompT_NAME); tid1.close(); - /* Commit enumeration datatype and close it */ + // Commit enumeration datatype and close it tid2.commit(file, EnumT_NAME); tid2.close(); - /* Open the datatype for query */ + // Open the datatypes for query tid1 = file.openCompType(CompT_NAME); - tid2 = file.openEnumType(EnumT_NAME); - /* Query member number and member index by name, for compound type */ + // Query member number and member index by name, for compound type nmembs = tid1.getNmembers(); verify_val(nmembs, 4, "CompType::getNmembers()", __LINE__, __FILE__); - index = tid1.getMemberIndex("c"); verify_val(index, 2, "CompType::getMemberIndex()", __LINE__, __FILE__); - /* Query member number and member index by name, for enumeration type */ + // Query member number and member index by name, for enumeration type nmembs = tid2.getNmembers(); verify_val(nmembs, 5, "EnumType::getNmembers()", __LINE__, __FILE__); - index = tid2.getMemberIndex("ORANGE"); verify_val(index, 3, "EnumType::getMemberIndex()", __LINE__, __FILE__); - /* Close data types and file */ + // Close datatypes and file tid1.close(); tid2.close(); file.close(); - PASSED(); + PASSED(); } // end of try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_query", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_query @@ -393,7 +294,7 @@ static void test_query(void) /*------------------------------------------------------------------------- * Function: test_transient * - * Purpose: Tests transient data types. + * Purpose: Tests transient datatypes. * * Return: Success: 0 * @@ -411,67 +312,50 @@ static void test_transient () { static hsize_t ds_size[2] = {10, 20}; - //MESSAGE(5, ("transient data types")); - SUBTEST("Transient data types"); + SUBTEST("Transient datatypes"); try { + // Create the file and the dataspace. H5File file(filename1, H5F_ACC_TRUNC); DataSpace space(2, ds_size, ds_size); - /* Predefined types cannot be modified or closed */ -// PredType::NATIVE_INT is a constant and cannot make a call, don't need these tests - - /* Copying a predefined type results in a modifiable copy */ + // Copying a predefined type results in a modifiable copy IntType type(PredType::NATIVE_INT); type.setPrecision(256); - /* It should not be possible to create an attribute for a transient type */ + // It should not be possible to create an attribute for a transient type try { Attribute attr(type.createAttribute("attr1", PredType::NATIVE_INT, space)); // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("H5Object::createAttribute", "Attempted to commit a predefined datatype."); - } catch (AttributeIException err) {} + } catch (AttributeIException err) {} // do nothing, failure expected - /* Create a dataset from a transient data type */ -// type.close(); - put printf in H5Tclose to make sure it's closed + // Create a dataset from a transient datatype + // type.close(); - put trace in H5Tclose to make sure it's closed type.copy(PredType::NATIVE_INT); DataSet dset(file.createDataSet("dset1", type, space)); - /* The type returned from a dataset should not be modifiable */ + // The type returned from a dataset should not be modifiable IntType itype(dset); try { itype.setPrecision(256); // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("PredType::setPrecision", "Dataset data types should not be modifiable!"); + throw InvalidActionException("PredType::setPrecision", "Dataset datatypes should not be modifiable!"); } catch (DataTypeIException err) {} - itype.close(); - /* - * Get the dataset data type by applying H5Tcopy() to the dataset. The - * result should be modifiable. - */ + // Get a copy of the dataset's datatype by applying DataType::copy() + // to the dataset. The resulted datatype should be modifiable. itype.copy(dset); itype.setPrecision(256); + itype.close(); - /* - * Close the dataset and reopen it, testing that its type is still - * read-only. <--- how come modifiable below? - */ + // Close the dataset and reopen it, testing that its type is still + // read-only. (Note that a copy of it is modifiable.) dset.close(); - //if (H5Dclose (dset)<0) printf("goto error in C\n"); dset = file.openDataSet("dset1"); - //if ((dset=H5Dopen (file, "dset1"))<0) printf("goto error in C\n"); - /* - * Get the dataset data type by applying H5Tcopy() to the dataset. The - * result should be modifiable. - */ - itype.copy(dset); - itype.setPrecision(256); - itype.close(); - // Close objects and file. dset.close(); file.close(); @@ -480,7 +364,7 @@ static void test_transient () PASSED(); } // end of try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_transient", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_transient @@ -488,7 +372,7 @@ static void test_transient () /*------------------------------------------------------------------------- * Function: test_named * - * Purpose: Tests named data types. + * Purpose: Tests named datatypes. * * Return: Success: 0 * @@ -510,133 +394,69 @@ static void test_named () unsigned attr_data[10][20]; char filename[1024]; - //MESSAGE(5, ("named data types")); - SUBTEST("Named data types"); + SUBTEST("Named datatypes"); try { - -// h5_fixname(FILENAME[1], fapl_id, filename, sizeof filename); + // Create the file. H5File file(filename2, H5F_ACC_TRUNC); + // Create a simple dataspace. DataSpace space(2, ds_size, ds_size); - /* Predefined types cannot be committed */ + // Predefined types cannot be committed. try { -PredType nativeint(PredType::NATIVE_INT); -nativeint.commit(file, "test_named_1 (should not exist)"); - //PredType::NATIVE_INT.commit(file, "test_named_1 (should not exist)"); + PredType nativeint(PredType::NATIVE_INT); + nativeint.commit(file, "test_named_1 (should not exist)"); + // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("PredType::commit", "Attempted to commit a predefined datatype."); } catch (DataTypeIException err) {} -/* - H5E_BEGIN_TRY { - status = H5Tcommit (file, "test_named_1 (should not exist)", - H5T_NATIVE_INT); - } H5E_END_TRY; - if (status>=0) { - H5_FAILED(); - puts (" Predefined types should not be committable!"); - printf("goto error in C\n"); - } -*/ - - /* Copy a predefined data type and commit the copy */ + // Copy a predefined datatype and commit the copy. IntType itype(PredType::NATIVE_INT); - //if ((type = H5Tcopy (H5T_NATIVE_INT))<0) printf("goto error in C\n"); - itype.commit(file, "native-int"); - //if (H5Tcommit (file, "native-int", type)<0) printf("goto error in C\n");0, + // Check that it is committed. if (itype.committed() <= 0) cerr << "IntType::committed() returned false" << endl; - -/* - if ((status=H5Tcommitted (type))<0) printf("goto error in C\n"); - if (0==status) { - H5_FAILED(); - puts (" H5Tcommitted() returned false!"); - printf("goto error in C\n"); - } -*/ - /* We should not be able to modify a type after it has been committed. */ + // We should not be able to modify a type after it has been committed. try { - itype.setPrecision(256); + itype.setPrecision(256); // attempt an invalid action... // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("IntType::setPrecision", "Attempted to modify a committed datatype."); } catch (DataTypeIException err) {} -/* - H5E_BEGIN_TRY { - status = H5Tset_precision (type, 256); - } H5E_END_TRY; - if (status>=0) { - H5_FAILED(); - puts (" Committed type is not constant!"); - printf("goto error in C\n"); - } -*/ - /* We should not be able to re-commit a committed type */ + // We should not be able to re-commit a committed type try { itype.commit(file, "test_named_2 (should not exist)"); // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("IntType::commit", "Attempted to re-commit a committed data type."); - } catch (DataTypeIException err) {} - -/* - H5E_BEGIN_TRY { - status = H5Tcommit(file, "test_named_2 (should not exist)", type); - } H5E_END_TRY; - if (status>=0) { - H5_FAILED(); - puts (" Committed types should not be recommitted!"); - printf("goto error in C\n"); - } -*/ + throw InvalidActionException("IntType::commit", "Attempted to re-commit a committed datatype."); + } catch (DataTypeIException err) {} // do nothing, failure expected - /* It should be possible to define an attribute for the named type */ + // It should be possible to define an attribute for the named type Attribute attr1 = itype.createAttribute("attr1", PredType::NATIVE_UCHAR, space); - //if ((attr1=H5Acreate (type, "attr1", H5T_NATIVE_UCHAR, space, -// H5P_DEFAULT))<0) printf("goto error in C\n"); - - - for (i=0; i<ds_size[0]*ds_size[1]; i++) attr_data[0][i] = (int)i;/*tricky*/ - + for (i=0; i<ds_size[0]*ds_size[1]; i++) + attr_data[0][i] = (int)i;/*tricky*/ attr1.write(PredType::NATIVE_UINT, attr_data); attr1.close(); - //if (H5Awrite(attr1, H5T_NATIVE_UINT, attr_data)<0) printf("goto error in C\n"); - //if (H5Aclose (attr1)<0) printf("goto error in C\n"); - /* - * Copying a committed type should result in a transient type which is - * not locked. - */ + // Copying a committed type should result in a transient type which is + // not locked. IntType trans_type; trans_type.copy(itype); bool iscommitted = trans_type.committed(); verify_val(iscommitted, 0, "DataType::committed() - Copying a named type should result in a transient type!", __LINE__, __FILE__); -/* - if ((t2 = H5Tcopy (type))<0) printf("goto error in C\n"); - if ((status=H5Tcommitted (t2))<0) printf("goto error in C\n"); - if (status) { - H5_FAILED(); - puts (" Copying a named type should result in a transient type!"); - printf("goto error in C\n"); - } -*/ trans_type.setPrecision(256); trans_type.close(); - //if (H5Tset_precision (t2, 256)<0) printf("goto error in C\n"); - //if (H5Tclose (t2)<0) printf("goto error in C\n"); /* * Close the committed type and reopen it. It should return a named type. - */ -/* This had something to do with the way IntType was returned and assigned +* This had something to do with the way IntType was returned and assigned and caused itype.committed not working correctly. So, use another_type for now. + itype.close(); itype = file.openIntType("native-int"); iscommitted = itype.committed(); */ @@ -645,139 +465,68 @@ now. if (!iscommitted) throw InvalidActionException("IntType::committed()", "Opened named types should be named types!"); -/* - if (H5Tclose (type)<0) printf("goto error in C\n"); - if ((type=H5Topen (file, "native-int"))<0) printf("goto error in C\n"); - if ((status=H5Tcommitted (type))<0) printf("goto error in C\n"); - if (!status) { - H5_FAILED(); - puts (" Opened named types should be named types!"); - printf("goto error in C\n"); - } - */ - /* Create a dataset that uses the named type */ - DataSet dset = file.createDataSet("dset1", itype, space); - //if ((dset = H5Dcreate (file, "dset1", type, space, H5P_DEFAULT))<0) - - /* Get the dataset's data type and make sure it's a named type */ + // Create a dataset that uses the named type, then get the dataset's + // datatype and make sure it's a named type. + DataSet dset = file.createDataSet("dset1", another_type, space); DataType *ds_type = new DataType(dset.getDataType()); iscommitted = ds_type->committed(); if (!iscommitted) throw InvalidActionException("IntType::committed()", "1 Dataset type should be named type!"); - -/* - if ((t2 = H5Dget_type (dset))<0) printf("goto error in C\n"); - if ((status=H5Tcommitted (t2))<0) printf("goto error in C\n"); - if (!status) { - H5_FAILED(); - puts (" Dataset type should be a named type!"); - printf("goto error in C\n"); - } -*/ - - /* Close the dataset, then close its type, then reopen the dataset */ dset.close(); ds_type->close(); - //if (H5Dclose (dset)<0) printf("goto error in C\n"); - //if (H5Tclose (t2)<0) printf("goto error in C\n"); + // Reopen the dataset and its type, then make sure the type is + // a named type. dset = file.openDataSet("dset1"); - //if ((dset = H5Dopen (file, "dset1"))<0) printf("goto error in C\n"); - - /* Get the dataset's type and make sure it's named */ - /* Get the dataset's data type and make sure it's a named type */ ds_type = new DataType(dset.getDataType()); iscommitted = ds_type->committed(); if (!iscommitted) throw InvalidActionException("IntType::committed()", "Dataset type should be named type!"); -/* - if ((t2 = H5Dget_type (dset))<0) printf("goto error in C\n"); - if ((status=H5Tcommitted (t2))<0) printf("goto error in C\n"); - if (!status) { - H5_FAILED(); - puts (" Dataset type should be a named type!"); - printf("goto error in C\n"); - } -*/ - /* - * Close the dataset and create another with the type returned from the - * first dataset. - */ + // Close the dataset and create another with the type returned from + // the first dataset. dset.close(); - //if (H5Dclose (dset)<0) printf("goto error in C\n"); dset = file.createDataSet("dset2", *ds_type, space); - //if ((dset=H5Dcreate (file, "dset2", t2, space, H5P_DEFAULT))<0) - - /* Reopen the second dataset and make sure the type is shared */ ds_type->close(); dset.close(); + + // Reopen the second dataset and make sure the type is shared dset = file.openDataSet("dset2"); ds_type = new DataType(dset.getDataType()); iscommitted = ds_type->committed(); if (!iscommitted) - throw InvalidActionException("IntType::committed()", "Dataset type should be named type!"); - -/* - if (H5Tclose (t2)<0) printf("goto error in C\n"); - if (H5Dclose (dset)<0) printf("goto error in C\n"); - if ((dset = H5Dopen (file, "dset2"))<0) printf("goto error in C\n"); - if ((t2 = H5Dget_type (dset))<0) printf("goto error in C\n"); - if ((status=H5Tcommitted (t2))<0) printf("goto error in C\n"); - if (!status) { - H5_FAILED(); - puts (" Dataset type should be a named type!"); - printf("goto error in C\n"); - } -*/ + throw InvalidActionException("DataType::iscommitted()", "Dataset type should be named type!"); ds_type->close(); - //if (H5Tclose (t2)<0) printf("goto error in C\n"); - /* - * Get the dataset data type by applying H5Tcopy() to the dataset. The - * result should be modifiable. - */ - //DataType copied_type = dset.copyType(); + // Get the dataset datatype by applying DataType::copy() to the + // dataset. The resulted datatype should be modifiable. IntType copied_type; copied_type.copy(dset); - //if ((t2=H5Tcopy (dset))<0) printf("goto error in C\n"); - -// find another function that can be in DataType copied_type.setPrecision(256); -// if (H5Tset_precision (t2, 256)<0) printf("goto error in C\n"); - //copied_type.close(); copied_type.close(); - //if (H5Tclose (t2)<0) printf("goto error in C\n"); - /* Clean up */ + // Clean up dset.close(); itype.close(); space.close(); file.close(); -/* - if (H5Dclose (dset)<0) printf("goto error in C\n"); - if (H5Tclose (type)<0) printf("goto error in C\n"); - if (H5Sclose (space)<0) printf("goto error in C\n"); - if (H5Fclose (file)<0) printf("goto error in C\n"); -*/ - PASSED(); + PASSED(); } // end of try block catch (Exception E) { -cerr << "all the way here?" << endl; - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_named", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_named /**************************************************************** ** -** test_types(): Main data types testing routine. +** test_types(): Main datatypes testing routine. ** ****************************************************************/ #ifdef __cplusplus extern "C" #endif -void test_types(void) +void test_types() { // Output message about test being performed MESSAGE(5, ("Testing Generic Data Types\n")); @@ -806,8 +555,10 @@ void test_types(void) * *------------------------------------------------------------------------- */ -void -cleanup_types(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_types() { for (int i = 0; i < 3; i++) HDremove(FILENAME[i]); diff --git a/c++/test/tvlstr.cpp b/c++/test/tvlstr.cpp index b1815a3..469e861 100644 --- a/c++/test/tvlstr.cpp +++ b/c++/test/tvlstr.cpp @@ -13,13 +13,14 @@ * access to either file, you may request a copy from help@hdfgroup.org. * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/*********************************************************** -* -* Test program: tvlstr -* -* Test the variable length string functionality -* -*************************************************************/ +/***************************************************************************** + FILE + tvlstr.cpp - HDF5 C++ testing the Variable-Length String functionality + + EXTERNAL ROUTINES/VARIABLES: + These routines are in the test directory of the C library: + + ***************************************************************************/ #ifdef OLD_HEADER_FILENAME #include <iostream.h> @@ -44,31 +45,14 @@ using namespace H5; #include "h5cpputil.h" // C++ utilility header file -const H5std_string DATAFILE("tvlstr.h5"); -const H5std_string DATAFILE2("tvlstr2.h5"); +// Data file used in most test functions +const H5std_string FILENAME("tvlstr.h5"); // 1-D dataset with fixed dimensions const int SPACE1_RANK = 1; const hsize_t SPACE1_DIM1 = 4; -// 2-D dataset with fixed dimensions -const int SPACE2_RANK = 2; -const hsize_t SPACE2_DIM1 = 10; -const hsize_t SPACE2_DIM2 = 10; - -const H5std_string VLSTR_TYPE("vl_string_type"); - -// Definitions for the VL re-writing test -const int REWRITE_NDATASETS = 32; - -/*********************************************************** -* -* Test program: tvlstr -* -* Test the Variable-Length String functionality -* -*************************************************************/ - +// Utility functions void *test_vlstr_alloc_custom(size_t size, void *info); void test_vlstr_free_custom(void *mem, void *info); @@ -77,7 +61,9 @@ void test_vlstr_free_custom(void *mem, void *info); ** test_vlstr_alloc_custom(): Test VL datatype custom memory ** allocation routines. This routine just uses malloc to ** allocate the memory and increments the amount of memory -** allocated. +** allocated. It is passed into setVlenMemManager. +** +** Note: exact copy from the C version. ** ****************************************************************/ void *test_vlstr_alloc_custom(size_t size, void *info) @@ -106,7 +92,9 @@ void *test_vlstr_alloc_custom(size_t size, void *info) ** test_vlstr_free_custom(): Test VL datatype custom memory ** allocation routines. This routine just uses free to ** release the memory and decrements the amount of memory -** allocated. +** allocated. It is passed into setVlenMemManager. +** +** Note: exact copy from the C version. ** ****************************************************************/ void test_vlstr_free_custom(void *_mem, void *info) @@ -129,14 +117,19 @@ void test_vlstr_free_custom(void *_mem, void *info) } // end if } -/**************************************************************** -** -** test_vlstrings_basic(): Test basic VL string code. -** Tests simple VL string I/O -** -****************************************************************/ -static void -test_vlstrings_basic(void) +/*------------------------------------------------------------------------- + * Function: test_vlstrings_basic + * + * Purpose: Test simple VL string I/O. + * + * Return: None + * + * Programmer: Binh-Minh Ribler (use C version) + * January, 2007 + * + *------------------------------------------------------------------------- + */ +static void test_vlstrings_basic() { const char *wdata[SPACE1_DIM1]= { "Four score and seven years ago our forefathers brought forth on this continent a new nation,", @@ -146,12 +139,12 @@ test_vlstrings_basic(void) }; // Information to write // Output message about test being performed - MESSAGE(5, ("Testing Basic VL String Functionality\n")); + SUBTEST("Testing Basic VL String Functionality"); H5File* file1 = NULL; try { // Create file. - file1 = new H5File (DATAFILE, H5F_ACC_TRUNC); + file1 = new H5File (FILENAME, H5F_ACC_TRUNC); // Create dataspace for datasets. hsize_t dims1[] = {SPACE1_DIM1}; @@ -160,36 +153,35 @@ test_vlstrings_basic(void) // Create a datatype to refer to. StrType tid1(0, H5T_VARIABLE); - // Create a dataset. + // Create and write a dataset. DataSet dataset(file1->createDataSet("Dataset1", tid1, sid1)); - - // Write dataset to disk. dataset.write(wdata, tid1); // Create H5S_SCALAR data space. - DataSpace dataspace; - - DataSet dataset2(file1->createDataSet("Dataset2", tid1, dataspace)); + DataSpace scalar_space; + // Create and write another dataset. + DataSet dataset2(file1->createDataSet("Dataset2", tid1, scalar_space)); char *wdata2 = (char*)HDcalloc(65534, sizeof(char)); HDmemset(wdata2, 'A', 65533); - dataset2.write(&wdata2, tid1); - dataspace.close(); + // Release resources from second dataset operation. + scalar_space.close(); dataset2.close(); HDfree(wdata2); - // Change to the custom memory allocation routines for reading VL string. + // Change to the custom memory allocation routines for reading + // VL string. DSetMemXferPropList xfer; - int mem_used=0; // Memory used during allocation + int mem_used = 0; // Memory used during allocation xfer.setVlenMemManager(test_vlstr_alloc_custom, &mem_used, test_vlstr_free_custom, &mem_used); // Make certain the correct amount of memory will be used. hsize_t vlsize = dataset.getVlenBufSize(tid1, sid1); // Count the actual number of bytes used by the strings. - int str_used; // String data in memory + int str_used; // String data in memory hsize_t i; // counting variable for (i=0,str_used=0; i<SPACE1_DIM1; i++) str_used+=HDstrlen(wdata[i])+1; @@ -198,20 +190,22 @@ test_vlstrings_basic(void) verify_val((int)vlsize,str_used,"DataSet::getVlenBufSize", __LINE__, __FILE__); // Read dataset from disk. - char *rdata[SPACE1_DIM1]; // Information read in + char *rdata[SPACE1_DIM1]; // Data read in dataset.read(rdata, tid1, DataSpace::ALL, DataSpace::ALL, xfer); // Make certain the correct amount of memory has been used. - VERIFY(mem_used, str_used, "H5Dread"); + verify_val(mem_used, str_used, "DataSet::read", __LINE__, __FILE__); // Compare data read in. 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])); + int wlen = HDstrlen(wdata[i]); + int rlen = HDstrlen(rdata[i]); + if(wlen != rlen) { + TestErrPrintf("VL data lengths don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n", (int)i, wlen, (int)i, rlen); 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]); + 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 @@ -220,7 +214,7 @@ test_vlstrings_basic(void) DataSet::vlenReclaim((void *)rdata, tid1, sid1, xfer); // Make certain the VL memory has been freed. - VERIFY(mem_used, 0, "DataSet::vlenReclaim"); + verify_val(mem_used, 0, "DataSet::vlenReclaim", __LINE__, __FILE__); // Close objects and file. dataset.close(); @@ -228,36 +222,44 @@ test_vlstrings_basic(void) sid1.close(); xfer.close(); file1->close(); + + PASSED(); } // end try // Catch all exceptions. catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vlstrings_basic()", __LINE__, __FILE__, E.getCDetailMsg()); if (file1 != NULL) // clean up delete file1; } } // end test_vlstrings_basic() -/**************************************************************** -** -** test_vlstrings_special(): Test VL string code for special -** string cases, nil and zero-sized. -** -****************************************************************/ -static void -test_vlstrings_special(void) +/*------------------------------------------------------------------------- + * Function: test_vlstrings_special + * + * Purpose: Test VL string code for special string cases, nil and + * zero-sized. + * + * Return: None + * + * Programmer: Binh-Minh Ribler (use C version) + * January, 2007 + * + *------------------------------------------------------------------------- + */ +static void test_vlstrings_special() { const char *wdata[SPACE1_DIM1] = {"one", "two", "", "four"}; const char *wdata2[SPACE1_DIM1] = {NULL, NULL, NULL, NULL}; char *rdata[SPACE1_DIM1]; // Information read in // Output message about test being performed. - MESSAGE(5, ("Testing Special VL Strings\n")); + SUBTEST("Testing Special VL Strings"); try { // Create file. - H5File file1(DATAFILE, H5F_ACC_TRUNC); + H5File file1(FILENAME, H5F_ACC_TRUNC); // Create dataspace for datasets. hsize_t dims1[] = {SPACE1_DIM1}; @@ -269,29 +271,29 @@ test_vlstrings_special(void) // Create a dataset. DataSet dataset(file1.createDataSet("Dataset3", tid1, sid1)); - // Read from dataset before writing data. + // Read from the dataset before writing data. dataset.read(rdata, tid1); // Check data read in. hsize_t i; // counting variable for (i=0; i<SPACE1_DIM1; i++) - if(rdata[i]!=NULL) + if(rdata[i] != NULL) TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i,rdata[i]); - // Write dataset to disk. + // Write dataset to disk, then read it back. dataset.write(wdata, tid1); - - // Read dataset from disk. dataset.read(rdata, tid1); // Compare data read in. 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])); + int wlen = HDstrlen(wdata[i]); + int rlen = HDstrlen(rdata[i]); + if(wlen != rlen) { + TestErrPrintf("VL data lengths don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n", (int)i, wlen, (int)i, rlen); 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]); + 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 @@ -302,13 +304,15 @@ test_vlstrings_special(void) // Close Dataset. dataset.close(); - // Create another dataset to test nil strings. - DSetCreatPropList dcpl; + /* + * Create another dataset to test nil strings. + */ - // Set the fill value for the second dataset. + // Create the property list and set the fill value for the second + // dataset. + DSetCreatPropList dcpl; char *fill = NULL; // Fill value dcpl.setFillValue(tid1, &fill); - dataset = file1.createDataSet("Dataset4", tid1, sid1, dcpl); // Close dataset creation property list. @@ -319,8 +323,8 @@ test_vlstrings_special(void) // Check data read in. for (i=0; i<SPACE1_DIM1; i++) - if(rdata[i]!=NULL) - TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i,rdata[i]); + if(rdata[i] != NULL) + TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)i, rdata[i]); // Try to write nil strings to disk. dataset.write(wdata2, tid1); @@ -338,6 +342,8 @@ test_vlstrings_special(void) tid1.close(); sid1.close(); file1.close(); + + PASSED(); } // end try // Catch all exceptions. @@ -347,32 +353,35 @@ test_vlstrings_special(void) } } // test_vlstrings_special -/**************************************************************** -** -** test_vlstring_type(): Test VL string type. -** Tests if VL string is treated as string. -** -****************************************************************/ -static void test_vlstring_type(void) +/*------------------------------------------------------------------------- + * Function: test_vlstring_type + * + * Purpose: Test if VL string is treated as string. + * + * Return: None + * + * Programmer: Binh-Minh Ribler (use C version) + * January, 2007 + * + *------------------------------------------------------------------------- + */ +const H5std_string VLSTR_TYPE("vl_string_type"); +static void test_vlstring_type() { - H5T_cset_t cset; - H5T_str_t pad; - herr_t ret; - // Output message about test being performed. - MESSAGE(5, ("Testing VL String type\n")); + SUBTEST("Testing VL String type"); H5File* file1 = NULL; try { // Open file. - file1 = new H5File(DATAFILE, H5F_ACC_RDWR); + file1 = new H5File(FILENAME, H5F_ACC_RDWR); // Create a datatype to refer to. StrType vlstr_type(PredType::C_S1); // Change padding and verify it. vlstr_type.setStrpad(H5T_STR_NULLPAD); - pad = vlstr_type.getStrpad(); + H5T_str_t pad = vlstr_type.getStrpad(); verify_val(pad, H5T_STR_NULLPAD, "StrType::getStrpad", __LINE__, __FILE__); // Convert to variable-length string. @@ -404,52 +413,51 @@ static void test_vlstring_type(void) file1->close(); // Open file. - file1 = new H5File(DATAFILE, H5F_ACC_RDWR); - - //fid = H5Fopen(DATAFILE.c_str(), H5F_ACC_RDWR, H5P_DEFAULT); + file1 = new H5File(FILENAME, H5F_ACC_RDWR); // Open the variable-length string datatype just created vlstr_type.setId((file1->openStrType(VLSTR_TYPE)).getId()); - //tid_vlstr = H5Topen(fid, VLSTR_TYPE.c_str()); // Verify character set and padding cset = vlstr_type.getCset(); verify_val(cset, H5T_CSET_ASCII, "StrType::getCset", __LINE__, __FILE__); - //cset = H5Tget_cset(tid_vlstr); pad = vlstr_type.getStrpad(); - //pad = H5Tget_strpad(tid_vlstr); verify_val(pad, H5T_STR_NULLPAD, "StrType::getStrpad", __LINE__, __FILE__); // Close datatype and file vlstr_type.close(); file1->close(); - } // end try + + PASSED(); + } // end try block // Catch all exceptions. catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vlstring_type()", __LINE__, __FILE__, E.getCDetailMsg()); } } // end test_vlstring_type() -/**************************************************************** -** -** test_compact_vlstring(): Test code for storing VL strings in -** compact datasets. -** -****************************************************************/ -static void -test_compact_vlstring(void) +/*------------------------------------------------------------------------- + * 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() { - const char *wdata[SPACE1_DIM1] = {"one", "two", "three", "four"}; - char *rdata[SPACE1_DIM1]; // Information read in - - // Output message about test being performed - MESSAGE(5, ("Testing VL Strings in compact dataset\n")); + // Output message about test being performed + SUBTEST("Testing VL Strings in compact dataset"); try { // Create file - H5File file1(DATAFILE, H5F_ACC_TRUNC); + H5File file1(FILENAME, H5F_ACC_TRUNC); // Create dataspace for datasets hsize_t dims1[] = {SPACE1_DIM1}; @@ -466,9 +474,11 @@ test_compact_vlstring(void) DataSet dataset(file1.createDataSet("Dataset5", tid1, sid1, plist)); // Write dataset to disk + const char *wdata[SPACE1_DIM1] = {"one", "two", "three", "four"}; dataset.write(wdata, tid1); // Read dataset from disk + char *rdata[SPACE1_DIM1]; // Information read in dataset.read(rdata, tid1); // Compare data read in @@ -493,21 +503,29 @@ test_compact_vlstring(void) sid1.close(); plist.close(); file1.close(); + + PASSED(); } // end try // Catch all exceptions. catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_compact_vlstrings()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compact_vlstrings -/**************************************************************** -** -** test_write_vl_string_attribute(): Test basic VL string code. -** Tests writing VL strings as attributes -** -****************************************************************/ +/*------------------------------------------------------------------------- + * Function: test_write_vl_string_attribute + * + * Purpose: Test writing VL strings as attributes. + * + * Return: None + * + * Programmer: Binh-Minh Ribler (use C version) + * January, 2007 + * + *------------------------------------------------------------------------- + */ // String for testing attributes static const char *string_att = "This is the string for the attribute"; static char *string_att_write=NULL; @@ -516,15 +534,14 @@ static char *string_att_write=NULL; const H5std_string ATTRSTR_NAME("String_attr"); const H5std_string ATTRSTR_DATA("String Attribute"); -static void -test_write_vl_string_attribute(void) +static void test_write_vl_string_attribute() { // Output message about test being performed - MESSAGE(5, ("Testing writing VL String as attributes\n")); + SUBTEST("Testing writing VL String as attributes"); try { // Open the file - H5File file1(DATAFILE, H5F_ACC_RDWR); + H5File file1(FILENAME, H5F_ACC_RDWR); // Create a datatype to refer to. StrType tid1(0, H5T_VARIABLE); @@ -564,16 +581,17 @@ test_write_vl_string_attribute(void) string_att_write = (char*)HDcalloc(8192, sizeof(char)); HDmemset(string_att_write, 'A', 8191); - // Write data to the attribute. + // Write data to the attribute, then read it back. gr_attr.write(tid1, &string_att_write); - gr_attr.read(tid1, &string_att_check); + // Verify data read. if(HDstrcmp(string_att_check,string_att_write)!=0) TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check); - HDfree(string_att_check); + gr_attr.close(); + // Open attribute ATTRSTR_NAME again. gr_attr = root.openAttribute(ATTRSTR_NAME); // The attribute string written is freed below, in the @@ -582,54 +600,58 @@ test_write_vl_string_attribute(void) // Close attribute and file gr_attr.close(); file1.close(); + + PASSED(); } // end try block // Catch all exceptions. catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_string_attr()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_string_attr() -/**************************************************************** -** -** test_read_vl_string_attribute(): Test basic VL string code. -** Tests reading VL strings from attributes -** -****************************************************************/ -static void test_read_vl_string_attribute(void) +/*------------------------------------------------------------------------- + * Function: test_read_vl_string_attribute + * + * Purpose: Test reading VL strings from attributes. + * + * Return: None + * + * Programmer: Binh-Minh Ribler (use C version) + * January, 2007 + * + *------------------------------------------------------------------------- + */ +static void test_read_vl_string_attribute() { - herr_t ret; - char *string_att_check; + + // Output message about test being performed + SUBTEST("Testing reading VL String as attributes"); try { // Open file - H5File file1(DATAFILE, H5F_ACC_RDONLY); + H5File file1(FILENAME, H5F_ACC_RDONLY); // Create a datatype to refer to. StrType tid1(0, H5T_VARIABLE); + // Open the root group and its attribute named ATTRSTR_NAME. Group root = file1.openGroup("/"); - Attribute att = root.openAttribute(ATTRSTR_NAME); // Test reading "normal" sized string attribute + char *string_att_check; att.read(tid1, &string_att_check); - if(HDstrcmp(string_att_check,ATTRSTR_DATA.c_str())!=0) TestErrPrintf("VL string attributes don't match!, string_att=%s, string_att_check=%s\n",ATTRSTR_DATA.c_str(),string_att_check); - HDfree(string_att_check); - - // Close this attribute. att.close(); // Test reading "large" sized string attribute att = root.openAttribute("test_scalar_large"); att.read(tid1, &string_att_check); - if(HDstrcmp(string_att_check,string_att_write)!=0) TestErrPrintf("VL string attributes don't match!, string_att_write=%s, string_att_check=%s\n",string_att_write,string_att_check); - HDfree(string_att_check); HDfree(string_att_write); // Free string allocated in test_write_vl_string_attribute @@ -638,16 +660,19 @@ static void test_read_vl_string_attribute(void) tid1.close(); root.close(); file1.close(); + + PASSED(); } // end try // Catch all exceptions. catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_read_vl_string_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_read_vl_string_attribute /* Helper routine for test_vl_rewrite() */ -static void write_scalar_dset(H5File& file, DataType& type, DataSpace& space, char *name, char *data) +static void write_scalar_dset(H5File& file, DataType& type, DataSpace& space, + char *name, char *data) { DataSet dset; try { @@ -664,7 +689,8 @@ static void write_scalar_dset(H5File& file, DataType& type, DataSpace& space, ch } /* Helper routine for test_vl_rewrite() */ -static void read_scalar_dset(H5File& file, DataType& type, DataSpace& space, char *name, char *data) +static void read_scalar_dset(H5File& file, DataType& type, DataSpace& space, + char *name, char *data) { char *data_read; DataSet dset; @@ -686,19 +712,30 @@ static void read_scalar_dset(H5File& file, DataType& type, DataSpace& space, cha } } -/**************************************************************** -** -** test_vl_rewrite(): Test basic VL string code. -** Tests I/O on VL strings when lots of objects in the file -** have been linked/unlinked. -** -****************************************************************/ -static void test_vl_rewrite(void) +/*------------------------------------------------------------------------- + * Function: test_vl_rewrite + * + * Purpose: Test I/O on VL strings when many objects in the file + * have been linked/unlinked. + * + * Return: None + * + * Programmer: Binh-Minh Ribler (use C version) + * January, 2007 + * + *------------------------------------------------------------------------- + */ +const H5std_string FILENAME2("tvlstr2.h5"); +const int REWRITE_NDATASETS = 32; +static void test_vl_rewrite() { + // Output message about test being performed + SUBTEST("Testing I/O on VL strings with link/unlink"); + try { // Create the files. - H5File file1(DATAFILE, H5F_ACC_TRUNC); - H5File file2(DATAFILE2, H5F_ACC_TRUNC); + H5File file1(FILENAME, H5F_ACC_TRUNC); + H5File file2(FILENAME2, H5F_ACC_TRUNC); // Create the VL string datatype. StrType type(0, H5T_VARIABLE); @@ -745,26 +782,35 @@ static void test_vl_rewrite(void) space.close(); file1.close(); file2.close(); + + PASSED(); } // end try // Catch all exceptions. catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vl_rewrite()", __LINE__, __FILE__, E.getCDetailMsg()); } } // end test_vl_rewrite() -/**************************************************************** -** -** test_vlstrings(): Main VL string testing routine. -** -****************************************************************/ +/*------------------------------------------------------------------------- + * Function: test_vlstrings + * + * Purpose: VL string testing main routine. + * + * Return: None + * + * Programmer: Binh-Minh Ribler + * January, 2007 + * + *------------------------------------------------------------------------- + */ #ifdef __cplusplus extern "C" #endif -void test_vlstrings(void) +void test_vlstrings() { // Output message about test being performed - MESSAGE(5, ("Testing Variable-Length Strings\n")); + MESSAGE(5, ("Testing Variable-Length Strings")); // These tests use the same file // Test basic VL string datatype @@ -797,10 +843,12 @@ void test_vlstrings(void) * *------------------------------------------------------------------------- */ -void -cleanup_vlstrings(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_vlstrings() { - HDremove(DATAFILE.c_str()); - HDremove(DATAFILE2.c_str()); + HDremove(FILENAME.c_str()); + HDremove(FILENAME2.c_str()); } |