summaryrefslogtreecommitdiffstats
path: root/test/dtypes.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/dtypes.c')
-rw-r--r--test/dtypes.c183
1 files changed, 182 insertions, 1 deletions
diff --git a/test/dtypes.c b/test/dtypes.c
index fe954d8..67f9f84 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -1136,7 +1136,8 @@ test_compound_6(void)
* Function: test_compound_7
*
* Purpose: Tests inserting fields into compound datatypes when the field
- * overlaps the end of the compound datatype.
+ * overlaps the end of the compound datatype. Also, tests
+ * increasing compound type size.
*
* Return: Success: 0
*
@@ -1146,6 +1147,9 @@ test_compound_6(void)
* Tuesday, December 18, 2001
*
* Modifications:
+ * The size of compound datatype can be expanded now.
+ * Raymond Lu
+ * Wednesday, September 10, 2003
*
*-------------------------------------------------------------------------
*/
@@ -1222,6 +1226,35 @@ test_compound_7(void)
goto error;
} /* end if */
+ /* Should not be able to shrink size of compound datatype */
+ H5E_BEGIN_TRY {
+ ret=H5Tset_size(tid2, sizeof(struct s1)/2);
+ } H5E_END_TRY;
+ if(ret>=0) {
+ H5_FAILED();
+ printf("Shrunk compound type?\n");
+ goto error;
+ } /* end if */
+
+ /* Increase compound type size and try inserting field again */
+ if(H5Tset_size(tid2, sizeof(struct s2))<0) {
+ H5_FAILED();
+ printf("Incorrect size for struct 2\n");
+ goto error;
+ } /* end if */
+
+ if( H5Tinsert(tid2,"d",HOFFSET(struct s2,d),H5T_NATIVE_DOUBLE)<0) {
+ H5_FAILED();
+ printf("Can't expand compound datatype\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tget_size(tid2)!=sizeof(struct s2)) {
+ H5_FAILED();
+ printf("Incorrect size for struct 2\n");
+ goto error;
+ } /* end if */
+
/* Release resources */
if (H5Tclose(tid1)<0 || H5Tclose(tid2)<0) {
H5_FAILED();
@@ -1239,6 +1272,153 @@ test_compound_7(void)
/*-------------------------------------------------------------------------
+ * Function: test_compound_8
+ *
+ * Purpose: Tests H5Tpack for compound data types.
+ *
+ * Return: Success: 0
+ *
+ * Failure: number of errors
+ *
+ * Programmer: Robb Matzke
+ * Wednesday, January 7, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static int
+test_compound_8(void)
+{
+ typedef struct s1 {
+ char a;
+ int b;
+ } s1;
+
+ typedef struct s2 {
+ char c;
+ s1 d;
+ } s2;
+
+ hid_t tid1, tid2, tid3;
+ herr_t ret;
+
+ TESTING("packing compound data types");
+
+ /* Create first compound datatype */
+ if((tid1 = H5Tcreate( H5T_COMPOUND, sizeof(struct s1)))<0) {
+ H5_FAILED(); AT();
+ printf("Can't create datatype!\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tinsert(tid1,"a",HOFFSET(struct s1,a),H5T_NATIVE_CHAR)<0) {
+ H5_FAILED(); AT();
+ printf("Can't insert field 'a'\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tinsert(tid1,"b",HOFFSET(struct s1,b),H5T_NATIVE_INT)<0) {
+ H5_FAILED(); AT();
+ printf("Can't insert field 'b'\n");
+ goto error;
+ } /* end if */
+
+ /* Test H5Tpack for the first compound type */
+ if(H5Tpack(tid1)<0) {
+ H5_FAILED(); AT();
+ printf("Can't pack the compound data type\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tlock(tid1)<0) {
+ H5_FAILED(); AT();
+ printf("Can't lock the compound data type\n");
+ goto error;
+ } /* end if */
+
+ /* If the type is already packed, packing a locked type is OK */
+ if(H5Tpack(tid1)<0) {
+ H5_FAILED(); AT();
+ printf("Can't pack the compound data type for second time\n");
+ goto error;
+ } /* end if */
+
+
+ /* Create second compound datatype */
+ if((tid2 = H5Tcreate( H5T_COMPOUND, sizeof(struct s2)))<0) {
+ H5_FAILED(); AT();
+ printf("Can't create datatype!\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tinsert(tid2,"c",HOFFSET(struct s2,c),H5T_NATIVE_CHAR)<0) {
+ H5_FAILED(); AT();
+ printf("Can't insert field 'c'\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tinsert(tid2,"d",HOFFSET(struct s2,d),tid1)<0) {
+ H5_FAILED(); AT();
+ printf("Can't insert field 'd'\n");
+ goto error;
+ } /* end if */
+
+ /* Make a copy of the type for later */
+ if((tid3=H5Tcopy(tid2))<0) {
+ H5_FAILED(); AT();
+ printf("Can't copy type #2\n");
+ goto error;
+ } /* end if */
+
+ /* Test H5Tpack for the second compound type */
+ if(H5Tpack(tid2)<0) {
+ H5_FAILED(); AT();
+ printf("Can't pack the compound data type\n");
+ goto error;
+ } /* end if */
+
+ if(H5Tlock(tid2)<0) {
+ H5_FAILED(); AT();
+ printf("Can't lock the compound data type\n");
+ goto error;
+ } /* end if */
+
+ /* If the type is already packed, packing a locked type is OK */
+ if(H5Tpack(tid2)<0) {
+ H5_FAILED(); AT();
+ printf("Can't pack the compound data type for second time\n");
+ goto error;
+ } /* end if */
+
+ /* Lock unpacked type */
+ if(H5Tlock(tid3)<0) {
+ H5_FAILED(); AT();
+ printf("Can't lock the compound data type\n");
+ goto error;
+ } /* end if */
+
+ /* If the type is not packed, packing a locked type shouldn't work */
+ H5E_BEGIN_TRY {
+ ret=H5Tpack(tid3);
+ } H5E_END_TRY;
+ if(ret>=0) {
+ H5_FAILED(); AT();
+ printf("Packing locked datatype worked?\n");
+ goto error;
+ } /* end if */
+
+ /* Can't release resources - they are locked */
+
+ PASSED();
+ return 0;
+
+ error:
+ return 1;
+}
+
+
+/*-------------------------------------------------------------------------
* Function: test_query
*
* Purpose: Tests query functions of compound and enumeration types.
@@ -4363,6 +4543,7 @@ main(void)
nerrors += test_compound_5();
nerrors += test_compound_6();
nerrors += test_compound_7();
+ nerrors += test_compound_8();
nerrors += test_conv_int ();
nerrors += test_conv_enum_1();
nerrors += test_conv_enum_2();