/**************************************************************************** * NCSA HDF * * Software Development Group * * National Center for Supercomputing Applications * * University of Illinois at Urbana-Champaign * * 605 E. Springfield, Champaign IL 61820 * * * * For conditions of distribution and use, see the accompanying * * hdf/COPYING file. * * * ****************************************************************************/ /* $Id$ */ /*********************************************************** * * Test program: tmisc * * Test miscellaneous features not tested elsewhere. Generally * regression tests for bugs that are reported and don't * have an existing test to add them to. * *************************************************************/ #include "hdf5.h" #include "testhdf5.h" #define FILE "tmisc.h5" /* Definitions for misc. test #1 */ #define MISC1_VAL (13417386) /* 0xccbbaa */ #define MISC1_VAL2 (15654348) /* 0xeeddcc */ #define MISC1_DSET_NAME "/scalar_set" /**************************************************************** ** ** test_misc1(): test unlinking a dataset from a group and immediately ** re-using the dataset name ** ****************************************************************/ static void test_misc1(void) { int i; int i_check; hid_t file, dataspace, dataset; herr_t ret; /* Output message about test being performed */ MESSAGE(5, ("Testing Unlinking Dataset and Re-creating It\n")); file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); CHECK(file, FAIL, "H5Fcreate"); dataspace = H5Screate(H5S_SCALAR); CHECK(dataspace, FAIL, "H5Screate"); /* Write the dataset the first time. */ dataset = H5Dcreate(file, MISC1_DSET_NAME, H5T_NATIVE_INT, dataspace, H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dcreate"); i = MISC1_VAL; ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &i); CHECK(ret, FAIL, "H5Dwrite"); ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); /* Remove the dataset. */ ret = H5Gunlink(file, MISC1_DSET_NAME); CHECK(ret, FAIL, "H5Gunlink"); /* Write the dataset for the second time with a different value. */ dataset = H5Dcreate(file, MISC1_DSET_NAME, H5T_NATIVE_INT, dataspace, H5P_DEFAULT); CHECK(dataset, FAIL, "H5Dcreate"); i = MISC1_VAL2; ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &i); CHECK(ret, FAIL, "H5Dwrite"); ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); ret = H5Sclose(dataspace); CHECK(ret, FAIL, "H5Sclose"); ret = H5Fclose(file); CHECK(ret, FAIL, "H5Fclose"); /* Now, check the value written to the dataset, after it was re-created */ file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT); CHECK(file, FAIL, "H5Fopen"); dataspace = H5Screate(H5S_SCALAR); CHECK(dataspace, FAIL, "H5Screate"); dataset = H5Dopen(file, MISC1_DSET_NAME); CHECK(dataset, FAIL, "H5Dopen"); ret = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &i_check); CHECK(ret, FAIL, "H5Dread"); VERIFY(i_check,MISC1_VAL2,"H5Dread"); ret = H5Sclose(dataspace); CHECK(ret, FAIL, "H5Sclose"); ret = H5Dclose(dataset); CHECK(ret, FAIL, "H5Dclose"); ret = H5Fclose(file); CHECK(ret, FAIL, "H5Fclose"); } /* end test_misc1() */ /**************************************************************** ** ** test_misc(): Main misc. test routine. ** ****************************************************************/ void test_misc(void) { /* Output message about test being performed */ MESSAGE(5, ("Testing Miscellaneous Routines\n")); /* Various tests, using the same test file */ test_misc1(); /* Test unlinking a dataset & immediately re-using name */ } /* test_misc() */ /*------------------------------------------------------------------------- * Function: cleanup_misc * * Purpose: Cleanup temporary test files * * Return: none * * Programmer: Albert Cheng * July 2, 1998 * * Modifications: * *------------------------------------------------------------------------- */ void cleanup_misc(void) { remove(FILE); }