summaryrefslogtreecommitdiffstats
path: root/c++/test/tattr.cpp
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2009-04-21 22:46:38 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2009-04-21 22:46:38 (GMT)
commit5bb857476f99118cda0e54ea522f52933a582747 (patch)
tree741024b69250fe9166091aa8f28bc78c35d3fb64 /c++/test/tattr.cpp
parent35bbc743d4cf77d6aa8af2acf5578db02e5129ca (diff)
downloadhdf5-5bb857476f99118cda0e54ea522f52933a582747.zip
hdf5-5bb857476f99118cda0e54ea522f52933a582747.tar.gz
hdf5-5bb857476f99118cda0e54ea522f52933a582747.tar.bz2
[svn-r16825] Description:
Bring revisions 16636:16821 from trunk to revise_chunks branch Tested on: FreeBSD/32 6.3 (duty) Mac OS X/32 10.5.6 (amazon) (h5committest not needed on this branch)
Diffstat (limited to 'c++/test/tattr.cpp')
-rw-r--r--c++/test/tattr.cpp90
1 files changed, 80 insertions, 10 deletions
diff --git a/c++/test/tattr.cpp b/c++/test/tattr.cpp
index 73b5a91..48a3200 100644
--- a/c++/test/tattr.cpp
+++ b/c++/test/tattr.cpp
@@ -356,7 +356,7 @@ static void test_attr_basic_read()
for(i=0; i<ATTR2_DIM1; i++)
for(j=0; j<ATTR2_DIM2; j++)
if(attr_data2[i][j]!=read_data2[i][j]) {
- TestErrPrintf("%d: attribute data different: attr_data2[%d][%d]=%d, read_data2[%d][%d]=%d\n",__LINE__, i,j,attr_data2[i][j],i,j,read_data1[i]);
+ TestErrPrintf("%d: attribute data different: attr_data2[%d][%d]=%d, read_data2[%d][%d]=%d\n",__LINE__, i,j,attr_data2[i][j],i,j,read_data2[i][j]);
}
PASSED();
} // end try block
@@ -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,88 @@ 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_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);
+
+ // Read and verify the attribute string as a string of chars; buffer
+ // is dynamically allocated.
+ size_t attr_size = gr_flattr1.getInMemDataSize();
+ char *fl_dyn_string_att_check;
+ fl_dyn_string_att_check = new char[attr_size+1];
+ gr_flattr1.read(fls_type, fl_dyn_string_att_check);
+ if(HDstrcmp(fl_dyn_string_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(), fl_dyn_string_att_check);
+ delete []fl_dyn_string_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