mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 09:45:39 +02:00
Initial JUnit model tests from Peter Graves's submission
This commit is contained in:
parent
e5d1c04186
commit
a000b4d73b
56 changed files with 2428 additions and 2 deletions
|
@ -3,6 +3,7 @@
|
|||
<classpathentry kind="src" path="src/"/>
|
||||
<classpathentry kind="src" path="ui"/>
|
||||
<classpathentry kind="src" path="core"/>
|
||||
<classpathentry kind="src" path="model"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.core.boot"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.core.resources"/>
|
||||
<classpathentry kind="src" path="/org.eclipse.core.runtime"/>
|
||||
|
|
|
@ -1 +1 @@
|
|||
source.cdttests.jar = src/
|
||||
source.cdttests.jar = src/, ui/, core/, model/
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
package org.eclipse.cdt.core.model.tests;
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.TranslationUnit;
|
||||
import org.eclipse.cdt.testplugin.util.*;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* AllTests.java
|
||||
* This is the main entry point for running this suite of JUnit tests
|
||||
* for all tests within the package "org.eclipse.cdt.core.model"
|
||||
*
|
||||
* @author Judy N. Green
|
||||
* @since Jul 19, 2002
|
||||
*/
|
||||
public class AllCoreTests {
|
||||
|
||||
public static void main(String[] args) {
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite();
|
||||
|
||||
// Just add more test cases here as you create them for
|
||||
// each class being tested
|
||||
|
||||
suite.addTest(CModelTests.suite());
|
||||
suite.addTest(CModelExceptionTest.suite());
|
||||
suite.addTest(FlagTests.suite());
|
||||
suite.addTest(ArchiveTests.suite());
|
||||
suite.addTest(TranslationUnitTests.suite());
|
||||
return suite;
|
||||
|
||||
}
|
||||
} // End of AllCoreTests.java
|
||||
|
|
@ -0,0 +1,305 @@
|
|||
package org.eclipse.cdt.core.model.tests;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import org.eclipse.cdt.testplugin.*;
|
||||
import org.eclipse.cdt.testplugin.util.*;
|
||||
import org.eclipse.cdt.core.model.*;
|
||||
import org.eclipse.core.internal.runtime.Log;
|
||||
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;
|
||||
import org.eclipse.cdt.internal.core.model.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author Peter Graves
|
||||
*
|
||||
* This file contains a set of generic tests for the core C model's Archive
|
||||
* class. There is nothing exotic here, mostly just sanity type tests
|
||||
*
|
||||
*/
|
||||
public class ArchiveTests extends TestCase {
|
||||
IWorkspace workspace;
|
||||
IWorkspaceRoot root;
|
||||
ICProject testProject;
|
||||
IFile cfile, exefile, libfile, archfile, objfile;
|
||||
Path cpath, exepath, libpath, archpath, objpath;
|
||||
NullProgressMonitor monitor;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for ArchiveTests
|
||||
* @param name
|
||||
*/
|
||||
public ArchiveTests(String name) {
|
||||
super(name);
|
||||
/***
|
||||
* The 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");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the test fixture.
|
||||
*
|
||||
* Called before every test case method.
|
||||
*
|
||||
* Example code test the packages in the project
|
||||
* "com.qnx.tools.ide.cdt.core"
|
||||
*/
|
||||
protected void setUp() throws CoreException,FileNotFoundException {
|
||||
|
||||
/***
|
||||
* Setup the various files, paths and projects that are needed by the
|
||||
* tests
|
||||
*/
|
||||
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.ui.tests").find(new Path("/")).getFile();
|
||||
testProject=CProjectHelper.createCProject("filetest", "none");
|
||||
if (testProject==null)
|
||||
fail("Unable to create project");
|
||||
|
||||
cfile = testProject.getProject().getFile("exetest.c");
|
||||
if (!cfile.exists()) {
|
||||
cfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/main.c"),false, monitor);
|
||||
|
||||
}
|
||||
cpath=new Path(workspace.getRoot().getLocation()+"/filetest/main.c");
|
||||
|
||||
objfile = testProject.getProject().getFile("exetest.o");
|
||||
if (!objfile.exists()) {
|
||||
objfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/main.o"),false, monitor);
|
||||
|
||||
}
|
||||
objpath=new Path(workspace.getRoot().getLocation()+"/filetest/main.o");
|
||||
|
||||
exefile = testProject.getProject().getFile("test_g");
|
||||
if (!exefile.exists()) {
|
||||
exefile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/exe_g"),false, monitor);
|
||||
|
||||
}
|
||||
exepath=new Path(workspace.getRoot().getLocation()+"/filetest/exe_g");
|
||||
|
||||
archfile = testProject.getProject().getFile("libtestlib_g.a");
|
||||
if (!archfile.exists()) {
|
||||
archfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/a.g/libtestlib_g.a"),false, monitor);
|
||||
|
||||
}
|
||||
libpath=new Path(workspace.getRoot().getLocation()+"/filetest/libtestlib_g.so");
|
||||
|
||||
libfile = testProject.getProject().getFile("libtestlib_g.so");
|
||||
if (!libfile.exists()) {
|
||||
libfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/so.g/libtestlib_g.so"),false, monitor);
|
||||
|
||||
}
|
||||
archpath=new Path(workspace.getRoot().getLocation()+"/filetest/libtestlib_g.a");
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the test fixture.
|
||||
*
|
||||
* Called after every test case method.
|
||||
*/
|
||||
protected void tearDown() throws CoreException {
|
||||
CProjectHelper.delete(testProject);
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(ArchiveTests.class);
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 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:12037 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;
|
||||
IBinary[] bins;
|
||||
ICElement[] elements;
|
||||
ExpectedStrings expBin, expObj[];
|
||||
String[] myStrings;
|
||||
int x;
|
||||
IArchive[] myArchives;
|
||||
|
||||
|
||||
/****
|
||||
* Setup the expected strings for the binaries, and the elements within
|
||||
* the binaries
|
||||
*/
|
||||
myStrings=new String[2];
|
||||
myStrings[0]="test.o";
|
||||
myStrings[1]="test2.o";
|
||||
expBin=new ExpectedStrings(myStrings);
|
||||
|
||||
expObj=new ExpectedStrings[2];
|
||||
myStrings[0]="func1";
|
||||
myStrings[1]="func2";
|
||||
expObj[0]=new ExpectedStrings(myStrings);
|
||||
myStrings[0]="test2func1";
|
||||
myStrings[1]="test2func2";
|
||||
expObj[1]=new ExpectedStrings(myStrings);
|
||||
|
||||
/***
|
||||
* Grab the archive we want to test, and find all the binaries and
|
||||
* all the elements in all the binaries and make sure we get
|
||||
* everything we expect.
|
||||
*/
|
||||
myArchive=CProjectHelper.findArchive(testProject, "libtestlib_g.a");
|
||||
if (myArchive==null)
|
||||
fail("Could not find archive");
|
||||
bins=myArchive.getBinaries();
|
||||
for (x=0;x<bins.length;x++) {
|
||||
expBin.foundString(bins[x].getElementName());
|
||||
elements=bins[x].getChildren();
|
||||
for (int i=0;i<elements.length;i++) {
|
||||
expObj[x].foundString(elements[i].getElementName());
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(expBin.getMissingString(), expBin.gotAll());
|
||||
assertTrue(expBin.getExtraString(), !expBin.gotExtra());
|
||||
for (x=0;x<expObj.length;x++) {
|
||||
assertTrue("Binary " + expBin.expStrings[x] + " " +expObj[x].getMissingString(), expObj[x].gotAll());
|
||||
assertTrue("Binary " + expBin.expStrings[x] + " " + expObj[x].getExtraString(), !expObj[x].gotExtra());
|
||||
}
|
||||
}
|
||||
/***
|
||||
* Simple sanity test to make sure Archive.isArchive returns true
|
||||
*
|
||||
*/
|
||||
public void testIsArchive() throws CoreException,FileNotFoundException {
|
||||
Archive myArchive;
|
||||
myArchive=CProjectHelper.findArchive(testProject, "libtestlib_g.a");
|
||||
|
||||
assertTrue("A archive", myArchive.isArchive());
|
||||
myArchive=null;
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,534 @@
|
|||
package org.eclipse.cdt.core.model.tests;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import org.eclipse.cdt.testplugin.*;
|
||||
import org.eclipse.cdt.testplugin.util.*;
|
||||
import org.eclipse.cdt.core.model.*;
|
||||
import org.eclipse.core.internal.runtime.Log;
|
||||
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;
|
||||
import org.eclipse.cdt.internal.core.model.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author Peter Graves
|
||||
*
|
||||
* This file contains a set of generic tests for the core C model's Binary
|
||||
* class. There is nothing exotic here, mostly just sanity type tests
|
||||
*
|
||||
*/
|
||||
public class BinaryTests extends TestCase {
|
||||
IWorkspace workspace;
|
||||
IWorkspaceRoot root;
|
||||
ICProject testProject;
|
||||
IFile cfile, exefile, libfile, archfile, objfile, bigexe, ppcexefile, ndexe;
|
||||
Path cpath, exepath, libpath, archpath, objpath;
|
||||
NullProgressMonitor monitor;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for BinaryTests
|
||||
* @param name
|
||||
*/
|
||||
public BinaryTests(String name) {
|
||||
super(name);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Object#finalize()
|
||||
*/
|
||||
protected void finalize() throws Throwable {
|
||||
super.finalize();
|
||||
|
||||
/**
|
||||
* Make sure we leave the workspace clean for the next set of tests
|
||||
*/
|
||||
CProjectHelper.delete(testProject);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sets up the test fixture.
|
||||
*
|
||||
* Called before every test case method.
|
||||
*
|
||||
* Example code test the packages in the project
|
||||
* "com.qnx.tools.ide.cdt.core"
|
||||
*/
|
||||
protected void setUp() throws CoreException,FileNotFoundException {
|
||||
String pluginRoot;
|
||||
/***
|
||||
* 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");
|
||||
|
||||
|
||||
/***
|
||||
* Setup the various files, paths and projects that are needed by the
|
||||
* tests
|
||||
*/
|
||||
|
||||
testProject=CProjectHelper.createCProject("filetest", "none");
|
||||
if (testProject==null)
|
||||
fail("Unable to create project");
|
||||
|
||||
pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.ui.tests").find(new Path("/")).getFile();
|
||||
|
||||
cfile = testProject.getProject().getFile("exetest.c");
|
||||
if (!cfile.exists()) {
|
||||
cfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/main.c"),false, monitor);
|
||||
|
||||
}
|
||||
cpath=new Path(workspace.getRoot().getLocation()+"/filetest/main.c");
|
||||
|
||||
objfile = testProject.getProject().getFile("exetest.o");
|
||||
if (!objfile.exists()) {
|
||||
objfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/main.o"),false, monitor);
|
||||
|
||||
}
|
||||
objpath=new Path(workspace.getRoot().getLocation()+"/filetest/exetest.o");
|
||||
|
||||
exefile = testProject.getProject().getFile("test_g");
|
||||
if (!exefile.exists()) {
|
||||
exefile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/exe_g"),false, monitor);
|
||||
|
||||
}
|
||||
exepath=new Path(workspace.getRoot().getLocation()+"/filetest/exe_g");
|
||||
ppcexefile = testProject.getProject().getFile("ppctest_g");
|
||||
if (!ppcexefile.exists()) {
|
||||
ppcexefile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/ppc/be.g/exe_g"),false, monitor);
|
||||
|
||||
}
|
||||
ndexe = testProject.getProject().getFile("exetest");
|
||||
if (!ndexe.exists()) {
|
||||
ndexe.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o/exe"),false, monitor);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
bigexe = testProject.getProject().getFile("exebig_g");
|
||||
if (!bigexe.exists()) {
|
||||
bigexe.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exebig/x86/o.g/exebig_g"),false, monitor);
|
||||
|
||||
}
|
||||
|
||||
archfile = testProject.getProject().getFile("libtestlib_g.a");
|
||||
if (!archfile.exists()) {
|
||||
archfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/a.g/libtestlib_g.a"),false, monitor);
|
||||
|
||||
}
|
||||
libpath=new Path(workspace.getRoot().getLocation()+"/filetest/libtestlib_g.so");
|
||||
|
||||
libfile = testProject.getProject().getFile("libtestlib_g.so");
|
||||
if (!libfile.exists()) {
|
||||
libfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/so.g/libtestlib_g.so"),false, monitor);
|
||||
|
||||
}
|
||||
archpath=new Path(workspace.getRoot().getLocation()+"/filetest/libtestlib_g.a");
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the test fixture.
|
||||
*
|
||||
* Called after every test case method.
|
||||
*/
|
||||
protected void tearDown() throws CoreException {
|
||||
// release resources here and clean-up
|
||||
testProject.getProject().close(null);
|
||||
testProject.getProject().open(null);
|
||||
|
||||
CProjectHelper.delete(testProject);
|
||||
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(BinaryTests.class);
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 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:13037 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;
|
||||
ICElement[] elements;
|
||||
ExpectedStrings expSyms;
|
||||
String[] myStrings = {"atexit", "exit", "_init_libc", "printf", "_fini",
|
||||
"test.c", "_init","main.c", "_start", "test2.c", "_btext", "errno"};
|
||||
|
||||
expSyms=new ExpectedStrings(myStrings);
|
||||
|
||||
/***
|
||||
* Grab the Binary 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");
|
||||
elements=myBinary.getChildren();
|
||||
for (int i=0;i<elements.length;i++) {
|
||||
expSyms.foundString(elements[i].getElementName());
|
||||
}
|
||||
|
||||
assertTrue(expSyms.getMissingString(), expSyms.gotAll());
|
||||
assertTrue(expSyms.getExtraString(), !expSyms.gotExtra());
|
||||
}
|
||||
|
||||
/***
|
||||
* A quick check to make sure the getBSS function works as expected.
|
||||
*/
|
||||
public void testGetBss(){
|
||||
Binary bigBinary,littleBinary;
|
||||
bigBinary=CProjectHelper.findBinary(testProject, "exebig_g");
|
||||
littleBinary=CProjectHelper.findBinary(testProject, "test_g");
|
||||
|
||||
assertTrue("Expected 432, Got: " + bigBinary.getBSS(), bigBinary.getBSS()==432);
|
||||
assertTrue("Expected 4, Got: " + littleBinary.getBSS(), littleBinary.getBSS()==4);
|
||||
}
|
||||
/***
|
||||
* A quick check to make sure the getBSS function works as expected.
|
||||
*/
|
||||
public void testGetData(){
|
||||
Binary bigBinary,littleBinary;
|
||||
bigBinary=CProjectHelper.findBinary(testProject, "exebig_g");
|
||||
littleBinary=CProjectHelper.findBinary(testProject, "test_g");
|
||||
if (false) {
|
||||
/****
|
||||
* Since there is no comment on this function, I have no idea what
|
||||
* it is ment to do. Once I find out what it's ment to do, I will
|
||||
* actually write some tests.
|
||||
* PR13052
|
||||
*/
|
||||
assertTrue("Expected 76 Got: " + bigBinary.getData(), bigBinary.getData()==76);
|
||||
assertTrue("Expected 8, Got: " + littleBinary.getData(), littleBinary.getData()==8);
|
||||
} else
|
||||
fail("PR:13052 No docs, can't test");
|
||||
}
|
||||
|
||||
/***
|
||||
* A very small set of tests to make usre Binary.getCPU() seems to return
|
||||
* something sane for the most common exe type (x86) and one other (ppc)
|
||||
* This is not a in depth test at all.
|
||||
*/
|
||||
public void testGetCpu() {
|
||||
Binary myBinary;
|
||||
myBinary=CProjectHelper.findBinary(testProject, "exebig_g");
|
||||
|
||||
assertTrue("Expected: x86 Got: " + myBinary.getCPU(),myBinary.getCPU().equals("x86"));
|
||||
myBinary=new Binary(testProject, ppcexefile);
|
||||
assertTrue("Expected: ppcbe Got: " + myBinary.getCPU(),myBinary.getCPU().equals("ppcbe"));
|
||||
|
||||
}
|
||||
|
||||
/****
|
||||
* A set of simple tests to make sute getNeededSharedLibs seems to be sane
|
||||
*/
|
||||
public void testGetNeededSharedLibs() {
|
||||
Binary myBinary;
|
||||
String[] exelibs={"libsocket.so.2", "libc.so.2"};
|
||||
String[] bigexelibs={"libc.so.2"};
|
||||
String[] gotlibs;
|
||||
ExpectedStrings exp;
|
||||
int x;
|
||||
|
||||
exp=new ExpectedStrings(exelibs);
|
||||
myBinary=CProjectHelper.findBinary(testProject, "test_g");
|
||||
gotlibs=myBinary.getNeededSharedLibs();
|
||||
for (x=0;x<gotlibs.length;x++) {
|
||||
exp.foundString(gotlibs[x]);
|
||||
}
|
||||
assertTrue(exp.getMissingString(), exp.gotAll());
|
||||
assertTrue(exp.getExtraString(), !exp.gotExtra());
|
||||
|
||||
exp=new ExpectedStrings(bigexelibs);
|
||||
myBinary=CProjectHelper.findBinary(testProject,"exebig_g");
|
||||
gotlibs=myBinary.getNeededSharedLibs();
|
||||
for (x=0;x<gotlibs.length;x++) {
|
||||
exp.foundString(gotlibs[x]);
|
||||
}
|
||||
assertTrue(exp.getMissingString(), exp.gotAll());
|
||||
assertTrue(exp.getExtraString(), !exp.gotExtra());
|
||||
|
||||
exp=new ExpectedStrings(bigexelibs);
|
||||
myBinary=CProjectHelper.findBinary(testProject, "libtestlib_g.so");
|
||||
gotlibs=myBinary.getNeededSharedLibs();
|
||||
for (x=0;x<gotlibs.length;x++) {
|
||||
exp.foundString(gotlibs[x]);
|
||||
}
|
||||
assertTrue(exp.getMissingString(), exp.gotAll());
|
||||
assertTrue(exp.getExtraString(), !exp.gotExtra());
|
||||
|
||||
}
|
||||
|
||||
/****
|
||||
* Simple tests for the getSoname method;
|
||||
*/
|
||||
public void testGetSoname() {
|
||||
Binary myBinary;
|
||||
String name;
|
||||
myBinary=CProjectHelper.findBinary(testProject, "test_g");
|
||||
assertTrue(myBinary.getSoname().equals(""));
|
||||
|
||||
myBinary=CProjectHelper.findBinary(testProject, "libtestlib_g.so");
|
||||
name=myBinary.getSoname();
|
||||
assertNotNull(name);
|
||||
assertTrue("Expected: libtestlib_g.so.1 Got: " + name,
|
||||
name.equals("libtestlib_g.so.1"));
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* Simple tests for getText
|
||||
*/
|
||||
public void testGetText() {
|
||||
Binary bigBinary,littleBinary;
|
||||
bigBinary=new Binary(testProject, bigexe);
|
||||
littleBinary=new Binary(testProject, exefile);
|
||||
if (false) {
|
||||
/****
|
||||
* Since there is no comment on this function, I have no idea what
|
||||
* it is ment to do. Once I find out what it's ment to do, I will
|
||||
* actually write some tests.
|
||||
* PR13052
|
||||
*/
|
||||
|
||||
assertTrue("Expected 296, Got: " + bigBinary.getText(), bigBinary.getText()==296);
|
||||
assertTrue("Expected 296, Got: " + littleBinary.getText(), littleBinary.getText()==296);
|
||||
} else
|
||||
fail("PR:13052 No docs, can't test");
|
||||
}
|
||||
|
||||
/***
|
||||
* Simple tests for the hadDebug call
|
||||
*/
|
||||
public void testHasDebug() {
|
||||
Binary myBinary;
|
||||
myBinary = CProjectHelper.findBinary(testProject, "test_g");
|
||||
assertTrue(myBinary.hasDebug());
|
||||
myBinary = CProjectHelper.findBinary(testProject, "libtestlib_g.so");
|
||||
assertTrue(myBinary.hasDebug());
|
||||
myBinary = CProjectHelper.findBinary(testProject, "exetest");
|
||||
assertTrue(!myBinary.hasDebug());
|
||||
}
|
||||
|
||||
/***
|
||||
* Sanity - isBinary and isReadonly should always return true;
|
||||
*/
|
||||
public void testisBinRead() {
|
||||
Binary myBinary;
|
||||
myBinary =CProjectHelper.findBinary(testProject, "test_g");
|
||||
assertTrue(myBinary.isBinary());
|
||||
assertTrue(myBinary.isReadOnly());
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* Quick tests to make sure isObject works as expected.
|
||||
*/
|
||||
public void testIsObject() {
|
||||
Binary myBinary;
|
||||
myBinary=CProjectHelper.findObject(testProject, "exetest.o");
|
||||
assertTrue(myBinary.isObject());
|
||||
|
||||
|
||||
myBinary= CProjectHelper.findBinary(testProject, "test_g");
|
||||
assertTrue(!myBinary.isObject());
|
||||
|
||||
myBinary= CProjectHelper.findBinary(testProject, "libtestlib_g.so");
|
||||
assertTrue(!myBinary.isObject());
|
||||
|
||||
myBinary= CProjectHelper.findBinary(testProject, "exetest");
|
||||
assertTrue(!myBinary.isObject());
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* Quick tests to make sure isSharedLib works as expected.
|
||||
*/
|
||||
public void testIsSharedLib() {
|
||||
Binary myBinary;
|
||||
|
||||
myBinary=CProjectHelper.findObject(testProject, "exetest.o");
|
||||
assertTrue(!myBinary.isSharedLib());
|
||||
|
||||
myBinary= CProjectHelper.findBinary(testProject, "libtestlib_g.so");
|
||||
assertTrue(myBinary.isSharedLib());
|
||||
|
||||
myBinary= CProjectHelper.findBinary(testProject, "test_g");
|
||||
assertTrue(!myBinary.isSharedLib());
|
||||
|
||||
|
||||
myBinary= CProjectHelper.findBinary(testProject, "exetest");
|
||||
assertTrue(!myBinary.isSharedLib());
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* Quick tests to make sure isExecutable works as expected.
|
||||
*/
|
||||
public void testIsExecutable() throws InterruptedException {
|
||||
Binary myBinary;
|
||||
myBinary=CProjectHelper.findObject(testProject, "exetest.o");
|
||||
assertTrue(!myBinary.isExecutable());
|
||||
|
||||
myBinary=CProjectHelper.findBinary(testProject, "test_g");
|
||||
assertTrue(myBinary.isExecutable());
|
||||
|
||||
myBinary= CProjectHelper.findBinary(testProject, "libtestlib_g.so");
|
||||
assertTrue(!myBinary.isExecutable());
|
||||
|
||||
|
||||
myBinary= CProjectHelper.findBinary(testProject, "exetest");
|
||||
assertTrue(myBinary.isExecutable());
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* Simple sanity test to make sure Binary.isBinary returns true
|
||||
*
|
||||
*/
|
||||
public void testIsBinary() throws CoreException,FileNotFoundException,Exception {
|
||||
Binary myBinary;
|
||||
|
||||
myBinary=CProjectHelper.findBinary(testProject, "exebig_g");
|
||||
assertTrue("A Binary", myBinary.isBinary());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,113 @@
|
|||
package org.eclipse.cdt.core.model.tests;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ICModelStatusConstants;
|
||||
import org.eclipse.cdt.internal.core.model.CModelStatus;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
/**
|
||||
*
|
||||
* CModelExceptionTest
|
||||
*
|
||||
* @author Judy N. Green
|
||||
* @since Jul 19, 2002
|
||||
*/
|
||||
public class CModelExceptionTest extends TestCase {
|
||||
// Shared values setup and torn down
|
||||
private Throwable throwableException;
|
||||
private CModelStatus cModelStatus;
|
||||
private CoreException coreException;
|
||||
|
||||
/**
|
||||
* Constructor for TestCModelException.
|
||||
* @param name
|
||||
*/
|
||||
public CModelExceptionTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the test fixture.
|
||||
*
|
||||
* Called before every test case method.
|
||||
*
|
||||
* Example code test the packages in the project
|
||||
* "com.qnx.tools.ide.cdt.core"
|
||||
*/
|
||||
protected void setUp() {
|
||||
// create shared resources and setup the test fixture
|
||||
cModelStatus = new CModelStatus();
|
||||
coreException = new CoreException(cModelStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the test fixture.
|
||||
*
|
||||
* Called after every test case method.
|
||||
*/
|
||||
protected void tearDown() {
|
||||
// release resources here and clean-up
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(CModelExceptionTest.class);
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
public void testCreationNoStatus(){
|
||||
CModelException testException = new CModelException(coreException);
|
||||
|
||||
// should not be null
|
||||
assertTrue("TestException is null", (testException != null));
|
||||
|
||||
// should be the same object inside
|
||||
assertTrue("Object compare failed", testException.getException() == coreException);
|
||||
}
|
||||
public void testCreationWithStatus(){
|
||||
CModelException testException = new CModelException(coreException,
|
||||
ICModelStatusConstants.INDEX_OUT_OF_BOUNDS);
|
||||
// should not be null
|
||||
assertTrue("TestException is null", (testException != null));
|
||||
|
||||
// should not be null
|
||||
assertTrue("TestException.getStatus() is null", (testException.getStatus() != null));
|
||||
|
||||
// should have the same status as was set on creation
|
||||
assertTrue("Object compare failed", testException.getStatus().getCode() == ICModelStatusConstants.INDEX_OUT_OF_BOUNDS);
|
||||
}
|
||||
|
||||
public void testElementDoesNotExist(){
|
||||
CModelException testException = new CModelException(coreException,
|
||||
ICModelStatusConstants.ELEMENT_DOES_NOT_EXIST);
|
||||
// should not be null
|
||||
assertTrue("TestException is null", (testException != null));
|
||||
|
||||
|
||||
// should not exist since this is the value we set on creation
|
||||
assertTrue("Object unexpectedly exists", testException.doesNotExist());
|
||||
}
|
||||
|
||||
public void testElementExists(){
|
||||
CModelException testException = new CModelException(coreException,
|
||||
ICModelStatusConstants.INVALID_CONTENTS);
|
||||
// should not be null
|
||||
assertTrue("TestException is null", (testException != null));
|
||||
|
||||
|
||||
// should not exist since this is the value we set on creation
|
||||
assertTrue("Object unexpectedly does not exist", testException.doesNotExist() == false);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,246 @@
|
|||
package org.eclipse.cdt.core.model.tests;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import org.eclipse.cdt.testplugin.*;
|
||||
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;
|
||||
|
||||
|
||||
/**
|
||||
* @author Peter Graves
|
||||
*
|
||||
* This file contains a set of generic tests for the core C model. Nothing
|
||||
* exotic, but should be a small sanity set of tests.
|
||||
*
|
||||
*/
|
||||
public class CModelTests extends TestCase {
|
||||
IWorkspace workspace;
|
||||
IWorkspaceRoot root;
|
||||
IProject project_c, project_cc;
|
||||
NullProgressMonitor monitor;
|
||||
String pluginRoot;
|
||||
|
||||
/**
|
||||
* Constructor for CModelTests.
|
||||
* @param name
|
||||
*/
|
||||
public CModelTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the test fixture.
|
||||
*
|
||||
* Called before every test case method.
|
||||
*
|
||||
* Example code test the packages in the project
|
||||
* "com.qnx.tools.ide.cdt.core"
|
||||
*/
|
||||
protected void setUp() throws CoreException {
|
||||
/***
|
||||
* 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.
|
||||
*/
|
||||
IWorkspaceDescription desc;
|
||||
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");
|
||||
pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.ui.tests").find(new Path("/")).getFile();
|
||||
desc=workspace.getDescription();
|
||||
desc.setAutoBuilding(false);
|
||||
workspace.setDescription(desc);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the test fixture.
|
||||
*
|
||||
* Called after every test case method.
|
||||
*/
|
||||
protected void tearDown() {
|
||||
// release resources here and clean-up
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(CModelTests.class);
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
/***
|
||||
* Very simple sanity tests to make sure the get*Nature* functions
|
||||
* are returning sane values
|
||||
*/
|
||||
public void testGetNatureId(){
|
||||
assertTrue("GetCNatureId returns correct value", CoreModel.getDefault().getCNatureId().equals(CoreModel.C_NATURE_ID));
|
||||
assertTrue("GetCNatureName returns correct value", CoreModel.getDefault().getCNatureName().equals(CoreModel.C_NATURE_NAME));
|
||||
|
||||
assertTrue("GetCCNatureId returns correct value", CoreModel.getDefault().getCCNatureId().equals(CoreModel.CC_NATURE_ID));
|
||||
assertTrue("GetCCNatureName returns correct value", CoreModel.getDefault().getCCNatureName().equals(CoreModel.CC_NATURE_NAME));
|
||||
|
||||
/***
|
||||
* The following tests are here to make sure the names/ids of the
|
||||
* natures do not change over time. Changing them would likely break
|
||||
* backwards compatibility, so if it happens, we should know about it.
|
||||
*/
|
||||
assertTrue("C_NATURE_NAME is constant", CoreModel.C_NATURE_NAME.equals("cnature"));
|
||||
assertTrue("C_NATURE_ID is constant", CoreModel.C_NATURE_ID.equals("org.eclipse.cdt.core.cnature"));
|
||||
assertTrue("CC_NATURE_NAME is constant", CoreModel.CC_NATURE_NAME.equals("ccnature"));
|
||||
assertTrue("CC_NATURE_ID is constant", CoreModel.CC_NATURE_ID.equals("org.eclipse.cdt.core.ccnature"));
|
||||
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* The follow are a simple set of tests to make usre the HasC/CCNature calls
|
||||
* seem to be sane.
|
||||
*
|
||||
* Assumes that the CProjectHelper.createCProject properly creates a C
|
||||
* project with a C nature, but does not add the CC nature.
|
||||
* It also assums that the AddCCNature call works
|
||||
*
|
||||
* @see CProjectHelper#createCProject
|
||||
* @see CoreModel#addCCNature
|
||||
*/
|
||||
public void testHasNature() throws CoreException {
|
||||
ICProject testProject;
|
||||
testProject=CProjectHelper.createCProject("naturetest", "none");
|
||||
if (testProject==null)
|
||||
fail("Unable to create project");
|
||||
assertTrue("hasCNature works", CoreModel.hasCNature(testProject.getProject()));
|
||||
assertTrue("hasCCNature works without ccnature", !(CoreModel.hasCCNature(testProject.getProject())));
|
||||
CoreModel.addCCNature(testProject.getProject(), monitor);
|
||||
assertTrue("hasCCNature works", (CoreModel.hasCCNature(testProject.getProject())));
|
||||
|
||||
CoreModel.removeCCNature(testProject.getProject(), monitor);
|
||||
CoreModel.removeCNature(testProject.getProject(), monitor);
|
||||
assertTrue("hasCNature works without cnature", !CoreModel.hasCNature(testProject.getProject()));
|
||||
assertTrue("hasCCNature works without ccnature or cnature", !(CoreModel.hasCCNature(testProject.getProject())));
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* Simple tests to make sure the models file identification methods seem
|
||||
* to work as expected.
|
||||
*/
|
||||
public void testFileType() throws CoreException,FileNotFoundException {
|
||||
ICProject testProject;
|
||||
ICFile myfile;
|
||||
testProject=CProjectHelper.createCProject("filetest", "none");
|
||||
if (testProject==null)
|
||||
fail("Unable to create project");
|
||||
|
||||
IFile file = testProject.getProject().getFile("exetest_g");
|
||||
if (!file.exists()) {
|
||||
file.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/exe_g"),false, monitor);
|
||||
|
||||
}
|
||||
/***
|
||||
* file should be a binary, executable, not shared or archive
|
||||
*/
|
||||
assertTrue("isBinary", CoreModel.isBinary(file));
|
||||
assertTrue("isExecutable", CoreModel.isExecutable(file));
|
||||
assertTrue("isSharedLib", !CoreModel.isSharedLib(file));
|
||||
assertTrue("isArchive", !CoreModel.isArchive(file));
|
||||
assertTrue("isObject", !CoreModel.isObject(file));
|
||||
assertTrue("isTranslationUnit", !CoreModel.isTranslationUnit(file));
|
||||
|
||||
|
||||
file = testProject.getProject().getFile("exetest.c");
|
||||
if (!file.exists()) {
|
||||
file.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/main.c"),false, monitor);
|
||||
|
||||
}
|
||||
/***
|
||||
* file should be a translation unit
|
||||
*/
|
||||
assertTrue("isBinary", !CoreModel.isBinary(file));
|
||||
assertTrue("isExecutable", !CoreModel.isExecutable(file));
|
||||
assertTrue("isSharedLib", !CoreModel.isSharedLib(file));
|
||||
assertTrue("isArchive", !CoreModel.isArchive(file));
|
||||
assertTrue("isObject", !CoreModel.isObject(file));
|
||||
assertTrue("isTranslationUnit", CoreModel.isTranslationUnit(file));
|
||||
|
||||
file = testProject.getProject().getFile("exetest.o");
|
||||
if (!file.exists()) {
|
||||
file.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/main.o"),false, monitor);
|
||||
|
||||
}
|
||||
/***
|
||||
* file should be a object file unit
|
||||
*/
|
||||
assertTrue("isBinary", CoreModel.isBinary(file));
|
||||
assertTrue("isExecutable", !CoreModel.isExecutable(file));
|
||||
assertTrue("isSharedLib", !CoreModel.isSharedLib(file));
|
||||
assertTrue("isArchive", !CoreModel.isArchive(file));
|
||||
assertTrue("isObject", CoreModel.isObject(file));
|
||||
assertTrue("isTranslationUnit", !CoreModel.isTranslationUnit(file));
|
||||
|
||||
file = testProject.getProject().getFile("liblibtest_g.so");
|
||||
if (!file.exists()) {
|
||||
file.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/so.g/libtestlib_g.so"),false, monitor);
|
||||
|
||||
}
|
||||
/***
|
||||
* file should be a sharedlib/binary file
|
||||
*/
|
||||
assertTrue("isBinary", CoreModel.isBinary(file));
|
||||
assertTrue("isExecutable", !CoreModel.isExecutable(file));
|
||||
assertTrue("isSharedLib", CoreModel.isSharedLib(file));
|
||||
assertTrue("isArchive", !CoreModel.isArchive(file));
|
||||
assertTrue("isObject", !CoreModel.isObject(file));
|
||||
assertTrue("isTranslationUnit", !CoreModel.isTranslationUnit(file));
|
||||
|
||||
file = testProject.getProject().getFile("liblibtest_g.a");
|
||||
if (!file.exists()) {
|
||||
file.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/a.g/libtestlib_g.a"),false, monitor);
|
||||
|
||||
} else {
|
||||
fail("Does not exist?");
|
||||
}
|
||||
/***
|
||||
* file should be a archive file
|
||||
*/
|
||||
assertTrue("isArchive", CoreModel.isArchive(file));
|
||||
assertTrue("isBinary:", !CoreModel.isBinary(file));
|
||||
assertTrue("isExecutable", !CoreModel.isExecutable(file));
|
||||
assertTrue("isSharedLib", !CoreModel.isSharedLib(file));
|
||||
assertTrue("isArchive", CoreModel.isArchive(file));
|
||||
assertTrue("isObject", !CoreModel.isObject(file));
|
||||
assertTrue("isTranslationUnit", !CoreModel.isTranslationUnit(file));
|
||||
|
||||
|
||||
testProject.getProject().delete(true,true,monitor);
|
||||
}
|
||||
|
||||
/****
|
||||
* Some simple tests for isValidTranslationUnitName
|
||||
*/
|
||||
public void testIsValidTranslationUnitName() throws CoreException {
|
||||
assertTrue("Invalid C file", !CoreModel.isValidTranslationUnitName("notcfile"));
|
||||
assertTrue("Invalid C file", !CoreModel.isValidTranslationUnitName("not.c.file"));
|
||||
assertTrue("Invalid C file", !CoreModel.isValidTranslationUnitName("not.ca"));
|
||||
assertTrue("Valid C file", CoreModel.isValidTranslationUnitName("areal.c"));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,214 @@
|
|||
package org.eclipse.cdt.core.model.tests;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import org.eclipse.cdt.testplugin.*;
|
||||
|
||||
import org.eclipse.cdt.core.model.*;
|
||||
import org.eclipse.cdt.internal.core.model.*;
|
||||
import org.eclipse.core.resources.*;
|
||||
import org.eclipse.core.runtime.*;
|
||||
/**
|
||||
* @author Peter Graves
|
||||
*
|
||||
* This is a very simple set of sanity tests for the flags class to make sure
|
||||
* there are no very silly problems in the class. It also verifies that there
|
||||
* is no overlap in the IConstants.
|
||||
*/
|
||||
public class FlagTests extends TestCase {
|
||||
|
||||
int flags[];
|
||||
/**
|
||||
* Constructor for FlagTests.
|
||||
* @param name
|
||||
*/
|
||||
public FlagTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
/**
|
||||
* Sets up the test fixture.
|
||||
*
|
||||
* Called before every test case method.
|
||||
*
|
||||
* Example code test the packages in the project
|
||||
* "com.qnx.tools.ide.cdt.core"
|
||||
*/
|
||||
protected void setUp() {
|
||||
flags=new int[15];
|
||||
flags[0]=IConstants.AccPublic;
|
||||
flags[1]=IConstants.AccPrivate;
|
||||
flags[2]=IConstants.AccProtected;
|
||||
flags[3]=IConstants.AccStatic;
|
||||
flags[4]=IConstants.AccExtern;
|
||||
flags[5]=IConstants.AccInline;
|
||||
flags[6]=IConstants.AccVolatile;
|
||||
flags[7]=IConstants.AccRegister;
|
||||
flags[8]=IConstants.AccExplicit;
|
||||
flags[9]=IConstants.AccExport;
|
||||
flags[10]=IConstants.AccAbstract;
|
||||
flags[11]=IConstants.AccMutable;
|
||||
flags[12]=IConstants.AccAuto;
|
||||
flags[13]=IConstants.AccVirtual;
|
||||
flags[14]=IConstants.AccTypename;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the test fixture.
|
||||
*
|
||||
* Called after every test case method.
|
||||
*/
|
||||
protected void tearDown() {
|
||||
// release resources here and clean-up
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(FlagTests.class);
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
public void testIsStatic()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isStatic with a static", Flags.isStatic(IConstants.AccStatic));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccStatic)
|
||||
assertTrue("isStatic with a non-static", !Flags.isStatic(flags[x]));
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsAbstract()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isAbstract with a abstract", Flags.isAbstract(IConstants.AccAbstract));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccAbstract)
|
||||
assertTrue("isAbstract with a non-abstract", !Flags.isAbstract(flags[x]));
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsExplicit()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isExplicit with a explicit", Flags.isExplicit(IConstants.AccExplicit));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccExplicit)
|
||||
assertTrue("isExplicit with a non-explicit", !Flags.isExplicit(flags[x]));
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsExport()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isExport with a Export", Flags.isExport(IConstants.AccExport));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccExport)
|
||||
assertTrue("isExport with a non-Export", !Flags.isExport(flags[x]));
|
||||
}
|
||||
}
|
||||
public void testIsExtern()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isExtern with a Extern", Flags.isExtern(IConstants.AccExtern));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccExtern)
|
||||
assertTrue("isExtern with a non-Extern", !Flags.isExtern(flags[x]));
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsInline()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isInline with a Inline", Flags.isInline(IConstants.AccInline));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccInline)
|
||||
assertTrue("isInline with a non-Inline", !Flags.isInline(flags[x]));
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsMutable()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isMutable with a Mutable", Flags.isMutable(IConstants.AccMutable));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccMutable)
|
||||
assertTrue("isMutable with a non-Mutable", !Flags.isMutable(flags[x]));
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsPrivate()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isPrivate with a Private", Flags.isPrivate(IConstants.AccPrivate));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccPrivate)
|
||||
assertTrue("isPrivate with a non-Private", !Flags.isPrivate(flags[x]));
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsPublic()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isPublic with a Public", Flags.isPublic(IConstants.AccPublic));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccPublic)
|
||||
assertTrue("isPublic with a non-Public", !Flags.isPublic(flags[x]));
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsProtected()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isProtected with a Protected", Flags.isProtected(IConstants.AccProtected));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccProtected)
|
||||
assertTrue("isProtected with a non-Protected", !Flags.isProtected(flags[x]));
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsRegister()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isRegister with a Register", Flags.isRegister(IConstants.AccRegister));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccRegister)
|
||||
assertTrue("isRegister with a non-Register", !Flags.isRegister(flags[x]));
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsVirtual()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isVirtual with a Virtual", Flags.isVirtual(IConstants.AccVirtual));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccVirtual)
|
||||
assertTrue("isVirtual with a non-Virtual", !Flags.isVirtual(flags[x]));
|
||||
}
|
||||
}
|
||||
|
||||
public void testIsVolatile()
|
||||
{
|
||||
int x;
|
||||
assertTrue("isVolatile with a Volatile", Flags.isVolatile(IConstants.AccVolatile));
|
||||
for (x=0;x<flags.length;x++) {
|
||||
if (flags[x]!=IConstants.AccVolatile)
|
||||
assertTrue("isVolatile with a non-Volatile", !Flags.isVolatile(flags[x]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,406 @@
|
|||
package org.eclipse.cdt.core.model.tests;
|
||||
|
||||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.Stack;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
import org.eclipse.cdt.testplugin.*;
|
||||
import org.eclipse.cdt.testplugin.util.*;
|
||||
import org.eclipse.cdt.core.model.*;
|
||||
import org.eclipse.core.internal.runtime.Log;
|
||||
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;
|
||||
import org.eclipse.cdt.internal.core.model.*;
|
||||
|
||||
|
||||
/**
|
||||
* @author Peter Graves
|
||||
*
|
||||
* This file contains a set of generic tests for the core C model's TranslationUnit
|
||||
* class. There is nothing exotic here, mostly just sanity type tests
|
||||
*
|
||||
*/
|
||||
public class TranslationUnitTests extends TestCase {
|
||||
IWorkspace workspace;
|
||||
IWorkspaceRoot root;
|
||||
ICProject testProject;
|
||||
IFile cfile, exefile, libfile, archfile, objfile;
|
||||
Path cpath, exepath, libpath, archpath, objpath;
|
||||
NullProgressMonitor monitor;
|
||||
|
||||
/* This is a list of elements in the test .c file. It will be used
|
||||
* in a number of places in the tests
|
||||
*/
|
||||
String[] expectedStringList= {"stdio.h", "unistd.h", "func2p",
|
||||
"globalvar", "myenum", "mystruct", "mystruct_t", "myunion", "mytype",
|
||||
"func1", "func2", "main", "func3"};
|
||||
int[] expectedLines={ 12,14,17,20,23,28,32,35,42,47,53,58,65};
|
||||
/* This is a list of that the types of the above list of elements is
|
||||
* expected to be.
|
||||
*/
|
||||
int[] expectedTypes= { ICElement.C_INCLUDE, ICElement.C_INCLUDE,
|
||||
ICElement.C_FUNCTION_DECLARATION, ICElement.C_VARIABLE,
|
||||
ICElement.C_ENUMERATION, ICElement.C_STRUCT, ICElement.C_TYPEDEF,
|
||||
ICElement.C_UNION, ICElement.C_TYPEDEF, ICElement.C_FUNCTION,
|
||||
ICElement.C_FUNCTION, ICElement.C_FUNCTION,ICElement.C_FUNCTION};
|
||||
|
||||
|
||||
/**
|
||||
* Constructor for TranslationUnitTests
|
||||
* @param name
|
||||
*/
|
||||
public TranslationUnitTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the test fixture.
|
||||
*
|
||||
* Called before every test case method.
|
||||
*
|
||||
* Example code test the packages in the project
|
||||
* "com.qnx.tools.ide.cdt.core"
|
||||
*/
|
||||
protected void setUp() throws CoreException,FileNotFoundException {
|
||||
/***
|
||||
* The rest 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.
|
||||
*/
|
||||
IWorkspaceDescription desc;
|
||||
String pluginRoot=org.eclipse.core.runtime.Platform.getPlugin("org.eclipse.cdt.ui.tests").find(new Path("/")).getFile();
|
||||
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");
|
||||
|
||||
desc=workspace.getDescription();
|
||||
desc.setAutoBuilding(false);
|
||||
workspace.setDescription(desc);
|
||||
|
||||
/***
|
||||
* Setup the various files, paths and projects that are needed by the
|
||||
* tests
|
||||
*/
|
||||
|
||||
testProject=CProjectHelper.createCProject("filetest", "none");
|
||||
if (testProject==null)
|
||||
fail("Unable to create project");
|
||||
|
||||
cfile = testProject.getProject().getFile("exetest.c");
|
||||
if (!cfile.exists()) {
|
||||
cfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/cfiles/TranslationUnits.c"),false, monitor);
|
||||
|
||||
}
|
||||
cpath=new Path(workspace.getRoot().getLocation()+"/filetest/main.c");
|
||||
|
||||
objfile = testProject.getProject().getFile("exetest.o");
|
||||
if (!objfile.exists()) {
|
||||
objfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/main.o"),false, monitor);
|
||||
|
||||
}
|
||||
objpath=new Path(workspace.getRoot().getLocation()+"/filetest/main.o");
|
||||
|
||||
exefile = testProject.getProject().getFile("test_g");
|
||||
if (!exefile.exists()) {
|
||||
exefile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/exe/x86/o.g/exe_g"),false, monitor);
|
||||
|
||||
}
|
||||
exepath=new Path(workspace.getRoot().getLocation()+"/filetest/exe_g");
|
||||
|
||||
archfile = testProject.getProject().getFile("libtestlib_g.a");
|
||||
if (!archfile.exists()) {
|
||||
archfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/a.g/libtestlib_g.a"),false, monitor);
|
||||
|
||||
}
|
||||
libpath=new Path(workspace.getRoot().getLocation()+"/filetest/libtestlib_g.so");
|
||||
|
||||
libfile = testProject.getProject().getFile("libtestlib_g.so");
|
||||
if (!libfile.exists()) {
|
||||
libfile.create(new FileInputStream(pluginRoot+"model/org/eclipse/cdt/core/model/tests/resources/testlib/x86/so.g/libtestlib_g.so"),false, monitor);
|
||||
|
||||
}
|
||||
archpath=new Path(workspace.getRoot().getLocation()+"/filetest/libtestlib_g.a");
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the test fixture.
|
||||
*
|
||||
* Called after every test case method.
|
||||
*/
|
||||
protected void tearDown() throws CoreException {
|
||||
// release resources here and clean-up
|
||||
testProject.getProject().delete(true,true,monitor);
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(TranslationUnitTests.class);
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* 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:13037 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);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
* Simple sanity test to make sure TranslationUnit.isTranslationUnit returns true
|
||||
*
|
||||
*/
|
||||
public void testIsTranslationUnit() throws CoreException,FileNotFoundException {
|
||||
TranslationUnit myTranslationUnit;
|
||||
|
||||
myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
assertTrue("A TranslationUnit", myTranslationUnit.isTranslationUnit());
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* Simple sanity tests to make sure TranslationUnit.getChildren seems to
|
||||
* basicly work
|
||||
*/
|
||||
public void testGetChildern() {
|
||||
TranslationUnit myTranslationUnit;
|
||||
ICElement[] elements;
|
||||
int x;
|
||||
|
||||
ExpectedStrings expectedString=new ExpectedStrings(expectedStringList);
|
||||
|
||||
myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
|
||||
|
||||
if (myTranslationUnit.hasChildren()) {
|
||||
elements=myTranslationUnit.getChildren();
|
||||
for (x=0;x<elements.length;x++) {
|
||||
expectedString.foundString(elements[x].getElementName());
|
||||
}
|
||||
}
|
||||
assertTrue("PR:13062 " +expectedString.getMissingString(),expectedString.gotAll());
|
||||
assertTrue(expectedString.getExtraString(),!expectedString.gotExtra());
|
||||
|
||||
}
|
||||
|
||||
/***
|
||||
* Simple sanity tests for the getElement() call
|
||||
*/
|
||||
public void testGetElement() {
|
||||
TranslationUnit myTranslationUnit;
|
||||
ICElement myElement;
|
||||
Stack missing=new Stack();
|
||||
int x;
|
||||
myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
|
||||
for (x=0;x<expectedStringList.length;x++) {
|
||||
myElement=myTranslationUnit.getElement(expectedStringList[x]);
|
||||
if (myElement==null)
|
||||
missing.push(expectedStringList[x]);
|
||||
else {
|
||||
assertTrue("Expected:" + expectedStringList[x] + " Got:" + myElement.getElementName(),
|
||||
expectedStringList[x].equals(myElement.getElementName()));
|
||||
}
|
||||
|
||||
}
|
||||
if (!missing.empty()) {
|
||||
String output=new String("PR: 13062 Could not get elements: ");
|
||||
while (!missing.empty())
|
||||
output+=missing.pop() + " ";
|
||||
assertTrue(output, false);
|
||||
}
|
||||
|
||||
}
|
||||
/***
|
||||
* Simple sanity tests for the getElementAtLine() call
|
||||
*/
|
||||
public void testGetElementAtLine() throws CoreException {
|
||||
TranslationUnit myTranslationUnit;
|
||||
ICElement myElement;
|
||||
Stack missing=new Stack();
|
||||
int x;
|
||||
myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
|
||||
for (x=0;x<expectedStringList.length;x++) {
|
||||
myElement=myTranslationUnit.getElementAtLine(expectedLines[x]);
|
||||
if (myElement==null)
|
||||
missing.push(expectedStringList[x]);
|
||||
else {
|
||||
if (expectedStringList[x].equals("mystruct_t")) {
|
||||
assertTrue("PR: 13062 expected:" + expectedStringList[x] + " Got:" + myElement.getElementName(),
|
||||
expectedStringList[x].equals(myElement.getElementName()));
|
||||
} else {
|
||||
assertTrue("Expected:" + expectedStringList[x] + " Got:" + myElement.getElementName(),
|
||||
expectedStringList[x].equals(myElement.getElementName()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
if (!missing.empty()) {
|
||||
String output=new String("PR: 13062 Could not get elements: ");
|
||||
while (!missing.empty())
|
||||
output+=missing.pop() + " ";
|
||||
assertTrue(output, false);
|
||||
}
|
||||
|
||||
}
|
||||
/***
|
||||
* Simple sanity tests for the getInclude call
|
||||
*/
|
||||
public void testGetInclude() {
|
||||
Include myInclude;
|
||||
int x;
|
||||
String includes[]={"stdio.h", "unistd.h"};
|
||||
TranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
|
||||
for (x=0;x<includes.length;x++) {
|
||||
myInclude=(Include)myTranslationUnit.getInclude(includes[x]);
|
||||
if (myInclude==null)
|
||||
fail("Unable to get include: " + includes[x]);
|
||||
else
|
||||
assertTrue("PR:BZ23478 Expected:"+includes[x] +" Got:"+ myInclude.getIncludeName(), includes[x].equals(myInclude.getIncludeName()));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
/***
|
||||
* Simple sanity tests for the getIncludes call
|
||||
*/
|
||||
public void testGetIncludes() throws CModelException {
|
||||
IInclude myIncludes[];
|
||||
String includes[]={"stdio.h", "unistd.h"};
|
||||
ExpectedStrings myExp= new ExpectedStrings(includes);
|
||||
int x;
|
||||
TranslationUnit myTranslationUnit=CProjectHelper.findTranslationUnit(testProject,"exetest.c");
|
||||
fail("Unable to test because we can't get the name of an include file (PR: BZ23478");
|
||||
|
||||
myIncludes=myTranslationUnit.getIncludes();
|
||||
for (x=0;x<myIncludes.length;x++) {
|
||||
myExp.foundString(myIncludes[x].getIncludeName());
|
||||
}
|
||||
assertTrue(myExp.getMissingString(), myExp.gotAll());
|
||||
assertTrue(myExp.getExtraString(), !myExp.gotExtra());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/*
|
||||
* (c) Copyright QNX Software Systems Ltd. 2002.
|
||||
* All Rights Reserved.
|
||||
*/
|
||||
/********
|
||||
* This is a sample C file that will be used in testing the TranslationUnit
|
||||
* class. It has a specific structure that will be looked for within the
|
||||
* test case.
|
||||
* This file is only ment to contain various C elements, and may not compile
|
||||
* into a running application (but should be valid C)
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* A function prototype */
|
||||
int func2p(void);
|
||||
|
||||
/* A global variable */
|
||||
int globalvar;
|
||||
|
||||
/* A enumeration */
|
||||
enum myenum {ENUM_A=1, ENUM_B=2, ENUM_C=3, ENUM_D=4};
|
||||
|
||||
/* A structure. This also includes a typedef around the strcture def
|
||||
* which at the time of writing was not picked up.
|
||||
*/
|
||||
typedef struct mystruct {
|
||||
int a;
|
||||
char b;
|
||||
long c;
|
||||
} mystruct_t;
|
||||
|
||||
/* A union */
|
||||
union myunion {
|
||||
int x;
|
||||
char y;
|
||||
long z;
|
||||
};
|
||||
|
||||
/* A typedef */
|
||||
typedef struct mystruct mytype;
|
||||
|
||||
|
||||
/* A couple functions */
|
||||
|
||||
void * func1(void)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
||||
int func2(void)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
int main(int argc, char ** argv)
|
||||
{
|
||||
int var1;
|
||||
printf("Hello world\n");
|
||||
}
|
||||
|
||||
|
||||
void func3()
|
||||
{
|
||||
printf("This is not really here\n");
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
LIST=VARIANT
|
||||
ifndef QRECURSE
|
||||
QRECURSE=recurse.mk
|
||||
ifdef QCONFIG
|
||||
QRDIR=$(dir $(QCONFIG))
|
||||
endif
|
||||
endif
|
||||
include $(QRDIR)$(QRECURSE)
|
|
@ -0,0 +1,7 @@
|
|||
ifndef QCONFIG
|
||||
QCONFIG=qconfig.mk
|
||||
endif
|
||||
include $(QCONFIG)
|
||||
USEFILE=
|
||||
LIBS+=socket
|
||||
include $(MKFILES_ROOT)/qtargets.mk
|
|
@ -0,0 +1,7 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("Hello there\n");
|
||||
return(0);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
LIST=VARIANT
|
||||
ifndef QRECURSE
|
||||
QRECURSE=recurse.mk
|
||||
ifdef QCONFIG
|
||||
QRDIR=$(dir $(QCONFIG))
|
||||
endif
|
||||
endif
|
||||
include $(QRDIR)$(QRECURSE)
|
|
@ -0,0 +1 @@
|
|||
include ../../common.mk
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
|
||||
|
||||
int func1 (void)
|
||||
{
|
||||
printf("This is func1\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
char * func2(void)
|
||||
{
|
||||
printf("This is func2\n");
|
||||
return(0);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int test2func1(void)
|
||||
{
|
||||
printf("This is a function in the second object\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
int test2func2(void)
|
||||
{
|
||||
printf("This is another function in the second object\n");
|
||||
return(2);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
LIST=VARIANT
|
||||
ifndef QRECURSE
|
||||
QRECURSE=recurse.mk
|
||||
ifdef QCONFIG
|
||||
QRDIR=$(dir $(QCONFIG))
|
||||
endif
|
||||
endif
|
||||
include $(QRDIR)$(QRECURSE)
|
|
@ -0,0 +1 @@
|
|||
include ../../common.mk
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
include ../../common.mk
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,8 @@
|
|||
LIST=VARIANT
|
||||
ifndef QRECURSE
|
||||
QRECURSE=recurse.mk
|
||||
ifdef QCONFIG
|
||||
QRDIR=$(dir $(QCONFIG))
|
||||
endif
|
||||
endif
|
||||
include $(QRDIR)$(QRECURSE)
|
|
@ -0,0 +1,7 @@
|
|||
ifndef QCONFIG
|
||||
QCONFIG=qconfig.mk
|
||||
endif
|
||||
include $(QCONFIG)
|
||||
USEFILE=
|
||||
|
||||
include $(MKFILES_ROOT)/qtargets.mk
|
|
@ -0,0 +1,8 @@
|
|||
#include <stdio.h>
|
||||
int bigArray[100];
|
||||
int x[10]={1,2,3,4,5,6,7,8,9,0};
|
||||
int main()
|
||||
{
|
||||
printf("Hello there\n");
|
||||
return(0);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
LIST=VARIANT
|
||||
ifndef QRECURSE
|
||||
QRECURSE=recurse.mk
|
||||
ifdef QCONFIG
|
||||
QRDIR=$(dir $(QCONFIG))
|
||||
endif
|
||||
endif
|
||||
include $(QRDIR)$(QRECURSE)
|
|
@ -0,0 +1 @@
|
|||
include ../../common.mk
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,8 @@
|
|||
LIST=VARIANT
|
||||
ifndef QRECURSE
|
||||
QRECURSE=recurse.mk
|
||||
ifdef QCONFIG
|
||||
QRDIR=$(dir $(QCONFIG))
|
||||
endif
|
||||
endif
|
||||
include $(QRDIR)$(QRECURSE)
|
|
@ -0,0 +1,6 @@
|
|||
ifndef QCONFIG
|
||||
QCONFIG=qconfig.mk
|
||||
endif
|
||||
include $(QCONFIG)
|
||||
|
||||
include $(MKFILES_ROOT)/qtargets.mk
|
|
@ -0,0 +1,14 @@
|
|||
#include <stdio.h>
|
||||
|
||||
|
||||
int func1 (void)
|
||||
{
|
||||
printf("This is func1\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
char * func2(void)
|
||||
{
|
||||
printf("This is func2\n");
|
||||
return(0);
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
#include <stdio.h>
|
||||
|
||||
int test2func1(void)
|
||||
{
|
||||
printf("This is a function in the second object\n");
|
||||
return(1);
|
||||
}
|
||||
|
||||
int test2func2(void)
|
||||
{
|
||||
printf("This is another function in the second object\n");
|
||||
return(2);
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
LIST=VARIANT
|
||||
ifndef QRECURSE
|
||||
QRECURSE=recurse.mk
|
||||
ifdef QCONFIG
|
||||
QRDIR=$(dir $(QCONFIG))
|
||||
endif
|
||||
endif
|
||||
include $(QRDIR)$(QRECURSE)
|
|
@ -0,0 +1 @@
|
|||
include ../../common.mk
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
include ../../common.mk
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -13,6 +13,14 @@ import org.eclipse.cdt.core.CProjectNature;
|
|||
import org.eclipse.cdt.core.model.CModelException;
|
||||
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.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.cdt.internal.core.model.CModelManager;
|
||||
import org.eclipse.core.resources.IContainer;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
|
@ -135,7 +143,132 @@ public class CProjectHelper {
|
|||
//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) {
|
||||
Archive myArchive;
|
||||
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);
|
||||
myArchive=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) {
|
||||
Binary myBinary;
|
||||
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);
|
||||
myBinary=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) {
|
||||
ICElement myICElement;
|
||||
int x;
|
||||
ICElement[] myElements;
|
||||
myElements=testProject.getChildren();
|
||||
if (myElements.length<1)
|
||||
return(null);
|
||||
myICElement=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) {
|
||||
ICElement myICElement;
|
||||
int x;
|
||||
ICElement[] myElements;
|
||||
myElements=testProject.getChildren();
|
||||
if (myElements.length<1)
|
||||
return(null);
|
||||
myICElement=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) {
|
||||
ICElement myICElement;
|
||||
int x;
|
||||
ICElement[] myElements;
|
||||
myElements=testProject.getChildren();
|
||||
if (myElements.length<1)
|
||||
return(null);
|
||||
myICElement=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
|
||||
|
|
|
@ -0,0 +1,97 @@
|
|||
package org.eclipse.cdt.testplugin.util;
|
||||
|
||||
|
||||
import java.util.Stack;
|
||||
/**
|
||||
* @author Peter Graves
|
||||
*
|
||||
* This utility class maintains a list of strings, and as a tests finds strings
|
||||
* in a structure/list, it will maintain a list of unfound/extra strings.
|
||||
*/
|
||||
public class ExpectedStrings {
|
||||
|
||||
public String [] expStrings;
|
||||
private boolean[] foundStrings;
|
||||
private Stack extraStrings; /* A stack of the unecpected strings we
|
||||
* recieved
|
||||
*/
|
||||
private boolean extra;
|
||||
|
||||
/**
|
||||
* Constructor for ExpectedStrings.
|
||||
*/
|
||||
public ExpectedStrings() {
|
||||
}
|
||||
/**
|
||||
* Constructor for ExpectedStrings that accepts a list of strings that
|
||||
* we expect to get.
|
||||
*/
|
||||
public ExpectedStrings(String[] values) {
|
||||
int x;
|
||||
expStrings=new String[values.length];
|
||||
for (x=0;x<values.length;x++) {
|
||||
expStrings[x]=new String(values[x]);
|
||||
}
|
||||
foundStrings=new boolean[values.length];
|
||||
for (x=0;x<values.length;x++) {
|
||||
foundStrings[x]=false;
|
||||
}
|
||||
extraStrings=new Stack();
|
||||
extra=false;
|
||||
}
|
||||
|
||||
public int foundString(String current) {
|
||||
int x;
|
||||
for (x=0;x<expStrings.length;x++) {
|
||||
if (current.equals(expStrings[x])) {
|
||||
foundStrings[x]=true;
|
||||
return(0);
|
||||
}
|
||||
}
|
||||
/* If we arrive here, the strings was not found, so this is
|
||||
* and extra string
|
||||
*/
|
||||
|
||||
extraStrings.push(new String(current));
|
||||
extra=true;
|
||||
return(1);
|
||||
}
|
||||
public int getNum(String name) {
|
||||
int x;
|
||||
for (x=0;x<expStrings.length;x++) {
|
||||
if (name.equals(expStrings[x]))
|
||||
return(x);
|
||||
}
|
||||
return(-1);
|
||||
}
|
||||
public boolean gotAll() {
|
||||
int x;
|
||||
for (x=0;x<expStrings.length;x++) {
|
||||
if (foundStrings[x]==false)
|
||||
return(false);
|
||||
}
|
||||
return(true);
|
||||
}
|
||||
public boolean gotExtra() {
|
||||
return(extra);
|
||||
}
|
||||
public String getMissingString() {
|
||||
int x;
|
||||
String missing = new String("Missing elements: ");
|
||||
for (x=0;x<expStrings.length;x++) {
|
||||
if (foundStrings[x]==false)
|
||||
missing+=expStrings[x];
|
||||
missing+=" ";
|
||||
}
|
||||
return(missing);
|
||||
}
|
||||
public String getExtraString() {
|
||||
int x;
|
||||
String extra= new String("Extra elements: ");
|
||||
while (!extraStrings.empty()) {
|
||||
extra+=extraStrings.pop();
|
||||
extra+=" ";
|
||||
}
|
||||
return(extra);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
package org.eclipse.cdt.testplugin.util;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* @author Peter Graves
|
||||
*
|
||||
*Some simple tests to make sure our ExtraStrings class seems to work.
|
||||
*/
|
||||
public class ExpectedStringsTests extends TestCase {
|
||||
|
||||
/**
|
||||
* Constructor for ExpectedStringsTests.
|
||||
* @param name
|
||||
*/
|
||||
public ExpectedStringsTests(String name) {
|
||||
super(name);
|
||||
}
|
||||
/**
|
||||
* Sets up the test fixture.
|
||||
*
|
||||
* Called before every test case method.
|
||||
*
|
||||
* Example code test the packages in the project
|
||||
* "com.qnx.tools.ide.cdt.core"
|
||||
*/
|
||||
protected void setUp() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Tears down the test fixture.
|
||||
*
|
||||
* Called after every test case method.
|
||||
*/
|
||||
protected void tearDown() {
|
||||
// release resources here and clean-up
|
||||
}
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new TestSuite(ExpectedStringsTests.class);
|
||||
}
|
||||
|
||||
public static void main (String[] args){
|
||||
junit.textui.TestRunner.run(suite());
|
||||
}
|
||||
|
||||
public void testGotAll() {
|
||||
ExpectedStrings myExp;
|
||||
String[] strings= {"stringOne", "stringTwo", "stringThree" };
|
||||
|
||||
myExp=new ExpectedStrings(strings);
|
||||
assertTrue("No found strings", !myExp.gotAll());
|
||||
myExp.foundString("stringOne");
|
||||
assertTrue("1 found strings", !myExp.gotAll());
|
||||
myExp.foundString("stringTwo");
|
||||
assertTrue("2 found strings", !myExp.gotAll());
|
||||
myExp.foundString("stringThree");
|
||||
assertTrue("All found strings", myExp.gotAll());
|
||||
|
||||
|
||||
}
|
||||
public void testGotExtra () {
|
||||
ExpectedStrings myExp;
|
||||
String[] strings= {"stringOne", "stringTwo", "stringThree" };
|
||||
|
||||
myExp=new ExpectedStrings(strings);
|
||||
assertTrue("No found strings", !myExp.gotExtra());
|
||||
myExp.foundString("stringOne");
|
||||
assertTrue("1 found strings", !myExp.gotExtra());
|
||||
myExp.foundString("stringTwo");
|
||||
assertTrue("2 found strings", !myExp.gotExtra());
|
||||
myExp.foundString("stringThree");
|
||||
assertTrue("All found strings", !myExp.gotExtra());
|
||||
myExp.foundString("Somerandomestring");
|
||||
assertTrue("Extra String", myExp.gotExtra());
|
||||
|
||||
}
|
||||
|
||||
public void testGetMissingString()
|
||||
{
|
||||
ExpectedStrings myExp;
|
||||
String[] strings= {"stringOne", "stringTwo", "stringThree" };
|
||||
|
||||
myExp=new ExpectedStrings(strings);
|
||||
assertNotNull(myExp.getMissingString());
|
||||
myExp.foundString("stringOne");
|
||||
assertNotNull(myExp.getMissingString());
|
||||
myExp.foundString("stringTwo");
|
||||
assertNotNull(myExp.getMissingString());
|
||||
myExp.foundString("stringThree");
|
||||
assertNotNull(myExp.getMissingString());
|
||||
|
||||
}
|
||||
|
||||
public void testGetExtraString()
|
||||
{
|
||||
ExpectedStrings myExp;
|
||||
String[] strings= {"stringOne", "stringTwo", "stringThree" };
|
||||
|
||||
myExp=new ExpectedStrings(strings);
|
||||
assertNotNull(myExp.getExtraString());
|
||||
myExp.foundString("stringOnenot");
|
||||
assertNotNull(myExp.getMissingString());
|
||||
myExp.foundString("stringTwonot");
|
||||
assertNotNull(myExp.getMissingString());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue