~ubuntu-branches/debian/sid/eclipse-cdt/sid

« back to all changes in this revision

Viewing changes to results/plugins/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexCPPBindingResolutionTest.java

  • Committer: Package Import Robot
  • Author(s): Jakub Adam
  • Date: 2011-10-06 21:15:04 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20111006211504-8dutmljjih0zikfv
Tags: 8.0.1-1
* New upstream release.
* Split the JNI packages into a separate architecture dependent
  package and made eclipse-cdt architecture independent.
* Install JNI libraries into multiarch aware location
* Bumped Standards-Version to 3.9.2.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*******************************************************************************
2
 
 * Copyright (c) 2007, 2008 Symbian Software Systems and others.
3
 
 * All rights reserved. This program and the accompanying materials
4
 
 * are made available under the terms of the Eclipse Public License v1.0
5
 
 * which accompanies this distribution, and is available at
6
 
 * http://www.eclipse.org/legal/epl-v10.html
7
 
 *
8
 
 * Contributors:
9
 
 *    Andrew Ferguson (Symbian) - Initial implementation
10
 
 *    Markus Schorn (Wind River Systems)
11
 
 *    Sergey Prigogin (Google)
12
 
 *******************************************************************************/
13
 
package org.eclipse.cdt.internal.index.tests;
14
 
 
15
 
import java.io.IOException;
16
 
import java.util.Arrays;
17
 
import java.util.HashSet;
18
 
import java.util.Set;
19
 
 
20
 
import junit.framework.TestSuite;
21
 
 
22
 
import org.eclipse.cdt.core.dom.ast.DOMException;
23
 
import org.eclipse.cdt.core.dom.ast.IBinding;
24
 
import org.eclipse.cdt.core.dom.ast.ICompositeType;
25
 
import org.eclipse.cdt.core.dom.ast.IEnumeration;
26
 
import org.eclipse.cdt.core.dom.ast.IEnumerator;
27
 
import org.eclipse.cdt.core.dom.ast.IPointerType;
28
 
import org.eclipse.cdt.core.dom.ast.IType;
29
 
import org.eclipse.cdt.core.dom.ast.IValue;
30
 
import org.eclipse.cdt.core.dom.ast.IVariable;
31
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBasicType;
32
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPBinding;
33
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassScope;
34
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPClassType;
35
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPConstructor;
36
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
37
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunction;
38
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPFunctionType;
39
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
40
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
41
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceScope;
42
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPPointerToMemberType;
43
 
import org.eclipse.cdt.core.dom.ast.cpp.ICPPVariable;
44
 
import org.eclipse.cdt.core.index.IIndex;
45
 
import org.eclipse.cdt.core.index.IIndexBinding;
46
 
import org.eclipse.core.runtime.CoreException;
47
 
 
48
 
/**
49
 
 * For testing PDOM binding CPP language resolution
50
 
 */
51
 
/*
52
 
 * aftodo - once we have non-problem bindings working, each test should
53
 
 * additionally check that the binding obtained has characteristics as
54
 
 * expected (type,name,etc..)
55
 
 */
56
 
public abstract class IndexCPPBindingResolutionTest extends IndexBindingResolutionTestBase {
57
 
 
58
 
        public static class SingleProject extends IndexCPPBindingResolutionTest {
59
 
                public SingleProject() {setStrategy(new SinglePDOMTestStrategy(true));}
60
 
                public static TestSuite suite() {return suite(SingleProject.class);}
61
 
        }
62
 
        public static class ProjectWithDepProj extends IndexCPPBindingResolutionTest {
63
 
                public ProjectWithDepProj() {setStrategy(new ReferencedProject(true));}
64
 
                public static TestSuite suite() {return suite(ProjectWithDepProj.class);}
65
 
        }
66
 
        
67
 
        public static void addTests(TestSuite suite) {          
68
 
                suite.addTest(SingleProject.suite());
69
 
                suite.addTest(ProjectWithDepProj.suite());
70
 
        }
71
 
        
72
 
        //      namespace ns { class A; enum E {E1}; typedef int T; }
73
 
        //
74
 
        //      class B {
75
 
        //    public:
76
 
        //        void m(ns::A* a);
77
 
        //    void n(ns::E* a);
78
 
        //        void o(ns::T* a);
79
 
        //    void p(ns::E a);
80
 
        //      };
81
 
        
82
 
        //      namespace ns {
83
 
        //        class A {};
84
 
        //    typedef int T;
85
 
        //      }
86
 
        //
87
 
        //      using ns::A;
88
 
        //      using ns::E;
89
 
        //      using ns::T;
90
 
        //  using ns::E1;
91
 
        // 
92
 
        //      void B::m(A* a) {}
93
 
        //      void B::n(E* a) {}
94
 
        //      void B::o(T* a) {}
95
 
    //  void B::p(E a) {}
96
 
        //
97
 
        //  void usage() {
98
 
        //    B b;
99
 
        //    b.p(E1);
100
 
        //  }
101
 
        public void testUsingTypeDirective_201177() {
102
 
                IBinding b0= getBindingFromASTName("B::m", 4);
103
 
                IBinding b1= getBindingFromASTName("B::n", 4);
104
 
                IBinding b2= getBindingFromASTName("B::o", 4);
105
 
                IBinding b3= getBindingFromASTName("p(E1)", 1);
106
 
                assertInstance(b0, ICPPMethod.class);
107
 
                assertInstance(b1, ICPPMethod.class);
108
 
                assertInstance(b2, ICPPMethod.class);
109
 
        }
110
 
        
111
 
        // namespace n { class A{}; class B{}; class C{}; }
112
 
 
113
 
        // namespace m {
114
 
        //    using namespace n;
115
 
        //    class D{};
116
 
        // }
117
 
        // m::C c;
118
 
        // m::D d;
119
 
        public void testUsingNamingDirective_177917_1a() {
120
 
                IBinding b0= getBindingFromASTName("C c", 1);
121
 
                IBinding b1= getBindingFromASTName("D d", 1);
122
 
        }
123
 
        
124
 
        // namespace n { class A{}; }
125
 
        // namespace m {
126
 
        // using namespace n;
127
 
        //     class B {};
128
 
        // }
129
 
 
130
 
        // #include "header.h"
131
 
        // namespace n { class C{}; }
132
 
        // m::C c;
133
 
        public void testUsingNamingDirective_177917_1b() {
134
 
                IBinding b0= getBindingFromASTName("C c", 1);
135
 
        }
136
 
 
137
 
        // int ff(int x) { return x; }
138
 
        // namespace n { class A {}; }
139
 
        // namespace m { class B {}; enum C{CE1,CE2}; }
140
 
        // namespace o { int (*f)(int)= ff; }
141
 
 
142
 
        // using n::A;
143
 
        // A a;
144
 
        // using namespace m;
145
 
        // B b;
146
 
        // C c= CE1;
147
 
        // using o::f;
148
 
        // int g(int x) {return 4;}
149
 
        // int g(char x) {return 2;}
150
 
        // int nn= g(f(2));
151
 
        public void testUsingTypeDirective_177917_1() {
152
 
                IBinding b1= getBindingFromASTName("A a", 1);
153
 
                IBinding b2= getBindingFromASTName("B b", 1);
154
 
                IBinding b3= getBindingFromASTName("C c", 1);
155
 
                IBinding b4= getBindingFromASTName("CE1", 3);
156
 
                IBinding b5= getBindingFromASTName("f(2", 1);
157
 
        }
158
 
        
159
 
        // namespace a { class A {}; }
160
 
        // namespace b {
161
 
        //     using a::A;
162
 
        //     class B {};
163
 
        // }
164
 
 
165
 
        // #include "header.h"
166
 
        // b::A aa;
167
 
        // b::B bb;
168
 
        public void testUsingTypeDirective_177917_2() {
169
 
                IBinding b0= getBindingFromASTName("A aa", 1);
170
 
                IBinding b1= getBindingFromASTName("B bb", 1);
171
 
        }
172
 
        
173
 
        //      namespace header {
174
 
        //              class clh {
175
 
        //              };
176
 
        //              void fh();
177
 
        //              void fh(int a);
178
 
        //              
179
 
        //              class cl {
180
 
        //              };
181
 
        //              void f();
182
 
        //              void f(int a);
183
 
        //      }
184
 
        //      using header::clh;
185
 
        //      using header::fh;
186
 
                
187
 
        //      #include "header.h"
188
 
        //      namespace source {
189
 
        //              class cls {
190
 
        //              };
191
 
        //              void fs();
192
 
        //              void fs(int a);
193
 
        //              
194
 
        //      }
195
 
        //      using header::cl;
196
 
        //      using header::f;
197
 
        //
198
 
        //
199
 
        //      using source::cls;
200
 
        //      using source::fs;
201
 
        //
202
 
        //      void test() {
203
 
        //              fh();
204
 
        //              fh(1);  
205
 
        //                    
206
 
        //              clh c;
207
 
        //              
208
 
        //              f();
209
 
        //              f(1);
210
 
        //              cl c1;
211
 
        //
212
 
        //              fs();
213
 
        //              fs(1);
214
 
        //              cls c2;
215
 
        //      }
216
 
        public void testUsingOverloadedFunctionDirective() {
217
 
                IBinding b;
218
 
                b= getBindingFromASTName("fh()", 2);
219
 
                b= getBindingFromASTName("fh(1)", 2);
220
 
                b= getBindingFromASTName("clh c", 3);
221
 
                b= getBindingFromASTName("f()", 1);
222
 
                b= getBindingFromASTName("f(1)", 1);
223
 
                b= getBindingFromASTName("cl c1", 2);
224
 
                b= getBindingFromASTName("fs()", 2);
225
 
                b= getBindingFromASTName("fs(1)", 2);
226
 
                b= getBindingFromASTName("cls c2", 3);
227
 
        }
228
 
 
229
 
        
230
 
        // int (*f)(int);
231
 
        // int g(int n){return n;}
232
 
        // int g(int n, int m){ return n+m; }
233
 
        
234
 
        // void foo() {
235
 
        //    f= g;
236
 
        // }
237
 
        public void testPointerToFunction() throws Exception {
238
 
                IBinding b0 = getBindingFromASTName("f= g;", 1);                
239
 
                IBinding b1 = getBindingFromASTName("g;", 1);
240
 
                
241
 
                assertInstance(b0, ICPPVariable.class);
242
 
                ICPPVariable v0= (ICPPVariable) b0;
243
 
                assertInstance(v0.getType(), IPointerType.class);
244
 
                IPointerType p0= (IPointerType) v0.getType();
245
 
                assertInstance(p0.getType(), ICPPFunctionType.class);
246
 
                ICPPFunctionType f0= (ICPPFunctionType) p0.getType();
247
 
                assertInstance(f0.getReturnType(), ICPPBasicType.class);
248
 
                assertEquals(1, f0.getParameterTypes().length);
249
 
                assertInstance(f0.getParameterTypes()[0], ICPPBasicType.class);
250
 
                
251
 
                assertInstance(b1, ICPPFunction.class);
252
 
                ICPPFunctionType f1= ((ICPPFunction)b1).getType();
253
 
                assertInstance(f1.getReturnType(), ICPPBasicType.class);
254
 
                assertEquals(1, f1.getParameterTypes().length);
255
 
                assertInstance(f1.getParameterTypes()[0], ICPPBasicType.class);
256
 
        }
257
 
 
258
 
        // // header file
259
 
        //  class Base {public: int field; void foo() {}};
260
 
        //      class C : public Base {
261
 
        //              public:
262
 
        //                      struct CS { long* l; C *method(CS **); };
263
 
        //                      CS cs;
264
 
        //                      CS **cspp;
265
 
        //                      long * CS::* ouch;
266
 
        //                      long * CS::* autsch;
267
 
        //                      C* (CS::*method)(CS **);
268
 
        //              };
269
 
 
270
 
        // // referencing file
271
 
        //      #include "header.h"
272
 
        //  
273
 
        //  C *cp = new C(); /*b0, b1*/
274
 
        //      void references() {
275
 
        //              long l = 5, *lp;
276
 
        //              lp = &l;
277
 
        //              cp->cs.*cp->ouch = lp = cp->cs.*cp->autsch; /*b2, b3, b4*/
278
 
        //              &(cp->cs)->*cp->autsch = lp = &(cp->cs)->*cp->ouch;
279
 
        //              (cp->cs).method(cp->cspp);/*1*/ (&(cp->cs))->method(cp->cspp);/*2*/
280
 
        //              ((cp->cs).*(cp->method))(cp->cspp);/*3*/
281
 
        //              ((&(cp->cs))->*(cp->method))(cp->cspp);/*4*/
282
 
        //      }
283
 
        public void testPointerToMemberFields() throws IOException, DOMException {
284
 
                IBinding b0 = getBindingFromASTName("C *cp", 1);
285
 
                assertClassType((ICPPClassType)b0, "C", ICPPClassType.k_class, 1, 6, 5, 9, 0, 1, 0, 2, 1);
286
 
                
287
 
                IBinding b1 = getBindingFromASTName("cp = new C()", 2);
288
 
                assertVariable(b1, "cp", IPointerType.class, null);
289
 
                IPointerType b1type = (IPointerType) ((ICPPVariable)b1).getType();
290
 
                assertClassType(b1type.getType(), "C", ICPPClassType.k_class, 1, 6, 5, 9, 0, 1, 0, 2, 1);
291
 
                
292
 
                IBinding b2 = getBindingFromASTName("cs.*cp->o", 2);
293
 
                ICPPField field0 = (ICPPField) b2;
294
 
                assertTrue(field0.getType() instanceof ICPPClassType);
295
 
 
296
 
                IBinding b3 = getBindingFromASTName("ouch = lp", 4);
297
 
                assertField(b3, "C::ouch", ICPPPointerToMemberType.class, null);
298
 
                assertPTM(((ICPPField)b3).getType(), "C::CS", null);
299
 
 
300
 
                IBinding b4 = getBindingFromASTName("autsch;", 6);
301
 
                assertField(b4, "C::autsch", ICPPPointerToMemberType.class, null);
302
 
                assertPTM(((ICPPField)b4).getType(), "C::CS", null);
303
 
 
304
 
                IBinding b5 = getBindingFromASTName("cs)->*cp->a", 2);
305
 
                assertField(b5, "C::cs", ICPPClassType.class, "C::CS");
306
 
                assertClassType(((ICPPField)b5).getType(), "C::CS", ICompositeType.k_struct, 0, 1, 1, 5, 1, 1, 0, 2, 0);
307
 
 
308
 
                IBinding b6 = getBindingFromASTName("autsch = lp", 6);
309
 
                assertField(b4, "C::autsch", ICPPPointerToMemberType.class, null);
310
 
                assertPTM(((ICPPField)b4).getType(), "C::CS", null);
311
 
 
312
 
                IBinding b7 = getBindingFromASTName("ouch;", 4);
313
 
                assertField(b3, "C::ouch", ICPPPointerToMemberType.class, null);
314
 
                assertPTM(((ICPPField)b3).getType(), "C::CS", null);
315
 
        }
316
 
 
317
 
        // // header file
318
 
        // class C {}; struct S {}; union U {}; enum E {ER1,ER2,ER3};
319
 
        // int var1; C var2; S *var3; void func(E); void func(C);
320
 
        // namespace ns {}
321
 
        // typedef int Int; typedef int *IntPtr;
322
 
        // void func(int*); void func(int);
323
 
 
324
 
        // // referencing file
325
 
        // #include "header.h"
326
 
        // void references() {
327
 
        //      C c; /*c*/ S s; /*s*/ U u; /*u*/ E e; /*e*/
328
 
        //  var1 = 1; /*var1*/ var2 = c; /*var2*/ var3 = &s; /*var3*/
329
 
        //  func(e); /*func1*/ func(var1); /*func2*/ func(c); /*func3*/
330
 
        //  Int a; /*a*/
331
 
        //  IntPtr b = &a; /*b*/
332
 
        //  func(*b); /*func4*/ func(a); /*func5*/
333
 
        // }
334
 
        // class C2 : public C {}; /*base*/
335
 
        // struct S2 : public S {}; /*base*/
336
 
        public void testSimpleGlobalBindings() throws IOException, DOMException {
337
 
                {
338
 
                        IBinding b0 = getBindingFromASTName("C c; ", 1);
339
 
                        assertClassTypeBinding(b0, "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
340
 
 
341
 
                        IBinding b1 = getBindingFromASTName("c; ", 1);
342
 
                        assertVariable(b1, "c", ICPPClassType.class, "C");
343
 
                        ICPPClassType b1type = (ICPPClassType)((ICPPVariable)b1).getType();
344
 
                        assertClassTypeBinding(b1type, "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
345
 
                        assertTrue(b1type.getScope() == null);
346
 
                        assertTrue(b1type.getCompositeScope() instanceof ICPPClassScope);
347
 
                        assertClassTypeBinding(((ICPPClassScope)b1type.getCompositeScope()).getClassType(), "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
348
 
                }
349
 
                {
350
 
                        IBinding b2 = getBindingFromASTName("S s;", 1);
351
 
                        assertClassTypeBinding(b2, "S", ICompositeType.k_struct, 0, 0, 0, 4, 0, 0, 0, 2, 0);
352
 
 
353
 
                        IBinding b3 = getBindingFromASTName("s;", 1);
354
 
                        assertVariable(b3, "s", ICPPClassType.class, "S");
355
 
                        ICPPClassType b3type = (ICPPClassType)((ICPPVariable)b3).getType();
356
 
                        assertClassTypeBinding(b3type, "S", ICompositeType.k_struct, 0, 0, 0, 4, 0, 0, 0, 2, 0);
357
 
                }
358
 
                {
359
 
                        IBinding b4 = getBindingFromASTName("U u;", 1);
360
 
                        assertClassTypeBinding(b4, "U", ICompositeType.k_union, 0, 0, 0, 4, 0, 0, 0, 2, 0);
361
 
 
362
 
                        IBinding b5 = getBindingFromASTName("u; ", 1);
363
 
                        assertVariable(b5, "u", ICPPClassType.class, "U");
364
 
                        ICPPClassType b5type = (ICPPClassType)((ICPPVariable)b5).getType();
365
 
                        assertClassTypeBinding(b5type, "U", ICompositeType.k_union, 0, 0, 0, 4, 0, 0, 0, 2, 0);
366
 
                }
367
 
                {
368
 
                        IBinding b6 = getBindingFromASTName("E e; ", 1);
369
 
                        assertEnumeration(b6, "E", new String[] {"ER1","ER2","ER3"});
370
 
 
371
 
                        IBinding b7 = getBindingFromASTName("e; ", 1);
372
 
                        assertVariable(b7, "e", IEnumeration.class, "E");
373
 
                        IEnumeration b5type = (IEnumeration)((ICPPVariable)b7).getType();
374
 
                        assertEnumeration(b5type, "E", new String[] {"ER1","ER2","ER3"});
375
 
                        assertTrue(b5type.getScope() == null);
376
 
                }
377
 
                {
378
 
                        IBinding b8 = getBindingFromASTName("var1 = 1;", 4);
379
 
                        assertVariable(b8, "var1", ICPPBasicType.class, null);
380
 
                }
381
 
                {
382
 
                        IBinding b9 = getBindingFromASTName("var2 = c;", 4);
383
 
                        assertVariable(b9, "var2", ICPPClassType.class, "C");
384
 
                        ICPPClassType b9type = (ICPPClassType)((ICPPVariable)b9).getType();
385
 
                        assertClassTypeBinding(b9type, "C", ICPPClassType.k_class, 0, 0, 0, 4, 0, 0, 0, 2, 0);
386
 
                }
387
 
                {
388
 
                        IBinding b10 = getBindingFromASTName("var3 = &s;", 4);
389
 
                        assertVariable(b10, "var3", IPointerType.class, null);
390
 
                        IPointerType b10type = (IPointerType) ((ICPPVariable)b10).getType();
391
 
                        assertClassTypeBinding((ICPPClassType) b10type.getType(), "S", ICompositeType.k_struct, 0, 0, 0, 4, 0, 0, 0, 2, 0);
392
 
                }
393
 
                {
394
 
                        IBinding b11 = getBindingFromASTName("func(e);", 4);
395
 
                }
396
 
                IBinding b12 = getBindingFromASTName("func(var1);", 4);
397
 
                IBinding b13 = getBindingFromASTName("func(c);", 4);
398
 
                IBinding b14 = getBindingFromASTName("Int a; ", 3);
399
 
                IBinding b15 = getBindingFromASTName("a; ", 1);
400
 
                IBinding b16 = getBindingFromASTName("IntPtr b = &a; ", 6);
401
 
                IBinding b17 = getBindingFromASTName("b = &a; /*b*/", 1);
402
 
                IBinding b18 = getBindingFromASTName("func(*b);", 4);
403
 
                IBinding b19 = getBindingFromASTName("b); /*func4*/", 1);
404
 
                IBinding b20 = getBindingFromASTName("func(a);", 4);
405
 
                IBinding b21 = getBindingFromASTName("a); /*func5*/", 1);
406
 
                IBinding b22 = getBindingFromASTName("C2 : public", 2);
407
 
                IBinding b23 = getBindingFromASTName("C {}; /*base*/", 1);              
408
 
                IBinding b24 = getBindingFromASTName("S2 : public", 2);
409
 
                IBinding b25 = getBindingFromASTName("S {}; /*base*/", 1);              
410
 
        }
411
 
 
412
 
 
413
 
        //// header content
414
 
        //class TopC {}; struct TopS {}; union TopU {}; enum TopE {TopER1,TopER2};
415
 
        //short topBasic; void *topPtr; TopC *topCPtr; TopU topFunc(){return *new TopU();}
416
 
 
417
 
        //// referencing content
418
 
        //namespace n1 {
419
 
        //   class TopC {}; struct TopS {}; union TopU {}; enum TopE {TopER1,TopER2};
420
 
        //   short topBasic; void *topPtr;/*A*/ TopC *topCPtr;/*A*/ TopU topFunc(){return *new TopU();}   
421
 
        //   class C {
422
 
        //      class TopC {}; struct TopS {}; union TopU {}; enum TopE {TopER1,TopER2};
423
 
        //      short topBasic; void *topPtr;/*B*/ TopC *topCPtr;/*B*/ TopU topFunc(){return *new TopU();}
424
 
        //      void references() {
425
 
        //         ::TopC c; ::TopS s; ::TopU u; ::TopE e = ::TopER1;
426
 
        //         ::topBasic++; ::topPtr = &::topBasic; ::topCPtr = &c; ::topFunc();
427
 
        //      } 
428
 
        //   };
429
 
        //}
430
 
        public void testSingletonQualifiedName() {
431
 
                IBinding b0 = getBindingFromASTName("TopC c", 4);
432
 
                IBinding b1 = getBindingFromASTName("TopS s", 4);
433
 
                IBinding b2 = getBindingFromASTName("TopU u", 4);
434
 
                IBinding b3 = getBindingFromASTName("TopE e", 4);
435
 
                IBinding b4 = getBindingFromASTName("TopER1;", 6);
436
 
                IBinding b5 = getBindingFromASTName("topBasic++", 8);
437
 
                IBinding b6 = getBindingFromASTName("topPtr = &", 6);
438
 
                IBinding b7 = getBindingFromASTName("topBasic; ::", 8);
439
 
                IBinding b8 = getBindingFromASTName("topCPtr = &", 7);
440
 
                IBinding b9 = getBindingFromASTName("topFunc();", 7);
441
 
 
442
 
                IBinding _b5 = getBindingFromASTName("topBasic; v", 8);
443
 
                IBinding _b6 = getBindingFromASTName("topPtr;/*A*/", 6);
444
 
                IBinding _b7 = getBindingFromASTName("topPtr;/*B*/", 6);
445
 
                IBinding _b8 = getBindingFromASTName("topCPtr;/*A*/", 7);
446
 
                IBinding _b9 = getBindingFromASTName("topCPtr;/*B*/", 7);
447
 
                IBinding _b10 = getBindingFromASTName("topFunc(){", 7);
448
 
        }
449
 
 
450
 
        //      // header content
451
 
        // namespace n1 { namespace n2 { struct S {}; } }
452
 
        // class c1 { public: class c2 { public: struct S {}; }; };
453
 
        // struct s1 { struct s2 { struct S {}; }; };
454
 
        // union u1 { struct u2 { struct S {}; }; };
455
 
        // namespace n3 { class c3 { public: struct s3 { union u3 { struct S {}; }; }; }; }
456
 
 
457
 
        // // reference content
458
 
        // void reference() {
459
 
        //  ::n1::n2::S _s0; n1::n2::S _s1;
460
 
        //  ::c1::c2::S _s2; c1::c2::S _s3;
461
 
        //  ::s1::s2::S _s4; s1::s2::S _s5;
462
 
        //  ::u1::u2::S _s6; u1::u2::S _s7;
463
 
        //  ::n3::c3::s3::u3::S _s8;
464
 
        //    n3::c3::s3::u3::S _s9;
465
 
        // }
466
 
        // namespace n3 { c3::s3::u3::S _s10; }
467
 
        // namespace n1 { n2::S _s11; }
468
 
        // namespace n1 { namespace n2 { S _s12; }} 
469
 
        public void testQualifiedNamesForStruct() throws DOMException {
470
 
                IBinding b0 = getBindingFromASTName("S _s0;", 1);
471
 
                assertTrue(b0.getScope() instanceof ICPPNamespaceScope);
472
 
                assertTrue(b0.getScope().getParent() instanceof ICPPNamespaceScope);
473
 
                assertTrue(b0.getScope().getParent().getParent() == null);
474
 
                assertQNEquals("n1::n2::S", b0);
475
 
                
476
 
                IBinding b1 = getBindingFromASTName("S _s1;", 1);
477
 
                assertTrue(b1.getScope() instanceof ICPPNamespaceScope);
478
 
                assertTrue(b1.getScope().getParent() instanceof ICPPNamespaceScope);
479
 
                assertTrue(b1.getScope().getParent().getParent() == null);
480
 
                assertQNEquals("n1::n2::S", b1);
481
 
                
482
 
                IBinding b2 = getBindingFromASTName("S _s2;", 1);
483
 
                assertTrue(b2.getScope() instanceof ICPPClassScope);
484
 
                assertTrue(b2.getScope().getParent() instanceof ICPPClassScope);
485
 
                assertTrue(b2.getScope().getParent().getParent() == null);
486
 
                assertQNEquals("c1::c2::S", b2);
487
 
                
488
 
                IBinding b3 = getBindingFromASTName("S _s3;", 1);
489
 
                assertQNEquals("c1::c2::S", b3);
490
 
                IBinding b4 = getBindingFromASTName("S _s4;", 1);
491
 
                assertQNEquals("s1::s2::S", b4);
492
 
                IBinding b5 = getBindingFromASTName("S _s5;", 1);
493
 
                assertQNEquals("s1::s2::S", b5);
494
 
                IBinding b6 = getBindingFromASTName("S _s6;", 1);
495
 
                assertQNEquals("u1::u2::S", b6);
496
 
                IBinding b7 = getBindingFromASTName("S _s7;", 1);
497
 
                assertQNEquals("u1::u2::S", b7);
498
 
                IBinding b8 = getBindingFromASTName("S _s8;", 1);
499
 
                assertQNEquals("n3::c3::s3::u3::S", b8);
500
 
                IBinding b9 = getBindingFromASTName("S _s9;", 1);
501
 
                assertQNEquals("n3::c3::s3::u3::S", b9);
502
 
                
503
 
                IBinding b10 = getBindingFromASTName("S _s10;", 1);
504
 
                assertTrue(b10.getScope() instanceof ICPPClassScope);
505
 
                assertTrue(b10.getScope().getParent() instanceof ICPPClassScope);
506
 
                assertTrue(b10.getScope().getParent().getParent() instanceof ICPPClassScope);
507
 
                assertTrue(b10.getScope().getParent().getParent().getParent() instanceof ICPPNamespaceScope);
508
 
                assertTrue(b10.getScope().getParent().getParent().getParent().getParent() == null);
509
 
                assertQNEquals("n3::c3::s3::u3::S", b10);
510
 
                
511
 
                IBinding b11 = getBindingFromASTName("S _s11;", 1);
512
 
                assertQNEquals("n1::n2::S", b11);
513
 
                IBinding b12 = getBindingFromASTName("S _s12;", 1);
514
 
                assertQNEquals("n1::n2::S", b12);
515
 
        }
516
 
 
517
 
        // // header content
518
 
        // namespace n1 { namespace n2 { union U {}; } }
519
 
        // class c1 { public: class c2 { public: union U {}; }; }; 
520
 
        // struct s1 { struct s2 { union U {}; }; };
521
 
        // union u1 { struct u2 { union U {}; }; };
522
 
        // namespace n3 { class c3 { public: struct s3 { union u3 { union U {}; }; }; }; }
523
 
 
524
 
        // // reference content
525
 
        // void reference() {
526
 
        //  ::n1::n2::U _u0; n1::n2::U _u1;
527
 
        //  ::c1::c2::U _u2; c1::c2::U _u3;
528
 
        //  ::s1::s2::U _u4; s1::s2::U _u5;
529
 
        //  ::u1::u2::U _u6; u1::u2::U _u7;
530
 
        //  ::n3::c3::s3::u3::U _u8;
531
 
        //    n3::c3::s3::u3::U _u9;
532
 
        // }
533
 
        // namespace n3 { c3::s3::u3::U _u10; }
534
 
        // namespace n1 { n2::U _u11; }
535
 
        // namespace n1 { namespace n2 { U _u12; }} 
536
 
        public void testQualifiedNamesForUnion() throws DOMException {
537
 
                IBinding b0 = getBindingFromASTName("U _u0;", 1);
538
 
                assertQNEquals("n1::n2::U", b0);
539
 
                IBinding b1 = getBindingFromASTName("U _u1;", 1);
540
 
                assertQNEquals("n1::n2::U", b1);
541
 
                IBinding b2 = getBindingFromASTName("U _u2;", 1);
542
 
                assertQNEquals("c1::c2::U", b2);
543
 
                IBinding b3 = getBindingFromASTName("U _u3;", 1);
544
 
                assertQNEquals("c1::c2::U", b3);
545
 
                IBinding b4 = getBindingFromASTName("U _u4;", 1);
546
 
                assertQNEquals("s1::s2::U", b4);
547
 
                IBinding b5 = getBindingFromASTName("U _u5;", 1);
548
 
                assertQNEquals("s1::s2::U", b5);
549
 
                IBinding b6 = getBindingFromASTName("U _u6;", 1);
550
 
                assertQNEquals("u1::u2::U", b6);
551
 
                IBinding b7 = getBindingFromASTName("U _u7;", 1);
552
 
                assertQNEquals("u1::u2::U", b7);
553
 
                IBinding b8 = getBindingFromASTName("U _u8;", 1);
554
 
                assertQNEquals("n3::c3::s3::u3::U", b8);
555
 
                IBinding b9 = getBindingFromASTName("U _u9;", 1);
556
 
                assertQNEquals("n3::c3::s3::u3::U", b9);
557
 
                IBinding b10 = getBindingFromASTName("U _u10;", 1);
558
 
                assertQNEquals("n3::c3::s3::u3::U", b10);
559
 
                IBinding b11 = getBindingFromASTName("U _u11;", 1);
560
 
                assertQNEquals("n1::n2::U", b11);
561
 
                IBinding b12 = getBindingFromASTName("U _u12;", 1);
562
 
                assertQNEquals("n1::n2::U", b12);
563
 
        }
564
 
 
565
 
        // // header content
566
 
        // namespace n1 { namespace n2 { class C {}; } }
567
 
        // class c1 { public: class c2 { public: class C {}; }; };
568
 
        // struct s1 { struct s2 { class C {}; }; };
569
 
        // union u1 { union u2 { class C {}; }; };
570
 
        // namespace n3 { class c3 { public: struct s3 { union u3 { class C {}; }; }; }; }
571
 
 
572
 
        // // reference content
573
 
        // void reference() {
574
 
        //  ::n1::n2::C _c0; n1::n2::C _c1;
575
 
        //  ::c1::c2::C _c2; c1::c2::C _c3;
576
 
        //  ::s1::s2::C _c4; s1::s2::C _c5;
577
 
        //  ::u1::u2::C _c6; u1::u2::C _c7;
578
 
        //  ::n3::c3::s3::u3::C _c8;
579
 
        //    n3::c3::s3::u3::C _c9;
580
 
        // }
581
 
        // namespace n3 { c3::s3::u3::C _c10; }
582
 
        // namespace n1 { n2::C _c11; }
583
 
        // namespace n1 { namespace n2 { C _c12; }} 
584
 
        public void testQualifiedNamesForClass() throws DOMException {
585
 
                IBinding b0 = getBindingFromASTName("C _c0;", 1);
586
 
                assertQNEquals("n1::n2::C", b0);
587
 
                IBinding b1 = getBindingFromASTName("C _c1;", 1);
588
 
                assertQNEquals("n1::n2::C", b1);
589
 
                IBinding b2 = getBindingFromASTName("C _c2;", 1);
590
 
                assertQNEquals("c1::c2::C", b2);
591
 
                IBinding b3 = getBindingFromASTName("C _c3;", 1);
592
 
                assertQNEquals("c1::c2::C", b3);
593
 
                IBinding b4 = getBindingFromASTName("C _c4;", 1);
594
 
                assertQNEquals("s1::s2::C", b4);
595
 
                IBinding b5 = getBindingFromASTName("C _c5;", 1);
596
 
                assertQNEquals("s1::s2::C", b5);
597
 
                IBinding b6 = getBindingFromASTName("C _c6;", 1);
598
 
                assertQNEquals("u1::u2::C", b6);
599
 
                IBinding b7 = getBindingFromASTName("C _c7;", 1);
600
 
                assertQNEquals("u1::u2::C", b7);
601
 
                IBinding b8 = getBindingFromASTName("C _c8;", 1);
602
 
                assertQNEquals("n3::c3::s3::u3::C", b8);
603
 
                IBinding b9 = getBindingFromASTName("C _c9;", 1);
604
 
                assertQNEquals("n3::c3::s3::u3::C", b9);
605
 
                IBinding b10 = getBindingFromASTName("C _c10;", 1);
606
 
                assertQNEquals("n3::c3::s3::u3::C", b10);
607
 
                IBinding b11 = getBindingFromASTName("C _c11;", 1);
608
 
                assertQNEquals("n1::n2::C", b11);
609
 
                IBinding b12 = getBindingFromASTName("C _c12;", 1);
610
 
                assertQNEquals("n1::n2::C", b12);
611
 
        }
612
 
 
613
 
        // // header content
614
 
        // namespace n1 { namespace n2 { typedef int Int; } }
615
 
        // class c1 { public: class c2 { public: typedef int Int; }; };
616
 
        // struct s1 { struct s2 { typedef int Int; }; };
617
 
        // union u1 { struct u2 { typedef int Int; }; };
618
 
        // namespace n3 { class c3 { public: struct s3 { union u3 { typedef int Int; }; }; }; }
619
 
 
620
 
        // // reference content
621
 
        // void reference() {
622
 
        //  ::n1::n2::Int i0; n1::n2::Int i1;
623
 
        //  ::c1::c2::Int i2; c1::c2::Int i3;
624
 
        //  ::s1::s2::Int i4; s1::s2::Int i5;
625
 
        //  ::u1::u2::Int i6; u1::u2::Int i7;
626
 
        //  ::n3::c3::s3::u3::Int i8;
627
 
        //    n3::c3::s3::u3::Int i9;
628
 
        // }
629
 
        // namespace n3 { c3::s3::u3::Int i10; }
630
 
        // namespace n1 { n2::Int i11; }
631
 
        // namespace n1 { namespace n2 { Int i12; }} 
632
 
        public void testQualifiedNamesForTypedef() throws DOMException {
633
 
                IBinding b0 = getBindingFromASTName("Int i0;", 3);
634
 
                assertQNEquals("n1::n2::Int", b0);
635
 
                IBinding b1= getBindingFromASTName("Int i1;", 3);
636
 
                assertQNEquals("n1::n2::Int", b1);
637
 
 
638
 
                IBinding b2 = getBindingFromASTName("Int i2;", 3);
639
 
                assertQNEquals("c1::c2::Int", b2);
640
 
                IBinding b3 = getBindingFromASTName("Int i3;", 3);
641
 
                assertQNEquals("c1::c2::Int", b3);
642
 
 
643
 
                IBinding b4 = getBindingFromASTName("Int i4;", 3);
644
 
                assertQNEquals("s1::s2::Int", b4);
645
 
                IBinding b5 = getBindingFromASTName("Int i5;", 3);
646
 
                assertQNEquals("s1::s2::Int", b5);
647
 
 
648
 
                IBinding b6 = getBindingFromASTName("Int i6;", 3);
649
 
                assertQNEquals("u1::u2::Int", b6);
650
 
                IBinding b7 = getBindingFromASTName("Int i7;", 3);
651
 
                assertQNEquals("u1::u2::Int", b7);
652
 
 
653
 
                IBinding b8 = getBindingFromASTName("Int i8;", 3);
654
 
                assertQNEquals("n3::c3::s3::u3::Int", b8);
655
 
                IBinding b9 = getBindingFromASTName("Int i9;", 3);
656
 
                assertQNEquals("n3::c3::s3::u3::Int", b9);
657
 
                IBinding b10 = getBindingFromASTName("Int i10;", 3);
658
 
                assertQNEquals("n3::c3::s3::u3::Int", b10);
659
 
                IBinding b11 = getBindingFromASTName("Int i11;", 3);
660
 
                assertQNEquals("n1::n2::Int", b11);
661
 
                IBinding b12 = getBindingFromASTName("Int i12;", 3);
662
 
                assertQNEquals("n1::n2::Int", b12);
663
 
        }
664
 
 
665
 
        // // header content
666
 
        // enum E { ER1, ER2 };
667
 
 
668
 
        // // referencing content
669
 
        // class C {
670
 
        //       E e1;
671
 
        //       static E e2;
672
 
        //       void m1() { e1 = ER1; }
673
 
        //       static void m2() { e2 = ER2; }
674
 
        // };
675
 
        public void testEnumeratorInClassScope() {
676
 
                IBinding b0 = getBindingFromASTName("E e1", 1);
677
 
                IBinding b1 = getBindingFromASTName("ER1; }", 3);
678
 
                IBinding b2 = getBindingFromASTName("ER2; }", 3);
679
 
        }
680
 
 
681
 
        // // header content
682
 
        // enum E { ER1, ER2 };
683
 
 
684
 
        // // referencing content
685
 
        // struct S {
686
 
        //       E e1;
687
 
        //       static E e2;
688
 
        //       void m1() { e1 = ER1; }
689
 
        //       static void m2() { e2 = ER2; }
690
 
        // };
691
 
        public void testEnumeratorInStructScope() {
692
 
                IBinding b0 = getBindingFromASTName("E e1", 1);
693
 
                IBinding b1 = getBindingFromASTName("ER1; }", 3);
694
 
                IBinding b2 = getBindingFromASTName("ER2; }", 3);
695
 
        }
696
 
 
697
 
        //       // header content
698
 
        // enum E { ER1, ER2 };
699
 
 
700
 
        // // referencing content
701
 
        // union U {
702
 
        //       E e1;
703
 
        //       static E e2;
704
 
        //       void m1() { e1 = ER1; }
705
 
        //       static void m2() { e2 = ER2; }
706
 
        // };
707
 
        public void testEnumeratorInUnionScope() {
708
 
                IBinding b0 = getBindingFromASTName("E e1", 1);
709
 
                IBinding b1 = getBindingFromASTName("ER1; }", 3);
710
 
                IBinding b2 = getBindingFromASTName("ER2; }", 3);
711
 
        }
712
 
 
713
 
        //       // header content
714
 
        // enum E { ER1, ER2 };
715
 
 
716
 
        // // referencing content
717
 
        // namespace n1 {
718
 
        //       E e1;
719
 
        //       static E e2;
720
 
        //       void f1() { e1 = ER1; }
721
 
        //       static void f2() { e2 = ER2; }
722
 
        // };
723
 
        public void testEnumeratorInNamespaceScope() {
724
 
                IBinding b0 = getBindingFromASTName("E e1", 1);
725
 
                IBinding b1 = getBindingFromASTName("ER1; }", 3);
726
 
                IBinding b2 = getBindingFromASTName("ER2; }", 3);
727
 
        }
728
 
 
729
 
        // // the header
730
 
        // void foo(int a=2, int b=3);
731
 
 
732
 
        // #include "header.h"
733
 
        // void ref() { foo(); }
734
 
        public void testFunctionDefaultArguments() {
735
 
                IBinding b0 = getBindingFromASTName("foo();", 3);
736
 
        }
737
 
 
738
 
        // // the header
739
 
        // typedef int TYPE;
740
 
        // namespace ns {
741
 
        //    const TYPE* foo(int a);
742
 
        // };
743
 
 
744
 
        // #include "header.h"
745
 
        // const TYPE* ns::foo(int a) { return 0; }
746
 
        public void testTypeQualifier() {
747
 
                IBinding b0 = getBindingFromASTName("foo(", 3);
748
 
        }
749
 
 
750
 
        // // header
751
 
        //      class Base { public: void foo(int i) {} };
752
 
        //      class Derived : public Base { public: void foo(long l) {} };
753
 
 
754
 
        // // references
755
 
        // #include "header.h"
756
 
        // void references() {
757
 
        //    Derived d; /*d*/
758
 
        //    d.foo(55L); // calls long version
759
 
        //    d.foo(4); // also calls long version (int version is hidden)
760
 
        //    // aftodo - does this test make sense?
761
 
        // }
762
 
        public void testMethodHidingInInheritance() {
763
 
                IBinding b0 = getBindingFromASTName("d; /*d*/", 1);
764
 
                IBinding b1 = getBindingFromASTName("foo(55L);", 3);
765
 
                IBinding b2 = getBindingFromASTName("foo(4);", 3);
766
 
        }
767
 
 
768
 
        // // header content
769
 
        // namespace x { namespace y { int i; } }
770
 
 
771
 
        // // the references
772
 
        // #include "header.h"
773
 
        // class C { public:
774
 
        //    class x { public:
775
 
        //       class y { public:
776
 
        //          static int j;
777
 
        //       };
778
 
        //    }; 
779
 
        //    void method() {
780
 
        //       ::x::y::i++;
781
 
        //       x::y::j++;
782
 
        //    }
783
 
        // };
784
 
        public void testGQualifiedReference() {
785
 
                IBinding b0 = getBindingFromASTName("x::y::i++", 1);
786
 
                assertTrue(ICPPNamespace.class.isInstance(b0));
787
 
                IBinding b1 = getBindingFromASTName("y::i++", 1);
788
 
                assertTrue(ICPPNamespace.class.isInstance(b1));
789
 
                IBinding b2 = getBindingFromASTName("i++", 1);
790
 
                assertTrue(ICPPVariable.class.isInstance(b2));
791
 
                IBinding b3 = getBindingFromASTName("x::y::j++", 1);
792
 
                assertTrue(ICPPClassType.class.isInstance(b3));
793
 
                IBinding b4 = getBindingFromASTName("y::j++", 1);
794
 
                assertTrue(ICPPClassType.class.isInstance(b4));
795
 
                IBinding b5 = getBindingFromASTName("j++", 1);
796
 
                assertTrue(ICPPVariable.class.isInstance(b5));
797
 
        }
798
 
 
799
 
 
800
 
        ////header content
801
 
        //struct S {int i;};
802
 
        //struct SS { S s, *sp; };
803
 
        //
804
 
        //S* retsptr() {return 0;}
805
 
        //S rets() { return *new S(); }
806
 
        //S s, *sp;
807
 
        //SS ss, *ssp;
808
 
        //S *a[3];
809
 
 
810
 
        ////reference content
811
 
        //void references() {
812
 
        //      a[0]->i/*0*/++; (*a[0]).i/*1*/++;                    // IASTArraySubscriptExpression
813
 
        //      /* not applicable ?? */                              // IASTBinaryExpression
814
 
        //      ((S*)sp)->i/*3*/++; ((S)s).i/*4*/++; //aftodo-valid? // IASTCastExpression
815
 
        //      (true ? sp : sp)->i/*5*/++; (true ? s : s).i/*6*/++; // IASTConditionalExpression
816
 
        //      (sp,sp)->i/*7*/++; (s,s).i/*8*/++;                   // IASTExpressionList
817
 
        //      ss.sp->i/*9*/++; ss.s.i/*10*/++;                     // IASTFieldReference
818
 
        //      ssp->sp->i/*11*/++; ssp->s.i/*12*/++;                // IASTFieldReference
819
 
        //      retsptr()->i/*13*/++; rets().i/*14*/++;              // IASTFunctionCallExpression     
820
 
        //      sp->i/*15*/++; s.i/*16*/++;                          // IASTIdExpression
821
 
        //      /* not applicable */                                 // IASTLiteralExpression
822
 
        //      /* not applicable */                                 // IASTTypeIdExpression
823
 
        //      (*sp).i/*17*/++;                                     // IASTUnaryExpression
824
 
        //      /* not applicable */                                 // ICPPASTDeleteExpression
825
 
        //      (new S())->i/*18*/++;                                // ICPPASTNewExpression
826
 
        //}
827
 
        public void testFieldReference() {
828
 
                IBinding b0 = getBindingFromASTName("i/*0*/", 1);
829
 
                IBinding b1 = getBindingFromASTName("i/*1*/", 1);
830
 
                // IBinding b2 = getBindingFromASTName(ast, "i/*2*/", 1);
831
 
                IBinding b3 = getBindingFromASTName("i/*3*/", 1);
832
 
                IBinding b4 = getBindingFromASTName("i/*4*/", 1);
833
 
                IBinding b5 = getBindingFromASTName("i/*5*/", 1);
834
 
                IBinding b6 = getBindingFromASTName("i/*6*/", 1);
835
 
                IBinding b7 = getBindingFromASTName("i/*7*/", 1);
836
 
                IBinding b8 = getBindingFromASTName("i/*8*/", 1);
837
 
                IBinding b9 = getBindingFromASTName("i/*9*/", 1);
838
 
                IBinding b10 = getBindingFromASTName("i/*10*/", 1);
839
 
                IBinding b11 = getBindingFromASTName("i/*11*/", 1);
840
 
                IBinding b12 = getBindingFromASTName("i/*12*/", 1);
841
 
                IBinding b13 = getBindingFromASTName("i/*13*/", 1);
842
 
                IBinding b14 = getBindingFromASTName("i/*14*/", 1);
843
 
                IBinding b15 = getBindingFromASTName("i/*15*/", 1);
844
 
                IBinding b16 = getBindingFromASTName("i/*16*/", 1);
845
 
                IBinding b17 = getBindingFromASTName("i/*17*/", 1);
846
 
                IBinding b18 = getBindingFromASTName("i/*18*/", 1);
847
 
        }
848
 
 
849
 
 
850
 
        // // header file
851
 
        //      class C {public: C* cp;};
852
 
        //      C foo(C c);
853
 
        //      C* foo(C* c);
854
 
        //      int foo(int i);
855
 
        //      int foo(int i, C c);
856
 
 
857
 
        // // referencing content
858
 
        // #include "header.h"
859
 
        //      void references() {
860
 
        //              C c, *cp;
861
 
        //              foo/*a*/(cp[1]);                        // IASTArraySubscriptExpression
862
 
        //              foo/*b*/(cp+1);                         // IASTBinaryExpression
863
 
        //              foo/*c*/((C*) cp);/*1*/                 // IASTCastExpression
864
 
        //              foo/*d*/(true ? c : c);/*2*/            // IASTConditionalExpression
865
 
        //              foo/*e*/(5, c);/*3*/                    // IASTExpressionList
866
 
        //              foo/*f*/(c.cp);/*4*/ foo(cp->cp);/*5*/  // IASTFieldReference
867
 
        //              foo/*g*/(foo(c));/*6*/ foo(foo(1));/*7*/// IASTFunctionCallExpression
868
 
        //              foo/*h*/(c);/*8*/                       // IASTIdExpression
869
 
        //              foo/*i*/(23489);                        // IASTLiteralExpression
870
 
        //              foo/*j*/(sizeof(C));/*9*/               // IASTTypeIdExpression
871
 
        //              foo/*k*/(*cp);/*10*/                    // IASTUnaryExpression
872
 
        //              foo/*l*/(delete cp);/*11*/              // ICPPASTDeleteExpression
873
 
        //              foo/*m*/(new C());/*12*/                // ICPPASTNewExpression
874
 
        //              // ?? foo/*n*/();                       // ICPPASTSimpleTypeConstructorExpression
875
 
        //              // ?? foo/*o*/();                       // ICPPASTTypenameExprssion
876
 
        //              // foo/*p*/(MADE_UP_SYMBOL);            // ICPPASTTypenameExprssion
877
 
        //      }
878
 
        public void testExpressionKindForFunctionCalls() {
879
 
                // depends on bug 164470 because resolution takes place during parse.
880
 
                IBinding b0 = getBindingFromASTName("foo/*a*/", 3);
881
 
                IBinding b0a = getBindingFromASTName("cp[1]", 2);
882
 
                // assertCompositeTypeParam(0, ICPPClassType.k_class, b0, "C");
883
 
 
884
 
                IBinding b1 = getBindingFromASTName("foo/*b*/", 3);
885
 
                IBinding b1a = getBindingFromASTName("cp+1", 2);
886
 
 
887
 
                IBinding b2 = getBindingFromASTName("foo/*c*/", 3);
888
 
                IBinding b2a = getBindingFromASTName("cp);/*1*/", 2);
889
 
 
890
 
                IBinding b3 = getBindingFromASTName("foo/*d*/", 3);
891
 
                IBinding b3a = getBindingFromASTName("c : c", 1);
892
 
                IBinding b3b = getBindingFromASTName("c);/*2*/", 1);
893
 
 
894
 
                IBinding b4 = getBindingFromASTName("foo/*e*/", 3);
895
 
                IBinding b4a = getBindingFromASTName("c);/*3*/", 1);
896
 
 
897
 
                IBinding b5 = getBindingFromASTName("cp);/*4*/", 2);
898
 
                IBinding b5a = getBindingFromASTName("foo/*f*/", 3);
899
 
                IBinding b5b = getBindingFromASTName("cp->cp);/*5*/", 2);
900
 
                IBinding b5c = getBindingFromASTName("cp);/*5*/", 2);
901
 
 
902
 
                IBinding b6 = getBindingFromASTName("foo/*g*/", 3);
903
 
                IBinding b6a = getBindingFromASTName("foo(c));/*6*/", 3);
904
 
                IBinding b6b = getBindingFromASTName("c));/*6*/", 1);
905
 
                IBinding b6c = getBindingFromASTName("foo(foo(1));/*7*/", 3);
906
 
                IBinding b6d = getBindingFromASTName("foo(1));/*7*/", 3);
907
 
 
908
 
                IBinding b7 = getBindingFromASTName("foo/*h*/", 3);
909
 
                IBinding b7a = getBindingFromASTName("c);/*8*/", 1);
910
 
 
911
 
                IBinding b8 = getBindingFromASTName("foo/*i*/", 3);
912
 
 
913
 
                IBinding b9 = getBindingFromASTName("foo/*j*/", 3);
914
 
                IBinding b9a = getBindingFromASTName("C));/*9*/", 1);
915
 
 
916
 
                IBinding b10 = getBindingFromASTName("foo/*k*/", 3);
917
 
                IBinding b10a = getBindingFromASTName("cp);/*10*/", 2);
918
 
 
919
 
                IBinding b11 = getBindingFromASTName("foo/*l*/", 3);
920
 
                IBinding b11a = getBindingFromASTName("cp);/*11*/", 2);
921
 
 
922
 
                IBinding b12 = getBindingFromASTName("foo/*m*/", 3);
923
 
                IBinding b12a = getBindingFromASTName("C());/*12*/", 1);
924
 
                // IBinding b13 = getBindingFromASTName(ast, "foo/*n*/", 3);
925
 
        }
926
 
 
927
 
        // // header content
928
 
        //      class C { public:
929
 
        //      typedef int i1; typedef long *lp1;
930
 
        //      class C1 {}; struct S1 {}; union U1 {}; enum E1 {A1};
931
 
        //      };
932
 
        //      struct S { public:
933
 
        //      typedef int i2; typedef long *lp2;
934
 
        //      class C2 {}; struct S2 {}; union U2 {}; enum E2 {A2};
935
 
        //      };
936
 
        //      union U { public:
937
 
        //      typedef int i3; typedef long *lp3;
938
 
        //      class C3 {}; struct S3 {}; union U3 {}; enum E3 {A3};
939
 
        //      };
940
 
        //      enum E {A};
941
 
        //      namespace n {
942
 
        //              typedef int i4; typedef long *lp4;
943
 
        //              class C4 {}; struct S4 {}; union U4 {}; enum E4 {A4};
944
 
        //      }
945
 
        //      void f(int);
946
 
        //      void f(long);
947
 
        //      void f(C); void f(C::i1); void f(C::lp1); void f(C::S1); void f(C::U1); void f(C::E1);
948
 
        //      void f(S); void f(S::i2); void f(S::lp2); void f(S::S2); void f(S::U2); void f(S::E2);  
949
 
        //      void f(U); void f(U::i3); void f(U::lp3); void f(U::S3); void f(U::U3); void f(U::E3);
950
 
        //      void f(n::i4); void f(n::lp4); void f(n::S4); void f(n::U4); void f(n::E4);
951
 
        //      void f(E);
952
 
 
953
 
        // // reference content
954
 
        //  #include "header.h"
955
 
        //      void references() {
956
 
        //              void (*fintptr)(int), (*flongptr)(long);
957
 
        //              void (*fC)(C), (*fCi1)(C::i1), (*fClp1)(C::lp1), (*fCS1)(C::S1), (*fCU1)(C::U1), (*fCE1)(C::E1);
958
 
        //              void (*fS)(S), (*fSi2)(S::i2), (*fSlp2)(S::lp2), (*fSS2)(S::S2), (*fSU2)(S::U2), (*fSE2)(S::E2);
959
 
        //              void (*fU)(U), (*fUi3)(U::i3), (*fUlp3)(U::lp3), (*fUS3)(U::S3), (*fUU3)(U::U3), (*fUE3)(U::E3);
960
 
        //              void           (*fni4)(n::i4), (*fnlp4)(n::lp4), (*fnS4)(n::S4), (*fnU4)(n::U4), (*fnE4)(n::E4);
961
 
        //              void (*fE)(E);
962
 
        //              fintptr = &f;/*0*/ flongptr = &f;/*1*/
963
 
        //              fC = &f;/*2*/ fCi1 = &f;/*3*/ fClp1 = &f;/*4*/ fCS1 = &f;/*5*/ fCU1 = &f;/*6*/ fCE1 = &f;/*7*/
964
 
        //              fS = &f;/*8*/ fSi2 = &f;/*9*/ fSlp2 = &f;/*10*/ fSS2 = &f;/*11*/ fSU2 = &f;/*12*/ fSE2 = &f;/*13*/
965
 
        //              fU = &f;/*14*/ fUi3 = &f;/*15*/ fUlp3 = &f;/*16*/ fUS3 = &f;/*17*/ fUU3 = &f;/*18*/ fUE3 = &f;/*19*/
966
 
        //                       fni4 = &f;/*20*/ fnlp4 = &f;/*21*/ fnS4 = &f;/*22*/ fnU4 = &f;/*23*/ fnE4 = &f;/*24*/
967
 
        //              fE = &f;/*25*/
968
 
        //      }       
969
 
        public void testAddressOfOverloadedFunction() throws DOMException {
970
 
                IBinding b0 = getBindingFromASTName("f;/*0*/", 1);
971
 
                IBinding b1 = getBindingFromASTName("f;/*1*/", 1);
972
 
                IBinding b2 = getBindingFromASTName("f;/*2*/", 1);
973
 
                IBinding b3 = getBindingFromASTName("f;/*3*/", 1);
974
 
                IBinding b4 = getBindingFromASTName("f;/*4*/", 1);
975
 
                IBinding b5 = getBindingFromASTName("f;/*5*/", 1);
976
 
                IBinding b6 = getBindingFromASTName("f;/*6*/", 1);
977
 
                IBinding b7 = getBindingFromASTName("f;/*7*/", 1);
978
 
                IBinding b8 = getBindingFromASTName("f;/*8*/", 1);
979
 
                IBinding b9 = getBindingFromASTName("f;/*9*/", 1);
980
 
                IBinding b10= getBindingFromASTName("f;/*10*/", 1);
981
 
                IBinding b11 = getBindingFromASTName("f;/*11*/", 1);
982
 
                IBinding b12 = getBindingFromASTName("f;/*12*/", 1);
983
 
                IBinding b13 = getBindingFromASTName("f;/*13*/", 1);
984
 
                IBinding b14 = getBindingFromASTName("f;/*14*/", 1);
985
 
                IBinding b15 = getBindingFromASTName("f;/*15*/", 1);
986
 
                IBinding b16 = getBindingFromASTName("f;/*16*/", 1);
987
 
                IBinding b17 = getBindingFromASTName("f;/*17*/", 1);
988
 
                IBinding b18 = getBindingFromASTName("f;/*18*/", 1);
989
 
                IBinding b19 = getBindingFromASTName("f;/*19*/", 1);
990
 
                IBinding b20 = getBindingFromASTName("f;/*20*/", 1);
991
 
                IBinding b21 = getBindingFromASTName("f;/*21*/", 1);
992
 
                IBinding b22 = getBindingFromASTName("f;/*22*/", 1);
993
 
                IBinding b23 = getBindingFromASTName("f;/*23*/", 1);
994
 
                IBinding b24 = getBindingFromASTName("f;/*24*/", 1);
995
 
        }
996
 
 
997
 
        // struct C {
998
 
        //       int m1(int a);
999
 
        //       int m2(int a) const;
1000
 
        // }; 
1001
 
        //
1002
 
        // C* func(int (C::*m)(int) const);
1003
 
        // C* func(int (C::*m)(int));
1004
 
 
1005
 
        // void ref() {
1006
 
        //       func(&C::m1);
1007
 
        //       func(&C::m2);
1008
 
        // }
1009
 
    public void testAddressOfConstMethod_233889() throws Exception {
1010
 
                IBinding fn1= getBindingFromASTName("func(&C::m1", 4, ICPPFunction.class);
1011
 
                IBinding fn2= getBindingFromASTName("func(&C::m2", 4, ICPPFunction.class);
1012
 
                assertNotSame(fn1, fn2);
1013
 
    }
1014
 
 
1015
 
        // // the header
1016
 
        // void f_int(int);
1017
 
        // void f_const_int(const int);
1018
 
        // void f_int_ptr(int*);
1019
 
 
1020
 
        // #include "header.h"
1021
 
        // void ref() { 
1022
 
        //       int                    i                               = 0;
1023
 
        //   const int          const_int               = 0;
1024
 
        //
1025
 
        //   f_int(i);                           // ok
1026
 
        //   f_int(const_int);       // ok (passed as value)
1027
 
        //   f_const_int(i);             // ok
1028
 
        //   f_const_int(const_int); // ok
1029
 
        // }
1030
 
        //
1031
 
        //  void f_const_int(const int const_int) {
1032
 
        //     f_int_ptr(&const_int); // error
1033
 
        //  }  
1034
 
        public void testConstIntParameter() {
1035
 
                getBindingFromASTName("f_int(i)", 5);
1036
 
                getBindingFromASTName("f_int(const_int)", 5);
1037
 
                getBindingFromASTName("f_const_int(i)", 11);
1038
 
                getBindingFromASTName("f_const_int(const_int)", 11);
1039
 
                getProblemFromASTName("f_int_ptr(&const_int)", 9);
1040
 
        }
1041
 
 
1042
 
        // // the header
1043
 
        // void f_int_ptr(int*);
1044
 
        // void f_const_int_ptr(const int*);
1045
 
        // void f_int_const_ptr(int const*);
1046
 
        // void f_int_ptr_const(int *const);
1047
 
        // void f_const_int_ptr_const(const int*const);
1048
 
        // void f_int_const_ptr_const(int const*const);
1049
 
 
1050
 
        // #include "header.h"
1051
 
        // void ref() { 
1052
 
        //       int*                   int_ptr                 = 0;
1053
 
        //   const int*         const_int_ptr   = 0;
1054
 
        //       int const*     int_const_ptr   = 0;
1055
 
        //       int *const     int_ptr_const   = 0;
1056
 
        //   const int*const            const_int_ptr_const   = 0;
1057
 
        //   int const*const            int_const_ptr_const   = 0;
1058
 
        //
1059
 
        //   f_int_ptr(int_ptr);                                // ok
1060
 
        //   f_int_ptr(const_int_ptr);                  // error
1061
 
        //   f_int_ptr(int_const_ptr);                  // error
1062
 
        //   f_int_ptr(int_ptr_const);                  // ok
1063
 
        //   f_int_ptr(const_int_ptr_const);    // error
1064
 
        //   f_int_ptr(int_const_ptr_const);    // error
1065
 
        //
1066
 
        //   f_const_int_ptr(int_ptr);                          // ok
1067
 
        //   f_const_int_ptr(const_int_ptr);            // ok
1068
 
        //   f_const_int_ptr(int_const_ptr);            // ok
1069
 
        //   f_const_int_ptr(int_ptr_const);            // ok
1070
 
        //   f_const_int_ptr(const_int_ptr_const);      // ok
1071
 
        //   f_const_int_ptr(int_const_ptr_const);      // ok
1072
 
        //
1073
 
        //   f_int_const_ptr(int_ptr);                          // ok
1074
 
        //   f_int_const_ptr(const_int_ptr);            // ok
1075
 
        //   f_int_const_ptr(int_const_ptr);            // ok
1076
 
        //   f_int_const_ptr(int_ptr_const);            // ok
1077
 
        //   f_int_const_ptr(const_int_ptr_const);      // ok
1078
 
        //   f_int_const_ptr(int_const_ptr_const);      // ok
1079
 
        //
1080
 
        //   f_int_ptr_const(int_ptr);                          // ok
1081
 
        //   f_int_ptr_const(const_int_ptr);            // error
1082
 
        //   f_int_ptr_const(int_const_ptr);            // error
1083
 
        //   f_int_ptr_const(int_ptr_const);            // ok
1084
 
        //   f_int_ptr_const(const_int_ptr_const);      // error
1085
 
        //   f_int_ptr_const(int_const_ptr_const);      // error
1086
 
        //
1087
 
        //   f_const_int_ptr_const(int_ptr);                     // ok
1088
 
        //   f_const_int_ptr_const(const_int_ptr);               // ok
1089
 
        //   f_const_int_ptr_const(int_const_ptr);               // ok
1090
 
        //   f_const_int_ptr_const(int_ptr_const);               // ok
1091
 
        //   f_const_int_ptr_const(const_int_ptr_const); // ok
1092
 
        //   f_const_int_ptr_const(int_const_ptr_const); // ok
1093
 
        //
1094
 
        //   f_int_const_ptr_const(int_ptr);                            // ok
1095
 
        //   f_int_const_ptr_const(const_int_ptr);                      // ok
1096
 
        //   f_int_const_ptr_const(int_const_ptr);                      // ok
1097
 
        //   f_int_const_ptr_const(int_ptr_const);                      // ok
1098
 
        //   f_int_const_ptr_const(const_int_ptr_const);        // ok
1099
 
        //   f_int_const_ptr_const(int_const_ptr_const);        // ok
1100
 
        // }
1101
 
        public void testConstIntPtrParameter() {
1102
 
                getBindingFromASTName("f_int_ptr(int_ptr)",                     9);
1103
 
                getProblemFromASTName("f_int_ptr(const_int_ptr)",               9);
1104
 
                getProblemFromASTName("f_int_ptr(int_const_ptr)",               9);
1105
 
                getBindingFromASTName("f_int_ptr(int_ptr_const)",               9);
1106
 
                getProblemFromASTName("f_int_ptr(const_int_ptr_const)", 9);
1107
 
                getProblemFromASTName("f_int_ptr(int_const_ptr_const)", 9);
1108
 
 
1109
 
                getBindingFromASTName("f_const_int_ptr(int_ptr)",                               15);
1110
 
                getBindingFromASTName("f_const_int_ptr(const_int_ptr)",                 15);
1111
 
                getBindingFromASTName("f_const_int_ptr(int_const_ptr)",                 15);
1112
 
                getBindingFromASTName("f_const_int_ptr(int_ptr_const)",                 15);
1113
 
                getBindingFromASTName("f_const_int_ptr(const_int_ptr_const)",   15);
1114
 
                getBindingFromASTName("f_const_int_ptr(int_const_ptr_const)",   15);
1115
 
 
1116
 
                getBindingFromASTName("f_int_const_ptr(int_ptr)",                               15);
1117
 
                getBindingFromASTName("f_int_const_ptr(const_int_ptr)",                 15);
1118
 
                getBindingFromASTName("f_int_const_ptr(int_const_ptr)",                 15);
1119
 
                getBindingFromASTName("f_int_const_ptr(int_ptr_const)",                 15);
1120
 
                getBindingFromASTName("f_int_const_ptr(const_int_ptr_const)",   15);
1121
 
                getBindingFromASTName("f_int_const_ptr(int_const_ptr_const)",   15);
1122
 
 
1123
 
                getBindingFromASTName("f_int_ptr_const(int_ptr)",                               15);
1124
 
                getProblemFromASTName("f_int_ptr_const(const_int_ptr)",                 15);
1125
 
                getProblemFromASTName("f_int_ptr_const(int_const_ptr)",                 15);
1126
 
                getBindingFromASTName("f_int_ptr_const(int_ptr_const)",                 15);
1127
 
                getProblemFromASTName("f_int_ptr_const(const_int_ptr_const)",   15);
1128
 
                getProblemFromASTName("f_int_ptr_const(int_const_ptr_const)",   15);
1129
 
 
1130
 
                getBindingFromASTName("f_const_int_ptr_const(int_ptr)",                         21);
1131
 
                getBindingFromASTName("f_const_int_ptr_const(const_int_ptr)",           21);
1132
 
                getBindingFromASTName("f_const_int_ptr_const(int_const_ptr)",           21);
1133
 
                getBindingFromASTName("f_const_int_ptr_const(int_ptr_const)",           21);
1134
 
                getBindingFromASTName("f_const_int_ptr_const(const_int_ptr_const)",     21);
1135
 
                getBindingFromASTName("f_const_int_ptr_const(int_const_ptr_const)", 21);
1136
 
 
1137
 
                getBindingFromASTName("f_int_const_ptr_const(int_ptr)",                         21);
1138
 
                getBindingFromASTName("f_int_const_ptr_const(const_int_ptr)",           21);
1139
 
                getBindingFromASTName("f_int_const_ptr_const(int_const_ptr)",           21);
1140
 
                getBindingFromASTName("f_int_const_ptr_const(int_ptr_const)",           21);
1141
 
                getBindingFromASTName("f_int_const_ptr_const(const_int_ptr_const)",     21);
1142
 
                getBindingFromASTName("f_int_const_ptr_const(int_const_ptr_const)", 21);
1143
 
        }
1144
 
 
1145
 
        // // the header
1146
 
 
1147
 
        // void f(int*){}               // b1
1148
 
        // void f(const int*){} // b2
1149
 
        // void f(int const*){} // b2, redef
1150
 
        // void f(int *const){} // b1, redef
1151
 
        // void f(const int*const){} // b2, redef
1152
 
        // void f(int const*const){} // b2, redef
1153
 
        public void testConstIntPtrParameterInDefinitionAST() throws CoreException {
1154
 
                IBinding binding1= getBindingFromASTName("f(int*){}", 1);
1155
 
                IBinding binding2= getBindingFromASTName("f(const int*){}", 1);
1156
 
                getProblemFromASTName("f(int const*){}", 1);
1157
 
                getProblemFromASTName("f(int *const){}", 1);
1158
 
                getProblemFromASTName("f(const int*const){}", 1);
1159
 
                getProblemFromASTName("f(int const*const){}", 1);
1160
 
        }
1161
 
 
1162
 
        // // the header
1163
 
 
1164
 
        // void f(int&){}               // b1
1165
 
        // void f(const int&){} // b2
1166
 
        // void f(int const&){} // b2, redef
1167
 
        public void testConstIntRefParameterInDefinitionAST() throws CoreException {
1168
 
                IBinding binding1= getBindingFromASTName("f(int&){}", 1);
1169
 
                IBinding binding2= getBindingFromASTName("f(const int&){}", 1);
1170
 
                getProblemFromASTName("f(int const&){}", 1);
1171
 
        }
1172
 
 
1173
 
        // // the header
1174
 
 
1175
 
        // void f(int*);                // b1
1176
 
        // void f(const int*);  // b2
1177
 
        // void f(int const*);  // b2
1178
 
        // void f(int *const);  // b1
1179
 
        // void f(const int*const);     // b2
1180
 
        // void f(int const*const); // b2
1181
 
        //
1182
 
        // void f(int*){}               // b1
1183
 
        // void f(const int*){} // b2
1184
 
        //
1185
 
        // void ref() {
1186
 
        //       int*                   int_ptr                 = 0;
1187
 
        //   const int*         const_int_ptr   = 0;
1188
 
        //       int const*     int_const_ptr   = 0;
1189
 
        //       int *const     int_ptr_const   = 0;
1190
 
        //   const int*const            const_int_ptr_const   = 0;
1191
 
        //   int const*const            int_const_ptr_const   = 0;
1192
 
        //
1193
 
        //   f(int_ptr);                                // b1
1194
 
        //   f(const_int_ptr);                  // b2
1195
 
        //   f(int_const_ptr);                  // b2
1196
 
        //   f(int_ptr_const);                  // b1
1197
 
        //   f(const_int_ptr_const);    // b2
1198
 
        //   f(int_const_ptr_const);    // b2
1199
 
        // }
1200
 
        public void testConstIntPtrParameterInDefinitionAST2() throws CoreException {
1201
 
                IBinding binding1= getBindingFromASTName("f(int*){}", 1);
1202
 
                IBinding binding2= getBindingFromASTName("f(const int*){}", 1);
1203
 
 
1204
 
                assertEquals(binding1, getBindingFromASTName("f(int_ptr)", 1));
1205
 
                assertEquals(binding2, getBindingFromASTName("f(const_int_ptr)", 1));
1206
 
                assertEquals(binding2, getBindingFromASTName("f(int_const_ptr)", 1));
1207
 
                assertEquals(binding1, getBindingFromASTName("f(int_ptr_const)", 1));
1208
 
                assertEquals(binding2, getBindingFromASTName("f(const_int_ptr_const)", 1));
1209
 
                assertEquals(binding2, getBindingFromASTName("f(int_const_ptr_const)", 1));
1210
 
        }
1211
 
 
1212
 
        // // the header
1213
 
        // void f(int*);                // b1
1214
 
        // void f(const int*);  // b2
1215
 
        // void f(int const*);  // b2
1216
 
        // void f(int *const);  // b1
1217
 
        // void f(const int*const);     // b2
1218
 
        // void f(int const*const); // b2
1219
 
 
1220
 
        // #include "header.h"
1221
 
        // void f(int*){}               // b1
1222
 
        // void f(const int*){} // b2
1223
 
        //
1224
 
        // void ref() {
1225
 
        //       int*                   int_ptr                 = 0;
1226
 
        //   const int*         const_int_ptr   = 0;
1227
 
        //       int const*     int_const_ptr   = 0;
1228
 
        //       int *const     int_ptr_const   = 0;
1229
 
        //   const int*const            const_int_ptr_const   = 0;
1230
 
        //   int const*const            int_const_ptr_const   = 0;
1231
 
        //
1232
 
        //   f(int_ptr);                                // b1
1233
 
        //   f(const_int_ptr);                  // b2
1234
 
        //   f(int_const_ptr);                  // b2
1235
 
        //   f(int_ptr_const);                  // b1
1236
 
        //   f(const_int_ptr_const);    // b2
1237
 
        //   f(int_const_ptr_const);    // b2
1238
 
        // }
1239
 
        public void testConstIntPtrParameterInDefinition() throws CoreException {
1240
 
                IBinding binding1= getBindingFromASTName("f(int*){}", 1);
1241
 
                IBinding binding2= getBindingFromASTName("f(const int*){}", 1);
1242
 
 
1243
 
                assertEquals(binding1, getBindingFromASTName("f(int_ptr)", 1));
1244
 
                assertEquals(binding2, getBindingFromASTName("f(const_int_ptr)", 1));
1245
 
                assertEquals(binding2, getBindingFromASTName("f(int_const_ptr)", 1));
1246
 
                assertEquals(binding1, getBindingFromASTName("f(int_ptr_const)", 1));
1247
 
                assertEquals(binding2, getBindingFromASTName("f(const_int_ptr_const)", 1));
1248
 
                assertEquals(binding2, getBindingFromASTName("f(int_const_ptr_const)", 1));
1249
 
 
1250
 
                assertEquals(2, getIndex().findNames(binding1, IIndex.FIND_DECLARATIONS).length);
1251
 
                assertEquals(4, getIndex().findNames(binding2, IIndex.FIND_DECLARATIONS).length);
1252
 
                assertEquals(1, getIndex().findNames(binding1, IIndex.FIND_DEFINITIONS).length);
1253
 
                assertEquals(1, getIndex().findNames(binding2, IIndex.FIND_DEFINITIONS).length);
1254
 
        }
1255
 
 
1256
 
        // // header file
1257
 
        // struct myStruct {
1258
 
        //    int a;
1259
 
        // };
1260
 
        // union myUnion {
1261
 
        //    int b;
1262
 
        // };
1263
 
 
1264
 
        // // referencing content
1265
 
        // struct myStruct; 
1266
 
        // union myUnion;
1267
 
        // void test() {
1268
 
        //    struct myStruct* u;
1269
 
        //    union myUnion* v;
1270
 
        //    u->a= 1;  // since we include the definition, we may use the type.
1271
 
        //    v->b= 1;  // since we include the definition, we may use the type.
1272
 
        // }
1273
 
        public void testTypeDefinitionWithFwdDeclaration() {
1274
 
                getBindingFromASTName("a= 1", 1);
1275
 
                getBindingFromASTName("b= 1", 1);
1276
 
        }
1277
 
        
1278
 
        // namespace x {
1279
 
        //    int a(int);
1280
 
        // }
1281
 
    // using namespace x;
1282
 
        // using x::a;
1283
 
        
1284
 
        // #include "header.h"
1285
 
        // void test() {
1286
 
        //    a(1);
1287
 
        // }
1288
 
    public void testLegalConflictWithUsingDeclaration() throws Exception {
1289
 
                getBindingFromASTName("a(1)", 1);
1290
 
    }
1291
 
    
1292
 
        //      class A {};
1293
 
        //      class B {};
1294
 
        //      class C {
1295
 
        //      public:
1296
 
        //              operator B() {B b; return b;}
1297
 
        //      };
1298
 
        //      class D : public C {};
1299
 
        //      void foo(B b) {}
1300
 
        
1301
 
    //  class E : public C {};
1302
 
        //      void refs() {
1303
 
        //              C c;
1304
 
        //              foo(c);
1305
 
        //              D d;
1306
 
        //              foo(d);
1307
 
        //              E e;
1308
 
        //              foo(e);
1309
 
        //      }
1310
 
    public void testUserDefinedConversionOperator_224364() throws Exception {
1311
 
        IBinding ca=   getBindingFromASTName("C c;", 1);
1312
 
        assertInstance(ca, ICPPClassType.class);
1313
 
                
1314
 
        IBinding foo1= getBindingFromASTName("foo(c)", 3);
1315
 
        
1316
 
        IBinding da=   getBindingFromASTName("D d", 1);
1317
 
        assertInstance(da, ICPPClassType.class);
1318
 
                
1319
 
                IBinding foo2= getBindingFromASTName("foo(d)", 3);
1320
 
                IBinding foo3= getBindingFromASTName("foo(e)", 3);
1321
 
    }
1322
 
 
1323
 
        // int a= 1+2-3*4+10/2; // -4
1324
 
        // int b= a+4;
1325
 
        // int* c= &b;
1326
 
        // enum X {e0, e4=4, e5, e2=2, e3};
1327
 
    
1328
 
    // void ref() {
1329
 
    // a; b; c; e0; e2; e3; e4; e5;
1330
 
    // }
1331
 
        public void testValues() throws Exception {
1332
 
                IVariable v= (IVariable) getBindingFromASTName("a;", 1);
1333
 
                checkValue(v.getInitialValue(), -4);
1334
 
                v= (IVariable) getBindingFromASTName("b;", 1);
1335
 
                checkValue(v.getInitialValue(), 0);
1336
 
                v= (IVariable) getBindingFromASTName("c;", 1);
1337
 
                assertNull(v.getInitialValue().numericalValue());
1338
 
 
1339
 
                IEnumerator e= (IEnumerator) getBindingFromASTName("e0", 2);
1340
 
                checkValue(e.getValue(), 0);
1341
 
                e= (IEnumerator) getBindingFromASTName("e2", 2);
1342
 
                checkValue(e.getValue(), 2);
1343
 
                e= (IEnumerator) getBindingFromASTName("e3", 2);
1344
 
                checkValue(e.getValue(), 3);
1345
 
                e= (IEnumerator) getBindingFromASTName("e4", 2);
1346
 
                checkValue(e.getValue(), 4);
1347
 
                e= (IEnumerator) getBindingFromASTName("e5", 2);
1348
 
                checkValue(e.getValue(), 5);
1349
 
        }
1350
 
 
1351
 
        //      namespace ns1 { namespace ns2 {
1352
 
        //        class A {};
1353
 
        //      }}
1354
 
        //      using namespace ns1::ns2;
1355
 
        
1356
 
        //      #include "header.h"
1357
 
        //      A a;
1358
 
        public void testUsingDirectiveWithQualifiedName_269727() throws Exception {
1359
 
        getBindingFromASTName("A a", 1, ICPPClassType.class);
1360
 
        }
1361
 
 
1362
 
        //      class A {
1363
 
        //        class B;
1364
 
        //        void method();
1365
 
        //      };
1366
 
 
1367
 
        //      class A::B {
1368
 
        //        B(int x);
1369
 
        //    static void m(int p);
1370
 
        //      };
1371
 
        //
1372
 
        //      void A::method() {
1373
 
        //        new B(0);
1374
 
        //    B::m(0);
1375
 
        //      }
1376
 
        public void testNestedClass_284665() throws Exception {
1377
 
        ICPPClassType b0 = getBindingFromASTName("B {", 1, ICPPClassType.class);
1378
 
        assertFalse(b0 instanceof IIndexBinding);
1379
 
        ICPPConstructor b1 = getBindingFromASTName("B(int x)", 1, ICPPConstructor.class);
1380
 
        assertFalse(b1 instanceof IIndexBinding);
1381
 
        ICPPConstructor b2 = getBindingFromASTName("B(0)", 1, ICPPConstructor.class);
1382
 
        assertFalse(b2 instanceof IIndexBinding);
1383
 
        assertEquals(b1, b2);
1384
 
        ICPPMethod b3 = getBindingFromASTName("m(0)", 1, ICPPMethod.class);
1385
 
        assertFalse(b3 instanceof IIndexBinding);
1386
 
        }
1387
 
 
1388
 
        //      class A {
1389
 
        //        friend inline void m(A p) {}
1390
 
        //      };
1391
 
 
1392
 
        //      void test(A a) {
1393
 
        //        m(a);
1394
 
        //      }
1395
 
        public void testInlineFriendFunction_284690() throws Exception {
1396
 
        getBindingFromASTName("m(a)", 1, ICPPFunction.class);
1397
 
        }
1398
 
 
1399
 
        private void checkValue(IValue initialValue, int i) {
1400
 
                assertNotNull(initialValue);
1401
 
                final Long numericalValue = initialValue.numericalValue();
1402
 
                assertNotNull(numericalValue);
1403
 
                assertEquals(i, numericalValue.intValue());
1404
 
        }
1405
 
 
1406
 
        /* CPP assertion helpers */
1407
 
        /* ##################################################################### */
1408
 
 
1409
 
        static protected void assertField(
1410
 
                        IBinding binding,
1411
 
                        String qn,
1412
 
                        Class expType,
1413
 
                        String expTypeQN
1414
 
        ) {
1415
 
                try {
1416
 
                        assertTrue(binding instanceof ICPPField);
1417
 
                        ICPPField field = (ICPPField) binding;
1418
 
                        assertQNEquals(qn, field);
1419
 
                        assertTrue(expType.isInstance(field.getType()));
1420
 
                        if(expTypeQN!=null) {
1421
 
                                assert(field.getType() instanceof ICPPBinding);
1422
 
                                ICPPBinding tyBinding = (ICPPBinding) field.getType();
1423
 
                                assertQNEquals(expTypeQN, tyBinding);
1424
 
                        }
1425
 
                } catch(DOMException de) {
1426
 
                        fail(de.getMessage());
1427
 
                }
1428
 
        }
1429
 
 
1430
 
        static protected void assertClassTypeBinding(IBinding binding,
1431
 
                        String qn,
1432
 
                        int key,
1433
 
                        int bases,
1434
 
                        int fields,
1435
 
                        int declaredFields,
1436
 
                        int methods,
1437
 
                        int declaredMethods,
1438
 
                        int allDeclaredMethods,
1439
 
                        int friends,
1440
 
                        int constructors,
1441
 
                        int nestedClasses) {
1442
 
                assertTrue(binding instanceof ICPPClassType);
1443
 
                assertClassType(((ICPPClassType) binding), qn, key, bases, fields, declaredFields, methods, declaredMethods, allDeclaredMethods, friends, constructors, nestedClasses);
1444
 
        }
1445
 
 
1446
 
        static protected void assertClassType(
1447
 
                        IType type,
1448
 
                        String qn,
1449
 
                        int key,
1450
 
                        int bases,
1451
 
                        int fields,
1452
 
                        int declaredFields,
1453
 
                        int methods,
1454
 
                        int declaredMethods,
1455
 
                        int allDeclaredMethods,
1456
 
                        int friends,
1457
 
                        int constructors,
1458
 
                        int nestedClasses
1459
 
        ) {
1460
 
                try {
1461
 
                        assertTrue(type instanceof ICPPClassType);
1462
 
                        ICPPClassType classType = (ICPPClassType) type;
1463
 
                        assertQNEquals(qn, classType);
1464
 
                        assertEquals(key, classType.getKey());
1465
 
                        assertEquals(bases, classType.getBases().length);
1466
 
                        assertEquals(fields, classType.getFields().length);
1467
 
                        assertEquals(declaredFields, classType.getDeclaredFields().length);
1468
 
                        assertEquals(methods, classType.getMethods().length);
1469
 
                        assertEquals(declaredMethods, classType.getDeclaredMethods().length);
1470
 
                        assertEquals(allDeclaredMethods, classType.getAllDeclaredMethods().length);
1471
 
                        // assertEquals(friends, classType.getFriends().length); (PDOMNotImplementedError)
1472
 
                        assertEquals(constructors, classType.getConstructors().length);
1473
 
                        assertEquals(nestedClasses, classType.getNestedClasses().length);
1474
 
                } catch(DOMException de) {
1475
 
                        fail(de.getMessage());
1476
 
                }
1477
 
        }
1478
 
 
1479
 
        public void assertEnumeration(IBinding binding, String name, String[] enumerators) throws DOMException {
1480
 
                assertTrue(binding instanceof IEnumeration);
1481
 
                assertEquals(name, binding.getName());
1482
 
                IEnumerator[] aEnumerators = ((IEnumeration)binding).getEnumerators();
1483
 
                Set expectedEnumerators = new HashSet();
1484
 
                expectedEnumerators.addAll(Arrays.asList(enumerators));
1485
 
                Set actualEnumerators = new HashSet();
1486
 
                for (IEnumerator enumerator : aEnumerators) {
1487
 
                        actualEnumerators.add(enumerator.getName());
1488
 
                }
1489
 
                assertEquals(expectedEnumerators, actualEnumerators);
1490
 
        }
1491
 
 
1492
 
        /**
1493
 
         * @param type
1494
 
         * @param cqn
1495
 
         * @param qn may be null
1496
 
         */
1497
 
        static protected void assertPTM(IType type, String cqn, String qn) {
1498
 
                try {
1499
 
                        assertTrue(type instanceof ICPPPointerToMemberType);
1500
 
                        ICPPPointerToMemberType ptmt = (ICPPPointerToMemberType) type;
1501
 
                        ICPPClassType classType = (ICPPClassType) ptmt.getMemberOfClass();
1502
 
                        assertQNEquals(cqn, classType);
1503
 
                        if(qn!=null) {
1504
 
                                assert(ptmt.getType() instanceof ICPPBinding);
1505
 
                                ICPPBinding tyBinding = (ICPPBinding) ptmt.getType();
1506
 
                                assertQNEquals(qn, tyBinding);
1507
 
                        }
1508
 
                } catch(DOMException de) {
1509
 
                        fail(de.getMessage());
1510
 
                }
1511
 
        }
1512
 
}