mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fixed reporting of "Test data not found" errors.
This commit is contained in:
parent
c42f98e333
commit
2737d2c708
6 changed files with 99 additions and 84 deletions
|
@ -120,12 +120,12 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
|||
len= section.length()+len;
|
||||
}
|
||||
IASTName name= findName(section, len);
|
||||
assertNotNull("name not found for \""+section+"\"", name);
|
||||
assertNotNull("Name not found for \"" + section + "\"", name);
|
||||
assertEquals(section.substring(0, len), name.getRawSignature());
|
||||
|
||||
IBinding binding = name.resolveBinding();
|
||||
assertNotNull("No binding for "+name.getRawSignature(), binding);
|
||||
assertFalse("Binding is a ProblemBinding for name "+name.getRawSignature(), IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
|
||||
assertNotNull("No binding for " + name.getRawSignature(), binding);
|
||||
assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
|
||||
assertInstance(binding, clazz, cs);
|
||||
return clazz.cast(binding);
|
||||
}
|
||||
|
@ -135,15 +135,15 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
|||
*/
|
||||
protected <T extends IBinding> T getBindingFromASTName(String section, int len) {
|
||||
if (len <= 0)
|
||||
len+= section.length();
|
||||
len += section.length();
|
||||
|
||||
IASTName name= findName(section, len);
|
||||
assertNotNull("name not found for \""+section+"\"", name);
|
||||
assertNotNull("Name not found for \"" + section + "\"", name);
|
||||
assertEquals(section.substring(0, len), name.getRawSignature());
|
||||
|
||||
IBinding binding = name.resolveBinding();
|
||||
assertNotNull("No binding for "+name.getRawSignature(), binding);
|
||||
assertFalse("Binding is a ProblemBinding for name "+name.getRawSignature(), IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
|
||||
assertNotNull("No binding for " + name.getRawSignature(), binding);
|
||||
assertFalse("Binding is a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
|
||||
return (T) binding;
|
||||
}
|
||||
|
||||
|
@ -155,12 +155,12 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
|||
*/
|
||||
protected IBinding getProblemFromASTName(String section, int len) {
|
||||
IASTName name= findName(section, len);
|
||||
assertNotNull("name not found for \""+section+"\"", name);
|
||||
assertNotNull("Name not found for \"" + section + "\"", name);
|
||||
assertEquals(section.substring(0, len), name.getRawSignature());
|
||||
|
||||
IBinding binding = name.resolveBinding();
|
||||
assertNotNull("No binding for "+name.getRawSignature(), binding);
|
||||
assertTrue("Binding is not a ProblemBinding for name "+name.getRawSignature(), IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
|
||||
assertNotNull("No binding for " + name.getRawSignature(), binding);
|
||||
assertTrue("Binding is not a ProblemBinding for name \"" + name.getRawSignature() + "\"", IProblemBinding.class.isAssignableFrom(name.resolveBinding().getClass()));
|
||||
return name.resolveBinding();
|
||||
}
|
||||
|
||||
|
@ -200,10 +200,10 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
|||
}
|
||||
|
||||
protected static <T> T assertInstance(Object o, Class<T> clazz, Class ... cs) {
|
||||
assertNotNull("Expected "+clazz.getName()+" but got null", o);
|
||||
assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), clazz.isInstance(o));
|
||||
assertNotNull("Expected " + clazz.getName() + " but got null", o);
|
||||
assertTrue("Expected " + clazz.getName() + " but got " + o.getClass().getName(), clazz.isInstance(o));
|
||||
for (Class c : cs) {
|
||||
assertTrue("Expected "+clazz.getName()+" but got "+o.getClass().getName(), c.isInstance(o));
|
||||
assertTrue("Expected " + clazz.getName() + " but got " + o.getClass().getName(), c.isInstance(o));
|
||||
}
|
||||
return clazz.cast(o);
|
||||
}
|
||||
|
|
|
@ -16,8 +16,11 @@ public class IndexCPPBindingResolutionBugsSingleProjectFirstAST extends IndexCPP
|
|||
public IndexCPPBindingResolutionBugsSingleProjectFirstAST() {
|
||||
setStrategy(new SinglePDOMTestFirstASTStrategy(true));
|
||||
}
|
||||
public static TestSuite suite() {return suite(IndexCPPBindingResolutionBugsSingleProjectFirstAST.class);}
|
||||
// invalid tests for this strategy, they assume that the second file is already indexed.
|
||||
public static TestSuite suite() {
|
||||
return suite(IndexCPPBindingResolutionBugsSingleProjectFirstAST.class);
|
||||
}
|
||||
|
||||
// Invalid tests for this strategy, they assume that the second file is already indexed.
|
||||
@Override public void testBug208558() {}
|
||||
@Override public void testBug176708_CCE() {}
|
||||
@Override public void testIsSameAnonymousType_Bug193962() {}
|
||||
|
|
|
@ -23,7 +23,6 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ILinkage;
|
||||
|
@ -54,10 +53,10 @@ import org.osgi.framework.Bundle;
|
|||
* Utilities for reading test source code from plug-in .java sources
|
||||
*/
|
||||
public class TestSourceReader {
|
||||
|
||||
/**
|
||||
* Returns an array of StringBuilder objects for each comment section found preceding the named
|
||||
* test in the source code.
|
||||
* test in the source code.
|
||||
*
|
||||
* @param bundle the bundle containing the source, if null can try to load using classpath
|
||||
* (source folder has to be in the classpath for this to work)
|
||||
* @param srcRoot the directory inside the bundle containing the packages
|
||||
|
@ -71,54 +70,61 @@ public class TestSourceReader {
|
|||
*/
|
||||
public static StringBuilder[] getContentsForTest(Bundle bundle, String srcRoot, Class clazz,
|
||||
final String testName, int sections) throws IOException {
|
||||
String fqn = clazz.getName().replace('.', '/');
|
||||
fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$"));
|
||||
String classFile = fqn + ".java";
|
||||
IPath filePath= new Path(srcRoot + '/' + classFile);
|
||||
|
||||
InputStream in;
|
||||
try {
|
||||
if (bundle != null) {
|
||||
in = FileLocator.openStream(bundle, filePath, false);
|
||||
} else {
|
||||
in = clazz.getResourceAsStream('/' + classFile);
|
||||
while (true) {
|
||||
String fqn = clazz.getName().replace('.', '/');
|
||||
fqn = fqn.indexOf("$") == -1 ? fqn : fqn.substring(0, fqn.indexOf("$"));
|
||||
String classFile = fqn + ".java";
|
||||
IPath filePath= new Path(srcRoot + '/' + classFile);
|
||||
|
||||
InputStream in;
|
||||
Class superclass = clazz.getSuperclass();
|
||||
try {
|
||||
if (bundle != null) {
|
||||
in = FileLocator.openStream(bundle, filePath, false);
|
||||
} else {
|
||||
in = clazz.getResourceAsStream('/' + classFile);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (superclass == null || !superclass.getPackage().equals(clazz.getPackage())) {
|
||||
throw e;
|
||||
}
|
||||
clazz = superclass;
|
||||
continue;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
if (clazz.getSuperclass() != null && !clazz.equals(TestCase.class)) {
|
||||
return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections);
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||
try {
|
||||
List<StringBuilder> contents = new ArrayList<StringBuilder>();
|
||||
StringBuilder content = new StringBuilder();
|
||||
for (String line = br.readLine(); line != null; line = br.readLine()) {
|
||||
line = line.replaceFirst("^\\s*", ""); // Replace leading whitespace, preserve trailing
|
||||
if (line.startsWith("//")) {
|
||||
content.append(line.substring(2) + "\n");
|
||||
} else {
|
||||
if (content.length() > 0) {
|
||||
contents.add(content);
|
||||
if (sections > 0 && contents.size() == sections + 1)
|
||||
contents.remove(0);
|
||||
content = new StringBuilder();
|
||||
}
|
||||
if (line.length() > 0 && !contents.isEmpty()) {
|
||||
int idx= line.indexOf(testName);
|
||||
if (idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) {
|
||||
return contents.toArray(new StringBuilder[contents.size()]);
|
||||
}
|
||||
contents.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
br.close();
|
||||
}
|
||||
throw e;
|
||||
|
||||
if (superclass == null || !superclass.getPackage().equals(clazz.getPackage())) {
|
||||
throw new IOException("Test data not found for " + clazz.getName() + "." + testName);
|
||||
}
|
||||
clazz = superclass;
|
||||
}
|
||||
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(in));
|
||||
|
||||
List<StringBuilder> contents = new ArrayList<StringBuilder>();
|
||||
StringBuilder content = new StringBuilder();
|
||||
for (String line = br.readLine(); line != null; line = br.readLine()) {
|
||||
line = line.replaceFirst("^\\s*", ""); // replace leading whitespace, preserve trailing
|
||||
if (line.startsWith("//")) {
|
||||
content.append(line.substring(2) + "\n");
|
||||
} else {
|
||||
if (content.length() > 0) {
|
||||
contents.add(content);
|
||||
if (sections > 0 && contents.size() == sections + 1)
|
||||
contents.remove(0);
|
||||
content = new StringBuilder();
|
||||
}
|
||||
if (line.length() > 0 && !contents.isEmpty()) {
|
||||
int idx= line.indexOf(testName);
|
||||
if (idx != -1 && !Character.isJavaIdentifierPart(line.charAt(idx + testName.length()))) {
|
||||
return contents.toArray(new StringBuilder[contents.size()]);
|
||||
}
|
||||
contents.clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (clazz.getSuperclass() != null && !clazz.equals(TestCase.class)) {
|
||||
return getContentsForTest(bundle, srcRoot, clazz.getSuperclass(), testName, sections);
|
||||
}
|
||||
throw new IOException("Test data not found for " + clazz + " " + testName);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -251,6 +257,7 @@ public class TestSourceReader {
|
|||
}
|
||||
result[0]= file;
|
||||
}
|
||||
|
||||
private void createFolders(IResource res) throws CoreException {
|
||||
IContainer container= res.getParent();
|
||||
if (!container.exists() && container instanceof IFolder) {
|
||||
|
@ -305,7 +312,7 @@ public class TestSourceReader {
|
|||
Thread.sleep(50);
|
||||
timeLeft= (int) (endTime - System.currentTimeMillis());
|
||||
}
|
||||
Assert.fail("Indexing " + file.getFullPath() + " did not complete in time!");
|
||||
Assert.fail("Indexing " + file.getFullPath() + " did not complete in " + maxmillis / 1000. + " sec");
|
||||
}
|
||||
|
||||
private static boolean areAllFilesNotOlderThan(IIndexFile[] files, long timestamp) throws CoreException {
|
||||
|
@ -323,7 +330,7 @@ public class TestSourceReader {
|
|||
ITranslationUnit tu= (ITranslationUnit) elem;
|
||||
return tu.getAST(index, ITranslationUnit.AST_SKIP_INDEXED_HEADERS);
|
||||
}
|
||||
Assert.fail("Could not create ast for " + file.getFullPath());
|
||||
Assert.fail("Could not create AST for " + file.getFullPath());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,10 +6,10 @@
|
|||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM Corporation
|
||||
* Ed Swartz (Nokia)
|
||||
* Andrew Ferguson (Symbian) - Initial implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* IBM Corporation
|
||||
* Ed Swartz (Nokia)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.search;
|
||||
|
||||
|
@ -67,9 +67,10 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fCProject = CProjectHelper.createCCProject(getName()+System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
|
||||
fCProject = CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin", IPDOMManager.ID_NO_INDEXER);
|
||||
Bundle b = CTestPlugin.getDefault().getBundle();
|
||||
testData = TestSourceReader.getContentsForTest(b, "ui", this.getClass(), getName(), 2);
|
||||
assertEquals("Incomplete test data", 2, testData.length);
|
||||
|
||||
IFile file = TestSourceReader.createFile(fCProject.getProject(), new Path("header.h"), testData[0].toString());
|
||||
CCorePlugin.getIndexManager().setIndexerId(fCProject, IPDOMManager.ID_FAST_INDEXER);
|
||||
|
@ -142,7 +143,8 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
}
|
||||
|
||||
// int x, y, xx, yy;
|
||||
|
||||
|
||||
// // empty
|
||||
public void testNoIndexerEnabled_158955() throws Exception {
|
||||
// rebuild the index with no indexer
|
||||
CCorePlugin.getIndexManager().setIndexerId(fCProject, IPDOMManager.ID_NO_INDEXER);
|
||||
|
@ -156,7 +158,7 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
|
||||
ISearchResultViewPart vp= NewSearchUI.getSearchResultView();
|
||||
ISearchResultPage page= vp.getActivePage();
|
||||
assertTrue(""+page, page instanceof PDOMSearchViewPage);
|
||||
assertTrue("" + page, page instanceof PDOMSearchViewPage);
|
||||
|
||||
PDOMSearchViewPage pdomsvp= (PDOMSearchViewPage) page;
|
||||
StructuredViewer viewer= pdomsvp.getViewer();
|
||||
|
@ -177,7 +179,8 @@ public class BasicSearchTest extends BaseUITestCase {
|
|||
final int INDEXER_IN_PROGRESS_STRUCT_COUNT = 100;
|
||||
|
||||
// #include "hugeHeader0.h"
|
||||
|
||||
|
||||
// // empty
|
||||
public void testIndexerInProgress() throws Exception {
|
||||
// make an external file
|
||||
File dir= CProjectHelper.freshDir();
|
||||
|
|
|
@ -7,10 +7,9 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
* Sergey Prigogin, Google
|
||||
* Sergey Prigogin (Google)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.tests.text;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
@ -36,12 +35,11 @@ import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
|
|||
import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy;
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
|
||||
|
||||
/**
|
||||
* Testing the auto indent strategies.
|
||||
*/
|
||||
public class DefaultCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
|
||||
private HashMap<String,String> fOptions;
|
||||
private HashMap<String, String> fOptions;
|
||||
|
||||
/**
|
||||
* @param name
|
||||
|
|
|
@ -7,11 +7,13 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Anton Leherbauer (Wind River Systems) - initial API and implementation
|
||||
* Sergey Prigogin, Google
|
||||
* Sergey Prigogin (Google)
|
||||
* Andrew Ferguson (Symbian)
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.text.doctools.doxygen;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import junit.framework.Test;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -20,13 +22,14 @@ import org.eclipse.jface.text.BadLocationException;
|
|||
import org.eclipse.jface.text.Document;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.util.TestSourceReader;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.tests.text.DefaultCCommentAutoEditStrategyTest;
|
||||
import org.eclipse.cdt.ui.tests.text.AbstractAutoEditTest;
|
||||
import org.eclipse.cdt.ui.text.ICPartitions;
|
||||
import org.eclipse.cdt.ui.text.doctools.DefaultMultilineCommentAutoEditStrategy;
|
||||
import org.eclipse.cdt.ui.text.doctools.doxygen.DoxygenMultilineAutoEditStrategy;
|
||||
|
@ -36,13 +39,13 @@ import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
|||
import org.eclipse.cdt.internal.ui.text.CAutoIndentStrategy;
|
||||
import org.eclipse.cdt.internal.ui.text.CTextTools;
|
||||
|
||||
|
||||
/**
|
||||
* Testing the auto indent strategies.
|
||||
*/
|
||||
public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEditStrategyTest {
|
||||
public class DoxygenCCommentAutoEditStrategyTest extends AbstractAutoEditTest {
|
||||
private HashMap<String, String> fOptions;
|
||||
protected ICProject fCProject;
|
||||
|
||||
|
||||
/**
|
||||
* @param name
|
||||
*/
|
||||
|
@ -57,7 +60,8 @@ public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEdit
|
|||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fCProject= CProjectHelper.createCCProject("test"+System.currentTimeMillis(), null);
|
||||
fOptions= CCorePlugin.getOptions();
|
||||
fCProject= CProjectHelper.createCCProject("test" + System.currentTimeMillis(), null);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -65,6 +69,7 @@ public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEdit
|
|||
*/
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
CCorePlugin.setOptions(fOptions);
|
||||
CProjectHelper.delete(fCProject);
|
||||
super.tearDown();
|
||||
}
|
||||
|
@ -75,7 +80,6 @@ public class DoxygenCCommentAutoEditStrategyTest extends DefaultCCommentAutoEdit
|
|||
textTools.setupCDocument(doc);
|
||||
AutoEditTester tester = new AutoEditTester(doc, ICPartitions.C_PARTITIONING);
|
||||
|
||||
|
||||
tester.setAutoEditStrategy(IDocument.DEFAULT_CONTENT_TYPE, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
|
||||
tester.setAutoEditStrategy(ICPartitions.C_MULTI_LINE_COMMENT, new DefaultMultilineCommentAutoEditStrategy());
|
||||
tester.setAutoEditStrategy(ICPartitions.C_PREPROCESSOR, new CAutoIndentStrategy(ICPartitions.C_PARTITIONING, null));
|
||||
|
|
Loading…
Add table
Reference in a new issue