summaryrefslogtreecommitdiffstats
path: root/c++/test
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2013-03-23 17:37:49 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2013-03-23 17:37:49 (GMT)
commit1f6cd26a93875c34d3a43921fe0d9637879b15ae (patch)
treeb87d0d0885d80240d9db183c7bb99740fb1e13d2 /c++/test
parent5c459618453c684cd7bcd8c2b8117bb3e6ad1b27 (diff)
downloadhdf5-1f6cd26a93875c34d3a43921fe0d9637879b15ae.zip
hdf5-1f6cd26a93875c34d3a43921fe0d9637879b15ae.tar.gz
hdf5-1f6cd26a93875c34d3a43921fe0d9637879b15ae.tar.bz2
[svn-r23438] Purpose: Fix bug HDFFV-7520
Description: Added wrappers for H5Aexists. Platforms Tested: Linux/32 2.6 (jam) Linux/64 2.6 (koala) Linux/ppc64 (ostrich)
Diffstat (limited to 'c++/test')
-rw-r--r--c++/test/tattr.cpp76
1 files changed, 72 insertions, 4 deletions
diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp
index 1a15aea..7e77e85 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
@@ -1354,6 +1374,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.
**
****************************************************************/
@@ -1382,6 +1449,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()