aboutsummaryrefslogtreecommitdiff
path: root/library/tests/src/com/bumptech/glide/LruBitmapPoolTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'library/tests/src/com/bumptech/glide/LruBitmapPoolTest.java')
-rw-r--r--library/tests/src/com/bumptech/glide/LruBitmapPoolTest.java162
1 files changed, 0 insertions, 162 deletions
diff --git a/library/tests/src/com/bumptech/glide/LruBitmapPoolTest.java b/library/tests/src/com/bumptech/glide/LruBitmapPoolTest.java
deleted file mode 100644
index 767403ef..00000000
--- a/library/tests/src/com/bumptech/glide/LruBitmapPoolTest.java
+++ /dev/null
@@ -1,162 +0,0 @@
-package com.bumptech.glide;
-
-import android.content.ComponentCallbacks2;
-import android.graphics.Bitmap;
-import android.test.AndroidTestCase;
-import com.bumptech.glide.resize.bitmap_recycle.LruBitmapPool;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class LruBitmapPoolTest extends AndroidTestCase {
- private static final int SIZE = 1024 * 1024;
- private LruBitmapPool pool;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- pool = new LruBitmapPool(SIZE);
- }
-
- public void testCanAddAndRemoveBitmap() {
- Bitmap bitmap = getBitmap();
- pool.put(bitmap);
- assertEquals(bitmap, getEquivalentFromPool(bitmap));
- }
-
- public void testCanAddAndRemoveBitmapsOfDifferentSizes() {
- Bitmap first = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
- Bitmap second = Bitmap.createBitmap(100, 200, Bitmap.Config.ARGB_8888);
- pool.put(first);
- pool.put(second);
- assertEquals(first, getEquivalentFromPool(first));
- assertEquals(second, getEquivalentFromPool(second));
- }
-
- public void testCanAddAndRemoveBitmapsOfDifferentConfigs() {
- Bitmap first = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
- Bitmap second = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
- pool.put(first);
- pool.put(second);
- assertEquals(first, getEquivalentFromPool(first));
- assertEquals(second, getEquivalentFromPool(second));
- }
-
- public void testPoolIsSizeLimited() {
- List<Bitmap> bitmaps = fillPool();
- Bitmap first = bitmaps.get(0);
- pool.put(Bitmap.createBitmap(first));
-
- int totalInPool = 0;
- for (int i = 0; i < bitmaps.size(); i++) {
- if (getEquivalentFromPool(first) == null) {
- break;
- }
- totalInPool++;
- }
-
- assertEquals(bitmaps.size(), totalInPool);
- }
-
- public void testLeastRecentlyAcquiredBitmapRemovedFirst() {
- Bitmap special = Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565);
- pool.put(Bitmap.createBitmap(special));
- pool.put(Bitmap.createBitmap(special));
- getEquivalentFromPool(special);
- List<Bitmap> bitmaps = fillPool();
-
- assertNotNull(getEquivalentFromPool(special));
-
- Bitmap first = bitmaps.get(0);
- int totalAcquired = 0;
- for (int i = 0; i < bitmaps.size(); i++) {
- if (getEquivalentFromPool(first) == null) {
- break;
- }
- totalAcquired++;
- }
-
- assertEquals(totalAcquired, bitmaps.size() - 1);
- }
-
- public void testTrimMemoryCompleteClearsPool() {
- doTestTrimMemory(ComponentCallbacks2.TRIM_MEMORY_COMPLETE, false);
- }
-
- public void testTrimMemoryModerateClearsPool() {
- doTestTrimMemory(ComponentCallbacks2.TRIM_MEMORY_MODERATE, false);
- }
-
- public void testTrimMemoryBackgroundRemovesHalf() {
- doTestTrimMemory(ComponentCallbacks2.TRIM_MEMORY_BACKGROUND, true);
- }
-
- private void doTestTrimMemory(int level, boolean half) {
- List<Bitmap> bitmaps = fillPool();
- Bitmap first = bitmaps.get(0);
- assertTrue(bitmaps.size() >= 2);
-
- Bitmap fromPool = getEquivalentFromPool(first);
- assertNotNull(fromPool);
- pool.put(fromPool);
- pool.trimMemory(level);
- if (half) {
- for (int i = 0; i < bitmaps.size() / 2; i++) {
- assertNotNull(getEquivalentFromPool(first));
- }
- }
- assertNull(getEquivalentFromPool(first));
- }
-
- public void testClearMemoryRemovesAllBitmaps() {
- List<Bitmap> bitmaps = fillPool();
- assertTrue(bitmaps.size() >= 2);
-
- Bitmap first = bitmaps.get(0);
- assertNotNull(getEquivalentFromPool(first));
- pool.clearMemory();
- assertNull(getEquivalentFromPool(first));
- }
-
- public void testTrimMemoryCallsRecycleOnRemovedBitmaps() {
- List<Bitmap> bitmaps = fillPool();
- pool.trimMemory(ComponentCallbacks2.TRIM_MEMORY_COMPLETE);
- for (Bitmap bitmap : bitmaps) {
- assertTrue(bitmap.isRecycled());
- }
- }
-
- public void testClearMemoryCallsRecycleOnRemovedBitmaps() {
- List<Bitmap> bitmaps = fillPool();
- pool.clearMemory();
- for (Bitmap bitmap : bitmaps) {
- assertTrue(bitmap.isRecycled());
- }
- }
-
- public List<Bitmap> fillPool() {
- List<Bitmap> bitmaps = new ArrayList<Bitmap>();
- Bitmap toPut = getBitmap();
- int bitmapSize = getSize(toPut);
- for (int i = 0; i < (SIZE / bitmapSize); i++) {
- bitmaps.add(Bitmap.createBitmap(toPut));
- }
- for (Bitmap bitmap : bitmaps) {
- pool.put(bitmap);
- }
- assertTrue(bitmaps.size() > 0);
- return bitmaps;
- }
-
- private Bitmap getEquivalentFromPool(Bitmap bitmap) {
- return pool.get(bitmap.getWidth(), bitmap.getHeight(), bitmap.getConfig());
- }
-
- private static int getSize(Bitmap bitmap) {
- return bitmap.getRowBytes() * bitmap.getHeight();
- }
-
- private static Bitmap getBitmap() {
- return Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
- }
-}