Search in sources :

Example 36 with SmallTest

use of android.support.test.filters.SmallTest in project android_frameworks_base by crdroidandroid.

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

Example 37 with SmallTest

use of android.support.test.filters.SmallTest in project android_frameworks_base by crdroidandroid.

the class ResourcesLocaleTest method testEnglishIsAlwaysConsideredSupported.

@SmallTest
public void testEnglishIsAlwaysConsideredSupported() throws Exception {
    final Resources resources = createResourcesWithApk(R.raw.locales);
    ensureNoLanguage(resources, "en");
    final LocaleList preferredLocales = LocaleList.forLanguageTags("en-US,pl-PL");
    final Configuration config = new Configuration();
    config.setLocales(preferredLocales);
    resources.updateConfiguration(config, null);
    // The APK we loaded has default and Polish languages. If English is first in the list,
    // always take it the default (assumed to be English).
    assertEquals(Locale.forLanguageTag("en-US"), resources.getConfiguration().getLocales().get(0));
}
Also used : LocaleList(android.os.LocaleList) SmallTest(android.support.test.filters.SmallTest)

Example 38 with SmallTest

use of android.support.test.filters.SmallTest in project android_frameworks_base by crdroidandroid.

the class ResourcesManagerTest method testUpdateConfigurationUpdatesAllAssetManagers.

@SmallTest
public void testUpdateConfigurationUpdatesAllAssetManagers() {
    Resources resources1 = mResourcesManager.getResources(null, APP_ONE_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, null, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
    assertNotNull(resources1);
    Resources resources2 = mResourcesManager.getResources(null, APP_TWO_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, null, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
    assertNotNull(resources2);
    Binder activity = new Binder();
    final Configuration overrideConfig = new Configuration();
    overrideConfig.orientation = Configuration.ORIENTATION_LANDSCAPE;
    Resources resources3 = mResourcesManager.getResources(activity, APP_ONE_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, overrideConfig, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
    assertNotNull(resources3);
    // No Resources object should be the same.
    assertNotSame(resources1, resources2);
    assertNotSame(resources1, resources3);
    assertNotSame(resources2, resources3);
    // Each ResourcesImpl should be different.
    assertNotSame(resources1.getImpl(), resources2.getImpl());
    assertNotSame(resources1.getImpl(), resources3.getImpl());
    assertNotSame(resources2.getImpl(), resources3.getImpl());
    Configuration newConfig = new Configuration();
    newConfig.orientation = Configuration.ORIENTATION_LANDSCAPE;
    mResourcesManager.applyConfigurationToResourcesLocked(newConfig, null);
    final Configuration expectedConfig = new Configuration();
    expectedConfig.setLocales(LocaleList.getAdjustedDefault());
    expectedConfig.densityDpi = mDisplayMetrics.densityDpi;
    expectedConfig.orientation = Configuration.ORIENTATION_LANDSCAPE;
    assertEquals(expectedConfig, resources1.getConfiguration());
    assertEquals(expectedConfig, resources2.getConfiguration());
    assertEquals(expectedConfig, resources3.getConfiguration());
}
Also used : Binder(android.os.Binder) SmallTest(android.support.test.filters.SmallTest)

Example 39 with SmallTest

use of android.support.test.filters.SmallTest in project android_frameworks_base by crdroidandroid.

the class ResourcesManagerTest method testTwoActivitiesWithIdenticalParametersShareImpl.

@SmallTest
public void testTwoActivitiesWithIdenticalParametersShareImpl() {
    Binder activity1 = new Binder();
    Resources resources1 = mResourcesManager.getResources(activity1, APP_ONE_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, null, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
    assertNotNull(resources1);
    Binder activity2 = new Binder();
    Resources resources2 = mResourcesManager.getResources(activity2, APP_ONE_RES_DIR, null, null, null, Display.DEFAULT_DISPLAY, null, CompatibilityInfo.DEFAULT_COMPATIBILITY_INFO, null);
    assertNotNull(resources1);
    // The references themselves should be unique.
    assertNotSame(resources1, resources2);
    // The implementations should be the same.
    assertSame(resources1.getImpl(), resources2.getImpl());
}
Also used : Binder(android.os.Binder) SmallTest(android.support.test.filters.SmallTest)

Example 40 with SmallTest

use of android.support.test.filters.SmallTest in project android_frameworks_base by crdroidandroid.

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)252 Test (org.junit.Test)137 AbstractExistingDBTest (org.liberty.android.fantastischmemo.test.AbstractExistingDBTest)86 Parcel (android.os.Parcel)48 TimeBase (com.android.internal.os.BatteryStatsImpl.TimeBase)45 Card (org.liberty.android.fantastischmemo.entity.Card)43 CardDao (org.liberty.android.fantastischmemo.dao.CardDao)37 Setting (org.liberty.android.fantastischmemo.entity.Setting)21 Binder (android.os.Binder)20 Category (org.liberty.android.fantastischmemo.entity.Category)17 AbstractPreferencesTest (org.liberty.android.fantastischmemo.test.AbstractPreferencesTest)17 LearningData (org.liberty.android.fantastischmemo.entity.LearningData)15 UiThreadTest (android.support.test.annotation.UiThreadTest)14 CategoryDao (org.liberty.android.fantastischmemo.dao.CategoryDao)13 LocaleList (android.os.LocaleList)10 Option (org.liberty.android.fantastischmemo.entity.Option)9 QueueManager (org.liberty.android.fantastischmemo.queue.QueueManager)9 ContentResolver (android.content.ContentResolver)8 Cursor (android.database.Cursor)8 OnTickListener (com.tmall.wireless.tangram.support.TimerSupport.OnTickListener)8