|
17 | 17 |
|
18 | 18 | import static androidx.media3.common.util.Util.binarySearchCeil;
|
19 | 19 | import static androidx.media3.common.util.Util.binarySearchFloor;
|
| 20 | +import static androidx.media3.common.util.Util.contentEquals; |
| 21 | +import static androidx.media3.common.util.Util.contentHashCode; |
20 | 22 | import static androidx.media3.common.util.Util.escapeFileName;
|
21 | 23 | import static androidx.media3.common.util.Util.getCodecsOfType;
|
22 | 24 | import static androidx.media3.common.util.Util.getStringForTime;
|
|
42 | 44 | import android.os.Handler;
|
43 | 45 | import android.os.HandlerThread;
|
44 | 46 | import android.os.Looper;
|
| 47 | +import android.util.SparseArray; |
45 | 48 | import android.util.SparseLongArray;
|
46 | 49 | import androidx.media3.common.C;
|
47 | 50 | import androidx.test.ext.junit.runners.AndroidJUnit4;
|
@@ -1523,6 +1526,77 @@ public void getRoleFlagStrings() {
|
1523 | 1526 | assertThat(roleFlags).containsExactly("describes-music", "easy-read");
|
1524 | 1527 | }
|
1525 | 1528 |
|
| 1529 | + @Test |
| 1530 | + public void contentEquals_twoNullSparseArrays_returnsTrue() { |
| 1531 | + assertThat(contentEquals(null, null)).isTrue(); |
| 1532 | + } |
| 1533 | + |
| 1534 | + @Test |
| 1535 | + public void contentEquals_oneNullSparseArrayAndOneNonNullSparseArray_returnsFalse() { |
| 1536 | + SparseArray<Integer> sparseArray = new SparseArray<>(); |
| 1537 | + sparseArray.put(1, 2); |
| 1538 | + |
| 1539 | + assertThat(contentEquals(sparseArray, null)).isFalse(); |
| 1540 | + assertThat(contentEquals(null, sparseArray)).isFalse(); |
| 1541 | + } |
| 1542 | + |
| 1543 | + @Test |
| 1544 | + @Config(minSdk = 16) // Specifies the minimum SDK to enforce the test to run with all API levels. |
| 1545 | + public void contentEquals_sparseArraysWithEqualContent_returnsTrue() { |
| 1546 | + SparseArray<Integer> sparseArray1 = new SparseArray<>(); |
| 1547 | + sparseArray1.put(1, 2); |
| 1548 | + sparseArray1.put(3, 4); |
| 1549 | + SparseArray<Integer> sparseArray2 = new SparseArray<>(); |
| 1550 | + sparseArray2.put(3, 4); |
| 1551 | + sparseArray2.put(1, 2); |
| 1552 | + |
| 1553 | + assertThat(contentEquals(sparseArray1, sparseArray2)).isTrue(); |
| 1554 | + } |
| 1555 | + |
| 1556 | + @Test |
| 1557 | + @Config(minSdk = 16) // Specifies the minimum SDK to enforce the test to run with all API levels. |
| 1558 | + public void contentEquals_sparseArraysWithDifferentContents_returnsFalse() { |
| 1559 | + SparseArray<Integer> sparseArray1 = new SparseArray<>(); |
| 1560 | + sparseArray1.put(1, 2); |
| 1561 | + sparseArray1.put(3, 4); |
| 1562 | + SparseArray<Integer> sparseArray2 = new SparseArray<>(); |
| 1563 | + sparseArray2.put(3, 4); |
| 1564 | + SparseArray<Integer> sparseArray3 = new SparseArray<>(); |
| 1565 | + sparseArray3.put(1, 3); |
| 1566 | + sparseArray3.put(3, 4); |
| 1567 | + |
| 1568 | + assertThat(contentEquals(sparseArray1, sparseArray2)).isFalse(); |
| 1569 | + assertThat(contentEquals(sparseArray1, sparseArray3)).isFalse(); |
| 1570 | + } |
| 1571 | + |
| 1572 | + @Test |
| 1573 | + @Config(minSdk = 16) // Specifies the minimum SDK to enforce the test to run with all API levels. |
| 1574 | + public void contentHashCode_sparseArraysWithEqualContent_returnsEqualContentHashCode() { |
| 1575 | + SparseArray<Integer> sparseArray1 = new SparseArray<>(); |
| 1576 | + sparseArray1.put(1, 2); |
| 1577 | + sparseArray1.put(3, 4); |
| 1578 | + SparseArray<Integer> sparseArray2 = new SparseArray<>(); |
| 1579 | + sparseArray2.put(3, 4); |
| 1580 | + sparseArray2.put(1, 2); |
| 1581 | + |
| 1582 | + assertThat(contentHashCode(sparseArray1)).isEqualTo(contentHashCode(sparseArray2)); |
| 1583 | + } |
| 1584 | + |
| 1585 | + @Test |
| 1586 | + @Config(minSdk = 16) // Specifies the minimum SDK to enforce the test to run with all API levels. |
| 1587 | + public void contentHashCode_sparseArraysWithDifferentContent_returnsDifferentContentHashCode() { |
| 1588 | + // In theory this is not guaranteed though, adding this test to ensure a sensible |
| 1589 | + // contentHashCode implementation. |
| 1590 | + SparseArray<Integer> sparseArray1 = new SparseArray<>(); |
| 1591 | + sparseArray1.put(1, 2); |
| 1592 | + sparseArray1.put(3, 4); |
| 1593 | + SparseArray<Integer> sparseArray2 = new SparseArray<>(); |
| 1594 | + sparseArray2.put(3, 2); |
| 1595 | + sparseArray2.put(1, 4); |
| 1596 | + |
| 1597 | + assertThat(contentHashCode(sparseArray1)).isNotEqualTo(contentHashCode(sparseArray2)); |
| 1598 | + } |
| 1599 | + |
1526 | 1600 | private static void assertEscapeUnescapeFileName(String fileName, String escapedFileName) {
|
1527 | 1601 | assertThat(escapeFileName(fileName)).isEqualTo(escapedFileName);
|
1528 | 1602 | assertThat(unescapeFileName(escapedFileName)).isEqualTo(fileName);
|
|
0 commit comments