OverlayBaseTestpublic 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 |
Methods Summary |
---|
private void | assertResource(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 void | assertResource(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 void | assertResource(int resId, boolean no, boolean so, boolean mo)
boolean expected = getExpected(no, so, mo);
boolean actual = mResources.getBoolean(resId);
assertEquals(expected, actual);
| private void | assertResource(int resId, int no, int so, int mo)
int expected = getExpected(no, so, mo);
int actual = mResources.getInteger(resId);
assertEquals(expected, actual);
| private int | calculateRawResourceChecksum(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 boolean | getExpected(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.String | getExpected(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 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 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 void | setLocale(java.util.Locale locale)
Locale.setDefault(locale);
Configuration config = new Configuration();
config.locale = locale;
mResources.updateConfiguration(config, mResources.getDisplayMetrics());
| protected void | setUp()
mResources = getContext().getResources();
| public void | testApp2()
final int resId = R.string.str2; // only in base package and first app overlay
assertResource(resId, "none", "single", "single");
| public void | testAppRaw()
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 void | testAppString()
final int resId = R.string.str;
assertResource(resId, "none", "single", "multiple");
| public void | testAppXml()
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 void | testBoolean()
// always_true has no overlay
final int resId = R.bool.always_true;
assertResource(resId, true, true, true);
| public void | testBooleanOverlay()
// 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 void | testDrawable()
// 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 void | testFrameworkBooleanOverlay()
// 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 void | testIntegerArray()
// 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 void | testIntegerArrayOverlay()
// 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 void | testMatrix100000()
final int resId = R.integer.matrix_100000;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 100, 100);
| public void | testMatrix100001()
final int resId = R.integer.matrix_100001;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 100, 600);
| public void | testMatrix100010()
final int resId = R.integer.matrix_100010;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 100, 500);
| public void | testMatrix100011()
final int resId = R.integer.matrix_100011;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 100, 600);
| public void | testMatrix100100()
final int resId = R.integer.matrix_100100;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 400, 400);
| public void | testMatrix100101()
final int resId = R.integer.matrix_100101;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 400, 600);
| public void | testMatrix100110()
final int resId = R.integer.matrix_100110;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 400, 400);
| public void | testMatrix100111()
final int resId = R.integer.matrix_100111;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 400, 600);
| public void | testMatrix101000()
final int resId = R.integer.matrix_101000;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 300, 300);
| public void | testMatrix101001()
final int resId = R.integer.matrix_101001;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 300, 600);
| public void | testMatrix101010()
final int resId = R.integer.matrix_101010;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 300, 500);
| public void | testMatrix101011()
final int resId = R.integer.matrix_101011;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 300, 600);
| public void | testMatrix101100()
final int resId = R.integer.matrix_101100;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 400, 400);
| public void | testMatrix101101()
final int resId = R.integer.matrix_101101;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 400, 600);
| public void | testMatrix101110()
final int resId = R.integer.matrix_101110;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 400, 400);
| public void | testMatrix101111()
final int resId = R.integer.matrix_101111;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 100, 400, 600);
| public void | testMatrix110000()
final int resId = R.integer.matrix_110000;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 200, 200);
| public void | testMatrix110001()
final int resId = R.integer.matrix_110001;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 200, 600);
| public void | testMatrix110010()
final int resId = R.integer.matrix_110010;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 200, 200);
| public void | testMatrix110011()
final int resId = R.integer.matrix_110011;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 200, 600);
| public void | testMatrix110100()
final int resId = R.integer.matrix_110100;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 400, 400);
| public void | testMatrix110101()
final int resId = R.integer.matrix_110101;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 400, 600);
| public void | testMatrix110110()
final int resId = R.integer.matrix_110110;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 400, 400);
| public void | testMatrix110111()
final int resId = R.integer.matrix_110111;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 400, 600);
| public void | testMatrix111000()
final int resId = R.integer.matrix_111000;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 200, 200);
| public void | testMatrix111001()
final int resId = R.integer.matrix_111001;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 200, 600);
| public void | testMatrix111010()
final int resId = R.integer.matrix_111010;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 200, 200);
| public void | testMatrix111011()
final int resId = R.integer.matrix_111011;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 200, 600);
| public void | testMatrix111100()
final int resId = R.integer.matrix_111100;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 400, 400);
| public void | testMatrix111101()
final int resId = R.integer.matrix_111101;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 400, 600);
| public void | testMatrix111110()
final int resId = R.integer.matrix_111110;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 400, 400);
| public void | testMatrix111111()
final int resId = R.integer.matrix_111111;
setLocale(new Locale("sv", "SE"));
assertResource(resId, 200, 400, 600);
|
|