From a62ecb4429a589e841ddeb2785dd45cdf0707edd Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Wed, 31 Jan 2007 14:50:11 +0000 Subject: [PATCH] Testcases for the quick type hierarchy and the type hierarchy opened via members --- .../typehierarchy/CTypeHierarchyTest.java | 203 ++++- .../typehierarchy/CppTypeHierarchyTest.java | 411 ++++++++- .../typehierarchy/QuickTypeHierarchyTest.java | 825 ++++++++++++++++++ .../typehierarchy/TypeHierarchyBaseTest.java | 51 +- .../typehierarchy/TypeHierarchyTestSuite.java | 1 + 5 files changed, 1486 insertions(+), 5 deletions(-) create mode 100644 core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/QuickTypeHierarchyTest.java diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CTypeHierarchyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CTypeHierarchyTest.java index 5751a554aec..dc4f0a84e73 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CTypeHierarchyTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CTypeHierarchyTest.java @@ -70,6 +70,43 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest { checkMethodTable(new String[] {"e5", "e6"}); } + // enum E1 {e1, e2}; + // typedef enum E2 {e3, e4} TE2; + // enum E3 {e5, e6}; + // typedef E3 TE3; + public void testEnumCFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "enummem.c", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item; + + editor.selectAndReveal(content.indexOf("e1"), 1); + openTypeHierarchy(editor); + tree = getHierarchyViewer().getTree(); + item= checkTreeNode(tree, 0, "E1"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"e1", "e2"}); + + editor.selectAndReveal(content.indexOf("e3"), 1); + openTypeHierarchy(editor); + tree = getHierarchyViewer().getTree(); + item= checkTreeNode(tree, 0, "E2"); + item= checkTreeNode(item, 0, "TE2"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"e3", "e4"}); + + editor.selectAndReveal(content.indexOf("e6"), 1); + openTypeHierarchy(editor); + tree = getHierarchyViewer().getTree(); + item= checkTreeNode(tree, 0, "E3"); + item= checkTreeNode(item, 0, "TE3"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"e5", "e6"}); + } + // enum E1 {e1, e2}; // typedef enum E2 {e3, e4} TE2; // enum E3 {e5, e6}; @@ -106,7 +143,44 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest { assertEquals(0, item.getItemCount()); checkMethodTable(new String[] {"e5", "e6"}); } - + + // enum E1 {e1, e2}; + // typedef enum E2 {e3, e4} TE2; + // enum E3 {e5, e6}; + // typedef E3 TE3; + public void testEnumCPPFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "enummem.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item; + + editor.selectAndReveal(content.indexOf("e1"), 1); + openTypeHierarchy(editor); + tree = getHierarchyViewer().getTree(); + item= checkTreeNode(tree, 0, "E1"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"e1", "e2"}); + + editor.selectAndReveal(content.indexOf("e4"), 1); + openTypeHierarchy(editor); + tree = getHierarchyViewer().getTree(); + item= checkTreeNode(tree, 0, "E2"); + item= checkTreeNode(item, 0, "TE2"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"e3", "e4"}); + + editor.selectAndReveal(content.indexOf("e6"), 1); + openTypeHierarchy(editor); + tree = getHierarchyViewer().getTree(); + item= checkTreeNode(tree, 0, "E3"); + item= checkTreeNode(item, 0, "TE3"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"e5", "e6"}); + } + // struct S1 { // int a1; // int b1; @@ -186,6 +260,37 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest { checkMethodTable(new String[0]); } + // struct S1 { + // int a1; + // int b1; + // }; + // typedef struct S3 { + // int a3; + // int b3; + // } T3; + public void testStructCFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "structmem.c", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + + editor.selectAndReveal(content.indexOf("a1"), 1); + openTypeHierarchy(editor); + Tree tree = getHierarchyViewer().getTree(); + TreeItem item= checkTreeNode(tree, 0, "S1"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"a1", "b1"}); + + editor.selectAndReveal(content.indexOf("b3"), 1); + openTypeHierarchy(editor); + tree = getHierarchyViewer().getTree(); + item= checkTreeNode(tree, 0, "S3"); + item= checkTreeNode(item, 0, "T3"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"a3", "b3"}); + } + // struct S1 { // int a1; // int b1; @@ -257,6 +362,49 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest { checkMethodTable(new String[0]); } + // struct S1 { + // int a1; + // int b1; + // }; + // typedef struct S2 { + // int a2; + // int b2; + // } S2; + // typedef struct S3 { + // int a3; + // int b3; + // } T3; + public void testStructCPPFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "structmem.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + + editor.selectAndReveal(content.indexOf("a1"), 1); + openTypeHierarchy(editor); + Tree tree = getHierarchyViewer().getTree(); + TreeItem item= checkTreeNode(tree, 0, "S1"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"a1", "b1"}); + + editor.selectAndReveal(content.indexOf("b2"), 1); + openTypeHierarchy(editor); + tree = getHierarchyViewer().getTree(); + item= checkTreeNode(tree, 0, "S2"); + item= checkTreeNode(item, 0, "S2"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"a2", "b2"}); + + editor.selectAndReveal(content.indexOf("a3"), 1); + openTypeHierarchy(editor); + tree = getHierarchyViewer().getTree(); + item= checkTreeNode(tree, 0, "S3"); + item= checkTreeNode(item, 0, "T3"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"a3", "b3"}); + } + // union U1 { // int a1; // char b1; @@ -324,6 +472,25 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest { checkMethodTable(new String[0]); } + // union U1 { + // int a1; + // char b1; + // }; + public void testUnionCFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "unionmem.c", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + + editor.selectAndReveal(content.indexOf("a1"), 1); + openTypeHierarchy(editor); + Tree tree = getHierarchyViewer().getTree(); + TreeItem item= checkTreeNode(tree, 0, "U1"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"a1", "b1"}); + } + // union U1 { // int a1; // int b1; @@ -397,4 +564,38 @@ public class CTypeHierarchyTest extends TypeHierarchyBaseTest { checkMethodTable(new String[0]); } + // union U1 { + // int a1; + // int b1; + // }; + // typedef union U2 { + // int a2; + // int b2; + // } U2; + // typedef union U3 { + // int a3; + // int b3; + // } T3; + public void testUnionCPPFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "unionmem.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + + editor.selectAndReveal(content.indexOf("a1"), 1); + openTypeHierarchy(editor); + Tree tree = getHierarchyViewer().getTree(); + TreeItem item= checkTreeNode(tree, 0, "U1"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"a1", "b1"}); + + editor.selectAndReveal(content.indexOf("b3"), 1); + openTypeHierarchy(editor); + tree = getHierarchyViewer().getTree(); + item= checkTreeNode(tree, 0, "U3"); + item= checkTreeNode(item, 0, "T3"); + assertEquals(0, item.getItemCount()); + checkMethodTable(new String[] {"a3", "b3"}); + } } diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CppTypeHierarchyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CppTypeHierarchyTest.java index a3f3a4a87d9..b06550ea5d9 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CppTypeHierarchyTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/CppTypeHierarchyTest.java @@ -126,7 +126,101 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest { assertEquals(0, item4.getItemCount()); checkMethodTable(new String[] {"field4", "method4()"}); } - + + // class Simple1 { + // public: + // int field1; + // int method1(); + // }; + // class Simple2 : public Simple1 { + // public: + // int field2; + // int method2(); + // }; + // class Simple3 : public Simple2 { + // public: + // int field3; + // int method3(); + // }; + // class Simple4 : public Simple1 { + // public: + // int field4; + // int method4(); + // }; + public void testSimpleInheritanceFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "classmem.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("field1"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + + item1= checkTreeNode(tree, 0, "Simple1"); + assertEquals(1, tree.getItemCount()); + getHierarchyViewer().expandAll(); + + item2= checkTreeNode(item1, 0, "Simple2"); + item4= checkTreeNode(item1, 1, "Simple4"); + assertEquals(2, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "Simple3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + checkMethodTable(new String[] {"field1", "method1()"}); + + + editor.selectAndReveal(content.indexOf("method2"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + item1= checkTreeNode(tree, 0, "Simple1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Simple2"); + assertEquals(1, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "Simple3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + checkMethodTable(new String[] {"field2", "method2()"}); + + + editor.selectAndReveal(content.indexOf("field3"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + item1= checkTreeNode(tree, 0, "Simple1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Simple2"); + assertEquals(1, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "Simple3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + checkMethodTable(new String[] {"field3", "method3()"}); + + + editor.selectAndReveal(content.indexOf("method4"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + item1= checkTreeNode(tree, 0, "Simple1"); + assertEquals(1, tree.getItemCount()); + + item4= checkTreeNode(item1, 0, "Simple4"); + assertEquals(1, item1.getItemCount()); + + assertEquals(0, item4.getItemCount()); + checkMethodTable(new String[] {"field4", "method4()"}); + } + // class Multi1 { // public: // int field1; @@ -238,6 +332,117 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest { checkMethodTable(new String[] {"field4", "method4()"}); } + // class Multi1 { + // public: + // int field1; + // int method1(); + // }; + // class Multi2 { + // public: + // int field2; + // int method2(); + // }; + // class Multi3 : public Multi1, Multi2 { + // public: + // int field3; + // int method3(); + // }; + // class Multi4 : public Multi3 { + // public: + // int field4; + // int method4(); + // }; + public void testMultipleInheritanceFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "multimem.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("field1"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + + item1= checkTreeNode(tree, 0, "Multi1"); + assertEquals(1, tree.getItemCount()); + getHierarchyViewer().expandAll(); + + item3= checkTreeNode(item1, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + + assertEquals(0, item4.getItemCount()); + checkMethodTable(new String[] {"field1", "method1()"}); + + + editor.selectAndReveal(content.indexOf("method2"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + + item2= checkTreeNode(tree, 0, "Multi2"); + assertEquals(1, tree.getItemCount()); + getHierarchyViewer().expandAll(); + + item3= checkTreeNode(item2, 0, "Multi3"); + assertEquals(1, item2.getItemCount()); + + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + + assertEquals(0, item4.getItemCount()); + checkMethodTable(new String[] {"field2", "method2()"}); + + + editor.selectAndReveal(content.indexOf("field3"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + item1= checkTreeNode(tree, 0, "Multi1"); + item2= checkTreeNode(tree, 1, "Multi2"); + assertEquals(2, tree.getItemCount()); + getHierarchyViewer().expandAll(); + + item3= checkTreeNode(item1, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + item3= checkTreeNode(item2, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + checkMethodTable(new String[] {"field3", "method3()"}); + + + editor.selectAndReveal(content.indexOf("method4"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + item1= checkTreeNode(tree, 0, "Multi1"); + item2= checkTreeNode(tree, 1, "Multi2"); + assertEquals(2, tree.getItemCount()); + getHierarchyViewer().expandAll(); + + item3= checkTreeNode(item1, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + item3= checkTreeNode(item2, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + checkMethodTable(new String[] {"field4", "method4()"}); + } + // class Diamond1 { // public: // int field1; @@ -349,6 +554,117 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest { checkMethodTable(new String[] {"field4", "method4()"}); } + // class Diamond1 { + // public: + // int field1; + // int method1(); + // }; + // class Diamond2 : public Diamond1 { + // public: + // int field2; + // int method2(); + // }; + // class Diamond3 : public Diamond1 { + // public: + // int field3; + // int method3(); + // }; + // class Diamond4 : public Diamond2, Diamond3 { + // public: + // int field4; + // int method4(); + // }; + public void testDiamondInheritanceFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "diamondmem.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("field1"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + + item1= checkTreeNode(tree, 0, "Diamond1"); + assertEquals(1, tree.getItemCount()); + getHierarchyViewer().expandAll(); + + item2= checkTreeNode(item1, 0, "Diamond2"); + item3= checkTreeNode(item1, 1, "Diamond3"); + assertEquals(2, item1.getItemCount()); + + item4= checkTreeNode(item2, 0, "Diamond4"); + assertEquals(1, item2.getItemCount()); + assertEquals(0, item4.getItemCount()); + + item4= checkTreeNode(item3, 0, "Diamond4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + checkMethodTable(new String[] {"field1", "method1()"}); + + + editor.selectAndReveal(content.indexOf("method2"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + + item1= checkTreeNode(tree, 0, "Diamond1"); + assertEquals(1, tree.getItemCount()); + getHierarchyViewer().expandAll(); + + item2= checkTreeNode(item1, 0, "Diamond2"); + assertEquals(1, item1.getItemCount()); + + item4= checkTreeNode(item2, 0, "Diamond4"); + assertEquals(1, item2.getItemCount()); + assertEquals(0, item4.getItemCount()); + + checkMethodTable(new String[] {"field2", "method2()"}); + + + editor.selectAndReveal(content.indexOf("field3"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + + item1= checkTreeNode(tree, 0, "Diamond1"); + assertEquals(1, tree.getItemCount()); + getHierarchyViewer().expandAll(); + + item3= checkTreeNode(item1, 0, "Diamond3"); + assertEquals(1, item1.getItemCount()); + + item4= checkTreeNode(item3, 0, "Diamond4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + checkMethodTable(new String[] {"field3", "method3()"}); + + + editor.selectAndReveal(content.indexOf("method4"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + + item1= checkTreeNode(tree, 0, "Diamond1"); + assertEquals(1, tree.getItemCount()); + getHierarchyViewer().expandAll(); + + item2= checkTreeNode(item1, 0, "Diamond2"); + item3= checkTreeNode(item1, 1, "Diamond3"); + assertEquals(2, item1.getItemCount()); + + item4= checkTreeNode(item2, 0, "Diamond4"); + assertEquals(1, item2.getItemCount()); + assertEquals(0, item4.getItemCount()); + + item4= checkTreeNode(item3, 0, "Diamond4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + checkMethodTable(new String[] {"field4", "method4()"}); + } + // class ViaTypedef1 { // public: // int field1; @@ -377,11 +693,11 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest { editor.selectAndReveal(content.indexOf("ViaTypedef1"), 1); openTypeHierarchy(editor); - getHierarchyViewer().expandAll(); tree= getHierarchyViewer().getTree(); item1= checkTreeNode(tree, 0, "ViaTypedef1"); assertEquals(1, tree.getItemCount()); + getHierarchyViewer().expandAll(); item2= checkTreeNode(item1, 0, "ViaTypedef2"); item4= checkTreeNode(item1, 1, "ViaTypedef4"); @@ -440,6 +756,97 @@ public class CppTypeHierarchyTest extends TypeHierarchyBaseTest { checkMethodTable(new String[] {"field4", "method4()"}); } + // class ViaTypedef1 { + // public: + // int field1; + // int method1(); + // }; + // typedef ViaTypedef1 ViaTypedef2; + // + // class ViaTypedef3 : public ViaTypedef2 { + // public: + // int field3; + // int method3(); + // }; + // class ViaTypedef4 : public ViaTypedef1 { + // public: + // int field4; + // int method4(); + // }; + public void testViaTypedefInheritanceFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "viaTypedefmem.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("field1"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + + item1= checkTreeNode(tree, 0, "ViaTypedef1"); + assertEquals(1, tree.getItemCount()); + getHierarchyViewer().expandAll(); + + item2= checkTreeNode(item1, 0, "ViaTypedef2"); + item4= checkTreeNode(item1, 1, "ViaTypedef4"); + assertEquals(2, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "ViaTypedef3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + checkMethodTable(new String[] {"field1", "method1()"}); + + + editor.selectAndReveal(content.indexOf("ViaTypedef2"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + item1= checkTreeNode(tree, 0, "ViaTypedef1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "ViaTypedef2"); + assertEquals(1, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "ViaTypedef3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + checkMethodTable(new String[] {}); + + + editor.selectAndReveal(content.indexOf("field3"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + item1= checkTreeNode(tree, 0, "ViaTypedef1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "ViaTypedef2"); + assertEquals(1, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "ViaTypedef3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + checkMethodTable(new String[] {"field3", "method3()"}); + + + editor.selectAndReveal(content.indexOf("method4"), 1); + openTypeHierarchy(editor); + tree= getHierarchyViewer().getTree(); + item1= checkTreeNode(tree, 0, "ViaTypedef1"); + assertEquals(1, tree.getItemCount()); + + item4= checkTreeNode(item1, 0, "ViaTypedef4"); + assertEquals(1, item1.getItemCount()); + + assertEquals(0, item4.getItemCount()); + checkMethodTable(new String[] {"field4", "method4()"}); + } + // template class SimpleTemplate { // public: // T field1; diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/QuickTypeHierarchyTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/QuickTypeHierarchyTest.java new file mode 100644 index 00000000000..519be2d8b86 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/QuickTypeHierarchyTest.java @@ -0,0 +1,825 @@ +/******************************************************************************* + * Copyright (c) 2007 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.ui.tests.typehierarchy; + +import junit.framework.Test; + +import org.eclipse.core.resources.IFile; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeItem; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; + +import org.eclipse.cdt.internal.ui.editor.CEditor; + + +public class QuickTypeHierarchyTest extends TypeHierarchyBaseTest { + + public QuickTypeHierarchyTest(String name) { + super(name); + } + + public static Test suite() { + return suite(QuickTypeHierarchyTest.class); + } + + // class Simple1 { + // public: + // int field1; + // int method1(); + // }; + // class Simple2 : public Simple1 { + // public: + // int field2; + // int method2(); + // }; + // class Simple3 : public Simple2 { + // public: + // int field3; + // int method3(); + // }; + // class Simple4 : public Simple1 { + // public: + // int field4; + // int method4(); + // }; + public void testSimpleInheritance() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "class.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("Simple1"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "Simple1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Simple2"); + item4= checkTreeNode(item1, 1, "Simple4"); + assertEquals(2, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "Simple3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + editor.selectAndReveal(content.indexOf("Simple2"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "Simple1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Simple2"); + assertEquals(1, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "Simple3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("Simple3"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "Simple1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Simple2"); + assertEquals(1, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "Simple3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("Simple4"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "Simple1"); + assertEquals(1, tree.getItemCount()); + + item4= checkTreeNode(item1, 0, "Simple4"); + assertEquals(1, item1.getItemCount()); + + assertEquals(0, item4.getItemCount()); + + } + + // class Simple1 { + // public: + // int field1; + // int method1(); + // }; + // class Simple2 : public Simple1 { + // public: + // int field2; + // int method2(); + // }; + // class Simple3 : public Simple2 { + // public: + // int field3; + // int method3(); + // }; + // class Simple4 : public Simple1 { + // public: + // int field4; + // int method4(); + // }; + public void testSimpleInheritanceFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "classmem.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("field1"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "Simple1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Simple2"); + item4= checkTreeNode(item1, 1, "Simple4"); + assertEquals(2, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "Simple3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("method2"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "Simple1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Simple2"); + assertEquals(1, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "Simple3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("field3"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "Simple1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Simple2"); + assertEquals(1, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "Simple3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("method4"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "Simple1"); + assertEquals(1, tree.getItemCount()); + + item4= checkTreeNode(item1, 0, "Simple4"); + assertEquals(1, item1.getItemCount()); + + assertEquals(0, item4.getItemCount()); + + } + + // class Multi1 { + // public: + // int field1; + // int method1(); + // }; + // class Multi2 { + // public: + // int field2; + // int method2(); + // }; + // class Multi3 : public Multi1, Multi2 { + // public: + // int field3; + // int method3(); + // }; + // class Multi4 : public Multi3 { + // public: + // int field4; + // int method4(); + // }; + public void testMultipleInheritance() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "multi.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("Multi1"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "Multi1"); + assertEquals(1, tree.getItemCount()); + + item3= checkTreeNode(item1, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + + assertEquals(0, item4.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("Multi2"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item2= checkTreeNode(tree, 0, "Multi2"); + assertEquals(1, tree.getItemCount()); + + item3= checkTreeNode(item2, 0, "Multi3"); + assertEquals(1, item2.getItemCount()); + + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + + assertEquals(0, item4.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("Multi3"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "Multi1"); + item2= checkTreeNode(tree, 1, "Multi2"); + assertEquals(2, tree.getItemCount()); + + item3= checkTreeNode(item1, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + item3= checkTreeNode(item2, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + + + editor.selectAndReveal(content.indexOf("Multi4"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "Multi1"); + item2= checkTreeNode(tree, 1, "Multi2"); + assertEquals(2, tree.getItemCount()); + + item3= checkTreeNode(item1, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + item3= checkTreeNode(item2, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + } + + // class Multi1 { + // public: + // int field1; + // int method1(); + // }; + // class Multi2 { + // public: + // int field2; + // int method2(); + // }; + // class Multi3 : public Multi1, Multi2 { + // public: + // int field3; + // int method3(); + // }; + // class Multi4 : public Multi3 { + // public: + // int field4; + // int method4(); + // }; + public void testMultipleInheritanceFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "multimem.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("field1"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "Multi1"); + assertEquals(1, tree.getItemCount()); + + item3= checkTreeNode(item1, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + + assertEquals(0, item4.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("method2"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item2= checkTreeNode(tree, 0, "Multi2"); + assertEquals(1, tree.getItemCount()); + + item3= checkTreeNode(item2, 0, "Multi3"); + assertEquals(1, item2.getItemCount()); + + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + + assertEquals(0, item4.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("field3"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "Multi1"); + item2= checkTreeNode(tree, 1, "Multi2"); + assertEquals(2, tree.getItemCount()); + + item3= checkTreeNode(item1, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + item3= checkTreeNode(item2, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + + + editor.selectAndReveal(content.indexOf("method4"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "Multi1"); + item2= checkTreeNode(tree, 1, "Multi2"); + assertEquals(2, tree.getItemCount()); + + item3= checkTreeNode(item1, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + item3= checkTreeNode(item2, 0, "Multi3"); + assertEquals(1, item1.getItemCount()); + item4= checkTreeNode(item3, 0, "Multi4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + } + + // class Diamond1 { + // public: + // int field1; + // int method1(); + // }; + // class Diamond2 : public Diamond1 { + // public: + // int field2; + // int method2(); + // }; + // class Diamond3 : public Diamond1 { + // public: + // int field3; + // int method3(); + // }; + // class Diamond4 : public Diamond2, Diamond3 { + // public: + // int field4; + // int method4(); + // }; + public void testDiamondInheritance() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "diamond.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("Diamond1"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "Diamond1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Diamond2"); + item3= checkTreeNode(item1, 1, "Diamond3"); + assertEquals(2, item1.getItemCount()); + + item4= checkTreeNode(item2, 0, "Diamond4"); + assertEquals(1, item2.getItemCount()); + assertEquals(0, item4.getItemCount()); + + item4= checkTreeNode(item3, 0, "Diamond4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + + + editor.selectAndReveal(content.indexOf("Diamond2"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "Diamond1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Diamond2"); + assertEquals(1, item1.getItemCount()); + + item4= checkTreeNode(item2, 0, "Diamond4"); + assertEquals(1, item2.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + + + editor.selectAndReveal(content.indexOf("Diamond3"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "Diamond1"); + assertEquals(1, tree.getItemCount()); + + item3= checkTreeNode(item1, 0, "Diamond3"); + assertEquals(1, item1.getItemCount()); + + item4= checkTreeNode(item3, 0, "Diamond4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + + + editor.selectAndReveal(content.indexOf("Diamond4"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "Diamond1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Diamond2"); + item3= checkTreeNode(item1, 1, "Diamond3"); + assertEquals(2, item1.getItemCount()); + + item4= checkTreeNode(item2, 0, "Diamond4"); + assertEquals(1, item2.getItemCount()); + assertEquals(0, item4.getItemCount()); + + item4= checkTreeNode(item3, 0, "Diamond4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + } + + // class Diamond1 { + // public: + // int field1; + // int method1(); + // }; + // class Diamond2 : public Diamond1 { + // public: + // int field2; + // int method2(); + // }; + // class Diamond3 : public Diamond1 { + // public: + // int field3; + // int method3(); + // }; + // class Diamond4 : public Diamond2, Diamond3 { + // public: + // int field4; + // int method4(); + // }; + public void testDiamondInheritanceFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "diamondmem.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("field1"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "Diamond1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Diamond2"); + item3= checkTreeNode(item1, 1, "Diamond3"); + assertEquals(2, item1.getItemCount()); + + item4= checkTreeNode(item2, 0, "Diamond4"); + assertEquals(1, item2.getItemCount()); + assertEquals(0, item4.getItemCount()); + + item4= checkTreeNode(item3, 0, "Diamond4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + + + editor.selectAndReveal(content.indexOf("method2"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "Diamond1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Diamond2"); + assertEquals(1, item1.getItemCount()); + + item4= checkTreeNode(item2, 0, "Diamond4"); + assertEquals(1, item2.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + + + editor.selectAndReveal(content.indexOf("field3"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "Diamond1"); + assertEquals(1, tree.getItemCount()); + + item3= checkTreeNode(item1, 0, "Diamond3"); + assertEquals(1, item1.getItemCount()); + + item4= checkTreeNode(item3, 0, "Diamond4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + editor.selectAndReveal(content.indexOf("method4"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "Diamond1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "Diamond2"); + item3= checkTreeNode(item1, 1, "Diamond3"); + assertEquals(2, item1.getItemCount()); + + item4= checkTreeNode(item2, 0, "Diamond4"); + assertEquals(1, item2.getItemCount()); + assertEquals(0, item4.getItemCount()); + + item4= checkTreeNode(item3, 0, "Diamond4"); + assertEquals(1, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + } + + // class ViaTypedef1 { + // public: + // int field1; + // int method1(); + // }; + // typedef ViaTypedef1 ViaTypedef2; + // + // class ViaTypedef3 : public ViaTypedef2 { + // public: + // int field3; + // int method3(); + // }; + // class ViaTypedef4 : public ViaTypedef1 { + // public: + // int field4; + // int method4(); + // }; + public void testViaTypedefInheritance() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "viaTypedef.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("ViaTypedef1"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "ViaTypedef1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "ViaTypedef2"); + item4= checkTreeNode(item1, 1, "ViaTypedef4"); + assertEquals(2, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "ViaTypedef3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("ViaTypedef2"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "ViaTypedef1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "ViaTypedef2"); + assertEquals(1, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "ViaTypedef3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("ViaTypedef3"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "ViaTypedef1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "ViaTypedef2"); + assertEquals(1, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "ViaTypedef3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("ViaTypedef4"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "ViaTypedef1"); + assertEquals(1, tree.getItemCount()); + + item4= checkTreeNode(item1, 0, "ViaTypedef4"); + assertEquals(1, item1.getItemCount()); + + assertEquals(0, item4.getItemCount()); + + } + + // class ViaTypedef1 { + // public: + // int field1; + // int method1(); + // }; + // typedef ViaTypedef1 ViaTypedef2; + // + // class ViaTypedef3 : public ViaTypedef2 { + // public: + // int field3; + // int method3(); + // }; + // class ViaTypedef4 : public ViaTypedef1 { + // public: + // int field4; + // int method4(); + // }; + public void testViaTypedefInheritanceFromMember() throws Exception { + String content= getContentsForTest(1)[0].toString(); + IFile file= createFile(getProject(), "viaTypedefmem.cpp", content); + waitForIndexer(fIndex, file, INDEXER_WAIT_TIME); + IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); + CEditor editor= (CEditor) IDE.openEditor(page, file); + Tree tree; + TreeItem item1, item2, item3, item4; + + editor.selectAndReveal(content.indexOf("field1"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + + item1= checkTreeNode(tree, 0, "ViaTypedef1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "ViaTypedef2"); + item4= checkTreeNode(item1, 1, "ViaTypedef4"); + assertEquals(2, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "ViaTypedef3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + assertEquals(0, item4.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("ViaTypedef2"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "ViaTypedef1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "ViaTypedef2"); + assertEquals(1, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "ViaTypedef3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("field3"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "ViaTypedef1"); + assertEquals(1, tree.getItemCount()); + + item2= checkTreeNode(item1, 0, "ViaTypedef2"); + assertEquals(1, item1.getItemCount()); + + item3= checkTreeNode(item2, 0, "ViaTypedef3"); + assertEquals(1, item2.getItemCount()); + + assertEquals(0, item3.getItemCount()); + + + + editor.selectAndReveal(content.indexOf("method4"), 1); + openQuickTypeHierarchy(editor); + tree= getQuickTypeHierarchyViewer(editor); + item1= checkTreeNode(tree, 0, "ViaTypedef1"); + assertEquals(1, tree.getItemCount()); + + item4= checkTreeNode(item1, 0, "ViaTypedef4"); + assertEquals(1, item1.getItemCount()); + + assertEquals(0, item4.getItemCount()); + + } +} diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/TypeHierarchyBaseTest.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/TypeHierarchyBaseTest.java index 32a4dd57855..12eaafec1be 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/TypeHierarchyBaseTest.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/TypeHierarchyBaseTest.java @@ -14,11 +14,17 @@ package org.eclipse.cdt.ui.tests.typehierarchy; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TableViewer; import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.SWT; import org.eclipse.swt.SWTException; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Table; import org.eclipse.swt.widgets.TableItem; +import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Tree; import org.eclipse.swt.widgets.TreeItem; import org.eclipse.ui.IWorkbenchPage; @@ -76,7 +82,8 @@ public class TypeHierarchyBaseTest extends BaseUITestCase { } protected void openTypeHierarchy(CEditor editor) { - TypeHierarchyUI.open(editor, (ITextSelection) editor.getSelectionProvider().getSelection()); + ISelectionProvider selectionProvider = editor.getSelectionProvider(); + TypeHierarchyUI.open(editor, (ITextSelection) selectionProvider.getSelection()); runEventQueue(200); } @@ -95,6 +102,11 @@ public class TypeHierarchyBaseTest extends BaseUITestCase { th.onSetHierarchyKind(mode); } + protected void openQuickTypeHierarchy(CEditor editor) { + editor.getAction("OpenHierarchy").run(); + runEventQueue(200); + } + protected TreeViewer getHierarchyViewer() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); runEventQueue(0); @@ -109,6 +121,27 @@ public class TypeHierarchyBaseTest extends BaseUITestCase { return th.getHiearchyViewer(); } + protected Tree getQuickTypeHierarchyViewer(CEditor editor) { + runEventQueue(0); + THViewPart th= null; + for (int i=0; i<50; i++) { + Control focus= editor.getSite().getShell().getDisplay().getFocusControl(); + if (focus instanceof Text) { + Composite parent= focus.getParent(); + Control[] children= parent.getChildren(); + for (int j = 0; j < children.length; j++) { + Control child = children[j]; + if (child instanceof Tree) { + return (Tree) child; + } + } + } + runEventQueue(10); + } + fail(); + return null; + } + protected TableViewer getMethodViewer() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); runEventQueue(0); @@ -174,7 +207,13 @@ public class TypeHierarchyBaseTest extends BaseUITestCase { for (int i=0; i<40; i++) { item= root.getItem(i1); try { - if (!"...".equals(item.getText())) { + if ("".equals(item.getText())) { + TreeItem parent= item.getParentItem(); + if (!parent.getExpanded()) { + expandTreeItem(parent); + } + } + else if (!"...".equals(item.getText())) { break; } } catch (SWTException e) { @@ -192,6 +231,14 @@ public class TypeHierarchyBaseTest extends BaseUITestCase { return item; } + protected void expandTreeItem(TreeItem item) { + item.setExpanded(true); + Event event = new Event(); + event.item = item; + item.getParent().notifyListeners(SWT.Expand, event); + runEventQueue(0); + } + protected void checkMethodTable(String[] items) { Table table= getMethodViewer().getTable(); TableItem[] titems= table.getItems(); diff --git a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/TypeHierarchyTestSuite.java b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/TypeHierarchyTestSuite.java index 0dfcba18c69..f9a21a0fee5 100644 --- a/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/TypeHierarchyTestSuite.java +++ b/core/org.eclipse.cdt.ui.tests/ui/org/eclipse/cdt/ui/tests/typehierarchy/TypeHierarchyTestSuite.java @@ -23,6 +23,7 @@ public class TypeHierarchyTestSuite extends TestSuite { super("Tests in package org.eclipse.cdt.ui.tests.typehierarchy"); addTest(CTypeHierarchyTest.suite()); addTest(CppTypeHierarchyTest.suite()); + addTest(QuickTypeHierarchyTest.suite()); addTest(TypeHierarchyAcrossProjectsTest.suite()); } }