summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/dtypes.c264
1 files changed, 264 insertions, 0 deletions
diff --git a/test/dtypes.c b/test/dtypes.c
index 0d7a000..444a0a7 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -66,6 +66,7 @@ const char *FILENAME[] = {
"dtypes4",
"dtypes5",
"dtypes6",
+ "dtypes7",
NULL
};
@@ -2365,6 +2366,265 @@ test_query(void)
/*-------------------------------------------------------------------------
+ * Function: test_derived_flt
+ *
+ * Purpose: Tests user-define and query functions of floating-point types.
+ *
+ * Return: Success: 0
+ *
+ * Failure: number of errors
+ *
+ * Programmer: Raymond Lu
+ * Thursday, Jan 6, 2005
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_derived_flt(void)
+{
+ hid_t file=-1, tid1=-1, tid2=-1;
+ char filename[1024];
+ size_t precision, spos, epos, esize, mpos, msize, size, ebias;
+ int offset;
+
+ TESTING("user-define and query functions of floating-point types");
+
+ /* Create File */
+ h5_fixname(FILENAME[6], H5P_DEFAULT, filename, sizeof filename);
+ if((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) {
+ H5_FAILED();
+ printf("Can't create file\n");
+ goto error;
+ }
+
+ if((tid1 = H5Tcopy(H5T_IEEE_F64LE))<0) {
+ H5_FAILED();
+ printf("Can't copy data type\n");
+ goto error;
+ }
+
+ if((tid2 = H5Tcopy(H5T_IEEE_F32LE))<0) {
+ H5_FAILED();
+ printf("Can't copy data type\n");
+ goto error;
+ }
+
+ /*------------------------------------------------------------------------
+ * 1st floating-point type
+ * size=7 byte, precision=40 bits, offset=3 bits, mantissa size=31 bits,
+ * mantissa position=3, exponent size=10 bits, exponent position=34,
+ * exponent bias=511. It can be illustrated in little-endian order as
+ *
+ * 6 5 4 3 2 1 0
+ * ???????? ???SEEEE EEEEEEMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMM???
+ *
+ * To create a new floating-point type, the following properties must be
+ * set in the order of
+ * set fields -> set offset -> set precision -> set size.
+ * All these properties must be set before the type can function. Other
+ * properties can be set anytime. Derived type size cannot be expanded
+ * bigger than original size but can be decreased. There should be no
+ * holes among the significant bits. Exponent bias usually is set
+ * 2^(n-1)-1, where n is the exponent size.
+ *-----------------------------------------------------------------------*/
+ if(H5Tset_fields(tid1, 44, 34, 10, 3, 31)<0) {
+ H5_FAILED();
+ printf("Can't set fields\n");
+ goto error;
+ }
+ if(H5Tset_offset(tid1, 3)<0) {
+ H5_FAILED();
+ printf("Can't set offset\n");
+ goto error;
+ }
+ if(H5Tset_precision(tid1, 42)<0) {
+ H5_FAILED();
+ printf("Can't set precision\n");
+ goto error;
+ }
+ if(H5Tset_size(tid1, 7)<0) {
+ H5_FAILED();
+ printf("Can't set size\n");
+ goto error;
+ }
+ if(H5Tset_ebias(tid1, 511)<0) {
+ H5_FAILED();
+ printf("Can't set exponent bias\n");
+ goto error;
+ }
+ if(H5Tset_pad(tid1, H5T_PAD_ZERO, H5T_PAD_ZERO)<0) {
+ H5_FAILED();
+ printf("Can't set padding\n");
+ goto error;
+ }
+
+ if(H5Tcommit(file, "new float type 1", tid1)<0) {
+ H5_FAILED();
+ printf("Can't set inpad\n");
+ goto error;
+ }
+ if(H5Tclose(tid1)<0) {
+ H5_FAILED();
+ printf("Can't close datatype\n");
+ goto error;
+ }
+
+ if((tid1 = H5Topen(file, "new float type 1"))<0) {
+ H5_FAILED();
+ printf("Can't open datatype\n");
+ goto error;
+ }
+ if(H5Tget_fields(tid1, &spos, &epos, &esize, &mpos, &msize)<0) {
+ H5_FAILED();
+ printf("Can't get fields\n");
+ goto error;
+ }
+ if(spos!=44 || epos!=34 || esize!=10 || mpos!=3 || msize!=31) {
+ H5_FAILED();
+ printf("Wrong field values\n");
+ goto error;
+ }
+
+ if((precision = H5Tget_precision(tid1))!=42) {
+ H5_FAILED();
+ printf("Can't get precision or wrong precision\n");
+ goto error;
+ }
+ if((offset = H5Tget_offset(tid1))!=3) {
+ H5_FAILED();
+ printf("Can't get offset or wrong offset\n");
+ goto error;
+ }
+ if((size = H5Tget_size(tid1))!=7) {
+ H5_FAILED();
+ printf("Can't get size or wrong size\n");
+ goto error;
+ }
+ if((ebias = H5Tget_ebias(tid1))!=511) {
+ H5_FAILED();
+ printf("Can't get exponent bias or wrong bias\n");
+ goto error;
+ }
+
+ /*--------------------------------------------------------------------------
+ * 2nd floating-point type
+ * size=3 byte, precision=12 bits, offset=5 bits, mantissa size=8 bits,
+ * mantissa position=5, exponent size=3 bits, exponent position=13, exponent
+ * bias=3. It can be illustrated in little-endian order as
+ *
+ * 2 1 0
+ * SEEEEEEE MMMMMMMM MMMMMMMM
+ *--------------------------------------------------------------------------*/
+ if(H5Tset_fields(tid2, 23, 16, 7, 0, 16)<0) {
+ H5_FAILED();
+ printf("Can't set fields\n");
+ goto error;
+ }
+ if(H5Tset_offset(tid2, 0)<0) {
+ H5_FAILED();
+ printf("Can't set offset\n");
+ goto error;
+ }
+ if(H5Tset_precision(tid2, 24)<0) {
+ H5_FAILED();
+ printf("Can't set precision\n");
+ goto error;
+ }
+ if(H5Tset_size(tid2, 3)<0) {
+ H5_FAILED();
+ printf("Can't set size\n");
+ goto error;
+ }
+ if(H5Tset_ebias(tid2, 63)<0) {
+ H5_FAILED();
+ printf("Can't set size\n");
+ goto error;
+ }
+ if(H5Tset_pad(tid2, H5T_PAD_ZERO, H5T_PAD_ZERO)<0) {
+ H5_FAILED();
+ printf("Can't set padding\n");
+ goto error;
+ }
+
+ if(H5Tcommit(file, "new float type 2", tid2)<0) {
+ H5_FAILED();
+ printf("Can't set inpad\n");
+ goto error;
+ }
+ if(H5Tclose(tid2)<0) {
+ H5_FAILED();
+ printf("Can't close datatype\n");
+ goto error;
+ }
+
+ if((tid2 = H5Topen(file, "new float type 2"))<0) {
+ H5_FAILED();
+ printf("Can't open datatype\n");
+ goto error;
+ }
+ if(H5Tget_fields(tid2, &spos, &epos, &esize, &mpos, &msize)<0) {
+ H5_FAILED();
+ printf("Can't get fields\n");
+ goto error;
+ }
+ if(spos!=23 || epos!=16 || esize!=7 || mpos!=0 || msize!=16) {
+ H5_FAILED();
+ printf("Wrong field values\n");
+ goto error;
+ }
+
+ if((precision = H5Tget_precision(tid2))!=24) {
+ H5_FAILED();
+ printf("Can't get precision or wrong precision\n");
+ goto error;
+ }
+ if((offset = H5Tget_offset(tid2))!=0) {
+ H5_FAILED();
+ printf("Can't get offset or wrong offset\n");
+ goto error;
+ }
+ if((size = H5Tget_size(tid2))!=3) {
+ H5_FAILED();
+ printf("Can't get size or wrong size\n");
+ goto error;
+ }
+ if((ebias = H5Tget_ebias(tid2))!=63) {
+ H5_FAILED();
+ printf("Can't get exponent bias or wrong bias\n");
+ goto error;
+ }
+
+ if(H5Tclose(tid2)<0) {
+ H5_FAILED();
+ printf("Can't close datatype\n");
+ goto error;
+ }
+
+ if(H5Fclose(file)<0) {
+ H5_FAILED();
+ printf("Can't close file\n");
+ goto error;
+ } /* end if */
+
+ PASSED();
+ reset_hdf5(); /*print statistics*/
+
+ return 0;
+
+ error:
+ H5E_BEGIN_TRY {
+ H5Tclose (tid1);
+ H5Tclose (tid2);
+ H5Fclose (file);
+ } H5E_END_TRY;
+ reset_hdf5(); /*print statistics*/
+ return 1;
+}
+
+
+/*-------------------------------------------------------------------------
* Function: test_transient
*
* Purpose: Tests transient data types.
@@ -7027,6 +7287,10 @@ main(void)
nerrors += test_conv_bitfield();
nerrors += test_opaque();
+ /* Test user-define, query functions and software conversion
+ * for user-defined floating-point types */
+ nerrors += test_derived_flt();
+
/* Does floating point overflow generate a SIGFPE? */
generates_sigfpe();