mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-09 10:46:02 +02:00
new test framework that QE people will be adding tests to
This commit is contained in:
parent
edb5e36994
commit
303494e284
6 changed files with 435 additions and 0 deletions
|
@ -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>
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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$
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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$
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue