summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorRaymond Lu <songyulu@hdfgroup.org>2010-01-20 20:41:23 (GMT)
committerRaymond Lu <songyulu@hdfgroup.org>2010-01-20 20:41:23 (GMT)
commit75f65c15836248688110342528629039e40c1cd0 (patch)
tree3e51865c389ec58c8745403630b1538579a9b222 /test
parent1e25bc217fca043e1b5c77e9f538c506c11be7af (diff)
downloadhdf5-75f65c15836248688110342528629039e40c1cd0.zip
hdf5-75f65c15836248688110342528629039e40c1cd0.tar.gz
hdf5-75f65c15836248688110342528629039e40c1cd0.tar.bz2
[svn-r18125] I added the support of bitfield in H5Tget_native_type. Bitfield is similar to unsigned
integer. I also added a test. Tested on jam. But I tested the same change for 1.8 with h5committest.
Diffstat (limited to 'test')
-rw-r--r--test/dtypes.c13
-rw-r--r--test/ntypes.c120
2 files changed, 91 insertions, 42 deletions
diff --git a/test/dtypes.c b/test/dtypes.c
index 04f526a..020a603 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -4496,7 +4496,7 @@ test_conv_bitfield(void)
static int
test_bitfield_funcs(void)
{
- hid_t type=-1, super=-1;
+ hid_t type=-1, ntype=-1, super=-1;
int size;
char* tag;
H5T_pad_t inpad;
@@ -4521,6 +4521,7 @@ test_bitfield_funcs(void)
if(H5Tset_pad(type, H5T_PAD_ONE, H5T_PAD_ONE)) goto error;
if((size=H5Tget_size(type))==0) goto error;
if(H5Tset_order(type, H5T_ORDER_BE) < 0) goto error;
+ if((ntype = H5Tget_native_type(type, H5T_DIR_ASCEND)) < 0) goto error;
H5E_BEGIN_TRY {
size=H5Tget_ebias(type);
@@ -4585,16 +4586,8 @@ test_bitfield_funcs(void)
goto error;
} /* end if */
- H5E_BEGIN_TRY {
- super = H5Tget_native_type(type, H5T_DIR_ASCEND);
- } H5E_END_TRY;
- if (super>=0) {
- H5_FAILED();
- printf("Operation not allowed for this type.\n");
- goto error;
- } /* end if */
-
H5Tclose(type);
+ H5Tclose(ntype);
PASSED();
reset_hdf5();
return 0;
diff --git a/test/ntypes.c b/test/ntypes.c
index 87484d9..6efabc6 100644
--- a/test/ntypes.c
+++ b/test/ntypes.c
@@ -52,14 +52,15 @@ int ipoints3[DIM0][DIM1][5], icheck3[DIM0][DIM1][5];
#define DSET_VLSTR_NAME "vlstr_type"
#define DSET_STR_NAME "str_type"
#define DSET_OPAQUE_NAME "opaque_type"
-#define DSET_BITFIELD_NAME "bitfield_type"
+#define DSET1_BITFIELD_NAME "bitfield_type_1"
+#define DSET2_BITFIELD_NAME "bitfield_type_2"
#define SPACE1_DIM1 4
#define SPACE1_RANK 1
#define SPACE2_RANK 2
#define SPACE2_DIM1 10
#define SPACE2_DIM2 10
-
+#define BITFIELD_ENUMB 8
/*-------------------------------------------------------------------------
@@ -2519,53 +2520,106 @@ error:
* October 15, 2002
*
* Modifications:
- *
+ * Raymond Lu
+ * 1 December 2009
+ * I added the support for bitfield and changed the test to
+ * compare the data being read back.
*-------------------------------------------------------------------------
*/
static herr_t
test_bitfield_dtype(hid_t file)
{
- hid_t type = -1, space = -1, dset = -1;
- hid_t dataset = -1, dtype = -1, native_type = -1;
- size_t i;
- unsigned char wbuf[32];
- hsize_t nelmts;
+ hid_t type=-1, space=-1, dset1=-1, dset2=-1;
+ hid_t dataset1=-1, dataset2=-1, dtype=-1, native_type=-1;
+ size_t ntype_size, i;
+ unsigned char wbuf[BITFIELD_ENUMB*sizeof(int)];
+ unsigned char *p=NULL;
+ void *rbuf = NULL;
+ unsigned int intw[BITFIELD_ENUMB], intr[BITFIELD_ENUMB];
+ hsize_t nelmts;
TESTING("bitfield datatype");
- /* opaque_1 */
- nelmts = sizeof(wbuf);
- if((type = H5Tcopy(H5T_STD_B8LE)) < 0) TEST_ERROR;
+ nelmts = BITFIELD_ENUMB;
+ if((type = H5Tcopy(H5T_STD_B32BE)) < 0) TEST_ERROR;
+
if((space = H5Screate_simple(1, &nelmts, NULL)) < 0) TEST_ERROR;
- if((dset = H5Dcreate2(file, DSET_BITFIELD_NAME, type, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
- TEST_ERROR;
- for(i = 0; i < sizeof(wbuf); i++)
- wbuf[i] = (unsigned char)0xff ^ (unsigned char)i;
+ /* Create and write to dataset1 with a unsigned char buffer */
+ if((dset1 = H5Dcreate2(file, DSET1_BITFIELD_NAME, type, space, H5P_DEFAULT, H5P_DEFAULT,
+ H5P_DEFAULT)) < 0) TEST_ERROR;
- if(H5Dwrite(dset, type, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf) < 0) TEST_ERROR;
+ for(i = 0; i < BITFIELD_ENUMB*sizeof(int); i++)
+ wbuf[i] = (unsigned int)0xff ^ (unsigned int)i;
+
+ if(H5Dwrite(dset1, H5T_NATIVE_B32, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf) < 0) TEST_ERROR;
+ if(H5Dclose(dset1) < 0) TEST_ERROR;
+
+ /* Create and write to dataset2 with a unsigned int buffer */
+ if((dset2 = H5Dcreate2(file, DSET2_BITFIELD_NAME, type, space, H5P_DEFAULT, H5P_DEFAULT,
+ H5P_DEFAULT)) < 0) TEST_ERROR;
+
+ for(i = 0; i < BITFIELD_ENUMB; i++)
+ intw[i] = (unsigned int)0xff << (unsigned int)((i*8)%32);
+
+ if(H5Dwrite(dset2, H5T_NATIVE_B32, H5S_ALL, H5S_ALL, H5P_DEFAULT, intw) < 0) TEST_ERROR;
+ if(H5Dclose(dset2) < 0) TEST_ERROR;
if(H5Sclose(space) < 0) TEST_ERROR;
- if(H5Dclose(dset) < 0) TEST_ERROR;
+ if(H5Tclose(type) < 0) TEST_ERROR;
+ /* Open dataset1 again to check H5Tget_native_type */
+ if((dataset1 = H5Dopen2(file, DSET1_BITFIELD_NAME, H5P_DEFAULT)) < 0) TEST_ERROR;
- /* Open dataset again to check H5Tget_native_type */
- if((dataset = H5Dopen2(file, DSET_BITFIELD_NAME, H5P_DEFAULT)) < 0) TEST_ERROR;
+ if((dtype = H5Dget_type(dataset1)) < 0) TEST_ERROR;
- if((dtype = H5Dget_type(dataset)) < 0) TEST_ERROR;
+ if((native_type = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) TEST_ERROR;
- H5E_BEGIN_TRY {
- native_type = H5Tget_native_type(dtype, H5T_DIR_DEFAULT);
- } H5E_END_TRY;
- if(native_type > 0) {
- H5_FAILED();
- puts(" Bit field isn't supported. Should have failed.");
- TEST_ERROR;
- } /* end if */
+ if((ntype_size = H5Tget_size(native_type)) == 0) TEST_ERROR;
+
+ rbuf = malloc((size_t)nelmts*ntype_size);
+
+ /* Read the data and compare them */
+ if(H5Dread(dataset1, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf) < 0) TEST_ERROR;
+
+ p = (unsigned int*)rbuf;
+ for(i = 0; i < BITFIELD_ENUMB*4; i++) {
+ if(*p != wbuf[i]) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d\n", i);
+ TEST_ERROR;
+ }
+ p++;
+ }
- if(H5Tclose(type) < 0) TEST_ERROR;
if(H5Tclose(dtype) < 0) TEST_ERROR;
- if(H5Dclose(dataset) < 0) TEST_ERROR;
+ if(H5Tclose(native_type) < 0) TEST_ERROR;
+ if(H5Dclose(dataset1) < 0) TEST_ERROR;
+ if(rbuf) free(rbuf);
+
+ /* Open dataset2 again to check H5Tget_native_type */
+ if((dataset2 = H5Dopen2(file, DSET2_BITFIELD_NAME, H5P_DEFAULT)) < 0) TEST_ERROR;
+
+ if((dtype = H5Dget_type(dataset2)) < 0) TEST_ERROR;
+
+ if((native_type = H5Tget_native_type(dtype, H5T_DIR_DEFAULT)) < 0) TEST_ERROR;
+ /* Read the data and compare them */
+ if(H5Dread(dataset2, native_type, H5S_ALL, H5S_ALL, H5P_DEFAULT, intr) < 0) TEST_ERROR;
+
+ for(i = 0; i < BITFIELD_ENUMB; i++) {
+ if(intr[i] != intw[i]) {
+ H5_FAILED();
+ printf(" Read different values than written.\n");
+ printf(" At index %d\n", i);
+ TEST_ERROR;
+ }
+ }
+
+ if(H5Tclose(dtype) < 0) TEST_ERROR;
+ if(H5Tclose(native_type) < 0) TEST_ERROR;
+ if(H5Dclose(dataset2) < 0) TEST_ERROR;
+
PASSED();
return 0;
@@ -2575,8 +2629,10 @@ error:
H5Tclose(type);
H5Tclose(dtype);
H5Tclose(native_type);
- H5Dclose(dset);
- H5Dclose(dataset);
+ H5Dclose(dset1);
+ H5Dclose(dset2);
+ H5Dclose(dataset1);
+ H5Dclose(dataset2);
} H5E_END_TRY;
return -1;