use of android.support.test.filters.SmallTest in project android_frameworks_base by DirtyUnicorns.
the class BatteryStatsTimerTest method testResetNoDetach.
/**
* Tests that reset() clears the correct times.
*/
@SmallTest
public void testResetNoDetach() throws Exception {
TimeBase timeBase = new TimeBase();
MockClocks clocks = new MockClocks();
TestTimer timer = new TestTimer(clocks, 0, timeBase);
timer.setCount(1);
timer.setLoadedCount(2);
timer.setLastCount(3);
timer.setUnpluggedCount(4);
timer.setTotalTime(9223372036854775807L);
timer.setLoadedTime(9223372036854775806L);
timer.setLastTime(9223372036854775805L);
timer.setUnpluggedTime(9223372036854775804L);
timer.setTimeBeforeMark(9223372036854775803L);
timer.reset(false);
Assert.assertEquals(0, timer.getCount());
Assert.assertEquals(0, timer.getLoadedCount());
Assert.assertEquals(0, timer.getLastCount());
Assert.assertEquals(4, timer.getUnpluggedCount());
Assert.assertEquals(0, timer.getTotalTime());
Assert.assertEquals(0, timer.getLoadedTime());
Assert.assertEquals(0, timer.getLastTime());
Assert.assertEquals(9223372036854775804L, timer.getUnpluggedTime());
Assert.assertEquals(0, timer.getTimeBeforeMark());
// reset(false) shouldn't remove it from the list
Assert.assertEquals(true, timeBase.hasObserver(timer));
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by DirtyUnicorns.
the class BatteryStatsTimerTest method testSummaryParceling.
/**
* Tests reading and writing the summary to a parcel
*/
@SmallTest
public void testSummaryParceling() throws Exception {
TimeBase timeBase = new TimeBase();
timeBase.setRunning(true, 10, 20);
timeBase.setRunning(false, 45, 60);
Assert.assertEquals(40, timeBase.getRealtime(200));
// the past uptime is 35 and the past runtime is 40
MockClocks clocks = new MockClocks();
TestTimer timer1 = new TestTimer(clocks, 0, timeBase);
timer1.setCount(1);
timer1.setLoadedCount(2);
timer1.setLastCount(3);
timer1.setUnpluggedCount(4);
timer1.setTotalTime(9223372036854775807L);
timer1.setLoadedTime(9223372036854775806L);
timer1.setLastTime(9223372036854775805L);
timer1.setUnpluggedTime(9223372036854775804L);
timer1.setTimeBeforeMark(9223372036854775803L);
Parcel parcel = Parcel.obtain();
timer1.nextComputeRunTime = 9223372036854775800L;
timer1.nextComputeCurrentCount = 1;
timer1.writeSummaryFromParcelLocked(parcel, 201);
Assert.assertEquals(40, timer1.lastComputeRunTimeRealtime);
TestTimer timer2 = new TestTimer(clocks, 0, timeBase);
// Make sure that all the values get touched
timer2.setCount(666);
timer2.setLoadedCount(666);
timer2.setLastCount(666);
timer2.setUnpluggedCount(666);
timer2.setTotalTime(666);
timer2.setLoadedTime(666);
timer2.setLastTime(666);
timer2.setUnpluggedTime(666);
timer2.setTimeBeforeMark(666);
parcel.setDataPosition(0);
parcel.setDataPosition(0);
timer2.readSummaryFromParcelLocked(parcel);
Assert.assertEquals(1, timer2.getCount());
Assert.assertEquals(1, timer2.getLoadedCount());
Assert.assertEquals(0, timer2.getLastCount());
Assert.assertEquals(1, timer2.getUnpluggedCount());
Assert.assertEquals(9223372036854775800L, timer2.getTotalTime());
Assert.assertEquals(9223372036854775800L, timer2.getLoadedTime());
Assert.assertEquals(0, timer2.getLastTime());
Assert.assertEquals(9223372036854775800L, timer2.getUnpluggedTime());
Assert.assertEquals(9223372036854775800L, timer2.getTimeBeforeMark());
parcel.recycle();
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by DirtyUnicorns.
the class BatteryStatsTimerTest method testGetCountLocked.
/**
* Tests getCountLocked
*/
@SmallTest
public void testGetCountLocked() throws Exception {
TimeBase timeBase = new TimeBase();
timeBase.setRunning(true, 10, 20);
timeBase.setRunning(false, 45, 60);
Assert.assertEquals(40, timeBase.getRealtime(200));
MockClocks clocks = new MockClocks();
TestTimer timer = new TestTimer(clocks, 0, timeBase);
timer.setCount(1);
timer.setLoadedCount(2);
timer.setLastCount(3);
timer.setUnpluggedCount(4);
timer.setTotalTime(100);
timer.setLoadedTime(200);
timer.setLastTime(300);
timer.setUnpluggedTime(400);
timer.setTimeBeforeMark(500);
// Timer.getCountLocked(STATS_SINCE_CHARGED)
timer.nextComputeCurrentCount = 10000;
Assert.assertEquals(10000, timer.getCountLocked(BatteryStats.STATS_SINCE_CHARGED));
// Timer.getCountLocked(STATS_CURRENT)
timer.nextComputeCurrentCount = 10000;
Assert.assertEquals(9998, timer.getCountLocked(BatteryStats.STATS_CURRENT));
// Timer.getCountLocked(STATS_SINCE_UNPLUGGED)
timer.nextComputeCurrentCount = 10000;
Assert.assertEquals(9996, timer.getCountLocked(BatteryStats.STATS_SINCE_UNPLUGGED));
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by DirtyUnicorns.
the class BatteryStatsTimerTest method testGetTotalTimeLocked.
/**
* Tests getTotalTimeLocked
*/
@SmallTest
public void testGetTotalTimeLocked() throws Exception {
TimeBase timeBase = new TimeBase();
timeBase.setRunning(true, 10, 20);
timeBase.setRunning(false, 45, 60);
Assert.assertEquals(40, timeBase.getRealtime(200));
MockClocks clocks = new MockClocks();
TestTimer timer = new TestTimer(clocks, 0, timeBase);
timer.setCount(1);
timer.setLoadedCount(2);
timer.setLastCount(3);
timer.setUnpluggedCount(4);
timer.setTotalTime(100);
timer.setLoadedTime(200);
timer.setLastTime(300);
timer.setUnpluggedTime(400);
timer.setTimeBeforeMark(500);
timer.nextComputeRunTime = 10000;
// Timer.getTotalTimeLocked(STATS_SINCE_CHARGED)
timer.lastComputeRunTimeRealtime = -1;
Assert.assertEquals(10000, timer.getTotalTimeLocked(66, BatteryStats.STATS_SINCE_CHARGED));
Assert.assertEquals(40, timer.lastComputeRunTimeRealtime);
// Timer.getTotalTimeLocked(STATS_CURRENT)
timer.lastComputeRunTimeRealtime = -1;
Assert.assertEquals(9800, timer.getTotalTimeLocked(66, BatteryStats.STATS_CURRENT));
Assert.assertEquals(40, timer.lastComputeRunTimeRealtime);
// Timer.getTotalTimeLocked(STATS_SINCE_UNPLUGGED)
timer.lastComputeRunTimeRealtime = -1;
Assert.assertEquals(9600, timer.getTotalTimeLocked(66, BatteryStats.STATS_SINCE_UNPLUGGED));
Assert.assertEquals(40, timer.lastComputeRunTimeRealtime);
}
use of android.support.test.filters.SmallTest in project platform_frameworks_base by android.
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));
}
Aggregations