You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ConditionTest.java 8.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. /*
  2. * The Apache Software License, Version 1.1
  3. *
  4. * Copyright (c) 2002 The Apache Software Foundation. All rights
  5. * reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. *
  14. * 2. Redistributions in binary form must reproduce the above copyright
  15. * notice, this list of conditions and the following disclaimer in
  16. * the documentation and/or other materials provided with the
  17. * distribution.
  18. *
  19. * 3. The end-user documentation included with the redistribution, if
  20. * any, must include the following acknowlegement:
  21. * "This product includes software developed by the
  22. * Apache Software Foundation (http://www.apache.org/)."
  23. * Alternately, this acknowlegement may appear in the software itself,
  24. * if and wherever such third-party acknowlegements normally appear.
  25. *
  26. * 4. The names "The Jakarta Project", "Ant", and "Apache Software
  27. * Foundation" must not be used to endorse or promote products derived
  28. * from this software without prior written permission. For written
  29. * permission, please contact apache@apache.org.
  30. *
  31. * 5. Products derived from this software may not be called "Apache"
  32. * nor may "Apache" appear in their names without prior written
  33. * permission of the Apache Group.
  34. *
  35. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38. * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46. * SUCH DAMAGE.
  47. * ====================================================================
  48. *
  49. * This software consists of voluntary contributions made by many
  50. * individuals on behalf of the Apache Software Foundation. For more
  51. * information on the Apache Software Foundation, please see
  52. * <http://www.apache.org/>.
  53. */
  54. package org.apache.tools.ant.taskdefs;
  55. import org.apache.tools.ant.Project;
  56. import org.apache.tools.ant.BuildException;
  57. import org.apache.tools.ant.BuildFileTest;
  58. import java.lang.reflect.InvocationTargetException;
  59. /**
  60. * @author steve_l
  61. * @created 13 January 2002
  62. */
  63. public class ConditionTest extends BuildFileTest {
  64. /**
  65. * Constructor for the ConditionTest object
  66. *
  67. * @param name we dont know
  68. */
  69. public ConditionTest(String name) {
  70. super(name);
  71. }
  72. /**
  73. * The JUnit setup method
  74. */
  75. public void setUp() {
  76. configureProject("src/etc/testcases/taskdefs/condition.xml");
  77. }
  78. /**
  79. * The teardown method for JUnit
  80. */
  81. public void tearDown() {
  82. executeTarget("cleanup");
  83. }
  84. public void testBasic() {
  85. expectPropertySet("basic","basic");
  86. }
  87. public void testConditionIncomplete() {
  88. expectSpecificBuildException("condition-incomplete",
  89. "property attribute has been omitted",
  90. "The property attribute is required.");
  91. }
  92. public void testConditionEmpty() {
  93. expectSpecificBuildException("condition-empty",
  94. "no conditions",
  95. "You must nest a condition into <condition>");
  96. }
  97. public void testShortcut() {
  98. expectPropertySet("shortcut","shortcut","set");
  99. }
  100. public void testUnset() {
  101. expectPropertyUnset("dontset","dontset");
  102. }
  103. public void testSetValue() {
  104. expectPropertySet("setvalue","setvalue","woowoo");
  105. }
  106. public void testNegation() {
  107. expectPropertySet("negation","negation");
  108. }
  109. public void testNegationFalse() {
  110. expectPropertyUnset("negationfalse","negationfalse");
  111. }
  112. public void testNegationIncomplete() {
  113. expectSpecificBuildException("negationincomplete",
  114. "no conditions in <not>",
  115. "You must nest a condition into <not>");
  116. }
  117. public void testAnd() {
  118. expectPropertySet("and","and");
  119. }
  120. public void testAndFails() {
  121. expectPropertyUnset("andfails","andfails");
  122. }
  123. public void testAndIncomplete() {
  124. expectPropertyUnset("andincomplete","andincomplete");
  125. }
  126. public void testAndempty() {
  127. expectPropertySet("andempty","andempty");
  128. }
  129. public void testOr() {
  130. expectPropertySet("or","or");
  131. }
  132. public void testOrincomplete() {
  133. expectPropertySet("or","or");
  134. }
  135. public void testOrFails() {
  136. expectPropertyUnset("orfails","orfails");
  137. }
  138. public void testOrboth() {
  139. expectPropertySet("orboth","orboth");
  140. }
  141. public void testFilesmatchIdentical() {
  142. expectPropertySet("filesmatch-identical","filesmatch-identical");
  143. }
  144. public void testFilesmatchIncomplete() {
  145. expectSpecificBuildException("filesmatch-incomplete",
  146. "Missing file2 attribute",
  147. "both file1 and file2 are required in filesmatch");
  148. }
  149. public void testFilesmatchOddsizes() {
  150. expectPropertyUnset("filesmatch-oddsizes","filesmatch-oddsizes");
  151. }
  152. public void testFilesmatchExistence() {
  153. expectPropertyUnset("filesmatch-existence", "filesmatch-existence");
  154. }
  155. public void testFilesmatchDifferent() {
  156. expectPropertyUnset("filesmatch-different","filesmatch-different");
  157. }
  158. public void testFilesmatchMatch() {
  159. expectPropertySet("filesmatch-match","filesmatch-match");
  160. }
  161. public void testFilesmatchDifferentSizes() {
  162. expectPropertyUnset("filesmatch-different-sizes",
  163. "filesmatch-different-sizes");
  164. }
  165. public void testFilesmatchDifferentOnemissing() {
  166. expectPropertyUnset("filesmatch-different-onemissing",
  167. "filesmatch-different-onemissing");
  168. }
  169. public void testContains() {
  170. expectPropertySet("contains","contains");
  171. }
  172. public void testContainsDoesnt() {
  173. expectPropertyUnset("contains-doesnt","contains-doesnt");
  174. }
  175. public void testContainsAnycase() {
  176. expectPropertySet("contains-anycase","contains-anycase");
  177. }
  178. public void testContainsIncomplete1() {
  179. expectSpecificBuildException("contains-incomplete1",
  180. "Missing contains attribute",
  181. "both string and substring are required in contains");
  182. }
  183. public void testContainsIncomplete2() {
  184. expectSpecificBuildException("contains-incomplete2",
  185. "Missing contains attribute",
  186. "both string and substring are required in contains");
  187. }
  188. public void testIstrue() {
  189. expectPropertySet("istrue","istrue");
  190. }
  191. public void testIstrueNot() {
  192. expectPropertyUnset("istrue-not","istrue-not");
  193. }
  194. public void testIstrueFalse() {
  195. expectPropertyUnset("istrue-false","istrue-false");
  196. }
  197. public void testIstrueIncomplete1() {
  198. expectSpecificBuildException("istrue-incomplete",
  199. "Missing attribute",
  200. "Nothing to test for truth");
  201. }
  202. public void testIsfalseTrue() {
  203. expectPropertyUnset("isfalse-true","isfalse-true");
  204. }
  205. public void testIsfalseNot() {
  206. expectPropertySet("isfalse-not","isfalse-not");
  207. }
  208. public void testIsfalseFalse() {
  209. expectPropertySet("isfalse-false","isfalse-false");
  210. }
  211. public void testIsfalseIncomplete1() {
  212. expectSpecificBuildException("isfalse-incomplete",
  213. "Missing attribute",
  214. "Nothing to test for falsehood");
  215. }
  216. }