private int getLargeEnoughMemoryClass() { float totalScreenBytes = harness.getScreenSize() * (harness.bitmapPoolScreens + harness.memoryCacheScreens); float totalBytes = totalScreenBytes + harness.byteArrayPoolSizeBytes; // Memory class is in mb, not bytes! float totalMb = totalBytes / (1024 * 1024); float memoryClassMb = totalMb / harness.sizeMultiplier; return (int) Math.ceil(memoryClassMb); }
@Test public void testDefaultBitmapPoolSizeIsLimitedByMemoryClass() { final int memoryClassBytes = Math.round(harness.getScreenSize() * harness.bitmapPoolScreens * harness.sizeMultiplier); Shadows.shadowOf(harness.activityManager).setMemoryClass(memoryClassBytes / (1024 * 1024)); int bitmapPoolSize = harness.getCalculator().getBitmapPoolSize(); assertThat((float) bitmapPoolSize) .isIn(Range.atMost(memoryClassBytes * harness.sizeMultiplier)); }
@Test public void testDefaultMemoryCacheSizeIsLimitedByMemoryClass() { final int memoryClassBytes = Math.round(harness.getScreenSize() * harness.memoryCacheScreens * harness.sizeMultiplier); Shadows.shadowOf(harness.activityManager).setMemoryClass(memoryClassBytes / (1024 * 1024)); float memoryCacheSize = harness.getCalculator().getMemoryCacheSize(); assertThat(memoryCacheSize) .isIn(Range.atMost(memoryClassBytes * harness.sizeMultiplier)); }
@Test public void testCumulativePoolAndMemoryCacheSizeAreLimitedByMemoryClass() { final int memoryClassBytes = Math.round( harness.getScreenSize() * (harness.bitmapPoolScreens + harness.memoryCacheScreens) * harness.sizeMultiplier); Shadows.shadowOf(harness.activityManager).setMemoryClass(memoryClassBytes / (1024 * 1024)); int memoryCacheSize = harness.getCalculator().getMemoryCacheSize(); int bitmapPoolSize = harness.getCalculator().getBitmapPoolSize(); assertThat((float) memoryCacheSize + bitmapPoolSize) .isIn(Range.atMost(memoryClassBytes * harness.sizeMultiplier)); }
@Test public void testCanSetCustomMemoryCacheSize() { harness.memoryCacheScreens = 9.5f; Shadows.shadowOf(harness.activityManager).setMemoryClass(getLargeEnoughMemoryClass()); float memoryCacheSize = harness.getCalculator().getMemoryCacheSize(); assertThat(memoryCacheSize).isEqualTo(harness.getScreenSize() * harness.memoryCacheScreens); }
@Test public void testCanSetCustomBitmapPoolSize() { harness.bitmapPoolScreens = 2f; Shadows.shadowOf(harness.activityManager).setMemoryClass(getLargeEnoughMemoryClass()); float bitmapPoolSize = harness.getCalculator().getBitmapPoolSize(); assertThat(bitmapPoolSize).isEqualTo(harness.getScreenSize() * harness.bitmapPoolScreens); }
@Test public void testDefaultMemoryCacheSizeIsTwiceScreenSize() { Shadows.shadowOf(harness.activityManager).setMemoryClass(getLargeEnoughMemoryClass()); float memoryCacheSize = harness.getCalculator().getMemoryCacheSize(); assertThat(memoryCacheSize).isEqualTo(harness.getScreenSize() * harness.memoryCacheScreens); }
@Test public void testDefaultBitmapPoolSize() { Shadows.shadowOf(harness.activityManager).setMemoryClass(getLargeEnoughMemoryClass()); float bitmapPoolSize = harness.getCalculator().getBitmapPoolSize(); assertThat(bitmapPoolSize).isEqualTo(harness.getScreenSize() * harness.bitmapPoolScreens); }