home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / hdf / unix / hdf3_2r2 / test / tstubs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-29  |  13.3 KB  |  452 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.7 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/test/RCS/tstubs.c,v 1.7 1992/06/30 23:24:53 chouck beta koziol $
  30.  
  31. $Log: tstubs.c,v $
  32.  * Revision 1.7  1992/06/30  23:24:53  chouck
  33.  * Fixed call to delete file under VMS
  34.  *
  35.  * Revision 1.6  1992/06/02  16:04:38  dilg
  36.  * Fixed error in expected return code from DFputelement().
  37.  *
  38.  * Revision 1.5  1992/06/01  19:41:48  dilg
  39.  * Added explicit test for dangling aids.
  40.  *
  41.  * Revision 1.4  1992/05/07  16:37:55  dilg
  42.  * Changed output file name frm "o1" to "tstubs.hdf"
  43.  *
  44.  * Revision 1.3  1992/04/28  19:36:55  dilg
  45.  * Some minor cosmetic changes.
  46.  *
  47.  * Revision 1.2  1992/04/28  19:09:29  dilg
  48.  * Corrected incorrect expected return value for DFwrite on line 347.
  49.  *
  50.  * Revision 1.1  1992/02/26  23:05:33  dilg
  51.  * Initial revision
  52.  *
  53. */
  54. #include <stdio.h>
  55. #include "df.h"
  56.  
  57. int nerrors = 0;
  58. char ar0[] = "Testing...";
  59. char ar1[] = "...one...";
  60. char ar2[30] = "...two...";
  61. char ar3[] = "...three";
  62.  
  63. main()
  64. {
  65.     DF *dfile;
  66.     DFdata dfinfo;
  67.     DFdesc dlist[5];
  68.     char in[20];
  69.     int a0size, a1size, a2size, a3size;
  70.     int ret, err, i, nd;
  71.  
  72.  
  73.     a0size = strlen(ar0) + 1;
  74.     a1size = strlen(ar1) + 1;
  75.     a2size = strlen(ar2) + 1;
  76.     a3size = strlen(ar3) + 1;
  77.  
  78.     printf("This program will test the DF emulation layer\n");
  79.     printf("of HDF 3.2 and beyond.  Many routines will be\n");
  80.     printf("tested individually.  Each test will report its\n");
  81.     printf("name and results.  If all goes well, all of the\n");
  82.     printf("results will begin with 'Success'.  If a test\n");
  83.     printf("fails, the results line will begin with '>>>Failure'.\n");
  84.     printf("An error count is kept and printed out at the end.\n");
  85.     printf("\nHit <return> to continue.");
  86.     getchar();
  87.  
  88. #if defined PC || defined VMS
  89. #ifdef VMS
  90.     system("del tstubs.hdf;*");
  91. #else
  92.     system("del tstubs.hdf");
  93. #endif
  94. #else
  95.     system("rm tstubs.hdf");
  96. #endif /* PC || VMS */
  97.  
  98.     printf("\nTesting DFishdf... (should fail with error %d)\n", DFE_BADOPEN);
  99.     ret = DFishdf("tstubs.hdf");
  100.     if (ret == -1) {
  101.     printf("Success:  DFishdf failed with DFerror = %d\n", DFerror);
  102.     } else {
  103.     printf("Failure at line %d:  ", __LINE__ - 5);
  104.     printf("Non-existent file looks like HDF file.\n");
  105.     nerrors++;
  106.     }
  107.  
  108.     printf("\nTesting DFopen... (new file)\n");
  109.     dfile = DFopen("tstubs.hdf", DFACC_WRITE|DFACC_CREATE, 0);
  110.     if (dfile == (DF *)NULL) {
  111.     printf("***ERROR %d opening file.\n", DFerror);
  112.     exit(1);
  113.     } else
  114.     printf("Success!\n");
  115.  
  116.     printf("\nTesting DFclose...\n");
  117.     ret = DFclose(dfile);
  118.     if (ret == -1) {
  119.     printf(">>>Close failed at line %d.\n", __LINE__ - 2);
  120.     printf("   DFerror = %d\n", DFerror);
  121.     nerrors++;
  122.     } else
  123.     printf("Success!\n");
  124.  
  125.     printf("\nTesting DFclose... (invalid file; should fail with error %d)\n",
  126.        DFE_NOTOPEN);
  127.     ret = DFclose(dfile);
  128.     if (ret == -1) {
  129.     printf("Success: DFclose failed with DFerror = %d\n", DFerror);
  130.     } else {
  131.     printf(">>>Failure at line %d:  Close allowed on unopened file.\n",
  132.         __LINE__ - 4);
  133.     nerrors++;
  134.     }
  135.  
  136.     printf("\nTesting DFerrno...\n");
  137.     ret = DFerrno();
  138.     if (ret != DFerror) {
  139.     printf(">>>DFerrno failed at line %d.  Returned %d\n",__LINE__ - 2,ret);
  140.     printf("   DFerror = %d\n", DFerror);
  141.     nerrors++;
  142.     } else
  143.     printf("Success!\n");
  144.  
  145.     printf("\nTesting DFopen... (existing file)\n");
  146.     dfile = DFopen("tstubs.hdf", DFACC_WRITE, 0);
  147.     if (dfile == (DF *)NULL) {
  148.     printf("***ERROR %d opening file.\n", DFerror);
  149.     exit(1);
  150.     } else
  151.     printf("Success!\n");
  152.  
  153.     printf("\nTesting DFputelement...\n");
  154.     ret = DFputelement(dfile, (uint16)255, (uint16)1, ar0, a0size);
  155.     if (ret != a0size) {
  156.     printf(">>>Write failed at line %d.\n", __LINE__ - 2);
  157.     printf("   DFerror = %d\n", DFerror);
  158.     nerrors++;
  159.     } else
  160.     printf("Success!\n");
  161.  
  162.     printf("\nTesting DFgetelement...\n");
  163.     ret = DFgetelement(dfile, (uint16)255, (uint16)1, in);
  164.     if (ret != a0size) {
  165.     printf(">>>Read failed at line %d.\n", __LINE__ - 2);
  166.     printf("   String read:  %-20s\n", in);
  167.     printf("   DFerror = %d\n", DFerror);
  168.     nerrors++;
  169.     } else {
  170.     err = 0;
  171.     for (i=0; i<a0size; i++) {
  172.         if (in[i] != ar0[i])
  173.         err = 1;
  174.     }
  175.     if (err == 1) {
  176.         printf(">>>Read failed at line %d:  strings differ.\n",__LINE__-13);
  177.         printf("   String written:  %-20s\n", ar0);
  178.         printf("   String read:     %-20s\n", in);
  179.         nerrors++;
  180.     } else
  181.         printf("Success:  string read is the same as string written.\n");
  182.     }
  183.     for (i=0; i<20; i++)
  184.     in[i] = (char)0;
  185.  
  186.     printf("\nTesting DFaccess (write)...\n");
  187.     ret = DFaccess(dfile, (uint16)255, (uint16)3, "w");
  188.     if (ret == -1) {
  189.     printf(">>>Write access failed at line %d.\n", __LINE__ - 2);
  190.     printf("   DFerror = %d\n", DFerror);
  191.     nerrors++;
  192.     } else
  193.     printf("Success!\n");
  194.  
  195.     printf("\nTesting DFread... (should fail with error %d)\n", DFE_ARGS);
  196.     ret = DFread(dfile, in, 5);
  197.     if (ret == -1) {
  198.     printf("Success:  DFread failed with DFerror = %d\n", DFerror);
  199.     } else {
  200.     printf(">>>Failure at line %d:  ", __LINE__ - 4);
  201.     printf("Read allowed on element set up for write.\n");
  202.     nerrors++;
  203.     }
  204.     for (i=0; i<20; i++)
  205.     in[i] = (char)0;
  206.  
  207.     printf("\nTesting DFwrite...\n");
  208.     ret = DFwrite(dfile, ar1, a1size);
  209.     if (ret != a1size) {
  210.     printf(">>>Write failed at line %d.  Wrote %d of %d bytes.\n",
  211.         __LINE__ - 3, ret, a1size);
  212.     printf("   DFerror = %d\n", DFerror);
  213.     nerrors++;
  214.     } else
  215.     printf("Success!\n");
  216.  
  217.     printf("\nTesting DFaccess (read)...\n");
  218.     ret = DFaccess(dfile, (uint16)255, (uint16)3, "r");
  219.     if (ret == -1) {
  220.     printf(">>>Read access failed at line %d.\n", __LINE__ - 2);
  221.     printf("   DFerror = %d\n", DFerror);
  222.     nerrors++;
  223.     } else
  224.     printf("Success!\n");
  225.  
  226.     printf("\nTesting DFwrite... (should fail with error %d)\n", DFE_BADACC);
  227.     ret = DFwrite(dfile, in, 5);
  228.     if (ret == -1) {
  229.     printf("Success:  DFwrite failed with DFerror = %d\n", DFerror);
  230.     } else {
  231.     printf(">>>Failure at line %d:  ", __LINE__ - 4);
  232.     printf("Write allowed on element set up for read.\n");
  233.     nerrors++;
  234.     }
  235.  
  236.     printf("\nTesting DFread...\n");
  237.     ret = DFread(dfile, in, a1size);
  238.     if (ret != a1size) {
  239.     printf(">>>Read failed at line %d.  Read %d of %d bytes.\n",
  240.         __LINE__ - 3, ret, a1size);
  241.     printf("   String read:  %-20s\n", in);
  242.     printf("   DFerror = %d\n", DFerror);
  243.     nerrors++;
  244.     } else {
  245.     err = 0;
  246.     for (i=0; i<a1size; i++) {
  247.         if (in[i] != ar1[i])
  248.         err = 1;
  249.     }
  250.     if (err == 1) {
  251.         printf(">>>Read failed at line %d:  strings differ.\n",__LINE__-14);
  252.         printf("   String written:  %-20s\n", ar1);
  253.         printf("   String read:     %-20s\n", in);
  254.         nerrors++;
  255.     } else
  256.         printf("Success:  string read is the same as string written.\n");
  257.     }
  258.     for (i=0; i<20; i++)
  259.     in[i] = (char)0;
  260.  
  261.     printf("\nTesting DFnumber...\n");
  262.     nd = DFnumber(dfile, (uint16)255);
  263.     if (nd != 2) {
  264.     printf(">>>DFnumber failed at line %d.  ", __LINE__ - 2);
  265.     printf("Reported %d occurrances of tag 255\n", nd);
  266.     printf("   rather than 2.\n");
  267.     printf("   DFerror = %d\n", DFerror);
  268.     nerrors++;
  269.     } else
  270.     printf("Success!\n");
  271.     
  272.     printf("\nTesting DFdescriptors...\n");
  273.     ret = DFdescriptors(dfile, dlist, 0, 5);
  274.     if (ret != (nd + 1)) {
  275.     printf(">>>DFdescriptors failed at line %d.  Returned %d\n",
  276.         __LINE__ - 3, ret);
  277.     printf("   DFerror = %d\n", DFerror);
  278.     nerrors++;
  279.     } else
  280.     if ((dlist[1].tag != 255) || (dlist[1].ref != 1) ||
  281.         (dlist[1].length != a0size) || (dlist[2].tag != 255) ||
  282.         (dlist[2].ref != 3) || (dlist[2].length != a1size)) {
  283.         printf(">>>DFdescriptors failed at line %d.  ", __LINE__ - 10);
  284.         printf("Descriptors have unexpected values\n");
  285.         nerrors++;
  286.         } else
  287.         printf("Success!\n");
  288.  
  289.     printf("\nTesting DFupdate\n");
  290.     ret = DFupdate(dfile);
  291.     if (ret != 0) {
  292.     printf(">>>DFupdate failed at line %d.\n", __LINE__ - 2);
  293.     printf("   DFerror = %d\n", DFerror);
  294.     nerrors++;
  295.     } else
  296.     printf("Success!\n");
  297.  
  298.     printf("\nTesting DFstat\n");
  299.     ret = DFstat(dfile, &dfinfo);
  300.     if (ret != 0) {
  301.     printf(">>>DFstat failed at line %d.\n", __LINE__ - 2);
  302.     printf("   DFerror = %d\n", DFerror);
  303.     nerrors++;
  304.     } else
  305.     printf("Success!\n");
  306.     
  307.     printf("\nTesting DFnewref...\n");
  308.     ret = DFnewref(dfile);
  309.     if (ret != 4) {
  310.     printf(">>>DFnewref failed at line %d.  ", __LINE__ - 2);
  311.     printf("Returned ref. no. %d instead of 4\n", ret);
  312.     printf("   DFerror = %d\n", DFerror);
  313.     nerrors++;
  314.     } else
  315.     printf("Success!\n");
  316.  
  317.     printf("\nTesting DFdup...\n");
  318.     ret = DFdup(dfile, (uint16)127, (uint16)7, (uint16)255, (uint16)3);
  319.     if (ret == -1) {
  320.     printf(">>>DFdup failed at line %d.\n", __LINE__ - 2);
  321.     printf("   DFerror = %d\n", DFerror);
  322.     nerrors++;
  323.     } else {
  324.     ret = DFnumber(dfile, (uint16)127);
  325.     if (ret != 1) {
  326.         printf(">>>DFdup failed at line %d.  Duplicated tag not found.\n",
  327.            __LINE__ - 8);
  328.         printf("   DFerror = %d\n", DFerror);
  329.         nerrors++;
  330.     } else
  331.         printf("Success!\n");
  332.     }
  333.  
  334.     printf("\nTesting DFdel...\n");
  335.     ret = DFdel(dfile, (uint16)127, (uint16)7);
  336.     if (ret == -1) {
  337.     printf(">>>DFdel failed at line %d.\n", __LINE__ - 2);
  338.     printf("   DFerror = %d\n", DFerror);
  339.     nerrors++;
  340.     } else {
  341.     ret = DFnumber(dfile, (uint16)127);
  342.     if (ret != 0) {
  343.         printf(">>>DFdel failed at line %d.  ", __LINE__ - 8);
  344.         printf("Found %d instances of deleted tag.\n", ret);
  345.         printf("   DFerror = %d\n", DFerror);
  346.         nerrors++;
  347.     } else
  348.         printf("Success!\n");
  349.     }
  350.  
  351.     printf("\nTesting DFsetfind...\n");
  352.     ret = DFsetfind(dfile, (uint16)254, (uint16)0);
  353.     if (ret == -1) {
  354.     printf(">>>DFsetfind failed at line %d.\n", __LINE__ - 2);
  355.     printf("   DFerror = %d\n", DFerror);
  356.     nerrors++;
  357.     } else
  358.     printf("Success!\n");
  359.  
  360.     printf("\nTesting DFfind...\n");
  361.     ret = DFdup(dfile, (uint16)254, (uint16)4, (uint16)255, (uint16)3);
  362.     if (ret != 0)
  363.         printf(">>>DFdup 1 failed.\n");
  364.     ret = DFdup(dfile, (uint16)254, (uint16)5, (uint16)255, (uint16)3);
  365.     if (ret != 0)
  366.         printf(">>>DFdup 2 failed.\n");
  367.     ret = DFdup(dfile, (uint16)254, (uint16)6, (uint16)255, (uint16)3);
  368.     if (ret != 0)
  369.         printf(">>>DFdup 3 failed.\n");
  370.     for (i=4; i<7; i++) {
  371.     ret = DFfind(dfile, dlist);
  372.     if (ret == -1) {
  373.     printf(">>>DFfind failed at line %d.\n", __LINE__ - 2);
  374.     printf("   DFerror = %d\n", DFerror);
  375.     nerrors++;
  376.     } else
  377.     if ((dlist[0].tag != 254) || (dlist[0].ref != i) ||
  378.         (dlist[0].length != a1size)) {
  379.         printf(">>>DFfind failed at line %d.  ", __LINE__ - 8);
  380.         printf("Descriptor has unexpected values\n");
  381.         nerrors++;
  382.         } else
  383.         printf("Success!\n");
  384.     } /* for i */
  385.  
  386.     printf("\nTesting appending...\n");
  387.     ret = DFputelement(dfile, (uint16)255, (uint16)7, ar2, a2size);
  388.     if (ret != a2size) {
  389.     printf(">>>Write failed at line %d.\n", __LINE__ - 2);
  390.     printf("   DFerror = %d\n", DFerror);
  391.     nerrors++;
  392.     } else {
  393.     ret = DFaccess(dfile, (uint16)255, (uint16)7, "a");
  394.         if (ret != 0) {
  395.         printf(">>>DFaccess failed at line %d.\n", __LINE__ - 2);
  396.         printf("   DFerror = %d\n", DFerror);
  397.         nerrors++;
  398.         } else {
  399.         ret = DFseek(dfile, a2size - 1);
  400.             if (ret != 0) {
  401.             printf(">>>DFseek failed at line %d.\n", __LINE__ - 2);
  402.             printf("   DFerror = %d\n", DFerror);
  403.             nerrors++;
  404.             } else {
  405.         ret = DFwrite(dfile, ar3, a3size);
  406.                 if (ret != a3size) {
  407.                 printf(">>>DFwrite failed at line %d.\n", __LINE__ - 2);
  408.                 printf("   DFerror = %d\n", DFerror);
  409.                 nerrors++;
  410.                 } else {
  411.             strcat(ar2, ar3);
  412.             ret = DFgetelement(dfile, (uint16)255, (uint16)7, in);
  413.                 if (ret != strlen(ar2)+1) {
  414.             printf(">>>Read failed at line %d.\n", __LINE__ - 2);
  415.             printf("   String read:  %-20s\n", in);
  416.             printf("   DFerror = %d\n", DFerror);
  417.             nerrors++;
  418.                 } else {
  419.             err = 0;
  420.             for (i=0; i<strlen(ar2)+1; i++) {
  421.                 if (in[i] != ar2[i])
  422.                 err = 1;
  423.             }
  424.             if (err == 1) {
  425.                 printf(">>>Append failed at line %d:", __LINE__-13);
  426.                 printf("  strings differ.\n");
  427.                 printf("   String written:  %-20s\n", ar2);
  428.                 printf("   String read:     %-20s\n", in);
  429.                 nerrors++;
  430.             } else {
  431.                     printf("Success!\n");
  432.             }
  433.             }
  434.         }
  435.         }
  436.     }
  437.     }
  438.  
  439.     ret = DFclose(dfile);
  440.     if (ret != 0) {
  441.     printf(">>>Failure:  DFclose failed (probably due to open aids)\n");
  442.     printf("   DFerror = %d\n", DFerror);
  443.     HEprint(stderr, 0);
  444.     nerrors++;
  445.     }
  446.  
  447.     printf("\n\nTest Summary:\n");
  448.     printf("   %d errors were encountered.\n", nerrors);
  449.     if (nerrors != 0)
  450.     printf("   Please check program output carefully.\n");
  451. }
  452.