1
/*******************************************************************************
2
* Copyright (c) 2006, 2008 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
*******************************************************************************/
11
package org.eclipse.cdt.ui.tests.callhierarchy;
13
import junit.framework.Test;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.jface.viewers.TreeViewer;
17
import org.eclipse.swt.widgets.Tree;
18
import org.eclipse.swt.widgets.TreeItem;
19
import org.eclipse.ui.IWorkbenchPage;
20
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.cdt.core.CCorePlugin;
24
import org.eclipse.cdt.internal.ui.editor.CEditor;
27
public class CppCallHierarchyTest extends CallHierarchyBaseTest {
29
public CppCallHierarchyTest(String name) {
33
public static Test suite() {
34
return suite(CppCallHierarchyTest.class);
41
// void inline_method() {
43
// inline_method(); // r1
48
// #include "testMethods.h"
49
// void MyClass::method() {
51
// inline_method(); // r2
57
// n->inline_method(); // r3
59
public void testMethods() throws Exception {
60
StringBuffer[] content= getContentsForTest(2);
61
String header= content[0].toString();
62
String source = content[1].toString();
63
IFile headerFile= createFile(getProject(), "testMethods.h", header);
64
IFile sourceFile= createFile(getProject(), "testMethods.cpp", source);
65
waitForIndexer(fIndex, sourceFile, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
67
CEditor editor= openEditor(sourceFile);
68
editor.selectAndReveal(source.indexOf("method"), 2);
69
openCallHierarchy(editor);
70
Tree tree = getCHTreeViewer().getTree();
72
checkTreeNode(tree, 0, "MyClass::method()");
73
checkTreeNode(tree, 0, 0, "func()");
74
checkTreeNode(tree, 0, 1, "MyClass::inline_method()");
75
checkTreeNode(tree, 0, 2, "MyClass::method()");
77
editor.selectAndReveal(source.indexOf("method(); // r2"), 2);
78
openCallHierarchy(editor);
80
checkTreeNode(tree, 0, "MyClass::method()");
81
checkTreeNode(tree, 0, 0, "func()");
82
checkTreeNode(tree, 0, 1, "MyClass::inline_method()");
83
checkTreeNode(tree, 0, 2, "MyClass::method()");
85
editor.selectAndReveal(source.indexOf("inline_method(); // r2"), 2);
86
openCallHierarchy(editor);
87
checkTreeNode(tree, 0, "MyClass::inline_method()");
88
checkTreeNode(tree, 0, 0, "func()");
89
checkTreeNode(tree, 0, 1, "MyClass::inline_method()");
90
checkTreeNode(tree, 0, 2, "MyClass::method()");
92
editor.selectAndReveal(source.indexOf("method(); // r3"), 2);
93
openCallHierarchy(editor);
94
checkTreeNode(tree, 0, "MyClass::method()");
95
checkTreeNode(tree, 0, 0, "func()");
96
checkTreeNode(tree, 0, 1, "MyClass::inline_method()");
97
checkTreeNode(tree, 0, 2, "MyClass::method()");
99
editor.selectAndReveal(source.indexOf("inline_method(); // r3"), 2);
100
openCallHierarchy(editor);
101
checkTreeNode(tree, 0, "MyClass::inline_method()");
102
checkTreeNode(tree, 0, 0, "func()");
103
checkTreeNode(tree, 0, 1, "MyClass::inline_method()");
104
checkTreeNode(tree, 0, 2, "MyClass::method()");
116
// // testMethods1.cpp
117
// #include "testMethods.h"
118
// void MyClass::method1() {
121
// void MyClass::method3() {
124
// // testMethods2.cpp
125
// #include "testMethods.h"
126
// void MyClass::method2() {
129
public void testMethodsInMultipleFiles() throws Exception {
130
StringBuffer[] content= getContentsForTest(3);
131
String header= content[0].toString();
132
String source1 = content[1].toString();
133
String source2 = content[2].toString();
134
IFile headerFile= createFile(getProject(), "testMethods.h", header);
135
IFile sourceFile1= createFile(getProject(), "testMethods1.cpp", source1);
136
IFile sourceFile2= createFile(getProject(), "testMethods2.cpp", source2);
138
CEditor editor= openEditor(sourceFile1);
139
waitForIndexer(fIndex, sourceFile2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
141
editor.selectAndReveal(source1.indexOf("method3"), 2);
142
openCallHierarchy(editor);
143
TreeViewer tv = getCHTreeViewer();
145
checkTreeNode(tv.getTree(), 0, "MyClass::method3()");
146
TreeItem item= checkTreeNode(tv.getTree(), 0, 0, "MyClass::method2()");
147
checkTreeNode(tv.getTree(), 0, 1, null);
148
tv.setExpandedState(item.getData(), true);
149
TreeItem nextItem = checkTreeNode(item, 0, "MyClass::method1()");
150
checkTreeNode(item, 1, null); item= nextItem;
151
tv.setExpandedState(item.getData(), true);
152
checkTreeNode(item, 0, null);
163
// // testMethods1.cpp
164
// #include "testMethods.h"
165
// void MyClass::method1() {
168
// void MyClass::method3() {
171
// // testMethods2.cpp
172
// #include "testMethods.h"
173
// void MyClass::method2() {
176
// void MyClass::method1() {
179
public void testMultipleImplsForMethod() throws Exception {
180
StringBuffer[] content= getContentsForTest(3);
181
String header= content[0].toString();
182
String source1 = content[1].toString();
183
String source2 = content[2].toString();
184
IFile headerFile= createFile(getProject(), "testMethods.h", header);
185
IFile sourceFile1= createFile(getProject(), "testMethods1.cpp", source1);
186
IFile sourceFile2= createFile(getProject(), "testMethods2.cpp", source2);
188
waitForIndexer(fIndex, sourceFile2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
190
CEditor editor= openEditor(sourceFile1);
191
editor.selectAndReveal(source1.indexOf("method3"), 2);
192
openCallHierarchy(editor);
193
TreeViewer tv = getCHTreeViewer();
195
TreeItem item= checkTreeNode(tv.getTree(), 0, "MyClass::method3()");
196
TreeItem item0= checkTreeNode(tv.getTree(), 0, 0, "MyClass::method1()");
197
TreeItem item1= checkTreeNode(tv.getTree(), 0, 1, "MyClass::method2()");
198
checkTreeNode(tv.getTree(), 0, 2, null); item= null;
201
tv.setExpandedState(item0.getData(), true);
202
checkTreeNode(item0, 0, null);
205
tv.setExpandedState(item1.getData(), true);
206
TreeItem nextItem= checkTreeNode(item1, 0, "MyClass::method1()");
207
checkTreeNode(item1, 1, null); item1= nextItem;
208
tv.setExpandedState(item1.getData(), true);
209
checkTreeNode(item1, 0, null);
220
// // testMethods1.cpp
221
// #include "testMethods.h"
222
// void MyClass::method1() {
225
// void MyClass::method3() {
228
// // testMethods2.cpp
229
// #include "testMethods.h"
230
// void MyClass::method1() {
233
// void MyClass::method2() {
239
public void testReverseMultipleImplsForMethod() throws Exception {
240
StringBuffer[] content= getContentsForTest(3);
241
String header= content[0].toString();
242
String source1 = content[1].toString();
243
String source2 = content[2].toString();
244
IFile headerFile= createFile(getProject(), "testMethods.h", header);
245
IFile sourceFile1= createFile(getProject(), "testMethods1.cpp", source1);
246
IFile sourceFile2= createFile(getProject(), "testMethods2.cpp", source2);
248
CEditor editor= openEditor(sourceFile2);
249
waitForIndexer(fIndex, sourceFile2, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
251
editor.selectAndReveal(source2.indexOf("main"), 2);
252
openCallHierarchy(editor, false);
253
TreeViewer tv = getCHTreeViewer();
255
TreeItem item= checkTreeNode(tv.getTree(), 0, "main()");
256
TreeItem nextItem= checkTreeNode(item, 0, "MyClass::method1()");
257
checkTreeNode(item, 1, null); item= nextItem;
258
tv.setExpandedState(item.getData(), true);
260
TreeItem item0= checkTreeNode(item, 0, "MyClass::method1()");
261
TreeItem item1= checkTreeNode(item, 1, "MyClass::method1()");
262
checkTreeNode(item, 2, null); item= null;
266
tv.setExpandedState(item0.getData(), true);
267
nextItem= checkTreeNode(item0, 0, "MyClass::method2()");
269
catch (Throwable e) {
270
TreeItem tmp= item0; item0= item1; item1= tmp;
272
expandTreeItem(item0);
273
nextItem= checkTreeNode(item0, 0, "MyClass::method2()");
274
checkTreeNode(item0, 1, null); item0= nextItem;
275
tv.setExpandedState(item0.getData(), true);
276
checkTreeNode(item0, 0, null);
279
tv.setExpandedState(item1.getData(), true);
280
nextItem= checkTreeNode(item1, 0, "MyClass::method3()");
281
checkTreeNode(item1, 1, null); item1= nextItem;
282
tv.setExpandedState(item1.getData(), true);
283
checkTreeNode(item1, 0, null);
292
// extern "C" void cxcpp();
296
public void testCPPCallsC() throws Exception {
297
StringBuffer[] content= getContentsForTest(2);
298
String cSource= content[0].toString();
299
String cppSource = content[1].toString();
300
IFile cFile= createFile(getProject(), "s.c", cSource);
301
IFile cppFile= createFile(getProject(), "s.cpp", cppSource);
302
CEditor editor= openEditor(cFile);
303
waitForIndexer(fIndex, cppFile, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
304
CCorePlugin.getIndexManager().joinIndexer(INDEXER_WAIT_TIME, NPM);
306
editor.selectAndReveal(cSource.indexOf("cfunc"), 2);
307
openCallHierarchy(editor);
308
Tree tree = getCHTreeViewer().getTree();
310
checkTreeNode(tree, 0, "cfunc()");
311
TreeItem node= checkTreeNode(tree, 0, 0, "cxcpp()");
312
checkTreeNode(tree, 0, 1, null);
314
expandTreeItem(node);
315
checkTreeNode(node, 0, "cppfunc()");
316
checkTreeNode(node, 1, null);
319
editor= openEditor(cppFile);
320
editor.selectAndReveal(cppSource.indexOf("cppfunc"), 2);
321
openCallHierarchy(editor, false);
322
tree = getCHTreeViewer().getTree();
324
checkTreeNode(tree, 0, "cppfunc()");
325
node= checkTreeNode(tree, 0, 0, "cxcpp()");
326
checkTreeNode(tree, 0, 1, null);
328
expandTreeItem(node);
329
checkTreeNode(node, 0, "cfunc()");
330
checkTreeNode(node, 1, null);
338
// extern "C" {void cxcpp() {
341
public void testCCallsCPP() throws Exception {
342
StringBuffer[] content= getContentsForTest(2);
343
String cSource= content[0].toString();
344
String cppSource = content[1].toString();
345
IFile cFile= createFile(getProject(), "s.c", cSource);
346
IFile cppFile= createFile(getProject(), "s.cpp", cppSource);
347
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
348
CEditor editor= openEditor(cFile);
349
waitForIndexer(fIndex, cppFile, CallHierarchyBaseTest.INDEXER_WAIT_TIME);
350
CCorePlugin.getIndexManager().joinIndexer(INDEXER_WAIT_TIME, NPM);
352
editor.selectAndReveal(cSource.indexOf("cfunc"), 2);
353
openCallHierarchy(editor, false);
354
Tree tree = getCHTreeViewer().getTree();
356
checkTreeNode(tree, 0, "cfunc()");
357
TreeItem node= checkTreeNode(tree, 0, 0, "cxcpp()");
358
checkTreeNode(tree, 0, 1, null);
360
expandTreeItem(node);
361
checkTreeNode(node, 0, "cppfunc()");
362
checkTreeNode(node, 1, null);
365
editor= openEditor(cppFile);
366
editor.selectAndReveal(cppSource.indexOf("cppfunc"), 2);
367
openCallHierarchy(editor, true);
368
tree = getCHTreeViewer().getTree();
370
checkTreeNode(tree, 0, "cppfunc()");
371
node= checkTreeNode(tree, 0, 0, "cxcpp()");
372
checkTreeNode(tree, 0, 1, null);
374
expandTreeItem(node);
375
checkTreeNode(node, 0, "cfunc()");
376
checkTreeNode(node, 1, null);