001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs.optional.i18n;
020:
021: import org.apache.tools.ant.BuildFileTest;
022:
023: import java.io.File;
024: import java.io.FileInputStream;
025: import java.io.IOException;
026:
027: /**
028: * Tests the Translate task.
029: *
030: * @since Ant 1.6
031: */
032: public class TranslateTest extends BuildFileTest {
033: static private final int BUF_SIZE = 32768;
034:
035: private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/i18n/translate";
036:
037: public TranslateTest(String name) {
038: super (name);
039: }
040:
041: public void setUp() {
042: configureProject(TASKDEFS_DIR + "/translate.xml");
043: }
044:
045: public void tearDown() {
046: executeTarget("cleanup");
047: }
048:
049: public void test1() {
050: executeTarget("test1");
051: assertTrue("translation of " + TASKDEFS_DIR
052: + "/input/template.txt", compareFiles(TASKDEFS_DIR
053: + "/expected/de/template.txt", TASKDEFS_DIR
054: + "/output/de/template.txt"));
055: }
056:
057: private boolean compareFiles(String name1, String name2) {
058: File file1 = new File(System.getProperty("root"), name1);
059: File file2 = new File(System.getProperty("root"), name2);
060:
061: try {
062: if (!file1.exists() || !file2.exists()) {
063: System.out.println("One or both files do not exist:"
064: + name1 + ", " + name2);
065: return false;
066: }
067:
068: if (file1.length() != file2.length()) {
069: System.out.println("File size mismatch:" + name1 + "("
070: + file1.length() + "), " + name2 + "("
071: + file2.length() + ")");
072: return false;
073: }
074:
075: // byte - byte compare
076: byte[] buffer1 = new byte[BUF_SIZE];
077: byte[] buffer2 = new byte[BUF_SIZE];
078:
079: FileInputStream fis1 = new FileInputStream(file1);
080: FileInputStream fis2 = new FileInputStream(file2);
081: int index = 0;
082: int read = 0;
083: while ((read = fis1.read(buffer1)) != -1) {
084: fis2.read(buffer2);
085: for (int i = 0; i < read; ++i, ++index) {
086: if (buffer1[i] != buffer2[i]) {
087: System.out.println("Bytes mismatch:" + name1
088: + ", " + name2 + " at byte " + index);
089: return false;
090: }
091: }
092: }
093: return true;
094: } catch (IOException e) {
095: System.out.println("IOException comparing files: " + name1
096: + ", " + name2);
097: return false;
098: }
099: }
100: }
|