From 6deffd9b82c0c66de2984b5f0977036b907748c1 Mon Sep 17 00:00:00 2001 From: John Camelon Date: Mon, 26 May 2003 16:59:50 +0000 Subject: [PATCH] Patch for Vlad Hirsl. New test suite added to run all build, model, parser and failure JUnit tests and produce a report. --- core/org.eclipse.cdt.ui.tests/.classpath | 1 + .../CModelElementsFailedTests.java | 116 +++++++++ .../TranslationUnitFailedTests.java | 206 ++++++++++++++++ .../core/model/tests/CModelElementsTests.java | 12 +- .../core/model/tests/ElementDeltaTests.java | 65 +++-- .../model/tests/TranslationUnitTests.java | 7 +- .../core/suite/AutomatedIntegrationSuite.java | 231 ++++++++++++++++++ 7 files changed, 607 insertions(+), 31 deletions(-) create mode 100644 core/org.eclipse.cdt.ui.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java create mode 100644 core/org.eclipse.cdt.ui.tests/failures/org/eclipse/cdt/core/model/failedTests/TranslationUnitFailedTests.java create mode 100644 core/org.eclipse.cdt.ui.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java diff --git a/core/org.eclipse.cdt.ui.tests/.classpath b/core/org.eclipse.cdt.ui.tests/.classpath index f58f7904ab8..f3b72f2ded0 100644 --- a/core/org.eclipse.cdt.ui.tests/.classpath +++ b/core/org.eclipse.cdt.ui.tests/.classpath @@ -22,5 +22,6 @@ + diff --git a/core/org.eclipse.cdt.ui.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java b/core/org.eclipse.cdt.ui.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java new file mode 100644 index 00000000000..ad3e08fc330 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/failures/org/eclipse/cdt/core/model/failedTests/CModelElementsFailedTests.java @@ -0,0 +1,116 @@ +package org.eclipse.cdt.core.model.failedTests; + +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * Rational Software - Initial API and implementation +***********************************************************************/ + +import java.io.FileInputStream; +import java.util.ArrayList; +import java.util.Map; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.CCProjectNature; +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.internal.core.model.TranslationUnit; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.INamespace; +import org.eclipse.cdt.core.model.IStructure; +import org.eclipse.cdt.internal.core.model.CElement; +import org.eclipse.cdt.testplugin.CProjectHelper; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; + + +/** + * @author vhirsl + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class CModelElementsFailedTests extends TestCase { + private ICProject fCProject; + private IFile headerFile; + private NullProgressMonitor monitor; + + public static Test suite() { + TestSuite suite= new TestSuite(); + suite.addTest(new CModelElementsFailedTests("testBug36379")); + return suite; + } + + public CModelElementsFailedTests(String name) { + super(name); + } + + protected void setUp() throws Exception { + monitor = new NullProgressMonitor(); + String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.ui.tests").find(new Path("/")).getFile(); + + fCProject= CProjectHelper.createCProject("TestProject1", "bin"); + headerFile = fCProject.getProject().getFile("CModelElementsTest.h"); + if (!headerFile.exists()) { + try{ + FileInputStream fileIn = new FileInputStream(pluginRoot+ "model/org/eclipse/cdt/core/model/tests/resources/cfiles/CModelElementsTestStart.h"); + headerFile.create(fileIn,false, monitor); + } catch (CoreException e) { + e.printStackTrace(); + } + } + if (!fCProject.getProject().hasNature(CCProjectNature.CC_NATURE_ID)) { + addNatureToProject(fCProject.getProject(), CCProjectNature.CC_NATURE_ID, null); + } + + CCorePlugin.getDefault().setUseNewParser(true); + } + + private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException { + IProjectDescription description = proj.getDescription(); + String[] prevNatures= description.getNatureIds(); + String[] newNatures= new String[prevNatures.length + 1]; + System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length); + newNatures[prevNatures.length]= natureId; + description.setNatureIds(newNatures); + proj.setDescription(description, monitor); + } + + protected void tearDown() throws Exception { + CProjectHelper.delete(fCProject); + } + + public void testBug36379() { + TranslationUnit tu = new TranslationUnit(fCProject, headerFile); + // parse the translation unit to get the elements tree + Map newElement = tu.parse(true); // require line numbers + + // tu ---> namespace: MyPackage + ArrayList tuPackages = tu.getChildrenOfType(ICElement.C_NAMESPACE); + INamespace namespace = (INamespace) tuPackages.get(0); + assertEquals(namespace.getElementName(), new String("MyPackage")); + + // MyPackage ---> class: Hello + ArrayList nsClasses = namespace.getChildrenOfType(ICElement.C_CLASS); + IStructure classHello = (IStructure) nsClasses.get(0); + assertEquals(classHello.getElementName(), new String("Hello")); + + // Bug 36379: parser does not provide line number information for nested definitions + assertEquals(0, ((CElement)classHello).getStartLine()); + assertEquals(0, ((CElement)classHello).getEndLine()); + } + +} diff --git a/core/org.eclipse.cdt.ui.tests/failures/org/eclipse/cdt/core/model/failedTests/TranslationUnitFailedTests.java b/core/org.eclipse.cdt.ui.tests/failures/org/eclipse/cdt/core/model/failedTests/TranslationUnitFailedTests.java new file mode 100644 index 00000000000..ef9332cb8ee --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/failures/org/eclipse/cdt/core/model/failedTests/TranslationUnitFailedTests.java @@ -0,0 +1,206 @@ +package org.eclipse.cdt.core.model.failedTests; + +/********************************************************************** + * Copyright (c) 2002,2003 Rational Software Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v0.5 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v05.html + * + * Contributors: + * Rational Software - Initial API and implementation +***********************************************************************/ + +import java.io.FileInputStream; +import java.io.FileNotFoundException; + +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.ICElement; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IInclude; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.testplugin.CProjectHelper; +import org.eclipse.cdt.testplugin.util.ExpectedStrings; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; + + + +/** + * @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 + * + */ +public class TranslationUnitFailedTests extends TestCase { + IWorkspace workspace; + IWorkspaceRoot root; + ICProject testProject; + IFile cfile, exefile, libfile, archfile, objfile; + Path cpath, exepath, libpath, archpath, objpath; + NullProgressMonitor monitor; + + /* 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}; + /* 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}; + + + /** + * Constructor for TranslationUnitTests + * @param name + */ + public TranslationUnitFailedTests(String name) { + super(name); + } + + /** + * Sets up the test fixture. + * + * Called before every test case method. + * + * Example code test the packages in the project + * "com.qnx.tools.ide.cdt.core" + */ + protected void setUp() throws CoreException,FileNotFoundException { + /*** + * The rest of the tests assume that they have a working workspace + * and workspace root object to use to create projects/files in, + * so we need to get them setup first. + */ + IWorkspaceDescription desc; + String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.ui.tests").find(new Path("/")).getFile(); + workspace= ResourcesPlugin.getWorkspace(); + root= workspace.getRoot(); + monitor = new NullProgressMonitor(); + if (workspace==null) + fail("Workspace was not setup"); + if (root==null) + fail("Workspace root was not setup"); + + desc=workspace.getDescription(); + desc.setAutoBuilding(false); + workspace.setDescription(desc); + + /*** + * Setup the various files, paths and projects that are needed by the + * tests + */ + + testProject=CProjectHelper.createCProject("filetest", "none"); + if (testProject==null) + fail("Unable to create project"); + + cfile = testProject.getProject().getFile("exetest.c"); + if (!cfile.exists()) { + cfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/cfiles/TranslationUnits.c"),false, monitor); + + } + cpath=new Path(workspace.getRoot().getLocation()+"/filetest/main.c"); + + objfile = testProject.getProject().getFile("exetest.o"); + if (!objfile.exists()) { + objfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/main.o"),false, monitor); + + } + objpath=new Path(workspace.getRoot().getLocation()+"/filetest/main.o"); + + exefile = testProject.getProject().getFile("test_g"); + if (!exefile.exists()) { + exefile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/exe_g"),false, monitor); + + } + exepath=new Path(workspace.getRoot().getLocation()+"/filetest/exe_g"); + + archfile = testProject.getProject().getFile("libtestlib_g.a"); + if (!archfile.exists()) { + archfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/a.g/libtestlib_g.a"),false, monitor); + + } + libpath=new Path(workspace.getRoot().getLocation()+"/filetest/libtestlib_g.so"); + + libfile = testProject.getProject().getFile("libtestlib_g.so"); + if (!libfile.exists()) { + libfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/so.g/libtestlib_g.so"),false, monitor); + + } + archpath=new Path(workspace.getRoot().getLocation()+"/filetest/libtestlib_g.a"); + + + } + + /** + * Tears down the test fixture. + * + * Called after every test case method. + */ + protected void tearDown() throws CoreException { + // release resources here and clean-up + testProject.getProject().delete(true,true,monitor); + } + + + /*** + * Simple sanity tests for the getInclude call + */ + public void testBug23478A() { + IInclude myInclude; + int x; + String includes[]={"stdio.h", "unistd.h"}; + ITranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c"); + + for (x=0; x < includes.length; x++) { + myInclude=myTranslationUnit.getInclude(includes[x]); + if (myInclude==null) + fail("Unable to get include: " + includes[x]); + else { + // Failed test: Include.getIncludeName() always returns ""; + // assertTrue + assertFalse("PR:23478 Expected:"+ new String("") +" Got:"+ myInclude.getIncludeName(), includes[x].equals(myInclude.getIncludeName())); + } + } + + + } + /*** + * Simple sanity tests for the getIncludes call + */ + public void testBug23478B() throws CModelException { + IInclude myIncludes[]; + String includes[]={"stdio.h", "unistd.h"}; + ExpectedStrings myExp= new ExpectedStrings(includes); + int x; + ITranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c"); + + myIncludes=myTranslationUnit.getIncludes(); + for (x=0; x < myIncludes.length; x++) { + myExp.foundString(myIncludes[x].getIncludeName()); + } + // Failed test: Include.getIncludeName() always returns ""; + // assertTrue + assertFalse(myExp.getMissingString(), myExp.gotAll()); + assertFalse(myExp.getExtraString(), !myExp.gotExtra()); + } + +} diff --git a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java index 4d2d21c0888..19c59feb808 100644 --- a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java +++ b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/CModelElementsTests.java @@ -45,7 +45,6 @@ import org.eclipse.cdt.internal.core.model.MethodTemplate; import org.eclipse.cdt.internal.core.model.TranslationUnit; import org.eclipse.cdt.internal.core.model.VariableTemplate; import org.eclipse.cdt.testplugin.CProjectHelper; -import org.eclipse.cdt.testplugin.TestPluginLauncher; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; @@ -59,10 +58,6 @@ public class CModelElementsTests extends TestCase { private IFile headerFile; private NullProgressMonitor monitor; - public static void main(String[] args) { - TestPluginLauncher.run(TestPluginLauncher.getLocationFromProperties(), WorkingCopyTests.class, args); - } - public static Test suite() { TestSuite suite= new TestSuite(); suite.addTest(new CModelElementsTests("testCModelElements")); @@ -123,7 +118,7 @@ public class CModelElementsTests extends TestCase { ArrayList tuPackages = tu.getChildrenOfType(ICElement.C_NAMESPACE); INamespace namespace = (INamespace) tuPackages.get(0); assertEquals(namespace.getElementName(), new String("MyPackage")); - checkLineNumbers((CElement)namespace, 8, 121); + checkLineNumbers((CElement)namespace, 8, 130); checkClass(namespace); checkEnums(namespace); @@ -470,8 +465,9 @@ public class CModelElementsTests extends TestCase { } private void checkLineNumbers(CElement element, int startLine, int endLine){ -// assertEquals(element.getStartLine(), startLine); -// assertEquals(element.getEndLine(), endLine); +// Remove comments when testBug36379() is fixed +// assertEquals(startLine, element.getStartLine()); +// assertEquals(endLine, element.getEndLine()); } } diff --git a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java index 21697f9ed5d..4604ee4e614 100644 --- a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java +++ b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/ElementDeltaTests.java @@ -91,7 +91,7 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen CModelManager.getDefault().addElementChangedListener(this); addedElements = new Vector(10); removedElements = new Vector(10); - changedElements = new Vector(100); + changedElements = new Vector(20); CCorePlugin.getDefault().setUseNewParser(true); } private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException { @@ -122,79 +122,116 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen wcBuf.setContents ("\n class Hello{ \n};"); wc.reconcile(); wc.commit(true, monitor); + assertChangedElement(ICElement.C_MODEL, ""); + assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); assertAddedElement(ICElement.C_CLASS, "Hello"); + assertRemovedElement(ICElement.C_INCLUDE, "stdio.h"); + assertEmptyDelta(); // add the field x wcBuf.setContents ("\n class Hello{\n int x; \n};"); wc.reconcile(); wc.commit(true, monitor); + assertChangedElement(ICElement.C_MODEL, ""); + assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); + assertChangedElement(ICElement.C_CLASS, "Hello"); assertAddedElement(ICElement.C_FIELD, "x"); + assertEmptyDelta(); // add the method setValue wcBuf.setContents ("\n class Hello{\n int x; \n void setValue(int val); \n};"); wc.reconcile(); wc.commit(true, monitor); + assertChangedElement(ICElement.C_MODEL, ""); + assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); + assertChangedElement(ICElement.C_CLASS, "Hello"); assertAddedElement(ICElement.C_METHOD_DECLARATION, "setValue"); + assertEmptyDelta(); // rename x to y // this is not a change, this is add and remove wcBuf.setContents ("\n class Hello{\n int y; \n void setValue(int val); \n};"); wc.reconcile(); wc.commit(true, monitor); + assertChangedElement(ICElement.C_MODEL, ""); + assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); + assertChangedElement(ICElement.C_CLASS, "Hello"); assertAddedElement(ICElement.C_FIELD, "y"); assertRemovedElement(ICElement.C_FIELD, "x"); + assertEmptyDelta(); // remove the method wcBuf.setContents ("\n class Hello{\n String y; \n};"); wc.reconcile(); wc.commit(true, monitor); + assertChangedElement(ICElement.C_MODEL, ""); + assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); + assertChangedElement(ICElement.C_CLASS, "Hello"); + assertChangedElement(ICElement.C_FIELD, "y"); assertRemovedElement(ICElement.C_METHOD_DECLARATION, "setValue"); + assertEmptyDelta(); // remove the field wcBuf.setContents ("\n class Hello{ \n};"); wc.reconcile(); wc.commit(true, monitor); + assertChangedElement(ICElement.C_MODEL, ""); + assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); + assertChangedElement(ICElement.C_CLASS, "Hello"); assertRemovedElement(ICElement.C_FIELD, "y"); + assertEmptyDelta(); // remove the class wcBuf.setContents (""); wc.reconcile(); wc.commit(true, monitor); + assertChangedElement(ICElement.C_MODEL, ""); + assertChangedElement(ICElement.C_PROJECT, "TestProject1"); + assertChangedElement(ICElement.C_UNIT, "WorkingCopyTest.h"); assertRemovedElement(ICElement.C_CLASS, "Hello"); + assertEmptyDelta(); wc.destroy(); assertFalse(wc.exists()); } public void assertAddedElement(int elementType, String elementName){ - System.out.println("Printing Added List: "); if(!isElementInList(elementType, elementName, addedElements)) fail("Element NOT found in Added list"); } public void assertRemovedElement(int elementType, String elementName){ - System.out.println("Printing Removed List: "); if(!isElementInList(elementType, elementName, removedElements)) fail("Element NOT found in Removed list"); } public void assertChangedElement(int elementType, String elementName){ - System.out.println("Printing Changed List: "); if(!isElementInList(elementType, elementName, changedElements)) fail("Element NOT found in Changed list"); } + public void assertEmptyDelta() { + assertTrue(addedElements.isEmpty()); + assertTrue(removedElements.isEmpty()); + assertTrue(changedElements.isEmpty()); + } public boolean isElementInList(int elementType, String elementName, Vector elementList) { boolean found = false; Iterator i = elementList.iterator(); while( i.hasNext()){ ICElement element = (ICElement)i.next(); - - System.out.print("ElementName " + element.getElementName()); - System.out.println(" ElementType " + element.getElementType()); if ((element.getElementName().equals(elementName)) && (element.getElementType() == elementType)){ // return true; // just to print the whole list found = true; + // Remove the element + elementList.remove(element); + break; } } //return false; @@ -218,37 +255,25 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen int flags= delta.getFlags(); ICElement element= delta.getElement(); - System.out.print("Processing " + element); // handle open and closing of a solution or project if ((flags & ICElementDelta.F_CLOSED) != 0) { - System.out.println(" Element Closed"); } if ((flags & ICElementDelta.F_OPENED) != 0) { - System.out.println(" Element Opened"); } - if (kind == ICElementDelta.REMOVED) { - System.out.println(" Element Removed"); removedElements.add(element); } - if (kind == ICElementDelta.ADDED) { - System.out.println(" Element Added"); addedElements.add(element); } - if (kind == ICElementDelta.CHANGED) { - System.out.println(" Element Changed"); changedElements.add(element); if (flags == ICElementDelta.F_MODIFIERS) { - System.out.println(" Modifiers changed"); } if (flags == ICElementDelta.F_CONTENT) { - System.out.println(" Contents changed"); } if (flags == ICElementDelta.F_CHILDREN) { - System.out.println(" Children changed"); } } @@ -257,5 +282,5 @@ public class ElementDeltaTests extends TestCase implements IElementChangedListen processDelta(affectedChildren[i]); } } - + } diff --git a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java index db8d6d889d5..31d5186c42c 100644 --- a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java +++ b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java @@ -269,6 +269,7 @@ public class TranslationUnitTests extends TestCase { /*** * Simple sanity tests for the getInclude call */ +/* Reintroduce this test when Bug# 23478 is fixed public void testGetInclude() { IInclude myInclude; int x; @@ -285,9 +286,11 @@ public class TranslationUnitTests extends TestCase { } +*/ /*** * Simple sanity tests for the getIncludes call */ +/* Reintroduce this test when Bug# 23478 is fixed public void testGetIncludes() throws CModelException { IInclude myIncludes[]; String includes[]={"stdio.h", "unistd.h"}; @@ -302,8 +305,6 @@ public class TranslationUnitTests extends TestCase { } assertTrue(myExp.getMissingString(), myExp.gotAll()); assertTrue(myExp.getExtraString(), !myExp.gotExtra()); - - } - +*/ } diff --git a/core/org.eclipse.cdt.ui.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java b/core/org.eclipse.cdt.ui.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java new file mode 100644 index 00000000000..08872677801 --- /dev/null +++ b/core/org.eclipse.cdt.ui.tests/suite/org/eclipse/cdt/core/suite/AutomatedIntegrationSuite.java @@ -0,0 +1,231 @@ +/* + * Created on May 16, 2003 + * + * To change the template for this generated file go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +package org.eclipse.cdt.core.suite; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; +import junit.framework.TestResult; +import junit.framework.TestListener; +import junit.framework.AssertionFailedError; + +import java.text.DecimalFormat; + +import org.eclipse.cdt.core.build.managed.tests.AllBuildTests; +import org.eclipse.cdt.core.model.tests.AllCoreTests; +import org.eclipse.cdt.core.model.tests.BinaryTests; +import org.eclipse.cdt.core.model.tests.ElementDeltaTests; +import org.eclipse.cdt.core.model.tests.WorkingCopyTests; +import org.eclipse.cdt.core.parser.failedTests.*; +import org.eclipse.cdt.core.parser.tests.ParserTestSuite; +import org.eclipse.cdt.core.model.failedTests.*; + +/** + * @author vhirsl + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ +public class AutomatedIntegrationSuite extends TestSuite implements TestListener { + + private String currentTestName; + // Statistical information + private int numberOfRuns = 0; + private int numberOfFailures = 0; + private int numberOfErrors = 0; + // success tests + private int numberOfSuccessTests = 0; + private int numberOfFailedSuccessTests = 0; + // failed tests for open bug reports + private int numberOfFailedTests = 0; + private int numberOfFailedFailedTests = 0; + // switching to failed tests + private boolean failedTests = false; + private boolean skipTest = false; + + + public AutomatedIntegrationSuite() {} + + public AutomatedIntegrationSuite(Class theClass, String name) { + super(theClass, name); + } + + public AutomatedIntegrationSuite(Class theClass) { + super(theClass); + } + + public AutomatedIntegrationSuite(String name) { + super(name); + } + + public static Test suite() { + final AutomatedIntegrationSuite suite = new AutomatedIntegrationSuite(); + + // Add all success tests + suite.addTest(AllBuildTests.suite()); + suite.addTest(ParserTestSuite.suite()); + suite.addTest(AllCoreTests.suite()); + suite.addTest(BinaryTests.suite()); + suite.addTest(ElementDeltaTests.suite()); + suite.addTest(WorkingCopyTests.suite()); + + // Last test to trigger report generation + suite.addTest(suite.new GenerateReport("testStartFailedTests")); + + // Add all failed tests + suite.addTestSuite(ACEFailedTest.class); + suite.addTestSuite(DOMFailedTest.class); + suite.addTestSuite(LokiFailures.class); + suite.addTestSuite(ScannerFailedTest.class); + suite.addTestSuite(STLFailedTests.class); + suite.addTestSuite(CModelElementsFailedTests.class); + suite.addTestSuite(TranslationUnitFailedTests.class); + + // Last test to trigger report generation + suite.addTest(suite.new GenerateReport("testGenerateReport")); + + return suite; + } + + /** + * Runs the tests and collects their result in a TestResult. + * Overloaded method + */ + public void run(TestResult result) { + // Add oneself as a listener + result.addListener(this); + // Call a base class method + super.run(result); + // Remove a listener + result.removeListener(this); + } + + + /** + * An error occurred. + */ + public void addError(Test test, Throwable t) { + ++numberOfErrors; + System.out.println("Error : " + test); + System.out.println("\tReason : " + t); + System.out.println("\tStack trace : "); + t.printStackTrace(System.out); + } + /** + * A failure occurred. + */ + public void addFailure(Test test, AssertionFailedError t) { + ++numberOfFailures; + if (failedTests) { + ++numberOfFailedFailedTests; + } + else { + ++numberOfFailedSuccessTests; + } + System.out.println("Failure : " + test); + System.out.println("\tReason : " + t); + System.out.println("\tStackTrace : "); + t.printStackTrace(System.out); + } + /** + * A test ended. + */ + public void endTest(Test test) { + if (currentTestName == null) { + System.out.println("Internal error - endTest: currentTestName == null"); + } + else { + if (skipTest) { + skipTest = false; + } + else { + ++numberOfRuns; + if (failedTests) { + ++numberOfFailedTests; + System.out.println(test); + } + else { + ++numberOfSuccessTests; + } + // System.out.println(test); + } + currentTestName = null; + } + } + /** + * A test started. + */ + public void startTest(Test test) { + if (currentTestName != null) { + System.out.println("Internal error - startTest: currentTestName != null"); + } + else { + currentTestName = test.toString(); + } + } + + /* + * generateReport + * + * @author vhirsl + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ + protected void generateReport() { + System.out.println("\n*** Generating report: ***\n"); + System.out.println("\tNumber of runs: " + numberOfRuns); + System.out.println("\tNumber of failures: " + numberOfFailures); + System.out.println("\tNumber of errors: " + numberOfErrors); + float successRate = (numberOfRuns-numberOfFailures)/(float)numberOfRuns; + DecimalFormat df = new DecimalFormat("##.##%"); + System.out.println("Sanity success rate : " + df.format(successRate)); + System.out.println("\tNumber of success tests: " + numberOfSuccessTests); + System.out.println("\tNumber of failed tests: " + numberOfFailedTests); + successRate = numberOfSuccessTests/(float)(numberOfSuccessTests+numberOfFailedTests); + System.out.println("Expected success test rate : " + df.format(successRate)); + successRate = (numberOfSuccessTests-numberOfFailedSuccessTests)/ + (float)(numberOfSuccessTests+numberOfFailedTests-numberOfFailedFailedTests); + System.out.print("Observed success test rate : " + df.format(successRate)); + System.out.println(" (failed success tests = " + numberOfFailedSuccessTests + ", failed failed tests = " + numberOfFailedFailedTests + ")"); + } + + private void startFailedTests() { + failedTests = true; + System.out.println("\n*** Starting failed tests ***\n"); + } + /* + * Public inner class to invoke generateReport + * + * @author vhirsl + * + * To change the template for this generated type comment go to + * Window>Preferences>Java>Code Generation>Code and Comments + */ + public class GenerateReport extends TestCase { + public GenerateReport(String name) { + super(name); + } + public GenerateReport(){} + + public void testGenerateReport() { + // skip this one + AutomatedIntegrationSuite.this.skipTest = true; + + // Calls a method of the outer class + AutomatedIntegrationSuite.this.generateReport(); + } + + public void testStartFailedTests() { + // skip this one + AutomatedIntegrationSuite.this.skipTest = true; + + // Calls a method of the outer class + AutomatedIntegrationSuite.this.startFailedTests(); + } + } +}