Track libcore tests moving from frameworks/base to libcore.

Bug: http://b/3073226
Change-Id: I07076e6ed74fcae5482dff477ed102c770c197c9
This commit is contained in:
Jesse Wilson
2011-12-13 13:35:04 -05:00
parent 5aa2136ddf
commit 0102c21f6b
5 changed files with 2 additions and 1365 deletions

View File

@@ -1,48 +0,0 @@
/*
* Copyright (C) 2008 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 android.core;
import junit.framework.TestCase;
import java.io.CharArrayWriter;
import android.test.suitebuilder.annotation.SmallTest;
/**
* Basic tests for CharArrayWriter.
*/
public class CharArrayWriterTest extends TestCase {
@SmallTest
public void testCharArrayWriter() throws Exception {
String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
CharArrayWriter a = new CharArrayWriter();
CharArrayWriter b = new CharArrayWriter();
a.write(str, 0, 26);
a.write('X');
a.writeTo(b);
assertEquals(27, a.size());
assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzX", a.toString());
b.write("alphabravodelta", 5, 5);
b.append('X');
assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoX", b.toString());
b.append("omega");
assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzXbravoXomega", b.toString());
}
}

View File

@@ -1,243 +0,0 @@
/*
* Copyright (C) 2008 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 android.core;
import junit.framework.TestCase;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import android.test.suitebuilder.annotation.Suppress;
/**
* Test for basic ClassLoader functionality.
*/
@Suppress
public class ClassLoaderTest extends TestCase {
/*
package my.pkg;
public class CLTest {
public CLTest() {}
public String test() { return "This is test 1"; }
}
*/
static private byte[] test1class = {
(byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x31,
(byte) 0x00, (byte) 0x11, (byte) 0x0a, (byte) 0x00,
(byte) 0x04, (byte) 0x00, (byte) 0x0d, (byte) 0x08,
(byte) 0x00, (byte) 0x0e, (byte) 0x07, (byte) 0x00,
(byte) 0x0f, (byte) 0x07, (byte) 0x00, (byte) 0x10,
(byte) 0x01, (byte) 0x00, (byte) 0x06, (byte) 0x3c,
(byte) 0x69, (byte) 0x6e, (byte) 0x69, (byte) 0x74,
(byte) 0x3e, (byte) 0x01, (byte) 0x00, (byte) 0x03,
(byte) 0x28, (byte) 0x29, (byte) 0x56, (byte) 0x01,
(byte) 0x00, (byte) 0x04, (byte) 0x43, (byte) 0x6f,
(byte) 0x64, (byte) 0x65, (byte) 0x01, (byte) 0x00,
(byte) 0x0f, (byte) 0x4c, (byte) 0x69, (byte) 0x6e,
(byte) 0x65, (byte) 0x4e, (byte) 0x75, (byte) 0x6d,
(byte) 0x62, (byte) 0x65, (byte) 0x72, (byte) 0x54,
(byte) 0x61, (byte) 0x62, (byte) 0x6c, (byte) 0x65,
(byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x74,
(byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x01,
(byte) 0x00, (byte) 0x14, (byte) 0x28, (byte) 0x29,
(byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76,
(byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61,
(byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x53,
(byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e,
(byte) 0x67, (byte) 0x3b, (byte) 0x01, (byte) 0x00,
(byte) 0x0a, (byte) 0x53, (byte) 0x6f, (byte) 0x75,
(byte) 0x72, (byte) 0x63, (byte) 0x65, (byte) 0x46,
(byte) 0x69, (byte) 0x6c, (byte) 0x65, (byte) 0x01,
(byte) 0x00, (byte) 0x0b, (byte) 0x43, (byte) 0x4c,
(byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74,
(byte) 0x2e, (byte) 0x6a, (byte) 0x61, (byte) 0x76,
(byte) 0x61, (byte) 0x0c, (byte) 0x00, (byte) 0x05,
(byte) 0x00, (byte) 0x06, (byte) 0x01, (byte) 0x00,
(byte) 0x0e, (byte) 0x54, (byte) 0x68, (byte) 0x69,
(byte) 0x73, (byte) 0x20, (byte) 0x69, (byte) 0x73,
(byte) 0x20, (byte) 0x74, (byte) 0x65, (byte) 0x73,
(byte) 0x74, (byte) 0x20, (byte) 0x31, (byte) 0x01,
(byte) 0x00, (byte) 0x0d, (byte) 0x6d, (byte) 0x79,
(byte) 0x2f, (byte) 0x70, (byte) 0x6b, (byte) 0x67,
(byte) 0x2f, (byte) 0x43, (byte) 0x4c, (byte) 0x54,
(byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x01,
(byte) 0x00, (byte) 0x10, (byte) 0x6a, (byte) 0x61,
(byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c,
(byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f,
(byte) 0x4f, (byte) 0x62, (byte) 0x6a, (byte) 0x65,
(byte) 0x63, (byte) 0x74, (byte) 0x00, (byte) 0x21,
(byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x04,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x01,
(byte) 0x00, (byte) 0x05, (byte) 0x00, (byte) 0x06,
(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x07,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1d,
(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05,
(byte) 0x2a, (byte) 0xb7, (byte) 0x00, (byte) 0x01,
(byte) 0xb1, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x01, (byte) 0x00, (byte) 0x08, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x06, (byte) 0x00,
(byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x00,
(byte) 0x09, (byte) 0x00, (byte) 0x0a, (byte) 0x00,
(byte) 0x01, (byte) 0x00, (byte) 0x07, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x1b, (byte) 0x00,
(byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x12,
(byte) 0x02, (byte) 0xb0, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x08,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x06,
(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x01,
(byte) 0x00, (byte) 0x0b, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x0c
};
/*
package my.pkg;
public class CLTest {
public CLTest() {}
public String test() { return "This is test 2"; }
}
*/
static private byte[] test2class = {
(byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x31,
(byte) 0x00, (byte) 0x11, (byte) 0x0a, (byte) 0x00,
(byte) 0x04, (byte) 0x00, (byte) 0x0d, (byte) 0x08,
(byte) 0x00, (byte) 0x0e, (byte) 0x07, (byte) 0x00,
(byte) 0x0f, (byte) 0x07, (byte) 0x00, (byte) 0x10,
(byte) 0x01, (byte) 0x00, (byte) 0x06, (byte) 0x3c,
(byte) 0x69, (byte) 0x6e, (byte) 0x69, (byte) 0x74,
(byte) 0x3e, (byte) 0x01, (byte) 0x00, (byte) 0x03,
(byte) 0x28, (byte) 0x29, (byte) 0x56, (byte) 0x01,
(byte) 0x00, (byte) 0x04, (byte) 0x43, (byte) 0x6f,
(byte) 0x64, (byte) 0x65, (byte) 0x01, (byte) 0x00,
(byte) 0x0f, (byte) 0x4c, (byte) 0x69, (byte) 0x6e,
(byte) 0x65, (byte) 0x4e, (byte) 0x75, (byte) 0x6d,
(byte) 0x62, (byte) 0x65, (byte) 0x72, (byte) 0x54,
(byte) 0x61, (byte) 0x62, (byte) 0x6c, (byte) 0x65,
(byte) 0x01, (byte) 0x00, (byte) 0x04, (byte) 0x74,
(byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x01,
(byte) 0x00, (byte) 0x14, (byte) 0x28, (byte) 0x29,
(byte) 0x4c, (byte) 0x6a, (byte) 0x61, (byte) 0x76,
(byte) 0x61, (byte) 0x2f, (byte) 0x6c, (byte) 0x61,
(byte) 0x6e, (byte) 0x67, (byte) 0x2f, (byte) 0x53,
(byte) 0x74, (byte) 0x72, (byte) 0x69, (byte) 0x6e,
(byte) 0x67, (byte) 0x3b, (byte) 0x01, (byte) 0x00,
(byte) 0x0a, (byte) 0x53, (byte) 0x6f, (byte) 0x75,
(byte) 0x72, (byte) 0x63, (byte) 0x65, (byte) 0x46,
(byte) 0x69, (byte) 0x6c, (byte) 0x65, (byte) 0x01,
(byte) 0x00, (byte) 0x0b, (byte) 0x43, (byte) 0x4c,
(byte) 0x54, (byte) 0x65, (byte) 0x73, (byte) 0x74,
(byte) 0x2e, (byte) 0x6a, (byte) 0x61, (byte) 0x76,
(byte) 0x61, (byte) 0x0c, (byte) 0x00, (byte) 0x05,
(byte) 0x00, (byte) 0x06, (byte) 0x01, (byte) 0x00,
(byte) 0x0e, (byte) 0x54, (byte) 0x68, (byte) 0x69,
(byte) 0x73, (byte) 0x20, (byte) 0x69, (byte) 0x73,
(byte) 0x20, (byte) 0x74, (byte) 0x65, (byte) 0x73,
(byte) 0x74, (byte) 0x20, (byte) 0x32, (byte) 0x01,
(byte) 0x00, (byte) 0x0d, (byte) 0x6d, (byte) 0x79,
(byte) 0x2f, (byte) 0x70, (byte) 0x6b, (byte) 0x67,
(byte) 0x2f, (byte) 0x43, (byte) 0x4c, (byte) 0x54,
(byte) 0x65, (byte) 0x73, (byte) 0x74, (byte) 0x01,
(byte) 0x00, (byte) 0x10, (byte) 0x6a, (byte) 0x61,
(byte) 0x76, (byte) 0x61, (byte) 0x2f, (byte) 0x6c,
(byte) 0x61, (byte) 0x6e, (byte) 0x67, (byte) 0x2f,
(byte) 0x4f, (byte) 0x62, (byte) 0x6a, (byte) 0x65,
(byte) 0x63, (byte) 0x74, (byte) 0x00, (byte) 0x21,
(byte) 0x00, (byte) 0x03, (byte) 0x00, (byte) 0x04,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x01,
(byte) 0x00, (byte) 0x05, (byte) 0x00, (byte) 0x06,
(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x07,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x1d,
(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x01,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x05,
(byte) 0x2a, (byte) 0xb7, (byte) 0x00, (byte) 0x01,
(byte) 0xb1, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x01, (byte) 0x00, (byte) 0x08, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x06, (byte) 0x00,
(byte) 0x01, (byte) 0x00, (byte) 0x00, (byte) 0x00,
(byte) 0x04, (byte) 0x00, (byte) 0x01, (byte) 0x00,
(byte) 0x09, (byte) 0x00, (byte) 0x0a, (byte) 0x00,
(byte) 0x01, (byte) 0x00, (byte) 0x07, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x1b, (byte) 0x00,
(byte) 0x01, (byte) 0x00, (byte) 0x01, (byte) 0x00,
(byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0x12,
(byte) 0x02, (byte) 0xb0, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x08,
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x06,
(byte) 0x00, (byte) 0x01, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x06, (byte) 0x00, (byte) 0x01,
(byte) 0x00, (byte) 0x0b, (byte) 0x00, (byte) 0x00,
(byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0x0c
};
/*
* Custom class loader.
*/
private class MyLoader extends ClassLoader {
public MyLoader(byte[] data) {
super();
mData = data;
}
protected Class<?> findClass(String name) throws ClassNotFoundException {
assertEquals("my.pkg.CLTest", name);
return defineClass(name, mData, 0, mData.length);
}
byte[] mData;
}
/*
* Simple test: manually load two class files that have the same class
* name but different contents.
*/
public void testClassLoader() throws Exception {
Class test1, test2;
MyLoader loader1 = new MyLoader(test1class);
MyLoader loader2 = new MyLoader(test2class);
test1 = loader1.loadClass("my.pkg.CLTest");
test2 = loader2.loadClass("my.pkg.CLTest");
methodTest(test1, "This is test 1");
methodTest(test2, "This is test 2");
}
/*
* Invoke the test() method and verify that the string returned
* matches what we expect.
*/
private static void methodTest(Class clazz, String expect)
throws NoSuchMethodException, InstantiationException,
IllegalAccessException, InvocationTargetException {
Method meth = clazz.getMethod("test", (Class[]) null);
Object obj = clazz.newInstance();
Object result = meth.invoke(obj, (Object[]) null);
assertEquals(result, expect);
}
}

View File

@@ -1,337 +0,0 @@
/*
* Copyright (C) 2008 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 android.core;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.widget.Button;
import junit.framework.TestCase;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.HashSet;
import java.util.Set;
class ClassWithPrivateConstructor {
private ClassWithPrivateConstructor() {
}
}
public class ClassTest extends TestCase {
@SmallTest
public void testClass() throws Exception {
// Now, never mind the fact that most of this stuff has to work
// for the test harness to get this far....
//System.out.println("Class.forName()");
Class helloClass = Class.forName(ClassTest.class.getName());
//System.out.println("Class.newInstance()");
Object instance = helloClass.newInstance();
assertNotNull(instance);
//System.out.println("Class.forName() nonexisting class");
try {
Class.forName("this.class.DoesNotExist");
fail("unexpected success");
} catch (ClassNotFoundException ex) {
// expected
}
//System.out.println("Class.newInstance() private constructor");
try {
Class.forName("android.core.ClassWithPrivateConstructor").newInstance();
fail("unexpected success");
} catch (IllegalAccessException ex) {
// this is expected
}
//System.out.println("Class.getDeclaredMethod()");
Method method = helloClass.getDeclaredMethod("method", (Class[]) null);
method.invoke(new ClassTest(), (Object[]) null);
//System.out.println("Class.getDeclaredMethod() w/ args");
method = helloClass.getDeclaredMethod("methodWithArgs", Object.class);
Object invokeArgs[] = new Object[1];
invokeArgs[0] = "Hello";
Object ret = method.invoke(new ClassTest(), invokeArgs);
assertEquals(ret, invokeArgs[0]);
//System.out.println("Class.getDeclaredMethod() -- private");
method = helloClass.getDeclaredMethod("privateMethod", (Class[]) null);
method.invoke(new ClassTest(), (Object[]) null);
//fail("unexpected success");
// TODO: I think this actually *should* succeed, because the
// call to the private method is being made from the same class.
// This needs to be replaced with a private call to a different
// class.
//System.out.println("Class.getSuperclass");
Class objectClass = Class.forName("java.lang.Object");
assertEquals(helloClass.getSuperclass().getSuperclass().getSuperclass(), objectClass);
//System.out.println("Class.isAssignableFrom");
assertTrue(objectClass.isAssignableFrom(helloClass));
assertFalse(helloClass.isAssignableFrom(objectClass));
//System.out.println("Class.getConstructor");
Constructor constructor = helloClass.getConstructor((Class[]) null);
assertNotNull(constructor);
//System.out.println("Class.getModifiers");
assertTrue(Modifier.isPublic(helloClass.getModifiers()));
//System.out.println("Modifiers: " + Modifier.toString(helloClass.getModifiers()));
//System.out.println("Class.getMethod");
helloClass.getMethod("method", (Class[]) null);
try {
Class[] argTypes = new Class[1];
argTypes[0] = helloClass;
helloClass.getMethod("method", argTypes);
fail("unexpected success");
} catch (NoSuchMethodException ex) {
// exception expected
}
// Test for public tracker issue 14
SimpleClass obj = new SimpleClass();
Field field = obj.getClass().getDeclaredField("str");
field.set(obj, null);
}
public class SimpleClass {
public String str;
}
public Object methodWithArgs(Object o) {
return o;
}
boolean methodInvoked;
public void method() {
methodInvoked = true;
}
boolean privateMethodInvoked;
public void privateMethod() {
privateMethodInvoked = true;
}
// Regression for 1018067: Class.getMethods() returns the same method over
// and over again from all base classes
@MediumTest
public void testClassGetMethodsNoDupes() {
Method[] methods = Button.class.getMethods();
Set<String> set = new HashSet<String>();
for (int i = 0; i < methods.length; i++) {
String signature = methods[i].toString();
int par = signature.indexOf('(');
int dot = signature.lastIndexOf('.', par);
signature = signature.substring(dot + 1);
assertFalse("Duplicate " + signature, set.contains(signature));
set.add(signature);
}
}
interface MyInterface {
void foo();
}
interface MyOtherInterface extends MyInterface {
void bar();
}
abstract class MyClass implements MyOtherInterface {
public void gabba() {
}
public void hey() {
}
}
// Check if we also reflect methods from interfaces
@SmallTest
public void testGetMethodsInterfaces() {
Method[] methods = MyInterface.class.getMethods();
assertTrue("Interface method must be there", hasMethod(methods, ".foo("));
methods = MyOtherInterface.class.getMethods();
assertTrue("Interface method must be there", hasMethod(methods, ".foo("));
assertTrue("Interface method must be there", hasMethod(methods, ".bar("));
methods = MyClass.class.getMethods();
assertTrue("Interface method must be there", hasMethod(methods, ".foo("));
assertTrue("Interface method must be there", hasMethod(methods, ".bar("));
assertTrue("Declared method must be there", hasMethod(methods, ".gabba("));
assertTrue("Declared method must be there", hasMethod(methods, ".hey("));
assertTrue("Inherited method must be there", hasMethod(methods, ".toString("));
}
private boolean hasMethod(Method[] methods, String signature) {
for (int i = 0; i < methods.length; i++) {
if (methods[i].toString().contains(signature)) {
return true;
}
}
return false;
}
// Test for Class.getPackage();
@SmallTest
public void testClassGetPackage() {
assertNotNull("Package must be non-null", getClass().getPackage());
assertEquals("Package must have expected name", "android.core", getClass().getPackage().getName());
assertEquals("Package must have expected title", "Unknown", getClass().getPackage().getSpecificationTitle());
Package p = java.lang.Object.class.getPackage();
assertNotNull("Package must be non-null", p);
assertEquals("Package must have expected name", "java.lang", p.getName());
assertSame("Package object must be same for each call", p, java.lang.Object.class.getPackage());
}
// Regression test for #1123708: Problem with getCanonicalName(),
// getSimpleName(), and getPackage().
//
// A couple of interesting cases need to be checked: Top-level classes,
// member classes, local classes, and anonymous classes. Also, boundary
// cases with '$' in the class names are checked, since the '$' is used
// as the separator between outer and inner class, so this might lead
// to problems (it did in the previous implementation).
//
// Caution: Adding local or anonymous classes elsewhere in this
// file might affect the test.
private class MemberClass {
// This space intentionally left blank.
}
private class Mi$o$oup {
// This space intentionally left blank.
}
@SmallTest
public void testVariousClassNames() {
Class<?> clazz = this.getClass();
String pkg = (clazz.getPackage() == null ? "" : clazz.getPackage().getName() + ".");
// Simple, top-level class
assertEquals("Top-level class name must be correct", pkg + "ClassTest", clazz.getName());
assertEquals("Top-level class simple name must be correct", "ClassTest", clazz.getSimpleName());
assertEquals("Top-level class canonical name must be correct", pkg + "ClassTest", clazz.getCanonicalName());
clazz = MemberClass.class;
assertEquals("Member class name must be correct", pkg + "ClassTest$MemberClass", clazz.getName());
assertEquals("Member class simple name must be correct", "MemberClass", clazz.getSimpleName());
assertEquals("Member class canonical name must be correct", pkg + "ClassTest.MemberClass", clazz.getCanonicalName());
class LocalClass {
// This space intentionally left blank.
}
clazz = LocalClass.class;
assertEquals("Local class name must be correct", pkg + "ClassTest$1LocalClass", clazz.getName());
assertEquals("Local class simple name must be correct", "LocalClass", clazz.getSimpleName());
assertNull("Local class canonical name must be null", clazz.getCanonicalName());
clazz = new Object() { }.getClass();
assertEquals("Anonymous class name must be correct", pkg + "ClassTest$1", clazz.getName());
assertEquals("Anonymous class simple name must be empty", "", clazz.getSimpleName());
assertNull("Anonymous class canonical name must be null", clazz.getCanonicalName());
// Weird special cases with dollar in name.
clazz = Mou$$aka.class;
assertEquals("Top-level class name must be correct", pkg + "Mou$$aka", clazz.getName());
assertEquals("Top-level class simple name must be correct", "Mou$$aka", clazz.getSimpleName());
assertEquals("Top-level class canonical name must be correct", pkg + "Mou$$aka", clazz.getCanonicalName());
clazz = Mi$o$oup.class;
assertEquals("Member class name must be correct", pkg + "ClassTest$Mi$o$oup", clazz.getName());
assertEquals("Member class simple name must be correct", "Mi$o$oup", clazz.getSimpleName());
assertEquals("Member class canonical name must be correct", pkg + "ClassTest.Mi$o$oup", clazz.getCanonicalName());
class Ma$hedPotatoe$ {
// This space intentionally left blank.
}
clazz = Ma$hedPotatoe$.class;
assertEquals("Member class name must be correct", pkg + "ClassTest$1Ma$hedPotatoe$", clazz.getName());
assertEquals("Member class simple name must be correct", "Ma$hedPotatoe$", clazz.getSimpleName());
assertNull("Member class canonical name must be null", clazz.getCanonicalName());
}
@SmallTest
public void testLocalMemberClass() {
Class<?> clazz = this.getClass();
assertFalse("Class must not be member", clazz.isMemberClass());
assertFalse("Class must not be local", clazz.isLocalClass());
clazz = MemberClass.class;
assertTrue("Class must be member", clazz.isMemberClass());
assertFalse("Class must not be local", clazz.isLocalClass());
class OtherLocalClass {
// This space intentionally left blank.
}
clazz = OtherLocalClass.class;
assertFalse("Class must not be member", clazz.isMemberClass());
assertTrue("Class must be local", clazz.isLocalClass());
clazz = new Object() { }.getClass();
assertFalse("Class must not be member", clazz.isMemberClass());
assertFalse("Class must not be local", clazz.isLocalClass());
}
}
class Mou$$aka {
// This space intentionally left blank.
}

View File

@@ -16,56 +16,12 @@
package android.core;
import junit.framework.Assert;
import android.test.suitebuilder.annotation.MediumTest;
import java.util.logging.Logger;
import junit.framework.TestCase;
import java.io.File;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.util.Arrays;
import java.util.ConcurrentModificationException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Random;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.logging.Logger;
import java.util.zip.Deflater;
import java.util.zip.Inflater;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
import android.test.suitebuilder.annotation.LargeTest;
public class MiscRegressionTest extends TestCase {
// Regression test for #857840: want JKS key store
@SmallTest
public void testDefaultKeystore() {
String type = KeyStore.getDefaultType();
Assert.assertEquals("Default keystore type must be Bouncy Castle", "BKS", type);
try {
KeyStore store = KeyStore.getInstance(KeyStore.getDefaultType());
Assert.assertNotNull("Keystore must not be null", store);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
try {
KeyStore store = KeyStore.getInstance("BKS");
Assert.assertNotNull("Keystore must not be null", store);
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
// Regression test for #951285: Suitable LogHandler should be chosen
// depending on the environment.
@MediumTest
@@ -78,408 +34,4 @@ public class MiscRegressionTest extends TestCase {
Logger.global.finer("This has logging Level.FINER, should become VERBOSE");
Logger.global.finest("This has logging Level.FINEST, should become VERBOSE");
}
// Regression test for Issue 5697:
// getContextClassLoader returns a non-application classloader
// http://code.google.com/p/android/issues/detail?id=5697
//
@MediumTest
public void testJavaContextClassLoader() throws Exception {
Assert.assertNotNull("Must hava a Java context ClassLoader",
Thread.currentThread().getContextClassLoader());
}
// Regression test for #1045939: Different output for Method.toString()
@SmallTest
public void testMethodToString() {
try {
Method m1 = Object.class.getMethod("notify", new Class[] { });
Method m2 = Object.class.getMethod("toString", new Class[] { });
Method m3 = Object.class.getMethod("wait", new Class[] { long.class, int.class });
Method m4 = Object.class.getMethod("equals", new Class[] { Object.class });
Method m5 = String.class.getMethod("valueOf", new Class[] { char[].class });
Method m6 = Runtime.class.getMethod("exec", new Class[] { String[].class });
assertEquals("Method.toString() must match expectations",
"public final native void java.lang.Object.notify()",
m1.toString());
assertEquals("Method.toString() must match expectations",
"public java.lang.String java.lang.Object.toString()",
m2.toString());
assertEquals("Method.toString() must match expectations",
"public final native void java.lang.Object.wait(long,int) throws java.lang.InterruptedException",
m3.toString());
assertEquals("Method.toString() must match expectations",
"public boolean java.lang.Object.equals(java.lang.Object)",
m4.toString());
assertEquals("Method.toString() must match expectations",
"public static java.lang.String java.lang.String.valueOf(char[])",
m5.toString());
assertEquals("Method.toString() must match expectations",
"public java.lang.Process java.lang.Runtime.exec(java.lang.String[]) throws java.io.IOException",
m6.toString());
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
// Regression test for #1062200: Enum fails to deserialize. Actual problem
// was that Class.isEnum() erroneously returned true for indirect
// descendants of Enum.
enum TrafficLights {
RED,
YELLOW {},
GREEN {
@SuppressWarnings("unused")
int i;
@SuppressWarnings("unused")
void foobar() {}
};
}
@SmallTest
public void testClassIsEnum() {
Class<?> trafficClass = TrafficLights.class;
Class<?> redClass = TrafficLights.RED.getClass();
Class<?> yellowClass = TrafficLights.YELLOW.getClass();
Class<?> greenClass = TrafficLights.GREEN.getClass();
Assert.assertSame("Classes must be equal", trafficClass, redClass);
Assert.assertNotSame("Classes must be different", trafficClass, yellowClass);
Assert.assertNotSame("Classes must be different", trafficClass, greenClass);
Assert.assertNotSame("Classes must be different", yellowClass, greenClass);
Assert.assertTrue("Must be an enum", trafficClass.isEnum());
Assert.assertTrue("Must be an enum", redClass.isEnum());
Assert.assertFalse("Must not be an enum", yellowClass.isEnum());
Assert.assertFalse("Must not be an enum", greenClass.isEnum());
Assert.assertNotNull("Must have enum constants", trafficClass.getEnumConstants());
Assert.assertNull("Must not have enum constants", yellowClass.getEnumConstants());
Assert.assertNull("Must not have enum constants", greenClass.getEnumConstants());
}
// Regression test for #1046174: JarEntry.getCertificates() is really slow.
public void checkJarCertificates(File file) {
try {
JarFile jarFile = new JarFile(file);
JarEntry je = jarFile.getJarEntry("AndroidManifest.xml");
byte[] readBuffer = new byte[1024];
long t0 = System.currentTimeMillis();
// We must read the stream for the JarEntry to retrieve
// its certificates.
InputStream is = jarFile.getInputStream(je);
while (is.read(readBuffer, 0, readBuffer.length) != -1) {
// not using
}
is.close();
Certificate[] certs = je != null ? je.getCertificates() : null;
long t1 = System.currentTimeMillis();
android.util.Log.d("TestHarness", "loadCertificates() took " + (t1 - t0) + " ms");
if (certs == null) {
android.util.Log.d("TestHarness", "We have no certificates");
} else {
android.util.Log.d("TestHarness", "We have " + certs.length + " certificates");
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
@LargeTest
public void testJarCertificates() {
File[] files = new File("/system/app").listFiles();
for (int i = 0; i < files.length; i++) {
checkJarCertificates(files[i]);
}
}
// Regression test for #1120750: Reflection for static long fields is broken
private static final long MY_LONG = 5073258162644648461L;
@SmallTest
public void testLongFieldReflection() {
try {
Field field = getClass().getDeclaredField("MY_LONG");
assertEquals(5073258162644648461L, field.getLong(null));
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
// Regression test for Harmony LinkedHashMap bug. Copied from core, just
// to make sure it doesn't get lost.
@SmallTest
public void testLinkedHashMap() {
// we want to test the LinkedHashMap in access ordering mode.
LinkedHashMap map = new LinkedHashMap<String, String>(10, 0.75f, true);
map.put("key1", "value1");
map.put("key2", "value2");
map.put("key3", "value3");
Iterator iterator = map.keySet().iterator();
String id = (String) iterator.next();
map.get(id);
try {
iterator.next();
// A LinkedHashMap is supposed to throw this Exception when a
// iterator.next() Operation takes place after a get
// Operation. This is because the get Operation is considered
// a structural modification if the LinkedHashMap is in
// access order mode.
fail("expected ConcurrentModificationException was not thrown.");
} catch(ConcurrentModificationException e) {
// expected
}
LinkedHashMap mapClone = (LinkedHashMap) map.clone();
iterator = map.keySet().iterator();
id = (String) iterator.next();
mapClone.get(id);
try {
iterator.next();
} catch(ConcurrentModificationException e) {
fail("expected ConcurrentModificationException was not thrown.");
}
}
// Regression test for #1212257: Boot-time package scan is slow. Not
// expected to fail. Please see log if you are interested in the results.
@LargeTest
public void testZipStressManifest() {
android.util.Log.d("MiscRegressionTest", "ZIP stress test started");
long time0 = System.currentTimeMillis();
try {
File[] files = new File("/system/app").listFiles();
byte[] buffer = new byte[512];
if (files != null) {
for (int i = 0; i < files.length; i++) {
android.util.Log.d("MiscRegressionTest",
"ZIP stress test processing " + files[i] + "...");
ZipFile zip = new ZipFile(files[i]);
ZipEntry entry = zip.getEntry("AndroidManifest.xml");
InputStream stream = zip.getInputStream(entry);
int j = stream.read(buffer);
while (j != -1) {
j = stream.read(buffer);
}
stream.close();
}
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
long time1 = System.currentTimeMillis();
android.util.Log.d("MiscRegressionTest", "ZIP stress test finished, " +
"time was " + (time1- time0) + "ms");
}
@LargeTest
public void testZipStressAllFiles() {
android.util.Log.d("MiscRegressionTest", "ZIP stress test started");
long time0 = System.currentTimeMillis();
try {
File[] files = new File("/system/app").listFiles();
byte[] buffer = new byte[512];
if (files != null) {
for (int i = 0; i < files.length; i++) {
android.util.Log.d("MiscRegressionTest",
"ZIP stress test processing " + files[i] + "...");
ZipFile zip = new ZipFile(files[i]);
Enumeration<? extends ZipEntry> entries = zip.entries();
while (entries.hasMoreElements()) {
InputStream stream = zip.getInputStream(entries.nextElement());
int j = stream.read(buffer);
while (j != -1) {
j = stream.read(buffer);
}
stream.close();
}
}
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
long time1 = System.currentTimeMillis();
android.util.Log.d("MiscRegressionTest", "ZIP stress test finished, " +
"time was " + (time1- time0) + "ms");
}
@SmallTest
public void testOsEncodingProperty() {
long time0 = System.currentTimeMillis();
String[] files = new File("/system/app").list();
long time1 = System.currentTimeMillis();
android.util.Log.d("MiscRegressionTest", "File.list() test finished, " +
"time was " + (time1- time0) + "ms");
}
// -------------------------------------------------------------------------
// Regression test for #1185084: Native memory allocated by
// java.util.zip.Deflater in system_server. The fix reduced some internal
// ZLIB buffers in size, so this test is trying to execute a lot of
// deflating to ensure that things are still working properly.
private void assertEquals(byte[] a, byte[] b) {
assertEquals("Arrays must have same length", a.length, b.length);
for (int i = 0; i < a.length; i++) {
assertEquals("Array elements #" + i + " must be equal", a[i], b[i]);
}
}
@LargeTest
public void testZipDeflateInflateStress() {
final int DATA_SIZE = 16384;
Random random = new Random(42); // Seed makes test reproducible
try {
// Outer loop selects "mode" of test.
for (int j = 1; j <=2 ; j++) {
byte[] input = new byte[DATA_SIZE];
if (j == 1) {
// Totally random content
random.nextBytes(input);
} else {
// Random contents with longer repetitions
int pos = 0;
while (pos < input.length) {
byte what = (byte)random.nextInt(256);
int howMany = random.nextInt(32);
if (pos + howMany >= input.length) {
howMany = input.length - pos;
}
Arrays.fill(input, pos, pos + howMany, what);
pos += howMany;
}
}
// Inner loop tries all 9 compression levels.
for (int i = 1; i <= 9; i++) {
android.util.Log.d("MiscRegressionTest", "ZipDeflateInflateStress test (" + j + "," + i + ")...");
byte[] zipped = new byte[2 * DATA_SIZE]; // Just to make sure...
Deflater deflater = new Deflater(i);
deflater.setInput(input);
deflater.finish();
deflater.deflate(zipped);
byte[] output = new byte[DATA_SIZE];
Inflater inflater = new Inflater();
inflater.setInput(zipped);
inflater.finished();
inflater.inflate(output);
assertEquals(input, output);
}
}
} catch (Exception ex) {
throw new RuntimeException(ex);
}
}
// -------------------------------------------------------------------------
// Regression test for #1252043: Thread.getStackTrace() is broken
class MyThread extends Thread {
public MyThread(String name) {
super(name);
}
@Override
public void run() {
doSomething();
}
public void doSomething() {
for (int i = 0; i < 20;) {
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
}
}
}
}
class MyOtherThread extends Thread {
public int visibleTraces;
public MyOtherThread(ThreadGroup group, String name) {
super(group, name);
}
@Override
public void run() {
visibleTraces = Thread.getAllStackTraces().size();
}
}
@LargeTest
public void testThreadGetStackTrace() {
MyThread t1 = new MyThread("t1");
t1.start();
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
}
StackTraceElement[] traces = t1.getStackTrace();
StackTraceElement trace = traces[traces.length - 2];
// Expect to find MyThread.doSomething in the trace
assertTrue("Must find MyThread.doSomething in trace",
trace.getClassName().endsWith("$MyThread") &&
trace.getMethodName().equals("doSomething"));
ThreadGroup g1 = new ThreadGroup("1");
MyOtherThread t2 = new MyOtherThread(g1, "t2");
t2.start();
try {
t2.join();
} catch (InterruptedException ex) {
}
// Expect to see the traces of all threads (not just t2)
assertTrue("Must have traces for all threads", t2.visibleTraces > 1);
}
}

View File

@@ -1,287 +0,0 @@
/*
* Copyright (C) 2008 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 android.core;
import android.test.suitebuilder.annotation.SmallTest;
import junit.framework.TestCase;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* Tests basic functionality of Pattern and Matcher classes.
*/
public class RegexTest extends TestCase {
@SmallTest
public void testMatches() throws Exception {
/* Tests class Matcher */
Pattern p = Pattern.compile("bcd");
Matcher m = p.matcher("bcd");
assertTrue("Should match.", m.matches());
/* Pattern in the middle */
p = Pattern.compile("bcd");
m = p.matcher("abcdefg");
assertFalse("Should not match.", m.matches());
/* Pattern at the head */
m = p.matcher("bcdefg");
assertFalse("Should not match.", m.matches());
/* Pattern at the tail */
m = p.matcher("abcd");
assertFalse("Should not match.", m.matches());
/* Make sure matches() doesn't change after calls to find() */
p = Pattern.compile(".*");
m = p.matcher("abc");
assertTrue(m.matches());
assertTrue(m.find());
assertTrue(m.matches());
p = Pattern.compile(".");
m = p.matcher("abc");
assertFalse(m.matches());
assertTrue(m.find());
assertFalse(m.matches());
/* Make sure matches() agrees after a reset() */
m.reset("z");
assertTrue(m.matches());
m.reset("xyz");
assertFalse(m.matches());
/* Tests class Pattern */
assertFalse("Erroneously matched partial string. " +
"See http://b/issue?id=754601", Pattern.matches("er", "xer"));
assertFalse("Erroneously matched partial string. " +
"See http://b/issue?id=754601", Pattern.matches("xe", "xer"));
assertTrue("Generic regex should match.",
Pattern.matches(".*", "bcd"));
assertTrue("Grouped regex should match.",
Pattern.matches("(b(c(d)))", "bcd"));
assertTrue("Grouped regex should match.",
Pattern.matches("(b)(c)(d)", "bcd"));
}
@SmallTest
public void testGroupCount() throws Exception {
Pattern p = Pattern.compile(
"\\b(?:\\+?1)?"
+ "(?:[ -\\.])?"
+ "\\(?(\\d{3})?\\)?"
+ "(?:[ -\\.\\/])?"
+ "(\\d{3})"
+ "(?:[ -\\.])?"
+ "(\\d{4})\\b"
);
Matcher m = p.matcher("1 (919) 555-1212");
assertEquals("groupCount is incorrect, see http://b/issue?id=759412",
3, m.groupCount());
}
@SmallTest
public void testGroups() throws Exception {
Pattern p = Pattern.compile("(b)([c|d])(z*)");
Matcher m = p.matcher("abcdefg");
/* Must call find() first, otherwise group*() are undefined. */
assertTrue(m.find());
assertEquals(3, m.groupCount());
assertEquals("bc", m.group(0));
assertEquals("b", m.group(1));
assertEquals("c", m.group(2));
assertEquals("", m.group(3));
}
@SmallTest
public void testFind() throws Exception {
Pattern p = Pattern.compile(".");
Matcher m = p.matcher("abc");
assertTrue(m.find());
assertEquals("a", m.group(0));
assertTrue(m.find());
assertEquals("b", m.group(0));
assertTrue(m.find());
assertEquals("c", m.group(0));
assertFalse(m.find());
}
@SmallTest
public void testReplaceAll() throws Exception {
// Begins with non-matching text, ends with matching text
Pattern p = Pattern.compile("a*b");
Matcher m = p.matcher("fooaabfooaabfooabfoob");
String r = m.replaceAll("-");
assertEquals("foo-foo-foo-foo-", r);
// Begins with matching text, ends with non-matching text
p = Pattern.compile("a*b");
m = p.matcher("aabfooaabfooabfoobfoo");
r = m.replaceAll("-");
assertEquals("-foo-foo-foo-foo", r);
}
@SmallTest
public void testReplaceFirst() throws Exception {
// Begins with non-matching text, ends with matching text
Pattern p = Pattern.compile("a*b");
Matcher m = p.matcher("fooaabfooaabfooabfoob");
String r = m.replaceFirst("-");
assertEquals("foo-fooaabfooabfoob", r);
// Begins with matching text, ends with non-matching text
p = Pattern.compile("a*b");
m = p.matcher("aabfooaabfooabfoobfoo");
r = m.replaceFirst("-");
assertEquals("-fooaabfooabfoobfoo", r);
}
@SmallTest
public void testSplit() throws Exception {
Pattern p = Pattern.compile(":");
String[] strings;
strings = p.split("boo:and:foo");
assertEquals(3, strings.length);
assertEquals("boo", strings[0]);
assertEquals("and", strings[1]);
assertEquals("foo", strings[2]);
strings = p.split("boo:and:foo", 2);
assertEquals(2, strings.length);
assertEquals("boo", strings[0]);
assertEquals("and:foo", strings[1]);
strings = p.split("boo:and:foo", 5);
assertEquals(3, strings.length);
assertEquals("boo", strings[0]);
assertEquals("and", strings[1]);
assertEquals("foo", strings[2]);
strings = p.split("boo:and:foo", -2);
assertEquals(3, strings.length);
assertEquals("boo", strings[0]);
assertEquals("and", strings[1]);
assertEquals("foo", strings[2]);
p = Pattern.compile("o");
strings = p.split("boo:and:foo");
assertEquals(3, strings.length);
assertEquals("b", strings[0]);
assertEquals("", strings[1]);
assertEquals(":and:f", strings[2]);
strings = p.split("boo:and:foo", 5);
assertEquals(5, strings.length);
assertEquals("b", strings[0]);
assertEquals("", strings[1]);
assertEquals(":and:f", strings[2]);
assertEquals("", strings[3]);
assertEquals("", strings[4]);
strings = p.split("boo:and:foo", -2);
assertEquals(5, strings.length);
assertEquals("b", strings[0]);
assertEquals("", strings[1]);
assertEquals(":and:f", strings[2]);
assertEquals("", strings[3]);
assertEquals("", strings[4]);
strings = p.split("boo:and:foo", 0);
assertEquals(3, strings.length);
assertEquals("b", strings[0]);
assertEquals("", strings[1]);
assertEquals(":and:f", strings[2]);
}
// -------------------------------------------------------------------
// Regression test for #1172774: Bug in Regex.java
// Regression test for #1216887: Regular expression match is very slow
public static final Pattern TOP_LEVEL_DOMAIN_PATTERN = Pattern.compile(
"((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[eghimnrwyz]"
+ "|l[abcikrstuvy]"
+ "|(mil|mobi|museum|m[acdghklmnopqrstuvwxyz])"
+ "|(name|net|n[acefgilopruz])"
+ "|(org|om)"
+ "|(pro|p[aefghklmnrstwy])"
+ "|qa"
+ "|r[eouw]"
+ "|s[abcdeghijklmnortuvyz]"
+ "|(tel|travel|t[cdfghjklmnoprtvwz])"
+ "|u[agkmsyz]"
+ "|v[aceginu]"
+ "|w[fs]"
+ "|y[etu]"
+ "|z[amw])");
public static final Pattern EMAIL_ADDRESS_PATTERN = Pattern.compile(
"[\\+a-zA-Z0-9\\.\\_\\%\\-]+\\@"
+ "(("
+ "[a-zA-Z0-9]\\.|"
+ "([a-zA-Z0-9][a-zA-Z0-9\\-]*[a-zA-Z0-9]\\.)+)"
+ TOP_LEVEL_DOMAIN_PATTERN
+ ")");
@SmallTest
public void testMonsterRegexCorrectness() {
assertTrue(EMAIL_ADDRESS_PATTERN.matcher("a+b@gmail.com").matches());
}
@SmallTest
public void testMonsterRegexPerformance() {
android.util.Log.e("RegexTest", "RegEx performance test started.");
long t0 = System.currentTimeMillis();
Matcher m = EMAIL_ADDRESS_PATTERN.matcher("donot repeate@RC8jjjjjjjjjjjjjjj");
assertFalse(m.find());
long t1 = System.currentTimeMillis();
android.util.Log.e("RegexTest", "RegEx performance test finished, " +
"took " + (t1 - t0) + " ms.");
}
//
// -------------------------------------------------------------------
}