|
78 | 78 | import static org.mockito.MockitoAnnotations.initMocks;
|
79 | 79 | import static org.robolectric.Robolectric.shadowOf;
|
80 | 80 |
|
| 81 | +import static android.media.ExifInterface.ORIENTATION_ROTATE_90; |
| 82 | +import static android.media.ExifInterface.ORIENTATION_FLIP_HORIZONTAL ; |
| 83 | +import static android.media.ExifInterface.ORIENTATION_FLIP_VERTICAL; |
| 84 | +import static android.media.ExifInterface.ORIENTATION_TRANSPOSE; |
| 85 | +import static android.media.ExifInterface.ORIENTATION_TRANSVERSE; |
| 86 | + |
81 | 87 | @RunWith(RobolectricTestRunner.class)
|
82 | 88 | @Config(manifest = Config.NONE)
|
83 | 89 | public class BitmapHunterTest {
|
@@ -407,15 +413,69 @@ public class BitmapHunterTest {
|
407 | 413 | @Test public void exifRotation() {
|
408 | 414 | Request data = new Request.Builder(URI_1).rotate(-45).build();
|
409 | 415 | Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
|
410 |
| - Bitmap result = transformResult(data, source, 90); |
| 416 | + Bitmap result = transformResult(data, source, ORIENTATION_ROTATE_90); |
| 417 | + ShadowBitmap shadowBitmap = shadowOf(result); |
| 418 | + assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source); |
| 419 | + |
| 420 | + Matrix matrix = shadowBitmap.getCreatedFromMatrix(); |
| 421 | + ShadowMatrix shadowMatrix = shadowOf(matrix); |
| 422 | + assertThat(shadowMatrix.getPreOperations()).containsOnly("rotate 90.0"); |
| 423 | + } |
| 424 | + |
| 425 | + @Test public void exifVerticalFlip() { |
| 426 | + Request data = new Request.Builder(URI_1).rotate(-45).build(); |
| 427 | + Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888); |
| 428 | + Bitmap result = transformResult(data, source, ORIENTATION_FLIP_VERTICAL); |
| 429 | + ShadowBitmap shadowBitmap = shadowOf(result); |
| 430 | + assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source); |
| 431 | + |
| 432 | + Matrix matrix = shadowBitmap.getCreatedFromMatrix(); |
| 433 | + ShadowMatrix shadowMatrix = shadowOf(matrix); |
| 434 | + assertThat(shadowMatrix.getPostOperations()).containsOnly("scale -1.0 1.0"); |
| 435 | + assertThat(shadowMatrix.getPreOperations()).containsOnly("rotate 180.0"); |
| 436 | + } |
| 437 | + |
| 438 | + @Test public void exifHorizontalFlip() { |
| 439 | + Request data = new Request.Builder(URI_1).rotate(-45).build(); |
| 440 | + Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888); |
| 441 | + Bitmap result = transformResult(data, source, ORIENTATION_FLIP_HORIZONTAL); |
| 442 | + ShadowBitmap shadowBitmap = shadowOf(result); |
| 443 | + assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source); |
| 444 | + |
| 445 | + Matrix matrix = shadowBitmap.getCreatedFromMatrix(); |
| 446 | + ShadowMatrix shadowMatrix = shadowOf(matrix); |
| 447 | + assertThat(shadowMatrix.getPostOperations()).containsOnly("scale -1.0 1.0"); |
| 448 | + assertThat(shadowMatrix.getPreOperations()).doesNotContain("rotate 180.0"); |
| 449 | + assertThat(shadowMatrix.getPreOperations()).doesNotContain("rotate 90.0"); |
| 450 | + assertThat(shadowMatrix.getPreOperations()).doesNotContain("rotate 270.0"); |
| 451 | + } |
| 452 | + |
| 453 | + @Test public void exifTranspose() { |
| 454 | + Request data = new Request.Builder(URI_1).rotate(-45).build(); |
| 455 | + Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888); |
| 456 | + Bitmap result = transformResult(data, source, ORIENTATION_TRANSPOSE); |
411 | 457 | ShadowBitmap shadowBitmap = shadowOf(result);
|
412 | 458 | assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source);
|
413 | 459 |
|
414 | 460 | Matrix matrix = shadowBitmap.getCreatedFromMatrix();
|
415 | 461 | ShadowMatrix shadowMatrix = shadowOf(matrix);
|
| 462 | + assertThat(shadowMatrix.getPostOperations()).containsOnly("scale -1.0 1.0"); |
416 | 463 | assertThat(shadowMatrix.getPreOperations()).containsOnly("rotate 90.0");
|
417 | 464 | }
|
418 | 465 |
|
| 466 | + @Test public void exifTransverse() { |
| 467 | + Request data = new Request.Builder(URI_1).rotate(-45).build(); |
| 468 | + Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888); |
| 469 | + Bitmap result = transformResult(data, source, ORIENTATION_TRANSVERSE); |
| 470 | + ShadowBitmap shadowBitmap = shadowOf(result); |
| 471 | + assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source); |
| 472 | + |
| 473 | + Matrix matrix = shadowBitmap.getCreatedFromMatrix(); |
| 474 | + ShadowMatrix shadowMatrix = shadowOf(matrix); |
| 475 | + assertThat(shadowMatrix.getPostOperations()).containsOnly("scale -1.0 1.0"); |
| 476 | + assertThat(shadowMatrix.getPreOperations()).containsOnly("rotate 270.0"); |
| 477 | + } |
| 478 | + |
419 | 479 | @Test public void keepsAspectRationWhileResizingWhenDesiredWidthIs0() {
|
420 | 480 | Request request = new Request.Builder(URI_1).resize(20, 0).build();
|
421 | 481 | Bitmap source = Bitmap.createBitmap(40, 20, ARGB_8888);
|
@@ -549,7 +609,7 @@ public class BitmapHunterTest {
|
549 | 609 | Bitmap source = Bitmap.createBitmap(10, 10, ARGB_8888);
|
550 | 610 | Request data = new Request.Builder(URI_1).rotate(-45).build();
|
551 | 611 |
|
552 |
| - Bitmap result = transformResult(data, source, 90); |
| 612 | + Bitmap result = transformResult(data, source, ORIENTATION_ROTATE_90); |
553 | 613 |
|
554 | 614 | ShadowBitmap shadowBitmap = shadowOf(result);
|
555 | 615 | assertThat(shadowBitmap.getCreatedFromBitmap()).isSameAs(source);
|
|
0 commit comments