mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-09-10 03:53:21 +02:00
Test case demonstrating the problem for bug 450888.
This commit is contained in:
parent
a3962a9bd8
commit
a3e3cec9c1
2 changed files with 115 additions and 20 deletions
|
@ -16,7 +16,9 @@ package org.eclipse.cdt.internal.index.tests;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.CCorePlugin;
|
import org.eclipse.cdt.core.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||||
|
@ -62,7 +64,7 @@ import org.osgi.framework.Bundle;
|
||||||
* then it is assumed to have come from a file which is already indexed.
|
* then it is assumed to have come from a file which is already indexed.
|
||||||
*
|
*
|
||||||
* This class is for testing the process by which bindings are looked up in
|
* This class is for testing the process by which bindings are looked up in
|
||||||
* the PDOM purely from AST information (i.e. without a real binding from the DOM)
|
* the PDOM purely from AST information (i.e. without a real binding from the DOM).
|
||||||
*/
|
*/
|
||||||
public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
||||||
private static final boolean DEBUG= false;
|
private static final boolean DEBUG= false;
|
||||||
|
@ -548,6 +550,10 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
||||||
* The first line of each comment section preceding the test contains the name of the file
|
* The first line of each comment section preceding the test contains the name of the file
|
||||||
* to put the contents of the section to. To request the AST of a file, put an asterisk after
|
* to put the contents of the section to. To request the AST of a file, put an asterisk after
|
||||||
* the file name.
|
* the file name.
|
||||||
|
*
|
||||||
|
* If the same file name is repeated more than once, the file will be created and then updated
|
||||||
|
* with the new contents. It is guaranteed that the indexer will run for the original and then
|
||||||
|
* for the updated file contents.
|
||||||
*/
|
*/
|
||||||
protected class SinglePDOMTestNamedFilesStrategy implements ITestStrategy {
|
protected class SinglePDOMTestNamedFilesStrategy implements ITestStrategy {
|
||||||
private IIndex index;
|
private IIndex index;
|
||||||
|
@ -597,27 +603,41 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
|
||||||
testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 0);
|
testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 0);
|
||||||
|
|
||||||
List<IFile> astFiles = new ArrayList<>();
|
List<IFile> astFiles = new ArrayList<>();
|
||||||
for (int i = 0; i < testData.length; i++) {
|
for (int i = 0; i < testData.length;) {
|
||||||
StringBuilder contents = testData[i];
|
Set<String> createdFiles = new HashSet<>();
|
||||||
int endOfLine = contents.indexOf("\n");
|
for (int j = i; j < testData.length; j++, i++) {
|
||||||
if (endOfLine >= 0)
|
StringBuilder contents = testData[j];
|
||||||
endOfLine++;
|
int endOfLine = contents.indexOf("\n");
|
||||||
else
|
if (endOfLine >= 0) {
|
||||||
endOfLine = contents.length();
|
endOfLine++;
|
||||||
String filename = contents.substring(0, endOfLine).trim();
|
} else {
|
||||||
contents.delete(0, endOfLine); // Remove first line from the file contents
|
endOfLine = contents.length();
|
||||||
boolean astRequested = filename.endsWith("*");
|
}
|
||||||
if (astRequested) {
|
String filename = contents.substring(0, endOfLine).trim();
|
||||||
filename = filename.substring(0, filename.length() - 1).trim();
|
boolean astRequested = filename.endsWith("*");
|
||||||
}
|
if (astRequested) {
|
||||||
IFile file = TestSourceReader.createFile(cproject.getProject(), new Path(filename), contents.toString());
|
filename = filename.substring(0, filename.length() - 1).trim();
|
||||||
if (astRequested || (i == testData.length - 1 && astFiles.isEmpty())) {
|
}
|
||||||
astSources.add(contents);
|
if (!createdFiles.add(filename)) {
|
||||||
astFiles.add(file);
|
// The file has already been encountered since the project was indexed.
|
||||||
|
// Wait for the indexer before updating the file.
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
contents.delete(0, endOfLine); // Remove first line from the file contents.
|
||||||
|
IFile file = TestSourceReader.createFile(cproject.getProject(), new Path(filename), contents.toString());
|
||||||
|
if (astRequested || (j == testData.length - 1 && astFiles.isEmpty())) {
|
||||||
|
int pos = astFiles.indexOf(file);
|
||||||
|
if (pos < 0) {
|
||||||
|
astFiles.add(file);
|
||||||
|
astSources.add(contents);
|
||||||
|
} else {
|
||||||
|
astSources.set(pos, contents);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
|
||||||
|
waitForIndexer(cproject);
|
||||||
}
|
}
|
||||||
CCorePlugin.getIndexManager().setIndexerId(cproject, IPDOMManager.ID_FAST_INDEXER);
|
|
||||||
waitForIndexer(cproject);
|
|
||||||
|
|
||||||
if (DEBUG) {
|
if (DEBUG) {
|
||||||
System.out.println("Project PDOM: " + getName());
|
System.out.println("Project PDOM: " + getName());
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2013, 2014 Google, Inc and others.
|
||||||
|
* All rights reserved. This program and the accompanying materials
|
||||||
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
|
* which accompanies this distribution, and is available at
|
||||||
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
|
*
|
||||||
|
* Contributors:
|
||||||
|
* Sergey Prigogin (Google) - initial API and implementation
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.internal.index.tests;
|
||||||
|
|
||||||
|
import junit.framework.TestSuite;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Index tests involving multiple header and source files.
|
||||||
|
*
|
||||||
|
* The first line of each comment section preceding a test contains the name of the file
|
||||||
|
* to put the contents of the section to. To request the AST of a file, put an asterisk after
|
||||||
|
* the file name.
|
||||||
|
*/
|
||||||
|
public class IndexUpdateMultiFileTest extends IndexBindingResolutionTestBase {
|
||||||
|
|
||||||
|
public IndexUpdateMultiFileTest() {
|
||||||
|
setStrategy(new SinglePDOMTestNamedFilesStrategy(true));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static TestSuite suite() {
|
||||||
|
return suite(IndexUpdateMultiFileTest.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
// A.h
|
||||||
|
// #if !defined(MACRO2)
|
||||||
|
// #define MACRO1
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
// B.h
|
||||||
|
// template <class T>
|
||||||
|
// struct A {
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template <class U>
|
||||||
|
// struct B : public A<typename U::t> {
|
||||||
|
// };
|
||||||
|
//
|
||||||
|
// template <typename T>
|
||||||
|
// struct C {
|
||||||
|
// typedef T t;
|
||||||
|
// void waldo(A<t>* p);
|
||||||
|
// };
|
||||||
|
|
||||||
|
// test.cpp
|
||||||
|
// #include "A.h"
|
||||||
|
// #include "B.h"
|
||||||
|
//
|
||||||
|
// struct E : public C<int> {
|
||||||
|
// void test() {
|
||||||
|
// waldo(new B<E>());
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
|
||||||
|
// test.cpp *
|
||||||
|
// //#include "A.h"
|
||||||
|
// #include "B.h"
|
||||||
|
//
|
||||||
|
// struct E : public C<int> {
|
||||||
|
// void test() {
|
||||||
|
// waldo(new B<E>());
|
||||||
|
// }
|
||||||
|
// };
|
||||||
|
public void test_450888() throws Exception {
|
||||||
|
getProblemFromFirstIdentifier("waldo");
|
||||||
|
// checkBindings();
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue