mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-24 09:25:31 +02:00
A test for Add Include.
This commit is contained in:
parent
78ff7d9795
commit
59fd518713
13 changed files with 206 additions and 0 deletions
|
@ -0,0 +1 @@
|
|||
int x = ONE;
|
|
@ -0,0 +1,2 @@
|
|||
#include "Macro.h"
|
||||
int x = ONE;
|
|
@ -0,0 +1 @@
|
|||
#define ONE 1
|
|
@ -0,0 +1,5 @@
|
|||
#include "A.h"
|
||||
#include "Macro.h"
|
||||
#include "OverloadedFunction.h"
|
||||
#include "VariableType.h"
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#include "A.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
void test() {
|
||||
func(0);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
#include "A.h"
|
||||
#include "OverloadedFunction.h"
|
||||
|
||||
namespace ns3 {
|
||||
|
||||
void test() {
|
||||
func(0);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,6 @@
|
|||
namespace ns3 {
|
||||
|
||||
void func(int p);
|
||||
void func(char* p);
|
||||
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
#include "VariableTypeHelper.h"
|
||||
|
||||
namespace ns2 {
|
||||
|
||||
void VT::method() {
|
||||
a_->m();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#include "VariableTypeHelper.h"
|
||||
#include "VariableType.h"
|
||||
|
||||
using ns1::A;
|
||||
|
||||
namespace ns2 {
|
||||
|
||||
void VT::method() {
|
||||
a_->m();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
namespace ns1 {
|
||||
|
||||
class A {
|
||||
A(int x);
|
||||
A(int x, int y);
|
||||
~A();
|
||||
void m();
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
namespace ns1 { class A; }
|
||||
|
||||
namespace ns2 {
|
||||
|
||||
class VT {
|
||||
void method();
|
||||
ns1::A* a_;
|
||||
};
|
||||
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2009 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.ui.tests.text;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
import junit.extensions.TestSetup;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.source.SourceViewer;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.AddIncludeOnSelectionAction;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
|
||||
/**
|
||||
* Tests the AddIncludeOnSelectionAction.
|
||||
*/
|
||||
public class AddIncludeTest extends TestCase {
|
||||
private static final String PROJECT= "AddIncludeTests";
|
||||
|
||||
private static final class EmptyBundle extends ListResourceBundle {
|
||||
protected Object[][] getContents() {
|
||||
return new Object[0][];
|
||||
}
|
||||
}
|
||||
|
||||
protected static class AddIncludeTestSetup extends TestSetup {
|
||||
private ICProject fCProject;
|
||||
|
||||
public AddIncludeTestSetup(Test test) {
|
||||
super(test);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fCProject= EditorTestHelper.createCProject(PROJECT, "resources/addInclude");
|
||||
CCorePlugin.getIndexManager().setIndexerId(fCProject, IPDOMManager.ID_FAST_INDEXER);
|
||||
// Wait until the indexer is done
|
||||
assertTrue(CCorePlugin.getIndexManager().joinIndexer(10000, new NullProgressMonitor()));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (fCProject != null)
|
||||
CProjectHelper.delete(fCProject);
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
return new AddIncludeTestSetup(new TestSuite(AddIncludeTest.class));
|
||||
}
|
||||
|
||||
private CEditor fEditor;
|
||||
private SourceViewer fSourceViewer;
|
||||
private IDocument fDocument;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
String filename= createFileName("");
|
||||
fEditor= (CEditor) EditorTestHelper.openInEditor(ResourceTestHelper.findFile(filename), true);
|
||||
fSourceViewer= EditorTestHelper.getSourceViewer(fEditor);
|
||||
fDocument= fSourceViewer.getDocument();
|
||||
IWorkingCopy tu = CUIPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(fEditor.getEditorInput());
|
||||
tu.makeConsistent(new NullProgressMonitor(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
EditorTestHelper.closeEditor(fEditor);
|
||||
}
|
||||
|
||||
private void assertAddIncludeResult() throws Exception {
|
||||
new AddIncludeOnSelectionAction(fEditor).run();
|
||||
|
||||
String file= createFileName(".expected");
|
||||
String expected= ResourceTestHelper.read(file).toString();
|
||||
assertEquals(expected, fDocument.get());
|
||||
}
|
||||
|
||||
private String createFileName(String suffix) {
|
||||
String name= getName();
|
||||
name= name.substring(4); // Strip "test" prefix.
|
||||
return "/" + PROJECT + "/src/" + name + ".cpp" + suffix;
|
||||
}
|
||||
|
||||
private void select(String name) {
|
||||
final int offset = fDocument.get().indexOf(name);
|
||||
assertTrue(offset >= 0);
|
||||
fSourceViewer.setSelectedRange(offset, name.length());
|
||||
}
|
||||
|
||||
public void testVariableType() throws Exception {
|
||||
select("a_");
|
||||
assertAddIncludeResult();
|
||||
}
|
||||
|
||||
public void testOverloadedFunction() throws Exception {
|
||||
select("func");
|
||||
assertAddIncludeResult();
|
||||
}
|
||||
|
||||
public void testMacro() throws Exception {
|
||||
select("ONE");
|
||||
assertAddIncludeResult();
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@
|
|||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Andrew Ferguson (Symbian)
|
||||
* Sergey Prigogin (Google)
|
||||
*******************************************************************************/
|
||||
|
||||
package org.eclipse.cdt.ui.tests.text;
|
||||
|
@ -74,5 +75,8 @@ public class TextTestSuite extends TestSuite {
|
|||
// block comment tests
|
||||
addTest(AddBlockCommentTest.suite());
|
||||
addTest(RemoveBlockCommentTest.suite());
|
||||
|
||||
// add include
|
||||
addTest(AddIncludeTest.suite());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue