Skip to content

Commit 0540609

Browse files
ideclaude
andcommitted
Test that ReactAndroid ships the ExifInterface Fresco needs
Fresco reads a HEIF image's EXIF orientation with `androidx.exifinterface.media.ExifInterface` but does not declare the dependency, so ReactAndroid declares it. Nothing failed if that declaration was removed. Call Fresco's `HeifExifUtil.getOrientation` on a stream with an EXIF orientation tag and expect the orientation back. Without the dependency the call throws `NoClassDefFoundError`, as it does in an app. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 3ea6c42 commit 0540609

1 file changed

Lines changed: 84 additions & 0 deletions

File tree

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.modules.fresco
9+
10+
import com.facebook.imageutils.HeifExifUtil
11+
import java.io.ByteArrayInputStream
12+
import org.assertj.core.api.Assertions.assertThat
13+
import org.junit.Test
14+
import org.junit.runner.RunWith
15+
import org.robolectric.RobolectricTestRunner
16+
17+
/**
18+
* Fresco reads a HEIF image's EXIF orientation with `androidx.exifinterface`, which it does not
19+
* declare as a dependency. ReactAndroid declares it, and this test fails with a
20+
* `NoClassDefFoundError` if that dependency is removed.
21+
*/
22+
@RunWith(RobolectricTestRunner::class)
23+
class HeifExifOrientationTest {
24+
25+
@Test
26+
fun heifExifUtil_readsTheOrientationWithExifInterface() {
27+
assertThat(HeifExifUtil.getOrientation(ByteArrayInputStream(EXIF_ROTATED_90))).isEqualTo(6)
28+
}
29+
30+
private companion object {
31+
// An EXIF block whose only tag is Orientation (0x0112) = 6, "rotate 90 CW", in the smallest
32+
// file ExifInterface reads: a JPEG with no image data. HeifExifUtil passes the stream to
33+
// ExifInterface without checking its format.
34+
private val EXIF_ROTATED_90 =
35+
byteArrayOf(
36+
// SOI
37+
0xFF.toByte(),
38+
0xD8.toByte(),
39+
// APP1, 34 bytes, "Exif\0\0"
40+
0xFF.toByte(),
41+
0xE1.toByte(),
42+
0x00,
43+
0x22,
44+
0x45,
45+
0x78,
46+
0x69,
47+
0x66,
48+
0x00,
49+
0x00,
50+
// TIFF header: big-endian, first IFD at offset 8
51+
0x4D,
52+
0x4D,
53+
0x00,
54+
0x2A,
55+
0x00,
56+
0x00,
57+
0x00,
58+
0x08,
59+
// IFD with one entry: Orientation, SHORT, count 1, value 6
60+
0x00,
61+
0x01,
62+
0x01,
63+
0x12,
64+
0x00,
65+
0x03,
66+
0x00,
67+
0x00,
68+
0x00,
69+
0x01,
70+
0x00,
71+
0x06,
72+
0x00,
73+
0x00,
74+
// No next IFD
75+
0x00,
76+
0x00,
77+
0x00,
78+
0x00,
79+
// EOI
80+
0xFF.toByte(),
81+
0xD9.toByte(),
82+
)
83+
}
84+
}

0 commit comments

Comments
 (0)