summaryrefslogtreecommitdiffstats
path: root/common/tests
diff options
context:
space:
mode:
authorDan Egnor <egnor@google.com>2009-11-18 11:23:45 -0800
committerDan Egnor <egnor@google.com>2009-11-18 12:05:04 -0800
commitded0e6447ed6e0f200dbca13e43c6cf4efc16a1d (patch)
treea9fa405cf73e77232588e6e35b9485f6e7170d67 /common/tests
parenta4fa107f97933a81c42ee3cd9ca3984c08e5ab25 (diff)
downloadframeworks_base-ded0e6447ed6e0f200dbca13e43c6cf4efc16a1d.zip
frameworks_base-ded0e6447ed6e0f200dbca13e43c6cf4efc16a1d.tar.gz
frameworks_base-ded0e6447ed6e0f200dbca13e43c6cf4efc16a1d.tar.bz2
Create android-common static library which gets included in frameworks.jar,
but can also be used by unbundled apps. Move android.text.util.Regex there as a starting example, renamed to a more sensible (?) com.android.common.Patterns. Set up a corresponding test package, and move RegexTest (to PatternsTest). Update clients.
Diffstat (limited to 'common/tests')
-rw-r--r--common/tests/Android.mk26
-rw-r--r--common/tests/AndroidManifest.xml30
-rw-r--r--common/tests/src/com/android/common/PatternsTest.java123
3 files changed, 179 insertions, 0 deletions
diff --git a/common/tests/Android.mk b/common/tests/Android.mk
new file mode 100644
index 0000000..0f2c3e4
--- /dev/null
+++ b/common/tests/Android.mk
@@ -0,0 +1,26 @@
+# Copyright (C) 2009 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.
+
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+LOCAL_CERTIFICATE := platform
+LOCAL_JAVA_LIBRARIES := android.test.runner
+LOCAL_MODULE_TAGS := tests
+LOCAL_PACKAGE_NAME := AndroidCommonTests
+LOCAL_SDK_VERSION := current
+LOCAL_SRC_FILES := $(call all-java-files-under, src)
+LOCAL_STATIC_JAVA_LIBRARIES := android-common
+
+include $(BUILD_PACKAGE)
diff --git a/common/tests/AndroidManifest.xml b/common/tests/AndroidManifest.xml
new file mode 100644
index 0000000..151ec20
--- /dev/null
+++ b/common/tests/AndroidManifest.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2009 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.
+-->
+
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.common.tests"
+ android:sharedUserId="com.android.uid.test">
+
+ <application>
+ <uses-library android:name="android.test.runner" />
+ </application>
+
+ <!-- Run tests with "runtest common" -->
+ <instrumentation android:name="android.test.InstrumentationTestRunner"
+ android:targetPackage="com.android.common.tests"
+ android:label="Android Common Library Tests" />
+
+</manifest>
diff --git a/common/tests/src/com/android/common/PatternsTest.java b/common/tests/src/com/android/common/PatternsTest.java
new file mode 100644
index 0000000..a89ad62
--- /dev/null
+++ b/common/tests/src/com/android/common/PatternsTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2007 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.common;
+
+import android.test.suitebuilder.annotation.SmallTest;
+import junit.framework.TestCase;
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class PatternsTest extends TestCase {
+
+ @SmallTest
+ public void testTldPattern() throws Exception {
+ boolean t;
+
+ t = Patterns.TOP_LEVEL_DOMAIN_PATTERN.matcher("com").matches();
+ assertTrue("Missed valid TLD", t);
+
+ t = Patterns.TOP_LEVEL_DOMAIN_PATTERN.matcher("xer").matches();
+ assertFalse("Matched invalid TLD!", t);
+ }
+
+ @SmallTest
+ public void testUrlPattern() throws Exception {
+ boolean t;
+
+ t = Patterns.WEB_URL_PATTERN.matcher("http://www.google.com").matches();
+ assertTrue("Valid URL", t);
+
+ t = Patterns.WEB_URL_PATTERN.matcher("ftp://www.example.com").matches();
+ assertFalse("Matched invalid protocol", t);
+
+ t = Patterns.WEB_URL_PATTERN.matcher("http://www.example.com:8080").matches();
+ assertTrue("Didn't match valid URL with port", t);
+
+ t = Patterns.WEB_URL_PATTERN.matcher("http://www.example.com:8080/?foo=bar").matches();
+ assertTrue("Didn't match valid URL with port and query args", t);
+
+ t = Patterns.WEB_URL_PATTERN.matcher("http://www.example.com:8080/~user/?foo=bar").matches();
+ assertTrue("Didn't match valid URL with ~", t);
+ }
+
+ @SmallTest
+ public void testIpPattern() throws Exception {
+ boolean t;
+
+ t = Patterns.IP_ADDRESS_PATTERN.matcher("172.29.86.3").matches();
+ assertTrue("Valid IP", t);
+
+ t = Patterns.IP_ADDRESS_PATTERN.matcher("1234.4321.9.9").matches();
+ assertFalse("Invalid IP", t);
+ }
+
+ @SmallTest
+ public void testDomainPattern() throws Exception {
+ boolean t;
+
+ t = Patterns.DOMAIN_NAME_PATTERN.matcher("mail.example.com").matches();
+ assertTrue("Valid domain", t);
+
+ t = Patterns.DOMAIN_NAME_PATTERN.matcher("__+&42.xer").matches();
+ assertFalse("Invalid domain", t);
+ }
+
+ @SmallTest
+ public void testPhonePattern() throws Exception {
+ boolean t;
+
+ t = Patterns.PHONE_PATTERN.matcher("(919) 555-1212").matches();
+ assertTrue("Valid phone", t);
+
+ t = Patterns.PHONE_PATTERN.matcher("2334 9323/54321").matches();
+ assertFalse("Invalid phone", t);
+
+ String[] tests = {
+ "Me: 16505551212 this\n",
+ "Me: 6505551212 this\n",
+ "Me: 5551212 this\n",
+
+ "Me: 1-650-555-1212 this\n",
+ "Me: (650) 555-1212 this\n",
+ "Me: +1 (650) 555-1212 this\n",
+ "Me: +1-650-555-1212 this\n",
+ "Me: 650-555-1212 this\n",
+ "Me: 555-1212 this\n",
+
+ "Me: 1.650.555.1212 this\n",
+ "Me: (650) 555.1212 this\n",
+ "Me: +1 (650) 555.1212 this\n",
+ "Me: +1.650.555.1212 this\n",
+ "Me: 650.555.1212 this\n",
+ "Me: 555.1212 this\n",
+
+ "Me: 1 650 555 1212 this\n",
+ "Me: (650) 555 1212 this\n",
+ "Me: +1 (650) 555 1212 this\n",
+ "Me: +1 650 555 1212 this\n",
+ "Me: 650 555 1212 this\n",
+ "Me: 555 1212 this\n",
+ };
+
+ for (String test : tests) {
+ Matcher m = Patterns.PHONE_PATTERN.matcher(test);
+
+ assertTrue("Valid phone " + test, m.find());
+ }
+ }
+}