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

« back to all changes in this revision

Viewing changes to core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/text/selection/CPPSelectionTestsAnyIndexer.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) 2006, 2010 Wind River Systems, Inc. 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
 *    Markus Schorn - initial API and implementation
 
10
 *    Sergey Prigogin (Google)
 
11
 *******************************************************************************/ 
 
12
package org.eclipse.cdt.ui.tests.text.selection;
 
13
 
 
14
import java.io.IOException;
 
15
 
 
16
import org.eclipse.core.resources.IFile;
 
17
import org.eclipse.core.runtime.CoreException;
 
18
import org.eclipse.ui.IEditorInput;
 
19
import org.eclipse.ui.IEditorPart;
 
20
import org.eclipse.ui.PlatformUI;
 
21
import org.eclipse.ui.part.FileEditorInput;
 
22
 
 
23
import org.eclipse.cdt.core.CCorePlugin;
 
24
import org.eclipse.cdt.core.dom.IPDOMManager;
 
25
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
 
26
import org.eclipse.cdt.core.dom.ast.IASTName;
 
27
import org.eclipse.cdt.core.dom.ast.IASTNode;
 
28
import org.eclipse.cdt.core.index.IIndex;
 
29
import org.eclipse.cdt.core.model.ICProject;
 
30
import org.eclipse.cdt.core.testplugin.CProjectHelper;
 
31
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
 
32
import org.eclipse.cdt.ui.testplugin.CTestPlugin;
 
33
 
 
34
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
 
35
 
 
36
/**
 
37
 * Test Ctrl_F3/F3 with the DOM Indexer for a C++ project.
 
38
 */
 
39
public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsIndexer {
 
40
        private static final int MAX_WAIT_TIME = 8000;
 
41
 
 
42
        protected String sourceIndexerID;
 
43
        protected IIndex index;
 
44
        
 
45
        public CPPSelectionTestsAnyIndexer(String name, String indexerID) {
 
46
                super(name);
 
47
                sourceIndexerID= indexerID;
 
48
        }
 
49
        
 
50
        @Override
 
51
        protected void setUp() throws Exception {
 
52
                super.setUp();
 
53
                
 
54
                // Create temp project
 
55
                fCProject= createProject("CPPSelectionTestsDOMIndexerProject");
 
56
                assertNotNull("Unable to create project", fCProject);
 
57
//              MakeProjectNature.addNature(project, new NullProgressMonitor());
 
58
//              ScannerConfigNature.addScannerConfigNature(project);
 
59
//              PerProjectSICollector.calculateCompilerBuiltins(project);
 
60
 
 
61
                CCorePlugin.getIndexManager().setIndexerId(fCProject, sourceIndexerID);
 
62
                index= CCorePlugin.getIndexManager().getIndex(fCProject);
 
63
        }
 
64
 
 
65
        @Override
 
66
        protected void tearDown() throws Exception {
 
67
                closeAllEditors();
 
68
                CProjectHelper.delete(fCProject);
 
69
                super.tearDown();
 
70
        }
 
71
 
 
72
        private ICProject createProject(String projectName) throws CoreException {
 
73
                ICProject cPrj = CProjectHelper.createCCProject(projectName, "bin", IPDOMManager.ID_NO_INDEXER);
 
74
                return cPrj;
 
75
        }
 
76
        
 
77
        protected StringBuffer[] getContents(int sections) throws IOException {
 
78
                return TestSourceReader.getContentsForTest(
 
79
                                CTestPlugin.getDefault().getBundle(), "ui", CPPSelectionTestsAnyIndexer.class, getName(), sections);
 
80
        }
 
81
 
 
82
        private void assertNode(String name, int offset, IASTNode node) {
 
83
                assertNotNull(node);
 
84
                assertEquals(node.toString(), name);
 
85
                IASTFileLocation loc= node.getFileLocation();
 
86
                assertEquals(loc.getNodeOffset(), offset);
 
87
                assertEquals(loc.getNodeLength(), name.length());
 
88
        }
 
89
 
 
90
        protected void waitUntilFileIsIndexed(IIndex index, IFile file, int maxmillis) throws Exception {
 
91
                TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
92
        }
 
93
 
 
94
        // // header
 
95
    // class Point{ 
 
96
    //  public:    
 
97
    //     Point(): xCoord(0){} 
 
98
    //     Point& operator=(const Point &rhs){return *this;}    
 
99
    //     void* operator new [ ] (unsigned int);
 
100
    //  private:                             
 
101
    //     int xCoord;                          
 
102
    //  };                                   
 
103
        
 
104
        // // source
 
105
        // #include "test93281.h"
 
106
    // static const Point zero;
 
107
    // int main(int argc, char **argv) {        
 
108
    //    Point *p2 = new Point();         
 
109
    //    p2->    operator // /* operator */ // F3 in the middle 
 
110
    //    // of "operator" should work
 
111
    //    // \
 
112
    //    /* */
 
113
    //    =(zero);           // line B
 
114
    //    p2->operator /* oh yeah */ new // F3 in the middle of "operator"
 
115
    //    // should work
 
116
    //    //
 
117
    //    [ /* sweet */ ] //
 
118
    //    (2);
 
119
    //    return (0);                          
 
120
    // }
 
121
    public void testBug93281() throws Exception {
 
122
        StringBuffer[] buffers= getContents(2);
 
123
        String hcode= buffers[0].toString();
 
124
        String scode= buffers[1].toString();
 
125
        IFile hfile = importFile("test93281.h", hcode); 
 
126
        IFile file = importFile("test93281.cpp", scode); 
 
127
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
128
        
 
129
        int offset = scode.indexOf("p2->operator") + 6;
 
130
        IASTNode node = testF3(file, offset);
 
131
        
 
132
        assertTrue(node instanceof IASTName);
 
133
        assertEquals(((IASTName)node).toString(), "operator new[]");
 
134
        assertEquals(((ASTNode)node).getOffset(), hcode.indexOf("operator new"));
 
135
        assertEquals(((ASTNode)node).getLength(), 16);
 
136
        
 
137
        offset = scode.indexOf("p2->    operator") + 11;
 
138
        node = testF3(file, offset);
 
139
        
 
140
        assertTrue(node instanceof IASTName);
 
141
        assertEquals(((IASTName)node).toString(), "operator =");
 
142
        assertEquals(((ASTNode)node).getOffset(), hcode.indexOf("operator="));
 
143
        assertEquals(((ASTNode)node).getLength(), 9);
 
144
    }
 
145
    
 
146
    //  template <class T>
 
147
        //      inline void testTemplate(T& aRef);
 
148
        //
 
149
        //      class Temp {
 
150
        //      };
 
151
 
 
152
        //      #include <stdio.h>
 
153
        //      #include <stdlib.h>
 
154
        //      #include "test.h"
 
155
        //      int main(void) {
 
156
        //              puts("Hello World!!!");
 
157
        //
 
158
        //              Temp testFile;
 
159
        //              testTemplate(testFile);
 
160
        //
 
161
        //              return EXIT_SUCCESS;
 
162
        //      }
 
163
        public void testBug207320() throws Exception {
 
164
                StringBuffer[] buffers= getContents(2);
 
165
        String hcode= buffers[0].toString();
 
166
        String scode= buffers[1].toString();
 
167
        IFile hfile = importFile("test.h", hcode); 
 
168
        IFile file = importFile("test.cpp", scode); 
 
169
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
170
        
 
171
        int hoffset= hcode.indexOf("testTemplate"); 
 
172
        int soffset = scode.indexOf("testTemplate"); 
 
173
        IASTNode def = testF3(file, soffset+2);
 
174
        assertTrue(def instanceof IASTName);
 
175
        assertEquals("testTemplate", ((IASTName) def).toString());
 
176
        assertEquals(hoffset, ((ASTNode) def).getOffset());
 
177
        assertEquals(12, ((ASTNode) def).getLength());
 
178
        }
 
179
 
 
180
        // template<typename T>
 
181
        // class C {
 
182
        //   public: void assign(const T* s) {}
 
183
        // };
 
184
 
 
185
        // void main() {
 
186
        //   C<char> a;
 
187
        //   a.assign("aaa");
 
188
        // }
 
189
        public void testTemplateClassMethod_207320() throws Exception {
 
190
                StringBuffer[] buffers= getContents(2);
 
191
        String hcode= buffers[0].toString();
 
192
        String scode= buffers[1].toString();
 
193
        IFile hfile = importFile("test.h", hcode); 
 
194
        IFile file = importFile("test.cpp", scode);
 
195
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
196
        
 
197
        int hoffset= hcode.indexOf("assign"); 
 
198
        int soffset = scode.indexOf("assign"); 
 
199
        IASTNode def = testF3(file, soffset + 2);
 
200
        assertTrue(def instanceof IASTName);
 
201
        assertEquals("assign", ((IASTName) def).toString());
 
202
        assertEquals(hoffset, ((ASTNode) def).getOffset());
 
203
        assertEquals(6, ((ASTNode) def).getLength());
 
204
        }
 
205
 
 
206
        // // the header
 
207
    // extern int MyInt;       // MyInt is in another file
 
208
    // extern const int MyConst;   // MyConst is in another file
 
209
    // void MyFunc(int);       // often used in header files
 
210
    // typedef int NewInt;     // a normal typedef statement
 
211
        // struct MyStruct { int Member1; int Member2; };
 
212
        // class MyClass { int MemberVar; };
 
213
    
 
214
    // #include "basicDefinition.h"
 
215
    // int MyInt;
 
216
    // extern const int MyConst = 42;
 
217
    // void MyFunc(int a) { cout << a << endl; }
 
218
        // class MyClass;          
 
219
        // struct MyStruct;        
 
220
    public void testBasicDefinition() throws Exception {
 
221
        StringBuffer[] buffers= getContents(2);
 
222
        String hcode= buffers[0].toString();
 
223
        String scode= buffers[1].toString();
 
224
        IFile hfile = importFile("basicDefinition.h", hcode); 
 
225
        IFile file = importFile("testBasicDefinition.cpp", scode); 
 
226
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
227
        
 
228
        int hoffset= hcode.indexOf("MyInt"); 
 
229
        int soffset = scode.indexOf("MyInt"); 
 
230
        IASTNode decl = testF3(file, soffset+2);
 
231
        IASTNode def = testF3(hfile, hoffset+2);
 
232
        assertTrue(def instanceof IASTName);
 
233
        assertTrue(decl instanceof IASTName);
 
234
        assertEquals("MyInt", ((IASTName) decl).toString());
 
235
        assertEquals(hoffset, ((ASTNode) decl).getOffset());
 
236
        assertEquals(5, ((ASTNode) decl).getLength());
 
237
        assertEquals("MyInt", ((IASTName) def).toString());
 
238
        assertEquals(soffset, def.getFileLocation().getNodeOffset());
 
239
        assertEquals(5, ((ASTNode) def).getLength());
 
240
        
 
241
        hoffset= hcode.indexOf("MyConst"); 
 
242
        soffset = scode.indexOf("MyConst"); 
 
243
        decl = testF3(file, soffset+2);
 
244
        def = testF3(hfile, hoffset+2);
 
245
        assertTrue(def instanceof IASTName);
 
246
        assertTrue(decl instanceof IASTName);
 
247
        assertEquals("MyConst", ((IASTName) decl).toString());
 
248
        assertEquals(hoffset, ((ASTNode) decl).getOffset());
 
249
        assertEquals(7, ((ASTNode) decl).getLength());
 
250
        assertEquals("MyConst", ((IASTName) def).toString());
 
251
        assertEquals(soffset, def.getFileLocation().getNodeOffset());
 
252
        assertEquals(7, ((ASTNode) def).getLength());
 
253
        
 
254
        hoffset= hcode.indexOf("MyFunc"); 
 
255
        soffset = scode.indexOf("MyFunc"); 
 
256
        decl = testF3(file, soffset+2);
 
257
        def = testF3(hfile, hoffset+2);
 
258
        assertTrue(def instanceof IASTName);
 
259
        assertTrue(decl instanceof IASTName);
 
260
        assertEquals("MyFunc", ((IASTName) decl).toString());
 
261
        assertEquals(hoffset, ((ASTNode) decl).getOffset());
 
262
        assertEquals(6, ((ASTNode) decl).getLength());
 
263
        assertEquals("MyFunc", ((IASTName) def).toString());
 
264
        assertEquals(soffset, def.getFileLocation().getNodeOffset());
 
265
        assertEquals(6, ((ASTNode) def).getLength());
 
266
        
 
267
        hoffset= hcode.indexOf("MyStruct"); 
 
268
        soffset = scode.indexOf("MyStruct"); 
 
269
        decl = testF3(file, soffset+2);
 
270
        def = testF3(hfile, hoffset+2);
 
271
        assertTrue(def instanceof IASTName);
 
272
        assertTrue(decl instanceof IASTName);
 
273
        assertEquals("MyStruct", ((IASTName) decl).toString());
 
274
        assertEquals(hoffset, ((ASTNode) decl).getOffset());
 
275
        assertEquals(8, ((ASTNode) decl).getLength());
 
276
        assertEquals("MyStruct", ((IASTName) def).toString());
 
277
        assertEquals(hoffset, def.getFileLocation().getNodeOffset());
 
278
        assertEquals(8, ((ASTNode) def).getLength());
 
279
        
 
280
        hoffset= hcode.indexOf("MyClass"); 
 
281
        soffset = scode.indexOf("MyClass"); 
 
282
        decl = testF3(file, soffset+2);
 
283
        def = testF3(hfile, hoffset+2);
 
284
        assertTrue(def instanceof IASTName);
 
285
        assertTrue(decl instanceof IASTName);
 
286
        assertEquals("MyClass", ((IASTName) decl).toString());
 
287
        assertEquals(hoffset, ((ASTNode) decl).getOffset());
 
288
        assertEquals(7, ((ASTNode) decl).getLength());
 
289
        assertEquals("MyClass", ((IASTName) def).toString());
 
290
        assertEquals(hoffset, def.getFileLocation().getNodeOffset());
 
291
        assertEquals(7, ((ASTNode) def).getLength());
 
292
    }
 
293
    
 
294
        // // the header
 
295
    // namespace N {
 
296
    //    template < class T > class AAA { T _t; };
 
297
    // };
 
298
    
 
299
    // #include "testBasicTemplateInstance.h"
 
300
    // N::AAA<int> a;
 
301
        public void testBasicTemplateInstance_207320() throws Exception{
 
302
        StringBuffer[] buffers= getContents(2);
 
303
        String hcode= buffers[0].toString();
 
304
        String scode= buffers[1].toString();
 
305
        IFile hfile = importFile("testBasicTemplateInstance.h", hcode); 
 
306
        IFile file = importFile("testBasicTemplateInstance.cpp", scode); 
 
307
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
308
        
 
309
        int hoffset= hcode.indexOf("AAA"); 
 
310
        int soffset = scode.indexOf("AAA<int>");
 
311
        IASTNode decl1 = testF3(file, soffset, 3);
 
312
        assertTrue(decl1 instanceof IASTName);
 
313
        assertEquals("AAA", ((IASTName) decl1).toString());
 
314
        assertEquals(hoffset, decl1.getFileLocation().getNodeOffset());
 
315
        assertEquals(3, ((ASTNode) decl1).getLength());
 
316
                
 
317
        IASTNode decl2 = testF3(file, soffset, 8);
 
318
        assertEquals("AAA", ((IASTName) decl2).toString());
 
319
        assertEquals(hoffset, decl2.getFileLocation().getNodeOffset());
 
320
        assertEquals(3, ((ASTNode) decl2).getLength());
 
321
        }
 
322
        
 
323
        // // the header
 
324
    // class X {
 
325
    // public: 
 
326
    //    X(int); // openReferences fails to find the constructor in g()
 
327
    // };
 
328
        
 
329
        // #include "testBug86829A.h"
 
330
    // X f(X);
 
331
    // void g()
 
332
    // {
 
333
    //    X b = f(X(2)); // openDeclarations on X(int) shall find constructor 
 
334
    // }
 
335
        public void testBug86829A() throws Exception {
 
336
        StringBuffer[] buffers= getContents(2);
 
337
        String hcode= buffers[0].toString();
 
338
        String scode= buffers[1].toString();
 
339
        IFile hfile = importFile("testBug86829A.h", hcode); 
 
340
        IFile file = importFile("testBug86829A.cpp", scode); 
 
341
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
342
        
 
343
        int offset = scode.indexOf("X(2)"); 
 
344
        int doffset= hcode.indexOf("X(int)");
 
345
        IASTNode decl = testF3(file, offset);
 
346
        assertTrue(decl instanceof IASTName);
 
347
        assertEquals("X", ((IASTName) decl).toString());
 
348
        assertEquals(doffset, decl.getFileLocation().getNodeOffset());
 
349
        assertEquals(1, ((ASTNode) decl).getLength());
 
350
        }
 
351
        
 
352
        // // the header
 
353
    // class X {
 
354
    // public:
 
355
    //    operator int();
 
356
    // };
 
357
    // class Y {
 
358
    // public:
 
359
    //    operator X();
 
360
    // };
 
361
        
 
362
        // #include "testBug86829B.h"
 
363
        // void testfunc() {
 
364
    // Y a;
 
365
    // int c = X(a); // OK: a.operator X().operator int()
 
366
        // }
 
367
        public void _testBug86829B() throws Exception {
 
368
        StringBuffer[] buffers= getContents(2);
 
369
        String hcode= buffers[0].toString();
 
370
        String scode= buffers[1].toString();
 
371
        IFile hfile = importFile("testBug86829B.h", hcode); 
 
372
        IFile file = importFile("testBug86829B.cpp", scode); 
 
373
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
374
                
 
375
        int offset = scode.indexOf("X(a)"); 
 
376
        int doffset = hcode.indexOf("X()"); 
 
377
        IASTNode decl = testF3(file, offset);
 
378
        assertTrue(decl instanceof IASTName);
 
379
        assertEquals(decl.toString(), "X");
 
380
        assertEquals(doffset, decl.getFileLocation().getNodeOffset());
 
381
        assertEquals(1, ((ASTNode) decl).getLength());
 
382
        }
 
383
        
 
384
        // // the header
 
385
        // extern int a;                                // declares 
 
386
        // extern const int c = 1;              // defines 
 
387
        // struct S {int a; int b;};    // defines 
 
388
        // struct X {                                   // defines 
 
389
        //    int x;                                    // defines nonstatic data member 
 
390
        //    static int y;                     // declares static data member 
 
391
        //    X(): x(0) { }                     // defines a constructor of 
 
392
        // };
 
393
        // enum E {up, down};                   // defines 
 
394
        // namespace N {int d;}                 // defines 
 
395
        // namespace N1 = N;                    // defines 
 
396
        // int f(int);                                  // declares 
 
397
        // extern X anotherX;                   // declares 
 
398
        
 
399
        // #include "testCPPSpecDeclsDefs.h"
 
400
        // int a;                                               // defines 
 
401
        // int X::y = 1;                                // defines 
 
402
        // X anX;                                               // defines variable, implicitly calls ctor
 
403
        // extern const int c;                  // declares
 
404
        // int f(int x) {return x+a;}   // defines
 
405
        // struct S;                                    // declares
 
406
        // typedef int Int;                     // declares 
 
407
        // using N::d;                                  // declares 
 
408
        // S s;
 
409
        // Int lhs= s.a+s.b+up+down+anX+0;
 
410
        public void testCPPSpecDeclsDefs() throws Exception {
 
411
        StringBuffer[] buffers= getContents(2);
 
412
        String hcode= buffers[0].toString();
 
413
        String scode= buffers[1].toString();
 
414
        IFile hfile = importFile("testCPPSpecDeclsDefs.h", hcode); 
 
415
        IFile file = importFile("testCPPSpecDeclsDefs.cpp", scode); 
 
416
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
417
        
 
418
        int offset0= hcode.indexOf("a;");
 
419
        int offset1= scode.indexOf("a;"); 
 
420
        IASTNode decl= testF3(hfile, offset0);
 
421
        assertNode("a", offset1, decl);
 
422
        decl= testF3(file, offset1);
 
423
        assertNode("a", offset0, decl);
 
424
 
 
425
        offset0= hcode.indexOf("int c") + 4;
 
426
        offset1= scode.indexOf("int c") + 4; 
 
427
        decl= testF3(hfile, offset0);
 
428
        assertNode("c", offset1, decl);
 
429
        decl= testF3(file, offset1);
 
430
        assertNode("c", offset0, decl);
 
431
 
 
432
        offset0= hcode.indexOf("f(int");
 
433
        offset1= scode.indexOf("f(int");
 
434
        decl= testF3(hfile, offset0);
 
435
        assertNode("f", offset1, decl);
 
436
        decl= testF3(file, offset1);
 
437
        assertNode("f", offset0, decl);
 
438
 
 
439
        offset0= scode.indexOf("x)");
 
440
        decl= testF3(file, offset0);
 
441
        assertNode("x", offset0, decl);
 
442
 
 
443
        offset1= scode.indexOf("x+a");
 
444
        decl= testF3(file, offset1);
 
445
        assertNode("x", offset0, decl);
 
446
 
 
447
        offset0= scode.indexOf("a;");
 
448
        offset1= scode.indexOf("a;}"); 
 
449
        decl= testF3(file, offset1);
 
450
        assertNode("a", offset0, decl);
 
451
 
 
452
        offset0= hcode.indexOf("S");
 
453
        offset1= scode.indexOf("S;"); 
 
454
        int offset2= scode.indexOf("S", offset1); 
 
455
        decl= testF3(hfile, offset0);
 
456
        assertNode("S", offset0, decl);
 
457
        decl= testF3(file, offset1);
 
458
        assertNode("S", offset0, decl);
 
459
        decl= testF3(file, offset2);
 
460
        assertNode("S", offset0, decl);
 
461
                
 
462
        offset0 = hcode.indexOf("a; int b;};");
 
463
        offset1 = scode.indexOf("a+s.b");
 
464
        decl= testF3(hfile, offset0);
 
465
        assertNode("a", offset0, decl);
 
466
        decl= testF3(file, offset1);
 
467
        assertNode("a", offset0, decl);
 
468
 
 
469
        offset0= hcode.indexOf("b;};");
 
470
        offset1= scode.indexOf("s.b") + 2;
 
471
        decl= testF3(hfile, offset0);
 
472
        assertNode("b", offset0, decl);
 
473
        decl= testF3(file, offset1);
 
474
        assertNode("b", offset0, decl);
 
475
 
 
476
        offset0= hcode.indexOf("X");
 
477
        offset1= scode.indexOf("X");
 
478
        offset2= scode.indexOf("X", offset1 + 1);
 
479
        decl= testF3(hfile, offset0);
 
480
        assertNode("X", offset0, decl);
 
481
        decl= testF3(file, offset1);
 
482
        assertNode("X", offset0, decl);
 
483
        decl= testF3(file, offset2);
 
484
        assertNode("X", offset0, decl);
 
485
 
 
486
        offset0= hcode.indexOf("x;");
 
487
        offset1= hcode.indexOf("x", offset0 + 1);
 
488
        decl= testF3(hfile, offset0);
 
489
        assertNode("x", offset0, decl);
 
490
        decl= testF3(hfile, offset1);
 
491
        assertNode("x", offset0, decl);
 
492
 
 
493
        offset0= hcode.indexOf("y;");
 
494
        offset1= scode.indexOf("y");
 
495
        decl= testF3(hfile, offset0);
 
496
        assertNode("y", offset1, decl);
 
497
        decl= testF3(file, offset1);
 
498
        assertNode("y", offset0, decl);
 
499
                
 
500
                offset0= hcode.indexOf("X()"); 
 
501
        decl = testF3(hfile, offset0);
 
502
        assertNode("X", offset0, decl);
 
503
                                
 
504
        offset0= hcode.indexOf("up");
 
505
        offset1= scode.indexOf("up");
 
506
        decl= testF3(hfile, offset0);
 
507
        assertNode("up", offset0, decl);
 
508
        decl= testF3(file, offset1);
 
509
        assertNode("up", offset0, decl);
 
510
 
 
511
        offset0= hcode.indexOf("down");
 
512
        offset1= scode.indexOf("down");
 
513
        decl= testF3(hfile, offset0);
 
514
        assertNode("down", offset0, decl);
 
515
        decl= testF3(file, offset1);
 
516
        assertNode("down", offset0, decl);
 
517
 
 
518
        offset0= hcode.indexOf("N");
 
519
        offset1= hcode.indexOf("N;", offset0 + 1);
 
520
        offset2= scode.indexOf("N");
 
521
        decl= testF3(hfile, offset0);
 
522
        assertNode("N", offset0, decl);
 
523
        decl= testF3(hfile, offset1);
 
524
        assertNode("N", offset0, decl);
 
525
        decl= testF3(file, offset2);
 
526
        assertNode("N", offset0, decl);
 
527
                
 
528
        offset0= hcode.indexOf("d;");
 
529
        offset1= scode.indexOf("d;");
 
530
        decl= testF3(hfile, offset0);
 
531
        assertNode("d", offset0, decl);
 
532
//          does not work, created separate testcase        
 
533
//        decl= testF3(file, offset1);
 
534
//        assertNode("d", offset0, decl);
 
535
 
 
536
        offset0= hcode.indexOf("N1");
 
537
        decl= testF3(hfile, offset0);
 
538
        assertNode("N1", offset0, decl);
 
539
 
 
540
        offset0= scode.indexOf("anX");
 
541
        offset1= scode.indexOf("anX", offset0 + 1);
 
542
        decl= testF3(file, offset0);
 
543
        assertNode("X", hcode.indexOf("X()"), decl);
 
544
        decl= testF3(file, offset1);
 
545
        assertNode("anX", offset0, decl);
 
546
 
 
547
        offset0= scode.indexOf("Int");
 
548
        offset1= scode.indexOf("Int", offset0 + 1);
 
549
        decl= testF3(file, offset0);
 
550
        assertNode("Int", offset0, decl);
 
551
        decl= testF3(file, offset1);
 
552
        assertNode("Int", offset0, decl);
 
553
        }
 
554
 
 
555
        // // the header
 
556
        // namespace N {int d;}                 // defines 
 
557
        
 
558
        // #include "testBug168533.h"
 
559
        // using N::d;                                  // declares 
 
560
        // int a= d;
 
561
        public void testBug168533() throws Exception {
 
562
        StringBuffer[] buffers= getContents(2);
 
563
        String hcode= buffers[0].toString();
 
564
        String scode= buffers[1].toString();
 
565
        IFile hfile = importFile("testBug168533.h", hcode); 
 
566
        IFile file = importFile("testBug168533.cpp", scode); 
 
567
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
568
                        
 
569
        int offset0= hcode.indexOf("d;");
 
570
        int offset1= scode.indexOf("d;");
 
571
        int offset2= scode.indexOf("d", offset1);
 
572
        IASTNode decl= testF3(hfile, offset0);
 
573
        assertNode("d", offset0, decl);
 
574
        decl= testF3(file, offset1);
 
575
        assertNode("d", offset0, decl);
 
576
        decl= testF3(file, offset2);
 
577
        assertNode("d", offset0, decl);
 
578
        }
 
579
 
 
580
    // class Overflow {
 
581
    // public:
 
582
    //    Overflow(char,double,double);
 
583
    // };
 
584
        
 
585
        // #include "testBug95225.h"
 
586
    // void f(double x) {
 
587
    //    throw Overflow('+',x,3.45e107);
 
588
    // }
 
589
    // int foo() {
 
590
    //    try {
 
591
    //       f(1.2);
 
592
    //    }
 
593
    //    catch(Overflow& oo) {
 
594
    //                          // handle exceptions of type Overflow here
 
595
    //    }
 
596
    // }
 
597
        public void testBug95225() throws Exception {
 
598
        StringBuffer[] buffers= getContents(2);
 
599
        String hcode= buffers[0].toString();
 
600
        String scode= buffers[1].toString();
 
601
        IFile hfile = importFile("testBug95225.h", hcode); 
 
602
        IFile file = importFile("testBug95225.cpp", scode); 
 
603
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
604
        IASTNode decl;
 
605
        int offset0, offset1;
 
606
 
 
607
        offset0= hcode.indexOf("Overflow"); 
 
608
        offset1= scode.indexOf("rflow&"); 
 
609
        decl = testF3(file, offset1);
 
610
        assertNode("Overflow", offset0, decl);
 
611
        decl = testF3(hfile, offset0);
 
612
        assertNode("Overflow", offset0, decl);
 
613
 
 
614
        offset0= hcode.indexOf("Overflow("); 
 
615
        offset1= scode.indexOf("rflow('+'"); 
 
616
        decl = testF3(file, offset1);
 
617
        assertNode("Overflow", offset0, decl);
 
618
        decl = testF3(hfile, offset0);
 
619
        assertNode("Overflow", offset0, decl);
 
620
 
 
621
        offset0= scode.indexOf("x"); 
 
622
        offset1= scode.indexOf("x", offset0); 
 
623
        decl = testF3(file, offset0);
 
624
        assertNode("x", offset0, decl);
 
625
        decl = testF3(file, offset1);
 
626
        assertNode("x", offset0, decl);
 
627
    }
 
628
        
 
629
    // struct A { }; // implicitly declared A::operator=
 
630
    // struct B : A {
 
631
    //    B& operator=(const B &);
 
632
    // };
 
633
        
 
634
        // #include "testBug95202.h"
 
635
    // B& B::operator=(const B& s) {
 
636
    //    this->B::operator=(s); // wellformed
 
637
    //    return *this;
 
638
    // }
 
639
    public void testBug95202() throws Exception {
 
640
        StringBuffer[] buffers= getContents(2);
 
641
        String hcode= buffers[0].toString();
 
642
        String scode= buffers[1].toString();
 
643
        IFile hfile = importFile("testBug95202.h", hcode); 
 
644
        IFile file = importFile("testBug95202.cpp", scode); 
 
645
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
646
        IASTNode decl;
 
647
        int offset0, offset1;
 
648
 
 
649
        offset0= scode.indexOf("s)"); 
 
650
        offset1= scode.indexOf("s);", offset0 + 1); 
 
651
        decl = testF3(file, offset0);
 
652
        assertNode("s", offset0, decl);
 
653
        decl = testF3(file, offset1);
 
654
        assertNode("s", offset0, decl);        
 
655
    }
 
656
        
 
657
        // extern int abc;
 
658
        
 
659
        // #include "testBug101287.h"
 
660
        // int main(int argc, char **argv) {
 
661
        //    abc;
 
662
        // }
 
663
        public void testBug101287() throws Exception {
 
664
        StringBuffer[] buffers= getContents(2);
 
665
        String hcode= buffers[0].toString();
 
666
        String scode= buffers[1].toString();
 
667
        IFile hfile = importFile("testBug101287.h", hcode); 
 
668
        IFile file = importFile("testBug101287.cpp", scode); 
 
669
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
670
        IASTNode decl;
 
671
        int offset0, offset1;
 
672
                        
 
673
        offset0 = hcode.indexOf("abc");
 
674
        offset1 = scode.indexOf("abc");
 
675
        decl = testF3(hfile, offset0);
 
676
        assertNode("abc", offset0, decl);
 
677
        decl = testF3(file, offset1);
 
678
        assertNode("abc", offset0, decl);        
 
679
        }
 
680
        
 
681
        // struct RTBindingEnd
 
682
        // {
 
683
        //    int index;
 
684
        // };
 
685
 
 
686
    // #include "testBug102258.h"
 
687
    // void f(RTBindingEnd & end) {
 
688
    // }
 
689
        public void testBug102258() throws Exception {
 
690
        StringBuffer[] buffers= getContents(2);
 
691
        String hcode= buffers[0].toString();
 
692
        String scode= buffers[1].toString();
 
693
        IFile hfile = importFile("testBug102258.h", hcode); 
 
694
        IFile file = importFile("testBug102258.cpp", scode); 
 
695
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
696
        IASTNode decl;
 
697
        int offset0, offset1;
 
698
 
 
699
        offset0 = hcode.indexOf("RTBindingEnd");
 
700
        offset1 = scode.indexOf("RTBindingEnd");
 
701
        decl = testF3(hfile, offset0);
 
702
        assertNode("RTBindingEnd", offset0, decl);
 
703
        decl = testF3(file, offset1);
 
704
        assertNode("RTBindingEnd", offset0, decl);        
 
705
        }
 
706
        
 
707
        // namespace foo {
 
708
        //    int g() {
 
709
        //       return 0;
 
710
        //    }
 
711
        // }
 
712
 
 
713
        // #include "testBug103323.h"
 
714
        // int f() {
 
715
        //    return foo::g();
 
716
        // }
 
717
        public void testBug103323() throws Exception {
 
718
        StringBuffer[] buffers= getContents(2);
 
719
        String hcode= buffers[0].toString();
 
720
        String scode= buffers[1].toString();
 
721
        IFile hfile = importFile("testBug103323.h", hcode); 
 
722
        IFile file = importFile("testBug103323.cpp", scode); 
 
723
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
724
        IASTNode decl;
 
725
        int offset0, offset1;
 
726
 
 
727
        offset0 = hcode.indexOf("g()");
 
728
        offset1 = scode.indexOf("g()");
 
729
        decl = testF3(hfile, offset0);
 
730
        assertNode("g", offset0, decl);
 
731
        decl = testF3(file, offset1);
 
732
        assertNode("g", offset0, decl);        
 
733
        
 
734
        testSimple_Ctrl_G_Selection(file, offset1, 1, 1);
 
735
        }
 
736
 
 
737
    // typedef int TestTypeOne;
 
738
    // typedef int TestTypeTwo;
 
739
 
 
740
        // #include "testBug78354.h"
 
741
    // int main()
 
742
    // {
 
743
    //    TestTypeOne myFirstLink = 5;
 
744
    //    TestTypeTwo mySecondLink = 6;
 
745
    //    return 0;
 
746
    // }
 
747
    public void testBug78354() throws Exception {
 
748
        StringBuffer[] buffers= getContents(2);
 
749
        String hcode= buffers[0].toString();
 
750
        String scode= buffers[1].toString();
 
751
        IFile hfile = importFile("testBug78354.h", hcode); 
 
752
        IFile file = importFile("testBug78354.cpp", scode); 
 
753
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
754
        IASTNode decl;
 
755
        int offset0, offset1;
 
756
        
 
757
        offset0 = hcode.indexOf("TestTypeOne");
 
758
        offset1 = scode.indexOf("TestTypeOne");
 
759
        decl = testF3(hfile, offset0);
 
760
        assertNode("TestTypeOne", offset0, decl);
 
761
        decl = testF3(file, offset1);
 
762
        assertNode("TestTypeOne", offset0, decl);        
 
763
 
 
764
        offset0 = hcode.indexOf("TestTypeTwo");
 
765
        offset1 = scode.indexOf("TestTypeTwo");
 
766
        decl = testF3(hfile, offset0);
 
767
        assertNode("TestTypeTwo", offset0, decl);
 
768
        decl = testF3(file, offset1);
 
769
        assertNode("TestTypeTwo", offset0, decl);        
 
770
    }
 
771
 
 
772
    // int x;
 
773
    
 
774
    // #include "testBug103697.h"
 
775
    // int foo() {
 
776
    //     return x;
 
777
    // }
 
778
    public void testBug103697() throws Exception {
 
779
        StringBuffer[] buffers= getContents(2);
 
780
        String hcode= buffers[0].toString();
 
781
        String scode= buffers[1].toString();
 
782
        IFile hfile = importFileWithLink("testBug103697.h", hcode); 
 
783
        IFile file = importFileWithLink("testBug103697.cpp", scode); 
 
784
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
785
        IASTNode decl;
 
786
        int offset0, offset1;
 
787
                
 
788
        offset0 = hcode.indexOf("x");
 
789
        offset1 = scode.indexOf("x");
 
790
        decl = testF3(hfile, offset0);
 
791
        assertNode("x", offset0, decl);
 
792
        decl = testF3(file, offset1);
 
793
        assertNode("x", offset0, decl);        
 
794
    }
 
795
    
 
796
        // class __attribute__((visibility("default"))) FooClass
 
797
        // {
 
798
        //    int foo();
 
799
        // };
 
800
 
 
801
    // #include "testBug108202.h"
 
802
    // int FooClass::foo() {
 
803
        //    return 0;
 
804
        // }
 
805
    public void testBug108202() throws Exception {
 
806
        StringBuffer[] buffers= getContents(2);
 
807
        String hcode= buffers[0].toString();
 
808
        String scode= buffers[1].toString();
 
809
        IFile hfile = importFile("testBug108202.h", hcode); 
 
810
        IFile file = importFile("testBug108202.cpp", scode); 
 
811
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
812
        IASTNode decl;
 
813
        int offset0, offset1;
 
814
        
 
815
        offset0 = hcode.indexOf("foo");
 
816
        offset1 = scode.indexOf("foo");
 
817
        decl = testF3(hfile, offset0);
 
818
        assertNode("foo", offset1, decl);
 
819
        decl = testF3(file, offset1);
 
820
        assertNode("foo", offset0, decl);        
 
821
    }
 
822
    
 
823
    // void c();
 
824
    
 
825
    // #include "c.h"
 
826
    // void c() {}
 
827
 
 
828
    // void cpp();
 
829
    
 
830
    // #include "cpp.h"
 
831
    // void cpp() {}
 
832
    public void testCNavigationInCppProject_bug183973() throws Exception {
 
833
        StringBuffer[] buffers= getContents(4);
 
834
        String hccode= buffers[0].toString();
 
835
        String ccode= buffers[1].toString();
 
836
        String hcppcode= buffers[2].toString();
 
837
        String cppcode= buffers[3].toString();
 
838
        IFile hcfile = importFile("c.h", hccode); 
 
839
        IFile cfile = importFile("c.c", ccode); 
 
840
        IFile hcppfile = importFile("cpp.h", hcppcode); 
 
841
        IFile cppfile = importFile("cpp.cpp", cppcode); 
 
842
        CCorePlugin.getIndexManager().reindex(fCProject);
 
843
        waitForIndex(MAX_WAIT_TIME);
 
844
        
 
845
        IASTNode decl;
 
846
        int offset0, offset1;
 
847
        // cpp navigation
 
848
        offset0 = hcppcode.indexOf("cpp(");
 
849
        offset1 = cppcode.indexOf("cpp(");
 
850
        decl = testF3(hcppfile, offset0);
 
851
        assertNode("cpp", offset1, decl);
 
852
        decl = testF3(cppfile, offset1);
 
853
        assertNode("cpp", offset0, decl);        
 
854
 
 
855
        // plain-c navigation
 
856
        offset0 = hccode.indexOf("c(");
 
857
        offset1 = ccode.indexOf("c(");
 
858
        decl = testF3(hcfile, offset0);
 
859
        assertNode("c", offset1, decl);
 
860
        decl = testF3(cfile, offset1);
 
861
        assertNode("c", offset0, decl);        
 
862
    }
 
863
    
 
864
    // typedef struct {
 
865
    //    int a;
 
866
    // } usertype;
 
867
    // void func(usertype t);
 
868
 
 
869
        // #include "testBug190730.h"
 
870
    // void func(usertype t) {
 
871
    // }
 
872
    public void testFuncWithTypedefForAnonymousStruct_190730() throws Exception {
 
873
        StringBuffer[] buffers= getContents(2);
 
874
        String hcode= buffers[0].toString();
 
875
        String scode= buffers[1].toString();
 
876
        IFile hfile = importFile("testBug190730.h", hcode); 
 
877
        IFile file = importFile("testBug190730.cpp", scode); 
 
878
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
879
        IASTNode decl;
 
880
        int offset0, offset1;
 
881
        
 
882
        offset0 = hcode.indexOf("func");
 
883
        offset1 = scode.indexOf("func");
 
884
        decl = testF3(hfile, offset0);
 
885
        assertNode("func", offset1, decl);
 
886
        decl = testF3(file, offset1);
 
887
        assertNode("func", offset0, decl);        
 
888
    }
 
889
    
 
890
    // typedef enum {
 
891
    //    int eitem
 
892
    // } userEnum;
 
893
    // void func(userEnum t);
 
894
 
 
895
        // #include "testBug190730_2.h"
 
896
    // void func(userEnum t) {
 
897
    // }
 
898
    public void testFuncWithTypedefForAnonymousEnum_190730() throws Exception {
 
899
        StringBuffer[] buffers= getContents(2);
 
900
        String hcode= buffers[0].toString();
 
901
        String scode= buffers[1].toString();
 
902
        IFile hfile = importFile("testBug190730_2.h", hcode); 
 
903
        IFile file = importFile("testBug190730_2.cpp", scode); 
 
904
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
905
        IASTNode decl;
 
906
        int offset0, offset1;
 
907
        
 
908
        offset0 = hcode.indexOf("func");
 
909
        offset1 = scode.indexOf("func");
 
910
        decl = testF3(hfile, offset0);
 
911
        assertNode("func", offset1, decl);
 
912
        decl = testF3(file, offset1);
 
913
        assertNode("func", offset0, decl);        
 
914
    }
 
915
    
 
916
    //    #define MY_MACRO 0xDEADBEEF
 
917
    //    #define MY_FUNC() 00
 
918
    //    #define MY_PAR( aRef );
 
919
 
 
920
        //  #include "macrodef.h"
 
921
        //      int basictest(void){
 
922
        //         int tester = MY_MACRO;  //OK: F3 works
 
923
        //         int xx= MY_FUNC();
 
924
    //     MY_PAR(0);
 
925
    //  }
 
926
    public void testMacroNavigation() throws Exception {
 
927
        StringBuffer[] buffers= getContents(2);
 
928
        String hcode= buffers[0].toString();
 
929
        String scode= buffers[1].toString();
 
930
        IFile hfile = importFile("macrodef.h", hcode); 
 
931
        IFile file = importFile("macronavi.cpp", scode); 
 
932
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
933
        IASTNode decl;
 
934
        int offset0, offset1;
 
935
        
 
936
        offset0 = hcode.indexOf("MY_MACRO");
 
937
        offset1 = scode.indexOf("MY_MACRO");
 
938
        decl = testF3(file, offset1);
 
939
        assertNode("MY_MACRO", offset0, decl);
 
940
        
 
941
        offset0 = hcode.indexOf("MY_FUNC");
 
942
        offset1 = scode.indexOf("MY_FUNC");
 
943
        decl = testF3(file, offset1);
 
944
        assertNode("MY_FUNC", offset0, decl);
 
945
 
 
946
        offset0 = hcode.indexOf("MY_PAR");
 
947
        offset1 = scode.indexOf("MY_PAR");
 
948
        decl = testF3(file, offset1);
 
949
        assertNode("MY_PAR", offset0, decl);
 
950
    }
 
951
    
 
952
    //  #define MY_MACRO 0xDEADBEEF
 
953
    //  #define MY_PAR( aRef ) aRef;
 
954
    //  int gvar;
 
955
 
 
956
        //  #include "macrodef.h"
 
957
        //      int basictest(void){
 
958
        //         int tester = MY_PAR(MY_MACRO);
 
959
    //     tester= MY_PAR(gvar);
 
960
    //  }
 
961
    public void testMacroNavigation_Bug208300() throws Exception {
 
962
        StringBuffer[] buffers= getContents(2);
 
963
        String hcode= buffers[0].toString();
 
964
        String scode= buffers[1].toString();
 
965
        IFile hfile = importFile("macrodef.h", hcode); 
 
966
        IFile file = importFile("macronavi.cpp", scode); 
 
967
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
968
        IASTNode decl;
 
969
        int offset0, offset1;
 
970
        
 
971
        offset0 = hcode.indexOf("MY_PAR");
 
972
        offset1 = scode.indexOf("MY_PAR");
 
973
        decl = testF3(file, offset1);
 
974
        assertNode("MY_PAR", offset0, decl);
 
975
 
 
976
        offset0 = hcode.indexOf("MY_MACRO");
 
977
        offset1 = scode.indexOf("MY_MACRO");
 
978
        decl = testF3(file, offset1);
 
979
        assertNode("MY_MACRO", offset0, decl);
 
980
 
 
981
        offset0 = hcode.indexOf("gvar");
 
982
        offset1 = scode.indexOf("gvar");
 
983
        decl = testF3(file, offset1);
 
984
        assertNode("gvar", offset0, decl);
 
985
    }
 
986
    
 
987
    //  int wurscht;
 
988
 
 
989
        //  #include "aheader.h"
 
990
    public void testIncludeNavigation() throws Exception {
 
991
        StringBuffer[] buffers= getContents(2);
 
992
        String hcode= buffers[0].toString();
 
993
        String scode= buffers[1].toString();
 
994
        IFile hfile = importFile("aheader.h", hcode); 
 
995
        IFile file = importFile("includenavi.cpp", scode); 
 
996
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
997
        IASTNode decl;
 
998
        int offset0, offset1;
 
999
 
 
1000
        offset1 = scode.indexOf("aheader.h");
 
1001
        testF3(file, offset1);
 
1002
        IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); 
 
1003
        IEditorInput input = part.getEditorInput();
 
1004
        assertEquals("aheader.h", ((FileEditorInput) input).getFile().getName());
 
1005
    }
 
1006
    
 
1007
        // void cfunc();
 
1008
        // void cxcpp() {
 
1009
        //    cfunc();
 
1010
        // }
 
1011
        
 
1012
        // extern "C" void cxcpp();
 
1013
        // void cppfunc() {
 
1014
        //    cxcpp();
 
1015
        // }
 
1016
    public void testNavigationCppCallsC() throws Exception {
 
1017
        StringBuffer[] buffers= getContents(2);
 
1018
        String ccode= buffers[0].toString();
 
1019
        String scode= buffers[1].toString();
 
1020
        IFile cfile = importFile("s.c", ccode); 
 
1021
        IFile cppfile = importFile("s.cpp", scode); 
 
1022
        waitUntilFileIsIndexed(index, cppfile, MAX_WAIT_TIME);
 
1023
        IASTNode decl;
 
1024
        int offset1, offset2;
 
1025
 
 
1026
        offset1 = scode.indexOf("cxcpp");
 
1027
        offset2 = scode.indexOf("cxcpp", offset1 + 1);
 
1028
        testF3(cppfile, offset1);
 
1029
        IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); 
 
1030
        IEditorInput input = part.getEditorInput();
 
1031
        assertEquals("s.c", ((FileEditorInput) input).getFile().getName());
 
1032
 
 
1033
        testF3(cppfile, offset2);
 
1034
        part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); 
 
1035
        input = part.getEditorInput();
 
1036
        assertEquals("s.c", ((FileEditorInput) input).getFile().getName());
 
1037
 
 
1038
        offset1 = ccode.indexOf("cxcpp");
 
1039
        testF3(cfile, offset1);
 
1040
        part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); 
 
1041
        input = part.getEditorInput();
 
1042
        assertEquals("s.cpp", ((FileEditorInput) input).getFile().getName());
 
1043
    }
 
1044
 
 
1045
    // void cxcpp();
 
1046
        // void cfunc() {
 
1047
        //    cxcpp();
 
1048
        // }
 
1049
        
 
1050
        // void cppfunc() {}
 
1051
        // extern "C" {void cxcpp() {
 
1052
        //    cppfunc();
 
1053
        // }}
 
1054
    public void testNavigationCCallsCpp() throws Exception {
 
1055
        StringBuffer[] buffers= getContents(2);
 
1056
        String ccode= buffers[0].toString();
 
1057
        String scode= buffers[1].toString();
 
1058
        IFile cfile = importFile("s.c", ccode); 
 
1059
        IFile cppfile = importFile("s.cpp", scode); 
 
1060
        waitUntilFileIsIndexed(index, cppfile, MAX_WAIT_TIME);
 
1061
        IASTNode decl;
 
1062
        int offset1, offset2;
 
1063
 
 
1064
        offset1 = ccode.indexOf("cxcpp");
 
1065
        offset2 = ccode.indexOf("cxcpp", offset1 + 1);
 
1066
        testF3(cfile, offset1);
 
1067
        IEditorPart part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); 
 
1068
        IEditorInput input = part.getEditorInput();
 
1069
        assertEquals("s.cpp", ((FileEditorInput) input).getFile().getName());
 
1070
 
 
1071
        testF3(cfile, offset2);
 
1072
        part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); 
 
1073
        input = part.getEditorInput();
 
1074
        assertEquals("s.cpp", ((FileEditorInput) input).getFile().getName());
 
1075
 
 
1076
        offset1 = scode.indexOf("cxcpp");
 
1077
        testF3(cppfile, offset1);
 
1078
        part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor(); 
 
1079
        input = part.getEditorInput();
 
1080
        assertEquals("s.c", ((FileEditorInput) input).getFile().getName());
 
1081
    }
 
1082
    
 
1083
    //    #define ADD_TEXT(txt1,txt2) txt1" "txt2 
 
1084
    //    #define ADD(a,b) (a + b)
 
1085
    //    void main(void) {
 
1086
    //    #if defined(ADD_TEXT) && defined(ADD)
 
1087
    //    #endif
 
1088
    //    }
 
1089
    public void testNavigationInDefinedExpression_215906() throws Exception {
 
1090
        StringBuffer[] buffers= getContents(1);
 
1091
        String code= buffers[0].toString();
 
1092
        IFile file = importFile("s.cpp", code); 
 
1093
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
1094
        IASTNode decl;
 
1095
        int offset1, offset2;
 
1096
 
 
1097
        offset1 = code.indexOf("ADD_TEXT");
 
1098
        offset2 = code.indexOf("ADD_TEXT", offset1 + 1);
 
1099
        decl= testF3(file, offset2);
 
1100
        assertNode("ADD_TEXT", offset1, decl);
 
1101
        
 
1102
        offset1 = code.indexOf("ADD", offset1 + 1);
 
1103
        offset2 = code.indexOf("ADD", offset2 + 1);
 
1104
        decl= testF3(file, offset2);
 
1105
        assertNode("ADD", offset1, decl);
 
1106
    }
 
1107
    
 
1108
        //  struct X {
 
1109
        //              int operator +(X);
 
1110
    //      int operator [](int);
 
1111
        //              ~X();
 
1112
        //      };
 
1113
        //
 
1114
        //      int test(X x) {
 
1115
        //              x + x;
 
1116
        //              x[6];
 
1117
        //              X* xx = new X();
 
1118
        //              delete xx;
 
1119
        //      }    
 
1120
    public void testNavigationToImplicitNames() throws Exception {
 
1121
        StringBuffer[] buffers= getContents(1);
 
1122
        String code= buffers[0].toString();
 
1123
        IFile file = importFile("in.cpp", code); 
 
1124
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
1125
        
 
1126
        int offset1 = code.indexOf("operator +");
 
1127
        int offset2 = code.indexOf("+ x;");
 
1128
        IASTNode decl = testF3(file, offset2);
 
1129
        assertNode("operator +", offset1, decl);
 
1130
        decl = testF3(file, offset2 + 1);
 
1131
        assertNode("operator +", offset1, decl);
 
1132
        
 
1133
        offset1 = code.indexOf("operator []");
 
1134
        offset2 = code.indexOf("[6];");
 
1135
        decl = testF3(file, offset2 + 1);
 
1136
        assertNode("operator []", offset1, decl);
 
1137
        offset2 = code.indexOf("];");
 
1138
        decl = testF3(file, offset2);
 
1139
        assertNode("operator []", offset1, decl);
 
1140
        decl = testF3(file, offset2 + 1);
 
1141
        assertNode("operator []", offset1, decl);
 
1142
        
 
1143
        offset1 = code.indexOf("~X()");
 
1144
        offset2 = code.indexOf("delete");
 
1145
        decl = testF3(file, offset2);
 
1146
        assertNode("~X", offset1, decl);
 
1147
    }
 
1148
 
 
1149
        // template<typename T>
 
1150
        // class C {
 
1151
        // public:
 
1152
        //    T operator+(int);
 
1153
        // };
 
1154
 
 
1155
        // void main() {
 
1156
        //   C<char> a;
 
1157
        //   a + 2;
 
1158
        // }
 
1159
        public void testBug272744() throws Exception {
 
1160
                StringBuffer[] buffers= getContents(2);
 
1161
        String hcode= buffers[0].toString();
 
1162
        String scode= buffers[1].toString();
 
1163
        IFile hfile = importFile("test.h", hcode); 
 
1164
        IFile file = importFile("test.cpp", scode);
 
1165
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
1166
        
 
1167
        int hoffset= hcode.indexOf("operator+"); 
 
1168
        int soffset = scode.indexOf("+"); 
 
1169
        IASTNode def = testF3(file, soffset + 1);
 
1170
        assertTrue(def instanceof IASTName);
 
1171
        assertEquals("operator +", ((IASTName) def).toString());
 
1172
        assertEquals(hoffset, ((ASTNode) def).getOffset());
 
1173
        assertEquals(9, ((ASTNode) def).getLength());
 
1174
        }
 
1175
        
 
1176
    //    void  test(ABC* p);
 
1177
    //    void  test(ABC* q) {}
 
1178
    //    void call_test(){
 
1179
    //          test(0);
 
1180
    //    }
 
1181
    public void testBug305487() throws Exception {
 
1182
        String code = getAboveComment();
 
1183
        IFile file = importFile("testBug305487.cpp", code);
 
1184
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
1185
        
 
1186
        int offset= code.indexOf("test(0)"); 
 
1187
        IASTNode def = testF3(file, offset + 1);
 
1188
        assertTrue(def instanceof IASTName);
 
1189
    }
 
1190
 
 
1191
        //      struct A {
 
1192
        //        A();
 
1193
        //        A(int x);
 
1194
        //      };
 
1195
 
 
1196
    //  #include "testImplicitConstructorCall_248855.h"
 
1197
        //      void func() {
 
1198
        //        A a1;
 
1199
        //        A a2(5);
 
1200
        //      }
 
1201
        //      struct B {
 
1202
        //        B() : a3(1) {}
 
1203
        //        A a3;
 
1204
        //      };
 
1205
        public void testImplicitConstructorCall_248855() throws Exception {
 
1206
        StringBuffer[] buffers= getContents(2);
 
1207
        String hcode= buffers[0].toString();
 
1208
        String scode= buffers[1].toString();
 
1209
        IFile hfile = importFile("testImplicitConstructorCall_248855.h", hcode); 
 
1210
        IFile file = importFile("testImplicitConstructorCall_248855.cpp", scode); 
 
1211
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
1212
        
 
1213
        IASTNode target = testF3(file, scode.indexOf("a1"));
 
1214
        assertTrue(target instanceof IASTName);
 
1215
        assertEquals("A", ((IASTName) target).toString());
 
1216
        assertEquals(hcode.indexOf("A()"), target.getFileLocation().getNodeOffset());
 
1217
        assertEquals("A".length(), ((ASTNode) target).getLength());
 
1218
 
 
1219
        target = testF3(file, scode.indexOf("a2"));
 
1220
        assertTrue(target instanceof IASTName);
 
1221
        assertEquals("A", ((IASTName) target).toString());
 
1222
        assertEquals(hcode.indexOf("A(int x)"), target.getFileLocation().getNodeOffset());
 
1223
        assertEquals("A".length(), ((ASTNode) target).getLength());
 
1224
 
 
1225
                try {
 
1226
                target = testF3(file, scode.indexOf("a3"));
 
1227
                        fail("Didn't expect navigation to succeed due to multiple choices: B::a3, A::A(int x).");
 
1228
                } catch (RuntimeException e) {
 
1229
                        assertEquals("ambiguous input: 2", e.getMessage());
 
1230
                }
 
1231
        }
 
1232
 
 
1233
        //      #define MYMACRO
 
1234
 
 
1235
        //      #undef MYMACRO
 
1236
        public void testUndef_312399() throws Exception {
 
1237
        StringBuffer[] buffers= getContents(2);
 
1238
        String hcode= buffers[0].toString();
 
1239
        String scode= buffers[1].toString();
 
1240
        IFile hfile = importFile("testUndef_312399.h", hcode); 
 
1241
        IFile file = importFile("testUndef_312399.cpp", scode); 
 
1242
        waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
 
1243
        
 
1244
        IASTNode target = testF3(file, scode.indexOf("MYMACRO"));
 
1245
        assertTrue(target instanceof IASTName);
 
1246
        assertEquals("MYMACRO", ((IASTName) target).toString());
 
1247
        assertEquals(hcode.indexOf("MYMACRO"), target.getFileLocation().getNodeOffset());
 
1248
        assertEquals("MYMACRO".length(), ((ASTNode) target).getLength());
 
1249
        }
 
1250
}