diff options
Diffstat (limited to 'framework/src/ant/apache-ant-1.9.6/src/tests')
576 files changed, 66047 insertions, 0 deletions
diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/antunit-base.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/antunit-base.xml new file mode 100644 index 00000000..80b289ca --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/antunit-base.xml @@ -0,0 +1,60 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="antunit-base"> + + <property name="antunit.tmpdir" location="${java.io.tmpdir}"/> + <property name="input" location="${antunit.tmpdir}/testinput"/> + <property name="output" location="${antunit.tmpdir}/testoutput"/> + <property name="resources" location="${antunit.tmpdir}/resources"/> + <property name="test.jar" location="${antunit.tmpdir}/test.jar"/> + <property name="test1.jar" location="${antunit.tmpdir}/test1.jar"/> + <property name="test2.jar" location="${antunit.tmpdir}/test2.jar"/> + <property name="test3.jar" location="${antunit.tmpdir}/test3.jar"/> + <property name="test4.jar" location="${antunit.tmpdir}/test4.jar"/> + <property name="test5.jar" location="${antunit.tmpdir}/test5.jar"/> + <condition property="jdk1.9+"> + <contains string="${java.version}" substring="1.9."/> + </condition> + <available property="jdk1.8+" classname="java.lang.reflect.Executable"/> + <available property="jdk1.7+" classname="java.nio.file.FileSystem"/> + <available property="jdk1.6+" classname="java.net.CookieStore"/> + <available property="jdk1.5+" classname="java.net.Proxy"/> + <condition property="build.sysclasspath.only"> + <equals arg1="${build.sysclasspath}" arg2="only"/> + </condition> + + <target name="tearDown"> + <delete dir="${input}"/> + <delete dir="${output}"/> + <delete dir="${resources}"/> + <delete file="${test.jar}" failonerror="false" deleteonexit="true"/> + <delete file="${test1.jar}" failonerror="false" deleteonexit="true"/> + <delete file="${test2.jar}" failonerror="false" deleteonexit="true"/> + <delete file="${test3.jar}" failonerror="false" deleteonexit="true"/> + <delete file="${test4.jar}" failonerror="false" deleteonexit="true"/> + <delete file="${test5.jar}" failonerror="false" deleteonexit="true"/> + </target> + + <target name="antunit"> + <antunit xmlns="antlib:org.apache.ant.antunit"> + <plainlistener /> + <file file="${ant.file}" xmlns="antlib:org.apache.tools.ant" /> + </antunit> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/README.txt b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/README.txt new file mode 100644 index 00000000..c2b5e5df --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/README.txt @@ -0,0 +1,2 @@ +This directory contains tests for the bugs +that have been fixed. diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/br50866/br50866-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/br50866/br50866-test.xml new file mode 100644 index 00000000..9e2d2037 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/br50866/br50866-test.xml @@ -0,0 +1,13 @@ +<project name="br50866" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../../antunit-base.xml" /> + + <include file="middle.xml" /> + + <target name="testinclude" depends="middle.common,middle.middle"> + <au:assertPropertyEquals name="prop-common-init" value="br50866"/> + <au:assertPropertyEquals name="prop-common" value="br50866"/> + <au:assertPropertyEquals name="prop-middle" value="br50866"/> + </target> + +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/br50866/common.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/br50866/common.xml new file mode 100644 index 00000000..7417c0de --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/br50866/common.xml @@ -0,0 +1,8 @@ +<project name="common" default="default"> + <target name="common-init"> + <property name="prop-common-init" value="br50866" /> + </target> + <target name="common" depends="common-init"> + <property name="prop-common" value="br50866" /> + </target> +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/br50866/middle.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/br50866/middle.xml new file mode 100644 index 00000000..b387f931 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/br50866/middle.xml @@ -0,0 +1,7 @@ +<project name="middle" default="default"> + <import file="common.xml" optional="true" /> + + <target name="middle" depends="common-init"> + <property name="prop-middle" value="br50866" /> + </target> +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/bugzilla-43324-stackoverflow-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/bugzilla-43324-stackoverflow-test.xml new file mode 100644 index 00000000..d706b8fc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/bugfixes/bugzilla-43324-stackoverflow-test.xml @@ -0,0 +1,68 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="length-test" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <target name="testnested"> + <macrodef name="root-macro"> + <element name="sub-tasks" optional="false" /> + + <sequential> + <!-- do stuff --> + <sub-tasks /> + </sequential> + </macrodef> + + <macrodef name="used-macro-a"> + <element name="a-sub-tasks" optional="false" implicit="true" /> + + <sequential> + <root-macro> + <sub-tasks> + <!-- do stuff --> + <a-sub-tasks /> + </sub-tasks> + </root-macro> + </sequential> + </macrodef> + + <macrodef name="used-macro-b"> + <element name="b-sub-tasks" optional="false" implicit="true" /> + + <sequential> + <used-macro-a> + <root-macro> + <sub-tasks> + <!-- do stuff --> + <b-sub-tasks /> + </sub-tasks> + </root-macro> + </used-macro-a> + </sequential> + </macrodef> + + <used-macro-b> + <echo message="Test B" /> + </used-macro-b> + + <au:assertLogContains text="Test B"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/ant-attribute-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/ant-attribute-test.xml new file mode 100644 index 00000000..6f6dc51d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/ant-attribute-test.xml @@ -0,0 +1,74 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="ant-attribute-test" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit" + xmlns:if="ant:if" + xmlns:unless="ant:unless" + > + + <import file="../antunit-base.xml" /> + + <target name="test-if-set"> + <echo message="message1" if:set="not-set"/> + <au:assertLogDoesntContain text="message1"/> + </target> + + <target name="test-unless-set"> + <echo message="message2" unless:set="not-set"/> + <au:assertLogContains text="message2"/> + </target> + + <target name="test-if-true"> + <property name="sample" value="true"/> + <echo message="message3" if:true="${sample}"/> + <au:assertLogContains text="message3"/> + </target> + + <target name="test-if-true-false"> + <property name="sample-1" value="false"/> + <echo message="message4" if:true="${sample-1}"/> + <au:assertLogDoesntContain text="message4"/> + </target> + + <target name="test-unless-true-false"> + <property name="sample-1" value="false"/> + <echo message="message5" unless:true="${sample-1}"/> + <au:assertLogContains text="message5"/> + </target> + + <target name="test-if-blank"> + <property name="sample-1" value=""/> + <echo message="message6" if:blank="${sample-1}"/> + <au:assertLogContains text="message6"/> + </target> + + + + + <target name="test-macrodef"> + <property name="verbose" value="true"/> + <macrodef name="sayhi"> + <sequential> + <echo>hi</echo> + </sequential> + </macrodef> + <sayhi if:set="verbose" /> + <au:assertLogContains text="hi"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/bindtargets-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/bindtargets-test.xml new file mode 100644 index 00000000..0279a2cc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/bindtargets-test.xml @@ -0,0 +1,39 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml"/> + + <target name="bound"> + <property name="test-bound" value="ok" /> + </target> + + <target name="bound2"> + <property name="test-bound2" value="ok" /> + </target> + + <extension-point name="extension" /> + + <bindtargets targets="bound,bound2" extensionPoint="extension" /> + + <target name="testBind" depends="extension"> + <au:assertPropertyEquals name="test-bound" value="ok"/> + <au:assertPropertyEquals name="test-bound2" value="ok"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/classloader-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/classloader-test.xml new file mode 100644 index 00000000..4af0040e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/classloader-test.xml @@ -0,0 +1,88 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml"/> + + <target name="setUp"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <condition property="gump"> + <available classname="org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"/> + </condition> + </target> + + <target name="testGetResource" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=44103" + depends="setUp" + unless="gump"> + <echo file="${input}/A.java"><![CDATA[ +public class A { + public static void main(String[] args) { + if (A.class.getClassLoader().getResource("org/apache/xerces/jaxp/DocumentBuilderFactoryImpl.class") != null) { + throw new RuntimeException("Didn't expect to find DocumentBuilderImpl"); + } + } +} +]]></echo> + <javac srcdir="${input}" destdir="${output}"/> + <java classname="A" failonerror="true" fork="false"> + <classpath location="${output}"/> + </java> + </target> + + <target name="testLoadClass" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=44103" + depends="setUp"> + <echo file="${input}/A.java"><![CDATA[ +public class A { + public static void main(String[] args) { + try { + A.class.getClassLoader().loadClass("org.apache.xerces.jaxp.DocumentBuilderFactoryImpl"); + throw new RuntimeException("Didn't expect to find DocumentBuilderImpl"); + } catch (ClassNotFoundException cnfe) { + } + } +} +]]></echo> + <javac srcdir="${input}" destdir="${output}"/> + <java classname="A" failonerror="true" fork="false"> + <classpath location="${output}"/> + </java> + </target> + + <target name="testGetResourceAsStream" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=44103" + depends="setUp" + unless="gump"> + <echo file="${input}/A.java"><![CDATA[ +public class A { + public static void main(String[] args) { + if (A.class.getClassLoader().getResourceAsStream("org/apache/xerces/jaxp/DocumentBuilderFactoryImpl.class") != null) { + throw new RuntimeException("Didn't expect to find DocumentBuilderImpl"); + } + } +} +]]></echo> + <javac srcdir="${input}" destdir="${output}"/> + <java classname="A" failonerror="true" fork="false"> + <classpath location="${output}"/> + </java> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/createtask-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/createtask-test.xml new file mode 100644 index 00000000..b69633b3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/createtask-test.xml @@ -0,0 +1,50 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml"/> + + <target name="setUp"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + </target> + + <target name="-create-task" depends="setUp"> + <mkdir dir="${input}/org/apache/ant/example"/> + <echo file="${input}/org/apache/ant/example/Foo.java"><![CDATA[ +package org.apache.ant.example; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +public class Foo extends Task { + public void execute() { + new Project().createTask("Delete"); + } +} +]]></echo> + <javac srcdir="${input}" destdir="${output}"/> + <taskdef name="foo" classname="org.apache.ant.example.Foo"> + <classpath location="${output}"/> + </taskdef> + </target> + + <target name="testCreateTaskInFreshProject" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50788" + depends="-create-task"> + <foo/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/dirscanner-symlinks-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/dirscanner-symlinks-test.xml new file mode 100644 index 00000000..0645946a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/dirscanner-symlinks-test.xml @@ -0,0 +1,200 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml"/> + + <target name="setUp"> + <property name="base" location="${input}/base"/> + <mkdir dir="${base}"/> + </target> + + <target name="checkOs"> + <condition property="unix"><os family="unix"/></condition> + </target> + + <macrodef name="assertDirIsEmpty"> + <attribute name="dir" default="${output}"/> + <sequential> + <local name="resources"/> + <resourcecount property="resources"> + <fileset dir="@{dir}"/> + </resourcecount> + <au:assertEquals expected="0" actual="${resources}"/> + </sequential> + </macrodef> + + <target name="testSymlinkToSiblingFollow" + depends="checkOs, setUp, -sibling" + if="unix"> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="true"/> + </copy> + <au:assertFileExists file="${output}/B/file.txt"/> + </target> + + <target name="testSymlinkToSiblingNoFollow" + depends="checkOs, setUp, -sibling" + if="unix"> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="false"/> + </copy> + <au:assertFileDoesntExist file="${output}/B/file.txt"/> + </target> + + <target name="testBasedirIsSymlinkFollow" + depends="checkOs, setUp, -basedir-as-symlink" + if="unix"> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="true"/> + </copy> + <au:assertFileExists file="${output}/file.txt"/> + </target> + + <target name="testBasedirIsSymlinkNoFollow" + depends="checkOs, setUp, -basedir-as-symlink" + if="unix"> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="false"/> + </copy> + <au:assertFileDoesntExist file="${output}/file.txt"/> + </target> + + <target name="testLinkToParentFollow" + depends="checkOs, setUp, -link-to-parent" + if="unix"> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="true" maxLevelsOfSymlinks="1"/> + </copy> + <symlink action="delete" link="${base}/A"/> + <au:assertFileExists file="${output}/A/B/file.txt"/> + <au:assertFileDoesntExist file="${output}/A/base/A/B/file.txt"/> + </target> + + <target name="testLinkToParentFollowMax2" + depends="checkOs, setUp, -link-to-parent" + if="unix"> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="true" maxLevelsOfSymlinks="2"/> + </copy> + <symlink action="delete" link="${base}/A"/> + <au:assertFileExists file="${output}/A/B/file.txt"/> + <au:assertFileExists file="${output}/A/base/A/B/file.txt"/> + </target> + + <target name="testLinkToParentFollowWithInclude" + depends="checkOs, setUp, -link-to-parent" + if="unix"> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="true"> + <include name="A/B/*"/> + </fileset> + </copy> + <symlink action="delete" link="${base}/A"/> + <au:assertFileExists file="${output}/A/B/file.txt"/> + </target> + + <!-- supposed to fail? --> + <target name="testLinkToParentFollowWithIncludeMultiFollow" + depends="checkOs, setUp, -link-to-parent" + if="unix"> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="true"> + <include name="A/base/A/B/*"/> + </fileset> + </copy> + <symlink action="delete" link="${base}/A"/> + <au:assertFileExists file="${output}/A/base/A/B/file.txt"/> + </target> + + <target name="testLinkToParentNoFollow" + depends="checkOs, setUp, -link-to-parent" + if="unix"> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="false"/> + </copy> + <symlink action="delete" link="${base}/A"/> + <au:assertFileDoesntExist file="${output}/A/B/file.txt"/> + </target> + + <target name="testSillyLoopFollow" + depends="checkOs, setUp, -silly-loop" + if="unix"> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="true"/> + </copy> + <symlink action="delete" link="${base}"/> + <assertDirIsEmpty/> + </target> + + <target name="testSillyLoopNoFollow" + depends="checkOs, setUp, -silly-loop" + if="unix"> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="false"/> + </copy> + <symlink action="delete" link="${base}"/> + <au:assertFileDoesntExist file="${output}"/> + </target> + + <target name="testRepeatedName" + depends="setUp"> + <mkdir dir="${base}/A/A/A/A"/> + <touch file="${base}/A/A/A/A/file.txt"/> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="true" maxLevelsOfSymlinks="1"/> + </copy> + <au:assertFileExists file="${output}/A/A/A/A/file.txt"/> + </target> + + <target name="testRepeatedNameWithLinkButNoLoop" + depends="checkOs, setUp" + if="unix"> + <mkdir dir="${base}/A/A/A/B"/> + <touch file="${base}/A/A/A/B/file.txt"/> + <symlink link="${base}/A/A/A/A" resource="${base}/A/A/A/B"/> + <copy todir="${output}"> + <fileset dir="${base}" followsymlinks="true" maxLevelsOfSymlinks="1"/> + </copy> + <au:assertFileExists file="${output}/A/A/A/A/file.txt"/> + </target> + + <target name="-sibling" if="unix"> + <mkdir dir="${base}/A"/> + <touch file="${base}/A/file.txt"/> + <symlink link="${base}/B" resource="${base}/A"/> + </target> + + <target name="-basedir-as-symlink" if="unix"> + <delete dir="${base}"/> + <mkdir dir="${input}/realdir"/> + <touch file="${input}/realdir/file.txt"/> + <symlink link="${base}" resource="${input}/realdir"/> + </target> + + <target name="-link-to-parent" if="unix"> + <mkdir dir="${input}/B"/> + <touch file="${input}/B/file.txt"/> + <symlink link="${base}/A" resource="${input}"/> + </target> + + <target name="-silly-loop" if="unix"> + <delete dir="${base}"/> + <symlink link="${base}" resource="${input}"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/extension-point-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/extension-point-test.xml new file mode 100644 index 00000000..8c0dbdb9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/extension-point-test.xml @@ -0,0 +1,210 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml"/> + + <extension-point name="testExtensionPointWorksLikeTarget" + depends="setProperty, assertProperty"/> + + <target name="setProperty"> + <property name="foo" value="bar"/> + </target> + + <target name="assertProperty"> + <au:assertPropertyEquals name="foo" value="bar"/> + </target> + + <target name="testExtensionPointMustBeEmpty"> + <mkdir dir="${output}"/> + <echo file="${output}/build.xml"><![CDATA[ +<project> + <extension-point name="foo"> + <echo>bar</echo> + </extension-point> +</project>]]></echo> + <au:expectfailure + expectedMessage="you must not nest child elements into an extension-point"> + <ant dir="${output}"/> + </au:expectfailure> + </target> + + <target name="testAddToExtensionPoint"> + <mkdir dir="${output}"/> + <echo file="${output}/build.xml"><![CDATA[ +<project default="foo"> + <extension-point name="foo"/> + <target name="bar" extensionOf="foo"> + <echo>In target bar</echo> + </target> +</project>]]></echo> + <ant dir="${output}"/> + <au:assertLogContains text="In target bar"/> + </target> + + <target name="testCantAddToPlainTarget"> + <mkdir dir="${output}"/> + <echo file="${output}/build.xml"><![CDATA[ +<project default="foo"> + <target name="foo"/> + <target name="bar" extensionOf="foo"/> +</project>]]></echo> + <au:expectfailure + expectedMessage="referenced target foo is not an extension-point"> + <ant dir="${output}"/> + </au:expectfailure> + </target> + + <target name="testExtensionPointInImportedBuildfile" description="Bug 48804"> + <mkdir dir="${output}"/> + <echo file="${output}/master.xml"><![CDATA[ +<project default="bar"> + <extension-point name="foo"/> + <target name="bar" depends="foo"/> +</project>]]></echo> + <echo file="${output}/build.xml"><![CDATA[ +<project> + <import file="master.xml"/> + <target name="prepare" extensionOf="foo"> + <echo>in target prepare</echo> + </target> +</project>]]></echo> + <ant dir="${output}" target="bar"/> + <au:assertLogContains text="in target prepare"/> + </target> + + <target name="testExtensionPointInIncludedBuildfileWithNestedInclude"> + <mkdir dir="${output}"/> + <echo file="${output}/abstract-compile.xml"><![CDATA[ +<project name="abstract-compile"> + <extension-point name="compile"/> +</project>]]></echo> + <echo file="${output}/compile-java.xml"><![CDATA[ +<project name="compile-java"> + <include file="abstract-compile.xml" as="abstract-compile"/> + <target name="compile-java" extensionOf="abstract-compile.compile"> + <echo>in compile java</echo> + </target> +</project>]]></echo> + <echo file="${output}/build.xml"><![CDATA[ +<project name="master"> + <include file="compile-java.xml" as="compile"/> +</project>]]></echo> + <!-- here prefix should be concatened from each include first + "compile" then "abstract-compile"--> + <ant dir="${output}" target="compile.abstract-compile.compile"/> + <au:assertLogContains text="in compile java"/> + + </target> + + <target name="testExtensionPointInIncludedBuildfileWithNestedImport"> + <mkdir dir="${output}"/> + <echo file="${output}/abstract-compile.xml"><![CDATA[ +<project name="abstract-compile"> + <extension-point name="compile"/> +</project>]]></echo> + <echo file="${output}/compile-java.xml"><![CDATA[ +<project name="compile-java"> + <import file="abstract-compile.xml"/> + <target name="compile-java" extensionOf="compile"> + <echo>in compile java</echo> + </target> +</project>]]></echo> + <echo file="${output}/build.xml"><![CDATA[ +<project name="master"> + <include file="compile-java.xml" as="compile"/> +</project>]]></echo> + <!-- here the prefix should be "compile" as the import containing + the extension point is done inside an include using "compile" + as prefix --> + <ant dir="${output}" target="compile.compile"/> + <au:assertLogContains text="in compile java"/> + + </target> + + <target name="testExtensionPointInImportedBuildfileWithNestedImport"> + <mkdir dir="${output}"/> + <echo file="${output}/abstract-compile.xml"><![CDATA[ +<project name="abstract-compile"> + <extension-point name="compile"/> +</project>]]></echo> + <echo file="${output}/compile-java.xml"><![CDATA[ +<project name="compile-java"> + <import file="abstract-compile.xml"/> + <target name="compile-java" extensionOf="compile"> + <echo>in compile java</echo> + </target> +</project>]]></echo> + <echo file="${output}/build.xml"><![CDATA[ +<project name="master"> + <import file="compile-java.xml"/> +</project>]]></echo> + <!-- here extension point should not be prefixed at all --> + <ant dir="${output}" target="compile"/> + <au:assertLogContains text="in compile java"/> + + </target> + + + + <target name="testMissingExtensionPointCausesError"> + <mkdir dir="${output}"/> + <echo file="${output}/build.xml"><![CDATA[ +<project default="bar"> + <target name="bar" extensionOf="foo"/> +</project>]]></echo> + <au:expectfailure + expectedMessage="can't add target bar to extension-point foo because the extension-point is unknown"> + <ant dir="${output}" target="bar"/> + </au:expectfailure> + </target> + + <target name="testMissingExtensionPointCausesWarningWhenConfigured"> + <mkdir dir="${output}"/> + <echo file="${output}/build.xml"><![CDATA[ +<project default="bar"> + <target name="bar" extensionOf="foo" onMissingExtensionPoint="warn"/> +</project>]]></echo> + <ant dir="${output}" target="bar"/> + <au:assertLogContains level="warning" + text="can't add target bar to extension-point foo because the extension-point is unknown" /> + </target> + + <target name="testMissingExtensionPointIgnoredWhenConfigured"> + <mkdir dir="${output}"/> + <echo file="${output}/build.xml"><![CDATA[ +<project default="bar"> + <target name="bar" extensionOf="foo" onMissingExtensionPoint="ignore"/> +</project>]]></echo> + <ant dir="${output}" target="bar"/> + <au:assertLogDoesntContain level="warning" + text="can't add target bar to extension-point foo because the extension-point is unknown" /> + </target> + + <target name="testOnlyAllowsExtensionPointMissingAttributeWhenExtensionOfPresent"> + <mkdir dir="${output}"/> + <echo file="${output}/build.xml"><![CDATA[ +<project default="bar"> + <target name="bar" onMissingExtensionPoint="ignore"/> +</project>]]></echo> + <au:expectfailure + expectedMessage="onMissingExtensionPoint attribute cannot be specified unless extensionOf is specified"> + <ant dir="${output}" target="bar"/> + </au:expectfailure> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/extension/include-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/extension/include-test.xml new file mode 100644 index 00000000..4d3b6748 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/extension/include-test.xml @@ -0,0 +1,34 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../../antunit-base.xml" /> + + <!-- declare a target that depends on the extension point --> + <target name="compile" depends="all.compile" /> + + <!-- declare our extension point --> + <extension-point name="all.compile" /> + + <!-- import all our modules --> + <import file="module1.xml" as="module1" /> + + <target name="testImport" depends="compile"> + <au:assertLogContains text="In module1 compile. Yay!" /> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/extension/module1.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/extension/module1.xml new file mode 100644 index 00000000..3b6312f6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/extension/module1.xml @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="module1"> + + <!-- declare a target with the same name as one in the master --> + <target name="compile" extensionOf="all.compile"> + <echo message="In module1 compile. Yay!"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/location/location.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/location/location.xml new file mode 100644 index 00000000..091d6f33 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/location/location.xml @@ -0,0 +1,93 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="location-test" basedir="." default="all" + xmlns:au="antlib:org.apache.ant.antunit"> + + <property name="ant.build.dir" location="../../../../../build"/> + <property name="working.dir" + location="${ant.build.dir}/ant-unit/location-dir"/> + <property name="classes.dir" location="${working.dir}/classes"/> + + <target name="all"> + <au:antunit> + <fileset file="${ant.file}"/> + <au:plainlistener/> + </au:antunit> + </target> + + <target name="setUp"> + <mkdir dir="${classes.dir}"/> + <javac srcdir="src" destdir="${classes.dir}" debug="yes"/> + <taskdef name="echo-location" classname="task.EchoLocation" + classpath="${classes.dir}"/> + </target> + + <target name="define"> + <taskdef name="echoloc" + classname="task.EchoLocation"> + <classpath> + <pathelement location="${classes.dir}" /> + <pathelement path="${java.class.path}"/> + </classpath> + </taskdef> + </target> + + <target name="macrodef" depends="define"> + <macrodef name="echoloc2" backtrace="false"> + <sequential> + <echoloc/> + </sequential> + </macrodef> + </target> + + <target name="presetdef" depends="define"> + <presetdef name="echoloc3"> + <echoloc/> + </presetdef> + </target> + + <target name="tearDown"> + <delete dir="${working.dir}"/> + </target> + + <target name="test-plain-task"> + <echo id="echo">Hello</echo> + <au:assertLogContains text="Hello"/> + </target> + + <target name="test-standalone-type"> + <!-- TODO --> + </target> + + <target name="test-condition-task"> + <!-- TODO --> + </target> + + <target name="test-macrodef-wrapped-task" depends="macrodef"> + <echo id="echo3">Hello</echo> + <echoloc2/> + <au:assertLogContains text="Line: "/> + </target> + + <target name="test-presetdef-wrapped-task" depends="presetdef"> + <echo id="echo4">Hello</echo> + <echoloc3/> + <au:assertLogContains text="Line: "/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/location/src/task/EchoLocation.java b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/location/src/task/EchoLocation.java new file mode 100644 index 00000000..e306357d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/location/src/task/EchoLocation.java @@ -0,0 +1,26 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You 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 task; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; + +public class EchoLocation extends Task { + public void execute() { + log("Line: " + getLocation().getLineNumber(), Project.MSG_INFO); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/magic-names-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/magic-names-test.xml new file mode 100644 index 00000000..88d8b2ea --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/magic-names-test.xml @@ -0,0 +1,51 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" + name="magicnames-test" + default="default target"> + + <target name="default target"/> + + <target name="setUp" + description="only here to force a second target into testInvokedTargets' list"/> + + <target name="testProjectName"> + <au:assertPropertyEquals + name="ant.project.name" value="magicnames-test"/> + </target> + + <target name="testDefaultTarget"> + <au:assertPropertyEquals + name="ant.project.default-target" value="default target"/> + </target> + + <target name="testInvokedTargets"> + <au:assertPropertyEquals + name="ant.project.invoked-targets" value="setUp,testInvokedTargets"/> + </target> + + <target name="nested"> + <au:assertPropertyEquals + name="ant.project.invoked-targets" value="nested"/> + </target> + + <target name="testInvokedTargetsWithNestedAntcall"> + <antcall target="nested"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/nested-elements-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/nested-elements-test.xml new file mode 100644 index 00000000..e031c41b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/nested-elements-test.xml @@ -0,0 +1,125 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml"/> + + <target name="testConditionBaseAndTaskContainer"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/ConditionRun.java"> +import org.apache.tools.ant.*; +import org.apache.tools.ant.taskdefs.condition.*; +import java.util.*; + +public class ConditionRun extends ConditionBase implements TaskContainer { + private List tasks = new ArrayList(); + + public void addTask(Task task) { + tasks.add(task); + } + + public void execute() { + for (Iterator iter = tasks.iterator(); iter.hasNext(); ) { + Task t = (Task) iter.next(); + t.perform(); + } + } +} + </echo> + <javac destdir="${output}" + srcdir="${input}"/> + <taskdef name="conditionrun" classpath="${output}" + classname="ConditionRun"/> + <conditionrun> + <echo>Hello</echo> + </conditionrun> + <au:assertLogContains text="Hello"/> + </target> + + <target name="testDynamicElementAndTaskContainer"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/Dynamic.java"> +import org.apache.tools.ant.*; +import java.util.*; + +public class Dynamic implements TaskContainer, DynamicElement { + private List tasks = new ArrayList(); + + public void addTask(Task task) { + tasks.add(task); + } + + public void execute() { + for (Iterator iter = tasks.iterator(); iter.hasNext(); ) { + Task t = (Task) iter.next(); + t.perform(); + } + } + public Object createDynamicElement(String name) { + return null; + } +} + </echo> + <javac destdir="${output}" + srcdir="${input}"/> + <taskdef name="dyn" classpath="${output}" + classname="Dynamic"/> + <dyn> + <echo>Hello</echo> + </dyn> + <au:assertLogContains text="Hello"/> + </target> + + <target name="testDynamicElementNSAndTaskContainer"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/Dynamic.java"> +import org.apache.tools.ant.*; +import java.util.*; + +public class Dynamic implements TaskContainer, DynamicElementNS { + private List tasks = new ArrayList(); + + public void addTask(Task task) { + tasks.add(task); + } + + public void execute() { + for (Iterator iter = tasks.iterator(); iter.hasNext(); ) { + Task t = (Task) iter.next(); + t.perform(); + } + } + public Object createDynamicElement(String uri, String localName, + String qName) { + return null; + } +} + </echo> + <javac destdir="${output}" + srcdir="${input}"/> + <taskdef name="dyn" classpath="${output}" + classname="Dynamic"/> + <dyn> + <echo>Hello</echo> + </dyn> + <au:assertLogContains text="Hello"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/nested-text-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/nested-text-test.xml new file mode 100644 index 00000000..05fb4c85 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/nested-text-test.xml @@ -0,0 +1,42 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml"/> + + <target name="testAcceptNested"> + <echo>foo</echo> + </target> + + <target name="testRejectNested"> + <typedef name="object" classname="java.lang.Object" /> + <au:expectfailure expectedMessage="The <object> type doesn't support nested text data ("foo")."> + <object>foo</object> + </au:expectfailure> + </target> + + <!-- https://issues.apache.org/bugzilla/show_bug.cgi?id=46285 --> + <target name="testNumericEntities"> + <echo encoding="UTF-8" file="${output}/abc.txt">ä©</echo> + <loadresource property="foo" encoding="UTF-8"> + <file file="${output}/abc.txt"/> + </loadresource> + <au:assertPropertyEquals name="foo" value="ä©"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers-test.xml new file mode 100644 index 00000000..9e9000dd --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers-test.xml @@ -0,0 +1,86 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml"/> + + <property name="projecthelperin" location="${input}"/> + <property name="projecthelperout" location="${output}"/> + + <target name="compileHelpers"> + <mkdir dir="${projecthelperin}/org/apache/tools/ant"/> + <mkdir dir="${projecthelperout}/org/apache/tools/ant"/> + + <echo file="${projecthelperin}/org/apache/tools/ant/ReferencerProjectHelper.java"> +<!-- helper that just delegate the parsing to the xml build with the proper name --> +<![CDATA[ + package org.apache.tools.ant; + + import org.apache.tools.ant.helper.ProjectHelper2; + import org.apache.tools.ant.types.Resource; + import org.apache.tools.ant.types.resources.FileResource; + + public class ReferencerProjectHelper extends ProjectHelper2 { + + public boolean canParseBuildFile(Resource buildFile) { + return buildFile instanceof FileResource && buildFile.getName().endsWith(".xmlref"); + } + + public String getDefaultBuildFile() { + return "build.xmlref"; + } + + public boolean canParseAntlibDescriptor(Resource resource) { + return resource instanceof FileResource && resource.getName().endsWith(".xmlref"); + } + + public void parse(Project project, Object source, RootHandler handler) + throws BuildException { + FileResource file = (FileResource) source; + String name = file.getName(); + Resource actual = new FileResource(file.getFile().getParentFile(), name.substring(0, name.length() - 3)); + // switch to the parsing of the xml build file + super.parse(project, actual, handler); + } + } +]]></echo> + <javac srcdir="${projecthelperin}" destdir="${projecthelperout}"/> + </target> + + <target name="defineHelpers" depends="compileHelpers"> + <typedef name="referencerhelper" classname="org.apache.tools.ant.ReferencerProjectHelper"> + <classpath location="${projecthelperout}"/> + </typedef> + <projecthelper> + <referencerhelper/> + </projecthelper> + </target> + + <target name="testCrossTargets" depends="defineHelpers"> + <ant antfile="projecthelpers/build-cross-targets.xml" /> + </target> + + <target name="testManyImport" depends="defineHelpers"> + <ant antfile="projecthelpers/build-many-import.xml" /> + </target> + + <target name="testCrossExtension" depends="defineHelpers"> + <ant antfile="projecthelpers/build-cross-extension.xml" /> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-extension-ref.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-extension-ref.xml new file mode 100644 index 00000000..67837a04 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-extension-ref.xml @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project> + <extension-point name="extension-ref" /> + <target name="setbar" extensionOf="extension"> + <property name="bar" value="hello" /> + </target> + <target name="setfoo" depends="init,extension-ref"> + <property name="foo" value="hello" /> + </target> +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-extension-ref.xmlref b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-extension-ref.xmlref new file mode 100644 index 00000000..f81d3dbd --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-extension-ref.xmlref @@ -0,0 +1,14 @@ + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-extension.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-extension.xml new file mode 100644 index 00000000..f8f1220b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-extension.xml @@ -0,0 +1,36 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="end" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="build-cross-extension-ref.xmlref" /> + <target name="init"> + <property name="start" value="true" /> + </target> + + <target name="setprop" extensionOf="extension-ref"> + <property name="prop" value="ok" /> + </target> + + <extension-point name="extension" /> + + <target name="end" depends="setfoo,extension"> + <au:assertPropertyEquals name="start" value="true" /> + <au:assertPropertyEquals name="foo" value="hello" /> + <au:assertPropertyEquals name="bar" value="hello" /> + <au:assertPropertyEquals name="prop" value="ok" /> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-targets-ref.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-targets-ref.xml new file mode 100644 index 00000000..c16d989d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-targets-ref.xml @@ -0,0 +1,22 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project> + <target name="setfoo" depends="init"> + <property name="foo" value="hello" /> + </target> +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-targets-ref.xmlref b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-targets-ref.xmlref new file mode 100644 index 00000000..f81d3dbd --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-targets-ref.xmlref @@ -0,0 +1,14 @@ + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-targets.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-targets.xml new file mode 100644 index 00000000..c4c7ca76 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-cross-targets.xml @@ -0,0 +1,27 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="end" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="build-cross-targets-ref.xmlref" /> + <target name="init"> + <property name="start" value="true" /> + </target> + <target name="end" depends="setfoo"> + <au:assertPropertyEquals name="start" value="true" /> + <au:assertPropertyEquals name="foo" value="hello" /> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import-common.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import-common.xml new file mode 100644 index 00000000..243de8cc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import-common.xml @@ -0,0 +1,23 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project> + <!-- build file imported by every other build --> + <target name="common" depends="init"> + <property name="common" value="ok" /> + </target> +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import-commonref.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import-commonref.xml new file mode 100644 index 00000000..38b50ada --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import-commonref.xml @@ -0,0 +1,23 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project> + <!-- build file imported by bot referenced build --> + <target name="commonref" depends="init"> + <property name="commonref" value="ok" /> + </target> +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import-ref.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import-ref.xml new file mode 100644 index 00000000..c9c02fe8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import-ref.xml @@ -0,0 +1,24 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project> + <import file="build-many-import-common.xml" /> + <import file="build-many-import-commonref.xml" /> + <target name="setfoo" depends="init"> + <property name="foo" value="hello" /> + </target> +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import-ref.xmlref b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import-ref.xmlref new file mode 100644 index 00000000..f81d3dbd --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import-ref.xmlref @@ -0,0 +1,14 @@ + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import.xml new file mode 100644 index 00000000..792fb56e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import.xml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="end" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="build-many-import-ref.xmlref" /> + <import file="build-many-import2-ref.xmlref" /> + <import file="build-many-import-common.xml" /> + <target name="init"> + <property name="start" value="true" /> + </target> + <target name="end" depends="setfoo,setbar,common,commonref"> + <au:assertPropertyEquals name="start" value="true" /> + <au:assertPropertyEquals name="foo" value="hello" /> + <au:assertPropertyEquals name="bar" value="hello" /> + <au:assertPropertyEquals name="common" value="ok" /> + <au:assertPropertyEquals name="commonref" value="ok" /> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import2-ref.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import2-ref.xml new file mode 100644 index 00000000..d32cf17a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import2-ref.xml @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project> + <import file="build-many-import-ref.xmlref" /> + <import file="build-many-import-common.xml" /> + <import file="build-many-import-commonref.xml" /> + <target name="setbar" depends="init,common"> + <property name="bar" value="hello" /> + </target> +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import2-ref.xmlref b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import2-ref.xmlref new file mode 100644 index 00000000..f81d3dbd --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/projecthelpers/build-many-import2-ref.xmlref @@ -0,0 +1,14 @@ + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/ref-propertyhelper-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/ref-propertyhelper-test.xml new file mode 100644 index 00000000..b3bc39ce --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/ref-propertyhelper-test.xml @@ -0,0 +1,104 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + <import file="../antunit-base.xml"/> + + <path id="foo" location="x.y"/> + + <target name="testToString"> + <echo message="${toString:foo}"/> + <au:assertLogContains + text="antunit${file.separator}core${file.separator}x.y"/> + </target> + + <target name="testImplicitToString"> + <echo message="${ant.refid:foo}"/> + <au:assertLogContains + text="antunit${file.separator}core${file.separator}x.y"/> + </target> + + <target name="testPathObject"> + <mkdir dir="${input}/org/example"/> + <mkdir dir="${output}"/> + <echo file="${input}/org/example/Task.java"><![CDATA[ +package org.example; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Path; + +public class Task { + private Project project; + public void setProject(Project p) { + project = p; + } + private boolean set = false; + public void setPath(Path p) { + if (p != (Path) project.getReference("foo")) { + throw new BuildException("this is not my path"); + } + set = true; + } + public void execute() { + if (!set) { + throw new BuildException("expected my path attribute to be set"); + } + } +} +]]></echo> + <javac srcdir="${input}" destdir="${output}"/> + <taskdef name="x" classname="org.example.Task" + classpath="${output}"/> + <x path="${ant.refid:foo}"/> + </target> + + <target name="testManualExample"> + <mkdir dir="${input}/org/example"/> + <mkdir dir="${output}"/> + <echo file="${input}/org/example/Task.java"><![CDATA[ +package org.example; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Resource; +import org.apache.tools.ant.types.resources.URLResource; + +public class Task { + private Resource r; + private boolean set = false; + public void setAttr(Resource r) { + this.r = r; + } + public void execute() { + if (r instanceof URLResource) { + System.out.println("URL is: " + ((URLResource) r).getURL()); + } else { + throw new BuildException("Expected an URLResource but got: " + + (r != null ? r.getClass().getName() + : "nothing")); + } + } +} +]]></echo> + <javac srcdir="${input}" destdir="${output}"/> + <taskdef name="x" classname="org.example.Task" + classpath="${output}"/> + <url url="http://ant.apache.org/" id="anturl"/> + <x attr="${ant.refid:anturl}"/> + <au:assertLogContains text="URL is: http://ant.apache.org/"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/ref-psyntax-hint-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/ref-psyntax-hint-test.xml new file mode 100644 index 00000000..de324113 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/ref-psyntax-hint-test.xml @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + <import file="../antunit-base.xml"/> + + <target name="testIt"> + <au:expectfailure> + <pathconvert refid="${foo}" /> + </au:expectfailure> + <au:assertLogContains level="warning" + text="Unresolvable reference $${foo} might be a misuse of property expansion syntax." /> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/target-test-helper.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/target-test-helper.xml new file mode 100644 index 00000000..6ca2452f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/target-test-helper.xml @@ -0,0 +1,57 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project> + + <target name="if-true" if="${ant.refid:true}"> + <echo>if-true called</echo> + </target> + + <target name="unless-true" unless="${ant.refid:true}"> + <echo>unless-true called</echo> + </target> + + <target name="if-false" if="${ant.refid:false}"> + <echo>if-false called</echo> + </target> + + <target name="unless-false" unless="${ant.refid:false}"> + <echo>unless-false called</echo> + </target> + + <target name="if-string-true" if="${true}"> + <echo>if-string-true called</echo> + </target> + + <target name="unless-string-true" unless="${true}"> + <echo>unless-string-true called</echo> + </target> + + <target name="if-string-false" if="${false}"> + <echo>if-string-false called</echo> + </target> + + <target name="unless-string-false" unless="${false}"> + <echo>unless-string-false called</echo> + </target> + + <target name="all" + depends="if-true,unless-true,if-false,unless-false, + if-string-true,unless-string-true, + if-string-false,unless-string-false"/> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/target-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/target-test.xml new file mode 100644 index 00000000..3e656be7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/target-test.xml @@ -0,0 +1,82 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml"/> + + <target name="setUp"> + <mkdir dir="${input}/org/example"/> + <mkdir dir="${output}"/> + <echo file="${input}/org/example/CreateBoolean.java"><![CDATA[ +package org.example; + +import org.apache.tools.ant.ProjectComponent; + +public class CreateBoolean extends ProjectComponent { + public void execute() { + getProject().addReference("true", Boolean.TRUE); + getProject().addReference("false", Boolean.FALSE); + } +}]]></echo> + <javac srcdir="${input}" destdir="${output}"/> + <taskdef name="cb" classname="org.example.CreateBoolean" + classpath="${output}"/> + <cb/> + </target> + + <target name="testReferencesNotSet" depends="setUp"> + <ant antfile="target-test-helper.xml" target="all" + inheritrefs="false"/> + <au:assertLogContains text="unless-true called"/> + <au:assertLogContains text="unless-false called"/> + <au:assertLogDoesntContain text="if-true called"/> + <au:assertLogDoesntContain text="if-false called"/> + <au:assertLogContains text="unless-string-true called"/> + <au:assertLogContains text="unless-string-false called"/> + <au:assertLogDoesntContain text="if-string-true called"/> + <au:assertLogDoesntContain text="if-string-false called"/> + </target> + + <target name="testReferencesSet" depends="setUp"> + <ant antfile="target-test-helper.xml" target="all" + inheritrefs="true"/> + <au:assertLogDoesntContain text="unless-true called"/> + <au:assertLogContains text="unless-false called"/> + <au:assertLogContains text="if-true called"/> + <au:assertLogDoesntContain text="if-false called"/> + <au:assertLogContains text="unless-string-true called"/> + <au:assertLogContains text="unless-string-false called"/> + <au:assertLogDoesntContain text="if-string-true called"/> + <au:assertLogDoesntContain text="if-string-false called"/> + </target> + + <target name="testProperttiesSet"> + <ant antfile="target-test-helper.xml" target="all"> + <property name="true" value="true"/> + <property name="false" value="false"/> + </ant> + <au:assertLogDoesntContain text="unless-string-true called"/> + <au:assertLogContains text="unless-string-false called"/> + <au:assertLogContains text="if-string-true called"/> + <au:assertLogDoesntContain text="if-string-false called"/> + <au:assertLogContains text="unless-true called"/> + <au:assertLogContains text="unless-false called"/> + <au:assertLogDoesntContain text="if-true called"/> + <au:assertLogDoesntContain text="if-false called"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/uuencode/src/task/BaseTask.java b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/uuencode/src/task/BaseTask.java new file mode 100644 index 00000000..22fb70e3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/uuencode/src/task/BaseTask.java @@ -0,0 +1,78 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 task; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.util.FileUtils; +import java.io.File; +import java.io.BufferedInputStream; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * Base class for the uuencode/decode test tasks. + */ +abstract public class BaseTask extends Task { + private final static FileUtils FILE_UTILS = FileUtils.getFileUtils(); + private File inFile; + private File outFile; + + public void setInFile(File inFile) { + this.inFile = inFile; + } + protected File getInFile() { + return inFile; + } + public void setOutFile(File outFile) { + this.outFile = outFile; + } + protected File getOutFile() { + return outFile; + } + public void execute() { + assertAttribute(inFile, "inFile"); + assertAttribute(outFile, "outFile"); + InputStream inputStream = null; + OutputStream outputStream = null; + try { + inputStream = new BufferedInputStream( + new FileInputStream(getInFile())); + outputStream = new FileOutputStream(getOutFile()); + doit(inputStream, outputStream); + } catch (Exception ex) { + throw new BuildException(ex); + } finally { + FILE_UTILS.close(inputStream); + FILE_UTILS.close(outputStream); + } + } + + abstract protected void doit( + InputStream is, OutputStream os) throws Exception; + + private void assertAttribute(File file, String attributeName) { + if (file == null) { + throw new BuildException("Required attribute " + attributeName + + " not set"); + } + } +} + + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/uuencode/src/task/UUDecodeTask.java b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/uuencode/src/task/UUDecodeTask.java new file mode 100644 index 00000000..8423f8ce --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/uuencode/src/task/UUDecodeTask.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 task; +import java.io.InputStream; +import java.io.OutputStream; +import sun.misc.UUDecoder; + +/** + * Decodes a uuencoded file using sun.misc.UUDecoder. + */ +public class UUDecodeTask extends BaseTask { + protected void doit(InputStream is, OutputStream os) throws Exception { + new UUDecoder().decodeBuffer(is, os); + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/uuencode/src/task/UUEncodeTask.java b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/uuencode/src/task/UUEncodeTask.java new file mode 100644 index 00000000..2b878f8c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/uuencode/src/task/UUEncodeTask.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 task; +import org.apache.tools.ant.util.UUEncoder; +import java.io.InputStream; +import java.io.OutputStream; + +/** + * UUEncodes a file using org.apache.tools.ant.util.UUEncoder. + */ +public class UUEncodeTask extends BaseTask { + protected void doit(InputStream is, OutputStream os) throws Exception { + new UUEncoder(getInFile().getName()).encode(is, os); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/uuencode/uuencode-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/uuencode/uuencode-test.xml new file mode 100644 index 00000000..2d68ab0b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/core/uuencode/uuencode-test.xml @@ -0,0 +1,45 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../antunit-base.xml"/> + + <target name="setUp"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <available property="sun.uudecode.avail" classname="sun.misc.UUDecoder"/> + </target> + + <target name="define" if="sun.uudecode.avail"> + <javac srcdir="src" destdir="${output}" debug="yes"/> + <taskdef name="uuencode" classname="task.UUEncodeTask" + classpath="${output}"/> + <taskdef name="uudecode" classname="task.UUDecodeTask" + classpath="${output}"/> + </target> + + <target name="test-simple" depends="define" if="sun.uudecode.avail"> + <uuencode infile="${ant.file}" + outfile="${input}/uuencoded"/> + <uudecode infile="${input}/uuencoded" + outfile="${input}/decoded"/> + <au:assertTrue> + <filesmatch file1="${ant.file}" file2="${input}/decoded"/> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expandproperties-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expandproperties-test.xml new file mode 100644 index 00000000..5dff8320 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expandproperties-test.xml @@ -0,0 +1,92 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. + --> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <property name="foo" value="FOO" /> + <property name="bar" value="BAR" /> + <property name="baz" value="BAZ" /> + + <target name="testClassic"> + <au:assertTrue> + <resourcesmatch> + <string value="FOO BAR BAZ" /> + <concat> + <string value="$${foo} $${bar} $${baz}" /> + <filterchain> + <expandproperties /> + </filterchain> + </concat> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testSubset"> + <au:assertTrue> + <resourcesmatch> + <string value="FOO $${bar} BAZ" /> + <concat> + <string value="$${foo} $${bar} $${baz}" /> + <filterchain> + <expandproperties> + <propertyset> + <propertyref name="foo" /> + <propertyref name="baz" /> + </propertyset> + </expandproperties> + </filterchain> + </concat> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testMappedPropertySet"> + <au:assertTrue> + <resourcesmatch> + <string value="FOO BAR BAZ" /> + <concat> + <string value="$${food} $${bard} $${bazd}" /> + <filterchain> + <expandproperties> + <propertyset> + <propertyref builtin="all" /> + <globmapper from="*" to="*d" /> + </propertyset> + </expandproperties> + </filterchain> + </concat> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testEmptyResource" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=53626"> + <au:assertTrue> + <resourcesmatch> + <string value="" /> + <concat> + <string value="" /> + <filterchain> + <expandproperties /> + </filterchain> + </concat> + </resourcesmatch> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/sort.sortComparator.test b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/sort.sortComparator.test new file mode 100644 index 00000000..a93e4f48 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/sort.sortComparator.test @@ -0,0 +1,10 @@ +Line 2 +Line 4 +Line 6 +Line 8 +Line 10 +Line 1 +Line 3 +Line 5 +Line 7 +Line 9 diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/sort.sortDefault.test b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/sort.sortDefault.test new file mode 100644 index 00000000..43d44e57 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/sort.sortDefault.test @@ -0,0 +1,10 @@ +Line 1 +Line 2 +Line 3 +Line 4 +Line 5 +Line 6 +Line 7 +Line 8 +Line 9 +Line 10 diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/sort.sortReverse.test b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/sort.sortReverse.test new file mode 100644 index 00000000..a847cc10 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/sort.sortReverse.test @@ -0,0 +1,10 @@ +Line 10 +Line 9 +Line 8 +Line 7 +Line 6 +Line 5 +Line 4 +Line 3 +Line 2 +Line 1 diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/sortuniq.txt b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/sortuniq.txt new file mode 100644 index 00000000..7dc51acc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/sortuniq.txt @@ -0,0 +1,4 @@ +A +AA +B +C diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/uniq.txt b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/uniq.txt new file mode 100644 index 00000000..e9d0f3db --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/uniq.txt @@ -0,0 +1,5 @@ +A +AA +B +C +B diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/unique-columns.txt b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/unique-columns.txt new file mode 100644 index 00000000..81f684e7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/expected/unique-columns.txt @@ -0,0 +1 @@ +A B C B diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/input/sort.sortDefault.test b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/input/sort.sortDefault.test new file mode 100644 index 00000000..05661185 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/input/sort.sortDefault.test @@ -0,0 +1,10 @@ +Line 10 +Line 1 +Line 9 +Line 6 +Line 3 +Line 2 +Line 4 +Line 5 +Line 7 +Line 8 diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/input/uniq.txt b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/input/uniq.txt new file mode 100644 index 00000000..9baebe55 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/input/uniq.txt @@ -0,0 +1,6 @@ +A +AA +AA +B +C +B diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/input/unique-columns.txt b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/input/unique-columns.txt new file mode 100644 index 00000000..ef797259 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/input/unique-columns.txt @@ -0,0 +1 @@ +A A B C B diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/replacetokens-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/replacetokens-test.xml new file mode 100644 index 00000000..c1f98ab6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/replacetokens-test.xml @@ -0,0 +1,68 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <import file="../propertyhelpers.xml" as="ph"/> + + <target name="tearDown" depends="antunit-base.tearDown"> + <delete dir="foo"/> + </target> + + <target name="setUp"> + <mkdir dir="${input}"/> + <echo file="${input}/text.txt"><![CDATA[ +Hello, @world@! +]]></echo> + </target> + + <target name="testPropertiesResource" depends="setUp,ph.defineHelpers"> + <mkdir dir="${output}"/> + <mkdir dir="foo"/> + <echo file="foo/foo.properties"><![CDATA[ +world=Ant +]]></echo> + <copy todir="${output}"> + <fileset dir="${input}"/> + <filterchain> + <replacetokens propertiesResource="${java:foo!foo.properties}"/> + </filterchain> + </copy> + <au:assertResourceContains + resource="${output}/text.txt" value="Hello, Ant!"/> + </target> + + <target name="testFileEndsWithToken" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47306" + depends="setUp"> + <mkdir dir="${output}"/> + <echo file="${input}/test47306.txt">Hello@</echo> + <copy todir="${output}"> + <fileset dir="${input}"/> + <filterchain> + <replacetokens> + <token key="foo" value="bar"/> + </replacetokens> + </filterchain> + </copy> + <au:assertFilesMatch + expected="${input}/test47306.txt" + actual="${output}/test47306.txt"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/sort-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/sort-test.xml new file mode 100644 index 00000000..8c2a88b5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/sort-test.xml @@ -0,0 +1,126 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. + --> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${output}"/> + </target> + + <target name="testSortFilterNoArgs" depends="setUp"> + <copy file="input/sort.sortDefault.test" + tofile="${output}/sort.sortDefault.test"> + <filterchain> + <sortfilter/> + </filterchain> + </copy> + <au:assertFilesMatch + expected="expected/sort.sortDefault.test" + actual="${output}/sort.sortDefault.test"/> + </target> + + <target name="testSortFilterNoArgsLong" depends="setUp"> + <copy file="input/sort.sortDefault.test" + tofile="${output}/sort.sortDefault.test"> + <filterchain> + <filterreader classname="org.apache.tools.ant.filters.SortFilter"/> + </filterchain> + </copy> + <au:assertFilesMatch + expected="expected/sort.sortDefault.test" + actual="${output}/sort.sortDefault.test"/> + </target> + + <target name="testSortFilterReverse" depends="setUp"> + <copy file="input/sort.sortDefault.test" + tofile="${output}/sort.sortReverse.test"> + <filterchain> + <sortfilter reverse="true"/> + </filterchain> + </copy> + <au:assertFilesMatch + expected="expected/sort.sortReverse.test" + actual="${output}/sort.sortReverse.test"/> + </target> + + <target name="testSortFilterReverseLong" depends="setUp"> + <copy file="input/sort.sortDefault.test" + tofile="${output}/sort.sortReverse.test"> + <filterchain> + <filterreader classname="org.apache.tools.ant.filters.SortFilter"> + <param name="reverse" value="true"/> + </filterreader> + </filterchain> + </copy> + <au:assertFilesMatch + expected="expected/sort.sortReverse.test" + actual="${output}/sort.sortReverse.test"/> + </target> + + <target name="-setUpEvenFirst" depends="setUp"> + <mkdir dir="${input}/src/org/apache/tools/ant/filters"/> + <echo file="${input}/src/org/apache/tools/ant/filters/EvenFirstCmp.java"><![CDATA[ +package org.apache.tools.ant.filters; + +import java.util.Comparator; + +public final class EvenFirstCmp implements Comparator { + + public int compare(Object o1, Object o2) { + String s1 = ((String) o1).substring(5).trim(); + String s2 = ((String) o2).substring(5).trim(); + int n1 = Integer.parseInt(s1); + int n2 = Integer.parseInt(s2); + if (n1 % 2 == 0) { + if (n2 % 2 == 0) { + return n1 - n2; + } else { + return -1; + } + } else { + if (n2 % 2 == 0) { + return 1; + } else { + return n1 - n2; + } + } + } +} +]]></echo> + <mkdir dir="${input}/build"/> + <javac srcdir="${input}/src" destdir="${input}/build"/> + <typedef classname="org.apache.tools.ant.filters.EvenFirstCmp" + name="evenfirst"> + <classpath location="${input}/build"/> + </typedef> + </target> + + <target name="testSortFilterComparator" depends="-setUpEvenFirst"> + <copy file="input/sort.sortDefault.test" + tofile="${output}/sort.sortComparator.test"> + <filterchain> + <sortfilter> + <evenfirst/> + </sortfilter> + </filterchain> + </copy> + <au:assertFilesMatch + expected="expected/sort.sortComparator.test" + actual="${output}/sort.sortComparator.test"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/striplinecomments-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/striplinecomments-test.xml new file mode 100644 index 00000000..2af0f013 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/striplinecomments-test.xml @@ -0,0 +1,85 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <property name="br" value="${line.separator}" /> + + <string id="input">foo +#pound +bar +//java sl +baz +REMark +</string> + + <macrodef name="test"> + <attribute name="lines" /> + <element name="comments" implicit="true" /> + <sequential> + <au:assertTrue> + <resourcecount count="@{lines}"> + <tokens> + <concat> + <resource refid="input" /> + <filterchain> + <striplinecomments> + <comments /> + </striplinecomments> + <ignoreblank /> + </filterchain> + </concat> + </tokens> + </resourcecount> + </au:assertTrue> + </sequential> + </macrodef> + + <target name="testBasic"> + <test lines="5"> + <comment value="#" /> + </test> + </target> + + <target name="testMultiple"> + <test lines="3"> + <comment value="#" /> + <comment value="//" /> + <comment value="REM" /> + </test> + </target> + + <target name="testNestedText"> + <test lines="3"> + <comment>#</comment> + <comment>//</comment> + <comment>REM</comment> + </test> + </target> + + <target name="testExclusivity"> + <au:expectfailure> + <filterchain> + <striplinecomments> + <comment value="#">#"</comment> + </striplinecomments> + </filterchain> + </au:expectfailure> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/suffix-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/suffix-test.xml new file mode 100644 index 00000000..a0a9403c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/suffix-test.xml @@ -0,0 +1,42 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. + --> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + </target> + + <target name="testSimple"> + <echo file="${input}/a.txt">a +b +c</echo> + <echo file="${input}/b.txt">aFoo +bFoo +cFoo</echo> + <copy todir="${output}"> + <fileset dir="${input}"/> + <filterchain> + <suffixlines suffix="Foo"/> + </filterchain> + </copy> + <au:assertFilesMatch expected="${input}/b.txt" + actual="${output}/a.txt"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/uniq-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/uniq-test.xml new file mode 100644 index 00000000..832ec944 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/filters/uniq-test.xml @@ -0,0 +1,81 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. + --> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${output}"/> + </target> + + <target name="testUniqFilter" depends="setUp"> + <copy file="input/uniq.txt" + tofile="${output}/uniq.txt"> + <filterchain> + <uniqfilter/> + </filterchain> + </copy> + <au:assertFilesMatch + expected="expected/uniq.txt" + actual="${output}/uniq.txt"/> + </target> + + <target name="testUniqTokenFilter" depends="setUp"> + <copy file="input/uniq.txt" + tofile="${output}/uniq.txt"> + <filterchain> + <tokenfilter> + <uniqfilter/> + </tokenfilter> + </filterchain> + </copy> + <au:assertFilesMatch + expected="expected/uniq.txt" + actual="${output}/uniq.txt"/> + </target> + + <target name="testSortUniq" depends="setUp"> + <copy file="input/uniq.txt" + tofile="${output}/uniq.txt"> + <filterchain> + <sortfilter/> + <tokenfilter> + <uniqfilter/> + </tokenfilter> + </filterchain> + </copy> + <au:assertFilesMatch + expected="expected/sortuniq.txt" + actual="${output}/uniq.txt"/> + </target> + + <target name="testUniqueColumns" depends="setUp"> + <copy file="input/unique-columns.txt" + tofile="${output}/unique-columns.txt"> + <filterchain> + <tokenfilter> + <stringtokenizer/> + <uniqfilter/> + </tokenfilter> + </filterchain> + </copy> + <au:assertFilesMatch + expected="expected/unique-columns.txt" + actual="${output}/unique-columns.txt"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/junit-frames.xsl b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/junit-frames.xsl new file mode 100644 index 00000000..9fab2854 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/junit-frames.xsl @@ -0,0 +1,889 @@ +<?xml version="1.0"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" + xmlns:lxslt="http://xml.apache.org/xslt" + xmlns:redirect="http://xml.apache.org/xalan/redirect" + xmlns:stringutils="xalan://org.apache.tools.ant.util.StringUtils" + extension-element-prefixes="redirect"> +<xsl:output method="html" indent="yes" encoding="US-ASCII"/> +<xsl:decimal-format decimal-separator="." grouping-separator=","/> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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. +--> + +<!-- + + Sample stylesheet to be used with Ant JUnitReport output. + + It creates a set of HTML files a la javadoc where you can browse easily + through all directories and projects. + +--> +<xsl:param name="output.dir" select="'.'"/> + + +<xsl:template match="testsuites"> + <!-- create the index.html --> + <redirect:write file="{$output.dir}/index.html"> + <xsl:call-template name="index.html"/> + </redirect:write> + + <!-- create the stylesheet.css --> + <redirect:write file="{$output.dir}/stylesheet.css"> + <xsl:call-template name="stylesheet.css"/> + </redirect:write> + + <!-- create the overview-directories.html at the root --> + <redirect:write file="{$output.dir}/overview-summary.html"> + <xsl:apply-templates select="." mode="overview.directories"/> + </redirect:write> + + <!-- create the all-directories.html at the root --> + <redirect:write file="{$output.dir}/overview-frame.html"> + <xsl:apply-templates select="." mode="all.directories"/> + </redirect:write> + + <!-- create the all-projects.html at the root --> + <redirect:write file="{$output.dir}/allprojects-frame.html"> + <xsl:apply-templates select="." mode="all.projects"/> + </redirect:write> + + <!-- create the all-tests.html at the root --> + <redirect:write file="{$output.dir}/all-tests.html"> + <xsl:apply-templates select="." mode="all.tests"/> + </redirect:write> + + <!-- create the alltests-fails.html at the root --> + <redirect:write file="{$output.dir}/alltests-fails.html"> + <xsl:apply-templates select="." mode="all.tests"> + <xsl:with-param name="type" select="'fails'"/> + </xsl:apply-templates> + </redirect:write> + + <!-- create the alltests-errors.html at the root --> + <redirect:write file="{$output.dir}/alltests-errors.html"> + <xsl:apply-templates select="." mode="all.tests"> + <xsl:with-param name="type" select="'errors'"/> + </xsl:apply-templates> + </redirect:write> + + <!-- process all directories --> + <xsl:for-each select="./testsuite[not(./@package = preceding-sibling::testsuite/@package)]"> + <xsl:call-template name="directory"> + <xsl:with-param name="name" select="@package"/> + </xsl:call-template> + </xsl:for-each> +</xsl:template> + + +<xsl:template name="directory"> + <xsl:param name="name"/> + <xsl:variable name="directory.dir"> + <xsl:if test="not($name = '')"><xsl:value-of select="translate($name,'.','/')"/></xsl:if> + <xsl:if test="$name = ''">.</xsl:if> + </xsl:variable> + <!--Processing directory <xsl:value-of select="@name"/> in <xsl:value-of select="$output.dir"/> --> + <!-- create a projects-list.html in the directory directory --> + <redirect:write file="{$output.dir}/{$directory.dir}/directory-frame.html"> + <xsl:call-template name="projects.list"> + <xsl:with-param name="name" select="$name"/> + </xsl:call-template> + </redirect:write> + + <!-- create a directory-summary.html in the directory directory --> + <redirect:write file="{$output.dir}/{$directory.dir}/directory-summary.html"> + <xsl:call-template name="directory.summary"> + <xsl:with-param name="name" select="$name"/> + </xsl:call-template> + </redirect:write> + + <!-- for each project, creates a @name.html --> + <!-- @bug there will be a problem with inner projects having the same name, it will be overwritten --> + <xsl:for-each select="/testsuites/testsuite[@package = $name]"> + <redirect:write file="{$output.dir}/{$directory.dir}/{@id}_{@name}.html"> + <xsl:apply-templates select="." mode="project.details"/> + </redirect:write> + <xsl:if test="string-length(./system-out)!=0"> + <redirect:write file="{$output.dir}/{$directory.dir}/{@id}_{@name}-out.txt"> + <xsl:value-of disable-output-escaping="yes" select="./system-out"/> + </redirect:write> + </xsl:if> + <xsl:if test="string-length(./system-err)!=0"> + <redirect:write file="{$output.dir}/{$directory.dir}/{@id}_{@name}-err.txt"> + <xsl:value-of disable-output-escaping="yes" select="./system-err"/> + </redirect:write> + </xsl:if> + <xsl:if test="failures/text() != 0"> + <redirect:write file="{$output.dir}/{$directory.dir}/{@id}_{@name}-fails.html"> + <xsl:apply-templates select="." mode="project.details"> + <xsl:with-param name="type" select="'fails'"/> + </xsl:apply-templates> + </redirect:write> + </xsl:if> + <xsl:if test="errors/text() != 0"> + <redirect:write file="{$output.dir}/{$directory.dir}/{@id}_{@name}-errors.html"> + <xsl:apply-templates select="." mode="project.details"> + <xsl:with-param name="type" select="'errors'"/> + </xsl:apply-templates> + </redirect:write> + </xsl:if> + </xsl:for-each> +</xsl:template> + +<xsl:template name="index.html"> +<html> + <head> + <title>AntUnit Test Results.</title> + </head> + <frameset cols="20%,80%"> + <frameset rows="30%,70%"> + <frame src="overview-frame.html" name="directoryListFrame"/> + <frame src="allprojects-frame.html" name="projectListFrame"/> + </frameset> + <frame src="overview-summary.html" name="projectFrame"/> + <noframes> + <h2>Frame Alert</h2> + <p> + This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. + </p> + </noframes> + </frameset> +</html> +</xsl:template> + +<!-- this is the stylesheet css to use for nearly everything --> +<xsl:template name="stylesheet.css"> +body { + font:normal 68% verdana,arial,helvetica; + color:#000000; +} +table tr td, table tr th { + font-size: 68%; +} +table.details tr th{ + font-weight: bold; + text-align:left; + background:#a6caf0; +} +table.details tr td{ + background:#eeeee0; +} + +p { + line-height:1.5em; + margin-top:0.5em; margin-bottom:1.0em; +} +h1 { + margin: 0px 0px 5px; font: 165% verdana,arial,helvetica +} +h2 { + margin-top: 1em; margin-bottom: 0.5em; font: bold 125% verdana,arial,helvetica +} +h3 { + margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica +} +h4 { + margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica +} +h5 { + margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica +} +h6 { + margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica +} +.Error { + font-weight:bold; color:red; +} +.Failure { + font-weight:bold; color:purple; +} +.Properties { + text-align:right; +} +</xsl:template> + +<!-- Create list of all/failed/errored tests --> +<xsl:template match="testsuites" mode="all.tests"> + <xsl:param name="type" select="'all'"/> + <html> + <xsl:variable name="title"> + <xsl:choose> + <xsl:when test="$type = 'fails'"> + <xsl:text>All Failures</xsl:text> + </xsl:when> + <xsl:when test="$type = 'errors'"> + <xsl:text>All Errors</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:text>All Tests</xsl:text> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> + <head> + <title>AntUnit Test Results: <xsl:value-of select="$title"/></title> + <xsl:call-template name="create.stylesheet.link"> + <xsl:with-param name="directory.name"/> + </xsl:call-template> + </head> + <body> + <xsl:attribute name="onload">open('allprojects-frame.html','projectListFrame')</xsl:attribute> + <xsl:call-template name="pageHeader"/> + <h2><xsl:value-of select="$title"/></h2> + + <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> + <xsl:call-template name="testcase.test.header"> + <xsl:with-param name="show.project" select="'yes'"/> + </xsl:call-template> + <!-- + test can even not be started at all (failure to load the project) + so report the error directly + --> + <xsl:if test="./error"> + <tr class="Error"> + <td colspan="4"> + <xsl:apply-templates select="./error"/> + </td> + </tr> + </xsl:if> + <xsl:choose> + <xsl:when test="$type = 'fails'"> + <xsl:apply-templates select=".//testcase[failure]" mode="print.test"> + <xsl:with-param name="show.project" select="'yes'"/> + </xsl:apply-templates> + </xsl:when> + <xsl:when test="$type = 'errors'"> + <xsl:apply-templates select=".//testcase[error]" mode="print.test"> + <xsl:with-param name="show.project" select="'yes'"/> + </xsl:apply-templates> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates select=".//testcase" mode="print.test"> + <xsl:with-param name="show.project" select="'yes'"/> + </xsl:apply-templates> + </xsl:otherwise> + </xsl:choose> + </table> + </body> + </html> +</xsl:template> + + +<!-- ====================================================================== + This page is created for every testsuite project. + It prints a summary of the testsuite and detailed information about + testcase methods. + ====================================================================== --> +<xsl:template match="testsuite" mode="project.details"> + <xsl:param name="type" select="'all'"/> + <xsl:variable name="directory.name" select="@package"/> + <xsl:variable name="project.name"><xsl:if test="not($directory.name = '')"><xsl:value-of select="$directory.name"/>.</xsl:if><xsl:value-of select="@name"/></xsl:variable> + <html> + <head> + <title>AntUnit Test Results: <xsl:value-of select="$project.name"/></title> + <xsl:call-template name="create.stylesheet.link"> + <xsl:with-param name="directory.name" select="$directory.name"/> + </xsl:call-template> + <script type="text/javascript" language="JavaScript"> + var TestCases = new Array(); + var cur; + <xsl:apply-templates select="properties"/> + </script> + <script type="text/javascript" language="JavaScript"><![CDATA[ + function displayProperties (name) { + var win = window.open('','JUnitSystemProperties','scrollbars=1,resizable=1'); + var doc = win.document; + doc.open(); + doc.write("<html><head><title>Properties of " + name + "</title>"); + doc.write("<style type=\"text/css\">"); + doc.write("body {font:normal 68% verdana,arial,helvetica; color:#000000; }"); + doc.write("table tr td, table tr th { font-size: 68%; }"); + doc.write("table.properties { border-collapse:collapse; border-left:solid 1 #cccccc; border-top:solid 1 #cccccc; padding:5px; }"); + doc.write("table.properties th { text-align:left; border-right:solid 1 #cccccc; border-bottom:solid 1 #cccccc; background-color:#eeeeee; }"); + doc.write("table.properties td { font:normal; text-align:left; border-right:solid 1 #cccccc; border-bottom:solid 1 #cccccc; background-color:#fffffff; }"); + doc.write("h3 { margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica }"); + doc.write("</style>"); + doc.write("</head><body>"); + doc.write("<h3>Properties of " + name + "</h3>"); + doc.write("<div align=\"right\"><a href=\"javascript:window.close();\">Close</a></div>"); + doc.write("<table class='properties'>"); + doc.write("<tr><th>Name</th><th>Value</th></tr>"); + for (prop in TestCases[name]) { + doc.write("<tr><th>" + prop + "</th><td>" + TestCases[name][prop] + "</td></tr>"); + } + doc.write("</table>"); + doc.write("</body></html>"); + doc.close(); + win.focus(); + } + ]]> + </script> + </head> + <body> + <xsl:call-template name="pageHeader"/> + <h3>Project <xsl:value-of select="$project.name"/></h3> + + + <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> + <xsl:call-template name="testsuite.test.header"/> + <xsl:apply-templates select="." mode="print.test"/> + </table> + + <xsl:choose> + <xsl:when test="$type = 'fails'"> + <h2>Failures</h2> + </xsl:when> + <xsl:when test="$type = 'errors'"> + <h2>Errors</h2> + </xsl:when> + <xsl:otherwise> + <h2>Tests</h2> + </xsl:otherwise> + </xsl:choose> + <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> + <xsl:call-template name="testcase.test.header"/> + <!-- + test can even not be started at all (failure to load the project) + so report the error directly + --> + <xsl:if test="./error"> + <tr class="Error"> + <td colspan="4"><xsl:apply-templates select="./error"/></td> + </tr> + </xsl:if> + <xsl:choose> + <xsl:when test="$type = 'fails'"> + <xsl:apply-templates select="./testcase[failure]" mode="print.test"/> + </xsl:when> + <xsl:when test="$type = 'errors'"> + <xsl:apply-templates select="./testcase[error]" mode="print.test"/> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates select="./testcase" mode="print.test"/> + </xsl:otherwise> + </xsl:choose> + </table> + <!--div class="Properties"> + <a> + <xsl:attribute name="href">javascript:displayProperties('<xsl:value-of select="@package"/>.<xsl:value-of select="@name"/>');</xsl:attribute> + Properties » + </a> + </div> + <xsl:if test="string-length(./system-out)!=0"> + <div class="Properties"> + <a> + <xsl:attribute name="href">./<xsl:value-of select="@id"/>_<xsl:value-of select="@name"/>-out.txt</xsl:attribute> + System.out » + </a> + </div> + </xsl:if> + <xsl:if test="string-length(./system-err)!=0"> + <div class="Properties"> + <a> + <xsl:attribute name="href">./<xsl:value-of select="@id"/>_<xsl:value-of select="@name"/>-err.txt</xsl:attribute> + System.err » + </a> + </div> + </xsl:if--> + </body> + </html> +</xsl:template> + + <!-- + Write properties into a JavaScript data structure. + This is based on the original idea by Erik Hatcher (ehatcher@apache.org) + --> + <xsl:template match="properties"> + cur = TestCases['<xsl:value-of select="../@package"/>.<xsl:value-of select="../@name"/>'] = new Array(); + <xsl:for-each select="property"> + <xsl:sort select="@name"/> + cur['<xsl:value-of select="@name"/>'] = '<xsl:call-template name="JS-escape"><xsl:with-param name="string" select="@value"/></xsl:call-template>'; + </xsl:for-each> + </xsl:template> + + +<!-- ====================================================================== + This page is created for every directory. + It prints the name of all projects that belongs to this directory. + @param name the directory name to print projects. + ====================================================================== --> +<!-- list of projects in a directory --> +<xsl:template name="projects.list"> + <xsl:param name="name"/> + <html> + <head> + <title>AntUnit Test Projects: <xsl:value-of select="$name"/></title> + <xsl:call-template name="create.stylesheet.link"> + <xsl:with-param name="directory.name" select="$name"/> + </xsl:call-template> + </head> + <body> + <table width="100%"> + <tr> + <td nowrap="nowrap"> + <h2><a href="directory-summary.html" target="projectFrame"> + <xsl:value-of select="$name"/> + <xsl:if test="$name = ''"><none></xsl:if> + </a></h2> + </td> + </tr> + </table> + + <h2>Projects</h2> + <table width="100%"> + <xsl:for-each select="/testsuites/testsuite[./@package = $name]"> + <xsl:sort select="@name"/> + <tr> + <td nowrap="nowrap"> + <a href="{@id}_{@name}.html" target="projectFrame"><xsl:value-of select="@name"/></a> + </td> + </tr> + </xsl:for-each> + </table> + </body> + </html> +</xsl:template> + + +<!-- + Creates an all-projects.html file that contains a link to all directory-summary.html + on each project. +--> +<xsl:template match="testsuites" mode="all.projects"> + <html> + <head> + <title>All AntUnit Test Projects</title> + <xsl:call-template name="create.stylesheet.link"> + <xsl:with-param name="directory.name"/> + </xsl:call-template> + </head> + <body> + <h2>Projects</h2> + <table width="100%"> + <xsl:apply-templates select="testsuite" mode="all.projects"> + <xsl:sort select="@name"/> + </xsl:apply-templates> + </table> + </body> + </html> +</xsl:template> + +<xsl:template match="testsuite" mode="all.projects"> + <xsl:variable name="directory.name" select="@package"/> + <tr> + <td nowrap="nowrap"> + <a target="projectFrame"> + <xsl:attribute name="href"> + <xsl:if test="not($directory.name='')"> + <xsl:value-of select="translate($directory.name,'.','/')"/><xsl:text>/</xsl:text> + </xsl:if><xsl:value-of select="@id"/>_<xsl:value-of select="@name"/><xsl:text>.html</xsl:text> + </xsl:attribute> + <xsl:value-of select="@name"/> + </a> + </td> + </tr> +</xsl:template> + + +<!-- + Creates an html file that contains a link to all directory-summary.html files on + each directory existing on testsuites. + @bug there will be a problem here, I don't know yet how to handle unnamed directory :( +--> +<xsl:template match="testsuites" mode="all.directories"> + <html> + <head> + <title>All AntUnit Test Directories</title> + <xsl:call-template name="create.stylesheet.link"> + <xsl:with-param name="directory.name"/> + </xsl:call-template> + </head> + <body> + <h2><a href="overview-summary.html" target="projectFrame">Home</a></h2> + <h2>Directories</h2> + <table width="100%"> + <xsl:apply-templates select="testsuite[not(./@package = preceding-sibling::testsuite/@package)]" mode="all.directories"> + <xsl:sort select="@package"/> + </xsl:apply-templates> + </table> + </body> + </html> +</xsl:template> + +<xsl:template match="testsuite" mode="all.directories"> + <tr> + <td nowrap="nowrap"> + <a href="./{translate(@package,'.','/')}/directory-summary.html" target="projectFrame"> + <xsl:value-of select="@package"/> + <xsl:if test="@package = ''"><none></xsl:if> + </a> + </td> + </tr> +</xsl:template> + + +<xsl:template match="testsuites" mode="overview.directories"> + <html> + <head> + <title>AntUnit Test Results: Summary</title> + <xsl:call-template name="create.stylesheet.link"> + <xsl:with-param name="directory.name"/> + </xsl:call-template> + </head> + <body> + <xsl:attribute name="onload">open('allprojects-frame.html','projectListFrame')</xsl:attribute> + <xsl:call-template name="pageHeader"/> + <h2>Summary</h2> + <xsl:variable name="testCount" select="sum(testsuite/tests/text())"/> + <xsl:variable name="errorCount" select="sum(testsuite/errors/text())"/> + <xsl:variable name="failureCount" select="sum(testsuite/failures/text())"/> + <xsl:variable name="timeCount" select="sum(testsuite/time/text())"/> + <xsl:variable name="successRate" select="($testCount - $failureCount - $errorCount) div $testCount"/> + <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> + <tr valign="top"> + <th>Tests</th> + <th>Failures</th> + <th>Errors</th> + <th>Success rate</th> + <th>Time</th> + </tr> + <tr valign="top"> + <xsl:attribute name="class"> + <xsl:choose> + <xsl:when test="$errorCount > 0">Error</xsl:when> + <xsl:when test="$failureCount > 0">Failure</xsl:when> + <xsl:otherwise>Pass</xsl:otherwise> + </xsl:choose> + </xsl:attribute> + <td><a title="Display all tests" href="all-tests.html"><xsl:value-of select="$testCount"/></a></td> + <td><a title="Display all failures" href="alltests-fails.html"><xsl:value-of select="$failureCount"/></a></td> + <td><a title="Display all errors" href="alltests-errors.html"><xsl:value-of select="$errorCount"/></a></td> + <td> + <xsl:call-template name="display-percent"> + <xsl:with-param name="value" select="$successRate"/> + </xsl:call-template> + </td> + <td> + <xsl:call-template name="display-time"> + <xsl:with-param name="value" select="$timeCount"/> + </xsl:call-template> + </td> + </tr> + </table> + <table border="0" width="95%"> + <tr> + <td style="text-align: justify;"> + Note: <em>failures</em> are anticipated and checked for with assertions while <em>errors</em> are unanticipated. + </td> + </tr> + </table> + + <h2>Directories</h2> + <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> + <xsl:call-template name="testsuite.test.header"/> + <xsl:for-each select="testsuite[not(./@package = preceding-sibling::testsuite/@package)]"> + <xsl:sort select="@package" order="ascending"/> + <!-- get the node set containing all testsuites that have the same directory --> + <xsl:variable name="insamedirectory" select="/testsuites/testsuite[./@package = current()/@package]"/> + <tr valign="top"> + <!-- display a failure if there is any failure/error in the directory --> + <xsl:attribute name="class"> + <xsl:choose> + <xsl:when test="sum($insamedirectory/errors/text()) > 0">Error</xsl:when> + <xsl:when test="sum($insamedirectory/failures/text()) > 0">Failure</xsl:when> + <xsl:otherwise>Pass</xsl:otherwise> + </xsl:choose> + </xsl:attribute> + <td><a href="./{translate(@package,'.','/')}/directory-summary.html"> + <xsl:value-of select="@package"/> + <xsl:if test="@package = ''"><none></xsl:if> + </a></td> + <td><xsl:value-of select="sum($insamedirectory/tests/text())"/></td> + <td><xsl:value-of select="sum($insamedirectory/errors/text())"/></td> + <td><xsl:value-of select="sum($insamedirectory/failures/text())"/></td> + <td> + <xsl:call-template name="display-time"> + <xsl:with-param name="value" select="sum($insamedirectory/time/text())"/> + </xsl:call-template> + </td> + <td><xsl:value-of select="$insamedirectory/@timestamp"/></td> + <td><xsl:value-of select="$insamedirectory/@hostname"/></td> + </tr> + </xsl:for-each> + </table> + </body> + </html> +</xsl:template> + + +<xsl:template name="directory.summary"> + <xsl:param name="name"/> + <html> + <head> + <xsl:call-template name="create.stylesheet.link"> + <xsl:with-param name="directory.name" select="$name"/> + </xsl:call-template> + </head> + <body> + <xsl:attribute name="onload">open('directory-frame.html','projectListFrame')</xsl:attribute> + <xsl:call-template name="pageHeader"/> + <h3>Directory <xsl:value-of select="$name"/></h3> + + <!--table border="0" cellpadding="5" cellspacing="2" width="95%"> + <xsl:call-template name="project.metrics.header"/> + <xsl:apply-templates select="." mode="print.metrics"/> + </table--> + + <xsl:variable name="insamedirectory" select="/testsuites/testsuite[./@package = $name]"/> + <xsl:if test="count($insamedirectory) > 0"> + <h2>Projects</h2> + <p> + <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> + <xsl:call-template name="testsuite.test.header"/> + <xsl:apply-templates select="$insamedirectory" mode="print.test"> + <xsl:sort select="@name"/> + </xsl:apply-templates> + </table> + </p> + </xsl:if> + </body> + </html> +</xsl:template> + + +<!-- + transform string like a.b.c to ../../../ + @param path the path to transform into a descending directory path +--> +<xsl:template name="path"> + <xsl:param name="path"/> + <xsl:if test="contains($path,'.')"> + <xsl:text>../</xsl:text> + <xsl:call-template name="path"> + <xsl:with-param name="path"><xsl:value-of select="substring-after($path,'.')"/></xsl:with-param> + </xsl:call-template> + </xsl:if> + <xsl:if test="not(contains($path,'.')) and not($path = '')"> + <xsl:text>../</xsl:text> + </xsl:if> +</xsl:template> + + +<!-- create the link to the stylesheet based on the directory name --> +<xsl:template name="create.stylesheet.link"> + <xsl:param name="directory.name"/> + <link rel="stylesheet" type="text/css" title="Style"><xsl:attribute name="href"><xsl:if test="not($directory.name = 'unnamed directory')"><xsl:call-template name="path"><xsl:with-param name="path" select="$directory.name"/></xsl:call-template></xsl:if>stylesheet.css</xsl:attribute></link> +</xsl:template> + + +<!-- Page HEADER --> +<xsl:template name="pageHeader"> + <h1>AntUnit Test Results</h1> + <table width="100%"> + <tr> + <td align="left"></td> + <td align="right">Designed for use with <a href="http://ant.apache.org/antlibs/antunit/">AntUnit</a> and <a href="http://ant.apache.org/">Ant</a>.</td> + </tr> + </table> + <hr size="1"/> +</xsl:template> + +<!-- project header --> +<xsl:template name="testsuite.test.header"> + <tr valign="top"> + <th width="80%">Name</th> + <th>Tests</th> + <th>Errors</th> + <th>Failures</th> + <th nowrap="nowrap">Time(s)</th> + <th nowrap="nowrap">Time Stamp</th> + <th>Host</th> + </tr> +</xsl:template> + +<!-- method header --> +<xsl:template name="testcase.test.header"> + <xsl:param name="show.project" select="''"/> + <tr valign="top"> + <xsl:if test="boolean($show.project)"> + <th>Project</th> + </xsl:if> + <th>Name</th> + <th>Status</th> + <th width="80%">Type</th> + <th nowrap="nowrap">Time(s)</th> + </tr> +</xsl:template> + + +<!-- project information --> +<xsl:template match="testsuite" mode="print.test"> + <tr valign="top"> + <xsl:attribute name="class"> + <xsl:choose> + <xsl:when test="errors/text()[.> 0]">Error</xsl:when> + <xsl:when test="failures/text()[.> 0]">Failure</xsl:when> + <xsl:otherwise>Pass</xsl:otherwise> + </xsl:choose> + </xsl:attribute> + <td><a title="Display all tests" href="{@id}_{@name}.html"><xsl:value-of select="@name"/></a></td> + <td><a title="Display all tests" href="{@id}_{@name}.html"><xsl:apply-templates select="tests/text()"/></a></td> + <td> + <xsl:choose> + <xsl:when test="errors/text() != 0"> + <a title="Display only errors" href="{@id}_{@name}-errors.html"><xsl:apply-templates select="errors/text()"/></a> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates select="errors/text()"/> + </xsl:otherwise> + </xsl:choose> + </td> + <td> + <xsl:choose> + <xsl:when test="failures/text() != 0"> + <a title="Display only failures" href="{@id}_{@name}-fails.html"><xsl:apply-templates select="failures/text()"/></a> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates select="failures/text()"/> + </xsl:otherwise> + </xsl:choose> + </td> + <td><xsl:call-template name="display-time"> + <xsl:with-param name="value" select="time/text()"/> + </xsl:call-template> + </td> + <td><xsl:apply-templates select="@timestamp"/></td> + <td><xsl:apply-templates select="@hostname"/></td> + </tr> +</xsl:template> + +<xsl:template match="testcase" mode="print.test"> + <xsl:param name="show.project" select="''"/> + <tr valign="top"> + <xsl:attribute name="class"> + <xsl:choose> + <xsl:when test="error">Error</xsl:when> + <xsl:when test="failure">Failure</xsl:when> + <xsl:otherwise>TableRowColor</xsl:otherwise> + </xsl:choose> + </xsl:attribute> + <xsl:variable name="project.href"> + <xsl:value-of select="concat(translate(../@package,'.','/'), '/', ../@id, '_', ../@name, '.html')"/> + </xsl:variable> + <xsl:if test="boolean($show.project)"> + <td><a href="{$project.href}"><xsl:value-of select="../@name"/></a></td> + </xsl:if> + <td> + <a name="{@name}"/> + <xsl:choose> + <xsl:when test="boolean($show.project)"> + <a href="{concat($project.href, '#', @name)}"><xsl:value-of select="@name"/></a> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="@name"/> + </xsl:otherwise> + </xsl:choose> + </td> + <xsl:choose> + <xsl:when test="failure"> + <td>Failure</td> + <td><xsl:apply-templates select="failure"/></td> + </xsl:when> + <xsl:when test="error"> + <td>Error</td> + <td><xsl:apply-templates select="error"/></td> + </xsl:when> + <xsl:otherwise> + <td>Success</td> + <td></td> + </xsl:otherwise> + </xsl:choose> + <td> + <xsl:call-template name="display-time"> + <xsl:with-param name="value" select="time/text()"/> + </xsl:call-template> + </td> + </tr> +</xsl:template> + + +<!-- Note : the below template error and failure are the same style + so just call the same style store in the toolkit template --> +<xsl:template match="failure"> + <xsl:call-template name="display-failures"/> +</xsl:template> + +<xsl:template match="error"> + <xsl:call-template name="display-failures"/> + <!-- display the stacktrace --> + <br/><br/> + <code> + <xsl:call-template name="br-replace"> + <xsl:with-param name="word" select="."/> + </xsl:call-template> + </code> + <!-- the latter is better but might be problematic for non-21" monitors... --> + <!--pre><xsl:value-of select="."/></pre--> +</xsl:template> + +<!-- Style for the error and failure in the testcase template --> +<xsl:template name="display-failures"> + <xsl:choose> + <xsl:when test="not(@message)">N/A</xsl:when> + <xsl:otherwise> + <xsl:value-of select="@message"/> + </xsl:otherwise> + </xsl:choose> + <xsl:choose> + <xsl:when test="@linenumber"> + <br></br> + at line <xsl:value-of select="@linenumber"/> + <xsl:choose> + <xsl:when test="@columnnumber"> + , column <xsl:value-of select="@columnnumber"/> + </xsl:when> + </xsl:choose> + </xsl:when> + </xsl:choose> +</xsl:template> + +<xsl:template name="JS-escape"> + <xsl:param name="string"/> + <xsl:param name="tmp1" select="stringutils:replace(string($string),'\','\\')"/> + <xsl:param name="tmp2" select="stringutils:replace(string($tmp1),"'","\'")"/> + <xsl:value-of select="$tmp2"/> +</xsl:template> + + +<!-- + template that will convert a carriage return into a br tag + @param word the text from which to convert CR to BR tag +--> +<xsl:template name="br-replace"> + <xsl:param name="word"/> + <xsl:value-of disable-output-escaping="yes" select='stringutils:replace(string($word),"
","<br/>")'/> +</xsl:template> + +<xsl:template name="display-time"> + <xsl:param name="value"/> + <xsl:value-of select="format-number($value,'0.000')"/> +</xsl:template> + +<xsl:template name="display-percent"> + <xsl:param name="value"/> + <xsl:value-of select="format-number($value,'0.00%')"/> +</xsl:template> +</xsl:stylesheet> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/junit-noframes.xsl b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/junit-noframes.xsl new file mode 100644 index 00000000..255046a8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/junit-noframes.xsl @@ -0,0 +1,485 @@ +<?xml version="1.0"?> +<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" + xmlns:lxslt="http://xml.apache.org/xslt" + xmlns:stringutils="xalan://org.apache.tools.ant.util.StringUtils"> +<xsl:output method="html" indent="yes" encoding="US-ASCII" + doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" /> +<xsl:decimal-format decimal-separator="." grouping-separator="," /> +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you 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. +--> +<!-- + + Sample stylesheet to be used with Ant JUnitReport output. + + It creates a non-framed report that can be useful to send via + e-mail or such. + +--> +<xsl:template match="testsuites"> + <html> + <head> + <title>AntUnit Test Results</title> + <style type="text/css"> + body { + font:normal 68% verdana,arial,helvetica; + color:#000000; + } + table tr td, table tr th { + font-size: 68%; + } + table.details tr th{ + font-weight: bold; + text-align:left; + background:#a6caf0; + } + table.details tr td{ + background:#eeeee0; + } + + p { + line-height:1.5em; + margin-top:0.5em; margin-bottom:1.0em; + } + h1 { + margin: 0px 0px 5px; font: 165% verdana,arial,helvetica + } + h2 { + margin-top: 1em; margin-bottom: 0.5em; font: bold 125% verdana,arial,helvetica + } + h3 { + margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica + } + h4 { + margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica + } + h5 { + margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica + } + h6 { + margin-bottom: 0.5em; font: bold 100% verdana,arial,helvetica + } + .Error { + font-weight:bold; color:red; + } + .Failure { + font-weight:bold; color:purple; + } + .Properties { + text-align:right; + } + </style> + <!-- + <script type="text/javascript" language="JavaScript"> + var Projects = new Array(); + var cur; + <xsl:for-each select="./testsuite"> + <xsl:apply-templates select="properties"/> + </xsl:for-each> + + </script> + <script type="text/javascript" language="JavaScript"><![CDATA[ + function displayProperties (name) { + var win = window.open('','JUnitSystemProperties','scrollbars=1,resizable=1'); + var doc = win.document; + doc.open(); + doc.write("<html><head><title>Properties of " + name + "</title>"); + doc.write("<style>") + doc.write("body {font:normal 68% verdana,arial,helvetica; color:#000000; }"); + doc.write("table tr td, table tr th { font-size: 68%; }"); + doc.write("table.properties { border-collapse:collapse; border-left:solid 1 #cccccc; border-top:solid 1 #cccccc; padding:5px; }"); + doc.write("table.properties th { text-align:left; border-right:solid 1 #cccccc; border-bottom:solid 1 #cccccc; background-color:#eeeeee; }"); + doc.write("table.properties td { font:normal; text-align:left; border-right:solid 1 #cccccc; border-bottom:solid 1 #cccccc; background-color:#fffffff; }"); + doc.write("h3 { margin-bottom: 0.5em; font: bold 115% verdana,arial,helvetica }"); + doc.write("</style>"); + doc.write("</head><body>"); + doc.write("<h3>Properties of " + name + "</h3>"); + doc.write("<div align=\"right\"><a href=\"javascript:window.close();\">Close</a></div>"); + doc.write("<table class='properties'>"); + doc.write("<tr><th>Name</th><th>Value</th></tr>"); + for (prop in Projects[name]) { + doc.write("<tr><th>" + prop + "</th><td>" + Projects[name][prop] + "</td></tr>"); + } + doc.write("</table>"); + doc.write("</body></html>"); + doc.close(); + win.focus(); + } + ]]> + </script> + --> + </head> + <body> + <a name="top"></a> + <xsl:call-template name="pageHeader"/> + + <!-- Summary part --> + <xsl:call-template name="summary"/> + <hr size="1" width="95%" align="left"/> + + <!-- Directory List part --> + <xsl:call-template name="directorylist"/> + <hr size="1" width="95%" align="left"/> + + <!-- For each directory create its part --> + <xsl:call-template name="directories"/> + <hr size="1" width="95%" align="left"/> + + <!-- For each class create the part --> + <xsl:call-template name="classes"/> + + </body> + </html> +</xsl:template> + + + + <!-- ================================================================== --> + <!-- Write a list of all directories with an hyperlink to the anchor of --> + <!-- of the directory name. --> + <!-- ================================================================== --> + <xsl:template name="directorylist"> + <h2>Directories</h2> + Note: directory statistics are not computed recursively, they only sum up all of its testsuites numbers. + <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> + <xsl:call-template name="testsuite.test.header"/> + <!-- list all directories recursively --> + <xsl:for-each select="./testsuite[not(./@package = preceding-sibling::testsuite/@package)]"> + <xsl:sort select="@package"/> + <xsl:variable name="testsuites-in-directory" select="/testsuites/testsuite[./@package = current()/@package]"/> + <xsl:variable name="testCount" select="sum($testsuites-in-directory/tests/text())"/> + <xsl:variable name="errorCount" select="sum($testsuites-in-directory/errors/text())"/> + <xsl:variable name="failureCount" select="sum($testsuites-in-directory/failures/text())"/> + <xsl:variable name="timeCount" select="sum($testsuites-in-directory/time/text())"/> + + <!-- write a summary for the directory --> + <tr valign="top"> + <!-- set a nice color depending if there is an error/failure --> + <xsl:attribute name="class"> + <xsl:choose> + <xsl:when test="$failureCount > 0">Failure</xsl:when> + <xsl:when test="$errorCount > 0">Error</xsl:when> + </xsl:choose> + </xsl:attribute> + <td><a href="#{@package}"><xsl:value-of select="@package"/></a></td> + <td><xsl:value-of select="$testCount"/></td> + <td><xsl:value-of select="$errorCount"/></td> + <td><xsl:value-of select="$failureCount"/></td> + <td> + <xsl:call-template name="display-time"> + <xsl:with-param name="value" select="$timeCount"/> + </xsl:call-template> + </td> + <td><xsl:value-of select="$testsuites-in-directory/@timestamp"/></td> + <td><xsl:value-of select="$testsuites-in-directory/@hostname"/></td> + </tr> + </xsl:for-each> + </table> + </xsl:template> + + + <!-- ================================================================== --> + <!-- Write a directory level report --> + <!-- It creates a table with values from the document: --> + <!-- Name | Tests | Errors | Failures | Time --> + <!-- ================================================================== --> + <xsl:template name="directories"> + <!-- create an anchor to this directory name --> + <xsl:for-each select="/testsuites/testsuite[not(./@package = preceding-sibling::testsuite/@package)]"> + <xsl:sort select="@package"/> + <a name="{@package}"></a> + <h3>Directory <xsl:value-of select="@package"/></h3> + + <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> + <xsl:call-template name="testsuite.test.header"/> + + <!-- match the testsuites of this directory --> + <xsl:apply-templates select="/testsuites/testsuite[./@package = current()/@package]" mode="print.test"/> + </table> + <a href="#top">Back to top</a> + <p/> + <p/> + </xsl:for-each> + </xsl:template> + + <xsl:template name="classes"> + <xsl:for-each select="testsuite"> + <xsl:sort select="@name"/> + <!-- create an anchor to this class name --> + <a name="{@name}"></a> + <h3>Project <xsl:value-of select="@name"/></h3> + + <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> + <xsl:call-template name="testcase.test.header"/> + <!-- + test can even not be started at all (failure to load the class) + so report the error directly + --> + <xsl:if test="./error"> + <tr class="Error"> + <td colspan="4"><xsl:apply-templates select="./error"/></td> + </tr> + </xsl:if> + <xsl:apply-templates select="./testcase" mode="print.test"/> + </table> + <!-- + <div class="Properties"> + <a> + <xsl:attribute name="href">javascript:displayProperties('<xsl:value-of select="@package"/>.<xsl:value-of select="@name"/>');</xsl:attribute> + Properties » + </a> + </div> + --> + <p/> + + <a href="#top">Back to top</a> + </xsl:for-each> + </xsl:template> + + <xsl:template name="summary"> + <h2>Summary</h2> + <xsl:variable name="testCount" select="sum(testsuite/tests/text())"/> + <xsl:variable name="errorCount" select="sum(testsuite/errors/text())"/> + <xsl:variable name="failureCount" select="sum(testsuite/failures/text())"/> + <xsl:variable name="timeCount" select="sum(testsuite/time/text())"/> + <xsl:variable name="successRate" select="($testCount - $failureCount - $errorCount) div $testCount"/> + <table class="details" border="0" cellpadding="5" cellspacing="2" width="95%"> + <tr valign="top"> + <th>Tests</th> + <th>Failures</th> + <th>Errors</th> + <th>Success rate</th> + <th>Time</th> + </tr> + <tr valign="top"> + <xsl:attribute name="class"> + <xsl:choose> + <xsl:when test="$failureCount > 0">Failure</xsl:when> + <xsl:when test="$errorCount > 0">Error</xsl:when> + </xsl:choose> + </xsl:attribute> + <td><xsl:value-of select="$testCount"/></td> + <td><xsl:value-of select="$failureCount"/></td> + <td><xsl:value-of select="$errorCount"/></td> + <td> + <xsl:call-template name="display-percent"> + <xsl:with-param name="value" select="$successRate"/> + </xsl:call-template> + </td> + <td> + <xsl:call-template name="display-time"> + <xsl:with-param name="value" select="$timeCount"/> + </xsl:call-template> + </td> + + </tr> + </table> + <table border="0" width="95%"> + <tr> + <td style="text-align: justify;"> + Note: <i>failures</i> are anticipated and checked for with assertions while <i>errors</i> are unanticipated. + </td> + </tr> + </table> + </xsl:template> + + <!-- + Write properties into a JavaScript data structure. + This is based on the original idea by Erik Hatcher (ehatcher@apache.org) + --> + <!-- + <xsl:template match="properties"> + cur = Projects['<xsl:value-of select="../@package"/>.<xsl:value-of select="../@name"/>'] = new Array(); + <xsl:for-each select="property"> + <xsl:sort select="@name"/> + cur['<xsl:value-of select="@name"/>'] = '<xsl:call-template name="JS-escape"><xsl:with-param name="string" select="@value"/></xsl:call-template>'; + </xsl:for-each> + </xsl:template> + --> + +<!-- Page HEADER --> +<xsl:template name="pageHeader"> + <h1>Unit Test Results</h1> + <table width="100%"> + <tr> + <td align="left"></td> + <td align="right">Designed for use with <a href='http://ant.apache.org/antlibs/antunit/'>AntUnit</a> and <a href='http://ant.apache.org/'>Ant</a>.</td> + </tr> + </table> + <hr size="1"/> +</xsl:template> + +<xsl:template match="testsuite" mode="header"> + <tr valign="top"> + <th width="80%">Name</th> + <th>Tests</th> + <th>Errors</th> + <th>Failures</th> + <th nowrap="nowrap">Time(s)</th> + </tr> +</xsl:template> + +<!-- class header --> +<xsl:template name="testsuite.test.header"> + <tr valign="top"> + <th width="80%">Name</th> + <th>Tests</th> + <th>Errors</th> + <th>Failures</th> + <th nowrap="nowrap">Time(s)</th> + <th nowrap="nowrap">Time Stamp</th> + <th>Host</th> + </tr> +</xsl:template> + +<!-- method header --> +<xsl:template name="testcase.test.header"> + <tr valign="top"> + <th>Name</th> + <th>Status</th> + <th width="80%">Type</th> + <th nowrap="nowrap">Time(s)</th> + </tr> +</xsl:template> + + +<!-- class information --> +<xsl:template match="testsuite" mode="print.test"> + <tr valign="top"> + <!-- set a nice color depending if there is an error/failure --> + <xsl:attribute name="class"> + <xsl:choose> + <xsl:when test="failures/text()[.> 0]">Failure</xsl:when> + <xsl:when test="errors/text()[.> 0]">Error</xsl:when> + </xsl:choose> + </xsl:attribute> + + <!-- print testsuite information --> + <td><a href="#{@name}"><xsl:value-of select="@name"/></a></td> + <td><xsl:value-of select="tests/text()"/></td> + <td><xsl:value-of select="errors/text()"/></td> + <td><xsl:value-of select="failures/text()"/></td> + <td> + <xsl:call-template name="display-time"> + <xsl:with-param name="value" select="time/text()"/> + </xsl:call-template> + </td> + <td><xsl:apply-templates select="@timestamp"/></td> + <td><xsl:apply-templates select="@hostname"/></td> + </tr> +</xsl:template> + +<xsl:template match="testcase" mode="print.test"> + <tr valign="top"> + <xsl:attribute name="class"> + <xsl:choose> + <xsl:when test="error">Error</xsl:when> + <xsl:when test="failure">Failure</xsl:when> + <xsl:otherwise>TableRowColor</xsl:otherwise> + </xsl:choose> + </xsl:attribute> + <td><xsl:value-of select="@name"/></td> + <xsl:choose> + <xsl:when test="failure"> + <td>Failure</td> + <td><xsl:apply-templates select="failure"/></td> + </xsl:when> + <xsl:when test="error"> + <td>Error</td> + <td><xsl:apply-templates select="error"/></td> + </xsl:when> + <xsl:otherwise> + <td>Success</td> + <td></td> + </xsl:otherwise> + </xsl:choose> + <td> + <xsl:call-template name="display-time"> + <xsl:with-param name="value" select="time/text()"/> + </xsl:call-template> + </td> + </tr> +</xsl:template> + + +<xsl:template match="failure"> + <xsl:call-template name="display-failures"/> +</xsl:template> + +<xsl:template match="error"> + <xsl:call-template name="display-failures"/> + <!-- display the stacktrace --> + <br/><br/> + <code> + <xsl:call-template name="br-replace"> + <xsl:with-param name="word" select="."/> + </xsl:call-template> + </code> + <!-- the latter is better but might be problematic for non-21" monitors... --> + <!--pre><xsl:value-of select="."/></pre--> +</xsl:template> + +<!-- Style for the error and failure in the tescase template --> +<xsl:template name="display-failures"> + <xsl:choose> + <xsl:when test="not(@message)">N/A</xsl:when> + <xsl:otherwise> + <xsl:value-of select="@message"/> + </xsl:otherwise> + </xsl:choose> + <xsl:choose> + <xsl:when test="@linenumber"> + <br></br> + at line <xsl:value-of select="@linenumber"/> + <xsl:choose> + <xsl:when test="@columnnumber"> + , column <xsl:value-of select="@columnnumber"/> + </xsl:when> + </xsl:choose> + </xsl:when> + </xsl:choose> +</xsl:template> + +<xsl:template name="JS-escape"> + <xsl:param name="string"/> + <xsl:param name="tmp1" select="stringutils:replace(string($string),'\','\\')"/> + <xsl:param name="tmp2" select="stringutils:replace(string($tmp1),"'","\'")"/> + <xsl:value-of select="$tmp2"/> +</xsl:template> + + +<!-- + template that will convert a carriage return into a br tag + @param word the text from which to convert CR to BR tag +--> +<xsl:template name="br-replace"> + <xsl:param name="word"/> + <xsl:value-of disable-output-escaping="yes" select='stringutils:replace(string($word),"
","<br/>")'/> +</xsl:template> + +<xsl:template name="display-time"> + <xsl:param name="value"/> + <xsl:value-of select="format-number($value,'0.000')"/> +</xsl:template> + +<xsl:template name="display-percent"> + <xsl:param name="value"/> + <xsl:value-of select="format-number($value,'0.00%')"/> +</xsl:template> + +</xsl:stylesheet> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/propertyhelpers.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/propertyhelpers.xml new file mode 100644 index 00000000..287f00c3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/propertyhelpers.xml @@ -0,0 +1,88 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project> + <import file="antunit-base.xml"/> + + <target name="compileHelpers"> + <mkdir dir="${input}/org/apache/ant/propertyhelper"/> + <mkdir dir="${output}/org/apache/ant/propertyhelper"/> + + <echo file="${input}/org/apache/ant/propertyhelper/URLHelper.java"><![CDATA[ +package org.apache.ant.propertyhelper; + +import org.apache.tools.ant.PropertyHelper; +import org.apache.tools.ant.types.resources.URLResource; + +public class URLHelper implements PropertyHelper.PropertyEvaluator { + private String prefix = "url:"; + public Object evaluate(String property, PropertyHelper propertyHelper) { + if (property.startsWith(prefix)) { + String s = property.substring(prefix.length()); + return new URLResource(s); + } + return null; + } +} +]]></echo> + <echo file="${input}/org/apache/ant/propertyhelper/JavaHelper.java"><![CDATA[ +package org.apache.ant.propertyhelper; + +import java.io.File; +import org.apache.tools.ant.ProjectComponent; +import org.apache.tools.ant.PropertyHelper; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.resources.JavaResource; + +public class JavaHelper extends ProjectComponent + implements PropertyHelper.PropertyEvaluator { + + private String prefix = "java:"; + public Object evaluate(String property, PropertyHelper propertyHelper) { + if (property.startsWith(prefix)) { + String s = property.substring(prefix.length()); + int index = s.indexOf("!"); + + Path p = new Path(getProject()); + p.setPath(s.substring(0, index)); + + JavaResource r = new JavaResource(s.substring(index + 1), p); + r.setProject(getProject()); + return r; + } + return null; + } +} +]]></echo> + <javac srcdir="${input}" destdir="${output}"/> + </target> + + <target name="defineHelpers" depends="compileHelpers"> + <componentdef name="urlhelper" + classname="org.apache.ant.propertyhelper.URLHelper"> + <classpath location="${output}"/> + </componentdef> + <componentdef name="javahelper" + classname="org.apache.ant.propertyhelper.JavaHelper"> + <classpath location="${output}"/> + </componentdef> + <propertyhelper> + <urlhelper/> + <javahelper/> + </propertyhelper> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/ant-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/ant-test.xml new file mode 100644 index 00000000..c3ee56b7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/ant-test.xml @@ -0,0 +1,55 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="testLastPropertyWins"> + <ant antfile="antcall-test.xml" target="checkB"> + <property name="b" value="1"/> + <property name="b" value="2"/> + <property name="expected" value="2"/> + </ant> + </target> + + <target name="makePropertiesFile"> + <ant antfile="antcall-test.xml" target="makePropertiesFile"/> + </target> + + <target name="testPropertiesLoadedFromFile" depends="makePropertiesFile"> + <ant antfile="antcall-test.xml" target="checkB"> + <property name="expected" value="2"/> + <property file="${input}/ant.properties"/> + </ant> + </target> + + <target name="testFileSeesExternalProperty" depends="makePropertiesFile"> + <property name="a" value="x"/> + <ant antfile="antcall-test.xml" target="checkB"> + <property name="expected" value="x"/> + <property file="${input}/ant.properties"/> + </ant> + </target> + + <target name="testFileSeesInternalProperty" depends="makePropertiesFile"> + <ant antfile="antcall-test.xml" target="checkB"> + <property name="a" value="y"/> + <property name="expected" value="y"/> + <property file="${input}/ant.properties"/> + </ant> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/antcall-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/antcall-test.xml new file mode 100644 index 00000000..9767185d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/antcall-test.xml @@ -0,0 +1,63 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="checkB"> + <au:assertPropertyEquals name="b" value="${expected}"/> + </target> + + <target name="testLastParamWins"> + <antcall target="checkB"> + <param name="b" value="1"/> + <param name="b" value="2"/> + <param name="expected" value="2"/> + </antcall> + </target> + + <target name="makePropertiesFile"> + <mkdir dir="${input}"/> + <echo file="${input}/ant.properties"><![CDATA[ +a=2 +b=$${a} +]]></echo> + </target> + + <target name="testPropertiesLoadedFromFile" depends="makePropertiesFile"> + <antcall target="checkB"> + <param name="expected" value="2"/> + <param file="${input}/ant.properties"/> + </antcall> + </target> + + <target name="testFileSeesExternalProperty" depends="makePropertiesFile"> + <property name="a" value="x"/> + <antcall target="checkB"> + <param name="expected" value="x"/> + <param file="${input}/ant.properties"/> + </antcall> + </target> + + <target name="testFileSeesInternalParam" depends="makePropertiesFile"> + <antcall target="checkB"> + <param name="a" value="y"/> + <param name="expected" value="y"/> + <param file="${input}/ant.properties"/> + </antcall> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt-test.xml new file mode 100644 index 00000000..9b240011 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt-test.xml @@ -0,0 +1,158 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + <!-- apt tests --> + + <property name="build.dir" location="aptbuild" /> + <property name="classes.dir" location="${build.dir}/classes" /> + <property name="classes2.dir" location="${build.dir}/classes2" /> + <property name="preprocess.dir" location="${build.dir}/source" /> + <property name="src" location="apt" /> + + <property name="AptExample.class" location="${classes.dir}/AptExample.class" /> + + <macrodef name="assertCompiled"> + <attribute name="file" /> + <sequential > + <fail message="not found: @{file}"> + <condition> + <not> + <available file="@{file}" /> + </not> + </condition> + </fail> + </sequential> + </macrodef> + + <macrodef name="assertProcessed"> + <sequential> + <au:assertLogContains text="DistributedAnnotationProcessor-is-go"/> + <au:assertLogContains text="[-Abuild.dir="/> + <au:assertLogContains text="visiting DistributedAnnotationFactory"/> + </sequential> + </macrodef> + + <presetdef name="assertAptExampleCompiled"> + <assertCompiled file="${AptExample.class}"/> + </presetdef> + + <target name="tearDown" depends="antunit-base.tearDown"> + <delete dir="${build.dir}"/> + </target> + + <target name="setUp"> + <mkdir dir="${classes.dir}"/> + <mkdir dir="${classes2.dir}"/> + <mkdir dir="${preprocess.dir}"/> + </target> + + <target name="testApt" depends="setUp" unless="jdk1.8+"> + <apt srcdir="${src}" + destdir="${classes.dir}" + debug="on" + compile="true" + preprocessdir="${preprocess.dir}"> + </apt> + <assertAptExampleCompiled /> + </target> + + <target name="testAptFork" depends="setUp" unless="jdk1.8+"> + <apt srcdir="${src}" + destdir="${classes.dir}" + debug="on" + compile="true" + fork="true" + preprocessdir="${preprocess.dir}"> + </apt> + <assertAptExampleCompiled /> + </target> + + <target name="testAptForkFalse" depends="setUp" unless="jdk1.8+"> + <apt srcdir="${src}" + destdir="${classes.dir}" + debug="on" + compile="true" + fork="false" + preprocessdir="${preprocess.dir}"> + </apt> + <assertAptExampleCompiled /> + <au:assertLogContains text="Apt only runs in its own JVM; fork=false option ignored"/> + + </target> + + <target name="testListAnnotationTypes" depends="setUp" unless="jdk1.8+"> + <apt srcdir="${src}" + destdir="${classes.dir}" + debug="on" + compile="true" + preprocessdir="${preprocess.dir}"> + <compilerarg value="-XListAnnotationTypes" /> + <compilerarg value="-Xlint:deprecation" /> + </apt> + + <assertAptExampleCompiled /> + <au:assertLogContains text="Set of annotations found:"/> + <au:assertLogContains text="Distributed"/> + </target> + + + <!-- use the factory we compiled. To avoid trouble + we deliver into a version in a new classpath, otherwise + the dependency logic will not run Apt--> + <target name="testAptNewFactory" depends="testApt" unless="jdk1.8+"> + <apt srcdir="${src}" + destdir="${classes2.dir}" + debug="on" + compile="true" + factory="DistributedAnnotationFactory" + preprocessdir="${preprocess.dir}"> + <factorypath path="${classes.dir}" /> + <option name="build.dir" value="${build.dir}" /> + </apt> + <assertAptExampleCompiled /> + <assertProcessed /> + </target> + + <target name="testAptNewFactoryFork" depends="testApt" unless="jdk1.8+"> + <apt srcdir="${src}" + destdir="${classes2.dir}" + debug="on" + compile="true" + fork="true" + factory="DistributedAnnotationFactory" + preprocessdir="${preprocess.dir}"> + <factorypath path="${classes.dir}" /> + <option name="build.dir" value="${build.dir}" /> + </apt> + <assertAptExampleCompiled /> + <assertProcessed /> + </target> + + <target name="testAptUnderJDK18" if="jdk1.8+"> + <au:expectfailure expectedMessage="apt does not exist under Java 1.8 and higher"> + <apt srcdir="${src}" + destdir="${classes.dir}" + debug="on" + compile="true" + fork="true" + preprocessdir="${preprocess.dir}"> + </apt> + </au:expectfailure> + </target> +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt/AptExample.java b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt/AptExample.java new file mode 100644 index 00000000..9d6fcba8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt/AptExample.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ +/** + */ +@Distributed( + protocol="CORBA", + distribution=Distributed.DistributionTypes.FEDERATED + ) +public class AptExample { +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt/Distributed.java b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt/Distributed.java new file mode 100644 index 00000000..ebc3467a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt/Distributed.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ +import java.lang.annotation.Annotation; +import java.lang.annotation.Target; +import java.lang.annotation.Retention; +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.RetentionPolicy; + +/** + */ +@Documented +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = ElementType.TYPE) +public @interface Distributed { + + public DistributionTypes distribution() default DistributionTypes.LOCAL; + + public String protocol() default "RMI"; + + public enum DistributionTypes { SINGLETON, LOCAL, FAULT_TOLERANT, FEDERATED, MOBILE}; + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt/DistributedAnnotationFactory.java b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt/DistributedAnnotationFactory.java new file mode 100644 index 00000000..a8fb6331 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt/DistributedAnnotationFactory.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ +import com.sun.mirror.apt.AnnotationProcessorFactory; +import com.sun.mirror.apt.AnnotationProcessor; +import com.sun.mirror.apt.AnnotationProcessorEnvironment; + +import java.util.Collection; +import java.util.Set; +import java.util.Arrays; +import java.util.Collections; + + +/** + * This was the first piece of Java1.5 code in the source tree. + * @since 20050-03-09T21:29:25Z + */ +public class DistributedAnnotationFactory implements AnnotationProcessorFactory { + + private static final Collection<String> supportedAnnotations + = Collections.unmodifiableCollection(Arrays.asList("*")); + + public Collection<String> supportedOptions() { + return Collections.emptySet(); + } + + public Collection<String> supportedAnnotationTypes() { + return supportedAnnotations; + } + + public AnnotationProcessor getProcessorFor( + Set<com.sun.mirror.declaration.AnnotationTypeDeclaration> annotationTypeDeclarations, + AnnotationProcessorEnvironment env) { + return new DistributedAnnotationProcessor(env); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt/DistributedAnnotationProcessor.java b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt/DistributedAnnotationProcessor.java new file mode 100644 index 00000000..f94ff7f7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/apt/DistributedAnnotationProcessor.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +//found in tools.jar, not the JRE runtime. +import com.sun.mirror.apt.AnnotationProcessor; +import com.sun.mirror.apt.AnnotationProcessorEnvironment; +import com.sun.mirror.declaration.TypeDeclaration; +import com.sun.mirror.declaration.ClassDeclaration; +import com.sun.mirror.util.SimpleDeclarationVisitor; +import static com.sun.mirror.util.DeclarationVisitors.*; + +import java.util.Map; + +/** + * Annotation processor outputs stuff + */ + +public class DistributedAnnotationProcessor implements AnnotationProcessor { + + public AnnotationProcessorEnvironment env; + + public DistributedAnnotationProcessor(AnnotationProcessorEnvironment env) { + this.env = env; + } + + public void echo(String text) { + env.getMessager().printNotice(text); + } + + public void process() { + echo("DistributedAnnotationProcessor-is-go"); + + Map<String, String> options=env.getOptions(); + for(String key:options.keySet()) { + echo("Option ["+key+"] = "+options.get(key)); + } + + //work time + for (TypeDeclaration typeDecl : env.getSpecifiedTypeDeclarations()) { + typeDecl.accept(getDeclarationScanner(new ClassVisitor(), + NO_OP)); + } + } + + private class ClassVisitor extends SimpleDeclarationVisitor { + public void visitClassDeclaration(ClassDeclaration d) { + echo("visiting "+ d.getQualifiedName()); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/augment-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/augment-test.xml new file mode 100644 index 00000000..2e6f3354 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/augment-test.xml @@ -0,0 +1,74 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="augment-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml"/> + + <target name="setUp"> + <mkdir dir="${input}" /> + <touch> + <filelist id="filelist" dir="${input}" files="foo,bar,baz" /> + </touch> + <fileset id="input-fs" dir="${input}" /> + <au:assertTrue> + <resourcecount refid="input-fs" count="3" /> + </au:assertTrue> + </target> + + <target name="test-augment-attribute" depends="setUp"> + <augment id="input-fs" excludes="foo" /> + <au:assertTrue> + <resourcecount refid="input-fs" count="2" /> + </au:assertTrue> + </target> + + <target name="test-augment-element" depends="setUp"> + <augment id="input-fs"> + <filename name="bar" /> + </augment> + <au:assertTrue> + <resourcecount refid="input-fs" count="1" /> + </au:assertTrue> + </target> + + <target name="test-noref"> + <au:expectfailure expectedMessage="Unknown reference "nosuchreference""> + <augment id="nosuchreference" /> + </au:expectfailure> + </target> + + <target name="test-id-not-set"> + <au:expectfailure expectedMessage="augment attribute 'id' unset"> + <augment foo="bar" /> + </au:expectfailure> + </target> + + <target name="test-illegal-attribute" depends="setUp"> + <au:expectfailure expectedMessage="augmented reference "input-fs" doesn't support the "filesetwillmostlikelyneversupportthisattribute" attribute"> + <augment id="input-fs" filesetwillmostlikelyneversupportthisattribute="blah" /> + </au:expectfailure> + </target> + + <target name="test-illegal-element" depends="setUp"> + <au:expectfailure expectedMessage="augmented reference "input-fs" doesn't support the nested "filesetwillmostlikelyneversupportthiselement" element"> + <augment id="input-fs"> + <filesetwillmostlikelyneversupportthiselement /> + </augment> + </au:expectfailure> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/broken_cd.zip b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/broken_cd.zip Binary files differnew file mode 100644 index 00000000..721fb450 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/broken_cd.zip diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/bunzip2-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/bunzip2-test.xml new file mode 100644 index 00000000..a9ca4237 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/bunzip2-test.xml @@ -0,0 +1,28 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="testExpandArchiveWithMultipleStreams"> + <mkdir dir="${output}"/> + <bunzip2 src="bzip2/multiple.bz2" dest="${output}"/> + <au:assertFilesMatch expected="bzip2/expected" + actual="${output}/multiple"/> + </target> + +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/bzip2/expected b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/bzip2/expected new file mode 100644 index 00000000..9ae9e86b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/bzip2/expected @@ -0,0 +1 @@ +ab
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/bzip2/multiple.bz2 b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/bzip2/multiple.bz2 Binary files differnew file mode 100644 index 00000000..26dc3a75 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/bzip2/multiple.bz2 diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/checksum-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/checksum-test.xml new file mode 100644 index 00000000..8341f425 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/checksum-test.xml @@ -0,0 +1,83 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="testChecksumConditionWithFileSet"> + <mkdir dir="${output}"/> + <checksum todir="${output}"> + <fileset dir="."/> + </checksum> + <condition property="checksumsMatch"> + <checksum todir="${output}"> + <fileset dir="."/> + </checksum> + </condition> + <au:assertPropertySet name="checksumsMatch"/> + </target> + + <target name="testTotalPropertyAcrossPlatforms" + description="testcase for + https://issues.apache.org/bugzilla/show_bug.cgi?id=36748"> + <mkdir dir="${input}"/> + <echo file="${input}/a.txt">abc</echo> + <echo file="${input}/subdir/A.txt">def</echo> + <echo file="${input}/B.txt">xyz</echo> + <checksum totalproperty="total"> + <fileset dir="${input}"/> + </checksum> + <au:assertPropertyEquals name="total" + value="f4d688789d32e6ca6bc93c504dbc6b46"/> + </target> + + <target name="testChecksumPattern2"> + <mkdir dir="${output}"/> + <mkdir dir="${input}"/> + <echo file="${input}/a.txt">abc</echo> + <checksum todir="${output}" pattern="{2}"> + <fileset dir="${input}"/> + </checksum> + <au:assertResourceContains + resource="${output}/a.txt.MD5" + value="../testinput/a.txt"/> + </target> + + <target name="testChecksumPattern3"> + <mkdir dir="${output}"/> + <checksum todir="${output}" pattern="{3}"> + <fileset dir=".." includes="types/fileset-test.xml"/> + </checksum> + <au:assertResourceContains + resource="${output}/types/fileset-test.xml.MD5" + value="../types/fileset-test.xml"/> + </target> + + <target name="testChecksumPattern4"> + <mkdir dir="${output}"/> + <mkdir dir="${input}"/> + <property name="a" location="${input}/a.txt"/> + <echo file="${a}">abc</echo> + <checksum todir="${output}" pattern="{4}"> + <fileset dir="${input}"/> + </checksum> + <au:assertResourceContains + resource="${output}/a.txt.MD5" + value="${a}"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/commandlauncher/commandlauncher-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/commandlauncher/commandlauncher-test.xml new file mode 100644 index 00000000..49519bd8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/commandlauncher/commandlauncher-test.xml @@ -0,0 +1,87 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + <import file="../../antunit-base.xml" /> + + <target name="testCommandLauncherTask"> + <echo message="${input}"/> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/MyCommandLauncher.java"> +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Execute; +import org.apache.tools.ant.taskdefs.launcher.Java13CommandLauncher; + +public class MyCommandLauncher extends Java13CommandLauncher { + public MyCommandLauncher() throws NoSuchMethodException { + super(); + } + + + + @Override + public Process exec(Project project, String[] cmd, String[] env, File workingDir) throws IOException { + Process p = super.exec(project, cmd, env, workingDir); + System.out.println("Hello World From CommandLauncher"); + return p; + } + +} + + </echo> + <echo file="${input}/MyJavaExecutable.java"> +public class MyJavaExecutable { + public static void main(String[] args) { + + } +} + + </echo> + <javac destdir="${output}" + srcdir="${input}"/> + <typedef + name="my-command-launcher" + classname="MyCommandLauncher" classpath="${output}"/> + + <commandlauncher vmlauncher="true"> + <my-command-launcher/> + </commandlauncher> + + <condition property="java" + value="${java.home}/bin/java.exe" + else="${java.home}/bin/java"> + <os family="dos"/> + </condition> + + <exec executable="${java}" failonerror="true"> + <arg value="-cp"/> + <arg value="${output}"/> + <arg value="MyJavaExecutable"/> + </exec> + + + <au:assertLogContains text="Hello World From CommandLauncher"/> + </target> + + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/concat-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/concat-test.xml new file mode 100644 index 00000000..4b285e38 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/concat-test.xml @@ -0,0 +1,202 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="tearDown" depends="antunit-base.tearDown"> + <delete file="concat.resources" /> + </target> + + <property name="encodeStringDest" location="${output}/encodeStringDest" /> + + <target name="testBinaryAppend"> + <property name="binaryAppendDest" location="${output}/binaryAppendDest" /> + <mkdir dir="${output}" /> + <au:assertTrue message="prerequisite conditions unmet"> + <length length="0"> + <!-- allow for nonexistent OR zero-length: --> + <fileset file="${binaryAppendDest}" /> + </length> + </au:assertTrue> + <echo file="${binaryAppendDest}">x</echo> + <au:assertTrue message="destfile setup failed"> + <length length="1" file="${binaryAppendDest}" /> + </au:assertTrue> + <concat append="true" destfile="${binaryAppendDest}" binary="true"> + <string value="x" /> + </concat> + <au:assertTrue message="expected length 2"> + <length file="${binaryAppendDest}" length="2" /> + </au:assertTrue> + </target> + + <target name="testStringEncoding" if="os.unix"> + <property name="br" value="${line.separator}" /> + <concat destfile="${encodeStringDest}" outputEncoding="utf-16">foo${br}bar${br}baz${br}</concat> + <au:assertTrue> + <resourcesmatch astext="true"> + <file file="utf-16.expected" /> + <file file="${encodeStringDest}" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testStringEncodingWindows" if="os.windows"> + <property name="br" value="${line.separator}" /> + <concat destfile="${encodeStringDest}" outputEncoding="utf-16">foo${br}bar${br}baz${br}</concat> + <au:assertTrue> + <resourcesmatch astext="true"> + <file file="utf-16.expected.windows" /> + <file file="${encodeStringDest}" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testDoNotFixNestedText" description="Bugzilla 42369"> + <au:assertTrue> + <resourcesmatch> + <string>foo</string> + <concat fixlastline="true">foo</concat> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="-fixlastline-setup"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/1">1</echo> + <echo file="${input}/2">2</echo> + </target> + + <target name="testFixLastLineActuallyFixes" depends="-fixlastline-setup"> + <au:assertTrue> + <resourcesmatch> + <string>1${line.separator}2${line.separator}</string> + <concat fixlastline="true"> + <filelist dir="${input}"> + <file name="1"/> + <file name="2"/> + </filelist> + </concat> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testFixLastLineActuallyFixesWithFilterChain" + depends="-fixlastline-setup" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=54672"> + <au:assertTrue> + <resourcesmatch> + <string>1${line.separator}2${line.separator}</string> + <concat fixlastline="true"> + <filelist dir="${input}"> + <file name="1"/> + <file name="2"/> + </filelist> + <filterchain> + <tokenfilter> + <ignoreblank/> + </tokenfilter> + </filterchain> + </concat> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testIgnoreEmptyFalseFileIsCreated"> + <mkdir dir="${input}" /> + <mkdir dir="${output}" /> + <concat destfile="${output}/TESTDEST" append="true" ignoreEmpty="false"> + <filelist dir="${input}" files="thisfiledoesnotexist" /> + </concat> + <au:assertFileExists file="${output}/TESTDEST" /> + </target> + + <target name="testIgnoreEmptyTrueFileIsNotCreated"> + <mkdir dir="${input}" /> + <mkdir dir="${output}" /> + <concat destfile="${output}/TESTDEST" append="true" ignoreEmpty="true"> + <filelist dir="${input}" files="thisfiledoesnotexist" /> + </concat> + <au:assertFileDoesntExist file="${output}/TESTDEST" /> + </target> + + <target name="testIgnoreEmptyFalseFileIsCreatedIncludesHeader"> + <mkdir dir="${input}" /> + <mkdir dir="${output}" /> + <concat destfile="${output}/TESTDEST" ignoreEmpty="false"> + <filelist dir="${input}" files="thisfiledoesnotexist" /> + <header filtering="false" trim="yes"> + header + </header> + </concat> + <au:assertFileExists file="${output}/TESTDEST" /> + <au:assertResourceContains resource="${output}/TESTDEST" value="header" /> + </target> + + <target name="testIgnoreEmptyFalseFileIsCreatedIncludesFooter"> + <mkdir dir="${input}" /> + <mkdir dir="${output}" /> + <concat destfile="${output}/TESTDEST" ignoreEmpty="false"> + <filelist dir="${input}" files="thisfiledoesnotexist" /> + <footer filtering="no">footer</footer> + </concat> + <au:assertFileExists file="${output}/TESTDEST" /> + <au:assertResourceContains resource="${output}/TESTDEST" value="footer" /> + </target> + + <target name="testResources"> + <string id="s1">The Quick Brown Fox</string> + <string id="s2">Jumped Over The Lazy Dog.</string> + + <concat destfile="concat.resources" binary="true"> + <resource refid="s1" /> + <resource refid="s2" /> + </concat> + <length property="expected"> + <resources> + <resource refid="s1" /> + <resource refid="s2" /> + </resources> + </length> + <length property="actual"> + <file file="concat.resources" /> + </length> + <fail> + <condition> + <or> + <equals arg1="${actual}" arg2="0" /> + <not> + <equals arg1="${actual}" arg2="${expected}" /> + </not> + </or> + </condition> + </fail> + </target> + + <target name="testBug48816"> + <concat> + <resources id="48816" /> + <string value="x" /> + </concat> + <au:assertTrue> + <resourcecount refid="48816" count="0" /> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/antversion-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/antversion-test.xml new file mode 100644 index 00000000..89c2d7eb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/antversion-test.xml @@ -0,0 +1,70 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="antversion-test" default="all" basedir="." xmlns:au="antlib:org.apache.ant.antunit"> + + <target name="test-atleast"> + <au:assertTrue message="Expected antversion of ${ant.version} to be at least 1.7.0"> + <!-- AntVersion was introduced like AntUnit in 1.7 - so this must be true --> + <antversion atleast="1.7.0" /> + </au:assertTrue> + </target> + + <target name="test-exactly"> + <antversion property="ant.actual.version" /> + <au:assertTrue message="Expected antversion of ${ant.actual.version}"> + <antversion exactly="${ant.actual.version}" /> + </au:assertTrue> + </target> + + <target name="test-atleast-fail"> + <property name="version" value="1.8.9" /> + <au:assertFalse> + <antversion atleast="1.1000.0" /> + </au:assertFalse> + </target> + + <target name="test-task"> + <antversion property="antversion" /> + <au:assertPropertySet name="antversion" message="Property 'antversion' should be set." /> + <echo>AntVersion=${antversion}</echo> + </target> + + <target name="test-property-conditional1"> + <antversion property="antversion" atleast="2.0.0" /> + <au:assertTrue message="Property 'antversion' should not be set because this is not Ant 2.0.0+."> + <not> + <isset property="antversion" /> + </not> + </au:assertTrue> + </target> + + <target name="test-property-conditional2"> + <antversion property="antversion" atleast="1.7.0" /> + <au:assertTrue message="Property 'antversion' should be set because we should have Ant 1.7.0+ (${ant.version})."> + <isset property="antversion" /> + </au:assertTrue> + </target> + + <target name="all"> + <au:antunit> + <fileset file="${ant.file}" /> + <au:plainlistener /> + </au:antunit> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/equals-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/equals-test.xml new file mode 100644 index 00000000..8888d396 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/equals-test.xml @@ -0,0 +1,80 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="equals-test" xmlns:au="antlib:org.apache.ant.antunit" + default="antunit"> + + <import file="../../antunit-base.xml" /> + + <target name="test-noforcestring"> + <string id="s" value="foo" /> + <au:assertFalse> + <equals arg1="foo" arg2="${ant.refid:s}" /> + </au:assertFalse> + </target> + + <target name="test-forcestring"> + <string id="s" value="foo" /> + <au:assertTrue> + <equals arg1="foo" arg2="${ant.refid:s}" forcestring="true" /> + </au:assertTrue> + </target> + + <target name="test-forcestring-notrim"> + <string id="s" value=" foo " /> + <au:assertFalse> + <equals arg1="foo" arg2="${ant.refid:s}" forcestring="true" /> + </au:assertFalse> + </target> + + <target name="test-forcestring-trim"> + <string id="s" value=" foo " /> + <au:assertTrue> + <equals arg1="foo" arg2="${ant.refid:s}" forcestring="true" trim="true" /> + </au:assertTrue> + </target> + + <target name="test-forcestring-cs"> + <string id="s" value="Foo" /> + <au:assertFalse> + <equals arg1="foo" arg2="${ant.refid:s}" forcestring="true" /> + </au:assertFalse> + </target> + + <target name="test-forcestring-nocs"> + <string id="s" value="Foo" /> + <au:assertTrue> + <equals arg1="foo" arg2="${ant.refid:s}" forcestring="true" casesensitive="false" /> + </au:assertTrue> + </target> + + <target name="test-forcestring-trim-cs"> + <string id="s" value=" Foo " /> + <au:assertFalse> + <equals arg1="foo" arg2="${ant.refid:s}" forcestring="true" trim="true" /> + </au:assertFalse> + </target> + + <target name="test-forcestring-trim-nocs"> + <string id="s" value=" Foo " /> + <au:assertTrue> + <equals arg1="foo" arg2="${ant.refid:s}" forcestring="true" + trim="true" casesensitive="false" /> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/filesmatch-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/filesmatch-test.xml new file mode 100644 index 00000000..67e7c00f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/filesmatch-test.xml @@ -0,0 +1,57 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}"/> + </target> + + <target name="testMatchWithSmallerFile2" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=48715" + depends="setUp"> + <property name="file1" location="${input}/LS.properties"/> + <property name="file2" location="${input}/LS.properties.old"/> + <echo file="${file1}"><![CDATA[foo=foo +bar=bar + +]]></echo> + <echo file="${file2}"><![CDATA[foo=foo +]]></echo> + <au:assertFalse> + <filesmatch file1="${file1}" file2="${file2}" textfile="true"/> + </au:assertFalse> + </target> + + <target name="testBinaryMatchWithSmallerFile2" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=48715" + depends="setUp"> + <property name="file1" location="${input}/LS.properties"/> + <property name="file2" location="${input}/LS.properties.old"/> + <echo file="${file1}"><![CDATA[foo=foo +bar=bar + +]]></echo> + <echo file="${file2}"><![CDATA[foo=foo +]]></echo> + <au:assertFalse> + <filesmatch file1="${file1}" file2="${file2}" textfile="false"/> + </au:assertFalse> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/hasfreespace-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/hasfreespace-test.xml new file mode 100644 index 00000000..01f18098 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/hasfreespace-test.xml @@ -0,0 +1,57 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="hasfreespace-test" default="all" basedir="." xmlns:au="antlib:org.apache.ant.antunit"> + + <available property="jdk6.available" classname="java.util.ServiceLoader" /> + + <property name="partition" value="${user.home}" /> + + + <target name="test-not-enough-space-human" if="jdk6.available"> + <au:assertFalse> + <hasfreespace partition="${partition}" needed="1P" /> + </au:assertFalse> + </target> + + <target name="test-enough-space-human" if="jdk6.available"> + <au:assertTrue> + <hasfreespace partition="${partition}" needed="1K" /> + </au:assertTrue> + </target> + + <target name="test-not-enough-space" if="jdk6.available"> + <property name="long.max-value" value="9223372036854775807" /> + <au:assertFalse> + <hasfreespace partition="${partition}" needed="${long.max-value}" /> + </au:assertFalse> + </target> + + <target name="test-enough-space" if="jdk6.available"> + <au:assertTrue> + <hasfreespace partition="${partition}" needed="1" /> + </au:assertTrue> + </target> + + <target name="all"> + <au:antunit> + <fileset file="${ant.file}" /> + <au:plainlistener /> + </au:antunit> + </target> + +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/hasmethod-text.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/hasmethod-text.xml new file mode 100644 index 00000000..9ae9b323 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/hasmethod-text.xml @@ -0,0 +1,63 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="equals-test" xmlns:au="antlib:org.apache.ant.antunit" + default="antunit"> + + <import file="../../antunit-base.xml" /> + + <target name="test-missingclass"> + <au:expectfailure + expectedMessage='class "org.example.somepackage.Foo" was not found'> + <condition property="foo"> + <hasmethod classname="org.example.somepackage.Foo" + method="bar"/> + </condition> + </au:expectfailure> + </target> + + <target name="test-missingclass-no-sysclasspath"> + <au:expectfailure + expectedMessage='class "org.example.somepackage.Foo" was not found'> + <condition property="foo"> + <hasmethod classname="org.example.somepackage.Foo" + ignoreSystemClasses="true" + method="bar"/> + </condition> + </au:expectfailure> + </target> + + <target name="test-restricted-class"> + <au:assertFalse> + <hasmethod classname="java.lang.String" + method="bar"/> + </au:assertFalse> + </target> + + <target name="test-restricted-class-no-sysclasspath"> + <au:expectfailure + expectedMessage='class "java.lang.String" was found but a SecurityException has been raised while loading it'> + <condition property="foo"> + <hasmethod classname="java.lang.String" + classpath="${java.home}/lib/rt.jar" + ignoreSystemClasses="true" + method="bar"/> + </condition> + </au:expectfailure> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/islastmodified-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/islastmodified-test.xml new file mode 100644 index 00000000..429e3f81 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/islastmodified-test.xml @@ -0,0 +1,118 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit" + xmlns:cond="antlib:org.apache.tools.ant.types.conditions"> + + <import file="../../antunit-base.xml"/> + + <target name="setUp"> + <mkdir dir="${output}"/> + <property name="file" location="${output}/test.txt"/> + <touch file="${file}" dateTime="08/18/2009 04:41:20 AM"/> + </target> + + <target name="testEquals" depends="setUp"> + <au:assertFalse> + <cond:islastmodified dateTime="08/18/2009 04:41:19 AM"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertFalse> + <au:assertTrue> + <cond:islastmodified dateTime="08/18/2009 04:41:20 AM"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertTrue> + <au:assertFalse> + <cond:islastmodified dateTime="08/18/2009 04:41:21 AM"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertFalse> + </target> + + <target name="testBefore" depends="setUp"> + <au:assertFalse> + <cond:islastmodified dateTime="08/18/2009 04:41:19 AM" mode="before"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertFalse> + <au:assertFalse> + <cond:islastmodified dateTime="08/18/2009 04:41:20 AM" mode="before"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertFalse> + <au:assertTrue> + <cond:islastmodified dateTime="08/18/2009 04:41:21 AM" mode="before"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertTrue> + </target> + + <target name="testAfter" depends="setUp"> + <au:assertTrue> + <cond:islastmodified dateTime="08/18/2009 04:41:19 AM" mode="after"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertTrue> + <au:assertFalse> + <cond:islastmodified dateTime="08/18/2009 04:41:20 AM" mode="after"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertFalse> + <au:assertFalse> + <cond:islastmodified dateTime="08/18/2009 04:41:21 AM" mode="after"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertFalse> + </target> + + <target name="testNotBefore" depends="setUp"> + <au:assertTrue> + <cond:islastmodified dateTime="08/18/2009 04:41:19 AM" mode="not-before"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertTrue> + <au:assertTrue> + <cond:islastmodified dateTime="08/18/2009 04:41:20 AM" mode="not-before"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertTrue> + <au:assertFalse> + <cond:islastmodified dateTime="08/18/2009 04:41:21 AM" mode="not-before"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertFalse> + </target> + + <target name="testNotAfter" depends="setUp"> + <au:assertFalse> + <cond:islastmodified dateTime="08/18/2009 04:41:19 AM" mode="not-after"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertFalse> + <au:assertTrue> + <cond:islastmodified dateTime="08/18/2009 04:41:20 AM" mode="not-after"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertTrue> + <au:assertTrue> + <cond:islastmodified dateTime="08/18/2009 04:41:21 AM" mode="not-after"> + <file file="${file}"/> + </cond:islastmodified> + </au:assertTrue> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/resourcecontains-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/resourcecontains-test.xml new file mode 100644 index 00000000..11c6a9ed --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/resourcecontains-test.xml @@ -0,0 +1,139 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="resourcecontains-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../../antunit-base.xml"/> + + <target name="setUp"> + <mkdir dir="${output}"/> + <property name="file" location="${output}/test-resource.txt"/> + <echo file="${file}" message="loads of text!"/> + </target> + + <target name="testcontains"> + <au:assertTrue message="Should have found the text in the resource"> + <resourcecontains resource="${file}" substring="text"/> + </au:assertTrue> + </target> + + <target name="testContainsLowerNonCS"> + <echo file="${file}" message="LOADS OF TEXT!"/> + <au:assertTrue message="Should have found the text in the resource"> + <resourcecontains resource="${file}" substring="text" + casesensitive="false"/> + </au:assertTrue> + </target> + + <target name="testContainsUpperNonCS"> + <au:assertTrue message="Should have found the text in the resource"> + <resourcecontains resource="${file}" substring="TEXT" + casesensitive="false"/> + </au:assertTrue> + </target> + + <target name="testContainsEmptyString"> + <au:assertTrue message="Should have found the text in the resource"> + <resourcecontains resource="${file}" substring="" /> + </au:assertTrue> + </target> + + <target name="testContainsEmptyProperty"> + <property name="testContainsEmptyProperty" value="" /> + <au:assertTrue message="Should have found the text in the resource"> + <resourcecontains resource="${file}" + substring="${testContainsEmptyProperty}" /> + </au:assertTrue> + </target> + + <target name="testwithemptyfile"> + <truncate file="${file}"/> + <au:assertFalse message="Should have found nothing as file is empty"> + <resourcecontains resource="${file}" substring="text"/> + </au:assertFalse> + </target> + + <target name="testWithEmptyFileAndSubstring"> + <truncate file="${file}"/> + <au:assertTrue message="Empty resource should contain empty string"> + <resourcecontains resource="${file}" substring=""/> + </au:assertTrue> + </target> + + <target name="testdoesntcontain"> + <au:assertFalse message="Should have found nothing as file is empty"> + <resourcecontains resource="${file}" substring="futurama"/> + </au:assertFalse> + </target> + + <target name="testFileRefContains"> + <file id="file" file="${file}" /> + <au:assertTrue message="Should have found the text in the resource"> + <resourcecontains refid="file" substring="text"/> + </au:assertTrue> + </target> + + <target name="testStringRefContains"> + <string id="string">loads of text!</string> + <au:assertTrue message="Should have found the text in the resource"> + <resourcecontains refid="string" substring="text"/> + </au:assertTrue> + </target> + + <target name="testTextConcatRefContains"> + <resources id="concat"> + <concat>loads of text!</concat> + </resources> + <au:assertTrue message="Should have found the text in the resource"> + <resourcecontains refid="concat" substring="text"/> + </au:assertTrue> + </target> + + <target name="testFileConcatRefContains"> + <resources id="concat"> + <concat><file file="${file}" /></concat> + </resources> + <au:assertTrue message="Should have found the text in the resource"> + <resourcecontains refid="concat" substring="text"/> + </au:assertTrue> + </target> + + <target name="testMultiConcatRefContains"> + <resources id="concat"> + <concat> + <header>HEADER</header> + <footer>FOOTER</footer> + <string>foo</string> + <file file="${file}" /> + <string>bar</string> + </concat> + </resources> + <au:assertTrue message="Should have found the text in the resource"> + <resourcecontains refid="concat" substring="text"/> + </au:assertTrue> + </target> + + <target name="testFirstRefContains"> + <first id="first"> + <fileset dir="${basedir}" includes="*-test.xml" /> + </first> + <au:assertTrue message="Should have found the text in the resource"> + <resourcecontains refid="first" substring="project"/> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/resourceexists-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/resourceexists-test.xml new file mode 100644 index 00000000..bdf40c2a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/condition/resourceexists-test.xml @@ -0,0 +1,47 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit" + xmlns:cond="antlib:org.apache.tools.ant.types.conditions"> + + <import file="../../antunit-base.xml"/> + + <target name="test-yes"> + <au:assertTrue> + <cond:resourceexists> + <file file="resourceexists-test.xml"/> + </cond:resourceexists> + </au:assertTrue> + </target> + + <target name="test-no"> + <au:assertFalse> + <cond:resourceexists> + <file file="resourceexists-test-not-there.xml"/> + </cond:resourceexists> + </au:assertFalse> + </target> + + <target name="testURL"> + <au:assertTrue> + <cond:resourceexists> + <url url="http://ant.apache.org/index.html"/> + </cond:resourceexists> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/copy-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/copy-test.xml new file mode 100644 index 00000000..51c6277c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/copy-test.xml @@ -0,0 +1,471 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="-fileResourceSetup"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <touch file="${input}/file.txt"/> + </target> + + <target name="testCopyFileFlatten" depends="-fileResourceSetup"> + <au:assertFileDoesntExist file="${output}/file.txt"/> + <copy todir="${output}" flatten="true"> + <file file="${input}/file.txt"/> + </copy> + <au:assertFileExists file="${output}/file.txt"/> + </target> + + <target name="testCopyFileInResourcesFlatten" depends="-fileResourceSetup"> + <au:assertFileDoesntExist file="${output}/file.txt"/> + <copy todir="${output}" flatten="true"> + <resources> + <file file="${input}/file.txt"/> + </resources> + </copy> + <au:assertFileExists file="${output}/file.txt"/> + </target> + + <target name="-setupNullByteStreamResource"> + <mkdir dir="${input}"/> + <echo file="${input}/NullByteStreamResource.java"><![CDATA[ +import org.apache.tools.ant.types.Resource; +import java.io.*; +public class NullByteStreamResource extends Resource { + private long length = 1024; + + public boolean isExists() { + return true; + } + + public long getLastModified() { + return UNKNOWN_DATETIME; + } + + public void setLength(long length) { + this.length = length; + } + + public InputStream getInputStream() { + return new InputStream() { + int readSoFar = 0; + + public int read() { + return readSoFar++ > length ? -1 : 0; + } + }; + } +} +]]></echo> + <mkdir dir="${output}"/> + <javac srcdir="${input}" destdir="${output}"/> + <typedef name="nullstream" classname="NullByteStreamResource"> + <classpath> + <pathelement location="${output}"/> + </classpath> + </typedef> + </target> + + <target name="testResourceWithoutName" + depends="-setupNullByteStreamResource"> + <au:expectfailure> + <copy todir="${output}"> + <nullstream/> + </copy> + </au:expectfailure> + </target> + + <target name="testResourceWithoutNameWithMergeMapper" + depends="-setupNullByteStreamResource"> + <copy todir="${output}"> + <nullstream/> + <mergemapper to="foo"/> + </copy> + <au:assertFileExists file="${output}/foo"/> + </target> + + <target name="testMappedResources"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/foo.txt">Hello, world!</echo> + <copy todir="${output}"> + <mappedresources> + <fileset dir="${input}"/> + <globmapper from="foo.*" to="bar.*"/> + </mappedresources> + </copy> + <au:assertFileDoesntExist file="${output}/foo.txt"/> + <au:assertFileExists file="${output}/bar.txt"/> + <au:assertFilesMatch expected="${input}/foo.txt" + actual="${output}/bar.txt"/> + </target> + + <target name="testMappedResourcesMultipleTrue"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/foo.txt">Hello, world!</echo> + <copy todir="${output}"> + <mappedresources enableMultipleMappings="true"> + <fileset dir="${input}"/> + <compositemapper> + <globmapper from="foo.*" to="bar.*"/> + <globmapper from="foo.*" to="baz.*"/> + </compositemapper> + </mappedresources> + </copy> + <au:assertFileDoesntExist file="${output}/foo.txt"/> + <au:assertFileExists file="${output}/bar.txt"/> + <au:assertFileExists file="${output}/baz.txt"/> + <au:assertFilesMatch expected="${input}/foo.txt" + actual="${output}/bar.txt"/> + <au:assertFilesMatch expected="${input}/foo.txt" + actual="${output}/baz.txt"/> + </target> + + <target name="testMappedResourcesMultipleFalse"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/foo.txt">Hello, world!</echo> + <copy todir="${output}"> + <mappedresources enableMultipleMappings="false"> + <fileset dir="${input}"/> + <compositemapper> + <globmapper from="foo.*" to="bar.*"/> + <globmapper from="foo.*" to="baz.*"/> + </compositemapper> + </mappedresources> + </copy> + <au:assertFileDoesntExist file="${output}/foo.txt"/> + <au:assertFileExists file="${output}/bar.txt"/> + <au:assertFileDoesntExist file="${output}/baz.txt"/> + <au:assertFilesMatch expected="${input}/foo.txt" + actual="${output}/bar.txt"/> + </target> + + <target name="testIncludeEmptyDirsDefaultsToTrue" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47168"> + <mkdir dir="${input}/foo"/> + <mkdir dir="${output}"/> + <copy todir="${output}"> + <fileset dir="${input}"/> + </copy> + <au:assertFileExists file="${output}/foo"/> + </target> + + <target name="XtestIncludeEmptyDirsAndZipfileset" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47168"> + <mkdir dir="${input}/foo"/> + <mkdir dir="${output}/final"/> + <zip destfile="${output}/zipfile.zip"> + <fileset dir="${input}"/> + </zip> + <copy todir="${output}/final"> + <zipfileset src="${output}/zipfile.zip"/> + </copy> + <au:assertFileExists file="${output}/final/foo"/> + </target> + + <target name="testFailOnURLConnectionError" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47362"> + <mkdir dir="${output}"/> + <au:expectfailure> + <copy todir="${output}" failonerror="true" flatten="true"> + <resources> + <url url="http://i-do-not-exist/"/> + </resources> + </copy> + </au:expectfailure> + </target> + + <target name="testNotModifiedSelector" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=43574" + > + <mkdir dir="${input}/images"/> + <mkdir dir="${input}/cache"/> + <touch file="${input}/images/foo.jpg"/> + <mkdir dir="${output}"/> + <selector id="cache.selector"> + <not> + <modified update="true" + seldirs="false" + cache="propertyfile" + algorithm="digest" + comparator="equal"> + <param name="cache.cachefile" + value="${input}/cache/cache.properties"/> + <param name="algorithm.algorithm" value="MD5"/> + </modified> + </not> + </selector> + <au:assertFileDoesntExist file="${input}/cache/cache.properties"/> + <copy todir="${output}" overwrite="true"> + <fileset dir="${input}/images"> + <include name="*.jpg" /> + <selector refid="cache.selector" /> + </fileset> + </copy> + <au:assertFileExists file="${input}/cache/cache.properties"/> + <au:assertFileDoesntExist file="${output}/foo.jpg"/> + <copy todir="${output}" overwrite="true"> + <fileset dir="${input}/images"> + <include name="*.jpg" /> + <selector refid="cache.selector" /> + </fileset> + </copy> + <au:assertFileExists file="${output}/foo.jpg"/> + </target> + + <target name="testMissingFileUsingFileAttribute"> + <mkdir dir="${output}"/> + <mkdir dir="${input}"/> + <au:expectfailure expectedMessage="Could not find file"> + <copy file="${input}/not-there.txt" todir="${output}"/> + </au:expectfailure> + <copy file="${input}/not-there.txt" todir="${output}" + failonerror="false"/> + </target> + + <target name="testQuiet"> + <mkdir dir="${output}"/> + <mkdir dir="${input}"/> + <copy file="${input}/not-there.txt" todir="${output}" failonerror="false" quiet="true" /> + <au:assertLogDoesntContain text="Could not find file" /> + </target> + + <target name="testMissingFilesetRoot"> + <mkdir dir="${output}"/> + <au:expectfailure expectedMessage="does not exist"> + <copy todir="${output}"> + <fileset dir="${input}"> + <include name="not-there.txt"/> + </fileset> + </copy> + </au:expectfailure> + <copy todir="${output}" failonerror="false"> + <fileset dir="${input}"> + <include name="not-there.txt"/> + </fileset> + </copy> + </target> + + <target name="testMissingFileUsingFilesetInclude" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49070"> + <mkdir dir="${output}"/> + <mkdir dir="${input}"/> + <au:expectfailure + expectedMessage="Cannot perform operation from directory to file."> + <copy tofile="${output}/foo.txt"> + <fileset dir="${input}"> + <include name="not-there.txt"/> + </fileset> + </copy> + </au:expectfailure> + <copy tofile="${output}/foo.txt" failonerror="false"> + <fileset dir="${input}"> + <include name="not-there.txt"/> + </fileset> + </copy> + </target> + + <target name="testMissingFileUsingFilesetFilename" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49070"> + <mkdir dir="${output}"/> + <mkdir dir="${input}"/> + <au:expectfailure + expectedMessage="Cannot perform operation from directory to file."> + <copy tofile="${output}/foo.txt"> + <fileset dir="${input}"> + <filename name="not-there.txt"/> + </fileset> + </copy> + </au:expectfailure> + <copy tofile="${output}/foo.txt" failonerror="false"> + <fileset dir="${input}"> + <filename name="not-there.txt"/> + </fileset> + </copy> + </target> + + <!-- stolen from ../types/readwrite-test.xml - create a read-only file --> + <property name="file" value="testfile"/> + <condition property="unix"> + <os family="unix"/> + </condition> + <target name="createTestdir"> + <mkdir dir="${output}"/> + <mkdir dir="${input}"/> + <touch file="${output}/${file}"/> + </target> + <target name="makeFileUnwritable" + depends="createTestdir,makeFileUnwritable-Unix,makeFileUnwritable-Windows"/> + <target name="makeFileUnwritable-Unix" id="unix"> + <chmod file="${output}/${file}" perm="444"/> + </target> + <target name="makeFileUnwritable-Windows" unless="unix"> + <attrib file="${output}/${file}" readonly="true"/> + </target> + + <target name="testCopyOverReadOnlyFile" depends="makeFileUnwritable"> + <sleep seconds="2"/> + <touch file="${input}/${file}"/> + <au:expectfailure + expectedMessage="can't write to read-only destination file "> + <copy toDir="${output}"> + <fileset dir="${input}"/> + </copy> + </au:expectfailure> + </target> + + <target name="testFilteredCopyOverReadOnlyFile" depends="makeFileUnwritable"> + <sleep seconds="2"/> + <touch file="${input}/${file}"/> + <au:expectfailure + expectedMessage="can't write to read-only destination file "> + <copy toDir="${output}"> + <fileset dir="${input}"/> + <filterset> + <filter token="foo" value="bar"/> + </filterset> + </copy> + </au:expectfailure> + </target> + + <target name="testCopyOverReadOnlyFileWithOverwrite" + depends="makeFileUnwritable"> + <touch file="${input}/${file}"/> + <au:expectfailure + expectedMessage="can't write to read-only destination file "> + <copy toDir="${output}" overwrite="true"> + <fileset dir="${input}"/> + </copy> + </au:expectfailure> + </target> + + <target name="testFilteredCopyOverReadOnlyFileWithOverwrite" + depends="makeFileUnwritable"> + <touch file="${input}/${file}"/> + <au:expectfailure + expectedMessage="can't write to read-only destination file "> + <copy toDir="${output}" overwrite="true"> + <fileset dir="${input}"/> + <filterset> + <filter token="foo" value="bar"/> + </filterset> + </copy> + </au:expectfailure> + </target> + + <target name="testForcedCopyOverReadOnlyFile" depends="makeFileUnwritable"> + <sleep seconds="2"/> + <touch file="${input}/${file}"/> + <copy toDir="${output}" force="true"> + <fileset dir="${input}"/> + </copy> + </target> + + <target name="testForcedFilteredCopyOverReadOnlyFile" + depends="makeFileUnwritable"> + <sleep seconds="2"/> + <touch file="${input}/${file}"/> + <copy toDir="${output}" force="true"> + <fileset dir="${input}"/> + <filterset> + <filter token="foo" value="bar"/> + </filterset> + </copy> + </target> + + <target name="testForcedCopyOverReadOnlyFileWithOverwrite" + depends="makeFileUnwritable"> + <touch file="${input}/${file}"/> + <copy toDir="${output}" overwrite="true" force="true"> + <fileset dir="${input}"/> + </copy> + </target> + + <target name="testForcedFilteredCopyOverReadOnlyFileWithOverwrite" + depends="makeFileUnwritable"> + <touch file="${input}/${file}"/> + <copy toDir="${output}" overwrite="true" force="true"> + <fileset dir="${input}"/> + <filterset> + <filter token="foo" value="bar"/> + </filterset> + </copy> + </target> + + <target name="testCopyWithResourceAndFile" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49756" + > + <mkdir dir="${input}"/> + <au:assertFileDoesntExist file="${input}/somefile"/> + <copy tofile="${input}/somefile"> + <first> + <union> + <restrict> + <exists/> + <fileset file="${input}/somefile"/> + </restrict> + <string value="default contents"/> + </union> + </first> + </copy> + <au:assertFileExists file="${input}/somefile"/> + <au:assertResourceContains resource="${input}/somefile" + value="default contents"/> + <delete file="${input}/somefile"/> + <touch file="${input}/somefile"/> + <copy tofile="${input}/somefile"> + <first> + <union> + <restrict> + <exists/> + <fileset file="${input}/somefile"/> + </restrict> + <string value="default contents"/> + </union> + </first> + </copy> + <au:assertFileExists file="${input}/somefile"/> + <au:assertResourceDoesntContain resource="${input}/somefile" + value="default contents"/> + </target> + + <target name="testCopyDoesntDeleteReadonlyTargetWhenCopyFails" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=53095"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <touch file="${input}/somefile"/> + <touch file="${output}/somefile"/> + <exec executable="chmod" osfamily="unix"> + <arg value="-w"/> + <arg file="${output}/somefile"/> + </exec> + <exec executable="attrib" osfamily="dos"> + <arg value="+r"/> + <arg file="${output}/somefile"/> + </exec> + <au:expectfailure> + <copy todir="${output}" file="${input}/somefile" + overwrite="true"/> + </au:expectfailure> + <au:assertFileExists file="${input}/somefile"/> + <au:assertFileExists file="${output}/somefile"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/cvs.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/cvs.xml new file mode 100644 index 00000000..564e5875 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/cvs.xml @@ -0,0 +1,169 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<!-- this file is not executed by the automated tests since it + requires a working CVS client. --> + +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../antunit-base.xml" /> + + <property name="cvsrootloc" location="repository"/> + <property name="cvsroot" value=":local:${cvsrootloc}"/> + + <target name="testVersion"> + <cvsversion clientversionproperty="client" cvsroot="${cvsroot}"/> + <au:assertPropertySet name="client"/> + </target> + + <target name="testBug38583"> + <mkdir dir="${output}"/> + <cvs cvsroot="${cvsroot}" package="antmodule1" dest="${output}"/> + <cvschangelog dir="${output}/antmodule1" + destfile="${output}/report.xml"/> + <au:assertFileExists file="${output}/report.xml"/> + </target> + + <target name="testRemoteChangelog"> + <mkdir dir="${output}"/> + <cvschangelog cvsroot="${cvsroot}" package="antmodule3" + remote="true" + destfile="${output}/report.xml"/> + <au:assertFileExists file="${output}/report.xml"/> + <au:assertResourceContains resource="${output}/report.xml" + value="[yet another test.txt]"/> + </target> + + <target name="testRemoteChangelogNestedModule"> + <mkdir dir="${output}"/> + <cvschangelog cvsroot="${cvsroot}" + remote="true" + destfile="${output}/report.xml"> + <module name="antmodule3"/> + </cvschangelog> + <au:assertFileExists file="${output}/report.xml"/> + <au:assertResourceContains resource="${output}/report.xml" + value="[yet another test.txt]"/> + </target> + + <target name="xtestRemoteChangelogStartTag"> + <mkdir dir="${output}"/> + <cvschangelog cvsroot="${cvsroot}" + remote="true" startTag="testtag1" + destfile="${output}/report.xml"> + <module name="antmodule3"/> + </cvschangelog> + <au:assertFileExists file="${output}/report.xml"/> + <au:assertResourceContains resource="${output}/report.xml" + value="[yet another test.txt]"/> + </target> + + <target name="testRemoteChangelogEndTag"> + <mkdir dir="${output}"/> + <cvschangelog cvsroot="${cvsroot}" + remote="true" endTag="testtag2" + destfile="${output}/report.xml"> + <module name="antmodule3"/> + </cvschangelog> + <au:assertFileExists file="${output}/report.xml"/> + <au:assertResourceContains resource="${output}/report.xml" + value="[yet another test.txt]"/> + </target> + + <target name="testRemoteChangelogWithTags"> + <mkdir dir="${output}"/> + <cvschangelog cvsroot="${cvsroot}" + remote="true" endTag="testtag2" startTag="testtag1" + destfile="${output}/report.xml"> + <module name="antmodule3"/> + </cvschangelog> + <au:assertFileExists file="${output}/report.xml"/> + <au:assertResourceContains resource="${output}/report.xml" + value="[yet another test.txt]"/> + </target> + + <target name="xtestLocalChangelogStartTag"> + <mkdir dir="${output}"/> + <cvs cvsroot="${cvsroot}" package="antmodule3" dest="${output}"/> + <cvschangelog dir="${output}/antmodule3" + remote="false" startTag="testtag1" + destfile="${output}/report.xml"/> + <au:assertFileExists file="${output}/report.xml"/> + <au:assertResourceContains resource="${output}/report.xml" + value="[yet another test.txt]"/> + </target> + + <target name="testLocalChangelogEndTag"> + <mkdir dir="${output}"/> + <cvs cvsroot="${cvsroot}" package="antmodule3" dest="${output}"/> + <cvschangelog dir="${output}/antmodule3" + remote="false" endTag="testtag2" + destfile="${output}/report.xml"/> + <au:assertFileExists file="${output}/report.xml"/> + <au:assertResourceContains resource="${output}/report.xml" + value="[yet another test.txt]"/> + </target> + + <target name="testLocalChangelogWithTags"> + <mkdir dir="${output}"/> + <cvs cvsroot="${cvsroot}" package="antmodule3" dest="${output}"/> + <cvschangelog dir="${output}/antmodule3" + remote="false" endTag="testtag2" startTag="testtag1" + destfile="${output}/report.xml"/> + <au:assertFileExists file="${output}/report.xml"/> + <au:assertResourceContains resource="${output}/report.xml" + value="[yet another test.txt]"/> + </target> + + <target name="testCvsWithSpaceInModule"> + <mkdir dir="${output}"/> + <cvs cvsroot="${cvsroot}" dest="${output}"> + <module name="ant module 2"/> + </cvs> + <au:assertFileExists file="${output}/ant module 2/test.txt"/> + <cvschangelog dir="${output}/ant module 2" + destfile="${output}/report.xml"/> + <au:assertFileExists file="${output}/report.xml"/> + </target> + + <target name="testCvsTagDiffWithSpaceInModule"> + <mkdir dir="${output}"/> + <cvstagdiff cvsroot="${cvsroot}" + startDate="2008-01-01" + endDate="2009-01-01" + destfile="${output}/tagdiff.xml"> + <module name="ant module 2"/> + </cvstagdiff> + <au:assertFileExists file="${output}/tagdiff.xml"/> + <au:assertResourceContains resource="${output}/tagdiff.xml" + value="[test.txt]"/> + </target> + + <target name="testCvsTagDiffWithMultipleModules"> + <mkdir dir="${output}"/> + <cvstagdiff cvsroot="${cvsroot}" + startDate="2008-01-01" + endDate="2009-01-01" + destfile="${output}/tagdiff.xml" + package="antmodule1 antmodule3"/> + <au:assertFileExists file="${output}/tagdiff.xml"/> + <au:assertResourceContains resource="${output}/tagdiff.xml" + value="[foo.txt]"/> + <au:assertResourceContains resource="${output}/tagdiff.xml" + value="[yet another test.txt]"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/checkoutlist b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/checkoutlist new file mode 100644 index 00000000..2921bffc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/checkoutlist @@ -0,0 +1,13 @@ +# The "checkoutlist" file is used to support additional version controlled +# administrative files in $CVSROOT/CVSROOT, such as template files. +# +# The first entry on a line is a filename which will be checked out from +# the corresponding RCS file in the $CVSROOT/CVSROOT directory. +# The remainder of the line is an error message to use if the file cannot +# be checked out. +# +# File format: +# +# [<whitespace>]<filename>[<whitespace><error message>]<end-of-line> +# +# comment lines begin with '#' diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/checkoutlist,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/checkoutlist,v new file mode 100644 index 00000000..4f0410b6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/checkoutlist,v @@ -0,0 +1,37 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# The "checkoutlist" file is used to support additional version controlled +# administrative files in $CVSROOT/CVSROOT, such as template files. +# +# The first entry on a line is a filename which will be checked out from +# the corresponding RCS file in the $CVSROOT/CVSROOT directory. +# The remainder of the line is an error message to use if the file cannot +# be checked out. +# +# File format: +# +# [<whitespace>]<filename>[<whitespace><error message>]<end-of-line> +# +# comment lines begin with '#' +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/commitinfo b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/commitinfo new file mode 100644 index 00000000..3903ceec --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/commitinfo @@ -0,0 +1,26 @@ +# The "commitinfo" file is used to control pre-commit checks. +# The filter on the right is invoked with the repository and a list +# of files to check. A non-zero exit of the filter program will +# cause the commit to be aborted. +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# Format strings present in the filter will be replaced as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# %{s} = file name, file name, ... +# +# If no format strings are present in the filter string, a default of +# " %r %s" will be appended to the filter string, but this usage is +# deprecated. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/commitinfo,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/commitinfo,v new file mode 100644 index 00000000..7cc0771c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/commitinfo,v @@ -0,0 +1,50 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# The "commitinfo" file is used to control pre-commit checks. +# The filter on the right is invoked with the repository and a list +# of files to check. A non-zero exit of the filter program will +# cause the commit to be aborted. +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# Format strings present in the filter will be replaced as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# %{s} = file name, file name, ... +# +# If no format strings are present in the filter string, a default of +# " %r %s" will be appended to the filter string, but this usage is +# deprecated. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/config b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/config new file mode 100644 index 00000000..50d85b5f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/config @@ -0,0 +1,97 @@ +# Set `SystemAuth' to `no' if pserver shouldn't check system users/passwords. +#SystemAuth=no + +# Set `LocalKeyword' to specify a local alias for a standard keyword. +#LocalKeyword=MYCVS=CVSHeader + +# Set `KeywordExpand' to `i' followed by a list of keywords to expand or +# `e' followed by a list of keywords to not expand. +#KeywordExpand=iMYCVS,Name,Date +#KeywordExpand=eCVSHeader + +# Set `TopLevelAdmin' to `yes' to create a CVS directory at the top +# level of the new working directory when using the `cvs checkout' +# command. +#TopLevelAdmin=no + +# Put CVS lock files in this directory rather than directly in the repository. +#LockDir=/var/lock/cvs + +# Set `LogHistory' to `all' or `TOEFWUPCGMAR' to log all transactions to the +# history file, or a subset as needed (ie `TMAR' logs all write operations) +#LogHistory=TOEFWUPCGMAR + +# Set `RereadLogAfterVerify' to `always' (the default) to allow the verifymsg +# script to change the log message. Set it to `stat' to force CVS to verify +# that the file has changed before reading it (this can take up to an extra +# second per directory being committed, so it is not recommended for large +# repositories. Set it to `never' (the previous CVS behavior) to prevent +# verifymsg scripts from changing the log message. +#RereadLogAfterVerify=always + +# Set `UserAdminOptions' to the list of `cvs admin' commands (options) +# that users not in the `cvsadmin' group are allowed to run. This +# defaults to `k', or only allowing the changing of the default +# keyword expansion mode for files for users not in the `cvsadmin' group. +# This value is ignored if the `cvsadmin' group does not exist. +# +# The following string would enable all `cvs admin' commands for all +# users: +#UserAdminOptions=aAbceIklLmnNostuU + +# Set `UseNewInfoFmtStrings' to `no' if you must support a legacy system by +# enabling the deprecated old style info file command line format strings. +# Be warned that these strings could be disabled in any new version of CVS. +UseNewInfoFmtStrings=yes + +# Set `ImportNewFilesToVendorBranchOnly' to `yes' if you wish to force +# every `cvs import' command to behave as if the `-X' flag was +# specified. +#ImportNewFilesToVendorBranchOnly=no + +# Set `PrimaryServer' to the CVSROOT to the primary, or write, server when +# establishing one or more read-only mirrors which serve as proxies for +# the write server in write mode or redirect the client to the primary for +# write requests. +# +# For example: +# +# PrimaryServer=:fork:localhost/cvsroot + +# Set `MaxProxyBufferSize' to the the maximum allowable secondary +# buffer memory cache size before the buffer begins being stored to disk, in +# bytes. Must be a positive integer but may end in `k', `M', `G', or `T' (for +# kiilo, mega, giga, & tera, respectively). If an otherwise valid number you +# specify is greater than the SIZE_MAX defined by your system's C compiler, +# then it will be resolved to SIZE_MAX without a warning. Defaults to 8M (8 +# megabytes). +# +# High values for MaxProxyBufferSize may speed up a secondary server +# with old hardware and a lot of available memory but can actually slow a +# modern system down slightly. +# +# For example: +# +# MaxProxyBufferSize=1G + +# Set `MaxCommentLeaderLength' to the maximum length permitted for the +# automagically determined comment leader used when expanding the Log +# keyword, in bytes. CVS's behavior when the automagically determined +# comment leader exceeds this length is dependant on the value of +# `UseArchiveCommentLeader' set in this file. `unlimited' is a valid +# setting for this value. Defaults to 20 bytes. +# +# For example: +# +# MaxCommentLeaderLength=20 + +# Set `UseArchiveCommentLeader' to `yes' to cause CVS to fall back on +# the comment leader set in the RCS archive file, if any, when the +# automagically determined comment leader exceeds `MaxCommentLeaderLength' +# bytes. If `UseArchiveCommentLeader' is not set and a comment leader +# greater than `MaxCommentLeaderLength' is calculated, the Log keyword +# being examined will not be expanded. Defaults to `no'. +# +# For example: +# +# UseArchiveCommentLeader=no diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/config,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/config,v new file mode 100644 index 00000000..d220b452 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/config,v @@ -0,0 +1,121 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# Set `SystemAuth' to `no' if pserver shouldn't check system users/passwords. +#SystemAuth=no + +# Set `LocalKeyword' to specify a local alias for a standard keyword. +#LocalKeyword=MYCVS=CVSHeader + +# Set `KeywordExpand' to `i' followed by a list of keywords to expand or +# `e' followed by a list of keywords to not expand. +#KeywordExpand=iMYCVS,Name,Date +#KeywordExpand=eCVSHeader + +# Set `TopLevelAdmin' to `yes' to create a CVS directory at the top +# level of the new working directory when using the `cvs checkout' +# command. +#TopLevelAdmin=no + +# Put CVS lock files in this directory rather than directly in the repository. +#LockDir=/var/lock/cvs + +# Set `LogHistory' to `all' or `TOEFWUPCGMAR' to log all transactions to the +# history file, or a subset as needed (ie `TMAR' logs all write operations) +#LogHistory=TOEFWUPCGMAR + +# Set `RereadLogAfterVerify' to `always' (the default) to allow the verifymsg +# script to change the log message. Set it to `stat' to force CVS to verify +# that the file has changed before reading it (this can take up to an extra +# second per directory being committed, so it is not recommended for large +# repositories. Set it to `never' (the previous CVS behavior) to prevent +# verifymsg scripts from changing the log message. +#RereadLogAfterVerify=always + +# Set `UserAdminOptions' to the list of `cvs admin' commands (options) +# that users not in the `cvsadmin' group are allowed to run. This +# defaults to `k', or only allowing the changing of the default +# keyword expansion mode for files for users not in the `cvsadmin' group. +# This value is ignored if the `cvsadmin' group does not exist. +# +# The following string would enable all `cvs admin' commands for all +# users: +#UserAdminOptions=aAbceIklLmnNostuU + +# Set `UseNewInfoFmtStrings' to `no' if you must support a legacy system by +# enabling the deprecated old style info file command line format strings. +# Be warned that these strings could be disabled in any new version of CVS. +UseNewInfoFmtStrings=yes + +# Set `ImportNewFilesToVendorBranchOnly' to `yes' if you wish to force +# every `cvs import' command to behave as if the `-X' flag was +# specified. +#ImportNewFilesToVendorBranchOnly=no + +# Set `PrimaryServer' to the CVSROOT to the primary, or write, server when +# establishing one or more read-only mirrors which serve as proxies for +# the write server in write mode or redirect the client to the primary for +# write requests. +# +# For example: +# +# PrimaryServer=:fork:localhost/cvsroot + +# Set `MaxProxyBufferSize' to the the maximum allowable secondary +# buffer memory cache size before the buffer begins being stored to disk, in +# bytes. Must be a positive integer but may end in `k', `M', `G', or `T' (for +# kiilo, mega, giga, & tera, respectively). If an otherwise valid number you +# specify is greater than the SIZE_MAX defined by your system's C compiler, +# then it will be resolved to SIZE_MAX without a warning. Defaults to 8M (8 +# megabytes). +# +# High values for MaxProxyBufferSize may speed up a secondary server +# with old hardware and a lot of available memory but can actually slow a +# modern system down slightly. +# +# For example: +# +# MaxProxyBufferSize=1G + +# Set `MaxCommentLeaderLength' to the maximum length permitted for the +# automagically determined comment leader used when expanding the Log +# keyword, in bytes. CVS's behavior when the automagically determined +# comment leader exceeds this length is dependant on the value of +# `UseArchiveCommentLeader' set in this file. `unlimited' is a valid +# setting for this value. Defaults to 20 bytes. +# +# For example: +# +# MaxCommentLeaderLength=20 + +# Set `UseArchiveCommentLeader' to `yes' to cause CVS to fall back on +# the comment leader set in the RCS archive file, if any, when the +# automagically determined comment leader exceeds `MaxCommentLeaderLength' +# bytes. If `UseArchiveCommentLeader' is not set and a comment leader +# greater than `MaxCommentLeaderLength' is calculated, the Log keyword +# being examined will not be expanded. Defaults to `no'. +# +# For example: +# +# UseArchiveCommentLeader=no +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/cvswrappers b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/cvswrappers new file mode 100644 index 00000000..e989b754 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/cvswrappers @@ -0,0 +1,19 @@ +# This file affects handling of files based on their names. +# +# The -m option specifies whether CVS attempts to merge files. +# +# The -k option specifies keyword expansion (e.g. -kb for binary). +# +# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers) +# +# wildcard [option value][option value]... +# +# where option is one of +# -f from cvs filter value: path to filter +# -t to cvs filter value: path to filter +# -m update methodology value: MERGE or COPY +# -k expansion mode value: b, o, kkv, &c +# +# and value is a single-quote delimited value. +# For example: +#*.gif -k 'b' diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/cvswrappers,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/cvswrappers,v new file mode 100644 index 00000000..00bd795c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/cvswrappers,v @@ -0,0 +1,43 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# This file affects handling of files based on their names. +# +# The -m option specifies whether CVS attempts to merge files. +# +# The -k option specifies keyword expansion (e.g. -kb for binary). +# +# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers) +# +# wildcard [option value][option value]... +# +# where option is one of +# -f from cvs filter value: path to filter +# -t to cvs filter value: path to filter +# -m update methodology value: MERGE or COPY +# -k expansion mode value: b, o, kkv, &c +# +# and value is a single-quote delimited value. +# For example: +#*.gif -k 'b' +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history new file mode 100644 index 00000000..f0ec96fa --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/history @@ -0,0 +1,65 @@ +O48f739fd|stefan|~/ASF/ant/ant-HEAD/src/tests/antunit/taskdefs/cvs/*0|antmodule1||antmodule1 +O48f747b5|stefan|~/ASF/ant/ant-HEAD/src/tests/antunit/taskdefs/cvs/*0|antmodule1||antmodule1 +M48f747fb|stefan|~/ASF/ant/ant-HEAD/src/tests/antunit/taskdefs/cvs/*0|antmodule1|1.2|foo.txt +M48f7480b|stefan|~/ASF/ant/ant-HEAD/src/tests/antunit/taskdefs/cvs/*0|antmodule1|1.3|foo.txt +O48f748cb|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f74940|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f749a9|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f74a02|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +M48f74a39|stefan|/tmp/testoutput/*0|antmodule1|1.4|foo.txt +O48f74a62|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f75161|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f75185|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f75186|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f75196|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f75279|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f75282|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f75d32|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f75d34|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f80394|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f80395|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f80ad6|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f80ad7|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f8a1d1|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f8a1d2|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f8a6a4|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f8a6a6|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f8a764|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f8a766|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f8abf0|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f8abf2|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f8ad8b|stefan|~/ASF/ant/ant-HEAD/*0|antmodule3||antmodule3 +M48f8add7|stefan|~/ASF/ant/ant-HEAD/*0|antmodule3|1.2|yet another test.txt +O48f8ae09|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f8ae0a|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f8b07c|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b07d|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b07e|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f8b07f|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b082|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f8b141|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b14c|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b1c3|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b1cd|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b20c|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b217|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b301|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b302|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f8b303|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b307|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f8b308|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b328|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48f8b329|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48f8b32b|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48f8b32c|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48fc5e01|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O48fc5e03|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O48fc5e05|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O48fc5e06|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O4936994c|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +M493699c6|stefan|/tmp/testoutput/*0|antmodule1|1.5|foo.txt +O49369a09|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O49369b73|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 +O49369b74|stefan|/tmp/testoutput/*0|antmodule1||antmodule1 +O49369b76|stefan|/tmp/testoutput/*0|ant module 2||ant module 2 +O49369b77|stefan|/tmp/testoutput/*0|antmodule3||antmodule3 diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/loginfo b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/loginfo new file mode 100644 index 00000000..6a1580d8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/loginfo @@ -0,0 +1,36 @@ +# The "loginfo" file controls where "cvs commit" log information is +# sent. The first entry on a line is a regular expression which must +# match the directory that the change is being made to, relative to the +# $CVSROOT. If a match is found, then the remainder of the line is a +# filter program that should expect log information on its standard input. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name ALL appears as a regular expression it is always used +# in addition to the first matching regex or DEFAULT. +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# %{sVv} = attribute list = file name, old version number (pre-checkin), +# new version number (post-checkin). When either old or new revision +# is unknown, doesn't exist, or isn't applicable, the string "NONE" +# will be placed on the command line instead. +# +# Note that %{sVv} is a list operator and not all elements are necessary. +# Thus %{sv} is a legal format string, but will only be replaced with +# file name and new revision. +# It also generates multiple arguments for each file being operated upon. +# That is, if two files, file1 & file2, are being commited from 1.1 to +# version 1.1.2.1 and from 1.1.2.2 to 1.1.2.3, respectively, %{sVv} will +# generate the following six arguments in this order: +# file1, 1.1, 1.1.2.1, file2, 1.1.2.2, 1.1.2.3. +# +# For example: +#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog +# or +#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/loginfo,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/loginfo,v new file mode 100644 index 00000000..5a6b8255 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/loginfo,v @@ -0,0 +1,60 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# The "loginfo" file controls where "cvs commit" log information is +# sent. The first entry on a line is a regular expression which must +# match the directory that the change is being made to, relative to the +# $CVSROOT. If a match is found, then the remainder of the line is a +# filter program that should expect log information on its standard input. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name ALL appears as a regular expression it is always used +# in addition to the first matching regex or DEFAULT. +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# %{sVv} = attribute list = file name, old version number (pre-checkin), +# new version number (post-checkin). When either old or new revision +# is unknown, doesn't exist, or isn't applicable, the string "NONE" +# will be placed on the command line instead. +# +# Note that %{sVv} is a list operator and not all elements are necessary. +# Thus %{sv} is a legal format string, but will only be replaced with +# file name and new revision. +# It also generates multiple arguments for each file being operated upon. +# That is, if two files, file1 & file2, are being commited from 1.1 to +# version 1.1.2.1 and from 1.1.2.2 to 1.1.2.3, respectively, %{sVv} will +# generate the following six arguments in this order: +# file1, 1.1, 1.1.2.1, file2, 1.1.2.2, 1.1.2.3. +# +# For example: +#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog +# or +#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/modules b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/modules new file mode 100644 index 00000000..cb9e9efc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/modules @@ -0,0 +1,26 @@ +# Three different line formats are valid: +# key -a aliases... +# key [options] directory +# key [options] directory files... +# +# Where "options" are composed of: +# -i prog Run "prog" on "cvs commit" from top-level of module. +# -o prog Run "prog" on "cvs checkout" of module. +# -e prog Run "prog" on "cvs export" of module. +# -t prog Run "prog" on "cvs rtag" of module. +# -u prog Run "prog" on "cvs update" of module. +# -d dir Place module in directory "dir" instead of module name. +# -l Top-level directory only -- do not recurse. +# +# NOTE: If you change any of the "Run" options above, you'll have to +# release and re-checkout any working directories of these modules. +# +# And "directory" is a path to a directory relative to $CVSROOT. +# +# The "-a" option specifies an alias. An alias is interpreted as if +# everything on the right of the "-a" had been typed on the command line. +# +# You can encode a module within a module by using the special '&' +# character to interpose another module into the current module. This +# can be useful for creating a module that consists of many directories +# spread out over the entire source repository. diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/modules,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/modules,v new file mode 100644 index 00000000..ca44716c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/modules,v @@ -0,0 +1,50 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# Three different line formats are valid: +# key -a aliases... +# key [options] directory +# key [options] directory files... +# +# Where "options" are composed of: +# -i prog Run "prog" on "cvs commit" from top-level of module. +# -o prog Run "prog" on "cvs checkout" of module. +# -e prog Run "prog" on "cvs export" of module. +# -t prog Run "prog" on "cvs rtag" of module. +# -u prog Run "prog" on "cvs update" of module. +# -d dir Place module in directory "dir" instead of module name. +# -l Top-level directory only -- do not recurse. +# +# NOTE: If you change any of the "Run" options above, you'll have to +# release and re-checkout any working directories of these modules. +# +# And "directory" is a path to a directory relative to $CVSROOT. +# +# The "-a" option specifies an alias. An alias is interpreted as if +# everything on the right of the "-a" had been typed on the command line. +# +# You can encode a module within a module by using the special '&' +# character to interpose another module into the current module. This +# can be useful for creating a module that consists of many directories +# spread out over the entire source repository. +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/notify b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/notify new file mode 100644 index 00000000..aaf98c59 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/notify @@ -0,0 +1,19 @@ +# The "notify" file controls where notifications from watches set by +# "cvs watch add" or "cvs edit" are sent. The first entry on a line is +# a regular expression which is tested against the directory that the +# change is being made to, relative to the $CVSROOT. If it matches, +# then the remainder of the line is a filter program that should contain +# one occurrence of %s for the user to notify, and information on its +# standard input. +# +# "ALL" or "DEFAULT" can be used in place of the regular expression. +# +# format strings are replaceed as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# %s = user to notify +# +# For example: +#ALL (echo Committed to %r/%p; cat) |mail %s -s "CVS notification" diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/notify,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/notify,v new file mode 100644 index 00000000..c0a02f98 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/notify,v @@ -0,0 +1,43 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# The "notify" file controls where notifications from watches set by +# "cvs watch add" or "cvs edit" are sent. The first entry on a line is +# a regular expression which is tested against the directory that the +# change is being made to, relative to the $CVSROOT. If it matches, +# then the remainder of the line is a filter program that should contain +# one occurrence of %s for the user to notify, and information on its +# standard input. +# +# "ALL" or "DEFAULT" can be used in place of the regular expression. +# +# format strings are replaceed as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# %s = user to notify +# +# For example: +#ALL (echo Committed to %r/%p; cat) |mail %s -s "CVS notification" +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postadmin b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postadmin new file mode 100644 index 00000000..a1a08128 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postadmin @@ -0,0 +1,20 @@ +# The "postadmin" file is called after the "admin" command finishes +# processing a directory. +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postadmin,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postadmin,v new file mode 100644 index 00000000..db853edc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postadmin,v @@ -0,0 +1,44 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# The "postadmin" file is called after the "admin" command finishes +# processing a directory. +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postproxy b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postproxy new file mode 100644 index 00000000..49c6cfb0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postproxy @@ -0,0 +1,22 @@ +# The "postproxy" file is called from a secondary server as soon as +# the secondary server closes its connection to the primary server. +# This script might, for example, be used to shut down a dial up +# or VPN connection to the primary server's network. +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository (currently always ".") +# %r = repository (path portion of $CVSROOT) +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postproxy,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postproxy,v new file mode 100644 index 00000000..454d19d7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postproxy,v @@ -0,0 +1,46 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# The "postproxy" file is called from a secondary server as soon as +# the secondary server closes its connection to the primary server. +# This script might, for example, be used to shut down a dial up +# or VPN connection to the primary server's network. +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository (currently always ".") +# %r = repository (path portion of $CVSROOT) +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/posttag b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/posttag new file mode 100644 index 00000000..7f369e38 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/posttag @@ -0,0 +1,37 @@ +# The "posttag" file is called after the "tag" command finishes +# processing a directory. +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %b = branch mode = "?" (delete ops - unknown) | "T" (branch) +# | "N" (not branch) +# %o = operation = "add" | "mov" | "del" +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# %t = tagname +# %{sVv} = attribute list = file name, old version tag will be deleted +# from, new version tag will be added to (or deleted from, but +# this feature is deprecated. When either old or new revision is +# unknown, doesn't exist, or isn't applicable, the string "NONE" +# will be placed on the command line. +# +# Note that %{sVv} is a list operator and not all elements are necessary. +# Thus %{sV} is a legal format string, but will only be replaced with file +# name and old revision. it also generates multiple arguments for each file +# being operated upon. i.e. if two files, file1 & file2, are having a tag +# moved from version 1.1 to version 1.1.2.9, %{sVv} will generate the +# following six arguments in this order: +# file1, 1.1, 1.1.2.9, file2, 1.1, 1.1.2.9. +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/posttag,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/posttag,v new file mode 100644 index 00000000..31c7024d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/posttag,v @@ -0,0 +1,61 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# The "posttag" file is called after the "tag" command finishes +# processing a directory. +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %b = branch mode = "?" (delete ops - unknown) | "T" (branch) +# | "N" (not branch) +# %o = operation = "add" | "mov" | "del" +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# %t = tagname +# %{sVv} = attribute list = file name, old version tag will be deleted +# from, new version tag will be added to (or deleted from, but +# this feature is deprecated. When either old or new revision is +# unknown, doesn't exist, or isn't applicable, the string "NONE" +# will be placed on the command line. +# +# Note that %{sVv} is a list operator and not all elements are necessary. +# Thus %{sV} is a legal format string, but will only be replaced with file +# name and old revision. it also generates multiple arguments for each file +# being operated upon. i.e. if two files, file1 & file2, are having a tag +# moved from version 1.1 to version 1.1.2.9, %{sVv} will generate the +# following six arguments in this order: +# file1, 1.1, 1.1.2.9, file2, 1.1, 1.1.2.9. +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postwatch b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postwatch new file mode 100644 index 00000000..5b001b12 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postwatch @@ -0,0 +1,20 @@ +# The "postwatch" file is called after any command finishes writing new +# file attibute (watch/edit) information in a directory. +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postwatch,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postwatch,v new file mode 100644 index 00000000..8e3825cb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/postwatch,v @@ -0,0 +1,44 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# The "postwatch" file is called after any command finishes writing new +# file attibute (watch/edit) information in a directory. +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/preproxy b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/preproxy new file mode 100644 index 00000000..a9f514f4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/preproxy @@ -0,0 +1,24 @@ +# The "preproxy" file is called form the secondary server as soon as +# the secondary server determines that it will be proxying a write +# command to a primary server and immediately before it opens a +# connection to the primary server. This script might, for example, be +# used to launch a dial up or VPN connection to the primary server's +# network. +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository (currently always ".") +# %r = repository (path portion of $CVSROOT) +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/preproxy,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/preproxy,v new file mode 100644 index 00000000..5dcaa279 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/preproxy,v @@ -0,0 +1,48 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# The "preproxy" file is called form the secondary server as soon as +# the secondary server determines that it will be proxying a write +# command to a primary server and immediately before it opens a +# connection to the primary server. This script might, for example, be +# used to launch a dial up or VPN connection to the primary server's +# network. +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository (currently always ".") +# %r = repository (path portion of $CVSROOT) +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/rcsinfo b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/rcsinfo new file mode 100644 index 00000000..49e59f4d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/rcsinfo @@ -0,0 +1,13 @@ +# The "rcsinfo" file is used to control templates with which the editor +# is invoked on commit and import. +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being made to, relative to the +# $CVSROOT. For the first match that is found, then the remainder of the +# line is the name of the file that contains the template. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/rcsinfo,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/rcsinfo,v new file mode 100644 index 00000000..df61bfb3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/rcsinfo,v @@ -0,0 +1,37 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# The "rcsinfo" file is used to control templates with which the editor +# is invoked on commit and import. +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being made to, relative to the +# $CVSROOT. For the first match that is found, then the remainder of the +# line is the name of the file that contains the template. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/taginfo b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/taginfo new file mode 100644 index 00000000..ce9d0dea --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/taginfo @@ -0,0 +1,46 @@ +# The "taginfo" file is used to control pre-tag checks. +# The filter on the right is invoked with the following arguments +# if no format strings are present: +# +# $1 -- tagname +# $2 -- operation "add" for tag, "mov" for tag -F, and "del" for tag -d +# $3 -- tagtype "?" on delete, "T" for branch, "N" for static +# $4 -- repository +# $5-> file revision [file revision ...] +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %b = branch mode = "?" (delete ops - unknown) | "T" (branch) +# | "N" (not branch) +# %o = operation = "add" | "mov" | "del" +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# %t = tagname +# %{sVv} = attribute list = file name, old version tag will be deleted +# from, new version tag will be added to (or deleted from, but +# this feature is deprecated. When either old or new revision is +# unknown, doesn't exist, or isn't applicable, the string "NONE" +# will be placed on the command line. +# +# Note that %{sVv} is a list operator and not all elements are necessary. +# Thus %{sV} is a legal format string, but will only be replaced with file +# name and old revision. it also generates multiple arguments for each file +# being operated upon. i.e. if two files, file1 & file2, are having a tag +# moved from version 1.1 to version 1.1.2.9, %{sVv} will generate the +# following six arguments in this order: +# file1, 1.1, 1.1.2.9, file2, 1.1, 1.1.2.9. +# +# A non-zero exit of the filter program will cause the tag to be aborted. +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/taginfo,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/taginfo,v new file mode 100644 index 00000000..82c87f25 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/taginfo,v @@ -0,0 +1,70 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# The "taginfo" file is used to control pre-tag checks. +# The filter on the right is invoked with the following arguments +# if no format strings are present: +# +# $1 -- tagname +# $2 -- operation "add" for tag, "mov" for tag -F, and "del" for tag -d +# $3 -- tagtype "?" on delete, "T" for branch, "N" for static +# $4 -- repository +# $5-> file revision [file revision ...] +# +# If any format strings are present in the filter, they will be replaced +# as follows: +# %b = branch mode = "?" (delete ops - unknown) | "T" (branch) +# | "N" (not branch) +# %o = operation = "add" | "mov" | "del" +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# %t = tagname +# %{sVv} = attribute list = file name, old version tag will be deleted +# from, new version tag will be added to (or deleted from, but +# this feature is deprecated. When either old or new revision is +# unknown, doesn't exist, or isn't applicable, the string "NONE" +# will be placed on the command line. +# +# Note that %{sVv} is a list operator and not all elements are necessary. +# Thus %{sV} is a legal format string, but will only be replaced with file +# name and old revision. it also generates multiple arguments for each file +# being operated upon. i.e. if two files, file1 & file2, are having a tag +# moved from version 1.1 to version 1.1.2.9, %{sVv} will generate the +# following six arguments in this order: +# file1, 1.1, 1.1.2.9, file2, 1.1, 1.1.2.9. +# +# A non-zero exit of the filter program will cause the tag to be aborted. +# +# The first entry on a line is a regular expression which is tested +# against the directory that the change is being committed to, relative +# to the $CVSROOT. For the first match that is found, then the remainder +# of the line is the name of the filter to run. +# +# If the repository name does not match any of the regular expressions in this +# file, the "DEFAULT" line is used, if it is specified. +# +# If the name "ALL" appears as a regular expression it is always used +# in addition to the first matching regex or "DEFAULT". +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/val-tags b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/val-tags new file mode 100644 index 00000000..a76de202 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/val-tags @@ -0,0 +1,2 @@ +testtag1 y +testtag2 y diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/verifymsg b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/verifymsg new file mode 100644 index 00000000..357a0b03 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/verifymsg @@ -0,0 +1,31 @@ +# The "verifymsg" file is used to allow verification of logging +# information. It works best when a template (as specified in the +# rcsinfo file) is provided for the logging procedure. Given a +# template with locations for, a bug-id number, a list of people who +# reviewed the code before it can be checked in, and an external +# process to catalog the differences that were code reviewed, the +# following test can be applied to the code: +# +# Making sure that the entered bug-id number is correct. +# Validating that the code that was reviewed is indeed the code being +# checked in (using the bug-id number or a seperate review +# number to identify this particular code set.). +# +# If any of the above test failed, then the commit would be aborted. +# +# Format strings present in the filter will be replaced as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# %l = name of log file to be verified. +# +# If no format strings are present in the filter, a default " %l" will +# be appended to the filter, but this usage is deprecated. +# +# Actions such as mailing a copy of the report to each reviewer are +# better handled by an entry in the loginfo file. +# +# One thing that should be noted is the the ALL keyword is not +# supported. There can be only one entry that matches a given +# repository. diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/verifymsg,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/verifymsg,v new file mode 100644 index 00000000..d80fd099 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/CVSROOT/verifymsg,v @@ -0,0 +1,55 @@ +head 1.1; +access ; +symbols ; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.12.52.41; author stefan; state Exp; +branches; +next ; +commitid f9748f739194567; + +desc +@@ + + + +1.1 +log +@initial checkin@ +text +@# The "verifymsg" file is used to allow verification of logging +# information. It works best when a template (as specified in the +# rcsinfo file) is provided for the logging procedure. Given a +# template with locations for, a bug-id number, a list of people who +# reviewed the code before it can be checked in, and an external +# process to catalog the differences that were code reviewed, the +# following test can be applied to the code: +# +# Making sure that the entered bug-id number is correct. +# Validating that the code that was reviewed is indeed the code being +# checked in (using the bug-id number or a seperate review +# number to identify this particular code set.). +# +# If any of the above test failed, then the commit would be aborted. +# +# Format strings present in the filter will be replaced as follows: +# %c = canonical name of the command being executed +# %R = the name of the referrer, if any, otherwise the value NONE +# %p = path relative to repository +# %r = repository (path portion of $CVSROOT) +# %l = name of log file to be verified. +# +# If no format strings are present in the filter, a default " %l" will +# be appended to the filter, but this usage is deprecated. +# +# Actions such as mailing a copy of the report to each reviewer are +# better handled by an entry in the loginfo file. +# +# One thing that should be noted is the the ALL keyword is not +# supported. There can be only one entry that matches a given +# repository. +@ + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/ant module 2/test.txt,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/ant module 2/test.txt,v new file mode 100644 index 00000000..b91d6968 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/ant module 2/test.txt,v @@ -0,0 +1,41 @@ +head 1.1; +branch 1.1.1; +access ; +symbols start:1.1.1.1 ant:1.1.1; +locks ; strict; +comment @# @; + + +1.1 +date 2008.10.16.14.14.17; author stefan; state Exp; +branches 1.1.1.1; +next ; +commitid cdf48f74c394567; + +1.1.1.1 +date 2008.10.16.14.14.17; author stefan; state Exp; +branches ; +next ; +commitid cdf48f74c394567; + + +desc +@@ + + + +1.1 +log +@Initial revision +@ +text +@What a nice file. +@ + + +1.1.1.1 +log +@module with space in it's name +@ +text +@@ diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/antmodule1/foo.txt,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/antmodule1/foo.txt,v new file mode 100644 index 00000000..47669791 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/antmodule1/foo.txt,v @@ -0,0 +1,108 @@ +head 1.5; +access; +symbols + start:1.1.1.1 ant:1.1.1; +locks; strict; +comment @# @; + + +1.5 +date 2008.12.03.14.37.58; author stefan; state Exp; +branches; +next 1.4; +commitid 2ca3493699c64567; + +1.4 +date 2008.10.16.14.05.45; author stefan; state Exp; +branches; +next 1.3; +commitid 761748f74a394567; + +1.3 +date 2008.10.16.13.56.27; author stefan; state Exp; +branches; +next 1.2; +commitid 4dcd48f7480b4567; + +1.2 +date 2008.10.16.13.56.11; author stefan; state Exp; +branches; +next 1.1; +commitid 4dae48f747fb4567; + +1.1 +date 2008.10.16.12.56.07; author stefan; state Exp; +branches + 1.1.1.1; +next ; +commitid 17ca48f739e74567; + +1.1.1.1 +date 2008.10.16.12.56.07; author stefan; state Exp; +branches; +next ; +commitid 17ca48f739e74567; + + +desc +@@ + + +1.5 +log +@add yet another line +@ +text +@This is a text. +Added a line. +and one more line. +and another line. +@ + + +1.4 +log +@---------------------------- +@ +text +@d4 1 +@ + + +1.3 +log +@typo +@ +text +@d3 1 +@ + + +1.2 +log +@-------------------- +@ +text +@d2 1 +a2 1 +added a line. +@ + + +1.1 +log +@Initial revision +@ +text +@d2 1 +a2 1 + +@ + + +1.1.1.1 +log +@Initial import +@ +text +@@ diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/antmodule3/yet another test.txt,v b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/antmodule3/yet another test.txt,v new file mode 100644 index 00000000..08f13b00 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/cvs/repository/antmodule3/yet another test.txt,v @@ -0,0 +1,60 @@ +head 1.2; +access; +symbols + testtag2:1.2 + testtag1:1.1.1.1 + start:1.1.1.1 + ant:1.1.1; +locks; strict; +comment @# @; + + +1.2 +date 2008.10.17.15.23.03; author stefan; state Exp; +branches; +next 1.1; +commitid 7ddc48f8add74567; + +1.1 +date 2008.10.16.14.51.11; author stefan; state Exp; +branches + 1.1.1.1; +next ; +commitid 7f8d48f754df4567; + +1.1.1.1 +date 2008.10.16.14.51.11; author stefan; state Exp; +branches; +next ; +commitid 7f8d48f754df4567; + + +desc +@@ + + +1.2 +log +@update weather report +@ +text +@dark and cloudy. +a bit brighter today. +@ + + +1.1 +log +@Initial revision +@ +text +@d2 1 +@ + + +1.1.1.1 +log +@three times is a charm +@ +text +@@ diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/defaultexcludes-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/defaultexcludes-test.xml new file mode 100644 index 00000000..cbea93c2 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/defaultexcludes-test.xml @@ -0,0 +1,52 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${output}"/> + <available property="in working copy" file=".svn"/> + </target> + + <target name="testCopyNoExplicitExcludes" depends="setUp" + if="in working copy"> + <copy todir="${output}"> + <fileset dir="."/> + </copy> + <au:assertFileExists file="${output}/defaultexcludes-test.xml"/> + <au:assertFileDoesntExist file="${output}/.svn/entries"/> + </target> + + <target name="testCopyExplicitExcludes" depends="setUp" + if="in working copy"> + <copy todir="${output}"> + <fileset dir="." defaultexcludes="true"/> + </copy> + <au:assertFileExists file="${output}/defaultexcludes-test.xml"/> + <au:assertFileDoesntExist file="${output}/.svn/entries"/> + </target> + + <target name="testCopyExplicitNoExcludes" depends="setUp" + if="in working copy"> + <copy todir="${output}"> + <fileset dir="." defaultexcludes="false"/> + </copy> + <au:assertFileExists file="${output}/defaultexcludes-test.xml"/> + <au:assertFileExists file="${output}/.svn/entries"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml new file mode 100644 index 00000000..ac789940 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/delete-and-symlinks-test.xml @@ -0,0 +1,84 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<project name="delete-test" basedir="." default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <condition property="unix"> + <os family="unix" /> + </condition> + + <target name="tearDown" depends="removelink, antunit-base.tearDown"/> + + <target name="removelink" if="link"> + <symlink action="delete" link="${link}"/> + </target> + + <target name="setUp" if="unix"> + <mkdir dir="${input}/A/B"/> + <mkdir dir="${input}/C"/> + <property name="link" location="${input}/A/B/C"/> + <symlink link="${link}" resource="${input}/C"/> + </target> + + <target name="testNotFollowedLink" if="unix" depends="setUp"> + <delete> + <fileset dir="${input}" followSymlinks="false"/> + </delete> + <au:assertFileExists file="${input}/A/B/C"/> + </target> + + <target name="testRemoveNotFollowedLink" if="unix" depends="setUp"> + <delete removeNotFollowedSymlinks="true"> + <fileset dir="${input}/A" followSymlinks="false"/> + </delete> + <au:assertFileDoesntExist file="${input}/A/B/C"/> + <au:assertFileExists file="${input}/C"/> + </target> + + <target name="testRemoveNotFollowedLinkHonorsIncludesOnFiles" + depends="setUp" if="unix" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=53959"> + <delete dir="${input}/C"/> + <touch file="${input}/C"/> + <delete removeNotFollowedSymlinks="true"> + <fileset dir="${input}/A" followSymlinks="false" includes="**/D"/> + </delete> + <au:assertFileExists file="${input}/A/B/C"/> + </target> + + <target name="testRemoveNotFollowedLinkDeletesNotIncludedDirs" + depends="setUp" if="unix" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=53959"> + <delete removeNotFollowedSymlinks="true"> + <fileset dir="${input}/A" followSymlinks="false" includes="**/D"/> + </delete> + <au:assertFileDoesntExist file="${input}/A/B/C"/> + <au:assertFileExists file="${input}/C"/> + </target> + + <target name="testRemoveNotFollowedLinkHonorsExcludes" if="unix" + depends="setUp"> + <delete removeNotFollowedSymlinks="true"> + <fileset dir="${input}/A" followSymlinks="false" excludes="**/C/**"/> + </delete> + <au:assertFileExists file="${input}/A/B/C"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/delete-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/delete-test.xml new file mode 100644 index 00000000..554f08fe --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/delete-test.xml @@ -0,0 +1,141 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<project name="delete-test" basedir="." default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <property name="existing.dir" location="${output}/exists"/> + <property name="nonexistent.dir" location="${output}/nonexists"/> + + <target name="init"> + <delete dir="${output}"/> + <mkdir dir="${output}"/> + <mkdir dir="${existing.dir}"/> + </target> + + <!--test that you can delete a fileset with a nonexistent dir without failure--> + <target name="testdelfileset" depends="init"> + <delete quiet="true" includeEmptyDirs="true"> + <fileset dir="${nonexistent.dir}"/> + </delete> + + <au:assertFileExists file="${existing.dir}" /> + + <delete quiet="true" includeEmptyDirs="true"> + <fileset dir="${existing.dir}"/> + </delete> + + <au:assertFileDoesntExist file="${existing.dir}" /> + + + <mkdir dir="${existing.dir}"/> + + <delete quiet="true" includeEmptyDirs="true"> + <fileset dir="${nonexistent.dir}"/> + <fileset dir="${existing.dir}"/> + </delete> + + + <au:assertFileDoesntExist file="${existing.dir}" /> + + <mkdir dir="${existing.dir}"/> + + <delete quiet="true" includeEmptyDirs="true"> + <fileset dir="${existing.dir}"/> + <fileset dir="${nonexistent.dir}"/> + </delete> + + + <au:assertFileDoesntExist file="${existing.dir}" /> + + </target> + + <target name="checkOs"> + <condition property="unix"> + <os family="unix" /> + </condition> + </target> + + <target name="testDanglingSymlinkInDir" if="unix" depends="checkOs,init"> + <touch file="${output}/foo"/> + <symlink link="${existing.dir}/link" + resource="${output}/foo"/> + <delete file="${output}/foo"/> + <delete dir="${existing.dir}"/> + <au:assertFileDoesntExist file="${existing.dir}" /> + </target> + + <target name="testDanglingSymlink" if="unix" depends="checkOs,init"> + <touch file="${output}/foo"/> + <symlink link="${output}/link" + resource="${output}/foo"/> + <delete file="${output}/foo"/> + <delete file="${output}/link"/> + + <!-- since File.exists returns false for dangling links, recreate + the file so that assertFileDoesntExist can actually work --> + <touch file="${output}/foo"/> + <au:assertFileDoesntExist file="${output}/link" /> + </target> + + <target name="testNotModifiedSelector" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=43574" + > + <mkdir dir="${input}/images"/> + <mkdir dir="${input}/cache"/> + <touch file="${input}/images/foo.jpg"/> + <selector id="cache.selector"> + <not> + <modified update="true" + seldirs="false" + cache="propertyfile" + algorithm="digest" + comparator="equal"> + <param name="cache.cachefile" + value="${input}/cache/cache.properties"/> + <param name="algorithm.algorithm" value="MD5"/> + </modified> + </not> + </selector> + <au:assertFileDoesntExist file="${input}/cache/cache.properties"/> + <delete> + <fileset dir="${input}/images"> + <include name="*.jpg" /> + <selector refid="cache.selector" /> + </fileset> + </delete> + <au:assertFileExists file="${input}/cache/cache.properties"/> + <au:assertFileExists file="${input}/images/foo.jpg"/> + <delete> + <fileset dir="${input}/images"> + <include name="*.jpg" /> + <selector refid="cache.selector" /> + </fileset> + </delete> + <au:assertFileDoesntExist file="${input}/images/foo.jpg"/> + </target> + + <target name="testFilesetWithMissingButIgnoredDir" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50124"> + <delete> + <fileset dir="${input}/not-there" errorOnMissingDir="false"/> + </delete> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/dependset-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/dependset-test.xml new file mode 100644 index 00000000..55252593 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/dependset-test.xml @@ -0,0 +1,196 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<project name="dependset-test" xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}" /> + <mkdir dir="${output}" /> + </target> + + <target name="testNoSourcesOrTargets"> + <au:expectfailure expectedMessage="At least one set of source resources must be specified"> + <dependset /> + </au:expectfailure> + </target> + + <target name="testNoTargets"> + <au:expectfailure expectedMessage="At least one set of target files must be specified"> + <dependset> + <srcfilelist dir="." files="test2.tmp" /> + </dependset> + </au:expectfailure> + </target> + + <target name="testNoSources"> + <au:expectfailure expectedMessage="At least one set of source resources must be specified"> + <dependset> + <targetfileset dir="." includes="test3.tmp" /> + </dependset> + </au:expectfailure> + </target> + + <target name="testMissingTargets" depends="setUp"> + <touch file="${input}/test4.tmp" /> + <dependset> + <srcfilelist dir="${input}" files="test4.tmp" /> + <targetfileset id="targetfs" dir="${output}" includes="i-do-not-exist" /> + </dependset> + <au:assertLogDoesntContain text="Deleting all target files." level="verbose" /> + </target> + + <target name="testMoreRecentSourceFile" depends="setUp"> + <touch file="${output}/older.tmp" /> + <sleep seconds="3" /> + <touch file="${input}/newer.tmp" /> + <dependset> + <srcfilelist dir="${input}" files="newer.tmp" /> + <targetfilelist dir="${output}" files="older.tmp" /> + </dependset> + <au:assertLogContains text="older.tmp" is oldest target file" level="verbose" /> + <au:assertLogContains text="newer.tmp" is newest source" level="verbose" /> + <au:assertLogContains text="Deleting all target files." level="verbose" /> + <au:assertLogDoesntContain text="Deleting" level="info" /> + <au:assertFileDoesntExist file="${output}/older.tmp" /> + </target> + + <target name="testMoreRecentSourceFileVerbose" depends="setUp"> + <touch file="${output}/older.tmp" /> + <sleep seconds="3" /> + <touch file="${input}/newer.tmp" /> + <dependset verbose="true"> + <srcfilelist dir="${input}" files="newer.tmp" /> + <targetfilelist dir="${output}" files="older.tmp" /> + </dependset> + <au:assertLogContains text="older.tmp" is oldest target file" level="info" /> + <au:assertLogContains text="newer.tmp" is newest source" level="info" /> + <au:assertLogContains text="Deleting all target files." level="verbose" /> + <au:assertLogContains text="Deleting" level="info" /> + <au:assertFileDoesntExist file="${output}/older.tmp" /> + </target> + + <target name="testMultipleFiles" depends="setUp"> + <touch file="${input}/sourceset_1.tmp" /> + <touch file="${output}/targetset_1.tmp" /> + <sleep seconds="3" /> + <touch file="${input}/sourceset_2.tmp" /> + <touch file="${output}/targetset_2.tmp" /> + <sleep seconds="2" /> + <dependset> + <sources> + <filelist dir="${input}" files="sourceset_1.tmp,sourceset_2.tmp" /> + </sources> + <targets> + <filelist dir="${output}/" files="targetset_1.tmp,targetset_2.tmp" /> + </targets> + </dependset> + <au:assertLogContains text="targetset_1.tmp" is oldest target file" level="verbose" /> + <au:assertLogContains text="sourceset_2.tmp" is newest source" level="verbose" /> + <au:assertLogContains text="Deleting all target files." level="verbose" /> + <au:assertLogDoesntContain text="Deleting" level="info" /> + <au:assertFileDoesntExist file="${output}/targetset_1.tmp" /> + <au:assertFileDoesntExist file="${output}/targetset_2.tmp" /> + </target> + + <target name="testMultipleFilesVerbose" depends="setUp"> + <touch file="${input}/sourceset_1.tmp" /> + <touch file="${output}/targetset_1.tmp" /> + <sleep seconds="3" /> + <touch file="${input}/sourceset_2.tmp" /> + <touch file="${output}/targetset_2.tmp" /> + <sleep seconds="2" /> + <dependset verbose="true"> + <sources> + <filelist dir="${input}" files="sourceset_1.tmp,sourceset_2.tmp" /> + </sources> + <targets> + <filelist dir="${output}/" files="targetset_1.tmp,targetset_2.tmp" /> + </targets> + </dependset> + <au:assertLogContains text="targetset_1.tmp" is oldest target file" level="info" /> + <au:assertLogContains text="sourceset_2.tmp" is newest source" level="info" /> + <au:assertLogContains text="Deleting all target files." level="verbose" /> + <au:assertLogContains text="Deleting" level="info" /> + <au:assertFileDoesntExist file="${output}/targetset_1.tmp" /> + <au:assertFileDoesntExist file="${output}/targetset_2.tmp" /> + </target> + + <target name="testMissingSourceResource" depends="setUp"> + <touch file="${output}/older.tmp" /> + <dependset> + <sources> + <propertyresource name="thereisnosuchproperty" /> + </sources> + <targets> + <filelist dir="${output}" files="older.tmp" /> + </targets> + </dependset> + <au:assertLogContains text="1 nonexistent sources" level="verbose" /> + <au:assertLogContains text="Deleting all target files." level="verbose" /> + <au:assertLogDoesntContain text="Deleting" level="info" /> + <au:assertLogDoesntContain text="Expected source propertyresource "null" is missing." level="info" /> + <au:assertFileDoesntExist file="${output}/older.tmp" /> + </target> + + <target name="testMissingSourceResourceVerbose" depends="setUp"> + <touch file="${output}/older.tmp" /> + <dependset verbose="true"> + <sources> + <propertyresource name="thereisnosuchproperty" /> + </sources> + <targets> + <filelist dir="${output}" files="older.tmp" /> + </targets> + </dependset> + <au:assertLogContains text="1 nonexistent sources" level="verbose" /> + <au:assertLogContains text="Deleting all target files." level="verbose" /> + <au:assertLogContains text="Deleting" level="info" /> + <au:assertLogContains text="Expected source propertyresource "null" is missing." level="info" /> + <au:assertFileDoesntExist file="${output}/older.tmp" /> + </target> + + <target name="testExistingSourceResource" depends="setUp"> + <touch file="${output}/older.tmp" /> + <property name="foo" value="bar" /> + <dependset> + <sources> + <propertyresource name="foo" /> + </sources> + <targets> + <filelist dir="${output}" files="older.tmp" /> + </targets> + </dependset> + <au:assertLogDoesntContain text="Deleting all target files." level="verbose" /> + <au:assertFileExists file="${output}/older.tmp" /> + </target> + + <target name="testMissingTargetDirectory" depends="setUp"> + <au:assertFalse> + <available file="${output}/test9dir" type="dir" /> + </au:assertFalse> + <touch file="${input}/test9.tmp" /> + <dependset> + <srcfileset dir="." includes="test9.tmp" /> + <targetfileset dir="${output}/test9dir" /> + </dependset> + <au:assertLogDoesntContain text="Deleting all target files." level="verbose" /> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/dirname-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/dirname-test.xml new file mode 100644 index 00000000..60caaf1a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/dirname-test.xml @@ -0,0 +1,59 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="dirname-test" basedir="." default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml"/> + + <target name="test1"> + <au:expectfailure expectedmessage="property attribute required"> + <dirname/> + </au:expectfailure> + </target> + + <target name="test2"> + <au:expectfailure expectedmessage="file attribute required"> + <dirname property="propname"/> + </au:expectfailure> + </target> + + <target name="test3"> + <au:expectfailure expectedmessage="property attribute required"> + <dirname file="filename"/> + </au:expectfailure> + </target> + + <target name="init-test4"> + <condition property="valid.os"> + <and> + <not><os family="dos"/></not><not><os family="netware"/></not> + </and> + </condition> + </target> + + <target name="test4" depends="init-test4" if="valid.os"> + <dirname property="local.dir" file="/usr/local/foo.txt"/> + <au:assertPropertyEquals name="local.dir" + value="${file.separator}usr${file.separator}local"/> + </target> + + <target name="test5"> + <dirname property="base.dir" file="foo.txt"/> + <au:assertPropertyEquals name="base.dir" value="${basedir}"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/ear-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/ear-test.xml new file mode 100644 index 00000000..239c501a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/ear-test.xml @@ -0,0 +1,31 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + <import file="../antunit-base.xml" /> + + <target name="testOnlyOneAppXml"> + <mkdir dir="${input}/META-INF"/> + <mkdir dir="${output}"/> + <touch file="${input}/META-INF/application.xml"/> + <touch file="${input}/x.xml"/> + <ear destfile="${output}/test.ear" appxml="${input}/x.xml"> + <fileset dir="${input}"/> + </ear> + <au:assertLogContains text="Warning: selected ear files include a META-INF/application.xml which will be ignored (please use appxml attribute to ear task)"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/echo-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/echo-test.xml new file mode 100644 index 00000000..bd1fc05e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/echo-test.xml @@ -0,0 +1,138 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<project name="echo-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${output}" /> + </target> + + <target name="test1"> + <echo/> + <au:assertTrue> + <length length="0"> + <au:logcontent /> + </length> + </au:assertTrue> + </target> + + <target name="test2"> + <echo message="OUTPUT OF ECHO"/> + <au:assertLogContains text="OUTPUT OF ECHO" /> + </target> + + <target name="test3"> + <echo> + This + is + a + multiline + message + </echo> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <au:logcontent /> + <contains text="This" /> + <contains text="is" /> + <contains text="a" /> + <contains text="multiline" /> + <contains text="message" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testFile"> + <echo file="${output}/echo.txt">Simple text</echo> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <file file="${output}/echo.txt" /> + <contains text="Simple text" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testOutputFile"> + <echo output="${output}/echo.txt">Simple text</echo> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <file file="${output}/echo.txt" /> + <contains text="Simple text" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testAppend"> + <echo file="${output}/echo.txt">Simple text</echo> + <echo file="${output}/echo.txt" append="true">Appended</echo> + <concat> + <file file="${output}/echo.txt" /> + </concat> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <file file="${output}/echo.txt" /> + <contains text="Simple text" /> + <contains text="Appended" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testEmptyEncoding"> + <echo file="${output}/echo.txt" encoding="">Simple text</echo> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <file file="${output}/echo.txt" /> + <contains text="Simple text" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testUTF16Encoding"> + <property name="char" value="©" /> + <echo file="${output}/echo16.txt" encoding="UTF-16">${char}</echo> + <loadfile property="out.16" srcfile="${output}/echo16.txt" + encoding="UTF-16"/> + <au:assertEquals expected="${char}" actual="${out.16}"/> + </target> + + <target name="testUTF8Encoding"> + <property name="char" value="©" /> + <echo file="${output}/echo8.txt" encoding="UTF8">${char}</echo> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <concat encoding="UTF-8"> + <file file="${output}/echo8.txt"/> + </concat> + <contains text="${char}" encoding="UTF-8"/> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/echoxml-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/echoxml-test.xml new file mode 100644 index 00000000..d461d3d8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/echoxml-test.xml @@ -0,0 +1,87 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <!-- note relies on antunit 1.1 --> + <import file="../antunit-base.xml"/> + + <target name="setUp"> + <property name="file" location="${output}/echoed.xml"/> + <mkdir dir="${output}"/> + <echoxml file="${file}"> + <project> + <property name="foo" value="bar" /> + <fail message="$$$${foo}=$${foo}"> + <condition> + <istrue value="${mustfail}" /> + </condition> + </fail> + </project> + </echoxml> + </target> + + <target name="testPass"> + <ant antfile="${file}"/> + </target> + + <target name="testFail"> + <au:expectfailure expectedmessage="${foo}=bar" message="Should have thrown an exception"> + <ant antfile="${file}"> + <property name="mustfail" value="true" /> + </ant> + </au:expectfailure> + </target> + + <target name="testEmpty"> + <au:expectfailure expectedmessage="No nested XML specified" message="Should have thrown an exception"> + <echoxml /> + </au:expectfailure> + </target> + + <!-- comment this and the next targets if you don't have the svn + trunk of antunit --> + <target name="test-ns-all"> + <echoxml file="${file}" xmlns:a="antlib:a" + namespacepolicy="all"> + <a:something a:foo="bar"/> + </echoxml> + <au:assertResourceContains resource="${file}" value="a:something"/> + <au:assertResourceContains resource="${file}" value="antlib:a"/> + </target> + + <target name="test-ns-elementsOnly"> + <echoxml file="${file}" xmlns:a="antlib:a" + namespacepolicy="elementsOnly"> + <a:something a:foo="bar"/> + </echoxml> + <au:assertResourceContains resource="${file}" value="a:something"/> + <au:assertResourceContains resource="${file}" value="antlib:a"/> + </target> + + <target name="test-ns-ignore"> + <echoxml file="${file}" xmlns:a="antlib:a" + namespacepolicy="ignore"> + <a:something a:foo="bar"/> + </echoxml> + <au:assertResourceContains resource="${file}" value="a:something"/> + <au:assertFalse message="Didn't expecte ${file} to contain antlib:a"> + <resourcecontains resource="${file}" substring="antlib:a"/> + </au:assertFalse> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/apply-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/apply-test.xml new file mode 100644 index 00000000..1b5a661a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/apply-test.xml @@ -0,0 +1,792 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="apply-test" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../antunit-base.xml" /> + + <property environment="env" /> + <!-- UNIX --> + <available file="sh" filepath="${env.PATH}" property="sh.executable" /> + <!-- CYGWIN --> + <available file="sh.exe" filepath="${env.PATH}" property="sh.exe.executable" /> + <condition property="test.can.run"> + <or> + <isset property="sh.executable" /> + <isset property="sh.exe.executable" /> + </or> + </condition> + <!-- UNIX --> + <available file="sed" filepath="${env.PATH}" property="sed.executable" /> + <!-- CYGWIN --> + <available file="sed.exe" filepath="${env.PATH}" property="sed.exe.executable" /> + <condition property="sed.can.run"> + <or> + <isset property="sed.executable" /> + <isset property="sed.exe.executable" /> + </or> + </condition> + <!-- UNIX --> + <available file="echo" filepath="${env.PATH}" property="echo.executable" /> + <!-- CYGWIN --> + <available file="echo.exe" filepath="${env.PATH}" property="echo.exe.executable" /> + <condition property="echo.can.run"> + <or> + <isset property="echo.executable" /> + <isset property="echo.exe.executable" /> + </or> + </condition> + + <!-- UNIX --> + <available file="ls" filepath="${env.PATH}" property="ls.executable" /> + <!-- CYGWIN --> + <available file="ls.exe" filepath="${env.PATH}" property="ls.exe.executable" /> + <!-- piggyback the name of the executable here --> + <condition property="ls.can.run" value="ls"> + <isset property="ls.executable" /> + </condition> + <condition property="ls.can.run" value="ls.exe"> + <isset property="ls.exe.executable" /> + </condition> + + <property name="eol" value="${line.separator}" /> + + <macrodef name="rcat"> + <attribute name="refid" /> + <sequential> + <echo>@@{refid}=@{refid}</echo> + <concat><resources refid="@{refid}" /></concat> + </sequential> + </macrodef> + + <macrodef name="assertEmptyFile"> + <attribute name="file" /> + <sequential> + <au:assertTrue> + <and> + <available file="@{file}" type="file" /> + <length length="0" file="@{file}" /> + </and> + </au:assertTrue> + </sequential> + </macrodef> + + <target name="xyz"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/x">s/x/blah/g${eol}</echo> + <echo file="${input}/y">s/y/blah/g${eol}</echo> + <echo file="${input}/z">s/z/blah/g${eol}</echo> + <fileset id="xyz" dir="${input}" includes="x,y,z" /> + <filelist id="xyzlist" dir="${input}" files="x,y,z" /> + <property name="x" location="${input}/x" /> + <property name="y" location="${input}/y" /> + <property name="z" location="${input}/z" /> + </target> + + <target name="testNoRedirect" depends="xyz" if="test.can.run"> + <apply executable="sh"> + <arg value="parrot.sh" /> + <fileset refid="xyz" /> + </apply> + + <au:assertLogContains text="${x} out" /> + <au:assertLogContains text="${y} out" /> + <au:assertLogContains text="${z} out" /> + <au:assertLogContains text="${x} err" /> + <au:assertLogContains text="${y} err" /> + <au:assertLogContains text="${z} err" /> + + <!-- + + The original junit test also verified that x out happened before + y out, and y out happened before z out; likewise with err output. + I added the antunit:logcontent resource hoping that would help, + but I think we need a way to filter (copy) resources first. + THAT necessitates the string-to-resource coding we are currently + discussing on the dev list IMO. MJB, 9/22/2006 + + --> + + </target> + + <target name="testRedirect1" depends="xyz" if="test.can.run"> + <apply executable="sh" output="${output}/redirect.out" append="true"> + <arg value="parrot.sh" /> + <fileset refid="xyz" /> + </apply> + + <au:assertTrue> + <resourcecount count="1"> + <restrict id="results"> + <file file="${output}/redirect.out" /> + <and xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <contains text="${x} out" /> + <contains text="${y} out" /> + <contains text="${z} out" /> + <contains text="${x} err" /> + <contains text="${y} err" /> + <contains text="${z} err" /> + </and> + </restrict> + </resourcecount> + </au:assertTrue> + + </target> + + <target name="testRedirect2" depends="xyz" if="test.can.run"> + <apply executable="sh" output="${output}/redirect.out" + error="${output}/redirect.err" append="true"> + <arg value="parrot.sh" /> + <fileset refid="xyz" /> + </apply> + + <au:assertTrue> + <and> + <resourcesmatch astext="true"> + <string value="${x} out${eol}${y} out${eol}${z} out" /> + <file file="${output}/redirect.out" /> + </resourcesmatch> + <resourcesmatch astext="true"> + <string value="${x} err${eol}${y} err${eol}${z} err" /> + <file file="${output}/redirect.err" /> + </resourcesmatch> + </and> + </au:assertTrue> + </target> + + <target name="testRedirect3" depends="xyz" if="test.can.run"> + <apply executable="sh" logerror="true" append="true" + output="${output}/redirect.out" outputproperty="redirect3.out"> + <arg value="parrot.sh" /> + <fileset refid="xyz" /> + </apply> + + <au:assertTrue> + <resourcesmatch astext="true"> + <string value="${x} out${eol}${y} out${eol}${z} out" /> + <file file="${output}/redirect.out" /> + <propertyresource name="redirect3.out" /> + </resourcesmatch> + </au:assertTrue> + + <au:assertLogContains text="${x} err" /> + <au:assertLogContains text="${y} err" /> + <au:assertLogContains text="${z} err" /> + </target> + + <target name="testRedirect4" depends="xyz" if="test.can.run"> + <apply executable="sh" append="true" + error="${output}/redirect.err" errorproperty="redirect4.err" + output="${output}/redirect.out" outputproperty="redirect4.out"> + <arg value="parrot.sh" /> + <fileset refid="xyz" /> + </apply> + + <au:assertTrue> + <and> + <resourcesmatch astext="true"> + <string value="${x} out${eol}${y} out${eol}${z} out" /> + <file file="${output}/redirect.out" /> + <propertyresource name="redirect4.out" /> + </resourcesmatch> + <resourcesmatch astext="true"> + <string value="${x} err${eol}${y} err${eol}${z} err" /> + <file file="${output}/redirect.err" /> + <propertyresource name="redirect4.err" /> + </resourcesmatch> + </and> + </au:assertTrue> + </target> + + <target name="testRedirect5" depends="xyz" if="sed.can.run"> + <apply executable="sed" inputstring="x y z${eol}" append="true" + error="${output}/redirect.err" errorproperty="redirect5.err" + output="${output}/redirect.out" outputproperty="redirect5.out"> + <arg value="-f" /> + <fileset refid="xyz" /> + </apply> + + <au:assertTrue> + <and> + <resourcesmatch astext="true"> + <propertyresource name="redirect5.out" /> + <string value="blah y z${eol}x blah z${eol}x y blah" /> + <file file="${output}/redirect.out" /> + </resourcesmatch> + <equals arg1="${redirect5.err}" arg2="" /> + </and> + </au:assertTrue> + <assertEmptyFile file="${output}/redirect.err" /> + </target> + + <target name="testRedirect6" depends="xyz" if="sed.can.run"> + <echo file="${input}/redirect.in">x y z${eol}</echo> + <apply executable="sed" input="${input}/redirect.in" append="true" + error="${output}/redirect.err" errorproperty="redirect6.err" + output="${output}/redirect.out" outputproperty="redirect6.out"> + <arg value="-f" /> + <filelist refid="xyzlist" /> + </apply> + + <au:assertTrue> + <and> + <resourcesmatch astext="true"> + <propertyresource name="redirect6.out" /> + <string value="blah y z${eol}x blah z${eol}x y blah" /> + <file file="${output}/redirect.out" /> + </resourcesmatch> + <equals arg1="${redirect6.err}" arg2="" /> + <length length="0"><file file="${output}/redirect.err" /></length> + </and> + </au:assertTrue> + </target> + + <target name="testRedirect7" depends="xyz" if="sed.can.run"> + <apply executable="sed" inputstring="x y z${eol}" + error="${output}/redirect.err" output="${output}/redirect.out" + outputproperty="redirect7.out"> + <arg value="-f" /> + <fileset refid="xyz" /> + </apply> + + <au:assertTrue> + <and> + <equals arg1="${redirect7.out}" arg2="blah y z" /> + <resourcesmatch astext="true"> + <file file="${output}/redirect.out" /> + <string value="x y blah" /> + </resourcesmatch> + </and> + </au:assertTrue> + <assertEmptyFile file="${output}/redirect.err" /> + </target> + + <target name="testRedirector1" description="fail" + depends="xyz" if="test.can.run"> + <au:expectfailure + expectedmessage="cannot have > 1 nested <redirector>s"> + <apply executable="sh"> + <arg value="parrot.sh" /> + <fileset refid="xyz" /> + <redirector output="${output}/redirector.out" /> + <redirector output="${output}/whocares" /> + </apply> + </au:expectfailure> + </target> + + <target name="testRedirector2" depends="xyz" if="test.can.run"> + <apply executable="sh"> + <arg value="parrot.sh" /> + <fileset refid="xyz" /> + <redirector output="${output}/redirector.out" append="true" /> + </apply> + <au:assertTrue> + <resourcecount count="1"> + <restrict id="results"> + <file file="${output}/redirector.out" /> + <and xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <contains text="${x} out" /> + <contains text="${y} out" /> + <contains text="${z} out" /> + <contains text="${x} err" /> + <contains text="${y} err" /> + <contains text="${z} err" /> + </and> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testRedirector3" depends="xyz" if="test.can.run"> + <apply executable="sh"> + <arg value="parrot.sh" /> + <fileset refid="xyz" /> + <redirector append="true" + output="${output}/redirector.out" + error="${output}/redirector.err" /> + </apply> + <au:assertTrue> + <and> + <resourcesmatch astext="true"> + <string value="${x} out${eol}${y} out${eol}${z} out" /> + <file file="${output}/redirector.out" /> + </resourcesmatch> + <resourcesmatch astext="true"> + <string value="${x} err${eol}${y} err${eol}${z} err" /> + <file file="${output}/redirector.err" /> + </resourcesmatch> + </and> + </au:assertTrue> + </target> + + <target name="testRedirector4" depends="xyz" if="test.can.run"> + <apply executable="sh"> + <arg value="parrot.sh" /> + <fileset refid="xyz" /> + <redirector output="${output}/redirector.out" logerror="true" + append="true" outputproperty="redirector4.out" /> + </apply> + + <au:assertTrue> + <resourcesmatch astext="true"> + <string value="${x} out${eol}${y} out${eol}${z} out" /> + <file file="${output}/redirector.out" /> + <propertyresource name="redirector4.out" /> + </resourcesmatch> + </au:assertTrue> + + <au:assertLogContains text="${x} err" /> + <au:assertLogContains text="${y} err" /> + <au:assertLogContains text="${z} err" /> + </target> + + <target name="testRedirector5" depends="xyz" if="test.can.run"> + <apply executable="sh"> + <redirector error="${output}/redirector.err" + errorproperty="redirector5.err" + output="${output}/redirector.out" + outputproperty="redirector5.out" + append="true" /> + <arg value="parrot.sh" /> + <fileset refid="xyz" /> + </apply> + <au:assertTrue> + <and> + <resourcesmatch astext="true"> + <string value="${x} out${eol}${y} out${eol}${z} out" /> + <file file="${output}/redirector.out" /> + <propertyresource name="redirector5.out" /> + </resourcesmatch> + <resourcesmatch astext="true"> + <string value="${x} err${eol}${y} err${eol}${z} err" /> + <file file="${output}/redirector.err" /> + <propertyresource name="redirector5.err" /> + </resourcesmatch> + </and> + </au:assertTrue> + </target> + + <target name="testRedirector6" depends="xyz" if="test.can.run"> + <apply executable="sh"> + <redirector append="true" outputproperty="redirector6.out" + errorproperty="redirector6.err"> + <outputmapper type="merge" to="${output}/redirector.out" /> + <errormapper type="merge" to="${output}/redirector.err" /> + </redirector> + <arg value="parrot.sh" /> + <filelist refid="xyzlist" /> + </apply> + + <au:assertTrue> + <and> + <resourcesmatch astext="true"> + <string value="${x} out${eol}${y} out${eol}${z} out" /> + <file file="${output}/redirector.out" /> + <propertyresource name="redirector6.out" /> + </resourcesmatch> + <resourcesmatch astext="true"> + <string value="${x} err${eol}${y} err${eol}${z} err" /> + <file file="${output}/redirector.err" /> + <propertyresource name="redirector6.err" /> + </resourcesmatch> + </and> + </au:assertTrue> + </target> + + <target name="testRedirector7" depends="xyz" if="test.can.run"> + <apply executable="sh"> + <redirector append="true" outputproperty="redirector7.out" + errorproperty="redirector7.err"> + <outputmapper type="merge" to="${output}/redirector.out" /> + <errormapper type="merge" to="${output}/redirector.err" /> + <errorfilterchain> + <replacestring from="err" to="ERROR!!!" /> + </errorfilterchain> + </redirector> + <arg value="parrot.sh" /> + <fileset refid="xyz" /> + </apply> + + <au:assertTrue> + <and> + <resourcesmatch astext="true"> + <string value="${x} out${eol}${y} out${eol}${z} out" /> + <file file="${output}/redirector.out" /> + <propertyresource name="redirector7.out" /> + </resourcesmatch> + <resourcesmatch astext="true"> + <string value="${x} ERROR!!!${eol}${y} ERROR!!!${eol}${z} ERROR!!!" /> + <file file="${output}/redirector.err" /> + <propertyresource name="redirector7.err" /> + </resourcesmatch> + </and> + </au:assertTrue> + </target> + + <target name="testRedirector8" depends="xyz" if="sed.can.run"> + <echo file="${input}/redirector.in">x y z${eol}</echo> + <apply executable="sed"> + <redirector append="true" outputproperty="redirector8.out" + errorproperty="redirector8.err"> + <inputmapper type="merge" to="${input}/redirector.in" /> + <outputmapper type="merge" to="${output}/redirector.out" /> + <errormapper type="merge" to="${output}/redirector.err" /> + </redirector> + <arg value="-f" /> + <fileset refid="xyz" /> + </apply> + + <au:assertTrue> + <and> + <resourcesmatch astext="true"> + <propertyresource name="redirector8.out" /> + <string value="blah y z${eol}x blah z${eol}x y blah" /> + <file file="${output}/redirector.out" /> + </resourcesmatch> + <equals arg1="${redirector8.err}" arg2="" /> + </and> + </au:assertTrue> + <assertEmptyFile file="${output}/redirector.err" /> + </target> + + <macrodef name="valRor9-12"> + <attribute name="n" /> + <sequential> + <au:assertTrue> + <and> + <equals arg1="" arg2="${redirector@{n}.err}" /> + <resourcesmatch astext="true"> + <string value="blah after y after z${eol}x after blah after z${eol}x after y after blah" /> + <propertyresource name="redirector@{n}.out" /> + <file file="${output}/redirector.out" /> + </resourcesmatch> + </and> + </au:assertTrue> + <assertEmptyFile file="${output}/redirector.err" /> + </sequential> + </macrodef> + + <target name="testRedirector9" depends="xyz" if="sed.can.run"> + <echo file="${input}/redirector.in">x before y before z${eol}</echo> + <apply executable="sed"> + <redirector outputproperty="redirector9.out" + errorproperty="redirector9.err" append="true"> + <inputfilterchain> + <replacestring from="before" to="after" /> + </inputfilterchain> + <inputmapper type="merge" to="${input}/redirector.in" /> + <outputmapper type="merge" to="${output}/redirector.out" /> + <errormapper type="merge" to="${output}/redirector.err" /> + </redirector> + <arg value="-f" /> + <fileset refid="xyz" /> + </apply> + + <valRor9-12 n="9" /> + </target> + + <target name="testRedirector10" depends="xyz" if="sed.can.run"> + <echo file="${input}/redirector.in">x before y before z${eol}</echo> + <apply executable="sed"> + <redirector outputproperty="redirector10.out" + errorproperty="redirector10.err" append="true"> + <outputfilterchain> + <replacestring from="before" to="after" /> + </outputfilterchain> + <outputmapper type="merge" to="${output}/redirector.out" /> + <errormapper type="merge" to="${output}/redirector.err" /> + </redirector> + <arg value="-f" /> + <srcfile /> + <arg value="${input}/redirector.in" /> + <filelist refid="xyzlist" /> + </apply> + + <valRor9-12 n="10" /> + </target> + + <target name="testRedirector11" depends="xyz" if="sed.can.run"> + <apply executable="sed"> + <redirector outputproperty="redirector11.out" + errorproperty="redirector11.err" + inputstring="x before y before z${eol}" + append="true"> + <inputfilterchain> + <replacestring from="before" to="after" /> + </inputfilterchain> + <outputmapper type="merge" to="${output}/redirector.out" /> + <errormapper type="merge" to="${output}/redirector.err" /> + </redirector> + <arg value="-f" /> + <fileset refid="xyz" /> + </apply> + + <valRor9-12 n="11" /> + </target> + + <target name="testRedirector12" depends="xyz" if="sed.can.run"> + <echo file="${input}/redirector.in">x before y before z${eol}</echo> + <apply executable="sed" output="${output}/redirector.out" + error="${output}/redirector.err"> + <redirector outputproperty="redirector12.out" + errorproperty="redirector12.err" append="true"> + <outputfilterchain> + <replacestring from="before" to="after" /> + </outputfilterchain> + <outputmapper type="glob" from="nomatch" to="nomatchout" /> + <errormapper type="glob" from="nomatch" to="nomatcherr" /> + </redirector> + <arg value="-f" /> + <srcfile /> + <arg value="${input}/redirector.in" /> + <filelist refid="xyzlist" /> + </apply> + + <valRor9-12 n="12" /> + </target> + + <target name="testRedirector13" depends="xyz" if="test.can.run"> + <apply executable="sh"> + <redirector> + <outputfilterchain> + <replacestring from="out" to="OUTPUT???" /> + </outputfilterchain> + <errorfilterchain> + <replacestring from="err" to="ERROR!!!" /> + </errorfilterchain> + </redirector> + <arg value="parrot.sh" /> + <fileset refid="xyz" /> + </apply> + + <au:assertLogContains text="${x} OUTPUT???" /> + <au:assertLogContains text="${y} OUTPUT???" /> + <au:assertLogContains text="${z} OUTPUT???" /> + <au:assertLogContains text="${x} ERROR!!!" /> + <au:assertLogContains text="${y} ERROR!!!" /> + <au:assertLogContains text="${z} ERROR!!!" /> + </target> + + <target name="testRedirector14" depends="xyz" if="sed.can.run"> + <echo file="${input}/redirector.in">z before y before x${eol}</echo> + <apply executable="sed"> + <redirector append="true" + inputstring="x before y before z${eol}"> + <outputfilterchain> + <replacestring from="before" to="after" /> + </outputfilterchain> + <inputmapper type="glob" from="x" to="${input}/redirector.in" /> + <outputmapper type="glob" from="y" to="${output}/redirector.out" /> + <errormapper type="glob" from="z" to="${output}/redirector.err" /> + </redirector> + <arg value="-f" /> + <fileset refid="xyz" /> + </apply> + + <assertEmptyFile file="${output}/redirector.err" /> + + <au:assertTrue> + <and> + <resourcesmatch astext="true"> + <string value="x after blah after z" /> + <file file="${output}/redirector.out" /> + </resourcesmatch> + </and> + </au:assertTrue> + <au:assertLogContains text="z after y after blahx after y after blah"/> + </target> + + <target name="pad"> + <condition property="pad" value=""> + <or> + <not> + <os family="dos" /> + </not> + <not> + <or> + <equals arg1="${ant.java.version}" arg2="1.1" /> + <equals arg1="${ant.java.version}" arg2="1.2" /> + </or> + </not> + </or> + </condition> + + <condition property="pad" value=" "> + <and> + <os family="dos" /> + <or> + <equals arg1="${ant.java.version}" arg2="1.2" /> + </or> + </and> + </condition> + + </target> + + <target name="testIgnoreMissing" depends="xyz,pad" if="echo.can.run"> + <filelist id="xylist" dir="${input}" files="x,y" /> + <delete file="${input}/z" /> + + <pathconvert property="xy" pathsep="${pad}${eol}" refid="xylist" /> + + <pathconvert property="xyz" pathsep="${pad}${eol}" refid="xyzlist" /> + + <apply executable="echo" ignoremissing="true" + outputproperty="ignoretrue" append="true"> + <filelist refid="xyzlist" /> + </apply> + + <apply executable="echo" ignoremissing="false" + outputproperty="ignorefalse" append="true"> + <filelist refid="xyzlist" /> + </apply> + + <au:assertTrue> + <and> + <equals arg1="${xy}${pad}" arg2="${ignoretrue}" /> + <equals arg1="${xyz}${pad}" arg2="${ignorefalse}" /> + </and> + </au:assertTrue> + </target> + + <target name="testForce" depends="xyz,pad" if="echo.can.run"> + <presetdef name="ekko"> + <apply executable="echo" append="true" dest="${input}"> + <filelist refid="xyzlist" /> + <mapper type="identity" /> + </apply> + </presetdef> + + <pathconvert property="xyz" pathsep="${pad}${eol}" refid="xyzlist" /> + + <ekko outputproperty="foo" /> + <ekko outputproperty="bar" force="true" /> + + <au:assertTrue> + <and> + <equals arg1="${foo}" arg2="" /> + <equals arg1="${bar}" arg2="${xyz}" /> + </and> + </au:assertTrue> + </target> + + <target name="testNoDest" depends="xyz" if="echo.can.run"> + <presetdef name="ekko"> + <apply executable="echo" addsourcefile="false" force="true"> + <filelist dir="${input}" files="x" /> + <globmapper from="*" to="${input}/*" /> + <targetfile /> + </apply> + </presetdef> + <ekko outputproperty="dest" dest="${input}" /> + <ekko outputproperty="nodest" /> + + <au:assertFileDoesntExist file="${dest}" /> + <au:assertFileExists file="${nodest}" /> + </target> + + <target name="testLsPath" if="ls.can.run" depends="xyz"> + <apply executable="ls" parallel="false" outputproperty="lsPathOut" + force="true" dest="${input}" append="true" type="both"> + <path path="${env.PATH}" /> + <identitymapper/> + </apply> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <propertyresource name="lsPathOut" /> + <containsregexp expression="^${ls.can.run}$" + xmlns="antlib:org.apache.tools.ant.types.resources.selectors" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testLsPathParallel" if="ls.can.run" depends="xyz"> + <apply executable="ls" parallel="true" outputproperty="lsPathParallelOut" + force="true" dest="${input}" append="true" type="both"> + <path path="${env.PATH}" /> + <identitymapper/> + </apply> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <propertyresource name="lsPathParallelOut" /> + <containsregexp expression="^${ls.can.run}$" + xmlns="antlib:org.apache.tools.ant.types.resources.selectors" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testSrcfilePrefix" if="test.can.run" depends="xyz"> + <apply executable="sh" force="true"> + <arg value="parrot.sh" /> + <srcfile prefix="-Dfoo="/> + <fileset refid="xyz" /> + </apply> + <au:assertLogContains text="-Dfoo=${x} out" /> + <au:assertLogContains text="-Dfoo=${y} out" /> + <au:assertLogContains text="-Dfoo=${z} out" /> + </target> + + <target name="testTargetfileSuffix" if="test.can.run" depends="xyz"> + <apply executable="sh" addsourcefile="false" dest="${input}"> + <arg value="parrot.sh" /> + <targetfile suffix=",x"/> + <fileset refid="xyz" /> + <globmapper from="*" to="*.bar"/> + </apply> + <au:assertLogContains text="${x}.bar,x out" /> + <au:assertLogContains text="${y}.bar,x out" /> + <au:assertLogContains text="${z}.bar,x out" /> + </target> + + <target name="testRedirectorWithParallel" if="test.can.run" depends="xyz"> + <apply executable="sh" dest="${input}" parallel="true" addsourcefile="yes"> + <arg value="parrot.sh" /> + <targetfile/> + <fileset refid="xyz" /> + <globmapper from="*" to="*.bar"/> + <redirector output="${output}/all_out.txt" append="yes"/> + </apply> + <au:assertResourceContains resource="${output}/all_out.txt" + value="x.bar out"/> + <au:assertResourceContains resource="${output}/all_out.txt" + value="x.bar err"/> + <au:assertResourceContains resource="${output}/all_out.txt" + value="x out"/> + <au:assertResourceContains resource="${output}/all_out.txt" + value="x err"/> + <au:assertResourceContains resource="${output}/all_out.txt" + value="y.bar out"/> + <au:assertResourceContains resource="${output}/all_out.txt" + value="y.bar err"/> + <au:assertResourceContains resource="${output}/all_out.txt" + value="y out"/> + <au:assertResourceContains resource="${output}/all_out.txt" + value="y err"/> + <au:assertResourceContains resource="${output}/all_out.txt" + value="z.bar out"/> + <au:assertResourceContains resource="${output}/all_out.txt" + value="z.bar err"/> + <au:assertResourceContains resource="${output}/all_out.txt" + value="z out"/> + <au:assertResourceContains resource="${output}/all_out.txt" + value="z err"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/exec-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/exec-test.xml new file mode 100644 index 00000000..25b00889 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/exec-test.xml @@ -0,0 +1,710 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="exec-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../antunit-base.xml" /> + + <macrodef name="assert-trimmed-resource-content"> + <attribute name="content" /> + <attribute name="astext" default="true" /> + <element name="resource" implicit="true" /> + <sequential> + <au:assertTrue> + <resourcesmatch astext="@{astext}"> + <string value="@{content}" /> + <concat> + <resource /> + <filterchain> + <trim /> + </filterchain> + </concat> + </resourcesmatch> + </au:assertTrue> + </sequential> + </macrodef> + + <target name="setUp"> + <mkdir dir="${input}" /> + <mkdir dir="${output}" /> + <property environment="env" /> + <!-- UNIX --> + <available file="sh" filepath="${env.PATH}" property="sh.executable" /> + <!-- CYGWIN --> + <available file="sh.exe" filepath="${env.PATH}" property="sh.exe.executable" /> + <condition property="test.can.run"> + <or> + <isset property="sh.executable" /> + <isset property="sh.exe.executable" /> + </or> + </condition> + <!-- UNIX --> + <available file="wc" filepath="${env.PATH}" property="wc.executable" /> + <!-- CYGWIN --> + <available file="wc.exe" filepath="${env.PATH}" property="wc.exe.executable" /> + <condition property="wc.can.run"> + <or> + <isset property="wc.executable" /> + <isset property="wc.exe.executable" /> + </or> + </condition> + <!-- UNIX --> + <available file="cat" filepath="${env.PATH}" property="cat.executable" /> + <!-- CYGWIN --> + <available file="cat.exe" filepath="${env.PATH}" property="cat.exe.executable" /> + <condition property="cat.can.run"> + <or> + <isset property="cat.executable" /> + <isset property="cat.exe.executable" /> + </or> + </condition> + </target> + + <target name="test-no-redirect" depends="setUp" if="test.can.run"> + <exec executable="sh"> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + </exec> + <au:assertLogContains text="${ant.file} out" /> + <au:assertLogContains text="${ant.file} err" /> + </target> + + <target name="test-redirect-output" depends="setUp" if="test.can.run"> + <exec executable="sh" output="${output}/redirect.out"> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} out${line.separator}${ant.file} err</string> + <file file="${output}/redirect.out" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="test-redirect-output-error" depends="setUp" if="test.can.run"> + <exec executable="sh" output="${output}/redirect.out" error="${output}/redirect.err"> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} out</string> + <file file="${output}/redirect.out" /> + </resourcesmatch> + </au:assertTrue> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} err</string> + <file file="${output}/redirect.err" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="test-redirect-output-outputproperty-logerror" depends="setUp" if="test.can.run"> + <exec executable="sh" logerror="true" + output="${output}/redirect.out" outputproperty="redirect.out"> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} out</string> + <file file="${output}/redirect.out" /> + <propertyresource name="redirect.out" /> + </resourcesmatch> + </au:assertTrue> + <au:assertLogContains text="${ant.file} err" /> + </target> + + <target name="test-redirect-output-outputproperty-error-errorproperty" + depends="setUp" if="test.can.run"> + <exec executable="sh" + error="${output}/redirect.err" errorproperty="redirect.err" + output="${output}/redirect.out" outputproperty="redirect.out"> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} out</string> + <file file="${output}/redirect.out" /> + <propertyresource name="redirect.out" /> + </resourcesmatch> + </au:assertTrue> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} err</string> + <file file="${output}/redirect.err" /> + <propertyresource name="redirect.err" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="test-redirect-inputstring-output-outputproperty-error-errorproperty" + depends="setUp" if="wc.can.run"> + <exec executable="wc" inputstring="x y z" + error="${output}/redirect.err" errorproperty="redirect.err" + output="${output}/redirect.out" outputproperty="redirect.out"> + <arg value="-w" /> + </exec> + <au:assertTrue> + <length length="0"> + <file file="${output}/redirect.err" /> + <propertyresource name="redirect.err" /> + </length> + </au:assertTrue> + <assert-trimmed-resource-content content="3"> + <file file="${output}/redirect.out" /> + </assert-trimmed-resource-content> + <assert-trimmed-resource-content content="3"> + <propertyresource name="redirect.out" /> + </assert-trimmed-resource-content> + </target> + + <target name="test-redirect-input-output-outputproperty-error-errorproperty" + depends="setUp" if="wc.can.run"> + <echo file="${input}/redirect.in">x y z</echo> + <exec executable="wc" input="${input}/redirect.in" + error="${output}/redirect.err" errorproperty="redirect.err" + output="${output}/redirect.out" outputproperty="redirect.out"> + <arg value="-w" /> + </exec> + <au:assertTrue> + <length length="0"> + <file file="${output}/redirect.err" /> + <propertyresource name="redirect.err" /> + </length> + </au:assertTrue> + <assert-trimmed-resource-content content="3"> + <file file="${output}/redirect.out" /> + </assert-trimmed-resource-content> + <assert-trimmed-resource-content content="3"> + <propertyresource name="redirect.out" /> + </assert-trimmed-resource-content> + </target> + + <target name="test-redirect-input-output-outputproperty-error" + depends="setUp" if="wc.can.run"> + <exec executable="wc" inputstring="x y z" + error="${output}/redirect.err" + output="${output}/redirect.out" outputproperty="redirect.out"> + <arg value="-w" /> + </exec> + <au:assertTrue> + <length length="0"> + <file file="${output}/redirect.err" /> + </length> + </au:assertTrue> + <concat> + <file file="${output}/redirect.out" /> + <propertyresource name="redirect.out" /> + </concat> + <assert-trimmed-resource-content content="3"> + <file file="${output}/redirect.out" /> + </assert-trimmed-resource-content> + <assert-trimmed-resource-content content="3"> + <propertyresource name="redirect.out" /> + </assert-trimmed-resource-content> + </target> + + <target name="test-multiple-redirectors" description="fail" + depends="setUp" if="test.can.run"> + <au:expectfailure> + <exec executable="sh"> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + <redirector output="${output}/redirector.out" /> + <redirector output="whocares" /> + </exec> + </au:expectfailure> + </target> + + <target name="test-redirector-output" depends="setUp" if="test.can.run"> + <exec executable="sh"> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + <redirector output="${output}/redirector.out" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} out${line.separator}${ant.file} err</string> + <file file="${output}/redirector.out" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="test-redirector-output-error" depends="setUp" if="test.can.run"> + <exec executable="sh"> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + <redirector output="${output}/redirector.out" error="${output}/redirector.err" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} out</string> + <file file="${output}/redirector.out" /> + </resourcesmatch> + </au:assertTrue> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} err</string> + <file file="${output}/redirector.err" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="test-redirector-output-outputproperty-logerror" depends="setUp" if="test.can.run"> + <exec executable="sh"> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + <redirector output="${output}/redirector.out" logerror="true" + outputproperty="redirector.out" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} out</string> + <file file="${output}/redirector.out" /> + <propertyresource name="redirector.out" /> + </resourcesmatch> + </au:assertTrue> + <au:assertLogContains text="${ant.file} err" /> + </target> + + <target name="test-redirector-output-outputproperty-error-errorproperty" + depends="setUp" if="test.can.run"> + <exec executable="sh"> + <redirector error="${output}/redirector.err" errorproperty="redirector.err" + output="${output}/redirector.out" outputproperty="redirector.out" /> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} out</string> + <file file="${output}/redirector.out" /> + <propertyresource name="redirector.out" /> + </resourcesmatch> + </au:assertTrue> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} err</string> + <file file="${output}/redirector.err" /> + <propertyresource name="redirector.err" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="test-redirector-outputproperty-errorproperty-outputmapper-errormapper" + depends="setUp" if="test.can.run"> + <exec executable="sh"> + <redirector outputproperty="redirector.out" + errorproperty="redirector.err"> + <outputmapper type="merge" to="${output}/redirector.out" /> + <errormapper type="merge" to="${output}/redirector.err" /> + </redirector> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} out</string> + <file file="${output}/redirector.out" /> + <propertyresource name="redirector.out" /> + </resourcesmatch> + </au:assertTrue> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} err</string> + <file file="${output}/redirector.err" /> + <propertyresource name="redirector.err" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="test-redirector-outputproperty-errorproperty-outputmapper-errormapper-errorfilterchain" + depends="setUp" if="test.can.run"> + <exec executable="sh"> + <redirector outputproperty="redirector.out" + errorproperty="redirector.err"> + <outputmapper type="merge" to="${output}/redirector.out" /> + <errormapper type="merge" to="${output}/redirector.err" /> + <errorfilterchain> + <replacestring from="err" to="ERROR!!!" /> + </errorfilterchain> + </redirector> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} out</string> + <file file="${output}/redirector.out" /> + <propertyresource name="redirector.out" /> + </resourcesmatch> + </au:assertTrue> + <au:assertTrue> + <resourcesmatch astext="true"> + <string>${ant.file} ERROR!!!</string> + <file file="${output}/redirector.err" /> + <propertyresource name="redirector.err" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="test-redirector-outputproperty-errorproperty-inputmapper-outputmapper-errormapper" + depends="setUp" if="wc.can.run"> + <echo file="${input}/redirector.in">x y z</echo> + <exec executable="wc"> + <redirector outputproperty="redirector.out" + errorproperty="redirector.err"> + <inputmapper type="merge" to="${input}/redirector.in" /> + <outputmapper type="merge" to="${output}/redirector.out" /> + <errormapper type="merge" to="${output}/redirector.err" /> + </redirector> + <arg value="-w" /> + </exec> + <assert-trimmed-resource-content content="3"> + <file file="${output}/redirector.out" /> + </assert-trimmed-resource-content> + <assert-trimmed-resource-content content="3"> + <propertyresource name="redirector.out" /> + </assert-trimmed-resource-content> + <au:assertTrue> + <length length="0"> + <file file="${output}/redirector.err" /> + <propertyresource name="redirector.err" /> + </length> + </au:assertTrue> + </target> + + <target name="test-redirector-outputproperty-errorproperty-inputfilterchain-inputmapper-outputmapper-errormapper" + depends="setUp" if="cat.can.run"> + <echo file="${input}/redirector.in">blah before blah</echo> + <exec executable="cat"> + <redirector outputproperty="redirector.out" + errorproperty="redirector.err"> + <inputfilterchain> + <replacestring from="before" to="after" /> + </inputfilterchain> + <inputmapper type="merge" to="${input}/redirector.in" /> + <outputmapper type="merge" to="${output}/redirector.out" /> + <errormapper type="merge" to="${output}/redirector.err" /> + </redirector> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string value="blah after blah" /> + <file file="${output}/redirector.out" /> + <propertyresource name="redirector.out" /> + </resourcesmatch> + </au:assertTrue> + <au:assertTrue> + <length length="0"> + <file file="${output}/redirector.err" /> + <propertyresource name="redirector.err" /> + </length> + </au:assertTrue> + </target> + + <target name="test-redirector-outputproperty-errorproperty-outputfilterchain-outputmapper-errormapper" + depends="setUp" if="cat.can.run"> + <echo file="${input}/redirector.in">blah before blah</echo> + <exec executable="cat"> + <redirector outputproperty="redirector.out" + errorproperty="redirector.err"> + <outputfilterchain> + <replacestring from="before" to="after" /> + </outputfilterchain> + <outputmapper type="merge" to="${output}/redirector.out" /> + <errormapper type="merge" to="${output}/redirector.err" /> + </redirector> + <arg value="${input}/redirector.in" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string value="blah after blah" /> + <file file="${output}/redirector.out" /> + <propertyresource name="redirector.out" /> + </resourcesmatch> + </au:assertTrue> + <au:assertTrue> + <length length="0"> + <file file="${output}/redirector.err" /> + <propertyresource name="redirector.err" /> + </length> + </au:assertTrue> + </target> + + <target name="test-redirector-outputproperty-errorproperty-inputstring-inputfilterchain-outputmapper-errormapper" + depends="setUp" if="cat.can.run"> + <exec executable="cat"> + <redirector outputproperty="redirector.out" + errorproperty="redirector.err" + inputstring="blah before blah"> + <inputfilterchain> + <replacestring from="before" to="after" /> + </inputfilterchain> + <outputmapper type="merge" to="${output}/redirector.out" /> + <errormapper type="merge" to="${output}/redirector.err" /> + </redirector> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string value="blah after blah" /> + <file file="${output}/redirector.out" /> + <propertyresource name="redirector.out" /> + </resourcesmatch> + </au:assertTrue> + <au:assertTrue> + <length length="0"> + <file file="${output}/redirector.err" /> + <propertyresource name="redirector.err" /> + </length> + </au:assertTrue> + </target> + + <target name="test-redirect-output-error-redirector-outputproperty-errorproperty-outputfilterchain-invalid-outputmapper-invalid-errormapper" + depends="setUp" if="cat.can.run"> + <echo file="${input}/redirector.in">blah before blah</echo> + <exec executable="cat" output="${output}/redirector.out" error="${output}/redirector.err"> + <redirector outputproperty="redirector.out" + errorproperty="redirector.err"> + <outputfilterchain> + <replacestring from="before" to="after" /> + </outputfilterchain> + <outputmapper type="glob" from="nomatch" to="${output}/nomatchout" /> + <errormapper type="glob" from="nomatch" to="${output}/nomatcherr" /> + </redirector> + <arg value="${input}/redirector.in" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <string value="blah after blah" /> + <file file="${output}/redirector.out" /> + <propertyresource name="redirector.out" /> + </resourcesmatch> + </au:assertTrue> + <au:assertTrue> + <length length="0"> + <file file="${output}/redirector.err" /> + <propertyresource name="redirector.err" /> + </length> + </au:assertTrue> + <au:assertTrue> + <resourcecount count="0"> + <fileset dir="${output}" includes="nomatch???" /> + </resourcecount> + </au:assertTrue> + </target> + + <target name="test-redirector-outputfilterchain-errorfilterchain" + depends="setUp" if="test.can.run"> + <exec executable="sh"> + <redirector> + <outputfilterchain> + <replacestring from="out" to="OUTPUT???" /> + </outputfilterchain> + <errorfilterchain> + <replacestring from="err" to="ERROR!!!" /> + </errorfilterchain> + </redirector> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + </exec> + <au:assertLogContains text="${ant.file} OUTPUT???" /> + <au:assertLogContains text="${ant.file} ERROR!!!" /> + </target> + + <target name="test-redirector-inputstring-outputfilterchain-outputmapper-errormapper" + depends="setUp" if="cat.can.run"> + <exec executable="cat"> + <redirector inputstring="blah before blah"> + <outputfilterchain> + <replacestring from="before" to="after" /> + </outputfilterchain> + <outputmapper type="glob" from="nomatch" to="nomatchout" /> + <errormapper type="glob" from="nomatch" to="nomatcherr" /> + </redirector> + </exec> + <au:assertLogContains text="blah after blah" /> + </target> + + <target name="test-redirector-input-output-inputencoding-outputencoding" + depends="setUp" if="cat.can.run"> + <exec executable="cat"> + <redirector input="input/iso8859-1" output="${output}/redirector.out" + inputencoding="ISO8859_1" outputencoding="UTF8" /> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <file file="${output}/redirector.out" /> + <file file="expected/utf-8" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="test-redirector-inputstring-output-error" depends="setUp" if="test.can.run"> + <exec executable="sh"> + <redirector inputstring="exit" + output="${output}/redirector.out" error="${output}/redirector.err" /> + </exec> + <au:assertTrue> + <and> + <available file="${output}/redirector.out" type="file" /> + <available file="${output}/redirector.err" type="file" /> + </and> + </au:assertTrue> + </target> + + <target name="test-redirector-inputstring-nocreateempty-output-error" + depends="setUp" if="test.can.run"> + <exec executable="sh"> + <redirector inputstring="exit" createemptyfiles="false" + output="${output}/redirector.out" error="${output}/redirector.err" /> + </exec> + <au:assertTrue> + <not> + <or> + <available file="${output}/redirector.out" type="file" /> + <available file="${output}/redirector.err" type="file" /> + </or> + </not> + </au:assertTrue> + </target> + + <target name="test-redirector-alwayslog-outputproperty" depends="setUp" if="test.can.run"> + <exec executable="sh"> + <arg value="parrot.sh" /> + <arg value="${ant.file}" /> + <redirector alwayslog="true" logerror="true" + outputproperty="redirector.out" /> + </exec> + <au:assertTrue> + <equals arg1="${ant.file} out" arg2="${redirector.out}" /> + </au:assertTrue> + <au:assertLogContains text="${ant.file} out" /> + </target> + + <!-- test will succeed as the OS wont match--> + <target name="testExecUnknownOS"> + <exec executable="nonexistent-program-we-expect" + failonerror="true" + os="ZX81"> + </exec> + </target> + + <target name="testExecOSFamily"> + <exec executable="uptime" + failonerror="true" + osFamily="unix"> + </exec> + <exec executable="cmd.exe" + failonerror="true" + osFamily="winnt"> + <arg value="/c" /> + <arg value="time /t" /> + </exec> + </target> + + <target name="testExecInconsistentSettings"> + <exec executable="nonexistent-program-we-expect" + failonerror="true" + osFamily="WIN9X" + os="linux unix"> + </exec> + </target> + + <target name="testDoesntWaitForChildren" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=5003"> + <condition property="java" + value="${java.home}/bin/java.exe" + else="${java.home}/bin/java"> + <os family="dos"/> + </condition> + <mkdir dir="${input}/org/example"/> + <pathconvert dirsep="/" property="out"> + <path location="${output}"/> + </pathconvert> + <pathconvert dirsep="/" property="javaP"> + <path location="${java}"/> + </pathconvert> + <echo file="${input}/org/example/CallHello.java"><![CDATA[ +package org.example; +public class CallHello { + public static void main(String[] args) + throws Exception { + String[] cmd = new String[] { + "${javaP}", "-cp", "${out}", "org.example.Hello" + }; + Runtime.getRuntime().exec(cmd); + Thread.sleep(1 * 1000); + System.out.println("finished"); + } +}]]></echo> + <echo file="${input}/org/example/Hello.java"><![CDATA[ +package org.example; +public class Hello { + public static void main(String[] args) + throws Exception { + for (int i = 0; i < 20; ++i) { + System.out.println("Hello " + i); + System.out.flush(); + Thread.sleep(1 * 1000); + } + } +}]]></echo> + <mkdir dir="${output}"/> + <javac srcdir="${input}" destdir="${output}"/> + <exec executable="${java}" failonerror="true"> + <arg value="-cp"/> + <arg value="${output}"/> + <arg value="org.example.CallHello"/> + </exec> + <au:assertLogContains text="finished"/> + <au:assertLogDoesntContain text="Hello 20"/> + </target> + + <target name="test-output-is-split-into-lines" if="cat.can.run" depends="setUp"> + <echo file="${input}/redirector.in">1
2
3</echo> + <echo file="${output}/expected">1${line.separator}2${line.separator}3</echo> + <exec executable="cat"> + <redirector output="${output}/redirector.out" + input="${input}/redirector.in"/> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <file file="${output}/redirector.out" /> + <file file="${output}/expected" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="test-binary-output-is-not-split-into-lines" if="cat.can.run" depends="setUp"> + <echo file="${input}/redirector.in">1
2
3</echo> + <exec executable="cat"> + <redirector output="${output}/redirector.out" binaryOutput="true" + input="${input}/redirector.in"/> + </exec> + <au:assertTrue> + <resourcesmatch astext="true"> + <file file="${output}/redirector.out" /> + <file file="${input}/redirector.in" /> + </resourcesmatch> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/expected/utf-8 b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/expected/utf-8 new file mode 100644 index 00000000..c1949bc1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/expected/utf-8 @@ -0,0 +1 @@ +äöüÄÖÜß diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/input/iso8859-1 b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/input/iso8859-1 new file mode 100644 index 00000000..09044014 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/input/iso8859-1 @@ -0,0 +1 @@ +äöüÄÖÜß diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/parrot.sh b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/parrot.sh new file mode 100644 index 00000000..2467f23a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/exec/parrot.sh @@ -0,0 +1,19 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You 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. +for arg in "$@" ; do + echo $arg out + sleep 1 + echo $arg err>&2 +done diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/fail-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/fail-test.xml new file mode 100644 index 00000000..d525b731 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/fail-test.xml @@ -0,0 +1,59 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<project name="echo-test" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="testIfNotSet"> + <au:expectfailure> + <fail unless="${if}"/> + </au:expectfailure> + <fail if="${if}"/> + </target> + + <target name="testIfSet"> + <property name="if" value="whatever"/> + <au:expectfailure> + <fail unless="${if}"/> + </au:expectfailure> + <fail if="${if}"/> + + <fail unless="if"/> + <au:expectfailure> + <fail if="if"/> + </au:expectfailure> + </target> + + <target name="testIfTrue"> + <property name="if" value="true"/> + <fail unless="${if}"/> + <au:expectfailure> + <fail if="${if}"/> + </au:expectfailure> + </target> + + <target name="testIfFalse"> + <property name="if" value="false"/> + <au:expectfailure> + <fail unless="${if}"/> + </au:expectfailure> + <fail if="${if}"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/get-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/get-test.xml new file mode 100644 index 00000000..0bca337c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/get-test.xml @@ -0,0 +1,125 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<project name="get-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <property name="location" value="http://ant.apache.org/webtest/gettest" /> + + <target name="setUp"> + <mkdir dir="${output}" /> + </target> + + <target name="testSeeOtherRedirect"> + <get src="${location}/other.txt" dest="${output}/other.tmp"/> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <file file="${output}/other.tmp" /> + <contains text="seeother redirect succeeded" /> + </restrict> + </resourcecount> + </au:assertTrue> + <au:assertLogContains text="other.txt moved to http" /> + </target> + + <target name="testPermanentRedirect"> + <get src="${location}/permanent.txt" dest="${output}/permanent.tmp"/> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <file file="${output}/permanent.tmp" /> + <contains text="permanent redirect succeeded" /> + </restrict> + </resourcecount> + </au:assertTrue> + <au:assertLogContains text="permanent.txt permanently moved to http" /> + </target> + + <target name="testTemporaryRedirect"> + <get src="${location}/temp.txt" dest="${output}/temp.txt"/> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <file file="${output}/temp.txt" /> + <contains text="temporary redirect succeeded" /> + </restrict> + </resourcecount> + </au:assertTrue> + <au:assertLogContains text="temp.txt moved to http" /> + </target> + + <target name="testStatusCode307Redirect"> + <get src="${location}/307.txt" dest="${output}/307.txt"/> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <file file="${output}/307.txt" /> + <contains text="307 status code redirect succeeded" /> + </restrict> + </resourcecount> + </au:assertTrue> + <au:assertLogContains text="307.txt moved to http" /> + </target> + + <target name="test5LevelsOfRedirect"> + <get src="${location}/redir5.txt" dest="${output}/redir5.tmp"/> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <file file="${output}/redir5.tmp" /> + <contains text="5 levels of redirect succeeded" /> + </restrict> + </resourcecount> + </au:assertTrue> + + <au:assertLogContains text="redir5.txt moved to http" /> + + <au:assertLogContains text="redir5-4.txt moved to http" /> + </target> + + + <target name="testInfiniteRedirect"> + <au:expectfailure expectedmessage="More than 25 times redirected, giving up"> + <get src="${location}/infinite.txt" dest="${output}/infinite.tmp"/> + </au:expectfailure> + </target> + + + <target name="testNestedResources"> + <get dest="${output}/downloads"> + <url url="http://ant.apache.org/index.html"/> + <url url="http://ant.apache.org/faq.html"/> + </get> + <au:assertFileExists file="${output}/downloads/index.html"/> + <au:assertFileExists file="${output}/downloads/faq.html"/> + </target> + + <target name="XtestRelativeRedirect"> + <get src="${location}/local.cgi" dest="${output}/other.tmp"/> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <file file="${output}/other.tmp" /> + <contains text="local redirect succeeded"/> + </restrict> + </resourcecount> + </au:assertTrue> + <au:assertLogContains text="local.cgi moved to http" /> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/gzip-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/gzip-test.xml new file mode 100644 index 00000000..38f0a7a6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/gzip-test.xml @@ -0,0 +1,46 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <!-- note relies on antunit 1.1 --> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${output}" /> + <mkdir dir="${output}/empty" /> + <touch file="${output}/fileone" /> + <touch file="${output}/filetwo" /> + </target> + + <target name="testFailNone"> + <au:expectfailure expectedmessage="No resource selected, gzip needs exactly one resource." message="Should have thrown an exception"> + <gzip destfile="${output}/file.gz"> + <fileset dir="${output}/empty" /> + </gzip> + </au:expectfailure> + </target> + + <target name="testFailTwo"> + <au:expectfailure expectedmessage="gzip cannot handle multiple resources at once. (2 resources were selected.)" message="Should have thrown an exception"> + <gzip destfile="${output}/file.gz"> + <fileset dir="${output}" /> + </gzip> + </au:expectfailure> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/hostinfo-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/hostinfo-test.xml new file mode 100644 index 00000000..a044b9b1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/hostinfo-test.xml @@ -0,0 +1,64 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="hostinfo-test" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <property name="undef-name" value="nonexistenthost.nonexistentdomain" /> + <property name="undef-hostname" value="nonexistenthost" /> + <property name="undef-domainname" value="nonexistentdomain" /> + + <property name="undef-ip4" value="0.0.0.0" /> + <property name="undef-ip6" value="::" /> + + <property name="xs4all-hostname" value="www.xs4all.nl" /> + <property name="xs4all-domain" value="xs4all.nl" /> + <property name="xs4all-realhost" value="www" /> + <property name="xs4all-ip4" value="194.109.6.92" /> + + <target name="setUp"> + </target> + + <target name="testLocal" depends="setUp"> + <hostinfo prefix="local" /> + <!-- Do not know what to expect here, machine dependent --> + </target> + + <target name="testForward" depends="setUp"> + <hostinfo host="${xs4all-hostname}"/> + <au:assertEquals expected="${xs4all-realhost}" actual="${NAME}"/> + <au:assertEquals expected="${xs4all-domain}" actual="${DOMAIN}"/> + <au:assertEquals expected="${xs4all-ip4}" actual="${ADDR4}"/> + </target> + + <target name="testReverse" depends="setUp"> + <hostinfo prefix="reverse" host="${xs4all-ip4}"/> + <au:assertEquals expected="${xs4all-realhost}" actual="${reverse.NAME}"/> + <au:assertEquals expected="${xs4all-domain}" actual="${reverse.DOMAIN}"/> + <au:assertEquals expected="${xs4all-ip4}" actual="${reverse.ADDR4}"/> + </target> + + <target name="testUndef" depends="setUp"> + <hostinfo prefix="undef" host="${undef-name}"/> + <au:assertEquals expected="${undef-hostname}" actual="${undef.NAME}"/> + <au:assertEquals expected="${undef-domainname}" actual="${undef.DOMAIN}"/> + <au:assertEquals expected="${undef-ip4}" actual="${undef.ADDR4}"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/import-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/import-test.xml new file mode 100644 index 00000000..f9e4b055 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/import-test.xml @@ -0,0 +1,55 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <import> + <file file="importtests/a.xml"/> + </import> + <import file="importtests/b.xml" as="c"/> + + <target name="testNoExplicitPrefix" depends="a.a"> + <au:assertEquals expected="bar" actual="${foo}"/> + </target> + + <target name="testExplicitPrefix" depends="c.b"> + <au:assertEquals expected="baz" actual="${foo}"/> + </target> + + <target name="testNoExplicitPrefixUsedWithoutPrefix" depends="a"> + <au:assertEquals expected="bar" actual="${foo}"/> + </target> + + <target name="testExplicitPrefixUsedWithoutPrefix" depends="b"> + <au:assertEquals expected="baz" actual="${foo}"/> + </target> + + <import> + <javaresource name="override.xml"> + <classpath location="importtests"/> + </javaresource> + </import> + + <target name="setProperty"> + <property name="prop" value="in including/importing"/> + </target> + + <target name="testOverride" depends="override.dummy"> + <au:assertEquals expected="in including/importing" actual="${prop}"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/import-url-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/import-url-test.xml new file mode 100644 index 00000000..103ece3e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/import-url-test.xml @@ -0,0 +1,101 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <mkdir dir="${output}"/> + <mkdir dir="${input}/a/b"/> + <mkdir dir="${input}/a/c"/> + <echo file="${input}/a/b/outer.xml"><![CDATA[ +<project name="outer"> + <import file="../c/inner.xml"/> +</project> +]]></echo> + <echo file="${input}/a/c/inner.xml"><![CDATA[ +<project name="inner"> + <target name="foo"> + <echo>In inner</echo> + <echo>ant.file.inner is ${ant.file.inner}</echo> + <echo>type is ${ant.file.type.inner}</echo> + <loadproperties> + <url baseUrl="${ant.file.inner}" relativePath="test.properties"/> + </loadproperties> + <echo>foo is ${foo}</echo> + </target> +</project>]]></echo> + <echo file="${input}/a/c/test.properties"><![CDATA[ +foo=bar +]]></echo> + <echo file="${input}/a/b/external-import.xml"><![CDATA[ +<project name="external-import"> + <import file="${output}/imported.xml"/> +</project> +]]></echo> + <echo file="${output}/imported.xml"><![CDATA[ +<project name="imported"> + <target name="bar"> + <echo>In imported</echo> + </target> +</project> +]]></echo> + <jar destfile="${test.jar}"> + <fileset dir="${input}"/> + </jar> + <delete dir="${input}"/> + + <import> + <javaresource name="a/b/outer.xml"> + <classpath location="${test.jar}"/> + </javaresource> + </import> + <import> + <javaresource name="a/b/outer.xml"> + <classpath location="${test.jar}"/> + </javaresource> + </import> + <import> + <javaresource name="a/b/external-import.xml"> + <classpath location="${test.jar}"/> + </javaresource> + </import> + + <target name="testImportOfNestedFile" depends="foo"> + <au:assertLogContains text="In inner"/> + <au:assertLogContains text="type is url"/> + <au:assertLogContains text="foo is bar"/> + </target> + + <target name="testImportOfNestedFileWithAbsolutePath" depends="bar" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50953"> + <au:assertLogContains text="In imported"/> + </target> + + <target name="tearDown"> + <taskdef name="close" + classname="org.apache.tools.ant.taskdefs.CloseResources"/> + <close> + <javaresource name="a/b/outer.xml"> + <classpath location="${test.jar}"/> + </javaresource> + </close> + <delete file="${test.jar}" quiet="true" deleteonexit="true"/> + <!-- Calling antunit-base.tearDown sometimes causes ISEs in <import> in Ant-Build-Matrix: --> + <delete dir="${input}"/> + <delete dir="${output}"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/a.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/a.xml new file mode 100644 index 00000000..6082990f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/a.xml @@ -0,0 +1,23 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="a"> + <target name="a"> + <property name="foo" value="bar"/> + </target> +</project> + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/b.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/b.xml new file mode 100644 index 00000000..546badf5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/b.xml @@ -0,0 +1,23 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="b"> + <target name="b"> + <property name="foo" value="baz"/> + </target> +</project> + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/nested.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/nested.xml new file mode 100644 index 00000000..28d7ad4b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/nested.xml @@ -0,0 +1,21 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project> + <include file="b.xml" as="b" prefixSeparator="::"/> + <include file="a.xml" as="a" prefixSeparator=""/> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/override.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/override.xml new file mode 100644 index 00000000..97fd320b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/override.xml @@ -0,0 +1,25 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="override"> + <target name="setProperty"> + <property name="prop" value="in included/imported"/> + </target> + + <target name="dummy" depends="setProperty"/> +</project> + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/w.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/w.xml new file mode 100644 index 00000000..e400c501 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/w.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="w"> + <echo>${ant.file.w}</echo> + <include file="x.xml"/> + <target name="ww" depends="x.xx, x.y.yy, x.y.z.zz"/> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/x.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/x.xml new file mode 100644 index 00000000..a509e574 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/x.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="x"> + <echo>${ant.file.x}</echo> + <include file="y.xml"/> + <target name="xx" depends="y.yy, y.z.zz"/> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/y.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/y.xml new file mode 100644 index 00000000..0e54fa83 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/y.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="y"> + <echo>${ant.file.y}</echo> + <include file="z.xml" as="z"/> + <target name="yy" depends="z.zz"/> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/z.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/z.xml new file mode 100644 index 00000000..607dee7e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/importtests/z.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="z"> + <echo>${ant.file.z}</echo> + <target name="zz"/> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/include-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/include-test.xml new file mode 100644 index 00000000..7e1a4523 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/include-test.xml @@ -0,0 +1,58 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <include> + <file file="importtests/a.xml"/> +</include> + <include file="importtests/b.xml" as="c"/> + + <target name="testNoExplicitPrefix" depends="a.a"> + <au:assertEquals expected="bar" actual="${foo}"/> + </target> + + <target name="testExplicitPrefix" depends="c.b"> + <au:assertEquals expected="baz" actual="${foo}"/> + </target> + + <include file="importtests/override.xml"/> + + <target name="setProperty"> + <property name="prop" value="in including/importing"/> + </target> + + <target name="testNoOverride" depends="override.dummy"> + <au:assertEquals expected="in included/imported" actual="${prop}"/> + </target> + + <include as="nested"> + <javaresource name="nested.xml"> + <classpath location="importtests"/> + </javaresource> + </include> + + <!-- really only tests that the targets have the expected names by + forcing an exception if the dependencies don't exist --> + <target name="testNesting" depends="nested.b::b, nested.aa"/> + <target name="testNoExplicitPrefixNested"> + <ant target="x.y.z.zz" antfile="importtests/w.xml"/> + </target> + + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/jar-spi-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/jar-spi-test.xml new file mode 100644 index 00000000..c05311aa --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/jar-spi-test.xml @@ -0,0 +1,149 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit"> + <property name="jar.dir" location="jar_spi_dir"/> + <property name="jar.src.dir" location="jar_spi_dir/src"/> + <property name="jar.src.file" location="jar_spi_dir/src/a_file"/> + + <available property="jdk1.4+" classname="java.lang.CharSequence"/> + <condition property="some.regexp.support"> + <or> + <isset property="jdk1.4+"/> + <isset property="apache.regexp.present"/> + <isset property="apache.oro.present"/> + </or> + </condition> + + <target name="init"> + <mkdir dir="${jar.src.dir}"/> + <delete quiet="yes" file="${jar.src.file}"/> + <touch file="${jar.src.file}"/> + <delete quiet="yes" file="${jar.dir}/file.jar"/> + <delete quiet="yes" dir="${jar.dir}/output"/> + </target> + + <target name="test-simple" depends="init" if="some.regexp.support"> + + <jar jarfile="${jar.dir}/file.jar"> + <fileset dir="${jar.src.dir}"/> + <service type="a.b.c" provider="a.b.c.d"/> + </jar> + + <unjar src="${jar.dir}/file.jar" + dest="${jar.dir}/output"/> + + <loadfile property="simple" + srcfile="${jar.dir}/output/META-INF/services/a.b.c" + encoding="UTF-8"/> + + <au:assertTrue> + <matches string="${simple}" pattern="^a\.b\.c\.d$"/> + </au:assertTrue> + + </target> + + <target name="test-providers" depends="init" if="some.regexp.support"> + + <jar jarfile="${jar.dir}/file.jar"> + <fileset dir="${jar.src.dir}"/> + <service type="a.b.c"> + <provider classname="a.X"/> + <provider classname="a.D"/> + </service> + </jar> + + <unjar src="${jar.dir}/file.jar" + dest="${jar.dir}/output"/> + + <loadfile property="providers" + srcfile="${jar.dir}/output/META-INF/services/a.b.c" + encoding="UTF-8"/> + <au:assertTrue> + <matches string="${providers}" pattern="^a\.X\na\.D$"/> + </au:assertTrue> + + </target> + + <target name="test-multi" depends="init" if="some.regexp.support"> + + <jar jarfile="${jar.dir}/file.jar"> + <fileset dir="${jar.src.dir}"/> + <service type="a.b.c"> + <provider classname="a.X"/> + <provider classname="a.D"/> + </service> + <service type="javax.a.service"> + <provider classname="a.O.T"/> + <provider classname="a.B"/> + </service> + </jar> + + <unjar src="${jar.dir}/file.jar" + dest="${jar.dir}/output"/> + + <loadfile property="multi-a" + srcfile="${jar.dir}/output/META-INF/services/a.b.c" + encoding="UTF-8"/> + + <au:assertTrue> + <matches string="${multi-a}" pattern="^a\.X\na\.D$"/> + </au:assertTrue> + + <loadfile property="multi-b" + srcfile="${jar.dir}/output/META-INF/services/javax.a.service" + encoding="UTF-8"/> + + <au:assertTrue> + <matches string="${multi-b}" pattern="^a\.O\.T\na\.B$"/> + </au:assertTrue> + + </target> + + <target name="test-reject-no-type" depends="init"> + <au:expectfailure> + <jar jarfile="${jar.dir}/file.jar"> + <fileset dir="${jar.src.dir}"/> + <service provider="a.X"/> + </jar> + </au:expectfailure> + </target> + + <target name="test-reject-no-provider" depends="init"> + <au:expectfailure> + <jar jarfile="${jar.dir}/file.jar"> + <fileset dir="${jar.src.dir}"/> + <service type="a.X"/> + </jar> + </au:expectfailure> + </target> + + <target name="test-reject-no-classname" depends="init"> + <au:expectfailure> + <jar jarfile="${jar.dir}/file.jar"> + <fileset dir="${jar.src.dir}"/> + <service type="a.X"> + <provider/> + </service> + </jar> + </au:expectfailure> + </target> + + <target name="tearDown"> + <delete quiet="yes" dir="${jar.dir}"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/jar-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/jar-test.xml new file mode 100644 index 00000000..c2c8834e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/jar-test.xml @@ -0,0 +1,252 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="testIndexOnlyUpdate"> + <mkdir dir="${output}"/> + <property name="index.jar" location="${output}/index.jar" /> + + <jar destfile="${index.jar}" index="false"> + <fileset dir="${basedir}" includes="*-test.xml" /> + </jar> + <au:assertTrue> + <resourcecount count="0"> + <restrict> + <zipentry zipfile="${index.jar}" name="META-INF/INDEX.LIST" /> + <exists /> + </restrict> + </resourcecount> + </au:assertTrue> + <jar destfile="${index.jar}" index="true" update="true"> + <fileset dir="${basedir}" includes="*-test.xml" /> + </jar> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <zipentry zipfile="${index.jar}" name="META-INF/INDEX.LIST" /> + <exists /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testResourcesOnly" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47470"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <touch file="${input}/foo"/> + <touch file="${output}/bar"/> + <jar destfile="${output}/foo.jar"> + <union> + <fileset dir="${input}"/> + <fileset dir="${output}" excludes="foo.jar"/> + </union> + </jar> + <au:assertLogDoesntContain text="skipping jar archive"/> + </target> + + <target name="-metainf-setup"> + <mkdir dir="${input}/services"/> + <touch file="${input}/services/foo"/> + <mkdir dir="${output}"/> + </target> + + <target name="testIndexNoMetaInf" depends="-metainf-setup"> + <jar index="true" destfile="${output}/test.jar"> + <metainf dir="${input}"/> + </jar> + <unjar src="${output}/test.jar" dest="${output}"/> + <au:assertFileExists file="${output}/META-INF/INDEX.LIST"/> + <au:assertResourceDoesntContain value="META-INF" + resource="${output}/META-INF/INDEX.LIST"/> + </target> + + <target name="testIndexMetaInf" depends="-metainf-setup"> + <jar index="true" destfile="${output}/test.jar" indexMetaInf="true"> + <metainf dir="${input}"/> + </jar> + <unjar src="${output}/test.jar" dest="${output}"/> + <au:assertFileExists file="${output}/META-INF/INDEX.LIST"/> + <au:assertResourceContains value="META-INF" + resource="${output}/META-INF/INDEX.LIST"/> + </target> + + <target name="testMergeWithoutMain" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=29731"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <jar destfile="${input}/first.jar"> + <manifest> + <attribute name="First" value="Main Section"/> + <section name="Nested"> + <attribute name="First" value="Nested Section"/> + </section> + </manifest> + </jar> + <jar destfile="${output}/second.jar" filesetmanifest="mergewithoutmain"> + <manifest> + <attribute name="Second" value="Main Section"/> + <section name="Nested"> + <attribute name="Second" value="Nested Section"/> + </section> + </manifest> + <zipgroupfileset dir="${input}" includes="first.jar"/> + </jar> + <unjar src="${output}/second.jar" dest="${output}"/> + <au:assertFileExists file="${output}/META-INF/MANIFEST.MF"/> + <au:assertResourceContains value="First: Nested Section" + resource="${output}/META-INF/MANIFEST.MF"/> + <au:assertResourceContains value="Second: Nested Section" + resource="${output}/META-INF/MANIFEST.MF"/> + <au:assertResourceDoesntContain + value="First: Main Section" + resource="${output}/META-INF/MANIFEST.MF"/> + <au:assertResourceContains value="Second: Main Section" + resource="${output}/META-INF/MANIFEST.MF"/> + </target> + + <target name="testWhenManifestOnly" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=43946"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <jar destfile="${output}/first.jar"> + <fileset dir="${input}"/> + </jar> + <au:assertFileExists file="${output}/first.jar"/> + <au:assertLogDoesntContain text="skipping jar archive"/> + <jar destfile="${output}/second.jar" whenmanifestonly="create"> + <fileset dir="${input}"/> + </jar> + <au:assertFileExists file="${output}/second.jar"/> + <au:assertLogDoesntContain text="skipping jar archive"/> + <jar destfile="${output}/third.jar" whenmanifestonly="skip"> + <fileset dir="${input}"/> + </jar> + <au:assertFileDoesntExist file="${output}/third.jar"/> + <au:assertLogContains text="skipping jar archive"/> + <au:expectfailure> + <jar destfile="${output}/forth.jar" whenmanifestonly="fail"> + <fileset dir="${input}"/> + </jar> + </au:expectfailure> + </target> + + <target name="test-update-and-filesetmanifest" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=30751"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <jar destfile="${input}/manifest.jar"> + <manifest> + <attribute name="Origin" value="manifest.jar"/> + </manifest> + </jar> + + <touch file="${input}/foo"/> + <jar destfile="${output}/test.jar"> + <fileset dir="${input}" excludes="*.jar"/> + <manifest> + <attribute name="Second-Origin" value="test.jar"/> + </manifest> + </jar> + + <touch file="${input}/bar"/> + <jar destfile="${output}/test.jar" update="true" filesetmanifest="merge"> + <fileset dir="${input}" excludes="*.jar"/> + <zipgroupfileset dir="${input}" includes="*.jar"/> + </jar> + + <unjar src="${output}/test.jar" dest="${output}"/> + <au:assertFileExists file="${output}/foo"/> + <au:assertFileExists file="${output}/bar"/> + <au:assertResourceContains value="Origin: manifest.jar" + resource="${output}/META-INF/MANIFEST.MF"/> + <au:assertResourceContains value="Second-Origin: test.jar" + resource="${output}/META-INF/MANIFEST.MF"/> + </target> + + <target name="testDuplicateFail"> + <mkdir dir="${input}/1"/> + <mkdir dir="${input}/2"/> + <mkdir dir="${output}"/> + <touch file="${input}/1/a.txt"/> + <touch file="${input}/2/a.txt"/> + <au:expectfailure message="Duplicate file"> + <jar destfile="${output}/test.jar" duplicate="fail"> + <fileset dir="${input}/1"/> + <fileset dir="${input}/2"/> + </jar> + </au:expectfailure> + </target> + + <target name="testFileSetMerge" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49090"> + <mkdir dir="${input}/META-INF"/> + <mkdir dir="${output}"/> + <echo file="${input}/META-INF/MANIFEST.MF"><![CDATA[Test: Header +]]></echo> + <jar destfile="${output}/test.jar" filesetmanifest="merge"> + <fileset dir="${input}"/> + </jar> + <unjar src="${output}/test.jar" dest="${output}"/> + <au:assertResourceContains value="Test: Header" + resource="${output}/META-INF/MANIFEST.MF"/> + </target> + + <target name="testZipfilesetMerge" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49605"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/MANIFEST.MF">Manifest-Version: 1.0 +Main-Class: MyClass + +</echo> + <jar destfile="${input}/manifesttest.jar" + filesetmanifest="merge"> + <zipfileset file="${input}/MANIFEST.MF" prefix="META-INF"/> + </jar> + <unjar src="${input}/manifesttest.jar" dest="${output}"/> + <au:assertFileExists file="${output}/META-INF/MANIFEST.MF"/> + <au:assertResourceContains value="Main-Class: MyClass" + resource="${output}/META-INF/MANIFEST.MF"/> + </target> + + <target name="testMergeWithoutMainWithoutExplicitManifest" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=54171"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <jar destfile="${input}/input.jar"> + <manifest> + <attribute name="Foo" value="Main Section"/> + </manifest> + <fileset dir="."/> + </jar> + <jar destfile="${input}/test.jar" + filesetmanifest="mergewithoutmain"> + <zipgroupfileset dir="${input}"> + <include name="input.jar"/> + </zipgroupfileset> + </jar> + <unjar src="${input}/test.jar" dest="${output}"/> + <au:assertFileExists file="${output}/META-INF/MANIFEST.MF"/> + <au:assertResourceDoesntContain + value="Foo: Main Section" + resource="${output}/META-INF/MANIFEST.MF"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/java-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/java-test.xml new file mode 100644 index 00000000..db673161 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/java-test.xml @@ -0,0 +1,75 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="-setUpWriterClass"> + <mkdir dir="${input}"/> + <echo file="${input}/A.java"><![CDATA[ +public class A { + public static void main(String[] args) { + System.err.println("to System.err"); + System.out.println("to System.out"); + } +}]]></echo> + <mkdir dir="${output}"/> + <javac srcdir="${input}" destdir="${output}"/> + </target> + + <target name="testOutputProperty" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47602" + depends="-setUpWriterClass"> + <java fork="false" classname="A" outputproperty="out" + errorproperty="err"> + <classpath location="${output}"/> + </java> + <au:assertPropertyEquals name="out" value="to System.out"/> + <au:assertPropertyEquals name="err" value="to System.err"/> + </target> + + <target name="testLogErrorNoInput" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47844" + depends="-setUpWriterClass"> + <property name="stdout" location="${output}/standard.txt"/> + <java fork="false" classname="A" output="${stdout}" logError="true"> + <classpath location="${output}"/> + </java> + <au:assertResourceContains resource="${stdout}" + value="to System.out"/> + <au:assertResourceDoesntContain resource="${stdout}" + value="to System.err"/> + <au:assertLogContains text="to System.err"/> + </target> + + <target name="testLogErrorWithInput" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47844" + depends="-setUpWriterClass"> + <property name="stdout" location="${output}/standard.txt"/> + <java fork="false" classname="A" output="${stdout}" + logError="true" inputstring=""> + <classpath location="${output}"/> + </java> + <au:assertResourceContains resource="${stdout}" + value="to System.out"/> + <au:assertResourceDoesntContain resource="${stdout}" + value="to System.err"/> + <au:assertLogContains text="to System.err"/> + </target> + +</project> + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/javac-dir/bad-src/Bad.java b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/javac-dir/bad-src/Bad.java new file mode 100644 index 00000000..3b749f88 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/javac-dir/bad-src/Bad.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ +/** a simple class with a bug */ +public class Simple { + // should get a not-terminated error + String s = "; +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/javac-dir/good-src/Simple.java b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/javac-dir/good-src/Simple.java new file mode 100644 index 00000000..9c08f568 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/javac-dir/good-src/Simple.java @@ -0,0 +1,20 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ +/** a simple do nothing class */ +public class Simple { +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/javac-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/javac-test.xml new file mode 100644 index 00000000..3c4d8489 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/javac-test.xml @@ -0,0 +1,316 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <property name="javac-dir" location="${output}/javac-dir" /> + <property name="build-dir" location="${javac-dir}/build" /> + + <target name="test-includeDestClasses"> + <property name="DATE" value="09/10/1999 4:30 pm" /> + <delete dir="${javac-dir}/src" /> + <mkdir dir="${javac-dir}/src" /> + <echo file="${javac-dir}/src/A.java"> + public class A { B b;} + </echo> + <echo file="${javac-dir}/src/B.java"> + public class B { } + </echo> + <delete dir="${javac-dir}/classes" quiet="yes" /> + <mkdir dir="${javac-dir}/classes" /> + <javac srcdir="${javac-dir}/src" destdir="${javac-dir}/classes" /> + <touch file="${javac-dir}/src/B.java" datetime="${DATE}" /> + <touch file="${javac-dir}/classes/B.class" datetime="${DATE}" /> + <!-- following should not update B.class --> + <delete quiet="yes" file="${javac-dir}/classes/A.class" /> + <javac srcdir="${javac-dir}/src" destdir="${javac-dir}/classes" /> + <au:assertTrue> + <isfileselected file="${javac-dir}/classes/B.class"> + <date datetime="${DATE}" when="equal" /> + </isfileselected> + </au:assertTrue> + <!-- following should update B.class --> + <delete quiet="yes" file="${javac-dir}/classes/A.class" /> + <javac srcdir="${javac-dir}/src" destdir="${javac-dir}/classes" includeDestClasses="no" /> + <au:assertFalse> + <isfileselected file="${javac-dir}/classes/B.class"> + <date datetime="${DATE}" when="equal" /> + </isfileselected> + </au:assertFalse> + </target> + + <target name="test-updated-property"> + <delete quiet="yes" dir="${build-dir}" /> + <mkdir dir="${build-dir}" /> + <javac srcdir="javac-dir/good-src" destdir="${build-dir}" updatedProperty="classes-updated" /> + <au:assertTrue> + <equals arg1="${classes-updated}" arg2="true" /> + </au:assertTrue> + <javac srcdir="javac-dir/good-src" destdir="${build-dir}" updatedProperty="classes-updated-2" /> + <au:assertFalse> + <isset property="classes-updated-2" /> + </au:assertFalse> + </target> + + <target name="test-error-property"> + <delete quiet="yes" dir="${build-dir}" /> + <mkdir dir="${build-dir}" /> + <javac srcdir="javac-dir/good-src" destdir="${build-dir}" failOnError="false" errorProperty="compile-failed" /> + <au:assertTrue> + <equals arg1="${compile-failed}" arg2="${compile-failed}" /> + </au:assertTrue> + <javac srcdir="javac-dir/bad-src" destdir="${build-dir}" failOnError="false" errorProperty="compile-failed" /> + <au:assertTrue> + <equals arg1="${compile-failed}" arg2="true" /> + </au:assertTrue> + </target> + + <target name="setUpForPackageInfoJava"> + <mkdir dir="${javac-dir}/src/a" /> + <mkdir dir="${build-dir}" /> + <echo file="${javac-dir}/src/a/package-info.java"> + <![CDATA[ +/** + * Some test javadocs at the package level. + */ +]]> + </echo> + <javac srcdir="${javac-dir}/src" destdir="${build-dir}" updatedProperty="first-pass" /> + <au:assertPropertyEquals name="first-pass" value="true" /> + </target> + + <target name="testPackageInfoJava" + depends="setUpForPackageInfoJava" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=43114"> + <!-- no changes, shouldn't recompile, the initial bug --> + <javac srcdir="${javac-dir}/src" destdir="${build-dir}" updatedProperty="second-pass" /> + <au:assertFalse> + <isset property="second-pass" /> + </au:assertFalse> + <sleep seconds="2" /> + + <!-- change package-info.java but make containing target dir even + more recent - the regression in Ant 1.7.1 --> + <touch file="${javac-dir}/src/a/package-info.java" /> + <sleep seconds="2" /> + <touch> + <file file="${build-dir}/a" /> + </touch> + <javac srcdir="${javac-dir}/src" destdir="${build-dir}" updatedProperty="third-pass" /> + <au:assertPropertyEquals name="third-pass" value="true" /> + </target> + + <target name="testPackageInfoJavaNoDest" + depends="setUpForPackageInfoJava" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=51947"> + <javac srcdir="${javac-dir}/src" updatedProperty="first-pass" /> + <au:assertPropertyEquals name="first-pass" value="true" /> + + <!-- no changes, shouldn't recompile, the initial bug --> + <javac srcdir="${javac-dir}/src" updatedProperty="second-pass" /> + <au:assertFalse> + <isset property="second-pass" /> + </au:assertFalse> + <sleep seconds="2" /> + + <!-- change package-info.java but make containing target dir even + more recent - the regression in Ant 1.7.1 --> + <touch file="${javac-dir}/src/a/package-info.java" /> + <sleep seconds="2" /> + <touch> + <file file="${javac-dir}/src/a" /> + </touch> + <javac srcdir="${javac-dir}/src" updatedProperty="third-pass" /> + <au:assertPropertyEquals name="third-pass" value="true" /> + </target> + + <target name="testSuppressPackageInfoClass" + depends="setUpForPackageInfoJava" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=52096"> + <au:assertFileExists file="${build-dir}/a/package-info.class"/> + <delete file="${build-dir}/a/package-info.class"/> + <javac srcdir="${javac-dir}/src" destdir="${build-dir}" + createMissingPackageInfoClass="false" + updatedProperty="second-pass" /> + <au:assertPropertyEquals name="second-pass" value="true" /> + <au:assertFileDoesntExist file="${build-dir}/a/package-info.class"/> + </target> + + <target name="-create-javac-adapter"> + <property name="adapter.dir" location="${output}/adapter" /> + <mkdir dir="${input}/org/example" /> + <echo file="${input}/org/example/Adapter.java"> + <![CDATA[ +package org.example; +import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter; +import org.apache.tools.ant.taskdefs.Javac; + +public class Adapter implements CompilerAdapter { + public void setJavac(Javac attributes) {} + public boolean execute() { + System.err.println("adapter called"); + return true; + } +}]]> + </echo> + <mkdir dir="${resources}" /> + <javac srcdir="${input}" destdir="${resources}" /> + </target> + + <target name="testCompilerNotFound" depends="-create-javac-adapter"> + <au:expectfailure> + <javac srcdir="${input}" destdir="${output}" compiler="org.example.Adapter" /> + </au:expectfailure> + <au:assertLogDoesntContain text="adapter called" /> + </target> + + <target name="testCompilerClasspath" depends="-create-javac-adapter" description="https://issues.apache.org/bugzilla/show_bug.cgi?id=11143"> + <mkdir dir="${output}" /> + <javac srcdir="${input}" destdir="${output}" compiler="org.example.Adapter"> + <compilerclasspath location="${resources}" /> + </javac> + <au:assertLogContains text="adapter called" /> + </target> + + <target name="testCompilerAsNestedElement" depends="-create-javac-adapter"> + <componentdef classname="org.example.Adapter" name="myjavac"> + <classpath location="${resources}" /> + </componentdef> + <mkdir dir="${output}" /> + <javac srcdir="${input}" destdir="${output}"> + <myjavac /> + </javac> + <au:assertLogContains text="adapter called" /> + </target> + + <target name="testSourceAttributes" xmlns:if="ant:if" xmlns:unless="ant:unless"> + <delete dir="${javac-dir}/src" /> + <mkdir dir="${javac-dir}/src" /> + <mkdir dir="${javac-dir}/classes" /> + <echo file="${javac-dir}/src/A.java"> + public class A { } + </echo> + <presetdef name="testJavac"> + <javac srcdir="${javac-dir}/src" destdir="${javac-dir}/classes" includeantruntime="false"/> + </presetdef> + + <au:expectfailure> + <testJavac source="notValid"/> + </au:expectfailure> + + <sequential unless:set="jdk1.9+"> + <echo>JDK 1.4+</echo> + <testJavac source="1.4"/> + <delete dir="${javac-dir}/classes"/> + <mkdir dir="${javac-dir}/classes"/> + </sequential> + + <sequential unless:set="jdk1.9+"> + <echo>JDK 1.5+</echo> + <testJavac source="1.5"/> + <delete dir="${javac-dir}/classes"/> + <mkdir dir="${javac-dir}/classes"/> + </sequential> + + <sequential if:set="jdk1.6+"> + <echo>JDK 1.6+</echo> + <testJavac source="1.6"/> + <delete dir="${javac-dir}/classes"/> + <mkdir dir="${javac-dir}/classes"/> + </sequential> + + <sequential if:set="jdk1.7+"> + <echo>JDK 1.7+</echo> + <testJavac source="1.7"/> + <delete dir="${javac-dir}/classes"/> + <mkdir dir="${javac-dir}/classes"/> + </sequential> + + <sequential if:set="jdk1.8+"> + <echo>JDK 1.8+</echo> + <testJavac source="1.8"/> + <delete dir="${javac-dir}/classes"/> + <mkdir dir="${javac-dir}/classes"/> + </sequential> + + <sequential if:set="jdk1.9+"> + <echo>JDK 1.9+</echo> + <testJavac source="1.9"/> + <delete dir="${javac-dir}/classes"/> + <mkdir dir="${javac-dir}/classes"/> + </sequential> + </target> + + <target name="testTargetAttributes" xmlns:if="ant:if" xmlns:unless="ant:unless"> + <delete dir="${javac-dir}/src" /> + <mkdir dir="${javac-dir}/src" /> + <mkdir dir="${javac-dir}/classes" /> + <echo file="${javac-dir}/src/A.java"> + public class A { } + </echo> + <presetdef name="testJavac"> + <javac srcdir="${javac-dir}/src" destdir="${javac-dir}/classes" includeantruntime="false"/> + </presetdef> + + <au:expectfailure> + <testJavac target="notValid"/> + </au:expectfailure> + + <sequential unless:set="jdk1.9+"> + <echo>JDK 1.4+</echo> + <testJavac source="1.4" target="1.4"/> + <delete dir="${javac-dir}/classes"/> + <mkdir dir="${javac-dir}/classes"/> + </sequential> + + <sequential unless:set="jdk1.9+"> + <echo>JDK 1.5+</echo> + <testJavac source="1.5" target="1.5"/> + <delete dir="${javac-dir}/classes"/> + <mkdir dir="${javac-dir}/classes"/> + </sequential> + + <sequential if:set="jdk1.6+"> + <echo>JDK 1.6+</echo> + <testJavac source="1.6" target="1.6"/> + <delete dir="${javac-dir}/classes"/> + <mkdir dir="${javac-dir}/classes"/> + </sequential> + + <sequential if:set="jdk1.7+"> + <echo>JDK 1.7+</echo> + <testJavac source="1.7" target="1.7"/> + <delete dir="${javac-dir}/classes"/> + <mkdir dir="${javac-dir}/classes"/> + </sequential> + + <sequential if:set="jdk1.8+"> + <echo>JDK 1.8+</echo> + <testJavac source="1.8" target="1.8"/> + <delete dir="${javac-dir}/classes"/> + <mkdir dir="${javac-dir}/classes"/> + </sequential> + + <sequential if:set="jdk1.9+"> + <echo>JDK 1.9+</echo> + <testJavac source="1.9" target="1.9"/> + <delete dir="${javac-dir}/classes"/> + <mkdir dir="${javac-dir}/classes"/> + </sequential> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/javadoc-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/javadoc-test.xml new file mode 100644 index 00000000..200082ba --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/javadoc-test.xml @@ -0,0 +1,157 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="-makeTestClass"> + <macrodef name="mktest"> + <attribute name="package"/> + <attribute name="class"/> + <sequential> + <mkdir dir="${input}/@{package}"/> + <echo file="${input}/@{package}/@{class}.java"><![CDATA[ +package @{package}; + +/** + * This is a test class. + */ +public class @{class} { + /** + * With a test method. + */ + public void foo(String bar) {} +} +]]></echo> + </sequential> + </macrodef> + <mktest package="test" class="A"/> + </target> + + <target name="-makeTwoTestClasses" depends="-makeTestClass"> + <mktest package="test2" class="B"/> + </target> + + <target name="testBottomWithLineBreaksWithFile" depends="-makeTestClass"> + <javadoc destdir="${output}" useexternalfile="true"> + <fileset dir="${input}"/> + <bottom><![CDATA[ +<hr/> +Hello World +]]></bottom> + </javadoc> + <au:assertFileExists file="${output}/test/A.html"/> + </target> + + <target name="-setUpDocFilesTests" depends="-makeTestClass"> + <mkdir dir="${input}/test/doc-files/a"/> + <mkdir dir="${input}/test/doc-files/b"/> + <macrodef name="mkfoo"> + <attribute name="file"/> + <sequential> + <echo file="@{file}"><![CDATA[<p>Hello, world!</p>]]></echo> + </sequential> + </macrodef> + <mkfoo file="${input}/test/doc-files/foo.html"/> + <mkfoo file="${input}/test/doc-files/a/foo.html"/> + <mkfoo file="${input}/test/doc-files/b/foo.html"/> + </target> + + <target name="-create-file-with-warning"> + <mkdir dir="${input}/test"/> + <echo file="${input}/test/Foo.java"><![CDATA[ +package test; + +/** + * This is a test class. + */ +public class Foo { + /** + * With a test method. + * @param baz wrong parameter name should cause warning. + */ + public void foo(String bar) {} +} +]]></echo> + </target> + + <target name="testPackageSetNoExcludes" depends="-makeTwoTestClasses"> + <javadoc destdir="${output}"> + <packageset dir="${input}"/> + </javadoc> + <au:assertFileExists file="${output}/test/A.html"/> + <au:assertFileExists file="${output}/test2/B.html"/> + </target> + + <target name="testPackageSetWithExcludes" + depends="-makeTwoTestClasses" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47196"> + <javadoc destdir="${output}"> + <packageset dir="${input}"> + <exclude name="test2"/> + </packageset> + </javadoc> + <au:assertFileExists file="${output}/test/A.html"/> + <au:assertFileDoesntExist file="${output}/test2/B.html"/> + </target> + + <!-- basically tests no exception is thrown --> + <target name="testDontFailOnWarning" + depends="-create-file-with-warning"> + <javadoc destdir="${output}"> + <packageset dir="${input}"/> + </javadoc> + </target> + + <target name="testFailOnWarning" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=55015" + depends="-create-file-with-warning"> + <au:expectfailure> + <javadoc destdir="${output}" failonwarning="true"> + <packageset dir="${input}"/> + </javadoc> + </au:expectfailure> + </target> + + <target name="XtestNoDocFiles" depends="-setUpDocFilesTests"> + <javadoc destdir="${output}"> + <packageset dir="${input}"/> + </javadoc> + <au:assertFileExists file="${output}/test/doc-files/foo.html"/> + <au:assertFileDoesntExist file="${output}/test/doc-files/a/foo.html"/> + </target> + + <target name="XtestDocFiles" depends="-setUpDocFilesTests"> + <javadoc destdir="${output}" docfilessubdirs="true"> + <packageset dir="${input}"/> + </javadoc> + <au:assertFileExists file="${output}/test/doc-files/foo.html"/> + <au:assertFileExists file="${output}/test/doc-files/a/foo.html"/> + <au:assertFileExists file="${output}/test/doc-files/b/foo.html"/> + </target> + + <target name="XtestDocFilesWithExclude" depends="-setUpDocFilesTests"> + <javadoc destdir="${output}" docfilessubdirs="true" + excludedocfilessubdir="a"> + <packageset dir="${input}"/> + </javadoc> + <au:assertFileExists file="${output}/test/doc-files/foo.html"/> + <au:assertFileDoesntExist file="${output}/test/doc-files/a/foo.html"/> + <au:assertFileExists file="${output}/test/doc-files/b/foo.html"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/length-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/length-test.xml new file mode 100644 index 00000000..acd5310b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/length-test.xml @@ -0,0 +1,240 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="length-test" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <property name="dir.a" location="${input}/a" /> + <property name="dir.b" location="${input}/b" /> + <property name="zipfile" location="${output}/lengthtest.zip" /> + + <target name="setUp"> + <mkdir dir="${output}" /> + <mkdir dir="${dir.a}" /> + <mkdir dir="${dir.b}" /> + <property name="foo" location="${dir.a}/foo" /> + <property name="bar" location="${dir.b}/bar" /> + <echo file="${foo}" message="foo" /> + <echo file="${bar}" message="bar" /> + </target> + + <target name="testEach" depends="setUp"> + <length mode="each" property="length.each"> + <fileset id="fs" dir="${input}" /> + </length> + <length string="${length.each}" property="length.length.each" /> + <length string="${foo}${bar}........${line.separator}" + property="length.expected" /> + + <au:assertTrue> + <!-- test that both files are represented, and that the + output is the expected length; do not assume order. --> + <and> + <contains string="${length.each}" substring="${foo} : 3" /> + <contains string="${length.each}" substring="${bar} : 3" /> + <equals arg1="${length.length.each}" arg2="${length.expected}" /> + </and> + </au:assertTrue> + </target> + + <target name="testEachCondition" depends="setUp"> + <length mode="each" property="length.each"> + <fileset id="fs" dir="${input}" /> + </length> + <length string="${foo}${bar}........${line.separator}" + property="length.expected" /> + <au:assertTrue> + <!-- test that both files are represented, and that the + output is the expected length; do not assume order. --> + <and> + <contains string="${length.each}" substring="${foo} : 3" /> + <contains string="${length.each}" substring="${bar} : 3" /> + <length string="${length.each}" length="${length.expected}" /> + </and> + </au:assertTrue> + </target> + + <target name="testAll" depends="setUp"> + <length property="length.all"> + <fileset id="foo" file="${dir.a}/foo" /> + <fileset id="bar" file="${dir.b}/bar" /> + </length> + <au:assertTrue> + <equals arg1="6" arg2="${length.all}" /> + </au:assertTrue> + </target> + + <target name="testAllCondition" depends="setUp"> + <au:assertTrue> + <length length="6"> + <fileset id="foo" file="${dir.a}/foo" /> + <fileset id="bar" file="${dir.b}/bar" /> + </length> + </au:assertTrue> + </target> + + <target name="testFile" depends="setUp"> + <length property="length.foo" file="${dir.a}/foo" /> + <au:assertTrue> + <equals arg1="3" arg2="${length.foo}" /> + </au:assertTrue> + </target> + + <target name="testFileCondition" depends="setUp"> + <au:assertTrue> + <length length="3" file="${dir.a}/foo" /> + </au:assertTrue> + </target> + + <target name="testBoth" depends="setUp"> + <length property="length.foo" file="${dir.a}/foo"> + <fileset file="${dir.b}/bar" /> + </length> + <au:assertTrue> + <equals arg1="6" arg2="${length.foo}" /> + </au:assertTrue> + </target> + + <target name="testBothCondition" depends="setUp"> + <au:assertTrue> + <length length="6" file="${dir.a}/foo"> + <fileset file="${dir.b}/bar" /> + </length> + </au:assertTrue> + </target> + + <target name="testDupes" depends="setUp"> + <length property="length.foo" file="${dir.a}/foo"> + <fileset dir="${input}" /> + </length> + <au:assertTrue> + <equals arg1="9" arg2="${length.foo}" /> + </au:assertTrue> + </target> + + <target name="testDupesCondition" depends="setUp"> + <au:assertTrue> + <length length="9" file="${dir.a}/foo"> + <fileset dir="${input}" /> + </length> + </au:assertTrue> + </target> + + <target name="testString"> + <length string="foo" property="length.string" /> + <au:assertTrue> + <equals arg1="3" arg2="${length.string}" /> + </au:assertTrue> + </target> + + <target name="testStringCondition"> + <au:assertTrue> + <length string="foo" length="3" /> + </au:assertTrue> + </target> + + <target name="testTrimString"> + <length string=" foo " trim="true" property="length.string" /> + <au:assertTrue> + <equals arg1="3" arg2="${length.string}" /> + </au:assertTrue> + </target> + + <target name="testTrimStringCondition"> + <au:assertTrue> + <length string=" foo " trim="true" length="3" /> + </au:assertTrue> + </target> + + <target name="testNoTrimString"> + <length string=" foo " property="length.string" /> + <au:assertTrue> + <equals arg1="5" arg2="${length.string}" /> + </au:assertTrue> + </target> + + <target name="testNoTrimStringCondition"> + <au:assertTrue> + <length string=" foo " length="5" /> + </au:assertTrue> + </target> + + <target name="testTrimFile" description="should fail"> + <au:expectfailure> + <length file="${ant.file}" trim="false" /> + </au:expectfailure> + </target> + + <target name="testStringFile" description="should fail"> + <au:expectfailure> + <length string="foo" file="${ant.file}" /> + </au:expectfailure> + </target> + + <target name="testImmutable"> + <length string="foo" property="length.string" /> + <length string="foobar" property="length.string" /> + <au:assertTrue> + <equals arg1="3" arg2="${length.string}" /> + </au:assertTrue> + </target> + + <target name="zip" depends="setUp"> + <zip destfile="${zipfile}"> + <fileset file="${foo}" /> + <fileset file="${bar}" /> + </zip> + </target> + + <target name="testZipFileSet" depends="zip"> + <length property="length.zipfile1"> + <zipfileset src="${zipfile}" /> + </length> + <length property="length.zipfile2"> + <zipfileset src="${zipfile}" includes="bar" /> + </length> + <au:assertTrue> + <and> + <equals arg1="6" arg2="${length.zipfile1}" /> + <equals arg1="3" arg2="${length.zipfile2}" /> + </and> + </au:assertTrue> + </target> + + <target name="testZipFileSetCondition" depends="zip"> + <au:assertTrue> + <and> + <length length="6"> + <zipfileset src="${zipfile}" /> + </length> + <length length="3"> + <zipfileset src="${zipfile}" includes="bar" /> + </length> + </and> + </au:assertTrue> + </target> + + <target name="testResourceAttribute"> + <string id="s" value="foo-bar-baz" /> + <au:assertTrue> + <length length="11" resource="${ant.refid:s}" /> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/loadproperties-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/loadproperties-test.xml new file mode 100644 index 00000000..04b53f11 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/loadproperties-test.xml @@ -0,0 +1,192 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="loadproperties-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}" /> + <property name="properties.tmp" location="${input}/properties.tmp" /> + </target> + + <target name="test-basic"> + <loadproperties> + <string>basic.foo=foo +basic.bar=bar +basic.baz=baz</string> + </loadproperties> + <au:assertPropertyEquals name="basic.foo" value="foo" /> + <au:assertPropertyEquals name="basic.bar" value="bar" /> + <au:assertPropertyEquals name="basic.baz" value="baz" /> + </target> + + <target name="test-xref"> + <loadproperties> + <string>xref.foo=foo +xref.bar=$${xref.foo} +xref.baz=$${xref.bar}</string> + </loadproperties> + <au:assertPropertyEquals name="xref.foo" value="foo" /> + <au:assertPropertyEquals name="xref.bar" value="foo" /> + <au:assertPropertyEquals name="xref.baz" value="foo" /> + </target> + + <target name="test-xref-complex"> + <loadproperties> + <string>xref-complex.a=$$ +xref-complex.b={ +xref-complex.c=} +xref-complex.d=x +xref-complex.e=$${xref-complex.a}$${xref-complex.b}xref-complex.d$${xref-complex.c} +xref-complex.f=$${xref-complex.e}</string> + </loadproperties> + <au:assertPropertyEquals name="xref-complex.a" value="$$" /> + <au:assertPropertyEquals name="xref-complex.b" value="{" /> + <au:assertPropertyEquals name="xref-complex.c" value="}" /> + <au:assertPropertyEquals name="xref-complex.d" value="x" /> + <au:assertPropertyEquals name="xref-complex.e" value="$${xref-complex.d}" /> + <au:assertPropertyEquals name="xref-complex.f" value="$${xref-complex.d}" /> + </target> + + <target name="testEncoding" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47382"> + <mkdir dir="${input}"/> + <echo file="${input}/ebcdic.properties" encoding="Cp1047"> +a=Hello world in EBCDIC + </echo> + <loadproperties srcfile="${input}/ebcdic.properties" encoding="Cp1047"/> + <au:assertPropertyEquals name="a" value="Hello world in EBCDIC"/> + </target> + + <target name="testPrefixedProperties" depends="setUp"> + <property name="server" value="localhost"/> + <echo file="${properties.tmp}"> +#http.@PORT@ = 90 +http.@PORT@ = 80 +http.@SERVER@ = ${server} + </echo> + <loadproperties srcFile="${properties.tmp}"> + <filterchain> + <striplinecomments> + <comment value="#"/> + </striplinecomments> + <prefixlines prefix="server1."/> + <replacetokens> + <token key="PORT" value="port"/> + <token key="SERVER" value="server"/> + </replacetokens> + <expandproperties/> + </filterchain> + </loadproperties> + <property name="server1.http.url" + value="http://${server1.http.server}:${server1.http.port}"/> + </target> + + <target name="testLineCommentsWithoutFiltering"> + <loadproperties> + <string value="#foo=bar" /> + </loadproperties> + <au:assertFalse> + <isset property="foo" /> + </au:assertFalse> + </target> + + <target name="testPrefixAttributeProperties"> + <loadproperties prefix="prefixFromAttribute."> + <string>foo=foo +bar=bar +baz=${foo} ${bar} + </string> + </loadproperties> + <au:assertTrue> + <and> + <equals arg1="foo" arg2="${prefixFromAttribute.foo}" /> + <equals arg1="bar" arg2="${prefixFromAttribute.bar}" /> + <equals arg1="foo bar" arg2="${prefixFromAttribute.baz}" /> + </and> + </au:assertTrue> + </target> + + <target name="testSelfContainedPrefixFilterFailure" + description="Show why the prefix attribute is needed"> + <loadproperties> + <string>foo=foo +bar=bar +baz=${foo} ${bar} + </string> + <filterchain> + <prefixlines prefix="prefixFromFilter." /> + </filterchain> + </loadproperties> + <au:assertTrue> + <and> + <equals arg1="$${foo} $${bar}" arg2="${prefixFromFilter.baz}" /> + <isset property="prefixFromFilter." /> + </and> + </au:assertTrue> + </target> + + <target name="write properties.tmp" depends="setUp"> + <echo file="${properties.tmp}"> +#tpfr.a=a +tpfr.a=A +tpfr.b=b\ + e +tpfr.c=@C@ + </echo> + </target> + + <presetdef name="assertPropertiesFromResourceOkay"> + <au:assertTrue> + <equals arg1="Abesea" arg2="${tpfr.a}${tpfr.b}${tpfr.c}" /> + </au:assertTrue> + </presetdef> + + <target name="testPropertiesFromResource" depends="write properties.tmp"> + <loadproperties resource="properties.tmp" classpath="${input}"> + <filterchain> + <replacetokens> + <token key="C" value="sea"/> + </replacetokens> + </filterchain> + </loadproperties> + </target> + + <target name="testPropertiesFromFileSet" depends="write properties.tmp"> + <loadproperties> + <fileset file="${properties.tmp}" /> + <filterchain> + <replacetokens> + <token key="C" value="sea"/> + </replacetokens> + </filterchain> + </loadproperties> + <assertPropertiesFromResourceOkay /> + </target> + + <target name="testLastPropertyWins"> + <loadproperties> + <string>foo=foo +foo=bar</string> + </loadproperties> + <au:assertTrue> + <equals arg1="bar" arg2="${foo}" /> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/loadresource-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/loadresource-test.xml new file mode 100644 index 00000000..814ded5b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/loadresource-test.xml @@ -0,0 +1,41 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <target name="test-resourceString"> + <loadresource property="p"> + <string value="one"/> + </loadresource > + <au:assertPropertyEquals name="p" value="one"/> + </target> + + <target name="test-resourceSizeZero" description="Bug 42319"> + <loadresource property="p"> + <string value=""/> + </loadresource > + <au:assertTrue> + <not> + <isset property="p"/> + </not> + </au:assertTrue> + <au:assertLogContains text="Do not set property p as its length is 0."/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/local-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/local-test.xml new file mode 100644 index 00000000..9c4e7b7e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/local-test.xml @@ -0,0 +1,96 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <property name="foo" value="foo" /> + + <local name="bar" /> + <property name="bar" value="bar" /> + <au:assertPropertyEquals name="bar" value="bar" /> + + <target name="testGlobalLocal"> + <au:assertFalse> + <isset property="bar" /> + </au:assertFalse> + </target> + + <target name="testBaseline"> + <au:assertPropertyEquals name="foo" value="foo" /> + </target> + + <target name="testTarget"> + <au:assertPropertyEquals name="foo" value="foo" /> + <local name="foo" /> + <property name="foo" value="foo.target" /> + <au:assertPropertyEquals name="foo" value="foo.target" /> + </target> + + <target name="testSequential"> + <sequential> + <local name="foo" /> + <property name="foo" value="foo.1" /> + <sequential> + <local name="foo" /> + <property name="foo" value="foo.2" /> + <au:assertPropertyEquals name="foo" value="foo.2" /> + </sequential> + <au:assertPropertyEquals name="foo" value="foo.1" /> + </sequential> + <au:assertPropertyEquals name="foo" value="foo" /> + </target> + + <target name="testParallel"> + <macrodef name="p"> + <attribute name="value" /> + <attribute name="sleep" default="0" /> + <sequential> + <local name="foo" /> + <sleep seconds="@{sleep}" /> + <property name="foo" value="@{value}" /> + <au:assertPropertyEquals name="foo" value="@{value}" /> + </sequential> + </macrodef> + <parallel> + <p sleep="2" value="foo.a" /> + <au:assertPropertyEquals name="foo" value="foo" /> + <p sleep="1" value="foo.b" /> + <au:assertPropertyEquals name="foo" value="foo" /> + <p sleep="0" value="foo.c" /> + <au:assertPropertyEquals name="foo" value="foo" /> + </parallel> + <au:assertPropertyEquals name="foo" value="foo" /> + </target> + + <target name="testMacrodef"> + <macrodef name="m"> + <sequential> + <local name="foo" /> + <property name="foo" value="foo.x" /> + <au:assertPropertyEquals name="foo" value="foo.x" /> + </sequential> + </macrodef> + <m /> + <au:assertPropertyEquals name="foo" value="foo" /> + <m /> + <au:assertPropertyEquals name="foo" value="foo" /> + <m /> + <au:assertPropertyEquals name="foo" value="foo" /> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/macrodef-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/macrodef-test.xml new file mode 100644 index 00000000..b12e6f75 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/macrodef-test.xml @@ -0,0 +1,60 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="length-test" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <target name="testDefaultTest"> + <macrodef name="test-log"> + <text name="log" default="DEFAULT-LOG-VALUE"/> + <sequential> + <concat>@{log}</concat> + </sequential> + </macrodef> + <test-log/> + <au:assertLogContains text="DEFAULT-LOG-VALUE"/> + <test-log>THIS IS NOT DEFAULT LOG</test-log> + <au:assertLogContains text="THIS IS NOT DEFAULT LOG"/> + </target> + + <target name="testDisableDoubleExpandedProperties" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=42046"> + <macrodef name="indirect"> + <attribute name="value" doubleexpanding="false"/> + <sequential> + <echo message="@{value}"/> + </sequential> + </macrodef> + <indirect value="$${basedir}"/> + <au:assertLogContains text="{basedir}"/> + </target> + + <target name="testEnableDoubleExpandedProperties" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=52621"> + <macrodef name="indirect"> + <attribute name="value"/> + <sequential> + <echo message="@{value}"/> + </sequential> + </macrodef> + <indirect value="$${basedir}"/> + <au:assertLogDoesntContain text="{basedir}"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/manifest-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/manifest-test.xml new file mode 100644 index 00000000..4247ef2d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/manifest-test.xml @@ -0,0 +1,180 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${output}"/> + <property name="file" location="${output}/test.mf"/> + </target> + + <target name="test8IsAllowed" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=45675" + depends="setUp"> + <manifest file="${file}"> + <attribute name="attrib8" value="test attribute"/> + </manifest> + </target> + + <target name="testMergeOverrides" depends="setUp"> + <manifest file="${file}"> + <attribute name="foo" value="value1"/> + <attribute name="bar" value="value1"/> + <section name="bar"> + <attribute name="foo" value="value2"/> + </section> + </manifest> + <manifest file="${file}" mode="update"> + <attribute name="foo" value="value3"/> + <section name="bar"> + <attribute name="foo" value="value5"/> + </section> + </manifest> + <au:assertResourceContains + resource="${file}" + value="foo: value3 "/> + <au:assertResourceContains + resource="${file}" + value="bar: value1 "/> + <au:assertResourceContains + resource="${file}" + value="foo: value5 "/> + <au:assertResourceDoesntContain + resource="${file}" + value="foo: value1 "/> + <au:assertResourceDoesntContain + resource="${file}" + value="foo: value2 "/> + </target> + + <target name="testMergeOverridesClassPath" depends="setUp"> + <manifest file="${file}"> + <attribute name="Class-Path" value="foo"/> + </manifest> + <manifest file="${file}" mode="update"> + <attribute name="Class-Path" value="bar"/> + </manifest> + <au:assertResourceContains + resource="${file}" + value="Class-Path: bar "/> + <au:assertResourceDoesntContain + resource="${file}" + value="Class-Path: foo "/> + </target> + + <target name="testMultipleClassPathAttributes" depends="setUp"> + <manifest file="${file}"> + <attribute name="Class-Path" value="foo"/> + <attribute name="Class-Path" value="bar"/> + </manifest> + <au:assertResourceContains + resource="${file}" + value="Class-Path: foo "/> + <au:assertResourceContains + resource="${file}" + value="Class-Path: bar "/> + </target> + + <target name="testMergeClassPathAttributes" depends="setUp"> + <manifest file="${file}"> + <attribute name="Class-Path" value="foo"/> + <attribute name="Class-Path" value="bar"/> + </manifest> + <manifest file="${file}" mergeClassPathAttributes="true" mode="update"> + <attribute name="Class-Path" value="baz"/> + </manifest> + <au:assertResourceContains + resource="${file}" + value="Class-Path: foo "/> + <au:assertResourceContains + resource="${file}" + value="Class-Path: bar "/> + <au:assertResourceContains + resource="${file}" + value="Class-Path: baz "/> + </target> + + <target name="testFlattenMultipleClassPathAttributes" depends="setUp"> + <manifest file="${file}" flattenAttributes="true"> + <attribute name="Class-Path" value="foo"/> + <attribute name="Class-Path" value="bar"/> + </manifest> + <au:assertResourceContains + resource="${file}" + value="Class-Path: foo bar "/> + </target> + + <target name="testMergeAndFlattenClassPathAttributes" depends="setUp"> + <manifest file="${file}"> + <attribute name="Class-Path" value="foo"/> + <attribute name="Class-Path" value="bar"/> + </manifest> + <manifest file="${file}" + mergeClassPathAttributes="true" + flattenAttributes="true" + mode="update"> + <attribute name="Class-Path" value="baz"/> + </manifest> + <au:assertResourceContains + resource="${file}" + value="Class-Path: baz foo bar "/> + </target> + + <target name="-prepareJava5JarTest" depends="setUp"> + <mkdir dir="${output}/bin"/> + <mkdir dir="${input}/org/example"/> + <echo file="${input}/org/example/AntFail.java"><![CDATA[ +package org.example; + +public class AntFail { + public static + void main(String[] args) { + System.out.println(System.getProperty("java.version")); + } + } +]]></echo> + <javac srcdir="${input}" destdir="${output}/bin" includeantruntime="no" /> + </target> + + <target name="testJava5JarProblemManifestInSeparateTask" + depends="-prepareJava5JarTest" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=54762"> + <manifest file="${output}/MANIFEST.MF"> + <attribute name="Main-Class" value="org.example.AntFail" /> + </manifest> + + <jar manifest="${output}/MANIFEST.MF" destfile="${output}/antfail.jar" + basedir="${output}/bin" /> + <java jar="${output}/antfail.jar" fork="true" failonerror="true"/> + </target> + + <target name="testJava5JarProblemManifestAsNestedElement" + depends="-prepareJava5JarTest" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=54762"> + + <jar destfile="${output}/antfail.jar" + basedir="${output}/bin"> + <manifest> + <attribute name="Main-Class" value="org.example.AntFail" /> + </manifest> + </jar> + <java jar="${output}/antfail.jar" fork="true" failonerror="true"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/manifestclasspath-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/manifestclasspath-test.xml new file mode 100644 index 00000000..612990b6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/manifestclasspath-test.xml @@ -0,0 +1,30 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <target name="testRelativePathOfParentDir"> + <manifestclasspath property="jar.classpath" + jarfile="${basedir}/foo.jar"> + <classpath path="${basedir}"/> + </manifestclasspath> + <au:assertPropertyEquals name="jar.classpath" value="./"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/move-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/move-test.xml new file mode 100644 index 00000000..9acac749 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/move-test.xml @@ -0,0 +1,234 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="test-move-caseonly"> + <!-- this test is inspired by bugzilla 41948 --> + <!-- Especially interesting if executed on case-insensitive file systems --> + <mkdir dir="${output}"/> + <touch file="${output}/abc"/> + <move file="${output}/abc" tofile="${output}/aBc"/> + <fileset dir="${output}" id="myfs"> + <include name="aBc"/> + </fileset> + <pathconvert refid="myfs" property="myproperty" setonempty="false"/> + <au:assertPropertySet name="myproperty" message="abc was not renamed aBc"/> + </target> + + <target name="test-regex-mapper" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=18656"> + <mkdir dir="${input}/AAA/foo"/> + <touch file="${input}/AAA/foo/bar.txt"/> + <mkdir dir="${input}/foo/AAA"/> + <touch file="${input}/foo/bar.txt"/> + <touch file="${input}/foo/AAA/bar.txt"/> + <mkdir dir="${input}/foo/bar"/> + <touch file="${input}/foo/bar/AAA.txt"/> + <touch file="${input}/foo/bar/baz.txt"/> + + <mkdir dir="${output}"/> + + <move todir="${output}"> + <fileset dir="${input}"/> + <firstmatchmapper> + <regexpmapper from="(.*)AAA(.*)" to="\1BBB\2"/> + <identitymapper/> + </firstmatchmapper> + </move> + + <au:assertFileExists file="${output}/BBB/foo/bar.txt"/> + <au:assertFileExists file="${output}/foo/bar.txt"/> + <au:assertFileExists file="${output}/foo/BBB/bar.txt"/> + <au:assertFileExists file="${output}/foo/bar/BBB.txt"/> + <au:assertFileExists file="${output}/foo/bar/baz.txt"/> + </target> + + <target name="testNotModifiedSelector" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=43574" + > + <mkdir dir="${input}/images"/> + <mkdir dir="${input}/cache"/> + <touch file="${input}/images/foo.jpg"/> + <mkdir dir="${output}"/> + <selector id="cache.selector"> + <not> + <modified update="true" + seldirs="false" + cache="propertyfile" + algorithm="digest" + comparator="equal"> + <param name="cache.cachefile" + value="${input}/cache/cache.properties"/> + <param name="algorithm.algorithm" value="MD5"/> + </modified> + </not> + </selector> + <au:assertFileDoesntExist file="${input}/cache/cache.properties"/> + <move todir="${output}" overwrite="true"> + <fileset dir="${input}/images"> + <include name="*.jpg" /> + <selector refid="cache.selector" /> + </fileset> + </move> + <au:assertFileExists file="${input}/cache/cache.properties"/> + <au:assertFileExists file="${input}/images/foo.jpg"/> + <au:assertFileDoesntExist file="${output}/foo.jpg"/> + <move todir="${output}" overwrite="true"> + <fileset dir="${input}/images"> + <include name="*.jpg" /> + <selector refid="cache.selector" /> + </fileset> + </move> + <au:assertFileDoesntExist file="${input}/images/foo.jpg"/> + <au:assertFileExists file="${output}/foo.jpg"/> + </target> + + <target name="testOverwriteIsTrueByDefault"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/x.txt">X</echo> + <sleep seconds="2"/> + <echo file="${output}/y.txt">Y</echo> + <move file="${input}/x.txt" tofile="${output}/y.txt"/> + <au:assertFileDoesntExist file="${input}/x.txt"/> + <au:assertResourceContains resource="${output}/y.txt" + value="X"/> + </target> + + <target name="testOverwriteIsHonored" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47755"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/x.txt">X</echo> + <sleep seconds="2"/> + <echo file="${output}/y.txt">Y</echo> + <move file="${input}/x.txt" tofile="${output}/y.txt" overwrite="false"/> + <au:assertFileExists file="${input}/x.txt"/> + <au:assertResourceContains resource="${output}/y.txt" + value="Y"/> + </target> + + <!-- stolen from ../types/readwrite-test.xml - create a read-only file --> + <property name="file" value="testfile"/> + <condition property="unix"> + <os family="unix"/> + </condition> + <target name="createTestdir"> + <mkdir dir="${output}"/> + <mkdir dir="${input}"/> + <touch file="${output}/${file}"/> + </target> + <target name="makeFileUnwritable" + depends="createTestdir,makeFileUnwritable-Unix,makeFileUnwritable-Windows"/> + <target name="makeFileUnwritable-Unix" id="unix"> + <chmod file="${output}/${file}" perm="444"/> + </target> + <target name="makeFileUnwritable-Windows" unless="unix"> + <attrib file="${output}/${file}" readonly="true"/> + </target> + + <target name="testMoveOverReadOnlyFile" depends="makeFileUnwritable"> + <sleep seconds="2"/> + <touch file="${input}/${file}"/> + <au:expectfailure + expectedMessage="can't replace read-only destination file "> + <move toDir="${output}"> + <fileset dir="${input}"/> + </move> + </au:expectfailure> + </target> + + <target name="testFilteredMoveOverReadOnlyFile" depends="makeFileUnwritable"> + <sleep seconds="2"/> + <touch file="${input}/${file}"/> + <au:expectfailure + expectedMessage="can't write to read-only destination file "> + <move toDir="${output}"> + <fileset dir="${input}"/> + <filterset> + <filter token="foo" value="bar"/> + </filterset> + </move> + </au:expectfailure> + </target> + + <target name="testMoveOverReadOnlyFileWithOverwrite" + depends="makeFileUnwritable"> + <touch file="${input}/${file}"/> + <au:expectfailure + expectedMessage="can't replace read-only destination file "> + <move toDir="${output}" overwrite="true"> + <fileset dir="${input}"/> + </move> + </au:expectfailure> + </target> + + <target name="testFilteredMoveOverReadOnlyFileWithOverwrite" + depends="makeFileUnwritable"> + <touch file="${input}/${file}"/> + <au:expectfailure + expectedMessage="can't write to read-only destination file "> + <move toDir="${output}" overwrite="true"> + <fileset dir="${input}"/> + <filterset> + <filter token="foo" value="bar"/> + </filterset> + </move> + </au:expectfailure> + </target> + + <target name="testForcedMoveOverReadOnlyFile" depends="makeFileUnwritable"> + <sleep seconds="2"/> + <touch file="${input}/${file}"/> + <move toDir="${output}" force="true"> + <fileset dir="${input}"/> + </move> + </target> + + <target name="testForcedFilteredMoveOverReadOnlyFile" + depends="makeFileUnwritable"> + <sleep seconds="2"/> + <touch file="${input}/${file}"/> + <move toDir="${output}" force="true"> + <fileset dir="${input}"/> + <filterset> + <filter token="foo" value="bar"/> + </filterset> + </move> + </target> + + <target name="testForcedMoveOverReadOnlyFileWithOverwrite" + depends="makeFileUnwritable"> + <touch file="${input}/${file}"/> + <move toDir="${output}" overwrite="true" force="true"> + <fileset dir="${input}"/> + </move> + </target> + + <target name="testForcedFilteredMoveOverReadOnlyFileWithOverwrite" + depends="makeFileUnwritable"> + <touch file="${input}/${file}"/> + <move toDir="${output}" overwrite="true" force="true"> + <fileset dir="${input}"/> + <filterset> + <filter token="foo" value="bar"/> + </filterset> + </move> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/depend/depend-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/depend/depend-test.xml new file mode 100644 index 00000000..48f94aa3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/depend/depend-test.xml @@ -0,0 +1,131 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../../antunit-base.xml" /> + + <property name="src1" location="${input}/src1"/> + <property name="src2" location="${input}/src2"/> + + <target name="setUp"> + <mkdir dir="${src1}"/> + <mkdir dir="${output}"/> + <mkdir dir="${src1}/a"/> + <echo file="${src1}/a/B.java"><![CDATA[ +package a; +public class B { + public static String hello() { + return "Hello"; + } +} +]]></echo> + <mkdir dir="${src2}/b"/> + </target> + + <target name="testBug45916" depends="setUp"> + <echo file="${src2}/b/Main.java"><![CDATA[ +package b; + +import a.B; + +public class Main { + + public static void main(String[] args) { + new Runnable() { + public void run() { + System.err.println(B.hello()); + } + }.run(); + } + +} +]]></echo> + <javac srcdir="${src1}:${src2}" + destdir="${output}"/> + + <!--to ensure that the classfiles generated in the previous step + will be outdated--> + <sleep seconds="3" /> + <touch file="${src1}/a/B.java" /> + <javac srcdir="${src1}" destdir="${output}"/> + <jar destfile="${output}/A.jar" basedir="${output}" includes="a/**"/> + <delete dir="${output}/a"/> + + <depend srcDir="${src1}" + destDir="${output}" cache="${output}" + classpath="${output}/A.jar"/> + <au:assertFileExists file="${output}/b/Main$1.class"/> + </target> + + <target name="classpathTestSetUp" depends="setUp"> + <echo file="${src2}/b/Main.java"><![CDATA[ +package b; + +import a.B; + +public class Main { + + public static void main(String[] args) { + System.err.println(B.hello()); + } + +} +]]></echo> + + <property name="dest2" location="${output}/dest2"/> + + <mkdir dir="${resources}"/> + <mkdir dir="${dest2}"/> + + <javac srcdir="${src1}" destdir="${resources}"/> + <javac srcdir="${src2}" destdir="${dest2}" classpath="${resources}"/> + <sleep seconds="3" /> + <touch file="${src1}/a/B.java" /> + <javac srcdir="${src1}" destdir="${resources}"/> + <au:assertFileExists file="${dest2}/b/Main.class"/> + </target> + + <target name="testClasspathJar" depends="classpathTestSetUp"> + + <jar destfile="${test.jar}" basedir="${resources}"/> + <delete dir="${resources}"/> + <path id="resources-id"> + <pathelement location="${test.jar}"/> + </path> + + <depend srcDir="${src2}" + destDir="${dest2}" cache="${output}" + classpathref="resources-id" + /> + <au:assertFileDoesntExist file="${dest2}/b/Main.class"/> + + </target> + + <target name="testClasspathDir" depends="classpathTestSetUp"> + + <path id="resources-id"> + <pathelement location="${resources}"/> + </path> + + <depend srcDir="${src2}" + destDir="${dest2}" cache="${output}" + classpathref="resources-id" + /> + <au:assertFileDoesntExist file="${dest2}/b/Main.class"/> + + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/funtest-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/funtest-test.xml new file mode 100644 index 00000000..6baa4f7e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/funtest-test.xml @@ -0,0 +1,128 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../antunit-base.xml"/> + + <!-- three presets for state--> + <presetdef name="p1"> + <property name="p1" value="true"/> + </presetdef> + <presetdef name="p2"> + <property name="p2" value="true"/> + </presetdef> + <presetdef name="p3"> + <property name="p3" value="true"/> + </presetdef> + <presetdef name="p4"> + <property name="p4" value="true"/> + </presetdef> + <presetdef name="p5"> + <property name="p5" value="true"/> + </presetdef> + + <presetdef name="assertP1"> + <au:assertPropertySet name="p1"/> + </presetdef> + <presetdef name="assertP2"> + <au:assertPropertySet name="p2"/> + </presetdef> + <presetdef name="assertP3"> + <au:assertPropertySet name="p3"/> + </presetdef> + <presetdef name="assertP4"> + <au:assertPropertySet name="p4"/> + </presetdef> + <presetdef name="assertP5"> + <au:assertPropertySet name="p5"/> + </presetdef> + + <target name="setUp"> + <taskdef name="funtest" + classname="org.apache.tools.ant.taskdefs.optional.testing.Funtest"/> + </target> + + <target name="testPresets" + description="test the presets behave"> + <p1/> + <assertP1/> + <p2/> + <assertP2/> + <p3/> + <assertP3/> + <p4/> + <assertP4/> + <p5/> + <assertP5/> + </target> + + <target name="testToSuccess"> + <funtest> + <setup> + <p1/> + </setup> + <application> + <assertP1/> + <p2/> + </application> + <block> + <isset property="p2"/> + </block> + <tests> + <assertP1/> + <assertP2/> + <p3/> + </tests> + <reporting> + <assertP3/> + <p4/> + </reporting> + <teardown> + <assertP4/> + <p5/> + </teardown> + </funtest> + <assertP5/> + </target> + + <target name="testCondition"> + <funtest > + <condition> + <isset property="unset"/> + </condition> + <setup> + <fail>should not be reached</fail> + </setup> + </funtest> + </target> + + <target name="testSetupFailureSkipsTeardown"> + <au:expectfailure message="setup failed"> + <funtest> + <setup> + <p1/> + <fail>setup failed</fail> + </setup> + <teardown> + <p5/> + </teardown> + </funtest> + </au:expectfailure> + <assertP1/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/javah-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/javah-test.xml new file mode 100644 index 00000000..e85293e2 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/javah-test.xml @@ -0,0 +1,65 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../antunit-base.xml" /> + + <target name="-create-javah-adapter"> + <mkdir dir="${input}/org/example" /> + <echo file="${input}/org/example/Adapter.java"> + <![CDATA[ +package org.example; +import org.apache.tools.ant.taskdefs.optional.javah.JavahAdapter; +import org.apache.tools.ant.taskdefs.optional.Javah; + +public class Adapter implements JavahAdapter { + public boolean compile(Javah javah) { + System.err.println("adapter called"); + return true; + } +}]]> + </echo> + <mkdir dir="${resources}" /> + <javac srcdir="${input}" destdir="${resources}" /> + </target> + + <target name="testAdapterNotFound" depends="-create-javah-adapter"> + <au:expectfailure> + <javah class="org.example.Adapter" destdir="${output}" implementation="org.example.Adapter" /> + </au:expectfailure> + <au:assertLogDoesntContain text="adapter called" /> + </target> + + <target name="testImplementationClasspath" depends="-create-javah-adapter" description="https://issues.apache.org/bugzilla/show_bug.cgi?id=11143"> + <mkdir dir="${output}" /> + <javah class="org.example.Adapter" destdir="${output}" implementation="org.example.Adapter"> + <implementationclasspath location="${resources}" /> + </javah> + <au:assertLogContains text="adapter called" /> + </target> + + <target name="testImplementationAsNestedElement" depends="-create-javah-adapter"> + <componentdef classname="org.example.Adapter" name="myjavac"> + <classpath location="${resources}" /> + </componentdef> + <mkdir dir="${output}" /> + <javah class="org.example.Adapter" destdir="${output}"> + <myjavac /> + </javah> + <au:assertLogContains text="adapter called" /> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/junit-formatter-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/junit-formatter-test.xml new file mode 100644 index 00000000..b9a63c94 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/junit-formatter-test.xml @@ -0,0 +1,93 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../../antunit-base.xml" /> + + <path id="junit"> + <fileset dir="../../../../../../lib/optional" includes="junit*"/> + </path> + + <target name="setUp"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/ATest.java"><![CDATA[ +package test; +import junit.framework.TestCase; + +public class ATest extends TestCase { + public void testEmpty() {} +} +]]></echo> + <javac srcdir="${input}" destdir="${output}"> + <classpath refid="junit"/> + </javac> + <macrodef name="j"> + <sequential> + <junit fork="true" forkMode="perBatch"> + <classpath refid="junit"/> + <classpath location="${output}"/> + <batchtest todir="${output}"> + <fileset dir="${output}"> + <include name="**/*Test.class" /> + </fileset> + </batchtest> + <formatter type="plain" if="${if}" extension=".dollar_if"/> + <formatter type="plain" if="if" extension=".if"/> + <formatter type="plain" unless="${if}" extension=".dollar_unless"/> + <formatter type="plain" unless="if" extension=".unless"/> + </junit> + </sequential> + </macrodef> + </target> + + <target name="testPropertyNotSet" depends="setUp"> + <j/> + <au:assertFileDoesntExist file="${output}/TEST-test.ATest.dollar_if"/> + <au:assertFileDoesntExist file="${output}/TEST-test.ATest.if"/> + <au:assertFileExists file="${output}/TEST-test.ATest.dollar_unless"/> + <au:assertFileExists file="${output}/TEST-test.ATest.unless"/> + </target> + + <target name="testPropertySet" depends="setUp"> + <property name="if" value="whatever"/> + <j/> + <au:assertFileDoesntExist file="${output}/TEST-test.ATest.dollar_if"/> + <au:assertFileExists file="${output}/TEST-test.ATest.if"/> + <au:assertFileExists file="${output}/TEST-test.ATest.dollar_unless"/> + <au:assertFileDoesntExist file="${output}/TEST-test.ATest.unless"/> + </target> + + <target name="testPropertyTrue" depends="setUp"> + <property name="if" value="true"/> + <j/> + <au:assertFileExists file="${output}/TEST-test.ATest.dollar_if"/> + <au:assertFileExists file="${output}/TEST-test.ATest.if"/> + <au:assertFileDoesntExist file="${output}/TEST-test.ATest.dollar_unless"/> + <au:assertFileDoesntExist file="${output}/TEST-test.ATest.unless"/> + </target> + + <target name="testPropertyFalse" depends="setUp"> + <property name="if" value="false"/> + <j/> + <au:assertFileDoesntExist file="${output}/TEST-test.ATest.dollar_if"/> + <au:assertFileExists file="${output}/TEST-test.ATest.if"/> + <au:assertFileExists file="${output}/TEST-test.ATest.dollar_unless"/> + <au:assertFileDoesntExist file="${output}/TEST-test.ATest.unless"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/junit-outputtoformatters-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/junit-outputtoformatters-test.xml new file mode 100644 index 00000000..29068e48 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/junit-outputtoformatters-test.xml @@ -0,0 +1,137 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="all" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../../antunit-base.xml" /> + <property name="ant-build" location="../../../../../../build"/> + <property name="build-junit-dir" location="${ant-build}/ant-unit/junit-dir"/> + <property name="reports.dir" location="${build-junit-dir}/report"/> + + <macrodef name="assert-file-not-contains" backtrace="no"> + <sequential> + <au:assertFalse> + <isfileselected file="${reports.dir}/TEST-ExampleTest.txt"> + <contains text="Hello From Test"/> + </isfileselected> + </au:assertFalse> + </sequential> + </macrodef> + + <macrodef name="assert-file-contains" backtrace="no"> + <sequential> + <au:assertTrue> + <isfileselected file="${reports.dir}/TEST-ExampleTest.txt"> + <contains text="Hello From Test"/> + </isfileselected> + </au:assertTrue> + </sequential> + </macrodef> + + <macrodef name="assert-log-not-contains" backtrace="no"> + <sequential> + <au:assertLogDoesntContain text="Hello From Test" /> + </sequential> + </macrodef> + + <macrodef name="assert-log-contains" backtrace="no"> + <sequential> + <au:assertLogContains text="Hello From Test"/> + </sequential> + </macrodef> + + <macrodef name="run-junit"> + <attribute name="fork"/> + <attribute name="showoutput"/> + <attribute name="outputtoformatters"/> + <sequential> + <junit fork="@{fork}" haltonfailure="no" showoutput="@{showoutput}" + outputtoformatters="@{outputtoformatters}"> + <test name="ExampleTest" todir="${reports.dir}"/> + <classpath path="${resources}"/> + <formatter type="plain" usefile="yes"/> + </junit> + </sequential> + </macrodef> + + <target name="init"> + <delete quiet="yes" dir="${build-junit-dir}"/> + <mkdir dir="${resources}"/> + <mkdir dir="${reports.dir}"/> + </target> + + <target name="compile" depends="init"> + <javac srcdir="src" destdir="${resources}" debug="yes"/> + </target> + + <target name="test-show-yes-formatters-yes" depends="compile"> + <run-junit fork="yes" showoutput="yes" + outputtoformatters="yes"/> + <assert-log-contains/> + <assert-file-contains/> + </target> + + <target name="test-show-yes-formatters-no" depends="compile"> + <run-junit fork="yes" showoutput="yes" + outputtoformatters="no"/> + <assert-log-contains/> + <assert-file-not-contains/> + </target> + + <target name="test-show-yes-formatters-no-forkno" depends="compile"> + <run-junit fork="no" showoutput="yes" + outputtoformatters="no"/> + <assert-log-contains/> + <assert-file-not-contains/> + </target> + + <target name="test-show-no-formatters-no" depends="compile"> + <run-junit fork="yes" showoutput="no" + outputtoformatters="no"/> + <assert-log-not-contains/> + <assert-file-not-contains/> + </target> + + <target name="test-show-no-formatters-no-fork-no" depends="compile"> + <run-junit fork="no" showoutput="no" + outputtoformatters="no"/> + <assert-log-not-contains/> + <assert-file-not-contains/> + </target> + + <target name="test-show-no-formatters-yes" depends="compile"> + <run-junit fork="yes" showoutput="no" + outputtoformatters="yes"/> + <assert-log-not-contains/> + <assert-file-contains/> + </target> + + <target name="test-show-no-formatters-yes-fork-no" depends="compile"> + <run-junit fork="no" showoutput="no" + outputtoformatters="yes"/> + <assert-log-not-contains/> + <assert-file-contains/> + </target> + + <target name="all"> + <au:antunit> + <fileset file="${ant.file}"/> + <au:plainlistener/> + </au:antunit> + </target> + +</project> + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/junit-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/junit-test.xml new file mode 100644 index 00000000..e6aa794c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/junit-test.xml @@ -0,0 +1,372 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../../antunit-base.xml" /> + + <path id="junit"> + <fileset dir="../../../../../../lib/optional" includes="junit*" /> + <fileset dir="../../../../../../lib/optional" includes="hamcrest-core*" /> + </path> + + <macrodef name="empty-test"> + <attribute name="classname" /> + <attribute name="package" default="test" /> + <sequential> + <echo file="${input}/@{classname}.java"> + <![CDATA[ +package @{package}; +import junit.framework.TestCase; + +public class @{classname} extends TestCase { + public void testEmpty() {} +} +]]> + </echo> + </sequential> + </macrodef> + + <target name="setUp"> + <mkdir dir="${input}" /> + <mkdir dir="${output}" /> + </target> + + <target name="testTimeoutLogOfBatchTests"> + <mkdir dir="${input}" /> + <mkdir dir="${output}" /> + <empty-test classname="ATest" package="org.apache.ant.test" /> + <echo file="${input}/BTest.java"> + <![CDATA[ +package org.apache.ant.test; +import junit.framework.TestCase; + +public class BTest extends TestCase { + public void testEmpty() throws Exception { + Thread.sleep(20 * 1000); + } +} +]]> + </echo> + <empty-test classname="CTest" package="org.apache.ant.test" /> + <empty-test classname="DTest" package="org.apache.ant.test" /> + <javac srcdir="${input}" destdir="${output}"> + <classpath refid="junit" /> + </javac> + <junit fork="true" forkMode="perBatch" timeout="5000" printsummary="yes"> + <classpath refid="junit" /> + <classpath location="${output}" /> + <batchtest> + <fileset dir="${output}"> + <include name="**/*Test.class" /> + </fileset> + </batchtest> + </junit> + <au:assertLogContains text="ATest" /> + <au:assertLogContains text="BTest" /> + <au:assertLogContains text="org.apache.ant.test.Batch-With-Multiple-Tests" /> + <au:assertLogDoesntContain text="CTest" /> + <au:assertLogDoesntContain text="DTest" /> + </target> + + <target name="testFailurePropertyOnTestCase"> + <mkdir dir="${input}" /> + <mkdir dir="${output}" /> + <echo file="${input}/ATest.java"> + <![CDATA[ +package test; +import junit.framework.TestCase; + +public class ATest extends TestCase { + public void testFail() { + assertTrue(false); + } +} +]]> + </echo> + <javac srcdir="${input}" destdir="${output}"> + <classpath refid="junit" /> + </javac> + <junit failureProperty="testcase.failed" haltonfailure="false"> + <classpath refid="junit" /> + <classpath location="${output}" /> + <batchtest> + <fileset dir="${output}"> + <include name="**/*Test.class" /> + </fileset> + </batchtest> + </junit> + <au:assertPropertySet name="testcase.failed" /> + </target> + + <target name="testFailurePropertyOnTestSuite"> + <mkdir dir="${input}" /> + <mkdir dir="${output}" /> + <echo file="${input}/ATest.java"> + <![CDATA[ +package test; +import junit.framework.Assert; +import junit.framework.TestSuite; + +public class ATest extends TestSuite { + public ATest() { + super(test.ATest.class); + } + public void testFail() { + Assert.assertTrue(false); + } +} +]]> + </echo> + <javac srcdir="${input}" destdir="${output}"> + <classpath refid="junit" /> + </javac> + <junit failureProperty="testsuite.failed" haltonfailure="false"> + <classpath refid="junit" /> + <classpath location="${output}" /> + <batchtest> + <fileset dir="${output}"> + <include name="**/*Test.class" /> + </fileset> + </batchtest> + </junit> + <au:assertPropertySet name="testsuite.failed" /> + </target> + + <target name="testTimeoutAndFormattersForkPerTest"> + <antcall target="runTimeoutAndFormattersTest"> + <param name="forkMode" value="perTest" /> + </antcall> + <au:assertFileExists file="${output}/TEST-test.CTest.txt" /> + <au:assertFileExists file="${output}/TEST-test.CTest.xml" /> + <au:assertFileExists file="${output}/TEST-test.DTest.txt" /> + <au:assertFileExists file="${output}/TEST-test.DTest.xml" /> + </target> + + <target name="testTimeoutAndFormattersForkOnce"> + <antcall target="runTimeoutAndFormattersTest"> + <param name="forkMode" value="once" /> + </antcall> + <au:assertFileDoesntExist file="${output}/TEST-test.CTest.txt" /> + <au:assertFileDoesntExist file="${output}/TEST-test.CTest.xml" /> + <au:assertFileDoesntExist file="${output}/TEST-test.DTest.txt" /> + <au:assertFileDoesntExist file="${output}/TEST-test.DTest.xml" /> + </target> + + <target name="runTimeoutAndFormattersTest" description="https://issues.apache.org/bugzilla/show_bug.cgi?id=35634"> + <mkdir dir="${input}" /> + <mkdir dir="${output}" /> + <empty-test classname="ATest" /> + <echo file="${input}/BTest.java"> + <![CDATA[ +package test; +import junit.framework.TestCase; + +public class BTest extends TestCase { + public void testEmpty() throws Exception { + Thread.sleep(20 * 1000); + } +} +]]> + </echo> + <empty-test classname="CTest" /> + <empty-test classname="DTest" /> + <javac srcdir="${input}" destdir="${output}"> + <classpath refid="junit" /> + </javac> + <junit fork="true" timeout="5000" forkmode="${forkMode}"> + <classpath refid="junit" /> + <classpath location="${output}" /> + <batchtest todir="${output}"> + <fileset dir="${output}"> + <include name="**/*Test.class" /> + </fileset> + </batchtest> + <formatter type="brief" /> + <formatter type="xml" /> + </junit> + <au:assertFileExists file="${output}/TEST-test.ATest.txt" /> + <au:assertFileExists file="${output}/TEST-test.ATest.xml" /> + <!-- + <au:assertFileExists file="${output}/TEST-test.BTest.txt" /> + <au:assertFileExists file="${output}/TEST-test.BTest.xml" /> + + These files should only exist if something was written to the log by te runner. + The test previously passed even though the files were empty, which isn't a meaningful result. + TODO we should probably improve the testing around reporting of tests that have timed-out + --> + </target> + + <target name="-ifUnlessSetup" depends="setUp"> + <empty-test classname="ATest" /> + <empty-test classname="BTest" /> + <empty-test classname="CTest" /> + <empty-test classname="DTest" /> + <empty-test classname="ETest" /> + <empty-test classname="FTest" /> + <empty-test classname="GTest" /> + <empty-test classname="HTest" /> + <javac srcdir="${input}" destdir="${output}"> + <classpath refid="junit" /> + </javac> + <macrodef name="j"> + <sequential> + <junit fork="true" forkMode="perBatch" printsummary="yes"> + <classpath refid="junit" /> + <classpath location="${output}" /> + <test name="test.ATest" if="${if}" /> + <test name="test.BTest" if="if" /> + <test name="test.CTest" unless="${if}" /> + <test name="test.DTest" unless="if" /> + <batchtest if="${if}"> + <fileset dir="${output}"> + <include name="**/ETest.class" /> + </fileset> + </batchtest> + <batchtest if="if"> + <fileset dir="${output}"> + <include name="**/FTest.class" /> + </fileset> + </batchtest> + <batchtest unless="${if}"> + <fileset dir="${output}"> + <include name="**/GTest.class" /> + </fileset> + </batchtest> + <batchtest unless="if"> + <fileset dir="${output}"> + <include name="**/HTest.class" /> + </fileset> + </batchtest> + </junit> + </sequential> + </macrodef> + </target> + + <target name="testPropertiesNotSet" depends="-ifUnlessSetup"> + <j /> + <au:assertLogDoesntContain text="Running test.ATest" /> + <au:assertLogDoesntContain text="Running test.BTest" /> + <au:assertLogContains text="Running test.CTest" /> + <au:assertLogContains text="Running test.DTest" /> + <au:assertLogDoesntContain text="Running test.ETest" /> + <au:assertLogDoesntContain text="Running test.FTest" /> + <au:assertLogContains text="Running test.GTest" /> + <au:assertLogContains text="Running test.HTest" /> + </target> + + <target name="testPropertiesSet" depends="-ifUnlessSetup"> + <property name="if" value="whatever" /> + <j /> + <au:assertLogDoesntContain text="Running test.ATest" /> + <au:assertLogContains text="Running test.BTest" /> + <au:assertLogContains text="Running test.CTest" /> + <au:assertLogDoesntContain text="Running test.DTest" /> + <au:assertLogDoesntContain text="Running test.ETest" /> + <au:assertLogContains text="Running test.FTest" /> + <au:assertLogContains text="Running test.GTest" /> + <au:assertLogDoesntContain text="Running test.HTest" /> + </target> + + <target name="testPropertiesTrue" depends="-ifUnlessSetup"> + <property name="if" value="true" /> + <j /> + <au:assertLogContains text="Running test.ATest" /> + <au:assertLogContains text="Running test.BTest" /> + <au:assertLogDoesntContain text="Running test.CTest" /> + <au:assertLogDoesntContain text="Running test.DTest" /> + <au:assertLogContains text="Running test.ETest" /> + <au:assertLogContains text="Running test.FTest" /> + <au:assertLogDoesntContain text="Running test.GTest" /> + <au:assertLogDoesntContain text="Running test.HTest" /> + </target> + + <target name="testPropertiesFalse" depends="-ifUnlessSetup"> + <property name="if" value="false" /> + <j /> + <au:assertLogDoesntContain text="Running test.ATest" /> + <au:assertLogContains text="Running test.BTest" /> + <au:assertLogContains text="Running test.CTest" /> + <au:assertLogDoesntContain text="Running test.DTest" /> + <au:assertLogDoesntContain text="Running test.ETest" /> + <au:assertLogContains text="Running test.FTest" /> + <au:assertLogContains text="Running test.GTest" /> + <au:assertLogDoesntContain text="Running test.HTest" /> + </target> + + <target name="testMissingTestName"> + <property name="test.name" value="null" /> + <au:expectfailure message="test name must be specified"> + <junit fork="false"> + <test name="${test.name}" /> + </junit> + </au:expectfailure> + </target> + + <target name="testTestMethods"> + <condition property="source" value="6"> + <isset property="jdk1.6+"/> + </condition> + <property name="source" value="5"/> + <echo file="${input}/T1.java">public class T1 extends + junit.framework.TestCase { + public void testOK() {} + public void testBad() {throw new RuntimeException("failed");} + }</echo> + <echo file="${input}/T2.java"> + import org.junit.Test; + public class T2 { + @Test + public void ok() {} + @Test + public void bad() { + throw new RuntimeException("failed");} + }</echo> + <javac srcdir="${input}" destdir="${output}" includes="T1.java,T2.java" source="${source}" includeantruntime="false"> + <classpath> + <path refid="junit" /> + </classpath> + </javac> + <junit fork="true" printsummary="true" haltonerror="true"> + <classpath> + <pathelement location="${output}" /> + <path refid="junit" /> + </classpath> + <test name="T1" methods="testOK" /> + <test name="T2" methods="ok" /> + </junit> + </target> + + <target name="testClasspathBuildingSurvivesNonZips" depends="setUp" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=53964"> + <empty-test classname="ATest" package="org.apache.ant.test" /> + <javac srcdir="${input}" destdir="${output}"> + <classpath refid="junit" /> + </javac> + <junit fork="true" printsummary="true" haltonerror="true"> + <classpath> + <pathelement location="${output}" /> + <pathelement location="${ant.file}" /> + <path refid="junit" /> + </classpath> + <batchtest> + <fileset dir="${output}"> + <include name="**/*Test.class" /> + </fileset> + </batchtest> + </junit> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/src/ExampleTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/src/ExampleTest.java new file mode 100644 index 00000000..f1e5ca2b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/src/ExampleTest.java @@ -0,0 +1,23 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You 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. +*/ +import junit.framework.TestCase; + +public class ExampleTest extends TestCase { + public void testHello() { + System.out.println("Hello From Test"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/xmlformatter-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/xmlformatter-test.xml new file mode 100644 index 00000000..4aa6e4da --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/junit/xmlformatter-test.xml @@ -0,0 +1,126 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../../antunit-base.xml"/> + + <path id="junit"> + <fileset dir="../../../../../../lib/optional" includes="junit*"/> + </path> + + <target name="test0Character"> + <mkdir dir="${input}/org/example"/> + <echo file="${input}/org/example/A.java"><![CDATA[ +package org.example; +import junit.framework.TestCase; +public class A extends TestCase { + public void testX() { + System.err.println("Here comes the zero: \u0000"); + } +} +]]></echo> + <mkdir dir="${output}"/> + <javac srcdir="${input}" destdir="${output}"> + <classpath refid="junit"/> + </javac> + <junit fork="true"> + <classpath refid="junit"/> + <classpath location="${output}"/> + <batchtest todir="${output}"> + <fileset dir="${output}"> + <include name="**/A.class" /> + </fileset> + </batchtest> + <formatter type="xml"/> + </junit> + <xmlvalidate file="${output}/TEST-org.example.A.xml" + lenient="true"/> + </target> + + <target name="testEntities" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49404"> + <mkdir dir="${input}/org/example"/> + <echo file="${input}/org/example/A.java"><![CDATA[ +package org.example; +import junit.framework.TestCase; +public class A extends TestCase { + public void testX() { + assertTrue("&&", false); + } +} +]]></echo> + <mkdir dir="${output}"/> + <javac srcdir="${input}" destdir="${output}"> + <classpath refid="junit"/> + </javac> + <junit fork="true"> + <classpath refid="junit"/> + <classpath location="${output}"/> + <batchtest todir="${output}"> + <fileset dir="${output}"> + <include name="**/A.class" /> + </fileset> + </batchtest> + <formatter type="xml"/> + </junit> + <xmlvalidate file="${output}/TEST-org.example.A.xml" + lenient="true"/> + <au:assertResourceContains + resource="${output}/TEST-org.example.A.xml" + value="message="&amp;amp;&amp;"/> + <au:assertResourceContains + resource="${output}/TEST-org.example.A.xml" + value="AssertionFailedError: &amp;amp;&"/> + </target> + + <target name="testMessageWithTheWordMore"> + <mkdir dir="${input}/org/example"/> + <echo file="${input}/org/example/A.java"><![CDATA[ +package org.example; +import junit.framework.TestCase; +public class A extends TestCase { + public void testX() { + assertTrue("Expected more than one result", 0 > 1); + } + public void testY() { + assertTrue("Expected less than one result", 2 < 1); + } +} +]]></echo> + <mkdir dir="${output}"/> + <javac srcdir="${input}" destdir="${output}"> + <classpath refid="junit"/> + </javac> + <junit fork="true"> + <classpath refid="junit"/> + <classpath location="${output}"/> + <batchtest todir="${output}"> + <fileset dir="${output}"> + <include name="**/A.class" /> + </fileset> + </batchtest> + <formatter type="xml"/> + </junit> + <au:assertResourceContains + resource="${output}/TEST-org.example.A.xml" + value="junit.framework.AssertionFailedError: Expected less than one result"/> + <au:assertResourceContains + resource="${output}/TEST-org.example.A.xml" + value="junit.framework.AssertionFailedError: Expected more than one result"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/native2ascii-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/native2ascii-test.xml new file mode 100644 index 00000000..7a30df79 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/native2ascii-test.xml @@ -0,0 +1,68 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../antunit-base.xml" /> + + <target name="-create-native2ascii-adapter"> + <mkdir dir="${input}/org/example"/> + <echo file="${input}/org/example/Adapter.java"><![CDATA[ +package org.example; +import java.io.File; +import org.apache.tools.ant.taskdefs.optional.native2ascii.Native2AsciiAdapter; +import org.apache.tools.ant.taskdefs.optional.Native2Ascii; + +public class Adapter implements Native2AsciiAdapter { + public boolean convert(Native2Ascii native2ascii, File f1, File f2) { + System.err.println("adapter called"); + return true; + } +}]]></echo> + <mkdir dir="${resources}"/> + <javac srcdir="${input}" destdir="${resources}"/> + </target> + + <target name="testAdapterNotFound" depends="-create-native2ascii-adapter" unless="build.sysclasspath.only"> + <!-- under gump the failure will not happen because the ${resources} directory is systematically on the classpath + what would be cool would be a task which removes a path element from the classpath. Do we have that ? --> + <au:expectfailure> + <native2ascii src="${input}" dest="${output}" includes="**/*.java" + implementation="org.example.Adapter"/> + </au:expectfailure> + <au:assertLogDoesntContain text="adapter called"/> + </target> + + <target name="testImplementationClasspath" depends="-create-native2ascii-adapter" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=11143"> + <native2ascii src="${input}" dest="${output}" includes="**/*.java" + implementation="org.example.Adapter"> + <implementationclasspath location="${resources}"/> + </native2ascii> + <au:assertLogContains text="adapter called"/> + </target> + + <target name="testImplementationAsNestedElement" + depends="-create-native2ascii-adapter"> + <componentdef classname="org.example.Adapter" name="myjavac"> + <classpath location="${resources}"/> + </componentdef> + <native2ascii src="${input}" dest="${output}" includes="**/*.java"> + <myjavac/> + </native2ascii> + <au:assertLogContains text="adapter called"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/propertyfile-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/propertyfile-test.xml new file mode 100644 index 00000000..0ea70513 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/propertyfile-test.xml @@ -0,0 +1,44 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${output}"/> + </target> + + <target name="testReadWithPrefix" depends="setUp" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=48768"> + <property name="test.txt" location="${output}/test.txt"/> + <echo file="${test.txt}"><![CDATA[ +bbb=val2 +aaa=val1 +]]></echo> + + <property file="${test.txt}"/> + <au:assertPropertyEquals name="aaa" value="val1"/> + <au:assertPropertyEquals name="bbb" value="val2"/> + <propertyfile file="${test.txt}"> + <entry key="bbb" value="dummy"/> + </propertyfile> + + <property file="${test.txt}" prefix="xxx"/> + <au:assertPropertyEquals name="xxx.aaa" value="val1"/> + <au:assertPropertyEquals name="xxx.bbb" value="dummy"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml new file mode 100644 index 00000000..f1b367f9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/propertyfilelayout-test.xml @@ -0,0 +1,289 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <echo file="${input}/initial.properties"><![CDATA[#my comment +foo=bar +#second comment +x=1 +]]></echo> + <fixcrlf file="${input}/initial.properties"/> + <presetdef name="pf"> + <propertyfile file="${output}/created.properties"> + <entry key="foo" value="bar"/> + <entry key="x" value="1" type="int"/> + </propertyfile> + </presetdef> + </target> + + <target name="testCreateWithoutComment" depends="setUp"> + <pf/> + <local name="head.in"/> + <local name="head.out"/> + <local name="tail.in"/> + <local name="tail.out"/> + <!-- skip comment --> + <loadfile srcfile="${input}/initial.properties" property="head.in"> + <filterchain> + <headfilter lines="1" skip="1"/> + </filterchain> + </loadfile> + <loadfile srcfile="${input}/initial.properties" property="tail.in"> + <filterchain> + <tailfilter lines="1"/> + </filterchain> + </loadfile> + <!-- skip date and blank line --> + <loadfile srcfile="${output}/created.properties" property="head.out"> + <filterchain> + <headfilter lines="1" skip="2"/> + </filterchain> + </loadfile> + <loadfile srcfile="${output}/created.properties" property="tail.out"> + <filterchain> + <tailfilter lines="1"/> + </filterchain> + </loadfile> + <au:assertPropertyEquals name="head.out" value="${head.in}"/> + <au:assertPropertyEquals name="tail.out" value="${tail.in}"/> + </target> + + <target name="testCreateWithComment" depends="setUp"> + <pf comment="my comment"/> + <local name="head.in"/> + <local name="head.out"/> + <local name="middle.in"/> + <local name="middle.out"/> + <local name="tail.in"/> + <local name="tail.out"/> + <!-- just comment --> + <loadfile srcfile="${input}/initial.properties" property="head.in"> + <filterchain> + <headfilter lines="1"/> + </filterchain> + </loadfile> + <!-- skip comment --> + <loadfile srcfile="${input}/initial.properties" property="middle.in"> + <filterchain> + <headfilter lines="1" skip="1"/> + </filterchain> + </loadfile> + <loadfile srcfile="${input}/initial.properties" property="tail.in"> + <filterchain> + <tailfilter lines="1"/> + </filterchain> + </loadfile> + <!-- just comment --> + <loadfile srcfile="${output}/created.properties" property="head.out"> + <filterchain> + <headfilter lines="1"/> + </filterchain> + </loadfile> + <!-- skip comment, date and blank line --> + <loadfile srcfile="${output}/created.properties" property="middle.out"> + <filterchain> + <headfilter lines="1" skip="3"/> + </filterchain> + </loadfile> + <loadfile srcfile="${output}/created.properties" property="tail.out"> + <filterchain> + <tailfilter lines="1"/> + </filterchain> + </loadfile> + <au:assertPropertyEquals name="head.out" value="${head.in}"/> + <au:assertPropertyEquals name="middle.out" value="${middle.in}"/> + <au:assertPropertyEquals name="tail.out" value="${tail.in}"/> + </target> + + <target name="-updateSetUp" depends="setUp"> + <copy file="${input}/initial.properties" + tofile="${output}/created.properties"/> + </target> + + <target name="testUpdateWithoutComment" depends="-updateSetUp"> + <pf/> + <local name="head.in"/> + <local name="head.out"/> + <loadfile srcfile="${input}/initial.properties" property="head.in"/> + <!-- skip date --> + <loadfile srcfile="${output}/created.properties" property="head.out"> + <filterchain> + <headfilter skip="1"/> + </filterchain> + </loadfile> + <au:assertPropertyEquals name="head.out" value="${head.in}"/> + </target> + + <target name="testUpdateWithNewComment" depends="-updateSetUp"> + <pf comment="new comment"/> + <local name="head.in"/> + <local name="head.out"/> + <local name="tail.in"/> + <local name="tail.out"/> + <property name="head.in" value="#new comment${line.separator}"/> + <!-- just comment --> + <loadfile srcfile="${output}/created.properties" property="head.out"> + <filterchain> + <headfilter lines="1"/> + </filterchain> + </loadfile> + <loadfile srcfile="${input}/initial.properties" property="tail.in"/> + <!-- skip new comment and date --> + <loadfile srcfile="${output}/created.properties" property="tail.out"> + <filterchain> + <headfilter skip="2"/> + </filterchain> + </loadfile> + <au:assertPropertyEquals name="head.out" value="${head.in}"/> + <au:assertPropertyEquals name="tail.out" value="${tail.in}"/> + </target> + + <target name="testUpdateWithSameComment" depends="-updateSetUp"> + <pf comment="my comment"/> + <local name="head.in"/> + <local name="head.out"/> + <local name="tail.in"/> + <local name="tail.out"/> + <!-- just comment --> + <loadfile srcfile="${input}/initial.properties" property="head.in"> + <filterchain> + <headfilter lines="1"/> + </filterchain> + </loadfile> + <!-- just comment --> + <loadfile srcfile="${output}/created.properties" property="head.out"> + <filterchain> + <headfilter lines="1"/> + </filterchain> + </loadfile> + <!-- skip comment --> + <loadfile srcfile="${input}/initial.properties" property="tail.in"> + <filterchain> + <headfilter skip="1"/> + </filterchain> + </loadfile> + <!-- skip comment and date --> + <loadfile srcfile="${output}/created.properties" property="tail.out"> + <filterchain> + <headfilter skip="2"/> + </filterchain> + </loadfile> + <au:assertPropertyEquals name="head.out" value="${head.in}"/> + <au:assertPropertyEquals name="tail.out" value="${tail.in}"/> + </target> + + <target name="testRepeatedUpdateWithoutComment" depends="-updateSetUp"> + <pf/> + <pf/> + <local name="head.in"/> + <local name="head.out"/> + <loadfile srcfile="${input}/initial.properties" property="head.in"/> + <!-- skip date --> + <loadfile srcfile="${output}/created.properties" property="head.out"> + <filterchain> + <headfilter skip="1"/> + </filterchain> + </loadfile> + <au:assertPropertyEquals name="head.out" value="${head.in}"/> + </target> + + <target name="testRepeatedUpdateWithSameComment" depends="-updateSetUp"> + <pf comment="my comment"/> + <pf comment="my comment"/> + <local name="head.in"/> + <local name="head.out"/> + <local name="tail.in"/> + <local name="tail.out"/> + <!-- just comment --> + <loadfile srcfile="${input}/initial.properties" property="head.in"> + <filterchain> + <headfilter lines="1"/> + </filterchain> + </loadfile> + <!-- just comment --> + <loadfile srcfile="${output}/created.properties" property="head.out"> + <filterchain> + <headfilter lines="1"/> + </filterchain> + </loadfile> + <!-- skip comment --> + <loadfile srcfile="${input}/initial.properties" property="tail.in"> + <filterchain> + <headfilter skip="1"/> + </filterchain> + </loadfile> + <!-- skip comment and date --> + <loadfile srcfile="${output}/created.properties" property="tail.out"> + <filterchain> + <headfilter skip="2"/> + </filterchain> + </loadfile> + <au:assertPropertyEquals name="head.out" value="${head.in}"/> + <au:assertPropertyEquals name="tail.out" value="${tail.in}"/> + </target> + + + <target name="testPreservesDosLineEnds" depends="setUp" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50049"> + <property name="test.txt" location="${output}/test.txt"/> + <echo file="${test.txt}"><![CDATA[ +bbb=val2 +aaa=val1 +]]></echo> + <fixcrlf eol="dos" file="${test.txt}"/> + <propertyfile file="${test.txt}" comment="${header}"/> + <copy file="${test.txt}" tofile="${test.txt}.expected"/> + <fixcrlf eol="dos" file="${test.txt}.expected"/> + <au:assertFilesMatch expected="${test.txt}.expected" + actual="${test.txt}"/> + </target> + + <target name="testPreservesUnixLineEnds" depends="setUp" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50049"> + <property name="test.txt" location="${output}/test.txt"/> + <echo file="${test.txt}"><![CDATA[ +bbb=val2 +aaa=val1 +]]></echo> + <fixcrlf eol="unix" file="${test.txt}"/> + <propertyfile file="${test.txt}" comment="${header}"/> + <copy file="${test.txt}" tofile="${test.txt}.expected"/> + <fixcrlf eol="unix" file="${test.txt}.expected"/> + <au:assertFilesMatch expected="${test.txt}.expected" + actual="${test.txt}"/> + </target> + + <target name="testPreservesMacLineEnds" depends="setUp" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50049"> + <property name="test.txt" location="${output}/test.txt"/> + <echo file="${test.txt}"><![CDATA[ +bbb=val2 +aaa=val1 +]]></echo> + <fixcrlf eol="mac" file="${test.txt}"/> + <propertyfile file="${test.txt}" comment="${header}"/> + <copy file="${test.txt}" tofile="${test.txt}.expected"/> + <fixcrlf eol="mac" file="${test.txt}.expected"/> + <au:assertFilesMatch expected="${test.txt}.expected" + actual="${test.txt}"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/replaceregexp-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/replaceregexp-test.xml new file mode 100644 index 00000000..2d64ce7a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/replaceregexp-test.xml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../antunit-base.xml" /> + + <target name="testRCSupport"> + <mkdir dir="${output}"/> + <echo file="${output}/text.txt"><![CDATA[ +Hello, world! +]]></echo> + <replaceregexp match="world" replace="Ant"> + <file file="${output}/text.txt"/> + </replaceregexp> + <au:assertResourceContains + resource="${output}/text.txt" value="Hello, Ant!"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml new file mode 100644 index 00000000..da78e427 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/script/scriptdef-test.xml @@ -0,0 +1,131 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../../../antunit-base.xml" /> + + <description> + In which we test interesting aspects of scripting. + The targeted language is javascript; this lets us run without + additions on Java6+. + </description> + + <condition property="prereqs-ok"> + <or> + <and> + <available classname="org.apache.bsf.BSFManager" /> + <available classname="org.apache.bsf.engines.javascript.JavaScriptEngine" /> + </and> + <available classname="javax.script.ScriptEngineManager" /> + </or> + </condition> + + <!-- auto doesn't verify the language is supported and selects BSF + even if the JavaScriptEngine is not there --> + <condition property="script.manager" value="javax"> + <and> + <not> + <available classname="org.apache.bsf.engines.javascript.JavaScriptEngine" /> + </not> + <isset property="prereqs-ok"/> + </and> + </condition> + <property name="script.manager" value="auto" /> + + <string id="script.code"> + self.log("Ant version =${ant.version}"); + project.setNewProperty("property","live"); + </string> + + <presetdef name="js"> + <scriptdef language="javascript" name="scripttest" manager="${script.manager}"> + <!-- optional property attribute--> + <attribute name="property" /> + </scriptdef> + </presetdef> + + <property name="prop" value='self.log("Ant version =${ant.version}");project.setNewProperty("property","live");' /> + + <presetdef name="assertPropSet"> + <au:assertPropertyEquals name="property" value="live" /> + </presetdef> + + + <!--purely to test that everything works --> + <target name="testInline" if="prereqs-ok"> + <js>self.log("Hello");</js> + <scripttest /> + </target> + + <target name="testStringResource" if="prereqs-ok"> + <js> + <string value='self.log("Ant version =${ant.version}");' /> + </js> + <scripttest /> + </target> + + <target name="testStringResourceRef" if="prereqs-ok"> + <js> + <string refid="script.code" /> + </js> + <scripttest /> + <assertPropSet /> + </target> + + <target name="testStringResourceInline" if="prereqs-ok"> + <js> + <string> + self.log("Ant version =${ant.version}"); + project.setNewProperty("property","live"); + </string> + </js> + <scripttest /> + <assertPropSet /> + </target> + + <target name="testPropertyResource" if="prereqs-ok"> + <js> + <propertyresource name="prop" /> + </js> + <scripttest /> + <assertPropSet /> + </target> + + <target name="testMixedResources" if="prereqs-ok"> + <js> + <string refid="script.code" /> + <propertyresource name="prop" /> + <string> + project.setNewProperty("property2","live"); + </string> + </js> + <scripttest /> + <assertPropSet name="property2" /> + </target> + + <target name="testExceptionNesting" description="https://issues.apache.org/bugzilla/show_bug.cgi?id=47509" if="prereqs-ok"> + <scriptdef name="quickfail" language="javascript"> + <![CDATA[ + self.fail("I failed!"); + ]]> + </scriptdef> + <au:expectfailure message="I failed!"> + <quickfail /> + </au:expectfailure> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/unix/symlink-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/unix/symlink-test.xml new file mode 100644 index 00000000..90c57f43 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/unix/symlink-test.xml @@ -0,0 +1,109 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="symlink-test" + default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../../antunit-base.xml"/> + + <target name="setUp"> + <condition property="isUnix"> + <os family="unix" /> + </condition> + </target> + + <target name="tearDown" depends="antunit-base.tearDown" + if="chmod.tmp"> + <chmod dir="${chmod.tmp}" perm="755"/> + <delete dir="${chmod.tmp}"/> + </target> + + <target name="os"> + + <mkdir dir="${output}" /> + <condition property="unix"> + <os family="unix" /> + </condition> + <property name="file_ref" + location="${output}/file"/> + <property name="hanging_ref" + location="${output}/hanging_ref"/> + </target> + + <target name="init" depends="os" if="unix"> + <touch file="${file_ref}" /> + </target> + + <target name="testCreateDouble" depends="init" if="unix"> + <symlink overwrite="true" link="${output}/link" + resource="${file_ref}"/> + <symlink overwrite="true" link="${output}/link" + resource="${file_ref}"/> + </target> + + + <target name="testCreateDoubleHanging" depends="init" if="unix"> + <symlink overwrite="true" link="${output}/link2" + resource="${hanging_ref}"/> + <symlink overwrite="true" link="${output}/link2" + resource="${hanging_ref}"/> + </target> + + <target name="testCreateOverFile" depends="init" if="unix"> + <touch file="${output}/link3" /> + <symlink overwrite="true" link="${output}/link3" + resource="${file_ref}"/> + </target> + + <target name="testDeleteOfBrokenLink" depends="init" if="unix"> + <symlink link="${output}/link" resource="${file_ref}"/> + <delete file="${file_ref}"/> + <symlink link="${output}/link" action="delete"/> + <au:assertFileDoesntExist file="${output}/link"/> + </target> + + <target name="testDeleteLinkToParent" depends="init" if="unix"> + <symlink link="${output}/link" resource="${output}"/> + <symlink link="${output}/link" action="delete"/> + <au:assertFileDoesntExist file="${output}/link"/> + </target> + + <target name="testDeleteWithNoPermissionToRenameTarget" + depends="init" if="unix"> + <!-- must be outside of ${output} or "base" tearDown will fail --> + <property name="chmod.tmp" location="${output}/../ant-symlink-test"/> + <mkdir dir="${chmod.tmp}/A"/> + <chmod perm="555" dir="${chmod.tmp}"/> + <symlink link="${output}/link" resource="${chmod.tmp}/A"/> + <symlink link="${output}/link" action="delete"/> + <au:assertFileDoesntExist file="${output}/link"/> + </target> + + <target name="testDeleteLinkInSameDirAsBuildFile" depends="setUp" if="isUnix" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49137"> + <mkdir dir="${output}/Templates"/> + <mkdir dir="${output}/project1"/> + <symlink action="single" link="${output}/project1/Templates" + resource="../Templates"/> + <echo file="${output}/project1/build.xml"><![CDATA[ +<project name="project1" default="build" basedir="."> + <target name="build"> + <symlink action="delete" link="Templates"/> + </target> +</project>]]></echo> + <ant antfile="${output}/project1/build.xml"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/windows/attrib-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/windows/attrib-test.xml new file mode 100644 index 00000000..d5cea2b5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/optional/windows/attrib-test.xml @@ -0,0 +1,46 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../../../antunit-base.xml" /> + + <target name="setUp"> + <condition property="windows?"> + <os family="windows"/> + </condition> + <mkdir dir="${input}"/> + </target> + + <target name="testPerformance" depends="setUp" if="windows?" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=48734"> + <touch file="${input}/0.tld"/> + <touch file="${input}/1.tld"/> + <touch file="${input}/2.tld"/> + <touch file="${input}/3.tld"/> + <touch file="${input}/4.tld"/> + <touch file="${input}/5.tld"/> + <touch file="${input}/6.tld"/> + <touch file="${input}/7.tld"/> + <touch file="${input}/8.tld"/> + <touch file="${input}/9.tld"/> + <attrib readonly="false"> + <fileset dir="${input}"> + <include name="*.tld" /> + </fileset> + </attrib> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/parallel-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/parallel-test.xml new file mode 100644 index 00000000..72e4828d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/parallel-test.xml @@ -0,0 +1,37 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<project default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <target name="testTimeout" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49527"> + <au:expectfailure message="Parallel execution timed out"> + <parallel timeout="2000"> + <sequential> + <echo message="Before sleep" /> + <sleep seconds="10" /> + <echo message="After sleep" /> + </sequential> + </parallel> + </au:expectfailure> + <au:assertLogDoesntContain text="After sleep"/> + </target> +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/pathconvert-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/pathconvert-test.xml new file mode 100644 index 00000000..3683affe --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/pathconvert-test.xml @@ -0,0 +1,31 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="test-dir-char"> + <pathconvert property="def|ghi" dirsep="|"> + <map from="${basedir}/abc/" to=''/> + <path location="abc/def/ghi"/> + </pathconvert> + <au:assertTrue> + <equals arg1="${def|ghi}" arg2="def|ghi"/> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/property-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/property-test.xml new file mode 100644 index 00000000..2eb0e18f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/property-test.xml @@ -0,0 +1,171 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. + --> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <target name="testNestedText"> + <property name="foo">bar</property> + <au:assertPropertyEquals name="foo" value="bar"/> + </target> + + <target name="testNoNestedTextButValueAttribute"> + <property name="foo" value="bar"> + </property> + <au:assertPropertyEquals name="foo" value="bar"/> + </target> + + <target name="testNestedTextAndValueAttribute"> + <au:expectfailure> + <property name="foo" value="bar"> + hello + </property> + </au:expectfailure> + </target> + + <!-- Ensure we have platform dependent path separator --> + <property name="base" location="${basedir}"/> + <!-- an existing file as anchor for calculating paths --> + <property name="testfile" value="condition${file.separator}antversion-test.xml"/> + + <target name="testLocation"> + <property name="foo" location="${testfile}"/> + <au:assertPropertyEquals name="foo" value="${base}${file.separator}${testfile}"/> + </target> + + <target name="testLocationWithRecursive"> + <property name="foo" location="${testfile}" relative="false"/> + <au:assertPropertyEquals name="foo" value="${base}${file.separator}${testfile}"/> + </target> + + <target name="testRelative"> + <property name="foo" location="${testfile}" relative="true"/> + <au:assertPropertyEquals name="foo" value="${testfile}"/> + </target> + + <target name="testRelativeBase"> + <property name="foo" location="${testfile}" relative="true" basedir="${base}"/> + <au:assertPropertyEquals name="foo" value="${testfile}"/> + </target> + + <target name="testRelativeUnderBase"> + <property name="foo" location="${testfile}" relative="true" basedir="condition"/> + <au:assertPropertyEquals name="foo" value="antversion-test.xml"/> + </target> + + <target name="testRelativeUnderBase2"> + <property name="foo" location="${testfile}" relative="true" basedir="cvs"/> + <au:assertPropertyEquals name="foo" value="..${file.separator}condition${file.separator}antversion-test.xml"/> + </target> + + <target name="testRelativeOverBase"> + <property name="foo" location="${testfile}" relative="true" basedir=".."/> + <au:assertPropertyEquals name="foo" value="taskdefs${file.separator}${testfile}"/> + </target> + + <target name="testNestedExpansionHonorsImmutability"> + <mkdir dir="${input}"/> + <property name="x" value="x"/> + <echo file="${input}/x.properties"><![CDATA[ +x=y +y=$${x} +]]></echo> + <property file="${input}/x.properties"/> + <au:assertPropertyEquals name="y" value="x"/> + <echo file="${input}/y.properties"><![CDATA[ +x=y +y=$${x} +]]></echo> + <property file="${input}/y.properties" prefix="foo"/> + <!-- passes in Ant 1.8.0 and 1.7.1, fails in 1.8.1 --> + <au:assertPropertyEquals name="foo.y" value="x"/> + <echo file="${input}/z.properties"><![CDATA[ +x=y +y=$${bar.x} +]]></echo> + <property file="${input}/z.properties" prefix="bar"/> + <!-- passes in Ant 1.7.1 and 1.8.1, fails in 1.8.0 --> + <!--echo>bar.y is ${bar.y}</echo> + <au:assertLogContains text="bar.y is y"/> + <au:assertPropertyEquals name="bar.y" value="y"/--> + </target> + + <!-- passes in Ant 1.7.1 and 1.8.1, fails in 1.8.0 --> + <target name="testMultiplePrefixes" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=48768"> + <mkdir dir="${input}"/> + <echo file="${input}/x.properties"><![CDATA[ +x=1 +y=2 +]]></echo> + <property file="${input}/x.properties"/> + <au:assertPropertyEquals name="x" value="1"/> + <au:assertPropertyEquals name="y" value="2"/> + <echo file="${input}/y.properties"><![CDATA[ +x=3 +]]></echo> + <property file="${input}/y.properties" prefix="foo"/> + <au:assertPropertyEquals name="foo.x" value="3"/> + </target> + + <!-- passes in Ant 1.7.1 and 1.8.0, fails in 1.8.1 --> + <target name="testNestedExpansionDoesntUsePrefix" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49373"> + <mkdir dir="${input}"/> + <property name="x" value="x"/> + <echo file="${input}/x.properties"><![CDATA[ +x=y +y=$${x} +]]></echo> + <property file="${input}/x.properties" prefix="foo"/> + <au:assertPropertyEquals name="foo.y" value="x"/> + </target> + + <target name="testInternalExpansionWithPrefixOnlyExpandsWhenPrefixValuesIsTrue" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=54769"> + <mkdir dir="${input}"/> + <echo file="${input}/x.properties"><![CDATA[ +a=A +b=$${a} +]]></echo> + <property file="${input}/x.properties" prefix="foo" prefixValues="true"/> + <au:assertPropertyEquals name="foo.b" value="A"/> + <property file="${input}/x.properties" prefix="bar" prefixValues="false"/> + <au:assertPropertyEquals name="bar.b" value="$${a}"/> + <property file="${input}/x.properties" prefix="baz"/> + <au:assertPropertyEquals name="baz.b" value="$${a}"/> + </target> + + <!-- + Problems with @-sign discussed on the mailinglist. + Seems to work. + http://mail-archives.apache.org/mod_mbox/ant-user/201412.mbox/%3CCAPxjwW%2BQKFFj45O-ZbCGOnAkJXe9KJ5qKtVQCvS2x7hObRJmkQ%40mail.gmail.com%3E + --> + <target name="testAtSign"> + <mkdir dir="${input}"/> + <echo file="${input}/x.properties"><![CDATA[ +once=@ +double=@@ +triple=@@@ +]]></echo> + <property file="${input}/x.properties"/> + <au:assertPropertyEquals name="once" value="@"/> + <au:assertPropertyEquals name="double" value="@@"/> + <au:assertPropertyEquals name="triple" value="@@@"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/propertyfile-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/propertyfile-test.xml new file mode 100644 index 00000000..b02cfa4c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/propertyfile-test.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. + --> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <target name="-fileResourceSetup"> + <mkdir dir="${output}"/> + </target> + + <target name="testInternationalText" depends="-fileResourceSetup" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50515"> + <property name="line1" value="è¬ åˆ© 食 å“ æ‰¹ 發 å…¬ å¸" /> + <property name="line2" value="TEL: (123)123-1234" /> + <propertyfile file="${output}/test.properties"> + <entry key="line1" value="${line1}" /> + <entry key="line2" value="${line2}" /> + </propertyfile> + <loadproperties prefix="rereading" srcfile="${output}/test.properties"/> + <au:assertTrue message="${line2}"> + <equals arg1="${line2}" arg2="${rereading.line2}" /> + </au:assertTrue> + <au:assertTrue message="${line1}"> + <equals arg1="${line1}" arg2="${rereading.line1}" /> + </au:assertTrue> + + </target> + +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/propertyhelper-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/propertyhelper-test.xml new file mode 100644 index 00000000..f86342e1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/propertyhelper-test.xml @@ -0,0 +1,151 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <!-- each test verifies that the PropertyEvaluator delegate works --> + <import file="../antunit-base.xml" /> + + <condition property="prereqs-ok"> + <and> + <available classname="org.apache.bsf.BSFManager"/> + <available classname="bsh.util.BeanShellBSFEngine"/> + </and> + </condition> + + <target name="setUp" unless="setup.complete" if="prereqs-ok"> + <script language="beanshell" manager="bsf"> + import org.apache.tools.ant.PropertyHelper; + public class MapEvaluator implements PropertyHelper.PropertyEvaluator { + HashMap map = new HashMap(); + public MapEvaluator() { + map.put("string", "string"); + map.put("object", new Object()); + map.put("int", new Integer(1)); + map.put("null", null); + } + public Object evaluate(String property, PropertyHelper propertyHelper) { + return map.get(property.toLowerCase()); + } + } + project.addReference("mapEvaluator", new MapEvaluator()); + </script> + <propertyhelper> + <delegate refid="mapEvaluator" /> + </propertyhelper> + <property name="setup.complete" value="true" /> + </target> + + <target name="testValueTypes" depends="setUp" if="prereqs-ok"> + <!-- verify BC, strings --> + <au:assertPropertyEquals name="string" value="${STRING}" /> + + <!-- verify non-string properties --> + <au:assertPropertyEquals name="object" value="${OBJECT}" /> + <au:assertPropertyEquals name="int" value="${INT}" /> + + <!-- verify that a string containing nothing but a property reference is a valid value --> + <property name="string2" value="${string}" /> + <au:assertPropertyEquals name="string2" value="${string}" /> + + <property name="object2" value="${object}" /> + <!-- demonstrate that equals args can be non-string --> + <au:assertPropertyEquals name="object2" value="${object}" /> + + <property name="int2" value="${int}" /> + <au:assertPropertyEquals name="int2" value="${int}" /> + </target> + + <target name="testNull" depends="setUp" if="prereqs-ok"> + <!-- demonstrate that a null value always implies a nonexistent property --> + <au:assertFalse> + <isset property="null" /> + </au:assertFalse> + </target> + + <target name="testAvailable" depends="setUp" if="prereqs-ok"> + <!-- verify the available task can set a non-string property --> + <available file="${ant.file}" type="file" property="available.string" value="bc" /> + <au:assertPropertyEquals name="available.string" value="bc" /> + <available file="${ant.file}" type="file" property="available.object" value="${object}" /> + <au:assertPropertyEquals name="available.object" value="${OBJECT}" /> + </target> + + <target name="testCondition" depends="setUp" if="prereqs-ok"> + <!-- verify the condition task can set a non-string property --> + <echo>$${ant.file}=${ant.file}</echo> + <condition property="condition.true.string"> + <available file="${ant.file}" type="file" /> + </condition> + <au:assertPropertyEquals name="condition.true.string" value="true" /> + <condition property="condition.else.string" value="true" else="false"> + <not><available file="${ant.file}" type="file" /></not> + </condition> + <au:assertPropertyEquals name="condition.else.string" value="false" /> + <condition property="condition.true.object" value="${object}"> + <available file="${ant.file}" type="file" /> + </condition> + <au:assertPropertyEquals name="condition.true.object" value="${OBJECT}" /> + <condition property="condition.else.int" value="${object}" else="${int}"> + <not><available file="${ant.file}" type="file" /></not> + </condition> + <au:assertPropertyEquals name="condition.else.int" value="${INT}" /> + </target> + + <target name="testEmbeddedNonString" if="prereqs-ok"> + <!-- verify that a property embedded in a string is a substring --> + <au:assertTrue> + <equals arg1="@${int}@" arg2="@1@" /> + </au:assertTrue> + </target> + + <target name="XtestLoadPropertiesWithObjects" if="prereqs-ok" depends="setUp"> + <au:assertFalse> + <isset property="object2" /> + </au:assertFalse> + <string id="props" value="object2=$${object}" /> + <!-- verify the property is not yet expanded --> + <au:assertTrue> + <length length="17"> + <resource refid="props" /> + </length> + </au:assertTrue> + <loadproperties> + <resource refid="props" /> + </loadproperties> + <au:assertPropertyEquals name="object2" value="${object}" /> + <au:assertPropertyEquals name="object2" value="${OBJECT}" /> + </target> + + <target name="testLoadPropertiesWithStrings" if="prereqs-ok" depends="setUp"> + <au:assertFalse> + <isset property="string2" /> + </au:assertFalse> + <string id="props" value="string2=$${string}" /> + <!-- verify the property is not yet expanded --> + <au:assertTrue> + <length length="17"> + <resource refid="props" /> + </length> + </au:assertTrue> + <loadproperties> + <resource refid="props" /> + </loadproperties> + <au:assertPropertyEquals name="string2" value="${string}" /> + <au:assertPropertyEquals name="string2" value="${STRING}" /> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/replace-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/replace-test.xml new file mode 100644 index 00000000..dd1617a6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/replace-test.xml @@ -0,0 +1,103 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <import file="../propertyhelpers.xml" as="ph"/> + + <target name="tearDown" depends="antunit-base.tearDown"> + <delete dir="foo"/> + </target> + + <target name="setUp"> + <mkdir dir="${output}"/> + <echo file="${output}/text.txt"><![CDATA[ +Hello, world! +]]></echo> + </target> + + <target name="testRCSupport" depends="setUp"> + <replace token="world" value="Ant"> + <file file="${output}/text.txt"/> + </replace> + <au:assertResourceContains + resource="${output}/text.txt" value="Hello, Ant!"/> + </target> + + <target name="testNestedElementsOfFilter" depends="setUp"> + <replace> + <file file="${output}/text.txt"/> + <replacefilter> + <replacetoken>world</replacetoken> + <replacevalue>Ant</replacevalue> + </replacefilter> + </replace> + <au:assertResourceContains + resource="${output}/text.txt" value="Hello, Ant!"/> + </target> + + <target name="testNoPropertyExpansion" depends="setUp"> + <property name="ant" value="Ant"/> + <replace> + <file file="${output}/text.txt"/> + <replacetoken>world</replacetoken> + <replacevalue>${ant}</replacevalue> + </replace> + <au:assertResourceDoesntContain + resource="${output}/text.txt" value="Hello, Ant!"/> + </target> + + <target name="testPropertyExpansion" depends="setUp"> + <property name="ant" value="Ant"/> + <replace> + <file file="${output}/text.txt"/> + <replacetoken>world</replacetoken> + <replacevalue expandproperties="true">${ant}</replacevalue> + </replace> + <au:assertResourceContains + resource="${output}/text.txt" value="Hello, Ant!"/> + </target> + + <target name="testNoReplace" depends="setUp"> + <replace token="ant" value="ant" summary="true"> + <file file="${output}/text.txt"/> + </replace> + <au:assertLogContains text="Replaced 0 occurrences in 0 files."/> + </target> + + <target name="testFailOnNoReplace" depends="setUp"> + <au:expectfailure expectedMessage="didn't replace anything"> + <replace token="ant" value="ant" failOnNoReplacements="true"> + <file file="${output}/text.txt"/> + </replace> + </au:expectfailure> + </target> + + <target name="testPropertyFilterResource" depends="setUp,ph.defineHelpers"> + <mkdir dir="foo"/> + <echo file="foo/foo.properties"><![CDATA[ +world=Ant +]]></echo> + <replace replacefilterresource="${java:foo!foo.properties}"> + <file file="${output}/text.txt"/> + </replace> + <au:assertResourceContains + resource="${output}/text.txt" value="Hello, Ant!"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/retry-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/retry-test.xml new file mode 100644 index 00000000..e81853b8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/retry-test.xml @@ -0,0 +1,45 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="retry-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml"/> + + <target name="setUp"> + <property name="i" value="3"/> + <mkdir dir="${output}"/> + <property name="dest" value="${output}/dest"/> + </target> + + <target name="test-fail-and-retry" depends="setUp"> + <!-- just in case this ever becomes a legit url... --> + <property name="src" value="http://iojasodjojaosdj"/> + <au:expectfailure expectedmessage="Task [get] failed after [${i}] attempts; giving up"> + <retry retrycount="${i}"> + <get src="${src}" dest="${dest}"/> + </retry> + </au:expectfailure> + <au:assertLogContains text="Attempt [1]: error occurred; retrying..."/> + </target> + + <target name="test-success" depends="setUp"> + <retry retrycount="${i}"> + <touch file="${dest}"/> + </retry> + <au:assertLogDoesntContain text="Attempt [1]: error occurred; retrying..."/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/rmic-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/rmic-test.xml new file mode 100644 index 00000000..67b4afc3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/rmic-test.xml @@ -0,0 +1,105 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="-create-rmic-adapter"> + <mkdir dir="${input}/org/example"/> + <echo file="${input}/org/example/Adapter.java"><![CDATA[ +package org.example; +import org.apache.tools.ant.taskdefs.rmic.RmicAdapter; +import org.apache.tools.ant.taskdefs.Rmic; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.FileNameMapper; +import org.apache.tools.ant.util.GlobPatternMapper; + +public class Adapter implements RmicAdapter { + public void setRmic(Rmic attributes) {} + public boolean execute() { + System.err.println("adapter called"); + return true; + } + public FileNameMapper getMapper() { + GlobPatternMapper m = new GlobPatternMapper(); + m.setFrom("*.class"); + m.setTo("*_foo.class"); + return m; + } + + public Path getClasspath() { + return new Path(null); + } +}]]></echo> + <mkdir dir="${resources}"/> + <javac srcdir="${input}" destdir="${resources}"/> + </target> + + <target name="testCompilerNotFound" depends="-create-rmic-adapter" unless="build.sysclasspath.only"> + <au:expectfailure> + <rmic base="${resources}" includes="**/*.class" + compiler="org.example.Adapter"/> + </au:expectfailure> + <au:assertLogDoesntContain text="adapter called"/> + </target> + + <target name="testCompilerClasspath" depends="-create-rmic-adapter" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=11143"> + <rmic base="${resources}" includes="**/*.class" + compiler="org.example.Adapter"> + <compilerclasspath location="${resources}"/> + </rmic> + <au:assertLogContains text="adapter called"/> + </target> + + <target name="testCompilerAsNestedElement" depends="-create-rmic-adapter"> + <componentdef classname="org.example.Adapter" name="myjavac"> + <classpath location="${resources}"/> + </componentdef> + <rmic base="${resources}" includes="**/*.class"> + <myjavac/> + </rmic> + <au:assertLogContains text="adapter called"/> + </target> + + <target name="testSourceBase" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=48970"> + <mkdir dir="${input}/org/example"/> + <mkdir dir="${output}"/> + <echo file="${input}/org/example/Foo.java"><![CDATA[ +package org.example; +import java.rmi.Remote; +import java.rmi.RemoteException; +public interface Foo extends Remote { + long bar() throws RemoteException ; +}]]></echo> + <echo file="${input}/org/example/FooImpl.java"><![CDATA[ +package org.example; +import java.rmi.RemoteException; +public class FooImpl implements Foo { + public long bar() throws RemoteException { + return 0; + } +}]]></echo> + <javac srcdir="${input}" destdir="${output}"/> + <rmic sourcebase="${input}" base="${output}"> + <include name="**/*Impl.class"/> + </rmic> + <au:assertFileExists file="${input}/org/example/FooImpl_Stub.java"/> + <au:assertFileDoesntExist file="${output}/org/example/FooImpl_Stub.java"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/secure-input.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/secure-input.xml new file mode 100644 index 00000000..8311ce9c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/secure-input.xml @@ -0,0 +1,32 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="test-input" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <target name="setUp"> + </target> + + <target name="test-secure-input" if="jdk1.6+"> + <input message="secure-input:>" addproperty="the.password"> + <handler classname="org.apache.tools.ant.input.SecureInputHandler" /> + </input> + <au:assertPropertySet name="the.password" /> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/signjar-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/signjar-test.xml new file mode 100644 index 00000000..0f03bc58 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/signjar-test.xml @@ -0,0 +1,272 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <property name="classes.dir" value="../../../../build/classes" /> + <property name="sign.dir" location="${output}" /> + <property name="subdir" location="${sign.dir}/subdir" /> + <property name="signtest.jar" location="${sign.dir}/signtest.jar" /> + <property name="subdirsigntest.jar" location="${subdir}/signtest.jar" /> + <property name="testkeystore" location="../../../etc/testcases/testkeystore" /> + + <macrodef name="assertSigned"> + <attribute name="jar" default="${signtest.jar}" /> + <sequential> + <au:assertTrue message="not signed: @{jar}"> + <issigned file="@{jar}" /> + </au:assertTrue> + </sequential> + </macrodef> + + <presetdef name="sign-base"> + <signjar alias="testonly" keystore="${testkeystore}" storepass="apacheant" /> + </presetdef> + + <presetdef name="verify-base"> + <verifyjar keystore="${testkeystore}" storepass="apacheant" /> + </presetdef> + + <presetdef name="sign"> + <sign-base jar="${signtest.jar}" /> + </presetdef> + + <target name="setUp"> + <mkdir dir="${sign.dir}" /> + <mkdir dir="${subdir}" /> + </target> + + <target name="jar" depends="setUp"> + <jar jarfile="${signtest.jar}" basedir="${classes.dir}" includes="**/Task.class" /> + </target> + + <target name="basic" depends="jar"> + <sign /> + </target> + + <target name="testBasic" depends="basic"> + <assertSigned /> + </target> + + <target name="testMaxmemory" depends="jar"> + <sign maxmemory="128m" /> + <assertSigned /> + </target> + + <target name="testPreserveLastModified" depends="jar"> + <touch file="${signtest.jar}" datetime="06/28/2000 2:02 pm" /> + <sign preservelastmodified="true" /> + <assertSigned /> + <fail message="preserveLastModified did not preserve the last modified time"> + <condition> + <not> + <isfileselected file="${signtest.jar}"> + <date datetime="06/28/2000 2:02 pm" when="equal" /> + </isfileselected> + </not> + </condition> + </fail> + </target> + + <target name="testFileset" depends="jar"> + <sign-base> + <fileset file="${signtest.jar}" /> + </sign-base> + <assertSigned /> + </target> + + <target name="testFilesetAndJar" depends="jar"> + <sign-base jar="${signtest.jar}" lazy="true"> + <fileset file="${signtest.jar}" /> + </sign-base> + <assertSigned /> + </target> + + <target name="testFilesetAndSignedJar" depends="jar"> + <au:expectfailure expectedMessage="You cannot specify the signed JAR when using paths or filesets"> + <sign-base signedjar="${sign.dir}/newfile.jar"> + <fileset file="${signtest.jar}" /> + </sign-base> + </au:expectfailure> + </target> + + <target name="testPath" depends="jar"> + <sign-base> + <path> + <fileset file="${signtest.jar}" /> + </path> + </sign-base> + <assertSigned /> + </target> + + <target name="testPathAndJar" depends="jar"> + <sign-base jar="${signtest.jar}" lazy="true"> + <path> + <fileset file="${signtest.jar}" /> + </path> + </sign-base> + <assertSigned /> + </target> + + <target name="testPathAndSignedJar" depends="jar"> + <au:expectfailure expectedMessage="You cannot specify the signed JAR when using paths or filesets"> + <sign-base signedjar="${sign.dir}/newfile.jar"> + <path> + <fileset file="${signtest.jar}" /> + </path> + </sign-base> + </au:expectfailure> + </target> + + <target name="testSignedJar" depends="jar"> + <sign signedjar="${subdirsigntest.jar}" /> + <assertSigned jar="${subdirsigntest.jar}" /> + </target> + + <target name="testDestDirAndSignedJar" depends="jar"> + <au:expectfailure expectedMessage="'destdir' and 'signedjar' cannot both be set"> + <sign destDir="${subdir}" signedjar="${sign.dir}/newfile.jar" /> + </au:expectfailure> + </target> + + <target name="testDestDir" depends="jar"> + <sign destDir="${subdir}" /> + <assertSigned jar="${subdirsigntest.jar}" /> + </target> + + <target name="testDestDirFileset" depends="jar"> + <sign-base destDir="${subdir}"> + <fileset file="${signtest.jar}" /> + </sign-base> + <assertSigned jar="${subdirsigntest.jar}" /> + </target> + + <target name="testDestDirPath" depends="jar"> + <sign-base destDir="${subdir}"> + <path> + <fileset file="${signtest.jar}" /> + </path> + </sign-base> + <assertSigned jar="${subdirsigntest.jar}" /> + </target> + + <target name="testMapperNoDest" depends="jar"> + <au:expectfailure expectedMessage="The destDir attribute is required if a mapper is set"> + <sign-base> + <flattenmapper /> + <fileset file="${signtest.jar}" /> + </sign-base> + </au:expectfailure> + </target> + + <target name="testMapperFileset" depends="jar"> + <sign-base destDir="${subdir}"> + <fileset file="${signtest.jar}" /> + <flattenmapper /> + </sign-base> + <assertSigned jar="${subdirsigntest.jar}" /> + </target> + + <target name="testMapperPath" depends="jar"> + <sign-base destDir="${subdir}"> + <path> + <pathelement location="${signtest.jar}" /> + </path> + <flattenmapper /> + </sign-base> + <assertSigned jar="${subdirsigntest.jar}" /> + </target> + + <target name="testTwoMappers" depends="jar"> + <au:expectfailure expectedMessage="Too many mappers"> + <sign-base destDir="${subdir}"> + <fileset file="${signtest.jar}" /> + <flattenmapper /> + <flattenmapper /> + </sign-base> + </au:expectfailure> + </target> + + <target name="testNoAlias" depends="jar"> + <au:expectfailure expectedMessage="alias attribute must be set"> + <signjar keystore="${testkeystore}" jar="${signtest.jar}" storepass="apacheant" /> + </au:expectfailure> + </target> + + <target name="testNoFiles"> + <au:expectfailure expectedMessage="jar must be set through jar attribute"> + <sign-base /> + </au:expectfailure> + </target> + + <target name="testNoStorePass" depends="jar"> + <au:expectfailure expectedMessage="storepass attribute must be set"> + <signjar keystore="${testkeystore}" alias="testonly" jar="${signtest.jar}" /> + </au:expectfailure> + </target> + + <target name="testSysProperty" depends="jar"> + <sign> + <sysproperty key="ant.home" value="${ant.home}" /> + </sign> + <assertSigned /> + </target> + + <target name="testVerifyJar" depends="basic"> + <verify-base jar="${signtest.jar}" /> + </target> + + <target name="testVerifyJarCertificates" depends="basic"> + <verify-base jar="${signtest.jar}" certificates="true" verbose="true" /> + </target> + + <target name="testVerifyJarUnsigned" depends="jar"> + <au:expectfailure expectedMessage="Failed to verify ${signtest.jar}"> + <verify-base jar="${signtest.jar}" /> + </au:expectfailure> + </target> + + <target name="NOtestVerifyJarNotInKeystore" depends="basic"> + <au:expectfailure> + <verifyjar jar="${signtest.jar}" certificates="true" verbose="true" /> + </au:expectfailure> + </target> + + <target name="testVerifyFileset" depends="basic"> + <verify-base> + <fileset file="${signtest.jar}" /> + </verify-base> + </target> + + <target name="testVerifyPath" depends="basic"> + <verify-base> + <path> + <pathelement location="${signtest.jar}" /> + </path> + </verify-base> + </target> + + <target name="testVerifyNoArgs"> + <au:expectfailure expectedMessage="jar must be set through jar attribute"> + <verify-base /> + </au:expectfailure> + </target> + +</project> + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/subant-helper/echo.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/subant-helper/echo.xml new file mode 100644 index 00000000..24f445cc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/subant-helper/echo.xml @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit"> + <au:assertMatches string="${basedir}" pattern=".*subant-helper$"/> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/subant-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/subant-test.xml new file mode 100644 index 00000000..3bc44059 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/subant-test.xml @@ -0,0 +1,111 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <description> + Test that subant properly sets various properties + </description> + <import file="../antunit-base.xml" /> + + <target name="assertProperties"> + <au:assertPropertySet name="ant.version" /> + <au:assertPropertySet name="java.home" /> + <au:assertPropertySet name="java.class.path" /> + </target> + + <target name="testAntVersion"> + <subant inheritall="false" target="assertProperties"> + <fileset file="${ant.file}" /> + </subant> + </target> + + <!-- four testcases for bug 30542, the last one failed --> + <target name="testSubAntDoesntSetBasedir"> + <subant antfile="echo.xml"> + <dirset dir="." includes="subant-helper"/> + </subant> + </target> + + <target name="testSubAntDoesntSetBasedirAfterAntCall"> + <antcall target="testSubAntDoesntSetBasedir"/> + </target> + + <target name="testSubAntDoesntSetBasedirAfterAnt"> + <ant antfile="${ant.file}" target="testSubAntDoesntSetBasedir"/> + </target> + + <target name="testSubAntDoesntSetBasedirAfterAntWithDir"> + <ant antfile="${ant.file}" dir="${basedir}" + target="testSubAntDoesntSetBasedir"/> + </target> + + <target name="testSubAntDoesntSetBasedirAfterAntWithDirWhenNativeDir"> + <ant antfile="${ant.file}" dir="${basedir}" + target="testSubAntDoesntSetBasedir" + useNativeBaseDir="true"/> + </target> + + <target name="testLastPropertyWins"> + <subant target="checkB"> + <file file="antcall-test.xml"/> + <property name="b" value="1"/> + <property name="b" value="2"/> + <property name="expected" value="2"/> + </subant> + </target> + + <target name="makePropertiesFile"> + <ant antfile="antcall-test.xml" target="makePropertiesFile"/> + </target> + + <target name="testPropertiesLoadedFromFile" depends="makePropertiesFile"> + <subant target="checkB"> + <file file="antcall-test.xml"/> + <property name="expected" value="2"/> + <property file="${input}/ant.properties"/> + </subant> + </target> + + <target name="testFileDoesntSeeExternalProperty" depends="makePropertiesFile"> + <property name="a" value="x"/> + <subant target="checkB"> + <file file="antcall-test.xml"/> + <property name="expected" value="2"/> + <property file="${input}/ant.properties"/> + </subant> + </target> + + <target name="testFileSeesExternalPropertyWhenInheritAll" + depends="makePropertiesFile"> + <property name="a" value="x"/> + <subant target="checkB" inheritall="true"> + <file file="antcall-test.xml"/> + <property name="expected" value="x"/> + <property file="${input}/ant.properties"/> + </subant> + </target> + + <target name="testFileSeesInternalProperty" depends="makePropertiesFile"> + <subant target="checkB"> + <file file="antcall-test.xml"/> + <property name="a" value="y"/> + <property name="expected" value="y"/> + <property file="${input}/ant.properties"/> + </subant> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/sync-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/sync-test.xml new file mode 100644 index 00000000..21a14426 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/sync-test.xml @@ -0,0 +1,175 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}/a"/> + <mkdir dir="${input}/d"/> + <mkdir dir="${output}/a"/> + <mkdir dir="${output}/d"/> + <mkdir dir="${output}/b/c"/> + <touch file="${input}/a/foo.txt"/> + <touch file="${output}/a/bar.txt"/> + <touch file="${output}/b/baz.txt"/> + </target> + + <target name="testIncludeEmptyPreservesEmptyDirs" depends="setUp"> + + <sync todir="${output}" includeemptydirs="true"> + <fileset dir="${input}"/> + <preserveintarget> + <include name="**/b/**"/> + </preserveintarget> + </sync> + + <au:assertFileDoesntExist file="${output}/a/bar.txt"/> + <au:assertFileExists file="${output}/a/foo.txt"/> + <au:assertFileExists file="${output}/b/baz.txt"/> + <au:assertFileExists file="${output}/b/c"/> + <au:assertFileExists file="${output}/d"/> + </target> + + <target name="testDefaultDoesntPreserveEmptyDirs" depends="setUp"> + + <sync todir="${output}"> + <fileset dir="${input}"/> + <preserveintarget> + <include name="**/b/**"/> + </preserveintarget> + </sync> + + <au:assertFileDoesntExist file="${output}/a/bar.txt"/> + <au:assertFileExists file="${output}/a/foo.txt"/> + <au:assertFileExists file="${output}/b/baz.txt"/> + <au:assertFileDoesntExist file="${output}/b/c"/> + <au:assertFileDoesntExist file="${output}/d"/> + </target> + + <target name="testPreserveEmptyOverridesDefault" depends="setUp"> + + <sync todir="${output}"> + <fileset dir="${input}"/> + <preserveintarget preserveEmptyDirs="true"> + <include name="**/b/**"/> + </preserveintarget> + </sync> + + <au:assertFileDoesntExist file="${output}/a/bar.txt"/> + <au:assertFileExists file="${output}/a/foo.txt"/> + <au:assertFileExists file="${output}/b/baz.txt"/> + <au:assertFileExists file="${output}/b/c"/> + <au:assertFileDoesntExist file="${output}/d"/> + </target> + + <target name="testPreserveEmptyOverrulesIncludeEmpty" depends="setUp"> + + <sync todir="${output}" includeEmptyDirs="true"> + <fileset dir="${input}"/> + <preserveintarget preserveEmptyDirs="false"> + <include name="**/b/**"/> + </preserveintarget> + </sync> + + <au:assertFileDoesntExist file="${output}/a/bar.txt"/> + <au:assertFileExists file="${output}/a/foo.txt"/> + <au:assertFileExists file="${output}/b/baz.txt"/> + <au:assertFileDoesntExist file="${output}/b/c"/> + <au:assertFileExists file="${output}/d"/> + </target> + + <target name="testPreserveEmptyAndIncludeEmptyFalse" depends="setUp"> + + <sync todir="${output}" includeEmptyDirs="false"> + <fileset dir="${input}"/> + <preserveintarget preserveEmptyDirs="false"> + <include name="**/b/**"/> + </preserveintarget> + </sync> + + <au:assertFileDoesntExist file="${output}/a/bar.txt"/> + <au:assertFileExists file="${output}/a/foo.txt"/> + <au:assertFileExists file="${output}/b/baz.txt"/> + <au:assertFileDoesntExist file="${output}/b/c"/> + <au:assertFileDoesntExist file="${output}/d"/> + </target> + + <target name="testPreserveEmptyAndIncludeEmptyTrue" depends="setUp"> + + <sync todir="${output}" includeEmptyDirs="true"> + <fileset dir="${input}"/> + <preserveintarget preserveEmptyDirs="true"> + <include name="**/b/**"/> + </preserveintarget> + </sync> + + <au:assertFileDoesntExist file="${output}/a/bar.txt"/> + <au:assertFileExists file="${output}/a/foo.txt"/> + <au:assertFileExists file="${output}/b/baz.txt"/> + <au:assertFileExists file="${output}/b/c"/> + <au:assertFileExists file="${output}/d"/> + </target> + + <target name="testPreserveEmptyDirsWithNonRecursiveExclude" depends="setUp"> + + <sync todir="${output}"> + <fileset dir="${input}"/> + <preserveintarget preserveEmptyDirs="true"> + <include name="**/b"/> + </preserveintarget> + </sync> + + <au:assertFileDoesntExist file="${output}/a/bar.txt"/> + <au:assertFileExists file="${output}/a/foo.txt"/> + <au:assertFileExists file="${output}/b"/> + <au:assertFileDoesntExist file="${output}/b/baz.txt"/> + <au:assertFileDoesntExist file="${output}/b/c"/> + <au:assertFileDoesntExist file="${output}/d"/> + </target> + + <!-- really only tests no exception is thrown --> + <target name="testCanAddMultipleResources" depends="setUp" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=51462"> + <sync todir="${output}"> + <file file="${input}/x"/> + <file file="${input}/y"/> + </sync> + </target> + + <target name="testSyncWithResources" depends="setUp" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=51462"> + <sync todir="${output}"> + <mappedresources> + <fileset dir="${input}"/> + <globmapper from="*" to="test/*"/> + </mappedresources> + </sync> + <au:assertFileDoesntExist file="${output}/bar.txt"/> + <au:assertFileExists file="${output}/test/a/foo.txt"/> + + <sync todir="${output}"> + <mappedresources> + <fileset dir="${input}"/> + <globmapper from="*" to="test/*"/> + </mappedresources> + </sync> + <au:assertFileDoesntExist file="${output}/bar.txt"/> + <au:assertFileExists file="${output}/test/a/foo.txt"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/tar-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/tar-test.xml new file mode 100644 index 00000000..1aac9a8d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/tar-test.xml @@ -0,0 +1,118 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<project name="tar-test" default="antunit" + xmlns:cond="antlib:org.apache.tools.ant.types.conditions" + xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}" /> + <mkdir dir="${output}" /> + </target> + + <target name="testTarFilesetHandlesFilesetReferences" depends="setUp"> + <fileset id="xml.fileset" dir="." includes="*.xml" /> + <tar destfile="${output}/testtar.tar"> + <tarfileset prefix="pre" refid="xml.fileset" /> + </tar> + </target> + + <target name="testRemoveLeadingSlashes" depends="setUp"> + <tar destfile="${output}/testtar.tar"> + <tarfileset file="${ant.file}" fullpath="/foo.xml"/> + </tar> + <au:assertTrue> + <cond:resourceexists> + <tarentry name="foo.xml"> + <file file="${output}/testtar.tar"/> + </tarentry> + </cond:resourceexists> + </au:assertTrue> + <au:assertFalse> + <cond:resourceexists> + <tarentry name="/foo.xml"> + <file file="${output}/testtar.tar"/> + </tarentry> + </cond:resourceexists> + </au:assertFalse> + </target> + + <target name="testPreserveLeadingSlashes" depends="setUp"> + <tar destfile="${output}/testtar.tar"> + <tarfileset file="${ant.file}" fullpath="/foo.xml" + preserveleadingslashes="true"/> + </tar> + <au:assertTrue> + <cond:resourceexists> + <tarentry name="/foo.xml"> + <file file="${output}/testtar.tar"/> + </tarentry> + </cond:resourceexists> + </au:assertTrue> + <au:assertFalse> + <cond:resourceexists> + <tarentry name="foo.xml"> + <file file="${output}/testtar.tar"/> + </tarentry> + </cond:resourceexists> + </au:assertFalse> + </target> + + <target name="testSingleFile" depends="setUp" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=48035"> + <touch file="${input}/foo.txt"/> + <tar destfile="${output}/foo.tar"> + <file file="${input}/foo.txt"/> + </tar> + <au:assertFileExists file="${output}/foo.tar"/> + <copy file="${output}/foo.tar" tofile="${output}/bar.tar" + preservelastmodified="true"/> + <sleep seconds="2"/> + <touch file="${input}/foo.txt"/> + <tar destfile="${output}/foo.tar"> + <file file="${input}/foo.txt"/> + </tar> + <au:assertDestIsOutofdate src="${output}/foo.tar" dest="${output}/bar.tar"/> + </target> + + <target name="-longfileSetup" depends="setUp"> + <property name="longfile.dir.name" + value="this/path/name/contains/more/than/one/hundred/characters/in/order/to/test/the/GNU/and/POSIX/long/file/name/capability/round"/> + <property name="longfile.file.name" + value="${longfile.dir.name}/tripped"/> + <mkdir dir="${input}/${longfile.dir.name}"/> + <touch file="${input}/${longfile.file.name}"/> + </target> + + <target name="testLongfileGNU" depends="-longfileSetup"> + <tar destfile="${output}/x.tar" longfile="gnu"> + <fileset dir="${input}"/> + </tar> + <untar dest="${output}" src="${output}/x.tar"/> + <au:assertFileExists file="${output}/${longfile.file.name}"/> + </target> + + <target name="testLongfilePOSIX" depends="-longfileSetup"> + <tar destfile="${output}/x.tar" longfile="posix"> + <fileset dir="${input}"/> + </tar> + <untar dest="${output}" src="${output}/x.tar"/> + <au:assertFileExists file="${output}/${longfile.file.name}"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/taskdef-antlib-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/taskdef-antlib-test.xml new file mode 100644 index 00000000..58d01f06 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/taskdef-antlib-test.xml @@ -0,0 +1,64 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <!-- Java5 has some trouble with the recursive Antlib lookup --> + + <target name="setUp" if="jdk1.6+"> + <mkdir dir="${input}/org/example" /> + <property name="tmpdir" location="../../../../build/ant-unit/taskdef" /> + <mkdir dir="${tmpdir}" /> + <echo file="${input}/org/example/antlib.xml"> + <![CDATA[<antlib xmlns:e="ant:current"> + <macrodef name="echoo" backtrace="false"> + <attribute name="message" /> + <sequential> + <echo message="@{message}@{message}" /> + </sequential> + </macrodef> + <macrodef name="echoooo" backtrace="false"> + <attribute name="message" /> + <sequential> + <e:echoo message="@{message}@{message}" /> + </sequential> + </macrodef> + </antlib>]]> + </echo> + <jar destfile="${test.jar}"> + <fileset dir="${input}" /> + </jar> + <sleep seconds="1"/> + </target> + + <target name="testAntlib" depends="setUp" if="jdk1.6+"> + <taskdef classpath="${test.jar}" uri="antlib:org.example" + loaderref="loader1"/> + <echoooo xmlns="antlib:org.example" message="exemple" /> + <au:assertLogContains text="exempleexempleexempleexemple" /> + </target> + + <target name="testURI" depends="setUp" if="jdk1.6+"> + <taskdef classpath="${test.jar}" uri="urn:my:exemple" + loaderref="loader2" + resource="org/example/antlib.xml" /> + <echoooo xmlns="urn:my:exemple" message="exemple" /> + <au:assertLogContains text="exempleexempleexempleexemple" /> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/taskdef-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/taskdef-test.xml new file mode 100644 index 00000000..95745082 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/taskdef-test.xml @@ -0,0 +1,99 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}/org/example"/> + <property name="tmpdir" location="../../../../build/ant-unit/taskdef"/> + <mkdir dir="${tmpdir}"/> + <echoxml file="${input}/org/example/antlib.xml"> + <antlib> + <taskdef name="echooo" + classname="org.apache.tools.ant.taskdefs.Echo"/> + </antlib> + </echoxml> + </target> + + <target name="testPlainDir" depends="setUp"> + <jar destfile="${test1.jar}"> + <fileset dir="${input}"/> + </jar> + <taskdef resource="org/example/antlib.xml" + classpath="${test1.jar}" + uri="urn:test:plain"/> + <echooo xmlns="urn:test:plain">Hello</echooo> + <au:assertLogContains text="Hello"/> + </target> + + <target name="testDirWithPling" depends="setUp" if="jdk1.6+" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50007"> + <property name="dir" location="${tmpdir}/pl!ng"/> + <mkdir dir="${dir}"/> + <jar destfile="${test2.jar}"> + <fileset dir="${input}"/> + </jar> + <taskdef resource="org/example/antlib.xml" + classpath="${test2.jar}" + uri="urn:test:indir"/> + <echooo xmlns="urn:test:indir">Hello</echooo> + <au:assertLogContains text="Hello"/> + </target> + + <!-- fails because URLConnection.connect() fails on the JAR URL returned + by ClassLoader.getResources() --> + <target name="NOtestDirWithPlingAtEnd" depends="setUp" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50007"> + <property name="dir" location="${tmpdir}/pling!"/> + <mkdir dir="${dir}"/> + <jar destfile="${test3.jar}"> + <fileset dir="${input}"/> + </jar> + <taskdef resource="org/example/antlib.xml" + classpath="${test3.jar}" + uri="urn:test:atend"/> + <echooo xmlns="urn:test:atend">Hello</echooo> + <au:assertLogContains text="Hello"/> + </target> + + <target name="testPlingInJar" depends="setUp"> + <move file="${input}/org/example/antlib.xml" + tofile="${input}/org/examp!e/antlib.xml"/> + <jar destfile="${test4.jar}"> + <fileset dir="${input}"/> + </jar> + <taskdef resource="org/examp!e/antlib.xml" + classpath="${test4.jar}" + uri="urn:test:injar"/> + <echooo xmlns="urn:test:injar">Hello</echooo> + <au:assertLogContains text="Hello"/> + </target> + + <target name="testPlingInJarAtEnd" depends="setUp"> + <move file="${input}/org/example/antlib.xml" + tofile="${input}/org/example!/antlib.xml"/> + <jar destfile="${test5.jar}"> + <fileset dir="${input}"/> + </jar> + <taskdef resource="org/example!/antlib.xml" + classpath="${test5.jar}" + uri="urn:test:injaratend"/> + <echooo xmlns="urn:test:injaratend">Hello</echooo> + <au:assertLogContains text="Hello"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/tempfile-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/tempfile-test.xml new file mode 100644 index 00000000..1132007a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/tempfile-test.xml @@ -0,0 +1,30 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="tearDown" depends="antunit-base.tearDown"> + <delete file="${tmp}" quiet="true"/> + </target> + + <target name="testCreateWithoutPrefix" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49755"> + <tempfile property="tmp" createfile="true"/> + <au:assertFileExists file="${tmp}"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/touch-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/touch-test.xml new file mode 100644 index 00000000..a9327ed8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/touch-test.xml @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="touch-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml"/> + + <target name="test-no-child"> + <au:expectfailure> + <touch /> + </au:expectfailure> + </target> + + <target name="test-no-match"> + <touch> + <fileset file="${ant.file}"> + <filename name="IDONOTMATCH" /> + </fileset> + </touch> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/truncate/truncate-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/truncate/truncate-test.xml new file mode 100644 index 00000000..86f896c6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/truncate/truncate-test.xml @@ -0,0 +1,145 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="truncate-test" default="default" + xmlns:au="antlib:org.apache.ant.antunit"> + + <target name="default"> + <au:antunit> + <file file="${ant.file}" /> + </au:antunit> + </target> + + <target name="tearDown"> + <delete file="foo" /> + <delete file="bar" /> + <delete dir="baz" /> + </target> + + <target name="test-basic"> + <truncate file="foo" /> + <au:assertTrue> + <length file="foo" length="0" /> + </au:assertTrue> + </target> + + <target name="test-explicit"> + <truncate file="foo" length="1034" /> + <au:assertTrue> + <length file="foo" length="1034" /> + </au:assertTrue> + </target> + + <target name="test-extend"> + <truncate file="foo" length="5" /> + <au:assertTrue> + <length file="foo" length="5" /> + </au:assertTrue> + <truncate file="foo" adjust="5" /> + <au:assertTrue> + <length file="foo" length="10" /> + </au:assertTrue> + </target> + + <target name="test-truncate"> + <truncate file="foo" length="5" /> + <au:assertTrue> + <length file="foo" length="5" /> + </au:assertTrue> + <truncate file="foo" adjust="-5" /> + <au:assertTrue> + <length file="foo" length="0" /> + </au:assertTrue> + </target> + + <target name="test-bigger"> + <truncate file="foo" length="1K" /> + <au:assertTrue> + <and> + <length file="foo" length="1K" /> + <length file="foo" length="1024" /> + </and> + </au:assertTrue> + </target> + + <target name="truncate-bigger"> + <truncate file="foo" length="3K" /> + <au:assertTrue> + <length file="foo" length="3K" /> + </au:assertTrue> + <truncate file="foo" adjust="-2K" /> + <au:assertTrue> + <length file="foo" length="1K" /> + </au:assertTrue> + </target> + + <target name="test-no-create"> + <au:assertFileDoesntExist file="foo" /> + <truncate file="foo" create="false" length="0" /> + <au:assertFileDoesntExist file="foo" /> + </target> + + <target name="test-mkdirs"> + <au:assertFileDoesntExist file="baz" /> + <truncate file="baz/foo" mkdirs="true" length="0" /> + <au:assertTrue> + <length file="baz/foo" length="0" /> + </au:assertTrue> + </target> + + <target name="test-rc"> + <truncate length="10"> + <resources> + <file file="foo" /> + <file file="bar" /> + </resources> + </truncate> + <au:assertTrue> + <and> + <length file="foo" length="10" /> + <length file="bar" length="10" /> + </and> + </au:assertTrue> + </target> + + <target name="test-bad-resource"> + <au:expectfailure> + <truncate length="1P"> + <string value="blah" /> + </truncate> + </au:expectfailure> + </target> + + <target name="test-invalid-attrs"> + <au:expectfailure> + <truncate file="foo" length="0" adjust="0" /> + </au:expectfailure> + </target> + + <target name="test-bad-length"> + <au:expectfailure> + <truncate file="foo" length="-1P" /> + </au:expectfailure> + </target> + + <target name="test-no-files"> + <au:expectfailure> + <truncate length="0" /> + </au:expectfailure> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/unzip-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/unzip-test.xml new file mode 100644 index 00000000..b2c2105d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/unzip-test.xml @@ -0,0 +1,70 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<project name="unzip-test" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${output}" /> + </target> + + <target name="testFailureOnBrokenCentralDirectoryStructure"> + <au:expectfailure + expectedmessage="central directory is empty, can't expand corrupt archive."> + <unzip src="broken_cd.zip" dest="${output}"/> + </au:expectfailure> + </target> + + <!-- Issue 28911 --> + <target name="testStrippingOfPathsep"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <touch file="${input}/file"/> + <zip destfile="${output}/a.zip"> + <zipfileset dir="${input}" prefix="/foo"/> + </zip> + <unzip src="${output}/a.zip" stripAbsolutePathSpec="true" + dest="${output}"/> + <au:assertFileExists file="${output}/foo/file"/> + </target> + + <target name="testTwoByteExtraFieldInLFH" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=42940" + > + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <copy file="zip/Bugzilla-42940.zip" tofile="${input}/test.zip"/> + <unzip src="${input}/test.zip" dest="${output}"/> + <au:assertFileExists file="${output}/META-INF/MANIFEST.MF"/> + </target> + + <target name="testArchiveIsClosedForInvalidZips" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=46559" + > + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <copy file="broken_cd.zip" tofile="${input}/test.zip"/> + <au:expectfailure> + <unzip src="${input}/test.zip" dest="${output}"/> + </au:expectfailure> + <delete file="${input}/test.zip" quiet="true"/> + <!-- failed on Windows and other OSes with implicit file locking --> + <au:assertFileDoesntExist file="${input}/test.zip"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/uptodate-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/uptodate-test.xml new file mode 100644 index 00000000..e477803e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/uptodate-test.xml @@ -0,0 +1,86 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="testModifiedDirectories" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=39122 + and + https://issues.apache.org/bugzilla/show_bug.cgi?id=44430"> + <mkdir dir="${input}/source"/> + <mkdir dir="${output}"/> + <sleep seconds="2"/> + <touch file="${input}/source/file"/> + <au:assertFalse> + <uptodate> + <srcresources> + <fileset dir="${input}"/> + <dirset dir="${input}"/> + </srcresources> + <globmapper from="*" to="${output}/*"/> + </uptodate> + </au:assertFalse> + <mkdir dir="${output}/source"/> + <touch file="${output}/source/file"/> + <au:assertTrue> + <uptodate targetfile="${output}"> + <srcresources> + <fileset dir="${input}"/> + <dirset dir="${input}"/> + </srcresources> + <globmapper from="*" to="${output}/*"/> + </uptodate> + </au:assertTrue> + <sleep seconds="2"/> + <touch> + <file file="${input}/source"/> + </touch> + <au:assertFalse> + <uptodate targetfile="${output}"> + <srcresources> + <fileset dir="${input}"/> + <dirset dir="${input}"/> + </srcresources> + <globmapper from="*" to="${output}/*"/> + </uptodate> + </au:assertFalse> + <touch> + <file file="${output}/source"/> + </touch> + <au:assertTrue> + <uptodate targetfile="${output}"> + <srcresources> + <fileset dir="${input}"/> + <dirset dir="${input}"/> + </srcresources> + <globmapper from="*" to="${output}/*"/> + </uptodate> + </au:assertTrue> + <sleep seconds="2"/> + <delete file="${input}/source/file"/> + <au:assertFalse> + <uptodate targetfile="${output}"> + <srcresources> + <fileset dir="${input}"/> + <dirset dir="${input}"/> + </srcresources> + <globmapper from="*" to="${output}/*"/> + </uptodate> + </au:assertFalse> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/utf-16.expected b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/utf-16.expected Binary files differnew file mode 100644 index 00000000..7c7c2a78 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/utf-16.expected diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/utf-16.expected.windows b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/utf-16.expected.windows Binary files differnew file mode 100644 index 00000000..1e138e81 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/utf-16.expected.windows diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/war-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/war-test.xml new file mode 100644 index 00000000..e264ebda --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/war-test.xml @@ -0,0 +1,194 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<project name="war-test" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}"/> + <property name="warfile" location="${input}/test.war"/> + <property name="web.xml" location="web.xml"/> + <property name="webxml.generated" location="${input}/WEB-INF/web.xml"/> + + <!--failing on duplicates is half our testing--> + <presetdef name="mkwar"> + <war destfile="${warfile}" duplicate="fail"/> + </presetdef> + <presetdef name="expandwar"> + <unzip src="${input}/test.war" dest="${input}"/> + </presetdef> + </target> + + <!--test that you can patch a fileset reference into a lib element--> + <target name="testlibrefs" depends="setUp"> + <mkwar webxml="${web.xml}"> + <fileset id="test" dir="." includes="web.xml"/> + <lib refid="test"/> + </mkwar> + <expandwar/> + <au:assertFileExists file="${webxml.generated}" /> + </target> + + <!-- + This checks that as of Java EE 5, the web.xml attr is optional. + Here there is a web.xml, in the webinf fileset, rather than a fileset + --> + <target name="testWebXmlInWebinf" depends="setUp"> + <mkwar> + <webinf dir="." includes="web.xml"/> + </mkwar> + <expandwar/> + <au:assertFileExists file="${webxml.generated}" /> + </target> + + <target name="testWebXmlMissingFromUpdate" depends="setUp"> + <mkwar webxml="${web.xml}" /> + <!-- there is no web.xml file, but that is ok, as + we are updating --> + <mkwar update="true"> + <classes dir="." includes="web.xml"/> + </mkwar> + <expandwar/> + <au:assertFileExists file="${webxml.generated}" /> + </target> + + <target name="testWebXmlInImplicitUpdate" depends="setUp"> + <mkwar webxml="${web.xml}" /> + <!-- when we are implicitly updating, the web.xml file does not get + pulled in, but the command still succeeds.--> + <mkwar webxml="${web.xml}" > + <classes dir="." includes="web.xml"/> + </mkwar> + <expandwar/> + <au:assertFileExists file="${webxml.generated}" /> + </target> + + <target name="NotestWebXmlFilesetInImplicitUpdate" depends="setUp"> + <mkwar webxml="${web.xml}" /> + <!-- when we are implicitly updating, the web.xml file does not get + pulled in, but the command still succeeds.--> + <mkwar > + <webinf dir="." includes="web.xml"/> + </mkwar> + <expandwar/> + <au:assertFileExists file="${webxml.generated}" /> + </target> + + + <target name="testDuplicateWebXml" depends="setUp"> + <mkwar webxml="${web.xml}" > + <webinf dir="." includes="web.xml"/> + <webinf file="${web.xml}"/> + <zipfileset file="${web.xml}" prefix="WEB-INF"/> + </mkwar> + <expandwar/> + <au:assertFileExists file="${webxml.generated}" /> + </target> + + <target name="testDifferentDuplicateWebXml" depends="setUp"> + <copy file="${web.xml}" todir="${input}" /> + <mkwar webxml="${web.xml}" > + <webinf dir="${input}" includes="web.xml"/> + <webinf file="${web.xml}"/> + <zipfileset file="${web.xml}" prefix="WEB-INF"/> + </mkwar> + <expandwar/> + <au:assertFileExists file="${webxml.generated}" /> + <au:assertLogContains text="The duplicate entry is"/> + </target> + + + <!-- + this target does not have a web.xml file. + Instead it pulls in + --> + <target name="testWebXmlOptional" depends="setUp"> + <mkwar needxmlfile="false"> + <classes dir="." includes="web.xml"/> + </mkwar> + <expandwar/> + <au:assertFileExists file="${input}/WEB-INF/classes/web.xml" /> + <au:assertFalse> + <available file="${webxml.generated}" /> + </au:assertFalse> + </target> + + <target name="testWebXmlOptionalFailure" depends="setUp"> + <au:expectfailure> + <mkwar > + <classes dir="." includes="web.xml"/> + </mkwar> + </au:expectfailure> + </target> + + <target name="testWebXmlOptionalFailure2" depends="setUp"> + <au:expectfailure> + <mkwar needxmlfile="true"> + <classes dir="." includes="web.xml"/> + </mkwar> + </au:expectfailure> + </target> + + <target name="testClassesElement" depends="setUp"> + <mkwar needxmlfile="false"> + <classes dir="." includes="web.xml"/> + </mkwar> + <expandwar/> + <au:assertFileExists file="${input}/WEB-INF/classes/web.xml" /> + </target> + + <target name="testLibElement" depends="setUp"> + <mkwar needxmlfile="false"> + <lib dir="." includes="web.xml"/> + </mkwar> + <expandwar/> + <au:assertFileExists file="${input}/WEB-INF/lib/web.xml" /> + </target> + + <target name="testMappedClasspathFromManual"> + <mkdir dir="${input}"/> + <mkdir dir="${output}/out"/> + <war destfile="${output}/test.war" webxml="${ant.file}"> + <mappedresources> + <restrict> + <path path="${java.class.path}"/> + <type type="file"/> + </restrict> + <chainedmapper> + <flattenmapper/> + <globmapper from="*" to="WEB-INF/lib/*"/> + </chainedmapper> + </mappedresources> + </war> + <unzip src="${output}/test.war" dest="${output}/out"/> + <au:assertFileExists file="${output}/out/WEB-INF/lib/ant.jar"/> + </target> + + <target name="testOnlyOneWebXml"> + <mkdir dir="${input}/WEB-INF"/> + <mkdir dir="${output}"/> + <touch file="${input}/WEB-INF/web.xml"/> + <touch file="${input}/x.xml"/> + <war destfile="${output}/test.war" webxml="${input}/x.xml"> + <fileset dir="${input}"/> + </war> + <au:assertLogContains text="Warning: selected war files include a second WEB-INF/web.xml which will be ignored."/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/web.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/web.xml new file mode 100644 index 00000000..414625ae --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/web.xml @@ -0,0 +1,21 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<web-app xmlns="http://java.sun.com/xml/ns/javaee" + version="2.5" metadata-complete="true"> + +</web-app> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/whichresource-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/whichresource-test.xml new file mode 100644 index 00000000..6bf5a881 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/whichresource-test.xml @@ -0,0 +1,51 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="init"> + <delete quiet="yes" dir="${output}"/> + <mkdir dir="${output}"/> + <javac srcdir="javac-dir/good-src" destdir="${output}"/> + <path id="whichresource-build" path="${output}"/> + </target> + + <target name="test-reference" depends="init"> + <whichresource + property="whichresource.prop" + class="Simple" + classpathref="whichresource-build"/> + + <au:assertTrue> + <contains string="${whichresource.prop}" + substring="Simple.class"/> + </au:assertTrue> + </target> + + <target name="test-not-present" depends="init"> + <whichresource + property="whichresource2.prop" + class="ClassNotPresent" + classpathref="whichresource-build"/> + + <au:assertFalse> + <isset property="whichresource.prop2"/> + </au:assertFalse> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xmlproperty-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xmlproperty-test.xml new file mode 100644 index 00000000..5be04207 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xmlproperty-test.xml @@ -0,0 +1,144 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <description/> + + <import file="../antunit-base.xml" /> + + <target name="test-empty"> + <xmlproperty file="xmlproperty-test.xml"/> + <au:assertTrue> + <equals arg1="" arg2="${project.description}"/> + </au:assertTrue> + </target> + + <target name="test-multi"> + <property name="root.element.value" value="original"/> + <xmlproperty file="xmlproperty.multi.xml" collapseAttributes="yes"/> + <au:assertTrue> + <equals arg1="original" arg2="${root.element.value}"/> + </au:assertTrue> + </target> + + <target name="load"> + <xmlproperty + file="xmlproperty.inline-expansion.xml" + collapseAttributes="true" + keepRoot="false" + semanticAttributes="true"/> + <echo> + element expected actual + p $${app.n} ${app.p} + n n ${app.n} + o n ${app.o} + m n ${app.m} + </echo> + </target> + + <target name="NotestInlineExpansion" depends="load"> + <au:assertPropertyEquals name="app.m" value="n"/> + <au:assertPropertyEquals name="app.n" value="n"/> + <au:assertPropertyEquals name="app.o" value="n"/> + <au:assertPropertyEquals name="app.p" value="$${app.n}"/> + <property name="sequence" value="${app.m}${app.n}${app.o}${app.p}"/> + <fail> + xml attributes are not expanding correctly + expected: mnop=nnn$${app.n} + actual mnop=${sequence} + <condition> + <not> + <equals arg1="${sequence}" arg2="nnn${app.n}"/> + </not> + </condition> + </fail> + </target> + + <target name="createDocExample"> + <mkdir dir="${input}"/> + <echoxml file="${input}/example.xml"> + <root-tag> + <version value="0.0.1"/> + <build folder="build"> + <classes id="build.classes" location="${build.folder}/classes"/> + <reference refid="build.classes"/> + </build> + <compile> + <classpath pathid="compile.classpath"> + <pathelement location="${build.classes}"/> + </classpath> + </compile> + <run-time> + <jars>*.jar</jars> + <classpath pathid="run-time.classpath"> + <path refid="compile.classpath"/> + <pathelement path="${run-time.jars}"/> + </classpath> + </run-time> + </root-tag> + </echoxml> + </target> + + <target name="testSemanticLoadingDocExample" depends="createDocExample"> + <xmlproperty file="${input}/example.xml" semanticAttributes="true" + keepRoot="false"/> + + <au:assertPropertyEquals name="version" value="0.0.1"/> + <au:assertPropertyEquals name="build.folder" value="build"/> + <property name="b.c" location="${build.folder}/classes"/> + <au:assertPropertyEquals name="build.classes" value="${b.c}"/> + <au:assertReferenceSet refid="build.classes"/> + <property name="b.c.r" refid="build.classes"/> + <au:assertPropertyEquals name="b.c.r" value="${b.c}"/> + <au:assertPropertyEquals name="build.reference" value="${b.c}"/> + <au:assertPropertyEquals name="run-time.jars" value="*.jar"/> + <au:assertReferenceIsType refid="compile.classpath" type="path"/> + <au:assertReferenceIsType refid="run-time.classpath" type="path"/> + <property name="c.c" refid="compile.classpath"/> + <au:assertPropertyEquals name="c.c" value="${b.c}"/> + <property name="rt.c" refid="run-time.classpath"/> + <property name="glob.dot.jar" location="*.jar"/> + <au:assertPropertyEquals name="rt.c" + value="${b.c}${path.separator}${glob.dot.jar}"/> + </target> + + <target name="testIncludeSemanticDocExample" depends="createDocExample"> + <xmlproperty file="${input}/example.xml" semanticAttributes="true" + keepRoot="false" includeSemanticAttribute="true"/> + + <au:assertPropertyEquals name="version.value" value="0.0.1"/> + <au:assertPropertyEquals name="build.folder" value="build"/> + <property name="b.c" location="${build.folder}/classes"/> + <au:assertPropertyEquals name="build.classes.location" value="${b.c}"/> + <au:assertReferenceSet refid="build.classes"/> + <property name="b.c.r" refid="build.classes"/> + <au:assertPropertyEquals name="b.c.r" value="${b.c}"/> + <au:assertPropertyEquals name="build.reference" value="${b.c}"/> + <au:assertPropertyEquals name="run-time.jars" value="*.jar"/> + <au:assertReferenceIsType refid="compile.classpath" type="path"/> + <au:assertReferenceIsType refid="run-time.classpath" type="path"/> + <property name="c.c" refid="compile.classpath"/> + <!-- not set at all because property's name is build.classes.refid now --> + <property name="b.c.loc" location="${build.classes}"/> + <au:assertPropertyEquals name="c.c" value="${b.c.loc}"/> + <property name="rt.c" refid="run-time.classpath"/> + <property name="glob.dot.jar" location="*.jar"/> + <au:assertPropertyEquals name="rt.c" + value="${b.c.loc}${path.separator}${glob.dot.jar}"/> + </target> +</project> + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xmlproperty.inline-expansion.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xmlproperty.inline-expansion.xml new file mode 100644 index 00000000..a9151799 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xmlproperty.inline-expansion.xml @@ -0,0 +1,33 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<root-tag> + <!--used to check that the ordering of attribute expansion/eval is the order of + declaration in the build file, not alphabetical + + expectations are + p : ${app.n} + n : n + o : n + m : n + --> + <app + p="${app.n}" + n="n" + o="${app.n}" + m="${app.n}"/> +</root-tag>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xmlproperty.multi.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xmlproperty.multi.xml new file mode 100644 index 00000000..9899c586 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xmlproperty.multi.xml @@ -0,0 +1,21 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<root> + <element value="a" /> + <element value="b" /> +</root> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xslt-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xslt-test.xml new file mode 100644 index 00000000..d6f6d668 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xslt-test.xml @@ -0,0 +1,260 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${output}"/> + <property name="legacy.dir" + location="../../../etc/testcases/taskdefs/style/"/> + </target> + + <target name="testParameterPropagation" depends="setUp"> + <xslt in="${legacy.dir}/data.xml" + out="${output}/out.xml" + style="${legacy.dir}/printParams.xsl"> + <param name="set" expression="myvalue"/> + </xslt> + <au:assertResourceContains + resource="${output}/out.xml" + value="set='myvalue'"/> + </target> + + <target name="testParameterTypes" depends="setUp" description="parameters of various data types and XPath expressions"> + + <property name="antProperty1" value="ANT_PROPERTY_1"/> + <property name="antProperty2" value="ANT_PROPERTY_2"/> + <property name="antProperty3" value="3"/> + <property name="antProperty4" value="substring-before"/> + + <xslt in="${legacy.dir}/data.xml" + out="${output}/out.xml"> + <param name="p1" expression="123" type="INT"/> + <param name="p2" expression="64 * 64 div 128 + 10" type="XPATH_NUMBER"/> + <param name="p3" expression="${antProperty4}($antProperty2, '_')" type="XPATH_STRING"/> + + <style> + <string><![CDATA[<xsl:stylesheet + version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:fo="http://www.w3.org/1999/XSL/Format"> + +<!-- get the xsl-parameter --> +<xsl:param name="p1"/> +<xsl:param name="p2"/> +<xsl:param name="p3"/> + +<!-- use the xsl-parameter --> +<xsl:template match="/"> +p1_result='<xsl:value-of select="$p1 + 321"/>' +p2_result='<xsl:value-of select="$p2"/>' +p3_result='<xsl:value-of select="$p3"/>' +</xsl:template> + +</xsl:stylesheet> +]]></string> + </style> + </xslt> + <au:assertResourceContains resource="${output}/out.xml" value="p1_result='444'"/> + <au:assertResourceContains resource="${output}/out.xml" value="p2_result='42'"/> + <au:assertResourceContains resource="${output}/out.xml" value="p3_result='ANT'"/> + </target> + + <target name="testInlineStyleSheet" depends="setUp"> + <xslt in="${legacy.dir}/data.xml" + out="${output}/out.xml"> + <param name="set" expression="somevalue"/> + <style> + <string><![CDATA[<xsl:stylesheet + version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:fo="http://www.w3.org/1999/XSL/Format"> + +<!-- get the xsl-parameter --> +<xsl:param name="set">set default value</xsl:param> +<xsl:param name="empty">empty default value</xsl:param> +<xsl:param name="undefined">undefined default value</xsl:param> + +<!-- use the xsl-parameter --> +<xsl:template match="/"> +set='<xsl:value-of select="$set"/>' +empty='<xsl:value-of select="$empty"/>' +undefined='<xsl:value-of select="$undefined"/>' +</xsl:template> + +</xsl:stylesheet> +]]></string> + </style> + </xslt> + <au:assertResourceContains + resource="${output}/out.xml" + value="set='somevalue'"/> + </target> + + <target name="testStyleDoesntExist" depends="setUp"> + <au:expectfailure expectedmessage="i-m-not-there.xslt doesn't exist."> + <xslt in="${legacy.dir}/data.xml" + out="${output}/out.xml" + style="i-m-not-there.xslt"/> + </au:expectfailure> + </target> + + <target name="testStyleDoesntExistNoError" depends="setUp"> + <xslt in="${legacy.dir}/data.xml" + out="${output}/out.xml" + style="i-m-not-there.xslt" + failOnError="false"/> + <au:assertFileDoesntExist file="${output}/out.xml"/> + </target> + + <target name="testStyleDoesntExistNoTransformationError" depends="setUp"> + <au:expectfailure expectedmessage="i-m-not-there.xslt doesn't exist."> + <xslt in="${legacy.dir}/data.xml" + out="${output}/out.xml" + style="i-m-not-there.xslt" + failOnTransformationError="false"/> + </au:expectfailure> + </target> + + <target name="testTransformationError" depends="setUp"> + <au:expectfailure expectedmessage="Fatal error during transformation"> + <xslt in="${legacy.dir}/data.xml" + out="${output}/out.xml" + style="xslt/printParams-invalid.xsl" + /> + </au:expectfailure> + </target> + + <target name="testTransformationErrorNoFail" depends="setUp"> + <xslt in="${legacy.dir}/data.xml" + out="${output}/out.xml" + style="xslt/printParams-invalid.xsl" + failOnError="false"/> + <au:assertFileDoesntExist file="${output}/out.xml"/> + </target> + + <target name="testTransformationErrorNoFailOnTransformation" depends="setUp"> + <xslt in="${legacy.dir}/../input.stdin" + out="${output}/out.xml" + style="${legacy.dir}/printParams.xsl" + failOnTransformationError="false"/> + <au:assertFileDoesntExist file="${output}/out.xml"/> + </target> + + <target name="testNoResources" depends="setUp"> + <au:expectfailure expectedmessage="no resources specified"> + <xslt destdir="${output}" style="${legacy.dir}/printParams.xsl" + useImplicitFileset="false"> + <fileset dir="."> + <include name="I don't exist"/> + </fileset> + </xslt> + </au:expectfailure> + </target> + + <target name="testNoResourcesNoFail" depends="setUp"> + <xslt destdir="${output}" style="${legacy.dir}/printParams.xsl" + useImplicitFileset="false" + failOnNoResources="false"> + <fileset dir="."> + <include name="I don't exist"/> + </fileset> + </xslt> + </target> + + <target name="testNoResourcesNoError" depends="setUp"> + <xslt destdir="${output}" style="${legacy.dir}/printParams.xsl" + useImplicitFileset="false" + failOnError="false"> + <fileset dir="."> + <include name="I don't exist"/> + </fileset> + </xslt> + </target> + + + <target name="testTraceJdk14" unless="jdk1.5+" depends="setUp"> + <xslt in="${legacy.dir}/data.xml" + out="${output}/out.xml" + style="${legacy.dir}/printParams.xsl"> + <param name="set" expression="myvalue"/> + <trace templates="true"/> + </xslt> + <au:assertLogContains text="Failed to enable tracing" level="warning"/> + </target> + + <target name="testTraceJdk15+" if="jdk1.5+" depends="setUp"> + <xslt in="${legacy.dir}/data.xml" + out="${output}/out.xml" + style="${legacy.dir}/printParams.xsl"> + <param name="set" expression="myvalue"/> + <trace templates="true" elements="true" generation="true" + selection="true" extension="true"/> + </xslt> + <au:assertLogDoesntContain text="Failed to enable tracing"/> + </target> + + <target name="setUpIfUnlessTests" depends="setUp"> + <macrodef name="xs"> + <sequential> + <xslt in="${legacy.dir}/data.xml" out="${output}/out.xml" + style="${legacy.dir}/printParams.xsl"> + <param name="set" expression="if-value" if="${if}"/> + <param name="set" expression="unless-value" unless="${if}"/> + <param name="empty" expression="if-value" if="if"/> + <param name="empty" expression="unless-value" unless="if"/> + </xslt> + </sequential> + </macrodef> + </target> + + <target name="testPropertiesNotSet" depends="setUpIfUnlessTests"> + <xs/> + <au:assertResourceContains resource="${output}/out.xml" + value="set='unless-value'"/> + <au:assertResourceContains resource="${output}/out.xml" + value="empty='unless-value'"/> + </target> + + <target name="testPropertiesSet" depends="setUpIfUnlessTests"> + <property name="if" value="whatever"/> + <xs/> + <au:assertResourceContains resource="${output}/out.xml" + value="set='unless-value'"/> + <au:assertResourceContains resource="${output}/out.xml" + value="empty='if-value'"/> + </target> + + <target name="testIfTrue" depends="setUpIfUnlessTests"> + <property name="if" value="true"/> + <xs/> + <au:assertResourceContains resource="${output}/out.xml" + value="set='if-value'"/> + <au:assertResourceContains resource="${output}/out.xml" + value="empty='if-value'"/> + </target> + + <target name="testIfFalse" depends="setUpIfUnlessTests"> + <property name="if" value="false"/> + <xs/> + <au:assertResourceContains resource="${output}/out.xml" + value="set='unless-value'"/> + <au:assertResourceContains resource="${output}/out.xml" + value="empty='if-value'"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xslt/printParams-invalid.xsl b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xslt/printParams-invalid.xsl new file mode 100644 index 00000000..36d404e8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/xslt/printParams-invalid.xsl @@ -0,0 +1,36 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<xsl:stylesheet + version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:fo="http://www.w3.org/1999/XSL/Format"> + +<!-- get the xsl-parameter --> +<xsl:param name="set">set default value</xsl:param> +<xsl:param name="empty">empty default value</xsl:param> +<xsl:param name="undefined">undefined default value</xsl:param> + +<!-- use the xsl-parameter --> +<xsl:template match="'"> +set='<xsl:value-of select="$set"/>' +empty='<xsl:value-of select="$empty"/>' +undefined='<xsl:value-of select="$undefined"/>' +</xsl:template> + +</xsl:stylesheet> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/zip-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/zip-test.xml new file mode 100644 index 00000000..6a054f13 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/zip-test.xml @@ -0,0 +1,185 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="testEmptyDirs"> + <mkdir dir="${input}/foo"/> + <mkdir dir="${output}/bar"/> + <zip destfile="${output}/test.zip"> + <fileset dir="${input}"/> + </zip> + <unzip src="${output}/test.zip" dest="${output}/bar"/> + <au:assertFileExists file="${output}/bar/foo"/> + </target> + + <target name="testMappedResources"> + <mkdir dir="${input}"/> + <mkdir dir="${output}/out"/> + <echo file="${input}/foo.txt">Hello, world!</echo> + <zip destfile="${output}/test.zip"> + <mappedresources> + <fileset dir="${input}"/> + <globmapper from="foo.*" to="bar.*"/> + </mappedresources> + </zip> + <unzip src="${output}/test.zip" dest="${output}/out"/> + <au:assertFileDoesntExist file="${output}/out/foo.txt"/> + <au:assertFileExists file="${output}/out/bar.txt"/> + <au:assertFilesMatch expected="${input}/foo.txt" + actual="${output}/out/bar.txt"/> + </target> + + <target name="test-54026"> + <mkdir dir="${input}"/> + <touch file="${input}/test1"/> + <mkdir dir="${input}/subdir"/> + <touch file="${input}/subdir/test2"/> + <zip destfile="${output}/br54026-destzip.zip"> + <mappedresources> + <fileset dir="${input}"/> + <globmapper from="subdir/*" to="subdir.orig/*"/> + </mappedresources> + </zip> + + <au:assertFileExists file="${output}/br54026-destzip.zip"/> + </target> + + <target name="testMappedClasspath"> + <mkdir dir="${input}"/> + <mkdir dir="${output}/out"/> + <zip destfile="${output}/test.zip"> + <mappedresources> + <path path="${java.class.path}"/> + <chainedmapper> + <flattenmapper/> + <globmapper from="*" to="WEB-INF/lib/*"/> + </chainedmapper> + </mappedresources> + </zip> + <unzip src="${output}/test.zip" dest="${output}/out"/> + <au:assertFileExists file="${output}/out/WEB-INF/lib/ant.jar"/> + </target> + + <target name="testIssue45902" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=45902"> + <mkdir dir="${input}/src/p"/> + <mkdir dir="${output}"/> + <touch file="${input}/src/p/X.java"/> + <touch file="${input}/src/p/x.properties"/> + <mkdir dir="${input}/build"/> + <copy todir="${input}/build"> + <fileset dir="${input}/src" includes="**/*.java"/> + </copy> + + <jar jarfile="${output}/jar.jar"> + <fileset dir="${input}/build"/> + <fileset dir="${input}/src" excludes="**/*.java"/> + </jar> + <copy file="${output}/jar.jar" tofile="${output}/reference.jar"/> + + <sleep seconds="1"/> + <touch file="${input}/src/p/y.properties"/> + <sleep seconds="1"/> + <delete file="${input}/src/p/y.properties"/> + <jar jarfile="${output}/jar.jar"> + <fileset dir="${input}/build"/> + <fileset dir="${input}/src" excludes="**/*.java"/> + </jar> + <au:assertDestIsUptodate src="${output}/jar.jar" + dest="${output}/reference.jar"/> + + <sleep seconds="1"/> + <jar jarfile="${output}/jar.jar"> + <fileset dir="${input}/build"/> + <fileset dir="${input}/src" excludes="**/*.java"/> + </jar> + <au:assertDestIsUptodate src="${output}/jar.jar" + dest="${output}/reference.jar"/> + + <jar jarfile="${output}/jar.jar"> + <fileset dir="${input}/build"/> + <fileset dir="${input}/src" excludes="**/*.java"/> + </jar> + <au:assertDestIsUptodate src="${output}/jar.jar" + dest="${output}/reference.jar"/> + </target> + + <target name="testNewEmptyDirUpdatesArchive"> + <mkdir dir="${input}"/> + <touch file="${input}/x"/> + <mkdir dir="${output}"/> + <jar jarfile="${output}/jar.jar"> + <fileset dir="${input}"/> + </jar> + <copy file="${output}/jar.jar" tofile="${output}/reference.jar"/> + + <mkdir dir="${input}/y"/> + <sleep seconds="2"/> + <jar jarfile="${output}/jar.jar"> + <fileset dir="${input}"/> + </jar> + <au:assertDestIsOutofdate src="${output}/jar.jar" + dest="${output}/reference.jar"/> + </target> + + <target name="testFilesetInsideResources" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50115"> + <mkdir dir="${input}/test2"/> + <touch file="${input}/test1.txt"/> + <mkdir dir="${output}"/> + <mkdir dir="${output}/expand"/> + <zip destfile="${output}/test.zip" whenempty="skip"> + <resources> + <fileset dir="${input}" includes="test**"/> + </resources> + </zip> + <au:assertLogDoesntContain text="skipping zip archive"/> + <unzip src="${output}/test.zip" dest="${output}/expand"/> + <au:assertFileExists file="${output}/expand/test1.txt"/> + <!--au:assertFileExists file="${output}/expand/test2"/--> + </target> + + <target name="testWhenEmptyChecksNonFileSets" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=50115"> + <mkdir dir="${input}/"/> + <touch file="${input}/test1.txt"/> + <mkdir dir="${output}"/> + <mkdir dir="${output}/expand"/> + <zip destfile="${output}/test.zip" whenempty="fail"> + <resources> + <fileset dir="${input}" includes="test**"/> + </resources> + </zip> + <unzip src="${output}/test.zip" dest="${output}/expand"/> + <au:assertFileExists file="${output}/expand/test1.txt"/> + </target> + + <target name="testUpdateZipWithDuplicateEntries" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=54967"> + <mkdir dir="${input}/"/> + <touch file="${input}/test1.txt"/> + <mkdir dir="${output}"/> + <zip destfile="${output}/test.zip" basedir="${input}"> + <fileset dir="${input}"/> + </zip> + <zip destfile="${output}/test.zip" update="true"> + <fileset dir="${basedir}" includes="zip-test.xml"/> + </zip> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/zip/Bugzilla-42940.zip b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/zip/Bugzilla-42940.zip Binary files differnew file mode 100644 index 00000000..2f756608 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/zip/Bugzilla-42940.zip diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/build-embedded-ref.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/build-embedded-ref.xml new file mode 100644 index 00000000..f2cbd2ad --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/build-embedded-ref.xml @@ -0,0 +1,20 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="all"> + <target name="all"/> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/conditions/isreference-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/conditions/isreference-test.xml new file mode 100644 index 00000000..8929e901 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/conditions/isreference-test.xml @@ -0,0 +1,40 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="isreference-test" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../../antunit-base.xml" /> + + <target name="out-of-band"> + <path id="out-of-band" path="."/> + </target> + + <target name="testOutOfBand"> + <au:assertFalse> + <isreference refid="out-of-band"/> + </au:assertFalse> + </target> + + <target name="testInBand"> + <path id="in-band" path="."/> + <au:assertTrue> + <isreference refid="in-band"/> + </au:assertTrue> + </target> +</project> + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/conditions/matches-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/conditions/matches-test.xml new file mode 100644 index 00000000..5d174613 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/conditions/matches-test.xml @@ -0,0 +1,114 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit"> + <!-- NB: ant's interface to JDK14 regex enables UNIX_LINES --> + <property name="NL" value=" "/> + <regexp id="myid" pattern="^[a-z]{3,4}$"/> + + <available property="jdk1.4+" classname="java.lang.CharSequence"/> + <condition property="some.regexp.support"> + <or> + <isset property="jdk1.4+"/> + <isset property="apache.regexp.present"/> + <isset property="apache.oro.present"/> + </or> + </condition> + + <target name="test-refid" if="some.regexp.support"> + <au:assertTrue> + <matches string="abc"> + <regexp refid="myid"/> + </matches> + </au:assertTrue> + </target> + + <target name="test-simple" if="some.regexp.support"> + <au:assertTrue> + <matches string="abc" pattern="^[a-z]{3,4}$"/> + </au:assertTrue> + </target> + + <target name="test-nomatch" if="some.regexp.support"> + <au:assertFalse> + <matches string="abc" pattern="^b.*" /> + </au:assertFalse> + </target> + + <target name="test-date" if="some.regexp.support"> + <tstamp> + <format property="today" pattern="dd-MM-yyyy" locale="en"/> + </tstamp> + <au:assertTrue> + <matches string="${today}"> + <regexp pattern="^[0123]\d-[01]\d-[12]\d\d\d$" /> + </matches> + </au:assertTrue> + </target> + + <target name="test-abc" if="some.regexp.support"> + <au:assertTrue> + <matches string="abc" pattern="ab?"/> + </au:assertTrue> + <au:assertTrue> + <matches string="abc" pattern="ab."/> + </au:assertTrue> + <au:assertTrue> + <matches string="ab" pattern="ab?"/> + </au:assertTrue> + <au:assertTrue> + <matches string="ab" pattern="ab"/> + </au:assertTrue> + <au:assertTrue> + <matches string="acb" pattern="ab?"/> + </au:assertTrue> + <au:assertFalse> + <matches string="acb" pattern="ab."/> + </au:assertFalse> + </target> + + <target name="test-caseinsensitive" if="some.regexp.support"> + <au:assertTrue> + <matches string="ABC" pattern="ab?" casesensitive="false"/> + </au:assertTrue> + </target> + + <target name="test-singleline" if="some.regexp.support"> + <au:assertTrue> + <matches string="AB${line.separator}C" pattern="^ab.*C$" + casesensitive="false" + singleline="true"/> + </au:assertTrue> + <au:assertFalse> + <matches string="AB${line.separator}C" pattern="^ab.*C$" + casesensitive="false" + singleline="false"/> + </au:assertFalse> + </target> + + <target name="test-multiline" if="some.regexp.support"> + <au:assertTrue> + <matches string="AB${NL}C" pattern="^C$" + multiline="true"/> + </au:assertTrue> + <au:assertTrue> + <matches string="AB${NL}C" pattern="^AB$" + multiline="true"/> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/cutdirs-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/cutdirs-test.xml new file mode 100644 index 00000000..64f0652b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/cutdirs-test.xml @@ -0,0 +1,56 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" + name="firstmatch-test" + default="antunit"> + + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + </target> + + <target name="testCut" depends="setUp"> + <mkdir dir="${input}/a/b/c"/> + <touch file="${input}/a/b/D"/> + <touch file="${input}/a/b/c/E"/> + <copy todir="${output}"> + <fileset dir="${input}"/> + <cutdirsmapper dirs="2"/> + </copy> + <au:assertFileExists file="${output}/D"/> + <au:assertFileExists file="${output}/c/E"/> + </target> + + <target name="testCutTooManyLevels" depends="setUp"> + <mkdir dir="${input}/a/b/c"/> + <touch file="${input}/a/b/D"/> + <touch file="${input}/a/b/c/E"/> + <copy todir="${output}"> + <fileset dir="${input}"/> + <cutdirsmapper dirs="5"/> + </copy> + <au:assertTrue> + <resourcecount count="0"> + <fileset dir="${output}"/> + </resourcecount> + </au:assertTrue> + </target> + +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/defer-reference-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/defer-reference-test.xml new file mode 100644 index 00000000..a67ad3b7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/defer-reference-test.xml @@ -0,0 +1,69 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="all" xmlns:au="antlib:org.apache.ant.antunit"> + <target name="notcalled"> + <filelist id="ref1" dir="${basedir}" files="xxx" /> + </target> + + <target name="test-macrodef-embedded-ref"> + <!-- bug 34458 --> + <macrodef name="foo"> + <element name="nested" implicit="yes" optional="yes"/> + <sequential> + <fileset id="abc" dir="."> + <nested/> + </fileset> + </sequential> + </macrodef> + + <ant antfile="build-embedded-ref.xml" inheritRefs="true"/> + </target> + + <condition property="allow.script"> + <and> + <available classname="org.apache.bsf.BSFManager" /> + <available classname="bsh.StringUtil" /> + </and> + </condition> + + <target name="test-script" if="allow.script"> + <!-- bugzilla: 37688 --> + <macrodef name="compileMapper" > + <attribute name="objDir" /> + <attribute name="id" default="compileMapperID" /> + <sequential> + <mkdir dir="@{objDir}"/> + <mapper id="@{id}"> + <chainedmapper > + <flattenmapper/> + <globmapper from="*" to="@{objDir}/*.o"/> + </chainedmapper> + </mapper> + </sequential> + </macrodef> + <script language="beanshell"/> + </target> + + <target name="all"> + <au:antunit> + <fileset file="${ant.file}"/> + <au:plainlistener/> + </au:antunit> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/fileset-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/fileset-test.xml new file mode 100644 index 00000000..9580a1ce --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/fileset-test.xml @@ -0,0 +1,67 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml"/> + + <target name="test-fileset-missing-dir"> + <path id="missing.path.id"> + <fileset id="missing.dir.fs" dir="not present" + erroronmissingdir="false"/> + </path> + <au:assertTrue> + <and> + <equals arg1="" arg2="${toString:missing.path.id}"/> + <resourcecount count="0" refid="missing.dir.fs" /> + </and> + </au:assertTrue> + </target> + + <target name="test-fileset-missing-dir-exception"> + <mkdir dir="${output}"/> + <au:expectfailure expectedmessage="not present does not exist"> + <copy todir="${output}"> + <fileset dir="not present" /> + </copy> + </au:expectfailure> + </target> + + <target name="test-fileset-with-if"> + <fileset id="this.xml" dir="."> + <include if="trigger.include" name="fileset-test.xml"/> + </fileset> + <pathconvert refid="this.xml" property="this.xml.prop" pathsep="${line.separator}" setonempty="false"/> + <au:assertTrue message="fileset this.xml should not contain anything but contains ${this.xml.prop}"> + <not> + <isset property="this.xml.prop"/> + </not> + </au:assertTrue> + </target> + + <target name="test-fileset-with-if-property-set"> + <property name="trigger.include" value="true"/> + <fileset id="this.xml" dir="."> + <include if="trigger.include" name="fileset-test.xml"/> + </fileset> + <pathconvert refid="this.xml" property="this.xml.prop" pathsep="${line.separator}" setonempty="false"/> + <au:assertPropertySet name="this.xml.prop" message="fileset should contain one file"/> + <echo>${this.xml.prop}</echo> + <au:assertLogContains text="fileset-test.xml"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/filterset-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/filterset-test.xml new file mode 100644 index 00000000..f1654f6d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/filterset-test.xml @@ -0,0 +1,96 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml" /> + + <property name="br" value="${line.separator}" /> + + <target name="testRecursionRegression"> + <mkdir dir="${output}"/> + <copy todir="${output}"> + <string value="@a@${br}@b@${br}@c@${br}@d@${br}" /> + <mergemapper to="filterset-output.txt" /> + <filterset> + <filter token="a" value="aaa" /> + <filter token="b" value="bbb" /> + <filter token="c" value="@a@:@b@" /> + <filter token="d" value="@c@:@c@" /> + </filterset> + </copy> + + <loadfile property="afterfiltering" srcFile="${output}/filterset-output.txt"/> + + <au:assertEquals + expected="aaa${br}bbb${br}aaa:bbb${br}aaa:bbb:aaa:bbb${br}" + actual="${afterfiltering}"/> + </target> + + <!-- https://issues.apache.org/bugzilla/show_bug.cgi?id=45094 --> + <target name="testOverlappingMulticharToken"> + <mkdir dir="${output}"/> + <copy todir="${output}"> + <string value="@@USER@@@@@HOST@@" /> + <mergemapper to="filterset-output.txt" /> + <filterset begintoken="@@" endtoken="@@"> + <filter token="USER" value="user" /> + <filter token="HOST" value="host" /> + </filterset> + </copy> + + <loadfile property="afterfiltering" srcFile="${output}/filterset-output.txt"/> + + <au:assertEquals + expected="user@host" + actual="${afterfiltering}"/> + </target> + + <target name="testNestedPropertySet"> + <mkdir dir="${output}"/> + <mkdir dir="${input}"/> + <echo file="${input}/src.txt"> +Filter with property set test +@foo.x@ - should change +@foo.y@ - should change +@bar.x@ - should not change +@cccc@ - should not change + </echo> + <echo file="${output}/expected.txt"> +Filter with property set test +1111 - should change +2222 - should change +@bar.x@ - should not change +@cccc@ - should not change + </echo> + <property name="foo.x" value="1111" /> + <property name="foo.y" value="2222" /> + <copy todir="${output}"> + <fileset dir="${input}"/> + <filterset> + <propertyset> + <propertyref prefix="foo." /> + </propertyset> + </filterset> + </copy> + <au:assertFilesMatch + actual="${output}/src.txt" + expected="${output}/expected.txt" + /> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/firstmatch-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/firstmatch-test.xml new file mode 100644 index 00000000..68c332b2 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/firstmatch-test.xml @@ -0,0 +1,41 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" + name="firstmatch-test" + default="antunit"> + + <import file="../antunit-base.xml" /> + + <target name="testMatch"> + <mkdir dir="${input}"/> + <touch file="${input}/A"/> + <touch file="${input}/B"/> + <mkdir dir="${output}"/> + <copy todir="${output}" enablemultiplemappings="true"> + <fileset dir="${input}"/> + <firstmatchmapper> + <globmapper from="A" to="A.txt"/> + <identitymapper/> + </firstmatchmapper> + </copy> + <au:assertFileExists file="${output}/A.txt"/> + <au:assertFileExists file="${output}/B"/> + <au:assertFileDoesntExist file="${output}/A"/> + <au:assertFileDoesntExist file="${output}/B.txt"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/javaresource-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/javaresource-test.xml new file mode 100644 index 00000000..d0e99e00 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/javaresource-test.xml @@ -0,0 +1,62 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${resources}"/> + <echo file="${resources}/foo.txt">Hello, world</echo> + <echo file="${resources}/x.properties">a=b</echo> + </target> + + <target name="testReadFromFile" depends="setUp"> + <concat> + <javaresource name="foo.txt"> + <classpath location="${resources}"/> + </javaresource> + </concat> + <au:assertLogContains text="Hello, world"/> + <loadproperties> + <javaresource name="x.properties"> + <classpath location="${resources}"/> + </javaresource> + </loadproperties> + <au:assertPropertyEquals name="a" value="b"/> + </target> + + <target name="testReadFromJar" depends="setUp"> + <jar destfile="${test.jar}"> + <fileset dir="${resources}"/> + </jar> + <delete dir="${resources}"/> + <concat> + <javaresource name="foo.txt"> + <classpath location="${test.jar}"/> + </javaresource> + </concat> + <au:assertLogContains text="Hello, world"/> + <loadproperties> + <javaresource name="x.properties"> + <classpath location="${test.jar}"/> + </javaresource> + </loadproperties> + <au:assertPropertyEquals name="a" value="b"/> + </target> +</project> + + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/mapper-ref.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/mapper-ref.xml new file mode 100644 index 00000000..3ada7f3b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/mapper-ref.xml @@ -0,0 +1,55 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<!-- does not address/replace the circular reference checks, etc. + in MapperTest.java (yet). + --> + +<project xmlns:au="antlib:org.apache.ant.antunit"> + <macrodef name="test"> + <sequential> + <pathconvert property="dest"> + <string value="foo" /> + <mapper refid="mapper" /> + </pathconvert> + <au:assertTrue> + <equals arg1="${dest}" arg2="bar" /> + </au:assertTrue> + </sequential> + </macrodef> + + <target name="testBasic" description="success"> + <mapper id="mapper" type="merge" to="bar" /> + <test /> + </target> + + <target name="testFileNameMapper" description="success"> + <mergemapper id="mapper" to="bar" /> + <test /> + </target> + + <target name="testWrongType" description="failure"> + <path id="mapper" path="whocares" /> + <au:expectfailure + expectedMessage="org.apache.tools.ant.types.Path at reference 'mapper' is not a valid mapper reference."> + <test /> + </au:expectfailure> + </target> + + <target name="all" depends="testBasic,testFileNameMapper,testWrongType" /> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/mappers/glob-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/mappers/glob-test.xml new file mode 100644 index 00000000..c4d92da2 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/mappers/glob-test.xml @@ -0,0 +1,80 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<!-- A test for bugzilla 44731 --> +<project xmlns:au="antlib:org.apache.ant.antunit" + name="glob-test" + default="antunit"> + + <import file="../../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + </target> + + <target name="test-overlapping-patterns" depends="setUp"> + <!-- shouldn't be moved because pre- and postfix of from pattern + overlap --> + <touch file="${input}/foobar-1.2.3.jar"/> + + <touch file="${input}/foobar-janfu-1.2.3.jar"/> + <touch file="${input}/foobar--1.2.3.jar"/> + <touch file="${input}/foobar-x-1.2.3.jar"/> + <move todir="${output}"> + <fileset dir="${input}"> + <include name="**/*.jar"/> + </fileset> + <mapper type="glob" from="foobar-*-1.2.3.jar" to="*.jar"/> + </move> + <au:assertFileExists file="${input}/foobar-1.2.3.jar"/> + <au:assertFileExists file="${output}/janfu.jar"/> + <au:assertFileExists file="${output}/.jar"/> + <au:assertFileExists file="${output}/x.jar"/> + </target> + + <target name="test-no-*-in-to" depends="setUp" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=46506"> + <touch file="${input}/a-b.jar"/> + <copy todir="${output}"> + <fileset dir="${input}"/> + <mapper type="glob" from="a*.jar" to="c.jar"/> + </copy> + <au:assertFileDoesntExist file="${output}/c.jar-b"/> + <au:assertFileExists file="${output}/c.jar"/> + </target> + + <target name="test-*-at-end-of-to" depends="setUp"> + <touch file="${input}/a-b.jar"/> + <copy todir="${output}"> + <fileset dir="${input}"/> + <mapper type="glob" from="a*.jar" to="c.jar*"/> + </copy> + <au:assertFileDoesntExist file="${output}/c.jar"/> + <au:assertFileExists file="${output}/c.jar-b"/> + </target> + + <target name="test-no-*-in-from" depends="setUp"> + <touch file="${input}/a-b.jar"/> + <copy todir="${output}"> + <fileset dir="${input}"/> + <mapper type="glob" from="a-b" to="c.jar"/> + </copy> + <au:assertFileDoesntExist file="${output}/c.jar"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/mappers/packagemapper-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/mappers/packagemapper-test.xml new file mode 100644 index 00000000..cad01464 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/mappers/packagemapper-test.xml @@ -0,0 +1,50 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" + default="antunit"> + + <import file="../../antunit-base.xml" /> + + <target name="testHandleDirSep" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=51086"> + <pathconvert property="p1"> + <string>foo/bar</string> + <packagemapper from="*" to="*" handledirsep="true"/> + </pathconvert> + <au:assertPropertyEquals name="p1" value="foo.bar"/> + <pathconvert property="p2"> + <string>foo\bar</string> + <packagemapper from="*" to="*" handledirsep="true"/> + </pathconvert> + <au:assertPropertyEquals name="p2" value="foo.bar"/> + </target> + + <target name="testMapsOnlySubstring" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=53399"> + <pathconvert property="p1"> + <string>xyzzy${file.separator}foo${file.separator}bar</string> + <packagemapper from="xyzzy${file.separator}*" to="*" handledirsep="false"/> + </pathconvert> + <au:assertPropertyEquals name="p1" value="foo.bar"/> + <pathconvert property="p2"> + <string>xyzzy${file.separator}foo${file.separator}bar</string> + <packagemapper from="xyzzy/*" to="*" handledirsep="true"/> + </pathconvert> + <au:assertPropertyEquals name="p2" value="foo.bar"/> + </target> +</project>
\ No newline at end of file diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/modified-selector-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/modified-selector-test.xml new file mode 100644 index 00000000..16688ca9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/modified-selector-test.xml @@ -0,0 +1,37 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml"/> + + <target name="test-one-file"> + <delete dir="${output}"/> + <mkdir dir="${output}"/> + <copy todir="${output}" overwrite="yes"> + <fileset dir="." includes="modified-selector-test.xml"> + <modified update="true"> + <param name="cache.cachefile" value="${output}/cc.properties"/> + </modified> + </fileset> + </copy> + + <au:assertTrue> + <available file="${output}/cc.properties"/> + </au:assertTrue> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/path-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/path-test.xml new file mode 100644 index 00000000..4f4be9ab --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/path-test.xml @@ -0,0 +1,51 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml" /> + + <property name="existingFile" value="${basedir}/build.xml" /> + + <files id="files"> + <include name="${existingFile}" /> + </files> + + <target name="test-directUse" description="Bug 42397 - works fine"> + <path id="path"> + <files> + <include name="${existingFile}" /> + </files> + </path> + </target> + + <target name="test-refid" description="Bug 42397"> + <path id="path"> + <files refid="files" /> + </path> + </target> + + <target name="test-wildcard" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=46842"> + <path id="with-wildcard"> + <pathelement location="*"/> + </path> + <au:assertEquals expected="${basedir}${file.separator}*" + actual="${toString:with-wildcard}"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/patternset-invert-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/patternset-invert-test.xml new file mode 100644 index 00000000..7c0912e7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/patternset-invert-test.xml @@ -0,0 +1,66 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="all" xmlns:au="antlib:org.apache.ant.antunit"> + + <macrodef name="test"> + <sequential> + <au:assertTrue> + <resourcecount count="0"> + <intersect> + <fileset dir="${basedir}"> + <patternset refid="plus" /> + </fileset> + <fileset dir="${basedir}"> + <patternset refid="minus" /> + </fileset> + </intersect> + </resourcecount> + </au:assertTrue> + </sequential> + </macrodef> + + <target name="testInvertNested"> + <basename property="basename" file="${ant.file}" /> + <echo>$${basename}=${basename}</echo> + <patternset id="plus" includes="${basename}" /> + <patternset id="minus"> + <invert> + <patternset refid="plus" /> + </invert> + </patternset> + <test /> + </target> + + <target name="testInvertRefid"> + <basename property="basename" file="${ant.file}" /> + <echo>$${basename}=${basename}</echo> + <patternset id="plus" includes="${basename}" /> + <patternset id="minus"> + <invert refid="plus" /> + </patternset> + <test /> + </target> + + <target name="all"> + <au:antunit> + <fileset file="${ant.file}"/> + <au:plainlistener /> + </au:antunit> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/patternset-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/patternset-test.xml new file mode 100644 index 00000000..60690d49 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/patternset-test.xml @@ -0,0 +1,78 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}"/> + <touch file="${input}/A"/> + <touch file="${input}/B"/> + <touch file="${input}/C"/> + <touch file="${input}/D"/> + <mkdir dir="${output}"/> + <macrodef name="cp"> + <sequential> + <copy todir="${output}"> + <fileset dir="${input}"> + <include name="A" if="${if}"/> + <include name="B" unless="${if}"/> + <include name="C" if="if"/> + <include name="D" unless="if"/> + </fileset> + </copy> + </sequential> + </macrodef> + </target> + + <target name="testIfNotSet" depends="setUp"> + <cp/> + <au:assertFileDoesntExist file="${output}/A"/> + <au:assertFileExists file="${output}/B"/> + <au:assertFileDoesntExist file="${output}/C"/> + <au:assertFileExists file="${output}/D"/> + </target> + + <target name="testIfSet" depends="setUp"> + <property name="if" value="whatever"/> + <cp/> + <au:assertFileDoesntExist file="${output}/A"/> + <au:assertFileExists file="${output}/B"/> + <au:assertFileExists file="${output}/C"/> + <au:assertFileDoesntExist file="${output}/D"/> + </target> + + <target name="testIfTrue" depends="setUp"> + <property name="if" value="true"/> + <cp/> + <au:assertFileExists file="${output}/A"/> + <au:assertFileDoesntExist file="${output}/B"/> + <au:assertFileExists file="${output}/C"/> + <au:assertFileDoesntExist file="${output}/D"/> + </target> + + <target name="testIfFalse" depends="setUp"> + <property name="if" value="false"/> + <cp/> + <au:assertFileDoesntExist file="${output}/A"/> + <au:assertFileExists file="${output}/B"/> + <au:assertFileExists file="${output}/C"/> + <au:assertFileDoesntExist file="${output}/D"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/propertyset-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/propertyset-test.xml new file mode 100644 index 00000000..0b7e236c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/propertyset-test.xml @@ -0,0 +1,125 @@ +<?xml version="1.0"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * +--> + +<project name="test-propertyset" basedir="." default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../antunit-base.xml" /> + + <property name="fooA" value="FooA"/> + <property name="barB" value="BarB"/> + + <propertyset id="properties-starting-with-foo"> + <propertyref prefix="foo"/> + </propertyset> + <propertyset id="properties-starting-with-bar"> + <propertyref prefix="bar"/> + </propertyset> + <propertyset id="my-set"> + <propertyset refid="properties-starting-with-foo"/> + <propertyset refid="properties-starting-with-bar"/> + </propertyset> + + <macrodef name="expect.equals"> + <attribute name="test"/> + <attribute name="exp"/> + <attribute name="got"/> + <sequential> + <fail message= + "@{test} failed: expected "@{exp}" got "@{got}""> + <condition> + <not> + <equals arg1="@{exp}" arg2="@{got}"/> + </not> + </condition> + </fail> + </sequential> + </macrodef> + + <target name="test-reference-to-two-references"> + <expect.equals + test="reference to two references" + exp="barB=BarB, fooA=FooA" + got="${toString:my-set}"/> + </target> + + <target name="test-nested-mapped"> + <propertyset id="nested-mapped"> + <propertyset> + <propertyset refid="properties-starting-with-foo"/> + <globmapper from="foo*" to="boo*" /> + </propertyset> + <propertyset> + <propertyset refid="properties-starting-with-bar"/> + <globmapper from="bar*" to="far*" /> + </propertyset> + </propertyset> + <expect.equals + test="nested mapped propertysets" + exp="booA=FooA, farB=BarB" + got="${toString:nested-mapped}"/> + </target> + + <target name="test-nested-mapped-mapped"> + <propertyset id="nested-mapped-mapped"> + <propertyset> + <propertyset refid="properties-starting-with-foo"/> + <globmapper from="foo*" to="boo*" /> + </propertyset> + <propertyset> + <propertyset refid="properties-starting-with-bar"/> + <globmapper from="bar*" to="far*" /> + </propertyset> + <mapper> + <globmapper from="boo*" to="hoo*" /> + <globmapper from="far*" to="near*" /> + </mapper> + </propertyset> + <expect.equals + test="nested mapped propertysets" + exp="hooA=FooA, nearB=BarB" + got="${toString:nested-mapped-mapped}"/> + </target> + + <target name="testResources"> + <au:assertTrue> + <resourcecount count="2"> + <restrict> + <exists /> + <resources refid="my-set" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testMappedResources"> + <au:assertTrue> + <resourcecount count="2"> + <restrict> + <exists /> + <propertyset> + <propertyset refid="my-set" /> + <globmapper from="bar*" to="far*" /> + </propertyset> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/archives-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/archives-test.xml new file mode 100644 index 00000000..961effc7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/archives-test.xml @@ -0,0 +1,136 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../../antunit-base.xml"/> + + <target name="testExtractJars"> + <mkdir dir="${output}"/> + <copy todir="${output}"> + <archives> + <zips> + <fileset dir="${ant.home}/lib" + includes="ant-*.jar"/> + </zips> + </archives> + </copy> + <au:assertFileExists + file="${output}/org/apache/tools/ant/launch/Launcher.class"/> + <au:assertFileExists + file="${output}/org/apache/tools/ant/BuildFileTest.class"/> + </target> + + <target name="testMixingZipsAndTars"> + <mkdir dir="${output}"/> + <tar destfile="${output}/test.tar.gz" compression="gzip"> + <fileset file="${ant.file}"/> + </tar> + <copy todir="${output}"> + <archives> + <zips> + <fileset dir="${ant.home}/lib" + includes="ant-launcher.jar"/> + </zips> + <tars> + <gzipresource> + <file file="${output}/test.tar.gz"/> + </gzipresource> + </tars> + </archives> + </copy> + <au:assertFileExists + file="${output}/org/apache/tools/ant/launch/Launcher.class"/> + <basename property="filename" file="${ant.file}"/> + <au:assertFileExists file="${output}/${filename}"/> + </target> + + <target name="testReference"> + <mkdir dir="${output}"/> + <archives id="ref"> + <zips> + <fileset dir="${ant.home}/lib" + includes="ant-launcher.jar"/> + </zips> + </archives> + <copy todir="${output}"> + <archives refid="ref"/> + </copy> + <au:assertFileExists + file="${output}/org/apache/tools/ant/launch/Launcher.class"/> + </target> + + <target name="testCircularReference"> + <au:expectfailure + message="This data type contains a circular reference."> + <copy todir="${output}"> + <archives id="ref"> + <zips> + <archives refid="ref"/> + </zips> + </archives> + </copy> + </au:expectfailure> + <au:expectfailure + message="This data type contains a circular reference."> + <copy todir="${output}"> + <archives refid="ref"/> + </copy> + </au:expectfailure> + </target> + + <!-- works but takes a veeeeeery long time --> + <target name="XtestResourcesManualExample"> + <mkdir dir="${output}"/> + <copy todir="${output}"> + <archives> + <zips> + <restrict> + <path path="${java.class.path}"/> + <name name="*.jar"/> + </restrict> + </zips> + </archives> + </copy> + <au:assertFileExists + file="${output}/org/apache/tools/ant/launch/Launcher.class"/> + </target> + + <target name="testZipManualExample"> + <mkdir dir="${output}/control"/> + <mkdir dir="${input}/htdocs/manual"/> + <touch file="${input}/htdocs/manual/foo.txt"/> + <zip destfile="${input}/examples-a.zip"> + <fileset dir="." includes="*.xml"/> + </zip> + <zip destfile="${output}/manual.zip"> + <mappedresources> + <fileset dir="${input}/htdocs/manual"/> + <globmapper from="*" to="docs/user-guide/*"/> + </mappedresources> + <archives> + <zips> + <fileset dir="${input}" includes="examples*.zip"/> + </zips> + </archives> + </zip> + <unzip src="${output}/manual.zip" dest="${output}/control"/> + <au:assertFileExists file="${output}/control/archives-test.xml"/> + <au:assertFileExists file="${output}/control/docs/user-guide/foo.txt"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/comparators/test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/comparators/test.xml new file mode 100644 index 00000000..524f67a1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/comparators/test.xml @@ -0,0 +1,299 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" + xmlns:au="antlib:org.apache.ant.antunit" + xmlns:rcmp="antlib:org.apache.tools.ant.types.resources.comparators"> + + <import file="../../../antunit-base.xml" /> + + <property name="dirname" value="work" /> + <property name="dir" location="${output}/${dirname}" /> + <property name="echolevel" value="debug" /> + + <target name="tearDown"> + <delete dir="${dir}" /> + <delete file="${zip}" /> + <delete file="${jar}" deleteonexit="true" /> + <delete file="${file}" /> + </target> + + <target name="setUp"> + <mkdir dir="${dir}" /> + + <echo file="${dir}/b" message="yyy" /> + <echo file="${dir}/e" message="aaa" /> + <sleep seconds="2" /> + <echo file="${dir}/c" message="x" /> + <echo file="${dir}/d" message="x" /> + <sleep seconds="2" /> + <echo file="${dir}/a" message="zz" /> + <echo file="${dir}/f" message="zz" /> + + <mkdir dir="${dir}/a.dir" /> + <mkdir dir="${dir}/b.dir" /> + <mkdir dir="${dir}/c.dir" /> + + <macrodef name="mysort"> + <attribute name="property" /> + <attribute name="separator" default="," /> + <element name="cmp" optional="true" implicit="true" /> + <sequential> + <pathconvert property="@{property}" pathsep="@{separator}"> + <sort> + <fileset dir="${dir}" includes="a,b,c" /> + <cmp /> + </sort> + <flattenmapper /> + </pathconvert> + <echo level="${echolevel}">@{property}=${@{property}}</echo> + </sequential> + </macrodef> + </target> + + <target name="testsortdefault" depends="setUp"> + <mysort property="sortdf" /> + <au:assertTrue> + <equals arg1="${sortdf}" arg2="a,b,c" /> + </au:assertTrue> + </target> + + <target name="testrvdefault" depends="setUp"> + <mysort property="sortdf-rev"> + <rcmp:reverse /> + </mysort> + <au:assertTrue> + <equals arg1="${sortdf-rev}" arg2="c,b,a" /> + </au:assertTrue> + </target> + + <target name="testname" depends="setUp"> + <mysort property="sortnm"> + <rcmp:name /> + </mysort> + <au:assertTrue> + <equals arg1="${sortnm}" arg2="a,b,c" /> + </au:assertTrue> + </target> + + <target name="testrvname" depends="setUp"> + <mysort property="sortnm-rev"> + <rcmp:reverse> + <rcmp:name /> + </rcmp:reverse> + </mysort> + <au:assertTrue> + <equals arg1="${sortnm-rev}" arg2="c,b,a" /> + </au:assertTrue> + </target> + + <target name="testdate" depends="setUp"> + <mysort property="sortlm"> + <rcmp:date /> + </mysort> + <au:assertTrue> + <equals arg1="${sortlm}" arg2="b,c,a" /> + </au:assertTrue> + </target> + + <target name="testrvdate" depends="setUp"> + <mysort property="sortlm-rev"> + <rcmp:reverse> + <rcmp:date /> + </rcmp:reverse> + </mysort> + <au:assertTrue> + <equals arg1="${sortlm-rev}" arg2="a,c,b" /> + </au:assertTrue> + </target> + + <target name="testsize" depends="setUp"> + <mysort property="sortsz"> + <rcmp:size /> + </mysort> + <au:assertTrue> + <equals arg1="${sortsz}" arg2="c,a,b" /> + </au:assertTrue> + </target> + + <target name="testrvsize" depends="setUp"> + <mysort property="sortsz-rev"> + <rcmp:reverse> + <rcmp:size /> + </rcmp:reverse> + </mysort> + <au:assertTrue> + <equals arg1="${sortsz-rev}" arg2="b,a,c" /> + </au:assertTrue> + </target> + + <target name="testcontent" depends="setUp"> + <mysort property="sortct"> + <rcmp:content /> + </mysort> + <au:assertTrue> + <equals arg1="${sortct}" arg2="c,b,a" /> + </au:assertTrue> + </target> + + <target name="testrvcontent" depends="setUp"> + <mysort property="sortct-rev"> + <rcmp:reverse> + <rcmp:content /> + </rcmp:reverse> + </mysort> + <au:assertTrue> + <equals arg1="${sortct-rev}" arg2="a,b,c" /> + </au:assertTrue> + </target> + + <target name="testexists" depends="setUp"> + <pathconvert property="sortex" pathsep=","> + <sort> + <resources> + <file file="${dir}/a" /> + <resource name="redherring" exists="false" /> + </resources> + <rcmp:exists /> + </sort> + <flattenmapper /> + </pathconvert> + <au:assertTrue> + <equals arg1="${sortex}" arg2="redherring,a" /> + </au:assertTrue> + </target> + + <target name="testrvexists" depends="setUp"> + <pathconvert property="sortex-rev" pathsep=","> + <sort> + <resources> + <file file="${dir}/a" /> + <resource name="redherring" exists="false" /> + </resources> + <rcmp:reverse> + <rcmp:exists /> + </rcmp:reverse> + </sort> + <flattenmapper /> + </pathconvert> + <au:assertTrue> + <equals arg1="${sortex-rev}" arg2="a,redherring" /> + </au:assertTrue> + </target> + + <target name="testtype" depends="setUp"> + <pathconvert property="sorttp" pathsep=","> + <sort> + <resources> + <file file="${dir}/a" /> + <file file="${dir}/a.dir" /> + </resources> + <rcmp:type /> + </sort> + <flattenmapper /> + </pathconvert> + <au:assertPropertyEquals name="sorttp" value="a,a.dir" /> + </target> + + <target name="testrvtype" depends="setUp"> + <pathconvert property="sorttp-rev" pathsep=","> + <sort> + <resources> + <file file="${dir}/a" /> + <file file="${dir}/a.dir" /> + </resources> + <rcmp:reverse> + <rcmp:type /> + </rcmp:reverse> + </sort> + <flattenmapper /> + </pathconvert> + <au:assertTrue> + <equals arg1="${sorttp-rev}" arg2="a.dir,a" /> + </au:assertTrue> + </target> + + <target name="forwardsort" + depends="testsortdefault,testname,testdate,testsize,testcontent,testexists,testtype" /> + + <target name="reversesort" + depends="testrvdefault,testrvname,testrvdate,testrvsize,testrvcontent,testrvexists,testrvtype" /> + + <target name="testcompoundsort1" depends="setUp"> + <pathconvert property="sortcmp1" pathsep=","> + <sort> + <resources> + <file file="${dir}/c" /> + <file file="${dir}/b.dir" /> + <file file="${dir}/a" /> + <file file="${dir}/c.dir" /> + <file file="${dir}/b" /> + <file file="${dir}/a.dir" /> + </resources> + <rcmp:reverse> + <rcmp:type /> + </rcmp:reverse> + <rcmp:name /> + </sort> + <flattenmapper /> + </pathconvert> + <au:assertPropertyEquals name="sortcmp1" value="a.dir,b.dir,c.dir,a,b,c" /> + </target> + + <target name="testcompoundsort2" depends="setUp"> + <pathconvert property="sortcmp2" pathsep=","> + <sort> + <fileset dir="${dir}" includes="?"/> + <rcmp:size /> + <rcmp:content /> + <rcmp:reverse> + <rcmp:name /> + </rcmp:reverse> + </sort> + <flattenmapper /> + </pathconvert> + <au:assertPropertyEquals name="sortcmp2" value="d,c,f,a,e,b" /> + </target> + + <target name="compoundsort" depends="testcompoundsort1,testcompoundsort2" /> + + <target name="sort" depends="forwardsort,reversesort,compoundsort" /> + + <target name="testEquals"> + <!-- test for PR 46527 --> + <sort id="testEquals"> + <resources> + <string>foo</string> + <string>foo</string> + <string>foo</string> + </resources> + </sort> + + <au:assertTrue> + <resourcecount refid="testEquals" count="3" /> + </au:assertTrue> + + <pathconvert refid="testEquals" property="testEquals" pathsep="" preserveduplicates="true"> + <mergemapper to="X" /> + </pathconvert> + + <au:assertTrue> + <length string="${testEquals}" length="3" /> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/concat-resource-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/concat-resource-test.xml new file mode 100644 index 00000000..554c13d2 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/concat-resource-test.xml @@ -0,0 +1,160 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<project name="test-concat" basedir="." default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../../antunit-base.xml" /> + + <property name="br" value="${line.separator}" /> + <property name="world" value="World" /> + + <target name="testCountEquals1"> + <au:assertTrue> + <resourcecount count="1"> + <concat>Hello, ${world}!</concat> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testReplacement"> + <au:assertTrue> + <resourcesmatch> + <string>Hello, ${world}!</string> + <concat>Hello, ${world}!</concat> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testResources"> + <au:assertTrue> + <resourcesmatch> + <string>foobarbaz</string> + <concat> + <string value="foo" /> + <string value="bar" /> + <string value="baz" /> + </concat> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testFixLastLineResources"> + <au:assertTrue> + <resourcesmatch> + <string>foo${line.separator}bar${line.separator}baz${line.separator}</string> + <concat fixlastline="true"> + <string value="foo" /> + <string value="bar" /> + <string value="baz" /> + </concat> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testEncoding"> + <mkdir dir="${output}"/> + <copy file="utf-16.in" toDir="${output}" encoding="utf-16"> + <filterchain> + <fixcrlf/> + </filterchain> + </copy> + <au:assertTrue> + <resourcesmatch astext="true"> + <file file="${output}/utf-16.in" /> + <concat outputEncoding="utf-16">foo${br}bar${br}baz${br}</concat> + <concat outputEncoding="utf-16" fixlastline="true"> + <string value="foo" /> + <string value="bar" /> + <string value="baz" /> + </concat> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testFiltering"> + <au:assertTrue> + <resourcesmatch astext="true"> + <concat>foo${br}bar${br}baz${br}</concat> + <concat> +foo +#comment 1 +bar +#comment 2 +baz +#comment 3 + <filterchain> + <striplinecomments> + <comment value="#" /> + </striplinecomments> + <ignoreblank /> + </filterchain> + </concat> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testReference"> + <resources id="concat"> + <concat>foo</concat> + </resources> + <au:assertTrue> + <and> + <resourcecount count="1" refid="concat" /> + <resourcesmatch> + <string>foo</string> + <resources refid="concat" /> + <!-- purposely hit it twice to see what happens --> + <resources refid="concat" /> + </resourcesmatch> + </and> + </au:assertTrue> + </target> + + <target name="testNonexistent"> + <au:assertTrue> + <resourcesmatch> + <string>foobar</string> + <concat> + <string>foo</string> + <propertyresource name="someunsetproperty" /> + <string>bar</string> + </concat> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testResourceName"> + <au:assertTrue> + <resourcecount count="1"> + <restrict> + <name name="snicklefritz" /> + <resources> + <concat resourceName="snicklefritz"> + whatever + </concat> + <concat> + whatever + </concat> + </resources> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/fileresource-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/fileresource-test.xml new file mode 100644 index 00000000..71141193 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/fileresource-test.xml @@ -0,0 +1,57 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../../antunit-base.xml" /> + + <!-- using restrict/exists to force getFile() to be called --> + + <target name="testFileAsBaseline"> + <au:assertTrue> + <resourcecount when="ge" count="0"> + <restrict> + <exists /> + <file name="foo" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testNameOnly"> + <au:assertTrue> + <resourcecount when="ge" count="0"> + <restrict> + <exists /> + <file name="foo" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testNameAndBasedir"> + <au:assertTrue> + <resourcecount when="ge" count="0"> + <restrict> + <exists /> + <file basedir="${basedir}" name="foo" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/files-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/files-test.xml new file mode 100644 index 00000000..447a2623 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/files-test.xml @@ -0,0 +1,52 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="files-test" default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <target name="antunit"> + <au:antunit> + <au:plainlistener/> + <file file="${ant.file}"/> + </au:antunit> + </target> + + <target name="setUp"> + <property name="out" value="out"/> + </target> + + <target name="tearDown"> + <delete dir="${out}"/> + </target> + + <target name="testEmptyReference" description="Bug43048"> + <files id="foo"/> + <mkdir dir="${out}"/> + <copy todir="${out}"> + <!-- threw a java.lang.NullPointerException --> + <files refid="foo"/> + </copy> + </target> + + <target name="testEmptyFiles" description="Bug43048"> + <mkdir dir="${out}"/> + <copy todir="${out}"> + <files/> + </copy> + </target> + + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/first-last-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/first-last-test.xml new file mode 100644 index 00000000..e7fc831b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/first-last-test.xml @@ -0,0 +1,280 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../../antunit-base.xml" /> + + <tokens id="testrc"> + <string value="1,2,3,4,5" /> + <stringtokenizer delims="," /> + </tokens> + + <target name="testfirst0"> + <au:assertTrue> + <resourcecount count="0"> + <first count="0"><resources refid="testrc" /></first> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testfirst1"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <first><resources refid="testrc" /></first> + <string value="1" /> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testfirst2"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <first count="2"><resources refid="testrc" /></first> + <resources> + <string value="1" /> + <string value="2" /> + </resources> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testfirst5"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <first count="5"><resources refid="testrc" /></first> + <resources refid="testrc" /> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testfirst6"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <first count="6"><resources refid="testrc" /></first> + <resources refid="testrc" /> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testfirst-1"> + <au:expectfailure expectedmessage="size-limited collection count should be set to an int >= 0"> + <resourcecount> + <first count="-1"><resources refid="testrc" /></first> + </resourcecount> + </au:expectfailure> + </target> + + <target name="testlast0"> + <au:assertTrue> + <resourcecount count="0"> + <last count="0"><resources refid="testrc" /></last> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testlast1"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <last><resources refid="testrc" /></last> + <string value="5" /> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testlast2"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <last count="2"><resources refid="testrc" /></last> + <resources> + <string value="4" /> + <string value="5" /> + </resources> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testlast5"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <last count="5"><resources refid="testrc" /></last> + <resources refid="testrc" /> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testlast6"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <last count="6"><resources refid="testrc" /></last> + <resources refid="testrc" /> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testlast-1"> + <au:expectfailure expectedmessage="size-limited collection count should be set to an int >= 0"> + <resourcecount> + <last count="-1"><resources refid="testrc" /></last> + </resourcecount> + </au:expectfailure> + </target> + + <target name="testallbutfirst5"> + <au:assertTrue> + <resourcecount count="0"> + <allbutfirst count="5"><resources refid="testrc" /></allbutfirst> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testallbutfirst4"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <allbutfirst count="4"><resources refid="testrc" /></allbutfirst> + <string value="5" /> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testallbutfirst3"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <allbutfirst count="3"><resources refid="testrc" /></allbutfirst> + <resources> + <string value="4" /> + <string value="5" /> + </resources> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testallbutfirst"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <allbutfirst><resources refid="testrc" /></allbutfirst> + <resources> + <string value="2" /> + <string value="3" /> + <string value="4" /> + <string value="5" /> + </resources> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testallbutfirst6"> + <au:assertTrue> + <resourcecount count="0"> + <allbutfirst count="6"><resources refid="testrc" /></allbutfirst> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testallbutfirst-1"> + <au:expectfailure expectedmessage="size-limited collection count should be set to an int >= 0"> + <resourcecount> + <allbutfirst count="-1"><resources refid="testrc" /></allbutfirst> + </resourcecount> + </au:expectfailure> + </target> + + <target name="testallbutlast5"> + <au:assertTrue> + <resourcecount count="0"> + <allbutlast count="5"><resources refid="testrc" /></allbutlast> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testallbutlast4"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <allbutlast count="4"><resources refid="testrc" /></allbutlast> + <string value="1" /> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testallbutlast1"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <allbutlast><resources refid="testrc" /></allbutlast> + <resources> + <string value="1" /> + <string value="2" /> + <string value="3" /> + <string value="4" /> + </resources> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testallbutlast0"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <allbutlast count="0"><resources refid="testrc" /></allbutlast> + <resources refid="testrc" /> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testallbutlast6"> + <au:assertTrue> + <resourcecount count="0"> + <allbutlast count="6"><resources refid="testrc" /></allbutlast> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testallbutlast-1"> + <au:expectfailure expectedmessage="size-limited collection count should be set to an int >= 0"> + <resourcecount> + <allbutlast count="-1"><resources refid="testrc" /></allbutlast> + </resourcecount> + </au:expectfailure> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/javaresource-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/javaresource-test.xml new file mode 100644 index 00000000..a83184d0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/javaresource-test.xml @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../../antunit-base.xml"/> + + <target name="setUp"> + <mkdir dir="${output}"/> + </target> + + <target name="testUsesSystemClasspath" depends="setUp"> + <copy todir="${output}"> + <javaresource name="org/apache/tools/ant/antlib.xml"/> + </copy> + <au:assertFileExists file="${output}/org/apache/tools/ant/antlib.xml"/> + </target> + + <target name="-setUpAntlibXmlInInput" depends="setUp"> + <mkdir dir="${input}/org/apache/tools/ant"/> + <echo file="${input}/org/apache/tools/ant/antlib.xml">Hello, world!</echo> + </target> + + <target name="testParentFirstIsDefault" depends="-setUpAntlibXmlInInput"> + <copy todir="${output}"> + <javaresource name="org/apache/tools/ant/antlib.xml"> + <classpath location="${input}"/> + </javaresource> + </copy> + <au:assertFileExists file="${output}/org/apache/tools/ant/antlib.xml"/> + <au:assertFilesDiffer + expected="${input}/org/apache/tools/ant/antlib.xml" + actual="${output}/org/apache/tools/ant/antlib.xml"/> + </target> + + <target name="testParentFirstFalse" depends="-setUpAntlibXmlInInput" unless="build.sysclasspath.only"> + <copy todir="${output}"> + <javaresource name="org/apache/tools/ant/antlib.xml" + parentFirst="false"> + <classpath location="${input}"/> + </javaresource> + </copy> + <au:assertFileExists file="${output}/org/apache/tools/ant/antlib.xml"/> + <au:assertFilesMatch + expected="${input}/org/apache/tools/ant/antlib.xml" + actual="${output}/org/apache/tools/ant/antlib.xml"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/latepath-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/latepath-test.xml new file mode 100644 index 00000000..5cafffde --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/latepath-test.xml @@ -0,0 +1,34 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit"> + + <target name="testLatePath" depends="tearDown"> + <path id="p"> + <fileset file="testLatePath" /> + </path> + <pathconvert refid="p" /> + <touch file="testLatePath" /> + <au:assertTrue> + <resourcecount when="eq" count="1" refid="p" /> + </au:assertTrue> + </target> + + <target name="tearDown"> + <delete file="testLatePath" /> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/multirootfileset-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/multirootfileset-test.xml new file mode 100644 index 00000000..27b6193e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/multirootfileset-test.xml @@ -0,0 +1,166 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../../antunit-base.xml"/> + + <target name="setUp"> + <property name="a" location="${input}/a"/> + <property name="b" location="${input}/b"/> + <touch mkdirs="true" file="${a}/1/1.txt"/> + <touch mkdirs="true" file="${a}/1/2.txt"/> + <touch mkdirs="true" file="${a}/1/3.txt"/> + <touch mkdirs="true" file="${b}/2/3.txt"/> + <touch mkdirs="true" file="${b}/2/4.txt"/> + <mkdir dir="${output}"/> + </target> + + <target name="test-count-in-simple-configuration" depends="setUp"> + <resourcecount property="files"> + <multirootfileset basedirs="${a},${b}"/> + </resourcecount> + <resourcecount property="dirs"> + <multirootfileset basedirs="${a},${b}" type="dir"/> + </resourcecount> + <resourcecount property="files-and-dirs"> + <multirootfileset basedirs="${a},${b}" type="both"/> + </resourcecount> + <au:assertPropertyEquals value="5" name="files"/> + <au:assertPropertyEquals value="4" name="dirs"/> + <au:assertPropertyEquals value="9" name="files-and-dirs"/> + </target> + + <target name="test-count-nested-basedir-elements" depends="setUp"> + <resourcecount property="files"> + <multirootfileset> + <basedir file="${a}"/> + <basedir file="${b}"/> + </multirootfileset> + </resourcecount> + <resourcecount property="dirs"> + <multirootfileset type="dir"> + <basedir file="${a}"/> + <basedir file="${b}"/> + </multirootfileset> + </resourcecount> + <resourcecount property="files-and-dirs"> + <multirootfileset type="both"> + <basedir file="${a}"/> + <basedir file="${b}"/> + </multirootfileset> + </resourcecount> + <au:assertPropertyEquals value="5" name="files"/> + <au:assertPropertyEquals value="4" name="dirs"/> + <au:assertPropertyEquals value="9" name="files-and-dirs"/> + </target> + + <target name="test-copying" depends="setUp"> + <copy todir="${output}"> + <multirootfileset basedirs="${a},${b}"/> + </copy> + <au:assertFileExists file="${output}/1/1.txt"/> + <au:assertFileExists file="${output}/1/2.txt"/> + <au:assertFileExists file="${output}/1/3.txt"/> + <au:assertFileExists file="${output}/2/3.txt"/> + <au:assertFileExists file="${output}/2/4.txt"/> + </target> + + <target name="test-dirs" depends="setUp"> + <pathconvert property="dirs" pathsep=":"> + <multirootfileset basedirs="${a},${b}" type="dir"/> + </pathconvert> + <au:assertPropertyEquals value="${a}:${a}${file.separator}1:${b}:${b}${file.separator}2" + name="dirs"/> + </target> + + <target name="test-include-pattern" depends="setUp"> + <copy todir="${output}"> + <multirootfileset basedirs="${a},${b}"> + <include name="**/3.txt"/> + </multirootfileset> + </copy> + <au:assertFileDoesntExist file="${output}/1/1.txt"/> + <au:assertFileExists file="${output}/1/3.txt"/> + <au:assertFileExists file="${output}/2/3.txt"/> + <au:assertFileDoesntExist file="${output}/2/4.txt"/> + <pathconvert property="dirs" pathsep=":"> + <multirootfileset basedirs="${a},${b}" type="dir"> + <include name="1/"/> + </multirootfileset> + </pathconvert> + <au:assertPropertyEquals value="${a}${file.separator}1" name="dirs"/> + </target> + + <target name="test-exclude-pattern" depends="setUp"> + <copy todir="${output}"> + <multirootfileset basedirs="${a},${b}"> + <exclude name="**/3.txt"/> + </multirootfileset> + </copy> + <au:assertFileExists file="${output}/1/1.txt"/> + <au:assertFileDoesntExist file="${output}/1/3.txt"/> + <au:assertFileDoesntExist file="${output}/2/3.txt"/> + <au:assertFileExists file="${output}/2/4.txt"/> + <pathconvert property="dirs" pathsep=":"> + <multirootfileset basedirs="${a},${b}" type="dir"> + <exclude name="1/"/> + </multirootfileset> + </pathconvert> + <au:assertPropertyEquals value="${a}:${b}:${b}${file.separator}2" + name="dirs"/> + </target> + + <target name="test-selectors" depends="setUp"> + <copy todir="${output}"> + <multirootfileset basedirs="${a},${b}"> + <filename regex=".*3\.txt"/> + </multirootfileset> + </copy> + <au:assertFileDoesntExist file="${output}/1/1.txt"/> + <au:assertFileExists file="${output}/1/3.txt"/> + <au:assertFileExists file="${output}/2/3.txt"/> + <au:assertFileDoesntExist file="${output}/2/4.txt"/> + <pathconvert property="dirs" pathsep=":"> + <multirootfileset basedirs="${a},${b}" type="dir"> + <filename regex="1"/> + </multirootfileset> + </pathconvert> + <au:assertPropertyEquals value="${a}${file.separator}1" name="dirs"/> + </target> + + <target name="test-cache-false" depends="setUp"> + <copy todir="${output}"> + <multirootfileset basedirs="${a},${b}" cache="false"> + <filename regex=".*3\.txt"/> + </multirootfileset> + </copy> + <au:assertFileDoesntExist file="${output}/1/1.txt"/> + <au:assertFileExists file="${output}/1/3.txt"/> + <au:assertFileExists file="${output}/2/3.txt"/> + <au:assertFileDoesntExist file="${output}/2/4.txt"/> + <multirootfileset basedirs="${a},${b}" type="dir" cache="false" + id="the-one-dirs"> + <filename regex="1"/> + </multirootfileset> + <pathconvert property="dirs" pathsep=":" refid="the-one-dirs"/> + <au:assertPropertyEquals value="${a}${file.separator}1" name="dirs"/> + <resourcecount property="dir-count" refid="the-one-dirs" /> + <au:assertPropertyEquals value="1" name="dir-count"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/resourcelist-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/resourcelist-test.xml new file mode 100644 index 00000000..33577476 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/resourcelist-test.xml @@ -0,0 +1,104 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> + +<project name="test-concat" basedir="." default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}"/> + <mkdir dir="${output}"/> + <touch file="${input}/b.txt"/> + </target> + + <target name="testBasicOperation" depends="setUp"> + <echo file="${input}/a.txt">${input}/b.txt +${input}/c.txt</echo> + <property name="c" location="${input}/c.txt"/> + <au:expectfailure expectedmessage="Could not find resource file "${c}""> + <copy todir="${output}" flatten="true"> + <resourcelist> + <file file="${input}/a.txt"/> + </resourcelist> + </copy> + </au:expectfailure> + <copy todir="${output}" flatten="true"> + <restrict> + <resourcelist> + <file file="${input}/a.txt"/> + </resourcelist> + <exists/> + </restrict> + </copy> + <au:assertFileExists file="${output}/b.txt"/> + <au:assertFileDoesntExist file="${output}/c.txt"/> + </target> + + <target name="testExpandsProperties" depends="setUp"> + <echo file="${input}/a.txt">$${input}/b.txt</echo> + <copy todir="${output}" flatten="true"> + <resourcelist> + <file file="${input}/a.txt"/> + </resourcelist> + </copy> + <au:assertFileExists file="${output}/b.txt"/> + </target> + + <target name="testFilterChain" depends="setUp"> + <echo file="${input}/a.txt">b.txt</echo> + <au:expectfailure expectedmessage="Could not find resource file"> + <copy todir="${output}" flatten="true"> + <resourcelist> + <file file="${input}/a.txt"/> + </resourcelist> + </copy> + </au:expectfailure> + <copy todir="${output}" flatten="true"> + <resourcelist> + <file file="${input}/a.txt"/> + <filterchain> + <prefixlines prefix="${input}/"/> + </filterchain> + </resourcelist> + </copy> + <au:assertFileExists file="${output}/b.txt"/> + </target> + + <target name="testPropertyExpandsToObject" depends="setUp"> + <file file="${ant.file}" id="self"/> + <echo file="${input}/a.txt">$${ant.refid:self}</echo> + <copy todir="${output}" flatten="true"> + <resourcelist> + <file file="${input}/a.txt"/> + </resourcelist> + </copy> + <au:assertFileExists file="${output}/resourcelist-test.xml"/> + </target> + + <target name="testReadsURLs" depends="setUp"> + <makeurl file="${ant.core.lib}" property="ant.jar"/> + <echo file="${input}/a.txt">jar:${ant.jar}!/org/apache/tools/ant/antlib.xml</echo> + <copy todir="${output}" flatten="true"> + <resourcelist> + <file file="${input}/a.txt"/> + </resourcelist> + </copy> + <au:assertFileExists file="${output}/antlib.xml"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/resources-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/resources-test.xml new file mode 100644 index 00000000..19985c72 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/resources-test.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../../antunit-base.xml"/> + + <target name="testToString" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=49588"> + <resources id="A"> + <string value="b"/> + </resources> + <union id="union"><resources refid="A"/></union> + <au:assertEquals expected="b" actual="${toString:A}"/> + <au:assertEquals expected="b" actual="${toString:union}"/> + <au:assertEquals expected="b" actual="${toString:A}"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/selectors/name-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/selectors/name-test.xml new file mode 100644 index 00000000..84cbedb4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/selectors/name-test.xml @@ -0,0 +1,90 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../../../antunit-base.xml" /> + + <property name="file" value="testfile"/> + + <target name="createTestdir"> + <mkdir dir="${output}"/> + <touch file="${output}/${file}"/> + </target> + + <target name="testPattern" depends="createTestdir"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <fileset dir="${output}"/> + <name name="*"/> + </restrict> + </resourcecount> + </au:assertTrue> + <au:assertTrue> + <resourcecount when="equal" count="0"> + <restrict> + <fileset dir="${output}"/> + <name name=".*"/> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testRegex" depends="createTestdir"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <fileset dir="${output}"/> + <name regex=".*"/> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testHandledirSep" depends="createTestdir"> + <au:assertTrue> + <!-- only one should match the current platform --> + <resourcecount when="equal" count="1"> + <resources> + <restrict> + <fileset dir="${output}"/> + <name name="**/${file}"/> + </restrict> + <restrict> + <fileset dir="${output}"/> + <name name="**\${file}"/> + </restrict> + </resources> + </resourcecount> + </au:assertTrue> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <resources> + <restrict> + <fileset dir="${output}"/> + <name name="**/${file}" handleDirSep="true"/> + </restrict> + <restrict> + <fileset dir="${output}"/> + <name name="**\${file}" handleDirSep="true"/> + </restrict> + </resources> + </resourcecount> + </au:assertTrue> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/selectors/readwrite-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/selectors/readwrite-test.xml new file mode 100644 index 00000000..6a0301ba --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/selectors/readwrite-test.xml @@ -0,0 +1,106 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit" + xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors"> + + <import file="../../../antunit-base.xml" /> + + <property name="dir" location="testdir"/> + <property name="file" value="testfile"/> + + <condition property="unix"> + <os family="unix"/> + </condition> + + <target name="createTestdir"> + <mkdir dir="${output}"/> + <touch file="${output}/${file}"/> + </target> + + <target name="testReadable" depends="createTestdir"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <fileset dir="${output}"/> + <rsel:readable/> + </restrict> + </resourcecount> + </au:assertTrue> + <au:assertTrue> + <resourcecount when="equal" count="0"> + <restrict> + <fileset dir="${output}" excludes="${file}"/> + <rsel:readable/> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testWritable" depends="createTestdir"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <fileset dir="${output}"/> + <rsel:writable/> + </restrict> + </resourcecount> + </au:assertTrue> + <au:assertTrue> + <resourcecount when="equal" count="0"> + <restrict> + <fileset dir="${output}" excludes="${file}"/> + <rsel:writable/> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="makeFileUnwritable" + depends="createTestdir,makeFileUnwritable-Unix,makeFileUnwritable-Windows"/> + <target name="makeFileUnwritable-Unix" id="unix"> + <chmod file="${output}/${file}" perm="444"/> + </target> + <target name="makeFileUnwritable-Windows" unless="unix"> + <attrib file="${output}/${file}" readonly="true"/> + </target> + + <target name="testUnwritable" depends="makeFileUnwritable"> + <au:assertTrue> + <resourcecount when="equal" count="0"> + <restrict> + <fileset dir="${output}"/> + <rsel:writable/> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testAsConditions" depends="makeFileUnwritable"> + <au:assertTrue> + <isfileselected file="${output}/${file}"> + <rsel:readable/> + </isfileselected> + </au:assertTrue> + <au:assertFalse> + <isfileselected file="${output}/${file}"> + <rsel:writable/> + </isfileselected> + </au:assertFalse> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/selectors/test-componentdef.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/selectors/test-componentdef.xml new file mode 100644 index 00000000..187412ec --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/selectors/test-componentdef.xml @@ -0,0 +1,458 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="all" xmlns:au="antlib:org.apache.ant.antunit"> + + <available property="jdk1.4+" classname="java.lang.CharSequence"/> + <condition property="some.regexp.support"> + <or> + <isset property="jdk1.4+"/> + <isset property="apache.regexp.present"/> + <isset property="apache.oro.present"/> + </or> + </condition> + + <target name="testname1"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <resource name="foo" /> + <resource name="bar" /> + <resource name="baz" /> + <resource name="boo" /> + <resource name="bang" /> + </resources> + <name name="ba?" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testname2"> + <au:assertTrue> + <resourcecount when="equal" count="3"> + <restrict> + <resources> + <file file="foo" /> + <resource name="foo" /> + <file file="foo" basedir="${basedir}" /> + </resources> + <name name="foo" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="name" depends="testname1,testname2" /> + + <target name="testexists"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <resources> + <file file="idonotexist" /> + <resource name="foo" /> + <resource name="foo" exists="false" /> + </resources> + <exists /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testinstanceoftype1"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <file file="foo" /> + <url url="http://ant.apache.org/index.html" /> + <resource name="foo" /> + <string value="foo" /> + <file file="bar" /> + </resources> + <instanceof type="file" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testinstanceoftype2"> + <typedef name="file" uri="test" + classname="org.apache.tools.ant.types.resources.FileResource" /> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <resources> + <url file="foo" /> + <file file="bar" xmlns="test" /> + </resources> + <instanceof type="test:file" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testinstanceoftype3"> + <typedef name="file" uri="test" + classname="org.apache.tools.ant.types.resources.FileResource" /> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <resources> + <url file="foo" /> + <file file="bar" xmlns="test" /> + </resources> + <instanceof type="file" uri="test" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="instanceoftype" + depends="testinstanceoftype1,testinstanceoftype2,testinstanceoftype3" /> + + <target name="testinstanceofclass"> + <au:assertTrue> + <resourcecount when="equal" count="7"> + <restrict> + <resources> + <filelist dir="${basedir}" files="a,b,c,d,e,f,g" /> + </resources> + <instanceof class="org.apache.tools.ant.types.Resource" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="instanceof" depends="instanceoftype,testinstanceofclass" /> + + <target name="testtype"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <file file="${basedir}" /> + <file file="${ant.file}" /> + <resource directory="true" /> + <resource directory="false" /> + </resources> + <type type="dir" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testdate"> + <au:assertTrue> + <resourcecount when="equal" count="3"> + <restrict> + <resources> + <resource lastmodified="4" /> + <resource lastmodified="5" /> + <resource lastmodified="6" /> + <resource lastmodified="7" /> + <resource lastmodified="8" /> + </resources> + <date when="after" millis="5" granularity="0" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testsize"> + <au:assertTrue> + <resourcecount when="equal" count="4"> + <restrict> + <resources> + <resource size="4" /> + <resource size="5" /> + <resource size="6" /> + <resource size="7" /> + <resource size="8" /> + </resources> + <size when="le" size="7" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testand"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <and xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <name name="f?" /> + <size size="3" /> + </and> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testor"> + <au:assertTrue> + <resourcecount when="equal" count="3"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <or xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <name name="f?" /> + <size size="3" /> + </or> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testnot"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <not xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <size size="3" /> + </not> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testnone"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <none xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <name name="f?" /> + <size size="3" /> + </none> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testmajority1"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <majority xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <name name="f?" /> + <size size="3" /> + <instanceof type="string" /> + </majority> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testmajority2"> + <au:assertTrue> + <resourcecount when="equal" count="3"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <majority> + <name name="f?" /> + <size size="3" /> + <instanceof type="resource" /> + </majority> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testmajority3"> + <au:assertTrue> + <resourcecount when="equal" count="3"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <majority allowtie="true"> + <name name="f?" /> + <size size="3" /> + <instanceof type="string" /> + <exists /> + </majority> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testmajority4"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <majority allowtie="false"> + <name name="f?" /> + <size size="3" /> + <instanceof type="string" /> + <exists /> + </majority> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testcontains"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <string value="foo" /> + <string value="bar" /> + <string value="baz" /> + </resources> + <contains text="b"/> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testcontainsregexp" if="some.regexp.support"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <string value="foo" /> + <string value="bar" /> + <string value="baz" /> + </resources> + <containsregexp expression="^b..$"/> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testcompare"> + <au:assertTrue> + <and> + <!-- basic test, natural ordering --> + <resourcecount count="3"> + <restrict> + <compare when="greater" against="each"> + <control><string value="b" /></control> + </compare> + <resources> + <string value="a" /> + <string value="b" /> + <string value="c" /> + <string value="d" /> + <string value="e" /> + </resources> + </restrict> + </resourcecount> + <!-- one comparator, default when/against --> + <resourcecount count="5"> + <restrict> + <compare> + <control><string value="." /></control> + <size /> + </compare> + <resources> + <string value="a" /> + <string value="b" /> + <string value="c" /> + <string value="d" /> + <string value="e" /> + </resources> + </restrict> + </resourcecount> + <!-- multiple controls, comparators --> + <resourcecount count="3"> + <restrict> + <compare when="greater" against="each"> + <control> + <string value="a" /> + <string value="b" /> + <string value="bb" /> + <string value="c" /> + <string value="ccc" /> + </control> + <name /> + <size /> + </compare> + <resources> + <string value="a" /> + <string value="bbbb" /> + <string value="ccc" /> + <string value="cccc" /> + <string value="d" /> + <string value="e" /> + </resources> + </restrict> + </resourcecount> + </and> + </au:assertTrue> + </target> + + <target name="majority" + depends="testmajority1,testmajority2,testmajority3,testmajority4" /> + + <target name="logical" + depends="testand,testor,testnone,testnot,majority" /> + + <target name="all" + depends="name,testexists,instanceof,testtype,testdate,testsize,testcontains,testcontainsregexp,logical,testcompare" /> + + <!-- + The tests for oata.types.selectors.ModifiedSelectorTest as + ResourceSelector are in its test-buildfile src\etc\testcases\types\selectors.xml. + --> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/selectors/test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/selectors/test.xml new file mode 100644 index 00000000..24b804a3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/selectors/test.xml @@ -0,0 +1,483 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit" + xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors" + xmlns:rcmp="antlib:org.apache.tools.ant.types.resources.comparators"> + + <import file="../../../antunit-base.xml" /> + + <available property="jdk1.4+" classname="java.lang.CharSequence"/> + <condition property="some.regexp.support"> + <or> + <isset property="jdk1.4+"/> + <isset property="apache.regexp.present"/> + <isset property="apache.oro.present"/> + </or> + </condition> + + <target name="testname1"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <resource name="foo" /> + <resource name="bar" /> + <resource name="baz" /> + <resource name="boo" /> + <resource name="bang" /> + </resources> + <rsel:name name="ba?" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testname2"> + <au:assertTrue> + <resourcecount when="equal" count="3"> + <restrict> + <resources> + <file file="foo" /> + <resource name="foo" /> + <file file="foo" basedir="${basedir}" /> + </resources> + <rsel:name name="foo" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="name" depends="testname1,testname2" /> + + <target name="testexists"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <resources> + <file file="idonotexist" /> + <resource name="foo" /> + <resource name="foo" exists="false" /> + </resources> + <rsel:exists /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testinstanceoftype1"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <file file="foo" /> + <url url="http://ant.apache.org/index.html" /> + <resource name="foo" /> + <string value="foo" /> + <file file="bar" /> + </resources> + <rsel:instanceof type="file" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testinstanceoftype2"> + <typedef name="file" uri="test" + classname="org.apache.tools.ant.types.resources.FileResource" /> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <resources> + <url file="foo" /> + <file file="bar" xmlns="test" /> + </resources> + <rsel:instanceof type="test:file" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testinstanceoftype3"> + <typedef name="file" uri="test" + classname="org.apache.tools.ant.types.resources.FileResource" /> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <resources> + <url file="foo" /> + <file file="bar" xmlns="test" /> + </resources> + <rsel:instanceof type="file" uri="test" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="instanceoftype" + depends="testinstanceoftype1,testinstanceoftype2,testinstanceoftype3" /> + + <target name="testinstanceofclass"> + <au:assertTrue> + <resourcecount when="equal" count="7"> + <restrict> + <resources> + <filelist dir="${basedir}" files="a,b,c,d,e,f,g" /> + </resources> + <rsel:instanceof class="org.apache.tools.ant.types.Resource" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="instanceof" depends="instanceoftype,testinstanceofclass" /> + + <target name="testtype"> + <resources id="testtype"> + <file file="${basedir}" /> + <file file="${ant.file}" /> + <resource directory="true" /> + <resource directory="false" /> + </resources> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources refid="testtype" /> + <rsel:type type="dir" /> + </restrict> + </resourcecount> + </au:assertTrue> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources refid="testtype" /> + <rsel:type type="file" /> + </restrict> + </resourcecount> + </au:assertTrue> + <au:assertTrue> + <resourcecount when="equal" count="4"> + <restrict> + <resources refid="testtype" /> + <rsel:type type="any" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testdate"> + <au:assertTrue> + <resourcecount when="equal" count="3"> + <restrict> + <resources> + <resource lastmodified="4" /> + <resource lastmodified="5" /> + <resource lastmodified="6" /> + <resource lastmodified="7" /> + <resource lastmodified="8" /> + </resources> + <rsel:date when="after" millis="5" granularity="0" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testsize"> + <au:assertTrue> + <resourcecount when="equal" count="4"> + <restrict> + <resources> + <resource size="4" /> + <resource size="5" /> + <resource size="6" /> + <resource size="7" /> + <resource size="8" /> + </resources> + <rsel:size when="le" size="7" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testand"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <and xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <name name="f?" /> + <size size="3" /> + </and> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testor"> + <au:assertTrue> + <resourcecount when="equal" count="3"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <or xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <name name="f?" /> + <size size="3" /> + </or> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testnot"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <not xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <size size="3" /> + </not> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testnone"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <none xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <name name="f?" /> + <size size="3" /> + </none> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testmajority1"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <majority xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <name name="f?" /> + <size size="3" /> + <instanceof type="string" /> + </majority> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testmajority2"> + <au:assertTrue> + <resourcecount when="equal" count="3"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <majority xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <name name="f?" /> + <size size="3" /> + <instanceof type="resource" /> + </majority> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testmajority3"> + <au:assertTrue> + <resourcecount when="equal" count="3"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <majority allowtie="true" + xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <name name="f?" /> + <size size="3" /> + <instanceof type="string" /> + <exists /> + </majority> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testmajority4"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <string value="fee" /> + <resource name="fi" size="3" /> + <resource name="fo" /> + <resource name="fum" /> + </resources> + <majority allowtie="false" + xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> + <name name="f?" /> + <size size="3" /> + <instanceof type="string" /> + <exists /> + </majority> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testcontains"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <string value="foo" /> + <string value="bar" /> + <string value="baz" /> + </resources> + <contains text="b" + xmlns="antlib:org.apache.tools.ant.types.resources.selectors" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testcontainsregexp" if="some.regexp.support"> + <au:assertTrue> + <resourcecount when="equal" count="2"> + <restrict> + <resources> + <string value="foo" /> + <string value="bar" /> + <string value="baz" /> + </resources> + <containsregexp expression="^b..$" + xmlns="antlib:org.apache.tools.ant.types.resources.selectors" /> + </restrict> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testcompare"> + <au:assertTrue> + <and> + <!-- basic test, natural ordering --> + <resourcecount count="3"> + <restrict> + <rsel:compare when="greater" against="each"> + <control><string value="b" /></control> + </rsel:compare> + <resources> + <string value="a" /> + <string value="b" /> + <string value="c" /> + <string value="d" /> + <string value="e" /> + </resources> + </restrict> + </resourcecount> + <!-- one comparator, default when/against --> + <resourcecount count="5"> + <restrict> + <rsel:compare> + <control><string value="." /></control> + <rcmp:size /> + </rsel:compare> + <resources> + <string value="a" /> + <string value="b" /> + <string value="c" /> + <string value="d" /> + <string value="e" /> + </resources> + </restrict> + </resourcecount> + <!-- multiple controls, comparators --> + <resourcecount count="3"> + <restrict> + <rsel:compare when="greater" against="each"> + <control> + <string value="a" /> + <string value="b" /> + <string value="bb" /> + <string value="c" /> + <string value="ccc" /> + </control> + <rcmp:name /> + <rcmp:size /> + </rsel:compare> + <resources> + <string value="a" /> + <string value="bbbb" /> + <string value="ccc" /> + <string value="cccc" /> + <string value="d" /> + <string value="e" /> + </resources> + </restrict> + </resourcecount> + </and> + </au:assertTrue> + </target> + + <target name="majority" + depends="testmajority1,testmajority2,testmajority3,testmajority4" /> + + <target name="logical" + depends="testand,testor,testnone,testnot,majority" /> + + <target name="all" + depends="name,testexists,instanceof,testtype,testdate,testsize,testcontains,testcontainsregexp,logical,testcompare" /> + + <!-- + The tests for oata.types.selectors.ModifiedSelectorTest as + ResourceSelector are in its test-buildfile src\etc\testcases\types\selectors.xml. + --> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/test.xml new file mode 100644 index 00000000..5af37b9a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/test.xml @@ -0,0 +1,460 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project default="antunit" xmlns:au="antlib:org.apache.ant.antunit"> + + <import file="../../antunit-base.xml" /> + + <property name="dirname" value="work" /> + <property name="dir" location="${output}/${dirname}" /> + <property name="zip" location="${output}/${dirname}.zip" /> + <property name="jar" location="${antunit.tmpdir}/${dirname}.jar" /> + <property name="file" location="${output}/${dirname}/file.txt" /> + + <condition property="offline"> + <not> + <or> + <http url="http://www.apache.org"/> + <http url="http://www.google.com"/> + </or> + </not> + </condition> + + <target name="setUp"> + + <touch mkdirs="true"> + <filelist dir="${dir}/foo/a" files="x,y,z" /> + </touch> + + <copy todir="${dir}/foo" enablemultiplemappings="true"> + <fileset dir="${dir}/foo" /> + <mapper> + <globmapper handledirsep="true" from="a/*" to="b/*" /> + <globmapper handledirsep="true" from="a/*" to="c/*" /> + </mapper> + </copy> + + <copy todir="${dir}/bar"> + <fileset dir="${dir}/foo" /> + </copy> + + <property name="foo" location="${dir}/foo" /> + <property name="foo.a" location="${dir}/foo/a" /> + <property name="foo.b" location="${dir}/foo/b" /> + <property name="foo.c" location="${dir}/foo/c" /> + + <property name="bar" location="${dir}/bar" /> + <property name="bar.a" location="${dir}/bar/a" /> + <property name="bar.b" location="${dir}/bar/b" /> + <property name="bar.c" location="${dir}/bar/c" /> + </target> + + <target name="tearDown"> + <delete dir="${dir}" /> + <delete file="${zip}" /> + <delete file="${jar}" deleteonexit="true" /> + <delete file="${file}" /> + </target> + + <target name="testfiles1" depends="setUp"> + <au:assertTrue> + <resourcecount count="26"> + <files> + <include name="${dir}/foo/" /> + <include name="${dir}/bar/" /> + </files> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testfiles2" depends="setUp"> + <au:assertTrue> + <resourcecount count="8"> + <files> + <include name="${dir}/foo/" /> + <include name="${dir}/bar/" /> + <type type="dir" /> + </files> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testfiles3" depends="setUp"> + <au:assertTrue> + <resourcecount count="18"> + <files> + <include name="${dir}/foo/" /> + <include name="${dir}/bar/" /> + <type type="file" /> + </files> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testnestedresources" depends="setUp"> + <au:assertTrue> + <resourcecount count="27"><!-- include duplicates! --> + <resources> + <files> + <include name="${dir}/foo/" /> + <include name="${dir}/bar/" /> + <type type="file" /> + </files> + <files> + <include name="${dir}/foo/" /> + <type type="file" /> + </files> + </resources> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testresourcesref" depends="setUp"> + <files id="files"> + <include name="${dir}/foo/" /> + <include name="${dir}/bar/" /> + <type type="file" /> + </files> + <au:assertTrue> + <resourcecount count="18"> + <resources refid="files" /> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testfileset" depends="setUp"> + <au:assertTrue> + <resourcecount count="9"> + <fileset dir="${dir}/foo" /> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testdirset" depends="setUp"> + <au:assertTrue> + <resourcecount count="4"> + <dirset dir="${dir}/foo" /> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testfilelist"> + <au:assertTrue> + <resourcecount count="5"> + <filelist dir="${dir}/foo" files="1,2,3,4,5" /> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testpath" depends="setUp"> + <au:assertTrue> + <resourcecount count="24"> + <path> + <path id="p"> + <fileset id="fs" dir="${foo.a}" /> <!-- 3 --> + <dirset id="ds" dir="${foo}" /> <!-- 4 --> + </path> + <pathelement id="pe" location="${dir}" /> <!-- 1 --> + <filelist id="fl" dir="${bar}" files="1,2,3,a,b,c" /> <!-- 6 --> + <files id="f"> <!-- 13; 3 overlap fl --> + <include name="${bar}/"/> + </files> + </path> + </resourcecount> + </au:assertTrue> + </target> + + <target name="createzip" depends="setUp"> + <zip destfile="${zip}" basedir="${dir}" /> + </target> + + <target name="testzipfileset" depends="createzip"> + <au:assertTrue> + <resourcecount count="9"> + <zipfileset src="${zip}" includes="foo/" /> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testpropertyset"> + <property name="testpropertyset.a" value="a" /> + <property name="testpropertyset.aa" value="aa" /> + <property name="testpropertyset.aaa" value="aaa" /> + <propertyset id="testpropertyset"> + <propertyref prefix="testpropertyset." /> + </propertyset> + <au:assertTrue> + <and> + <resourcecount refid="testpropertyset" count="3" /> + <length length="12"> + <resources> + <resources refid="testpropertyset" /> + <propertyset refid="testpropertyset" /> + </resources> + </length> + </and> + </au:assertTrue> + </target> + + <target name="testunion" depends="setUp"> + <au:assertTrue> + <resourcecount count="4"> + <union> + <files> <!-- 1 --> + <include name="${foo.a}/w"/> + <include name="${foo.a}/x"/> + </files> + <fileset dir="${foo.a}" includes="x,y" /> <!-- 2; net 1 --> + <filelist dir="${foo.a}" files="v" /> <!-- 1 --> + <files> <!-- 2; net 1 --> + <include name="${foo.a}/y"/> + <include name="${foo.a}/z"/> + </files> + </union> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testintersect"> + <au:assertTrue> + <resourcecount count="3"> + <intersect> + <filelist dir="${dir}" files="1,2,3,4,5" /> + <filelist dir="${dir}" files="2,3,4,5,6" /> + <filelist dir="${dir}" files="3,4,5,6,7" /> + </intersect> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testdifference"> + <au:assertTrue> + <resourcecount count="2"> + <difference id="diff"> + <filelist dir="${dir}" files="1,2,3,4,5" /> + <filelist dir="${dir}" files="2,3,4,5,6" /> + <filelist dir="${dir}" files="3,4,5,6,7" /> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testfileurl"> + <au:assertTrue> + <length when="greater" length="0"> + <url file="${ant.file}" /> + </length> + </au:assertTrue> + </target> + + <target name="testfileurlref"> + <url id="fileurl" file="${ant.file}" /> + <au:assertTrue> + <length when="greater" length="0"> + <url refid="fileurl" /> + </length> + </au:assertTrue> + </target> + + <target name="testhttpurl1" unless="offline"> + <au:assertTrue> + <length when="greater" length="0"> + <url url="http://www.w3.org/MarkUp/" /> + </length> + </au:assertTrue> + </target> + + <target name="testhttpurl2" unless="offline"> + <concat destfile="${file}" force="true" append="false"> + <url id="httpurl" url="http://ant.apache.org/index.html" /> + <url refid="httpurl" /> + </concat> + <length property="httpurl.length"> + <url refid="httpurl" /> + </length> + <length property="file.length"> + <file file="${file}"/> + </length> + <au:assertTrue message="length of url ${httpurl.length} length of file ${file.length} file should be twice as big"> + <length file="${file}" when="greater" length="${httpurl.length}" /> + </au:assertTrue> + </target> + + <target name="createjar" depends="setUp"> + <jar destfile="${jar}" basedir="${dir}" /> + </target> + + <target name="testjarurl" depends="createjar"> + <pathconvert property="jarurl"> + <url file="${jar}" /> + </pathconvert> + <au:assertTrue> + <length when="greater" length="0"> + <url url="jar:${jarurl}!/META-INF/MANIFEST.MF" /> + </length> + </au:assertTrue> + </target> + + <target name="testfile" depends="setUp"> + <echo file="${file}">This is a test.</echo> + <au:assertTrue> + <length length="15"> + <file file="${file}" /> + </length> + </au:assertTrue> + </target> + + <target name="testzipentry" depends="createjar"> + <au:assertTrue> + <length when="greater" length="0"> + <zipentry zipfile="${jar}" name="META-INF/MANIFEST.MF" /> + </length> + </au:assertTrue> + </target> + + <target name="teststring1"> + <au:assertTrue> + <length length="15"> + <string value="This is a test." /> + </length> + </au:assertTrue> + </target> + + <target name="teststring2"> + <property name="test" value="foo" /> + <au:assertTrue> + <length length="14"> + <string value="This is a ${test}." /> + </length> + </au:assertTrue> + </target> + + <target name="testresource"> + <au:assertTrue> + <length length="4096"> + <resource size="4096" /> + </length> + </au:assertTrue> + </target> + + <target name="testproperty"> + <property name="testproperty" value="abcdefghij" /> + <au:assertTrue> + <length length="10"> + <propertyresource name="testproperty" /> + </length> + </au:assertTrue> + </target> + + <target name="testPropertyResolvedAsResource"> + <string id="s" value="abcdefghij" /> + <au:assertTrue> + <resourcesmatch> + <resource refid="s" /> + <propertyresource name="ant.refid:s" /> + </resourcesmatch> + </au:assertTrue> + </target> + + <target name="testfirst0"> + <au:assertTrue> + <resourcecount count="0"> + <first count="0"> + <filelist dir="${dir}" files="1,2,3,4,5" /> + </first> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testfirst1"> + <au:assertTrue> + <resourcecount count="1"> + <first> + <filelist dir="${dir}" files="1,2,3,4,5" /> + </first> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testfirst2"> + <au:assertTrue> + <resourcecount count="2"> + <first count="2"> + <filelist dir="${dir}" files="1,2,3,4,5" /> + </first> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testJavaConstant"> + <property name="test.tmp.dir" value="${antunit.tmpdir}/testJavaConstant"/> + <mkdir dir="${test.tmp.dir}"/> + <echo file="${test.tmp.dir}/SomeClass.java"> + public class SomeClass { + public static final String CONSTANT = "constant"; + public final String NOT_STATIC = "not-static"; + private static final String PRIVATE = "private"; + } + </echo> + <javac srcdir="${test.tmp.dir}" destdir="${test.tmp.dir}"/> + <path id="tmp.cp"> + <pathelement location="${test.tmp.dir}"/> + </path> + + <loadresource property="actual"> + <javaconstant name="org.apache.tools.ant.Main.DEFAULT_BUILD_FILENAME"/> + </loadresource> + <au:assertEquals message="could not read java constant" expected="build.xml" actual="${actual}" /> + + <!-- + We can't test for special error messages using built-in tasks + because they catch these messages + --> + <au:expectfailure> + <loadresource property="p"> + <javaconstant/> + </loadresource> + </au:expectfailure> + <au:expectfailure> + <loadresource property="p"> + <javaconstant name="org.apache.tools.ant.MissingClass"/> + </loadresource> + </au:expectfailure> + <au:expectfailure> + <loadresource property="p"> + <javaconstant name="SomeClass.CONSTANT2" classpathref="tmp.cp"/> + </loadresource> + </au:expectfailure> + <au:expectfailure> + <loadresource property="p"> + <javaconstant name="SomeClass.PRIVATE"> + <classpath> + <pathelement location="${test.tmp.dir}"/> + </classpath> + </javaconstant> + </loadresource> + </au:expectfailure> + <au:expectfailure> + <loadresource property="p"> + <javaconstant name="SomeClass.NOT_STATIC"/> + </loadresource> + </au:expectfailure> + + <delete dir="${test.tmp.dir}"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/tokens-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/tokens-test.xml new file mode 100644 index 00000000..c09d604c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/tokens-test.xml @@ -0,0 +1,128 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project name="test-tokens" default="antunit" + xmlns:au="antlib:org.apache.ant.antunit"> + + <property name="eol" value="${line.separator}" /> + + <target name="antunit"> + <au:antunit> + <au:plainlistener /> + <file file="${ant.file}" /> + </au:antunit> + </target> + + <target name="testLines"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <tokens> + <string value="foo${eol}bar${eol}baz" /> + </tokens> + <resources> + <string value="foo" /> + <string value="bar" /> + <string value="baz" /> + </resources> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testExplicitLines"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <tokens> + <string value="foo${eol}bar${eol}baz" /> + <linetokenizer /> + </tokens> + <resources> + <string value="foo" /> + <string value="bar" /> + <string value="baz" /> + </resources> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testFileTokenizer"> + <au:assertTrue> + <resourcecount count="1"> + <tokens> + <resources> + <string value="foo${eol}bar${eol}baz" /> + <file file="${ant.file}" /> + </resources> + <filetokenizer /> + </tokens> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testStringTokenizer"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <tokens> + <string value="foo bar baz " /> + <stringtokenizer /> + </tokens> + <resources> + <string value="foo" /> + <string value="bar" /> + <string value="baz" /> + </resources> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testEncoding"> + <au:assertTrue> + <resourcecount count="0"> + <difference> + <tokens encoding="utf-16"> + <file file="utf-16.in" /> + </tokens> + <resources> + <string value="foo" /> + <string value="bar" /> + <string value="baz" /> + </resources> + </difference> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testSort"> + <pathconvert property="sorted" pathsep="${eol}"> + <sort> + <tokens> + <string value="foo bar etc baz" /> + <stringtokenizer /> + </tokens> + </sort> + </pathconvert> + <au:assertTrue> + <equals arg1="bar${eol}baz${eol}etc${eol}foo" arg2="${sorted}" /> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/utf-16.in b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/utf-16.in Binary files differnew file mode 100644 index 00000000..7c7c2a78 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/resources/utf-16.in diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/depend-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/depend-test.xml new file mode 100644 index 00000000..e868f6a6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/depend-test.xml @@ -0,0 +1,45 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../../antunit-base.xml" /> + + <property name="output.dir" location="output" /> + <property name="foo.file" location="${output.dir}/foo" /> + + <target name="setUp"> + <touch file="${foo.file}" mkdirs="true" /> + </target> + + <target name="tearDown"> + <delete dir="${output.dir}" /> + </target> + + <target name="testMapperByTypedef" depends="setUp"> + <au:assertTrue> + <resourcecount count="1"> + <fileset file="${foo.file}"> + <depend targetdir="${basedir}"><!-- dummy targetdir --> + <mergemapper to="${ant.file}" /> + </depend> + </fileset> + </resourcecount> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/different-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/different-test.xml new file mode 100644 index 00000000..c2542d2f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/different-test.xml @@ -0,0 +1,46 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../../antunit-base.xml" /> + + <property name="output.dir" location="output" /> + <property name="foo.file" location="${output.dir}/foo" /> + + <target name="setUp"> + <mkdir dir="${output.dir}"/> + <echo file="${foo.file}">foo</echo> + </target> + + <target name="tearDown"> + <delete dir="${output.dir}" /> + </target> + + <target name="testMapperByTypedef" depends="setUp"> + <au:assertTrue> + <resourcecount count="1"> + <fileset file="${foo.file}"> + <different targetdir="${basedir}"><!-- dummy targetdir --> + <mergemapper to="${ant.file}" /> + </different> + </fileset> + </resourcecount> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/filename-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/filename-test.xml new file mode 100644 index 00000000..3f28e11e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/filename-test.xml @@ -0,0 +1,69 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../../antunit-base.xml" /> + + <property name="file" value="testfile"/> + + <target name="createTestdir"> + <mkdir dir="${output}"/> + <touch file="${output}/${file}"/> + </target> + + <target name="testPattern" depends="createTestdir"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <fileset dir="${output}"> + <filename name="*"/> + </fileset> + </resourcecount> + </au:assertTrue> + <au:assertTrue> + <resourcecount when="equal" count="0"> + <fileset dir="${output}"> + <filename name="*" negate="true"/> + </fileset> + </resourcecount> + </au:assertTrue> + <au:assertTrue> + <resourcecount when="equal" count="0"> + <fileset dir="${output}"> + <filename name=".*"/> + </fileset> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testRegex" depends="createTestdir"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <fileset dir="${output}"> + <filename regex=".*"/> + </fileset> + </resourcecount> + </au:assertTrue> + <au:assertTrue> + <resourcecount when="equal" count="0"> + <fileset dir="${output}"> + <filename regex=".*" negate="true"/> + </fileset> + </resourcecount> + </au:assertTrue> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/modified-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/modified-test.xml new file mode 100644 index 00000000..a4c43e04 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/modified-test.xml @@ -0,0 +1,76 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../../antunit-base.xml" /> + + <target name="tearDown" depends="antunit-base.tearDown"> + <delete file="cache.properties" quiet="true"/> + </target> + + <target name="testUpdate" + description="https://issues.apache.org/bugzilla/show_bug.cgi?id=32597"> + <mkdir dir="${input}"/> + <touch file="${input}/A"/> + <mkdir dir="${output}"/> + <pathconvert> + <fileset dir="${input}"> + <modified/> + </fileset> + </pathconvert> + <au:assertFileExists file="cache.properties"/> + <copy todir="${output}" file="cache.properties"/> + <echo file="${input}/A">Hello</echo> + <pathconvert> + <fileset dir="${input}"> + <modified update="false"/> + </fileset> + </pathconvert> + <au:assertFilesMatch + expected="${output}/cache.properties" + actual="cache.properties"/> + <pathconvert> + <fileset dir="${input}"> + <modified> + <param name="update" value="false"/> + </modified> + </fileset> + </pathconvert> + <au:assertFilesMatch + expected="${output}/cache.properties" + actual="cache.properties"/> + <pathconvert> + <fileset dir="${input}"> + <modified update="true"/> + </fileset> + </pathconvert> + <au:assertFilesDiffer + expected="${output}/cache.properties" + actual="cache.properties"/> + <copy todir="${output}" file="cache.properties"/> + <echo file="${input}/A">world</echo> + <pathconvert> + <fileset dir="${input}"> + <modified update="true"/> + </fileset> + </pathconvert> + <au:assertFilesDiffer + expected="${output}/cache.properties" + actual="cache.properties"/> + </target> +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/present-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/present-test.xml new file mode 100644 index 00000000..e31c722d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/present-test.xml @@ -0,0 +1,45 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../../antunit-base.xml" /> + + <property name="output.dir" location="output" /> + <property name="foo.file" location="${output.dir}/foo" /> + + <target name="setUp"> + <touch file="${foo.file}" mkdirs="true" /> + </target> + + <target name="tearDown"> + <delete dir="${output.dir}" /> + </target> + + <target name="testMapperByTypedef" depends="setUp"> + <au:assertTrue> + <resourcecount count="1"> + <fileset file="${foo.file}"> + <present targetdir="${basedir}"><!-- dummy targetdir --> + <mergemapper to="${ant.file}" /> + </present> + </fileset> + </resourcecount> + </au:assertTrue> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/readwrite-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/readwrite-test.xml new file mode 100644 index 00000000..bd4ac8de --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/readwrite-test.xml @@ -0,0 +1,99 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../../antunit-base.xml" /> + + <property name="file" value="testfile"/> + + <condition property="unix"> + <os family="unix"/> + </condition> + + <target name="createTestdir"> + <mkdir dir="${output}"/> + <touch file="${output}/${file}"/> + </target> + + <target name="testReadable" depends="createTestdir"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <fileset dir="${output}"> + <readable/> + </fileset> + </resourcecount> + </au:assertTrue> + <au:assertTrue> + <resourcecount when="equal" count="0"> + <fileset dir="${output}" excludes="${file}"> + <readable/> + </fileset> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testWritable" depends="createTestdir"> + <au:assertTrue> + <resourcecount when="equal" count="1"> + <fileset dir="${output}"> + <writable/> + </fileset> + </resourcecount> + </au:assertTrue> + <au:assertTrue> + <resourcecount when="equal" count="0"> + <fileset dir="${output}" excludes="${file}"> + <writable/> + </fileset> + </resourcecount> + </au:assertTrue> + </target> + + <target name="makeFileUnwritable" + depends="createTestdir,makeFileUnwritable-Unix,makeFileUnwritable-Windows"/> + <target name="makeFileUnwritable-Unix" id="unix"> + <chmod file="${output}/${file}" perm="444"/> + </target> + <target name="makeFileUnwritable-Windows" unless="unix"> + <attrib file="${output}/${file}" readonly="true"/> + </target> + + <target name="testUnwritable" depends="makeFileUnwritable"> + <au:assertTrue> + <resourcecount when="equal" count="0"> + <fileset dir="${output}"> + <writable/> + </fileset> + </resourcecount> + </au:assertTrue> + </target> + + <target name="testAsConditions" depends="makeFileUnwritable"> + <au:assertTrue> + <isfileselected file="${output}/${file}"> + <readable/> + </isfileselected> + </au:assertTrue> + <au:assertFalse> + <isfileselected file="${output}/${file}"> + <writable/> + </isfileselected> + </au:assertFalse> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/select-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/select-test.xml new file mode 100644 index 00000000..f5f5b99e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/selectors/select-test.xml @@ -0,0 +1,88 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + + <import file="../../antunit-base.xml" /> + + <target name="setUp"> + <mkdir dir="${input}"/> + <touch file="${input}/A"/> + <touch file="${input}/B"/> + <touch file="${input}/C"/> + <touch file="${input}/D"/> + <mkdir dir="${output}"/> + <macrodef name="cp"> + <sequential> + <copy todir="${output}"> + <fileset dir="${input}"> + <or> + <selector if="${if}"> + <filename name="A"/> + </selector> + <selector unless="${if}"> + <filename name="B"/> + </selector> + <selector if="if"> + <filename name="C"/> + </selector> + <selector unless="if"> + <filename name="D"/> + </selector> + </or> + </fileset> + </copy> + </sequential> + </macrodef> + </target> + + <target name="testIfNotSet" depends="setUp"> + <cp/> + <au:assertFileDoesntExist file="${output}/C"/> + <au:assertFileExists file="${output}/D"/> + <au:assertFileDoesntExist file="${output}/A"/> + <au:assertFileExists file="${output}/B"/> + </target> + + <target name="testIfSet" depends="setUp"> + <property name="if" value="whatever"/> + <cp/> + <au:assertFileDoesntExist file="${output}/A"/> + <au:assertFileExists file="${output}/B"/> + <au:assertFileExists file="${output}/C"/> + <au:assertFileDoesntExist file="${output}/D"/> + </target> + + <target name="testIfTrue" depends="setUp"> + <property name="if" value="true"/> + <cp/> + <au:assertFileExists file="${output}/A"/> + <au:assertFileDoesntExist file="${output}/B"/> + <au:assertFileExists file="${output}/C"/> + <au:assertFileDoesntExist file="${output}/D"/> + </target> + + <target name="testIfFalse" depends="setUp"> + <property name="if" value="false"/> + <cp/> + <au:assertFileDoesntExist file="${output}/A"/> + <au:assertFileExists file="${output}/B"/> + <au:assertFileExists file="${output}/C"/> + <au:assertFileDoesntExist file="${output}/D"/> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/tarfileset-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/tarfileset-test.xml new file mode 100644 index 00000000..3c4d3a98 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/tarfileset-test.xml @@ -0,0 +1,48 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + <import file="../antunit-base.xml"/> + + <target name="testMissingArchive"> + <mkdir dir="${output}"/> + <au:expectfailure expectedMessage="The archive foo.tar doesn't exist"> + <copy todir="${output}"> + <tarfileset src="foo.tar"/> + </copy> + </au:expectfailure> + </target> + + <target name="testMissingArchiveDoesntMatter"> + <mkdir dir="${output}"/> + <copy todir="${output}"> + <tarfileset src="foo.tar" errorOnMissingArchive="false"/> + </copy> + </target> + + <target name="test-refid-check-encoding"> + <tarfileset id="test-refid2" + encoding="utf-8" + dir="${basedir}"/> + <au:expectfailure> + <tarfileset id="ref4" + encoding="utf-8" + refid="test-refid2"/> + </au:expectfailure> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/zipfileset-test.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/zipfileset-test.xml new file mode 100644 index 00000000..c8bb022b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/types/zipfileset-test.xml @@ -0,0 +1,83 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<project xmlns:au="antlib:org.apache.ant.antunit" default="antunit"> + <import file="../antunit-base.xml"/> + + <target name="test-refid-modify"> + <fileset id="modify-refid-1" + dir="${basedir}" + includes="*.xml" + /> + <zipfileset id="modify-refid-2" + refid="modify-refid-1" + prefix="WEB-INF/lib/"/> + <delete quiet="yes" dir="${build.dir}"/> + <mkdir dir="${output}"/> + <jar jarfile="${output}/jar.jar"> + <zipfileset refid="modify-refid-2"/> + </jar> + <unjar src="${output}/jar.jar" + dest="${output}"/> + <au:assertTrue> + <available file="${output}/WEB-INF/lib/zipfileset-test.xml"/> + </au:assertTrue> + </target> + + <target name="test-refid-check-prefix"> + <zipfileset id="test-refid" + dir="${basedir}"/> + <au:expectfailure> + <zipfileset id="ref2" + refid="test-refid" + prefix="WEB-INF/lib/"/> + </au:expectfailure> + <au:expectfailure> + <zipfileset id="ref3" + prefix="WEB-INF/lib/" + ReFiD="test-refid"/> + </au:expectfailure> + </target> + + <target name="test-refid-check-encoding"> + <zipfileset id="test-refid2" + encoding="utf-8" + dir="${basedir}"/> + <au:expectfailure> + <zipfileset id="ref4" + encoding="utf-8" + refid="test-refid2"/> + </au:expectfailure> + </target> + + <target name="testMissingArchive"> + <mkdir dir="${output}"/> + <au:expectfailure expectedMessage="The archive foo.zip doesn't exist"> + <copy todir="${output}"> + <zipfileset src="foo.zip"/> + </copy> + </au:expectfailure> + </target> + + <target name="testMissingArchiveDoesntMatter"> + <mkdir dir="${output}"/> + <copy todir="${output}"> + <zipfileset src="foo.zip" errorOnMissingArchive="false"/> + </copy> + </target> + +</project> diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/AntAssert.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/AntAssert.java new file mode 100644 index 00000000..7771924f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/AntAssert.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Provides common assert functions for use across multiple tests, similar to the <tt>Assert</tt>s + * within JUnit. + */ +public class AntAssert { + + /** + * Assert that a string contains the given substring. + * @param message the message to fail with if the substring is not present in the target string. + * @param needle the string to search for. + * @param haystack the string to search in. + */ + public static void assertContains(String message, String needle, String haystack) { + String formattedMessage = (message == null ? "" : message + " "); + assertTrue(formattedMessage + String.format("expected message containing: <%s> but got: <%s>", needle, haystack), haystack.contains(needle)); + } + + /** + * Assert that a string contains the given substring. A default failure message will be used if the target string + * is not found. + * @param needle the target string to search for. + * @param haystack the string to search in. + */ + public static void assertContains(String needle, String haystack) { + assertContains("", needle, haystack); + } + + /** + * Assert that a string does not contain the given substring. + * @param message the message to fail with if the substring is present in the target string. + * @param needle the string to search for. + * @param haystack the string to search in. + */ + public static void assertNotContains(String message, String needle, String haystack) { + String formattedMessage = (message == null ? "" : message + " "); + assertFalse(formattedMessage + String.format("expected message not to contain: <%s> but got: <%s>", needle, haystack), haystack.contains(needle)); + } + + /** + * Assert that a string does not contain the given substring. A default failure message will be used if the target + * string is found. + * @param needle the target string to search for. + * @param haystack the string to search in. + */ + public static void assertNotContains(String needle, String haystack) { + assertNotContains("", needle, haystack); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/AntClassLoaderDelegationTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/AntClassLoaderDelegationTest.java new file mode 100644 index 00000000..ae5ce627 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/AntClassLoaderDelegationTest.java @@ -0,0 +1,124 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.Arrays; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +/** + * Test case for ant class loader + * + */ +public class AntClassLoaderDelegationTest { + + /** Instance of a utility class to use for file operations. */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + private Project p; + + @Before + public void setUp() { + p = new Project(); + p.init(); + } + + /** Sample resource present in build/testcases/ */ + private static final String TEST_RESOURCE + = "apache/tools/ant/IncludeTest.class"; + + @Test + public void testFindResources() throws Exception { + // This path should contain the class files for these testcases: + String buildTestcases = System.getProperty("build.tests"); + assertNotNull("defined ${build.tests}", buildTestcases); + assertTrue("have a dir " + buildTestcases, + new File(buildTestcases).isDirectory()); + Path path = new Path(p, buildTestcases + "/org"); + // A special parent loader which is not the system class loader: + ClassLoader parent = new ParentLoader(); + // An AntClassLoader which is supposed to delegate to + // the parent and then to the disk path: + ClassLoader acl = new AntClassLoader(parent, p, path, true); + // The intended result URLs: + URL urlFromPath = new URL( + FILE_UTILS.toURI(buildTestcases) + "org/" + TEST_RESOURCE); + URL urlFromParent = new URL("http://ant.apache.org/" + TEST_RESOURCE); + assertEquals("correct resources (regular delegation order)", + Arrays.asList(new URL[] {urlFromParent, urlFromPath}), + enum2List(acl.getResources(TEST_RESOURCE))); + acl = new AntClassLoader(parent, p, path, false); + assertEquals("correct resources (reverse delegation order)", + Arrays.asList(new URL[] {urlFromPath, urlFromParent}), + enum2List(acl.getResources(TEST_RESOURCE))); + } + + @Test + public void testFindIsolateResources() throws Exception { + String buildTestcases = System.getProperty("build.tests"); + assertNotNull("defined ${build.tests}", buildTestcases); + assertTrue("have a dir " + buildTestcases, + new File(buildTestcases).isDirectory()); + Path path = new Path(p, buildTestcases + "/org"); + // A special parent loader which is not the system class loader: + ClassLoader parent = new ParentLoader(); + + URL urlFromPath = new URL( + FILE_UTILS.toURI(buildTestcases) + "org/" + TEST_RESOURCE); + AntClassLoader acl = new AntClassLoader(parent, p, path, false); + acl.setIsolated(true); + assertEquals("correct resources (reverse delegation order)", + Arrays.asList(new URL[] {urlFromPath}), + enum2List(acl.getResources(TEST_RESOURCE))); + } + + private static List enum2List(Enumeration e) { + return Collections.list(e); + } + + /** Special loader that just knows how to find TEST_RESOURCE. */ + private static final class ParentLoader extends ClassLoader { + + public ParentLoader() {} + + protected Enumeration findResources(String name) throws IOException { + if (name.equals(TEST_RESOURCE)) { + return Collections.enumeration( + Collections.singleton( + new URL("http://ant.apache.org/" + name))); + } else { + return Collections.enumeration(Collections.EMPTY_SET); + } + } + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/AntClassLoaderPerformance.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/AntClassLoaderPerformance.java new file mode 100644 index 00000000..2145cfa1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/AntClassLoaderPerformance.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import java.io.File; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Test; + +/** + * Used to verify the performance effect of classloader changes. + */ +public class AntClassLoaderPerformance { + + @Test + public void testFindClass() throws Exception { + String testCaseURL = getClass() + .getClassLoader().getResource("junit/framework/TestCase.class") + .toExternalForm(); + int pling = testCaseURL.indexOf('!'); + String jarName = testCaseURL.substring(4, pling); + File f = new File(FileUtils.getFileUtils().fromURI(jarName)); + Path p = new Path(null); + p.createPathElement().setLocation(f); + AntClassLoader al = null; + for (int i = 0; i < 1000; i++) { + try { + // not using factory method so the test can run on Ant + // 1.7.1 as well + al = new AntClassLoader(null, null, p, false); + al.findClass("junit.framework.TestCase"); + } finally { + if (al != null) { + al.cleanup(); + } + } + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java new file mode 100644 index 00000000..8419037e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/AntClassLoaderTest.java @@ -0,0 +1,210 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.PrintStream; +import java.net.URL; + +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.FileUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Test case for ant class loader + * + */ +public class AntClassLoaderTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private AntClassLoader loader; + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/core/antclassloader.xml"); + buildRule.executeTarget("setUp"); + } + + @After + public void tearDown() { + if (loader != null) { + loader.cleanup(); + } + } + + //test inspired by bug report 37085 + @Test + public void testJarWithManifestInDirWithSpace() { + String mainjarstring = buildRule.getProject().getProperty("main.jar"); + String extjarstring = buildRule.getProject().getProperty("ext.jar"); + Path myPath = new Path(buildRule.getProject()); + myPath.setLocation(new File(mainjarstring)); + buildRule.getProject().setUserProperty("build.sysclasspath","ignore"); + loader = buildRule.getProject().createClassLoader(myPath); + String path = loader.getClasspath(); + assertEquals(mainjarstring + File.pathSeparator + extjarstring, path); + } + + @Test + public void testJarWithManifestInNonAsciiDir() { + String mainjarstring = buildRule.getProject().getProperty("main.jar.nonascii"); + String extjarstring = buildRule.getProject().getProperty("ext.jar.nonascii"); + Path myPath = new Path(buildRule.getProject()); + myPath.setLocation(new File(mainjarstring)); + buildRule.getProject().setUserProperty("build.sysclasspath","ignore"); + loader = buildRule.getProject().createClassLoader(myPath); + String path = loader.getClasspath(); + assertEquals(mainjarstring + File.pathSeparator + extjarstring, path); + } + + @Test + public void testCleanup() throws BuildException { + Path path = new Path(buildRule.getProject(), "."); + loader = buildRule.getProject().createClassLoader(path); + try { + // we don't expect to find this + loader.findClass("fubar"); + fail("Did not expect to find fubar class"); + } catch (ClassNotFoundException e) { + // ignore expected + } + + loader.cleanup(); + try { + // we don't expect to find this + loader.findClass("fubar"); + fail("Did not expect to find fubar class"); + } catch (ClassNotFoundException e) { + // ignore expected + } catch (NullPointerException e) { + fail("loader should not fail even if cleaned up"); + } + + // tell the build it is finished + buildRule.getProject().fireBuildFinished(null); + try { + // we don't expect to find this + loader.findClass("fubar"); + fail("Did not expect to find fubar class"); + } catch (ClassNotFoundException e) { + // ignore expected + } catch (NullPointerException e) { + fail("loader should not fail even if project finished"); + } + } + + @Test + public void testGetPackage() throws Exception { + buildRule.executeTarget("prepareGetPackageTest"); + Path myPath = new Path(buildRule.getProject()); + myPath.setLocation(new File(buildRule.getProject().getProperty("test.jar"))); + buildRule.getProject().setUserProperty("build.sysclasspath","ignore"); + loader = buildRule.getProject().createClassLoader(myPath); + assertNotNull("should find class", loader.findClass("org.example.Foo")); + assertNotNull("should find package", + new GetPackageWrapper(loader).getPackage("org.example")); + } + + @Test + public void testCodeSource() throws Exception { + buildRule.executeTarget("prepareGetPackageTest"); + Path myPath = new Path(buildRule.getProject()); + File testJar = new File(buildRule.getProject().getProperty("test.jar")); + myPath.setLocation(testJar); + buildRule.getProject().setUserProperty("build.sysclasspath","ignore"); + loader = buildRule.getProject().createClassLoader(myPath); + Class<?> foo = loader.findClass("org.example.Foo"); + URL codeSourceLocation = + foo.getProtectionDomain().getCodeSource().getLocation(); + assertEquals(codeSourceLocation + " should point to test.jar", + FileUtils.getFileUtils().getFileURL(testJar), codeSourceLocation); + } + + @Test + public void testSignedJar() throws Exception { + buildRule.executeTarget("signTestJar"); + File jar = new File(buildRule.getProject().getProperty("test.jar")); + + Path myPath = new Path(buildRule.getProject()); + myPath.setLocation(jar); + buildRule.getProject().setUserProperty("build.sysclasspath","ignore"); + loader = buildRule.getProject().createClassLoader(myPath); + Class<?> foo = loader.findClass("org.example.Foo"); + + assertNotNull("should find class", foo); + assertNotNull("should have certificates", + foo.getProtectionDomain().getCodeSource() + .getCertificates()); + assertNotNull("should be signed", foo.getSigners()); + } + + /** + * @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=47593"> + * bug 47593, request to log the name of corrupt zip files from which + * classes cannot be loaded</a> + */ + @Test + public void testInvalidZipException() throws Exception { + buildRule.executeTarget("createNonJar"); + File jar = new File(buildRule.getProject().getProperty("tmp.dir") + + "/foo.jar"); + + Path myPath = new Path(buildRule.getProject()); + myPath.setLocation(jar); + buildRule.getProject().setUserProperty("build.sysclasspath","ignore"); + loader = buildRule.getProject().createClassLoader(myPath); + PrintStream sysErr = System.err; + try { + StringBuffer errBuffer = new StringBuffer(); + PrintStream err = + new PrintStream(new BuildFileRule.AntOutputStream(errBuffer)); + System.setErr(err); + loader.getResource("foo.txt"); + String log = buildRule.getLog(); + int startMessage = log.indexOf("CLASSPATH element "); + assertTrue(startMessage >= 0); + assertTrue(log.indexOf("foo.jar is not a JAR", startMessage) > 0); + log = errBuffer.toString(); + startMessage = log.indexOf("CLASSPATH element "); + assertTrue(startMessage >= 0); + assertTrue(log.indexOf("foo.jar is not a JAR", startMessage) > 0); + } finally { + System.setErr(sysErr); + } + } + + private static class GetPackageWrapper extends ClassLoader { + GetPackageWrapper(ClassLoader parent) { + super(parent); + } + public Package getPackage(String s) { + return super.getPackage(s); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/BuildFileRule.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/BuildFileRule.java new file mode 100644 index 00000000..b4e00fdc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/BuildFileRule.java @@ -0,0 +1,318 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import java.io.File; +import java.io.OutputStream; +import java.io.PrintStream; + +import org.apache.tools.ant.util.ProcessUtil; +import org.junit.rules.ExternalResource; + +/** + * Provides access for JUnit tests to execute Ant targets and access execution details (i.e logs). + * + * Example usage: + * <code> + * public class MyTest { + * + * \@Rule + * public BuildFileRule rule = new BuildFileRule(); + * + * \@Before + * public void setUp() { + * rule.configureProject("my/and/file.xml"); + * } + * + * \@Test + * public void testSuccess() { + * rule.executeTarget("passingTaget"); + * assertEquals("Incorrect log message", "[taskName] Action Complete", rule.getLog()); + * } + * + * \@Test + * public void testException() { + * try { + * rule.executeTarget("failingTarget"); + * fail("Target should have thrown a BuildException"); + * } catch (BuildException ex) { + * assertContains("Exception did not contain correct text", "Could not find compiler on classpath", ex.getMessage()); + * } + * } + * + * } + * </code> + */ +public class BuildFileRule extends ExternalResource { + + private Project project; + + private StringBuffer logBuffer; + private StringBuffer fullLogBuffer; + private StringBuffer outputBuffer; + private StringBuffer errorBuffer; + + + + /** + * Tidies up following a test execution. If the currently configured + * project has a <tt>tearDown</tt> target then this will automatically + * be called, otherwise this method will not perform any actions. + */ + @Override + protected void after() { + if (project == null) { + // configureProject has not been called - nothing we can clean-up + return; + } + final String tearDown = "tearDown"; + if (project.getTargets().containsKey(tearDown)) { + project.executeTarget(tearDown); + } + } + + /** + * Gets the INFO, WARNING and ERROR message from the current execution, + * unless the logging level is set above any of these level in which case + * the message is excluded. + * This is only valid if configureProject() has been called. + * + * @return The INFO, WARN and ERROR messages in the log. + */ + public String getLog() { + return logBuffer.toString(); + } + + /** + * Gets any messages that have been logged during the current execution, unless + * the logging level has been set above the log level defined in the message. + * + * Only valid if configureProject() has been called. + * @return the content of the log. + */ + public String getFullLog() { + return fullLogBuffer.toString(); + } + + /** + * Provides all output sent to the System.out stream during the current execution. + * @return all output messages in a single string, normalised to have platform independent line breaks. + */ + public String getOutput() { + return cleanBuffer(outputBuffer); + } + + /** + * Provides all output sent to the System.err stream during the current execution. + * @return all error messages in a single string, normalised to have platform independent line breaks. + */ + public String getError() { + return cleanBuffer(errorBuffer); + } + + private String cleanBuffer(StringBuffer buffer) { + StringBuilder cleanedBuffer = new StringBuilder(); + for (int i = 0; i < buffer.length(); i++) { + char ch = buffer.charAt(i); + if (ch != '\r') { + cleanedBuffer.append(ch); + } + } + return cleanedBuffer.toString(); + } + + /** + * Sets up to run the named project + * + * @param filename name of project file to run + */ + public void configureProject(String filename) throws BuildException { + configureProject(filename, Project.MSG_DEBUG); + } + + /** + * Sets up to run the named project + * + * @param filename name of project file to run + */ + public void configureProject(String filename, int logLevel) throws BuildException { + logBuffer = new StringBuffer(); + fullLogBuffer = new StringBuffer(); + project = new Project(); + project.init(); + File antFile = new File(System.getProperty("root"), filename); + project.setProperty("ant.processid", ProcessUtil.getProcessId("<Process>")); + project.setProperty("ant.threadname", Thread.currentThread().getName()); + project.setUserProperty("ant.file" , antFile.getAbsolutePath()); + project.addBuildListener(new AntTestListener(logLevel)); + ProjectHelper.configureProject(project, antFile); + } + + /** + * Executes a target in the configured Ant build file. Requires #configureProject() + * to have been invoked before this call. + * + * @param targetName the target in the currently configured build file to run. + */ + public void executeTarget(String targetName) { + outputBuffer = new StringBuffer(); + PrintStream out = new PrintStream(new AntOutputStream(outputBuffer)); + errorBuffer = new StringBuffer(); + PrintStream err = new PrintStream(new AntOutputStream(errorBuffer)); + logBuffer = new StringBuffer(); + fullLogBuffer = new StringBuffer(); + + /* we synchronize to protect our custom output streams from being overridden + * by other tests executing targets concurrently. Ultimately this would only + * happen if we ran a multi-threaded test executing multiple targets at once, and + * this protection doesn't prevent a target from internally modifying the output + * stream during a test - but at least this scenario is fairly deterministic so + * easier to troubleshoot. + */ + synchronized (System.out) { + PrintStream sysOut = System.out; + PrintStream sysErr = System.err; + sysOut.flush(); + sysErr.flush(); + try { + System.setOut(out); + System.setErr(err); + project.executeTarget(targetName); + } finally { + System.setOut(sysOut); + System.setErr(sysErr); + } + } + } + + /** + * Get the project which has been configured for a test. + * + * @return the Project instance for this test. + */ + public Project getProject() { + return project; + } + + + /** + * An output stream which saves contents to our buffer. + */ + protected static class AntOutputStream extends OutputStream { + private StringBuffer buffer; + + public AntOutputStream( StringBuffer buffer ) { + this.buffer = buffer; + } + + public void write(int b) { + buffer.append((char)b); + } + } + + /** + * Our own personal build listener. + */ + private class AntTestListener implements BuildListener { + private int logLevel; + + /** + * Constructs a test listener which will ignore log events + * above the given level. + */ + public AntTestListener(int logLevel) { + this.logLevel = logLevel; + } + + /** + * Fired before any targets are started. + */ + public void buildStarted(BuildEvent event) { + } + + /** + * Fired after the last target has finished. This event + * will still be thrown if an error occurred during the build. + * + * @see BuildEvent#getException() + */ + public void buildFinished(BuildEvent event) { + } + + /** + * Fired when a target is started. + * + * @see BuildEvent#getTarget() + */ + public void targetStarted(BuildEvent event) { + } + + /** + * Fired when a target has finished. This event will + * still be thrown if an error occurred during the build. + * + * @see BuildEvent#getException() + */ + public void targetFinished(BuildEvent event) { + } + + /** + * Fired when a task is started. + * + * @see BuildEvent#getTask() + */ + public void taskStarted(BuildEvent event) { + } + + /** + * Fired when a task has finished. This event will still + * be throw if an error occurred during the build. + * + * @see BuildEvent#getException() + */ + public void taskFinished(BuildEvent event) { + } + + /** + * Fired whenever a message is logged. + * + * @see BuildEvent#getMessage() + * @see BuildEvent#getPriority() + */ + public void messageLogged(BuildEvent event) { + if (event.getPriority() > logLevel) { + // ignore event + return; + } + + if (event.getPriority() == Project.MSG_INFO || + event.getPriority() == Project.MSG_WARN || + event.getPriority() == Project.MSG_ERR) { + logBuffer.append(event.getMessage()); + } + fullLogBuffer.append(event.getMessage()); + } + } + + public File getOutputDir() { + return new File(getProject().getProperty("output")); + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/BuildFileTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/BuildFileTest.java new file mode 100644 index 00000000..e18d71b8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/BuildFileTest.java @@ -0,0 +1,592 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import java.io.File; +import java.io.PrintStream; +import java.net.URL; + +import junit.framework.TestCase; +import org.apache.tools.ant.util.ProcessUtil; + +/** + * A BuildFileTest is a TestCase which executes targets from an Ant buildfile + * for testing. + * + * This class provides a number of utility methods for particular build file + * tests which extend this class. + * + * @deprecated as of 1.9.4. Use BuildFileRule, Assert, AntAssert and JUnit4 annotations to drive tests instead + * @see org.apache.tools.ant.BuildFileRule + */ +@Deprecated +public abstract class BuildFileTest extends TestCase { + + protected Project project; + + private StringBuffer logBuffer; + private StringBuffer fullLogBuffer; + private StringBuffer outBuffer; + private StringBuffer errBuffer; + private BuildException buildException; + + /** + * Default constructor for the BuildFileTest object. + */ + public BuildFileTest() { + super(); + } + + /** + * Constructor for the BuildFileTest object. + * + * @param name string to pass up to TestCase constructor + */ + public BuildFileTest(String name) { + super(name); + } + + /** + * Automatically calls the target called "tearDown" + * from the build file tested if it exits. + * + * This allows to use Ant tasks directly in the build file + * to clean up after each test. Note that no "setUp" target + * is automatically called, since it's trivial to have a + * test target depend on it. + */ + protected void tearDown() throws Exception { + if (project == null) { + /* + * Maybe the BuildFileTest was subclassed and there is + * no initialized project. So we could avoid getting a + * NPE. + * If there is an initialized project getTargets() does + * not return null as it is initialized by an empty + * HashSet. + */ + return; + } + final String tearDown = "tearDown"; + if (project.getTargets().containsKey(tearDown)) { + project.executeTarget(tearDown); + } + } + + /** + * run a target, expect for any build exception + * + * @param target target to run + * @param cause information string to reader of report + */ + public void expectBuildException(String target, String cause) { + expectSpecificBuildException(target, cause, null); + } + + /** + * Assert that only the given message has been logged with a + * priority <= INFO when running the given target. + */ + public void expectLog(String target, String log) { + executeTarget(target); + String realLog = getLog(); + assertEquals(log, realLog); + } + + /** + * Assert that the given substring is in the log messages. + */ + public void assertLogContaining(String substring) { + String realLog = getLog(); + assertTrue("expecting log to contain \"" + substring + "\" log was \"" + + realLog + "\"", + realLog.indexOf(substring) >= 0); + } + + /** + * Assert that the given substring is not in the log messages. + */ + public void assertLogNotContaining(String substring) { + String realLog = getLog(); + assertFalse("didn't expect log to contain \"" + substring + "\" log was \"" + + realLog + "\"", + realLog.indexOf(substring) >= 0); + } + + /** + * Assert that the given substring is in the output messages. + * @since Ant1.7 + */ + public void assertOutputContaining(String substring) { + assertOutputContaining(null, substring); + } + + /** + * Assert that the given substring is in the output messages. + * @param message Print this message if the test fails. Defaults to + * a meaningful text if <tt>null</tt> is passed. + * @since Ant1.7 + */ + public void assertOutputContaining(String message, String substring) { + String realOutput = getOutput(); + String realMessage = (message != null) + ? message + : "expecting output to contain \"" + substring + "\" output was \"" + realOutput + "\""; + assertTrue(realMessage, realOutput.indexOf(substring) >= 0); + } + + /** + * Assert that the given substring is not in the output messages. + * @param message Print this message if the test fails. Defaults to + * a meaningful text if <tt>null</tt> is passed. + * @since Ant1.7 + */ + public void assertOutputNotContaining(String message, String substring) { + String realOutput = getOutput(); + String realMessage = (message != null) + ? message + : "expecting output to not contain \"" + substring + "\" output was \"" + realOutput + "\""; + assertFalse(realMessage, realOutput.indexOf(substring) >= 0); + } + + /** + * Assert that the given message has been logged with a priority <= INFO when running the + * given target. + */ + public void expectLogContaining(String target, String log) { + executeTarget(target); + assertLogContaining(log); + } + + /** + * Assert that the given message has not been logged with a + * priority <= INFO when running the given target. + */ + public void expectLogNotContaining(String target, String log) { + executeTarget(target); + assertLogNotContaining(log); + } + + /** + * Gets the log the BuildFileTest object. + * Only valid if configureProject() has been called. + * + * @pre logBuffer!=null + * @return The log value + */ + public String getLog() { + return logBuffer.toString(); + } + + /** + * Assert that the given message has been logged with a priority + * >= VERBOSE when running the given target. + */ + public void expectDebuglog(String target, String log) { + executeTarget(target); + String realLog = getFullLog(); + assertEquals(log, realLog); + } + + /** + * Assert that the given substring is in the log messages. + */ + public void assertDebuglogContaining(String substring) { + String realLog = getFullLog(); + assertTrue("expecting debug log to contain \"" + substring + + "\" log was \"" + + realLog + "\"", + realLog.indexOf(substring) >= 0); + } + + /** + * Gets the log the BuildFileTest object. + * + * Only valid if configureProject() has been called. + * + * @pre fullLogBuffer!=null + * @return The log value + */ + public String getFullLog() { + return fullLogBuffer.toString(); + } + + /** + * execute the target, verify output matches expectations + * + * @param target target to execute + * @param output output to look for + */ + public void expectOutput(String target, String output) { + executeTarget(target); + String realOutput = getOutput(); + assertEquals(output, realOutput.trim()); + } + + /** + * Executes the target, verify output matches expectations + * and that we got the named error at the end + * + * @param target target to execute + * @param output output to look for + * @param error Description of Parameter + */ + public void expectOutputAndError(String target, String output, String error) { + executeTarget(target); + String realOutput = getOutput(); + assertEquals(output, realOutput); + String realError = getError(); + assertEquals(error, realError); + } + + public String getOutput() { + return cleanBuffer(outBuffer); + } + + public String getError() { + return cleanBuffer(errBuffer); + } + + public BuildException getBuildException() { + return buildException; + } + + private String cleanBuffer(StringBuffer buffer) { + StringBuffer cleanedBuffer = new StringBuffer(); + for (int i = 0; i < buffer.length(); i++) { + char ch = buffer.charAt(i); + if (ch != '\r') { + cleanedBuffer.append(ch); + } + } + return cleanedBuffer.toString(); + } + + /** + * Sets up to run the named project + * + * @param filename name of project file to run + */ + public void configureProject(String filename) throws BuildException { + configureProject(filename, Project.MSG_DEBUG); + } + + /** + * Sets up to run the named project + * + * @param filename name of project file to run + */ + public void configureProject(String filename, int logLevel) + throws BuildException { + logBuffer = new StringBuffer(); + fullLogBuffer = new StringBuffer(); + project = new Project(); + project.init(); + File antFile = new File(System.getProperty("root"), filename); + project.setUserProperty("ant.file" , antFile.getAbsolutePath()); + // set two new properties to allow to build unique names when running multithreaded tests + project.setProperty("ant.processid", ProcessUtil.getProcessId("<Process>")); + project.setProperty("ant.threadname", Thread.currentThread().getName()); + project.addBuildListener(new AntTestListener(logLevel)); + ProjectHelper.configureProject(project, antFile); + } + + /** + * Executes a target we have set up + * + * @pre configureProject has been called + * @param targetName target to run + */ + public void executeTarget(String targetName) { + PrintStream sysOut = System.out; + PrintStream sysErr = System.err; + try { + sysOut.flush(); + sysErr.flush(); + outBuffer = new StringBuffer(); + PrintStream out = new PrintStream(new AntOutputStream(outBuffer)); + System.setOut(out); + errBuffer = new StringBuffer(); + PrintStream err = new PrintStream(new AntOutputStream(errBuffer)); + System.setErr(err); + logBuffer = new StringBuffer(); + fullLogBuffer = new StringBuffer(); + buildException = null; + project.executeTarget(targetName); + } finally { + System.setOut(sysOut); + System.setErr(sysErr); + } + + } + + /** + * Get the project which has been configured for a test. + * + * @return the Project instance for this test. + */ + public Project getProject() { + return project; + } + + /** + * Gets the directory of the project. + * + * @return the base dir of the project + */ + public File getProjectDir() { + return project.getBaseDir(); + } + + /** + * get location of temporary directory pointed to by property "output" + * @return location of temporary directory pointed to by property "output" + * @since Ant 1.9.4 + */ + public File getOutputDir() { + return new File(project.getProperty("output")); + } + + /** + * Runs a target, wait for a build exception. + * + * @param target target to run + * @param cause information string to reader of report + * @param msg the message value of the build exception we are waiting + * for set to null for any build exception to be valid + */ + public void expectSpecificBuildException(String target, String cause, String msg) { + try { + executeTarget(target); + } catch (org.apache.tools.ant.BuildException ex) { + buildException = ex; + if ((null != msg) && (!ex.getMessage().equals(msg))) { + fail("Should throw BuildException because '" + cause + + "' with message '" + msg + + "' (actual message '" + ex.getMessage() + "' instead)"); + } + return; + } + fail("Should throw BuildException because: " + cause); + } + + /** + * run a target, expect an exception string + * containing the substring we look for (case sensitive match) + * + * @param target target to run + * @param cause information string to reader of report + * @param contains substring of the build exception to look for + */ + public void expectBuildExceptionContaining(String target, String cause, String contains) { + try { + executeTarget(target); + } catch (org.apache.tools.ant.BuildException ex) { + buildException = ex; + if ((null != contains) && (ex.getMessage().indexOf(contains) == -1)) { + fail("Should throw BuildException because '" + cause + "' with message containing '" + contains + "' (actual message '" + ex.getMessage() + "' instead)"); + } + return; + } + fail("Should throw BuildException because: " + cause); + } + + /** + * call a target, verify property is as expected + * + * @param target build file target + * @param property property name + * @param value expected value + */ + public void expectPropertySet(String target, String property, String value) { + executeTarget(target); + assertPropertyEquals(property, value); + } + + /** + * assert that a property equals a value; comparison is case sensitive. + * + * @param property property name + * @param value expected value + */ + public void assertPropertyEquals(String property, String value) { + String result = project.getProperty(property); + assertEquals("property " + property,value,result); + } + + /** + * assert that a property equals "true". + * + * @param property property name + */ + public void assertPropertySet(String property) { + assertPropertyEquals(property, "true"); + } + + /** + * assert that a property is null. + * + * @param property property name + */ + public void assertPropertyUnset(String property) { + String result = project.getProperty(property); + if (result != null) { + fail("Expected property " + property + + " to be unset, but it is set to the value: " + result); + } + } + + /** + * call a target, verify named property is "true". + * + * @param target build file target + * @param property property name + */ + public void expectPropertySet(String target, String property) { + expectPropertySet(target, property, "true"); + } + + /** + * Call a target, verify property is null. + * + * @param target build file target + * @param property property name + */ + public void expectPropertyUnset(String target, String property) { + expectPropertySet(target, property, null); + } + + /** + * Retrieve a resource from the caller classloader to avoid + * assuming a vm working directory. The resource path must be + * relative to the package name or absolute from the root path. + * + * @param resource the resource to retrieve its url. + * @throws junit.framework.AssertionFailedError if the resource is not found. + */ + public URL getResource(String resource){ + URL url = getClass().getResource(resource); + assertNotNull("Could not find resource :" + resource, url); + return url; + } + + /** + * an output stream which saves stuff to our buffer. + */ + protected static class AntOutputStream extends java.io.OutputStream { + private StringBuffer buffer; + + public AntOutputStream( StringBuffer buffer ) { + this.buffer = buffer; + } + + public void write(int b) { + buffer.append((char)b); + } + } + + /** + * Our own personal build listener. + */ + private class AntTestListener implements BuildListener { + private int logLevel; + + /** + * Constructs a test listener which will ignore log events + * above the given level. + */ + public AntTestListener(int logLevel) { + this.logLevel = logLevel; + } + + /** + * Fired before any targets are started. + */ + public void buildStarted(BuildEvent event) { + } + + /** + * Fired after the last target has finished. This event + * will still be thrown if an error occurred during the build. + * + * @see BuildEvent#getException() + */ + public void buildFinished(BuildEvent event) { + } + + /** + * Fired when a target is started. + * + * @see BuildEvent#getTarget() + */ + public void targetStarted(BuildEvent event) { + //System.out.println("targetStarted " + event.getTarget().getName()); + } + + /** + * Fired when a target has finished. This event will + * still be thrown if an error occurred during the build. + * + * @see BuildEvent#getException() + */ + public void targetFinished(BuildEvent event) { + //System.out.println("targetFinished " + event.getTarget().getName()); + } + + /** + * Fired when a task is started. + * + * @see BuildEvent#getTask() + */ + public void taskStarted(BuildEvent event) { + //System.out.println("taskStarted " + event.getTask().getTaskName()); + } + + /** + * Fired when a task has finished. This event will still + * be throw if an error occurred during the build. + * + * @see BuildEvent#getException() + */ + public void taskFinished(BuildEvent event) { + //System.out.println("taskFinished " + event.getTask().getTaskName()); + } + + /** + * Fired whenever a message is logged. + * + * @see BuildEvent#getMessage() + * @see BuildEvent#getPriority() + */ + public void messageLogged(BuildEvent event) { + if (event.getPriority() > logLevel) { + // ignore event + return; + } + + if (event.getPriority() == Project.MSG_INFO || + event.getPriority() == Project.MSG_WARN || + event.getPriority() == Project.MSG_ERR) { + logBuffer.append(event.getMessage()); + } + fullLogBuffer.append(event.getMessage()); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/CaseTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/CaseTest.java new file mode 100644 index 00000000..81cf385f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/CaseTest.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.fail; + +/** + * Simple tests of build file processing + */ +public class CaseTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/core/case.xml"); + } + + /** + * Test whether the build file treats nested elements without + * regard to case. This should not cause an exception. + */ + @Test + public void testCaseSensitivity() { + buildRule.executeTarget("case-sensitivity"); + } + + /** + * Test whether the build file uses case when determining + * task names. + */ + @Test + public void testTaskCase() { + try { + buildRule.executeTarget("taskcase"); + fail("Build exception should have been thrown due to case sensitivity of name"); + } catch(BuildException ex) { + assertContains("Task names should be case sensitive", "Problem: failed to create task or type ecHO", ex.getMessage()); + } + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java new file mode 100644 index 00000000..00f4dfa1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DefaultLoggerTest.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.apache.tools.ant.util.StringUtils; +import org.junit.Test; + +import java.io.PrintWriter; + +import static org.junit.Assert.assertEquals; + +public class DefaultLoggerTest { + + + private static String msg(Throwable error, boolean verbose) { + StringBuffer m = new StringBuffer(); + DefaultLogger.throwableMessage(m, error, verbose); + return m.toString(); + } + + @Test + public void testThrowableMessage() throws Exception { // #43398 + BuildException be = new BuildException("oops", new Location("build.xml", 1, 0)); + assertEquals( + "build.xml:1: oops" + StringUtils.LINE_SEP, + msg(be, false)); + be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 2, 0)); + assertEquals( + "build.xml:2: The following error occurred while executing this line:" + StringUtils.LINE_SEP + + "build.xml:1: oops" + StringUtils.LINE_SEP, + msg(be, false)); + be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 3, 0)); + assertEquals( + "build.xml:3: The following error occurred while executing this line:" + StringUtils.LINE_SEP + + "build.xml:2: The following error occurred while executing this line:" + StringUtils.LINE_SEP + + "build.xml:1: oops" + StringUtils.LINE_SEP, + msg(be, false)); + Exception x = new Exception("problem") { + public void printStackTrace(PrintWriter w) { + w.println("problem"); + w.println(" at p.C.m"); + } + }; + assertEquals( + "problem" + StringUtils.LINE_SEP + + " at p.C.m" + StringUtils.LINE_SEP, + msg(x, false)); + be = new BuildException(x, new Location("build.xml", 1, 0)); + assertEquals( + "build.xml:1: problem" + StringUtils.LINE_SEP + + " at p.C.m" + StringUtils.LINE_SEP, + msg(be, false)); + be = ProjectHelper.addLocationToBuildException(be, new Location("build.xml", 2, 0)); + assertEquals( + "build.xml:2: The following error occurred while executing this line:" + StringUtils.LINE_SEP + + "build.xml:1: problem" + StringUtils.LINE_SEP + + " at p.C.m" + StringUtils.LINE_SEP, + msg(be, false)); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java new file mode 100644 index 00000000..c0c25fd7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DirectoryScannerTest.java @@ -0,0 +1,588 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; +import static org.junit.Assume.assumeFalse; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.Set; +import java.util.TreeSet; + +import org.apache.tools.ant.taskdefs.condition.Os; +import org.apache.tools.ant.types.selectors.TokenizedPath; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * JUnit testcases for org.apache.tools.ant.DirectoryScanner + * + */ +public class DirectoryScannerTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + // keep track of what operating systems are supported here. + private boolean supportsSymlinks = Os.isFamily("unix"); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/core/directoryscanner.xml"); + buildRule.getProject().executeTarget("setUp"); + } + + @Test + public void test1() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha"}); + ds.scan(); + compareFiles(ds, new String[] {} ,new String[] {"alpha"}); + } + + @Test + public void test2() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha/"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void test3() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"", "alpha", "alpha/beta", + "alpha/beta/gamma"}); + } + + @Test + public void testFullPathMatchesCaseSensitive() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"}); + ds.scan(); + compareFiles(ds, new String[] {}, new String[] {}); + } + + @Test + public void testFullPathMatchesCaseInsensitive() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setCaseSensitive(false); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {}); + } + + @Test + public void test2ButCaseInsensitive() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"ALPHA/"}); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testAllowSymlinks() { + + assumeTrue("Current system does not support Symlinks", supportsSymlinks); + + buildRule.getProject().executeTarget("symlink-setup"); + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha/beta/gamma/"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha/beta/gamma"}); + } + + @Test + public void testProhibitSymlinks() { + assumeTrue("Current system does not support Symlinks", supportsSymlinks); + + + buildRule.getProject().executeTarget("symlink-setup"); + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha/beta/gamma/"}); + ds.setFollowSymlinks(false); + ds.scan(); + compareFiles(ds, new String[] {}, new String[] {}); + } + + // father and child pattern test + @Test + public void testOrderOfIncludePatternsIrrelevant() { + String [] expectedFiles = {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}; + String [] expectedDirectories = {"alpha/beta", "alpha/beta/gamma" }; + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha/be?a/**", "alpha/beta/gamma/"}); + ds.scan(); + compareFiles(ds, expectedFiles, expectedDirectories); + // redo the test, but the 2 include patterns are inverted + ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha/beta/gamma/", "alpha/be?a/**"}); + ds.scan(); + compareFiles(ds, expectedFiles, expectedDirectories); + } + + @Test + public void testPatternsDifferInCaseScanningSensitive() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha/", "ALPHA/"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testPatternsDifferInCaseScanningInsensitive() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha/", "ALPHA/"}); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testFullpathDiffersInCaseScanningSensitive() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] { + "alpha/beta/gamma/gamma.xml", + "alpha/beta/gamma/GAMMA.XML" + }); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {}); + } + + @Test + public void testFullpathDiffersInCaseScanningInsensitive() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] { + "alpha/beta/gamma/gamma.xml", + "alpha/beta/gamma/GAMMA.XML" + }); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {}); + } + + @Test + public void testParentDiffersInCaseScanningSensitive() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testParentDiffersInCaseScanningInsensitive() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"}); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + /** + * Test case for setFollowLinks() and associated functionality. + * Only supports test on Linux at the moment because Java has + * no real notion of symlinks built in, so an os-specfic call + * to Runtime.exec() must be made to create a link to test against. + * @throws InterruptedException + */ + @Test + public void testSetFollowLinks() throws IOException, InterruptedException { + if (supportsSymlinks) { + File linkFile = new File(System.getProperty("root"), "src/main/org/apache/tools/ThisIsALink"); + System.err.println("link exists pre-test? " + linkFile.exists()); + + try { + // add conditions and more commands as soon as the need arises + String[] command = new String[] { + "ln", "-s", "ant", linkFile.getAbsolutePath() + }; + Process process = Runtime.getRuntime().exec(command); + assertEquals("0 return code expected for external process", 0, process.waitFor()); + + + File dir = new File(System.getProperty("root"), "src/main/org/apache/tools"); + + DirectoryScanner ds = new DirectoryScanner(); + + // followLinks should be true by default, but if this ever + // changes we will need this line. + ds.setFollowSymlinks(true); + + ds.setBasedir(dir); + ds.setExcludes(new String[] {"ant/**"}); + ds.scan(); + + boolean haveZipPackage = false; + boolean haveTaskdefsPackage = false; + + String[] included = ds.getIncludedDirectories(); + for (int i=0; i<included.length; i++) { + if (included[i].equals("zip")) { + haveZipPackage = true; + } else if (included[i].equals("ThisIsALink" + + File.separator + + "taskdefs")) { + haveTaskdefsPackage = true; + } + } + + // if we followed the symlink we just made we should + // bypass the excludes. + + assertTrue("(1) zip package included", haveZipPackage); + assertTrue("(1) taskdefs package included", + haveTaskdefsPackage); + + + ds = new DirectoryScanner(); + ds.setFollowSymlinks(false); + + ds.setBasedir(dir); + ds.setExcludes(new String[] {"ant/**"}); + ds.scan(); + + haveZipPackage = false; + haveTaskdefsPackage = false; + included = ds.getIncludedDirectories(); + for (int i=0; i<included.length; i++) { + if (included[i].equals("zip")) { + haveZipPackage = true; + } else if (included[i].equals("ThisIsALink" + + File.separator + + "taskdefs")) { + haveTaskdefsPackage = true; + } + } + assertTrue("(2) zip package included", haveZipPackage); + assertTrue("(2) taskdefs package not included", + !haveTaskdefsPackage); + + } finally { + if (!linkFile.delete()) { + //TODO log this? + //throw new RuntimeException("Failed to delete " + linkFile); + } + + } + } + } + + @Test + public void testExcludeOneFile() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] { + "**/*.xml" + }); + ds.setExcludes(new String[] { + "alpha/beta/b*xml" + }); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {}); + } + + @Test + public void testExcludeHasPrecedence() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] { + "alpha/**" + }); + ds.setExcludes(new String[] { + "alpha/**" + }); + ds.scan(); + compareFiles(ds, new String[] {}, + new String[] {}); + + } + + @Test + public void testAlternateIncludeExclude() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setIncludes(new String[] { + "alpha/**", + "alpha/beta/gamma/**" + }); + ds.setExcludes(new String[] { + "alpha/beta/**" + }); + ds.scan(); + compareFiles(ds, new String[] {}, + new String[] {"alpha"}); + + } + + @Test + public void testAlternateExcludeInclude() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setExcludes(new String[] { + "alpha/**", + "alpha/beta/gamma/**" + }); + ds.setIncludes(new String[] { + "alpha/beta/**" + }); + ds.scan(); + compareFiles(ds, new String[] {}, + new String[] {}); + + } + + /** + * Test inspired by Bug#1415. + */ + @Test + public void testChildrenOfExcludedDirectory() { + buildRule.getProject().executeTarget("children-of-excluded-dir-setup"); + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setExcludes(new String[] {"alpha/**"}); + ds.setFollowSymlinks(false); + ds.scan(); + compareFiles(ds, new String[] {"delta/delta.xml"}, + new String[] {"", "delta"}); + + ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setExcludes(new String[] {"alpha"}); + ds.setFollowSymlinks(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml", + "delta/delta.xml"}, + new String[] {"", "alpha/beta", "alpha/beta/gamma", "delta"}); + + } + + @Test + public void testIsExcludedDirectoryScanned() { + String shareclassloader = buildRule.getProject().getProperty("tests.and.ant.share.classloader"); + // when the test is started by the build.xml of ant + // if the property tests.and.ant.share.classloader is not set in the build.xml + // a sysproperty with name tests.and.ant.share.classloader and value + // ${tests.and.ant.share.classloader} will be set + // we are trying to catch this here. + assumeFalse("cannot execute testIsExcludedDirectoryScanned when tests are forked, " + + "package private method called", shareclassloader == null + || (shareclassloader != null && shareclassloader.indexOf("${") == 0)); + buildRule.getProject().executeTarget("children-of-excluded-dir-setup"); + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + + ds.setExcludes(new String[] {"**/gamma/**"}); + ds.setFollowSymlinks(false); + ds.scan(); + Set<String> set = ds.getScannedDirs(); + assertFalse("empty set", set.isEmpty()); + String s = "alpha/beta/gamma/".replace('/', File.separatorChar); + assertFalse("scanned " + s, set.contains(s)); + } + + @Test + public void testAbsolute1() { + buildRule.getProject().executeTarget("extended-setup"); + DirectoryScanner ds = new DirectoryScanner(); + String tmpdir = buildRule.getProject().getProperty("output").replace( + File.separatorChar, '/'); + ds.setIncludes(new String[] {tmpdir + "/**/*"}); + ds.scan(); + compareFiles(ds, new String[] {tmpdir + "/alpha/beta/beta.xml", + tmpdir + "/alpha/beta/gamma/gamma.xml", + tmpdir + "/delta/delta.xml"}, + new String[] {tmpdir + "/alpha", + tmpdir + "/alpha/beta", + tmpdir + "/alpha/beta/gamma", + tmpdir + "/delta"}); + } + + @Test + public void testAbsolute2() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setIncludes(new String[] {"alpha/**", "alpha/beta/gamma/**"}); + ds.scan(); + String[] mt = new String[0]; + compareFiles(ds, mt, mt); + } + + @Test + public void testAbsolute3() { + buildRule.getProject().executeTarget("extended-setup"); + DirectoryScanner ds = new DirectoryScanner(); + String tmpdir = buildRule.getProject().getProperty("output").replace( + File.separatorChar, '/'); + ds.setIncludes(new String[] {tmpdir + "/**/*"}); + ds.setExcludes(new String[] {"**/alpha", + "**/delta/*"}); + ds.scan(); + compareFiles(ds, new String[] {tmpdir + "/alpha/beta/beta.xml", + tmpdir + "/alpha/beta/gamma/gamma.xml"}, + new String[] {tmpdir + "/alpha/beta", + tmpdir + "/alpha/beta/gamma", + tmpdir + "/delta"}); + } + + @Test + public void testAbsolute4() { + buildRule.getProject().executeTarget("extended-setup"); + DirectoryScanner ds = new DirectoryScanner(); + String tmpdir = buildRule.getProject().getProperty("output").replace( + File.separatorChar, '/') ; + ds.setIncludes(new String[] {tmpdir + "/alpha/beta/**/*", + tmpdir + "/delta/*"}); + ds.setExcludes(new String[] {"**/beta.xml"}); + ds.scan(); + compareFiles(ds, new String[] {tmpdir + "/alpha/beta/gamma/gamma.xml", + tmpdir + "/delta/delta.xml"}, + new String[] {tmpdir + "/alpha/beta/gamma"}); + } + + @Test + public void testAbsolute5() { + //testing drive letter search from root: + assumeTrue("Can't use drive letters on non DOS or Netware systems", (Os.isFamily("dos") || Os.isFamily("netware"))); + DirectoryScanner ds = new DirectoryScanner(); + String pattern = new File(File.separator).getAbsolutePath().toUpperCase() + "*"; + ds.setIncludes(new String[] {pattern}); + ds.scan(); + //if this is our context we assume there must be something here: + assertTrue("should have at least one resident file", + ds.getIncludedFilesCount() + ds.getIncludedDirsCount() > 0); + } + + private void compareFiles(DirectoryScanner ds, String[] expectedFiles, + String[] expectedDirectories) { + String includedFiles[] = ds.getIncludedFiles(); + String includedDirectories[] = ds.getIncludedDirectories(); + assertEquals("file present: ", expectedFiles.length, + includedFiles.length); + assertEquals("directories present: ", expectedDirectories.length, + includedDirectories.length); + + TreeSet<String> files = new TreeSet<String>(); + for (int counter = 0; counter < includedFiles.length; counter++) { + files.add(includedFiles[counter].replace(File.separatorChar, '/')); + } + TreeSet<String> directories = new TreeSet<String>(); + for (int counter = 0; counter < includedDirectories.length; counter++) { + directories.add(includedDirectories[counter] + .replace(File.separatorChar, '/')); + } + + String currentfile; + Iterator<String> i = files.iterator(); + int counter = 0; + while (i.hasNext()) { + currentfile = (String) i.next(); + assertEquals(expectedFiles[counter], currentfile); + counter++; + } + String currentdirectory; + Iterator<String> dirit = directories.iterator(); + counter = 0; + while (dirit.hasNext()) { + currentdirectory = (String) dirit.next(); + assertEquals(expectedDirectories[counter], currentdirectory); + counter++; + } + } + + @Test + public void testRecursiveExcludes() throws Exception { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(buildRule.getProject().getProperty("output"))); + ds.setExcludes(new String[] {"**/beta/**"}); + ds.scan(); + List<String> dirs = Arrays.asList(ds.getExcludedDirectories()); + assertEquals(2, dirs.size()); + assertTrue("beta is excluded", + dirs.contains("alpha/beta".replace('/', File.separatorChar))); + assertTrue("gamma is excluded", + dirs.contains("alpha/beta/gamma".replace('/', + File.separatorChar))); + List<String> files = Arrays.asList(ds.getExcludedFiles()); + assertEquals(2, files.size()); + assertTrue("beta.xml is excluded", + files.contains("alpha/beta/beta.xml" + .replace('/', File.separatorChar))); + assertTrue("gamma.xml is excluded", + files.contains("alpha/beta/gamma/gamma.xml" + .replace('/', File.separatorChar))); + } + + @Test + public void testContentsExcluded() { + DirectoryScanner ds = new DirectoryScanner(); + ds.setBasedir(new File(".")); + ds.setIncludes(new String[] {"**"}); + ds.addDefaultExcludes(); + ds.ensureNonPatternSetsReady(); + File f = new File(".svn"); + TokenizedPath p = new TokenizedPath(f.getAbsolutePath()); + assertTrue(ds.contentsExcluded(p)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DispatchTaskTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DispatchTaskTest.java new file mode 100644 index 00000000..604a0a2e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DispatchTaskTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import static org.junit.Assert.fail; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class DispatchTaskTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/core/dispatch/dispatch.xml"); + } + + @Test + public void testDisp() { + try { + buildRule.executeTarget("disp"); + fail("BuildException should have been thrown"); + } catch(BuildException ex) { + //FIXME the previous method used here ignored the build exception - what are we trying to test + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskAbstract.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskAbstract.java new file mode 100644 index 00000000..18fe09d2 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskAbstract.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.apache.tools.ant.Task; + +public abstract class DummyTaskAbstract extends Task { + + public DummyTaskAbstract() { + } + + public void execute() { + } + + public abstract void abstractDummy(); +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskInterface.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskInterface.java new file mode 100644 index 00000000..8ae5f5b3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskInterface.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +public interface DummyTaskInterface { + + void execute(); + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskOk.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskOk.java new file mode 100644 index 00000000..ff8fdab3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskOk.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.apache.tools.ant.Task; + +public class DummyTaskOk extends Task { + + public DummyTaskOk() { + } + + public void execute() { + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskOkNonTask.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskOkNonTask.java new file mode 100644 index 00000000..234abd61 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskOkNonTask.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +public class DummyTaskOkNonTask { + + public DummyTaskOkNonTask() { + } + + public void execute() { + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithNonPublicExecute.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithNonPublicExecute.java new file mode 100644 index 00000000..766283d6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithNonPublicExecute.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +public class DummyTaskWithNonPublicExecute { + + public DummyTaskWithNonPublicExecute() { + } + + void execute() { + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithNonVoidExecute.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithNonVoidExecute.java new file mode 100644 index 00000000..876b9b70 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithNonVoidExecute.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +public class DummyTaskWithNonVoidExecute { + + public DummyTaskWithNonVoidExecute() { + } + + public int execute() { + return 0; + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithoutDefaultConstructor.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithoutDefaultConstructor.java new file mode 100644 index 00000000..40661f5e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithoutDefaultConstructor.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.apache.tools.ant.Task; + +public class DummyTaskWithoutDefaultConstructor extends Task { + + public DummyTaskWithoutDefaultConstructor(int dummy) { + } + + public void execute() { + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithoutExecute.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithoutExecute.java new file mode 100644 index 00000000..6d5ea006 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithoutExecute.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +public class DummyTaskWithoutExecute { + + public DummyTaskWithoutExecute() { + } + + public void execute(String dummy) { + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithoutPublicConstructor.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithoutPublicConstructor.java new file mode 100644 index 00000000..0ec4ff8e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/DummyTaskWithoutPublicConstructor.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.apache.tools.ant.Task; + +public class DummyTaskWithoutPublicConstructor extends Task { + + DummyTaskWithoutPublicConstructor() { + } + + public void execute() { + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ExecutorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ExecutorTest.java new file mode 100644 index 00000000..6a370935 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ExecutorTest.java @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.util.Vector; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Executor tests + */ +public class ExecutorTest implements BuildListener { + + private static final String SINGLE_CHECK + = "org.apache.tools.ant.helper.SingleCheckExecutor"; + private static final String IGNORE_DEPS + = "org.apache.tools.ant.helper.IgnoreDependenciesExecutor"; + + private static final Vector<String> TARGET_NAMES; + static { + TARGET_NAMES = new Vector<String>(); + TARGET_NAMES.add("a"); + TARGET_NAMES.add("b"); + } + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private int targetCount; + + /* BuildListener stuff */ + public void targetStarted(BuildEvent event) { + targetCount++; + } + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) {} + public void targetFinished(BuildEvent event) {} + public void taskStarted(BuildEvent event) {} + public void taskFinished(BuildEvent event) {} + public void messageLogged(BuildEvent event) {} + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/core/executor.xml"); + targetCount = 0; + buildRule.getProject().addBuildListener(this); + } + + private Project getProject(String e) { + return getProject(e, false); + } + + private Project getProject(String e, boolean f) { + return getProject(e, f, false); + } + + private Project getProject(String e, boolean f, boolean k) { + Project p = buildRule.getProject(); + p.setNewProperty("ant.executor.class", e); + p.setKeepGoingMode(k); + if (f) { + p.setNewProperty("failfoo", "foo"); + } + return p; + } + + @Test + public void testDefaultExecutor() { + buildRule.getProject().executeTargets(TARGET_NAMES); + assertEquals(4, targetCount); + } + + @Test + public void testSingleCheckExecutor() { + getProject(SINGLE_CHECK).executeTargets(TARGET_NAMES); + assertEquals(3, targetCount); + } + + @Test + public void testIgnoreDependenciesExecutor() { + getProject(IGNORE_DEPS).executeTargets(TARGET_NAMES); + assertEquals(2, targetCount); + } + + @Test + public void testDefaultFailure() { + try { + getProject(null, true).executeTargets(TARGET_NAMES); + fail("should fail"); + } catch (BuildException e) { + assertEquals("failfoo", e.getMessage()); + assertEquals(1, targetCount); + } + } + + @Test + public void testSingleCheckFailure() { + try { + getProject(SINGLE_CHECK, true).executeTargets(TARGET_NAMES); + fail("should fail"); + } catch (BuildException e) { + assertEquals("failfoo", e.getMessage()); + assertEquals(1, targetCount); + } + } + + @Test + public void testIgnoreDependenciesFailure() { + //no foo failure; foo is never executed as dependencies are ignored! + getProject(IGNORE_DEPS, true).executeTargets(TARGET_NAMES); + } + + @Test + public void testKeepGoingDefault() { + try { + getProject(null, true, true).executeTargets(TARGET_NAMES); + fail("should fail"); + } catch (BuildException e) { + assertEquals("failfoo", e.getMessage()); + assertEquals(2, targetCount); + } + } + + @Test + public void testKeepGoingSingleCheck() { + try { + getProject(SINGLE_CHECK, true, true).executeTargets(TARGET_NAMES); + fail("should fail"); + } catch (BuildException e) { + assertEquals("failfoo", e.getMessage()); + assertEquals(1, targetCount); + } + } + + @Test + public void testKeepGoingIgnoreDependencies() { + try { + //explicitly add foo for failure + Vector<String> targetNames = new Vector<String>(TARGET_NAMES); + targetNames.add(0, "foo"); + getProject(IGNORE_DEPS, true, true).executeTargets(targetNames); + fail("should fail"); + } catch (BuildException e) { + assertEquals("failfoo", e.getMessage()); + assertEquals(3, targetCount); + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ExtendedTaskdefTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ExtendedTaskdefTest.java new file mode 100644 index 00000000..a1412414 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ExtendedTaskdefTest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import static org.junit.Assert.fail; + +import static org.apache.tools.ant.AntAssert.assertContains; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * created 16-Mar-2006 12:25:12 + */ + +public class ExtendedTaskdefTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/core/extended-taskdef.xml"); + } + + @After + public void tearDown() throws Exception { + buildRule.executeTarget("teardown"); + } + + @Test + public void testRun() throws Exception { + try { + buildRule.executeTarget("testRun"); + fail("BuildException should have been thrown"); + } catch(BuildException ex) { + assertContains("exception thrown by the subclass", "executing the Foo task", ex.getMessage()); + } + } + + @Test + public void testRun2() throws Exception { + try { + buildRule.executeTarget("testRun2"); + fail("BuildException should have been thrown"); + } catch(BuildException ex) { + assertContains("exception thrown by the subclass", "executing the Foo task", ex.getMessage()); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/FileUtilities.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/FileUtilities.java new file mode 100644 index 00000000..a9de5cea --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/FileUtilities.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + + +import org.apache.tools.ant.util.FileUtils; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import static org.junit.Assume.assumeTrue; + +public class FileUtilities { + + /** + * Reads the contents of a file into a String. + * @param project the project containing the base directory the file is in. + * @param fileName the path to the file from the base directory. + * @return the contents of the given file as a string. + * @throws IOException on error reading the file (not existing, not readable etc) + */ + public static String getFileContents(Project project, String fileName) throws IOException { + return getFileContents(new File(project.getBaseDir(), fileName)); + } + + /** + * Reads the contents of a file into a String. + * @param file the file to read. + * @return the contents of the given file as a string. + * @throws IOException on error reading the file (not existing, not readable etc) + */ + public static String getFileContents(File file) throws IOException { + FileReader rdr = null; + try { + rdr = new FileReader(file); + return FileUtils.readFully(rdr); + } + finally { + if (rdr != null) { + rdr.close(); + } + } + } + + + /** + * Modified the timestamp on a file so it's <tt>seconds</tt> earlier than it was before. Where <tt>file</tt> + * is a directory, this function recurses into all child files (and directories) and reduces their modified + * timestamps by the same range, rather than set all timestamps to the same time. + * @param file the file to change, or the directory to change then recurse into + * @param seconds how many seconds to roll the timestamp back by + */ + public static void rollbackTimetamps(File file, long seconds) { + if (null == file || !file.exists()) { + return; + } + + assumeTrue(file.setLastModified(file.lastModified() - (seconds * 1000))); + + if (file.isDirectory()) { + File[] children = file.listFiles(); + // only possible if exception occurs, or abstract path was not valid + if (children == null) { + return; + } + for (File child : children) { + rollbackTimetamps(child, seconds); + } + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ImmutableTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ImmutableTest.java new file mode 100644 index 00000000..cd65a5a6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ImmutableTest.java @@ -0,0 +1,90 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertEquals; + +/** + */ +public class ImmutableTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/core/immutable.xml"); + } + + // override allowed on <available> + @Test + public void test1() { + buildRule.executeTarget("test1"); + assertEquals("override",buildRule.getProject().getProperty("test")); + } + + // ensure <tstamp>'s new prefix attribute is working + @Test + public void test2() { + buildRule.executeTarget("test2"); + assertNotNull(buildRule.getProject().getProperty("DSTAMP")); + assertNotNull(buildRule.getProject().getProperty("start.DSTAMP")); + } + + // ensure <tstamp> follows the immutability rule + @Test + public void test3() { + buildRule.executeTarget("test3"); + assertEquals("original", buildRule.getProject().getProperty("DSTAMP")); + } + + // ensure <condition> follows the immutability rule + @Test + public void test4() { + buildRule.executeTarget("test4"); + assertEquals("original", buildRule.getProject().getProperty("test")); + } + // ensure <checksum> follows the immutability rule + @Test + public void test5() { + buildRule.executeTarget("test5"); + assertEquals("original", buildRule.getProject().getProperty("test")); + } + + // ensure <exec> follows the immutability rule + @Test + public void test6() { + buildRule.executeTarget("test6"); + assertEquals("original", buildRule.getProject().getProperty("test1")); + assertEquals("original", buildRule.getProject().getProperty("test2")); + } + + // ensure <pathconvert> follows the immutability rule + @Test + public void test7() { + buildRule.executeTarget("test7"); + assertEquals("original", buildRule.getProject().getProperty("test")); + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/IncludeTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/IncludeTest.java new file mode 100644 index 00000000..54e61a41 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/IncludeTest.java @@ -0,0 +1,151 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.junit.Rule; +import org.junit.Test; + +/** + * Test the build file inclusion using XML entities. + * + */ +public class IncludeTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Test + public void test1() { + buildRule.configureProject("src/etc/testcases/core/include/basic/include.xml"); + buildRule.executeTarget("test1"); + assertEquals("from included entity", buildRule.getLog()); + } + + @Test + public void test2() { + buildRule.configureProject("src/etc/testcases/core/include/frag#ment/include.xml"); + buildRule.executeTarget("test1"); + assertEquals("from included entity", buildRule.getLog()); + } + + @Test + public void test3() { + buildRule.configureProject("src/etc/testcases/core/include/frag#ment/simple.xml"); + buildRule.executeTarget("test1"); + assertEquals("from simple buildfile", buildRule.getLog()); + } + + @Test + public void test4() { + buildRule.configureProject("src/etc/testcases/core/include/basic/relative.xml"); + buildRule.executeTarget("test1"); + assertEquals("from included entity", buildRule.getLog()); + } + + @Test + public void test5() { + buildRule.configureProject("src/etc/testcases/core/include/frag#ment/relative.xml"); + buildRule.executeTarget("test1"); + assertEquals("from included entity", buildRule.getLog()); + } + + @Test + public void testParseErrorInIncluding() { + try { + buildRule.configureProject("src/etc/testcases/core/include/including_file_parse_error/build.xml"); + fail("should have caused a parser exception"); + } catch (BuildException e) { + assertContains(e.getLocation().toString() + + " should refer to build.xml", + "build.xml:", e.getLocation().toString()); + } + } + + @Test + public void testTaskErrorInIncluding() { + buildRule.configureProject("src/etc/testcases/core/include/including_file_task_error/build.xml"); + try { + buildRule.executeTarget("test"); + fail("should have cause a build failure"); + } catch (BuildException e) { + assertTrue(e.getMessage() + + " should start with \'Warning: Could not find", + e.getMessage().startsWith("Warning: Could not find file ")); + assertTrue(e.getLocation().toString() + + " should end with build.xml:14: ", + e.getLocation().toString().endsWith("build.xml:14: ")); + } + } + + @Test + public void testParseErrorInIncluded() { + try { + buildRule.configureProject("src/etc/testcases/core/include/included_file_parse_error/build.xml"); + fail("should have caused a parser exception"); + } catch (BuildException e) { + assertContains(e.getLocation().toString() + + " should refer to included_file.xml", + "included_file.xml:", + e.getLocation().toString()); + } + } + + @Test + public void testTaskErrorInIncluded() { + buildRule.configureProject("src/etc/testcases/core/include/included_file_task_error/build.xml"); + try { + buildRule.executeTarget("test"); + fail("should have cause a build failure"); + } catch (BuildException e) { + assertTrue(e.getMessage() + + " should start with \'Warning: Could not find", + e.getMessage().startsWith("Warning: Could not find file ")); + assertTrue(e.getLocation().toString() + + " should end with included_file.xml:2: ", + e.getLocation().toString().endsWith("included_file.xml:2: ")); + } + } + + @Test + public void testWithSpaceInclude() { + buildRule.configureProject("src/etc/testcases/core/include/with space/include.xml"); + buildRule.executeTarget("test1"); + assertEquals("from included entity in 'with space'", buildRule.getLog()); + } + + @Test + public void testWithSpaceSimple() { + buildRule.configureProject("src/etc/testcases/core/include/with space/simple.xml"); + buildRule.executeTarget("test1"); + assertEquals("from simple buildfile in 'with space'", buildRule.getLog()); + } + + @Test + public void testWithSpaceRelative() { + buildRule.configureProject("src/etc/testcases/core/include/with space/relative.xml"); + buildRule.executeTarget("test1"); + assertEquals("from included entity in 'with space'", buildRule.getLog()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java new file mode 100644 index 00000000..ca4085d2 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/IntrospectionHelperTest.java @@ -0,0 +1,726 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import java.io.File; +import java.lang.reflect.Method; +import java.lang.reflect.InvocationTargetException; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import org.apache.tools.ant.taskdefs.condition.Os; +import org.junit.Before; +import org.junit.ComparisonFailure; +import org.junit.Ignore; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * JUnit testcases for org.apache.tools.ant.IntrospectionHelper. + * + */ + +public class IntrospectionHelperTest { + + private Project p; + private IntrospectionHelper ih; + private static final String projectBasedir = File.separator; + + @Before + public void setUp() { + p = new Project(); + p.setBasedir(projectBasedir); + ih = IntrospectionHelper.getHelper(getClass()); + } + + @Test + public void testIsDynamic() { + assertFalse("Not dynamic", ih.isDynamic()); + } + + @Test + public void testIsContainer() { + assertFalse("Not a container", ih.isContainer()); + } + + @Test + public void testAddText() throws BuildException { + ih.addText(p, this, "test"); + try { + ih.addText(p, this, "test2"); + fail("test2 shouldn\'t be equal to test"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof ComparisonFailure); + } + + ih = IntrospectionHelper.getHelper(String.class); + try { + ih.addText(p, "", "test"); + fail("String doesn\'t support addText"); + } catch (BuildException be) { + //TODO the value should be asserted + } + } + + @Test + @Ignore("This silently ignores a build exception") + public void testGetAddTextMethod() { + Method m = ih.getAddTextMethod(); + assertMethod(m, "addText", String.class, "test", "bing!"); + + ih = IntrospectionHelper.getHelper(String.class); + try { + m = ih.getAddTextMethod(); + } catch (BuildException e) {} + } + + @Test + public void testSupportsCharacters() { + assertTrue("IntrospectionHelperTest supports addText", + ih.supportsCharacters()); + + ih = IntrospectionHelper.getHelper(String.class); + assertTrue("String doesn\'t support addText", !ih.supportsCharacters()); + } + + public void addText(String text) { + assertEquals("test", text); + } + + @Test + public void testElementCreators() throws BuildException { + try { + ih.getElementType("one"); + fail("don't have element type one"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.getElementType("two"); + fail("createTwo takes arguments"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.getElementType("three"); + fail("createThree returns void"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.getElementType("four"); + fail("createFour returns array"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.getElementType("five"); + fail("createFive returns primitive type"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + assertEquals(String.class, ih.getElementType("six")); + assertEquals("test", ih.createElement(p, this, "six")); + + try { + ih.getElementType("seven"); + fail("addSeven takes two arguments"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.getElementType("eight"); + fail("addEight takes no arguments"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.getElementType("nine"); + fail("nine return non void"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.getElementType("ten"); + fail("addTen takes array argument"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.getElementType("eleven"); + fail("addEleven takes primitive argument"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.getElementType("twelve"); + fail("no primitive constructor for java.lang.Class"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + assertEquals(StringBuffer.class, ih.getElementType("thirteen")); + assertEquals("test", ih.createElement(p, this, "thirteen").toString()); + + try { + ih.createElement(p, this, "fourteen"); + fail("fourteen throws NullPointerException"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof NullPointerException); + } + + try { + ih.createElement(p, this, "fourteen"); + fail("fifteen throws NullPointerException"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof NullPointerException); + } + } + + private Map getExpectedNestedElements() { + Map elemMap = new Hashtable(); + elemMap.put("six", String.class); + elemMap.put("thirteen", StringBuffer.class); + elemMap.put("fourteen", StringBuffer.class); + elemMap.put("fifteen", StringBuffer.class); + return elemMap; + } + + @Test + public void testGetNestedElements() { + Map elemMap = getExpectedNestedElements(); + Enumeration e = ih.getNestedElements(); + while (e.hasMoreElements()) { + String name = (String) e.nextElement(); + Class expect = (Class) elemMap.get(name); + assertNotNull("Support for "+name+" in IntrospectioNHelperTest?", + expect); + assertEquals("Return type of "+name, expect, ih.getElementType(name)); + elemMap.remove(name); + } + assertTrue("Found all", elemMap.isEmpty()); + } + + @Test + public void testGetNestedElementMap() { + Map elemMap = getExpectedNestedElements(); + Map actualMap = ih.getNestedElementMap(); + for (Iterator i = actualMap.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + String elemName = (String) entry.getKey(); + Class elemClass = (Class) elemMap.get(elemName); + assertNotNull("Support for " + elemName + + " in IntrospectionHelperTest?", elemClass); + assertEquals("Type of " + elemName, elemClass, entry.getValue()); + elemMap.remove(elemName); + } + assertTrue("Found all", elemMap.isEmpty()); + + // Check it's a read-only map. + try { + actualMap.clear(); + //TODO we should be asserting a value somewhere in here + } catch (UnsupportedOperationException e) {} + } + + @Test + public void testGetElementMethod() { + assertElemMethod("six", "createSix", String.class, null); + assertElemMethod("thirteen", "addThirteen", null, StringBuffer.class); + assertElemMethod("fourteen", "addFourteen", null, StringBuffer.class); + assertElemMethod("fifteen", "createFifteen", StringBuffer.class, null); + } + + private void assertElemMethod(String elemName, String methodName, + Class returnType, Class methodArg) { + Method m = ih.getElementMethod(elemName); + assertEquals("Method name", methodName, m.getName()); + Class expectedReturnType = (returnType == null)? Void.TYPE: returnType; + assertEquals("Return type", expectedReturnType, m.getReturnType()); + Class[] args = m.getParameterTypes(); + if (methodArg != null) { + assertEquals("Arg Count", 1, args.length); + assertEquals("Arg Type", methodArg, args[0]); + } else { + assertEquals("Arg Count", 0, args.length); + } + } + + public Object createTwo(String s) { + return null; + } + + public void createThree() {} + + public Object[] createFour() { + return null; + } + + public int createFive() { + return 0; + } + + public String createSix() { + return "test"; + } + + public StringBuffer createFifteen() { + throw new NullPointerException(); + } + + public void addSeven(String s, String s2) {} + + public void addEight() {} + + public String addNine(String s) { + return null; + } + + public void addTen(String[] s) {} + + public void addEleven(int i) {} + + public void addTwelve(Class c) {} + + public void addThirteen(StringBuffer sb) { + sb.append("test"); + } + + public void addFourteen(StringBuffer s) { + throw new NullPointerException(); + } + + @Test + public void testAttributeSetters() throws BuildException { + try { + ih.setAttribute(p, this, "one", "test"); + fail("setOne doesn't exist"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.setAttribute(p, this, "two", "test"); + fail("setTwo returns non void"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.setAttribute(p, this, "three", "test"); + fail("setThree takes no args"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.setAttribute(p, this, "four", "test"); + fail("setFour takes two args"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.setAttribute(p, this, "five", "test"); + fail("setFive takes array arg"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + try { + ih.setAttribute(p, this, "six", "test"); + fail("Project doesn't have a String constructor"); + } catch (BuildException be) { + //TODO we should be asserting a value in here + } + ih.setAttribute(p, this, "seven", "2"); + try { + ih.setAttribute(p, this, "seven", "3"); + fail("2 shouldn't be equals to three"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof ComparisonFailure); + } + ih.setAttribute(p, this, "eight", "2"); + try { + ih.setAttribute(p, this, "eight", "3"); + fail("2 shouldn't be equals to three - as int"); + } catch (BuildException be) { + assertTrue("Cause of error: " + be.toString(), be.getCause() instanceof AssertionError); + } + ih.setAttribute(p, this, "nine", "2"); + try { + ih.setAttribute(p, this, "nine", "3"); + fail("2 shouldn't be equals to three - as Integer"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof AssertionError); + } + ih.setAttribute(p, this, "ten", "2"); + try { + ih.setAttribute(p, this, "ten", "3"); + fail(projectBasedir+"2 shouldn't be equals to "+projectBasedir+"3"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof AssertionError); + } + ih.setAttribute(p, this, "eleven", "2"); + try { + ih.setAttribute(p, this, "eleven", "on"); + fail("on shouldn't be false"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof AssertionError); + } + ih.setAttribute(p, this, "twelve", "2"); + try { + ih.setAttribute(p, this, "twelve", "on"); + fail("on shouldn't be false"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof AssertionError); + } + ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.Project"); + try { + ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.ProjectHelper"); + fail("org.apache.tools.ant.Project shouldn't be equal to org.apache.tools.ant.ProjectHelper"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof AssertionError); + } + try { + ih.setAttribute(p, this, "thirteen", "org.apache.tools.ant.Project2"); + fail("org.apache.tools.ant.Project2 doesn't exist"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof ClassNotFoundException); + } + ih.setAttribute(p, this, "fourteen", "2"); + try { + ih.setAttribute(p, this, "fourteen", "on"); + fail("2 shouldn't be equals to three - as StringBuffer"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof ComparisonFailure); + } + ih.setAttribute(p, this, "fifteen", "abcd"); + try { + ih.setAttribute(p, this, "fifteen", "on"); + fail("o shouldn't be equal to a"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof AssertionError); + } + ih.setAttribute(p, this, "sixteen", "abcd"); + try { + ih.setAttribute(p, this, "sixteen", "on"); + fail("o shouldn't be equal to a"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof AssertionError); + } + ih.setAttribute(p, this, "seventeen", "17"); + try { + ih.setAttribute(p, this, "seventeen", "3"); + fail("17 shouldn't be equals to three"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof AssertionError); + } + ih.setAttribute(p, this, "eightteen", "18"); + try { + ih.setAttribute(p, this, "eightteen", "3"); + fail("18 shouldn't be equals to three"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof AssertionError); + } + ih.setAttribute(p, this, "nineteen", "19"); + try { + ih.setAttribute(p, this, "nineteen", "3"); + fail("19 shouldn't be equals to three"); + } catch (BuildException be) { + assertTrue(be.getCause() instanceof AssertionError); + } + } + + private Map getExpectedAttributes() { + Map attrMap = new Hashtable(); + attrMap.put("seven", String.class); + attrMap.put("eight", Integer.TYPE); + attrMap.put("nine", Integer.class); + attrMap.put("ten", File.class); + attrMap.put("eleven", Boolean.TYPE); + attrMap.put("twelve", Boolean.class); + attrMap.put("thirteen", Class.class); + attrMap.put("fourteen", StringBuffer.class); + attrMap.put("fifteen", Character.TYPE); + attrMap.put("sixteen", Character.class); + attrMap.put("seventeen", Byte.TYPE); + attrMap.put("eightteen", Short.TYPE); + attrMap.put("nineteen", Double.TYPE); + + /* + * JUnit 3.7 adds a getName method to TestCase - so we now + * have a name attribute in IntrospectionHelperTest if we run + * under JUnit 3.7 but not in earlier versions. + * + * Simply add it here and remove it after the tests. + */ + attrMap.put("name", String.class); + + return attrMap; + } + + @Test + public void testGetAttributes() { + Map attrMap = getExpectedAttributes(); + Enumeration e = ih.getAttributes(); + while (e.hasMoreElements()) { + String name = (String) e.nextElement(); + Class expect = (Class) attrMap.get(name); + assertNotNull("Support for "+name+" in IntrospectionHelperTest?", + expect); + assertEquals("Type of "+name, expect, ih.getAttributeType(name)); + attrMap.remove(name); + } + attrMap.remove("name"); + assertTrue("Found all", attrMap.isEmpty()); + } + + @Test + public void testGetAttributeMap() { + Map attrMap = getExpectedAttributes(); + Map actualMap = ih.getAttributeMap(); + for (Iterator i = actualMap.entrySet().iterator(); i.hasNext();) { + Map.Entry entry = (Map.Entry) i.next(); + String attrName = (String) entry.getKey(); + Class attrClass = (Class) attrMap.get(attrName); + assertNotNull("Support for " + attrName + + " in IntrospectionHelperTest?", attrClass); + assertEquals("Type of " + attrName, attrClass, entry.getValue()); + attrMap.remove(attrName); + } + attrMap.remove("name"); + assertTrue("Found all", attrMap.isEmpty()); + + // Check it's a read-only map. + try { + actualMap.clear(); + //TODO we should be asserting a value somewhere in here + } catch (UnsupportedOperationException e) {} + } + + @Test + public void testGetAttributeMethod() { + assertAttrMethod("seven", "setSeven", String.class, + "2", "3"); + assertAttrMethod("eight", "setEight", Integer.TYPE, + new Integer(2), new Integer(3)); + assertAttrMethod("nine", "setNine", Integer.class, + new Integer(2), new Integer(3)); + assertAttrMethod("ten", "setTen", File.class, + new File(projectBasedir + 2), new File("toto")); + assertAttrMethod("eleven", "setEleven", Boolean.TYPE, + Boolean.FALSE, Boolean.TRUE); + assertAttrMethod("twelve", "setTwelve", Boolean.class, + Boolean.FALSE, Boolean.TRUE); + assertAttrMethod("thirteen", "setThirteen", Class.class, + Project.class, Map.class); + assertAttrMethod("fourteen", "setFourteen", StringBuffer.class, + new StringBuffer("2"), new StringBuffer("3")); + assertAttrMethod("fifteen", "setFifteen", Character.TYPE, + new Character('a'), new Character('b')); + assertAttrMethod("sixteen", "setSixteen", Character.class, + new Character('a'), new Character('b')); + assertAttrMethod("seventeen", "setSeventeen", Byte.TYPE, + new Byte((byte)17), new Byte((byte)10)); + assertAttrMethod("eightteen", "setEightteen", Short.TYPE, + new Short((short)18), new Short((short)10)); + assertAttrMethod("nineteen", "setNineteen", Double.TYPE, + new Double(19), new Double((short)10)); + + try { + assertAttrMethod("onehundred", null, null, null, null); + fail("Should have raised a BuildException!"); + } catch (BuildException e) { + //TODO we should be asserting a value in here + } + } + + private void assertAttrMethod(String attrName, String methodName, + Class methodArg, Object arg, Object badArg) { + Method m = ih.getAttributeMethod(attrName); + assertMethod(m, methodName, methodArg, arg, badArg); + } + + public int setTwo(String s) { + return 0; + } + + public void setThree() {} + + public void setFour(String s1, String s2) {} + + public void setFive(String[] s) {} + + public void setSix(Project p) {} + + public void setSeven(String s) { + assertEquals("2", s); + } + + public void setEight(int i) { + assertEquals(2, i); + } + + public void setNine(Integer i) { + assertEquals(2, i.intValue()); + } + + public void setTen(File f) { + String path = f.getAbsolutePath(); + if (Os.isFamily("unix") || Os.isFamily("openvms")) { + assertEquals(projectBasedir+"2", path); + } else if (Os.isFamily("netware")) { + assertEquals(projectBasedir+"2", path.toLowerCase(Locale.US)); + } else { + assertEquals(":"+projectBasedir+"2", + path.toLowerCase(Locale.US).substring(1)); + } + } + + public void setEleven(boolean b) { + assertTrue(!b); + } + + public void setTwelve(Boolean b) { + assertTrue(!b.booleanValue()); + } + + public void setThirteen(Class c) { + assertEquals(Project.class, c); + } + + public void setFourteen(StringBuffer sb) { + assertEquals("2", sb.toString()); + } + + public void setFifteen(char c) { + assertEquals(c, 'a'); + } + + public void setSixteen(Character c) { + assertEquals(c.charValue(), 'a'); + } + + public void setSeventeen(byte b) { + assertEquals(17, b); + } + + public void setEightteen(short s) { + assertEquals(18, s); + } + + public void setNineteen(double d) { + double diff = d - 19; + assertTrue("Expected 19, received " + d, diff > -1e-6 && diff < 1e-6); + } + + @Test + public void testGetExtensionPoints() { + List extensions = ih.getExtensionPoints(); + final int adders = 2; + assertEquals("extension count", adders, extensions.size()); + + // this original test assumed something about the order of + // add(Number) and addConfigured(Map) returned by reflection. + // Unfortunately the assumption doesn't hold for all VMs + // (failed on MacOS X using JDK 1.4.2_05) and the possible + // combinatorics are too hard to check. We really only want + // to ensure that the more derived Hashtable can be found + // before Map. +// assertExtMethod(extensions.get(0), "add", Number.class, +// new Integer(2), new Integer(3)); + + // addConfigured(Hashtable) should come before addConfigured(Map) + assertExtMethod(extensions.get(adders - 2), + "addConfigured", Hashtable.class, + makeTable("key", "value"), makeTable("1", "2")); + + assertExtMethod(extensions.get(adders - 1), "addConfigured", Map.class, + new HashMap(), makeTable("1", "2")); + } + + private void assertExtMethod(Object mo, String methodName, Class methodArg, + Object arg, Object badArg) { + assertMethod((Method) mo, methodName, methodArg, arg, badArg); + } + + private void assertMethod(Method m, String methodName, Class methodArg, + Object arg, Object badArg) { + assertEquals("Method name", methodName, m.getName()); + assertEquals("Return type", Void.TYPE, m.getReturnType()); + Class[] args = m.getParameterTypes(); + assertEquals("Arg Count", 1, args.length); + assertEquals("Arg Type", methodArg, args[0]); + + try { + m.invoke(this, new Object[] { arg }); + } catch (IllegalAccessException e) { + throw new BuildException(e); + } catch (InvocationTargetException e) { + throw new BuildException(e); + } + + try { + m.invoke(this, new Object[] { badArg }); + fail("Should have raised an assertion exception"); + } catch (IllegalAccessException e) { + throw new BuildException(e); + } catch (InvocationTargetException e) { + Throwable t = e.getTargetException(); + assertTrue(t.toString(), t instanceof AssertionError); + } + } + + public List add(List l) { + // INVALID extension point + return null; + } + + // see comments in testGetExtensionPoints +// public void add(Number n) { +// // Valid extension point +// assertEquals(2, n.intValue()); +// } + + public void add(List l, int i) { + // INVALID extension point + } + + public void addConfigured(Map m) { + // Valid extension point + assertTrue(m.size() == 0); + } + + public void addConfigured(Hashtable h) { + // Valid extension point, more derived than Map above, but *after* it! + assertEquals(makeTable("key", "value"), h); + } + + private Hashtable makeTable(Object key, Object value) { + Hashtable table = new Hashtable(); + table.put(key, value); + return table; + } + +} // IntrospectionHelperTest + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/LoaderRefTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/LoaderRefTest.java new file mode 100644 index 00000000..2fb7439b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/LoaderRefTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.fail; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + */ +public class LoaderRefTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/core/loaderref/loaderref.xml"); + buildRule.executeTarget("setUp"); + } + + // override allowed on <available> + @Test + public void testBadRef() { + try { + buildRule.executeTarget("testbadref"); + fail("BuildRule should have thrown an exception due to a bad classloader being specified"); + } catch (BuildException ex) { + assertContains("Should fail due to ref not being a class loader", "does not reference a class loader", ex.getMessage()); + } + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/LocationTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/LocationTest.java new file mode 100644 index 00000000..c8048a31 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/LocationTest.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.apache.tools.ant.taskdefs.ConditionTask; +import org.apache.tools.ant.taskdefs.Echo; +import org.apache.tools.ant.types.FileSet; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +public class LocationTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/core/location.xml"); + } + + @Test + public void testPlainTask() { + buildRule.executeTarget("testPlainTask"); + Echo e = (Echo) buildRule.getProject().getReference("echo"); + assertFalse(e.getLocation() == Location.UNKNOWN_LOCATION); + assertFalse(e.getLocation().getLineNumber() == 0); + } + + @Test + public void testStandaloneType() { + buildRule.executeTarget("testStandaloneType"); + Echo e = (Echo) buildRule.getProject().getReference("echo2"); + FileSet f = (FileSet) buildRule.getProject().getReference("fs"); + assertFalse(f.getLocation() == Location.UNKNOWN_LOCATION); + assertEquals(e.getLocation().getLineNumber() + 1, + f.getLocation().getLineNumber()); + } + + @Test + public void testConditionTask() { + buildRule.executeTarget("testConditionTask"); + TaskAdapter ta = (TaskAdapter) buildRule.getProject().getReference("cond"); + ConditionTask c = (ConditionTask) ta.getProxy(); + assertFalse(c.getLocation() == Location.UNKNOWN_LOCATION); + assertFalse(c.getLocation().getLineNumber() == 0); + } + + @Test + public void testMacrodefWrappedTask() { + buildRule.executeTarget("testMacrodefWrappedTask"); + Echo e = (Echo) buildRule.getProject().getReference("echo3"); + assertTrue(buildRule.getLog().indexOf("Line: " + + (e.getLocation().getLineNumber() + 1)) + > -1); + } + + @Test + public void testPresetdefWrappedTask() { + buildRule.executeTarget("testPresetdefWrappedTask"); + Echo e = (Echo) buildRule.getProject().getReference("echo4"); + assertTrue(buildRule.getLog().indexOf("Line: " + + (e.getLocation().getLineNumber() + 1)) + > -1); + } + + public static class EchoLocation extends Task { + public void execute() { + log("Line: " + getLocation().getLineNumber(), Project.MSG_INFO); + } + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/MockBuildListener.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/MockBuildListener.java new file mode 100644 index 00000000..e3a96a85 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/MockBuildListener.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; + +import java.util.Vector; + +public class MockBuildListener implements BuildListener { + + private final Vector<BuildEvent> buffer = new Vector<BuildEvent>(); + private final Project project; + + public MockBuildListener(final Project project) { + this.project = project; + } + + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) {} + public void targetStarted(BuildEvent event) {} + public void targetFinished(BuildEvent event) {} + public void taskStarted(BuildEvent event) {} + public void taskFinished(BuildEvent event) {} + + public void messageLogged(final BuildEvent actual) { + if(actual.getPriority()==Project.MSG_DEBUG) + return; + assertTrue("unexpected messageLogged: "+actual.getMessage(), !buffer.isEmpty()); + assertEquals("unexpected project ", project, actual.getProject()); + + BuildEvent expected = (BuildEvent) buffer.elementAt(0); + buffer.removeElementAt(0); + assertEquals("unexpected messageLogged ", expected.getMessage(), actual.getMessage()); + assertEquals("unexpected priority ", expected.getPriority(), actual.getPriority()); + } + + public void assertEmpty() { + assertTrue("MockBuildListener is not empty", buffer.isEmpty()); + } + + public void addBuildEvent(final String message, final int priority) { + final BuildEvent be = new BuildEvent(project); + be.setMessage(message, priority); + buffer.addElement(be); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/PickOneTask.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/PickOneTask.java new file mode 100644 index 00000000..560194b0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/PickOneTask.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.apache.tools.ant.dispatch.DispatchTask; + +public class PickOneTask extends DispatchTask { + public void list() { + throw new BuildException("list"); + } + + public void show() { + throw new BuildException("show"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ProjectComponentTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ProjectComponentTest.java new file mode 100644 index 00000000..44ea56fb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ProjectComponentTest.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.junit.Test; + +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; + +public class ProjectComponentTest { + + @Test + public void testClone() throws CloneNotSupportedException { + Project expectedProject = new Project(); + Location expectedLocation = new Location("foo"); + String expectedDescription = "bar"; + + // use an anonymous subclass since ProjectComponent is abstract + ProjectComponent pc = new ProjectComponent() { + }; + pc.setProject(expectedProject); + pc.setLocation(expectedLocation); + pc.setDescription(expectedDescription); + + ProjectComponent cloned = (ProjectComponent) pc.clone(); + assertNotSame(pc, cloned); + assertSame(cloned.getProject(), expectedProject); + assertSame(cloned.getLocation(), expectedLocation); + assertSame(cloned.getDescription(), expectedDescription); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ProjectHelperRepositoryTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ProjectHelperRepositoryTest.java new file mode 100644 index 00000000..550c342b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ProjectHelperRepositoryTest.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import java.io.File; + +import org.apache.tools.ant.helper.ProjectHelper2; +import org.apache.tools.ant.types.Resource; +import org.apache.tools.ant.types.resources.FileResource; +import org.apache.tools.ant.types.resources.StringResource; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Testing around the management of the project helpers + */ +public class ProjectHelperRepositoryTest { + + public static class SomeHelper extends ProjectHelper { + public boolean canParseBuildFile(Resource buildFile) { + return buildFile instanceof FileResource + && buildFile.getName().endsWith(".myext"); + } + + public boolean canParseAntlibDescriptor(Resource r) { + return r instanceof FileResource && r.getName().endsWith(".myext"); + } + } + + @Test + public void testFind() throws Exception { + ProjectHelperRepository repo = ProjectHelperRepository.getInstance(); + repo.registerProjectHelper(SomeHelper.class); + + Resource r = new FileResource(new File("test.xml")); + ProjectHelper helper = repo.getProjectHelperForBuildFile(r); + assertTrue(helper instanceof ProjectHelper2); + helper = repo.getProjectHelperForAntlib(r); + assertTrue(helper instanceof ProjectHelper2); + + r = new FileResource(new File("test.myext")); + helper = repo.getProjectHelperForBuildFile(r); + assertTrue(helper instanceof SomeHelper); + helper = repo.getProjectHelperForAntlib(r); + assertTrue(helper instanceof SomeHelper); + + r = new StringResource("test.myext"); + helper = repo.getProjectHelperForBuildFile(r); + assertTrue(helper instanceof ProjectHelper2); + helper = repo.getProjectHelperForAntlib(r); + assertTrue(helper instanceof ProjectHelper2); + + r = new StringResource("test.other"); + helper = repo.getProjectHelperForBuildFile(r); + assertTrue(helper instanceof ProjectHelper2); + helper = repo.getProjectHelperForAntlib(r); + assertTrue(helper instanceof ProjectHelper2); + } + + @Test + public void testNoDefaultContructor() throws Exception { + + class IncrrectHelper extends ProjectHelper { + // the default constructor is not visible to ant here + } + + ProjectHelperRepository repo = ProjectHelperRepository.getInstance(); + try { + repo.registerProjectHelper(IncrrectHelper.class); + fail("Registring an helper with no default constructor should fail"); + } catch (BuildException e) { + // ok + //TODO we should be asserting a value in here + } + } + + @Test + public void testUnkwnowHelper() throws Exception { + ProjectHelperRepository repo = ProjectHelperRepository.getInstance(); + try { + repo.registerProjectHelper("xxx.yyy.zzz.UnknownHelper"); + fail("Registring an unknwon helper should fail"); + } catch (BuildException e) { + // ok + //TODO we should be asserting a value in here + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ProjectTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ProjectTest.java new file mode 100644 index 00000000..17c15c22 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/ProjectTest.java @@ -0,0 +1,327 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.apache.tools.ant.input.DefaultInputHandler; +import org.apache.tools.ant.input.InputHandler; +import org.apache.tools.ant.input.PropertyFileInputHandler; +import org.apache.tools.ant.taskdefs.condition.Os; + +import java.io.File; + +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.PatternSet; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + + +/** + * Very limited test class for Project. Waiting to be extended. + * + */ +public class ProjectTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private Project p; + private String root; + private MockBuildListener mbl; + + @Before + public void setUp() { + p = new Project(); + p.init(); + root = new File(File.separator).getAbsolutePath().toUpperCase(); + mbl = new MockBuildListener(p); + } + + @Test + public void testDataTypes() throws BuildException { + assertNull("dummy is not a known data type", + p.createDataType("dummy")); + Object o = p.createDataType("fileset"); + assertNotNull("fileset is a known type", o); + assertTrue("fileset creates FileSet", o instanceof FileSet); + assertTrue("PatternSet", + p.createDataType("patternset") instanceof PatternSet); + assertTrue("Path", p.createDataType("path") instanceof Path); + } + + /** + * This test has been a starting point for moving the code to FileUtils. + */ + @Test + public void testResolveFile() { + if (Os.isFamily("netware") || Os.isFamily("dos")) { + assertEqualsIgnoreDriveCase(localize(File.separator), + p.resolveFile("/", null).getPath()); + assertEqualsIgnoreDriveCase(localize(File.separator), + p.resolveFile("\\", null).getPath()); + /* + * throw in drive letters + */ + String driveSpec = "C:"; + String driveSpecLower = "c:"; + + assertEqualsIgnoreDriveCase(driveSpecLower + "\\", + p.resolveFile(driveSpec + "/", null).getPath()); + assertEqualsIgnoreDriveCase(driveSpecLower + "\\", + p.resolveFile(driveSpec + "\\", null).getPath()); + assertEqualsIgnoreDriveCase(driveSpecLower + "\\", + p.resolveFile(driveSpecLower + "/", null).getPath()); + assertEqualsIgnoreDriveCase(driveSpecLower + "\\", + p.resolveFile(driveSpecLower + "\\", null).getPath()); + /* + * promised to eliminate consecutive slashes after drive letter. + */ + assertEqualsIgnoreDriveCase(driveSpec + "\\", + p.resolveFile(driveSpec + "/////", null).getPath()); + assertEqualsIgnoreDriveCase(driveSpec + "\\", + p.resolveFile(driveSpec + "\\\\\\\\\\\\", null).getPath()); + } else { + /* + * Start with simple absolute file names. + */ + assertEquals(File.separator, + p.resolveFile("/", null).getPath()); + assertEquals(File.separator, + p.resolveFile("\\", null).getPath()); + /* + * drive letters are not used, just to be considered as normal + * part of a name + */ + String driveSpec = "C:"; + String udir = System.getProperty("user.dir") + File.separatorChar; + assertEquals(udir + driveSpec, + p.resolveFile(driveSpec + "/", null).getPath()); + assertEquals(udir + driveSpec, + p.resolveFile(driveSpec + "\\", null).getPath()); + String driveSpecLower = "c:"; + assertEquals(udir + driveSpecLower, + p.resolveFile(driveSpecLower + "/", null).getPath()); + assertEquals(udir + driveSpecLower, + p.resolveFile(driveSpecLower + "\\", null).getPath()); + } + /* + * Now test some relative file name magic. + */ + assertEquals(localize("/1/2/3/4"), + p.resolveFile("4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile("./4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile(".\\4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile("./.\\4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile("../3/4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile("..\\3\\4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile("../../5/.././2/./3/6/../4", new File(localize("/1/2/3"))).getPath()); + assertEquals(localize("/1/2/3/4"), + p.resolveFile("..\\../5/..\\./2/./3/6\\../4", new File(localize("/1/2/3"))).getPath()); + + } + + /** + * adapt file separators to local conventions + */ + private String localize(String path) { + path = root + path.substring(1); + return path.replace('\\', File.separatorChar).replace('/', File.separatorChar); + } + + /** + * convenience method + * the drive letter is in lower case under cygwin + * calling this method allows tests where FileUtils.normalize + * is called via resolveFile to pass under cygwin + */ + private void assertEqualsIgnoreDriveCase(String s1, String s2) { + if ((Os.isFamily("dos") || Os.isFamily("netware")) + && s1.length() >= 1 && s2.length() >= 1) { + StringBuffer sb1 = new StringBuffer(s1); + StringBuffer sb2 = new StringBuffer(s2); + sb1.setCharAt(0, Character.toUpperCase(s1.charAt(0))); + sb2.setCharAt(0, Character.toUpperCase(s2.charAt(0))); + assertEquals(sb1.toString(), sb2.toString()); + } else { + assertEquals(s1, s2); + } + } + + private void assertTaskDefFails(final Class taskClass, + final String message) { + final String dummyName = "testTaskDefinitionDummy"; + try { + mbl.addBuildEvent(message, Project.MSG_ERR); + p.addTaskDefinition(dummyName, taskClass); + fail("expected BuildException(\""+message+"\", Project.MSG_ERR) when adding task " + taskClass); + } + catch(BuildException e) { + assertEquals(message, e.getMessage()); + mbl.assertEmpty(); + assertTrue(!p.getTaskDefinitions().containsKey(dummyName)); + } + } + + @Test + public void testAddTaskDefinition() { + p.addBuildListener(mbl); + + p.addTaskDefinition("Ok", DummyTaskOk.class); + assertEquals(DummyTaskOk.class, p.getTaskDefinitions().get("Ok")); + p.addTaskDefinition("OkNonTask", DummyTaskOkNonTask.class); + assertEquals(DummyTaskOkNonTask.class, p.getTaskDefinitions().get("OkNonTask")); + mbl.assertEmpty(); + + assertTaskDefFails(DummyTaskPrivate.class, DummyTaskPrivate.class + " is not public"); + + assertTaskDefFails(DummyTaskProtected.class, + DummyTaskProtected.class + " is not public"); + + assertTaskDefFails(DummyTaskPackage.class, DummyTaskPackage.class + " is not public"); + + assertTaskDefFails(DummyTaskAbstract.class, DummyTaskAbstract.class + " is abstract"); + assertTaskDefFails(DummyTaskInterface.class, DummyTaskInterface.class + " is abstract"); + + assertTaskDefFails(DummyTaskWithoutDefaultConstructor.class, "No public no-arg constructor in " + DummyTaskWithoutDefaultConstructor.class); + assertTaskDefFails(DummyTaskWithoutPublicConstructor.class, "No public no-arg constructor in " + DummyTaskWithoutPublicConstructor.class); + + assertTaskDefFails(DummyTaskWithoutExecute.class, "No public execute() in " + DummyTaskWithoutExecute.class); + assertTaskDefFails(DummyTaskWithNonPublicExecute.class, "No public execute() in " + DummyTaskWithNonPublicExecute.class); + + mbl.addBuildEvent("return type of execute() should be void but was \"int\" in " + DummyTaskWithNonVoidExecute.class, Project.MSG_WARN); + p.addTaskDefinition("NonVoidExecute", DummyTaskWithNonVoidExecute.class); + mbl.assertEmpty(); + assertEquals(DummyTaskWithNonVoidExecute.class, p.getTaskDefinitions().get("NonVoidExecute")); + } + + @Test + public void testInputHandler() { + InputHandler ih = p.getInputHandler(); + assertNotNull(ih); + assertTrue(ih instanceof DefaultInputHandler); + InputHandler pfih = new PropertyFileInputHandler(); + p.setInputHandler(pfih); + assertSame(pfih, p.getInputHandler()); + } + + @Test + public void testTaskDefinitionContainsKey() { + assertTrue(p.getTaskDefinitions().containsKey("echo")); + } + + @Test + public void testTaskDefinitionContains() { + assertTrue(p.getTaskDefinitions().contains(org.apache.tools.ant.taskdefs.Echo.class)); + } + + @Test + public void testDuplicateTargets() { + // fail, because buildfile contains two targets with the same name + try { + buildRule.configureProject("src/etc/testcases/core/duplicate-target.xml"); + fail("Should throw BuildException about duplicate target"); + } catch (BuildException ex) { + assertEquals("specific message", + "Duplicate target 'twice'", + ex.getMessage()); + } + } + + @Test + public void testDuplicateTargetsImport() { + // overriding target from imported buildfile is allowed + buildRule.configureProject("src/etc/testcases/core/duplicate-target2.xml"); + buildRule.executeTarget("once"); + assertContains("once from buildfile", buildRule.getLog()); + } + + @Test + public void testOutputDuringMessageLoggedIsSwallowed() + throws InterruptedException { + final String FOO = "foo", BAR = "bar"; + p.addBuildListener(new BuildListener() { + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) {} + public void targetStarted(BuildEvent event) {} + public void targetFinished(BuildEvent event) {} + public void taskStarted(BuildEvent event) {} + public void taskFinished(BuildEvent event) {} + public void messageLogged(final BuildEvent actual) { + assertEquals(FOO, actual.getMessage()); + // each of the following lines would cause an + // infinite loop if the message wasn't swallowed + System.err.println(BAR); + System.out.println(BAR); + p.log(BAR, Project.MSG_INFO); + } + }); + final boolean[] done = new boolean[] {false}; + Thread t = new Thread() { + public void run() { + p.log(FOO, Project.MSG_INFO); + done[0] = true; + } + }; + t.start(); + t.join(2000); + assertTrue("Expected logging thread to finish successfully", done[0]); + } + + /** + * @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=47623"> + * https://issues.apache.org/bugzilla/show_bug.cgi?id=47623</a> + */ + @Test + public void testNullThrowableMessageLog() { + p.log(new Task() {}, null, new Throwable(), Project.MSG_ERR); + // be content if no exception has been thrown + } + + private class DummyTaskPrivate extends Task { + public DummyTaskPrivate() {} + public void execute() {} + } + + protected class DummyTaskProtected extends Task { + public DummyTaskProtected() {} + public void execute() {} + } + + + class DummyTaskPackage extends Task { + public DummyTaskPackage() {} + public void execute() {} + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/PropertyExpansionTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/PropertyExpansionTest.java new file mode 100644 index 00000000..4ac8c5f7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/PropertyExpansionTest.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * class to look at how we expand properties + */ +public class PropertyExpansionTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + /** + * we bind to an existing test file because we are too lazy to write our + * own, and we don't really care what it is + */ + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/core/immutable.xml"); + } + + /** + * run through the test cases of expansion + */ + @Test + public void testPropertyExpansion() { + assertExpandsTo("",""); + assertExpandsTo("$","$"); + assertExpandsTo("$$-","$-"); + assertExpandsTo("$$","$"); + buildRule.getProject().setProperty("expanded","EXPANDED"); + assertExpandsTo("a${expanded}b","aEXPANDEDb"); + assertExpandsTo("${expanded}${expanded}","EXPANDEDEXPANDED"); + assertExpandsTo("$$$","$$"); + assertExpandsTo("$$$$-","$$-"); + assertExpandsTo("",""); + assertExpandsTo("Class$$subclass","Class$subclass"); + } + + /** + * new things we want + */ + @Test + public void testDollarPassthru() { + assertExpandsTo("$-","$-"); + assertExpandsTo("Class$subclass","Class$subclass"); + assertExpandsTo("$$$-","$$-"); + assertExpandsTo("$$$$$","$$$"); + assertExpandsTo("${unassigned.property}","${unassigned.property}"); + assertExpandsTo("a$b","a$b"); + assertExpandsTo("$}}","$}}"); + } + + + /** + * old things we dont want; not a test no more + */ + @Test + @Ignore("Previously disabled through naming convention") + public void oldtestQuirkyLegacyBehavior() { + assertExpandsTo("Class$subclass","Classsubclass"); + assertExpandsTo("$$$-","$-"); + assertExpandsTo("a$b","ab"); + assertExpandsTo("$}}","}}"); + } + + /** + * little helper method to validate stuff + */ + private void assertExpandsTo(String source,String expected) { + String actual = buildRule.getProject().replaceProperties(source); + assertEquals(source,expected,actual); + } + +//end class +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java new file mode 100644 index 00000000..37188829 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/PropertyFileCLITest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import java.io.File; +import java.io.FileReader; +import java.io.FileWriter; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; + +public class PropertyFileCLITest { + + @Test + public void testPropertyResolution() throws Exception { + FileUtils fu = FileUtils.getFileUtils(); + File props = fu.createTempFile("propertyfilecli", ".properties", + null, true, true); + File build = fu.createTempFile("propertyfilecli", ".xml", null, true, + true); + File log = fu.createTempFile("propertyfilecli", ".log", null, true, + true); + FileWriter fw = null; + FileReader fr = null; + try { + fw = new FileWriter(props); + fw.write("w=world\nmessage=Hello, ${w}\n"); + fw.close(); + fw = new FileWriter(build); + fw.write("<project><echo>${message}</echo></project>"); + fw.close(); + fw = null; + Main m = new NoExitMain(); + m.startAnt(new String[] { + "-propertyfile", props.getAbsolutePath(), + "-f", build.getAbsolutePath(), + "-l", log.getAbsolutePath() + }, null, null); + String l = FileUtils.safeReadFully(fr = new FileReader(log)); + assertContains("Hello, world", l); + } finally { + FileUtils.close(fw); + FileUtils.close(fr); + } + } + + private static class NoExitMain extends Main { + protected void exit(int exitCode) { + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/TaskContainerTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/TaskContainerTest.java new file mode 100644 index 00000000..700b7c11 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/TaskContainerTest.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class TaskContainerTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/core/taskcontainer.xml"); + } + + @Test + public void testPropertyExpansion() { + buildRule.executeTarget("testPropertyExpansion"); + assertTrue("attribute worked", + buildRule.getLog().indexOf("As attribute: it worked") > -1); + assertTrue("nested text worked", + buildRule.getLog().indexOf("As nested text: it worked") > -1); + } + + @Test + public void testTaskdef() { + buildRule.executeTarget("testTaskdef"); + assertTrue("attribute worked", + buildRule.getLog().indexOf("As attribute: it worked") > -1); + assertTrue("nested text worked", + buildRule.getLog().indexOf("As nested text: it worked") > -1); + assertTrue("nested text worked", + buildRule.getLog().indexOf("As nested task: it worked") > -1); + } + + @Test + public void testCaseInsensitive() { + buildRule.executeTarget("testCaseInsensitive"); + assertTrue("works outside of container", + buildRule.getLog().indexOf("hello ") > -1); + assertTrue("works inside of container", + buildRule.getLog().indexOf("world") > -1); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/TopLevelTaskTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/TopLevelTaskTest.java new file mode 100644 index 00000000..7d73dc0e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/TopLevelTaskTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +// This test will fail with embed, or if top-level is moved out of +// dependency - as 'echo' happens as part of configureProject stage. + +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Tests for builds with tasks at the top level + * + * @since Ant 1.6 + */ +public class TopLevelTaskTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Test + public void testNoTarget() { + buildRule.configureProject("src/etc/testcases/core/topleveltasks/notarget.xml"); + buildRule.executeTarget(""); + assertEquals("Called", buildRule.getLog()); + } + + @Test + public void testCalledFromTopLevelAnt() { + buildRule.configureProject("src/etc/testcases/core/topleveltasks/toplevelant.xml"); + buildRule.executeTarget(""); + assertEquals("Called", buildRule.getLog()); + } + + @Test + public void testCalledFromTargetLevelAnt() { + buildRule.configureProject("src/etc/testcases/core/topleveltasks/targetlevelant.xml"); + buildRule.executeTarget("foo"); + assertEquals("Called", buildRule.getLog()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/UnknownElementTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/UnknownElementTest.java new file mode 100644 index 00000000..be7e21b8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/UnknownElementTest.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; + +public class UnknownElementTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/core/unknownelement.xml"); + } + + @Test + public void testMaybeConfigure() { + // make sure we do not get a NPE + buildRule.executeTarget("testMaybeConfigure"); + } + + /** + * Not really a UnknownElement test but rather one of "what + * information is available in taskFinished". + * @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=26197"> + * https://issues.apache.org/bugzilla/show_bug.cgi?id=26197</a> + */ + @Test + @Ignore("Previously disabled through naming convention") + public void XtestTaskFinishedEvent() { + buildRule.getProject().addBuildListener(new BuildListener() { + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) {} + public void targetStarted(BuildEvent event) {} + public void targetFinished(BuildEvent event) {} + public void taskStarted(BuildEvent event) { + assertTaskProperties(event.getTask()); + } + public void taskFinished(BuildEvent event) { + assertTaskProperties(event.getTask()); + } + public void messageLogged(BuildEvent event) {} + private void assertTaskProperties(Task ue) { + assertNotNull(ue); + assertTrue(ue instanceof UnknownElement); + Task t = ((UnknownElement) ue).getTask(); + assertNotNull(t); + assertEquals("org.apache.tools.ant.taskdefs.Echo", + t.getClass().getName()); + } + }); + buildRule.executeTarget("echo"); + } + + public static class Child extends Task { + Parent parent; + public void injectParent(Parent parent) { + this.parent = parent; + } + public void execute() { + parent.fromChild(); + } + } + + public static class Parent extends Task implements TaskContainer { + List children = new ArrayList(); + public void addTask(Task t) { + children.add(t); + } + + public void fromChild() { + log("fromchild"); + } + + public void execute() { + for (Iterator i = children.iterator(); i.hasNext();) { + UnknownElement el = (UnknownElement) i.next(); + el.maybeConfigure(); + Child child = (Child) el.getRealThing(); + child.injectParent(this); + child.perform(); + } + } + } +} + + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/XmlLoggerTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/XmlLoggerTest.java new file mode 100644 index 00000000..cfeb16b4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/XmlLoggerTest.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant; + +import org.apache.tools.ant.taskdefs.Cvs; +import org.junit.Test; + +public class XmlLoggerTest { + + @Test + // see https://issues.apache.org/bugzilla/show_bug.cgi?id=56850 + // "NPE in XmlLogger.buildFinished" + public void test() throws Throwable { + final XmlLogger logger = new XmlLogger(); + final Cvs task = new Cvs(); + final BuildEvent event = new BuildEvent(task); + logger.buildStarted(event); + logger.buildFinished(event); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java new file mode 100644 index 00000000..38583540 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/ConcatFilterTest.java @@ -0,0 +1,143 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.filters; + +import java.io.File; +import java.io.IOException; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.apache.tools.ant.util.StringUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * JUnit Testcases for ConcatReader + */ +public class ConcatFilterTest { + + private static final String lSep = StringUtils.LINE_SEP; + + private static final String FILE_PREPEND_WITH = + "this-should-be-the-first-line" + lSep + + "Line 1" + lSep + + "Line 2" + lSep + + "Line 3" + lSep + + "Line 4" + lSep + ; + + private static final String FILE_PREPEND = + "Line 1" + lSep + + "Line 2" + lSep + + "Line 3" + lSep + + "Line 4" + lSep + + "Line 5" + lSep + ; + + private static final String FILE_APPEND_WITH = + "Line 57" + lSep + + "Line 58" + lSep + + "Line 59" + lSep + + "Line 60" + lSep + + "this-should-be-the-last-line" + lSep + ; + + private static final String FILE_APPEND = + "Line 56" + lSep + + "Line 57" + lSep + + "Line 58" + lSep + + "Line 59" + lSep + + "Line 60" + lSep + ; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/concat.xml"); + } + + @Test + public void testFilterReaderNoArgs() throws IOException { + buildRule.executeTarget("testFilterReaderNoArgs"); + File expected = new File(buildRule.getProject().getProperty("output"), "concatfilter.test"); + File result = new File(buildRule.getProject().getProperty("output"), "concat.FilterReaderNoArgs.test"); + assertEquals("testFilterReaderNoArgs: Result not like expected", FileUtilities.getFileContents(expected), + FileUtilities.getFileContents(result)); + } + + @Test + public void testFilterReaderBefore() throws IOException { + doTest("testFilterReaderPrepend", FILE_PREPEND_WITH, FILE_APPEND); + } + + @Test + public void testFilterReaderAfter() throws IOException { + doTest("testFilterReaderAppend", FILE_PREPEND, FILE_APPEND_WITH); + } + + @Test + public void testFilterReaderBeforeAfter() throws IOException { + doTest("testFilterReaderPrependAppend", FILE_PREPEND_WITH, FILE_APPEND_WITH); + } + + @Test + public void testConcatFilter() throws IOException { + doTest("testConcatFilter", FILE_PREPEND, FILE_APPEND); + } + + @Test + public void testConcatFilterBefore() throws IOException { + doTest("testConcatFilterPrepend", FILE_PREPEND_WITH, FILE_APPEND); + } + + @Test + public void testConcatFilterAfter() throws IOException { + doTest("testConcatFilterAppend", FILE_PREPEND, FILE_APPEND_WITH); + } + + @Test + public void testConcatFilterBeforeAfter() throws IOException { + doTest("testConcatFilterPrependAppend", FILE_PREPEND_WITH, FILE_APPEND_WITH); + } + + + /** + * Executes a target and checks the beginning and the ending of a file. + * The filename depends on the target name: target name <i>testHelloWorld</i> + * will search for a file <i>result/concat.HelloWorld.test</i>. + * @param target The target to invoke + * @param expectedStart The string which should be at the beginning of the file + * @param expectedEnd The string which should be at the end of the file + */ + protected void doTest(String target, String expectedStart, String expectedEnd) throws IOException { + buildRule.executeTarget(target); + String resultContent = FileUtilities.getFileContents( + new File(buildRule.getProject().getProperty("output") + "/concat." + target.substring(4) + ".test")); + assertTrue("First 5 lines differs.", resultContent.startsWith(expectedStart)); + assertTrue("Last 5 lines differs.", resultContent.endsWith(expectedEnd)); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/DynamicFilterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/DynamicFilterTest.java new file mode 100644 index 00000000..5de7f6bc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/DynamicFilterTest.java @@ -0,0 +1,80 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.filters; + +import java.io.File; +import java.io.Reader; +import java.io.IOException; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; + +public class DynamicFilterTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/dynamicfilter.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void testCustomFilter() throws IOException { + buildRule.executeTarget("dynamicfilter"); + String content = FileUtilities.getFileContents( + new File(buildRule.getProject().getProperty("output") + "/dynamicfilter")); + assertContains("hellO wOrld", content); + } + + + + public static class CustomFilter implements ChainableReader { + char replace = 'x'; + char with = 'y'; + + public void setReplace(char replace) { + this.replace = replace; + } + + public void setWith(char with) { + this.with = with; + } + + public Reader chain(final Reader rdr) { + return new BaseFilterReader(rdr) { + public int read() + throws IOException + { + int c = in.read(); + if (c == replace) + return with; + else + return c; + } + }; + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/EscapeUnicodeTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/EscapeUnicodeTest.java new file mode 100644 index 00000000..7c5e3040 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/EscapeUnicodeTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.filters; + +import java.io.File; +import java.io.IOException; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class EscapeUnicodeTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/build.xml"); + } + + @Test + public void testEscapeUnicode() throws IOException { + buildRule.executeTarget("testEscapeUnicode"); + File expected = buildRule.getProject().resolveFile("expected/escapeunicode.test"); + File result = new File(buildRule.getProject().getProperty("output"), "escapeunicode.test"); + assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java new file mode 100644 index 00000000..7c910d12 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/HeadTailTest.java @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.filters; + +import java.io.File; +import java.io.IOException; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** JUnit Testcases for TailFilter and HeadFilter + */ +/* I wrote the testcases in one java file because I want also to test the + * combined behaviour (see end of the class). +*/ +public class HeadTailTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/head-tail.xml"); + } + + @Test + public void testHead() throws IOException { + buildRule.executeTarget("testHead"); + File expected = buildRule.getProject().resolveFile("expected/head-tail.head.test"); + File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.head.test"); + assertEquals("testHead: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testHeadLines() throws IOException { + buildRule.executeTarget("testHeadLines"); + File expected = buildRule.getProject().resolveFile("expected/head-tail.headLines.test"); + File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headLines.test"); + assertEquals("testHeadLines: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testHeadSkip() throws IOException { + buildRule.executeTarget("testHeadSkip"); + File expected = buildRule.getProject().resolveFile("expected/head-tail.headSkip.test"); + File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headSkip.test"); + assertEquals("testHeadSkip: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testHeadLinesSkip() throws IOException { + buildRule.executeTarget("testHeadLinesSkip"); + File expected = buildRule.getProject().resolveFile("expected/head-tail.headLinesSkip.test"); + File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headLinesSkip.test"); + assertEquals("testHeadLinesSkip: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testFilterReaderHeadLinesSkip() throws IOException { + buildRule.executeTarget("testFilterReaderHeadLinesSkip"); + File expected = buildRule.getProject().resolveFile("expected/head-tail.headLinesSkip.test"); + File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.filterReaderHeadLinesSkip.test"); + assertEquals("testFilterReaderHeadLinesSkip: Result not like expected", + FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testTail() throws IOException { + buildRule.executeTarget("testTail"); + File expected =buildRule.getProject().resolveFile("expected/head-tail.tail.test"); + File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tail.test"); + assertEquals("testTail: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testTailLines() throws IOException { + buildRule.executeTarget("testTailLines"); + File expected = buildRule.getProject().resolveFile("expected/head-tail.tailLines.test"); + File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tailLines.test"); + assertEquals("testTailLines: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testTailSkip() throws IOException { + buildRule.executeTarget("testTailSkip"); + File expected = buildRule.getProject().resolveFile("expected/head-tail.tailSkip.test"); + File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tailSkip.test"); + assertEquals("testTailSkip: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testTailLinesSkip() throws IOException { + buildRule.executeTarget("testTailLinesSkip"); + File expected = buildRule.getProject().resolveFile("expected/head-tail.tailLinesSkip.test"); + File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.tailLinesSkip.test"); + assertEquals("testTailLinesSkip: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testFilterReaderTailLinesSkip() throws IOException { + buildRule.executeTarget("testFilterReaderTailLinesSkip"); + File expected = buildRule.getProject().resolveFile("expected/head-tail.tailLinesSkip.test"); + File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.filterReaderTailLinesSkip.test"); + assertEquals("testFilterReaderTailLinesSkip: Result not like expected", + FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testHeadTail() throws IOException { + buildRule.executeTarget("testHeadTail"); + File expected = buildRule.getProject().resolveFile("expected/head-tail.headtail.test"); + File result = new File(buildRule.getProject().getProperty("output") + "/head-tail.headtail.test"); + assertEquals("testHeadTail: Result not like expected", FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/LineContainsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/LineContainsTest.java new file mode 100644 index 00000000..9dcb291b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/LineContainsTest.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.filters; + +import java.io.File; +import java.io.IOException; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + + +public class LineContainsTest { + + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/build.xml"); + } + + @Test + public void testLineContains() throws IOException { + buildRule.executeTarget("testLineContains"); + File expected = buildRule.getProject().resolveFile("expected/linecontains.test"); + File result = new File(buildRule.getProject().getProperty("output"),"linecontains.test"); + assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testNegateLineContains() throws IOException { + buildRule.executeTarget("testNegateLineContains"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/NoNewLineTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/NoNewLineTest.java new file mode 100644 index 00000000..c12a1d3f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/NoNewLineTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.filters; + +import java.io.IOException; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** JUnit Testcases for No new line when filterchain used + */ + + +public class NoNewLineTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/build.xml"); + } + + + @Test + public void testNoAddNewLine() throws IOException { + buildRule.executeTarget("testNoAddNewLine"); + } + + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/ReplaceTokensTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/ReplaceTokensTest.java new file mode 100644 index 00000000..4db8d7a0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/ReplaceTokensTest.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.filters; + +import java.io.File; +import java.io.IOException; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class ReplaceTokensTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/build.xml"); + } + + @Test + public void testReplaceTokens() throws IOException { + buildRule.executeTarget("testReplaceTokens"); + File expected = buildRule.getProject().resolveFile("expected/replacetokens.test"); + File result = new File(buildRule.getProject().getProperty("output"), "replacetokens.test"); + assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testReplaceTokensPropertyFile() throws IOException { + buildRule.executeTarget("testReplaceTokensPropertyFile"); + File expected = buildRule.getProject().resolveFile("expected/replacetokens.test"); + File result = new File(buildRule.getProject().getProperty("output"), "replacetokensPropertyFile.test"); + assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testReplaceTokensDoubleEncoded() throws IOException { + buildRule.executeTarget("testReplaceTokensDoubleEncoded"); + File expected = buildRule.getProject().resolveFile("expected/replacetokens.double.test"); + File result = new File(buildRule.getProject().getProperty("output"), "replacetokens.double.test"); + assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testReplaceTokensDoubleEncodedToSimple() throws IOException { + buildRule.executeTarget("testReplaceTokensDoubleEncodedToSimple"); + File expected = buildRule.getProject().resolveFile("expected/replacetokens.test"); + File result = new File(buildRule.getProject().getProperty("output"), "replacetokens.double.test"); + assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + + @Test + public void testReplaceTokensMustacheStyle() throws IOException { + buildRule.executeTarget("testReplaceTokensMustacheStyle"); + File expected = buildRule.getProject().resolveFile("expected/replacetokens.test"); + File result = new File(buildRule.getProject().getProperty("output"), "replacetokens.mustache.test"); + assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/StripJavaCommentsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/StripJavaCommentsTest.java new file mode 100644 index 00000000..7114d497 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/StripJavaCommentsTest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.filters; + +import java.io.File; +import java.io.IOException; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class StripJavaCommentsTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/build.xml"); + } + + + @Test + public void testStripJavaComments() throws IOException { + buildRule.executeTarget("testStripJavaComments"); + File expected = buildRule.getProject().resolveFile("expected/stripjavacomments.test"); + File result = new File(buildRule.getProject().getProperty("output"), "stripjavacomments.test"); + assertEquals(FileUtilities.getFileContents(expected), FileUtilities.getFileContents(result)); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java new file mode 100644 index 00000000..f0db15a0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/filters/TokenFilterTest.java @@ -0,0 +1,279 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.filters; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.apache.tools.ant.AntAssert.assertNotContains; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.FileReader; +import java.io.IOException; +import java.io.Reader; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + */ +public class TokenFilterTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/filters/tokenfilter.xml"); + buildRule.executeTarget("setUp"); + } + + /** make sure tokenfilter exists */ + @Test + public void testTokenfilter() throws IOException { + buildRule.executeTarget("tokenfilter"); + } + + @Test + public void testTrimignore() throws IOException { + buildRule.executeTarget("trimignore"); + assertContains("Hello-World", buildRule.getLog()); + } + + @Test + public void testStringTokenizer() throws IOException { + buildRule.executeTarget("stringtokenizer"); + assertContains("#This#is#a#number#of#words#", buildRule.getLog()); + } + + @Test + public void testUnixLineOutput() throws IOException { + buildRule.executeTarget("unixlineoutput"); + assertContains("\nThis\nis\na\nnumber\nof\nwords\n", + getFileString(buildRule.getProject().getProperty("output") + "/unixlineoutput")); + } + + @Test + public void testDosLineOutput() throws IOException { + + buildRule.executeTarget("doslineoutput"); + assertContains("\r\nThis\r\nis\r\na\r\nnumber\r\nof\r\nwords\r\n", + getFileString(buildRule.getProject().getProperty("output") + "/doslineoutput")); + } + + @Test + public void testFileTokenizer() throws IOException { + buildRule.executeTarget("filetokenizer"); + String contents = getFileString(buildRule.getProject().getProperty("output") + "/filetokenizer"); + assertContains(" of words", contents); + assertNotContains(" This is", contents); + } + + @Test + public void testReplaceString() throws IOException { + buildRule.executeTarget("replacestring"); + assertContains("this is the moon", + getFileString(buildRule.getProject().getProperty("output") + "/replacestring")); + } + + @Test + public void testReplaceStrings() throws IOException { + buildRule.executeTarget("replacestrings"); + assertContains("bar bar bar", buildRule.getLog()); + } + + @Test + public void testContainsString() throws IOException { + buildRule.executeTarget("containsstring"); + String contents = getFileString(buildRule.getProject().getProperty("output") + "/containsstring"); + assertContains("this is a line contains foo", contents); + assertNotContains("this line does not", contents); + } + + @Test + public void testReplaceRegex() throws IOException { + + buildRule.executeTarget("hasregex"); + Assume.assumeTrue("Regex not present", + getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); + + buildRule.executeTarget("replaceregex"); + String contents = getFileString(buildRule.getProject().getProperty("output") + "/replaceregex"); + assertContains("world world world world", contents); + assertContains("dog Cat dog", contents); + assertContains("moon Sun Sun", contents); + assertContains("found WhiteSpace", contents); + assertContains("Found digits [1234]", contents); + assertNotContains("This is a line with digits", contents); + } + + @Test + public void testFilterReplaceRegex() throws IOException { + buildRule.executeTarget("hasregex"); + Assume.assumeTrue("Regex not present", + getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); + + buildRule.executeTarget("filterreplaceregex"); + String contents = getFileString(buildRule.getProject().getProperty("output") + "/filterreplaceregex"); + assertContains("world world world world", contents); + + } + + @Test + public void testHandleDollerMatch() throws IOException { + buildRule.executeTarget("hasregex"); + Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); + + buildRule.executeTarget("dollermatch"); + } + + @Test + public void testTrimFile() throws IOException { + buildRule.executeTarget("trimfile"); + String contents = getFileString(buildRule.getProject().getProperty("output") + "/trimfile"); + assertTrue("no ws at start", contents.startsWith("This is th")); + assertTrue("no ws at end", contents.endsWith("second line.")); + assertContains(" This is the second", contents); + } + + @Test + public void testTrimFileByLine() throws IOException { + buildRule.executeTarget("trimfilebyline"); + String contents = getFileString(buildRule.getProject().getProperty("output") + "/trimfilebyline"); + assertFalse("no ws at start", contents.startsWith("This is th")); + assertFalse("no ws at end", contents.endsWith("second line.")); + assertNotContains(" This is the second", contents); + assertContains("file.\nThis is the second", contents); + } + + @Test + public void testFilterReplaceString() throws IOException { + buildRule.executeTarget("filterreplacestring"); + String contents = getFileString(buildRule.getProject().getProperty("output") + "/filterreplacestring"); + assertContains("This is the moon", contents); + } + + @Test + public void testFilterReplaceStrings() throws IOException { + buildRule.executeTarget("filterreplacestrings"); + assertContains("bar bar bar", buildRule.getLog()); + } + + @Test + public void testContainsRegex() throws IOException { + buildRule.executeTarget("hasregex"); + Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); + + //expectFileContains(buildRule.getProject().getProperty("output") + "/replaceregexp", "bye world"); + + buildRule.executeTarget("containsregex"); + String contents = getFileString(buildRule.getProject().getProperty("output") + "/containsregex"); + assertContains("hello world", contents); + assertNotContains("this is the moon", contents); + assertContains("World here", contents); + } + + @Test + public void testFilterContainsRegex() throws IOException { + buildRule.executeTarget("hasregex"); + Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); + + buildRule.executeTarget("filtercontainsregex"); + String contents = getFileString(buildRule.getProject().getProperty("output") + "/filtercontainsregex"); + assertContains("hello world", contents); + assertNotContains("this is the moon", contents); + assertContains("World here", contents); + } + + @Test + public void testContainsRegex2() throws IOException { + buildRule.executeTarget("hasregex"); + Assume.assumeTrue("Regex not present", getFileString(buildRule.getProject().getProperty("output") + "/replaceregexp").contains("bye world")); + + buildRule.executeTarget("containsregex2"); + String contents = getFileString(buildRule.getProject().getProperty("output") + "/containsregex2"); + assertContains("void register_bits();", contents); + } + + @Test + public void testDeleteCharacters() throws IOException { + buildRule.executeTarget("deletecharacters"); + String contents = getFileString(buildRule.getProject().getProperty("output") + "/deletechars"); + assertNotContains("#", contents); + assertNotContains("*", contents); + assertContains("This is some ", contents); + } + + @Test + public void testScriptFilter() throws IOException { + Assume.assumeTrue("Project does not have 'testScriptFilter' target", + buildRule.getProject().getTargets().contains("testScriptFilter")); + buildRule.executeTarget("scriptfilter"); + assertContains("HELLO WORLD", getFileString(buildRule.getProject().getProperty("output") + "/scriptfilter")); + + } + + @Test + public void testScriptFilter2() throws IOException { + Assume.assumeTrue("Project does not have 'testScriptFilter' target", buildRule.getProject().getTargets().contains("testScriptFilter")); + buildRule.executeTarget("scriptfilter2"); + assertContains("HELLO MOON", getFileString(buildRule.getProject().getProperty("output") + "/scriptfilter2")); + } + + @Test + public void testCustomTokenFilter() throws IOException { + buildRule.executeTarget("customtokenfilter"); + assertContains("Hello World", getFileString(buildRule.getProject().getProperty("output") + "/custom")); + } + + // ------------------------------------------------------ + // Helper methods + // ----------------------------------------------------- + + private String getFileString(String filename) + throws IOException + { + Reader r = null; + try { + r = new FileReader(FILE_UTILS.resolveFile(buildRule.getProject().getBaseDir(),filename)); + return FileUtils.readFully(r); + } + finally { + FileUtils.close(r); + } + } + + + public static class Capitalize + implements TokenFilter.Filter + { + public String filter(String token) { + if (token.length() == 0) + return token; + return token.substring(0, 1).toUpperCase() + + token.substring(1); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java new file mode 100644 index 00000000..0c3c24fd --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/launch/LocatorTest.java @@ -0,0 +1,180 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.launch; + +import java.io.File; + +import org.apache.tools.ant.taskdefs.condition.Os; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import static junit.framework.Assert.assertEquals; +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.fail; + +/** Test the locator in the ant-launch JAR */ +public class LocatorTest { + private boolean windows; + private boolean unix; + private static final String LAUNCHER_JAR = "//morzine/slo/Java/Apache/ant/lib/ant-launcher.jar"; + private static final String SHARED_JAR_URI = "jar:file:"+ LAUNCHER_JAR +"!/org/apache/tools/ant/launch/Launcher.class"; + + + @Before + public void setUp() throws Exception { + windows = Os.isFamily(Os.FAMILY_DOS); + unix = Os.isFamily(Os.FAMILY_UNIX); + } + + /** + * expect a uri to resolve to strings on different platforms + * @param uri uri to parse + * @param expectedUnix unix string (or null to skip that test) + * @param expectedDos DOS string (or null to skip that test) + * @return the resolved string + */ + private String resolveTo(String uri, String expectedUnix, String expectedDos) { + String result = Locator.fromURI(uri); + assertResolved(uri, expectedUnix, result, unix); + assertResolved(uri, expectedDos, result, windows); + return result; + } + + /** + * Assert something resolved + * @param uri original URI + * @param expectedResult what we expected + * @param result what we got + * @param enabled is the test enabled? + */ + private void assertResolved(String uri, String expectedResult, String result, boolean enabled) { + if (enabled && expectedResult != null && expectedResult.length() > 0) { + assertEquals("Expected " + uri + " to resolve to \n" + expectedResult + "\n but got\n" + + result + "\n", expectedResult, result); + } + } + + /** + * This asserts that we can round trip the path to a URI and back again + * @param path filename with no directory separators + * @return the trailing filename + */ + private String assertResolves(String path) { + String asuri = new File(path).toURI().toASCIIString(); + String fullpath = System.getProperty("user.dir") + File.separator + path; + String result = resolveTo(asuri, fullpath, fullpath); + return result.substring(result.lastIndexOf(File.separatorChar) + 1); + } + + + /** + * this isnt really a valid URI, except maybe in IE + * @throws Exception + */ + public void testNetworkURI() throws Exception { + resolveTo("file:\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar", "" + + "\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar", + "\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar"); + } + + @Ignore("We don't appear to generate paths like this in the launcher") + @Test + public void testTripleForwardSlashNetworkURI() throws Exception { + resolveTo("file:///PC03/jclasses/lib/ant-1.7.0.jar", + "///PC03/jclasses/lib/ant-1.7.0.jar", + "\\\\PC03\\jclasses\\lib\\ant-1.7.0.jar"); + } + + @Test + public void testUnixNetworkPath() throws Exception { + resolveTo("file://cluster/home/ant/lib", + "//cluster/home/ant/lib", + "\\\\cluster\\home\\ant\\lib"); + } + + @Test + public void testUnixPath() throws Exception { + resolveTo("file:/home/ant/lib", "/home/ant/lib", null); + } + + @Test + public void testSpacedURI() throws Exception { + resolveTo("file:C:\\Program Files\\Ant\\lib", + "C:\\Program Files\\Ant\\lib", + "C:\\Program Files\\Ant\\lib"); + } + + /** + * Bug 42275; Ant failing to run off a remote share + * @throws Throwable if desired + */ + @Test + public void testAntOnRemoteShare() throws Throwable { + String resolved=Locator.fromJarURI(SHARED_JAR_URI); + assertResolved(SHARED_JAR_URI, LAUNCHER_JAR, resolved, unix); + assertResolved(SHARED_JAR_URI, LAUNCHER_JAR.replace('/', '\\'), + resolved, windows); + } + + /** + * Bug 42275; Ant failing to run off a remote share + * + * @throws Throwable if desired + */ + @Test + public void testFileFromRemoteShare() throws Throwable { + String resolved = Locator.fromJarURI(SHARED_JAR_URI); + File f = new File(resolved); + String path = f.getAbsolutePath(); + if (windows) { + assertEquals(0, path.indexOf("\\\\")); + } + } + + @Test + public void testHttpURI() throws Exception { + String url = "http://ant.apache.org"; + try { + Locator.fromURI(url); + fail("Exception should have been thrown"); + } catch (IllegalArgumentException e) { + String message = e.getMessage(); + assertContains(Locator.ERROR_NOT_FILE_URI, message); + assertContains(url, message); + } + } + + @Test + public void testInternationalURI() throws Exception { + String result = assertResolves("L\u00f6wenbrau.aus.M\u00fcnchen"); + char umlauted = result.charAt(1); + assertEquals("expected 0xf6 (\u00f6), but got " + Integer.toHexString(umlauted) + " '" + + umlauted + "'", 0xf6, umlauted); + assertEquals("file:/tmp/a%C3%A7a%C3%AD%20berry", Locator.encodeURI("file:/tmp/a\u00E7a\u00ED berry")); + assertEquals("file:/tmp/a\u00E7a\u00ED berry", Locator.decodeUri("file:/tmp/a%C3%A7a%C3%AD%20berry")); + assertEquals("file:/tmp/a\u00E7a\u00ED berry", Locator.decodeUri("file:/tmp/a\u00E7a\u00ED%20berry")); // #50543 + assertEquals("file:/tmp/hezky \u010Desky", Locator.decodeUri("file:/tmp/hezky%20\u010Desky")); // non-ISO-8859-1 variant + } + + @Test + public void testOddLowAsciiURI() throws Exception { + assertResolves("hash# and percent%"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/loader/AntClassLoader5Test.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/loader/AntClassLoader5Test.java new file mode 100644 index 00000000..469877a4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/loader/AntClassLoader5Test.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.loader; + +import java.io.IOException; +import java.net.URL; +import java.util.Enumeration; +import org.apache.tools.ant.AntClassLoader; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.CollectionUtils; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +public class AntClassLoader5Test { + + /** + * Asserts that getResources won't return resources that cannot be + * seen by AntClassLoader but by ClassLoader.this.parent. + * + * @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=46752"> + * https://issues.apache.org/bugzilla/show_bug.cgi?id=46752</a> + */ + @Test + public void testGetResources() throws IOException { + AntClassLoader acl = new AntClassLoader5(new EmptyLoader(), null, + new Path(null), true); + assertNull(acl.getResource("META-INF/MANIFEST.MF")); + assertFalse(acl.getResources("META-INF/MANIFEST.MF").hasMoreElements()); + + // double check using system classloader as parent + acl = new AntClassLoader5(null, null, new Path(null), true); + assertNotNull(acl.getResource("META-INF/MANIFEST.MF")); + assertTrue(acl.getResources("META-INF/MANIFEST.MF").hasMoreElements()); + } + + @Test + public void testGetResourcesUsingFactory() throws IOException { + AntClassLoader acl = + AntClassLoader.newAntClassLoader(new EmptyLoader(), null, + new Path(null), true); + assertNull(acl.getResource("META-INF/MANIFEST.MF")); + assertFalse(acl.getResources("META-INF/MANIFEST.MF").hasMoreElements()); + } + + private static class EmptyLoader extends ClassLoader { + public URL getResource(String n) { + return null; + } + public Enumeration getResources(String n) { + return new CollectionUtils.EmptyEnumeration(); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AbstractCvsTaskTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AbstractCvsTaskTest.java new file mode 100644 index 00000000..227987fa --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AbstractCvsTaskTest.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildFileRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertTrue; + +/** + */ +public class AbstractCvsTaskTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/abstractcvstask.xml"); + buildRule.executeTarget("setUp"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void testAbstractCvsTask() { + buildRule.executeTarget("all"); + } + + @Test + public void testPackageAttribute() { + File f = new File(buildRule.getProject().getProperty("output") + "/src/Makefile"); + assertTrue("starting empty", !f.exists()); + buildRule.executeTarget("package-attribute"); + AntAssert.assertContains("U src/Makefile", buildRule.getLog()); + assertTrue("now it is there", f.exists()); + } + + @Test + public void testTagAttribute() { + File f = new File(buildRule.getProject().getProperty("output") + "/src/Makefile"); + assertTrue("starting empty", !f.exists()); + buildRule.executeTarget("tag-attribute"); + AntAssert.assertContains("OPENBSD_5_3", buildRule.getLog()); + assertTrue("now it is there", f.exists()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java new file mode 100644 index 00000000..298bf098 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntLikeTasksAtTopLevelTest.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * @since Ant 1.6 + */ +public class AntLikeTasksAtTopLevelTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Test + public void testAnt() { + try { + buildRule.configureProject("src/etc/testcases/taskdefs/toplevelant.xml"); + fail("no exception thrown"); + } catch (BuildException e) { + assertEquals("ant task at the top level must not invoke its own" + + " build file.", e.getMessage()); + } + } + + @Test + public void testSubant() { + try { + buildRule.configureProject("src/etc/testcases/taskdefs/toplevelsubant.xml"); + fail("no exception thrown"); + } catch (BuildException e) { + assertEquals("subant task at the top level must not invoke its own" + + " build file.", e.getMessage()); + } + } + + @Test + public void testAntcall() { + try { + buildRule.configureProject("src/etc/testcases/taskdefs/toplevelantcall.xml"); + fail("no exception thrown"); + } catch (BuildException e) { + assertEquals("antcall must not be used at the top level.", + e.getMessage()); + } + } + +}// AntLikeTasksAtTopLevelTest diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java new file mode 100644 index 00000000..da51b5d9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntStructureTest.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.PrintWriter; +import java.util.Hashtable; + +import static org.junit.Assert.fail; + +/** + */ +public class AntStructureTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/antstructure.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("tearDown"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument not specified"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void testCustomPrinter() { + buildRule.executeTarget("testCustomPrinter"); + // can't access the booleans in MyPrinter here (even if they + // were static) since the MyPrinter instance that was used in + // the test has likely been loaded via a different classloader + // than this class. Therefore we make the printer assert its + // state and only check for the tail invocation. + AntAssert.assertContains(MyPrinter.TAIL_CALLED, buildRule.getLog()); + } + + public static class MyPrinter implements AntStructure.StructurePrinter { + private static final String TAIL_CALLED = "tail has been called"; + private boolean headCalled = false; + private boolean targetCalled = false; + private boolean tailCalled = false; + private int elementCalled = 0; + private Project p; + + public void printHead(PrintWriter out, Project p, Hashtable tasks, + Hashtable types) { + Assert.assertTrue(!headCalled); + Assert.assertTrue(!targetCalled); + Assert.assertTrue(!tailCalled); + Assert.assertEquals(0, elementCalled); + headCalled = true; + } + public void printTargetDecl(PrintWriter out) { + Assert.assertTrue(headCalled); + Assert.assertTrue(!targetCalled); + Assert.assertTrue(!tailCalled); + Assert.assertEquals(0, elementCalled); + targetCalled = true; + } + public void printElementDecl(PrintWriter out, Project p, String name, + Class element) { + Assert.assertTrue(headCalled); + Assert.assertTrue(targetCalled); + Assert.assertTrue(!tailCalled); + elementCalled++; + this.p = p; + } + public void printTail(PrintWriter out) { + Assert.assertTrue(headCalled); + Assert.assertTrue(targetCalled); + Assert.assertTrue(!tailCalled); + Assert.assertTrue(elementCalled > 0); + tailCalled = true; + p.log(TAIL_CALLED); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java new file mode 100644 index 00000000..0d6453c4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntTest.java @@ -0,0 +1,607 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.File; + +import junit.framework.AssertionFailedError; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.BuildListener; +import org.apache.tools.ant.input.InputHandler; +import org.apache.tools.ant.input.PropertyFileInputHandler; +import org.apache.tools.ant.types.Path; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + */ +public class AntTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/ant.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("recursive call"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + // target must be specified + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("required argument not specified"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + // Should fail since a recursion will occur... + @Test + public void test3() { + try { + buildRule.executeTarget("test1"); + fail("recursive call"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("target attribute must not be empty"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test4b() { + try { + buildRule.executeTarget("test4b"); + fail("target doesn't exist"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + } + + @Test + public void test6() { + buildRule.executeTarget("test6"); + } + + @Test + public void testExplicitBasedir1() { + File dir1 = buildRule.getProject().getBaseDir(); + File dir2 = buildRule.getProject().resolveFile(".."); + testBaseDirs("explicitBasedir1", + new String[] {dir1.getAbsolutePath(), + dir2.getAbsolutePath() + }); + } + + @Test + public void testExplicitBasedir2() { + File dir1 = buildRule.getProject().getBaseDir(); + File dir2 = buildRule.getProject().resolveFile(".."); + testBaseDirs("explicitBasedir2", + new String[] {dir1.getAbsolutePath(), + dir2.getAbsolutePath() + }); + } + + @Test + public void testInheritBasedir() { + String basedir = buildRule.getProject().getBaseDir().getAbsolutePath(); + testBaseDirs("inheritBasedir", new String[] {basedir, basedir}); + } + + @Test + public void testDoNotInheritBasedir() { + File dir1 = buildRule.getProject().getBaseDir(); + File dir2 = buildRule.getProject().resolveFile("ant"); + testBaseDirs("doNotInheritBasedir", + new String[] {dir1.getAbsolutePath(), + dir2.getAbsolutePath() + }); + } + + @Test + public void testBasedirTripleCall() { + File dir1 = buildRule.getProject().getBaseDir(); + File dir2 = buildRule.getProject().resolveFile("ant"); + testBaseDirs("tripleCall", + new String[] {dir1.getAbsolutePath(), + dir2.getAbsolutePath(), + dir1.getAbsolutePath() + }); + } + + protected void testBaseDirs(String target, String[] dirs) { + BasedirChecker bc = new BasedirChecker(dirs); + buildRule.getProject().addBuildListener(bc); + buildRule.executeTarget(target); + AssertionFailedError ae = bc.getError(); + if (ae != null) { + throw ae; + } + buildRule.getProject().removeBuildListener(bc); + } + + @Test + public void testReferenceInheritance() { + Path p = Path.systemClasspath; + p.setProject(buildRule.getProject()); + buildRule.getProject().addReference("path", p); + buildRule.getProject().addReference("no-override", p); + testReference("testInherit", new String[] {"path", "path"}, + new boolean[] {true, true}, p); + testReference("testInherit", + new String[] {"no-override", "no-override"}, + new boolean[] {true, false}, p); + testReference("testInherit", + new String[] {"no-override", "no-override"}, + new boolean[] {false, false}, null); + } + + @Test + public void testReferenceNoInheritance() { + Path p = Path.systemClasspath; + p.setProject(buildRule.getProject()); + buildRule.getProject().addReference("path", p); + buildRule.getProject().addReference("no-override", p); + testReference("testNoInherit", new String[] {"path", "path"}, + new boolean[] {true, false}, p); + testReference("testNoInherit", new String[] {"path", "path"}, + new boolean[] {false, true}, null); + testReference("testInherit", + new String[] {"no-override", "no-override"}, + new boolean[] {true, false}, p); + testReference("testInherit", + new String[] {"no-override", "no-override"}, + new boolean[] {false, false}, null); + } + + @Test + public void testReferenceRename() { + Path p = Path.systemClasspath; + p.setProject(buildRule.getProject()); + buildRule.getProject().addReference("path", p); + testReference("testRename", new String[] {"path", "path"}, + new boolean[] {true, false}, p); + testReference("testRename", new String[] {"path", "path"}, + new boolean[] {false, true}, null); + testReference("testRename", new String[] {"newpath", "newpath"}, + new boolean[] {false, true}, p); + } + + @Test + public void testInheritPath() { + buildRule.executeTarget("testInheritPath"); + } + + protected void testReference(String target, String[] keys, + boolean[] expect, Object value) { + ReferenceChecker rc = new ReferenceChecker(keys, expect, value); + buildRule.getProject().addBuildListener(rc); + buildRule.executeTarget(target); + AssertionFailedError ae = rc.getError(); + if (ae != null) { + throw ae; + } + buildRule.getProject().removeBuildListener(rc); + } + + @Test + public void testLogfilePlacement() { + File[] logFiles = new File[] { + buildRule.getProject().resolveFile("test1.log"), + buildRule.getProject().resolveFile("test2.log"), + buildRule.getProject().resolveFile("ant/test3.log"), + buildRule.getProject().resolveFile("ant/test4.log") + }; + for (int i=0; i<logFiles.length; i++) { + assertTrue(logFiles[i].getName()+" doesn\'t exist", + !logFiles[i].exists()); + } + + buildRule.executeTarget("testLogfilePlacement"); + + for (int i=0; i<logFiles.length; i++) { + assertTrue(logFiles[i].getName()+" exists", + logFiles[i].exists()); + } + } + + @Test + public void testInputHandlerInheritance() { + InputHandler ih = new PropertyFileInputHandler(); + buildRule.getProject().setInputHandler(ih); + InputHandlerChecker ic = new InputHandlerChecker(ih); + buildRule.getProject().addBuildListener(ic); + buildRule.executeTarget("tripleCall"); + AssertionFailedError ae = ic.getError(); + if (ae != null) { + throw ae; + } + buildRule.getProject().removeBuildListener(ic); + } + + @Test + public void testRefId() { + Path testPath = new Path(buildRule.getProject()); + testPath.createPath().setPath(System.getProperty("java.class.path")); + PropertyChecker pc = + new PropertyChecker("testprop", + new String[] {null, + testPath.toString()}); + buildRule.getProject().addBuildListener(pc); + buildRule.executeTarget("testRefid"); + AssertionFailedError ae = pc.getError(); + if (ae != null) { + throw ae; + } + buildRule.getProject().removeBuildListener(pc); + } + + @Test + public void testUserPropertyWinsInheritAll() { + buildRule.getProject().setUserProperty("test", "7"); + buildRule.executeTarget("test-property-override-inheritall-start"); + + AntAssert.assertContains("The value of test is 7", buildRule.getLog()); + } + + @Test + public void testUserPropertyWinsNoInheritAll() { + buildRule.getProject().setUserProperty("test", "7"); + buildRule.executeTarget("test-property-override-no-inheritall-start"); + + AntAssert.assertContains("The value of test is 7", buildRule.getLog()); + } + + @Test + public void testOverrideWinsInheritAll() { + buildRule.executeTarget("test-property-override-inheritall-start"); + + AntAssert.assertContains("The value of test is 4", buildRule.getLog()); + } + + @Test + public void testOverrideWinsNoInheritAll() { + buildRule.executeTarget("test-property-override-no-inheritall-start"); + AntAssert.assertContains("The value of test is 4", buildRule.getLog()); + } + + @Test + public void testPropertySet() { + buildRule.executeTarget("test-propertyset"); + assertTrue(buildRule.getLog().indexOf("test1 is ${test1}") > -1); + assertTrue(buildRule.getLog().indexOf("test2 is ${test2}") > -1); + assertTrue(buildRule.getLog().indexOf("test1.x is 1") > -1); + } + + @Test + public void testInfiniteLoopViaDepends() { + try { + buildRule.executeTarget("infinite-loop-via-depends"); + fail("recursive call"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void testMultiSameProperty() { + buildRule.executeTarget("multi-same-property"); + assertEquals("prop is two", buildRule.getLog()); + } + + @Test + public void testTopLevelTarget() { + buildRule.executeTarget("topleveltarget"); + + assertEquals("Hello world", buildRule.getLog()); + } + + @Test + public void testMultiplePropertyFileChildren() { + PropertyChecker pcBar = new PropertyChecker("bar", + new String[] {null, "Bar"}); + PropertyChecker pcFoo = new PropertyChecker("foo", + new String[] {null, "Foo"}); + buildRule.getProject().addBuildListener(pcBar); + buildRule.getProject().addBuildListener(pcFoo); + buildRule.executeTarget("multiple-property-file-children"); + AssertionFailedError aeBar = pcBar.getError(); + if (aeBar != null) { + throw aeBar; + } + AssertionFailedError aeFoo = pcFoo.getError(); + if (aeFoo != null) { + throw aeFoo; + } + buildRule.getProject().removeBuildListener(pcBar); + buildRule.getProject().removeBuildListener(pcFoo); + } + + @Test + public void testBlankTarget() { + try { + buildRule.executeTarget("blank-target"); + fail("target name must not be empty"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void testMultipleTargets() { + buildRule.executeTarget("multiple-targets"); + assertEquals("tadadctbdbtc", buildRule.getLog()); + } + + @Test + public void testMultipleTargets2() { + buildRule.executeTarget("multiple-targets-2"); + assertEquals("dadctb", buildRule.getLog()); + } + + @Test + public void testAntCoreLib() { + // Cf. #42263 + buildRule.executeTarget("sub-show-ant.core.lib"); + String realLog = buildRule.getLog(); + assertTrue("found ant.core.lib in: " + realLog, realLog.matches(".*(ant[.]jar|build.classes).*")); + } + + private class BasedirChecker implements BuildListener { + private String[] expectedBasedirs; + private int calls = 0; + private AssertionFailedError error; + + BasedirChecker(String[] dirs) { + expectedBasedirs = dirs; + } + + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) {} + public void targetFinished(BuildEvent event){} + public void taskStarted(BuildEvent event) {} + public void taskFinished(BuildEvent event) {} + public void messageLogged(BuildEvent event) {} + + public void targetStarted(BuildEvent event) { + if (event.getTarget().getName().equals("")) { + return; + } + if (error == null) { + try { + assertEquals(expectedBasedirs[calls++], + event.getProject().getBaseDir().getAbsolutePath()); + } catch (AssertionFailedError e) { + error = e; + } + } + } + + AssertionFailedError getError() { + return error; + } + + } + + private class ReferenceChecker implements BuildListener { + private String[] keys; + private boolean[] expectSame; + private Object value; + private int calls = 0; + private AssertionFailedError error; + + ReferenceChecker(String[] keys, boolean[] expectSame, Object value) { + this.keys = keys; + this.expectSame = expectSame; + this.value = value; + } + + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) {} + public void targetFinished(BuildEvent event){} + public void taskStarted(BuildEvent event) {} + public void taskFinished(BuildEvent event) {} + public void messageLogged(BuildEvent event) {} + + public void targetStarted(BuildEvent event) { + if (event.getTarget().getName().equals("")) { + return; + } + if (error == null) { + try { + String msg = + "Call " + calls + " refid=\'" + keys[calls] + "\'"; + if (value == null) { + Object o = event.getProject().getReference(keys[calls]); + if (expectSame[calls++]) { + assertNull(msg, o); + } else { + assertNotNull(msg, o); + } + } else { + // a rather convoluted equals() test + Path expect = (Path) value; + Path received = (Path) event.getProject().getReference(keys[calls]); + boolean shouldBeEqual = expectSame[calls++]; + if (received == null) { + assertTrue(msg, !shouldBeEqual); + } else { + String[] l1 = expect.list(); + String[] l2 = received.list(); + if (l1.length == l2.length) { + for (int i=0; i<l1.length; i++) { + if (!l1[i].equals(l2[i])) { + assertTrue(msg, !shouldBeEqual); + } + } + assertTrue(msg, shouldBeEqual); + } else { + assertTrue(msg, !shouldBeEqual); + } + } + } + } catch (AssertionFailedError e) { + error = e; + } + } + } + + AssertionFailedError getError() { + return error; + } + + } + + private class InputHandlerChecker implements BuildListener { + private InputHandler ih; + private AssertionFailedError error; + + InputHandlerChecker(InputHandler value) { + ih = value; + } + + public void buildStarted(BuildEvent event) { + check(event); + } + public void buildFinished(BuildEvent event) { + check(event); + } + public void targetFinished(BuildEvent event) { + check(event); + } + public void taskStarted(BuildEvent event) { + check(event); + } + public void taskFinished(BuildEvent event) { + check(event); + } + public void messageLogged(BuildEvent event) { + check(event); + } + + public void targetStarted(BuildEvent event) { + check(event); + } + + private void check(BuildEvent event) { + if (error == null) { + try { + assertNotNull(event.getProject().getInputHandler()); + assertSame(ih, event.getProject().getInputHandler()); + } catch (AssertionFailedError e) { + error = e; + } + } + } + + AssertionFailedError getError() { + return error; + } + + } + + private class PropertyChecker implements BuildListener { + private String[] expectedValues; + private String key; + private int calls = 0; + private AssertionFailedError error; + + PropertyChecker(String key, String[] values) { + this.key = key; + this.expectedValues = values; + } + + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) {} + public void targetFinished(BuildEvent event){} + public void taskStarted(BuildEvent event) {} + public void taskFinished(BuildEvent event) {} + public void messageLogged(BuildEvent event) {} + + public void targetStarted(BuildEvent event) { + if (event.getTarget().getName().equals("")) { + return; + } + if (calls >= expectedValues.length) { + error = new AssertionFailedError("Unexpected invocation of" + + " target " + + event.getTarget().getName()); + } + + if (error == null) { + try { + assertEquals(expectedValues[calls++], + event.getProject().getProperty(key)); + } catch (AssertionFailedError e) { + error = e; + } + } + } + + AssertionFailedError getError() { + return error; + } + + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntlibTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntlibTest.java new file mode 100644 index 00000000..c5c78ab3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AntlibTest.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.Project; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + */ +public class AntlibTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/antlib.xml"); + } + + /** + * only do the antlib tests if we are in the same JVM as ant. + * @return + */ + private boolean isSharedJVM() { + String property = System.getProperty("tests.and.ant.share.classloader"); + return property!=null && Project.toBoolean(property); + } + + @Test + public void testAntlibFile() { + buildRule.executeTarget("antlib.file"); + assertEquals("MyTask called", buildRule.getLog()); + } + + /** + * Confirms that all matching resources will be used, so that you + * can collect several antlibs in one Definer call. + * @see "http://issues.apache.org/bugzilla/show_bug.cgi?id=24024" + */ + @Test + public void testAntlibResource() { + buildRule.executeTarget("antlib.resource"); + assertEquals("MyTask called-and-then-MyTask2 called", buildRule.getLog()); + } + + @Test + public void testNsCurrent() { + buildRule.executeTarget("ns.current"); + assertEquals("Echo2 inside a macroHello from x:p", buildRule.getLog()); + } + + @Test + public void testAntlib_uri() { + Assume.assumeTrue("Test requires shared JVM", isSharedJVM()); + buildRule.executeTarget("antlib_uri"); + } + + @Test + public void testAntlib_uri_auto() { + Assume.assumeTrue("Test requires shared JVM", isSharedJVM()); + buildRule.executeTarget("antlib_uri_auto"); + } + + @Test + public void testAntlib_uri_auto2() { + Assume.assumeTrue("Test requires shared JVM", isSharedJVM()); + buildRule.executeTarget("antlib_uri_auto2"); + } + + public static class MyTask extends Task { + public void execute() { + log("MyTask called"); + } + } + + public static class MyTask2 extends Task { + public void execute() { + log("MyTask2 called"); + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java new file mode 100644 index 00000000..ef97e375 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/AvailableTest.java @@ -0,0 +1,272 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * JUnit test for the Available task/condition. + */ +public class AvailableTest { + + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/available.xml"); + buildRule.executeTarget("setUp"); + } + + // Nothing specified -> Fail + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Required argument not specified"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + // Only property specified -> Fail + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Required argument not specified"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + // Only file specified -> Fail + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("Required argument not specified"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + // file doesn't exist -> property 'test' == null + @Test + public void test4() { + buildRule.executeTarget("test4"); + assertTrue(buildRule.getProject().getProperty("test") == null); + } + + // file does exist -> property 'test' == 'true' + public void test5() { + buildRule.executeTarget("test5"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // resource doesn't exist -> property 'test' == null + @Test + public void test6() { + buildRule.executeTarget("test6"); + assertTrue(buildRule.getProject().getProperty("test") == null); + } + + // resource does exist -> property 'test' == 'true' + @Test + public void test7() { + buildRule.executeTarget("test7"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // class doesn't exist -> property 'test' == null + @Test + public void test8() { + buildRule.executeTarget("test8"); + assertTrue(buildRule.getProject().getProperty("test") == null); + } + + // class does exist -> property 'test' == 'true' + @Test + public void test9() { + buildRule.executeTarget("test9"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // All three specified and all three exist -> true + @Test + public void test10() { + buildRule.executeTarget("test10"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // All three specified but class missing -> null + @Test + public void test11() { + buildRule.executeTarget("test11"); + assertNull(buildRule.getProject().getProperty("test")); + } + + // Specified property-name is "" -> true + @Test + public void test12() { + buildRule.executeTarget("test12"); + assertNull(buildRule.getProject().getProperty("test")); + assertEquals("true", buildRule.getProject().getProperty("")); + } + + // Specified file is "" -> invalid files do not exist + @Test + public void test13() { + buildRule.executeTarget("test13"); + assertNull(buildRule.getProject().getProperty("test")); + } + + // Specified file is "" actually a directory, so it should pass + @Test + public void test13b() { + buildRule.executeTarget("test13b"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // Specified resource is "" -> can such a thing exist? + /* + * returns non null IBM JDK 1.3 Linux + */ +// public void test14() { +// buildRule.executeTarget("test14"); +// assertEquals(buildRule.getProject().getProperty("test"), null); +// } + + // Specified class is "" -> can not exist + @Test + public void test15() { + buildRule.executeTarget("test15"); + assertNull(buildRule.getProject().getProperty("test")); + } + + // Specified dir is "" -> this is the current directory and should + // always exist + @Test + public void test16() { + buildRule.executeTarget("test16"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // Specified dir is "../taskdefs" -> should exist since it's the + // location of the buildfile used... + @Test + public void test17() { + buildRule.executeTarget("test17"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // Specified dir is "../this_dir_should_never_exist" -> null + @Test + public void test18() { + buildRule.executeTarget("test18"); + assertNull(buildRule.getProject().getProperty("test")); + } + + // Invalid type specified + @Test + public void test19() { + try { + buildRule.executeTarget("test19"); + fail("Invalid value for type attribute"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + // Core class that exists in system classpath is ignored + @Test + public void test20() { + buildRule.executeTarget("test20"); + assertNull(buildRule.getProject().getProperty("test")); + } + + // Core class that exists in system classpath is ignored, but found in specified classpath + @Test + public void test21() { + buildRule.executeTarget("test21"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // Core class that exists in system classpath is not ignored with ignoresystemclass="false" + @Test + public void test22() { + buildRule.executeTarget("test22"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // Core class that exists in system classpath is not ignored with default ignoresystemclasses value + @Test + public void test23() { + buildRule.executeTarget("test23"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // Class is found in specified classpath + @Test + public void test24() { + buildRule.executeTarget("test24"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // File is not found in specified filepath + @Test + public void testSearchInPathNotThere() { + buildRule.executeTarget("searchInPathNotThere"); + assertNull(buildRule.getProject().getProperty("test")); + } + + // File is not found in specified filepath + @Test + public void testSearchInPathIsThere() { + buildRule.executeTarget("searchInPathIsThere"); + assertEquals("true", buildRule.getProject().getProperty("test")); + } + + // test when file begins with basedir twice + @Test + public void testDoubleBasedir() { + buildRule.executeTarget("testDoubleBasedir"); + } + + // test for searching parents + @Test + public void testSearchParents() { + buildRule.executeTarget("search-parents"); + } + // test for not searching parents + @Test + public void testSearchParentsNot() { + buildRule.executeTarget("search-parents-not"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BUnzip2Test.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BUnzip2Test.java new file mode 100644 index 00000000..9ea9a4ff --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BUnzip2Test.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.File; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + + +public class BUnzip2Test { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private File outputDir; + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/bunzip2.xml"); + outputDir = new File(buildRule.getProject().getProperty("output")); + buildRule.executeTarget("prepare"); + } + + @Test + public void testRealTest() throws java.io.IOException { + testRealTest("realTest"); + } + + @Test + public void testRealTestWithResource() throws java.io.IOException { + testRealTest("realTestWithResource"); + } + + private void testRealTest(String target) throws java.io.IOException { + buildRule.executeTarget(target); + assertEquals("File content mismatch after bunzip2", + FileUtilities.getFileContents(new File(outputDir, "asf-logo-huge-from-gzip.tar")), + FileUtilities.getFileContents(new File(outputDir, "asf-logo-huge.tar"))); + } + + @Test + public void testDocumentationClaimsOnCopy() throws java.io.IOException { + testRealTest("testDocumentationClaimsOnCopy"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java new file mode 100644 index 00000000..bd881430 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BZip2Test.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.bzip2.CBZip2InputStream; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + */ +public class BZip2Test { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private File outputDir; + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/bzip2.xml"); + outputDir = new File(buildRule.getProject().getProperty("output")); + buildRule.executeTarget("prepare"); + } + + @Test + public void testRealTest() throws IOException { + buildRule.executeTarget("realTest"); + + // doesn't work: Depending on the compression engine used, + // compressed bytes may differ. False errors would be + // reported. + // assertTrue("File content mismatch", + // FILE_UTILS.contentEquals(project.resolveFile("expected/asf-logo-huge.tar.bz2"), + // project.resolveFile("asf-logo-huge.tar.bz2"))); + + // We have to compare the decompressed content instead: + + File originalFile = + buildRule.getProject().resolveFile("expected/asf-logo-huge.tar.bz2"); + File actualFile = new File(outputDir, "asf-logo-huge.tar.bz2"); + + InputStream originalIn = + new BufferedInputStream(new FileInputStream(originalFile)); + assertEquals((byte) 'B', originalIn.read()); + assertEquals((byte) 'Z', originalIn.read()); + + InputStream actualIn = + new BufferedInputStream(new FileInputStream(actualFile)); + assertEquals((byte) 'B', actualIn.read()); + assertEquals((byte) 'Z', actualIn.read()); + + originalIn = new CBZip2InputStream(originalIn); + actualIn = new CBZip2InputStream(actualIn); + + while (true) { + int expected = originalIn.read(); + int actual = actualIn.read(); + if (expected >= 0) { + if (expected != actual) { + fail("File content mismatch"); + } + } else { + if (actual >= 0) { + fail("File content mismatch"); + } + break; + } + } + + originalIn.close(); + actualIn.close(); + } + + @Test + public void testResource(){ + buildRule.executeTarget("realTestWithResource"); + } + + @Test + public void testDateCheck(){ + buildRule.executeTarget("testDateCheck"); + String log = buildRule.getLog(); + assertTrue( + "Expecting message ending with 'asf-logo.gif.bz2 is up to date.' but got '" + log + "'", + log.endsWith("asf-logo.gif.bz2 is up to date.")); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java new file mode 100644 index 00000000..3915d6b1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/BasenameTest.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + */ +public class BasenameTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/basename.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Required attribute missing"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Required attribute missing"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("Required attribute missing"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + String checkprop = buildRule.getProject().getProperty("file.w.suf"); + assertEquals("foo.txt", checkprop); + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + String checkprop = buildRule.getProject().getProperty("file.wo.suf"); + assertEquals("foo", checkprop); + } + + @Test + public void testMultipleDots() { + buildRule.executeTarget("testMultipleDots"); + String checkprop = buildRule.getProject().getProperty("file.wo.suf"); + assertEquals("foo.bar", checkprop); + } + + @Test + public void testNoDots() { + buildRule.executeTarget("testNoDots"); + String checkprop = buildRule.getProject().getProperty("file.wo.suf"); + assertEquals("foo.bar", checkprop); + } + + @Test + public void testValueEqualsSuffixWithDot() { + buildRule.executeTarget("testValueEqualsSuffixWithDot"); + String checkprop = buildRule.getProject().getProperty("file.wo.suf"); + assertEquals("", checkprop); + } + + @Test + public void testValueEqualsSuffixWithoutDot() { + buildRule.executeTarget("testValueEqualsSuffixWithoutDot"); + String checkprop = buildRule.getProject().getProperty("file.wo.suf"); + assertEquals("", checkprop); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java new file mode 100644 index 00000000..9fe42b15 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CVSPassTest.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.*; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests CVSLogin task. + * + */ +public class CVSPassTest { + private final String EOL = System.getProperty("line.separator"); + private static final String JAKARTA_URL = + ":pserver:anoncvs@jakarta.apache.org:/home/cvspublic Ay=0=h<Z"; + private static final String XML_URL = + ":pserver:anoncvs@xml.apache.org:/home/cvspublic Ay=0=h<Z"; + private static final String TIGRIS_URL = + ":pserver:guest@cvs.tigris.org:/cvs AIbdZ,"; + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/cvspass.xml"); + } + + @Test + public void testNoCVSRoot() { + try{ + buildRule.executeTarget("test1"); + fail("BuildException not thrown"); + }catch(BuildException e){ + assertEquals("cvsroot is required", e.getMessage()); + } + } + + @Test + public void testNoPassword() { + try{ + buildRule.executeTarget("test2"); + fail("BuildException not thrown"); + }catch(BuildException e){ + assertEquals("password is required", e.getMessage()); + } + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void testPassFile() throws Exception { + buildRule.executeTarget("test3"); + File f = new File(buildRule.getProject().getBaseDir(), "testpassfile.tmp"); + + assertTrue( "Passfile "+f+" not created", f.exists()); + + assertEquals(JAKARTA_URL+EOL, FileUtilities.getFileContents(f)); + + } + + @Test + public void testPassFileDuplicateEntry() throws Exception { + buildRule.executeTarget("test4"); + File f = new File(buildRule.getProject().getBaseDir(), "testpassfile.tmp"); + + assertTrue( "Passfile "+f+" not created", f.exists()); + + assertEquals( + JAKARTA_URL+ EOL+ + TIGRIS_URL+ EOL, + FileUtilities.getFileContents(f)); + } + + @Test + public void testPassFileMultipleEntry() throws Exception { + buildRule.executeTarget("test5"); + File f = new File(buildRule.getProject().getBaseDir(), "testpassfile.tmp"); + + assertTrue( "Passfile "+f+" not created", f.exists()); + + assertEquals( + JAKARTA_URL+ EOL+ + XML_URL+ EOL+ + TIGRIS_URL+ EOL, + FileUtilities.getFileContents(f)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java new file mode 100644 index 00000000..337c6a46 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CallTargetTest.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.util.Vector; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + */ +public class CallTargetTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/calltarget.xml"); + buildRule.executeTarget("setUp"); + } + + // see bugrep 21724 (references not passing through with antcall) + @Test + public void testInheritRefFileSet() { + buildRule.executeTarget("testinheritreffileset"); + AntAssert.assertContains("calltarget.xml", buildRule.getLog()); + } + + // see bugrep 21724 (references not passing through with antcall) + @Test + public void testInheritFilterset() { + buildRule.getProject().executeTarget("testinheritreffilterset"); + } + + // see bugrep 11418 (In repeated calls to the same target, + // params will not be passed in) + @Test + public void testMultiCall() { + Vector<String> v = new Vector<String>(); + v.add("call-multi"); + v.add("call-multi"); + buildRule.getProject().executeTargets(v); + AntAssert.assertContains("multi is SETmulti is SET", buildRule.getLog()); + } + + @Test + public void testBlankTarget() { + try { + buildRule.executeTarget("blank-target"); + fail("target name must not be empty"); + } catch (BuildException ex) { + //TODO assert exception contents + } + } + + @Test + public void testMultipleTargets() { + buildRule.executeTarget("multiple-targets"); + assertEquals("tadadctbdbtc", buildRule.getLog()); + } + + @Test + public void testMultipleTargets2() { + buildRule.executeTarget("multiple-targets-2"); + assertEquals("dadctb", buildRule.getLog()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ChecksumTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ChecksumTest.java new file mode 100644 index 00000000..bd4bdfcf --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ChecksumTest.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.IOException; + +public class ChecksumTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/checksum.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void testCreateMd5() throws IOException { + buildRule.executeTarget("createMd5"); + } + + @Test + public void testCreateMD5SUMformat() throws IOException { + buildRule.executeTarget("createMD5SUMformat"); + } + + @Test + public void testCreateSVFformat() throws IOException { + buildRule.executeTarget("createSVFformat"); + } + + @Test + public void testCreatePattern() throws IOException { + buildRule.executeTarget("createPattern"); + } + + @Test + public void testSetProperty() { + buildRule.executeTarget("setProperty"); + } + + @Test + public void testVerifyTotal() { + buildRule.executeTarget("verifyTotal"); + } + + @Test + public void testVerifyTotalRC() { + buildRule.executeTarget("verifyTotalRC"); + } + + @Test + public void testVerifyChecksumdir() { + buildRule.executeTarget("verifyChecksumdir"); + } + + @Test + public void testVerifyAsTask() { + buildRule.executeTarget("verifyAsTask"); + } + + @Test + public void testVerifyMD5SUMAsTask() { + buildRule.executeTarget("verifyMD5SUMAsTask"); + } + + @Test + public void testVerifyAsCondition() { + buildRule.executeTarget("verifyAsCondition"); + } + + @Test + public void testVerifyFromProperty() { + buildRule.executeTarget("verifyFromProperty"); + } + + @Test + public void testVerifyChecksumdirNoTotal() { + buildRule.executeTarget("verifyChecksumdirNoTotal"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java new file mode 100644 index 00000000..b5441830 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ConcatTest.java @@ -0,0 +1,315 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * A test class for the 'concat' task, used to concatenate a series of + * files into a single stream. + * + */ +public class ConcatTest { + + /** + * The name of the temporary file. + */ + private static final String tempFile = "concat.tmp"; + + /** + * The name of the temporary file. + */ + private static final String tempFile2 = "concat.tmp.2"; + + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + + /** + * Test set up, called by the unit test framework prior to each + * test. + */ + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/concat.xml"); + } + + /** + * Test tear down, called by the unit test framework prior to each + * test. + */ + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + /** + * Expect an exception when insufficient information is provided. + */ + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException should have been thrown - Insufficient information"); + } catch (BuildException ex) { + //TODO assert value + } + + } + + /** + * Expect an exception when the destination file is invalid. + */ + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException should have been thrown - Invalid destination file"); + } catch(BuildException ex) { + //TODO assert value + } + } + + /** + * Cats the string 'Hello, World!' to a temporary file. + */ + @Test + public void test3() { + + File file = new File(buildRule.getProject().getBaseDir(), tempFile); + if (file.exists()) { + file.delete(); + } + + buildRule.executeTarget("test3"); + + assertTrue(file.exists()); + } + + /** + * Cats the file created in test3 three times. + */ + @Test + public void test4() { + test3(); + + File file = new File(buildRule.getProject().getBaseDir(), tempFile); + final long origSize = file.length(); + + buildRule.executeTarget("test4"); + + File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); + final long newSize = file2.length(); + + assertEquals(origSize * 3, newSize); + } + + /** + * Cats the string 'Hello, World!' to the console. + */ + @Test + public void test5() { + buildRule.executeTarget("test5"); + assertEquals("Hello, World!", buildRule.getLog()); + } + + @Test + public void test6() { + String filename = "src/etc/testcases/taskdefs/thisfiledoesnotexist" + .replace('/', File.separatorChar); + buildRule.executeTarget("test6"); + assertContains(filename + " does not exist", buildRule.getLog()); + } + + @Test + public void testConcatNoNewline() { + buildRule.executeTarget("testConcatNoNewline"); + assertEquals("ab", buildRule.getLog()); + } + + @Test + public void testConcatNoNewlineEncoding() { + buildRule.executeTarget("testConcatNoNewlineEncoding"); + assertEquals("ab", buildRule.getLog()); + } + + @Test + public void testPath() { + test3(); + + File file = new File(buildRule.getProject().getBaseDir(), tempFile); + final long origSize = file.length(); + + buildRule.executeTarget("testPath"); + + File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); + final long newSize = file2.length(); + + assertEquals(origSize, newSize); + + } + + @Test + public void testAppend() { + test3(); + + File file = new File(buildRule.getProject().getBaseDir(), tempFile); + final long origSize = file.length(); + + buildRule.executeTarget("testAppend"); + + File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); + final long newSize = file2.length(); + + assertEquals(origSize*2, newSize); + + } + + @Test + public void testFilter() { + buildRule.executeTarget("testfilter"); + assertTrue(buildRule.getLog().indexOf("REPLACED") > -1); + } + + @Test + public void testNoOverwrite() { + buildRule.executeTarget("testnooverwrite"); + File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); + long size = file2.length(); + assertEquals(size, 0); + } + + @Test + public void testOverwrite() { + buildRule.executeTarget("testoverwrite"); + File file2 = new File(buildRule.getProject().getBaseDir(), tempFile2); + long size = file2.length(); + assertTrue(size > 0); + } + + @Test + public void testheaderfooter() { + test3(); + buildRule.executeTarget("testheaderfooter"); + assertEquals("headerHello, World!footer", buildRule.getLog()); + } + + @Test + public void testfileheader() { + test3(); + buildRule.executeTarget("testfileheader"); + assertEquals("Hello, World!Hello, World!", buildRule.getLog()); + } + + /** + * Expect an exception when attempting to cat an file to itself + */ + @Test + public void testsame() { + try { + buildRule.executeTarget("samefile"); + fail("Build exception should have been thrown - output file same as input"); + } catch(BuildException ex) { + //TODO assert value + } + } + + /** + * Check if filter inline works + */ + @Test + public void testfilterinline() { + buildRule.executeTarget("testfilterinline"); + assertTrue(buildRule.getLog().indexOf("REPLACED") > -1); + } + + /** + * Check if multireader works + */ + @Test + public void testmultireader() { + buildRule.executeTarget("testmultireader"); + assertTrue(buildRule.getLog().indexOf("Bye") > -1); + assertTrue(buildRule.getLog().indexOf("Hello") == -1); + } + /** + * Check if fixlastline works + */ + @Test + public void testfixlastline() + throws IOException + { + buildRule.executeTarget("testfixlastline"); + assertContains("end of line" + System.getProperty("line.separator") + "This has", + FileUtilities.getFileContents(buildRule.getProject(), "concat.line4")); + } + + /** + * Check if fixlastline works with eol + */ + @Test + public void testfixlastlineeol() + throws IOException + { + buildRule.executeTarget("testfixlastlineeol"); + assertContains("end of line\rThis has", FileUtilities.getFileContents(buildRule.getProject(), "concat.linecr")); + } + + + @Test + public void testTranscoding() throws IOException { + buildRule.executeTarget("testTranscoding"); + File f1 = buildRule.getProject().resolveFile("copy/expected/utf-8"); + File f2 = buildRule.getProject().resolveFile("concat.utf8"); + assertEquals(f1.toString() + " differs from " + f2.toString(), + FileUtilities.getFileContents(f1), FileUtilities.getFileContents(f2)); + } + + // ------------------------------------------------------ + // Helper methods - should be in a utility class + // ----------------------------------------------------- + private void expectFileContainsx( + String target, String filename, String contains) + throws IOException + { + buildRule.executeTarget(target); + String content = FileUtilities.getFileContents(buildRule.getProject(), filename); + assertTrue( + "expecting file " + filename + " to contain " + + contains + + " but got " + content, content.indexOf(contains) > -1); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java new file mode 100644 index 00000000..1b6c1039 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ConditionTest.java @@ -0,0 +1,379 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +public class ConditionTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + + /** + * The JUnit setup method + */ + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/condition.xml"); + } + + + /** + * The teardown method for JUnit + */ + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void testBasic() { + buildRule.executeTarget("basic"); + assertEquals("true", buildRule.getProject().getProperty("basic")); + } + + @Test + public void testConditionIncomplete() { + try { + buildRule.executeTarget("condition-incomplete"); + fail("BuildException should have been thrown - property attribute has been omitted"); + } catch (BuildException ex) { + assertEquals("The property attribute is required.", ex.getMessage()); + } + } + + @Test + public void testConditionEmpty() { + try { + buildRule.executeTarget("condition-empty"); + fail("BuildException should have been thrown - no conditions"); + } catch(BuildException ex) { + assertEquals("You must nest a condition into <condition>", ex.getMessage()); + } + } + + @Test + public void testShortcut() { + buildRule.executeTarget("shortcut"); + assertEquals("set", buildRule.getProject().getProperty("shortcut")); + } + + @Test + public void testUnset() { + buildRule.executeTarget("dontset"); + assertNull(buildRule.getProject().getProperty("dontset")); + } + + @Test + public void testSetValue() { + buildRule.executeTarget("setvalue"); + assertEquals("woowoo", buildRule.getProject().getProperty("setvalue")); + } + + @Test + public void testNegation() { + buildRule.executeTarget("negation"); + assertEquals("true", buildRule.getProject().getProperty("negation")); + } + + @Test + public void testNegationFalse() { + buildRule.executeTarget("negationfalse"); + assertNull(buildRule.getProject().getProperty("negationfalse")); + } + + @Test + public void testNegationIncomplete() { + try { + buildRule.executeTarget("negationincomplete"); + fail("BuildException should have been thrown - no conditions in <not>"); + } catch (BuildException ex) { + assertEquals("You must nest a condition into <not>", ex.getMessage()); + } + } + + @Test + public void testAnd() { + buildRule.executeTarget("and"); + assertEquals("true", buildRule.getProject().getProperty("and")); + } + + @Test + public void testAndFails() { + buildRule.executeTarget("andfails"); + assertNull(buildRule.getProject().getProperty("andfails")); + } + + @Test + public void testAndIncomplete() { + buildRule.executeTarget("andincomplete"); + assertNull(buildRule.getProject().getProperty("andincomplete")); + } + + @Test + public void testAndempty() { + buildRule.executeTarget("andempty"); + assertEquals("true", buildRule.getProject().getProperty("andempty")); + } + + @Test + public void testOr() { + buildRule.executeTarget("or"); + assertEquals("true", buildRule.getProject().getProperty("or")); + } + + @Test + public void testOrincomplete() { + buildRule.executeTarget("or"); + assertEquals("true", buildRule.getProject().getProperty("or")); + } + + @Test + public void testOrFails() { + buildRule.executeTarget("orfails"); + assertNull(buildRule.getProject().getProperty("orfails")); + } + + @Test + public void testOrboth() { + buildRule.executeTarget("orboth"); + assertEquals("true", buildRule.getProject().getProperty("orboth")); + } + + @Test + public void testFilesmatchIdentical() { + buildRule.executeTarget("filesmatch-identical"); + assertEquals("true", buildRule.getProject().getProperty("filesmatch-identical")); + } + + @Test + public void testFilesmatchIncomplete() { + try { + buildRule.executeTarget("filesmatch-incomplete"); + fail("Build exception should have been thrown - Missing file2 attirbute"); + } catch (BuildException ex) { + assertEquals("both file1 and file2 are required in filesmatch", ex.getMessage()); + } + } + + @Test + public void testFilesmatchOddsizes() { + buildRule.executeTarget("filesmatch-oddsizes"); + assertNull(buildRule.getProject().getProperty("filesmatch-oddsizes")); + } + + @Test + public void testFilesmatchExistence() { + buildRule.executeTarget("filesmatch-existence"); + assertNull(buildRule.getProject().getProperty("filesmatch-existence")); + } + + @Test + public void testFilesmatchDifferent() { + buildRule.executeTarget("filesmatch-different"); + assertNull(buildRule.getProject().getProperty("filesmatch-different")); + } + + @Test + public void testFilesmatchMatch() { + buildRule.executeTarget("filesmatch-match"); + assertEquals("true", buildRule.getProject().getProperty("filesmatch-match")); + } + + @Test + public void testFilesmatchDifferentSizes() { + buildRule.executeTarget("filesmatch-different-sizes"); + assertNull(buildRule.getProject().getProperty("filesmatch-different-sizes")); + } + + @Test + public void testFilesmatchDifferentOnemissing() { + buildRule.executeTarget("filesmatch-different-onemissing"); + assertNull(buildRule.getProject().getProperty("filesmatch-different-onemissing")); + } + + @Test + public void testFilesmatchDifferentEol() { + buildRule.executeTarget("filesmatch-different-eol"); + } + + @Test + public void testFilesmatchSameEol() { + buildRule.executeTarget("filesmatch-same-eol"); + } + + @Test + public void testFilesmatchNeitherExist() { + buildRule.executeTarget("filesmatch-neitherexist"); + } + + @Test + public void testContains() { + buildRule.executeTarget("contains"); + assertEquals("true", buildRule.getProject().getProperty("contains")); + } + + @Test + public void testContainsDoesnt() { + buildRule.executeTarget("contains-doesnt"); + assertNull(buildRule.getProject().getProperty("contains-doesnt")); + } + + @Test + public void testContainsAnycase() { + buildRule.executeTarget("contains-anycase"); + assertEquals("true", buildRule.getProject().getProperty("contains-anycase")); + } + + @Test + public void testContainsIncomplete1() { + try { + buildRule.executeTarget("contains-incomplete1"); + fail("BuildException should have been thrown - Missing contains attribute"); + } catch(BuildException ex) { + assertEquals("both string and substring are required in contains", ex.getMessage()); + } + } + + @Test + public void testContainsIncomplete2() { + try { + buildRule.executeTarget("contains-incomplete2"); + fail("BuildException should have been thrown - Missing contains attribute"); + } catch(BuildException ex) { + assertEquals("both string and substring are required in contains", ex.getMessage()); + } + } + + @Test + public void testIstrue() { + buildRule.executeTarget("istrue"); + assertEquals("true", buildRule.getProject().getProperty("istrue")); + } + + @Test + public void testIstrueNot() { + buildRule.executeTarget("istrue-not"); + assertNull(buildRule.getProject().getProperty("istrue-not")); + } + + @Test + public void testIstrueFalse() { + buildRule.executeTarget("istrue-false"); + assertNull(buildRule.getProject().getProperty("istrue-false")); + } + + @Test + public void testIstrueIncomplete1() { + try { + buildRule.executeTarget("istrue-incomplete"); + fail("BuildException should have been thrown - Missing attribute"); + } catch(BuildException ex) { + assertEquals("Nothing to test for truth", ex.getMessage()); + } + } + + @Test + public void testIsfalseTrue() { + buildRule.executeTarget("isfalse-true"); + assertNull(buildRule.getProject().getProperty("isfalse-true")); + } + + @Test + public void testIsfalseNot() { + buildRule.executeTarget("isfalse-not"); + assertEquals("true", buildRule.getProject().getProperty("isfalse-not")); + } + + @Test + public void testIsfalseFalse() { + + buildRule.executeTarget("isfalse-false"); + assertEquals("true", buildRule.getProject().getProperty("isfalse-false")); + } + + @Test + public void testIsfalseIncomplete1() { + try { + buildRule.executeTarget("isfalse-incomplete"); + fail("BuildException should have been thrown - Missing attribute"); + } catch(BuildException ex) { + assertEquals("Nothing to test for falsehood", ex.getMessage()); + } + } + + @Test + public void testElse() { + buildRule.executeTarget("testElse"); + } + + @Test + public void testResourcesmatchError() { + try { + buildRule.executeTarget("resourcematch-error"); + fail("BuildException should have been thrown - no resources specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testResourcesmatchEmpty() { + buildRule.executeTarget("resourcesmatch-match-empty"); + } + + @Test + public void testResourcesmatchOne() { + buildRule.executeTarget("resourcesmatch-match-one"); + } + + @Test + public void testResourcesmatchBinary() { + buildRule.executeTarget("resourcesmatch-match-binary"); + } + + @Test + public void testResourcesmatchMultipleBinary() { + buildRule.executeTarget("resourcesmatch-match-multiple-binary"); + } + + @Test + public void testResourcesmatchDiffer() { + buildRule.executeTarget("resourcesmatch-differ"); + } + + @Test + public void testResourcesmatchText() { + buildRule.executeTarget("resourcesmatch-match-text"); + } + + @Test + public void testResourcesmatchNoneExist() { + buildRule.executeTarget("resourcesmatch-noneexist"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java new file mode 100644 index 00000000..a7a32a9a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopyTest.java @@ -0,0 +1,280 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests FileSet using the Copy task. + * + */ +public class CopyTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/copy.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + buildRule.executeTarget("test1"); + File f = new File(buildRule.getProject().getProperty("output"), "copytest1.tmp"); + if ( !f.exists()) { + fail("Copy failed"); + } + } + + @Test + public void test2() { + buildRule.executeTarget("test2"); + File f = new File(buildRule.getProject().getProperty("output"), "copytest1dir/copy.xml"); + if ( !f.exists()) { + fail("Copy failed"); + } + } + + @Test + public void test3() { + buildRule.executeTarget("test3"); + File file3 = new File(buildRule.getProject().getProperty("output"), "copytest3.tmp"); + //rollback file timestamp instead of delaying test + FileUtilities.rollbackTimetamps(file3, 3); + buildRule.executeTarget("test3Part2"); + assertTrue(file3.exists()); + + File file3a = new File(buildRule.getProject().getProperty("output"), "copytest3a.tmp"); + assertTrue(file3a.exists()); + File file3b = new File(buildRule.getProject().getProperty("output"), "copytest3b.tmp"); + assertTrue(file3b.exists()); + File file3c = new File(buildRule.getProject().getProperty("output"), "copytest3c.tmp"); + assertTrue(file3c.exists()); + + //file length checks rely on touch generating a zero byte file + if(file3.length()==0) { + fail("could not overwrite an existing, older file"); + } + if(file3c.length()!=0) { + fail("could not force overwrite an existing, newer file"); + } + if(file3b.length()==0) { + fail("unexpectedly overwrote an existing, newer file"); + } + + //file time checks for java1.2+ + assertTrue(file3a.lastModified()==file3.lastModified()); + assertTrue(file3c.lastModified()<file3a.lastModified()); + + } + + @Test + public void testFilterTest() { + buildRule.executeTarget("filtertest"); + assertTrue(buildRule.getLog().indexOf("loop in tokens") == -1); + } + + @Test + public void testInfiniteFilter() { + buildRule.executeTarget("infinitetest"); + assertContains("loop in tokens", buildRule.getOutput()); + } + + @Test + public void testFilterSet() throws IOException { + buildRule.executeTarget("testFilterSet"); + File tmp = new File(buildRule.getProject().getProperty("output"), "copy.filterset.tmp"); + File check = new File(buildRule.getProject().getBaseDir(), "expected/copy.filterset.filtered"); + assertTrue(tmp.exists()); + assertEquals(FileUtilities.getFileContents(tmp), FileUtilities.getFileContents(check)); + } + + @Test + public void testFilterChain() throws IOException { + buildRule.executeTarget("testFilterChain"); + File tmp = new File(buildRule.getProject().getProperty("output"), "copy.filterchain.tmp"); + File check = new File(buildRule.getProject().getBaseDir(), "expected/copy.filterset.filtered"); + assertTrue(tmp.exists()); + assertEquals(FileUtilities.getFileContents(tmp), FileUtilities.getFileContents(check)); + } + + @Test + public void testSingleFileFileset() { + buildRule.executeTarget("test_single_file_fileset"); + File file = new File(buildRule.getProject().getProperty("output"), + "copytest_single_file_fileset.tmp"); + assertTrue(file.exists()); + } + + @Test + public void testSingleFilePath() { + buildRule.executeTarget("test_single_file_path"); + File file = new File(buildRule.getProject().getProperty("output"), + "copytest_single_file_path.tmp"); + assertTrue(file.exists()); + } + + @Test + public void testTranscoding() throws IOException { + buildRule.executeTarget("testTranscoding"); + File f1 = buildRule.getProject().resolveFile("copy/expected/utf-8"); + File f2 = new File(buildRule.getProject().getProperty("output"), "copytest1.tmp"); + assertEquals(FileUtilities.getFileContents(f1), FileUtilities.getFileContents(f2)); + } + + @Test + public void testMissingFileIgnore() { + buildRule.executeTarget("testMissingFileIgnore"); + assertContains("Warning: Could not find file", buildRule.getLog()); + } + + @Test + public void testMissingFileBail() { + try { + buildRule.executeTarget("testMissingFileBail"); + fail("not-there doesn't exist"); + } catch (BuildException ex) { + assertTrue(ex.getMessage() + .startsWith("Warning: Could not find file ")); + } + } + + @Test + public void testMissingDirIgnore() { + buildRule.executeTarget("testMissingDirIgnore"); + assertContains("Warning: ", buildRule.getLog()); + } + + @Test + public void testMissingDirBail() { + try { + buildRule.executeTarget("testMissingDirBail"); + fail("not-there doesn't exist"); + } catch (BuildException ex) { + assertTrue(ex.getMessage().endsWith(" does not exist.")); + } + } + + @Test + public void testFileResourcePlain() { + buildRule.executeTarget("testFileResourcePlain"); + File file1 = new File(buildRule.getProject().getProperty("to.dir")+"/file1.txt"); + File file2 = new File(buildRule.getProject().getProperty("to.dir")+"/file2.txt"); + File file3 = new File(buildRule.getProject().getProperty("to.dir")+"/file3.txt"); + assertTrue(file1.exists()); + assertTrue(file2.exists()); + assertTrue(file3.exists()); + } + + @Ignore("Previously ignored by naming convention") + @Test + public void testFileResourceWithMapper() { + buildRule.executeTarget("testFileResourceWithMapper"); + File file1 = new File(buildRule.getProject().getProperty("to.dir")+"/file1.txt.bak"); + File file2 = new File(buildRule.getProject().getProperty("to.dir")+"/file2.txt.bak"); + File file3 = new File(buildRule.getProject().getProperty("to.dir")+"/file3.txt.bak"); + assertTrue(file1.exists()); + assertTrue(file2.exists()); + assertTrue(file3.exists()); + } + + @Test + public void testFileResourceWithFilter() { + buildRule.executeTarget("testFileResourceWithFilter"); + File file1 = new File(buildRule.getProject().getProperty("to.dir")+"/fileNR.txt"); + assertTrue(file1.exists()); + try { + String file1Content = FileUtils.readFully(new FileReader(file1)); + assertEquals("This is file 42", file1Content); + } catch (IOException e) { + // no-op: not a real business error + } + } + + @Test + public void testPathAsResource() { + buildRule.executeTarget("testPathAsResource"); + File file1 = new File(buildRule.getProject().getProperty("to.dir")+"/file1.txt"); + File file2 = new File(buildRule.getProject().getProperty("to.dir")+"/file2.txt"); + File file3 = new File(buildRule.getProject().getProperty("to.dir")+"/file3.txt"); + assertTrue(file1.exists()); + assertTrue(file2.exists()); + assertTrue(file3.exists()); + } + + @Test + public void testZipfileset() { + buildRule.executeTarget("testZipfileset"); + File file1 = new File(buildRule.getProject().getProperty("to.dir")+"/file1.txt"); + File file2 = new File(buildRule.getProject().getProperty("to.dir")+"/file2.txt"); + File file3 = new File(buildRule.getProject().getProperty("to.dir")+"/file3.txt"); + assertTrue(file1.exists()); + assertTrue(file2.exists()); + assertTrue(file3.exists()); + } + + @Test + public void testDirset() { + buildRule.executeTarget("testDirset"); + } + + @Ignore("Previously ignored due to naming convention") + @Test + public void testResourcePlain() { + buildRule.executeTarget("testResourcePlain"); + } + + @Ignore("Previously ignored due to naming convention") + @Test + public void testResourcePlainWithMapper() { + buildRule.executeTarget("testResourcePlainWithMapper"); + } + + @Ignore("Previously ignored due to naming convention") + @Test + public void testResourcePlainWithFilter() { + buildRule.executeTarget("testResourcePlainWithFilter"); + } + + @Ignore("Previously ignored due to naming convention") + @Test + public void testOnlineResources() { + buildRule.executeTarget("testOnlineResources"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java new file mode 100644 index 00000000..a7fdd5cb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopydirTest.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +public class CopydirTest { + + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/copydir.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + assertEquals("DEPRECATED - The copydir task is deprecated. Use copy instead.Warning: src == dest", + buildRule.getLog()); + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + java.io.File f = new java.io.File(new File(buildRule.getProject().getProperty("output")), "taskdefs.tmp"); + + if (!f.exists() || !f.isDirectory()) { + fail("Copy failed"); + } + // We keep this, so we have something to delete in later tests :-) + } + + @Test + public void test6() { + try { + buildRule.executeTarget("test6"); + fail("target is file"); + } catch (BuildException ex) { + //TODO assert value + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java new file mode 100644 index 00000000..a3d84eeb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/CopyfileTest.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + */ +public class CopyfileTest { + + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/copyfile.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + assertEquals("DEPRECATED - The copyfile task is deprecated. Use copy instead.Warning: src == dest", + buildRule.getLog()); + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + File f = new File(new File(buildRule.getProject().getProperty("output")), "copyfile.tmp"); + if (f.exists()) { + f.delete(); + } else { + fail("Copy failed"); + } + } + + @Test + public void test6() { + try { + buildRule.executeTarget("test6"); + fail("Required argument not specified"); + } catch (BuildException ex) { + // TODO assert value + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java new file mode 100644 index 00000000..e093d4f7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DefaultExcludesTest.java @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.DirectoryScanner; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + */ +public class DefaultExcludesTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/defaultexcludes.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + // Output the default excludes + @Test + public void test1() { + String[] expected = { + "**/*~", + "**/#*#", + "**/.#*", + "**/%*%", + "**/._*", + "**/CVS", + "**/CVS/**", + "**/.cvsignore", + "**/SCCS", + "**/SCCS/**", + "**/vssver.scc", + "**/.svn", + "**/.svn/**", + "**/.git", + "**/.git/**", + "**/.gitattributes", + "**/.gitignore", + "**/.gitmodules", + "**/.hg", + "**/.hg/**", + "**/.hgignore", + "**/.hgsub", + "**/.hgsubstate", + "**/.hgtags", + "**/.bzr", + "**/.bzr/**", + "**/.bzrignore", + "**/.DS_Store"}; + buildRule.getProject().executeTarget("test1"); + assertArrayContentsEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); + } + + // adding something to the excludes' + @Test + public void test2() { + String[] expected = { + "**/*~", + "**/#*#", + "**/.#*", + "**/%*%", + "**/._*", + "**/CVS", + "**/CVS/**", + "**/.cvsignore", + "**/SCCS", + "**/SCCS/**", + "**/vssver.scc", + "**/.svn", + "**/.svn/**", + "**/.git", + "**/.git/**", + "**/.gitattributes", + "**/.gitignore", + "**/.gitmodules", + "**/.hg", + "**/.hg/**", + "**/.hgignore", + "**/.hgsub", + "**/.hgsubstate", + "**/.hgtags", + "**/.bzr", + "**/.bzr/**", + "**/.bzrignore", + "**/.DS_Store", + "foo"}; + buildRule.executeTarget("test2"); + assertArrayContentsEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); + } + + // removing something from the defaults + @Test + public void test3() { + String[] expected = { + "**/*~", + "**/#*#", + "**/.#*", + "**/%*%", + "**/._*", + //CVS missing + "**/CVS/**", + "**/.cvsignore", + "**/SCCS", + "**/SCCS/**", + "**/vssver.scc", + "**/.svn", + "**/.svn/**", + "**/.git", + "**/.git/**", + "**/.gitattributes", + "**/.gitignore", + "**/.gitmodules", + "**/.hg", + "**/.hg/**", + "**/.hgignore", + "**/.hgsub", + "**/.hgsubstate", + "**/.hgtags", + "**/.bzr", + "**/.bzr/**", + "**/.bzrignore", + "**/.DS_Store"}; + buildRule.executeTarget("test3"); + assertArrayContentsEquals("current default excludes", expected, DirectoryScanner.getDefaultExcludes()); + } + + private void assertArrayContentsEquals(String message, String[] expected, String[] actual) { + // check that both arrays have the same size + assertEquals(message + " : string array length match", expected.length, actual.length); + for (int counter=0; counter < expected.length; counter++) { + boolean found = false; + for (int i = 0; !found && i < actual.length; i++) { + found |= expected[counter].equals(actual[i]); + } + assertTrue(message + " : didn't find element " + + expected[counter] + " in array match", found); + } + + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DeleteTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DeleteTest.java new file mode 100644 index 00000000..fb244213 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DeleteTest.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + */ +public class DeleteTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/delete.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + buildRule.executeTarget("test2"); + } +//where oh where has my test case 3 gone? + @Test + public void test4() { + buildRule.executeTarget("test4"); + } + @Test + public void test5() { + buildRule.executeTarget("test5"); + } + @Test + public void test6() { + buildRule.executeTarget("test6"); + } + @Test + public void test7() { + buildRule.executeTarget("test7"); + } + @Test + public void test8() { + buildRule.executeTarget("test8"); + } + @Test + public void test9() { + buildRule.executeTarget("test9"); + } + @Test + public void test10() { + buildRule.executeTarget("test10"); + } + @Test + public void test11() { + buildRule.executeTarget("test11"); + } + @Test + public void test12() { + buildRule.executeTarget("test12"); + } + @Test + public void test13() { + buildRule.executeTarget("test13"); + } + @Test + public void test14() { + buildRule.executeTarget("test14"); + } + @Test + public void test15() { + buildRule.executeTarget("test15"); + } + @Test + public void test16() { + buildRule.executeTarget("test16"); + } + @Test + public void test17() { + buildRule.executeTarget("test17"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java new file mode 100644 index 00000000..b2dcc69e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DeltreeTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class DeltreeTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/deltree.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + // We try to delete the directory created in CopydirTest + buildRule.executeTarget("test2"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DemuxOutputTask.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DemuxOutputTask.java new file mode 100644 index 00000000..e5e3b2f9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DemuxOutputTask.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.util.Random; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; + +/** + * A simple task that prints to System.out and System.err and then catches + * the output which it then checks. If the output does not match, an + * exception is thrown + * + * @since 1.5 + * @created 21 February 2002 + */ +public class DemuxOutputTask extends Task { + private String randomOutValue; + private String randomErrValue; + private boolean outputReceived = false; + private boolean errorReceived = false; + + public void execute() { + Random generator = new Random(); + randomOutValue = "Output Value is " + generator.nextInt(); + randomErrValue = "Error Value is " + generator.nextInt(); + + System.out.println(randomOutValue); + System.err.println(randomErrValue); + if (!outputReceived) { + throw new BuildException("Did not receive output"); + } + + if (!errorReceived) { + throw new BuildException("Did not receive error"); + } + } + + protected void handleOutput(String line) { + line = line.trim(); + if (line.length() != 0 && !line.equals(randomOutValue)) { + String message = "Received = [" + line + "], expected = [" + + randomOutValue + "]"; + throw new BuildException(message); + } + outputReceived = true; + } + + protected void handleErrorOutput(String line) { + line = line.trim(); + if (line.length() != 0 && !line.equals(randomErrValue)) { + String message = "Received = [" + line + "], expected = [" + + randomErrValue + "]"; + throw new BuildException(message); + } + errorReceived = true; + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java new file mode 100644 index 00000000..96c6c4a1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DirnameTest.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.taskdefs.condition.Os; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + */ +public class DirnameTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/dirname.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Build exception should have been thrown as property attribute is required"); + } catch(BuildException ex) { + assertEquals("property attribute required", ex.getMessage()); + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Build exception should have been thrown as file attribute is required"); + } catch(BuildException ex) { + assertEquals("file attribute required", ex.getMessage()); + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("Build exception should have been thrown as property attribute is required"); + } catch(BuildException ex) { + assertEquals("property attribute required", ex.getMessage()); + } + } + + @Test + public void test4() { + Assume.assumeFalse("Test not possible on DOS or Netware family OS", Os.isFamily("netware") || Os.isFamily("dos")); + buildRule.executeTarget("test4"); + String filesep = System.getProperty("file.separator"); + String expected = filesep + "usr" + filesep + "local"; + String checkprop = buildRule.getProject().getProperty("local.dir"); + assertEquals("dirname failed", expected, checkprop); + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + String expected = buildRule.getProject().getProperty("basedir"); + String checkprop = buildRule.getProject().getProperty("base.dir"); + assertEquals("dirname failed", expected, checkprop); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DynamicTask.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DynamicTask.java new file mode 100644 index 00000000..0d4b6cda --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DynamicTask.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.DynamicConfigurator; +import org.apache.tools.ant.Task; + +public class DynamicTask extends Task implements DynamicConfigurator { + + public void execute() { + } + + public void setDynamicAttribute(String name, String value) { + getProject().setNewProperty(name, value); + } + + public Object createDynamicElement(String name) { + return new Sub(); + } + + public class Sub implements DynamicConfigurator { + public void setDynamicAttribute(String name, String value) { + getProject().setNewProperty(name, value); + } + + public Object createDynamicElement(String name) { + return null; + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DynamicTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DynamicTest.java new file mode 100644 index 00000000..615dd903 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/DynamicTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class DynamicTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/dynamictask.xml"); + } + + @Test + public void testSimple() { + buildRule.executeTarget("simple"); + assertEquals("1", buildRule.getProject().getProperty("prop1")); + assertEquals("2", buildRule.getProject().getProperty("prop2")); + assertEquals("3", buildRule.getProject().getProperty("prop3")); + assertEquals("4", buildRule.getProject().getProperty("prop4")); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java new file mode 100644 index 00000000..5c2ae28e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/EchoTest.java @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintStream; + +import org.apache.tools.ant.DefaultLogger; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.FileUtils; +import org.junit.After; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Test Java-dependent parts of the Echo task. + */ +public class EchoTest { + + private File removeThis; + + @Test + public void testLogBlankEcho() { + Project p = new Project(); + p.init(); + EchoTestLogger logger = new EchoTestLogger(); + p.addBuildListener(logger); + Echo echo = new Echo(); + echo.setProject(p); + echo.setTaskName("testLogBlankEcho"); + echo.execute(); + assertEquals("[testLogBlankEcho] ", logger.lastLoggedMessage ); + } + + @Test + public void testLogUTF8Echo() throws IOException { + Project p = new Project(); + p.init(); + EchoTestLogger logger = new EchoTestLogger(); + p.addBuildListener(logger); + Echo echo = new Echo(); + echo.setProject(p); + echo.setTaskName("testLogUTF8Echo"); + echo.setMessage("\u00e4\u00a9"); + removeThis = new File("abc.txt"); + echo.setFile(removeThis); + echo.setEncoding("UTF-8"); + echo.execute(); + String x = FileUtils.readFully(new InputStreamReader(new FileInputStream(removeThis), "UTF-8" )); + assertEquals(x,"\u00e4\u00a9"); + } + + @After + public void tearDown() { + if (removeThis != null && removeThis.exists()) { + if (!removeThis.delete()) + { + removeThis.deleteOnExit(); + } + } + } + + private class EchoTestLogger extends DefaultLogger { + String lastLoggedMessage; + + /** + * Create a new EchoTestLogger. + */ + public EchoTestLogger() { + super(); + this.setMessageOutputLevel(Project.MSG_DEBUG); + this.setOutputPrintStream(new PrintStream(new ByteArrayOutputStream(256))); + this.setErrorPrintStream(new PrintStream(new ByteArrayOutputStream(256))); + } + + /** + * {@inheritDoc} + */ + protected void log(String message) { + this.lastLoggedMessage = message; + } + + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java new file mode 100644 index 00000000..cc9ec24e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/EchoXMLTest.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.fail; + +public class EchoXMLTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/echoxml.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("tearDown"); + } + + @Test + public void testPass() { + buildRule.executeTarget("testPass"); + } + + @Test + public void testFail() { + try { + buildRule.executeTarget("testFail"); + fail("BuildException expected: must fail"); + } catch (BuildException ex) { + assertContains("${foo}=bar", ex.getMessage()); + } + } + + @Test + public void testEmpty() { + try { + buildRule.executeTarget("testEmpty"); + fail("BuildException expected: must fail"); + } catch (BuildException ex) { + assertContains("No nested XML specified", ex.getMessage()); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java new file mode 100644 index 00000000..b7427606 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecTaskTest.java @@ -0,0 +1,192 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.util.GregorianCalendar; + +import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.BuildListener; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.ProjectHelper; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +/** + * Unit test for the <exec> task. + */ +public class ExecTaskTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private static final String BUILD_PATH = "src/etc/testcases/taskdefs/exec/"; + private static final String BUILD_FILE = BUILD_PATH + "exec.xml"; + private static final int TIME_TO_WAIT = 1; + /** maximum time allowed for the build in milliseconds */ + private static final int MAX_BUILD_TIME = 6000; + private static final int SECURITY_MARGIN = 4000; // wait 4 second extras + // the test failed with 100 ms of margin on cvs.apache.org on August 1st, 2003 + // the test randomly failed with 3 s of margin on Windows Jenkins slaves on during July 2014 + + /** Utilities used for file operations */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + private File logFile; + private MonitoredBuild myBuild = null; + volatile private boolean buildFinished = false; + + + @Before + public void setUp() { + buildRule.configureProject(BUILD_FILE); + } + + @Test + public void testspawn() throws InterruptedException { + buildRule.getProject().executeTarget("setUp"); + Assume.assumeNotNull(buildRule.getProject().getProperty("test.can.run")); + myBuild = new MonitoredBuild(new File(System.getProperty("root"), BUILD_FILE), "spawn"); + logFile = FILE_UTILS.createTempFile("spawn", "log", new File(buildRule.getProject().getProperty("output")), + false, false); + // this is guaranteed by FileUtils#createTempFile + assertTrue("log file not existing", !logFile.exists()); + // make the spawned process run 1 seconds + myBuild.setTimeToWait(TIME_TO_WAIT); + myBuild.setLogFile(logFile.getAbsolutePath()); + myBuild.addBuildListener(new MonitoredBuildListener()); + myBuild.start(); + GregorianCalendar startwait = new GregorianCalendar(); + // this loop runs parallel to the build + while (!buildFinished) { + Thread.sleep(10); + GregorianCalendar now = new GregorianCalendar(); + // security + if (now.getTime().getTime() - startwait.getTime().getTime() > MAX_BUILD_TIME) { + System.out.println("aborting wait, too long " + + (now.getTime().getTime() - startwait.getTime().getTime()) + + "milliseconds"); + break; + } + } + // now wait until the spawned process is finished + Thread.sleep((TIME_TO_WAIT) * 1000 + SECURITY_MARGIN); + // time of the build in milli seconds + long elapsed = myBuild.getTimeElapsed(); + assertTrue("we waited more than the process lasted", + TIME_TO_WAIT * 1000 + SECURITY_MARGIN > elapsed); + logFile = new File(logFile.getAbsolutePath()); + assertTrue("log file found after spawn", logFile.exists()); + } + + @Test + @Ignore("#50507 - fails at least on Linux") + /* TODO #50507 - fails at least on Linux */ + public void testOutAndErr() { + buildRule.getProject().executeTarget("test-out-and-err"); + } + + private static class MonitoredBuild implements Runnable { + private Thread worker; + private File myBuildFile = null; + private String target = null; + private Project project = null; + private GregorianCalendar timeStarted = null; + private GregorianCalendar timeFinished = null; + + public void setLogFile(String logFile) { + project.setProperty("logFile", logFile); + } + + public void setTimeToWait(int timeToWait) { + project.setProperty("timeToWait", Long.toString(timeToWait)); + } + + public void addBuildListener(BuildListener bl) { + project.addBuildListener(bl); + } + + public MonitoredBuild(File buildFile, String target) { + myBuildFile = buildFile; + this.target = target; + project = new Project(); + project = new Project(); + project.init(); + project.setUserProperty("ant.file", myBuildFile.getAbsolutePath()); + ProjectHelper.configureProject(project, myBuildFile); + } + + /** + * + * @return time in millis of the build + */ + public long getTimeElapsed() { + return timeFinished.getTime().getTime() - timeStarted.getTime().getTime(); + } + + public void start() { + worker = new Thread(this, myBuildFile.toString() + "/" + target); + worker.start(); + } + + public void run() { + startProject(); + } + + private void startProject() { + timeStarted = new GregorianCalendar(); + project.executeTarget(target); + timeFinished = new GregorianCalendar(); + } + } + + private class MonitoredBuildListener implements BuildListener { + public void buildStarted(BuildEvent event) { + } + + public void buildFinished(BuildEvent event) { + } + + public void targetStarted(BuildEvent event) { + } + + public void targetFinished(BuildEvent event) { + if (event.getTarget().getName().equals("spawn")) { + buildFinished = true; + } + } + + public void taskStarted(BuildEvent event) { + } + + public void taskFinished(BuildEvent event) { + } + + public void messageLogged(BuildEvent event) { + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java new file mode 100644 index 00000000..069645b3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteJavaTest.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.MagicNames; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.Commandline; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Simple testcase for the ExecuteJava class - mostly stolen from + * ExecuteWatchdogTest. + * + */ +public class ExecuteJavaTest { + + private final static int TIME_OUT = 5000; + + private final static int CLOCK_ERROR=200; + private final static int TIME_OUT_TEST=TIME_OUT-CLOCK_ERROR; + + private ExecuteJava ej; + private Project project; + private Path cp; + + @Before + public void setUp(){ + ej = new ExecuteJava(); + ej.setTimeout((long)TIME_OUT); + project = new Project(); + project.setBasedir("."); + project.setProperty(MagicNames.ANT_HOME, System.getProperty(MagicNames.ANT_HOME)); + cp = new Path(project, getTestClassPath()); + ej.setClasspath(cp); + } + + private Commandline getCommandline(int timetorun) throws Exception { + Commandline cmd = new Commandline(); + cmd.setExecutable(TimeProcess.class.getName()); + cmd.createArgument().setValue(String.valueOf(timetorun)); + return cmd; + } + + @Test + public void testNoTimeOut() throws Exception { + Commandline cmd = getCommandline(TIME_OUT/2); + ej.setJavaCommand(cmd); + ej.execute(project); + assertTrue("process should not have been killed", !ej.killedProcess()); + } + + // test that the watchdog ends the process + @Test + public void testTimeOut() throws Exception { + Commandline cmd = getCommandline(TIME_OUT*2); + ej.setJavaCommand(cmd); + long now = System.currentTimeMillis(); + ej.execute(project); + long elapsed = System.currentTimeMillis() - now; + assertTrue("process should have been killed", ej.killedProcess()); + + assertTrue("elapse time of "+elapsed + +" ms is less than timeout value of "+TIME_OUT_TEST+" ms", + elapsed >= TIME_OUT_TEST); + assertTrue("elapse time of "+elapsed + +" ms is greater than run value of "+(TIME_OUT*2)+" ms", + elapsed < TIME_OUT*2); + } + + @Test + public void testNoTimeOutForked() throws Exception { + Commandline cmd = getCommandline(TIME_OUT/2); + ej.setJavaCommand(cmd); + ej.fork(cp); + assertTrue("process should not have been killed", !ej.killedProcess()); + } + + // test that the watchdog ends the process + @Test + public void testTimeOutForked() throws Exception { + Commandline cmd = getCommandline(TIME_OUT*2); + ej.setJavaCommand(cmd); + long now = System.currentTimeMillis(); + ej.fork(cp); + long elapsed = System.currentTimeMillis() - now; + assertTrue("process should have been killed", ej.killedProcess()); + + assertTrue("elapse time of "+elapsed + +" ms is less than timeout value of "+TIME_OUT_TEST+" ms", + elapsed >= TIME_OUT_TEST); + assertTrue("elapse time of "+elapsed + +" ms is greater than run value of "+(TIME_OUT*2)+" ms", + elapsed < TIME_OUT*2); + } + + /** + * Dangerous method to obtain the classpath for the test. This is + * severely tighted to the build.xml properties. + */ + private static String getTestClassPath(){ + String classpath = System.getProperty("build.tests"); + if (classpath == null) { + System.err.println("WARNING: 'build.tests' property is not available !"); + classpath = System.getProperty("java.class.path"); + } + + return classpath; + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java new file mode 100644 index 00000000..1834d5e3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ExecuteWatchdogTest.java @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.BufferedReader; +import java.io.InputStreamReader; + +import org.apache.tools.ant.util.JavaEnvUtils; +import org.junit.Before; +import org.junit.Test; +import org.junit.internal.AssumptionViolatedException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Simple testcase for the ExecuteWatchdog class. + * + */ +public class ExecuteWatchdogTest { + + private final static long TIME_OUT = 5000; + + private final static String TEST_CLASSPATH = getTestClassPath(); + + private final static int CLOCK_ERROR=200; + private final static long TIME_OUT_TEST=TIME_OUT-CLOCK_ERROR; + + private ExecuteWatchdog watchdog; + + @Before + public void setUp(){ + watchdog = new ExecuteWatchdog(TIME_OUT); + } + + /** + * Dangerous method to obtain the classpath for the test. This is + * severely tied to the build.xml properties. + */ + private static String getTestClassPath(){ + String classpath = System.getProperty("build.tests"); + if (classpath == null) { + System.err.println("WARNING: 'build.tests' property is not available !"); + classpath = System.getProperty("java.class.path"); + } + + return classpath; + } + + private Process getProcess(long timetorun) throws Exception { + String[] cmdArray = { + JavaEnvUtils.getJreExecutable("java"), "-classpath", TEST_CLASSPATH, + TimeProcess.class.getName(), String.valueOf(timetorun) + }; + //System.out.println("Testing with classpath: " + System.getProperty("java.class.path")); + return Runtime.getRuntime().exec(cmdArray); + } + + private String getErrorOutput(Process p) throws Exception { + BufferedReader err = new BufferedReader( new InputStreamReader(p.getErrorStream()) ); + StringBuffer buf = new StringBuffer(); + String line; + while ( (line = err.readLine()) != null){ + buf.append(line); + } + return buf.toString(); + } + + private int waitForEnd(Process p) throws Exception { + int retcode = p.waitFor(); + if (retcode != 0){ + String err = getErrorOutput(p); + if (err.length() > 0){ + System.err.println("ERROR:"); + System.err.println(err); + } + } + return retcode; + } + + @Test + public void testNoTimeOut() throws Exception { + Process process = getProcess(TIME_OUT/2); + watchdog.start(process); + int retCode = waitForEnd(process); + assertTrue("process should not have been killed", !watchdog.killedProcess()); + assertFalse(Execute.isFailure(retCode)); + } + + // test that the watchdog ends the process + @Test + public void testTimeOut() throws Exception { + Process process = getProcess(TIME_OUT*2); + long now = System.currentTimeMillis(); + watchdog.start(process); + int retCode = process.waitFor(); + long elapsed = System.currentTimeMillis() - now; + assertTrue("process should have been killed", watchdog.killedProcess()); + // assertTrue("return code is invalid: " + retCode, retCode!=0); + assertTrue("elapse time of "+elapsed+" ms is less than timeout value of "+TIME_OUT_TEST+" ms", elapsed >= TIME_OUT_TEST); + assertTrue("elapse time of "+elapsed+" ms is greater than run value of "+(TIME_OUT*2)+" ms", elapsed < TIME_OUT*2); + } + + // test a process that runs and failed + @Test + public void testFailed() throws Exception { + Process process = getProcess(-1); // process should abort + watchdog.start(process); + int retCode = process.waitFor(); + assertTrue("process should not have been killed", !watchdog.killedProcess()); + assertTrue("return code is invalid: " + retCode, retCode!=0); + } + + @Test + public void testManualStop() throws Exception { + final Process process = getProcess(TIME_OUT*2); + watchdog.start(process); + + // I assume that starting this takes less than TIME_OUT/2 ms... + Thread thread = new Thread(){ + public void run(){ + try { + process.waitFor(); + } catch(InterruptedException e){ + // not very nice but will do the job + throw new AssumptionViolatedException("process interrupted in thread", e); + } + } + }; + thread.start(); + + // wait for TIME_OUT/2, there should be about TIME_OUT/2 ms remaining before timeout + thread.join(TIME_OUT/2); + + // now stop the watchdog. + watchdog.stop(); + + // wait for the thread to die, should be the end of the process + thread.join(); + + // process should be dead and well finished + assertEquals(0, process.exitValue()); + assertTrue("process should not have been killed", !watchdog.killedProcess()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java new file mode 100644 index 00000000..8883558d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FailTest.java @@ -0,0 +1,210 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + */ +public class FailTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/fail.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals("No message", ex.getMessage()); + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals("test2", ex.getMessage()); + } + } + + @Test + public void testText() { + try { + buildRule.executeTarget("testText"); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals("testText", ex.getMessage()); + } + } + + @Test + public void testIf() { + buildRule.executeTarget("testIf"); + buildRule.getProject().setProperty("foo", ""); + try { + buildRule.executeTarget("testIf"); + fail("testIf must fail if foo has been set") ; + } catch (BuildException ex) { + //TODO assert result + } + } + + @Test + public void testUnless() { + try { + buildRule.executeTarget("testUnless"); + fail("testUnless must fail unless foo has been set") ; + } catch (BuildException ex) { + //TODO assert rules + } + buildRule.getProject().setProperty("foo", ""); + buildRule.executeTarget("testUnless"); + + } + + /** + * see that the different combinations work, and + * that the autogenerated text contains information + * about which condition was not met + */ + @Test + public void testIfAndUnless() { + //neither + buildRule.executeTarget("testIfAndUnless"); + buildRule.getProject().setProperty("if", ""); + try { + buildRule.executeTarget("testIfAndUnless"); + fail("expect fail on defined(if)") ; + } catch (BuildException ex) { + assertEquals("if=if and unless=unless", ex.getMessage()); + } + buildRule.getProject().setProperty("unless", ""); + //this call should succeed as unless overrides if + buildRule.executeTarget("testIfAndUnless"); + } + /** + * see that the different combinations work, and + * that the autogenerated text contains information + * about which condition was not met + */ + @Test + public void testIfAndUnless2() { + buildRule.getProject().setProperty("unless", ""); + buildRule.executeTarget("testIfAndUnless"); + } + + @Test + public void testNested1() { + try { + buildRule.executeTarget("testNested1"); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals("condition satisfied", ex.getMessage()); + } + } + + @Test + public void testNested2() { + buildRule.executeTarget("testNested2"); + } + + @Test + public void testNested3() { + try { + buildRule.executeTarget("testNested3"); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals("testNested3", ex.getMessage()); + } + } + + @Test + public void testNested4() { + String specificMessage = "Nested conditions " + + "not permitted in conjunction with if/unless attributes"; + + char[] c = {'a', 'b', 'c'}; + StringBuffer target = new StringBuffer("testNested4x"); + + for (int i = 0; i < c.length; i++) { + target.setCharAt(target.length() - 1, c[i]); + try { + buildRule.executeTarget(target.toString()); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals(specificMessage, ex.getMessage()); + } + } + } + + @Test + public void testNested5() { + try { + buildRule.executeTarget("testNested5"); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals("Only one nested condition is allowed.", ex.getMessage()); + } + } + + @Test + public void testNested6() { + try { + buildRule.executeTarget("testNested6"); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals("testNested6\ntestNested6\ntestNested6", ex.getMessage()); + } + } + + @Test + public void testNested7() { + String specificMessage = "A single nested condition is required."; + + char[] c = {'a', 'b'}; + StringBuffer target = new StringBuffer("testNested7x"); + + for (int i = 0; i < c.length; i++) { + target.setCharAt(target.length() - 1, c[i]); + try { + buildRule.executeTarget(target.toString()); + fail("it is required to fail :-)") ; + } catch (BuildException ex) { + assertEquals(specificMessage, ex.getMessage()); + } + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java new file mode 100644 index 00000000..fdbec6e8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FilterTest.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +public class FilterTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/filter.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + assertEquals("2000", + getFilteredFile("5", "filtered.tmp")); + } + + + @Test + public void test6() { + buildRule.executeTarget("test6"); + assertEquals("2000", + getFilteredFile("6", "taskdefs.tmp/filter1.txt")); + } + + @Test + public void test7() { + buildRule.executeTarget("test7"); + assertEquals("<%@ include file=\"root/some/include.jsp\"%>", + getFilteredFile("7", "filtered.tmp")); + } + + @Test + public void test8() { + buildRule.executeTarget("test8"); + assertEquals("<%@ include file=\"root/some/include.jsp\"%>", + getFilteredFile("8", "taskdefs.tmp/filter2.txt")); + } + + @Test + public void test9() { + buildRule.executeTarget("test9"); + assertEquals("included", + getFilteredFile("9", "taskdefs.tmp/filter3.txt")); + } + + private String getFilteredFile(String testNumber, String filteredFile) { + + String line = null; + File f = new File(buildRule.getProject().getBaseDir(), filteredFile); + if (!f.exists()) { + fail("filter test"+testNumber+" failed"); + } else { + BufferedReader in = null; + try { + in = new BufferedReader(new FileReader(f)); + } catch (FileNotFoundException fnfe) { + fail("filter test"+testNumber+" failed, filtered file: " + f.toString() + " not found"); + } + try { + line = in.readLine(); + in.close(); + } catch (IOException ioe) { + fail("filter test"+testNumber+" failed. IOException while reading filtered file: " + ioe); + } + } + f.delete(); + return line; + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FixCrLfTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FixCrLfTest.java new file mode 100644 index 00000000..06a18cc8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/FixCrLfTest.java @@ -0,0 +1,262 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import junit.framework.AssertionFailedError; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + */ +public class FixCrLfTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/fixcrlf/build.xml"); + } + + @Test + public void test1() throws IOException { + buildRule.executeTarget("test1"); + } + + @Test + public void test2() throws IOException { + buildRule.executeTarget("test2"); + } + + @Test + public void test3() throws IOException { + buildRule.executeTarget("test3"); + } + + @Test + public void test4() throws IOException { + buildRule.executeTarget("test4"); + } + + @Test + public void test5() throws IOException { + buildRule.executeTarget("test5"); + } + + @Test + public void test6() throws IOException { + buildRule.executeTarget("test6"); + } + + @Test + public void test7() throws IOException { + buildRule.executeTarget("test7"); + } + + @Test + public void test8() throws IOException { + buildRule.executeTarget("test8"); + } + + @Test + public void test9() throws IOException { + buildRule.executeTarget("test9"); + } + + @Test + public void testMacLines() throws IOException { + buildRule.executeTarget("testMacLines"); + } + + @Test + public void testNoOverwrite() throws IOException { + buildRule.executeTarget("testNoOverwrite"); + } + + @Test + public void testEncoding() throws IOException { + buildRule.executeTarget("testEncoding"); + } + + @Test + public void testOutputEncoding() throws IOException { + buildRule.executeTarget("testOutputEncoding"); + } + + @Test + public void testLongLines() throws IOException { + buildRule.executeTarget("testLongLines"); + } + + @Test + public void testCrCrLfSequenceUnix() throws IOException { + buildRule.executeTarget("testCrCrLfSequence-unix"); + } + + @Test + public void testCrCrLfSequenceDos() throws IOException { + buildRule.executeTarget("testCrCrLfSequence-dos"); + } + + @Test + public void testCrCrLfSequenceMac() throws IOException { + buildRule.executeTarget("testCrCrLfSequence-mac"); + } + + @Test + public void testFixlastDos() throws IOException { + buildRule.executeTarget("testFixlastDos"); + } + + @Test + public void testFixlastFalseMac() throws IOException { + buildRule.executeTarget("testFixlastFalseMac"); + } + + @Test + public void testFixFile() throws Exception { + buildRule.executeTarget("testFixFile"); + } + + @Test + public void testFixFileExclusive() throws Exception { + try { + buildRule.executeTarget("testFixFileExclusive"); + fail(FixCRLF.ERROR_FILE_AND_SRCDIR); + } catch (BuildException ex) { + AntAssert.assertContains(FixCRLF.ERROR_FILE_AND_SRCDIR, ex.getMessage()); + } + } + + /** + * Bugzilla Report 20840 + * + * Will fail with an exception if the parent directories do not + * get created. + */ + @Test + public void testCreateParentDirs() { + buildRule.executeTarget("createParentDirs"); + } + + @Test + public void testPreserveLastModified() { + buildRule.executeTarget("testPreserveLastModified"); + } + + @Test + public void testFilter1() { + buildRule.executeTarget("testFilter1"); + } + + @Test + public void testFilter2() { + buildRule.executeTarget("testFilter2"); + } + + @Test + public void testFilter3() { + buildRule.executeTarget("testFilter3"); + } + + @Test + public void testFilter4() { + buildRule.executeTarget("testFilter4"); + } + + @Test + public void testFilter5() { + buildRule.executeTarget("testFilter5"); + } + + @Test + public void testFilter6() { + buildRule.executeTarget("testFilter6"); + } + + @Test + public void testFilter7() { + buildRule.executeTarget("testFilter7"); + } + + @Test + public void testFilter8() { + buildRule.executeTarget("testFilter8"); + } + + @Test + public void testFilter9() { + buildRule.executeTarget("testFilter9"); + } + + @Test + public void testCannotDoubleEof() { + buildRule.executeTarget("testCannotDoubleEof"); + } + + @Test + public void testTabInLiteralInComment() { + buildRule.executeTarget("testTabInLiteralInComment"); + } + + // not used, but public so theoretically must remain for BC? + @Deprecated + public void assertEqualContent(File expect, File result) + throws AssertionFailedError, IOException { + if (!result.exists()) { + fail("Expected file "+result+" doesn\'t exist"); + } + + InputStream inExpect = null; + InputStream inResult = null; + try { + inExpect = new BufferedInputStream(new FileInputStream(expect)); + inResult = new BufferedInputStream(new FileInputStream(result)); + + int expectedByte = inExpect.read(); + while (expectedByte != -1) { + assertEquals(expectedByte, inResult.read()); + expectedByte = inExpect.read(); + } + assertEquals("End of file", -1, inResult.read()); + } finally { + if (inResult != null) { + inResult.close(); + } + if (inExpect != null) { + inExpect.close(); + } + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java new file mode 100644 index 00000000..fc731f75 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GUnzipTest.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class GUnzipTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/gunzip.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("attribute src invalid"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testRealTest() throws java.io.IOException { + testRealTest("realTest"); + } + + @Test + public void testRealTestWithResource() throws java.io.IOException { + testRealTest("realTestWithResource"); + } + + private void testRealTest(String target) throws java.io.IOException { + buildRule.executeTarget(target); + assertEquals(FileUtilities.getFileContents(buildRule.getProject().resolveFile("../asf-logo.gif")), + FileUtilities.getFileContents(buildRule.getProject().resolveFile("asf-logo.gif"))); + } + + @Test + public void testTestGzipTask() throws java.io.IOException { + testRealTest("testGzipTask"); + } + + @Test + public void testDocumentationClaimsOnCopy() throws java.io.IOException { + testRealTest("testDocumentationClaimsOnCopy"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java new file mode 100644 index 00000000..3e1157d8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GetTest.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + */ +public class GetTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/get.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("src invalid"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test5() { + try { + buildRule.executeTarget("test5"); + fail("dest invalid (or no http-server on local machine"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test6() { + buildRule.executeTarget("test6"); + } + + @Test + public void test7() { + try { + buildRule.executeTarget("test7"); + fail("userAgent may not be null or empty"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testUseTimestamp() { + buildRule.executeTarget("testUseTimestamp"); + } + + @Test + public void testUseTomorrow() { + buildRule.executeTarget("testUseTomorrow"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java new file mode 100644 index 00000000..00ea0638 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/GzipTest.java @@ -0,0 +1,113 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + */ +public class GzipTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/gzip.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException expected: zipfile must not point to a directory"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testGZip(){ + buildRule.executeTarget("realTest"); + String log = buildRule.getLog(); + assertTrue("Expecting message starting with 'Building:' but got '" + + log + "'", log.startsWith("Building:")); + assertTrue("Expecting message ending with 'asf-logo.gif.gz' but got '" + + log + "'", log.endsWith("asf-logo.gif.gz")); + } + + @Test + public void testResource(){ + buildRule.executeTarget("realTestWithResource"); + } + + @Test + public void testDateCheck(){ + buildRule.executeTarget("testDateCheck"); + String log = buildRule.getLog(); + assertTrue( + "Expecting message ending with 'asf-logo.gif.gz is up to date.' but got '" + log + "'", + log.endsWith("asf-logo.gif.gz is up to date.")); + } + + @After + public void tearDown(){ + buildRule.executeTarget("cleanup"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java new file mode 100644 index 00000000..e64d6f8c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ImportTest.java @@ -0,0 +1,174 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Location; +import org.apache.tools.ant.Project; +import org.junit.Assume; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +public class ImportTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Test + public void testSimpleImport() { + buildRule.configureProject("src/etc/testcases/taskdefs/import/import.xml"); + assertContains("Before importIn imported topAfter import", buildRule.getLog()); + } + + @Test + public void testUnnamedNesting() { + buildRule.configureProject("src/etc/testcases/taskdefs/import/unnamedImport.xml", + Project.MSG_WARN); + String log = buildRule.getLog(); + assertTrue("Warnings logged when not expected: " + log, + log.length() == 0); + } + + @Test + public void testSerial() { + buildRule.configureProject("src/etc/testcases/taskdefs/import/subdir/serial.xml"); + assertContains("Unnamed2.xmlUnnamed1.xml", buildRule.getLog()); + assertContains("Expected string was not found in log", + "Skipped already imported file", buildRule.getFullLog()); + } + + // allow this as imported in targets are only tested when a target is run + @Test + public void testImportInTargetNoEffect() { + buildRule.configureProject("src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); + buildRule.executeTarget("no-import"); + assertNull(buildRule.getProject().getProperty("foo")); + assertNull(buildRule.getProject().getReference("baz")); + } + + @Ignore("deactivate this test as imports within targets are not allowed") + @Test + public void notTestImportInTargetWithEffect() { + buildRule.configureProject("src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); + buildRule.executeTarget("do-import"); + assertEquals(buildRule.getProject().getProperty("foo"), "bar"); + assertNotNull(buildRule.getProject().getReference("baz")); + } + + @Test + public void testImportInTargetNotAllowed() { + buildRule.configureProject( + "src/etc/testcases/taskdefs/import/subdir/importintarget.xml"); + try { + buildRule.executeTarget("do-import"); + fail("Build exception should have been thrown as import only allowed in top level task"); + } catch(BuildException ex) { + assertContains( "not a top level task", "import only allowed as a top-level task", ex.getMessage()); + } + } + + @Test + public void testImportInSequential() { + buildRule.configureProject( + "src/etc/testcases/taskdefs/import/subdir/importinsequential.xml"); + buildRule.executeTarget("within-imported"); + assertEquals(buildRule.getProject().getProperty("foo"), "bar"); + assertNotNull(buildRule.getProject().getReference("baz")); + } + + @Test + public void testImportSameTargets() { + try { + buildRule.configureProject( + "src/etc/testcases/taskdefs/import/same_target.xml"); + fail("Expected build exception"); + } catch (BuildException ex) { + assertContains("Message did not contain expected contents", "Duplicate target", ex.getMessage()); + } + } + + @Test + public void testImportError() { + try { + buildRule.configureProject( + "src/etc/testcases/taskdefs/import/import_bad_import.xml"); + fail("Build exception should have been thrown"); + } catch (BuildException ex) { + Location lo = ex.getLocation(); + assertNotNull( + "expected location of build exception to be set", lo); + assertContains( + "expected location to contain calling file", "import_bad_import.xml", lo.getFileName()); + assertContains( + "expected message of ex to contain called file", "bad.xml", ex.getMessage()); + } + } + + @Test + public void testSymlinkedImports() throws Exception { + String ln = "/usr/bin/ln"; + if (!new File(ln).exists()) { + ln = "/bin/ln"; + } + Assume.assumeTrue("Current system does not support Symlinks", new File(ln).exists()); + String symlink = "src/etc/testcases/taskdefs/import/symlinks/d3b"; + File symlinkFile = new File(System.getProperty("root"), symlink); + if (Runtime.getRuntime().exec(new String[] {ln, "-s", "d3a", symlinkFile.getAbsolutePath()}).waitFor() != 0) { + throw new IOException("'" + ln + " -s d3a " + symlink + "' failed"); + } + try { + buildRule.configureProject( + "src/etc/testcases/taskdefs/import/symlinks/d1/p1.xml"); + assertEquals( + buildRule.getProject().getProperty("ant.file.p2"), + new File(System.getProperty("root"), "src/etc/testcases/taskdefs/import/symlinks/d2/p2.xml") + .getAbsolutePath()); + assertEquals( + buildRule.getProject().getProperty("ant.file.p3"), + new File(System.getProperty("root"), "src/etc/testcases/taskdefs/import/symlinks/d3b/p3.xml") + .getAbsolutePath()); + } finally { + symlinkFile.delete(); + } + } + + @Test + public void testTargetFirst() { + buildRule.configureProject("src/etc/testcases/taskdefs/import/importtargetfirst.xml"); + assertContains("Importing targetfirstAfter target firstAfter importing", buildRule.getLog()); + } + + @Test + public void testTargetName() { + buildRule.configureProject("src/etc/testcases/taskdefs/import/c.xml"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/InitializeClassTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/InitializeClassTest.java new file mode 100644 index 00000000..a44303f9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/InitializeClassTest.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Test to see if static initializers are invoked the same way + * when <java> is invoked in forked and unforked modes. + * + */ +public class InitializeClassTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private File f1 = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/forkedout"); + private File f2 = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/unforkedout"); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/initializeclass.xml"); + } + + @Test + public void testAll() throws IOException { + buildRule.executeTarget("forked"); + synchronized (System.out) { + PrintStream ps = System.out; + PrintStream newps = new PrintStream(new FileOutputStream(f2)); + try { + System.setOut(newps); + buildRule.getProject().executeTarget("unforked"); + } finally { + System.setOut(ps); + + newps.close(); + } + } + assertEquals(FileUtilities.getFileContents(f1), FileUtilities.getFileContents(f2)); + } + + @After + public void tearDown() { + f1.delete(); + f2.delete(); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java new file mode 100644 index 00000000..4b6efaa1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/InputTest.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.input.PropertyFileInputHandler; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +public class InputTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private InputStream originalStdIn; + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/input.xml"); + System.getProperties() + .put(PropertyFileInputHandler.FILE_NAME_KEY, + buildRule.getProject().resolveFile("input.properties") + .getAbsolutePath()); + buildRule.getProject().setInputHandler(new PropertyFileInputHandler()); + originalStdIn = System.in; + } + + @After + public void tearDown() { + System.setIn(originalStdIn); + } + + @Test + public void test1() { + buildRule.executeTarget("test1"); + } + + @Test + public void test2() { + buildRule.executeTarget("test2"); + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: invalid input"); + } catch (BuildException ex) { + assertEquals("Found invalid input test for 'All data is going to be deleted from DB continue?'", + ex.getMessage()); + } + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + } + + @Test + public void test6() { + buildRule.executeTarget("test6"); + assertEquals("scott", buildRule.getProject().getProperty("db.user")); + } + + @Test + public void testPropertyFileInlineHandler() { + buildRule.executeTarget("testPropertyFileInlineHandler"); + } + + @Test + public void testDefaultInlineHandler() throws IOException { + stdin(); + buildRule.executeTarget("testDefaultInlineHandler"); + } + + @Test + public void testGreedyInlineHandler() throws IOException { + stdin(); + buildRule.executeTarget("testGreedyInlineHandler"); + } + + @Test + public void testGreedyInlineHandlerClassname() throws IOException { + stdin(); + buildRule.executeTarget("testGreedyInlineHandlerClassname"); + } + + @Test + public void testGreedyInlineHandlerRefid() throws IOException { + stdin(); + buildRule.executeTarget("testGreedyInlineHandlerRefid"); + } + + private void stdin() throws IOException { + System.setIn(new FileInputStream(buildRule.getProject().resolveFile("input.stdin"))); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java new file mode 100644 index 00000000..9b8ff155 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JarTest.java @@ -0,0 +1,375 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.Reader; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.apache.tools.ant.util.FileUtils; +import org.junit.After; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + */ +public class JarTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private static String tempJar = "tmp.jar"; + private static String tempDir = "jartmp/"; + private Reader r1, r2; + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/jar.xml"); + buildRule.executeTarget("setUp"); + } + + @After + public void tearDown() { + if (r1 != null) { + try { + r1.close(); + } catch (IOException e) { + } + } + if (r2 != null) { + try { + r2.close(); + } catch (IOException e) { + } + } + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: manifest file does not exist"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: Unrecognized whenempty attribute: format C: /y"); + } catch (BuildException ex) { + //TODO assert value + } + } + + private File getOutputDir() { + return new File(buildRule.getProject().getProperty("output")); + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + File jarFile = new File(getOutputDir(), tempJar); + + assertTrue(jarFile.exists()); + } + + @Test + public void testNoRecreateWithoutUpdate() { + testNoRecreate("test4"); + } + + @Test + public void testNoRecreateWithUpdate() { + testNoRecreate("testNoRecreateWithUpdate"); + } + + private void testNoRecreate(String secondTarget) { + buildRule.executeTarget("test4"); + File jarFile = new File(getOutputDir(), tempJar); + + // move the modified date back a couple of seconds rather than delay the test on each run + Assume.assumeTrue(jarFile.setLastModified(jarFile.lastModified() + - (FileUtils.getFileUtils().getFileTimestampGranularity() * 3))); + long jarModifiedDate = jarFile.lastModified(); + + buildRule.executeTarget(secondTarget); + assertEquals("jar has not been recreated in " + secondTarget, + jarModifiedDate, jarFile.lastModified()); + } + + @Test + public void testRecreateWithoutUpdateAdditionalFiles() { + testRecreate("test4", "testRecreateWithoutUpdateAdditionalFiles"); + } + + @Test + public void testRecreateWithUpdateAdditionalFiles() { + testRecreate("test4", "testRecreateWithUpdateAdditionalFiles"); + } + + @Test + public void testRecreateWithoutUpdateNewerFile() { + testRecreate("testRecreateNewerFileSetup", + "testRecreateWithoutUpdateNewerFile"); + } + + @Test + public void testRecreateWithUpdateNewerFile() { + testRecreate("testRecreateNewerFileSetup", + "testRecreateWithUpdateNewerFile"); + } + + private void testRecreate(String firstTarget, String secondTarget) { + //Move the modified date on all input back a couple of seconds rather then delay the test to achieve a similar effect + FileUtilities.rollbackTimetamps(buildRule.getProject().getBaseDir(), 5); + + buildRule.executeTarget(firstTarget); + File jarFile = new File(getOutputDir(), tempJar); + + //Move the modified date back a couple of seconds rather then delay the test to achieve a similar effect + FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5); + + long jarModifiedDate = jarFile.lastModified(); + buildRule.executeTarget(secondTarget); + jarFile = new File(getOutputDir(), tempJar); + assertTrue("jar has been recreated in " + secondTarget, + jarModifiedDate < jarFile.lastModified()); + } + + @Test + public void testManifestStaysIntact() + throws IOException, ManifestException { + buildRule.executeTarget("testManifestStaysIntact"); + + r1 = new FileReader(new File(getOutputDir(), + tempDir + "manifest")); + r2 = new FileReader(new File(getOutputDir(), + tempDir + "META-INF/MANIFEST.MF")); + + Manifest mf1 = new Manifest(r1); + Manifest mf2 = new Manifest(r2); + assertEquals(mf1, mf2); + } + + @Test + public void testNoRecreateBasedirExcludesWithUpdate() { + testNoRecreate("testNoRecreateBasedirExcludesWithUpdate"); + } + + @Test + public void testNoRecreateBasedirExcludesWithoutUpdate() { + testNoRecreate("testNoRecreateBasedirExcludesWithoutUpdate"); + } + + @Test + public void testNoRecreateZipfilesetExcludesWithUpdate() { + testNoRecreate("testNoRecreateZipfilesetExcludesWithUpdate"); + } + + @Test + public void testNoRecreateZipfilesetExcludesWithoutUpdate() { + testNoRecreate("testNoRecreateZipfilesetExcludesWithoutUpdate"); + } + + @Test + public void testRecreateZipfilesetWithoutUpdateAdditionalFiles() { + testRecreate("test4", + "testRecreateZipfilesetWithoutUpdateAdditionalFiles"); + } + + @Test + public void testRecreateZipfilesetWithUpdateAdditionalFiles() { + testRecreate("test4", + "testRecreateZipfilesetWithUpdateAdditionalFiles"); + } + + @Test + public void testRecreateZipfilesetWithoutUpdateNewerFile() { + testRecreate("testRecreateNewerFileSetup", + "testRecreateZipfilesetWithoutUpdateNewerFile"); + } + + @Test + public void testRecreateZipfilesetWithUpdateNewerFile() { + testRecreate("testRecreateNewerFileSetup", + "testRecreateZipfilesetWithUpdateNewerFile"); + } + + @Test + public void testCreateWithEmptyFileset() { + buildRule.executeTarget("testCreateWithEmptyFilesetSetUp"); + buildRule.executeTarget("testCreateWithEmptyFileset"); + buildRule.executeTarget("testCreateWithEmptyFileset"); + } + + @Test + public void testUpdateIfOnlyManifestHasChanged() { + buildRule.executeTarget("testUpdateIfOnlyManifestHasChanged"); + File jarXml = new File(getOutputDir(), tempDir + "jar.xml"); + assertTrue(jarXml.exists()); + } + + // bugzilla report 10262 + @Test + public void testNoDuplicateIndex() throws IOException { + ZipFile archive = null; + try { + buildRule.executeTarget("testIndexTests"); + archive = new ZipFile(new File(getOutputDir(), tempJar)); + Enumeration e = archive.entries(); + int numberOfIndexLists = 0; + while (e.hasMoreElements()) { + ZipEntry ze = (ZipEntry) e.nextElement(); + if (ze.getName().equals("META-INF/INDEX.LIST")) { + numberOfIndexLists++; + } + } + assertEquals(1, numberOfIndexLists); + } finally { + if (archive != null) { + archive.close(); + } + } + } + + // bugzilla report 16972 + @Test + public void testRootFilesInIndex() throws IOException { + ZipFile archive = null; + try { + buildRule.executeTarget("testIndexTests"); + archive = new ZipFile(new File(getOutputDir(), tempJar)); + ZipEntry ze = archive.getEntry("META-INF/INDEX.LIST"); + InputStream is = archive.getInputStream(ze); + BufferedReader r = new BufferedReader(new InputStreamReader(is, + "UTF8")); + boolean foundSub = false; + boolean foundSubFoo = false; + boolean foundFoo = false; + + String line = r.readLine(); + while (line != null) { + if (line.equals("foo")) { + foundFoo = true; + } else if (line.equals("sub")) { + foundSub = true; + } else if (line.equals("sub/foo")) { + foundSubFoo = true; + } + line = r.readLine(); + } + + assertTrue(foundSub); + assertTrue(!foundSubFoo); + assertTrue(foundFoo); + } finally { + if (archive != null) { + archive.close(); + } + } + } + @Test + public void testManifestOnlyJar() { + + buildRule.executeTarget("testManifestOnlyJar"); + assertContains("Building MANIFEST-only jar: ", buildRule.getLog()); + File manifestFile = new File(getOutputDir(), tempDir + "META-INF" + File.separator + "MANIFEST.MF"); + assertTrue(manifestFile.exists()); + } + + @Test + public void testIndexJarsPlusJarMarker() { + buildRule.executeTarget("testIndexJarsPlusJarMarker"); + } + + @Test + public void testNoVersionInfoFail() { + try { + buildRule.executeTarget("testNoVersionInfoFail"); + fail("BuildException expected: Manifest Implemention information missing."); + } catch (BuildException ex) { + assertContains("No Implementation-Title set.", ex.getMessage()); + } + } + + @Test + public void testNoVersionInfoIgnore() { + buildRule.executeTarget("testNoVersionInfoIgnore"); + assertTrue(buildRule.getFullLog().indexOf("No Implementation-Title set.") > -1 ); + assertTrue(buildRule.getFullLog().indexOf("No Implementation-Version set.") > -1 ); + assertTrue(buildRule.getFullLog().indexOf("No Implementation-Vendor set.") > -1 ); + } + + @Test + public void testNoVersionInfoWarn() { + buildRule.executeTarget("testNoVersionInfoWarn"); + assertTrue(buildRule.getLog().indexOf("No Implementation-Title set.") > -1 ); + assertTrue(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); + assertTrue(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); + } + + @Test + public void testNoVersionInfoNoStrict() { + buildRule.executeTarget("testNoVersionInfoNoStrict"); + assertFalse(buildRule.getLog().indexOf("No Implementation-Title set.") > -1 ); + assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); + assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); + } + + @Test + public void testHasVersionInfo() { + buildRule.executeTarget("testHasVersionInfo"); + assertFalse(buildRule.getLog().indexOf("No Implementation-Title set.") > -1 ); + assertFalse(buildRule.getLog().indexOf("No Implementation-Version set.") > -1 ); + assertFalse(buildRule.getLog().indexOf("No Implementation-Vendor set.") > -1 ); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java new file mode 100644 index 00000000..d54b8f28 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavaTest.java @@ -0,0 +1,475 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.PipedInputStream; +import java.io.PipedOutputStream; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.input.DefaultInputHandler; +import org.apache.tools.ant.util.FileUtils; +import org.apache.tools.ant.util.TeeOutputStream; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.internal.AssumptionViolatedException; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * stress out java task + * */ +public class JavaTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private static final int TIME_TO_WAIT = 1; + // wait 1 second extra to allow for java to start ... + // this time was OK on a Win NT machine and on nagoya + private static final int SECURITY_MARGIN = 2000; + + /** Utilities used for file operations */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + private boolean runFatalTests=false; + + + /** + * configure the project. + * if the property junit.run.fatal.tests is set we run + * the fatal tests + */ + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/java.xml"); + buildRule.executeTarget("setUp"); + + //final String propname="tests-classpath.value"; + //String testClasspath=System.getProperty(propname); + //System.out.println("Test cp="+testClasspath); + String runFatal=System.getProperty("junit.run.fatal.tests"); + if(runFatal!=null) + runFatalTests=true; + } + + @Test + public void testNoJarNoClassname(){ + try { + buildRule.executeTarget("testNoJarNoClassname"); + fail("Build exception should have been thrown - parameter validation"); + } catch (BuildException ex) { + assertContains("Classname must not be null.", ex.getMessage()); + } + } + + @Test + public void testJarNoFork() { + try { + buildRule.executeTarget("testJarNoFork"); + fail("Build exception should have been thrown - parameter validation"); + } catch (BuildException ex) { + assertContains("Cannot execute a jar in non-forked mode. Please set fork='true'. ", ex.getMessage()); + } + } + + @Test + public void testJarAndClassName() { + try { + buildRule.executeTarget("testJarAndClassName"); + fail("Build exception should have been thrown - both classname and JAR are not allowed"); + } catch (BuildException ex) { + assertEquals("Cannot use 'jar' and 'classname' attributes in same command", ex.getMessage()); + } + } + + @Test + public void testClassnameAndJar() { + try { + buildRule.executeTarget("testClassnameAndJar"); + fail("Build exception should have been thrown - both classname and JAR are not allowed"); + } catch (BuildException ex) { + assertEquals("Cannot use 'jar' and 'classname' attributes in same command.", ex.getMessage()); + } + } + + @Test + public void testRun() { + buildRule.executeTarget("testRun"); + } + + + + /** this test fails but we ignore the return value; + * we verify that failure only matters when failonerror is set + */ + @Test + public void testRunFail() { + Assume.assumeTrue("Fatal tests have not been set to run", runFatalTests); + buildRule.executeTarget("testRunFail"); + } + + @Test + public void testRunFailFoe() { + Assume.assumeTrue("Fatal tests have not been set to run", runFatalTests); + try { + buildRule.executeTarget("testRunFailFoe"); + fail("Build exception should have been thrown - " + "java failures being propagated"); + } catch (BuildException ex) { + assertContains("Java returned:", ex.getMessage()); + } + } + + @Test + public void testRunFailFoeFork() { + try { + buildRule.executeTarget("testRunFailFoeFork"); + fail("Build exception should have been thrown - " + "java failures being propagated"); + } catch (BuildException ex) { + assertContains("Java returned:", ex.getMessage()); + } + } + + @Test + public void testExcepting() { + buildRule.executeTarget("testExcepting"); + assertContains("Exception raised inside called program", buildRule.getLog()); + } + + @Test + public void testExceptingFork() { + buildRule.executeTarget("testExceptingFork"); + assertContains("Java Result:", buildRule.getLog()); + } + + @Test + public void testExceptingFoe() { + try { + buildRule.executeTarget("testExceptingFoe"); + fail("Build exception should have been thrown - " + "passes exception through"); + } catch (BuildException ex) { + assertContains("Exception raised inside called program", ex.getMessage()); + } + } + + @Test + public void testExceptingFoeFork() { + try { + buildRule.executeTarget("testExceptingFoeFork"); + fail("Build exception should have been thrown - " + "exceptions turned into error codes"); + } catch (BuildException ex) { + assertContains("Java returned:", ex.getMessage()); + } + } + + @Test + public void testResultPropertyZero() { + buildRule.executeTarget("testResultPropertyZero"); + assertEquals("0", buildRule.getProject().getProperty("exitcode")); + } + + @Test + public void testResultPropertyNonZero() { + buildRule.executeTarget("testResultPropertyNonZero"); + assertEquals("2", buildRule.getProject().getProperty("exitcode")); + } + + @Test + public void testResultPropertyZeroNoFork() { + buildRule.executeTarget("testResultPropertyZeroNoFork"); + assertEquals("0", buildRule.getProject().getProperty("exitcode")); + } + + @Test + public void testResultPropertyNonZeroNoFork() { + buildRule.executeTarget("testResultPropertyNonZeroNoFork"); + assertEquals("-1", buildRule.getProject().getProperty("exitcode")); + } + + @Test + public void testRunFailWithFailOnError() { + try { + buildRule.executeTarget("testRunFailWithFailOnError"); + fail("Build exception should have been thrown - " + "non zero return code"); + } catch (BuildException ex) { + assertContains("Java returned:", ex.getMessage()); + } + } + + @Test + public void testRunSuccessWithFailOnError() { + buildRule.executeTarget("testRunSuccessWithFailOnError"); + } + + @Test + public void testSpawn() throws InterruptedException { + File logFile = FILE_UTILS.createTempFile("spawn", "log", + new File(buildRule.getProject().getProperty("output")), false, false); + // this is guaranteed by FileUtils#createTempFile + assertTrue("log file not existing", !logFile.exists()); + buildRule.getProject().setProperty("logFile", logFile.getAbsolutePath()); + buildRule.getProject().setProperty("timeToWait", Long.toString(TIME_TO_WAIT)); + buildRule.getProject().executeTarget("testSpawn"); + + Thread.sleep(TIME_TO_WAIT * 1000 + SECURITY_MARGIN); + + + // let's be nice with the next generation of developers + if (!logFile.exists()) { + System.out.println("suggestion: increase the constant" + + " SECURITY_MARGIN to give more time for java to start."); + } + assertTrue("log file exists", logFile.exists()); + } + + @Test + public void testRedirect1() { + buildRule.executeTarget("redirect1"); + } + + @Test + public void testRedirect2() { + buildRule.executeTarget("redirect2"); + } + + @Test + public void testRedirect3() { + buildRule.executeTarget("redirect3"); + } + + @Test + public void testRedirector1() { + buildRule.executeTarget("redirector1"); + } + + @Test + public void testRedirector2() { + buildRule.executeTarget("redirector2"); + } + + @Test + public void testReleasedInput() throws Exception { + PipedOutputStream out = new PipedOutputStream(); + final PipedInputStream in = new PipedInputStream(out); + buildRule.getProject().setInputHandler(new DefaultInputHandler() { + protected InputStream getInputStream() { + return in; + } + }); + buildRule.getProject().setDefaultInputStream(in); + + Java java = new Java(); + java.setProject(buildRule.getProject()); + java.setClassname("org.apache.tools.ant.Main"); + java.setArgs("-version"); + java.setFork(true); + // note: due to the missing classpath it will fail, but the input stream + // reader will be read + java.execute(); + + Thread inputThread = new Thread(new Runnable() { + public void run() { + Input input = new Input(); + input.setProject(buildRule.getProject()); + input.setAddproperty("input.value"); + input.execute(); + } + }); + inputThread.start(); + + // wait a little bit for the task to wait for input + Thread.sleep(100); + + // write some stuff in the input stream to be catched by the input task + out.write("foo\n".getBytes()); + out.flush(); + try { + out.write("bar\n".getBytes()); + out.flush(); + } catch (IOException x) { + // "Pipe closed" on XP; ignore? + } + + inputThread.join(2000); + + assertEquals("foo", buildRule.getProject().getProperty("input.value")); + } + + @Test + public void testFlushedInput() throws Exception { + final PipedOutputStream out = new PipedOutputStream(); + final PipedInputStream in = new PipedInputStream(out); + buildRule.getProject().setInputHandler(new DefaultInputHandler() { + protected InputStream getInputStream() { + return in; + } + }); + buildRule.getProject().setDefaultInputStream(in); + + final boolean[] timeout = new boolean[1]; + timeout[0] = false; + + Thread writingThread = new Thread(new Runnable() { + public void run() { + try { + // wait a little bit to have the target executed + Thread.sleep(500); + } catch (InterruptedException e) { + throw new AssumptionViolatedException("Thread interrupted", e); + } + try { + out.write("foo-FlushedInput\n".getBytes()); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + }); + writingThread.setDaemon(true); + + writingThread.start(); + buildRule.executeTarget("flushedInput"); + } + + /** + * entry point class with no dependencies other + * than normal JRE runtime + */ + public static class EntryPoint { + + /** + * this entry point is used by the java.xml tests to + * generate failure strings to handle + * argv[0] = exit code (optional) + * argv[1] = string to print to System.out (optional) + * argv[1] = string to print to System.err (optional) + */ + public static void main(String[] argv) { + int exitCode=0; + if(argv.length>0) { + try { + exitCode=Integer.parseInt(argv[0]); + } catch(NumberFormatException nfe) { + exitCode=-1; + } + } + if(argv.length>1) { + System.out.println(argv[1]); + } + if(argv.length>2) { + System.err.println(argv[2]); + } + if(exitCode!=0) { + System.exit(exitCode); + } + } + } + + /** + * entry point class with no dependencies other + * than normal JRE runtime + */ + public static class ExceptingEntryPoint { + + /** + * throw a run time exception which does not need + * to be in the signature of the entry point + */ + public static void main(String[] argv) { + throw new NullPointerException("Exception raised inside called program"); + } + } + /** + * test class for spawn + */ + public static class SpawnEntryPoint { + public static void main(String [] argv) throws InterruptedException { + int sleepTime = 10; + String logFile = "spawn.log"; + if (argv.length >= 1) { + sleepTime = Integer.parseInt(argv[0]); + } + if (argv.length >= 2) + { + logFile = argv[1]; + } + OutputStreamWriter out = null; + Thread.sleep(sleepTime * 1000); + + try { + File dest = new File(logFile); + FileOutputStream fos = new FileOutputStream(dest); + out = new OutputStreamWriter(fos); + out.write("bye bye\n"); + } catch (Exception ex) {} + finally { + try {out.close();} catch (IOException ioe) {}} + + } + } + + /** + * entry point class to pipe System.in to the specified stream: + * "out", "err", or "both". If none specified, swallow the input. + */ + public static class PipeEntryPoint { + + /** + * pipe input to specified output + */ + public static void main(String[] args) throws InterruptedException { + OutputStream os = null; + if (args.length > 0) { + if ("out".equalsIgnoreCase(args[0])) { + os = System.out; + } else if ("err".equalsIgnoreCase(args[0])) { + os = System.err; + } else if ("both".equalsIgnoreCase(args[0])) { + os = new TeeOutputStream(System.out, System.err); + } + } + if (os != null) { + Thread t = new Thread(new StreamPumper(System.in, os, true)); + t.setName("PipeEntryPoint " + args[0]); + t.start(); + t.join(); + } + } + } + + public static class ReadPoint { + public static void main(String[] args) throws IOException { + String line = new BufferedReader(new InputStreamReader(System.in)).readLine(); + System.out.println(line); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java new file mode 100644 index 00000000..12ceea28 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavacTest.java @@ -0,0 +1,247 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter; +import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory; +import org.apache.tools.ant.taskdefs.compilers.Javac13; +import org.apache.tools.ant.taskdefs.compilers.JavacExternal; + +import org.junit.Before; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +/** + * Testcase for <javac>. + * + */ +public class JavacTest { + + private Project project; + private Javac javac; + + @Before + public void setUp() { + project = new Project(); + project.init(); + javac = new Javac(); + javac.setProject(project); + } + + /** + * Test setting the name of the javac executable. + */ + @Test + public void testForkedExecutableName() { + assertNull("no fork means no executable", javac.getJavacExecutable()); + + project.setProperty("build.compiler", "modern"); + assertNull("no fork means no executable", javac.getJavacExecutable()); + + javac.setFork(true); + assertNotNull("normal fork", javac.getJavacExecutable()); + assertContains("name should contain \"javac\"", "javac", + javac.getJavacExecutable()); + + project.setProperty("build.compiler", "extJavac"); + javac.setFork(false); + assertNotNull("fork via property", javac.getJavacExecutable()); + assertContains("name should contain \"javac\"", "javac", javac.getJavacExecutable()); + + project.setProperty("build.compiler", "whatever"); + assertNull("no fork and not extJavac means no executable", + javac.getJavacExecutable()); + + String myJavac = "Slartibartfast"; + javac.setFork(true); + javac.setExecutable(myJavac); + assertEquals(myJavac, javac.getJavacExecutable()); + } + + /** + * Test nested compiler args. + */ + @Test + public void testCompilerArg() { + String[] args = javac.getCurrentCompilerArgs(); + assertNotNull(args); + assertEquals("no args", 0, args.length); + + Javac.ImplementationSpecificArgument arg = javac.createCompilerArg(); + String ford = "Ford"; + String prefect = "Prefect"; + String testArg = ford + " " + prefect; + arg.setValue(testArg); + args = javac.getCurrentCompilerArgs(); + assertEquals("unconditional single arg", 1, args.length); + assertEquals(testArg, args[0]); + + arg.setCompiler("jikes"); + args = javac.getCurrentCompilerArgs(); + assertNotNull(args); + assertEquals("implementation is jikes but build.compiler is null", + 0, args.length); + + project.setProperty("build.compiler", "jvc"); + args = javac.getCurrentCompilerArgs(); + assertNotNull(args); + assertEquals("implementation is jikes but build.compiler is jvc", + 0, args.length); + + project.setProperty("build.compiler", "jikes"); + args = javac.getCurrentCompilerArgs(); + assertEquals("both are jikes", 1, args.length); + assertEquals(testArg, args[0]); + + arg.setLine(testArg); + args = javac.getCurrentCompilerArgs(); + assertEquals("split at space", 2, args.length); + assertEquals(ford, args[0]); + assertEquals(prefect, args[1]); + } + + /** + * Test nested compiler args in the fork="true" and + * implementation="extJavac" case. + */ + @Test + public void testCompilerArgForForkAndExtJavac() { + Javac.ImplementationSpecificArgument arg = javac.createCompilerArg(); + String ford = "Ford"; + String prefect = "Prefect"; + String testArg = ford + " " + prefect; + arg.setValue(testArg); + arg.setCompiler("extJavac"); + javac.setFork(true); + String[] args = javac.getCurrentCompilerArgs(); + assertEquals("both are forked javac", 1, args.length); + assertEquals(testArg, args[0]); + } + + /** + * Test compiler attribute. + */ + @Test + public void testCompilerAttribute() { + // check defaults + String compiler = javac.getCompiler(); + assertNotNull(compiler); + if (System.getProperty("build.compiler") != null) { + assertEquals(System.getProperty("build.compiler"), + compiler); + } else { + assertTrue("default value", + "javac1.1".equals(compiler) + || "javac1.2".equals(compiler) + || "javac1.3".equals(compiler) + || "javac1.4".equals(compiler) + || "javac1.5".equals(compiler) + || "classic".equals(compiler)); + } + + javac.setFork(true); + assertNotNull(javac.getCompiler()); + assertEquals("extJavac", javac.getCompiler()); + assertEquals(compiler, javac.getCompilerVersion()); + + // check build.compiler provides defaults + javac = new Javac(); + javac.setProject(project); + // setUserProperty to override system properties + project.setUserProperty("build.compiler", "jikes"); + compiler = javac.getCompiler(); + assertNotNull(compiler); + assertEquals("jikes", compiler); + + javac.setFork(true); + compiler = javac.getCompiler(); + assertNotNull(compiler); + assertEquals("jikes", compiler); + + // check attribute overrides build.compiler + javac.setFork(false); + javac.setCompiler("jvc"); + compiler = javac.getCompiler(); + assertNotNull(compiler); + assertEquals("jvc", compiler); + + javac.setFork(true); + compiler = javac.getCompiler(); + assertNotNull(compiler); + assertEquals("jvc", compiler); + } + + @Test + public void testCompilerAdapter() { + javac.setCompiler("javac1.4"); + + javac.setDepend(true); + CompilerAdapter adapter = + CompilerAdapterFactory.getCompiler(javac.getCompiler(), javac); + + assertTrue(adapter instanceof Javac13); + + javac.setFork(true); + adapter = + CompilerAdapterFactory.getCompiler(javac.getCompiler(), javac); + assertTrue(adapter instanceof JavacExternal); + } + + @Test + public void testSourceNoDefault() { + assertNull(javac.getSource()); + } + + @Test + public void testSourceWithDefault() { + project.setNewProperty("ant.build.javac.source", "1.4"); + assertEquals("1.4", javac.getSource()); + } + + @Test + public void testSourceOverridesDefault() { + project.setNewProperty("ant.build.javac.source", "1.4"); + javac.setSource("1.5"); + assertEquals("1.5", javac.getSource()); + } + + @Test + public void testTargetNoDefault() { + assertNull(javac.getTarget()); + } + + @Test + public void testTargetWithDefault() { + project.setNewProperty("ant.build.javac.target", "1.4"); + assertEquals("1.4", javac.getTarget()); + } + + @Test + public void testTargetOverridesDefault() { + project.setNewProperty("ant.build.javac.target", "1.4"); + javac.setTarget("1.5"); + assertEquals("1.5", javac.getTarget()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavadocTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavadocTest.java new file mode 100644 index 00000000..f7a287d5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/JavadocTest.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class JavadocTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private static final String BUILD_PATH = "src/etc/testcases/taskdefs/javadoc/"; + private static final String BUILD_FILENAME = "javadoc.xml"; + private static final String BUILD_FILE = BUILD_PATH + BUILD_FILENAME; + + @Before + public void setUp() { + buildRule.configureProject(BUILD_FILE); + } + + // PR 38370 + @Test + public void testDirsetPath() { + buildRule.executeTarget("dirsetPath"); + } + + // PR 38370 + @Test + public void testDirsetPathWithoutPackagenames() { + buildRule.executeTarget("dirsetPathWithoutPackagenames"); + } + + // PR 38370 + @Test + public void testNestedDirsetPath() { + buildRule.executeTarget("nestedDirsetPath"); + } + + // PR 38370 + @Test + public void testFilesetPath() { + buildRule.executeTarget("filesetPath"); + } + + // PR 38370 + @Test + public void testNestedFilesetPath() { + buildRule.executeTarget("nestedFilesetPath"); + } + + // PR 38370 + @Test + public void testFilelistPath() { + buildRule.executeTarget("filelistPath"); + } + + // PR 38370 + @Test + public void testNestedFilelistPath() { + buildRule.executeTarget("nestedFilelistPath"); + } + + // PR 38370 + @Test + public void testPathelementPath() { + buildRule.executeTarget("pathelementPath"); + } + + // PR 38370 + @Test + public void testPathelementLocationPath() { + buildRule.executeTarget("pathelementLocationPath"); + } + + // PR 38370 + @Test + public void testNestedSource() { + buildRule.executeTarget("nestedSource"); + } + + // PR 38370 + @Test + public void testNestedFilesetRef() { + buildRule.executeTarget("nestedFilesetRef"); + } + + // PR 38370 + @Test + public void testNestedFilesetRefInPath() { + buildRule.executeTarget("nestedFilesetRefInPath"); + } + + @Test + public void testNestedFilesetNoPatterns() { + buildRule.executeTarget("nestedFilesetNoPatterns"); + } + + @Test + public void testDoublyNestedFileset() { + buildRule.executeTarget("doublyNestedFileset"); + } + + @Test + public void testDoublyNestedFilesetNoPatterns() { + buildRule.executeTarget("doublyNestedFilesetNoPatterns"); + } + + @Test + public void testNonJavaIncludes() { // #41264 + buildRule.executeTarget("nonJavaIncludes"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java new file mode 100644 index 00000000..fd8c3281 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/LoadFileTest.java @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +/** + * Test the load file task + */ +public class LoadFileTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/loadfile.xml"); + } + + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + + /** + * A unit test for JUnit + */ + @Test + public void testNoSourcefileDefined() { + try { + buildRule.executeTarget("testNoSourcefileDefined"); + fail("BuildException expected: source file not defined"); + } catch (BuildException ex) { + //TODO assert value + } + } + + + /** + * A unit test for JUnit + */ + @Test + public void testNoPropertyDefined() { + try { + buildRule.executeTarget("testNoPropertyDefined"); + fail("BuildException expected: output property not defined"); + } catch (BuildException ex) { + //TODO assert value + } + } + + + /** + * A unit test for JUnit + */ + @Test + public void testNoSourcefilefound() { + try { + buildRule.executeTarget("testNoSourcefilefound"); + fail("BuildException expected: File not found"); + } catch (BuildException ex) { + assertContains(" doesn't exist", ex.getMessage()); + } + } + + /** + * A unit test for JUnit + */ + @Test + public void testFailOnError() + throws BuildException { + buildRule.executeTarget("testFailOnError"); + assertNull(buildRule.getProject().getProperty("testFailOnError")); + } + + + /** + * A unit test for JUnit + */ + @Test + public void testLoadAFile() + throws BuildException { + buildRule.executeTarget("testLoadAFile"); + if(buildRule.getProject().getProperty("testLoadAFile").indexOf("eh?")<0) { + fail("property is not all in the file"); + } + } + + + /** + * A unit test for JUnit + */ + @Test + public void testLoadAFileEnc() + throws BuildException { + buildRule.executeTarget("testLoadAFileEnc"); + assertNotNull("file load files", buildRule.getProject().getProperty("testLoadAFileEnc")); + } + + /** + * A unit test for JUnit + */ + @Test + public void testEvalProps() + throws BuildException { + buildRule.executeTarget("testEvalProps"); + if(buildRule.getProject().getProperty("testEvalProps").indexOf("rain")<0) { + fail("property eval broken"); + } + } + + /** + * Test FilterChain and FilterReaders + */ + @Test + public void testFilterChain() + throws BuildException { + buildRule.executeTarget("testFilterChain"); + if(buildRule.getProject().getProperty("testFilterChain").indexOf("World!")<0) { + fail("Filter Chain broken"); + } + } + + /** + * Test StripJavaComments filterreader functionality. + */ + @Test + public final void testStripJavaComments() + throws BuildException { + buildRule.executeTarget("testStripJavaComments"); + final String expected = buildRule.getProject().getProperty("expected"); + final String generated = buildRule.getProject().getProperty("testStripJavaComments"); + assertEquals(expected, generated); + } + + @Test + public void testOneLine() { + buildRule.executeTarget("testOneLine"); + assertEquals("1,2,3,4", buildRule.getProject().getProperty("testOneLine")); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MacroDefTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MacroDefTest.java new file mode 100644 index 00000000..18b9786b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MacroDefTest.java @@ -0,0 +1,206 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + */ +public class MacroDefTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/macrodef.xml"); + } + + @Test + public void testSimple() { + buildRule.executeTarget("simple"); + assertEquals("Hello World", buildRule.getLog()); + } + + @Test + public void testText() { + buildRule.executeTarget("text"); + assertEquals("Inner Text", buildRule.getLog()); + } + + @Test + public void testDuplicateAttribute() { + try { + buildRule.executeTarget("duplicate.attribute"); + fail("BuildException expected: the attribute text has already been specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testDuplicateElement() { + try { + buildRule.executeTarget("duplicate.element"); + fail("BuildException expected: the element text has already been specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testUri() { + buildRule.executeTarget("uri"); + assertEquals("Hello World", buildRule.getLog()); + } + + @Test + public void testNested() { + buildRule.executeTarget("nested"); + assertEquals("A nested element", buildRule.getLog()); + } + + @Test + public void testDouble() { + buildRule.executeTarget("double"); + assertEquals("@{prop} is 'property', value of ${property} is 'A property value'", buildRule.getLog()); + } + + @Test + public void testIgnoreCase() { + buildRule.executeTarget("ignorecase"); + assertEquals("a is ab is b", buildRule.getLog()); + } + + @Test + public void testIgnoreElementCase() { + buildRule.executeTarget("ignore-element-case"); + assertEquals("nested elementnested element", buildRule.getLog()); + } + + @Test + public void testTextElement() { + buildRule.executeTarget("textelement"); + assertContains("Hello world", buildRule.getLog()); + } + + @Test + public void testTextTrim() { + buildRule.executeTarget("text.trim"); + assertContains("[Hello world]", buildRule.getLog()); + } + + @Test + public void testDuplicateTextName() { + try { + buildRule.executeTarget("duplicatetextname"); + fail("BuildException expected: the name \"text\" is already used as an attribute"); + } catch (BuildException ex) { + //TODO assert value + } + } + @Test + public void testDuplicateTextName2() { + try { + buildRule.executeTarget("duplicatetextname2"); + fail("BuildException expected: the attribute name \"text\" has already been used by the text element"); + } catch (BuildException ex) { + //TODO assert value + } + } + @Test + public void testEscape() { + buildRule.executeTarget("escape"); + assertEquals("a@b or a@b is avalue@bvalue", buildRule.getLog()); + } + @Test + public void testAttributeDescription() { + buildRule.executeTarget("attribute.description"); + assertEquals("description is hello world", buildRule.getLog()); + } + @Test + public void testOverrideDefault() { + buildRule.executeTarget("override.default"); + assertEquals("value is new", buildRule.getLog()); + } + @Test + public void testImplicit() { + buildRule.executeTarget("implicit"); + assertEquals("Before implicitIn implicitAfter implicit", buildRule.getLog()); + } + @Test + public void testImplicitNotOptional() { + try { + buildRule.executeTarget("implicit.notoptional"); + fail("BuildException expected: Missing nested elements for implicit element implicit"); + } catch (BuildException ex) { + assertEquals("Missing nested elements for implicit element implicit", ex.getMessage()); + } + } + @Test + public void testImplicitOptional() { + buildRule.executeTarget("implicit.optional"); + assertEquals("Before implicitAfter implicit", buildRule.getLog()); + } + @Test + public void testImplicitExplicit() { + try { + buildRule.executeTarget("implicit.explicit"); + fail("BuildException expected: Only one element allowed when using implicit elements"); + } catch (BuildException ex) { + assertEquals("Only one element allowed when using implicit elements", ex.getMessage()); + } + } + + @Test + public void testBackTraceOff() { + try { + buildRule.executeTarget("backtraceoff"); + } catch (BuildException ex) { + if (ex.getMessage().indexOf("following error occurred") != -1) { + fail("error message contained backtrace - " + ex.getMessage()); + } + } + } + + @Test + public void testBackTrace() { + try { + buildRule.executeTarget("backtraceon"); + fail("BuildException expected: Checking if a back trace is created"); + } catch (BuildException ex) { + assertContains("following error occurred", ex.getMessage()); + } + } + + @Test + public void testTopLevelText() { + buildRule.executeTarget("top-level-text"); + assertContains("Hello World", buildRule.getLog()); + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java new file mode 100644 index 00000000..8c2762a7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MakeUrlTest.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.InputStream; +import java.io.IOException; +import java.net.URL; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + + +public class MakeUrlTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/makeurl.xml"); + } + + @Test + public void testEmpty() { + try { + buildRule.executeTarget("testEmpty"); + fail("BuildException expected: missing property"); + } catch (BuildException ex) { + assertContains("property", ex.getMessage()); + } + } + + @Test + public void testNoProperty() { + try { + buildRule.executeTarget("testNoProperty"); + fail("BuildException expected: missing property"); + } catch (BuildException ex) { + assertContains("property", ex.getMessage()); + } + } + + @Test + public void testNoFile() { + try { + buildRule.executeTarget("testNoFile"); + fail("BuildException expected: missing file"); + } catch (BuildException ex) { + assertContains("file", ex.getMessage()); + } + } + + @Test + public void testValidation() { + try { + buildRule.executeTarget("testValidation"); + fail("BuildException expected: " + MakeUrl.ERROR_MISSING_FILE); + } catch (BuildException ex) { + assertContains("file", ex.getMessage()); + } + } + + @Test + public void testWorks() { + buildRule.executeTarget("testWorks"); + assertPropertyContains("testWorks", "file:"); + assertPropertyContains("testWorks", "/foo"); + } + + @Test + public void testIllegalChars() { + buildRule.executeTarget("testIllegalChars"); + assertPropertyContains("testIllegalChars", "file:"); + assertPropertyContains("testIllegalChars", "fo%20o%25"); + } + + /** + * test that we can round trip by opening a url that exists + * + * @throws IOException + */ + @Test + public void testRoundTrip() throws IOException { + buildRule.executeTarget("testRoundTrip"); + assertPropertyContains("testRoundTrip", "file:"); + String property = getProperty("testRoundTrip"); + URL url = new URL(property); + InputStream instream = url.openStream(); + instream.close(); + } + + @Test + public void testIllegalCombinations() { + buildRule.executeTarget("testIllegalCombinations"); + assertPropertyContains("testIllegalCombinations", "/foo"); + assertPropertyContains("testIllegalCombinations", ".xml"); + } + + @Test + public void testFileset() { + buildRule.executeTarget("testFileset"); + assertPropertyContains("testFileset", ".xml "); + assertPropertyEndsWith("testFileset", ".xml"); + } + + @Test + public void testFilesetSeparator() { + buildRule.executeTarget("testFilesetSeparator"); + assertPropertyContains("testFilesetSeparator", ".xml\",\""); + assertPropertyEndsWith("testFilesetSeparator", ".xml"); + } + + @Test + public void testPath() { + buildRule.executeTarget("testPath"); + assertPropertyContains("testPath", "makeurl.xml"); + } + + /** + * assert that a property ends with + * + * @param property + * @param ending + */ + private void assertPropertyEndsWith(String property, String ending) { + String result = getProperty(property); + String substring = result.substring(result.length() - ending.length()); + assertEquals(ending, substring); + } + + /** + * assert that a property contains a string + * + * @param property name of property to look for + * @param contains what to search for in the string + */ + protected void assertPropertyContains(String property, String contains) { + String result = getProperty(property); + + assertTrue("expected " + contains + " in " + result, + result != null && result.indexOf(contains) >= 0); + } + + /** + * get a property from the project + * + * @param property + * @return + */ + protected String getProperty(String property) { + return buildRule.getProject().getProperty(property); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java new file mode 100644 index 00000000..95d4f3de --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestClassPathTest.java @@ -0,0 +1,249 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.taskdefs.condition.Os; +import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Tests <bm:manifestclasspath>. + */ +public class ManifestClassPathTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/manifestclasspath.xml"); + } + + @Test + public void testBadDirectory() { + try { + buildRule.executeTarget("test-bad-directory"); + fail("Build exception should have been thrown on bad directory"); + } catch (BuildException ex) { + assertContains("Jar's directory not found:", ex.getMessage()); + } + assertNull(buildRule.getProject().getProperty("jar.classpath")); + } + + @Test + public void testBadNoProperty() { + try { + buildRule.executeTarget("test-bad-no-property"); + fail("Build exception should have been thrown on no property"); + } catch (BuildException ex) { + assertContains("Missing 'property' attribute!", ex.getMessage()); + } + assertNull(buildRule.getProject().getProperty("jar.classpath")); + } + + @Test + public void testBadPropertyExists() { + try { + buildRule.executeTarget("test-bad-property-exists"); + fail("Build exception should have been thrown on bad property"); + } catch (BuildException ex) { + assertContains("Property 'jar.classpath' already set!", ex.getMessage()); + } + assertEquals(buildRule.getProject().getProperty("jar.classpath"), "exists"); + } + + @Test + public void testBadNoJarfile() { + try { + buildRule.executeTarget("test-bad-no-jarfile"); + fail("Build exception should have been thrown on bad jar file"); + } catch (BuildException ex) { + assertContains("Missing 'jarfile' attribute!", ex.getMessage()); + } + assertNull(buildRule.getProject().getProperty("jar.classpath")); + } + + @Test + public void testBadNoClassPath() { + try { + buildRule.executeTarget("test-bad-no-classpath"); + fail("Build exception should have been thrown on no classpath"); + } catch (BuildException ex) { + assertContains("Missing nested <classpath>!", ex.getMessage()); + } + assertNull(buildRule.getProject().getProperty("jar.classpath")); + } + + @Test + public void testParentLevel1() { + buildRule.executeTarget("test-parent-level1"); + + assertEquals(buildRule.getProject().getProperty("jar.classpath"), "dsp-core/ " + + "dsp-pres/ " + + "dsp-void/ " + + "../generated/dsp-core/ " + + "../generated/dsp-pres/ " + + "../generated/dsp-void/ " + + "../resources/dsp-core/ " + + "../resources/dsp-pres/ " + + "../resources/dsp-void/"); + } + + @Test + public void testParentLevel2() { + buildRule.executeTarget("test-parent-level2"); + + assertEquals(buildRule.getProject().getProperty("jar.classpath"), "../dsp-core/ " + + "../dsp-pres/ " + + "../dsp-void/ " + + "../../generated/dsp-core/ " + + "../../generated/dsp-pres/ " + + "../../generated/dsp-void/ " + + "../../resources/dsp-core/ " + + "../../resources/dsp-pres/ " + + "../../resources/dsp-void/"); + } + + @Test + public void testParentLevel2TooDeep() { + try { + buildRule.executeTarget("test-parent-level2-too-deep"); + fail("Build exception should have been thrown on no suitable path"); + } catch (BuildException ex) { + assertContains("No suitable relative path from ", ex.getMessage()); + } + assertNull(buildRule.getProject().getProperty("jar.classpath")); + } + + @Test + public void testPseudoTahoeRefid() { + Assume.assumeTrue("No regexp matcher is present", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject())); + + buildRule.executeTarget("test-pseudo-tahoe-refid"); + assertEquals(buildRule.getProject().getProperty("jar.classpath"), "classes/dsp-core/ " + + "classes/dsp-pres/ " + + "classes/dsp-void/ " + + "generated/dsp-core/ " + + "resources/dsp-core/ " + + "resources/dsp-pres/"); + } + + @Test + public void testPseudoTahoeNested() { + Assume.assumeTrue("No regexp matcher is present", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject())); + + buildRule.executeTarget("test-pseudo-tahoe-nested"); + assertEquals(buildRule.getProject().getProperty("jar.classpath"), "classes/dsp-core/ " + + "classes/dsp-pres/ " + + "classes/dsp-void/ " + + "generated/dsp-core/ " + + "resources/dsp-core/ " + + "resources/dsp-pres/"); + } + + @Test + public void testParentLevel2WithJars() { + buildRule.executeTarget("test-parent-level2-with-jars"); + + assertEquals(buildRule.getProject().getProperty("jar.classpath"), "../../lib/acme-core.jar " + + "../../lib/acme-pres.jar " + + "../dsp-core/ " + + "../dsp-pres/ " + + "../dsp-void/ " + + "../../generated/dsp-core/ " + + "../../generated/dsp-pres/ " + + "../../generated/dsp-void/ " + + "../../resources/dsp-core/ " + + "../../resources/dsp-pres/ " + + "../../resources/dsp-void/"); + } + + @Test + public void testInternationalGerman() { + buildRule.executeTarget("international-german"); + buildRule.executeTarget("run-two-jars"); + assertContains("beta alpha", buildRule.getLog()); + + } + + @Test + public void testInternationalHebrew() { + Assume.assumeFalse("Test with hebrew path not attempted under Windows", Os.isFamily("windows")); + buildRule.executeTarget("international-hebrew"); + buildRule.executeTarget("run-two-jars"); + assertContains("beta alpha", buildRule.getLog()); + } + + @Test + public void testSameWindowsDrive() { + Assume.assumeTrue("Test with drive letters only run on windows", Os.isFamily("windows")); + buildRule.executeTarget("testSameDrive"); + assertEquals(buildRule.getProject().getProperty("cp"), "../a/b/x.jar"); + } + + @Test + public void testDifferentWindowsDrive() { + Assume.assumeTrue("Test with drive letters only run on windows", Os.isFamily("windows")); + // the lines below try to find a drive name different than the one containing the temp dir + // if the temp dir is C will try to use D + // if the temp dir is on D or other will try to use C + File tmpdir = new File(System.getProperty("java.io.tmpdir")); + String driveLetter = "C"; + try { + String tmpCanonicalPath = tmpdir.getCanonicalPath(); + driveLetter = tmpCanonicalPath.substring(0, 1).toUpperCase(); + } catch (IOException ioe) { + System.out.println("exception happened getting canonical path of java.io.tmpdir : " + ioe.getMessage()); + } + String altDriveLetter = null; + try { + if ("C".equals(driveLetter)) { + altDriveLetter = "D"; + } else { + altDriveLetter = "C"; + } + new java.io.File(altDriveLetter + ":/foo.txt").getCanonicalPath(); + } catch (java.io.IOException e) { + Assume.assumeNoException("Drive " + altDriveLetter + ": doesn't exist or is not ready", e); + } + buildRule.getProject().setProperty("altDriveLetter", altDriveLetter); + + try { + buildRule.executeTarget("testDifferentDrive"); + fail("Build exception should have been thrown on no alternative drive"); + } catch (BuildException ex) { + assertContains("No suitable relative path from ", ex.getMessage()); + } + + assertNull(buildRule.getProject().getProperty("cp")); + } +} // END class ManifestClassPathTest diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java new file mode 100644 index 00000000..6e794327 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ManifestTest.java @@ -0,0 +1,477 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.util.Enumeration; +import java.util.HashSet; +import java.util.Set; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Testcase for the Manifest class used in the jar task. + * + */ +public class ManifestTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private File expandedManifest; + private File outDir; + + public static final String LONG_LINE + = "AReallyLongLineToTestLineBreakingInManifests-ACapabilityWhich" + + "IsSureToLeadToHundredsOfQuestionsAboutWhyAntMungesManifests" + + "OfCourseTheAnswerIsThatIsWhatTheSpecRequiresAndIfAnythingHas" + + "AProblemWithThatItIsNotABugInAnt"; + + public static final String LONG_70_NAME + = "ThisNameIsJustSeventyCharactersWhichIsAllowedAccordingToTheSpecsFiller"; + public static final String LONG_68_NAME + = "ThisNameIsJustSixtyEightCharactersWhichIsAllowedAccordingToTheSpecsX"; + public static final String NOT_LONG_NAME + = "NameIsJustUnderSeventyCharactersWhichIsAllowedAccordingTheSpec"; + + public static final String VALUE = "NOT_LONG"; + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/manifest.xml"); + outDir = new File(buildRule.getProject().getProperty("output")); + expandedManifest = new File(outDir, "manifests/META-INF/MANIFEST.MF"); + } + + @After + public void tearDown() { + buildRule.executeTarget("tearDown"); + } + + /** + * Empty manifest - is OK + */ + @Test + public void test1() throws ManifestException, IOException { + buildRule.executeTarget("test1"); + Manifest manifest = getManifest(expandedManifest); + String version = manifest.getManifestVersion(); + assertEquals("Manifest was not created with correct version - ", "1.0", version); + } + + /** + * Simple Manifest with version 2.0 + */ + @Test + public void test2() throws ManifestException, IOException { + buildRule.executeTarget("test2"); + Manifest manifest = getManifest(expandedManifest); + String version = manifest.getManifestVersion(); + assertEquals("Manifest was not created with correct version - ", "2.0", version); + } + + /** + * Malformed manifest - no : on the line + */ + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: Manifest is invalid - no colon on header line"); + } catch (BuildException ex) { + assertContains("Invalid Manifest", ex.getMessage()); + } + } + + /** + * Malformed manifest - starts with continuation line + */ + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException expected: Manifest is invalid - section starts with continuation line"); + } catch (BuildException ex) { + assertContains("Invalid Manifest", ex.getMessage()); + } + } + + /** + * Malformed manifest - Name attribute in main section + */ + @Test + public void test5() { + buildRule.executeTarget("test5"); + String output = buildRule.getLog(); + boolean hasWarning = output.indexOf("Manifest warning: \"Name\" attributes should not occur in the main section") != -1; + assertTrue("Expected warning about Name in main section", hasWarning); + } + + /** + * New Section not starting with Name attribute. + */ + @Test + public void test6() { + try { + buildRule.executeTarget("test6"); + fail("BuildException expected: Manifest is invalid - section starts with incorrect attribute"); + } catch (BuildException ex) { + assertContains("Invalid Manifest", ex.getMessage()); + } + String output = buildRule.getLog(); + boolean hasWarning = output.indexOf("Manifest sections should start with a \"Name\" attribute") != -1; + assertTrue("Expected warning about section not starting with Name: attribute", hasWarning); + } + + + /** + * From attribute is illegal + */ + @Test + public void test7() { + buildRule.executeTarget("test7"); + + boolean hasWarning = buildRule.getLog().indexOf(Manifest.ERROR_FROM_FORBIDDEN) != -1; + assertTrue("Expected warning about From: attribute", hasWarning); + } + + /** + * Inline manifest - OK + */ + @Test + public void test8() throws IOException, ManifestException { + buildRule.executeTarget("test8"); + Manifest manifest = getManifest(expandedManifest); + Manifest.Section mainSection = manifest.getMainSection(); + String classpath = mainSection.getAttributeValue("class-path"); + assertEquals("Class-Path attribute was not set correctly - ", "fubar", classpath); + + Manifest.Section testSection = manifest.getSection("Test"); + String testAttr = testSection.getAttributeValue("TestAttr"); + assertEquals("TestAttr attribute was not set correctly - ", "Test", testAttr); + } + + /** + * Inline manifest - Invalid since has a Name attribute in the section element + */ + @Test + public void test9() { + try { + buildRule.executeTarget("test9"); + fail("BuildException expected: Construction is invalid - Name attribute should not be used"); + } catch (BuildException ex) { + assertContains("Specify the section name using the \"name\" attribute of the <section> element", + ex.getMessage()); + } + } + + /** + * Inline manifest - Invalid attribute without name + */ + @Test + public void test10() { + try { + buildRule.executeTarget("test10"); + fail("BuildException expected: Attribute has no name"); + } catch (BuildException ex) { + assertContains("Attributes must have name and value", ex.getMessage()); + } + } + + /** + * Inline manifest - Invalid attribute without value + */ + @Test + public void test11() { + try { + buildRule.executeTarget("test11"); + fail("BuildException expected: Attribute has no value"); + } catch (BuildException ex) { + assertContains("Attributes must have name and value", ex.getMessage()); + } + } + + /** + * Inline manifest - Invalid attribute without value + */ + @Test + public void test12() { + try { + buildRule.executeTarget("test12"); + fail("BuildException expected: Section with no name"); + } catch (BuildException ex) { + assertContains("Sections must have a name", ex.getMessage()); + } + } + + /** + * Inline manifest - Duplicate attribute + */ + @Test + public void test13() { + try { + buildRule.executeTarget("test13"); + fail("BuildException expected: Duplicate Attribute"); + } catch (BuildException ex) { + assertContains("The attribute \"Test\" may not occur more than once in the same section", ex.getMessage()); + } + } + + /** + * Inline manifest - OK since classpath entries can be duplicated. + */ + @Test + public void test14() throws IOException, ManifestException { + buildRule.executeTarget("test14"); + Manifest manifest = getManifest(expandedManifest); + Manifest.Section mainSection = manifest.getMainSection(); + String classpath = mainSection.getAttributeValue("class-path"); + assertEquals("Class-Path attribute was not set correctly - ", + "Test1 Test2 Test3 Test4", classpath); + } + + /** + * Tets long line wrapping + */ + @Test + public void testLongLine() throws IOException, ManifestException { + Project p = buildRule.getProject(); + p.setUserProperty("test.longline", LONG_LINE); + p.setUserProperty("test.long68name" , LONG_68_NAME); + p.setUserProperty("test.long70name" , LONG_70_NAME); + p.setUserProperty("test.notlongname" , NOT_LONG_NAME); + p.setUserProperty("test.value", VALUE); + buildRule.executeTarget("testLongLine"); + + Manifest manifest = getManifest(expandedManifest); + Manifest.Section mainSection = manifest.getMainSection(); + String classpath = mainSection.getAttributeValue("class-path"); + assertEquals("Class-Path attribute was not set correctly - ", + LONG_LINE, classpath); + + String value = mainSection.getAttributeValue(LONG_68_NAME); + assertEquals("LONG_68_NAME_VALUE_MISMATCH", VALUE, value); + value = mainSection.getAttributeValue(LONG_70_NAME); + assertEquals("LONG_70_NAME_VALUE_MISMATCH", VALUE, value); + value = mainSection.getAttributeValue(NOT_LONG_NAME); + assertEquals("NOT_LONG_NAME_VALUE_MISMATCH", VALUE, value); + + Set set = new HashSet(); + FileReader fin = new FileReader(expandedManifest); + try { + BufferedReader in = new BufferedReader(fin); + + String read = in.readLine(); + while (read != null) { + set.add(read); + read = in.readLine(); + } + in.close(); + } finally { + fin.close(); + } + + assertTrue("Manifest file should have contained string ", set + .remove(" NOT_LONG")); + assertTrue("Manifest file should have contained string ", set + .remove(" NG")); + assertTrue("Manifest file should have contained string ", set + .remove(LONG_70_NAME + ": ")); + assertTrue("Manifest file should have contained string ", set + .remove(NOT_LONG_NAME + ": NOT_LO")); + } + + /** + * Tests ordering of sections + */ + @Test + public void testOrder1() throws IOException, ManifestException { + buildRule.executeTarget("testOrder1"); + + Manifest manifest = getManifest(expandedManifest); + Enumeration e = manifest.getSectionNames(); + String section1 = (String)e.nextElement(); + String section2 = (String)e.nextElement(); + assertEquals("First section name unexpected", "Test1", section1); + assertEquals("Second section name unexpected", "Test2", section2); + + Manifest.Section section = manifest.getSection("Test1"); + e = section.getAttributeKeys(); + String attr1Key = (String)e.nextElement(); + String attr2Key = (String)e.nextElement(); + String attr1 = section.getAttribute(attr1Key).getName(); + String attr2 = section.getAttribute(attr2Key).getName(); + assertEquals("First attribute name unexpected", "TestAttr1", attr1); + assertEquals("Second attribute name unexpected", "TestAttr2", attr2); + } + + /** + * Tests ordering of sections + */ + @Test + public void testOrder2() throws IOException, ManifestException { + buildRule.executeTarget("testOrder2"); + + Manifest manifest = getManifest(expandedManifest); + Enumeration e = manifest.getSectionNames(); + String section1 = (String)e.nextElement(); + String section2 = (String)e.nextElement(); + assertEquals("First section name unexpected", "Test2", section1); + assertEquals("Second section name unexpected", "Test1", section2); + + Manifest.Section section = manifest.getSection("Test1"); + e = section.getAttributeKeys(); + String attr1Key = (String)e.nextElement(); + String attr2Key = (String)e.nextElement(); + String attr1 = section.getAttribute(attr1Key).getName(); + String attr2 = section.getAttribute(attr2Key).getName(); + assertEquals("First attribute name unexpected", "TestAttr2", attr1); + assertEquals("Second attribute name unexpected", "TestAttr1", attr2); + } + + /** + * file attribute for manifest task is required. + */ + @Test + public void testNoFile() { + try { + buildRule.executeTarget("testNoFile"); + fail("BuildException expected: file is required"); + } catch (BuildException ex) { + //TODO assert value + } + } + + /** + * replace changes Manifest-Version from 2.0 to 1.0 + */ + @Test + public void testReplace() throws IOException, ManifestException { + buildRule.executeTarget("testReplace"); + Manifest mf = getManifest(new File(outDir, "mftest.mf")); + assertNotNull(mf); + assertEquals(Manifest.getDefaultManifest(), mf); + } + + /** + * update keeps the Manifest-Version and adds a new attribute Foo + */ + @Test + public void testUpdate() throws IOException, ManifestException { + buildRule.executeTarget("testUpdate"); + Manifest mf = getManifest(new File(outDir, "mftest.mf")); + assertNotNull(mf); + assertTrue(!Manifest.getDefaultManifest().equals(mf)); + String mfAsString = mf.toString(); + assertNotNull(mfAsString); + assertTrue(mfAsString.startsWith("Manifest-Version: 2.0")); + assertTrue(mfAsString.indexOf("Foo: Bar") > -1); + + mf = getManifest(new File(outDir, "mftest2.mf")); + assertNotNull(mf); + mfAsString = mf.toString(); + assertNotNull(mfAsString); + assertEquals(-1, mfAsString.indexOf("Foo: Bar")); + assertTrue(mfAsString.indexOf("Foo: Baz") > -1); + } + + @Test + public void testFrom() { + buildRule.executeTarget("testFrom"); + assertContains(Manifest.ERROR_FROM_FORBIDDEN, buildRule.getLog()); + } + + @Test + public void testIllegalName() { + try { + buildRule.executeTarget("testIllegalName"); + fail("BuildException expected: Manifest attribute names must not contain ' '"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testIllegalNameInSection() { + try { + buildRule.executeTarget("testIllegalNameInSection"); + fail("BuildException expected: Manifest attribute names must not contain ' '"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testIllegalNameBegin() { + try { + buildRule.executeTarget("testIllegalNameInSection"); + fail("BuildException expected: Manifest attribute names must not start with '-' at the begin."); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testIllegalName2() { + try { + buildRule.executeTarget("testIllegalName"); + fail("BuildException expected: Manifest attribute names must not contain '.'"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testIllegalName3() { + try { + buildRule.executeTarget("testIllegalName"); + fail("BuildException expected: Manifest attribute names must not contain '*'"); + } catch (BuildException ex) { + //TODO assert value + } + } + + /** + * Reads mftest.mf. + */ + private Manifest getManifest(File file) throws IOException, ManifestException { + FileReader r = new FileReader(file); + try { + return new Manifest(r); + } finally { + r.close(); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java new file mode 100644 index 00000000..d8f1bfc5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MkdirTest.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + */ +public class MkdirTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/mkdir.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: directory already exists as a file"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + buildRule.executeTarget("test3"); + java.io.File f = new java.io.File(buildRule.getProject().getProperty("output"), "testdir.tmp"); + if (!f.exists() || !f.isDirectory()) { + fail("mkdir failed"); + } else { + f.delete(); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MoveTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MoveTest.java new file mode 100644 index 00000000..0537c0a0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MoveTest.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Tests the Move task. + * + */ +public class MoveTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/move.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void testFilterSet() throws IOException { + buildRule.executeTarget("testFilterSet"); + File tmp = new File(buildRule.getProject().getProperty("output"), "move.filterset.tmp"); + File check = new File(buildRule.getProject().getBaseDir(), "expected/copy.filterset.filtered"); + assertTrue(tmp.exists()); + assertEquals(FileUtilities.getFileContents(check), FileUtilities.getFileContents(tmp)); + } + + @Test + public void testFilterChain() throws IOException { + buildRule.executeTarget("testFilterChain"); + File tmp = new File(buildRule.getProject().getProperty("output"), "move.filterchain.tmp"); + File check = new File(buildRule.getProject().getBaseDir(), "expected/copy.filterset.filtered"); + assertTrue(tmp.exists()); + assertEquals(FileUtilities.getFileContents(check), FileUtilities.getFileContents(tmp)); + } + + /** Bugzilla Report 11732 */ + @Test + public void testDirectoryRemoval() throws IOException { + + buildRule.executeTarget("testDirectoryRemoval"); + String output = buildRule.getProject().getProperty("output"); + assertTrue(!new File(output,"E/B/1").exists()); + assertTrue(new File(output, "E/C/2").exists()); + assertTrue(new File(output,"E/D/3").exists()); + assertTrue(new File(output,"A/B/1").exists()); + assertTrue(!new File(output,"A/C/2").exists()); + assertTrue(!new File(output,"A/D/3").exists()); + assertTrue(!new File(output,"A/C").exists()); + assertTrue(!new File(output,"A/D").exists()); + } + + /** Bugzilla Report 18886 */ + @Test + public void testDirectoryRetaining() throws IOException { + buildRule.executeTarget("testDirectoryRetaining"); + String output = buildRule.getProject().getProperty("output"); + assertTrue(new File(output,"E").exists()); + assertTrue(new File(output,"E/1").exists()); + assertTrue(!new File(output,"A/1").exists()); + assertTrue(new File(output,"A").exists()); + } + + @Test + public void testCompleteDirectoryMove() throws IOException { + testCompleteDirectoryMove("testCompleteDirectoryMove"); + } + + @Test + public void testCompleteDirectoryMove2() throws IOException { + testCompleteDirectoryMove("testCompleteDirectoryMove2"); + } + + private void testCompleteDirectoryMove(String target) throws IOException { + buildRule.executeTarget(target); + String output = buildRule.getProject().getProperty("output"); + assertTrue(new File(output,"E").exists()); + assertTrue(new File(output,"E/1").exists()); + assertTrue(!new File(output,"A/1").exists()); + // <path> swallows the basedir, it seems + //assertTrue(!new File(getOutputDir(),"A").exists()); + } + + @Test + public void testPathElementMove() throws IOException { + buildRule.executeTarget("testPathElementMove"); + String output = buildRule.getProject().getProperty("output"); + assertTrue(new File(output,"E").exists()); + assertTrue(new File(output,"E/1").exists()); + assertTrue(!new File(output,"A/1").exists()); + assertTrue(new File(output,"A").exists()); + } + + @Test + public void testMoveFileAndFileset() { + buildRule.executeTarget("testMoveFileAndFileset"); + } + + @Test + public void testCompleteDirectoryMoveToExistingDir() { + buildRule.executeTarget("testCompleteDirectoryMoveToExistingDir"); + } + + @Test + public void testCompleteDirectoryMoveFileToFile() { + buildRule.executeTarget("testCompleteDirectoryMoveFileToFile"); + } + + @Test + public void testCompleteDirectoryMoveFileToDir() { + buildRule.executeTarget("testCompleteDirectoryMoveFileToDir"); + } + + @Test + public void testCompleteDirectoryMoveFileAndFileset() { + buildRule.executeTarget("testCompleteDirectoryMoveFileAndFileset"); + } + + @Test + public void testCompleteDirectoryMoveFileToExistingFile() { + buildRule.executeTarget("testCompleteDirectoryMoveFileToExistingFile"); + } + + @Test + public void testCompleteDirectoryMoveFileToExistingDir() { + buildRule.executeTarget("testCompleteDirectoryMoveFileToExistingDir"); + } + + @Test + public void testCompleteDirectoryMoveFileToDirWithExistingFile() { + buildRule.executeTarget("testCompleteDirectoryMoveFileToDirWithExistingFile"); + } + + @Test + public void testCompleteDirectoryMoveFileToDirWithExistingDir() { + buildRule.executeTarget("testCompleteDirectoryMoveFileToDirWithExistingDir"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MultiMapTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MultiMapTest.java new file mode 100644 index 00000000..95f9eafd --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/MultiMapTest.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileNameMapper; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + + +/** + */ +public class MultiMapTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/multimap.xml"); + } + + @Test + public void testMultiCopy() { + buildRule.executeTarget("multicopy"); + } + + @Test + public void testMultiMove() { + buildRule.executeTarget("multimove"); + } + + @Test + public void testSingleCopy() { + buildRule.executeTarget("singlecopy"); + } + + @Test + public void testSingleMove() { + buildRule.executeTarget("singlemove"); + } + + @Test + public void testCopyWithEmpty() { + buildRule.executeTarget("copywithempty"); + } + + @Test + public void testMoveWithEmpty() { + buildRule.executeTarget("movewithempty"); + } + + public static class TestMapper implements FileNameMapper { + public TestMapper() {} + public void setFrom(String from) {} + public void setTo(String to) {} + public String[] mapFileName(final String source_file_name) { + return new String[] { + source_file_name, source_file_name+".copy2" }; + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/NiceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/NiceTest.java new file mode 100644 index 00000000..98d9fa58 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/NiceTest.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.fail; + +/** + * test nice + */ +public class NiceTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/nice.xml"); + } + + @Test + public void testNoop() { + buildRule.executeTarget("noop"); + } + + @Test + public void testCurrent() { + buildRule.executeTarget("current"); + } + + @Test + public void testFaster() { + buildRule.executeTarget("faster"); + } + + @Test + public void testSlower() { + buildRule.executeTarget("slower"); + } + + @Test + public void testTooSlow() { + try { + buildRule.executeTarget("too_slow"); + fail("BuildException expected: out of range"); + } catch (BuildException ex) { + assertContains("out of the range 1-10", ex.getMessage()); + } + } + + @Test + public void testTooFast() { + try { + buildRule.executeTarget("too_fast"); + fail("BuildException expected: out of range"); + } catch (BuildException ex) { + assertContains("out of the range 1-10", ex.getMessage()); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java new file mode 100644 index 00000000..3ca7cf78 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ParallelTest.java @@ -0,0 +1,195 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.PrintStream; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.DemuxOutputStream; +import org.apache.tools.ant.ExitStatusException; +import org.apache.tools.ant.Project; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Test of the parallel TaskContainer + */ +public class ParallelTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + /** Standard property value for the basic test */ + public final static String DIRECT_MESSAGE = "direct"; + /** Standard property value for the basic and fail test */ + public final static String DELAYED_MESSAGE = "delayed"; + /** Standard property value for the fail test */ + public final static String FAILURE_MESSAGE = "failure"; + + /** the build fiel associated with this test */ + public final static String TEST_BUILD_FILE + = "src/etc/testcases/taskdefs/parallel.xml"; + + + /** The JUnit setup method */ + @Before + public void setUp() { + buildRule.configureProject(TEST_BUILD_FILE); + } + + /** tests basic operation of the parallel task */ + @Test + public void testBasic() { + // should get no output at all + Project p = buildRule.getProject(); + p.setUserProperty("test.direct", DIRECT_MESSAGE); + p.setUserProperty("test.delayed", DELAYED_MESSAGE); + buildRule.executeTarget("testBasic"); + assertEquals("", buildRule.getOutput()); + assertEquals("", buildRule.getError()); + String log = buildRule.getLog(); + assertEquals("parallel tasks didn't output correct data", log, + DIRECT_MESSAGE + DELAYED_MESSAGE); + + } + + /** tests basic operation of the parallel task */ + @Test + public void testThreadCount() { + // should get no output at all + Project p = buildRule.getProject(); + p.setUserProperty("test.direct", DIRECT_MESSAGE); + p.setUserProperty("test.delayed", DELAYED_MESSAGE); + buildRule.executeTarget("testThreadCount"); + assertEquals("", buildRule.getOutput()); + assertEquals("", buildRule.getError()); + String log = buildRule.getLog(); + int pos = 0; + while (pos > -1) { + pos = countThreads(log, pos); + } + } + + /** + * the test result string should match the regex + * <code>^(\|\d+\/(+-)*)+\|$</code> for someting like + * <code>|3/++--+-|5/+++++-----|</code> + * + *@return -1 no more tests + * # start pos of next test + */ + static int countThreads(String s, int start) { + int firstPipe = s.indexOf('|', start); + int beginSlash = s.indexOf('/', firstPipe); + int lastPipe = s.indexOf('|', beginSlash); + if ((firstPipe == -1) || (beginSlash == -1) || (lastPipe == -1)) { + return -1; + } + + int max = Integer.parseInt(s.substring(firstPipe + 1, beginSlash)); + int current = 0; + int pos = beginSlash + 1; + while (pos < lastPipe) { + switch (s.charAt(pos++)) { + case '+': + current++; + break; + case '-': + current--; + break; + default: + fail("Only expect '+-' in result count, found " + + s.charAt(--pos) + " at position " + pos); + } + if (current > max) { + fail("Number of executing threads exceeded number allowed: " + + current + " > " + max); + } + } + return lastPipe; + } + + + /** tests the failure of a task within a parallel construction */ + @Test + public void testFail() { + // should get no output at all + Project p = buildRule.getProject(); + p.setUserProperty("test.failure", FAILURE_MESSAGE); + p.setUserProperty("test.delayed", DELAYED_MESSAGE); + try { + buildRule.executeTarget("testFail"); + fail("fail task in one parallel branch"); + } catch (BuildException ex) { + assertEquals(FAILURE_MESSAGE, ex.getMessage()); + } + } + + /** tests the demuxing of output streams in a multithreaded situation */ + @Test + public void testDemux() { + Project p = buildRule.getProject(); + p.addTaskDefinition("demuxtest", DemuxOutputTask.class); + synchronized (System.out) { + PrintStream out = System.out; + PrintStream err = System.err; + System.setOut(new PrintStream(new DemuxOutputStream(p, false))); + System.setErr(new PrintStream(new DemuxOutputStream(p, true))); + + try { + p.executeTarget("testDemux"); + } finally { + System.setOut(out); + System.setErr(err); + } + } + } + + /** + * @see "https://issues.apache.org/bugzilla/show_bug.cgi?id=55539" + */ + @Test + public void testSingleExit() { + try { + buildRule.executeTarget("testSingleExit"); + fail("ExitStatusException should have been thrown"); + } catch (ExitStatusException ex) { + assertEquals(42, ex.getStatus()); + } + } + + /** + * @see "https://issues.apache.org/bugzilla/show_bug.cgi?id=55539" + */ + @Test + public void testExitAndOtherException() { + try { + buildRule.executeTarget("testExitAndOtherException"); + fail("ExitStatusException should have been thrown"); + } catch (ExitStatusException ex) { + assertEquals(42, ex.getStatus()); + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java new file mode 100644 index 00000000..31a516e3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PathConvertTest.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Unit test for the <pathconvert> task. + */ +public class PathConvertTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private static final String BUILD_PATH = "src/etc/testcases/taskdefs/"; + private static final String BUILD_FILENAME = "pathconvert.xml"; + private static final String BUILD_FILE = BUILD_PATH + BUILD_FILENAME; + + @Before + public void setUp() { + buildRule.configureProject(BUILD_FILE); + } + + @Test + public void testMap() { + test("testmap"); + } + + @Test + public void testMapper() { + test("testmapper"); + } + + @Test + public void testNoTargetOs() { + buildRule.executeTarget("testnotargetos"); + } + + private void test(String target) { + buildRule.executeTarget(target); + assertEquals("test#" + BUILD_FILENAME, buildRule.getProject().getProperty("result")); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PreSetDefTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PreSetDefTest.java new file mode 100644 index 00000000..8c7c1f3f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PreSetDefTest.java @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.FileSet; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + */ +public class PreSetDefTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/presetdef.xml"); + } + + @Test + public void testSimple() { + buildRule.executeTarget("simple"); + assertEquals("Hello world", buildRule.getLog()); + } + + @Test + public void testText() { + buildRule.executeTarget("text"); + assertEquals("Inner Text", buildRule.getLog()); + } + + @Test + public void testUri() { + buildRule.executeTarget("uri"); + assertEquals("Hello world", buildRule.getLog()); + } + + @Test + public void testDefaultTest() { + buildRule.executeTarget("defaulttest"); + assertEquals("attribute is false", buildRule.getLog()); + } + + @Test + public void testDoubleDefault() { + buildRule.executeTarget("doubledefault"); + assertEquals("attribute is falseattribute is true", buildRule.getLog()); + } + + @Test + public void testTextOptional() { + buildRule.executeTarget("text.optional"); + assertEquals("MyTextoverride text", buildRule.getLog()); + } + + @Test + public void testElementOrder() { + buildRule.executeTarget("element.order"); + assertEquals("Line 1Line 2", buildRule.getLog()); + } + + @Test + public void testElementOrder2() { + buildRule.executeTarget("element.order2"); + assertEquals("Line 1Line 2Line 3", buildRule.getLog()); + } + + @Test + public void testAntTypeTest() { + buildRule.executeTarget("antTypeTest"); + assertEquals("", buildRule.getLog()); + } + + @Test + public void testCorrectTaskNameBadAttr() { + try { + buildRule.executeTarget("correct_taskname_badattr"); + fail("BuildException expected: attribute message"); + } catch (BuildException ex) { + assertContains("javac doesn't support the", ex.getMessage()); + } + } + + @Test + public void testCorrectTaskNameBadEl() { + try { + buildRule.executeTarget("correct_taskname_badel"); + fail("BuildException expected: element message"); + } catch (BuildException ex) { + assertContains("javac doesn't support the", ex.getMessage()); + } + } + + @Test + public void testPresetdefWithNestedElementTwice() { // #38056 + buildRule.executeTarget("presetdef-with-nested-element-twice"); + buildRule.executeTarget("presetdef-with-nested-element-twice"); + } + + /** + * A test class to check default properties + */ + public static class DefaultTest extends Task { + boolean isSet = false; + boolean attribute = false; + public void setAttribute(boolean b) { + if (isSet) { + throw new BuildException("Attribute Already set"); + } + attribute = b; + isSet = true; + } + + public void execute() { + getProject().log("attribute is " + attribute); + } + } + + /** + * A test class to check presetdef with add and addConfigured and ant-type + */ + public static class AntTypeTest extends Task { + public void addFileSet(FileSet fileset) { + } + public void addConfiguredConfigured(FileSet fileset) { + } + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ProcessDestroyerTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ProcessDestroyerTest.java new file mode 100644 index 00000000..eadac406 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ProcessDestroyerTest.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Created on Feb 19, 2003 + */ +package org.apache.tools.ant.taskdefs; + +import java.io.IOException; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + */ +//TODO this test seems really unsafe due to the infinite loop +public class ProcessDestroyerTest { + + @Test + public void testProcessDestroyer() throws IOException { + ProcessDestroyer processDestroyer = new ProcessDestroyer(); + Process process = + Runtime.getRuntime().exec( + "java -cp " + + System.getProperty("java.class.path") + + " " + + getClass().getName()); + + assertFalse("Not registered as shutdown hook", + processDestroyer.isAddedAsShutdownHook()); + + processDestroyer.add(process); + + assertTrue("Registered as shutdown hook", + processDestroyer.isAddedAsShutdownHook()); + try { + process.destroy(); + } finally { + processDestroyer.remove(process); + } + + assertFalse("Not registered as shutdown hook", + processDestroyer.isAddedAsShutdownHook()); + + } + + public static void main(String[] args) throws IOException, InterruptedException { + new ProcessDestroyerTest().testProcessDestroyer(); + Thread.sleep(60000); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java new file mode 100644 index 00000000..52b762d0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/PropertyTest.java @@ -0,0 +1,141 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + */ +public class PropertyTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + /** Utilities used for file operations */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/property.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + // should get no output at all + buildRule.executeTarget("test1"); + assertEquals("System output should have been empty", "", buildRule.getOutput()); + assertEquals("System error should have been empty", "", buildRule.getError()); + } + + @Test + public void test2() { + buildRule.executeTarget("test2"); + assertContains("testprop1=aa, testprop3=xxyy, testprop4=aazz", buildRule.getLog()); + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("Did not throw exception on circular exception"); + } + catch (BuildException e) { + assertTrue("Circular definition not detected - ", + e.getMessage().indexOf("was circularly defined") != -1); + } + + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + assertContains("http.url is http://localhost:999", buildRule.getLog()); + } + + @Test + public void test5() { + String baseDir = buildRule.getProject().getProperty("basedir"); + String uri = FILE_UTILS.toURI(baseDir + "/property3.properties"); + buildRule.getProject().setNewProperty("test5.url", uri); + + buildRule.executeTarget("test5"); + assertContains("http.url is http://localhost:999", buildRule.getLog()); + } + + @Test + public void testPrefixSuccess() { + buildRule.executeTarget("prefix.success"); + assertEquals("80", buildRule.getProject().getProperty("server1.http.port")); + } + + @Test + public void testPrefixFailure() { + try { + buildRule.executeTarget("prefix.fail"); + fail("Did not throw exception on invalid use of prefix"); + } + catch (BuildException e) { + assertContains("Prefix allowed on non-resource/file load - ", + "Prefix is only valid", e.getMessage()); + } + } + + @Test + public void testCircularReference() { + try { + buildRule.executeTarget("testCircularReference"); + fail("Did not throw exception on circular exception"); + } catch (BuildException e) { + assertContains("Circular definition not detected - ", + "was circularly defined", e.getMessage()); + } + } + + @Test + public void testThisIsNotACircularReference() { + buildRule.executeTarget("thisIsNotACircularReference"); + assertContains("b is A/A/A", buildRule.getLog()); + } + + @Test + public void testXmlProperty() { + try { + Class.forName("java.lang.Iterable"); + } catch (ClassNotFoundException e) { + Assume.assumeNoException("XML Loading only on Java 5+", e); + } + buildRule.executeTarget("testXmlProperty"); + assertEquals("ONE", buildRule.getProject().getProperty("xml.one")); + assertEquals("TWO", buildRule.getProject().getProperty("xml.two")); + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java new file mode 100644 index 00000000..27b3c8c8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ProtectedJarMethodsTest.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +/** + */ +public class ProtectedJarMethodsTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + private static String tempJar = "tmp.jar"; + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/jar.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void testGrabFilesAndDirs() throws IOException { + buildRule.executeTarget("testIndexTests"); + String archive = buildRule.getProject().getProperty(tempJar); + ArrayList dirs = new ArrayList(); + ArrayList files = new ArrayList(); + String[] expectedDirs = new String[] { + "META-INF/", + "sub/", + }; + String[] expectedFiles = new String[] { + "foo", + }; + Jar.grabFilesAndDirs(archive, dirs, files); + assertEquals(expectedDirs.length, dirs.size()); + for (int i = 0; i < expectedDirs.length; i++) { + assertTrue("Found " + expectedDirs[i], + dirs.contains(expectedDirs[i])); + } + assertEquals(expectedFiles.length, files.size()); + for (int i = 0; i < expectedFiles.length; i++) { + assertTrue("Found " + expectedFiles[i], + files.contains(expectedFiles[i])); + } + } + + @Test + public void testFindJarNameNoClasspath() { + assertEquals("foo", Jar.findJarName("foo", null)); + assertEquals("foo", Jar.findJarName("lib" + File.separatorChar + "foo", + null)); + } + + @Test + public void testFindJarNameNoMatch() { + assertNull(Jar.findJarName("foo", new String[] {"bar"})); + } + + @Test + public void testFindJarNameSimpleMatches() { + assertEquals("foo", Jar.findJarName("foo", new String[] {"foo"})); + assertEquals("lib/foo", Jar.findJarName("foo", + new String[] {"lib/foo"})); + assertEquals("foo", Jar.findJarName("bar" + File.separatorChar + "foo", + new String[] {"foo"})); + assertEquals("lib/foo", + Jar.findJarName("bar" + File.separatorChar + "foo", + new String[] {"lib/foo"})); + } + + @Test + public void testFindJarNameLongestMatchWins() { + assertEquals("lib/foo", + Jar.findJarName("lib/foo", + new String[] {"foo", "lib/foo", + "lib/bar/foo"})); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RecorderTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RecorderTest.java new file mode 100644 index 00000000..c4806cd8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RecorderTest.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; + +import static org.junit.Assert.assertTrue; + +/** + */ +public class RecorderTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private static final String REC_IN = "recorder/"; + + /** Utilities used for file operations */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/recorder.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void testNoAppend() throws IOException { + buildRule.executeTarget("noappend"); + assertTrue(FILE_UTILS + .contentEquals(buildRule.getProject().resolveFile(REC_IN + + "rectest1.result"), + new File(buildRule.getOutputDir(), + "rectest1.log"), true)); + } + + @Test + public void testAppend() throws IOException { + buildRule.executeTarget("append"); + assertTrue(FILE_UTILS + .contentEquals(buildRule.getProject().resolveFile(REC_IN + + "rectest2.result"), + new File(buildRule.getOutputDir(), + "rectest2.log"), true)); + } + + @Test + public void testRestart() throws IOException { + buildRule.executeTarget("restart"); + assertTrue(FILE_UTILS + .contentEquals(buildRule.getProject().resolveFile(REC_IN + + "rectest3.result"), + new File(buildRule.getOutputDir(), "rectest3.log"), true)); + } + + @Test + public void testDeleteRestart() throws IOException { + buildRule.executeTarget("deleterestart"); + assertTrue(FILE_UTILS + .contentEquals(buildRule.getProject().resolveFile(REC_IN + + "rectest4.result"), + new File(buildRule.getOutputDir(), + "rectest4.log"), true)); + } + + @Test + public void testSubBuild() throws IOException { + buildRule.executeTarget("subbuild"); + assertTrue(FILE_UTILS + .contentEquals(buildRule.getProject().resolveFile(REC_IN + + "rectest5.result"), + new File(buildRule.getOutputDir(), "rectest5.log"), true)); + assertTrue(FILE_UTILS + .contentEquals(buildRule.getProject().resolveFile(REC_IN + + "rectest6.result"), + new File(buildRule.getOutputDir(), "rectest6.log"), true)); + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java new file mode 100644 index 00000000..0cb13441 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RenameTest.java @@ -0,0 +1,88 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class RenameTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/rename.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException should have been thrown: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException should have been thrown: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException should have been thrown: required argument missing"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + @Ignore("Previously commented out") + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException should have been thrown: source and destination the same"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + @Ignore("Previously commented out") + public void test5() { + buildRule.executeTarget("test5"); + } + @Test + public void test6() { + buildRule.executeTarget("test6"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java new file mode 100644 index 00000000..387c54dc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ReplaceTest.java @@ -0,0 +1,180 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.BufferedInputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import junit.framework.AssertionFailedError; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +/** + */ +public class ReplaceTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/replace.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException expected: empty token not allowed"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + } + + @Test + public void test6() { + try { + buildRule.executeTarget("test6"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test7() { + try { + buildRule.executeTarget("test7"); + fail("BuildException expected: empty token not allowed"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test8() { + buildRule.executeTarget("test8"); + } + + @Test + public void test9() throws IOException { + + buildRule.executeTarget("test9"); + assertEqualContent(new File(buildRule.getOutputDir(), "result.txt"), + new File(buildRule.getOutputDir(), "output.txt")); + } + + @Test + public void testNoPreserveLastModified() throws Exception { + buildRule.executeTarget("lastModifiedSetup"); + File testFile = new File(buildRule.getOutputDir(), "test.txt"); + assumeTrue("Could not change file modification time", + testFile.setLastModified(testFile.lastModified() - (FileUtils.getFileUtils().getFileTimestampGranularity() * 5))); + long ts1 = testFile.lastModified(); + buildRule.executeTarget("testNoPreserve"); + assertTrue(ts1 < new File(buildRule.getOutputDir(), "test.txt").lastModified()); + } + + @Test + public void testPreserveLastModified() throws Exception { + buildRule.executeTarget("lastModifiedSetup"); + File testFile = new File(buildRule.getOutputDir(), "test.txt"); + assumeTrue("Could not change file modification time", + testFile.setLastModified(testFile.lastModified() - (FileUtils.getFileUtils().getFileTimestampGranularity() * 5))); + long ts1 = testFile.lastModified();buildRule.executeTarget("testPreserve"); + assertTrue(ts1 == new File(buildRule.getOutputDir(), "test.txt").lastModified()); + } + + public void assertEqualContent(File expect, File result) + throws AssertionFailedError, IOException { + if (!result.exists()) { + fail("Expected file "+result+" doesn\'t exist"); + } + + InputStream inExpect = null; + InputStream inResult = null; + try { + inExpect = new BufferedInputStream(new FileInputStream(expect)); + inResult = new BufferedInputStream(new FileInputStream(result)); + + int expectedByte = inExpect.read(); + while (expectedByte != -1) { + assertEquals(expectedByte, inResult.read()); + expectedByte = inExpect.read(); + } + assertEquals("End of file", -1, inResult.read()); + } finally { + if (inResult != null) { + inResult.close(); + } + if (inExpect != null) { + inExpect.close(); + } + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java new file mode 100644 index 00000000..c9d25146 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RmicAdvancedTest.java @@ -0,0 +1,467 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.rmic.RmicAdapterFactory; +import org.apache.tools.ant.taskdefs.rmic.DefaultRmicAdapter; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + * Date: 04-Aug-2004 + * Time: 22:15:46 + */ +public class RmicAdvancedTest { + + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/rmic/"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + /** + * The JUnit setup method + */ + @Before + public void setUp() throws Exception { + buildRule.configureProject(TASKDEFS_DIR + "rmic.xml"); + } + + /** + * verify that "default" binds us to the default compiler + */ + @Test + public void testDefault() throws Exception { + buildRule.executeTarget("testDefault"); + } + + /** + * verify that "default" binds us to the default compiler + */ + @Test + public void testDefaultDest() throws Exception { + buildRule.executeTarget("testDefaultDest"); + } + + /** + * verify that "" binds us to the default compiler + */ + @Test + public void testEmpty() throws Exception { + buildRule.executeTarget("testEmpty"); + } + + /** + * verify that "" binds us to the default compiler + */ + @Test + public void testEmptyDest() throws Exception { + buildRule.executeTarget("testEmptyDest"); + } + + /** + * test sun's rmic compiler + */ + @Test + public void testRmic() throws Exception { + buildRule.executeTarget("testRmic"); + } + + /** + * test sun's rmic compiler + */ + @Test + public void testRmicDest() throws Exception { + buildRule.executeTarget("testRmicDest"); + } + + /** + * test sun's rmic compiler strips + * out -J arguments when not forking + */ + @Test + public void testRmicJArg() throws Exception { + buildRule.executeTarget("testRmicJArg"); + } + + /** + * test sun's rmic compiler strips + * out -J arguments when not forking + */ + @Test + public void testRmicJArgDest() throws Exception { + buildRule.executeTarget("testRmicJArgDest"); + } + + /** + * A unit test for JUnit + */ + @Test + public void testKaffe() throws Exception { + buildRule.executeTarget("testKaffe"); + } + + /** + * A unit test for JUnit + */ + @Test + public void testKaffeDest() throws Exception { + buildRule.executeTarget("testKaffeDest"); + } + + // WLrmic tests don't work + /** + * test weblogic + */ + @Test + @Ignore("WLRmin tests don't work") + public void XtestWlrmic() throws Exception { + buildRule.executeTarget("testWlrmic"); + } + + /** + * test weblogic's stripping of -J args + */ + @Test + @Ignore("WLRmin tests don't work") + public void XtestWlrmicJArg() throws Exception { + buildRule.executeTarget("testWlrmicJArg"); + } + + /** + * test the forking compiler + */ + @Test + @Ignore("WLRmin tests don't work") + public void NotestForking() throws Exception { + buildRule.executeTarget("testForking"); + } + + /** + * test the forking compiler + */ + @Test + public void testForkingAntClasspath() throws Exception { + buildRule.executeTarget("testForkingAntClasspath"); + } + + /** + * test the forking compiler + */ + @Test + public void testForkingAntClasspathDest() throws Exception { + buildRule.executeTarget("testForkingAntClasspathDest"); + } + + /** + * test the forking compiler + */ + @Test + public void testAntClasspath() throws Exception { + buildRule.executeTarget("testAntClasspath"); + } + + /** + * test the forking compiler + */ + @Test + public void testAntClasspathDest() throws Exception { + buildRule.executeTarget("testAntClasspathDest"); + } + + /** + * A unit test for JUnit + */ + @Test + public void testBadName() throws Exception { + try { + buildRule.executeTarget("testBadName"); + fail("Compile not known"); + } catch (BuildException ex) { + AntAssert.assertContains(RmicAdapterFactory.ERROR_UNKNOWN_COMPILER, ex.getMessage()); + } + } + + /** + * load an adapter by name + */ + @Test + public void testExplicitClass() throws Exception { + buildRule.executeTarget("testExplicitClass"); + } + + /** + * A unit test for JUnit + */ + @Test + public void testWrongClass() throws Exception { + try { + buildRule.executeTarget("testWrongClass"); + fail("Class not an RMIC adapter"); + } catch (BuildException ex) { + AntAssert.assertContains(RmicAdapterFactory.ERROR_NOT_RMIC_ADAPTER, ex.getMessage()); + } + } + + + /** + * A unit test for JUnit + */ + @Test + public void testDefaultBadClass() throws Exception { + try { + buildRule.executeTarget("testDefaultBadClass"); + fail("expected the class to fail"); + } catch(BuildException ex) { + AntAssert.assertContains(Rmic.ERROR_RMIC_FAILED, ex.getMessage()); + } + //dont look for much text here as it is vendor and version dependent + AntAssert.assertContains("unimplemented.class", buildRule.getLog()); + } + + + /** + * A unit test for JUnit + */ + @Test + public void testMagicProperty() throws Exception { + try { + buildRule.executeTarget("testMagicProperty"); + fail("Magic property not working"); + } catch (BuildException ex) { + AntAssert.assertContains(RmicAdapterFactory.ERROR_UNKNOWN_COMPILER, ex.getMessage()); + } + } + + /** + * A unit test for JUnit + */ + @Test + public void testMagicPropertyOverridesEmptyString() throws Exception { + try { + buildRule.executeTarget("testMagicPropertyOverridesEmptyString"); + fail("Magic property not working"); + } catch (BuildException ex) { + AntAssert.assertContains(RmicAdapterFactory.ERROR_UNKNOWN_COMPILER, ex.getMessage()); + } + } + + + @Test + public void testMagicPropertyIsEmptyString() throws Exception { + buildRule.executeTarget("testMagicPropertyIsEmptyString"); + } + + + @Test + @Ignore("Previously named to prevent execution") + public void NotestFailingAdapter() throws Exception { + try { + buildRule.executeTarget("testFailingAdapter"); + fail("Expected failures to propogate"); + } catch (BuildException ex) { + AntAssert.assertContains(Rmic.ERROR_RMIC_FAILED, ex.getMessage()); + } + } + + + /** + * test that version 1.1 stubs are good + * @throws Exception + */ + @Test + public void testVersion11() throws Exception { + buildRule.executeTarget("testVersion11"); + } + + /** + * test that version 1.1 stubs are good + * @throws Exception + */ + @Test + public void testVersion11Dest() throws Exception { + buildRule.executeTarget("testVersion11Dest"); + } + + /** + * test that version 1.2 stubs are good + * + * @throws Exception + */ + @Test + public void testVersion12() throws Exception { + buildRule.executeTarget("testVersion12"); + } + + /** + * test that version 1.2 stubs are good + * + * @throws Exception + */ + @Test + public void testVersion12Dest() throws Exception { + buildRule.executeTarget("testVersion12Dest"); + } + + /** + * test that version compat stubs are good + * + * @throws Exception + */ + @Test + public void testVersionCompat() throws Exception { + buildRule.executeTarget("testVersionCompat"); + } + + /** + * test that version compat stubs are good + * + * @throws Exception + */ + @Test + public void testVersionCompatDest() throws Exception { + buildRule.executeTarget("testVersionCompatDest"); + } + + /** + * test that passes -Xnew to sun's rmic. + * + * @throws Exception + */ + @Test + public void testXnew() throws Exception { + buildRule.executeTarget("testXnew"); + } + + /** + * test that passes -Xnew to sun's rmic. + * + * @throws Exception + */ + @Test + public void testXnewDest() throws Exception { + buildRule.executeTarget("testXnewDest"); + } + + /** + * test that passes -Xnew to sun's rmic running in a different VM. + * + * @throws Exception + */ + @Test + public void testXnewForked() throws Exception { + buildRule.executeTarget("testXnewForked"); + } + + /** + * test that passes -Xnew to sun's rmic running in a different VM. + * + * @throws Exception + */ + @Test + public void testXnewForkedDest() throws Exception { + buildRule.executeTarget("testXnewForkedDest"); + } + + /** + * test that runs the new xnew compiler adapter. + * + * @throws Exception + */ + @Test + public void testXnewCompiler() throws Exception { + buildRule.executeTarget("testXnewCompiler"); + } + + /** + * test that runs the new xnew compiler adapter. + * + * @throws Exception + */ + @Test + public void testXnewCompilerDest() throws Exception { + buildRule.executeTarget("testXnewCompilerDest"); + } + + /** + * test that verifies that IDL compiles. + * + * @throws Exception + */ + @Test + public void testIDL() throws Exception { + buildRule.executeTarget("testIDL"); + } + + /** + * test that verifies that IDL compiles. + * + * @throws Exception + */ + @Test + public void testIDLDest() throws Exception { + buildRule.executeTarget("testIDLDest"); + } + + /** + * test that verifies that IIOP compiles. + * + * @throws Exception + */ + @Test + public void testIIOP() throws Exception { + buildRule.executeTarget("testIIOP"); + } + + /** + * test that verifies that IIOP compiles. + * + * @throws Exception + */ + @Test + public void testIIOPDest() throws Exception { + buildRule.executeTarget("testIIOPDest"); + } + + /** + * this little bunny verifies that we can load stuff, and that + * a failure to execute is turned into a fault + */ + public static class FailingRmicAdapter extends DefaultRmicAdapter { + public static final String LOG_MESSAGE = "hello from FailingRmicAdapter"; + + /** + * Executes the task. + * + * @return false -always + */ + public boolean execute() throws BuildException { + getRmic().log(LOG_MESSAGE); + return false; + } + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RmicTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RmicTest.java new file mode 100644 index 00000000..8d3200c3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/RmicTest.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.Project; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + + +/** + * Testcase for <rmic>. + * + * @since Ant 1.5 + */ +public class RmicTest { + + private Project project; + private Rmic rmic; + + @Before + public void setUp() { + project = new Project(); + project.init(); + rmic = new Rmic(); + rmic.setProject(project); + } + + /** + * Test nested compiler args. + */ + @Test + public void testCompilerArg() { + String[] args = rmic.getCurrentCompilerArgs(); + assertNotNull(args); + assertEquals("no args", 0, args.length); + + Rmic.ImplementationSpecificArgument arg = rmic.createCompilerArg(); + String ford = "Ford"; + String prefect = "Prefect"; + String testArg = ford + " " + prefect; + arg.setValue(testArg); + args = rmic.getCurrentCompilerArgs(); + assertEquals("unconditional single arg", 1, args.length); + assertEquals(testArg, args[0]); + + arg.setCompiler("weblogic"); + args = rmic.getCurrentCompilerArgs(); + assertNotNull(args); + assertEquals("implementation is weblogic but build.rmic is null", + 0, args.length); + + project.setProperty("build.rmic", "sun"); + args = rmic.getCurrentCompilerArgs(); + assertNotNull(args); + assertEquals("implementation is weblogic but build.rmic is sun", + 0, args.length); + + project.setProperty("build.rmic", "weblogic"); + args = rmic.getCurrentCompilerArgs(); + assertEquals("both are weblogic", 1, args.length); + assertEquals(testArg, args[0]); + } + + /** + * Test compiler attribute. + */ + @Test + public void testCompilerAttribute() { + // check defaults + String compiler = rmic.getCompiler(); + assertNotNull(compiler); + assertEquals("expected sun or kaffe, but found "+compiler,compiler,"default"); + + project.setNewProperty("build.rmic", "weblogic"); + compiler = rmic.getCompiler(); + assertNotNull(compiler); + assertEquals("weblogic", compiler); + + // check attribute overrides build.compiler + rmic.setCompiler("kaffe"); + compiler = rmic.getCompiler(); + assertNotNull(compiler); + assertEquals("kaffe", compiler); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java new file mode 100644 index 00000000..fbce8a6d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SQLExecTest.java @@ -0,0 +1,326 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.sql.Driver; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.DriverPropertyInfo; +import java.util.Properties; +import java.io.File; +import java.net.URL; +import java.util.logging.Logger; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.BuildException; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Simple testcase to test for driver caching. + * To test for your own database, you may need to tweak getProperties(int) + * and add a couple of keys. see testOracle and testMySQL for an example. + * + * It would be much better to extend this testcase by using HSQL + * as the test db, so that a db is really used. + * + */ +public class SQLExecTest { + + // some database keys, see #getProperties(int) + public final static int NULL = 0; + public final static int ORACLE = 1; + public final static int MYSQL = 2; + + // keys used in properties. + public final static String DRIVER = "driver"; + public final static String USER = "user"; + public final static String PASSWORD = "password"; + public final static String URL = "url"; + public final static String PATH = "path"; + public final static String SQL = "sql"; + + @Before + public void setUp() throws Exception { + // make sure the cache is cleared. + JDBCTask.getLoaderMap().clear(); + } + + // simple test to ensure that the caching does work... + @Test + public void testDriverCaching(){ + SQLExec sql = createTask(getProperties(NULL)); + assertTrue(!SQLExec.getLoaderMap().containsKey(NULL_DRIVER)); + try { + sql.execute(); + fail("BuildException should have been thrown"); + } catch (BuildException e){ + assertContains("No suitable Driver", e.getMessage()); + } + assertTrue(SQLExec.getLoaderMap().containsKey(NULL_DRIVER)); + assertSame(sql.getLoader(), JDBCTask.getLoaderMap().get(NULL_DRIVER)); + ClassLoader loader1 = sql.getLoader(); + + // 2nd run.. + sql = createTask(getProperties(NULL)); + // the driver must still be cached. + assertTrue(JDBCTask.getLoaderMap().containsKey(NULL_DRIVER)); + try { + sql.execute(); + } catch (BuildException e){ + assertTrue(e.getCause().getMessage().indexOf("No suitable Driver") != -1); + } + assertTrue(JDBCTask.getLoaderMap().containsKey(NULL_DRIVER)); + assertSame(sql.getLoader(), JDBCTask.getLoaderMap().get(NULL_DRIVER)); + assertSame(loader1, sql.getLoader()); + } + + @Test + public void testNull() throws Exception { + doMultipleCalls(1000, NULL, true, true); + } + + @Ignore + @Test + public void testOracle(){ + doMultipleCalls(1000, ORACLE, true, false); + } + + @Ignore + @Test + public void testMySQL(){ + doMultipleCalls(1000, MYSQL, true, false); + } + + + /** + * run a sql tasks multiple times. + * @param calls number of times to execute the task + * @param database the database to execute on. + * @param caching should caching be enabled ? + * @param catchexception true to catch exception for each call, false if not. + */ + protected void doMultipleCalls(int calls, int database, boolean caching, boolean catchexception){ + Properties props = getProperties(database); + for (int i = 0; i < calls; i++){ + SQLExec sql = createTask(props); + sql.setCaching(caching); + try { + sql.execute(); + } catch (BuildException e){ + if (!catchexception){ + throw e; + } + } + } + } + + /** + * Create a task from a set of properties + * @see #getProperties(int) + */ + protected SQLExec createTask(Properties props){ + SQLExec sql = new SQLExec(); + sql.setProject( new Project() ); + sql.setDriver( props.getProperty(DRIVER) ); + sql.setUserid( props.getProperty(USER) ); + sql.setPassword( props.getProperty(PASSWORD) ); + sql.setUrl( props.getProperty(URL) ); + sql.createClasspath().setLocation( new File(props.getProperty(PATH)) ); + sql.addText( props.getProperty(SQL) ); + return sql; + } + + /** + * try to find the path from a resource (jar file or directory name) + * so that it can be used as a classpath to load the resource. + */ + protected String findResourcePath(String resource){ + resource = resource.replace('.', '/') + ".class"; + URL url = getClass().getClassLoader().getResource(resource); + if (url == null) { + return null; + } + String u = url.toString(); + if (u.startsWith("jar:file:")) { + int pling = u.indexOf("!"); + return u.substring("jar:file:".length(), pling); + } else if (u.startsWith("file:")) { + int tail = u.indexOf(resource); + return u.substring("file:".length(), tail); + } + return null; + } + + /** + * returns a configuration associated to a specific database. + * If you want to test on your specific base, you'd better + * tweak this to make it run or add your own database. + * The driver lib should be dropped into the system classloader. + */ + protected Properties getProperties(int database){ + Properties props = null; + switch (database){ + case ORACLE: + props = getProperties("oracle.jdbc.driver.OracleDriver", "test", "test", "jdbc:oracle:thin:@127.0.0.1:1521:orcl"); + break; + case MYSQL: + props = getProperties("org.gjt.mm.mysql.Driver", "test", "test", "jdbc:mysql://127.0.0.1:3306/test"); + break; + case NULL: + default: + props = getProperties(NULL_DRIVER, "test", "test", "jdbc:database://hostname:port/name"); + } + // look for the driver path... + String path = findResourcePath(props.getProperty(DRIVER)); + props.put(PATH, path); + props.put(SQL, "create table OOME_TEST(X INTEGER NOT NULL);\ndrop table if exists OOME_TEST;"); + return props; + } + + /** helper method to build properties */ + protected Properties getProperties(String driver, String user, String pwd, String url){ + Properties props = new Properties(); + props.put(DRIVER, driver); + props.put(USER, user); + props.put(PASSWORD, pwd); + props.put(URL, url); + return props; + } + + +//--- NULL JDBC driver just for simple test since there are no db driver +// available as a default in Ant :) + + public final static String NULL_DRIVER = NullDriver.class.getName(); + + public static class NullDriver implements Driver { + public Connection connect(String url, Properties info) + throws SQLException { + return null; + } + + public boolean acceptsURL(String url) throws SQLException { + return false; + } + + public DriverPropertyInfo[] getPropertyInfo(String url, Properties info) + throws SQLException { + return new DriverPropertyInfo[0]; + } + + public int getMajorVersion() { + return 0; + } + + public int getMinorVersion() { + return 0; + } + + public boolean jdbcCompliant() { + return false; + } + + public Logger getParentLogger() /*throws SQLFeatureNotSupportedException*/ { + return Logger.getAnonymousLogger(); + } + } + + @Test + public void testLastDelimiterPositionNormalModeStrict() { + SQLExec s = new SQLExec(); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer(), null)); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer("GO"), null)); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer("; "), null)); + assertEquals(2, + s.lastDelimiterPosition(new StringBuffer("ab;"), null)); + s.setDelimiter("GO"); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer("GO "), null)); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer("go"), null)); + assertEquals(0, + s.lastDelimiterPosition(new StringBuffer("GO"), null)); + } + + @Test + public void testLastDelimiterPositionNormalModeNonStrict() { + SQLExec s = new SQLExec(); + s.setStrictDelimiterMatching(false); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer(), null)); + assertEquals(-1, + s.lastDelimiterPosition(new StringBuffer("GO"), null)); + assertEquals(0, + s.lastDelimiterPosition(new StringBuffer("; "), null)); + assertEquals(2, + s.lastDelimiterPosition(new StringBuffer("ab;"), null)); + s.setDelimiter("GO"); + assertEquals(0, + s.lastDelimiterPosition(new StringBuffer("GO "), null)); + assertEquals(0, + s.lastDelimiterPosition(new StringBuffer("go"), null)); + assertEquals(0, + s.lastDelimiterPosition(new StringBuffer("GO"), null)); + } + + @Test + public void testLastDelimiterPositionRowModeStrict() { + SQLExec s = new SQLExec(); + SQLExec.DelimiterType t = new SQLExec.DelimiterType(); + t.setValue("row"); + s.setDelimiterType(t); + assertEquals(-1, s.lastDelimiterPosition(null, "")); + assertEquals(-1, s.lastDelimiterPosition(null, "GO")); + assertEquals(-1, s.lastDelimiterPosition(null, "; ")); + assertEquals(1, s.lastDelimiterPosition(new StringBuffer("ab"), ";")); + s.setDelimiter("GO"); + assertEquals(-1, s.lastDelimiterPosition(null, "GO ")); + assertEquals(-1, s.lastDelimiterPosition(null, "go")); + assertEquals(0, s.lastDelimiterPosition(new StringBuffer("ab"), "GO")); + } + + @Test + public void testLastDelimiterPositionRowModeNonStrict() { + SQLExec s = new SQLExec(); + SQLExec.DelimiterType t = new SQLExec.DelimiterType(); + t.setValue("row"); + s.setDelimiterType(t); + s.setStrictDelimiterMatching(false); + assertEquals(-1, s.lastDelimiterPosition(null, "")); + assertEquals(-1, s.lastDelimiterPosition(null, "GO")); + assertEquals(0, s.lastDelimiterPosition(new StringBuffer("; "), "; ")); + assertEquals(1, s.lastDelimiterPosition(new StringBuffer("ab"), ";")); + s.setDelimiter("GO"); + assertEquals(1, + s.lastDelimiterPosition(new StringBuffer("abcd"), "GO ")); + assertEquals(0, s.lastDelimiterPosition(new StringBuffer("go"), "go")); + assertEquals(0, s.lastDelimiterPosition(new StringBuffer("ab"), "GO")); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java new file mode 100644 index 00000000..95585fde --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SignJarTest.java @@ -0,0 +1,139 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.JavaEnvUtils; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Testcase for the Signjar task + * + */ +public class SignJarTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/signjar.xml"); + } + + /** + * check for being offline + * @return true if the system property "offline" is "true" + */ + private boolean isOffline() { + return Boolean.getBoolean("offline"); + } + + @Test + public void testSigFile() { + buildRule.executeTarget("sigfile"); + SignJarChild sj = new SignJarChild(); + sj.setAlias("testonly"); + sj.setKeystore("testkeystore"); + sj.setStorepass("apacheant"); + File jar = new File(buildRule.getProject().getProperty("test.jar")); + sj.setJar(jar); + assertFalse("mustn't find signature without sigfile attribute", + sj.isSigned()); + sj.setSigfile("TEST"); + assertTrue("must find signature with sigfile attribute", + sj.isSigned()); + } + + @Test + public void testInvalidChars() { + buildRule.executeTarget("invalidchars"); + SignJarChild sj = new SignJarChild(); + sj.setAlias("test@nly"); + sj.setKeystore("testkeystore"); + sj.setStorepass("apacheant"); + File jar = new File(buildRule.getProject().getProperty("test.jar")); + sj.setJar(jar); + assertTrue(sj.isSigned()); + } + + /** + * subclass in order to get access to protected isSigned method if + * tests and task come from different classloaders. + */ + private static class SignJarChild extends SignJar { + public boolean isSigned() { + return isSigned(jar); + } + } + + @Test + public void testURLKeystoreFile() { + buildRule.executeTarget("urlKeystoreFile"); + } + + @Test + public void testURLKeystoreHTTP() { + Assume.assumeFalse("Test is set offline", isOffline()); + buildRule.executeTarget("urlKeystoreHTTP"); + } + + @Test + public void testTsaLocalhost() { + Assume.assumeTrue("Only runs on Java 1.5+", JavaEnvUtils.getJavaVersionNumber()>=15); + try { + buildRule.executeTarget("testTsaLocalhost"); + fail("Should have thrown exception - no TSA at localhost:0"); + } catch(BuildException ex) { + assertEquals("jarsigner returned: 1", ex.getMessage()); + } + } + + /** + * @see <a href="https://issues.apache.org/bugzilla/show_bug.cgi?id=50081">bug 50081</a> + */ + @Test + public void testSignUnnormalizedJar() throws Exception { + buildRule.executeTarget("jar"); + File testJar = new File(buildRule.getProject().getProperty("test.jar")); + File testJarParent = testJar.getParentFile(); + File f = new File(testJarParent, + "../" + testJarParent.getName() + "/" + + testJar.getName()); + assertFalse(testJar.equals(f)); + assertEquals(testJar.getCanonicalPath(), f.getCanonicalPath()); + SignJar s = new SignJar(); + s.setProject(buildRule.getProject()); + s.setJar(f); + s.setAlias("testonly"); + s.setStorepass("apacheant"); + s.setKeystore("testkeystore"); + s.execute(); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java new file mode 100644 index 00000000..d1487df9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SleepTest.java @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class SleepTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/"; + private final static int ERROR_RANGE=1000; + + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "sleep.xml"); + } + + @Test + public void test1() { + Timer timer=new Timer(); + buildRule.executeTarget("test1"); + timer.stop(); + assertTrue(timer.time()>=0); + } + + @Test + public void test2() { + Timer timer=new Timer(); + buildRule.executeTarget("test2"); + timer.stop(); + assertTrue(timer.time()>=0); + } + + @Test + public void test3() { + Timer timer=new Timer(); + buildRule.executeTarget("test3"); + timer.stop(); + assertTrue(timer.time()>=(2000-ERROR_RANGE)); + } + + @Test + public void test4() { + Timer timer=new Timer(); + buildRule.executeTarget("test3"); + timer.stop(); + assertTrue(timer.time()>=(2000-ERROR_RANGE) && timer.time()<60000); + } + + @Test + public void test5() { + try { + buildRule.executeTarget("test5"); + fail("Negative sleep periods are not supported"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test6() { + Timer timer=new Timer(); + buildRule.executeTarget("test6"); + timer.stop(); + assertTrue(timer.time()<2000); + } + + + /** + * inner timer class + */ + private static class Timer { + long start=0; + long stop=0; + + public Timer() { + start(); + } + + public void start() { + start=System.currentTimeMillis(); + } + + public void stop() { + stop=System.currentTimeMillis(); + } + + public long time() { + return stop-start; + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java new file mode 100644 index 00000000..24c4e9de --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/StyleTest.java @@ -0,0 +1,225 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + + +import java.io.File; +import java.io.IOException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + + +/** + * TestCases for {@link XSLTProcess} task. + * TODO merge with {@link org.apache.tools.ant.taskdefs.optional.XsltTest}? + * @version 2003-08-05 + */ +public class StyleTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() throws Exception { + buildRule.configureProject("src/etc/testcases/taskdefs/style/build.xml"); + } + + @Test + public void testStyleIsSet() throws Exception { + + try { + buildRule.executeTarget("testStyleIsSet"); + fail("Must throws a BuildException: no stylesheet specified"); + } catch (BuildException ex) { + assertEquals("specify the stylesheet either as a filename in style attribute or as a nested resource", + ex.getMessage()); + } + } + + @Test + public void testTransferParameterSet() throws Exception { + expectFileContains("testTransferParameterSet", // target + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", // file + "set='myvalue'"); // exptected string + } + + @Test + public void testTransferParameterEmpty() throws Exception { + expectFileContains("testTransferParameterEmpty", + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", + "empty=''"); + } + + @Test + public void testTransferParameterUnset() throws Exception { + expectFileContains("testTransferParameterUnset", + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", + "undefined='${value}'"); + } + + @Test + public void testTransferParameterUnsetWithIf() throws Exception { + expectFileContains("testTransferParameterUnsetWithIf", + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", + "undefined='undefined default value'"); + } + + @Test + public void testNewerStylesheet() throws Exception { + expectFileContains("testNewerStylesheet", + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", + "new-value"); + } + + @Test + public void testDefaultMapper() throws Exception { + testDefaultMapper("testDefaultMapper"); + } + + @Test + public void testExplicitFileset() throws Exception { + testDefaultMapper("testExplicitFileset"); + } + + public void testDefaultMapper(String target) throws Exception { + assertTrue(!( + new File(buildRule.getOutputDir().getAbsoluteFile(), "data.html").exists())); + expectFileContains(target, + buildRule.getOutputDir().getAbsoluteFile() + "/data.html", + "set='myvalue'"); + } + + @Test + public void testCustomMapper() throws Exception { + assertTrue(!new File(buildRule.getOutputDir().getAbsoluteFile(), "out.xml").exists()); + expectFileContains("testCustomMapper", + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", + "set='myvalue'"); + } + + @Test + public void testTypedMapper() throws Exception { + assertTrue(!new File(buildRule.getOutputDir().getAbsoluteFile(), "out.xml").exists()); + expectFileContains("testTypedMapper", + buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", + "set='myvalue'"); + } + + @Test + public void testDirectoryHierarchyWithDirMatching() throws Exception { + buildRule.executeTarget("testDirectoryHierarchyWithDirMatching"); + assertTrue(new File(buildRule.getOutputDir().getAbsoluteFile(), "dest/level1/data.html") + .exists()); + } + + @Test + public void testDirsWithSpaces() throws Exception { + buildRule.executeTarget("testDirsWithSpaces"); + assertTrue(new File(buildRule.getOutputDir().getAbsoluteFile(), "d est/data.html") + .exists()); + } + + @Test + public void testWithStyleAttrAndResource() { + try { + buildRule.executeTarget("testWithStyleAttrAndResource"); + fail("Must throws a BuildException"); + } catch (BuildException ex) { + assertEquals("specify the stylesheet either as a filename in style attribute or as a " + + "nested resource but not as both", ex.getMessage()); + } + } + + @Test + public void testWithFileResource() throws Exception { + expectFileContains("testWithFileResource", buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", "set='value'"); + } + + @Test + public void testWithUrlResource() throws Exception { + expectFileContains("testWithUrlResource", buildRule.getOutputDir().getAbsoluteFile() + "/out.xml", "set='value'"); + } + + @Test + public void testFilenameAsParam() throws Exception { + buildRule.executeTarget("testFilenameAsParam"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/one.txt", "filename='one.xml'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/two.txt", "filename='two.xml'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/three.txt", "filename='three.xml'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/dir/four.txt", "filename='four.xml'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/dir/four.txt", "filedir ='-not-set-'"); + } + + @Test + public void testFilenameAsParamNoSetting() throws Exception { + buildRule.executeTarget("testFilenameAsParamNoSetting"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/one.txt", "filename='-not-set-'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/two.txt", "filename='-not-set-'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/three.txt", "filename='-not-set-'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/dir/four.txt", "filename='-not-set-'"); + } + + @Test + public void testFilenameAndFiledirAsParam() throws Exception { + buildRule.executeTarget("testFilenameAndFiledirAsParam"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/one.txt", "filename='one.xml'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/one.txt", "filedir ='.'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/dir/four.txt", "filename='four.xml'"); + assertFileContains(buildRule.getOutputDir().getAbsoluteFile() + "/dir/four.txt", "filedir ='dir'"); + } + + + // ************* copied from ConcatTest ************* + + // ------------------------------------------------------ + // Helper methods - should be in BuildFileTest + // ----------------------------------------------------- + + private String getFileString(String filename) + throws IOException + { + return FileUtilities.getFileContents(new File(filename)); + } + + private void expectFileContains( + String target, String filename, String contains) + throws IOException + { + buildRule.executeTarget(target); + assertFileContains(filename, contains); + } + + private void assertFileContains(String filename, String contains) throws IOException { + String content = getFileString(filename); + assertTrue( + "expecting file " + filename + + " to contain " + contains + + " but got " + content, + content.indexOf(contains) > -1); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SubAntTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SubAntTest.java new file mode 100644 index 00000000..58ee4f3e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SubAntTest.java @@ -0,0 +1,161 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.File; + +import junit.framework.AssertionFailedError; + +import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.BuildListener; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +public class SubAntTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/subant.xml"); + } + + @Test + public void testnodirs() { + buildRule.executeTarget("testnodirs"); + assertEquals("No sub-builds to iterate on",buildRule.getLog()); + } + + // target must be specified + @Test + public void testgenericantfile() { + File dir1 = buildRule.getProject().resolveFile("."); + File dir2 = buildRule.getProject().resolveFile("subant/subant-test1"); + File dir3 = buildRule.getProject().resolveFile("subant/subant-test2"); + + testBaseDirs("testgenericantfile", + new String[] { dir1.getAbsolutePath(), + dir2.getAbsolutePath(), + dir3.getAbsolutePath() + + }); + } + + @Test + public void testantfile() { + File dir1 = buildRule.getProject().resolveFile("."); + // basedir of subant/subant-test1/subant.xml is .. + // therefore we expect here the subant/subant-test1 subdirectory + File dir2 = buildRule.getProject().resolveFile("subant/subant-test1"); + // basedir of subant/subant-test2/subant.xml is .. + // therefore we expect here the subant subdirectory + File dir3 = buildRule.getProject().resolveFile("subant"); + + testBaseDirs("testantfile", + new String[] { dir1.getAbsolutePath(), + dir2.getAbsolutePath(), + dir3.getAbsolutePath() + + }); + + } + + @Test + public void testMultipleTargets() { + buildRule.executeTarget("multipleTargets"); + assertContains("test1-one", buildRule.getLog()); + assertContains("test1-two", buildRule.getLog()); + assertContains("test2-one", buildRule.getLog()); + assertContains("test2-two", buildRule.getLog()); + } + + @Test + public void testMultipleTargetsOneDoesntExist_FOEfalse() { + buildRule.executeTarget("multipleTargetsOneDoesntExist_FOEfalse"); + assertContains("Target \"three\" does not exist in the project \"subant\"", buildRule.getLog()); + } + + @Test + public void testMultipleTargetsOneDoesntExist_FOEtrue() { + try { + buildRule.executeTarget("multipleTargetsOneDoesntExist_FOEtrue"); + fail("BuildException expected: Calling not existent target"); + } catch (BuildException ex) { + assertContains("Target \"three\" does not exist in the project \"subant\"", ex.getMessage()); + } + } + + protected void testBaseDirs(String target, String[] dirs) { + SubAntTest.BasedirChecker bc = new SubAntTest.BasedirChecker(dirs); + buildRule.getProject().addBuildListener(bc); + buildRule.executeTarget(target); + AssertionFailedError ae = bc.getError(); + if (ae != null) { + throw ae; + } + buildRule.getProject().removeBuildListener(bc); + } + + private class BasedirChecker implements BuildListener { + private String[] expectedBasedirs; + private int calls = 0; + private AssertionFailedError error; + + BasedirChecker(String[] dirs) { + expectedBasedirs = dirs; + } + + public void buildStarted(BuildEvent event) {} + public void buildFinished(BuildEvent event) {} + public void targetFinished(BuildEvent event){} + public void taskStarted(BuildEvent event) {} + public void taskFinished(BuildEvent event) {} + public void messageLogged(BuildEvent event) {} + + public void targetStarted(BuildEvent event) { + if (event.getTarget().getName().equals("")) { + return; + } + if (error == null) { + try { + assertEquals(expectedBasedirs[calls++], + event.getProject().getBaseDir().getAbsolutePath()); + } catch (AssertionFailedError e) { + error = e; + } + } + } + + AssertionFailedError getError() { + return error; + } + + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SyncTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SyncTest.java new file mode 100644 index 00000000..93431dcb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/SyncTest.java @@ -0,0 +1,148 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertTrue; + +public class SyncTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/sync.xml"); + } + + @Test + public void testSimpleCopy() { + buildRule.executeTarget("simplecopy"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsPresent(d); + assertTrue(buildRule.getFullLog().indexOf("dangling") == -1); + } + + @Test + public void testEmptyCopy() { + buildRule.executeTarget("emptycopy"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsNotPresent(d); + String c = buildRule.getProject().getProperty("dest") + "/a/b/c"; + assertFileIsNotPresent(c); + assertTrue(buildRule.getFullLog().indexOf("dangling") == -1); + } + + @Test + public void testEmptyDirCopy() { + buildRule.executeTarget("emptydircopy"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsNotPresent(d); + String c = buildRule.getProject().getProperty("dest") + "/a/b/c"; + assertFileIsPresent(c); + assertTrue(buildRule.getFullLog().indexOf("dangling") == -1); + } + + @Test + public void testCopyAndRemove() { + testCopyAndRemove("copyandremove"); + } + + @Test + public void testCopyAndRemoveWithFileList() { + testCopyAndRemove("copyandremove-with-filelist"); + } + + @Test + public void testCopyAndRemoveWithZipfileset() { + testCopyAndRemove("copyandremove-with-zipfileset"); + } + + private void testCopyAndRemove(String target) { + buildRule.executeTarget(target); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsPresent(d); + String f = buildRule.getProject().getProperty("dest") + "/e/f"; + assertFileIsNotPresent(f); + assertTrue(buildRule.getFullLog().indexOf("Removing orphan file:") > -1); + assertContains("Removed 1 dangling file from", buildRule.getFullLog()); + assertContains("Removed 1 dangling directory from", buildRule.getFullLog()); + } + + @Test + public void testCopyAndRemoveEmptyPreserve() { + buildRule.executeTarget("copyandremove-emptypreserve"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsPresent(d); + String f = buildRule.getProject().getProperty("dest") + "/e/f"; + assertFileIsNotPresent(f); + assertTrue(buildRule.getFullLog().indexOf("Removing orphan file:") > -1); + assertContains("Removed 1 dangling file from", buildRule.getFullLog()); + assertContains("Removed 1 dangling directory from", buildRule.getFullLog()); + } + + @Test + public void testEmptyDirCopyAndRemove() { + buildRule.executeTarget("emptydircopyandremove"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsNotPresent(d); + String c = buildRule.getProject().getProperty("dest") + "/a/b/c"; + assertFileIsPresent(c); + String f = buildRule.getProject().getProperty("dest") + "/e/f"; + assertFileIsNotPresent(f); + assertTrue(buildRule.getFullLog().indexOf("Removing orphan directory:") > -1); + assertContains("NO dangling file to remove from", buildRule.getFullLog()); + assertContains("Removed 2 dangling directories from", buildRule.getFullLog()); + } + + @Test + public void testCopyNoRemove() { + buildRule.executeTarget("copynoremove"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsPresent(d); + String f = buildRule.getProject().getProperty("dest") + "/e/f"; + assertFileIsPresent(f); + assertTrue(buildRule.getFullLog().indexOf("Removing orphan file:") == -1); + } + + @Test + public void testCopyNoRemoveSelectors() { + buildRule.executeTarget("copynoremove-selectors"); + String d = buildRule.getProject().getProperty("dest") + "/a/b/c/d"; + assertFileIsPresent(d); + String f = buildRule.getProject().getProperty("dest") + "/e/f"; + assertFileIsPresent(f); + assertTrue(buildRule.getFullLog().indexOf("Removing orphan file:") == -1); + } + + public void assertFileIsPresent(String f) { + assertTrue("Expected file " + f, + buildRule.getProject().resolveFile(f).exists()); + } + + public void assertFileIsNotPresent(String f) { + assertTrue("Didn't expect file " + f, + !buildRule.getProject().resolveFile(f).exists()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TStampTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TStampTest.java new file mode 100644 index 00000000..ed7403c7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TStampTest.java @@ -0,0 +1,117 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.util.Calendar; +import java.util.TimeZone; +import java.util.Date; +import java.text.SimpleDateFormat; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Location; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * + */ +public class TStampTest { + + protected Tstamp tstamp; + protected Project project; + protected Location location; + + @Before + public void setUp() throws Exception { + location = new Location("test.xml"); + project = new Project(); + tstamp = new Tstamp(); + tstamp.setLocation(location); + tstamp.setProject(project); + } + + @Test + public void testTimeZone() throws Exception { + Tstamp.CustomFormat format = tstamp.createFormat(); + format.setProperty("today"); + format.setPattern("HH:mm:ss z"); + format.setTimezone("GMT"); + Date date = Calendar.getInstance().getTime(); + format.execute(project, date, location); + String today = project.getProperty("today"); + + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z"); + sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); + String expected = sdf.format(date); + + assertEquals(expected, today); + } + + /** + * verifies that custom props have priority over the + * originals + * @throws Exception + */ + @Test + public void testWriteOrder() throws Exception { + Tstamp.CustomFormat format = tstamp.createFormat(); + format.setProperty("TODAY"); + format.setPattern("HH:mm:ss z"); + format.setTimezone("GMT"); + Date date = Calendar.getInstance().getTime(); + format.execute(project, date, location); + String today = project.getProperty("TODAY"); + + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z"); + sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); + String expected = sdf.format(date); + + assertEquals(expected, today); + + } + + /** + * verifies that custom props have priority over the + * originals + * @throws Exception + */ + @Test + public void testPrefix() throws Exception { + tstamp.setPrefix("prefix"); + tstamp.execute(); + String prop= project.getProperty("prefix.DSTAMP"); + assertNotNull(prop); + } + + @Test + public void testFormatPrefix() throws Exception { + Tstamp.CustomFormat format = tstamp.createFormat(); + format.setProperty("format"); + format.setPattern("HH:mm:ss z"); + format.setTimezone("GMT"); + + tstamp.setPrefix("prefix"); + tstamp.execute(); + String prop= project.getProperty("prefix.format"); + assertNotNull(prop); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java new file mode 100644 index 00000000..c5ba1200 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TarTest.java @@ -0,0 +1,210 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.IOException; +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class TarTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/tar.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException expected: tar cannot include itself"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + File f + = new File(buildRule.getProject().getProperty("output"), "test5.tar"); + + if (!f.exists()) { + fail("Tarring a directory failed"); + } + } + + @Test + public void test6() { + try { + buildRule.executeTarget("test6"); + fail("BuildException expected: Invalid value specified for longfile attribute."); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test7() { + test7("test7"); + } + + @Test + public void test7UsingPlainFileSet() { + test7("test7UsingPlainFileSet"); + } + + @Test + public void test7UsingFileList() { + test7("test7UsingFileList"); + } + + private void test7(String target) { + buildRule.executeTarget(target); + File f1 + = new File(buildRule.getProject().getProperty("output"), "untar/test7-prefix"); + + if (!(f1.exists() && f1.isDirectory())) { + fail("The prefix attribute is not working properly."); + } + + File f2 + = new File(buildRule.getProject().getProperty("output"), "untar/test7dir"); + + if (!(f2.exists() && f2.isDirectory())) { + fail("The prefix attribute is not working properly."); + } + } + + @Test + public void test8() { + test8("test8"); + } + + @Test + public void test8UsingZipFileset() { + test8("test8UsingZipFileset"); + } + + @Test + public void test8UsingZipFilesetSrc() { + test8("test8UsingZipFilesetSrc"); + } + + @Test + public void test8UsingTarFilesetSrc() { + test8("test8UsingTarFilesetSrc"); + } + + @Test + public void test8UsingZipEntry() { + test8("test8UsingZipEntry"); + } + + private void test8(String target) { + buildRule.executeTarget(target); + File f1 + = new File(buildRule.getProject().getProperty("output"), "untar/test8.xml"); + if (! f1.exists()) { + fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work propertly"); + } + } + + @Test + public void test9() { + try { + buildRule.executeTarget("test9"); + fail("BuildException expected: Invalid value specified for compression attribute."); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test10() { + buildRule.executeTarget("test10"); + File f1 + = new File(buildRule.getProject().getProperty("output"), "untar/test10.xml"); + if (! f1.exists()) { + fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work propertly"); + } + } + + @Test + public void test11() { + buildRule.executeTarget("test11"); + File f1 + = new File(buildRule.getProject().getProperty("output"), "untar/test11.xml"); + if (! f1.exists()) { + fail("The fullpath attribute or the preserveLeadingSlashes attribute does not work propertly"); + } + } + + @Test + public void testGZipResource() throws IOException { + buildRule.executeTarget("testGZipResource"); + assertEquals(FileUtilities.getFileContents(buildRule.getProject().resolveFile("../asf-logo.gif")), + FileUtilities.getFileContents(new File(buildRule.getProject().getProperty("output"), "untar/asf-logo.gif.gz"))); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java new file mode 100644 index 00000000..eaa8a667 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefTest.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + */ +public class TaskdefTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/taskdef.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException expected: classname specified doesn't exist"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test5() { + try { + buildRule.executeTarget("test5"); + fail("BuildException expected: No public execute() in " + Project.class); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test5a() { + buildRule.executeTarget("test5a"); + } + + @Test + public void test6() { + buildRule.executeTarget("test6"); + assertEquals("simpletask: worked", buildRule.getLog()); + } + + @Test + public void test7() { + buildRule.executeTarget("test7"); + assertEquals("worked", buildRule.getLog()); + } + + @Test + public void testGlobal() { + buildRule.executeTarget("testGlobal"); + assertEquals("worked", buildRule.getLog()); + } + + @Test + public void testOverride() { + buildRule.executeTarget("testOverride"); + String log = buildRule.getLog(); + assertTrue("override warning sent", + log.indexOf("Trying to override old definition of task copy") > -1); + assertTrue("task inside target worked", + log.indexOf("In target") > -1); + assertTrue("task inside target worked", + log.indexOf("In TaskContainer") > -1); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefsTest.java new file mode 100644 index 00000000..9316059c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TaskdefsTest.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileTest; + +/** + * @deprecated use {@link org.apache.tools.ant.BuildFileRule} instead. + */ +public abstract class TaskdefsTest extends BuildFileTest { + + public TaskdefsTest(String name) { + super(name); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TestProcess.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TestProcess.java new file mode 100644 index 00000000..062003fa --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TestProcess.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.junit.internal.AssumptionViolatedException; + +/** + * Interactive Testcase for Processdestroyer. + * + */ +public class TestProcess + implements Runnable +{ + private boolean run = true; + private boolean done = false; + + public void shutdown() + { + if (!done) + { + System.out.println("shutting down TestProcess"); + run = false; + + synchronized(this) + { + while (!done) + { + try { + wait(); + } catch (InterruptedException ie) { + throw new AssumptionViolatedException("Thread interrupted", ie); + } + } + } + + System.out.println("TestProcess shut down"); + } + } + + public void run() + { + for (int i = 0; i < 5 && run; i++) + { + System.out.println(Thread.currentThread().getName()); + + try { + Thread.sleep(2000); + } catch (InterruptedException ie) { + throw new AssumptionViolatedException("Thread interrupted", ie); + } + } + + synchronized(this) + { + done = true; + notifyAll(); + } + } + + public Thread getShutdownHook() + { + return new TestProcessShutdownHook(); + } + + private class TestProcessShutdownHook + extends Thread + { + public void run() + { + shutdown(); + } + } + + public static void main(String[] args) + { + TestProcess tp = new TestProcess(); + new Thread(tp, "TestProcess thread").start(); + Runtime.getRuntime().addShutdownHook(tp.getShutdownHook()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TimeProcess.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TimeProcess.java new file mode 100644 index 00000000..eee15d12 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TimeProcess.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +/** + * Helper class for ExecuteWatchdogTest and ExecuteJavaTest. + * + * <p>Used to be an inner class of ExecuteWatchdogTest. + * + */ +public class TimeProcess { + public static void main(String[] args) throws Exception { + int time = Integer.parseInt(args[0]); + if (time < 1) { + throw new IllegalArgumentException("Invalid time: " + time); + } + Thread.sleep(time); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TouchTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TouchTest.java new file mode 100644 index 00000000..0a968b25 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TouchTest.java @@ -0,0 +1,211 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.util.FileUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class TouchTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + private static String TOUCH_FILE = "src/etc/testcases/taskdefs/touchtest"; + + /** Utilities used for file operations */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/touch.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + public long getTargetTime() { + + File file = new File(System.getProperty("root"), TOUCH_FILE); + if(!file.exists()) { + throw new BuildException("failed to touch file " + file); + } + return file.lastModified(); + } + + /** + * No real test, simply checks whether the dateformat without + * seconds is accepted - by erroring out otherwise. + */ + @Test + public void testNoSeconds() { + buildRule.executeTarget("noSeconds"); + getTargetTime(); + } + + /** + * No real test, simply checks whether the dateformat with + * seconds is accepted - by erroring out otherwise. + */ + @Test + public void testSeconds() { + buildRule.executeTarget("seconds"); + getTargetTime(); + } + /** + * verify that the millis test sets things up + */ + @Test + public void testMillis() { + touchFile("testMillis", 662256000000L); + } + + /** + * verify that the default value defaults to now + */ + @Test + public void testNow() { + long now=System.currentTimeMillis(); + buildRule.executeTarget("testNow"); + long time = getTargetTime(); + assertTimesNearlyMatch(time,now,5000); + } + /** + * verify that the millis test sets things up + */ + @Test + public void test2000() { + touchFile("test2000", 946080000000L); + } + + /** + * test the file list + */ + @Test + public void testFilelist() { + touchFile("testFilelist", 662256000000L); + } + + /** + * test the file set + */ + @Test + public void testFileset() { + touchFile("testFileset", 946080000000L); + } + + /** + * test the resource collection + */ + @Test + public void testResourceCollection() { + touchFile("testResourceCollection", 1662256000000L); + } + + /** + * test the mapped file set + */ + @Test + public void testMappedFileset() { + buildRule.executeTarget("testMappedFileset"); + } + + /** + * test the explicit mapped file set + */ + @Test + public void testExplicitMappedFileset() { + buildRule.executeTarget("testExplicitMappedFileset"); + } + + /** + * test the mapped file list + */ + @Test + public void testMappedFilelist() { + buildRule.executeTarget("testMappedFilelist"); + } + + /** + * test the pattern attribute + */ + @Test + public void testGoodPattern() { + buildRule.executeTarget("testGoodPattern"); + } + + /** + * test the pattern attribute again + */ + @Test + public void testBadPattern() { + try { + buildRule.executeTarget("testBadPattern"); + fail("No parsing exception thrown"); + } catch (BuildException ex) { + assertContains("Unparseable", ex.getMessage()); + } + + } + + /** + * run a target to touch the test file; verify the timestamp is as expected + * @param targetName + * @param timestamp + */ + private void touchFile(String targetName, long timestamp) { + buildRule.executeTarget(targetName); + long time = getTargetTime(); + assertTimesNearlyMatch(timestamp, time); + } + + /** + * assert that two times are within the current FS granularity; + * @param timestamp + * @param time + */ + public void assertTimesNearlyMatch(long timestamp,long time) { + long granularity= FILE_UTILS.getFileTimestampGranularity(); + assertTimesNearlyMatch(timestamp, time, granularity); + } + + /** + * assert that two times are within a specified range + * @param timestamp + * @param time + * @param range + */ + private void assertTimesNearlyMatch(long timestamp, long time, long range) { + assertTrue("Time " + timestamp + " is not within " + range + " ms of " + + time, (Math.abs(time - timestamp) <= range)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TypeAdapterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TypeAdapterTest.java new file mode 100644 index 00000000..3488f399 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TypeAdapterTest.java @@ -0,0 +1,176 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.lang.reflect.Method; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.TypeAdapter; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +/** + */ +public class TypeAdapterTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/typeadapter.xml"); + } + + @Test + public void testTaskAdapter() { + buildRule.executeTarget("taskadapter"); + assertContains("MyExec called", buildRule.getLog()); + } + + @Test + public void testRunAdapter() { + buildRule.executeTarget("runadapter"); + assertContains("MyRunnable called", buildRule.getLog()); + } + + @Test + public void testRunAdapterError() { + try { + buildRule.executeTarget("runadaptererror"); + fail("BuildException expected: no public run method"); + } catch (BuildException ex) { + assertContains("No public run() method in", ex.getMessage()); + } + } + + @Test + public void testDelay() { + buildRule.executeTarget("delay"); + assertContains("MyTask called", buildRule.getLog()); + } + + @Test + public void testOnErrorReport() { + buildRule.executeTarget("onerror.report"); + assertContains("MyTaskNotPresent cannot be found", buildRule.getLog()); + } + + @Test + public void testOnErrorIgnore() { + buildRule.executeTarget("onerror.ignore"); + assertEquals("", buildRule.getLog()); + } + + public static class MyTask extends Task { + public void execute() { + log("MyTask called"); + } + } + + public static class MyExec { + private Project project; + public void setProject(Project project) { + this.project = project; + } + + public void execute() { + project.log("MyExec called"); + } + } + + public static class MyRunnable { + private Project project; + public void setProject(Project project) { + this.project = project; + } + + public void run() { + project.log("MyRunnable called"); + } + } + + public static class RunnableAdapter + extends Task implements TypeAdapter + { + private String execMethodName = "run"; + private Object proxy; + + public Method getExecuteMethod(Class proxyClass) { + try { + Method execMethod = proxyClass.getMethod(execMethodName); + if (!Void.TYPE.equals(execMethod.getReturnType())) { + String message = + "return type of " + execMethodName + "() should be " + + "void but was \"" + execMethod.getReturnType() + + "\" in " + + proxyClass; + log(message, Project.MSG_WARN); + } + return execMethod; + } catch (NoSuchMethodException e) { + String message = "No public "+ execMethodName + + "() method in " + + proxyClass; + log(message, Project.MSG_ERR); + throw new BuildException(message); + } + } + public void checkProxyClass(Class proxyClass) { + getExecuteMethod(proxyClass); + } + + public void setProxy(Object o) { + getExecuteMethod(o.getClass()); + this.proxy = o; + } + + public Object getProxy() { + return proxy; + } + + public void execute() { + getProject().setProjectReference(proxy); + Method executeMethod = getExecuteMethod(proxy.getClass()); + try { + executeMethod.invoke(proxy); + } catch (java.lang.reflect.InvocationTargetException ie) { + log("Error in " + proxy.getClass(), Project.MSG_ERR); + Throwable t = ie.getTargetException(); + if (t instanceof BuildException) { + throw ((BuildException) t); + } else { + throw new BuildException(t); + } + } catch (Exception ex) { + log("Error in " + proxy.getClass(), Project.MSG_ERR); + throw new BuildException(ex); + } + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TypedefTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TypedefTest.java new file mode 100644 index 00000000..bfc11dd4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/TypedefTest.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; + +/** + */ +public class TypedefTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/typedef.xml"); + } + + @Test + public void testEmpty() { + try { + buildRule.executeTarget("empty"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testNoName() { + try { + buildRule.executeTarget("noName"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testNoClassname() { + try { + buildRule.executeTarget("noClassname"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testClassNotFound() { + try { + buildRule.executeTarget("classNotFound"); + fail("BuildException expected: classname specified doesn't exist"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testGlobal() { + buildRule.executeTarget("testGlobal"); + assertEquals("", buildRule.getLog()); + Object ref = buildRule.getProject().getReferences().get("global"); + assertNotNull("ref is not null", ref); + assertEquals("org.example.types.TypedefTestType", + ref.getClass().getName()); + } + + @Test + public void testLocal() { + buildRule.executeTarget("testLocal"); + assertEquals("", buildRule.getLog()); + Object ref = buildRule.getProject().getReferences().get("local"); + assertNotNull("ref is not null", ref); + assertEquals("org.example.types.TypedefTestType", + ref.getClass().getName()); + } + + /** + * test to make sure that one can define a not present + * optional type twice and then have a valid definition. + */ + @Test + public void testDoubleNotPresent() { + buildRule.executeTarget("double-notpresent"); + assertContains("hi", buildRule.getLog()); + } + + @Test + public void testNoResourceOnErrorFailAll(){ + try { + buildRule.executeTarget("noresourcefailall"); + fail("BuildException expected: the requested resource does not exist"); + } catch (BuildException ex) { + assertContains("Could not load definitions from resource ", ex.getMessage()); + } + } + + @Test + public void testNoResourceOnErrorFail(){ + buildRule.executeTarget("noresourcefail"); + assertContains("Could not load definitions from resource ", buildRule.getLog()); + } + + @Test + public void testNoResourceOnErrorNotFail(){ + buildRule.executeTarget("noresourcenotfail"); + assertContains("Could not load definitions from resource ", buildRule.getLog()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UntarTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UntarTest.java new file mode 100644 index 00000000..e0f7eb2a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UntarTest.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + + +public class UntarTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/untar.xml"); + } + + @Test + public void testRealTest() throws java.io.IOException { + testLogoExtraction("realTest"); + } + + @Test + public void testRealGzipTest() throws java.io.IOException { + testLogoExtraction("realGzipTest"); + } + + @Test + public void testRealBzip2Test() throws java.io.IOException { + testLogoExtraction("realBzip2Test"); + } + + @Test + public void testTestTarTask() throws java.io.IOException { + testLogoExtraction("testTarTask"); + } + + @Test + public void testTestGzipTarTask() throws java.io.IOException { + testLogoExtraction("testGzipTarTask"); + } + + @Test + public void testTestBzip2TarTask() throws java.io.IOException { + testLogoExtraction("testBzip2TarTask"); + } + + @Test + public void testSrcDirTest() { + try { + buildRule.executeTarget("srcDirTest"); + fail("Src cannot be a directory."); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testEncoding() { + buildRule.executeTarget("encodingTest"); + String filename = buildRule.getProject().getProperty("output") + "/untartestout/foo"; + assertTrue("foo has been properly named", + buildRule.getProject().resolveFile(filename).exists()); + } + + @Test + public void testResourceCollection() throws java.io.IOException { + testLogoExtraction("resourceCollection"); + } + + private void testLogoExtraction(String target) throws java.io.IOException { + buildRule.executeTarget(target); + assertEquals(FileUtilities.getFileContents(buildRule.getProject().resolveFile("../asf-logo.gif")), + FileUtilities.getFileContents(new File(buildRule.getProject().getProperty("output"), "untar/asf-logo.gif"))); + + } + + @Test + public void testDocumentationClaimsOnCopy() { + buildRule.executeTarget("testDocumentationClaimsOnCopy"); + assertFalse(new File(buildRule.getProject().getProperty("output"), "untar/1/foo").exists()); + assertTrue(new File(buildRule.getProject().getProperty("output"), "untar/2/bar").exists()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java new file mode 100644 index 00000000..ad99620e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UnzipTest.java @@ -0,0 +1,250 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class UnzipTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/unzip.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + + @Test + public void testRealTest() throws java.io.IOException { + buildRule.executeTarget("realTest"); + assertLogoUncorrupted(); + } + + /** + * test that the logo gif file has not been corrupted + * @throws IOException + */ + private void assertLogoUncorrupted() throws IOException { + assertEquals(FileUtilities.getFileContents(buildRule.getProject().resolveFile("../asf-logo.gif")), + FileUtilities.getFileContents(new File(buildRule.getProject().getProperty("output"), "asf-logo.gif"))); + + } + + @Test + public void testTestZipTask() throws java.io.IOException { + buildRule.executeTarget("testZipTask"); + assertLogoUncorrupted(); + } + + @Test + public void testTestUncompressedZipTask() throws java.io.IOException { + buildRule.executeTarget("testUncompressedZipTask"); + assertLogoUncorrupted(); + } + + /* + * PR 11100 + */ + @Test + public void testPatternSetExcludeOnly() { + buildRule.executeTarget("testPatternSetExcludeOnly"); + assertFileMissing("1/foo is excluded", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("2/bar is not excluded", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } + + /* + * PR 11100 + */ + @Test + public void testPatternSetIncludeOnly() { + buildRule.executeTarget("testPatternSetIncludeOnly"); + assertFileMissing("1/foo is not included", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("2/bar is included", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } + + /* + * PR 11100 + */ + @Test + public void testPatternSetIncludeAndExclude() { + buildRule.executeTarget("testPatternSetIncludeAndExclude"); + assertFileMissing("1/foo is not included", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileMissing("2/bar is excluded", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } + + /* + * PR 38973 + */ + @Test + public void testTwoPatternSets() { + buildRule.executeTarget("testTwoPatternSets"); + assertFileMissing("1/foo is not included", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("2/bar is included", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } + + /* + * PR 38973 + */ + @Test + public void testTwoPatternSetsWithExcludes() { + buildRule.executeTarget("testTwoPatternSetsWithExcludes"); + assertFileMissing("1/foo is not included", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileMissing("2/bar is excluded", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } + + /* + * PR 16213 + */ + @Test + @Ignore("we lack a self extracting archive that we are allowed to distribute - see PR 49080") + public void testSelfExtractingArchive() { + // disabled because we lack a self extracting archive that we + // are allowed to distribute - see PR 49080 + buildRule.executeTarget("selfExtractingArchive"); + } + + + /* + * PR 20969 + */ + @Test + public void testPatternSetSlashOnly() { + buildRule.executeTarget("testPatternSetSlashOnly"); + assertFileMissing("1/foo is not included", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("\"2/bar is included", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } + + + /* + * PR 10504 + */ + @Test + public void testEncoding() { + buildRule.executeTarget("encodingTest"); + assertFileExists("foo has been properly named", buildRule.getProject().getProperty("output") + "/unziptestout/foo"); + } + + /* + * PR 21996 + */ + @Test + public void testFlattenMapper() { + buildRule.executeTarget("testFlattenMapper"); + assertFileMissing("1/foo is not flattened", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("foo is flattened", buildRule.getProject().getProperty("output") + "/unziptestout/foo"); + } + + /** + * assert that a file exists, relative to the project + * @param message message if there is no mpatch + * @param filename filename to resolve against the project + */ + private void assertFileExists(String message, String filename) { + assertTrue(message, + buildRule.getProject().resolveFile(filename).exists()); + } + + /** + * assert that a file doesnt exist, relative to the project + * + * @param message message if there is no mpatch + * @param filename filename to resolve against the project + */ + private void assertFileMissing(String message, String filename) { + assertTrue(message, + !buildRule.getProject().resolveFile(filename).exists()); + } + + /** + * PR 21996 + */ + @Test + public void testGlobMapper() { + buildRule.executeTarget("testGlobMapper"); + assertFileMissing("1/foo is not mapped", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("1/foo is mapped", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo.txt"); + } + + @Test + public void testTwoMappers() { + try { + buildRule.executeTarget("testTwoMappers"); + fail("BuildException expected: " + Expand.ERROR_MULTIPLE_MAPPERS); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void testResourceCollections() { + buildRule.executeTarget("testResourceCollection"); + assertFileExists("junit.jar has been extracted", + buildRule.getProject().getProperty("output") + "/unziptestout/junit/framework/Assert.class"); + } + + @Test + public void testDocumentationClaimsOnCopy() { + buildRule.executeTarget("testDocumentationClaimsOnCopy"); + assertFileMissing("1/foo is excluded", buildRule.getProject().getProperty("output") + "/unziptestout/1/foo"); + assertFileExists("2/bar is not excluded", buildRule.getProject().getProperty("output") + "/unziptestout/2/bar"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UpToDateTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UpToDateTest.java new file mode 100644 index 00000000..b9677c4b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/UpToDateTest.java @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assume.assumeTrue; + +public class UpToDateTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/uptodate.xml"); + buildRule.executeTarget("setUp"); + File srcDir = buildRule.getProject().resolveFile("source"); + assumeTrue("Could not change modification timestamp of source directory", + srcDir.setLastModified(srcDir.lastModified() + - (3 * FileUtils.getFileUtils().getFileTimestampGranularity()))); + } + + @After + public void tearDown() { + buildRule.executeTarget("tearDown"); + } + + @Test + public void testFilesetUpToDate() { + buildRule.executeTarget("testFilesetUpToDate"); + assertEquals("true", buildRule.getProject().getProperty("foo")); + } + + @Test + public void testFilesetOutOfDate() { + buildRule.executeTarget("testFilesetOutOfDate"); + assertNull(buildRule.getProject().getProperty("foo")); + } + + @Test + public void testRCUpToDate() { + buildRule.executeTarget("testRCUpToDate"); + assertEquals("true", buildRule.getProject().getProperty("foo")); + } + + @Test + public void testRCOutOfDate() { + buildRule.executeTarget("testRCOutOfDate"); + assertNull(buildRule.getProject().getProperty("foo")); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/WarTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/WarTest.java new file mode 100644 index 00000000..1513ac75 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/WarTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.File; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Testcase for the war task + * + */ +public class WarTest { + public static final String TEST_BUILD_FILE + = "src/etc/testcases/taskdefs/war.xml"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TEST_BUILD_FILE); + } + + /** + * Test direct dependency removal + */ + @Test + public void testLibRefs() { + buildRule.executeTarget("testlibrefs"); + File f = new File(buildRule.getOutputDir(), "WEB-INF/lib/war.xml"); + assertTrue("File has been put into lib", f.exists()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/WhichResourceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/WhichResourceTest.java new file mode 100644 index 00000000..8e282b3a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/WhichResourceTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; + +public class WhichResourceTest { + public static final String TEST_BUILD_FILE + = "src/etc/testcases/taskdefs/whichresource.xml"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject(TEST_BUILD_FILE); + } + + @Test + public void testClassname() { + buildRule.executeTarget("testClassname"); + assertNotNull(buildRule.getProject().getProperty("antmain")); + } + + @Test + public void testResourcename() { + buildRule.executeTarget("testResourcename"); + assertNotNull(buildRule.getProject().getProperty("defaults")); + } + + @Test + public void testResourcenameWithLeadingSlash() { + buildRule.executeTarget("testResourcenameWithLeadingSlash"); + assertNotNull(buildRule.getProject().getProperty("defaults")); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java new file mode 100644 index 00000000..89069173 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/XmlPropertyTest.java @@ -0,0 +1,376 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Properties; +import java.util.Vector; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + */ +public class XmlPropertyTest { + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/xmlproperty.xml"); + } + + @Test + public void testFile() { + testProperties("test"); + } + + @Test + public void testResource() { + testProperties("testResource"); + } + + private void testProperties(String target) { + buildRule.executeTarget(target); + assertEquals("true", buildRule.getProject().getProperty("root-tag(myattr)")); + assertEquals("Text", buildRule.getProject().getProperty("root-tag.inner-tag")); + assertEquals("val", + buildRule.getProject().getProperty("root-tag.inner-tag(someattr)")); + assertEquals("false", buildRule.getProject().getProperty("root-tag.a2.a3.a4")); + assertEquals("CDATA failed", + "<test>", buildRule.getProject().getProperty("root-tag.cdatatag")); + } + + @Test + public void testDTD() { + buildRule.executeTarget("testdtd"); + assertEquals("Text", buildRule.getProject().getProperty("root-tag.inner-tag")); + } + + @Test + public void testNone () throws IOException { + doTest("testNone", false, false, false, false, false); + } + + @Test + public void testKeeproot() throws IOException { + doTest("testKeeproot", true, false, false, false, false); + } + + @Test + public void testCollapse () throws IOException { + doTest("testCollapse", false, true, false, false, false); + } + + @Test + public void testSemantic () throws IOException { + doTest("testSemantic", false, false, true, false, false); + } + + @Test + public void testKeeprootCollapse () throws IOException { + doTest("testKeeprootCollapse", true, true, false, false, false); + } + + @Test + public void testKeeprootSemantic () throws IOException { + doTest("testKeeprootSemantic", true, false, true, false, false); + } + + @Test + public void testCollapseSemantic () throws IOException { + doTest("testCollapseSemantic", false, true, true, false, false); + } + + @Test + public void testKeeprootCollapseSemantic () throws IOException { + doTest("testKeeprootCollapseSemantic", true, true, true, false, false); + } + + @Test + public void testInclude () throws IOException { + doTest("testInclude", false, false, false, true, false); + } + + @Test + public void testSemanticInclude () throws IOException { + doTest("testSemanticInclude", false, false, true, true, false); + } + + @Test + public void testSemanticLocal () throws IOException { + doTest("testSemanticInclude", false, false, true, false, true); + } + + @Test + public void testNeedsCatalog() { + buildRule.executeTarget("testneedscat"); + assertEquals("true", buildRule.getProject().getProperty("skinconfig.foo")); + } + + /** + * Actually run a test, finding all input files (and corresponding + * goldfile) + */ + private void doTest(String msg, boolean keepRoot, boolean collapse, + boolean semantic, boolean include, boolean localRoot) throws IOException { + Enumeration iter = + getFiles(new File(System.getProperty("root"), "src/etc/testcases/taskdefs/xmlproperty/inputs")); + while (iter.hasMoreElements()) { + File inputFile = (File) iter.nextElement(); + // What's the working directory? If local, then its the + // folder of the input file. Otherwise, its the "current" dir.. + File workingDir; + if ( localRoot ) { + workingDir = inputFile.getParentFile(); + } else { + workingDir = FILE_UTILS.resolveFile(new File("."), "."); + } + + + File propertyFile = getGoldfile(inputFile, keepRoot, collapse, + semantic, include, localRoot); + if (!propertyFile.exists()) { +// System.out.println("Skipping as " +// + propertyFile.getAbsolutePath() +// + ") doesn't exist."); + continue; + } + + // System.out.println(msg + " (" + propertyFile.getName() + ") in (" + workingDir + ")"); + + Project p = new Project(); + + XmlProperty xmlproperty = new XmlProperty(); + xmlproperty.setProject(p); + xmlproperty.setFile(inputFile); + + xmlproperty.setKeeproot(keepRoot); + xmlproperty.setCollapseAttributes(collapse); + xmlproperty.setSemanticAttributes(semantic); + xmlproperty.setIncludeSemanticAttribute(include); + xmlproperty.setRootDirectory(workingDir); + + // Set a property on the project to make sure that loading + // a property with the same name from an xml file will + // *not* change it. + p.setNewProperty("override.property.test", "foo"); + + xmlproperty.execute(); + + Properties props = new Properties(); + props.load(new FileInputStream(propertyFile)); + + //printProperties(p.getProperties()); + + ensureProperties(msg, inputFile, workingDir, p, props); + ensureReferences(msg, inputFile, p.getReferences()); + + } + } + + /** + * Make sure every property loaded from the goldfile was also + * read from the XmlProperty. We could try and test the other way, + * but some other properties may get set in the XmlProperty due + * to generic Project/Task configuration. + */ + private static void ensureProperties (String msg, File inputFile, + File workingDir, Project p, + Properties properties) { + Hashtable xmlproperties = p.getProperties(); + // Every key identified by the Properties must have been loaded. + Enumeration propertyKeyEnum = properties.propertyNames(); + while(propertyKeyEnum.hasMoreElements()){ + String currentKey = propertyKeyEnum.nextElement().toString(); + String assertMsg = msg + "-" + inputFile.getName() + + " Key=" + currentKey; + + String propertyValue = properties.getProperty(currentKey); + + String xmlValue = (String)xmlproperties.get(currentKey); + + if (propertyValue.startsWith("ID.")) { + // The property is an id's thing -- either a property + // or a path. We need to make sure + // that the object was created with the given id. + // We don't have an adequate way of testing the actual + // *value* of the Path object, though... + String id = currentKey; + Object obj = p.getReferences().get(id); + + if ( obj == null ) { + fail(assertMsg + " Object ID does not exist."); + } + + // What is the property supposed to be? + propertyValue = + propertyValue.substring(3, propertyValue.length()); + if (propertyValue.equals("path")) { + if (!(obj instanceof Path)) { + fail(assertMsg + " Path ID is a " + + obj.getClass().getName()); + } + } else { + assertEquals(assertMsg, propertyValue, obj.toString()); + } + + } else { + + if (propertyValue.startsWith("FILE.")) { + // The property is the name of a file. We are testing + // a location attribute, so we need to resolve the given + // file name in the provided folder. + String fileName = + propertyValue.substring(5, propertyValue.length()); + File f = new File(workingDir, fileName); + propertyValue = f.getAbsolutePath(); + } + + assertEquals(assertMsg, propertyValue, xmlValue); + } + + } + } + + /** + * Debugging method to print the properties in the given hashtable + */ + private static void printProperties(Hashtable xmlproperties) { + Enumeration keyEnum = xmlproperties.keys(); + while (keyEnum.hasMoreElements()) { + String currentKey = keyEnum.nextElement().toString(); + System.out.println(currentKey + " = " + + xmlproperties.get(currentKey)); + } + } + + /** + * Ensure all references loaded by the project are valid. + */ + private static void ensureReferences (String msg, File inputFile, + Hashtable references) { + Enumeration referenceKeyEnum = references.keys(); + while(referenceKeyEnum.hasMoreElements()){ + String currentKey = referenceKeyEnum.nextElement().toString(); + Object currentValue = references.get(currentKey); + + if (currentValue instanceof Path) { + } else if (currentValue instanceof String) { + } else { + if( ! currentKey.startsWith("ant.") ) { + fail(msg + "-" + inputFile.getName() + " Key=" + + currentKey + " is not a recognized type."); + } + } + } + } + + /** + * Munge the name of the input file to find an appropriate goldfile, + * based on hardwired naming conventions. + */ + private static File getGoldfile (File input, boolean keepRoot, + boolean collapse, boolean semantic, + boolean include, boolean localRoot) { + // Substitute .xml with .properties + String baseName = input.getName().toLowerCase(); + if (baseName.endsWith(".xml")) { + baseName = baseName.substring(0, baseName.length() - 4) + + ".properties"; + } + + File dir = input.getParentFile().getParentFile(); + + String goldFileFolder = "goldfiles/"; + + if (keepRoot) { + goldFileFolder += "keeproot-"; + } else { + goldFileFolder += "nokeeproot-"; + } + + if (semantic) { + goldFileFolder += "semantic-"; + if (include) { + goldFileFolder += "include-"; + } + } else { + if (collapse) { + goldFileFolder += "collapse-"; + } else { + goldFileFolder += "nocollapse-"; + } + } + + return new File(dir, goldFileFolder + baseName); + } + + /** + * Retrieve a list of xml files in the specified folder + * and below. + */ + private static Enumeration getFiles (final File startingDir) { + Vector result = new Vector(); + getFiles(startingDir, result); + return result.elements(); + } + + /** + * Collect a list of xml files in the specified folder + * and below. + */ + private static void getFiles (final File startingDir, Vector collect) { + FileFilter filter = new FileFilter() { + public boolean accept (File file) { + if (file.isDirectory()) { + return true; + } else { + return (file.getPath().indexOf("taskdefs") > 0 && + file.getPath().toLowerCase().endsWith(".xml") ); + } + } + }; + + File[] files = startingDir.listFiles(filter); + for (int i=0;i<files.length;i++) { + File f = files[i]; + if (!f.isDirectory()) { + collect.addElement(f); + } else { + getFiles(f, collect); + } + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/XmlnsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/XmlnsTest.java new file mode 100644 index 00000000..590a4db9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/XmlnsTest.java @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Task; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +public class XmlnsTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/xmlns.xml"); + } + + @Test + public void testXmlns() { + buildRule.executeTarget("xmlns"); + assertEquals("MyTask called", buildRule.getLog()); + } + + @Test + public void testXmlnsFile() { + buildRule.executeTarget("xmlns.file"); + assertEquals("MyTask called", buildRule.getLog()); + } + + @Test + public void testCore() { + buildRule.executeTarget("core"); + assertEquals("MyTask called", buildRule.getLog()); + } + + @Test + public void testExcluded() { + try { + buildRule.executeTarget("excluded"); + fail("BuildException expected: excluded uri"); + } catch (BuildException ex) { + assertEquals("Attempt to use a reserved URI ant:notallowed", ex.getMessage()); + } + } + + @Test + public void testOther() { + buildRule.executeTarget("other"); + assertEquals("a message", buildRule.getLog()); + } + + @Test + public void testNsAttributes() { + buildRule.executeTarget("ns.attributes"); + assertEquals("hello world", buildRule.getLog()); + } + + public static class MyTask extends Task { + public void execute() { + log("MyTask called"); + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ZipExtraFieldTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ZipExtraFieldTest.java new file mode 100644 index 00000000..c5a42162 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ZipExtraFieldTest.java @@ -0,0 +1,109 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.io.IOException; +import java.util.Collections; +import java.util.Iterator; + +import org.apache.tools.ant.types.Resource; + +import org.apache.tools.ant.types.ResourceCollection; +import org.apache.tools.ant.types.resources.ZipResource; +import org.apache.tools.zip.JarMarker; +import org.apache.tools.zip.Zip64ExtendedInformationExtraField; +import org.apache.tools.zip.ZipEntry; +import org.apache.tools.zip.ZipExtraField; +import org.apache.tools.zip.ZipFile; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class ZipExtraFieldTest { + + @Test + public void testPreservesExtraFields() throws IOException { + testExtraField(new Zip(), true); + } + + public void testDoesntCreateZip64ExtraFieldForJar() throws IOException { + testExtraField(new Jar(), false); + } + + private void testExtraField(Zip testInstance, boolean expectZip64) + throws IOException { + + File f = File.createTempFile("ziptest", ".zip"); + f.delete(); + ZipFile zf = null; + try { + testInstance.setDestFile(f); + final ZipResource r = new ZipResource() { + public String getName() { + return "x"; + } + public boolean isExists() { + return true; + } + public boolean isDirectory() { + return false; + } + public long getLastModified() { + return 1; + } + public InputStream getInputStream() { + return new ByteArrayInputStream(new byte[0]); + } + public ZipExtraField[] getExtraFields() { + return new ZipExtraField[] { + new JarMarker() + }; + } + }; + testInstance.add(new ResourceCollection() { + public boolean isFilesystemOnly() { return false; } + public int size() { return 1; } + public Iterator<Resource> iterator() { + return Collections.<Resource>singleton(r).iterator(); + } + }); + testInstance.execute(); + + zf = new ZipFile(f); + ZipEntry ze = zf.getEntry("x"); + assertNotNull(ze); + assertEquals(expectZip64 ? 2 : 1, ze.getExtraFields().length); + assertTrue(ze.getExtraFields()[0] instanceof JarMarker); + if (expectZip64) { + assertTrue(ze.getExtraFields()[1] + instanceof Zip64ExtendedInformationExtraField); + } + } finally { + ZipFile.closeQuietly(zf); + if (f.exists()) { + f.delete(); + } + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java new file mode 100644 index 00000000..5a7a3590 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/ZipTest.java @@ -0,0 +1,300 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs; + +import java.io.File; +import java.io.IOException; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.apache.tools.zip.UnixStat; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + + +public class ZipTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + //instance variable to allow cleanup + ZipFile zfPrefixAddsDir = null; + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/zip.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("BuildException expected: required argument not specified"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("BuildException expected: zip cannot include itself"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @Test + @Ignore("Previously commented out") + public void test4() { + try { + buildRule.executeTarget("test4"); + fail("BuildException expected: zip cannot include itself"); + } catch (BuildException ex) { + //TODO assert value + } + } + + @After + public void tearDown() { + try { + if ( zfPrefixAddsDir != null) { + zfPrefixAddsDir.close(); + } + + } catch (IOException e) { + //ignored + } + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + } + + + @Test + public void test6() { + buildRule.executeTarget("test6"); + } + + + @Test + public void test7() { + buildRule.executeTarget("test7"); + } + + @Test + public void test8() { + buildRule.executeTarget("test8"); + } + + @Test + public void testZipgroupfileset() throws IOException { + buildRule.executeTarget("testZipgroupfileset"); + + ZipFile zipFile = new ZipFile(new File(buildRule.getProject().getProperty("output"), "zipgroupfileset.zip")); + + assertTrue(zipFile.getEntry("ant.xml") != null); + assertTrue(zipFile.getEntry("optional/jspc.xml") != null); + assertTrue(zipFile.getEntry("zip/zipgroupfileset3.zip") != null); + + assertTrue(zipFile.getEntry("test6.mf") == null); + assertTrue(zipFile.getEntry("test7.mf") == null); + + zipFile.close(); + } + + @Test + public void testUpdateNotNecessary() { + buildRule.executeTarget("testUpdateNotNecessary"); + assertEquals(-1, buildRule.getLog().indexOf("Updating")); + } + + @Test + public void testUpdateIsNecessary() { + buildRule.executeTarget("testUpdateIsNecessary"); + assertContains("Updating", buildRule.getLog()); + } + + // Bugzilla Report 18403 + @Test + public void testPrefixAddsDir() throws IOException { + buildRule.executeTarget("testPrefixAddsDir"); + File archive = new File(buildRule.getProject().getProperty("output"), "test3.zip"); + zfPrefixAddsDir = new ZipFile(archive); + ZipEntry ze = zfPrefixAddsDir.getEntry("test/"); + assertNotNull("test/ has been added", ze); + + } + + // Bugzilla Report 19449 + @Test + public void testFilesOnlyDoesntCauseRecreate() { + buildRule.executeTarget("testFilesOnlyDoesntCauseRecreateSetup"); + File testFile = new File(buildRule.getOutputDir(), "test3.zip"); + assumeTrue("Could not change file modification time", + testFile.setLastModified(testFile.lastModified() - (FileUtils.getFileUtils().getFileTimestampGranularity() * 5))); + long l = testFile.lastModified(); + + buildRule.executeTarget("testFilesOnlyDoesntCauseRecreate"); + assertEquals(l, testFile.lastModified()); + } + + // Bugzilla Report 22865 + @Test + public void testEmptySkip() { + buildRule.executeTarget("testEmptySkip"); + } + // Bugzilla Report 30365 + @Test + public void testZipEmptyDir() { + buildRule.executeTarget("zipEmptyDir"); + } + // Bugzilla Report 40258 + @Test + public void testZipEmptyDirFilesOnly() { + buildRule.executeTarget("zipEmptyDirFilesOnly"); + } + @Test + public void testZipEmptyCreate() { + buildRule.executeTarget("zipEmptyCreate"); + assertContains("Note: creating empty", buildRule.getLog()); + } + // Bugzilla Report 25513 + @Test + public void testCompressionLevel() { + buildRule.executeTarget("testCompressionLevel"); + } + + // Bugzilla Report 33412 + @Test + public void testDefaultExcludesAndUpdate() + throws ZipException, IOException { + buildRule.executeTarget("testDefaultExcludesAndUpdate"); + ZipFile f = null; + try { + f = new ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip")); + assertNotNull("ziptest~ should be included", + f.getEntry("ziptest~")); + } finally { + if (f != null) { + f.close(); + } + } + } + + @Test + public void testFileResource() { + buildRule.executeTarget("testFileResource"); + } + + @Test + public void testNonFileResource() { + buildRule.executeTarget("testNonFileResource"); + } + + @Test + public void testTarFileSet() throws IOException { + buildRule.executeTarget("testTarFileSet"); + org.apache.tools.zip.ZipFile zf = null; + try { + zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip")); + org.apache.tools.zip.ZipEntry ze = zf.getEntry("asf-logo.gif"); + assertEquals(UnixStat.FILE_FLAG | 0446, ze.getUnixMode()); + } finally { + if (zf != null) { + zf.close(); + } + } + } + + @Test + public void testRewriteZeroPermissions() throws IOException { + buildRule.executeTarget("rewriteZeroPermissions"); + org.apache.tools.zip.ZipFile zf = null; + try { + zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip")); + org.apache.tools.zip.ZipEntry ze = zf.getEntry("testdir/test.txt"); + assertEquals(UnixStat.FILE_FLAG | 0644, ze.getUnixMode()); + } finally { + if (zf != null) { + zf.close(); + } + } + } + + @Test + public void testAcceptZeroPermissions() throws IOException { + buildRule.executeTarget("acceptZeroPermissions"); + org.apache.tools.zip.ZipFile zf = null; + try { + zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip")); + org.apache.tools.zip.ZipEntry ze = zf.getEntry("testdir/test.txt"); + assertEquals(0000, ze.getUnixMode()); + } finally { + if (zf != null) { + zf.close(); + } + } + } + + @Test + public void testForBugzilla34764() throws IOException { + buildRule.executeTarget("testForBugzilla34764"); + org.apache.tools.zip.ZipFile zf = null; + try { + zf = new org.apache.tools.zip.ZipFile(new File(buildRule.getProject().getProperty("output"), "test3.zip")); + org.apache.tools.zip.ZipEntry ze = zf.getEntry("file1"); + assertEquals(UnixStat.FILE_FLAG | 0644, ze.getUnixMode()); + } finally { + if (zf != null) { + zf.close(); + } + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java new file mode 100644 index 00000000..750098f9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapterTest.java @@ -0,0 +1,223 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.compilers; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Javac; +import org.apache.tools.ant.types.Commandline; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; + +public class DefaultCompilerAdapterTest { + + private static class LogCapturingJavac extends Javac { + private StringBuffer sb = new StringBuffer(); + public void log(String msg, int msgLevel) { + sb.append(msg); + } + String getLog() { + return sb.toString(); + } + } + + private static class SourceTargetHelper extends DefaultCompilerAdapter { + /** + * Overridden to have no effect. + */ + protected Commandline setupJavacCommandlineSwitches(Commandline cmd, + boolean debug) { + return cmd; + } + + public boolean execute() { return false; } + + /** + * public to avoid classloader issues. + */ + public Commandline setupModernJavacCommandlineSwitches(Commandline cmd) { + return super.setupModernJavacCommandlineSwitches(cmd); + } + } + + @Test + public void testSourceIsIgnoredForJavac13() { + testSource(null, "javac1.3", "", null, "1.1"); + testSource(null, "javac1.3", "", null, "1.2"); + testSource(null, "javac1.3", "", null, "1.3"); + testSource(null, "javac1.3", "", null, "1.4"); + } + + @Test + public void testSource11IsUpgradedTo13() { + testSource("1.3", "javac1.4", "", null, "1.1"); + testSource("1.3", "javac1.5", "", null, "1.1"); + testSource("1.3", "javac1.6", "", null, "1.1"); + testSource("1.3", "javac1.7", "", null, "1.1"); + testSource("1.3", "javac1.8", "", null, "1.1"); + } + + @Test + public void testSource12IsUpgradedTo13() { + testSource("1.3", "javac1.4", "", null, "1.2"); + testSource("1.3", "javac1.5", "", null, "1.2"); + testSource("1.3", "javac1.6", "", null, "1.2"); + testSource("1.3", "javac1.7", "", null, "1.2"); + testSource("1.3", "javac1.8", "", null, "1.2"); + } + + @Test + public void testImplicitSourceForJava15() { + commonSourceDowngrades("javac1.5"); + testSource(null, "javac1.5", "", "1.5"); + testSource(null, "javac1.5", "", "5"); + } + + @Test + public void testImplicitSourceForJava16() { + commonSourceDowngrades("javac1.6"); + testSource(null, "javac1.6", "", "1.5"); + testSource(null, "javac1.6", "", "5"); + testSource(null, "javac1.6", "", "1.6"); + testSource(null, "javac1.6", "", "6"); + } + + @Test + public void testImplicitSourceForJava17() { + commonSourceDowngrades("javac1.7"); + testSource("1.5", "javac1.7", + "If you specify -target 1.5 you now must also specify" + + " -source 1.5", "1.5"); + testSource("1.6", "javac1.7", + "If you specify -target 1.6 you now must also specify" + + " -source 1.6", "1.6"); + testSource("5", "javac1.7", + "If you specify -target 5 you now must also specify" + + " -source 5", "5"); + testSource("6", "javac1.7", + "If you specify -target 6 you now must also specify" + + " -source 6", "6"); + testSource(null, "javac1.7", "", "1.7"); + testSource(null, "javac1.7", "", "7"); + } + + @Test + public void testImplicitSourceForJava18() { + commonSourceDowngrades("javac1.8"); + testSource("1.5", "javac1.8", + "If you specify -target 1.5 you now must also specify" + + " -source 1.5", "1.5"); + testSource("1.6", "javac1.8", + "If you specify -target 1.6 you now must also specify" + + " -source 1.6", "1.6"); + testSource("1.7", "javac1.8", + "If you specify -target 1.7 you now must also specify" + + " -source 1.7", "1.7"); + testSource("5", "javac1.8", + "If you specify -target 5 you now must also specify" + + " -source 5", "5"); + testSource("6", "javac1.8", + "If you specify -target 6 you now must also specify" + + " -source 6", "6"); + testSource("7", "javac1.8", + "If you specify -target 7 you now must also specify" + + " -source 7", "7"); + testSource(null, "javac1.8", "", "1.8"); + testSource(null, "javac1.8", "", "8"); + } + + @Test + public void testImplicitSourceForJava19() { + commonSourceDowngrades("javac1.9"); + testSource("1.5", "javac1.9", + "If you specify -target 1.5 you now must also specify" + + " -source 1.5", "1.5"); + testSource("1.6", "javac1.9", + "If you specify -target 1.6 you now must also specify" + + " -source 1.6", "1.6"); + testSource("1.7", "javac1.9", + "If you specify -target 1.7 you now must also specify" + + " -source 1.7", "1.7"); + testSource("1.8", "javac1.9", + "If you specify -target 1.8 you now must also specify" + + " -source 1.8", "1.8"); + testSource("5", "javac1.9", + "If you specify -target 5 you now must also specify" + + " -source 5", "5"); + testSource("6", "javac1.9", + "If you specify -target 6 you now must also specify" + + " -source 6", "6"); + testSource("7", "javac1.9", + "If you specify -target 7 you now must also specify" + + " -source 7", "7"); + testSource("8", "javac1.9", + "If you specify -target 8 you now must also specify" + + " -source 8", "8"); + testSource(null, "javac1.9", "", "1.9"); + testSource(null, "javac1.9", "", "9"); + } + + private void commonSourceDowngrades(String javaVersion) { + testSource("1.3", javaVersion, + "If you specify -target 1.1 you now must also specify" + + " -source 1.3", "1.1"); + testSource("1.3", javaVersion, + "If you specify -target 1.2 you now must also specify" + + " -source 1.3", "1.2"); + testSource("1.3", javaVersion, + "If you specify -target 1.3 you now must also specify" + + " -source 1.3", "1.3"); + testSource("1.4", javaVersion, + "If you specify -target 1.4 you now must also specify" + + " -source 1.4", "1.4"); + } + + private void testSource(String expectedSource, String javaVersion, + String expectedLog, String configuredTarget) { + testSource(expectedSource, javaVersion, expectedLog, configuredTarget, + null); + } + + private void testSource(String expectedSource, String javaVersion, + String expectedLog, String configuredTarget, + String configuredSource) { + LogCapturingJavac javac = new LogCapturingJavac(); + javac.setProject(new Project()); + javac.setCompiler(javaVersion); + javac.setSource(configuredSource); + javac.setTarget(configuredTarget); + SourceTargetHelper sth = new SourceTargetHelper(); + sth.setJavac(javac); + Commandline cmd = new Commandline(); + sth.setupModernJavacCommandlineSwitches(cmd); + if ("".equals(expectedLog)) { + assertEquals("", javac.getLog()); + } else { + String l = javac.getLog(); + assertContains(expectedLog, l); + } + String[] args = cmd.getCommandline(); + assertEquals(expectedSource == null ? 0 : 2, args.length); + if (expectedSource != null) { + assertEquals("-source", args[0]); + assertEquals(expectedSource, args[1]); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/AntVersionTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/AntVersionTest.java new file mode 100644 index 00000000..b70a1381 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/AntVersionTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.condition; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcases for the <antversion> condition. + * + */ +public class AntVersionTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() throws Exception { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/antversion.xml"); + } + + @Test + public void testAtLeast() { + buildRule.executeTarget("testatleast"); + } + + @Test + public void testExactly() { + buildRule.executeTarget("testexactly"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ContainsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ContainsTest.java new file mode 100644 index 00000000..a45b511a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ContainsTest.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.condition; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Testcase for the <contains> condition. + * + */ +public class ContainsTest { + + @Test + public void testCaseSensitive() { + Contains con = new Contains(); + con.setString("abc"); + con.setSubstring("A"); + assertTrue(!con.eval()); + + con.setCasesensitive(false); + assertTrue(con.eval()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/EqualsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/EqualsTest.java new file mode 100644 index 00000000..5f9b996a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/EqualsTest.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.condition; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Testcase for the <equals> condition. + * + */ +public class EqualsTest { + + @Test + public void testTrim() { + Equals eq = new Equals(); + eq.setArg1("a"); + eq.setArg2(" a"); + assertTrue(!eq.eval()); + + eq.setTrim(true); + assertTrue(eq.eval()); + + eq.setArg2("a\t"); + assertTrue(eq.eval()); + } + + @Test + public void testCaseSensitive() { + Equals eq = new Equals(); + eq.setArg1("a"); + eq.setArg2("A"); + assertTrue(!eq.eval()); + + eq.setCasesensitive(false); + assertTrue(eq.eval()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java new file mode 100644 index 00000000..15a9d2d3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/HttpTest.java @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.condition; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.fail; + +/** + * Testcases for the <http> condition. All these tests require + * us to be online as they attempt to get the status of various pages + * on the Ant Apache web site. + */ +public class HttpTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/http.xml"); + } + + @Test + public void testNoMethod() { + buildRule.executeTarget("basic-no-method"); + assertEquals("true", buildRule.getProject().getProperty("basic-no-method")); + assertNull(buildRule.getProject().getProperty("basic-no-method-bad-url")); + } + + @Test + public void testHeadRequest() { + buildRule.executeTarget("test-head-request"); + assertEquals("true", buildRule.getProject().getProperty("test-head-request")); + assertNull(buildRule.getProject().getProperty("test-head-request-bad-url")); + } + + @Test + public void testGetRequest() { + buildRule.executeTarget("test-get-request"); + assertEquals("true", buildRule.getProject().getProperty("test-get-request")); + assertNull(buildRule.getProject().getProperty("test-get-request-bad-url")); + } + + @Test + public void testBadRequestMethod() { + try { + buildRule.executeTarget("bad-request-method"); + fail("Exception should have been thrown as invalid HTTP request method specified"); + } catch (BuildException ex) { + //TODO we should assert the correct build exception was thrown + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java new file mode 100644 index 00000000..86594765 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFailureTest.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.condition; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcases for the <isfailure> condition. + * + */ +public class IsFailureTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/isfailure.xml"); + } + + @Test + public void testIsFailure() { + buildRule.executeTarget("testisfailure"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFileSelectedTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFileSelectedTest.java new file mode 100644 index 00000000..84d88a55 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsFileSelectedTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.condition; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + * Testcase for the <isfileselected> condition. + * + */ +public class IsFileSelectedTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/isfileselected.xml"); + } + + @Test + public void testSimple() { + buildRule.executeTarget("simple"); + } + + @Test + public void testName() { + buildRule.executeTarget("name"); + } + + @Test + public void testBaseDir() { + buildRule.executeTarget("basedir"); + } + + @Test + public void testType() { + buildRule.executeTarget("type"); + } + + @Test + public void testNotSelector() { + try { + buildRule.executeTarget("not.selector"); + fail("Exception should have been thrown: checking for use as a selector (not allowed)"); + } catch(BuildException ex) { + AntAssert.assertContains("fileset doesn't support the nested \"isfile", + ex.getMessage()); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java new file mode 100644 index 00000000..d036834c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReachableTest.java @@ -0,0 +1,116 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.condition; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * test for reachable things + */ +public class IsReachableTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject( + "src/etc/testcases/taskdefs/conditions/isreachable.xml"); + } + + + @Test + public void testLocalhost() throws Exception { + buildRule.executeTarget("testLocalhost"); + } + + @Test + public void testLocalhostURL() throws Exception { + buildRule.executeTarget("testLocalhostURL"); + } + + @Test + public void testIpv4localhost() throws Exception { + buildRule.executeTarget("testIpv4localhost"); + } + + @Test + public void testFTPURL() throws Exception { + buildRule.executeTarget("testFTPURL"); + } + + @Test + public void testBoth() throws Exception { + try { + buildRule.executeTarget("testBoth"); + fail("Build exception expected: error on two targets"); + } catch(BuildException ex) { + assertEquals(IsReachable.ERROR_BOTH_TARGETS, ex.getMessage()); + } + } + + @Test + public void testNoTargets() throws Exception { + try { + buildRule.executeTarget("testNoTargets"); + fail("Build exception expected: no params"); + } catch(BuildException ex) { + assertEquals(IsReachable.ERROR_NO_HOSTNAME, ex.getMessage()); + } + } + + @Test + public void testBadTimeout() throws Exception { + try { + buildRule.executeTarget("testBadTimeout"); + fail("Build exception expected: error on -ve timeout"); + } catch(BuildException ex) { + assertEquals(IsReachable.ERROR_BAD_TIMEOUT, ex.getMessage()); + } + } + + @Test + @Ignore("Previously named in a way to prevent execution") + public void NotestFile() throws Exception { + try { + buildRule.executeTarget("testFile"); + fail("Build exception expected: error on file URL"); + } catch(BuildException ex) { + assertEquals(IsReachable.ERROR_NO_HOST_IN_URL, ex.getMessage()); + } + } + + @Test + public void testBadURL() throws Exception { + try { + buildRule.executeTarget("testBadURL"); + fail("Build exception expected: error in URL"); + } catch(BuildException ex) { + AntAssert.assertContains(IsReachable.ERROR_BAD_URL, ex.getMessage()); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReferenceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReferenceTest.java new file mode 100644 index 00000000..01b6b47c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsReferenceTest.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.condition; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.junit.Assert.assertNull; + +/** + * Testcases for the <isreference> condition. + * + */ +public class IsReferenceTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/isreference.xml"); + } + + @Test + public void testBasic() { + buildRule.executeTarget("basic"); + assertEquals("true", buildRule.getProject().getProperty("global-path")); + assertEquals("true", buildRule.getProject().getProperty("target-path")); + assertNull(buildRule.getProject().getProperty("undefined")); + } + + @Test + public void testNotEnoughArgs() { + try { + buildRule.executeTarget("isreference-incomplete"); + fail("Build exception expected: refid attirbute has been omitted"); + } catch(BuildException ex) { + assertEquals("No reference specified for isreference condition", ex.getMessage()); + } + } + + @Test + public void testType() { + buildRule.executeTarget("type"); + assertEquals("true", buildRule.getProject().getProperty("global-path")); + assertNull(buildRule.getProject().getProperty("global-path-as-fileset")); + assertNull(buildRule.getProject().getProperty("global-path-as-foo")); + assertEquals("true", buildRule.getProject().getProperty("global-echo")); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsSignedTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsSignedTest.java new file mode 100644 index 00000000..0f4001c3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/IsSignedTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.condition; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcase for the <issigned> condition. + * + */ +public class IsSignedTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/issigned.xml"); + } + + @Test + public void testPass() { + buildRule.executeTarget("pass"); + } + + @Test + public void testPassword() { + buildRule.executeTarget("password"); + } + + @Test + public void testAPassword() { + buildRule.executeTarget("apassword"); + } + + @Test + public void testAllSigned() { + buildRule.executeTarget("allsigned"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ParserSupportsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ParserSupportsTest.java new file mode 100644 index 00000000..2a2354ff --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/ParserSupportsTest.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.condition; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + + */ +public class ParserSupportsTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/parsersupports.xml"); + } + + @Test + public void testEmpty() { + try { + buildRule.executeTarget("testEmpty"); + fail("Build exception expected: " + ParserSupports.ERROR_NO_ATTRIBUTES); + } catch(BuildException ex) { + assertEquals(ParserSupports.ERROR_NO_ATTRIBUTES, ex.getMessage()); + } + } + + @Test + public void testBoth() { + try { + buildRule.executeTarget("testBoth"); + fail("Build exception expected: " + ParserSupports.ERROR_BOTH_ATTRIBUTES); + } catch(BuildException ex) { + assertEquals(ParserSupports.ERROR_BOTH_ATTRIBUTES, ex.getMessage()); + } + } + + @Test + public void testNamespaces() { + buildRule.executeTarget("testNamespaces"); + } + + @Test + public void testPropertyNoValue() { + try { + buildRule.executeTarget("testPropertyNoValue"); + fail("Build exception expected: " + ParserSupports.ERROR_NO_VALUE); + } catch(BuildException ex) { + assertEquals(ParserSupports.ERROR_NO_VALUE, ex.getMessage()); + } + } + + @Test + public void testUnknownProperty() { + buildRule.executeTarget("testUnknownProperty"); + } + + @Test + @Ignore("Previously named in a manner to prevent execution") + public void NotestPropertyInvalid() { + buildRule.executeTarget("testPropertyInvalid"); + } + + @Test + @Ignore("Previously named in a manner to prevent execution") + public void NotestXercesProperty() { + buildRule.executeTarget("testXercesProperty"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java new file mode 100644 index 00000000..ab284943 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/TypeFoundTest.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.condition; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.junit.Assert.assertNull; + +/** + * test the typeexists condition + */ +public class TypeFoundTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/typefound.xml"); + } + + @Test + public void testTask() { + buildRule.executeTarget("testTask"); + assertEquals("true", buildRule.getProject().getProperty("testTask")); + } + + @Test + public void testUndefined() { + try { + buildRule.executeTarget("testUndefined"); + fail("Build exception expected: left out the name attribute"); + } catch(BuildException ex) { + AntAssert.assertContains("No type specified", ex.getMessage()); + } + } + + @Test + public void testTaskThatIsntDefined() { + buildRule.executeTarget("testTaskThatIsntDefined"); + assertNull(buildRule.getProject().getProperty("testTaskThatIsntDefined")); + } + + @Test + public void testTaskThatDoesntReallyExist() { + buildRule.executeTarget("testTaskThatDoesntReallyExist"); + assertNull(buildRule.getProject().getProperty("testTaskThatDoesntReallyExist")); + } + + @Test + public void testType() { + buildRule.executeTarget("testType"); + assertEquals("true", buildRule.getProject().getProperty("testType")); + } + + @Test + public void testPreset() { + buildRule.executeTarget("testPreset"); + assertEquals("true", buildRule.getProject().getProperty("testPreset")); + } + + @Test + public void testMacro() { + buildRule.executeTarget("testMacro"); + assertEquals("true", buildRule.getProject().getProperty("testMacro")); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/XorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/XorTest.java new file mode 100644 index 00000000..4f04c357 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/condition/XorTest.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.condition; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Test that Xor follows the conventional boolean logic semantics + * (a ^ b) === (a||b)&!(a&&b) + */ +public class XorTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/conditions/xor.xml"); + } + + @Test + public void testEmpty() { + buildRule.executeTarget("testEmpty"); + } + + @Test + public void test0() { + buildRule.executeTarget("test0"); + } + + @Test + public void test1() { + buildRule.executeTarget("test1"); + } + + @Test + public void test00() { + buildRule.executeTarget("test00"); + } + + @Test + public void test10() { + buildRule.executeTarget("test10"); + } + + @Test + public void test01() { + buildRule.executeTarget("test01"); + } + + @Test + public void test11() { + buildRule.executeTarget("test11"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java new file mode 100644 index 00000000..3dfaf8dd --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogParserTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.cvslib; + +import org.junit.Test; + +import java.util.Calendar; +import java.util.Locale; +import java.util.TimeZone; +import java.util.Date; + +import static org.junit.Assert.assertEquals; + +/** + * Minimal test of the parser implementation + */ +public class ChangeLogParserTest { + + protected ChangeLogParser parser = new ChangeLogParser(); + + @Test + public void testOldCvsFormat() throws Exception { + parser.stdout("Working file: build.xml"); + parser.stdout("revision 1.475"); + parser.stdout("date: 2004/06/05 16:10:32; author: somebody; state: Exp; lines: +2 -2"); + parser.stdout("I have done something. I swear."); + parser.stdout("============================================================================="); + CVSEntry[] entries = parser.getEntrySetAsArray(); + assertEquals("somebody", entries[0].getAuthor()); + Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.US); + cal.set(Calendar.MILLISECOND, 0); + cal.set(2004, Calendar.JUNE, 5, 16, 10, 32); + Date date = cal.getTime(); + assertEquals(date, entries[0].getDate()); + } + + @Test + public void testCvs112Format() throws Exception { + parser.stdout("Working file: build.xml"); + parser.stdout("revision 1.475"); + parser.stdout("date: 2004-06-05 16:10:32 +0000; author: somebody; state: Exp; lines: +2 -2"); + parser.stdout("I have done something. I swear."); + parser.stdout("============================================================================="); + CVSEntry[] entries = parser.getEntrySetAsArray(); + assertEquals("somebody", entries[0].getAuthor()); + Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.US); + cal.set(Calendar.MILLISECOND, 0); + cal.set(2004, Calendar.JUNE, 5, 16, 10, 32); + Date date = cal.getTime(); + assertEquals(date, entries[0].getDate()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java new file mode 100644 index 00000000..a2531d8e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/cvslib/ChangeLogWriterTest.java @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.cvslib; + +import java.util.Date; +import java.io.PrintWriter; +import java.io.OutputStreamWriter; +import java.io.ByteArrayOutputStream; +import java.io.ByteArrayInputStream; +import java.io.InputStream; + +import org.apache.tools.ant.util.JAXPUtils; +import org.junit.Test; +import org.xml.sax.XMLReader; +import org.xml.sax.InputSource; +import org.xml.sax.ContentHandler; +import org.xml.sax.SAXException; +import org.xml.sax.Locator; +import org.xml.sax.Attributes; + +/** + * Test for the cvslib ChangeLogWriter + */ +public class ChangeLogWriterTest { + + private ChangeLogWriter writer = new ChangeLogWriter(); + + @Test + public void testNonUTF8Characters() throws Exception { + CVSEntry entry = new CVSEntry(new Date(), "Se\u00f1orita", "2003 < 2004 && 3 > 5"); + entry.addFile("Medicare & review.doc", "1.1"); + entry.addFile("El\u00e8ments de style", "1.2"); + CVSEntry[] entries = { entry }; + + ByteArrayOutputStream output = new ByteArrayOutputStream(); + PrintWriter pwriter = new PrintWriter(new OutputStreamWriter(output, "UTF-8")); + writer.printChangeLog(pwriter, entries); + + // make sure that the parsing does not break + XMLReader xmlReader = JAXPUtils.getXMLReader(); + InputStream input = new ByteArrayInputStream(output.toByteArray()); + xmlReader.setContentHandler(new NullContentHandler()); + xmlReader.parse(new InputSource(input)); + } + + public static class NullContentHandler implements ContentHandler { + public void endDocument() throws SAXException { + } + + public void startDocument() throws SAXException { + } + + public void characters(char ch[], int start, int length) throws SAXException { + String debug = new String(ch, start, length); + } + + public void ignorableWhitespace(char ch[], int start, int length) throws SAXException { + } + + public void endPrefixMapping(String prefix) throws SAXException { + } + + public void skippedEntity(String name) throws SAXException { + } + + public void setDocumentLocator(Locator locator) { + } + + public void processingInstruction(String target, String data) throws SAXException { + } + + public void startPrefixMapping(String prefix, String uri) throws SAXException { + } + + public void endElement(String namespaceURI, String localName, String qName) throws SAXException { + } + + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/dir1/B.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/dir1/B.java new file mode 100644 index 00000000..9057fa0c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/dir1/B.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.dir1; + +public class B extends org.apache.tools.ant.taskdefs.dir2.A { + static { + System.out.println("B CLASS INITIALIZATION"); + setA(new B()); + } + + public String toString() { + return "I am a B."; + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/dir2/A.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/dir2/A.java new file mode 100644 index 00000000..5186ac4c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/dir2/A.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.dir2; + +public class A { + public static void main(String [] args) { + System.out.println("MAIN"); + System.out.println(a); + } + + static A a=new A(); + + static { + System.out.println("A CLASS INITIALIZATION"); + } + + protected static void setA(A oa) { + a=oa; + } + + public String toString() { + return "I am a A."; + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java new file mode 100644 index 00000000..31ecafba --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailAddressTest.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.email; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + +/** + * @since Ant 1.6 + */ +public class EmailAddressTest { + + @Test + public void test1() { + expectNameAddress( new EmailAddress("address (name)") ); + } + + @Test + public void test2() { + expectNameAddress( new EmailAddress("(name) address") ); + } + + @Test + public void test3() { + expectNameAddress( new EmailAddress("name <address>") ); + } + + @Test + public void test4() { + expectNameAddress( new EmailAddress("<address> name") ); + } + + @Test + public void test5() { + expectNameAddress( new EmailAddress("<address> (name)") ); + } + + @Test + public void test6() { + expectNameAddress( new EmailAddress("(name) <address>") ); + } + + @Test + public void test7() { + expectNameAddress2( new EmailAddress("address (<name>)") ); + } + + @Test + public void test8() { + expectNameAddress2( new EmailAddress("(<name>) address") ); + } + + @Test + public void test9() { + expectNameAddress3( new EmailAddress("address") ); + } + + @Test + public void testA() { + expectNameAddress3( new EmailAddress("<address>") ); + } + + @Test + public void testB() { + expectNameAddress3( new EmailAddress(" <address> ") ); + } + + @Test + public void testC() { + expectNameAddress3( new EmailAddress("< address >") ); + } + + @Test + public void testD() { + expectNameAddress3( new EmailAddress(" < address > ") ); + } + + private void expectNameAddress(EmailAddress e) { + assertEquals( "name", e.getName() ); + assertEquals( "address", e.getAddress() ); + } + + // where the name contains <> + private void expectNameAddress2(EmailAddress e) { + assertEquals( "<name>", e.getName() ); + assertEquals( "address", e.getAddress() ); + } + + // where only an address is supplied + private void expectNameAddress3(EmailAddress e) { + assertNull("Expected null, found <" + e.getName() + ">", e.getName()); + assertEquals( "address", e.getAddress() ); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailTaskTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailTaskTest.java new file mode 100644 index 00000000..6363f90d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/EmailTaskTest.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.email; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + * TODO : develop these testcases - the email task needs to have attributes allowing + * to simulate sending mail and to catch the output in text files or streams + */ +public class EmailTaskTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/email/mail.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Build exception expected: SMTP auth only possibly with MIME mail"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Build exception expected: SSL only possibly with MIME mail"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java new file mode 100644 index 00000000..df75067f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.email; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintStream; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.FileUtils; +import org.junit.After; +import org.junit.Test; + +public class MessageTest { + private static final File f = new File(System.getProperty("java.io.tmpdir"), + "message.txt"); + /** + * test for bugzilla 48932 + */ + @Test + public void testPrintStreamDoesNotGetClosed() throws IOException { + Message ms = new Message(); + Project p = new Project(); + ms.setProject(p); + ms.addText("hi, this is an email"); + FileOutputStream fis = null; + try { + fis = new FileOutputStream(f); + ms.print(new PrintStream(fis)); + fis.write(120); + } finally { + FileUtils.close(fis); + } + + } + + @After + public void tearDown() { + if (f.exists()) { + FileUtils fu = FileUtils.getFileUtils(); + fu.tryHardToDelete(f); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java new file mode 100644 index 00000000..92584483 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java @@ -0,0 +1,216 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; +import java.io.FilenameFilter; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.apache.tools.ant.AntAssert.assertNotContains; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * If you want to run tests, it is highly recommended + * to download ANTLR (www.antlr.org), build the 'antlrall.jar' jar + * with <code>make antlr-all.jar</code> and drop the jar (about 300KB) into + * Ant lib. + * - Running w/ the default antlr.jar (70KB) does not work (missing class) + * + * Unless of course you specify the ANTLR classpath in your + * system classpath. (see ANTLR install.html) + * + */ +public class ANTLRTest { + + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/antlr/"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "antlr.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("required argument, target, missing"); + } catch (BuildException ex) { + //TODO should check exception message + } + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("Invalid output directory"); + } catch (BuildException ex) { + //TODO should check exception message + } + } + + @Test + public void test3() { + buildRule.executeTarget("test3"); + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + } + + @Test + public void test5() { + // should print "panic: Cannot find importVocab file 'JavaTokenTypes.txt'" + // since it needs to run java.g first before java.tree.g + try { + buildRule.executeTarget("test5"); + fail("ANTLR returned: 1"); + } catch (BuildException ex) { + //TODO should check exception message + } + } + + @Test + public void test6() { + buildRule.executeTarget("test6"); + } + + @Test + public void test7() { + try { + buildRule.executeTarget("test7"); + fail("Unable to determine generated class"); + } catch (BuildException ex) { + //TODO should check exception message + } + } + + /** + * This is a negative test for the super grammar (glib) option. + */ + @Test + public void test8() { + try { + buildRule.executeTarget("test8"); + fail("Invalid super grammar file"); + } catch (BuildException ex) { + //TODO should check exception message + } + } + + /** + * This is a positive test for the super grammar (glib) option. ANTLR + * will throw an error if everything is not correct. + */ + @Test + public void test9() { + buildRule.executeTarget("test9"); + } + + /** + * This test creates an html-ized version of the calculator grammar. + * The sanity check is simply whether or not an html file was generated. + */ + @Test + public void test10() { + buildRule.executeTarget("test10"); + File outputDirectory = new File(buildRule.getProject().getProperty("output")); + String[] calcFiles = outputDirectory.list(new HTMLFilter()); + assertTrue(calcFiles.length > 0); + } + + /** + * This is just a quick sanity check to run the diagnostic option and + * make sure that it doesn't throw any funny exceptions. + */ + @Test + public void test11() { + buildRule.executeTarget("test11"); + } + + /** + * This is just a quick sanity check to run the trace option and + * make sure that it doesn't throw any funny exceptions. + */ + @Test + public void test12() { + buildRule.executeTarget("test12"); + } + + /** + * This is just a quick sanity check to run all the rest of the + * trace options (traceLexer, traceParser, and traceTreeWalker) to + * make sure that they don't throw any funny exceptions. + */ + @Test + public void test13() { + buildRule.executeTarget("test13"); + } + + @Test + public void testNoRecompile() { + buildRule.executeTarget("test9"); + assertNotContains("Skipped grammar file.", buildRule.getFullLog()); + buildRule.executeTarget("noRecompile"); + assertContains("Skipped grammar file.", buildRule.getFullLog()); + } + + @Test + public void testNormalRecompile() { + buildRule.executeTarget("test9"); + assertNotContains("Skipped grammar file.", buildRule.getFullLog()); + + FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5); + + buildRule.executeTarget("normalRecompile"); + assertNotContains("Skipped grammar file.", buildRule.getFullLog()); + } + + @Test + // Bugzilla Report 12961 + public void testSupergrammarChangeRecompile() { + buildRule.executeTarget("test9"); + assertNotContains("Skipped grammar file.", buildRule.getFullLog()); + + FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5); + + buildRule.executeTarget("supergrammarChangeRecompile"); + assertNotContains("Skipped grammar file.", buildRule.getFullLog()); + + } + +} + +class HTMLFilter implements FilenameFilter { + public boolean accept(File dir, String name) { + return name.endsWith("html"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java new file mode 100644 index 00000000..434e81f5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java @@ -0,0 +1,104 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.FileNotFoundException; +import java.net.URL; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; + +import org.apache.tools.ant.taskdefs.XSLTLiaison; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Before; +import org.junit.Test; +import org.w3c.dom.Document; + +/** + * Abtract testcase for XSLTLiaison. + * Override createLiaison for each XSLTLiaison. + * + * <a href="sbailliez@apache.org">Stephane Bailliez</a> + */ +public abstract class AbstractXSLTLiaisonTest { + + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + protected XSLTLiaison liaison; + + @Before + public void setUp() throws Exception { + liaison = createLiaison(); + } + + // to override + protected abstract XSLTLiaison createLiaison() throws Exception ; + + /** load the file from the caller classloader that loaded this class */ + protected File getFile(String name) throws FileNotFoundException { + URL url = getClass().getResource(name); + if (url == null){ + throw new FileNotFoundException("Unable to load '" + name + "' from classpath"); + } + return new File(FILE_UTILS.fromURI(url.toExternalForm())); + } + + /** keep it simple stupid */ + @Test + public void testTransform() throws Exception { + File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl"); + liaison.setStylesheet(xsl); + liaison.addParam("param", "value"); + File in = getFile("/taskdefs/optional/xsltliaison-in.xml"); + File out = new File("xsltliaison.tmp"); + out.deleteOnExit(); // just to be sure + try { + liaison.transform(in, out); + } finally { + out.delete(); + } + } + + @Test + public void testEncoding() throws Exception { + File xsl = getFile("/taskdefs/optional/xsltliaison-encoding-in.xsl"); + liaison.setStylesheet(xsl); + File in = getFile("/taskdefs/optional/xsltliaison-encoding-in.xml"); + File out = new File("xsltliaison-encoding.tmp"); + out.deleteOnExit(); // just to be sure + try { + liaison.transform(in, out); + Document doc = parseXML(out); + assertEquals("root",doc.getDocumentElement().getNodeName()); + assertEquals("message",doc.getDocumentElement().getFirstChild().getNodeName()); + assertEquals("\u00E9\u00E0\u00E8\u00EF\u00F9",doc.getDocumentElement().getFirstChild().getFirstChild().getNodeValue()); + } finally { + out.delete(); + } + } + + public Document parseXML(File file) throws Exception { + DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dbuilder = dbfactory.newDocumentBuilder(); + return dbuilder.parse(file); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java new file mode 100644 index 00000000..88020229 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Tests the examples of the <script> task docs. + * + * @since Ant 1.5.2 + */ +public class BeanShellScriptTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/script.xml"); + } + + @Test + public void testCanLoad() { + buildRule.executeTarget("useBeanshell"); + assertEquals("I'm here", buildRule.getLog()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java new file mode 100644 index 00000000..925777c5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java @@ -0,0 +1,266 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Tests the EchoProperties task. + * + * @created 17-Jan-2002 + * @since Ant 1.5 + */ +public class EchoPropertiesTest { + + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; + private static final String GOOD_OUTFILE = "test.properties"; + private static final String GOOD_OUTFILE_XML = "test.xml"; + private static final String PREFIX_OUTFILE = "test-prefix.properties"; + private static final String TEST_VALUE = "isSet"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "echoproperties.xml"); + buildRule.getProject().setProperty("test.property", TEST_VALUE); + } + + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + + @Test + public void testEchoToLog() { + buildRule.executeTarget("testEchoToLog"); + assertContains("test.property=" + TEST_VALUE, buildRule.getLog()); + } + + @Test + public void testEchoWithEmptyPrefixToLog() { + buildRule.executeTarget("testEchoWithEmptyPrefixToLog"); + assertContains("test.property="+TEST_VALUE, buildRule.getLog()); + } + + + @Test + public void testReadBadFile() { + try { + buildRule.executeTarget("testReadBadFile"); + fail("BuildException should have been thrown on bad file"); + } + catch(BuildException ex) { + assertContains("srcfile is a directory","srcfile is a directory!", ex.getMessage()); + } + } + + @Test + public void testReadBadFileNoFail() { + buildRule.executeTarget("testReadBadFileNoFail"); + assertContains("srcfile is a directory!", buildRule.getLog()); + } + + + @Test + public void testEchoToBadFile() { + try { + buildRule.executeTarget("testEchoToBadFile"); + fail("BuildException should have been thrown on destination file being a directory"); + } catch(BuildException ex) { + assertContains("destfile is a directory", "destfile is a directory!", ex.getMessage()); + } + } + + + @Test + public void testEchoToBadFileNoFail() { + buildRule.executeTarget("testEchoToBadFileNoFail"); + assertContains("destfile is a directory!", buildRule.getLog()); + } + + + @Test + public void testEchoToGoodFile() throws Exception { + buildRule.executeTarget("testEchoToGoodFile"); + assertGoodFile(); + } + + + @Test + public void testEchoToGoodFileXml() throws Exception { + buildRule.executeTarget("testEchoToGoodFileXml"); + + // read in the file + File f = createRelativeFile(GOOD_OUTFILE_XML); + FileReader fr = new FileReader(f); + BufferedReader br = new BufferedReader(fr); + try { + String read = null; + while ((read = br.readLine()) != null) { + if (read.indexOf("<property name=\"test.property\" value=\""+TEST_VALUE+"\" />") >= 0) { + // found the property we set - it's good. + return; + } + } + fail("did not encounter set property in generated file."); + } finally { + try { + fr.close(); + } catch(IOException e) {} + try { + br.close(); + } catch(IOException e) {} + } + } + + + @Test + public void testEchoToGoodFileFail() throws Exception { + buildRule.executeTarget("testEchoToGoodFileFail"); + assertGoodFile(); + } + + + @Test + public void testEchoToGoodFileNoFail() throws Exception { + buildRule.executeTarget("testEchoToGoodFileNoFail"); + assertGoodFile(); + } + + @Test + public void testEchoPrefix() throws Exception { + testEchoPrefixVarious("testEchoPrefix"); + } + + @Test + public void testEchoPrefixAsPropertyset() throws Exception { + testEchoPrefixVarious("testEchoPrefixAsPropertyset"); + } + + @Test + public void testEchoPrefixAsNegatedPropertyset() throws Exception { + testEchoPrefixVarious("testEchoPrefixAsNegatedPropertyset"); + } + + @Test + public void testEchoPrefixAsDoublyNegatedPropertyset() throws Exception { + testEchoPrefixVarious("testEchoPrefixAsDoublyNegatedPropertyset"); + } + + @Test + public void testWithPrefixAndRegex() throws Exception { + try { + buildRule.executeTarget("testWithPrefixAndRegex"); + fail("BuildException should have been thrown on Prefix and RegEx beng set"); + } catch (BuildException ex) { + assertEquals("The target must fail with prefix and regex attributes set", "Please specify either prefix or regex, but not both", ex.getMessage()); + } + } + + @Test + public void testWithEmptyPrefixAndRegex() throws Exception { + buildRule.executeTarget("testEchoWithEmptyPrefixToLog"); + assertContains("test.property="+TEST_VALUE, buildRule.getLog()); + } + + @Test + public void testWithRegex() throws Exception { + assumeTrue("Test skipped because no regexp matcher is present.", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject())); + buildRule.executeTarget("testWithRegex"); + // the following line has been changed from checking ant.home to ant.version so the test will still work when run outside of an ant script + assertContains("ant.version=", buildRule.getFullLog()); + } + + private void testEchoPrefixVarious(String target) throws Exception { + buildRule.executeTarget(target); + Properties props = loadPropFile(PREFIX_OUTFILE); + assertEquals("prefix didn't include 'a.set' property", + "true", props.getProperty("a.set")); + assertNull("prefix failed to filter out property 'b.set'", + props.getProperty("b.set")); + } + + protected Properties loadPropFile(String relativeFilename) + throws IOException { + File f = createRelativeFile(relativeFilename); + Properties props=new Properties(); + InputStream in=null; + try { + in=new BufferedInputStream(new FileInputStream(f)); + props.load(in); + } finally { + if(in!=null) { + try { in.close(); } catch(IOException e) {} + } + } + return props; + } + + protected void assertGoodFile() throws Exception { + File f = createRelativeFile(GOOD_OUTFILE); + assertTrue("Did not create "+f.getAbsolutePath(), + f.exists()); + Properties props=loadPropFile(GOOD_OUTFILE); + props.list(System.out); + assertEquals("test property not found ", + TEST_VALUE, props.getProperty("test.property")); + } + + + protected String toAbsolute(String filename) { + return createRelativeFile(filename).getAbsolutePath(); + } + + + protected File createRelativeFile(String filename) { + if (filename.equals(".")) { + return buildRule.getProject().getBaseDir(); + } + // else + return new File(buildRule.getProject().getBaseDir(), filename); + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java new file mode 100644 index 00000000..8b02fff5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java @@ -0,0 +1,60 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertTrue; + +public class JavahTest { + + private final static String BUILD_XML = + "src/etc/testcases/taskdefs/optional/javah/build.xml"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(BUILD_XML); + } + + @After + public void tearDown() { + buildRule.executeTarget("tearDown"); + } + + @Test + public void testSimpleCompile() { + buildRule.executeTarget("simple-compile"); + assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h") + .exists()); + } + + @Test + public void testCompileFileset() { + buildRule.executeTarget("test-fileset"); + assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h").exists()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java new file mode 100644 index 00000000..57475cc1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java @@ -0,0 +1,200 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.taskdefs.optional.jsp.Jasper41Mangler; +import org.apache.tools.ant.taskdefs.optional.jsp.JspMangler; +import org.apache.tools.ant.taskdefs.optional.jsp.JspNameMangler; +import org.apache.tools.ant.taskdefs.optional.jsp.compilers.JspCompilerAdapter; +import org.apache.tools.ant.taskdefs.optional.jsp.compilers.JspCompilerAdapterFactory; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests the Jspc task. + * + * created 07 March 2002 + * @since Ant 1.5 + */ +public class JspcTest { + + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; + + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "jspc.xml"); + } + + + + @Test + public void testSimple() { + executeJspCompile("testSimple", "simple_jsp.java"); + } + + + @Test + public void testUriroot() throws Exception { + executeJspCompile("testUriroot", "uriroot_jsp.java"); + } + + + @Test + public void testXml() throws Exception { + executeJspCompile("testXml", "xml_jsp.java"); + } + + + /** + * try a keyword in a file + */ + @Test + public void testKeyword() throws Exception { + executeJspCompile("testKeyword", "default_jsp.java"); + } + + + /** + * what happens to 1nvalid-classname + */ + @Test + public void testInvalidClassname() throws Exception { + executeJspCompile("testInvalidClassname", + "_1nvalid_0002dclassname_jsp.java"); + } + + + @Test + public void testNoTld() throws Exception { + try { + buildRule.executeTarget("testNoTld"); + fail("Not found"); + } catch (BuildException ex) { + assertEquals("Java returned: 9", ex.getMessage()); + } + } + + + @Test + public void testNotAJspFile() throws Exception { + buildRule.executeTarget("testNotAJspFile"); + } + + /** + * webapp test is currently broken, because it picks up + * on the missing_tld file, and bails. + */ + @Ignore("picks up on the missing_tld file, and incorrectly bails") + @Test + public void testWebapp() throws Exception { + buildRule.executeTarget("testWebapp"); + } + + /** + * run a target then verify the named file gets created + * + * @param target Description of Parameter + * @param javafile Description of Parameter + */ + protected void executeJspCompile(String target, String javafile) { + buildRule.executeTarget(target); + assertJavaFileCreated(javafile); + } + + + /** + * verify that a named file was created + * + * @param filename Description of Parameter + */ + protected void assertJavaFileCreated(String filename) { + File file = getOutputFile(filename); + assertTrue("file " + filename + " not found", file.exists()); + assertTrue("file " + filename + " is empty", file.length() > 0); + } + + /** + * Gets the OutputFile attribute of the JspcTest object + * + * @param subpath Description of Parameter + * @return The OutputFile value + */ + protected File getOutputFile(String subpath) { + return new File(buildRule.getProject().getProperty("output"), subpath); + } + + /** + * verify that we select the appropriate mangler + */ + @Test + public void testJasperNameManglerSelection() { + JspCompilerAdapter adapter= + JspCompilerAdapterFactory.getCompiler("jasper", null,null); + JspMangler mangler=adapter.createMangler(); + assertTrue(mangler instanceof JspNameMangler); + adapter= JspCompilerAdapterFactory.getCompiler("jasper41", null, null); + mangler = adapter.createMangler(); + assertTrue(mangler instanceof Jasper41Mangler); + } + + @Test + public void testJasper41() { + JspMangler mangler = new Jasper41Mangler(); + //java keywords are not special + assertMapped(mangler, "for.jsp", "for_jsp"); + //underscores go in front of invalid start chars + assertMapped(mangler, "0.jsp", "_0_jsp"); + //underscores at the front get an underscore too + assertMapped(mangler, "_.jsp", "___jsp"); + //non java char at start => underscore then the the _hex value + assertMapped(mangler, "-.jsp", "__0002d_jsp"); + //and paths are stripped + char s = File.separatorChar; + assertMapped(mangler, "" + s + s + "somewhere" + s + "file" + s + "index.jsp", "index_jsp"); + } + + /** + * assert our mapping rules + * @param mangler + * @param filename + * @param classname + */ + protected void assertMapped(JspMangler mangler, String filename, String classname) { + String mappedname = mangler.mapJspToJavaName(new File(filename)); + assertTrue(filename+" should have mapped to "+classname + +" but instead mapped to "+mappedname, + classname.equals(mappedname)); + } + + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java new file mode 100644 index 00000000..53da2af4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import java.io.File; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class Native2AsciiTest { + + private final static String BUILD_XML = + "src/etc/testcases/taskdefs/optional/native2ascii/build.xml"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(BUILD_XML); + } + + @After + public void tearDown() { + buildRule.executeTarget("tearDown"); + } + + @Test + public void testIso8859_1() throws java.io.IOException { + buildRule.executeTarget("testIso8859-1"); + File in = buildRule.getProject().resolveFile("expected/iso8859-1.test"); + File out = new File(buildRule.getProject().getProperty("output"), "iso8859-1.test"); + assertTrue(FileUtils.getFileUtils().contentEquals(in, out, true)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java new file mode 100644 index 00000000..7056ca90 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java @@ -0,0 +1,235 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.util.Properties; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +/** + * JUnit testcase that exercises the optional PropertyFile task in ant. + * (this is really more of a functional test so far.., but it's enough to let + * me start refactoring...) + * + *created October 2, 2001 + */ + +public class PropertyFileTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() throws Exception { + buildRule.configureProject(projectFilePath); + buildRule.executeTarget("setUp"); + initTestPropFile(); + initBuildPropFile(); + buildRule.configureProject(projectFilePath); + buildRule.getProject().setProperty(valueDoesNotGetOverwrittenPropertyFileKey, + valueDoesNotGetOverwrittenPropertyFile); + } + + + @Test + public void testNonExistingFile() { + PropertyFile props = new PropertyFile(); + props.setProject( buildRule.getProject() ); + File file = new File("this-file-does-not-exist.properties"); + props.setFile(file); + assertFalse("Properties file exists before test.", file.exists()); + props.execute(); + assertTrue("Properties file does not exist after test.", file.exists()); + file.delete(); + } + + /** + * A unit test for JUnit- Exercises the propertyfile tasks ability to + * update properties that are already defined- + */ + @Test + public void testUpdatesExistingProperties() throws Exception { + Properties beforeUpdate = getTestProperties(); + assertEquals(FNAME, beforeUpdate.getProperty(FNAME_KEY)); + assertEquals(LNAME, beforeUpdate.getProperty(LNAME_KEY)); + assertEquals(EMAIL, beforeUpdate.getProperty(EMAIL_KEY)); + assertEquals(null, beforeUpdate.getProperty(PHONE_KEY)); + assertEquals(null, beforeUpdate.getProperty(AGE_KEY)); + assertEquals(null, beforeUpdate.getProperty(DATE_KEY)); + + // ask ant to update the properties... + buildRule.executeTarget("update-existing-properties"); + + Properties afterUpdate = getTestProperties(); + assertEquals(NEW_FNAME, afterUpdate.getProperty(FNAME_KEY)); + assertEquals(NEW_LNAME, afterUpdate.getProperty(LNAME_KEY)); + assertEquals(NEW_EMAIL, afterUpdate.getProperty(EMAIL_KEY)); + assertEquals(NEW_PHONE, afterUpdate.getProperty(PHONE_KEY)); + assertEquals(NEW_AGE, afterUpdate.getProperty(AGE_KEY)); + assertEquals(NEW_DATE, afterUpdate.getProperty(DATE_KEY)); + } + + @Test + public void testDeleteProperties() throws Exception { + Properties beforeUpdate = getTestProperties(); + assertEquals("Property '" + FNAME_KEY + "' should exist before deleting", + FNAME, beforeUpdate.getProperty(FNAME_KEY)); + assertEquals("Property '" + LNAME_KEY + "' should exist before deleting", + LNAME, beforeUpdate.getProperty(LNAME_KEY)); + + buildRule.executeTarget("delete-properties"); + Properties afterUpdate = getTestProperties(); + + assertEquals("Property '" + LNAME_KEY + "' should exist after deleting", + LNAME, afterUpdate.getProperty(LNAME_KEY)); + assertNull("Property '" + FNAME_KEY + "' should be deleted", + afterUpdate.getProperty(FNAME_KEY)); + } + + @Test + public void testExerciseDefaultAndIncrement() throws Exception { + buildRule.executeTarget("exercise"); + assertEquals("3",buildRule.getProject().getProperty("int.with.default")); + assertEquals("1",buildRule.getProject().getProperty("int.without.default")); + assertEquals("-->",buildRule.getProject().getProperty("string.with.default")); + assertEquals(".",buildRule.getProject().getProperty("string.without.default")); + assertEquals("2002/01/21 12:18", buildRule.getProject().getProperty("ethans.birth")); + assertEquals("2003/01/21", buildRule.getProject().getProperty("first.birthday")); + assertEquals("0124", buildRule.getProject().getProperty("olderThanAWeek")); + assertEquals("37", buildRule.getProject().getProperty("existing.prop")); + assertEquals("6",buildRule.getProject().getProperty("int.without.value")); + } + + @Test + public void testValueDoesNotGetOverwritten() { + // this test shows that the bug report 21505 is fixed + buildRule.executeTarget("bugDemo1"); + buildRule.executeTarget("bugDemo2"); + assertEquals("5", buildRule.getProject().getProperty("foo")); + } + + + @Test + @Ignore("Previously commented out") + public void testDirect() throws Exception { + PropertyFile pf = new PropertyFile(); + pf.setProject(buildRule.getProject()); + pf.setFile(new File(System.getProperty("root"), testPropsFilePath)); + PropertyFile.Entry entry = pf.createEntry(); + + entry.setKey("date"); + entry.setValue("123"); + PropertyFile.Entry.Type type = new PropertyFile.Entry.Type(); + type.setValue("date"); + entry.setType(type); + + entry.setPattern("yyyy/MM/dd"); + + PropertyFile.Entry.Operation operation = new PropertyFile.Entry.Operation(); + operation.setValue("+"); + pf.execute(); + + Properties props = getTestProperties(); + assertEquals("yeehaw", props.getProperty("date")); + } + + + private Properties getTestProperties() throws Exception { + Properties testProps = new Properties(); + FileInputStream propsFile = new FileInputStream(new File(buildRule.getOutputDir(), testPropsFilePath)); + testProps.load(propsFile); + propsFile.close(); + return testProps; + } + + + private void initTestPropFile() throws IOException { + Properties testProps = new Properties(); + testProps.put(FNAME_KEY, FNAME); + testProps.put(LNAME_KEY, LNAME); + testProps.put(EMAIL_KEY, EMAIL); + testProps.put("existing.prop", "37"); + + FileOutputStream fos = new FileOutputStream(new File(buildRule.getOutputDir(), testPropsFilePath)); + testProps.store(fos, "defaults"); + fos.close(); + } + + + private void initBuildPropFile() throws IOException { + Properties buildProps = new Properties(); + buildProps.put(testPropertyFileKey, testPropertyFile); + buildProps.put(FNAME_KEY, NEW_FNAME); + buildProps.put(LNAME_KEY, NEW_LNAME); + buildProps.put(EMAIL_KEY, NEW_EMAIL); + buildProps.put(PHONE_KEY, NEW_PHONE); + buildProps.put(AGE_KEY, NEW_AGE); + buildProps.put(DATE_KEY, NEW_DATE); + + FileOutputStream fos = new FileOutputStream(new File(buildRule.getOutputDir(), buildPropsFilePath)); + buildProps.store(fos, null); + fos.close(); + } + + private static final String + projectFilePath = "src/etc/testcases/taskdefs/optional/propertyfile.xml", + + testPropertyFile = "propertyfile.test.properties", + testPropertyFileKey = "test.propertyfile", + testPropsFilePath = testPropertyFile, + + valueDoesNotGetOverwrittenPropertyFile = "overwrite.test.properties", + valueDoesNotGetOverwrittenPropertyFileKey = "overwrite.test.propertyfile", + valueDoesNotGetOverwrittenPropsFilePath = valueDoesNotGetOverwrittenPropertyFile, + + buildPropsFilePath = "propertyfile.build.properties", + + FNAME = "Bruce", + NEW_FNAME = "Clark", + FNAME_KEY = "firstname", + + LNAME = "Banner", + NEW_LNAME = "Kent", + LNAME_KEY = "lastname", + + EMAIL = "incredible@hulk.com", + NEW_EMAIL = "kc@superman.com", + EMAIL_KEY = "email", + + NEW_PHONE = "(520) 555-1212", + PHONE_KEY = "phone", + + NEW_AGE = "30", + AGE_KEY = "age", + + NEW_DATE = "2001/01/01 12:45", + DATE_KEY = "date"; +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java new file mode 100644 index 00000000..cd7a4316 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class PvcsTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/pvcs.xml"); + } + + @Test + public void test1() { + try { + buildRule.executeTarget("test1"); + fail("Required argument repository not specified"); + } catch (BuildException ex) { + //TODO check exception message + } + } + + @Test + public void test2() { + buildRule.executeTarget("test2"); + } + + @Test + public void test3() { + buildRule.executeTarget("test3"); + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + } + + @Test + public void test5() { + buildRule.executeTarget("test5"); + } + + @Test + public void test6() { + try { + buildRule.executeTarget("test6"); + fail("Failed executing: /never/heard/of/a/directory/structure/like/this/pcli lvf -z " + + "-aw -pr//ct4serv2/pvcs/monitor /. Exception: /never/heard/of/a/directory/structure/like/this/pcli: not found"); + } catch(BuildException ex) { + //TODO assert exception message + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java new file mode 100644 index 00000000..b6c09a5c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java @@ -0,0 +1,132 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.FileUtilities; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.util.Properties; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNull; +import static org.junit.Assume.assumeTrue; + +/** + * JUnit Testcase for the optional replaceregexp task. + * + */ +public class ReplaceRegExpTest { + private static final String PROJECT_PATH = "src/etc/testcases/taskdefs/optional"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(PROJECT_PATH + "/replaceregexp.xml"); + } + + @Test + public void testReplace() throws IOException { + Properties original = new Properties(); + FileInputStream propsFile = null; + try { + propsFile = new FileInputStream(new File(buildRule.getProject().getBaseDir() + "/replaceregexp.properties")); + original.load(propsFile); + } finally { + if (propsFile != null) { + propsFile.close(); + propsFile = null; + } + } + + assertEquals("Def", original.get("OldAbc")); + + buildRule.executeTarget("testReplace"); + + Properties after = new Properties(); + try { + propsFile = new FileInputStream(new File(buildRule.getOutputDir(), "test.properties")); + after.load(propsFile); + } finally { + if (propsFile != null) { + propsFile.close(); + } + } + + assertNull(after.get("OldAbc")); + assertEquals("AbcDef", after.get("NewProp")); + } + + // inspired by bug 22541 + @Test + public void testDirectoryDateDoesNotChange() { + buildRule.executeTarget("touchDirectory"); + File myFile = buildRule.getOutputDir(); + long timeStampBefore = myFile.lastModified(); + buildRule.executeTarget("testDirectoryDateDoesNotChange"); + long timeStampAfter = myFile.lastModified(); + assertEquals("directory date should not change", + timeStampBefore, timeStampAfter); + } + + @Test + public void testDontAddNewline1() throws IOException { + buildRule.executeTarget("testDontAddNewline1"); + assertEquals(FileUtilities.getFileContents(new File(buildRule.getOutputDir(), "test.properties")), + FileUtilities.getFileContents(new File(buildRule.getProject().getBaseDir(), "replaceregexp2.result.properties"))); + } + + @Test + public void testDontAddNewline2() throws IOException { + buildRule.executeTarget("testDontAddNewline2"); + assertEquals(FileUtilities.getFileContents(new File(buildRule.getOutputDir(), "test.properties")), + FileUtilities.getFileContents(new File(buildRule.getProject().getBaseDir(), "replaceregexp2.result.properties"))); + } + + @Test + public void testNoPreserveLastModified() throws Exception { + buildRule.executeTarget("lastModifiedSetup"); + File testFile = new File(buildRule.getOutputDir(), "test.txt"); + assumeTrue(testFile.setLastModified(testFile.lastModified() + - (FileUtils.getFileUtils().getFileTimestampGranularity() * 3))); + long ts1 = testFile.lastModified(); + buildRule.executeTarget("testNoPreserve"); + assertTrue(ts1 < testFile.lastModified()); + } + + @Test + public void testPreserveLastModified() throws Exception { + buildRule.executeTarget("lastModifiedSetup"); + File testFile = new File(buildRule.getOutputDir(), "test.txt"); + assumeTrue(testFile.setLastModified(testFile.lastModified() + - (FileUtils.getFileUtils().getFileTimestampGranularity() * 3))); + long ts1 = testFile.lastModified(); + buildRule.executeTarget("testPreserve"); + assertEquals(ts1 , testFile.lastModified()); + } + +}// ReplaceRegExpTest diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java new file mode 100644 index 00000000..41803de6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Tests using an undefined reference. + * + * @since Ant 1.6 + */ +public class RhinoReferenceTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject( + "src/etc/testcases/taskdefs/optional/script_reference.xml"); + } + + @Test + public void testScript() { + buildRule.executeTarget("script"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java new file mode 100644 index 00000000..35576dcb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Tests the examples of the <script> task docs. + * + * @since Ant 1.5.2 + */ +public class RhinoScriptTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/script.xml"); + } + + @Test + public void testExample1() { + buildRule.executeTarget("example1"); + int index = buildRule.getLog().indexOf("1"); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("4", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("9", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("16", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("25", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("36", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("49", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("64", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("81", index); + assertTrue(index > -1); + index = buildRule.getLog().indexOf("100", index); + assertTrue(index > -1); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java new file mode 100644 index 00000000..ac4462d5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.Execute; +import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; +import org.apache.tools.ant.types.Commandline; + +import org.junit.Test; + +import static org.junit.Assert.fail; +import static org.apache.tools.ant.AntAssert.assertContains; + +public class RpmTest { + + @Test + public void testShouldThrowExceptionWhenRpmFails() throws Exception { + Rpm rpm = new MyRpm(); + rpm.setProject(new org.apache.tools.ant.Project()); + rpm.setFailOnError(true); + // execute + try { + rpm.execute(); + fail("should have thrown a build exception"); + } catch (BuildException ex) { + assertContains("' failed with exit code 2", ex.getMessage()); + } + } + + @Test + public void testShouldNotThrowExceptionWhenRpmFails() throws Exception { + Rpm rpm = new MyRpm(); + rpm.execute(); + } + + // override some of the code so we can test the handling of the + // return code only. + public static class MyRpm extends Rpm { + protected Execute getExecute(Commandline toExecute, + ExecuteStreamHandler streamhandler) { + return new Execute() { + public int execute() { + // 2 is != 0 and even, so it is considered + // failure on any platform currently supported + // by Execute#isFailure. + return 2; + } + }; + } + + public void log(String msg, int msgLevel) { + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java new file mode 100644 index 00000000..667c8904 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java @@ -0,0 +1,128 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + * Test schema validation + */ + +public class SchemaValidateTest { + + /** + * where tasks run + */ + private final static String TASKDEFS_DIR = + "src/etc/testcases/taskdefs/optional/"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "schemavalidate.xml"); + } + + /** + * test with no namespace + */ + @Test + public void testNoNamespace() throws Exception { + buildRule.executeTarget("testNoNamespace"); + } + + /** + * add namespace awareness. + */ + @Test + public void testNSMapping() throws Exception { + buildRule.executeTarget("testNSMapping"); + } + + @Test + public void testNoEmptySchemaNamespace() throws Exception { + try { + buildRule.executeTarget("testNoEmptySchemaNamespace"); + fail("Empty namespace URI"); + } catch (BuildException ex) { + AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_NO_URI, ex.getMessage()); + } + } + + @Test + public void testNoEmptySchemaLocation() throws Exception { + try { + buildRule.executeTarget("testNoEmptySchemaLocation"); + fail("Empty schema location"); + } catch (BuildException ex) { + AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_NO_LOCATION, + ex.getMessage()); + } + } + + @Test + public void testNoFile() throws Exception { + try { + buildRule.executeTarget("testNoFile"); + fail("No file at file attribute"); + } catch (BuildException ex) { + AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_NO_FILE, + ex.getMessage()); + } + } + + @Test + public void testNoDoubleSchemaLocation() throws Exception { + try { + buildRule.executeTarget("testNoDoubleSchemaLocation"); + fail("Two locations for schemas"); + } catch (BuildException ex) { + AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_TWO_LOCATIONS, + ex.getMessage()); + } + } + + @Test + public void testNoDuplicateSchema() throws Exception { + try { + buildRule.executeTarget("testNoDuplicateSchema"); + fail("duplicate schemas with different values"); + } catch (BuildException ex) { + AntAssert.assertContains(SchemaValidate.ERROR_DUPLICATE_SCHEMA, + ex.getMessage()); + } + } + + @Test + public void testEqualsSchemasOK() throws Exception { + buildRule.executeTarget("testEqualsSchemasOK"); + } + + @Test + public void testFileset() throws Exception { + buildRule.executeTarget("testFileset"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java new file mode 100644 index 00000000..02281eb6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java @@ -0,0 +1,129 @@ +package org.apache.tools.ant.taskdefs.optional; + +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.InputStream; +import java.security.Permission; + +import junit.framework.AssertionFailedError; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.XSLTLiaison; +import org.apache.tools.ant.taskdefs.XSLTLogger; +import org.apache.tools.ant.util.JAXPUtils; +import org.junit.After; +import org.junit.Assume; +import org.junit.Test; + +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/** + * TraX XSLTLiaison testcase + */ +public class TraXLiaisonTest extends AbstractXSLTLiaisonTest + implements XSLTLogger { + + + @After + public void tearDown() { + File f = new File("xalan2-redirect-out.tmp"); + if (f.exists()) { + f.delete(); + } + } + + public XSLTLiaison createLiaison() throws Exception { + TraXLiaison l = new TraXLiaison(); + l.setLogger(this); + return l; + } + + @Test + public void testXalan2Redirect() throws Exception { + try { + getClass().getClassLoader().loadClass("org.apache.xalan.lib.Redirect"); + } catch (Exception exc) { + Assume.assumeNoException("xalan redirect is not on the classpath", exc); + } + File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl"); + liaison.setStylesheet(xsl); + File out = new File("xalan2-redirect-out-dummy.tmp"); + File in = getFile("/taskdefs/optional/xsltliaison-in.xsl"); + ClassLoader orig = Thread.currentThread().getContextClassLoader(); + try { + liaison.addParam("xalan-version", "2"); + // Use the JRE's Xerces, not lib/optional/xerces.jar: + Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) { + public InputStream getResourceAsStream(String name) { + if (name.startsWith("META-INF/services/")) { + // work around JAXP #6723276 in JDK 6 + return new ByteArrayInputStream(new byte[0]); + } + return super.getResourceAsStream(name); + } + }); + // Tickle #52382: + System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); + liaison.transform(in, out); + } finally { + out.delete(); + Thread.currentThread().setContextClassLoader(orig); + System.setSecurityManager(null); + } + } + + @Test + public void testMultipleTransform() throws Exception { + File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl"); + liaison.setStylesheet(xsl); + liaison.addParam("param", "value"); + File in = getFile("/taskdefs/optional/xsltliaison-in.xml"); + // test for 10 consecutives transform + for (int i = 0; i < 50; i++){ + File out = new File("xsltliaison" + i + ".tmp"); + try { + liaison.transform(in, out); + } catch (Exception e){ + throw new BuildException("failed in transform " + i, e); + } finally { + out.delete(); + } + } + } + + @Test + public void testSystemId(){ + File file = null; + if ( File.separatorChar == '\\' ){ + file = new File("d:\\jdk"); + } else { + file = new File("/user/local/bin"); + } + String systemid = JAXPUtils.getSystemId(file); + assertTrue("SystemIDs should start by file:/", systemid.startsWith("file:/")); + assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////")); + } + + public void log(String message) { + throw new AssertionFailedError("Liaison sent message: "+message); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java new file mode 100644 index 00000000..c9948bb9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Tests the XMLValidate optional task with nested external catalogs. + * + * @see XmlValidateTest + * @since Ant 1.6 + */ +public class XmlValidateCatalogTest { + + /** + * where tasks run + */ + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "xmlvalidate.xml"); + } + + + /** + * catalogfiles fileset should be ignored + * if resolver.jar is not present, but will + * be used if it is. either way, test should + * work b/c we have a nested dtd with the same + * entity + */ + @Test + public void testXmlCatalogFiles() { + buildRule.executeTarget("xmlcatalogfiles"); + } + + /** + * Test nested catalogpath. + * It should be ignored if resolver.jar is not + * present, but will be used if it is. either + * way, test should work b/c we have a nested + * dtd with the same entity + */ + @Test + public void testXmlCatalogPath() { + buildRule.executeTarget("xmlcatalogpath"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java new file mode 100644 index 00000000..58f7a4b1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java @@ -0,0 +1,193 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.internal.AssumptionViolatedException; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests the XMLValidate optional task, by running targets in the test script + * <code>src/etc/testcases/taskdefs/optional/xmlvalidate.xml</code> + * <p> + * + * @see XmlValidateCatalogTest + * @since Ant 1.5 + */ +public class XmlValidateTest { + + /** + * where tasks run + */ + private final static String TASKDEFS_DIR = + "src/etc/testcases/taskdefs/optional/"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "xmlvalidate.xml"); + } + + /** + * Basic inline 'dtd' element test. + */ + @Test + public void testValidate() throws Exception { + buildRule.executeTarget("testValidate"); + } + + /** + * Test indirect validation. + */ + @Test + public void testDeepValidate() throws Exception { + buildRule.executeTarget("testDeepValidate"); + } + + @Test + public void testXmlCatalog() { + buildRule.executeTarget("xmlcatalog"); + } + + @Test + public void testXmlCatalogViaRefid() { + buildRule.executeTarget("xmlcatalogViaRefid"); + } + + /** + * Test that the nested dtd element is used when resolver.jar is not + * present. This test should pass either way. + */ + @Test + public void testXmlCatalogFiles() { + buildRule.executeTarget("xmlcatalogfiles-override"); + } + + /** + * Test nested catalogpath. + * Test that the nested dtd element is used when resolver.jar is not + * present. This test should pass either way. + */ + @Test + public void testXmlCatalogPath() { + buildRule.executeTarget("xmlcatalogpath-override"); + } + + /** + * Test nested xmlcatalog definitions + */ + @Test + public void testXmlCatalogNested() { + buildRule.executeTarget("xmlcatalognested"); + } + + /** + * Test xml schema validation + */ + @Test + public void testXmlSchemaGood() throws BuildException { + try { + buildRule.executeTarget("testSchemaGood"); + } catch (BuildException e) { + if (e + .getMessage() + .endsWith(" doesn't recognize feature http://apache.org/xml/features/validation/schema") + || e.getMessage().endsWith( + " doesn't support feature http://apache.org/xml/features/validation/schema")) { + throw new AssumptionViolatedException("parser doesn't support schema"); + } else { + throw e; + } + } + } + /** + * Test xml schema validation + */ + @Test + public void testXmlSchemaBad() { + try { + buildRule.executeTarget("testSchemaBad"); + fail("Should throw BuildException because 'Bad Schema Validation'"); + + } catch (BuildException e) { + if (e + .getMessage() + .endsWith(" doesn't recognize feature http://apache.org/xml/features/validation/schema") + || e.getMessage().endsWith( + " doesn't support feature http://apache.org/xml/features/validation/schema")) { + throw new AssumptionViolatedException("parser doesn't support schema"); + } else { + assertTrue( + e.getMessage().indexOf("not a valid XML document") > -1); + } + } + } + + /** + * iso-2022-jp.xml is valid but wouldn't get recognized on systems + * with a different native encoding. + * + * Bug 11279 + */ + @Test + public void testIso2022Jp() { + buildRule.executeTarget("testIso2022Jp"); + } + + /** + * utf-8.xml is invalid as it contains non-UTF-8 characters, but + * would pass on systems with a native iso-8859-1 (or similar) + * encoding. + * + * Bug 11279 + */ + @Test + public void testUtf8() { + try { + buildRule.executeTarget("testUtf8"); + fail("Invalid characters in file"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + // Tests property element, using XML schema properties as an example. + @Test + public void testPropertySchemaForValidXML() { + buildRule.executeTarget("testProperty.validXML"); + } + + @Test + public void testPropertySchemaForInvalidXML() { + try { + buildRule.executeTarget("testProperty.invalidXML"); + fail("XML file does not satisfy schema"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java new file mode 100644 index 00000000..a5b71def --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + * Tests the {@link org.apache.tools.ant.taskdefs.XSLTProcess} task. + * TODO merge with {@link org.apache.tools.ant.taskdefs.StyleTest}? + * @since Ant 1.5 + */ +public class XsltTest { + + /** + * where tasks run + */ + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "xslt.xml"); + } + + + @Test + public void testCatchNoDtd() { + try { + buildRule.executeTarget("testCatchNoDtd"); + fail("Expected failure"); + } catch(BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void testCatalog() throws Exception { + buildRule.executeTarget("testCatalog"); + } + + @Test + public void testOutputProperty() throws Exception { + buildRule.executeTarget("testOutputProperty"); + } + + @Test + public void testXMLWithEntitiesInNonAsciiPath() throws Exception { + buildRule.executeTarget("testXMLWithEntitiesInNonAsciiPath"); + } + + /** + * check that the system id gets set properly on stylesheets. + * @throws Exception if something goes wrong. + */ + @Test + public void testStyleSheetWithInclude() throws Exception { + buildRule.executeTarget("testStyleSheetWithInclude"); + if (buildRule.getLog().indexOf("java.io.FileNotFoundException") != -1) { + fail("xsl:include was not found"); + } + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java new file mode 100644 index 00000000..95c1eb0b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java @@ -0,0 +1,213 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.depend; + +import java.io.File; +import java.util.Hashtable; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.FileUtilities; +import org.apache.tools.ant.types.FileSet; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Testcase for the Depend optional task. + * + */ +public class DependTest { + public static final String RESULT_FILESET = "result"; + + public static final String TEST_BUILD_FILE + = "src/etc/testcases/taskdefs/optional/depend/depend.xml"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TEST_BUILD_FILE); + } + + /** + * Test direct dependency removal + */ + @Test + public void testDirect() { + buildRule.executeTarget("src1setup"); + buildRule.executeTarget("compile"); + + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + + buildRule.executeTarget("testdirect"); + Hashtable files = getResultFiles(); + assertEquals("Depend did not leave correct number of files", 3, + files.size()); + assertTrue("Result did not contain A.class", + files.containsKey("A.class")); + assertTrue("Result did not contain D.class", + files.containsKey("D.class")); + } + + /** + * Test dependency traversal (closure) + */ + @Test + public void testClosure() { + buildRule.executeTarget("src1setup"); + buildRule.executeTarget("compile"); + + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + + buildRule.executeTarget("testclosure"); + Hashtable files = getResultFiles(); + assertTrue("Depend did not leave correct number of files", + files.size() <= 2); + assertTrue("Result did not contain D.class", + files.containsKey("D.class")); + } + + /** + * Test that inner class dependencies trigger deletion of the outer class + */ + @Test + public void testInner() { + buildRule.executeTarget("src2setup"); + buildRule.executeTarget("compile"); + + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + + + buildRule.executeTarget("testinner"); + assertEquals("Depend did not leave correct number of files", 0, + getResultFiles().size()); + } + + /** + * Test that multi-leve inner class dependencies trigger deletion of + * the outer class + */ + @Test + public void testInnerInner() { + buildRule.executeTarget("src3setup"); + buildRule.executeTarget("compile"); + + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + + buildRule.executeTarget("testinnerinner"); + assertEquals("Depend did not leave correct number of files", 0, + getResultFiles().size()); + } + + /** + * Test that an exception is thrown when there is no source + */ + @Test + public void testNoSource() { + try { + buildRule.executeTarget("testnosource"); + fail("Build exception expected: No source specified"); + } catch(BuildException ex) { + assertContains("srcdir attribute must be set", ex.getMessage()); + } + } + + /** + * Test that an exception is thrown when the source attribute is empty + */ + @Test + public void testEmptySource() { + try { + buildRule.executeTarget("testemptysource"); + fail("Build exception expected: No source specified"); + } catch(BuildException ex) { + assertContains("srcdir attribute must be non-empty", ex.getMessage()); + } + } + + /** + * Read the result fileset into a Hashtable + * + * @return a Hashtable containing the names of the files in the result + * fileset + */ + private Hashtable getResultFiles() { + FileSet resultFileSet = (FileSet) buildRule.getProject().getReference(RESULT_FILESET); + DirectoryScanner scanner = resultFileSet.getDirectoryScanner(buildRule.getProject()); + String[] scannedFiles = scanner.getIncludedFiles(); + Hashtable files = new Hashtable(); + for (int i = 0; i < scannedFiles.length; ++i) { + files.put(scannedFiles[i], scannedFiles[i]); + } + return files; + } + + + /** + * Test mutual dependency between inner and outer do not cause both to be + * deleted + */ + @Test + public void testInnerClosure() { + buildRule.executeTarget("testinnerclosure"); + assertEquals("Depend did not leave correct number of files", 4, + getResultFiles().size()); + } + + /** + * Test the operation of the cache + */ + @Test + public void testCache() { + buildRule.executeTarget("testcache"); + } + + /** + * Test the detection and warning of non public classes + */ + @Test + public void testNonPublic() { + buildRule.executeTarget("src5setup"); + buildRule.executeTarget("compile"); + + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5); + FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5); + + buildRule.executeTarget("testnonpublic"); + String log = buildRule.getLog(); + assertContains("Expected warning about APrivate", + "The class APrivate in file", log); + assertContains("but has not been deleted because its source file " + + "could not be determined", + "The class APrivate in file", log); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java new file mode 100644 index 00000000..6abc4f2d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java @@ -0,0 +1,87 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.i18n; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; + +import static org.junit.Assert.assertTrue; + +/** + * Tests the Translate task. + * + * @since Ant 1.6 + */ +public class TranslateTest { + + @Rule + public final BuildFileRule buildRule = new BuildFileRule(); + + static private final int BUF_SIZE = 32768; + + private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/i18n/translate"; + + + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "/translate.xml"); + } + + @Test + public void test1() throws IOException { + buildRule.executeTarget("test1"); + assertTrue("translation of "+ TASKDEFS_DIR + "/input/template.txt",compareFiles(new File(buildRule.getProject().getBaseDir(), "expected/de/template.txt"), + new File(buildRule.getOutputDir(), "de/template.txt"))); + } + private boolean compareFiles(File file1, File file2) throws IOException { + if (!file1.exists() || !file2.exists()) { + return false; + } + + if (file1.length() != file2.length()) { + return false; + } + + // byte - byte compare + byte[] buffer1 = new byte[BUF_SIZE]; + byte[] buffer2 = new byte[BUF_SIZE]; + + FileInputStream fis1 = new FileInputStream(file1); + FileInputStream fis2 = new FileInputStream(file2); + int index = 0; + int read = 0; + while ((read = fis1.read(buffer1)) != -1) { + fis2.read(buffer2); + for (int i = 0; i < read; ++i, ++index) { + if (buffer1[i] != buffer2[i]) { + return false; + } + } + } + return true; + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java new file mode 100644 index 00000000..be79262d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java @@ -0,0 +1,133 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.image; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; + + +/** + * Tests the Image task. + * + * @since Ant 1.5 + */ +public class ImageTest { + + private final static String TASKDEFS_DIR = + "src/etc/testcases/taskdefs/optional/image/"; + private final static String LARGEIMAGE = "largeimage.jpg"; + + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject(TASKDEFS_DIR + "image.xml"); + } + + + @Test + public void testEchoToLog() { + buildRule.executeTarget("testEchoToLog"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + } + + @Test + public void testSimpleScale(){ + buildRule.executeTarget("testSimpleScale"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + + File f = new File(buildRule.getOutputDir(), LARGEIMAGE); + assertTrue( + "Did not create "+f.getAbsolutePath(), + f.exists()); + + } + + @Test + public void testOverwriteTrue() throws InterruptedException { + buildRule.executeTarget("testSimpleScale"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + File f = new File(buildRule.getOutputDir(), LARGEIMAGE); + assumeTrue("Could not change file modificaiton date", + f.setLastModified(f.lastModified() - (FILE_UTILS.getFileTimestampGranularity() * 2))); + long lastModified = f.lastModified(); + buildRule.executeTarget("testOverwriteTrue"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + f = new File(buildRule.getOutputDir(), LARGEIMAGE); + long overwrittenLastModified = f.lastModified(); + assertTrue("File was not overwritten.", + lastModified < overwrittenLastModified); + } + + @Test + public void testOverwriteFalse() { + buildRule.executeTarget("testSimpleScale"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + File f = new File(buildRule.getOutputDir(), LARGEIMAGE); + long lastModified = f.lastModified(); + buildRule.executeTarget("testOverwriteFalse"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + f = new File(buildRule.getOutputDir(), LARGEIMAGE); + long overwrittenLastModified = f.lastModified(); + assertTrue("File was overwritten.", + lastModified == overwrittenLastModified); + } + + @Test + public void testSimpleScaleWithMapper() { + buildRule.executeTarget("testSimpleScaleWithMapper"); + AntAssert.assertContains("Processing File", buildRule.getLog()); + File f = new File(buildRule.getOutputDir(), "scaled-" + LARGEIMAGE); + assertTrue( + "Did not create "+f.getAbsolutePath(), + f.exists()); + + } + + @Test + @Ignore("Previously named in a manner to prevent execution") + public void testFailOnError() { + try { + buildRule.executeTarget("testFailOnError"); + AntAssert.assertContains("Unable to process image stream", buildRule.getLog()); + } + catch (RuntimeException re){ + assertTrue("Run time exception should say " + + "'Unable to process image stream'. :" + + re.toString(), + re.toString() + .indexOf("Unable to process image stream") > -1); + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java new file mode 100644 index 00000000..545b7cbc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.jdepend; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcase for the JDepend optional task. + * + */ +public class JDependTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject( + "src/etc/testcases/taskdefs/optional/jdepend/jdepend.xml"); + } + + /** + * Test simple + */ + @Test + public void testSimple() { + buildRule.executeTarget("simple"); + AntAssert.assertContains("Package: org.apache.tools.ant.util.facade", + buildRule.getOutput()); + } + + /** + * Test xml + */ + @Test + public void testXml() { + buildRule.executeTarget("xml"); + AntAssert.assertContains("<DependsUpon>", buildRule.getOutput()); + } + + /** + * Test fork + * - forked output goes to log + */ + @Test + public void testFork() { + buildRule.executeTarget("fork"); + AntAssert.assertContains("Package: org.apache.tools.ant.util.facade", buildRule.getLog()); + } + + /** + * Test fork xml + */ + @Test + public void testForkXml() { + buildRule.executeTarget("fork-xml"); + AntAssert.assertContains("<DependsUpon>", buildRule.getLog()); + } + + /** + * Test timeout + */ + @Test + public void testTimeout() { + buildRule.executeTarget("fork-xml"); + AntAssert.assertContains( "JDepend FAILED - Timed out", buildRule.getLog()); + } + + + /** + * Test timeout without timing out + */ + @Test + public void testTimeoutNot() { + buildRule.executeTarget("fork-timeout-not"); + AntAssert.assertContains("Package: org.apache.tools.ant.util.facade", buildRule.getLog()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java new file mode 100644 index 00000000..52a12ecc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + + +import static org.junit.Assert.fail; +import static org.junit.Assert.assertArrayEquals; + +import org.junit.Test; + +/** + * + * @author Marian Petras + */ +public class BatchTestTest { + + @Test + public void testParseTestMethodNamesList() { + try { + JUnitTest.parseTestMethodNamesList(null); + fail("IllegalArgumentException expected when the param is <null>"); + } catch (IllegalArgumentException ex) { + //this is an expected exception + } + + assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList("")); + assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(" ")); + assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(" ")); + + checkParseCausesIAE(","); + checkParseCausesIAE(" ,"); + checkParseCausesIAE(", "); + checkParseCausesIAE(" , "); + checkParseCausesIAE(",a"); + checkParseCausesIAE(" ,a"); + checkParseCausesIAE(" ,a"); + checkParseCausesIAE(" , a"); + checkParseCausesIAE(" ,a "); + checkParseCausesIAE(" ,a ,"); + checkParseCausesIAE("ab,,cd"); + checkParseCausesIAE("ab, ,cd"); + checkParseCausesIAE("ab, ,cd"); + checkParseCausesIAE("ab, ,cd,"); + checkParseCausesIAE(",ab, ,cd,"); + + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc,")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc, ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ,")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc , ")); + assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc ,")); + + /* legal Java identifiers: */ + assertArrayEquals(new String[] {"a"}, JUnitTest.parseTestMethodNamesList("a")); + assertArrayEquals(new String[] {"a1"}, JUnitTest.parseTestMethodNamesList("a1")); + assertArrayEquals(new String[] {"a$"}, JUnitTest.parseTestMethodNamesList("a$")); + assertArrayEquals(new String[] {"a$1"}, JUnitTest.parseTestMethodNamesList("a$1")); + assertArrayEquals(new String[] {"_bc"}, JUnitTest.parseTestMethodNamesList("_bc")); + assertArrayEquals(new String[] {"___"}, JUnitTest.parseTestMethodNamesList("___")); + + /* illegal Java identifiers: */ + checkParseCausesIAE("1"); + checkParseCausesIAE("1a"); + checkParseCausesIAE("1ab"); + checkParseCausesIAE("1abc"); + checkParseCausesIAE("1abc d"); + checkParseCausesIAE("1abc de"); + checkParseCausesIAE("1abc def"); + checkParseCausesIAE("1abc def,"); + checkParseCausesIAE(",1abc def"); + + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def,")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc, def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc, def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc ,def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc ,def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc , def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc , def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc,def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc,def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc, def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc, def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc ,def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc ,def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def ")); + assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def ,")); + } + + private static void checkParseCausesIAE(String param) { + try { + JUnitTest.parseTestMethodNamesList(param); + fail("IllegalArgumentException expected when the param is \"" + param + '"'); + } catch (IllegalArgumentException ex) { + //this is an expected exception + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java new file mode 100644 index 00000000..b72f69cc --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import static org.junit.Assert.assertEquals; + +import java.io.IOException; +import java.io.InputStream; + +import javax.xml.parsers.DocumentBuilder; + +import org.apache.tools.ant.util.JAXPUtils; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +public class DOMUtilTest { + + @Test + public void testListChildNodes() throws SAXException, IOException { + DocumentBuilder db = JAXPUtils.getDocumentBuilder(); + InputStream is = this.getClass().getClassLoader().getResourceAsStream("taskdefs/optional/junit/matches.xml"); + Document doc = db.parse(is); + NodeList nl = DOMUtil.listChildNodes(doc.getDocumentElement(), new FooNodeFilter(), true); + assertEquals("expecting 3", 3, nl.getLength()); + } + + public class FooNodeFilter implements DOMUtil.NodeFilter { + public boolean accept(Node node) { + if (node.getNodeName().equals("foo")) { + return true; + } + return false; + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java new file mode 100644 index 00000000..4baf7418 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import static org.junit.Assert.assertSame; + +import org.junit.Test; + +/** + * Test to ensure that the classloader loading JUnit testcase + * is also the context classloader. + * + */ +public class JUnitClassLoaderTest { + + @Test + public void testContextClassLoader(){ + ClassLoader context = Thread.currentThread().getContextClassLoader(); + ClassLoader caller = getClass().getClassLoader(); + assertSame(context, caller); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java new file mode 100644 index 00000000..c5b6feb9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java @@ -0,0 +1,211 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.FileReader; +import java.io.InputStream; +import java.net.URL; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Small testcase for the junitreporttask. + * First test added to reproduce an fault, still a lot to improve + * + */ +public class JUnitReportTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/junitreport.xml"); + } + + /** + * Verifies that no empty junit-noframes.html is generated when frames + * output is selected via the default. + * Needs reports1 task from junitreport.xml. + */ + @Test + public void testNoFileJUnitNoFrames() { + buildRule.executeTarget("reports1"); + assertFalse("No file junit-noframes.html expected", (new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/junit-noframes.html").exists())); + + } + + public void assertIndexCreated() { + if (!new File(buildRule.getProject().getProperty("output"), "html/index.html").exists()) { + fail("No file index file found"); + } + + } + + + @Test + public void testEmptyFile() throws Exception { + buildRule.executeTarget("testEmptyFile"); + assertIndexCreated(); + assertContains("Required text not found in log", XMLResultAggregator.WARNING_EMPTY_FILE, buildRule.getLog()); + } + + @Test + public void testIncompleteFile() throws Exception { + buildRule.executeTarget("testIncompleteFile"); + assertIndexCreated(); + assertContains("Required text not found in log", XMLResultAggregator.WARNING_IS_POSSIBLY_CORRUPTED, buildRule.getLog()); + } + + @Test + public void testWrongElement() throws Exception { + buildRule.executeTarget("testWrongElement"); + assertIndexCreated(); + assertContains("Required text not found in log", XMLResultAggregator.WARNING_INVALID_ROOT_ELEMENT, buildRule.getLog()); + } + + // Bugzilla Report 34963 + @Test + public void testStackTraceLineBreaks() throws Exception { + buildRule.executeTarget("testStackTraceLineBreaks"); + assertIndexCreated(); + FileReader r = null; + try { + r = new FileReader(new File(buildRule.getOutputDir(), "html/sampleproject/coins/0_CoinTest.html")); + String report = FileUtils.readFully(r); + assertContains("output must contain <br>:\n" + report, "junit.framework.AssertionFailedError: DOEG<br>", report); + assertContains("#51049: output must translate line breaks:\n" + report, "cur['line.separator'] = '\\r\\n';", report); + } finally { + FileUtils.close(r); + } + } + + + // Bugzilla Report 38477 + @Test + public void testSpecialSignsInSrcPath() throws Exception { + buildRule.executeTarget("testSpecialSignsInSrcPath"); + File reportFile = new File(buildRule.getOutputDir(), "html/index.html"); + // tests one the file object + assertTrue("No index.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } + + @Test + public void testSpecialSignsInHtmlPath() throws Exception { + buildRule.executeTarget("testSpecialSignsInHtmlPath"); + File reportFile = new File(buildRule.getOutputDir(), "html# $%\u00A7&-!report/index.html"); + // tests one the file object + assertTrue("No index.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } + + //Bugzilla Report 39708 + @Test + public void testWithStyleFromDir() throws Exception { + buildRule.executeTarget("testWithStyleFromDir"); + File reportFile = new File(buildRule.getOutputDir(), "html/index.html"); + // tests one the file object + assertTrue("No index.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } + + //Bugzilla Report 40021 + @Test + public void testNoFrames() throws Exception { + buildRule.executeTarget("testNoFrames"); + File reportFile = new File(buildRule.getOutputDir(), "html/junit-noframes.html"); + // tests one the file object + assertTrue("No junit-noframes.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } + //Bugzilla Report 39708 + @Test + public void testWithStyleFromDirAndXslImport() throws Exception { + buildRule.executeTarget("testWithStyleFromDirAndXslImport"); + File reportFile = new File(buildRule.getOutputDir(), "html/index.html"); + // tests one the file object + assertTrue("No index.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } + + @Test + public void testWithStyleFromClasspath() throws Exception { + buildRule.executeTarget("testWithStyleFromClasspath"); + File reportFile = new File(buildRule.getOutputDir(), "html/index.html"); + // tests one the file object + assertTrue("No index.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } + + @Test + public void testWithParams() throws Exception { + buildRule.executeTarget("testWithParams"); + assertContains("key1=value1,key2=value2", buildRule.getLog()); + File reportFile = new File(buildRule.getOutputDir(), "html/index.html"); + // tests one the file object + assertTrue("No index.html present. Not generated?", reportFile.exists() ); + assertTrue("Cant read the report file.", reportFile.canRead() ); + assertTrue("File shouldn't be empty.", reportFile.length() > 0 ); + // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report + URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) ); + InputStream reportStream = reportUrl.openStream(); + assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java new file mode 100644 index 00000000..61504ad1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java @@ -0,0 +1,398 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +import static org.apache.tools.ant.AntAssert.assertNotContains; +import static org.apache.tools.ant.AntAssert.assertContains; + +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.xpath.XPath; +import javax.xml.xpath.XPathConstants; +import javax.xml.xpath.XPathFactory; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.JavaEnvUtils; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; + +public class JUnitTaskTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + /** + * The JUnit setup method. + */ + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml"); + } + + @Test + public void testCrash() { + buildRule.executeTarget("crash"); + assertEquals("true", buildRule.getProject().getProperty("crashed")); + } + + @Test + public void testNoCrash() { + buildRule.executeTarget("nocrash"); + assertNull(buildRule.getProject().getProperty("crashed")); + } + + @Test + public void testTimeout() { + buildRule.executeTarget("timeout"); + assertEquals("true", buildRule.getProject().getProperty("timeout")); + } + + @Test + public void testNoTimeout() { + buildRule.executeTarget("notimeout"); + assertNull(buildRule.getProject().getProperty("timeout")); + } + + @Test + public void testNonForkedCapture() throws IOException { + buildRule.executeTarget("capture"); + assertNoPrint(buildRule.getLog(), "log"); + assertNoPrint(buildRule.getFullLog(), "debug log"); + } + + @Test + public void testForkedCapture() throws IOException { + buildRule.getProject().setProperty("fork", "true"); + testNonForkedCapture(); + // those would fail because of the way BuildFileRule captures output + assertNoPrint(buildRule.getOutput(), "output"); + assertNoPrint(buildRule.getError(), "error output"); + assertOutput(); + } + + @Test + public void testBatchTestForkOnceToDir() { + assertResultFilesExist("testBatchTestForkOnceToDir", ".xml"); + } + + /** Bugzilla Report 32973 */ + @Test + public void testBatchTestForkOnceExtension() { + assertResultFilesExist("testBatchTestForkOnceExtension", ".foo"); + } + + + /* Bugzilla Report 42984 */ + //TODO This scenario works from command line, but not from JUnit ... + // Running these steps from the junit.xml-directory work + // $ ant -f junit.xml failureRecorder.prepare + // $ ant -f junit.xml failureRecorder.runtest + // $ ant -f junit.xml failureRecorder.runtest + // $ ant -f junit.xml failureRecorder.fixing + // $ ant -f junit.xml failureRecorder.runtest + // $ ant -f junit.xml failureRecorder.runtest + // But running the JUnit testcase fails in 4th run. + @Test + public void testFailureRecorder() { + if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_5)) { + try { + Class<?> clazz =Class.forName("junit.framework.JUnit4TestAdapter"); + Assume.assumeFalse("Skipping test since it fails with JUnit 4", clazz != null); + } catch (ClassNotFoundException e) { + // OK, this is JUnit3, can run test + } + } + + File testDir = new File(buildRule.getOutputDir(), "out"); + File collectorFile = new File(buildRule.getOutputDir(), + "out/FailedTests.java"); + + // ensure that there is a clean test environment + assertFalse("Test directory '" + testDir.getAbsolutePath() + + "' must not exist before the test preparation.", + testDir.exists()); + assertFalse("The collector file '" + + collectorFile.getAbsolutePath() + + "'must not exist before the test preparation.", + collectorFile.exists()); + + + // prepare the test environment + buildRule.executeTarget("failureRecorder.prepare"); + assertTrue("Test directory '" + testDir.getAbsolutePath() + + "' was not created.", testDir.exists()); + assertTrue("There should be one class.", + (new File(testDir, "A.class")).exists()); + assertFalse("The collector file '" + + collectorFile.getAbsolutePath() + + "' should not exist before the 1st run.", + collectorFile.exists()); + + + // 1st junit run: should do all tests - failing and not failing tests + buildRule.executeTarget("failureRecorder.runtest"); + assertTrue("The collector file '" + collectorFile.getAbsolutePath() + + "' should exist after the 1st run.", + collectorFile.exists()); + // the passing test cases + buildRule.executeTarget("A.test01"); + assertContains("1st run: should run A.test01", buildRule.getOutput()); + buildRule.executeTarget("B.test05"); + assertContains("1st run: should run B.test05", buildRule.getOutput()); + buildRule.executeTarget("B.test06"); + assertContains("1st run: should run B.test06", buildRule.getOutput()); + buildRule.executeTarget("C.test07"); + assertContains("1st run: should run C.test07", buildRule.getOutput()); + buildRule.executeTarget("C.test08"); + assertContains("1st run: should run C.test08", buildRule.getOutput()); + buildRule.executeTarget("C.test09"); + assertContains("1st run: should run C.test09", buildRule.getOutput()); + // the failing test cases + buildRule.executeTarget("A.test02"); + assertContains("1st run: should run A.test02", buildRule.getOutput()); + buildRule.executeTarget("A.test03"); + assertContains("1st run: should run A.test03", buildRule.getOutput()); + buildRule.executeTarget("B.test04"); + assertContains("1st run: should run B.test04", buildRule.getOutput()); + buildRule.executeTarget("D.test10"); + assertContains("1st run: should run D.test10", buildRule.getOutput()); + + + // 2nd junit run: should do only failing tests + buildRule.executeTarget("failureRecorder.runtest"); + assertTrue("The collector file '" + collectorFile.getAbsolutePath() + + "' should exist after the 2nd run.", + collectorFile.exists()); + // the passing test cases + buildRule.executeTarget("A.test01"); + assertNotContains("2nd run: should not run A.test01", buildRule.getOutput()); + buildRule.executeTarget("B.test05"); + assertNotContains("2nd run: should not run A.test05", buildRule.getOutput()); + buildRule.executeTarget("B.test06"); + assertNotContains("2nd run: should not run B.test06", buildRule.getOutput()); + buildRule.executeTarget("C.test07"); + assertNotContains("2nd run: should not run C.test07", buildRule.getOutput()); + buildRule.executeTarget("C.test08"); + assertNotContains("2nd run: should not run C.test08", buildRule.getOutput()); + buildRule.executeTarget("C.test09"); + assertNotContains("2nd run: should not run C.test09", buildRule.getOutput()); + // the failing test cases + buildRule.executeTarget("A.test02"); + assertContains("2nd run: should run A.test02", buildRule.getOutput()); + buildRule.executeTarget("A.test03"); + assertContains("2nd run: should run A.test03", buildRule.getOutput()); + buildRule.executeTarget("B.test04"); + assertContains("2nd run: should run B.test04", buildRule.getOutput()); + buildRule.executeTarget("D.test10"); + assertContains("2nd run: should run D.test10", buildRule.getOutput()); + + + // "fix" errors in class A + buildRule.executeTarget("failureRecorder.fixing"); + + // 3rd run: four running tests with two errors + buildRule.executeTarget("failureRecorder.runtest"); + assertTrue("The collector file '" + collectorFile.getAbsolutePath() + + "' should exist after the 3rd run.", + collectorFile.exists()); + buildRule.executeTarget("A.test02"); + assertContains("3rd run: should run A.test02", buildRule.getOutput()); + buildRule.executeTarget("A.test03"); + assertContains("3rd run: should run A.test03", buildRule.getOutput()); + buildRule.executeTarget("B.test04"); + assertContains("3rd run: should run B.test04", buildRule.getOutput()); + buildRule.executeTarget("D.test10"); + assertContains("3rd run: should run D.test10", buildRule.getOutput()); + + + // 4rd run: two running tests with errors + buildRule.executeTarget("failureRecorder.runtest"); + assertTrue("The collector file '" + collectorFile.getAbsolutePath() + + "' should exist after the 4th run.", + collectorFile.exists()); + //TODO: these two statements fail + //buildRule.executeTarget("A.test02");assertNotContains("4th run: should not run A.test02", buildRule.getOutput()); + //buildRule.executeTarget("A.test03");assertNotContains("4th run: should not run A.test03", buildRule.getOutput()); + buildRule.executeTarget("B.test04"); + assertContains("4th run: should run B.test04", buildRule.getOutput()); + buildRule.executeTarget("D.test10"); + assertContains("4th run: should run D.test10", buildRule.getOutput()); + + } + + @Test + public void testBatchTestForkOnceCustomFormatter() { + assertResultFilesExist("testBatchTestForkOnceCustomFormatter", "foo"); + } + + // Bugzilla Issue 45411 + @Test + public void testMultilineAssertsNoFork() { + buildRule.executeTarget("testMultilineAssertsNoFork"); + assertNotContains("messaged up", buildRule.getLog()); + assertNotContains("crashed)", buildRule.getLog()); + } + + // Bugzilla Issue 45411 + @Test + public void testMultilineAssertsFork() { + buildRule.executeTarget("testMultilineAssertsFork"); + assertNotContains("messaged up", buildRule.getLog()); + assertNotContains("crashed)", buildRule.getLog()); + } + + private void assertResultFilesExist(String target, String extension) { + buildRule.executeTarget(target); + assertResultFileExists("JUnitClassLoader", extension); + assertResultFileExists("JUnitTestRunner", extension); + assertResultFileExists("JUnitVersionHelper", extension); + } + + private void assertResultFileExists(String classNameFragment, String ext) { + assertTrue("result for " + classNameFragment + "Test" + ext + " exists", + + new File(buildRule.getOutputDir(), "TEST-org.apache.tools.ant." + + "taskdefs.optional.junit." + + classNameFragment + "Test" + ext) + .exists()); + } + + private void assertNoPrint(String result, String where) { + assertNotContains(where + " '" + result + "' must not contain print statement", + "print to System.", result); + } + + private void assertOutput() throws IOException { + FileReader inner = new FileReader(new File(buildRule.getOutputDir(), + "testlog.txt")); + BufferedReader reader = new BufferedReader(inner); + try { + String line = reader.readLine(); + assertEquals("Testsuite: org.apache.tools.ant.taskdefs.optional.junit.Printer", + line); + line = reader.readLine(); + assertNotNull(line); + assertTrue(line.startsWith("Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed:")); + line = reader.readLine(); + assertEquals("------------- Standard Output ---------------", + line); + assertPrint(reader.readLine(), "static", "out"); + assertPrint(reader.readLine(), "constructor", "out"); + assertPrint(reader.readLine(), "method", "out"); + line = reader.readLine(); + assertEquals("------------- ---------------- ---------------", + line); + line = reader.readLine(); + assertEquals("------------- Standard Error -----------------", + line); + assertPrint(reader.readLine(), "static", "err"); + assertPrint(reader.readLine(), "constructor", "err"); + assertPrint(reader.readLine(), "method", "err"); + line = reader.readLine(); + assertEquals("------------- ---------------- ---------------", + line); + line = reader.readLine(); + assertEquals("", line); + line = reader.readLine(); + assertNotNull(line); + assertTrue(line.startsWith("Testcase: testNoCrash took ")); + } finally { + inner.close(); + } + } + + private void assertPrint(String line, String from, String to) { + String search = from + " print to System." + to; + assertEquals(search, line); + } + + @Test + public void testJUnit4Skip() throws Exception { + buildRule.executeTarget("testSkippableTests"); + + DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); + DocumentBuilder dBuilder = dbFactory.newDocumentBuilder(); + Document doc = dBuilder.parse(new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit4Skippable.xml")); + + assertEquals("Incorrect number of nodes created", 8, doc.getElementsByTagName("testcase").getLength()); + + XPathFactory factory = XPathFactory.newInstance(); + XPath xpath = factory.newXPath(); + + assertEquals("Incorrect number of skipped tests in header", 4, Integer.parseInt(xpath.compile("//testsuite/@skipped").evaluate(doc))); + assertEquals("Incorrect number of error tests in header", 1, Integer.parseInt(xpath.compile("//testsuite/@errors").evaluate(doc))); + assertEquals("Incorrect number of failure tests in header", 2, Integer.parseInt(xpath.compile("//testsuite/@failures").evaluate(doc))); + assertEquals("Incorrect number of tests in header", 8, Integer.parseInt(xpath.compile("//testsuite/@tests").evaluate(doc))); + + + assertEquals("Incorrect ignore message on explicit ignored test", "Please don't ignore me!", xpath.compile("//testsuite/testcase[@name='explicitIgnoreTest']/skipped/@message").evaluate(doc)); + assertEquals("No message should be set on Ignored tests with no Ignore annotation text", 0, ((Node)xpath.compile("//testsuite/testcase[@name='explicitlyIgnoreTestNoMessage']/skipped").evaluate(doc, XPathConstants.NODE)).getAttributes().getLength()); + assertEquals("Incorrect ignore message on implicit ignored test", "This test will be ignored", xpath.compile("//testsuite/testcase[@name='implicitlyIgnoreTest']/skipped/@message").evaluate(doc)); + assertNotNull("Implicit ignore test should have an ignore element", xpath.compile("//testsuite/testcase[@name='implicitlyIgnoreTestNoMessage']/skipped").evaluate(doc, XPathConstants.NODE)); + + } + + @Test + public void testTestMethods() throws Exception { + buildRule.executeTarget("testTestMethods"); + } + + @Test + public void testNonTestsSkipped() throws Exception { + + buildRule.executeTarget("testNonTests"); + assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.NonTestMissed.xml").exists()); + assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestMissed.xml").exists()); + assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.AbstractTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestMissed.xml").exists()); + assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.AbstractJUnit3TestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractJUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestWithSuiteNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestWithSuiteNotMissed.xml").exists()); + + buildRule.executeTarget("testNonTestsRun"); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.NonTestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3NonTestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestNotMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractJUnit3TestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3NonTestMissed.xml").exists()); + assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestWithSuiteNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestWithSuiteNotMissed.xml").exists()); + + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java new file mode 100644 index 00000000..38eaa142 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java @@ -0,0 +1,111 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.apache.tools.ant.AntAssert.assertNotContains; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class JUnitTestListenerTest{ + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + // The captureToSummary test writes to stdout and stderr, good for + // verifying that the TestListener support doesn't break anything. + private static final String PASS_TEST_TARGET = "captureToSummary"; + + // testNoCrash is the test invoked by the captureToSummary's junit task + private static final String PASS_TEST = "testNoCrash"; + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml"); + } + + + @Test + public void testFullLogOutput() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting full log to have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); + } + + @Test + public void testNoLogOutput() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertNotContains("expecting log to not have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getLog()); + } + + @Test + public void testTestCountFired() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting test count message", JUnitTask.TESTLISTENER_PREFIX + + "tests to run: ", buildRule.getFullLog()); + } + + @Test + public void testStartTestFired() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting test started message", JUnitTask.TESTLISTENER_PREFIX + + "startTest(" + PASS_TEST + ")", buildRule.getFullLog()); + } + + @Test + public void testEndTestFired() { + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting test ended message", JUnitTask.TESTLISTENER_PREFIX + + "endTest(" + PASS_TEST + ")", buildRule.getFullLog()); + } + + @Test + public void testNoFullLogOutputByDefault() { + buildRule.executeTarget(PASS_TEST_TARGET); + assertNotContains("expecting full log to not have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); + } + + @Test + public void testFullLogOutputMagicProperty() { + buildRule.getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertContains("expecting full log to have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); + } + + @Test + public void testNoFullLogOutputMagicPropertyWins() { + buildRule.getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "false"); + buildRule.getProject().setProperty("enableEvents", "true"); + buildRule.executeTarget(PASS_TEST_TARGET); + assertNotContains("expecting full log to not have BuildListener events", + JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java new file mode 100644 index 00000000..a75c5cbe --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java @@ -0,0 +1,217 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.io.PrintWriter; +import java.io.StringWriter; + +import junit.framework.AssertionFailedError; +import junit.framework.TestCase; +import junit.framework.TestSuite; + +import org.apache.tools.ant.BuildException; +import org.junit.Test; + +/** + * Small testcase for the runner, tests are very very very basics. + * They must be enhanced with time. + * + */ +public class JUnitTestRunnerTest{ + + + + // check that a valid method name generates no errors + @Test + public void testValidMethod(){ + TestRunner runner = createRunnerForTestMethod(ValidMethodTestCase.class,"testA"); + runner.run(); + assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode()); + } + + // check that having an invalid method name generates an error + @Test + public void testInvalidMethod(){ + TestRunner runner = createRunnerForTestMethod(InvalidMethodTestCase.class,"testInvalid"); + runner.run(); + String error = runner.getFormatter().getError(); + // might be FAILURES or ERRORS depending on JUnit version? + assertTrue(error, runner.getRetCode() != JUnitTestRunner.SUCCESS); + } + + // check that having no suite generates no errors + @Test + public void testNoSuite(){ + TestRunner runner = createRunner(NoSuiteTestCase.class); + runner.run(); + assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode()); + } + + // check that a suite generates no errors + @Test + public void testSuite(){ + TestRunner runner = createRunner(SuiteTestCase.class); + runner.run(); + assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode()); + } + + // check that an invalid suite generates an error. + @Test + public void testInvalidSuite(){ + TestRunner runner = createRunner(InvalidSuiteTestCase.class); + runner.run(); + String error = runner.getFormatter().getError(); + assertEquals(error, JUnitTestRunner.ERRORS, runner.getRetCode()); + assertTrue(error, error.indexOf("thrown on purpose") != -1); + } + + // check that something which is not a testcase generates no errors + // at first even though this is incorrect. + @Test + public void testNoTestCase(){ + TestRunner runner = createRunner(NoTestCase.class); + runner.run(); + // On junit3 this is a FAILURE, on junit4 this is an ERROR + int ret = runner.getRetCode(); + + if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) { + fail("Unexpected result " + ret + " from junit runner"); + } + // JUnit3 test + //assertEquals(runner.getFormatter().getError(), JUnitTestRunner.FAILURES, runner.getRetCode()); + } + + // check that an exception in the constructor is noticed + @Test + public void testInvalidTestCase(){ + TestRunner runner = createRunner(InvalidTestCase.class); + runner.run(); + // On junit3 this is a FAILURE, on junit4 this is an ERROR + int ret = runner.getRetCode(); + if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) { + fail("Unexpected result " + ret + " from junit runner"); + } + // JUNIT3 test + //assertEquals(error, JUnitTestRunner.FAILURES, runner.getRetCode()); + //@fixme as of now does not report the original stacktrace. + //assertTrue(error, error.indexOf("thrown on purpose") != -1); + } + + protected TestRunner createRunner(Class<?> clazz){ + return new TestRunner(new JUnitTest(clazz.getName()), null, + true, true, true); + } + + protected TestRunner createRunnerForTestMethod(Class<?> clazz, String method){ + return new TestRunner(new JUnitTest(clazz.getName()), new String[] {method}, + true, true, true); + } + + // the test runner that wrap the dummy formatter that interests us + private final static class TestRunner extends JUnitTestRunner { + private ResultFormatter formatter = new ResultFormatter(); + TestRunner(JUnitTest test, String[] methods, boolean haltonerror, + boolean filtertrace, boolean haltonfailure){ + super(test, methods, haltonerror, filtertrace, haltonfailure, + false, false, TestRunner.class.getClassLoader()); + // use the classloader that loaded this class otherwise + // it will not be able to run inner classes if this test + // is ran in non-forked mode. + addFormatter(formatter); + } + ResultFormatter getFormatter(){ + return formatter; + } + } + + // dummy formatter just to catch the error + private final static class ResultFormatter implements JUnitResultFormatter { + private Throwable error; + public void setSystemOutput(String output){} + public void setSystemError(String output){} + public void startTestSuite(JUnitTest suite) throws BuildException{} + public void endTestSuite(JUnitTest suite) throws BuildException{} + public void setOutput(java.io.OutputStream out){} + public void startTest(junit.framework.Test t) {} + public void endTest(junit.framework.Test test) {} + public void addFailure(junit.framework.Test test, AssertionFailedError t) { } + public void addError(junit.framework.Test test, Throwable t) { + error = t; + } + String getError(){ + if (error == null){ + return ""; + } + StringWriter sw = new StringWriter(); + error.printStackTrace(new PrintWriter(sw)); + return sw.toString(); + } + } + + public static class NoTestCase { + } + + public static class InvalidMethodTestCase extends TestCase { + public InvalidMethodTestCase(String name){ super(name); } + public void testA(){ + throw new NullPointerException("thrown on purpose"); + } + } + + public static class ValidMethodTestCase extends TestCase { + public ValidMethodTestCase(String name){ super(name); } + public void testA(){ + // expected to be executed + } + public void testB(){ + // should not be executed + throw new NullPointerException("thrown on purpose"); + } + } + + public static class InvalidTestCase extends TestCase { + public InvalidTestCase(String name){ + super(name); + throw new NullPointerException("thrown on purpose"); + } + } + + public static class NoSuiteTestCase extends TestCase { + public NoSuiteTestCase(String name){ super(name); } + public void testA(){} + } + + public static class SuiteTestCase extends NoSuiteTestCase { + public SuiteTestCase(String name){ super(name); } + public static junit.framework.Test suite(){ + return new TestSuite(SuiteTestCase.class); + } + } + + public static class InvalidSuiteTestCase extends NoSuiteTestCase { + public InvalidSuiteTestCase(String name){ super(name); } + public static junit.framework.Test suite(){ + throw new NullPointerException("thrown on purpose"); + } + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java new file mode 100644 index 00000000..8af3d23c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import static org.junit.Assert.assertEquals; +import junit.framework.JUnit4TestAdapterCache; +import junit.framework.TestCase; +import junit.framework.TestResult; + +import org.junit.Test; +import org.junit.runner.Description; + +/** + */ +public class JUnitVersionHelperTest { + + @Test + public void testMyOwnName() { + assertEquals("testMyOwnName", + JUnitVersionHelper.getTestCaseName( + JUnit4TestAdapterCache.getDefault().asTest( + Description.createTestDescription(JUnitVersionHelperTest.class, "testMyOwnName") + ) + ) + ); + } + + @Test + public void testNonTestCaseName() { + assertEquals("I'm a foo", + JUnitVersionHelper.getTestCaseName(new Foo1())); + } + + @Test + public void testNoStringReturn() { + assertEquals("unknown", + JUnitVersionHelper.getTestCaseName(new Foo2())); + } + + @Test + public void testNoGetName() { + assertEquals("unknown", + JUnitVersionHelper.getTestCaseName(new Foo3())); + } + + @Test + public void testNameNotGetName() { + assertEquals("I'm a foo, too", + JUnitVersionHelper.getTestCaseName(new Foo4())); + } + + @Test + public void testNull() { + assertEquals("unknown", JUnitVersionHelper.getTestCaseName(null)); + } + + @Test + public void testTestCaseSubClass() { + assertEquals("overridden getName", + JUnitVersionHelper.getTestCaseName(new Foo5())); + } + + public static class Foo implements junit.framework.Test { + public int countTestCases() {return 0;} + public void run(TestResult result) {} + } + + public static class Foo1 extends Foo { + public String getName() {return "I'm a foo";} + } + + public static class Foo2 extends Foo { + public int getName() {return 1;} + } + + public static class Foo3 extends Foo { + } + + public static class Foo4 extends Foo { + public String name() {return "I'm a foo, too";} + } + + public static class Foo5 extends TestCase { + public String getName() {return "overridden getName";} + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java new file mode 100644 index 00000000..392a92ee --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import org.junit.Test; + +/** + */ +public class NoVmCrash { + + @Test + public void testNoCrash() { + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java new file mode 100644 index 00000000..0200648d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import org.junit.Test; + +/** + */ +public class Printer { + + public Printer() { + System.err.println("constructor print to System.err"); + System.out.println("constructor print to System.out"); + } + + static { + System.err.println("static print to System.err"); + System.out.println("static print to System.out"); + } + + @Test + public void testNoCrash() { + System.err.println("method print to System.err"); + System.out.println("method print to System.out"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java new file mode 100644 index 00000000..15098948 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + + +import org.junit.Test; + +public class Sleeper { + + @Test + public void testSleep() throws InterruptedException { + Thread.sleep(5 * 1000); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java new file mode 100644 index 00000000..14a09661 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import junit.framework.Test; +import junit.framework.TestCase; + +/** + * validates that the suite() method works in classes that don't + * implement Test. + */ +public class SuiteMethodTest { + + public static Test suite() { + return new Nested("testMethod"); + } + + public static class Nested extends TestCase { + public Nested(String name) { + super(name); + } + + public void testMethod() { + assertTrue(true); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java new file mode 100644 index 00000000..9908eeea --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.apache.tools.ant.AntAssert.assertNotContains; +import static org.junit.Assert.assertEquals; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class TearDownOnVmCrashTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit/teardownlistener.xml"); + } + + @Test + public void testNoTeardown() { + buildRule.executeTarget("testNoTeardown"); + assertEquals("true", buildRule.getProject().getProperty("error")); + assertNotContains("tearDown called on Timeout", buildRule.getOutput()); + } + + @Test + public void testTeardown() { + buildRule.executeTarget("testTeardown"); + assertEquals("true", buildRule.getProject().getProperty("error")); + assertContains("tearDown called on Timeout", buildRule.getOutput()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java new file mode 100644 index 00000000..27420d6f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import java.io.IOException; +import java.io.OutputStream; + +import junit.framework.AssertionFailedError; +import junit.framework.Test; + +import org.apache.tools.ant.BuildException; + +public class TestFormatter implements JUnitResultFormatter { + + private static final byte[] grafitto = new byte[] { + (byte) 'T', (byte) 'e', (byte) 's', (byte) 't', (byte) 'F', (byte) 'o', + (byte) 'r', (byte) 'm', (byte) 'a', (byte) 't', (byte) 't', (byte) 'e', + (byte) 'r', (byte) ' ', (byte) 'w', (byte) 'a', (byte) 's', (byte) ' ', + (byte) 'h', (byte) 'e', (byte) 'r', (byte) 'e', 10 + }; + + /** + * Where to write the log to. + */ + private OutputStream out; + + /** + * Empty + */ + public TestFormatter() { + } + + /** + * Empty + */ + public void startTestSuite(JUnitTest suite) { + } + /** + * Empty + */ + public void startTest(Test t) { + } + /** + * Empty + */ + public void endTest(Test test) { + } + /** + * Empty + */ + public void addFailure(Test test, Throwable t) { + } + /** + * Empty + */ + public void addFailure(Test test, AssertionFailedError t) { + } + /** + * Empty + */ + public void addError(Test test, Throwable t) { + } + /** + * Empty + */ + public void setSystemOutput(String out) { + } + /** + * Empty + */ + public void setSystemError(String err) { + } + + public void setOutput(OutputStream out) { + this.out = out; + } + + public void endTestSuite(JUnitTest suite) throws BuildException { + if (out != null) { + try { + out.write(grafitto); + out.flush(); + } catch (IOException ioex) { + throw new BuildException("Unable to write output", ioex); + } finally { + if (out != System.out && out != System.err) { + try { + out.close(); + } catch (IOException e) { + // ignore + } + } + } + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java new file mode 100644 index 00000000..92d21b68 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import org.junit.Test; + +/** + */ +public class VmCrash { + + @Test + public void testCrash() { + System.exit(0); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java new file mode 100644 index 00000000..3f464d87 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class XMLFormatterWithCDATAOnSystemOut { + + private static final String DIR = "src/etc/testcases/taskdefs/optional/junit"; + private static final String REPORT = + "TEST-" + XMLFormatterWithCDATAOnSystemOut.class.getName() + ".xml"; + + private static final String TESTDATA = + "<ERROR>" + + "<![CDATA[<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + + " <RESPONSE>" + + " <GDS/>" + + " <ERROR>" + + " <ID/>" + + " <MESSAGE/>" + + " <REQUEST_TYPE/>" + + " <RESEND/>" + + " <RAW_RESPONSE/>" + + " </ERROR>" + + " </RESPONSE>" + + "]]>" + + "</ERROR>"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Test + public void testOutput() { + System.out.println(TESTDATA); + } + + @Test + public void testBuildfile() throws IOException { + buildRule.configureProject(DIR + "/cdataoutput.xml"); + if (buildRule.getProject().getProperty("cdata.inner") == null) { + // avoid endless loop + buildRule.executeTarget("run-junit"); + File f = buildRule.getProject().resolveFile(REPORT); + FileReader reader = null; + try { + reader = new FileReader(f); + String content = FileUtils.readFully(reader); + assertTrue(content.indexOf("</RESPONSE>]]>" + + "</ERROR>") > 0); + } finally { + if (reader != null) { + reader.close(); + } + f.delete(); + } + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java new file mode 100644 index 00000000..da67fec8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.junit; + +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.PrintWriter; +import java.security.Permission; + +import org.apache.tools.ant.DefaultLogger; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Delete; +import org.apache.tools.ant.types.FileSet; +import org.junit.Assume; +import org.junit.Test; + +public class XMLResultAggregatorTest { + + @Test + public void testFrames() throws Exception { + // For now, skip this test on JDK 6 (and below); see below for why: + try { + Class.forName("java.nio.file.Files"); + } catch (ClassNotFoundException x) { + Assume.assumeNoException("Skip test on JDK 6 and below", x); + } + final File d = new File(System.getProperty("java.io.tmpdir"), "XMLResultAggregatorTest"); + if (d.exists()) { + new Delete() {{removeDir(d);}}; // is there no utility method for this? + } + assertTrue(d.getAbsolutePath(), d.mkdir()); + File xml = new File(d, "x.xml"); + PrintWriter pw = new PrintWriter(new FileOutputStream(xml)); + try { + pw.println("<testsuite errors='0' failures='0' name='my.UnitTest' tests='1'>"); + pw.println(" <testcase classname='my.UnitTest' name='testSomething'/>"); + pw.println("</testsuite>"); + pw.flush(); + } finally { + pw.close(); + } + XMLResultAggregator task = new XMLResultAggregator(); + task.setTodir(d); + Project project = new Project(); + DefaultLogger logger = new DefaultLogger(); + logger.setOutputPrintStream(System.out); + logger.setErrorPrintStream(System.err); + logger.setMessageOutputLevel(Project.MSG_INFO); + project.addBuildListener(logger); + project.init(); + task.setProject(project); + AggregateTransformer report = task.createReport(); + report.setTodir(d); + FileSet fs = new FileSet(); + fs.setFile(xml); + task.addFileSet(fs); + /* getResourceAsStream override unnecessary on JDK 7. Ought to work around JAXP #6723276 in JDK 6, but causes a TypeCheckError in FunctionCall for reasons TBD: + Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) { + public InputStream getResourceAsStream(String name) { + if (name.startsWith("META-INF/services/")) { + return new ByteArrayInputStream(new byte[0]); + } + return super.getResourceAsStream(name); + } + }); + */ + // Use the JRE's Xerces, not lib/optional/xerces.jar: + Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader().getParent()); + // Tickle #51668: + System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}}); + task.execute(); + assertTrue(new File(d, "index.html").isFile()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java new file mode 100644 index 00000000..1a22115e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java @@ -0,0 +1,879 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.net; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; +import java.io.IOException; +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import java.util.Vector; + +import org.apache.commons.net.ftp.FTPClient; +import org.apache.tools.ant.BuildEvent; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.DefaultLogger; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.condition.Os; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.util.RetryHandler; +import org.apache.tools.ant.util.Retryable; +import org.apache.tools.ant.util.regexp.RegexpMatcher; +import org.apache.tools.ant.util.regexp.RegexpMatcherFactory; +import org.junit.After; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +//FIXME these tests are more integration than unit tests and report errors badly +public class FTPTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + // keep track of what operating systems are supported here. + private boolean supportsSymlinks = Os.isFamily("unix"); + + private FTPClient ftp; + + private boolean loginSuceeded = false; + + private String loginFailureMessage; + + private String tmpDir = null; + private String remoteTmpDir = null; + private String ftpFileSep = null; + private myFTP myFTPTask = new myFTP(); + + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/net/ftp.xml"); + Project project = buildRule.getProject(); + project.executeTarget("setup"); + tmpDir = project.getProperty("tmp.dir"); + ftp = new FTPClient(); + ftpFileSep = project.getProperty("ftp.filesep"); + myFTPTask.setSeparator(ftpFileSep); + myFTPTask.setProject(project); + remoteTmpDir = myFTPTask.resolveFile(tmpDir); + String remoteHost = project.getProperty("ftp.host"); + int port = Integer.parseInt(project.getProperty("ftp.port")); + String remoteUser = project.getProperty("ftp.user"); + String password = project.getProperty("ftp.password"); + boolean connectionSucceeded = false; + try { + ftp.connect(remoteHost, port); + connectionSucceeded = true; + } catch (Exception ex) { + loginFailureMessage = "could not connect to host " + remoteHost + " on port " + port; + } + if (connectionSucceeded) { + try { + ftp.login(remoteUser, password); + loginSuceeded = true; + } catch (IOException ioe) { + loginFailureMessage = "could not log on to " + remoteHost + " as user " + remoteUser; + } + } + } + + @After + public void tearDown() { + try { + if (ftp!= null) { + ftp.disconnect(); + } + } catch (IOException ioe) { + // do nothing + } + buildRule.getProject().executeTarget("cleanup"); + } + + private boolean changeRemoteDir(String remoteDir) { + boolean result = true; + try { + ftp.cwd(remoteDir); + } + catch (Exception ex) { + System.out.println("could not change directory to " + remoteTmpDir); + result = false; + } + return result; + } + + @Test + public void test1() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha"}); + ds.scan(); + compareFiles(ds, new String[] {} ,new String[] {"alpha"}); + } + + @Test + public void test2() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void test3() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", + "alpha/beta/gamma"}); + } + + @Test + public void testFullPathMatchesCaseSensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"}); + ds.scan(); + compareFiles(ds, new String[] {}, new String[] {}); + } + + @Test + public void testFullPathMatchesCaseInsensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setCaseSensitive(false); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {}); + } + + @Test + public void test2ButCaseInsensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"ALPHA/"}); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void test2bisButCaseInsensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/BETA/gamma/"}); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha/beta/gamma"}); + } + + @Test + public void testGetWithSelector() { + buildRule.executeTarget("ftp-get-with-selector"); + assertContains("selectors are not supported in remote filesets", buildRule.getLog()); + FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector"); + DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject()); + dsDestination.scan(); + String [] sortedDestinationDirectories = dsDestination.getIncludedDirectories(); + String [] sortedDestinationFiles = dsDestination.getIncludedFiles(); + for (int counter = 0; counter < sortedDestinationDirectories.length; counter++) { + sortedDestinationDirectories[counter] = + sortedDestinationDirectories[counter].replace(File.separatorChar, '/'); + } + for (int counter = 0; counter < sortedDestinationFiles.length; counter++) { + sortedDestinationFiles[counter] = + sortedDestinationFiles[counter].replace(File.separatorChar, '/'); + } + FileSet fsSource = (FileSet) buildRule.getProject().getReference("fileset-source-without-selector"); + DirectoryScanner dsSource = fsSource.getDirectoryScanner(buildRule.getProject()); + dsSource.scan(); + compareFiles(dsSource, sortedDestinationFiles, sortedDestinationDirectories); + } + + @Test + public void testGetFollowSymlinksTrue() { + Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + buildRule.getProject().executeTarget("ftp-get-directory-symbolic-link"); + FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector"); + DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject()); + dsDestination.scan(); + compareFiles(dsDestination, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testGetFollowSymlinksFalse() { + Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + buildRule.getProject().executeTarget("ftp-get-directory-no-symbolic-link"); + FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector"); + DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject()); + dsDestination.scan(); + compareFiles(dsDestination, new String[] {}, + new String[] {}); + } + + @Test + public void testAllowSymlinks() { + Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + buildRule.getProject().executeTarget("symlink-setup"); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/beta/gamma/"}); + ds.setFollowSymlinks(true); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha/beta/gamma"}); + } + + @Test + public void testProhibitSymlinks() { + Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + buildRule.getProject().executeTarget("symlink-setup"); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/beta/gamma/"}); + ds.setFollowSymlinks(false); + ds.scan(); + compareFiles(ds, new String[] {}, new String[] {}); + } + + @Test + public void testFileSymlink() { + Assume.assumeTrue("System does not support Symlinks", supportsSymlinks); + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + buildRule.getProject().executeTarget("symlink-file-setup"); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/beta/gamma/"}); + ds.setFollowSymlinks(true); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha/beta/gamma"}); + } + + // father and child pattern test + @Test + public void testOrderOfIncludePatternsIrrelevant() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + String [] expectedFiles = {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}; + String [] expectedDirectories = {"alpha/beta", "alpha/beta/gamma" }; + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/be?a/**", "alpha/beta/gamma/"}); + ds.scan(); + compareFiles(ds, expectedFiles, expectedDirectories); + // redo the test, but the 2 include patterns are inverted + ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/beta/gamma/", "alpha/be?a/**"}); + ds.scan(); + compareFiles(ds, expectedFiles, expectedDirectories); + } + + @Test + public void testPatternsDifferInCaseScanningSensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/", "ALPHA/"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testPatternsDifferInCaseScanningInsensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/", "ALPHA/"}); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testFullpathDiffersInCaseScanningSensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] { + "alpha/beta/gamma/gamma.xml", + "alpha/beta/gamma/GAMMA.XML" + }); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {}); + } + + @Test + public void testFullpathDiffersInCaseScanningInsensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] { + "alpha/beta/gamma/gamma.xml", + "alpha/beta/gamma/GAMMA.XML" + }); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {}); + } + + @Test + public void testParentDiffersInCaseScanningSensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testParentDiffersInCaseScanningInsensitive() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"}); + ds.setCaseSensitive(false); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml"}, + new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"}); + } + + @Test + public void testExcludeOneFile() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] { + "**/*.xml" + }); + ds.setExcludes(new String[] { + "alpha/beta/b*xml" + }); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"}, + new String[] {}); + } + + @Test + public void testExcludeHasPrecedence() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] { + "alpha/**" + }); + ds.setExcludes(new String[] { + "alpha/**" + }); + ds.scan(); + compareFiles(ds, new String[] {}, + new String[] {}); + + } + + @Test + public void testAlternateIncludeExclude() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setIncludes(new String[] { + "alpha/**", + "alpha/beta/gamma/**" + }); + ds.setExcludes(new String[] { + "alpha/beta/**" + }); + ds.scan(); + compareFiles(ds, new String[] {}, + new String[] {"alpha"}); + + } + + @Test + public void testAlternateExcludeInclude() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setExcludes(new String[] { + "alpha/**", + "alpha/beta/gamma/**" + }); + ds.setIncludes(new String[] { + "alpha/beta/**" + }); + ds.scan(); + compareFiles(ds, new String[] {}, + new String[] {}); + + } + + /** + * Test inspired by Bug#1415. + */ + @Test + public void testChildrenOfExcludedDirectory() { + Assume.assumeTrue(loginFailureMessage, loginSuceeded); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + buildRule.getProject().executeTarget("children-of-excluded-dir-setup"); + FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setExcludes(new String[] {"alpha/**"}); + ds.scan(); + compareFiles(ds, new String[] {"delta/delta.xml"}, + new String[] {"delta"}); + + ds = myFTPTask.newScanner(ftp); + Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir)); + ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp")); + ds.setExcludes(new String[] {"alpha"}); + ds.scan(); + compareFiles(ds, new String[] {"alpha/beta/beta.xml", + "alpha/beta/gamma/gamma.xml", + "delta/delta.xml"}, + new String[] {"alpha/beta", "alpha/beta/gamma", "delta"}); + + } + + /** + * This class enables the use of the log messages as a way of testing + * the number of files actually transferred. + * It uses the ant regular expression mechanism to get a regex parser + * to parse the log output. + */ + private class CountLogListener extends DefaultLogger { + private Vector lastMatchGroups = null; + private RegexpMatcher matcher = new RegexpMatcherFactory().newRegexpMatcher(); + + /** + * The only constructor for a CountLogListener + * @param pattern a regular expression pattern. It should have + * one parenthesized group and that group should contain the + * number desired. + */ + public CountLogListener(String pattern) { + super(); + this.matcher.setPattern(pattern); + } + + + /* + * @param event the build event that is being logged. + */ + public void messageLogged(BuildEvent event) { + String message = event.getMessage(); + if (this.matcher.matches(message)) { + lastMatchGroups = this.matcher.getGroups(message); + } + super.messageLogged(event); + } + + /** + * returns the desired number that results from parsing the log + * message + * @return the number of files indicated in the desired message or -1 + * if a matching log message was never found. + */ + public int getCount() { + if (this.lastMatchGroups == null) { + return -1; + } + return Integer.parseInt((String) this.lastMatchGroups.get(1)); + } + } + + /** + * This class enables the use of the log to count the number + * of times a message has been emitted. + */ + private class LogCounter extends DefaultLogger { + private Map searchMap = new HashMap(); + private int matchCount; + + public void addLogMessageToSearch(String message) { + searchMap.put(message, new Integer(0)); + } + + /* + * @param event the build event that is being logged. + */ + public void messageLogged(BuildEvent event) { + String message = event.getMessage(); + Integer mcnt = (Integer) searchMap.get(message); + if (null != mcnt) { + searchMap.put(message, new Integer(mcnt.intValue() + 1)); + } + super.messageLogged(event); + } + + /** + * @return the number of times that the looked for message was sent + * to the log + */ + public int getMatchCount(String message) { + Integer mcnt = (Integer) searchMap.get(message); + if (null != mcnt) { + return mcnt.intValue(); + } + return 0; + } + } + /** + * Tests the combination of the newer parameter and the + * serverTimezoneConfig parameter in the PUT action. The default + * configuration is an ftp server on localhost which formats + * timestamps as GMT. + */ + @Test + public void testTimezonePut() { + CountLogListener log = new CountLogListener("(\\d+) files? sent"); + buildRule.getProject().executeTarget("timed.test.setup"); + buildRule.getProject().addBuildListener(log); + buildRule.getProject().executeTarget("timed.test.put.older"); + assertEquals(1, log.getCount()); + } + + /** + * Tests the combination of the newer parameter and the + * serverTimezoneConfig parameter in the GET action. The default + * configuration is an ftp server on localhost which formats + * timestamps as GMT. + */ + @Test + public void testTimezoneGet() { + CountLogListener log = new CountLogListener("(\\d+) files? retrieved"); + buildRule.getProject().executeTarget("timed.test.setup"); + buildRule.getProject().addBuildListener(log); + buildRule.getProject().executeTarget("timed.test.get.older"); + assertEquals(3, log.getCount()); + } + + + /** + * Tests that the presence of one of the server config params forces + * the system type to Unix if not specified. + */ + @Test + public void testConfiguration1() { + int[] expectedCounts = { + 1,1,0,1,0,0,0 + }; + performConfigTest("configuration.1", expectedCounts); + + } + + /** + * Tests the systemTypeKey attribute. + */ + @Test + public void testConfiguration2() { + int[] expectedCounts = { + 1,0,0,1,1,0,0 + }; + performConfigTest("configuration.2", expectedCounts); + + } + + /** + * Tests the systemTypeKey attribute with UNIX specified. + */ + @Test + public void testConfiguration3() { + int[] expectedCounts = { + 1,0,1,0,0,1,0 + }; + performConfigTest("configuration.3", expectedCounts); + + } + + @Test + public void testConfigurationLang() { + int[] expectedCounts = { + 1,1,0,0,0,0,1 + }; + performConfigTest("configuration.lang.good", expectedCounts); + + try { + performConfigTest("configuration.lang.bad", expectedCounts); + fail("BuildException Expected"); + } catch (Exception bx) { + assertTrue(bx instanceof BuildException); + } + } + /** + * Tests the systemTypeKey attribute. + */ + @Test + public void testConfigurationNone() { + int[] expectedCounts = { + 0,0,0,0,0,0,0 + }; + performConfigTest("configuration.none", expectedCounts); + + } + + private void performConfigTest(String target, int[] expectedCounts) { + String[] messages = new String[]{ + "custom configuration", + "custom config: system key = default (UNIX)", + "custom config: system key = UNIX", + "custom config: server time zone ID = " + buildRule.getProject().getProperty("ftp.server.timezone"), + "custom config: system key = WINDOWS", + "custom config: default date format = yyyy/MM/dd HH:mm", + "custom config: server language code = de" + + }; + LogCounter counter = new LogCounter(); + for (int i=0; i < messages.length; i++) { + counter.addLogMessageToSearch(messages[i]); + } + + buildRule.getProject().addBuildListener(counter); + buildRule.getProject().executeTarget(target); + for (int i=0; i < messages.length; i++) { + assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i])); + } + + } + + + /** + * this test is inspired by a user reporting that deletions of directories with the ftp task do not work + */ + @Test + public void testFTPDelete() { + buildRule.getProject().executeTarget("ftp-delete"); + } + + private void compareFiles(DirectoryScanner ds, String[] expectedFiles, + String[] expectedDirectories) { + String includedFiles[] = ds.getIncludedFiles(); + String includedDirectories[] = ds.getIncludedDirectories(); + assertEquals("file present: ", expectedFiles.length, + includedFiles.length); + assertEquals("directories present: ", expectedDirectories.length, + includedDirectories.length); + + for (int counter=0; counter < includedFiles.length; counter++) { + includedFiles[counter] = includedFiles[counter].replace(File.separatorChar, '/'); + } + Arrays.sort(includedFiles); + for (int counter=0; counter < includedDirectories.length; counter++) { + includedDirectories[counter] = includedDirectories[counter] + .replace(File.separatorChar, '/'); + } + Arrays.sort(includedDirectories); + for (int counter=0; counter < includedFiles.length; counter++) { + assertEquals(expectedFiles[counter], includedFiles[counter]); + } + for (int counter=0; counter < includedDirectories.length; counter++) { + assertEquals(expectedDirectories[counter], includedDirectories[counter]); + counter++; + } + } + private static class myFTP extends FTP { + public FTP.FTPDirectoryScanner newScanner(FTPClient client) { + return new FTP.FTPDirectoryScanner(client); + } + // provide public visibility + public String resolveFile(String file) { + return super.resolveFile(file); + } + } + + + public abstract static class myRetryableFTP extends FTP { + private final int numberOfFailuresToSimulate; + private int simulatedFailuresLeft; + + protected myRetryableFTP(int numberOfFailuresToSimulate) { + this.numberOfFailuresToSimulate = numberOfFailuresToSimulate; + this.simulatedFailuresLeft = numberOfFailuresToSimulate; + } + + protected void getFile(FTPClient ftp, String dir, String filename) + throws IOException, BuildException + { + if (this.simulatedFailuresLeft > 0) { + this.simulatedFailuresLeft--; + throw new IOException("Simulated failure for testing"); + } + super.getFile(ftp, dir, filename); + } + protected void executeRetryable(RetryHandler h, Retryable r, + String filename) throws IOException + { + this.simulatedFailuresLeft = this.numberOfFailuresToSimulate; + super.executeRetryable(h, r, filename); + } + } + public static class oneFailureFTP extends myRetryableFTP { + public oneFailureFTP() { + super(1); + } + } + public static class twoFailureFTP extends myRetryableFTP { + public twoFailureFTP() { + super(2); + } + } + public static class threeFailureFTP extends myRetryableFTP { + public threeFailureFTP() { + super(3); + } + } + + public static class randomFailureFTP extends myRetryableFTP { + public randomFailureFTP() { + super(new Random().nextInt(Short.MAX_VALUE)); + } + } + public void testGetWithSelectorRetryable1() { + buildRule.getProject().addTaskDefinition("ftp", oneFailureFTP.class); + try { + buildRule.getProject().executeTarget("ftp-get-with-selector-retryable"); + } catch (BuildException bx) { + fail("Two retries expected, failed after one."); + } + } + + @Test + public void testGetWithSelectorRetryable2() { + buildRule.getProject().addTaskDefinition("ftp", twoFailureFTP.class); + try { + buildRule.getProject().executeTarget("ftp-get-with-selector-retryable"); + } catch (BuildException bx) { + fail("Two retries expected, failed after two."); + } + } + + @Test + public void testGetWithSelectorRetryable3() { + buildRule.getProject().addTaskDefinition("ftp", threeFailureFTP.class); + try { + buildRule.getProject().executeTarget("ftp-get-with-selector-retryable"); + fail("Two retries expected, continued after two."); + } catch (BuildException bx) { + } + } + + @Test + public void testGetWithSelectorRetryableRandom() { + buildRule.getProject().addTaskDefinition("ftp", randomFailureFTP.class); + try { + buildRule.getProject().setProperty("ftp.retries", "forever"); + buildRule.getProject().executeTarget("ftp-get-with-selector-retryable"); + } catch (BuildException bx) { + fail("Retry forever specified, but failed."); + } + } + + @Test + public void testInitialCommand() { + performCommandTest("test-initial-command", new int[] { 1,0 }); + } + + @Test + public void testSiteAction() { + performCommandTest("test-site-action", new int[] { 1,0 }); + } + + private void performCommandTest(String target, int[] expectedCounts) { + String[] messages = new String[]{ + "Doing Site Command: umask 222", + "Failed to issue Site Command: umask 222", + + }; + LogCounter counter = new LogCounter(); + for (int i=0; i < messages.length; i++) { + counter.addLogMessageToSearch(messages[i]); + } + + buildRule.getProject().addBuildListener(counter); + buildRule.getProject().executeTarget(target); + for (int i=0; i < messages.length; i++) { + assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i])); + } + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java new file mode 100644 index 00000000..5d4d4cf6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java @@ -0,0 +1,146 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.script; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.FileSet; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * Tests the examples of the <scriptdef> task. + * + * @since Ant 1.6 + */ +public class ScriptDefTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/script/scriptdef.xml"); + } + + @Test + public void testSimple() { + buildRule.executeTarget("simple"); + // get the fileset and its basedir + Project p = buildRule.getProject(); + FileSet fileset = (FileSet) p.getReference("testfileset"); + File baseDir = fileset.getDir(p); + String log = buildRule.getLog(); + assertTrue("Expecting attribute value printed", + log.indexOf("Attribute attr1 = test") != -1); + + assertTrue("Expecting nested element value printed", + log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1); + } + + @Test + public void testNoLang() { + try { + buildRule.executeTarget("nolang"); + fail("Absence of language attribute not detected"); + } catch(BuildException ex) { + AntAssert.assertContains("requires a language attribute", ex.getMessage()); + } + } + + @Test + public void testNoName() { + try { + buildRule.executeTarget("noname"); + fail("Absence of name attribute not detected"); + } catch(BuildException ex) { + AntAssert.assertContains("scriptdef requires a name attribute", ex.getMessage()); + } + } + + @Test + public void testNestedByClassName() { + buildRule.executeTarget("nestedbyclassname"); + // get the fileset and its basedir + Project p = buildRule.getProject(); + FileSet fileset = (FileSet) p.getReference("testfileset"); + File baseDir = fileset.getDir(p); + String log = buildRule.getLog(); + assertTrue("Expecting attribute value to be printed", + log.indexOf("Attribute attr1 = test") != -1); + + assertTrue("Expecting nested element value to be printed", + log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1); + } + + @Test + public void testNoElement() { + buildRule.executeTarget("noelement"); + assertEquals("Attribute attr1 = test", buildRule.getOutput().trim()); + } + + @Test + public void testException() { + try { + buildRule.executeTarget("exception"); + fail("Should have thrown an exception in the script"); + } catch(BuildException ex) { + AntAssert.assertContains("TypeError", ex.getMessage()); + } + } + + @Test + public void testDoubleDef() { + buildRule.executeTarget("doubledef"); + String log = buildRule.getLog(); + assertTrue("Task1 did not execute", + log.indexOf("Task1") != -1); + assertTrue("Task2 did not execute", + log.indexOf("Task2") != -1); + } + + @Test + public void testDoubleAttribute() { + try { + buildRule.executeTarget("doubleAttributeDef"); + fail("Should have detected duplicate attirbute definition"); + } catch(BuildException ex) { + AntAssert.assertContains("attr1 attribute more than once", ex.getMessage()); + } + } + + @Test + public void testProperty() { + buildRule.executeTarget("property"); + // get the fileset and its basedir + String log = buildRule.getLog(); + assertTrue("Expecting property in attribute value replaced", + log.indexOf("Attribute value = test") != -1); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java new file mode 100644 index 00000000..c45ec17e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java @@ -0,0 +1,351 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.sos; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Path; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Testcase to ensure that command line generation and required attributes are + * correct. + * + */ +public class SOSTest { + + private Commandline commandline; + + private static final String VSS_SERVER_PATH = "\\\\server\\vss\\srcsafe.ini"; + private static final String VSS_PROJECT_PATH = "/SourceRoot/Project"; + private static final String DS_VSS_PROJECT_PATH = "$/SourceRoot/Project"; + private static final String SOS_SERVER_PATH = "192.168.0.1:8888"; + private static final String SOS_USERNAME = "ant"; + private static final String SOS_PASSWORD = "rocks"; + private static final String LOCAL_PATH = "testdir"; + private static final String SRC_FILE = "Class1.java"; + private static final String SRC_LABEL = "label1"; + private static final String SRC_COMMENT = "I fixed a bug"; + private static final String SOS_HOME = "/home/user/.sos"; + private static final String VERSION = "007"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + private Project project; + + @Before + public void setUp() { + project = new Project(); + project.init(); + project.setBasedir("."); + } + + @After + public void tearDown() { + File file = new File(project.getBaseDir(), LOCAL_PATH); + if (file.exists()) { + file.delete(); + } + } + + /** Test SOSGetFile flags & commandline generation */ + @Test + public void testGetFileFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "GetFile", "-file", + SRC_FILE, "-revision", "007", "-server", SOS_SERVER_PATH, "-name", + SOS_USERNAME, "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, + "-project", DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", + "-nocache", "-workdir", project.getBaseDir().getAbsolutePath() + + File.separator + LOCAL_PATH}; + + // Set up a SOSGet task + SOSGet sosGet = new SOSGet(); + sosGet.setProject(project); + sosGet.setVssServerPath(VSS_SERVER_PATH); + sosGet.setSosServerPath(SOS_SERVER_PATH); + sosGet.setProjectPath(VSS_PROJECT_PATH); + sosGet.setFile(SRC_FILE); + sosGet.setUsername(SOS_USERNAME); + sosGet.setPassword(SOS_PASSWORD); + sosGet.setVersion(VERSION); + sosGet.setLocalPath(new Path(project, LOCAL_PATH)); + sosGet.setNoCache(true); + sosGet.setNoCompress(true); + sosGet.setVerbose(true); + sosGet.setRecursive(true); + + commandline = sosGet.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Test SOSGetProject flags & commandline generation */ + @Test + public void testGetProjectFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "GetProject", "-recursive", + "-label", SRC_LABEL, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME, + "-password", "", "-database", VSS_SERVER_PATH, "-project", + DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir", + project.getBaseDir().getAbsolutePath()}; + + // Set up a SOSGet task + SOSGet sosGet = new SOSGet(); + sosGet.setProject(project); + sosGet.setVssServerPath(VSS_SERVER_PATH); + sosGet.setSosServerPath(SOS_SERVER_PATH); + sosGet.setProjectPath(DS_VSS_PROJECT_PATH); + sosGet.setLabel(SRC_LABEL); + sosGet.setUsername(SOS_USERNAME); + sosGet.setSosHome(SOS_HOME); + sosGet.setNoCache(true); + sosGet.setNoCompress(false); + sosGet.setVerbose(false); + sosGet.setRecursive(true); + + commandline = sosGet.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Tests SOSGet required attributes. */ + @Test + public void testGetExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml"); + expectSpecificBuildException("sosget.1", "some cause", "sosserverpath attribute must be set!"); + expectSpecificBuildException("sosget.2", "some cause", "username attribute must be set!"); + expectSpecificBuildException("sosget.3", "some cause", "vssserverpath attribute must be set!"); + expectSpecificBuildException("sosget.4", "some cause", "projectpath attribute must be set!"); + } + + /** Test CheckInFile option flags */ + @Test + public void testCheckinFileFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "CheckInFile", "-file", + SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME, + "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, "-project", + DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", "-nocache", + "-workdir", project.getBaseDir().getAbsolutePath() + File.separator + + LOCAL_PATH, "-log", SRC_COMMENT}; + + // Set up a SOSCheckin task + SOSCheckin sosCheckin = new SOSCheckin(); + sosCheckin.setProject(project); + sosCheckin.setVssServerPath(VSS_SERVER_PATH); + sosCheckin.setSosServerPath(SOS_SERVER_PATH); + sosCheckin.setProjectPath(VSS_PROJECT_PATH); + sosCheckin.setFile(SRC_FILE); + sosCheckin.setComment(SRC_COMMENT); + sosCheckin.setUsername(SOS_USERNAME); + sosCheckin.setPassword(SOS_PASSWORD); + sosCheckin.setLocalPath(new Path(project, LOCAL_PATH)); + sosCheckin.setNoCache(true); + sosCheckin.setNoCompress(true); + sosCheckin.setVerbose(true); + sosCheckin.setRecursive(true); + + commandline = sosCheckin.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Test CheckInProject option flags */ + @Test + public void testCheckinProjectFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "CheckInProject", + "-recursive", "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME, + "-password", "", "-database", VSS_SERVER_PATH, "-project", + DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir", + project.getBaseDir().getAbsolutePath(), "-log", SRC_COMMENT,}; + + // Set up a SOSCheckin task + SOSCheckin sosCheckin = new SOSCheckin(); + sosCheckin.setProject(project); + sosCheckin.setVssServerPath(VSS_SERVER_PATH); + sosCheckin.setSosServerPath(SOS_SERVER_PATH); + sosCheckin.setProjectPath(DS_VSS_PROJECT_PATH); + sosCheckin.setComment(SRC_COMMENT); + sosCheckin.setUsername(SOS_USERNAME); + sosCheckin.setSosHome(SOS_HOME); + sosCheckin.setNoCache(true); + sosCheckin.setNoCompress(false); + sosCheckin.setVerbose(false); + sosCheckin.setRecursive(true); + + commandline = sosCheckin.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Test SOSCheckIn required attributes. */ + @Test + public void testCheckinExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml"); + expectSpecificBuildException("soscheckin.1", "some cause", "sosserverpath attribute must be set!"); + expectSpecificBuildException("soscheckin.2", "some cause", "username attribute must be set!"); + expectSpecificBuildException("soscheckin.3", "some cause", "vssserverpath attribute must be set!"); + expectSpecificBuildException("soscheckin.4", "some cause", "projectpath attribute must be set!"); + } + + /** Test CheckOutFile option flags */ + @Test + public void testCheckoutFileFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "CheckOutFile", "-file", + SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME, + "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, "-project", + DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", "-nocache", + "-workdir", project.getBaseDir().getAbsolutePath() + + File.separator + LOCAL_PATH}; + + // Set up a SOSCheckout task + SOSCheckout sosCheckout = new SOSCheckout(); + sosCheckout.setProject(project); + sosCheckout.setVssServerPath(VSS_SERVER_PATH); + sosCheckout.setSosServerPath(SOS_SERVER_PATH); + sosCheckout.setProjectPath(DS_VSS_PROJECT_PATH); + sosCheckout.setFile(SRC_FILE); + sosCheckout.setUsername(SOS_USERNAME); + sosCheckout.setPassword(SOS_PASSWORD); + sosCheckout.setLocalPath(new Path(project, LOCAL_PATH)); + sosCheckout.setNoCache(true); + sosCheckout.setNoCompress(true); + sosCheckout.setVerbose(true); + sosCheckout.setRecursive(true); + + commandline = sosCheckout.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Test CheckOutProject option flags */ + @Test + public void testCheckoutProjectFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "CheckOutProject", + "-recursive", "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME, + "-password", "", "-database", VSS_SERVER_PATH, "-project", + DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir", + project.getBaseDir().getAbsolutePath()}; + + // Set up a sosCheckout task + SOSCheckout sosCheckout = new SOSCheckout(); + sosCheckout.setProject(project); + sosCheckout.setVssServerPath(VSS_SERVER_PATH); + sosCheckout.setSosServerPath(SOS_SERVER_PATH); + sosCheckout.setProjectPath(VSS_PROJECT_PATH); + sosCheckout.setUsername(SOS_USERNAME); + sosCheckout.setSosHome(SOS_HOME); + sosCheckout.setNoCache(true); + sosCheckout.setNoCompress(false); + sosCheckout.setVerbose(false); + sosCheckout.setRecursive(true); + + commandline = sosCheckout.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Test SOSCheckout required attributes. */ + @Test + public void testCheckoutExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml"); + expectSpecificBuildException("soscheckout.1", "some cause", "sosserverpath attribute must be set!"); + expectSpecificBuildException("soscheckout.2", "some cause", "username attribute must be set!"); + expectSpecificBuildException("soscheckout.3", "some cause", "vssserverpath attribute must be set!"); + expectSpecificBuildException("soscheckout.4", "some cause", "projectpath attribute must be set!"); + } + + /** Test Label option flags */ + @Test + public void testLabelFlags() { + String[] sTestCmdLine = {"soscmd", "-command", "AddLabel", "-server", + SOS_SERVER_PATH, "-name", SOS_USERNAME, "-password", "", "-database", + VSS_SERVER_PATH, "-project", DS_VSS_PROJECT_PATH, "-label", + SRC_LABEL, "-verbose", "-log", SRC_COMMENT}; + + // Set up a sosCheckout task + SOSLabel sosLabel = new SOSLabel(); + sosLabel.setVssServerPath(VSS_SERVER_PATH); + sosLabel.setSosServerPath(SOS_SERVER_PATH); + sosLabel.setProjectPath(DS_VSS_PROJECT_PATH); + sosLabel.setUsername(SOS_USERNAME); + sosLabel.setSosHome(SOS_HOME); + sosLabel.setComment(SRC_COMMENT); + sosLabel.setLabel(SRC_LABEL); + sosLabel.setNoCache(true); + sosLabel.setNoCompress(false); + sosLabel.setVerbose(true); + + commandline = sosLabel.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Test SOSLabel required attributes. */ + @Test + public void testLabelExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml"); + expectSpecificBuildException("soslabel.1", "some cause", "sosserverpath attribute must be set!"); + expectSpecificBuildException("soslabel.2", "some cause", "username attribute must be set!"); + expectSpecificBuildException("soslabel.3", "some cause", "vssserverpath attribute must be set!"); + expectSpecificBuildException("soslabel.4", "some cause", "projectpath attribute must be set!"); + expectSpecificBuildException("soslabel.5", "some cause", "label attribute must be set!"); + } + + private void expectSpecificBuildException(String target, String errorMessage, + String exceptionMessage) { + try { + buildRule.executeTarget(target); + fail(errorMessage); + } catch(BuildException ex) { + assertEquals(exceptionMessage, ex.getMessage()); + } + } + + /** + * Iterate through the generated command line comparing it to reference + * one. + * + * @param sTestCmdLine The reference command line; + * @param sGeneratedCmdLine The generated command line; + */ + private void checkCommandLines(String[] sTestCmdLine, String[] sGeneratedCmdLine) { + int length = sTestCmdLine.length; + for (int i = 0; i < length; i++) { + try { + assertEquals("arg # " + String.valueOf(i), + sTestCmdLine[i], + sGeneratedCmdLine[i]); + } catch (ArrayIndexOutOfBoundsException aioob) { + fail("missing arg " + sTestCmdLine[i]); + } + } + if (sGeneratedCmdLine.length > sTestCmdLine.length) { + // We have extra elements + fail("extra args"); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java new file mode 100644 index 00000000..fb0b3eaf --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.splash; + +import org.apache.tools.ant.Project; + +/** + * This is an "interactive" test, it passes if the splash screen + * disappears after the "finished" but before the "exiting" message. + * + * This even isn't a JUnit test case. + * + * @since Ant 1.5.2 + */ +public class SplashScreenTest { + + public static void main(String[] args) throws InterruptedException { + Project p = new Project(); + SplashTask t = new SplashTask(); + t.setProject(p); + t.execute(); + + // give it some time to display + Thread.sleep(2000); + + p.fireBuildFinished(null); + System.err.println("finished"); + + Thread.sleep(2000); + System.err.println("exiting"); + System.exit(0); + } +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java new file mode 100644 index 00000000..dff5b25a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java @@ -0,0 +1,206 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.ssh; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.condition.FilesMatch; +import org.apache.tools.ant.types.FileSet; +import org.apache.tools.ant.types.selectors.FilenameSelector; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * This is a unit test for the Scp task in Ant. It must be + * configured with command line options in order for it to work. + * Here are the options: + * + * scp.tmp This is a local path to a temporary + * directory for this task to use. + * scp.host This is the remote location of the form: + * "user:password@host:/path/to/directory" + * scp.port The port of the listening SSH service. + * Defaults to 22. (optional) + * scp.known.hosts The file containing the public keys of known + * hosts. Must be a SSH2 version file, but + * supports RSA and DSA keys. If it is not present + * this task setTrust() to true. (optional) + */ +public class ScpTest { + + private File tempDir; + private String sshHostUri = System.getProperty("scp.host"); + private int port = Integer.parseInt( System.getProperty( "scp.port", "22" ) ); + private String knownHosts = System.getProperty("scp.known.hosts"); + + private List cleanUpList = new ArrayList(); + + public ScpTest() { + if (System.getProperty("scp.tmp") != null) { + tempDir = new File(System.getProperty("scp.tmp")); + } + } + + @Before + public void setUp() { + cleanUpList.clear(); + } + + @After + public void tearDown() { + for( Iterator i = cleanUpList.iterator(); i.hasNext(); ) { + File file = (File) i.next(); + file.delete(); + } + } + + @Test + public void testSingleFileUploadAndDownload() throws IOException { + assertNotNull("system property scp.tmp must be set", tempDir); + File uploadFile = createTemporaryFile(); + + // upload + Scp scpTask = createTask(); + scpTask.setFile( uploadFile.getPath() ); + scpTask.setTodir( sshHostUri ); + scpTask.execute(); + + File testFile = new File( tempDir.getPath() + File.separator + + "download-testSingleFileUploadAndDownload.test" ); + addCleanup(testFile ); + assertFalse("Assert that the testFile does not exist.", testFile.exists()); + + // download + scpTask = createTask(); + scpTask.setFile( sshHostUri + "/" + uploadFile.getName() ); + scpTask.setTodir( testFile.getPath() ); + scpTask.execute(); + + assertTrue( "Assert that the testFile exists.", testFile.exists() ); + compareFiles( uploadFile, testFile ); + } + + @Test + public void testMultiUploadAndDownload() throws IOException { + assertNotNull("system property scp.tmp must be set", tempDir); + List uploadList = new ArrayList(); + for( int i = 0; i < 5; i++ ) { + uploadList.add( createTemporaryFile() ); + } + + Scp scp = createTask(); + FilenameSelector selector = new FilenameSelector(); + selector.setName( "scp*" ); + FileSet fileset = new FileSet(); + fileset.setDir( tempDir ); + fileset.addFilename( selector ); + scp.addFileset( fileset ); + scp.setTodir( sshHostUri ); + scp.execute(); + + File multi = new File( tempDir, "multi" ); + multi.mkdir(); + addCleanup( multi ); + + Scp scp2 = createTask(); + scp2.setFile( sshHostUri + "/scp*" ); + scp2.setTodir( multi.getPath() ); + scp2.execute(); + + FilesMatch match = new FilesMatch(); + for( Iterator i = uploadList.iterator(); i.hasNext(); ) { + File f = (File)i.next(); + match.setFile1( f ); + File f2 = new File( multi, f.getName() ); + match.setFile2( f2 ); + assertTrue("Assert file '" + f.getPath() + "' and file '" + + f2.getPath() + "'", match.eval() ); + } + } + + @Test + public void testRemoteToDir() throws IOException { + Scp scpTask = createTask(); + + // first try an invalid URI + try { + scpTask.setRemoteTodir( "host:/a/path/without/an/at" ); + fail("Expected a BuildException to be thrown due to invalid" + + " remoteToDir"); + } + catch (BuildException e) + { + // expected + //TODO we should be asserting a value in here + } + + // And this one should work + scpTask.setRemoteTodir( "user:password@host:/a/path/with/an/at" ); + // no exception + } + + public void addCleanup( File file ) { + cleanUpList.add( file ); + } + + private void compareFiles(File src, File dest) { + FilesMatch match = new FilesMatch(); + match.setFile1( src ); + match.setFile2( dest ); + + assertTrue( "Assert files are equal.", match.eval() ); + } + + private File createTemporaryFile() throws IOException { + File uploadFile; + uploadFile = File.createTempFile( "scp", "test", tempDir ); + FileWriter writer = new FileWriter( uploadFile ); + writer.write("Can you hear me now?\n"); + writer.close(); + addCleanup( uploadFile ); + return uploadFile; + } + + private Scp createTask() { + Scp scp = new Scp(); + Project p = new Project(); + p.init(); + scp.setProject( p ); + if( knownHosts != null ) { + scp.setKnownhosts( knownHosts ); + } else { + scp.setTrust( true ); + } + scp.setPort( port ); + return scp; + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java new file mode 100644 index 00000000..e36d6838 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java @@ -0,0 +1,297 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + * + */ + +/* + * Since the initial version of this file was deveolped on the clock on + * an NSF grant I should say the following boilerplate: + * + * This material is based upon work supported by the National Science + * Foundaton under Grant No. EIA-0196404. Any opinions, findings, and + * conclusions or recommendations expressed in this material are those + * of the author and do not necessarily reflect the views of the + * National Science Foundation. + */ + +package org.apache.tools.ant.taskdefs.optional.unix; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.taskdefs.condition.Os; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.SymbolicLinkUtils; +import org.junit.After; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; + +/** + * Test cases for the Symlink task. Link creation, link deletion, recording + * of links in multiple directories, and restoration of links recorded are + * all tested. A separate test for the utility method Symlink.deleteSymlink + * is not included because action="delete" only prints a message and calls + * Symlink.deleteSymlink, making a separate test redundant. + * + */ + +public class SymlinkTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private boolean supportsSymlinks = Os.isFamily("unix"); + + @Before + public void setUp() { + Assume.assumeTrue("Symlinks not supported on current operating system", supportsSymlinks); + buildRule.configureProject("src/etc/testcases/taskdefs/optional/unix/symlink.xml"); + buildRule.executeTarget("setUp"); + } + + @Test + public void testSingle() { + buildRule.executeTarget("test-single"); + Project p = buildRule.getProject(); + assertNotNull("Failed to create file", + p.getProperty("test.single.file.created")); + assertNotNull("Failed to create link", + p.getProperty("test.single.link.created")); + } + + @Test + public void testDelete() { + buildRule.executeTarget("test-delete"); + Project p = buildRule.getProject(); + String linkDeleted = p.getProperty("test.delete.link.still.there"); + assertNotNull("Actual file deleted by symlink", + p.getProperty("test.delete.file.still.there")); + if (linkDeleted != null) { + fail(linkDeleted); + } + } + + @Test + public void testRecord() { + buildRule.executeTarget("test-record"); + Project p = buildRule.getProject(); + + assertNotNull("Failed to create dir1", + p.getProperty("test.record.dir1.created")); + + assertNotNull("Failed to create dir2", + p.getProperty("test.record.dir2.created")); + + assertNotNull("Failed to create file1", + p.getProperty("test.record.file1.created")); + + assertNotNull("Failed to create file2", + p.getProperty("test.record.file2.created")); + + assertNotNull("Failed to create fileA", + p.getProperty("test.record.fileA.created")); + + assertNotNull("Failed to create fileB", + p.getProperty("test.record.fileB.created")); + + assertNotNull("Failed to create fileC", + p.getProperty("test.record.fileC.created")); + + assertNotNull("Failed to create link1", + p.getProperty("test.record.link1.created")); + + assertNotNull("Failed to create link2", + p.getProperty("test.record.link2.created")); + + assertNotNull("Failed to create link3", + p.getProperty("test.record.link3.created")); + + assertNotNull("Failed to create dirlink", + p.getProperty("test.record.dirlink.created")); + + assertNotNull("Failed to create dirlink2", + p.getProperty("test.record.dirlink2.created")); + + assertNotNull("Couldn't record links in dir1", + p.getProperty("test.record.dir1.recorded")); + + assertNotNull("Couldn't record links in dir2", + p.getProperty("test.record.dir2.recorded")); + + String dir3rec = p.getProperty("test.record.dir3.recorded"); + + if (dir3rec != null) { + fail(dir3rec); + } + + } + + @Test + public void testRecreate() { + buildRule.executeTarget("test-recreate"); + Project p = buildRule.getProject(); + String link1Rem = p.getProperty("test.recreate.link1.not.removed"); + String link2Rem = p.getProperty("test.recreate.link2.not.removed"); + String link3Rem = p.getProperty("test.recreate.link3.not.removed"); + String dirlinkRem = p.getProperty("test.recreate.dirlink.not.removed"); + if (link1Rem != null) { + fail(link1Rem); + } + if (link2Rem != null) { + fail(link2Rem); + } + if (link3Rem != null) { + fail(link3Rem); + } + if (dirlinkRem != null) { + fail(dirlinkRem); + } + assertNotNull("Failed to recreate link1", + p.getProperty("test.recreate.link1.recreated")); + assertNotNull("Failed to recreate link2", + p.getProperty("test.recreate.link2.recreated")); + assertNotNull("Failed to recreate link3", + p.getProperty("test.recreate.link3.recreated")); + assertNotNull("Failed to recreate dirlink", + p.getProperty("test.recreate.dirlink.recreated")); + + String doubleRecreate = p.getProperty("test.recreate.dirlink2.recreated.twice"); + + if (doubleRecreate != null) { + fail(doubleRecreate); + } + + assertNotNull("Failed to alter dirlink3", + p.getProperty("test.recreate.dirlink3.was.altered")); + } + + @Test + public void testSymbolicLinkUtilsMethods() throws Exception { + + buildRule.executeTarget("test-fileutils"); + SymbolicLinkUtils su = SymbolicLinkUtils.getSymbolicLinkUtils(); + + java.io.File f = new File(buildRule.getOutputDir(), "file1"); + assertTrue(f.exists()); + assertFalse(f.isDirectory()); + assertTrue(f.isFile()); + assertFalse(su.isSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isSymbolicLink(f.getParentFile(), + f.getName())); + assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + f = new File(buildRule.getOutputDir(), "dir1"); + assertTrue(f.exists()); + assertTrue(f.isDirectory()); + assertFalse(f.isFile()); + assertFalse(su.isSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isSymbolicLink(f.getParentFile(), + f.getName())); + assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + f = new File(buildRule.getOutputDir(), "file2"); + assertFalse(f.exists()); + assertFalse(f.isDirectory()); + assertFalse(f.isFile()); + assertFalse(su.isSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isSymbolicLink(f.getParentFile(), + f.getName())); + assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + f = new File(buildRule.getOutputDir(), "dir2"); + assertFalse(f.exists()); + assertFalse(f.isDirectory()); + assertFalse(f.isFile()); + assertFalse(su.isSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isSymbolicLink(f.getParentFile(), + f.getName())); + assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + + f = new File(buildRule.getOutputDir(), "file.there"); + assertTrue(f.exists()); + assertFalse(f.isDirectory()); + assertTrue(f.isFile()); + assertTrue(su.isSymbolicLink(f.getAbsolutePath())); + assertTrue(su.isSymbolicLink(f.getParentFile(), + f.getName())); + assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + f = new File(buildRule.getOutputDir(), "dir.there"); + assertTrue(f.exists()); + assertTrue(f.isDirectory()); + assertFalse(f.isFile()); + assertTrue(su.isSymbolicLink(f.getAbsolutePath())); + assertTrue(su.isSymbolicLink(f.getParentFile(), + f.getName())); + assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertFalse(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + // it is not possible to find out that symbolic links pointing + // to inexistent files or directories are symbolic links + // it used to be possible to detect this on Mac + // this is not true under Snow Leopard and JDK 1.5 + // Removing special handling of MacOS until someone shouts + // Antoine + f = new File(buildRule.getOutputDir(), "file.notthere"); + assertFalse(f.exists()); + assertFalse(f.isDirectory()); + assertFalse(f.isFile()); + assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false); + assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false); + assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertTrue(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + f = new File(buildRule.getOutputDir(), "dir.notthere"); + assertFalse(f.exists()); + assertFalse(f.isDirectory()); + assertFalse(f.isFile()); + assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false); + assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false); + assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath())); + assertTrue(su.isDanglingSymbolicLink(f.getParentFile(), + f.getName())); + + } + + @After + public void tearDown() { + if (buildRule.getProject() != null) { + buildRule.executeTarget("tearDown"); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java new file mode 100644 index 00000000..aa96d8d5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java @@ -0,0 +1,475 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.taskdefs.optional.vss; + +import java.io.File; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.TimeZone; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Location; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Tstamp; +import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.types.Path; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Testcase to ensure that command line generation and required attributes are correct. + * + */ +public class MSVSSTest implements MSVSSConstants { + + private Commandline commandline; + + private static final String VSS_PROJECT_PATH = "/SourceRoot/Project"; + private static final String DS_VSS_PROJECT_PATH = "$/SourceRoot/Project"; + private static final String VSS_USERNAME = "ant"; + private static final String VSS_PASSWORD = "rocks"; + private static final String LOCAL_PATH = "testdir"; + private static final String SRC_LABEL = "label1"; + private static final String LONG_LABEL = "123456789012345678901234567890"; + private static final String SRC_COMMENT = "I fixed a bug"; + private static final String VERSION = "007"; + private static final String DATE = "00-00-00"; + private static final String DATE2 = "01-01-01"; + private static final String OUTPUT = "output.log"; + private static final String SS_DIR = "c:/winnt".replace('/', File.separatorChar); + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + private Project project; + + @Before + public void setUp(){ + project = new Project(); + project.setBasedir("."); + project.init(); + } + + @After + public void tearDown() { + File file = new File(project.getBaseDir(), LOCAL_PATH); + if (file.exists()) { + file.delete(); + } + } + + @Test + public void testGetCommandLine() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_GET, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_OVERRIDE_WORKING_DIR + project.getBaseDir() + .getAbsolutePath() + + File.separator + LOCAL_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, + MSVSS.FLAG_RECURSION, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN + + VSS_USERNAME + "," + VSS_PASSWORD, FLAG_FILETIME_UPDATED, FLAG_SKIP_WRITABLE}; + + // Set up a VSSGet task + MSVSSGET vssGet = new MSVSSGET(); + vssGet.setProject(project); + vssGet.setRecursive(true); + vssGet.setLocalpath(new Path(project, LOCAL_PATH)); + vssGet.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); + vssGet.setVersion(VERSION); + vssGet.setQuiet(false); + vssGet.setDate(DATE); + vssGet.setLabel(SRC_LABEL); + vssGet.setVsspath(VSS_PROJECT_PATH); + MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated(); + cmu.setValue(TIME_UPDATED); + vssGet.setFileTimeStamp(cmu); + MSVSS.WritableFiles wf = new MSVSS.WritableFiles(); + wf.setValue(WRITABLE_SKIP); + vssGet.setWritableFiles(wf); + + commandline = vssGet.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Tests VSSGet required attributes. */ + @Test + public void testGetExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vssget.1", "some cause", "vsspath attribute must be set!"); + } + + /** Tests Label commandline generation. */ + @Test + public void testLabelCommandLine1() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_YES, + MSVSS.FLAG_LABEL + SRC_LABEL, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN + + VSS_USERNAME + "," + VSS_PASSWORD}; + + // Set up a VSSLabel task + MSVSSLABEL vssLabel = new MSVSSLABEL(); + vssLabel.setProject(project); + vssLabel.setComment(SRC_COMMENT); + vssLabel.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); + vssLabel.setVersion(VERSION); + vssLabel.setAutoresponse("Y"); + vssLabel.setLabel(SRC_LABEL); + vssLabel.setVsspath(VSS_PROJECT_PATH); + + commandline = vssLabel.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Tests Label commandline generation with a label of more than 31 chars. */ + @Test + public void testLabelCommandLine2() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_DEF, + MSVSS.FLAG_LABEL + LONG_LABEL, + MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD}; + + // Set up a VSSLabel task + MSVSSLABEL vssLabel = new MSVSSLABEL(); + vssLabel.setProject(project); + vssLabel.setComment(SRC_COMMENT); + vssLabel.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); + vssLabel.setLabel(LONG_LABEL + "blahblah"); + vssLabel.setVsspath(VSS_PROJECT_PATH); + + commandline = vssLabel.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Test VSSLabel required attributes. + */ + @Test + public void testLabelExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vsslabel.1", "some cause", "vsspath attribute must be set!"); + expectSpecificBuildException("vsslabel.2", "some cause", "label attribute must be set!"); + } + + /** Tests VSSHistory commandline generation with from label. */ + @Test + public void testHistoryCommandLine1() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_LABEL + LONG_LABEL + + MSVSS.VALUE_FROMLABEL + SRC_LABEL, MSVSS.FLAG_LOGIN + VSS_USERNAME + + "," + VSS_PASSWORD, MSVSS.FLAG_OUTPUT + project.getBaseDir() + .getAbsolutePath() + + File.separator + OUTPUT}; + + // Set up a VSSHistory task + MSVSSHISTORY vssHistory = new MSVSSHISTORY(); + vssHistory.setProject(project); + + vssHistory.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); + + vssHistory.setFromLabel(SRC_LABEL); + vssHistory.setToLabel(LONG_LABEL + "blahblah"); + vssHistory.setVsspath(VSS_PROJECT_PATH); + vssHistory.setRecursive(false); + vssHistory.setOutput(new File(project.getBaseDir().getAbsolutePath(), OUTPUT)); + + commandline = vssHistory.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Tests VSSHistory commandline generation with from date. */ + @Test + public void testHistoryCommandLine2() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + DATE + MSVSS.VALUE_FROMDATE + + DATE2, MSVSS.FLAG_RECURSION, MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD}; + + // Set up a VSSHistory task + MSVSSHISTORY vssHistory = new MSVSSHISTORY(); + vssHistory.setProject(project); + vssHistory.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); + vssHistory.setFromDate(DATE2); + vssHistory.setToDate(DATE); + vssHistory.setVsspath(VSS_PROJECT_PATH); + vssHistory.setRecursive(true); + + commandline = vssHistory.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** Tests VSSHistory commandline generation with date calculation. */ + @Test + public void testHistoryCommandLine3() { + // Set up a Timestamp + Tstamp tstamp = new Tstamp(); + Location location = new Location("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + tstamp.setLocation(location); + tstamp.setProject(project); + Tstamp.CustomFormat format = tstamp.createFormat(); + format.setProperty("today"); + format.setPattern("HH:mm:ss z"); + format.setTimezone("GMT"); + Date date = Calendar.getInstance().getTime(); + format.execute(project, date, location); + String today = project.getProperty("today"); + + // Get today's date + SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z"); + sdf.setTimeZone( TimeZone.getTimeZone("GMT") ); + String expected = sdf.format(date); + + // Set up a VSSHistory task + MSVSSHISTORY vssHistory = new MSVSSHISTORY(); + vssHistory.setProject(project); + vssHistory.setLogin(VSS_USERNAME); + vssHistory.setToDate(today); + vssHistory.setVsspath(VSS_PROJECT_PATH); + + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + expected, MSVSS.FLAG_LOGIN + VSS_USERNAME}; + + commandline = vssHistory.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Tests VSSHistory required attributes. + */ + @Test + public void testHistoryExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vsshistory.1", "some cause", "vsspath attribute must be set!"); + } + + private void expectSpecificBuildException(String target, String failMessage, + String exceptionMessage) { + try { + buildRule.executeTarget(target); + fail(failMessage); + } catch(BuildException ex) { + assertEquals(exceptionMessage, ex.getMessage()); + } + } + + /** Tests CheckIn commandline generation. */ + @Test + public void testCheckinCommandLine() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CHECKIN, DS_VSS_PROJECT_PATH, + MSVSS.FLAG_AUTORESPONSE_NO, MSVSS.FLAG_WRITABLE, MSVSS.FLAG_LOGIN + VSS_USERNAME, + MSVSS.FLAG_COMMENT + SRC_COMMENT}; + + // Set up a VSSCheckIn task + MSVSSCHECKIN vssCheckin = new MSVSSCHECKIN(); + vssCheckin.setProject(project); + vssCheckin.setComment(SRC_COMMENT); + vssCheckin.setLogin(VSS_USERNAME); + vssCheckin.setAutoresponse("N"); + vssCheckin.setVsspath(VSS_PROJECT_PATH); + vssCheckin.setWritable(true); + + commandline = vssCheckin.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Test VSSCheckIn required attributes. + */ + @Test + public void testCheckinExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vsscheckin.1", "some cause", "vsspath attribute must be set!"); + } + + /** Tests CheckOut commandline generation. */ + @Test + public void testCheckoutCommandLine() { + String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_CHECKOUT, + DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION, + MSVSS.FLAG_VERSION_DATE + DATE, MSVSS.FLAG_LOGIN + VSS_USERNAME, + FLAG_FILETIME_MODIFIED, FLAG_NO_GET}; + + // Set up a VSSCheckOut task + MSVSSCHECKOUT vssCheckout = new MSVSSCHECKOUT(); + vssCheckout.setProject(project); + vssCheckout.setLogin(VSS_USERNAME); + vssCheckout.setVsspath(DS_VSS_PROJECT_PATH); + vssCheckout.setRecursive(true); + vssCheckout.setDate(DATE); + vssCheckout.setLabel(SRC_LABEL); + vssCheckout.setSsdir(SS_DIR); + MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated(); + cmu.setValue(TIME_MODIFIED); + vssCheckout.setFileTimeStamp(cmu); + vssCheckout.setGetLocalCopy(false); + + commandline = vssCheckout.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Test VSSCheckout required attributes. + */ + @Test + public void testCheckoutExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vsscheckout.1", "some cause", "vsspath attribute must be set!"); + expectSpecificBuildException("vsscheckout.2", "some cause", "blah is not a legal value for this attribute"); + } + + /** Tests Add commandline generation. */ + @Test + public void testAddCommandLine() { + String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_ADD, + project.getBaseDir().getAbsolutePath() + File.separator + LOCAL_PATH, + MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION, + MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD, MSVSS.FLAG_COMMENT + "-"}; + + // Set up a VSSAdd task + MSVSSADD vssAdd = new MSVSSADD(); + vssAdd.setProject(project); + vssAdd.setLogin(VSS_USERNAME + "," + VSS_PASSWORD); + vssAdd.setVsspath(DS_VSS_PROJECT_PATH); + vssAdd.setRecursive(true); + vssAdd.setSsdir(SS_DIR); + vssAdd.setWritable(false); + vssAdd.setLocalpath(new Path(project, LOCAL_PATH)); + + commandline = vssAdd.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Test VSSAdd required attributes. + */ + @Test + public void testAddExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vssadd.1", "some cause", "localPath attribute must be set!"); + } + + /** Tests CP commandline generation. */ + @Test + public void testCpCommandLine() { + String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CP, + DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_LOGIN + + VSS_USERNAME}; + + // Set up a VSSCp task + MSVSSCP vssCp = new MSVSSCP(); + vssCp.setProject(project); + vssCp.setLogin(VSS_USERNAME); + vssCp.setVsspath(DS_VSS_PROJECT_PATH); + + commandline = vssCp.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Test VSSCP required attributes. + */ + @Test + public void testCpExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vsscp.1", "some cause", "vsspath attribute must be set!"); + } + + /** Tests Create commandline generation. */ + @Test + public void testCreateCommandLine() { + String[] sTestCmdLine = { MSVSS.SS_EXE, MSVSS.COMMAND_CREATE, + DS_VSS_PROJECT_PATH, MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_NO, + MSVSS.FLAG_QUIET, MSVSS.FLAG_LOGIN + VSS_USERNAME}; + + // Set up a VSSCreate task + MSVSSCREATE vssCreate = new MSVSSCREATE(); + vssCreate.setProject(project); + vssCreate.setComment(SRC_COMMENT); + vssCreate.setLogin(VSS_USERNAME); + vssCreate.setVsspath(DS_VSS_PROJECT_PATH); + vssCreate.setFailOnError(true); + vssCreate.setAutoresponse("N"); + vssCreate.setQuiet(true); + + commandline = vssCreate.buildCmdLine(); + + checkCommandLines(sTestCmdLine, commandline.getCommandline()); + } + + /** + * Test VSSCreate required attributes. + */ + @Test + public void testCreateExceptions() { + buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml"); + expectSpecificBuildException("vsscreate.1", "some cause", "vsspath attribute must be set!"); + } + + /** + * Iterate through the generated command line comparing it to reference one. + * @param sTestCmdLine The reference command line; + * @param sGeneratedCmdLine The generated command line; + */ + private void checkCommandLines(String[] sTestCmdLine, String[] sGeneratedCmdLine) { + int testLength = sTestCmdLine.length; + int genLength = sGeneratedCmdLine.length; + + int genIndex = 0; + int testIndex = 0; + + while (testIndex < testLength) { + try { + if (sGeneratedCmdLine[genIndex].equals("")) { + genIndex++; + continue; + } + assertEquals("arg # " + testIndex, + sTestCmdLine[testIndex], + sGeneratedCmdLine[genIndex]); + testIndex++; + genIndex++; + } catch (ArrayIndexOutOfBoundsException aioob) { + fail("missing arg " + sTestCmdLine[testIndex]); + } + } + + // Count the number of empty strings + int cnt = 0; + for (int i = 0; i < genLength; i++) { + if (sGeneratedCmdLine[i].equals("")) { + cnt++; + } + } + if (genLength - cnt > sTestCmdLine.length) { + // We have extra elements + fail("extra args"); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java new file mode 100644 index 00000000..aa4fd39c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java @@ -0,0 +1,248 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Base class for FileSetTest and DirSetTest. + * + * <p>This doesn't actually test much, mainly reference handling. + * + */ + +public abstract class AbstractFileSetTest { + + private Project project; + + + @Before + public void setUp() { + project = new Project(); + project.setBasedir("."); + } + + protected abstract AbstractFileSet getInstance(); + + protected final Project getProject() { + return project; + } + + @Test + public final void testEmptyElementIfIsReference() { + AbstractFileSet f = getInstance(); + f.setIncludes("**/*.java"); + try { + f.setRefid(new Reference(getProject(), "dummyref")); + fail("Can add reference to " + + f.getDataTypeName() + + " with elements from setIncludes"); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + + f = getInstance(); + f.createPatternSet(); + try { + f.setRefid(new Reference(getProject(), "dummyref")); + fail("Can add reference to " + + f.getDataTypeName() + + " with nested patternset element."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when " + + "using refid", be.getMessage()); + } + + f = getInstance(); + f.createInclude(); + try { + f.setRefid(new Reference(getProject(), "dummyref")); + fail("Can add reference to " + + f.getDataTypeName() + + " with nested include element."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + + f = getInstance(); + f.setRefid(new Reference(getProject(), "dummyref")); + try { + f.setIncludes("**/*.java"); + fail("Can set includes in " + + f.getDataTypeName() + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + try { + f.setIncludesfile(new File("/a")); + fail("Can set includesfile in " + + f.getDataTypeName() + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + try { + f.setExcludes("**/*.java"); + fail("Can set excludes in " + + f.getDataTypeName() + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + try { + f.setExcludesfile(new File("/a")); + fail("Can set excludesfile in " + + f.getDataTypeName() + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + try { + f.setDir(project.resolveFile(".")); + fail("Can set dir in " + + f.getDataTypeName() + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + try { + f.createInclude(); + fail("Can add nested include in " + + f.getDataTypeName() + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using " + + "refid", be.getMessage()); + } + try { + f.createExclude(); + fail("Can add nested exclude in " + + f.getDataTypeName() + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using " + + "refid", be.getMessage()); + } + try { + f.createIncludesFile(); + fail("Can add nested includesfile in " + + f.getDataTypeName() + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using " + + "refid", be.getMessage()); + } + try { + f.createExcludesFile(); + fail("Can add nested excludesfile in " + + f.getDataTypeName() + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using " + + "refid", be.getMessage()); + } + try { + f.createPatternSet(); + fail("Can add nested patternset in " + + f.getDataTypeName() + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using " + + "refid", be.getMessage()); + } + } + + @Test + public void testCircularReferenceCheck() { + AbstractFileSet f = getInstance(); + project.addReference("dummy", f); + f.setRefid(new Reference(getProject(), "dummy")); + try { + f.getDir(project); + fail("Can make " + f.getDataTypeName() + + " a Reference to itself."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + try { + f.getDirectoryScanner(project); + fail("Can make " + f.getDataTypeName() + + " a Reference to itself."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + + // dummy1 --> dummy2 --> dummy3 --> dummy1 + AbstractFileSet f1 = getInstance(); + project.addReference("dummy1", f1); + f1.setRefid(new Reference(getProject(), "dummy2")); + AbstractFileSet f2 = getInstance(); + project.addReference("dummy2", f2); + f2.setRefid(new Reference(getProject(), "dummy3")); + AbstractFileSet f3 = getInstance(); + project.addReference("dummy3", f3); + f3.setRefid(new Reference(getProject(), "dummy1")); + try { + f1.getDir(project); + fail("Can make circular reference."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + try { + f1.getDirectoryScanner(project); + fail("Can make circular reference."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + + // dummy1 --> dummy2 --> dummy3 + // (which has the Project's basedir as root). + f1 = getInstance(); + project.addReference("dummy1", f1); + f1.setRefid(new Reference(getProject(), "dummy2")); + f2 = getInstance(); + project.addReference("dummy2", f2); + f2.setRefid(new Reference(getProject(), "dummy3")); + f3 = getInstance(); + project.addReference("dummy3", f3); + f3.setDir(project.resolveFile(".")); + File dir = f1.getDir(project); + assertEquals("Dir is basedir", dir, project.getBaseDir()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java new file mode 100644 index 00000000..6c91a9af --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java @@ -0,0 +1,223 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.taskdefs.condition.Condition; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class AddTypeTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/addtype.xml"); + } + + @Test + public void testAddPath() { + buildRule.executeTarget("addpath"); + } + + @Test + public void testAddCondition() { + buildRule.executeTarget("addcondition"); + } + + @Test + public void testAddFilter() { + buildRule.executeTarget("addfilter"); + } + + @Test + public void testAddSelector() { + buildRule.executeTarget("addselector"); + } + + @Test + public void testNestedA() { + buildRule.executeTarget("nested.a"); + AntAssert.assertContains("add A called", buildRule.getLog()); + } + + @Test + public void testNestedB() { + buildRule.executeTarget("nested.b"); + AntAssert.assertContains( "add B called", buildRule.getLog()); + } + + @Test + public void testNestedC() { + buildRule.executeTarget("nested.c"); + AntAssert.assertContains( "add C called", buildRule.getLog()); + } + + @Test + public void testNestedAB() { + try { + buildRule.executeTarget("nested.ab"); + fail("Build exception expected: Should have got ambiguous"); + } catch (BuildException ex) { + AntAssert.assertContains("ambiguous", ex.getMessage()); + } + } + + @Test + public void testConditionType() { + buildRule.executeTarget("condition.type"); + AntAssert.assertContains( "beforeafter", buildRule.getLog()); + } + + @Test + public void testConditionTask() { + buildRule.executeTarget("condition.task"); + AntAssert.assertContains( "My Condition execution", buildRule.getLog()); + } + + @Test + public void testConditionConditionType() { + buildRule.executeTarget("condition.condition.type"); + AntAssert.assertContains( "My Condition eval", buildRule.getLog()); + } + + @Test + public void testConditionConditionTask() { + try { + buildRule.executeTarget("condition.condition.task"); + fail("Build exception expected: Task masking condition"); + } catch (BuildException ex) { + AntAssert.assertContains("doesn't support the nested", ex.getMessage()); + } + } + + @Test + public void testAddConfigured() { + buildRule.executeTarget("myaddconfigured"); + AntAssert.assertContains("value is Value Setexecute: value is Value Set", + buildRule.getLog()); + } + + @Test + public void testAddConfiguredValue() { + buildRule.executeTarget("myaddconfiguredvalue"); + AntAssert.assertContains("value is Value Setexecute: value is Value Set", + buildRule.getLog()); + } + + @Test + public void testNamespace() { + buildRule.executeTarget("namespacetest"); + } + + // The following will be used as types and tasks + + public static interface A {} + public static interface B {} + public static interface C extends A {} + public static interface AB extends A, B {} + + public static class AImpl implements A{} + public static class BImpl implements B{} + public static class CImpl implements C{} + public static class ABImpl implements AB{} + + public static class NestedContainer + extends Task + { + public void add(A el) { + log("add A called"); + } + public void add(B el) { + log("add B called"); + } + public void add(C el) { + log("add C called"); + } + } + + public static class MyCondition + implements Condition + { + Project project; + public void setProject(Project project) { + this.project = project; + } + public boolean eval() { + project.log("My Condition eval"); + return true; + } + public void execute() { + project.log("My Condition execution"); + } + } + + public static class MyValue + { + private String text = "NOT SET YET"; + public void addText(String text) { + this.text = text; + } + public String toString() { + return text; + } + } + + public static class MyAddConfigured + extends Task + { + MyValue value; + public void addConfigured(MyValue value) { + log("value is " + value); + this.value = value; + } + public void add(MyValue value) { + throw new BuildException("Should not be called"); + } + public void execute() { + log("execute: value is " + value); + } + } + + public static class MyAddConfiguredValue + extends Task + { + MyValue value; + public void addConfiguredValue(MyValue value) { + log("value is " + value); + this.value = value; + } + public void addValue(MyValue value) { + throw new BuildException("Should not be called"); + } + public void execute() { + log("execute: value is " + value); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java new file mode 100644 index 00000000..4210fc1a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.fail; + +/** + * test assertion handling + */ +public class AssertionsTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/assertions.xml"); + } + + + /** + * runs a test and expects an assertion thrown in forked code + * @param target + */ + private void expectAssertion(String target) { + try { + buildRule.executeTarget(target); + fail("BuildException should have been thrown by assertion fail in task"); + } catch (BuildException ex) { + assertContains("assertion not thrown in "+target, "Java returned: 1", ex.getMessage()); + } + } + + @Test + public void testClassname() { + expectAssertion("test-classname"); + } + + @Test + public void testPackage() { + expectAssertion("test-package"); + } + + @Test + public void testEmptyAssertions() { + buildRule.executeTarget("test-empty-assertions"); + } + + @Test + public void testDisable() { + buildRule.executeTarget("test-disable"); + } + + @Test + public void testOverride() { + expectAssertion("test-override"); + } + + @Test + public void testOverride2() { + buildRule.executeTarget("test-override2"); + } + + @Test + public void testReferences() { + expectAssertion("test-references"); + } + + @Test + public void testMultipleAssertions() { + try { + buildRule.executeTarget("test-multiple-assertions"); + fail("BuildException should have been thrown by assertion fail in task"); + } catch (BuildException ex) { + assertContains("multiple assertions rejected", "Only one assertion declaration is allowed", ex.getMessage()); + } + } + + @Test + public void testReferenceAbuse() { + try { + buildRule.executeTarget("test-reference-abuse"); + fail("BuildException should have been thrown by reference abuse"); + } catch (BuildException ex) { + assertContains("reference abuse rejected", "You must not specify", ex.getMessage()); + } + } + + @Test + public void testNofork() { + Assume.assumeFalse("ran Ant tests with -ea and this would fail spuriously", AssertionsTest.class.desiredAssertionStatus()); + buildRule.executeTarget("test-nofork"); + assertContains("Assertion statements are currently ignored in non-forked mode", buildRule.getLog()); + } + + @Test + public void testJUnit() { + buildRule.executeTarget("test-junit"); + } +} + + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java new file mode 100644 index 00000000..c18ff5ee --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java @@ -0,0 +1,191 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + + +import org.apache.tools.ant.MagicNames; +import org.apache.tools.ant.Project; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +/** + * JUnit testcases for org.apache.tools.ant.CommandlineJava + * + */ +public class CommandlineJavaTest { + + private String cloneVm; + + + private Project project; + + @Before + public void setUp() { + project = new Project(); + project.setBasedir(System.getProperty("root")); + project.setProperty("build.sysclasspath", "ignore"); + cloneVm = System.getProperty("ant.build.clonevm"); + if (cloneVm != null) { + System.setProperty("ant.build.clonevm", "false"); + } + } + + @After + public void tearDown() { + if (cloneVm != null) { + System.setProperty("ant.build.clonevm", cloneVm); + } + } + + @Test + public void testGetCommandline() throws Exception { + CommandlineJava c = new CommandlineJava(); + c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest"); + c.setClassname("junit.textui.TestRunner"); + c.createVmArgument().setValue("-Djava.compiler=NONE"); + String[] s = c.getCommandline(); + assertEquals("no classpath", 4, s.length); + /* + * After changing CommandlineJava to search for the java + * executable, I don't know, how to tests the value returned + * here without using the same logic as applied in the class + * itself. + * + * assertTrue("no classpath", "java", s[0]); + */ + assertEquals("no classpath", "-Djava.compiler=NONE", s[1]); + assertEquals("no classpath", "junit.textui.TestRunner", s[2]); + assertEquals("no classpath", + "org.apache.tools.ant.CommandlineJavaTest", s[3]); + try { + c.clone(); + } catch (NullPointerException ex) { + fail("cloning should work without classpath specified"); + } + + c.createClasspath(project).setLocation(project.resolveFile("build.xml")); + c.createClasspath(project).setLocation(project.resolveFile( + System.getProperty(MagicNames.ANT_HOME)+"/lib/ant.jar")); + s = c.getCommandline(); + assertEquals("with classpath", 6, s.length); + // assertEquals("with classpath", "java", s[0]); + assertEquals("with classpath", "-Djava.compiler=NONE", s[1]); + assertEquals("with classpath", "-classpath", s[2]); + assertTrue("build.xml contained", + s[3].indexOf("build.xml"+java.io.File.pathSeparator) >= 0); + assertTrue("ant.jar contained", s[3].endsWith("ant.jar")); + assertEquals("with classpath", "junit.textui.TestRunner", s[4]); + assertEquals("with classpath", + "org.apache.tools.ant.CommandlineJavaTest", s[5]); + } + + @Test + public void testJarOption() throws Exception { + CommandlineJava c = new CommandlineJava(); + c.createArgument().setValue("arg1"); + c.setJar("myfile.jar"); + c.createVmArgument().setValue("-classic"); + c.createVmArgument().setValue("-Dx=y"); + String[] s = c.getCommandline(); + assertEquals("-classic", s[1]); + assertEquals("-Dx=y", s[2]); + assertEquals("-jar", s[3]); + assertEquals("myfile.jar", s[4]); + assertEquals("arg1", s[5]); + } + + @Test + public void testSysproperties() { + String currentClasspath = System.getProperty("java.class.path"); + assertNotNull(currentClasspath); + assertNull(System.getProperty("key")); + CommandlineJava c = new CommandlineJava(); + Environment.Variable v = new Environment.Variable(); + v.setKey("key"); + v.setValue("value"); + c.addSysproperty(v); + + project.setProperty("key2", "value2"); + PropertySet ps = new PropertySet(); + ps.setProject(project); + ps.appendName("key2"); + c.addSyspropertyset(ps); + + try { + c.setSystemProperties(); + String newClasspath = System.getProperty("java.class.path"); + assertNotNull(newClasspath); + assertEquals(currentClasspath, newClasspath); + assertNotNull(System.getProperty("key")); + assertEquals("value", System.getProperty("key")); + assertTrue(System.getProperties().containsKey("java.class.path")); + assertNotNull(System.getProperty("key2")); + assertEquals("value2", System.getProperty("key2")); + } finally { + c.restoreSystemProperties(); + } + assertNull(System.getProperty("key")); + assertNull(System.getProperty("key2")); + } + + @Test + public void testAssertions() throws Exception { + CommandlineJava c = new CommandlineJava(); + c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest"); + c.setClassname("junit.textui.TestRunner"); + c.createVmArgument().setValue("-Djava.compiler=NONE"); + Assertions a = new Assertions(); + a.setProject(project); + Assertions.EnabledAssertion ea = new Assertions.EnabledAssertion(); + ea.setClass("junit.textui.TestRunner"); + a.addEnable(ea); + c.setAssertions(a); + + String[] expected = new String[] { + null, + "-Djava.compiler=NONE", + "-ea:junit.textui.TestRunner", + "junit.textui.TestRunner", + "org.apache.tools.ant.CommandlineJavaTest", + }; + + // only the second iteration would pass because of PR 27218 + for (int i = 0; i < 3; i++) { + String[] s = c.getCommandline(); + assertEquals(expected.length, s.length); + for (int j = 1; j < expected.length; j++) { + assertEquals(expected[j], s[j]); + } + } + CommandlineJava c2 = (CommandlineJava) c.clone(); + String[] s = c2.getCommandline(); + assertEquals(expected.length, s.length); + for (int j = 1; j < expected.length; j++) { + assertEquals(expected[j], s[j]); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java new file mode 100644 index 00000000..e8e44429 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java @@ -0,0 +1,180 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import org.apache.tools.ant.BuildException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.junit.Assert.assertNotNull; + +/** + * JUnit 3 testcases for org.apache.tools.ant.CommandLine + * + */ +public class CommandlineTest { + + @Test + public void testTokenizer() { + String[] s = Commandline.translateCommandline("1 2 3"); + assertEquals("Simple case", 3, s.length); + for (int i=0; i<3; i++) { + assertEquals(""+(i+1), s[i]); + } + + s = Commandline.translateCommandline(""); + assertEquals("empty string", 0, s.length); + + s = Commandline.translateCommandline(null); + assertEquals("null", 0, s.length); + + s = Commandline.translateCommandline("1 \'2\' 3"); + assertEquals("Simple case with single quotes", 3, s.length); + assertEquals("Single quotes have been stripped", "2", s[1]); + + s = Commandline.translateCommandline("1 \"2\" 3"); + assertEquals("Simple case with double quotes", 3, s.length); + assertEquals("Double quotes have been stripped", "2", s[1]); + + s = Commandline.translateCommandline("1 \"2 3\" 4"); + assertEquals("Case with double quotes and whitespace", 3, s.length); + assertEquals("Double quotes stripped, space included", "2 3", s[1]); + + s = Commandline.translateCommandline("1 \"2\'3\" 4"); + assertEquals("Case with double quotes around single quote", 3, s.length); + assertEquals("Double quotes stripped, single quote included", "2\'3", + s[1]); + + s = Commandline.translateCommandline("1 \'2 3\' 4"); + assertEquals("Case with single quotes and whitespace", 3, s.length); + assertEquals("Single quotes stripped, space included", "2 3", s[1]); + + s = Commandline.translateCommandline("1 \'2\"3\' 4"); + assertEquals("Case with single quotes around double quote", 3, s.length); + assertEquals("Single quotes stripped, double quote included", "2\"3", + s[1]); + + // \ doesn't have a special meaning anymore - this is different from + // what the Unix sh does but causes a lot of problems on DOS + // based platforms otherwise + s = Commandline.translateCommandline("1 2\\ 3 4"); + assertEquals("case with quoted whitespace", 4, s.length); + assertEquals("backslash included", "2\\", s[1]); + + // "" should become a single empty argument, same for '' + // PR 5906 + s = Commandline.translateCommandline("\"\" a"); + assertEquals("Doublequoted null arg prepend", 2, s.length); + assertEquals("Doublequoted null arg prepend", "", s[0]); + assertEquals("Doublequoted null arg prepend", "a", s[1]); + s = Commandline.translateCommandline("a \"\""); + assertEquals("Doublequoted null arg append", 2, s.length); + assertEquals("Doublequoted null arg append", "a", s[0]); + assertEquals("Doublequoted null arg append", "", s[1]); + s = Commandline.translateCommandline("\"\""); + assertEquals("Doublequoted null arg", 1, s.length); + assertEquals("Doublequoted null arg", "", s[0]); + + s = Commandline.translateCommandline("\'\' a"); + assertEquals("Singlequoted null arg prepend", 2, s.length); + assertEquals("Singlequoted null arg prepend", "", s[0]); + assertEquals("Singlequoted null arg prepend", "a", s[1]); + s = Commandline.translateCommandline("a \'\'"); + assertEquals("Singlequoted null arg append", 2, s.length); + assertEquals("Singlequoted null arg append", "a", s[0]); + assertEquals("Singlequoted null arg append", "", s[1]); + s = Commandline.translateCommandline("\'\'"); + assertEquals("Singlequoted null arg", 1, s.length); + assertEquals("Singlequoted null arg", "", s[0]); + + // now to the expected failures + + try { + Commandline.translateCommandline("a \'b c"); + fail("unbalanced single quotes undetected"); + } catch (BuildException be) { + assertEquals("unbalanced quotes in a \'b c", be.getMessage()); + } + + try { + Commandline.translateCommandline("a \"b c"); + fail("unbalanced double quotes undetected"); + } catch (BuildException be) { + assertEquals("unbalanced quotes in a \"b c", be.getMessage()); + } + } + + @Test + public void testToString() { + assertEquals("", Commandline.toString(new String[0])); + assertEquals("", Commandline.toString(null)); + assertEquals("1 2 3", Commandline.toString(new String[] {"1", "2", "3"})); + assertEquals("1 \"2 3\"", Commandline.toString(new String[] {"1", "2 3"})); + assertEquals("1 \"2\'3\"", Commandline.toString(new String[] {"1", "2\'3"})); + assertEquals("1 \'2\"3\'", Commandline.toString(new String[] {"1", "2\"3"})); + } + + @Test + public void testAwkCommand() { + Commandline c = new Commandline(); + c.setExecutable("awk"); + c.createArgument().setValue("'NR == 2 { print $NF }'"); + String[] s = c.getCommandline(); + assertNotNull(s); + assertEquals(2, s.length); + assertEquals("awk", s[0]); + assertEquals("'NR == 2 { print $NF }'", s[1]); + } + + @Test + public void testPrefix() { + Commandline c = new Commandline(); + Commandline.Argument a = c.createArgument(); + a.setValue("foo"); + a.setPrefix("-f="); + String[] s = c.getCommandline(); + assertEquals(1, s.length); + assertEquals("-f=foo", s[0]); + } + + @Test + public void testSuffix() { + Commandline c = new Commandline(); + Commandline.Argument a = c.createArgument(); + a.setValue("foo"); + a.setSuffix(",1"); + String[] s = c.getCommandline(); + assertEquals(1, s.length); + assertEquals("foo,1", s[0]); + } + + @Test + public void testPrefixSuffixLine() { + Commandline c = new Commandline(); + Commandline.Argument a = c.createArgument(); + a.setLine("one two"); + a.setPrefix("number "); + a.setSuffix("."); + String[] s = c.getCommandline(); + assertEquals(2, s.length); + assertEquals("number one.", s[0]); + assertEquals("number two.", s[1]); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java new file mode 100644 index 00000000..90dbce7f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * FilterSet testing + * + */ +public class DescriptionTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Test + public void test1() { + buildRule.configureProject("src/etc/testcases/types/description1.xml"); + assertEquals("Single description failed", "Test Project Description", buildRule.getProject().getDescription()); + } + + @Test + public void test2() { + buildRule.configureProject("src/etc/testcases/types/description2.xml"); + assertEquals("Multi line description failed", "Multi Line\nProject Description", buildRule.getProject().getDescription()); + } + + @Test + public void test3() { + buildRule.configureProject("src/etc/testcases/types/description3.xml"); + assertEquals("Multi instance description failed", "Multi Instance Project Description", buildRule.getProject().getDescription()); + } + + @Test + public void test4() { + buildRule.configureProject("src/etc/testcases/types/description4.xml"); + assertEquals("Multi instance nested description failed", "Multi Instance Nested Project Description", buildRule.getProject().getDescription()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java new file mode 100644 index 00000000..8c659ba7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import java.io.File; +import java.io.FileOutputStream; +import org.apache.tools.ant.BuildException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * JUnit 3 testcases for org.apache.tools.ant.types.DirSet. + * + */ +public class DirSetTest extends AbstractFileSetTest { + + protected AbstractFileSet getInstance() { + return new DirSet(); + } + + @Test + public void testFileSetIsNoDirSet() { + DirSet ds = (DirSet) getInstance(); + ds.setProject(getProject()); + FileSet fs = new FileSet(); + fs.setProject(getProject()); + getProject().addReference("dummy", fs); + ds.setRefid(new Reference(getProject(), "dummy")); + try { + ds.getDir(getProject()); + fail("DirSet created from FileSet reference"); + } catch (BuildException e) { + assertEquals("dummy doesn\'t denote a DirSet", e.getMessage()); + } + + ds = (DirSet) getInstance(); + ds.setProject(getProject()); + getProject().addReference("dummy2", ds); + fs.setRefid(new Reference(getProject(), "dummy2")); + try { + fs.getDir(getProject()); + fail("FileSet created from DirSet reference"); + } catch (BuildException e) { + assertEquals("dummy2 doesn\'t denote a FileSet", e.getMessage()); + } + } + + public void testToString() throws Exception { + File tmp = File.createTempFile("DirSetTest", ""); + try { + tmp.delete(); + File a = new File(tmp, "a"); + a.mkdirs(); + File b = new File(tmp, "b"); + File bc = new File(b, "c"); + bc.mkdirs(); + new FileOutputStream(new File(a, "x")).close(); + new FileOutputStream(new File(b, "x")).close(); + new FileOutputStream(new File(bc, "x")).close(); + DirSet ds = new DirSet(); + ds.setProject(getProject()); + ds.setDir(tmp); + ds.setIncludes("b/"); + assertEquals("b;b" + File.separator + "c", ds.toString()); + } finally { + new File(tmp, "a/x").delete(); + new File(tmp, "a").delete(); + new File(tmp, "b/c/x").delete(); + new File(tmp, "b/c").delete(); + new File(tmp, "b/x").delete(); + new File(tmp, "b").delete(); + tmp.delete(); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java new file mode 100644 index 00000000..0e2e241e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + + +import org.apache.tools.ant.BuildException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * JUnit testcases for org.apache.tools.ant.EnumeratedAttribute. + */ +public class EnumeratedAttributeTest { + + private static String[] expected = {"a", "b", "c"}; + + @Test + public void testContains() { + EnumeratedAttribute t1 = new TestNormal(); + for (int i=0; i<expected.length; i++) { + assertTrue(expected[i]+" is in TestNormal", + t1.containsValue(expected[i])); + assertTrue(expected[i].toUpperCase()+" is in TestNormal", + !t1.containsValue(expected[i].toUpperCase())); + } + assertTrue("TestNormal doesn\'t have \"d\" attribute", + !t1.containsValue("d")); + assertTrue("TestNull doesn\'t have \"d\" attribute and doesn\'t die", + !(new TestNull()).containsValue("d")); + } + + @Test + public void testFactory() { + Factory ea = (Factory)EnumeratedAttribute.getInstance(Factory.class, "one"); + assertEquals("Factory did not set the right value.", ea.getValue(), "one"); + try { + EnumeratedAttribute.getInstance(Factory.class, "illegal"); + fail("Factory should fail when trying to set an illegal value."); + } catch (BuildException be) { + // was expected + //TODO assert exception message + } + } + + @Test + public void testExceptions() { + EnumeratedAttribute t1 = new TestNormal(); + for (int i=0; i<expected.length; i++) { + try { + t1.setValue(expected[i]); + } catch (BuildException be) { + fail("unexpected exception for value "+expected[i]); + } + } + try { + t1.setValue("d"); + fail("expected exception for value \"d\""); + } catch (BuildException be) { + //TODO assert build exception + } + try { + (new TestNull()).setValue("d"); + fail("expected exception for value \"d\" in TestNull"); + } catch (BuildException be) { + //TODO assert exception message + } + } + + public static class TestNormal extends EnumeratedAttribute { + public String[] getValues() { + return expected; + } + } + + public static class TestNull extends EnumeratedAttribute { + public String[] getValues() { + return null; + } + } + + public static class Factory extends EnumeratedAttribute { + public String[] getValues() { + return new String[] { "one", "two", "three" }; + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/FileListTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/FileListTest.java new file mode 100644 index 00000000..463ba782 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/FileListTest.java @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Some tests for filelist. + */ + +public class FileListTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/filelist.xml"); + } + + @Test + public void testEmptyElementIfIsReference() { + FileList f = new FileList(); + f.setDir(buildRule.getProject().resolveFile(".")); + try { + f.setRefid(new Reference(buildRule.getProject(), "dummyref")); + fail("Can add reference to FileList with directory attribute set."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + f = new FileList(); + f.setFiles("foo.xml,c/d/bar.xml"); + try { + f.setRefid(new Reference(buildRule.getProject(), "dummyref")); + fail("Can add reference to FileList with file attribute set."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + f = new FileList(); + f.setRefid(new Reference(buildRule.getProject(), "dummyref")); + try { + f.setFiles("a/b/foo.java"); + fail("Can set files in FileList that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + try { + f.setDir(buildRule.getProject().resolveFile(".")); + fail("Can set dir in FileList that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + } + + @Test + public void testCircularReferenceCheck() { + FileList f = new FileList(); + buildRule.getProject().addReference("dummy", f); + f.setRefid(new Reference(buildRule.getProject(), "dummy")); + try { + f.getDir(buildRule.getProject()); + fail("Can make FileList a Reference to itself."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + try { + f.getFiles(buildRule.getProject()); + fail("Can make FileList a Reference to itself."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + + // dummy1 --> dummy2 --> dummy3 --> dummy1 + FileList f1 = new FileList(); + buildRule.getProject().addReference("dummy1", f1); + f1.setRefid(new Reference(buildRule.getProject(), "dummy2")); + FileList f2 = new FileList(); + buildRule.getProject().addReference("dummy2", f2); + f2.setRefid(new Reference(buildRule.getProject(), "dummy3")); + FileList f3 = new FileList(); + buildRule.getProject().addReference("dummy3", f3); + f3.setRefid(new Reference(buildRule.getProject(), "dummy1")); + try { + f1.getDir(buildRule.getProject()); + fail("Can make circular reference."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + try { + f1.getFiles(buildRule.getProject()); + fail("Can make circular reference."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + + // dummy1 --> dummy2 --> dummy3 + // (which has the Project's basedir as root). + f1 = new FileList(); + buildRule.getProject().addReference("dummy1", f1); + f1.setRefid(new Reference(buildRule.getProject(), "dummy2")); + f2 = new FileList(); + buildRule.getProject().addReference("dummy2", f2); + f2.setRefid(new Reference(buildRule.getProject(), "dummy3")); + f3 = new FileList(); + buildRule.getProject().addReference("dummy3", f3); + f3.setDir(buildRule.getProject().resolveFile(".")); + File dir = f1.getDir(buildRule.getProject()); + assertEquals("Dir is basedir", dir, buildRule.getProject().getBaseDir()); + } + + @Test + public void testSimple() { + buildRule.executeTarget("simple"); + assertEquals("/abc/a", buildRule.getLog()); + } + + @Test + public void testDouble() { + buildRule.executeTarget("double"); + assertEquals("/abc/a:/abc/b", buildRule.getLog()); + } + + @Test + public void testNested() { + buildRule.executeTarget("nested"); + assertEquals("/abc/a:/abc/b", buildRule.getLog()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java new file mode 100644 index 00000000..8a1c35ac --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + + +/** + * JUnit 3 testcases for org.apache.tools.ant.types.FileSet. + * + * <p>This doesn't actually test much, mainly reference handling. + * + */ + +public class FileSetTest extends AbstractFileSetTest { + + + protected AbstractFileSet getInstance() { + return new FileSet(); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java new file mode 100644 index 00000000..f4df4a38 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java @@ -0,0 +1,239 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.util.Hashtable; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * FilterSet testing + * + */ +public class FilterSetTest { + + static private final int BUF_SIZE = 32768; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/filterset.xml"); + } + + @After + public void tearDown() { + buildRule.executeTarget("cleanup"); + } + + @Test + public void test1() throws IOException { + buildRule.executeTarget("test1"); + assertTrue("Filterset 1 failed", compareFiles("src/etc/testcases/types/gold/filterset1.txt", + "src/etc/testcases/types/dest1.txt")); + } + + @Test + public void test2() throws IOException { + buildRule.executeTarget("test2"); + assertTrue("Filterset 2 failed", compareFiles("src/etc/testcases/types/gold/filterset2.txt", + "src/etc/testcases/types/dest2.txt")); + } + + @Test + public void test3() throws IOException { + buildRule.executeTarget("test3"); + assertTrue("Filterset 3 failed", compareFiles("src/etc/testcases/types/gold/filterset3.txt", + "src/etc/testcases/types/dest3.txt")); + } + + /** + * This will test the recursive FilterSet. Which means that if + * the filter value @test@ contains another filter value, it will + * actually resolve. + */ + @Test + public void testRecursive() { + String result = "it works line"; + String line="@test@ line"; + FilterSet fs = new FilterSet(); + fs.addFilter("test", "@test1@"); + fs.addFilter("test1","@test2@"); + fs.addFilter("test2", "it works"); + fs.setBeginToken("@"); + fs.setEndToken("@"); + assertEquals(result, fs.replaceTokens(line)); + } + + /** + * Test to see what happens when the resolving occurs in an + * infinite loop. + */ + @Test + public void testInfinite() { + String result = "@test@ line testvalue"; + String line = "@test@ line @test3@"; + FilterSet fs = new FilterSet(); + fs.addFilter("test", "@test1@"); + fs.addFilter("test1","@test2@"); + fs.addFilter("test2", "@test@"); + fs.addFilter("test3", "testvalue"); + fs.setBeginToken("@"); + fs.setEndToken("@"); + assertEquals(result, fs.replaceTokens(line)); + } + + /** + * Test to see what happens when the resolving occurs in + * what would be an infinite loop, but with recursion disabled. + */ + @Test + public void testRecursionDisabled() { + String result = "@test1@ line testvalue"; + String line = "@test@ line @test2@"; + FilterSet fs = new FilterSet(); + fs.addFilter("test", "@test1@"); + fs.addFilter("test1","@test@"); + fs.addFilter("test2", "testvalue"); + fs.setBeginToken("@"); + fs.setEndToken("@"); + fs.setRecurse(false); + assertEquals(result, fs.replaceTokens(line)); + } + + @Test + public void testNonInfiniteRecursiveMultipleOnSingleLine() { + FilterSet filters = new FilterSet(); + + filters.setBeginToken("<"); + filters.setEndToken(">"); + + filters.addFilter("ul", "<itemizedlist>"); + filters.addFilter("/ul", "</itemizedList>"); + filters.addFilter("li", "<listitem>"); + filters.addFilter("/li", "</listitem>"); + + String result = "<itemizedlist><listitem>Item 1</listitem> <listitem>Item 2</listitem></itemizedList>"; + String line = "<ul><li>Item 1</li> <li>Item 2</li></ul>"; + + assertEquals(result, filters.replaceTokens(line)); + } + + @Test + public void testNestedFilterSets() { + buildRule.executeTarget("test-nested-filtersets"); + + FilterSet fs = (FilterSet) buildRule.getProject().getReference("1"); + Hashtable filters = fs.getFilterHash(); + assertEquals(1, filters.size()); + assertEquals("value1", filters.get("token1")); + + fs = (FilterSet) buildRule.getProject().getReference("2"); + filters = fs.getFilterHash(); + assertEquals(2, filters.size()); + assertEquals("1111", filters.get("aaaa")); + assertEquals("2222", filters.get("bbbb")); + + fs = (FilterSet) buildRule.getProject().getReference("3"); + filters = fs.getFilterHash(); + assertEquals(1, filters.size()); + assertEquals("value4", filters.get("token4")); + + fs = (FilterSet) buildRule.getProject().getReference("5"); + filters = fs.getFilterHash(); + assertEquals(1, filters.size()); + assertEquals("value1", filters.get("token1")); + } + + @Test + public void testFiltersFileElement() { + buildRule.executeTarget("testFiltersFileElement"); + } + + @Test + public void testFiltersFileAttribute() { + buildRule.executeTarget("testFiltersFileAttribute"); + } + + @Test + public void testMultipleFiltersFiles() { + buildRule.executeTarget("testMultipleFiltersFiles"); + } + + @Test + public void testMissingFiltersFile() { + try { + buildRule.executeTarget("testMissingFiltersFile"); + fail("should fail due to missing filtersfile"); + } catch (BuildException ex) { + //TODO assert exception text + } + } + + @Test + public void testAllowMissingFiltersFile() { + buildRule.executeTarget("testAllowMissingFiltersFile"); + } + + private boolean compareFiles(String name1, String name2) throws IOException { + File file1 = new File(System.getProperty("root"), name1); + File file2 = new File(System.getProperty("root"), name2); + + + if (!file1.exists() || !file2.exists()) { + return false; + } + + if (file1.length() != file2.length()) { + return false; + } + + // byte - byte compare + byte[] buffer1 = new byte[BUF_SIZE]; + byte[] buffer2 = new byte[BUF_SIZE]; + + FileInputStream fis1 = new FileInputStream(file1); + FileInputStream fis2 = new FileInputStream(file2); + int index = 0; + int read = 0; + while ((read = fis1.read(buffer1)) != -1) { + fis2.read(buffer2); + for (int i = 0; i < read; ++i, ++index) { + if (buffer1[i] != buffer2[i]) { + return false; + } + } + } + return true; + + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/FlexIntegerTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/FlexIntegerTest.java new file mode 100644 index 00000000..3e08b2cb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/FlexIntegerTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.BuildException; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class FlexIntegerTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/flexinteger.xml"); + } + + @Test + public void testFlexInteger() { + buildRule.executeTarget("test"); + assertEquals(buildRule.getProject().getProperty("flexint.value1"), "10"); + assertEquals(buildRule.getProject().getProperty("flexint.value2"), "8"); + } + + // This class acts as a custom Ant task also + // and uses these variables/methods in that mode + private Project taskProject; + String propName; + private FlexInteger value; + + + + public void setPropName(String propName) { + this.propName = propName; + } + + public void setValue(FlexInteger value) { + this.value = value; + } + + public void setProject(Project project) { + taskProject = project; + } + + public void execute() { + if (propName == null || value == null) { + throw new BuildException("name and value required"); + } + + taskProject.setNewProperty(propName, value.toString()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/MapperTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/MapperTest.java new file mode 100644 index 00000000..980f5cc2 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/MapperTest.java @@ -0,0 +1,235 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import java.util.Arrays; +import java.util.List; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.ChainedMapper; +import org.apache.tools.ant.util.FileNameMapper; +import org.apache.tools.ant.util.FlatFileNameMapper; +import org.apache.tools.ant.util.GlobPatternMapper; +import org.apache.tools.ant.util.MergingMapper; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * JUnit testcases for org.apache.tools.ant.types.Mapper. + * + */ + +public class MapperTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + private Project project; + + @Before + public void setUp() { + project = new Project(); + project.setBasedir("."); + } + + @Test + public void testEmptyElementIfIsReference() { + Mapper m = new Mapper(project); + m.setFrom("*.java"); + try { + m.setRefid(new Reference(project, "dummyref")); + fail("Can add reference to Mapper with from attribute set"); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + m = new Mapper(project); + m.setRefid(new Reference(project, "dummyref")); + try { + m.setFrom("*.java"); + fail("Can set from in Mapper that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + m = new Mapper(project); + m.setRefid(new Reference(project, "dummyref")); + try { + m.setTo("*.java"); + fail("Can set to in Mapper that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + try { + Mapper.MapperType mt = new Mapper.MapperType(); + mt.setValue("glob"); + m.setType(mt); + fail("Can set type in Mapper that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + } + + @Test + public void testCircularReferenceCheck() { + Mapper m = new Mapper(project); + project.addReference("dummy", m); + m.setRefid(new Reference(project, "dummy")); + try { + m.getImplementation(); + fail("Can make Mapper a Reference to itself."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + + // dummy1 --> dummy2 --> dummy3 --> dummy1 + Mapper m1 = new Mapper(project); + project.addReference("dummy1", m1); + m1.setRefid(new Reference(project, "dummy2")); + Mapper m2 = new Mapper(project); + project.addReference("dummy2", m2); + m2.setRefid(new Reference(project, "dummy3")); + Mapper m3 = new Mapper(project); + project.addReference("dummy3", m3); + m3.setRefid(new Reference(project, "dummy1")); + try { + m1.getImplementation(); + fail("Can make circular reference."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + + // dummy1 --> dummy2 --> dummy3 + // (which holds a glob mapper from "*.java" to "*.class" + m1 = new Mapper(project); + project.addReference("dummy1", m1); + m1.setRefid(new Reference(project, "dummy2")); + m2 = new Mapper(project); + project.addReference("dummy2", m2); + m2.setRefid(new Reference(project, "dummy3")); + m3 = new Mapper(project); + project.addReference("dummy3", m3); + Mapper.MapperType mt = new Mapper.MapperType(); + mt.setValue("glob"); + m3.setType(mt); + m3.setFrom("*.java"); + m3.setTo("*.class"); + FileNameMapper fmm = m1.getImplementation(); + assertTrue("should be glob", fmm instanceof GlobPatternMapper); + String[] result = fmm.mapFileName("a.java"); + assertEquals("a.java should match", 1, result.length); + assertEquals("a.class", result[0]); + } + + @Test + public void testNested() { + Mapper mapper1 = new Mapper(project); + Mapper.MapperType mt = new Mapper.MapperType(); + mt.setValue("glob"); + mapper1.setType(mt); + mapper1.setFrom("from*"); + mapper1.setTo("to*"); + + //mix element types + FileNameMapper mapper2 = new FlatFileNameMapper(); + FileNameMapper mapper3 = new MergingMapper(); + mapper3.setTo("mergefile"); + + Mapper container = new Mapper(project); + container.addConfiguredMapper(mapper1); + container.add(mapper2); + container.add(mapper3); + + FileNameMapper fileNameMapper = container.getImplementation(); + String[] targets = fileNameMapper.mapFileName("fromfilename"); + assertNotNull("no filenames mapped", targets); + assertEquals("wrong number of filenames mapped", 3, targets.length); + List list = Arrays.asList(targets); + assertTrue("cannot find expected target \"tofilename\"", + list.contains("tofilename")); + assertTrue("cannot find expected target \"fromfilename\"", + list.contains("fromfilename")); + assertTrue("cannot find expected target \"mergefile\"", + list.contains("mergefile")); + } + + @Test + public void testChained() { + + // a --> b --> c --- def + // \-- ghi + + FileNameMapper mapperAB = new GlobPatternMapper(); + mapperAB.setFrom("a"); + mapperAB.setTo("b"); + + FileNameMapper mapperBC = new GlobPatternMapper(); + mapperBC.setFrom("b"); + mapperBC.setTo("c"); + + //implicit composite + Mapper mapperCX = new Mapper(project); + + FileNameMapper mapperDEF = new GlobPatternMapper(); + mapperDEF.setFrom("c"); + mapperDEF.setTo("def"); + + FileNameMapper mapperGHI = new GlobPatternMapper(); + mapperGHI.setFrom("c"); + mapperGHI.setTo("ghi"); + + mapperCX.add(mapperDEF); + mapperCX.add(mapperGHI); + + Mapper chained = new Mapper(project); + chained.setClassname(ChainedMapper.class.getName()); + chained.add(mapperAB); + chained.add(mapperBC); + chained.addConfiguredMapper(mapperCX); + + FileNameMapper fileNameMapper = chained.getImplementation(); + String[] targets = fileNameMapper.mapFileName("a"); + assertNotNull("no filenames mapped", targets); + assertEquals("wrong number of filenames mapped", 2, targets.length); + List list = Arrays.asList(targets); + assertTrue("cannot find expected target \"def\"", list.contains("def")); + assertTrue("cannot find expected target \"ghi\"", list.contains("ghi")); + } + + @Test + public void testCopyTaskWithTwoFilesets() { + buildRule.configureProject("src/etc/testcases/types/mapper.xml"); + buildRule.executeTarget("test1"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/PathTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/PathTest.java new file mode 100644 index 00000000..2ad1819c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/PathTest.java @@ -0,0 +1,579 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import java.io.File; +import java.util.Locale; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.condition.Os; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * JUnit testcases for org.apache.tools.ant.types.Path + * + */ + +public class PathTest { + + public static boolean isUnixStyle = File.pathSeparatorChar == ':'; + public static boolean isNetWare = Os.isFamily("netware"); + + private Project project; + + @Before + public void setUp() { + project = new Project(); + project.setBasedir(System.getProperty("root")); + } + + // actually tests constructor as well as setPath + @Test + public void testConstructorUnixStyle() { + Path p = new Path(project, "/a:/b"); + String[] l = p.list(); + assertEquals("two items, Unix style", 2, l.length); + if (isUnixStyle) { + assertEquals("/a", l[0]); + assertEquals("/b", l[1]); + } else if (isNetWare) { + assertEquals("\\a", l[0]); + assertEquals("\\b", l[1]); + } else { + String base = new File(File.separator).getAbsolutePath(); + assertEquals(base + "a", l[0]); + assertEquals(base + "b", l[1]); + } + } + + @Test + public void testRelativePathUnixStyle() { + project.setBasedir(new File(System.getProperty("root"), "src/etc").getAbsolutePath()); + Path p = new Path(project, "..:testcases"); + String[] l = p.list(); + assertEquals("two items, Unix style", 2, l.length); + if (isUnixStyle) { + assertTrue("test resolved relative to src/etc", + l[0].endsWith("/src")); + assertTrue("test resolved relative to src/etc", + l[1].endsWith("/src/etc/testcases")); + } else if (isNetWare) { + assertTrue("test resolved relative to src/etc", + l[0].endsWith("\\src")); + assertTrue("test resolved relative to src/etc", + l[1].endsWith("\\src\\etc\\testcases")); + } else { + assertTrue("test resolved relative to src/etc", + l[0].endsWith("\\src")); + assertTrue("test resolved relative to src/etc", + l[1].endsWith("\\src\\etc\\testcases")); + } + } + + @Test + public void testConstructorWindowsStyle() { + Path p = new Path(project, "\\a;\\b"); + String[] l = p.list(); + assertEquals("two items, DOS style", 2, l.length); + if (isUnixStyle) { + assertEquals("/a", l[0]); + assertEquals("/b", l[1]); + } else if (isNetWare) { + assertEquals("\\a", l[0]); + assertEquals("\\b", l[1]); + } else { + String base = new File(File.separator).getAbsolutePath(); + assertEquals(base + "a", l[0]); + assertEquals(base + "b", l[1]); + } + + p = new Path(project, "c:\\test"); + l = p.list(); + if (isUnixStyle) { + assertEquals("no drives on Unix", 2, l.length); + assertTrue("c resolved relative to project\'s basedir", + l[0].endsWith("/c")); + assertEquals("/test", l[1]); + } else if (isNetWare) { + assertEquals("volumes on NetWare", 1, l.length); + assertEquals("c:\\test", l[0].toLowerCase(Locale.US)); + } else { + assertEquals("drives on DOS", 1, l.length); + assertEquals("c:\\test", l[0].toLowerCase(Locale.US)); + } + + p = new Path(project, "c:\\test;d:\\programs"); + l = p.list(); + if (isUnixStyle) { + assertEquals("no drives on Unix", 4, l.length); + assertTrue("c resolved relative to project\'s basedir", + l[0].endsWith("/c")); + assertEquals("/test", l[1]); + assertTrue("d resolved relative to project\'s basedir", + l[2].endsWith("/d")); + assertEquals("/programs", l[3]); + } else if (isNetWare) { + assertEquals("volumes on NetWare", 2, l.length); + assertEquals("c:\\test", l[0].toLowerCase(Locale.US)); + assertEquals("d:\\programs", l[1].toLowerCase(Locale.US)); + } else { + assertEquals("drives on DOS", 2, l.length); + assertEquals("c:\\test", l[0].toLowerCase(Locale.US)); + assertEquals("d:\\programs", l[1].toLowerCase(Locale.US)); + } + + p = new Path(project, "c:/test"); + l = p.list(); + if (isUnixStyle) { + assertEquals("no drives on Unix", 2, l.length); + assertTrue("c resolved relative to project\'s basedir", + l[0].endsWith("/c")); + assertEquals("/test", l[1]); + } else if (isNetWare) { + assertEquals("volumes on NetWare", 1, l.length); + assertEquals("c:\\test", l[0].toLowerCase(Locale.US)); + } else { + assertEquals("drives on DOS", 1, l.length); + assertEquals("c:\\test", l[0].toLowerCase(Locale.US)); + } + + p = new Path(project, "c:/test;d:/programs"); + l = p.list(); + if (isUnixStyle) { + assertEquals("no drives on Unix", 4, l.length); + assertTrue("c resolved relative to project\'s basedir", + l[0].endsWith("/c")); + assertEquals("/test", l[1]); + assertTrue("d resolved relative to project\'s basedir", + l[2].endsWith("/d")); + assertEquals("/programs", l[3]); + } else if (isNetWare) { + assertEquals("volumes on NetWare", 2, l.length); + assertEquals("c:\\test", l[0].toLowerCase(Locale.US)); + assertEquals("d:\\programs", l[1].toLowerCase(Locale.US)); + } else { + assertEquals("drives on DOS", 2, l.length); + assertEquals("c:\\test", l[0].toLowerCase(Locale.US)); + assertEquals("d:\\programs", l[1].toLowerCase(Locale.US)); + } + } + + @Test + public void testConstructorNetWareStyle() { + // try a netware-volume length path, see how it is handled + Path p = new Path(project, "sys:\\test"); + String[] l = p.list(); + if (isUnixStyle) { + assertEquals("no drives on Unix", 2, l.length); + assertTrue("sys resolved relative to project\'s basedir", + l[0].endsWith("/sys")); + assertEquals("/test", l[1]); + } else if (isNetWare) { + assertEquals("sys:\\test", l[0].toLowerCase(Locale.US)); + assertEquals("volumes on NetWare", 1, l.length); + } else { + assertEquals("no multiple character-length volumes on Windows", 2, l.length); + assertTrue("sys resolved relative to project\'s basedir", + l[0].endsWith("\\sys")); + assertTrue("test resolved relative to project\'s basedir", + l[1].endsWith("\\test")); + } + + // try a multi-part netware-volume length path, see how it is handled + p = new Path(project, "sys:\\test;dev:\\temp"); + l = p.list(); + if (isUnixStyle) { + assertEquals("no drives on Unix", 4, l.length); + assertTrue("sys resolved relative to project\'s basedir", + l[0].endsWith("/sys")); + assertEquals("/test", l[1]); + assertTrue("dev resolved relative to project\'s basedir", + l[2].endsWith("/dev")); + assertEquals("/temp", l[3]); + } else if (isNetWare) { + assertEquals("volumes on NetWare", 2, l.length); + assertEquals("sys:\\test", l[0].toLowerCase(Locale.US)); + assertEquals("dev:\\temp", l[1].toLowerCase(Locale.US)); + } else { + assertEquals("no multiple character-length volumes on Windows", 4, l.length); + assertTrue("sys resolved relative to project\'s basedir", + l[0].endsWith("\\sys")); + assertTrue("test resolved relative to project\'s basedir", + l[1].endsWith("\\test")); + assertTrue("dev resolved relative to project\'s basedir", + l[2].endsWith("\\dev")); + assertTrue("temp resolved relative to project\'s basedir", + l[3].endsWith("\\temp")); + } + + // try a netware-volume length path w/forward slash, see how it is handled + p = new Path(project, "sys:/test"); + l = p.list(); + if (isUnixStyle) { + assertEquals("no drives on Unix", 2, l.length); + assertTrue("sys resolved relative to project\'s basedir", + l[0].endsWith("/sys")); + assertEquals("/test", l[1]); + } else if (isNetWare) { + assertEquals("volumes on NetWare", 1, l.length); + assertEquals("sys:\\test", l[0].toLowerCase(Locale.US)); + } else { + assertEquals("no multiple character-length volumes on Windows", 2, l.length); + assertTrue("sys resolved relative to project\'s basedir", + l[0].endsWith("\\sys")); + assertTrue("test resolved relative to project\'s basedir", + l[1].endsWith("\\test")); + } + + // try a multi-part netware-volume length path w/forward slash, see how it is handled + p = new Path(project, "sys:/test;dev:/temp"); + l = p.list(); + if (isUnixStyle) { + assertEquals("no drives on Unix", 4, l.length); + assertTrue("sys resolved relative to project\'s basedir", + l[0].endsWith("/sys")); + assertEquals("/test", l[1]); + assertTrue("dev resolved relative to project\'s basedir", + l[2].endsWith("/dev")); + assertEquals("/temp", l[3]); + } else if (isNetWare) { + assertEquals("volumes on NetWare", 2, l.length); + assertEquals("sys:\\test", l[0].toLowerCase(Locale.US)); + assertEquals("dev:\\temp", l[1].toLowerCase(Locale.US)); + } else { + assertEquals("no multiple character-length volumes on Windows", 4, l.length); + assertTrue("sys resolved relative to project\'s basedir", + l[0].endsWith("\\sys")); + assertTrue("test resolved relative to project\'s basedir", + l[1].endsWith("\\test")); + assertTrue("dev resolved relative to project\'s basedir", + l[2].endsWith("\\dev")); + assertTrue("temp resolved relative to project\'s basedir", + l[3].endsWith("\\temp")); + } + + // try a multi-part netware-volume length path with UNIX + // separator (this testcase if from an actual bug that was + // found, in AvailableTest, which uses PathTokenizer) + p = new Path(project, + "SYS:\\JAVA/lib/rt.jar:SYS:\\JAVA/lib/classes.zip"); + l = p.list(); + if (isUnixStyle) { + assertEquals("no drives on Unix", 3, l.length); + assertTrue("sys resolved relative to project\'s basedir", + l[0].endsWith("/SYS")); + assertEquals("/JAVA/lib/rt.jar", l[1]); + assertEquals("/JAVA/lib/classes.zip", l[2]); + } else if (isNetWare) { + assertEquals("volumes on NetWare", 2, l.length); + assertEquals("sys:\\java\\lib\\rt.jar", l[0].toLowerCase(Locale.US)); + assertEquals("sys:\\java\\lib\\classes.zip", l[1].toLowerCase(Locale.US)); + } else { + assertEquals("no multiple character-length volumes on Windows", 3, l.length); + assertTrue("sys resolved relative to project\'s basedir", + l[0].endsWith("\\SYS")); + assertTrue("java/lib/rt.jar resolved relative to project\'s basedir", + l[1].endsWith("\\JAVA\\lib\\rt.jar")); + assertTrue("java/lib/classes.zip resolved relative to project\'s basedir", + l[2].endsWith("\\JAVA\\lib\\classes.zip")); + } + } + + @Test + public void testConstructorMixedStyle() { + Path p = new Path(project, "\\a;\\b:/c"); + String[] l = p.list(); + assertEquals("three items, mixed style", 3, l.length); + if (isUnixStyle) { + assertEquals("/a", l[0]); + assertEquals("/b", l[1]); + assertEquals("/c", l[2]); + } else if (isNetWare) { + assertEquals("\\a", l[0]); + assertEquals("\\b", l[1]); + assertEquals("\\c", l[2]); + } else { + String base = new File(File.separator).getAbsolutePath(); + assertEquals(base + "a", l[0]); + assertEquals(base + "b", l[1]); + assertEquals(base + "c", l[2]); + } + } + + @Test + public void testSetLocation() { + Path p = new Path(project); + p.setLocation(new File(File.separatorChar+"a")); + String[] l = p.list(); + if (isUnixStyle) { + assertEquals(1, l.length); + assertEquals("/a", l[0]); + } else if (isNetWare) { + assertEquals(1, l.length); + assertEquals("\\a", l[0]); + } else { + assertEquals(1, l.length); + assertEquals(":\\a", l[0].substring(1)); + } + } + + @Test + public void testAppending() { + Path p = new Path(project, "/a:/b"); + String[] l = p.list(); + assertEquals("2 after construction", 2, l.length); + p.setLocation(new File("/c")); + l = p.list(); + assertEquals("3 after setLocation", 3, l.length); + p.setPath("\\d;\\e"); + l = p.list(); + assertEquals("5 after setPath", 5, l.length); + p.append(new Path(project, "\\f")); + l = p.list(); + assertEquals("6 after append", 6, l.length); + p.createPath().setLocation(new File("/g")); + l = p.list(); + assertEquals("7 after append", 7, l.length); + } + + @Test + public void testEmpyPath() { + Path p = new Path(project, ""); + String[] l = p.list(); + assertEquals("0 after construction", 0, l.length); + p.setPath(""); + l = p.list(); + assertEquals("0 after setPath", 0, l.length); + p.append(new Path(project)); + l = p.list(); + assertEquals("0 after append", 0, l.length); + p.createPath(); + l = p.list(); + assertEquals("0 after append", 0, l.length); + } + + @Test + public void testUnique() { + Path p = new Path(project, "/a:/a"); + String[] l = p.list(); + assertEquals("1 after construction", 1, l.length); + String base = new File(File.separator).getAbsolutePath(); + p.setLocation(new File(base, "a")); + l = p.list(); + assertEquals("1 after setLocation", 1, l.length); + p.setPath("\\a;/a"); + l = p.list(); + assertEquals("1 after setPath", 1, l.length); + p.append(new Path(project, "/a;\\a:\\a")); + l = p.list(); + assertEquals("1 after append", 1, l.length); + p.createPath().setPath("\\a:/a"); + l = p.list(); + assertEquals("1 after append", 1, l.length); + } + + @Test + public void testEmptyElementIfIsReference() { + Path p = new Path(project, "/a:/a"); + try { + p.setRefid(new Reference(project, "dummyref")); + fail("Can add reference to Path with elements from constructor"); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + p = new Path(project); + p.setLocation(new File("/a")); + try { + p.setRefid(new Reference(project, "dummyref")); + fail("Can add reference to Path with elements from setLocation"); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + Path another = new Path(project, "/a:/a"); + project.addReference("dummyref", another); + p = new Path(project); + p.setRefid(new Reference(project, "dummyref")); + try { + p.setLocation(new File("/a")); + fail("Can set location in Path that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + try { + p.setPath("/a;\\a"); + fail("Can set path in Path that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + try { + p.createPath(); + fail("Can create nested Path in Path that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + + try { + p.createPathElement(); + fail("Can create nested PathElement in Path that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + + try { + p.addFileset(new FileSet()); + fail("Can add nested FileSet in Path that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + + try { + p.addFilelist(new FileList()); + fail("Can add nested FileList in Path that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + + try { + p.addDirset(new DirSet()); + fail("Can add nested Dirset in Path that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + } + + @Test + public void testCircularReferenceCheck() { + Path p = new Path(project); + project.addReference("dummy", p); + p.setRefid(new Reference(project, "dummy")); + try { + p.list(); + fail("Can make Path a Reference to itself."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + + // dummy1 --> dummy2 --> dummy3 --> dummy1 + Path p1 = new Path(project); + project.addReference("dummy1", p1); + Path p2 = p1.createPath(); + project.addReference("dummy2", p2); + Path p3 = p2.createPath(); + project.addReference("dummy3", p3); + p3.setRefid(new Reference(project, "dummy1")); + try { + p1.list(); + fail("Can make circular reference."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + + // dummy1 --> dummy2 --> dummy3 (with Path "/a") + p1 = new Path(project); + project.addReference("dummy1", p1); + p2 = p1.createPath(); + project.addReference("dummy2", p2); + p3 = p2.createPath(); + project.addReference("dummy3", p3); + p3.setLocation(new File("/a")); + String[] l = p1.list(); + assertEquals("One element buried deep inside a nested path structure", + 1, l.length); + if (isUnixStyle) { + assertEquals("/a", l[0]); + } else if (isNetWare) { + assertEquals("\\a", l[0]); + } else { + assertEquals(":\\a", l[0].substring(1)); + } + } + + @Test + public void testFileList() { + Path p = new Path(project); + FileList f = new FileList(); + f.setProject(project); + f.setDir(project.resolveFile(".")); + f.setFiles("build.xml"); + p.addFilelist(f); + String[] l = p.list(); + assertEquals(1, l.length); + assertEquals(project.resolveFile("build.xml").getAbsolutePath(), l[0]); + } + + @Test + public void testFileSet() { + Path p = new Path(project); + FileSet f = new FileSet(); + f.setProject(project); + f.setDir(project.resolveFile(".")); + f.setIncludes("build.xml"); + p.addFileset(f); + String[] l = p.list(); + assertEquals(1, l.length); + assertEquals(project.resolveFile("build.xml").getAbsolutePath(), l[0]); + } + + @Test + public void testDirSet() { + Path p = new Path(project); + DirSet d = new DirSet(); + d.setProject(project); + d.setDir(project.resolveFile(".")); + d.setIncludes("build"); + p.addDirset(d); + String[] l = p.list(); + assertEquals(1, l.length); + assertEquals(project.resolveFile("build").getAbsolutePath(), l[0]); + } + + @Test + public void testRecursion() { + Path p = new Path(project); + try { + p.append(p); + assertEquals(0, p.list().length); + } catch (BuildException x) { + String m = x.toString(); + assertTrue(m, m.indexOf("circular") != -1); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java new file mode 100644 index 00000000..065d757d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java @@ -0,0 +1,206 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.junit.Before; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * JUnit 3 testcases for org.apache.tools.ant.types.PatternSet. + * + * <p>This doesn't actually test much, mainly reference handling.</p> + * + */ + +public class PatternSetTest { + + private Project project; + + @Before + public void setUp() { + project = new Project(); + project.setBasedir("."); + } + + @Test + public void testEmptyElementIfIsReference() { + PatternSet p = new PatternSet(); + p.setIncludes("**/*.java"); + try { + p.setRefid(new Reference(project, "dummyref")); + fail("Can add reference to PatternSet with elements from setIncludes"); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + p = new PatternSet(); + p.setRefid(new Reference(project, "dummyref")); + try { + p.setIncludes("**/*.java"); + fail("Can set includes in PatternSet that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + p = new PatternSet(); + p.setRefid(new Reference(project, "dummyref")); + try { + p.setIncludesfile(new File("/a")); + fail("Can set includesfile in PatternSet that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + try { + p.setExcludes("**/*.java"); + fail("Can set excludes in PatternSet that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + try { + p.setExcludesfile(new File("/a")); + fail("Can set excludesfile in PatternSet that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + try { + p.createInclude(); + fail("Can add nested include in PatternSet that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + try { + p.createExclude(); + fail("Can add nested exclude in PatternSet that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + try { + p.createIncludesFile(); + fail("Can add nested includesfile in PatternSet that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + try { + p.createExcludesFile(); + fail("Can add nested excludesfile in PatternSet that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + } + + @Test + public void testCircularReferenceCheck() { + PatternSet p = new PatternSet(); + project.addReference("dummy", p); + p.setRefid(new Reference(project, "dummy")); + try { + p.getIncludePatterns(project); + fail("Can make PatternSet a Reference to itself."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + try { + p.getExcludePatterns(project); + fail("Can make PatternSet a Reference to itself."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + + // dummy1 --> dummy2 --> dummy3 --> dummy1 + PatternSet p1 = new PatternSet(); + project.addReference("dummy1", p1); + p1.setRefid(new Reference(project, "dummy2")); + PatternSet p2 = new PatternSet(); + project.addReference("dummy2", p2); + p2.setRefid(new Reference(project, "dummy3")); + PatternSet p3 = new PatternSet(); + project.addReference("dummy3", p3); + p3.setRefid(new Reference(project, "dummy1")); + try { + p1.getIncludePatterns(project); + fail("Can make circular reference."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + try { + p1.getExcludePatterns(project); + fail("Can make circular reference."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + + // dummy1 --> dummy2 --> dummy3 + // (which holds patterns "include" and "exclude") + p1 = new PatternSet(); + project.addReference("dummy1", p1); + p1.setRefid(new Reference(project, "dummy2")); + p2 = new PatternSet(); + project.addReference("dummy2", p2); + p2.setRefid(new Reference(project, "dummy3")); + p3 = new PatternSet(); + project.addReference("dummy3", p3); + p3.setIncludes("include"); + p3.createExclude().setName("exclude"); + String[] i = p1.getIncludePatterns(project); + assertEquals("One include pattern buried deep inside a nested patternset structure", + 1, i.length); + assertEquals("include", i[0]); + i = p3.getExcludePatterns(project); + assertEquals("One exclude pattern buried deep inside a nested patternset structure", + 1, i.length); + assertEquals("exclude", i[0]); + } + + @Test + public void testNestedPatternset() { + PatternSet p = new PatternSet(); + p.setIncludes("**/*.java"); + + PatternSet nested = new PatternSet(); + nested.setExcludes("**/*.class"); + + p.addConfiguredPatternset(nested); + + String[] excludes = p.getExcludePatterns(project); + String[] includes = p.getIncludePatterns(project); + + assertEquals("Includes","**/*.java", includes[0]); + assertEquals("Excludes","**/*.class", excludes[0]); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/PermissionsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/PermissionsTest.java new file mode 100644 index 00000000..1e43fe1a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/PermissionsTest.java @@ -0,0 +1,158 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import org.apache.tools.ant.ExitException; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.fail; + +/** + * JUnit 3 testcases for org.apache.tools.ant.types.Permissions. + * + */ +public class PermissionsTest { + + Permissions perms; + + @Before + public void setUp() { + perms = new Permissions(); + Permissions.Permission perm = new Permissions.Permission(); + // Grant extra permissions to read and write the user.* properties and read to the + // java.home property + perm.setActions("read, write"); + perm.setName("user.*"); + perm.setClass("java.util.PropertyPermission"); + perms.addConfiguredGrant(perm); + + perm = new Permissions.Permission(); + perm.setActions("read"); + perm.setName("java.home"); + perm.setClass("java.util.PropertyPermission"); + perms.addConfiguredGrant(perm); + + perm = new Permissions.Permission(); + perm.setActions("read"); + perm.setName("file.encoding"); + perm.setClass("java.util.PropertyPermission"); + perms.addConfiguredGrant(perm); + + // Revoke permission to write user.home (granted above via user.*), still able to read though. + // and the default granted permission to read os.name. + perm = new Permissions.Permission(); + perm.setActions("write"); + perm.setName("user.home"); + perm.setClass("java.util.PropertyPermission"); + perms.addConfiguredRevoke(perm); + + perm = new Permissions.Permission(); + perm.setActions("read"); + perm.setName("os.*"); + perm.setClass("java.util.PropertyPermission"); + perms.addConfiguredRevoke(perm); + } + + /** Tests a permission that is granted per default. */ + @Test + public void testDefaultGranted() { + perms.setSecurityManager(); + try { + System.getProperty("line.separator"); + } finally { + perms.restoreSecurityManager(); + } + } + + /** Tests a permission that has been granted later via wildcard. */ + @Test + public void testGranted() { + perms.setSecurityManager(); + try { + String s = System.getProperty("user.name"); + System.setProperty("user.name", s); + } finally { + perms.restoreSecurityManager(); + } + } + + /** Tests a permission that has been granted and revoked later. */ + @Test + public void testGrantedAndRevoked() { + perms.setSecurityManager(); + try { + String s = System.getProperty("user.home"); + System.setProperty("user.home", s); + fail("Could perform an action that should have been forbidden."); + } catch (SecurityException e){ + // Was expected, test passes + } finally { + perms.restoreSecurityManager(); + } + } + + /** Tests a permission that is granted as per default but revoked later via wildcard. */ + @Test + public void testDefaultRevoked() { + perms.setSecurityManager(); + try { + System.getProperty("os.name"); + fail("Could perform an action that should have been forbidden."); + } catch (SecurityException e){ + // Was expected, test passes + } finally { + perms.restoreSecurityManager(); + } + } + /** Tests a permission that has not been granted or revoked. */ + @Test + public void testOther() { + String ls = System.getProperty("line.separator"); + perms.setSecurityManager(); + try { + System.setProperty("line.separator",ls); + fail("Could perform an action that should have been forbidden."); + } catch (SecurityException e){ + //TODO assert exception message + // Was expected, test passes + } finally { + perms.restoreSecurityManager(); + } + } + + /** Tests an exit condition. */ + @Test + public void testExit() { + perms.setSecurityManager(); + try { + System.out.println("If this is the last line on standard out the testExit f.a.i.l.e.d"); + System.exit(3); + fail("Totaly impossible that this fail is ever executed. Please let me know if it is!"); + } catch (ExitException e) { + if (e.getStatus() != 3) { + fail("Received wrong exit status in Exit Exception."); + } + System.out.println("testExit successful."); + } finally { + perms.restoreSecurityManager(); + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/PolyTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/PolyTest.java new file mode 100644 index 00000000..0d5e2ceb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/PolyTest.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +public class PolyTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/poly.xml"); + } + + @Test + public void testFileSet() { + buildRule.executeTarget("fileset"); + AntAssert.assertContains( "types.FileSet", buildRule.getLog()); + } + + @Test + public void testFileSetAntType() { + buildRule.executeTarget("fileset-ant-type"); + AntAssert.assertContains("types.PolyTest$MyFileSet", buildRule.getLog()); + } + + @Test + public void testPath() { + buildRule.executeTarget("path"); + AntAssert.assertContains( "types.Path", buildRule.getLog()); + } + + @Test + public void testPathAntType() { + buildRule.executeTarget("path-ant-type"); + AntAssert.assertContains( "types.PolyTest$MyPath", buildRule.getLog()); + } + + public static class MyFileSet extends FileSet {} + + public static class MyPath extends Path { + public MyPath(Project project) { + super(project); + } + } + + public static class MyTask extends Task { + public void addPath(Path path) { + log("class of path is " + path.getClass()); + } + public void addFileset(FileSet fileset) { + log("class of fileset is " + fileset.getClass()); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java new file mode 100644 index 00000000..f4c2abe0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class RedirectorElementTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/redirector.xml", Project.MSG_VERBOSE); + } + + @Test + public void test1() { + buildRule.executeTarget("test1"); + assertTrue((buildRule.getProject().<Object> getReference("test1") + instanceof RedirectorElement)); + } + + @Test + public void test2() { + try { + buildRule.executeTarget("test2"); + fail("You must not specify more than one attribute when using refid"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test3() { + try { + buildRule.executeTarget("test3"); + fail("You must not specify nested elements when using refid"); + } catch (BuildException ex) { + //TODO assert exception message + } + } + + @Test + public void test4() { + buildRule.executeTarget("test4"); + } + + @Test + public void testLogInputString() { + buildRule.executeTarget("testLogInputString"); + if (buildRule.getLog().indexOf("testLogInputString can-cat") >=0 ) { + AntAssert.assertContains("Using input string", buildRule.getFullLog()); + } + } + + @Test + public void testRefid() { + buildRule.executeTarget("testRefid"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java new file mode 100644 index 00000000..b66335a3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/ResourceOutputTest.java @@ -0,0 +1,160 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import java.io.File; +import java.io.IOException; +import java.net.UnknownServiceException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Zip; +import org.apache.tools.ant.types.resources.ImmutableResourceException; +import org.apache.tools.ant.types.resources.PropertyResource; +import org.apache.tools.ant.types.resources.StringResource; +import org.apache.tools.ant.types.resources.URLResource; +import org.apache.tools.ant.types.resources.ZipResource; +import org.apache.tools.ant.util.FileUtils; +import org.apache.tools.ant.util.ResourceUtils; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class ResourceOutputTest { + + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + private static final File basedir = new File(System.getProperty("root"), + "src/etc/testcases/types/resources"); + + private Project project; + + @Before + public void setUp() { + project = new Project(); + project.init(); + project.setUserProperty("basedir" , basedir.getAbsolutePath()); + } + + @Test + public void testresourceoutput() { + try { + testoutputbe(new Resource("foo")); + fail("should have caught UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + //TODO assert exception message + } + } + + @Test + public void teststringoutput1() { + StringResource r = new StringResource(); + testoutputbe(r); + assertEquals("foo", r.getValue()); + } + + @Test + public void teststringoutput2() throws IOException { + StringResource r = new StringResource("bar"); + try { + testoutput(r); + fail("should have caught ImmutableResourceException"); + } catch (ImmutableResourceException e) { + //TODO assert exception message + } + assertEquals("bar", r.getValue()); + } + + @Test + public void testpropertyoutput1() { + PropertyResource r = new PropertyResource(project, "bar"); + testoutputbe(r); + assertEquals("foo", project.getProperty("bar")); + } + + @Test + public void testpropertyoutput2() throws IOException { + project.setNewProperty("bar", "bar"); + PropertyResource r = new PropertyResource(project, "bar"); + try { + testoutput(r); + fail("should have caught ImmutableResourceException"); + } catch (ImmutableResourceException e) { + //TODO assert exception message + } + assertEquals("bar", project.getProperty("bar")); + } + + @Test + public void testurloutput() throws IOException { + File f = project.resolveFile("testurloutput"); + try { + FILE_UTILS.createNewFile(f); + testoutput(new URLResource(f)); + fail("should have caught UnknownServiceException"); + } catch (UnknownServiceException e) { + //TODO assert exception message + } finally { + if (!f.delete()) { + f.deleteOnExit(); + } + } + } + + @Test + public void testzipentryoutput() { + Zip z = new Zip(); + z.setProject(project); + Zip.WhenEmpty create = new Zip.WhenEmpty(); + create.setValue("create"); + z.setWhenempty(create); + z.setBasedir(basedir); + z.setExcludes("**/*"); + File f = project.resolveFile("foo"); + z.setDestFile(f); + z.execute(); + ZipResource r = new ZipResource(); + r.setZipfile(f); + r.setName("foo"); + try { + testoutputbe(r); + fail("should have caught UnsupportedOperationException"); + } catch (UnsupportedOperationException e) { + //TODO assert exception message + } finally { + if (!f.delete()) { + f.deleteOnExit(); + } + } + } + + private void testoutputbe(Resource dest) { + try { + testoutput(dest); + } catch (IOException e) { + throw new BuildException(e); + } + } + + private void testoutput(Resource dest) throws IOException { + ResourceUtils.copyResource(new StringResource("foo"), dest, null); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java new file mode 100644 index 00000000..b30168aa --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/TarFileSetTest.java @@ -0,0 +1,119 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * JUnit 3 testcases for org.apache.tools.ant.types.TarFileSet. + * + * <p>This doesn't actually test much, mainly reference handling. + * + */ + +public class TarFileSetTest extends AbstractFileSetTest { + + + protected AbstractFileSet getInstance() { + return new TarFileSet(); + } + + @Test + public final void testAttributes() { + TarFileSet f = (TarFileSet)getInstance(); + //check that dir and src are incompatible + f.setSrc(new File("example.tar")); + try { + f.setDir(new File("examples")); + fail("can add dir to " + + f.getDataTypeName() + + " when a src is already present"); + } catch (BuildException be) { + assertEquals("Cannot set both dir and src attributes",be.getMessage()); + } + f = (TarFileSet)getInstance(); + //check that dir and src are incompatible + f.setDir(new File("examples")); + try { + f.setSrc(new File("example.tar")); + fail("can add src to " + + f.getDataTypeName() + + " when a dir is already present"); + } catch (BuildException be) { + assertEquals("Cannot set both dir and src attributes",be.getMessage()); + } + //check that fullpath and prefix are incompatible + f = (TarFileSet)getInstance(); + f.setSrc(new File("example.tar")); + f.setPrefix("/examples"); + try { + f.setFullpath("/doc/manual/index.html"); + fail("Can add fullpath to " + + f.getDataTypeName() + + " when a prefix is already present"); + } catch (BuildException be) { + assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); + } + f = (TarFileSet)getInstance(); + f.setSrc(new File("example.tar")); + f.setFullpath("/doc/manual/index.html"); + try { + f.setPrefix("/examples"); + fail("Can add prefix to " + + f.getDataTypeName() + + " when a fullpath is already present"); + } catch (BuildException be) { + assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); + } + // check that reference tarfilesets cannot have specific attributes + f = (TarFileSet)getInstance(); + f.setRefid(new Reference(getProject(), "test")); + try { + f.setSrc(new File("example.tar")); + fail("Can add src to " + + f.getDataTypeName() + + " when a refid is already present"); + } catch (BuildException be) { + assertEquals("You must not specify more than one " + + "attribute when using refid", be.getMessage()); + } + // check that a reference tarfileset gets the same attributes as the original + f = (TarFileSet)getInstance(); + f.setSrc(new File("example.tar")); + f.setPrefix("/examples"); + f.setFileMode("600"); + f.setDirMode("530"); + getProject().addReference("test",f); + TarFileSet zid=(TarFileSet)getInstance(); + zid.setRefid(new Reference(getProject(), "test")); + assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject()))); + assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject()))); + assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject())); + assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject())); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/XMLCatalogBuildFileTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/XMLCatalogBuildFileTest.java new file mode 100644 index 00000000..96c0c5d2 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/XMLCatalogBuildFileTest.java @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * testcases for org.apache.tools.ant.types.XMLCatalog + * + * @see org.apache.tools.ant.types.XMLCatalogTest + * + */ +public class XMLCatalogBuildFileTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + + + // + // Ensure that an external entity resolves as expected with NO + // XMLCatalog involvement: + // + // Transform an XML file that refers to the entity into a text + // file, stuff result into property: val1 + // + @Test + public void testEntityNoCatalog() { + buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml"); + buildRule.executeTarget("testentitynocatalog"); + assertEquals("A stitch in time saves nine", buildRule.getProject().getProperty("val1")); + } + + // + // Ensure that an external entity resolves as expected Using an + // XMLCatalog: + // + // Transform an XML file that refers to the entity into a text + // file, entity is listed in the XMLCatalog pointing to a + // different file. Stuff result into property: val2 + // + @Test + public void testEntityWithCatalog() { + buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml"); + buildRule.executeTarget("testentitywithcatalog"); + assertEquals("No news is good news", buildRule.getProject().getProperty("val2")); + } + + // + // Ensure that an external entity resolves as expected with NO + // XMLCatalog involvement: + // + // Transform an XML file that contains a reference to a _second_ XML file + // via the document() function. The _second_ XML file refers to an entity. + // Stuff result into the property: val3 + // + @Test + public void testDocumentNoCatalog() { + buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml"); + buildRule.executeTarget("testdocumentnocatalog"); + assertEquals("A stitch in time saves nine", buildRule.getProject().getProperty("val3")); + } + + // + // Ensure that an external entity resolves as expected Using an + // XMLCatalog: + // + // Transform an XML file that contains a reference to a _second_ XML file + // via the document() function. The _second_ XML file refers to an entity. + // The entity is listed in the XMLCatalog pointing to a different file. + // Stuff result into the property: val4 + @Test + public void testDocumentWithCatalog() { + buildRule.configureProject("src/etc/testcases/types/xmlcatalog.xml"); + buildRule.executeTarget("testdocumentwithcatalog"); + assertEquals("No news is good news", buildRule.getProject().getProperty("val4")); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java new file mode 100644 index 00000000..c1adc30d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java @@ -0,0 +1,392 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import java.io.File; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; + +import javax.xml.transform.Source; +import javax.xml.transform.TransformerException; +import javax.xml.transform.sax.SAXSource; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.util.JAXPUtils; +import org.junit.Before; +import org.junit.Test; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assert.assertNotNull; + +/** + * JUnit testcases for org.apache.tools.ant.types.XMLCatalog + * + */ +public class XMLCatalogTest { + + private Project project; + private XMLCatalog catalog; + + private XMLCatalog newCatalog() { + XMLCatalog cat = new XMLCatalog(); + cat.setProject(project); + return cat; + } + + private static String toURLString(File file) throws MalformedURLException { + return JAXPUtils.getSystemId(file); + } + + @Before + public void setUp() { + project = new Project(); + project.setBasedir(System.getProperty("root")); + + // This causes XMLCatalog to print out detailed logging + // messages for debugging + // + // DefaultLogger logger = new DefaultLogger(); + // logger.setMessageOutputLevel(Project.MSG_DEBUG); + // logger.setOutputPrintStream(System.out); + // logger.setErrorPrintStream(System.err); + // project.addBuildListener(logger); + + catalog = newCatalog(); + } + + @Test + public void testEmptyCatalog() { + try { + InputSource result = catalog.resolveEntity("PUBLIC ID ONE", + "i/dont/exist.dtd"); + assertNull("Empty catalog should return null", result); + } catch (Exception e) { + fail("resolveEntity() failed!" + e.toString()); + } + + try { + Source result = catalog.resolve("i/dont/exist.dtd", null); + String expected = toURLString(new File(project.getBaseDir() + + "/i/dont/exist.dtd")); + String resultStr = + fileURLPartWithoutLeadingSlashes((SAXSource)result); + assertTrue("Empty catalog should return input with a system ID like " + + expected + " but was " + resultStr, + expected.endsWith(resultStr)); + } catch (Exception e) { + fail("resolve() failed!" + e.toString()); + } + } + + private static String fileURLPartWithoutLeadingSlashes(SAXSource result) + throws MalformedURLException { + // + // These shenanigans are necessary b/c Norm Walsh's resolver + // has a different idea of how file URLs are created on windoze + // ie file://c:/foo instead of file:///c:/foo + // + String resultStr = + new URL(result.getInputSource().getSystemId()).getFile(); + // on Sun's Java6 this returns an unexpected number of four + // leading slashes, at least on Linux - strip all of them + while (resultStr.startsWith("/")) { + resultStr = resultStr.substring(1); + } + return resultStr; + } + + @Test + public void testNonExistentEntry() throws IOException, SAXException, TransformerException { + + ResourceLocation dtd = new ResourceLocation(); + dtd.setPublicId("PUBLIC ID ONE"); + dtd.setLocation("i/dont/exist.dtd"); + + InputSource isResult = catalog.resolveEntity("PUBLIC ID ONE", + "i/dont/exist.dtd"); + assertNull("Nonexistent Catalog entry should not be returned", isResult); + + Source result = catalog.resolve("i/dont/exist.dtd", null); + String expected = toURLString(new File(project.getBaseDir().toURL() + + "/i/dont/exist.dtd")); + String resultStr = + fileURLPartWithoutLeadingSlashes((SAXSource)result); + assertTrue("Nonexistent Catalog entry return input with a system ID like " + + expected + " but was " + resultStr, + expected.endsWith(resultStr)); + } + + @Test + public void testEmptyElementIfIsReference() { + ResourceLocation dtd = new ResourceLocation(); + dtd.setPublicId("PUBLIC ID ONE"); + dtd.setLocation("i/dont/exist.dtd"); + catalog.addDTD(dtd); + project.addReference("catalog", catalog); + + try { + catalog.setRefid(new Reference(project, "dummyref")); + fail("Can add reference to nonexistent XMLCatalog"); + } catch (BuildException be) { + assertEquals("You must not specify more than one " + + "attribute when using refid", be.getMessage()); + } + + XMLCatalog catalog2 = newCatalog(); + catalog2.setRefid(new Reference(project, "catalog")); + + try { + catalog2.addConfiguredXMLCatalog(catalog); + fail("Can add nested XMLCatalog to XMLCatalog that is a reference"); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + } + + @Test + public void testCircularReferenceCheck() throws IOException, SAXException { + + // catalog <--> catalog + project.addReference("catalog", catalog); + catalog.setRefid(new Reference(project, "catalog")); + + try { + InputSource result = catalog.resolveEntity("PUBLIC ID ONE", + "i/dont/exist.dtd"); + fail("Can make XMLCatalog a Reference to itself."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } catch (Exception e) { + fail("resolveEntity() failed!" + e.toString()); + } + + // catalog1 --> catalog2 --> catalog3 --> catalog1 + XMLCatalog catalog1 = newCatalog(); + project.addReference("catalog1", catalog1); + XMLCatalog catalog2 = newCatalog(); + project.addReference("catalog2", catalog2); + XMLCatalog catalog3 = newCatalog(); + project.addReference("catalog3", catalog3); + + catalog3.setRefid(new Reference(project, "catalog1")); + catalog2.setRefid(new Reference(project, "catalog3")); + catalog1.setRefid(new Reference(project, "catalog2")); + + try { + catalog1.resolveEntity("PUBLIC ID ONE", + "i/dont/exist.dtd"); + fail("Can make circular reference"); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + } + // inspired by Bugzilla Report 23913 + // a problem used to happen under Windows when the location of the DTD was given as an absolute path + // possibly with a mixture of file separators + @Test + public void testAbsolutePath() throws IOException, SAXException { + ResourceLocation dtd = new ResourceLocation(); + dtd.setPublicId("-//stevo//DTD doc 1.0//EN"); + + String sysid = System.getProperty("root") + File.separator + "src/etc/testcases/taskdefs/optional/xml/doc.dtd"; + dtd.setLocation(sysid); + catalog.addDTD(dtd); + File dtdFile = project.resolveFile(sysid); + + InputSource result = catalog.resolveEntity("-//stevo//DTD doc 1.0//EN", + "nap:chemical+brothers"); + assertNotNull(result); + assertEquals(toURLString(dtdFile), + result.getSystemId()); + + + } + + @Test + public void testSimpleEntry() throws IOException, SAXException { + + ResourceLocation dtd = new ResourceLocation(); + dtd.setPublicId("-//stevo//DTD doc 1.0//EN"); + String sysid = "src/etc/testcases/taskdefs/optional/xml/doc.dtd"; + dtd.setLocation(sysid); + catalog.addDTD(dtd); + File dtdFile = project.resolveFile(sysid); + + InputSource result = catalog.resolveEntity("-//stevo//DTD doc 1.0//EN", + "nap:chemical+brothers"); + assertNotNull(result); + assertEquals(toURLString(dtdFile), + result.getSystemId()); + + } + + @Test + public void testEntryReference() throws IOException, SAXException, TransformerException { + + String publicId = "-//stevo//DTD doc 1.0//EN"; + String sysid = "src/etc/testcases/taskdefs/optional/xml/doc.dtd"; + + // catalog2 --> catalog1 --> catalog + ResourceLocation dtd = new ResourceLocation(); + dtd.setPublicId(publicId); + dtd.setLocation(sysid); + catalog.addDTD(dtd); + File dtdFile = project.resolveFile(sysid); + + String uri = "http://foo.com/bar/blah.xml"; + String uriLoc = "src/etc/testcases/taskdefs/optional/xml/about.xml"; + + ResourceLocation entity = new ResourceLocation(); + entity.setPublicId(uri); + entity.setLocation(uriLoc); + catalog.addEntity(entity); + File xmlFile = project.resolveFile(uriLoc); + + project.addReference("catalog", catalog); + + XMLCatalog catalog1 = newCatalog(); + project.addReference("catalog1", catalog1); + XMLCatalog catalog2 = newCatalog(); + project.addReference("catalog2", catalog1); + + catalog1.setRefid(new Reference(project, "catalog")); + catalog2.setRefid(new Reference(project, "catalog1")); + + InputSource isResult = catalog2.resolveEntity(publicId, + "nap:chemical+brothers"); + + assertNotNull(isResult); + assertEquals(toURLString(dtdFile), + isResult.getSystemId()); + + + Source result = catalog.resolve(uri, null); + assertNotNull(result); + assertEquals(toURLString(xmlFile), + result.getSystemId()); + } + + @Test + public void testNestedCatalog() throws IOException, SAXException, TransformerException { + + String publicId = "-//stevo//DTD doc 1.0//EN"; + String dtdLoc = "src/etc/testcases/taskdefs/optional/xml/doc.dtd"; + + ResourceLocation dtd = new ResourceLocation(); + dtd.setPublicId(publicId); + dtd.setLocation(dtdLoc); + catalog.addDTD(dtd); + File dtdFile = project.resolveFile(dtdLoc); + + String uri = "http://foo.com/bar/blah.xml"; + String uriLoc = "src/etc/testcases/taskdefs/optional/xml/about.xml"; + + ResourceLocation entity = new ResourceLocation(); + entity.setPublicId(uri); + entity.setLocation(uriLoc); + catalog.addEntity(entity); + File xmlFile = project.resolveFile(uriLoc); + + XMLCatalog catalog1 = newCatalog(); + catalog1.addConfiguredXMLCatalog(catalog); + + InputSource isResult = catalog1.resolveEntity(publicId, + "nap:chemical+brothers"); + assertNotNull(isResult); + assertEquals(toURLString(dtdFile), + isResult.getSystemId()); + + Source result = catalog.resolve(uri, null); + assertNotNull(result); + assertEquals(toURLString(xmlFile), + result.getSystemId()); + + } + + @Test + public void testResolverBase() throws MalformedURLException, TransformerException { + + String uri = "http://foo.com/bar/blah.xml"; + String uriLoc = "etc/testcases/taskdefs/optional/xml/about.xml"; + String base = toURLString(project.getBaseDir()) + "/src/"; + + ResourceLocation entity = new ResourceLocation(); + entity.setPublicId(uri); + entity.setLocation(uriLoc); + catalog.addEntity(entity); + File xmlFile = project.resolveFile("src/" + uriLoc); + + Source result = catalog.resolve(uri, base); + assertNotNull(result); + assertEquals(toURLString(xmlFile), + result.getSystemId()); + + } + + @Test + public void testClasspath() throws IOException, TransformerException, SAXException { + + + String publicId = "-//stevo//DTD doc 1.0//EN"; + String dtdLoc = "testcases/taskdefs/optional/xml/doc.dtd"; + String path1 = project.getBaseDir().toString() + "/src/etc"; + + ResourceLocation dtd = new ResourceLocation(); + dtd.setPublicId(publicId); + dtd.setLocation(dtdLoc); + catalog.addDTD(dtd); + File dtdFile = project.resolveFile("src/etc/" + dtdLoc); + + String uri = "http://foo.com/bar/blah.xml"; + String uriLoc = "etc/testcases/taskdefs/optional/xml/about.xml"; + String path2 = project.getBaseDir().toString() + "/src"; + + ResourceLocation entity = new ResourceLocation(); + entity.setPublicId(uri); + entity.setLocation(uriLoc); + catalog.addEntity(entity); + File xmlFile = project.resolveFile("src/" + uriLoc); + + Path aPath = new Path(project, path1); + aPath.append(new Path(project, path2)); + catalog.setClasspath(aPath); + + InputSource isResult = catalog.resolveEntity(publicId, + "nap:chemical+brothers"); + assertNotNull(isResult); + String resultStr1 = new URL(isResult.getSystemId()).getFile(); + assertTrue(toURLString(dtdFile).endsWith(resultStr1)); + + Source result = catalog.resolve(uri, null); + assertNotNull(result); + String resultStr = new URL(result.getSystemId()).getFile(); + assertTrue(toURLString(xmlFile).endsWith(resultStr)); + + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java new file mode 100644 index 00000000..e7b14c19 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/ZipFileSetTest.java @@ -0,0 +1,118 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * JUnit 3 testcases for org.apache.tools.ant.types.ZipFileSet. + * + * <p>This doesn't actually test much, mainly reference handling. + * + */ + +public class ZipFileSetTest extends AbstractFileSetTest { + + protected AbstractFileSet getInstance() { + return new ZipFileSet(); + } + + @Test + public final void testAttributes() { + ZipFileSet f = (ZipFileSet)getInstance(); + //check that dir and src are incompatible + f.setSrc(new File("example.zip")); + try { + f.setDir(new File("examples")); + fail("can add dir to " + + f.getDataTypeName() + + " when a src is already present"); + } catch (BuildException be) { + assertEquals("Cannot set both dir and src attributes",be.getMessage()); + } + f = (ZipFileSet)getInstance(); + //check that dir and src are incompatible + f.setDir(new File("examples")); + try { + f.setSrc(new File("example.zip")); + fail("can add src to " + + f.getDataTypeName() + + " when a dir is already present"); + } catch (BuildException be) { + assertEquals("Cannot set both dir and src attributes",be.getMessage()); + } + //check that fullpath and prefix are incompatible + f = (ZipFileSet)getInstance(); + f.setSrc(new File("example.zip")); + f.setPrefix("/examples"); + try { + f.setFullpath("/doc/manual/index.html"); + fail("Can add fullpath to " + + f.getDataTypeName() + + " when a prefix is already present"); + } catch (BuildException be) { + assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); + } + f = (ZipFileSet)getInstance(); + f.setSrc(new File("example.zip")); + f.setFullpath("/doc/manual/index.html"); + try { + f.setPrefix("/examples"); + fail("Can add prefix to " + + f.getDataTypeName() + + " when a fullpath is already present"); + } catch (BuildException be) { + assertEquals("Cannot set both fullpath and prefix attributes", be.getMessage()); + } + // check that reference zipfilesets cannot have specific attributes + f = (ZipFileSet)getInstance(); + f.setRefid(new Reference(getProject(), "test")); + try { + f.setSrc(new File("example.zip")); + fail("Can add src to " + + f.getDataTypeName() + + " when a refid is already present"); + } catch (BuildException be) { + assertEquals("You must not specify more than one " + + "attribute when using refid", be.getMessage()); + } + // check that a reference zipfileset gets the same attributes as the original + f = (ZipFileSet)getInstance(); + f.setSrc(new File("example.zip")); + f.setPrefix("/examples"); + f.setFileMode("600"); + f.setDirMode("530"); + getProject().addReference("test",f); + ZipFileSet zid=(ZipFileSet)getInstance(); + zid.setRefid(new Reference(getProject(), "test")); + assertTrue("src attribute copied by copy constructor",zid.getSrc(getProject()).equals(f.getSrc(getProject()))); + assertTrue("prefix attribute copied by copy constructor",f.getPrefix(getProject()).equals(zid.getPrefix(getProject()))); + assertTrue("file mode attribute copied by copy constructor",f.getFileMode(getProject())==zid.getFileMode(getProject())); + assertTrue("dir mode attribute copied by copy constructor",f.getDirMode(getProject())==zid.getDirMode(getProject())); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/mappers/GlobMapperTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/mappers/GlobMapperTest.java new file mode 100644 index 00000000..310fb5e5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/mappers/GlobMapperTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.mappers; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcase for the <globmapper> mapper. + * + */ +public class GlobMapperTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/mappers/globmapper.xml"); + } + + @Test + public void testIgnoreCase() { + buildRule.executeTarget("ignore.case"); + } + public void testHandleDirSep() { + buildRule.executeTarget("handle.dirsep"); + } +} + + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java new file mode 100644 index 00000000..43a7b296 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/mappers/MapperResult.java @@ -0,0 +1,103 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.mappers; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.Mapper; +import org.apache.tools.ant.util.FileNameMapper; + +/** + * This is a test task to show the result of a mapper + * on a specific input. + * (Test is not in the name of the class, to make sure that + * it is not treated as a unit test. + */ + +public class MapperResult extends Task { + + private String failMessage = ""; + private String input; + private String output; + private FileNameMapper fileNameMapper; + + /** + * The output on an empty string array + */ + private static final String NULL_MAPPER_RESULT = "<NULL>"; + + public void setFailMessage(String failMessage) { + this.failMessage = failMessage; + } + + public void setInput(String input) { + this.input = input; + } + + public void setOutput(String output) { + this.output = output; + } + + public void addConfiguredMapper(Mapper mapper) { + add(mapper.getImplementation()); + } + + public void add(FileNameMapper fileNameMapper) { + if (this.fileNameMapper != null) { + throw new BuildException("Only one mapper type nested element allowed"); + } + this.fileNameMapper = fileNameMapper; + } + + public void execute() { + if (input == null) { + throw new BuildException("Missing attribute 'input'"); + } + if (output == null) { + throw new BuildException("Missing attribute 'output'"); + } + if (fileNameMapper == null) { + throw new BuildException("Missing a nested file name mapper type element"); + } + String[] result = fileNameMapper.mapFileName(input); + String flattened; + if (result == null) { + flattened = NULL_MAPPER_RESULT; + } else { + StringBuffer b = new StringBuffer(); + for (int i = 0; i < result.length; ++i) { + if (i != 0) { + b.append("|"); + } + b.append(result[i]); + } + flattened = b.toString(); + } + if (!flattened.equals(output)) { + throw new BuildException( + failMessage + + " " + + "got " + + flattened + + " " + + "expected " + + output); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/mappers/RegexpPatternMapperTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/mappers/RegexpPatternMapperTest.java new file mode 100644 index 00000000..d01593b4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/mappers/RegexpPatternMapperTest.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.mappers; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcase for the <regexpmapper> mapper. + * + */ +public class RegexpPatternMapperTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/mappers/regexpmapper.xml"); + } + + @Test + public void testIgnoreCase() { + buildRule.executeTarget("ignore.case"); + } + + @Test + public void testHandleDirSep() { + buildRule.executeTarget("handle.dirsep"); + } +} + + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/optional/ScriptMapperTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/optional/ScriptMapperTest.java new file mode 100644 index 00000000..bf727db9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/optional/ScriptMapperTest.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.optional; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Test our script mapping + */ +public class ScriptMapperTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/mappers/scriptmapper.xml"); + } + + @Test + public void testClear() { + buildRule.executeTarget("testClear"); + } + + @Test + public void testSetMultiple() { + buildRule.executeTarget("testSetMultiple"); + } + + @Test + public void testPassthrough() { + buildRule.executeTarget("testPassthrough"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java new file mode 100644 index 00000000..304d6d09 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/optional/ScriptSelectorTest.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.optional; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.apache.tools.ant.AntAssert.assertContains; +import static org.junit.Assert.fail; + +/** + * Test that scripting selection works. Needs scripting support to work + */ +public class ScriptSelectorTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/selectors/scriptselector.xml"); + } + + @Test + public void testNolanguage() { + try { + buildRule.executeTarget("testNolanguage"); + fail("Absence of language attribute not detected"); + } catch(BuildException ex) { + assertContains("script language must be specified", ex.getMessage()); + + } + } + + @Test + public void testSelectionSetByDefault() { + buildRule.executeTarget("testSelectionSetByDefault"); + } + + @Test + public void testSelectionSetWorks() { + buildRule.executeTarget("testSelectionSetWorks"); + } + + @Test + public void testSelectionClearWorks() { + buildRule.executeTarget("testSelectionClearWorks"); + } + + @Test + public void testFilenameAttribute() { + buildRule.executeTarget("testFilenameAttribute"); + } + + @Test + public void testFileAttribute() { + buildRule.executeTarget("testFileAttribute"); + } + + @Test + public void testBasedirAttribute() { + buildRule.executeTarget("testBasedirAttribute"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java new file mode 100644 index 00000000..392667cb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/optional/depend/ClassFileSetTest.java @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.optional.depend; + +import java.io.File; +import java.util.Hashtable; + +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.DirectoryScanner; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.FileSet; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Testcase for the Classfileset optional type. + * + */ +public class ClassFileSetTest { + public static final String RESULT_FILESET = "result"; + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + // share the setup for testing the depend task + buildRule.configureProject("src/etc/testcases/taskdefs/optional/depend/depend.xml"); + } + + /** + * Test basic classfileset + */ + @Test + public void testBasicSet() { + Project p = buildRule.getProject(); + buildRule.executeTarget("testbasicset"); + FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET); + DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p); + String[] scannedFiles = scanner.getIncludedFiles(); + Hashtable files = new Hashtable(); + for (int i = 0; i < scannedFiles.length; ++i) { + files.put(scannedFiles[i], scannedFiles[i]); + } + assertEquals("Classfileset did not pick up expected number of " + + "class files", 4, files.size()); + assertTrue("Result did not contain A.class", + files.containsKey("A.class")); + assertTrue("Result did not contain B.class", + files.containsKey("B.class")); + assertTrue("Result did not contain C.class", + files.containsKey("C.class")); + assertTrue("Result did not contain D.class", + files.containsKey("D.class")); + } + + /** + * Test small classfileset + */ + @Test + public void testSmallSet() { + Project p = buildRule.getProject(); + buildRule.executeTarget("testsmallset"); + FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET); + DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p); + String[] scannedFiles = scanner.getIncludedFiles(); + Hashtable files = new Hashtable(); + for (int i = 0; i < scannedFiles.length; ++i) { + files.put(scannedFiles[i], scannedFiles[i]); + } + assertEquals("Classfileset did not pick up expected number of " + + "class files", 2, files.size()); + assertTrue("Result did not contain B.class", + files.containsKey("B.class")); + assertTrue("Result did not contain C.class", + files.containsKey("C.class")); + } + + /** + * Test combo classfileset + */ + @Test + public void testComboSet() { + Project p = buildRule.getProject(); + buildRule.executeTarget("testcomboset"); + FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET); + DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p); + String[] scannedFiles = scanner.getIncludedFiles(); + Hashtable files = new Hashtable(); + for (int i = 0; i < scannedFiles.length; ++i) { + files.put(scannedFiles[i], scannedFiles[i]); + } + assertEquals("Classfileset did not pick up expected number of " + + "class files", 1, files.size()); + assertTrue("Result did not contain C.class", + files.containsKey("C.class")); + } + + /** + * Test that you can pass a classfileset by reference to a fileset. + */ + @Test + public void testByReference() { + buildRule.executeTarget("testbyreference"); + } + + /** + * Test that classes included in a method "System.out.println(MyClass.class)" are included. + */ + @Test + public void testMethodParam() { + Project p = buildRule.getProject(); + buildRule.executeTarget("testmethodparam"); + FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET); + DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p); + String[] scannedFiles = scanner.getIncludedFiles(); + Hashtable files = new Hashtable(); + for (int i = 0; i < scannedFiles.length; ++i) { + files.put(scannedFiles[i], scannedFiles[i]); + } + assertEquals("Classfileset did not pick up expected number of " + + "class files", 5, files.size()); + assertTrue("Result did not contain A.class", + files.containsKey("A.class")); + assertTrue("Result did not contain B.class", + files.containsKey("B.class")); + assertTrue("Result did not contain C.class", + files.containsKey("C.class")); + assertTrue("Result did not contain D.class", + files.containsKey("D.class")); + assertTrue("Result did not contain E.class", + files.containsKey("E.class")); + } + + /** + * Test that classes included in a method "System.out.println(Outer.Inner.class)" are included. + */ + @Test + public void testMethodParamInner() { + Project p = buildRule.getProject(); + buildRule.executeTarget("testmethodparaminner"); + FileSet resultFileSet = (FileSet)p.getReference(RESULT_FILESET); + DirectoryScanner scanner = resultFileSet.getDirectoryScanner(p); + String[] scannedFiles = scanner.getIncludedFiles(); + Hashtable files = new Hashtable(); + for (int i = 0; i < scannedFiles.length; ++i) { + files.put(scannedFiles[i], scannedFiles[i]); + } + assertEquals("Classfileset did not pick up expected number of " + + "class files", 4, files.size()); + assertTrue("Result did not contain test" + File.separator + "Outer$Inner.class", + files.containsKey("test" + File.separator + "Outer$Inner.class")); + assertTrue("Result did not contain test" + File.separator + "Outer.class", + files.containsKey("test" + File.separator + "Outer.class")); + assertTrue("Result did not contain test" + File.separator + "ContainsOnlyInner.class", + files.containsKey("test" + File.separator + "ContainsOnlyInner.class")); + assertTrue("Result did not contain test" + File.separator + "ContainsOnlyInner.class", + files.containsKey("test" + File.separator + "MethodParam.class")); + } + + @Test + public void testResourceCollection() { + buildRule.executeTarget("testresourcecollection"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java new file mode 100644 index 00000000..71efc656 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.resources; + +import java.io.File; + +import org.apache.tools.ant.Project; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Test Java API of {@link FileResource}. + */ +public class FileResourceTest { + + private File root; + + @Before + public void setUp() { + root = new File(System.getProperty("root")); + } + + @Test + public void testAttributes() { + FileResource f = new FileResource(); + f.setBaseDir(root); + f.setName("foo"); + assertEquals(new File(root, "foo"), f.getFile()); + assertEquals(root, f.getBaseDir()); + assertEquals("foo", f.getName()); + } + + @Test + public void testNonImmediateBasedir() { + FileResource f = new FileResource(); + f.setBaseDir(root); + f.setName("foo/bar"); + assertEquals(new File(root, "foo/bar"), f.getFile()); + assertEquals(root, f.getBaseDir()); + assertEquals("foo/bar", f.getName().replace(File.separatorChar, '/')); + } + + @Test + public void testFile() { + FileResource f = new FileResource(new File(root, "foo")); + assertEquals(new File(root, "foo"), f.getFile()); + assertEquals(root, f.getBaseDir()); + assertEquals("foo", f.getName()); + } + + @Test + public void testBasedirAndName() { + FileResource f = new FileResource(root, "foo"); + assertEquals(new File(root, "foo"), f.getFile()); + assertEquals(root, f.getBaseDir()); + assertEquals("foo", f.getName()); + } + + @Test + public void testNonImmediateBasedirAndName() { + FileResource f = new FileResource(root, "foo/bar"); + assertEquals(new File(root, "foo/bar"), f.getFile()); + assertEquals(root, f.getBaseDir()); + assertEquals("foo/bar", f.getName().replace(File.separatorChar, '/')); + } + + @Test + public void testProjectAndFilename() { + Project p = new Project(); + p.setBaseDir(root); + FileResource f = new FileResource(p, "foo"); + assertEquals(new File(root, "foo"), f.getFile()); + assertEquals(root, f.getBaseDir()); + assertEquals("foo", f.getName()); + } + + @Test + public void testRelativeFactoryResource() { + FileResource f = new FileResource(root, "foo"); + FileResource relative = f.getResource("bar").as(FileResource.class); + assertEquals(new File(root, "foo/bar"), relative.getFile()); + assertEquals("foo/bar", relative.getName().replace(File.separatorChar, '/')); + assertEquals(root, relative.getBaseDir()); + } + + @Test + public void testAbsoluteFactoryResource() { + FileResource f = new FileResource(new File(root, "foo/a")); + assertEquals(new File(root, "foo"), f.getBaseDir()); + File bar = new File(root, "bar"); + FileResource fromFactory = f.getResource(bar.getAbsolutePath()).as(FileResource.class); + assertEquals(bar, fromFactory.getFile()); + assertEquals(root, fromFactory.getBaseDir()); + } + + @Test + public void testParentSiblingFactoryResource() { + FileResource f = new FileResource(new File(root, "foo/a")); + assertEquals(new File(root, "foo"), f.getBaseDir()); + FileResource parentSibling = f.getResource("../../bar").as(FileResource.class); + assertEquals(root, parentSibling.getBaseDir()); + assertEquals("bar", parentSibling.getName()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java new file mode 100644 index 00000000..a67db39b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/JavaResourceTest.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.resources; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; + +public class JavaResourceTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/resources/javaresource.xml"); + } + + @Test + public void testLoadManifest() { + buildRule.executeTarget("loadManifest"); + assertNotNull(buildRule.getProject().getProperty("manifest")); + + // this actually relies on the first manifest being found on + // the classpath (probably rt.jar's) being valid + assertTrue(buildRule.getProject().getProperty("manifest") + .startsWith("Manifest-Version:")); + } + + @Test + public void testIsURLProvider() { + JavaResource r = new JavaResource(); + assertSame(r, r.as(URLProvider.class)); + } + + @Test + public void testGetURLOfManifest() { + JavaResource r = new JavaResource(); + r.setName("META-INF/MANIFEST.MF"); + assertNotNull(r.getURL()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java new file mode 100644 index 00000000..f91077a6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/LazyResourceCollectionTest.java @@ -0,0 +1,186 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.resources; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; +import java.util.List; +import java.util.NoSuchElementException; + + +import org.apache.tools.ant.types.Resource; +import org.apache.tools.ant.types.ResourceCollection; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class LazyResourceCollectionTest { + + private class StringResourceCollection implements ResourceCollection { + List resources = Arrays.<Resource>asList(); + + List createdIterators = new ArrayList(); + + public int size() { + return resources.size(); + } + + public Iterator<Resource> iterator() { + StringResourceIterator it = new StringResourceIterator(); + createdIterators.add(it); + return it; + } + + public boolean isFilesystemOnly() { + return false; + } + } + + private class StringResourceIterator implements Iterator { + int cursor = 0; + + public void remove() { + throw new UnsupportedOperationException(); + } + + public Object next() { + if (cursor < 3) { + cursor++; + return new StringResource("r" + cursor); + } + return null; + } + + public boolean hasNext() { + return cursor < 3; + } + } + + @Test + public void testLazyLoading() throws Exception { + StringResourceCollection collectionTest = new StringResourceCollection(); + LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); + lazyCollection.add(collectionTest); + + Iterator<Resource> it = lazyCollection.iterator(); + assertOneCreatedIterator(collectionTest); + StringResourceIterator stringResourceIterator = (StringResourceIterator) collectionTest.createdIterators + .get(0); + assertEquals("A resource was loaded without iterating", 1, + stringResourceIterator.cursor); + + StringResource r = (StringResource) it.next(); + assertOneCreatedIterator(collectionTest); + assertEquals("r1", r.getValue()); + assertEquals("Iterating once load more than 1 resource", 2, + stringResourceIterator.cursor); + + r = (StringResource) it.next(); + assertOneCreatedIterator(collectionTest); + assertEquals("r2", r.getValue()); + assertEquals("Iterating twice load more than 2 resources", 3, + stringResourceIterator.cursor); + + r = (StringResource) it.next(); + assertOneCreatedIterator(collectionTest); + assertEquals("r3", r.getValue()); + assertEquals("Iterating 3 times load more than 3 resources", 3, + stringResourceIterator.cursor); + + try { + it.next(); + fail("NoSuchElementException should have been raised"); + } catch (NoSuchElementException e) { + // ok + } + } + + private void assertOneCreatedIterator( + StringResourceCollection testCollection) { + assertEquals("More than one iterator has been created", 1, + testCollection.createdIterators.size()); + } + + @Test + public void testCaching() throws Exception { + StringResourceCollection collectionTest = new StringResourceCollection(); + LazyResourceCollectionWrapper lazyCollection = new LazyResourceCollectionWrapper(); + lazyCollection.add(collectionTest); + + assertTrue(lazyCollection.isCache()); + Iterator<Resource> it1 = lazyCollection.iterator(); + assertOneCreatedIterator(collectionTest); + Iterator<Resource> it2 = lazyCollection.iterator(); + assertOneCreatedIterator(collectionTest); + + StringResourceIterator stringResourceIterator = (StringResourceIterator) collectionTest.createdIterators + .get(0); + assertEquals("A resource was loaded without iterating", 1, + stringResourceIterator.cursor); + + StringResource r = (StringResource) it1.next(); + assertEquals("r1", r.getValue()); + assertEquals("Iterating once load more than 1 resource", 2, + stringResourceIterator.cursor); + + r = (StringResource) it2.next(); + assertEquals("r1", r.getValue()); + assertEquals( + "The second iterator did not lookup in the cache for a resource", + 2, stringResourceIterator.cursor); + + r = (StringResource) it2.next(); + assertEquals("r2", r.getValue()); + assertEquals("Iterating twice load more than 2 resources", 3, + stringResourceIterator.cursor); + + r = (StringResource) it1.next(); + assertEquals("r2", r.getValue()); + assertEquals( + "The first iterator did not lookup in the cache for a resource", + 3, stringResourceIterator.cursor); + + r = (StringResource) it2.next(); + assertEquals("r3", r.getValue()); + assertEquals("Iterating 3 times load more than 3 resources", 3, + stringResourceIterator.cursor); + + r = (StringResource) it1.next(); + assertEquals("r3", r.getValue()); + assertEquals( + "The first iterator did not lookup in the cache for a resource", + 3, stringResourceIterator.cursor); + + try { + it1.next(); + fail("NoSuchElementException should have been raised"); + } catch (NoSuchElementException e) { + // ok + } + + try { + it2.next(); + fail("NoSuchElementException should have been raised"); + } catch (NoSuchElementException e) { + // ok + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java new file mode 100644 index 00000000..6c05963b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/MultiRootFileSetTest.java @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.resources; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.AbstractFileSet; +import org.apache.tools.ant.types.AbstractFileSetTest; +import org.apache.tools.ant.types.Reference; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * This doesn't actually test much, mainly reference handling. + */ +public class MultiRootFileSetTest extends AbstractFileSetTest { + + + protected AbstractFileSet getInstance() { + return new MultiRootFileSet() { + // overriding so set/getDir works as expected by the base test class + private File dir; + public void setDir(File dir) { + if (isReference()) { + throw tooManyAttributes(); + } + this.dir = dir; + } + + public synchronized File getDir(Project p) { + if (isReference()) { + return getRef(p).getDir(p); + } + dieOnCircularReference(); + return dir; + } + }; + } + + @Test + public void testEmptyElementIfIsReferenceAdditionalAttributes() { + MultiRootFileSet f = new MultiRootFileSet(); + f.setProject(getProject()); + f.setBaseDirs("a"); + try { + f.setRefid(new Reference(getProject(), "dummyref")); + fail("Can add reference to multirootfileset " + + " with elements from setBasedirs"); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + f = new MultiRootFileSet(); + f.addConfiguredBaseDir(new FileResource(new File("."))); + try { + f.setRefid(new Reference(getProject(), "dummyref")); + fail("Can add reference to multirootfileset" + + " with elements from addConfiguredBaseDir"); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + + f = new MultiRootFileSet(); + f.setRefid(new Reference(getProject(), "dummyref")); + try { + f.setBaseDirs("a"); + fail("Can set basedirs in multirootfileset" + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + try { + f.setCache(true); + fail("Can set cache in multirootfileset" + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + try { + f.setType(MultiRootFileSet.SetType.file); + fail("Can set type in multirootfileset" + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute " + + "when using refid", be.getMessage()); + } + try { + f.addConfiguredBaseDir(new FileResource(new File("."))); + fail("Can add nested basedir in multirootfileset " + + " that is a reference."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using " + + "refid", be.getMessage()); + } + } + + @Test + public void testDirCannotBeSet() { + try { + new MultiRootFileSet().setDir(new File(".")); + fail("Can set dir in a multirootfileset"); + } catch (BuildException e) { + assertTrue(e.getMessage() + .endsWith(" doesn't support the dir attribute")); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java new file mode 100644 index 00000000..f0201789 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/ResourceListTest.java @@ -0,0 +1,134 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.resources; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.types.FilterChain; +import org.apache.tools.ant.types.Reference; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +public class ResourceListTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() throws Exception { + buildRule.configureProject("src/etc/testcases/types/resources/resourcelist.xml"); + } + + @After + public void tearDown() throws Exception { + buildRule.executeTarget("tearDown"); + } + + @Test + public void testEmptyElementWithReference() { + ResourceList rl = new ResourceList(); + rl.setEncoding("foo"); + try { + rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); + fail("Can add reference to ResourceList with encoding attribute set."); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + rl = new ResourceList(); + rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); + try { + rl.setEncoding("foo"); + fail("Can set encoding in ResourceList that is a reference"); + } catch (BuildException be) { + assertEquals("You must not specify more than one attribute when using refid", + be.getMessage()); + } + + rl = new ResourceList(); + rl.add(new FileResource(buildRule.getProject(), ".")); + try { + rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); + fail("Can add reference to ResourceList with nested resource collection."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + + rl = new ResourceList(); + rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); + try { + rl.add(new FileResource(buildRule.getProject(), ".")); + fail("Can add reference to ResourceList with nested resource collection."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + + rl = new ResourceList(); + rl.addFilterChain(new FilterChain()); + try { + rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); + fail("Can add reference to ResourceList with nested filter chain."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + + rl = new ResourceList(); + rl.setRefid(new Reference(buildRule.getProject(), "dummyref")); + try { + rl.addFilterChain(new FilterChain()); + fail("Can add reference to ResourceList with nested filter chain."); + } catch (BuildException be) { + assertEquals("You must not specify nested elements when using refid", + be.getMessage()); + } + } + + @Test + public void testCircularReference() throws Exception { + ResourceList rl1 = new ResourceList(); + rl1.setProject(buildRule.getProject()); + rl1.setRefid(new Reference(buildRule.getProject(), "foo")); + + ResourceList rl2 = new ResourceList(); + rl2.setProject(buildRule.getProject()); + buildRule.getProject().addReference("foo", rl2); + + Union u = new Union(); + u.add(rl1); + u.setProject(buildRule.getProject()); + + rl2.add(u); + + try { + rl2.size(); + fail("Can make ResourceList a Reference to itself."); + } catch (BuildException be) { + assertEquals("This data type contains a circular reference.", + be.getMessage()); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java new file mode 100644 index 00000000..a9593f09 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/resources/TarResourceTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.resources; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.apache.tools.ant.FileUtilities.getFileContents; +import static org.junit.Assert.assertEquals; + + +public class TarResourceTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() throws Exception { + buildRule.configureProject("src/etc/testcases/types/resources/tarentry.xml"); + } + + + @After + public void tearDown() throws Exception { + buildRule.executeTarget("tearDown"); + } + + @Test + public void testUncompressSource() throws java.io.IOException { + buildRule.executeTarget("uncompressSource"); + assertEquals(getFileContents(buildRule.getProject().resolveFile("../../asf-logo.gif")), + getFileContents(new File(buildRule.getProject().getProperty("output"), "asf-logo.gif"))); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java new file mode 100644 index 00000000..d5613b26 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorRule.java @@ -0,0 +1,125 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import java.io.File; + + +import org.apache.tools.ant.BuildFileRule; + + +/** + * Base test case for Selectors. Provides a shared test as well as + * a test bed for selecting on, and a helper method for determining + * whether selections are correct. + * + */ +public class BaseSelectorRule extends BuildFileRule { + + private File beddir; + private File mirrordir; + private final String[] filenames = {".","asf-logo.gif.md5","asf-logo.gif.bz2", + "asf-logo.gif.gz","copy.filterset.filtered","zip/asf-logo.gif.zip", + "tar/asf-logo.gif.tar","tar/asf-logo-huge.tar.gz", + "tar/gz/asf-logo.gif.tar.gz","tar/bz2/asf-logo.gif.tar.bz2", + "tar/bz2/asf-logo-huge.tar.bz2","tar/bz2"}; + private File[] files = new File[filenames.length]; + private File[] mirrorfiles = new File[filenames.length]; + + @Override + public void before() throws Throwable { + super.before(); + configureProject("src/etc/testcases/types/selectors.xml"); + executeTarget("setUp"); + + executeTarget("setupfiles"); + executeTarget("mirrorfiles"); + + beddir = new File(super.getProject().getProperty("test.dir")); + mirrordir = new File(super.getProject().getProperty("mirror.dir")); + + for (int x = 0; x < files.length; x++) { + files[x] = new File(beddir,filenames[x]); + mirrorfiles[x] = new File(mirrordir,filenames[x]); + } + } + + @Override + public void after() { + super.after(); + executeTarget("tearDown"); + } + + public File getBeddir() { + return beddir; + } + + public File[] getMirrorFiles() { + return mirrorfiles; + } + + public File[] getFiles() { + return files; + } + + public String[] getFilenames() { + return filenames; + } + + + /** + * This is a helper method that takes a selector and calls its + * isSelected() method on each file in the testbed. It returns + * a string of "T"s amd "F"s + */ + public String selectionString(FileSelector selector) { + return selectionString(beddir,files,selector); + } + + /** + * This is a helper method that takes a selector and calls its + * isSelected() method on each file in the mirror testbed. This + * variation is used for dependency checks and to get around the + * limitations in the touch task when running JDK 1.1. It returns + * a string of "T"s amd "F"s. + */ + public String mirrorSelectionString(FileSelector selector) { + return selectionString(mirrordir,mirrorfiles,selector); + } + + /** + * Worker method for the two convenience methods above. Applies a + * selector on a set of files passed in and returns a string of + * "T"s amd "F"s from applying the selector to each file. + */ + public String selectionString(File basedir, File[] files, FileSelector selector) { + StringBuilder buf = new StringBuilder(); + for (int x = 0; x < files.length; x++) { + if (selector.isSelected(basedir,filenames[x],files[x])) { + buf.append('T'); + } + else { + buf.append('F'); + } + } + return buf.toString(); + } + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java new file mode 100644 index 00000000..2332778e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/BaseSelectorTest.java @@ -0,0 +1,295 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import java.io.File; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileTest; +import org.apache.tools.ant.Project; + +/** + * Base test case for Selectors. Provides a shared test as well as + * a test bed for selecting on, and a helper method for determining + * whether selections are correct. + * + * @deprecated as of 1.9.4. Use {@link org.apache.tools.ant.types.selectors.BaseSelectorRule} instead. + */ +@Deprecated +public abstract class BaseSelectorTest extends BuildFileTest { + + private Project project; + private TaskdefForMakingBed tbed = null; + protected File basedir; + protected File beddir; + protected File mirrordir; + protected String[] filenames = {".","asf-logo.gif.md5","asf-logo.gif.bz2", + "asf-logo.gif.gz","copy.filterset.filtered","zip/asf-logo.gif.zip", + "tar/asf-logo.gif.tar","tar/asf-logo-huge.tar.gz", + "tar/gz/asf-logo.gif.tar.gz","tar/bz2/asf-logo.gif.tar.bz2", + "tar/bz2/asf-logo-huge.tar.bz2","tar/bz2"}; + protected File[] files = new File[filenames.length]; + protected File[] mirrorfiles = new File[filenames.length]; + + public BaseSelectorTest(String name) { + super(name); + } + + public void setUp() { + configureProject("src/etc/testcases/types/selectors.xml"); + executeTarget("setUp"); + beddir = new File(super.getProject().getProperty("test.dir")); + mirrordir = new File(super.getProject().getProperty("mirror.dir")); + basedir = getProjectDir(); + project = new Project(); + project.init(); + project.setBaseDir(basedir); + for (int x = 0; x < files.length; x++) { + files[x] = new File(beddir,filenames[x]); + mirrorfiles[x] = new File(mirrordir,filenames[x]); + } + } + + /** + * Override this in child classes to return a specific Selector + */ + public abstract BaseSelector getInstance(); + + + /** + * Return a preconfigured selector (with a set reference to + * project instance). + * @return the selector + */ + public BaseSelector getSelector() { + BaseSelector selector = getInstance(); + selector.setProject( getProject() ); + return selector; + } + + + public Project getProject() { + return project; + } + + /** + * This is a test that all Selectors derived from BaseSelector can + * use. It calls the setError() method and checks to ensure that a + * BuildException is thrown as a result. + */ + public void testRespondsToError() { + BaseSelector s = getInstance(); + if (s == null) { + return; + } + s.setError("test error"); + try { + s.isSelected(beddir,filenames[0],files[0]); + fail("Cannot cause BuildException when setError() is called"); + } catch (BuildException be) { + assertEquals("test error", + be.getMessage()); + } + } + + + /** + * This is a helper method that takes a selector and calls its + * isSelected() method on each file in the testbed. It returns + * a string of "T"s amd "F"s + */ + public String selectionString(FileSelector selector) { + return selectionString(beddir,files,selector); + } + + /** + * This is a helper method that takes a selector and calls its + * isSelected() method on each file in the mirror testbed. This + * variation is used for dependency checks and to get around the + * limitations in the touch task when running JDK 1.1. It returns + * a string of "T"s amd "F"s. + */ + public String mirrorSelectionString(FileSelector selector) { + return selectionString(mirrordir,mirrorfiles,selector); + } + + /** + * Worker method for the two convenience methods above. Applies a + * selector on a set of files passed in and returns a string of + * "T"s amd "F"s from applying the selector to each file. + */ + public String selectionString(File basedir, File[] files, FileSelector selector) { + StringBuffer buf = new StringBuffer(); + for (int x = 0; x < files.length; x++) { + if (selector.isSelected(basedir,filenames[x],files[x])) { + buf.append('T'); + } + else { + buf.append('F'); + } + } + return buf.toString(); + } + + /** + * Does the selection test for a given selector and prints the + * filenames of the differing files (selected but shouldn't, + * not selected but should). + * @param selector The selector to test + * @param expected The expected result + */ + public void performTests(FileSelector selector, String expected) { + String result = selectionString(selector); + String diff = diff(expected, result); + String resolved = resolve(diff); + assertEquals("Differing files: " + resolved, result, expected); + } + + /** + * Checks which files are selected and shouldn't be or which + * are not selected but should. + * @param expected String containing 'F's and 'T's + * @param result String containing 'F's and 'T's + * @return Difference as String containing '-' (equal) and + * 'X' (difference). + */ + public String diff(String expected, String result) { + int length1 = expected.length(); + int length2 = result.length(); + int min = (length1 > length2) ? length2 : length1; + StringBuffer sb = new StringBuffer(); + for (int i=0; i<min; i++) { + sb.append( + (expected.charAt(i) == result.charAt(i)) + ? "-" + : "X" + ); + } + return sb.toString(); + } + + + /** + * Resolves a diff-String (@see diff()) against the (inherited) filenames- + * and files arrays. + * @param filelist Diff-String + * @return String containing the filenames for all differing files, + * separated with semicolons ';' + */ + public String resolve(String filelist) { + StringBuffer sb = new StringBuffer(); + int min = (filenames.length > filelist.length()) + ? filelist.length() + : filenames.length; + for (int i=0; i<min; i++) { + if ('X'==filelist.charAt(i)) { + sb.append(filenames[i]); + sb.append(";"); + } + } + return sb.toString(); + } + + + /** + * <p>Creates a testbed. We avoid the dreaded "test" word so that we + * don't falsely identify this as a test to be run. The actual + * setting up of the testbed is done in the + * <code>src/etc/testcases/types/selectors.xml</code> build file.</p> + * + * <p>Note that the right way to call this is within a try block, + * with a finally clause that calls cleanupBed(). You place tests of + * the isSelected() method within the try block.</p> + */ + protected void makeBed() { + tbed = new TaskdefForMakingBed("setupfiles"); + tbed.setUp(); + tbed.makeTestbed(); + } + + /** + * Cleans up the testbed by calling a target in the + * <code>src/etc/testcases/types/selectors.xml</code> file. + */ + protected void cleanupBed() { + if (tbed != null) { + tbed.tearDown(); + tbed = null; + } + } + + + /** + * <p>Creates a mirror of the testbed for use in dependency checks.</p> + * + * <p>Note that the right way to call this is within a try block, + * with a finally clause that calls cleanupMirror(). You place tests of + * the isSelected() method within the try block.</p> + */ + protected void makeMirror() { + tbed = new TaskdefForMakingBed("mirrorfiles"); + tbed.setUp(); + tbed.makeMirror(); + } + + /** + * Cleans up the mirror testbed by calling a target in the + * <code>src/etc/testcases/types/selectors.xml</code> file. + */ + protected void cleanupMirror() { + if (tbed != null) { + tbed.deleteMirror(); + tbed = null; + } + } + + private class TaskdefForMakingBed extends BuildFileTest { + + TaskdefForMakingBed(String name) { + super(name); + } + + public void setUp() { + configureProject("src/etc/testcases/types/selectors.xml"); + } + + public void tearDown() { + try { + super.tearDown(); + } catch (Exception exc) { + // ignore + } + } + + public void makeTestbed() { + executeTarget("setupfiles"); + } + + public void makeMirror() { + executeTarget("mirrorfiles"); + } + + public void deleteMirror() { + executeTarget("tearDown"); + } + } + + + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java new file mode 100644 index 00000000..41e9c830 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import java.io.File; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + + +public class ContainsRegexpTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/selectors.xml"); + } + + @Test + public void testContainsRegexp() { + buildRule.executeTarget("containsregexp"); + File dir = new File(buildRule.getOutputDir(), "regexpseltestdest"); + File[] files = dir.listFiles(); + int filecount = files.length; + + if (filecount != 1) { + assertEquals("ContainsRegexp test should have copied 1 file", + 1, files.length); + + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java new file mode 100644 index 00000000..9a5a83fe --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java @@ -0,0 +1,114 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Parameter; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Tests Contains Selectors. + * + */ +public class ContainsSelectorTest { + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + + /** + * Test the code that validates the selector. + */ + @Test + public void testValidate() { + ContainsSelector s = new ContainsSelector(); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("ContainsSelector did not check for required field 'text'"); + } catch (BuildException be1) { + assertEquals("The text attribute is required", be1.getMessage()); + } + + s = new ContainsSelector(); + Parameter param = new Parameter(); + param.setName("garbage in"); + param.setValue("garbage out"); + Parameter[] params = {param}; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("ContainsSelector did not check for valid parameter element"); + } catch (BuildException be2) { + assertEquals("Invalid parameter garbage in", be2.getMessage()); + } + + } + + /** + * Tests to make sure that the selector is selecting files correctly. + */ + @Test + public void testSelectionBehaviour() { + ContainsSelector s; + String results; + + + s = new ContainsSelector(); + s.setText("no such string in test files"); + results = selectorRule.selectionString(s); + assertEquals("TFFFFFFFFFFT", results); + + s = new ContainsSelector(); + s.setText("Apache Ant"); + results = selectorRule.selectionString(s); + assertEquals("TFFFTFFFFFFT", results); + + s = new ContainsSelector(); + s.setText("apache ant"); + s.setCasesensitive(true); + results = selectorRule.selectionString(s); + assertEquals("TFFFFFFFFFFT", results); + + s = new ContainsSelector(); + s.setText("apache ant"); + s.setCasesensitive(false); + results = selectorRule.selectionString(s); + assertEquals("TFFFTFFFFFFT", results); + + s = new ContainsSelector(); + s.setText("ApacheAnt"); + s.setIgnorewhitespace(true); + results = selectorRule.selectionString(s); + assertEquals("TFFFTFFFFFFT", results); + + s = new ContainsSelector(); + s.setText("A p a c h e A n t"); + s.setIgnorewhitespace(true); + results = selectorRule.selectionString(s); + assertEquals("TFFFTFFFFFFT", results); + + + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java new file mode 100644 index 00000000..6e461bab --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java @@ -0,0 +1,229 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Parameter; +import org.junit.Assume; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +/** + * Tests Date Selectors. + * + */ +public class DateSelectorTest { + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + + /** + * Test the code that validates the selector. + */ + @Test + public void testValidate() { + DateSelector s = new DateSelector(); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DateSelector did not check for required fields"); + } catch (BuildException be1) { + assertEquals("You must provide a datetime or the number of " + + "milliseconds.", be1.getMessage()); + } + + s = new DateSelector(); + s.setDatetime("01/01/1969 01:01 AM"); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DateSelector did not check for Datetime being in the " + + "allowable range"); + } catch (BuildException be2) { + assertEquals("Date of 01/01/1969 01:01 AM results in negative " + + "milliseconds value relative to epoch (January 1, " + + "1970, 00:00:00 GMT).", be2.getMessage()); + } + + s = new DateSelector(); + s.setDatetime("this is not a date"); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DateSelector did not check for Datetime being in a " + + "valid format"); + } catch (BuildException be3) { + assertEquals("Date of this is not a date" + + " Cannot be parsed correctly. It should be in" + + " MM/DD/YYYY HH:MM AM_PM format.", be3.getMessage()); + } + + s = new DateSelector(); + Parameter param = new Parameter(); + param.setName("garbage in"); + param.setValue("garbage out"); + Parameter[] params = new Parameter[1]; + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DateSelector did not check for valid parameter element"); + } catch (BuildException be4) { + assertEquals("Invalid parameter garbage in", be4.getMessage()); + } + + s = new DateSelector(); + param = new Parameter(); + param.setName("millis"); + param.setValue("garbage out"); + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DateSelector did not check for valid millis parameter"); + } catch (BuildException be5) { + assertEquals("Invalid millisecond setting garbage out", + be5.getMessage()); + } + + s = new DateSelector(); + param = new Parameter(); + param.setName("granularity"); + param.setValue("garbage out"); + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DateSelector did not check for valid granularity parameter"); + } catch (BuildException be6) { + assertEquals("Invalid granularity setting garbage out", + be6.getMessage()); + } + + } + + /** + * Tests to make sure that the selector is selecting files correctly. + */ + @Test + public void testSelectionBehaviour() { + DateSelector s; + String results; + + DateSelector.TimeComparisons before = new + DateSelector.TimeComparisons(); + before.setValue("before"); + DateSelector.TimeComparisons equal = new + DateSelector.TimeComparisons(); + equal.setValue("equal"); + DateSelector.TimeComparisons after = new + DateSelector.TimeComparisons(); + after.setValue("after"); + + + s = new DateSelector(); + s.setDatetime("10/10/1999 1:45 PM"); + s.setWhen(before); + results = selectorRule.selectionString(s); + assertEquals("TFFFFFFFFFFT", results); + + s = new DateSelector(); + s.setDatetime("10/10/1999 1:45 PM"); + s.setWhen(before); + s.setCheckdirs(true); + results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFFFF", results); + + s = new DateSelector(); + s.setDatetime("10/10/1999 1:45 PM"); + s.setWhen(after); + results = selectorRule.selectionString(s); + assertEquals("TTTTTTTTTTTT", results); + + s = new DateSelector(); + s.setDatetime("11/21/2001 4:54 AM"); + s.setWhen(before); + results = selectorRule.selectionString(s); + assertEquals("TFTFFFFFFFFT", results); + + s = new DateSelector(); + s.setDatetime("11/21/2001 4:55 AM"); + + long milliseconds = s.getMillis(); + s.setWhen(equal); + results = selectorRule.selectionString(s); + assertEquals("TTFFTFFFTTTT", results); + + s = new DateSelector(); + s.setMillis(milliseconds); + s.setWhen(equal); + results = selectorRule.selectionString(s); + assertEquals("TTFFTFFFTTTT", results); + + s = new DateSelector(); + s.setDatetime("11/21/2001 4:56 AM"); + s.setWhen(after); + results = selectorRule.selectionString(s); + assertEquals("TFFTFTTTFFFT", results); + + s = new DateSelector(); + Parameter param1 = new Parameter(); + Parameter param2 = new Parameter(); + param1.setName("datetime"); + param1.setValue("11/21/2001 4:56 AM"); + param2.setName("when"); + param2.setValue("after"); + Parameter[] params = {param1,param2}; + s.setParameters(params); + results = selectorRule.selectionString(s); + assertEquals("TFFTFTTTFFFT", results); + + s = new DateSelector(); + long testtime = selectorRule.getMirrorFiles()[5].lastModified(); + s.setMillis(testtime); + s.setWhen(after); + s.setGranularity(2); + + // setup the modified timestamp to match what the test needs, although be aware that the 3rd and 4th + // files don't exist so can't be changed, so don't try and loop over them + for (int i = 1; i <=2; i++) { + Assume.assumeTrue("Cannot setup file times for test", selectorRule.getMirrorFiles()[i].setLastModified(testtime - (3*60*60*100))); + } + + + results = selectorRule.mirrorSelectionString(s); + assertEquals("TFFFFTTTTTTT", results); + + s = new DateSelector(); + testtime = selectorRule.getMirrorFiles()[6].lastModified(); + s.setMillis(testtime); + s.setWhen(before); + s.setGranularity(2); + for (int i = 7; i <= 10; i++) { + Assume.assumeTrue("Cannot setup file times for test", selectorRule.getMirrorFiles()[i].setLastModified(testtime + (3*60*60*100))); + } + + results = selectorRule.mirrorSelectionString(s); + assertEquals("TTTTTTTFFFFT", results); + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java new file mode 100644 index 00000000..ec95878a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java @@ -0,0 +1,185 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Mapper; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +/** + * Tests Depend Selectors + * + */ +public class DependSelectorTest { + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + @Test + public void testValidateSingleMapper() { + try { + DependSelector s = new DependSelector(); + s.createMapper(); + s.createMapper(); + fail("DependSelector allowed more than one nested mapper."); + } catch (BuildException be1) { + assertEquals("Cannot define more than one mapper", + be1.getMessage()); + } + } + + + @Test + public void testValidateRequiredFields() { + try { + DependSelector s = new DependSelector(); + s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0], selectorRule.getFiles()[0]); + fail("DependSelector did not check for required fields"); + } catch (BuildException be2) { + assertEquals("The targetdir attribute is required.", + be2.getMessage()); + } + + } + + @Test + public void testNoMapper() { + DependSelector s = new DependSelector(); + s.setTargetdir(selectorRule.getBeddir()); + + String results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFFFF", results); + } + + @Test + public void testIdentityMapper() { + DependSelector s = new DependSelector(); + s.setTargetdir(selectorRule.getBeddir()); + + Mapper.MapperType identity = new Mapper.MapperType(); + identity.setValue("identity"); + + Mapper m = s.createMapper(); + m.setType(identity); + + String results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFFFF", results); + } + + @Test + public void testMergeMapper() { + DependSelector s = new DependSelector(); + s.setTargetdir(selectorRule.getBeddir()); + + Mapper.MapperType merge = new Mapper.MapperType(); + merge.setValue("merge"); + + Mapper m = s.createMapper(); + m.setType(merge); + m.setTo("asf-logo.gif.gz"); + + String results = selectorRule.selectionString(s); + assertEquals("TFFFFTTTFFF", results.substring(0,11)); + } + + @Test + public void testMergeMapper2() { + DependSelector s = new DependSelector(); + s.setTargetdir(selectorRule.getBeddir()); + + Mapper.MapperType merge = new Mapper.MapperType(); + merge.setValue("merge"); + + Mapper m = s.createMapper(); + m.setType(merge); + m.setTo("asf-logo.gif.bz2"); + String results = selectorRule.selectionString(s); + assertEquals("TTFTTTTTTTTT", results); + } + + @Test + public void testGlobMapperRelativePath() { + DependSelector s = new DependSelector(); + File subdir = new File("selectortest/tar/bz2"); + s.setTargetdir(subdir); + + Mapper.MapperType glob = new Mapper.MapperType(); + glob.setValue("glob"); + + Mapper m = s.createMapper(); + m.setType(glob); + m.setFrom("*.bz2"); + m.setTo("*.tar.bz2"); + + String results = selectorRule.selectionString(s); + assertEquals("FFTFFFFFFTTF", results); + } + + @Test + public void testRestrictedGlobMapper() { + DependSelector s = new DependSelector(); + File subdir = new File(selectorRule.getBeddir(), "tar/bz2"); + s.setTargetdir(subdir); + + Mapper.MapperType glob = new Mapper.MapperType(); + glob.setValue("glob"); + + Mapper m = s.createMapper(); + m.setType(glob); + m.setFrom("*.bz2"); + m.setTo("*.tar.bz2"); + String results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFTTF", results); + } + + @Test + public void testSelectionNoMapper() { + DependSelector s = new DependSelector(); + s.setTargetdir(new File(selectorRule.getOutputDir(), "selectortest2")); + String results = selectorRule.selectionString(s); + assertEquals("FFFTTFFFFFFF", results); + } + + + @Test + public void testMirroredSelection() { + DependSelector s = new DependSelector(); + s.setTargetdir(new File(selectorRule.getOutputDir(), "selectortest2/tar/bz2")); + + Mapper.MapperType glob = new Mapper.MapperType(); + glob.setValue("glob"); + + Mapper m = s.createMapper(); + m.setType(glob); + m.setFrom("*.bz2"); + m.setTo("*.tar.bz2"); + String results = selectorRule.mirrorSelectionString(s); + assertEquals("FFFFFFFFFTTF", results); + results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFTTF", results); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java new file mode 100644 index 00000000..391fb27d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java @@ -0,0 +1,147 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Parameter; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Tests Depth Selectors + * + */ +public class DepthSelectorTest { + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + + /** + * Test the code that validates the selector. + */ + @Test + public void testValidate() { + DepthSelector s = new DepthSelector(); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DepthSelector did not check for required fields"); + } catch (BuildException be1) { + assertEquals("You must set at least one of the min or the " + + "max levels.", be1.getMessage()); + } + + s = new DepthSelector(); + s.setMin(5); + s.setMax(2); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DepthSelector did not check for maximum being higher " + + "than minimum"); + } catch (BuildException be2) { + assertEquals("The maximum depth is lower than the minimum.", + be2.getMessage()); + } + + s = new DepthSelector(); + Parameter param = new Parameter(); + param.setName("garbage in"); + param.setValue("garbage out"); + Parameter[] params = new Parameter[1]; + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DepthSelector did not check for valid parameter element"); + } catch (BuildException be3) { + assertEquals("Invalid parameter garbage in", be3.getMessage()); + } + + s = new DepthSelector(); + param = new Parameter(); + param.setName("min"); + param.setValue("garbage out"); + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DepthSelector accepted bad minimum as parameter"); + } catch (BuildException be4) { + assertEquals("Invalid minimum value garbage out", + be4.getMessage()); + } + + s = new DepthSelector(); + param = new Parameter(); + param.setName("max"); + param.setValue("garbage out"); + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("DepthSelector accepted bad maximum as parameter"); + } catch (BuildException be5) { + assertEquals("Invalid maximum value garbage out", + be5.getMessage()); + } + + } + + /** + * Tests to make sure that the selector is selecting files correctly. + */ + @Test + public void testSelectionBehaviour() { + DepthSelector s; + String results; + + s = new DepthSelector(); + s.setMin(20); + s.setMax(25); + results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFFFF", results); + + s = new DepthSelector(); + s.setMin(0); + results = selectorRule.selectionString(s); + assertEquals("TTTTTTTTTTTT", results); + + s = new DepthSelector(); + s.setMin(1); + results = selectorRule.selectionString(s); + assertEquals("FFFFFTTTTTTT", results); + + s = new DepthSelector(); + s.setMax(0); + results = selectorRule.selectionString(s); + assertEquals("TTTTTFFFFFFF", results); + + s = new DepthSelector(); + s.setMin(1); + s.setMax(1); + results = selectorRule.selectionString(s); + assertEquals("FFFFFTTTFFFT", results); + + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java new file mode 100644 index 00000000..ce7729a8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Parameter; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Tests Filename Selectors + * + */ +public class FilenameSelectorTest { + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + /** + * Test the code that validates the selector. + */ + @Test + public void testValidate() { + FilenameSelector s = new FilenameSelector(); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("FilenameSelector did not check for required fields"); + } catch (BuildException be1) { + assertEquals("The name or regex attribute is required", be1.getMessage()); + } + + s = new FilenameSelector(); + Parameter param = new Parameter(); + param.setName("garbage in"); + param.setValue("garbage out"); + Parameter[] params = {param}; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("FilenameSelector did not check for valid parameter element"); + } catch (BuildException be2) { + assertEquals("Invalid parameter garbage in", be2.getMessage()); + } + + } + + /** + * Tests to make sure that the selector is selecting files correctly. + */ + @Test + public void testSelectionBehaviour() { + FilenameSelector s; + String results; + + + s = new FilenameSelector(); + s.setName("no match possible"); + results = selectorRule.selectionString(s); + assertEquals("FFFFFFFFFFFF", results); + + s = new FilenameSelector(); + s.setName("*.gz"); + results = selectorRule.selectionString(s); + // This is turned off temporarily. There appears to be a bug + // in SelectorUtils.matchPattern() where it is recursive on + // Windows even if no ** is in pattern. + //assertEquals("FFFTFFFFFFFF", results); // Unix + // vs + //assertEquals("FFFTFFFFTFFF", results); // Windows + + s = new FilenameSelector(); + s.setName("**/*.gz"); + s.setNegate(true); + results = selectorRule.selectionString(s); + assertEquals("TTTFTTTFFTTT", results); + + s = new FilenameSelector(); + s.setName("**/*.GZ"); + s.setCasesensitive(false); + results = selectorRule.selectionString(s); + assertEquals("FFFTFFFTTFFF", results); + + s = new FilenameSelector(); + Parameter param1 = new Parameter(); + param1.setName("name"); + param1.setValue("**/*.bz2"); + Parameter[] params = {param1}; + s.setParameters(params); + results = selectorRule.selectionString(s); + assertEquals("FFTFFFFFFTTF", results); + + + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/MockAlgorithm.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/MockAlgorithm.java new file mode 100644 index 00000000..458c83fe --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/MockAlgorithm.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + + +import java.io.File; +import org.apache.tools.ant.types.selectors.modifiedselector.Algorithm; + +public class MockAlgorithm implements Algorithm { + public boolean isValid() { + return true; + } + + public String getValue(File file) { + return "TEST"; + } + + public String toString() { + return "MockAlgorithm@" + hashCode(); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/MockCache.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/MockCache.java new file mode 100644 index 00000000..e501a6b8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/MockCache.java @@ -0,0 +1,68 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + + +import java.util.Iterator; +import org.apache.tools.ant.types.selectors.modifiedselector.Cache; + +public class MockCache implements Cache { + + public boolean debug = false; + public boolean saved = false; + + + public MockCache() { + log("()"); + } + + public boolean isValid() { + log(".isValid()"); + return true; + } + public void delete() { + log(".delete()"); + } + public void load() { + log(".load()"); + } + public void save() { + log(".save()"); + saved = true; + } + public Object get(Object key) { + log(".get("+key+")"); + return key; + } + public void put(Object key, Object value) { + log(".put("+key+", "+value+")"); + saved = false; + } + public Iterator<String> iterator() { + log("iterator()"); + return null; + } + public String toString() { + return "MockCache@" + hashCode(); + } + + private void log(String msg) { + if (debug) System.out.println(this+msg); + } +}//class-MockCache diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/MockComparator.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/MockComparator.java new file mode 100644 index 00000000..a7c15539 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/MockComparator.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import java.util.Comparator; + +public class MockComparator implements Comparator { + + public int compare(Object o1, Object o2) { + return 0; + } + + public String toString() { + return "MockComparator"; + } +}//class-MockCache diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java new file mode 100644 index 00000000..80dd6dfa --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java @@ -0,0 +1,1062 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + + +// Java +import java.io.File; +import java.text.RuleBasedCollator; +import java.util.Comparator; +import java.util.Iterator; + +import org.apache.tools.ant.AntAssert; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.BuildFileRule; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Target; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.types.Parameter; +import org.apache.tools.ant.types.Path; +import org.apache.tools.ant.types.selectors.modifiedselector.Algorithm; +import org.apache.tools.ant.types.selectors.modifiedselector.Cache; +import org.apache.tools.ant.types.selectors.modifiedselector.ChecksumAlgorithm; +import org.apache.tools.ant.types.selectors.modifiedselector.DigestAlgorithm; +import org.apache.tools.ant.types.selectors.modifiedselector.EqualComparator; +import org.apache.tools.ant.types.selectors.modifiedselector.HashvalueAlgorithm; +import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector; +import org.apache.tools.ant.types.selectors.modifiedselector.PropertiesfileCache; +import org.apache.tools.ant.util.FileUtils; +import org.junit.Assume; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + + +/** + * Unit tests for ModifiedSelector. + * + * @since Ant 1.6 + */ +public class ModifiedSelectorTest { + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + /** Utilities used for file operations */ + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + // ===================== attributes ===================== + + + /** Path where the testclasses are. */ + private Path testclasses = null; + + + + + // ===================== JUnit stuff ===================== + + + @Before + public void setUp() { + // init the testclasses path object + Project prj = selectorRule.getProject(); + testclasses = new Path(prj, prj.getProperty("build.tests.value")); + } + + + // ======= testcases for the attributes and nested elements of the selector ===== + + + /** Test right use of cache names. */ + @Test + public void testValidateWrongCache() { + String name = "this-is-not-a-valid-cache-name"; + try { + ModifiedSelector.CacheName cacheName = new ModifiedSelector.CacheName(); + cacheName.setValue(name); + fail("CacheSelector.CacheName accepted invalid value."); + } catch (BuildException be) { + assertEquals(name + " is not a legal value for this attribute", + be.getMessage()); + } + } + + + /** Test right use of cache names. */ + @Test + public void testValidateWrongAlgorithm() { + String name = "this-is-not-a-valid-algorithm-name"; + try { + ModifiedSelector.AlgorithmName algoName + = new ModifiedSelector.AlgorithmName(); + algoName.setValue(name); + fail("CacheSelector.AlgorithmName accepted invalid value."); + } catch (BuildException be) { + assertEquals(name + " is not a legal value for this attribute", + be.getMessage()); + } + } + + + /** Test right use of comparator names. */ + @Test + public void testValidateWrongComparator() { + String name = "this-is-not-a-valid-comparator-name"; + try { + ModifiedSelector.ComparatorName compName + = new ModifiedSelector.ComparatorName(); + compName.setValue(name); + fail("ModifiedSelector.ComparatorName accepted invalid value."); + } catch (BuildException be) { + assertEquals(name + " is not a legal value for this attribute", + be.getMessage()); + } + } + + + @Test + public void testIllegalCustomAlgorithm() { + try { + getAlgoName("java.lang.Object"); + fail("Illegal classname used."); + } catch (BuildException e) { + assertEquals("Wrong exception message.", + "Specified class (java.lang.Object) is not an Algorithm.", + e.getMessage()); + + } + } + + + @Test + public void testNonExistentCustomAlgorithm() { + try { + getAlgoName("non.existent.custom.Algorithm"); + fail("does 'non.existent.custom.Algorithm' really exist?"); + } catch (BuildException e) { + assertEquals("Wrong exception message.", + "Specified class (non.existent.custom.Algorithm) not found.", + e.getMessage()); + + } + } + + @Test + public void testCustomAlgorithm() { + String algo = getAlgoName("org.apache.tools.ant.types.selectors.modifiedselector.HashvalueAlgorithm"); + assertTrue("Wrong algorithm used: "+algo, algo.startsWith("HashvalueAlgorithm")); + } + + @Test + public void testCustomAlgorithm2() { + String algo = getAlgoName("org.apache.tools.ant.types.selectors.MockAlgorithm"); + assertTrue("Wrong algorithm used: "+algo, algo.startsWith("MockAlgorithm")); + } + + + @Test + public void testCustomClasses() { + Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home") ); + BFT bft = new BFT(); + bft.setUp(); + try { + // do the actions + bft.doTarget("modifiedselectortest-customClasses"); + // do the checks - the buildfile stores the fileset as property + String fsFullValue = bft.getProperty("fs.full.value"); + String fsModValue = bft.getProperty("fs.mod.value"); + + assertNotNull("'fs.full.value' must be set.", fsFullValue); + assertTrue("'fs.full.value' must not be null.", !"".equals(fsFullValue)); + assertTrue("'fs.full.value' must contain ant.bat.", fsFullValue.indexOf("ant.bat")>-1); + + assertNotNull("'fs.mod.value' must be set.", fsModValue); + // must be empty according to the Mock* implementations + assertTrue("'fs.mod.value' must be empty.", "".equals(fsModValue)); + // don't catch the JUnit exceptions + } finally { + bft.doTarget("modifiedselectortest-scenario-clean"); + bft.deletePropertiesfile(); + bft.tearDown(); + } + } + + + @Test + public void testDelayUpdateTaskFinished() { + doDelayUpdateTest(1); + } + + + @Test + public void testDelayUpdateTargetFinished() { + doDelayUpdateTest(2); + } + + + @Test + public void testDelayUpdateBuildFinished() { + doDelayUpdateTest(3); + } + + + public void doDelayUpdateTest(int kind) { + // no check for 1<=kind<=3 - only internal use therefore check it + // while development + + // readable form of parameter kind + String[] kinds = {"task", "target", "build"}; + + // setup the "Ant project" + MockProject project = new MockProject(); + File base = new File("base"); + File file1 = new File("file1"); + File file2 = new File("file2"); + + // setup the selector + ModifiedSelector sel = new ModifiedSelector(); + sel.setProject(project); + sel.setUpdate(true); + sel.setDelayUpdate(true); + // sorry - otherwise we will get a ClassCastException because the MockCache + // is loaded by two different classloader ... + sel.setClassLoader(this.getClass().getClassLoader()); + sel.addClasspath(testclasses); + + sel.setAlgorithmClass("org.apache.tools.ant.types.selectors.MockAlgorithm"); + sel.setCacheClass("org.apache.tools.ant.types.selectors.MockCache"); + sel.configure(); + + // get the cache, so we can check our things + MockCache cache = (MockCache)sel.getCache(); + + // the test + assertFalse("Cache must not be saved before 1st selection.", cache.saved); + sel.isSelected(base, "file1", file1); + assertFalse("Cache must not be saved after 1st selection.", cache.saved); + sel.isSelected(base, "file2", file2); + assertFalse("Cache must not be saved after 2nd selection.", cache.saved); + switch (kind) { + case 1 : project.fireTaskFinished(); break; + case 2 : project.fireTargetFinished(); break; + case 3 : project.fireBuildFinished(); break; + } + assertTrue("Cache must be saved after " + kinds[kind-1] + "Finished-Event.", cache.saved); + + // MockCache doesnt create a file - therefore no cleanup needed + } + + + /** + * Extracts the real used algorithm name from the ModifiedSelector using + * its toString() method. + * @param classname the classname from the algorithm to use + * @return the algorithm part from the toString() (without brackets) + */ + private String getAlgoName(String classname) { + ModifiedSelector sel = new ModifiedSelector(); + sel.setProject(selectorRule.getProject()); + // add the test classes to its classpath + sel.addClasspath(testclasses); + sel.setAlgorithmClass(classname); + // let the selector do its checks + sel.validate(); + // extract the algorithm name (and config) from the selectors output + String s1 = sel.toString(); + int posStart = s1.indexOf("algorithm=") + 10; + int posEnd = s1.indexOf(" comparator="); + String algo = s1.substring(posStart, posEnd); + // '<' and '>' are only used if the algorithm has properties + if (algo.startsWith("<")) algo = algo.substring(1); + if (algo.endsWith(">")) algo = algo.substring(0, algo.length()-1); + // return the clean value + return algo; + } + + + // ================ testcases for the cache implementations ================ + + + /** + * Propertycache must have a set 'cachefile' attribute. + * The default in ModifiedSelector "cache.properties" is set by the selector. + */ + @Test + public void testPropcacheInvalid() { + Cache cache = new PropertiesfileCache(); + if (cache.isValid()) + fail("PropertyfilesCache does not check its configuration."); + } + + + @Test + public void testPropertyfileCache() { + PropertiesfileCache cache = new PropertiesfileCache(); + File cachefile = new File("cache.properties"); + cache.setCachefile(cachefile); + doTest(cache); + assertFalse("Cache file not deleted.", cachefile.exists()); + } + + + /** Checks whether a cache file is created. */ + @Test + public void testCreatePropertiesCacheDirect() { + File cachefile = new File(selectorRule.getProject().getBaseDir(), "cachefile.properties"); + + PropertiesfileCache cache = new PropertiesfileCache(); + cache.setCachefile(cachefile); + + cache.put("key", "value"); + cache.save(); + + assertTrue("Cachefile not created.", cachefile.exists()); + + cache.delete(); + assertFalse("Cachefile not deleted.", cachefile.exists()); + } + + + /** Checks whether a cache file is created. */ + @Test + public void testCreatePropertiesCacheViaModifiedSelector() { + File cachefile = new File(selectorRule.getProject().getBaseDir(), "cachefile.properties"); + + // Configure the selector + ModifiedSelector s = new ModifiedSelector(); + s.setDelayUpdate(false); + s.addParam("cache.cachefile", cachefile); + + ModifiedSelector.CacheName cacheName = new ModifiedSelector.CacheName(); + cacheName.setValue("propertyfile"); + s.setCache(cacheName); + + s.setUpdate(true); + + selectorRule.selectionString(s); + + // evaluate correctness + assertTrue("Cache file is not created.", cachefile.exists()); + cachefile.delete(); + + } + + + /** + * In earlier implementations there were problems with the <i>order</i> + * of the <param>s. The scenario was <pre> + * <custom class="ModifiedSelector"> + * <param name="cache.cachefile" value="mycache.properties" /> + * <param name="cache" value="propertyfiles" /> + * </custom> + * </pre> It was important first to set the cache and then to set + * the cache's configuration parameters. That results in the reorganized + * configure() method of ModifiedSelector. This testcase tests that. + */ + @Test + public void testCreatePropertiesCacheViaCustomSelector() { + File cachefile = FILE_UTILS.createTempFile("tmp-cache-", ".properties", null, false, false); + + // Configure the selector + + ExtendSelector s = new ExtendSelector(); + s.setClassname("org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector"); + s.addParam(createParam("update", "true")); + s.addParam(createParam("cache.cachefile", cachefile.getAbsolutePath())); + s.addParam(createParam("cache", "propertyfile")); + + selectorRule.selectionString(s); + + // evaluate correctness + assertTrue("Cache file is not created.", cachefile.exists()); + cachefile.delete(); + + } + + + @Test + @Ignore("same logic as on algorithm, no testcases created") + public void testCustomCache() { + // same logic as on algorithm, no testcases created + } + + + /** + * Test the interface semantic of Caches. + * This method does some common test for cache implementations. + * A cache must return a stored value and a valid iterator. + * After calling the delete() the cache must be empty. + * + * @param cache configured test object + */ + protected void doTest(Cache cache) { + assertTrue("Cache not proper configured.", cache.isValid()); + + String key1 = "key1"; + String value1 = "value1"; + String key2 = "key2"; + String value2 = "value2"; + + // given cache must be empty + Iterator it1 = cache.iterator(); + assertFalse("Cache is not empty", it1.hasNext()); + + // cache must return a stored value + cache.put(key1, value1); + cache.put(key2, value2); + assertEquals("cache returned wrong value", value1, cache.get(key1)); + assertEquals("cache returned wrong value", value2, cache.get(key2)); + + // test the iterator + Iterator it2 = cache.iterator(); + Object returned = it2.next(); + boolean ok = (key1.equals(returned) || key2.equals(returned)); + String msg = "Iterator returned unexpected value." + + " key1.equals(returned)="+key1.equals(returned) + + " key2.equals(returned)="+key2.equals(returned) + + " returned="+returned + + " ok="+ok; + assertTrue(msg, ok); + + // clear the cache + cache.delete(); + Iterator it3 = cache.iterator(); + assertFalse("Cache is not empty", it3.hasNext()); + } + + + // ============== testcases for the algorithm implementations ============== + + + @Test + public void testHashvalueAlgorithm() { + HashvalueAlgorithm algo = new HashvalueAlgorithm(); + doTest(algo); + } + + + @Test + public void testDigestAlgorithmMD5() { + DigestAlgorithm algo = new DigestAlgorithm(); + algo.setAlgorithm("MD5"); + doTest(algo); + } + + + @Test + public void testDigestAlgorithmSHA() { + DigestAlgorithm algo = new DigestAlgorithm(); + algo.setAlgorithm("SHA"); + doTest(algo); + } + + + @Test + public void testChecksumAlgorithm() { + ChecksumAlgorithm algo = new ChecksumAlgorithm(); + doTest(algo); + } + + + @Test + public void testChecksumAlgorithmCRC() { + ChecksumAlgorithm algo = new ChecksumAlgorithm(); + algo.setAlgorithm("CRC"); + doTest(algo); + } + + + @Test + public void testChecksumAlgorithmAdler() { + ChecksumAlgorithm algo = new ChecksumAlgorithm(); + algo.setAlgorithm("Adler"); + doTest(algo); + } + + + /** + * Test the interface semantic of Algorithms. + * This method does some common test for algorithm implementations. + * An algorithm must return always the same value for the same file and + * it must not return <i>null</i>. + * + * @param algo configured test object + */ + protected void doTest(Algorithm algo) { + assertTrue("Algorithm not proper configured.", algo.isValid()); + for (int i=0; i<selectorRule.getFiles().length; i++) { + File file = selectorRule.getFiles()[i]; // must not be a directory + if (file.isFile()) { + // get the Hashvalues + String hash1 = algo.getValue(file); + String hash2 = algo.getValue(file); + String hash3 = algo.getValue(file); + String hash4 = algo.getValue(file); + String hash5 = algo.getValue(new File(file.getAbsolutePath())); + + // Assert !=null and equality + assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash1); + assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash2); + assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash3); + assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash4); + assertNotNull("Hashvalue was null for "+file.getAbsolutePath(), hash5); + assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash2); + assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash3); + assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash4); + assertEquals("getHashvalue() returned different value for "+file.getAbsolutePath(), hash1, hash5); + }//if-isFile + }//for + + } + + + + // ============== testcases for the comparator implementations ============== + + + @Test + public void testEqualComparator() { + EqualComparator comp = new EqualComparator(); + doTest(comp); + } + + + @Test + public void testRuleComparator() { + RuleBasedCollator comp = (RuleBasedCollator)RuleBasedCollator.getInstance(); + doTest(comp); + } + + + @Test + public void testEqualComparatorViaSelector() { + ModifiedSelector s = new ModifiedSelector(); + ModifiedSelector.ComparatorName compName = new ModifiedSelector.ComparatorName(); + compName.setValue("equal"); + s.setComparator(compName); + try { + performTests(s, "TTTTTTTTTTTT"); + } finally { + s.getCache().delete(); + } + } + + + @Test + @Ignore("not yet supported see note in selector") + public void testRuleComparatorViaSelector() { + ModifiedSelector s = new ModifiedSelector(); + ModifiedSelector.ComparatorName compName = new ModifiedSelector.ComparatorName(); + compName.setValue("rule"); + s.setComparator(compName); + try { + performTests(s, "TTTTTTTTTTTT"); + } finally { + s.getCache().delete(); + } + } + + + @Test + @Ignore("same logic as on algorithm, no testcases created") + public void testCustomComparator() { + // same logic as on algorithm, no testcases created + } + + + @Test + public void testResourceSelectorSimple() { + BFT bft = new BFT(); + bft.doTarget("modifiedselectortest-ResourceSimple"); + bft.deleteCachefile(); + //new File("src/etc/testcases/types/resources/selectors/cache.properties").delete(); + } + + @Test + public void testResourceSelectorSelresTrue() { + BFT bft = new BFT(); + bft.doTarget("modifiedselectortest-ResourceSelresTrue"); + AntAssert.assertContains("does not provide an InputStream", bft.getLog()); + bft.deleteCachefile(); + } + + @Test + public void testResourceSelectorSelresFalse() { + BFT bft = new BFT(); + bft.doTarget("modifiedselectortest-ResourceSelresFalse"); + bft.deleteCachefile(); + } + + @Test + public void testResourceSelectorScenarioSimple() { + + Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home")); + BFT bft = new BFT(); + bft.doTarget("modifiedselectortest-scenario-resourceSimple"); + bft.doTarget("modifiedselectortest-scenario-clean"); + bft.deleteCachefile(); + } + + /** + * Test the interface semantic of Comparators. + * This method does some common test for comparator implementations. + * + * @param comp configured test object + */ + protected void doTest(Comparator comp) { + Object o1 = new String("string1"); + Object o2 = new String("string2"); + Object o3 = new String("string2"); // really "2" + + assertTrue("Comparator gave wrong value.", comp.compare(o1, o2) != 0); + assertTrue("Comparator gave wrong value.", comp.compare(o1, o3) != 0); + assertTrue("Comparator gave wrong value.", comp.compare(o2, o3) == 0); + } + + + // ===================== scenario tests ===================== + + + /** + * Tests whether the seldirs attribute is used. + */ + @Test + public void testSeldirs() { + ModifiedSelector s = new ModifiedSelector(); + StringBuffer sbTrue = new StringBuffer(); + StringBuffer sbFalse = new StringBuffer(); + for (int i=0; i<selectorRule.getFiles().length; i++) { + if (selectorRule.getFiles()[i].isDirectory()) { + sbTrue.append("T"); + sbFalse.append("F"); + } else { + sbTrue.append("T"); + sbFalse.append("T"); + } + } + + s.setSeldirs(true); + performTests(s, sbTrue.toString()); + s.getCache().delete(); + + s.setSeldirs(false); + performTests(s, sbFalse.toString()); + s.getCache().delete(); + + s.getCache().delete(); + } + + + /** + * Complex test scenario using default values (DigestAlgorithm with MD5, + * PropertiesfileCache with file=cache.properties, EqualComparator + * and update=true). <ol> + * <li> try fist time --> should select all </li> + * <li> try second time --> should select no files (only directories) </li> + * <li> modify timestamp of one file and content of a nother one </li> + * <li> try third time --> should select only the file with modified + * content </li> + */ + @Test + public void testScenario1() { + BFT bft = null; + ModifiedSelector s = null; + try { + + String results; + + // Configure the selector - only defaults are used + s = new ModifiedSelector(); + + // + // ***** First Run ***** + // the first call should get all files, because nothing is in + // the cache + // + performTests(s, "TTTTTTTTTTTT"); + + // + // ***** Second Run ***** + // the second call should get no files, because no content + // has changed + // + performTests(s, "TFFFFFFFFFFT"); + + // + // ***** make some files dirty ***** + // + + // these files are made dirty --> 3+4 with different content + String f2name = "tar/bz2/asf-logo-huge.tar.bz2"; + String f3name = "asf-logo.gif.md5"; + String f4name = "copy.filterset.filtered"; + + // AccessObject to the test-Ant-environment + bft = new BFT(); + // give some values (via property file) to that environment + bft.writeProperties("f2name="+f2name); + bft.writeProperties("f3name="+f3name); + bft.writeProperties("f4name="+f4name); + // call the target for making the files dirty + bft.doTarget("modifiedselectortest-makeDirty"); + + // + // ***** Third Run ***** + // third call should get only those files, which CONTENT changed + // (no timestamp changes required!) + results = selectorRule.selectionString(s); + + // + // ***** Check the result ***** + // + + // Mark all files which should be selected as (T)rue and all others + // as (F)alse. Directories are always selected so they always are + // (T)rue. + StringBuffer expected = new StringBuffer(); + for (int i=0; i<selectorRule.getFiles().length; i++) { + String ch = "F"; + if (selectorRule.getFiles()[i].isDirectory()) ch = "T"; + // f2name shouldn't be selected: only timestamp has changed! + if (selectorRule.getFilenames()[i].equalsIgnoreCase(f3name)) ch = "T"; + if (selectorRule.getFilenames()[i].equalsIgnoreCase(f4name)) ch = "T"; + expected.append(ch); + } + + assertEquals( + "Wrong files selected. Differing files: " // info text + + resolve(diff(expected.toString(), results)), // list of files + expected.toString(), // expected result + results // result + ); + + } finally { + // cleanup the environment + if (s!=null) s.getCache().delete(); + if (bft!=null) bft.deletePropertiesfile(); + } + } + + + /** + * This scenario is based on scenario 1, but does not use any + * default value and its based on <custom> selector. Used values are:<ul> + * <li><b>Cache: </b> Propertyfile, + * cachefile={java.io.tmpdir}/mycache.txt </li> + * <li><b>Algorithm: </b> Digest + * algorithm=SHA, Provider=null </li> + * <li><b>Comparator: </b> java.text.RuleBasedCollator + * <li><b>Update: </b> true </li> + */ + @Test + @Ignore("RuleBasedCollator not yet supported - see Selector:375 note") + public void testScenario2() { + ExtendSelector s = new ExtendSelector(); + BFT bft = new BFT(); + String cachefile = System.getProperty("java.io.tmpdir")+"/mycache.txt"; + try { + + s.setClassname("org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector"); + + s.addParam(createParam("cache.cachefile", cachefile)); + //s.addParam(createParam("algorithm.provider","---")); // i don't know any valid + s.addParam(createParam("cache","propertyfile")); + s.addParam(createParam("update","true")); + s.addParam(createParam("comparator","rule")); + s.addParam(createParam("algorithm.name","sha")); + s.addParam(createParam("algorithm","digest")); + + // first and second run + performTests(s, "TTTTTTTTTTTT"); + performTests(s, "TFFFFFFFFFFT"); + // make dirty + String f2name = "tar/bz2/asf-logo-huge.tar.bz2"; + String f3name = "asf-logo.gif.md5"; + String f4name = "copy.filterset.filtered"; + bft.writeProperties("f2name="+f2name); + bft.writeProperties("f3name="+f3name); + bft.writeProperties("f4name="+f4name); + bft.doTarget("modifiedselectortest-makeDirty"); + // third run + String results = selectorRule.selectionString(s); + StringBuffer expected = new StringBuffer(); + for (int i=0; i<selectorRule.getFilenames().length; i++) { + String ch = "F"; + if (selectorRule.getFiles()[i].isDirectory()) ch = "T"; + if (selectorRule.getFilenames()[i].equalsIgnoreCase(f3name)) ch = "T"; + if (selectorRule.getFilenames()[i].equalsIgnoreCase(f4name)) ch = "T"; + expected.append(ch); + } + assertEquals( + "Wrong files selected. Differing files: " // info text + + resolve(diff(expected.toString(), results)), // list of files + expected.toString(), // expected result + results // result + ); + } finally { + // cleanup the environment + (new java.io.File(cachefile)).delete(); + bft.deletePropertiesfile(); + } + } + + + @Test + public void testScenarioCoreSelectorDefaults() { + Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home") ); + doScenarioTest("modifiedselectortest-scenario-coreselector-defaults", "cache.properties"); + } + + + @Test + public void testScenarioCoreSelectorSettings() { + Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home") ); + doScenarioTest("modifiedselectortest-scenario-coreselector-settings", "core.cache.properties"); + } + + + @Test + public void testScenarioCustomSelectorSettings() { + Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home") ); + doScenarioTest("modifiedselectortest-scenario-customselector-settings", "core.cache.properties"); + } + + + public void doScenarioTest(String target, String cachefilename) { + BFT bft = new BFT(); + bft.setUp(); + File cachefile = new File(selectorRule.getProject().getBaseDir(), cachefilename); + try { + // do the actions + bft.doTarget("modifiedselectortest-scenario-clean"); + bft.doTarget(target); + + // the directories to check + File to1 = new File(selectorRule.getOutputDir(), "selectortest/to-1"); + File to2 = new File(selectorRule.getOutputDir(), "selectortest/to-2"); + File to3 = new File(selectorRule.getOutputDir(), "selectortest/to-3"); + + // do the checks + assertTrue("Cache file not created.", cachefile.exists()); + assertTrue("Not enough files copied on first time.", to1.list().length>5); + assertTrue("Too much files copied on second time.", to2.list().length==0); + assertTrue("Too much files copied on third time.", to3.list().length==2); + // don't catch the JUnit exceptions + } finally { + bft.doTarget("modifiedselectortest-scenario-clean"); + bft.deletePropertiesfile(); + bft.tearDown(); + cachefile.delete(); + } + } + + + // ===================== helper methods and classes ==================== + + + /** + * Creates a configured parameter object. + * @param name name of the parameter + * @param value value of the parameter + * @return the parameter object + */ + private Parameter createParam(String name, String value) { + Parameter p = new Parameter(); + p.setName(name); + p.setValue(value); + return p; + } + + + /** + * The BFT class wrapps the selector test-builfile inside an + * ant project. It supports target execution + * and property transfer to that project. + */ + private class BFT extends BuildFileRule { + String buildfile = "src/etc/testcases/types/selectors.xml"; + + String propfile = "ModifiedSelectorTest.properties"; + + boolean isConfigured = false; + + + public void setUp() { + super.configureProject(buildfile); + isConfigured = true; + } + + + /** + * This stub teardown is here because the outer class needs to call the + * tearDown method, and in the superclass it is protected. + */ + public void tearDown() { + super.after(); + + } + + public void doTarget(String target) { + if (!isConfigured) setUp(); + executeTarget(target); + } + + public String getProperty(String property) { + return super.getProject().getProperty(property); + } + + public void writeProperties(String line) { + if (!isConfigured) setUp(); + File dir = getProject().getBaseDir(); + File file = new File(dir, propfile); + try { + java.io.FileWriter out = + new java.io.FileWriter(file.getAbsolutePath(), true); + out.write(line); + out.write(System.getProperty("line.separator")); + out.flush(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + } + } + + public void deletePropertiesfile() { + if (!isConfigured) setUp(); + new File(getProject().getBaseDir(), propfile).delete(); + } + + public void deleteCachefile() { + File basedir = new File(buildfile).getParentFile(); + File cacheFile = new File(basedir, "cache.properties"); + cacheFile.delete(); + } + + }//class-BFT + + + /** + * MockProject wrappes a very small ant project (one target, one task) + * but provides public methods to fire the build events. + */ + private class MockProject extends Project { + private Task task; + private Target target; + + public MockProject() { + task = new Task(){ + public void execute() { + } + }; + task.setTaskName("testTask"); + target = new Target(); + target.setName("testTarget"); + target.setProject(this); + target.addTask(task); + task.setOwningTarget(target); + } + + public void fireBuildFinished() { + super.fireBuildFinished(null); + } + public void fireSubBuildFinished() { + super.fireSubBuildFinished(null); + } + public void fireTargetStarted() { + super.fireTargetStarted(target); + } + public void fireTargetFinished() { + super.fireTargetFinished(target, null); + } + public void fireTaskStarted() { + super.fireTaskStarted(task); + } + public void fireTaskFinished() { + super.fireTaskFinished(task, null); + } + }//class-MockProject + + + /** + * Does the selection test for a given selector and prints the + * filenames of the differing files (selected but shouldn't, + * not selected but should). + * @param selector The selector to test + * @param expected The expected result + */ + private void performTests(FileSelector selector, String expected) { + String result = selectorRule.selectionString(selector); + String diff = diff(expected, result); + String resolved = resolve(diff); + assertEquals("Differing files: " + resolved, result, expected); + } + /** + * Checks which files are selected and shouldn't be or which + * are not selected but should. + * @param expected String containing 'F's and 'T's + * @param result String containing 'F's and 'T's + * @return Difference as String containing '-' (equal) and + * 'X' (difference). + */ + private String diff(String expected, String result) { + int length1 = expected.length(); + int length2 = result.length(); + int min = (length1 > length2) ? length2 : length1; + StringBuffer sb = new StringBuffer(); + for (int i=0; i<min; i++) { + sb.append( + (expected.charAt(i) == result.charAt(i)) + ? "-" + : "X" + ); + } + return sb.toString(); + } + + /** + * Resolves a diff-String (@see diff()) against the (inherited) filenames- + * and files arrays. + * @param filelist Diff-String + * @return String containing the filenames for all differing files, + * separated with semicolons ';' + */ + private String resolve(String filelist) { + StringBuffer sb = new StringBuffer(); + int min = (selectorRule.getFilenames().length > filelist.length()) + ? filelist.length() + : selectorRule.getFilenames().length; + for (int i=0; i<min; i++) { + if ('X'==filelist.charAt(i)) { + sb.append(selectorRule.getFilenames()[i]); + sb.append(";"); + } + } + return sb.toString(); + } + + +}//class-ModifiedSelectorTest diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/PresentSelectorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/PresentSelectorTest.java new file mode 100644 index 00000000..e96a6758 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/PresentSelectorTest.java @@ -0,0 +1,137 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Mapper; +import org.junit.Rule; +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + + +/** + * Tests Present Selectors + * + */ +public class PresentSelectorTest { + + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + /** + * Test the code that validates the selector. + */ + @Test + public void testValidate() { + PresentSelector s = new PresentSelector(); + try { + s.createMapper(); + s.createMapper(); + fail("PresentSelector allowed more than one nested mapper."); + } catch (BuildException be1) { + assertEquals("Cannot define more than one mapper", + be1.getMessage()); + } + + s = new PresentSelector(); + try { + s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("PresentSelector did not check for required fields"); + } catch (BuildException be2) { + assertEquals("The targetdir attribute is required.", + be2.getMessage()); + } + + } + + /** + * Tests to make sure that the selector is selecting files correctly. + */ + @Test + public void testSelectionBehaviour() { + PresentSelector s; + String results; + Mapper m; + Mapper.MapperType identity = new Mapper.MapperType(); + identity.setValue("identity"); + Mapper.MapperType glob = new Mapper.MapperType(); + glob.setValue("glob"); + Mapper.MapperType merge = new Mapper.MapperType(); + merge.setValue("merge"); + Mapper.MapperType flatten = new Mapper.MapperType(); + flatten.setValue("flatten"); + + File beddir = selectorRule.getBeddir(); + + s = new PresentSelector(); + s.setTargetdir(beddir); + results = selectorRule.selectionString(s); + assertEquals("TTTTTTTTTTTT", results); + + s = new PresentSelector(); + s.setTargetdir(beddir); + m = s.createMapper(); + m.setType(identity); + results = selectorRule.selectionString(s); + assertEquals("TTTTTTTTTTTT", results); + + s = new PresentSelector(); + File subdir = new File(System.getProperty("root"), "src/etc/testcases/taskdefs/expected"); + s.setTargetdir(subdir); + m = s.createMapper(); + m.setType(flatten); + results = selectorRule.selectionString(s); + assertEquals("TTTTTTTTTTTF", results); + + s = new PresentSelector(); + s.setTargetdir(beddir); + m = s.createMapper(); + m.setType(merge); + m.setTo("asf-logo.gif.gz"); + results = selectorRule.selectionString(s); + assertEquals("TTTTTTTTTTTT", results); + + s = new PresentSelector(); + subdir = new File(beddir, "tar/bz2"); + s.setTargetdir(subdir); + m = s.createMapper(); + m.setType(glob); + m.setFrom("*.bz2"); + m.setTo("*.tar.bz2"); + results = selectorRule.selectionString(s); + assertEquals("FFTFFFFFFFFF", results); + + + s = new PresentSelector(); + subdir = new File(selectorRule.getOutputDir(), "selectortest2"); + s.setTargetdir(subdir); + results = selectorRule.selectionString(s); + assertEquals("TTTFFTTTTTTT", results); + results = selectorRule.selectionString(s); + assertEquals("TTTFFTTTTTTT", results); + + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/README b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/README new file mode 100644 index 00000000..eb48f6bb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/README @@ -0,0 +1,96 @@ +A DESCRIPTION OF THE SELECTOR TEST FRAMEWORK + +When writing tests for selectors, I found that I wanted to have some +standard way of working with a set of files and testing whether one or +another of them was selected. To that end, I created a base class called +BaseSelectorTest that does most of the heavy lifting. Of course, you can +test your selectors any way you want, but if you want to reuse this code, +read on. + +What BaseSelectorTest does is use an ant build file +"src/etc/testcases/types/selector.xml" to copy a tree of files out of +"src/etc/testcases/taskdefs/expected" into a "selectortest" directories. +Then it takes a list of 12 of the files and directories in this tree, and +applies whatever selector you pass in to each one. It passes back to your +test a 12 character long string indicating which of the 12 files and +directories was selected, using 'T' for selected and 'F' for not selected. +In the Test class for your selector, you override the getInstance() method +to create your own type of selector, and set the elements of your selector +a variety of ways to ensure that the string of T's and F's returned when +the selector is applied to those 12 files is correct. + +So, for example, DepthSelectorTest.java extends BaseSelectorTest and has +the following code: + + + public BaseSelector getInstance() { + return new DepthSelector(); + } + + + public void testSelectionBehaviour() { + DepthSelector s; + String results; + + + try { + makeBed(); + + + s = (DepthSelector)getInstance(); + s.setMin(20); + s.setMax(25); + results = selectionString(s); + assertEquals("FFFFFFFFFFFF", results); + + + s = (DepthSelector)getInstance(); + s.setMin(0); + results = selectionString(s); + assertEquals("TTTTTTTTTTTT", results); + + + s = (DepthSelector)getInstance(); + s.setMin(1); + results = selectionString(s); + assertEquals("FFFFFTTTTTTT", results); + + +The first test says that none of the 12 files or directories will match if +the depth range for the selector is between 20 and 25 (that would be one +deep directory tree!). The second says that all files and directories +match if the minimum depth is set to 0 and the maximum isn't specified. The +third test says that if the minumum depth is 1, the first 5 entries in the +list of 12 will not be selected and the rest will. + + +You can find the 12 files and directories that are tested for selection in +the BaseSelectorTest class. I used a fixed list so that if someone added +new files to the src/etc/testcases/types directory it wouldn't break my +tests: + + + protected String[] filenames = {".","asf-logo.gif.md5","asf- + logo.gif.bz2", + "asf-logo.gif.gz","copy.filterset.filtered","zip/asf- + logo.gif.zip", + "tar/asf-logo.gif.tar","tar/asf-logo-huge.tar.gz", + "tar/gz/asf-logo.gif.tar.gz","tar/bz2/asf-logo.gif.tar.bz2", + "tar/bz2/asf-logo-huge.tar.bz2","tar/bz2"}; + + +If you wish to use this set of files and directories to test your selector, +you can reuse the BaseSelectorTest with no change to it. + +You may find you need to alter the build file so that you get some +variation in the files that your selector can work with. Most of the core +selectors have required that kind of modification. If you do that, make +sure that it doesn't alter the output strings on the other selector test, +or if it does that you update their expected return results. + +You may also want to alter the set of files you look at in a particular +selector test. Since the filelist in BaseSelectorTest is protected, you +should be able to override it as you need to. Or you can alter the fileset +in BaseSelectorTest itself, provided you update the test strings in all the +other unit tests. + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/SignedSelectorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/SignedSelectorTest.java new file mode 100644 index 00000000..1eb40dc4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/SignedSelectorTest.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; + +/** + * Testcase for the <signedselector> selector. + * + */ +public class SignedSelectorTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/selectors/signedselector.xml"); + } + + @Test + public void testSelectSigned() { + buildRule.executeTarget("selectsigned"); + } + + @Test + public void testNotSelected() { + buildRule.executeTarget("notselected"); + } + + @Test + public void testName() { + buildRule.executeTarget("name"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/SizeSelectorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/SizeSelectorTest.java new file mode 100644 index 00000000..0e543f1c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/SizeSelectorTest.java @@ -0,0 +1,237 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import java.util.Locale; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.types.Parameter; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Tests Size Selectors + * + */ +public class SizeSelectorTest { + + @Rule + public final BaseSelectorRule selectorRule = new BaseSelectorRule(); + + /** + * Test the code that validates the selector. + */ + @Test + public void testValidate() { + SizeSelector s = new SizeSelector(); + try { + s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("SizeSelector did not check for required fields"); + } catch (BuildException be1) { + assertEquals("The value attribute is required, and must " + + "be positive", be1.getMessage()); + } + + s = new SizeSelector(); + s.setValue(-10); + try { + s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("SizeSelector did not check for value being in the " + + "allowable range"); + } catch (BuildException be2) { + assertEquals("The value attribute is required, and must " + + "be positive", be2.getMessage()); + } + + s = new SizeSelector(); + Parameter param = new Parameter(); + param.setName("garbage in"); + param.setValue("garbage out"); + Parameter[] params = {param}; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("SizeSelector did not check for valid parameter element"); + } catch (BuildException be3) { + assertEquals("Invalid parameter garbage in", be3.getMessage()); + } + + s = new SizeSelector(); + param = new Parameter(); + param.setName("value"); + param.setValue("garbage out"); + params[0] = param; + s.setParameters(params); + try { + s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("SizeSelector accepted bad value as parameter"); + } catch (BuildException be4) { + assertEquals("Invalid size setting garbage out", + be4.getMessage()); + } + + s = new SizeSelector(); + Parameter param1 = new Parameter(); + Parameter param2 = new Parameter(); + param1.setName("value"); + param1.setValue("5"); + param2.setName("units"); + param2.setValue("garbage out"); + params = new Parameter[2]; + params[0] = param1; + params[1] = param2; + try { + s.setParameters(params); + s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]); + fail("SizeSelector accepted bad units as parameter"); + } catch (BuildException be5) { + assertEquals("garbage out is not a legal value for this attribute", + be5.getMessage()); + } + + } + + /** + * Tests to make sure that the selector is selecting files correctly. + */ + @Test + public void testSelectionBehaviour() { + SizeSelector s; + String results; + + SizeSelector.ByteUnits kilo = new SizeSelector.ByteUnits(); + kilo.setValue("K"); + SizeSelector.ByteUnits kibi = new SizeSelector.ByteUnits(); + kibi.setValue("Ki"); + SizeSelector.ByteUnits tibi = new SizeSelector.ByteUnits(); + tibi.setValue("Ti"); + SizeSelector.SizeComparisons less = new SizeSelector.SizeComparisons(); + less.setValue("less"); + SizeSelector.SizeComparisons equal = new SizeSelector.SizeComparisons(); + equal.setValue("equal"); + SizeSelector.SizeComparisons more = new SizeSelector.SizeComparisons(); + more.setValue("more"); + + + + s = new SizeSelector(); + s.setValue(10); + s.setWhen(less); + results = selectorRule.selectionString(s); + assertEquals("TFFFFFFFFFFT", results); + + s = new SizeSelector(); + s.setValue(10); + s.setWhen(more); + results = selectorRule.selectionString(s); + assertEquals("TTTTTTTTTTTT", results); + + s = new SizeSelector(); + s.setValue(32); + s.setWhen(equal); + results = selectorRule.selectionString(s); + assertEquals("TFFFTFFFFFFT", results); + + s = new SizeSelector(); + s.setValue(7); + s.setWhen(more); + s.setUnits(kilo); + results = selectorRule.selectionString(s); + assertEquals("TFTFFTTTTTTT", results); + + s = new SizeSelector(); + s.setValue(7); + s.setWhen(more); + s.setUnits(kibi); + results = selectorRule.selectionString(s); + assertEquals("TFTFFFTTFTTT", results); + + s = new SizeSelector(); + s.setValue(99999); + s.setWhen(more); + s.setUnits(tibi); + results = selectorRule.selectionString(s); + assertEquals("TFFFFFFFFFFT", results); + + s = new SizeSelector(); + Parameter param1 = new Parameter(); + Parameter param2 = new Parameter(); + Parameter param3 = new Parameter(); + param1.setName("value"); + param1.setValue("20"); + param2.setName("units"); + param2.setValue("Ki"); + param3.setName("when"); + param3.setValue("more"); + Parameter[] params = {param1,param2,param3}; + s.setParameters(params); + results = selectorRule.selectionString(s); + assertEquals("TFFFFFFTFFTT", results); + + + } + + @Test + public void testParameterParsingLowerCase() { + testCaseInsensitiveParameterParsing("units"); + } + + @Test + public void testParameterParsingUpperCase() { + testCaseInsensitiveParameterParsing("UNITS"); + } + + @Test + public void testParameterParsingLowerCaseTurkish() { + Locale l = Locale.getDefault(); + try { + Locale.setDefault(new Locale("tr")); + testCaseInsensitiveParameterParsing("units"); + } finally { + Locale.setDefault(l); + } + } + + @Test + public void testParameterParsingUpperCaseTurkish() { + Locale l = Locale.getDefault(); + try { + Locale.setDefault(new Locale("tr")); + testCaseInsensitiveParameterParsing("UNITS"); + } finally { + Locale.setDefault(l); + } + } + + private void testCaseInsensitiveParameterParsing(String name) { + SizeSelector s = new SizeSelector(); + Parameter p = new Parameter(); + p.setName(name); + p.setValue("foo"); + try { + s.setParameters(new Parameter[] {p}); + fail("should have caused an exception"); + } catch (BuildException be) { + assertEquals("foo is not a legal value for this attribute", + be.getMessage()); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/TokenizedPatternTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/TokenizedPatternTest.java new file mode 100644 index 00000000..06e86bd9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/TokenizedPatternTest.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import java.io.File; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class TokenizedPatternTest { + private static final String DOT_SVN_PATTERN = + SelectorUtils.DEEP_TREE_MATCH + File.separator + ".svn" + + File.separator + SelectorUtils.DEEP_TREE_MATCH; + + @Test + public void testTokenization() { + TokenizedPattern pat = new TokenizedPattern(DOT_SVN_PATTERN); + assertEquals(3, pat.depth()); + assertEquals(DOT_SVN_PATTERN, pat.getPattern()); + assertTrue(pat.containsPattern(SelectorUtils.DEEP_TREE_MATCH)); + assertTrue(pat.containsPattern(".svn")); + } + + @Test + public void testEndsWith() { + assertTrue(new TokenizedPattern(DOT_SVN_PATTERN) + .endsWith(SelectorUtils.DEEP_TREE_MATCH)); + } + + @Test + public void testWithoutLastToken() { + assertEquals(SelectorUtils.DEEP_TREE_MATCH + File.separatorChar + + ".svn" + File.separator, + new TokenizedPattern(DOT_SVN_PATTERN) + .withoutLastToken().getPattern()); + } + + @Test + public void testMatchPath() { + File f = new File(".svn"); + TokenizedPath p = new TokenizedPath(f.getAbsolutePath()); + assertTrue(new TokenizedPattern(DOT_SVN_PATTERN).matchPath(p, true)); + assertTrue(new TokenizedPattern(DOT_SVN_PATTERN) + .withoutLastToken().matchPath(p, true)); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java new file mode 100644 index 00000000..2973d2b4 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.types.selectors; + +import org.apache.tools.ant.BuildException; +import org.junit.Rule; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Tests Type Selectors. + * + */ +public class TypeSelectorTest { + + @Rule + public BaseSelectorRule selectorRule = new BaseSelectorRule(); + + + /** + * Test the code that validates the selector. + */ + @Test + public void testValidate() { + TypeSelector s = new TypeSelector(); + try { + s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0] ,selectorRule.getFiles()[0]); + fail("TypeSelector did not check for required fields"); + } catch (BuildException be1) { + assertEquals("The type attribute is required" + , be1.getMessage()); + } + } + + /** + * Tests to make sure that the selector is selecting files correctly. + */ + @Test + public void testSelectionBehaviour() { + TypeSelector s; + String results; + + TypeSelector.FileType directory = new TypeSelector.FileType(); + directory.setValue("dir"); + TypeSelector.FileType file = new TypeSelector.FileType(); + file.setValue("file"); + + + + s = new TypeSelector(); + s.setType(directory); + results = selectorRule.selectionString(s); + assertEquals("TFFFFFFFFFFT", results); + + s = new TypeSelector(); + s.setType(file); + results = selectorRule.selectionString(s); + assertEquals("FTTTTTTTTTTF", results); + + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java new file mode 100644 index 00000000..48a4cbd7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * TestCase for Base64Converter. + * + */ +public class Base64ConverterTest { + + @Test + public void testOneValue() { + byte[] mybytes = {0, 0, (byte)0xFF}; + Base64Converter base64Converter = new Base64Converter(); + assertEquals("AAD/",base64Converter.encode(mybytes)); + } + + @Test + public void testHelloWorld() { + byte[] mybytes = "Hello World".getBytes(); + Base64Converter base64Converter = new Base64Converter(); + assertEquals("SGVsbG8gV29ybGQ=", base64Converter.encode(mybytes)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java new file mode 100644 index 00000000..3cffa100 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.io.IOException; +import java.util.Enumeration; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Project; +import org.apache.tools.ant.types.Path; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + + +/** + * Test case for ClasspathUtils + * + */ +public class ClasspathUtilsTest { + + private Project p; + + @Before + public void setUp() { + p = new Project(); + p.init(); + } + + + @Test + public void testOnlyOneInstance() { + Enumeration enumeration; + String list = ""; + ClassLoader c = ClasspathUtils.getUniqueClassLoaderForPath(p, (Path) null, false); + try { + enumeration = c.getResources( + "org/apache/tools/ant/taskdefs/defaults.properties"); + } catch (IOException e) { + throw new BuildException( + "Could not get the defaults.properties resource", e); + } + int count = 0; + while (enumeration.hasMoreElements()) { + list = list + " " + enumeration.nextElement(); + count++; + } + assertTrue("Should be only one and not " + count + " " + list, count == 1); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/CollectionUtilsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/CollectionUtilsTest.java new file mode 100644 index 00000000..425dc471 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/CollectionUtilsTest.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.util.Hashtable; +import java.util.Properties; +import java.util.Stack; +import java.util.Vector; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * Tests for org.apache.tools.ant.util.CollectionUtils. + * + */ +public class CollectionUtilsTest { + + + @Test + public void testVectorEquals() { + assertTrue(!CollectionUtils.equals(null, new Vector())); + assertTrue(!CollectionUtils.equals(new Vector(), null)); + assertTrue(CollectionUtils.equals(new Vector(), new Vector())); + Vector v1 = new Vector(); + Stack s2 = new Stack(); + v1.addElement("foo"); + s2.push("foo"); + assertTrue(CollectionUtils.equals(v1, s2)); + assertTrue(CollectionUtils.equals(s2, v1)); + v1.addElement("bar"); + assertTrue(!CollectionUtils.equals(v1, s2)); + assertTrue(!CollectionUtils.equals(s2, v1)); + s2.push("bar"); + assertTrue(CollectionUtils.equals(v1, s2)); + assertTrue(CollectionUtils.equals(s2, v1)); + s2.push("baz"); + assertTrue(!CollectionUtils.equals(v1, s2)); + assertTrue(!CollectionUtils.equals(s2, v1)); + v1.addElement("baz"); + assertTrue(CollectionUtils.equals(v1, s2)); + assertTrue(CollectionUtils.equals(s2, v1)); + v1.addElement("zyzzy"); + s2.push("zyzzy2"); + assertTrue(!CollectionUtils.equals(v1, s2)); + assertTrue(!CollectionUtils.equals(s2, v1)); + } + + @Test + public void testDictionaryEquals() { + assertTrue(!CollectionUtils.equals(null, new Hashtable())); + assertTrue(!CollectionUtils.equals(new Hashtable(), null)); + assertTrue(CollectionUtils.equals(new Hashtable(), new Properties())); + Hashtable h1 = new Hashtable(); + Properties p2 = new Properties(); + h1.put("foo", ""); + p2.put("foo", ""); + assertTrue(CollectionUtils.equals(h1, p2)); + assertTrue(CollectionUtils.equals(p2, h1)); + h1.put("bar", ""); + assertTrue(!CollectionUtils.equals(h1, p2)); + assertTrue(!CollectionUtils.equals(p2, h1)); + p2.put("bar", ""); + assertTrue(CollectionUtils.equals(h1, p2)); + assertTrue(CollectionUtils.equals(p2, h1)); + p2.put("baz", ""); + assertTrue(!CollectionUtils.equals(h1, p2)); + assertTrue(!CollectionUtils.equals(p2, h1)); + h1.put("baz", ""); + assertTrue(CollectionUtils.equals(h1, p2)); + assertTrue(CollectionUtils.equals(p2, h1)); + h1.put("zyzzy", ""); + p2.put("zyzzy2", ""); + assertTrue(!CollectionUtils.equals(h1, p2)); + assertTrue(!CollectionUtils.equals(p2, h1)); + p2.put("zyzzy", ""); + h1.put("zyzzy2", ""); + assertTrue(CollectionUtils.equals(h1, p2)); + assertTrue(CollectionUtils.equals(p2, h1)); + h1.put("dada", "1"); + p2.put("dada", "2"); + assertTrue(!CollectionUtils.equals(h1, p2)); + assertTrue(!CollectionUtils.equals(p2, h1)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java new file mode 100644 index 00000000..fe09ce93 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java @@ -0,0 +1,305 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; + +import java.io.IOException; +import java.io.StringWriter; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * Tests for org.apache.tools.ant.util.DOMElementWriter. + * + */ +public class DOMElementWriterTest { + + private DOMElementWriter w = new DOMElementWriter(); + + @Test + public void testIsReference() { + assertTrue("", w.isReference("")); + assertTrue(" ", w.isReference(" ")); + assertTrue(" ", w.isReference(" ")); + assertTrue("&#A0;", !w.isReference("&#A0;")); + assertTrue("20;", !w.isReference("20;")); + assertTrue("", !w.isReference("")); + assertTrue(""", w.isReference(""")); + assertTrue("'", w.isReference("'")); + assertTrue(">", w.isReference(">")); + assertTrue("<", w.isReference("<")); + assertTrue("&", w.isReference("&")); + } + + @Test + public void testEncode() { + assertEquals("&#20;", w.encode("")); + assertEquals("&#x20;", w.encode(" ")); + assertEquals("&#xA0;", w.encode(" ")); + assertEquals("&#A0;", w.encode("&#A0;")); + assertEquals("20;", w.encode("20;")); + assertEquals("&#20", w.encode("")); + assertEquals("&quot;", w.encode(""")); + assertEquals("&apos;", w.encode("'")); + assertEquals("&gt;", w.encode(">")); + assertEquals("&lt;", w.encode("<")); + assertEquals("&amp;", w.encode("&")); + assertEquals(""", w.encode("\"")); + assertEquals("<", w.encode("<")); + assertEquals("&", w.encode("&")); + assertEquals("", w.encode("\u0017")); + assertEquals("\r\n\t", w.encode("\r\n\t")); + } + + @Test + public void testEncodeAttributeValue() { + assertEquals("&#20;", w.encodeAttributeValue("")); + assertEquals("&#x20;", w.encodeAttributeValue(" ")); + assertEquals("&#xA0;", w.encodeAttributeValue(" ")); + assertEquals("&#A0;", w.encodeAttributeValue("&#A0;")); + assertEquals("20;", w.encodeAttributeValue("20;")); + assertEquals("&#20", w.encodeAttributeValue("")); + assertEquals("&quot;", w.encodeAttributeValue(""")); + assertEquals("&apos;", w.encodeAttributeValue("'")); + assertEquals("&gt;", w.encodeAttributeValue(">")); + assertEquals("&lt;", w.encodeAttributeValue("<")); + assertEquals("&amp;", w.encodeAttributeValue("&")); + assertEquals(""", w.encodeAttributeValue("\"")); + assertEquals("<", w.encodeAttributeValue("<")); + assertEquals("&", w.encodeAttributeValue("&")); + assertEquals("", w.encodeAttributeValue("\u0017")); + assertEquals("
	", w.encodeAttributeValue("\r\n\t")); + } + + @Test + public void testAttributeWithWhitespace() throws IOException { + Document d = DOMUtils.newDocument(); + Element root = d.createElement("root"); + root.setAttribute("foo", "bar\nbaz"); + StringWriter sw = new StringWriter(); + DOMElementWriter w = new DOMElementWriter(); + w.write(root, sw, 0, " "); + assertEquals("<root foo=\"bar
baz\" />" + StringUtils.LINE_SEP, + sw.toString()); + } + + @Test + public void testEncodeData() { + assertEquals("\"20;&", w.encodedata("\"20;&")); + assertEquals("", w.encodedata("\u0017")); + } + + @Test + public void testIsLegalCharacter() { + assertTrue("0x00", !w.isLegalCharacter('\u0000')); + assertTrue("0x09", w.isLegalCharacter('\t')); + assertTrue("0x0A", w.isLegalCharacter('\n')); + assertTrue("0x0C", w.isLegalCharacter('\r')); + assertTrue("0x1F", !w.isLegalCharacter('\u001F')); + assertTrue("0x20", w.isLegalCharacter('\u0020')); + assertTrue("0xD7FF", w.isLegalCharacter('\uD7FF')); + assertTrue("0xD800", !w.isLegalCharacter('\uD800')); + assertTrue("0xDFFF", !w.isLegalCharacter('\uDFFF')); + assertTrue("0xE000", w.isLegalCharacter('\uE000')); + assertTrue("0xFFFD", w.isLegalCharacter('\uFFFD')); + assertTrue("0xFFFE", !w.isLegalCharacter('\uFFFE')); + } + + @Test + public void testCDATAEndEncoding() { + assertEquals("]>", w.encodedata("]>")); + assertEquals("]]", w.encodedata("]]")); + assertEquals("]]]]><![CDATA[>", w.encodedata("]]>")); + assertEquals("]]]]><![CDATA[>A", w.encodedata("]]>A")); + assertEquals("A]]]]><![CDATA[>", w.encodedata("A]]>")); + assertEquals("A]]]]><![CDATA[>A", w.encodedata("A]]>A")); + assertEquals("A]]]]><![CDATA[>B]]]]><![CDATA[>C", + w.encodedata("A]]>B]]>C")); + } + + @Test + public void testNoAdditionalWhiteSpaceForText() throws IOException { + Document d = DOMUtils.newDocument(); + Element root = d.createElement("root"); + DOMUtils.appendTextElement(root, "textElement", "content"); + + StringWriter sw = new StringWriter(); + DOMElementWriter w = new DOMElementWriter(); + w.write(root, sw, 0, " "); + assertEquals("<root>" + StringUtils.LINE_SEP + + " <textElement>content</textElement>" + + StringUtils.LINE_SEP + + "</root>" + StringUtils.LINE_SEP, + sw.toString()); + } + + @Test + public void testNoAdditionalWhiteSpaceForCDATA() throws IOException { + Document d = DOMUtils.newDocument(); + Element root = d.createElement("root"); + DOMUtils.appendCDATAElement(root, "cdataElement", "content"); + + StringWriter sw = new StringWriter(); + DOMElementWriter w = new DOMElementWriter(); + w.write(root, sw, 0, " "); + assertEquals("<root>" + StringUtils.LINE_SEP + + " <cdataElement><![CDATA[content]]></cdataElement>" + + StringUtils.LINE_SEP + + "</root>" + StringUtils.LINE_SEP, + sw.toString()); + } + + @Test + public void testNoAdditionalWhiteSpaceForEmptyElement() throws IOException { + Document d = DOMUtils.newDocument(); + Element root = d.createElement("root"); + DOMUtils.createChildElement(root, "emptyElement"); + + StringWriter sw = new StringWriter(); + DOMElementWriter w = new DOMElementWriter(); + w.write(root, sw, 0, " "); + assertEquals("<root>" + StringUtils.LINE_SEP + // + " <emptyElement></emptyElement>" + + " <emptyElement />" + + StringUtils.LINE_SEP + + "</root>" + StringUtils.LINE_SEP, + sw.toString()); + } + + @Test + public void testNoNSPrefixByDefault() throws IOException { + Document d = DOMUtils.newDocument(); + Element root = d.createElementNS("urn:foo", "root"); + root.setAttributeNS("urn:foo2", "bar", "baz"); + + StringWriter sw = new StringWriter(); + DOMElementWriter w = new DOMElementWriter(); + w.write(root, sw, 0, " "); + assertEquals("<root bar=\"baz\" />" + + StringUtils.LINE_SEP, sw.toString()); + } + + @Test + public void testNSOnElement() throws IOException { + Document d = DOMUtils.newDocument(); + Element root = d.createElementNS("urn:foo", "root"); + root.setAttributeNS("urn:foo2", "bar", "baz"); + + StringWriter sw = new StringWriter(); + DOMElementWriter w = + new DOMElementWriter(false, + DOMElementWriter.XmlNamespacePolicy + .ONLY_QUALIFY_ELEMENTS); + w.write(root, sw, 0, " "); + assertEquals("<root bar=\"baz\" xmlns=\"urn:foo\" />" + + StringUtils.LINE_SEP, sw.toString()); + } + + @Test + public void testNSPrefixOnAttribute() throws IOException { + Document d = DOMUtils.newDocument(); + Element root = d.createElementNS("urn:foo", "root"); + root.setAttributeNS("urn:foo2", "bar", "baz"); + + StringWriter sw = new StringWriter(); + DOMElementWriter w = + new DOMElementWriter(false, + DOMElementWriter.XmlNamespacePolicy + .QUALIFY_ALL); + w.write(root, sw, 0, " "); + assertEquals("<root ns0:bar=\"baz\" xmlns=\"urn:foo\"" + + " xmlns:ns0=\"urn:foo2\" />" + + StringUtils.LINE_SEP, sw.toString()); + } + + @Test + public void testNSPrefixOnAttributeEvenWithoutElement() throws IOException { + Document d = DOMUtils.newDocument(); + Element root = d.createElementNS("urn:foo", "root"); + root.setAttributeNS("urn:foo2", "bar", "baz"); + + StringWriter sw = new StringWriter(); + DOMElementWriter w = + new DOMElementWriter(false, + new DOMElementWriter.XmlNamespacePolicy(false, + true) + ); + w.write(root, sw, 0, " "); + assertEquals("<root ns0:bar=\"baz\" xmlns:ns0=\"urn:foo2\" />" + + StringUtils.LINE_SEP, sw.toString()); + } + + @Test + public void testNSGetsReused() throws IOException { + Document d = DOMUtils.newDocument(); + Element root = d.createElementNS("urn:foo", "root"); + Element child = d.createElementNS("urn:foo", "child"); + root.appendChild(child); + StringWriter sw = new StringWriter(); + DOMElementWriter w = + new DOMElementWriter(false, + DOMElementWriter.XmlNamespacePolicy + .ONLY_QUALIFY_ELEMENTS); + w.write(root, sw, 0, " "); + assertEquals("<root xmlns=\"urn:foo\">" + + StringUtils.LINE_SEP + + " <child />" + + StringUtils.LINE_SEP + + "</root>" + + StringUtils.LINE_SEP, sw.toString()); + } + + @Test + public void testNSGoesOutOfScope() throws IOException { + Document d = DOMUtils.newDocument(); + Element root = d.createElementNS("urn:foo", "root"); + Element child = d.createElementNS("urn:foo2", "child"); + root.appendChild(child); + Element child2 = d.createElementNS("urn:foo2", "child"); + root.appendChild(child2); + Element grandChild = d.createElementNS("urn:foo2", "grandchild"); + child2.appendChild(grandChild); + Element child3 = d.createElementNS("urn:foo2", "child"); + root.appendChild(child3); + StringWriter sw = new StringWriter(); + DOMElementWriter w = + new DOMElementWriter(false, + DOMElementWriter.XmlNamespacePolicy + .ONLY_QUALIFY_ELEMENTS); + w.write(root, sw, 0, " "); + assertEquals("<root xmlns=\"urn:foo\">" + + StringUtils.LINE_SEP + + " <ns0:child xmlns:ns0=\"urn:foo2\" />" + + StringUtils.LINE_SEP + + " <ns1:child xmlns:ns1=\"urn:foo2\">" + + StringUtils.LINE_SEP + + " <ns1:grandchild />" + + StringUtils.LINE_SEP + + " </ns1:child>" + + StringUtils.LINE_SEP + + " <ns2:child xmlns:ns2=\"urn:foo2\" />" + + StringUtils.LINE_SEP + + "</root>" + + StringUtils.LINE_SEP, sw.toString()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/DateUtilsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/DateUtilsTest.java new file mode 100644 index 00000000..4f5aa844 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/DateUtilsTest.java @@ -0,0 +1,106 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.util.Calendar; +import java.util.TimeZone; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * TestCase for DateUtils. + * + */ +public class DateUtilsTest { + + + @Test + public void testElapsedTime(){ + String text = DateUtils.formatElapsedTime(50*1000); + assertEquals("50 seconds", text); + text = DateUtils.formatElapsedTime(65*1000); + assertEquals("1 minute 5 seconds", text); + text = DateUtils.formatElapsedTime(120*1000); + assertEquals("2 minutes 0 seconds", text); + text = DateUtils.formatElapsedTime(121*1000); + assertEquals("2 minutes 1 second", text); + } + + // https://issues.apache.org/bugzilla/show_bug.cgi?id=44659 + @Test + public void testLongElapsedTime(){ + assertEquals("2926 minutes 13 seconds", + DateUtils.formatElapsedTime(1000 * 175573)); + assertEquals("153722867280912 minutes 55 seconds", + DateUtils.formatElapsedTime(Long.MAX_VALUE)); + } + + @Test + public void testDateTimeISO(){ + TimeZone timeZone = TimeZone.getTimeZone("GMT+1"); + Calendar cal = Calendar.getInstance(timeZone); + cal.set(2002,1,23,10,11,12); + String text = DateUtils.format(cal.getTime(), + DateUtils.ISO8601_DATETIME_PATTERN); + assertEquals("2002-02-23T09:11:12", text); + } + + @Test + public void testDateISO(){ + TimeZone timeZone = TimeZone.getTimeZone("GMT"); + Calendar cal = Calendar.getInstance(timeZone); + cal.set(2002,1,23); + String text = DateUtils.format(cal.getTime(), + DateUtils.ISO8601_DATE_PATTERN); + assertEquals("2002-02-23", text); + } + + @Test + public void testTimeISODate(){ + // make sure that elapsed time in set via date works + TimeZone timeZone = TimeZone.getTimeZone("GMT+1"); + Calendar cal = Calendar.getInstance(timeZone); + cal.set(2002,1,23, 21, 11, 12); + String text = DateUtils.format(cal.getTime(), + DateUtils.ISO8601_TIME_PATTERN); + assertEquals("20:11:12", text); + } + + @Test + public void testTimeISO(){ + // make sure that elapsed time in ms works + long ms = (20*3600 + 11*60 + 12)*1000; + String text = DateUtils.format(ms, + DateUtils.ISO8601_TIME_PATTERN); + assertEquals("20:11:12", text); + } + + @Test + public void testPhaseOfMoon() { + TimeZone timeZone = TimeZone.getTimeZone("GMT"); + Calendar cal = Calendar.getInstance(timeZone); + // should be full moon + cal.set(2002, 2, 27); + assertEquals(4, DateUtils.getPhaseOfMoon(cal)); + // should be new moon + cal.set(2002, 2, 12); + assertEquals(0, DateUtils.getPhaseOfMoon(cal)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java new file mode 100644 index 00000000..bcda609b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import org.junit.Test; + +@SuppressWarnings("ResultOfObjectAllocationIgnored") +public class DeweyDecimalTest { + + @Test public void parse() { + assertEquals("1.2.3", new DeweyDecimal("1.2.3").toString()); + } + + @Test(expected=NumberFormatException.class) public void misparseEmpty() { + new DeweyDecimal("1..2"); + } + + @Test(expected=NumberFormatException.class) public void misparseNonNumeric() { + new DeweyDecimal("1.2.3-beta-5"); + } + + @Test(expected=NumberFormatException.class) public void misparseFinalDot() { + new DeweyDecimal("1.2."); + } + + // TODO initial dots, empty string, null, negative numbers, ... + + @Test public void testHashCode() { + assertEquals(new DeweyDecimal("1.2.3").hashCode(), new DeweyDecimal("1.2.3").hashCode()); + } + + @Test public void testEquals() { + assertTrue(new DeweyDecimal("1.2.3").equals(new DeweyDecimal("1.2.3"))); + assertFalse(new DeweyDecimal("1.2.3").equals(new DeweyDecimal("1.2.4"))); + assertTrue(new DeweyDecimal("1.2.0").equals(new DeweyDecimal("1.2"))); + assertTrue(new DeweyDecimal("1.2").equals(new DeweyDecimal("1.2.0"))); + } + + @Test public void compareTo() { + assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2")) > 0); + assertTrue(new DeweyDecimal("1.2").compareTo(new DeweyDecimal("1.2.3")) < 0); + assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2.3")) == 0); + assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.1.4")) > 0); + assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2.2.9")) > 0); + assertTrue(new DeweyDecimal("1.2.0").compareTo(new DeweyDecimal("1.2")) == 0); + assertTrue(new DeweyDecimal("1.2").compareTo(new DeweyDecimal("1.2.0")) == 0); + } + + // TODO isGreaterThan, ... + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java new file mode 100644 index 00000000..d0361cc5 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java @@ -0,0 +1,625 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.condition.Os; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.junit.Assume.assumeTrue; + +/** + * Tests for org.apache.tools.ant.util.FileUtils. + * + */ +public class FileUtilsTest { + + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + private File removeThis; + private String root; + + + @Before + public void setUp() { + // Windows adds the drive letter in uppercase, unless you run Cygwin + root = new File(File.separator).getAbsolutePath().toUpperCase(); + } + + @After + public void tearDown() { + if (removeThis != null && removeThis.exists()) { + if (!removeThis.delete()) + { + removeThis.deleteOnExit(); + } + } + } + + /** + * test modification. + * Since Ant1.7, the method being tested no longer uses + * reflection to provide backwards support to Java1.1, so this + * test is not so critical. But it does explore file system + * behaviour and will help catch any regression in Java itself, + * so is worth retaining. + * @see FileUtils#setFileLastModified(java.io.File, long) + * @throws IOException + */ + @Test + public void testSetLastModified() throws IOException { + removeThis = new File("dummy"); + FileOutputStream fos = new FileOutputStream(removeThis); + fos.write(new byte[0]); + fos.close(); + assumeTrue("Could not change file modified time", removeThis.setLastModified(removeThis.lastModified() - 2000)); + long modTime = removeThis.lastModified(); + assertTrue(modTime != 0); + + + FILE_UTILS.setFileLastModified(removeThis, -1); + long secondModTime = removeThis.lastModified(); + assertTrue(secondModTime > modTime); + + // number of milliseconds in a day + final int millisperday=24 * 3600 * 1000; + // in a previous version, the date of the file was set to 123456 + // milliseconds since 01.01.1970 + // it did not work on a computer running JDK 1.4.1_02 + Windows 2000 + FILE_UTILS.setFileLastModified(removeThis, secondModTime + millisperday); + long thirdModTime = removeThis.lastModified(); + /* + * I would love to compare this with 123456, but depending on + * the filesystems granularity it can take an arbitrary value. + * + * Just assert the time has changed. + */ + assertTrue(thirdModTime != secondModTime); + } + + @Test + public void testResolveFile() { + if (!(Os.isFamily("dos") || Os.isFamily("netware"))) { + /* + * Start with simple absolute file names. + */ + assertEquals(File.separator, + FILE_UTILS.resolveFile(null, "/").getPath()); + assertEquals(File.separator, + FILE_UTILS.resolveFile(null, "\\").getPath()); + } else { + assertEqualsIgnoreDriveCase(localize(File.separator), + FILE_UTILS.resolveFile(null, "/").getPath()); + assertEqualsIgnoreDriveCase(localize(File.separator), + FILE_UTILS.resolveFile(null, "\\").getPath()); + /* + * throw in drive letters + */ + String driveSpec = "C:"; + assertEquals(driveSpec + "\\", + FILE_UTILS.resolveFile(null, driveSpec + "/").getPath()); + assertEquals(driveSpec + "\\", + FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath()); + String driveSpecLower = "c:"; + assertEquals(driveSpecLower + "\\", + FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath()); + assertEquals(driveSpecLower + "\\", + FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath()); + /* + * promised to eliminate consecutive slashes after drive letter. + */ + assertEquals(driveSpec + "\\", + FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath()); + assertEquals(driveSpec + "\\", + FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath()); + } + if (Os.isFamily("netware")) { + /* + * throw in NetWare volume names + */ + String driveSpec = "SYS:"; + assertEquals(driveSpec, + FILE_UTILS.resolveFile(null, driveSpec + "/").getPath()); + assertEquals(driveSpec, + FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath()); + String driveSpecLower = "sys:"; + assertEquals(driveSpec, + FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath()); + assertEquals(driveSpec, + FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath()); + /* + * promised to eliminate consecutive slashes after drive letter. + */ + assertEquals(driveSpec, + FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath()); + assertEquals(driveSpec, + FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath()); + } else if (!(Os.isFamily("dos"))) { + /* + * drive letters must be considered just normal filenames. + */ + String driveSpec = "C:"; + String udir = System.getProperty("user.dir"); + assertEquals(udir + File.separator + driveSpec, + FILE_UTILS.resolveFile(null, driveSpec + "/").getPath()); + assertEquals(udir + File.separator + driveSpec, + FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath()); + String driveSpecLower = "c:"; + assertEquals(udir + File.separator + driveSpecLower, + FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath()); + assertEquals(udir + File.separator + driveSpecLower, + FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath()); + } + + /* + * Now test some relative file name magic. + */ + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "4").getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "./4").getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.resolveFile(new File(localize("/1/2/3")), ".\\4").getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "./.\\4").getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "../3/4").getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "..\\3\\4").getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "../../5/.././2/./3/6/../4").getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "..\\../5/..\\./2/./3/6\\../4").getPath()); + + assertEquals("meaningless result but no exception", + new File(localize("/1/../../b")), + FILE_UTILS.resolveFile(new File(localize("/1")), "../../b")); + + } + + @Test + public void testNormalize() { + if (!(Os.isFamily("dos") || Os.isFamily("netware"))) { + /* + * Start with simple absolute file names. + */ + assertEquals(File.separator, + FILE_UTILS.normalize("/").getPath()); + assertEquals(File.separator, + FILE_UTILS.normalize("\\").getPath()); + } else { + try { + FILE_UTILS.normalize("/").getPath(); + fail("normalized \"/\" on dos or netware"); + } catch (Exception e) { + } + try { + FILE_UTILS.normalize("\\").getPath(); + fail("normalized \"\\\" on dos or netware"); + } catch (Exception e) { + } + } + + if (Os.isFamily("dos")) { + /* + * throw in drive letters + */ + String driveSpec = "C:"; + try { + FILE_UTILS.normalize(driveSpec).getPath(); + fail(driveSpec + " is not an absolute path"); + } catch (Exception e) { + } + assertEquals(driveSpec + "\\", + FILE_UTILS.normalize(driveSpec + "/").getPath()); + assertEquals(driveSpec + "\\", + FILE_UTILS.normalize(driveSpec + "\\").getPath()); + String driveSpecLower = "c:"; + assertEquals(driveSpecLower + "\\", + FILE_UTILS.normalize(driveSpecLower + "/").getPath()); + assertEquals(driveSpecLower + "\\", + FILE_UTILS.normalize(driveSpecLower + "\\").getPath()); + /* + * promised to eliminate consecutive slashes after drive letter. + */ + assertEquals(driveSpec + "\\", + FILE_UTILS.normalize(driveSpec + "/////").getPath()); + assertEquals(driveSpec + "\\", + FILE_UTILS.normalize(driveSpec + "\\\\\\\\\\\\").getPath()); + } else if (Os.isFamily("netware")) { + /* + * throw in NetWare volume names + */ + String driveSpec = "SYS:"; + assertEquals(driveSpec, + FILE_UTILS.normalize(driveSpec).getPath()); + assertEquals(driveSpec, + FILE_UTILS.normalize(driveSpec + "/").getPath()); + assertEquals(driveSpec, + FILE_UTILS.normalize(driveSpec + "\\").getPath()); + String driveSpecLower = "sys:"; + assertEquals(driveSpec, + FILE_UTILS.normalize(driveSpecLower).getPath()); + assertEquals(driveSpec, + FILE_UTILS.normalize(driveSpecLower + "/").getPath()); + assertEquals(driveSpec, + FILE_UTILS.normalize(driveSpecLower + "\\").getPath()); + assertEquals(driveSpec + "\\junk", + FILE_UTILS.normalize(driveSpecLower + "\\junk").getPath()); + /* + * promised to eliminate consecutive slashes after drive letter. + */ + assertEquals(driveSpec, + FILE_UTILS.normalize(driveSpec + "/////").getPath()); + assertEquals(driveSpec, + FILE_UTILS.normalize(driveSpec + "\\\\\\\\\\\\").getPath()); + } else { + try { + String driveSpec = "C:"; + assertEquals(driveSpec, + FILE_UTILS.normalize(driveSpec).getPath()); + fail("Expected failure, C: isn't an absolute path on other os's"); + } catch (BuildException e) { + // Passed test + } + } + + /* + * Now test some relative file name magic. + */ + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.normalize(localize("/1/2/3/4")).getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.normalize(localize("/1/2/3/./4")).getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.normalize(localize("/1/2/3/.\\4")).getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.normalize(localize("/1/2/3/./.\\4")).getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.normalize(localize("/1/2/3/../3/4")).getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.normalize(localize("/1/2/3/..\\3\\4")).getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.normalize(localize("/1/2/3/../../5/.././2/./3/6/../4")).getPath()); + assertEquals(localize("/1/2/3/4"), + FILE_UTILS.normalize(localize("/1/2/3/..\\../5/..\\./2/./3/6\\../4")).getPath()); + + try { + FILE_UTILS.normalize("foo"); + fail("foo is not an absolute path"); + } catch (BuildException e) { + // Expected exception caught + } + + assertEquals("will not go outside FS root (but will not throw an exception either)", + new File(localize("/1/../../b")), + FILE_UTILS.normalize(localize("/1/../../b"))); + } + + /** + * Test handling of null arguments. + */ + @Test + public void testNullArgs() { + try { + FILE_UTILS.normalize(null); + fail("successfully normalized a null-file"); + } catch (NullPointerException npe) { + // Expected exception caught + } + + File f = FILE_UTILS.resolveFile(null, "a"); + assertEquals(f, new File("a").getAbsoluteFile()); + } + + + /** + * Test createTempFile + */ + @Test + public void testCreateTempFile() + { + // null parent dir + File tmp1 = FILE_UTILS.createTempFile("pre", ".suf", null, false, true); + String tmploc = System.getProperty("java.io.tmpdir"); + String name = tmp1.getName(); + assertTrue("starts with pre", name.startsWith("pre")); + assertTrue("ends with .suf", name.endsWith(".suf")); + assertTrue("File was created", tmp1.exists()); + assertEquals((new File(tmploc, tmp1.getName())).getAbsolutePath(), tmp1 + .getAbsolutePath()); + tmp1.delete(); + + File dir2 = new File(tmploc + "/ant-test"); + dir2.mkdir(); + removeThis = dir2; + + File tmp2 = FILE_UTILS.createTempFile("pre", ".suf", dir2, true, true); + String name2 = tmp2.getName(); + assertTrue("starts with pre", name2.startsWith("pre")); + assertTrue("ends with .suf", name2.endsWith(".suf")); + assertTrue("File was created", tmp2.exists()); + assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(), tmp2 + .getAbsolutePath()); + tmp2.delete(); + dir2.delete(); + + File parent = new File((new File("/tmp")).getAbsolutePath()); + tmp1 = FILE_UTILS.createTempFile("pre", ".suf", parent, false); + assertTrue("new file", !tmp1.exists()); + + name = tmp1.getName(); + assertTrue("starts with pre", name.startsWith("pre")); + assertTrue("ends with .suf", name.endsWith(".suf")); + assertEquals("is inside parent dir", parent.getAbsolutePath(), tmp1 + .getParent()); + + tmp2 = FILE_UTILS.createTempFile("pre", ".suf", parent, false); + assertTrue("files are different", !tmp1.getAbsolutePath().equals( + tmp2.getAbsolutePath())); + + // null parent dir + File tmp3 = FILE_UTILS.createTempFile("pre", ".suf", null, false); + tmploc = System.getProperty("java.io.tmpdir"); + assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(), tmp3 + .getAbsolutePath()); + } + + /** + * Test contentEquals + */ + @Test + public void testContentEquals() throws IOException { + assertTrue("Non existing files", FILE_UTILS.contentEquals(new File(System.getProperty("root"), "foo"), + new File(System.getProperty("root"), "bar"))); + assertTrue("One exists, the other one doesn\'t", + !FILE_UTILS.contentEquals(new File(System.getProperty("root"), "foo"), new File(System.getProperty("root"), "build.xml"))); + assertTrue("Don\'t compare directories", + !FILE_UTILS.contentEquals(new File(System.getProperty("root"), "src"), new File(System.getProperty("root"), "src"))); + assertTrue("File equals itself", + FILE_UTILS.contentEquals(new File(System.getProperty("root"), "build.xml"), + new File(System.getProperty("root"), "build.xml"))); + assertTrue("Files are different", + !FILE_UTILS.contentEquals(new File(System.getProperty("root"), "build.xml"), + new File(System.getProperty("root"), "docs.xml"))); + } + + /** + * Test createNewFile + */ + @Test + public void testCreateNewFile() throws IOException { + removeThis = new File("dummy"); + assertTrue(!removeThis.exists()); + FILE_UTILS.createNewFile(removeThis); + assertTrue(removeThis.exists()); + } + + /** + * Test removeLeadingPath. + */ + @Test + public void testRemoveLeadingPath() { + assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("/foo"), + new File("/foo/bar"))); + assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("/foo/"), + new File("/foo/bar"))); + assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("\\foo"), + new File("\\foo\\bar"))); + assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("\\foo\\"), + new File("\\foo\\bar"))); + assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:/foo"), + new File("c:/foo/bar"))); + assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:/foo/"), + new File("c:/foo/bar"))); + assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:\\foo"), + new File("c:\\foo\\bar"))); + assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:\\foo\\"), + new File("c:\\foo\\bar"))); + if (!(Os.isFamily("dos") || Os.isFamily("netware"))) { + assertEquals(FILE_UTILS.normalize("/bar").getAbsolutePath(), + FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/bar"))); + assertEquals(FILE_UTILS.normalize("/foobar").getAbsolutePath(), + FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/foobar"))); + } + // bugzilla report 19979 + assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar"), + new File("/foo/bar"))); + assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar"), + new File("/foo/bar/"))); + assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar/"), + new File("/foo/bar/"))); + assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar/"), + new File("/foo/bar"))); + + String expected = "foo/bar".replace('\\', File.separatorChar) + .replace('/', File.separatorChar); + assertEquals(expected, FILE_UTILS.removeLeadingPath(new File("/"), + new File("/foo/bar"))); + assertEquals(expected, FILE_UTILS.removeLeadingPath(new File("c:/"), + new File("c:/foo/bar"))); + assertEquals(expected, FILE_UTILS.removeLeadingPath(new File("c:\\"), + new File("c:\\foo\\bar"))); + } + + /** + * test toUri + */ + @Test + public void testToURI() { + String dosRoot; + if (Os.isFamily("dos") || Os.isFamily("netware")) { + dosRoot = System.getProperty("user.dir") + .substring(0, 3).replace(File.separatorChar, '/'); + } + else + { + dosRoot = ""; + } + if (Os.isFamily("dos")) { + assertEquals("file:/c:/foo", removeExtraneousAuthority(FILE_UTILS.toURI("c:\\foo"))); + } + if (Os.isFamily("netware")) { + assertEquals("file:/SYS:/foo", removeExtraneousAuthority(FILE_UTILS.toURI("sys:\\foo"))); + } + if (File.pathSeparatorChar == '/') { + assertEquals("file:/foo", removeExtraneousAuthority(FILE_UTILS.toURI("/foo"))); + assertTrue("file: URIs must name absolute paths", FILE_UTILS.toURI("./foo").startsWith("file:/")); + assertTrue(FILE_UTILS.toURI("./foo").endsWith("/foo")); + assertEquals("file:/" + dosRoot + "foo%20bar", removeExtraneousAuthority(FILE_UTILS.toURI("/foo bar"))); + assertEquals("file:/" + dosRoot + "foo%23bar", removeExtraneousAuthority(FILE_UTILS.toURI("/foo#bar"))); + } else if (File.pathSeparatorChar == '\\') { + assertEquals("file:/" + dosRoot + "foo", removeExtraneousAuthority(FILE_UTILS.toURI("\\foo"))); + assertTrue("file: URIs must name absolute paths", FILE_UTILS.toURI(".\\foo").startsWith("file:/")); + assertTrue(FILE_UTILS.toURI(".\\foo").endsWith("/foo")); + assertEquals("file:/" + dosRoot + "foo%20bar", removeExtraneousAuthority(FILE_UTILS.toURI("\\foo bar"))); + assertEquals("file:/" + dosRoot + "foo%23bar", removeExtraneousAuthority(FILE_UTILS.toURI("\\foo#bar"))); + } + // a test with ant for germans + // the escaped character used for the test is the "a umlaut" + // this is the fix for the bug 37348 + assertEquals("file:/" + dosRoot + "%C3%A4nt", removeExtraneousAuthority(FILE_UTILS.toURI("/\u00E4nt"))); + } + + /** + * Authority field is unnecessary, but harmless, in file: URIs. + * Java 1.4 does not produce it when using File.toURI. + */ + private static String removeExtraneousAuthority(String uri) { + String prefix = "file:///"; + if (uri.startsWith(prefix)) { + return "file:/" + uri.substring(prefix.length()); + } else { + return uri; + } + } + + @Test + public void testIsContextRelativePath() { + assumeTrue("Test only runs on DOS", Os.isFamily("dos")); + assertTrue(FileUtils.isContextRelativePath("/\u00E4nt")); + assertTrue(FileUtils.isContextRelativePath("\\foo")); + } + + /** + * test fromUri + */ + @Test + public void testFromURI() { + String dosRoot; + if (Os.isFamily("dos") || Os.isFamily("netware")) { + dosRoot = System.getProperty("user.dir").substring(0, 2); + } else { + dosRoot = ""; + } + if (Os.isFamily("netware")) { + assertEqualsIgnoreDriveCase("SYS:\\foo", FILE_UTILS.fromURI("file:///sys:/foo")); + } + if (Os.isFamily("dos")) { + assertEqualsIgnoreDriveCase("C:\\foo", FILE_UTILS.fromURI("file:///c:/foo")); + } + assertEqualsIgnoreDriveCase(dosRoot + File.separator + "foo", FILE_UTILS.fromURI("file:///foo")); + assertEquals("." + File.separator + "foo", + FILE_UTILS.fromURI("file:./foo")); + assertEquals(dosRoot + File.separator + "foo bar", FILE_UTILS.fromURI("file:///foo%20bar")); + assertEquals(dosRoot + File.separator + "foo#bar", FILE_UTILS.fromURI("file:///foo%23bar")); + } + + @Test + public void testModificationTests() { + + //get a time + long firstTime=System.currentTimeMillis(); + //add some time. We assume no OS has a granularity this bad + long secondTime=firstTime+60000; +/* + assertTrue("same timestamp is up to date", + fu.isUpToDate(firstTime, firstTime)); + */ + + //check that older is up to date with a newer dest + assertTrue("older source files are up to date", + FILE_UTILS.isUpToDate(firstTime,secondTime)); + //check that older is up to date with a newer dest + assertFalse("newer source files are no up to date", + FILE_UTILS.isUpToDate(secondTime, firstTime)); + + assertTrue("-1 dest timestamp implies nonexistence", + !FILE_UTILS.isUpToDate(firstTime,-1L)); + } + + @Test + public void testHasErrorInCase() { + File tempFolder = new File(System.getProperty("java.io.tmpdir")); + File wellcased = FILE_UTILS.createTempFile("alpha", "beta", tempFolder, + true, true); + String s = wellcased.getName().toUpperCase(); + File wrongcased = new File(tempFolder, s); + if (Os.isFamily("mac") && Os.isFamily("unix")) { + //no guarantees on filesystem case-sensitivity + } else if (Os.isFamily("dos")) { + assertTrue(FILE_UTILS.hasErrorInCase(wrongcased)); + assertFalse(FILE_UTILS.hasErrorInCase(wellcased)); + } else { + assertFalse(FILE_UTILS.hasErrorInCase(wrongcased)); + assertFalse(FILE_UTILS.hasErrorInCase(wellcased)); + } + + } + public void testGetDefaultEncoding() { + // This just tests that the function does not blow up + FILE_UTILS.getDefaultEncoding(); + } + + /** + * adapt file separators to local conventions + */ + private String localize(String path) { + path = root + path.substring(1); + return path.replace('\\', File.separatorChar).replace('/', File.separatorChar); + } + + /** + * convenience method + * normalize brings the drive in uppercase + * the drive letter is in lower case under cygwin + * calling this method allows tests where normalize is called to pass under cygwin + */ + private void assertEqualsIgnoreDriveCase(String s1, String s2) { + if ((Os.isFamily("dos") || Os.isFamily("netware")) + && s1.length() > 0 && s2.length() > 0) { + StringBuilder sb1 = new StringBuilder(s1); + StringBuilder sb2 = new StringBuilder(s2); + sb1.setCharAt(0, Character.toUpperCase(s1.charAt(0))); + sb2.setCharAt(0, Character.toUpperCase(s2.charAt(0))); + assertEquals(sb1.toString(), sb2.toString()); + } else { + assertEquals(s1, s2); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/GlobPatternMapperTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/GlobPatternMapperTest.java new file mode 100644 index 00000000..5bd7db60 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/GlobPatternMapperTest.java @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + +/** + * Tests for org.apache.tools.ant.util;GlobPatternMapper. + * + */ +public class GlobPatternMapperTest { + + @Test + public void testNoPatternAtAll() { + GlobPatternMapper m = new GlobPatternMapper(); + m.setFrom("foobar"); + m.setTo("baz"); + assertNull("Shouldn\'t match foobar", m.mapFileName("plonk")); + String[] result = m.mapFileName("foobar"); + assertNotNull("Should match foobar", result); + assertEquals("only one result for foobar", 1, result.length); + assertEquals("baz", result[0]); + } + + @Test + public void testPostfixOnly() { + GlobPatternMapper m = new GlobPatternMapper(); + m.setFrom("*foo"); + m.setTo("*plonk"); + assertNull("Shouldn\'t match *foo", m.mapFileName("bar.baz")); + String[] result = m.mapFileName("bar.foo"); + assertNotNull("Should match *.foo", result); + assertEquals("only one result for bar.foo", 1, result.length); + assertEquals("bar.plonk", result[0]); + + // Try a silly case + m.setTo("foo*"); + result = m.mapFileName("bar.foo"); + assertEquals("foobar.", result[0]); + } + + @Test + public void testPrefixOnly() { + GlobPatternMapper m = new GlobPatternMapper(); + m.setFrom("foo*"); + m.setTo("plonk*"); + assertNull("Shouldn\'t match foo*", m.mapFileName("bar.baz")); + String[] result = m.mapFileName("foo.bar"); + assertNotNull("Should match foo*", result); + assertEquals("only one result for foo.bar", 1, result.length); + assertEquals("plonk.bar", result[0]); + + // Try a silly case + m.setTo("*foo"); + result = m.mapFileName("foo.bar"); + assertEquals(".barfoo", result[0]); + } + + @Test + public void testPreAndPostfix() { + GlobPatternMapper m = new GlobPatternMapper(); + m.setFrom("foo*bar"); + m.setTo("plonk*pling"); + assertNull("Shouldn\'t match foo*bar", m.mapFileName("bar.baz")); + String[] result = m.mapFileName("foo.bar"); + assertNotNull("Should match foo*bar", result); + assertEquals("only one result for foo.bar", 1, result.length); + assertEquals("plonk.pling", result[0]); + + // and a little longer + result = m.mapFileName("foo.baz.bar"); + assertNotNull("Should match foo*bar", result); + assertEquals("only one result for foo.baz.bar", 1, result.length); + assertEquals("plonk.baz.pling", result[0]); + + // and a little shorter + result = m.mapFileName("foobar"); + assertNotNull("Should match foo*bar", result); + assertEquals("only one result for foobar", 1, result.length); + assertEquals("plonkpling", result[0]); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java new file mode 100644 index 00000000..105c33d1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/JAXPUtilsTest.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertTrue; + +/** + * JAXPUtils test case + */ +public class JAXPUtilsTest { + + @Test + public void testGetSystemId(){ + File file = null; + if ( File.separatorChar == '\\' ){ + file = new File("d:\\jdk"); + } else { + file = new File("/user/local/bin"); + } + String systemid = JAXPUtils.getSystemId(file); + assertTrue("SystemIDs should start by file:/", systemid.startsWith("file:/")); + assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////")); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java new file mode 100644 index 00000000..8bcb1f2c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/JavaEnvUtilsTest.java @@ -0,0 +1,144 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.io.File; + +import junit.framework.AssertionFailedError; + +import org.apache.tools.ant.taskdefs.condition.Os; +import org.junit.Assume; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * TestCase for JavaEnvUtils. + * + */ +public class JavaEnvUtilsTest { + + private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); + + + @Test + public void testGetExecutableNetware() { + Assume.assumeTrue("Test only runs on netware", Os.isName("netware")); + assertEquals("java", JavaEnvUtils.getJreExecutable("java")); + assertEquals("javac", JavaEnvUtils.getJdkExecutable("javac")); + assertEquals("foo", JavaEnvUtils.getJreExecutable("foo")); + assertEquals("foo", JavaEnvUtils.getJdkExecutable("foo")); + } + + @Test + public void testGetExecutableWindows() { + Assume.assumeTrue("Test only runs on windows", Os.isFamily("windows")); + String javaHome = + FILE_UTILS.normalize(System.getProperty("java.home")) + .getAbsolutePath(); + + String j = JavaEnvUtils.getJreExecutable("java"); + assertTrue(j.endsWith(".exe")); + assertTrue(j+" is absolute", (new File(j)).isAbsolute()); + try { + assertTrue(j+" is normalized and in the JRE dir", + j.startsWith(javaHome)); + } catch (AssertionFailedError e) { + // java.home is bogus + assertEquals("java.exe", j); + } + + j = JavaEnvUtils.getJdkExecutable("javac"); + assertTrue(j.endsWith(".exe")); + try { + assertTrue(j+" is absolute", (new File(j)).isAbsolute()); + String javaHomeParent = + FILE_UTILS.normalize(javaHome+"/..").getAbsolutePath(); + assertTrue(j+" is normalized and in the JDK dir", + j.startsWith(javaHomeParent)); + assertTrue(j+" is normalized and not in the JRE dir", + !j.startsWith(javaHome)); + + } catch (AssertionFailedError e) { + // java.home is bogus + assertEquals("javac.exe", j); + } + + assertEquals("foo.exe", JavaEnvUtils.getJreExecutable("foo")); + assertEquals("foo.exe", JavaEnvUtils.getJdkExecutable("foo")); + } + + @Test + public void testGetExecutableMostPlatforms() { + Assume.assumeTrue("Test only runs on non Netware and non Windows systems", + !Os.isName("netware") && !Os.isFamily("windows")); + String javaHome = + FILE_UTILS.normalize(System.getProperty("java.home")) + .getAbsolutePath(); + + // could still be OS/2 + String extension = Os.isFamily("dos") ? ".exe" : ""; + + String j = JavaEnvUtils.getJreExecutable("java"); + if (!extension.equals("")) { + assertTrue(j.endsWith(extension)); + } + assertTrue(j+" is absolute", (new File(j)).isAbsolute()); + assertTrue(j+" is normalized and in the JRE dir", + j.startsWith(javaHome)); + + j = JavaEnvUtils.getJdkExecutable("javac"); + if (!extension.equals("")) { + assertTrue(j.endsWith(extension)); + } + assertTrue(j+" is absolute", (new File(j)).isAbsolute()); + + String javaHomeParent = + FILE_UTILS.normalize(javaHome+"/..").getAbsolutePath(); + assertTrue(j+" is normalized and in the JDK dir", + j.startsWith(javaHomeParent)); + + if ((Os.isFamily("mac") && JavaEnvUtils.getJavaVersionNumber() <= JavaEnvUtils.VERSION_1_6) + || JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_9)) { + assertTrue(j+" is normalized and in the JRE dir", + j.startsWith(javaHome)); + } else { + assertTrue(j+" is normalized and not in the JRE dir", + !j.startsWith(javaHome)); + } + + assertEquals("foo"+extension, + JavaEnvUtils.getJreExecutable("foo")); + assertEquals("foo"+extension, + JavaEnvUtils.getJdkExecutable("foo")); + } + + @Test + public void testIsAtLeastJavaVersion() + { + assertTrue( + "Current java version is not at least the current java version...", + JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.getJavaVersion())); + assertFalse( + "In case the current java version is higher than 9.0 definitely a new algorithem will be needed", + JavaEnvUtils.isAtLeastJavaVersion("9.0")); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java new file mode 100644 index 00000000..89cd3daa --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java @@ -0,0 +1,316 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.util.Properties; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +public class LayoutPreservingPropertiesTest { + + /** + * Tests that a properties file read by the + * LayoutPreservingPropertiesFile and then saves the properties in + * it. + */ + @Test + public void testPreserve() throws Exception { + File simple = new File(System.getProperty("root"), + "src/etc/testcases/util/simple.properties"); + FileInputStream fis = new FileInputStream(simple); + LayoutPreservingProperties lpf = new LayoutPreservingProperties(); + lpf.load(fis); + + File tmp = File.createTempFile("tmp", "props"); + tmp.deleteOnExit(); + lpf.saveAs(tmp); + + // now compare original and tmp for property equivalence + Properties originalProps = new Properties(); + originalProps.load(new FileInputStream(simple)); + + Properties tmpProps = new Properties(); + tmpProps.load(new FileInputStream(tmp)); + + assertEquals("properties corrupted", originalProps, tmpProps); + + // and now make sure that the comments made it into the new file + String s = readFile(tmp); + assertTrue("missing comment", s.indexOf("# a comment") > -1); + assertTrue("missing comment", s.indexOf("! more comment") > -1); + } + + /** + * Tests that names and value are properly escaped when being + * written out. + */ + @Test + public void testEscaping() throws Exception { + LayoutPreservingProperties lpf = new LayoutPreservingProperties(); + + lpf.setProperty(" prop one ", " leading and trailing spaces "); + lpf.setProperty("prop\ttwo", "contains\ttab"); + lpf.setProperty("prop\nthree", "contains\nnewline"); + lpf.setProperty("prop\rfour", "contains\rcarraige return"); + lpf.setProperty("prop\ffive", "contains\fform feed"); + lpf.setProperty("prop\\six", "contains\\backslash"); + lpf.setProperty("prop:seven", "contains:colon"); + lpf.setProperty("prop=eight", "contains=equals"); + lpf.setProperty("prop#nine", "contains#hash"); + lpf.setProperty("prop!ten", "contains!exclamation"); + + File tmp = File.createTempFile("tmp", "props"); + tmp.deleteOnExit(); + lpf.saveAs(tmp); + + // and check that the resulting file looks okay + String s = readFile(tmp); + + assertTrue(s.indexOf("\\ prop\\ one\\ =\\ \\ leading and trailing" + + " spaces ") > -1); + assertTrue(s.indexOf("prop\\ttwo=contains\\ttab") > -1); + assertTrue(s.indexOf("prop\\nthree=contains\\nnewline") > -1); + assertTrue(s.indexOf("prop\\rfour=contains\\rcarraige return") > -1); + assertTrue(s.indexOf("prop\\\\six=contains\\\\backslash") > -1); + assertTrue(s.indexOf("prop\\:seven=contains\\:colon") > -1); + assertTrue(s.indexOf("prop\\=eight=contains\\=equals") > -1); + assertTrue(s.indexOf("prop\\#nine=contains\\#hash") > -1); + assertTrue(s.indexOf("prop\\!ten=contains\\!exclamation") > -1); + } + + /** + * Tests that properties are correctly indexed, so that when we set + * an existing property, it updates the logical line, and it doesn't + * append a new one. + */ + @Test + public void testOverwrite() throws Exception { + File unusual = new File(System.getProperty("root"), + "src/etc/testcases/util/unusual.properties"); + FileInputStream fis = new FileInputStream(unusual); + LayoutPreservingProperties lpf = new LayoutPreservingProperties(); + lpf.load(fis); + + lpf.setProperty(" prop one ", "new one"); + lpf.setProperty("prop\ttwo", "new two"); + lpf.setProperty("prop\nthree", "new three"); + + File tmp = File.createTempFile("tmp", "props"); + tmp.deleteOnExit(); + lpf.saveAs(tmp); + + // and check that the resulting file looks okay + String s = readFile(tmp); + + assertTrue(s.indexOf("\\ prop\\ one\\ =\\ \\ leading and" + + " trailing spaces ") == -1); + assertTrue(s.indexOf("\\ prop\\ one\\ =new one") > -1); + assertTrue(s.indexOf("prop\\ttwo=contains\\ttab") == -1); + assertTrue(s.indexOf("prop\\ttwo=new two") > -1); + assertTrue(s.indexOf("prop\\nthree=contains\\nnewline") == -1); + assertTrue(s.indexOf("prop\\nthree=new three") > -1); + } + + @Test + public void testStoreWithHeader() throws Exception { + File simple = new File(System.getProperty("root"), + "src/etc/testcases/util/simple.properties"); + FileInputStream fis = new FileInputStream(simple); + LayoutPreservingProperties lpf = new LayoutPreservingProperties(); + lpf.load(fis); + + File tmp = File.createTempFile("tmp", "props"); + tmp.deleteOnExit(); + FileOutputStream fos = new FileOutputStream(tmp); + lpf.store(fos, "file-header"); + fos.close(); + + // and check that the resulting file looks okay + String s = readFile(tmp); + + assertTrue("should have had header ", s.startsWith("#file-header")); + } + + @Test + public void testClear() throws Exception { + File simple = new File(System.getProperty("root"), + "src/etc/testcases/util/simple.properties"); + FileInputStream fis = new FileInputStream(simple); + LayoutPreservingProperties lpf = new LayoutPreservingProperties(); + lpf.load(fis); + + lpf.clear(); + + File tmp = File.createTempFile("tmp", "props"); + tmp.deleteOnExit(); + lpf.saveAs(tmp); + + // and check that the resulting file looks okay + String s = readFile(tmp); + + assertTrue("should have had no properties ", + s.indexOf("prop.alpha") == -1); + assertTrue("should have had no properties ", + s.indexOf("prop.beta") == -1); + assertTrue("should have had no properties ", + s.indexOf("prop.gamma") == -1); + + assertTrue("should have had no comments", + s.indexOf("# a comment") == -1); + assertTrue("should have had no comments", + s.indexOf("! more comment") == -1); + assertTrue("should have had no comments", + s.indexOf("# now a line wrapping one") == -1); + } + + @Test + public void testRemove() throws Exception { + File simple = new File(System.getProperty("root"), + "src/etc/testcases/util/simple.properties"); + FileInputStream fis = new FileInputStream(simple); + LayoutPreservingProperties lpf = new LayoutPreservingProperties(); + lpf.load(fis); + + lpf.remove("prop.beta"); + + File tmp = File.createTempFile("tmp", "props"); + tmp.deleteOnExit(); + lpf.saveAs(tmp); + + // and check that the resulting file looks okay + String s = readFile(tmp); + + assertTrue("should not have had prop.beta", + s.indexOf("prop.beta") == -1); + assertTrue("should have had prop.beta's comment", + s.indexOf("! more comment") > -1); + } + + @Test + public void testRemoveWithComment() throws Exception { + File simple = new File(System.getProperty("root"), + "src/etc/testcases/util/simple.properties"); + FileInputStream fis = new FileInputStream(simple); + LayoutPreservingProperties lpf = new LayoutPreservingProperties(); + lpf.load(fis); + + lpf.setRemoveComments(true); + + lpf.remove("prop.beta"); + + File tmp = File.createTempFile("tmp", "props"); + tmp.deleteOnExit(); + lpf.saveAs(tmp); + + // and check that the resulting file looks okay + String s = readFile(tmp); + + assertTrue("should not have had prop.beta", + s.indexOf("prop.beta") == -1); + assertTrue("should not have had prop.beta's comment", + s.indexOf("! more comment") == -1); + } + + @Test + public void testClone() throws Exception { + File simple = new File(System.getProperty("root"), + "src/etc/testcases/util/simple.properties"); + FileInputStream fis = new FileInputStream(simple); + LayoutPreservingProperties lpf1 = new LayoutPreservingProperties(); + lpf1.load(fis); + + LayoutPreservingProperties lpf2 = + (LayoutPreservingProperties) lpf1.clone(); + + lpf2.setProperty("prop.new", "a new property"); + lpf2.setProperty("prop.beta", "a new value for beta"); + + assertEquals("size of original is wrong", 3, lpf1.size()); + assertEquals("size of clone is wrong", 4, lpf2.size()); + + File tmp1 = File.createTempFile("tmp", "props"); + tmp1.deleteOnExit(); + lpf1.saveAs(tmp1); + String s1 = readFile(tmp1); + + File tmp2 = File.createTempFile("tmp", "props"); + tmp2.deleteOnExit(); + lpf2.saveAs(tmp2); + String s2 = readFile(tmp2); + + // check original is untouched + assertTrue("should have had 'simple'", s1.indexOf("simple") > -1); + assertTrue("should not have had prop.new", s1.indexOf("prop.new") == -1); + + // check clone has the changes + assertTrue("should have had 'a new value for beta'", + s2.indexOf("a new value for beta") > -1); + assertTrue("should have had prop.new", s2.indexOf("prop.new") > -1); + } + + @Test + public void testPreserveEscapeName() throws Exception { + LayoutPreservingProperties lpf = new LayoutPreservingProperties(); + File unusual = new File(System.getProperty("root"), + "src/etc/testcases/util/unusual.properties"); + FileInputStream fis = new FileInputStream(unusual); + lpf.load(fis); + + lpf.setProperty("prop:seven", "new value for seven"); + lpf.setProperty("prop=eight", "new value for eight"); + lpf.setProperty("prop eleven", "new value for eleven"); + + lpf.setProperty("alpha", "new value for alpha"); + lpf.setProperty("beta", "new value for beta"); + + File tmp = File.createTempFile("tmp", "props"); + tmp.deleteOnExit(); + lpf.saveAs(tmp); + + // and check that the resulting file looks okay + String s = readFile(tmp); + + assertTrue(s.indexOf("prop\\:seven=new value for seven") > -1); + assertTrue(s.indexOf("prop\\=eight=new value for eight") > -1); + assertTrue(s.indexOf("prop\\ eleven=new value for eleven") > -1); + assertTrue(s.indexOf("alpha=new value for alpha") > -1); + assertTrue(s.indexOf("beta=new value for beta") > -1); + + assertTrue(s.indexOf("prop\\:seven=contains\\:colon") == -1); + assertTrue(s.indexOf("prop\\=eight=contains\\=equals") == -1); + assertTrue(s.indexOf("alpha:set with a colon") == -1); + assertTrue(s.indexOf("beta set with a space") == -1); + } + + private static String readFile(File f) throws IOException { + FileInputStream fis = new FileInputStream(f); + InputStreamReader isr = new InputStreamReader(fis); + String s = FileUtils.readFully(isr); + isr.close(); + fis.close(); + return s; + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LazyFileOutputStreamTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LazyFileOutputStreamTest.java new file mode 100644 index 00000000..82c36340 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LazyFileOutputStreamTest.java @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.io.File; +import java.io.IOException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +/** + * @since Ant 1.6 + */ +public class LazyFileOutputStreamTest { + private LazyFileOutputStream los; + private final static File f = new File("test.txt"); + + @Before + public void setUp() { + los = new LazyFileOutputStream(f); + } + + @After + public void tearDown() throws IOException { + try { + los.close(); + } finally { + f.delete(); + } + } + + @Test + public void testNoFileWithoutWrite() throws IOException { + los.close(); + assertTrue(f + " has not been written.", !f.exists()); + } + + @Test + public void testOpen() throws IOException { + los.open(); + los.close(); + assertTrue(f + " has been written.", f.exists()); + } + + @Test + public void testSingleByte() throws IOException { + los.write(0); + los.close(); + assertTrue(f + " has been written.", f.exists()); + } + + @Test + public void testByteArray() throws IOException { + los.write(new byte[] {0}); + los.close(); + assertTrue(f + " has been written.", f.exists()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java new file mode 100644 index 00000000..1fa23e84 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LineOrientedOutputStreamTest.java @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.io.IOException; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + + +public class LineOrientedOutputStreamTest { + + private static String LINE = "This is a line"; + private DummyStream stream; + + + @Before + public void setUp() { + stream = new DummyStream(); + } + + @After + public void tearDown() throws IOException { + if (stream != null) { + stream.close(); + } + } + + @Test + public void testLineWithLinefeedArray() throws IOException { + writeByteArray(); + writeAsArray('\n'); + stream.assertInvoked(); + } + + @Test + public void testLineWithLinefeedSingleBytes() throws IOException { + writeSingleBytes(); + stream.write('\n'); + stream.assertInvoked(); + } + + @Test + public void testLineWithCariagereturnArray() throws IOException { + writeByteArray(); + writeAsArray('\r'); + stream.assertInvoked(); + } + + @Test + public void testLineWithCariagereturnSingleBytes() throws IOException { + writeSingleBytes(); + stream.write('\r'); + stream.assertInvoked(); + } + + @Test + public void testLineWithCariagereturnLinefeedArray() throws IOException { + writeByteArray(); + writeAsArray('\r'); + writeAsArray('\n'); + stream.assertInvoked(); + } + + @Test + public void testLineWithCariagereturnLinefeedSingleBytes() throws IOException { + writeSingleBytes(); + stream.write('\r'); + stream.write('\n'); + stream.assertInvoked(); + } + + @Test + public void testFlushArray() throws IOException { + writeByteArray(); + stream.flush(); + stream.assertNotInvoked(); + } + + @Test + public void testFlushSingleBytes() throws IOException { + writeSingleBytes(); + stream.flush(); + stream.assertNotInvoked(); + } + + @Test + public void testCloseArray() throws IOException { + writeByteArray(); + stream.close(); + stream.assertInvoked(); + stream = null; + } + + @Test + public void testCloseSingleBytes() throws IOException { + writeSingleBytes(); + stream.close(); + stream.assertInvoked(); + stream = null; + } + + private void writeByteArray() throws IOException { + stream.write(LINE.getBytes(), 0, LINE.length()); + } + + private void writeSingleBytes() throws IOException { + byte[] b = LINE.getBytes(); + for (int i = 0; i < b.length; i++) { + stream.write(b[i]); + } + } + + private void writeAsArray(char c) throws IOException { + stream.write(new byte[] {(byte) c}, 0, 1); + } + + private class DummyStream extends LineOrientedOutputStream { + private boolean invoked; + protected void processLine(String line) { + assertFalse("Only one line", invoked); + assertEquals(LINE, line); + invoked = true; + } + + private void assertInvoked() { + assertTrue("At least one line", invoked); + } + private void assertNotInvoked() { + assertTrue("No output", !invoked); + } + } +}// LineOrientedOutputStreamTest diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LinkedHashtableTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LinkedHashtableTest.java new file mode 100644 index 00000000..bfd2cda7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LinkedHashtableTest.java @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.util.Hashtable; +import java.util.Iterator; +import java.util.Map; + +import org.junit.Test; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertEquals; + +public class LinkedHashtableTest { + + private static final Object K1 = new Object(); + private static final Object K2 = new Object(); + private static final Object V1 = new Object(); + private static final Object V2 = new Object(); + private Hashtable h = new LinkedHashtable(); + + public void testClear() { + h.put(K1, V1); + h.clear(); + assertTrue(h.isEmpty()); + } + + public void testClone() { + h.put(K1, V1); + Hashtable h2 = (Hashtable) h.clone(); + assertTrue(h2 instanceof LinkedHashtable); + assertTrue(h2.containsKey(K1)); + } + + @Test + public void testContainsAndPut() { + h.put(K1, V1); + assertTrue(h.contains(K1)); + assertTrue(h.containsKey(K1)); + assertTrue(h.containsValue(V1)); + assertFalse(h.containsKey(K2)); + } + + @Test + public void testGet() { + assertNull(h.get(K1)); + h.put(K1, V1); + assertSame(V1, h.get(K1)); + } + + @Test + public void testIsEmpty() { + assertTrue(h.isEmpty()); + h.put(K1, V1); + assertFalse(h.isEmpty()); + } + + @Test + public void testPutReturnValue() { + assertNull(h.put(K1, V1)); + assertSame(V1, h.put(K1, V2)); + } + + @Test + public void testPutAll() { + LinkedHashtable h2 = new LinkedHashtable(); + h.put(K1, V1); + h2.putAll(h); + assertTrue(h2.containsKey(K1)); + } + + @Test + public void testRemove() { + h.put(K1, V1); + assertSame(V1, h.remove(K1)); + assertTrue(h.isEmpty()); + assertNull(h.remove(K1)); + } + + @Test + public void testSize() { + assertEquals(0, h.size()); + h.put(K1, V1); + assertEquals(1, h.size()); + } + + @Test + public void testKeys() { + multiSetup(); + assertKeys(CollectionUtils.asIterator(h.keys())); + } + + @Test + public void testKeySet() { + multiSetup(); + assertKeys(h.keySet().iterator()); + } + + @Test + public void testElements() { + multiSetup(); + assertValues(CollectionUtils.asIterator(h.elements())); + } + + @Test + public void testValues() { + multiSetup(); + assertValues(h.values().iterator()); + } + + @Test + public void testEntrySet() { + multiSetup(); + Iterator i = h.entrySet().iterator(); + assertTrue(i.hasNext()); + Map.Entry e = (Map.Entry) i.next(); + assertSame(K1, e.getKey()); + assertSame(V1, e.getValue()); + assertTrue(i.hasNext()); + e = (Map.Entry) i.next(); + assertSame(K2, e.getKey()); + assertSame(V2, e.getValue()); + assertFalse(i.hasNext()); + } + + private void multiSetup() { + h.put(K1, V1); + h.put(K2, V2); + } + + private static void assertKeys(Iterator i) { + assertTrue(i.hasNext()); + assertSame(K1, i.next()); + assertTrue(i.hasNext()); + assertSame(K2, i.next()); + assertFalse(i.hasNext()); + } + + private static void assertValues(Iterator i) { + assertTrue(i.hasNext()); + assertSame(V1, i.next()); + assertTrue(i.hasNext()); + assertSame(V2, i.next()); + assertFalse(i.hasNext()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LoaderUtilsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LoaderUtilsTest.java new file mode 100644 index 00000000..9935edd6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/LoaderUtilsTest.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.io.File; +import org.junit.Test; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertEquals; + +/** + * @since Ant 1.6 + */ +public class LoaderUtilsTest { + + @Test + public void testGetXyzSource() { + File f1 = LoaderUtils.getClassSource(LoaderUtils.class); + assertNotNull(f1); + + File f2 = LoaderUtils.getResourceSource(null, + "org/apache/tools/ant/taskdefs/defaults.properties"); + assertNotNull(f2); + + assertEquals(f1.getAbsolutePath(), f2.getAbsolutePath()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/PackageNameMapperTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/PackageNameMapperTest.java new file mode 100644 index 00000000..fdf73931 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/PackageNameMapperTest.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import org.junit.Test; + +import java.io.File; + +import static org.junit.Assert.assertEquals; + +public class PackageNameMapperTest { + + @Test + public void testMapping() { + PackageNameMapper mapper = new PackageNameMapper(); + mapper.setFrom("*.java"); + mapper.setTo("TEST-*.xml"); + String file = fixupPath("org/apache/tools/ant/util/PackageNameMapperTest.java"); + String result = mapper.mapFileName(file)[0]; + + assertEquals("TEST-org.apache.tools.ant.util.PackageNameMapperTest.xml", + result); + } + + private String fixupPath(String file) { + return file.replace('/', File.separatorChar); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java new file mode 100644 index 00000000..bd07251e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java @@ -0,0 +1,142 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.InputStreamReader; +import java.io.StringReader; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +/** + * Test for ReaderInputStream + */ +public class ReaderInputStreamTest { + + @Test + public void testSimple() throws Exception { + compareBytes("abc", "utf-8"); + } + + @Test + public void testSimple16() throws Exception { + compareBytes("a", "utf-16"); + } + + @Test + public void testSimpleAbc16() throws Exception { + // THIS WILL FAIL. + //compareBytes("abc", "utf-16"); + byte[] bytes = new byte[40]; + int pos = 0; + ReaderInputStream r = new ReaderInputStream( + new StringReader("abc"), "utf-16"); + for (int i = 0; true; ++i) { + int res = r.read(); + if (res == -1) { + break; + } + bytes[pos++] = (byte) res; + } + bytes = "abc".getBytes("utf-16"); + // String n = new String(bytes, 0, pos, "utf-16"); + new String(bytes, 0, bytes.length, "utf-16"); + } + + @Test + public void testReadZero() throws Exception { + ReaderInputStream r = new ReaderInputStream( + new StringReader("abc")); + byte[] bytes = new byte[30]; + // First read in zero bytes + r.read(bytes, 0, 0); + // Now read in the string + int readin = r.read(bytes, 0, 10); + // Make sure that the counts are the same + assertEquals("abc".getBytes().length, readin); + } + + @Test + public void testPreample() throws Exception { + byte[] bytes = "".getBytes("utf-16"); + System.out.println("Preample len is " + bytes.length); + } + + @Test + public void testIso88591ToUtf8() throws Exception { + InputStreamReader fin = null; + ReaderInputStream r = null; + FileInputStream utf8 = null; + try { + fin = new InputStreamReader(new FileInputStream(new File(System.getProperty("root"), "src/tests/antunit/taskdefs/exec/input/iso8859-1")), + "ISO8859_1"); + r = new ReaderInputStream(fin, "UTF8"); + + ByteArrayOutputStream actualOS = new ByteArrayOutputStream(); + int b = r.read(); + while (b > -1) { + actualOS.write((byte) b); + b = r.read(); + } + + utf8 = new FileInputStream(new File(System.getProperty("root"), "src/tests/antunit/taskdefs/exec/expected/utf-8")); + ByteArrayOutputStream expectedOS = new ByteArrayOutputStream(); + b = utf8.read(); + while (b > -1) { + expectedOS.write((byte) b); + b = utf8.read(); + } + + byte[] expected = expectedOS.toByteArray(); + byte[] actual = actualOS.toByteArray(); + assertEquals("length", expected.length, actual.length); + for (int i = 0; i < actual.length; i++) { + assertEquals("byte " + i, expected[i], actual[i]); + } + } finally { + FileUtils.close(fin); + FileUtils.close(r); + FileUtils.close(utf8); + } + } + + private void compareBytes(String s, String encoding) throws Exception { + byte[] expected = s.getBytes(encoding); + + ReaderInputStream r = new ReaderInputStream( + new StringReader(s), encoding); + for (int i = 0; i < expected.length; ++i) { + int expect = expected[i] & 0xFF; + int read = r.read(); + if (expect != read) { + fail("Mismatch in ReaderInputStream at index " + i + + " expecting " + expect + " got " + read + " for string " + + s + " with encoding " + encoding); + } + } + if (r.read() != -1) { + fail("Mismatch in ReaderInputStream - EOF not seen for string " + + s + " with encoding " + encoding); + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/ResourceUtilsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/ResourceUtilsTest.java new file mode 100644 index 00000000..96cc9cbf --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/ResourceUtilsTest.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.Echo; +import org.apache.tools.ant.types.Resource; +import org.apache.tools.ant.types.ResourceFactory; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Tests for org.apache.tools.ant.util.ResourceUtils. + */ +public class ResourceUtilsTest implements ResourceFactory, FileNameMapper { + + private Echo taskINeedForLogging = new Echo(); + + @Before + public void setUp() { + taskINeedForLogging.setProject(new Project()); + } + + @Test + public void testNoDuplicates() { + Resource r = new Resource("samual vimes", true, 1, false); + Resource[] toNew = + ResourceUtils.selectOutOfDateSources(taskINeedForLogging, + new Resource[] {r}, + this, this); + assertEquals(1, toNew.length); + } + + /* ============ ResourceFactory interface ====================== */ + public Resource getResource(String name) { + return new Resource(name); // implies lastModified == 0 + } + + /* ============ FileNameMapper interface ======================= */ + public void setFrom(String s) {} + public void setTo(String s) {} + public String[] mapFileName(String s) { + return new String[] {"fred colon", "carrot ironfoundersson"}; + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java new file mode 100644 index 00000000..53ef1b29 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/StringUtilsTest.java @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.util.Vector; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +/** + * Test for StringUtils + */ +public class StringUtilsTest { + + @Test + public void testSplit(){ + final String data = "a,b,,"; + Vector res = StringUtils.split(data, ','); + assertEquals(4, res.size()); + assertEquals("a", res.elementAt(0)); + assertEquals("b", res.elementAt(1)); + assertEquals("", res.elementAt(2)); + assertEquals("", res.elementAt(3)); + } + + @Test + public void testSplitLines(){ + final String data = "a\r\nb\nc\nd\ne"; + Vector res = StringUtils.lineSplit(data); + assertEquals(5, res.size()); + assertEquals("a\r", res.elementAt(0)); + assertEquals("b", res.elementAt(1)); + assertEquals("c", res.elementAt(2)); + assertEquals("d", res.elementAt(3)); + assertEquals("e", res.elementAt(4)); + } + + @Test + public void testReplace() { + final String data = "abcabcabca"; + String res = StringUtils.replace(data, "a", ""); + assertEquals("bcbcbc", res); + } + + @Test + public void testEndsWithBothEmpty() { + assertTrue( StringUtils.endsWith( new StringBuffer(), "") ); + } + + @Test + public void testEndsWithEmptyString() { + assertTrue( StringUtils.endsWith( new StringBuffer("12234545"), "") ); + } + + @Test + public void testEndsWithShorterString() { + assertTrue( StringUtils.endsWith( new StringBuffer("12345678"), "78")); + } + + @Test + public void testEndsWithSameString() { + assertTrue( StringUtils.endsWith( new StringBuffer("123"), "123")); + } + + @Test + public void testEndsWithLongerString() { + assertFalse( StringUtils.endsWith( new StringBuffer("12"), "1245")); + } + + @Test + public void testEndsWithNoMatch() { + assertFalse( StringUtils.endsWith( new StringBuffer("12345678"), "789")); + } + + @Test + public void testEndsWithEmptyBuffer() { + assertFalse( StringUtils.endsWith( new StringBuffer(""), "12345667") ); + } + + @Test + public void testEndsWithJDKPerf() { + StringBuffer buf = getFilledBuffer(1024*300, 'a'); + for (int i = 0; i < 1000; i++) { + assertTrue(buf.toString().endsWith("aa")); + } + } + + @Test + public void testEndsWithPerf() { + StringBuffer buf = getFilledBuffer(1024*300, 'a'); + for (int i = 0; i < 1000; i++) { + assertTrue(StringUtils.endsWith(buf, "aa")); + } + } + + private StringBuffer getFilledBuffer(int size, char ch) { + StringBuffer buf = new StringBuffer(size); + for (int i = 0; i < size; i++) { buf.append(ch); }; + return buf; + } + + @Test + public void testParseHumanSizes() throws Exception { + final long KILOBYTE = 1024; + final long MEGABYTE = KILOBYTE * 1024; + final long GIGABYTE = MEGABYTE * 1024; + final long TERABYTE = GIGABYTE * 1024; + final long PETABYTE = TERABYTE * 1024; + assertEquals(StringUtils.parseHumanSizes("1K"), KILOBYTE); + assertEquals(StringUtils.parseHumanSizes("1M"), MEGABYTE); + assertEquals(StringUtils.parseHumanSizes("1G"), GIGABYTE); + assertEquals(StringUtils.parseHumanSizes("1T"), TERABYTE); + assertEquals(StringUtils.parseHumanSizes("1P"), PETABYTE); + assertEquals(StringUtils.parseHumanSizes("1"), 1L); + } + + @Test + public void testRemoveSuffix() { + String prefix = "Prefix"; + String name = "Name"; + String suffix = "Suffix"; + String input = prefix + name + suffix; + assertEquals( + "Does not remove the suffix right.", + prefix + name, + StringUtils.removeSuffix(input, suffix) + ); + assertEquals( + "Should leave the string unattended.", + prefix + name + suffix, + StringUtils.removeSuffix(input, "bla") + ); + } + + @Test + public void testRemovePrefix() { + String prefix = "Prefix"; + String name = "Name"; + String suffix = "Suffix"; + String input = prefix + name + suffix; + assertEquals( + "Does not remove the prefix right.", + name + suffix, + StringUtils.removePrefix(input, prefix) + ); + assertEquals( + "Should leave the string unattended.", + prefix + name + suffix, + StringUtils.removePrefix(input, "bla") + ); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java new file mode 100644 index 00000000..d1de1b1a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/SymlinkUtilsTest.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import static org.junit.Assert.assertFalse; + +import java.io.IOException; + +import org.apache.tools.ant.taskdefs.condition.Os; +import org.junit.Assume; +import org.junit.Test; + +public class SymlinkUtilsTest { + + private static final SymbolicLinkUtils SYMLINK_UTILS = + SymbolicLinkUtils.getSymbolicLinkUtils(); + + @Test + public void testRootIsNoSymlink() throws IOException { + Assume.assumeFalse("Symlink doesn't work on Windows", Os.isFamily("windows")); + assertFalse(SYMLINK_UTILS.isSymbolicLink("/")); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/UnPackageNameMapperTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/UnPackageNameMapperTest.java new file mode 100644 index 00000000..7586950d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/UnPackageNameMapperTest.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.io.File; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class UnPackageNameMapperTest { + + @Test + public void testMapping() { + UnPackageNameMapper mapper = new UnPackageNameMapper(); + mapper.setFrom("TEST-*.xml"); + mapper.setTo("*.java"); + String file ="TEST-org.apache.tools.ant.util.UnPackageNameMapperTest.xml"; + String result = mapper.mapFileName(file)[0]; + String expected = fixupPath("org/apache/tools/ant/util/UnPackageNameMapperTest.java"); + + assertEquals(expected, result); + } + + private String fixupPath(String file) { + return file.replace('/', File.separatorChar); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/UnicodeUtilTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/UnicodeUtilTest.java new file mode 100644 index 00000000..090da569 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/UnicodeUtilTest.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class UnicodeUtilTest { + + @Test + public void testChineseWord() { + String word = "\u81ea\u7531"; + assertEquals("u81ea", UnicodeUtil.EscapeUnicode(word.charAt(0)).toString()); + assertEquals("u7531", UnicodeUtil.EscapeUnicode(word.charAt(1)).toString()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/VectorSetTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/VectorSetTest.java new file mode 100644 index 00000000..11491e3a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/VectorSetTest.java @@ -0,0 +1,295 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import java.util.ArrayList; +import java.util.Arrays; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class VectorSetTest { + + private static final Object O = new Object(); + private VectorSet v = new VectorSet(); + + @Test + public void testAdd() { + assertTrue(v.add(O)); + assertFalse(v.add(O)); + assertEquals(1, v.size()); + } + + @Test + public void testAdd2() { + v.add(0, O); + v.add(1, O); + assertEquals(1, v.size()); + } + + @Test + public void testAddElement() { + v.addElement(O); + v.addElement(O); + assertEquals(1, v.size()); + } + + @Test + public void testAddAll() { + assertTrue(v.addAll(Arrays.asList(new Object[] {O, O}))); + assertEquals(1, v.size()); + } + + @Test + public void testAddAll2() { + assertTrue(v.addAll(0, Arrays.asList(new Object[] {O, O}))); + assertEquals(1, v.size()); + } + + @Test + public void testClear() { + v.add(O); + v.clear(); + assertEquals(0, v.size()); + } + + @Test + public void testClone() { + v.add(O); + Object o = v.clone(); + assertTrue(o instanceof VectorSet); + VectorSet vs = (VectorSet) o; + assertEquals(1, vs.size()); + assertTrue(vs.contains(O)); + } + + @Test + public void testContains() { + assertFalse(v.contains(O)); + v.add(O); + assertTrue(v.contains(O)); + assertFalse(v.contains(null)); + } + + @Test + public void testContainsAll() { + assertFalse(v.containsAll(Arrays.asList(new Object[] {O, O}))); + v.add(O); + assertTrue(v.containsAll(Arrays.asList(new Object[] {O, O}))); + assertFalse(v.containsAll(Arrays.asList(new Object[] {O, null}))); + } + + @Test + public void testInsertElementAt() { + v.insertElementAt(O, 0); + v.insertElementAt(O, 1); + assertEquals(1, v.size()); + } + + @Test + public void testRemoveIndex() { + v.add(O); + assertSame(O, v.remove(0)); + assertEquals(0, v.size()); + try { + v.remove(0); + fail("expected an AIOBE"); + } catch (ArrayIndexOutOfBoundsException e) { + //TODO assert exception values + // expected + } + } + + @Test + public void testRemoveObject() { + v.add(O); + assertTrue(v.remove(O)); + assertEquals(0, v.size()); + assertFalse(v.remove(O)); + } + + @Test + public void testRemoveAtEndWhenSizeEqualsCapacity() { + v = new VectorSet(3, 1); + Object a = new Object(); + v.add(a); + Object b = new Object(); + v.add(b); + v.add(O); + assertEquals(3, v.size()); + assertEquals(3, v.capacity()); + assertTrue(v.remove(O)); + assertEquals(2, v.size()); + assertFalse(v.remove(O)); + assertSame(a, v.elementAt(0)); + assertSame(b, v.elementAt(1)); + } + + @Test + public void testRemoveAtFrontWhenSizeEqualsCapacity() { + v = new VectorSet(3, 1); + v.add(O); + Object a = new Object(); + v.add(a); + Object b = new Object(); + v.add(b); + assertEquals(3, v.size()); + assertEquals(3, v.capacity()); + assertTrue(v.remove(O)); + assertEquals(2, v.size()); + assertFalse(v.remove(O)); + assertSame(a, v.elementAt(0)); + assertSame(b, v.elementAt(1)); + } + + @Test + public void testRemoveInMiddleWhenSizeEqualsCapacity() { + v = new VectorSet(3, 1); + Object a = new Object(); + v.add(a); + v.add(O); + Object b = new Object(); + v.add(b); + assertEquals(3, v.size()); + assertEquals(3, v.capacity()); + assertTrue(v.remove(O)); + assertEquals(2, v.size()); + assertFalse(v.remove(O)); + assertSame(a, v.elementAt(0)); + assertSame(b, v.elementAt(1)); + } + + @Test + public void testRemoveAll() { + v.add(O); + assertTrue(v.removeAll(Arrays.asList(new Object[] {O, O}))); + assertEquals(0, v.size()); + assertFalse(v.removeAll(Arrays.asList(new Object[] {O, O}))); + } + + @Test + public void testRemoveAllElements() { + v.add(O); + v.removeAllElements(); + assertEquals(0, v.size()); + } + + @Test + public void testRemoveElement() { + v.add(O); + assertTrue(v.removeElement(O)); + assertEquals(0, v.size()); + assertFalse(v.removeElement(O)); + } + + @Test + public void testRemoveElementAt() { + v.add(O); + v.removeElementAt(0); + assertEquals(0, v.size()); + try { + v.removeElementAt(0); + fail("expected an AIOBE"); + } catch (ArrayIndexOutOfBoundsException e) { + //TODO assert exception values + // expected + } + } + + @Test + public void testRemoveRange() { + Object a = new Object(); + Object b = new Object(); + Object c = new Object(); + v.addAll(Arrays.asList(new Object[] {O, a, b, c})); + v.removeRange(1, 3); + assertEquals(2, v.size()); + assertTrue(v.contains(O)); + assertTrue(v.contains(c)); + } + + @Test + public void testRetainAll() { + Object a = new Object(); + Object b = new Object(); + Object c = new Object(); + v.addAll(Arrays.asList(new Object[] {O, a, b, c})); + assertEquals(0, v.indexOf(O)); + assertTrue(v.retainAll(Arrays.asList(new Object[] {c, O}))); + assertEquals(2, v.size()); + assertTrue(v.contains(O)); + assertTrue(v.contains(c)); + assertEquals(0, v.indexOf(O)); + } + + @Test + public void testRetainAllReturnValueAndEmptiness() { + v.add(1); + v.add(2); + v.add(3); + assertTrue(v.retainAll(Arrays.asList(1, 2))); + assertEquals(2, v.size()); + assertFalse(v.retainAll(Arrays.asList(1, 2))); + assertEquals(2, v.size()); + assertTrue(v.retainAll(Arrays.asList(4, 5))); + assertEquals(0, v.size()); + assertFalse(v.retainAll(Arrays.asList(4, 5))); + } + + @Test + public void testSet() { + v.add(O); + Object a = new Object(); + assertSame(O, v.set(0, a)); + assertSame(a, v.get(0)); + assertEquals(1, v.size()); + } + + @Test + public void testSetElementAt() { + v.add(O); + Object a = new Object(); + v.setElementAt(a, 0); + assertSame(a, v.get(0)); + assertEquals(1, v.size()); + } + + @Test + public void testRetainAllSpeed() { + int size = 50000; + for (int i = 0; i < size; i++) { + v.add(i); + v.add(i); + } + assertEquals(size, v.size()); + ArrayList<Integer> list = new ArrayList<Integer>(); + for (int i = size - 4; i < 2 * size; i++) { + list.add(i); + v.add(i); + } + assertTrue(v.retainAll(list)); + assertEquals(v.toString(), size + 4, v.size()); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/XMLFragmentTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/XMLFragmentTest.java new file mode 100644 index 00000000..0ac938f0 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/XMLFragmentTest.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util; + +import org.apache.tools.ant.BuildFileRule; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class XMLFragmentTest { + + @Rule + public BuildFileRule buildRule = new BuildFileRule(); + + @Before + public void setUp() { + buildRule.configureProject("src/etc/testcases/types/xmlfragment.xml"); + } + + @Test + public void testNestedText() { + XMLFragment x = (XMLFragment) buildRule.getProject().getReference("nested-text"); + assertNotNull(x); + Node n = x.getFragment(); + assertTrue("No attributes", !n.hasAttributes()); + NodeList nl = n.getChildNodes(); + assertEquals(1, nl.getLength()); + assertEquals(Node.TEXT_NODE, nl.item(0).getNodeType()); + assertEquals("foo", nl.item(0).getNodeValue()); + } + + @Test + public void testNestedChildren() { + XMLFragment x = + (XMLFragment) buildRule.getProject().getReference("with-children"); + assertNotNull(x); + Node n = x.getFragment(); + assertTrue("No attributes", !n.hasAttributes()); + NodeList nl = n.getChildNodes(); + assertEquals(3, nl.getLength()); + + assertEquals(Node.ELEMENT_NODE, nl.item(0).getNodeType()); + Element child1 = (Element) nl.item(0); + assertEquals("child1", child1.getTagName()); + assertTrue(!child1.hasAttributes()); + NodeList nl2 = child1.getChildNodes(); + assertEquals(1, nl2.getLength()); + assertEquals(Node.TEXT_NODE, nl2.item(0).getNodeType()); + assertEquals("foo", nl2.item(0).getNodeValue()); + + assertEquals(Node.ELEMENT_NODE, nl.item(1).getNodeType()); + Element child2 = (Element) nl.item(1); + assertEquals("child2", child2.getTagName()); + assertTrue(child2.hasAttributes()); + nl2 = child2.getChildNodes(); + assertEquals(0, nl2.getLength()); + assertEquals("bar", child2.getAttribute("foo")); + + assertEquals(Node.ELEMENT_NODE, nl.item(2).getNodeType()); + Element child3 = (Element) nl.item(2); + assertEquals("child3", child3.getTagName()); + assertTrue(!child3.hasAttributes()); + nl2 = child3.getChildNodes(); + assertEquals(1, nl2.getLength()); + assertEquals(Node.ELEMENT_NODE, nl2.item(0).getNodeType()); + assertEquals("child4", ((Element) nl2.item(0)).getTagName()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/facade/FacadeTaskHelperTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/facade/FacadeTaskHelperTest.java new file mode 100644 index 00000000..df2d43b3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/facade/FacadeTaskHelperTest.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util.facade; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +/** + * @since Ant 1.5 + */ +public class FacadeTaskHelperTest { + + @Test + public void testPrecedenceRules() { + FacadeTaskHelper fth = new FacadeTaskHelper("foo"); + assertEquals("foo", fth.getImplementation()); + + fth.setMagicValue("bar"); + assertEquals("bar", fth.getImplementation()); + + fth = new FacadeTaskHelper("foo", "bar"); + assertEquals("bar", fth.getImplementation()); + + fth = new FacadeTaskHelper("foo", null); + assertEquals("foo", fth.getImplementation()); + + fth = new FacadeTaskHelper("foo"); + fth.setMagicValue("bar"); + fth.setImplementation("baz"); + assertEquals("baz", fth.getImplementation()); + } + + @Test + public void testHasBeenSet() { + FacadeTaskHelper fth = new FacadeTaskHelper("foo"); + assertTrue("nothing set", !fth.hasBeenSet()); + fth.setMagicValue(null); + assertTrue("magic has not been set", !fth.hasBeenSet()); + fth.setMagicValue("foo"); + assertTrue("magic has been set", fth.hasBeenSet()); + fth.setMagicValue(null); + assertTrue(!fth.hasBeenSet()); + fth.setImplementation("baz"); + assertTrue("set explicitly", fth.hasBeenSet()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/facade/ImplementationSpecificArgumentTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/facade/ImplementationSpecificArgumentTest.java new file mode 100644 index 00000000..a1b97d1d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/facade/ImplementationSpecificArgumentTest.java @@ -0,0 +1,59 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util.facade; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +/** + * @since Ant 1.5 + */ +public class ImplementationSpecificArgumentTest { + + @Test + public void testDependsOnImplementation() { + ImplementationSpecificArgument ia = + new ImplementationSpecificArgument(); + ia.setLine("A B"); + String[] parts = ia.getParts(); + assertNotNull(parts); + assertEquals(2, parts.length); + assertEquals("A", parts[0]); + assertEquals("B", parts[1]); + + parts = ia.getParts(null); + assertNotNull(parts); + assertEquals(2, parts.length); + assertEquals("A", parts[0]); + assertEquals("B", parts[1]); + + ia.setImplementation("foo"); + parts = ia.getParts(null); + assertNotNull(parts); + assertEquals(0, parts.length); + + parts = ia.getParts("foo"); + assertNotNull(parts); + assertEquals(2, parts.length); + assertEquals("A", parts[0]); + assertEquals("B", parts[1]); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaOroMatcherTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaOroMatcherTest.java new file mode 100644 index 00000000..d1405f4a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaOroMatcherTest.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util.regexp; + +/** + * Tests for the jakarta-oro implementation of the RegexpMatcher interface. + * + */ +public class JakartaOroMatcherTest extends RegexpMatcherTest { + + public RegexpMatcher getImplementation() { + return new JakartaOroMatcher(); + } + + public JakartaOroMatcherTest(String name) { + super(name); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaOroRegexpTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaOroRegexpTest.java new file mode 100644 index 00000000..e869c62e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaOroRegexpTest.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util.regexp; + +/** + * Tests for the jakarta-oro implementation of the Regexp interface. + * + */ +public class JakartaOroRegexpTest extends RegexpTest { + + public Regexp getRegexpImplementation() { + return new JakartaOroRegexp(); + } + + public JakartaOroRegexpTest(String name) { + super(name); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpMatcherTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpMatcherTest.java new file mode 100644 index 00000000..3340b59c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpMatcherTest.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util.regexp; + +import java.io.IOException; + +import junit.framework.AssertionFailedError; + +/** + * Tests for the jakarta-regexp implementation of the RegexpMatcher interface. + * + */ +public class JakartaRegexpMatcherTest extends RegexpMatcherTest { + + public RegexpMatcher getImplementation() { + return new JakartaRegexpMatcher(); + } + + public JakartaRegexpMatcherTest(String name) { + super(name); + } + + public void testWindowsLineSeparator2() throws IOException { + try { + super.testWindowsLineSeparator2(); + fail("Should trigger when this bug is fixed. {@since 1.2}"); + } catch (AssertionFailedError e) { + } + } + + /** + * Fails for the same reason as "default" mode in doEndTest2. + */ + public void testUnixLineSeparator() throws IOException { + try { + super.testUnixLineSeparator(); + fail("Should trigger once this bug is fixed. {@since 1.2}"); + } catch (AssertionFailedError e) { + } + } + + + /** + * Fails for "default" mode. + */ + protected void doEndTest2(String text) {} +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java new file mode 100644 index 00000000..078fbb1b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/JakartaRegexpRegexpTest.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util.regexp; + +import java.io.IOException; + +import junit.framework.AssertionFailedError; + +/** + * Tests for the jakarta-regexp implementation of the Regexp interface. + * + */ +public class JakartaRegexpRegexpTest extends RegexpTest { + + public Regexp getRegexpImplementation() { + return new JakartaRegexpRegexp(); + } + + public JakartaRegexpRegexpTest(String name) { + super(name); + } + + public void testWindowsLineSeparator2() throws IOException { + try { + super.testWindowsLineSeparator2(); + fail("Should trigger when this bug is fixed. {@since 1.2}"); + } catch (AssertionFailedError e){ + } + } + + /** + * Fails for the same reason as "default" mode in doEndTest2. + */ + public void testUnixLineSeparator() throws IOException { + try { + super.testUnixLineSeparator(); + fail("Should trigger once this bug is fixed. {@since 1.2}"); + } catch (AssertionFailedError e){ + } + } + + /** + * Fails for "default" mode. + */ + protected void doEndTest2(String text) {} +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcherTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcherTest.java new file mode 100644 index 00000000..c042e715 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpMatcherTest.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util.regexp; + +import java.io.IOException; + +import junit.framework.AssertionFailedError; + +/** + * Tests for the JDK 1.4 implementation of the RegexpMatcher interface. + * + */ +public class Jdk14RegexpMatcherTest extends RegexpMatcherTest { + + public RegexpMatcher getImplementation() { + return new Jdk14RegexpMatcher(); + } + + public Jdk14RegexpMatcherTest(String name) { + super(name); + } + + public void testParagraphCharacter() throws IOException { + try { + super.testParagraphCharacter(); + fail("Should trigger once fixed. {@since JDK 1.4RC1}"); + } catch (AssertionFailedError e){ + } + } + + public void testLineSeparatorCharacter() throws IOException { + try { + super.testLineSeparatorCharacter(); + fail("Should trigger once fixed. {@since JDK 1.4RC1}"); + } catch (AssertionFailedError e){ + } + } + + public void testStandaloneCR() throws IOException { + try { + super.testStandaloneCR(); + fail("Should trigger once fixed. {@since JDK 1.4RC1}"); + } catch (AssertionFailedError e){ + } + } + + public void testWindowsLineSeparator() throws IOException { + try { + super.testWindowsLineSeparator(); + fail("Should trigger once fixed. {@since JDK 1.4RC1}"); + } catch (AssertionFailedError e){ + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java new file mode 100644 index 00000000..2b60406a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/Jdk14RegexpRegexpTest.java @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util.regexp; + +import java.io.IOException; + +import junit.framework.AssertionFailedError; + +/** + * Tests for the JDK 1.4 implementation of the Regexp interface. + * + */ +public class Jdk14RegexpRegexpTest extends RegexpTest { + + public Regexp getRegexpImplementation() { + return new Jdk14RegexpRegexp(); + } + + public Jdk14RegexpRegexpTest(String name) { + super(name); + } + + public void testParagraphCharacter() throws IOException { + try { + super.testParagraphCharacter(); + fail("Should trigger once fixed. {@since JDK 1.4RC1}"); + } catch (AssertionFailedError e){ + } + } + + public void testLineSeparatorCharacter() throws IOException { + try { + super.testLineSeparatorCharacter(); + fail("Should trigger once fixed. {@since JDK 1.4RC1}"); + } catch (AssertionFailedError e){ + } + } + + public void testStandaloneCR() throws IOException { + try { + super.testStandaloneCR(); + fail("Should trigger once fixed. {@since JDK 1.4RC1}"); + } catch (AssertionFailedError e){ + } + } + + public void testWindowsLineSeparator() throws IOException { + try { + super.testWindowsLineSeparator(); + fail("Should trigger once fixed. {@since JDK 1.4RC1}"); + } catch (AssertionFailedError e){ + } + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java new file mode 100644 index 00000000..09508274 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpMatcherTest.java @@ -0,0 +1,204 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util.regexp; + +import java.io.IOException; +import java.util.Vector; + +import junit.framework.TestCase; + +/** + * Tests for all implementations of the RegexpMatcher interface. + * + */ +public abstract class RegexpMatcherTest extends TestCase { + + public final static String UNIX_LINE = "\n"; + + private RegexpMatcher reg; + + public abstract RegexpMatcher getImplementation(); + + protected final RegexpMatcher getReg() {return reg;} + + public RegexpMatcherTest(String name) { + super(name); + } + + public void setUp() { + reg = getImplementation(); + } + + public void testMatches() { + reg.setPattern("aaaa"); + assertTrue("aaaa should match itself", reg.matches("aaaa")); + assertTrue("aaaa should match xaaaa", reg.matches("xaaaa")); + assertTrue("aaaa shouldn\'t match xaaa", !reg.matches("xaaa")); + reg.setPattern("^aaaa"); + assertTrue("^aaaa shouldn\'t match xaaaa", !reg.matches("xaaaa")); + assertTrue("^aaaa should match aaaax", reg.matches("aaaax")); + reg.setPattern("aaaa$"); + assertTrue("aaaa$ shouldn\'t match aaaax", !reg.matches("aaaax")); + assertTrue("aaaa$ should match xaaaa", reg.matches("xaaaa")); + reg.setPattern("[0-9]+"); + assertTrue("[0-9]+ should match 123", reg.matches("123")); + assertTrue("[0-9]+ should match 1", reg.matches("1")); + assertTrue("[0-9]+ shouldn\'t match \'\'", !reg.matches("")); + assertTrue("[0-9]+ shouldn\'t match a", !reg.matches("a")); + reg.setPattern("[0-9]*"); + assertTrue("[0-9]* should match 123", reg.matches("123")); + assertTrue("[0-9]* should match 1", reg.matches("1")); + assertTrue("[0-9]* should match \'\'", reg.matches("")); + assertTrue("[0-9]* should match a", reg.matches("a")); + reg.setPattern("([0-9]+)=\\1"); + assertTrue("([0-9]+)=\\1 should match 1=1", reg.matches("1=1")); + assertTrue("([0-9]+)=\\1 shouldn\'t match 1=2", !reg.matches("1=2")); + } + + public void testGroups() { + reg.setPattern("aaaa"); + Vector v = reg.getGroups("xaaaa"); + assertEquals("No parens -> no extra groups", 1, v.size()); + assertEquals("Trivial match with no parens", "aaaa", + (String) v.elementAt(0)); + + reg.setPattern("(aaaa)"); + v = reg.getGroups("xaaaa"); + assertEquals("Trivial match with single paren", 2, v.size()); + assertEquals("Trivial match with single paren, full match", "aaaa", + (String) v.elementAt(0)); + assertEquals("Trivial match with single paren, matched paren", "aaaa", + (String) v.elementAt(0)); + + reg.setPattern("(a+)b(b+)"); + v = reg.getGroups("xaabb"); + assertEquals(3, v.size()); + assertEquals("aabb", (String) v.elementAt(0)); + assertEquals("aa", (String) v.elementAt(1)); + assertEquals("b", (String) v.elementAt(2)); + } + + public void testBugzillaReport14619() { + reg.setPattern("^(.*)/src/((.*/)*)([a-zA-Z0-9_\\.]+)\\.java$"); + Vector v = reg.getGroups("de/tom/src/Google.java"); + assertEquals(5, v.size()); + assertEquals("de/tom", v.elementAt(1)); + assertEquals("", v.elementAt(2)); + assertEquals("", v.elementAt(3)); + assertEquals("Google", v.elementAt(4)); + } + + public void testCaseInsensitiveMatch() { + reg.setPattern("aaaa"); + assertTrue("aaaa doesn't match AAaa", !reg.matches("AAaa")); + assertTrue("aaaa matches AAaa ignoring case", + reg.matches("AAaa", RegexpMatcher.MATCH_CASE_INSENSITIVE)); + } + + +// make sure there are no issues concerning line separator interpretation +// a line separator for regex (perl) is always a unix line (ie \n) + + public void testParagraphCharacter() throws IOException { + reg.setPattern("end of text$"); + assertTrue("paragraph character", !reg.matches("end of text\u2029")); + } + + public void testLineSeparatorCharacter() throws IOException { + reg.setPattern("end of text$"); + assertTrue("line-separator character", !reg.matches("end of text\u2028")); + } + + public void testNextLineCharacter() throws IOException { + reg.setPattern("end of text$"); + assertTrue("next-line character", !reg.matches("end of text\u0085")); + } + + public void testStandaloneCR() throws IOException { + reg.setPattern("end of text$"); + assertTrue("standalone CR", !reg.matches("end of text\r")); + } + + public void testWindowsLineSeparator() throws IOException { + reg.setPattern("end of text$"); + assertTrue("Windows line separator", !reg.matches("end of text\r\n")); + } + + public void testWindowsLineSeparator2() throws IOException { + reg.setPattern("end of text\r$"); + assertTrue("Windows line separator", reg.matches("end of text\r\n")); + } + + public void testUnixLineSeparator() throws IOException { + reg.setPattern("end of text$"); + assertTrue("Unix line separator", reg.matches("end of text\n")); + } + + + public void testMultiVersusSingleLine() throws IOException { + StringBuffer buf = new StringBuffer(); + buf.append("Line1").append(UNIX_LINE); + buf.append("starttest Line2").append(UNIX_LINE); + buf.append("Line3 endtest").append(UNIX_LINE); + buf.append("Line4").append(UNIX_LINE); + String text = buf.toString(); + + doStartTest1(text); + doStartTest2(text); + doEndTest1(text); + doEndTest2(text); + } + + protected void doStartTest1(String text) { + reg.setPattern("^starttest"); + assertTrue("^starttest in default mode", !reg.matches(text)); + assertTrue("^starttest in single line mode", + !reg.matches(text, RegexpMatcher.MATCH_SINGLELINE)); + assertTrue("^starttest in multi line mode", + reg.matches(text, RegexpMatcher.MATCH_MULTILINE)); + } + + protected void doStartTest2(String text) { + reg.setPattern("^Line1"); + assertTrue("^Line1 in default mode", reg.matches(text)); + assertTrue("^Line1 in single line mode", + reg.matches(text, RegexpMatcher.MATCH_SINGLELINE)); + assertTrue("^Line1 in multi line mode", + reg.matches(text, RegexpMatcher.MATCH_MULTILINE)); + } + + protected void doEndTest1(String text) { + reg.setPattern("endtest$"); + assertTrue("endtest$ in default mode", !reg.matches(text)); + assertTrue("endtest$ in single line mode", + !reg.matches(text, RegexpMatcher.MATCH_SINGLELINE)); + assertTrue("endtest$ in multi line mode", + reg.matches(text, RegexpMatcher.MATCH_MULTILINE)); + } + + protected void doEndTest2(String text) { + reg.setPattern("Line4$"); + assertTrue("Line4$ in default mode", reg.matches(text)); + assertTrue("Line4$ in single line mode", + reg.matches(text, RegexpMatcher.MATCH_SINGLELINE)); + assertTrue("Line4$ in multi line mode", + reg.matches(text, RegexpMatcher.MATCH_MULTILINE)); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpTest.java new file mode 100644 index 00000000..5cfe8c97 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/ant/util/regexp/RegexpTest.java @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.ant.util.regexp; + +/** + * Tests for all implementations of the Regexp interface. + * + */ +public abstract class RegexpTest extends RegexpMatcherTest { + + private static final String test = "abcdefg-abcdefg"; + private static final String pattern = "ab([^d]*)d([^f]*)f"; + + public RegexpTest(String name) { + super(name); + } + + public final RegexpMatcher getImplementation() { + return getRegexpImplementation(); + } + + public abstract Regexp getRegexpImplementation(); + + public void testSubstitution() { + Regexp reg = (Regexp) getReg(); + reg.setPattern(pattern); + assertTrue(reg.matches(test)); + assertEquals("abedcfg-abcdefg", reg.substitute(test, "ab\\2d\\1f", + Regexp.MATCH_DEFAULT)); + } + + public void testReplaceFirstSubstitution() { + Regexp reg = (Regexp) getReg(); + reg.setPattern(pattern); + assertTrue(reg.matches(test)); + assertEquals("abedcfg-abcdefg", reg.substitute(test, "ab\\2d\\1f", + Regexp.REPLACE_FIRST)); + } + + public void testReplaceAllSubstitution() { + Regexp reg = (Regexp) getReg(); + reg.setPattern(pattern); + assertTrue(reg.matches(test)); + assertEquals("abedcfg-abedcfg", reg.substitute(test, "ab\\2d\\1f", + Regexp.REPLACE_ALL)); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/bzip2/BlockSortTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/bzip2/BlockSortTest.java new file mode 100644 index 00000000..12b871ed --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/bzip2/BlockSortTest.java @@ -0,0 +1,171 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.tools.bzip2; + +import org.junit.Test; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +public class BlockSortTest { + + private static final byte[] FIXTURE = { 0, 1, (byte) 252, (byte) 253, (byte) 255, + (byte) 254, 3, 2, (byte) 128 }; + + /* + Burrows-Wheeler transform of fixture the manual way: + + * build the matrix + + 0, 1, 252, 253, 255, 254, 3, 2, 128 + 1, 252, 253, 255, 254, 3, 2, 128, 0 + 252, 253, 255, 254, 3, 2, 128, 0, 1 + 253, 255, 254, 3, 2, 128, 0, 1, 252 + 255, 254, 3, 2, 128, 0, 1, 252, 253 + 254, 3, 2, 128, 0, 1, 252, 253, 255 + 3, 2, 128, 0, 1, 252, 253, 255, 254 + 2, 128, 0, 1, 252, 253, 255, 254, 3 + 128, 0, 1, 252, 253, 255, 254, 3, 2 + + * sort it + + 0, 1, 252, 253, 255, 254, 3, 2, 128 + 1, 252, 253, 255, 254, 3, 2, 128, 0 + 2, 128, 0, 1, 252, 253, 255, 254, 3 + 3, 2, 128, 0, 1, 252, 253, 255, 254 + 128, 0, 1, 252, 253, 255, 254, 3, 2 + 252, 253, 255, 254, 3, 2, 128, 0, 1 + 253, 255, 254, 3, 2, 128, 0, 1, 252 + 254, 3, 2, 128, 0, 1, 252, 253, 255 + 255, 254, 3, 2, 128, 0, 1, 252, 253 + + * grab last column + + 128, 0, 3, 254, 2, 1, 252, 255, 253 + + and the original line has been 0 + */ + + private static final byte[] FIXTURE_BWT = { (byte) 128, 0, 3, (byte) 254, 2, 1, + (byte) 252, (byte) 255, (byte) 253 }; + + private static final int[] FIXTURE_SORTED = { + 0, 1, 7, 6, 8, 2, 3, 5, 4 + }; + + private static final byte[] FIXTURE2 = { + 'C', 'o', 'm', 'm', 'o', 'n', 's', ' ', 'C', 'o', 'm', 'p', 'r', 'e', 's', 's', + }; + + private static final byte[] FIXTURE2_BWT = { + 's', 's', ' ', 'r', 'o', 'm', 'o', 'o', 'C', 'C', 'm', 'm', 'p', 'n', 's', 'e', + }; + + @Test + public void testSortFixture() { + DS ds = setUpFixture(); + ds.s.blockSort(ds.data, FIXTURE.length - 1); + assertFixtureSorted(ds.data); + assertEquals(0, ds.data.origPtr); + } + + @Test + public void testSortFixtureMainSort() { + DS ds = setUpFixture(); + ds.s.mainSort(ds.data, FIXTURE.length - 1); + assertFixtureSorted(ds.data); + } + + @Test + public void testSortFixtureFallbackSort() { + DS ds = setUpFixture(); + ds.s.fallbackSort(ds.data, FIXTURE.length - 1); + assertFixtureSorted(ds.data); + } + + @Test + public void testSortFixture2() { + DS ds = setUpFixture2(); + ds.s.blockSort(ds.data, FIXTURE2.length - 1); + assertFixture2Sorted(ds.data); + assertEquals(1, ds.data.origPtr); + } + + @Test + public void testSortFixture2MainSort() { + DS ds = setUpFixture2(); + ds.s.mainSort(ds.data, FIXTURE2.length - 1); + assertFixture2Sorted(ds.data); + } + + @Test + public void testSortFixture2FallbackSort() { + DS ds = setUpFixture2(); + ds.s.fallbackSort(ds.data, FIXTURE2.length - 1); + assertFixture2Sorted(ds.data); + } + + @Test + public void testFallbackSort() { + CBZip2OutputStream.Data data = new CBZip2OutputStream.Data(1); + BlockSort s = new BlockSort(data); + int[] fmap = new int[FIXTURE.length]; + s.fallbackSort(fmap, FIXTURE, FIXTURE.length); + assertArrayEquals(FIXTURE_SORTED, fmap); + } + + private DS setUpFixture() { + return setUpFixture(FIXTURE); + } + + private void assertFixtureSorted(CBZip2OutputStream.Data data) { + assertFixtureSorted(data, FIXTURE, FIXTURE_BWT); + } + + private DS setUpFixture2() { + return setUpFixture(FIXTURE2); + } + + private void assertFixture2Sorted(CBZip2OutputStream.Data data) { + assertFixtureSorted(data, FIXTURE2, FIXTURE2_BWT); + } + + private DS setUpFixture(byte[] fixture) { + CBZip2OutputStream.Data data = new CBZip2OutputStream.Data(1); + System.arraycopy(fixture, 0, data.block, 1, fixture.length); + return new DS(data, new BlockSort(data)); + } + + private void assertFixtureSorted(CBZip2OutputStream.Data data, + byte[] fixture, byte[] fixtureBwt) { + assertEquals(fixture[fixture.length - 1], data.block[0]); + for (int i = 0; i < fixture.length; i++) { + assertEquals(fixtureBwt[i], data.block[data.fmap[i]]); + } + } + + private static class DS { + private final CBZip2OutputStream.Data data; + private final BlockSort s; + DS(CBZip2OutputStream.Data data, BlockSort s) { + this.data = data; + this.s = s; + } + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java new file mode 100644 index 00000000..50e0e576 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/bzip2/CBZip2StreamTest.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.bzip2; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class CBZip2StreamTest { + + @Test + public void testNullPointer() throws IOException { + try { + new CBZip2InputStream(new ByteArrayInputStream(new byte[0])); + fail("expected an exception"); + } catch (IOException e) { + // expected + //TODO assert exception values + } + } + + @Test + public void testDivisionByZero() throws IOException { + CBZip2OutputStream cb = new CBZip2OutputStream(new ByteArrayOutputStream()); + cb.close(); + // expected no exception + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/mail/MailMessageTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/mail/MailMessageTest.java new file mode 100644 index 00000000..87e2f754 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/mail/MailMessageTest.java @@ -0,0 +1,707 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.mail; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintStream; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; +import java.util.Enumeration; +import java.util.Vector; + +import org.apache.tools.ant.BuildException; +import org.junit.Before; +import org.junit.Test; +import org.junit.internal.AssumptionViolatedException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; + +/** + * JUnit testcases for org.apache.tools.mail.MailMessage. + * + * @since Ant 1.6 + */ +public class MailMessageTest { + + // 27224 = magic (a random port which is unlikely to be in use) + private static int TEST_PORT = 27224; + + private String local = null; + + @Before + public void setUp() { + try { + local = InetAddress.getLocalHost().getHostName(); + } catch (java.net.UnknownHostException uhe) { + // ignore + } + } + + /** + * Test an example that is similar to the one given in the API + * If this testcase takes >90s to complete, it is very likely that + * the two threads are blocked waiting for each other and Thread.join() + * timed out. + * @throws InterruptedException + */ + @Test + public void testAPIExample() throws InterruptedException { + + ServerThread testMailServer = new ServerThread(); + Thread server = new Thread(testMailServer); + server.start(); + + ClientThread testMailClient = new ClientThread(); + + testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>"); + testMailClient.to("to@you.com"); + testMailClient.cc("cc1@you.com"); + testMailClient.cc("cc2@you.com"); + testMailClient.bcc("bcc@you.com"); + testMailClient.setSubject("Test subject"); + testMailClient.setMessage( "test line 1\n" + + "test line 2" ); + + Thread client = new Thread(testMailClient); + client.start(); + + server.join(60 * 1000); // 60s + client.join(30 * 1000); // a further 30s + + String result = testMailServer.getResult(); + String expectedResult = "220 test SMTP EmailTaskTest\r\n" + + "HELO " + local + "\r\n" + + "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" + + "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" + + "250\r\n" + + "RCPT TO: <to@you.com>\r\n" + + "250\r\n" + + "RCPT TO: <cc1@you.com>\r\n" + + "250\r\n" + + "RCPT TO: <cc2@you.com>\r\n" + + "250\r\n" + + "RCPT TO: <bcc@you.com>\r\n" + + "250\r\n" + + "DATA\r\n" + + "354\r\n" + + "Subject: Test subject\r\n" + + "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" + + "To: to@you.com\r\n" + + "Cc: cc1@you.com, cc2@you.com\r\n" + + "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" + + "\r\n" + + "test line 1\r\n" + + "test line 2\r\n" + + "\r\n" + + ".\r\n" + + "250\r\n" + + "QUIT\r\n" + + "221\r\n"; + /*for (int icounter = 0; icounter<expectedResult.length(); icounter++) { + if (icounter < result.length()) { + if (expectedResult.charAt(icounter) != result.charAt(icounter)) { + System.out.println("posit " + icounter + " expected " + + expectedResult.charAt(icounter) + + " result " + result.charAt(icounter)); + } + } + } + if (expectedResult.length()>result.length()) { + System.out.println("excedent of expected result " + + expectedResult.substring(result.length())); + } + if (expectedResult.length()<result.length()) { + System.out.println("excedent of result " + + result.substring(expectedResult.length())); + }*/ + assertEquals(expectedResult.length(), result.length()); + assertEquals(expectedResult, result); // order of headers cannot be guaranteed + assertFalse(testMailClient.getFailMessage(), testMailClient.isFailed()); + } + + /** + * Test a MailMessage with no cc or bcc lines + * @throws InterruptedException + */ + @Test + public void testToOnly() throws InterruptedException { + ServerThread testMailServer = new ServerThread(); + Thread server = new Thread(testMailServer); + server.start(); + + ClientThread testMailClient = new ClientThread(); + + testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>"); + testMailClient.to("to@you.com"); + testMailClient.setSubject("Test subject"); + testMailClient.setMessage( "test line 1\n" + + "test line 2" ); + + Thread client = new Thread(testMailClient); + client.start(); + + server.join(60 * 1000); // 60s + client.join(30 * 1000); // a further 30s + + String result = testMailServer.getResult(); + String expectedResult = "220 test SMTP EmailTaskTest\r\n" + + "HELO " + local + "\r\n" + + "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" + + "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" + + "250\r\n" + + "RCPT TO: <to@you.com>\r\n" + + "250\r\n" + + "DATA\r\n" + + "354\r\n" + + "Subject: Test subject\r\n" + + "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" + + "To: to@you.com\r\n" + + "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" + + "\r\n" + + "test line 1\r\n" + + "test line 2\r\n" + + "\r\n" + + ".\r\n" + + "250\r\n" + + "QUIT\r\n" + + "221\r\n"; + assertEquals(expectedResult.length(), result.length()); + assertEquals(expectedResult, result); // order of headers cannot be guaranteed + assertFalse(testMailClient.getFailMessage(), testMailClient.isFailed()); + } + + + /** + * Test a MailMessage with no to or bcc lines + * @throws InterruptedException + */ + @Test + public void testCcOnly() throws InterruptedException { + ServerThread testMailServer = new ServerThread(); + Thread server = new Thread(testMailServer); + server.start(); + + ClientThread testMailClient = new ClientThread(); + + testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>"); + testMailClient.cc("cc@you.com"); + testMailClient.setSubject("Test subject"); + testMailClient.setMessage( "test line 1\n" + + "test line 2" ); + + Thread client = new Thread(testMailClient); + client.start(); + + server.join(60 * 1000); // 60s + client.join(30 * 1000); // a further 30s + + String result = testMailServer.getResult(); + String expectedResult = "220 test SMTP EmailTaskTest\r\n" + + "HELO " + local + "\r\n" + + "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" + + "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" + + "250\r\n" + + "RCPT TO: <cc@you.com>\r\n" + + "250\r\n" + + "DATA\r\n" + + "354\r\n" + + "Subject: Test subject\r\n" + + "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" + + "Cc: cc@you.com\r\n" + + "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" + + "\r\n" + + "test line 1\r\n" + + "test line 2\r\n" + + "\r\n" + + ".\r\n" + + "250\r\n" + + "QUIT\r\n" + + "221\r\n"; + assertEquals(expectedResult.length(), result.length()); + assertEquals(expectedResult, result); + assertFalse(testMailClient.getFailMessage(), testMailClient.isFailed()); + } + + + /** + * Test a MailMessage with no to or cc lines + * @throws InterruptedException + */ + @Test + public void testBccOnly() throws InterruptedException { + ServerThread testMailServer = new ServerThread(); + Thread server = new Thread(testMailServer); + server.start(); + + ClientThread testMailClient = new ClientThread(); + + testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>"); + testMailClient.bcc("bcc@you.com"); + testMailClient.setSubject("Test subject"); + testMailClient.setMessage( "test line 1\n" + + "test line 2" ); + + Thread client = new Thread(testMailClient); + client.start(); + + server.join(60 * 1000); // 60s + client.join(30 * 1000); // a further 30s + + String result = testMailServer.getResult(); + String expectedResult = "220 test SMTP EmailTaskTest\r\n" + + "HELO " + local + "\r\n" + + "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" + + "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" + + "250\r\n" + + "RCPT TO: <bcc@you.com>\r\n" + + "250\r\n" + + "DATA\r\n" + + "354\r\n" + + "Subject: Test subject\r\n" + + "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" + + "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" + + "\r\n" + + "test line 1\r\n" + + "test line 2\r\n" + + "\r\n" + + ".\r\n" + + "250\r\n" + + "QUIT\r\n" + + "221\r\n"; + assertEquals( expectedResult.length(), result.length() ); + assertEquals( expectedResult, result ); + assertFalse(testMailClient.getFailMessage(), testMailClient.isFailed()); + } + + + /** + * Test a MailMessage with no subject line + * Subject is an optional field (RFC 822 s4.1) + * @throws InterruptedException + */ + @Test + public void testNoSubject() throws InterruptedException { + ServerThread testMailServer = new ServerThread(); + Thread server = new Thread(testMailServer); + server.start(); + + ClientThread testMailClient = new ClientThread(); + + testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>"); + testMailClient.to("to@you.com"); + testMailClient.setMessage( "test line 1\n" + + "test line 2" ); + + Thread client = new Thread(testMailClient); + client.start(); + + server.join(60 * 1000); // 60s + client.join(30 * 1000); // a further 30s + + String result = testMailServer.getResult(); + String expectedResult = "220 test SMTP EmailTaskTest\r\n" + + "HELO " + local + "\r\n" + + "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" + + "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" + + "250\r\n" + + "RCPT TO: <to@you.com>\r\n" + + "250\r\n" + + "DATA\r\n" + + "354\r\n" + + "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" + + "To: to@you.com\r\n" + + "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" + + "\r\n" + + "test line 1\r\n" + + "test line 2\r\n" + + "\r\n" + + ".\r\n" + + "250\r\n" + + "QUIT\r\n" + + "221\r\n"; + assertEquals( expectedResult.length(), result.length() ); + assertEquals( expectedResult, result ); + assertFalse(testMailClient.getFailMessage(), testMailClient.isFailed()); + } + + + /** + * Test a MailMessage with empty body message + * @throws InterruptedException + */ + @Test + public void testEmptyBody() throws InterruptedException { + ServerThread testMailServer = new ServerThread(); + Thread server = new Thread(testMailServer); + server.start(); + + ClientThread testMailClient = new ClientThread(); + + testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>"); + testMailClient.to("to@you.com"); + testMailClient.setSubject("Test subject"); + testMailClient.setMessage(""); + + Thread client = new Thread(testMailClient); + client.start(); + + server.join(60 * 1000); // 60s + client.join(30 * 1000); // a further 30s + + String result = testMailServer.getResult(); + String expectedResult = "220 test SMTP EmailTaskTest\r\n" + + "HELO " + local + "\r\n" + + "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" + + "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" + + "250\r\n" + + "RCPT TO: <to@you.com>\r\n" + + "250\r\n" + + "DATA\r\n" + + "354\r\n" + + "Subject: Test subject\r\n" + + "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" + + "To: to@you.com\r\n" + + "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" + + "\r\n" + + "\r\n" + + "\r\n" + + ".\r\n" + + "250\r\n" + + "QUIT\r\n" + + "221\r\n"; + assertEquals(expectedResult.length(), result.length()); + assertEquals(expectedResult, result); + assertFalse(testMailClient.getFailMessage(), testMailClient.isFailed()); + } + + + /** + * Test a MailMessage with US-ASCII character set + * The next four testcase can be kinda hard to debug as Ant will often + * print the junit failure in US-ASCII. + * @throws InterruptedException + */ + @Test + public void testAsciiCharset() throws InterruptedException { + + ServerThread testMailServer = new ServerThread(); + Thread server = new Thread(testMailServer); + server.start(); + + ClientThread testMailClient = new ClientThread(); + + testMailClient.from("Mail Message <EmailTaskTest@ant.apache.org>"); + testMailClient.to("Ceki G\u00fclc\u00fc <abuse@mail-abuse.org>"); + testMailClient.setSubject("Test subject"); + testMailClient.setMessage(""); + + Thread client = new Thread(testMailClient); + client.start(); + + server.join(60 * 1000); // 60s + client.join(30 * 1000); // a further 30s + + String result = testMailServer.getResult(); + String expectedResult = "220 test SMTP EmailTaskTest\r\n" + + "HELO " + local + "\r\n" + + "250 " + local + " Hello " + local + " [127.0.0.1], pleased to meet you\r\n" + + "MAIL FROM: <EmailTaskTest@ant.apache.org>\r\n" + + "250\r\n" + + "RCPT TO: <abuse@mail-abuse.org>\r\n" + + "250\r\n" + + "DATA\r\n" + + "354\r\n" + + "Subject: Test subject\r\n" + + "From: Mail Message <EmailTaskTest@ant.apache.org>\r\n" + + "To: Ceki G\u00fclc\u00fc <abuse@mail-abuse.org>\r\n" + + "X-Mailer: org.apache.tools.mail.MailMessage (ant.apache.org)\r\n" + + "\r\n" + + "\r\n" + + "\r\n" + + ".\r\n" + + "250\r\n" + + "QUIT\r\n" + + "221\r\n"; + ByteArrayOutputStream baos1 = new ByteArrayOutputStream(); + ByteArrayOutputStream baos2 = new ByteArrayOutputStream(); + PrintStream bos1 = new PrintStream(baos1, true); + PrintStream bos2 = new PrintStream(baos2, true); + + bos1.print(expectedResult); + bos2.print(result); + + assertEquals( "expected message length != actual message length " + + "in testAsciiCharset()", expectedResult.length(), result.length() ); + assertEquals( "baos1 and baos2 should be the same in testAsciiCharset()", + baos1.toString(), baos2.toString() ); // order of headers cannot be guaranteed + assertFalse(testMailClient.getFailMessage(), testMailClient.isFailed()); + } + + + + + /** + * A private test class that pretends to be a mail transfer agent + */ + private class ServerThread implements Runnable { + + private StringBuffer sb = null; + private boolean loop = false; + ServerSocket ssock = null; + Socket sock = null; + BufferedWriter out = null; + BufferedReader in = null; + private boolean data = false; // state engine: false=envelope, true=message + + public void run() { + + try { + ssock = new ServerSocket(TEST_PORT); + sock = ssock.accept(); // wait for connection + in = new BufferedReader( new InputStreamReader( + sock.getInputStream()) ); + out = new BufferedWriter( new OutputStreamWriter( + sock.getOutputStream() ) ); + sb = new StringBuffer(); + send( "220 test SMTP EmailTaskTest\r\n" ); + loop = true; + while ( loop ) { + String response = in.readLine(); + if ( response == null ) { + loop = false; + break; + } + sb.append( response + "\r\n" ); + + if ( !data && response.startsWith( "HELO" ) ) { + send( "250 " + local + " Hello " + local + " " + + "[127.0.0.1], pleased to meet you\r\n" ); + } else if ( !data && response.startsWith("MAIL") ) { + send( "250\r\n" ); + } else if ( !data && response.startsWith("RCPT")) { + send( "250\r\n" ); + } else if (!data && response.startsWith("DATA")) { + send( "354\r\n" ); + data = true; + } else if (data && response.equals(".") ) { + send( "250\r\n" ); + data = false; + } else if (!data && response.startsWith("QUIT")) { + send( "221\r\n" ); + loop = false; + } else if (!data) { + //throw new IllegalStateException("Command unrecognized: " + // + response); + send( "500 5.5.1 Command unrecognized: \"" + + response + "\"\r\n" ); + loop = false; + } else { + // sb.append( response + "\r\n" ); + } + + } // while + } catch (IOException ioe) { + throw new BuildException(ioe); + } finally { + disconnect(); + } + } + + private void send(String retmsg) throws IOException { + out.write( retmsg ); + out.flush(); + sb.append( retmsg ); + } + + private void disconnect() { + if (out != null) { + try { + out.flush(); + out.close(); + out = null; + } catch (IOException e) { + // ignore + } + } + if (in != null) { + try { + in.close(); + in = null; + } catch (IOException e) { + // ignore + } + } + if (sock != null) { + try { + sock.close(); + sock = null; + } catch (IOException e) { + // ignore + } + } + if (ssock != null) { + try { + ssock.close(); + ssock = null; + } catch (IOException e) { + // ignore + } + } + } + + public synchronized String getResult() { + loop = false; + return sb.toString(); + } + + } + + /** + * A private test class that wraps MailMessage + */ + private class ClientThread implements Runnable { + + private MailMessage msg; + private boolean fail = false; + private String failMessage = null; + + protected String from = null; + protected String subject = null; + protected String message = null; + + protected Vector replyToList = new Vector(); + protected Vector toList = new Vector(); + protected Vector ccList = new Vector(); + protected Vector bccList = new Vector(); + + + public void run() { + for (int i = 9; i > 0; i--) { + try { + msg = new MailMessage("localhost", TEST_PORT); + } catch (java.net.ConnectException ce) { + try { + Thread.sleep(10 * 1000); + } catch (InterruptedException ie) { + throw new AssumptionViolatedException("Thread interrupted", ie); + } + } catch (IOException ioe) { + fail = true; + failMessage = "IOException: " + ioe; + return; + } + if (msg != null) { + break; + } + } + + if (msg == null) { + fail = true; + failMessage = "java.net.ConnectException: Connection refused"; + return; + } + + try { + msg.from(from); + + Enumeration e; + + e = replyToList.elements(); + while (e.hasMoreElements()) { + msg.replyto(e.nextElement().toString()); + } + + e = toList.elements(); + while (e.hasMoreElements()) { + msg.to(e.nextElement().toString()); + } + + e = ccList.elements(); + while (e.hasMoreElements()) { + msg.cc(e.nextElement().toString()); + } + + e = bccList.elements(); + while (e.hasMoreElements()) { + msg.bcc(e.nextElement().toString()); + } + + if (subject != null) { + msg.setSubject(subject); + } + + if (message != null ) { + PrintStream out = msg.getPrintStream(); + out.println( message ); + } + + msg.sendAndClose(); + } catch (IOException ioe) { + fail = true; + failMessage = "IOException: " + ioe; + return; + } + } + + public boolean isFailed() { + return fail; + } + + public String getFailMessage() { + return failMessage; + } + + public void replyTo(String replyTo) { + replyToList.add(replyTo); + } + + public void to(String to) { + toList.add(to); + } + + public void cc(String cc) { + ccList.add(cc); + } + + public void bcc(String bcc) { + bccList.add(bcc); + } + + public void setSubject(String subject) { + this.subject = subject; + } + + public void from(String from) { + this.from = from; + } + + public void setMessage(String message) { + this.message = message; + } + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/tar/TarEntryTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/tar/TarEntryTest.java new file mode 100644 index 00000000..e942cdb3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/tar/TarEntryTest.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.tar; + +import org.junit.Test; + +/** + * @since Ant 1.6 + */ +public class TarEntryTest { + + /** + * demonstrates bug 18105 on OSes with os.name shorter than 7. + */ + @Test + public void testFileConstructor() { + new TarEntry(new java.io.File("/foo")); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/tar/TarOutputStreamTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/tar/TarOutputStreamTest.java new file mode 100644 index 00000000..cb65e2df --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/tar/TarOutputStreamTest.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.tar; + +import org.junit.Test; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +public class TarOutputStreamTest { + + @Test + public void testClose() throws IOException { + ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); + TarOutputStream stream = new TarOutputStream(byteStream); + stream.close(); + stream.close(); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/tar/TarRoundTripTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/tar/TarRoundTripTest.java new file mode 100644 index 00000000..98e6378d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/tar/TarRoundTripTest.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.tar; + +import org.junit.Test; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + +public class TarRoundTripTest { + + private static final String LONG_NAME + = "this/path/name/contains/more/than/one/hundred/characters/in/order/" + + "to/test/the/GNU/long/file/name/capability/round/tripped"; + + /** + * test round-tripping long (GNU) entries + */ + @Test + public void testLongRoundTrippingGNU() throws IOException { + testLongRoundTripping(TarOutputStream.LONGFILE_GNU); + } + + /** + * test round-tripping long (POSIX) entries + */ + @Test + public void testLongRoundTrippingPOSIX() throws IOException { + testLongRoundTripping(TarOutputStream.LONGFILE_POSIX); + } + + private void testLongRoundTripping(int mode) throws IOException { + TarEntry original = new TarEntry(LONG_NAME); + assertTrue("over 100 chars", LONG_NAME.length() > 100); + assertEquals("original name", LONG_NAME, original.getName()); + + + ByteArrayOutputStream buff = new ByteArrayOutputStream(); + TarOutputStream tos = new TarOutputStream(buff); + tos.setLongFileMode(mode); + tos.putNextEntry(original); + tos.closeEntry(); + tos.close(); + + TarInputStream tis + = new TarInputStream(new ByteArrayInputStream(buff.toByteArray())); + TarEntry tripped = tis.getNextEntry(); + assertEquals("round-tripped name", LONG_NAME, tripped.getName()); + assertNull("no more entries", tis.getNextEntry()); + tis.close(); + } +} + + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java new file mode 100644 index 00000000..873b3f50 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/AsiExtraFieldTest.java @@ -0,0 +1,163 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.zip; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * JUnit testcases for org.apache.tools.zip.AsiExtraField. + * + */ +public class AsiExtraFieldTest implements UnixStat { + + /** + * Test file mode magic. + */ + @Test + public void testModes() { + AsiExtraField a = new AsiExtraField(); + a.setMode(0123); + assertEquals("plain file", 0100123, a.getMode()); + a.setDirectory(true); + assertEquals("directory", 040123, a.getMode()); + a.setLinkedFile("test"); + assertEquals("symbolic link", 0120123, a.getMode()); + } + + /** + * Test content. + */ + @Test + public void testContent() { + AsiExtraField a = new AsiExtraField(); + a.setMode(0123); + a.setUserId(5); + a.setGroupId(6); + byte[] b = a.getLocalFileDataData(); + + // CRC manually calculated, sorry + byte[] expect = {(byte)0xC6, 0x02, 0x78, (byte)0xB6, // CRC + 0123, (byte)0x80, // mode + 0, 0, 0, 0, // link length + 5, 0, 6, 0}; // uid, gid + assertEquals("no link", expect.length, b.length); + for (int i=0; i<expect.length; i++) { + assertEquals("no link, byte "+i, expect[i], b[i]); + } + + a.setLinkedFile("test"); + expect = new byte[] {0x75, (byte)0x8E, 0x41, (byte)0xFD, // CRC + 0123, (byte)0xA0, // mode + 4, 0, 0, 0, // link length + 5, 0, 6, 0, // uid, gid + (byte)'t', (byte)'e', (byte)'s', (byte)'t'}; + b = a.getLocalFileDataData(); + assertEquals("no link", expect.length, b.length); + for (int i=0; i<expect.length; i++) { + assertEquals("no link, byte "+i, expect[i], b[i]); + } + + } + + /** + * Test reparse + */ + @Test + public void testReparse() throws Exception { + // CRC manually calculated, sorry + byte[] data = {(byte)0xC6, 0x02, 0x78, (byte)0xB6, // CRC + 0123, (byte)0x80, // mode + 0, 0, 0, 0, // link length + 5, 0, 6, 0}; // uid, gid + AsiExtraField a = new AsiExtraField(); + a.parseFromLocalFileData(data, 0, data.length); + assertEquals("length plain file", data.length, + a.getLocalFileDataLength().getValue()); + assertTrue("plain file, no link", !a.isLink()); + assertTrue("plain file, no dir", !a.isDirectory()); + assertEquals("mode plain file", FILE_FLAG | 0123, a.getMode()); + assertEquals("uid plain file", 5, a.getUserId()); + assertEquals("gid plain file", 6, a.getGroupId()); + + data = new byte[] {0x75, (byte)0x8E, 0x41, (byte)0xFD, // CRC + 0123, (byte)0xA0, // mode + 4, 0, 0, 0, // link length + 5, 0, 6, 0, // uid, gid + (byte)'t', (byte)'e', (byte)'s', (byte)'t'}; + a = new AsiExtraField(); + a.parseFromLocalFileData(data, 0, data.length); + assertEquals("length link", data.length, + a.getLocalFileDataLength().getValue()); + assertTrue("link, is link", a.isLink()); + assertTrue("link, no dir", !a.isDirectory()); + assertEquals("mode link", LINK_FLAG | 0123, a.getMode()); + assertEquals("uid link", 5, a.getUserId()); + assertEquals("gid link", 6, a.getGroupId()); + assertEquals("test", a.getLinkedFile()); + + data = new byte[] {(byte)0x8E, 0x01, (byte)0xBF, (byte)0x0E, // CRC + 0123, (byte)0x40, // mode + 0, 0, 0, 0, // link + 5, 0, 6, 0}; // uid, gid + a = new AsiExtraField(); + a.parseFromLocalFileData(data, 0, data.length); + assertEquals("length dir", data.length, + a.getLocalFileDataLength().getValue()); + assertTrue("dir, no link", !a.isLink()); + assertTrue("dir, is dir", a.isDirectory()); + assertEquals("mode dir", DIR_FLAG | 0123, a.getMode()); + assertEquals("uid dir", 5, a.getUserId()); + assertEquals("gid dir", 6, a.getGroupId()); + + data = new byte[] {0, 0, 0, 0, // bad CRC + 0123, (byte)0x40, // mode + 0, 0, 0, 0, // link + 5, 0, 6, 0}; // uid, gid + a = new AsiExtraField(); + try { + a.parseFromLocalFileData(data, 0, data.length); + fail("should raise bad CRC exception"); + } catch (Exception e) { + assertEquals("bad CRC checksum 0 instead of ebf018e", + e.getMessage()); + } + } + + @Test + public void testClone() { + AsiExtraField s1 = new AsiExtraField(); + s1.setUserId(42); + s1.setGroupId(12); + s1.setLinkedFile("foo"); + s1.setMode(0644); + s1.setDirectory(true); + AsiExtraField s2 = (AsiExtraField) s1.clone(); + assertNotSame(s1, s2); + assertEquals(s1.getUserId(), s2.getUserId()); + assertEquals(s1.getGroupId(), s2.getGroupId()); + assertEquals(s1.getLinkedFile(), s2.getLinkedFile()); + assertEquals(s1.getMode(), s2.getMode()); + assertEquals(s1.isDirectory(), s2.isDirectory()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ExtraFieldUtilsTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ExtraFieldUtilsTest.java new file mode 100644 index 00000000..95a6779e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ExtraFieldUtilsTest.java @@ -0,0 +1,210 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.zip; + +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +/** + * JUnit 3 testcases for org.apache.tools.zip.ExtraFieldUtils. + * + */ +public class ExtraFieldUtilsTest implements UnixStat { + + /** + * Header-ID of a ZipExtraField not supported by Ant. + * + * <p>Used to be ZipShort(1) but this is the ID of the Zip64 extra + * field.</p> + */ + static final ZipShort UNRECOGNIZED_HEADER = new ZipShort(0x5555); + + private AsiExtraField a; + private UnrecognizedExtraField dummy; + private byte[] data; + private byte[] aLocal; + + @Before + public void setUp() { + a = new AsiExtraField(); + a.setMode(0755); + a.setDirectory(true); + dummy = new UnrecognizedExtraField(); + dummy.setHeaderId(UNRECOGNIZED_HEADER); + dummy.setLocalFileDataData(new byte[] {0}); + dummy.setCentralDirectoryData(new byte[] {0}); + + aLocal = a.getLocalFileDataData(); + byte[] dummyLocal = dummy.getLocalFileDataData(); + data = new byte[4 + aLocal.length + 4 + dummyLocal.length]; + System.arraycopy(a.getHeaderId().getBytes(), 0, data, 0, 2); + System.arraycopy(a.getLocalFileDataLength().getBytes(), 0, data, 2, 2); + System.arraycopy(aLocal, 0, data, 4, aLocal.length); + System.arraycopy(dummy.getHeaderId().getBytes(), 0, data, + 4+aLocal.length, 2); + System.arraycopy(dummy.getLocalFileDataLength().getBytes(), 0, data, + 4+aLocal.length+2, 2); + System.arraycopy(dummyLocal, 0, data, + 4+aLocal.length+4, dummyLocal.length); + + } + + /** + * test parser. + */ + @Test + public void testParse() throws Exception { + ZipExtraField[] ze = ExtraFieldUtils.parse(data); + assertEquals("number of fields", 2, ze.length); + assertTrue("type field 1", ze[0] instanceof AsiExtraField); + assertEquals("mode field 1", 040755, + ((AsiExtraField) ze[0]).getMode()); + assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField); + assertEquals("data length field 2", 1, + ze[1].getLocalFileDataLength().getValue()); + + byte[] data2 = new byte[data.length-1]; + System.arraycopy(data, 0, data2, 0, data2.length); + try { + ExtraFieldUtils.parse(data2); + fail("data should be invalid"); + } catch (Exception e) { + assertEquals("message", + "bad extra field starting at "+(4 + aLocal.length) + + ". Block length of 1 bytes exceeds remaining data of 0 bytes.", + e.getMessage()); + } + } + + @Test + public void testParseWithRead() throws Exception { + ZipExtraField[] ze = + ExtraFieldUtils.parse(data, true, + ExtraFieldUtils.UnparseableExtraField.READ); + assertEquals("number of fields", 2, ze.length); + assertTrue("type field 1", ze[0] instanceof AsiExtraField); + assertEquals("mode field 1", 040755, + ((AsiExtraField) ze[0]).getMode()); + assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField); + assertEquals("data length field 2", 1, + ze[1].getLocalFileDataLength().getValue()); + + byte[] data2 = new byte[data.length-1]; + System.arraycopy(data, 0, data2, 0, data2.length); + ze = ExtraFieldUtils.parse(data2, true, + ExtraFieldUtils.UnparseableExtraField.READ); + assertEquals("number of fields", 2, ze.length); + assertTrue("type field 1", ze[0] instanceof AsiExtraField); + assertEquals("mode field 1", 040755, + ((AsiExtraField) ze[0]).getMode()); + assertTrue("type field 2", ze[1] instanceof UnparseableExtraFieldData); + assertEquals("data length field 2", 4, + ze[1].getLocalFileDataLength().getValue()); + for (int i = 0; i < 4; i++) { + assertEquals("byte number " + i, + data2[data.length - 5 + i], + ze[1].getLocalFileDataData()[i]); + } + } + + @Test + public void testParseWithSkip() throws Exception { + ZipExtraField[] ze = + ExtraFieldUtils.parse(data, true, + ExtraFieldUtils.UnparseableExtraField.SKIP); + assertEquals("number of fields", 2, ze.length); + assertTrue("type field 1", ze[0] instanceof AsiExtraField); + assertEquals("mode field 1", 040755, + ((AsiExtraField) ze[0]).getMode()); + assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField); + assertEquals("data length field 2", 1, + ze[1].getLocalFileDataLength().getValue()); + + byte[] data2 = new byte[data.length-1]; + System.arraycopy(data, 0, data2, 0, data2.length); + ze = ExtraFieldUtils.parse(data2, true, + ExtraFieldUtils.UnparseableExtraField.SKIP); + assertEquals("number of fields", 1, ze.length); + assertTrue("type field 1", ze[0] instanceof AsiExtraField); + assertEquals("mode field 1", 040755, + ((AsiExtraField) ze[0]).getMode()); + } + + /** + * Test merge methods + */ + @Test + public void testMerge() { + byte[] local = + ExtraFieldUtils.mergeLocalFileDataData(new ZipExtraField[] {a, dummy}); + assertEquals("local length", data.length, local.length); + for (int i=0; i<local.length; i++) { + assertEquals("local byte "+i, data[i], local[i]); + } + + byte[] dummyCentral = dummy.getCentralDirectoryData(); + byte[] data2 = new byte[4 + aLocal.length + 4 + dummyCentral.length]; + System.arraycopy(data, 0, data2, 0, 4 + aLocal.length + 2); + System.arraycopy(dummy.getCentralDirectoryLength().getBytes(), 0, + data2, 4+aLocal.length+2, 2); + System.arraycopy(dummyCentral, 0, data2, + 4+aLocal.length+4, dummyCentral.length); + + + byte[] central = + ExtraFieldUtils.mergeCentralDirectoryData(new ZipExtraField[] {a, dummy}); + assertEquals("central length", data2.length, central.length); + for (int i=0; i<central.length; i++) { + assertEquals("central byte "+i, data2[i], central[i]); + } + + } + + @Test + public void testMergeWithUnparseableData() throws Exception { + ZipExtraField d = new UnparseableExtraFieldData(); + byte[] b = UNRECOGNIZED_HEADER.getBytes(); + d.parseFromLocalFileData(new byte[] {b[0], b[1], 1, 0}, 0, 4); + byte[] local = + ExtraFieldUtils.mergeLocalFileDataData(new ZipExtraField[] {a, d}); + assertEquals("local length", data.length - 1, local.length); + for (int i = 0; i < local.length; i++) { + assertEquals("local byte " + i, data[i], local[i]); + } + + byte[] dCentral = d.getCentralDirectoryData(); + byte[] data2 = new byte[4 + aLocal.length + dCentral.length]; + System.arraycopy(data, 0, data2, 0, 4 + aLocal.length + 2); + System.arraycopy(dCentral, 0, data2, + 4 + aLocal.length, dCentral.length); + + + byte[] central = + ExtraFieldUtils.mergeCentralDirectoryData(new ZipExtraField[] {a, d}); + assertEquals("central length", data2.length, central.length); + for (int i = 0; i < central.length; i++) { + assertEquals("central byte " + i, data2[i], central[i]); + } + + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java new file mode 100644 index 00000000..38b2df58 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/UTF8ZipFilesTest.java @@ -0,0 +1,260 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.zip; + +import java.io.File; +import java.io.InputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.Enumeration; +import java.util.zip.CRC32; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +public class UTF8ZipFilesTest { + + private static final String UTF_8 = "utf-8"; + private static final String CP437 = "cp437"; + private static final String US_ASCII = "US-ASCII"; + private static final String ASCII_TXT = "ascii.txt"; + private static final String EURO_FOR_DOLLAR_TXT = "\u20AC_for_Dollar.txt"; + private static final String OIL_BARREL_TXT = "\u00D6lf\u00E4sser.txt"; + + @Test + public void testUtf8FileRoundtripExplicitUnicodeExtra() + throws IOException { + testFileRoundtrip(UTF_8, true, true); + } + + @Test + public void testUtf8FileRoundtripNoEFSExplicitUnicodeExtra() + throws IOException { + testFileRoundtrip(UTF_8, false, true); + } + + @Test + public void testCP437FileRoundtripExplicitUnicodeExtra() + throws IOException { + testFileRoundtrip(CP437, false, true); + } + + @Test + public void testASCIIFileRoundtripExplicitUnicodeExtra() + throws IOException { + testFileRoundtrip(US_ASCII, false, true); + } + + @Test + public void testUtf8FileRoundtripImplicitUnicodeExtra() + throws IOException { + testFileRoundtrip(UTF_8, true, false); + } + + @Test + public void testUtf8FileRoundtripNoEFSImplicitUnicodeExtra() + throws IOException { + testFileRoundtrip(UTF_8, false, false); + } + + @Test + public void testCP437FileRoundtripImplicitUnicodeExtra() + throws IOException { + testFileRoundtrip(CP437, false, false); + } + + @Test + public void testASCIIFileRoundtripImplicitUnicodeExtra() + throws IOException { + testFileRoundtrip(US_ASCII, false, false); + } + + @Test + public void testZipFileReadsUnicodeFields() throws IOException { + File file = File.createTempFile("unicode-test", ".zip"); + ZipFile zf = null; + try { + createTestFile(file, US_ASCII, false, true); + zf = new ZipFile(file, US_ASCII, true); + assertCanRead(zf, ASCII_TXT); + assertCanRead(zf, EURO_FOR_DOLLAR_TXT); + assertCanRead(zf, OIL_BARREL_TXT); + } finally { + ZipFile.closeQuietly(zf); + if (file.exists()) { + file.delete(); + } + } + } + + private static void testFileRoundtrip(String encoding, boolean withEFS, + boolean withExplicitUnicodeExtra) + throws IOException { + + File file = File.createTempFile(encoding + "-test", ".zip"); + try { + createTestFile(file, encoding, withEFS, withExplicitUnicodeExtra); + testFile(file, encoding); + } finally { + if (file.exists()) { + file.delete(); + } + } + } + + private static void createTestFile(File file, String encoding, + boolean withEFS, + boolean withExplicitUnicodeExtra) + throws IOException { + + ZipEncoding zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); + + ZipOutputStream zos = null; + try { + zos = new ZipOutputStream(file); + zos.setEncoding(encoding); + zos.setUseLanguageEncodingFlag(withEFS); + zos.setCreateUnicodeExtraFields(withExplicitUnicodeExtra ? + ZipOutputStream + .UnicodeExtraFieldPolicy.NEVER + : ZipOutputStream + .UnicodeExtraFieldPolicy.ALWAYS); + + ZipEntry ze = new ZipEntry(OIL_BARREL_TXT); + if (withExplicitUnicodeExtra + && !zipEncoding.canEncode(ze.getName())) { + + ByteBuffer en = zipEncoding.encode(ze.getName()); + + ze.addExtraField(new UnicodePathExtraField(ze.getName(), + en.array(), + en.arrayOffset(), + en.limit())); + } + + zos.putNextEntry(ze); + zos.write("Hello, world!".getBytes("US-ASCII")); + zos.closeEntry(); + + ze = new ZipEntry(EURO_FOR_DOLLAR_TXT); + if (withExplicitUnicodeExtra + && !zipEncoding.canEncode(ze.getName())) { + + ByteBuffer en = zipEncoding.encode(ze.getName()); + + ze.addExtraField(new UnicodePathExtraField(ze.getName(), + en.array(), + en.arrayOffset(), + en.limit())); + } + + zos.putNextEntry(ze); + zos.write("Give me your money!".getBytes("US-ASCII")); + zos.closeEntry(); + + ze = new ZipEntry(ASCII_TXT); + + if (withExplicitUnicodeExtra + && !zipEncoding.canEncode(ze.getName())) { + + ByteBuffer en = zipEncoding.encode(ze.getName()); + + ze.addExtraField(new UnicodePathExtraField(ze.getName(), + en.array(), + en.arrayOffset(), + en.limit())); + } + + zos.putNextEntry(ze); + zos.write("ascii".getBytes("US-ASCII")); + zos.closeEntry(); + } finally { + if (zos != null) { + try { + zos.close(); + } catch (IOException e) { /* swallow */ } + } + } + } + + private static void testFile(File file, String encoding) + throws IOException { + ZipFile zf = null; + try { + zf = new ZipFile(file, encoding, false); + + Enumeration e = zf.getEntries(); + while (e.hasMoreElements()) { + ZipEntry ze = (ZipEntry) e.nextElement(); + + if (ze.getName().endsWith("sser.txt")) { + assertUnicodeName(ze, OIL_BARREL_TXT, encoding); + + } else if (ze.getName().endsWith("_for_Dollar.txt")) { + assertUnicodeName(ze, EURO_FOR_DOLLAR_TXT, encoding); + } else if (!ze.getName().equals(ASCII_TXT)) { + throw new AssertionError("Urecognized ZIP entry with name [" + + ze.getName() + "] found."); + } + } + } finally { + ZipFile.closeQuietly(zf); + } + } + + private static UnicodePathExtraField findUniCodePath(ZipEntry ze) { + return (UnicodePathExtraField) + ze.getExtraField(UnicodePathExtraField.UPATH_ID); + } + + private static void assertUnicodeName(ZipEntry ze, + String expectedName, + String encoding) + throws IOException { + if (!expectedName.equals(ze.getName())) { + UnicodePathExtraField ucpf = findUniCodePath(ze); + assertNotNull(ucpf); + + ZipEncoding enc = ZipEncodingHelper.getZipEncoding(encoding); + ByteBuffer ne = enc.encode(ze.getName()); + + CRC32 crc = new CRC32(); + crc.update(ne.array(),ne.arrayOffset(),ne.limit()); + + assertEquals(crc.getValue(), ucpf.getNameCRC32()); + assertEquals(expectedName, new String(ucpf.getUnicodeName(), + UTF_8)); + } + } + + private static void assertCanRead(ZipFile zf, String fileName) throws IOException { + ZipEntry entry = zf.getEntry(fileName); + assertNotNull("Entry " + fileName + " doesn't exist", entry); + InputStream is = zf.getInputStream(entry); + assertNotNull("InputStream is null", is); + try { + is.read(); + } finally { + is.close(); + } + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipEncodingTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipEncodingTest.java new file mode 100644 index 00000000..826e410a --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipEncodingTest.java @@ -0,0 +1,152 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.tools.zip; + +import java.io.IOException; +import java.nio.ByteBuffer; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +/** + * Test zip encodings. + */ +public class ZipEncodingTest { + private static final String UNENC_STRING = "\u2016"; + + // stress test for internal grow method. + private static final String BAD_STRING = + "\u2016\u2015\u2016\u2015\u2016\u2015\u2016\u2015\u2016\u2015\u2016"; + + private static final String BAD_STRING_ENC = + "%U2016%U2015%U2016%U2015%U2016%U2015%U2016%U2015%U2016%U2015%U2016"; + + @Test + public void testSimpleCp437Encoding() throws IOException { + + doSimpleEncodingTest("Cp437", null); + } + + @Test + public void testSimpleCp850Encoding() throws IOException { + + doSimpleEncodingTest("Cp850", null); + } + + @Test + public void testNioCp1252Encoding() throws IOException { + // CP1252 has some undefined code points, these are + // the defined ones + // retrieved by + // awk '/^0x/ && NF>2 {print $1;}' CP1252.TXT + byte[] b = + new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, + 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, + 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, + 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F, + 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, + 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, + 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F, + (byte) 0x80, (byte) 0x82, (byte) 0x83, (byte) 0x84, + (byte) 0x85, (byte) 0x86, (byte) 0x87, (byte) 0x88, + (byte) 0x89, (byte) 0x8A, (byte) 0x8B, (byte) 0x8C, + (byte) 0x8E, (byte) 0x91, (byte) 0x92, (byte) 0x93, + (byte) 0x94, (byte) 0x95, (byte) 0x96, (byte) 0x97, + (byte) 0x98, (byte) 0x99, (byte) 0x9A, (byte) 0x9B, + (byte) 0x9C, (byte) 0x9E, (byte) 0x9F, (byte) 0xA0, + (byte) 0xA1, (byte) 0xA2, (byte) 0xA3, (byte) 0xA4, + (byte) 0xA5, (byte) 0xA6, (byte) 0xA7, (byte) 0xA8, + (byte) 0xA9, (byte) 0xAA, (byte) 0xAB, (byte) 0xAC, + (byte) 0xAD, (byte) 0xAE, (byte) 0xAF, (byte) 0xB0, + (byte) 0xB1, (byte) 0xB2, (byte) 0xB3, (byte) 0xB4, + (byte) 0xB5, (byte) 0xB6, (byte) 0xB7, (byte) 0xB8, + (byte) 0xB9, (byte) 0xBA, (byte) 0xBB, (byte) 0xBC, + (byte) 0xBD, (byte) 0xBE, (byte) 0xBF, (byte) 0xC0, + (byte) 0xC1, (byte) 0xC2, (byte) 0xC3, (byte) 0xC4, + (byte) 0xC5, (byte) 0xC6, (byte) 0xC7, (byte) 0xC8, + (byte) 0xC9, (byte) 0xCA, (byte) 0xCB, (byte) 0xCC, + (byte) 0xCD, (byte) 0xCE, (byte) 0xCF, (byte) 0xD0, + (byte) 0xD1, (byte) 0xD2, (byte) 0xD3, (byte) 0xD4, + (byte) 0xD5, (byte) 0xD6, (byte) 0xD7, (byte) 0xD8, + (byte) 0xD9, (byte) 0xDA, (byte) 0xDB, (byte) 0xDC, + (byte) 0xDD, (byte) 0xDE, (byte) 0xDF, (byte) 0xE0, + (byte) 0xE1, (byte) 0xE2, (byte) 0xE3, (byte) 0xE4, + (byte) 0xE5, (byte) 0xE6, (byte) 0xE7, (byte) 0xE8, + (byte) 0xE9, (byte) 0xEA, (byte) 0xEB, (byte) 0xEC, + (byte) 0xED, (byte) 0xEE, (byte) 0xEF, (byte) 0xF0, + (byte) 0xF1, (byte) 0xF2, (byte) 0xF3, (byte) 0xF4, + (byte) 0xF5, (byte) 0xF6, (byte) 0xF7, (byte) 0xF8, + (byte) 0xF9, (byte) 0xFA, (byte) 0xFB, (byte) 0xFC, + (byte) 0xFD, (byte) 0xFE, (byte) 0xFF }; + + doSimpleEncodingTest("Cp1252",b); + } + + private static void assertByteEquals(byte[] expected, ByteBuffer actual) { + + assertEquals(expected.length, actual.limit()); + + for (int i = 0; i < expected.length; ++i) { + + byte a = actual.get(); + assertEquals(expected[i], a); + } + + } + + private void doSimpleEncodingTest(String name, byte[] testBytes) + throws IOException { + + ZipEncoding enc = ZipEncodingHelper.getZipEncoding(name); + + if (testBytes == null) { + + testBytes = new byte[256]; + for (int i = 0; i < 256; ++i) { + testBytes[i] = (byte) i; + } + } + + String decoded = enc.decode(testBytes); + + assertEquals(true, enc.canEncode(decoded)); + + ByteBuffer encoded = enc.encode(decoded); + + assertByteEquals(testBytes, encoded); + + assertEquals(false, enc.canEncode(UNENC_STRING)); + assertByteEquals("%U2016".getBytes("US-ASCII"), enc.encode(UNENC_STRING)); + assertEquals(false, enc.canEncode(BAD_STRING)); + assertByteEquals(BAD_STRING_ENC.getBytes("US-ASCII"), + enc.encode(BAD_STRING)); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java new file mode 100644 index 00000000..3c21f6f3 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java @@ -0,0 +1,228 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.zip; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.fail; + +/** + * JUnit 3 testcases for org.apache.tools.zip.ZipEntry. + * + */ +public class ZipEntryTest { + + + /** + * test handling of extra fields + */ + @Test + public void testExtraFields() { + AsiExtraField a = new AsiExtraField(); + a.setDirectory(true); + a.setMode(0755); + UnrecognizedExtraField u = new UnrecognizedExtraField(); + u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); + u.setLocalFileDataData(new byte[0]); + + ZipEntry ze = new ZipEntry("test/"); + ze.setExtraFields(new ZipExtraField[] {a, u}); + byte[] data1 = ze.getExtra(); + ZipExtraField[] result = ze.getExtraFields(); + assertEquals("first pass", 2, result.length); + assertSame(a, result[0]); + assertSame(u, result[1]); + + UnrecognizedExtraField u2 = new UnrecognizedExtraField(); + u2.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); + u2.setLocalFileDataData(new byte[] {1}); + + ze.addExtraField(u2); + byte[] data2 = ze.getExtra(); + result = ze.getExtraFields(); + assertEquals("second pass", 2, result.length); + assertSame(a, result[0]); + assertSame(u2, result[1]); + assertEquals("length second pass", data1.length+1, data2.length); + + UnrecognizedExtraField u3 = new UnrecognizedExtraField(); + u3.setHeaderId(new ZipShort(2)); + u3.setLocalFileDataData(new byte[] {1}); + ze.addExtraField(u3); + result = ze.getExtraFields(); + assertEquals("third pass", 3, result.length); + + ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); + byte[] data3 = ze.getExtra(); + result = ze.getExtraFields(); + assertEquals("fourth pass", 2, result.length); + assertSame(a, result[0]); + assertSame(u3, result[1]); + assertEquals("length fourth pass", data2.length, data3.length); + + try { + ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); + fail("should be no such element"); + } catch (java.util.NoSuchElementException nse) { + //TODO assert exception values + } + } + + /** + * test handling of extra fields via central directory + */ + @Test + public void testExtraFieldMerging() { + AsiExtraField a = new AsiExtraField(); + a.setDirectory(true); + a.setMode(0755); + UnrecognizedExtraField u = new UnrecognizedExtraField(); + u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); + u.setLocalFileDataData(new byte[0]); + + ZipEntry ze = new ZipEntry("test/"); + ze.setExtraFields(new ZipExtraField[] {a, u}); + + // merge + // Header-ID 1 + length 1 + one byte of data + byte[] b = ExtraFieldUtilsTest.UNRECOGNIZED_HEADER.getBytes(); + ze.setCentralDirectoryExtra(new byte[] {b[0], b[1], 1, 0, 127}); + + ZipExtraField[] result = ze.getExtraFields(); + assertEquals("first pass", 2, result.length); + assertSame(a, result[0]); + assertEquals(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER, + result[1].getHeaderId()); + assertEquals(new ZipShort(0), result[1].getLocalFileDataLength()); + assertEquals(new ZipShort(1), result[1].getCentralDirectoryLength()); + + // add new + // Header-ID 2 + length 0 + ze.setCentralDirectoryExtra(new byte[] {2, 0, 0, 0}); + + result = ze.getExtraFields(); + assertEquals("second pass", 3, result.length); + + // merge + // Header-ID 2 + length 1 + one byte of data + ze.setExtra(new byte[] {2, 0, 1, 0, 127}); + + result = ze.getExtraFields(); + assertEquals("third pass", 3, result.length); + assertSame(a, result[0]); + assertEquals(new ZipShort(2), result[2].getHeaderId()); + assertEquals(new ZipShort(1), result[2].getLocalFileDataLength()); + assertEquals(new ZipShort(0), result[2].getCentralDirectoryLength()); + } + + /** + * test handling of extra fields + */ + @Test + public void testAddAsFirstExtraField() { + AsiExtraField a = new AsiExtraField(); + a.setDirectory(true); + a.setMode(0755); + UnrecognizedExtraField u = new UnrecognizedExtraField(); + u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); + u.setLocalFileDataData(new byte[0]); + + ZipEntry ze = new ZipEntry("test/"); + ze.setExtraFields(new ZipExtraField[] {a, u}); + byte[] data1 = ze.getExtra(); + + UnrecognizedExtraField u2 = new UnrecognizedExtraField(); + u2.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER); + u2.setLocalFileDataData(new byte[] {1}); + + ze.addAsFirstExtraField(u2); + byte[] data2 = ze.getExtra(); + ZipExtraField[] result = ze.getExtraFields(); + assertEquals("second pass", 2, result.length); + assertSame(u2, result[0]); + assertSame(a, result[1]); + assertEquals("length second pass", data1.length + 1, data2.length); + + UnrecognizedExtraField u3 = new UnrecognizedExtraField(); + u3.setHeaderId(new ZipShort(2)); + u3.setLocalFileDataData(new byte[] {1}); + ze.addAsFirstExtraField(u3); + result = ze.getExtraFields(); + assertEquals("third pass", 3, result.length); + assertSame(u3, result[0]); + assertSame(u2, result[1]); + assertSame(a, result[2]); + } + + @Test + public void testUnixMode() { + ZipEntry ze = new ZipEntry("foo"); + assertEquals(0, ze.getPlatform()); + ze.setUnixMode(0755); + assertEquals(3, ze.getPlatform()); + assertEquals(0755, + (ze.getExternalAttributes() >> 16) & 0xFFFF); + assertEquals(0, ze.getExternalAttributes() & 0xFFFF); + + ze.setUnixMode(0444); + assertEquals(3, ze.getPlatform()); + assertEquals(0444, + (ze.getExternalAttributes() >> 16) & 0xFFFF); + assertEquals(1, ze.getExternalAttributes() & 0xFFFF); + + ze = new ZipEntry("foo/"); + assertEquals(0, ze.getPlatform()); + ze.setUnixMode(0777); + assertEquals(3, ze.getPlatform()); + assertEquals(0777, + (ze.getExternalAttributes() >> 16) & 0xFFFF); + assertEquals(0x10, ze.getExternalAttributes() & 0xFFFF); + + ze.setUnixMode(0577); + assertEquals(3, ze.getPlatform()); + assertEquals(0577, + (ze.getExternalAttributes() >> 16) & 0xFFFF); + assertEquals(0x11, ze.getExternalAttributes() & 0xFFFF); + } + + /** + * Test case for + * <a href="https://issues.apache.org/jira/browse/COMPRESS-94" + * >COMPRESS-94</a>. + */ + @Test + public void testNotEquals() { + ZipEntry entry1 = new ZipEntry("foo"); + ZipEntry entry2 = new ZipEntry("bar"); + assertFalse(entry1.equals(entry2)); + } + + @Test + public void testCopyConstructor() throws Exception { + ZipEntry archiveEntry = new ZipEntry("fred"); + archiveEntry.setUnixMode(0664); + archiveEntry.setMethod(ZipEntry.DEFLATED); + archiveEntry.getGeneralPurposeBit().useStrongEncryption(true); + ZipEntry copy = new ZipEntry(archiveEntry); + assertEquals(archiveEntry, copy); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipLongTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipLongTest.java new file mode 100644 index 00000000..a7ece044 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipLongTest.java @@ -0,0 +1,94 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.zip; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + +/** + * JUnit testcases for org.apache.tools.zip.ZipLong. + * + */ +public class ZipLongTest { + + /** + * Test conversion to bytes. + */ + @Test + public void testToBytes() { + ZipLong zl = new ZipLong(0x12345678); + byte[] result = zl.getBytes(); + assertEquals("length getBytes", 4, result.length); + assertEquals("first byte getBytes", 0x78, result[0]); + assertEquals("second byte getBytes", 0x56, result[1]); + assertEquals("third byte getBytes", 0x34, result[2]); + assertEquals("fourth byte getBytes", 0x12, result[3]); + } + + /** + * Test conversion from bytes. + */ + @Test + public void testFromBytes() { + byte[] val = new byte[] {0x78, 0x56, 0x34, 0x12}; + ZipLong zl = new ZipLong(val); + assertEquals("value from bytes", 0x12345678, zl.getValue()); + } + + /** + * Test the contract of the equals method. + */ + @Test + public void testEquals() { + ZipLong zl = new ZipLong(0x12345678); + ZipLong zl2 = new ZipLong(0x12345678); + ZipLong zl3 = new ZipLong(0x87654321); + + assertTrue("reflexive", zl.equals(zl)); + + assertTrue("works", zl.equals(zl2)); + assertTrue("works, part two", !zl.equals(zl3)); + + assertTrue("symmetric", zl2.equals(zl)); + + assertTrue("null handling", !zl.equals(null)); + assertTrue("non ZipLong handling", !zl.equals(new Integer(0x1234))); + } + + /** + * Test sign handling. + */ + @Test + public void testSign() { + ZipLong zl = new ZipLong(new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF}); + assertEquals(0x00000000FFFFFFFFl, zl.getValue()); + } + + @Test + public void testClone() { + ZipLong s1 = new ZipLong(42); + ZipLong s2 = (ZipLong) s1.clone(); + assertNotSame(s1, s2); + assertEquals(s1, s2); + assertEquals(s1.getValue(), s2.getValue()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java new file mode 100644 index 00000000..a69db6c1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.zip; + +import org.junit.Before; +import org.junit.Test; + +import java.util.Calendar; +import java.util.Date; + +import static org.junit.Assert.assertEquals; + +public class ZipOutputStreamTest { + + private Date time; + private ZipLong zl; + + @Before + public void setUp() throws Exception { + time = new Date(); + Calendar cal = Calendar.getInstance(); + cal.setTime(time); + int year = cal.get(Calendar.YEAR); + int month = cal.get(Calendar.MONTH) + 1; + long value = ((year - 1980) << 25) + | (month << 21) + | (cal.get(Calendar.DAY_OF_MONTH) << 16) + | (cal.get(Calendar.HOUR_OF_DAY) << 11) + | (cal.get(Calendar.MINUTE) << 5) + | (cal.get(Calendar.SECOND) >> 1); + + byte[] result = new byte[4]; + result[0] = (byte) ((value & 0xFF)); + result[1] = (byte) ((value & 0xFF00) >> 8); + result[2] = (byte) ((value & 0xFF0000) >> 16); + result[3] = (byte) ((value & 0xFF000000L) >> 24); + zl = new ZipLong(result); + } + + + @Test + public void testZipLong() throws Exception { + ZipLong test = ZipOutputStream.toDosTime(time); + assertEquals(test.getValue(), zl.getValue()); + } + + @Test + public void testAdjustToLong() { + assertEquals((long) Integer.MAX_VALUE, + ZipOutputStream.adjustToLong(Integer.MAX_VALUE)); + assertEquals(((long) Integer.MAX_VALUE) + 1, + ZipOutputStream.adjustToLong(Integer.MAX_VALUE + 1)); + assertEquals(2 * ((long) Integer.MAX_VALUE), + ZipOutputStream.adjustToLong(2 * Integer.MAX_VALUE)); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipShortTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipShortTest.java new file mode 100644 index 00000000..a6aa3e78 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/apache/tools/zip/ZipShortTest.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.apache.tools.zip; + +import org.junit.Test; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + +/** + * JUnit 3 testcases for org.apache.tools.zip.ZipShort. + * + */ +public class ZipShortTest { + + /** + * Test conversion to bytes. + */ + @Test + public void testToBytes() { + ZipShort zs = new ZipShort(0x1234); + byte[] result = zs.getBytes(); + assertEquals("length getBytes", 2, result.length); + assertEquals("first byte getBytes", 0x34, result[0]); + assertEquals("second byte getBytes", 0x12, result[1]); + } + + /** + * Test conversion from bytes. + */ + @Test + public void testFromBytes() { + byte[] val = new byte[] {0x34, 0x12}; + ZipShort zs = new ZipShort(val); + assertEquals("value from bytes", 0x1234, zs.getValue()); + } + + /** + * Test the contract of the equals method. + */ + @Test + public void testEquals() { + ZipShort zs = new ZipShort(0x1234); + ZipShort zs2 = new ZipShort(0x1234); + ZipShort zs3 = new ZipShort(0x5678); + + assertTrue("reflexive", zs.equals(zs)); + + assertTrue("works", zs.equals(zs2)); + assertTrue("works, part two", !zs.equals(zs3)); + + assertTrue("symmetric", zs2.equals(zs)); + + assertTrue("null handling", !zs.equals(null)); + assertTrue("non ZipShort handling", !zs.equals(new Integer(0x1234))); + } + + /** + * Test sign handling. + */ + @Test + public void testSign() { + ZipShort zs = new ZipShort(new byte[] {(byte)0xFF, (byte)0xFF}); + assertEquals(0x0000FFFF, zs.getValue()); + } + + @Test + public void testClone() { + ZipShort s1 = new ZipShort(42); + ZipShort s2 = (ZipShort) s1.clone(); + assertNotSame(s1, s2); + assertEquals(s1, s2); + assertEquals(s1.getValue(), s2.getValue()); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/AbstractJUnit3TestMissed.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/AbstractJUnit3TestMissed.java new file mode 100644 index 00000000..fd261f5d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/AbstractJUnit3TestMissed.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import junit.framework.TestCase; + +public abstract class AbstractJUnit3TestMissed extends TestCase { + + public void testNothing() { + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/AbstractJUnit3TestNotMissed.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/AbstractJUnit3TestNotMissed.java new file mode 100644 index 00000000..e1d1c0b9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/AbstractJUnit3TestNotMissed.java @@ -0,0 +1,31 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import junit.framework.TestCase; + +public abstract class AbstractJUnit3TestNotMissed extends TestCase { + + public void testNothing() { + } + + public static class InnerAbstractTestNotMissed extends AbstractJUnit3TestNotMissed { + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/AbstractTestMissed.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/AbstractTestMissed.java new file mode 100644 index 00000000..6724d5b8 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/AbstractTestMissed.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import org.junit.Test; + + +public abstract class AbstractTestMissed { + + @Test + public void testNothing() { + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/AbstractTestNotMissed.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/AbstractTestNotMissed.java new file mode 100644 index 00000000..9a77d1b7 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/AbstractTestNotMissed.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import org.junit.Test; + +public abstract class AbstractTestNotMissed { + + @Test + public void testNothing() { + } + + public static class InnerAbstractTestNotMissed extends AbstractTestNotMissed { + + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/JUnit3NonTestMissed.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/JUnit3NonTestMissed.java new file mode 100644 index 00000000..76cead6c --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/JUnit3NonTestMissed.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import junit.framework.TestCase; + +public class JUnit3NonTestMissed extends TestCase { + + public void notATest() { + //this isn't a test but shouldn't case an error + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/JUnit3TestNotMissed.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/JUnit3TestNotMissed.java new file mode 100644 index 00000000..1e5ac2de --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/JUnit3TestNotMissed.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import junit.framework.TestCase; + +public class JUnit3TestNotMissed extends TestCase { + + public void testNothing() { + // don't fail + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/JUnit4Skippable.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/JUnit4Skippable.java new file mode 100644 index 00000000..aa89ab7d --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/JUnit4Skippable.java @@ -0,0 +1,74 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import org.junit.Assume; +import org.junit.Ignore; +import org.junit.Test; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +public class JUnit4Skippable { + + @Test + public void passingTest() { + assertTrue("This test passed", true); + } + + @Ignore("Please don't ignore me!") + @Test + public void explicitIgnoreTest() { + fail("This test should be skipped"); + } + + @Test + public void implicitlyIgnoreTest() { + Assume.assumeFalse("This test will be ignored", true); + fail("I told you, this test should have been ignored!"); + } + + @Test + @Ignore + public void explicitlyIgnoreTestNoMessage() { + fail("This test should be skipped"); + } + + @Test + public void implicitlyIgnoreTestNoMessage() { + Assume.assumeFalse(true); + fail("I told you, this test should have been ignored!"); + } + + @Test + public void failingTest() { + fail("I told you this test was going to fail"); + } + + @Test + public void failingTestNoMessage() { + fail(); + } + + @Test + public void errorTest() { + throw new RuntimeException("Whoops, this test went wrong"); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/MultilineAsserts.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/MultilineAsserts.java new file mode 100644 index 00000000..06e10390 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/MultilineAsserts.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import junit.framework.TestCase; + +public class MultilineAsserts extends TestCase { + public void testFoo() { assertTrue("testFoo \nmessed up", false); } + public void testBar() { assertTrue("testBar \ndidn't work", true); } + public void testFee() { assertTrue("testFee \ncrashed", false); } + public void testFie() { assertTrue("testFie \nbroke", true); } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/NonTestMissed.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/NonTestMissed.java new file mode 100644 index 00000000..0a020ec9 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/NonTestMissed.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +public class NonTestMissed { + + public void notATest() { + //this isn't a test but shouldn't case an error + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/Output.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/Output.java new file mode 100644 index 00000000..a7135f7b --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/Output.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import junit.framework.TestCase; + +/** + * Not really a test of Ant but a test that is run by the test of the + * junit task. Confused? + * + * @since Ant 1.5 + */ +public class Output extends TestCase { + + public Output(String s) { + super(s); + } + + public void testOutput() { + System.out.println("foo"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/TestNotMissed.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/TestNotMissed.java new file mode 100644 index 00000000..6d3babeb --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/TestNotMissed.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + + +import org.junit.Test; + +public class TestNotMissed { + + @Test + public void testNothing() { + // don't fail + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/TestWithSuiteNotMissed.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/TestWithSuiteNotMissed.java new file mode 100644 index 00000000..80b722c2 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/TestWithSuiteNotMissed.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import junit.framework.Test; +import junit.framework.TestSuite; + +public class TestWithSuiteNotMissed { + + public static Test suite() { + TestSuite test = new TestSuite("meh"); + JUnit3TestNotMissed testCase = new JUnit3TestNotMissed(); + testCase.setName("testNothing"); + test.addTest(testCase); + return test; + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/ThreadedOutput.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/ThreadedOutput.java new file mode 100644 index 00000000..91f462a2 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/ThreadedOutput.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import junit.framework.TestCase; + +/** + * Not really a test of Ant but a test that is run by the test of the + * junit task. Confused? + * + * @since Ant 1.5 + */ +public class ThreadedOutput extends TestCase { + + public ThreadedOutput(String s) { + super(s); + } + + public void testOutput() throws InterruptedException { + Thread t = new Thread(new Runnable() { + public void run() { + System.out.println("foo"); + } + }); + t.start(); + t.join(); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/Timeout.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/Timeout.java new file mode 100644 index 00000000..6a42ee75 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/Timeout.java @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import org.junit.After; +import org.junit.Test; + +public class Timeout { + @Test + public void testTimeout() throws InterruptedException { + Thread.sleep(5000); + } + @After + public void tearDown() { + System.out.println("tearDown called on Timeout"); + } +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/XmlParserTest.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/XmlParserTest.java new file mode 100644 index 00000000..e5fae55f --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/junit/XmlParserTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.junit; + +import org.junit.Test; +import org.xml.sax.SAXException; +import org.xml.sax.XMLReader; +import org.xml.sax.helpers.XMLReaderFactory; + +import static org.junit.Assert.assertNotNull; + +/** + * created Aug 12, 2004 1:39:59 PM + */ + +public class XmlParserTest { + + + @Test + public void testXercesIsPresent() throws SAXException { + XMLReader xerces; + xerces = XMLReaderFactory.createXMLReader( + "org.apache.xerces.parsers.SAXParser"); + assertNotNull(xerces); + } + + @Test + public void testXercesHandlesSchema() throws SAXException { + XMLReader xerces; + xerces = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser"); + xerces.setFeature("http://apache.org/xml/features/validation/schema", + true); + } + + @Test + public void testParserHandlesSchema() throws SAXException { + XMLReader xerces; + xerces = XMLReaderFactory.createXMLReader(); + xerces.setFeature("http://apache.org/xml/features/validation/schema", + true); + } + +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/tasks/TaskdefTestContainerTask.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/tasks/TaskdefTestContainerTask.java new file mode 100644 index 00000000..a566d5c1 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/tasks/TaskdefTestContainerTask.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.tasks; + +import org.apache.tools.ant.taskdefs.Sequential; + +public class TaskdefTestContainerTask extends Sequential { + public TaskdefTestContainerTask() {} +} diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/tasks/TaskdefTestSimpleTask.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/tasks/TaskdefTestSimpleTask.java new file mode 100644 index 00000000..bce8cd50 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/tasks/TaskdefTestSimpleTask.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.tasks; + +import org.apache.tools.ant.Project; +import org.apache.tools.ant.Task; + +public class TaskdefTestSimpleTask extends Task { + + public class Echo { + Echo() {} + private String message = null; + public void setMessage(String s) {message = s;} + } + + public TaskdefTestSimpleTask() {} + + private Echo echo; + public Echo createEcho() { + echo = new Echo(); + return echo; + } + + public void execute() { + log("simpletask: "+echo.message, Project.MSG_INFO); + } + +} + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/tasks/antlib.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/tasks/antlib.xml new file mode 100644 index 00000000..b920da7e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/tasks/antlib.xml @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<antlib> +<macrodef name="simple"> + <element name="some-tasks" optional="yes" implicit="yes"/> + <sequential> + <some-tasks/> + </sequential> +</macrodef> +</antlib> + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/tasks/antlib2.xml b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/tasks/antlib2.xml new file mode 100644 index 00000000..b920da7e --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/tasks/antlib2.xml @@ -0,0 +1,26 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You 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. +--> +<antlib> +<macrodef name="simple"> + <element name="some-tasks" optional="yes" implicit="yes"/> + <sequential> + <some-tasks/> + </sequential> +</macrodef> +</antlib> + diff --git a/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/types/TypedefTestType.java b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/types/TypedefTestType.java new file mode 100644 index 00000000..235b76f6 --- /dev/null +++ b/framework/src/ant/apache-ant-1.9.6/src/tests/junit/org/example/types/TypedefTestType.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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 org.example.types; + +import org.apache.tools.ant.ProjectComponent; + +public class TypedefTestType extends ProjectComponent { +} + |