diff options
Diffstat (limited to 'c++/test/tfile.cpp')
-rw-r--r-- | c++/test/tfile.cpp | 133 |
1 files changed, 65 insertions, 68 deletions
diff --git a/c++/test/tfile.cpp b/c++/test/tfile.cpp index 794bda0..5314741 100644 --- a/c++/test/tfile.cpp +++ b/c++/test/tfile.cpp @@ -79,7 +79,7 @@ const string FILE4("tfile4.h5"); * 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 + * arises later, this will have to be specificly handled * with a special routine. * *------------------------------------------------------------------------- @@ -87,14 +87,14 @@ const string FILE4("tfile4.h5"); static void test_file_create(void) { - /* Output message about test being performed */ + // Output message about test being performed MESSAGE(5, ("Testing File Creation I/O\n")); - /* Test create with various sequences of H5F_ACC_EXCL and */ - /* H5F_ACC_TRUNC flags */ + // Test create with various sequences of H5F_ACC_EXCL and + // H5F_ACC_TRUNC flags - /* Create with H5F_ACC_EXCL */ - /* First ensure the file does not exist */ + // Create with H5F_ACC_EXCL + // First ensure the file does not exist remove(FILE1.c_str()); // Setting this to NULL for cleaning up in failure situations @@ -109,21 +109,22 @@ test_file_create(void) 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."); + throw InvalidActionException("H5File constructor", "Attempted to create an existing file."); } - catch( FileIException E ) {} // do nothing, FAIL expected + 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 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."); + throw InvalidActionException("H5File constructor", "File already exists."); } catch( FileIException E ) // catching creating existing file {} // do nothing, FAIL expected @@ -131,15 +132,13 @@ test_file_create(void) // Test create with H5F_ACC_TRUNC. This will truncate the existing file. file1 = new H5File (FILE1, H5F_ACC_TRUNC); - /* - * Try to truncate first file again. This should fail because file1 is the - * same file and is currently open. - */ + // Try to truncate 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."); + throw InvalidActionException("H5File constructor", "H5F_ACC_TRUNC attempt on an opened file."); } catch( FileIException E ) // catching truncating opened file {} // do nothing, FAIL expected @@ -150,7 +149,7 @@ test_file_create(void) 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."); + 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 @@ -196,10 +195,10 @@ test_file_create(void) FileCreatPropList* tmpl1 = NULL; try { - /* Create a new file with a non-standard file-creation template */ + // Create a new file with a non-standard file-creation template tmpl1 = new FileCreatPropList; - /* Set the new file-creation parameters */ + // 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 ); @@ -208,48 +207,46 @@ test_file_create(void) // params. H5File file2( FILE2, H5F_ACC_TRUNC, *tmpl1 ); - /* Release file-creation template */ + // Release file-creation template delete tmpl1; tmpl1 = NULL; - /* Get the file-creation template */ + // Get the file-creation template tmpl1 = new FileCreatPropList (file2.getCreatePlist()); - /* Get the file-creation parameters */ + // 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 */ + 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 */ + // Clone the file-creation template FileCreatPropList tmpl2; tmpl2.copy (*tmpl1); - /* Dynamically release file-creation template */ + // Release file-creation template delete tmpl1; tmpl1 = NULL; - /* Set the new file-creation parameter */ + // Set the new file-creation parameter tmpl2.setUserblock( F3_USERBLOCK_SIZE ); - /* - * Try to create second file, with non-standard file-creation template - * params - */ + // Try to create second file, with non-standard file-creation template + // params H5File file3( FILE3, H5F_ACC_TRUNC, tmpl2 ); - /* Get the file-creation template */ + // Get the file-creation template tmpl1 = new FileCreatPropList (file3.getCreatePlist()); - /* Get the file-creation parameters */ + // Get the file-creation parameters ublock = tmpl1->getUserblock(); verify_val((long)ublock, (long)F3_USERBLOCK_SIZE, "FileCreatPropList::getUserblock", __LINE__, __FILE__); @@ -261,17 +258,17 @@ test_file_create(void) verify_val(iparm1, F3_SYM_INTERN_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); verify_val(iparm2, F3_SYM_LEAF_K, "FileCreatPropList::getSymk", __LINE__, __FILE__); - /* Dynamically release file-creation template */ + // Release file-creation template delete tmpl1; } // catch all exceptions catch (Exception E) { issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); - if (tmpl1 != NULL) // clean up + if (tmpl1 != NULL) // clean up delete tmpl1; } -} /* test_file_create() */ +} // test_file_create() /*------------------------------------------------------------------------- @@ -289,7 +286,7 @@ test_file_create(void) * 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 + * arises later, this will have to be specificly handled * with a special routine. * *------------------------------------------------------------------------- @@ -297,27 +294,27 @@ test_file_create(void) static void test_file_open(void) { - /* Output message about test being performed */ + // Output message about test being performed MESSAGE(5, ("Testing File Opening I/O\n")); try { - /* Open first file */ + // Open first file H5File file1 (FILE2, H5F_ACC_RDWR ); - /* Get the file-creation template */ + // Get the file-creation template FileCreatPropList tmpl1 = file1.getCreatePlist(); - /* Get the file-creation parameters */ + // 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 */ + 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__); @@ -326,7 +323,7 @@ test_file_open(void) catch( Exception E ) { issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_file_open() */ +} // test_file_open() /*------------------------------------------------------------------------- @@ -346,7 +343,7 @@ test_file_open(void) static void test_file_size(void) { - /* Output message about test being performed */ + // Output message about test being performed MESSAGE(5, ("Testing File Size\n")); hid_t fapl_id; @@ -360,7 +357,7 @@ test_file_size(void) // 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); @@ -380,7 +377,7 @@ test_file_size(void) // use C test utility routine to close property list. H5Pclose(fapl_id); -} /* test_file_size() */ +} // test_file_size() /*------------------------------------------------------------------------- @@ -405,7 +402,7 @@ const string DSETNAME ("dataset"); const string ATTRNAME ("attribute"); const string DTYPENAME ("compound"); -/* Compound datatype */ +// Compound datatype typedef struct s1_t { unsigned int a; float b; @@ -414,7 +411,7 @@ typedef struct s1_t { static void test_file_name() { - /* Output message about test being performed */ + // Output message about test being performed MESSAGE(5, ("Testing File Name\n")); string file_name; @@ -426,42 +423,42 @@ test_file_name() file_name = file4.getFileName(); verify_val(file_name, FILE4, "H5File::getFileName", __LINE__, __FILE__); - /* Create a group in the root group */ + // Create a group in the root group Group group(file4.createGroup(GROUPNAME, 0)); - /* Get and verify file name */ + // Get and verify file name file_name = group.getFileName(); verify_val(file_name, FILE4, "Group::getFileName", __LINE__, __FILE__); - /* Create the data space */ + // Create the data space hsize_t dims[RANK] = {NX, NY}; DataSpace space(RANK, dims); - /* Create a new dataset */ + // Create a new dataset DataSet dataset(file4.createDataSet (DSETNAME, PredType::NATIVE_INT, space)); - /* Get and verify file name */ + // Get and verify file name file_name = dataset.getFileName(); verify_val(file_name, FILE4, "DataSet::getFileName", __LINE__, __FILE__); - /* Create an attribute for the dataset */ + // Create an attribute for the dataset Attribute attr(dataset.createAttribute(ATTRNAME, PredType::NATIVE_INT, space)); - /* Get and verify file name */ + // Get and verify file name file_name = attr.getFileName(); verify_val(file_name, FILE4, "Attribute::getFileName", __LINE__, __FILE__); - /* Create a compound datatype */ + // Create a compound datatype CompType comp_type (sizeof(s1_t)); - /* Insert fields */ + // 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 */ + // Save it on file comp_type.commit(file4, DTYPENAME); - /* Get and verify file name */ + // Get and verify file name comp_type.getFileName(); verify_val(file_name, FILE4, "CompType::getFileName", __LINE__, __FILE__); } // end of try block @@ -470,7 +467,7 @@ test_file_name() issue_fail_msg(E.getCFuncName(), __LINE__, __FILE__, E.getCDetailMsg()); } -} /* test_file_name() */ +} // test_file_name() /*------------------------------------------------------------------------- @@ -490,14 +487,14 @@ test_file_name() void test_file(void) { - /* Output message about test being performed */ + // 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() */ + 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() /*------------------------------------------------------------------------- @@ -520,4 +517,4 @@ cleanup_file(void) remove(FILE2.c_str()); remove(FILE3.c_str()); remove(FILE4.c_str()); -} /* cleanup_file */ +} // cleanup_file |