From 3b3e71a2a1b2a21a25212a8a0130f00ffb14d79d Mon Sep 17 00:00:00 2001 From: Peter Graves Date: Mon, 30 Sep 2002 19:43:26 +0000 Subject: [PATCH] Removed most usage of internal classes in favor of public interfaces. Removed some invalid tests. Come code formating cleanups. --- .../cdt/core/model/tests/ArchiveTests.java | 106 +--- .../cdt/core/model/tests/BinaryTests.java | 136 +---- .../cdt/core/model/tests/FlagTests.java | 5 +- .../model/tests/TranslationUnitTests.java | 116 +--- .../cdt/testplugin/CProjectHelper.java | 519 +++++++++--------- 5 files changed, 289 insertions(+), 593 deletions(-) diff --git a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/ArchiveTests.java b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/ArchiveTests.java index 3cf0dbe7e8e..f581520f0d0 100644 --- a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/ArchiveTests.java +++ b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/ArchiveTests.java @@ -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()); diff --git a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/BinaryTests.java b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/BinaryTests.java index 611e17aa784..c3cf998272d 100644 --- a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/BinaryTests.java +++ b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/BinaryTests.java @@ -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()); diff --git a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/FlagTests.java b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/FlagTests.java index f640aec9541..9da06490c36 100644 --- a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/FlagTests.java +++ b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/FlagTests.java @@ -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 * diff --git a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java index 13c8afbd2e4..9f55a12f0d8 100644 --- a/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java +++ b/core/org.eclipse.cdt.ui.tests/model/org/eclipse/cdt/core/model/tests/TranslationUnitTests.java @@ -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