1 // Copyright 2011 Google Inc. All Rights Reserved.
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
7 // http://www.apache.org/licenses/LICENSE-2.0
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.
15 package com.hughes.android.dictionary.engine;
18 import java.io.IOException;
19 import java.io.PrintStream;
20 import java.io.RandomAccessFile;
22 import com.hughes.util.FileUtil;
24 import junit.framework.TestCase;
26 public class DictionaryBuilderTest extends TestCase {
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(),
35 "--dictInfo=SomeWikiData",
38 "--input3=wikiSplit/english.data",
39 "--input3Name=enwiktionary.english",
40 "--input3Format=enwiktionary",
41 "--input3LangPattern=Italian",
42 "--input3LangCodePattern=it",
44 "--input3PageLimit=1000",
46 "--input4=wikiSplit/italian.data",
47 "--input4Name=enwiktionary.italian",
48 "--input4Format=enwiktionary",
49 "--input4LangPattern=Italian",
50 "--input4LangCodePattern=it",
52 "--input4PageLimit=1000",
54 "--print=testdata/wiktionary.it.test",
58 assertFilesEqual("testdata/wiktionary.it.golden2", "testdata/wiktionary.it.test");
62 final Dictionary dict = new Dictionary(new RandomAccessFile(result.getAbsolutePath(), "r"));
63 final PrintStream out = new PrintStream(new File("testdata/wiktionary.it.test"));
67 assertFilesEqual("testdata/wiktionary.it.golden", "testdata/wiktionary.it.test");
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(),
78 "--dictInfo=@testdata/de-en_dictInfo.txt",
80 "--input1=testdata/de-en_chemnitz_100",
81 "--input1Name=chemnitz",
82 "--input1Charset=UTF8",
83 "--input1Format=chemnitz",
85 "--input2=testdata/de-en_dictcc_100",
86 "--input2Name=dictcc",
87 "--input2Charset=UTF8",
88 "--input2Format=dictcc",
90 "--print=testdata/de-en.test",
94 assertFilesEqual("testdata/de-en.golden", "testdata/de-en.test");
98 final Dictionary dict = new Dictionary(new RandomAccessFile(result.getAbsolutePath(), "r"));
99 final PrintStream out = new PrintStream(new File("testdata/de-en.test"));
103 assertFilesEqual("testdata/de-en.golden", "testdata/de-en.test");
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);