Esempio n. 1
0
  @Test
  public void createShouldSetSizeToValueFromMapAsFirstPriority() {
    ShadowBitmapFactory.provideWidthAndHeightHints("image.png", 111, 222);

    final Bitmap bitmap = ShadowBitmapFactory.create("file:image.png", null, new Point(50, 60));

    assertThat(bitmap.getWidth()).isEqualTo(111);
    assertThat(bitmap.getHeight()).isEqualTo(222);
  }
Esempio n. 2
0
  @Test
  public void createShouldSetSizeToParameterAsSecondPriority() {
    final Bitmap bitmap = ShadowBitmapFactory.create(null, null, new Point(70, 80));

    assertThat(bitmap.getWidth()).isEqualTo(70);
    assertThat(bitmap.getHeight()).isEqualTo(80);
  }
Esempio n. 3
0
  @Test
  public void createShouldSetSizeToHardcodedValueAsLastPriority() {
    final Bitmap bitmap = ShadowBitmapFactory.create(null, null, null);

    assertThat(bitmap.getWidth()).isEqualTo(100);
    assertThat(bitmap.getHeight()).isEqualTo(100);
  }
Esempio n. 4
0
  @Test
  public void decodeFileEtc_shouldSetOptionsOutWidthAndOutHeightFromHints() throws Exception {
    ShadowBitmapFactory.provideWidthAndHeightHints("/some/file.jpg", 123, 456);

    BitmapFactory.Options options = new BitmapFactory.Options();
    BitmapFactory.decodeFile("/some/file.jpg", options);
    assertEquals(123, options.outWidth);
    assertEquals(456, options.outHeight);
  }
Esempio n. 5
0
  @Test
  public void decodeFile_shouldGetWidthAndHeightFromHints() throws Exception {
    ShadowBitmapFactory.provideWidthAndHeightHints("/some/file.jpg", 123, 456);

    Bitmap bitmap = BitmapFactory.decodeFile("/some/file.jpg");
    assertEquals("Bitmap for file:/some/file.jpg", shadowOf(bitmap).getDescription());
    assertEquals(123, bitmap.getWidth());
    assertEquals(456, bitmap.getHeight());
  }
Esempio n. 6
0
  @Test
  public void decodeByteArray_shouldIncludeOffsets() throws Exception {
    String data = "arbitrary bytes";
    ShadowBitmapFactory.provideWidthAndHeightHints(Uri.parse(data), 123, 456);

    byte[] bytes = data.getBytes();
    Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 1, bytes.length - 2);
    assertEquals("Bitmap for " + data + " bytes 1..13", shadowOf(bitmap).getDescription());
  }
Esempio n. 7
0
  @Test
  public void decodeResource_shouldGetWidthAndHeightFromHints() throws Exception {
    ShadowBitmapFactory.provideWidthAndHeightHints(R.drawable.an_image, 123, 456);

    Bitmap bitmap =
        BitmapFactory.decodeResource(Robolectric.application.getResources(), R.drawable.an_image);
    assertEquals("Bitmap for resource:drawable/an_image", shadowOf(bitmap).getDescription());
    assertEquals(123, bitmap.getWidth());
    assertEquals(456, bitmap.getHeight());
  }
Esempio n. 8
0
 public static void resetStaticState() {
   ShadowWrangler.getInstance().silence();
   Robolectric.application = new Application();
   ShadowBitmapFactory.reset();
   ShadowDrawable.reset();
   ShadowMediaStore.reset();
   ShadowLog.reset();
   ShadowContext.clearFilesAndCache();
   ShadowLooper.resetThreadLoopers();
 }
Esempio n. 9
0
  @Test
  public void decodeByteArray_shouldGetWidthAndHeightFromHints() throws Exception {
    String data = "arbitrary bytes";
    ShadowBitmapFactory.provideWidthAndHeightHints(Uri.parse(data), 123, 456);

    byte[] bytes = data.getBytes();
    Bitmap bitmap = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
    assertEquals("Bitmap for " + data, shadowOf(bitmap).getDescription());
    assertEquals(123, bitmap.getWidth());
    assertEquals(456, bitmap.getHeight());
  }
Esempio n. 10
0
  @Test
  public void decodeUri_shouldGetWidthAndHeightFromHints() throws Exception {
    ShadowBitmapFactory.provideWidthAndHeightHints(Uri.parse("content:/path"), 123, 456);

    Bitmap bitmap =
        MediaStore.Images.Media.getBitmap(
            Robolectric.application.getContentResolver(), Uri.parse("content:/path"));
    assertEquals("Bitmap for content:/path", shadowOf(bitmap).getDescription());
    assertEquals(123, bitmap.getWidth());
    assertEquals(456, bitmap.getHeight());
  }
Esempio n. 11
0
  @Test
  public void decodeWithDifferentSampleSize() {
    String name = "test";
    BitmapFactory.Options options = new BitmapFactory.Options();

    options.inSampleSize = 0;
    Bitmap bm = ShadowBitmapFactory.create(name, options);
    assertThat(bm.getWidth()).isEqualTo(100);
    assertThat(bm.getHeight()).isEqualTo(100);

    options.inSampleSize = 2;
    bm = ShadowBitmapFactory.create(name, options);
    assertThat(bm.getWidth()).isEqualTo(50);
    assertThat(bm.getHeight()).isEqualTo(50);

    options.inSampleSize = 101;
    bm = ShadowBitmapFactory.create(name, options);
    assertThat(bm.getWidth()).isEqualTo(1);
    assertThat(bm.getHeight()).isEqualTo(1);
  }
Esempio n. 12
0
  @Test
  public void decodeByteArray_shouldSetDataChecksum() throws Exception {
    byte[] data = {23, -125, 0, 52, 23, 18, 76, 43};

    Bitmap bitmap = ShadowBitmapFactory.decodeByteArray(data, 0, data.length);
    assertThat(bitmap).isNotNull();
    assertThat(shadowOf(bitmap).getDescription())
        .isEqualTo("Bitmap for byte array, checksum: 3693078531");
    assertThat(bitmap.getWidth()).isEqualTo(100);
    assertThat(bitmap.getHeight()).isEqualTo(100);
  }
Esempio n. 13
0
  @Test
  public void decodeStream_shouldGetWidthAndHeightFromHints() throws Exception {
    ShadowBitmapFactory.provideWidthAndHeightHints(Uri.parse("content:/path"), 123, 456);

    InputStream inputStream =
        Robolectric.application.getContentResolver().openInputStream(Uri.parse("content:/path"));
    Bitmap bitmap = BitmapFactory.decodeStream(inputStream);
    assertEquals("Bitmap for content:/path", shadowOf(bitmap).getDescription());
    assertEquals(123, bitmap.getWidth());
    assertEquals(456, bitmap.getHeight());
  }
Esempio n. 14
0
  @Test
  public void decodeByteArray_shouldSetDataChecksum() throws Exception {
    byte[] data = {23, 100, 23, 52, 23, 18, 76, 43};

    Bitmap bitmap = ShadowBitmapFactory.decodeByteArray(data, 0, data.length);
    assertThat(bitmap, notNullValue());
    assertThat(
        shadowOf(bitmap).getDescription(),
        equalTo("Bitmap for byte array, checksum:80429753 offset: 0 length: 8"));
    assertThat(bitmap.getWidth(), equalTo(100));
    assertThat(bitmap.getHeight(), equalTo(100));
  }
Esempio n. 15
0
  @Test
  public void decodeByteArray_withOptionsShouldSetDataChecksum() throws Exception {
    byte[] data = {23, -125, 0, 52, 23, 18, 76, 43};

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;
    Bitmap bitmap = ShadowBitmapFactory.decodeByteArray(data, 0, data.length - 1, options);
    assertThat(shadowOf(bitmap).getDescription())
        .isEqualTo(
            "Bitmap for byte array, checksum: 3693078531 bytes 0..7 with options inSampleSize=4");
    assertThat(bitmap.getWidth()).isEqualTo(25);
    assertThat(bitmap.getHeight()).isEqualTo(25);
  }
Esempio n. 16
0
  @Test
  public void decodeByteArray_withOptionsShouldSetDataChecksum() throws Exception {
    byte[] data = {23, 100, 23, 52, 23, 18, 76, 43};

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;
    Bitmap bitmap = ShadowBitmapFactory.decodeByteArray(data, 0, data.length, options);
    assertThat(
        shadowOf(bitmap).getDescription(),
        equalTo(
            "Bitmap for byte array, checksum:80429753 offset: 0 length: 8 with options inSampleSize=4"));
    assertThat(bitmap.getWidth(), equalTo(25));
    assertThat(bitmap.getHeight(), equalTo(25));
  }
Esempio n. 17
0
 public static void resetStaticState() {
   ShadowWrangler.getInstance().silence();
   Robolectric.application = new Application();
   ShadowBitmapFactory.reset();
   ShadowDrawable.reset();
   ShadowMediaStore.reset();
   ShadowLog.reset();
   ShadowContext.clearFilesAndCache();
   ShadowLooper.resetThreadLoopers();
   ShadowDialog.reset();
   ShadowContentResolver.reset();
   ShadowLocalBroadcastManager.reset();
   ShadowMimeTypeMap.reset();
   ShadowPowerManager.reset();
   ShadowStatFs.reset();
   ShadowTypeface.reset();
 }