use of android.support.test.filters.SmallTest in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
the class BatteryStatsServTest method testParceling.
/**
* Test parceling and unparceling.
*/
@SmallTest
public void testParceling() throws Exception {
MockBatteryStatsImpl bsi = new MockBatteryStatsImpl();
TestServ orig = new TestServ(bsi);
orig.populate();
Parcel parcel = Parcel.obtain();
orig.writeToParcelLocked(parcel);
parcel.setDataPosition(0);
TestServ serv = new TestServ(bsi);
serv.readFromParcelLocked(parcel);
Assert.assertEquals(1010, serv.getStartTime());
Assert.assertEquals(2021, serv.getRunningSince());
Assert.assertTrue(serv.getRunning());
Assert.assertEquals(4042, serv.getStarts());
Assert.assertEquals(5053, serv.getLaunchedTime());
Assert.assertEquals(6064, serv.getLaunchedSince());
Assert.assertTrue(serv.getLaunched());
Assert.assertEquals(8085, serv.getLaunches());
Assert.assertEquals(9096, serv.getLoadedStartTime());
Assert.assertEquals(10017, serv.getLoadedStarts());
Assert.assertEquals(11118, serv.getLoadedLaunches());
Assert.assertEquals(0, serv.getLastStartTime());
Assert.assertEquals(0, serv.getLastStarts());
Assert.assertEquals(0, serv.getLastLaunches());
Assert.assertEquals(15512, serv.getUnpluggedStartTime());
Assert.assertEquals(16613, serv.getUnpluggedStarts());
Assert.assertEquals(17714, serv.getUnpluggedLaunches());
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by ResurrectionRemix.
the class BatteryStatsTimeBaseTest method testParcellingWhileNotRunning.
/**
* Test writeToParcel and readFromParcel
*/
@SmallTest
public void testParcellingWhileNotRunning() throws Exception {
TestTimeBase tb1 = new TestTimeBase();
tb1.populate(100, 200, false, 300, 400, 500, 600, 700, 800);
Parcel parcel = Parcel.obtain();
tb1.writeToParcel(parcel, 666, 6666);
parcel.setDataPosition(0);
TestTimeBase tb2 = new TestTimeBase();
tb2.readFromParcel(parcel);
tb2.verify(100, 200, false, 300, 400, 500, 600, 700, 800);
}
use of android.support.test.filters.SmallTest in project android_frameworks_base by ResurrectionRemix.
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 ResourcesManagerTest method testMultipleResourcesForOneActivityGetUpdatedWhenActivityBaseUpdates.
@SmallTest
public void testMultipleResourcesForOneActivityGetUpdatedWhenActivityBaseUpdates() {
Binder activity1 = new Binder();
// Create a Resources for the Activity.
Configuration config1 = new Configuration();
config1.densityDpi = 280;
Resources resources1 = mResourcesManager.createBaseActivityResources(activity1, APP_ONE_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, config1, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
assertNotNull(resources1);
// Create a Resources based on the Activity.
Configuration config2 = new Configuration();
config2.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
Resources resources2 = mResourcesManager.getResources(activity1, APP_ONE_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, config2, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
assertNotNull(resources2);
assertNotSame(resources1, resources2);
assertNotSame(resources1.getImpl(), resources2.getImpl());
final Configuration expectedConfig1 = new Configuration();
expectedConfig1.setLocales(LocaleList.getAdjustedDefault());
expectedConfig1.densityDpi = 280;
assertEquals(expectedConfig1, resources1.getConfiguration());
// resources2 should be based on the Activity's override config, so the density should
// be the same as resources1.
final Configuration expectedConfig2 = new Configuration();
expectedConfig2.setLocales(LocaleList.getAdjustedDefault());
expectedConfig2.densityDpi = 280;
expectedConfig2.screenLayout |= Configuration.SCREENLAYOUT_ROUND_YES;
assertEquals(expectedConfig2, resources2.getConfiguration());
// Now update the Activity base override, and both resources should update.
config1.orientation = Configuration.ORIENTATION_LANDSCAPE;
mResourcesManager.updateResourcesForActivity(activity1, config1);
expectedConfig1.orientation = Configuration.ORIENTATION_LANDSCAPE;
assertEquals(expectedConfig1, resources1.getConfiguration());
expectedConfig2.orientation = Configuration.ORIENTATION_LANDSCAPE;
assertEquals(expectedConfig2, resources2.getConfiguration());
}
Aggregations