1
/*******************************************************************************
2
* Copyright (c) 2007, 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.typehierarchy;
13
import junit.framework.Test;
15
import org.eclipse.core.resources.IFile;
16
import org.eclipse.swt.widgets.Tree;
17
import org.eclipse.swt.widgets.TreeItem;
19
import org.eclipse.cdt.internal.ui.editor.CEditor;
22
public class CTypeHierarchyTest extends TypeHierarchyBaseTest {
24
public CTypeHierarchyTest(String name) {
28
public static Test suite() {
29
return suite(CTypeHierarchyTest.class);
33
// typedef enum E2 {e3, e4} TE2;
35
// typedef enum E3 TE3;
36
public void testEnumC() throws Exception {
37
String content= getContentsForTest(1)[0].toString();
38
IFile file= createFile(getProject(), "enum.c", content);
39
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
40
CEditor editor= openEditor(file);
44
editor.selectAndReveal(content.indexOf("E1"), 1);
45
openTypeHierarchy(editor);
46
tree = getHierarchyViewer().getTree();
47
item= checkTreeNode(tree, 0, "E1");
48
assertEquals(0, item.getItemCount());
49
checkMethodTable(new String[] {"e1", "e2"});
51
editor.selectAndReveal(content.indexOf("E2"), 1);
52
openTypeHierarchy(editor);
53
tree = getHierarchyViewer().getTree();
54
item= checkTreeNode(tree, 0, "E2");
55
item= checkTreeNode(item, 0, "TE2");
56
assertEquals(0, item.getItemCount());
57
checkMethodTable(new String[] {"e3", "e4"});
59
editor.selectAndReveal(content.indexOf("E3"), 1);
60
openTypeHierarchy(editor);
61
tree = getHierarchyViewer().getTree();
62
item= checkTreeNode(tree, 0, "E3");
63
item= checkTreeNode(item, 0, "TE3");
64
assertEquals(0, item.getItemCount());
65
checkMethodTable(new String[] {"e5", "e6"});
69
// typedef enum E2 {e3, e4} TE2;
71
// typedef enum E3 TE3;
72
public void testEnumCFromMember() throws Exception {
73
String content= getContentsForTest(1)[0].toString();
74
IFile file= createFile(getProject(), "enummem.c", content);
75
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
76
CEditor editor= openEditor(file);
80
editor.selectAndReveal(content.indexOf("e1"), 1);
81
openTypeHierarchy(editor);
82
tree = getHierarchyViewer().getTree();
83
item= checkTreeNode(tree, 0, "E1");
84
assertEquals(0, item.getItemCount());
85
checkMethodTable(new String[] {"e1", "e2"});
87
editor.selectAndReveal(content.indexOf("e3"), 1);
88
openTypeHierarchy(editor);
89
tree = getHierarchyViewer().getTree();
90
item= checkTreeNode(tree, 0, "E2");
91
item= checkTreeNode(item, 0, "TE2");
92
assertEquals(0, item.getItemCount());
93
checkMethodTable(new String[] {"e3", "e4"});
95
editor.selectAndReveal(content.indexOf("e6"), 1);
96
openTypeHierarchy(editor);
97
tree = getHierarchyViewer().getTree();
98
item= checkTreeNode(tree, 0, "E3");
99
item= checkTreeNode(item, 0, "TE3");
100
assertEquals(0, item.getItemCount());
101
checkMethodTable(new String[] {"e5", "e6"});
105
// typedef enum E2 {e3, e4} TE2;
108
public void testEnumCPP() throws Exception {
109
String content= getContentsForTest(1)[0].toString();
110
IFile file= createFile(getProject(), "enum.cpp", content);
111
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
112
CEditor editor= openEditor(file);
116
editor.selectAndReveal(content.indexOf("E1"), 1);
117
openTypeHierarchy(editor);
118
tree = getHierarchyViewer().getTree();
119
item= checkTreeNode(tree, 0, "E1");
120
assertEquals(0, item.getItemCount());
121
checkMethodTable(new String[] {"e1", "e2"});
123
editor.selectAndReveal(content.indexOf("E2"), 1);
124
openTypeHierarchy(editor);
125
tree = getHierarchyViewer().getTree();
126
item= checkTreeNode(tree, 0, "E2");
127
item= checkTreeNode(item, 0, "TE2");
128
assertEquals(0, item.getItemCount());
129
checkMethodTable(new String[] {"e3", "e4"});
131
editor.selectAndReveal(content.indexOf("E3"), 1);
132
openTypeHierarchy(editor);
133
tree = getHierarchyViewer().getTree();
134
item= checkTreeNode(tree, 0, "E3");
135
item= checkTreeNode(item, 0, "TE3");
136
assertEquals(0, item.getItemCount());
137
checkMethodTable(new String[] {"e5", "e6"});
141
// typedef enum E2 {e3, e4} TE2;
144
public void testEnumCPPFromMember() throws Exception {
145
String content= getContentsForTest(1)[0].toString();
146
IFile file= createFile(getProject(), "enummem.cpp", content);
147
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
148
CEditor editor= openEditor(file);
152
editor.selectAndReveal(content.indexOf("e1"), 1);
153
openTypeHierarchy(editor);
154
tree = getHierarchyViewer().getTree();
155
item= checkTreeNode(tree, 0, "E1");
156
assertEquals(0, item.getItemCount());
157
checkMethodTable(new String[] {"e1", "e2"});
159
editor.selectAndReveal(content.indexOf("e4"), 1);
160
openTypeHierarchy(editor);
161
tree = getHierarchyViewer().getTree();
162
item= checkTreeNode(tree, 0, "E2");
163
item= checkTreeNode(item, 0, "TE2");
164
assertEquals(0, item.getItemCount());
165
checkMethodTable(new String[] {"e3", "e4"});
167
editor.selectAndReveal(content.indexOf("e6"), 1);
168
openTypeHierarchy(editor);
169
tree = getHierarchyViewer().getTree();
170
item= checkTreeNode(tree, 0, "E3");
171
item= checkTreeNode(item, 0, "TE3");
172
assertEquals(0, item.getItemCount());
173
checkMethodTable(new String[] {"e5", "e6"});
180
// typedef struct S2 {
184
// typedef struct S3 {
188
public void testStructC() throws Exception {
189
String content= getContentsForTest(1)[0].toString();
190
IFile file= createFile(getProject(), "struct.c", content);
191
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
192
CEditor editor= openEditor(file);
194
editor.selectAndReveal(content.indexOf("S1"), 1);
195
openTypeHierarchy(editor);
196
Tree tree = getHierarchyViewer().getTree();
197
TreeItem item= checkTreeNode(tree, 0, "S1");
198
assertEquals(0, item.getItemCount());
199
checkMethodTable(new String[] {"a1", "b1"});
201
editor.selectAndReveal(content.indexOf("S2"), 1);
202
openTypeHierarchy(editor);
203
tree = getHierarchyViewer().getTree();
204
item = checkTreeNode(tree, 0, "S2");
205
item= checkTreeNode(item, 0, "S2");
206
assertEquals(0, item.getItemCount());
207
checkMethodTable(new String[] {"a2", "b2"});
209
editor.selectAndReveal(content.indexOf("S2;"), 1);
210
openTypeHierarchy(editor);
211
tree = getHierarchyViewer().getTree();
212
item= checkTreeNode(tree, 0, "S2");
213
item= checkTreeNode(item, 0, "S2");
214
assertEquals(0, item.getItemCount());
215
checkMethodTable(new String[0]);
217
editor.selectAndReveal(content.indexOf("S3"), 1);
218
openTypeHierarchy(editor);
219
tree = getHierarchyViewer().getTree();
220
item= checkTreeNode(tree, 0, "S3");
221
item= checkTreeNode(item, 0, "T3");
222
assertEquals(0, item.getItemCount());
223
checkMethodTable(new String[] {"a3", "b3"});
225
editor.selectAndReveal(content.indexOf("T3"), 1);
226
openTypeHierarchy(editor);
227
tree = getHierarchyViewer().getTree();
228
item= checkTreeNode(tree, 0, "S3");
229
item= checkTreeNode(item, 0, "T3");
230
assertEquals(0, item.getItemCount());
231
checkMethodTable(new String[0]);
238
// typedef struct S3 {
242
public void testStructCFromMember() throws Exception {
243
String content= getContentsForTest(1)[0].toString();
244
IFile file= createFile(getProject(), "structmem.c", content);
245
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
246
CEditor editor= openEditor(file);
248
editor.selectAndReveal(content.indexOf("a1"), 1);
249
openTypeHierarchy(editor);
250
Tree tree = getHierarchyViewer().getTree();
251
TreeItem item= checkTreeNode(tree, 0, "S1");
252
assertEquals(0, item.getItemCount());
253
checkMethodTable(new String[] {"a1", "b1"});
255
editor.selectAndReveal(content.indexOf("b3"), 1);
256
openTypeHierarchy(editor);
257
tree = getHierarchyViewer().getTree();
258
item= checkTreeNode(tree, 0, "S3");
259
item= checkTreeNode(item, 0, "T3");
260
assertEquals(0, item.getItemCount());
261
checkMethodTable(new String[] {"a3", "b3"});
268
// typedef struct S2 {
272
// typedef struct S3 {
276
public void testStructCPP() throws Exception {
277
String content= getContentsForTest(1)[0].toString();
278
IFile file= createFile(getProject(), "struct.cpp", content);
279
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
280
CEditor editor= openEditor(file);
282
editor.selectAndReveal(content.indexOf("S1"), 1);
283
openTypeHierarchy(editor);
284
Tree tree = getHierarchyViewer().getTree();
285
TreeItem item= checkTreeNode(tree, 0, "S1");
286
assertEquals(0, item.getItemCount());
287
checkMethodTable(new String[] {"a1", "b1"});
289
editor.selectAndReveal(content.indexOf("S2"), 1);
290
openTypeHierarchy(editor);
291
tree = getHierarchyViewer().getTree();
292
item= checkTreeNode(tree, 0, "S2");
293
item= checkTreeNode(item, 0, "S2");
294
assertEquals(0, item.getItemCount());
295
checkMethodTable(new String[] {"a2", "b2"});
297
editor.selectAndReveal(content.indexOf("S2;"), 1);
298
openTypeHierarchy(editor);
299
tree = getHierarchyViewer().getTree();
300
item = checkTreeNode(tree, 0, "S2");
301
item= checkTreeNode(item, 0, "S2");
302
assertEquals(0, item.getItemCount());
303
checkMethodTable(new String[0]);
305
editor.selectAndReveal(content.indexOf("S3"), 1);
306
openTypeHierarchy(editor);
307
tree = getHierarchyViewer().getTree();
308
item= checkTreeNode(tree, 0, "S3");
309
item= checkTreeNode(item, 0, "T3");
310
assertEquals(0, item.getItemCount());
311
checkMethodTable(new String[] {"a3", "b3"});
313
editor.selectAndReveal(content.indexOf("T3"), 1);
314
openTypeHierarchy(editor);
315
tree = getHierarchyViewer().getTree();
316
item= checkTreeNode(tree, 0, "S3");
317
item= checkTreeNode(item, 0, "T3");
318
assertEquals(0, item.getItemCount());
319
checkMethodTable(new String[0]);
327
// typedef struct S3 {
331
public void testStructCPPFromMember() throws Exception {
332
String content= getContentsForTest(1)[0].toString();
333
IFile file= createFile(getProject(), "structmem.cpp", content);
334
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
335
CEditor editor= openEditor(file);
337
editor.selectAndReveal(content.indexOf("a1"), 1);
338
openTypeHierarchy(editor);
339
Tree tree = getHierarchyViewer().getTree();
340
TreeItem item= checkTreeNode(tree, 0, "S1");
341
assertEquals(0, item.getItemCount());
342
checkMethodTable(new String[] {"a1", "b1"});
344
editor.selectAndReveal(content.indexOf("a3"), 1);
345
openTypeHierarchy(editor);
346
tree = getHierarchyViewer().getTree();
347
item= checkTreeNode(tree, 0, "S3");
348
item= checkTreeNode(item, 0, "T3");
349
assertEquals(0, item.getItemCount());
350
checkMethodTable(new String[] {"a3", "b3"});
357
// typedef union U2 {
361
// typedef union U3 {
365
public void testUnionC() throws Exception {
366
String content= getContentsForTest(1)[0].toString();
367
IFile file= createFile(getProject(), "union.c", content);
368
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
369
CEditor editor= openEditor(file);
371
editor.selectAndReveal(content.indexOf("U1"), 1);
372
openTypeHierarchy(editor);
373
Tree tree = getHierarchyViewer().getTree();
374
TreeItem item= checkTreeNode(tree, 0, "U1");
375
assertEquals(0, item.getItemCount());
376
checkMethodTable(new String[] {"a1", "b1"});
378
editor.selectAndReveal(content.indexOf("U2"), 1);
379
openTypeHierarchy(editor);
380
tree = getHierarchyViewer().getTree();
381
item = checkTreeNode(tree, 0, "U2");
382
item= checkTreeNode(item, 0, "U2");
383
assertEquals(0, item.getItemCount());
384
checkMethodTable(new String[] {"a2", "b2"});
386
editor.selectAndReveal(content.indexOf("U2;"), 1);
387
openTypeHierarchy(editor);
388
tree = getHierarchyViewer().getTree();
389
item= checkTreeNode(tree, 0, "U2");
390
item= checkTreeNode(item, 0, "U2");
391
assertEquals(0, item.getItemCount());
392
checkMethodTable(new String[0]);
394
editor.selectAndReveal(content.indexOf("U3"), 1);
395
openTypeHierarchy(editor);
396
tree = getHierarchyViewer().getTree();
397
item= checkTreeNode(tree, 0, "U3");
398
item= checkTreeNode(item, 0, "T3");
399
assertEquals(0, item.getItemCount());
400
checkMethodTable(new String[] {"a3", "b3"});
402
editor.selectAndReveal(content.indexOf("T3"), 1);
403
openTypeHierarchy(editor);
404
tree = getHierarchyViewer().getTree();
405
item= checkTreeNode(tree, 0, "U3");
406
item= checkTreeNode(item, 0, "T3");
407
assertEquals(0, item.getItemCount());
408
checkMethodTable(new String[0]);
415
public void testUnionCFromMember() throws Exception {
416
String content= getContentsForTest(1)[0].toString();
417
IFile file= createFile(getProject(), "unionmem.c", content);
418
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
419
CEditor editor= openEditor(file);
421
editor.selectAndReveal(content.indexOf("a1"), 1);
422
openTypeHierarchy(editor);
423
Tree tree = getHierarchyViewer().getTree();
424
TreeItem item= checkTreeNode(tree, 0, "U1");
425
assertEquals(0, item.getItemCount());
426
checkMethodTable(new String[] {"a1", "b1"});
433
// typedef union U2 {
437
// typedef union U3 {
441
public void testUnionCPP() throws Exception {
442
String content= getContentsForTest(1)[0].toString();
443
IFile file= createFile(getProject(), "union.cpp", content);
444
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
445
CEditor editor= openEditor(file);
447
editor.selectAndReveal(content.indexOf("U1"), 1);
448
openTypeHierarchy(editor);
449
Tree tree = getHierarchyViewer().getTree();
450
TreeItem item= checkTreeNode(tree, 0, "U1");
451
assertEquals(0, item.getItemCount());
452
checkMethodTable(new String[] {"a1", "b1"});
454
editor.selectAndReveal(content.indexOf("U2"), 1);
455
openTypeHierarchy(editor);
456
tree = getHierarchyViewer().getTree();
457
item= checkTreeNode(tree, 0, "U2");
458
item= checkTreeNode(item, 0, "U2");
459
assertEquals(0, item.getItemCount());
460
checkMethodTable(new String[] {"a2", "b2"});
463
editor.selectAndReveal(content.indexOf("U2;"), 1);
464
openTypeHierarchy(editor);
465
tree = getHierarchyViewer().getTree();
466
item = checkTreeNode(tree, 0, "U2");
467
item= checkTreeNode(item, 0, "U2");
468
assertEquals(0, item.getItemCount());
469
checkMethodTable(new String[0]);
471
editor.selectAndReveal(content.indexOf("U3"), 1);
472
openTypeHierarchy(editor);
473
tree = getHierarchyViewer().getTree();
474
item= checkTreeNode(tree, 0, "U3");
475
item= checkTreeNode(item, 0, "T3");
476
assertEquals(0, item.getItemCount());
477
checkMethodTable(new String[] {"a3", "b3"});
479
editor.selectAndReveal(content.indexOf("T3"), 1);
480
openTypeHierarchy(editor);
481
tree = getHierarchyViewer().getTree();
482
item= checkTreeNode(tree, 0, "U3");
483
item= checkTreeNode(item, 0, "T3");
484
assertEquals(0, item.getItemCount());
485
checkMethodTable(new String[0]);
492
// typedef union U2 {
496
// typedef union U3 {
500
public void testUnionCPPFromMember() throws Exception {
501
String content= getContentsForTest(1)[0].toString();
502
IFile file= createFile(getProject(), "unionmem.cpp", content);
503
waitForIndexer(fIndex, file, INDEXER_WAIT_TIME);
504
CEditor editor= openEditor(file);
506
editor.selectAndReveal(content.indexOf("a1"), 1);
507
openTypeHierarchy(editor);
508
Tree tree = getHierarchyViewer().getTree();
509
TreeItem item= checkTreeNode(tree, 0, "U1");
510
assertEquals(0, item.getItemCount());
511
checkMethodTable(new String[] {"a1", "b1"});
513
editor.selectAndReveal(content.indexOf("b3"), 1);
514
openTypeHierarchy(editor);
515
tree = getHierarchyViewer().getTree();
516
item= checkTreeNode(tree, 0, "U3");
517
item= checkTreeNode(item, 0, "T3");
518
assertEquals(0, item.getItemCount());
519
checkMethodTable(new String[] {"a3", "b3"});