mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Removed most usage of internal classes in favor of public interfaces. Removed some invalid tests. Come code formating cleanups.
This commit is contained in:
parent
1fc9b37e74
commit
3b3e71a2a1
5 changed files with 289 additions and 593 deletions
|
@ -16,7 +16,7 @@ import org.eclipse.cdt.testplugin.util.*;
|
|||
import org.eclipse.cdt.core.model.*;
|
||||
import org.eclipse.core.resources.*;
|
||||
import org.eclipse.core.runtime.*;
|
||||
import org.eclipse.cdt.internal.core.model.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -131,109 +131,9 @@ public class ArchiveTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
/***
|
||||
* This is a simple test to make sure we can not create an Archive with
|
||||
* a non-archive Ifile/IPath
|
||||
* Note: This test is of questionable merit, as people should always be
|
||||
* getting their binaries from the project, not creating them themselves
|
||||
|
||||
*/
|
||||
public void testArchive() throws CoreException {
|
||||
Archive myArchive;
|
||||
boolean caught;
|
||||
|
||||
myArchive=null;
|
||||
caught=false;
|
||||
try {
|
||||
myArchive=new Archive(testProject, cfile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("PR:23601 Created an archive with a C file", caught);
|
||||
myArchive=null;
|
||||
caught=false;
|
||||
try {
|
||||
myArchive=new Archive(testProject, cpath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an archive with a C file", caught);
|
||||
|
||||
myArchive=null;
|
||||
caught=false;
|
||||
try {
|
||||
myArchive=new Archive(testProject, objfile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an archive with a .o file", caught);
|
||||
myArchive=null;
|
||||
caught=false;
|
||||
try {
|
||||
myArchive=new Archive(testProject, objpath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an archive with a .o file", caught);
|
||||
|
||||
myArchive=null;
|
||||
caught=false;
|
||||
try {
|
||||
myArchive=new Archive(testProject, exefile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an archive with a exe file", caught);
|
||||
myArchive=null;
|
||||
caught=false;
|
||||
try {
|
||||
myArchive=new Archive(testProject, exepath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an archive with a exe file", caught);
|
||||
|
||||
myArchive=null;
|
||||
caught=false;
|
||||
try {
|
||||
myArchive=new Archive(testProject, libfile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an archive with a .so file", caught);
|
||||
myArchive=null;
|
||||
caught=false;
|
||||
try {
|
||||
myArchive=new Archive(testProject, libpath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an archive with a .so file", caught);
|
||||
|
||||
myArchive=null;
|
||||
caught=false;
|
||||
try {
|
||||
myArchive=new Archive(testProject, archfile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an archive with a .a file", !caught);
|
||||
myArchive=null;
|
||||
caught=false;
|
||||
try {
|
||||
myArchive=new Archive(testProject, archpath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an archive with a .a file", !caught);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void testGetBinaries() throws CoreException,FileNotFoundException {
|
||||
Archive myArchive;
|
||||
IArchive myArchive;
|
||||
IBinary[] bins;
|
||||
ICElement[] elements;
|
||||
ExpectedStrings expBin, expObj[];
|
||||
|
@ -287,7 +187,7 @@ public class ArchiveTests extends TestCase {
|
|||
*
|
||||
*/
|
||||
public void testIsArchive() throws CoreException,FileNotFoundException {
|
||||
Archive myArchive;
|
||||
IArchive myArchive;
|
||||
myArchive=CProjectHelper.findArchive(testProject, "libtestlib_g.a");
|
||||
|
||||
assertTrue("A archive", myArchive.isArchive());
|
||||
|
|
|
@ -16,7 +16,7 @@ import org.eclipse.cdt.testplugin.util.*;
|
|||
import org.eclipse.cdt.core.model.*;
|
||||
import org.eclipse.core.resources.*;
|
||||
import org.eclipse.core.runtime.*;
|
||||
import org.eclipse.cdt.internal.core.model.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -176,112 +176,12 @@ public class BinaryTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
/***
|
||||
* This is a simple test to make sure we can not create a Binary with
|
||||
* a non-binary Ifile/IPath
|
||||
* Note: This test is of questionable merit, as people should always be
|
||||
* getting their archives from the project, not creating them themselves
|
||||
*/
|
||||
public void testBinary() throws CoreException {
|
||||
Binary myBinary;
|
||||
boolean caught;
|
||||
|
||||
myBinary=null;
|
||||
caught=false;
|
||||
try {
|
||||
myBinary=new Binary(testProject, cfile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("PR:23601 Created an Binary with a C file", caught);
|
||||
myBinary=null;
|
||||
caught=false;
|
||||
try {
|
||||
myBinary=new Binary(testProject, cpath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an Binary with a C file", caught);
|
||||
|
||||
myBinary=null;
|
||||
caught=false;
|
||||
try {
|
||||
myBinary=new Binary(testProject, objfile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
|
||||
assertTrue("Created an Binary with a .o file", !caught);
|
||||
myBinary=null;
|
||||
caught=false;
|
||||
try {
|
||||
myBinary=new Binary(testProject, objpath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an Binary with a .o file", !caught);
|
||||
|
||||
myBinary=null;
|
||||
caught=false;
|
||||
try {
|
||||
myBinary=new Binary(testProject, exefile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an Binary with a exe file", !caught);
|
||||
myBinary=null;
|
||||
caught=false;
|
||||
try {
|
||||
myBinary=new Binary(testProject, exepath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an Binary with a exe file", !caught);
|
||||
|
||||
myBinary=null;
|
||||
caught=false;
|
||||
try {
|
||||
myBinary=new Binary(testProject, libfile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an Binary with a .so file", caught);
|
||||
myBinary=null;
|
||||
caught=false;
|
||||
try {
|
||||
myBinary=new Binary(testProject, libpath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an Binary with a .so file", caught);
|
||||
|
||||
myBinary=null;
|
||||
caught=false;
|
||||
try {
|
||||
myBinary=new Binary(testProject, archfile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an Binary with a .a file", !caught);
|
||||
myBinary=null;
|
||||
caught=false;
|
||||
try {
|
||||
myBinary=new Binary(testProject, archpath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an Binary with a .a file", !caught);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/****
|
||||
* Simple tests to make sure we can get all of a binarys children
|
||||
*/
|
||||
public void testGetChildren() throws CoreException,FileNotFoundException {
|
||||
Binary myBinary;
|
||||
IBinary myBinary;
|
||||
ICElement[] elements;
|
||||
ExpectedStrings expSyms;
|
||||
String[] myStrings = {"atexit", "exit", "_init_libc", "printf", "_fini",
|
||||
|
@ -290,7 +190,7 @@ public class BinaryTests extends TestCase {
|
|||
expSyms=new ExpectedStrings(myStrings);
|
||||
|
||||
/***
|
||||
* Grab the Binary we want to test, and find all the elements in all
|
||||
* Grab the IBinary we want to test, and find all the elements in all
|
||||
* the binarie and make sure we get everything we expect.
|
||||
*/
|
||||
myBinary=CProjectHelper.findBinary(testProject, "test_g");
|
||||
|
@ -307,7 +207,7 @@ public class BinaryTests extends TestCase {
|
|||
* A quick check to make sure the getBSS function works as expected.
|
||||
*/
|
||||
public void testGetBss(){
|
||||
Binary bigBinary,littleBinary;
|
||||
IBinary bigBinary,littleBinary;
|
||||
bigBinary=CProjectHelper.findBinary(testProject, "exebig_g");
|
||||
littleBinary=CProjectHelper.findBinary(testProject, "test_g");
|
||||
|
||||
|
@ -318,7 +218,7 @@ public class BinaryTests extends TestCase {
|
|||
* A quick check to make sure the getBSS function works as expected.
|
||||
*/
|
||||
public void testGetData(){
|
||||
Binary bigBinary,littleBinary;
|
||||
IBinary bigBinary,littleBinary;
|
||||
bigBinary=CProjectHelper.findBinary(testProject, "exebig_g");
|
||||
littleBinary=CProjectHelper.findBinary(testProject, "test_g");
|
||||
if (false) {
|
||||
|
@ -340,11 +240,11 @@ public class BinaryTests extends TestCase {
|
|||
* This is not a in depth test at all.
|
||||
*/
|
||||
public void testGetCpu() {
|
||||
Binary myBinary;
|
||||
IBinary myBinary;
|
||||
myBinary=CProjectHelper.findBinary(testProject, "exebig_g");
|
||||
|
||||
assertTrue("Expected: x86 Got: " + myBinary.getCPU(),myBinary.getCPU().equals("x86"));
|
||||
myBinary=new Binary(testProject, ppcexefile);
|
||||
myBinary=CProjectHelper.findBinary(testProject, ppcexefile.toString());
|
||||
assertTrue("Expected: ppcbe Got: " + myBinary.getCPU(),myBinary.getCPU().equals("ppcbe"));
|
||||
|
||||
}
|
||||
|
@ -353,7 +253,7 @@ public class BinaryTests extends TestCase {
|
|||
* A set of simple tests to make sute getNeededSharedLibs seems to be sane
|
||||
*/
|
||||
public void testGetNeededSharedLibs() {
|
||||
Binary myBinary;
|
||||
IBinary myBinary;
|
||||
String[] exelibs={"libsocket.so.2", "libc.so.2"};
|
||||
String[] bigexelibs={"libc.so.2"};
|
||||
String[] gotlibs;
|
||||
|
@ -393,7 +293,7 @@ public class BinaryTests extends TestCase {
|
|||
* Simple tests for the getSoname method;
|
||||
*/
|
||||
public void testGetSoname() {
|
||||
Binary myBinary;
|
||||
IBinary myBinary;
|
||||
String name;
|
||||
myBinary=CProjectHelper.findBinary(testProject, "test_g");
|
||||
assertTrue(myBinary.getSoname().equals(""));
|
||||
|
@ -410,9 +310,9 @@ public class BinaryTests extends TestCase {
|
|||
* Simple tests for getText
|
||||
*/
|
||||
public void testGetText() {
|
||||
Binary bigBinary,littleBinary;
|
||||
bigBinary=new Binary(testProject, bigexe);
|
||||
littleBinary=new Binary(testProject, exefile);
|
||||
IBinary bigBinary,littleBinary;
|
||||
bigBinary=CProjectHelper.findBinary(testProject, bigexe.toString());
|
||||
littleBinary=CProjectHelper.findBinary(testProject, exefile.toString());
|
||||
if (false) {
|
||||
/****
|
||||
* Since there is no comment on this function, I have no idea what
|
||||
|
@ -431,7 +331,7 @@ public class BinaryTests extends TestCase {
|
|||
* Simple tests for the hadDebug call
|
||||
*/
|
||||
public void testHasDebug() {
|
||||
Binary myBinary;
|
||||
IBinary myBinary;
|
||||
myBinary = CProjectHelper.findBinary(testProject, "test_g");
|
||||
assertTrue(myBinary.hasDebug());
|
||||
myBinary = CProjectHelper.findBinary(testProject, "libtestlib_g.so");
|
||||
|
@ -444,7 +344,7 @@ public class BinaryTests extends TestCase {
|
|||
* Sanity - isBinary and isReadonly should always return true;
|
||||
*/
|
||||
public void testisBinRead() {
|
||||
Binary myBinary;
|
||||
IBinary myBinary;
|
||||
myBinary =CProjectHelper.findBinary(testProject, "test_g");
|
||||
assertTrue(myBinary.isBinary());
|
||||
assertTrue(myBinary.isReadOnly());
|
||||
|
@ -455,7 +355,7 @@ public class BinaryTests extends TestCase {
|
|||
* Quick tests to make sure isObject works as expected.
|
||||
*/
|
||||
public void testIsObject() {
|
||||
Binary myBinary;
|
||||
IBinary myBinary;
|
||||
myBinary=CProjectHelper.findObject(testProject, "exetest.o");
|
||||
assertTrue(myBinary.isObject());
|
||||
|
||||
|
@ -475,7 +375,7 @@ public class BinaryTests extends TestCase {
|
|||
* Quick tests to make sure isSharedLib works as expected.
|
||||
*/
|
||||
public void testIsSharedLib() {
|
||||
Binary myBinary;
|
||||
IBinary myBinary;
|
||||
|
||||
myBinary=CProjectHelper.findObject(testProject, "exetest.o");
|
||||
assertTrue(!myBinary.isSharedLib());
|
||||
|
@ -496,7 +396,7 @@ public class BinaryTests extends TestCase {
|
|||
* Quick tests to make sure isExecutable works as expected.
|
||||
*/
|
||||
public void testIsExecutable() throws InterruptedException {
|
||||
Binary myBinary;
|
||||
IBinary myBinary;
|
||||
myBinary=CProjectHelper.findObject(testProject, "exetest.o");
|
||||
assertTrue(!myBinary.isExecutable());
|
||||
|
||||
|
@ -517,7 +417,7 @@ public class BinaryTests extends TestCase {
|
|||
*
|
||||
*/
|
||||
public void testIsBinary() throws CoreException,FileNotFoundException,Exception {
|
||||
Binary myBinary;
|
||||
IBinary myBinary;
|
||||
|
||||
myBinary=CProjectHelper.findBinary(testProject, "exebig_g");
|
||||
assertTrue("A Binary", myBinary.isBinary());
|
||||
|
|
|
@ -10,8 +10,9 @@ package org.eclipse.cdt.core.model.tests;
|
|||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.model.*;
|
||||
import org.eclipse.cdt.internal.core.model.*;
|
||||
import org.eclipse.cdt.core.model.Flags;
|
||||
import org.eclipse.cdt.internal.core.model.IConstants;
|
||||
|
||||
/**
|
||||
* @author Peter Graves
|
||||
*
|
||||
|
|
|
@ -8,7 +8,6 @@ package org.eclipse.cdt.core.model.tests;
|
|||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.Stack;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
@ -18,7 +17,7 @@ import org.eclipse.cdt.testplugin.util.*;
|
|||
import org.eclipse.cdt.core.model.*;
|
||||
import org.eclipse.core.resources.*;
|
||||
import org.eclipse.core.runtime.*;
|
||||
import org.eclipse.cdt.internal.core.model.*;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
|
@ -155,101 +154,6 @@ public class TranslationUnitTests extends TestCase {
|
|||
}
|
||||
|
||||
|
||||
/***
|
||||
* This is a simple test to make sure we can not create an TranslationUnit with
|
||||
* a non-TranslationUnit Ifile/IPath
|
||||
*/
|
||||
public void testTranslationUnit() throws CoreException {
|
||||
TranslationUnit myTranslationUnit;
|
||||
boolean caught;
|
||||
|
||||
myTranslationUnit=null;
|
||||
caught=false;
|
||||
try {
|
||||
myTranslationUnit=new TranslationUnit(testProject, cfile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an TranslationUnit with a C file", !caught);
|
||||
myTranslationUnit=null;
|
||||
caught=false;
|
||||
try {
|
||||
myTranslationUnit=new TranslationUnit(testProject, cpath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an TranslationUnit with a C file", !caught);
|
||||
|
||||
myTranslationUnit=null;
|
||||
caught=false;
|
||||
try {
|
||||
myTranslationUnit=new TranslationUnit(testProject, objfile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("PR:23601 Created an TranslationUnit with a .o file", caught);
|
||||
myTranslationUnit=null;
|
||||
caught=false;
|
||||
try {
|
||||
myTranslationUnit=new TranslationUnit(testProject, objpath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an TranslationUnit with a .o file", caught);
|
||||
|
||||
myTranslationUnit=null;
|
||||
caught=false;
|
||||
try {
|
||||
myTranslationUnit=new TranslationUnit(testProject, exefile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an TranslationUnit with a exe file", caught);
|
||||
myTranslationUnit=null;
|
||||
caught=false;
|
||||
try {
|
||||
myTranslationUnit=new TranslationUnit(testProject, exepath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an TranslationUnit with a exe file", caught);
|
||||
|
||||
myTranslationUnit=null;
|
||||
caught=false;
|
||||
try {
|
||||
myTranslationUnit=new TranslationUnit(testProject, libfile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an TranslationUnit with a .so file", caught);
|
||||
myTranslationUnit=null;
|
||||
caught=false;
|
||||
try {
|
||||
myTranslationUnit=new TranslationUnit(testProject, libpath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an TranslationUnit with a .so file", caught);
|
||||
|
||||
myTranslationUnit=null;
|
||||
caught=false;
|
||||
try {
|
||||
myTranslationUnit=new TranslationUnit(testProject, archfile);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an TranslationUnit with a .a file", caught);
|
||||
myTranslationUnit=null;
|
||||
caught=false;
|
||||
try {
|
||||
myTranslationUnit=new TranslationUnit(testProject, archpath);
|
||||
} catch (IllegalArgumentException e) {
|
||||
caught=true;
|
||||
}
|
||||
assertTrue("Created an TranslationUnit with a .a file", caught);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
|
@ -257,7 +161,7 @@ public class TranslationUnitTests extends TestCase {
|
|||
*
|
||||
*/
|
||||
public void testIsTranslationUnit() throws CoreException,FileNotFoundException {
|
||||
TranslationUnit myTranslationUnit;
|
||||
ITranslationUnit myTranslationUnit;
|
||||
|
||||
myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
assertTrue("A TranslationUnit", myTranslationUnit.isTranslationUnit());
|
||||
|
@ -269,7 +173,7 @@ public class TranslationUnitTests extends TestCase {
|
|||
* basicly work
|
||||
*/
|
||||
public void testGetChildern() {
|
||||
TranslationUnit myTranslationUnit;
|
||||
ITranslationUnit myTranslationUnit;
|
||||
ICElement[] elements;
|
||||
int x;
|
||||
|
||||
|
@ -292,8 +196,8 @@ public class TranslationUnitTests extends TestCase {
|
|||
/***
|
||||
* Simple sanity tests for the getElement() call
|
||||
*/
|
||||
public void testGetElement() {
|
||||
TranslationUnit myTranslationUnit;
|
||||
public void testGetElement() throws CModelException {
|
||||
ITranslationUnit myTranslationUnit;
|
||||
ICElement myElement;
|
||||
Stack missing=new Stack();
|
||||
int x;
|
||||
|
@ -321,7 +225,7 @@ public class TranslationUnitTests extends TestCase {
|
|||
* Simple sanity tests for the getElementAtLine() call
|
||||
*/
|
||||
public void testGetElementAtLine() throws CoreException {
|
||||
TranslationUnit myTranslationUnit;
|
||||
ITranslationUnit myTranslationUnit;
|
||||
ICElement myElement;
|
||||
Stack missing=new Stack();
|
||||
int x;
|
||||
|
@ -355,13 +259,13 @@ public class TranslationUnitTests extends TestCase {
|
|||
* Simple sanity tests for the getInclude call
|
||||
*/
|
||||
public void testGetInclude() {
|
||||
Include myInclude;
|
||||
IInclude myInclude;
|
||||
int x;
|
||||
String includes[]={"stdio.h", "unistd.h"};
|
||||
TranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
ITranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
|
||||
for (x=0;x<includes.length;x++) {
|
||||
myInclude=(Include)myTranslationUnit.getInclude(includes[x]);
|
||||
myInclude=myTranslationUnit.getInclude(includes[x]);
|
||||
if (myInclude==null)
|
||||
fail("Unable to get include: " + includes[x]);
|
||||
else
|
||||
|
@ -378,7 +282,7 @@ public class TranslationUnitTests extends TestCase {
|
|||
String includes[]={"stdio.h", "unistd.h"};
|
||||
ExpectedStrings myExp= new ExpectedStrings(includes);
|
||||
int x;
|
||||
TranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
ITranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
fail("PR:23478 Unable to test because we can't get the name of an include file");
|
||||
|
||||
myIncludes=myTranslationUnit.getIncludes();
|
||||
|
|
|
@ -7,14 +7,13 @@ import java.util.zip.ZipFile;
|
|||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CProjectNature;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.IArchiveContainer;
|
||||
import org.eclipse.cdt.core.model.IBinaryContainer;
|
||||
import org.eclipse.cdt.core.model.ICFolder;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.internal.core.model.Archive;
|
||||
import org.eclipse.cdt.internal.core.model.Binary;
|
||||
import org.eclipse.cdt.internal.core.model.BinaryContainer;
|
||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.internal.core.model.ArchiveContainer;
|
||||
import org.eclipse.cdt.core.model.IArchive;
|
||||
import org.eclipse.cdt.core.model.IBinary;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
|
@ -36,278 +35,270 @@ import org.eclipse.ui.wizards.datatransfer.ZipFileStructureProvider;
|
|||
* Helper methods to set up a IJavaProject.
|
||||
*/
|
||||
public class CProjectHelper {
|
||||
|
||||
public static final IPath RT_STUBS= new Path("testresources/rtstubs.jar");
|
||||
public static final IPath JUNIT_SRC= new Path("testresources/junit37-noUI-src.zip");
|
||||
|
||||
public static final IPath MYLIB= new Path("testresources/mylib.jar");
|
||||
|
||||
|
||||
public static final IPath RT_STUBS= new Path("testresources/rtstubs.jar");
|
||||
public static final IPath JUNIT_SRC= new Path("testresources/junit37-noUI-src.zip");
|
||||
|
||||
public static final IPath MYLIB= new Path("testresources/mylib.jar");
|
||||
|
||||
|
||||
/**
|
||||
* Creates a ICProject.
|
||||
*/
|
||||
public static ICProject createCProject(String projectName, String binFolderName) throws CoreException {
|
||||
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
|
||||
IProject project= root.getProject(projectName);
|
||||
if (!project.exists()) {
|
||||
project.create(null);
|
||||
} else {
|
||||
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
}
|
||||
|
||||
if (!project.isOpen()) {
|
||||
project.open(null);
|
||||
}
|
||||
|
||||
|
||||
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
|
||||
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
|
||||
}
|
||||
|
||||
ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project);
|
||||
|
||||
return cproject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a ICProject.
|
||||
*/
|
||||
public static void delete(ICProject cproject) throws CoreException {
|
||||
performDummySearch();
|
||||
cproject.getProject().delete(true, true, null);
|
||||
}
|
||||
/**
|
||||
* Creates a ICProject.
|
||||
*/
|
||||
public static ICProject createCProject(String projectName, String binFolderName) throws CoreException {
|
||||
IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
|
||||
IProject project= root.getProject(projectName);
|
||||
if (!project.exists()) {
|
||||
project.create(null);
|
||||
} else {
|
||||
project.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
}
|
||||
|
||||
if (!project.isOpen()) {
|
||||
project.open(null);
|
||||
}
|
||||
|
||||
|
||||
if (!project.hasNature(CProjectNature.C_NATURE_ID)) {
|
||||
addNatureToProject(project, CProjectNature.C_NATURE_ID, null);
|
||||
}
|
||||
|
||||
ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project);
|
||||
|
||||
return cproject;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a ICProject.
|
||||
*/
|
||||
public static void delete(ICProject cproject) throws CoreException {
|
||||
performDummySearch();
|
||||
cproject.getProject().delete(true, true, null);
|
||||
}
|
||||
|
||||
public static void performDummySearch() throws CModelException {
|
||||
/* SearchEngine().searchAllTypeNames(
|
||||
ResourcesPlugin.getWorkspace(),
|
||||
null,
|
||||
null,
|
||||
IJavaSearchConstants.EXACT_MATCH,
|
||||
IJavaSearchConstants.CASE_SENSITIVE,
|
||||
IJavaSearchConstants.CLASS,
|
||||
SearchEngine.createJavaSearchScope(new IJavaElement[0]),
|
||||
new Requestor(),
|
||||
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
|
||||
null); */
|
||||
}
|
||||
public static void performDummySearch() throws CModelException {
|
||||
/* SearchEngine().searchAllTypeNames(
|
||||
ResourcesPlugin.getWorkspace(),
|
||||
null,
|
||||
null,
|
||||
IJavaSearchConstants.EXACT_MATCH,
|
||||
IJavaSearchConstants.CASE_SENSITIVE,
|
||||
IJavaSearchConstants.CLASS,
|
||||
SearchEngine.createJavaSearchScope(new IJavaElement[0]),
|
||||
new Requestor(),
|
||||
IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH,
|
||||
null); */
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a source container to a ICProject.
|
||||
*/
|
||||
public static ICFolder addSourceContainer(ICProject cproject, String containerName) throws CoreException {
|
||||
IProject project= cproject.getProject();
|
||||
IContainer container= null;
|
||||
if (containerName == null || containerName.length() == 0) {
|
||||
container= project;
|
||||
} else {
|
||||
IFolder folder= project.getFolder(containerName);
|
||||
if (!folder.exists()) {
|
||||
folder.create(false, true, null);
|
||||
}
|
||||
container= folder;
|
||||
}
|
||||
/**
|
||||
* Adds a source container to a ICProject.
|
||||
*/
|
||||
public static ICFolder addSourceContainer(ICProject cproject, String containerName) throws CoreException {
|
||||
IProject project= cproject.getProject();
|
||||
IContainer container= null;
|
||||
if (containerName == null || containerName.length() == 0) {
|
||||
container= project;
|
||||
} else {
|
||||
IFolder folder= project.getFolder(containerName);
|
||||
if (!folder.exists()) {
|
||||
folder.create(false, true, null);
|
||||
}
|
||||
container= folder;
|
||||
}
|
||||
|
||||
return (ICFolder)container;
|
||||
}
|
||||
return (ICFolder)container;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a source container to a ICProject and imports all files contained
|
||||
* in the given Zip file.
|
||||
*/
|
||||
public static ICFolder addSourceContainerWithImport(ICProject cproject, String containerName, ZipFile zipFile) throws InvocationTargetException, CoreException {
|
||||
ICFolder root= addSourceContainer(cproject, containerName);
|
||||
importFilesFromZip(zipFile, root.getPath(), null);
|
||||
return root;
|
||||
}
|
||||
/**
|
||||
* Adds a source container to a ICProject and imports all files contained
|
||||
* in the given Zip file.
|
||||
*/
|
||||
public static ICFolder addSourceContainerWithImport(ICProject cproject, String containerName, ZipFile zipFile) throws InvocationTargetException, CoreException {
|
||||
ICFolder root= addSourceContainer(cproject, containerName);
|
||||
importFilesFromZip(zipFile, root.getPath(), null);
|
||||
return root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a source folder from a IJavaProject.
|
||||
*/
|
||||
public static void removeSourceContainer(ICProject cproject, String containerName) throws CoreException {
|
||||
IFolder folder= cproject.getProject().getFolder(containerName);
|
||||
folder.delete(true, null);
|
||||
}
|
||||
/**
|
||||
* Removes a source folder from a IJavaProject.
|
||||
*/
|
||||
public static void removeSourceContainer(ICProject cproject, String containerName) throws CoreException {
|
||||
IFolder folder= cproject.getProject().getFolder(containerName);
|
||||
folder.delete(true, null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Adds a required project entry.
|
||||
*/
|
||||
public static void addRequiredProject(ICProject cproject, ICProject required) throws CModelException {
|
||||
//IClasspathEntry cpe= JavaCore.newProjectEntry(required.getProject().getFullPath());
|
||||
//addToClasspath(cproject, cpe);
|
||||
}
|
||||
/**
|
||||
* Adds a required project entry.
|
||||
*/
|
||||
public static void addRequiredProject(ICProject cproject, ICProject required) throws CModelException {
|
||||
//IClasspathEntry cpe= JavaCore.newProjectEntry(required.getProject().getFullPath());
|
||||
//addToClasspath(cproject, cpe);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to find an archive with the given name in the workspace
|
||||
*/
|
||||
public static Archive findArchive(ICProject testProject,String name) {
|
||||
int x;
|
||||
IArchive[] myArchives;
|
||||
ArchiveContainer archCont;
|
||||
/***
|
||||
* Since ArchiveContainer.getArchives does not wait until
|
||||
* all the archives in the project have been parsed before
|
||||
* returning the list, we have to do a sync ArchiveContainer.getChildren
|
||||
* first to make sure we find all the archives.
|
||||
*/
|
||||
archCont=(ArchiveContainer)testProject.getArchiveContainer();
|
||||
archCont.getChildren(true);
|
||||
myArchives=testProject.getArchiveContainer().getArchives();
|
||||
if (myArchives.length<1)
|
||||
return(null);
|
||||
for (x=0;x<myArchives.length;x++) {
|
||||
if (myArchives[x].getElementName().equals(name))
|
||||
if (myArchives[x] instanceof Archive) {
|
||||
return((Archive) myArchives[x]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return(null);
|
||||
}
|
||||
/**
|
||||
* Attempts to find a binary with the given name in the workspace
|
||||
*/
|
||||
public static Binary findBinary(ICProject testProject,String name) {
|
||||
BinaryContainer binCont;
|
||||
int x;
|
||||
IBinary[] myBinaries;
|
||||
binCont=(BinaryContainer)testProject.getBinaryContainer();
|
||||
/* Make sure we wait for the childern to be parsed, see comment about
|
||||
* ArchiveContainer.getArchives() above */
|
||||
binCont.getChildren(true);
|
||||
myBinaries=binCont.getBinaries();
|
||||
if (myBinaries.length<1)
|
||||
return(null);
|
||||
for (x=0;x<myBinaries.length;x++) {
|
||||
if (myBinaries[x].getElementName().equals(name))
|
||||
if (myBinaries[x] instanceof Binary) {
|
||||
return((Binary) myBinaries[x]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return(null);
|
||||
}
|
||||
/**
|
||||
* Attempts to find an archive with the given name in the workspace
|
||||
*/
|
||||
public static IArchive findArchive(ICProject testProject,String name) {
|
||||
int x;
|
||||
IArchive[] myArchives;
|
||||
IArchiveContainer archCont;
|
||||
/***
|
||||
* Since ArchiveContainer.getArchives does not wait until
|
||||
* all the archives in the project have been parsed before
|
||||
* returning the list, we have to do a sync ArchiveContainer.getChildren
|
||||
* first to make sure we find all the archives.
|
||||
*/
|
||||
archCont=testProject.getArchiveContainer();
|
||||
|
||||
/**
|
||||
* Attempts to find an object with the given name in the workspace
|
||||
*/
|
||||
public static Binary findObject(ICProject testProject,String name) {
|
||||
int x;
|
||||
ICElement[] myElements;
|
||||
myElements=testProject.getChildren();
|
||||
if (myElements.length<1)
|
||||
return(null);
|
||||
for (x=0;x<myElements.length;x++) {
|
||||
if (myElements[x].getElementName().equals(name))
|
||||
if (myElements[x] instanceof ICElement) {
|
||||
if (myElements[x] instanceof Binary) {
|
||||
return((Binary) myElements[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(null);
|
||||
}
|
||||
/**
|
||||
* Attempts to find a TranslationUnit with the given name in the workspace
|
||||
*/
|
||||
public static TranslationUnit findTranslationUnit(ICProject testProject,String name) {
|
||||
int x;
|
||||
ICElement[] myElements;
|
||||
myElements=testProject.getChildren();
|
||||
if (myElements.length<1)
|
||||
return(null);
|
||||
for (x=0;x<myElements.length;x++) {
|
||||
if (myElements[x].getElementName().equals(name))
|
||||
if (myElements[x] instanceof ICElement) {
|
||||
if (myElements[x] instanceof TranslationUnit) {
|
||||
return((TranslationUnit) myElements[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(null);
|
||||
}
|
||||
myArchives=archCont.getArchives();
|
||||
if (myArchives.length<1)
|
||||
return(null);
|
||||
for (x=0;x<myArchives.length;x++) {
|
||||
if (myArchives[x].getElementName().equals(name))
|
||||
return(myArchives[x]);
|
||||
|
||||
}
|
||||
return(null);
|
||||
}
|
||||
/**
|
||||
* Attempts to find a binary with the given name in the workspace
|
||||
*/
|
||||
public static IBinary findBinary(ICProject testProject,String name) {
|
||||
IBinaryContainer binCont;
|
||||
int x;
|
||||
IBinary[] myBinaries;
|
||||
binCont=testProject.getBinaryContainer();
|
||||
|
||||
myBinaries=binCont.getBinaries();
|
||||
if (myBinaries.length<1)
|
||||
return(null);
|
||||
for (x=0;x<myBinaries.length;x++) {
|
||||
if (myBinaries[x].getElementName().equals(name))
|
||||
return(myBinaries[x]);
|
||||
|
||||
|
||||
}
|
||||
return(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to find an object with the given name in the workspace
|
||||
*/
|
||||
public static IBinary findObject(ICProject testProject,String name) {
|
||||
int x;
|
||||
ICElement[] myElements;
|
||||
myElements=testProject.getChildren();
|
||||
if (myElements.length<1)
|
||||
return(null);
|
||||
for (x=0;x<myElements.length;x++) {
|
||||
if (myElements[x].getElementName().equals(name))
|
||||
if (myElements[x] instanceof ICElement) {
|
||||
if (myElements[x] instanceof IBinary) {
|
||||
return((IBinary) myElements[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(null);
|
||||
}
|
||||
/**
|
||||
* Attempts to find a TranslationUnit with the given name in the workspace
|
||||
*/
|
||||
public static ITranslationUnit findTranslationUnit(ICProject testProject,String name) {
|
||||
int x;
|
||||
ICElement[] myElements;
|
||||
myElements=testProject.getChildren();
|
||||
if (myElements.length<1)
|
||||
return(null);
|
||||
for (x=0;x<myElements.length;x++) {
|
||||
if (myElements[x].getElementName().equals(name))
|
||||
if (myElements[x] instanceof ICElement) {
|
||||
if (myElements[x] instanceof ITranslationUnit) {
|
||||
return((ITranslationUnit) myElements[x]);
|
||||
}
|
||||
}
|
||||
}
|
||||
return(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to find an element with the given name in the workspace
|
||||
*/
|
||||
public static ICElement findElement(ICProject testProject,String name) {
|
||||
int x;
|
||||
ICElement[] myElements;
|
||||
myElements=testProject.getChildren();
|
||||
if (myElements.length<1)
|
||||
return(null);
|
||||
for (x=0;x<myElements.length;x++) {
|
||||
if (myElements[x].getElementName().equals(name))
|
||||
if (myElements[x] instanceof ICElement) {
|
||||
return((ICElement) myElements[x]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return(null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Try to find rt.jar
|
||||
*/
|
||||
public static IPath[] findRtJar() {
|
||||
File rtStubs= CTestPlugin.getDefault().getFileInPlugin(RT_STUBS);
|
||||
if (rtStubs != null && rtStubs.exists()) {
|
||||
return new IPath[] {
|
||||
new Path(rtStubs.getPath()),
|
||||
null,
|
||||
null
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
IVMInstall vmInstall= JavaRuntime.getDefaultVMInstall();
|
||||
if (vmInstall != null) {
|
||||
LibraryLocation loc= vmInstall.getVMInstallType().getDefaultLibraryLocation(vmInstall.getInstallLocation());
|
||||
if (loc != null) {
|
||||
return new IPath[] {
|
||||
new Path(loc.getSystemLibrary().getPath()),
|
||||
new Path(loc.getSystemLibrarySource().getPath()),
|
||||
loc.getPackageRootPath()
|
||||
};
|
||||
}
|
||||
}*/
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
String[] prevNatures= description.getNatureIds();
|
||||
String[] newNatures= new String[prevNatures.length + 1];
|
||||
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
|
||||
newNatures[prevNatures.length]= natureId;
|
||||
description.setNatureIds(newNatures);
|
||||
proj.setDescription(description, monitor);
|
||||
}
|
||||
|
||||
private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException {
|
||||
ZipFileStructureProvider structureProvider= new ZipFileStructureProvider(srcZipFile);
|
||||
try {
|
||||
ImportOperation op= new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, new ImportOverwriteQuery());
|
||||
op.run(monitor);
|
||||
} catch (InterruptedException e) {
|
||||
// should not happen
|
||||
}
|
||||
}
|
||||
|
||||
private static class ImportOverwriteQuery implements IOverwriteQuery {
|
||||
public String queryOverwrite(String file) {
|
||||
return ALL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to find an element with the given name in the workspace
|
||||
*/
|
||||
public static ICElement findElement(ICProject testProject,String name) {
|
||||
int x;
|
||||
ICElement[] myElements;
|
||||
myElements=testProject.getChildren();
|
||||
if (myElements.length<1)
|
||||
return(null);
|
||||
for (x=0;x<myElements.length;x++) {
|
||||
if (myElements[x].getElementName().equals(name))
|
||||
if (myElements[x] instanceof ICElement) {
|
||||
return((ICElement) myElements[x]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
return(null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Try to find rt.jar
|
||||
*/
|
||||
public static IPath[] findRtJar() {
|
||||
File rtStubs= CTestPlugin.getDefault().getFileInPlugin(RT_STUBS);
|
||||
if (rtStubs != null && rtStubs.exists()) {
|
||||
return new IPath[] {
|
||||
new Path(rtStubs.getPath()),
|
||||
null,
|
||||
null
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
IVMInstall vmInstall= JavaRuntime.getDefaultVMInstall();
|
||||
if (vmInstall != null) {
|
||||
LibraryLocation loc= vmInstall.getVMInstallType().getDefaultLibraryLocation(vmInstall.getInstallLocation());
|
||||
if (loc != null) {
|
||||
return new IPath[] {
|
||||
new Path(loc.getSystemLibrary().getPath()),
|
||||
new Path(loc.getSystemLibrarySource().getPath()),
|
||||
loc.getPackageRootPath()
|
||||
};
|
||||
}
|
||||
}*/
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void addNatureToProject(IProject proj, String natureId, IProgressMonitor monitor) throws CoreException {
|
||||
IProjectDescription description = proj.getDescription();
|
||||
String[] prevNatures= description.getNatureIds();
|
||||
String[] newNatures= new String[prevNatures.length + 1];
|
||||
System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
|
||||
newNatures[prevNatures.length]= natureId;
|
||||
description.setNatureIds(newNatures);
|
||||
proj.setDescription(description, monitor);
|
||||
}
|
||||
|
||||
private static void importFilesFromZip(ZipFile srcZipFile, IPath destPath, IProgressMonitor monitor) throws InvocationTargetException {
|
||||
ZipFileStructureProvider structureProvider= new ZipFileStructureProvider(srcZipFile);
|
||||
try {
|
||||
ImportOperation op= new ImportOperation(destPath, structureProvider.getRoot(), structureProvider, new ImportOverwriteQuery());
|
||||
op.run(monitor);
|
||||
} catch (InterruptedException e) {
|
||||
// should not happen
|
||||
}
|
||||
}
|
||||
|
||||
private static class ImportOverwriteQuery implements IOverwriteQuery {
|
||||
public String queryOverwrite(String file) {
|
||||
return ALL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue