From d055cca7d28812a480eb49e8264f02d6b16fdfd5 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Mon, 27 Aug 2012 14:51:57 +0900 Subject: [PATCH] Add an initial test command to dicttool. Also fix some warnings This is a preliminary change to help track b/8526576 Bug: 8526576 Change-Id: If2ed74bb92f9b5fb7bbaf9c4851d9d0b5514b405 --- tools/dicttool/Android.mk | 8 ++-- tools/dicttool/etc/dicttool_aosp | 12 +++++- .../latin/dicttool/CommandList.java | 1 + .../inputmethod/latin/dicttool/Crypt.java | 4 ++ .../inputmethod/latin/dicttool/Package.java | 6 ++- .../inputmethod/latin/dicttool/Test.java | 43 +++++++++++++++++++ 6 files changed, 66 insertions(+), 8 deletions(-) create mode 100644 tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java diff --git a/tools/dicttool/Android.mk b/tools/dicttool/Android.mk index 666887a2e..d3bff8688 100644 --- a/tools/dicttool/Android.mk +++ b/tools/dicttool/Android.mk @@ -28,12 +28,10 @@ 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) -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/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 + " : 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 + " : 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 + " : 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 + " : 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..fdc53b30e --- /dev/null +++ b/tools/dicttool/src/com/android/inputmethod/latin/dicttool/Test.java @@ -0,0 +1,43 @@ +/** + * 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.UnsupportedFormatException; + +import java.io.IOException; + +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 { + final BinaryDictOffdeviceUtilsTests tests = new BinaryDictOffdeviceUtilsTests(); + tests.testGetRawDictWorks(); + } +}