FileDocCategorySizeDatePackage
OverlayBaseTest.javaAPI DocAndroid 5.1 API16418Thu Mar 12 22:22:12 GMT 2015com.android.overlaytest

OverlayBaseTest

public abstract class OverlayBaseTest extends android.test.AndroidTestCase

Fields Summary
private android.content.res.Resources
mResources
protected int
mMode
protected static final int
MODE_NO_OVERLAY
protected static final int
MODE_SINGLE_OVERLAY
protected static final int
MODE_MULTIPLE_OVERLAYS
Constructors Summary
Methods Summary
private voidassertResource(int resId, java.lang.String no, java.lang.String so, java.lang.String mo)

        String expected = getExpected(no, so, mo);
        String actual = mResources.getString(resId);
        assertEquals(expected, actual);
    
private voidassertResource(int resId, int[] no, int[] so, int[] mo)

        int[] expected = getExpected(no, so, mo);
        int[] actual = mResources.getIntArray(resId);
        assertEquals("length:", expected.length, actual.length);
        for (int i = 0; i < actual.length; ++i) {
            assertEquals("index " + i + ":", actual[i], expected[i]);
        }
    
private voidassertResource(int resId, boolean no, boolean so, boolean mo)

        boolean expected = getExpected(no, so, mo);
        boolean actual = mResources.getBoolean(resId);
        assertEquals(expected, actual);
    
private voidassertResource(int resId, int no, int so, int mo)

        int expected = getExpected(no, so, mo);
        int actual = mResources.getInteger(resId);
        assertEquals(expected, actual);
    
private intcalculateRawResourceChecksum(int resId)

        InputStream input = null;
        try {
            input = mResources.openRawResource(resId);
            int ch, checksum = 0;
            while ((ch = input.read()) != -1) {
                checksum = (checksum + ch) % 0xffddbb00;
            }
            return checksum;
        } finally {
            input.close();
        }
    
private booleangetExpected(boolean no, boolean so, boolean mo)

        switch (mMode) {
            case MODE_NO_OVERLAY:
                return no;
            case MODE_SINGLE_OVERLAY:
                return so;
            case MODE_MULTIPLE_OVERLAYS:
                return mo;
            default:
                fail("Unknown mode!");
                return no;
        }
    
private java.lang.StringgetExpected(java.lang.String no, java.lang.String so, java.lang.String mo)

        switch (mMode) {
            case MODE_NO_OVERLAY:
                return no;
            case MODE_SINGLE_OVERLAY:
                return so;
            case MODE_MULTIPLE_OVERLAYS:
                return mo;
            default:
                fail("Unknown mode!");
                return no;
        }
    
private intgetExpected(int no, int so, int mo)

        switch (mMode) {
            case MODE_NO_OVERLAY:
                return no;
            case MODE_SINGLE_OVERLAY:
                return so;
            case MODE_MULTIPLE_OVERLAYS:
                return mo;
            default:
                fail("Unknown mode!");
                return no;
        }
    
private int[]getExpected(int[] no, int[] so, int[] mo)

        switch (mMode) {
            case MODE_NO_OVERLAY:
                return no;
            case MODE_SINGLE_OVERLAY:
                return so;
            case MODE_MULTIPLE_OVERLAYS:
                return mo;
            default:
                fail("Unknown mode!");
                return no;
        }
    
private voidsetLocale(java.util.Locale locale)

        Locale.setDefault(locale);
        Configuration config = new Configuration();
        config.locale = locale;
        mResources.updateConfiguration(config, mResources.getDisplayMetrics());
    
protected voidsetUp()


       
        mResources = getContext().getResources();
    
public voidtestApp2()

        final int resId = R.string.str2; // only in base package and first app overlay
        assertResource(resId, "none", "single", "single");
    
public voidtestAppRaw()

        final int resId = R.raw.lorem_ipsum;

        InputStream input = null;
        BufferedReader reader = null;
        String actual = "";
        try {
            input = mResources.openRawResource(resId);
            reader = new BufferedReader(new InputStreamReader(input));
            actual = reader.readLine();
        } finally {
            reader.close();
            input.close();
        }

        final String no = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, " +
            "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " +
            "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip " +
            "ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit " +
            "esse cillum dolore eu fugiat nulla pariatur. " +
            "Excepteur sint occaecat cupidatat non proident, " +
            "sunt in culpa qui officia deserunt mollit anim id est laborum.";
        final String so = "Lorem ipsum: single overlay.";
        final String mo = "Lorem ipsum: multiple overlays.";

        assertEquals(getExpected(no, so, mo), actual);
    
public voidtestAppString()

        final int resId = R.string.str;
        assertResource(resId, "none", "single", "multiple");
    
public voidtestAppXml()

        int expected = getExpected(0, 1, 2);
        int actual = -1;
        XmlResourceParser parser = mResources.getXml(R.xml.integer);
        int type = parser.getEventType();
        while (type != XmlResourceParser.END_DOCUMENT && actual == -1) {
            if (type == XmlResourceParser.START_TAG && "integer".equals(parser.getName())) {
                AttributeSet as = Xml.asAttributeSet(parser);
                actual = as.getAttributeIntValue(null, "value", -1);
            }
            type = parser.next();
        }
        parser.close();
        assertEquals(expected, actual);
    
public voidtestBoolean()

        // always_true has no overlay
        final int resId = R.bool.always_true;
        assertResource(resId, true, true, true);
    
public voidtestBooleanOverlay()

        // usually_false has the value:
        // - false when no overlay exists (MODE_NO_OVERLAY)
        // - true when a single overlay exists (MODE_SINGLE_OVERLAY)
        // - false when multiple overlays exists (MODE_MULTIPLE_OVERLAYS)
        final int resId = R.bool.usually_false;
        assertResource(resId, false, true, false);
    
public voidtestDrawable()

        // drawable-nodpi/drawable has overlay (default config)
        final int resId = R.drawable.drawable;
        int actual = calculateRawResourceChecksum(resId);
        int expected = 0;
        switch (mMode) {
            case MODE_NO_OVERLAY:
                expected = 0x00005665;
                break;
            case MODE_SINGLE_OVERLAY:
            case MODE_MULTIPLE_OVERLAYS:
                expected = 0x000051da;
                break;
            default:
                fail("Unknown mode " + mMode);
        }
        assertEquals(expected, actual);
    
public voidtestFrameworkBooleanOverlay()

        // config_annoy_dianne has the value:
        // - true when no overlay exists (MODE_NO_OVERLAY)
        // - false when a single overlay exists (MODE_SINGLE_OVERLAY)
        // - false when multiple overlays exists (MODE_MULTIPLE_OVERLAYS)
        final int resId = com.android.internal.R.bool.config_annoy_dianne;
        assertResource(resId, true, false, false);
    
public voidtestIntegerArray()

        // prime_numbers has no overlay
        final int resId = R.array.prime_numbers;
        final int[] expected = {2, 3, 5, 7, 11, 13, 17, 19};
        assertResource(resId, expected, expected, expected);
    
public voidtestIntegerArrayOverlay()

        // fibonacci has values:
        // - eight first values of Fibonacci sequence, when no overlay exists (MODE_NO_OVERLAY)
        // - eight first values of Fibonacci sequence (reversed), for single and multiple overlays
        //   (MODE_SINGLE_OVERLAY, MODE_MULTIPLE_OVERLAYS)
        final int resId = R.array.fibonacci;
        assertResource(resId,
                new int[]{1, 1, 2, 3, 5, 8, 13, 21},
                new int[]{21, 13, 8, 5, 3, 2, 1, 1},
                new int[]{21, 13, 8, 5, 3, 2, 1, 1});
    
public voidtestMatrix100000()

        final int resId = R.integer.matrix_100000;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 100, 100);
    
public voidtestMatrix100001()

        final int resId = R.integer.matrix_100001;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 100, 600);
    
public voidtestMatrix100010()

        final int resId = R.integer.matrix_100010;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 100, 500);
    
public voidtestMatrix100011()

        final int resId = R.integer.matrix_100011;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 100, 600);
    
public voidtestMatrix100100()

        final int resId = R.integer.matrix_100100;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 400, 400);
    
public voidtestMatrix100101()

        final int resId = R.integer.matrix_100101;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 400, 600);
    
public voidtestMatrix100110()

        final int resId = R.integer.matrix_100110;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 400, 400);
    
public voidtestMatrix100111()

        final int resId = R.integer.matrix_100111;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 400, 600);
    
public voidtestMatrix101000()

        final int resId = R.integer.matrix_101000;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 300, 300);
    
public voidtestMatrix101001()

        final int resId = R.integer.matrix_101001;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 300, 600);
    
public voidtestMatrix101010()

        final int resId = R.integer.matrix_101010;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 300, 500);
    
public voidtestMatrix101011()

        final int resId = R.integer.matrix_101011;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 300, 600);
    
public voidtestMatrix101100()

        final int resId = R.integer.matrix_101100;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 400, 400);
    
public voidtestMatrix101101()

        final int resId = R.integer.matrix_101101;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 400, 600);
    
public voidtestMatrix101110()

        final int resId = R.integer.matrix_101110;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 400, 400);
    
public voidtestMatrix101111()

        final int resId = R.integer.matrix_101111;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 100, 400, 600);
    
public voidtestMatrix110000()

        final int resId = R.integer.matrix_110000;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 200, 200);
    
public voidtestMatrix110001()

        final int resId = R.integer.matrix_110001;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 200, 600);
    
public voidtestMatrix110010()

        final int resId = R.integer.matrix_110010;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 200, 200);
    
public voidtestMatrix110011()

        final int resId = R.integer.matrix_110011;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 200, 600);
    
public voidtestMatrix110100()

        final int resId = R.integer.matrix_110100;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 400, 400);
    
public voidtestMatrix110101()

        final int resId = R.integer.matrix_110101;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 400, 600);
    
public voidtestMatrix110110()

        final int resId = R.integer.matrix_110110;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 400, 400);
    
public voidtestMatrix110111()

        final int resId = R.integer.matrix_110111;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 400, 600);
    
public voidtestMatrix111000()

        final int resId = R.integer.matrix_111000;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 200, 200);
    
public voidtestMatrix111001()

        final int resId = R.integer.matrix_111001;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 200, 600);
    
public voidtestMatrix111010()

        final int resId = R.integer.matrix_111010;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 200, 200);
    
public voidtestMatrix111011()

        final int resId = R.integer.matrix_111011;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 200, 600);
    
public voidtestMatrix111100()

        final int resId = R.integer.matrix_111100;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 400, 400);
    
public voidtestMatrix111101()

        final int resId = R.integer.matrix_111101;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 400, 600);
    
public voidtestMatrix111110()

        final int resId = R.integer.matrix_111110;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 400, 400);
    
public voidtestMatrix111111()

        final int resId = R.integer.matrix_111111;
        setLocale(new Locale("sv", "SE"));
        assertResource(resId, 200, 400, 600);