Add tests for Util.toByteArray
The implementation of these methods is changed in a follow-up CL, and these tests help to ensure nothing breaks. This doesn't include tests for `toByteArray(InputStream)` or `toByteArray(int)` because these implementations are fully replaced by Guava equivalents in a follow-up CL. PiperOrigin-RevId: 613581845
This commit is contained in:
parent
ab8b77a6d3
commit
5b48ef4e53
@ -47,8 +47,10 @@ import android.os.Looper;
|
|||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
import android.util.SparseLongArray;
|
import android.util.SparseLongArray;
|
||||||
import androidx.media3.common.C;
|
import androidx.media3.common.C;
|
||||||
|
import androidx.media3.test.utils.TestUtil;
|
||||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||||
import com.google.common.io.ByteStreams;
|
import com.google.common.io.ByteStreams;
|
||||||
|
import com.google.common.primitives.Bytes;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.common.util.concurrent.SettableFuture;
|
import com.google.common.util.concurrent.SettableFuture;
|
||||||
@ -76,6 +78,33 @@ public class UtilTest {
|
|||||||
|
|
||||||
private static final int TIMEOUT_MS = 10000;
|
private static final int TIMEOUT_MS = 10000;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void toByteArray_fromIntArray() {
|
||||||
|
assertThat(Util.toByteArray(Integer.MIN_VALUE, -1, 0, 1, Integer.MAX_VALUE))
|
||||||
|
.isEqualTo(
|
||||||
|
Bytes.concat(
|
||||||
|
TestUtil.createByteArray(0x80, 0, 0, 0),
|
||||||
|
TestUtil.createByteArray(0xFF, 0xFF, 0xFF, 0xFF),
|
||||||
|
TestUtil.createByteArray(0, 0, 0, 0),
|
||||||
|
TestUtil.createByteArray(0, 0, 0, 1),
|
||||||
|
TestUtil.createByteArray(0x7F, 0xFF, 0xFF, 0xFF)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void toByteArray_fromFloat() {
|
||||||
|
assertThat(Util.toByteArray(Float.MAX_VALUE))
|
||||||
|
.isEqualTo(TestUtil.createByteArray(0x7F, 0x7F, 0xFF, 0xFF));
|
||||||
|
|
||||||
|
assertThat(Util.toByteArray(Float.MIN_VALUE))
|
||||||
|
.isEqualTo(TestUtil.createByteArray(0x00, 0x00, 0x00, 0x01));
|
||||||
|
|
||||||
|
assertThat(Util.toByteArray(0)).isEqualTo(TestUtil.createByteArray(0x00, 0x00, 0x00, 0x00));
|
||||||
|
|
||||||
|
assertThat(Util.toByteArray(1.0f)).isEqualTo(TestUtil.createByteArray(0x3F, 0x80, 0x00, 0x00));
|
||||||
|
|
||||||
|
assertThat(Util.toByteArray(-1.0f)).isEqualTo(TestUtil.createByteArray(0xBF, 0x80, 0x00, 0x00));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void addWithOverflowDefault_withoutOverFlow_returnsSum() {
|
public void addWithOverflowDefault_withoutOverFlow_returnsSum() {
|
||||||
long res = Util.addWithOverflowDefault(5, 10, /* overflowResult= */ 0);
|
long res = Util.addWithOverflowDefault(5, 10, /* overflowResult= */ 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user