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 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/";
32 public static final String TEST_OUTPUTS = "../DictionaryData/testdata/outputs/";
33 public static final String OUTPUTS = "../DictionaryData/outputs/";
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(),
42 "--dictInfo=SomeWikiData",
45 "--input3=" + WIKISPLIT + "english.data",
46 "--input3Name=enwiktionary.english",
47 "--input3Format=enwiktionary",
48 "--input3LangPattern=Italian",
49 "--input3LangCodePattern=it",
51 "--input3PageLimit=1000",
53 "--input4=" + WIKISPLIT + "italian.data",
54 "--input4Name=enwiktionary.italian",
55 "--input4Format=enwiktionary",
56 "--input4LangPattern=Italian",
57 "--input4LangCodePattern=it",
59 "--input4PageLimit=1000",
61 "--print=" + result.getName() + ".text",
65 assertFilesEqual(GOLDENS + "wiktionary.it_it.quickdic.text", result.getName() + ".text");
68 final Dictionary dict = new Dictionary(new RandomAccessFile(result.getAbsolutePath(), "r"));
69 final PrintStream out = new PrintStream(new File(result.getName() + ".text"));
73 assertFilesEqual(GOLDENS + "wiktionary.it_it.quickdic.text", result.getName() + ".text");
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(),
84 "--dictInfo=@" + TEST_INPUTS + "de-en_dictInfo.txt",
86 "--input1=" + TEST_INPUTS + "de-en_chemnitz_100",
87 "--input1Name=chemnitz",
88 "--input1Charset=UTF8",
89 "--input1Format=chemnitz",
91 "--input2=" + TEST_INPUTS + "de-en_dictcc_simulated",
92 "--input2Name=dictcc",
93 "--input2Charset=UTF8",
94 "--input2Format=dictcc",
96 "--print=" + result.getName() + ".text",
100 assertFilesEqual(GOLDENS + "de-en.quickdic.text", result.getName() + ".text");
103 final Dictionary dict = new Dictionary(new RandomAccessFile(result.getAbsolutePath(), "r"));
104 final PrintStream out = new PrintStream(result.getName() + ".text");
108 assertFilesEqual(GOLDENS + "de-en.quickdic.text", result.getName() + ".text");
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);