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