]>
code.delx.au - gnu-emacs/blob - test/cedet/tests/test.cpp
0c43944a0318df421a98c373d1a6e50dcd77fa43
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
12 #include "c++-test.hh"
14 #include <c++-test.hh>
26 struct foo2
: public foo1
{
27 const int foo21(int a
, int b
);
28 const int foo22(int a
, int b
) { return 1 }
41 class i_class1
: public class1
{
59 class i_class2
: public class1
, public class2
{
71 /* A class with strange things in it */
73 class3(); /* A constructor */
74 enum embedded_foo_enum
{
77 struct embedded_bar_struct
{
81 class embedded_baz_class
{
83 ~embedded_baz_class();
85 ~class3(); /* destructor */
88 int method_for_class3(int a
, char b
);
90 int inline_method(int c
) { return c
; }
93 class3
& operator^= (const class3
& something
);
96 const class3
* const method_const_ptr_ptr(const int * const argconst
) const = 0;
101 /* Constructor outside the definition. */
104 int class3::method_for_class3(int a
, char b
)
108 int class3::method1_for_class3( int a
, int &b
)
112 class3 moose
= new class3
;
114 // Complktion testing line should find external members.
128 char class3::method2_for_class3( int a
, int b
) throw ( exception1
)
133 void *class3::method3_for_class3( int a
, int b
) throw ( exception1
, exception2
)
139 void *class3::method31_for_class3( int a
, int b
) throw ( )
145 void *class3::method4_for_class3( int a
, int b
) reentrant
149 ct
.method5_for_class3(1,a
);
155 * A method on class3.
157 void *class3::method5_for_class3( int a
, int b
) const
162 * Namespace parsing tests
165 class class_in_namespace
{
166 int equiv(const NS::class_in_namespace
*) const;
170 int NS::class_in_namespace::equiv(const NS::class_in_namespace
*cin
) const
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;
182 // The whacky constructor type
196 class class5
: public virtual class4
{
197 // Virtual inheritance
200 class class6
: class1
{
206 namespace namespace1
{
207 void ns_method1() { }
211 void method11(int a
) { }
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
) { }
219 // Macros in the namespace
222 // Template in the namespace
223 template<class T
> T
nsti1(const Foo
& foo
);
224 template<> int nsti1
<int>(const Foo
& foo
);
228 namespace namespace2
{
230 using namespace1::n_class1
;
235 void tinitializers1(): inita1(False
),
241 /* How about Extern C type things. */
242 int funny_prototype(int ,int b
,float c
)
248 int extern_c_1(int a
, int b
)
251 funny_prototype(1,2,3.4);
260 int extern_c_2(int a
, int b
)
267 // Some operator stuff
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*=();
281 // class with namespace qualified parents
282 class Multiinherit
: public virtual POA::Parent
,
283 public virtual POA::Parent1
,
293 // method with a list of qualified exceptions
296 Testnamespace::Exception1
,
297 Testnamespace::Excpetion2
,
298 Testnamespace::testnamespace1::Exception3
);
303 Multiinherit::throwtest()
305 Testnamespace::Exception1
,
306 Testnamespace::Excpetion2
,
307 Testnamespace::testnamespace1::Exception3
)
312 // Jens Rock <jens.rock@asamnet.de>: Nested classes or structs defined
313 // outside of the containing class/struct.
322 struct container::contained
330 * Ok, how about some template stuff.
332 template <class CT
, class container
= vector
<CT
> >
333 const CT
& max (const CT
& a
, const CT
& b
)
335 return a
< b
? b
: a
;
338 // Arne Schmitz found this one
339 std::vector
<int> &a
, &b
, &c
;
341 class TemplateUsingClass
343 typedef TestClassMap::iterator iterator
;
344 typedef map
<long, long> TestClassMap
;
346 // typedefs with const and volatile
347 typedef const map
<long, long> const_TestClassMap
;
348 typedef TestClassMap
<string
>::iterator
volatile volatile_iterator
;
350 map
<int, int> mapclassvarthingy
;
353 template<class T
> T
ti1(const Foo
& foo
);
354 template<> int ti1
<int>(const Foo
& foo
);
357 // -----------------------------------
358 // Now some namespace and related stuff
359 // -----------------------------------
361 using CORBA::LEX::get_token
;
364 using namespace POA::std
;
365 using namespace Test
;
373 using Lexer::get_test
;
380 class Foobar
: public virtual POA::Parent
,
381 public virtual POA::Parent1
,
382 private POA::list
<fact
>,
386 list
<shared_ptr
<item
> >::const_iterator l
;
395 void test_function(int i
);
399 // unnamed namespaces - even nested
404 using Lexer::get_test
;
408 // some builtin types
412 unsigned long int **uli
= 0;
418 // expressions with namespace/class-qualifyiers
419 ORB_var cGlobalOrb
= ORB::_nil();
420 ORB_var1 cGlobalOrb1
= ORB::_test
;
433 static void test_function(unsigned int i
);
438 // outside method implementations which should be grouped to type Test
451 // outside method implementations with namespaces which should be grouped to
452 // their complete (incl. namespace) types
454 Parser::XXX::Foobar::wait(int i
, const char const * const * p
)
460 Namespace1::Test::wait1(int i
)
466 Namespace1::Test::waiting(int i
)
471 // a class with some outside implementations which should all be grouped to
472 // this class declaration
473 class ClassWithExternals
479 ClassWithExternals();
480 ~ClassWithExternals();
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.
493 // are correctly grouped to the ClassWithExternals class
495 ClassWithExternals::non_nil()
497 String s
= "lödfjg dlfgkdlfkgjdl";
501 ClassWithExternals::ClassWithExternals()
507 ClassWithExternals::~ClassWithExternals()
513 // -------------------------------
514 // Now some macro and define stuff
515 // -------------------------------
518 #define TEST1 "String"
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) \
524 CzkMethodLog lMethodLog(METHOD,"Framework");\
527 #define ZK_ASSERTM(METHOD,ASSERTION,MESSAGE) \
530 std::ostringstream lMesgStream; \
531 lMesgStream << "Assertion failed: " \
533 CzkLogManager::doLog(CzkLogManager::FATAL,"",METHOD, \
534 "Assert",lMesgStream); \
539 // Test if not newline-backslashes are handled correctly
540 string s
= "My \"quoted\" string";
542 // parsed fine as macro
543 #define FOO (arg) method(arg, "foo");
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");
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
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
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
565 // Should not be parsed because this is invalid code
566 int const & const r3
= i
;
570 boolean
const & r2
= i
;
572 // const * sequences can be very long in C++ ;-)
573 char const * const * const * const * ppp
;
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
);
579 // complex function declarationen with unnamed pointer-arguments
580 const char* foobar2(const char***);
581 const char* foobar21(const Test::Namespace::Char
<char>***);
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';
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";
592 // arch-tag: 59828880-d72f-4059-922f-89579edf9e58