diff options
author | Andrew Niefer | 2004-10-04 21:06:38 +0000 |
---|---|---|
committer | Andrew Niefer | 2004-10-04 21:06:38 +0000 |
commit | 303494e2845a57cae91312b5b9c4afd235f063ce (patch) | |
tree | 2ae1c9c5b096236396393b2247ca8c8677e45467 | |
parent | edb5e36994b4efd803c9ea59caf2d647e82c3295 (diff) | |
download | org.eclipse.cdt-303494e2845a57cae91312b5b9c4afd235f063ce.tar.gz org.eclipse.cdt-303494e2845a57cae91312b5b9c4afd235f063ce.tar.xz org.eclipse.cdt-303494e2845a57cae91312b5b9c4afd235f063ce.zip |
new test framework that QE people will be adding tests to
6 files changed, 435 insertions, 0 deletions
diff --git a/core/org.eclipse.cdt.core.tests/.classpath b/core/org.eclipse.cdt.core.tests/.classpath index 8171adca772..8bd9ee23ce3 100644 --- a/core/org.eclipse.cdt.core.tests/.classpath +++ b/core/org.eclipse.cdt.core.tests/.classpath @@ -10,5 +10,6 @@ <classpathentry kind="src" path="search"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> + <classpathentry kind="src" path="regression"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/core/org.eclipse.cdt.core.tests/ChangeLog b/core/org.eclipse.cdt.core.tests/ChangeLog index a56eddf391e..310ee77b969 100644 --- a/core/org.eclipse.cdt.core.tests/ChangeLog +++ b/core/org.eclipse.cdt.core.tests/ChangeLog @@ -1,3 +1,6 @@ +2004-10-4 Andrew Niefer
+ created regression source folder and a test framework for search and content assist tests
+
2004-08-11 Bogdan Gheorghe
Modified indexer test to work with new forward declartion encoding.
diff --git a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java new file mode 100644 index 00000000000..cdc2085cd37 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/BaseTestFramework.java @@ -0,0 +1,140 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +/* + * Created on Oct 4, 2004 + */ +package org.eclipse.cdt.core.tests; + +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import junit.framework.TestCase; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.internal.core.search.indexing.IndexManager; +import org.eclipse.cdt.testplugin.CProjectHelper; +import org.eclipse.cdt.testplugin.FileManager; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.NullProgressMonitor; + +/** + * @author aniefer + */ +abstract public class BaseTestFramework extends TestCase { + static protected NullProgressMonitor monitor; + static protected IWorkspace workspace; + static protected IProject project; + static protected FileManager fileManager; + + { + if( CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null){ + (CCorePlugin.getDefault().getCoreModel().getIndexManager()).reset(); + monitor = new NullProgressMonitor(); + + workspace = ResourcesPlugin.getWorkspace(); + + ICProject cPrj; + try { + cPrj = CProjectHelper.createCCProject("RegressionTestProject", "bin"); //$NON-NLS-1$ //$NON-NLS-2$ + + project = cPrj.getProject(); + project.setSessionProperty(IndexManager.activationKey, Boolean.FALSE ); + } catch ( CoreException e ) { + /*boo*/ + } + if (project == null) + fail("Unable to create project"); //$NON-NLS-1$ + + //Create file manager + fileManager = new FileManager(); + } + } + + public void enableIndexing(){ + if( CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null){ + if( project != null ) + try { + project.setSessionProperty( IndexManager.activationKey, Boolean.TRUE ); + } catch ( CoreException e ) { //boo + } + } + } + + public void disableIndexing(){ + if( CCorePlugin.getDefault() != null && CCorePlugin.getDefault().getCoreModel() != null){ + if( project != null ) + try { + project.setSessionProperty( IndexManager.activationKey, Boolean.FALSE ); + } catch ( CoreException e ) { //boo + } + } + } + + public BaseTestFramework() + { + super(); + } + /** + * @param name + */ + public BaseTestFramework(String name) + { + super(name); + } + + public void cleanupProject() throws Exception { + try{ + project.delete( true, false, monitor ); + project = null; + } catch( Throwable e ){ + /*boo*/ + } + } + + protected void tearDown() throws Exception { + if( project == null || !project.exists() ) + return; + + IResource [] members = project.members(); + for( int i = 0; i < members.length; i++ ){ + if( members[i].getName().equals( ".project" ) || members[i].getName().equals( ".cdtproject" ) ) //$NON-NLS-1$ //$NON-NLS-2$ + continue; + try{ + members[i].delete( false, monitor ); + } catch( Throwable e ){ + /*boo*/ + } + } + } + protected IFile importFile(String fileName, String contents ) throws Exception{ + //Obtain file handle + IFile file = project.getProject().getFile(fileName); + + InputStream stream = new ByteArrayInputStream( contents.getBytes() ); + //Create file input stream + if( file.exists() ) + file.setContents( stream, false, false, monitor ); + else + file.create( stream, false, monitor ); + + fileManager.addFile(file); + + return file; + } + +} diff --git a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/ContentAssistRegressionTests.java b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/ContentAssistRegressionTests.java new file mode 100644 index 00000000000..eac8437880b --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/ContentAssistRegressionTests.java @@ -0,0 +1,91 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +/* + * Created on Oct 4, 2004 + */ +package org.eclipse.cdt.core.tests; + +import java.io.StringWriter; + +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ITranslationUnit; +import org.eclipse.cdt.core.model.IWorkingCopy; +import org.eclipse.cdt.internal.ui.text.contentassist.CCompletionProcessor; +import org.eclipse.core.resources.IFile; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.contentassist.ICompletionProposal; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * @author aniefer + */ +public class ContentAssistRegressionTests extends BaseTestFramework { + + public ContentAssistRegressionTests() + { + super(); + } + /** + * @param name + */ + public ContentAssistRegressionTests(String name) + { + super(name); + } + + protected ICompletionProposal[] getResults( IFile file, int offset ) throws Exception { + ITranslationUnit tu = (ITranslationUnit)CoreModel.getDefault().create( file ); + String buffer = tu.getBuffer().getContents(); + IWorkingCopy wc = null; + try{ + wc = tu.getWorkingCopy(); + }catch (CModelException e){ + fail("Failed to get working copy"); //$NON-NLS-1$ + } + + // call the CompletionProcessor + CCompletionProcessor completionProcessor = new CCompletionProcessor(null); + ICompletionProposal[] results = completionProcessor.evalProposals( new Document(buffer), offset, wc, null); + return results; + } + + public static Test suite() { + TestSuite suite = new TestSuite(); + suite.addTest( new ContentAssistRegressionTests("testMemberCompletion") ); //$NON-NLS-1$ + suite.addTest( new ContentAssistRegressionTests("cleanupProject") ); //$NON-NLS-1$ + return suite; + } + + public void testMemberCompletion() throws Exception { + StringWriter writer = new StringWriter(); + writer.write("class A { \n"); //$NON-NLS-1$ + writer.write(" int var; \n"); //$NON-NLS-1$ + writer.write(" void f(); \n"); //$NON-NLS-1$ + writer.write("}; \n"); //$NON-NLS-1$ + writer.write("void A::f(){ \n"); //$NON-NLS-1$ + writer.write(" v[^] \n"); //$NON-NLS-1$ + writer.write("} \n"); //$NON-NLS-1$ + + String code = writer.toString(); + IFile t = importFile( "t.cpp", code ); //$NON-NLS-1$ + ICompletionProposal [] results = getResults( t, code.indexOf( "[^]" ) ); //$NON-NLS-1$ + + assertEquals( results.length, 4 ); + assertEquals( results[0].getDisplayString(), "var : int" ); //$NON-NLS-1$ + assertEquals( results[1].getDisplayString(), "virtual" ); //$NON-NLS-1$ + assertEquals( results[2].getDisplayString(), "void" ); //$NON-NLS-1$ + assertEquals( results[3].getDisplayString(), "volatile" ); //$NON-NLS-1$ + } +} diff --git a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/RegressionTestSuite.java b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/RegressionTestSuite.java new file mode 100644 index 00000000000..8bd5918cd22 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/RegressionTestSuite.java @@ -0,0 +1,48 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +/* + * Created on Oct 4, 2004 + */ +package org.eclipse.cdt.core.tests; + +import junit.framework.Test; +import junit.framework.TestSuite; + +/** + * @author aniefer + */ +public class RegressionTestSuite extends TestSuite { + public RegressionTestSuite() { + super(); + } + + public RegressionTestSuite(Class theClass, String name) { + super(theClass, name); + } + + public RegressionTestSuite(Class theClass) { + super(theClass); + } + + public RegressionTestSuite(String name) { + super(name); + } + + public static Test suite() { + final RegressionTestSuite suite = new RegressionTestSuite(); + + suite.addTest( SearchRegressionTests.suite() ); + suite.addTest( ContentAssistRegressionTests.suite() ); + + return suite; + } +} diff --git a/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java new file mode 100644 index 00000000000..4465a3a4dbb --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/regression/org/eclipse/cdt/core/tests/SearchRegressionTests.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * Copyright (c) 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +/* + * Created on Oct 4, 2004 + */ +package org.eclipse.cdt.core.tests; + +import java.io.StringWriter; +import java.io.Writer; +import java.util.Iterator; +import java.util.Set; + +import junit.framework.Test; +import junit.framework.TestSuite; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.index.IIndexChangeListener; +import org.eclipse.cdt.core.index.IndexChangeEvent; +import org.eclipse.cdt.core.search.BasicSearchResultCollector; +import org.eclipse.cdt.core.search.ICSearchConstants; +import org.eclipse.cdt.core.search.ICSearchPattern; +import org.eclipse.cdt.core.search.ICSearchScope; +import org.eclipse.cdt.core.search.IMatch; +import org.eclipse.cdt.core.search.SearchEngine; +import org.eclipse.cdt.internal.core.search.indexing.IndexManager; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; + +/** + * @author aniefer + */ +public class SearchRegressionTests extends BaseTestFramework implements ICSearchConstants, IIndexChangeListener{ + static protected ICSearchScope scope; + static protected SearchEngine searchEngine; + static protected BasicSearchResultCollector resultCollector; + static private boolean indexChanged = false; + + { + scope = SearchEngine.createWorkspaceScope(); + resultCollector = new BasicSearchResultCollector(); + searchEngine = new SearchEngine(); + try{ + project.setSessionProperty( IndexManager.activationKey, new Boolean( true ) ); + } catch ( CoreException e ) { //boo + } + } + public SearchRegressionTests() + { + super(); + } + /** + * @param name + */ + public SearchRegressionTests(String name) + { + super(name); + } + + protected void setUp() throws Exception { + super.setUp(); + IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); + indexManager.addIndexChangeListener( this ); + } + + protected void tearDown() throws Exception { + if( project == null || !project.exists() ) + return; + + IndexManager indexManager = CCorePlugin.getDefault().getCoreModel().getIndexManager(); + indexManager.removeIndexChangeListener( this ); + + super.tearDown(); + } + + protected Set search( ICSearchPattern pattern ) { + try { + searchEngine.search( workspace, pattern, scope, resultCollector, false ); + } catch (InterruptedException e) { + //boo + } + + return resultCollector.getSearchResults(); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.core.index.IIndexChangeListener#indexChanged(org.eclipse.cdt.core.index.IndexChangeEvent) + */ + public void indexChanged( IndexChangeEvent event ) { + indexChanged = true; + } + + protected IFile importFile(String fileName, String contents ) throws Exception{ + indexChanged = false; + IFile file = super.importFile( fileName, contents ); + + int loops = 0; + while( !indexChanged && loops++ < 20){ + Thread.sleep( 100 ); + } + if( loops >= 20 ) + fail("Timeout waiting for file \"" + fileName + "\" to index." ); //$NON-NLS-1$//$NON-NLS-2$ + + return file; + } + + public void assertMatch( Set matches, IFile file, int offset ) throws Exception { + Iterator i = matches.iterator(); + while( i.hasNext() ){ + IMatch match = (IMatch) i.next(); + if( match.getStartOffset() == offset && match.getLocation().equals( file.getLocation() ) ) + return; //match + } + fail( "Match at offset " + offset + " in \"" + file.getLocation() + "\" not found." ); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ + } + + public static Test suite() { + TestSuite suite = new TestSuite(); + suite.addTest( new SearchRegressionTests("testClassDeclarationReference") ); //$NON-NLS-1$ + suite.addTest( new SearchRegressionTests("cleanupProject") ); //$NON-NLS-1$ + return suite; + } + + public void testClassDeclarationReference() throws Exception { + Writer writer = new StringWriter(); + writer.write(" class A { \n" ); //$NON-NLS-1$ + writer.write(" int foo(); \n" ); //$NON-NLS-1$ + writer.write(" }; \n" ); //$NON-NLS-1$ + writer.write(" int A::foo() { \n" ); //$NON-NLS-1$ + writer.write(" } \n" ); //$NON-NLS-1$ + + String code = writer.toString(); + IFile f = importFile( "f.cpp", code ); //$NON-NLS-1$ + + ICSearchPattern pattern = SearchEngine.createSearchPattern( "A", CLASS, ALL_OCCURRENCES, true ); //$NON-NLS-1$ + Set matches = search( pattern ); + + assertEquals( matches.size(), 2 ); + assertMatch( matches, f, code.indexOf( "A {" ) ); //$NON-NLS-1$ //$NON-NLS-2$ + assertMatch( matches, f, code.indexOf( "A::" ) ); //$NON-NLS-1$ //$NON-NLS-2$ + } + + +} |