FileDocCategorySizeDatePackage
AidlTest.javaAPI DocAndroid 5.1 API12818Thu Mar 12 22:22:12 GMT 2015android.os

AidlTest

public class AidlTest extends junit.framework.TestCase

Fields Summary
private IAidlTest
mRemote
Constructors Summary
Methods Summary
private static booleancheck(android.os.AidlTest$TestParcelable p, int n, java.lang.String s)

        return p.mAnInt == n &&
                ((s == null && p.mAString == null) || s.equals(p.mAString));
    
protected voidsetUp()

        super.setUp();
        AidlObject mLocal = new AidlObject();
        mRemote = IAidlTest.Stub.asInterface(mLocal);
    
public voidtestArrays()

        // boolean
        boolean[] b0 = new boolean[]{true};
        boolean[] b1 = new boolean[]{false, true};
        boolean[] b2 = new boolean[]{true, false, true};
        boolean[] br = mRemote.booleanArray(b0, b1, b2);

        assertEquals(1, br.length);
        assertTrue(br[0]);

        assertTrue(b1[0]);
        assertFalse(b1[1]);

        assertTrue(b2[0]);
        assertFalse(b2[1]);
        assertTrue(b2[2]);

        // char
        char[] c0 = new char[]{'a"};
        char[] c1 = new char[]{'b", 'c"};
        char[] c2 = new char[]{'d", 'e", 'f"};
        char[] cr = mRemote.charArray(c0, c1, c2);

        assertEquals(1, cr.length);
        assertEquals('a", cr[0]);

        assertEquals('a", c1[0]);
        assertEquals('\0", c1[1]);

        assertEquals('a", c2[0]);
        assertEquals('e", c2[1]);
        assertEquals('f", c2[2]);

        // int
        int[] i0 = new int[]{34};
        int[] i1 = new int[]{38, 39};
        int[] i2 = new int[]{42, 43, 44};
        int[] ir = mRemote.intArray(i0, i1, i2);

        assertEquals(1, ir.length);
        assertEquals(34, ir[0]);

        assertEquals(34, i1[0]);
        assertEquals(0, i1[1]);

        assertEquals(34, i2[0]);
        assertEquals(43, i2[1]);
        assertEquals(44, i2[2]);

        // long
        long[] l0 = new long[]{50};
        long[] l1 = new long[]{51, 52};
        long[] l2 = new long[]{53, 54, 55};
        long[] lr = mRemote.longArray(l0, l1, l2);

        assertEquals(1, lr.length);
        assertEquals(50, lr[0]);

        assertEquals(50, l1[0]);
        assertEquals(0, l1[1]);

        assertEquals(50, l2[0]);
        assertEquals(54, l2[1]);
        assertEquals(55, l2[2]);

        // float
        float[] f0 = new float[]{90.1f};
        float[] f1 = new float[]{90.2f, 90.3f};
        float[] f2 = new float[]{90.4f, 90.5f, 90.6f};
        float[] fr = mRemote.floatArray(f0, f1, f2);

        assertEquals(1, fr.length);
        assertEquals(90.1f, fr[0]);

        assertEquals(90.1f, f1[0]);
        assertEquals(0f, f1[1], 0.0f);

        assertEquals(90.1f, f2[0]);
        assertEquals(90.5f, f2[1]);
        assertEquals(90.6f, f2[2]);

        // double
        double[] d0 = new double[]{100.1};
        double[] d1 = new double[]{100.2, 100.3};
        double[] d2 = new double[]{100.4, 100.5, 100.6};
        double[] dr = mRemote.doubleArray(d0, d1, d2);

        assertEquals(1, dr.length);
        assertEquals(100.1, dr[0]);

        assertEquals(100.1, d1[0]);
        assertEquals(0, d1[1], 0.0);

        assertEquals(100.1, d2[0]);
        assertEquals(100.5, d2[1]);
        assertEquals(100.6, d2[2]);

        // String
        String[] s0 = new String[]{"s0[0]"};
        String[] s1 = new String[]{"s1[0]", "s1[1]"};
        String[] s2 = new String[]{"s2[0]", "s2[1]", "s2[2]"};
        String[] sr = mRemote.stringArray(s0, s1, s2);

        assertEquals(1, sr.length);
        assertEquals("s0[0]", sr[0]);

        assertEquals("s0[0]", s1[0]);
        assertNull(s1[1]);

        assertEquals("s0[0]", s2[0]);
        assertEquals("s2[1]", s2[1]);
        assertEquals("s2[2]", s2[2]);
    
public voidtestInt()

        int result = mRemote.intMethod(42);
        assertEquals(42, result);
    
public voidtestIntSecurityException()

        boolean good = false;
        try {
            mRemote.intSecurityException();
        } catch (SecurityException e) {
            good = true;
        }
        assertEquals(good, true);
    
public voidtestListParcelableLonger()

        List<TestParcelable> list = Lists.newArrayList();
        list.add(new TestParcelable(33, "asdf"));
        list.add(new TestParcelable(34, "jkl;"));

        TestParcelable result = mRemote.listParcelableLonger(list, 1);

//        System.out.println("result=" + result);
//        for (TestParcelable p : list) {
//            System.out.println("longer: " + p);
//        }

        assertEquals("jkl;", result.mAString);
        assertEquals(34, result.mAnInt);

        assertEquals(3, list.size());
        assertTrue("out parameter 0: " + list.get(0), check(list.get(0), 33, "asdf"));
        assertTrue("out parameter 1: " + list.get(1), check(list.get(1), 34, "jkl;"));
        assertTrue("out parameter 2: " + list.get(2), check(list.get(2), 34, "jkl;"));

        assertNotSame(list.get(1), list.get(2));
    
public voidtestListParcelableShorter()

        List<TestParcelable> list = Lists.newArrayList();
        list.add(new TestParcelable(33, "asdf"));
        list.add(new TestParcelable(34, "jkl;"));
        list.add(new TestParcelable(35, "qwerty"));

        int result = mRemote.listParcelableShorter(list, 2);

//        System.out.println("result=" + result);
//        for (TestParcelable p : list) {
//            System.out.println("shorter: " + p);
//        }

        assertEquals(2, result);
        assertEquals(2, list.size());
        assertTrue("out parameter 0: " + list.get(0), check(list.get(0), 33, "asdf"));
        assertTrue("out parameter 1: " + list.get(1), check(list.get(1), 34, "jkl;"));

        assertNotSame(list.get(0), list.get(1));
    
public voidtestParcelableIn()

        TestParcelable arg = new TestParcelable(43, "hi");
        TestParcelable result = mRemote.parcelableIn(arg);
        assertNotSame(arg, result);

        assertEquals(43, arg.mAnInt);
        assertEquals(44, result.mAnInt);
    
public voidtestParcelableInOut()

        TestParcelable arg = new TestParcelable(43, "hi");
        TestParcelable result = mRemote.parcelableInOut(arg);
        assertNotSame(arg, result);
        assertEquals(44, arg.mAnInt);
    
public voidtestParcelableOut()

        TestParcelable arg = new TestParcelable(43, "hi");
        TestParcelable result = mRemote.parcelableOut(arg);
        assertNotSame(arg, result);
        assertEquals(44, arg.mAnInt);
    
public voidtestVoidSecurityException()

        boolean good = false;
        try {
            mRemote.voidSecurityException();
        } catch (SecurityException e) {
            good = true;
        }
        assertEquals(good, true);