diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2013-09-30 19:44:52 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2013-09-30 19:44:52 (GMT) |
commit | 467050b23dca60a1177b1fb7dc6e080709e08dac (patch) | |
tree | a97ed61b21df2f6eab3b12bd4a1e70f69c73780d /c++/test/tattr.cpp | |
parent | eccd41643b07c2e33b2c163cfc8c71a9f60a54d3 (diff) | |
download | hdf5-467050b23dca60a1177b1fb7dc6e080709e08dac.zip hdf5-467050b23dca60a1177b1fb7dc6e080709e08dac.tar.gz hdf5-467050b23dca60a1177b1fb7dc6e080709e08dac.tar.bz2 |
[svn-r24229] Purpose: Fix bug HDFFV-7520
Description:
Added wrappers for H5Aexists.
(merged from trunk)
Platforms Tested:
Linux/32 2.6 (jam)
Linux/64 2.6 (koala)
Linux/ppc64 (ostrich)
Diffstat (limited to 'c++/test/tattr.cpp')
-rw-r--r-- | c++/test/tattr.cpp | 76 |
1 files changed, 72 insertions, 4 deletions
diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index 6f7674d..3339bb3 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -252,14 +252,19 @@ static void test_attr_rename() int read_data1[ATTR1_DIM1]={0}; // Buffer for reading the attribute int i; - // Output message about test being performed - SUBTEST("Rename Attribute Function"); + // Output message about test being performed + SUBTEST("Checking for Existence and Renaming Attribute"); try { // Open file H5File fid1(FILE_BASIC, H5F_ACC_RDWR); - // Check rename of 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"); // Change attribute name fid1.renameAttr(FATTR1_NAME, FATTR_TMP_NAME); @@ -280,7 +285,12 @@ static void test_attr_rename() // Open the dataset DataSet dataset = fid1.openDataSet(DSET1_NAME); - // Check rename of 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"); // Change attribute name dataset.renameAttr(ATTR1_NAME, ATTR_TMP_NAME); @@ -303,6 +313,11 @@ static void test_attr_rename() // 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"); + // Open the second attribute Attribute attr2(dataset.openAttribute(ATTR2_NAME)); @@ -324,6 +339,11 @@ static void test_attr_rename() // 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"); + PASSED(); } // end try block @@ -1355,6 +1375,53 @@ static void test_string_attr() /**************************************************************** ** +** test_attr_exists(): Test checking for attribute existence. +** (additional attrExists tests are in test_attr_rename()) +** +****************************************************************/ +static void test_attr_exists() +{ + // Output message about test being performed + SUBTEST("Check Attribute Existence"); + + try { + // Open file. + H5File fid1(FILE_BASIC, H5F_ACC_RDWR); + + // 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 + 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); + + // 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(); + } // end try block + + catch (InvalidActionException E) { + issue_fail_msg("test_attr_exists()", __LINE__, __FILE__, E.getCDetailMsg()); + } + catch (Exception E) { + issue_fail_msg("test_attr_exists()", __LINE__, __FILE__, E.getCDetailMsg()); + } +} // test_attr_exists() + +/**************************************************************** +** ** test_attr(): Main attribute testing routine. ** ****************************************************************/ @@ -1384,6 +1451,7 @@ void test_attr() 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_attr() |