1 17 18 package org.apache.tools.ant.taskdefs.optional.i18n; 19 20 import org.apache.tools.ant.BuildFileTest; 21 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.IOException ; 25 26 31 public class TranslateTest extends BuildFileTest { 32 static private final int BUF_SIZE = 32768; 33 34 private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/i18n/translate"; 35 36 public TranslateTest(String name) { 37 super(name); 38 } 39 40 41 public void setUp() { 42 configureProject(TASKDEFS_DIR + "/translate.xml"); 43 } 44 45 public void tearDown() { 46 executeTarget("cleanup"); 47 } 48 49 public void test1() { 50 executeTarget("test1"); 51 assertTrue("translation of "+ TASKDEFS_DIR + "/input/template.txt",compareFiles(TASKDEFS_DIR+"/expected/de/template.txt",TASKDEFS_DIR+"/output/de/template.txt")); 52 } 53 private boolean compareFiles(String name1, String name2) { 54 File file1 = new File (name1); 55 File file2 = new File (name2); 56 57 try { 58 if (!file1.exists() || !file2.exists()) { 59 System.out.println("One or both files do not exist:" + name1 + ", " + name2); 60 return false; 61 } 62 63 if (file1.length() != file2.length()) { 64 System.out.println("File size mismatch:" + name1 + "(" + file1.length() + "), " + 65 name2 + "(" + file2.length() + ")"); 66 return false; 67 } 68 69 byte[] buffer1 = new byte[BUF_SIZE]; 71 byte[] buffer2 = new byte[BUF_SIZE]; 72 73 FileInputStream fis1 = new FileInputStream (file1); 74 FileInputStream fis2 = new FileInputStream (file2); 75 int index = 0; 76 int read = 0; 77 while ((read = fis1.read(buffer1)) != -1) { 78 fis2.read(buffer2); 79 for (int i = 0; i < read; ++i, ++index) { 80 if (buffer1[i] != buffer2[i]) { 81 System.out.println("Bytes mismatch:" + name1 + ", " + name2 + 82 " at byte " + index); 83 return false; 84 } 85 } 86 } 87 return true; 88 } 89 catch (IOException e) { 90 System.out.println("IOException comparing files: " + name1 + ", " + name2); 91 return false; 92 } 93 } 94 } 95 96 | Popular Tags |