diff options
Diffstat (limited to 'tests/src/com/android/inputmethod/latin/common')
4 files changed, 89 insertions, 13 deletions
diff --git a/tests/src/com/android/inputmethod/latin/common/InputPointersTests.java b/tests/src/com/android/inputmethod/latin/common/InputPointersTests.java index 6b3490de8..9ead0ae25 100644 --- a/tests/src/com/android/inputmethod/latin/common/InputPointersTests.java +++ b/tests/src/com/android/inputmethod/latin/common/InputPointersTests.java @@ -16,15 +16,27 @@ package com.android.inputmethod.latin.common; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; import java.util.Arrays; @SmallTest -public class InputPointersTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class InputPointersTests { private static final int DEFAULT_CAPACITY = 48; + @Test public void testNewInstance() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); assertEquals("new instance size", 0, src.getPointerSize()); @@ -34,6 +46,7 @@ public class InputPointersTests extends AndroidTestCase { assertNotNull("new instance times", src.getTimes()); } + @Test public void testReset() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final int[] xCoordinates = src.getXCoordinates(); @@ -49,6 +62,7 @@ public class InputPointersTests extends AndroidTestCase { assertNotSame("times after reset", times, src.getTimes()); } + @Test public void testAdd() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final int limit = src.getXCoordinates().length * 2 + 10; @@ -72,6 +86,7 @@ public class InputPointersTests extends AndroidTestCase { } } + @Test public void testAddAt() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final int limit = 1000, step = 100; @@ -95,6 +110,7 @@ public class InputPointersTests extends AndroidTestCase { } } + @Test public void testSet() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final int limit = src.getXCoordinates().length * 2 + 10; @@ -114,6 +130,7 @@ public class InputPointersTests extends AndroidTestCase { assertSame("times after set", dst.getTimes(), src.getTimes()); } + @Test public void testCopy() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final int limit = 100; @@ -142,6 +159,7 @@ public class InputPointersTests extends AndroidTestCase { dst.getTimes(), 0, src.getTimes(), 0, size); } + @Test public void testAppend() { final int dstLength = 50; final InputPointers dst = new InputPointers(DEFAULT_CAPACITY); @@ -211,6 +229,7 @@ public class InputPointersTests extends AndroidTestCase { srcTimes.getPrimitiveArray(), startPos, dst.getTimes(), dstLength, srcLength); } + @Test public void testAppendResizableIntArray() { final int dstLength = 50; final InputPointers dst = new InputPointers(DEFAULT_CAPACITY); @@ -296,6 +315,7 @@ public class InputPointersTests extends AndroidTestCase { } } + @Test public void testShift() { final InputPointers src = new InputPointers(DEFAULT_CAPACITY); final int limit = 100; diff --git a/tests/src/com/android/inputmethod/latin/common/ResizableIntArrayTests.java b/tests/src/com/android/inputmethod/latin/common/ResizableIntArrayTests.java index bd1629faf..d9b6bad75 100644 --- a/tests/src/com/android/inputmethod/latin/common/ResizableIntArrayTests.java +++ b/tests/src/com/android/inputmethod/latin/common/ResizableIntArrayTests.java @@ -16,15 +16,27 @@ package com.android.inputmethod.latin.common; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import java.util.Arrays; +import org.junit.Test; +import org.junit.runner.RunWith; + @SmallTest -public class ResizableIntArrayTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class ResizableIntArrayTests { private static final int DEFAULT_CAPACITY = 48; + @Test public void testNewInstance() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int[] array = src.getPrimitiveArray(); @@ -33,6 +45,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { assertEquals("new instance array length", DEFAULT_CAPACITY, array.length); } + @Test public void testAdd() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int[] array = src.getPrimitiveArray(); @@ -62,6 +75,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { } } + @Test public void testAddAt() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int limit = DEFAULT_CAPACITY * 10, step = DEFAULT_CAPACITY * 2; @@ -76,6 +90,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { } } + @Test public void testGet() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); try { @@ -105,6 +120,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { } } + @Test public void testReset() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int[] array = src.getPrimitiveArray(); @@ -136,6 +152,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { } } + @Test public void testSetLength() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int[] array = src.getPrimitiveArray(); @@ -172,6 +189,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { } } + @Test public void testSet() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int limit = DEFAULT_CAPACITY * 2 + 10; @@ -186,6 +204,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { assertSame("array after set", dst.getPrimitiveArray(), src.getPrimitiveArray()); } + @Test public void testCopy() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); for (int i = 0; i < DEFAULT_CAPACITY; i++) { @@ -214,6 +233,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { dst.getPrimitiveArray(), 0, src.getPrimitiveArray(), 0, dst.getLength()); } + @Test public void testAppend() { final int srcLength = DEFAULT_CAPACITY; final ResizableIntArray src = new ResizableIntArray(srcLength); @@ -264,6 +284,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { srcLength); } + @Test public void testFill() { final int srcLength = DEFAULT_CAPACITY; final ResizableIntArray src = new ResizableIntArray(srcLength); @@ -359,6 +380,7 @@ public class ResizableIntArrayTests extends AndroidTestCase { } } + @Test public void testShift() { final ResizableIntArray src = new ResizableIntArray(DEFAULT_CAPACITY); final int limit = DEFAULT_CAPACITY * 10; diff --git a/tests/src/com/android/inputmethod/latin/common/StringUtilsTests.java b/tests/src/com/android/inputmethod/latin/common/StringUtilsTests.java index ec9d4be92..393efe6eb 100644 --- a/tests/src/com/android/inputmethod/latin/common/StringUtilsTests.java +++ b/tests/src/com/android/inputmethod/latin/common/StringUtilsTests.java @@ -16,13 +16,21 @@ package com.android.inputmethod.latin.common; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; import java.util.Locale; +import org.junit.Test; +import org.junit.runner.RunWith; + @SmallTest -public class StringUtilsTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class StringUtilsTests { private static final Locale US = Locale.US; private static final Locale GERMAN = Locale.GERMAN; private static final Locale TURKEY = new Locale("tr", "TR"); @@ -34,6 +42,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.toTitleCaseOfKeyLabel(lowerCase, locale)); } + @Test public void test_toTitleCaseOfKeyLabel() { assert_toTitleCaseOfKeyLabel(US, null, null); assert_toTitleCaseOfKeyLabel(US, "", ""); @@ -116,6 +125,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.toTitleCaseOfKeyCode(lowerCase, locale)); } + @Test public void test_toTitleCaseOfKeyCode() { assert_toTitleCaseOfKeyCode(US, Constants.CODE_ENTER, Constants.CODE_ENTER); assert_toTitleCaseOfKeyCode(US, Constants.CODE_SPACE, Constants.CODE_SPACE); @@ -148,6 +158,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.capitalizeFirstCodePoint(text, locale)); } + @Test public void test_capitalizeFirstCodePoint() { assert_capitalizeFirstCodePoint(US, "", ""); assert_capitalizeFirstCodePoint(US, "a", "A"); @@ -167,6 +178,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.capitalizeFirstAndDowncaseRest(text, locale)); } + @Test public void test_capitalizeFirstAndDowncaseRest() { assert_capitalizeFirstAndDowncaseRest(US, "", ""); assert_capitalizeFirstAndDowncaseRest(US, "a", "A"); @@ -185,6 +197,7 @@ public class StringUtilsTests extends AndroidTestCase { assert_capitalizeFirstAndDowncaseRest(GREECE, "ΆΝΕΣΗ", "Άνεση"); } + @Test public void testContainsInArray() { assertFalse("empty array", StringUtils.containsInArray("key", new String[0])); assertFalse("not in 1 element", StringUtils.containsInArray("key", new String[] { @@ -202,6 +215,7 @@ public class StringUtilsTests extends AndroidTestCase { })); } + @Test public void testContainsInCommaSplittableText() { assertFalse("null", StringUtils.containsInCommaSplittableText("key", null)); assertFalse("empty", StringUtils.containsInCommaSplittableText("key", "")); @@ -214,6 +228,7 @@ public class StringUtilsTests extends AndroidTestCase { assertTrue("in 2 elements", StringUtils.containsInCommaSplittableText("key", "key1,key")); } + @Test public void testRemoveFromCommaSplittableTextIfExists() { assertEquals("null", "", StringUtils.removeFromCommaSplittableTextIfExists("key", null)); assertEquals("empty", "", StringUtils.removeFromCommaSplittableTextIfExists("key", "")); @@ -239,7 +254,7 @@ public class StringUtilsTests extends AndroidTestCase { "key", "key1,key,key3,key,key5")); } - + @Test public void testCapitalizeFirstCodePoint() { assertEquals("SSaa", StringUtils.capitalizeFirstCodePoint("ßaa", Locale.GERMAN)); @@ -259,6 +274,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.capitalizeFirstCodePoint("A", Locale.ENGLISH)); } + @Test public void testCapitalizeFirstAndDowncaseRest() { assertEquals("SSaa", StringUtils.capitalizeFirstAndDowncaseRest("ßaa", Locale.GERMAN)); @@ -278,6 +294,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.capitalizeFirstAndDowncaseRest("A", Locale.ENGLISH)); } + @Test public void testGetCapitalizationType() { assertEquals(StringUtils.CAPITALIZE_NONE, StringUtils.getCapitalizationType("capitalize")); @@ -301,6 +318,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.getCapitalizationType("")); } + @Test public void testIsIdenticalAfterUpcaseIsIdenticalAfterDowncase() { assertFalse(StringUtils.isIdenticalAfterUpcase("capitalize")); assertTrue(StringUtils.isIdenticalAfterDowncase("capitalize")); @@ -337,6 +355,7 @@ public class StringUtilsTests extends AndroidTestCase { StringUtils.toSortedCodePointArray(" \n.!?*()&"); private static final int[] WORD_SEPARATORS = StringUtils.toSortedCodePointArray(" \n.!?*,();&"); + @Test public void testCapitalizeEachWord() { checkCapitalize("", "", SPACE, Locale.ENGLISH); checkCapitalize("test", "Test", SPACE, Locale.ENGLISH); @@ -367,6 +386,7 @@ public class StringUtilsTests extends AndroidTestCase { WORD_SEPARATORS, Locale.ENGLISH); } + @Test public void testLooksLikeURL() { assertTrue(StringUtils.lastPartLooksLikeURL("http://www.google.")); assertFalse(StringUtils.lastPartLooksLikeURL("word wo")); @@ -389,6 +409,7 @@ public class StringUtilsTests extends AndroidTestCase { assertTrue(StringUtils.lastPartLooksLikeURL(".abc/def")); } + @Test public void testHexStringUtils() { final byte[] bytes = new byte[] { (byte)0x01, (byte)0x11, (byte)0x22, (byte)0x33, (byte)0x55, (byte)0x88, (byte)0xEE }; @@ -401,6 +422,7 @@ public class StringUtilsTests extends AndroidTestCase { assertTrue(bytesStr.equals(bytesStr2)); } + @Test public void testToCodePointArray() { final String STR_WITH_SUPPLEMENTARY_CHAR = "abcde\uD861\uDED7fgh\u0000\u2002\u2003\u3000xx"; final int[] EXPECTED_RESULT = new int[] { 'a', 'b', 'c', 'd', 'e', 0x286D7, 'f', 'g', 'h', @@ -414,6 +436,7 @@ public class StringUtilsTests extends AndroidTestCase { } } + @Test public void testCopyCodePointsAndReturnCodePointCount() { final String STR_WITH_SUPPLEMENTARY_CHAR = "AbcDE\uD861\uDED7fGh\u0000\u2002\u3000あx"; final int[] EXPECTED_RESULT = new int[] { 'A', 'b', 'c', 'D', 'E', 0x286D7, @@ -465,6 +488,7 @@ public class StringUtilsTests extends AndroidTestCase { exceptionHappened); } + @Test public void testGetTrailingSingleQuotesCount() { assertEquals(0, StringUtils.getTrailingSingleQuotesCount("")); assertEquals(1, StringUtils.getTrailingSingleQuotesCount("'")); diff --git a/tests/src/com/android/inputmethod/latin/common/UnicodeSurrogateTests.java b/tests/src/com/android/inputmethod/latin/common/UnicodeSurrogateTests.java index 59bb08292..43fdeec96 100644 --- a/tests/src/com/android/inputmethod/latin/common/UnicodeSurrogateTests.java +++ b/tests/src/com/android/inputmethod/latin/common/UnicodeSurrogateTests.java @@ -16,18 +16,28 @@ package com.android.inputmethod.latin.common; -import android.test.AndroidTestCase; -import android.test.suitebuilder.annotation.SmallTest; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import android.support.test.filters.SmallTest; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; @SmallTest -public class UnicodeSurrogateTests extends AndroidTestCase { +@RunWith(AndroidJUnit4.class) +public class UnicodeSurrogateTests { + @Test public void testIsLowSurrogate() { assertFalse(UnicodeSurrogate.isLowSurrogate('\uD7FF')); assertTrue(UnicodeSurrogate.isLowSurrogate('\uD83D')); assertFalse(UnicodeSurrogate.isLowSurrogate('\uDC00')); } + @Test public void testIsHighSurrogate() { assertFalse(UnicodeSurrogate.isHighSurrogate('\uDBFF')); assertTrue(UnicodeSurrogate.isHighSurrogate('\uDE25')); |