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 >
Wrap
Text File
|
1989-08-01
|
3KB
|
146 lines
/*
Tests of CPP
source: cpp.tst
version:
February 14, 1989
August 1, 1989
Add tests of //
Add test of long macro expansions.
*/
/*
PART I
Weird and wonderful tests of macro expansion.
see page 93 of Draft C Standard of January, 1988.
*/
#define x 3
#define f(a) f(x * (a))
#undef x
#define x 2
#define g f
#define z z[0]
#define h g(~
#define m(a) a(w)
#define w 0,1
#define t(a) a
/* subtest 1
f(y+1); should expand to:
f(2 * (y+1));
*/
f(y+1);
/* subtest 2
f(f(z)); should expand to:
f(2 * (f(2 * (z[0]))));
*/
f(f(z));
/* subtest 3
t(t(g)(0) + t)(1); should expand to:
f(2 * (0)) + t(1);
*/
t(t(g)(0) + t)(1);
/* subtest 4
g(x+(3,4)-w) | h 5) & m (f)^m(m);
should result in:
f(2 * (2+(3,4)-0,1)) | f(2 * (~ 5)) & f(2 * (0,1))^m(0,1);
*/
g(x+(3,4)-w) | h 5) & m (f)^m(m);
/*
PART 2
Tests of string concatenation and token pasting.
*/
#define str(s) # s
#define xstr(s) str(s)
#define debug(s,t) printf("x" # s "= %d, x" # t "= %s", x ## s, x ## t)
/*
#define str(s) # s
#define xstr(s) str(s)
#define debug(s,t) printf("x" # s "= %d, x" # t "= %s", x ## s, x ## t)
debug(1, 2);
should result in:
printf("x1= %d, x2= %s", x1, x2);
*/
debug(1, 2);
/*
fputs(str(strncmp("abc\0d", "abc", '\4') == 0) str(: @\n), s);
should result in:
fputs("strncmp(\"abc\\0d\", \"abc\", '\\4') == 0: @\n", s);
*/
fputs(str(strncmp("abc\0d", "abc", '\4') == 0) str(: @\n), s);
/*
PART 3
Tests of detecting duplicate definitions
These examples do not follow the standard yet.
Please do not report these as bugs to me.
*/
#define OBJ_LIKE (1-1)
#define OBJ_LIKE /* a */ (1-1) /* b */
#define FTN_LIKE(a) ( a )
#define FTN_LIKE( a ) ( /* a */ \
a /* b
*/ )
#define OBJ_LIKE (0)
#define OBJ_LIKE (1 - 1)
#define FTN_LIKE(b) ( a )
#define FTN_LIKE(b) (b)
/* PART 4
Bug regression test:
Test for white space in argument list in macros.
Test for more than six arguments.
Test for recursive definition of keywords
*/
#define a( b , c , d , e , f , g , h ) b c d e f g h
a(one,two,three,four,five,six,seven);
#define char (signed) char
char c;
#pragma this can be anything
#pragma ##who cares##??
/* Test of defined keyword. */
#if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
included line
#endif
/* Test of continuation. Comments continue PP directives! */
#include /* abc */ <c:\include\turboc\stdio.h> /*
this is a comment */
// This is a single-line comment
// so is this /*
/*
Test line number handling.
Note: #error will terminate the processing of this test file.
*/
#define FILE_NAME "d:\sherlock\sl.h"
#define LINE2 1000
#define FILE2 "changed_file"
#include FILE_NAME
#line LINE2 FILE2
#error This should be line 1001 of changed_file