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.

FixCrLfTest.java 5.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. /*
  2. * Copyright 2001-2006 The Apache Software Foundation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. *
  16. */
  17. package org.apache.tools.ant.taskdefs;
  18. import java.io.BufferedInputStream;
  19. import java.io.File;
  20. import java.io.FileInputStream;
  21. import java.io.IOException;
  22. import java.io.InputStream;
  23. import junit.framework.AssertionFailedError;
  24. import org.apache.tools.ant.BuildFileTest;
  25. /**
  26. */
  27. public class FixCrLfTest extends BuildFileTest {
  28. public FixCrLfTest(String name) {
  29. super(name);
  30. }
  31. public void setUp() {
  32. configureProject("src/etc/testcases/taskdefs/fixcrlf/build.xml");
  33. }
  34. public void tearDown() {
  35. executeTarget("cleanup");
  36. }
  37. public void test1() throws IOException {
  38. executeTarget("test1");
  39. }
  40. public void test2() throws IOException {
  41. executeTarget("test2");
  42. }
  43. public void test3() throws IOException {
  44. executeTarget("test3");
  45. }
  46. public void test4() throws IOException {
  47. executeTarget("test4");
  48. }
  49. public void test5() throws IOException {
  50. executeTarget("test5");
  51. }
  52. public void test6() throws IOException {
  53. executeTarget("test6");
  54. }
  55. public void test7() throws IOException {
  56. executeTarget("test7");
  57. }
  58. public void test8() throws IOException {
  59. executeTarget("test8");
  60. }
  61. public void test9() throws IOException {
  62. executeTarget("test9");
  63. }
  64. public void testMacLines() throws IOException {
  65. executeTarget("testMacLines");
  66. }
  67. public void testNoOverwrite() throws IOException {
  68. executeTarget("testNoOverwrite");
  69. }
  70. public void testEncoding() throws IOException {
  71. executeTarget("testEncoding");
  72. }
  73. public void testOutputEncoding() throws IOException {
  74. executeTarget("testOutputEncoding");
  75. }
  76. public void testLongLines() throws IOException {
  77. executeTarget("testLongLines");
  78. }
  79. public void testCrCrLfSequenceUnix() throws IOException {
  80. executeTarget("testCrCrLfSequence-unix");
  81. }
  82. public void testCrCrLfSequenceDos() throws IOException {
  83. executeTarget("testCrCrLfSequence-dos");
  84. }
  85. public void testCrCrLfSequenceMac() throws IOException {
  86. executeTarget("testCrCrLfSequence-mac");
  87. }
  88. public void testFixlastDos() throws IOException {
  89. executeTarget("testFixlastDos");
  90. }
  91. public void testFixlastFalseMac() throws IOException {
  92. executeTarget("testFixlastFalseMac");
  93. }
  94. public void testFixFile() throws Exception {
  95. executeTarget("testFixFile");
  96. }
  97. public void testFixFileExclusive() throws Exception {
  98. expectBuildExceptionContaining("testFixFileExclusive",
  99. FixCRLF.ERROR_FILE_AND_SRCDIR, FixCRLF.ERROR_FILE_AND_SRCDIR);
  100. }
  101. /**
  102. * Bugzilla Report 20840
  103. *
  104. * Will fail with an exception if the parent directories do not
  105. * get created.
  106. */
  107. public void testCreateParentDirs() {
  108. executeTarget("createParentDirs");
  109. }
  110. public void testPreserveLastModified() {
  111. executeTarget("testPreserveLastModified");
  112. }
  113. public void testFilter1() {
  114. executeTarget("testFilter1");
  115. }
  116. public void testFilter2() {
  117. executeTarget("testFilter2");
  118. }
  119. public void testFilter3() {
  120. executeTarget("testFilter3");
  121. }
  122. public void testFilter4() {
  123. executeTarget("testFilter4");
  124. }
  125. public void testFilter5() {
  126. executeTarget("testFilter5");
  127. }
  128. public void testFilter6() {
  129. executeTarget("testFilter6");
  130. }
  131. public void testFilter7() {
  132. executeTarget("testFilter7");
  133. }
  134. public void testFilter8() {
  135. executeTarget("testFilter8");
  136. }
  137. public void testFilter9() {
  138. executeTarget("testFilter9");
  139. }
  140. public void testCannotDoubleEof() {
  141. executeTarget("testCannotDoubleEof");
  142. }
  143. public void testTabInLiteralInComment() {
  144. executeTarget("testTabInLiteralInComment");
  145. }
  146. // not used, but public so theoretically must remain for BC?
  147. public void assertEqualContent(File expect, File result)
  148. throws AssertionFailedError, IOException {
  149. if (!result.exists()) {
  150. fail("Expected file "+result+" doesn\'t exist");
  151. }
  152. InputStream inExpect = null;
  153. InputStream inResult = null;
  154. try {
  155. inExpect = new BufferedInputStream(new FileInputStream(expect));
  156. inResult = new BufferedInputStream(new FileInputStream(result));
  157. int expectedByte = inExpect.read();
  158. while (expectedByte != -1) {
  159. assertEquals(expectedByte, inResult.read());
  160. expectedByte = inExpect.read();
  161. }
  162. assertEquals("End of file", -1, inResult.read());
  163. } finally {
  164. if (inResult != null) {
  165. inResult.close();
  166. }
  167. if (inExpect != null) {
  168. inExpect.close();
  169. }
  170. }
  171. }
  172. }