]> code.delx.au - gnu-emacs/blob - test/cedet/tests/test.cpp
0c43944a0318df421a98c373d1a6e50dcd77fa43
[gnu-emacs] / test / cedet / tests / test.cpp
1 /* Test file for C++ language.
2 * Attempt to include as many aspects of the C++ language as possible.
3 * Do not include things tested in test.c since that shares the
4 * same language.
5 */
6
7 /* An include test */
8 #include <stdio.h>
9
10 #include <cmath>
11
12 #include "c++-test.hh"
13
14 #include <c++-test.hh>
15
16 double var1 = 1.2;
17
18 int simple1(int a) {
19
20 }
21
22 struct foo1 {
23 int test;
24 };
25
26 struct foo2 : public foo1 {
27 const int foo21(int a, int b);
28 const int foo22(int a, int b) { return 1 }
29 };
30
31 /* Classes */
32 class class1 {
33 private:
34 int var11;
35 struct foo1 var12;
36 public:
37 int p_var11;
38 struct foo p_var12;
39 };
40
41 class i_class1 : public class1 {
42 private:
43 int var11;
44 struct foo var12;
45 public:
46 int p_var11;
47 struct foo p_var12;
48 };
49
50 class class2 {
51 private:
52 int var21;
53 struct foo var22;
54 public:
55 int p_var21;
56 struct foo p_var22;
57 };
58
59 class i_class2 : public class1, public class2 {
60 private:
61 int var21;
62 struct foo var22;
63 protected:
64 int pt_var21;
65 public:
66 int p_var21;
67 struct foo p_var22;
68 };
69
70 class class3 {
71 /* A class with strange things in it */
72 public:
73 class3(); /* A constructor */
74 enum embedded_foo_enum {
75 a, b, c
76 } embed1;
77 struct embedded_bar_struct {
78 int a;
79 int b;
80 } embed2;
81 class embedded_baz_class {
82 embedded_baz_class();
83 ~embedded_baz_class();
84 } embed3;
85 ~class3(); /* destructor */
86
87 /* Methods */
88 int method_for_class3(int a, char b);
89
90 int inline_method(int c) { return c; }
91
92 /* Operators */
93 class3& operator^= (const class3& something);
94
95 /* Funny declmods */
96 const class3 * const method_const_ptr_ptr(const int * const argconst) const = 0;
97 };
98
99 class3::class3()
100 {
101 /* Constructor outside the definition. */
102 }
103
104 int class3::method_for_class3(int a, char b)
105 {
106 }
107
108 int class3::method1_for_class3( int a, int &b)
109 {
110 int cvariablename;
111 class3 fooy[];
112 class3 moose = new class3;
113
114 // Complktion testing line should find external members.
115 a = fooy[1].me ;
116 b = cv ;
117
118 if (fooy.emb) {
119 simple1(c);
120 }
121
122 cos(10);
123 abs(10);
124
125 return 1;
126 }
127
128 char class3::method2_for_class3( int a, int b) throw ( exception1 )
129 {
130 return 'a';
131 }
132
133 void *class3::method3_for_class3( int a, int b) throw ( exception1, exception2 )
134 {
135 int q = a;
136 return "Moose";
137 }
138
139 void *class3::method31_for_class3( int a, int b) throw ( )
140 {
141 int q = a;
142 return "Moose";
143 }
144
145 void *class3::method4_for_class3( int a, int b) reentrant
146 {
147 class3 ct;
148
149 ct.method5_for_class3(1,a);
150
151 pritf();
152 }
153
154 /*
155 * A method on class3.
156 */
157 void *class3::method5_for_class3( int a, int b) const
158 {
159 }
160
161 /*
162 * Namespace parsing tests
163 */
164 namespace NS {
165 class class_in_namespace {
166 int equiv(const NS::class_in_namespace *) const;
167 };
168 }
169
170 int NS::class_in_namespace::equiv(const NS::class_in_namespace *cin) const
171 {
172 return 0;
173 }
174
175 // Stuff Klaus found.
176 // Inheritance w/out a specifying for public.
177 class class4 : class1 {
178 // Pure virtual methods.
179 void virtual print () const = 0;
180
181 public:
182 // The whacky constructor type
183 class4()
184 try : class1(args)
185 {
186 // constructor body
187 }
188 catch ()
189 {
190
191 }
192
193
194 };
195
196 class class5 : public virtual class4 {
197 // Virtual inheritance
198 };
199
200 class class6 : class1 {
201 // Mutable
202 mutable int i;
203 };
204
205 /* Namespaces */
206 namespace namespace1 {
207 void ns_method1() { }
208
209 class n_class1 {
210 public:
211 void method11(int a) { }
212 };
213
214 /* This shouldn't parse due to missing semicolon. */
215 class _n_class2 : public n_class1 {
216 void n_c2_method1(int a, int b) { }
217 };
218
219 // Macros in the namespace
220 #define NSMACRO 1
221
222 // Template in the namespace
223 template<class T> T nsti1(const Foo& foo);
224 template<> int nsti1<int>(const Foo& foo);
225
226 }
227
228 namespace namespace2 {
229
230 using namespace1::n_class1;
231
232 }
233
234 /* Initializers */
235 void tinitializers1(): inita1(False),
236 inita2(False)
237 {
238 inita1= 1;
239 }
240
241 /* How about Extern C type things. */
242 int funny_prototype(int ,int b,float c)
243 {
244
245 }
246
247 extern "C"
248 int extern_c_1(int a, int b)
249 {
250
251 funny_prototype(1,2,3.4);
252
253 printf("Moose", );
254
255 return 1;
256 }
257
258 extern "C" {
259
260 int extern_c_2(int a, int b)
261 {
262 return 1;
263 }
264
265 }
266
267 // Some operator stuff
268 class Action
269 {
270 // Problems!! operator() and operator[] can not be parsed with semantic
271 // 1.4.2 but with latest c.by
272 virtual void operator()(int i, char *p ) = 0;
273 virtual String& operator[]() = 0;
274 virtual void operator!() = 0;
275 virtual void operator->() = 0;
276 virtual T& operator+=();
277 virtual T& operator*();
278 virtual T& operator*=();
279 };
280
281 // class with namespace qualified parents
282 class Multiinherit : public virtual POA::Parent,
283 public virtual POA::Parent1,
284 Parent
285 {
286 private:
287 int i;
288
289 public:
290 Multiinherit();
291 ~Multiinherit();
292
293 // method with a list of qualified exceptions
294 void* throwtest()
295 throw(Exception0,
296 Testnamespace::Exception1,
297 Testnamespace::Excpetion2,
298 Testnamespace::testnamespace1::Exception3);
299
300 };
301
302 void*
303 Multiinherit::throwtest()
304 throw (Exception0,
305 Testnamespace::Exception1,
306 Testnamespace::Excpetion2,
307 Testnamespace::testnamespace1::Exception3)
308 {
309 return;
310 }
311
312 // Jens Rock <jens.rock@asamnet.de>: Nested classes or structs defined
313 // outside of the containing class/struct.
314 class container
315 {
316 public:
317 struct contained;
318 container();
319 ~container();
320 };
321
322 struct container::contained
323 {
324 public:
325 contained();
326 ~contained();
327 };
328
329 /*
330 * Ok, how about some template stuff.
331 */
332 template <class CT, class container = vector<CT> >
333 const CT& max (const CT& a, const CT& b)
334 {
335 return a < b ? b : a;
336 }
337
338 // Arne Schmitz found this one
339 std::vector<int> &a, &b, &c;
340
341 class TemplateUsingClass
342 {
343 typedef TestClassMap::iterator iterator;
344 typedef map<long, long> TestClassMap;
345
346 // typedefs with const and volatile
347 typedef const map<long, long> const_TestClassMap;
348 typedef TestClassMap<string>::iterator volatile volatile_iterator;
349
350 map<int, int> mapclassvarthingy;
351 };
352
353 template<class T> T ti1(const Foo& foo);
354 template<> int ti1<int>(const Foo& foo);
355
356
357 // -----------------------------------
358 // Now some namespace and related stuff
359 // -----------------------------------
360
361 using CORBA::LEX::get_token;
362 using Namespace1;
363
364 using namespace POA::std;
365 using namespace Test;
366
367
368
369 namespace Parser
370 {
371 namespace
372 {
373 using Lexer::get_test;
374 string str = "";
375 }
376
377 namespace XXX
378 {
379
380 class Foobar : public virtual POA::Parent,
381 public virtual POA::Parent1,
382 private POA::list<fact>,
383 private map<string>
384 {
385 ini i;
386 list <shared_ptr<item> >::const_iterator l;
387 public:
388
389 Foobar();
390 ~Foobar();
391 };
392 }
393
394
395 void test_function(int i);
396
397 };
398
399 // unnamed namespaces - even nested
400 namespace
401 {
402 namespace
403 {
404 using Lexer::get_test;
405 string str = "";
406 }
407
408 // some builtin types
409 long long ll = 0;
410 long double d = 0.0;
411 unsigned test;
412 unsigned long int **uli = 0;
413 signed si = 0;
414 signed short ss = 0;
415 short int i = 0;
416 long int li = 0;
417
418 // expressions with namespace/class-qualifyiers
419 ORB_var cGlobalOrb = ORB::_nil();
420 ORB_var1 cGlobalOrb1 = ORB::_test;
421
422 class Testclass
423 {
424 #define TEST 0
425 ini i;
426
427 public:
428
429 Testclass();
430 ~Testclass();
431 };
432
433 static void test_function(unsigned int i);
434
435 };
436
437
438 // outside method implementations which should be grouped to type Test
439 XXX&
440 Test::waiting()
441 {
442 return;
443 }
444
445 void
446 Test::print()
447 {
448 return;
449 }
450
451 // outside method implementations with namespaces which should be grouped to
452 // their complete (incl. namespace) types
453 void*
454 Parser::XXX::Foobar::wait(int i, const char const * const * p)
455 {
456 return;
457 }
458
459 void*
460 Namespace1::Test::wait1(int i)
461 {
462 return;
463 }
464
465 int
466 Namespace1::Test::waiting(int i)
467 {
468 return;
469 }
470
471 // a class with some outside implementations which should all be grouped to
472 // this class declaration
473 class ClassWithExternals
474 {
475 private:
476 int i;
477
478 public:
479 ClassWithExternals();
480 ~ClassWithExternals();
481 void non_nil();
482 };
483
484
485 // Foobar is not displayed; seems that semantic tries to add this to the class
486 // Foobar but can not find/display it, because contained in the namespace above.
487 void
488 Foobar::non_nil()
489 {
490 return;
491 }
492
493 // are correctly grouped to the ClassWithExternals class
494 void
495 ClassWithExternals::non_nil()
496 {
497 String s = "lödfjg dlfgkdlfkgjdl";
498 return;
499 }
500
501 ClassWithExternals::ClassWithExternals()
502 {
503 return;
504 }
505
506 void
507 ClassWithExternals::~ClassWithExternals()
508 {
509 return;
510 }
511
512
513 // -------------------------------
514 // Now some macro and define stuff
515 // -------------------------------
516
517 #define TEST 0
518 #define TEST1 "String"
519
520 // The first backslash makes this macro unmatched syntax with semantic 1.4.2!
521 // With flexing \+newline as nothing all is working fine!
522 #define MZK_ENTER(METHOD) \
523 { \
524 CzkMethodLog lMethodLog(METHOD,"Framework");\
525 }
526
527 #define ZK_ASSERTM(METHOD,ASSERTION,MESSAGE) \
528 { if(!(ASSERTION))\
529 {\
530 std::ostringstream lMesgStream; \
531 lMesgStream << "Assertion failed: " \
532 << MESSAGE; \
533 CzkLogManager::doLog(CzkLogManager::FATAL,"",METHOD, \
534 "Assert",lMesgStream); \
535 assert(ASSERTION);\
536 }\
537 }
538
539 // Test if not newline-backslashes are handled correctly
540 string s = "My \"quoted\" string";
541
542 // parsed fine as macro
543 #define FOO (arg) method(arg, "foo");
544
545 // With semantic 1.4.2 this parsed as macro BAR *and* function method.
546 // With latest c.bnf at least one-liner macros can be parsed correctly.
547 #define BAR (arg) CzkMessageLog method(arg, "bar");
548
549 // some const and volatile stuff
550 char * p1 = "Hello"; // 1. variable Pointer, variable Data
551 const char * p2 = "Hello"; // 2. variable pointer, constant data
552 char * const p3 = "Hello"; // 3. constant pointer, variable data
553 const char * const p4 = "Hello"; // 4. constant pointer, constant data
554
555 // Case 2 and 4 can exchange first "const" and "char"
556 char const * p21 = "Hello"; // variable pointer, constant data
557 char const * const p41 = "Hello"; // constant pointer, constant data
558
559 char volatile a = 0; // a volatile char
560 void foo(bar const &arg); // a reference to a const bar
561 int foobar(bar const * const p); // a const pointer to a const bar
562 int foobar(bar const volatile * const p); // a const pointer to a const bar
563 int foobar3(char* p); // a const pointer to a const bar
564
565 // Should not be parsed because this is invalid code
566 int const & const r3 = i;
567
568 boolean i = 0;
569 boolean & r1 = i;
570 boolean const & r2 = i;
571
572 // const * sequences can be very long in C++ ;-)
573 char const * const * const * const * ppp;
574
575 // complex function declarationen with named pointer-arguments
576 const char** foobar1(volatile char const * const **p);
577 const char** foobar11(volatile Test::Namespace::Char<char*> const * const **p);
578
579 // complex function declarationen with unnamed pointer-arguments
580 const char* foobar2(const char***);
581 const char* foobar21(const Test::Namespace::Char<char>***);
582
583 // string literal parsing even with wchar_t
584 char const *p = "string1";
585 char const *q = "string1" "str\"ing2" "string3";
586 wchar_t testc = L'a';
587
588 wchar_t const *wp = L"string with a \" in it";
589 wchar_t const *wq = L"string \n\t\"test" L"string2";
590 wchar_t const *wr = L"string L";
591
592 // arch-tag: 59828880-d72f-4059-922f-89579edf9e58