home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / C / CL / CLTEST.CPP < prev   
C/C++ Source or Header  |  1991-12-13  |  5KB  |  230 lines

  1. #include "cl.h"
  2.  
  3. void checkName (CmdLn &CL,int no)
  4. {
  5.     char *p = CL.getName (no);
  6.     if (p)
  7.     {
  8.         cout << "Name value check failed " << p
  9.               << "Any key to continue ";
  10.         cin.get ();
  11.     }
  12. }
  13.  
  14. void checkOption (CmdLn &CL,int no)
  15. {
  16.     char *p;
  17.     char c = CL.getOption (no,p);
  18.     if (c != CL_ENDOFLIST)
  19.     {
  20.         cout << "Option value check failed " << c << "Any key to continue ";
  21.         cin.get ();
  22.     }
  23. }
  24.  
  25. void checkError (CmdLn &CL,int no)
  26. {
  27.     char c = CL.getError (no);
  28.     if (c != CL_ENDOFLIST)
  29.     {
  30.         cout << "Error value check failed " << c << "Any key to continue ";
  31.         cin.get ();
  32.     }
  33. }
  34.  
  35. int main ()
  36. {
  37.     int i;
  38.     char *p;
  39.     char c;
  40.     char s [81];
  41.  
  42.  
  43. // Parse the command line
  44.  
  45.     CmdLn CL ("cCe:E:gGhHl:L:o:O:P:p:vVxX");
  46.     clrscr ();
  47.     cout << "Command Line Parser Test - version " << CL.version () << endl;
  48.     cout << "Any key to continue "; cin.get ();
  49.  
  50. // Get additional user input
  51.  
  52.     cout << "Command Line Parsed" << endl;
  53.     CL.printContentsOn (cout);
  54.     cout << "Any key to continue "; cin.get ();
  55.  
  56.     clrscr ();
  57.     cout << "Enter additional test fields (Names or Options) - ";
  58.     cin.getline (s,80);
  59.     CL.add (s);
  60.     cout << "User input parsed" << endl;
  61.     CL.printContentsOn (cout);
  62.     cout << "Any key to continue "; cin.get ();
  63.  
  64. // Check invalid values
  65.  
  66.     clrscr ();
  67.     cout << "Checking invalid values" << endl;
  68.     checkName (CL,-1);
  69.     checkName (CL,999);
  70.     checkOption (CL,-1);
  71.     checkOption (CL,999);
  72.     checkError (CL,-1);
  73.     checkError (CL,999);
  74.     cout << "Any key to continue "; cin.get ();
  75.  
  76. // Examine the Name entries
  77.  
  78.     clrscr ();
  79.     cout << "Sequential Name Test" << endl;
  80.  
  81.     for (i = 0; i < CL.numNames (); i++)
  82.     {
  83.         p = CL.getName (i);
  84.         cout << "No " << i <<  " " << p << endl;
  85.     }
  86.     cout << "Any key to continue "; cin.get ();
  87.  
  88. // Examine the Option entries
  89.  
  90.     clrscr ();
  91.     cout << "Sequential Option Test" << endl;
  92.     for (i = 0; i < CL.numOptions (); i++)
  93.     {
  94.         c = CL.getOption (i,p);
  95.         cout << "No " << i <<  " Option " << c << ":" << p << endl;
  96.     }
  97.     cout << "Any key to continue "; cin.get ();
  98.  
  99. // Examine the Error entries
  100.  
  101.     clrscr ();
  102.     cout << "Sequential Error Test" << endl;
  103.     for (i = 0; i < CL.numErrors (); i++)
  104.     {
  105.         c = CL.getError (i);
  106.         cout << "No " << i <<  " Option " << c << endl;
  107.     }
  108.     cout << "Any key to continue "; cin.get ();
  109.  
  110. // Clear name entries
  111.  
  112.     clrscr ();
  113.     cout << "Clear Names Test" << endl;
  114.     CL.clearNames ();
  115.     CL.printContentsOn (cout);
  116.     cout << "Any key to continue "; cin.get ();
  117.  
  118. // Clear option entries
  119.  
  120.     clrscr ();
  121.     cout << "Clear Options Test" << endl;
  122.     CL.clearOptions ();
  123.     CL.printContentsOn (cout);
  124.     cout << "Any key to continue "; cin.get ();
  125.  
  126. // Clear error entries
  127.  
  128.     clrscr ();
  129.     cout << "Clear Errors Test" << endl;
  130.     CL.clearErrors ();
  131.     CL.printContentsOn (cout);
  132.     cout << "Any key to continue "; cin.get ();
  133.  
  134. // Clear all entries and reparse the command line
  135.  
  136.     clrscr ();
  137.     cout << "Reparse Command Line Test" << endl;
  138.     CL.reset ();
  139.     CL.printContentsOn (cout);
  140.     cout << "Any key to continue "; cin.get ();
  141.  
  142. // Get Last Name Test
  143.  
  144.     clrscr ();
  145.     cout << "Get Last Name Test" << endl;
  146.     p = CL.getLastName ();
  147.     cout << p << endl;
  148.     cout << "Any key to continue "; cin.get ();
  149.  
  150.     clrscr ();
  151.     cout << "Get First Name Test" << endl;
  152.     p = CL.getFirstName ();
  153.     cout << p << endl;
  154.     cout << "Any key to continue "; cin.get ();
  155.  
  156.     clrscr ();
  157.     cout << "Get Next Name Test" << endl;
  158.     while ((p = CL.getNextName ()) != NULL)
  159.     {
  160.         cout << p << endl;
  161.     }
  162.     cout << "Any key to continue "; cin.get ();
  163.  
  164.     clrscr ();
  165.     cout << "Get Previous Name Test" << endl;
  166.     p = CL.getLastName ();
  167.     while ((p = CL.getPrevName ()) != NULL)
  168.     {
  169.         cout << p << endl;
  170.     }
  171.     cout << "Any key to continue "; cin.get ();
  172.  
  173.     clrscr ();
  174.     cout << "Get Last Option Test" << endl;
  175.     c = CL.getLastOption (p);
  176.     cout << "Option " << c << ":" << p << endl;
  177.     cout << "Any key to continue "; cin.get ();
  178.  
  179.     clrscr ();
  180.     cout << "Get First Option Test" << endl;
  181.     c = CL.getFirstOption (p);
  182.     cout << "Option " << c << ":" << p << endl;
  183.     cout << "Any key to continue "; cin.get ();
  184.  
  185.     clrscr ();
  186.     cout << "Get Next Option Test" << endl;
  187.     while ((c = CL.getNextOption (p)) != CL_ENDOFLIST)
  188.     {
  189.         cout << "Option " << c << ":" << p << endl;
  190.     }
  191.     cout << "Any key to continue "; cin.get ();
  192.     clrscr ();
  193.     cout << "Get Previous Option Test" << endl;
  194.     c = CL.getLastOption (p);
  195.     while ((c = CL.getPrevOption (p)) != CL_ENDOFLIST)
  196.     {
  197.         cout << "Option " << c << ":" << p << endl;
  198.     }
  199.     cout << "Any key to continue "; cin.get ();
  200.  
  201.     clrscr ();
  202.     cout << "Get Last Error Test" << endl;
  203.     c = CL.getLastError ();
  204.     cout << "Error : " << c << endl;
  205.     cout << "Any key to continue "; cin.get ();
  206.  
  207.     clrscr ();
  208.     cout << "Get First Error Test" << endl;
  209.     c = CL.getFirstError ();
  210.     cout << "Error : " << c << endl;
  211.     cout << "Any key to continue "; cin.get ();
  212.  
  213.     clrscr ();
  214.     cout << "Get Next Error Test" << endl;
  215.     while ((c = CL.getNextError ()) != CL_ENDOFLIST)
  216.     {
  217.         cout << "Error : " << c << endl;
  218.     }
  219.     cout << "Any key to continue "; cin.get ();
  220.     clrscr ();
  221.     cout << "Get Previous Error Test" << endl;
  222.     c = CL.getLastError ();
  223.     while ((c = CL.getPrevError ()) != CL_ENDOFLIST)
  224.     {
  225.         cout << "Error : " << c << endl;
  226.     }
  227.     cout << "Any key to continue "; cin.get ();
  228.     return 0;
  229. }
  230.