aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/ant/apache-ant-1.9.6/src/tests/antunit/taskdefs/length-test.xml
blob: acd5310bb01fff11c727a92deb4e2255e682950a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
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>