Subversion Repositories DevTools

Rev

Details | Last modification | View Log | RSS feed

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