Make CueSerializationTest
more realistic
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: androidx/media#836 PiperOrigin-RevId: 585643486
This commit is contained in:
parent
5f27b18210
commit
63062a9c10
@ -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 {
|
publishing {
|
||||||
singleVariant('release') {
|
singleVariant('release') {
|
||||||
@ -44,6 +47,9 @@ dependencies {
|
|||||||
testImplementation project(modulePrefix + 'test-utils')
|
testImplementation project(modulePrefix + 'test-utils')
|
||||||
testImplementation project(modulePrefix + 'test-data')
|
testImplementation project(modulePrefix + 'test-data')
|
||||||
testImplementation 'org.robolectric:robolectric:' + robolectricVersion
|
testImplementation 'org.robolectric:robolectric:' + robolectricVersion
|
||||||
|
androidTestImplementation 'androidx.test:runner:' + androidxTestRunnerVersion
|
||||||
|
androidTestImplementation project(modulePrefix + 'test-utils')
|
||||||
|
androidTestImplementation 'com.linkedin.dexmaker:dexmaker:' + dexmakerVersion
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
|
33
libraries/extractor/src/androidTest/AndroidManifest.xml
Normal file
33
libraries/extractor/src/androidTest/AndroidManifest.xml
Normal file
@ -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>
|
@ -18,7 +18,9 @@ package androidx.media3.extractor.text;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.text.Layout;
|
import android.text.Layout;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableString;
|
import android.text.SpannableString;
|
||||||
@ -28,18 +30,26 @@ import android.text.style.StrikethroughSpan;
|
|||||||
import androidx.media3.common.text.Cue;
|
import androidx.media3.common.text.Cue;
|
||||||
import androidx.media3.common.text.RubySpan;
|
import androidx.media3.common.text.RubySpan;
|
||||||
import androidx.media3.common.text.TextAnnotation;
|
import androidx.media3.common.text.TextAnnotation;
|
||||||
|
import androidx.media3.test.utils.TestUtil;
|
||||||
import androidx.media3.test.utils.truth.SpannedSubject;
|
import androidx.media3.test.utils.truth.SpannedSubject;
|
||||||
|
import androidx.test.core.app.ApplicationProvider;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of {@link Cue} serialization and deserialization using {@link CueEncoder} and {@link
|
* Test of {@link Cue} serialization and deserialization using {@link CueEncoder} and {@link
|
||||||
* CueDecoder}.
|
* 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)
|
@RunWith(AndroidJUnit4.class)
|
||||||
public class CueSerializationTest {
|
public class CueSerializationTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serializingCueWithoutSpans() {
|
public void serializingCueWithoutSpans() {
|
||||||
CueEncoder encoder = new CueEncoder();
|
CueEncoder encoder = new CueEncoder();
|
||||||
@ -86,10 +96,16 @@ public class CueSerializationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void serializingBitmapCue() {
|
@Ignore("Currently broken: https://github.com/androidx/media/issues/836")
|
||||||
|
public void serializingBitmapCue() throws Exception {
|
||||||
CueEncoder encoder = new CueEncoder();
|
CueEncoder encoder = new CueEncoder();
|
||||||
CueDecoder decoder = new CueDecoder();
|
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();
|
Cue bitmapCue = new Cue.Builder().setBitmap(bitmap).build();
|
||||||
|
|
||||||
// encoding and decoding
|
// encoding and decoding
|
Loading…
x
Reference in New Issue
Block a user