From cd284ca6ec787a9d394dc976606f837a515f2339 Mon Sep 17 00:00:00 2001 From: Doug Schaefer Date: Thu, 20 Apr 2006 22:57:14 +0000 Subject: [PATCH] Fix 137821, header files were returning true as valid source unit names. This causes certain builders to try and build them. --- .../model/tests/TranslationUnitTests.java | 324 ++++++++++-------- .../org/eclipse/cdt/core/model/CoreModel.java | 4 + 2 files changed, 177 insertions(+), 151 deletions(-) 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 0fce00bce7d..c55b310c00c 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 @@ -17,6 +17,7 @@ import java.util.Stack; import junit.framework.TestSuite; import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.IInclude; import org.eclipse.cdt.core.model.ITranslationUnit; @@ -24,160 +25,173 @@ import org.eclipse.cdt.core.testplugin.CProjectHelper; import org.eclipse.cdt.core.testplugin.util.ExpectedStrings; import org.eclipse.core.runtime.CoreException; - - /** * @author Peter Graves - * - * This file contains a set of generic tests for the core C model's TranslationUnit - * class. There is nothing exotic here, mostly just sanity type tests - * + * + * This file contains a set of generic tests for the core C model's + * TranslationUnit class. There is nothing exotic here, mostly just sanity type + * tests + * */ public class TranslationUnitTests extends TranslationUnitBaseTest { - /* This is a list of elements in the test .c file. It will be used - * in a number of places in the tests - */ - String[] expectedStringList= {"stdio.h", "unistd.h", "func2p", - "globalvar", "myenum", "mystruct", "mystruct_t", "myunion", "mytype", - "func1", "func2", "main", "func3" }; - int[] expectedLines={ 12,14,17,20,23,28,32,35,42,47,53,58,65,70}; - /* This is a list of that the types of the above list of elements is - * expected to be. - */ - int[] expectedTypes= { ICElement.C_INCLUDE, ICElement.C_INCLUDE, - ICElement.C_FUNCTION_DECLARATION, ICElement.C_VARIABLE, - ICElement.C_ENUMERATION, ICElement.C_STRUCT, ICElement.C_TYPEDEF, - ICElement.C_UNION, ICElement.C_TYPEDEF, ICElement.C_FUNCTION, - ICElement.C_FUNCTION, ICElement.C_FUNCTION,ICElement.C_FUNCTION, - ICElement.C_FUNCTION}; - + /* + * This is a list of elements in the test .c file. It will be used in a + * number of places in the tests + */ + String[] expectedStringList = { "stdio.h", "unistd.h", "func2p", + "globalvar", "myenum", "mystruct", "mystruct_t", "myunion", + "mytype", "func1", "func2", "main", "func3" }; - /** - * Constructor for TranslationUnitTests - * @param name - */ - public TranslationUnitTests(String name) { - super(name); - } - - public static TestSuite suite() { - TestSuite suite= new TestSuite(TranslationUnitTests.class.getName()); + int[] expectedLines = { 12, 14, 17, 20, 23, 28, 32, 35, 42, 47, 53, 58, 65, + 70 }; + + /* + * This is a list of that the types of the above list of elements is + * expected to be. + */ + int[] expectedTypes = { ICElement.C_INCLUDE, ICElement.C_INCLUDE, + ICElement.C_FUNCTION_DECLARATION, ICElement.C_VARIABLE, + ICElement.C_ENUMERATION, ICElement.C_STRUCT, ICElement.C_TYPEDEF, + ICElement.C_UNION, ICElement.C_TYPEDEF, ICElement.C_FUNCTION, + ICElement.C_FUNCTION, ICElement.C_FUNCTION, ICElement.C_FUNCTION, + ICElement.C_FUNCTION }; + + /** + * Constructor for TranslationUnitTests + * + * @param name + */ + public TranslationUnitTests(String name) { + super(name); + } + + public static TestSuite suite() { + TestSuite suite = new TestSuite(TranslationUnitTests.class.getName()); suite.addTest(new TranslationUnitTests("testIsTranslationUnit")); suite.addTest(new TranslationUnitTests("testGetChildren")); suite.addTest(new TranslationUnitTests("testGetElement")); suite.addTest(new TranslationUnitTests("testBug23478A")); suite.addTest(new TranslationUnitTests("testBug23478B")); - // TODO: suite.addTest(new TranslationUnitTests("testGetElementAtLine")); + suite.addTest(new TranslationUnitTests("testIsValidSourceUnitName")); + // TODO: suite.addTest(new + // TranslationUnitTests("testGetElementAtLine")); return suite; - } - - public static void main (String[] args){ - junit.textui.TestRunner.run(suite()); - } + } + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); + } + /*************************************************************************** + * Simple sanity test to make sure TranslationUnit.isTranslationUnit returns + * true + * + */ + public void testIsTranslationUnit() throws CoreException, + FileNotFoundException { + ITranslationUnit myTranslationUnit; + myTranslationUnit = CProjectHelper.findTranslationUnit(testProject, + "exetest.c"); + assertTrue("A TranslationUnit", myTranslationUnit != null); - /*** - * Simple sanity test to make sure TranslationUnit.isTranslationUnit returns true - * - */ - public void testIsTranslationUnit() throws CoreException,FileNotFoundException { - ITranslationUnit myTranslationUnit; - - myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c"); - assertTrue("A TranslationUnit", myTranslationUnit != null); + } - } + /*************************************************************************** + * Simple sanity tests to make sure TranslationUnit.getChildren seems to + * basicly work + */ + public void testGetChildren() throws CModelException { + ITranslationUnit myTranslationUnit; + ICElement[] elements; + int x; - /*** - * Simple sanity tests to make sure TranslationUnit.getChildren seems to - * basicly work - */ - public void testGetChildren() throws CModelException { - ITranslationUnit myTranslationUnit; - ICElement[] elements; - int x; + ExpectedStrings expectedString = new ExpectedStrings(expectedStringList); - ExpectedStrings expectedString=new ExpectedStrings(expectedStringList); + myTranslationUnit = CProjectHelper.findTranslationUnit(testProject, + "exetest.c"); - myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c"); + if (myTranslationUnit.hasChildren()) { + elements = myTranslationUnit.getChildren(); + for (x = 0; x < elements.length; x++) { + expectedString.foundString(elements[x].getElementName()); + } + } + assertTrue("PR:23603 " + expectedString.getMissingString(), + expectedString.gotAll()); + assertTrue(expectedString.getExtraString(), !expectedString.gotExtra()); - - if (myTranslationUnit.hasChildren()) { - elements=myTranslationUnit.getChildren(); - for (x=0;x