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
9
* Markus Schorn - initial API and implementation
10
* Sergey Prigogin (Google)
11
*******************************************************************************/
12
package org.eclipse.cdt.ui.tests.text.selection;
14
import java.io.IOException;
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;
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;
34
import org.eclipse.cdt.internal.core.dom.parser.ASTNode;
37
* Test Ctrl_F3/F3 with the DOM Indexer for a C++ project.
39
public abstract class CPPSelectionTestsAnyIndexer extends BaseSelectionTestsIndexer {
40
private static final int MAX_WAIT_TIME = 8000;
42
protected String sourceIndexerID;
43
protected IIndex index;
45
public CPPSelectionTestsAnyIndexer(String name, String indexerID) {
47
sourceIndexerID= indexerID;
51
protected void setUp() throws Exception {
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);
61
CCorePlugin.getIndexManager().setIndexerId(fCProject, sourceIndexerID);
62
index= CCorePlugin.getIndexManager().getIndex(fCProject);
66
protected void tearDown() throws Exception {
68
CProjectHelper.delete(fCProject);
72
private ICProject createProject(String projectName) throws CoreException {
73
ICProject cPrj = CProjectHelper.createCCProject(projectName, "bin", IPDOMManager.ID_NO_INDEXER);
77
protected StringBuffer[] getContents(int sections) throws IOException {
78
return TestSourceReader.getContentsForTest(
79
CTestPlugin.getDefault().getBundle(), "ui", CPPSelectionTestsAnyIndexer.class, getName(), sections);
82
private void assertNode(String name, int offset, IASTNode node) {
84
assertEquals(node.toString(), name);
85
IASTFileLocation loc= node.getFileLocation();
86
assertEquals(loc.getNodeOffset(), offset);
87
assertEquals(loc.getNodeLength(), name.length());
90
protected void waitUntilFileIsIndexed(IIndex index, IFile file, int maxmillis) throws Exception {
91
TestSourceReader.waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
97
// Point(): xCoord(0){}
98
// Point& operator=(const Point &rhs){return *this;}
99
// void* operator new [ ] (unsigned int);
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
113
// =(zero); // line B
114
// p2->operator /* oh yeah */ new // F3 in the middle of "operator"
117
// [ /* sweet */ ] //
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);
129
int offset = scode.indexOf("p2->operator") + 6;
130
IASTNode node = testF3(file, offset);
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);
137
offset = scode.indexOf("p2-> operator") + 11;
138
node = testF3(file, offset);
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);
146
// template <class T>
147
// inline void testTemplate(T& aRef);
152
// #include <stdio.h>
153
// #include <stdlib.h>
156
// puts("Hello World!!!");
159
// testTemplate(testFile);
161
// return EXIT_SUCCESS;
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);
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());
180
// template<typename T>
182
// public: void assign(const T* s) {}
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);
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());
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; };
214
// #include "basicDefinition.h"
216
// extern const int MyConst = 42;
217
// void MyFunc(int a) { cout << a << endl; }
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);
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());
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());
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());
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());
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());
296
// template < class T > class AAA { T _t; };
299
// #include "testBasicTemplateInstance.h"
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);
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());
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());
326
// X(int); // openReferences fails to find the constructor in g()
329
// #include "testBug86829A.h"
333
// X b = f(X(2)); // openDeclarations on X(int) shall find constructor
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);
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());
362
// #include "testBug86829B.h"
365
// int c = X(a); // OK: a.operator X().operator int()
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);
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());
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
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
399
// #include "testCPPSpecDeclsDefs.h"
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
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);
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);
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);
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);
439
offset0= scode.indexOf("x)");
440
decl= testF3(file, offset0);
441
assertNode("x", offset0, decl);
443
offset1= scode.indexOf("x+a");
444
decl= testF3(file, offset1);
445
assertNode("x", offset0, decl);
447
offset0= scode.indexOf("a;");
448
offset1= scode.indexOf("a;}");
449
decl= testF3(file, offset1);
450
assertNode("a", offset0, decl);
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);
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);
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);
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);
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);
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);
500
offset0= hcode.indexOf("X()");
501
decl = testF3(hfile, offset0);
502
assertNode("X", offset0, decl);
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);
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);
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);
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);
536
offset0= hcode.indexOf("N1");
537
decl= testF3(hfile, offset0);
538
assertNode("N1", offset0, decl);
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);
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);
556
// namespace N {int d;} // defines
558
// #include "testBug168533.h"
559
// using N::d; // declares
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);
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);
582
// Overflow(char,double,double);
585
// #include "testBug95225.h"
586
// void f(double x) {
587
// throw Overflow('+',x,3.45e107);
593
// catch(Overflow& oo) {
594
// // handle exceptions of type Overflow here
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);
605
int offset0, offset1;
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);
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);
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);
629
// struct A { }; // implicitly declared A::operator=
631
// B& operator=(const B &);
634
// #include "testBug95202.h"
635
// B& B::operator=(const B& s) {
636
// this->B::operator=(s); // wellformed
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);
647
int offset0, offset1;
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);
659
// #include "testBug101287.h"
660
// int main(int argc, char **argv) {
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);
671
int offset0, offset1;
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);
681
// struct RTBindingEnd
686
// #include "testBug102258.h"
687
// void f(RTBindingEnd & end) {
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);
697
int offset0, offset1;
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);
713
// #include "testBug103323.h"
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);
725
int offset0, offset1;
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);
734
testSimple_Ctrl_G_Selection(file, offset1, 1, 1);
737
// typedef int TestTypeOne;
738
// typedef int TestTypeTwo;
740
// #include "testBug78354.h"
743
// TestTypeOne myFirstLink = 5;
744
// TestTypeTwo mySecondLink = 6;
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);
755
int offset0, offset1;
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);
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);
774
// #include "testBug103697.h"
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);
786
int offset0, offset1;
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);
796
// class __attribute__((visibility("default"))) FooClass
801
// #include "testBug108202.h"
802
// int FooClass::foo() {
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);
813
int offset0, offset1;
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);
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);
846
int offset0, offset1;
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);
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);
867
// void func(usertype t);
869
// #include "testBug190730.h"
870
// void func(usertype t) {
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);
880
int offset0, offset1;
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);
893
// void func(userEnum t);
895
// #include "testBug190730_2.h"
896
// void func(userEnum t) {
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);
906
int offset0, offset1;
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);
916
// #define MY_MACRO 0xDEADBEEF
917
// #define MY_FUNC() 00
918
// #define MY_PAR( aRef );
920
// #include "macrodef.h"
921
// int basictest(void){
922
// int tester = MY_MACRO; //OK: F3 works
923
// int xx= MY_FUNC();
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);
934
int offset0, offset1;
936
offset0 = hcode.indexOf("MY_MACRO");
937
offset1 = scode.indexOf("MY_MACRO");
938
decl = testF3(file, offset1);
939
assertNode("MY_MACRO", offset0, decl);
941
offset0 = hcode.indexOf("MY_FUNC");
942
offset1 = scode.indexOf("MY_FUNC");
943
decl = testF3(file, offset1);
944
assertNode("MY_FUNC", offset0, decl);
946
offset0 = hcode.indexOf("MY_PAR");
947
offset1 = scode.indexOf("MY_PAR");
948
decl = testF3(file, offset1);
949
assertNode("MY_PAR", offset0, decl);
952
// #define MY_MACRO 0xDEADBEEF
953
// #define MY_PAR( aRef ) aRef;
956
// #include "macrodef.h"
957
// int basictest(void){
958
// int tester = MY_PAR(MY_MACRO);
959
// tester= MY_PAR(gvar);
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);
969
int offset0, offset1;
971
offset0 = hcode.indexOf("MY_PAR");
972
offset1 = scode.indexOf("MY_PAR");
973
decl = testF3(file, offset1);
974
assertNode("MY_PAR", offset0, decl);
976
offset0 = hcode.indexOf("MY_MACRO");
977
offset1 = scode.indexOf("MY_MACRO");
978
decl = testF3(file, offset1);
979
assertNode("MY_MACRO", offset0, decl);
981
offset0 = hcode.indexOf("gvar");
982
offset1 = scode.indexOf("gvar");
983
decl = testF3(file, offset1);
984
assertNode("gvar", offset0, decl);
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);
998
int offset0, offset1;
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());
1012
// extern "C" void cxcpp();
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);
1024
int offset1, offset2;
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());
1033
testF3(cppfile, offset2);
1034
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
1035
input = part.getEditorInput();
1036
assertEquals("s.c", ((FileEditorInput) input).getFile().getName());
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());
1050
// void cppfunc() {}
1051
// extern "C" {void cxcpp() {
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);
1062
int offset1, offset2;
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());
1071
testF3(cfile, offset2);
1072
part = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
1073
input = part.getEditorInput();
1074
assertEquals("s.cpp", ((FileEditorInput) input).getFile().getName());
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());
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)
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);
1095
int offset1, offset2;
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);
1102
offset1 = code.indexOf("ADD", offset1 + 1);
1103
offset2 = code.indexOf("ADD", offset2 + 1);
1104
decl= testF3(file, offset2);
1105
assertNode("ADD", offset1, decl);
1109
// int operator +(X);
1110
// int operator [](int);
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);
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);
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);
1143
offset1 = code.indexOf("~X()");
1144
offset2 = code.indexOf("delete");
1145
decl = testF3(file, offset2);
1146
assertNode("~X", offset1, decl);
1149
// template<typename T>
1152
// T operator+(int);
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);
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());
1176
// void test(ABC* p);
1177
// void test(ABC* q) {}
1178
// void call_test(){
1181
public void testBug305487() throws Exception {
1182
String code = getAboveComment();
1183
IFile file = importFile("testBug305487.cpp", code);
1184
waitUntilFileIsIndexed(index, file, MAX_WAIT_TIME);
1186
int offset= code.indexOf("test(0)");
1187
IASTNode def = testF3(file, offset + 1);
1188
assertTrue(def instanceof IASTName);
1196
// #include "testImplicitConstructorCall_248855.h"
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);
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());
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());
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());
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);
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());