home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
- *
- *
- * NCSA HDF version 3.2r2
- * October 30, 1992
- *
- * NCSA HDF Version 3.2 source code and documentation are in the public
- * domain. Specifically, we give to the public domain all rights for future
- * licensing of the source code, all resale rights, and all publishing rights.
- *
- * We ask, but do not require, that the following message be included in all
- * derived works:
- *
- * Portions developed at the National Center for Supercomputing Applications at
- * the University of Illinois at Urbana-Champaign, in collaboration with the
- * Information Technology Institute of Singapore.
- *
- * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
- * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
- * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
- *
- ****************************************************************************
- */
-
- #ifdef RCSID
- static char RcsId[] = "@(#)$Revision: 1.8 $";
- #endif
- /*
- $Header: /hdf/hdf/v3.2r2/test/RCS/thfile.c,v 1.8 1992/10/30 19:05:24 koziol beta koziol $
-
- $Log: thfile.c,v $
- * Revision 1.8 1992/10/30 19:05:24 koziol
- * Added a "const char *" to strcmp calls to make the SGI ANSI compiler hapy
- *
- * Revision 1.7 1992/07/16 19:34:08 mlivin
- * changed re-opening of file to NOT include DFACC_CREATE
- *
- * Revision 1.6 1992/06/26 20:23:20 mlivin
- * added in tests for Hishdf - open HDF, closed HDF, non-HDF, non-existing
- *
- * Revision 1.5 1992/06/22 23:04:42 chouck
- * Removed calls to fork()
- *
- * Revision 1.4 1992/06/01 19:23:47 chouck
- * Cleaned up output
- *
- * Revision 1.3 1992/05/31 15:23:30 mfolk
- * Added uint8 * and uint16 casts to make Convex stop complaining.
- *
- * Revision 1.2 1992/05/28 14:24:01 chouck
- * Added casts for calls to Hinquire()
- *
- * Revision 1.1 1992/02/10 20:59:34 chouck
- * Initial revision
- *
- */
- /*
-
- * Hopen
- ** Create a file.
- ** Open an existing file.
- *** Normally.
- *** Read-only file with DFACC_WRITE.
- ** Open non-existent file.
- *** With DFACC_READ.
- *** With DFACC_WRITE.
- ** Create an illegal file.
- ** Open the same file twice.
- *** First with DFACC_WRITE then with DFACC_READ.
- *** First with DFACC_WRITE then with DFACC_WRITE.
- *** First with DFACC_READ and then with DFACC_WRITE.
- *** First with DFACC_<any> and then with DFACC_CREATE.
- ** Open more files than there is slots.
-
- * Hclose
- ** Close a proper file.
- ** Close with an illegal file id.
- *** Random file id.
- *** Correct tag but bad slot.
-
- * Hstartread
- ** Normal.
- ** With illegal file id.
- ** With illegal tag/ref.
- ** With wildcard.
- ** Open more access elements than there is space.
-
- */
-
- #include "hdf.h"
- #define TESTFILE_NAME "t.hdf"
- uint8 outbuf[4096], inbuf[4096];
-
-
- #define CHECK(ret, val, where) \
- {if(ret == val) { fprintf(stderr, "%s failed, line %d, code %d\n", \
- where, __LINE__, ret); \
- HEprint(stderr, 0); exit(1);}}
-
- int main(argc, argv)
- int argc;
- char *argv[];
- {
- int32 fid, fid1;
- int32 aid1, aid2;
- int32 fileid, length, offset, posn;
- uint16 tag, ref;
- int16 access, special;
- int ret, i;
- intn errors = 0;
- bool ret_bool;
-
- for (i=0; i<4096; i++) outbuf[i] = (char) (i % 256);
-
- printf("Creating a file %s\n\n", TESTFILE_NAME);
- fid = Hopen(TESTFILE_NAME, DFACC_CREATE, 0);
- CHECK(fid, FAIL, "Hopen");
-
- ret_bool = Hishdf(TESTFILE_NAME);
- CHECK(ret_bool, FALSE, "Hishdf");
-
- ret = Hnewref(fid);
- CHECK(ret, FAIL, "Hnewref");
-
- printf("Reading / Writing to file\n");
- ret = Hputelement(fid, (uint16) 100, 1,
- (uint8 *) "testing 100 1", strlen("testing 100 1")+1);
- CHECK(ret, FAIL, "Hputelement");
-
- ret = Hputelement(fid, (uint16) 100, (uint16) 4, outbuf, 2000);
- CHECK(ret, FAIL, "Hputelement");
-
- ret = Hnewref(fid);
- CHECK(ret, FAIL, "Hnewref");
-
- ret = Hputelement(fid, (uint16) 103, (uint16) 2,
- (uint8 *) "element 103 2", strlen("element 103 2")+1);
- CHECK(ret, FAIL, "Hputlement");
-
- ret = Hgetelement(fid, (uint16) 100, (uint16) 4, inbuf);
- if(ret != 2000) {
- fprintf(stderr, "Hgetelement returned wrong count: %d\n", ret);
- errors++;
- }
-
- for (i=0; i<ret; i++) {
- if (inbuf[i] != outbuf[i])
- printf("Wrong data at %d, out %d in %d\n", i, outbuf[i], inbuf[i]);
- inbuf[i] = '\0';
- }
-
- ret = Hputelement(fid, 102, 2, outbuf, 4096);
- CHECK(ret, FAIL, "Hputlement");
-
- ret = Hclose(fid);
- CHECK(ret, FAIL, "Hclose");
-
- printf("\nClosing and re-opening file %s\n\n", TESTFILE_NAME);
- fid = Hopen(TESTFILE_NAME, DFACC_RDWR, 0);
- CHECK(fid, FAIL, "Hopen");
-
- ret = Hnewref(fid);
- CHECK(ret, FAIL, "Hnewref");
-
- aid1 = Hstartread(fid, 100, 1);
- CHECK(aid1, FAIL, "Hstartread");
-
- ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
- &access, &special);
- CHECK(ret, FAIL, "Hinquire");
-
- printf("Verifying data\n\n");
- ret = Hread(aid1, length, inbuf);
- if(ret != 14) {
- fprintf(stderr, "ERROR: Hread returned the wrong length: %d\n", ret);
- errors++;
- }
-
- if(strcmp((const char *)inbuf, "testing 100 1")) {
- fprintf(stderr, "ERROR: Hread returned the wrong data\n");
- fprintf(stderr, "\t Is: %s\n", inbuf);
- fprintf(stderr, "\tShould be: testing 100 1\n");
- errors++;
- }
-
- ret = Hnewref(fid);
- CHECK(ret, FAIL, "Hnewref");
-
- printf("Testing a number of searching schemes\n\n");
- ret = Hnextread(aid1, 100, DFREF_WILDCARD, DF_CURRENT);
- CHECK(ret, FAIL, "Hnextread");
-
- ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
- &access, &special);
- CHECK(ret, FAIL, "Hinquire");
-
- ret = Hnextread(aid1, 100, DFREF_WILDCARD, DF_CURRENT);
- if(ret != FAIL) {
- fprintf(stderr, "ERROR: Found a non-existant element at line %d\n",
- __LINE__);
- errors++;
- }
-
- ret = Hnextread(aid1, DFTAG_WILDCARD, DFREF_WILDCARD, DF_START);
- CHECK(ret, FAIL, "Hnextread");
-
- ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
- &access, &special);
- CHECK(ret, FAIL, "Hinquire");
-
- ret = Hnextread(aid1, DFTAG_WILDCARD, 3, DF_CURRENT);
- if(ret != FAIL) {
- fprintf(stderr, "ERROR: Found a non-existant element at line %d\n",
- __LINE__);
- errors++;
- }
-
- ret = Hnextread(aid1, DFTAG_WILDCARD, 2, DF_CURRENT);
- CHECK(ret, FAIL, "Hnextread");
-
- ret = Hinquire(aid1, &fileid, &tag, &ref, &length, &offset, &posn,
- &access, &special);
- CHECK(ret, FAIL, "Hinquire");
-
- aid2 = Hstartwrite(fid, 100, 1, 4);
- if(aid2 == FAIL) {
- fprintf(stderr, "ERROR: was not allowed to startwrite on existing object\n");
- errors++;
- }
-
- ret = Hwrite(aid1, 4, (uint8 *) "ABCD");
- if(ret != FAIL) {
- fprintf(stderr, "ERROR: was allowed to write to read access object\n");
- errors++;
- }
-
- ret = Hendaccess(aid1);
- CHECK(ret, FAIL, "Hendaccess");
-
- ret = Hendaccess(aid2);
- CHECK(ret, FAIL, "Hendaccess");
-
- printf("Attempting to gain multiple access to file (is allowed)\n");
- fid1 = Hopen(TESTFILE_NAME, DFACC_READ, 0);
- if(fid1 == FAIL) {
- fprintf(stderr, "ERROR: Failed to have two concurrent access to file\n");
- errors++;
- }
-
- ret = Hnewref(fid1);
- CHECK(ret, FAIL, "Hnewref");
-
- ret = Hclose(fid);
- CHECK(ret, FAIL, "Hclose");
-
- ret = Hclose(fid1);
- CHECK(ret, FAIL, "Hclose");
-
- ret_bool = Hishdf(TESTFILE_NAME);
- CHECK(ret_bool, FALSE, "Hishdf");
-
- ret_bool = Hishdf(__FILE__);
- CHECK(ret_bool, TRUE, "Hishdf");
-
- ret_bool = Hishdf("qqqqqqqq.qqq"); /* I sure hope it isn't there */
- CHECK(ret, TRUE, "Hishdf");
-
- if(errors)
- fprintf(stderr, "\n\t>>> %d errors were encountered <<<\n\n");
- else
- fprintf(stderr, "\n\t>>> All tests passed <<< \n\n");
-
- }
-