PrimitiveTestpublic class PrimitiveTest extends android.test.AndroidTestCase
Fields Summary |
---|
private android.content.res.Resources | mResources |
Methods Summary |
---|
private static void | checkString(int resid, java.lang.String actual, java.lang.String expected)
assertEquals("Expecting string value \"" + expected + "\" got \""
+ actual + "\" in resources 0x" + Integer.toHexString(resid),
expected, actual);
| protected void | setUp()
super.setUp();
mResources = mContext.getResources();
| public void | testBoolean()
tryBoolean(R.bool.trueRes, true);
tryBoolean(R.bool.falseRes, false);
| public void | testEnum()
tryEnum(R.style.TestEnum1, 1);
tryEnum(R.style.TestEnum2, 2);
tryEnum(R.style.TestEnum10, 10);
tryEnum(R.style.TestEnum1_EmptyInherit, 1);
| public void | testFlags()
tryFlag(R.style.TestFlag1, 0x1);
tryFlag(R.style.TestFlag2, 0x2);
tryFlag(R.style.TestFlag31, 0x40000000);
tryFlag(R.style.TestFlag1And2, 0x3);
tryFlag(R.style.TestFlag1And2And31, 0x40000003);
| public void | testFormattedString()
// Make sure the regular one doesn't format anything
checkString(R.string.formattedStringNone,
mResources.getString(R.string.formattedStringNone),
"Format[]");
checkString(R.string.formattedStringOne,
mResources.getString(R.string.formattedStringOne),
"Format[%d]");
checkString(R.string.formattedStringTwo,
mResources.getString(R.string.formattedStringTwo),
"Format[%3$d,%2$s]");
// Make sure the formatted one works
checkString(R.string.formattedStringNone,
mResources.getString(R.string.formattedStringNone),
"Format[]");
checkString(R.string.formattedStringOne,
mResources.getString(R.string.formattedStringOne, 42),
"Format[42]");
checkString(R.string.formattedStringTwo,
mResources.getString(R.string.formattedStringTwo, "unused", "hi", 43),
"Format[43,hi]");
| public void | testStringCoerce()
tryString(R.string.coerceIntegerToString, "100");
tryString(R.string.coerceBooleanToString, "true");
tryString(R.string.coerceColorToString, "#fff");
tryString(R.string.coerceFloatToString, "100.0");
tryString(R.string.coerceDimensionToString, "100px");
tryString(R.string.coerceFractionToString, "100%");
| private void | tryBoolean(int resid, boolean expected)
TypedValue v = new TypedValue();
mContext.getResources().getValue(resid, v, true);
assertEquals(TypedValue.TYPE_INT_BOOLEAN, v.type);
assertEquals("Expecting boolean value " + expected + " got " + v
+ " from TypedValue: in resource 0x" + Integer.toHexString(resid),
expected, v.data != 0);
assertEquals("Expecting boolean value " + expected + " got " + v
+ " from getBoolean(): in resource 0x" + Integer.toHexString(resid),
expected, mContext.getResources().getBoolean(resid));
| private void | tryEnum(int resid, int expected)
TypedArray sa =
mContext.obtainStyledAttributes(resid, R.styleable.EnumStyle);
int value = sa.getInt(R.styleable.EnumStyle_testEnum, -1);
sa.recycle();
assertEquals("Expecting value " + expected + " got " + value
+ ": in resource 0x" + Integer.toHexString(resid),
expected, value);
| private void | tryFlag(int resid, int expected)
TypedArray sa =
mContext.obtainStyledAttributes(resid, R.styleable.FlagStyle);
int value = sa.getInt(R.styleable.FlagStyle_testFlags, -1);
sa.recycle();
assertEquals("Expecting value " + expected + " got " + value
+ ": in resource 0x" + Integer.toHexString(resid),
expected, value);
| private void | tryString(int resid, java.lang.String expected)
TypedValue v = new TypedValue();
mContext.getResources().getValue(resid, v, true);
assertEquals(TypedValue.TYPE_STRING, v.type);
assertEquals("Expecting string value " + expected + " got " + v
+ ": in resource 0x" + Integer.toHexString(resid),
expected, v.string);
|
|