home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / hdf / unix / hdf3_2r2 / test / tanfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-29  |  5.6 KB  |  177 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.1 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/test/RCS/tanfile.c,v 1.1 1992/02/28 22:21:15 mfolk beta koziol $
  30.  
  31. $Log: tanfile.c,v $
  32.  * Revision 1.1  1992/02/28  22:21:15  mfolk
  33.  * Initial revision
  34.  *
  35.  * Revision 1.1  1992/02/28  22:19:20  mfolk
  36.  * Initial revision
  37.  *
  38. */
  39. #include "hdf.h"
  40.  
  41. #define TESTFILE "tdfan.hdf"
  42. #define RESULT(a) if (ret == -1) {                              \
  43.                       printf( "%s FAILED: ret = %d\n", a, ret);  \
  44.                       testflag = FAIL;                          \
  45.                   } else                                        \
  46.                       printf("%s SUCCESSFUL\n", (a)); 
  47.  
  48. #define ISFIRST    (int)1
  49. #define NOTFIRST   (int)0
  50. #define MAXLEN_LAB     50
  51. #define MAXLEN_DESC  1000
  52.  
  53. main()
  54. {
  55.     char lab1[MAXLEN_LAB], lab2[MAXLEN_LAB],
  56.          desc1[MAXLEN_DESC], desc2[MAXLEN_DESC],
  57.          tempstr[MAXLEN_DESC];
  58.     uint16 ref1, ref2, ref3;
  59.     int32 testflag = SUCCEED;
  60.     int32 file_id, ret;
  61.  
  62. /* set up file labels and descriptions */
  63.  
  64.     strcpy(lab1, "File label #1: aaa");
  65.     strcpy(lab2, "File label #2: bbbbbb");
  66.     strcpy(desc1,"File Descr #1: 1  2  3  4  5  6  7  8  9 10 11 12 13\n" );
  67.     strcat(desc1,"              14 15 16 17 18 19 20 **END FILE DESCR**\n");
  68.     strcpy(desc2,"File Descr #2: A B C D E F G H I J K L\n");
  69.     strcat(desc2, "              M N O **END FILE DESCR**\n");
  70.  
  71.  
  72.  
  73. /********  Write file labels and descriptions *********/
  74.  
  75.     file_id = Hopen(TESTFILE, DFACC_CREATE, 0);
  76.     if (file_id == FAIL) 
  77.         printf("\nUnable to open file %s for writing.\n\n", TESTFILE);
  78.  
  79.     puts("\nWriting file labels.\n");
  80.     ret = DFANaddfid(file_id, lab1);
  81.     RESULT("DFANaddfid");
  82.  
  83.     ret = DFANaddfid(file_id, lab2);
  84.     RESULT("DFANaddfid");
  85.  
  86.     puts("\nWriting file descriptions.\n");
  87.     ret = DFANaddfds(file_id, desc1, strlen(desc1));
  88.     RESULT("DFANaddfds");
  89.  
  90.     ret = DFANaddfds(file_id, desc2, strlen(desc2));
  91.     RESULT("DFANaddfds");
  92.  
  93.     if (FAIL == Hclose(file_id) ) 
  94.         printf("\nUnable to close file %s after writing.\n\n", TESTFILE);
  95.  
  96. /********  Read file labels *********/
  97.  
  98.     file_id = Hopen(TESTFILE, DFACC_READ, 0);
  99.     if (file_id == FAIL)
  100.         printf("\n\nUnable to open file %s for reading.\n\n", TESTFILE);
  101.     
  102.     puts("\nReading length of first file label, followed by label.\n");
  103.     ret = DFANgetfidlen(file_id, ISFIRST); 
  104.     RESULT("DFANgetfidlen"); 
  105.     checkannlen(ret, lab1, "label", &testflag);
  106.  
  107.     ret = DFANgetfid(file_id, tempstr, MAXLEN_LAB, ISFIRST );
  108.     RESULT("DFANgetfid");
  109.     checkann (lab1, tempstr, ret, "label", testflag);
  110.  
  111.     puts("\nReading length of second file label, followed by label.\n");
  112.     ret = DFANgetfidlen(file_id, NOTFIRST);
  113.     RESULT("DFANgetfidlen");
  114.     checkannlen(ret, lab2, "label", &testflag);
  115.  
  116.     ret = DFANgetfid(file_id, tempstr, MAXLEN_LAB, NOTFIRST );
  117.     RESULT("DFANgetfid");
  118.     checkann (lab2, tempstr, ret, "label", testflag);
  119.  
  120. /********  Read file descriptions *********/
  121.  
  122.     puts("\nReading length of first file descr, followed by descr.\n");
  123.     ret = DFANgetfdslen(file_id, ISFIRST);
  124.     RESULT("DFANgetfdslen");
  125.     checkannlen(ret, desc1, "description", &testflag);
  126.  
  127.     ret = DFANgetfds(file_id, tempstr, MAXLEN_DESC, ISFIRST );
  128.     RESULT("DFANgetfds");
  129.     checkann (desc1, tempstr, ret, "description", testflag);
  130.  
  131.     puts("\nReading length of second file descr, followed by descr.\n");
  132.     ret = DFANgetfdslen(file_id, NOTFIRST);
  133.     RESULT("DFANgetfdslen");
  134.     checkannlen(ret, desc2, "description", &testflag);
  135.  
  136.     ret = DFANgetfds(file_id, tempstr, MAXLEN_DESC, NOTFIRST );
  137.     RESULT("DFANgetfds");
  138.     checkann (desc2, tempstr, ret, "description", testflag);
  139.  
  140.     if (FAIL == Hclose(file_id) ) 
  141.         printf("\n\nUnable to close file %s after reading.\n\n", TESTFILE);
  142.  
  143.     if ( testflag == SUCCEED)
  144.         printf("\n\n***** ALL TESTS SUCCESSFUL ***** \n\n");
  145.     else
  146.         printf("\n\n***** ONE OR MORE TESTS FAILED ***** \n\n");
  147. }
  148.  
  149. checkannlen(ret, oldstr, type, testflag)
  150. int32 ret, testflag;
  151. char *oldstr, *type;
  152. {
  153.     if ( (ret >=0) && (ret != strlen(oldstr)) ) {
  154.         printf("Length of %s is INCORRECT\n", type);
  155.         printf("It is:  %d\n", ret);
  156.         printf("It should be: %d\n", strlen(oldstr));
  157.         testflag = FAIL;
  158.         return FAIL;
  159.     }
  160.     return SUCCEED;
  161. }
  162.  
  163. checkann (oldstr, newstr, ret, type, testflag)
  164. char *oldstr, *newstr, *type;
  165. int32 ret, testflag;
  166. {
  167.     if ( (ret >=0) && (0 != strcmp(oldstr, newstr)) ) {
  168.         printf("%s is INCORRECT.\n", type);
  169.         printf("It is:  %s\n", newstr);
  170.         printf("It should be: %s\n", oldstr);
  171.         testflag = FAIL;
  172.         return (FAIL);
  173.     }
  174.     return (SUCCEED); 
  175. }
  176.  
  177.