diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java index 560a785e224..d33d356ae7b 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation and others. + * Copyright (c) 2002, 2007 IBM Corporation 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 @@ -131,6 +131,17 @@ public class CModelElementsTests extends TestCase { checkTemplates(namespace); checkArrays(tu); + + checkBug180815(tu); + } + + // https://bugs.eclipse.org/bugs/show_bug.cgi?id=180815 + private void checkBug180815(IParent parent) throws CModelException { + List structs = parent.getChildrenOfType(ICElement.C_STRUCT); + assertEquals(1, structs.size()); + IStructure struct= (IStructure)structs.get(0); + assertEquals("bug180815", struct.getElementName()); + assertEquals(2, struct.getChildren().length); } private void checkInclude(IParent tu) throws CModelException{ @@ -397,11 +408,11 @@ public class CModelElementsTests extends TestCase { // struct no name IStructure struct2; - if (IParent.class.isAssignableFrom(ITypeDef.class)) { + List nsTypeDefs = namespace.getChildrenOfType(ICElement.C_TYPEDEF); + ITypeDef td = (ITypeDef) nsTypeDefs.get(1); + if (td instanceof IParent) { // nested in typedef decl - List nsTypeDefs = namespace.getChildrenOfType(ICElement.C_TYPEDEF); - ITypeDef td2 = (ITypeDef) nsTypeDefs.get(1); - struct2 = (IStructure) td2.getChildren()[0]; + struct2 = (IStructure) ((IParent)td).getChildren()[0]; } else { struct2 = (IStructure) nsStructs.get(1); } @@ -418,7 +429,6 @@ public class CModelElementsTests extends TestCase { fail("field visibility should be public!"); // typedefs - List nsTypeDefs = namespace.getChildrenOfType(ICElement.C_TYPEDEF); ITypeDef td1 = (ITypeDef) nsTypeDefs.get(0); assertEquals(td1.getElementName(), new String ("myStruct")); checkElementOffset(td1); @@ -428,7 +438,7 @@ public class CModelElementsTests extends TestCase { assertEquals(td2.getElementName(), new String ("myTypedef")); checkElementOffset(td2); assertEquals(td2.getTypeName(), new String ("struct")); - checkLineNumbers(td2, 101, 103); + checkLineNumbers(td2, 103, 103); // union List nsUnions = namespace.getChildrenOfType(ICElement.C_UNION); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java index f911d0a4a6e..8a7493d592a 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/StructuralCModelElementsTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2007 IBM Corporation 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 @@ -399,11 +399,11 @@ public class StructuralCModelElementsTests extends TestCase { // struct no name IStructure struct2; - if (IParent.class.isAssignableFrom(ITypeDef.class)) { + List nsTypeDefs = namespace.getChildrenOfType(ICElement.C_TYPEDEF); + ITypeDef td = (ITypeDef) nsTypeDefs.get(1); + if (td instanceof IParent) { // nested in typedef decl - List nsTypeDefs = namespace.getChildrenOfType(ICElement.C_TYPEDEF); - ITypeDef td2 = (ITypeDef) nsTypeDefs.get(1); - struct2 = (IStructure) td2.getChildren()[0]; + struct2 = (IStructure) ((IParent)td).getChildren()[0]; } else { struct2 = (IStructure) nsStructs.get(1); } @@ -420,7 +420,6 @@ public class StructuralCModelElementsTests extends TestCase { fail("field visibility should be public!"); //$NON-NLS-1$ // typedefs - List nsTypeDefs = namespace.getChildrenOfType(ICElement.C_TYPEDEF); ITypeDef td1 = (ITypeDef) nsTypeDefs.get(0); assertEquals(td1.getElementName(), new String ("myStruct")); //$NON-NLS-1$ checkElementOffset(td1); @@ -430,7 +429,7 @@ public class StructuralCModelElementsTests extends TestCase { assertEquals(td2.getElementName(), new String ("myTypedef")); //$NON-NLS-1$ checkElementOffset(td2); assertEquals(td2.getTypeName(), new String ("struct")); //$NON-NLS-1$ - checkLineNumbers(td2, 101, 103); + checkLineNumbers(td2, 103, 103); // union List nsUnions = namespace.getChildrenOfType(ICElement.C_UNION); diff --git a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java index 7b56ae0f5d4..b61890d21b2 100644 --- a/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java +++ b/core/org.eclipse.cdt.core.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2006 QNX Software Systems and others. + * Copyright (c) 2000, 2007 QNX Software Systems 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 @@ -37,7 +37,7 @@ public class TranslationUnitTests extends TranslationUnitBaseTest { * number of places in the tests */ String[] expectedStringList = { "stdio.h", "unistd.h", "func2p", - "globalvar", "myenum", "mystruct_t", "myunion", + "globalvar", "myenum", "mystruct_t", "mystruct", "myunion", "mytype", "func1", "func2", "main", "func3" }; int[] expectedLines = { 12, 14, 17, 20, 23, 28, 32, 35, 42, 47, 53, 58, 65, diff --git a/core/org.eclipse.cdt.core.tests/resources/cfiles/CModelElementsTestStart.h b/core/org.eclipse.cdt.core.tests/resources/cfiles/CModelElementsTestStart.h index f28ad072044..45bfd1fb15e 100644 --- a/core/org.eclipse.cdt.core.tests/resources/cfiles/CModelElementsTestStart.h +++ b/core/org.eclipse.cdt.core.tests/resources/cfiles/CModelElementsTestStart.h @@ -134,5 +134,8 @@ namespace MyPackage int main(int argc, char * argv[]) { } - +// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180815 +struct bug180815 { + int i,j; +} bug180815_var0, bug180815_var1;