summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorAndy McFadden <fadden@android.com>2012-01-20 13:37:56 -0800
committerAndy McFadden <fadden@android.com>2012-01-20 13:38:32 -0800
commita5a184892e60a89b564ca7c74e50b2ecb27d9f80 (patch)
treef2832b895a3a8341f084c83c2a44afe1384dd5f2 /tests
parent8a7b9fd899ea2b89e99fe3d81210fa8349ec2c60 (diff)
downloadandroid_dalvik-a5a184892e60a89b564ca7c74e50b2ecb27d9f80.tar.gz
android_dalvik-a5a184892e60a89b564ca7c74e50b2ecb27d9f80.tar.bz2
android_dalvik-a5a184892e60a89b564ca7c74e50b2ecb27d9f80.zip
Update and extend Dalvik tests
029 - exercise setDefaultAssertionStatus 031 - enable some tests that were disabled back when our generics support didn't exist. Added new FancyClass test. 034 - print success/fail rather than matching exact exception text 038 - (same as 034) 042 - added new test for bug 5861201, currently disabled 045 - added a bunch of new tests, including one that fails 046 - added new tests, including some for bug 5861201 (the latter are disabled) 068 - loadClass() wants class names with dots, not slashes 086 - (same as 068) 087 - (same as 068) 092 - new test, exercises some locale-specific classes 093 - new test, exercises object serialization 094 - new test, exercises regex code Test 045 now fails, because it's exercising a feature that should work but doesn't. All others pass. Change-Id: I6481bfa88681c4ac8af629cb60797b2708bdeba4
Diffstat (limited to 'tests')
-rw-r--r--tests/029-assert/src/Main.java3
-rw-r--r--tests/031-class-attributes/expected.txt47
-rw-r--r--tests/031-class-attributes/src/ClassAttrs.java17
-rw-r--r--tests/031-class-attributes/src/FancyClass.java22
-rw-r--r--tests/034-call-null/expected.txt4
-rw-r--r--tests/034-call-null/src/Main.java7
-rw-r--r--tests/038-inner-null/expected.txt5
-rw-r--r--tests/038-inner-null/src/Main.java6
-rw-r--r--tests/042-new-instance/expected.txt1
-rw-r--r--tests/042-new-instance/src/Main.java21
-rw-r--r--tests/042-new-instance/src/otherpackage/PackageAccess.java23
-rw-r--r--tests/045-reflect-array/expected.txt3
-rw-r--r--tests/045-reflect-array/src/Main.java123
-rw-r--r--tests/046-reflect/expected.txt5
-rw-r--r--tests/046-reflect/src/Main.java118
-rw-r--r--tests/046-reflect/src/otherpackage/Other.java38
-rw-r--r--tests/068-classloader/src/FancyLoader.java2
-rw-r--r--tests/086-null-super/src/Main.java2
-rw-r--r--tests/087-gc-after-link/src/Main.java2
-rw-r--r--tests/092-locale/expected.txt8
-rw-r--r--tests/092-locale/info.txt1
-rw-r--r--tests/092-locale/src/Main.java136
-rw-r--r--tests/093-serialization/expected.txt1
-rw-r--r--tests/093-serialization/info.txt1
-rw-r--r--tests/093-serialization/src/Main.java116
-rw-r--r--tests/094-pattern/expected.txt3
-rw-r--r--tests/094-pattern/info.txt4
-rw-r--r--tests/094-pattern/src/Main.java95
28 files changed, 787 insertions, 27 deletions
diff --git a/tests/029-assert/src/Main.java b/tests/029-assert/src/Main.java
index 1e5cc7c67..3b1f8da4c 100644
--- a/tests/029-assert/src/Main.java
+++ b/tests/029-assert/src/Main.java
@@ -12,5 +12,8 @@ public class Main {
} catch (AssertionError ae) {
System.out.println("caught expected assert exception");
}
+
+ // exercise this code path
+ ClassLoader.getSystemClassLoader().setDefaultAssertionStatus(true);
}
}
diff --git a/tests/031-class-attributes/expected.txt b/tests/031-class-attributes/expected.txt
index 47eaeeec2..afa3416e2 100644
--- a/tests/031-class-attributes/expected.txt
+++ b/tests/031-class-attributes/expected.txt
@@ -4,6 +4,7 @@
simple: ClassAttrs
genericSignature: null
super: class java.lang.Object
+ genericSuperclass: class java.lang.Object
declaring: null
enclosing: null
enclosingCon: null
@@ -21,12 +22,15 @@
isMemberClass: false
isPrimitive: false
isSynthetic: false
+ genericInterfaces: [0]
+ typeParameters: [0]
***** class OtherClass:
name: OtherClass
canonical: OtherClass
simple: OtherClass
genericSignature: null
super: class java.lang.Object
+ genericSuperclass: class java.lang.Object
declaring: null
enclosing: null
enclosingCon: null
@@ -44,12 +48,15 @@
isMemberClass: false
isPrimitive: false
isSynthetic: false
+ genericInterfaces: [0]
+ typeParameters: [0]
***** class otherpackage.OtherPackageClass:
name: otherpackage.OtherPackageClass
canonical: otherpackage.OtherPackageClass
simple: OtherPackageClass
genericSignature: null
super: class java.lang.Object
+ genericSuperclass: class java.lang.Object
declaring: null
enclosing: null
enclosingCon: null
@@ -67,12 +74,15 @@
isMemberClass: false
isPrimitive: false
isSynthetic: false
+ genericInterfaces: [0]
+ typeParameters: [0]
***** class ClassAttrs$1InnerNamed:
name: ClassAttrs$1InnerNamed
canonical: null
simple: InnerNamed
genericSignature: null
super: class java.lang.Object
+ genericSuperclass: class java.lang.Object
declaring: null
enclosing: class ClassAttrs
enclosingCon: null
@@ -90,12 +100,15 @@
isMemberClass: false
isPrimitive: false
isSynthetic: false
+ genericInterfaces: [0]
+ typeParameters: [0]
***** class ClassAttrs$1ConsInnerNamed:
name: ClassAttrs$1ConsInnerNamed
canonical: null
simple: ConsInnerNamed
genericSignature: null
super: class java.lang.Object
+ genericSuperclass: class java.lang.Object
declaring: null
enclosing: class ClassAttrs
enclosingCon: ClassAttrs()
@@ -113,12 +126,15 @@
isMemberClass: false
isPrimitive: false
isSynthetic: false
+ genericInterfaces: [0]
+ typeParameters: [0]
***** class ClassAttrs$1:
name: ClassAttrs$1
canonical: null
simple:
genericSignature: null
super: class OtherClass
+ genericSuperclass: class OtherClass
declaring: null
enclosing: class ClassAttrs
enclosingCon: null
@@ -136,12 +152,15 @@
isMemberClass: false
isPrimitive: false
isSynthetic: false
+ genericInterfaces: [0]
+ typeParameters: [0]
***** class ClassAttrs$MemberClass:
name: ClassAttrs$MemberClass
canonical: ClassAttrs.MemberClass
simple: MemberClass
genericSignature: <XYZ:Ljava/lang/Object;>Ljava/lang/Object;
super: class java.lang.Object
+ genericSuperclass: class java.lang.Object
declaring: class ClassAttrs
enclosing: class ClassAttrs
enclosingCon: null
@@ -159,6 +178,34 @@
isMemberClass: true
isPrimitive: false
isSynthetic: false
+ genericInterfaces: [0]
+ typeParameters: [1] XYZ
+***** class FancyClass:
+ name: FancyClass
+ canonical: FancyClass
+ simple: FancyClass
+ genericSignature: <K:Ljava/lang/Object;V:Ljava/lang/Object;>Ljava/util/HashMap<TK;TV;>;Ljava/util/Map<TK;TV;>;
+ super: class java.util.HashMap
+ genericSuperclass: java.util.HashMap<K, V>
+ declaring: null
+ enclosing: null
+ enclosingCon: null
+ enclosingMeth: null
+ modifiers: 1
+ package: null
+ declaredClasses: [0]
+ member classes: [2] class java.util.AbstractMap$SimpleEntry, class java.util.AbstractMap$SimpleImmutableEntry
+ isAnnotation: false
+ isAnonymous: false
+ isArray: false
+ isEnum: false
+ isInterface: false
+ isLocalClass: false
+ isMemberClass: false
+ isPrimitive: false
+ isSynthetic: false
+ genericInterfaces: [1] java.util.Map<K, V>
+ typeParameters: [2] K, V
constructor signature: (LClassAttrs$MemberClass<TXYZ;>;)V
method signature: ()Ljava/lang/Class<TXYZ;>;
field signature: LClassAttrs$MemberClass<TXYZ;>;
diff --git a/tests/031-class-attributes/src/ClassAttrs.java b/tests/031-class-attributes/src/ClassAttrs.java
index c1407bdcf..d93a9257f 100644
--- a/tests/031-class-attributes/src/ClassAttrs.java
+++ b/tests/031-class-attributes/src/ClassAttrs.java
@@ -6,6 +6,7 @@ import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
public class ClassAttrs {
ClassAttrs() {
@@ -42,6 +43,9 @@ public class ClassAttrs {
/* member, not anonymous, not local */
printClassAttrs(MemberClass.class);
+ /* fancy */
+ printClassAttrs(FancyClass.class);
+
try {
Constructor cons;
cons = MemberClass.class.getConstructor(
@@ -82,8 +86,8 @@ public class ClassAttrs {
}
method.setAccessible(true);
} catch (NoSuchMethodException ex) {
- System.err.println("getSignatureAttribute() not defined.");
- ex.printStackTrace();
+ //System.err.println("getSignatureAttribute() not defined.");
+ //ex.printStackTrace();
return "<unknown>";
}
@@ -118,7 +122,6 @@ public class ClassAttrs {
* Dump a variety of class attributes.
*/
public static void printClassAttrs(Class clazz) {
- final boolean WORKING = false;
Class clazz2;
System.out.println("***** " + clazz + ":");
@@ -134,7 +137,7 @@ public class ClassAttrs {
System.out.println(" super: "
+ clazz.getSuperclass());
- if (WORKING) System.out.println(" genericSuperclass: "
+ System.out.println(" genericSuperclass: "
+ clazz.getGenericSuperclass());
System.out.println(" declaring: "
+ clazz.getDeclaringClass());
@@ -173,8 +176,12 @@ public class ClassAttrs {
System.out.println(" isSynthetic: "
+ clazz.isSynthetic());
- if (WORKING) System.out.println(" genericInterfaces: "
+ System.out.println(" genericInterfaces: "
+ stringifyTypeArray(clazz.getGenericInterfaces()));
+
+ TypeVariable<Class<?>>[] typeParameters = clazz.getTypeParameters();
+ System.out.println(" typeParameters: "
+ + stringifyTypeArray(typeParameters));
}
/*
diff --git a/tests/031-class-attributes/src/FancyClass.java b/tests/031-class-attributes/src/FancyClass.java
new file mode 100644
index 000000000..a58b6a623
--- /dev/null
+++ b/tests/031-class-attributes/src/FancyClass.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class FancyClass<K,V> extends HashMap<K,V> implements Map<K,V> {
+}
+
diff --git a/tests/034-call-null/expected.txt b/tests/034-call-null/expected.txt
index 5ffbe052a..19f86f493 100644
--- a/tests/034-call-null/expected.txt
+++ b/tests/034-call-null/expected.txt
@@ -1,3 +1 @@
-java.lang.NullPointerException
- at Main.main(Main.java:12)
- at dalvik.system.NativeStart.main(Native Method)
+done
diff --git a/tests/034-call-null/src/Main.java b/tests/034-call-null/src/Main.java
index a0a129e86..8fe88bdd9 100644
--- a/tests/034-call-null/src/Main.java
+++ b/tests/034-call-null/src/Main.java
@@ -9,6 +9,11 @@ public class Main {
public static void main(String[] args) {
Main instance = null;
- instance.doStuff();
+ try {
+ instance.doStuff();
+ throw new RuntimeException("fail");
+ } catch (NullPointerException npe) { }
+
+ System.out.println("done");
}
}
diff --git a/tests/038-inner-null/expected.txt b/tests/038-inner-null/expected.txt
index 0be8ffdc4..29c1e420e 100644
--- a/tests/038-inner-null/expected.txt
+++ b/tests/038-inner-null/expected.txt
@@ -1,5 +1,2 @@
new Special()
-java.lang.NullPointerException
- at Main$Special.callInner(Main.java:17)
- at Main.main(Main.java:6)
- at dalvik.system.NativeStart.main(Native Method)
+done
diff --git a/tests/038-inner-null/src/Main.java b/tests/038-inner-null/src/Main.java
index acc87640b..1239248c0 100644
--- a/tests/038-inner-null/src/Main.java
+++ b/tests/038-inner-null/src/Main.java
@@ -4,6 +4,7 @@ public class Main {
public static void main(String[] args) {
Special special = new Special();
special.callInner();
+ System.out.println("done");
}
public static class Special {
@@ -14,7 +15,10 @@ public class Main {
}
public void callInner() {
- mBlort.repaint();
+ try {
+ mBlort.repaint();
+ throw new RuntimeException("fail");
+ } catch (NullPointerException npe) {}
}
}
diff --git a/tests/042-new-instance/expected.txt b/tests/042-new-instance/expected.txt
index 53447db2b..bb1b80c12 100644
--- a/tests/042-new-instance/expected.txt
+++ b/tests/042-new-instance/expected.txt
@@ -6,3 +6,4 @@ Cons LocalClass failed as expected
Cons LocalClass2 succeeded
Cons got expected PackageAccess complaint
Cons got expected InstantationException
+Cons got expected PackageAccess2 complaint
diff --git a/tests/042-new-instance/src/Main.java b/tests/042-new-instance/src/Main.java
index 8faef1349..e43c5a568 100644
--- a/tests/042-new-instance/src/Main.java
+++ b/tests/042-new-instance/src/Main.java
@@ -16,12 +16,12 @@
import java.lang.reflect.Constructor;
-import java.lang.reflect.Constructor;
-
/**
* Test instance creation.
*/
public class Main {
+ private static boolean FULL_ACCESS_CHECKS = false; // b/5861201
+
public static void main(String[] args) {
testClassNewInstance();
testConstructorNewInstance();
@@ -98,6 +98,7 @@ public class Main {
Constructor cons = c.getConstructor(new Class[0] /*(Class[])null*/);
System.err.println("ERROR: Cons PackageAccess succeeded unexpectedly");
} catch (NoSuchMethodException nsme) {
+ // constructor isn't public
System.out.println("Cons got expected PackageAccess complaint");
} catch (Exception ex) {
System.err.println("Cons got unexpected PackageAccess failure");
@@ -117,6 +118,22 @@ public class Main {
System.err.println("Cons got unexpected MaybeAbstract failure");
ex.printStackTrace();
}
+
+ // should fail
+ try {
+ Class c = Class.forName("otherpackage.PackageAccess2");
+ Constructor cons = c.getConstructor((Class[]) null);
+ if (!FULL_ACCESS_CHECKS) { throw new IllegalAccessException(); }
+ Object obj = cons.newInstance();
+ System.err.println("ERROR: Cons PackageAccess2 succeeded unexpectedly");
+ } catch (IllegalAccessException iae) {
+ // constructor is public, but class has package scope
+ System.out.println("Cons got expected PackageAccess2 complaint");
+ } catch (Exception ex) {
+ System.err.println("Cons got unexpected PackageAccess2 failure");
+ ex.printStackTrace();
+ }
+
}
}
diff --git a/tests/042-new-instance/src/otherpackage/PackageAccess.java b/tests/042-new-instance/src/otherpackage/PackageAccess.java
index 0749d6792..f4541f20c 100644
--- a/tests/042-new-instance/src/otherpackage/PackageAccess.java
+++ b/tests/042-new-instance/src/otherpackage/PackageAccess.java
@@ -1,6 +1,29 @@
+/*
+ * 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 otherpackage;
class PackageAccess {
/*package*/ PackageAccess() {
+ System.out.println("created PackageAccess");
+ }
+}
+
+class PackageAccess2 {
+ public PackageAccess2() {
+ System.out.println("created PackageAccess2");
}
}
diff --git a/tests/045-reflect-array/expected.txt b/tests/045-reflect-array/expected.txt
index 5c609b5c1..5990b34a4 100644
--- a/tests/045-reflect-array/expected.txt
+++ b/tests/045-reflect-array/expected.txt
@@ -1,4 +1,7 @@
ReflectArrayTest.testSingleInt passed
+ReflectArrayTest.testSingleChar passed
+ReflectArrayTest.testSingleShort passed
+ReflectArrayTest.testSingleLong passed
ReflectArrayTest.testSingle passed
ReflectArrayTest.testMultiInt passed
zero one two ++
diff --git a/tests/045-reflect-array/src/Main.java b/tests/045-reflect-array/src/Main.java
index c70e291fa..36f8ac388 100644
--- a/tests/045-reflect-array/src/Main.java
+++ b/tests/045-reflect-array/src/Main.java
@@ -10,6 +10,9 @@ import java.lang.reflect.Array;
public class Main {
public static void main(String[] args) {
testSingleInt();
+ testSingleChar();
+ testSingleShort();
+ testSingleLong();
testSingle();
testMultiInt();
testMulti();
@@ -33,22 +36,31 @@ public class Main {
try {
array[2] = 27;
throw new RuntimeException("store should have failed");
- }
- catch (ArrayIndexOutOfBoundsException abe) {
- }
+ } catch (ArrayIndexOutOfBoundsException abe) { }
+ try {
+ Array.setInt(intArray, 2, 27);
+ throw new RuntimeException("store should have failed");
+ } catch (ArrayIndexOutOfBoundsException abe) { }
if (array.length != Array.getLength(intArray) ||
array.length != 2)
{
throw new RuntimeException("bad len");
}
+ Integer x123 = Integer.valueOf(123);
+ Integer x456 = Integer.valueOf(456);
+
+ Array.set(intArray, 0, x123);
+ Array.set(intArray, 1, x456);
+ if (!Array.get(intArray, 0).equals(x123) || !Array.get(intArray, 1).equals(x456)) {
+ throw new RuntimeException("bad 123 or 456");
+ }
+
int[][] wrongArray;
try {
wrongArray = (int[][]) intArray;
throw new RuntimeException("cast should have failed");
- }
- catch (ClassCastException cce) {
- }
+ } catch (ClassCastException cce) { }
intArray = Array.newInstance(Integer.TYPE, 0);
if (Array.getLength(intArray) != 0)
@@ -56,6 +68,96 @@ public class Main {
System.out.println("ReflectArrayTest.testSingleInt passed");
}
+ static void testSingleChar() {
+ Object charArray = Array.newInstance(Character.TYPE, 7);
+
+ char[] array = (char[]) charArray;
+ array[0] = '0';
+ array[1] = 'W';
+ array[2] = '2';
+ array[3] = '3';
+ array[4] = 'X';
+ array[5] = '5';
+ array[6] = '6';
+ Array.setChar(charArray, 1, '1');
+ Array.setChar(charArray, 4, '4');
+ try {
+ Array.setShort(charArray, 3, (short) 'Y');
+ throw new RuntimeException("shouldn't allow short in char array");
+ } catch (IllegalArgumentException iae) {}
+ try {
+ Array.setInt(charArray, 5, 'Z');
+ throw new RuntimeException("shouldn't allow int in char array");
+ } catch (IllegalArgumentException iae) {}
+
+ try {
+ for (int i = 0; i < array.length; i++) {
+ if (Array.getInt(charArray, i) - '0' != i) {
+ throw new RuntimeException("mismatch: " + i + " is " + array[i]);
+ }
+ }
+
+ if (Array.getInt(charArray, 4) != '4') {
+ throw new RuntimeException("load should have worked");
+ }
+ } catch (IllegalArgumentException iae) {
+ System.err.println("Couldn't Array.getInt(charArray)");
+ }
+ try {
+ Array.getByte(charArray, 2);
+ throw new RuntimeException("shouldn't allow read of char as byte");
+ } catch (IllegalArgumentException iae) {}
+
+ Array.setChar(charArray, 3, (char) 0xffff);
+ try {
+ if (Array.getInt(charArray, 3) != 0xffff) {
+ throw new RuntimeException("char got sign-extended? "
+ + Array.getInt(charArray, 3));
+ }
+ } catch (IllegalArgumentException iae) {
+ System.err.println("Couldn't Array.getInt(charArray)");
+ }
+
+ System.out.println("ReflectArrayTest.testSingleChar passed");
+ }
+
+ static void testSingleShort() {
+ Object shortArray = Array.newInstance(Short.TYPE, 1);
+ Array.setShort(shortArray, 0, (short) -1);
+ if (Array.getInt(shortArray, 0) != -1) {
+ throw new RuntimeException("short didn't get sign-extended");
+ }
+
+ Short box = (Short) Array.get(shortArray, 0);
+
+ System.out.println("ReflectArrayTest.testSingleShort passed");
+ }
+
+ static void testSingleLong() {
+ Object longArray = Array.newInstance(Long.TYPE, 2);
+ Array.setInt(longArray, 0, 123);
+ Array.setLong(longArray, 1, 0x1122334455667788L);
+ try {
+ Array.getInt(longArray, 0);
+ throw new RuntimeException("shouldn't allow read of long as int");
+ } catch (IllegalArgumentException iae) {}
+
+ long[] array = (long[]) longArray;
+ if (array[0] != 123 || array[1] != 0x1122334455667788L) {
+ throw new RuntimeException();
+ }
+
+ float f = Array.getFloat(longArray, 0);
+ if (f < 122.9 || f > 123.1) {
+ throw new RuntimeException("long-as-float failed - " + f);
+ }
+ if (Array.getLong(longArray, 1) != 0x1122334455667788L) {
+ throw new RuntimeException("long1 failed");
+ }
+
+ System.out.println("ReflectArrayTest.testSingleLong passed");
+ }
+
static void testSingle() {
Object strArray;
@@ -64,6 +166,10 @@ public class Main {
String[] array = (String[]) strArray;
array[0] = "entry zero";
Array.set(strArray, 1, "entry one");
+ try {
+ Array.set(strArray, 2, "entry two");
+ throw new RuntimeException("store should have failed");
+ } catch (ArrayIndexOutOfBoundsException abe) { }
//System.out.println("array: " + array);
@@ -77,6 +183,11 @@ public class Main {
{
throw new RuntimeException("bad len");
}
+
+ try {
+ Array.set(strArray, 0, new Integer(5));
+ throw new RuntimeException("store of Integer should have failed");
+ } catch (IllegalArgumentException iae) {}
System.out.println("ReflectArrayTest.testSingle passed");
}
diff --git a/tests/046-reflect/expected.txt b/tests/046-reflect/expected.txt
index 55b0eca6b..309b07689 100644
--- a/tests/046-reflect/expected.txt
+++ b/tests/046-reflect/expected.txt
@@ -90,8 +90,13 @@ Target constructor (IF)V : ii=7 ff=3.3333
myMethod (I)I
arg=17 anInt=7
ReflectTest done!
+public method
checkType invoking null
checkType got expected exception
got methods
NoisyInitUser is initializing
NoisyInit is initializing
+
+generic field: java.util.List<java.lang.String>
+generic method fancyMethod params='[1] java.util.ArrayList<java.lang.String>' ret='java.util.Map<java.lang.Integer, java.lang.String>'
+generic ctor Main params='[1] java.util.ArrayList<java.lang.Integer>'
diff --git a/tests/046-reflect/src/Main.java b/tests/046-reflect/src/Main.java
index e6049797c..e2a3929dd 100644
--- a/tests/046-reflect/src/Main.java
+++ b/tests/046-reflect/src/Main.java
@@ -3,11 +3,18 @@
import java.lang.reflect.*;
import java.io.IOException;
import java.util.Collections;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
/**
* Reflection test.
*/
public class Main {
+ private static boolean FULL_ACCESS_CHECKS = false; // b/5861201
+ public Main() {}
+ public Main(ArrayList<Integer> stuff) {}
+
void printMethodInfo(Method meth) {
Class[] params, exceptions;
int i;
@@ -55,6 +62,48 @@ public class Main {
System.out.println(" ::: " + one + ":" + two + ":" + three);
}
+ public static void checkAccess() {
+ try {
+ Class target = otherpackage.Other.class;
+ Object instance = new otherpackage.Other();
+ Method meth;
+
+ meth = target.getMethod("publicMethod", (Class[]) null);
+ meth.invoke(instance);
+
+ try {
+ meth = target.getMethod("packageMethod", (Class[]) null);
+ System.err.println("succeeded on package-scope method");
+ } catch (NoSuchMethodException nsme) {
+ // good
+ }
+
+
+ instance = otherpackage.Other.getInnerClassInstance();
+ target = instance.getClass();
+ meth = target.getMethod("innerMethod", (Class[]) null);
+ try {
+ if (!FULL_ACCESS_CHECKS) { throw new IllegalAccessException(); }
+ meth.invoke(instance);
+ System.err.println("inner-method invoke unexpectedly worked");
+ } catch (IllegalAccessException iae) {
+ // good
+ }
+
+ Field field = target.getField("innerField");
+ try {
+ int x = field.getInt(instance);
+ if (!FULL_ACCESS_CHECKS) { throw new IllegalAccessException(); }
+ System.err.println("field get unexpectedly worked: " + x);
+ } catch (IllegalAccessException iae) {
+ // good
+ }
+ } catch (Exception ex) {
+ System.out.println("----- unexpected exception -----");
+ ex.printStackTrace();
+ }
+ }
+
public void run() {
Class target = Target.class;
Method meth = null;
@@ -295,8 +344,7 @@ public class Main {
targ = cons.newInstance(args);
targ.myMethod(17);
- }
- catch (Exception ex) {
+ } catch (Exception ex) {
System.out.println("----- unexpected exception -----");
ex.printStackTrace();
}
@@ -347,14 +395,80 @@ public class Main {
/* neither NoisyInit nor NoisyInitUser should be initialized yet */
NoisyInitUser niu = new NoisyInitUser();
NoisyInit ni = new NoisyInit();
+
+ System.out.println("");
+ }
+
+
+ /*
+ * Test some generic type stuff.
+ */
+ public List<String> dummy;
+ public Map<Integer,String> fancyMethod(ArrayList<String> blah) { return null; }
+ public static void checkGeneric() {
+ Field field;
+ try {
+ field = Main.class.getField("dummy");
+ } catch (NoSuchFieldException nsfe) {
+ throw new RuntimeException(nsfe);
+ }
+ Type listType = field.getGenericType();
+ System.out.println("generic field: " + listType);
+
+ Method method;
+ try {
+ method = Main.class.getMethod("fancyMethod",
+ new Class[] { ArrayList.class });
+ } catch (NoSuchMethodException nsme) {
+ throw new RuntimeException(nsme);
+ }
+ Type[] parmTypes = method.getGenericParameterTypes();
+ Type ret = method.getGenericReturnType();
+ System.out.println("generic method " + method.getName() + " params='"
+ + stringifyTypeArray(parmTypes) + "' ret='" + ret + "'");
+
+ Constructor ctor;
+ try {
+ ctor = Main.class.getConstructor(new Class[] { ArrayList.class });
+ } catch (NoSuchMethodException nsme) {
+ throw new RuntimeException(nsme);
+ }
+ parmTypes = ctor.getGenericParameterTypes();
+ System.out.println("generic ctor " + ctor.getName() + " params='"
+ + stringifyTypeArray(parmTypes) + "'");
+ }
+
+ /*
+ * Convert an array of Type into a string. Start with an array count.
+ */
+ private static String stringifyTypeArray(Type[] types) {
+ StringBuilder stb = new StringBuilder();
+ boolean first = true;
+
+ stb.append("[" + types.length + "]");
+
+ for (Type t: types) {
+ if (first) {
+ stb.append(" ");
+ first = false;
+ } else {
+ stb.append(", ");
+ }
+ stb.append(t.toString());
+ }
+
+ return stb.toString();
}
+
public static void main(String[] args) {
Main test = new Main();
test.run();
+ checkAccess();
checkType();
checkInit();
+ checkGeneric();
}
}
diff --git a/tests/046-reflect/src/otherpackage/Other.java b/tests/046-reflect/src/otherpackage/Other.java
new file mode 100644
index 000000000..702ab6d68
--- /dev/null
+++ b/tests/046-reflect/src/otherpackage/Other.java
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2012 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 otherpackage;
+
+public class Other {
+ public void publicMethod() {
+ System.out.println("public method");
+ }
+ void packageMethod() {
+ System.out.println("package method");
+ }
+
+ public static InnerOther getInnerClassInstance() {
+ return new InnerOther();
+ }
+
+ private static class InnerOther {
+ public void innerMethod() {
+ System.out.println("inner method");
+ }
+
+ public int innerField = 7;
+ }
+}
diff --git a/tests/068-classloader/src/FancyLoader.java b/tests/068-classloader/src/FancyLoader.java
index 173b08f56..d04083afc 100644
--- a/tests/068-classloader/src/FancyLoader.java
+++ b/tests/068-classloader/src/FancyLoader.java
@@ -53,7 +53,7 @@ public class FancyLoader extends ClassLoader {
super(parent);
try {
- mDexClass = parent.loadClass("dalvik/system/DexFile");
+ mDexClass = parent.loadClass("dalvik.system.DexFile");
} catch (ClassNotFoundException cnfe) {
// ignore -- not running Dalvik
}
diff --git a/tests/086-null-super/src/Main.java b/tests/086-null-super/src/Main.java
index 6decb20cc..82237c523 100644
--- a/tests/086-null-super/src/Main.java
+++ b/tests/086-null-super/src/Main.java
@@ -76,7 +76,7 @@ public class Main {
* through reflection, then call loadCLass on it.
*/
Class mDexClass = ClassLoader.getSystemClassLoader().
- loadClass("dalvik/system/DexFile");
+ loadClass("dalvik.system.DexFile");
Constructor ctor = mDexClass.
getConstructor(new Class[] {String.class});
Object mDexFile = ctor.newInstance(DEX_FILE);
diff --git a/tests/087-gc-after-link/src/Main.java b/tests/087-gc-after-link/src/Main.java
index dc68f9f21..11fb2d316 100644
--- a/tests/087-gc-after-link/src/Main.java
+++ b/tests/087-gc-after-link/src/Main.java
@@ -79,7 +79,7 @@ public class Main {
* through reflection, then call loadClass on it.
*/
dexClass = ClassLoader.getSystemClassLoader().
- loadClass("dalvik/system/DexFile");
+ loadClass("dalvik.system.DexFile");
Constructor ctor = dexClass.
getConstructor(new Class[] {String.class});
dexFile = ctor.newInstance(DEX_FILE);
diff --git a/tests/092-locale/expected.txt b/tests/092-locale/expected.txt
new file mode 100644
index 000000000..3f5514c98
--- /dev/null
+++ b/tests/092-locale/expected.txt
@@ -0,0 +1,8 @@
+USA: Sunday, January 1, 2012
+USA: first=1, name=Sunday
+France: Monday, January 2, 2012
+France: first=2, name=lundi
+USA dfs: [AM, PM]
+en_US: USD $2
+jp_JP: JPY ¥0
+Normalizer passed
diff --git a/tests/092-locale/info.txt b/tests/092-locale/info.txt
new file mode 100644
index 000000000..e3c3a98a5
--- /dev/null
+++ b/tests/092-locale/info.txt
@@ -0,0 +1 @@
+Exercise some locale-specific classes.
diff --git a/tests/092-locale/src/Main.java b/tests/092-locale/src/Main.java
new file mode 100644
index 000000000..1303d3ceb
--- /dev/null
+++ b/tests/092-locale/src/Main.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+import java.text.DateFormat;
+import java.text.DateFormatSymbols;
+import java.text.Normalizer;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.Currency;
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+
+/**
+ * Exercise some locale-table-driven stuff.
+ */
+public class Main {
+
+ public static void main(String[] args) {
+ try {
+ testCalendar();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ try {
+ testDateFormatSymbols();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ try {
+ testCurrency();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ try {
+ testNormalizer();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ try {
+ testTimeZone();
+ } catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ static void testCalendar() {
+ TimeZone tz = TimeZone.getTimeZone("GMT");
+
+ Locale usa = new Locale("en", "US");
+ Calendar usaCal = Calendar.getInstance(tz, usa);
+ usaCal.set(2012, Calendar.JANUARY, 1);
+
+ Date when = usaCal.getTime();
+ DateFormat fmt = DateFormat.getDateInstance(DateFormat.FULL, usa);
+ System.out.println("USA: " + fmt.format(when));
+
+ System.out.println("USA: first="
+ + usaCal.getFirstDayOfWeek() + ", name="
+ + usaCal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, usa));
+
+
+ Locale france = new Locale("fr", "FR");
+ Calendar franceCal = Calendar.getInstance(tz, france);
+ franceCal.set(2012, Calendar.JANUARY, 2);
+
+ when = franceCal.getTime();
+ fmt = DateFormat.getDateInstance(DateFormat.FULL, usa);
+ System.out.println("France: " + fmt.format(when));
+
+ System.out.println("France: first="
+ + franceCal.getFirstDayOfWeek() + ", name="
+ + franceCal.getDisplayName(Calendar.DAY_OF_WEEK, Calendar.LONG, france));
+ }
+
+ static void testDateFormatSymbols() {
+ Locale usa = new Locale("en", "US");
+ DateFormatSymbols syms = DateFormatSymbols.getInstance(usa);
+ String[] list = syms.getAmPmStrings();
+ System.out.println("USA dfs: " + Arrays.deepToString(list));
+ }
+
+ static void testCurrency() {
+ Locale usa = new Locale("en", "US");
+ Currency dollars = Currency.getInstance(usa);
+
+ System.out.println(usa.toString() + ": " + dollars.toString()
+ + " " + dollars.getSymbol() + dollars.getDefaultFractionDigits());
+
+ Locale japan = new Locale("jp", "JP");
+ Currency yen = Currency.getInstance(japan);
+
+ System.out.println(japan.toString() + ": " + yen.toString()
+ + " " + yen.getSymbol() + yen.getDefaultFractionDigits());
+ }
+
+ static void testNormalizer() {
+ String composed = "Bl\u00c1ah";
+ String decomposed = "Bl\u0041\u0301ah";
+ String res;
+
+ res = Normalizer.normalize(composed, Normalizer.Form.NFD);
+ if (!decomposed.equals(res)) {
+ System.err.println("Bad decompose: '" + composed + "' --> '"
+ + res + "'");
+ }
+
+ res = Normalizer.normalize(decomposed, Normalizer.Form.NFC);
+ if (!composed.equals(res)) {
+ System.err.println("Bad compose: '" + decomposed + "' --> '"
+ + res + "'");
+ }
+
+ System.out.println("Normalizer passed");
+ }
+
+ static void testTimeZone() {
+ }
+}
diff --git a/tests/093-serialization/expected.txt b/tests/093-serialization/expected.txt
new file mode 100644
index 000000000..60c64f8e9
--- /dev/null
+++ b/tests/093-serialization/expected.txt
@@ -0,0 +1 @@
+one=true two=2 three=three four=4.0 five=5.0 six=6 seven=7 eight=8 nine=9 thing=X
diff --git a/tests/093-serialization/info.txt b/tests/093-serialization/info.txt
new file mode 100644
index 000000000..effe3d8bf
--- /dev/null
+++ b/tests/093-serialization/info.txt
@@ -0,0 +1 @@
+Tests object serialization.
diff --git a/tests/093-serialization/src/Main.java b/tests/093-serialization/src/Main.java
new file mode 100644
index 000000000..ca3dc9fd0
--- /dev/null
+++ b/tests/093-serialization/src/Main.java
@@ -0,0 +1,116 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.io.Serializable;
+
+/**
+ * Exercise serialization.
+ */
+public class Main {
+
+ public static void main(String[] args) {
+ testObjectSerialization();
+ }
+
+ static void testObjectSerialization() {
+ byte[] serialData;
+
+ try {
+ serialData = createStream();
+ checkStream(serialData);
+ } catch (IOException ioe) {
+ throw new RuntimeException(ioe);
+ }
+ }
+
+ static byte[] createStream() throws IOException {
+ ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
+ ObjectOutputStream objStream = new ObjectOutputStream(byteStream);
+
+ Sub sub = new Sub('X');
+ objStream.writeObject(sub);
+ byte[] bytes = byteStream.toByteArray();
+
+ objStream.close();
+ byteStream.close();
+ return bytes;
+ }
+
+ static void checkStream(byte[] input) throws IOException {
+ ByteArrayInputStream byteStream = new ByteArrayInputStream(input);
+ ObjectInputStream objStream = new ObjectInputStream(byteStream);
+
+ Sub sub;
+ try {
+ sub = (Sub) objStream.readObject();
+ } catch (ClassNotFoundException cnfe) {
+ throw new RuntimeException(cnfe);
+ }
+
+ objStream.close();
+ byteStream.close();
+
+ sub.check();
+ }
+}
+
+class Base implements Serializable {
+ private static final long serialVersionUID = 12345;
+
+ Boolean one;
+ Integer two;
+ String three;
+
+ public Base() {
+ one = true;
+ two = Integer.valueOf(2);
+ three = "three";
+ }
+}
+
+class Sub extends Base {
+ private static final long serialVersionUID = 54321;
+
+ Double four;
+ Float five;
+ private Byte six = 26;
+ Character seven = '7';
+ Short eight;
+ long nine;
+ public Character thing;
+
+ public Sub(char thing) {
+ four = 4.0;
+ five = 5.0f;
+ six = 6;
+ eight = 8;
+ nine = 9;
+ this.thing = thing;
+ }
+
+ public void check() {
+ System.out.println("one=" + one + " two=" + two + " three=" + three
+ + " four=" + four + " five=" + five + " six=" + six
+ + " seven=" + seven + " eight=" + eight + " nine=" + nine
+ + " thing=" + thing);
+ }
+}
+
diff --git a/tests/094-pattern/expected.txt b/tests/094-pattern/expected.txt
new file mode 100644
index 000000000..4af0c66dd
--- /dev/null
+++ b/tests/094-pattern/expected.txt
@@ -0,0 +1,3 @@
+str1 matches: true
+str2 matches: false
+str3 matches: true
diff --git a/tests/094-pattern/info.txt b/tests/094-pattern/info.txt
new file mode 100644
index 000000000..c1ade3336
--- /dev/null
+++ b/tests/094-pattern/info.txt
@@ -0,0 +1,4 @@
+A simple test to exercise pattern matching.
+
+The test may throw a StackOverflowError if the stack size is too small. With
+some regex libs, -Xss65k is the minimum allowable size.
diff --git a/tests/094-pattern/src/Main.java b/tests/094-pattern/src/Main.java
new file mode 100644
index 000000000..4d7e1a316
--- /dev/null
+++ b/tests/094-pattern/src/Main.java
@@ -0,0 +1,95 @@
+/*
+ * Copyright (C) 2012 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.
+ */
+
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class Main {
+ // from android.util.Patterns
+ public static final String GOOD_IRI_CHAR =
+ "a-zA-Z0-9\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF";
+
+ public static final String TOP_LEVEL_DOMAIN_STR_FOR_WEB_URL =
+ "(?:"
+ + "(?:aero|arpa|asia|a[cdefgilmnoqrstuwxz])"
+ + "|(?:biz|b[abdefghijmnorstvwyz])"
+ + "|(?:cat|com|coop|c[acdfghiklmnoruvxyz])"
+ + "|d[ejkmoz]"
+ + "|(?:edu|e[cegrstu])"
+ + "|f[ijkmor]"
+ + "|(?:gov|g[abdefghilmnpqrstuwy])"
+ + "|h[kmnrtu]"
+ + "|(?:info|int|i[delmnoqrst])"
+ + "|(?:jobs|j[emop])"
+ + "|k[eghimnprwyz]"
+ + "|l[abcikrstuvy]"
+ + "|(?:mil|mobi|museum|m[acdeghklmnopqrstuvwxyz])"
+ + "|(?:name|net|n[acefgilopruz])"
+ + "|(?:org|om)"
+ + "|(?:pro|p[aefghklmnrstwy])"
+ + "|qa"
+ + "|r[eosuw]"
+ + "|s[abcdeghijklmnortuvyz]"
+ + "|(?:tel|travel|t[cdfghjklmnoprtvwz])"
+ + "|u[agksyz]"
+ + "|v[aceginu]"
+ + "|w[fs]"
+ + "|(?:\u03b4\u03bf\u03ba\u03b9\u03bc\u03ae|\u0438\u0441\u043f\u044b\u0442\u0430\u043d\u0438\u0435|\u0440\u0444|\u0441\u0440\u0431|\u05d8\u05e2\u05e1\u05d8|\u0622\u0632\u0645\u0627\u06cc\u0634\u06cc|\u0625\u062e\u062a\u0628\u0627\u0631|\u0627\u0644\u0627\u0631\u062f\u0646|\u0627\u0644\u062c\u0632\u0627\u0626\u0631|\u0627\u0644\u0633\u0639\u0648\u062f\u064a\u0629|\u0627\u0644\u0645\u063a\u0631\u0628|\u0627\u0645\u0627\u0631\u0627\u062a|\u0628\u06be\u0627\u0631\u062a|\u062a\u0648\u0646\u0633|\u0633\u0648\u0631\u064a\u0629|\u0641\u0644\u0633\u0637\u064a\u0646|\u0642\u0637\u0631|\u0645\u0635\u0631|\u092a\u0930\u0940\u0915\u094d\u0937\u093e|\u092d\u093e\u0930\u0924|\u09ad\u09be\u09b0\u09a4|\u0a2d\u0a3e\u0a30\u0a24|\u0aad\u0abe\u0ab0\u0aa4|\u0b87\u0ba8\u0bcd\u0ba4\u0bbf\u0baf\u0bbe|\u0b87\u0bb2\u0b99\u0bcd\u0b95\u0bc8|\u0b9a\u0bbf\u0b99\u0bcd\u0b95\u0baa\u0bcd\u0baa\u0bc2\u0bb0\u0bcd|\u0baa\u0bb0\u0bbf\u0b9f\u0bcd\u0b9a\u0bc8|\u0c2d\u0c3e\u0c30\u0c24\u0c4d|\u0dbd\u0d82\u0d9a\u0dcf|\u0e44\u0e17\u0e22|\u30c6\u30b9\u30c8|\u4e2d\u56fd|\u4e2d\u570b|\u53f0\u6e7e|\u53f0\u7063|\u65b0\u52a0\u5761|\u6d4b\u8bd5|\u6e2c\u8a66|\u9999\u6e2f|\ud14c\uc2a4\ud2b8|\ud55c\uad6d|xn\\-\\-0zwm56d|xn\\-\\-11b5bs3a9aj6g|xn\\-\\-3e0b707e|xn\\-\\-45brj9c|xn\\-\\-80akhbyknj4f|xn\\-\\-90a3ac|xn\\-\\-9t4b11yi5a|xn\\-\\-clchc0ea0b2g2a9gcd|xn\\-\\-deba0ad|xn\\-\\-fiqs8s|xn\\-\\-fiqz9s|xn\\-\\-fpcrj9c3d|xn\\-\\-fzc2c9e2c|xn\\-\\-g6w251d|xn\\-\\-gecrj9c|xn\\-\\-h2brj9c|xn\\-\\-hgbk6aj7f53bba|xn\\-\\-hlcj6aya9esc7a|xn\\-\\-j6w193g|xn\\-\\-jxalpdlp|xn\\-\\-kgbechtv|xn\\-\\-kprw13d|xn\\-\\-kpry57d|xn\\-\\-lgbbat1ad8j|xn\\-\\-mgbaam7a8h|xn\\-\\-mgbayh7gpa|xn\\-\\-mgbbh1a71e|xn\\-\\-mgbc0a9azcg|xn\\-\\-mgberp4a5d4ar|xn\\-\\-o3cw4h|xn\\-\\-ogbpf8fl|xn\\-\\-p1ai|xn\\-\\-pgbs0dh|xn\\-\\-s9brj9c|xn\\-\\-wgbh1c|xn\\-\\-wgbl6a|xn\\-\\-xkc2al3hye2a|xn\\-\\-xkc2dl3a5ee0h|xn\\-\\-yfro4i67o|xn\\-\\-ygbi2ammx|xn\\-\\-zckzah|xxx)"
+ + "|y[et]"
+ + "|z[amw]))";
+
+ public static final String WEB_URL_STR =
+ "((?:(http|https|Http|Https|rtsp|Rtsp):\\/\\/(?:(?:[a-zA-Z0-9\\$\\-\\_\\.\\+\\!\\*\\'\\(\\)"
+ + "\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,64}(?:\\:(?:[a-zA-Z0-9\\$\\-\\_"
+ + "\\.\\+\\!\\*\\'\\(\\)\\,\\;\\?\\&\\=]|(?:\\%[a-fA-F0-9]{2})){1,25})?\\@)?)?"
+ + "((?:(?:[" + GOOD_IRI_CHAR + "][" + GOOD_IRI_CHAR + "\\-]{0,64}\\.)+" // named host
+ + TOP_LEVEL_DOMAIN_STR_FOR_WEB_URL
+ + "|(?:(?:25[0-5]|2[0-4]" // or ip address
+ + "[0-9]|[0-1][0-9]{2}|[1-9][0-9]|[1-9])\\.(?:25[0-5]|2[0-4][0-9]"
+ + "|[0-1][0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1]"
+ + "[0-9]{2}|[1-9][0-9]|[1-9]|0)\\.(?:25[0-5]|2[0-4][0-9]|[0-1][0-9]{2}"
+ + "|[1-9][0-9]|[0-9])))"
+ + "(?:\\:\\d{1,5})?)" // plus option port number
+ + "(\\/(?:(?:[" + GOOD_IRI_CHAR + "\\;\\/\\?\\:\\@\\&\\=\\#\\~" // plus option query params
+ + "\\-\\.\\+\\!\\*\\'\\(\\)\\,\\_])|(?:\\%[a-fA-F0-9]{2}))*)?"
+ + "(?:\\b|$)"; // and finally, a word boundary or end of
+ // input. This is to stop foo.sure from
+ // matching as foo.su
+
+ public static final Pattern WEB_URL = Pattern.compile(WEB_URL_STR);
+
+ public static final String testStr1 =
+ "http://www.google.com/blah?client=tablet-android&source=android-home";
+ public static final String testStr2 = "http:///www.google.com/";
+ public static final String testStr3 =
+ "http://www.google.com/search?hl=en&redir_esc=&client=tablet-android-verizon&source=android-browser-type&v=141000000&qsubts=1327020479959&action=devloc&q=cnn";
+
+ public static void main(String[] args) {
+ System.out.println("str1 matches: " + WEB_URL.matcher(testStr1).matches());
+ System.out.println("str2 matches: " + WEB_URL.matcher(testStr2).matches());
+ System.out.println("str3 matches: " + WEB_URL.matcher(testStr3).matches());
+ }
+
+ static String getStringAsHex(String text) {
+ StringBuilder sb = new StringBuilder(text.length() * 4);
+
+ for (int i = 0; i < text.length(); i++) {
+ sb.append(Integer.toHexString((int) text.charAt(i)));
+ }
+
+ return sb.toString();
+ }
+}