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

Commit 29ac247d authored by Jesse Wilson's avatar Jesse Wilson
Browse files

Move 41 tests to libcore, closer to the tested code. (2nd half)

Change-Id: I18650718a7e49c84a0cc3c5b0c1172c71d2d54cf
http://b/3073226
parent f5a1a0b6
Loading
Loading
Loading
Loading
+0 −94
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.util.ArrayList;
import android.test.suitebuilder.annotation.SmallTest;

/**
 * This test case tests several often used functionality of ArrayLists.
 */
public class ArrayListTest extends TestCase {

    @SuppressWarnings("unchecked")
    @SmallTest
    public void testArrayList() throws Exception {
        ArrayList array = new ArrayList();
        assertEquals(0, array.size());
        assertTrue(array.isEmpty());

        array.add(new Integer(0));
        array.add(0, new Integer(1));
        array.add(1, new Integer(2));
        array.add(new Integer(3));
        array.add(new Integer(1));

        assertEquals(5, array.size());
        assertFalse(array.isEmpty());

        assertEquals(1, ((Integer) array.get(0)).intValue());
        assertEquals(2, ((Integer) array.get(1)).intValue());
        assertEquals(0, ((Integer) array.get(2)).intValue());
        assertEquals(3, ((Integer) array.get(3)).intValue());
        assertEquals(1, ((Integer) array.get(4)).intValue());

        assertFalse(array.contains(null));
        assertTrue(array.contains(new Integer(2)));
        assertEquals(0, array.indexOf(new Integer(1)));
        assertEquals(4, array.lastIndexOf(new Integer(1)));
        assertTrue(array.indexOf(new Integer(5)) < 0);
        assertTrue(array.lastIndexOf(new Integer(5)) < 0);


        array.remove(1);
        array.remove(1);

        assertEquals(3, array.size());
        assertFalse(array.isEmpty());
        assertEquals(1, ((Integer) array.get(0)).intValue());
        assertEquals(3, ((Integer) array.get(1)).intValue());
        assertEquals(1, ((Integer) array.get(2)).intValue());

        assertFalse(array.contains(null));
        assertFalse(array.contains(new Integer(2)));
        assertEquals(0, array.indexOf(new Integer(1)));
        assertEquals(2, array.lastIndexOf(new Integer(1)));
        assertTrue(array.indexOf(new Integer(5)) < 0);
        assertTrue(array.lastIndexOf(new Integer(5)) < 0);

        array.clear();

        assertEquals(0, array.size());
        assertTrue(array.isEmpty());
        assertTrue(array.indexOf(new Integer(5)) < 0);
        assertTrue(array.lastIndexOf(new Integer(5)) < 0);

        ArrayList al = new ArrayList();

        assertFalse(al.remove(null));
        assertFalse(al.remove("string"));

        al.add("string");
        al.add(null);

        assertTrue(al.remove(null));
        assertTrue(al.remove("string"));
    }
}
+0 −46
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 android.test.suitebuilder.annotation.SmallTest;

/**
 * Tests some basic functionality of Booleans.
 */
public class BooleanTest extends TestCase {

    @SmallTest
    public void testBoolean() throws Exception {
        Boolean a = new Boolean(true);
        Boolean b = new Boolean("True");
        Boolean c = new Boolean(false);
        Boolean d = new Boolean("Yes");

        assertEquals(a, b);
        assertEquals(c, d);
        assertTrue(a.booleanValue());
        assertFalse(c.booleanValue());
        assertEquals("true", a.toString());
        assertEquals("false", c.toString());
        assertEquals(Boolean.TRUE, a);
        assertEquals(Boolean.FALSE, c);
        assertSame(Boolean.valueOf(true), Boolean.TRUE);
        assertSame(Boolean.valueOf(false), Boolean.FALSE);
    }
}
+0 −81
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.BufferedInputStream;
import java.io.ByteArrayInputStream;
import android.test.suitebuilder.annotation.SmallTest;

/**
 * Tests to verify that simple functionality works for BufferedInputStreams.
 */
public class BufferedInputStreamTest extends TestCase {

    @SmallTest
    public void testBufferedInputStream() throws Exception {
        String str = "AbCdEfGhIjKlM\nOpQrStUvWxYz";
        ByteArrayInputStream aa = new ByteArrayInputStream(str.getBytes());
        ByteArrayInputStream ba = new ByteArrayInputStream(str.getBytes());
        ByteArrayInputStream ca = new ByteArrayInputStream(str.getBytes());
        ByteArrayInputStream da = new ByteArrayInputStream(str.getBytes());
        ByteArrayInputStream ea = new ByteArrayInputStream(str.getBytes());

        BufferedInputStream a = new BufferedInputStream(aa, 6);
        try {
            assertEquals(str, IOUtil.read(a));
        } finally {
            a.close();
        }

        BufferedInputStream b = new BufferedInputStream(ba, 7);
        try {
            assertEquals("AbCdEfGhIj", IOUtil.read(b, 10));
        } finally {
            b.close();
        }

        BufferedInputStream c = new BufferedInputStream(ca, 9);
        try {
            assertEquals("bdfhjl\nprtvxz", IOUtil.skipRead(c));
        } finally {
            c.close();
        }

        BufferedInputStream d = new BufferedInputStream(da, 9);
        try {
            assertEquals('A', d.read());
            d.mark(15);
            assertEquals('b', d.read());
            assertEquals('C', d.read());
            d.reset();
            assertEquals('b', d.read());
        } finally {
            d.close();
        }

        BufferedInputStream e = new BufferedInputStream(ea, 11);
        try {
            // test that we can ask for more than is present, and that we'll get
            // back only what is there.
            assertEquals(str, IOUtil.read(e, 10000));
        } finally {
            e.close();
        }
    }
}
+0 −50
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.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import android.test.suitebuilder.annotation.SmallTest;

/**
 * Tests to verify that simple functionality works for BufferedOutputStreams.
 */
public class BufferedOutputStreamTest extends TestCase {

    @SmallTest
    public void testBufferedOutputStream() throws Exception {
        String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
        ByteArrayOutputStream aa = new ByteArrayOutputStream();
        BufferedOutputStream a = new BufferedOutputStream(aa, 15);
        try {
            a.write(str.getBytes(), 0, 26);
            a.write('A');

            assertEquals(26, aa.size());
            assertEquals(aa.toString(), str);

            a.flush();

            assertEquals(27, aa.size());
            assertEquals("AbCdEfGhIjKlMnOpQrStUvWxYzA", aa.toString());
        } finally {
            a.close();
        }
    }
}
+0 −66
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.BufferedReader;
import java.io.StringReader;
import android.test.suitebuilder.annotation.MediumTest;

/**
 * Tests to verify that simple functionality works for BufferedReaders.
 */
public class BufferedReaderTest extends TestCase {

    @MediumTest
    public void testBufferedReader() throws Exception {
        String str = "AbCdEfGhIjKlMnOpQrStUvWxYz";
        StringReader aa = new StringReader(str);
        StringReader ba = new StringReader(str);
        StringReader ca = new StringReader(str);
        StringReader da = new StringReader(str);

        BufferedReader a = new BufferedReader(aa, 5);
        try {
            assertEquals(str, IOUtil.read(a));
        } finally {
            a.close();
        }

        BufferedReader b = new BufferedReader(ba, 15);
        try {
            assertEquals("AbCdEfGhIj", IOUtil.read(b, 10));
        } finally {
            b.close();
        }

        BufferedReader c = new BufferedReader(ca);
        try {
            assertEquals("bdfhjlnprtvxz", IOUtil.skipRead(c));
        } finally {
            c.close();
        }

        BufferedReader d = new BufferedReader(da);
        try {
            assertEquals("AbCdEfGdEfGhIjKlMnOpQrStUvWxYz", IOUtil.markRead(d, 3, 4));
        } finally {
            d.close();
        }
    }
}
Loading