use of android.support.test.filters.SmallTest in project android_frameworks_base by DirtyUnicorns.
the class ResourcesManagerTest method testThemesGetUpdatedWithNewImpl.
@SmallTest
public void testThemesGetUpdatedWithNewImpl() {
Binder activity1 = new Binder();
Resources resources1 = mResourcesManager.createBaseActivityResources(activity1, APP_ONE_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, null, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
assertNotNull(resources1);
Resources.Theme theme = resources1.newTheme();
assertSame(resources1, theme.getResources());
theme.applyStyle(android.R.style.Theme_NoTitleBar, false);
TypedValue value = new TypedValue();
assertTrue(theme.resolveAttribute(android.R.attr.windowNoTitle, value, true));
assertEquals(TypedValue.TYPE_INT_BOOLEAN, value.type);
assertTrue(value.data != 0);
final Configuration overrideConfig = new Configuration();
overrideConfig.orientation = Configuration.ORIENTATION_LANDSCAPE;
mResourcesManager.updateResourcesForActivity(activity1, overrideConfig);
assertSame(resources1, theme.getResources());
// Make sure we can still access the data.
assertTrue(theme.resolveAttribute(android.R.attr.windowNoTitle, value, true));
assertEquals(TypedValue.TYPE_INT_BOOLEAN, value.type);
assertTrue(value.data != 0);
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by DirtyUnicorns.
the class BatteryStatsDurationTimerTest method testParceling.
@SmallTest
public void testParceling() throws Exception {
final MockClocks clocks = new MockClocks();
final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase();
timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime());
final BatteryStatsImpl.DurationTimer timer = new BatteryStatsImpl.DurationTimer(clocks, null, BatteryStats.WAKE_TYPE_PARTIAL, null, timeBase);
// Start running on battery.
clocks.realtime = 100;
clocks.uptime = 10;
timeBase.setRunning(true, clocks.uptimeMillis() * 1000, clocks.elapsedRealtime() * 1000);
timer.startRunningLocked(300);
// Check that it did start running
assertEquals(400, timer.getMaxDurationMsLocked(700));
assertEquals(401, timer.getCurrentDurationMsLocked(701));
// Write summary
final Parcel summaryParcel = Parcel.obtain();
timer.writeSummaryFromParcelLocked(summaryParcel, 1500 * 1000);
summaryParcel.setDataPosition(0);
// Read summary
final BatteryStatsImpl.DurationTimer summary = new BatteryStatsImpl.DurationTimer(clocks, null, BatteryStats.WAKE_TYPE_PARTIAL, null, timeBase);
summary.startRunningLocked(3100);
summary.readSummaryFromParcelLocked(summaryParcel);
// The new one shouldn't be running, and therefore 0 for current time
assertFalse(summary.isRunningLocked());
assertEquals(0, summary.getCurrentDurationMsLocked(6300));
// The new one should have the max duration that we had when we wrote it
assertEquals(1200, summary.getMaxDurationMsLocked(6301));
// Write full
final Parcel fullParcel = Parcel.obtain();
timer.writeToParcel(fullParcel, 1500 * 1000);
fullParcel.setDataPosition(0);
// Read full - Should be the same as the summary as far as DurationTimer is concerned.
final BatteryStatsImpl.DurationTimer full = new BatteryStatsImpl.DurationTimer(clocks, null, BatteryStats.WAKE_TYPE_PARTIAL, null, timeBase, fullParcel);
// The new one shouldn't be running, and therefore 0 for current time
assertFalse(full.isRunningLocked());
assertEquals(0, full.getCurrentDurationMsLocked(6300));
// The new one should have the max duration that we had when we wrote it
assertEquals(1200, full.getMaxDurationMsLocked(6301));
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by DirtyUnicorns.
the class BatteryStatsSamplingTimerTest method testSampleTimerSummaryParceling.
@SmallTest
public void testSampleTimerSummaryParceling() throws Exception {
final MockClocks clocks = new MockClocks();
clocks.realtime = 0;
clocks.uptime = 0;
final BatteryStatsImpl.TimeBase timeBase = new BatteryStatsImpl.TimeBase();
timeBase.init(clocks.uptimeMillis(), clocks.elapsedRealtime());
BatteryStatsImpl.SamplingTimer timer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase);
// Start running on battery.
timeBase.setRunning(true, clocks.uptimeMillis(), clocks.elapsedRealtime());
// The first update on battery consumes the values as a way of starting cleanly.
timer.add(10, 1);
timer.add(10, 1);
clocks.realtime = 20;
clocks.uptime = 20;
assertEquals(10, timer.getTotalTimeLocked(clocks.elapsedRealtime(), BatteryStats.STATS_SINCE_CHARGED));
assertEquals(1, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
// Grab a summary parcel while on battery.
final Parcel onBatterySummaryParcel = Parcel.obtain();
timer.writeSummaryFromParcelLocked(onBatterySummaryParcel, clocks.elapsedRealtime() * 1000);
onBatterySummaryParcel.setDataPosition(0);
// Stop running on battery.
timeBase.setRunning(false, clocks.uptimeMillis(), clocks.elapsedRealtime());
assertEquals(10, timer.getTotalTimeLocked(clocks.elapsedRealtime(), BatteryStats.STATS_SINCE_CHARGED));
assertEquals(1, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
// Grab a summary parcel while not on battery.
final Parcel offBatterySummaryParcel = Parcel.obtain();
timer.writeSummaryFromParcelLocked(offBatterySummaryParcel, clocks.elapsedRealtime() * 1000);
offBatterySummaryParcel.setDataPosition(0);
// Set the timebase running again. That way any issues with tracking reported values
// get tested when we unparcel the timers below.
timeBase.setRunning(true, clocks.uptimeMillis(), clocks.elapsedRealtime());
// Read the on battery summary from the parcel.
BatteryStatsImpl.SamplingTimer unparceledOnBatteryTimer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase);
unparceledOnBatteryTimer.readSummaryFromParcelLocked(onBatterySummaryParcel);
assertEquals(10, unparceledOnBatteryTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED));
assertEquals(1, unparceledOnBatteryTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
// Read the off battery summary from the parcel.
BatteryStatsImpl.SamplingTimer unparceledOffBatteryTimer = new BatteryStatsImpl.SamplingTimer(clocks, timeBase);
unparceledOffBatteryTimer.readSummaryFromParcelLocked(offBatterySummaryParcel);
assertEquals(10, unparceledOffBatteryTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED));
assertEquals(1, unparceledOffBatteryTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
// Now, just like with a fresh timer, the first update should be absorbed to account for
// data being collected when we weren't recording.
unparceledOnBatteryTimer.update(10, 10);
assertEquals(10, unparceledOnBatteryTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED));
assertEquals(1, unparceledOnBatteryTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
unparceledOffBatteryTimer.update(10, 10);
assertEquals(10, unparceledOffBatteryTimer.getTotalTimeLocked(0, BatteryStats.STATS_SINCE_CHARGED));
assertEquals(1, unparceledOffBatteryTimer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by DirtyUnicorns.
the class BatteryStatsTimeBaseTest method testSummary.
/**
* Test writeSummaryToParcel and readSummaryFromParcel
*/
@SmallTest
public void testSummary() throws Exception {
TestTimeBase tb1 = new TestTimeBase();
tb1.populate(100, 200, true, 300, 400, 500, 600, 700, 800);
Parcel parcel = Parcel.obtain();
tb1.writeSummaryToParcel(parcel, 666, 6666);
parcel.setDataPosition(0);
TestTimeBase tb2 = new TestTimeBase();
// readSummaryFromParcel doesn't affect the other fields.
// Not sure if this is deliberate
tb2.populate(1, 2, true, 3, 4, 5, 6, 7, 8);
tb2.readSummaryFromParcel(parcel);
tb2.verify(666, 6766, true, 3, 4, 5, 6, 7, 8);
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by DirtyUnicorns.
the class BatteryStatsTimeBaseTest method testDump.
/**
* Test dump
*/
@SmallTest
public void testDump() throws Exception {
TestTimeBase tb = new TestTimeBase();
tb.populate(100, 200, true, 300, 400, 500, 600, 50, 60);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
tb.dump(pw, "+++++ ");
pw.close();
// note the spaces at the ends of the lines which come from formatTimeMs.
final String CORRECT = "+++++ mRunning=true\n" + "+++++ mUptime=0ms \n" + "+++++ mRealtime=0ms \n" + "+++++ mPastUptime=0ms mUptimeStart=0ms mUnpluggedUptime=0ms \n" + "+++++ mPastRealtime=0ms mRealtimeStart=0ms mUnpluggedRealtime=0ms \n";
Assert.assertEquals(CORRECT, sw.toString());
}
Aggregations