diff options
Diffstat (limited to 'c++/test')
-rw-r--r-- | c++/test/dsets.cpp | 1668 | ||||
-rw-r--r-- | c++/test/h5cpputil.cpp | 142 | ||||
-rw-r--r-- | c++/test/h5cpputil.h | 70 | ||||
-rw-r--r-- | c++/test/tarray.cpp | 486 | ||||
-rw-r--r-- | c++/test/tattr.cpp | 2062 | ||||
-rw-r--r-- | c++/test/tcompound.cpp | 958 | ||||
-rw-r--r-- | c++/test/tdspl.cpp | 124 | ||||
-rw-r--r-- | c++/test/testhdf5.cpp | 88 | ||||
-rw-r--r-- | c++/test/tfile.cpp | 846 | ||||
-rw-r--r-- | c++/test/tfilter.cpp | 90 | ||||
-rw-r--r-- | c++/test/th5s.cpp | 575 | ||||
-rw-r--r-- | c++/test/titerate.cpp | 370 | ||||
-rw-r--r-- | c++/test/tlinks.cpp | 312 | ||||
-rw-r--r-- | c++/test/tobject.cpp | 500 | ||||
-rw-r--r-- | c++/test/trefer.cpp | 1062 | ||||
-rw-r--r-- | c++/test/ttypes.cpp | 622 | ||||
-rw-r--r-- | c++/test/tvlstr.cpp | 1022 |
17 files changed, 5498 insertions, 5499 deletions
diff --git a/c++/test/dsets.cpp b/c++/test/dsets.cpp index 8752744..48a0c4d 100644 --- a/c++/test/dsets.cpp +++ b/c++/test/dsets.cpp @@ -16,12 +16,12 @@ /***************************************************************************** FILE dsets.cpp - HDF5 C++ testing the functionalities associated with the - C dataset interface (H5D) + C dataset interface (H5D) 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 + h5_reset() -- in h5test.c, resets the library by closing it + h5_fileaccess() -- in h5test.c, returns a file access template ***************************************************************************/ @@ -34,20 +34,20 @@ using std::cerr; using std::endl; #include <string> -#include "H5Cpp.h" // C++ API header file +#include "H5Cpp.h" // C++ API header file using namespace H5; #include "h5test.h" -#include "h5cpputil.h" // C++ utilility header file +#include "h5cpputil.h" // C++ utilility header file -const H5std_string FILE1("dataset.h5"); -const H5std_string DSET_DEFAULT_NAME("default"); -const H5std_string DSET_DEFAULT_NAME_PATH("/default"); -const H5std_string DSET_CHUNKED_NAME("chunked"); -const H5std_string DSET_SIMPLE_IO_NAME("simple_io"); -const H5std_string DSET_TCONV_NAME ("tconv"); -const H5std_string DSET_COMPRESS_NAME("compressed"); -const H5std_string DSET_BOGUS_NAME ("bogus"); +const H5std_string FILE1("dataset.h5"); +const H5std_string DSET_DEFAULT_NAME("default"); +const H5std_string DSET_DEFAULT_NAME_PATH("/default"); +const H5std_string DSET_CHUNKED_NAME("chunked"); +const H5std_string DSET_SIMPLE_IO_NAME("simple_io"); +const H5std_string DSET_TCONV_NAME("tconv"); +const H5std_string DSET_COMPRESS_NAME("compressed"); +const H5std_string DSET_BOGUS_NAME("bogus"); /* Temporary filter IDs used for testing */ const int H5Z_FILTER_BOGUS = 305; @@ -58,16 +58,16 @@ static size_t filter_bogus(unsigned int flags, size_t cd_nelmts, /*------------------------------------------------------------------------- - * Function: test_create + * Function: test_create * - * Purpose: Attempts to create a dataset. + * Purpose Attempts to create a dataset. * - * Return: Success: 0 + * Return Success: 0 * - * Failure: -1 + * Failure: -1 * - * Programmer: Binh-Minh Ribler (using C version) - * Friday, January 5, 2001 + * Programmer Binh-Minh Ribler (using C version) + * Friday, January 5, 2001 * * Modifications: * @@ -81,125 +81,125 @@ test_create( H5File& file) // Setting this to NULL for cleaning up in failure situations DataSet *dataset = NULL; try { - // Create a data space - hsize_t dims[2]; - dims[0] = 256; - dims[1] = 512; - DataSpace space (2, dims, NULL); - - // Create a dataset using the default dataset creation properties. - // We're not sure what they are, so we won't check. - dataset = new DataSet (file.createDataSet - (DSET_DEFAULT_NAME, PredType::NATIVE_DOUBLE, space)); - - - // Add a comment to the dataset - file.setComment (DSET_DEFAULT_NAME, "This is a dataset"); - - // Close the dataset - delete dataset; - dataset = NULL; - - // Try creating a dataset that already exists. This should fail since a - // dataset can only be created once. If an exception is not thrown for - // this action by createDataSet, then throw an invalid action exception. - try { - dataset = new DataSet (file.createDataSet - (DSET_DEFAULT_NAME, PredType::NATIVE_DOUBLE, space)); - - // continuation here, that means no exception has been thrown - throw InvalidActionException("H5File::createDataSet", "Library allowed overwrite of existing dataset"); - } - catch (FileIException& E) // catching invalid creating dataset - {} // do nothing, exception expected - - // Open the dataset we created above and then close it. This is one - // way to open an existing dataset for accessing. - dataset = new DataSet (file.openDataSet (DSET_DEFAULT_NAME)); - - // Get and verify the name of this dataset, using - // H5std_string getObjName() - H5std_string ds_name = dataset->getObjName(); - verify_val(ds_name, DSET_DEFAULT_NAME_PATH, "DataSet::getObjName", __LINE__, __FILE__); - - // Get and verify the comment from this dataset, using - // H5std_string getComment(const H5std_string& name, <buf_size=0, by default>) - H5std_string comment = file.getComment(DSET_DEFAULT_NAME); - verify_val(comment, "This is a dataset", "DataSet::getComment", __LINE__, __FILE__); - - // Close the dataset when accessing is completed - delete dataset; - - // This is another way to open an existing dataset for accessing. - DataSet another_dataset(file.openDataSet (DSET_DEFAULT_NAME)); - - // Try opening a non-existent dataset. This should fail so if an - // exception is not thrown for this action by openDataSet, then - // display failure information and throw an exception. - try { - dataset = new DataSet (file.openDataSet( "does_not_exist" )); - - // continuation here, that means no exception has been thrown - throw InvalidActionException("H5File::openDataSet", "Attempted to open a non-existent dataset"); - } - catch (FileIException& E ) // catching creating non-existent dataset - {} // do nothing, exception expected - - // Create a new dataset that uses chunked storage instead of the default - // layout. - DSetCreatPropList create_parms; - hsize_t csize[2]; - csize[0] = 5; - csize[1] = 100; - create_parms.setChunk( 2, csize ); - - dataset = new DataSet (file.createDataSet - (DSET_CHUNKED_NAME, PredType::NATIVE_DOUBLE, space, create_parms)); - // Note: this one has no error message in C when failure occurs? - - // clean up and return with success - delete dataset; - - PASSED(); - return 0; - } // outer most try block + // Create a data space + hsize_t dims[2]; + dims[0] = 256; + dims[1] = 512; + DataSpace space (2, dims, NULL); + + // Create a dataset using the default dataset creation properties. + // We're not sure what they are, so we won't check. + dataset = new DataSet (file.createDataSet + (DSET_DEFAULT_NAME, PredType::NATIVE_DOUBLE, space)); + + + // Add a comment to the dataset + file.setComment (DSET_DEFAULT_NAME, "This is a dataset"); + + // Close the dataset + delete dataset; + dataset = NULL; + + // Try creating a dataset that already exists. This should fail since a + // dataset can only be created once. If an exception is not thrown for + // this action by createDataSet, then throw an invalid action exception. + try { + dataset = new DataSet (file.createDataSet + (DSET_DEFAULT_NAME, PredType::NATIVE_DOUBLE, space)); + + // continuation here, that means no exception has been thrown + throw InvalidActionException("H5File::createDataSet", "Library allowed overwrite of existing dataset"); + } + catch (FileIException& E) // catching invalid creating dataset + {} // do nothing, exception expected + + // Open the dataset we created above and then close it. This is one + // way to open an existing dataset for accessing. + dataset = new DataSet (file.openDataSet (DSET_DEFAULT_NAME)); + + // Get and verify the name of this dataset, using + // H5std_string getObjName() + H5std_string ds_name = dataset->getObjName(); + verify_val(ds_name, DSET_DEFAULT_NAME_PATH, "DataSet::getObjName", __LINE__, __FILE__); + + // Get and verify the comment from this dataset, using + // H5std_string getComment(const H5std_string& name, <buf_size=0, by default>) + H5std_string comment = file.getComment(DSET_DEFAULT_NAME); + verify_val(comment, "This is a dataset", "DataSet::getComment", __LINE__, __FILE__); + + // Close the dataset when accessing is completed + delete dataset; + + // This is another way to open an existing dataset for accessing. + DataSet another_dataset(file.openDataSet (DSET_DEFAULT_NAME)); + + // Try opening a non-existent dataset. This should fail so if an + // exception is not thrown for this action by openDataSet, then + // display failure information and throw an exception. + try { + dataset = new DataSet (file.openDataSet( "does_not_exist" )); + + // continuation here, that means no exception has been thrown + throw InvalidActionException("H5File::openDataSet", "Attempted to open a non-existent dataset"); + } + catch (FileIException& E ) // catching creating non-existent dataset + {} // do nothing, exception expected + + // Create a new dataset that uses chunked storage instead of the default + // layout. + DSetCreatPropList create_parms; + hsize_t csize[2]; + csize[0] = 5; + csize[1] = 100; + create_parms.setChunk( 2, csize ); + + dataset = new DataSet (file.createDataSet(DSET_CHUNKED_NAME, + PredType::NATIVE_DOUBLE, space, create_parms)); + // Note: this one has no error message in C when failure occurs? + + // clean up and return with success + delete dataset; + + PASSED(); + return 0; + } // outer most try block catch (InvalidActionException& E) { - cerr << " FAILED" << endl; - cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; + cerr << " FAILED" << endl; + cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; - // clean up and return with failure - if (dataset != NULL) - delete dataset; - return -1; + // clean up and return with failure + if (dataset != NULL) + delete dataset; + return -1; } // catch all other exceptions catch (Exception& E) { - issue_fail_msg("test_create", __LINE__, __FILE__); + issue_fail_msg("test_create", __LINE__, __FILE__); - // clean up and return with failure - if (dataset != NULL) - delete dataset; - return -1; + // clean up and return with failure + if (dataset != NULL) + delete dataset; + return -1; } } // test_create /*------------------------------------------------------------------------- - * Function: test_simple_io + * Function: test_simple_io * - * Purpose: Tests simple I/O. That is, reading and writing a complete - * multi-dimensional array without data type or data space - * conversions, without compression, and stored contiguously. + * Purpose Tests simple I/O. That is, reading and writing a complete + * multi-dimensional array without data type or data space + * conversions, without compression, and stored contiguously. * - * Return: Success: 0 + * Return Success: 0 * - * Failure: -1 + * Failure: -1 * - * Programmer: Binh-Minh Ribler (using C version) - * Friday, January 5, 2001 + * Programmer Binh-Minh Ribler (using C version) + * Friday, January 5, 2001 * * Modifications: * @@ -211,81 +211,81 @@ test_simple_io( H5File& file) SUBTEST("Simple I/O"); - int points[100][200]; - int check[100][200]; - int i, j, n; + int points[100][200]; + int check[100][200]; + int i, j, n; // Initialize the dataset for (i = n = 0; i < 100; i++) { - for (j = 0; j < 200; j++) { - points[i][j] = n++; - } + for (j = 0; j < 200; j++) { + points[i][j] = n++; + } } char* tconv_buf = new char [1000]; try { - // Create the data space - hsize_t dims[2]; - dims[0] = 100; - dims[1] = 200; - DataSpace space (2, dims, NULL); - - // Create a small conversion buffer to test strip mining - DSetMemXferPropList xfer; - - xfer.setBuffer (1000, tconv_buf, NULL); - - // Create the dataset - DataSet dataset (file.createDataSet (DSET_SIMPLE_IO_NAME, PredType::NATIVE_INT, space)); - - // Write the data to the dataset - dataset.write(static_cast<void*>(points), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); - - // Read the dataset back - dataset.read (static_cast<void*>(check), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); - - // Check that the values read are the same as the values written - for (i = 0; i < 100; i++) - for (j = 0; j < 200; j++) - { - int status = check_values (i, j, points[i][j], check[i][j]); - if (status == -1) - throw Exception("DataSet::read"); - } - - // clean up and return with success - delete [] tconv_buf; - PASSED(); - return 0; + // Create the data space + hsize_t dims[2]; + dims[0] = 100; + dims[1] = 200; + DataSpace space (2, dims, NULL); + + // Create a small conversion buffer to test strip mining + DSetMemXferPropList xfer; + + xfer.setBuffer (1000, tconv_buf, NULL); + + // Create the dataset + DataSet dataset (file.createDataSet (DSET_SIMPLE_IO_NAME, PredType::NATIVE_INT, space)); + + // Write the data to the dataset + dataset.write(static_cast<void*>(points), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); + + // Read the dataset back + dataset.read (static_cast<void*>(check), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); + + // Check that the values read are the same as the values written + for (i = 0; i < 100; i++) + for (j = 0; j < 200; j++) + { + int status = check_values (i, j, points[i][j], check[i][j]); + if (status == -1) + throw Exception("DataSet::read"); + } + + // clean up and return with success + delete [] tconv_buf; + PASSED(); + return 0; } // end try // catch all dataset, space, plist exceptions catch (Exception& E) { - cerr << " FAILED" << endl; - cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; + cerr << " FAILED" << endl; + cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; - // clean up and return with failure - if (tconv_buf) - delete [] tconv_buf; - return -1; + // clean up and return with failure + if (tconv_buf) + delete [] tconv_buf; + return -1; } } // test_simple_io /*------------------------------------------------------------------------- - * Function: test_datasize + * Function: test_datasize * - * Purpose: Tests DataSet::getInMemDataSize(). + * Purpose Tests DataSet::getInMemDataSize(). * - * Return: Success: 0 + * Return Success: 0 * - * Failure: -1 + * Failure: -1 * - * Programmer: Binh-Minh Ribler - * Thursday, March 22, 2012 + * Programmer Binh-Minh Ribler + * Thursday, March 22, 2012 * * Modifications: * @@ -297,65 +297,65 @@ test_datasize(FileAccPropList &fapl) SUBTEST("DataSet::getInMemDataSize()"); try { - // Open FILE1. - H5File file(FILE1, H5F_ACC_RDWR, FileCreatPropList::DEFAULT, fapl); - - // Open dataset DSET_SIMPLE_IO_NAME. - DataSet dset = file.openDataSet (DSET_SIMPLE_IO_NAME); - - // Get the dataset's dataspace to calculate the size for verification. - DataSpace space(dset.getSpace()); - - // Get the dimension sizes. - hsize_t dims[2]; - int n_dims = space.getSimpleExtentDims(dims); - if (n_dims < 0) - { - throw Exception("test_compression", "DataSpace::getSimpleExtentDims() failed"); - } - - // Calculate the supposed size. Size of each value is int (4), from - // test_simple_io. - size_t expected_size = 4 * dims[0] * dims[1]; - - // getInMemDataSize() returns the in memory size of the data. - size_t ds_size = dset.getInMemDataSize(); - - // Verify the data size. - if (ds_size != expected_size) - { - H5_FAILED(); - cerr << " Expected data size = " << expected_size; - cerr << " but dset.getInMemDataSize() returned " << ds_size << endl; - throw Exception("test_compression", "Failed in testing DataSet::getInMemDataSize()"); - } - - PASSED(); - return 0; + // Open FILE1. + H5File file(FILE1, H5F_ACC_RDWR, FileCreatPropList::DEFAULT, fapl); + + // Open dataset DSET_SIMPLE_IO_NAME. + DataSet dset = file.openDataSet (DSET_SIMPLE_IO_NAME); + + // Get the dataset's dataspace to calculate the size for verification. + DataSpace space(dset.getSpace()); + + // Get the dimension sizes. + hsize_t dims[2]; + int n_dims = space.getSimpleExtentDims(dims); + if (n_dims < 0) + { + throw Exception("test_compression", "DataSpace::getSimpleExtentDims() failed"); + } + + // Calculate the supposed size. Size of each value is int (4), from + // test_simple_io. + size_t expected_size = 4 * dims[0] * dims[1]; + + // getInMemDataSize() returns the in memory size of the data. + size_t ds_size = dset.getInMemDataSize(); + + // Verify the data size. + if (ds_size != expected_size) + { + H5_FAILED(); + cerr << " Expected data size = " << expected_size; + cerr << " but dset.getInMemDataSize() returned " << ds_size << endl; + throw Exception("test_compression", "Failed in testing DataSet::getInMemDataSize()"); + } + + PASSED(); + return 0; } // end try // catch all dataset, space, plist exceptions catch (Exception& E) { - cerr << " FAILED" << endl; - cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; + cerr << " FAILED" << endl; + cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; - return -1; + return -1; } } // test_datasize /*------------------------------------------------------------------------- - * Function: test_tconv + * Function: test_tconv * - * Purpose: Test some simple data type conversion stuff. + * Purpose Test some simple data type conversion stuff. * - * Return: Success: 0 + * Return Success: 0 * - * Failure: -1 + * Failure: -1 * - * Programmer: Binh-Minh Ribler (using C version) - * Friday, January 5, 2001 + * Programmer Binh-Minh Ribler (using C version) + * Friday, January 5, 2001 * * Modifications: * @@ -365,7 +365,7 @@ static herr_t test_tconv(H5File& file) { // Prepare buffers for input/output - char *out=NULL, *in=NULL; + char *out=NULL, *in=NULL; out = new char [4*1000000]; // assert (out); - should use exception handler for new - BMR in = new char [4*1000000]; @@ -375,81 +375,81 @@ test_tconv(H5File& file) // Initialize the dataset for (int i = 0; i < 1000000; i++) { - out[i*4+0] = 0x11; - out[i*4+1] = 0x22; - out[i*4+2] = 0x33; - out[i*4+3] = 0x44; + out[i*4+0] = 0x11; + out[i*4+1] = 0x22; + out[i*4+2] = 0x33; + out[i*4+3] = 0x44; } try { - // Create the data space - hsize_t dims[1]; - dims[0] = 1000000; - DataSpace space (1, dims, NULL); - - // Create the data set - DataSet dataset (file.createDataSet (DSET_TCONV_NAME, PredType::STD_I32LE, space)); - - // Write the data to the dataset - dataset.write (static_cast<void*>(out), PredType::STD_I32LE); - - // Read data with byte order conversion - dataset.read (static_cast<void*>(in), PredType::STD_I32BE); - - // Check - for (int i = 0; i < 1000000; i++) { - if (in[4*i+0]!=out[4*i+3] || - in[4*i+1]!=out[4*i+2] || - in[4*i+2]!=out[4*i+1] || - in[4*i+3]!=out[4*i+0]) - { - throw Exception("DataSet::read", "Read with byte order conversion failed"); - } - } - - // clean up and return with success - delete [] out; - delete [] in; - PASSED(); - return 0; + // Create the data space + hsize_t dims[1]; + dims[0] = 1000000; + DataSpace space (1, dims, NULL); + + // Create the data set + DataSet dataset (file.createDataSet (DSET_TCONV_NAME, PredType::STD_I32LE, space)); + + // Write the data to the dataset + dataset.write (static_cast<void*>(out), PredType::STD_I32LE); + + // Read data with byte order conversion + dataset.read (static_cast<void*>(in), PredType::STD_I32BE); + + // Check + for (int i = 0; i < 1000000; i++) { + if (in[4*i+0]!=out[4*i+3] || + in[4*i+1]!=out[4*i+2] || + in[4*i+2]!=out[4*i+1] || + in[4*i+3]!=out[4*i+0]) + { + throw Exception("DataSet::read", "Read with byte order conversion failed"); + } + } + + // clean up and return with success + delete [] out; + delete [] in; + PASSED(); + return 0; } // end try // catch all dataset and space exceptions catch (Exception& E) { - cerr << " FAILED" << endl; - cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; + cerr << " FAILED" << endl; + cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; - // clean up and return with failure - delete [] out; - delete [] in; - return -1; + // clean up and return with failure + delete [] out; + delete [] in; + return -1; } } // test_tconv /* This message derives from H5Z */ const H5Z_class2_t H5Z_BOGUS[1] = {{ - H5Z_CLASS_T_VERS, /* H5Z_class_t version number */ - H5Z_FILTER_BOGUS, /* Filter id number */ - 1, 1, /* Encode and decode enabled */ - "bogus", /* Filter name for debugging */ + H5Z_CLASS_T_VERS, /* H5Z_class_t version number */ + H5Z_FILTER_BOGUS, /* Filter id number */ + 1, 1, /* Encode and decode enabled */ + "bogus", /* Filter name for debugging */ NULL, /* The "can apply" callback */ NULL, /* The "set local" callback */ - (H5Z_func_t)filter_bogus, /* The actual filter function */ + (H5Z_func_t)filter_bogus, /* The actual filter function */ }}; /*------------------------------------------------------------------------- - * Function: bogus + * Function: bogus * - * Purpose: A bogus compression method that doesn't do anything. + * Purpose A bogus compression method that doesn't do anything. * - * Return: Success: Data chunk size + * Return Success: Data chunk size * - * Failure: 0 + * Failure: 0 * - * Programmer: Robb Matzke - * Tuesday, April 21, 1998 + * Programmer Robb Matzke + * Tuesday, April 21, 1998 * * Modifications: * @@ -466,19 +466,19 @@ filter_bogus(unsigned int flags, size_t cd_nelmts, /*------------------------------------------------------------------------- - * Function: test_compression + * Function: test_compression * - * Purpose: Tests dataset compression. If compression is requested when - * it hasn't been compiled into the library (such as when - * updating an existing compressed dataset) then data is sent to - * the file uncompressed but no errors are returned. + * Purpose Tests dataset compression. If compression is requested when + * it hasn't been compiled into the library (such as when + * updating an existing compressed dataset) then data is sent to + * the file uncompressed but no errors are returned. * - * Return: Success: 0 + * Return Success: 0 * - * Failure: -1 + * Failure: -1 * - * Programmer: Binh-Minh Ribler (using C version) - * Friday, January 5, 2001 + * Programmer Binh-Minh Ribler (using C version) + * Friday, January 5, 2001 * * Modifications: * @@ -488,266 +488,266 @@ static herr_t test_compression(H5File& file) { #ifndef H5_HAVE_FILTER_DEFLATE - const char *not_supported; + const char *not_supported; not_supported = " Deflate compression is not enabled."; #endif /* H5_HAVE_FILTER_DEFLATE */ - int points[100][200]; - int check[100][200]; - hsize_t i, j, n; + int points[100][200]; + int check[100][200]; + hsize_t i, j, n; // Initialize the dataset for (i = n = 0; i < 100; i++) { - for (j = 0; j < 200; j++) { - points[i][j] = static_cast<int>(n++); - } + for (j = 0; j < 200; j++) { + points[i][j] = static_cast<int>(n++); + } } char* tconv_buf = new char [1000]; DataSet* dataset = NULL; try { - const hsize_t size[2] = {100, 200}; - // Create the data space - DataSpace space1(2, size, NULL); + const hsize_t size[2] = {100, 200}; + // Create the data space + DataSpace space1(2, size, NULL); - // Create a small conversion buffer to test strip mining - DSetMemXferPropList xfer; + // Create a small conversion buffer to test strip mining + DSetMemXferPropList xfer; - xfer.setBuffer (1000, tconv_buf, NULL); + xfer.setBuffer (1000, tconv_buf, NULL); - // Use chunked storage with compression - DSetCreatPropList dscreatplist; + // Use chunked storage with compression + DSetCreatPropList dscreatplist; - const hsize_t chunk_size[2] = {2, 25}; - dscreatplist.setChunk (2, chunk_size); - dscreatplist.setDeflate (6); + const hsize_t chunk_size[2] = {2, 25}; + dscreatplist.setChunk (2, chunk_size); + dscreatplist.setDeflate (6); #ifdef H5_HAVE_FILTER_DEFLATE - SUBTEST("Compression (setup)"); - - // Create the dataset - dataset = new DataSet (file.createDataSet - (DSET_COMPRESS_NAME, PredType::NATIVE_INT, space1, dscreatplist)); - - PASSED(); - - /*---------------------------------------------------------------------- - * STEP 1: Read uninitialized data. It should be zero. - *---------------------------------------------------------------------- - */ - SUBTEST("Compression (uninitialized read)"); - - dataset->read (static_cast<void*>(check), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); - - for (i=0; i<size[0]; i++) { - for (j=0; j<size[1]; j++) { - if (0!=check[i][j]) { - H5_FAILED(); - cerr << " Read a non-zero value." << endl; - cerr << " At index " << static_cast<unsigned long>(i) << "," << - static_cast<unsigned long>(j) << endl; - throw Exception("test_compression", "Failed in uninitialized read"); - } - } - } - PASSED(); - - /*---------------------------------------------------------------------- - * STEP 2: Test compression by setting up a chunked dataset and writing - * to it. - *---------------------------------------------------------------------- - */ - SUBTEST("Compression (write)"); - - for (i=n=0; i<size[0]; i++) - { - for (j=0; j<size[1]; j++) - { - points[i][j] = static_cast<int>(n++); - } - } - - dataset->write (static_cast<void*>(points), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); - - PASSED(); - - /*---------------------------------------------------------------------- - * STEP 3: Try to read the data we just wrote. - *---------------------------------------------------------------------- - */ - SUBTEST("Compression (read)"); - - // Read the dataset back - dataset->read (static_cast<void*>(check), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); - - // Check that the values read are the same as the values written - for (i = 0; i < size[0]; i++) - for (j = 0; j < size[1]; j++) - { - int status = check_values (i, j, points[i][j], check[i][j]); - if (status == -1) - throw Exception("test_compression", "Failed in read"); - } - - PASSED(); - - /*---------------------------------------------------------------------- - * STEP 4: Write new data over the top of the old data. The new data is - * random thus not very compressible, and will cause the chunks to move - * around as they grow. We only change values for the left half of the - * dataset although we rewrite the whole thing. - *---------------------------------------------------------------------- - */ - SUBTEST("Compression (modify)"); - - for (i=0; i<size[0]; i++) - { - for (j=0; j<size[1]/2; j++) - { - points[i][j] = rand (); - } - } - dataset->write (static_cast<void*>(points), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); - - // Read the dataset back and check it - dataset->read (static_cast<void*>(check), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); - - // Check that the values read are the same as the values written - for (i = 0; i < size[0]; i++) - for (j = 0; j < size[1]; j++) - { - int status = check_values (i, j, points[i][j], check[i][j]); - if (status == -1) - throw Exception("test_compression", "Failed in modify"); - } - - PASSED(); - - /*---------------------------------------------------------------------- - * STEP 5: Close the dataset and then open it and read it again. This - * insures that the compression message is picked up properly from the - * object header. - *---------------------------------------------------------------------- - */ - SUBTEST("Compression (re-open)"); - - // close this dataset to reuse the var - delete dataset; - - dataset = new DataSet (file.openDataSet (DSET_COMPRESS_NAME)); - dataset->read (static_cast<void*>(check), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); - - // Check that the values read are the same as the values written - for (i = 0; i < size[0]; i++) - for (j = 0; j < size[1]; j++) - { - int status = check_values (i, j, points[i][j], check[i][j]); - if (status == -1) - throw Exception("test_compression", "Failed in re-open"); - } - - PASSED(); - - - /*---------------------------------------------------------------------- - * STEP 6: Test partial I/O by writing to and then reading from a - * hyperslab of the dataset. The hyperslab does not line up on chunk - * boundaries (we know that case already works from above tests). - *---------------------------------------------------------------------- - */ - SUBTEST("Compression (partial I/O)"); - - const hsize_t hs_size[2] = {4, 50}; - const hsize_t hs_offset[2] = {7, 30}; - for (i = 0; i < hs_size[0]; i++) { - for (j = 0; j < hs_size[1]; j++) { - points[hs_offset[0]+i][hs_offset[1]+j] = rand (); - } - } - space1.selectHyperslab( H5S_SELECT_SET, hs_size, hs_offset ); - dataset->write (static_cast<void*>(points), PredType::NATIVE_INT, space1, space1, xfer); - dataset->read (static_cast<void*>(check), PredType::NATIVE_INT, space1, space1, xfer); - - // Check that the values read are the same as the values written - for (i=0; i<hs_size[0]; i++) { - for (j=0; j<hs_size[1]; j++) { - if (points[hs_offset[0]+i][hs_offset[1]+j] != - check[hs_offset[0]+i][hs_offset[1]+j]) { - H5_FAILED(); - cerr << " Read different values than written.\n" << endl; - cerr << " At index " << static_cast<unsigned long>((hs_offset[0]+i)) << - "," << static_cast<unsigned long>((hs_offset[1]+j)) << endl; - - cerr << " At original: " << static_cast<int>(points[hs_offset[0]+i][hs_offset[1]+j]) << endl; - cerr << " At returned: " << static_cast<int>(check[hs_offset[0]+i][hs_offset[1]+j]) << endl; - throw Exception("test_compression", "Failed in partial I/O"); - } - } // for j - } // for i - - delete dataset; - dataset = NULL; - - PASSED(); + SUBTEST("Compression (setup)"); + + // Create the dataset + dataset = new DataSet (file.createDataSet + (DSET_COMPRESS_NAME, PredType::NATIVE_INT, space1, dscreatplist)); + + PASSED(); + + /*---------------------------------------------------------------------- + * STEP 1: Read uninitialized data. It should be zero. + *---------------------------------------------------------------------- + */ + SUBTEST("Compression (uninitialized read)"); + + dataset->read (static_cast<void*>(check), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); + + for (i=0; i<size[0]; i++) { + for (j=0; j<size[1]; j++) { + if (0!=check[i][j]) { + H5_FAILED(); + cerr << " Read a non-zero value." << endl; + cerr << " At index " << static_cast<unsigned long>(i) + << "," << static_cast<unsigned long>(j) << endl; + throw Exception("test_compression", "Failed in uninitialized read"); + } + } + } + PASSED(); + + /*---------------------------------------------------------------------- + * STEP 2: Test compression by setting up a chunked dataset and writing + * to it. + *---------------------------------------------------------------------- + */ + SUBTEST("Compression (write)"); + + for (i=n=0; i<size[0]; i++) + { + for (j=0; j<size[1]; j++) + { + points[i][j] = static_cast<int>(n++); + } + } + + dataset->write (static_cast<void*>(points), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); + + PASSED(); + + /*---------------------------------------------------------------------- + * STEP 3: Try to read the data we just wrote. + *---------------------------------------------------------------------- + */ + SUBTEST("Compression (read)"); + + // Read the dataset back + dataset->read (static_cast<void*>(check), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); + + // Check that the values read are the same as the values written + for (i = 0; i < size[0]; i++) + for (j = 0; j < size[1]; j++) + { + int status = check_values (i, j, points[i][j], check[i][j]); + if (status == -1) + throw Exception("test_compression", "Failed in read"); + } + + PASSED(); + + /*---------------------------------------------------------------------- + * STEP 4: Write new data over the top of the old data. The new data is + * random thus not very compressible, and will cause the chunks to move + * around as they grow. We only change values for the left half of the + * dataset although we rewrite the whole thing. + *---------------------------------------------------------------------- + */ + SUBTEST("Compression (modify)"); + + for (i=0; i<size[0]; i++) + { + for (j=0; j<size[1]/2; j++) + { + points[i][j] = rand (); + } + } + dataset->write (static_cast<void*>(points), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); + + // Read the dataset back and check it + dataset->read (static_cast<void*>(check), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); + + // Check that the values read are the same as the values written + for (i = 0; i < size[0]; i++) + for (j = 0; j < size[1]; j++) + { + int status = check_values (i, j, points[i][j], check[i][j]); + if (status == -1) + throw Exception("test_compression", "Failed in modify"); + } + + PASSED(); + + /*---------------------------------------------------------------------- + * STEP 5: Close the dataset and then open it and read it again. This + * insures that the compression message is picked up properly from the + * object header. + *---------------------------------------------------------------------- + */ + SUBTEST("Compression (re-open)"); + + // close this dataset to reuse the var + delete dataset; + + dataset = new DataSet (file.openDataSet (DSET_COMPRESS_NAME)); + dataset->read (static_cast<void*>(check), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); + + // Check that the values read are the same as the values written + for (i = 0; i < size[0]; i++) + for (j = 0; j < size[1]; j++) + { + int status = check_values (i, j, points[i][j], check[i][j]); + if (status == -1) + throw Exception("test_compression", "Failed in re-open"); + } + + PASSED(); + + + /*---------------------------------------------------------------------- + * STEP 6: Test partial I/O by writing to and then reading from a + * hyperslab of the dataset. The hyperslab does not line up on chunk + * boundaries (we know that case already works from above tests). + *---------------------------------------------------------------------- + */ + SUBTEST("Compression (partial I/O)"); + + const hsize_t hs_size[2] = {4, 50}; + const hsize_t hs_offset[2] = {7, 30}; + for (i = 0; i < hs_size[0]; i++) { + for (j = 0; j < hs_size[1]; j++) { + points[hs_offset[0]+i][hs_offset[1]+j] = rand (); + } + } + space1.selectHyperslab( H5S_SELECT_SET, hs_size, hs_offset ); + dataset->write (static_cast<void*>(points), PredType::NATIVE_INT, space1, space1, xfer); + dataset->read (static_cast<void*>(check), PredType::NATIVE_INT, space1, space1, xfer); + + // Check that the values read are the same as the values written + for (i=0; i<hs_size[0]; i++) { + for (j=0; j<hs_size[1]; j++) { + if (points[hs_offset[0]+i][hs_offset[1]+j] != + check[hs_offset[0]+i][hs_offset[1]+j]) { + H5_FAILED(); + cerr << " Read different values than written.\n" << endl; + cerr << " At index " << static_cast<unsigned long>((hs_offset[0]+i)) << + "," << static_cast<unsigned long>((hs_offset[1]+j)) << endl; + + cerr << " At original: " << static_cast<int>(points[hs_offset[0]+i][hs_offset[1]+j]) << endl; + cerr << " At returned: " << static_cast<int>(check[hs_offset[0]+i][hs_offset[1]+j]) << endl; + throw Exception("test_compression", "Failed in partial I/O"); + } + } // for j + } // for i + + delete dataset; + dataset = NULL; + + PASSED(); #else - SUBTEST("deflate filter"); - SKIPPED(); - cerr << not_supported << endl; + SUBTEST("deflate filter"); + SKIPPED(); + cerr << not_supported << endl; #endif - /*---------------------------------------------------------------------- - * STEP 7: Register an application-defined compression method and use it - * to write and then read the dataset. - *---------------------------------------------------------------------- - */ - SUBTEST("Compression (app-defined method)"); + /*---------------------------------------------------------------------- + * STEP 7: Register an application-defined compression method and use it + * to write and then read the dataset. + *---------------------------------------------------------------------- + */ + SUBTEST("Compression (app-defined method)"); if (H5Zregister (H5Z_BOGUS)<0) - throw Exception("test_compression", "Failed in app-defined method"); - if (H5Pset_filter (dscreatplist.getId(), H5Z_FILTER_BOGUS, 0, 0, NULL)<0) - throw Exception("test_compression", "Failed in app-defined method"); - dscreatplist.setFilter (H5Z_FILTER_BOGUS, 0, 0, NULL); - - DataSpace space2 (2, size, NULL); - dataset = new DataSet (file.createDataSet (DSET_BOGUS_NAME, PredType::NATIVE_INT, space2, dscreatplist)); - - dataset->write (static_cast<void*>(points), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); - dataset->read (static_cast<void*>(check), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); - - // Check that the values read are the same as the values written - for (i = 0; i < size[0]; i++) - for (j = 0; j < size[1]; j++) - { - int status = check_values (i, j, points[i][j], check[i][j]); - if (status == -1) - throw Exception("test_compression", "Failed in app-defined method"); - } - - PASSED(); - - /*---------------------------------------------------------------------- - * Cleanup - *---------------------------------------------------------------------- - */ - delete dataset; - delete [] tconv_buf; - return 0; + throw Exception("test_compression", "Failed in app-defined method"); + if (H5Pset_filter (dscreatplist.getId(), H5Z_FILTER_BOGUS, 0, 0, NULL)<0) + throw Exception("test_compression", "Failed in app-defined method"); + dscreatplist.setFilter (H5Z_FILTER_BOGUS, 0, 0, NULL); + + DataSpace space2 (2, size, NULL); + dataset = new DataSet (file.createDataSet (DSET_BOGUS_NAME, PredType::NATIVE_INT, space2, dscreatplist)); + + dataset->write (static_cast<void*>(points), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); + dataset->read (static_cast<void*>(check), PredType::NATIVE_INT, DataSpace::ALL, DataSpace::ALL, xfer); + + // Check that the values read are the same as the values written + for (i = 0; i < size[0]; i++) + for (j = 0; j < size[1]; j++) + { + int status = check_values (i, j, points[i][j], check[i][j]); + if (status == -1) + throw Exception("test_compression", "Failed in app-defined method"); + } + + PASSED(); + + /*---------------------------------------------------------------------- + * Cleanup + *---------------------------------------------------------------------- + */ + delete dataset; + delete [] tconv_buf; + return 0; } // end try // catch all dataset, file, space, and plist exceptions catch (Exception& E) { - cerr << " FAILED" << endl; - cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; - - // clean up and return with failure - if (dataset != NULL) - delete dataset; - if (tconv_buf) - delete [] tconv_buf; - return -1; + cerr << " FAILED" << endl; + cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; + + // clean up and return with failure + if (dataset != NULL) + delete dataset; + if (tconv_buf) + delete [] tconv_buf; + return -1; } } // test_compression @@ -755,18 +755,18 @@ test_compression(H5File& file) /*------------------------------------------------------------------------- * Function: test_nbit_methods * - * Purpose: Tests setting nbit compression methods. + * Purpose Tests setting nbit compression methods. * - * Return: Success: 0 + * Return Success: 0 * - * Failure: -1 + * Failure: -1 * - * Programmer: Binh-Minh Ribler - * Friday, April 22, 2016 + * Programmer Binh-Minh Ribler + * Friday, April 22, 2016 * *------------------------------------------------------------------------- */ -const H5std_string DSET_NBIT_NAME("nbit_dataset"); +const H5std_string DSET_NBIT_NAME("nbit_dataset"); const hsize_t DIM1 = 2; const hsize_t DIM2 = 5; static herr_t test_nbit_compression(H5File& file) @@ -787,101 +787,101 @@ static herr_t test_nbit_compression(H5File& file) try { - // Define datatypes of members of compound datatype - IntType i_type(PredType::NATIVE_INT); - IntType c_type(PredType::NATIVE_CHAR); - IntType s_type(PredType::NATIVE_SHORT); - - // Create a dataset compound datatype - CompType cmpd(sizeof(s1_t)); - cmpd.insertMember("i", HOFFSET(s1_t, i), i_type); - cmpd.insertMember("c", HOFFSET(s1_t, c), c_type); - cmpd.insertMember("s", HOFFSET(s1_t, s), s_type); - - // Create a memory compound datatype - CompType mem_cmpd(sizeof(s1_t)); - mem_cmpd.insertMember("i", HOFFSET(s1_t, i), i_type); - mem_cmpd.insertMember("c", HOFFSET(s1_t, c), c_type); - mem_cmpd.insertMember("s", HOFFSET(s1_t, s), s_type); - - // Set order of dataset compound datatype - //cmpd.setOrder(H5T_ORDER_BE); only for atomic type? - - // Create the data space - DataSpace space(2, size); - - // Use nbit filter - DSetCreatPropList dscreat; - dscreat.setChunk(2, chunk_size); - dscreat.setNbit(); - - // Create the dataset - DataSet dataset(file.createDataSet(DSET_NBIT_NAME, cmpd, space, dscreat)); - - // Initialize data, assuming size of long long >= size of member datatypes - for (i = 0; i < size[0]; i++) - for (j = 0; j < size[1]; j++) - { - orig_data[i][j].i = static_cast<int>(i * j); - orig_data[i][j].c = static_cast<char>('a' + i); - orig_data[i][j].s = static_cast<short>(i + j); - - // Some even-numbered integer values are negative - if ((i*size[1]+j+1)%2 == 0) { - orig_data[i][j].i = -orig_data[i][j].i; - orig_data[i][j].s = static_cast<short>(-orig_data[i][j].s); - } - } - - // Write to the dataset - dataset.write(static_cast<void*>(orig_data), mem_cmpd); - - // Read the dataset back */ - dataset.read(static_cast<void*>(new_data), mem_cmpd); - - // Check that the values read are the same as the values written. - for (i = 0; i < size[0]; i++) - for (j = 0; j < size[1]; j++) - { - if((new_data[i][j].i != orig_data[i][j].i) || - (new_data[i][j].c != orig_data[i][j].c) || - (new_data[i][j].s != orig_data[i][j].s)) - { - H5_FAILED(); - printf(" Read different values than written.\n"); - printf(" At index %lu,%lu\n", static_cast<unsigned long>(i), static_cast<unsigned long>(j)); - } + // Define datatypes of members of compound datatype + IntType i_type(PredType::NATIVE_INT); + IntType c_type(PredType::NATIVE_CHAR); + IntType s_type(PredType::NATIVE_SHORT); + + // Create a dataset compound datatype + CompType cmpd(sizeof(s1_t)); + cmpd.insertMember("i", HOFFSET(s1_t, i), i_type); + cmpd.insertMember("c", HOFFSET(s1_t, c), c_type); + cmpd.insertMember("s", HOFFSET(s1_t, s), s_type); + + // Create a memory compound datatype + CompType mem_cmpd(sizeof(s1_t)); + mem_cmpd.insertMember("i", HOFFSET(s1_t, i), i_type); + mem_cmpd.insertMember("c", HOFFSET(s1_t, c), c_type); + mem_cmpd.insertMember("s", HOFFSET(s1_t, s), s_type); + + // Set order of dataset compound datatype + //cmpd.setOrder(H5T_ORDER_BE); only for atomic type? + + // Create the data space + DataSpace space(2, size); + + // Use nbit filter + DSetCreatPropList dscreat; + dscreat.setChunk(2, chunk_size); + dscreat.setNbit(); + + // Create the dataset + DataSet dataset(file.createDataSet(DSET_NBIT_NAME, cmpd, space, dscreat)); + + // Initialize data, assuming size of long long >= size of member datatypes + for (i = 0; i < size[0]; i++) + for (j = 0; j < size[1]; j++) + { + orig_data[i][j].i = static_cast<int>(i * j); + orig_data[i][j].c = static_cast<char>('a' + i); + orig_data[i][j].s = static_cast<short>(i + j); + + // Some even-numbered integer values are negative + if ((i*size[1]+j+1)%2 == 0) { + orig_data[i][j].i = -orig_data[i][j].i; + orig_data[i][j].s = static_cast<short>(-orig_data[i][j].s); + } + } + + // Write to the dataset + dataset.write(static_cast<void*>(orig_data), mem_cmpd); + + // Read the dataset back */ + dataset.read(static_cast<void*>(new_data), mem_cmpd); + + // Check that the values read are the same as the values written. + for (i = 0; i < size[0]; i++) + for (j = 0; j < size[1]; j++) + { + if((new_data[i][j].i != orig_data[i][j].i) || + (new_data[i][j].c != orig_data[i][j].c) || + (new_data[i][j].s != orig_data[i][j].s)) + { + H5_FAILED(); + printf(" Read different values than written.\n"); + printf(" At index %lu,%lu\n", static_cast<unsigned long>(i), static_cast<unsigned long>(j)); + } } - PASSED(); - return 0; + PASSED(); + return 0; } // end try block // catch all dataset, file, space, and plist exceptions catch (Exception& E) { - cerr << " FAILED" << endl; - cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; + cerr << " FAILED" << endl; + cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; - return -1; + return -1; } } // test_nbit_compression /*------------------------------------------------------------------------- - * Function: test_multiopen + * Function: test_multiopen * - * Purpose: Tests that a bug no longer exists. If a dataset is opened - * twice and one of the handles is used to extend the dataset, - * then the other handle should return the new size when - * queried. + * Purpose Tests that a bug no longer exists. If a dataset is opened + * twice and one of the handles is used to extend the dataset, + * then the other handle should return the new size when + * queried. * - * Return: Success: 0 + * Return Success: 0 * - * Failure: -1 + * Failure: -1 * - * Programmer: Binh-Minh Ribler (using C version) - * Saturday, February 17, 2001 + * Programmer Binh-Minh Ribler (using C version) + * Saturday, February 17, 2001 * * Modifications: * @@ -896,74 +896,75 @@ test_multiopen (H5File& file) DataSpace* space = NULL; try { - // Create a dataset creation property list - DSetCreatPropList dcpl; + // Create a dataset creation property list + DSetCreatPropList dcpl; - // Set chunk size to given size - hsize_t cur_size[1] = {10}; - dcpl.setChunk (1, cur_size); + // Set chunk size to given size + hsize_t cur_size[1] = {10}; + dcpl.setChunk (1, cur_size); - // Create a simple data space with unlimited size - hsize_t max_size[1] = {H5S_UNLIMITED}; - space = new DataSpace (1, cur_size, max_size); + // Create a simple data space with unlimited size + hsize_t max_size[1] = {H5S_UNLIMITED}; + space = new DataSpace (1, cur_size, max_size); - // Create first dataset - DataSet dset1 = file.createDataSet ("multiopen", PredType::NATIVE_INT, *space, dcpl); + // Create first dataset + DataSet dset1 = file.createDataSet ("multiopen", PredType::NATIVE_INT, *space, dcpl); - // Open again the first dataset from the file to another DataSet object. - DataSet dset2 = file.openDataSet ("multiopen"); + // Open again the first dataset from the file to another DataSet object. + DataSet dset2 = file.openDataSet ("multiopen"); - // Relieve the dataspace - delete space; - space = NULL; + // Relieve the dataspace + delete space; + space = NULL; - // Extend the dimensionality of the first dataset - cur_size[0] = 20; - dset1.extend (cur_size); + // Extend the dimensionality of the first dataset + cur_size[0] = 20; + dset1.extend (cur_size); - // Get the size from the second handle - space = new DataSpace (dset2.getSpace()); + // Get the size from the second handle + space = new DataSpace (dset2.getSpace()); - hsize_t tmp_size[1]; - space->getSimpleExtentDims (tmp_size); - if (cur_size[0]!=tmp_size[0]) - { - cerr << " Got " << static_cast<int>(tmp_size[0]) << " instead of " - << static_cast<int>(cur_size[0]) << "!" << endl; - throw Exception("test_multiopen", "Failed in multi-open with extending"); - } + hsize_t tmp_size[1]; + space->getSimpleExtentDims (tmp_size); + if (cur_size[0]!=tmp_size[0]) + { + cerr << " Got " << static_cast<int>(tmp_size[0]) + << " instead of " << static_cast<int>(cur_size[0]) + << "!" << endl; + throw Exception("test_multiopen", "Failed in multi-open with extending"); + } - // clean up and return with success - delete space; - PASSED(); - return 0; + // clean up and return with success + delete space; + PASSED(); + return 0; } // end try block // catch all dataset, file, space, and plist exceptions catch (Exception& E) { - cerr << " FAILED" << endl; - cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; + cerr << " FAILED" << endl; + cerr << " <<< " << E.getDetailMsg() << " >>>" << endl << endl; - // clean up and return with failure - if (space != NULL) - delete space; - return -1; + // clean up and return with failure + if (space != NULL) + delete space; + return -1; } } // test_multiopen /*------------------------------------------------------------------------- - * Function: test_types + * Function: test_types * - * Purpose: Test various types - should be moved to dtypes.cpp + * Purpose Test various types - should be moved to dtypes.cpp * - * Return: Success: 0 + * Return Success: 0 * - * Failure: -1 + * Failure: -1 * - * Programmer: Binh-Minh Ribler (using C version) - * February 17, 2001 + * Programmer Binh-Minh Ribler (using C version) + * February 17, 2001 * * Modifications: * @@ -974,239 +975,238 @@ test_types(H5File& file) { SUBTEST("Various datatypes"); - size_t i; + size_t i; DataSet* dset = NULL; try { - // Create a group in the file that was passed in from the caller - Group grp = file.createGroup ("typetests"); - - /* bitfield_1 */ - unsigned char buf[32]; - hsize_t nelmts = sizeof(buf); - DataType type; - try { // block of bitfield_1 - // test copying a predefined type - type.copy (PredType::STD_B8LE); - - // Test copying a user-defined type using DataType::copy - DataType copied_type; - copied_type.copy(type); - - // Test copying a user-defined type using DataType::operator= - DataType another_copied_type; - another_copied_type = type; - - // Test copying a user-defined int type using DataType::operator= - IntType orig_int(PredType::STD_B8LE); - DataType generic_type; - generic_type = orig_int; - - // Test copying an integer predefined type - IntType new_int_type(PredType::STD_B8LE); - - // Test copying an int predefined type using DataType::operator= - IntType another_int_type; - another_int_type = new_int_type; - - DataSpace space (1, &nelmts); - dset = new DataSet(grp.createDataSet("bitfield_1", type, space)); - - // Fill buffer - for (i=0; i<sizeof buf; i++) - buf[i] = static_cast<unsigned char>(0xff) ^ static_cast<unsigned char>(i); - - // Write data from buf using all default dataspaces and property list - dset->write (buf, type); - - // no failure in bitfield_1, close this dataset - delete dset; - } // end try block of bitfield_1 - - // catch exceptions thrown in try block of bitfield_1 - catch (Exception& E) - { - cerr << " FAILED" << endl; - cerr << " <<< " << "bitfield_1: " << E.getFuncName() - << " - " << E.getDetailMsg() << " >>>" << endl << endl; - if (dset != NULL) - delete dset; - return -1; - } - - /* bitfield_2 */ - nelmts = sizeof(buf)/2; - try { // bitfield_2 block - type.copy (PredType::STD_B16LE); - DataSpace space (1, &nelmts); - dset = new DataSet(grp.createDataSet("bitfield_2", type, space)); - - // Fill buffer - for (i=0; i<sizeof(buf); i++) - buf[i] = static_cast<unsigned char>(0xff) ^ static_cast<unsigned char>(i); - - // Write data from buf using all default dataspaces and property - // list; if writing fails, deallocate dset and return. - dset->write (buf, type); - - // no failure in bitfield_2, close this dataset and reset for - // variable reuse - delete dset; - dset = NULL; - } // end try block of bitfield_2 - - // catch exceptions thrown in try block of bitfield_2 - catch (Exception& E) - { - cerr << " FAILED" << endl; - cerr << " <<< " << "bitfield_2: " << E.getFuncName() - << " - " << E.getDetailMsg() << " >>>" << endl << endl; - if (dset != NULL) - delete dset; - throw E; // propagate the exception - } - - /* opaque_1 */ - DataType* optype = NULL; - try { // opaque_1 block - optype = new DataType(H5T_OPAQUE, 1); - nelmts = sizeof(buf); - DataSpace space (1, &nelmts); - optype->setTag ("testing 1-byte opaque type"); - dset = new DataSet(grp.createDataSet("opaque_1", *optype, space)); - - // Fill buffer - for (i=0; i<sizeof buf; i++) - buf[i] = static_cast<unsigned char>(0xff) ^ static_cast<unsigned char>(i); - - // Write data from buf using all default dataspaces and property - // list; if writing fails, deallocate dset and return. - dset->write (buf, *optype); - - // no failure in opaque_1 - delete dset; dset = NULL; - delete optype; optype = NULL; - } // end try block of opaque_1 - - // catch exceptions thrown in try block of opaque_1 - catch (Exception& E) - { - cerr << " FAILED" << endl; - cerr << " <<< " << "opaque_1: " << E.getFuncName() - << " - " << E.getDetailMsg() << " >>>" << endl << endl; - if (dset != NULL) - delete dset; - if (optype != NULL) - delete optype; - throw E; // propagate the exception - } - - /* opaque_2 */ - try { // block opaque_2 - nelmts = sizeof(buf)/4; - DataSpace space (1, &nelmts); - optype = new DataType(H5T_OPAQUE, 4); - optype->setTag ("testing 4-byte opaque type"); - dset = new DataSet(grp.createDataSet("opaque_2", *optype, space)); - - // Fill buffer - for (i=0; i<sizeof(buf); i++) - buf[i] = static_cast<unsigned char>(0xff) ^ static_cast<unsigned char>(i); - - // Write data from buf using all default dataspaces and property - // list; if writing fails, deallocate dset and return. - dset->write (buf, *optype); - - // no failure in opaque_1 - delete dset; dset = NULL; - delete optype; optype = NULL; - } //end try block of opaque_2 - - // catch exceptions thrown in try block of opaque_2 - catch (Exception& E) - { - cerr << " FAILED" << endl; - cerr << " <<< " << "opaque_2: " << E.getFuncName() - << " - " << E.getDetailMsg() << " >>>" << endl << endl; - if (dset != NULL) - delete dset; - if (optype != NULL) - delete optype; - throw E; // propagate the exception - } - - PASSED(); - return 0; + // Create a group in the file that was passed in from the caller + Group grp = file.createGroup ("typetests"); + + /* bitfield_1 */ + unsigned char buf[32]; + hsize_t nelmts = sizeof(buf); + DataType type; + try { // block of bitfield_1 + // test copying a predefined type + type.copy (PredType::STD_B8LE); + + // Test copying a user-defined type using DataType::copy + DataType copied_type; + copied_type.copy(type); + + // Test copying a user-defined type using DataType::operator= + DataType another_copied_type; + another_copied_type = type; + + // Test copying a user-defined int type using DataType::operator= + IntType orig_int(PredType::STD_B8LE); + DataType generic_type; + generic_type = orig_int; + + // Test copying an integer predefined type + IntType new_int_type(PredType::STD_B8LE); + + // Test copying an int predefined type using DataType::operator= + IntType another_int_type; + another_int_type = new_int_type; + + DataSpace space (1, &nelmts); + dset = new DataSet(grp.createDataSet("bitfield_1", type, space)); + + // Fill buffer + for (i=0; i<sizeof buf; i++) + buf[i] = static_cast<unsigned char>(0xff) ^ static_cast<unsigned char>(i); + + // Write data from buf using all default dataspaces and property list + dset->write (buf, type); + + // no failure in bitfield_1, close this dataset + delete dset; + } // end try block of bitfield_1 + + // catch exceptions thrown in try block of bitfield_1 + catch (Exception& E) + { + cerr << " FAILED" << endl; + cerr << " <<< " << "bitfield_1: " << E.getFuncName() + << " - " << E.getDetailMsg() << " >>>" << endl << endl; + if (dset != NULL) + delete dset; + return -1; + } + + /* bitfield_2 */ + nelmts = sizeof(buf)/2; + try { // bitfield_2 block + type.copy (PredType::STD_B16LE); + DataSpace space (1, &nelmts); + dset = new DataSet(grp.createDataSet("bitfield_2", type, space)); + + // Fill buffer + for (i=0; i<sizeof(buf); i++) + buf[i] = static_cast<unsigned char>(0xff) ^ static_cast<unsigned char>(i); + + // Write data from buf using all default dataspaces and property + // list; if writing fails, deallocate dset and return. + dset->write (buf, type); + + // no failure in bitfield_2, close this dataset and reset for + // variable reuse + delete dset; + dset = NULL; + } // end try block of bitfield_2 + + // catch exceptions thrown in try block of bitfield_2 + catch (Exception& E) + { + cerr << " FAILED" << endl; + cerr << " <<< " << "bitfield_2: " << E.getFuncName() + << " - " << E.getDetailMsg() << " >>>" << endl << endl; + if (dset != NULL) + delete dset; + throw E; // propagate the exception + } + + /* opaque_1 */ + DataType* optype = NULL; + try { // opaque_1 block + optype = new DataType(H5T_OPAQUE, 1); + nelmts = sizeof(buf); + DataSpace space (1, &nelmts); + optype->setTag ("testing 1-byte opaque type"); + dset = new DataSet(grp.createDataSet("opaque_1", *optype, space)); + + // Fill buffer + for (i=0; i<sizeof buf; i++) + buf[i] = static_cast<unsigned char>(0xff) ^ static_cast<unsigned char>(i); + + // Write data from buf using all default dataspaces and property + // list; if writing fails, deallocate dset and return. + dset->write (buf, *optype); + + // no failure in opaque_1 + delete dset; dset = NULL; + delete optype; optype = NULL; + } // end try block of opaque_1 + + // catch exceptions thrown in try block of opaque_1 + catch (Exception& E) + { + cerr << " FAILED" << endl; + cerr << " <<< " << "opaque_1: " << E.getFuncName() + << " - " << E.getDetailMsg() << " >>>" << endl << endl; + if (dset != NULL) + delete dset; + if (optype != NULL) + delete optype; + throw E; // propagate the exception + } + + /* opaque_2 */ + try { // block opaque_2 + nelmts = sizeof(buf)/4; + DataSpace space (1, &nelmts); + optype = new DataType(H5T_OPAQUE, 4); + optype->setTag ("testing 4-byte opaque type"); + dset = new DataSet(grp.createDataSet("opaque_2", *optype, space)); + + // Fill buffer + for (i=0; i<sizeof(buf); i++) + buf[i] = static_cast<unsigned char>(0xff) ^ static_cast<unsigned char>(i); + + // Write data from buf using all default dataspaces and property + // list; if writing fails, deallocate dset and return. + dset->write (buf, *optype); + + // no failure in opaque_1 + delete dset; dset = NULL; + delete optype; optype = NULL; + } //end try block of opaque_2 + + // catch exceptions thrown in try block of opaque_2 + catch (Exception& E) + { + cerr << " FAILED" << endl; + cerr << " <<< " << "opaque_2: " << E.getFuncName() + << " - " << E.getDetailMsg() << " >>>" << endl << endl; + if (dset != NULL) + delete dset; + if (optype != NULL) + delete optype; + throw E; // propagate the exception + } + + PASSED(); + return 0; } // end top try block catch (Exception& E) { - return -1; + return -1; } } // test_types /*------------------------------------------------------------------------- - * Function: test_dset + * Function: test_dset * - * Purpose: Tests the dataset interface (H5D) + * Purpose Tests the dataset interface (H5D) * - * Return: Success: 0 + * Return Success: 0 * - * Failure: -1 + * Failure: -1 * - * Programmer: Binh-Minh Ribler (using C version) - * Friday, January 5, 2001 + * Programmer Binh-Minh Ribler (using C version) + * Friday, January 5, 2001 * * Modifications: - * Nov 12, 01: - * - moved h5_cleanup to outside of try block because - * dataset.h5 cannot be removed until "file" is out of - * scope and dataset.h5 is closed. - * Feb 20, 05: - * - cleanup_dsets took care of the cleanup now. + * Nov 12, 01: + * - moved h5_cleanup to outside of try block because + * dataset.h5 cannot be removed until "file" is out of + * scope and dataset.h5 is closed. + * Feb 20, 05: + * - cleanup_dsets took care of the cleanup now. * *------------------------------------------------------------------------- */ extern "C" void test_dset() { - hid_t fapl_id; + hid_t fapl_id; fapl_id = h5_fileaccess(); // in h5test.c, returns a file access template - - int nerrors=0; // keep track of number of failures occurr + int nerrors=0; // keep track of number of failures occur 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); - H5File file(FILE1, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); + H5File file(FILE1, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); - // Cause the library to emit initial messages - Group grp = file.createGroup( "emit diagnostics", 0); - grp.setComment("Causes diagnostic messages to be emitted"); + // Cause the library to emit initial messages + Group grp = file.createGroup( "emit diagnostics", 0); + grp.setComment("Causes diagnostic messages to be emitted"); - nerrors += test_create(file) < 0 ? 1:0; - nerrors += test_simple_io(file) < 0 ? 1:0; - nerrors += test_tconv(file) < 0 ? 1:0; - nerrors += test_compression(file) < 0 ? 1:0; - nerrors += test_nbit_compression(file) < 0 ? 1:0; - nerrors += test_multiopen (file) < 0 ? 1:0; - nerrors += test_types(file) < 0 ? 1:0; + nerrors += test_create(file) < 0 ? 1:0; + nerrors += test_simple_io(file) < 0 ? 1:0; + nerrors += test_tconv(file) < 0 ? 1:0; + nerrors += test_compression(file) < 0 ? 1:0; + nerrors += test_nbit_compression(file) < 0 ? 1:0; + nerrors += test_multiopen (file) < 0 ? 1:0; + nerrors += test_types(file) < 0 ? 1:0; - // Close group "emit diagnostics". - grp.close(); + // Close group "emit diagnostics". + grp.close(); - // Close the file before testing data size. - file.close(); + // Close the file before testing data size. + file.close(); - nerrors += test_datasize(fapl) <0 ? 1:0; + nerrors += test_datasize(fapl) <0 ? 1:0; } catch (Exception& E) { - test_report(nerrors, H5std_string(" Dataset")); + test_report(nerrors, H5std_string(" Dataset")); } // Clean up data file @@ -1216,11 +1216,11 @@ void test_dset() /*------------------------------------------------------------------------- * Function: cleanup_dsets * - * Purpose: Cleanup temporary test files + * Purpose Cleanup temporary test files * - * Return: none + * Return none * - * Programmer: (use C version) + * Programmer (use C version) * * Modifications: * diff --git a/c++/test/h5cpputil.cpp b/c++/test/h5cpputil.cpp index 95d29a8..cf7fc2c 100644 --- a/c++/test/h5cpputil.cpp +++ b/c++/test/h5cpputil.cpp @@ -37,18 +37,18 @@ using namespace H5; #include "h5cpputil.h" // C++ utilility header file /*------------------------------------------------------------------------- - * Function: test_report + * Function: test_report * - * Purpose: Prints out the number of errors for the tests indicated - * by 'testname,' if there were any failures occurred. If - * no failure, test_report prints out the tests passed message. + * Purpose Prints out the number of errors for the tests indicated + * by 'testname,' if there were any failures occurred. If + * no failure, test_report prints out the tests passed message. * - * Return: if any failure has occurred: 1 + * Return if any failure has occurred: 1 * - * if no failure occurs: 0 + * if no failure occurs: 0 * - * Programmer: Binh-Minh Ribler (using C code segment for reporting tests) - * Friday, February 6, 2001 + * Programmer Binh-Minh Ribler (using C code segment for reporting tests) + * Friday, February 6, 2001 * * Modifications: * @@ -59,12 +59,12 @@ int test_report( int nerrors, const H5std_string& testname ) if (nerrors) { nerrors = MAX(1, nerrors); - if (1 == nerrors) - cerr << "***** " << nerrors << testname - << " TEST FAILED! *****" << endl; - else - cerr << "***** " << nerrors << testname - << " TESTS FAILED! *****" << endl; + if (1 == nerrors) + cerr << "***** " << nerrors << testname + << " TEST FAILED! *****" << endl; + else + cerr << "***** " << nerrors << testname + << " TESTS FAILED! *****" << endl; return 1; } else @@ -75,68 +75,68 @@ int test_report( int nerrors, const H5std_string& testname ) } /*------------------------------------------------------------------------- - * Function: issue_fail_msg + * Function: issue_fail_msg * - * Purpose: Displays that a function has failed with its location. + * Purpose Displays that a function has failed with its location. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (copied and modified macro CHECK from C) - * Monday, December 20, 2004 + * Programmer Binh-Minh Ribler (copied and modified macro CHECK from C) + * Monday, December 20, 2004 * *------------------------------------------------------------------------- */ void issue_fail_msg(const char* where, int line, const char* file_name, - const char* message) + const char* message) { if (GetTestVerbosity()>=VERBO_HI) { - cerr << endl; + cerr << endl; cerr << ">>> FAILED in " << where << " at line " << line << " in " << file_name << " - " << message << endl << endl; } } /*------------------------------------------------------------------------- - * Function: issue_fail_msg + * Function: issue_fail_msg * - * Purpose: Displays that a function has failed with its location. + * Purpose Displays that a function has failed with its location. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (copied and modified macro CHECK from C) - * Monday, December 20, 2004 + * Programmer Binh-Minh Ribler (copied and modified macro CHECK from C) + * Monday, December 20, 2004 * *------------------------------------------------------------------------- */ void issue_fail_msg(const char* where, int line, const char* file_name, - const char* func_name, const char* message) + const char* func_name, const char* message) { if (GetTestVerbosity()>=VERBO_HI) { - cerr << endl; + cerr << endl; cerr << ">>> FAILED in " << where << ": " << func_name << endl << - " at line " << line << " in " << file_name << endl << - " C library detail: " << message << endl << endl; + " at line " << line << " in " << file_name << endl << + " C library detail: " << message << endl << endl; } } /*------------------------------------------------------------------------- - * Function: check_values + * Function: check_values * - * Purpose: Checks a read value against the written value. If they are - * different, the function will print out a message and the - * different values. This function is made to reuse the code - * segment that is used in various places throughout - * the test code. Where the C version of this code segment - * "goto error," this function will return -1. + * Purpose Checks a read value against the written value. If they are + * different, the function will print out a message and the + * different values. This function is made to reuse the code + * segment that is used in various places throughout + * 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 + * Programmer Binh-Minh Ribler (using C code segment for checking values) + * Friday, February 6, 2001 * * Modifications: * @@ -146,26 +146,26 @@ int check_values (hsize_t i, hsize_t j, int apoint, int acheck) { if (apoint != acheck) { - cerr << " Read different values than written.\n" << endl; - cerr << " At index " << static_cast<unsigned long>(i) << "," << - static_cast<unsigned long>(j) << endl; - return -1; + cerr << " Read different values than written.\n" << endl; + cerr << " At index " << static_cast<unsigned long>(i) << "," << + static_cast<unsigned long>(j) << endl; + return -1; } return 0; } // check_values /*------------------------------------------------------------------------- - * Function: check_values + * Function: check_values * - * Purpose: Checks a char string pointer for NULL. If it is NULL, - * the function will print out a message + * Purpose Checks a char string pointer for NULL. If it is NULL, + * the function will print out a message * - * Return: Success: 0 + * Return Success: 0 * - * Failure: -1 + * Failure: -1 * - * Programmer: Binh-Minh Ribler (using C code segment for checking values) - * Friday, September 16, 2016 + * Programmer Binh-Minh Ribler (using C code segment for checking values) + * Friday, September 16, 2016 * *------------------------------------------------------------------------- */ @@ -173,26 +173,26 @@ void check_values(const char *value, const char* msg, int line, const char* file { if (value == NULL) { - cerr << endl; + cerr << endl; cerr << "*** ERROR: " << msg << ", at line " << line << endl; - IncTestNumErrs(); - throw TestFailedException(file_name, msg); + IncTestNumErrs(); + throw TestFailedException(file_name, msg); } } /*------------------------------------------------------------------------- - * Function: verify_val (const char*, const char*,...) + * Function: verify_val (const char*, const char*,...) * - * Purpose: Compares two character strings. If they are - * different, the function will print out a message and the - * different values. + * Purpose Compares two character strings. If they are + * different, the function will print out a message and the + * different values. * - * Return: Success: 0 + * Return Success: 0 * - * Failure: -1 + * Failure: -1 * - * Programmer: Binh-Minh Ribler - * May 2, 2010 + * Programmer Binh-Minh Ribler + * May 2, 2010 * * Modifications: * @@ -225,12 +225,12 @@ InvalidActionException::InvalidActionException():Exception(){} //-------------------------------------------------------------------------- // Function: InvalidActionException overloaded constructor // -// Purpose: Creates an InvalidActionException with the name of the function, +// Purpose Creates an InvalidActionException with the name of the function, // which the failure should have occurred but didn't, and a -// message explaining why it should fail. +// message explaining why it should fail. // Parameters -// func - IN: Name of the function where failure should occur -// message - IN: Message +// func - IN: Name of the function where failure should occur +// message - IN: Message //-------------------------------------------------------------------------- InvalidActionException::InvalidActionException(const H5std_string func, const H5std_string message) : Exception(func, message) {} @@ -247,12 +247,12 @@ TestFailedException::TestFailedException():Exception(){} //-------------------------------------------------------------------------- // Function: TestFailedException overloaded constructor // -// Purpose: Creates an TestFailedException with the name of the function, +// 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. +// message explaining why it should fail. // Parameters -// func - IN: Name of the function where failure should occur -// message - IN: Message +// func - IN: Name of the function where failure should occur +// message - IN: Message //-------------------------------------------------------------------------- TestFailedException::TestFailedException(const H5std_string func, const H5std_string message) : Exception(func, message) {} diff --git a/c++/test/h5cpputil.h b/c++/test/h5cpputil.h index f8aaec7..7f92e60 100644 --- a/c++/test/h5cpputil.h +++ b/c++/test/h5cpputil.h @@ -37,22 +37,22 @@ int check_values (hsize_t i, hsize_t j, int apoint, int acheck); void check_values(const char *value, const char* msg, int line, const char* file_name); int test_report (int, const H5std_string&); void issue_fail_msg(const char* where, int line, const char* file_name, - const char* message=""); + const char* message=""); void issue_fail_msg(const char* where, int line, const char* file_name, - const char* func_name, const char* message); + const char* func_name, const char* message); class InvalidActionException : public Exception { public: - InvalidActionException(const H5std_string func_name, const H5std_string message = DEFAULT_MSG); - InvalidActionException(); - virtual ~InvalidActionException() throw(); + InvalidActionException(const H5std_string func_name, const H5std_string message = DEFAULT_MSG); + InvalidActionException(); + virtual ~InvalidActionException() throw(); }; class TestFailedException : public Exception { public: - TestFailedException(const H5std_string func_name, const H5std_string message = DEFAULT_MSG); - TestFailedException(); - virtual ~TestFailedException() throw(); + TestFailedException(const H5std_string func_name, const H5std_string message = DEFAULT_MSG); + TestFailedException(); + virtual ~TestFailedException() throw(); }; // Overloaded/Template functions to verify values and display proper info @@ -65,18 +65,18 @@ template <class Type1, class Type2> { if (GetTestVerbosity()>=VERBO_HI) { - cerr << endl; + cerr << endl; cerr << " Call to routine: " << where << " at line " << line - << " in " << file_name << " had value " << x << endl; + << " in " << file_name << " had value " << x << endl; } if (x != value) { - cerr << endl; + cerr << endl; cerr << "*** UNEXPECTED VALUE from " << where << " should be " - << value << ", but is " << x << " at line " << line - << " in " << file_name << endl; - IncTestNumErrs(); - throw TestFailedException(where, ""); + << value << ", but is " << x << " at line " << line + << " in " << file_name << endl; + IncTestNumErrs(); + throw TestFailedException(where, ""); } } @@ -85,12 +85,12 @@ template <class Type1, class Type2> { if (x != value) { - cerr << endl; + cerr << endl; cerr << "*** UNEXPECTED VALUE: " << file_name << ":line " << line - << ": " << msg << " different: " << x << ", should be " << value - << endl; - IncTestNumErrs(); - throw TestFailedException(file_name, msg); + << ": " << msg << " different: " << x << ", should be " << value + << endl; + IncTestNumErrs(); + throw TestFailedException(file_name, msg); } } @@ -99,17 +99,17 @@ template <class Type1, class Type2> { if (GetTestVerbosity()>=VERBO_HI) { - cerr << endl; + cerr << endl; cerr << " Call to routine: " << where << " at line " << line - << " in " << file_name << " had value " << x << endl; + << " in " << file_name << " had value " << x << endl; } if (x == value) { - cerr << endl; + cerr << endl; cerr << "*** UNEXPECTED VALUE from " << where << " should not be " - << value << " at line " << line << " in " << file_name << endl; - IncTestNumErrs(); - throw TestFailedException(where, ""); + << value << " at line " << line << " in " << file_name << endl; + IncTestNumErrs(); + throw TestFailedException(where, ""); } } @@ -118,10 +118,10 @@ template <class Type1, class Type2> { if (x == value) { - cerr << endl; + cerr << endl; cerr << "*** Function " << msg << " FAILED at line " << line << endl; - IncTestNumErrs(); - throw TestFailedException(file_name, msg); + IncTestNumErrs(); + throw TestFailedException(file_name, msg); } } @@ -130,12 +130,12 @@ template <class Type1, class Type2> { if (x == value) { - cerr << endl; - cerr << "*** UNEXPECTED FLOAT VALUE: " << file_name << ":line " << line - << ": " << msg << " different: " << x << ", should be " << value - << " (epsilon=" << epsilon << ")" << endl; - IncTestNumErrs(); - throw TestFailedException(file_name, msg); + cerr << endl; + cerr << "*** UNEXPECTED FLOAT VALUE: " << file_name << ":line " << line + << ": " << msg << " different: " << x << ", should be " << value + << " (epsilon=" << epsilon << ")" << endl; + IncTestNumErrs(); + throw TestFailedException(file_name, msg); } } diff --git a/c++/test/tarray.cpp b/c++/test/tarray.cpp index f10016f..490772f 100644 --- a/c++/test/tarray.cpp +++ b/c++/test/tarray.cpp @@ -53,12 +53,12 @@ typedef enum int_t { /*------------------------------------------------------------------------- * Function: test_array_compound_array * - * Purpose: Tests 1-D array of compound datatypes (with array fields) + * Purpose Tests 1-D array of compound datatypes (with array fields) * - * Return: None. + * Return None. * - * Programmer: Binh-Minh Ribler (using C version) - * January, 2016 + * Programmer Binh-Minh Ribler (using C version) + * January, 2016 * * Modifications: * @@ -76,7 +76,7 @@ static void test_array_compound_array() hsize_t sdims1[] = {SPACE1_DIM1}; hsize_t tdims1[] = {ARRAY1_DIM1}; int nmemb; // Number of compound members - int ii; // counting variables + int ii; // counting variables hsize_t idxi, idxj, idxk; // dimension indicing variables H5T_class_t mclass; // Datatype class for field @@ -85,193 +85,193 @@ static void test_array_compound_array() for (idxj = 0; idxj < ARRAY1_DIM1; idxj++) { wdata[idxi][idxj].i = idxi * 10 + idxj; for(idxk = 0; idxk < ARRAY1_DIM1; idxk++) - { + { float temp = idxi * 10.0 + idxj * 2.5 + idxk; wdata[idxi][idxj].f[idxk] = temp; - } + } } // end for try { - // Create File - H5File file1(FILENAME, H5F_ACC_TRUNC); + // Create File + H5File file1(FILENAME, H5F_ACC_TRUNC); - // Create dataspace for datasets - DataSpace space(SPACE1_RANK, sdims1, NULL); + // Create dataspace for datasets + DataSpace space(SPACE1_RANK, sdims1, NULL); - /* - * Create an array datatype of compounds, arrtype. Each compound - * datatype, comptype, contains an integer and an array of floats, - * arrfltype. - */ + /* + * Create an array datatype of compounds, arrtype. Each compound + * datatype, comptype, contains an integer and an array of floats, + * arrfltype. + */ - // Create a compound datatype - CompType comptype(sizeof(s1_t)); + // Create a compound datatype + CompType comptype(sizeof(s1_t)); - // Insert integer field - comptype.insertMember("i", HOFFSET(s1_t, i), PredType::NATIVE_INT); + // Insert integer field + comptype.insertMember("i", HOFFSET(s1_t, i), PredType::NATIVE_INT); - // Create an array of floats datatype - ArrayType arrfltype(PredType::NATIVE_FLOAT, ARRAY1_RANK, tdims1); + // Create an array of floats datatype + ArrayType arrfltype(PredType::NATIVE_FLOAT, ARRAY1_RANK, tdims1); - // Insert float array field - comptype.insertMember("f", HOFFSET(s1_t, f), arrfltype); + // Insert float array field + comptype.insertMember("f", HOFFSET(s1_t, f), arrfltype); - // Close array of floats field datatype - arrfltype.close(); + // Close array of floats field datatype + arrfltype.close(); - // Create an array datatype of the compound datatype - ArrayType arrtype(comptype, ARRAY1_RANK, tdims1); + // Create an array datatype of the compound datatype + ArrayType arrtype(comptype, ARRAY1_RANK, tdims1); - // Close compound datatype comptype - comptype.close(); + // Close compound datatype comptype + comptype.close(); - // Create a dataset - DataSet dataset = file1.createDataSet("Dataset1", arrtype, space); + // Create a dataset + DataSet dataset = file1.createDataSet("Dataset1", arrtype, space); - // Write dataset to disk - dataset.write(wdata, arrtype); + // Write dataset to disk + dataset.write(wdata, arrtype); - // Test opening ArrayType with opening constructor (Dec 2016) + // Test opening ArrayType with opening constructor (Dec 2016) - // Commit the arrtype to give it a name - arrtype.commit(file1, ARRAYTYPE_NAME); + // Commit the arrtype to give it a name + arrtype.commit(file1, ARRAYTYPE_NAME); - // Close it, then re-open with the opening constructor - arrtype.close(); - ArrayType named_type(file1, ARRAYTYPE_NAME); + // Close it, then re-open with the opening constructor + arrtype.close(); + ArrayType named_type(file1, ARRAYTYPE_NAME); - // Get and verify the type's name - H5std_string type_name = named_type.getObjName(); - verify_val(type_name, ARRAYTYPE_NAME, "DataType::getObjName tests constructor", __LINE__, __FILE__); - named_type.close(); + // Get and verify the type's name + H5std_string type_name = named_type.getObjName(); + verify_val(type_name, ARRAYTYPE_NAME, "DataType::getObjName tests constructor", __LINE__, __FILE__); + named_type.close(); - // Close all - dataset.close(); - space.close(); - file1.close(); + // Close all + dataset.close(); + space.close(); + file1.close(); - // Re-open file - file1.openFile(FILENAME, H5F_ACC_RDONLY); + // Re-open file + file1.openFile(FILENAME, H5F_ACC_RDONLY); - // Open the dataset - dataset = file1.openDataSet("Dataset1"); + // Open the dataset + dataset = file1.openDataSet("Dataset1"); - /* - * Check the datatype array of compounds - */ + /* + * Check the datatype array of compounds + */ - // Verify that it is an array of compounds - DataType dstype = dataset.getDataType(); - mclass = dstype.getClass(); - verify_val(mclass==H5T_ARRAY, true, "f2_type.getClass", __LINE__, __FILE__); + // Verify that it is an array of compounds + DataType dstype = dataset.getDataType(); + mclass = dstype.getClass(); + verify_val(mclass==H5T_ARRAY, true, "f2_type.getClass", __LINE__, __FILE__); - dstype.close(); + dstype.close(); - // Get the array datatype to check - ArrayType atype_check = dataset.getArrayType(); + // Get the array datatype to check + ArrayType atype_check = dataset.getArrayType(); - // Check the array rank - int ndims = atype_check.getArrayNDims(); - verify_val(ndims, ARRAY1_RANK, "atype_check.getArrayNDims", __LINE__, __FILE__); + // Check the array rank + int ndims = atype_check.getArrayNDims(); + verify_val(ndims, ARRAY1_RANK, "atype_check.getArrayNDims", __LINE__, __FILE__); - // Get the array dimensions - hsize_t rdims1[H5S_MAX_RANK]; - atype_check.getArrayDims(rdims1); + // Get the array dimensions + hsize_t rdims1[H5S_MAX_RANK]; + atype_check.getArrayDims(rdims1); - // Check the array dimensions - for (ii =0; ii <ndims; ii++) - if (rdims1[ii]!=tdims1[ii]) { - TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%zd, tdims1[%d]=z%d\n", ii, rdims1[ii], ii, tdims1[ii]); + // Check the array dimensions + for (ii =0; ii <ndims; ii++) + if (rdims1[ii]!=tdims1[ii]) { + TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%zd, tdims1[%d]=z%d\n", ii, rdims1[ii], ii, tdims1[ii]); continue; } // end if - // Test ArrayType::ArrayType(const hid_t existing_id) - ArrayType new_arrtype(atype_check.getId()); + // Test ArrayType::ArrayType(const hid_t existing_id) + ArrayType new_arrtype(atype_check.getId()); - // Check the array rank - ndims = new_arrtype.getArrayNDims(); - verify_val(ndims, ARRAY1_RANK, "new_arrtype.getArrayNDims", __LINE__, __FILE__); + // Check the array rank + ndims = new_arrtype.getArrayNDims(); + verify_val(ndims, ARRAY1_RANK, "new_arrtype.getArrayNDims", __LINE__, __FILE__); - // Get the array dimensions - new_arrtype.getArrayDims(rdims1); + // Get the array dimensions + new_arrtype.getArrayDims(rdims1); - // Check the array dimensions - for (ii = 0; ii < ndims; ii++) - if (rdims1[ii] != tdims1[ii]) { - TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%zd, tdims1[%d]=%zd\n", ii, rdims1[ii], ii, tdims1[ii]); + // Check the array dimensions + for (ii = 0; ii < ndims; ii++) + if (rdims1[ii] != tdims1[ii]) { + TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%zd, tdims1[%d]=%zd\n", ii, rdims1[ii], ii, tdims1[ii]); continue; } // end if - /* - * Check the compound datatype and the array of floats datatype - * in the compound. - */ - // Get the compound datatype, which is the base datatype of the - // array datatype atype_check. - DataType base_type = atype_check.getSuper(); - mclass = base_type.getClass(); - verify_val(mclass==H5T_COMPOUND, true, "atype_check.getClass", __LINE__, __FILE__); - - // Verify the compound datatype info - CompType ctype_check(base_type.getId()); - base_type.close(); - - // Check the number of members - nmemb = ctype_check.getNmembers(); - verify_val(nmemb, 2, "ctype_check.getNmembers", __LINE__, __FILE__); - - // Check the 2nd field's name - H5std_string field2_name = ctype_check.getMemberName(1); - if (HDstrcmp(field2_name.c_str(),"f") != 0) - TestErrPrintf("Compound field name doesn't match!, field2_name=%s\n",field2_name.c_str()); - - // Get the 2nd field's datatype - DataType f2_type = ctype_check.getMemberDataType(1); - - // Get the 2nd field's class, this 2nd field should have an array type - mclass = f2_type.getClass(); - verify_val(mclass==H5T_ARRAY, true, "f2_type.getClass", __LINE__, __FILE__); - f2_type.close(); - - // Get the 2nd field, array of floats datatype, to check - ArrayType f2_atype_check = ctype_check.getMemberArrayType(1); - - // Check the array rank - ndims = f2_atype_check.getArrayNDims(); - verify_val(ndims, ARRAY1_RANK, "f2_atype_check.getArrayNDims", __LINE__, __FILE__); - - // Get the array dimensions - HDmemset(rdims1, 0, H5S_MAX_RANK); - f2_atype_check.getArrayDims(rdims1); - - // Check the array dimensions - for (ii = 0; ii < ndims; ii++) - if (rdims1[ii] != tdims1[ii]) { - TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%zd, tdims1[%d]=%zd\n", ii, rdims1[ii], ii, tdims1[ii]); - continue; - } // end if - - // Close done datatypes - f2_atype_check.close(); - ctype_check.close(); - - // Read dataset from disk - dataset.read(rdata, atype_check); - - // Compare data read in - for (idxi = 0; idxi < SPACE1_DIM1; idxi++) { - for (idxj = 0; idxj < ARRAY1_DIM1; idxj++) { - if (wdata[idxi][idxj].i != rdata[idxi][idxj].i) { - TestErrPrintf("Array data information doesn't match!, wdata[%d][%d].i=%d, rdata[%d][%d].i=%d\n",idxi,idxj,wdata[idxi][idxj].i,idxi,idxj,rdata[idxi][idxj].i); - continue; - } // end if - } // end for - } // end for - - // Close all - atype_check.close(); - dataset.close(); - file1.close(); + /* + * Check the compound datatype and the array of floats datatype + * in the compound. + */ + // Get the compound datatype, which is the base datatype of the + // array datatype atype_check. + DataType base_type = atype_check.getSuper(); + mclass = base_type.getClass(); + verify_val(mclass==H5T_COMPOUND, true, "atype_check.getClass", __LINE__, __FILE__); + + // Verify the compound datatype info + CompType ctype_check(base_type.getId()); + base_type.close(); + + // Check the number of members + nmemb = ctype_check.getNmembers(); + verify_val(nmemb, 2, "ctype_check.getNmembers", __LINE__, __FILE__); + + // Check the 2nd field's name + H5std_string field2_name = ctype_check.getMemberName(1); + if (HDstrcmp(field2_name.c_str(),"f") != 0) + TestErrPrintf("Compound field name doesn't match!, field2_name=%s\n",field2_name.c_str()); + + // Get the 2nd field's datatype + DataType f2_type = ctype_check.getMemberDataType(1); + + // Get the 2nd field's class, this 2nd field should have an array type + mclass = f2_type.getClass(); + verify_val(mclass==H5T_ARRAY, true, "f2_type.getClass", __LINE__, __FILE__); + f2_type.close(); + + // Get the 2nd field, array of floats datatype, to check + ArrayType f2_atype_check = ctype_check.getMemberArrayType(1); + + // Check the array rank + ndims = f2_atype_check.getArrayNDims(); + verify_val(ndims, ARRAY1_RANK, "f2_atype_check.getArrayNDims", __LINE__, __FILE__); + + // Get the array dimensions + HDmemset(rdims1, 0, H5S_MAX_RANK); + f2_atype_check.getArrayDims(rdims1); + + // Check the array dimensions + for (ii = 0; ii < ndims; ii++) + if (rdims1[ii] != tdims1[ii]) { + TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%zd, tdims1[%d]=%zd\n", ii, rdims1[ii], ii, tdims1[ii]); + continue; + } // end if + + // Close done datatypes + f2_atype_check.close(); + ctype_check.close(); + + // Read dataset from disk + dataset.read(rdata, atype_check); + + // Compare data read in + for (idxi = 0; idxi < SPACE1_DIM1; idxi++) { + for (idxj = 0; idxj < ARRAY1_DIM1; idxj++) { + if (wdata[idxi][idxj].i != rdata[idxi][idxj].i) { + TestErrPrintf("Array data information doesn't match!, wdata[%d][%d].i=%d, rdata[%d][%d].i=%d\n",idxi,idxj,wdata[idxi][idxj].i,idxi,idxj,rdata[idxi][idxj].i); + continue; + } // end if + } // end for + } // end for + + // Close all + atype_check.close(); + dataset.close(); + file1.close(); PASSED(); } // end of try block catch (Exception& E) @@ -285,15 +285,15 @@ static void test_array_compound_array() /*------------------------------------------------------------------------- * Function: test_array_assignment * - * Purpose: Tests the operator= + * Purpose Tests the operator= * - * Return: None. + * Return None. * - * Programmer: Binh-Minh Ribler (using C version) - * March, 2016 + * Programmer Binh-Minh Ribler (using C version) + * March, 2016 * * Description: - * Used user's sample code in HDFFV-9562 + * Used user's sample code in HDFFV-9562 * * Modifications: * @@ -317,35 +317,35 @@ static void test_array_assignment() SUBTEST("ArrayType::operator="); try { - // Create File - H5File file1(FILENAME, H5F_ACC_TRUNC); + // Create File + H5File file1(FILENAME, H5F_ACC_TRUNC); - // Create dataspace for datasets - DataSpace space(SPACE1_RANK, sdims1, NULL); + // Create dataspace for datasets + DataSpace space(SPACE1_RANK, sdims1, NULL); - /* - * Create an array datatype of compounds, arrtype. Each compound - * datatype, comptype, contains an integer and an array of floats, - * arrfltype. - */ + /* + * Create an array datatype of compounds, arrtype. Each compound + * datatype, comptype, contains an integer and an array of floats, + * arrfltype. + */ - // Create a compound datatype - CompType comptype(static_cast<size_t>(24)); + // Create a compound datatype + CompType comptype(static_cast<size_t>(24)); - // Insert integer field - comptype.insertMember("i", 0, PredType::NATIVE_INT); + // Insert integer field + comptype.insertMember("i", 0, PredType::NATIVE_INT); - // Insert float array field - comptype.insertMember("a", 4, getArr()); + // Insert float array field + comptype.insertMember("a", 4, getArr()); - // Create a dataset - DataSet dataset = file1.createDataSet("Dataset1", comptype, space); + // Create a dataset + DataSet dataset = file1.createDataSet("Dataset1", comptype, space); - // Close all - dataset.close(); - comptype.close(); - space.close(); - file1.close(); + // Close all + dataset.close(); + comptype.close(); + space.close(); + file1.close(); PASSED(); } // end of try block @@ -359,12 +359,12 @@ static void test_array_assignment() /*------------------------------------------------------------------------- * Function: test_array_info * - * Purpose: Tests getting array information using the const methods. + * Purpose Tests getting array information using the const methods. * - * Return: None. + * Return None. * - * Programmer: Binh-Minh Ribler - * April, 2016 + * Programmer Binh-Minh Ribler + * April, 2016 * * Modifications: * @@ -382,7 +382,7 @@ static void test_array_info() hsize_t sdims1[] = {SPACE1_DIM1}; hsize_t tdims1[] = {ARRAY1_DIM1}; int nmemb; // Number of compound members - int ii; // counting variables + int ii; // counting variables hsize_t idxi, idxj, idxk; // dimension indicing variables H5T_class_t mclass; // Datatype class for field @@ -391,84 +391,84 @@ static void test_array_info() for (idxj = 0; idxj < ARRAY1_DIM1; idxj++) { wdata[idxi][idxj].i = idxi * 10 + idxj; for(idxk = 0; idxk < ARRAY1_DIM1; idxk++) - { + { float temp = idxi * 10.0 + idxj * 2.5 + idxk; wdata[idxi][idxj].f[idxk] = temp; - } + } } // end for try { - // Create File - H5File file1(FILENAME, H5F_ACC_TRUNC); + // Create File + H5File file1(FILENAME, H5F_ACC_TRUNC); - // Create dataspace for datasets - DataSpace space(SPACE1_RANK, sdims1, NULL); + // Create dataspace for datasets + DataSpace space(SPACE1_RANK, sdims1, NULL); - /* - * Create some array datatypes, then close the file. - */ + /* + * Create some array datatypes, then close the file. + */ - // Create an array of floats datatype - ArrayType arrfltype(PredType::NATIVE_FLOAT, ARRAY1_RANK, tdims1); + // Create an array of floats datatype + ArrayType arrfltype(PredType::NATIVE_FLOAT, ARRAY1_RANK, tdims1); - // Create an array datatype of the compound datatype - ArrayType arrtype(PredType::NATIVE_UINT, ARRAY1_RANK, tdims1); + // Create an array datatype of the compound datatype + ArrayType arrtype(PredType::NATIVE_UINT, ARRAY1_RANK, tdims1); - // Create a dataset - DataSet dataset = file1.createDataSet("Dataset1", arrtype, space); + // Create a dataset + DataSet dataset = file1.createDataSet("Dataset1", arrtype, space); - // Write dataset to disk - dataset.write(wdata, arrtype); + // Write dataset to disk + dataset.write(wdata, arrtype); - // Close array of floats field datatype - arrfltype.close(); + // Close array of floats field datatype + arrfltype.close(); - // Close all - dataset.close(); - arrtype.close(); - space.close(); - file1.close(); + // Close all + dataset.close(); + arrtype.close(); + space.close(); + file1.close(); - // Re-open file - file1.openFile(FILENAME, H5F_ACC_RDONLY); + // Re-open file + file1.openFile(FILENAME, H5F_ACC_RDONLY); - // Open the dataset - dataset = file1.openDataSet("Dataset1"); + // Open the dataset + dataset = file1.openDataSet("Dataset1"); - /* - * Check the datatype array of compounds - */ + /* + * Check the datatype array of compounds + */ - // Verify that it is an array of compounds - DataType dstype = dataset.getDataType(); - mclass = dstype.getClass(); - verify_val(mclass==H5T_ARRAY, true, "f2_type.getClass", __LINE__, __FILE__); + // Verify that it is an array of compounds + DataType dstype = dataset.getDataType(); + mclass = dstype.getClass(); + verify_val(mclass==H5T_ARRAY, true, "f2_type.getClass", __LINE__, __FILE__); - dstype.close(); + dstype.close(); - { // Let atype_check go out of scope - // Get the array datatype, declared as const - const ArrayType atype_check = dataset.getArrayType(); + { // Let atype_check go out of scope + // Get the array datatype, declared as const + const ArrayType atype_check = dataset.getArrayType(); - // Check the array rank with the const method - int ndims = atype_check.getArrayNDims(); - verify_val(ndims, ARRAY1_RANK, "atype_check.getArrayNDims", __LINE__, __FILE__); + // Check the array rank with the const method + int ndims = atype_check.getArrayNDims(); + verify_val(ndims, ARRAY1_RANK, "atype_check.getArrayNDims", __LINE__, __FILE__); - // Get the array dimensions with the const method - hsize_t rdims1[H5S_MAX_RANK]; - atype_check.getArrayDims(rdims1); + // Get the array dimensions with the const method + hsize_t rdims1[H5S_MAX_RANK]; + atype_check.getArrayDims(rdims1); - // Check the array dimensions - for (ii =0; ii <ndims; ii++) - if (rdims1[ii]!=tdims1[ii]) { - TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%zd, tdims1[%d]=z%d\n", ii, rdims1[ii], ii, tdims1[ii]); + // Check the array dimensions + for (ii =0; ii <ndims; ii++) + if (rdims1[ii]!=tdims1[ii]) { + TestErrPrintf("Array dimension information doesn't match!, rdims1[%d]=%zd, tdims1[%d]=z%d\n", ii, rdims1[ii], ii, tdims1[ii]); continue; } // end if - } + } - // Close all - dataset.close(); - file1.close(); + // Close all + dataset.close(); + file1.close(); PASSED(); } // end of try block catch (Exception& E) @@ -503,14 +503,14 @@ void test_array() /*------------------------------------------------------------------------- - * Function: cleanup_array + * Function: cleanup_array * - * Purpose: Cleanup temporary test files + * Purpose Cleanup temporary test files * - * Return: none + * Return none * - * Programmer: Binh-Minh Ribler (using C version) - * January, 2016 + * Programmer Binh-Minh Ribler (using C version) + * January, 2016 * * Modifications: * diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index bc46d0f..0fcaf09 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -34,14 +34,14 @@ using namespace H5; #include "h5test.h" #include "h5cpputil.h" // C++ utilility header file -const H5std_string FILE_BASIC("tattr_basic.h5"); -const H5std_string FILE_COMPOUND("tattr_compound.h5"); -const H5std_string FILE_SCALAR("tattr_scalar.h5"); -const H5std_string FILE_MULTI("tattr_multi.h5"); -const H5std_string FILE_DTYPE("tattr_dtype.h5"); -const H5std_string ATTR_TMP_NAME("temp_attr_name"); -const H5std_string FATTR_TMP_NAME("temp_fattr_name"); -const size_t ATTR_MAX_DIMS = 7; +const H5std_string FILE_BASIC("tattr_basic.h5"); +const H5std_string FILE_COMPOUND("tattr_compound.h5"); +const H5std_string FILE_SCALAR("tattr_scalar.h5"); +const H5std_string FILE_MULTI("tattr_multi.h5"); +const H5std_string FILE_DTYPE("tattr_dtype.h5"); +const H5std_string ATTR_TMP_NAME("temp_attr_name"); +const H5std_string FATTR_TMP_NAME("temp_fattr_name"); +const size_t ATTR_MAX_DIMS = 7; /* 3-D dataset with fixed dimensions */ const int SPACE1_RANK = 3; @@ -97,7 +97,7 @@ struct attr4_struct { const H5std_string ATTR5_NAME("Attr5"); const int ATTR5_RANK = 0; -float attr_data5 = (float)-5.123; // Test data for 5th attribute +float attr_data5 = (float)-5.123; // Test data for 5th attribute /* Info for another attribute */ const H5std_string ATTR1A_NAME("Attr1_a"); @@ -121,117 +121,117 @@ static void test_attr_basic_write() SUBTEST("Basic Attribute Writing Functions"); try { - // Create file - H5File fid1 (FILE_BASIC, H5F_ACC_TRUNC); + // Create file + H5File fid1 (FILE_BASIC, H5F_ACC_TRUNC); - // Create dataspace for dataset - DataSpace ds_space (SPACE1_RANK, dims1); + // Create dataspace for dataset + DataSpace ds_space (SPACE1_RANK, dims1); - /* - * Test attribute with dataset - */ + /* + * Test attribute with dataset + */ - // Create a dataset - DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space); + // Create a dataset + DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space); - // Create dataspace for attribute - DataSpace att_space (ATTR1_RANK, dims2); + // Create dataspace for attribute + DataSpace att_space (ATTR1_RANK, dims2); - // Create a file attribute - Attribute file_attr2 = fid1.createAttribute (FATTR1_NAME, PredType::NATIVE_INT, att_space); + // Create a file attribute + Attribute file_attr2 = fid1.createAttribute (FATTR1_NAME, PredType::NATIVE_INT, att_space); - // Create a file attribute - Attribute file_attr1 = fid1.createAttribute (FATTR2_NAME, PredType::NATIVE_INT, att_space); + // Create a file attribute + Attribute file_attr1 = fid1.createAttribute (FATTR2_NAME, PredType::NATIVE_INT, att_space); - // Create an attribute for the dataset - Attribute ds_attr1 = dataset.createAttribute (ATTR1_NAME, PredType::NATIVE_INT, att_space); + // Create an attribute for the dataset + Attribute ds_attr1 = dataset.createAttribute (ATTR1_NAME, PredType::NATIVE_INT, att_space); - // Try creating an attribute that already exists. This should fail - // since two attributes cannot have the same name. If an exception - // is not thrown for this action by createAttribute, then throw an - // invalid action exception. - try { - Attribute invalid_attr = dataset.createAttribute (ATTR1_NAME, PredType::NATIVE_INT, att_space); + // Try creating an attribute that already exists. This should fail + // since two attributes cannot have the same name. If an exception + // is not thrown for this action by createAttribute, then throw an + // invalid action exception. + try { + Attribute invalid_attr = dataset.createAttribute (ATTR1_NAME, PredType::NATIVE_INT, att_space); - // continuation here, that means no exception has been thrown - throw InvalidActionException("H5File::createDataSet", "Library allowed overwrite of existing dataset"); - } - catch (AttributeIException& E) // catching invalid creating attribute + // continuation here, that means no exception has been thrown + throw InvalidActionException("H5File::createDataSet", "Library allowed overwrite of existing dataset"); + } + catch (AttributeIException& E) // catching invalid creating attribute {} // do nothing, exception expected - // Write attribute information - ds_attr1.write (PredType::NATIVE_INT, attr_data1); + // Write attribute information + ds_attr1.write (PredType::NATIVE_INT, attr_data1); - // Read attribute information immediately, without closing attribute - ds_attr1.read (PredType::NATIVE_INT, read_data1); + // Read attribute information immediately, without closing attribute + ds_attr1.read (PredType::NATIVE_INT, read_data1); - // Verify values read in - for(i=0; i<ATTR1_DIM1; i++) - if(attr_data1[i]!=read_data1[i]) - TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d,read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]); + // Verify values read in + for(i=0; i<ATTR1_DIM1; i++) + if(attr_data1[i]!=read_data1[i]) + TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d,read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]); - // Create two more attributes for this dataset, but only write to one. - Attribute ds_attr2 = dataset.createAttribute (ATTR2_NAME, PredType::NATIVE_INT, att_space); - Attribute ds_attr3 = dataset.createAttribute (ATTR3_NAME, PredType::NATIVE_INT, att_space); + // Create two more attributes for this dataset, but only write to one. + Attribute ds_attr2 = dataset.createAttribute (ATTR2_NAME, PredType::NATIVE_INT, att_space); + Attribute ds_attr3 = dataset.createAttribute (ATTR3_NAME, PredType::NATIVE_INT, att_space); - // Write attribute information - ds_attr2.write (PredType::NATIVE_INT, attr_data1a); + // Write attribute information + ds_attr2.write (PredType::NATIVE_INT, attr_data1a); - // Read attribute information immediately, without closing attribute - ds_attr2.read (PredType::NATIVE_INT, read_data1); + // Read attribute information immediately, without closing attribute + ds_attr2.read (PredType::NATIVE_INT, read_data1); - // Verify values read in - for(i=0; i<ATTR1_DIM1; i++) - if(attr_data1a[i]!=read_data1[i]) - TestErrPrintf("%d: attribute data different: attr_data1a[%d]=%d,read_data1[%d]=%d\n",__LINE__,i,attr_data1a[i],i,read_data1[i]); + // Verify values read in + for(i=0; i<ATTR1_DIM1; i++) + if(attr_data1a[i]!=read_data1[i]) + TestErrPrintf("%d: attribute data different: attr_data1a[%d]=%d,read_data1[%d]=%d\n",__LINE__,i,attr_data1a[i],i,read_data1[i]); - // Close both attributes - ds_attr1.close(); - ds_attr2.close(); - ds_attr3.close(); + // Close both attributes + ds_attr1.close(); + ds_attr2.close(); + ds_attr3.close(); - /* - * Test attribute with group - */ + /* + * Test attribute with group + */ - // Create group in file fid1 - Group group = fid1.createGroup (GROUP1_NAME); + // Create group in file fid1 + Group group = fid1.createGroup (GROUP1_NAME); - // Create dataspace for attribute - DataSpace sid3(ATTR2_RANK, dims3); + // Create dataspace for attribute + DataSpace sid3(ATTR2_RANK, dims3); - // Create an attribute for the group - Attribute gr_attr = group.createAttribute (ATTR2_NAME, PredType::NATIVE_INT, sid3); + // Create an attribute for the group + Attribute gr_attr = group.createAttribute (ATTR2_NAME, PredType::NATIVE_INT, sid3); - // Check storage size for attribute - hsize_t attr_size = gr_attr.getStorageSize(); - verify_val((long)attr_size, (long)(ATTR2_DIM1*ATTR2_DIM2*sizeof(int)), - "Attribute::getStorageSize",__LINE__,__FILE__); + // Check storage size for attribute + hsize_t attr_size = gr_attr.getStorageSize(); + verify_val((long)attr_size, (long)(ATTR2_DIM1*ATTR2_DIM2*sizeof(int)), + "Attribute::getStorageSize",__LINE__,__FILE__); - // Try to create the same attribute again (should fail) - try { - Attribute invalid_attr = group.createAttribute (ATTR2_NAME, PredType::NATIVE_INT, sid3); + // Try to create the same attribute again (should fail) + try { + Attribute invalid_attr = group.createAttribute (ATTR2_NAME, PredType::NATIVE_INT, sid3); // continuation here, that means no exception has been thrown throw InvalidActionException("H5Group::createAttribute", - "Attempting to create an existing attribute"); - } + "Attempting to create an existing attribute"); + } catch (AttributeIException& E) // catching invalid creating attribute {} // do nothing, exception expected - // Write attribute information - gr_attr.write (PredType::NATIVE_INT, attr_data2); + // Write attribute information + gr_attr.write (PredType::NATIVE_INT, attr_data2); - // Check storage size for attribute - attr_size = gr_attr.getStorageSize(); - verify_val((long)attr_size, (long)(ATTR2_DIM1*ATTR2_DIM2*sizeof(int)), - "Attribute::getStorageSize", __LINE__, __FILE__); + // Check storage size for attribute + attr_size = gr_attr.getStorageSize(); + verify_val((long)attr_size, (long)(ATTR2_DIM1*ATTR2_DIM2*sizeof(int)), + "Attribute::getStorageSize", __LINE__, __FILE__); - PASSED(); + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_basic_write()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_basic_write()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_basic_write() @@ -248,14 +248,14 @@ static void test_attr_basic_write() ** B. ssize_t Attribute::getName(H5std_string& attr_name, size_t buf_size) ** 1. With buffer smaller than the actual name ** 2. Same test but with retiring overloaded function -** ssize_t Attribute::getName(size_t buf_size, H5std_string& attr_name) +** ssize_t Attribute::getName(size_t buf_size, H5std_string& attr_name) ** ** C. H5std_string Attribute::getName() ** ** D. H5std_string Attribute::getName(size_t len) ** ** E. ssize_t Attribute::getName(H5std_string& attr_name, size_t buf_size) -** With buffer size equals the name's length, i.e., buf_size=0 +** With buffer size equals the name's length, i.e., buf_size=0 ** ****************************************************************/ static void test_attr_getname() @@ -264,109 +264,109 @@ static void test_attr_getname() SUBTEST("Testing all overloads of Attribute::getName"); try { - // - // Open the file FILE_BASIC and test getName with its attribute - // - - // Open file - H5File fid1(FILE_BASIC, H5F_ACC_RDWR); - - // Check for existence of attribute FATTR1_NAME - bool attr_exists = fid1.attrExists(FATTR1_NAME); - if (attr_exists == false) - throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not"); - - // Open attribute - Attribute fattr1(fid1.openAttribute(FATTR1_NAME)); - - // A. Get attribute name with - // ssize_t Attribute::getName(char* attr_name, size_t buf_size) - // using different buffer sizes and verify against FATTR1_NAME (3 cases) - - // 1. With arbitrary buf_size that is larger than the name size - size_t buf_size = FATTR1_NAME.length() + 10; - char* fattr1_name = new char[buf_size+1]; - HDmemset(fattr1_name, 0, buf_size+1); - ssize_t name_size = 0; // actual length of attribute name - name_size = fattr1.getName(fattr1_name, buf_size+1); - CHECK(name_size, FAIL, "Attribute::getName", __LINE__, __FILE__); - verify_val((size_t)name_size, FATTR1_NAME.length(), "Attribute::getName", __LINE__, __FILE__); - verify_val((const char*)fattr1_name, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); - delete []fattr1_name; - - // 2. With arbitrary buf_size that is smaller than the name's length. - // Let's try 4 first characters in the name. - buf_size = 4; - char short_name[5] = "File"; // to verify the read name - fattr1_name = new char[buf_size+1]; - HDmemset(fattr1_name, 0, buf_size+1); - name_size = fattr1.getName(fattr1_name, buf_size+1); - CHECK(name_size, FAIL, "Attribute::getName", __LINE__, __FILE__); - verify_val((size_t)name_size, FATTR1_NAME.size(), "Attribute::getName", __LINE__, __FILE__); - verify_val((const char*)fattr1_name, (const char*)short_name, "Attribute::getName", __LINE__, __FILE__); - delete []fattr1_name; - - // 3. With a buf_size that equals the name's length. - buf_size = FATTR1_NAME.length(); - fattr1_name = new char[buf_size+1]; - HDmemset(fattr1_name, 0, buf_size+1); - name_size = fattr1.getName(fattr1_name, buf_size+1); - CHECK(name_size, FAIL, "Attribute::getName", __LINE__, __FILE__); - verify_val(fattr1_name, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); - delete []fattr1_name; - - // B. Get attribute name with - // ssize_t Attribute::getName(H5std_string& attr_name, size_t buf_size) - // using buffer smaller than the actual name - buf_size = 4; - H5std_string fattr1_name2; - name_size = fattr1.getName(fattr1_name2, buf_size); - verify_val(fattr1_name2, "File", "Attribute::getName", __LINE__, __FILE__); - - // Same test as above, but with deprecated overloaded function - // ssize_t Attribute::getName(size_t buf_size, H5std_string& attr_name) - // using buffer smaller than the actual name - H5std_string fattr1_name2a; - name_size = fattr1.getName(fattr1_name2a, buf_size); - verify_val(fattr1_name2a, "File", "Attribute::getName", __LINE__, __FILE__); - - // C. Get file attribute's name with - // H5std_string Attribute::getName() - H5std_string fattr1_name3 = fattr1.getName(); - verify_val(fattr1_name3, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); - - // - // D. Test getName getting part of an attribute's name using - // H5std_string Attribute::getName(len) - // - - // Open dataset DSET1_NAME - DataSet dataset = fid1.openDataSet(DSET1_NAME); - - // Check for existence of attribute - attr_exists = dataset.attrExists(ATTR1_NAME); - if (attr_exists == false) - throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not"); - - // Open attribute - Attribute attr1(dataset.openAttribute(ATTR1_NAME)); - - size_t len = 4; - H5std_string dattr_name1 = attr1.getName(len); - verify_val(dattr_name1, "Attr", "Attribute::getName", __LINE__, __FILE__); - - // E. Get dataset's attribute name with - // H5std_string Attribute::getName(H5std_string attr_name, buf_size=0) - H5std_string dattr_name2; - name_size = attr1.getName(dattr_name2); - verify_val(dattr_name2, ATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); - - PASSED(); + // + // Open the file FILE_BASIC and test getName with its attribute + // + + // Open file + H5File fid1(FILE_BASIC, H5F_ACC_RDWR); + + // Check for existence of attribute FATTR1_NAME + bool attr_exists = fid1.attrExists(FATTR1_NAME); + if (attr_exists == false) + throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not"); + + // Open attribute + Attribute fattr1(fid1.openAttribute(FATTR1_NAME)); + + // A. Get attribute name with + // ssize_t Attribute::getName(char* attr_name, size_t buf_size) + // using different buffer sizes and verify against FATTR1_NAME (3 cases) + + // 1. With arbitrary buf_size that is larger than the name size + size_t buf_size = FATTR1_NAME.length() + 10; + char* fattr1_name = new char[buf_size+1]; + HDmemset(fattr1_name, 0, buf_size+1); + ssize_t name_size = 0; // actual length of attribute name + name_size = fattr1.getName(fattr1_name, buf_size+1); + CHECK(name_size, FAIL, "Attribute::getName", __LINE__, __FILE__); + verify_val((size_t)name_size, FATTR1_NAME.length(), "Attribute::getName", __LINE__, __FILE__); + verify_val((const char*)fattr1_name, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); + delete []fattr1_name; + + // 2. With arbitrary buf_size that is smaller than the name's length. + // Let's try 4 first characters in the name. + buf_size = 4; + char short_name[5] = "File"; // to verify the read name + fattr1_name = new char[buf_size+1]; + HDmemset(fattr1_name, 0, buf_size+1); + name_size = fattr1.getName(fattr1_name, buf_size+1); + CHECK(name_size, FAIL, "Attribute::getName", __LINE__, __FILE__); + verify_val((size_t)name_size, FATTR1_NAME.size(), "Attribute::getName", __LINE__, __FILE__); + verify_val((const char*)fattr1_name, (const char*)short_name, "Attribute::getName", __LINE__, __FILE__); + delete []fattr1_name; + + // 3. With a buf_size that equals the name's length. + buf_size = FATTR1_NAME.length(); + fattr1_name = new char[buf_size+1]; + HDmemset(fattr1_name, 0, buf_size+1); + name_size = fattr1.getName(fattr1_name, buf_size+1); + CHECK(name_size, FAIL, "Attribute::getName", __LINE__, __FILE__); + verify_val(fattr1_name, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); + delete []fattr1_name; + + // B. Get attribute name with + // ssize_t Attribute::getName(H5std_string& attr_name, size_t buf_size) + // using buffer smaller than the actual name + buf_size = 4; + H5std_string fattr1_name2; + name_size = fattr1.getName(fattr1_name2, buf_size); + verify_val(fattr1_name2, "File", "Attribute::getName", __LINE__, __FILE__); + + // Same test as above, but with deprecated overloaded function + // ssize_t Attribute::getName(size_t buf_size, H5std_string& attr_name) + // using buffer smaller than the actual name + H5std_string fattr1_name2a; + name_size = fattr1.getName(fattr1_name2a, buf_size); + verify_val(fattr1_name2a, "File", "Attribute::getName", __LINE__, __FILE__); + + // C. Get file attribute's name with + // H5std_string Attribute::getName() + H5std_string fattr1_name3 = fattr1.getName(); + verify_val(fattr1_name3, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); + + // + // D. Test getName getting part of an attribute's name using + // H5std_string Attribute::getName(len) + // + + // Open dataset DSET1_NAME + DataSet dataset = fid1.openDataSet(DSET1_NAME); + + // Check for existence of attribute + attr_exists = dataset.attrExists(ATTR1_NAME); + if (attr_exists == false) + throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not"); + + // Open attribute + Attribute attr1(dataset.openAttribute(ATTR1_NAME)); + + size_t len = 4; + H5std_string dattr_name1 = attr1.getName(len); + verify_val(dattr_name1, "Attr", "Attribute::getName", __LINE__, __FILE__); + + // E. Get dataset's attribute name with + // H5std_string Attribute::getName(H5std_string attr_name, buf_size=0) + H5std_string dattr_name2; + name_size = attr1.getName(dattr_name2); + verify_val(dattr_name2, ATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); + + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_getname()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_getname()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_getname() @@ -384,100 +384,100 @@ static void test_attr_rename() SUBTEST("Checking for Existence and Renaming Attribute"); try { - // Open file - H5File fid1(FILE_BASIC, H5F_ACC_RDWR); + // Open file + H5File fid1(FILE_BASIC, H5F_ACC_RDWR); - // Check and rename attribute belonging to a file + // Check and rename attribute belonging to a file - // Check for existence of attribute - bool attr_exists = fid1.attrExists(FATTR1_NAME); - if (attr_exists == false) - throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not"); + // Check for existence of attribute + bool attr_exists = fid1.attrExists(FATTR1_NAME); + if (attr_exists == false) + throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not"); - // Change attribute name - fid1.renameAttr(FATTR1_NAME, FATTR_TMP_NAME); + // Change attribute name + fid1.renameAttr(FATTR1_NAME, FATTR_TMP_NAME); - // Open attribute again - Attribute fattr1(fid1.openAttribute(FATTR_TMP_NAME)); + // Open attribute again + Attribute fattr1(fid1.openAttribute(FATTR_TMP_NAME)); - // Verify new attribute name - H5std_string fattr_name = fattr1.getName(); - verify_val(fattr_name, FATTR_TMP_NAME, "Attribute::getName", __LINE__, __FILE__); + // Verify new attribute name + H5std_string fattr_name = fattr1.getName(); + verify_val(fattr_name, FATTR_TMP_NAME, "Attribute::getName", __LINE__, __FILE__); - int num_attrs = fid1.getNumAttrs(); - verify_val(num_attrs, 2, "Attribute::getNumAttrs", __LINE__, __FILE__); + int num_attrs = fid1.getNumAttrs(); + verify_val(num_attrs, 2, "Attribute::getNumAttrs", __LINE__, __FILE__); - // Change first file attribute back to the original name - fid1.renameAttr(FATTR_TMP_NAME, FATTR1_NAME); + // Change first file attribute back to the original name + fid1.renameAttr(FATTR_TMP_NAME, FATTR1_NAME); - // Open the dataset - DataSet dataset = fid1.openDataSet(DSET1_NAME); + // Open the dataset + DataSet dataset = fid1.openDataSet(DSET1_NAME); - // Check and rename attribute belonging to a dataset + // Check and rename attribute belonging to a dataset - // Check for existence of attribute - attr_exists = dataset.attrExists(ATTR1_NAME); - if (attr_exists == false) - throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not"); + // Check for existence of attribute + attr_exists = dataset.attrExists(ATTR1_NAME); + if (attr_exists == false) + throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not"); - // Change attribute name - dataset.renameAttr(ATTR1_NAME, ATTR_TMP_NAME); + // Change attribute name + dataset.renameAttr(ATTR1_NAME, ATTR_TMP_NAME); - // Open attribute again - Attribute attr1(dataset.openAttribute(ATTR_TMP_NAME)); + // Open attribute again + Attribute attr1(dataset.openAttribute(ATTR_TMP_NAME)); - // Verify new attribute name - H5std_string attr_name = attr1.getName(); - verify_val(attr_name, ATTR_TMP_NAME, "Attribute::getName", __LINE__, __FILE__); + // Verify new attribute name + H5std_string attr_name = attr1.getName(); + verify_val(attr_name, ATTR_TMP_NAME, "Attribute::getName", __LINE__, __FILE__); - // Read attribute information immediately, without closing attribute - attr1.read (PredType::NATIVE_INT, read_data1); + // Read attribute information immediately, without closing attribute + attr1.read (PredType::NATIVE_INT, read_data1); - // Verify values read in - for(i=0; i<ATTR1_DIM1; i++) - if(attr_data1[i]!=read_data1[i]) - TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d,read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]); + // Verify values read in + for(i=0; i<ATTR1_DIM1; i++) + if(attr_data1[i]!=read_data1[i]) + TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d,read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]); - // Close attribute - attr1.close(); + // Close attribute + attr1.close(); - // Check for existence of second attribute - attr_exists = dataset.attrExists(ATTR2_NAME); - if (attr_exists == false) - throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not"); + // Check for existence of second attribute + attr_exists = dataset.attrExists(ATTR2_NAME); + if (attr_exists == false) + throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not"); - // Open the second attribute - Attribute attr2(dataset.openAttribute(ATTR2_NAME)); + // Open the second attribute + Attribute attr2(dataset.openAttribute(ATTR2_NAME)); - // Verify second attribute name - H5std_string attr2_name = attr2.getName(); - verify_val(attr2_name, ATTR2_NAME, "Attribute::getName", __LINE__, __FILE__); + // Verify second attribute name + H5std_string attr2_name = attr2.getName(); + verify_val(attr2_name, ATTR2_NAME, "Attribute::getName", __LINE__, __FILE__); - // Read attribute information immediately, without closing attribute - attr2.read (PredType::NATIVE_INT, read_data1); + // Read attribute information immediately, without closing attribute + attr2.read (PredType::NATIVE_INT, read_data1); - // Verify values read in - for(i=0; i<ATTR1_DIM1; i++) - if(attr_data1a[i]!=read_data1[i]) - TestErrPrintf("%d: attribute data different: attr_data1a[%d]=%d,read_data1[%d]=%d\n",__LINE__,i,attr_data1a[i],i,read_data1[i]); + // Verify values read in + for(i=0; i<ATTR1_DIM1; i++) + if(attr_data1a[i]!=read_data1[i]) + TestErrPrintf("%d: attribute data different: attr_data1a[%d]=%d,read_data1[%d]=%d\n",__LINE__,i,attr_data1a[i],i,read_data1[i]); - // Close attribute - attr2.close(); + // Close attribute + attr2.close(); - // Change first attribute back to the original name - dataset.renameAttr(ATTR_TMP_NAME, ATTR1_NAME); + // Change first attribute back to the original name + dataset.renameAttr(ATTR_TMP_NAME, ATTR1_NAME); - // Check for existence of attribute after renaming - attr_exists = dataset.attrExists(ATTR1_NAME); - if (attr_exists == false) - throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not"); + // Check for existence of attribute after renaming + attr_exists = dataset.attrExists(ATTR1_NAME); + if (attr_exists == false) + throw InvalidActionException("H5File::attrExists", "Attribute should exist but does not"); - PASSED(); + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_rename()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_rename()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_rename() @@ -494,59 +494,59 @@ static void test_attr_basic_read() SUBTEST("Basic Attribute Reading Functions"); try { - // Open file - H5File fid1(FILE_BASIC, H5F_ACC_RDWR); + // Open file + H5File fid1(FILE_BASIC, H5F_ACC_RDWR); - // Open the dataset - DataSet dataset = fid1.openDataSet(DSET1_NAME); + // Open the dataset + DataSet dataset = fid1.openDataSet(DSET1_NAME); - // Verify the correct number of attributes - int num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); + // Verify the correct number of attributes + int num_attrs = dataset.getNumAttrs(); + verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); - // Open an attribute for the dataset - Attribute ds_attr=dataset.openAttribute(ATTR1_NAME); + // Open an attribute for the dataset + Attribute ds_attr=dataset.openAttribute(ATTR1_NAME); - // Read attribute information - int read_data1[ATTR1_DIM1]={0}; // Buffer for reading 1st attribute - ds_attr.read(PredType::NATIVE_INT, &read_data1); + // Read attribute information + int read_data1[ATTR1_DIM1]={0}; // Buffer for reading 1st attribute + ds_attr.read(PredType::NATIVE_INT, &read_data1); - // Verify values read in - for(i=0; i<ATTR1_DIM1; i++) + // Verify values read in + for(i=0; i<ATTR1_DIM1; i++) if(attr_data1[i]!=read_data1[i]) - TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]); + TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d, read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]); - /* - * Test attribute with group - */ - // Open the group - Group group = fid1.openGroup(GROUP1_NAME); + /* + * Test attribute with group + */ + // Open the group + Group group = fid1.openGroup(GROUP1_NAME); - // Verify the correct number of attributes - num_attrs = group.getNumAttrs(); - verify_val(num_attrs, 1, "H5Group::getNumAttrs", __LINE__, __FILE__); + // Verify the correct number of attributes + num_attrs = group.getNumAttrs(); + verify_val(num_attrs, 1, "H5Group::getNumAttrs", __LINE__, __FILE__); - // Open an attribute for the group - Attribute gr_attr = group.openAttribute(ATTR2_NAME); + // Open an attribute for the group + Attribute gr_attr = group.openAttribute(ATTR2_NAME); - // Buffer for reading 2nd attribute - int read_data2[ATTR2_DIM1][ATTR2_DIM2]={{0}}; + // Buffer for reading 2nd attribute + int read_data2[ATTR2_DIM1][ATTR2_DIM2]={{0}}; - // Read attribute information - gr_attr.read(PredType::NATIVE_INT, read_data2); + // Read attribute information + gr_attr.read(PredType::NATIVE_INT, read_data2); - // Verify values read in - for(i=0; i<ATTR2_DIM1; i++) + // Verify values read in + for(i=0; i<ATTR2_DIM1; i++) for(j=0; j<ATTR2_DIM2; j++) - 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_data2[i][j]); - } - PASSED(); + 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_data2[i][j]); + } + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_basic_read()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_basic_read()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_basic_read() @@ -558,55 +558,55 @@ static void test_attr_basic_read() static void test_attr_compound_write() { - // Output message about test being performed + // Output message about test being performed SUBTEST("Multiple Attribute Functions"); try { - // Create file - H5File fid1(FILE_COMPOUND.c_str(), H5F_ACC_TRUNC); + // Create file + H5File fid1(FILE_COMPOUND.c_str(), H5F_ACC_TRUNC); - // Create dataspace for dataset - hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; - DataSpace sid1(SPACE1_RANK, dims1); + // Create dataspace for dataset + hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; + DataSpace sid1(SPACE1_RANK, dims1); - // Create a dataset - DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR,sid1); + // Create a dataset + DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR,sid1); - // Create the attribute datatype. - CompType comp_type(sizeof(struct attr4_struct)); + // Create the attribute datatype. + CompType comp_type(sizeof(struct attr4_struct)); - attr4_field1_off = HOFFSET(struct attr4_struct, i); - comp_type.insertMember(ATTR4_FIELDNAME1, attr4_field1_off, PredType::NATIVE_INT); + attr4_field1_off = HOFFSET(struct attr4_struct, i); + comp_type.insertMember(ATTR4_FIELDNAME1, attr4_field1_off, PredType::NATIVE_INT); - attr4_field2_off = HOFFSET(struct attr4_struct, d); - comp_type.insertMember(ATTR4_FIELDNAME2, attr4_field2_off, PredType::NATIVE_DOUBLE); + attr4_field2_off = HOFFSET(struct attr4_struct, d); + comp_type.insertMember(ATTR4_FIELDNAME2, attr4_field2_off, PredType::NATIVE_DOUBLE); - attr4_field3_off = HOFFSET(struct attr4_struct, c); - comp_type.insertMember(ATTR4_FIELDNAME3, attr4_field3_off, PredType::NATIVE_SCHAR); + attr4_field3_off = HOFFSET(struct attr4_struct, c); + comp_type.insertMember(ATTR4_FIELDNAME3, attr4_field3_off, PredType::NATIVE_SCHAR); - // Create dataspace for 1st attribute - hsize_t dims2[] = {ATTR4_DIM1,ATTR4_DIM2}; - DataSpace sid2(ATTR4_RANK, dims2); + // Create dataspace for 1st attribute + hsize_t dims2[] = {ATTR4_DIM1,ATTR4_DIM2}; + DataSpace sid2(ATTR4_RANK, dims2); - // Create complex attribute for the dataset - Attribute attr = dataset.createAttribute(ATTR4_NAME, comp_type, sid2); + // Create complex attribute for the dataset + Attribute attr = dataset.createAttribute(ATTR4_NAME, comp_type, sid2); - // Try to create the same attribute again (should fail) - try { - Attribute invalid_attr = dataset.createAttribute (ATTR4_NAME, comp_type, sid2); - } + // Try to create the same attribute again (should fail) + try { + Attribute invalid_attr = dataset.createAttribute (ATTR4_NAME, comp_type, sid2); + } catch (AttributeIException& E) // catching invalid creating attribute {} // do nothing, exception expected - // Write complex attribute data - attr.write(comp_type, attr_data4); + // Write complex attribute data + attr.write(comp_type, attr_data4); - PASSED(); + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_compound_write()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_compound_write()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_compound_write() @@ -617,7 +617,7 @@ static void test_attr_compound_write() ****************************************************************/ static void test_attr_compound_read() { - hsize_t dims[ATTR_MAX_DIMS]; // Attribute dimensions + hsize_t dims[ATTR_MAX_DIMS]; // Attribute dimensions size_t size; // Attribute datatype size as stored in file size_t offset; // Attribute datatype field offset struct attr4_struct read_data4[ATTR4_DIM1][ATTR4_DIM2]; // Buffer for reading 4th attribute @@ -626,139 +626,139 @@ static void test_attr_compound_read() SUBTEST("Basic Attribute Functions"); try { - // Open file - H5File fid1(FILE_COMPOUND, H5F_ACC_RDWR); + // Open file + H5File fid1(FILE_COMPOUND, H5F_ACC_RDWR); - // Open the dataset - DataSet dataset = fid1.openDataSet(DSET1_NAME); + // Open the dataset + DataSet dataset = fid1.openDataSet(DSET1_NAME); - // Verify the correct number of attributes - int num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__); + // Verify the correct number of attributes + int num_attrs = dataset.getNumAttrs(); + verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__); - // Open 1st attribute for the dataset - Attribute attr = dataset.openAttribute((unsigned)0); + // Open 1st attribute for the dataset + Attribute attr = dataset.openAttribute((unsigned)0); - /* Verify Dataspace */ + /* Verify Dataspace */ - // Get the dataspace of the attribute - DataSpace space = attr.getSpace(); + // Get the dataspace of the attribute + DataSpace space = attr.getSpace(); - // Get the rank of the dataspace and verify it - int rank = space.getSimpleExtentNdims(); - verify_val(rank, ATTR4_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); + // Get the rank of the dataspace and verify it + int rank = space.getSimpleExtentNdims(); + verify_val(rank, ATTR4_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); - // Get the dims of the dataspace and verify them - int ndims = space.getSimpleExtentDims(dims); - verify_val(ndims, ATTR4_RANK, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); + // Get the dims of the dataspace and verify them + int ndims = space.getSimpleExtentDims(dims); + verify_val(ndims, ATTR4_RANK, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); verify_val((long)dims[0], (long)ATTR4_DIM1, "DataSpace::getSimpleExtentDims",__LINE__, __FILE__); verify_val((long)dims[1], (long)ATTR4_DIM2, "DataSpace::getSimpleExtentDims",__LINE__, __FILE__); - // Get the class of the datatype that is used by attr - H5T_class_t type_class = attr.getTypeClass(); + // Get the class of the datatype that is used by attr + H5T_class_t type_class = attr.getTypeClass(); - // Verify that the type is of compound datatype - verify_val(type_class, H5T_COMPOUND, "Attribute::getTypeClass", __LINE__, __FILE__); + // Verify that the type is of compound datatype + verify_val(type_class, H5T_COMPOUND, "Attribute::getTypeClass", __LINE__, __FILE__); - // Get the compound datatype - CompType datatype = attr.getCompType(); + // Get the compound datatype + CompType datatype = attr.getCompType(); - // Verify the number of fields in the datatype, which must be 3 - int fields = datatype.getNmembers(); - verify_val(fields, 3, "CompType::getNmembers", __LINE__, __FILE__); + // Verify the number of fields in the datatype, which must be 3 + int fields = datatype.getNmembers(); + verify_val(fields, 3, "CompType::getNmembers", __LINE__, __FILE__); - // Verify that the fields have the same names as when the type - // was created - int j; - for(j=0; j<fields; j++) - { - H5std_string fieldname = datatype.getMemberName(j); - if(!((fieldname == ATTR4_FIELDNAME1) || - (fieldname == ATTR4_FIELDNAME2) || - (fieldname == ATTR4_FIELDNAME3))) + // Verify that the fields have the same names as when the type + // was created + int j; + for(j=0; j<fields; j++) + { + H5std_string fieldname = datatype.getMemberName(j); + if(!((fieldname == ATTR4_FIELDNAME1) || + (fieldname == ATTR4_FIELDNAME2) || + (fieldname == ATTR4_FIELDNAME3))) TestErrPrintf("%d:invalid field name for field #%d: %s\n",__LINE__,j,fieldname.c_str()); - } /* end for */ - - offset = datatype.getMemberOffset(0); - verify_val(offset, attr4_field1_off, "DataType::getMemberOffset", __LINE__, __FILE__); - - offset = datatype.getMemberOffset(1); - verify_val(offset, attr4_field2_off, "DataType::getMemberOffset", __LINE__, __FILE__); - - offset = datatype.getMemberOffset(2); - verify_val(offset, attr4_field3_off, "DataType::getMemberOffset", __LINE__, __FILE__); - - /* Verify each field's type, class & size */ - - // Get and verify the type class of the first member - type_class = datatype.getMemberClass(0); - verify_val(type_class, H5T_INTEGER, "DataType::getMemberClass", __LINE__, __FILE__); - // Get and verify the order of this member's type - IntType i_type = datatype.getMemberIntType(0); - H5T_order_t order = i_type.getOrder(); - verify_val(order, PredType::NATIVE_INT.getOrder(), "DataType::getOrder", __LINE__, __FILE__); - - // Get and verify the size of this member's type - size = i_type.getSize(); - verify_val(size, PredType::NATIVE_INT.getSize(), "DataType::getSize", __LINE__, __FILE__); - - // Get and verify class, order, and size of the second member's type - type_class = datatype.getMemberClass(1); - verify_val(type_class, H5T_FLOAT, "DataType::getMemberClass", __LINE__, __FILE__); - FloatType f_type = datatype.getMemberFloatType(1); - order = f_type.getOrder(); - verify_val(order, PredType::NATIVE_DOUBLE.getOrder(), "DataType::getOrder", __LINE__, __FILE__); - size = f_type.getSize(); - verify_val(size, PredType::NATIVE_DOUBLE.getSize(), "DataType::getSize", __LINE__, __FILE__); - - // Get and verify class, order, and size of the third member's type - type_class = datatype.getMemberClass(2); - verify_val(type_class, H5T_INTEGER, "DataType::getMemberClass", __LINE__, __FILE__); - // Note: H5T_INTEGER is correct here! - - StrType s_type = datatype.getMemberStrType(2); - order = s_type.getOrder(); - verify_val(order, PredType::NATIVE_SCHAR.getOrder(), "DataType::getOrder", __LINE__, __FILE__); - size = s_type.getSize(); - verify_val(size, PredType::NATIVE_SCHAR.getSize(), "DataType::getSize", __LINE__, __FILE__); - - // Read attribute information - attr.read(datatype, read_data4); - - // Verify values read in - hsize_t ii, jj; - for(ii=0; ii<ATTR4_DIM1; ii++) - for(jj=0; jj<ATTR4_DIM2; jj++) - if(HDmemcmp(&attr_data4[ii][jj],&read_data4[ii][jj],sizeof(struct attr4_struct))) { - TestErrPrintf("%d:attribute data different: attr_data4[%d][%d].i=%d, read_data4[%d][%d].i=%d\n",__LINE__,ii,jj,attr_data4[ii][jj].i,ii,jj,read_data4[ii][jj].i); - TestErrPrintf("%d:attribute data different: attr_data4[%d][%d].d=%f, read_data4[%d][%d].d=%f\n",__LINE__,ii,jj,attr_data4[ii][jj].d,ii,jj,read_data4[ii][jj].d); - TestErrPrintf("%d:attribute data different: attr_data4[%d][%d].c=%c, read_data4[%d][%d].c=%c\n",__LINE__,ii,jj,attr_data4[ii][jj].c,ii,jj,read_data4[ii][jj].c); + } /* end for */ + + offset = datatype.getMemberOffset(0); + verify_val(offset, attr4_field1_off, "DataType::getMemberOffset", __LINE__, __FILE__); + + offset = datatype.getMemberOffset(1); + verify_val(offset, attr4_field2_off, "DataType::getMemberOffset", __LINE__, __FILE__); + + offset = datatype.getMemberOffset(2); + verify_val(offset, attr4_field3_off, "DataType::getMemberOffset", __LINE__, __FILE__); + + /* Verify each field's type, class & size */ + + // Get and verify the type class of the first member + type_class = datatype.getMemberClass(0); + verify_val(type_class, H5T_INTEGER, "DataType::getMemberClass", __LINE__, __FILE__); + // Get and verify the order of this member's type + IntType i_type = datatype.getMemberIntType(0); + H5T_order_t order = i_type.getOrder(); + verify_val(order, PredType::NATIVE_INT.getOrder(), "DataType::getOrder", __LINE__, __FILE__); + + // Get and verify the size of this member's type + size = i_type.getSize(); + verify_val(size, PredType::NATIVE_INT.getSize(), "DataType::getSize", __LINE__, __FILE__); + + // Get and verify class, order, and size of the second member's type + type_class = datatype.getMemberClass(1); + verify_val(type_class, H5T_FLOAT, "DataType::getMemberClass", __LINE__, __FILE__); + FloatType f_type = datatype.getMemberFloatType(1); + order = f_type.getOrder(); + verify_val(order, PredType::NATIVE_DOUBLE.getOrder(), "DataType::getOrder", __LINE__, __FILE__); + size = f_type.getSize(); + verify_val(size, PredType::NATIVE_DOUBLE.getSize(), "DataType::getSize", __LINE__, __FILE__); + + // Get and verify class, order, and size of the third member's type + type_class = datatype.getMemberClass(2); + verify_val(type_class, H5T_INTEGER, "DataType::getMemberClass", __LINE__, __FILE__); + // Note: H5T_INTEGER is correct here! + + StrType s_type = datatype.getMemberStrType(2); + order = s_type.getOrder(); + verify_val(order, PredType::NATIVE_SCHAR.getOrder(), "DataType::getOrder", __LINE__, __FILE__); + size = s_type.getSize(); + verify_val(size, PredType::NATIVE_SCHAR.getSize(), "DataType::getSize", __LINE__, __FILE__); + + // Read attribute information + attr.read(datatype, read_data4); + + // Verify values read in + hsize_t ii, jj; + for(ii=0; ii<ATTR4_DIM1; ii++) + for(jj=0; jj<ATTR4_DIM2; jj++) + if(HDmemcmp(&attr_data4[ii][jj],&read_data4[ii][jj],sizeof(struct attr4_struct))) { + TestErrPrintf("%d:attribute data different: attr_data4[%d][%d].i=%d, read_data4[%d][%d].i=%d\n",__LINE__,ii,jj,attr_data4[ii][jj].i,ii,jj,read_data4[ii][jj].i); + TestErrPrintf("%d:attribute data different: attr_data4[%d][%d].d=%f, read_data4[%d][%d].d=%f\n",__LINE__,ii,jj,attr_data4[ii][jj].d,ii,jj,read_data4[ii][jj].d); + TestErrPrintf("%d:attribute data different: attr_data4[%d][%d].c=%c, read_data4[%d][%d].c=%c\n",__LINE__,ii,jj,attr_data4[ii][jj].c,ii,jj,read_data4[ii][jj].c); } /* end if */ - // Verify name - H5std_string attr_name = attr.getName(); - verify_val(attr_name, ATTR4_NAME, "Attribute::getName", __LINE__, __FILE__); + // Verify name + H5std_string attr_name = attr.getName(); + verify_val(attr_name, ATTR4_NAME, "Attribute::getName", __LINE__, __FILE__); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_compound_read()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_compound_read()", __LINE__, __FILE__, E.getCDetailMsg()); } try { - // Now, try truncating the file to make sure reference counting is good. - // If any references to ids in the previous block are left unterminated, - // the truncating will fail, because the file will not be closed in - // the file.close() above. - H5File file1(FILE_COMPOUND, H5F_ACC_TRUNC); + // Now, try truncating the file to make sure reference counting is good. + // If any references to ids in the previous block are left unterminated, + // the truncating will fail, because the file will not be closed in + // the file.close() above. + H5File file1(FILE_COMPOUND, H5F_ACC_TRUNC); - PASSED(); + PASSED(); } // end try block catch (FileIException& E) { - issue_fail_msg("test_attr_compound_read()", __LINE__, __FILE__, "Unable to truncate file, possibly because some objects are left opened"); + issue_fail_msg("test_attr_compound_read()", __LINE__, __FILE__, "Unable to truncate file, possibly because some objects are left opened"); } } // test_attr_compound_read() @@ -773,47 +773,47 @@ static void test_attr_scalar_write() SUBTEST("Basic Scalar Attribute Writing Functions"); try { - // Create file - H5File fid1(FILE_SCALAR, H5F_ACC_TRUNC); + // Create file + H5File fid1(FILE_SCALAR, H5F_ACC_TRUNC); - // Create dataspace for dataset - hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; - DataSpace sid1(SPACE1_RANK, dims1); + // Create dataspace for dataset + hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; + DataSpace sid1(SPACE1_RANK, dims1); - // Create a dataset - DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR,sid1); + // Create a dataset + DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR,sid1); - // Close dataset's dataspace - sid1.close(); + // Close dataset's dataspace + sid1.close(); - // Create dataspace for attribute - DataSpace att_space(ATTR5_RANK, NULL); + // Create dataspace for attribute + DataSpace att_space(ATTR5_RANK, NULL); - // Create an attribute for the dataset - Attribute ds_attr = dataset.createAttribute (ATTR5_NAME, PredType::NATIVE_FLOAT, att_space); + // Create an attribute for the dataset + Attribute ds_attr = dataset.createAttribute (ATTR5_NAME, PredType::NATIVE_FLOAT, att_space); - // Try creating an attribute that already exists. This should fail - // since two attributes cannot have the same name. If an exception - // is not thrown for this action by createAttribute, then throw an - // invalid action exception. - try { - Attribute invalid_attr = dataset.createAttribute (ATTR5_NAME, PredType::NATIVE_FLOAT, att_space); + // Try creating an attribute that already exists. This should fail + // since two attributes cannot have the same name. If an exception + // is not thrown for this action by createAttribute, then throw an + // invalid action exception. + try { + Attribute invalid_attr = dataset.createAttribute (ATTR5_NAME, PredType::NATIVE_FLOAT, att_space); - // continuation here, that means no exception has been thrown - throw InvalidActionException("H5File::createDataSet", "Library allowed overwrite of existing dataset"); - } - catch (AttributeIException& E) // catching invalid creating attribute + // continuation here, that means no exception has been thrown + throw InvalidActionException("H5File::createDataSet", "Library allowed overwrite of existing dataset"); + } + catch (AttributeIException& E) // catching invalid creating attribute {} // do nothing, exception expected - // Write attribute information - ds_attr.write (PredType::NATIVE_FLOAT, &attr_data5); + // Write attribute information + ds_attr.write (PredType::NATIVE_FLOAT, &attr_data5); - PASSED(); + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_scalar_write()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_scalar_write()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_scalar_write() @@ -831,38 +831,38 @@ static void test_attr_scalar_read() SUBTEST("Basic Scalar Attribute Reading Functions"); try { - // Open file - H5File fid1(FILE_SCALAR, H5F_ACC_RDWR); + // Open file + H5File fid1(FILE_SCALAR, H5F_ACC_RDWR); - // Open the dataset - DataSet dataset = fid1.openDataSet(DSET1_NAME); + // Open the dataset + DataSet dataset = fid1.openDataSet(DSET1_NAME); - // Verify the correct number of attributes - int num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__); + // Verify the correct number of attributes + int num_attrs = dataset.getNumAttrs(); + verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__); - // Open an attribute for the dataset - Attribute ds_attr=dataset.openAttribute(ATTR5_NAME); + // Open an attribute for the dataset + Attribute ds_attr=dataset.openAttribute(ATTR5_NAME); - // Read attribute information - float read_data2=0.0; // Buffer for reading 1st attribute - ds_attr.read(PredType::NATIVE_FLOAT,&read_data2); - if (HDfabs(read_data2 - attr_data5) > FP_EPSILON) - verify_val(read_data2, attr_data5, FP_EPSILON, "Attribute::read", __LINE__, __FILE__); + // Read attribute information + float read_data2=0.0; // Buffer for reading 1st attribute + ds_attr.read(PredType::NATIVE_FLOAT,&read_data2); + if (HDfabs(read_data2 - attr_data5) > FP_EPSILON) + verify_val(read_data2, attr_data5, FP_EPSILON, "Attribute::read", __LINE__, __FILE__); - // Get the dataspace of the attribute - DataSpace att_space = ds_attr.getSpace(); + // Get the dataspace of the attribute + DataSpace att_space = ds_attr.getSpace(); - // Make certain the dataspace is scalar - H5S_class_t space_type = att_space.getSimpleExtentType(); - verify_val(space_type, H5S_SCALAR, "DataSpace::getSimpleExtentType", __LINE__, __FILE__); + // 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(); + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_scalar_read()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_scalar_read()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_scalar_read() @@ -877,65 +877,65 @@ static void test_attr_mult_write() SUBTEST("Multiple Attribute Writing Functions"); try { - // Create file - H5File fid1 (FILE_MULTI, H5F_ACC_TRUNC); + // Create file + H5File fid1 (FILE_MULTI, H5F_ACC_TRUNC); - // Create dataspace for dataset - hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; - DataSpace ds_space (SPACE1_RANK, dims1); + // Create dataspace for dataset + hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; + DataSpace ds_space (SPACE1_RANK, dims1); - // Create a dataset - DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space); + // Create a dataset + DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space); - // Create dataspace for 1st attribute - hsize_t dims2[] = {ATTR1_DIM1}; - DataSpace att_space (ATTR1_RANK, dims2); + // Create dataspace for 1st attribute + hsize_t dims2[] = {ATTR1_DIM1}; + DataSpace att_space (ATTR1_RANK, dims2); - // Create 1st attribute for the dataset - Attribute ds_attr = dataset.createAttribute (ATTR1_NAME, PredType::NATIVE_INT, att_space); + // Create 1st attribute for the dataset + Attribute ds_attr = dataset.createAttribute (ATTR1_NAME, PredType::NATIVE_INT, att_space); - // Write attribute information - ds_attr.write (PredType::NATIVE_INT, attr_data1); + // Write attribute information + ds_attr.write (PredType::NATIVE_INT, attr_data1); - // Create dataspace for 2nd attribute - hsize_t dims3[] = {ATTR2_DIM1,ATTR2_DIM2}; - DataSpace att2_space (ATTR2_RANK, dims3); + // Create dataspace for 2nd attribute + hsize_t dims3[] = {ATTR2_DIM1,ATTR2_DIM2}; + DataSpace att2_space (ATTR2_RANK, dims3); - // Create 2nd attribute for the dataset - Attribute ds_attr2 = dataset.createAttribute (ATTR2_NAME, PredType::NATIVE_INT, att2_space); + // Create 2nd attribute for the dataset + Attribute ds_attr2 = dataset.createAttribute (ATTR2_NAME, PredType::NATIVE_INT, att2_space); - // Write 2nd attribute information - ds_attr2.write (PredType::NATIVE_INT, attr_data2); + // Write 2nd attribute information + ds_attr2.write (PredType::NATIVE_INT, attr_data2); - // Create dataspace for 3rd attribute - hsize_t dims4[] = {ATTR3_DIM1,ATTR3_DIM2,ATTR3_DIM3}; - DataSpace att3_space (ATTR3_RANK, dims4); + // Create dataspace for 3rd attribute + hsize_t dims4[] = {ATTR3_DIM1,ATTR3_DIM2,ATTR3_DIM3}; + DataSpace att3_space (ATTR3_RANK, dims4); - // Create 3rd attribute for the dataset - Attribute ds_attr3 = dataset.createAttribute (ATTR3_NAME, PredType::NATIVE_DOUBLE, att3_space); + // Create 3rd attribute for the dataset + Attribute ds_attr3 = dataset.createAttribute (ATTR3_NAME, PredType::NATIVE_DOUBLE, att3_space); - // Try creating an attribute that already exists. This should fail - // since two attributes cannot have the same name. If an exception - // is not thrown for this action by createAttribute, then throw an - // invalid action exception. - try { - Attribute invalid_attr = dataset.createAttribute (ATTR3_NAME, PredType::NATIVE_DOUBLE, att3_space); + // Try creating an attribute that already exists. This should fail + // since two attributes cannot have the same name. If an exception + // is not thrown for this action by createAttribute, then throw an + // invalid action exception. + try { + Attribute invalid_attr = dataset.createAttribute (ATTR3_NAME, PredType::NATIVE_DOUBLE, att3_space); - // continuation here, that means no exception has been thrown - throw InvalidActionException("DataSet::createAttribute", "Attempting to create a duplicate attribute"); - } - catch (AttributeIException& E) // catching invalid creating attribute + // continuation here, that means no exception has been thrown + throw InvalidActionException("DataSet::createAttribute", "Attempting to create a duplicate attribute"); + } + catch (AttributeIException& E) // catching invalid creating attribute {} // do nothing, exception expected - // Write 3rd attribute information - ds_attr3.write (PredType::NATIVE_DOUBLE, attr_data3); + // Write 3rd attribute information + ds_attr3.write (PredType::NATIVE_DOUBLE, attr_data3); - PASSED(); + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_mult_write()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_mult_write()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_mult_write() @@ -951,39 +951,39 @@ static void test_attr_mult_read() double read_data3[ATTR3_DIM1][ATTR3_DIM2][ATTR3_DIM3]={{{0}}}; // Buffer for reading 3rd attribute hsize_t i,j,k; - // Output message about test being performed + // Output message about test being performed SUBTEST("Multiple Attribute Reading Functions"); try { - // Open file - H5File fid1(FILE_MULTI, H5F_ACC_RDWR); + // Open file + H5File fid1(FILE_MULTI, H5F_ACC_RDWR); - // Open the dataset - DataSet dataset = fid1.openDataSet(DSET1_NAME); + // Open the dataset + DataSet dataset = fid1.openDataSet(DSET1_NAME); - // Verify the correct number of attributes - int num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); + // Verify the correct number of attributes + int num_attrs = dataset.getNumAttrs(); + verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); - // Open 1st attribute for the dataset - Attribute attr = dataset.openAttribute((unsigned)0); + // Open 1st attribute for the dataset + Attribute attr = dataset.openAttribute((unsigned)0); - /* Verify Dataspace */ + /* Verify Dataspace */ - // Get the dataspace of the attribute - DataSpace space = attr.getSpace(); + // Get the dataspace of the attribute + DataSpace space = attr.getSpace(); - // Get the rank of the dataspace and verify it - int rank = space.getSimpleExtentNdims(); - verify_val(rank, ATTR1_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); + // Get the rank of the dataspace and verify it + int rank = space.getSimpleExtentNdims(); + verify_val(rank, ATTR1_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); - // Get the dims of the dataspace and verify them - hsize_t dims[ATTR_MAX_DIMS]; // Attribute dimensions - int ndims = space.getSimpleExtentDims(dims); - if ((long)dims[0] != (long)ATTR1_DIM1) - TestErrPrintf("%d:attribute dimensions different: dims[0]=%d, should be %d\n",__LINE__,(int)dims[0],ATTR1_DIM1); + // Get the dims of the dataspace and verify them + hsize_t dims[ATTR_MAX_DIMS]; // Attribute dimensions + int ndims = space.getSimpleExtentDims(dims); + if ((long)dims[0] != (long)ATTR1_DIM1) + TestErrPrintf("%d:attribute dimensions different: dims[0]=%d, should be %d\n",__LINE__,(int)dims[0],ATTR1_DIM1); - /* Verify Datatype */ + /* Verify Datatype */ // Get the class of the datatype that is used by attr H5T_class_t type_class = attr.getTypeClass(); @@ -991,51 +991,51 @@ static void test_attr_mult_read() // Verify that the type is of integer datatype verify_val(type_class, H5T_INTEGER, "Attribute::getTypeClass", __LINE__, __FILE__); - // Get the integer datatype + // Get the integer datatype IntType i_type1 = attr.getIntType(); - // Get and verify the order of this type - H5T_order_t order = i_type1.getOrder(); - verify_val(order, PredType::NATIVE_INT.getOrder(), "DataType::getOrder", __LINE__, __FILE__); + // Get and verify the order of this type + H5T_order_t order = i_type1.getOrder(); + verify_val(order, PredType::NATIVE_INT.getOrder(), "DataType::getOrder", __LINE__, __FILE__); - // Get and verify the size of this type - size_t size = i_type1.getSize(); - verify_val(size, PredType::NATIVE_INT.getSize(), "DataType::getSize", __LINE__, __FILE__); + // Get and verify the size of this type + size_t size = i_type1.getSize(); + verify_val(size, PredType::NATIVE_INT.getSize(), "DataType::getSize", __LINE__, __FILE__); - // Read attribute information - attr.read(PredType::NATIVE_INT, read_data1); + // Read attribute information + attr.read(PredType::NATIVE_INT, read_data1); - // Verify values read in - for(i=0; i<ATTR1_DIM1; i++) - if(attr_data1[i]!=read_data1[i]) - TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d,read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]); + // Verify values read in + for(i=0; i<ATTR1_DIM1; i++) + if(attr_data1[i]!=read_data1[i]) + TestErrPrintf("%d: attribute data different: attr_data1[%d]=%d,read_data1[%d]=%d\n",__LINE__,i,attr_data1[i],i,read_data1[i]); - // Verify Name - H5std_string attr_name = attr.getName(); - verify_val(attr_name, ATTR1_NAME, "DataType::getName", __LINE__, __FILE__); + // Verify Name + H5std_string attr_name = attr.getName(); + verify_val(attr_name, ATTR1_NAME, "DataType::getName", __LINE__, __FILE__); - attr.close(); - space.close(); + attr.close(); + space.close(); - // Open 2nd attribute for the dataset - attr = dataset.openAttribute((unsigned)1); + // Open 2nd attribute for the dataset + attr = dataset.openAttribute((unsigned)1); - /* Verify Dataspace */ + /* Verify Dataspace */ - // Get the dataspace of the attribute - space = attr.getSpace(); + // Get the dataspace of the attribute + space = attr.getSpace(); - // Get the rank of the dataspace and verify it - rank = space.getSimpleExtentNdims(); - verify_val(rank, ATTR2_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); + // Get the rank of the dataspace and verify it + rank = space.getSimpleExtentNdims(); + verify_val(rank, ATTR2_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); - // Get the dims of the dataspace and verify them - ndims = space.getSimpleExtentDims(dims); + // Get the dims of the dataspace and verify them + ndims = space.getSimpleExtentDims(dims); verify_val((long)dims[0], (long)ATTR2_DIM1, "DataSpace::getSimpleExtentDims",__LINE__, __FILE__); verify_val((long)dims[1], (long)ATTR2_DIM2, "DataSpace::getSimpleExtentDims",__LINE__, __FILE__); - /* Verify Datatype */ + /* Verify Datatype */ // Get the class of the datatype that is used by attr type_class = attr.getTypeClass(); @@ -1043,52 +1043,52 @@ static void test_attr_mult_read() // Verify that the type is of integer datatype verify_val(type_class, H5T_INTEGER, "Attribute::getTypeClass", __LINE__, __FILE__); - // Get the integer datatype + // Get the integer datatype IntType i_type2 = attr.getIntType(); - // Get and verify the order of this type - order = i_type2.getOrder(); - verify_val(order, PredType::NATIVE_INT.getOrder(), "DataType::getOrder", __LINE__, __FILE__); + // Get and verify the order of this type + order = i_type2.getOrder(); + verify_val(order, PredType::NATIVE_INT.getOrder(), "DataType::getOrder", __LINE__, __FILE__); - // Get and verify the size of this type - size = i_type2.getSize(); - verify_val(size, PredType::NATIVE_INT.getSize(), "DataType::getSize", __LINE__, __FILE__); + // Get and verify the size of this type + size = i_type2.getSize(); + verify_val(size, PredType::NATIVE_INT.getSize(), "DataType::getSize", __LINE__, __FILE__); - // Read attribute information - attr.read(PredType::NATIVE_INT, read_data2); - //attr.read(i_type, read_data2); + // Read attribute information + attr.read(PredType::NATIVE_INT, read_data2); + //attr.read(i_type, read_data2); - // Verify values read in - for(i=0; i<ATTR2_DIM1; i++) - for(j=0; j<ATTR2_DIM2; j++) + // Verify values read in + for(i=0; i<ATTR2_DIM1; i++) + for(j=0; j<ATTR2_DIM2; j++) 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_data2[i][j]); - // Verify Name - attr_name = attr.getName(); - verify_val(attr_name, ATTR2_NAME, "DataType::getName", __LINE__, __FILE__); - attr.close(); - space.close(); + // Verify Name + attr_name = attr.getName(); + verify_val(attr_name, ATTR2_NAME, "DataType::getName", __LINE__, __FILE__); + attr.close(); + space.close(); - // Open 3rd attribute for the dataset - attr = dataset.openAttribute((unsigned)2); + // Open 3rd attribute for the dataset + attr = dataset.openAttribute((unsigned)2); - /* Verify Dataspace */ + /* Verify Dataspace */ - // Get the dataspace of the attribute - space = attr.getSpace(); + // Get the dataspace of the attribute + space = attr.getSpace(); - // Get the rank of the dataspace and verify it - rank = space.getSimpleExtentNdims(); - verify_val(rank, ATTR3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); + // Get the rank of the dataspace and verify it + rank = space.getSimpleExtentNdims(); + verify_val(rank, ATTR3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); - // Get the dims of the dataspace and verify them - ndims = space.getSimpleExtentDims(dims); - verify_val((long)dims[0],(long)ATTR3_DIM1,"attribute dimensions",__FILE__,__LINE__); - verify_val((long)dims[1],(long)ATTR3_DIM2,"attribute dimensions",__FILE__,__LINE__); - verify_val((long)dims[2],(long)ATTR3_DIM3,"attribute dimensions",__FILE__,__LINE__); + // Get the dims of the dataspace and verify them + ndims = space.getSimpleExtentDims(dims); + verify_val((long)dims[0],(long)ATTR3_DIM1,"attribute dimensions",__FILE__,__LINE__); + verify_val((long)dims[1],(long)ATTR3_DIM2,"attribute dimensions",__FILE__,__LINE__); + verify_val((long)dims[2],(long)ATTR3_DIM3,"attribute dimensions",__FILE__,__LINE__); - /* Verify Datatype */ + /* Verify Datatype */ // Get the class of the datatype that is used by attr type_class = attr.getTypeClass(); @@ -1096,44 +1096,44 @@ static void test_attr_mult_read() // Verify that the type is of compound datatype verify_val(type_class, H5T_FLOAT, "Attribute::getTypeClass", __LINE__, __FILE__); - // Get the double datatype + // Get the double datatype FloatType f_type = attr.getFloatType(); - // Get and verify the order of this type - order = f_type.getOrder(); - verify_val(order, PredType::NATIVE_DOUBLE.getOrder(), "DataType::getOrder", __LINE__, __FILE__); + // Get and verify the order of this type + order = f_type.getOrder(); + verify_val(order, PredType::NATIVE_DOUBLE.getOrder(), "DataType::getOrder", __LINE__, __FILE__); - // Get and verify the size of this type - size = f_type.getSize(); - verify_val(size, PredType::NATIVE_DOUBLE.getSize(), "DataType::getSize", __LINE__, __FILE__); + // Get and verify the size of this type + size = f_type.getSize(); + verify_val(size, PredType::NATIVE_DOUBLE.getSize(), "DataType::getSize", __LINE__, __FILE__); - // Read attribute information - attr.read(PredType::NATIVE_DOUBLE, read_data3); + // Read attribute information + attr.read(PredType::NATIVE_DOUBLE, read_data3); - // Verify values read in - for(i=0; i<ATTR3_DIM1; i++) - for(j=0; j<ATTR3_DIM2; j++) - for(k=0; k<ATTR3_DIM3; k++) - if(attr_data3[i][j][k]!=read_data3[i][j][k]) - TestErrPrintf("%d: attribute data different: attr_data3[%d][%d][%d]=%f, read_data3[%d][%d][%d]=%f\n",__LINE__,i,j,k,attr_data3[i][j][k],i,j,k,read_data3[i][j][k]); + // Verify values read in + for(i=0; i<ATTR3_DIM1; i++) + for(j=0; j<ATTR3_DIM2; j++) + for(k=0; k<ATTR3_DIM3; k++) + if(attr_data3[i][j][k]!=read_data3[i][j][k]) + TestErrPrintf("%d: attribute data different: attr_data3[%d][%d][%d]=%f, read_data3[%d][%d][%d]=%f\n",__LINE__,i,j,k,attr_data3[i][j][k],i,j,k,read_data3[i][j][k]); - // Verify Name - attr_name = attr.getName(); - verify_val(attr_name, ATTR3_NAME, "DataType::getName", __LINE__, __FILE__); + // Verify Name + attr_name = attr.getName(); + verify_val(attr_name, ATTR3_NAME, "DataType::getName", __LINE__, __FILE__); - PASSED(); + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_mult_read()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_mult_read()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_mult_read() /**************************************************************** ** ** test_attr_delete(): Test deleting attribute from different -** hdf5 objects. +** hdf5 objects. ** ****************************************************************/ static void test_attr_delete() @@ -1144,113 +1144,113 @@ static void test_attr_delete() SUBTEST("Removing Attribute Function"); try { - // Open file. - H5File fid1(FILE_BASIC, H5F_ACC_RDWR); - - // Get the number of file attributes - int num_attrs = fid1.getNumAttrs(); - verify_val(num_attrs, 2, "H5File::getNumAttrs", __LINE__, __FILE__); - - // Delete the second file attribute - fid1.removeAttr(FATTR2_NAME); - - // Get the number of file attributes - num_attrs = fid1.getNumAttrs(); - verify_val(num_attrs, 1, "H5File::getNumAttrs", __LINE__, __FILE__); - - // Verify the name of the only file attribute left - Attribute fattr = fid1.openAttribute((unsigned)0); - attr_name = fattr.getName(); - verify_val(attr_name, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); - fattr.close(); - - // Test deleting non-existing attribute - - // Open the dataset - DataSet dataset = fid1.openDataSet(DSET1_NAME); - - // Verify the correct number of attributes - num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); - - // Try to delete bogus attribute, should fail - try { - dataset.removeAttr("Bogus"); - - // continuation here, that means no exception has been thrown - throw InvalidActionException("DataSet::removeAttr", "Attempting to remove non-existing attribute"); - } - catch (AttributeIException& E) // catching invalid removing attribute + // Open file. + H5File fid1(FILE_BASIC, H5F_ACC_RDWR); + + // Get the number of file attributes + int num_attrs = fid1.getNumAttrs(); + verify_val(num_attrs, 2, "H5File::getNumAttrs", __LINE__, __FILE__); + + // Delete the second file attribute + fid1.removeAttr(FATTR2_NAME); + + // Get the number of file attributes + num_attrs = fid1.getNumAttrs(); + verify_val(num_attrs, 1, "H5File::getNumAttrs", __LINE__, __FILE__); + + // Verify the name of the only file attribute left + Attribute fattr = fid1.openAttribute((unsigned)0); + attr_name = fattr.getName(); + verify_val(attr_name, FATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); + fattr.close(); + + // Test deleting non-existing attribute + + // Open the dataset + DataSet dataset = fid1.openDataSet(DSET1_NAME); + + // Verify the correct number of attributes + num_attrs = dataset.getNumAttrs(); + verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); + + // Try to delete bogus attribute, should fail + try { + dataset.removeAttr("Bogus"); + + // continuation here, that means no exception has been thrown + throw InvalidActionException("DataSet::removeAttr", "Attempting to remove non-existing attribute"); + } + catch (AttributeIException& E) // catching invalid removing attribute {} // do nothing, exception expected - // Test deleting dataset's attributes + // Test deleting dataset's attributes - // Verify the correct number of attributes - num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); + // Verify the correct number of attributes + num_attrs = dataset.getNumAttrs(); + verify_val(num_attrs, 3, "DataSet::getNumAttrs", __LINE__, __FILE__); - // Delete middle (2nd) attribute - dataset.removeAttr(ATTR2_NAME); + // Delete middle (2nd) attribute + dataset.removeAttr(ATTR2_NAME); - // Verify the correct number of attributes - num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 2, "DataSet::getNumAttrs", __LINE__, __FILE__); + // Verify the correct number of attributes + num_attrs = dataset.getNumAttrs(); + verify_val(num_attrs, 2, "DataSet::getNumAttrs", __LINE__, __FILE__); - // Open 1st attribute for the dataset - Attribute attr = dataset.openAttribute((unsigned)0); + // Open 1st attribute for the dataset + Attribute attr = dataset.openAttribute((unsigned)0); - // Verify Name - attr_name = attr.getName(); - verify_val(attr_name, ATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); + // Verify Name + attr_name = attr.getName(); + verify_val(attr_name, ATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); - // Close attribute - attr.close(); + // Close attribute + attr.close(); - // Open last (formally 3rd) attribute for the dataset - attr = dataset.openAttribute((unsigned)1); + // Open last (formally 3rd) attribute for the dataset + attr = dataset.openAttribute((unsigned)1); - // Verify Name - attr_name = attr.getName(); - verify_val(attr_name, ATTR3_NAME, "Attribute::getName", __LINE__, __FILE__); + // Verify Name + attr_name = attr.getName(); + verify_val(attr_name, ATTR3_NAME, "Attribute::getName", __LINE__, __FILE__); - attr.close(); + attr.close(); - // Delete first attribute - dataset.removeAttr(ATTR1_NAME); + // Delete first attribute + dataset.removeAttr(ATTR1_NAME); - // Verify the correct number of attributes - num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__); + // Verify the correct number of attributes + num_attrs = dataset.getNumAttrs(); + verify_val(num_attrs, 1, "DataSet::getNumAttrs", __LINE__, __FILE__); - // Open the only attribute for the dataset (formally 3rd) - attr = dataset.openAttribute((unsigned)0); + // Open the only attribute for the dataset (formally 3rd) + attr = dataset.openAttribute((unsigned)0); - // Verify Name - attr_name = attr.getName(); - verify_val(attr_name, ATTR3_NAME, "Attribute::getName", __LINE__, __FILE__); - // Close attribute - attr.close(); + // Verify Name + attr_name = attr.getName(); + verify_val(attr_name, ATTR3_NAME, "Attribute::getName", __LINE__, __FILE__); + // Close attribute + attr.close(); - // Delete first attribute - dataset.removeAttr(ATTR3_NAME); + // Delete first attribute + dataset.removeAttr(ATTR3_NAME); - // Verify the correct number of attributes - num_attrs = dataset.getNumAttrs(); - verify_val(num_attrs, 0, "DataSet::getNumAttrs", __LINE__, __FILE__); + // Verify the correct number of attributes + num_attrs = dataset.getNumAttrs(); + verify_val(num_attrs, 0, "DataSet::getNumAttrs", __LINE__, __FILE__); - PASSED(); + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_delete()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_delete()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_delete() /**************************************************************** ** ** test_attr_dtype_shared(): Test code for using shared datatypes -** in attributes. +** in attributes. ** ****************************************************************/ static void test_attr_dtype_shared() @@ -1266,142 +1266,142 @@ static void test_attr_dtype_shared() SUBTEST("Shared Datatypes with Attributes"); try { - // Create a file - H5File fid1(FILE_DTYPE, H5F_ACC_TRUNC); + // Create a file + H5File fid1(FILE_DTYPE, H5F_ACC_TRUNC); - // Close file - fid1.close(); + // Close file + fid1.close(); - // Get size of file - h5_stat_size_t empty_filesize; // Size of empty file - empty_filesize = h5_get_file_size(FILE_DTYPE.c_str(), H5P_DEFAULT); - if (empty_filesize < 0) + // Get size of file + h5_stat_size_t empty_filesize; // Size of empty file + empty_filesize = h5_get_file_size(FILE_DTYPE.c_str(), H5P_DEFAULT); + if (empty_filesize < 0) TestErrPrintf("Line %d: file size wrong!\n", __LINE__); - // Open the file again - fid1.openFile(FILE_DTYPE, H5F_ACC_RDWR); + // Open the file again + fid1.openFile(FILE_DTYPE, H5F_ACC_RDWR); - // Enclosing to work around the issue of unused variables and/or - // objects created by copy constructors stay around until end of - // scope, causing incorrect number of ref counts. - { // First enclosed block + // Enclosing to work around the issue of unused variables and/or + // objects created by copy constructors stay around until end of + // scope, causing incorrect number of ref counts. + { // First enclosed block - // Create a datatype to commit and use - IntType dtype(PredType::NATIVE_INT); + // Create a datatype to commit and use + IntType dtype(PredType::NATIVE_INT); - // Commit datatype to file - dtype.commit(fid1, TYPE1_NAME); + // Commit datatype to file + dtype.commit(fid1, TYPE1_NAME); #ifndef H5_NO_DEPRECATED_SYMBOLS - // Check reference count on named datatype - fid1.getObjinfo(TYPE1_NAME, statbuf); - verify_val((int)statbuf.nlink, 1, "DataType::getObjinfo", __LINE__, __FILE__); + // Check reference count on named datatype + fid1.getObjinfo(TYPE1_NAME, statbuf); + verify_val((int)statbuf.nlink, 1, "DataType::getObjinfo", __LINE__, __FILE__); #endif /* H5_NO_DEPRECATED_SYMBOLS */ - // Create dataspace for dataset - DataSpace dspace; + // Create dataspace for dataset + DataSpace dspace; - DataSet dset = fid1.createDataSet(DSET1_NAME, dtype, dspace); + DataSet dset = fid1.createDataSet(DSET1_NAME, dtype, dspace); #ifndef H5_NO_DEPRECATED_SYMBOLS - // Check reference count on named datatype - fid1.getObjinfo(TYPE1_NAME, statbuf); - verify_val((int)statbuf.nlink, 2, "H5File::getObjinfo", __LINE__, __FILE__); + // Check reference count on named datatype + fid1.getObjinfo(TYPE1_NAME, statbuf); + verify_val((int)statbuf.nlink, 2, "H5File::getObjinfo", __LINE__, __FILE__); #endif /* H5_NO_DEPRECATED_SYMBOLS */ - // Create attribute on dataset - Attribute attr = dset.createAttribute(ATTR1_NAME,dtype,dspace); + // Create attribute on dataset + Attribute attr = dset.createAttribute(ATTR1_NAME,dtype,dspace); #ifndef H5_NO_DEPRECATED_SYMBOLS - // Check reference count on named datatype - fid1.getObjinfo(TYPE1_NAME, statbuf); - verify_val((int)statbuf.nlink, 3, "DataSet::getObjinfo", __LINE__, __FILE__); + // Check reference count on named datatype + fid1.getObjinfo(TYPE1_NAME, statbuf); + verify_val((int)statbuf.nlink, 3, "DataSet::getObjinfo", __LINE__, __FILE__); #endif /* H5_NO_DEPRECATED_SYMBOLS */ // Close attribute attr.close(); - // Delete attribute - dset.removeAttr(ATTR1_NAME); + // Delete attribute + dset.removeAttr(ATTR1_NAME); #ifndef H5_NO_DEPRECATED_SYMBOLS - // Check reference count on named datatype - fid1.getObjinfo(TYPE1_NAME, statbuf); - verify_val((int)statbuf.nlink, 2, "DataSet::getObjinfo after DataSet::removeAttr", __LINE__, __FILE__); + // Check reference count on named datatype + fid1.getObjinfo(TYPE1_NAME, statbuf); + verify_val((int)statbuf.nlink, 2, "DataSet::getObjinfo after DataSet::removeAttr", __LINE__, __FILE__); #endif /* H5_NO_DEPRECATED_SYMBOLS */ // Create attribute on dataset attr = dset.createAttribute(ATTR1_NAME,dtype,dspace); #ifndef H5_NO_DEPRECATED_SYMBOLS - // Check reference count on named datatype - fid1.getObjinfo(TYPE1_NAME, statbuf); - verify_val((int)statbuf.nlink, 3, "DataSet::createAttribute", __LINE__, __FILE__); + // Check reference count on named datatype + fid1.getObjinfo(TYPE1_NAME, statbuf); + verify_val((int)statbuf.nlink, 3, "DataSet::createAttribute", __LINE__, __FILE__); #endif /* H5_NO_DEPRECATED_SYMBOLS */ - // Write data into the attribute - attr.write(PredType::NATIVE_INT,&data); + // Write data into the attribute + attr.write(PredType::NATIVE_INT,&data); - // Close attribute, dataset, dataspace, datatype, and file - attr.close(); - dset.close(); - dspace.close(); - dtype.close(); - } // end of first enclosing + // Close attribute, dataset, dataspace, datatype, and file + attr.close(); + dset.close(); + dspace.close(); + dtype.close(); + } // end of first enclosing - fid1.close(); + fid1.close(); - // Open the file again - fid1.openFile(FILE_DTYPE, H5F_ACC_RDWR); + // Open the file again + fid1.openFile(FILE_DTYPE, H5F_ACC_RDWR); - { // Second enclosed block... + { // Second enclosed block... - // Open dataset - DataSet *dset2 = new DataSet (fid1.openDataSet(DSET1_NAME)); + // Open dataset + DataSet *dset2 = new DataSet (fid1.openDataSet(DSET1_NAME)); - // Open attribute - Attribute *attr2 = new Attribute (dset2->openAttribute(ATTR1_NAME)); + // Open attribute + Attribute *attr2 = new Attribute (dset2->openAttribute(ATTR1_NAME)); - // Read data from the attribute - attr2->read(PredType::NATIVE_INT, &rdata); - verify_val(data, rdata, "Attribute::read", __LINE__, __FILE__); + // Read data from the attribute + attr2->read(PredType::NATIVE_INT, &rdata); + verify_val(data, rdata, "Attribute::read", __LINE__, __FILE__); - // Close attribute and dataset - delete attr2; - delete dset2; + // Close attribute and dataset + delete attr2; + delete dset2; #ifndef H5_NO_DEPRECATED_SYMBOLS - // Check reference count on named datatype - fid1.getObjinfo(TYPE1_NAME, statbuf); - verify_val((int)statbuf.nlink, 3, "DataSet::openAttribute", __LINE__, __FILE__); + // Check reference count on named datatype + fid1.getObjinfo(TYPE1_NAME, statbuf); + verify_val((int)statbuf.nlink, 3, "DataSet::openAttribute", __LINE__, __FILE__); #endif /* H5_NO_DEPRECATED_SYMBOLS */ - } // end of second enclosing + } // end of second enclosing - // Unlink the dataset - fid1.unlink(DSET1_NAME); + // Unlink the dataset + fid1.unlink(DSET1_NAME); #ifndef H5_NO_DEPRECATED_SYMBOLS - // Check reference count on named datatype - fid1.getObjinfo(TYPE1_NAME, statbuf); - verify_val((int)statbuf.nlink, 1, "H5File::unlink", __LINE__, __FILE__); + // Check reference count on named datatype + fid1.getObjinfo(TYPE1_NAME, statbuf); + verify_val((int)statbuf.nlink, 1, "H5File::unlink", __LINE__, __FILE__); #endif /* H5_NO_DEPRECATED_SYMBOLS */ - // Unlink the named datatype - fid1.unlink(TYPE1_NAME); + // Unlink the named datatype + fid1.unlink(TYPE1_NAME); - // Close file - fid1.close(); + // Close file + fid1.close(); - // Check size of file - filesize = h5_get_file_size(FILE_DTYPE.c_str(), H5P_DEFAULT); - verify_val((long)filesize, (long)empty_filesize, "Checking file size", __LINE__, __FILE__); + // Check size of file + filesize = h5_get_file_size(FILE_DTYPE.c_str(), H5P_DEFAULT); + verify_val((long)filesize, (long)empty_filesize, "Checking file size", __LINE__, __FILE__); - PASSED(); + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_dtype_shared()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_dtype_shared()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_dtype_shared() @@ -1424,116 +1424,116 @@ static void test_string_attr() SUBTEST("I/O on FL and VL String Attributes"); try { - // Create file - H5File fid1(FILE_BASIC, H5F_ACC_RDWR); - - // - // Fixed-lenth string attributes - // - // Create a fixed-length string datatype to refer to. - StrType fls_type(0, ATTR_LEN); - - // Open the root group. - Group root = fid1.openGroup("/"); - - // Create dataspace for the attribute. - DataSpace att_space (H5S_SCALAR); - - /* Test Attribute::write(...,const void *buf) with Fixed len string */ - - // Create an attribute for the root group. - Attribute gr_flattr1 = root.createAttribute(ATTR1_FL_STR_NAME, fls_type, att_space); - - // Write data to the attribute. - gr_flattr1.write(fls_type, ATTRSTR_DATA.c_str()); - - /* Test Attribute::write(...,const H5std_string& strg) with FL string */ - - // Create an attribute for the root group. - Attribute gr_flattr2 = root.createAttribute(ATTR2_FL_STR_NAME, fls_type, att_space); - - // Write data to the attribute. - gr_flattr2.write(fls_type, ATTRSTR_DATA); - - /* Test Attribute::read(...,void *buf) with FL string */ - - // Read and verify the attribute string as a string of chars. - char flstring_att_check[ATTR_LEN]; - gr_flattr1.read(fls_type, flstring_att_check); - if(HDstrcmp(flstring_att_check, ATTRSTR_DATA.c_str())!=0) - TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), flstring_att_check); - - // Read and verify the attribute string as a string of chars; buffer - // is dynamically allocated. - size_t attr_size = gr_flattr1.getInMemDataSize(); - char *fl_dyn_string_att_check; - fl_dyn_string_att_check = new char[attr_size+1]; - gr_flattr1.read(fls_type, fl_dyn_string_att_check); - if(HDstrcmp(fl_dyn_string_att_check, ATTRSTR_DATA.c_str())!=0) - TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), fl_dyn_string_att_check); - delete []fl_dyn_string_att_check; - - /* Test Attribute::read(...,H5std_string& strg) with FL string */ - - // Read and verify the attribute string as an std::string. - H5std_string read_flstr1; - gr_flattr1.read(fls_type, read_flstr1); - if (read_flstr1 != ATTRSTR_DATA) - TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_flstr1=%s\n",__LINE__, ATTRSTR_DATA.c_str(), read_flstr1.c_str()); - - // Read and verify the attribute string as a string of chars. - HDstrcpy(flstring_att_check, ""); - gr_flattr2.read(fls_type, flstring_att_check); - if(HDstrcmp(flstring_att_check, ATTRSTR_DATA.c_str())!=0) - TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), flstring_att_check); - - /* Test Attribute::read(...,H5std_string& strg) with FL string */ - - // Read and verify the attribute string as an std::string. - H5std_string read_flstr2; - gr_flattr2.read(fls_type, read_flstr2); - if (read_flstr2 != ATTRSTR_DATA) - TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_flstr2=%s\n",__LINE__, ATTRSTR_DATA.c_str(), read_flstr2.c_str()); - - // - // Variable-lenth string attributes - // - // Create a variable length string datatype to refer to. - StrType vls_type(0, H5T_VARIABLE); - - // Create an attribute for the root group. - Attribute gr_vlattr = root.createAttribute(ATTR_VL_STR_NAME, vls_type, att_space); - - // Write data to the attribute. - gr_vlattr.write(vls_type, ATTRSTR_DATA); - - /* Test Attribute::read(...,void *buf) with Variable len string */ - // Read and verify the attribute string as a string of chars. - char *string_att_check; - gr_vlattr.read(vls_type, &string_att_check); - if(HDstrcmp(string_att_check, ATTRSTR_DATA.c_str())!=0) - TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,string_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), string_att_check); - HDfree(string_att_check); - - /* Test Attribute::read(...,H5std_string& strg) with VL string */ - // Read and verify the attribute string as an std::string. - H5std_string read_str; - gr_vlattr.read(vls_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(); + // Create file + H5File fid1(FILE_BASIC, H5F_ACC_RDWR); + + // + // Fixed-lenth string attributes + // + // Create a fixed-length string datatype to refer to. + StrType fls_type(0, ATTR_LEN); + + // Open the root group. + Group root = fid1.openGroup("/"); + + // Create dataspace for the attribute. + DataSpace att_space (H5S_SCALAR); + + /* Test Attribute::write(...,const void *buf) with Fixed len string */ + + // Create an attribute for the root group. + Attribute gr_flattr1 = root.createAttribute(ATTR1_FL_STR_NAME, fls_type, att_space); + + // Write data to the attribute. + gr_flattr1.write(fls_type, ATTRSTR_DATA.c_str()); + + /* Test Attribute::write(...,const H5std_string& strg) with FL string */ + + // Create an attribute for the root group. + Attribute gr_flattr2 = root.createAttribute(ATTR2_FL_STR_NAME, fls_type, att_space); + + // Write data to the attribute. + gr_flattr2.write(fls_type, ATTRSTR_DATA); + + /* Test Attribute::read(...,void *buf) with FL string */ + + // Read and verify the attribute string as a string of chars. + char flstring_att_check[ATTR_LEN]; + gr_flattr1.read(fls_type, flstring_att_check); + if(HDstrcmp(flstring_att_check, ATTRSTR_DATA.c_str())!=0) + TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), flstring_att_check); + + // Read and verify the attribute string as a string of chars; buffer + // is dynamically allocated. + size_t attr_size = gr_flattr1.getInMemDataSize(); + char *fl_dyn_string_att_check; + fl_dyn_string_att_check = new char[attr_size+1]; + gr_flattr1.read(fls_type, fl_dyn_string_att_check); + if(HDstrcmp(fl_dyn_string_att_check, ATTRSTR_DATA.c_str())!=0) + TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), fl_dyn_string_att_check); + delete []fl_dyn_string_att_check; + + /* Test Attribute::read(...,H5std_string& strg) with FL string */ + + // Read and verify the attribute string as an std::string. + H5std_string read_flstr1; + gr_flattr1.read(fls_type, read_flstr1); + if (read_flstr1 != ATTRSTR_DATA) + TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_flstr1=%s\n",__LINE__, ATTRSTR_DATA.c_str(), read_flstr1.c_str()); + + // Read and verify the attribute string as a string of chars. + HDstrcpy(flstring_att_check, ""); + gr_flattr2.read(fls_type, flstring_att_check); + if(HDstrcmp(flstring_att_check, ATTRSTR_DATA.c_str())!=0) + TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,flstring_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), flstring_att_check); + + /* Test Attribute::read(...,H5std_string& strg) with FL string */ + + // Read and verify the attribute string as an std::string. + H5std_string read_flstr2; + gr_flattr2.read(fls_type, read_flstr2); + if (read_flstr2 != ATTRSTR_DATA) + TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,read_flstr2=%s\n",__LINE__, ATTRSTR_DATA.c_str(), read_flstr2.c_str()); + + // + // Variable-lenth string attributes + // + // Create a variable length string datatype to refer to. + StrType vls_type(0, H5T_VARIABLE); + + // Create an attribute for the root group. + Attribute gr_vlattr = root.createAttribute(ATTR_VL_STR_NAME, vls_type, att_space); + + // Write data to the attribute. + gr_vlattr.write(vls_type, ATTRSTR_DATA); + + /* Test Attribute::read(...,void *buf) with Variable len string */ + // Read and verify the attribute string as a string of chars. + char *string_att_check; + gr_vlattr.read(vls_type, &string_att_check); + if(HDstrcmp(string_att_check, ATTRSTR_DATA.c_str())!=0) + TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,string_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), string_att_check); + HDfree(string_att_check); + + /* Test Attribute::read(...,H5std_string& strg) with VL string */ + // Read and verify the attribute string as an std::string. + H5std_string read_str; + gr_vlattr.read(vls_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("test_string_attr()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_string_attr()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_string_attr() /**************************************************************** ** ** test_attr_exists(): Test checking for attribute existence. -** (additional attrExists tests are in test_attr_rename()) +** (additional attrExists tests are in test_attr_rename()) ** ****************************************************************/ static void test_attr_exists() @@ -1542,40 +1542,40 @@ static void test_attr_exists() SUBTEST("Check Attribute Existence"); try { - // Open file. - H5File fid1(FILE_BASIC, H5F_ACC_RDWR); + // Open file. + H5File fid1(FILE_BASIC, H5F_ACC_RDWR); - // Open the root group. - Group root = fid1.openGroup("/"); + // Open the root group. + Group root = fid1.openGroup("/"); - // Check for existence of attribute - bool attr_exists = fid1.attrExists(ATTR1_FL_STR_NAME); - if (attr_exists == false) - throw InvalidActionException("H5File::attrExists", "fid1, ATTR1_FL_STR_NAMEAttribute should exist but does not"); + // Check for existence of attribute + bool attr_exists = fid1.attrExists(ATTR1_FL_STR_NAME); + if (attr_exists == false) + throw InvalidActionException("H5File::attrExists", "fid1, ATTR1_FL_STR_NAMEAttribute should exist but does not"); - // Check for existence of attribute - attr_exists = fid1.attrExists(FATTR1_NAME); - if (attr_exists == false) - throw InvalidActionException("H5File::attrExists", "fid1,FATTR2_NAMEAttribute should exist but does not"); + // Check for existence of attribute + attr_exists = fid1.attrExists(FATTR1_NAME); + if (attr_exists == false) + throw InvalidActionException("H5File::attrExists", "fid1,FATTR2_NAMEAttribute should exist but does not"); - // Open a group. - Group group = fid1.openGroup(GROUP1_NAME); + // Open a group. + Group group = fid1.openGroup(GROUP1_NAME); - // Check for existence of attribute - attr_exists = group.attrExists(ATTR2_NAME); - if (attr_exists == false) - throw InvalidActionException("H5File::attrExists", "group, ATTR2_NAMEAttribute should exist but does not"); + // Check for existence of attribute + attr_exists = group.attrExists(ATTR2_NAME); + if (attr_exists == false) + throw InvalidActionException("H5File::attrExists", "group, ATTR2_NAMEAttribute should exist but does not"); - PASSED(); + PASSED(); } // end try block catch (InvalidActionException& E) { - issue_fail_msg("test_attr_exists()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_exists()", __LINE__, __FILE__, E.getCDetailMsg()); } catch (Exception& E) { - issue_fail_msg("test_attr_exists()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_exists()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_exists() @@ -1591,100 +1591,100 @@ const unsigned MAX_COMPACT_DEF = 8; const unsigned MIN_DENSE_DEF = 6; static void test_attr_dense_create(FileCreatPropList& fcpl, - FileAccPropList& fapl) + FileAccPropList& fapl) { // Output message about test being performed SUBTEST("Dense Attribute Storage Creation"); try { - // Create file - H5File fid1 (FILE_CRTPROPS, H5F_ACC_TRUNC, fcpl, fapl); + // Create file + H5File fid1 (FILE_CRTPROPS, H5F_ACC_TRUNC, fcpl, fapl); - // Close file - fid1.close(); + // Close file + fid1.close(); - // Get size of file - h5_stat_size_t empty_filesize; // Size of empty file - empty_filesize = h5_get_file_size(FILE_CRTPROPS.c_str(), fapl.getId()); - if (empty_filesize < 0) + // Get size of file + h5_stat_size_t empty_filesize; // Size of empty file + empty_filesize = h5_get_file_size(FILE_CRTPROPS.c_str(), fapl.getId()); + if (empty_filesize < 0) TestErrPrintf("Line %d: file size wrong!\n", __LINE__); - // Re-open file - fid1.openFile(FILE_CRTPROPS, H5F_ACC_RDWR, fapl); + // Re-open file + fid1.openFile(FILE_CRTPROPS, H5F_ACC_RDWR, fapl); - // Create dataspace for dataset - DataSpace ds_space(H5S_SCALAR); + // Create dataspace for dataset + DataSpace ds_space(H5S_SCALAR); - // Create dataset creation property list. - DSetCreatPropList dcpl; + // Create dataset creation property list. + DSetCreatPropList dcpl; - // Create a dataset - DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space, dcpl); + // Create a dataset + DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space, dcpl); - unsigned max_compact = 0, min_dense = 0; + unsigned max_compact = 0, min_dense = 0; - // Retrieve limits for compact/dense attribute storage - dcpl.getAttrPhaseChange(max_compact, min_dense); - verify_val(max_compact, MAX_COMPACT_DEF, "DSetCreatPropList::getAttrPhaseChange",__LINE__,__FILE__); - verify_val(min_dense, MIN_DENSE_DEF, "DSetCreatPropList::getAttrPhaseChange",__LINE__,__FILE__); + // Retrieve limits for compact/dense attribute storage + dcpl.getAttrPhaseChange(max_compact, min_dense); + verify_val(max_compact, MAX_COMPACT_DEF, "DSetCreatPropList::getAttrPhaseChange",__LINE__,__FILE__); + verify_val(min_dense, MIN_DENSE_DEF, "DSetCreatPropList::getAttrPhaseChange",__LINE__,__FILE__); - // Set new compact/dense attribute storage limits to some random numbers - dcpl.setAttrPhaseChange(7, 5); + // Set new compact/dense attribute storage limits to some random numbers + dcpl.setAttrPhaseChange(7, 5); - // Retrieve limits for compact/dense attribute storage and verify them - dcpl.getAttrPhaseChange(max_compact, min_dense); - verify_val(max_compact, static_cast<unsigned>(7), "DSetCreatPropList::getAttrPhaseChange",__LINE__,__FILE__); - verify_val(min_dense, static_cast<unsigned>(5), "DSetCreatPropList::getAttrPhaseChange",__LINE__,__FILE__); + // Retrieve limits for compact/dense attribute storage and verify them + dcpl.getAttrPhaseChange(max_compact, min_dense); + verify_val(max_compact, static_cast<unsigned>(7), "DSetCreatPropList::getAttrPhaseChange",__LINE__,__FILE__); + verify_val(min_dense, static_cast<unsigned>(5), "DSetCreatPropList::getAttrPhaseChange",__LINE__,__FILE__); - // Close property list - dcpl.close(); + // Close property list + dcpl.close(); - // H5O_is_attr_dense_test - un-usable + // H5O_is_attr_dense_test - un-usable - // Add attributes, until just before converting to dense storage - char attr_name[NAME_BUF_SIZE]; - unsigned attr_num; - for (attr_num = 0; attr_num < max_compact; attr_num++) - { - // Create attribute - sprintf(attr_name, "attr %02u", attr_num); - Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space); + // Add attributes, until just before converting to dense storage + char attr_name[NAME_BUF_SIZE]; + unsigned attr_num; + for (attr_num = 0; attr_num < max_compact; attr_num++) + { + // Create attribute + sprintf(attr_name, "attr %02u", attr_num); + Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space); - // Write data to the attribute - attr.write(PredType::NATIVE_UINT, &attr_num); - } // end for + // Write data to the attribute + attr.write(PredType::NATIVE_UINT, &attr_num); + } // end for - // H5O_is_attr_dense_test - un-usable + // H5O_is_attr_dense_test - un-usable - { // Add one more attribute, to push into "dense" storage + { // Add one more attribute, to push into "dense" storage - // Create another attribute - sprintf(attr_name, "attr %02u", attr_num); - Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space); + // Create another attribute + sprintf(attr_name, "attr %02u", attr_num); + Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space); - // Write data to the attribute - attr.write(PredType::NATIVE_UINT, &attr_num); - } + // Write data to the attribute + attr.write(PredType::NATIVE_UINT, &attr_num); + } - // Attempt to add attribute again, which should fail - try - { - // Create another attribute - sprintf(attr_name, "attr %02u", attr_num); - Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space); + // Attempt to add attribute again, which should fail + try + { + // Create another attribute + sprintf(attr_name, "attr %02u", attr_num); + Attribute attr = dataset.createAttribute(attr_name, PredType::NATIVE_UINT, ds_space); - // continuation here, that means no exception has been thrown - throw InvalidActionException("DataSet::createAttribute", "Maximum number of attributes has been reached"); - } - catch (AttributeIException& E) // catching invalid action + // continuation here, that means no exception has been thrown + throw InvalidActionException("DataSet::createAttribute", "Maximum number of attributes has been reached"); + } + catch (AttributeIException& E) // catching invalid action {} // do nothing, exception expected - PASSED(); + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_dense_create()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_dense_create()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_dense_create() @@ -1695,81 +1695,81 @@ static void test_attr_dense_create(FileCreatPropList& fcpl, ** ****************************************************************/ static void test_attr_corder_create_basic(FileCreatPropList& fcpl, - FileAccPropList& fapl) + FileAccPropList& fapl) { // Output message about test being performed SUBTEST("Basic Code for Attributes with Creation Order Info"); try { - // Create file - H5File fid1 (FILE_CRTPROPS, H5F_ACC_TRUNC, fcpl, fapl); - - // Create dataset creation property list. - DSetCreatPropList dcpl; - - // Get creation order indexing on object - unsigned crt_order_flags = 0; - crt_order_flags = dcpl.getAttrCrtOrder(); - verify_val(crt_order_flags, (unsigned)0, "DSetCreatPropList::getAttrCrtOrder",__LINE__,__FILE__); - - // Setting invalid combination of a attribute order creation order - // indexing on should fail - try { - dcpl.setAttrCrtOrder(H5P_CRT_ORDER_INDEXED); - - // continuation here, that means no exception has been thrown - throw InvalidActionException("DSetCreatPropList::getAttrCrtOrder", "Indexing cannot be set alone, order tracking is required"); - } - catch (PropListIException& E) // catching invalid action + // Create file + H5File fid1 (FILE_CRTPROPS, H5F_ACC_TRUNC, fcpl, fapl); + + // Create dataset creation property list. + DSetCreatPropList dcpl; + + // Get creation order indexing on object + unsigned crt_order_flags = 0; + crt_order_flags = dcpl.getAttrCrtOrder(); + verify_val(crt_order_flags, (unsigned)0, "DSetCreatPropList::getAttrCrtOrder",__LINE__,__FILE__); + + // Setting invalid combination of a attribute order creation order + // indexing on should fail + try { + dcpl.setAttrCrtOrder(H5P_CRT_ORDER_INDEXED); + + // continuation here, that means no exception has been thrown + throw InvalidActionException("DSetCreatPropList::getAttrCrtOrder", "Indexing cannot be set alone, order tracking is required"); + } + catch (PropListIException& E) // catching invalid action {} // do nothing, exception expected - // Set attribute creation order tracking & indexing for object then - // verify them - dcpl.setAttrCrtOrder(H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED); - crt_order_flags = dcpl.getAttrCrtOrder(); - verify_val(crt_order_flags, (unsigned)(H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED), "DSetCreatPropList::getAttrCrtOrder",__LINE__,__FILE__); + // Set attribute creation order tracking & indexing for object then + // verify them + dcpl.setAttrCrtOrder(H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED); + crt_order_flags = dcpl.getAttrCrtOrder(); + verify_val(crt_order_flags, (unsigned)(H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED), "DSetCreatPropList::getAttrCrtOrder",__LINE__,__FILE__); - // Create dataspace for dataset - DataSpace ds_space(H5S_SCALAR); + // Create dataspace for dataset + DataSpace ds_space(H5S_SCALAR); - // Create a dataset - DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space, dcpl); + // Create a dataset + DataSet dataset = fid1.createDataSet(DSET1_NAME, PredType::NATIVE_UCHAR, ds_space, dcpl); - // Close dataspace - ds_space.close(); + // Close dataspace + ds_space.close(); - // Check on dataset's attribute storage status. - // NOTE: Wrappers not available yet (H5O_is_attr_empty_test - // and H5O_is_attr_dense_test) + // Check on dataset's attribute storage status. + // NOTE: Wrappers not available yet (H5O_is_attr_empty_test + // and H5O_is_attr_dense_test) - // Close dataset - dataset.close(); + // Close dataset + dataset.close(); - // Close property list - dcpl.close(); + // Close property list + dcpl.close(); - // Close file - fid1.close(); + // Close file + fid1.close(); - // Re-open file - fid1.openFile(FILE_CRTPROPS, H5F_ACC_RDWR, fapl); + // Re-open file + fid1.openFile(FILE_CRTPROPS, H5F_ACC_RDWR, fapl); - // Open dataset created previously - dataset = fid1.openDataSet(DSET1_NAME); + // Open dataset created previously + dataset = fid1.openDataSet(DSET1_NAME); - // Retrieve dataset creation property list for the dataset - dcpl = dataset.getCreatePlist(); + // Retrieve dataset creation property list for the dataset + dcpl = dataset.getCreatePlist(); - // Query the attribute creation properties - crt_order_flags = dcpl.getAttrCrtOrder(); - verify_val(crt_order_flags, (unsigned)(H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED), "DSetCreatPropList::getAttrCrtOrder",__LINE__,__FILE__); + // Query the attribute creation properties + crt_order_flags = dcpl.getAttrCrtOrder(); + verify_val(crt_order_flags, (unsigned)(H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED), "DSetCreatPropList::getAttrCrtOrder",__LINE__,__FILE__); - PASSED(); + PASSED(); } // end try block catch (Exception& E) { - issue_fail_msg("test_attr_corder_create_basic()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr_corder_create_basic()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr_corder_create_basic() @@ -1814,42 +1814,42 @@ void test_attr() // Set the file access proplist for the type of format if (new_format) { - MESSAGE(7, ("testing with new file format\n")); - curr_fapl = fapl_new; + MESSAGE(7, ("testing with new file format\n")); + curr_fapl = fapl_new; } else { - MESSAGE(7, ("testing with old file format\n")); - curr_fapl = fapl; + MESSAGE(7, ("testing with old file format\n")); + curr_fapl = fapl; } - test_attr_basic_write(); // Test basic H5A writing code - test_attr_getname(); // Test overloads of Attribute::getName - test_attr_rename(); // Test renaming attribute - test_attr_basic_read(); // Test basic H5A reading code + test_attr_basic_write(); // Test basic H5A writing code + test_attr_getname(); // Test overloads of Attribute::getName + test_attr_rename(); // Test renaming attribute + test_attr_basic_read(); // Test basic H5A reading code - test_attr_compound_write(); // Test complex datatype H5A writing code - test_attr_compound_read(); // Test complex datatype H5A reading code + test_attr_compound_write(); // Test complex datatype H5A writing code + test_attr_compound_read(); // Test complex datatype H5A reading code - test_attr_scalar_write(); // Test scalar dataspace H5A writing code - test_attr_scalar_read(); // Test scalar dataspace H5A reading code + test_attr_scalar_write(); // Test scalar dataspace H5A writing code + test_attr_scalar_read(); // Test scalar dataspace H5A reading code - test_attr_mult_write(); // Test writing multiple attributes - test_attr_mult_read(); // Test reading multiple attributes - test_attr_delete(); // Test deleting attributes + test_attr_mult_write(); // Test writing multiple attributes + test_attr_mult_read(); // Test reading multiple attributes + test_attr_delete(); // Test deleting attributes - test_attr_dtype_shared(); // Test using shared datatypes in attributes + test_attr_dtype_shared(); // Test using shared datatypes in attributes - test_string_attr(); // Test read/write string attribute - test_attr_exists(); // Test H5Location::attrExists + test_string_attr(); // Test read/write string attribute + test_attr_exists(); // Test H5Location::attrExists // Test with new format if (new_format) { - // Test dense attribute storage creation + // Test dense attribute storage creation test_attr_dense_create(fcpl, curr_fapl); - // Test create objects with attribute creation info + // Test create objects with attribute creation info test_attr_corder_create_basic(fcpl, curr_fapl); } } // end for @@ -1857,18 +1857,18 @@ void test_attr() catch (Exception& E) { - issue_fail_msg("test_attr()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_attr()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_attr() /*------------------------------------------------------------------------- - * Function: cleanup_attr + * Function cleanup_attr * - * Purpose: Cleanup temporary test files + * Purpose Cleanup temporary test files * - * Return: none + * Return none * - * Programmer: Albert Cheng + * Programmer Albert Cheng * July 2, 1998 * * Modifications: diff --git a/c++/test/tcompound.cpp b/c++/test/tcompound.cpp index f49ebb2..ee634c2 100644 --- a/c++/test/tcompound.cpp +++ b/c++/test/tcompound.cpp @@ -34,7 +34,7 @@ using namespace H5; #include "h5cpputil.h" // C++ utilility header file /* Number of elements in each test */ -#define NTESTELEM 100000 +#define NTESTELEM 100000 typedef struct complex_t { double re; @@ -45,11 +45,11 @@ typedef struct complex_t { /*------------------------------------------------------------------------- * Function: test_compound_1 * - * Purpose: Tests various things about compound data types. + * Purpose Tests various things about compound data types. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (using C version) + * Programmer Binh-Minh Ribler (using C version) * January, 2007 * * Modifications: @@ -61,13 +61,13 @@ static void test_compound_1() // Output message about test being performed SUBTEST("Compound Data Types"); try { - // Create an empty compound datatype - CompType complex_type(sizeof(complex_t)); + // 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(); + // 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) @@ -78,15 +78,15 @@ static void test_compound_1() /*------------------------------------------------------------------------- - * Function: test_compound_2 + * Function: test_compound_2 * - * Purpose: Tests a compound type conversion where the source and - * destination are the same except for the order of the - * elements. + * Purpose Tests a compound type conversion where the source and + * destination are the same except for the order of the + * elements. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) + * Programmer Binh-Minh Ribler (use C version) * January, 2007 * * Modifications: @@ -96,100 +96,100 @@ static void test_compound_1() static void test_compound_2() { typedef struct { - int a, b, c[4], d, e; + int a, b, c[4], d, e; } src_typ_t; typedef struct { - int e, d, c[4], b, a; + int e, d, c[4], b, a; } dst_typ_t; - src_typ_t *s_ptr; - dst_typ_t *d_ptr; - const int nelmts = NTESTELEM; + src_typ_t *s_ptr; + dst_typ_t *d_ptr; + const int nelmts = NTESTELEM; const hsize_t four = 4; - int i; + int i; unsigned char *buf = NULL, *orig = NULL, *bkg = NULL; ArrayType *array_dt = NULL; // Output message about test being performed SUBTEST("Compound Element Reordering"); try { - // Sizes should be the same, but be careful just in case - buf = (unsigned char*)HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); - bkg = (unsigned char*)HDmalloc(nelmts * sizeof(dst_typ_t)); - orig = (unsigned char*)HDmalloc(nelmts * sizeof(src_typ_t)); - for (i=0; i<nelmts; i++) { - s_ptr = ((src_typ_t*)orig) + i; - s_ptr->a = i*8+0; - s_ptr->b = i*8+1; - s_ptr->c[0] = i*8+2; - s_ptr->c[1] = i*8+3; - s_ptr->c[2] = i*8+4; - s_ptr->c[3] = i*8+5; - s_ptr->d = i*8+6; - s_ptr->e = i*8+7; - } - memcpy(buf, orig, nelmts*sizeof(src_typ_t)); - - // Build hdf5 datatypes - array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); - - // Create an empty compound datatype - CompType st(sizeof(src_typ_t)); - st.insertMember("a", HOFFSET(src_typ_t, a), PredType::NATIVE_INT); - st.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_INT); - st.insertMember("c", HOFFSET(src_typ_t, c), *array_dt); - st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_INT); - st.insertMember("e", HOFFSET(src_typ_t, e), PredType::NATIVE_INT); - array_dt->close(); + // Sizes should be the same, but be careful just in case + buf = (unsigned char*)HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); + bkg = (unsigned char*)HDmalloc(nelmts * sizeof(dst_typ_t)); + orig = (unsigned char*)HDmalloc(nelmts * sizeof(src_typ_t)); + for (i=0; i<nelmts; i++) { + s_ptr = ((src_typ_t*)orig) + i; + s_ptr->a = i*8+0; + s_ptr->b = i*8+1; + s_ptr->c[0] = i*8+2; + s_ptr->c[1] = i*8+3; + s_ptr->c[2] = i*8+4; + s_ptr->c[3] = i*8+5; + s_ptr->d = i*8+6; + s_ptr->e = i*8+7; + } + memcpy(buf, orig, nelmts*sizeof(src_typ_t)); + + // Build hdf5 datatypes + array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); + + // Create an empty compound datatype + CompType st(sizeof(src_typ_t)); + st.insertMember("a", HOFFSET(src_typ_t, a), PredType::NATIVE_INT); + st.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_INT); + st.insertMember("c", HOFFSET(src_typ_t, c), *array_dt); + st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_INT); + st.insertMember("e", HOFFSET(src_typ_t, e), PredType::NATIVE_INT); + array_dt->close(); delete array_dt; - array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); - - // Create an empty compound datatype - CompType dt(sizeof(dst_typ_t)); - dt.insertMember("a", HOFFSET(dst_typ_t, a), PredType::NATIVE_INT); - dt.insertMember("b", HOFFSET(dst_typ_t, b), PredType::NATIVE_INT); - dt.insertMember("c", HOFFSET(dst_typ_t, c), *array_dt); - dt.insertMember("d", HOFFSET(dst_typ_t, d), PredType::NATIVE_INT); - dt.insertMember("e", HOFFSET(dst_typ_t, e), PredType::NATIVE_INT); - array_dt->close(); - - // Perform the conversion - st.convert(dt, (size_t)nelmts, buf, bkg); - - // Compare results - for (i=0; i<nelmts; i++) { - s_ptr = ((src_typ_t*)orig) + i; - d_ptr = ((dst_typ_t*)buf) + i; - if (s_ptr->a != d_ptr->a || - s_ptr->b != d_ptr->b || - s_ptr->c[0] != d_ptr->c[0] || - s_ptr->c[1] != d_ptr->c[1] || - s_ptr->c[2] != d_ptr->c[2] || - s_ptr->c[3] != d_ptr->c[3] || - s_ptr->d != d_ptr->d || - s_ptr->e != d_ptr->e) { - H5_FAILED(); - cerr << " i=" << i << endl; - cerr << " src={a=" << s_ptr->a << ", b=" << s_ptr->b - << "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; - cerr << " dst={a=" << s_ptr->a << ", b=" << s_ptr->b - << "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 - HDfree(buf); - HDfree(bkg); - HDfree(orig); - s_ptr = NULL; - d_ptr = NULL; - st.close(); - dt.close(); - PASSED(); + array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); + + // Create an empty compound datatype + CompType dt(sizeof(dst_typ_t)); + dt.insertMember("a", HOFFSET(dst_typ_t, a), PredType::NATIVE_INT); + dt.insertMember("b", HOFFSET(dst_typ_t, b), PredType::NATIVE_INT); + dt.insertMember("c", HOFFSET(dst_typ_t, c), *array_dt); + dt.insertMember("d", HOFFSET(dst_typ_t, d), PredType::NATIVE_INT); + dt.insertMember("e", HOFFSET(dst_typ_t, e), PredType::NATIVE_INT); + array_dt->close(); + + // Perform the conversion + st.convert(dt, (size_t)nelmts, buf, bkg); + + // Compare results + for (i=0; i<nelmts; i++) { + s_ptr = ((src_typ_t*)orig) + i; + d_ptr = ((dst_typ_t*)buf) + i; + if (s_ptr->a != d_ptr->a || + s_ptr->b != d_ptr->b || + s_ptr->c[0] != d_ptr->c[0] || + s_ptr->c[1] != d_ptr->c[1] || + s_ptr->c[2] != d_ptr->c[2] || + s_ptr->c[3] != d_ptr->c[3] || + s_ptr->d != d_ptr->d || + s_ptr->e != d_ptr->e) { + H5_FAILED(); + cerr << " i=" << i << endl; + cerr << " src={a=" << s_ptr->a << ", b=" << s_ptr->b + << "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; + cerr << " dst={a=" << s_ptr->a << ", b=" << s_ptr->b + << "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 + HDfree(buf); + HDfree(bkg); + HDfree(orig); + s_ptr = NULL; + d_ptr = NULL; + st.close(); + dt.close(); + PASSED(); } // end of try block catch (Exception& E) @@ -203,15 +203,15 @@ static void test_compound_2() /*------------------------------------------------------------------------- - * Function: test_compound_3 + * Function: test_compound_3 * - * Purpose: Tests compound conversions where the source and destination - * are the same except the destination is missing a couple - * members which appear in the source. + * Purpose Tests compound conversions where the source and destination + * are the same except the destination is missing a couple + * members which appear in the source. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) + * Programmer Binh-Minh Ribler (use C version) * January, 2007 * * Modifications: @@ -221,16 +221,16 @@ static void test_compound_2() static void test_compound_3() { typedef struct { - int a, b, c[4], d, e; + int a, b, c[4], d, e; } src_typ_t; typedef struct { - int a, c[4], e; + int a, c[4], e; } dst_typ_t; - src_typ_t *s_ptr; - dst_typ_t *d_ptr; - int i; - const int nelmts = NTESTELEM; + src_typ_t *s_ptr; + dst_typ_t *d_ptr; + int i; + const int nelmts = NTESTELEM; const hsize_t four = 4; unsigned char *buf = NULL, *orig = NULL, *bkg = NULL; ArrayType* array_dt = NULL; @@ -238,85 +238,85 @@ static void test_compound_3() // Output message about test being performed SUBTEST("Compound Datatype Subset Conversions"); try { - /* Initialize */ - buf = (unsigned char*)HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); - bkg = (unsigned char*)HDmalloc(nelmts * sizeof(dst_typ_t)); - orig = (unsigned char*)HDmalloc(nelmts * sizeof(src_typ_t)); - for (i=0; i<nelmts; i++) { - s_ptr = ((src_typ_t*)orig) + i; - s_ptr->a = i*8+0; - s_ptr->b = i*8+1; - s_ptr->c[0] = i*8+2; - s_ptr->c[1] = i*8+3; - s_ptr->c[2] = i*8+4; - s_ptr->c[3] = i*8+5; - s_ptr->d = i*8+6; - s_ptr->e = i*8+7; - } - memcpy(buf, orig, nelmts*sizeof(src_typ_t)); - - /* Build hdf5 datatypes */ - array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); - - // Create an empty compound datatype - CompType st(sizeof(src_typ_t)); - st.insertMember("a", HOFFSET(src_typ_t, a), PredType::NATIVE_INT); - st.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_INT); - st.insertMember("c", HOFFSET(src_typ_t, c), *array_dt); - st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_INT); - st.insertMember("e", HOFFSET(src_typ_t, e), PredType::NATIVE_INT); - array_dt->close(); + /* Initialize */ + buf = (unsigned char*)HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); + bkg = (unsigned char*)HDmalloc(nelmts * sizeof(dst_typ_t)); + orig = (unsigned char*)HDmalloc(nelmts * sizeof(src_typ_t)); + for (i=0; i<nelmts; i++) { + s_ptr = ((src_typ_t*)orig) + i; + s_ptr->a = i*8+0; + s_ptr->b = i*8+1; + s_ptr->c[0] = i*8+2; + s_ptr->c[1] = i*8+3; + s_ptr->c[2] = i*8+4; + s_ptr->c[3] = i*8+5; + s_ptr->d = i*8+6; + s_ptr->e = i*8+7; + } + memcpy(buf, orig, nelmts*sizeof(src_typ_t)); + + /* Build hdf5 datatypes */ + array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); + + // Create an empty compound datatype + CompType st(sizeof(src_typ_t)); + st.insertMember("a", HOFFSET(src_typ_t, a), PredType::NATIVE_INT); + st.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_INT); + st.insertMember("c", HOFFSET(src_typ_t, c), *array_dt); + st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_INT); + st.insertMember("e", HOFFSET(src_typ_t, e), PredType::NATIVE_INT); + array_dt->close(); delete array_dt; - array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); - - // Create an empty compound datatype - CompType dt(sizeof(dst_typ_t)); - dt.insertMember("a", HOFFSET(dst_typ_t, a), PredType::NATIVE_INT); - dt.insertMember("c", HOFFSET(dst_typ_t, c), *array_dt); - dt.insertMember("e", HOFFSET(dst_typ_t, e), PredType::NATIVE_INT); - array_dt->close(); - - /* Perform the conversion */ - st.convert(dt, (size_t)nelmts, buf, bkg); - - /* Compare results */ - for (i=0; i<nelmts; i++) { - s_ptr = ((src_typ_t*)orig) + i; - d_ptr = ((dst_typ_t*)buf) + i; - if (s_ptr->a != d_ptr->a || - s_ptr->c[0] != d_ptr->c[0] || - s_ptr->c[1] != d_ptr->c[1] || - s_ptr->c[2] != d_ptr->c[2] || - s_ptr->c[3] != d_ptr->c[3] || - s_ptr->e != d_ptr->e) { - H5_FAILED(); - cerr << " i=" << i << endl; - cerr << " src={a=" << s_ptr->a << ", b=" << s_ptr->b - << ", 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; - cerr << " dst={a=" << d_ptr->a - << ", c=[" << d_ptr->c[0] << "," << d_ptr->c[1] << "," - << d_ptr->c[2] << "," << d_ptr->c[3] << "], e=" - << d_ptr->e << "}" << endl; - } // if - } // for - - /* Release resources */ - HDfree(buf); - HDfree(bkg); - HDfree(orig); - s_ptr = NULL; - d_ptr = NULL; - st.close(); - dt.close(); - PASSED(); + array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); + + // Create an empty compound datatype + CompType dt(sizeof(dst_typ_t)); + dt.insertMember("a", HOFFSET(dst_typ_t, a), PredType::NATIVE_INT); + dt.insertMember("c", HOFFSET(dst_typ_t, c), *array_dt); + dt.insertMember("e", HOFFSET(dst_typ_t, e), PredType::NATIVE_INT); + array_dt->close(); + + /* Perform the conversion */ + st.convert(dt, (size_t)nelmts, buf, bkg); + + /* Compare results */ + for (i=0; i<nelmts; i++) { + s_ptr = ((src_typ_t*)orig) + i; + d_ptr = ((dst_typ_t*)buf) + i; + if (s_ptr->a != d_ptr->a || + s_ptr->c[0] != d_ptr->c[0] || + s_ptr->c[1] != d_ptr->c[1] || + s_ptr->c[2] != d_ptr->c[2] || + s_ptr->c[3] != d_ptr->c[3] || + s_ptr->e != d_ptr->e) { + H5_FAILED(); + cerr << " i=" << i << endl; + cerr << " src={a=" << s_ptr->a << ", b=" << s_ptr->b + << ", 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; + cerr << " dst={a=" << d_ptr->a + << ", c=[" << d_ptr->c[0] << "," << d_ptr->c[1] << "," + << d_ptr->c[2] << "," << d_ptr->c[3] << "], e=" + << d_ptr->e << "}" << endl; + } // if + } // for + + /* Release resources */ + HDfree(buf); + HDfree(bkg); + HDfree(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(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } if(array_dt) @@ -325,16 +325,16 @@ static void test_compound_3() /*------------------------------------------------------------------------- - * Function: test_compound_4 + * Function: test_compound_4 * - * Purpose: Tests compound conversions when the destination has the same - * fields as the source but one or more of the fields are - * smaller. + * Purpose Tests compound conversions when the destination has the same + * fields as the source but one or more of the fields are + * smaller. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * * Modifications: * @@ -344,20 +344,20 @@ static void test_compound_4() { typedef struct { - int a, b, c[4], d, e; + int a, b, c[4], d, e; } src_typ_t; typedef struct { - short b; - int a, c[4]; - short d; - int e; + short b; + int a, c[4]; + short d; + int e; } dst_typ_t; - src_typ_t *s_ptr; - dst_typ_t *d_ptr; - int i; - const int nelmts = NTESTELEM; + src_typ_t *s_ptr; + dst_typ_t *d_ptr; + int i; + const int nelmts = NTESTELEM; const hsize_t four = 4; unsigned char *buf = NULL, *orig = NULL, *bkg = NULL; ArrayType* array_dt = NULL; @@ -365,85 +365,85 @@ static void test_compound_4() // Output message about test being performed SUBTEST("Compound Element Shrinking & Reordering"); try { - /* Sizes should be the same, but be careful just in case */ - buf = (unsigned char*)HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); - bkg = (unsigned char*)HDmalloc(nelmts * sizeof(dst_typ_t)); - orig = (unsigned char*)HDmalloc(nelmts * sizeof(src_typ_t)); - for (i=0; i<nelmts; i++) { - s_ptr = ((src_typ_t*)orig) + i; - s_ptr->a = i*8+0; - s_ptr->b = (i*8+1) & 0x7fff; - s_ptr->c[0] = i*8+2; - s_ptr->c[1] = i*8+3; - s_ptr->c[2] = i*8+4; - s_ptr->c[3] = i*8+5; - s_ptr->d = (i*8+6) & 0x7fff; - s_ptr->e = i*8+7; - } - memcpy(buf, orig, nelmts*sizeof(src_typ_t)); - - /* Build hdf5 datatypes */ - array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); - - // Create an empty compound datatype - CompType st(sizeof(src_typ_t)); - st.insertMember("a", HOFFSET(src_typ_t, a), PredType::NATIVE_INT); - st.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_INT); - st.insertMember("c", HOFFSET(src_typ_t, c), *array_dt); - st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_INT); - st.insertMember("e", HOFFSET(src_typ_t, e), PredType::NATIVE_INT); - array_dt->close(); + /* Sizes should be the same, but be careful just in case */ + buf = (unsigned char*)HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); + bkg = (unsigned char*)HDmalloc(nelmts * sizeof(dst_typ_t)); + orig = (unsigned char*)HDmalloc(nelmts * sizeof(src_typ_t)); + for (i=0; i<nelmts; i++) { + s_ptr = ((src_typ_t*)orig) + i; + s_ptr->a = i*8+0; + s_ptr->b = (i*8+1) & 0x7fff; + s_ptr->c[0] = i*8+2; + s_ptr->c[1] = i*8+3; + s_ptr->c[2] = i*8+4; + s_ptr->c[3] = i*8+5; + s_ptr->d = (i*8+6) & 0x7fff; + s_ptr->e = i*8+7; + } + memcpy(buf, orig, nelmts*sizeof(src_typ_t)); + + /* Build hdf5 datatypes */ + array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); + + // Create an empty compound datatype + CompType st(sizeof(src_typ_t)); + st.insertMember("a", HOFFSET(src_typ_t, a), PredType::NATIVE_INT); + st.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_INT); + st.insertMember("c", HOFFSET(src_typ_t, c), *array_dt); + st.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_INT); + st.insertMember("e", HOFFSET(src_typ_t, e), PredType::NATIVE_INT); + array_dt->close(); delete array_dt; - array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); - - // Create an empty compound datatype - CompType dt(sizeof(dst_typ_t)); - dt.insertMember("a", HOFFSET(dst_typ_t, a), PredType::NATIVE_INT); - dt.insertMember("b", HOFFSET(dst_typ_t, b), PredType::NATIVE_SHORT); - dt.insertMember("c", HOFFSET(dst_typ_t, c), *array_dt); - dt.insertMember("d", HOFFSET(dst_typ_t, d), PredType::NATIVE_SHORT); - dt.insertMember("e", HOFFSET(dst_typ_t, e), PredType::NATIVE_INT); - array_dt->close(); - - /* Perform the conversion */ - st.convert(dt, (size_t)nelmts, buf, bkg); - - /* Compare results */ - for (i=0; i<nelmts; i++) { - s_ptr = ((src_typ_t*)orig) + i; - d_ptr = ((dst_typ_t*)buf) + i; - if (s_ptr->a != d_ptr->a || - s_ptr->b != d_ptr->b || - s_ptr->c[0] != d_ptr->c[0] || - s_ptr->c[1] != d_ptr->c[1] || - s_ptr->c[2] != d_ptr->c[2] || - s_ptr->c[3] != d_ptr->c[3] || - s_ptr->d != d_ptr->d || - s_ptr->e != d_ptr->e) - { - H5_FAILED(); - cerr << " i=" << i << endl; - cerr << " src={a=" << s_ptr->a << ", b=" << s_ptr->b - << "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; - cerr << " dst={a=" << d_ptr->a << ", b=" << d_ptr->b - << "c=[" << d_ptr->c[0] << "," << d_ptr->c[1] << "," - << d_ptr->c[2] << "," << d_ptr->c[3] << ", d=" - << d_ptr->d << ", e=" << d_ptr->e << "}" << endl; - } // if - } // for - - /* Release resources */ - HDfree(buf); - HDfree(bkg); - HDfree(orig); - s_ptr = NULL; - d_ptr = NULL; - st.close(); - dt.close(); - PASSED(); + array_dt = new ArrayType(PredType::NATIVE_INT, 1, &four); + + // Create an empty compound datatype + CompType dt(sizeof(dst_typ_t)); + dt.insertMember("a", HOFFSET(dst_typ_t, a), PredType::NATIVE_INT); + dt.insertMember("b", HOFFSET(dst_typ_t, b), PredType::NATIVE_SHORT); + dt.insertMember("c", HOFFSET(dst_typ_t, c), *array_dt); + dt.insertMember("d", HOFFSET(dst_typ_t, d), PredType::NATIVE_SHORT); + dt.insertMember("e", HOFFSET(dst_typ_t, e), PredType::NATIVE_INT); + array_dt->close(); + + /* Perform the conversion */ + st.convert(dt, (size_t)nelmts, buf, bkg); + + /* Compare results */ + for (i=0; i<nelmts; i++) { + s_ptr = ((src_typ_t*)orig) + i; + d_ptr = ((dst_typ_t*)buf) + i; + if (s_ptr->a != d_ptr->a || + s_ptr->b != d_ptr->b || + s_ptr->c[0] != d_ptr->c[0] || + s_ptr->c[1] != d_ptr->c[1] || + s_ptr->c[2] != d_ptr->c[2] || + s_ptr->c[3] != d_ptr->c[3] || + s_ptr->d != d_ptr->d || + s_ptr->e != d_ptr->e) + { + H5_FAILED(); + cerr << " i=" << i << endl; + cerr << " src={a=" << s_ptr->a << ", b=" << s_ptr->b + << "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; + cerr << " dst={a=" << d_ptr->a << ", b=" << d_ptr->b + << "c=[" << d_ptr->c[0] << "," << d_ptr->c[1] << "," + << d_ptr->c[2] << "," << d_ptr->c[3] << ", d=" + << d_ptr->d << ", e=" << d_ptr->e << "}" << endl; + } // if + } // for + + /* Release resources */ + HDfree(buf); + HDfree(bkg); + HDfree(orig); + s_ptr = NULL; + d_ptr = NULL; + st.close(); + dt.close(); + PASSED(); } // end of try block catch (Exception& E) @@ -457,17 +457,17 @@ static void test_compound_4() /*------------------------------------------------------------------------- - * Function: test_compound_5 + * Function: test_compound_5 * - * Purpose: Many versions of HDF5 have a bug in the optimized compound + * Purpose Many versions of HDF5 have a bug in the optimized compound * datatype conversion function, H5T_conv_struct_opt(), which * is triggered when the top-level type contains a struct * which must undergo a conversion. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * * Modifications: * @@ -499,55 +499,55 @@ static void test_compound_5() SUBTEST("Optimized Struct Converter"); try { - /* Build datatypes */ - array_dt = new ArrayType(PredType::NATIVE_SHORT, 1, dims); - CompType short_array(4*sizeof(short)); - short_array.insertMember("_", 0, *array_dt); - array_dt->close(); + /* Build datatypes */ + array_dt = new ArrayType(PredType::NATIVE_SHORT, 1, dims); + CompType short_array(4*sizeof(short)); + short_array.insertMember("_", 0, *array_dt); + array_dt->close(); delete array_dt; - CompType int_array(4*sizeof(int)); - array_dt = new ArrayType(PredType::NATIVE_INT, 1, dims); - int_array.insertMember("_", 0, *array_dt); - array_dt->close(); - - StrType strg(PredType::C_S1, 16); - CompType src_type(sizeof(src_typ_t)); - src_type.insertMember("name", HOFFSET(src_typ_t, name), strg); - src_type.insertMember("tdim", HOFFSET(src_typ_t, tdim), PredType::NATIVE_SHORT); - src_type.insertMember("coll_ids", HOFFSET(src_typ_t, coll_ids), short_array); - - CompType dst_type(sizeof(dst_typ_t)); - dst_type.insertMember("name", HOFFSET(dst_typ_t, name), strg); - 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 */ - memcpy(buf, src, sizeof(src)); - src_type.convert(dst_type, (size_t)2, buf, bkg); - dst = (dst_typ_t*)buf; - - /* Cleanup */ - src_type.close(); - dst_type.close(); - strg.close(); - short_array.close(); - int_array.close(); - - /* 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] || - src[1].coll_ids[1]!=dst[1].coll_ids[1] || - src[1].coll_ids[2]!=dst[1].coll_ids[2] || - src[1].coll_ids[3]!=dst[1].coll_ids[3]) - { H5_FAILED(); } - - /* Free memory buffers */ - HDfree(buf); - HDfree(bkg); - dst = NULL; - PASSED(); + CompType int_array(4*sizeof(int)); + array_dt = new ArrayType(PredType::NATIVE_INT, 1, dims); + int_array.insertMember("_", 0, *array_dt); + array_dt->close(); + + StrType strg(PredType::C_S1, 16); + CompType src_type(sizeof(src_typ_t)); + src_type.insertMember("name", HOFFSET(src_typ_t, name), strg); + src_type.insertMember("tdim", HOFFSET(src_typ_t, tdim), PredType::NATIVE_SHORT); + src_type.insertMember("coll_ids", HOFFSET(src_typ_t, coll_ids), short_array); + + CompType dst_type(sizeof(dst_typ_t)); + dst_type.insertMember("name", HOFFSET(dst_typ_t, name), strg); + 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 */ + memcpy(buf, src, sizeof(src)); + src_type.convert(dst_type, (size_t)2, buf, bkg); + dst = (dst_typ_t*)buf; + + /* Cleanup */ + src_type.close(); + dst_type.close(); + strg.close(); + short_array.close(); + int_array.close(); + + /* 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] || + src[1].coll_ids[1]!=dst[1].coll_ids[1] || + src[1].coll_ids[2]!=dst[1].coll_ids[2] || + src[1].coll_ids[3]!=dst[1].coll_ids[3]) + { H5_FAILED(); } + + /* Free memory buffers */ + HDfree(buf); + HDfree(bkg); + dst = NULL; + PASSED(); } // end of try block catch (Exception& E) @@ -561,16 +561,16 @@ static void test_compound_5() /*------------------------------------------------------------------------- - * Function: test_compound_6 + * Function: test_compound_6 * - * Purpose: Tests compound conversions when the destination has the same - * fields as the source but one or more of the fields are - * larger. + * Purpose Tests compound conversions when the destination has the same + * fields as the source but one or more of the fields are + * larger. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * * Modifications: * @@ -579,72 +579,72 @@ static void test_compound_5() static void test_compound_6() { typedef struct { - short b; - short d; + short b; + short d; } src_typ_t; typedef struct { - long b; - long d; + long b; + long d; } dst_typ_t; - src_typ_t *s_ptr; - dst_typ_t *d_ptr; - int i; - const int nelmts = NTESTELEM; + src_typ_t *s_ptr; + dst_typ_t *d_ptr; + int i; + const int nelmts = NTESTELEM; unsigned char *buf=NULL, *orig=NULL, *bkg=NULL; // Output message about test being performed SUBTEST("Compound Element Growing"); try { - /* Sizes should be the same, but be careful just in case */ - buf = (unsigned char*)HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); - bkg = (unsigned char*)HDmalloc(nelmts * sizeof(dst_typ_t)); - orig = (unsigned char*)HDmalloc(nelmts * sizeof(src_typ_t)); - for (i=0; i<nelmts; i++) { - s_ptr = ((src_typ_t*)orig) + i; - s_ptr->b = (i*8+1) & 0x7fff; - s_ptr->d = (i*8+6) & 0x7fff; - } - memcpy(buf, orig, nelmts*sizeof(src_typ_t)); - - /* 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); - - CompType dt(sizeof(dst_typ_t)); - 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 */ - st.convert(dt, (size_t)nelmts, buf, bkg); - - /* Compare results */ - for (i=0; i<nelmts; i++) { - s_ptr = ((src_typ_t*)orig) + i; - d_ptr = ((dst_typ_t*)buf) + i; - if (s_ptr->b != d_ptr->b || - s_ptr->d != d_ptr->d) - { - H5_FAILED(); - cerr << " i=" << i << endl; - cerr << " src={b=" << s_ptr->b << ", d=" << s_ptr->d - << "}" << endl; - cerr << " dst={b=" << d_ptr->b << ", d=" << d_ptr->d - << "}" << endl; - } // if - } // for - - /* Release resources */ - HDfree(buf); - HDfree(bkg); - HDfree(orig); - s_ptr = NULL; - d_ptr = NULL; - st.close(); - dt.close(); - PASSED(); + /* Sizes should be the same, but be careful just in case */ + buf = (unsigned char*)HDmalloc(nelmts * MAX(sizeof(src_typ_t), sizeof(dst_typ_t))); + bkg = (unsigned char*)HDmalloc(nelmts * sizeof(dst_typ_t)); + orig = (unsigned char*)HDmalloc(nelmts * sizeof(src_typ_t)); + for (i=0; i<nelmts; i++) { + s_ptr = ((src_typ_t*)orig) + i; + s_ptr->b = (i*8+1) & 0x7fff; + s_ptr->d = (i*8+6) & 0x7fff; + } + memcpy(buf, orig, nelmts*sizeof(src_typ_t)); + + /* 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); + + CompType dt(sizeof(dst_typ_t)); + 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 */ + st.convert(dt, (size_t)nelmts, buf, bkg); + + /* Compare results */ + for (i=0; i<nelmts; i++) { + s_ptr = ((src_typ_t*)orig) + i; + d_ptr = ((dst_typ_t*)buf) + i; + if (s_ptr->b != d_ptr->b || + s_ptr->d != d_ptr->d) + { + H5_FAILED(); + cerr << " i=" << i << endl; + cerr << " src={b=" << s_ptr->b << ", d=" << s_ptr->d + << "}" << endl; + cerr << " dst={b=" << d_ptr->b << ", d=" << d_ptr->d + << "}" << endl; + } // if + } // for + + /* Release resources */ + HDfree(buf); + HDfree(bkg); + HDfree(orig); + s_ptr = NULL; + d_ptr = NULL; + st.close(); + dt.close(); + PASSED(); } // end of try block catch (Exception& E) @@ -654,15 +654,15 @@ static void test_compound_6() } // test_compound_6() /*------------------------------------------------------------------------- - * Function: test_compound_7 + * Function: test_compound_7 * - * Purpose: Tests inserting fields into compound datatypes when the field - * overlaps the end of the compound datatype. + * Purpose Tests inserting fields into compound datatypes when the field + * overlaps the end of the compound datatype. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * * Modifications: * @@ -671,47 +671,47 @@ static void test_compound_6() static void test_compound_7() { typedef struct { - int a; - float b; - long c; + int a; + float b; + long c; } s1_typ_t; typedef struct { - int a; - float b; - long c; - double d; + int a; + float b; + long c; + double d; } s2_typ_t; // Output message about test being performed SUBTEST("Compound Element Insertion"); try { - CompType tid1(sizeof(s1_typ_t)); + CompType tid1(sizeof(s1_typ_t)); - tid1.insertMember("a", HOFFSET(s1_typ_t,a),PredType::NATIVE_INT); - tid1.insertMember("b", HOFFSET(s1_typ_t,b),PredType::NATIVE_FLOAT); - tid1.insertMember("c", HOFFSET(s1_typ_t,c),PredType::NATIVE_LONG); + tid1.insertMember("a", HOFFSET(s1_typ_t,a),PredType::NATIVE_INT); + tid1.insertMember("b", HOFFSET(s1_typ_t,b),PredType::NATIVE_FLOAT); + tid1.insertMember("c", HOFFSET(s1_typ_t,c),PredType::NATIVE_LONG); - size_t type_size = tid1.getSize(); - verify_val(type_size, sizeof(s1_typ_t), "DataType::getSize", __LINE__, __FILE__); + size_t type_size = tid1.getSize(); + verify_val(type_size, sizeof(s1_typ_t), "DataType::getSize", __LINE__, __FILE__); - CompType tid2; - tid2.copy(tid1); + CompType tid2; + tid2.copy(tid1); - type_size = tid2.getSize(); - verify_val_noteq(type_size, sizeof(s2_typ_t), "DataType::getSize", __LINE__, __FILE__); + 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 */ - 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) {} + /* 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 */ - tid1.close(); - tid2.close(); - PASSED(); + /* Release resources */ + tid1.close(); + tid2.close(); + PASSED(); } // end of try block catch (Exception& E) @@ -721,13 +721,13 @@ static void test_compound_7() } // test_compound_7() /*------------------------------------------------------------------------- - * Function: test_compound_set_size + * Function: test_compound_set_size * - * Purpose: Tests member function setSize() on compound datatype + * Purpose Tests member function setSize() on compound datatype * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use partial C version test_ooo_order) + * Programmer Binh-Minh Ribler (use partial C version test_ooo_order) * March, 2014 * * Modifications: @@ -738,7 +738,7 @@ const H5std_string COMPFILE("tcompound_types.h5"); static void test_compound_set_size() { typedef struct { - int a, b, c[4], d, e; + int a, b, c[4], d, e; } src_typ_t; // Output message about test being performed @@ -755,53 +755,53 @@ static void test_compound_set_size() dtype.insertMember("c", HOFFSET(src_typ_t, c), PredType::NATIVE_LONG); dtype.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_DOUBLE); - // Verify that the compound is not packed - // bool packed = dtype.packed(); // not until C library provides API - // verify_val(packed, FALSE, "DataType::packed", __LINE__, __FILE__); + // Verify that the compound is not packed + // bool packed = dtype.packed(); // not until C library provides API + // verify_val(packed, FALSE, "DataType::packed", __LINE__, __FILE__); - dtype.commit(file, "dtype"); + dtype.commit(file, "dtype"); - // Close the type and file - dtype.close(); - file.close(); + // Close the type and file + dtype.close(); + file.close(); - // Open the file for read/write - file.openFile(COMPFILE, H5F_ACC_RDWR); + // Open the file for read/write + file.openFile(COMPFILE, H5F_ACC_RDWR); - // Open the data type "dtype" - CompType dtype_tmp = file.openCompType("dtype"); + // Open the data type "dtype" + CompType dtype_tmp = file.openCompType("dtype"); - // Make a copy of the data type - dtype.copy(dtype_tmp); + // Make a copy of the data type + dtype.copy(dtype_tmp); - // Verify that the compound is not packed - // packed = dtype_tmp.packed(); // not until C library provides API - // verify_val(packed, FALSE, "DataType::packed", __LINE__, __FILE__); + // Verify that the compound is not packed + // packed = dtype_tmp.packed(); // not until C library provides API + // verify_val(packed, FALSE, "DataType::packed", __LINE__, __FILE__); - // Expand the type, and verify that it became unpacked - dtype.setSize((size_t)33); - // packed = dtype.packed(); // not until C library provides API - // verify_val(packed, FALSE, "DataType::packed", __LINE__, __FILE__); + // Expand the type, and verify that it became unpacked + dtype.setSize((size_t)33); + // packed = dtype.packed(); // not until C library provides API + // verify_val(packed, FALSE, "DataType::packed", __LINE__, __FILE__); - // Verify setSize() actually set size - size_t new_size = dtype.getSize(); - verify_val(new_size, (size_t)33, "DataType::getSize", __LINE__, __FILE__); + // Verify setSize() actually set size + size_t new_size = dtype.getSize(); + verify_val(new_size, (size_t)33, "DataType::getSize", __LINE__, __FILE__); - // Shrink the type, and verify that it became packed - dtype.setSize((size_t)32); - // packed = dtype.packed(); // not until C library provides API - // verify_val(packed, TRUE, "DataType::packed", __LINE__, __FILE__); + // Shrink the type, and verify that it became packed + dtype.setSize((size_t)32); + // packed = dtype.packed(); // not until C library provides API + // verify_val(packed, TRUE, "DataType::packed", __LINE__, __FILE__); - // Verify setSize() actually set size again - new_size = dtype.getSize(); - verify_val(new_size, (size_t)32, "DataType::getSize", __LINE__, __FILE__); + // Verify setSize() actually set size again + new_size = dtype.getSize(); + verify_val(new_size, (size_t)32, "DataType::getSize", __LINE__, __FILE__); - /* Close types and file */ - dtype_tmp.close(); - dtype.close(); - file.close(); + /* Close types and file */ + dtype_tmp.close(); + dtype.close(); + file.close(); - PASSED(); + PASSED(); } // end of try block catch (Exception& E) @@ -811,14 +811,14 @@ static void test_compound_set_size() } // test_compound_set_size() /*------------------------------------------------------------------------- - * Function: test_compound + * Function: test_compound * - * Purpose: Main compound datatype testing routine + * Purpose Main compound datatype testing routine * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler - * January 2007 + * Programmer Binh-Minh Ribler + * January 2007 * * Modifications: * @@ -830,23 +830,23 @@ void test_compound() // Output message about test being performed MESSAGE(5, ("Testing Compound Data Type operations\n")); - test_compound_1(); // various things about compound data types - test_compound_2(); // compound element reordering - test_compound_3(); // compound datatype subset conversions - test_compound_4(); // compound element shrinking & reordering - test_compound_5(); // optimized struct converter - test_compound_6(); // compound element growing - test_compound_7(); // compound element insertion - test_compound_set_size(); // set size on compound data types + test_compound_1(); // various things about compound data types + test_compound_2(); // compound element reordering + test_compound_3(); // compound datatype subset conversions + test_compound_4(); // compound element shrinking & reordering + test_compound_5(); // optimized struct converter + test_compound_6(); // compound element growing + test_compound_7(); // compound element insertion + test_compound_set_size(); // set size on compound data types } // test_compound() /*------------------------------------------------------------------------- - * Function: cleanup_compound + * Function: cleanup_compound * - * Purpose: Cleanup temporary test files - nothing at this time. + * Purpose Cleanup temporary test files - nothing at this time. * - * Return: none + * Return none * * Modifications: * diff --git a/c++/test/tdspl.cpp b/c++/test/tdspl.cpp index d733ffe..f39694b 100644 --- a/c++/test/tdspl.cpp +++ b/c++/test/tdspl.cpp @@ -16,7 +16,7 @@ /***************************************************************************** FILE tdspl.cpp - HDF5 C++ testing the dataset memory and transfer property - list functionality + list functionality ***************************************************************************/ #ifdef OLD_HEADER_FILENAME @@ -45,70 +45,70 @@ static void test_transfplist() SUBTEST("DSetMemXferPropList::set/getDataTransform()"); try { - // Create various data set prop lists and set data transform expression. - DSetMemXferPropList dxpl_c_to_f(c_to_f); - - DSetMemXferPropList dxpl_simple; - dxpl_simple.setDataTransform(simple); - - DSetMemXferPropList dxpl_utrans_inv; - dxpl_utrans_inv.setDataTransform(utrans_inv); - - // - // Make a copy of one of those prop lists then read the data transform - // expression and verify that it's the same as the original. - // - - // Copy the prop list. - DSetMemXferPropList dxpl_c_to_f_copy; - dxpl_c_to_f_copy.copy(dxpl_c_to_f); - - // Find out the length of the transform expression, allocate the buffer - // for it, then read and verify the expression from the copied plist - ssize_t tran_len = dxpl_c_to_f_copy.getDataTransform(NULL); - char *c_to_f_read = (char *)HDmalloc(tran_len+1); - HDmemset(c_to_f_read, 0, tran_len+1); - dxpl_c_to_f_copy.getDataTransform(c_to_f_read, tran_len+1); - verify_val((const char*)c_to_f_read, (const char*)c_to_f, - "DSetMemXferPropList::getDataTransform", __LINE__, __FILE__); - HDfree(c_to_f_read); - - // - // Read the expression of each of the prop lists and verify the read - // expression - // - - // Get and verify the expression with: - // ssize_t getDataTransform(char* exp, const size_t buf_size [default=0]) - tran_len = dxpl_c_to_f.getDataTransform(NULL); - c_to_f_read = (char *)HDmalloc(tran_len+1); - HDmemset(c_to_f_read, 0, tran_len+1); - dxpl_c_to_f.getDataTransform(c_to_f_read, tran_len+1); - verify_val((const char*)c_to_f_read, (const char*)c_to_f, - "DSetMemXferPropList::getDataTransform", __LINE__, __FILE__); - HDfree(c_to_f_read); - - // Get and verify the expression with: - // H5std_string DSetMemXferPropList::getDataTransform() - H5std_string simple_read = dxpl_simple.getDataTransform(); - verify_val((const char*)simple_read.c_str(), (const char*)simple, - "DSetMemXferPropList::getDataTransform", __LINE__, __FILE__); - - // Get and verify the expression with: - // ssize_t getDataTransform(char* exp, const size_t buf_size) - tran_len = dxpl_utrans_inv.getDataTransform(NULL, 0); - char *utrans_inv_read = (char *)HDmalloc(tran_len+1); - HDmemset(utrans_inv_read, 0, tran_len+1); - dxpl_utrans_inv.getDataTransform(utrans_inv_read, tran_len+1); - verify_val((const char*)utrans_inv_read, (const char*)utrans_inv, - "DSetMemXferPropList::getDataTransform", __LINE__, __FILE__); - HDfree(utrans_inv_read); - - PASSED(); + // Create various data set prop lists and set data transform expression. + DSetMemXferPropList dxpl_c_to_f(c_to_f); + + DSetMemXferPropList dxpl_simple; + dxpl_simple.setDataTransform(simple); + + DSetMemXferPropList dxpl_utrans_inv; + dxpl_utrans_inv.setDataTransform(utrans_inv); + + // + // Make a copy of one of those prop lists then read the data transform + // expression and verify that it's the same as the original. + // + + // Copy the prop list. + DSetMemXferPropList dxpl_c_to_f_copy; + dxpl_c_to_f_copy.copy(dxpl_c_to_f); + + // Find out the length of the transform expression, allocate the buffer + // for it, then read and verify the expression from the copied plist + ssize_t tran_len = dxpl_c_to_f_copy.getDataTransform(NULL); + char *c_to_f_read = (char *)HDmalloc(tran_len+1); + HDmemset(c_to_f_read, 0, tran_len+1); + dxpl_c_to_f_copy.getDataTransform(c_to_f_read, tran_len+1); + verify_val((const char*)c_to_f_read, (const char*)c_to_f, + "DSetMemXferPropList::getDataTransform", __LINE__, __FILE__); + HDfree(c_to_f_read); + + // + // Read the expression of each of the prop lists and verify the read + // expression + // + + // Get and verify the expression with: + // ssize_t getDataTransform(char* exp, const size_t buf_size [default=0]) + tran_len = dxpl_c_to_f.getDataTransform(NULL); + c_to_f_read = (char *)HDmalloc(tran_len+1); + HDmemset(c_to_f_read, 0, tran_len+1); + dxpl_c_to_f.getDataTransform(c_to_f_read, tran_len+1); + verify_val((const char*)c_to_f_read, (const char*)c_to_f, + "DSetMemXferPropList::getDataTransform", __LINE__, __FILE__); + HDfree(c_to_f_read); + + // Get and verify the expression with: + // H5std_string DSetMemXferPropList::getDataTransform() + H5std_string simple_read = dxpl_simple.getDataTransform(); + verify_val((const char*)simple_read.c_str(), (const char*)simple, + "DSetMemXferPropList::getDataTransform", __LINE__, __FILE__); + + // Get and verify the expression with: + // ssize_t getDataTransform(char* exp, const size_t buf_size) + tran_len = dxpl_utrans_inv.getDataTransform(NULL, 0); + char *utrans_inv_read = (char *)HDmalloc(tran_len+1); + HDmemset(utrans_inv_read, 0, tran_len+1); + dxpl_utrans_inv.getDataTransform(utrans_inv_read, tran_len+1); + verify_val((const char*)utrans_inv_read, (const char*)utrans_inv, + "DSetMemXferPropList::getDataTransform", __LINE__, __FILE__); + HDfree(utrans_inv_read); + + PASSED(); } catch (Exception& E) { - issue_fail_msg("test_transfplist", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_transfplist", __LINE__, __FILE__, E.getCDetailMsg()); } } diff --git a/c++/test/testhdf5.cpp b/c++/test/testhdf5.cpp index 28ede6b..779c931 100644 --- a/c++/test/testhdf5.cpp +++ b/c++/test/testhdf5.cpp @@ -28,16 +28,16 @@ base functionality testing. EXTERNAL ROUTINES/VARIABLES: - TestInit(...) -- Initialize testing framework - TestInfo(...) -- Print test info - AddTest(...) -- Setup a test function and add it to the list of tests - TestParseCmdLine(...) -- Parse command line arguments - PerformTests() -- Perform requested testing - GetTestSummary() -- Retrieve Summary request value - TestSummary() -- Display test summary - GetTestCleanup() -- Retrieve Cleanup request value - TestCleanup() -- Clean up files from testing - GetTestNumErrs() -- Retrieve the number of testing errors + TestInit(...) -- Initialize testing framework + TestInfo(...) -- Print test info + AddTest(...) -- Setup a test function and add it to the list of tests + TestParseCmdLine(...) -- Parse command line arguments + PerformTests() -- Perform requested testing + GetTestSummary() -- Retrieve Summary request value + TestSummary() -- Display test summary + GetTestCleanup() -- Retrieve Cleanup request value + TestCleanup() -- Clean up files from testing + GetTestNumErrs() -- Retrieve the number of testing errors ***************************************************************************/ #ifdef OLD_HEADER_FILENAME @@ -60,47 +60,47 @@ main(int argc, char *argv[]) { try { - // Turn of the auto-printing when failure occurs so that we can - // handle the errors appropriately since sometime failures are - // caused deliberately and expected. - Exception::dontPrint(); - /* Initialize testing framework */ - TestInit(argv[0], NULL, NULL); - - // testing file creation and opening in tfile.cpp - AddTest("tfile", test_file, cleanup_file, "File I/O Operations", NULL); - // testing dataset functionalities in dset.cpp - AddTest("dsets", test_dset, cleanup_dsets, "Dataset I/O Operations", NULL); - // testing dataspace functionalities in th5s.cpp - AddTest("th5s", test_h5s, cleanup_h5s, "Dataspaces", NULL); - // testing attribute functionalities in tattr.cpp - AddTest("tattr", test_attr, cleanup_attr, "Attributes", NULL); - // testing object functionalities in tobject.cpp - AddTest("tobject", test_object, cleanup_object, "Objects", NULL); - // testing reference functionalities in trefer.cpp - AddTest("trefer", test_reference, cleanup_reference, "References", NULL); - // testing variable-length strings in tvlstr.cpp - AddTest("tvlstr", test_vlstrings, cleanup_vlstrings, "Variable-Length Strings", NULL); - AddTest("ttypes", test_types, cleanup_types, "Generic Data Types", NULL); - AddTest("tarray", test_array, cleanup_array, "Array Datatypes", NULL); - AddTest("tcompound", test_compound, cleanup_compound, "Compound Data Types", NULL); - AddTest("tdspl", test_dsproplist, cleanup_dsproplist, "Dataset Property List", NULL); - AddTest("tfilter", test_filters, cleanup_filters, "Various Filters", NULL); - AddTest("tlinks", test_links, cleanup_links, "Various Links", NULL); + // Turn of the auto-printing when failure occurs so that we can + // handle the errors appropriately since sometime failures are + // caused deliberately and expected. + Exception::dontPrint(); + /* Initialize testing framework */ + TestInit(argv[0], NULL, NULL); + + // testing file creation and opening in tfile.cpp + AddTest("tfile", test_file, cleanup_file, "File I/O Operations", NULL); + // testing dataset functionalities in dset.cpp + AddTest("dsets", test_dset, cleanup_dsets, "Dataset I/O Operations", NULL); + // testing dataspace functionalities in th5s.cpp + AddTest("th5s", test_h5s, cleanup_h5s, "Dataspaces", NULL); + // testing attribute functionalities in tattr.cpp + AddTest("tattr", test_attr, cleanup_attr, "Attributes", NULL); + // testing object functionalities in tobject.cpp + AddTest("tobject", test_object, cleanup_object, "Objects", NULL); + // testing reference functionalities in trefer.cpp + AddTest("trefer", test_reference, cleanup_reference, "References", NULL); + // testing variable-length strings in tvlstr.cpp + AddTest("tvlstr", test_vlstrings, cleanup_vlstrings, "Variable-Length Strings", NULL); + AddTest("ttypes", test_types, cleanup_types, "Generic Data Types", NULL); + AddTest("tarray", test_array, cleanup_array, "Array Datatypes", NULL); + AddTest("tcompound", test_compound, cleanup_compound, "Compound Data Types", NULL); + AddTest("tdspl", test_dsproplist, cleanup_dsproplist, "Dataset Property List", NULL); + AddTest("tfilter", test_filters, cleanup_filters, "Various Filters", NULL); + AddTest("tlinks", test_links, cleanup_links, "Various Links", NULL); /* Comment out tests that are not done yet. - BMR, Feb 2001 - AddTest("select", test_select, cleanup_select, "Selections", NULL); - AddTest("time", test_time, cleanup_time, "Time Datatypes", NULL); - AddTest("vltypes", test_vltypes, cleanup_vltypes, "Variable-Length Datatypes", NULL); + AddTest("select", test_select, cleanup_select, "Selections", NULL); + AddTest("time", test_time, cleanup_time, "Time Datatypes", NULL); + AddTest("vltypes", test_vltypes, cleanup_vltypes, "Variable-Length Datatypes", NULL); */ - AddTest("iterate", test_iterate, cleanup_iterate, "Group & Attribute Iteration", NULL); + AddTest("iterate", test_iterate, cleanup_iterate, "Group & Attribute Iteration", NULL); /* - AddTest("genprop", test_genprop, cleanup_genprop, "Generic Properties", NULL); - AddTest("id", test_ids, NULL, "User-Created Identifiers", NULL); + AddTest("genprop", test_genprop, cleanup_genprop, "Generic Properties", NULL); + AddTest("id", test_ids, NULL, "User-Created Identifiers", NULL); Comment out tests that are not done yet */ /* Tentative - BMR 2007/1/12 - AddTest("enum", test_enum, cleanup_enum, "Enum Data Types", NULL); + AddTest("enum", test_enum, cleanup_enum, "Enum Data Types", NULL); */ } catch (Exception& E) diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp index 934d6e6..261beab 100644 --- a/c++/test/tfile.cpp +++ b/c++/test/tfile.cpp @@ -66,20 +66,20 @@ const H5std_string FILE4("tfile4.h5"); /*------------------------------------------------------------------------- * Function: test_file_create * - * Purpose: Test file and template creations + * Purpose Test file and template creations * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) + * Programmer Binh-Minh Ribler (use C version) * January, 2001 * * Modifications: - * January, 2005: C tests' macro VERIFY casts values to 'long' for all - * cases. Since there are no operator<< for 'long long' - * or int64 in VS C++ ostream, I casted the hsize_t values - * passed to verify_val to 'long' as well. If problems - * arises later, this will have to be specificly handled - * with a special routine. + * January, 2005: C tests' macro VERIFY casts values to 'long' for all + * cases. Since there are no operator<< for 'long long' + * or int64 in VS C++ ostream, I casted the hsize_t values + * passed to verify_val to 'long' as well. If problems + * arises later, this will have to be specificly handled + * with a special routine. * *------------------------------------------------------------------------- */ @@ -98,81 +98,81 @@ static void test_file_create() // Setting this to NULL for cleaning up in failure situations H5File* file1 = NULL; try { - // Create file FILE1 - file1 = new H5File (FILE1, H5F_ACC_EXCL); - - // Try to create the same file with H5F_ACC_TRUNC. This should fail - // because file1 is the same file and is currently open. - try { - H5File file2 (FILE1, H5F_ACC_TRUNC); // should throw E - - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("H5File constructor", "Attempted to create an existing file."); - } - catch (FileIException& E) // catch truncating existing file - {} // do nothing, FAIL expected - - // Close file1 - delete file1; - file1 = NULL; - - // Try again with H5F_ACC_EXCL. This should fail because the file - // already exists from the previous steps. - try { - H5File file2(FILE1, H5F_ACC_EXCL); // should throw E - - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("H5File constructor", "File already exists."); - } - catch (FileIException& E) // catching creating existing file - {} // do nothing, FAIL expected - - // Test create with H5F_ACC_TRUNC. This will truncate the existing file. - file1 = new H5File (FILE1, H5F_ACC_TRUNC); - - // Try to create first file again. This should fail because file1 - // is the same file and is currently open. - try { - H5File file2 (FILE1, H5F_ACC_TRUNC); // should throw E - - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("H5File constructor", "H5F_ACC_TRUNC attempt on an opened file."); - } - catch (FileIException& E) // catching truncating opened file - {} // do nothing, FAIL expected - - // Try with H5F_ACC_EXCL. This should fail too because the file already - // exists. - try { - H5File file3 (FILE1, H5F_ACC_EXCL); // should throw E - - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("H5File constructor", "H5F_ACC_EXCL attempt on an existing file."); - } - catch (FileIException& E) // catching H5F_ACC_EXCL on existing file - {} // do nothing, FAIL expected - - // Get the file-creation template - FileCreatPropList tmpl1 = file1->getCreatePlist(); - - hsize_t ublock = tmpl1.getUserblock(); - verify_val((long)ublock, (long)F1_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); - - 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__); + // Create file FILE1 + file1 = new H5File (FILE1, H5F_ACC_EXCL); + + // Try to create the same file with H5F_ACC_TRUNC. This should fail + // because file1 is the same file and is currently open. + try { + H5File file2 (FILE1, H5F_ACC_TRUNC); // should throw E + + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("H5File constructor", "Attempted to create an existing file."); + } + catch (FileIException& E) // catch truncating existing file + {} // do nothing, FAIL expected + + // Close file1 + delete file1; + file1 = NULL; + + // Try again with H5F_ACC_EXCL. This should fail because the file + // already exists from the previous steps. + try { + H5File file2(FILE1, H5F_ACC_EXCL); // should throw E + + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("H5File constructor", "File already exists."); + } + catch (FileIException& E) // catching creating existing file + {} // do nothing, FAIL expected + + // Test create with H5F_ACC_TRUNC. This will truncate the existing file. + file1 = new H5File (FILE1, H5F_ACC_TRUNC); + + // Try to create first file again. This should fail because file1 + // is the same file and is currently open. + try { + H5File file2 (FILE1, H5F_ACC_TRUNC); // should throw E + + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("H5File constructor", "H5F_ACC_TRUNC attempt on an opened file."); + } + catch (FileIException& E) // catching truncating opened file + {} // do nothing, FAIL expected + + // Try with H5F_ACC_EXCL. This should fail too because the file already + // exists. + try { + H5File file3 (FILE1, H5F_ACC_EXCL); // should throw E + + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("H5File constructor", "H5F_ACC_EXCL attempt on an existing file."); + } + catch (FileIException& E) // catching H5F_ACC_EXCL on existing file + {} // do nothing, FAIL expected + + // Get the file-creation template + FileCreatPropList tmpl1 = file1->getCreatePlist(); + + hsize_t ublock = tmpl1.getUserblock(); + verify_val((long)ublock, (long)F1_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); + + 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__); unsigned iparm1,iparm2; // file-creation parameters tmpl1.getSymk( iparm1, iparm2); verify_val(iparm1, F1_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); verify_val(iparm2, F1_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); - // tmpl1 is automatically closed; if error occurs, it'll be - // caught in the catch block + // tmpl1 is automatically closed; if error occurs, it'll be + // caught in the catch block - // Close first file - delete file1; + // Close first file + delete file1; } catch (InvalidActionException& E) { @@ -184,7 +184,7 @@ static void test_file_create() // catch all other exceptions catch (Exception& E) { - issue_fail_msg("test_file_create()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_file_create()", __LINE__, __FILE__, E.getCDetailMsg()); if (file1 != NULL) // clean up delete file1; } @@ -193,79 +193,79 @@ static void test_file_create() FileCreatPropList* tmpl1 = NULL; try { - // Create a new file with a non-standard file-creation template - tmpl1 = new FileCreatPropList; + // Create a new file with a non-standard file-creation template + tmpl1 = new FileCreatPropList; - // Set the new file-creation parameters - tmpl1->setUserblock (F2_USERBLOCK_SIZE); - tmpl1->setSizes( F2_OFFSET_SIZE, F2_LENGTH_SIZE ); - tmpl1->setSymk( F2_SYM_INTERN_K, F2_SYM_LEAF_K ); + // Set the new file-creation parameters + tmpl1->setUserblock (F2_USERBLOCK_SIZE); + tmpl1->setSizes( F2_OFFSET_SIZE, F2_LENGTH_SIZE ); + tmpl1->setSymk( F2_SYM_INTERN_K, F2_SYM_LEAF_K ); - // Try to create second file, with non-standard file-creation template - // params. - H5File file2( FILE2, H5F_ACC_TRUNC, *tmpl1 ); + // Try to create second file, with non-standard file-creation template + // params. + H5File file2( FILE2, H5F_ACC_TRUNC, *tmpl1 ); - // Release file-creation template - delete tmpl1; - tmpl1 = NULL; + // Release file-creation template + delete tmpl1; + tmpl1 = NULL; - // Get the file-creation template - tmpl1 = new FileCreatPropList (file2.getCreatePlist()); + // Get the file-creation template + tmpl1 = new FileCreatPropList (file2.getCreatePlist()); - // Get the file-creation parameters - hsize_t ublock = tmpl1->getUserblock(); - verify_val((long)ublock, (long)F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); + // Get the file-creation parameters + hsize_t ublock = tmpl1->getUserblock(); + verify_val((long)ublock, (long)F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); - size_t parm1, parm2; // file-creation parameters - tmpl1->getSizes( parm1, parm2); - verify_val(parm1, F2_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); - verify_val(parm2, F2_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); + size_t parm1, parm2; // file-creation parameters + tmpl1->getSizes( parm1, parm2); + verify_val(parm1, F2_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); + verify_val(parm2, F2_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); - unsigned iparm1,iparm2; // file-creation parameters + unsigned iparm1,iparm2; // file-creation parameters 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__); - // Clone the file-creation template - FileCreatPropList tmpl2; - tmpl2.copy (*tmpl1); + // Clone the file-creation template + FileCreatPropList tmpl2; + tmpl2.copy (*tmpl1); - // Release file-creation template - delete tmpl1; - tmpl1 = NULL; + // Release file-creation template + delete tmpl1; + tmpl1 = NULL; - // Set the new file-creation parameter - tmpl2.setUserblock( F3_USERBLOCK_SIZE ); + // Set the new file-creation parameter + tmpl2.setUserblock( F3_USERBLOCK_SIZE ); - // Try to create second file, with non-standard file-creation template - // params - H5File file3( FILE3, H5F_ACC_TRUNC, tmpl2 ); + // Try to create second file, with non-standard file-creation template + // params + H5File file3( FILE3, H5F_ACC_TRUNC, tmpl2 ); - // Get the file-creation template - tmpl1 = new FileCreatPropList (file3.getCreatePlist()); + // Get the file-creation template + tmpl1 = new FileCreatPropList (file3.getCreatePlist()); - // Get the file-creation parameters - ublock = tmpl1->getUserblock(); - verify_val((long)ublock, (long)F3_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); + // Get the file-creation parameters + ublock = tmpl1->getUserblock(); + verify_val((long)ublock, (long)F3_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); - tmpl1->getSizes( parm1, parm2); - verify_val(parm1, F3_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); - verify_val(parm2, F3_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); + tmpl1->getSizes( parm1, parm2); + verify_val(parm1, F3_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); + verify_val(parm2, F3_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); - tmpl1->getSymk( iparm1, iparm2); - verify_val(iparm1, F3_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); - verify_val(iparm2, F3_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); + tmpl1->getSymk( iparm1, iparm2); + verify_val(iparm1, F3_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); + verify_val(iparm2, F3_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); - // Release file-creation template - delete tmpl1; - PASSED(); + // Release file-creation template + delete tmpl1; + PASSED(); } // catch all exceptions catch (Exception& E) { - issue_fail_msg("test_file_create()", __LINE__, __FILE__, E.getCDetailMsg()); - if (tmpl1 != NULL) // clean up - delete tmpl1; + issue_fail_msg("test_file_create()", __LINE__, __FILE__, E.getCDetailMsg()); + if (tmpl1 != NULL) // clean up + delete tmpl1; } } // test_file_create() @@ -273,20 +273,20 @@ static void test_file_create() /*------------------------------------------------------------------------- * Function: test_file_open * - * Purpose: Test file accesses + * Purpose Test file accesses * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) + * Programmer Binh-Minh Ribler (use C version) * January, 2001 * * Modifications: - * January, 2005: C tests' macro VERIFY casts values to 'long' for all - * cases. Since there are no operator<< for 'long long' - * or int64 in VS C++ ostream, I casted the hsize_t values - * passed to verify_val to 'long' as well. If problems - * arises later, this will have to be specificly handled - * with a special routine. + * January, 2005: C tests' macro VERIFY casts values to 'long' for all + * cases. Since there are no operator<< for 'long long' + * or int64 in VS C++ ostream, I casted the hsize_t values + * passed to verify_val to 'long' as well. If problems + * arises later, this will have to be specificly handled + * with a special routine. * *------------------------------------------------------------------------- */ @@ -297,53 +297,53 @@ static void test_file_open() try { - // Open first file - H5File file1 (FILE2, H5F_ACC_RDWR ); + // Open first file + H5File file1 (FILE2, H5F_ACC_RDWR ); - // Get the file-creation template - FileCreatPropList tmpl1 = file1.getCreatePlist(); + // Get the file-creation template + FileCreatPropList tmpl1 = file1.getCreatePlist(); - // Get the file-creation parameters - hsize_t ublock = tmpl1.getUserblock(); - verify_val((long)ublock, (long)F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); + // Get the file-creation parameters + hsize_t ublock = tmpl1.getUserblock(); + verify_val((long)ublock, (long)F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); - size_t parm1, parm2; // file-creation parameters - tmpl1.getSizes( parm1, parm2); - verify_val(parm1, F2_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); - verify_val(parm2, F2_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); + size_t parm1, parm2; // file-creation parameters + tmpl1.getSizes( parm1, parm2); + verify_val(parm1, F2_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); + verify_val(parm2, F2_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); unsigned iparm1,iparm2; // file-creation parameters 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__); - // Test H5File constructor with existing file id - H5File file2(file1.getId()); - file1.close(); + // Test H5File constructor with existing file id + H5File file2(file1.getId()); + file1.close(); - // Try truncating the file, and it should fail because the file is - // still opened with file2. - try { - H5File file3 (FILE2, H5F_ACC_TRUNC); // should throw E + // Try truncating the file, and it should fail because the file is + // still opened with file2. + try { + H5File file3 (FILE2, H5F_ACC_TRUNC); // should throw E - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("H5File constructor", "Attempt truncating an opened file."); - } - catch (FileIException& E) // catching H5F_ACC_TRUNC on opened file - {} // do nothing, FAIL expected + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("H5File constructor", "Attempt truncating an opened file."); + } + catch (FileIException& E) // catching H5F_ACC_TRUNC on opened file + {} // do nothing, FAIL expected - // Now, really close the file. - file2.close(); + // Now, really close the file. + file2.close(); - // Truncating should succeed now. - H5File file3(FILE2, H5F_ACC_TRUNC); + // Truncating should succeed now. + H5File file3(FILE2, H5F_ACC_TRUNC); - // Opening another file to file3 object, FILE2 should be closed, so - // the next attempt to truncate FILE2 should succeed. - file3.openFile(FILE1, H5F_ACC_RDONLY); - H5File file4(FILE2, H5F_ACC_TRUNC); + // Opening another file to file3 object, FILE2 should be closed, so + // the next attempt to truncate FILE2 should succeed. + file3.openFile(FILE1, H5F_ACC_RDONLY); + H5File file4(FILE2, H5F_ACC_TRUNC); - PASSED(); + PASSED(); } // end of try block catch (Exception& E) @@ -356,11 +356,11 @@ static void test_file_open() /*------------------------------------------------------------------------- * Function: test_file_size * - * Purpose: Test file size. + * Purpose Test file size. * - * Return: None + * Return None * - * Programmer: Raymond Lu + * Programmer Raymond Lu * June, 2004 * * Modifications: @@ -372,7 +372,7 @@ static void test_file_size() // Output message about test being performed SUBTEST("File Size"); - hid_t fapl_id; + hid_t fapl_id; fapl_id = h5_fileaccess(); // in h5test.c, returns a file access template try { @@ -380,13 +380,13 @@ static void test_file_size() // list object to pass in H5File::H5File FileAccPropList fapl(fapl_id); - // Set to sec2 driver. Do we want to test other file drivers? + // Set to sec2 driver. Do we want to test other file drivers? // They're not tested in C++. // File drivers seem not implemented. - // fapl.setSec2(); + // fapl.setSec2(); // Create a file - H5File file4( FILE4, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); + H5File file4( FILE4, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); // Get file size hsize_t file_size = file4.getFileSize(); @@ -395,14 +395,14 @@ static void test_file_size() if (file_size < 1*KB || file_size > 4*KB) issue_fail_msg("test_file_size()", __LINE__, __FILE__, "getFileSize() returned unreasonable value"); - // Get the amount of free space in the file - hssize_t free_space = file4.getFreeSpace(); + // Get the amount of free space in the file + hssize_t free_space = file4.getFreeSpace(); - // Check if it's reasonable. It's 0 now. - if (free_space < 0 || free_space > 4*KB) - issue_fail_msg("test_file_size()", __LINE__, __FILE__, "getFreeSpace returned unreasonable value"); + // Check if it's reasonable. It's 0 now. + if (free_space < 0 || free_space > 4*KB) + issue_fail_msg("test_file_size()", __LINE__, __FILE__, "getFreeSpace returned unreasonable value"); - PASSED(); + PASSED(); } // end of try block catch (Exception& E) @@ -421,25 +421,25 @@ static void test_file_size() /*------------------------------------------------------------------------- * Function: test_file_name * - * Purpose: Test getting file's name. + * Purpose Test getting file's name. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler + * Programmer Binh-Minh Ribler * July, 2004 * * Modifications: * *------------------------------------------------------------------------- */ -const int RANK = 2; -const int NX = 4; -const int NY = 5; -const H5std_string GROUPNAME ("group"); -const H5std_string DSETNAME ("dataset"); -const H5std_string DATTRNAME ("dataset attribute"); -const H5std_string FATTRNAME ("file attribute"); -const H5std_string DTYPENAME ("compound"); +const int RANK = 2; +const int NX = 4; +const int NY = 5; +const H5std_string GROUPNAME ("group"); +const H5std_string DSETNAME ("dataset"); +const H5std_string DATTRNAME ("dataset attribute"); +const H5std_string FATTRNAME ("file attribute"); +const H5std_string DTYPENAME ("compound"); // Compound datatype typedef struct s1_t { @@ -455,51 +455,51 @@ static void test_file_name() H5std_string file_name; try { // Create a file using default properties. - H5File file4(FILE4, H5F_ACC_TRUNC); + H5File file4(FILE4, H5F_ACC_TRUNC); // Get file name from the file instance. file_name = file4.getFileName(); - verify_val(file_name, FILE4, "H5File::getFileName", __LINE__, __FILE__); + verify_val(file_name, FILE4, "H5File::getFileName", __LINE__, __FILE__); - // Create a group in the root group. - Group group(file4.createGroup(GROUPNAME, 0)); + // Create a group in the root group. + Group group(file4.createGroup(GROUPNAME, 0)); - // Get and verify file name via a group. - file_name = group.getFileName(); - verify_val(file_name, FILE4, "Group::getFileName", __LINE__, __FILE__); + // Get and verify file name via a group. + file_name = group.getFileName(); + verify_val(file_name, FILE4, "Group::getFileName", __LINE__, __FILE__); - // Create the data space. - hsize_t dims[RANK] = {NX, NY}; - DataSpace space(RANK, dims); + // Create the data space. + hsize_t dims[RANK] = {NX, NY}; + DataSpace space(RANK, dims); - // Create a new dataset. - DataSet dataset(file4.createDataSet (DSETNAME, PredType::NATIVE_INT, space)); + // Create a new dataset. + DataSet dataset(file4.createDataSet (DSETNAME, PredType::NATIVE_INT, space)); - // Get and verify file name via a dataset. - file_name = dataset.getFileName(); - verify_val(file_name, FILE4, "DataSet::getFileName", __LINE__, __FILE__); + // Get and verify file name via a dataset. + file_name = dataset.getFileName(); + verify_val(file_name, FILE4, "DataSet::getFileName", __LINE__, __FILE__); - // Create an attribute for the dataset. - Attribute attr(dataset.createAttribute(DATTRNAME, PredType::NATIVE_INT, space)); + // Create an attribute for the dataset. + Attribute attr(dataset.createAttribute(DATTRNAME, PredType::NATIVE_INT, space)); - // Get and verify file name via an attribute. - file_name = attr.getFileName(); - verify_val(file_name, FILE4, "Attribute::getFileName", __LINE__, __FILE__); + // Get and verify file name via an attribute. + file_name = attr.getFileName(); + verify_val(file_name, FILE4, "Attribute::getFileName", __LINE__, __FILE__); - // Create a compound datatype. - CompType comp_type (sizeof(s1_t)); + // Create a compound datatype. + CompType comp_type (sizeof(s1_t)); - // Insert fields. - comp_type.insertMember("a", HOFFSET(s1_t, a), PredType::NATIVE_INT); - comp_type.insertMember("b", HOFFSET(s1_t, b), PredType::NATIVE_FLOAT); + // Insert fields. + comp_type.insertMember("a", HOFFSET(s1_t, a), PredType::NATIVE_INT); + comp_type.insertMember("b", HOFFSET(s1_t, b), PredType::NATIVE_FLOAT); - // Save it on file. - comp_type.commit(file4, DTYPENAME); + // Save it on file. + comp_type.commit(file4, DTYPENAME); - // Get and verify file name via a committed datatype. - comp_type.getFileName(); - verify_val(file_name, FILE4, "CompType::getFileName", __LINE__, __FILE__); - PASSED(); + // Get and verify file name via a committed datatype. + comp_type.getFileName(); + verify_val(file_name, FILE4, "CompType::getFileName", __LINE__, __FILE__); + PASSED(); } // end of try block catch (Exception& E) @@ -509,11 +509,11 @@ static void test_file_name() } // test_file_name() -const int RANK1 = 1; -const int ATTR1_DIM1 = 3; -const H5std_string FILE5("tfattrs.h5"); -const H5std_string FATTR1_NAME ("file attribute 1"); -const H5std_string FATTR2_NAME ("file attribute 2"); +const int RANK1 = 1; +const int ATTR1_DIM1 = 3; +const H5std_string FILE5("tfattrs.h5"); +const H5std_string FATTR1_NAME ("file attribute 1"); +const H5std_string FATTR2_NAME ("file attribute 2"); int fattr_data[ATTR1_DIM1]={512,-234,98123}; // Test data for file attribute int dattr_data[ATTR1_DIM1]={256,-123,1000}; // Test data for dataset attribute @@ -528,89 +528,89 @@ static void test_file_attribute() H5std_string file_name; try { // Create a file using default properties. - H5File file5(FILE5, H5F_ACC_TRUNC); + H5File file5(FILE5, H5F_ACC_TRUNC); - // Create the data space - hsize_t dims[RANK1] = {ATTR1_DIM1}; - DataSpace space(RANK1, dims); + // Create the data space + hsize_t dims[RANK1] = {ATTR1_DIM1}; + DataSpace space(RANK1, dims); - // Create two attributes for the file - Attribute fattr1(file5.createAttribute(FATTR1_NAME, PredType::NATIVE_FLOAT, space)); - Attribute fattr2(file5.createAttribute(FATTR2_NAME, PredType::NATIVE_INT, space)); + // Create two attributes for the file + Attribute fattr1(file5.createAttribute(FATTR1_NAME, PredType::NATIVE_FLOAT, space)); + Attribute fattr2(file5.createAttribute(FATTR2_NAME, PredType::NATIVE_INT, space)); - fattr2.write(PredType::NATIVE_INT, fattr_data); + fattr2.write(PredType::NATIVE_INT, fattr_data); - try { - // Try to create the same attribute again (should fail) - Attribute fattr_dup(file5.createAttribute(FATTR2_NAME, PredType::NATIVE_INT, space)); - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("H5File createAttribute", "Attempted to create an existing attribute."); - } - catch (AttributeIException& E) // catch creating existing attribute - {} // do nothing, FAIL expected + try { + // Try to create the same attribute again (should fail) + Attribute fattr_dup(file5.createAttribute(FATTR2_NAME, PredType::NATIVE_INT, space)); + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("H5File createAttribute", "Attempted to create an existing attribute."); + } + catch (AttributeIException& E) // catch creating existing attribute + {} // do nothing, FAIL expected - // Create a new dataset - DataSet dataset(file5.createDataSet (DSETNAME, PredType::NATIVE_INT, space)); + // Create a new dataset + DataSet dataset(file5.createDataSet (DSETNAME, PredType::NATIVE_INT, space)); - // Create an attribute for the dataset - Attribute dattr(dataset.createAttribute(DATTRNAME, PredType::NATIVE_INT, space)); + // Create an attribute for the dataset + Attribute dattr(dataset.createAttribute(DATTRNAME, PredType::NATIVE_INT, space)); - // Write data to the second file attribute - dattr.write(PredType::NATIVE_INT, dattr_data); + // Write data to the second file attribute + dattr.write(PredType::NATIVE_INT, dattr_data); - // Test flushing out the data from the attribute object + // Test flushing out the data from the attribute object dattr.flush(H5F_SCOPE_GLOBAL); - // Get and verify the number of all objects in the file - // Current: 1 file, 2 file attr, 1 ds, and 1 ds attr. - ssize_t num_objs = file5.getObjCount(H5F_OBJ_ALL); - verify_val(num_objs, 5, "H5File::getObjCount", __LINE__, __FILE__); - - num_objs = file5.getObjCount(H5F_OBJ_GROUP); - verify_val(num_objs, 0, "H5File::getObjCount(H5F_OBJ_GROUP)", __LINE__, __FILE__); - num_objs = file5.getObjCount(H5F_OBJ_DATASET); - verify_val(num_objs, 1, "H5File::getObjCount(H5F_OBJ_DATASET)", __LINE__, __FILE__); - num_objs = file5.getObjCount(H5F_OBJ_ATTR); - verify_val(num_objs, 3, "H5File::getObjCount(H5F_OBJ_ATTR)", __LINE__, __FILE__); - num_objs = file5.getObjCount(H5F_OBJ_DATATYPE); - verify_val(num_objs, 0, "H5File::getObjCount(H5F_OBJ_DATATYPE)", __LINE__, __FILE__); - num_objs = file5.getObjCount(H5F_OBJ_FILE); - verify_val(num_objs, 1, "H5File::getObjCount(H5F_OBJ_FILE)", __LINE__, __FILE__); - - // Get the file name using the attributes - H5std_string fname = fattr1.getFileName(); - verify_val(fname, FILE5, "H5File::getFileName()", __LINE__, __FILE__); - - fname.clear(); - fname = dattr.getFileName(); - verify_val(fname, FILE5, "H5File::getFileName()", __LINE__, __FILE__); - - // Get the class of a file attribute's datatype - H5T_class_t atclass = fattr1.getTypeClass(); - verify_val(atclass, H5T_FLOAT, "Attribute::getTypeClass()", __LINE__, __FILE__); - - // Get and verify the number of attributes attached to a file - int n_attrs = file5.getNumAttrs(); - verify_val(n_attrs, 2, "H5File::getNumAttrs()", __LINE__, __FILE__); - - // Get and verify the number of attributes attached to a dataset - n_attrs = 0; - n_attrs = dataset.getNumAttrs(); - verify_val(n_attrs, 1, "DataSet::getNumAttrs()", __LINE__, __FILE__); - - // Read back attribute's data - HDmemset(rdata, 0, sizeof(rdata)); + // Get and verify the number of all objects in the file + // Current: 1 file, 2 file attr, 1 ds, and 1 ds attr. + ssize_t num_objs = file5.getObjCount(H5F_OBJ_ALL); + verify_val(num_objs, 5, "H5File::getObjCount", __LINE__, __FILE__); + + num_objs = file5.getObjCount(H5F_OBJ_GROUP); + verify_val(num_objs, 0, "H5File::getObjCount(H5F_OBJ_GROUP)", __LINE__, __FILE__); + num_objs = file5.getObjCount(H5F_OBJ_DATASET); + verify_val(num_objs, 1, "H5File::getObjCount(H5F_OBJ_DATASET)", __LINE__, __FILE__); + num_objs = file5.getObjCount(H5F_OBJ_ATTR); + verify_val(num_objs, 3, "H5File::getObjCount(H5F_OBJ_ATTR)", __LINE__, __FILE__); + num_objs = file5.getObjCount(H5F_OBJ_DATATYPE); + verify_val(num_objs, 0, "H5File::getObjCount(H5F_OBJ_DATATYPE)", __LINE__, __FILE__); + num_objs = file5.getObjCount(H5F_OBJ_FILE); + verify_val(num_objs, 1, "H5File::getObjCount(H5F_OBJ_FILE)", __LINE__, __FILE__); + + // Get the file name using the attributes + H5std_string fname = fattr1.getFileName(); + verify_val(fname, FILE5, "H5File::getFileName()", __LINE__, __FILE__); + + fname.clear(); + fname = dattr.getFileName(); + verify_val(fname, FILE5, "H5File::getFileName()", __LINE__, __FILE__); + + // Get the class of a file attribute's datatype + H5T_class_t atclass = fattr1.getTypeClass(); + verify_val(atclass, H5T_FLOAT, "Attribute::getTypeClass()", __LINE__, __FILE__); + + // Get and verify the number of attributes attached to a file + int n_attrs = file5.getNumAttrs(); + verify_val(n_attrs, 2, "H5File::getNumAttrs()", __LINE__, __FILE__); + + // Get and verify the number of attributes attached to a dataset + n_attrs = 0; + n_attrs = dataset.getNumAttrs(); + verify_val(n_attrs, 1, "DataSet::getNumAttrs()", __LINE__, __FILE__); + + // Read back attribute's data + HDmemset(rdata, 0, sizeof(rdata)); dattr.read(PredType::NATIVE_INT, rdata); /* Check results */ for (i = 0; i < ATTR1_DIM1; i++) { if (rdata[i] != dattr_data[i]) { H5_FAILED(); - cerr << endl; + cerr << endl; cerr << "element [" << i << "] is " << rdata[i] << - "but should have been " << dattr_data[i] << endl; + "but should have been " << dattr_data[i] << endl; } } - PASSED(); + PASSED(); } // end of try block catch (Exception& E) @@ -620,28 +620,28 @@ static void test_file_attribute() } // test_file_attribute() -const H5std_string FILE6("tfile5.h5"); -const H5std_string ROOTGROUP("/"); -const H5std_string GROUP1("/G1"); -const H5std_string SUBGROUP3("/G1/G3"); +const H5std_string FILE6("tfile5.h5"); +const H5std_string ROOTGROUP("/"); +const H5std_string GROUP1("/G1"); +const H5std_string SUBGROUP3("/G1/G3"); /*------------------------------------------------------------------------- - * Function: test_libver_bounds_real + * Function: test_libver_bounds_real * - * Purpose: Verify that a file created and modified with the - * specified libver bounds has the specified object header - * versions for the right objects. + * Purpose Verify that a file created and modified with the + * specified libver bounds has the specified object header + * versions for the right objects. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * March, 2015 + * Programmer Binh-Minh Ribler (use C version) + * March, 2015 * *------------------------------------------------------------------------- */ static void test_libver_bounds_real( - H5F_libver_t libver_create, unsigned oh_vers_create, - H5F_libver_t libver_mod, unsigned oh_vers_mod) + H5F_libver_t libver_create, unsigned oh_vers_create, + H5F_libver_t libver_mod, unsigned oh_vers_mod) { try { @@ -713,12 +713,12 @@ static void test_libver_bounds_real( * * Function: test_libver_bounds * - * Purpose: Verify that a file created and modified with various - * libver bounds is handled correctly. + * Purpose Verify that a file created and modified with various + * libver bounds is handled correctly. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) + * Programmer Binh-Minh Ribler (use C version) * March 2015 * *------------------------------------------------------------------------- @@ -735,14 +735,14 @@ static void test_libver_bounds() } /* end test_libver_bounds() */ /*------------------------------------------------------------------------- - * Function: test_commonfg + * Function: test_commonfg * - * Purpose: Verify that H5File works as a root group. + * Purpose Verify that H5File works as a root group. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * March, 2015 + * Programmer Binh-Minh Ribler (use C version) + * March, 2015 * *------------------------------------------------------------------------- */ @@ -753,40 +753,40 @@ static void test_commonfg() try { // Create a file using default properties. - H5File file4(FILE4, H5F_ACC_TRUNC); + H5File file4(FILE4, H5F_ACC_TRUNC); - // Try opening the root group. - Group rootgroup(file4.openGroup(ROOTGROUP)); + // Try opening the root group. + Group rootgroup(file4.openGroup(ROOTGROUP)); - // Create a group in the root group. - Group group(rootgroup.createGroup(GROUPNAME, 0)); + // Create a group in the root group. + Group group(rootgroup.createGroup(GROUPNAME, 0)); - // Create the data space. - hsize_t dims[RANK] = {NX, NY}; - DataSpace space(RANK, dims); + // Create the data space. + hsize_t dims[RANK] = {NX, NY}; + DataSpace space(RANK, dims); - // Create a new dataset. - DataSet dataset(group.createDataSet (DSETNAME, PredType::NATIVE_INT, space)); + // Create a new dataset. + DataSet dataset(group.createDataSet (DSETNAME, PredType::NATIVE_INT, space)); - // Get and verify file name via a dataset. - H5std_string file_name = dataset.getFileName(); - verify_val(file_name, FILE4, "DataSet::getFileName", __LINE__, __FILE__); + // Get and verify file name via a dataset. + H5std_string file_name = dataset.getFileName(); + verify_val(file_name, FILE4, "DataSet::getFileName", __LINE__, __FILE__); - // Create an attribute for the dataset. - Attribute attr(dataset.createAttribute(DATTRNAME, PredType::NATIVE_INT, space)); + // Create an attribute for the dataset. + Attribute attr(dataset.createAttribute(DATTRNAME, PredType::NATIVE_INT, space)); - // Get and verify file name via an attribute. - file_name = attr.getFileName(); - verify_val(file_name, FILE4, "Attribute::getFileName", __LINE__, __FILE__); + // Get and verify file name via an attribute. + file_name = attr.getFileName(); + verify_val(file_name, FILE4, "Attribute::getFileName", __LINE__, __FILE__); - // Create an attribute for the file via root group. - Attribute rootg_attr(rootgroup.createAttribute(FATTRNAME, PredType::NATIVE_INT, space)); + // Create an attribute for the file via root group. + Attribute rootg_attr(rootgroup.createAttribute(FATTRNAME, PredType::NATIVE_INT, space)); - // Get and verify file name via an attribute. - file_name = attr.getFileName(); - verify_val(file_name, FILE4, "Attribute::getFileName", __LINE__, __FILE__); + // Get and verify file name via an attribute. + file_name = attr.getFileName(); + verify_val(file_name, FILE4, "Attribute::getFileName", __LINE__, __FILE__); - PASSED(); + PASSED(); } // end of try block catch (Exception& E) @@ -796,19 +796,19 @@ static void test_commonfg() } /* end test_commonfg() */ -const H5std_string FILE7("tfile7.h5"); +const H5std_string FILE7("tfile7.h5"); /*------------------------------------------------------------------------- - * Function: test_file_info + * Function: test_file_info * - * Purpose: Verify that various properties in a file creation property - * lists are stored correctly in the file and can be retrieved - * when the file is re-opened. + * Purpose Verify that various properties in a file creation property + * lists are stored correctly in the file and can be retrieved + * when the file is re-opened. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler - * February, 2017 + * Programmer Binh-Minh Ribler + * February, 2017 * *------------------------------------------------------------------------- */ @@ -817,8 +817,8 @@ static void test_file_info() // Output message about test being performed SUBTEST("File general information"); - hsize_t in_threshold = 2; // Free space section threshold to set */ - hsize_t out_threshold = 0; // Free space section threshold to get */ + hsize_t in_threshold = 2; // Free space section threshold to set */ + hsize_t out_threshold = 0; // Free space section threshold to get */ // File space handling strategy H5F_file_space_type_t in_strategy = H5F_FILE_SPACE_ALL; // File space handling strategy @@ -826,88 +826,88 @@ static void test_file_info() try { // Create a file using default properties. - H5File tempfile(FILE7, H5F_ACC_TRUNC); + H5File tempfile(FILE7, H5F_ACC_TRUNC); - // Get the file's version information. - H5F_info2_t finfo; - tempfile.getFileInfo(finfo); - verify_val(finfo.super.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); - verify_val(finfo.free.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); - verify_val(finfo.sohm.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); + // Get the file's version information. + H5F_info2_t finfo; + tempfile.getFileInfo(finfo); + verify_val(finfo.super.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); + verify_val(finfo.free.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); + verify_val(finfo.sohm.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); - // Close the file. - tempfile.close(); + // Close the file. + tempfile.close(); - // Create file creation property list. - FileCreatPropList fcpl; + // Create file creation property list. + FileCreatPropList fcpl; - // Set various file information. - fcpl.setUserblock(F2_USERBLOCK_SIZE); - fcpl.setSizes(F2_OFFSET_SIZE, F2_LENGTH_SIZE); - fcpl.setSymk(F2_SYM_INTERN_K, F2_SYM_LEAF_K); - fcpl.setIstorek(F2_ISTORE); - fcpl.setFileSpace(in_strategy, in_threshold); + // Set various file information. + fcpl.setUserblock(F2_USERBLOCK_SIZE); + fcpl.setSizes(F2_OFFSET_SIZE, F2_LENGTH_SIZE); + fcpl.setSymk(F2_SYM_INTERN_K, F2_SYM_LEAF_K); + fcpl.setIstorek(F2_ISTORE); + fcpl.setFileSpace(in_strategy, in_threshold); - // Creating a file with the non-default file creation property list - // should create a version 1 superblock + // Creating a file with the non-default file creation property list + // should create a version 1 superblock - // Create file with custom file creation property list. - H5File file7(FILE7, H5F_ACC_TRUNC, fcpl); + // Create file with custom file creation property list. + H5File file7(FILE7, H5F_ACC_TRUNC, fcpl); - // Close the file creation property list. - fcpl.close(); + // Close the file creation property list. + fcpl.close(); - // Get the file's version information. - file7.getFileInfo(finfo); - verify_val(finfo.super.version, 2, "H5File::getFileInfo", __LINE__, __FILE__); - verify_val(finfo.free.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); - verify_val(finfo.sohm.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); + // Get the file's version information. + file7.getFileInfo(finfo); + verify_val(finfo.super.version, 2, "H5File::getFileInfo", __LINE__, __FILE__); + verify_val(finfo.free.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); + verify_val(finfo.sohm.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); - // Close the file. - file7.close(); + // Close the file. + file7.close(); - // Re-open the file. - file7.openFile(FILE7, H5F_ACC_RDONLY); + // Re-open the file. + file7.openFile(FILE7, H5F_ACC_RDONLY); - // Get the file's creation property list. - FileCreatPropList fcpl2 = file7.getCreatePlist(); + // Get the file's creation property list. + FileCreatPropList fcpl2 = file7.getCreatePlist(); - // Get the file's version information. - file7.getFileInfo(finfo); - verify_val(finfo.super.version, 2, "H5File::getFileInfo", __LINE__, __FILE__); - verify_val(finfo.free.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); - verify_val(finfo.sohm.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); + // Get the file's version information. + file7.getFileInfo(finfo); + verify_val(finfo.super.version, 2, "H5File::getFileInfo", __LINE__, __FILE__); + verify_val(finfo.free.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); + verify_val(finfo.sohm.version, 0, "H5File::getFileInfo", __LINE__, __FILE__); - // Retrieve the property values & check them. - hsize_t userblock = fcpl2.getUserblock(); - verify_val(userblock, F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); + // Retrieve the property values & check them. + hsize_t userblock = fcpl2.getUserblock(); + verify_val(userblock, F2_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); - size_t off_size = 0, len_size = 0; - fcpl2.getSizes(off_size, len_size); - verify_val(off_size, F2_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); - verify_val(len_size, F2_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); + size_t off_size = 0, len_size = 0; + fcpl2.getSizes(off_size, len_size); + verify_val(off_size, F2_OFFSET_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); + verify_val(len_size, F2_LENGTH_SIZE, "FileCreatPropList::getSizes", __LINE__, __FILE__); - unsigned sym_ik = 0, sym_lk = 0; - fcpl2.getSymk(sym_ik, sym_lk); - verify_val(sym_ik, F2_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); - verify_val(sym_lk, F2_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); + unsigned sym_ik = 0, sym_lk = 0; + fcpl2.getSymk(sym_ik, sym_lk); + verify_val(sym_ik, F2_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); + verify_val(sym_lk, F2_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); - unsigned istore_ik = fcpl2.getIstorek(); - verify_val(istore_ik, F2_ISTORE, "FileCreatPropList::getIstorek", __LINE__, __FILE__); + unsigned istore_ik = fcpl2.getIstorek(); + verify_val(istore_ik, F2_ISTORE, "FileCreatPropList::getIstorek", __LINE__, __FILE__); /* ret=H5Pget_shared_mesg_nindexes(fcpl2,&nindexes); CHECK(ret, FAIL, "H5Pget_shared_mesg_nindexes"); VERIFY(nindexes, MISC11_NINDEXES, "H5Pget_shared_mesg_nindexes"); */ - // Get and verify the file space info from the creation property list */ - out_strategy = fcpl2.getFileSpaceStrategy(); - verify_val(static_cast<unsigned>(out_strategy), static_cast<unsigned>(in_strategy), "FileCreatPropList::getFileSpaceStrategy", __LINE__, __FILE__); + // Get and verify the file space info from the creation property list */ + out_strategy = fcpl2.getFileSpaceStrategy(); + verify_val(static_cast<unsigned>(out_strategy), static_cast<unsigned>(in_strategy), "FileCreatPropList::getFileSpaceStrategy", __LINE__, __FILE__); - out_threshold = fcpl2.getFileSpaceThreshold(); - verify_val(static_cast<unsigned>(out_threshold), static_cast<unsigned>(in_threshold), "FileCreatPropList::getFileSpaceThreshold", __LINE__, __FILE__); + out_threshold = fcpl2.getFileSpaceThreshold(); + verify_val(static_cast<unsigned>(out_threshold), static_cast<unsigned>(in_threshold), "FileCreatPropList::getFileSpaceThreshold", __LINE__, __FILE__); - PASSED(); + PASSED(); } // end of try block catch (Exception& E) { @@ -918,11 +918,11 @@ static void test_file_info() /*------------------------------------------------------------------------- * Function: test_file * - * Purpose: Main file testing routine + * Purpose Main file testing routine * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) + * Programmer Binh-Minh Ribler (use C version) * January 2001 * * Modifications: @@ -935,25 +935,25 @@ void test_file() // Output message about test being performed MESSAGE(5, ("Testing File I/O Operations\n")); - test_file_create(); // Test file creation (also creation templates) - test_file_open(); // Test file opening - test_file_size(); // Test file size - test_file_name(); // Test getting file's name - test_file_attribute(); // Test file attribute feature - test_libver_bounds(); // Test format version - test_commonfg(); // Test H5File as a root group - test_file_info(); // Test various file info + test_file_create(); // Test file creation (also creation templates) + test_file_open(); // Test file opening + test_file_size(); // Test file size + test_file_name(); // Test getting file's name + test_file_attribute(); // Test file attribute feature + test_libver_bounds(); // Test format version + test_commonfg(); // Test H5File as a root group + test_file_info(); // Test various file info } // test_file() /*------------------------------------------------------------------------- - * Function: cleanup_file + * Function: cleanup_file * - * Purpose: Cleanup temporary test files + * Purpose Cleanup temporary test files * - * Return: none + * Return none * - * Programmer: (use C version) + * Programmer (use C version) * * Modifications: * diff --git a/c++/test/tfilter.cpp b/c++/test/tfilter.cpp index ee78fe1..19f5b5a 100644 --- a/c++/test/tfilter.cpp +++ b/c++/test/tfilter.cpp @@ -33,15 +33,15 @@ using namespace H5; #include "h5test.h" #include "h5cpputil.h" // C++ utilility header file -#define DSET_DIM1 100 -#define DSET_DIM2 200 +#define DSET_DIM1 100 +#define DSET_DIM2 200 #define FILTER_CHUNK_DIM1 2 #define FILTER_CHUNK_DIM2 25 // will do this function later or use it as guideline - BMR - 2007/01/26 #if 0 static herr_t test_filter_internal(hid_t fid, const char *name, hid_t dcpl, - int if_fletcher32, int corrupted, hsize_t *dset_size) + int if_fletcher32, int corrupted, hsize_t *dset_size) { cerr << "do nothing right now" << endl; return(0); @@ -58,25 +58,25 @@ static size_t filter_bogus(unsigned int flags, size_t cd_nelmts, static size_t filter_bogus(size_t nbytes); /* This message derives from H5Z */ const H5Z_class2_t H5Z_BOGUS[1] = {{ - H5Z_CLASS_T_VERS, /* H5Z_class_t version */ - H5Z_FILTER_BOGUS, /* Filter id number */ - 1, 1, /* Encoding and decoding enabled */ - "bogus", /* Filter name for debugging */ - NULL, /* The "can apply" callback */ - NULL, /* The "set local" callback */ + H5Z_CLASS_T_VERS, /* H5Z_class_t version */ + H5Z_FILTER_BOGUS, /* Filter id number */ + 1, 1, /* Encoding and decoding enabled */ + "bogus", /* Filter name for debugging */ + NULL, /* The "can apply" callback */ + NULL, /* The "set local" callback */ (H5Z_func_t)filter_bogus, /* The actual filter function */ }}; /*------------------------------------------------------------------------- * Function: filter_bogus * - * Purpose: A bogus compression method that doesn't do anything. + * Purpose A bogus compression method that doesn't do anything. * - * Return: Success: Data chunk size + * Return Success: Data chunk size * - * Failure: 0 + * Failure: 0 * - * Programmer: Robb Matzke + * Programmer Robb Matzke * Tuesday, April 21, 1998 * * Modifications: @@ -95,17 +95,17 @@ filter_bogus(size_t nbytes) } /*------------------------------------------------------------------------- - * Function: test_null_filter + * Function: test_null_filter * - * Purpose: Test null I/O filter by itself. + * Purpose Test null I/O filter by itself. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version, from dsets.c/test_filters) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version, from dsets.c/test_filters) + * January, 2007 * * Modifications: - * Note: H5Z interface is not implemented yet. + * Note: H5Z interface is not implemented yet. * *------------------------------------------------------------------------- */ @@ -118,25 +118,25 @@ static void test_null_filter() // Output message about test being performed SUBTEST("'Null' filter"); try { - //hsize_t null_size; // Size of dataset with null filter + //hsize_t null_size; // Size of dataset with null filter - // Prepare dataset create property list - DSetCreatPropList dsplist; - dsplist.setChunk(2, chunk_size); + // Prepare dataset create property list + DSetCreatPropList dsplist; + dsplist.setChunk(2, chunk_size); - if (H5Zregister (H5Z_BOGUS)<0) + if (H5Zregister (H5Z_BOGUS)<0) throw Exception("test_null_filter", "H5Zregister failed"); - // Set some pretent filter - dsplist.setFilter(H5Z_FILTER_BOGUS); + // Set some pretent filter + dsplist.setFilter(H5Z_FILTER_BOGUS); - // this function is just a stub right now; will work on it later - BMR - //if(test_filter_internal(file,DSET_BOGUS_NAME,dc,DISABLE_FLETCHER32,DATA_NOT_CORRUPTED,&null_size)<0) + // this function is just a stub right now; will work on it later - BMR + //if(test_filter_internal(file,DSET_BOGUS_NAME,dc,DISABLE_FLETCHER32,DATA_NOT_CORRUPTED,&null_size)<0) // throw Exception("test_null_filter", "test_filter_internal failed"); - // Close objects. - dsplist.close(); - PASSED(); + // Close objects. + dsplist.close(); + PASSED(); } // end of try // catch all other exceptions @@ -147,17 +147,17 @@ static void test_null_filter() } // test_null_filter /*------------------------------------------------------------------------- - * Function: test_szip_filter + * Function: test_szip_filter * - * Purpose: Test SZIP filter by itself. + * Purpose Test SZIP filter by itself. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (partly from dsets.c/test_filters) - * January, 2007 + * Programmer Binh-Minh Ribler (partly from dsets.c/test_filters) + * January, 2007 * * Modifications: - * Note: H5Z interface is not implemented yet. + * Note: H5Z interface is not implemented yet. * *------------------------------------------------------------------------- */ @@ -232,7 +232,7 @@ static void test_szip_filter(H5File& file1) delete[] tconv_buf; } // if szip presents else { - SKIPPED(); + SKIPPED(); } #else /* H5_HAVE_FILTER_SZIP */ @@ -266,9 +266,9 @@ void test_filters() H5File file1(FILE1, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); - // Test basic VL string datatype - test_null_filter(); - test_szip_filter(file1); + // Test basic VL string datatype + test_null_filter(); + test_szip_filter(file1); } catch (Exception& E) { @@ -277,13 +277,13 @@ void test_filters() } // test_filters() /*------------------------------------------------------------------------- - * Function: cleanup_filters + * Function: cleanup_filters * - * Purpose: Cleanup temporary test files + * Purpose Cleanup temporary test files * - * Return: none + * Return none * - * Programmer: Quincey Koziol + * Programmer Quincey Koziol * September 10, 1999 * * Modifications: diff --git a/c++/test/th5s.cpp b/c++/test/th5s.cpp index c795c08..a3aafb3 100644 --- a/c++/test/th5s.cpp +++ b/c++/test/th5s.cpp @@ -35,7 +35,7 @@ using namespace H5; #include "h5test.h" #include "h5cpputil.h" // C++ utilility header file -#include "H5srcdir.h" // srcdir querying header file +#include "H5srcdir.h" // srcdir querying header file const H5std_string TESTFILE("th5s.h5"); const H5std_string DATAFILE("th5s1.h5"); @@ -86,124 +86,123 @@ int space5_data = 7; /*------------------------------------------------------------------------- * - * Function: test_h5s_basic + * Function: test_h5s_basic * - * Purpose: Test basic H5S (dataspace) code + * Purpose Test basic H5S (dataspace) code * - * Return: none + * Return none * - * Programmer: Binh-Minh Ribler (using C version) + * Programmer Binh-Minh Ribler (using C version) * Mar 2001 * * Modifications: * January, 2005: C tests' macro VERIFY casts values to 'long' for all - * cases. Since there are no operator<< for 'long long' - * or int64 in VS C++ ostream, I casted the hssize_t values - * passed to verify_val to 'long' as well. If problems - * arises later, this will have to be specificly handled - * with a special routine. + * cases. Since there are no operator<< for 'long long' + * or int64 in VS C++ ostream, I casted the hssize_t values + * passed to verify_val to 'long' as well. If problems + * arises later, this will have to be specificly handled + * with a special routine. * April 12, 2011: Raymond Lu - * Starting from the 1.8.7 release, we allow dimension - * size to be zero. So I took out the test against it. + * Starting from the 1.8.7 release, we allow dimension + * size to be zero. So I took out the test against it. *------------------------------------------------------------------------- */ static void test_h5s_basic() { - hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; - hsize_t dims2[] = {SPACE2_DIM1, SPACE2_DIM2, SPACE2_DIM3, - SPACE2_DIM4}; - hsize_t dims3[H5S_MAX_RANK+1]; - hsize_t tmax[4]; + hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3}; + hsize_t dims2[] = {SPACE2_DIM1, SPACE2_DIM2, SPACE2_DIM3, SPACE2_DIM4}; + hsize_t dims3[H5S_MAX_RANK+1]; + hsize_t tmax[4]; // Output message about test being performed SUBTEST("Dataspace Manipulation"); try { - // Create simple dataspace sid1 - DataSpace sid1 (SPACE1_RANK, dims1 ); - - // Get simple extent npoints of the dataspace sid1 and verify it - hssize_t n; // Number of dataspace elements - n = sid1.getSimpleExtentNpoints(); - verify_val((long)n, (long)(SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3), - "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); - - // Get the logical rank of dataspace sid1 and verify it - int rank; // Logical rank of dataspace - rank = sid1.getSimpleExtentNdims(); - verify_val(rank, SPACE1_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); - - // Retrieves dimension size of dataspace sid1 and verify it - int ndims; // Number of dimensions - hsize_t tdims[4]; // Dimension array to test with - ndims = sid1.getSimpleExtentDims( tdims ); - verify_val(ndims, SPACE1_RANK, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); - verify_val(HDmemcmp(tdims, dims1, SPACE1_RANK * sizeof(unsigned)), 0, - "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); - - // Create simple dataspace sid2 - hsize_t max2[] = {SPACE2_MAX1, SPACE2_MAX2, SPACE2_MAX3, SPACE2_MAX4}; - DataSpace sid2 (SPACE2_RANK, dims2, max2); - - // Get simple extent npoints of dataspace sid2 and verify it - n = sid2.getSimpleExtentNpoints(); - verify_val((long)n, (long)(SPACE2_DIM1 * SPACE2_DIM2 * SPACE2_DIM3 * SPACE2_DIM4), - "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); - - // Get the logical rank of dataspace sid2 and verify it - rank = sid2.getSimpleExtentNdims(); - verify_val(rank, SPACE2_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); - - // Retrieves dimension size and max size of dataspace sid2 and - // verify them - ndims = sid2.getSimpleExtentDims( tdims, tmax ); - verify_val(HDmemcmp(tdims, dims2, SPACE2_RANK * sizeof(unsigned)), 0, - "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); - verify_val(HDmemcmp(tmax, max2, SPACE2_RANK * sizeof(unsigned)), 0, - "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); - - // Check to be sure we can't create a simple data space that has too - // many dimensions. - try { - DataSpace manydims_ds(H5S_MAX_RANK+1, dims3, NULL); - - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("DataSpace constructor", "Library allowed overwrite of existing dataset"); - } - catch (DataSpaceIException& E) // Simple data space with too many dims - {} // do nothing, exception expected + // Create simple dataspace sid1 + DataSpace sid1 (SPACE1_RANK, dims1 ); + + // Get simple extent npoints of the dataspace sid1 and verify it + hssize_t n; // Number of dataspace elements + n = sid1.getSimpleExtentNpoints(); + verify_val((long)n, (long)(SPACE1_DIM1 * SPACE1_DIM2 * SPACE1_DIM3), + "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); + + // Get the logical rank of dataspace sid1 and verify it + int rank; // Logical rank of dataspace + rank = sid1.getSimpleExtentNdims(); + verify_val(rank, SPACE1_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); + + // Retrieves dimension size of dataspace sid1 and verify it + int ndims; // Number of dimensions + hsize_t tdims[4]; // Dimension array to test with + ndims = sid1.getSimpleExtentDims( tdims ); + verify_val(ndims, SPACE1_RANK, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); + verify_val(HDmemcmp(tdims, dims1, SPACE1_RANK * sizeof(unsigned)), 0, + "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); + + // Create simple dataspace sid2 + hsize_t max2[] = {SPACE2_MAX1, SPACE2_MAX2, SPACE2_MAX3, SPACE2_MAX4}; + DataSpace sid2 (SPACE2_RANK, dims2, max2); + + // Get simple extent npoints of dataspace sid2 and verify it + n = sid2.getSimpleExtentNpoints(); + verify_val((long)n, (long)(SPACE2_DIM1 * SPACE2_DIM2 * SPACE2_DIM3 * SPACE2_DIM4), + "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); + + // Get the logical rank of dataspace sid2 and verify it + rank = sid2.getSimpleExtentNdims(); + verify_val(rank, SPACE2_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); + + // Retrieves dimension size and max size of dataspace sid2 and + // verify them + ndims = sid2.getSimpleExtentDims( tdims, tmax ); + verify_val(HDmemcmp(tdims, dims2, SPACE2_RANK * sizeof(unsigned)), 0, + "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); + verify_val(HDmemcmp(tmax, max2, SPACE2_RANK * sizeof(unsigned)), 0, + "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); + + // Check to be sure we can't create a simple data space that has too + // many dimensions. + try { + DataSpace manydims_ds(H5S_MAX_RANK+1, dims3, NULL); + + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("DataSpace constructor", "Library allowed overwrite of existing dataset"); + } + catch (DataSpaceIException& E) // Simple data space with too many dims + {} // do nothing, exception expected /* - * Try reading a file that has been prepared that has a dataset with a - * higher dimensionality than what the library can handle. - * - * If this test fails and the H5S_MAX_RANK variable has changed, follow - * the instructions in space_overflow.c for regenating the th5s.h5 file. - */ - char *tmp_str = new char[TESTFILE.length()+1]; - strcpy(tmp_str, TESTFILE.c_str()); - const char *testfile = H5_get_srcdir_filename(tmp_str); - delete []tmp_str; - - // Create file - H5File fid1(testfile, H5F_ACC_RDONLY); - - // Try to open the dataset that has higher dimensionality than - // what the library can handle and this operation should fail. - try { - DataSet dset1 = fid1.openDataSet( "dset" ); - - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("H5File::openDataSet", "Opening a dataset with higher dimensionality than what the library can handle"); - } - catch (FileIException& E) // catching higher dimensionality dataset - {} // do nothing, exception expected + * Try reading a file that has been prepared that has a dataset with a + * higher dimensionality than what the library can handle. + * + * If this test fails and the H5S_MAX_RANK variable has changed, follow + * the instructions in space_overflow.c for regenating the th5s.h5 file. + */ + char *tmp_str = new char[TESTFILE.length()+1]; + strcpy(tmp_str, TESTFILE.c_str()); + const char *testfile = H5_get_srcdir_filename(tmp_str); + delete []tmp_str; + + // Create file + H5File fid1(testfile, H5F_ACC_RDONLY); + + // Try to open the dataset that has higher dimensionality than + // what the library can handle and this operation should fail. + try { + DataSet dset1 = fid1.openDataSet( "dset" ); + + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("H5File::openDataSet", "Opening a dataset with higher dimensionality than what the library can handle"); + } + 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 + // in the p_close see how this will handle it. - BMR - PASSED(); - } // end of try block + PASSED(); + } // end of try block catch (InvalidActionException& E) { @@ -219,22 +218,22 @@ static void test_h5s_basic() /*------------------------------------------------------------------------- * - * Function: test_h5s_scalar_write + * Function: test_h5s_scalar_write * - * Purpose: Test scalar H5S (dataspace) writing code + * Purpose Test scalar H5S (dataspace) writing code * - * Return: none + * Return none * - * Programmer: Binh-Minh Ribler (using C version) + * Programmer Binh-Minh Ribler (using C version) * Mar 2001 * * Modifications: * January, 2005: C tests' macro VERIFY casts values to 'long' for all - * cases. Since there are no operator<< for 'long long' - * or int64 in VS C++ ostream, I casted the hssize_t values - * passed to verify_val to 'long' as well. If problems - * arises later, this will have to be specificly handled - * with a special routine. + * cases. Since there are no operator<< for 'long long' + * or int64 in VS C++ ostream, I casted the hssize_t values + * passed to verify_val to 'long' as well. If problems + * arises later, this will have to be specificly handled + * with a special routine. *------------------------------------------------------------------------- */ static void test_h5s_scalar_write() @@ -243,124 +242,124 @@ static void test_h5s_scalar_write() SUBTEST("Scalar Dataspace Writing"); try { - // Create file - H5File fid1(DATAFILE, H5F_ACC_TRUNC); + // Create file + H5File fid1(DATAFILE, H5F_ACC_TRUNC); - // Create scalar dataspace - DataSpace sid1(SPACE3_RANK, NULL); + // Create scalar dataspace + DataSpace sid1(SPACE3_RANK, NULL); - //n = H5Sget_simple_extent_npoints(sid1); - hssize_t n; // Number of dataspace elements - n = sid1.getSimpleExtentNpoints(); - verify_val((long)n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); + //n = H5Sget_simple_extent_npoints(sid1); + hssize_t n; // Number of dataspace elements + n = sid1.getSimpleExtentNpoints(); + verify_val((long)n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); - int rank; // Logical rank of dataspace - rank = sid1.getSimpleExtentNdims(); - verify_val(rank, SPACE3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); + int rank; // Logical rank of dataspace + rank = sid1.getSimpleExtentNdims(); + verify_val(rank, SPACE3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); - // Retrieves dimension size of dataspace sid1 and verify it - int ndims; // Number of dimensions - hsize_t tdims[4]; // Dimension array to test with - ndims = sid1.getSimpleExtentDims( tdims ); - verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); + // Retrieves dimension size of dataspace sid1 and verify it + int ndims; // Number of dimensions + hsize_t tdims[4]; // Dimension array to test with + ndims = sid1.getSimpleExtentDims( tdims ); + verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); - // Verify extent type - H5S_class_t ext_type; // Extent type - ext_type = sid1.getSimpleExtentType(); - verify_val(ext_type, H5S_SCALAR, "DataSpace::getSimpleExtentType", __LINE__, __FILE__); + // Verify extent type + H5S_class_t ext_type; // Extent type + ext_type = sid1.getSimpleExtentType(); + verify_val(ext_type, H5S_SCALAR, "DataSpace::getSimpleExtentType", __LINE__, __FILE__); - // Create and write a dataset - DataSet dataset = fid1.createDataSet("Dataset1", PredType::NATIVE_UINT,sid1); - dataset.write(&space3_data, PredType::NATIVE_UINT); + // Create and write a dataset + DataSet dataset = fid1.createDataSet("Dataset1", PredType::NATIVE_UINT,sid1); + dataset.write(&space3_data, PredType::NATIVE_UINT); - PASSED(); + PASSED(); } // end of try block catch (Exception& E) { - issue_fail_msg("test_h5s_scalar_write()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_h5s_scalar_write()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_h5s_scalar_write() /*------------------------------------------------------------------------- * - * Function: test_h5s_scalar_read + * Function: test_h5s_scalar_read * - * Purpose: Test scalar H5S (dataspace) reading code + * Purpose Test scalar H5S (dataspace) reading code * - * Return: none + * Return none * - * Programmer: Binh-Minh Ribler (using C version) + * Programmer Binh-Minh Ribler (using C version) * Mar 2001 * * Modifications: * January, 2005: C tests' macro VERIFY casts values to 'long' for all - * cases. Since there are no operator<< for 'long long' - * or int64 in VS C++ ostream, I casted the hssize_t values - * passed to verify_val to 'long' as well. If problems - * arises later, this will have to be specificly handled - * with a special routine. + * cases. Since there are no operator<< for 'long long' + * or int64 in VS C++ ostream, I casted the hssize_t values + * passed to verify_val to 'long' as well. If problems + * arises later, this will have to be specificly handled + * with a special routine. *------------------------------------------------------------------------- */ static void test_h5s_scalar_read() { - hsize_t tdims[4]; // Dimension array to test with + hsize_t tdims[4]; // Dimension array to test with // Output message about test being performed SUBTEST("Scalar Dataspace Reading"); try { - // Open file - H5File fid1(DATAFILE, H5F_ACC_RDWR); + // Open file + H5File fid1(DATAFILE, H5F_ACC_RDWR); - // Create a dataset - DataSet dataset = fid1.openDataSet("Dataset1"); + // Create a dataset + DataSet dataset = fid1.openDataSet("Dataset1"); - DataSpace sid1 = dataset.getSpace(); + DataSpace sid1 = dataset.getSpace(); - // Get the number of dataspace elements - hssize_t n = sid1.getSimpleExtentNpoints(); - verify_val((long)n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); + // Get the number of dataspace elements + hssize_t n = sid1.getSimpleExtentNpoints(); + verify_val((long)n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); - // Get the logical rank of the dataspace - int ndims = sid1.getSimpleExtentNdims(); - verify_val(ndims, SPACE3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); + // Get the logical rank of the dataspace + int ndims = sid1.getSimpleExtentNdims(); + verify_val(ndims, SPACE3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); - ndims = sid1.getSimpleExtentDims(tdims); - verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); + 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__); + // 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(); + PASSED(); } // end of try block catch (Exception& E) { - // all the exceptions caused by negative returned values by C APIs - issue_fail_msg("test_h5s_scalar_read()", __LINE__, __FILE__, E.getCDetailMsg()); + // all the exceptions caused by negative returned values by C APIs + issue_fail_msg("test_h5s_scalar_read()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_h5s_scalar_read() /*------------------------------------------------------------------------- * - * Function: test_h5s_null + * Function: test_h5s_null * - * Purpose: Test null H5S (dataspace) code + * Purpose Test null H5S (dataspace) code * - * Return: none + * Return none * - * Programmer: Raymond Lu (using C version) + * Programmer Raymond Lu (using C version) * May 18, 2004 * * Modifications: * January, 2005: C tests' macro VERIFY casts values to 'long' for all - * cases. Since there are no operator<< for 'long long' - * or int64 in VS C++ ostream, I casted the hssize_t values - * passed to verify_val to 'long' as well. If problems - * arises later, this will have to be specificly handled - * with a special routine. + * cases. Since there are no operator<< for 'long long' + * or int64 in VS C++ ostream, I casted the hssize_t values + * passed to verify_val to 'long' as well. If problems + * arises later, this will have to be specificly handled + * with a special routine. *------------------------------------------------------------------------- */ static void test_h5s_null() @@ -369,53 +368,53 @@ static void test_h5s_null() SUBTEST("Null Dataspace Writing"); try { - // Create file - H5File fid1(DATAFILE, H5F_ACC_TRUNC); + // Create file + H5File fid1(DATAFILE, H5F_ACC_TRUNC); - // Create scalar dataspace - DataSpace sid1(H5S_NULL); + // Create scalar dataspace + DataSpace sid1(H5S_NULL); - hssize_t n; // Number of dataspace elements - n = sid1.getSimpleExtentNpoints(); - verify_val((long)n, 0, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); + hssize_t n; // Number of dataspace elements + n = sid1.getSimpleExtentNpoints(); + verify_val((long)n, 0, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); - // Create a dataset - DataSet dataset = fid1.createDataSet("Dataset1", PredType::NATIVE_UINT,sid1); + // Create a dataset + DataSet dataset = fid1.createDataSet("Dataset1", PredType::NATIVE_UINT,sid1); // Try to write nothing to the dataset - dataset.write(&space5_data, PredType::NATIVE_INT); + dataset.write(&space5_data, PredType::NATIVE_INT); // 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__); + dataset.read(&space5_data, PredType::NATIVE_INT); + verify_val(space5_data, 7, "DataSet::read", __LINE__, __FILE__); - PASSED(); + PASSED(); } // end of try block catch (Exception& E) { - issue_fail_msg("test_h5s_null()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_h5s_null()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_h5s_null() /*------------------------------------------------------------------------- * - * Function: test_h5s_compound_scalar_write + * Function: test_h5s_compound_scalar_write * - * Purpose: Test scalar H5S (dataspace) writing for compound - * datatypes + * Purpose Test scalar H5S (dataspace) writing for compound + * datatypes * - * Return: none + * Return none * - * Programmer: Binh-Minh Ribler (using C version) + * Programmer Binh-Minh Ribler (using C version) * Mar 2001 * * Modifications: * January, 2005: C tests' macro VERIFY casts values to 'long' for all - * cases. Since there are no operator<< for 'long long' - * or int64 in VS C++ ostream, I casted the hssize_t values - * passed to verify_val to 'long' as well. If problems - * arises later, this will have to be specificly handled - * with a special routine. + * cases. Since there are no operator<< for 'long long' + * or int64 in VS C++ ostream, I casted the hssize_t values + * passed to verify_val to 'long' as well. If problems + * arises later, this will have to be specificly handled + * with a special routine. *------------------------------------------------------------------------- */ static void test_h5s_compound_scalar_write() @@ -424,135 +423,135 @@ static void test_h5s_compound_scalar_write() SUBTEST("Compound Dataspace Writing"); try { - // Create file - H5File fid1(DATAFILE, H5F_ACC_TRUNC); - - // Create the compound datatype. - CompType tid1(sizeof(struct space4_struct)); - space4_field1_off=HOFFSET(struct space4_struct, c1); - tid1.insertMember(SPACE4_FIELDNAME1, space4_field1_off, - PredType::NATIVE_SCHAR); - space4_field2_off=HOFFSET(struct space4_struct, u); - tid1.insertMember(SPACE4_FIELDNAME2, space4_field2_off, - PredType::NATIVE_UINT); - space4_field3_off=HOFFSET(struct space4_struct, f); - tid1.insertMember(SPACE4_FIELDNAME3, space4_field3_off, - PredType::NATIVE_FLOAT); - space4_field4_off=HOFFSET(struct space4_struct, c2); - tid1.insertMember(SPACE4_FIELDNAME4, space4_field4_off, - PredType::NATIVE_SCHAR); - - // Create scalar dataspace - DataSpace sid1(SPACE3_RANK, NULL); - - // Get the number of dataspace elements - hssize_t n = sid1.getSimpleExtentNpoints(); - verify_val((long)n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); - - // Get the logical rank of the dataspace - int ndims = sid1.getSimpleExtentNdims(); - verify_val(ndims, SPACE3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); - - hsize_t tdims[4]; // Dimension array to test with - ndims = sid1.getSimpleExtentDims(tdims); - verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); - - // Create and write a dataset - DataSet dataset = fid1.createDataSet("Dataset1", tid1, sid1); - dataset.write(&space4_data, tid1); - - PASSED(); - } // end of try block + // Create file + H5File fid1(DATAFILE, H5F_ACC_TRUNC); + + // Create the compound datatype. + CompType tid1(sizeof(struct space4_struct)); + space4_field1_off=HOFFSET(struct space4_struct, c1); + tid1.insertMember(SPACE4_FIELDNAME1, space4_field1_off, + PredType::NATIVE_SCHAR); + space4_field2_off=HOFFSET(struct space4_struct, u); + tid1.insertMember(SPACE4_FIELDNAME2, space4_field2_off, + PredType::NATIVE_UINT); + space4_field3_off=HOFFSET(struct space4_struct, f); + tid1.insertMember(SPACE4_FIELDNAME3, space4_field3_off, + PredType::NATIVE_FLOAT); + space4_field4_off=HOFFSET(struct space4_struct, c2); + tid1.insertMember(SPACE4_FIELDNAME4, space4_field4_off, + PredType::NATIVE_SCHAR); + + // Create scalar dataspace + DataSpace sid1(SPACE3_RANK, NULL); + + // Get the number of dataspace elements + hssize_t n = sid1.getSimpleExtentNpoints(); + verify_val((long)n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); + + // Get the logical rank of the dataspace + int ndims = sid1.getSimpleExtentNdims(); + verify_val(ndims, SPACE3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); + + hsize_t tdims[4]; // Dimension array to test with + ndims = sid1.getSimpleExtentDims(tdims); + verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); + + // 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("test_h5s_compound_scalar_write()", __LINE__, __FILE__, E.getCDetailMsg()); + // all the exceptions caused by negative returned values by C APIs + issue_fail_msg("test_h5s_compound_scalar_write()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_h5s_compound_scalar_write() /*------------------------------------------------------------------------- * - * Function: test_h5s_compound_scalar_read + * Function: test_h5s_compound_scalar_read * - * Purpose: Test scalar H5S (dataspace) reading for compound - * datatypes + * Purpose Test scalar H5S (dataspace) reading for compound + * datatypes * - * Return: none + * Return none * - * Programmer: Binh-Minh Ribler (using C version) + * Programmer Binh-Minh Ribler (using C version) * Mar 2001 * * Modifications: * January, 2005: C tests' macro VERIFY casts values to 'long' for all - * cases. Since there are no operator<< for 'long long' - * or int64 in VS C++ ostream, I casted the hssize_t values - * passed to verify_val to 'long' as well. If problems - * arises later, this will have to be specificly handled - * with a special routine. + * cases. Since there are no operator<< for 'long long' + * or int64 in VS C++ ostream, I casted the hssize_t values + * passed to verify_val to 'long' as well. If problems + * arises later, this will have to be specificly handled + * with a special routine. *------------------------------------------------------------------------- */ static void test_h5s_compound_scalar_read() { - hsize_t tdims[4]; // Dimension array to test with + hsize_t tdims[4]; // Dimension array to test with // Output message about test being performed SUBTEST("Compound Dataspace Reading"); try { - // Open file - H5File fid1(DATAFILE, H5F_ACC_RDWR); + // Open file + H5File fid1(DATAFILE, H5F_ACC_RDWR); - // Create a dataset - DataSet dataset = fid1.openDataSet("Dataset1"); + // Create a dataset + DataSet dataset = fid1.openDataSet("Dataset1"); - DataSpace sid1 = dataset.getSpace(); + DataSpace sid1 = dataset.getSpace(); - // Get the number of dataspace elements - hssize_t n = sid1.getSimpleExtentNpoints(); - verify_val((long)n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); + // Get the number of dataspace elements + hssize_t n = sid1.getSimpleExtentNpoints(); + verify_val((long)n, 1, "DataSpace::getSimpleExtentNpoints", __LINE__, __FILE__); - // Get the logical rank of the dataspace - int ndims = sid1.getSimpleExtentNdims(); - verify_val(ndims, SPACE3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); + // Get the logical rank of the dataspace + int ndims = sid1.getSimpleExtentNdims(); + verify_val(ndims, SPACE3_RANK, "DataSpace::getSimpleExtentNdims", __LINE__, __FILE__); - ndims = sid1.getSimpleExtentDims(tdims); - verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); + ndims = sid1.getSimpleExtentDims(tdims); + verify_val(ndims, 0, "DataSpace::getSimpleExtentDims", __LINE__, __FILE__); - // Get the datatype of this dataset. - CompType type(dataset); + // Get the datatype of this dataset. + CompType type(dataset); - struct space4_struct rdata; // Scalar data read in - dataset.read(&rdata, type); + struct space4_struct rdata; // Scalar data read in + dataset.read(&rdata, type); - // Verify read data - if(HDmemcmp(&space4_data,&rdata,sizeof(struct space4_struct))) - { + // Verify read data + if(HDmemcmp(&space4_data,&rdata,sizeof(struct space4_struct))) + { cerr << "scalar data different: space4_data.c1=" - << space4_data.c1 << ", read_data4.c1=" << rdata.c1 << endl; + << space4_data.c1 << ", read_data4.c1=" << rdata.c1 << endl; cerr << "scalar data different: space4_data.u=" - << space4_data.u << ", read_data4.u=" << rdata.u << endl; + << space4_data.u << ", read_data4.u=" << rdata.u << endl; cerr << "scalar data different: space4_data.f=" - << space4_data.f << ", read_data4.f=" << rdata.f << endl; + << space4_data.f << ", read_data4.f=" << rdata.f << endl; TestErrPrintf("scalar data different: space4_data.c1=%c, read_data4.c1=%c\n", - space4_data.c1, rdata.c2); - } // end if - PASSED(); + 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("test_h5s_compound_scalar_read()", __LINE__, __FILE__, E.getCDetailMsg()); + // all the exceptions caused by negative returned values by C APIs + issue_fail_msg("test_h5s_compound_scalar_read()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_h5s_compound_scalar_read() /*------------------------------------------------------------------------- * - * Function: test_h5s + * Function: test_h5s * - * Purpose: Main dataspace testing routine + * Purpose Main dataspace testing routine * - * Return: none + * Return none * - * Programmer: Binh-Minh Ribler (using C version) + * Programmer Binh-Minh Ribler (using C version) * Mar 2001 * * Modifications: @@ -564,23 +563,23 @@ void test_h5s() // Output message about test being performed MESSAGE(5, ("Testing Dataspaces\n")); - test_h5s_basic(); // Test basic H5S code - test_h5s_scalar_write(); // Test scalar H5S writing code - test_h5s_scalar_read(); // Test scalar H5S reading code - test_h5s_null(); // Test null H5S code - test_h5s_compound_scalar_write(); // Test compound datatype scalar H5S writing code - test_h5s_compound_scalar_read(); // Test compound datatype scalar H5S reading code + test_h5s_basic(); // Test basic H5S code + test_h5s_scalar_write(); // Test scalar H5S writing code + test_h5s_scalar_read(); // Test scalar H5S reading code + test_h5s_null(); // Test null H5S code + test_h5s_compound_scalar_write(); // Test compound datatype scalar H5S writing code + test_h5s_compound_scalar_read(); // Test compound datatype scalar H5S reading code } // test_h5s() /*------------------------------------------------------------------------- - * Function: cleanup_h5s + * Function: cleanup_h5s * - * Purpose: Cleanup temporary test files + * Purpose Cleanup temporary test files * - * Return: none + * Return none * - * Programmer: Albert Cheng + * Programmer Albert Cheng * July 2, 1998 * * Modifications: diff --git a/c++/test/titerate.cpp b/c++/test/titerate.cpp index 7ee2b53..fce42fa 100644 --- a/c++/test/titerate.cpp +++ b/c++/test/titerate.cpp @@ -49,20 +49,20 @@ using namespace H5; //#define SPACE1_RANK 1 //#define SPACE1_DIM1 4 -const H5std_string FILE_ITERATE("titerate.h5"); -const H5std_string GROUP1("Top Group"); -const H5std_string GROUP1_PATH("/Top Group"); -const H5std_string GROUP1_1("Sub-Group 1.1"); -const H5std_string GROUP1_1_PATH("/Top Group/Sub-Group 1.1"); -const H5std_string GROUP1_2("Sub-Group 1.2"); -const H5std_string GROUP1_2_PATH("/Top Group/Sub-Group 1.2"); -const H5std_string DSET_DEFAULT_NAME("default"); -const H5std_string DSET_IN_FILE("Dataset in File"); -const H5std_string DSET_IN_FILE_PATH("/Dataset in File"); -const H5std_string DSET_IN_GRP1("Dataset in Group 1"); -const H5std_string DSET_IN_GRP1_PATH("/Top Group/Dataset in Group 1"); -const H5std_string DSET_IN_GRP1_2("Dataset in Group 1.2"); -const H5std_string DSET_IN_GRP1_2_PATH("/Top Group/Sub-Group 1.2/Dataset in Group 1.2"); +const H5std_string FILE_ITERATE("titerate.h5"); +const H5std_string GROUP1("Top Group"); +const H5std_string GROUP1_PATH("/Top Group"); +const H5std_string GROUP1_1("Sub-Group 1.1"); +const H5std_string GROUP1_1_PATH("/Top Group/Sub-Group 1.1"); +const H5std_string GROUP1_2("Sub-Group 1.2"); +const H5std_string GROUP1_2_PATH("/Top Group/Sub-Group 1.2"); +const H5std_string DSET_DEFAULT_NAME("default"); +const H5std_string DSET_IN_FILE("Dataset in File"); +const H5std_string DSET_IN_FILE_PATH("/Dataset in File"); +const H5std_string DSET_IN_GRP1("Dataset in Group 1"); +const H5std_string DSET_IN_GRP1_PATH("/Top Group/Dataset in Group 1"); +const H5std_string DSET_IN_GRP1_2("Dataset in Group 1.2"); +const H5std_string DSET_IN_GRP1_2_PATH("/Top Group/Sub-Group 1.2/Dataset in Group 1.2"); typedef enum { RET_ZERO, @@ -127,15 +127,15 @@ liter_cb(hid_t H5_ATTR_UNUSED group, const char *name, const H5L_info_t H5_ATTR_ } /* end liter_cb() */ /*------------------------------------------------------------------------- - * Function: test_iter_group + * Function: test_iter_group * - * Purpose: Tests group iteration + * Purpose Tests group iteration * - * Return: Success: 0 - * Failure: -1 + * Return Success: 0 + * Failure: -1 * - * Programmer: Binh-Minh Ribler - * Friday, September 9, 2016 + * Programmer Binh-Minh Ribler + * Friday, September 9, 2016 * * Modifications: * @@ -148,142 +148,142 @@ static void test_iter_group(FileAccPropList& fapl) char name[NAMELEN]; /* temporary name buffer */ char *lnames[NDATASETS + 2];/* Names of the links created */ iter_info info; /* Custom iteration information */ - herr_t ret; /* Generic return value */ + herr_t ret; /* Generic return value */ /* Output message about test being performed */ SUBTEST("Group Iteration"); /* Create the test file with the datasets */ try { - // Create file - H5File file(FILE_ITERATE, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); + // Create file + H5File file(FILE_ITERATE, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); - /* Test iterating over empty group */ - info.command = RET_ZERO; - idx = 0; - ret = H5Literate(file.getId(), H5_INDEX_NAME, H5_ITER_INC, &idx, liter_cb, &info); - verify_val(ret, SUCCEED, "H5Literate", __LINE__, __FILE__); + /* Test iterating over empty group */ + info.command = RET_ZERO; + idx = 0; + ret = H5Literate(file.getId(), H5_INDEX_NAME, H5_ITER_INC, &idx, liter_cb, &info); + verify_val(ret, SUCCEED, "H5Literate", __LINE__, __FILE__); - DataType datatype(PredType::NATIVE_INT); + DataType datatype(PredType::NATIVE_INT); - // Create a scalar file space - DataSpace filespace; + // Create a scalar file space + DataSpace filespace; - for (i=0; i< NDATASETS; i++) - { + for (i=0; i< NDATASETS; i++) + { sprintf(name, "Dataset %d", i); - // Create a dataset in the file - DataSet dataset = file.createDataSet(name, datatype, filespace); + // Create a dataset in the file + DataSet dataset = file.createDataSet(name, datatype, filespace); /* Keep a copy of the dataset names */ lnames[i] = HDstrdup(name); check_values(lnames[i], "HDstrdup returns NULL", __LINE__, __FILE__); - } /* end for */ + } /* end for */ - /* Create a group and named datatype under root group for testing */ - Group grp(file.createGroup(GROUP1, 0)); - lnames[NDATASETS] = HDstrdup("grp"); - check_values(lnames[NDATASETS], "HDstrdup returns NULL", __LINE__, __FILE__); + /* Create a group and named datatype under root group for testing */ + Group grp(file.createGroup(GROUP1, 0)); + lnames[NDATASETS] = HDstrdup("grp"); + check_values(lnames[NDATASETS], "HDstrdup returns NULL", __LINE__, __FILE__); - datatype.commit(file, "dtype"); - lnames[NDATASETS + 1] = HDstrdup("dtype"); - check_values(lnames[NDATASETS], "HDstrdup returns NULL", __LINE__, __FILE__); + datatype.commit(file, "dtype"); + lnames[NDATASETS + 1] = HDstrdup("dtype"); + check_values(lnames[NDATASETS], "HDstrdup returns NULL", __LINE__, __FILE__); - /* Sort the dataset names */ - HDqsort(lnames, (size_t)(NDATASETS + 2), sizeof(char *), iter_strcmp); + /* Sort the dataset names */ + HDqsort(lnames, (size_t)(NDATASETS + 2), sizeof(char *), iter_strcmp); - /* Iterate through the datasets in the root group in various ways */ + /* Iterate through the datasets in the root group in various ways */ - // Open data file to read - file.openFile(FILE_ITERATE, H5F_ACC_RDONLY, fapl); + // Open data file to read + file.openFile(FILE_ITERATE, H5F_ACC_RDONLY, fapl); - // Open the root group - Group root_group(file.openGroup("/")); + // Open the root group + Group root_group(file.openGroup("/")); - // Get the number of object in the root group - hsize_t nobjs = root_group.getNumObjs(); - verify_val(nobjs, (hsize_t)(NDATASETS + 2), "H5Gget_info", __LINE__, __FILE__); + // Get the number of object in the root group + hsize_t nobjs = root_group.getNumObjs(); + verify_val(nobjs, (hsize_t)(NDATASETS + 2), "H5Gget_info", __LINE__, __FILE__); - H5std_string obj_name; - for (i = 0; i < nobjs; i++) - { - //H5O_info_t oinfo; /* Object info */ + H5std_string obj_name; + for (i = 0; i < nobjs; i++) + { + //H5O_info_t oinfo; /* Object info */ - obj_name = root_group.getObjnameByIdx(i); + obj_name = root_group.getObjnameByIdx(i); //ret = (herr_t)H5Lget_name_by_idx(root_group, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)i, dataset_name, (size_t)NAMELEN, H5P_DEFAULT); - //oinfo = root_group.childObjType((hsize_t)i, H5_INDEX_NAME, H5_ITER_INC, "."); + //oinfo = root_group.childObjType((hsize_t)i, H5_INDEX_NAME, H5_ITER_INC, "."); //ret = H5Oget_info_by_idx(root_group, ".", H5_INDEX_NAME, H5_ITER_INC, (hsize_t)i, &oinfo, H5P_DEFAULT); - } /* end for */ - - // Attempted to iterate with invalid index, should fail - try { - obj_name = root_group.getObjnameByIdx(NDATASETS + 3); - - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("Group::getObjnameByIdx", "Attempt to iterate with invalid index"); - } - catch (GroupIException& invalid_action) // invalid index - {} // do nothing, exception expected - - // Attempted to iterate with negative index, should fail - try { - info.command = RET_ZERO; - idx = (hsize_t)-1; - obj_name = root_group.getObjnameByIdx(idx); - - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("Group::getObjnameByIdx", "Attempt to iterate with negative index"); - } - catch (FileIException& invalid_action) // invalid index - {} // do nothing, exception expected - catch (GroupIException& invalid_action) // invalid index - {} // do nothing, exception expected - - /* Test skipping exactly as many entries as in the group */ - try { - info.command = RET_ZERO; - idx = NDATASETS + 2; - obj_name = root_group.getObjnameByIdx(idx); - - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("Group::getObjnameByIdx", "Attempt to iterate with negative index"); - } - catch (FileIException& invalid_action) // invalid index - {} // do nothing, exception expected - catch (GroupIException& invalid_action) // invalid index - {} // do nothing, exception expected - - /* Test skipping more entries than are in the group */ - try { - info.command = RET_ZERO; - idx = NDATASETS + 3; - obj_name = root_group.getObjnameByIdx(idx); - - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("Group::getObjnameByIdx", "Attempt to iterate with negative index"); - } - catch (FileIException& invalid_action) // invalid index - {} // do nothing, exception expected - catch (GroupIException& invalid_action) // invalid index - {} // do nothing, exception expected - - /* Free the dataset names */ - for(i = 0; i< (NDATASETS + 2); i++) - HDfree(lnames[i]); - - // Everything will be closed as they go out of scope - - PASSED(); - } // try block + } /* end for */ + + // Attempted to iterate with invalid index, should fail + try { + obj_name = root_group.getObjnameByIdx(NDATASETS + 3); + + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("Group::getObjnameByIdx", "Attempt to iterate with invalid index"); + } + catch (GroupIException& invalid_action) // invalid index + {} // do nothing, exception expected + + // Attempted to iterate with negative index, should fail + try { + info.command = RET_ZERO; + idx = (hsize_t)-1; + obj_name = root_group.getObjnameByIdx(idx); + + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("Group::getObjnameByIdx", "Attempt to iterate with negative index"); + } + catch (FileIException& invalid_action) // invalid index + {} // do nothing, exception expected + catch (GroupIException& invalid_action) // invalid index + {} // do nothing, exception expected + + /* Test skipping exactly as many entries as in the group */ + try { + info.command = RET_ZERO; + idx = NDATASETS + 2; + obj_name = root_group.getObjnameByIdx(idx); + + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("Group::getObjnameByIdx", "Attempt to iterate with negative index"); + } + catch (FileIException& invalid_action) // invalid index + {} // do nothing, exception expected + catch (GroupIException& invalid_action) // invalid index + {} // do nothing, exception expected + + /* Test skipping more entries than are in the group */ + try { + info.command = RET_ZERO; + idx = NDATASETS + 3; + obj_name = root_group.getObjnameByIdx(idx); + + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("Group::getObjnameByIdx", "Attempt to iterate with negative index"); + } + catch (FileIException& invalid_action) // invalid index + {} // do nothing, exception expected + catch (GroupIException& invalid_action) // invalid index + {} // do nothing, exception expected + + /* Free the dataset names */ + for(i = 0; i< (NDATASETS + 2); i++) + HDfree(lnames[i]); + + // Everything will be closed as they go out of scope + + PASSED(); + } // try block // catch all other exceptions catch (Exception& E) { - issue_fail_msg("test_iter_group", __LINE__, __FILE__); + issue_fail_msg("test_iter_group", __LINE__, __FILE__); } #if 0 @@ -355,59 +355,59 @@ static void test_iter_group(FileAccPropList& fapl) /**************************************************************** ** ** printelems(): Open an attribute and verify that it has a -** the correct name +** the correct name ** ****************************************************************/ -const H5std_string FILE_NAME("titerate.h5"); -const H5std_string GRP_NAME("/Group_A"); -const H5std_string FDATASET_NAME( "file dset" ); -const H5std_string GDATASET_NAME( "group dset" ); -const H5std_string ATTR_NAME( "Units" ); -const H5std_string FATTR_NAME( "F attr" ); -const H5std_string GATTR_NAME( "G attr" ); -const int DIM1 = 2; +const H5std_string FILE_NAME("titerate.h5"); +const H5std_string GRP_NAME("/Group_A"); +const H5std_string FDATASET_NAME("file dset"); +const H5std_string GDATASET_NAME("group dset"); +const H5std_string ATTR_NAME("Units"); +const H5std_string FATTR_NAME("F attr"); +const H5std_string GATTR_NAME("G attr"); +const int DIM1 = 2; void printelems(const Group& group, const H5std_string& dsname, const H5std_string& atname) { try { - DataSet d1(group.openDataSet(dsname)); - DataSpace s1 = d1.getSpace(); - s1.close(); - d1.close(); - - unsigned idx = 0; - Attribute a1(group.openAttribute(idx)); - H5std_string aname = a1.getName(); + DataSet d1(group.openDataSet(dsname)); + DataSpace s1 = d1.getSpace(); + s1.close(); + d1.close(); + + unsigned idx = 0; + Attribute a1(group.openAttribute(idx)); + H5std_string aname = a1.getName(); verify_val(aname, atname, "printelems", __LINE__, __FILE__); - a1.close(); + a1.close(); } // catch failure caused by the DataSpace operations catch( DataSpaceIException error ) { - error.printError(); + error.printError(); } // catch failure caused by the Group operations catch( GroupIException error ) { - error.printError(); + error.printError(); } // catch failure caused by the DataSet operations catch( DataSetIException error ) { - error.printError(); + error.printError(); } } /*------------------------------------------------------------------------- - * Function: test_HDFFV_9920 + * Function: test_HDFFV_9920 * - * Purpose: Tests the fix for HDFFV-9920 + * Purpose Tests the fix for HDFFV-9920 * - * Programmer: Binh-Minh Ribler - * Friday, September 9, 2016 + * Programmer Binh-Minh Ribler + * Friday, September 9, 2016 * * Modifications: * @@ -420,74 +420,74 @@ static void test_HDFFV_9920() try { - // Create a new file and a group in it - H5File file( FILE_NAME, H5F_ACC_TRUNC ); + // Create a new file and a group in it + H5File file( FILE_NAME, H5F_ACC_TRUNC ); - Group gr1(file.createGroup(GRP_NAME)); + Group gr1(file.createGroup(GRP_NAME)); - // Create the data space for the attribute. - DataSpace dspace = DataSpace (1, dims ); + // Create the data space for the attribute. + DataSpace dspace = DataSpace (1, dims ); - DataSet fds = file.createDataSet(FDATASET_NAME, PredType::STD_I32BE, dspace); - DataSet gds = gr1.createDataSet(GDATASET_NAME, PredType::STD_I32BE, dspace); + DataSet fds = file.createDataSet(FDATASET_NAME, PredType::STD_I32BE, dspace); + DataSet gds = gr1.createDataSet(GDATASET_NAME, PredType::STD_I32BE, dspace); - // Create a file attribute and a group attribute. - Attribute fa1 = file.createAttribute(FATTR_NAME, PredType::STD_I32BE, - dspace); - Attribute ga1 = gr1.createAttribute(GATTR_NAME, PredType::STD_I32BE, - dspace); + // Create a file attribute and a group attribute. + Attribute fa1 = file.createAttribute(FATTR_NAME, PredType::STD_I32BE, + dspace); + Attribute ga1 = gr1.createAttribute(GATTR_NAME, PredType::STD_I32BE, + dspace); - // Write the attribute data. - fa1.write( PredType::NATIVE_INT, attr_data); - ga1.write( PredType::NATIVE_INT, attr_data); + // Write the attribute data. + fa1.write( PredType::NATIVE_INT, attr_data); + ga1.write( PredType::NATIVE_INT, attr_data); - fa1.close(); - ga1.close(); - fds.close(); - gds.close(); + fa1.close(); + ga1.close(); + fds.close(); + gds.close(); - // Verify the attributes have correct names. - printelems(file, FDATASET_NAME, FATTR_NAME); - printelems(gr1, GDATASET_NAME, GATTR_NAME); + // Verify the attributes have correct names. + printelems(file, FDATASET_NAME, FATTR_NAME); + printelems(gr1, GDATASET_NAME, GATTR_NAME); } // end of try block // catch failure caused by the H5File operations catch( DataSpaceIException error ) { - error.printError(); + error.printError(); } // catch failure caused by the H5File operations catch( AttributeIException error ) { - error.printError(); + error.printError(); } // catch failure caused by the H5File operations catch( FileIException error ) { - error.printError(); + error.printError(); } // catch failure caused by the DataSet operations catch( DataSetIException error ) { - error.printError(); + error.printError(); } } /*------------------------------------------------------------------------- - * Function: test_iterate + * Function: test_iterate * - * Purpose: Tests iterate functionality + * Purpose Tests iterate functionality * - * Return: Success: 0 - * Failure: -1 + * Return Success: 0 + * Failure: -1 * - * Programmer: Binh-Minh Ribler - * Tuesday, September 6, 2016 + * Programmer Binh-Minh Ribler + * Tuesday, September 6, 2016 * * Modifications: * @@ -503,20 +503,20 @@ void test_iterate() FileAccPropList fapl; fapl.setLibverBounds(H5F_LIBVER_LATEST, H5F_LIBVER_LATEST); - test_iter_group(fapl); // Test iterating groups - test_HDFFV_9920(); // Test the fix of HDFFV-9920 - //test_iter_attr(fapl); // Test iterating attributes + test_iter_group(fapl); // Test iterating groups + test_HDFFV_9920(); // Test the fix of HDFFV-9920 + //test_iter_attr(fapl); // Test iterating attributes } // test_iterate /*------------------------------------------------------------------------- * Function: cleanup_iterate * - * Purpose: Cleanup temporary test files + * Purpose Cleanup temporary test files * - * Return: none + * Return none * - * Programmer: (use C version) + * Programmer (use C version) * * Modifications: * diff --git a/c++/test/tlinks.cpp b/c++/test/tlinks.cpp index 3acf4e1..c217718 100644 --- a/c++/test/tlinks.cpp +++ b/c++/test/tlinks.cpp @@ -43,9 +43,9 @@ using namespace H5; //#define H5G_TESTING //#include "h5test.h" -//#include "H5Gpkg.h" /* Groups */ -//#include "H5Iprivate.h" /* IDs */ -//#include "H5Lprivate.h" /* Links */ +//#include "H5Gpkg.h" /* Groups */ +//#include "H5Iprivate.h" /* IDs */ +//#include "H5Lprivate.h" /* Links */ /* File for external link test. Created with gen_udlinks.c */ #define LINKED_FILE "be_extlink2.h5" @@ -64,39 +64,39 @@ const char *FILENAME[] = { "links6", /* 9 */ "links7", /* 10 */ "links8", /* 11 */ - "extlinks0", /* 12: main files */ - "tmp/extlinks0", /* 13: */ - "extlinks1", /* 14: target files */ - "tmp/extlinks1", /* 15: */ - "extlinks2", /* 16: */ - "tmp/extlinks2", /* 17: */ - "extlinks3", /* 18: */ - "tmp/extlinks3", /* 19: */ - "extlinks4", /* 20: */ - "tmp/extlinks4", /* 21: */ - "extlinks5", /* 22: */ - "tmp/extlinks6", /* 23: */ - "extlinks7", /* 24: */ - "tmp/extlinks7", /* 25: */ - "tmp/extlinks8", /* 26: */ - "extlinks9", /* 27: */ - "tmp/extlinks9", /* 28: */ - "extlinks10", /* 29: */ /* TESTS for windows */ - "tmp/extlinks10", /* 30: */ - "tmp/extlinks11", /* 31: */ - "tmp/extlinks12", /* 32: */ - "extlinks13", /* 33: */ - "tmp/extlinks13", /* 34: */ - "tmp/extlinks14", /* 35: */ - "tmp/extlinks15", /* 36: */ - "extlinks16A", /* 37: */ /* TESTS for H5P_set_elink_fapl */ - "extlinks16B", /* 38: */ - "extlinks17", /* 39: */ - "extlinks18A", /* 40: */ - "extlinks18B", /* 41: */ - "extlinks19A", /* 42: */ - "extlinks19B", /* 43: */ - "extlinks20", /* 44: */ + "extlinks0", /* 12: main files */ + "tmp/extlinks0", /* 13: */ + "extlinks1", /* 14: target files */ + "tmp/extlinks1", /* 15: */ + "extlinks2", /* 16: */ + "tmp/extlinks2", /* 17: */ + "extlinks3", /* 18: */ + "tmp/extlinks3", /* 19: */ + "extlinks4", /* 20: */ + "tmp/extlinks4", /* 21: */ + "extlinks5", /* 22: */ + "tmp/extlinks6", /* 23: */ + "extlinks7", /* 24: */ + "tmp/extlinks7", /* 25: */ + "tmp/extlinks8", /* 26: */ + "extlinks9", /* 27: */ + "tmp/extlinks9", /* 28: */ + "extlinks10", /* 29: */ /* TESTS for windows */ + "tmp/extlinks10", /* 30: */ + "tmp/extlinks11", /* 31: */ + "tmp/extlinks12", /* 32: */ + "extlinks13", /* 33: */ + "tmp/extlinks13", /* 34: */ + "tmp/extlinks14", /* 35: */ + "tmp/extlinks15", /* 36: */ + "extlinks16A", /* 37: */ /* TESTS for H5P_set_elink_fapl */ + "extlinks16B", /* 38: */ + "extlinks17", /* 39: */ + "extlinks18A", /* 40: */ + "extlinks18B", /* 41: */ + "extlinks19A", /* 42: */ + "extlinks19B", /* 43: */ + "extlinks20", /* 44: */ NULL }; @@ -104,12 +104,12 @@ const char *FILENAME[] = { #define TMPDIR "tmp" -#define FAMILY_SIZE 1024 +#define FAMILY_SIZE 1024 #define CORE_INCREMENT 1024 -#define NUM400 400 +#define NUM400 400 /* do not do check_all_closed() for "ext*" files and "tmp/ext*" */ -#define EXTSTOP 12 +#define EXTSTOP 12 #define LINK_BUF_SIZE 1024 #define NAME_BUF_SIZE 1024 @@ -323,16 +323,16 @@ static const char *FILENAME[] = { /*------------------------------------------------------------------------- - * Function: test_basic_links + * Function: test_basic_links * - * Purpose: Test building a file with assorted links. + * Purpose Test building a file with assorted links. * - * Return: Success: 0 + * Return Success: 0 * - * Failure: -1 + * Failure: -1 * - * Programmer: Binh-Minh Ribler - * October 16, 2009 + * Programmer Binh-Minh Ribler + * October 16, 2009 * * Modifications: * @@ -340,114 +340,114 @@ static const char *FILENAME[] = { */ static void test_basic_links(hid_t fapl_id, hbool_t new_format) { - hsize_t size[1] = {1}; - char filename[NAME_BUF_SIZE]; + hsize_t size[1] = {1}; + char filename[NAME_BUF_SIZE]; // Use the file access template id to create a file access prop. list. FileAccPropList fapl(fapl_id); try { - if(new_format) - SUBTEST("Link creation (w/new group format)") - else - SUBTEST("Link creation") + if(new_format) + SUBTEST("Link creation (w/new group format)") + else + SUBTEST("Link creation") - h5_fixname(FILENAME[0], fapl_id, filename, sizeof filename); - H5File file(filename, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); + h5_fixname(FILENAME[0], fapl_id, filename, sizeof filename); + H5File file(filename, H5F_ACC_TRUNC, FileCreatPropList::DEFAULT, fapl); - // Create simple dataspace - DataSpace scalar (1, size, size); + // Create simple dataspace + DataSpace scalar (1, size, size); - // Create a group then close it by letting the object go out of scope - { - Group group(file.createGroup("grp1", 0)); - } + // Create a group then close it by letting the object go out of scope + { + Group group(file.createGroup("grp1", 0)); + } - // Create a dataset then close it by letting the object go out of scope - { - DataSet dset1(file.createDataSet("dset1", PredType::NATIVE_INT, scalar)); - } + // Create a dataset then close it by letting the object go out of scope + { + DataSet dset1(file.createDataSet("dset1", PredType::NATIVE_INT, scalar)); + } - hid_t file_id = file.getId(); + hid_t file_id = file.getId(); - // Because these are not implemented in the C++ API yet, they are - // used so CommonFG::getLinkval can be tested. - // Create a hard link - if(H5Lcreate_hard( - file_id, "dset1", H5L_SAME_LOC, "grp1/hard1", - H5P_DEFAULT, H5P_DEFAULT) < 0) - throw Exception("test_basic_links", "H5Lcreate_hard failed"); + // Because these are not implemented in the C++ API yet, they are + // used so CommonFG::getLinkval can be tested. + // Create a hard link + if(H5Lcreate_hard( + file_id, "dset1", H5L_SAME_LOC, "grp1/hard1", + H5P_DEFAULT, H5P_DEFAULT) < 0) + throw Exception("test_basic_links", "H5Lcreate_hard failed"); - // Create a symbolic link - if(H5Lcreate_soft( - "/dset1", file_id, "grp1/soft", H5P_DEFAULT, H5P_DEFAULT) < 0) - throw Exception("test_basic_links", "H5Lcreate_soft failed"); + // Create a symbolic link + if(H5Lcreate_soft( + "/dset1", file_id, "grp1/soft", H5P_DEFAULT, H5P_DEFAULT) < 0) + throw Exception("test_basic_links", "H5Lcreate_soft failed"); - // Create a symbolic link to something that doesn't exist - if(H5Lcreate_soft( - "foobar", file_id, "grp1/dangle", H5P_DEFAULT, H5P_DEFAULT) < 0) - throw Exception("test_basic_links", "H5Lcreate_soft failed"); + // Create a symbolic link to something that doesn't exist + if(H5Lcreate_soft( + "foobar", file_id, "grp1/dangle", H5P_DEFAULT, H5P_DEFAULT) < 0) + throw Exception("test_basic_links", "H5Lcreate_soft failed"); - // Create a recursive symbolic link - if(H5Lcreate_soft( - "/grp1/recursive", file_id, "/grp1/recursive", - H5P_DEFAULT, H5P_DEFAULT) < 0) - throw Exception("test_basic_links", "H5Lcreate_soft failed"); + // Create a recursive symbolic link + if(H5Lcreate_soft( + "/grp1/recursive", file_id, "/grp1/recursive", + H5P_DEFAULT, H5P_DEFAULT) < 0) + throw Exception("test_basic_links", "H5Lcreate_soft failed"); - // Verify link values before closing the file + // Verify link values before closing the file - H5std_string softlink_val = file.getLinkval("grp1/soft"); - verify_val(softlink_val, "/dset1", "H5File::getLinkval grp1/soft", __LINE__, __FILE__); + H5std_string softlink_val = file.getLinkval("grp1/soft"); + verify_val(softlink_val, "/dset1", "H5File::getLinkval grp1/soft", __LINE__, __FILE__); - H5std_string dngllink_val = file.getLinkval("grp1/dangle"); - verify_val(dngllink_val, "foobar", "H5File::getLinkval grp1/dangle", __LINE__, __FILE__); + H5std_string dngllink_val = file.getLinkval("grp1/dangle"); + verify_val(dngllink_val, "foobar", "H5File::getLinkval grp1/dangle", __LINE__, __FILE__); - H5std_string reclink_val = file.getLinkval("grp1/recursive"); - verify_val(reclink_val, "/grp1/recursive", "H5File::getLinkval grp1/recursive", __LINE__, __FILE__); + H5std_string reclink_val = file.getLinkval("grp1/recursive"); + verify_val(reclink_val, "/grp1/recursive", "H5File::getLinkval grp1/recursive", __LINE__, __FILE__); } // end of try block catch (Exception& E) { - issue_fail_msg("test_basic_links()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_basic_links()", __LINE__, __FILE__, E.getCDetailMsg()); } // Open the file and check on the links in it try { - // Open the file above - H5File file(filename, H5F_ACC_RDWR, FileCreatPropList::DEFAULT, fapl); + // Open the file above + H5File file(filename, H5F_ACC_RDWR, FileCreatPropList::DEFAULT, fapl); - // Verify link existence - if(file.exists("dset1", LinkAccPropList::DEFAULT) != TRUE) - throw InvalidActionException("H5File::exists", "dset1 doesn't exist"); - if(file.exists("grp1/soft", LinkAccPropList::DEFAULT) != TRUE) - throw InvalidActionException("H5File::exists", "grp1/soft doesn't exist"); + // Verify link existence + if(file.exists("dset1", LinkAccPropList::DEFAULT) != TRUE) + throw InvalidActionException("H5File::exists", "dset1 doesn't exist"); + if(file.exists("grp1/soft", LinkAccPropList::DEFAULT) != TRUE) + throw InvalidActionException("H5File::exists", "grp1/soft doesn't exist"); - // Verify link values - H5std_string softlink_val = file.getLinkval("grp1/soft"); - verify_val(softlink_val, "/dset1", "H5File::getLinkval grp1/soft", __LINE__, __FILE__); + // Verify link values + H5std_string softlink_val = file.getLinkval("grp1/soft"); + verify_val(softlink_val, "/dset1", "H5File::getLinkval grp1/soft", __LINE__, __FILE__); - H5std_string reclink_val = file.getLinkval("grp1/recursive"); - verify_val(reclink_val, "/grp1/recursive", "H5File::getLinkval grp1/recursive", __LINE__, __FILE__); + H5std_string reclink_val = file.getLinkval("grp1/recursive"); + verify_val(reclink_val, "/grp1/recursive", "H5File::getLinkval grp1/recursive", __LINE__, __FILE__); - PASSED(); + PASSED(); } // end of try block catch (Exception& E) { - issue_fail_msg("test_basic_links()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_basic_links()", __LINE__, __FILE__, E.getCDetailMsg()); } } /*------------------------------------------------------------------------- - * Function: test_links + * Function: test_links * - * Purpose: Test links + * Purpose Test links * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler + * Programmer Binh-Minh Ribler * October 16, 2009 * *------------------------------------------------------------------------- @@ -455,7 +455,7 @@ static void test_basic_links(hid_t fapl_id, hbool_t new_format) extern "C" void test_links() { - hid_t fapl_id, fapl2_id; /* File access property lists */ + hid_t fapl_id, fapl2_id; /* File access property lists */ unsigned new_format; /* Whether to use the new format or not */ const char *envval; @@ -469,40 +469,40 @@ void test_links() MESSAGE(5, ("Testing Various Links\n")); try { - /* Copy the file access property list */ - if((fapl2_id = H5Pcopy(fapl_id)) < 0) - throw Exception("test_links", "H5Pcopy failed"); - - /* Set the "use the latest version of the format" bounds for creating objects in the file */ - if(H5Pset_libver_bounds(fapl2_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) - throw Exception("test_links", "H5Pset_libver_bounds failed"); - - /* Loop over using new group format */ - for(new_format = FALSE; new_format <= TRUE; new_format++) - { - hid_t my_fapl_id; - - /* Check for FAPL to use */ - if(new_format) - my_fapl_id = fapl2_id; - else - my_fapl_id = fapl_id; - - /* General tests... (on both old & new format groups */ - // FileAccPropList may be passed in instead of fapl id - test_basic_links(my_fapl_id, new_format); + /* Copy the file access property list */ + if((fapl2_id = H5Pcopy(fapl_id)) < 0) + throw Exception("test_links", "H5Pcopy failed"); + + /* Set the "use the latest version of the format" bounds for creating objects in the file */ + if(H5Pset_libver_bounds(fapl2_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) + throw Exception("test_links", "H5Pset_libver_bounds failed"); + + /* Loop over using new group format */ + for(new_format = FALSE; new_format <= TRUE; new_format++) + { + hid_t my_fapl_id; + + /* Check for FAPL to use */ + if(new_format) + my_fapl_id = fapl2_id; + else + my_fapl_id = fapl_id; + + /* General tests... (on both old & new format groups */ + // FileAccPropList may be passed in instead of fapl id + test_basic_links(my_fapl_id, new_format); #if 0 // these tests are from the C test links.c and left here for future // implementation of H5L API - nerrors += test_basic_links(fapl_id, new_format) < 0 ? 1 : 0; - nerrors += cklinks(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += new_links(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += ck_new_links(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += long_links(my_fapl, new_format) < 0 ? 1 : 0; - nerrors += toomany(my_fapl, new_format) < 0 ? 1 : 0; - - /* Test new H5L link creation routine */ - nerrors += test_lcpl(my_fapl, new_format); + nerrors += test_basic_links(fapl_id, new_format) < 0 ? 1 : 0; + nerrors += cklinks(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += new_links(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += ck_new_links(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += long_links(my_fapl, new_format) < 0 ? 1 : 0; + nerrors += toomany(my_fapl, new_format) < 0 ? 1 : 0; + + /* Test new H5L link creation routine */ + nerrors += test_lcpl(my_fapl, new_format); nerrors += test_move(my_fapl, new_format); nerrors += test_copy(my_fapl, new_format); nerrors += test_move_preserves(my_fapl, new_format); @@ -579,7 +579,7 @@ void test_links() /* do not do this for files used by external link tests */ nerrors += check_all_closed(my_fapl, new_format, EXTSTOP) < 0 ? 1 : 0; #endif // 0 - } /* end for */ + } /* end for */ #if 0 /* New group revision feature tests */ @@ -609,33 +609,33 @@ void test_links() nerrors += group_info_old(fapl) < 0 ? 1 : 0; #endif - /* Close 2nd FAPL */ - H5Pclose(fapl2_id); + /* Close 2nd FAPL */ + H5Pclose(fapl2_id); - h5_clean_files(FILENAME, fapl_id); + h5_clean_files(FILENAME, fapl_id); - /* Test that external links can be used after a library reset. MUST be - * called last so the reset doesn't interfere with the property lists. This - * routine will delete its own file. */ - /* nerrors += external_reset_register() < 0 ? 1 : 0; + /* Test that external links can be used after a library reset. MUST be + * called last so the reset doesn't interfere with the property lists. This + * routine will delete its own file. */ + /* nerrors += external_reset_register() < 0 ? 1 : 0; */ } catch (Exception& E) { - issue_fail_msg("test_links()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_links()", __LINE__, __FILE__, E.getCDetailMsg()); } } /*------------------------------------------------------------------------- - * Function: cleanup_links + * Function: cleanup_links * - * Purpose: Cleanup temporary test files + * Purpose Cleanup temporary test files * - * Return: none + * Return none * - * Programmer: Binh-Minh Ribler - * October 16, 2009 + * Programmer Binh-Minh Ribler + * October 16, 2009 * * Modifications: * diff --git a/c++/test/tobject.cpp b/c++/test/tobject.cpp index 325b2b0..6003dd6 100644 --- a/c++/test/tobject.cpp +++ b/c++/test/tobject.cpp @@ -31,41 +31,41 @@ using namespace H5; #include "h5test.h" #include "h5cpputil.h" // C++ utilility header file -const H5std_string FILE_OBJECTS("tobjects.h5"); -const H5std_string GROUP1("Top Group"); -const H5std_string GROUP1_PATH("/Top Group"); -const H5std_string GROUP1_1("Sub-Group 1.1"); -const H5std_string GROUP1_1_PATH("/Top Group/Sub-Group 1.1"); -const H5std_string GROUP1_2("Sub-Group 1.2"); -const H5std_string GROUP1_2_PATH("/Top Group/Sub-Group 1.2"); -const H5std_string DSET_DEFAULT_NAME("default"); -const H5std_string DSET_IN_FILE("Dataset in File"); -const H5std_string DSET_IN_FILE_PATH("/Dataset in File"); -const H5std_string DSET_IN_GRP1("Dataset_in_Group_1"); -const H5std_string DSET_IN_GRP1_PATH("/Top Group/Dataset_in_Group_1"); -const H5std_string DSET_IN_GRP1_2("Dataset_in_Group_1.2"); -const H5std_string DSET_IN_GRP1_2_PATH("/Top Group/Sub-Group 1.2/Dataset_in_Group_1.2"); +const H5std_string FILE_OBJECTS("tobjects.h5"); +const H5std_string GROUP1("Top Group"); +const H5std_string GROUP1_PATH("/Top Group"); +const H5std_string GROUP1_1("Sub-Group 1.1"); +const H5std_string GROUP1_1_PATH("/Top Group/Sub-Group 1.1"); +const H5std_string GROUP1_2("Sub-Group 1.2"); +const H5std_string GROUP1_2_PATH("/Top Group/Sub-Group 1.2"); +const H5std_string DSET_DEFAULT_NAME("default"); +const H5std_string DSET_IN_FILE("Dataset in File"); +const H5std_string DSET_IN_FILE_PATH("/Dataset in File"); +const H5std_string DSET_IN_GRP1("Dataset_in_Group_1"); +const H5std_string DSET_IN_GRP1_PATH("/Top Group/Dataset_in_Group_1"); +const H5std_string DSET_IN_GRP1_2("Dataset_in_Group_1.2"); +const H5std_string DSET_IN_GRP1_2_PATH("/Top Group/Sub-Group 1.2/Dataset_in_Group_1.2"); /*------------------------------------------------------------------------- - * Function: test_get_objname + * Function: test_get_objname * - * Purpose: Tests getting object name of groups and datasets. + * Purpose Tests getting object name of groups and datasets. * * Description: - * File structure: - * GROUP1 - * GROUP1_1 - * GROUP1_2 - * DSET_IN_GRP1_2 - * DSET_IN_GRP1 - * DSET_IN_FILE + * File structure: + * GROUP1 + * GROUP1_1 + * GROUP1_2 + * DSET_IN_GRP1_2 + * DSET_IN_GRP1 + * DSET_IN_FILE * * - * Return: Success: 0 - * Failure: -1 + * Return Success: 0 + * Failure: -1 * - * Programmer: Binh-Minh Ribler - * Friday, March 4, 2014 + * Programmer Binh-Minh Ribler + * Friday, March 4, 2014 * * Modifications: * @@ -76,104 +76,104 @@ static void test_get_objname() SUBTEST("H5Object::getObjName on Groups and Datasets"); try { - // Create file - H5File file(FILE_OBJECTS, H5F_ACC_TRUNC); + // Create file + H5File file(FILE_OBJECTS, H5F_ACC_TRUNC); - // Create a top group and 2 subgroups - Group grp1 = file.createGroup(GROUP1, 0); - Group grp1_1 = grp1.createGroup(GROUP1_1, 0); - Group grp1_2 = grp1.createGroup(GROUP1_2, 0); + // Create a top group and 2 subgroups + Group grp1 = file.createGroup(GROUP1, 0); + Group grp1_1 = grp1.createGroup(GROUP1_1, 0); + Group grp1_2 = grp1.createGroup(GROUP1_2, 0); - // Get part of the group's name, random length using - // ssize_t getObjName(char* comment, size_t buf_size) + // Get part of the group's name, random length using + // ssize_t getObjName(char* comment, size_t buf_size) - // Get the length of the group's name first - ssize_t name_len = grp1.getObjName(NULL); + // Get the length of the group's name first + ssize_t name_len = grp1.getObjName(NULL); - // Random length is 4 - if (name_len > 4) - { - char* grp1_name = new char[5]; - name_len = grp1.getObjName(grp1_name, 5); - verify_val((const char*)grp1_name, "/Top", "Group::getObjName", __LINE__, __FILE__); - delete []grp1_name; - } + // Random length is 4 + if (name_len > 4) + { + char* grp1_name = new char[5]; + name_len = grp1.getObjName(grp1_name, 5); + verify_val((const char*)grp1_name, "/Top", "Group::getObjName", __LINE__, __FILE__); + delete []grp1_name; + } - // Create a data space - hsize_t dims[2]; - dims[0] = 2; - dims[1] = 5; - DataSpace space (2, dims, NULL); + // Create a data space + hsize_t dims[2]; + dims[0] = 2; + dims[1] = 5; + DataSpace space (2, dims, NULL); - // Create a dataset in the file - DataSet dsinfile = file.createDataSet(DSET_IN_FILE, - PredType::NATIVE_DOUBLE, space); + // Create a dataset in the file + DataSet dsinfile = file.createDataSet(DSET_IN_FILE, + PredType::NATIVE_DOUBLE, space); - // Create a dataset in the group - DataSet dsingrp = grp1.createDataSet(DSET_IN_GRP1, - PredType::NATIVE_INT, space); + // Create a dataset in the group + DataSet dsingrp = grp1.createDataSet(DSET_IN_GRP1, + PredType::NATIVE_INT, space); - // Get and verify the name of each dataset, using - // H5std_string getObjName() and - // ssize_t getObjName(H5std_string& obj_name, size_t len = 0) - H5std_string ds_name = dsinfile.getObjName(); - verify_val(ds_name, DSET_IN_FILE_PATH, "DataSet::getObjName", __LINE__, __FILE__); + // Get and verify the name of each dataset, using + // H5std_string getObjName() and + // ssize_t getObjName(H5std_string& obj_name, size_t len = 0) + H5std_string ds_name = dsinfile.getObjName(); + verify_val(ds_name, DSET_IN_FILE_PATH, "DataSet::getObjName", __LINE__, __FILE__); - name_len = dsingrp.getObjName(ds_name); // default len - verify_val(ds_name, DSET_IN_GRP1_PATH, "DataSet::getObjName", __LINE__, __FILE__); + name_len = dsingrp.getObjName(ds_name); // default len + verify_val(ds_name, DSET_IN_GRP1_PATH, "DataSet::getObjName", __LINE__, __FILE__); - // Close dataset - dsingrp.close(); + // Close dataset + dsingrp.close(); - // Create a dataset in sub-group 1.2 - dsingrp = grp1_2.createDataSet(DSET_IN_GRP1_2, PredType::NATIVE_INT, space); + // Create a dataset in sub-group 1.2 + dsingrp = grp1_2.createDataSet(DSET_IN_GRP1_2, PredType::NATIVE_INT, space); - // Get and verify the name of the dataset that belongs to subgroup - // 1.2, using H5std_string getObjName() - ds_name = dsingrp.getObjName(); - verify_val(ds_name, DSET_IN_GRP1_2_PATH, "DataSet::getObjName", __LINE__, __FILE__); + // Get and verify the name of the dataset that belongs to subgroup + // 1.2, using H5std_string getObjName() + ds_name = dsingrp.getObjName(); + verify_val(ds_name, DSET_IN_GRP1_2_PATH, "DataSet::getObjName", __LINE__, __FILE__); - // Close dataset - dsingrp.close(); + // Close dataset + dsingrp.close(); - // Reopen that same dataset then check the name again with another - // overload: ssize_t getObjName(H5std_string& obj_name, size_t len = 0) - dsingrp = grp1_2.openDataSet(DSET_IN_GRP1_2); - name_len = dsingrp.getObjName(ds_name); - verify_val(ds_name, DSET_IN_GRP1_2_PATH, "DataSet::getObjName", __LINE__, __FILE__); + // Reopen that same dataset then check the name again with another + // overload: ssize_t getObjName(H5std_string& obj_name, size_t len = 0) + dsingrp = grp1_2.openDataSet(DSET_IN_GRP1_2); + name_len = dsingrp.getObjName(ds_name); + verify_val(ds_name, DSET_IN_GRP1_2_PATH, "DataSet::getObjName", __LINE__, __FILE__); - // Everything will be closed as they go out of scope + // Everything will be closed as they go out of scope - PASSED(); - } // try block + PASSED(); + } // try block // catch all other exceptions catch (Exception& E) { - issue_fail_msg("test_get_objname", __LINE__, __FILE__); + issue_fail_msg("test_get_objname", __LINE__, __FILE__); } } // test_get_objname /*------------------------------------------------------------------------- - * Function: test_existance + * Function: test_existance * - * Purpose: Tests getting object name of groups and datasets. + * Purpose Tests getting object name of groups and datasets. * * Description: - * File structure: - * GROUP1 - * GROUP1_1 - * GROUP1_2 - * DSET_IN_GRP1_2 - * DSET_IN_GRP1 - * DSET_IN_FILE + * File structure: + * GROUP1 + * GROUP1_1 + * GROUP1_2 + * DSET_IN_GRP1_2 + * DSET_IN_GRP1 + * DSET_IN_FILE * * - * Return: Success: 0 - * Failure: -1 + * Return Success: 0 + * Failure: -1 * - * Programmer: Binh-Minh Ribler - * Friday, March 4, 2014 + * Programmer Binh-Minh Ribler + * Friday, March 4, 2014 * * Modifications: * @@ -184,62 +184,62 @@ static void test_existance() SUBTEST("H5File::exists and Group::exists"); try { - // Open file - H5File file(FILE_OBJECTS, H5F_ACC_RDONLY); + // Open file + H5File file(FILE_OBJECTS, H5F_ACC_RDONLY); - // Check if GROUP1 exists in the file - bool exists = file.exists(GROUP1); + // Check if GROUP1 exists in the file + bool exists = file.exists(GROUP1); - // Open GROUP1 - Group grp1 = file.openGroup(GROUP1); + // Open GROUP1 + Group grp1 = file.openGroup(GROUP1); - // Check if GROUP1_1 and GROUP1_2 exist in GROUP1 - exists = grp1.exists(GROUP1_1); - verify_val(exists, TRUE, "Group::exists GROUP1_1", __LINE__, __FILE__); - exists = grp1.exists(GROUP1_2); - verify_val(exists, TRUE, "Group::exists GROUP1_2", __LINE__, __FILE__); + // Check if GROUP1_1 and GROUP1_2 exist in GROUP1 + exists = grp1.exists(GROUP1_1); + verify_val(exists, TRUE, "Group::exists GROUP1_1", __LINE__, __FILE__); + exists = grp1.exists(GROUP1_2); + verify_val(exists, TRUE, "Group::exists GROUP1_2", __LINE__, __FILE__); - // Check if DSET_IN_GRP1 exists in GROUP1 - exists = grp1.exists(DSET_IN_GRP1); - verify_val(exists, TRUE, "Group::exists DSET_IN_GRP1", __LINE__, __FILE__); + // Check if DSET_IN_GRP1 exists in GROUP1 + exists = grp1.exists(DSET_IN_GRP1); + verify_val(exists, TRUE, "Group::exists DSET_IN_GRP1", __LINE__, __FILE__); - // Open GROUP1_2 - Group grp1_2 = grp1.openGroup(GROUP1_2); + // Open GROUP1_2 + Group grp1_2 = grp1.openGroup(GROUP1_2); - // Check if DSET_IN_GRP1_2 exists in GROUP1_2 - exists = grp1_2.exists(DSET_IN_GRP1_2); - verify_val(exists, TRUE, "Group::exists DSET_IN_GRP1_2", __LINE__, __FILE__); + // Check if DSET_IN_GRP1_2 exists in GROUP1_2 + exists = grp1_2.exists(DSET_IN_GRP1_2); + verify_val(exists, TRUE, "Group::exists DSET_IN_GRP1_2", __LINE__, __FILE__); - // Check if a dataset exists given dataset as location with full path name - DataSet dset1 = file.openDataSet(DSET_IN_FILE); - exists = dset1.exists("/Top Group/Dataset_in_Group_1"); - verify_val(exists, TRUE, "Group::exists given dataset with full path name", __LINE__, __FILE__); + // Check if a dataset exists given dataset as location with full path name + DataSet dset1 = file.openDataSet(DSET_IN_FILE); + exists = dset1.exists("/Top Group/Dataset_in_Group_1"); + verify_val(exists, TRUE, "Group::exists given dataset with full path name", __LINE__, __FILE__); - exists = grp1_2.exists(DSET_IN_GRP1); - verify_val(exists, FALSE, "Group::exists DSET_IN_GRP1", __LINE__, __FILE__); + exists = grp1_2.exists(DSET_IN_GRP1); + verify_val(exists, FALSE, "Group::exists DSET_IN_GRP1", __LINE__, __FILE__); - // Everything will be closed as they go out of scope + // Everything will be closed as they go out of scope - PASSED(); - } // try block + PASSED(); + } // try block // catch all other exceptions catch (Exception& E) { - issue_fail_msg("test_existance", __LINE__, __FILE__); + issue_fail_msg("test_existance", __LINE__, __FILE__); } } // test_existance /*------------------------------------------------------------------------- - * Function: test_get_objname_ontypes + * Function: test_get_objname_ontypes * - * Purpose: Test getting object name from various committed types. + * Purpose Test getting object name from various committed types. * - * Return: Success: 0 - * Failure: -1 + * Return Success: 0 + * Failure: -1 * - * Programmer: Binh-Minh Ribler - * March 4, 2014 + * Programmer Binh-Minh Ribler + * March 4, 2014 * * Modifications: * @@ -250,97 +250,97 @@ static void test_get_objname_ontypes() SUBTEST("H5Object::getObjName on Committed Datatypes"); try { - // Create a file with default prop lists - H5File file(FILE_OBJECTS, H5F_ACC_RDWR); - - // Create a group - Group grp = file.createGroup ("typetests"); - - // Create a datatype and save it - IntType inttype(PredType::STD_B8LE); - inttype.commit(file, "INT type of STD_B8LE"); - - // Close the type then open it again to test getting its name - inttype.close(); - inttype = file.openIntType("INT type of STD_B8LE"); // deprecated - - // Get and verify its name - H5std_string inttype_name = inttype.getObjName(); - verify_val(inttype_name, "/INT type of STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); - - // Close the type then open it again to test getting its name, but - // with the constructor this time - inttype.close(); - IntType std_b8le(file, "INT type of STD_B8LE"); - - // Get and verify its name - H5std_string std_b8le_name = std_b8le.getObjName(); - verify_val(std_b8le_name, "/INT type of STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); - - // Make copy of a predefined type and save it - DataType dtype(PredType::STD_B8LE); - dtype.commit(file, "STD_B8LE"); - - // Close the data type and file - dtype.close(); - file.close(); - - // Re-open the file and the data type to test getting its name - file.openFile(FILE_OBJECTS, H5F_ACC_RDWR); - dtype = file.openDataType("STD_B8LE"); // deprecated - - // Get and verify its name - H5std_string type_name = dtype.getObjName(); - verify_val(type_name, "/STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); - - // Close the type and open it again with the constructor then test - // getting its name - dtype.close(); - DataType dtype2(file, "STD_B8LE"); - type_name = dtype2.getObjName(); - verify_val(type_name, "/STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); - - // Test getting type's name from copied type - DataType copied_type; - copied_type.copy(dtype2); - copied_type.commit(file, "copy of STD_B8LE"); - type_name = copied_type.getObjName(); - verify_val(type_name, "/copy of STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); - - // Test copying an integer predefined type - IntType new_int_type(PredType::NATIVE_INT); - - // Name this datatype - new_int_type.commit(grp, "IntType NATIVE_INT"); - ssize_t name_len = new_int_type.getObjName(type_name); // default len - verify_val(name_len, (ssize_t)HDstrlen("/typetests/IntType NATIVE_INT"), "DataType::getObjName", __LINE__, __FILE__); - verify_val(type_name, "/typetests/IntType NATIVE_INT", "DataType::getObjName", __LINE__, __FILE__); - - // Close everything or they can be closed when objects go out of scope - dtype2.close(); - copied_type.close(); - new_int_type.close(); - grp.close(); - - PASSED(); + // Create a file with default prop lists + H5File file(FILE_OBJECTS, H5F_ACC_RDWR); + + // Create a group + Group grp = file.createGroup ("typetests"); + + // Create a datatype and save it + IntType inttype(PredType::STD_B8LE); + inttype.commit(file, "INT type of STD_B8LE"); + + // Close the type then open it again to test getting its name + inttype.close(); + inttype = file.openIntType("INT type of STD_B8LE"); // deprecated + + // Get and verify its name + H5std_string inttype_name = inttype.getObjName(); + verify_val(inttype_name, "/INT type of STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); + + // Close the type then open it again to test getting its name, but + // with the constructor this time + inttype.close(); + IntType std_b8le(file, "INT type of STD_B8LE"); + + // Get and verify its name + H5std_string std_b8le_name = std_b8le.getObjName(); + verify_val(std_b8le_name, "/INT type of STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); + + // Make copy of a predefined type and save it + DataType dtype(PredType::STD_B8LE); + dtype.commit(file, "STD_B8LE"); + + // Close the data type and file + dtype.close(); + file.close(); + + // Re-open the file and the data type to test getting its name + file.openFile(FILE_OBJECTS, H5F_ACC_RDWR); + dtype = file.openDataType("STD_B8LE"); // deprecated + + // Get and verify its name + H5std_string type_name = dtype.getObjName(); + verify_val(type_name, "/STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); + + // Close the type and open it again with the constructor then test + // getting its name + dtype.close(); + DataType dtype2(file, "STD_B8LE"); + type_name = dtype2.getObjName(); + verify_val(type_name, "/STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); + + // Test getting type's name from copied type + DataType copied_type; + copied_type.copy(dtype2); + copied_type.commit(file, "copy of STD_B8LE"); + type_name = copied_type.getObjName(); + verify_val(type_name, "/copy of STD_B8LE", "DataType::getObjName", __LINE__, __FILE__); + + // Test copying an integer predefined type + IntType new_int_type(PredType::NATIVE_INT); + + // Name this datatype + new_int_type.commit(grp, "IntType NATIVE_INT"); + ssize_t name_len = new_int_type.getObjName(type_name); // default len + verify_val(name_len, (ssize_t)HDstrlen("/typetests/IntType NATIVE_INT"), "DataType::getObjName", __LINE__, __FILE__); + verify_val(type_name, "/typetests/IntType NATIVE_INT", "DataType::getObjName", __LINE__, __FILE__); + + // Close everything or they can be closed when objects go out of scope + dtype2.close(); + copied_type.close(); + new_int_type.close(); + grp.close(); + + PASSED(); } // end top try block catch (Exception& E) { - issue_fail_msg("test_get_objname_ontypes", __LINE__, __FILE__); + issue_fail_msg("test_get_objname_ontypes", __LINE__, __FILE__); } } // test_get_objname_ontypes /*------------------------------------------------------------------------- - * Function: test_get_objtype + * Function: test_get_objtype * - * Purpose: Tests getting object type + * Purpose Tests getting object type * - * Return: Success: 0 - * Failure: -1 + * Return Success: 0 + * Failure: -1 * - * Programmer: Binh-Minh Ribler - * Friday, March 4, 2014 + * Programmer Binh-Minh Ribler + * Friday, March 4, 2014 * * Modifications: * @@ -351,61 +351,61 @@ static void test_get_objtype() SUBTEST("H5File::childObjType and H5Group::childObjType"); try { - // Open file - H5File file(FILE_OBJECTS, H5F_ACC_RDWR); + // Open file + H5File file(FILE_OBJECTS, H5F_ACC_RDWR); - // Open the top group - Group grp1 = file.openGroup(GROUP1); + // Open the top group + Group grp1 = file.openGroup(GROUP1); - // Create a datatype and save it - DataType dtype(PredType::STD_I32LE); - dtype.commit(grp1, "STD_I32LE"); + // Create a datatype and save it + DataType dtype(PredType::STD_I32LE); + dtype.commit(grp1, "STD_I32LE"); - // Get and verify object type with - // H5O_type_t childObjType(const H5std_string& objname) - H5O_type_t objtype = file.childObjType(DSET_IN_FILE); - verify_val(objtype, H5O_TYPE_DATASET, "DataSet::childObjType", __LINE__, __FILE__); + // Get and verify object type with + // H5O_type_t childObjType(const H5std_string& objname) + H5O_type_t objtype = file.childObjType(DSET_IN_FILE); + verify_val(objtype, H5O_TYPE_DATASET, "DataSet::childObjType", __LINE__, __FILE__); - // Get and verify object type with - // H5O_type_t childObjType(const char* objname) - objtype = grp1.childObjType(GROUP1_1.c_str()); - verify_val(objtype, H5O_TYPE_GROUP, "DataSet::childObjType", __LINE__, __FILE__); + // Get and verify object type with + // H5O_type_t childObjType(const char* objname) + objtype = grp1.childObjType(GROUP1_1.c_str()); + verify_val(objtype, H5O_TYPE_GROUP, "DataSet::childObjType", __LINE__, __FILE__); - // Get and verify object type with - // H5O_type_t childObjType(hsize_t index, H5_index_t index_type, - // H5_iter_order_t order, const char* objname=".") - objtype = grp1.childObjType((hsize_t)1, H5_INDEX_NAME, H5_ITER_INC); - verify_val(objtype, H5O_TYPE_NAMED_DATATYPE, "DataSet::childObjType", __LINE__, __FILE__); + // Get and verify object type with + // H5O_type_t childObjType(hsize_t index, H5_index_t index_type, + // H5_iter_order_t order, const char* objname=".") + objtype = grp1.childObjType((hsize_t)1, H5_INDEX_NAME, H5_ITER_INC); + verify_val(objtype, H5O_TYPE_NAMED_DATATYPE, "DataSet::childObjType", __LINE__, __FILE__); - // Get and verify object type with - // H5O_type_t childObjType(hsize_t index, - // H5_index_t index_type=H5_INDEX_NAME, - // H5_iter_order_t order=H5_ITER_INC, const char* objname=".") - objtype = grp1.childObjType((hsize_t)2); - verify_val(objtype, H5O_TYPE_GROUP, "DataSet::childObjType", __LINE__, __FILE__); + // Get and verify object type with + // H5O_type_t childObjType(hsize_t index, + // H5_index_t index_type=H5_INDEX_NAME, + // H5_iter_order_t order=H5_ITER_INC, const char* objname=".") + objtype = grp1.childObjType((hsize_t)2); + verify_val(objtype, H5O_TYPE_GROUP, "DataSet::childObjType", __LINE__, __FILE__); - // Everything will be closed as they go out of scope + // Everything will be closed as they go out of scope - PASSED(); - } // try block + PASSED(); + } // try block // catch all other exceptions catch (Exception& E) { - issue_fail_msg("test_get_objtype", __LINE__, __FILE__); + issue_fail_msg("test_get_objtype", __LINE__, __FILE__); } } // test_get_objtype /*------------------------------------------------------------------------- - * Function: test_objects + * Function: test_objects * - * Purpose: Tests HDF5 object related functionality + * Purpose Tests HDF5 object related functionality * - * Return: Success: 0 - * Failure: -1 + * Return Success: 0 + * Failure: -1 * - * Programmer: Binh-Minh Ribler - * Friday, Mar 4, 2014 + * Programmer Binh-Minh Ribler + * Friday, Mar 4, 2014 * * Modifications: * @@ -419,7 +419,7 @@ void test_object() test_get_objname(); // Test get object name from groups/datasets test_existance(); // Test check for object existance - test_get_objname_ontypes(); // Test get object name from types + test_get_objname_ontypes(); // Test get object name from types test_get_objtype(); // Test get object type } // test_objects @@ -427,11 +427,11 @@ void test_object() /*------------------------------------------------------------------------- * Function: cleanup_objects * - * Purpose: Cleanup temporary test files + * Purpose Cleanup temporary test files * - * Return: none + * Return none * - * Programmer: (use C version) + * Programmer (use C version) * * Modifications: * diff --git a/c++/test/trefer.cpp b/c++/test/trefer.cpp index 9bc2eb0..d8a0d5f 100644 --- a/c++/test/trefer.cpp +++ b/c++/test/trefer.cpp @@ -16,7 +16,7 @@ /***************************************************************************** FILE trefer.cpp - HDF5 C++ testing the functionalities associated with the C - Reference interface (H5R) + Reference interface (H5R) ***************************************************************************/ #ifdef OLD_HEADER_FILENAME @@ -79,100 +79,100 @@ test_reference_params(void) H5File* file1 = NULL; try { - hobj_ref_t *wbuf, // buffer to write to disk - *rbuf, // buffer read from disk - *tbuf; // temp. buffer read from disk + hobj_ref_t *wbuf, // buffer to write to disk + *rbuf, // buffer read from disk + *tbuf; // temp. buffer read from disk - // Allocate write & read buffers - int temp_size = MAX(sizeof(unsigned),sizeof(hobj_ref_t)); - 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); + // Allocate write & read buffers + int temp_size = MAX(sizeof(unsigned),sizeof(hobj_ref_t)); + 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); - // Create dataspace for datasets - hsize_t dims1[] = {SPACE1_DIM1}; - DataSpace sid1(SPACE1_RANK, dims1); - - // Create a group - Group group = file1->createGroup("Group1"); - - // Set group's comment - group.setComment(".", write_comment); - - // Create a dataset (inside /Group1) - DataSet dataset = group.createDataSet(DSET1_NAME, PredType::NATIVE_UINT, sid1); - - unsigned *tu32; // Temporary pointer to uint32 data - int i; - for (tu32=(unsigned *)wbuf, i=0; i<SPACE1_DIM1; i++) - *tu32++=i*3; // from C test - - // Write selection to disk - dataset.write(wbuf, PredType::NATIVE_UINT); - - // Close Dataset - dataset.close(); - - // Create another dataset (inside /Group1) - dataset = group.createDataSet("Dataset2", PredType::NATIVE_UCHAR, sid1); - - // Close Dataset - dataset.close(); - - // Create a datatype to refer to - CompType dtype1(sizeof(s1_t)); - - // Insert fields - dtype1.insertMember(MEMBER1, HOFFSET(s1_t, a), PredType::NATIVE_INT); - dtype1.insertMember(MEMBER2, HOFFSET(s1_t, b), PredType::NATIVE_INT); - dtype1.insertMember(MEMBER3, HOFFSET(s1_t, c), PredType::NATIVE_FLOAT); - - // Save datatype for later - dtype1.commit(group, "Datatype1"); - - // Close datatype and group - dtype1.close(); - group.close(); - - // Create a dataset - dataset = file1->createDataSet("Dataset3", PredType::STD_REF_OBJ, sid1); - - /* Test parameters to H5Location::reference */ - try { - file1->reference(NULL, "/Group1/Dataset1"); - } catch (ReferenceException& E) {} // We expect this to fail - try { - file1->reference(&wbuf[0], NULL); - } catch (ReferenceException& E) {} // We expect this to fail - try { - file1->reference(&wbuf[0], ""); - } catch (ReferenceException& E) {} // We expect this to fail - try { - file1->reference(&wbuf[0], "/Group1/Dataset1", H5R_MAXTYPE); - } catch (ReferenceException& E) {} // We expect this to fail - try { - file1->reference(&wbuf[0], "/Group1/Dataset1", H5R_DATASET_REGION); - } catch (ReferenceException& E) {} // We expect this to fail - - // Close resources - dataset.close(); - file1->close(); - // Let sid1 go out of scope - - // Free memory buffers - HDfree(wbuf); - HDfree(rbuf); - HDfree(tbuf); - - PASSED(); + // Create dataspace for datasets + hsize_t dims1[] = {SPACE1_DIM1}; + DataSpace sid1(SPACE1_RANK, dims1); + + // Create a group + Group group = file1->createGroup("Group1"); + + // Set group's comment + group.setComment(".", write_comment); + + // Create a dataset (inside /Group1) + DataSet dataset = group.createDataSet(DSET1_NAME, PredType::NATIVE_UINT, sid1); + + unsigned *tu32; // Temporary pointer to uint32 data + int i; + for (tu32=(unsigned *)wbuf, i=0; i<SPACE1_DIM1; i++) + *tu32++=i*3; // from C test + + // Write selection to disk + dataset.write(wbuf, PredType::NATIVE_UINT); + + // Close Dataset + dataset.close(); + + // Create another dataset (inside /Group1) + dataset = group.createDataSet("Dataset2", PredType::NATIVE_UCHAR, sid1); + + // Close Dataset + dataset.close(); + + // Create a datatype to refer to + CompType dtype1(sizeof(s1_t)); + + // Insert fields + dtype1.insertMember(MEMBER1, HOFFSET(s1_t, a), PredType::NATIVE_INT); + dtype1.insertMember(MEMBER2, HOFFSET(s1_t, b), PredType::NATIVE_INT); + dtype1.insertMember(MEMBER3, HOFFSET(s1_t, c), PredType::NATIVE_FLOAT); + + // Save datatype for later + dtype1.commit(group, "Datatype1"); + + // Close datatype and group + dtype1.close(); + group.close(); + + // Create a dataset + dataset = file1->createDataSet("Dataset3", PredType::STD_REF_OBJ, sid1); + + /* Test parameters to H5Location::reference */ + try { + file1->reference(NULL, "/Group1/Dataset1"); + } catch (ReferenceException& E) {} // We expect this to fail + try { + file1->reference(&wbuf[0], NULL); + } catch (ReferenceException& E) {} // We expect this to fail + try { + file1->reference(&wbuf[0], ""); + } catch (ReferenceException& E) {} // We expect this to fail + try { + file1->reference(&wbuf[0], "/Group1/Dataset1", H5R_MAXTYPE); + } catch (ReferenceException& E) {} // We expect this to fail + try { + file1->reference(&wbuf[0], "/Group1/Dataset1", H5R_DATASET_REGION); + } catch (ReferenceException& E) {} // We expect this to fail + + // Close resources + dataset.close(); + file1->close(); + // Let sid1 go out of scope + + // Free memory buffers + HDfree(wbuf); + HDfree(rbuf); + HDfree(tbuf); + + PASSED(); } // end try catch (Exception& E) { - issue_fail_msg("test_reference_param()",__LINE__,__FILE__, - E.getCFuncName(), E.getCDetailMsg()); + issue_fail_msg("test_reference_param()",__LINE__,__FILE__, + E.getCFuncName(), E.getCDetailMsg()); } if(file1) @@ -182,7 +182,7 @@ test_reference_params(void) /**************************************************************** ** ** test_reference_obj(): Test basic object reference functions -** to various kinds of objects +** to various kinds of objects ** ****************************************************************/ static void test_reference_obj(void) @@ -195,176 +195,176 @@ static void test_reference_obj(void) H5File* file1 = NULL; try { - hobj_ref_t *wbuf, // buffer to write to disk - *rbuf, // buffer read from disk - *tbuf; // temp. buffer read from disk + hobj_ref_t *wbuf, // buffer to write to disk + *rbuf, // buffer read from disk + *tbuf; // temp. buffer read from disk - // Allocate write & read buffers - int temp_size = MAX(sizeof(unsigned),sizeof(hobj_ref_t)); - 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); + // Allocate write & read buffers + int temp_size = MAX(sizeof(unsigned),sizeof(hobj_ref_t)); + 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); - // Create dataspace for datasets - hsize_t dims1[] = {SPACE1_DIM1}; - DataSpace sid1(SPACE1_RANK, dims1); + // Create dataspace for datasets + hsize_t dims1[] = {SPACE1_DIM1}; + DataSpace sid1(SPACE1_RANK, dims1); - // Create dataset access property list - PropList dapl(H5P_DATASET_ACCESS); + // Create dataset access property list + PropList dapl(H5P_DATASET_ACCESS); - // Create a group - Group group = file1->createGroup("Group1"); + // Create a group + Group group = file1->createGroup("Group1"); - // Set group's comment - group.setComment(".", write_comment); + // Set group's comment + group.setComment(".", write_comment); - // Create a dataset (inside /Group1) - DataSet dataset = group.createDataSet(DSET1_NAME, PredType::NATIVE_UINT, sid1); + // Create a dataset (inside /Group1) + DataSet dataset = group.createDataSet(DSET1_NAME, PredType::NATIVE_UINT, sid1); - unsigned *tu32; // Temporary pointer to uint32 data - for (tu32 = (unsigned *)wbuf, i = 0; i < SPACE1_DIM1; i++) - *tu32++=i*3; // from C test + unsigned *tu32; // Temporary pointer to uint32 data + for (tu32 = (unsigned *)wbuf, i = 0; i < SPACE1_DIM1; i++) + *tu32++=i*3; // from C test - // Write selection to disk - dataset.write(wbuf, PredType::NATIVE_UINT); + // Write selection to disk + dataset.write(wbuf, PredType::NATIVE_UINT); - // Close Dataset - dataset.close(); + // Close Dataset + dataset.close(); - // Create another dataset (inside /Group1) - dataset = group.createDataSet("Dataset2", PredType::NATIVE_UCHAR, sid1); + // Create another dataset (inside /Group1) + dataset = group.createDataSet("Dataset2", PredType::NATIVE_UCHAR, sid1); - // Close Dataset - dataset.close(); + // Close Dataset + dataset.close(); - // Create a datatype to refer to - CompType dtype1(sizeof(s1_t)); + // Create a datatype to refer to + CompType dtype1(sizeof(s1_t)); - // Insert fields - dtype1.insertMember(MEMBER1, HOFFSET(s1_t, a), PredType::NATIVE_INT); - dtype1.insertMember(MEMBER2, HOFFSET(s1_t, b), PredType::NATIVE_INT); - dtype1.insertMember(MEMBER3, HOFFSET(s1_t, c), PredType::NATIVE_FLOAT); + // Insert fields + dtype1.insertMember(MEMBER1, HOFFSET(s1_t, a), PredType::NATIVE_INT); + dtype1.insertMember(MEMBER2, HOFFSET(s1_t, b), PredType::NATIVE_INT); + dtype1.insertMember(MEMBER3, HOFFSET(s1_t, c), PredType::NATIVE_FLOAT); - // Save datatype for later - dtype1.commit(group, "Datatype1"); + // Save datatype for later + dtype1.commit(group, "Datatype1"); - // Close datatype and group - dtype1.close(); - group.close(); + // Close datatype and group + dtype1.close(); + group.close(); - // Create a dataset - dataset = file1->createDataSet("Dataset3", PredType::STD_REF_OBJ, sid1); + // Create a dataset + dataset = file1->createDataSet("Dataset3", PredType::STD_REF_OBJ, sid1); - // Create reference to dataset and test getRefObjType - file1->reference(&wbuf[0], "/Group1/Dataset1"); - H5O_type_t refobj_type = dataset.getRefObjType(&wbuf[0], H5R_OBJECT); - verify_val(refobj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__); + // Create reference to dataset and test getRefObjType + file1->reference(&wbuf[0], "/Group1/Dataset1"); + H5O_type_t refobj_type = dataset.getRefObjType(&wbuf[0], H5R_OBJECT); + verify_val(refobj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__); - // Create reference to dataset and test getRefObjType - file1->reference(&wbuf[1], "/Group1/Dataset2"); - refobj_type = dataset.getRefObjType(&wbuf[1], H5R_OBJECT); - verify_val(refobj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__); + // Create reference to dataset and test getRefObjType + file1->reference(&wbuf[1], "/Group1/Dataset2"); + refobj_type = dataset.getRefObjType(&wbuf[1], H5R_OBJECT); + verify_val(refobj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__); - // Create reference to group - file1->reference(&wbuf[2], "/Group1"); - refobj_type = dataset.getRefObjType(&wbuf[2], H5R_OBJECT); - verify_val(refobj_type, H5O_TYPE_GROUP, "DataSet::getRefObjType",__LINE__,__FILE__); + // Create reference to group + file1->reference(&wbuf[2], "/Group1"); + refobj_type = dataset.getRefObjType(&wbuf[2], H5R_OBJECT); + verify_val(refobj_type, H5O_TYPE_GROUP, "DataSet::getRefObjType",__LINE__,__FILE__); - // Create reference to named datatype - file1->reference(&wbuf[3], "/Group1/Datatype1"); - refobj_type = dataset.getRefObjType(&wbuf[3], H5R_OBJECT); - verify_val(refobj_type, H5O_TYPE_NAMED_DATATYPE, "DataSet::getRefObjType",__LINE__,__FILE__); + // Create reference to named datatype + file1->reference(&wbuf[3], "/Group1/Datatype1"); + refobj_type = dataset.getRefObjType(&wbuf[3], H5R_OBJECT); + verify_val(refobj_type, H5O_TYPE_NAMED_DATATYPE, "DataSet::getRefObjType",__LINE__,__FILE__); - // Write selection to disk - dataset.write(wbuf, PredType::STD_REF_OBJ); + // Write selection to disk + dataset.write(wbuf, PredType::STD_REF_OBJ); - // Close disk dataspace, dataset, and file - sid1.close(); - dataset.close(); - delete file1; + // Close disk dataspace, dataset, and file + sid1.close(); + dataset.close(); + delete file1; - // Re-open the file - file1 = new H5File(FILE1, H5F_ACC_RDWR); + // Re-open the file + file1 = new H5File(FILE1, H5F_ACC_RDWR); - // Open the dataset - dataset = file1->openDataSet("/Dataset3"); + // Open the dataset + dataset = file1->openDataSet("/Dataset3"); - // Read selection from disk - dataset.read(rbuf, PredType::STD_REF_OBJ); + // Read selection from disk + dataset.read(rbuf, PredType::STD_REF_OBJ); - // Dereference dataset object by ctor, from the location where - // 'dataset' is located - DataSet dset2(dataset, &rbuf[0], H5R_OBJECT, dapl); + // Dereference dataset object by ctor, from the location where + // 'dataset' is located + DataSet dset2(dataset, &rbuf[0], H5R_OBJECT, dapl); - // Check information in the referenced dataset - sid1 = dset2.getSpace(); - hssize_t n_elements = sid1.getSimpleExtentNpoints(); - verify_val((long)n_elements, 4, "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); + // Check information in the referenced dataset + sid1 = dset2.getSpace(); + hssize_t n_elements = sid1.getSimpleExtentNpoints(); + verify_val((long)n_elements, 4, "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); - // Read from disk - dset2.read(tbuf, PredType::NATIVE_UINT); + // Read from disk + dset2.read(tbuf, PredType::NATIVE_UINT); - for(tu32 = (unsigned *)tbuf, i = 0; i < SPACE1_DIM1; i++, tu32++) - verify_val(*tu32, (uint32_t)(i*3), "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); + for(tu32 = (unsigned *)tbuf, i = 0; i < SPACE1_DIM1; i++, tu32++) + verify_val(*tu32, (uint32_t)(i*3), "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); - // Close dereferenced dataset - dset2.close(); + // Close dereferenced dataset + dset2.close(); - // Dereference group object from the location where 'dataset' is located - group.dereference(dataset, &rbuf[2]); + // Dereference group object from the location where 'dataset' is located + group.dereference(dataset, &rbuf[2]); - // Get group's comment using - // H5std_string getComment(const char* name, <buf_size=0 by default>) - H5std_string read_comment1 = group.getComment(".", 10); - verify_val(read_comment1.c_str(), write_comment, "Group::getComment",__LINE__,__FILE__); + // Get group's comment using + // H5std_string getComment(const char* name, <buf_size=0 by default>) + H5std_string read_comment1 = group.getComment(".", 10); + verify_val(read_comment1.c_str(), write_comment, "Group::getComment",__LINE__,__FILE__); - // Test with the old default value - read_comment1 = group.getComment(".", 256); - verify_val(read_comment1.c_str(), write_comment, "Group::getComment",__LINE__,__FILE__); + // Test with the old default value + read_comment1 = group.getComment(".", 256); + verify_val(read_comment1.c_str(), write_comment, "Group::getComment",__LINE__,__FILE__); - // Test that getComment handles failures gracefully, using - // H5std_string getComment(const char* name, <buf_size=0 by default>) - try { - H5std_string read_comment_tmp = group.getComment(NULL); - } - catch (Exception& E) {} // We expect this to fail + // Test that getComment handles failures gracefully, using + // H5std_string getComment(const char* name, <buf_size=0 by default>) + try { + H5std_string read_comment_tmp = group.getComment(NULL); + } + catch (Exception& E) {} // We expect this to fail - // Close group - group.close(); + // Close group + group.close(); - /* - * Verify correct referenced datatype - */ - // Open datatype object - dtype1.dereference(dataset, &rbuf[3]); + /* + * Verify correct referenced datatype + */ + // Open datatype object + dtype1.dereference(dataset, &rbuf[3]); - // Verify correct datatype + // Verify correct datatype H5T_class_t tclass; tclass = dtype1.getClass(); - verify_val(tclass, H5T_COMPOUND, "DataType::getClass",__LINE__,__FILE__); - int n_members = dtype1.getNmembers(); + verify_val(tclass, H5T_COMPOUND, "DataType::getClass",__LINE__,__FILE__); + int n_members = dtype1.getNmembers(); verify_val(n_members, 3, "CompType::getNmembers",__LINE__,__FILE__); - // Close all objects and file - dtype1.close(); - dataset.close(); - file1->close(); + // Close all objects and file + dtype1.close(); + dataset.close(); + file1->close(); - // Free allocated buffers - HDfree(wbuf); - HDfree(rbuf); - HDfree(tbuf); + // Free allocated buffers + HDfree(wbuf); + HDfree(rbuf); + HDfree(tbuf); - PASSED(); + PASSED(); } // end try catch (Exception& E) { - issue_fail_msg("test_reference_obj()",__LINE__,__FILE__, - E.getCFuncName(), E.getCDetailMsg()); + issue_fail_msg("test_reference_obj()",__LINE__,__FILE__, + E.getCFuncName(), E.getCDetailMsg()); } if(file1) @@ -376,7 +376,7 @@ static void test_reference_obj(void) ** ** test_reference_group(): Test object reference functionality ** Tests for correct behavior of various routines on -** dereferenced group +** dereferenced group ** ****************************************************************/ #define GROUPNAME "/group" @@ -389,8 +389,8 @@ static void test_reference_obj(void) static void test_reference_group(void) { - hobj_ref_t wref; /* Reference to write */ - hobj_ref_t rref; /* Reference to read */ + hobj_ref_t wref; /* Reference to write */ + hobj_ref_t rref; /* Reference to read */ const H5std_string write_comment="Foo!"; // Comments for group // Output message about test being performed @@ -398,102 +398,102 @@ test_reference_group(void) H5File* file1 = NULL; try { - /* - * Create file with a group and a dataset containing an object - * reference to the group - */ + /* + * Create file with a group and a dataset containing an object + * reference to the group + */ // Create file FILE1 file1 = new H5File (FILE1, H5F_ACC_TRUNC); - // Create scalar dataspace - DataSpace sid1; + // Create scalar dataspace + DataSpace sid1; - // Create a group - Group group = file1->createGroup(GROUPNAME); + // Create a group + Group group = file1->createGroup(GROUPNAME); - /* Create nested groups */ - Group group2 = group.createGroup(GROUPNAME2); - group2.close(); - group2 = group.createGroup(GROUPNAME3); - group2.close(); + /* Create nested groups */ + Group group2 = group.createGroup(GROUPNAME2); + group2.close(); + group2 = group.createGroup(GROUPNAME3); + group2.close(); - // Create bottom dataset - DataSet dset1 = group.createDataSet(DSETNAME2, PredType::NATIVE_INT, sid1); - dset1.close(); + // Create bottom dataset + DataSet dset1 = group.createDataSet(DSETNAME2, PredType::NATIVE_INT, sid1); + dset1.close(); - // Close group 1 - group.close(); + // Close group 1 + group.close(); - // Create dataset - DataSet dset2 = file1->createDataSet(DSETNAME, PredType::STD_REF_OBJ, sid1); + // Create dataset + DataSet dset2 = file1->createDataSet(DSETNAME, PredType::STD_REF_OBJ, sid1); - file1->reference(&wref, GROUPNAME); + file1->reference(&wref, GROUPNAME); - // Write selection to disk - dset2.write(&wref, PredType::STD_REF_OBJ); + // Write selection to disk + dset2.write(&wref, PredType::STD_REF_OBJ); - // Close resources - dset2.close(); - sid1.close(); - file1->close(); + // Close resources + dset2.close(); + sid1.close(); + file1->close(); - /* - * Re-open the file and test deferencing group - */ + /* + * Re-open the file and test deferencing group + */ - // Re-open file + // Re-open file file1->openFile(FILE1, H5F_ACC_RDWR); - // Re-open dataset - dset1 = file1->openDataSet(DSETNAME); + // Re-open dataset + dset1 = file1->openDataSet(DSETNAME); - // Read in the reference - dset1.read(&rref, PredType::STD_REF_OBJ); + // Read in the reference + dset1.read(&rref, PredType::STD_REF_OBJ); - // Dereference to get the group - Group refgroup(dset1, &rref); + // Dereference to get the group + Group refgroup(dset1, &rref); - // Dereference group object the other way - group.dereference(dset1, &rref); + // Dereference group object the other way + group.dereference(dset1, &rref); - /* - * Various queries on the group opened - */ + /* + * Various queries on the group opened + */ - // Check number of objects in the group dereferenced by constructor - hsize_t nobjs = refgroup.getNumObjs(); - verify_val(nobjs, (hsize_t)3, "H5Group::getNumObjs",__LINE__,__FILE__); + // Check number of objects in the group dereferenced by constructor + hsize_t nobjs = refgroup.getNumObjs(); + verify_val(nobjs, (hsize_t)3, "H5Group::getNumObjs",__LINE__,__FILE__); - // Check number of objects in the group dereferenced by ::reference - nobjs = group.getNumObjs(); - verify_val(nobjs, (hsize_t)3, "H5Group::getNumObjs",__LINE__,__FILE__); + // Check number of objects in the group dereferenced by ::reference + nobjs = group.getNumObjs(); + verify_val(nobjs, (hsize_t)3, "H5Group::getNumObjs",__LINE__,__FILE__); - // Check getting file name given the group dereferenced via constructor - H5std_string fname = refgroup.getFileName(); - verify_val(fname, FILE1, "H5Group::getFileName",__LINE__,__FILE__); + // Check getting file name given the group dereferenced via constructor + H5std_string fname = refgroup.getFileName(); + verify_val(fname, FILE1, "H5Group::getFileName",__LINE__,__FILE__); - // Check getting file name given the group dereferenced by ::reference - fname = group.getFileName(); - verify_val(fname, FILE1, "H5Group::getFileName",__LINE__,__FILE__); - - // Unlink one of the objects in the dereferenced group, and re-check - refgroup.unlink(GROUPNAME2); - nobjs = refgroup.getNumObjs(); - verify_val(nobjs, (hsize_t)2, "H5Group::getNumObjs",__LINE__,__FILE__); - - // Close resources - group.close(); - refgroup.close(); - dset1.close(); - file1->close(); - - PASSED(); + // Check getting file name given the group dereferenced by ::reference + fname = group.getFileName(); + verify_val(fname, FILE1, "H5Group::getFileName",__LINE__,__FILE__); + + // Unlink one of the objects in the dereferenced group, and re-check + refgroup.unlink(GROUPNAME2); + nobjs = refgroup.getNumObjs(); + verify_val(nobjs, (hsize_t)2, "H5Group::getNumObjs",__LINE__,__FILE__); + + // Close resources + group.close(); + refgroup.close(); + dset1.close(); + file1->close(); + + PASSED(); } // end try catch (Exception& E) { - issue_fail_msg("test_reference_group()",__LINE__,__FILE__, - E.getCFuncName(), E.getCDetailMsg()); + issue_fail_msg("test_reference_group()",__LINE__,__FILE__, + E.getCFuncName(), E.getCDetailMsg()); } if(file1) @@ -509,283 +509,283 @@ test_reference_group(void) static void test_reference_region_1D(void) { - hsize_t start[SPACE3_RANK]; /* Starting location of hyperslab */ - hsize_t stride[SPACE3_RANK]; /* Stride of hyperslab */ - hsize_t count[SPACE3_RANK]; /* Element count of hyperslab */ - hsize_t block[SPACE3_RANK]; /* Block size of hyperslab */ - hsize_t coord1[POINT1_NPOINTS][SPACE3_RANK]; /* Coordinates for point selection */ + hsize_t start[SPACE3_RANK]; /* Starting location of hyperslab */ + hsize_t stride[SPACE3_RANK]; /* Stride of hyperslab */ + hsize_t count[SPACE3_RANK]; /* Element count of hyperslab */ + hsize_t block[SPACE3_RANK]; /* Block size of hyperslab */ + hsize_t coord1[POINT1_NPOINTS][SPACE3_RANK]; /* Coordinates for point selection */ hsize_t * coords; /* Coordinate buffer */ - hsize_t low[SPACE3_RANK]; /* Selection bounds */ - hsize_t high[SPACE3_RANK]; /* Selection bounds */ + hsize_t low[SPACE3_RANK]; /* Selection bounds */ + hsize_t high[SPACE3_RANK]; /* Selection bounds */ int i; /* counting variables */ // Output message about test being performed SUBTEST("1-D Dataset Region Reference Functions"); try { - hdset_reg_ref_t *wbuf, // buffer to write to disk - *rbuf; // buffer read from disk - uint8_t *dwbuf, // Buffer for writing numeric data to disk - *drbuf; // Buffer for reading numeric data from disk + hdset_reg_ref_t *wbuf, // buffer to write to disk + *rbuf; // buffer read from disk + uint8_t *dwbuf, // Buffer for writing numeric data to disk + *drbuf; // Buffer for reading numeric data from disk - // Allocate write & read buffers - wbuf = (hdset_reg_ref_t *)HDcalloc(sizeof(hdset_reg_ref_t), (size_t)SPACE1_DIM1); - rbuf = (hdset_reg_ref_t *)HDmalloc(sizeof(hdset_reg_ref_t) * SPACE1_DIM1); - dwbuf = (uint8_t *)HDmalloc(sizeof(uint8_t) * SPACE3_DIM1); - drbuf = (uint8_t *)HDcalloc(sizeof(uint8_t), (size_t)SPACE3_DIM1); + // Allocate write & read buffers + wbuf = (hdset_reg_ref_t *)HDcalloc(sizeof(hdset_reg_ref_t), (size_t)SPACE1_DIM1); + rbuf = (hdset_reg_ref_t *)HDmalloc(sizeof(hdset_reg_ref_t) * SPACE1_DIM1); + dwbuf = (uint8_t *)HDmalloc(sizeof(uint8_t) * SPACE3_DIM1); + drbuf = (uint8_t *)HDcalloc(sizeof(uint8_t), (size_t)SPACE3_DIM1); // Create file FILE1 H5File file1(FILE2, H5F_ACC_TRUNC); - // Create dataspace for datasets - hsize_t dims3[] = {SPACE3_DIM1}; - DataSpace sid3(SPACE3_RANK, dims3); + // Create dataspace for datasets + hsize_t dims3[] = {SPACE3_DIM1}; + DataSpace sid3(SPACE3_RANK, dims3); - // Create dataset access property list - PropList dapl(H5P_DATASET_ACCESS); + // Create dataset access property list + PropList dapl(H5P_DATASET_ACCESS); - // Create a dataset - DataSet dset3 = file1.createDataSet(DSET2_NAME, PredType::STD_U8LE, sid3); + // Create a dataset + DataSet dset3 = file1.createDataSet(DSET2_NAME, PredType::STD_U8LE, sid3); - uint8_t *tu8; // Temporary pointer to uint8 data - for (tu8 = dwbuf, i = 0; i < SPACE3_DIM1; i++) - *tu8++ = i * 3; // from C test + uint8_t *tu8; // Temporary pointer to uint8 data + for (tu8 = dwbuf, i = 0; i < SPACE3_DIM1; i++) + *tu8++ = i * 3; // from C test - // Write selection to disk - dset3.write(dwbuf, PredType::STD_U8LE); + // Write selection to disk + dset3.write(dwbuf, PredType::STD_U8LE); - // Close Dataset - dset3.close(); + // Close Dataset + dset3.close(); - // Create dataspace for datasets - hsize_t dims1[] = {SPACE1_DIM1}; - DataSpace sid1(SPACE1_RANK, dims1); + // Create dataspace for datasets + hsize_t dims1[] = {SPACE1_DIM1}; + DataSpace sid1(SPACE1_RANK, dims1); - // Create a dataset - DataSet dset1 = file1.createDataSet(DSET1_NAME, PredType::STD_REF_DSETREG, sid1); + // Create a dataset + DataSet dset1 = file1.createDataSet(DSET1_NAME, PredType::STD_REF_DSETREG, sid1); - /* - * Create references and prepare for testing - */ + /* + * Create references and prepare for testing + */ - /* Select 15 2x1 hyperslabs for first reference */ - start[0] = 2; - stride[0] = 5; - count[0] = 15; - block[0] = 2; + /* Select 15 2x1 hyperslabs for first reference */ + start[0] = 2; + stride[0] = 5; + count[0] = 15; + block[0] = 2; - // Select a hyperslab region to add to the current selected region - sid3.selectHyperslab(H5S_SELECT_SET, count, start, stride, block); + // Select a hyperslab region to add to the current selected region + sid3.selectHyperslab(H5S_SELECT_SET, count, start, stride, block); - // Get and verify the number of elements in a dataspace selection - hssize_t nelms = sid3.getSelectNpoints(); - verify_val(nelms, 30, "DataSet::getRefObjType",__LINE__,__FILE__); + // Get and verify the number of elements in a dataspace selection + hssize_t nelms = sid3.getSelectNpoints(); + verify_val(nelms, 30, "DataSet::getRefObjType",__LINE__,__FILE__); - // Store first dataset region - file1.reference(&wbuf[0], "/Dataset2", sid3); + // Store first dataset region + file1.reference(&wbuf[0], "/Dataset2", sid3); - // Get and verify object type - H5O_type_t obj_type = dset1.getRefObjType(&wbuf[0], H5R_DATASET_REGION); - verify_val(obj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__); + // Get and verify object type + H5O_type_t obj_type = dset1.getRefObjType(&wbuf[0], H5R_DATASET_REGION); + verify_val(obj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__); - /* Select sequence of ten points for second reference */ - coord1[0][0] = 16; - coord1[1][0] = 22; - coord1[2][0] = 38; - coord1[3][0] = 41; - coord1[4][0] = 52; - coord1[5][0] = 63; - coord1[6][0] = 70; - coord1[7][0] = 89; - coord1[8][0] = 97; - coord1[9][0] = 3; - - // Selects array elements to be included in the selection for sid3 - sid3.selectElements(H5S_SELECT_SET, (size_t)POINT1_NPOINTS, (const hsize_t *)coord1); - - // Get and verify the number of elements in a dataspace selection - nelms = sid3.getSelectNpoints(); - verify_val(nelms, 10, "DataSet::getRefObjType",__LINE__,__FILE__); - - // Store first dataset region - file1.reference(&wbuf[1], "/Dataset2", sid3); - - // Write selection to disk - dset1.write(wbuf, PredType::STD_REF_DSETREG); - - // Close disk dataspace, dataset, and file - sid1.close(); - dset1.close(); - sid3.close(); - file1.close(); - - /* - * Testing various dereference functions - */ - - // Re-open the file - file1.openFile(FILE2, H5F_ACC_RDWR); - - // Open the dataset - dset1 = file1.openDataSet("/Dataset1"); - - // Read selection from disk - dset1.read(rbuf, PredType::STD_REF_DSETREG); - - { // Test DataSet::dereference - dset3.dereference(dset1, &rbuf[0], H5R_DATASET_REGION, dapl); - - // Get and verify object type - obj_type = dset1.getRefObjType(&rbuf[0], H5R_DATASET_REGION); - verify_val(obj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__); - - // Get dataspace of dset3 the verify number of elements - sid1 = dset3.getSpace(); - nelms = sid1.getSimpleExtentNpoints(); - verify_val((long)nelms, 100, "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); - } // End of test DataSet::dereference - - { // Test DataSet constructor -by dereference - // Dereference dataset object by ctor, from the location where - // 'dset1' is located - DataSet newds(dset1, &rbuf[0], H5R_DATASET_REGION, dapl); - - // Get dataspace of newds then verify number of elements - sid1 = newds.getSpace(); - nelms = sid1.getSimpleExtentNpoints(); - verify_val((long)nelms, 100, "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); - - // Close objects for this mini test - newds.close(); - sid1.close(); - } // End of test DataSet constructor -by dereference - - // Read from disk - dset3.read(drbuf, PredType::STD_U8LE); - - for(tu8 = (uint8_t *)drbuf, i = 0; i < SPACE3_DIM1; i++, tu8++) - verify_val(*tu8, (uint8_t)(i * 3), "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); - - /* - * Test getting the referenced region - */ - - // Get region - DataSpace reg_sp = dset1.getRegion(&rbuf[0]); - - // Get and verify number of elements in a dataspace selection - nelms = reg_sp.getSelectNpoints(); - verify_val((long)nelms, 30, "DataSpace::getSelectNpoints",__LINE__,__FILE__); - - // Get and verify number of hyperslab blocks - nelms = reg_sp.getSelectHyperNblocks(); - verify_val((long)nelms, 15, "DataSpace::getSelectNpoints",__LINE__,__FILE__); - - /* Allocate space for the hyperslab blocks */ - coords = (hsize_t *)HDmalloc(nelms * SPACE3_RANK * sizeof(hsize_t) * 2); - - // Get the list of hyperslab blocks currently selected - reg_sp.getSelectHyperBlocklist((hsize_t)0, (hsize_t)nelms, coords); - - // Verify values in the list - verify_val(coords[0], (hsize_t)2, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[1], (hsize_t)3, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[2], (hsize_t)7, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[3], (hsize_t)8, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[4],(hsize_t)12, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[5],(hsize_t)13, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[6],(hsize_t)17, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[7],(hsize_t)18, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[8],(hsize_t)22, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[9],(hsize_t)23, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[10],(hsize_t)27, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[11],(hsize_t)28, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[12],(hsize_t)32, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[13],(hsize_t)33, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[14],(hsize_t)37, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[15],(hsize_t)38, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[16],(hsize_t)42, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[17],(hsize_t)43, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[18],(hsize_t)47, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[19],(hsize_t)48, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[20],(hsize_t)52, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[21],(hsize_t)53, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[22],(hsize_t)57, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[23],(hsize_t)58, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[24],(hsize_t)62, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[25],(hsize_t)63, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[26],(hsize_t)67, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[27],(hsize_t)68, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[28],(hsize_t)72, "Hyperslab Coordinates",__LINE__,__FILE__); - verify_val(coords[29],(hsize_t)73, "Hyperslab Coordinates",__LINE__,__FILE__); - - HDfree(coords); - - // Check boundaries - reg_sp.getSelectBounds(low, high); - verify_val(low[0],(hsize_t)2, "DataSpace::getSelectBounds",__LINE__,__FILE__); - verify_val(high[0],(hsize_t)73, "DataSpace::getSelectBounds",__LINE__,__FILE__); - - /* Close region space */ - reg_sp.close(); - - /* - * Another test on getting the referenced region - */ - - // Get region - DataSpace elm_sp = dset1.getRegion(&rbuf[1]); - - // Get and verify number of element points in the current selection - hssize_t nelmspts = elm_sp.getSelectElemNpoints(); - verify_val((long)nelmspts, 10, "DataSpace::getSelectNpoints",__LINE__,__FILE__); - - /* Allocate space for the hyperslab blocks */ - coords = (hsize_t *)HDmalloc(nelmspts * SPACE3_RANK * sizeof(hsize_t)); - - // Get the list of element points currently selected - elm_sp.getSelectElemPointlist((hsize_t)0, (hsize_t)nelmspts, coords); - - // Verify points - verify_val(coords[0], coord1[0][0], "Element Coordinates",__LINE__,__FILE__); - verify_val(coords[1], coord1[1][0], "Element Coordinates",__LINE__,__FILE__); - verify_val(coords[2], coord1[2][0], "Element Coordinates",__LINE__,__FILE__); - verify_val(coords[3], coord1[3][0], "Element Coordinates",__LINE__,__FILE__); - verify_val(coords[4], coord1[4][0], "Element Coordinates",__LINE__,__FILE__); - verify_val(coords[5], coord1[5][0], "Element Coordinates",__LINE__,__FILE__); - verify_val(coords[6], coord1[6][0], "Element Coordinates",__LINE__,__FILE__); - verify_val(coords[7], coord1[7][0], "Element Coordinates",__LINE__,__FILE__); - verify_val(coords[8], coord1[8][0], "Element Coordinates",__LINE__,__FILE__); - verify_val(coords[9], coord1[9][0], "Element Coordinates",__LINE__,__FILE__); - - HDfree(coords); - - // Check boundaries - elm_sp.getSelectBounds(low, high); - verify_val(low[0],(hsize_t)3, "DataSpace::getSelectBounds",__LINE__,__FILE__); - verify_val(high[0],(hsize_t)97, "DataSpace::getSelectBounds",__LINE__,__FILE__); - - // Close element space - elm_sp.close(); - - // Close resources - sid1.close(); - dset3.close(); - dset1.close(); - file1.close(); - - // Free memory buffers - HDfree(wbuf); - HDfree(rbuf); - HDfree(dwbuf); - HDfree(drbuf); - - PASSED(); + /* Select sequence of ten points for second reference */ + coord1[0][0] = 16; + coord1[1][0] = 22; + coord1[2][0] = 38; + coord1[3][0] = 41; + coord1[4][0] = 52; + coord1[5][0] = 63; + coord1[6][0] = 70; + coord1[7][0] = 89; + coord1[8][0] = 97; + coord1[9][0] = 3; + + // Selects array elements to be included in the selection for sid3 + sid3.selectElements(H5S_SELECT_SET, (size_t)POINT1_NPOINTS, (const hsize_t *)coord1); + + // Get and verify the number of elements in a dataspace selection + nelms = sid3.getSelectNpoints(); + verify_val(nelms, 10, "DataSet::getRefObjType",__LINE__,__FILE__); + + // Store first dataset region + file1.reference(&wbuf[1], "/Dataset2", sid3); + + // Write selection to disk + dset1.write(wbuf, PredType::STD_REF_DSETREG); + + // Close disk dataspace, dataset, and file + sid1.close(); + dset1.close(); + sid3.close(); + file1.close(); + + /* + * Testing various dereference functions + */ + + // Re-open the file + file1.openFile(FILE2, H5F_ACC_RDWR); + + // Open the dataset + dset1 = file1.openDataSet("/Dataset1"); + + // Read selection from disk + dset1.read(rbuf, PredType::STD_REF_DSETREG); + + { // Test DataSet::dereference + dset3.dereference(dset1, &rbuf[0], H5R_DATASET_REGION, dapl); + + // Get and verify object type + obj_type = dset1.getRefObjType(&rbuf[0], H5R_DATASET_REGION); + verify_val(obj_type, H5O_TYPE_DATASET, "DataSet::getRefObjType",__LINE__,__FILE__); + + // Get dataspace of dset3 the verify number of elements + sid1 = dset3.getSpace(); + nelms = sid1.getSimpleExtentNpoints(); + verify_val((long)nelms, 100, "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); + } // End of test DataSet::dereference + + { // Test DataSet constructor -by dereference + // Dereference dataset object by ctor, from the location where + // 'dset1' is located + DataSet newds(dset1, &rbuf[0], H5R_DATASET_REGION, dapl); + + // Get dataspace of newds then verify number of elements + sid1 = newds.getSpace(); + nelms = sid1.getSimpleExtentNpoints(); + verify_val((long)nelms, 100, "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); + + // Close objects for this mini test + newds.close(); + sid1.close(); + } // End of test DataSet constructor -by dereference + + // Read from disk + dset3.read(drbuf, PredType::STD_U8LE); + + for(tu8 = (uint8_t *)drbuf, i = 0; i < SPACE3_DIM1; i++, tu8++) + verify_val(*tu8, (uint8_t)(i * 3), "DataSpace::getSimpleExtentNpoints",__LINE__,__FILE__); + + /* + * Test getting the referenced region + */ + + // Get region + DataSpace reg_sp = dset1.getRegion(&rbuf[0]); + + // Get and verify number of elements in a dataspace selection + nelms = reg_sp.getSelectNpoints(); + verify_val((long)nelms, 30, "DataSpace::getSelectNpoints",__LINE__,__FILE__); + + // Get and verify number of hyperslab blocks + nelms = reg_sp.getSelectHyperNblocks(); + verify_val((long)nelms, 15, "DataSpace::getSelectNpoints",__LINE__,__FILE__); + + /* Allocate space for the hyperslab blocks */ + coords = (hsize_t *)HDmalloc(nelms * SPACE3_RANK * sizeof(hsize_t) * 2); + + // Get the list of hyperslab blocks currently selected + reg_sp.getSelectHyperBlocklist((hsize_t)0, (hsize_t)nelms, coords); + + // Verify values in the list + verify_val(coords[0], (hsize_t)2, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[1], (hsize_t)3, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[2], (hsize_t)7, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[3], (hsize_t)8, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[4],(hsize_t)12, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[5],(hsize_t)13, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[6],(hsize_t)17, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[7],(hsize_t)18, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[8],(hsize_t)22, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[9],(hsize_t)23, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[10],(hsize_t)27, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[11],(hsize_t)28, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[12],(hsize_t)32, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[13],(hsize_t)33, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[14],(hsize_t)37, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[15],(hsize_t)38, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[16],(hsize_t)42, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[17],(hsize_t)43, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[18],(hsize_t)47, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[19],(hsize_t)48, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[20],(hsize_t)52, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[21],(hsize_t)53, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[22],(hsize_t)57, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[23],(hsize_t)58, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[24],(hsize_t)62, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[25],(hsize_t)63, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[26],(hsize_t)67, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[27],(hsize_t)68, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[28],(hsize_t)72, "Hyperslab Coordinates",__LINE__,__FILE__); + verify_val(coords[29],(hsize_t)73, "Hyperslab Coordinates",__LINE__,__FILE__); + + HDfree(coords); + + // Check boundaries + reg_sp.getSelectBounds(low, high); + verify_val(low[0],(hsize_t)2, "DataSpace::getSelectBounds",__LINE__,__FILE__); + verify_val(high[0],(hsize_t)73, "DataSpace::getSelectBounds",__LINE__,__FILE__); + + /* Close region space */ + reg_sp.close(); + + /* + * Another test on getting the referenced region + */ + + // Get region + DataSpace elm_sp = dset1.getRegion(&rbuf[1]); + + // Get and verify number of element points in the current selection + hssize_t nelmspts = elm_sp.getSelectElemNpoints(); + verify_val((long)nelmspts, 10, "DataSpace::getSelectNpoints",__LINE__,__FILE__); + + /* Allocate space for the hyperslab blocks */ + coords = (hsize_t *)HDmalloc(nelmspts * SPACE3_RANK * sizeof(hsize_t)); + + // Get the list of element points currently selected + elm_sp.getSelectElemPointlist((hsize_t)0, (hsize_t)nelmspts, coords); + + // Verify points + verify_val(coords[0], coord1[0][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[1], coord1[1][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[2], coord1[2][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[3], coord1[3][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[4], coord1[4][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[5], coord1[5][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[6], coord1[6][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[7], coord1[7][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[8], coord1[8][0], "Element Coordinates",__LINE__,__FILE__); + verify_val(coords[9], coord1[9][0], "Element Coordinates",__LINE__,__FILE__); + + HDfree(coords); + + // Check boundaries + elm_sp.getSelectBounds(low, high); + verify_val(low[0],(hsize_t)3, "DataSpace::getSelectBounds",__LINE__,__FILE__); + verify_val(high[0],(hsize_t)97, "DataSpace::getSelectBounds",__LINE__,__FILE__); + + // Close element space + elm_sp.close(); + + // Close resources + sid1.close(); + dset3.close(); + dset1.close(); + file1.close(); + + // Free memory buffers + HDfree(wbuf); + HDfree(rbuf); + HDfree(dwbuf); + HDfree(drbuf); + + PASSED(); } // end try catch (Exception& E) { - issue_fail_msg("test_reference_region_1D()",__LINE__,__FILE__, - E.getCFuncName(), E.getCDetailMsg()); + issue_fail_msg("test_reference_region_1D()",__LINE__,__FILE__, + E.getCFuncName(), E.getCDetailMsg()); } } /* test_reference_region_1D() */ @@ -823,9 +823,9 @@ void test_reference(void) /**************************************************************** -** Function: cleanup_reference -** Purpose: Cleanup temporary test files -** Return: none +** Function: cleanup_reference +** Purpose Cleanup temporary test files +** Return none ****************************************************************/ extern "C" void cleanup_reference(void) diff --git a/c++/test/ttypes.cpp b/c++/test/ttypes.cpp index 6605c03..0cc8918 100644 --- a/c++/test/ttypes.cpp +++ b/c++/test/ttypes.cpp @@ -37,7 +37,7 @@ using namespace H5; * Offset from alinged memory returned by malloc(). This can be used to test * that type conversions handle non-aligned buffers correctly. */ -#define ALIGNMENT 1 +#define ALIGNMENT 1 /* * Define if you want to test alignment code on a machine that doesn't @@ -70,7 +70,7 @@ const char *FILENAME[] = { * endian. If local variable `endian' is H5T_ORDER_BE then the result will * be I, otherwise the result will be Z-(I+1). */ -#define ENDIAN(Z,I) (H5T_ORDER_BE==endian?(I):(Z)-((I)+1)) +#define ENDIAN(Z,I) (H5T_ORDER_BE==endian?(I):(Z)-((I)+1)) typedef enum flt_t { @@ -86,12 +86,12 @@ typedef enum int_t { /*------------------------------------------------------------------------- * Function: test_classes * - * Purpose: Test type classes + * Purpose Test type classes * - * Return: None. + * Return None. * - * Programmer: Binh-Minh Ribler (using C version) - * January, 2007 + * Programmer Binh-Minh Ribler (using C version) + * January, 2007 * * Modifications: * @@ -101,38 +101,38 @@ static void test_classes() { SUBTEST("PredType::getClass()"); try { - // maybe later, 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) { - 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) { - verify_val(tcls, H5T_FLOAT, "test_class: invalid type class for NATIVE_DOUBLE -", __LINE__, __FILE__); - } - PASSED(); + // maybe later, 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) { + 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) { + verify_val(tcls, H5T_FLOAT, "test_class: invalid type class for NATIVE_DOUBLE -", __LINE__, __FILE__); + } + PASSED(); } // end of try block catch (Exception& E) { - issue_fail_msg("test_classes", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_classes", __LINE__, __FILE__, E.getCDetailMsg()); } } /*------------------------------------------------------------------------- * Function: test_copy * - * Purpose: Test datatype copy functionality + * Purpose Test datatype copy functionality * - * Return: Success: 0 + * Return Success: 0 * - * Failure: number of errors + * Failure: number of errors * - * Programmer: Binh-Minh Ribler (using C version) - * January, 2007 + * Programmer Binh-Minh Ribler (using C version) + * January, 2007 * * Modifications: * @@ -143,21 +143,21 @@ static void test_copy() SUBTEST("DataType::copy() and DataType::operator="); try { - // Test copying from a predefined datatype using DataType::operator= - DataType assigned_type; - assigned_type = PredType::NATIVE_SHORT; + // Test copying from a predefined datatype using DataType::operator= + DataType assigned_type; + assigned_type = PredType::NATIVE_SHORT; // Test copying a predefined type using DataType::copy - DataType copied_type; + DataType copied_type; copied_type.copy (PredType::STD_B8LE); - // Test copying a user-defined type using DataType::operator= - DataType assigned_usertype; - assigned_usertype = copied_type; + // Test copying a user-defined type using DataType::operator= + DataType assigned_usertype; + assigned_usertype = copied_type; - // Test copying from a user-defined datatype using DataType::copy - DataType copied_usertype; - copied_usertype.copy(copied_type); + // Test copying from a user-defined datatype using DataType::copy + DataType copied_usertype; + copied_usertype.copy(copied_type); // Test copying a user-defined int type using DataType::operator= IntType orig_int(PredType::STD_B8LE); @@ -171,26 +171,26 @@ static void test_copy() IntType another_int_type; another_int_type = new_int_type; - PASSED(); + PASSED(); } catch (Exception& E) { - issue_fail_msg("test_copy", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_copy", __LINE__, __FILE__, E.getCDetailMsg()); } } /*------------------------------------------------------------------------- - * Function: test_query + * Function: test_query * - * Purpose: Tests query functions of compound and enumeration types. + * Purpose Tests query functions of compound and enumeration types. * - * Return: Success: 0 + * Return Success: 0 * - * Failure: number of errors + * Failure: number of errors * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * * Modifications: * @@ -203,113 +203,113 @@ const H5std_string EnumT_NAME("Enum_type"); static void test_query() { typedef struct { - int a; - float b; - long c; - double d; + int a; + float b; + long c; + double d; } src_typ_t; - short enum_val; + short enum_val; // Output message about test being performed SUBTEST("Query functions of compound and enumeration types"); try { - // Create File - H5File file(FILENAME[2], H5F_ACC_TRUNC); - - // Create a compound datatype - CompType tid1(sizeof(src_typ_t)); - - tid1.insertMember("a", HOFFSET(src_typ_t, a), PredType::NATIVE_INT); - tid1.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_FLOAT); - tid1.insertMember("c", HOFFSET(src_typ_t, c), PredType::NATIVE_LONG); - tid1.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_DOUBLE); - - // Create a enumerate datatype - EnumType tid2(sizeof(short)); - - tid2.insert("RED", (enum_val=0,&enum_val)); - tid2.insert("GREEN", (enum_val=1,&enum_val)); - tid2.insert("BLUE", (enum_val=2,&enum_val)); - 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 - 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. - 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 - tid1.commit(file, CompT_NAME); - tid1.close(); - - // Commit enumeration datatype and close it - tid2.commit(file, EnumT_NAME); - tid2.close(); - - // Open the datatypes for query - - // Deprecated functions - tid1 = file.openCompType(CompT_NAME); - tid1.close(); - tid2 = file.openEnumType(EnumT_NAME); - tid2.close(); - - CompType comptype(file, CompT_NAME); - EnumType enumtype(file, EnumT_NAME); - - // Query member number and member index by name, for compound type - nmembs = comptype.getNmembers(); - verify_val(nmembs, 4, "CompType::getNmembers()", __LINE__, __FILE__); - index = comptype.getMemberIndex("c"); - verify_val(index, 2, "CompType::getMemberIndex()", __LINE__, __FILE__); - - // Query member number and member index by name, for enumeration type - nmembs = enumtype.getNmembers(); - verify_val(nmembs, 5, "EnumType::getNmembers()", __LINE__, __FILE__); - index = enumtype.getMemberIndex("ORANGE"); - verify_val(index, 3, "EnumType::getMemberIndex()", __LINE__, __FILE__); - - // Close datatypes and file - comptype.close(); - enumtype.close(); - file.close(); - - // Try truncating the file to make sure reference counting is good. - // If any references to ids of the accessed types are left unterminated, - // the truncating will fail, because the file will not be closed in - // the file.close() above. - H5File file1(FILENAME[2], H5F_ACC_TRUNC); - - PASSED(); + // Create File + H5File file(FILENAME[2], H5F_ACC_TRUNC); + + // Create a compound datatype + CompType tid1(sizeof(src_typ_t)); + + tid1.insertMember("a", HOFFSET(src_typ_t, a), PredType::NATIVE_INT); + tid1.insertMember("b", HOFFSET(src_typ_t, b), PredType::NATIVE_FLOAT); + tid1.insertMember("c", HOFFSET(src_typ_t, c), PredType::NATIVE_LONG); + tid1.insertMember("d", HOFFSET(src_typ_t, d), PredType::NATIVE_DOUBLE); + + // Create a enumerate datatype + EnumType tid2(sizeof(short)); + + tid2.insert("RED", (enum_val=0,&enum_val)); + tid2.insert("GREEN", (enum_val=1,&enum_val)); + tid2.insert("BLUE", (enum_val=2,&enum_val)); + 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 + 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. + 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 + tid1.commit(file, CompT_NAME); + tid1.close(); + + // Commit enumeration datatype and close it + tid2.commit(file, EnumT_NAME); + tid2.close(); + + // Open the datatypes for query + + // Deprecated functions + tid1 = file.openCompType(CompT_NAME); + tid1.close(); + tid2 = file.openEnumType(EnumT_NAME); + tid2.close(); + + CompType comptype(file, CompT_NAME); + EnumType enumtype(file, EnumT_NAME); + + // Query member number and member index by name, for compound type + nmembs = comptype.getNmembers(); + verify_val(nmembs, 4, "CompType::getNmembers()", __LINE__, __FILE__); + index = comptype.getMemberIndex("c"); + verify_val(index, 2, "CompType::getMemberIndex()", __LINE__, __FILE__); + + // Query member number and member index by name, for enumeration type + nmembs = enumtype.getNmembers(); + verify_val(nmembs, 5, "EnumType::getNmembers()", __LINE__, __FILE__); + index = enumtype.getMemberIndex("ORANGE"); + verify_val(index, 3, "EnumType::getMemberIndex()", __LINE__, __FILE__); + + // Close datatypes and file + comptype.close(); + enumtype.close(); + file.close(); + + // Try truncating the file to make sure reference counting is good. + // If any references to ids of the accessed types are left unterminated, + // the truncating will fail, because the file will not be closed in + // the file.close() above. + H5File file1(FILENAME[2], H5F_ACC_TRUNC); + + PASSED(); } // end of try block catch (Exception& E) { - issue_fail_msg("test_query", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_query", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_query /*------------------------------------------------------------------------- - * Function: test_transient + * Function: test_transient * - * Purpose: Tests transient datatypes. + * Purpose Tests transient datatypes. * - * Return: Success: 0 + * Return Success: 0 * - * Failure: number of errors + * Failure: number of errors * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * * Modifications: * @@ -318,58 +318,58 @@ static void test_query() const char* filename1 = "dtypes1.h5"; static void test_transient () { - static hsize_t ds_size[2] = {10, 20}; + static hsize_t ds_size[2] = {10, 20}; SUBTEST("Transient datatypes"); try { - // Create the file and the dataspace. - H5File file(filename1, H5F_ACC_TRUNC); - DataSpace space(2, ds_size, ds_size); - - // 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 - 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) {} // do nothing, failure expected - - // 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 - IntType itype(dset); - try { - itype.setPrecision(256); - - // Should FAIL but didn't, so throw an invalid action exception - throw InvalidActionException("PredType::setPrecision", "Dataset datatypes should not be modifiable!"); - } catch (DataTypeIException& err) {} - itype.close(); - - // 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. (Note that a copy of it is modifiable.) - dset.close(); - dset = file.openDataSet("dset1"); - - // Close objects and file. - dset.close(); - file.close(); - type.close(); - space.close(); - PASSED(); + // Create the file and the dataspace. + H5File file(filename1, H5F_ACC_TRUNC); + DataSpace space(2, ds_size, ds_size); + + // 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 + 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) {} // do nothing, failure expected + + // 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 + IntType itype(dset); + try { + itype.setPrecision(256); + + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("PredType::setPrecision", "Dataset datatypes should not be modifiable!"); + } catch (DataTypeIException& err) {} + itype.close(); + + // 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. (Note that a copy of it is modifiable.) + dset.close(); + dset = file.openDataSet("dset1"); + + // Close objects and file. + dset.close(); + file.close(); + type.close(); + space.close(); + PASSED(); } // end of try block catch (Exception& E) { @@ -379,16 +379,16 @@ static void test_transient () /*------------------------------------------------------------------------- - * Function: test_named + * Function: test_named * - * Purpose: Tests named datatypes. + * Purpose Tests named datatypes. * - * Return: Success: 0 + * Return Success: 0 * - * Failure: number of errors + * Failure: number of errors * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * * Modifications: * @@ -397,141 +397,141 @@ static void test_transient () const H5std_string filename2("dtypes2.h5"); static void test_named () { - static hsize_t ds_size[2] = {10, 20}; - hsize_t i; - unsigned attr_data[10][20]; - DataType *ds_type = NULL; + static hsize_t ds_size[2] = {10, 20}; + hsize_t i; + unsigned attr_data[10][20]; + DataType *ds_type = NULL; SUBTEST("Named datatypes"); try { - // Create the file. - H5File file(filename2, H5F_ACC_TRUNC); + // Create the file. + H5File file(filename2, H5F_ACC_TRUNC); - // Create a simple dataspace. - DataSpace space(2, ds_size, ds_size); + // Create a simple dataspace. + DataSpace space(2, ds_size, ds_size); - // Predefined types cannot be committed. - try { - PredType nativeint(PredType::NATIVE_INT); - nativeint.commit(file, "test_named_1 (should not exist)"); + // Predefined types cannot be committed. + try { + 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) {} + // Should FAIL but didn't, so throw an invalid action exception + throw InvalidActionException("PredType::commit", "Attempted to commit a predefined datatype."); + } catch (DataTypeIException& err) {} - // Copy a predefined datatype and commit the copy. + // Copy a predefined datatype and commit the copy. IntType itype(PredType::NATIVE_INT); itype.commit(file, "native-int"); - // Test commit passing in const H5File& for prototype with const - try - { - // Create random char type - IntType atype(PredType::NATIVE_UCHAR); + // Test commit passing in const H5File& for prototype with const + try + { + // Create random char type + IntType atype(PredType::NATIVE_UCHAR); - // Creating group, declared as const - const Group const_grp = file.createGroup("GR as loc"); + // Creating group, declared as const + const Group const_grp = file.createGroup("GR as loc"); - // Commit type passing in const group; compilation would fail if - // no matching prototype - atype.commit(const_grp, "random uchar"); - } // end of try block - catch (Exception& E) + // Commit type passing in const group; compilation would fail if + // no matching prototype + atype.commit(const_grp, "random uchar"); + } // end of try block + catch (Exception& E) { - issue_fail_msg("test_named", __LINE__, __FILE__, "Commit at const group"); - } - - // Check that it is committed. - if (itype.committed() == false) - cerr << "IntType::committed() returned false" << endl; - - // We should not be able to modify a type after it has been committed. - try { - 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) {} - - // 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 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); - 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(); - - // 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__); - trans_type.setPrecision(256); - trans_type.close(); - - // Close the committed type and reopen it. It should be a named type. - itype.close(); - itype = file.openIntType("native-int"); - iscommitted = itype.committed(); - if (!iscommitted) - throw InvalidActionException("IntType::committed()", "Opened named types should be named types!"); - - // 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", itype, space); - ds_type = new DataType(dset.getDataType()); - iscommitted = ds_type->committed(); - if (!iscommitted) - throw InvalidActionException("IntType::committed()", "Dataset type should be named type!"); - dset.close(); - ds_type->close(); + issue_fail_msg("test_named", __LINE__, __FILE__, "Commit at const group"); + } + + // Check that it is committed. + if (itype.committed() == false) + cerr << "IntType::committed() returned false" << endl; + + // We should not be able to modify a type after it has been committed. + try { + 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) {} + + // 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 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); + 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(); + + // 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__); + trans_type.setPrecision(256); + trans_type.close(); + + // Close the committed type and reopen it. It should be a named type. + itype.close(); + itype = file.openIntType("native-int"); + iscommitted = itype.committed(); + if (!iscommitted) + throw InvalidActionException("IntType::committed()", "Opened named types should be named types!"); + + // 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", itype, space); + ds_type = new DataType(dset.getDataType()); + iscommitted = ds_type->committed(); + if (!iscommitted) + throw InvalidActionException("IntType::committed()", "Dataset type should be named type!"); + dset.close(); + ds_type->close(); delete ds_type; - // Reopen the dataset and its type, then make sure the type is - // a named type. - dset = file.openDataSet("dset1"); - 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. - dset.close(); - dset = file.createDataSet("dset2", *ds_type, space); - ds_type->close(); - dset.close(); + // Reopen the dataset and its type, then make sure the type is + // a named type. + dset = file.openDataSet("dset1"); + 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. + dset.close(); + dset = file.createDataSet("dset2", *ds_type, space); + ds_type->close(); + dset.close(); delete ds_type; - // 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("DataType::iscommitted()", "Dataset type should be named type!"); - ds_type->close(); - - // Get the dataset 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); - copied_type.close(); - - // Clean up - dset.close(); - itype.close(); - space.close(); - file.close(); - PASSED(); + // 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("DataType::iscommitted()", "Dataset type should be named type!"); + ds_type->close(); + + // Get the dataset 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); + copied_type.close(); + + // Clean up + dset.close(); + itype.close(); + space.close(); + file.close(); + PASSED(); } // end of try block catch (Exception& E) { @@ -565,14 +565,14 @@ void test_types() /*------------------------------------------------------------------------- - * Function: cleanup_types + * Function: cleanup_types * - * Purpose: Cleanup temporary test files + * Purpose Cleanup temporary test files * - * Return: none + * Return none * - * Programmer: Quincey Koziol - * September 10, 1999 + * Programmer Quincey Koziol + * September 10, 1999 * * Modifications: * @@ -582,5 +582,5 @@ extern "C" void cleanup_types() { for (int i = 0; i < 3; i++) - HDremove(FILENAME[i]); + HDremove(FILENAME[i]); } // cleanup_types diff --git a/c++/test/tvlstr.cpp b/c++/test/tvlstr.cpp index 43dcc0b..5dee1a2 100644 --- a/c++/test/tvlstr.cpp +++ b/c++/test/tvlstr.cpp @@ -45,9 +45,9 @@ const hsize_t SPACE1_DIM1 = 4; /**************************************************************** ** ** 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. It is passed into setVlenMemManager. +** 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. ** (Not used now) @@ -55,9 +55,9 @@ const hsize_t SPACE1_DIM1 = 4; #if 0 // not used now static void *test_vlstr_alloc_custom(size_t size, void *info) { - void *ret_value=NULL; // Pointer to return + void *ret_value=NULL; // Pointer to return size_t *mem_used=(size_t *)info; // Get the pointer to the memory used - size_t extra; // Extra space needed + size_t extra; // Extra space needed /* * This weird contortion is required on the DEC Alpha to keep the @@ -67,8 +67,8 @@ static void *test_vlstr_alloc_custom(size_t size, void *info) extra=MAX(sizeof(void *),sizeof(size_t)); if((ret_value=HDmalloc(extra+size))!=NULL) { - *(size_t *)ret_value=size; - *mem_used+=size; + *(size_t *)ret_value=size; + *mem_used+=size; } // end if ret_value = ((unsigned char *)ret_value) + extra; @@ -79,9 +79,9 @@ static 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. It is passed into setVlenMemManager. +** allocation routines. This routine just uses free to +** release the memory and decrements the amount of memory +** allocated. It is passed into setVlenMemManager. ** ** Note: exact copy from the C version. ** (Not used now) @@ -91,7 +91,7 @@ static void test_vlstr_free_custom(void *_mem, void *info) { unsigned char *mem; size_t *mem_used=(size_t *)info; // Get the pointer to the memory used - size_t extra; // Extra space needed + size_t extra; // Extra space needed /* * This weird contortion is required on the DEC Alpha to keep the @@ -109,14 +109,14 @@ static void test_vlstr_free_custom(void *_mem, void *info) #endif /*------------------------------------------------------------------------- - * Function: test_vlstring_dataset + * Function: test_vlstring_dataset * - * Purpose: Test writing/reading VL strings on datasets. + * Purpose Test writing/reading VL strings on datasets. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * *------------------------------------------------------------------------- */ @@ -136,89 +136,89 @@ static void test_vlstring_dataset() SUBTEST("VL String on Datasets"); try { - // Open the file - H5File file1(FILENAME, H5F_ACC_TRUNC); + // Open the file + H5File file1(FILENAME, H5F_ACC_TRUNC); - // Create a datatype to refer to. - StrType vlst(0, H5T_VARIABLE); + // Create a datatype to refer to. + StrType vlst(0, H5T_VARIABLE); - // Open the root group. - Group root = file1.openGroup("/"); + // Open the root group. + Group root = file1.openGroup("/"); - // Create dataspace for the dataset. - DataSpace ds_space (H5S_SCALAR); + // Create dataspace for the dataset. + DataSpace ds_space (H5S_SCALAR); - // Create an dataset in the root group. - DataSet dset1 = root.createDataSet(DSET1_NAME, vlst, ds_space); + // Create an dataset in the root group. + DataSet dset1 = root.createDataSet(DSET1_NAME, vlst, ds_space); - // Write data to the dataset. - dset1.write(DSET1_DATA, vlst); + // Write data to the dataset. + dset1.write(DSET1_DATA, vlst); - // Read and verify the dataset string as a string of chars. - dset1.read(&string_ds_check, vlst); - if(HDstrcmp(string_ds_check, DSET1_DATA.c_str())!=0) - TestErrPrintf("Line %d: Attribute data different: DSET1_DATA=%s,string_ds_check=%s\n",__LINE__, DSET1_DATA.c_str(), string_ds_check); + // Read and verify the dataset string as a string of chars. + dset1.read(&string_ds_check, vlst); + if(HDstrcmp(string_ds_check, DSET1_DATA.c_str())!=0) + TestErrPrintf("Line %d: Attribute data different: DSET1_DATA=%s,string_ds_check=%s\n",__LINE__, DSET1_DATA.c_str(), string_ds_check); - HDfree(string_ds_check); // note: no need for std::string test + HDfree(string_ds_check); // note: no need for std::string test string_ds_check = NULL; - // Read and verify the dataset string as an std::string. - H5std_string read_str; - dset1.read(read_str, vlst); - if (read_str != DSET1_DATA) - TestErrPrintf("Line %d: Attribute data different: DSET1_DATA=%s,read_str=%s\n",__LINE__, DSET1_DATA.c_str(), read_str.c_str()); + // Read and verify the dataset string as an std::string. + H5std_string read_str; + dset1.read(read_str, vlst); + if (read_str != DSET1_DATA) + TestErrPrintf("Line %d: Attribute data different: DSET1_DATA=%s,read_str=%s\n",__LINE__, DSET1_DATA.c_str(), read_str.c_str()); - // Close the dataset. - dset1.close(); + // Close the dataset. + dset1.close(); - // Test scalar type dataset with 1 value. - dset1 = root.createDataSet("test_scalar_small", vlst, ds_space); + // Test scalar type dataset with 1 value. + dset1 = root.createDataSet("test_scalar_small", vlst, ds_space); - dynstring_ds_write = (char*)HDcalloc(1, sizeof(char)); - HDmemset(dynstring_ds_write, 'A', 1); + dynstring_ds_write = (char*)HDcalloc(1, sizeof(char)); + HDmemset(dynstring_ds_write, 'A', 1); - // Write data to the dataset, then read it back. - dset1.write(&dynstring_ds_write, vlst); - dset1.read(&string_ds_check, vlst); + // Write data to the dataset, then read it back. + dset1.write(&dynstring_ds_write, vlst); + dset1.read(&string_ds_check, vlst); - // Verify data read. - if(HDstrcmp(string_ds_check,dynstring_ds_write)!=0) - TestErrPrintf("VL string datasets don't match!, dynstring_ds_write=%s, string_ds_check=%s\n",dynstring_ds_write,string_ds_check); - HDfree(string_ds_check); + // Verify data read. + if(HDstrcmp(string_ds_check,dynstring_ds_write)!=0) + TestErrPrintf("VL string datasets don't match!, dynstring_ds_write=%s, string_ds_check=%s\n",dynstring_ds_write,string_ds_check); + HDfree(string_ds_check); string_ds_check = NULL; - dset1.close(); + dset1.close(); - // Open dataset DSET1_NAME again. - dset1 = root.openDataSet(DSET1_NAME); + // Open dataset DSET1_NAME again. + dset1 = root.openDataSet(DSET1_NAME); - // Close dataset and file - dset1.close(); - file1.close(); + // Close dataset and file + dset1.close(); + file1.close(); - PASSED(); + PASSED(); } // end try block // Catch all exceptions. catch (Exception& E) { - issue_fail_msg("test_vlstring_dataset()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vlstring_dataset()", __LINE__, __FILE__, E.getCDetailMsg()); } if(dynstring_ds_write) HDfree(dynstring_ds_write); if(string_ds_check) - HDfree(string_ds_check); + HDfree(string_ds_check); } // test_vlstring_dataset() /*------------------------------------------------------------------------- - * Function: test_vlstring_array_dataset + * Function: test_vlstring_array_dataset * - * Purpose: Test writing/reading VL string array to/from datasets. + * Purpose Test writing/reading VL string array to/from datasets. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler - * July, 2009 + * Programmer Binh-Minh Ribler + * July, 2009 * *------------------------------------------------------------------------- */ @@ -235,89 +235,89 @@ static void test_vlstring_array_dataset() H5File* file1 = NULL; try { // Create file. - file1 = new H5File(FILENAME, H5F_ACC_RDWR); + file1 = new H5File(FILENAME, H5F_ACC_RDWR); // Create dataspace for datasets. hsize_t dims1[] = {SPACE1_DIM1}; DataSpace ds_space(SPACE1_RANK, dims1); - // Create a datatype to refer to. - StrType vlst(0, H5T_VARIABLE); - - // Create and write a dataset. - DataSet dataset(file1->createDataSet(DSSTRARR_NAME, vlst, ds_space)); - dataset.write(string_ds_array, vlst); - - // Read and verify the dataset using strings of chars as buffer. - // Note: reading by array of H5std_string doesn't work yet. - char *string_ds_check[SPACE1_DIM1]; - dataset.read(string_ds_check, vlst); - - hsize_t ii; - for (ii = 0; ii < SPACE1_DIM1; ii++) - { - if(HDstrcmp(string_ds_check[ii], string_ds_array[ii])!=0) - TestErrPrintf("Line %d: Dataset data different: written=%s,read=%s\n",__LINE__, string_ds_array[ii], string_ds_check[ii]); - - HDfree(string_ds_check[ii]); - } - - // Close objects that are no longer needed. - dataset.close(); - ds_space.close(); - - // - // Test with scalar data space. - // - - // Create H5S_SCALAR data space. - DataSpace scalar_space; - - // Create and write another dataset. - DataSet dataset2(file1->createDataSet("Dataset2", vlst, scalar_space)); - char *wdata2 = (char*)HDcalloc(65534, sizeof(char)); - HDmemset(wdata2, 'A', 65533); - dataset2.write(&wdata2, vlst); - - char *rdata2; - dataset2.read(&rdata2, vlst); - if (HDstrcmp(wdata2, rdata2)!=0) - TestErrPrintf("Line %d: Dataset data different: written=%s,read=%s\n",__LINE__, wdata2, rdata2); - - // Release resources from second dataset operation. - scalar_space.close(); - dataset2.close(); - HDfree(wdata2); - HDfree(rdata2); - - // Close objects and file. - dataset2.close(); - vlst.close(); - file1->close(); - - PASSED(); + // Create a datatype to refer to. + StrType vlst(0, H5T_VARIABLE); + + // Create and write a dataset. + DataSet dataset(file1->createDataSet(DSSTRARR_NAME, vlst, ds_space)); + dataset.write(string_ds_array, vlst); + + // Read and verify the dataset using strings of chars as buffer. + // Note: reading by array of H5std_string doesn't work yet. + char *string_ds_check[SPACE1_DIM1]; + dataset.read(string_ds_check, vlst); + + hsize_t ii; + for (ii = 0; ii < SPACE1_DIM1; ii++) + { + if(HDstrcmp(string_ds_check[ii], string_ds_array[ii])!=0) + TestErrPrintf("Line %d: Dataset data different: written=%s,read=%s\n",__LINE__, string_ds_array[ii], string_ds_check[ii]); + + HDfree(string_ds_check[ii]); + } + + // Close objects that are no longer needed. + dataset.close(); + ds_space.close(); + + // + // Test with scalar data space. + // + + // Create H5S_SCALAR data space. + DataSpace scalar_space; + + // Create and write another dataset. + DataSet dataset2(file1->createDataSet("Dataset2", vlst, scalar_space)); + char *wdata2 = (char*)HDcalloc(65534, sizeof(char)); + HDmemset(wdata2, 'A', 65533); + dataset2.write(&wdata2, vlst); + + char *rdata2; + dataset2.read(&rdata2, vlst); + if (HDstrcmp(wdata2, rdata2)!=0) + TestErrPrintf("Line %d: Dataset data different: written=%s,read=%s\n",__LINE__, wdata2, rdata2); + + // Release resources from second dataset operation. + scalar_space.close(); + dataset2.close(); + HDfree(wdata2); + HDfree(rdata2); + + // Close objects and file. + dataset2.close(); + vlst.close(); + file1->close(); + + PASSED(); } // end try // Catch all exceptions. catch (Exception& E) { - issue_fail_msg("test_vlstring_array_dataset()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vlstring_array_dataset()", __LINE__, __FILE__, E.getCDetailMsg()); } if(file1) - delete file1; + delete file1; } // end test_vlstring_array_dataset() /*------------------------------------------------------------------------- - * Function: test_vlstrings_special + * Function: test_vlstrings_special * - * Purpose: Test VL string code for special string cases, nil and - * zero-sized. + * Purpose Test VL string code for special string cases, nil and + * zero-sized. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * *------------------------------------------------------------------------- */ @@ -331,110 +331,110 @@ static void test_vlstrings_special() SUBTEST("Special VL Strings"); try { - // Create file. - H5File file1(FILENAME, H5F_ACC_TRUNC); + // Create file. + H5File file1(FILENAME, H5F_ACC_TRUNC); // Create dataspace for datasets. hsize_t dims1[] = {SPACE1_DIM1}; DataSpace sid1(SPACE1_RANK, dims1); - // Create a datatype to refer to. - StrType vlst(0, H5T_VARIABLE); - - // Create a dataset. - DataSet dataset(file1.createDataSet("Dataset3", vlst, sid1)); - - // Read from the dataset before writing data. - dataset.read(rdata, vlst); - - // Check data read in. - hsize_t ii; // counting variable - for (ii=0; ii<SPACE1_DIM1; ii++) - if(rdata[ii]!=NULL) - TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)ii,rdata[ii]); - - // Write dataset to disk, then read it back. - dataset.write(wdata, vlst); - dataset.read(rdata, vlst); - - // Compare data read in. - for (ii = 0; ii < SPACE1_DIM1; ii++) { - size_t wlen = HDstrlen(wdata[ii]); - size_t rlen = HDstrlen(rdata[ii]); - if(wlen != rlen) { - TestErrPrintf("VL data lengths don't match!, strlen(wdata[%d])=%u, strlen(rdata[%d])=%u\n", (int)ii, (unsigned)wlen, (int)ii, (unsigned)rlen); - continue; - } // end if - if(HDstrcmp(wdata[ii],rdata[ii]) != 0) { - TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n", (int)ii, wdata[ii], (int)ii, rdata[ii]); - continue; - } // end if - } // end for - - // Reclaim the read VL data. - DataSet::vlenReclaim((void *)rdata, vlst, sid1); - - // Close Dataset. - dataset.close(); - - /* - * Create another dataset to test nil strings. - */ - - // Create the property list and set the fill value for the second - // dataset. - DSetCreatPropList dcpl; - char *fill = NULL; // Fill value - dcpl.setFillValue(vlst, &fill); - dataset = file1.createDataSet("Dataset4", vlst, sid1, dcpl); - - // Close dataset creation property list. - dcpl.close(); - - // Read from dataset before writing data. - dataset.read(rdata, vlst); - - // Check data read in. - for (ii=0; ii<SPACE1_DIM1; ii++) - if(rdata[ii]!=NULL) - TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)ii,rdata[ii]); - - // Try to write nil strings to disk. - dataset.write(wdata2, vlst); - - // Read nil strings back from disk. - dataset.read(rdata, vlst); - - // Check data read in. - for (ii=0; ii<SPACE1_DIM1; ii++) - if(rdata[ii]!=NULL) - TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)ii,rdata[ii]); - - // Close objects and file. - dataset.close(); - vlst.close(); - sid1.close(); - file1.close(); - - PASSED(); + // Create a datatype to refer to. + StrType vlst(0, H5T_VARIABLE); + + // Create a dataset. + DataSet dataset(file1.createDataSet("Dataset3", vlst, sid1)); + + // Read from the dataset before writing data. + dataset.read(rdata, vlst); + + // Check data read in. + hsize_t ii; // counting variable + for (ii=0; ii<SPACE1_DIM1; ii++) + if(rdata[ii]!=NULL) + TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)ii,rdata[ii]); + + // Write dataset to disk, then read it back. + dataset.write(wdata, vlst); + dataset.read(rdata, vlst); + + // Compare data read in. + for (ii = 0; ii < SPACE1_DIM1; ii++) { + size_t wlen = HDstrlen(wdata[ii]); + size_t rlen = HDstrlen(rdata[ii]); + if(wlen != rlen) { + TestErrPrintf("VL data lengths don't match!, strlen(wdata[%d])=%u, strlen(rdata[%d])=%u\n", (int)ii, (unsigned)wlen, (int)ii, (unsigned)rlen); + continue; + } // end if + if(HDstrcmp(wdata[ii],rdata[ii]) != 0) { + TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n", (int)ii, wdata[ii], (int)ii, rdata[ii]); + continue; + } // end if + } // end for + + // Reclaim the read VL data. + DataSet::vlenReclaim((void *)rdata, vlst, sid1); + + // Close Dataset. + dataset.close(); + + /* + * Create another dataset to test nil strings. + */ + + // Create the property list and set the fill value for the second + // dataset. + DSetCreatPropList dcpl; + char *fill = NULL; // Fill value + dcpl.setFillValue(vlst, &fill); + dataset = file1.createDataSet("Dataset4", vlst, sid1, dcpl); + + // Close dataset creation property list. + dcpl.close(); + + // Read from dataset before writing data. + dataset.read(rdata, vlst); + + // Check data read in. + for (ii=0; ii<SPACE1_DIM1; ii++) + if(rdata[ii]!=NULL) + TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)ii,rdata[ii]); + + // Try to write nil strings to disk. + dataset.write(wdata2, vlst); + + // Read nil strings back from disk. + dataset.read(rdata, vlst); + + // Check data read in. + for (ii=0; ii<SPACE1_DIM1; ii++) + if(rdata[ii]!=NULL) + TestErrPrintf("VL doesn't match!, rdata[%d]=%p\n",(int)ii,rdata[ii]); + + // Close objects and file. + dataset.close(); + vlst.close(); + sid1.close(); + file1.close(); + + PASSED(); } // end try // Catch all exceptions. catch (Exception& E) { - issue_fail_msg("test_vlstrings_special()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vlstrings_special()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_vlstrings_special /*------------------------------------------------------------------------- - * Function: test_vlstring_type + * Function: test_vlstring_type * - * Purpose: Test if VL string is treated as string. + * Purpose Test if VL string is treated as string. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * *------------------------------------------------------------------------- */ @@ -446,67 +446,67 @@ static void test_vlstring_type() H5File* file1 = NULL; try { - // Open file. - file1 = new H5File(FILENAME, H5F_ACC_RDWR); + // Open file. + file1 = new H5File(FILENAME, H5F_ACC_RDWR); - // Create a datatype to refer to. - StrType vlst(PredType::C_S1); + // Create a datatype to refer to. + StrType vlst(PredType::C_S1); - // Change padding and verify it. - vlst.setStrpad(H5T_STR_NULLPAD); - H5T_str_t pad = vlst.getStrpad(); - verify_val(pad, H5T_STR_NULLPAD, "StrType::getStrpad", __LINE__, __FILE__); + // Change padding and verify it. + vlst.setStrpad(H5T_STR_NULLPAD); + H5T_str_t pad = vlst.getStrpad(); + verify_val(pad, H5T_STR_NULLPAD, "StrType::getStrpad", __LINE__, __FILE__); - // Convert to variable-length string. - vlst.setSize(H5T_VARIABLE); + // Convert to variable-length string. + vlst.setSize(H5T_VARIABLE); - // Check if datatype is VL string. - H5T_class_t type_class = vlst.getClass(); - verify_val(type_class, H5T_STRING, "DataType::getClass", __LINE__, __FILE__); - bool is_variable_str = vlst.isVariableStr(); - verify_val(is_variable_str, true, "DataType::isVariableStr", __LINE__, __FILE__); + // Check if datatype is VL string. + H5T_class_t type_class = vlst.getClass(); + verify_val(type_class, H5T_STRING, "DataType::getClass", __LINE__, __FILE__); + bool is_variable_str = vlst.isVariableStr(); + verify_val(is_variable_str, true, "DataType::isVariableStr", __LINE__, __FILE__); - // Check default character set and padding. - H5T_cset_t cset = vlst.getCset(); - verify_val(cset, H5T_CSET_ASCII, "StrType::getCset", __LINE__, __FILE__); - pad = vlst.getStrpad(); - verify_val(pad, H5T_STR_NULLPAD, "StrType::getStrpad", __LINE__, __FILE__); + // Check default character set and padding. + H5T_cset_t cset = vlst.getCset(); + verify_val(cset, H5T_CSET_ASCII, "StrType::getCset", __LINE__, __FILE__); + pad = vlst.getStrpad(); + verify_val(pad, H5T_STR_NULLPAD, "StrType::getStrpad", __LINE__, __FILE__); - // Commit variable-length string datatype to storage. - vlst.commit(*file1, VLSTR_TYPE); + // Commit variable-length string datatype to storage. + vlst.commit(*file1, VLSTR_TYPE); - // Close datatype. - vlst.close(); + // Close datatype. + vlst.close(); - // Try opening datatype again. - vlst = file1->openStrType(VLSTR_TYPE); // deprecated + // Try opening datatype again. + vlst = file1->openStrType(VLSTR_TYPE); // deprecated - // Close again and reopen with constructor. - vlst.close(); - StrType vlst1(*file1, VLSTR_TYPE); + // Close again and reopen with constructor. + vlst.close(); + StrType vlst1(*file1, VLSTR_TYPE); - // Close datatype and file. - vlst1.close(); - file1->close(); + // Close datatype and file. + vlst1.close(); + file1->close(); delete file1; - // Open file. - file1 = new H5File(FILENAME, H5F_ACC_RDWR); + // Open file. + file1 = new H5File(FILENAME, H5F_ACC_RDWR); - // Open the variable-length string datatype just created - StrType vlst2(*file1, VLSTR_TYPE); + // Open the variable-length string datatype just created + StrType vlst2(*file1, VLSTR_TYPE); - // Verify character set and padding - cset = vlst2.getCset(); - verify_val(cset, H5T_CSET_ASCII, "StrType::getCset", __LINE__, __FILE__); - pad = vlst2.getStrpad(); - verify_val(pad, H5T_STR_NULLPAD, "StrType::getStrpad", __LINE__, __FILE__); + // Verify character set and padding + cset = vlst2.getCset(); + verify_val(cset, H5T_CSET_ASCII, "StrType::getCset", __LINE__, __FILE__); + pad = vlst2.getStrpad(); + verify_val(pad, H5T_STR_NULLPAD, "StrType::getStrpad", __LINE__, __FILE__); - // Close datatype and file - vlst2.close(); - file1->close(); + // Close datatype and file + vlst2.close(); + file1->close(); - PASSED(); + PASSED(); } // end try block // Catch all exceptions. @@ -516,18 +516,18 @@ static void test_vlstring_type() } if(file1) - delete file1; + delete file1; } // end test_vlstring_type() /*------------------------------------------------------------------------- - * Function: test_compact_vlstring + * Function: test_compact_vlstring * - * Purpose: Test storing VL strings in compact datasets. + * Purpose Test storing VL strings in compact datasets. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * *------------------------------------------------------------------------- */ @@ -537,55 +537,55 @@ static void test_compact_vlstring() SUBTEST("VL Strings on Compact Dataset"); try { - // Create file - H5File file1(FILENAME, H5F_ACC_TRUNC); + // Create file + H5File file1(FILENAME, H5F_ACC_TRUNC); - // Create dataspace for datasets + // Create dataspace for datasets hsize_t dims1[] = {SPACE1_DIM1}; DataSpace sid1(SPACE1_RANK, dims1); - // Create a datatype to refer to - StrType vlst(0, H5T_VARIABLE); - - // Create dataset create property list and set layout - DSetCreatPropList plist; - plist.setLayout(H5D_COMPACT); - - // Create a dataset - DataSet dataset(file1.createDataSet("Dataset5", vlst, sid1, plist)); - - // Write dataset to disk - const char *wdata[SPACE1_DIM1] = {"one", "two", "three", "four"}; - dataset.write(wdata, vlst); - - // Read dataset from disk - char *rdata[SPACE1_DIM1]; // Information read in - dataset.read(rdata, vlst); - - // Compare data read in - hsize_t i; - for (i=0; i<SPACE1_DIM1; i++) { - if (HDstrlen(wdata[i])!=strlen(rdata[i])) { - TestErrPrintf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",(int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i])); - continue; - } // end if - if (HDstrcmp(wdata[i],rdata[i]) != 0) { - TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",(int)i,wdata[i],(int)i,rdata[i]); - continue; - } // end if - } // end for - - // Reclaim the read VL data - DataSet::vlenReclaim((void *)rdata, vlst, sid1); - - // Close objects and file - dataset.close(); - vlst.close(); - sid1.close(); - plist.close(); - file1.close(); - - PASSED(); + // Create a datatype to refer to + StrType vlst(0, H5T_VARIABLE); + + // Create dataset create property list and set layout + DSetCreatPropList plist; + plist.setLayout(H5D_COMPACT); + + // Create a dataset + DataSet dataset(file1.createDataSet("Dataset5", vlst, sid1, plist)); + + // Write dataset to disk + const char *wdata[SPACE1_DIM1] = {"one", "two", "three", "four"}; + dataset.write(wdata, vlst); + + // Read dataset from disk + char *rdata[SPACE1_DIM1]; // Information read in + dataset.read(rdata, vlst); + + // Compare data read in + hsize_t i; + for (i=0; i<SPACE1_DIM1; i++) { + if (HDstrlen(wdata[i])!=strlen(rdata[i])) { + TestErrPrintf("VL data length don't match!, strlen(wdata[%d])=%d, strlen(rdata[%d])=%d\n",(int)i,(int)strlen(wdata[i]),(int)i,(int)strlen(rdata[i])); + continue; + } // end if + if (HDstrcmp(wdata[i],rdata[i]) != 0) { + TestErrPrintf("VL data values don't match!, wdata[%d]=%s, rdata[%d]=%s\n",(int)i,wdata[i],(int)i,rdata[i]); + continue; + } // end if + } // end for + + // Reclaim the read VL data + DataSet::vlenReclaim((void *)rdata, vlst, sid1); + + // Close objects and file + dataset.close(); + vlst.close(); + sid1.close(); + plist.close(); + file1.close(); + + PASSED(); } // end try // Catch all exceptions. @@ -596,14 +596,14 @@ static void test_compact_vlstring() } // test_compact_vlstrings /*------------------------------------------------------------------------- - * Function: test_vlstring_attribute + * Function: test_vlstring_attribute * - * Purpose: Test writing/reading VL strings on attributes. + * Purpose Test writing/reading VL strings on attributes. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * *------------------------------------------------------------------------- */ @@ -620,81 +620,81 @@ static void test_vlstring_attribute() SUBTEST("VL String on Attributes"); try { - // Open the file - H5File file1(FILENAME, H5F_ACC_RDWR); + // Open the file + H5File file1(FILENAME, H5F_ACC_RDWR); - // Create a datatype to refer to. - StrType vlst(0, H5T_VARIABLE); + // Create a datatype to refer to. + StrType vlst(0, H5T_VARIABLE); - // Open the root group. - Group root = file1.openGroup("/"); + // Open the root group. + Group root = file1.openGroup("/"); - // Create dataspace for the attribute. - DataSpace att_space (H5S_SCALAR); + // Create dataspace for the attribute. + DataSpace att_space (H5S_SCALAR); - // Create an attribute for the root group. - Attribute gr_attr = root.createAttribute(ATTRSTR_NAME, vlst, att_space); + // Create an attribute for the root group. + Attribute gr_attr = root.createAttribute(ATTRSTR_NAME, vlst, att_space); - // Write data to the attribute. - gr_attr.write(vlst, ATTRSTR_DATA); + // Write data to the attribute. + gr_attr.write(vlst, ATTRSTR_DATA); - // Read and verify the attribute string as a string of chars. - char *string_att_check; - gr_attr.read(vlst, &string_att_check); - if(HDstrcmp(string_att_check, ATTRSTR_DATA.c_str())!=0) - TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,string_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), string_att_check); + // Read and verify the attribute string as a string of chars. + char *string_att_check; + gr_attr.read(vlst, &string_att_check); + if(HDstrcmp(string_att_check, ATTRSTR_DATA.c_str())!=0) + TestErrPrintf("Line %d: Attribute data different: ATTRSTR_DATA=%s,string_att_check=%s\n",__LINE__, ATTRSTR_DATA.c_str(), string_att_check); - HDfree(string_att_check); // note: no need for std::string test + HDfree(string_att_check); // note: no need for std::string test - // Read and verify the attribute string as an std::string. - H5std_string read_str; - gr_attr.read(vlst, 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()); + // Read and verify the attribute string as an std::string. + H5std_string read_str; + gr_attr.read(vlst, 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()); - // Close group's attribute. - gr_attr.close(); + // Close group's attribute. + gr_attr.close(); - // Test creating a "large" sized string attribute - gr_attr = root.createAttribute("test_scalar_large", vlst, att_space); + // Test creating a "large" sized string attribute + gr_attr = root.createAttribute("test_scalar_large", vlst, att_space); - string_att_write = (char*)HDcalloc(8192, sizeof(char)); - HDmemset(string_att_write, 'A', 8191); + string_att_write = (char*)HDcalloc(8192, sizeof(char)); + HDmemset(string_att_write, 'A', 8191); - // Write data to the attribute, then read it back. - gr_attr.write(vlst, &string_att_write); - gr_attr.read(vlst, &string_att_check); + // Write data to the attribute, then read it back. + gr_attr.write(vlst, &string_att_write); + gr_attr.read(vlst, &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); + // 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); - // Release resources. - HDfree(string_att_check); - HDfree(string_att_write); - gr_attr.close(); - file1.close(); + // Release resources. + HDfree(string_att_check); + HDfree(string_att_write); + gr_attr.close(); + file1.close(); - PASSED(); + PASSED(); } // end try block // Catch all exceptions. catch (Exception& E) { - issue_fail_msg("test_vlstring_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vlstring_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_vlstring_attribute() #if 0 /*------------------------------------------------------------------------- - * Function: test_read_vl_string_attribute + * Function: test_read_vl_string_attribute * - * Purpose: Test reading VL strings from attributes. + * Purpose Test reading VL strings from attributes. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * *------------------------------------------------------------------------- */ @@ -705,58 +705,58 @@ static void test_read_vl_string_attribute() SUBTEST("reading VL String as attributes"); try { - // Open file - H5File file1(FILENAME, H5F_ACC_RDONLY); - - // Create a datatype to refer to. - StrType vlst(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(vlst, &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); - att.close(); - - // Test reading "large" sized string attribute - att = root.openAttribute("test_scalar_large"); - att.read(vlst, &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 - - // Close objects and file. - att.close(); - vlst.close(); - root.close(); - file1.close(); - - PASSED(); + // Open file + H5File file1(FILENAME, H5F_ACC_RDONLY); + + // Create a datatype to refer to. + StrType vlst(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(vlst, &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); + att.close(); + + // Test reading "large" sized string attribute + att = root.openAttribute("test_scalar_large"); + att.read(vlst, &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 + + // Close objects and file. + att.close(); + vlst.close(); + root.close(); + file1.close(); + + PASSED(); } // end try // Catch all exceptions. catch (Exception& E) { - issue_fail_msg("test_read_vl_string_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_read_vl_string_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_read_vl_string_attribute #endif // 2013: need to verify before adding to test /*------------------------------------------------------------------------- - * Function: test_vlstring_array_attribute + * Function: test_vlstring_array_attribute * - * Purpose: Test writing/reading VL string array to/from attributes. + * Purpose Test writing/reading VL string array to/from attributes. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler - * July, 2009 + * Programmer Binh-Minh Ribler + * July, 2009 * *------------------------------------------------------------------------- */ @@ -772,105 +772,105 @@ static void test_vlstring_array_attribute() SUBTEST("VL String Array on Attributes"); try { - // Open the file - H5File file1(FILENAME, H5F_ACC_RDWR); + // Open the file + H5File file1(FILENAME, H5F_ACC_RDWR); - // Create a datatype to refer to. - StrType vlst(0, H5T_VARIABLE); + // Create a datatype to refer to. + StrType vlst(0, H5T_VARIABLE); - // Open the root group. - Group root = file1.openGroup("/"); + // Open the root group. + Group root = file1.openGroup("/"); // Create dataspace for datasets. hsize_t dims1[] = {SPACE1_DIM1}; DataSpace att_space(SPACE1_RANK, dims1); - // Create an attribute for the root group. - Attribute gr_attr = root.createAttribute(ATTRSTRARR_NAME, vlst, att_space); + // Create an attribute for the root group. + Attribute gr_attr = root.createAttribute(ATTRSTRARR_NAME, vlst, att_space); - // Write data to the attribute. - gr_attr.write(vlst, string_att_array); + // Write data to the attribute. + gr_attr.write(vlst, string_att_array); - // Read and verify the attribute string as a string of chars. - // Note: reading by array of H5std_string doesn't work yet. - char *string_att_check[SPACE1_DIM1]; - gr_attr.read(vlst, &string_att_check); + // Read and verify the attribute string as a string of chars. + // Note: reading by array of H5std_string doesn't work yet. + char *string_att_check[SPACE1_DIM1]; + gr_attr.read(vlst, &string_att_check); - hsize_t ii; - for (ii = 0; ii < SPACE1_DIM1; ii++) - { - if(HDstrcmp(string_att_check[ii], string_att_array[ii])!=0) - TestErrPrintf("Line %d: Attribute data different: written=%s,read=%s\n",__LINE__, string_att_check[ii], string_att_check[ii]); + hsize_t ii; + for (ii = 0; ii < SPACE1_DIM1; ii++) + { + if(HDstrcmp(string_att_check[ii], string_att_array[ii])!=0) + TestErrPrintf("Line %d: Attribute data different: written=%s,read=%s\n",__LINE__, string_att_check[ii], string_att_check[ii]); - HDfree(string_att_check[ii]); // note: no need for std::string test - } + HDfree(string_att_check[ii]); // note: no need for std::string test + } - // Close group's attribute. - gr_attr.close(); - file1.close(); + // Close group's attribute. + gr_attr.close(); + file1.close(); - PASSED(); + PASSED(); } // end try block // Catch all exceptions. catch (Exception& E) { - issue_fail_msg("test_vlstring_array_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vlstring_array_attribute()", __LINE__, __FILE__, E.getCDetailMsg()); } } // test_vlstring_array_attribute() /* Helper routine for test_vl_rewrite() */ static void write_scalar_dset(H5File& file, DataType& type, DataSpace& space, - char *name, char *data) + char *name, char *data) { DataSet dset; try { - dset = file.createDataSet(name, type, space); - dset.write(&data, type, space, space); - dset.close(); + dset = file.createDataSet(name, type, space); + dset.write(&data, type, space, space); + dset.close(); } // end try catch (FileIException& ferr) { - throw; + throw; } catch (DataSetIException& derr) { - throw; + throw; } } /* Helper routine for test_vl_rewrite() */ static void read_scalar_dset(H5File& file, DataType& type, DataSpace& space, - char *name, char *data) + char *name, char *data) { char *data_read; DataSet dset; try { - dset = file.openDataSet(name); - dset.read(&data_read, type, space, space); - dset.close(); + dset = file.openDataSet(name); + dset.read(&data_read, type, space, space); + dset.close(); - if(HDstrcmp(data, data_read)) - TestErrPrintf("Expected %s for dataset %s but read %s\n", data, name, data_read); + if(HDstrcmp(data, data_read)) + TestErrPrintf("Expected %s for dataset %s but read %s\n", data, name, data_read); - HDfree(data_read); + HDfree(data_read); } // end try catch (FileIException& ferr) { - throw; + throw; } catch (DataSetIException& derr) { - throw; + throw; } } /*------------------------------------------------------------------------- - * Function: test_vl_rewrite + * Function: test_vl_rewrite * - * Purpose: Test I/O on VL strings when many objects in the file - * have been linked/unlinked. + * Purpose Test I/O on VL strings when many objects in the file + * have been linked/unlinked. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler (use C version) - * January, 2007 + * Programmer Binh-Minh Ribler (use C version) + * January, 2007 * *------------------------------------------------------------------------- */ @@ -882,75 +882,75 @@ static void test_vl_rewrite() SUBTEST("I/O on VL strings with link/unlink"); try { - // Create the files. - H5File file1(FILENAME, H5F_ACC_TRUNC); - H5File file2(FILENAME2, H5F_ACC_TRUNC); - - // Create the VL string datatype. - StrType type(0, H5T_VARIABLE); - - // Create dataspace for the attribute. - DataSpace space (H5S_SCALAR); - - // Create in file 1. - int i; - char name[256]; // Buffer for names & data - for (i=0; i<REWRITE_NDATASETS; i++) { - sprintf(name, "/set_%d", i); - write_scalar_dset(file1, type, space, name, name); - } - - // Effectively copy data from file 1 to 2. - for (i=0; i<REWRITE_NDATASETS; i++) { - sprintf(name, "/set_%d", i); - read_scalar_dset(file1, type, space, name, name); - write_scalar_dset(file2, type, space, name, name); - } - - // Read back from file 2. - for (i=0; i<REWRITE_NDATASETS; i++) { - sprintf(name, "/set_%d", i); - read_scalar_dset(file2, type, space, name, name); - } - - // Remove from file 2. - for (i=0; i<REWRITE_NDATASETS; i++) { - sprintf(name, "/set_%d", i); - file2.unlink(name); - } - - // Effectively copy from file 1 to file 2. - for (i=0; i<REWRITE_NDATASETS; i++) { - sprintf(name, "/set_%d", i); - read_scalar_dset(file1, type, space, name, name); - write_scalar_dset(file2, type, space, name, name); - } - - // Close objects and file. - type.close(); - space.close(); - file1.close(); - file2.close(); - - PASSED(); + // Create the files. + H5File file1(FILENAME, H5F_ACC_TRUNC); + H5File file2(FILENAME2, H5F_ACC_TRUNC); + + // Create the VL string datatype. + StrType type(0, H5T_VARIABLE); + + // Create dataspace for the attribute. + DataSpace space (H5S_SCALAR); + + // Create in file 1. + int i; + char name[256]; // Buffer for names & data + for (i=0; i<REWRITE_NDATASETS; i++) { + sprintf(name, "/set_%d", i); + write_scalar_dset(file1, type, space, name, name); + } + + // Effectively copy data from file 1 to 2. + for (i=0; i<REWRITE_NDATASETS; i++) { + sprintf(name, "/set_%d", i); + read_scalar_dset(file1, type, space, name, name); + write_scalar_dset(file2, type, space, name, name); + } + + // Read back from file 2. + for (i=0; i<REWRITE_NDATASETS; i++) { + sprintf(name, "/set_%d", i); + read_scalar_dset(file2, type, space, name, name); + } + + // Remove from file 2. + for (i=0; i<REWRITE_NDATASETS; i++) { + sprintf(name, "/set_%d", i); + file2.unlink(name); + } + + // Effectively copy from file 1 to file 2. + for (i=0; i<REWRITE_NDATASETS; i++) { + sprintf(name, "/set_%d", i); + read_scalar_dset(file1, type, space, name, name); + write_scalar_dset(file2, type, space, name, name); + } + + // Close objects and file. + type.close(); + space.close(); + file1.close(); + file2.close(); + + PASSED(); } // end try // Catch all exceptions. catch (Exception& E) { - issue_fail_msg("test_vl_rewrite()", __LINE__, __FILE__, E.getCDetailMsg()); + issue_fail_msg("test_vl_rewrite()", __LINE__, __FILE__, E.getCDetailMsg()); } } // end test_vl_rewrite() /*------------------------------------------------------------------------- - * Function: test_vlstrings + * Function: test_vlstrings * - * Purpose: VL string testing main routine. + * Purpose VL string testing main routine. * - * Return: None + * Return None * - * Programmer: Binh-Minh Ribler - * January, 2007 + * Programmer Binh-Minh Ribler + * January, 2007 * *------------------------------------------------------------------------- */ @@ -981,13 +981,13 @@ void test_vlstrings() /*------------------------------------------------------------------------- - * Function: cleanup_vlstrings + * Function: cleanup_vlstrings * - * Purpose: Cleanup temporary test files + * Purpose Cleanup temporary test files * - * Return: none + * Return none * - * Programmer: Quincey Koziol + * Programmer Quincey Koziol * September 10, 1999 * * Modifications: |