diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2009-04-20 06:03:41 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2009-04-20 06:03:41 (GMT) |
commit | 637280023566692eb5115fc303fcfa18a04f09e2 (patch) | |
tree | c913c2f546c911897a8cf49f0414ee790b5731b0 | |
parent | 30a170379210b8ec5e466f6c899d945264313003 (diff) | |
download | hdf5-637280023566692eb5115fc303fcfa18a04f09e2.zip hdf5-637280023566692eb5115fc303fcfa18a04f09e2.tar.gz hdf5-637280023566692eb5115fc303fcfa18a04f09e2.tar.bz2 |
[svn-r16794] Description:
Fixed to pass parameters to H5Awrite/H5Aread correctly so that
all Attribute::write and Attribute::read methods work correctly
for both fixed-length and variable-length string attributes.
Added more test cases.
Platforms tested:
Linux/32 2.6 (jam)
FreeBSD/64 6.3 (liberty)
-rw-r--r-- | c++/test/tattr.cpp | 78 |
1 files changed, 69 insertions, 9 deletions
diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp index 74b68ea..00adb84 100644 --- a/c++/test/tattr.cpp +++ b/c++/test/tattr.cpp @@ -1166,20 +1166,26 @@ static void test_attr_dtype_shared(void) ** ****************************************************************/ /* Info for a string attribute */ -const H5std_string ATTRSTR_NAME("String_attr"); +const H5std_string ATTR1_FL_STR_NAME("String_attr 1"); +const H5std_string ATTR2_FL_STR_NAME("String_attr 2"); +const H5std_string ATTR_VL_STR_NAME("String_attr"); const H5std_string ATTRSTR_DATA("String Attribute"); +const int ATTR_LEN = 17; static void test_string_attr(void) { // Output message about test being performed - SUBTEST("Testing String Attribute Functions"); + SUBTEST("Testing I/O on FL and VL String Attributes"); try { // Create file H5File fid1(FILENAME, H5F_ACC_RDWR); - // Create a variable length string datatype to refer to. - StrType type(0, H5T_VARIABLE); + // + // 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("/"); @@ -1187,24 +1193,78 @@ static void test_string_attr(void) // 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); + + /* 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_attr = root.createAttribute(ATTRSTR_NAME, type, att_space); + Attribute gr_vlattr = root.createAttribute(ATTR_VL_STR_NAME, vls_type, att_space); // Write data to the attribute. - gr_attr.write(type, ATTRSTR_DATA); + 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_attr.read(type, &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_attr.read(type, 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 |