• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.tv.util;
2 
3 import android.graphics.Bitmap;
4 import android.test.AndroidTestCase;
5 import android.test.suitebuilder.annotation.SmallTest;
6 
7 import com.android.tv.util.BitmapUtils.ScaledBitmapInfo;
8 
9 /**
10  * Tests for {@link ScaledBitmapInfo}.
11  */
12 @SmallTest
13 public class ScaledBitmapInfoTest extends AndroidTestCase {
14     private static final Bitmap B80x100 = Bitmap.createBitmap(80, 100, Bitmap.Config.RGB_565);
15     private static final Bitmap B960x1440 = Bitmap.createBitmap(960, 1440, Bitmap.Config.RGB_565);
16 
testSize_B100x100to50x50()17     public void testSize_B100x100to50x50() {
18         ScaledBitmapInfo actual = BitmapUtils.createScaledBitmapInfo("B80x100", B80x100, 50, 50);
19         assertScaledBitmapSize(2, 40, 50, actual);
20     }
21 
testNeedsToReload_B100x100to50x50()22     public void testNeedsToReload_B100x100to50x50() {
23         ScaledBitmapInfo actual = BitmapUtils.createScaledBitmapInfo("B80x100", B80x100, 50, 50);
24         assertNeedsToReload(false, actual, 25, 25);
25         assertNeedsToReload(false, actual, 50, 50);
26         assertNeedsToReload(false, actual, 99, 99);
27         assertNeedsToReload(true, actual, 100, 100);
28         assertNeedsToReload(true, actual, 101, 101);
29     }
30 
31     /**
32      * Reproduces <a href="http://b/20488453">b/20488453</a>.
33      */
testBug20488453()34     public void testBug20488453() {
35         ScaledBitmapInfo actual = BitmapUtils
36                 .createScaledBitmapInfo("B960x1440", B960x1440, 284, 160);
37         assertScaledBitmapSize(8, 107, 160, actual);
38         assertNeedsToReload(false, actual, 284, 160);
39     }
40 
assertNeedsToReload(boolean expected, ScaledBitmapInfo scaledBitmap, int reqWidth, int reqHeight)41     private static void assertNeedsToReload(boolean expected, ScaledBitmapInfo scaledBitmap,
42             int reqWidth, int reqHeight) {
43         assertEquals(scaledBitmap.id + " needToReload(" + reqWidth + "," + reqHeight + ")",
44                 expected, scaledBitmap.needToReload(reqWidth, reqHeight));
45     }
46 
assertScaledBitmapSize(int expectedInSampleSize, int expectedWidth, int expectedHeight, ScaledBitmapInfo actual)47     private static void assertScaledBitmapSize(int expectedInSampleSize, int expectedWidth,
48             int expectedHeight, ScaledBitmapInfo actual) {
49         assertEquals(actual.id + " inSampleSize", expectedInSampleSize, actual.inSampleSize);
50         assertEquals(actual.id + " width", expectedWidth, actual.bitmap.getWidth());
51         assertEquals(actual.id + " height", expectedHeight, actual.bitmap.getHeight());
52     }
53 }
54