home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / X / mit / demos / xcmstest / TekCMS_TCI.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-31  |  7.2 KB  |  339 lines

  1. /* $XConsortum: TekCMS_TCI.c,v 1.1 91/02/11 19:40:35 dave Exp $ */
  2.  
  3.  
  4. /*
  5.  * (c) Copyright 1990, Tektronix Inc.
  6.  *     All Rights Reserved
  7.  *
  8.  * Permission to use, copy, modify, and distribute this software and its
  9.  * documentation for any purpose and without fee is hereby granted,
  10.  * provided that the above copyright notice appear in all copies and that
  11.  * both that copyright notice and this permission notice appear in
  12.  * supporting documentation, and that the name of Tektronix not be used
  13.  * in advertising or publicity pertaining to distribution of the software
  14.  * without specific, written prior permission.
  15.  *
  16.  * Tektronix disclaims all warranties with regard to this software, including
  17.  * all implied warranties of merchantability and fitness, in no event shall
  18.  * Tektronix be liable for any special, indirect or consequential damages or
  19.  * any damages whatsoever resulting from loss of use, data or profits,
  20.  * whether in an action of contract, negligence or other tortious action,
  21.  * arising out of or in connection with the use or performance of this
  22.  * software.
  23.  *
  24.  *    NAME
  25.  *        TekCmsTCI.c -- TekCMS Test Case Interface
  26.  *
  27.  *    DESCRIPTION
  28.  *        This file contains the definition of the Test Case Table.
  29.  *        For each test case, two things are necessary:
  30.  *            1. Entry into the Test Case Table
  31.  *            Create an entry into the Test Case Table (TekCMS_TestCaseTbl)
  32.  *            which is a command string and then a pointer to
  33.  *            the test case function.  String entry should
  34.  *            conform to the Test Case Identifier specified in
  35.  *            the test design specifications.
  36.  *            2. Test Case Function
  37.  *            Create the test case function.
  38.  */
  39.  
  40.  
  41. /*
  42.  *      EXTERNAL INCLUDES
  43.  *              Include files that must be exported to any package or
  44.  *              program using this package.
  45.  */
  46. #include "LibTest.h"
  47.  
  48.  
  49. /*
  50.  *      INTERNAL INCLUDES
  51.  *              Include files that need NOT be exported to any package or
  52.  *              program using this package.
  53.  */
  54. #include <stdio.h>
  55. #include <X11/Xlib.h>
  56. #include <X11/Xcms.h>
  57. #ifdef AUTOHEADER
  58. #  include "TekCMS_LT.ah"
  59. #  include "TestInit.ah"
  60. #else
  61. #  include "TekCMS_LT.h"
  62. #  include "TestInit.h"
  63. #endif
  64.  
  65. #ifdef DONE
  66. #  include "TekCmsTC.h"
  67. #endif /* DONE */
  68.  
  69. /*
  70.  *    INTERNALS
  71.  *        Declarations that are local to this module.
  72.  *        (ignored by 'autohdr').
  73.  */
  74.  
  75. /*
  76.  *    EXTERNALS
  77.  *        Declarations that are needed by calling modules.
  78.  *        When using 'autohdr', these declaration will be placed
  79.  *        in the resulting header file.
  80.  */
  81. char    TekCMS_idir[BUFSIZ];
  82. char    TekCMS_vdir[BUFSIZ];
  83. char    TekCMS_rdir[BUFSIZ];
  84.  
  85.  
  86. /************************************************************************
  87.  *                                    *
  88.  *             PRIVATE ROUTINES                *
  89.  *                                    *
  90.  ************************************************************************/
  91.  
  92. /*
  93.  *    NAME
  94.  *        filecmp
  95.  *
  96.  *    SYNOPSIS
  97.  */
  98. static int
  99. filecmp(fp1, fp2)
  100.     FILE *fp1, *fp2;
  101. /*
  102.  *    DESCRIPTION
  103.  *        CompareResults
  104.  *
  105.  *    RETURNS
  106.  *        1 if contents of vfile identical to rfile
  107.  *        0 otherwise
  108.  *
  109.  */
  110. {
  111.     char *line1, *line2, buf[BUFSIZ * 2] ;
  112.     int different ;
  113.     different = 0 ;
  114.  
  115.     while (! different) {
  116.     line1 = fgets(buf, BUFSIZ, fp1);
  117.     line2 = fgets(buf, BUFSIZ, fp2);
  118.     if ((line1 == NULL) && (line2 == NULL)) {
  119.         return(1);
  120.     }
  121.     if ((line1 == NULL) || (line2 == NULL)) {
  122.         return(0);
  123.     }
  124.     different = strcmp(line1, line2) ;
  125.     }
  126.     return(0) ;
  127. }
  128.  
  129.  
  130. /************************************************************************
  131.  *                                    *
  132.  *             PUBLIC ROUTINES                *
  133.  *                                    *
  134.  ************************************************************************/
  135.  
  136. /*
  137.  *    NAME
  138.  *        TCI
  139.  *
  140.  *    SYNOPSIS
  141.  */
  142. int
  143. TCI(buf)
  144.     char *buf;
  145. /*
  146.  *    DESCRIPTION
  147.  *        TCI
  148.  *
  149.  *    RETURNS
  150.  *        void
  151.  *
  152.  */
  153. {
  154. #ifndef DONE
  155.     printf("Not yet implemented \n");
  156.     return(0);
  157. #else
  158.     PFStatus pfunc;
  159.     char tmpstr[BUFSIZ];
  160.     char ifile[BUFSIZ], vfile[BUFSIZ], rfile[BUFSIZ];
  161.     int i=0;
  162.  
  163.     if(!Check_init()) {
  164.     return(0);
  165.     }
  166.  
  167.     if ((sscanf(buf, "%s", tmpstr)<=0) || (strcmp("-help", tmpstr) == 0)) {
  168.     goto TCI_Usage;
  169.     }
  170.  
  171.     ifile[0] = vfile[0] = rfile[0] = '\0';
  172.  
  173.     while (sscanf(&buf[i], "%s", tmpstr) > 0) {
  174.     if (!strcmp(tmpstr, "-ifile")) {
  175.         i += strlen(tmpstr) + 1;
  176.         if (sscanf(&buf[i], "%s", tmpstr) > 0) {
  177.         if (tmpstr[0] == '/') {
  178.             /* full path */
  179.             strcpy(ifile, tmpstr);
  180.         } else {
  181.             /* relative path */
  182.             strcpy(ifile, TekCMS_idir);
  183.             if (ifile[0] != '\0') {
  184.             strcat(ifile, "/");
  185.             }
  186.             strcat(ifile, tmpstr);
  187.         }
  188.         i += strlen(tmpstr) + 1;
  189.         printf("ifile = %s\n",ifile);
  190.         continue;
  191.         } else {
  192.         goto TCI_Usage;
  193.         }
  194.     } 
  195.  
  196.     if (!strcmp(tmpstr, "-vfile")) {
  197.         i += strlen(tmpstr) + 1;
  198.         if (sscanf(&buf[i], "%s", tmpstr) > 0) {
  199.         if (tmpstr[0] == '/') {
  200.             /* full path */
  201.             strcpy(vfile, tmpstr);
  202.         } else {
  203.             /* relative path */
  204.             strcpy(vfile, TekCMS_vdir);
  205.             if (vfile[0] != '\0') {
  206.             strcat(vfile, "/");
  207.             }
  208.             strcat(vfile, tmpstr);
  209.         }
  210.         i += strlen(tmpstr) + 1;
  211.         printf("vfile = %s\n",vfile);
  212.         continue;
  213.         } else {
  214.         goto TCI_Usage;
  215.         }
  216.     } 
  217.  
  218.     if (!strcmp(tmpstr, "-rfile")) {
  219.         i += strlen(tmpstr) + 1;
  220.         if (sscanf(&buf[i], "%s", tmpstr) > 0) {
  221.         if (tmpstr[0] == '/') {
  222.             /* full path */
  223.             strcpy(rfile, tmpstr);
  224.         } else {
  225.             /* relative path */
  226.             strcpy(rfile, TekCMS_rdir);
  227.             if (rfile[0] != '\0') {
  228.             strcat(rfile, "/");
  229.             }
  230.             strcat(rfile, tmpstr);
  231.         }
  232.         i += strlen(tmpstr) + 1;
  233.         printf("rfile = %s\n",rfile);
  234.         continue;
  235.         } else {
  236.         goto TCI_Usage;
  237.         }
  238.     }
  239.     if ((pfunc = LtStrToFuncPtr(LIBTEST_TCTBL, tmpstr)) == (PFStatus) -1) {
  240.         printf("Error: Invalid Test Case Identifier - %s\n", tmpstr);
  241.         return(0);
  242.     }
  243.     (*pfunc)(
  244.         ifile, /* Input File */
  245.         vfile, /* Verification File */
  246.         rfile, /* Results File */
  247.         &buf[i + strlen(tmpstr)]); /* Any test case arguments */
  248.     return(1);
  249.     }
  250. TCI_Usage:
  251.     printf("Usage:\n");
  252.     printf("\tTestCase [-ifile input_file] [-vfile valid_file] [-rfile result_file] <testcase_identifier> [testcase args]\n\n");
  253.     return(0);
  254. #endif /* DONE */
  255. }
  256.  
  257. /*
  258.  *    NAME
  259.  *        CompareResults
  260.  *
  261.  *    SYNOPSIS
  262.  */
  263. int
  264. TC_CompareResults(tc_id, vfile, rfile)
  265.     char *tc_id, *vfile, *rfile;
  266. /*
  267.  *    DESCRIPTION
  268.  *        CompareResults
  269.  *
  270.  *    RETURNS
  271.  *        1 if contents of vfile identical to rfile
  272.  *        0 if different
  273.  *           -1 otherwise
  274.  *
  275.  */
  276. {
  277.     FILE *fp1 = NULL;
  278.     FILE *fp2 = NULL;
  279.     int retval = -1;
  280.  
  281.     if ((fp1 = fopen(vfile, "r")) && (fp2 = fopen(rfile, "r")))
  282.     retval = filecmp(fp1, fp2);
  283.     switch (retval) {
  284.       case 0:
  285.     printf("%s:  FAILED\n", tc_id);
  286.     break;
  287.       case 1:
  288.     printf("%s:  passed\n", tc_id);
  289.     break;
  290.       default:
  291.     printf("%s:  unable to verify results\n", tc_id);
  292.     break;
  293.     }
  294.     if (fp1)
  295.     fclose(fp1);
  296.     if (fp2)
  297.     fclose(fp2);
  298.     return(retval);
  299. }
  300.  
  301. /*
  302.  *    NAME
  303.  *        Cmd_ListTC
  304.  *
  305.  *    SYNOPSIS
  306.  */
  307. int
  308. Cmd_ListTC(argbuf)
  309.     char *argbuf;
  310. /*
  311.  *    DESCRIPTION
  312.  *        Get TekCMS_rdir
  313.  *
  314.  *    RETURNS
  315.  *        0=fail, 1=Success
  316.  *
  317.  */
  318. {
  319. #ifndef DONE
  320.     fprintf(stderr, "ListTC not yet implemented\n");
  321. #else
  322.     char tmpstr[BUFSIZ];
  323.     FuncTableEntry    *pTCEntry;
  324.  
  325.     if (sscanf(argbuf, "%s", tmpstr) > 0) {
  326.         printf("Usage:\n");
  327.         printf("\tListTC\n\n");
  328.         return(0);
  329.     } 
  330.  
  331.     for (pTCEntry = TekCMS_TestCaseTbl; *pTCEntry->pstring != '\0'; pTCEntry++) {
  332.     printf("\t%s\n", pTCEntry->pstring);
  333.     }
  334.     printf("\n");
  335.  
  336.     return(1);
  337. #endif /* DONE */
  338. }
  339.