Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0102c21f authored by Jesse Wilson's avatar Jesse Wilson
Browse files

Track libcore tests moving from frameworks/base to libcore.

Bug: http://b/3073226
Change-Id: I07076e6ed74fcae5482dff477ed102c770c197c9
parent 5aa2136d
Loading
Loading
Loading
Loading
+0 −48
Original line number Diff line number Diff line
/*
 * 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());
    }
}
+0 −243
Original line number Diff line number Diff line
/*
 * 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);
    }
}
+0 −337

File deleted.

Preview size limit exceeded, changes collapsed.

+2 −450

File changed.

Preview size limit exceeded, changes collapsed.

+0 −287
Original line number Diff line number Diff line
/*
 * 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.");
    }

    //
    // -------------------------------------------------------------------
    
}