@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 testCumulativePoolAndMemoryCacheSizesAreSmallerOnLowMemoryDevices() { Shadows.shadowOf(harness.activityManager).setMemoryClass(getLargeEnoughMemoryClass() / 2); final int normalMemoryCacheSize = harness.getCalculator().getMemoryCacheSize(); final int normalBitmapPoolSize = harness.getCalculator().getBitmapPoolSize(); Util.setSdkVersionInt(10); // Keep the bitmap pool size constant, even though normally it would change. harness.byteArrayPoolSizeBytes *= 2; final int smallMemoryCacheSize = harness.getCalculator().getMemoryCacheSize(); final int smallBitmapPoolSize = harness.getCalculator().getBitmapPoolSize(); assertThat(smallMemoryCacheSize).isLessThan(normalMemoryCacheSize); assertThat(smallBitmapPoolSize).isLessThan(normalBitmapPoolSize); }
@Test public void testByteArrayPoolSize_withLowRamDevice_isHalfTheSpecifiedBytes() { LowRamActivityManager activityManager = Shadow.extract(harness.activityManager); activityManager.setMemoryClass(getLargeEnoughMemoryClass()); activityManager.setIsLowRam(); int byteArrayPoolSize = harness.getCalculator().getArrayPoolSizeInBytes(); assertThat(byteArrayPoolSize).isEqualTo(harness.byteArrayPoolSizeBytes / 2); }
@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 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 testDefaultBitmapPoolSize() { Shadows.shadowOf(harness.activityManager).setMemoryClass(getLargeEnoughMemoryClass()); float bitmapPoolSize = harness.getCalculator().getBitmapPoolSize(); assertThat(bitmapPoolSize).isEqualTo(harness.getScreenSize() * harness.bitmapPoolScreens); }