diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2014-04-01 05:59:37 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2014-04-01 05:59:37 (GMT) |
commit | 0fcac5670573e802100c2a099cdc6eb8af229d12 (patch) | |
tree | ea32d7a50dd8daa24f72d90333ea08e9ab3aca61 /c++/test | |
parent | d01ee66666f4cad8e5f3f67a51a5774adcc03e45 (diff) | |
download | hdf5-0fcac5670573e802100c2a099cdc6eb8af229d12.zip hdf5-0fcac5670573e802100c2a099cdc6eb8af229d12.tar.gz hdf5-0fcac5670573e802100c2a099cdc6eb8af229d12.tar.bz2 |
[svn-r24938] Description:
- Overloaded Atribute::getName to take a char* for the attribute name:
ssize_t Attribute::getName(char* attr_name, size_t buf_size)
- Switched the arguments in this function:
ssize_t getName(size_t buf_size, H5std_string& attr_name)
so it became:
ssize_t getName(H5std_string& attr_name, size_t buf_size)
The second argument is default to 0, and can be skipped.
- Removed this function:
H5std_string getName(size_t buf_size); it'll collide with the
first function when that function takes a NULL for the first
argument, and uses default value for the second argument.
- Added more tests
Platforms tested:
Linux/ppc64 (ostrich)
Linux/32 2.6 (jam)
SunOS 5.11 (emu)
Diffstat (limited to 'c++/test')
-rw-r--r-- | c++/test/tattr.cpp | 118 |
1 files changed, 118 insertions, 0 deletions
diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index 7e77e85..e2e347b 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -244,6 +244,123 @@ static void test_attr_basic_write() /**************************************************************** ** +** test_attr_getname(): Test getting attribute name functions. +** +** Test these functions: +** A. ssize_t Attribute::getName(char* attr_name, size_t buf_size) +** 1. With arbitrary buf_size that is larger than the name size +** 2. With arbitrary buf_size that is smaller than the name's length. +** 3. With a buf_size that equals the name's length. +** +** B. ssize_t Attribute::getName(H5std_string& attr_name, size_t buf_size) +** With buffer smaller than the actual name +** +** C. H5std_string Attribute::getName() with file's and dataset's attrs. +** +** D. 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 +** +****************************************************************/ +static void test_attr_getname() +{ + // Output message about test being performed + 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); + 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); + 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); + 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); + + // 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__); + + // + // Open the dataset DSET1_NAME and test getName with its attribute + // + + // 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)); + + // Get dataset attribute's name with + // H5std_string Attribute::getName() + H5std_string dattr_name1 = attr1.getName(); + verify_val(dattr_name1, ATTR1_NAME, "Attribute::getName", __LINE__, __FILE__); + + // D. Get 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()); + } +} // test_attr_getname() + +/**************************************************************** +** ** test_attr_rename(): Test renaming attribute function. ** ****************************************************************/ @@ -1433,6 +1550,7 @@ void test_attr() MESSAGE(5, ("Testing Attributes\n")); 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 |