summaryrefslogtreecommitdiff
path: root/test/junit/net/sf/antcontrib/cpptasks/compiler
diff options
context:
space:
mode:
authorMark Donszelmann <Mark.Donszelmann@gmail.com>2005-11-18 21:02:34 +0000
committerMark Donszelmann <Mark.Donszelmann@gmail.com>2005-11-18 21:02:34 +0000
commit1381c87965ab669820a4a7b48c09aca026f5b478 (patch)
tree947d5ba097efbc93fae515fdae35e626c1be7bef /test/junit/net/sf/antcontrib/cpptasks/compiler
downloadcpptasks-parallel-1381c87965ab669820a4a7b48c09aca026f5b478.tar.gz
cpptasks-parallel-1381c87965ab669820a4a7b48c09aca026f5b478.tar.bz2
cpptasks-parallel-1381c87965ab669820a4a7b48c09aca026f5b478.tar.xz
cpptasks-parallel-1381c87965ab669820a4a7b48c09aca026f5b478.zip
Diffstat (limited to 'test/junit/net/sf/antcontrib/cpptasks/compiler')
-rw-r--r--test/junit/net/sf/antcontrib/cpptasks/compiler/CVS/Entries7
-rw-r--r--test/junit/net/sf/antcontrib/cpptasks/compiler/CVS/Repository1
-rw-r--r--test/junit/net/sf/antcontrib/cpptasks/compiler/CVS/Root1
-rw-r--r--test/junit/net/sf/antcontrib/cpptasks/compiler/TestAbstractCompiler.java85
-rw-r--r--test/junit/net/sf/antcontrib/cpptasks/compiler/TestAbstractLinker.java89
-rw-r--r--test/junit/net/sf/antcontrib/cpptasks/compiler/TestAbstractProcessor.java80
-rw-r--r--test/junit/net/sf/antcontrib/cpptasks/compiler/TestCommandLineCompilerConfiguration.java59
-rw-r--r--test/junit/net/sf/antcontrib/cpptasks/compiler/TestCompilerConfiguration.java68
-rw-r--r--test/junit/net/sf/antcontrib/cpptasks/compiler/TestLinkType.java59
9 files changed, 449 insertions, 0 deletions
diff --git a/test/junit/net/sf/antcontrib/cpptasks/compiler/CVS/Entries b/test/junit/net/sf/antcontrib/cpptasks/compiler/CVS/Entries
new file mode 100644
index 0000000..07eeda9
--- /dev/null
+++ b/test/junit/net/sf/antcontrib/cpptasks/compiler/CVS/Entries
@@ -0,0 +1,7 @@
+/TestAbstractCompiler.java/1.21/Tue May 11 03:50:12 2004//
+/TestAbstractLinker.java/1.20/Tue May 11 03:50:13 2004//
+/TestAbstractProcessor.java/1.17/Tue May 11 03:50:12 2004//
+/TestCommandLineCompilerConfiguration.java/1.10/Sat Feb 28 19:04:47 2004//
+/TestCompilerConfiguration.java/1.9/Tue May 11 03:50:13 2004//
+/TestLinkType.java/1.2/Sat Feb 28 19:04:47 2004//
+D
diff --git a/test/junit/net/sf/antcontrib/cpptasks/compiler/CVS/Repository b/test/junit/net/sf/antcontrib/cpptasks/compiler/CVS/Repository
new file mode 100644
index 0000000..43e8cff
--- /dev/null
+++ b/test/junit/net/sf/antcontrib/cpptasks/compiler/CVS/Repository
@@ -0,0 +1 @@
+cpptasks/test/junit/net/sf/antcontrib/cpptasks/compiler
diff --git a/test/junit/net/sf/antcontrib/cpptasks/compiler/CVS/Root b/test/junit/net/sf/antcontrib/cpptasks/compiler/CVS/Root
new file mode 100644
index 0000000..1ac95cd
--- /dev/null
+++ b/test/junit/net/sf/antcontrib/cpptasks/compiler/CVS/Root
@@ -0,0 +1 @@
+:pserver:anonymous@cvs.sourceforge.net:/cvsroot/ant-contrib
diff --git a/test/junit/net/sf/antcontrib/cpptasks/compiler/TestAbstractCompiler.java b/test/junit/net/sf/antcontrib/cpptasks/compiler/TestAbstractCompiler.java
new file mode 100644
index 0000000..5a1e66b
--- /dev/null
+++ b/test/junit/net/sf/antcontrib/cpptasks/compiler/TestAbstractCompiler.java
@@ -0,0 +1,85 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.compiler;
+import java.io.File;
+
+import net.sf.antcontrib.cpptasks.CCTask;
+import net.sf.antcontrib.cpptasks.CompilerDef;
+import net.sf.antcontrib.cpptasks.ProcessorDef;
+import net.sf.antcontrib.cpptasks.parser.CParser;
+import net.sf.antcontrib.cpptasks.parser.Parser;
+import net.sf.antcontrib.cpptasks.VersionInfo;
+
+import org.apache.tools.ant.BuildException;
+/**
+ * Test for abstract compiler class
+ *
+ * Override create to test concrete compiler implementions
+ */
+public class TestAbstractCompiler extends TestAbstractProcessor {
+ private class DummyAbstractCompiler extends AbstractCompiler {
+ public DummyAbstractCompiler() {
+ super(new String[]{".cpp", ".c"},
+ new String[]{".hpp", ".h", ".inl"}, ".o");
+ }
+ public void compile(CCTask task, File[] srcfile, File[] outputfile,
+ CompilerConfiguration config) throws BuildException {
+ throw new BuildException("Not implemented");
+ }
+ public CompilerConfiguration createConfiguration(CCTask task,
+ LinkType linkType, ProcessorDef[] def1, CompilerDef def2,
+ net.sf.antcontrib.cpptasks.TargetDef targetPlatform,
+ VersionInfo versionInfo) {
+ return null;
+ }
+ public Parser createParser(File file) {
+ return new CParser();
+ }
+ public String getIdentifier() {
+ return "dummy";
+ }
+ public Linker getLinker(LinkType type) {
+ return null;
+ }
+ }
+ public TestAbstractCompiler(String name) {
+ super(name);
+ }
+ protected AbstractProcessor create() {
+ return new DummyAbstractCompiler();
+ }
+ protected String getObjectExtension() {
+ return ".o";
+ }
+ public void testCanParseTlb() {
+ AbstractCompiler compiler = (AbstractCompiler) create();
+ assertEquals(false, compiler.canParse(new File("sample.tlb")));
+ }
+ public void testGetOutputFileName1() {
+ AbstractProcessor compiler = create();
+ String[] output = compiler.getOutputFileNames("c:/foo\\bar\\hello.c", null);
+ assertEquals("hello" + getObjectExtension(), output[0]);
+ output = compiler.getOutputFileNames("c:/foo\\bar/hello.c", null);
+ assertEquals("hello" + getObjectExtension(), output[0]);
+ output = compiler.getOutputFileNames("hello.c", null);
+ assertEquals("hello" + getObjectExtension(), output[0]);
+ output = compiler.getOutputFileNames("c:/foo\\bar\\hello.h", null);
+ assertEquals(0, output.length);
+ output = compiler.getOutputFileNames("c:/foo\\bar/hello.h", null);
+ assertEquals(0, output.length);
+ }
+}
diff --git a/test/junit/net/sf/antcontrib/cpptasks/compiler/TestAbstractLinker.java b/test/junit/net/sf/antcontrib/cpptasks/compiler/TestAbstractLinker.java
new file mode 100644
index 0000000..b444a0a
--- /dev/null
+++ b/test/junit/net/sf/antcontrib/cpptasks/compiler/TestAbstractLinker.java
@@ -0,0 +1,89 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.compiler;
+import java.io.File;
+
+import net.sf.antcontrib.cpptasks.CCTask;
+import net.sf.antcontrib.cpptasks.LinkerDef;
+import net.sf.antcontrib.cpptasks.ProcessorDef;
+import net.sf.antcontrib.cpptasks.types.LibraryTypeEnum;
+import net.sf.antcontrib.cpptasks.TargetDef;
+import net.sf.antcontrib.cpptasks.VersionInfo;
+
+/**
+ * Test for abstract compiler class
+ *
+ * Override create to test concrete compiler implementions
+ */
+public class TestAbstractLinker extends TestAbstractProcessor {
+ private class DummyAbstractLinker extends AbstractLinker {
+ public DummyAbstractLinker() {
+ super(new String[]{".obj", ".lib"}, new String[]{".map", ".exp"});
+ }
+ public LinkerConfiguration createConfiguration(final CCTask task,
+ final LinkType linkType,
+ final ProcessorDef[] def1,
+ final LinkerDef def2,
+ final TargetDef targetPlatform,
+ final VersionInfo versionInfo) {
+ return null;
+ }
+ public String getIdentifier() {
+ return "dummy";
+ }
+ public File[] getLibraryPath() {
+ return new File[0];
+ }
+ public String[] getLibraryPatterns(String[] libnames, LibraryTypeEnum libType) {
+ return libnames;
+ }
+ public Linker getLinker(LinkType type) {
+ return null;
+ }
+ public String[] getOutputFileNames(String sourceFile, VersionInfo versionInfo) {
+ return new String[0];
+ }
+ public String[][] getRuntimeLibraries(boolean debug,
+ boolean multithreaded, boolean staticLink) {
+ return new String[2][0];
+ }
+ public boolean isCaseSensitive() {
+ return true;
+ }
+ }
+ public TestAbstractLinker(String name) {
+ super(name);
+ }
+ protected AbstractProcessor create() {
+ return new DummyAbstractLinker();
+ }
+ public void testBid() {
+ AbstractProcessor compiler = create();
+ int bid = compiler.bid("c:/foo\\bar\\hello.obj");
+ assertEquals(100, bid);
+ bid = compiler.bid("c:/foo\\bar/hello.lib");
+ assertEquals(100, bid);
+ bid = compiler.bid("c:/foo\\bar\\hello.map");
+ assertEquals(0, bid);
+ bid = compiler.bid("c:/foo\\bar/hello.map");
+ assertEquals(0, bid);
+ bid = compiler.bid("c:/foo\\bar/hello.c");
+ assertEquals(1, bid);
+ bid = compiler.bid("c:/foo\\bar/hello.cpp");
+ assertEquals(1, bid);
+ }
+}
diff --git a/test/junit/net/sf/antcontrib/cpptasks/compiler/TestAbstractProcessor.java b/test/junit/net/sf/antcontrib/cpptasks/compiler/TestAbstractProcessor.java
new file mode 100644
index 0000000..f2c04a3
--- /dev/null
+++ b/test/junit/net/sf/antcontrib/cpptasks/compiler/TestAbstractProcessor.java
@@ -0,0 +1,80 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.compiler;
+import junit.framework.TestCase;
+import net.sf.antcontrib.cpptasks.CCTask;
+import net.sf.antcontrib.cpptasks.ProcessorDef;
+import net.sf.antcontrib.cpptasks.VersionInfo;
+/**
+ * Test for abstract compiler class
+ *
+ * Override create to test concrete compiler implementions
+ */
+public class TestAbstractProcessor extends TestCase {
+ private class DummyAbstractProcessor extends AbstractProcessor {
+ public DummyAbstractProcessor() {
+ super(new String[]{".cpp", ".c"},
+ new String[]{".hpp", ".h", ".inl"});
+ }
+ public ProcessorConfiguration createConfiguration(CCTask task,
+ LinkType linkType, ProcessorDef[] defaultProvider,
+ ProcessorDef specificProvider,
+ net.sf.antcontrib.cpptasks.TargetDef targetPlatform,
+ VersionInfo versionInfo) {
+ return null;
+ }
+ public String getIdentifier() {
+ return "dummy";
+ }
+ public Linker getLinker(LinkType type) {
+ return null;
+ }
+ public String[] getOutputFileNames(String sourceFile, VersionInfo versionInfo) {
+ return new String[0];
+ }
+ public String[][] getRuntimeLibraries(boolean debug,
+ boolean multithreaded, boolean staticLink) {
+ return new String[2][0];
+ }
+ }
+ public TestAbstractProcessor(String name) {
+ super(name);
+ }
+ protected AbstractProcessor create() {
+ return new DummyAbstractProcessor();
+ }
+ public void testBid() {
+ AbstractProcessor compiler = create();
+ int bid = compiler.bid("c:/foo\\bar\\hello.c");
+ assertEquals(100, bid);
+ bid = compiler.bid("c:/foo\\bar/hello.c");
+ assertEquals(100, bid);
+ bid = compiler.bid("c:/foo\\bar\\hello.h");
+ assertEquals(1, bid);
+ bid = compiler.bid("c:/foo\\bar/hello.h");
+ assertEquals(1, bid);
+ bid = compiler.bid("c:/foo\\bar/hello.pas");
+ assertEquals(0, bid);
+ bid = compiler.bid("c:/foo\\bar/hello.java");
+ assertEquals(0, bid);
+ }
+ public void testGetIdentfier() {
+ AbstractProcessor compiler = create();
+ String id = compiler.getIdentifier();
+ assertEquals("dummy", id);
+ }
+}
diff --git a/test/junit/net/sf/antcontrib/cpptasks/compiler/TestCommandLineCompilerConfiguration.java b/test/junit/net/sf/antcontrib/cpptasks/compiler/TestCommandLineCompilerConfiguration.java
new file mode 100644
index 0000000..a22fa0d
--- /dev/null
+++ b/test/junit/net/sf/antcontrib/cpptasks/compiler/TestCommandLineCompilerConfiguration.java
@@ -0,0 +1,59 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.compiler;
+import java.io.File;
+
+import net.sf.antcontrib.cpptasks.ProcessorParam;
+import net.sf.antcontrib.cpptasks.gcc.GccCCompiler;
+/**
+ */
+public class TestCommandLineCompilerConfiguration
+ extends
+ TestCompilerConfiguration {
+ private final CommandLineCompiler compiler;
+ private final String compilerId;
+ public TestCommandLineCompilerConfiguration(String name) {
+ super(name);
+ compiler = (GccCCompiler) GccCCompiler.getInstance();
+ compilerId = compiler.getIdentifier();
+ }
+ protected CompilerConfiguration create() {
+ return new CommandLineCompilerConfiguration(compiler, "dummy",
+ new File[0], new File[0], new File[0], "",
+ new String[]{"/Id:/gcc"}, new ProcessorParam[0], false,
+ new String[0]);
+ }
+ public void testConstructorNullCompiler() {
+ try {
+ new CommandLineCompilerConfiguration(null, "dummy", new File[0],
+ new File[0], new File[0], "", new String[0],
+ new ProcessorParam[0], false, new String[0]);
+ fail("Should throw exception for null compiler");
+ } catch (NullPointerException ex) {
+ }
+ }
+ public void testGetIdentifier() {
+ CompilerConfiguration config = create();
+ String id = config.getIdentifier();
+ assertEquals("dummy", id);
+ }
+ public void testToString() {
+ CompilerConfiguration config = create();
+ String toString = config.toString();
+ assertEquals("dummy", toString);
+ }
+}
diff --git a/test/junit/net/sf/antcontrib/cpptasks/compiler/TestCompilerConfiguration.java b/test/junit/net/sf/antcontrib/cpptasks/compiler/TestCompilerConfiguration.java
new file mode 100644
index 0000000..a928ae4
--- /dev/null
+++ b/test/junit/net/sf/antcontrib/cpptasks/compiler/TestCompilerConfiguration.java
@@ -0,0 +1,68 @@
+/*
+ *
+ * Copyright 2002-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.compiler;
+import junit.framework.TestCase;
+/**
+ */
+public abstract class TestCompilerConfiguration extends TestCase {
+ public TestCompilerConfiguration(String name) {
+ super(name);
+ }
+ protected abstract CompilerConfiguration create();
+ public String getObjectFileExtension() {
+ return ".o";
+ }
+ public void testBid() {
+ CompilerConfiguration compiler = create();
+ int bid = compiler.bid("c:/foo\\bar\\hello.c");
+ assertEquals(100, bid);
+ bid = compiler.bid("c:/foo\\bar/hello.c");
+ assertEquals(100, bid);
+ bid = compiler.bid("c:/foo\\bar\\hello.h");
+ assertEquals(1, bid);
+ bid = compiler.bid("c:/foo\\bar/hello.h");
+ assertEquals(1, bid);
+ bid = compiler.bid("c:/foo\\bar/hello.pas");
+ assertEquals(0, bid);
+ bid = compiler.bid("c:/foo\\bar/hello.java");
+ assertEquals(0, bid);
+ }
+ public void testGetOutputFileName1() {
+ CompilerConfiguration compiler = create();
+ String input = "c:/foo\\bar\\hello.c";
+ //
+ // may cause IllegalStateException since
+ // setPlatformInfo has not been called
+ try {
+ String[] output = compiler.getOutputFileNames(input, null);
+ } catch (java.lang.IllegalStateException ex) {
+ }
+ }
+ public void testGetOutputFileName2() {
+ CompilerConfiguration compiler = create();
+ String[] output = compiler.getOutputFileNames("c:/foo\\bar\\hello.c", null);
+ assertEquals("hello" + getObjectFileExtension(), output[0]);
+ output = compiler.getOutputFileNames("c:/foo\\bar/hello.c", null);
+ assertEquals("hello" + getObjectFileExtension(), output[0]);
+ output = compiler.getOutputFileNames("hello.c", null);
+ assertEquals("hello" + getObjectFileExtension(), output[0]);
+ output = compiler.getOutputFileNames("c:/foo\\bar\\hello.h", null);
+ assertEquals(0, output.length);
+ output = compiler.getOutputFileNames("c:/foo\\bar/hello.h", null);
+ assertEquals(0, output.length);
+ }
+}
diff --git a/test/junit/net/sf/antcontrib/cpptasks/compiler/TestLinkType.java b/test/junit/net/sf/antcontrib/cpptasks/compiler/TestLinkType.java
new file mode 100644
index 0000000..a7e3a45
--- /dev/null
+++ b/test/junit/net/sf/antcontrib/cpptasks/compiler/TestLinkType.java
@@ -0,0 +1,59 @@
+/*
+ *
+ * Copyright 2003-2004 The Ant-Contrib project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.antcontrib.cpptasks.compiler;
+import junit.framework.TestCase;
+import net.sf.antcontrib.cpptasks.OutputTypeEnum;
+/**
+ * Tests for LinkType
+ *
+ * @author CurtA
+ */
+public class TestLinkType extends TestCase {
+ /**
+ * Constructor
+ *
+ * @param name
+ * test case name
+ */
+ public TestLinkType(String name) {
+ super(name);
+ }
+ /**
+ * Tests if isPluginModule returns true when set to plugin output type
+ *
+ * See patch [ 676276 ] Enhanced support for Mac OS X
+ */
+ public void testIsPluginFalse() {
+ LinkType type = new LinkType();
+ OutputTypeEnum pluginType = new OutputTypeEnum();
+ pluginType.setValue("executable");
+ type.setOutputType(pluginType);
+ assertTrue(!type.isPluginModule());
+ }
+ /**
+ * Tests if isPluginModule returns true when set to plugin output type
+ *
+ * See patch [ 676276 ] Enhanced support for Mac OS X
+ */
+ public void testIsPluginTrue() {
+ LinkType type = new LinkType();
+ OutputTypeEnum pluginType = new OutputTypeEnum();
+ pluginType.setValue("plugin");
+ type.setOutputType(pluginType);
+ assertTrue(type.isPluginModule());
+ }
+}