home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 355_03 / slk3.exe / TEST / TST / CPP.TST < prev    next >
Text File  |  1989-08-01  |  3KB  |  146 lines

  1. /*
  2.     Tests of CPP
  3.  
  4.     source: cpp.tst
  5.     version:
  6.         February 14, 1989
  7.         August 1, 1989
  8.             Add tests of //
  9.             Add test of long macro expansions.
  10. */
  11.  
  12. /*
  13.     PART I
  14.  
  15.     Weird and wonderful tests of macro expansion.
  16.     see page 93 of Draft C Standard of January, 1988.
  17. */
  18. #define x 3
  19. #define f(a) f(x * (a))
  20. #undef x
  21.  
  22. #define x 2
  23. #define g f
  24. #define z z[0]
  25. #define h g(~
  26. #define m(a) a(w)
  27. #define w 0,1
  28. #define t(a) a
  29.  
  30. /* subtest 1
  31. f(y+1); should expand to:
  32. f(2 * (y+1));
  33. */
  34. f(y+1);
  35.  
  36. /* subtest 2
  37. f(f(z)); should expand to:
  38. f(2 * (f(2 * (z[0]))));
  39. */
  40. f(f(z));
  41.  
  42. /* subtest 3
  43. t(t(g)(0) + t)(1); should expand to:
  44. f(2 * (0)) + t(1);
  45. */
  46. t(t(g)(0) + t)(1);
  47.  
  48. /* subtest 4
  49. g(x+(3,4)-w) | h 5) & m (f)^m(m);
  50. should result in:
  51. f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
  52. */
  53. g(x+(3,4)-w) | h 5) & m (f)^m(m);
  54.  
  55.  
  56. /*
  57.     PART 2
  58.     Tests of string concatenation and token pasting.
  59. */
  60. #define str(s) # s
  61. #define xstr(s) str(s)
  62. #define debug(s,t) printf("x" # s "= %d, x" # t "= %s", x ## s, x ## t)
  63.  
  64. /*
  65. #define str(s) # s
  66. #define xstr(s) str(s)
  67. #define debug(s,t) printf("x" # s "= %d, x" # t "= %s", x ## s, x ## t)
  68. debug(1, 2);
  69.  
  70. should result in:
  71. printf("x1= %d, x2= %s", x1, x2);
  72. */
  73. debug(1, 2);
  74.  
  75. /*
  76. fputs(str(strncmp("abc\0d", "abc", '\4') == 0) str(: @\n), s);
  77. should result in:
  78. fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: @\n", s);
  79. */
  80. fputs(str(strncmp("abc\0d", "abc", '\4') == 0) str(: @\n), s);
  81.  
  82. /*
  83.     PART 3
  84.     Tests of detecting duplicate definitions
  85.  
  86.     These examples do not follow the standard yet.
  87.     Please do not report these as bugs to me.
  88. */
  89. #define OBJ_LIKE (1-1)
  90. #define OBJ_LIKE /* a */  (1-1) /* b */
  91. #define FTN_LIKE(a) ( a )
  92. #define FTN_LIKE( a ) ( /* a */ \
  93.     a  /* b
  94.     */ )
  95.  
  96.  
  97. #define OBJ_LIKE (0)
  98. #define OBJ_LIKE (1 - 1)
  99. #define FTN_LIKE(b) ( a )
  100. #define FTN_LIKE(b) (b)
  101.  
  102. /*    PART 4
  103.     Bug regression test:
  104.  
  105.     Test for white space in argument list in macros.
  106.  
  107.     Test for more than six arguments.
  108.  
  109.     Test for recursive definition of keywords
  110. */
  111. #define a( b , c , d , e , f , g , h ) b c d e f g h
  112.  
  113. a(one,two,three,four,five,six,seven);
  114.  
  115. #define char (signed) char
  116. char c;
  117.  
  118. #pragma this can be anything
  119.  
  120. #pragma ##who cares##??
  121.  
  122. /* Test of defined keyword. */
  123. #if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
  124. included line
  125. #endif
  126.  
  127. /* Test of continuation.  Comments continue PP directives! */
  128. #include /* abc */ <c:\include\turboc\stdio.h> /* 
  129. this is a comment */
  130.  
  131. // This is a single-line comment
  132. // so is this /*
  133.  
  134.  
  135.  
  136. /*
  137.     Test line number handling.
  138.     Note: #error will terminate the processing of this test file.
  139. */
  140. #define FILE_NAME "d:\sherlock\sl.h"
  141. #define LINE2 1000
  142. #define FILE2 "changed_file"
  143. #include FILE_NAME
  144. #line LINE2 FILE2
  145. #error This should be line 1001 of changed_file
  146.