summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/dtypes.c107
-rw-r--r--test/enum.c22
2 files changed, 121 insertions, 8 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) {
diff --git a/test/enum.c b/test/enum.c
index e9f607d..df3ae3d 100644
--- a/test/enum.c
+++ b/test/enum.c
@@ -26,11 +26,13 @@ const char *FILENAME[] = {
};
typedef enum {
- E1_RED,
- E1_GREEN,
- E1_BLUE,
- E1_WHITE,
- E1_BLACK
+ E1_ERROR = -1,
+ E1_RED = 0,
+ E1_GREEN = 1,
+ E1_BLUE = 2,
+ E1_WHITE = 3,
+ E1_BLACK = 4,
+ E1_NO_COLOR
} c_e1;
@@ -121,7 +123,12 @@ test_named(hid_t file)
* Monday, January 4, 1999
*
* 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 conversion happens is in the
+ * test_conv_enum_2() of dtypes.c.
*-------------------------------------------------------------------------
*/
static int
@@ -132,7 +139,8 @@ test_noconv(hid_t file)
static c_e1 data1[]={E1_RED, E1_GREEN, E1_BLUE, E1_GREEN, E1_WHITE,
E1_WHITE, E1_BLACK, E1_GREEN, E1_BLUE, E1_RED,
E1_RED, E1_BLUE, E1_GREEN, E1_BLACK, E1_WHITE,
- E1_RED, E1_WHITE, E1_GREEN, E1_GREEN, E1_BLUE};
+ E1_RED, E1_WHITE, E1_GREEN, E1_GREEN, E1_BLUE,
+ E1_ERROR, E1_ERROR, E1_NO_COLOR, E1_NO_COLOR, E1_NO_COLOR};
c_e1 data2[NELMTS(data1)];
hsize_t ds_size[1]={NELMTS(data1)};
size_t i;