Skip to content

Commit

Permalink
fbandroid/libraries/fresco/static-webp/src/androidTest/java/com/faceb…
Browse files Browse the repository at this point in the history
…ook/webpsupport/WebpDecodingTest.java

Reviewed By: jocelynluizzi13

Differential Revision: D68490289

fbshipit-source-id: c301c348c57ed2ceb4ba02b44d7ca6528d6feb92
  • Loading branch information
generatedunixname89002005287564 authored and facebook-github-bot committed Jan 22, 2025
1 parent 885f089 commit 50d81fb
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.facebook.common.internal.Throwables;
import com.facebook.imagepipeline.core.ImagePipelineConfig;
import com.facebook.imagepipeline.core.ImagePipelineFactory;
import com.facebook.infer.annotation.Nullsafe;
import java.io.FileDescriptor;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -24,6 +25,7 @@
import org.junit.Test;

/** This is the test in order to directly decoding all types of webp images */
@Nullsafe(Nullsafe.Mode.LOCAL)
public class WebpDecodingTest extends TestCase {

private static Method sGetFileDescriptorMethod;
Expand All @@ -38,6 +40,7 @@ public void setUp() {
mInstrumentation = InstrumentationRegistry.getInstrumentation();
mWebpBitmapFactory = new WebpBitmapFactoryImpl();
ImagePipelineConfig.Builder configBuilder =
// NULLSAFE_FIXME[Not Vetted Third-Party]
ImagePipelineConfig.newBuilder(mInstrumentation.getContext());
configBuilder.experiment().setWebpBitmapFactory(mWebpBitmapFactory);
ImagePipelineFactory.initialize(configBuilder.build());
Expand Down Expand Up @@ -69,6 +72,7 @@ private synchronized Method getFileDescriptorMethod() {
private FileDescriptor getMemoryFileDescriptor(MemoryFile memoryFile) {
try {
Object rawFD = getFileDescriptorMethod().invoke(memoryFile);
// NULLSAFE_FIXME[Return Not Nullable]
return (FileDescriptor) rawFD;
} catch (Exception e) {
throw Throwables.propagate(e);
Expand All @@ -77,6 +81,7 @@ private FileDescriptor getMemoryFileDescriptor(MemoryFile memoryFile) {

private InputStream getTestImageInputStream(String path) {
try {
// NULLSAFE_FIXME[Not Vetted Third-Party]
return mInstrumentation.getContext().getResources().getAssets().open(path);
} catch (IOException e) {
throw Throwables.propagate(e);
Expand All @@ -87,6 +92,7 @@ private InputStream getTestImageInputStream(String path) {
public void test_webp_extended_decoding_inputstream_bitmap() throws Throwable {
final Bitmap bitmap =
mWebpBitmapFactory.decodeStream(getTestImageInputStream("webp_e.webp"), null, null);
// NULLSAFE_FIXME[Parameter Not Nullable]
assertBitmap(bitmap, 480, 320);
}

Expand All @@ -96,6 +102,7 @@ public void test_webp_extended_decoding_filedescriptor_bitmap() throws Throwable
final Bitmap bitmap =
mWebpBitmapFactory.decodeFileDescriptor(getMemoryFileDescriptor(memoryFile), null, null);
memoryFile.close();
// NULLSAFE_FIXME[Parameter Not Nullable]
assertBitmap(bitmap, 480, 320);
}

Expand All @@ -104,6 +111,7 @@ public void test_webp_extended_with_alpha_decoding_inputstream_bitmap() throws T
final Bitmap bitmap =
mWebpBitmapFactory.decodeStream(getTestImageInputStream("webp_ea.webp"), null, null);

// NULLSAFE_FIXME[Parameter Not Nullable]
assertBitmap(bitmap, 400, 301);
}

Expand All @@ -113,6 +121,7 @@ public void test_webp_extended_with_alpha_decoding_filedescriptor_bitmap() throw
final Bitmap bitmap =
mWebpBitmapFactory.decodeFileDescriptor(getMemoryFileDescriptor(memoryFile), null, null);
memoryFile.close();
// NULLSAFE_FIXME[Parameter Not Nullable]
assertBitmap(bitmap, 400, 301);
}

Expand All @@ -121,6 +130,7 @@ public void test_webp_lossless_decoding_inputstream_bitmap() throws Throwable {
final Bitmap bitmap =
mWebpBitmapFactory.decodeStream(getTestImageInputStream("webp_ll.webp"), null, null);

// NULLSAFE_FIXME[Parameter Not Nullable]
assertBitmap(bitmap, 400, 301);
}

Expand All @@ -130,6 +140,7 @@ public void test_webp_lossless_decoding_filedescriptor_bitmap() throws Throwable
final Bitmap bitmap =
mWebpBitmapFactory.decodeFileDescriptor(getMemoryFileDescriptor(memoryFile), null, null);
memoryFile.close();
// NULLSAFE_FIXME[Parameter Not Nullable]
assertBitmap(bitmap, 400, 301);
}

Expand All @@ -138,6 +149,7 @@ public void test_webp_plain_inputstream_bitmap() throws Throwable {
final Bitmap bitmap =
mWebpBitmapFactory.decodeStream(getTestImageInputStream("webp_plain.webp"), null, null);

// NULLSAFE_FIXME[Parameter Not Nullable]
assertBitmap(bitmap, 320, 214);
}

Expand All @@ -147,6 +159,7 @@ public void test_webp_plain_decoding_filedescriptor_bitmap() throws Throwable {
final Bitmap bitmap =
mWebpBitmapFactory.decodeFileDescriptor(getMemoryFileDescriptor(memoryFile), null, null);
memoryFile.close();
// NULLSAFE_FIXME[Parameter Not Nullable]
assertBitmap(bitmap, 320, 214);
}

Expand Down

0 comments on commit 50d81fb

Please sign in to comment.