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
6 * $Id: test.cpp,v 1.1 2007-11-26 15:12:22 michaels Exp $
13 #include "c++-test.hh"
15 #include <c++-test.hh>
29 struct foo2 : public foo1 {
30 const int foo21(int a, int b);
31 const int foo22(int a, int b) { return 1 }
44 class i_class1 : public class1 {
62 class i_class2 : public class1, public class2 {
74 /* A class with strange things in it */
76 class3(); /* A constructor */
77 enum embedded_foo_enum {
80 struct embedded_bar_struct {
84 class embedded_baz_class {
86 ~embedded_baz_class();
88 ~class3(); /* destructor */
91 int method_for_class3(int a, char b);
93 int inline_method(int c) { return c; }
96 class3& operator^= (const class3& something);
99 const class3 * const method_const_ptr_ptr(const int * const argconst) const = 0;
104 /* Constructor outside the definition. */
107 int class3::method_for_class3(int a, char b)
111 int class3::method1_for_class3( int a, int &b)
116 // Complktion testing line should find external members.
130 char class3::method2_for_class3( int a, int b) throw ( exception1 )
135 void *class3::method3_for_class3( int a, int b) throw ( exception1, exception2 )
141 void *class3::method31_for_class3( int a, int b) throw ( )
147 void *class3::method4_for_class3( int a, int b) reentrant
151 ct.method5_for_class3(1,a)
155 * A method on class3.
157 void *class3::method5_for_class3( int a, int b) const
161 // Stuff Klaus found.
162 // Inheritance w/out a specifying for public.
163 class class4 : class1 {
164 // Pure virtual methods.
165 void virtual print () const = 0;
168 // The whacky constructor type
182 class class5 : public virtual class4 {
183 // Virtual inheritance
186 class class6 : class1 {
192 namespace namespace1 {
193 void ns_method1() { }
197 void method11(int a) { }
200 /* This shouldn't parse due to missing semicolon. */
201 class _n_class2 : public n_class1 {
202 void n_c2_method1(int a, int b) { }
205 // Macros in the namespace
208 // Template in the namespace
209 template<class T> T nsti1(const Foo& foo);
210 template<> int nsti1<int>(const Foo& foo);
214 namespace namespace2 {
216 using namespace1::n_class1;
221 void tinitializers1(): inita1(False),
227 /* How about Extern C type things. */
228 int funny_prototype(int ,int b,float c)
234 int extern_c_1(int a, int b)
237 funny_prototype(1,2,3.4);
244 int extern_c_2(int a, int b)
251 // Some operator stuff
254 // Problems!! operator() and operator[] can not be parsed with semantic
255 // 1.4.2 but with latest c.bnf
256 virtual void operator()(int i, char *p ) = 0;
257 virtual String& operator[]() = 0;
258 virtual void operator!() = 0;
259 virtual void operator->() = 0;
260 virtual T& operator+=();
263 // class with namespace qualified parents
264 class Multiinherit : public virtual POA::Parent,
265 public virtual POA::Parent1,
275 // method with a list of qualified exceptions
278 Testnamespace::Exception1,
279 Testnamespace::Excpetion2,
280 Testnamespace::testnamespace1::Exception3);
285 Multiinherit::throwtest()
287 Testnamespace::Exception1,
288 Testnamespace::Excpetion2,
289 Testnamespace::testnamespace1::Exception3)
294 // Jens Rock <jens.rock@asamnet.de>: Nested classes or structs defined
295 // outside of the containing class/struct.
304 struct container::contained
312 * Ok, how about some template stuff.
314 template <class CT, class container = vector<CT> >
315 const CT& max (const CT& a, const CT& b)
317 return a < b ? b : a;
320 class TemplateUsingClass
322 typedef TestClassMap::iterator iterator;
323 typedef map<long, long> TestClassMap;
325 // typedefs with const and volatile
326 typedef const map<long, long> const_TestClassMap;
327 typedef TestClassMap<string>::iterator volatile volatile_iterator;
329 map<int, int> mapclassvarthingy;
332 template<class T> T ti1(const Foo& foo);
333 template<> int ti1<int>(const Foo& foo);
336 // -----------------------------------
337 // Now some namespace and related stuff
338 // -----------------------------------
340 using CORBA::LEX::get_token;
343 using namespace POA::std;
344 using namespace Test;
352 using Lexer::get_test;
359 class Foobar : public virtual POA::Parent,
360 public virtual POA::Parent1,
361 private POA::list<fact>,
365 list <shared_ptr<item> >::const_iterator l;
374 void test_function(int i);
378 // unnamed namespaces - even nested
383 using Lexer::get_test;
387 // some builtin types
391 unsigned long int **uli = 0;
397 // expressions with namespace/class-qualifyiers
398 ORB_var cGlobalOrb = ORB::_nil();
399 ORB_var1 cGlobalOrb1 = ORB::_test;
412 static void test_function(unsigned int i);
417 // outside method implementations which should be grouped to type Test
430 // outside method implementations with namespaces which should be grouped to
431 // their complete (incl. namespace) types
433 Parser::XXX::Foobar::wait(int i, const char const * const * p)
439 Namespace1::Test::wait1(int i)
445 Namespace1::Test::waiting(int i)
450 // a class with some outside implementations which should all be grouped to
451 // this class declaration
452 class ClassWithExternals
458 ClassWithExternals();
459 ~ClassWithExternals();
464 // Foobar is not displayed; seems that semantic tries to add this to the class
465 // Foobar but can not find/display it, because contained in the namespace above.
472 // are correctly grouped to the ClassWithExternals class
474 ClassWithExternals::non_nil()
476 String s = "lödfjg dlfgkdlfkgjdl";
480 ClassWithExternals::ClassWithExternals()
486 ClassWithExternals::~ClassWithExternals()
492 // -------------------------------
493 // Now some macro and define stuff
494 // -------------------------------
497 #define TEST1 "String"
499 // The first backslash makes this macro unmatched syntax with semantic 1.4.2!
500 // With flexing \+newline as nothing all is working fine!
501 #define MZK_ENTER(METHOD) \
503 CzkMethodLog lMethodLog(METHOD,"Framework");\
506 #define ZK_ASSERTM(METHOD,ASSERTION,MESSAGE) \
509 std::ostringstream lMesgStream; \
510 lMesgStream << "Assertion failed: " \
512 CzkLogManager::doLog(CzkLogManager::FATAL,"",METHOD, \
513 "Assert",lMesgStream); \
518 // Test if not newline-backslashes are handled correctly
519 string s = "My \"quoted\" string";
521 // parsed fine as macro
522 #define FOO (arg) method(arg, "foo");
524 // With semantic 1.4.2 this parsed as macro BAR *and* function method.
525 // With latest c.bnf at least one-liner macros can be parsed correctly.
526 #define BAR (arg) CzkMessageLog method(arg, "bar");
528 // some const and volatile stuff
529 char * p1 = "Hello"; // 1. variable Pointer, variable Data
530 const char * p2 = "Hello"; // 2. variable pointer, constant data
531 char * const p3 = "Hello"; // 3. constant pointer, variable data
532 const char * const p4 = "Hello"; // 4. constant pointer, constant data
534 // Case 2 and 4 can exchange first "const" and "char"
535 char const * p21 = "Hello"; // variable pointer, constant data
536 char const * const p41 = "Hello"; // constant pointer, constant data
538 char volatile a = 0; // a volatile char
539 void foo(bar const &arg); // a reference to a const bar
540 int foobar(bar const * const p); // a const pointer to a const bar
541 int foobar(bar const volatile * const p); // a const pointer to a const bar
542 int foobar3(char* p); // a const pointer to a const bar
544 // Should not be parsed because this is invalid code
545 int const & const r3 = i;
549 boolean const & r2 = i;
551 // const * sequences can be very long in C++ ;-)
552 char const * const * const * const * ppp;
554 // complex function declarationen with named pointer-arguments
555 const char** foobar1(volatile char const * const **p);
556 const char** foobar11(volatile Test::Namespace::Char<char*> const * const **p);
558 // complex function declarationen with unnamed pointer-arguments
559 const char* foobar2(const char***);
560 const char* foobar21(const Test::Namespace::Char<char>***);
562 // string literal parsing even with wchar_t
563 char const *p = "string1";
564 char const *q = "string1" "str\"ing2" "string3";
565 wchar_t testc = L'a';
567 wchar_t const *wp = L"string with a \" in it";
568 wchar_t const *wq = L"string \n\t\"test" L"string2";
569 wchar_t const *wr = L"string L";