summaryrefslogtreecommitdiffstats
path: root/test/tattr.c
diff options
context:
space:
mode:
authorJames Laird <jlaird@hdfgroup.org>2006-01-02 19:20:19 (GMT)
committerJames Laird <jlaird@hdfgroup.org>2006-01-02 19:20:19 (GMT)
commit216a6e99047f32a8cdf857f6cf3b195d605549a1 (patch)
tree8f48cea87963afad81a38fd70edb45238848299e /test/tattr.c
parent63e522aa138db60749a97f0d6896934b8a6d338c (diff)
downloadhdf5-216a6e99047f32a8cdf857f6cf3b195d605549a1.zip
hdf5-216a6e99047f32a8cdf857f6cf3b195d605549a1.tar.gz
hdf5-216a6e99047f32a8cdf857f6cf3b195d605549a1.tar.bz2
[svn-r11850] Purpose:
Feature Description: Added character encoding and attribute creation property lists. Solution: Attributes' character encoding is set via the ACPL. The default is ASCII, with UTF-8 being the other option currently. Platforms tested: heping, mir, sleipnir, copper
Diffstat (limited to 'test/tattr.c')
-rw-r--r--test/tattr.c118
1 files changed, 117 insertions, 1 deletions
diff --git a/test/tattr.c b/test/tattr.c
index dc82190..2363401 100644
--- a/test/tattr.c
+++ b/test/tattr.c
@@ -457,7 +457,120 @@ test_attr_flush(void)
CHECK(ret, FAIL, "H5Dclose");
ret=H5Fclose(fil);
CHECK(ret, FAIL, "H5Fclose");
-} /* test_attr_basic_flush() */
+} /* test_attr_flush() */
+
+/****************************************************************
+**
+** test_attr_plist(): Test Attribute Creation Property Lists
+**
+****************************************************************/
+static void
+test_attr_plist(void)
+{
+ hid_t fid1; /* HDF5 File IDs */
+ hid_t dataset; /* Dataset ID */
+ hid_t sid1,sid2; /* Dataspace ID */
+ hid_t attr; /* Attribute ID */
+ hid_t plist; /* Property list ID */
+ char *attr_name=NULL; /* name of attribute */
+ hsize_t dims1[] = {SPACE1_DIM1, SPACE1_DIM2, SPACE1_DIM3};
+ hsize_t dims2[] = {ATTR1_DIM1};
+ H5T_cset_t cset; /* Character set for attributes */
+ herr_t ret; /* Generic return value */
+
+ /* Output message about test being performed */
+ MESSAGE(5, ("Testing Attribute Property Lists\n"));
+
+ /* Create file */
+ fid1 = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ CHECK(fid1, FAIL, "H5Fcreate");
+
+ /* Create dataspace for dataset */
+ sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
+ CHECK(sid1, FAIL, "H5Screate_simple");
+
+ /* Create a dataset */
+ dataset=H5Dcreate(fid1,DSET1_NAME,H5T_NATIVE_UCHAR,sid1,H5P_DEFAULT);
+ CHECK(dataset, FAIL, "H5Dcreate");
+
+ /* Create dataspace for attribute */
+ sid2 = H5Screate_simple(ATTR1_RANK, dims2, NULL);
+ CHECK(sid2, FAIL, "H5Screate_simple");
+
+ /* Create default property list for attribute */
+ plist = H5Pcreate(H5P_ATTRIBUTE_CREATE);
+ CHECK(plist, FAIL, "H5Pcreate");
+
+ /* Get the character encoding and ensure that it is the default (ASCII) */
+ ret = H5Pget_char_encoding(plist, &cset);
+ CHECK(ret, FAIL, "H5Pget_char_encoding");
+ VERIFY(cset, H5T_CSET_ASCII, "H5Pget_char_encoding");
+
+ /* Create an attribute for the dataset using the property list */
+ attr=H5Acreate(dataset,ATTR1_NAME,H5T_NATIVE_INT,sid2,plist);
+ CHECK(attr, FAIL, "H5Acreate");
+
+ /* Close the property list, and get the attribute's property list */
+ ret = H5Pclose(plist);
+ CHECK(ret, FAIL, "H5Pclose");
+ plist = H5Aget_create_plist(attr);
+ CHECK(plist, FAIL, "H5Aget_create_plist");
+
+ /* Get the character encoding and ensure that it is the default (ASCII) */
+ ret = H5Pget_char_encoding(plist, &cset);
+ CHECK(ret, FAIL, "H5Pget_char_encoding");
+ VERIFY(cset, H5T_CSET_ASCII, "H5Pget_char_encoding");
+
+ /* Close the property list and attribute */
+ ret = H5Pclose(plist);
+ CHECK(ret, FAIL, "H5Pclose");
+ ret = H5Aclose(attr);
+ CHECK(ret, FAIL, "H5Aclose");
+
+ /* Create a new property list and modify it to use a different encoding */
+ plist = H5Pcreate(H5P_ATTRIBUTE_CREATE);
+ CHECK(plist, FAIL, "H5Pcreate");
+ ret=H5Pset_char_encoding(plist, H5T_CSET_UTF8);
+ CHECK(ret, FAIL, "H5Pset_char_encoding");
+
+ /* Get the character encoding and ensure that it has been changed */
+ ret = H5Pget_char_encoding(plist, &cset);
+ CHECK(ret, FAIL, "H5Pget_char_encoding");
+ VERIFY(cset, H5T_CSET_UTF8, "H5Pget_char_encoding");
+
+ /* Create an attribute for the dataset using the modified property list */
+ attr=H5Acreate(dataset,ATTR2_NAME,H5T_NATIVE_INT,sid2,plist);
+ CHECK(attr, FAIL, "H5Acreate");
+
+ /* Close the property list and attribute */
+ ret = H5Pclose(plist);
+ CHECK(ret, FAIL, "H5Pclose");
+ ret = H5Aclose(attr);
+ CHECK(ret, FAIL, "H5Aclose");
+
+ /* Re-open the second attribute and ensure that its character encoding is correct */
+ attr = H5Aopen_name(dataset, ATTR2_NAME);
+ CHECK(attr, FAIL, "H5Aopen_name");
+ plist = H5Aget_create_plist(attr);
+ CHECK(plist, FAIL, "H5Aget_create_plist");
+ ret = H5Pget_char_encoding(plist, &cset);
+ CHECK(ret, FAIL, "H5Pget_char_encoding");
+ VERIFY(cset, H5T_CSET_UTF8, "H5Pget_char_encoding");
+
+ /* Close everything */
+ ret=H5Sclose(sid1);
+ CHECK(ret, FAIL, "H5Sclose");
+ ret=H5Sclose(sid2);
+ CHECK(ret, FAIL, "H5Sclose");
+ ret = H5Pclose(plist);
+ CHECK(ret, FAIL, "H5Pclose");
+ ret=H5Aclose(attr);
+ CHECK(ret, FAIL, "H5Aclose");
+ ret=H5Dclose(dataset);
+ CHECK(ret, FAIL, "H5Dclose");
+ ret=H5Fclose(fid1);
+ CHECK(ret, FAIL, "H5Fclose");
+} /* test_attr_plist() */
/****************************************************************
**
@@ -1571,6 +1684,9 @@ test_attr(void)
test_attr_basic_read(); /* Test basic H5A reading code */
test_attr_flush(); /* Test H5A I/O in the presence of H5Fflush calls */
+ /* This next test uses the same file information */
+ test_attr_plist(); /* Test attribute property lists */
+
/* These next two tests use the same file information */
test_attr_compound_write(); /* Test complex datatype H5A writing code */
test_attr_compound_read(); /* Test complex datatype H5A reading code */