summaryrefslogtreecommitdiffstats
path: root/test/dtypes.c
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2011-05-27 17:30:24 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2011-05-27 17:30:24 (GMT)
commit157623de6a3970f68d725d9dda0974c0ef6f67cd (patch)
tree0b73f16bbc6c3d85c6340ed484af37b9943c1a98 /test/dtypes.c
parentde14c332f9dc8535d435e19a2a43e7f9f0ff0e80 (diff)
downloadhdf5-157623de6a3970f68d725d9dda0974c0ef6f67cd.zip
hdf5-157623de6a3970f68d725d9dda0974c0ef6f67cd.tar.gz
hdf5-157623de6a3970f68d725d9dda0974c0ef6f67cd.tar.bz2
[svn-r20913] Issue 7579 - The overflowing ENUM values are inconsistent. When no conversion is involved in reading or writing the
data, overflowing values are retained. When conversion happens, the values become -1. The conversion function puts -1 when overflow happens. I added two new dataset transfer property to control whether to fill 0xff in the destination data or convert to the destination data when overflow happens. The two new functions are H5Pset(get)_enum_conv_overflow. I also added test cases in enum.c and dtypes.c. Tested on jam, koala, and heiwa.
Diffstat (limited to 'test/dtypes.c')
-rw-r--r--test/dtypes.c107
1 files changed, 106 insertions, 1 deletions
diff --git a/test/dtypes.c b/test/dtypes.c
index 51cfed2..fbb552d 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -4482,12 +4482,20 @@ error:
* Programmer: Robb Matzke, LLNL, 2003-06-09
*
* Modifications:
+ * Raymond Lu
+ * 26 May 2011
+ * I added a few overflowing values (beyond the range of enumerate
+ * values) to make sure the library retains these values. The test
+ * for overflowing values when no conversion happens is in
+ * test_noconv of enum.c.
*-------------------------------------------------------------------------
*/
static int
test_conv_enum_2(void)
{
hid_t srctype=-1, dsttype=-1, oddsize=-1;
+ hid_t dxpl_id=-1;
+ hbool_t conv_overflow;
int *data=NULL, i, nerrors=0;
const char *mname[] = { "RED",
"GREEN",
@@ -4497,7 +4505,7 @@ test_conv_enum_2(void)
"PURPLE",
"ORANGE",
"WHITE" };
-
+
TESTING("non-native enumeration type conversion");
/* Source enum type */
@@ -4539,11 +4547,108 @@ test_conv_enum_2(void)
}
}
+ /* Now make the source data overflow and see the conversion retain the original values by default.
+ * The initialization makes the first 128 values be -1, -2, -3,..., -128. In hexadecimal,
+ * they are 0xffffff, 0xfffffe, 0xfffffd,..., 0xffff7f. The rest values are between 0
+ * and 127. */
+ for (i=0; i<NTESTELEM; i++) {
+ if(i > 127) {
+ ((char*)data)[i*3+2] = i % 128;
+ ((char*)data)[i*3+0] = 0;
+ ((char*)data)[i*3+1] = 0;
+ } else {
+ ((char*)data)[i*3+2] = -(i+1);
+ ((char*)data)[i*3+0] = -1;
+ ((char*)data)[i*3+1] = -1;
+ }
+ }
+
+ /* Convert to destination type */
+ H5Tconvert(srctype, dsttype, (size_t)NTESTELEM, data, NULL, H5P_DEFAULT);
+
+ /* Check results */
+ for (i=0; i<NTESTELEM; i++) {
+ if(i > 127) {
+ if (data[i] != i%128) {
+ if (!nerrors++) {
+ H5_FAILED();
+ printf("element %d is %d but should have been %d\n",
+ i, data[i], i%128);
+ }
+ }
+ } else {
+ if (data[i] != -(i+1)) {
+ if (!nerrors++) {
+ H5_FAILED();
+ printf("element %d is %d but should have been %d\n",
+ i, data[i], -(i+1));
+ }
+ }
+ }
+ }
+
+ /* Now make the source data overflow and set the property for handling overflowing data to fill them
+ * them with 0xff (-1). The initialization makes the first 128 values be -1, -2, -3,..., -128. In
+ * hexadecimal, they are 0xffffff, 0xfffffe, 0xfffffd,..., 0xffff7f. The next 128 values are 128 to
+ * 255. The rest values are between 0 and 7. */
+ for (i=0; i<NTESTELEM; i++) {
+ if(i > 255) {
+ ((char*)data)[i*3+2] = i % 8;
+ ((char*)data)[i*3+0] = 0;
+ ((char*)data)[i*3+1] = 0;
+ } else if(i > 127) {
+ ((char*)data)[i*3+2] = i;
+ ((char*)data)[i*3+0] = 0;
+ ((char*)data)[i*3+1] = 0;
+
+ } else {
+ ((char*)data)[i*3+2] = -(i+1);
+ ((char*)data)[i*3+0] = -1;
+ ((char*)data)[i*3+1] = -1;
+ }
+ }
+
+ /* Set the property for handling overflowing data */
+ dxpl_id = H5Pcreate(H5P_DATASET_XFER);
+
+ /* First verify it's TRUE by default */
+ H5Pget_enum_conv_overflow(dxpl_id, &conv_overflow);
+ if(!conv_overflow)
+ nerrors++;
+
+ /* Then set it to FALSE */
+ H5Pset_enum_conv_overflow(dxpl_id, FALSE);
+
+ /* Convert to destination type */
+ H5Tconvert(srctype, dsttype, (size_t)NTESTELEM, data, NULL, dxpl_id);
+
+ /* Check results. All overflowing values should turn to -1. */
+ for (i=0; i<NTESTELEM; i++) {
+ if(i > 255) {
+ if (data[i] != i%8) {
+ if (!nerrors++) {
+ H5_FAILED();
+ printf("element %d is %d but should have been %d\n",
+ i, data[i], i%8);
+ }
+ }
+ } else {
+ if (data[i] != -1) {
+ if (!nerrors++) {
+ H5_FAILED();
+ printf("element %d is %d but should have been -1\n",
+ i, data[i]);
+ }
+ }
+ }
+ }
+
/* Cleanup */
free(data);
H5Tclose(srctype);
H5Tclose(dsttype);
H5Tclose(oddsize);
+ H5Pclose(dxpl_id);
/* Failure */
if (nerrors) {