[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[cdt-patch] org.eclipse.cdt.ui.tests - Patch to remove usage of internal classes
|
Attached is a patch org.eclipse.cdt.ui.tests to remove most of the
usage of internal classes. This includes removing a couple tests, and
converting others to use the interfaces provided by the CDT instead of
actual classes. There is also a few code format cleanups as well. I
will commit this.
-Peter
? core/org/eclipse/cdt/tests
Index: core/org/eclipse/cdt/CoreNatureTest.java
===================================================================
RCS file: core/org/eclipse/cdt/CoreNatureTest.java
diff -N core/org/eclipse/cdt/CoreNatureTest.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ core/org/eclipse/cdt/CoreNatureTest.java 30 Sep 2002 19:33:56 -0000
@@ -0,0 +1,231 @@
+package org.eclipse.cdt.core.tests;
+
+/*
+ * (c) Copyright QNX Software Systems Ltd. 2002.
+ * All Rights Reserved.
+ */
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.cdt.core.model.*;
+
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.*;
+import org.eclipse.cdt.core.CCorePlugin;
+import org.eclipse.cdt.core.CCProjectNature;
+import org.eclipse.cdt.core.CProjectNature;
+
+/**
+ *
+ * CoreNatureTest
+ *
+ * @author Peter Graves
+ * @since Aug 28, 2002
+ */
+public class CoreNatureTest extends TestCase {
+ // Shared values setup and torn down
+ private static CoreModel cmodel = null;
+ private static final String TEST_OBJ_FILENAME = "";
+ private static final String TEST_ELF_FILENAME = "";
+ private static final String TEST_ARCHIVE_FILENAME = "";
+ private static final String TEST_TRANSLATION_UNIT_FILENAME = "";
+ private static final String TEST_PROJECT_NAME="myproject";
+ IWorkspace workspace;
+ IWorkspaceRoot root;
+ IProject project_c, project_cc;
+ NullProgressMonitor monitor;
+
+
+ /**
+ * Constructor for CoreNatureTest
+ * @param name
+ */
+ public CoreNatureTest(String name) {
+ super(name);
+ }
+
+ /**
+ * Sets up the test fixture.
+ *
+ * Called before every test case method.
+ *
+ */
+ protected void setUp() {
+ /***
+ * The test of the tests assume that they have a working workspace
+ * and workspace root object to use to create projects/files in,
+ * so we need to get them setup first.
+ */
+ workspace= ResourcesPlugin.getWorkspace();
+ root= workspace.getRoot();
+ monitor = new NullProgressMonitor();
+ if (workspace==null)
+ fail("Workspace was not setup");
+ if (root==null)
+ fail("Workspace root was not setup");
+ }
+
+ /**
+ * Tears down the test fixture.
+ *
+ * Called after every test case method.
+ */
+ protected void tearDown() throws CoreException {
+
+ /* Make sure we delete any of the projects that we create so what
+ * we always have a nice clean workspace to start with.
+ */
+ if (project_c!=null)
+ project_c.delete(true, true, null);
+ if (project_cc!=null)
+ project_cc.delete(true, true, null);
+
+ }
+
+ public static TestSuite suite() {
+ return new TestSuite(CoreNatureTest.class);
+ }
+
+ public static void main (String[] args){
+ junit.textui.TestRunner.run(suite());
+ }
+
+ /****
+ * This test will do some quick sanity to make sure we can only add
+ * the C nature to a project once
+ **/
+ public void testAddCNature() throws CoreException {
+ int i, natureCount;
+ project_c = root.getProject(TEST_PROJECT_NAME+"_c");
+ if (project_c==null)
+ fail("Could not get project");
+ project_c.delete(true, true, null);
+
+ project_c.create(null);
+
+ project_c.open(monitor);
+
+ /* Try to add the C nature to a project a lot of times. It should be
+ * only once, and no exceptions should be thrown.
+ */
+ for (i=0;i<1000;i++) {
+ CProjectNature.addCNature(project_c, monitor);
+ }
+ IProjectDescription description = project_c.getDescription();
+ String[] natures= description.getNatureIds();
+ natureCount=0;
+ for (i= 0; i < natures.length; i++) {
+ if (natures[i]==CProjectNature.C_NATURE_ID)
+ natureCount++;
+ }
+ assertTrue("No cnature added", natureCount!=0);
+ assertTrue("More then 1 cnature added", !(natureCount>1));
+
+
+ }
+
+ /****
+ * This test will do some quick sanity to make sure we can only add
+ * the CC nature to a project once
+ **/
+ public void testAddCCNature() throws CoreException {
+ int i, natureCount;
+ project_cc = root.getProject(TEST_PROJECT_NAME+"_cc");
+ if (project_cc==null)
+ fail("Could not get project");
+ project_cc.delete(true, true, null);
+
+ project_cc.create(null);
+
+ project_cc.open(monitor);
+
+ CProjectNature.addCNature(project_cc, monitor);
+
+ /* Try to add the CC nature to a project a lot of times. It should be
+ * only once, and no exceptions should be thrown.
+ */
+ for (i=0;i<1000;i++) {
+ CCProjectNature.addCCNature(project_cc, monitor);
+ }
+ IProjectDescription description = project_cc.getDescription();
+ String[] natures= description.getNatureIds();
+ natureCount=0;
+ for (i= 0; i < natures.length; i++) {
+ if (natures[i]==CCProjectNature.CC_NATURE_ID)
+ natureCount++;
+ }
+ assertTrue("No ccnature added", natureCount!=0);
+ assertTrue("More then 1 ccnature added", !(natureCount>1));
+
+
+ }
+ /***
+ * This test will make sure convering a project to a C project will work as expected
+ * and can only be done once.
+ **/
+ public void testConvertToC() throws CoreException {
+ boolean failed=false;
+ /***
+ * Setup the test project. We delete and recreate the project to make
+ * sure there is nothing "bad" hanging around
+ */
+ project_c = root.getProject(TEST_PROJECT_NAME+"_c");
+ if (project_c==null)
+ fail("Could not get project");
+ project_c.delete(true, true, null);
+ project_c.create(null);
+ project_c.open(monitor);
+
+ /* Convert the project to a C project. */
+ CCorePlugin.getDefault().convertProjectToC(project_c, monitor, CCorePlugin.getDefault().PLUGIN_ID + ".make");
+
+ assertTrue("It does not exist", project_c.exists());
+ assertTrue("Project has the cnature", project_c.hasNature(CProjectNature.C_NATURE_ID));
+
+ /***
+ * Since the project is not a C project, we should not sucessfully be
+ * able to convert the project to a C project again
+ */
+ try {
+ /* Convert the project to a C project. */
+ CCorePlugin.getDefault().convertProjectToC(project_c, monitor, CCorePlugin.getDefault().PLUGIN_ID + ".make");
+ } catch (CoreException e) {
+ failed=true;
+ }
+ assertTrue("Convert project twice", failed);
+
+
+
+ }
+ /***
+ * This test will make sure convering a project to a C project will work as expected
+ * and can only be done once.
+ **/
+
+ public void testConvertToCC() throws CoreException {
+
+ project_cc = root.getProject(TEST_PROJECT_NAME+"_cc");
+ assertNotNull("Could not get project", project_cc);
+
+ project_cc.delete(true, true, null);
+
+ project_cc.create(null);
+
+ project_cc.open(monitor);
+ //project_cc.open(null);
+ /* Convert the project to a C project. */
+ CCorePlugin.getDefault().convertProjectToCC(project_cc, monitor, CCorePlugin.getDefault().PLUGIN_ID + ".make");
+ if (!project_cc.exists()) {
+ assertNotNull("It does not exist", null);
+ }
+ assertTrue("Project has the ccnature", project_cc.hasNature(CCProjectNature.CC_NATURE_ID));
+ assertTrue("Project still has the cnature", project_cc.hasNature(CProjectNature.C_NATURE_ID));
+
+ }
+
+
+}
Index: model/org/eclipse/cdt/core/model/tests/ArchiveTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/ArchiveTests.java,v
retrieving revision 1.2
diff -u -r1.2 ArchiveTests.java
--- model/org/eclipse/cdt/core/model/tests/ArchiveTests.java 27 Sep 2002 13:46:54 -0000 1.2
+++ model/org/eclipse/cdt/core/model/tests/ArchiveTests.java 30 Sep 2002 19:33:55 -0000
@@ -16,7 +16,7 @@
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 @@
}
- /***
- * 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 void testIsArchive() throws CoreException,FileNotFoundException {
- Archive myArchive;
+ IArchive myArchive;
myArchive=CProjectHelper.findArchive(testProject, "libtestlib_g.a");
assertTrue("A archive", myArchive.isArchive());
Index: model/org/eclipse/cdt/core/model/tests/BinaryTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/BinaryTests.java,v
retrieving revision 1.2
diff -u -r1.2 BinaryTests.java
--- model/org/eclipse/cdt/core/model/tests/BinaryTests.java 27 Sep 2002 13:46:54 -0000 1.2
+++ model/org/eclipse/cdt/core/model/tests/BinaryTests.java 30 Sep 2002 19:33:55 -0000
@@ -16,7 +16,7 @@
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 @@
}
- /***
- * 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 @@
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 @@
* 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 @@
* 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 @@
* 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 @@
* 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 @@
* 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 @@
* 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 @@
* 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 @@
* 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 @@
* 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 @@
* 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 @@
* 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 void testIsBinary() throws CoreException,FileNotFoundException,Exception {
- Binary myBinary;
+ IBinary myBinary;
myBinary=CProjectHelper.findBinary(testProject, "exebig_g");
assertTrue("A Binary", myBinary.isBinary());
Index: model/org/eclipse/cdt/core/model/tests/FlagTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/FlagTests.java,v
retrieving revision 1.2
diff -u -r1.2 FlagTests.java
--- model/org/eclipse/cdt/core/model/tests/FlagTests.java 27 Sep 2002 13:46:54 -0000 1.2
+++ model/org/eclipse/cdt/core/model/tests/FlagTests.java 30 Sep 2002 19:33:56 -0000
@@ -10,8 +10,9 @@
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
*
Index: model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java,v
retrieving revision 1.2
diff -u -r1.2 TranslationUnitTests.java
--- model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java 27 Sep 2002 13:46:54 -0000 1.2
+++ model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java 30 Sep 2002 19:33:55 -0000
@@ -8,7 +8,6 @@
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.core.model.*;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.*;
-import org.eclipse.cdt.internal.core.model.*;
+
/**
@@ -155,101 +154,6 @@
}
- /***
- * 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 void testIsTranslationUnit() throws CoreException,FileNotFoundException {
- TranslationUnit myTranslationUnit;
+ ITranslationUnit myTranslationUnit;
myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
assertTrue("A TranslationUnit", myTranslationUnit.isTranslationUnit());
@@ -269,7 +173,7 @@
* basicly work
*/
public void testGetChildern() {
- TranslationUnit myTranslationUnit;
+ ITranslationUnit myTranslationUnit;
ICElement[] elements;
int x;
@@ -292,8 +196,8 @@
/***
* 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 @@
* 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 @@
* 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 @@
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();
Index: src/org/eclipse/cdt/testplugin/CProjectHelper.java
===================================================================
RCS file: /home/tools/org.eclipse.cdt.ui.tests/src/org/eclipse/cdt/testplugin/CProjectHelper.java,v
retrieving revision 1.3
diff -u -r1.3 CProjectHelper.java
--- src/org/eclipse/cdt/testplugin/CProjectHelper.java 27 Sep 2002 13:46:54 -0000 1.3
+++ src/org/eclipse/cdt/testplugin/CProjectHelper.java 30 Sep 2002 19:33:55 -0000
@@ -7,14 +7,13 @@
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 @@
* 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");
-
-
- /**
- * 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); */
- }
-
-
- /**
- * 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;
- }
-
- /**
- * 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);
- }
-
-
- /**
- * 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 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);
- }
-
-
-
- /**
- * 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;
- }
- }
-
-
+
+ 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);
+ }
+
+ 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;
+ }
+
+ 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;
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
+ * 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();
+
+ 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;
+ }
+ }
+
+
}