summaryrefslogtreecommitdiffstats
path: root/c++/test
diff options
context:
space:
mode:
authorBinh-Minh Ribler <bmribler@hdfgroup.org>2009-04-19 04:35:19 (GMT)
committerBinh-Minh Ribler <bmribler@hdfgroup.org>2009-04-19 04:35:19 (GMT)
commitaa775d9738f0f56eef7dd5f1ee75179daffa16fa (patch)
tree718ffc58dd2a7a4358691896cd89d565bc7d0213 /c++/test
parentceffce7203e466d3262be30e8470ccdf1826a5de (diff)
downloadhdf5-aa775d9738f0f56eef7dd5f1ee75179daffa16fa.zip
hdf5-aa775d9738f0f56eef7dd5f1ee75179daffa16fa.tar.gz
hdf5-aa775d9738f0f56eef7dd5f1ee75179daffa16fa.tar.bz2
[svn-r16787] 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) SunOS 5.10 (linew)
Diffstat (limited to 'c++/test')
-rw-r--r--c++/test/tattr.cpp78
1 files changed, 69 insertions, 9 deletions
diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp
index 73b5a91..fc39c2b 100644
--- a/c++/test/tattr.cpp
+++ b/c++/test/tattr.cpp
@@ -1180,20 +1180,26 @@ static void test_attr_dtype_shared()
**
****************************************************************/
/* 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()
{
// Output message about test being performed
- SUBTEST("Testing Basic Attribute Writing 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("/");
@@ -1201,24 +1207,78 @@ static void test_string_attr()
// 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_attr = root.createAttribute(ATTRSTR_NAME, type, att_space);
+ Attribute gr_flattr1 = root.createAttribute(ATTR1_FL_STR_NAME, fls_type, att_space);
// Write data to the attribute.
- gr_attr.write(type, ATTRSTR_DATA);
+ 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_vlattr = root.createAttribute(ATTR_VL_STR_NAME, vls_type, att_space);
+
+ // Write data to the attribute.
+ 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