home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre4.z / postgre4 / src / test / teststubs.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  2.0 KB  |  92 lines

  1. /*================================================================
  2.  *
  3.  * FILE:
  4.  *   teststubs.c
  5.  *
  6.  * $Header: /private/postgres/src/test/RCS/teststubs.c,v 1.1 1991/01/09 19:18:05 sp Exp $
  7.  *
  8.  * Test the routines that manipulate rule stub records.
  9.  *
  10.  *================================================================
  11.  */
  12.  
  13. #include <stdio.h>
  14. #include "utils/log.h"
  15. #include "rules/prs2.h"
  16. #include "rules/prs2stub.h"
  17.  
  18. void testStubsInout();
  19.  
  20. /*--------------------------------------------------------
  21.  * main routine
  22.  *--------------------------------------------------------
  23.  */
  24. TestMain(argc, argv)
  25. int argc;
  26. char *argv[];
  27. {
  28.     int i;
  29.  
  30.     for (i=1; i<argc; i++) {
  31.     if (!strcmp(argv[i], "-inout")) {
  32.         testStubsInout();
  33.     }
  34.     }
  35. }
  36.  
  37. /*--------------------------------------------------------
  38.  * testStubsInout:
  39.  *
  40.  * read stubs from the input & transform them to 'Prs2RawStubs'
  41.  * and then back to strings. Used to test the 'stubin', 'stubout',
  42.  * 'Prs2StubToString' & 'Prs2StringToStub' routines....
  43.  *--------------------------------------------------------
  44.  */
  45. void
  46. testStubsInout()
  47. {
  48.     char s[1000];
  49.     int i, c;
  50.     Prs2RawStub raw1;
  51.     Prs2Stub stub1, stub2;
  52.     char *s1, *s2;
  53.  
  54.     printf("Give me the stub: ");
  55.     i=0;
  56.     while ((c=getchar()) != EOF) {
  57.     if (i > sizeof(s) -1) {
  58.         elog(WARN, "testStubsInout: string toooooo big!");
  59.     }
  60.     if (c == '\n')
  61.         c = ' ';
  62.     s[i] = c;
  63.     i++;
  64.     }
  65.     s[i] = '\0';
  66.  
  67.     if (i==0)
  68.     return;
  69.  
  70.     printf("---String = \n'%s'\n", s);
  71.  
  72.     stub1 = prs2StringToStub(s);
  73.     s1 = prs2StubToString(stub1);
  74.     printf("--- String->Stub->String:\n'%s'\n", s1);
  75.  
  76.     raw1 = prs2StubToRawStub(stub1);
  77.     stub2 = prs2RawStubToStub(raw1);
  78.     s2 = prs2StubToString(stub2);
  79.     printf("--- Stub->Raw->Stub:\n'%s'\n", s2);
  80.     if (strcmp(s1, s2)) {
  81.     fprintf(stderr, "*** stub->raw->stub DOES NOT WORK! ***\n");
  82.     }
  83.  
  84.     raw1 = stubin(s1);
  85.     s2 = stubout(raw1);
  86.     printf("--- Stub->in/out:\n'%s'\n", s2);
  87.     if (strcmp(s1, s2)) {
  88.     fprintf(stderr, "*** stub->in/out DOES NOT WORK! ***\n");
  89.     }
  90. }
  91.  
  92.