1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +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:
Peter Graves 2002-09-30 19:43:26 +00:00
parent 1fc9b37e74
commit 3b3e71a2a1
5 changed files with 289 additions and 593 deletions

View file

@ -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());

View file

@ -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());

View file

@ -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
*

View file

@ -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();

View file

@ -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;
@ -141,28 +140,24 @@ public class CProjectHelper {
/**
* Attempts to find an archive with the given name in the workspace
*/
public static Archive findArchive(ICProject testProject,String name) {
public static IArchive findArchive(ICProject testProject,String name) {
int x;
IArchive[] myArchives;
ArchiveContainer archCont;
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=(ArchiveContainer)testProject.getArchiveContainer();
archCont.getChildren(true);
myArchives=testProject.getArchiveContainer().getArchives();
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))
if (myArchives[x] instanceof Archive) {
return((Archive) myArchives[x]);
}
return(myArchives[x]);
}
return(null);
@ -170,22 +165,18 @@ public class CProjectHelper {
/**
* Attempts to find a binary with the given name in the workspace
*/
public static Binary findBinary(ICProject testProject,String name) {
BinaryContainer binCont;
public static IBinary findBinary(ICProject testProject,String name) {
IBinaryContainer 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);
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))
if (myBinaries[x] instanceof Binary) {
return((Binary) myBinaries[x]);
}
return(myBinaries[x]);
}
@ -195,7 +186,7 @@ public class CProjectHelper {
/**
* Attempts to find an object with the given name in the workspace
*/
public static Binary findObject(ICProject testProject,String name) {
public static IBinary findObject(ICProject testProject,String name) {
int x;
ICElement[] myElements;
myElements=testProject.getChildren();
@ -204,8 +195,8 @@ public class CProjectHelper {
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]);
if (myElements[x] instanceof IBinary) {
return((IBinary) myElements[x]);
}
}
}
@ -214,7 +205,7 @@ public class CProjectHelper {
/**
* Attempts to find a TranslationUnit with the given name in the workspace
*/
public static TranslationUnit findTranslationUnit(ICProject testProject,String name) {
public static ITranslationUnit findTranslationUnit(ICProject testProject,String name) {
int x;
ICElement[] myElements;
myElements=testProject.getChildren();
@ -223,8 +214,8 @@ public class CProjectHelper {
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]);
if (myElements[x] instanceof ITranslationUnit) {
return((ITranslationUnit) myElements[x]);
}
}
}