Search in sources :

Example 1 with TimeBase

use of com.android.internal.os.BatteryStatsImpl.TimeBase in project platform_frameworks_base by android.

the class BatteryStatsTimerTest method testRunning.

/**
     * Tests that the flow through TimeBase.setRunning propagates through
     * to the timer.
     */
@SmallTest
public void testRunning() throws Exception {
    TimeBase timeBase = new TimeBase();
    MockClocks clocks = new MockClocks();
    TestTimer timer = new TestTimer(clocks, 0, timeBase);
    timer.nextComputeCurrentCount = 3000;
    // Test that starting the timer counts the unplugged time and counters
    timer.nextComputeRunTime = 4;
    timer.onTimeStarted(10, 20, 50);
    Assert.assertEquals(50, timer.lastComputeRunTimeRealtime);
    Assert.assertEquals(4, timer.getUnpluggedTime());
    Assert.assertEquals(3000, timer.getUnpluggedCount());
    // Test that stopping the timer updates mTotalTime and mCount
    timer.nextComputeRunTime = 17;
    timer.onTimeStopped(100, 130, 170);
    Assert.assertEquals(17, timer.getTotalTime());
    Assert.assertEquals(3000, timer.getCount());
}
Also used : TimeBase(com.android.internal.os.BatteryStatsImpl.TimeBase) SmallTest(android.support.test.filters.SmallTest)

Example 2 with TimeBase

use of com.android.internal.os.BatteryStatsImpl.TimeBase in project platform_frameworks_base by android.

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));
}
Also used : TimeBase(com.android.internal.os.BatteryStatsImpl.TimeBase) SmallTest(android.support.test.filters.SmallTest)

Example 3 with TimeBase

use of com.android.internal.os.BatteryStatsImpl.TimeBase in project platform_frameworks_base by android.

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));
}
Also used : TimeBase(com.android.internal.os.BatteryStatsImpl.TimeBase) SmallTest(android.support.test.filters.SmallTest)

Example 4 with TimeBase

use of com.android.internal.os.BatteryStatsImpl.TimeBase in project platform_frameworks_base by android.

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);
}
Also used : TimeBase(com.android.internal.os.BatteryStatsImpl.TimeBase) SmallTest(android.support.test.filters.SmallTest)

Example 5 with TimeBase

use of com.android.internal.os.BatteryStatsImpl.TimeBase in project platform_frameworks_base by android.

the class BatteryStatsTimerTest method testGetTimeSinceMarked.

/**
     * Tests getTimeSinceMarkLocked
     */
@SmallTest
public void testGetTimeSinceMarked() 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;
    Assert.assertEquals(9500, timer.getTimeSinceMarkLocked(666));
}
Also used : TimeBase(com.android.internal.os.BatteryStatsImpl.TimeBase) SmallTest(android.support.test.filters.SmallTest)

Aggregations

SmallTest (android.support.test.filters.SmallTest)45 TimeBase (com.android.internal.os.BatteryStatsImpl.TimeBase)45 Parcel (android.os.Parcel)10 StringBuilderPrinter (android.util.StringBuilderPrinter)5