hdf5/test/tfile.c
Robb Matzke b5e2752ad6 [svn-r673] Changes since 19980908
----------------------

./COPYING
	Reformatted as text instead of C.  Removed zlib crew from the
	list of contributors since no zlib code is actually in the
	hdf5 library.

./INSTALL
./INSTALL.ascired
./MANIFEST
	Minor updates for Beta release including version number
	change.

./INSTALL_MAINT
	Added information about making a release.

./RELEASE
	Updated function list based on public header files.

./bin/checkposix
	Got rid of complaints about some obvious things.

./doc/html/H5.api.html
./doc/html/RM_H5F.html
./src/H5F.c
./src/H5Fpublic.h
./test/tfile.c
	Changed H5Fget_create_template() and H5Fget_access_template()
	to H5Fget_create_plist() and H5Fget_access_plist() since that
	conforms better to lots of other names.

./doc/html/Datatypes.html
./doc/html/ExternalFiles.html
./doc/html/Files.html
./doc/html/H5.api.html
./doc/html/H5.sample_code.html
./doc/html/RM_H5F.html
./doc/html/RM_H5Front.html
	Changed `template' to `property list', etc.

./doc/html/Ragged.html	   [NEW]
	Documentation for ragged arrays.

./src/H5Iprivate.h
./src/H5Ipublic.h
./src/H5I.c
	Changed the scope of some symbols to be more local.

./src/H5.c
./src/H5AC.c
./src/H5D.c
./src/H5E.c
./src/H5F.c
./src/H5Ffamily.c
./src/H5Fistore.c
./src/H5Flow.c
./src/H5Fsec2.c
./src/H5Fsplit.c
./src/H5Fstdio.c
./src/H5G.c
./src/H5Gnode.c
./src/H5HG.c
./src/H5I.c
./src/H5O.c
./src/H5Ocomp.c
./src/H5Odtype.c
./src/H5Oefl.c
./src/H5Omtime.c
./src/H5Oname.c
./src/H5P.c
./src/H5S.c
./src/H5Shyper.c
./src/H5Tbit.c
./src/H5Tconv.c
./src/H5V.c
./src/H5Z.c
./src/H5private.h
	Fixed some violations of our naming scheme by adding HD to the
	beginning of all Posix functions.
1998-09-08 14:15:44 -05:00

328 lines
9.9 KiB
C
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/****************************************************************************
* 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. *
* *
****************************************************************************/
#ifdef RCSID
static char RcsId[] = "$Revision$";
#endif
/* $Id$ */
/***********************************************************
*
* Test program: tfile
*
* Test the low-level file I/O features.
*
*************************************************************/
#include <testhdf5.h>
#include <H5private.h>
#include <H5Bprivate.h>
#include <H5Pprivate.h>
#define F1_USERBLOCK_SIZE (hsize_t)0
#define F1_OFFSET_SIZE sizeof(hsize_t)
#define F1_LENGTH_SIZE sizeof(hsize_t)
#define F1_SYM_LEAF_K 4
#define F1_SYM_INTERN_K 16
#define FILE1 "tfile1.h5"
#define F2_USERBLOCK_SIZE (hsize_t)512
#define F2_OFFSET_SIZE 8
#define F2_LENGTH_SIZE 8
#define F2_SYM_LEAF_K 8
#define F2_SYM_INTERN_K 32
#define FILE2 "tfile2.h5"
#define F3_USERBLOCK_SIZE (hsize_t)0
#define F3_OFFSET_SIZE F2_OFFSET_SIZE
#define F3_LENGTH_SIZE F2_LENGTH_SIZE
#define F3_SYM_LEAF_K F2_SYM_LEAF_K
#define F3_SYM_INTERN_K F2_SYM_INTERN_K
#define FILE3 "tfile3.h5"
/****************************************************************
**
** test_file_create(): Low-level file creation I/O test routine.
**
****************************************************************/
static void
test_file_create(void)
{
hid_t fid1, fid2, fid3; /* HDF5 File IDs */
hid_t tmpl1, tmpl2; /*file creation templates */
hsize_t ublock; /*sizeof userblock */
size_t parm; /*file-creation parameters */
size_t parm2; /*file-creation parameters */
int iparm, iparm2;
herr_t ret; /*generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing Low-Level File Creation I/O\n"));
/* Test create with various sequences of H5F_ACC_EXCL and */
/* H5F_ACC_TRUNC flags */
/* Create with H5F_ACC_EXCL */
/* First ensure the file does not exist */
remove(FILE1);
fid1 = H5Fcreate(FILE1, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fcreate");
/* try to create the same file with H5F_ACC_TRUNC (should fail) */
fid2 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
VERIFY(fid2, FAIL, "H5Fcreate");
/* Close the file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
/* Try again with H5F_ACC_EXCL (should fail) */
fid1 = H5Fcreate(FILE1, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
VERIFY(fid1, FAIL, "H5Fcreate");
/* Test create with H5F_ACC_TRUNC */
/* Create first file */
fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fcreate");
/* Try to create first file again (should fail) */
fid2 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
VERIFY(fid2, FAIL, "H5Fcreate");
/* Try with H5F_ACC_EXCL (should fail too) */
fid2 = H5Fcreate(FILE1, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
VERIFY(fid2, FAIL, "H5Fcreate");
/* Get the file-creation template */
tmpl1 = H5Fget_create_plist(fid1);
CHECK(tmpl1, FAIL, "H5Fget_create_plist");
/* Get the file-creation parameters */
ret = H5Pget_userblock(tmpl1, &ublock);
CHECK(ret, FAIL, "H5Pget_userblock");
VERIFY(ublock, F1_USERBLOCK_SIZE, "H5Pget_userblock");
ret = H5Pget_sizes(tmpl1, &parm, &parm2);
CHECK(ret, FAIL, "H5Pget_sizes");
VERIFY(parm, F1_OFFSET_SIZE, "H5Pget_sizes");
VERIFY(parm2, F1_LENGTH_SIZE, "H5Pget_sizes");
ret = H5Pget_sym_k(tmpl1, &iparm, &iparm2);
CHECK(ret, FAIL, "H5Pget_sym_k");
VERIFY(iparm, F1_SYM_INTERN_K, "H5Pget_sym_k");
VERIFY(iparm2, F1_SYM_LEAF_K, "H5Pget_sym_k");
/* Release file-creation template */
ret = H5Pclose(tmpl1);
CHECK(ret, FAIL, "H5Pclose");
#ifdef LATER
/* Double-check that the atom has been vaporized */
ret = H5Pclose(tmpl1);
VERIFY(ret, FAIL, "H5Pclose");
#endif
/* Create a new file with a non-standard file-creation template */
tmpl1 = H5Pcreate(H5P_FILE_CREATE);
CHECK(tmpl1, FAIL, "H5Pnew");
/* Set the new file-creation parameters */
ret = H5Pset_userblock(tmpl1, F2_USERBLOCK_SIZE);
CHECK(ret, FAIL, "H5Pset_userblock");
ret = H5Pset_sizes(tmpl1, F2_OFFSET_SIZE, F2_LENGTH_SIZE);
CHECK(ret, FAIL, "H5Pset_sizes");
ret = H5Pset_sym_k(tmpl1, F2_SYM_INTERN_K, F2_SYM_LEAF_K);
CHECK(ret, FAIL, "H5Pset_sym_k");
/*
* Try to create second file, with non-standard file-creation template
* params.
*/
fid2 = H5Fcreate(FILE2, H5F_ACC_TRUNC, tmpl1, H5P_DEFAULT);
CHECK(fid2, FAIL, "H5Fcreate");
/* Release file-creation template */
ret = H5Pclose(tmpl1);
CHECK(ret, FAIL, "H5Pclose");
/* Get the file-creation template */
tmpl1 = H5Fget_create_plist(fid2);
CHECK(tmpl1, FAIL, "H5Fget_create_plist");
/* Get the file-creation parameters */
ret = H5Pget_userblock(tmpl1, &ublock);
CHECK(ret, FAIL, "H5Pget_userblock");
VERIFY(ublock, F2_USERBLOCK_SIZE, "H5Pget_userblock");
ret = H5Pget_sizes(tmpl1, &parm, &parm2);
CHECK(ret, FAIL, "H5Pget_sizes");
VERIFY(parm, F2_OFFSET_SIZE, "H5Pget_sizes");
VERIFY(parm2, F2_LENGTH_SIZE, "H5Pget_sizes");
ret = H5Pget_sym_k(tmpl1, &iparm, &iparm2);
CHECK(ret, FAIL, "H5Pget_sym_k");
VERIFY(iparm, F2_SYM_INTERN_K, "H5Pget_sym_k");
VERIFY(iparm2, F2_SYM_LEAF_K, "H5Pget_sym_k");
/* Clone the file-creation template */
tmpl2 = H5Pcopy(tmpl1);
CHECK(tmpl2, FAIL, "H5Pcopy");
/* Release file-creation template */
ret = H5Pclose(tmpl1);
CHECK(ret, FAIL, "H5Pclose");
/* Set the new file-creation parameter */
ret = H5Pset_userblock(tmpl2, F3_USERBLOCK_SIZE);
CHECK(ret, FAIL, "H5Pset_userblock");
/*
* Try to create second file, with non-standard file-creation template
* params
*/
fid3 = H5Fcreate(FILE3, H5F_ACC_TRUNC, tmpl2, H5P_DEFAULT);
CHECK(fid3, FAIL, "H5Fcreate");
/* Release file-creation template */
ret = H5Pclose(tmpl2);
CHECK(ret, FAIL, "H5Pclose");
/* Get the file-creation template */
tmpl1 = H5Fget_create_plist(fid3);
CHECK(tmpl1, FAIL, "H5Fget_create_plist");
/* Get the file-creation parameters */
ret = H5Pget_userblock(tmpl1, &ublock);
CHECK(ret, FAIL, "H5Pget_userblock");
VERIFY(ublock, F3_USERBLOCK_SIZE, "H5Pget_userblock");
ret = H5Pget_sizes(tmpl1, &parm, &parm2);
CHECK(ret, FAIL, "H5Pget_sizes");
VERIFY(parm, F3_OFFSET_SIZE, "H5Pget_sizes");
VERIFY(parm2, F3_LENGTH_SIZE, "H5Pget_sizes");
ret = H5Pget_sym_k(tmpl1, &iparm, &iparm2);
CHECK(ret, FAIL, "H5Pget_sym_k");
VERIFY(iparm, F3_SYM_INTERN_K, "H5Pget_sym_k");
VERIFY(iparm2, F3_SYM_LEAF_K, "H5Pget_sym_k");
/* Release file-creation template */
ret = H5Pclose(tmpl1);
CHECK(ret, FAIL, "H5Pclose");
/* Close first file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
/* Close second file */
ret = H5Fclose(fid2);
CHECK(ret, FAIL, "H5Fclose");
/* Close third file */
ret = H5Fclose(fid3);
CHECK(ret, FAIL, "H5Fclose");
} /* test_file_create() */
/****************************************************************
**
** test_file_open(): Low-level file open I/O test routine.
**
****************************************************************/
static void
test_file_open(void)
{
hid_t fid1; /*HDF5 File IDs */
hid_t tmpl1; /*file creation templates */
hsize_t ublock; /*sizeof user block */
size_t parm; /*file-creation parameters */
size_t parm2; /*file-creation parameters */
int iparm, iparm2;
herr_t ret; /*generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing Low-Level File Opening I/O\n"));
/* Open first file */
fid1 = H5Fopen(FILE2, H5F_ACC_RDWR, H5P_DEFAULT);
CHECK(fid1, FAIL, "H5Fopen");
/* Get the file-creation template */
tmpl1 = H5Fget_create_plist(fid1);
CHECK(tmpl1, FAIL, "H5Fget_create_plist");
/* Get the file-creation parameters */
ret = H5Pget_userblock(tmpl1, &ublock);
CHECK(ret, FAIL, "H5Pget_userblock");
VERIFY(ublock, F2_USERBLOCK_SIZE, "H5Pget_userblock");
ret = H5Pget_sizes(tmpl1, &parm, &parm2);
CHECK(ret, FAIL, "H5Pget_sizes");
VERIFY(parm, F2_OFFSET_SIZE, "H5Pget_sizes");
VERIFY(parm2, F2_LENGTH_SIZE, "H5Pget_sizes");
ret = H5Pget_sym_k(tmpl1, &iparm, &iparm2);
CHECK(ret, FAIL, "H5Pget_sym_k");
VERIFY(iparm, F2_SYM_INTERN_K, "H5Pget_sym_k");
VERIFY(iparm2, F2_SYM_LEAF_K, "H5Pget_sym_k");
/* Release file-creation template */
ret = H5Pclose(tmpl1);
CHECK(ret, FAIL, "H5Pclose");
/* Close first file */
ret = H5Fclose(fid1);
CHECK(ret, FAIL, "H5Fclose");
} /* test_file_open() */
/****************************************************************
**
** test_file(): Main low-level file I/O test routine.
**
****************************************************************/
void
test_file(void)
{
/* Output message about test being performed */
MESSAGE(5, ("Testing Low-Level File I/O\n"));
test_file_create(); /* Test file creation (also creation templates) */
test_file_open(); /* Test file opening */
} /* test_file() */
/*-------------------------------------------------------------------------
* Function: cleanup_file
*
* Purpose: Cleanup temporary test files
*
* Return: none
*
* Programmer: Albert Cheng
* July 2, 1998
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
void
cleanup_file(void)
{
remove(FILE1);
remove(FILE2);
remove(FILE3);
}