diff options
author | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2009-07-22 04:12:48 (GMT) |
---|---|---|
committer | Binh-Minh Ribler <bmribler@hdfgroup.org> | 2009-07-22 04:12:48 (GMT) |
commit | b88498636fa193053676accb2c3bde278cb08ef5 (patch) | |
tree | 3016f2bb729f5f7f7edc72dd36fac8de419a87ef /c++/test/tvlstr.cpp | |
parent | 3cbb84471a8c2e4b0500cfec3514512656fc2bc7 (diff) | |
download | hdf5-b88498636fa193053676accb2c3bde278cb08ef5.zip hdf5-b88498636fa193053676accb2c3bde278cb08ef5.tar.gz hdf5-b88498636fa193053676accb2c3bde278cb08ef5.tar.bz2 |
[svn-r17219] Purpose: Improve readability
Description:
Divided Attribute::read into specific private functions for fixed-
and variable-len string data: p_read_fixed_len and p_read_variable_len.
Added test to write/read array of strings to attributes.
Platforms tested:
Linux/32 2.6 (jam)
FreeBSD/64 6.3 (liberty)
SunOS 5.10 (linew)
Diffstat (limited to 'c++/test/tvlstr.cpp')
-rw-r--r-- | c++/test/tvlstr.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/c++/test/tvlstr.cpp b/c++/test/tvlstr.cpp index 7f6c8d8..34e1d74 100644 --- a/c++/test/tvlstr.cpp +++ b/c++/test/tvlstr.cpp @@ -671,6 +671,77 @@ static void test_read_vl_string_attribute() } } // test_read_vl_string_attribute + +/*------------------------------------------------------------------------- + * Function: test_vl_stringarray_attribute + * + * Purpose: Test writing/reading VL string array to/from attributes. + * + * Return: None + * + * Programmer: Binh-Minh Ribler + * July, 2009 + * + *------------------------------------------------------------------------- + */ +const H5std_string ATTRSTRARR_NAME("StringArray_attr"); + +static void test_vl_stringarray_attribute() +{ + const char *string_att_array[SPACE1_DIM1]= { + "Line 1", "Line 2", "Line 3", "Line 4" + }; // Information to write + + // Output message about test being performed + SUBTEST("Testing writing/reading VL String Array on attribute"); + + try { + // Open the file + H5File file1(FILENAME, H5F_ACC_RDWR); + + // Create a datatype to refer to. + StrType tid1(0, H5T_VARIABLE); + + // Open the root group. + Group root = file1.openGroup("/"); + + // Create dataspace for datasets. + hsize_t dims1[] = {SPACE1_DIM1}; + DataSpace att_space(SPACE1_RANK, dims1); + + // Create an attribute for the root group. + Attribute gr_attr = root.createAttribute(ATTRSTRARR_NAME, tid1, att_space); + + // Write data to the attribute. + gr_attr.write(tid1, string_att_array); + + // Read and verify the attribute string as a string of chars. + // Note: reading by array of H5std_string doesn't work yet. + char *string_att_check[SPACE1_DIM1]; + gr_attr.read(tid1, &string_att_check); + + int ii; + for (ii = 0; ii < SPACE1_DIM1; ii++) + { + if(HDstrcmp(string_att_check[ii], string_att_array[ii])!=0) + TestErrPrintf("Line %d: Attribute data different: written=%s,read=%s\n",__LINE__, string_att_check[ii], string_att_check[ii]); + + HDfree(string_att_check[ii]); // note: no need for std::string test + } + + // Close group's attribute. + gr_attr.close(); + file1.close(); + + PASSED(); + } // end try block + + // Catch all exceptions. + catch (Exception E) { + issue_fail_msg("test_string_attr()", __LINE__, __FILE__, E.getCDetailMsg()); + } +} // test_vl_stringarray_attribute() + /* Helper routine for test_vl_rewrite() */ static void write_scalar_dset(H5File& file, DataType& type, DataSpace& space, char *name, char *data) @@ -824,6 +895,9 @@ void test_vlstrings() test_write_vl_string_attribute(); test_read_vl_string_attribute(); + // Test using VL string array in attributes + test_vl_stringarray_attribute(); + // Test writing VL datasets in files with lots of unlinking test_vl_rewrite(); |