]> gitweb.fperrin.net Git - DictionaryPC.git/blob - src/com/hughes/android/dictionary/engine/DictionaryBuilderTest.java
Apache license.
[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 void testWiktionaryItalian() throws Exception {
29     final File result = new File("testdata/wiktionary.it.quickdic");
30     System.out.println("Writing to: " + result);
31     DictionaryBuilder.main(new String[] {
32         "--dictOut=" + result.getAbsolutePath(),
33         "--lang1=IT",
34         "--lang2=EN",
35         "--dictInfo=SomeWikiData",
36
37         /*
38         "--input3=wikiSplit/english.data",
39         "--input3Name=enwiktionary.english",
40         "--input3Format=enwiktionary",
41         "--input3LangPattern=Italian",
42         "--input3LangCodePattern=it",
43         "--input3EnIndex=2",
44         "--input3PageLimit=1000",
45 */
46         "--input4=wikiSplit/italian.data",
47         "--input4Name=enwiktionary.italian",
48         "--input4Format=enwiktionary",
49         "--input4LangPattern=Italian",
50         "--input4LangCodePattern=it",
51         "--input4EnIndex=2",
52         "--input4PageLimit=1000",
53
54         "--print=testdata/wiktionary.it.test",
55     });
56     
57     // Check it once:
58     assertFilesEqual("testdata/wiktionary.it.golden2", "testdata/wiktionary.it.test"); 
59     
60     
61     // Check it again.
62     final Dictionary dict = new Dictionary(new RandomAccessFile(result.getAbsolutePath(), "r"));
63     final PrintStream out = new PrintStream(new File("testdata/wiktionary.it.test"));
64     dict.print(out);
65     out.close();
66     
67     assertFilesEqual("testdata/wiktionary.it.golden", "testdata/wiktionary.it.test");
68   }
69
70   
71   public void testGermanCombined() throws Exception {
72     final File result = new File("testdata/de-en.quickdic");
73     System.out.println("Writing to: " + result);
74     DictionaryBuilder.main(new String[] {
75         "--dictOut=" + result.getAbsolutePath(),
76         "--lang1=DE",
77         "--lang2=EN",
78         "--dictInfo=@testdata/de-en_dictInfo.txt",
79
80         "--input1=testdata/de-en_chemnitz_100",
81         "--input1Name=chemnitz",
82         "--input1Charset=UTF8",
83         "--input1Format=chemnitz",
84
85         "--input2=testdata/de-en_dictcc_100",
86         "--input2Name=dictcc",
87         "--input2Charset=UTF8",
88         "--input2Format=dictcc",
89
90         "--print=testdata/de-en.test",
91     });
92     
93     // Check it once:
94     assertFilesEqual("testdata/de-en.golden", "testdata/de-en.test"); 
95     
96     
97     // Check it again.
98     final Dictionary dict = new Dictionary(new RandomAccessFile(result.getAbsolutePath(), "r"));
99     final PrintStream out = new PrintStream(new File("testdata/de-en.test"));
100     dict.print(out);
101     out.close();
102     
103     assertFilesEqual("testdata/de-en.golden", "testdata/de-en.test");
104   }
105
106
107
108   void assertFilesEqual(final String expected, final String actual) throws IOException {
109     final String expectedString = FileUtil.readToString(new File(expected));
110     final String actualString = FileUtil.readToString(new File(actual));
111     assertEquals(expectedString, actualString);
112   }
113
114   
115 }