diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2008-07-26 02:33:30 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2008-07-26 02:33:30 (GMT) |
commit | e37a8bb365d7940a86cdcf869fbbf4426d0eeb09 (patch) | |
tree | a1e28ea5c265e0a18b090ffbab407ac0fe075090 | |
parent | aff214baed310f7a8a25c7060397f33b32b87b4f (diff) | |
download | hdf5-e37a8bb365d7940a86cdcf869fbbf4426d0eeb09.zip hdf5-e37a8bb365d7940a86cdcf869fbbf4426d0eeb09.tar.gz hdf5-e37a8bb365d7940a86cdcf869fbbf4426d0eeb09.tar.bz2 |
[svn-r15409] Purpose: Clean up C++ tests
Description:
Cleaned up test formats, comments, messages, etc... for consistency.
Platforms tested:
Linux 2.6 (kagiso)
SunOS 5.10 (linew)
FreeBSD (duty)
-rw-r--r-- | c++/test/dsets.cpp | 40 | ||||
-rw-r--r-- | c++/test/h5cpputil.cpp | 37 | ||||
-rw-r--r-- | c++/test/h5cpputil.h | 38 | ||||
-rw-r--r-- | c++/test/tattr.cpp | 167 | ||||
-rw-r--r-- | c++/test/tcompound.cpp | 124 | ||||
-rw-r--r-- | c++/test/testhdf5.cpp | 4 | ||||
-rw-r--r-- | c++/test/tfile.cpp | 110 | ||||
-rw-r--r-- | c++/test/tfilter.cpp | 62 | ||||
-rw-r--r-- | c++/test/th5s.cpp | 93 | ||||
-rw-r--r-- | c++/test/trefer.cpp | 35 | ||||
-rw-r--r-- | c++/test/ttypes.cpp | 189 | ||||
-rw-r--r-- | c++/test/tvlstr.cpp | 248 |
12 files changed, 605 insertions, 542 deletions
diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp index be67035..2e79240 100644 --- a/c++/test/dsets.cpp +++ b/c++/test/dsets.cpp @@ -20,7 +20,6 @@ EXTERNAL ROUTINES/VARIABLES: These routines are in the test directory of the C library: - h5_reset() -- in h5test.c, resets the library by closing it h5_fileaccess() -- in h5test.c, returns a file access template ***************************************************************************/ @@ -43,7 +42,7 @@ #include "H5Cpp.h" // C++ API header file #ifndef H5_NO_NAMESPACE -using namespace H5; + using namespace H5; #endif #include "h5cpputil.h" // C++ utilility header file @@ -61,7 +60,6 @@ const int H5Z_FILTER_BOGUS = 305; // Local prototypes static size_t 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); /*------------------------------------------------------------------------- @@ -80,8 +78,7 @@ void cleanup_dsets(void); * *------------------------------------------------------------------------- */ -static herr_t -test_create( H5File& file) +static herr_t test_create( H5File& file) { TESTING("create, open, close"); @@ -173,7 +170,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) @@ -181,7 +178,6 @@ test_create( H5File& file) return -1; } } // test_create - /*------------------------------------------------------------------------- * Function: test_simple_io @@ -201,8 +197,7 @@ test_create( H5File& file) * *------------------------------------------------------------------------- */ -static herr_t -test_simple_io( H5File& file) +static herr_t test_simple_io( H5File& file) { TESTING("simple I/O"); @@ -286,8 +281,7 @@ test_simple_io( H5File& file) * *------------------------------------------------------------------------- */ -static herr_t -test_tconv( H5File& file) +static herr_t test_tconv( H5File& file) { // Prepare buffers for input/output char *out=NULL, *in=NULL; @@ -336,7 +330,7 @@ test_tconv( H5File& file) // clean up and return with success delete [] out; delete [] in; - cerr << " PASSED" << endl; + PASSED(); return 0; } // end try @@ -410,8 +404,7 @@ bogus(unsigned int flags, size_t cd_nelmts, * *------------------------------------------------------------------------- */ -static herr_t -test_compression(H5File& file) +static herr_t test_compression(H5File& file) { const char *not_supported; not_supported = " Deflate compression is not enabled."; @@ -698,8 +691,7 @@ test_compression(H5File& file) * *------------------------------------------------------------------------- */ -static herr_t -test_multiopen (H5File& file) +static herr_t test_multiopen (H5File& file) { TESTING("multi-open with extending"); @@ -780,8 +772,7 @@ test_multiopen (H5File& file) * *------------------------------------------------------------------------- */ -static herr_t -test_types(H5File& file) +static herr_t test_types(H5File& file) { TESTING("various datatypes"); @@ -975,11 +966,8 @@ test_types(H5File& file) * *------------------------------------------------------------------------- */ -int -main(void) +int main(void) { - h5_reset(); // in h5test.c, resets the library by closing it - hid_t fapl_id; fapl_id = h5_fileaccess(); // in h5test.c, returns a file access template @@ -1034,9 +1022,11 @@ main(void) * *------------------------------------------------------------------------- */ -void -cleanup_dsets(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_dsets(void) { - remove(FILE1.c_str()); + HDremove(FILE1.c_str()); } // cleanup_dsets diff --git a/c++/test/h5cpputil.cpp b/c++/test/h5cpputil.cpp index db5b75b..1d34d53 100644 --- a/c++/test/h5cpputil.cpp +++ b/c++/test/h5cpputil.cpp @@ -37,12 +37,13 @@ #include "h5test.h" #include "H5Cpp.h" // C++ API header file -#include "h5cpputil.h" #ifndef H5_NO_NAMESPACE -using namespace H5; + using namespace H5; #endif +#include "h5cpputil.h" + /*------------------------------------------------------------------------- * Function: test_report @@ -99,8 +100,8 @@ void issue_fail_msg(const char* where, int line, const char* file_name, { //if (GetTestVerbosity()>=VERBO_HI) { - cerr << "ERROR>>> From " << where << " at line " << line - << " in " << file_name << " - " << message << endl << endl; + cerr << ">>> FAILED in " << where << " at line " << line + << " in " << file_name << " - " << message << endl << endl; } } @@ -114,9 +115,9 @@ void issue_fail_msg(const char* where, int line, const char* file_name, * the test code. Where the C version of this code segment * "goto error," this function will return -1. * - * Return: Success: 0 + * Return: Success: 0 * - * Failure: -1 + * Failure: -1 * * Programmer: Binh-Minh Ribler (using C code segment for checking values) * Friday, February 6, 2001 @@ -146,7 +147,7 @@ InvalidActionException::InvalidActionException():Exception(){} // Function: InvalidActionException overloaded constructor // // Purpose: Creates an InvalidActionException with the name of the function, -// which the failure should have occurred but didn't, and a +// 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 @@ -159,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 eaeb4a9..a040aa0 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,25 +95,24 @@ 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" { +#endif void test_attr(void); void test_compound(void); void test_file(void); @@ -107,12 +125,18 @@ 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); void cleanup_reference(void); void cleanup_types(void); void cleanup_vlstrings(void); + +#ifdef __cplusplus +} +#endif + /* not yet void cleanup_select(void); void cleanup_time(void); diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index e5ceee6..46eb4f7 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -44,27 +44,21 @@ #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 */ +/* Attribute Names, Rank & Dimensions */ const H5std_string ATTR1_NAME("Attr1"); const int ATTR1_RANK = 1; const int ATTR1_DIM1 = 3; @@ -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(void) { 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(void) { 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(void) { 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,28 +358,28 @@ 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(void) { - // Output message about test being performed - MESSAGE(5, ("Testing Multiple Attribute Functions\n")); + // Output message about test being performed + SUBTEST("Testing Writing Compound Attribute Functions"); try { // Create file - H5File fid1(FILENAME.c_str(), H5F_ACC_TRUNC); + H5File fid1(FILENAME, H5F_ACC_TRUNC); // Create dataspace for dataset hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; @@ -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(void) { 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 Reading Compound 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(void) { // 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(void) { // 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(void) { // 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(void) { 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(void) { H5std_string attr_name; // Buffer for attribute names - // Output message about test being performed - MESSAGE(5, ("Testing Removing Attribute Function\n")); + // Output message about test being performed + 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(void) { 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 Attributes with Shared Datatypes"); try { // Create a file @@ -1142,12 +1146,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() /**************************************************************** ** @@ -1159,11 +1165,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(void) { // Output message about test being performed - MESSAGE(5, ("Testing Basic Attribute Writing Functions\n")); + SUBTEST("Testing String Attribute Functions"); try { // Create file @@ -1195,20 +1200,24 @@ 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() /**************************************************************** ** ** test_attr(): Main attribute testing routine. ** ****************************************************************/ -void -test_attr(void) +#ifdef __cplusplus +extern "C" +#endif +void test_attr(void) { // Output message about test being performed MESSAGE(5, ("Testing Attributes\n")); @@ -1231,7 +1240,7 @@ test_attr(void) test_string_attr(); // Test read/write string attribute -} /* test_attr() */ +} // test_attr() /*------------------------------------------------------------------------- * Function: cleanup_attr @@ -1247,9 +1256,11 @@ test_attr(void) * *------------------------------------------------------------------------- */ -void -cleanup_attr(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_attr(void) { - remove(FILENAME.c_str()); + HDremove(FILENAME.c_str()); } diff --git a/c++/test/tcompound.cpp b/c++/test/tcompound.cpp index 4811b68..33aac31 100644 --- a/c++/test/tcompound.cpp +++ b/c++/test/tcompound.cpp @@ -69,20 +69,18 @@ static void test_compound_1(void) { // 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) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_compound_1", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_1() @@ -121,9 +119,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 +137,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 +160,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,23 +185,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) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_compound_2", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_2() @@ -243,9 +238,8 @@ static void test_compound_3(void) // Output message about test being performed SUBTEST("Compound Datatype Subset Conversions"); - try - { - /* Initialize */ + 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)); orig = (unsigned char*)malloc(nelmts * sizeof(src_typ_t)); @@ -262,7 +256,7 @@ static void test_compound_3(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 @@ -283,10 +277,10 @@ static void test_compound_3(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; @@ -309,7 +303,7 @@ static void test_compound_3(void) } // if } // for - /* Release resources */ + // Release resources free(buf); free(bkg); free(orig); @@ -317,12 +311,11 @@ static void test_compound_3(void) d_ptr = NULL; st.close(); dt.close(); - PASSED(); } // end of try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_compound_3", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_3() @@ -366,9 +359,8 @@ static void test_compound_4(void) // Output message about test being performed SUBTEST("Compound Element Shrinking & 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)); @@ -385,7 +377,7 @@ static void test_compound_4(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 @@ -408,10 +400,10 @@ static void test_compound_4(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; @@ -437,7 +429,7 @@ static void test_compound_4(void) } // if } // for - /* Release resources */ + // Release resources free(buf); free(bkg); free(orig); @@ -445,12 +437,11 @@ static void test_compound_4(void) d_ptr = NULL; st.close(); dt.close(); - PASSED(); } // end of try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_compound_4", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_4() @@ -495,10 +486,8 @@ static void test_compound_5(void) // Output message about test being performed SUBTEST("Optimized Struct Converter"); - try - { - - /* Build datatypes */ + try { + // Build datatypes ArrayType* array_dt = new ArrayType(PredType::NATIVE_SHORT, 1, dims); CompType short_array(4*sizeof(short)); short_array.insertMember("_", 0, *array_dt); @@ -520,19 +509,19 @@ static void test_compound_5(void) dst_type.insertMember("tdim", HOFFSET(dst_typ_t, tdim), PredType::NATIVE_SHORT); dst_type.insertMember("coll_ids", HOFFSET(dst_typ_t, coll_ids), int_array); - /* Convert data */ + // Convert data memcpy(buf, src, sizeof(src)); src_type.convert(dst_type, (size_t)2, buf, bkg); dst = (dst_typ_t*)buf; - /* Cleanup */ + // Cleanup src_type.close(); dst_type.close(); strg.close(); short_array.close(); int_array.close(); - /* Check results */ + // Check results if (memcmp(src[1].name, dst[1].name, sizeof(src[1].name)) || src[1].tdim!=dst[1].tdim || src[1].coll_ids[0]!=dst[1].coll_ids[0] || @@ -541,7 +530,7 @@ static void test_compound_5(void) src[1].coll_ids[3]!=dst[1].coll_ids[3]) { H5_FAILED(); } - /* Free memory buffers */ + // Free memory buffers free(buf); free(bkg); dst = NULL; @@ -549,7 +538,7 @@ static void test_compound_5(void) } // end of try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_compound_5", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_5() @@ -590,9 +579,8 @@ static void test_compound_6(void) // Output message about test being performed SUBTEST("Compound Element Growing"); - 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)); @@ -603,7 +591,7 @@ static void test_compound_6(void) } memcpy(buf, orig, nelmts*sizeof(src_typ_t)); - /* Build hdf5 datatypes */ + // Build hdf5 datatypes CompType st(sizeof(src_typ_t)); st.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_SHORT); st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_SHORT); @@ -612,10 +600,10 @@ static void test_compound_6(void) dt.insertMember("b", HOFFSET(dst_typ_t, b), PredType::NATIVE_LONG); dt.insertMember("d", HOFFSET(dst_typ_t, d), PredType::NATIVE_LONG); - /* 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; @@ -631,7 +619,7 @@ static void test_compound_6(void) } // if } // for - /* Release resources */ + // Release resources free(buf); free(bkg); free(orig); @@ -639,12 +627,11 @@ static void test_compound_6(void) d_ptr = NULL; st.close(); dt.close(); - PASSED(); } // end of try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_compound_6", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_6() @@ -680,8 +667,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); @@ -697,22 +683,21 @@ static void test_compound_7(void) type_size = tid2.getSize(); verify_val_noteq(type_size, sizeof(s2_typ_t), "DataType::getSize", __LINE__, __FILE__); - /* Should not be able to insert field past end of compound datatype */ + // Should not be able to insert field past end of compound datatype try { tid2.insertMember("d", HOFFSET(s2_typ_t, d), PredType::NATIVE_DOUBLE); // Should FAIL but didn't, so throw an invalid action exception throw InvalidActionException("CompType::insertMember", "Attempted to insert field past end of compound data type."); } catch (DataTypeIException err) {} - /* Release resources */ + // Release resources tid1.close(); tid2.close(); - PASSED(); } // end of try block catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_compound_7", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_compound_7() @@ -731,6 +716,9 @@ static void test_compound_7(void) * *------------------------------------------------------------------------- */ +#ifdef __cplusplus +extern "C" +#endif void test_compound(void) { // Output message about test being performed @@ -757,7 +745,9 @@ void test_compound(void) * *------------------------------------------------------------------------- */ -void -cleanup_compound(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_compound(void) { } // cleanup_file diff --git a/c++/test/testhdf5.cpp b/c++/test/testhdf5.cpp index 65f17a0..d8b9533 100644 --- a/c++/test/testhdf5.cpp +++ b/c++/test/testhdf5.cpp @@ -95,6 +95,10 @@ main(int argc, char *argv[]) Comment out tests that are not done yet */ +/* Tentative - BMR 2007/1/12 + AddTest("datatypes", test_dtypes, cleanup_dtypes, "Data Types", NULL); + AddTest("enum", test_enum, cleanup_enum, "Enum Data Types", NULL); +*/ /* Display testing information */ TestInfo(argv[0]); diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp index f4aa6f4..a82f40d 100644 --- a/c++/test/tfile.cpp +++ b/c++/test/tfile.cpp @@ -19,7 +19,7 @@ EXTERNAL ROUTINES/VARIABLES: These routines are in the test directory of the C library: - h5_fileaccess() -- in h5test.c, returns a file access template + h5_fileaccess() -- in h5test.c, returns a file access template ***************************************************************************/ @@ -41,7 +41,7 @@ #include "H5Cpp.h" // C++ API header file #ifndef H5_NO_NAMESPACE -using namespace H5; + using namespace H5; #endif #include "h5cpputil.h" // C++ utilility header file @@ -94,7 +94,7 @@ const H5std_string FILE4("tfile4.h5"); * Return: None * * Programmer: Binh-Minh Ribler (use C version) - * January, 2001 + * January, 2001 * * Modifications: * January, 2005: C tests' macro VERIFY casts values to 'long' for all @@ -106,11 +106,10 @@ const H5std_string FILE4("tfile4.h5"); * *------------------------------------------------------------------------- */ -static void -test_file_create(void) +static void test_file_create(void) { // 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 @@ -182,7 +181,7 @@ test_file_create(void) hsize_t ublock = tmpl1.getUserblock(); verify_val((long)ublock, (long)F1_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); - size_t parm1, parm2; // file-creation parameters + size_t parm1, parm2; // file-creation parameters tmpl1.getSizes( parm1, parm2); verify_val(parm1, F1_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); verify_val(parm2, F1_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); @@ -205,17 +204,17 @@ test_file_create(void) catch (InvalidActionException E) { - cerr << " FAILED" << endl; - cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; - if (file1 != NULL) // clean up - delete file1; + cerr << " FAILED" << endl; + cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; + if (file1 != NULL) // clean up + delete file1; } // catch all other exceptions catch (Exception E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); - if (file1 != NULL) // clean up - delete file1; + issue_fail_msg("test_file_create()", __LINE__, __FILE__, E.getCDetailMsg()); + if (file1 != NULL) // clean up + delete file1; } // Setting this to NULL for cleaning up in failure situations @@ -291,11 +290,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; } @@ -310,7 +310,7 @@ test_file_create(void) * Return: None * * Programmer: Binh-Minh Ribler (use C version) - * January, 2001 + * January, 2001 * * Modifications: * January, 2005: C tests' macro VERIFY casts values to 'long' for all @@ -322,11 +322,10 @@ test_file_create(void) * *------------------------------------------------------------------------- */ -static void -test_file_open(void) +static void test_file_open(void) { // Output message about test being performed - MESSAGE(5, ("Testing File Opening I/O\n")); + SUBTEST("Testing File Opening I/O"); try { @@ -354,10 +353,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() @@ -370,44 +370,44 @@ test_file_open(void) * Return: None * * Programmer: Raymond Lu - * June, 2004 + * June, 2004 * * Modifications: * *------------------------------------------------------------------------- */ -static void -test_file_size(void) +static void test_file_size(void) { // 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 try { - // Use the file access template id to create a file access prop. - // list object to pass in H5File::H5File - FileAccPropList fapl(fapl_id); + // Use the file access template id to create a file access prop. + // list object to pass in H5File::H5File + FileAccPropList fapl(fapl_id); // Set to sec2 driver. Do we want to test other file drivers? - // They're not tested in C++. - // File drivers seem not implemented. + // They're not tested in C++. + // File drivers seem not implemented. // fapl.setSec2(); - // Create a file + // Create a file H5File file4( FILE4, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); - // Get file size - hsize_t file_size = file4.getFileSize(); + // Get file size + hsize_t file_size = file4.getFileSize(); - // 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__); + // 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__); + 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. @@ -424,7 +424,7 @@ test_file_size(void) * Return: None * * Programmer: Binh-Minh Ribler - * July, 2004 + * July, 2004 * * Modifications: * @@ -444,19 +444,18 @@ typedef struct s1_t { float b; } s1_t; -static void -test_file_name() +static void test_file_name(void) { // Output message about test being performed - MESSAGE(5, ("Testing File Name\n")); + SUBTEST("Testing File Name"); H5std_string file_name; try { - // Create a file using default properties. + // Create a file using default properties. H5File file4(FILE4, H5F_ACC_TRUNC); - // Get file name from the file instance. - file_name = file4.getFileName(); + // Get file name from the file instance. + file_name = file4.getFileName(); verify_val(file_name, FILE4, "H5File::getFileName", __LINE__, __FILE__); // Create a group in the root group @@ -497,10 +496,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() @@ -514,14 +514,16 @@ test_file_name() * Return: None * * Programmer: Binh-Minh Ribler (use C version) - * January 2001 + * January 2001 * * Modifications: * *------------------------------------------------------------------------- */ -void -test_file(void) +#ifdef __cplusplus +extern "C" +#endif +void test_file(void) { // Output message about test being performed MESSAGE(5, ("Testing File I/O operations\n")); @@ -546,11 +548,13 @@ test_file(void) * *------------------------------------------------------------------------- */ -void -cleanup_file(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_file(void) { - 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 9051bf4..2d072f5 100644 --- a/c++/test/tfilter.cpp +++ b/c++/test/tfilter.cpp @@ -72,35 +72,6 @@ const H5Z_class_t H5Z_BOGUS[1] = {{ filter_bogus, /* The actual filter function */ }}; -#ifndef H5_WANT_H5_V1_4_COMPAT -static herr_t can_apply_bogus(hid_t dcpl_id, hid_t type_id, hid_t space_id); - -/*------------------------------------------------------------------------- - * Function: can_apply_bogus - * - * Purpose: A bogus 'can apply' callback that returns 0 for H5T_NATIVE_DOUBLE - * dataype, but returns 1 for all other datatypes - * - * Return: Success: Described above - * Failure: 0 - * - * Programmer: Quincey Koziol - * Friday, April 5, 2003 - * - * Modifications: - * - *------------------------------------------------------------------------- - */ -static herr_t -can_apply_bogus(hid_t UNUSED dcpl_id, hid_t type_id, hid_t UNUSED space_id) -{ - if(H5Tequal(type_id,H5T_NATIVE_DOUBLE)) - return 0; - else - return 1; -} -#endif - /*------------------------------------------------------------------------- * Function: filter_bogus * @@ -147,10 +118,9 @@ const hsize_t chunk_size[2] = {FILTER_CHUNK_DIM1, FILTER_CHUNK_DIM2}; static void test_null_filter(void) { // Output message about test being performed - SUBTEST("'Null' filter"); + SUBTEST("Testing 'Null' Filter"); - try - { + try { //hsize_t null_size; // Size of dataset with null filter // Prepare dataset create property list @@ -181,7 +151,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 @@ -207,16 +177,15 @@ void test_szip_filter(H5File& file1) { #ifdef H5_HAVE_FILTER_SZIP int points[DSET_DIM1][DSET_DIM2], check[DSET_DIM1][DSET_DIM2]; - //hsize_t szip_size; /* Size of dataset with szip filter */ unsigned szip_options_mask=H5_SZIP_NN_OPTION_MASK; unsigned szip_pixels_per_block=4; // Output message about test being performed - SUBTEST("szip filter (with encoder)"); + SUBTEST("Testing 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 @@ -265,9 +234,9 @@ void test_szip_filter(H5File& file1) // 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(); } @@ -286,6 +255,9 @@ void test_szip_filter(H5File& file1) ** ****************************************************************/ const H5std_string FILE1("tfilters.h5"); +#ifdef __cplusplus +extern "C" +#endif void test_filters(void) { // Output message about test being performed @@ -294,8 +266,8 @@ void test_filters(void) hid_t fapl_id; fapl_id = h5_fileaccess(); // in h5test.c, returns a file access template - try - { + int nerrors=0; // keep track of number of failures occurr + try { // Use the file access template id to create a file access prop. list FileAccPropList fapl(fapl_id); @@ -307,7 +279,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() @@ -325,8 +297,10 @@ void test_filters(void) * *------------------------------------------------------------------------- */ -void -cleanup_filters(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_filters(void) { HDremove(FILE1.c_str()); } diff --git a/c++/test/th5s.cpp b/c++/test/th5s.cpp index 42ee6a2..57a8e91 100644 --- a/c++/test/th5s.cpp +++ b/c++/test/th5s.cpp @@ -40,7 +40,7 @@ #include "H5Cpp.h" // C++ API header file #ifndef H5_NO_NAMESPACE -using namespace H5; + using namespace H5; #endif #include "h5cpputil.h" // C++ utilility header file @@ -109,8 +109,7 @@ struct space4_struct { * with a special routine. *------------------------------------------------------------------------- */ -static void -test_h5s_basic(void) +static void test_h5s_basic(void) { hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; hsize_t dims2[] = {SPACE2_DIM1, SPACE2_DIM2, SPACE2_DIM3, @@ -119,11 +118,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 ); @@ -139,9 +136,10 @@ test_h5s_basic(void) verify_val(rank, SPACE1_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); // Retrieves dimension size of dataspace sid1 and verify it - int ndims; // Number of dimensions + int ndims; // Number of dimensions hsize_t tdims[4]; // Dimension array to test with ndims = sid1.getSimpleExtentDims( tdims ); + verify_val(ndims, SPACE1_RANK, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); verify_val(HDmemcmp(tdims, dims1, SPACE1_RANK * sizeof(unsigned)), 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); @@ -206,10 +204,7 @@ test_h5s_basic(void) catch( FileIException E ) // catching higher dimensionality dataset {} // do nothing, exception expected - // 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); @@ -230,7 +225,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) { @@ -240,7 +237,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() @@ -264,14 +261,12 @@ test_h5s_basic(void) * with a special routine. *------------------------------------------------------------------------- */ -static void -test_h5s_scalar_write(void) +static void test_h5s_scalar_write(void) { // 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); @@ -298,14 +293,15 @@ test_h5s_scalar_write(void) ext_type = sid1.getSimpleExtentType(); verify_val(ext_type, H5S_SCALAR, "DataSpace::getSimpleExtentType", __LINE__, __FILE__); - // Create a dataset + // 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() @@ -329,16 +325,14 @@ test_h5s_scalar_write(void) * with a special routine. *------------------------------------------------------------------------- */ -static void -test_h5s_scalar_read(void) +static void test_h5s_scalar_read(void) { 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); @@ -358,14 +352,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() @@ -391,14 +388,12 @@ test_h5s_scalar_read(void) * with a special routine. *------------------------------------------------------------------------- */ -static void -test_h5s_compound_scalar_write(void) +static void test_h5s_compound_scalar_write(void) { // 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); @@ -432,15 +427,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() @@ -465,15 +461,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(void) { 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); @@ -511,11 +505,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() @@ -533,8 +528,10 @@ test_h5s_compound_scalar_read(void) * Modifications: *------------------------------------------------------------------------- */ -void -test_h5s(void) +#ifdef __cplusplus +extern "C" +#endif +void test_h5s(void) { // Output message about test being performed MESSAGE(5, ("Testing Dataspaces\n")); @@ -561,9 +558,11 @@ test_h5s(void) * *------------------------------------------------------------------------- */ -void -cleanup_h5s(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_h5s(void) { - remove(DATAFILE.c_str()); + HDremove(DATAFILE.c_str()); } // cleanup_h5s diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp index b508ca7..3171138 100644 --- a/c++/test/trefer.cpp +++ b/c++/test/trefer.cpp @@ -76,14 +76,13 @@ typedef struct s1_t { ** Tests references to various kinds of objects ** ****************************************************************/ -static void -test_reference_obj(void) +static void test_reference_obj(void) { 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 { @@ -93,9 +92,9 @@ test_reference_obj(void) // Allocate write & read buffers int temp_size = MAX(sizeof(unsigned),sizeof(hobj_ref_t)); - wbuf=(hobj_ref_t*)malloc(temp_size*SPACE1_DIM1); - rbuf=(hobj_ref_t*)malloc(temp_size*SPACE1_DIM1); - tbuf=(hobj_ref_t*)malloc(temp_size*SPACE1_DIM1); + wbuf=(hobj_ref_t*)HDmalloc(temp_size*SPACE1_DIM1); + rbuf=(hobj_ref_t*)HDmalloc(temp_size*SPACE1_DIM1); + tbuf=(hobj_ref_t*)HDmalloc(temp_size*SPACE1_DIM1); // Create file FILE1 file1 = new H5File (FILE1, H5F_ACC_TRUNC); @@ -255,12 +254,14 @@ test_reference_obj(void) file1->close(); // Free memory buffers - free(wbuf); - free(rbuf); - free(tbuf); + HDfree(wbuf); + HDfree(rbuf); + HDfree(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() @@ -269,8 +270,10 @@ test_reference_obj(void) ** test_reference(): Main reference testing routine. ** ****************************************************************/ -void -test_reference(void) +#ifdef __cplusplus +extern "C" +#endif +void test_reference(void) { // Output message about test being performed MESSAGE(5, ("Testing References\n")); @@ -285,9 +288,11 @@ test_reference(void) ** Purpose: Cleanup temporary test files ** Return: none ****************************************************************/ -void -cleanup_reference(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_reference(void) { - remove(FILE1.c_str()); + HDremove(FILE1.c_str()); } diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp index 06ed367..fb85406 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 ***************************************************************************/ @@ -61,7 +61,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. */ @@ -131,7 +131,7 @@ static int noverflows_g = 0; /*------------------------------------------------------------------------- * Function: overflow_handler * - * Purpose: Gets called for all data type conversion overflows. + * Purpose: Gets called for all datatype conversion overflows. * * Return: Success: 0 * @@ -160,9 +160,7 @@ overflow_handler(hid_t UNUSED src_id, hid_t UNUSED dst_id, * * Purpose: Test type classes * - * Return: Success: 0 - * - * Failure: number of errors + * Return: None * * Programmer: Binh-Minh Ribler (using C version) * January, 2007 @@ -173,27 +171,27 @@ overflow_handler(hid_t UNUSED src_id, hid_t UNUSED dst_id, */ static void test_classes(void) { + // Output message about test being performed SUBTEST("PredType::getClass()"); + try { // 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"); + verify_val(tcls, H5T_INTEGER, "test_class: invalid type class for NATIVE_INTEGER -", __LINE__, __FILE__); } // 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()); } -} +} // test_classes() /*------------------------------------------------------------------------- * Function: test_copy @@ -213,7 +211,9 @@ static void test_classes(void) */ static void test_copy(void) { + // Output message about test being performed SUBTEST("DataType::copy() and DataType::operator="); + try { // Test copying from a predefined datatype using DataType::operator= DataType assigned_type; @@ -244,11 +244,11 @@ static void test_copy(void) another_int_type = new_int_type; PASSED(); - } - catch (DataTypeIException E) { - issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); + } // end of try block + catch (Exception E) { + issue_fail_msg("test_copy()", __LINE__, __FILE__, E.getCDetailMsg()); } -} +} // test_copy() /*------------------------------------------------------------------------- @@ -273,18 +273,18 @@ const H5std_string EnumT_NAME("Enum_type"); static void test_query(void) { + short enum_val; typedef struct { int a; float b; long c; double d; } s_type_t; - short enum_val; // Output message about test being performed SUBTEST("Query functions of compound and enumeration types"); - try - { + + try { // Create File H5File file(FILENAME[2], H5F_ACC_TRUNC); @@ -327,9 +327,8 @@ static void test_query(void) 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 @@ -346,15 +345,15 @@ static void test_query(void) 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 @@ -362,7 +361,7 @@ static void test_query(void) /*------------------------------------------------------------------------- * Function: test_transient * - * Purpose: Tests transient data types. + * Purpose: Tests transient datatypes. * * Return: Success: 0 * @@ -375,34 +374,35 @@ static void test_query(void) * *------------------------------------------------------------------------- */ -const H5std_string filename1("dtypes1.h5"); -static void test_transient () +const H5std_string FILENAME1("dtypes1.h5"); +static void test_transient (void) { static hsize_t ds_size[2] = {10, 20}; - SUBTEST("Transient data types"); - try { + // Output message about test being performed + SUBTEST("Transient datatypes"); - H5File file(filename1, H5F_ACC_TRUNC); + 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 + // PredType::NATIVE_INT is a constant and cannot make a call, + // don't need these C tests in C++ API. // 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 + // Create a dataset from a transient datatype type.copy(PredType::NATIVE_INT); DataSet dset(file.createDataSet("dset1", type, space)); @@ -412,35 +412,27 @@ static void test_transient () 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); - // - // 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. - /// + // Get the dataset's datatype 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(); @@ -449,7 +441,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 @@ -457,7 +449,7 @@ static void test_transient () /*------------------------------------------------------------------------- * Function: test_named * - * Purpose: Tests named data types. + * Purpose: Tests named datatypes. * * Return: Success: 0 * @@ -470,23 +462,24 @@ static void test_transient () * *------------------------------------------------------------------------- */ -const H5std_string filename2("dtypes2.h5"); -static void test_named () +const H5std_string FILENAME2("dtypes2.h5"); +static void test_named (void) { static hsize_t ds_size[2] = {10, 20}; hsize_t i; unsigned attr_data[10][20]; - - //MESSAGE(5, ("named data types")); - SUBTEST("Named data types"); + + // Output message about test being performed + SUBTEST("Named datatypes"); + try { - // Create the file - H5File file(filename2, H5F_ACC_TRUNC); + // Create the file. + H5File file(FILENAME2, H5F_ACC_TRUNC); - // Create simple dataspace + // 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)"); @@ -495,15 +488,17 @@ static void test_named () throw InvalidActionException("PredType::commit", "Attempted to commit a predefined datatype."); } catch (DataTypeIException err) {} - // Copy a predefined data type and commit the copy + // Copy a predefined datatype and commit the copy. IntType itype(PredType::NATIVE_INT); itype.commit(file, "native-int"); + + // Check that it is committed. if (itype.committed() <= (bool)0) cerr << "IntType::committed() returned false" << endl; // 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."); @@ -514,8 +509,8 @@ static void test_named () 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) {} + 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 Attribute attr1 = itype.createAttribute("attr1", PredType::NATIVE_UCHAR, space); @@ -526,21 +521,20 @@ static void test_named () attr1.write(PredType::NATIVE_UINT, attr_data); attr1.close(); - // 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, (bool)0, "DataType::committed() - Copying a named type should result in a transient type!", __LINE__, __FILE__); - + verify_val(iscommitted, 0, "DataType::committed() - Copying a named type should result in a transient type!", __LINE__, __FILE__); trans_type.setPrecision(256); trans_type.close(); - // Close the committed type and reopen it. It should return a + // 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 and caused itype.committed not working correctly. So, + /* 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. Need to address it later - BMR 01/2007 itype = file.openIntType("native-int"); iscommitted = itype.committed(); @@ -550,46 +544,44 @@ static void test_named () if (!iscommitted) throw InvalidActionException("IntType::committed()", "Opened named types should be named types!"); - // Create a dataset that uses the named type - DataSet dset = file.createDataSet("dset1", itype, space); - - // 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!"); - // Close the dataset, then close its type, then reopen the dataset + // Close the dataset and its type dset.close(); ds_type->close(); + // Reopen the dataset and its type, then make sure the type is + // a named type. dset = file.openDataSet("dset1"); - - // 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!"); - // 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(); dset = file.createDataSet("dset2", *ds_type, space); - - // Close then 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!"); + throw InvalidActionException("DataType::iscommitted()", "Dataset type should be named type!"); ds_type->close(); - // Get the dataset data type by way of copying via the dataset. The - // result should be modifiable. + // Get the dataset's datatype by applying DataType::copy() to the + // dataset. The resulted datatype should be modifiable. IntType copied_type; copied_type.copy(dset); copied_type.setPrecision(256); // modifiable @@ -600,19 +592,22 @@ static void test_named () itype.close(); space.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_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) { // Output message about test being performed @@ -642,9 +637,11 @@ void test_types(void) * *------------------------------------------------------------------------- */ -void -cleanup_types(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_types(void) { for (int i = 0; i < 3; i++) HDremove(FILENAME[i]); -} +} // cleanup_types diff --git a/c++/test/tvlstr.cpp b/c++/test/tvlstr.cpp index b4a2667..a60c3fe 100644 --- a/c++/test/tvlstr.cpp +++ b/c++/test/tvlstr.cpp @@ -13,13 +13,13 @@ * 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: + + ***************************************************************************/ #ifdef OLD_HEADER_FILENAME #include <iostream.h> @@ -39,30 +39,18 @@ #include "H5Cpp.h" // C++ API header file #ifndef H5_NO_NAMESPACE -using namespace H5; + using namespace H5; #endif #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; -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 -* -*************************************************************/ void *test_vlstr_alloc_custom(size_t size, void *info); void test_vlstr_free_custom(void *mem, void *info); @@ -70,9 +58,11 @@ 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. +** allocation routines. This routine just uses malloc to +** allocate the memory and increments the amount of memory +** allocated. It is passed into setVlenMemManager. +** +** Note: exact copy from the C version. ** ****************************************************************/ void *test_vlstr_alloc_custom(size_t size, void *info) @@ -124,14 +114,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(void) { const char *wdata[SPACE1_DIM1]= { "Four score and seven years ago our forefathers brought forth on this continent a new nation,", @@ -141,12 +136,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}; @@ -223,36 +218,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(void) { 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}; @@ -333,30 +336,39 @@ test_vlstrings_special(void) tid1.close(); sid1.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_special()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_vlstrings_special -/**************************************************************** -** -** test_vlstring_type(): Test VL string type. -** Tests if VL string is treated as string. -** -****************************************************************/ +/*------------------------------------------------------------------------- + * 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(void) { // 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); @@ -395,9 +407,9 @@ static void test_vlstring_type(void) file1->close(); // Open file. - file1 = new H5File(DATAFILE, H5F_ACC_RDWR); + file1 = new H5File(FILENAME, H5F_ACC_RDWR); - //fid = H5Fopen(DATAFILE.c_str(), H5F_ACC_RDWR, H5P_DEFAULT); + //fid = H5Fopen(FILENAME.c_str(), H5F_ACC_RDWR, H5P_DEFAULT); // Open the variable-length string datatype just created vlstr_type.setId((file1->openStrType(VLSTR_TYPE)).getId()); @@ -414,12 +426,14 @@ static void test_vlstring_type(void) // Close datatype and file vlstr_type.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_vlstring_type()", __LINE__, __FILE__, E.getCDetailMsg()); } } // end test_vlstring_type() @@ -429,18 +443,17 @@ static void test_vlstring_type(void) ** compact datasets. ** ****************************************************************/ -static void -test_compact_vlstring(void) +static void test_compact_vlstring(void) { 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")); + 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}; @@ -484,37 +497,45 @@ 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; // Info for a string attribute 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); @@ -554,16 +575,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 @@ -572,53 +594,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_write_vl_string_attribute() -/**************************************************************** -** -** 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() { - 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 @@ -627,14 +654,17 @@ 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) { @@ -682,12 +712,17 @@ static void read_scalar_dset(H5File& file, DataType& type, DataSpace& space, cha ** have been linked/unlinked. ** ****************************************************************/ +const H5std_string FILENAME2("tvlstr2.h5"); +const int REWRITE_NDATASETS = 32; static void test_vl_rewrite(void) { + // 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); @@ -734,11 +769,13 @@ 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() @@ -747,10 +784,13 @@ static void test_vl_rewrite(void) ** test_vlstrings(): Main VL string testing routine. ** ****************************************************************/ +#ifdef __cplusplus +extern "C" +#endif void test_vlstrings(void) { // 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 @@ -783,10 +823,12 @@ void test_vlstrings(void) * *------------------------------------------------------------------------- */ -void -cleanup_vlstrings(void) +#ifdef __cplusplus +extern "C" +#endif +void cleanup_vlstrings(void) { - HDremove(DATAFILE.c_str()); - HDremove(DATAFILE2.c_str()); + HDremove(FILENAME.c_str()); + HDremove(FILENAME2.c_str()); } |