Skip to content

Commit

Permalink
Make CueSerializationTest more realistic
Browse files Browse the repository at this point in the history
Serializing bitmap cues is currently broken, but this test is
incorrectly passing. This change makes two changes to introduce the same
failure (both changes are necessary, each one alone still passes):

1. Move from Robolectric to an instrumentation test.
2. Trigger the `Bitmap` to be serialized using a file descriptor, either
   by calling `Bitmap.asShared` in the test when constructing the `Cue`,
   or constructing the `Bitmap` from a 'real' image byte array instead a
   1x1 token image.

Issue: #836
PiperOrigin-RevId: 585643486
  • Loading branch information
icbaker authored and copybara-github committed Nov 27, 2023
1 parent 5f27b18 commit 63062a9
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
8 changes: 7 additions & 1 deletion libraries/extractor/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ android {
}
}

sourceSets.test.assets.srcDir '../test_data/src/test/assets/'
sourceSets {
androidTest.assets.srcDir '../test_data/src/test/assets'
test.assets.srcDir '../test_data/src/test/assets/'
}

publishing {
singleVariant('release') {
Expand All @@ -44,6 +47,9 @@ dependencies {
testImplementation project(modulePrefix + 'test-utils')
testImplementation project(modulePrefix + 'test-data')
testImplementation 'org.robolectric:robolectric:' + robolectricVersion
androidTestImplementation 'androidx.test:runner:' + androidxTestRunnerVersion
androidTestImplementation project(modulePrefix + 'test-utils')
androidTestImplementation 'com.linkedin.dexmaker:dexmaker:' + dexmakerVersion
}

ext {
Expand Down
33 changes: 33 additions & 0 deletions libraries/extractor/src/androidTest/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="androidx.media3.extractor.test">

<uses-sdk/>

<application
android:name="androidx.multidex.MultiDexApplication"
android:allowBackup="false"
tools:ignore="MissingApplicationIcon,HardcodedDebugMode"
android:usesCleartextTraffic="true"/>

<instrumentation
android:targetPackage="androidx.media3.extractor.test"
android:name="androidx.test.runner.AndroidJUnitRunner"/>

</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
import static com.google.common.truth.Truth.assertThat;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.text.Layout;
import android.text.Spannable;
import android.text.SpannableString;
Expand All @@ -28,18 +30,26 @@
import androidx.media3.common.text.Cue;
import androidx.media3.common.text.RubySpan;
import androidx.media3.common.text.TextAnnotation;
import androidx.media3.test.utils.TestUtil;
import androidx.media3.test.utils.truth.SpannedSubject;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.common.collect.ImmutableList;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Test of {@link Cue} serialization and deserialization using {@link CueEncoder} and {@link
* CueDecoder}.
*
* <p>This needs to be an instrumentation test because Robolectric's handling of serializing a
* {@link Bundle} containing a {@link Bitmap} is not realistic, leading to real failures not being
* caught by the test (e.g. https://github.com/androidx/media/issues/836).
*/
@RunWith(AndroidJUnit4.class)
public class CueSerializationTest {

@Test
public void serializingCueWithoutSpans() {
CueEncoder encoder = new CueEncoder();
Expand Down Expand Up @@ -86,10 +96,16 @@ public void serializingCueWithoutSpans() {
}

@Test
public void serializingBitmapCue() {
@Ignore("Currently broken: https://github.com/androidx/media/issues/836")
public void serializingBitmapCue() throws Exception {
CueEncoder encoder = new CueEncoder();
CueDecoder decoder = new CueDecoder();
Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

byte[] imageData =
TestUtil.getByteArray(
ApplicationProvider.getApplicationContext(),
"media/png/non-motion-photo-shortened.png");
Bitmap bitmap = BitmapFactory.decodeByteArray(imageData, 0, imageData.length);
Cue bitmapCue = new Cue.Builder().setBitmap(bitmap).build();

// encoding and decoding
Expand Down

0 comments on commit 63062a9

Please sign in to comment.