PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/bundle/tagbar/tests/jptest ??????????/test.cpp

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