home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR24 / CFF51B.ZIP / MISCTEST.C < prev    next >
C/C++ Source or Header  |  1993-10-22  |  9KB  |  301 lines

  1. /* MISCTEST.C */
  2. /* Copyright 1990, 1991, 1992, 1993 Norman D. Culver Ft. Lauderdale, FL */
  3. /*                    All Rights Reserved                                   */
  4.  
  5. #include <stdlib.h>
  6. #include "../cff.h"
  7.  
  8. #define PACKSIZE 100
  9.  
  10. void *h1;
  11. void *h2;
  12. void *h3;
  13. void *h4;
  14. void *h5;
  15. void *h6;
  16.  
  17. static void print_dir(void *);
  18. static void dir_test(void);
  19. static void stat_test(void);
  20. static void trn_test(void);
  21.  
  22. void
  23. main()
  24. {
  25.     cfinit("misctest",1024,NULL);
  26.     cfprintf("MISCTEST: TEST OF VARIOUS FUNCTIONS\n");
  27.  
  28.     h1 = cfopen("testfile.cff", F_RDWR|F_CREAT, NULL);
  29.     cfdef("TESTFILE", "testfile.cff");
  30.     if(h1 == NULL)
  31.         cfprintf("Failed to create TESTFILE\n");
  32.  
  33.     h2 = cfopen("TESTFILE/object1", F_RDWR|F_CREAT, NULL);
  34.     cfdef("OBJECT1", "TESTFILE/object1");
  35.     if(h2 == NULL)
  36.         cfprintf("Failed to create OBJECT1\n");
  37.  
  38.     h3 = cfopen("OBJECT1/object2", F_RDWR|F_CREAT|F_SORTED, NULL);
  39.     cfdef("OBJECT2", "OBJECT1/object2");
  40.     if(h3 == NULL)
  41.         cfprintf("Failed to create OBJECT2\n");
  42.  
  43.     h4 = cfopen("OBJECT2/object3", F_RDWR|F_CREAT, NULL);
  44.     cfdef("OBJECT3", "OBJECT2/object3");
  45.     if(h4 == NULL)
  46.         cfprintf("Failed to create OBJECT3\n");
  47.  
  48.     h5 = cfopen("OBJECT2/object4", F_RDWR|F_CREAT, NULL);
  49.     cfdef("OBJECT4", "OBJECT2/object4");
  50.     if(h5 == NULL)
  51.         cfprintf("Failed to create OBJECT4\n");
  52.  
  53.     cfdef("PLAINFILE", "plnfile.xxx");
  54.     h6 = cfopen("PLAINFILE", F_RDWR|F_CREAT, NULL);
  55.     if(h6 == NULL)
  56.         cfprintf("Failed to create PLAINFILE\n");
  57.  
  58.  
  59.     trn_test();
  60.     stat_test();
  61.     dir_test();
  62.     cfunlink("TESTFILE");
  63.     cfunlink("PLAINFILE");
  64.  
  65.     cfexit();
  66. } /* MAIN */
  67.  
  68. static void
  69. trn_test()
  70. {
  71. char *newpath;
  72. int type;
  73.  
  74.     cfprintf("\nNAME TRANSLATION TESTS\n");
  75.     type = cfpathtrn(".", &newpath);
  76.     cfprintf("%s becomes %s type=%d\n", ".", newpath, type);
  77.     free(newpath);
  78.     type = cfpathtrn("./xx.cff", &newpath);
  79.     cfprintf("%s becomes %s type=%d\n", "./xx.cff", newpath, type);
  80.     free(newpath);
  81.     type = cfpathtrn("./xx.cff/abc/def", &newpath);
  82.     cfprintf("%s becomes %s type=%d\n", "./xx.cff/abc/def", newpath, type);
  83.     free(newpath);
  84.     type = cfpathtrn("TESTFILE", &newpath);
  85.     cfprintf("%s becomes %s type=%d\n", "TESTFILE", newpath, type);
  86.     free(newpath);
  87.     type = cfpathtrn("OBJECT1", &newpath);
  88.     cfprintf("%s becomes %s type=%d\n", "OBJECT1", newpath, type);
  89.     free(newpath);
  90.     type = cfpathtrn("OBJECT2", &newpath);
  91.     cfprintf("%s becomes %s type=%d\n", "OBJECT2", newpath, type);
  92.     free(newpath);
  93.     type = cfpathtrn("OBJECT3", &newpath);
  94.     cfprintf("%s becomes %s type=%d\n", "OBJECT3", newpath, type);
  95.     free(newpath);
  96.     type = cfpathtrn("OBJECT4", &newpath);
  97.     cfprintf("%s becomes %s type=%d\n", "OBJECT4", newpath, type);
  98.     free(newpath);
  99.     type = cfpathtrn("PLAINFILE", &newpath);
  100.     cfprintf("%s becomes %s type=%d\n", "PLAINFILE", newpath, type);
  101.     free(newpath);
  102. }
  103.  
  104. static void
  105. stat_test()
  106. {
  107. CFSTAT stats;
  108.  
  109.     cfprintf("\nSTAT TESTS\n");
  110.     if(cfstat(".", &stats) == OK)
  111.         cfprintf("mode of . = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  112.     else
  113.         cfprintf("stat of . failed\n");
  114.  
  115.     cfprintf("STAT FILES THAT ARE OPEN by name\n");
  116.     if(cfstat("PLAINFILE", &stats) == OK)
  117.         cfprintf("mode of PLAINFILE = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  118.     else
  119.         cfprintf("stat of PLAINFILE failed\n");
  120.  
  121.     if(cfstat("TESTFILE", &stats) == OK)
  122.         cfprintf("mode of TESTFILE = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  123.     else
  124.         cfprintf("stat of TESTFILE failed\n");
  125.  
  126.     if(cfstat("OBJECT1", &stats) == OK)
  127.         cfprintf("mode of OBJECT1 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  128.     else
  129.         cfprintf("stat of OBJECT1 failed\n");
  130.  
  131.     if(cfstat("OBJECT2", &stats) == OK)
  132.         cfprintf("mode of OBJECT2 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  133.     else
  134.         cfprintf("stat of OBJECT2 failed\n");
  135.  
  136.     if(cfstat("OBJECT3", &stats) == OK)
  137.         cfprintf("mode of OBJECT3 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  138.     else
  139.         cfprintf("stat of OBJECT3 failed\n");
  140.  
  141.     if(cfstat("OBJECT4", &stats) == OK)
  142.         cfprintf("mode of OBJECT4 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  143.     else
  144.         cfprintf("stat of OBJECT4 failed\n");
  145.  
  146.     cfprintf("STAT FILES THAT ARE OPEN by handle\n");
  147.  
  148.     if(cfstat(h1, &stats) == OK)
  149.         cfprintf("mode of h1 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  150.     else
  151.         cfprintf("stat of h1 failed\n");
  152.  
  153.     if(cfstat(h2, &stats) == OK)
  154.         cfprintf("mode of h2 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  155.     else
  156.         cfprintf("stat of h2 failed\n");
  157.  
  158.     if(cfstat(h3, &stats) == OK)
  159.         cfprintf("mode of h3 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  160.     else
  161.         cfprintf("stat of h3 failed\n");
  162.  
  163.     if(cfstat(h4, &stats) == OK)
  164.         cfprintf("mode of h4 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  165.     else
  166.         cfprintf("stat of h4 failed\n");
  167.  
  168.     if(cfstat(h5, &stats) == OK)
  169.         cfprintf("mode of h5 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  170.     else
  171.         cfprintf("stat of h5 failed\n");
  172.  
  173.     if(cfstat(h6, &stats) == OK)
  174.         cfprintf("mode of h6 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  175.     else
  176.         cfprintf("stat of h6 failed\n");
  177.  
  178.     cfprintf("GET OBTYPE OF FILES THAT ARE OPEN by handle\n");
  179.     cfprintf("obtype of h1 = %lx\n", cfobtype(h1));
  180.     cfprintf("obtype of h2 = %lx\n", cfobtype(h2));
  181.     cfprintf("obtype of h3 = %lx\n", cfobtype(h3));
  182.     cfprintf("obtype of h4 = %lx\n", cfobtype(h4));
  183.     cfprintf("obtype of h5 = %lx\n", cfobtype(h5));
  184.     cfprintf("obtype of h6 = %lx\n", cfobtype(h6));
  185.  
  186.     cfprintf("GET OBTYPE OF FILES THAT ARE OPEN by name\n");
  187.     cfprintf("obtype of TESTFILE = %lx\n", cfobtype("TESTFILE"));
  188.     cfprintf("obtype of OBJECT1 = %lx\n", cfobtype("OBJECT1"));
  189.     cfprintf("obtype of OBJECT2 = %lx\n", cfobtype("OBJECT2"));
  190.     cfprintf("obtype of OBJECT3 = %lx\n", cfobtype("OBJECT3"));
  191.     cfprintf("obtype of OBJECT4 = %lx\n", cfobtype("OBJECT4"));
  192.     cfprintf("obtype of PLAINFILE = %lx\n", cfobtype("PLAINFILE"));
  193.  
  194.  
  195.  
  196.     cfprintf("CLOSE THE OPEN FILES\n");
  197.     cfclose(h1);
  198.     cfclose(h2);
  199.     cfclose(h3);
  200.     cfclose(h4);
  201.     cfclose(h5);
  202.     cfclose(h6);
  203.  
  204.     cfprintf("STAT FILES THAT ARE CLOSED by name\n");
  205.     if(cfstat("PLAINFILE", &stats) == OK)
  206.         cfprintf("mode of PLAINFILE = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  207.     else
  208.         cfprintf("stat of PLAINFILE failed\n");
  209.  
  210.     if(cfstat("TESTFILE", &stats) == OK)
  211.         cfprintf("mode of TESTFILE = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  212.     else
  213.         cfprintf("stat of TESTFILE failed\n");
  214.  
  215.     if(cfstat("OBJECT1", &stats) == OK)
  216.         cfprintf("mode of OBJECT1 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  217.     else
  218.         cfprintf("stat of OBJECT1 failed\n");
  219.  
  220.     if(cfstat("OBJECT2", &stats) == OK)
  221.         cfprintf("mode of OBJECT2 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  222.     else
  223.         cfprintf("stat of OBJECT2 failed\n");
  224.  
  225.     if(cfstat("OBJECT3", &stats) == OK)
  226.         cfprintf("mode of OBJECT3 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  227.     else
  228.         cfprintf("stat of OBJECT3 failed\n");
  229.  
  230.     if(cfstat("OBJECT4", &stats) == OK)
  231.         cfprintf("mode of OBJECT4 = %lx obtype=%lx\n", stats.st_mode, stats.st_obtype);
  232.     else
  233.         cfprintf("stat of OBJECT4 failed\n");
  234.  
  235.  
  236.     cfprintf("GET OBTYPE OF FILES THAT ARE CLOSED by name\n");
  237.     cfprintf("obtype of PLAINFILE = %lx\n", cfobtype("PLAINFILE"));
  238.     cfprintf("obtype of TESTFILE = %lx\n", cfobtype("TESTFILE"));
  239.     cfprintf("obtype of OBJECT1 = %lx\n", cfobtype("OBJECT1"));
  240.     cfprintf("obtype of OBJECT2 = %lx\n", cfobtype("OBJECT2"));
  241.     cfprintf("obtype of OBJECT3 = %lx\n", cfobtype("OBJECT3"));
  242.     cfprintf("obtype of OBJECT4 = %lx\n", cfobtype("OBJECT4"));
  243.  
  244.     cfprintf("REOPEN THE FILES\n");
  245.     h3 = cfopen("OBJECT2", F_RDWR, NULL);
  246.     h1 = cfopen("TESTFILE", F_RDWR, NULL);
  247.     h2 = cfopen("OBJECT1", F_RDWR, NULL);
  248.     h6 = cfopen("PLAINFILE", F_RDWR, NULL);
  249.     h4 = cfopen("OBJECT3", F_RDWR, NULL);
  250.     h5 = cfopen("OBJECT4", F_RDWR, NULL);
  251. }
  252.  
  253. static void
  254. dir_test()
  255. {
  256.     cfprintf("\nDIRECTORY SCAN TESTS\n");
  257.     cfprintf("DIRECTORY of .\n");
  258.     print_dir(".");
  259.     cfprintf("DIRECTORY of TESTFILE open by handle\n");
  260.     print_dir(h1);
  261.     cfprintf("DIRECTORY of TESTFILE open by name\n");
  262.     print_dir("TESTFILE");
  263.     cfprintf("DIRECTORY of OBJECT1 open by handle\n");
  264.     print_dir(h2);
  265.     cfprintf("DIRECTORY of OBJECT1 open by name\n");
  266.     print_dir("OBJECT1");
  267.     cfprintf("DIRECTORY of OBJECT2 open by handle\n");
  268.     print_dir(h3);
  269.     cfprintf("DIRECTORY of OBJECT2 open by name\n");
  270.     print_dir("OBJECT2");
  271.  
  272.     cfprintf("\nCLOSE THE FILES\n");
  273.     cfclose(h1);
  274.     cfclose(h2);
  275.     cfclose(h3);
  276.     cfclose(h4);
  277.     cfclose(h5);
  278.     cfclose(h6);
  279.  
  280.     cfprintf("DIRECTORY of TESTFILE closed by name\n");
  281.     print_dir("TESTFILE");
  282.     cfprintf("DIRECTORY of OBJECT1 closed by name\n");
  283.     print_dir("OBJECT1");
  284.     cfprintf("DIRECTORY of OBJECT2 closed by name\n");
  285.     print_dir("OBJECT2");
  286. }
  287. static void
  288. print_dir(void *path)
  289. {
  290. void *h;
  291. CFDIRENT *dir;
  292. int i = 0;
  293.  
  294.     h = cfopendir(path,NULL);
  295.     while((dir = cfreaddir(h))) {
  296.         cfprintf("%d:\t%s\n", ++i, dir->d_name);
  297.     }
  298.     cfclosedir(h);
  299. }
  300.  
  301.