diff options
author | Robert Ewald <robewald@gmx.net> | 2012-09-30 02:47:55 +0200 |
---|---|---|
committer | Jack Palevich <jackpal@google.com> | 2012-10-07 10:12:21 -0700 |
commit | 7785940304e1a21fd25730770e6d8ba01a8a33b2 (patch) | |
tree | 1d22bf87e5ad02f7981116661e3d958085cec52a | |
parent | 8f83011f12c3eaee305f18d5a4213d0bb5c835b4 (diff) | |
download | AndroidTerm-7785940304e1a21fd25730770e6d8ba01a8a33b2.tar.gz |
Add testcases for TermKeyListener.
This change attempts full code coverage. However the Fn key
functionality cannot be reached by my emulator version. All the tests
with Function key fail.
-rw-r--r-- | tests/emulatorview-test/AndroidManifest.xml | 19 | ||||
-rw-r--r-- | tests/emulatorview-test/ant.properties | 18 | ||||
-rw-r--r-- | tests/emulatorview-test/proguard-project.txt | 20 | ||||
-rw-r--r-- | tests/emulatorview-test/project.properties | 14 | ||||
-rw-r--r-- | tests/emulatorview-test/res/drawable-hdpi/ic_launcher.png | bin | 0 -> 9397 bytes | |||
-rw-r--r-- | tests/emulatorview-test/res/drawable-ldpi/ic_launcher.png | bin | 0 -> 2729 bytes | |||
-rw-r--r-- | tests/emulatorview-test/res/drawable-mdpi/ic_launcher.png | bin | 0 -> 5237 bytes | |||
-rw-r--r-- | tests/emulatorview-test/res/drawable-xhdpi/ic_launcher.png | bin | 0 -> 14383 bytes | |||
-rw-r--r-- | tests/emulatorview-test/res/values/strings.xml | 6 | ||||
-rw-r--r-- | tests/emulatorview-test/src/jackpal/androidterm/emulatorview/InputConnectionTest.java | 26 | ||||
-rw-r--r-- | tests/emulatorview-test/src/jackpal/androidterm/emulatorview/ModifierKeyTest.java | 14 | ||||
-rw-r--r-- | tests/emulatorview-test/src/jackpal/androidterm/emulatorview/TermKeyListenerTest.java | 384 |
12 files changed, 501 insertions, 0 deletions
diff --git a/tests/emulatorview-test/AndroidManifest.xml b/tests/emulatorview-test/AndroidManifest.xml new file mode 100644 index 0000000..e647f8d --- /dev/null +++ b/tests/emulatorview-test/AndroidManifest.xml @@ -0,0 +1,19 @@ +<?xml version="1.0" encoding="utf-8"?> +<manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="jackpal.androidterm.test" + android:versionCode="1" + android:versionName="1.0" > + + <uses-sdk android:minSdkVersion="3" /> + + <instrumentation + android:name="android.test.InstrumentationTestRunner" + android:targetPackage="jackpal.androidterm" /> + + <application + android:icon="@drawable/ic_launcher" + android:label="@string/app_name" > + <uses-library android:name="android.test.runner" /> + </application> + +</manifest>
\ No newline at end of file diff --git a/tests/emulatorview-test/ant.properties b/tests/emulatorview-test/ant.properties new file mode 100644 index 0000000..1572240 --- /dev/null +++ b/tests/emulatorview-test/ant.properties @@ -0,0 +1,18 @@ +# This file is used to override default values used by the Ant build system. +# +# This file must be checked into Version Control Systems, as it is +# integral to the build system of your project. + +# This file is only used by the Ant script. + +# You can use this to override default values such as +# 'source.dir' for the location of your java source folder and +# 'out.dir' for the location of your output folder. + +# You can also use it define how the release builds are signed by declaring +# the following properties: +# 'key.store' for the location of your keystore and +# 'key.alias' for the name of the key to use. +# The password will be asked during the build when you use the 'release' target. + +tested.project.dir=../.. diff --git a/tests/emulatorview-test/proguard-project.txt b/tests/emulatorview-test/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/tests/emulatorview-test/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/tests/emulatorview-test/project.properties b/tests/emulatorview-test/project.properties new file mode 100644 index 0000000..4d07452 --- /dev/null +++ b/tests/emulatorview-test/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-11 diff --git a/tests/emulatorview-test/res/drawable-hdpi/ic_launcher.png b/tests/emulatorview-test/res/drawable-hdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..96a442e --- /dev/null +++ b/tests/emulatorview-test/res/drawable-hdpi/ic_launcher.png diff --git a/tests/emulatorview-test/res/drawable-ldpi/ic_launcher.png b/tests/emulatorview-test/res/drawable-ldpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..9923872 --- /dev/null +++ b/tests/emulatorview-test/res/drawable-ldpi/ic_launcher.png diff --git a/tests/emulatorview-test/res/drawable-mdpi/ic_launcher.png b/tests/emulatorview-test/res/drawable-mdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..359047d --- /dev/null +++ b/tests/emulatorview-test/res/drawable-mdpi/ic_launcher.png diff --git a/tests/emulatorview-test/res/drawable-xhdpi/ic_launcher.png b/tests/emulatorview-test/res/drawable-xhdpi/ic_launcher.png Binary files differnew file mode 100644 index 0000000..71c6d76 --- /dev/null +++ b/tests/emulatorview-test/res/drawable-xhdpi/ic_launcher.png diff --git a/tests/emulatorview-test/res/values/strings.xml b/tests/emulatorview-test/res/values/strings.xml new file mode 100644 index 0000000..4d3121d --- /dev/null +++ b/tests/emulatorview-test/res/values/strings.xml @@ -0,0 +1,6 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + + <string name="app_name">Emulatorview-testTest</string> + +</resources>
\ No newline at end of file diff --git a/tests/emulatorview-test/src/jackpal/androidterm/emulatorview/InputConnectionTest.java b/tests/emulatorview-test/src/jackpal/androidterm/emulatorview/InputConnectionTest.java new file mode 100644 index 0000000..8c91066 --- /dev/null +++ b/tests/emulatorview-test/src/jackpal/androidterm/emulatorview/InputConnectionTest.java @@ -0,0 +1,26 @@ +package jackpal.androidterm.emulatorview; + +import android.test.AndroidTestCase; +import android.test.mock.MockApplication; +import android.test.mock.MockContext; +import android.util.DisplayMetrics; +import android.view.inputmethod.InputConnection; + +public class InputConnectionTest extends AndroidTestCase { + + + + + public InputConnectionTest() { + super(); + } + + public void testBackSpace() { +// MockContext cn = new MockContext(); +// MockApplication a = new MockApplication(); +// TermSession ts = new TermSession(); +// DisplayMetrics m = new DisplayMetrics(); +// EmulatorView e = new EmulatorView(cn, ts, m); +// InputConnection c = e.onCreateInputConnection(null); + } +} diff --git a/tests/emulatorview-test/src/jackpal/androidterm/emulatorview/ModifierKeyTest.java b/tests/emulatorview-test/src/jackpal/androidterm/emulatorview/ModifierKeyTest.java new file mode 100644 index 0000000..97b8eb4 --- /dev/null +++ b/tests/emulatorview-test/src/jackpal/androidterm/emulatorview/ModifierKeyTest.java @@ -0,0 +1,14 @@ +package jackpal.androidterm.emulatorview; + +import android.test.AndroidTestCase; +import android.view.KeyEvent; + +public class ModifierKeyTest extends AndroidTestCase { + + public void testCtrlKey() { +// ModifierKey mk = new ModifierKey(KeyEvent.KEYCODE_CTRL_LEFT); +// assertFalse(mk.isActive()); +// mk.handleModifierKey(KeyEvent.KEYCODE_CTRL_LEFT, true); +// assertTrue(mk.isActive()); + } +} diff --git a/tests/emulatorview-test/src/jackpal/androidterm/emulatorview/TermKeyListenerTest.java b/tests/emulatorview-test/src/jackpal/androidterm/emulatorview/TermKeyListenerTest.java new file mode 100644 index 0000000..235cf11 --- /dev/null +++ b/tests/emulatorview-test/src/jackpal/androidterm/emulatorview/TermKeyListenerTest.java @@ -0,0 +1,384 @@ +package jackpal.androidterm.emulatorview; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; +import java.nio.charset.Charset; +import java.nio.charset.CharsetEncoder; + +import android.annotation.TargetApi; +import android.test.AndroidTestCase; +import android.view.KeyEvent; + +class MockTermSession extends TermSession { + + private byte[] charseq = null; + + @Override + public void write(byte[] data, int offset, int count) { + charseq = data; + } + + public void clearQueue() { + charseq = null; + } + + public byte[] getCharSequence() { + return charseq; + } + + @Override + public void write(String data) { + try { + byte[] bytes = data.getBytes("UTF-8"); + write(bytes, 0, bytes.length); + } catch (UnsupportedEncodingException e) { + } + } + + @Override + public void write(int codePoint) { + CharBuffer charBuf = CharBuffer.allocate(2); + ByteBuffer byteBuf = ByteBuffer.allocate(4); + CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder(); + + charBuf.clear(); + byteBuf.clear(); + Character.toChars(codePoint, charBuf.array(), 0); + encoder.reset(); + encoder.encode(charBuf, byteBuf, true); + encoder.flush(byteBuf); + write(byteBuf.array(), 0, byteBuf.position()-1); + } + +} + +@TargetApi(3) +public class TermKeyListenerTest extends AndroidTestCase { + //TermKeyListener tkl_AltIsEsc; + TermKeyListener tkl_AltNotEsc; + //MockTermSession mckTermSessionA = new MockTermSession(); + MockTermSession mckTermSessionB = new MockTermSession(); + public TermKeyListenerTest() { + super(); + } + + public void setUp() { + //tkl_AltIsEsc = new TermKeyListener(mckTermSessionA); + tkl_AltNotEsc = new TermKeyListener(mckTermSessionB); + } + + public void testKey_a() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_A, + 0, + new byte[]{0x61}); + } + + public void testKey_X() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_X, + KeyEvent.META_SHIFT_ON, + new byte[]{0x58}); + } + + public void testKey_CTRL_c() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_C, + + KeyEvent.META_CTRL_ON , + new byte[]{0x03}); + } + + public void testKey_ALT_x_no_esc() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_X, + + KeyEvent.META_ALT_ON, + new byte[]{0x00,0x00,0x00,0x00}); + } + + public void testKey_ALT_c_no_esc() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_C, + + KeyEvent.META_ALT_ON, + new byte[]{-61,-89,0x00,0x00}); + } + + + public void testKey_enter() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_ENTER, + 0, + new byte[]{0x0d}); + } + + + public void testKey_del() + throws UnsupportedEncodingException, IOException { + KeyEvent event = new KeyEvent(1,2, KeyEvent.ACTION_DOWN, + KeyEvent.KEYCODE_DEL,0 ,0); + tkl_AltNotEsc.keyDown(event.getKeyCode(), event, true); + byte[] res = mckTermSessionB.getCharSequence(); + byte[] exp = "\177".getBytes("UTF-8"); + assertNotNull(res); + assertEquals(exp.length, res.length); + for (int i = 0; i<exp.length; i++) { + assertEquals(exp[i],res[i]); + } + } + + public void testKey_CTRL_C() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_C, + KeyEvent.META_CTRL_ON | KeyEvent.META_SHIFT_ON, + new byte[]{0x03}); + } + + public void testKey_CTRL_2() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_2, + KeyEvent.META_CTRL_ON, + new byte[]{0x00}); + } + + public void testKey_CTRL_SPC() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_SPACE, + KeyEvent.META_CTRL_ON, + new byte[]{0x00}); + } + + public void testKey_CTRL_3() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_3, + KeyEvent.META_CTRL_ON, + new byte[]{0x1b}); + } + + public void testKey_CTRL_LEFT_BRACKET() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_LEFT_BRACKET, + KeyEvent.META_CTRL_ON, + new byte[]{0x1b}); + } + + public void testKey_CTRL_BACKSLASH() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_BACKSLASH, + KeyEvent.META_CTRL_ON, + new byte[]{0x1c}); + } + + public void testKey_CTRL_4() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_4, + KeyEvent.META_CTRL_ON, + new byte[]{0x1c}); + } + + public void testKey_CTRL_RIGHT_BRACKET() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_RIGHT_BRACKET, + KeyEvent.META_CTRL_ON, + new byte[]{0x1d}); + } + + public void testKey_CTRL_5() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_5, + KeyEvent.META_CTRL_ON, + new byte[]{0x1d}); + } + + public void testKey_CTRL_CARET() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_6, + KeyEvent.META_CTRL_ON | KeyEvent.META_SHIFT_ON, + new byte[]{0x1e}); + } + + public void testKey_CTRL_6() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_6, + KeyEvent.META_CTRL_ON, + new byte[]{0x1e}); + } + + public void testKey_CTRL_UNDERSCORE() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_MINUS, + KeyEvent.META_CTRL_ON | KeyEvent.META_SHIFT_ON, + new byte[]{0x1f}); + } + + public void testKey_CTRL_7() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_7, + KeyEvent.META_CTRL_ON, + new byte[]{0x1f}); + } + + public void testKey_CTRL_8() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_8, + KeyEvent.META_CTRL_ON, + new byte[]{0x7f}); + } + + public void testKey_CTRL_9() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_9, + KeyEvent.META_CTRL_ON, + new byte[]{27,91,50,51,126}); + } + + public void testKey_CTRL_0() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_0, + KeyEvent.META_CTRL_ON, + new byte[]{27,91,50,52,126}); + } + + public void testKey_FN_w() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_W, + KeyEvent.META_FUNCTION_ON, + new byte[]{27,79,65}); + } + + public void testKey_FN_a() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_A, + KeyEvent.META_FUNCTION_ON, + new byte[]{27,79,68}); + } + + public void testKey_FN_s() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_S, + KeyEvent.META_FUNCTION_ON, + new byte[]{27,79,66}); + } + + public void testKey_FN_d() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_D, + KeyEvent.META_FUNCTION_ON, + new byte[]{27,79,67}); + } + + public void testKey_FN_p() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_P, + KeyEvent.META_FUNCTION_ON, + new byte[]{27,91,53,126}); + } + + public void testKey_FN_n() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_N, + KeyEvent.META_FUNCTION_ON, + new byte[]{27,91,54,126}); + } + + public void testKey_FN_t() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_T, + KeyEvent.META_FUNCTION_ON, + new byte[]{9}); + } + + public void testKey_FN_l() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_L, + KeyEvent.META_FUNCTION_ON, + new byte[]{124,0,0,0}); + } + + public void testKey_FN_u() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_U, + KeyEvent.META_FUNCTION_ON, + new byte[]{95,0,0,0}); + } + + public void testKey_FN_e() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_E, + KeyEvent.META_FUNCTION_ON, + new byte[]{27,0,0,0}); + } + + public void testKey_FN_i() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_I, + KeyEvent.META_FUNCTION_ON, + new byte[]{27,91,50,126}); + } + + public void testKey_FN_x() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_X, + KeyEvent.META_FUNCTION_ON, + new byte[]{27,91,51,126}); + } + + public void testKey_FN_h() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_H, + KeyEvent.META_FUNCTION_ON, + new byte[]{27,91,49,126}); + } + + public void testKey_FN_f() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_F, + KeyEvent.META_FUNCTION_ON, + new byte[]{27,91,52,126}); + } + + public void testKey_FN_PERIOD() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_PERIOD, + KeyEvent.META_FUNCTION_ON, + new byte[]{28,0,0,0}); + } + + public void testKey_FN_9() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_9, + KeyEvent.META_FUNCTION_ON, + new byte[]{-62,-69,0,0}); + } + + public void testKey_FN_0() + throws UnsupportedEncodingException, IOException { + keyHelper(KeyEvent.KEYCODE_0, + KeyEvent.META_FUNCTION_ON, + new byte[]{27,91,50,49,126}); + } + + private void keyHelper(int keycode, int metastate, byte[] expectedOutPut) + throws UnsupportedEncodingException, IOException { + KeyEvent event = new KeyEvent(1,2, KeyEvent.ACTION_DOWN, keycode, 0, + metastate); + tkl_AltNotEsc.keyDown(event.getKeyCode(), event, true); + byte[] res = mckTermSessionB.getCharSequence(); + assertNotNull(res); + assertTrue(expectedOutPut.length <= res.length); + for (int i=0; i<expectedOutPut.length; i++) { + assertEquals(expectedOutPut[i], res[i]); + } + } + + public void testPreconditions() { + + } + + public void tearDown() { + } + +} |