Search in sources :

Example 36 with TimeBase

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

the class BatteryStatsTimerTest method testParceling.

/**
     * Tests that the parcel can be parceled and unparceled without losing anything.
     */
@SmallTest
public void testParceling() throws Exception {
    TimeBase timeBase = new TimeBase();
    MockClocks clocks = new MockClocks();
    // Test write then read
    TestTimer timer1 = new TestTimer(clocks, 0, timeBase);
    timer1.setCount(1);
    timer1.setLoadedCount(3);
    timer1.setLastCount(4);
    timer1.setUnpluggedCount(5);
    timer1.setTotalTime(9223372036854775807L);
    timer1.setLoadedTime(9223372036854775806L);
    timer1.setLastTime(9223372036854775805L);
    timer1.setUnpluggedTime(9223372036854775804L);
    timer1.setTimeBeforeMark(9223372036854775803L);
    timer1.nextComputeRunTime = 201;
    timer1.nextComputeCurrentCount = 2;
    Parcel parcel = Parcel.obtain();
    Timer.writeTimerToParcel(parcel, timer1, 77);
    parcel.setDataPosition(0);
    Assert.assertTrue("parcel null object", parcel.readInt() != 0);
    TestTimer timer2 = new TestTimer(clocks, 0, timeBase, parcel);
    // from computeTotalCountLocked()
    Assert.assertEquals(2, timer2.getCount());
    Assert.assertEquals(3, timer2.getLoadedCount());
    // NOT saved
    Assert.assertEquals(0, timer2.getLastCount());
    Assert.assertEquals(5, timer2.getUnpluggedCount());
    // from computeRunTimeLocked()
    Assert.assertEquals(201, timer2.getTotalTime());
    Assert.assertEquals(9223372036854775806L, timer2.getLoadedTime());
    // NOT saved
    Assert.assertEquals(0, timer2.getLastTime());
    Assert.assertEquals(9223372036854775804L, timer2.getUnpluggedTime());
    Assert.assertEquals(9223372036854775803L, timer2.getTimeBeforeMark());
    parcel.recycle();
}
Also used : Parcel(android.os.Parcel) TimeBase(com.android.internal.os.BatteryStatsImpl.TimeBase) SmallTest(android.support.test.filters.SmallTest)

Example 37 with TimeBase

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

the class BatteryStatsTimerTest method testResetDetach.

/**
     * Tests that reset() clears the correct times.
     */
@SmallTest
public void testResetDetach() 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(true);
    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(true) should remove it from the list
    Assert.assertEquals(false, timeBase.hasObserver(timer));
}
Also used : TimeBase(com.android.internal.os.BatteryStatsImpl.TimeBase) SmallTest(android.support.test.filters.SmallTest)

Example 38 with TimeBase

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

the class BatteryStatsTimerTest method testLogState.

/**
     * Tests logState
     */
@SmallTest
public void testLogState() throws Exception {
    TimeBase timeBase = new TimeBase();
    MockClocks clocks = new MockClocks();
    TestTimer timer = new TestTimer(clocks, 0, timeBase);
    timer.setTotalTime(100);
    timer.setLoadedTime(200);
    timer.setLastTime(300);
    timer.setUnpluggedTime(400);
    timer.setTimeBeforeMark(500);
    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);
    StringBuilder sb = new StringBuilder();
    StringBuilderPrinter pw = new StringBuilderPrinter(sb);
    timer.logState(pw, "  ");
    Assert.assertEquals("  mCount=1 mLoadedCount=2 mLastCount=3 mUnpluggedCount=4\n" + "  mTotalTime=9223372036854775807 mLoadedTime=9223372036854775806\n" + "  mLastTime=9223372036854775805 mUnpluggedTime=9223372036854775804\n", sb.toString());
}
Also used : StringBuilderPrinter(android.util.StringBuilderPrinter) TimeBase(com.android.internal.os.BatteryStatsImpl.TimeBase) SmallTest(android.support.test.filters.SmallTest)

Example 39 with TimeBase

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

the class BatteryStatsTimerTest method testParceling.

/**
     * Tests that the parcel can be parceled and unparceled without losing anything.
     */
@SmallTest
public void testParceling() throws Exception {
    TimeBase timeBase = new TimeBase();
    MockClocks clocks = new MockClocks();
    // Test write then read
    TestTimer timer1 = new TestTimer(clocks, 0, timeBase);
    timer1.setCount(1);
    timer1.setLoadedCount(3);
    timer1.setLastCount(4);
    timer1.setUnpluggedCount(5);
    timer1.setTotalTime(9223372036854775807L);
    timer1.setLoadedTime(9223372036854775806L);
    timer1.setLastTime(9223372036854775805L);
    timer1.setUnpluggedTime(9223372036854775804L);
    timer1.setTimeBeforeMark(9223372036854775803L);
    timer1.nextComputeRunTime = 201;
    timer1.nextComputeCurrentCount = 2;
    Parcel parcel = Parcel.obtain();
    Timer.writeTimerToParcel(parcel, timer1, 77);
    parcel.setDataPosition(0);
    Assert.assertTrue("parcel null object", parcel.readInt() != 0);
    TestTimer timer2 = new TestTimer(clocks, 0, timeBase, parcel);
    // from computeTotalCountLocked()
    Assert.assertEquals(2, timer2.getCount());
    Assert.assertEquals(3, timer2.getLoadedCount());
    // NOT saved
    Assert.assertEquals(0, timer2.getLastCount());
    Assert.assertEquals(5, timer2.getUnpluggedCount());
    // from computeRunTimeLocked()
    Assert.assertEquals(201, timer2.getTotalTime());
    Assert.assertEquals(9223372036854775806L, timer2.getLoadedTime());
    // NOT saved
    Assert.assertEquals(0, timer2.getLastTime());
    Assert.assertEquals(9223372036854775804L, timer2.getUnpluggedTime());
    Assert.assertEquals(9223372036854775803L, timer2.getTimeBeforeMark());
    parcel.recycle();
}
Also used : Parcel(android.os.Parcel) TimeBase(com.android.internal.os.BatteryStatsImpl.TimeBase) SmallTest(android.support.test.filters.SmallTest)

Example 40 with TimeBase

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

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)

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