~ubuntu-branches/ubuntu/wily/gargoyle-free/wily-proposed

« back to all changes in this revision

Viewing changes to tads/tads3/test/data/ifdef.c

  • Committer: Bazaar Package Importer
  • Author(s): Sylvain Beucler
  • Date: 2009-09-11 20:09:43 UTC
  • Revision ID: james.westby@ubuntu.com-20090911200943-idgzoyupq6650zpn
Tags: upstream-2009-08-25
ImportĀ upstreamĀ versionĀ 2009-08-25

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 1999, 2002 Michael J. Roberts.  All Rights Reserved. */
 
2
/*
 
3
Name
 
4
  main.t - test source file for test_tok.exe.
 
5
Function
 
6
  Tests the tokenizer and preprocessor functions
 
7
Notes
 
8
  
 
9
Modified
 
10
  04/17/99 MJRoberts  - Creation
 
11
*/
 
12
 
 
13
#pragma all_once-
 
14
 
 
15
#define AAA  1
 
16
#define YES  1
 
17
#define NO   0
 
18
 
 
19
#if AAA ? YES : NO
 
20
"AAA -> yes - ok";
 
21
#else
 
22
"AAA -> no???";
 
23
#endif
 
24
 
 
25
#undef AAA
 
26
#define AAA 0
 
27
#if AAA ? YES : NO
 
28
"AAA -> yes???";
 
29
#else
 
30
"AAA -> no - ok";
 
31
#endif
 
32
 
 
33
 
 
34
#if 1 + 2 > 8 - 5 ? 1 : 0
 
35
"bad ?:";
 
36
#else
 
37
"good ?:";
 
38
#endif
 
39
 
 
40
#if 1+2*3 > 8 ? 0 : 1
 
41
"good ?:";
 
42
#else
 
43
"bad ?:";
 
44
#endif
 
45
 
 
46
#define PRINTVAL(val) printf(#@val + '= %d\n', val)
 
47
PRINTVAL(abc);
 
48
PRINTVAL(def_);
 
49
 
 
50
#if defined(PRINTVAL)
 
51
"printval is defined!";
 
52
#endif
 
53
 
 
54
#if defined(UNDEFINED_SYMBOL) && defined(PRINTVAL)
 
55
"something's wrong!!!";
 
56
#endif
 
57
 
 
58
#if defined(DEFINITELY_NOT_DEFINED) || defined(PRINTVAL)
 
59
"okay!!!";
 
60
#endif
 
61
 
 
62
 
 
63
#define LINENUM  100
 
64
#define FILENAME "test"
 
65
 
 
66
"try string translations";
 
67
#if 'u' > '7'
 
68
#pragma message("u > 7 - ok")
 
69
#else
 
70
#pragma message("u not > 7 - WRONG")
 
71
#endif
 
72
 
 
73
#if '\u00C7' > 'aaaa'
 
74
#pragma message("\\u00C7 > aaaa - ok")
 
75
#else
 
76
#pragma message("\\u00c7 not > aaaa - WRONG")
 
77
#endif
 
78
 
 
79
#if '\uC7' > '\xC6'
 
80
#pragma message("\\uC7 > \\xC6 - ok")
 
81
#else
 
82
#pragma message("\\C7 not > \\xC6 - WRONG")
 
83
#endif
 
84
 
 
85
"pragma message with a translation";
 
86
#define TEST "this is a test message"
 
87
#pragma message(TEST)
 
88
#error "macro: " TEST "!!!"
 
89
 
 
90
 
 
91
"try some macros with arguments";
 
92
#define PRODUCT(a, b) ((a) * (b))
 
93
#define SUM(a, b) ((a) + (b))
 
94
#define SUM3(a, b, c) ((a) + (b) + (c))
 
95
 
 
96
"testing product(10, 20): "; PRODUCT(10, 20);
 
97
"testing product(sum(10, sum3(1, 2, 3)), product(5, 10)): ";
 
98
   PRODUCT(SUM(10, SUM3(1, 2, 3)), PRODUCT(5, 10));
 
99
 
 
100
"testing sum(sum(sum(1, 2), sum(3, 4)), sum(sum(5, 6), sum(7, 8))): ";
 
101
   SUM(SUM(SUM(1, 2), SUM(3, 4)), SUM(SUM(5, 6), SUM(7, 8)));
 
102
 
 
103
#define CIRCULAR_A(foo) CIRCULAR_B(foo*A)
 
104
#define CIRCULAR_B(foo) CIRCULAR_A(foo*B)
 
105
"circular_a(100): "; CIRCULAR_A(100);
 
106
"circular_a(circular_b(50)): "; CIRCULAR_A(CIRCULAR_B(50));
 
107
 
 
108
#if SUM(1+2, 3+4) == PRODUCT(2, 5)
 
109
   "good argument expansion";
 
110
#else
 
111
   "bad argument expansion";
 
112
#endif
 
113
 
 
114
#if PRODUCT(10,11) != PRODUCT(11,10)
 
115
    "bad expansion";
 
116
#elif SUM(5 + 6, 7) == SUM3(5, 6, 7)
 
117
    "good expansion";
 
118
#else
 
119
    "bad else expansion";
 
120
#endif
 
121
    
 
122
 
 
123
"try some #if's with macro expansions";
 
124
 
 
125
#define TEST_ONE  1
 
126
#define TEST_NINE 9
 
127
#define TEST_TEN  10
 
128
 
 
129
#if TEST_ONE == TEST_TEN
 
130
   "bad if";
 
131
#elif TEST_ONE + TEST_NINE == TEST_TEN
 
132
   "good elif with expansion!!!";
 
133
#else
 
134
   "bad else";
 
135
#endif
 
136
 
 
137
#define TEST_STR_1  'abc'
 
138
#define TEST_STR_2  'def'
 
139
#define TEST_STR_3  'abc'
 
140
 
 
141
#if TEST_STR_1 < TEST_STR_2
 
142
    "good string #if";
 
143
#endif
 
144
 
 
145
#if TEST_STR_1 > TEST_STR_2
 
146
    "bad string #if";
 
147
#else
 
148
    "good string #else";
 
149
#endif
 
150
 
 
151
#if TEST_STR_1 == TEST_STR_2
 
152
    "bad string #if";
 
153
#elif TEST_STR_1 == TEST_STR_3
 
154
    "good string #elif";
 
155
#endif
 
156
 
 
157
"try some #if's with constant expressions"
 
158
#if 0
 
159
    "bad if"
 
160
#elif 1
 
161
   "good if!!!"
 
162
#else
 
163
   "bad else"
 
164
#endif
 
165
 
 
166
#if 1+2*3 == (4+11)*2 - ((6+7) << 1) + (0xF03 & 03)
 
167
   "good if!!! (and a tough one, too)";
 
168
#elif 1 == 1
 
169
   "bad if"
 
170
#elif 1 == 2
 
171
   "another bad if"
 
172
#else
 
173
   "bad else"
 
174
#endif
 
175
 
 
176
#if 1 == 2
 
177
   "bad if"
 
178
#elif 2 == 3
 
179
   "another bad if"
 
180
#elif 3+1 == 6-4/2
 
181
   "good elif!!!!!!"
 
182
#elif 3 == 3
 
183
   "bad elif"
 
184
#elif 4 == 0
 
185
   "bad elif"
 
186
#elif 4 == 4
 
187
   "bad elif"
 
188
#else
 
189
   "bad else"
 
190
#endif
 
191
"done with if/elif";
 
192
 
 
193
"define some macros";
 
194
#define FOO
 
195
#define BAR
 
196
 
 
197
"try out a positive #if";
 
198
#ifdef FOO
 
199
   "this is a good #if";
 
200
#else /* FOO */
 
201
   "this is a bad #else";
 
202
#endif /* FOO */
 
203
"end of positive #if";
 
204
 
 
205
"try a negative #if";
 
206
#ifdef BLECH
 
207
   "this is a bad #if";
 
208
#else /* FOO */
 
209
   "this is a good #else";
 
210
#endif /* FOO */
 
211
"end of negative #if";
 
212
 
 
213
"try some nested #if's";
 
214
#ifdef FOO
 
215
      "good #if - level 1";   A
 
216
# ifdef BAR
 
217
      "good #if - level 2";   B
 
218
#  ifdef BLECH
 
219
      "bad #if - level 3";    C
 
220
#  else
 
221
      "good #else - level 3";  D
 
222
#  endif /* BLECH */
 
223
      "good #if - level 2";    E
 
224
# else /* BAR */
 
225
      "bad #else - level 2";   F
 
226
#  ifdef FOO
 
227
      "good #if within a bad #if -> bad - level 2";   G
 
228
#  else
 
229
      "bad #else within bad #if -> bad - level 2";  H
 
230
#  endif /* nested FOO */
 
231
# endif /* BAR */
 
232
      "good #if - level 1";    I
 
233
#else /* FOO */
 
234
      "bad #else - level 1";   J
 
235
# ifdef BAR
 
236
      "good #if in bad else -> bad - level 2";   B
 
237
#  ifdef BLECH
 
238
      "bad #if in bad else -> bad - level 3";    C
 
239
#  else
 
240
      "good #else in bad else -> bad - level 3";  D
 
241
#  endif /* BLECH */
 
242
      "good #if in bad else -> bad - level 2";    E
 
243
# else /* BAR */
 
244
      "bad #else in bad else -> bad - level 2";   F
 
245
#  ifdef FOO
 
246
      "good #if within a bad #if within bad #else -> bad - level 2";   G
 
247
#  else
 
248
      "bad #else within bad #if within bad #else -> bad - level 2";  H
 
249
#  endif /* nested FOO */
 
250
# endif /* BAR */
 
251
#endif /* FOO */
 
252
#ifdef FOO
 
253
    "good again";
 
254
#else
 
255
    "bad again";
 
256
#endif
 
257
"done with nested #if's";
 
258
 
 
259
"ifndef test";
 
260
#ifndef FOO
 
261
   "bad ifndef";
 
262
#else
 
263
   "good ifndef else";
 
264
#endif
 
265
#ifndef BLECH
 
266
   "good ifndef";
 
267
#else
 
268
   "bad ifndef else";
 
269
#endif
 
270
 
 
271
 
 
272
 
 
273
// this is a single-line comment, which should be eliminated
 
274
 
 
275
/* this is a multi-line comment on just one line */
 
276
 
 
277
/*
 
278
 *   this is a full multi-line comment 
 
279
 */
 
280
 
 
281
/*
 
282
 *   This is another multi-line comment.  The #include that follows should
 
283
 *   be ignored, since it's part of this comment.
 
284
 
 
285
#include "badfile.t"
 
286
 
 
287
 */
 
288
 
 
289
// the following #include should be ignored
 
290
// #include "badfile.t"
 
291
 
 
292
/*
 
293
 *   the following #include should be obeyed 
 
294
 */
 
295
#include "header.t"
 
296
 
 
297
"This is a string.  The #include below should be ignored,
 
298
because it's part of the string.
 
299
 
 
300
#include "badfile.t"
 
301
 
 
302
That's that!";
 
303
 
 
304
"This is a string with escaped \"quote marks\".  Those quotes
 
305
shouldn't end the string.
 
306
\"the next #include should be ignored, since it's still part of the string:
 
307
 
 
308
#include <badfile.t>
 
309
 
 
310
That's all for the string!";
 
311
 
 
312
/*
 
313
 *   here's a comment with a "string" embedded 
 
314
 */
 
315
 
 
316
"Here's a string with a /*comment*/ embedded.";
 
317
 
 
318
"Here's some mixing:" /* comment */  "String" /* comment */ "Done!!!" // EOL
 
319
 
 
320
 
 
321
/*
 
322
 *   Include the header with a comment dangling after the end of the
 
323
 *   include line. 
 
324
 */
 
325
#include "header.t"    /* Start a comment here,
 
326
                          but don't finish it
 
327
                          for a few lines, just to
 
328
                          make it harder. */  "<--- after the comment";
 
329
 
 
330
"That's it!";
 
331
 
 
332
#include "header.t"
 
333
Line directly after the header!
 
334
 
 
335
 
 
336
"Try some random #line directives!";
 
337
 
 
338
#line 1234 "foo_test.c"
 
339
 
 
340
hello!
 
341
 
 
342
#line 6789 "test2.c"
 
343
 
 
344
goodbye!
 
345
 
 
346
#line 1+2+3 "foo_test.c"
 
347
 
 
348
"__LINE__ and __FILE__ near the end of file: "; __LINE__, __FILE__;
 
349
 
 
350
"Make sure we come back here after we're done with an include file.";
 
351
#include "header.t"
 
352
>>> back from include!!! <<<
 
353
 
 
354
 
 
355
"Try expanding macros and calculating values in #line";
 
356
#line 5 + 2*LINENUM FILENAME + ".h"
 
357
 
 
358
"try __FILE__ and __LINE__";
 
359
"__FILE__: <<__FILE__>>, __LINE__: << __LINE__ >>\n";
 
360
 
 
361
"__FILE__: <<
 
362
  __FILE__
 
363
  >>, __LINE__:
 
364
  <<
 
365
  __LINE__ >> -- that was __FILE and __LINE!\n";
 
366