1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-23 17:05:26 +02:00

Test case demonstrating the problem for bug 450888.

This commit is contained in:
Sergey Prigogin 2014-11-17 18:34:49 -08:00
parent a3962a9bd8
commit a3e3cec9c1
2 changed files with 115 additions and 20 deletions

View file

@ -16,7 +16,9 @@ package org.eclipse.cdt.internal.index.tests;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin;
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.
*
* 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 {
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
* to put the contents of the section to. To request the AST of a file, put an asterisk after
* 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 {
private IIndex index;
@ -597,27 +603,41 @@ public abstract class IndexBindingResolutionTestBase extends BaseTestCase {
testData = TestSourceReader.getContentsForTest(b, "parser", IndexBindingResolutionTestBase.this.getClass(), getName(), 0);
List<IFile> astFiles = new ArrayList<>();
for (int i = 0; i < testData.length; i++) {
StringBuilder contents = testData[i];
int endOfLine = contents.indexOf("\n");
if (endOfLine >= 0)
endOfLine++;
else
endOfLine = contents.length();
String filename = contents.substring(0, endOfLine).trim();
contents.delete(0, endOfLine); // Remove first line from the file contents
boolean astRequested = filename.endsWith("*");
if (astRequested) {
filename = filename.substring(0, filename.length() - 1).trim();
}
IFile file = TestSourceReader.createFile(cproject.getProject(), new Path(filename), contents.toString());
if (astRequested || (i == testData.length - 1 && astFiles.isEmpty())) {
astSources.add(contents);
astFiles.add(file);
for (int i = 0; i < testData.length;) {
Set<String> createdFiles = new HashSet<>();
for (int j = i; j < testData.length; j++, i++) {
StringBuilder contents = testData[j];
int endOfLine = contents.indexOf("\n");
if (endOfLine >= 0) {
endOfLine++;
} else {
endOfLine = contents.length();
}
String filename = contents.substring(0, endOfLine).trim();
boolean astRequested = filename.endsWith("*");
if (astRequested) {
filename = filename.substring(0, filename.length() - 1).trim();
}
if (!createdFiles.add(filename)) {
// 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) {
System.out.println("Project PDOM: " + getName());

View file

@ -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();
}
}