aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/dicttool/Android.mk25
-rw-r--r--tools/dicttool/compat/android/test/AndroidTestCase.java35
-rw-r--r--tools/dicttool/compat/android/test/MoreAsserts.java35
-rw-r--r--tools/dicttool/compat/android/test/suitebuilder/annotation/LargeTest.java25
-rw-r--r--tools/dicttool/compat/android/util/Log.java37
-rwxr-xr-xtools/dicttool/etc/dicttool_aosp12
-rw-r--r--tools/dicttool/src/com/android/inputmethod/latin/dicttool/CommandList.java1
-rw-r--r--tools/dicttool/src/com/android/inputmethod/latin/dicttool/Crypt.java4
-rw-r--r--tools/dicttool/src/com/android/inputmethod/latin/dicttool/Package.java6
-rw-r--r--tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java51
-rw-r--r--tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java4
11 files changed, 222 insertions, 13 deletions
diff --git a/tools/dicttool/Android.mk b/tools/dicttool/Android.mk
index 666887a2e..931678793 100644
--- a/tools/dicttool/Android.mk
+++ b/tools/dicttool/Android.mk
@@ -16,10 +16,22 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
-LATINIME_BASE_SOURCE_DIRECTORY := ../../java/src/com/android/inputmethod
+BUILD_TOP := ../../../../..
+FRAMEWORK_TOP := $(BUILD_TOP)/frameworks/base/core/java
+LATINIME_DIR := $(BUILD_TOP)/packages/inputmethods/LatinIME
+LATINIME_BASE_SOURCE_DIRECTORY := $(LATINIME_DIR)/java/src/com/android/inputmethod
LATINIME_CORE_SOURCE_DIRECTORY := $(LATINIME_BASE_SOURCE_DIRECTORY)/latin
LATINIME_ANNOTATIONS_SOURCE_DIRECTORY := $(LATINIME_BASE_SOURCE_DIRECTORY)/annotations
MAKEDICT_CORE_SOURCE_DIRECTORY := $(LATINIME_CORE_SOURCE_DIRECTORY)/makedict
+DICTTOOL_COMPAT_TESTS_DIRECTORY := compat
+DICTTOOL_ONDEVICE_TESTS_DIRECTORY := \
+ $(LATINIME_DIR)/tests/src/com/android/inputmethod/latin/makedict/
+
+USED_TARGETTED_UTILS := \
+ $(FRAMEWORK_TOP)/android/util/SparseArray.java \
+ $(FRAMEWORK_TOP)/com/android/internal/util/ArrayUtils.java \
+ $(LATINIME_CORE_SOURCE_DIRECTORY)/ByteArrayWrapper.java \
+ $(LATINIME_CORE_SOURCE_DIRECTORY)/utils/CollectionUtils.java
LOCAL_MAIN_SRC_FILES := $(call all-java-files-under, $(MAKEDICT_CORE_SOURCE_DIRECTORY))
LOCAL_TOOL_SRC_FILES := $(call all-java-files-under, src)
@@ -28,12 +40,13 @@ LOCAL_ANNOTATIONS_SRC_FILES := \
LOCAL_SRC_FILES := $(LOCAL_TOOL_SRC_FILES) \
$(filter-out $(addprefix %/, $(notdir $(LOCAL_TOOL_SRC_FILES))), $(LOCAL_MAIN_SRC_FILES)) \
$(LOCAL_ANNOTATIONS_SRC_FILES) \
- $(LATINIME_CORE_SOURCE_DIRECTORY)/Constants.java
+ $(LATINIME_CORE_SOURCE_DIRECTORY)/Constants.java \
+ $(call all-java-files-under, tests) \
+ $(call all-java-files-under, $(DICTTOOL_ONDEVICE_TESTS_DIRECTORY)) \
+ $(call all-java-files-under, $(DICTTOOL_COMPAT_TESTS_DIRECTORY)) \
+ $(USED_TARGETTED_UTILS)
-ifeq ($(DICTTOOL_UNITTEST), true)
- LOCAL_SRC_FILES += $(call all-java-files-under, tests)
- LOCAL_JAVA_LIBRARIES := junit
-endif
+LOCAL_JAVA_LIBRARIES := junit
LOCAL_JAR_MANIFEST := etc/manifest.txt
LOCAL_MODULE := dicttool_aosp
diff --git a/tools/dicttool/compat/android/test/AndroidTestCase.java b/tools/dicttool/compat/android/test/AndroidTestCase.java
new file mode 100644
index 000000000..d01b7ad7c
--- /dev/null
+++ b/tools/dicttool/compat/android/test/AndroidTestCase.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.test;
+
+import junit.framework.TestCase;
+
+import java.io.File;
+
+/**
+ * This is a compatibility class that aims at emulating android.test.AndroidTestcase from the
+ * Android library as simply as possible, and only to the extent that is used by the client classes.
+ * Its purpose is to provide compatibility without having to pull the whole Android library.
+ */
+public class AndroidTestCase extends TestCase {
+ public File getCacheDir() {
+ return new File(".");
+ }
+ public AndroidTestCase getContext() {
+ return this;
+ }
+}
diff --git a/tools/dicttool/compat/android/test/MoreAsserts.java b/tools/dicttool/compat/android/test/MoreAsserts.java
new file mode 100644
index 000000000..f56420b9c
--- /dev/null
+++ b/tools/dicttool/compat/android/test/MoreAsserts.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.test;
+
+import junit.framework.Assert;
+
+/**
+ * This is a compatibility class that aims at emulating android.test.MoreAsserts from the
+ * Android library as simply as possible, and only to the extent that is used by the client classes.
+ * Its purpose is to provide compatibility without having to pull the whole Android library.
+ */
+public class MoreAsserts {
+ public static void assertNotEqual(Object unexpected, Object actual) {
+ if (equal(unexpected, actual)) {
+ Assert.fail("expected not to be:<" + unexpected + ">");
+ }
+ }
+ private static boolean equal(Object a, Object b) {
+ return a == b || (a != null && a.equals(b));
+ }
+}
diff --git a/tools/dicttool/compat/android/test/suitebuilder/annotation/LargeTest.java b/tools/dicttool/compat/android/test/suitebuilder/annotation/LargeTest.java
new file mode 100644
index 000000000..ed00f8d5f
--- /dev/null
+++ b/tools/dicttool/compat/android/test/suitebuilder/annotation/LargeTest.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.test.suitebuilder.annotation;
+
+/**
+ * This is a compatibility class that aims at emulating the LargeTest annotation from the
+ * Android library as simply as possible, and only to the extent that is used by the client classes.
+ * Its purpose is to provide compatibility without having to pull the whole Android library.
+ */
+public @interface LargeTest {
+}
diff --git a/tools/dicttool/compat/android/util/Log.java b/tools/dicttool/compat/android/util/Log.java
new file mode 100644
index 000000000..d9df3a4ae
--- /dev/null
+++ b/tools/dicttool/compat/android/util/Log.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.util;
+
+/**
+ * This is a compatibility class that aims at emulating android.util.Log from the
+ * Android library as simply as possible, and only to the extent that is used by the client classes.
+ * Its purpose is to provide compatibility without having to pull the whole Android library.
+ */
+public class Log {
+ public static void d(final String tag, final String message) {
+ System.out.println(tag + " : " + message);
+ }
+ public static void d(final String tag, final String message, final Exception e) {
+ System.out.println(tag + " : " + message + " : " + e);
+ }
+ public static void e(final String tag, final String message) {
+ d(tag, message);
+ }
+ public static void e(final String tag, final String message, final Exception e) {
+ e(tag, message, e);
+ }
+}
diff --git a/tools/dicttool/etc/dicttool_aosp b/tools/dicttool/etc/dicttool_aosp
index a4879a279..cc7111a2c 100755
--- a/tools/dicttool/etc/dicttool_aosp
+++ b/tools/dicttool/etc/dicttool_aosp
@@ -33,6 +33,7 @@ progdir=`pwd`
prog="${progdir}"/`basename "${prog}"`
cd "${oldwd}"
+classname=com.android.inputmethod.latin.dicttool.Dicttool
jarfile=dicttool_aosp.jar
frameworkdir="$progdir"
if [ ! -r "$frameworkdir/$jarfile" ]
@@ -51,12 +52,21 @@ then
exit 1
fi
+lib=junit.jar
+if [ ! -r "$frameworkdir/$lib" ]
+then
+ echo `basename "$prog"`": can't find lib $lib"
+ exit 1
+fi
+
if [ "$OSTYPE" = "cygwin" ] ; then
jarpath=`cygpath -w "$frameworkdir/$jarfile"`
+ libpath=`cygpath -w "$frameworkdir/$lib"`
progdir=`cygpath -w "$progdir"`
else
jarpath="$frameworkdir/$jarfile"
+ libpath="$frameworkdir/$lib"
fi
# might need more memory, e.g. -Xmx128M
-exec java -ea -jar "$jarpath" "$@"
+exec java -ea -classpath "$libpath":"$jarpath" "$classname" "$@"
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CommandList.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CommandList.java
index 0e0095bd6..0d93c7fa9 100644
--- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CommandList.java
+++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/CommandList.java
@@ -27,5 +27,6 @@ public class CommandList {
Dicttool.addCommand("package", Package.Packager.class);
Dicttool.addCommand("unpackage", Package.Unpackager.class);
Dicttool.addCommand("makedict", Makedict.class);
+ Dicttool.addCommand("test", Test.class);
}
}
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Crypt.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Crypt.java
index f8990231e..4612ae4ab 100644
--- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Crypt.java
+++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Crypt.java
@@ -40,10 +40,12 @@ public class Crypt {
public Encrypter() {
}
+ @Override
public String getHelp() {
return COMMAND + " <src_filename> <dst_filename>: Encrypts a file";
}
+ @Override
public void run() {
throw new UnsupportedOperationException();
}
@@ -55,10 +57,12 @@ public class Crypt {
public Decrypter() {
}
+ @Override
public String getHelp() {
return COMMAND + " <src_filename> <dst_filename>: Decrypts a file";
}
+ @Override
public void run() {
throw new UnsupportedOperationException();
}
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Package.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Package.java
index b29480764..9274dcd2e 100644
--- a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Package.java
+++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Package.java
@@ -22,9 +22,7 @@ import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
-import java.io.InputStream;
import java.io.IOException;
-import java.io.OutputStream;
public class Package {
private Package() {
@@ -39,10 +37,12 @@ public class Package {
public Packager() {
}
+ @Override
public String getHelp() {
return COMMAND + " <src_filename> <dst_filename>: Package a file for distribution";
}
+ @Override
public void run() throws IOException {
if (mArgs.length != 2) {
throw new RuntimeException("Too many/too few arguments for command " + COMMAND);
@@ -67,11 +67,13 @@ public class Package {
public Unpackager() {
}
+ @Override
public String getHelp() {
return COMMAND + " <src_filename> <dst_filename>: Detects how a file is packaged and\n"
+ "decrypts/uncompresses as necessary to produce a raw binary file.";
}
+ @Override
public void run() throws FileNotFoundException, IOException {
if (mArgs.length != 2) {
throw new RuntimeException("Too many/too few arguments for command " + COMMAND);
diff --git a/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java
new file mode 100644
index 000000000..827c5e3a9
--- /dev/null
+++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright (C) 2013 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+
+package com.android.inputmethod.latin.dicttool;
+
+import com.android.inputmethod.latin.makedict.BinaryDictIOUtilsTests;
+import com.android.inputmethod.latin.makedict.BinaryDictInputOutputTest;
+import com.android.inputmethod.latin.makedict.FusionDictionaryTest;
+import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
+
+import java.io.IOException;
+
+/**
+ * Dicttool command implementing self-tests.
+ */
+public class Test extends Dicttool.Command {
+ public static final String COMMAND = "test";
+
+ public Test() {
+ }
+
+ @Override
+ public String getHelp() {
+ return "test";
+ }
+
+ @Override
+ public void run() throws IOException, UnsupportedFormatException {
+ test();
+ }
+
+ private void test() throws IOException, UnsupportedFormatException {
+ new BinaryDictOffdeviceUtilsTests().testGetRawDictWorks();
+ new FusionDictionaryTest().testFusion();
+ new BinaryDictInputOutputTest().testFlattenNodes();
+ new BinaryDictIOUtilsTests().testRandomWords();
+ }
+}
diff --git a/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java b/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java
index fe3781d80..76071133d 100644
--- a/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java
+++ b/tools/dicttool/tests/com/android/inputmethod/latin/makedict/FusionDictionaryTest.java
@@ -73,10 +73,6 @@ public class FusionDictionaryTest extends TestCase {
for (final String word : words) {
if (--limit < 0) return;
final CharGroup cg = FusionDictionary.findWordInTree(dict.mRoot, word);
- if (null == cg) {
- System.out.println("word " + dumpWord(word));
- dumpDict(dict);
- }
assertNotNull(cg);
}
}