summaryrefslogtreecommitdiffstats
path: root/test/tid.c
diff options
context:
space:
mode:
authorJames Laird <jlaird@hdfgroup.org>2005-06-17 19:36:57 (GMT)
committerJames Laird <jlaird@hdfgroup.org>2005-06-17 19:36:57 (GMT)
commitbd867cf9f6c14077357a7306e4a236a72c938ec9 (patch)
tree399cf43e8ce9664e8d6b234695dfde1cb2644d11 /test/tid.c
parent92fba3f6630d28f7f82c6f57caf81e9bad654d69 (diff)
downloadhdf5-bd867cf9f6c14077357a7306e4a236a72c938ec9.zip
hdf5-bd867cf9f6c14077357a7306e4a236a72c938ec9.tar.gz
hdf5-bd867cf9f6c14077357a7306e4a236a72c938ec9.tar.bz2
[svn-r10944] Purpose:
Bug fix Description: tid.c is a test for user-defined hid_t's. It should be part of the testhdf5 tests, but was not being run. It also had a couple of minor bugs. Solution: Added id test to testhdf5 and fixed bugs. Platforms tested: mir, sleipnir, modi4
Diffstat (limited to 'test/tid.c')
-rw-r--r--test/tid.c119
1 files changed, 77 insertions, 42 deletions
diff --git a/test/tid.c b/test/tid.c
index b30849e..5d35607 100644
--- a/test/tid.c
+++ b/test/tid.c
@@ -1,3 +1,18 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/* Test user-created identifiers (hid_t's) and identifier types. */
#include "testhdf5.h"
#include "hdf5.h"
@@ -7,7 +22,7 @@
#include "H5Ipkg.h"
/* Test basic functionality of registering and deleting types and IDs */
-static int id_test(void)
+static int basic_id_test(void)
{
H5I_type_t myType = H5I_BADID;
hid_t arrayID = H5I_INVALID_HID;
@@ -20,7 +35,6 @@ static int id_test(void)
int num_ref;
hsize_t num_members;
- testObj = malloc(7 * sizeof(int));
/* Try to register an ID with ficticious types */
H5E_BEGIN_TRY
@@ -41,19 +55,19 @@ static int id_test(void)
/* Try to access IDs with ficticious types */
H5E_BEGIN_TRY
- testObj = H5Iobject_verify(100, (H5I_type_t) 0);
+ testPtr = H5Iobject_verify(100, (H5I_type_t) 0);
H5E_END_TRY
- VERIFY(testObj, NULL, "H5Iobject_verify");
- if(testObj != NULL)
+ VERIFY(testPtr, NULL, "H5Iobject_verify");
+ if(testPtr != NULL)
goto out;
H5E_BEGIN_TRY
- testObj = H5Iobject_verify(700, (H5I_type_t) 700);
+ testPtr = H5Iobject_verify(700, (H5I_type_t) 700);
H5E_END_TRY
- VERIFY(testObj, NULL, "H5Iobject_verify");
- if(testObj != NULL)
+ VERIFY(testPtr, NULL, "H5Iobject_verify");
+ if(testPtr != NULL)
goto out;
/* Register a type */
@@ -63,12 +77,18 @@ static int id_test(void)
if(myType == H5I_BADID)
goto out;
- /* Register an ID and retrieve the object it points to */
+ /* Register an ID and retrieve the object it points to.
+ * Once the ID has been registered, testObj will be freed when
+ * its ID type is destroyed. */
+ testObj = malloc(7 * sizeof(int));
arrayID = H5Iregister(myType, testObj);
CHECK(arrayID, H5I_INVALID_HID, "H5Iregister");
if(arrayID == H5I_INVALID_HID)
+ {
+ free(testObj);
goto out;
+ }
testPtr = (int *) H5Iobject_verify(arrayID, myType);
@@ -76,7 +96,8 @@ static int id_test(void)
if(testPtr != testObj)
goto out;
- /* Ensure that H5Iget_file_id and H5Iget_name() fail */
+ /* Ensure that H5Iget_file_id and H5Iget_name() fail, since this
+ * is an hid_t for the wrong kind of object */
H5E_BEGIN_TRY
testID = H5Iget_file_id(arrayID);
H5E_END_TRY
@@ -93,7 +114,7 @@ static int id_test(void)
if(testSize != 0)
goto out;
- /* Make sure H5Iremove_verify catches objects of the wrong type */
+ /* Make sure H5Iremove_verify catches objects of the wrong type */
H5E_BEGIN_TRY
testPtr = (int*) H5Iremove_verify(arrayID, (H5I_type_t) 0);
H5E_END_TRY
@@ -112,7 +133,7 @@ static int id_test(void)
/* Remove an ID and make sure we can't access it */
testPtr = (int*) H5Iremove_verify(arrayID, myType);
-
+
CHECK(testPtr, NULL, "H5Iremove_verify");
if(testPtr == NULL)
goto out;
@@ -125,7 +146,7 @@ static int id_test(void)
if(testPtr != NULL)
goto out;
- /* Delete the type and make sure we can't access objects within it */
+ /* Delete the type and make sure we can't access objects within it */
arrayID = H5Iregister(myType, testObj);
err = H5Idestroy_type(myType);
@@ -142,19 +163,27 @@ static int id_test(void)
goto out;
H5E_END_TRY
- /* Register another type and another object in that type */
+ /* Register another type and another object in that type */
myType = H5Iregister_type(64, 0, (H5I_free_t) free );
CHECK(myType, H5I_BADID, "H5Iregister_type");
if(myType == H5I_BADID)
goto out;
+ /* The memory that testObj pointed to should already have been
+ * freed when the previous type was destroyed. Allocate new
+ * memory for it.
+ */
testObj = malloc(7 * sizeof(int));
arrayID = H5Iregister(myType, testObj);
CHECK(arrayID, H5I_INVALID_HID, "H5Iregister");
if(arrayID == H5I_INVALID_HID)
+ {
+ free(testObj);
goto out;
+ }
+
err = H5Inmembers(myType, &num_members);
CHECK(err, -1, "H5Inmembers");
if (err < 0)
@@ -163,8 +192,8 @@ static int id_test(void)
if(num_members != 1)
goto out;
- /* Increment references to type and ensure that dec_type_ref
- doesn't destroy the type */
+ /* Increment references to type and ensure that dec_type_ref
+ doesn't destroy the type */
num_ref = H5Iinc_type_ref(myType);
VERIFY(num_ref, 2, "H5Iinc_type_ref");
if( num_ref != 2)
@@ -181,7 +210,7 @@ static int id_test(void)
if(num_members != 1)
goto out;
- /* This call to dec_type_ref should destroy the type */
+ /* This call to dec_type_ref should destroy the type */
num_ref = H5Idec_type_ref(myType);
VERIFY(num_ref, 0, "H5Idec_type_ref");
if(num_ref != 0)
@@ -199,7 +228,8 @@ static int id_test(void)
return 0;
out:
- /* Clean up type if it has been allocated */
+ /* Clean up type if it has been allocated and free memory used
+ * by testObj */
if(myType >= 0)
H5Idestroy_type(myType);
@@ -221,7 +251,7 @@ static int id_predefined_test(void )
testObj = malloc(sizeof(int));
- /* Try to perform illegal functions on various predefined types */
+ /* Try to perform illegal functions on various predefined types */
H5E_BEGIN_TRY
testID = H5Iregister(H5I_FILE, testObj);
H5E_END_TRY
@@ -262,7 +292,7 @@ static int id_predefined_test(void )
if(testErr >= 0)
goto out;
- /* Create a datatype ID and try to perform illegal functions on it */
+ /* Create a datatype ID and try to perform illegal functions on it */
typeID = H5Tcreate(H5T_OPAQUE, 42);
CHECK(typeID, H5I_INVALID_HID, "H5Tcreate");
if(typeID == H5I_INVALID_HID)
@@ -286,12 +316,16 @@ static int id_predefined_test(void )
H5Tclose(typeID);
- free(testObj);
+ /* testObj was never registered as an atom, so it will not be
+ * automatically freed. */
+ free(testObj);
return 0;
out:
if(typeID != H5I_INVALID_HID)
H5Tclose(typeID);
+ if(testObj != NULL)
+ free(testObj);
return -1;
}
@@ -299,19 +333,19 @@ out:
/* Test boundary cases with lots of types */
- /* Type IDs range from H5I_NTYPES to MAX_NUM_TYPES. The system will assign */
- /* IDs in sequential order until MAX_NUM_TYPES IDs have been given out, at which */
- /* point it will search for type IDs that were allocated but have since been */
- /* deleted. */
- /* This test will allocate IDs up to MAX_NUM_TYPES, ensure that IDs wrap around */
- /* to low values successfully, ensure that an error is thrown when all possible */
- /* type IDs are taken, then ensure that deleting types frees up their IDs. */
- /* Note that this test depends on the implementation of IDs, so may break */
- /* if the implementation changes. */
- /* Also note that if someone else registered a user-defined type and forgot to */
- /* destroy it, this test will mysteriously fail (because it will expect there to */
- /* be one more "free" type ID than there is). */
- /* H5I_NTYPES is defined in h5public.h, MAX_NUM_TYPES is defined in h5pkg.h */
+/* Type IDs range from H5I_NTYPES to MAX_NUM_TYPES. The system will assign */
+/* IDs in sequential order until MAX_NUM_TYPES IDs have been given out, at which */
+/* point it will search for type IDs that were allocated but have since been */
+/* deleted. */
+/* This test will allocate IDs up to MAX_NUM_TYPES, ensure that IDs wrap around */
+/* to low values successfully, ensure that an error is thrown when all possible */
+/* type IDs are taken, then ensure that deleting types frees up their IDs. */
+/* Note that this test depends on the implementation of IDs, so may break */
+/* if the implementation changes. */
+/* Also note that if someone else registered a user-defined type and forgot to */
+/* destroy it, this test will mysteriously fail (because it will expect there to */
+/* be one more "free" type ID than there is). */
+/* H5I_NTYPES is defined in h5public.h, MAX_NUM_TYPES is defined in h5pkg.h */
static int test_id_type_list(void)
{
H5I_type_t startType; /* The first type ID we were assigned in this test */
@@ -324,14 +358,14 @@ static int test_id_type_list(void)
if(startType == H5I_BADID)
goto out;
- /* Sanity check */
+ /* Sanity check */
if(startType >= MAX_NUM_TYPES || startType < H5I_NTYPES)
{
/* Error condition, throw an error */
CHECK(1, 1, "H5Iregister_type");
goto out;
}
- /* Create types up to MAX_NUM_TYPES */
+ /* Create types up to MAX_NUM_TYPES */
for(i = startType + 1; i < MAX_NUM_TYPES; i++)
{
currentType = H5Iregister_type(8, 0, (H5I_free_t) free );
@@ -340,7 +374,7 @@ static int test_id_type_list(void)
goto out;
}
- /* Wrap around to low type ID numbers */
+ /* Wrap around to low type ID numbers */
for(i = H5I_NTYPES; i < startType; i++)
{
currentType = H5Iregister_type(8, 0, (H5I_free_t) free );
@@ -349,7 +383,7 @@ static int test_id_type_list(void)
goto out;
}
- /* There should be no room at the inn */
+ /* There should be no room at the inn for a new ID type*/
H5E_BEGIN_TRY
testType = H5Iregister_type(8, 0, (H5I_free_t) free );
H5E_END_TRY
@@ -358,7 +392,7 @@ static int test_id_type_list(void)
if(testType != H5I_BADID)
goto out;
- /* Now delete a type and try to insert again */
+ /* Now delete a type and try to insert again */
H5Idestroy_type(H5I_NTYPES);
testType = H5Iregister_type(8, 0, (H5I_free_t) free );
@@ -366,14 +400,14 @@ static int test_id_type_list(void)
if(testType != H5I_NTYPES)
goto out;
- /* Cleanup. Destroy all types. */
+ /* Cleanup. Destroy all types. */
for(i = H5I_NTYPES; i < MAX_NUM_TYPES; i++)
H5Idestroy_type((H5I_type_t) i);
return 0;
out:
- /* Cleanup. For simplicity, just destroy all types and ignore errors. */
+ /* Cleanup. For simplicity, just destroy all types and ignore errors. */
H5E_BEGIN_TRY
for(i = H5I_NTYPES; i < MAX_NUM_TYPES; i++)
H5Idestroy_type((H5I_type_t) i);
@@ -383,7 +417,8 @@ out:
void test_ids(void)
{
- id_test();
+ basic_id_test();
id_predefined_test();
test_id_type_list();
+
}