]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/engine/DictionaryBuilderTest.java
Fixing tests after moving out data.
[DictionaryPC.git] / src / com / hughes / android / dictionary / engine / DictionaryBuilderTest.java
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package com.hughes.android.dictionary.engine;
16
17 import java.io.File;
18 import java.io.IOException;
19 import java.io.PrintStream;
20 import java.io.RandomAccessFile;
21
22 import com.hughes.util.FileUtil;
23
24 import junit.framework.TestCase;
25
26 public class DictionaryBuilderTest extends TestCase {
27   
28   public static final String TEST_INPUTS = "../DictionaryData/testdata/inputs/";
29   public static final String WIKISPLIT = "../DictionaryData/inputs/wikiSplit/";
30   public static final String GOLDENS = "../DictionaryData/testdata/goldens/";
31
32   public static final String TEST_OUTPUTS = "../DictionaryData/testdata/outputs/";
33   public static final String OUTPUTS = "../DictionaryData/outputs/";
34
35   public void testWiktionaryItalian() throws Exception {
36     final File result = new File(TEST_OUTPUTS + "wiktionary.it.quickdic");
37     System.out.println("Writing to: " + result);
38     DictionaryBuilder.main(new String[] {
39         "--dictOut=" + result.getAbsolutePath(),
40         "--lang1=IT",
41         "--lang2=EN",
42         "--dictInfo=SomeWikiData",
43
44         /*
45         "--input3=" + WIKISPLIT + "english.data",
46         "--input3Name=enwiktionary.english",
47         "--input3Format=enwiktionary",
48         "--input3LangPattern=Italian",
49         "--input3LangCodePattern=it",
50         "--input3EnIndex=2",
51         "--input3PageLimit=1000",
52 */
53         "--input4=" + WIKISPLIT + "italian.data",
54         "--input4Name=enwiktionary.italian",
55         "--input4Format=enwiktionary",
56         "--input4LangPattern=Italian",
57         "--input4LangCodePattern=it",
58         "--input4EnIndex=2",
59         "--input4PageLimit=1000",
60
61         "--print=" + result.getName() + ".text",
62     });
63     
64     // Check it once:
65     assertFilesEqual(GOLDENS + "wiktionary.it_it.quickdic.text", result.getName() + ".text"); 
66     
67     // Check it again.
68     final Dictionary dict = new Dictionary(new RandomAccessFile(result.getAbsolutePath(), "r"));
69     final PrintStream out = new PrintStream(new File(result.getName() + ".text"));
70     dict.print(out);
71     out.close();
72     
73     assertFilesEqual(GOLDENS + "wiktionary.it_it.quickdic.text", result.getName() + ".text");
74   }
75
76   
77   public void testGermanCombined() throws Exception {
78     final File result = new File(TEST_OUTPUTS + "de-en.quickdic");
79     System.out.println("Writing to: " + result);
80     DictionaryBuilder.main(new String[] {
81         "--dictOut=" + result.getAbsolutePath(),
82         "--lang1=DE",
83         "--lang2=EN",
84         "--dictInfo=@" + TEST_INPUTS + "de-en_dictInfo.txt",
85
86         "--input1=" + TEST_INPUTS + "de-en_chemnitz_100",
87         "--input1Name=chemnitz",
88         "--input1Charset=UTF8",
89         "--input1Format=chemnitz",
90
91         "--input2=" + TEST_INPUTS + "de-en_dictcc_simulated",
92         "--input2Name=dictcc",
93         "--input2Charset=UTF8",
94         "--input2Format=dictcc",
95
96         "--print=" + result.getName() + ".text",
97     });
98     
99     // Check it once:
100     assertFilesEqual(GOLDENS + "de-en.quickdic.text", result.getName() + ".text"); 
101     
102     // Check it again.
103     final Dictionary dict = new Dictionary(new RandomAccessFile(result.getAbsolutePath(), "r"));
104     final PrintStream out = new PrintStream(result.getName() + ".text");
105     dict.print(out);
106     out.close();
107     
108     assertFilesEqual(GOLDENS + "de-en.quickdic.text", result.getName() + ".text"); 
109   }
110
111
112
113   void assertFilesEqual(final String expected, final String actual) throws IOException {
114     final String expectedString = FileUtil.readToString(new File(expected));
115     final String actualString = FileUtil.readToString(new File(actual));
116     assertEquals(expectedString, actualString);
117   }
118
119   
120 }