1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-13 19:25:38 +02:00

Patch for Hoda Amer

Core Tests: 
        Modified CCompletionProposalsTest to complete on a body file that includes a header file.
This commit is contained in:
John Camelon 2003-09-02 17:17:01 +00:00
parent 82d1ef95c0
commit 08ceac730e
4 changed files with 46 additions and 43 deletions

View file

@ -1,3 +1,7 @@
2003-09-02 Hoda Amer
Modified CCompletionProposalsTest to complete on a body file
that includes a header file.
2003-08-28 Andrew Niefer 2003-08-28 Andrew Niefer
Modified BaseSearchTest.setup to properly include the "include.h" file Modified BaseSearchTest.setup to properly include the "include.h" file

View file

@ -18,6 +18,7 @@ import junit.framework.TestSuite;
import org.eclipse.cdt.core.CCProjectNature; import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.internal.core.model.TranslationUnit; import org.eclipse.cdt.internal.core.model.TranslationUnit;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager; import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
@ -43,6 +44,7 @@ public class CompletionProposalsTest extends TestCase{
private final static long MAGIC_NUMBER = 1000; private final static long MAGIC_NUMBER = 1000;
private ICProject fCProject; private ICProject fCProject;
private IFile headerFile; private IFile headerFile;
private IFile bodyFile;
private NullProgressMonitor monitor; private NullProgressMonitor monitor;
public static Test suite() { public static Test suite() {
@ -60,11 +62,14 @@ public class CompletionProposalsTest extends TestCase{
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile(); String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.core.tests").find(new Path("/")).getFile();
fCProject= CProjectHelper.createCProject("TestProject1", "bin"); fCProject= CProjectHelper.createCProject("TestProject1", "bin");
headerFile = fCProject.getProject().getFile("CompletionProposalsTest.h"); bodyFile = fCProject.getProject().getFile("CompletionProposalsTestStart.cpp");
if (!headerFile.exists()) { headerFile = fCProject.getProject().getFile("CompletionProposalsTestStart.h");
if ((!headerFile.exists()) || (!bodyFile.exists())) {
try{ try{
FileInputStream fileIn = new FileInputStream(pluginRoot+ "resources/cfiles/CompletionProposalsTestStart.h"); FileInputStream bodyFileIn = new FileInputStream(pluginRoot+ "resources/cfiles/CompletionProposalsTestStart.cpp");
headerFile.create(fileIn,false, monitor); bodyFile.create(bodyFileIn,false, monitor);
FileInputStream headerFileIn = new FileInputStream(pluginRoot+ "resources/cfiles/CompletionProposalsTestStart.h");
headerFile.create(headerFileIn,false, monitor);
} catch (CoreException e) { } catch (CoreException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -97,9 +102,10 @@ public class CompletionProposalsTest extends TestCase{
public void testCompletionProposals(){ public void testCompletionProposals(){
try{ try{
TranslationUnit tu = new TranslationUnit(fCProject, headerFile); TranslationUnit headerTu = new TranslationUnit(fCProject, headerFile);
TranslationUnit tu = new TranslationUnit(fCProject, bodyFile);
Document document = new Document(tu.getBuffer().getContents()); Document document = new Document(tu.getBuffer().getContents());
int pos = 399; int pos = 255;
int length = 0; int length = 0;
CCompletionProcessor completionProcessor = new CCompletionProcessor(null); CCompletionProcessor completionProcessor = new CCompletionProcessor(null);
ICompletionProposal[] results = completionProcessor.evalProposals(document, pos, length, tu); ICompletionProposal[] results = completionProcessor.evalProposals(document, pos, length, tu);
@ -108,36 +114,30 @@ public class CompletionProposalsTest extends TestCase{
} catch (InterruptedException e1) { } catch (InterruptedException e1) {
fail( "Bogdan's hack did not suffice"); fail( "Bogdan's hack did not suffice");
} }
assertEquals(results.length, 9); assertEquals(results.length, 7);
for (int i = 0; i<results.length; i++){ for (int i = 0; i<results.length; i++){
ICompletionProposal proposal = results[i]; ICompletionProposal proposal = results[i];
String displayString = proposal.getDisplayString(); String displayString = proposal.getDisplayString();
switch(i){ switch(i){
case 0: case 0:
assertEquals(displayString, "anotherField");
break;
case 1:
assertEquals(displayString, "aVariable"); assertEquals(displayString, "aVariable");
break; break;
case 1:
assertEquals(displayString, "aFunction() void");
break;
case 2: case 2:
assertEquals(displayString, "anotherMethod(int, char) void");
break;
case 3:
assertEquals(displayString, "aFunction(char, int) void");
break;
case 4:
assertEquals(displayString, "aClass"); assertEquals(displayString, "aClass");
break; break;
case 5: case 3:
assertEquals(displayString, "anotherClass"); assertEquals(displayString, "anotherClass");
break; break;
case 6: case 4:
assertEquals(displayString, "aStruct"); assertEquals(displayString, "aStruct");
break; break;
case 7: case 5:
assertEquals(displayString, "aMacro"); assertEquals(displayString, "aMacro");
break; break;
case 8: case 6:
assertEquals(displayString, "anEnumeration"); assertEquals(displayString, "anEnumeration");
break; break;
} }

View file

@ -0,0 +1,20 @@
#include "CompletionProposalsTestStart.h"
#define aMacro(x) x+1
int aVariable = 0;
void aFunction();
enum anEnumeration {
first,
second,
third
};
struct aStruct{
int aStructField = 0;
};
void anotherClass::anotherMethod(){
a
};

View file

@ -1,32 +1,11 @@
#define aMacro(x) x+1
int aVariable = 0;
void aFunction(char P1, int P2){
int f1 = 0;
}
enum anEnumeration {
first,
second,
third
};
struct aStruct{
int aStructField = 0;
};
class aClass { class aClass {
public: public:
int aField; int aField;
int aMethod(int P1, char P2){ int aMethod();
return P1 + P2;
}
}; };
class anotherClass { class anotherClass {
public: public:
int anotherField = 0; int anotherField = 0;
void anotherMethod(int P1, char P2){ void anotherMethod();
a
}
}; };