1 | /*
|
---|
2 | * Copyright 2003-2004 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 |
|
---|
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 | /**
|
---|
27 | * Tests the Translate task.
|
---|
28 | *
|
---|
29 | * @since Ant 1.6
|
---|
30 | */
|
---|
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 - byte compare
|
---|
70 | 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 |
|
---|