From a3e3cec9c1ed8905ac7b84543b3e5954cf26bf4d Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Mon, 17 Nov 2014 18:34:49 -0800 Subject: [PATCH] Test case demonstrating the problem for bug 450888. --- .../tests/IndexBindingResolutionTestBase.java | 60 ++++++++++----- .../index/tests/IndexUpdateMultiFileTest.java | 75 +++++++++++++++++++ 2 files changed, 115 insertions(+), 20 deletions(-) create mode 100644 core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateMultiFileTest.java diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java index 2921245f87f..d4ce67ce9dd 100644 --- a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexBindingResolutionTestBase.java @@ -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 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 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()); diff --git a/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateMultiFileTest.java b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateMultiFileTest.java new file mode 100644 index 00000000000..fbca108b6f2 --- /dev/null +++ b/core/org.eclipse.cdt.core.tests/parser/org/eclipse/cdt/internal/index/tests/IndexUpdateMultiFileTest.java @@ -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 + // struct A { + // }; + // + // template + // struct B : public A { + // }; + // + // template + // struct C { + // typedef T t; + // void waldo(A* p); + // }; + + // test.cpp + // #include "A.h" + // #include "B.h" + // + // struct E : public C { + // void test() { + // waldo(new B()); + // } + // }; + + // test.cpp * + // //#include "A.h" + // #include "B.h" + // + // struct E : public C { + // void test() { + // waldo(new B()); + // } + // }; + public void test_450888() throws Exception { + getProblemFromFirstIdentifier("waldo"); +// checkBindings(); + } +}