mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2026-04-20 05:41:23 +00:00
Merge branch 'dev' into pr8221
This commit is contained in:
@@ -9,7 +9,7 @@ class FeedGroupIconTest {
|
||||
fun `No gaps and repeated ids`() {
|
||||
val usedIds = HashSet<Int>()
|
||||
|
||||
for ((shouldBeId, currentIcon) in FeedGroupIcon.values().withIndex()) {
|
||||
for ((shouldBeId, currentIcon) in FeedGroupIcon.entries.withIndex()) {
|
||||
val added = usedIds.add(currentIcon.id)
|
||||
assertTrue("Repeated ids (current item: ${currentIcon.name} - ${currentIcon.id})", added)
|
||||
|
||||
@@ -24,7 +24,7 @@ class FeedGroupIconTest {
|
||||
fun `No icons pointing to the same attr`() {
|
||||
val usedIcons = HashSet<Int>()
|
||||
|
||||
for (groupIcon in FeedGroupIcon.values()) {
|
||||
for (groupIcon in FeedGroupIcon.entries) {
|
||||
val added = usedIcons.add(groupIcon.drawableResource)
|
||||
assertTrue("Repeated icon (current item: ${groupIcon.name} - ${groupIcon.id})", added)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
package org.schabi.newpipe.local.subscription.services;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.extractor.subscription.SubscriptionExtractor;
|
||||
import org.schabi.newpipe.extractor.subscription.SubscriptionItem;
|
||||
@@ -11,9 +14,6 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @see ImportExportJsonHelper
|
||||
*/
|
||||
@@ -47,8 +47,8 @@ public class ImportExportJsonHelperTest {
|
||||
|
||||
fail("didn't throw exception");
|
||||
} catch (final Exception e) {
|
||||
final boolean isExpectedException
|
||||
= e instanceof SubscriptionExtractor.InvalidSourceException;
|
||||
final boolean isExpectedException =
|
||||
e instanceof SubscriptionExtractor.InvalidSourceException;
|
||||
assertTrue("\"" + e.getClass().getSimpleName()
|
||||
+ "\" is not the expected exception", isExpectedException);
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.util.Objects;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
@@ -153,7 +152,7 @@ public class PlayQueueTest {
|
||||
@Test
|
||||
public void itemsAreNotCloned() {
|
||||
final PlayQueueItem item = makeItemWithUrl("A url");
|
||||
final PlayQueue playQueue = makePlayQueue(0, Collections.singletonList(item));
|
||||
final PlayQueue playQueue = makePlayQueue(0, List.of(item));
|
||||
|
||||
// make sure that items are not cloned when added to the queue
|
||||
assertSame(playQueue.getItem(), item);
|
||||
@@ -169,7 +168,8 @@ public class PlayQueueTest {
|
||||
final List<PlayQueueItem> streams = Collections.nCopies(5, item1);
|
||||
final PlayQueue queue1 = makePlayQueue(0, streams);
|
||||
final PlayQueue queue2 = makePlayQueue(0, streams);
|
||||
assertEquals(queue1, queue2);
|
||||
assertTrue(queue1.equalStreams(queue2));
|
||||
assertTrue(queue1.equalStreamsAndIndex(queue2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -177,7 +177,8 @@ public class PlayQueueTest {
|
||||
final List<PlayQueueItem> streams = Collections.nCopies(5, item1);
|
||||
final PlayQueue queue1 = makePlayQueue(1, streams);
|
||||
final PlayQueue queue2 = makePlayQueue(4, streams);
|
||||
assertEquals(queue1, queue2);
|
||||
assertTrue(queue1.equalStreams(queue2));
|
||||
assertFalse(queue1.equalStreamsAndIndex(queue2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -186,7 +187,7 @@ public class PlayQueueTest {
|
||||
final List<PlayQueueItem> streams2 = Collections.nCopies(5, item2);
|
||||
final PlayQueue queue1 = makePlayQueue(0, streams1);
|
||||
final PlayQueue queue2 = makePlayQueue(0, streams2);
|
||||
assertNotEquals(queue1, queue2);
|
||||
assertFalse(queue1.equalStreams(queue2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -195,7 +196,7 @@ public class PlayQueueTest {
|
||||
final List<PlayQueueItem> streams2 = Collections.nCopies(6, item2);
|
||||
final PlayQueue queue1 = makePlayQueue(0, streams1);
|
||||
final PlayQueue queue2 = makePlayQueue(0, streams2);
|
||||
assertNotEquals(queue1, queue2);
|
||||
assertFalse(queue1.equalStreams(queue2));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package org.schabi.newpipe.settings.tabs;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
import com.grack.nanojson.JsonArray;
|
||||
import com.grack.nanojson.JsonObject;
|
||||
import com.grack.nanojson.JsonParser;
|
||||
@@ -11,11 +16,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
public class TabsJsonHelperTest {
|
||||
private static final String JSON_TABS_ARRAY_KEY = "tabs";
|
||||
private static final String JSON_TAB_ID_KEY = "tab_id";
|
||||
@@ -59,8 +59,8 @@ public class TabsJsonHelperTest {
|
||||
|
||||
fail("didn't throw exception");
|
||||
} catch (final Exception e) {
|
||||
final boolean isExpectedException
|
||||
= e instanceof TabsJsonHelper.InvalidJsonException;
|
||||
final boolean isExpectedException =
|
||||
e instanceof TabsJsonHelper.InvalidJsonException;
|
||||
assertTrue("\"" + e.getClass().getSimpleName()
|
||||
+ "\" is not the expected exception", isExpectedException);
|
||||
}
|
||||
|
||||
@@ -3,60 +3,75 @@ package org.schabi.newpipe.util;
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.extractor.MediaFormat;
|
||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||
import org.schabi.newpipe.extractor.stream.AudioTrackType;
|
||||
import org.schabi.newpipe.extractor.stream.VideoStream;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class ListHelperTest {
|
||||
private static final String BEST_RESOLUTION_KEY = "best_resolution";
|
||||
private static final List<AudioStream> AUDIO_STREAMS_TEST_LIST = Arrays.asList(
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 128),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192),
|
||||
new AudioStream("", MediaFormat.MP3, /**/ 64),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192),
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 128),
|
||||
new AudioStream("", MediaFormat.MP3, /**/ 128),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 64),
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 320),
|
||||
new AudioStream("", MediaFormat.MP3, /**/ 192),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 320));
|
||||
private static final List<AudioStream> AUDIO_STREAMS_TEST_LIST = List.of(
|
||||
generateAudioStream("m4a-128-1", MediaFormat.M4A, 128),
|
||||
generateAudioStream("webma-192", MediaFormat.WEBMA, 192),
|
||||
generateAudioStream("mp3-64", MediaFormat.MP3, 64),
|
||||
generateAudioStream("webma-192", MediaFormat.WEBMA, 192),
|
||||
generateAudioStream("m4a-128-2", MediaFormat.M4A, 128),
|
||||
generateAudioStream("mp3-128", MediaFormat.MP3, 128),
|
||||
generateAudioStream("webma-64", MediaFormat.WEBMA, 64),
|
||||
generateAudioStream("m4a-320", MediaFormat.M4A, 320),
|
||||
generateAudioStream("mp3-192", MediaFormat.MP3, 192),
|
||||
generateAudioStream("webma-320", MediaFormat.WEBMA, 320));
|
||||
|
||||
private static final List<VideoStream> VIDEO_STREAMS_TEST_LIST = Arrays.asList(
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "720p"),
|
||||
new VideoStream("", MediaFormat.v3GPP, /**/ "240p"),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "480p"),
|
||||
new VideoStream("", MediaFormat.v3GPP, /**/ "144p"),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "360p"),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "360p"));
|
||||
private static final List<AudioStream> AUDIO_TRACKS_TEST_LIST = List.of(
|
||||
generateAudioTrack("en.or", "en.or", Locale.ENGLISH, AudioTrackType.ORIGINAL),
|
||||
generateAudioTrack("en.du", "en.du", Locale.ENGLISH, AudioTrackType.DUBBED),
|
||||
generateAudioTrack("en.ds", "en.ds", Locale.ENGLISH, AudioTrackType.DESCRIPTIVE),
|
||||
generateAudioTrack("unknown", null, null, null),
|
||||
generateAudioTrack("de.du", "de.du", Locale.GERMAN, AudioTrackType.DUBBED),
|
||||
generateAudioTrack("de.ds", "de.ds", Locale.GERMAN, AudioTrackType.DESCRIPTIVE)
|
||||
);
|
||||
|
||||
private static final List<VideoStream> VIDEO_ONLY_STREAMS_TEST_LIST = Arrays.asList(
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "720p", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "720p", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "2160p", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "1440p60", true),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "720p60", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "2160p60", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "720p60", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "1080p", true),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "1080p60", true));
|
||||
private static final List<VideoStream> VIDEO_STREAMS_TEST_LIST = List.of(
|
||||
generateVideoStream("mpeg_4-720", MediaFormat.MPEG_4, "720p", false),
|
||||
generateVideoStream("v3gpp-240", MediaFormat.v3GPP, "240p", false),
|
||||
generateVideoStream("webm-480", MediaFormat.WEBM, "480p", false),
|
||||
generateVideoStream("v3gpp-144", MediaFormat.v3GPP, "144p", false),
|
||||
generateVideoStream("mpeg_4-360", MediaFormat.MPEG_4, "360p", false),
|
||||
generateVideoStream("webm-360", MediaFormat.WEBM, "360p", false));
|
||||
|
||||
private static final List<VideoStream> VIDEO_ONLY_STREAMS_TEST_LIST = List.of(
|
||||
generateVideoStream("mpeg_4-720-1", MediaFormat.MPEG_4, "720p", true),
|
||||
generateVideoStream("mpeg_4-720-2", MediaFormat.MPEG_4, "720p", true),
|
||||
generateVideoStream("mpeg_4-2160", MediaFormat.MPEG_4, "2160p", true),
|
||||
generateVideoStream("mpeg_4-1440_60", MediaFormat.MPEG_4, "1440p60", true),
|
||||
generateVideoStream("webm-720_60", MediaFormat.WEBM, "720p60", true),
|
||||
generateVideoStream("mpeg_4-2160_60", MediaFormat.MPEG_4, "2160p60", true),
|
||||
generateVideoStream("mpeg_4-720_60", MediaFormat.MPEG_4, "720p60", true),
|
||||
generateVideoStream("mpeg_4-1080", MediaFormat.MPEG_4, "1080p", true),
|
||||
generateVideoStream("mpeg_4-1080_60", MediaFormat.MPEG_4, "1080p60", true));
|
||||
|
||||
@Test
|
||||
public void getSortedStreamVideosListTest() {
|
||||
List<VideoStream> result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
|
||||
VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, true, false);
|
||||
|
||||
List<String> expected = Arrays.asList("144p", "240p", "360p", "480p", "720p", "720p60",
|
||||
List<String> expected = List.of("144p", "240p", "360p", "480p", "720p", "720p60",
|
||||
"1080p", "1080p60", "1440p60", "2160p", "2160p60");
|
||||
|
||||
assertEquals(expected.size(), result.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertEquals(expected.get(i), result.get(i).resolution);
|
||||
assertEquals(result.get(i).getResolution(), expected.get(i));
|
||||
assertEquals(expected.get(i), result.get(i).getResolution());
|
||||
}
|
||||
|
||||
////////////////////
|
||||
@@ -65,11 +80,11 @@ public class ListHelperTest {
|
||||
|
||||
result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
|
||||
VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, false, false);
|
||||
expected = Arrays.asList("2160p60", "2160p", "1440p60", "1080p60", "1080p", "720p60",
|
||||
expected = List.of("2160p60", "2160p", "1440p60", "1080p60", "1080p", "720p60",
|
||||
"720p", "480p", "360p", "240p", "144p");
|
||||
assertEquals(expected.size(), result.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertEquals(expected.get(i), result.get(i).resolution);
|
||||
assertEquals(expected.get(i), result.get(i).getResolution());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,12 +94,12 @@ public class ListHelperTest {
|
||||
null, VIDEO_ONLY_STREAMS_TEST_LIST, true, true);
|
||||
|
||||
List<String> expected =
|
||||
Arrays.asList("720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
|
||||
List.of("720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
|
||||
|
||||
assertEquals(expected.size(), result.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertEquals(expected.get(i), result.get(i).resolution);
|
||||
assertTrue(result.get(i).isVideoOnly);
|
||||
assertEquals(expected.get(i), result.get(i).getResolution());
|
||||
assertTrue(result.get(i).isVideoOnly());
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////
|
||||
@@ -93,11 +108,11 @@ public class ListHelperTest {
|
||||
|
||||
result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
|
||||
VIDEO_STREAMS_TEST_LIST, null, false, true);
|
||||
expected = Arrays.asList("720p", "480p", "360p", "240p", "144p");
|
||||
expected = List.of("720p", "480p", "360p", "240p", "144p");
|
||||
assertEquals(expected.size(), result.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertEquals(expected.get(i), result.get(i).resolution);
|
||||
assertFalse(result.get(i).isVideoOnly);
|
||||
assertEquals(expected.get(i), result.get(i).getResolution());
|
||||
assertFalse(result.get(i).isVideoOnly());
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
@@ -106,17 +121,16 @@ public class ListHelperTest {
|
||||
|
||||
result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4, true,
|
||||
VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, true, true);
|
||||
expected = Arrays.asList("144p", "240p", "360p", "480p", "720p", "720p60",
|
||||
expected = List.of("144p", "240p", "360p", "480p", "720p", "720p60",
|
||||
"1080p", "1080p60", "1440p60", "2160p", "2160p60");
|
||||
final List<String> expectedVideoOnly =
|
||||
Arrays.asList("720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
|
||||
List.of("720p", "720p60", "1080p", "1080p60", "1440p60", "2160p", "2160p60");
|
||||
|
||||
assertEquals(expected.size(), result.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertEquals(expected.get(i), result.get(i).resolution);
|
||||
assertEquals(
|
||||
expectedVideoOnly.contains(result.get(i).resolution),
|
||||
result.get(i).isVideoOnly);
|
||||
assertEquals(expected.get(i), result.get(i).getResolution());
|
||||
assertEquals(expectedVideoOnly.contains(result.get(i).getResolution()),
|
||||
result.get(i).isVideoOnly());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -128,105 +142,109 @@ public class ListHelperTest {
|
||||
|
||||
final List<VideoStream> result = ListHelper.getSortedStreamVideosList(MediaFormat.MPEG_4,
|
||||
false, VIDEO_STREAMS_TEST_LIST, VIDEO_ONLY_STREAMS_TEST_LIST, false, false);
|
||||
final List<String> expected = Arrays.asList(
|
||||
final List<String> expected = List.of(
|
||||
"1080p60", "1080p", "720p60", "720p", "480p", "360p", "240p", "144p");
|
||||
assertEquals(expected.size(), result.size());
|
||||
for (int i = 0; i < result.size(); i++) {
|
||||
assertEquals(expected.get(i), result.get(i).resolution);
|
||||
assertEquals(expected.get(i), result.get(i).getResolution());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDefaultResolutionTest() {
|
||||
final List<VideoStream> testList = Arrays.asList(
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "720p"),
|
||||
new VideoStream("", MediaFormat.v3GPP, /**/ "240p"),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "480p"),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "240p"),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "240p"),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "144p"),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "360p"),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "360p"));
|
||||
final List<VideoStream> testList = new ArrayList<>(List.of(
|
||||
generateVideoStream("mpeg_4-720", MediaFormat.MPEG_4, "720p", false),
|
||||
generateVideoStream("v3gpp-240", MediaFormat.v3GPP, "240p", false),
|
||||
generateVideoStream("webm-480", MediaFormat.WEBM, "480p", false),
|
||||
generateVideoStream("webm-240", MediaFormat.WEBM, "240p", false),
|
||||
generateVideoStream("mpeg_4-240", MediaFormat.MPEG_4, "240p", false),
|
||||
generateVideoStream("webm-144", MediaFormat.WEBM, "144p", false),
|
||||
generateVideoStream("mpeg_4-360", MediaFormat.MPEG_4, "360p", false),
|
||||
generateVideoStream("webm-360", MediaFormat.WEBM, "360p", false)));
|
||||
VideoStream result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"720p", BEST_RESOLUTION_KEY, MediaFormat.MPEG_4, testList));
|
||||
assertEquals("720p", result.resolution);
|
||||
assertEquals("720p", result.getResolution());
|
||||
assertEquals(MediaFormat.MPEG_4, result.getFormat());
|
||||
|
||||
// Have resolution and the format
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"480p", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("480p", result.resolution);
|
||||
assertEquals("480p", result.getResolution());
|
||||
assertEquals(MediaFormat.WEBM, result.getFormat());
|
||||
|
||||
// Have resolution but not the format
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"480p", BEST_RESOLUTION_KEY, MediaFormat.MPEG_4, testList));
|
||||
assertEquals("480p", result.resolution);
|
||||
assertEquals("480p", result.getResolution());
|
||||
assertEquals(MediaFormat.WEBM, result.getFormat());
|
||||
|
||||
// Have resolution and the format
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"240p", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("240p", result.resolution);
|
||||
assertEquals("240p", result.getResolution());
|
||||
assertEquals(MediaFormat.WEBM, result.getFormat());
|
||||
|
||||
// The best resolution
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
BEST_RESOLUTION_KEY, BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("720p", result.resolution);
|
||||
assertEquals("720p", result.getResolution());
|
||||
assertEquals(MediaFormat.MPEG_4, result.getFormat());
|
||||
|
||||
// Doesn't have the 60fps variant and format
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"720p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("720p", result.resolution);
|
||||
assertEquals("720p", result.getResolution());
|
||||
assertEquals(MediaFormat.MPEG_4, result.getFormat());
|
||||
|
||||
// Doesn't have the 60fps variant
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"480p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("480p", result.resolution);
|
||||
assertEquals("480p", result.getResolution());
|
||||
assertEquals(MediaFormat.WEBM, result.getFormat());
|
||||
|
||||
// Doesn't have the resolution, will return the best one
|
||||
result = testList.get(ListHelper.getDefaultResolutionIndex(
|
||||
"2160p60", BEST_RESOLUTION_KEY, MediaFormat.WEBM, testList));
|
||||
assertEquals("720p", result.resolution);
|
||||
assertEquals("720p", result.getResolution());
|
||||
assertEquals(MediaFormat.MPEG_4, result.getFormat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHighestQualityAudioFormatTest() {
|
||||
AudioStream stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getHighestQualityAudioIndex(
|
||||
MediaFormat.M4A, AUDIO_STREAMS_TEST_LIST));
|
||||
Comparator<AudioStream> cmp = ListHelper.getAudioFormatComparator(MediaFormat.M4A, false);
|
||||
AudioStream stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
|
||||
AUDIO_STREAMS_TEST_LIST, cmp));
|
||||
assertEquals(320, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.M4A, stream.getFormat());
|
||||
|
||||
stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getHighestQualityAudioIndex(
|
||||
MediaFormat.WEBMA, AUDIO_STREAMS_TEST_LIST));
|
||||
cmp = ListHelper.getAudioFormatComparator(MediaFormat.WEBMA, false);
|
||||
stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
|
||||
AUDIO_STREAMS_TEST_LIST, cmp));
|
||||
assertEquals(320, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.WEBMA, stream.getFormat());
|
||||
|
||||
stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getHighestQualityAudioIndex(
|
||||
MediaFormat.MP3, AUDIO_STREAMS_TEST_LIST));
|
||||
cmp = ListHelper.getAudioFormatComparator(MediaFormat.MP3, false);
|
||||
stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
|
||||
AUDIO_STREAMS_TEST_LIST, cmp));
|
||||
assertEquals(192, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.MP3, stream.getFormat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHighestQualityAudioFormatPreferredAbsent() {
|
||||
final Comparator<AudioStream> cmp =
|
||||
ListHelper.getAudioFormatComparator(MediaFormat.MP3, false);
|
||||
|
||||
//////////////////////////////////////////
|
||||
// Doesn't contain the preferred format //
|
||||
////////////////////////////////////////
|
||||
|
||||
List<AudioStream> testList = Arrays.asList(
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 128),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192));
|
||||
List<AudioStream> testList = List.of(
|
||||
generateAudioStream("m4a-128", MediaFormat.M4A, 128),
|
||||
generateAudioStream("webma-192", MediaFormat.WEBMA, 192));
|
||||
// List doesn't contains this format
|
||||
// It should fallback to the highest bitrate audio no matter what format it is
|
||||
AudioStream stream = testList.get(ListHelper.getHighestQualityAudioIndex(
|
||||
MediaFormat.MP3, testList));
|
||||
AudioStream stream = testList.get(ListHelper.getAudioIndexByHighestRank(testList, cmp));
|
||||
assertEquals(192, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.WEBMA, stream.getFormat());
|
||||
|
||||
@@ -234,72 +252,78 @@ public class ListHelperTest {
|
||||
// Multiple not-preferred-formats and equal bitrates //
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
testList = new ArrayList<>(Arrays.asList(
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192),
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 192),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192),
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 192),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192),
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 192),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192)));
|
||||
testList = new ArrayList<>(List.of(
|
||||
generateAudioStream("webma-192-1", MediaFormat.WEBMA, 192),
|
||||
generateAudioStream("m4a-192-1", MediaFormat.M4A, 192),
|
||||
generateAudioStream("webma-192-2", MediaFormat.WEBMA, 192),
|
||||
generateAudioStream("m4a-192-2", MediaFormat.M4A, 192),
|
||||
generateAudioStream("webma-192-3", MediaFormat.WEBMA, 192),
|
||||
generateAudioStream("m4a-192-3", MediaFormat.M4A, 192),
|
||||
generateAudioStream("webma-192-4", MediaFormat.WEBMA, 192)));
|
||||
// List doesn't contains this format, it should fallback to the highest bitrate audio and
|
||||
// the highest quality format.
|
||||
stream = testList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.MP3, testList));
|
||||
stream =
|
||||
testList.get(ListHelper.getAudioIndexByHighestRank(testList, cmp));
|
||||
assertEquals(192, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.M4A, stream.getFormat());
|
||||
|
||||
// Adding a new format and bitrate. Adding another stream will have no impact since
|
||||
// it's not a preferred format.
|
||||
testList.add(new AudioStream("", MediaFormat.WEBMA, /**/ 192));
|
||||
stream = testList.get(ListHelper.getHighestQualityAudioIndex(MediaFormat.MP3, testList));
|
||||
testList.add(generateAudioStream("webma-192-5", MediaFormat.WEBMA, 192));
|
||||
stream =
|
||||
testList.get(ListHelper.getAudioIndexByHighestRank(testList, cmp));
|
||||
assertEquals(192, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.M4A, stream.getFormat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getHighestQualityAudioNull() {
|
||||
assertEquals(-1, ListHelper.getHighestQualityAudioIndex(null, null));
|
||||
assertEquals(-1, ListHelper.getHighestQualityAudioIndex(null, new ArrayList<>()));
|
||||
final Comparator<AudioStream> cmp = ListHelper.getAudioFormatComparator(null, false);
|
||||
assertEquals(-1, ListHelper.getAudioIndexByHighestRank(null, cmp));
|
||||
assertEquals(-1, ListHelper.getAudioIndexByHighestRank(new ArrayList<>(), cmp));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLowestQualityAudioFormatTest() {
|
||||
AudioStream stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getMostCompactAudioIndex(
|
||||
MediaFormat.M4A, AUDIO_STREAMS_TEST_LIST));
|
||||
Comparator<AudioStream> cmp = ListHelper.getAudioFormatComparator(MediaFormat.M4A, true);
|
||||
AudioStream stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
|
||||
AUDIO_STREAMS_TEST_LIST, cmp));
|
||||
assertEquals(128, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.M4A, stream.getFormat());
|
||||
|
||||
stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getMostCompactAudioIndex(
|
||||
MediaFormat.WEBMA, AUDIO_STREAMS_TEST_LIST));
|
||||
cmp = ListHelper.getAudioFormatComparator(MediaFormat.WEBMA, true);
|
||||
stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
|
||||
AUDIO_STREAMS_TEST_LIST, cmp));
|
||||
assertEquals(64, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.WEBMA, stream.getFormat());
|
||||
|
||||
stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getMostCompactAudioIndex(
|
||||
MediaFormat.MP3, AUDIO_STREAMS_TEST_LIST));
|
||||
cmp = ListHelper.getAudioFormatComparator(MediaFormat.MP3, true);
|
||||
stream = AUDIO_STREAMS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
|
||||
AUDIO_STREAMS_TEST_LIST, cmp));
|
||||
assertEquals(64, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.MP3, stream.getFormat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLowestQualityAudioFormatPreferredAbsent() {
|
||||
Comparator<AudioStream> cmp = ListHelper.getAudioFormatComparator(MediaFormat.MP3, true);
|
||||
|
||||
//////////////////////////////////////////
|
||||
// Doesn't contain the preferred format //
|
||||
////////////////////////////////////////
|
||||
|
||||
List<AudioStream> testList = new ArrayList<>(Arrays.asList(
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 128),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192)));
|
||||
List<AudioStream> testList = new ArrayList<>(List.of(
|
||||
generateAudioStream("m4a-128", MediaFormat.M4A, 128),
|
||||
generateAudioStream("webma-192-1", MediaFormat.WEBMA, 192)));
|
||||
// List doesn't contains this format
|
||||
// It should fallback to the most compact audio no matter what format it is.
|
||||
AudioStream stream = testList.get(ListHelper.getMostCompactAudioIndex(
|
||||
MediaFormat.MP3, testList));
|
||||
AudioStream stream = testList.get(ListHelper.getAudioIndexByHighestRank(testList, cmp));
|
||||
assertEquals(128, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.M4A, stream.getFormat());
|
||||
|
||||
// WEBMA is more compact than M4A
|
||||
testList.add(new AudioStream("", MediaFormat.WEBMA, /**/ 128));
|
||||
stream = testList.get(ListHelper.getMostCompactAudioIndex(MediaFormat.MP3, testList));
|
||||
testList.add(generateAudioStream("webma-192-2", MediaFormat.WEBMA, 128));
|
||||
stream = testList.get(ListHelper.getAudioIndexByHighestRank(testList, cmp));
|
||||
assertEquals(128, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.WEBMA, stream.getFormat());
|
||||
|
||||
@@ -307,42 +331,80 @@ public class ListHelperTest {
|
||||
// Multiple not-preferred-formats and equal bitrates //
|
||||
//////////////////////////////////////////////////////
|
||||
|
||||
testList = new ArrayList<>(Arrays.asList(
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192),
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 192),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 256),
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 192),
|
||||
new AudioStream("", MediaFormat.WEBMA, /**/ 192),
|
||||
new AudioStream("", MediaFormat.M4A, /**/ 192)));
|
||||
testList = new ArrayList<>(List.of(
|
||||
generateAudioStream("webma-192-1", MediaFormat.WEBMA, 192),
|
||||
generateAudioStream("m4a-192-1", MediaFormat.M4A, 192),
|
||||
generateAudioStream("webma-256", MediaFormat.WEBMA, 256),
|
||||
generateAudioStream("m4a-192-2", MediaFormat.M4A, 192),
|
||||
generateAudioStream("webma-192-2", MediaFormat.WEBMA, 192),
|
||||
generateAudioStream("m4a-192-3", MediaFormat.M4A, 192)));
|
||||
// List doesn't contain this format
|
||||
// It should fallback to the most compact audio no matter what format it is.
|
||||
stream = testList.get(ListHelper.getMostCompactAudioIndex(MediaFormat.MP3, testList));
|
||||
stream = testList.get(
|
||||
ListHelper.getAudioIndexByHighestRank(testList, cmp));
|
||||
assertEquals(192, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.WEBMA, stream.getFormat());
|
||||
|
||||
// Should be same as above
|
||||
stream = testList.get(ListHelper.getMostCompactAudioIndex(null, testList));
|
||||
cmp = ListHelper.getAudioFormatComparator(null, true);
|
||||
stream = testList.get(
|
||||
ListHelper.getAudioIndexByHighestRank(testList, cmp));
|
||||
assertEquals(192, stream.getAverageBitrate());
|
||||
assertEquals(MediaFormat.WEBMA, stream.getFormat());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getLowestQualityAudioNull() {
|
||||
assertEquals(-1, ListHelper.getMostCompactAudioIndex(null, null));
|
||||
assertEquals(-1, ListHelper.getMostCompactAudioIndex(null, new ArrayList<>()));
|
||||
final Comparator<AudioStream> cmp = ListHelper.getAudioFormatComparator(null, false);
|
||||
assertEquals(-1, ListHelper.getAudioIndexByHighestRank(null, cmp));
|
||||
assertEquals(-1, ListHelper.getAudioIndexByHighestRank(new ArrayList<>(), cmp));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getAudioTrack() {
|
||||
// English language
|
||||
Comparator<AudioStream> cmp =
|
||||
ListHelper.getAudioTrackComparator(Locale.ENGLISH, false, false);
|
||||
AudioStream stream = AUDIO_TRACKS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
|
||||
AUDIO_TRACKS_TEST_LIST, cmp));
|
||||
assertEquals("en.or", stream.getId());
|
||||
|
||||
// German language
|
||||
cmp = ListHelper.getAudioTrackComparator(Locale.GERMAN, false, false);
|
||||
stream = AUDIO_TRACKS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
|
||||
AUDIO_TRACKS_TEST_LIST, cmp));
|
||||
assertEquals("de.du", stream.getId());
|
||||
|
||||
// German language, but prefer original
|
||||
cmp = ListHelper.getAudioTrackComparator(Locale.GERMAN, true, false);
|
||||
stream = AUDIO_TRACKS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
|
||||
AUDIO_TRACKS_TEST_LIST, cmp));
|
||||
assertEquals("en.or", stream.getId());
|
||||
|
||||
// Prefer descriptive audio
|
||||
cmp = ListHelper.getAudioTrackComparator(Locale.ENGLISH, false, true);
|
||||
stream = AUDIO_TRACKS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
|
||||
AUDIO_TRACKS_TEST_LIST, cmp));
|
||||
assertEquals("en.ds", stream.getId());
|
||||
|
||||
// Japanese language, fall back to original
|
||||
cmp = ListHelper.getAudioTrackComparator(Locale.JAPANESE, true, false);
|
||||
stream = AUDIO_TRACKS_TEST_LIST.get(ListHelper.getAudioIndexByHighestRank(
|
||||
AUDIO_TRACKS_TEST_LIST, cmp));
|
||||
assertEquals("en.or", stream.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getVideoDefaultStreamIndexCombinations() {
|
||||
final List<VideoStream> testList = Arrays.asList(
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "1080p"),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "720p60"),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "720p"),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "480p"),
|
||||
new VideoStream("", MediaFormat.MPEG_4, /**/ "360p"),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "360p"),
|
||||
new VideoStream("", MediaFormat.v3GPP, /**/ "240p60"),
|
||||
new VideoStream("", MediaFormat.WEBM, /**/ "144p"));
|
||||
final List<VideoStream> testList = List.of(
|
||||
generateVideoStream("mpeg_4-1080", MediaFormat.MPEG_4, "1080p", false),
|
||||
generateVideoStream("mpeg_4-720_60", MediaFormat.MPEG_4, "720p60", false),
|
||||
generateVideoStream("mpeg_4-720", MediaFormat.MPEG_4, "720p", false),
|
||||
generateVideoStream("webm-480", MediaFormat.WEBM, "480p", false),
|
||||
generateVideoStream("mpeg_4-360", MediaFormat.MPEG_4, "360p", false),
|
||||
generateVideoStream("webm-360", MediaFormat.WEBM, "360p", false),
|
||||
generateVideoStream("v3gpp-240_60", MediaFormat.v3GPP, "240p60", false),
|
||||
generateVideoStream("webm-144", MediaFormat.WEBM, "144p", false));
|
||||
|
||||
// exact matches
|
||||
assertEquals(1, ListHelper.getVideoStreamIndex("720p60", MediaFormat.MPEG_4, testList));
|
||||
@@ -375,4 +437,46 @@ public class ListHelperTest {
|
||||
// Can't find a match
|
||||
assertEquals(-1, ListHelper.getVideoStreamIndex("100p", null, testList));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static AudioStream generateAudioStream(@NonNull final String id,
|
||||
@Nullable final MediaFormat mediaFormat,
|
||||
final int averageBitrate) {
|
||||
return new AudioStream.Builder()
|
||||
.setId(id)
|
||||
.setContent("", true)
|
||||
.setMediaFormat(mediaFormat)
|
||||
.setAverageBitrate(averageBitrate)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static AudioStream generateAudioTrack(
|
||||
@NonNull final String id,
|
||||
@Nullable final String trackId,
|
||||
@Nullable final Locale locale,
|
||||
@Nullable final AudioTrackType trackType) {
|
||||
return new AudioStream.Builder()
|
||||
.setId(id)
|
||||
.setContent("", true)
|
||||
.setMediaFormat(MediaFormat.M4A)
|
||||
.setAverageBitrate(128)
|
||||
.setAudioTrackId(trackId)
|
||||
.setAudioLocale(locale)
|
||||
.setAudioTrackType(trackType)
|
||||
.build();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private static VideoStream generateVideoStream(@NonNull final String id,
|
||||
@Nullable final MediaFormat mediaFormat,
|
||||
@NonNull final String resolution,
|
||||
final boolean isVideoOnly) {
|
||||
return new VideoStream.Builder()
|
||||
.setId(id)
|
||||
.setContent("", true)
|
||||
.setIsVideoOnly(isVideoOnly)
|
||||
.setResolution(resolution)
|
||||
.setMediaFormat(mediaFormat)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.schabi.newpipe.util.external_communication;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.schabi.newpipe.util.text.TimestampExtractor;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
package org.schabi.newpipe.util.image;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.schabi.newpipe.extractor.Image.HEIGHT_UNKNOWN;
|
||||
import static org.schabi.newpipe.extractor.Image.WIDTH_UNKNOWN;
|
||||
import static org.schabi.newpipe.util.image.ImageStrategy.choosePreferredImage;
|
||||
import static org.schabi.newpipe.util.image.ImageStrategy.estimatePixelCount;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.schabi.newpipe.extractor.Image;
|
||||
import org.schabi.newpipe.extractor.Image.ResolutionLevel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ImageStrategyTest {
|
||||
|
||||
private static final List<ResolutionLevel> RESOLUTION_LEVELS = List.of(
|
||||
ResolutionLevel.LOW, ResolutionLevel.MEDIUM, ResolutionLevel.HIGH);
|
||||
|
||||
private Image img(final int height, final int width) {
|
||||
return new Image("", height, width, ResolutionLevel.UNKNOWN);
|
||||
}
|
||||
|
||||
private Image img(final String url, final ResolutionLevel resolutionLevel) {
|
||||
return new Image(url, HEIGHT_UNKNOWN, WIDTH_UNKNOWN, resolutionLevel);
|
||||
}
|
||||
|
||||
private Image img(final String url,
|
||||
final int height,
|
||||
final int width,
|
||||
final ResolutionLevel resolutionLevel) {
|
||||
return new Image(url, height, width, resolutionLevel);
|
||||
}
|
||||
|
||||
private void assertChoosePreferredImage(final String low,
|
||||
final String medium,
|
||||
final String high,
|
||||
final List<Image> images) {
|
||||
assertEquals(low, choosePreferredImage(images, PreferredImageQuality.LOW));
|
||||
assertEquals(medium, choosePreferredImage(images, PreferredImageQuality.MEDIUM));
|
||||
assertEquals(high, choosePreferredImage(images, PreferredImageQuality.HIGH));
|
||||
}
|
||||
|
||||
|
||||
// CHECKSTYLE:OFF
|
||||
@Test
|
||||
public void testEstimatePixelCountAllKnown() {
|
||||
assertEquals(20000.0, estimatePixelCount(img(100, 200), 1.0), 0.0);
|
||||
assertEquals(20000.0, estimatePixelCount(img(100, 200), 12.0), 0.0);
|
||||
assertEquals( 100.0, estimatePixelCount(img(100, 1), 12.0), 0.0);
|
||||
assertEquals( 100.0, estimatePixelCount(img( 1, 100), 0.5), 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEstimatePixelCountHeightUnknown() {
|
||||
assertEquals( 10000.0, estimatePixelCount(img(HEIGHT_UNKNOWN, 100), 1.0 ), 0.0);
|
||||
assertEquals( 20000.0, estimatePixelCount(img(HEIGHT_UNKNOWN, 200), 2.0 ), 0.0);
|
||||
assertEquals( 10.0, estimatePixelCount(img(HEIGHT_UNKNOWN, 1), 0.1 ), 0.0);
|
||||
assertEquals(230400.0, estimatePixelCount(img(HEIGHT_UNKNOWN, 640), 16.0/9.0), 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEstimatePixelCountWidthUnknown() {
|
||||
assertEquals( 10000.0, estimatePixelCount(img(100, WIDTH_UNKNOWN), 1.0 ), 0.0);
|
||||
assertEquals( 20000.0, estimatePixelCount(img(200, WIDTH_UNKNOWN), 0.5 ), 0.0);
|
||||
assertEquals( 12.0, estimatePixelCount(img( 1, WIDTH_UNKNOWN), 12.0 ), 0.0);
|
||||
assertEquals(230400.0, estimatePixelCount(img(360, WIDTH_UNKNOWN), 16.0/9.0), 0.0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEstimatePixelCountAllUnknown() {
|
||||
assertEquals(0.0, estimatePixelCount(img(HEIGHT_UNKNOWN, WIDTH_UNKNOWN), 1.0 ), 0.0);
|
||||
assertEquals(0.0, estimatePixelCount(img(HEIGHT_UNKNOWN, WIDTH_UNKNOWN), 12.0 ), 0.0);
|
||||
assertEquals(0.0, estimatePixelCount(img(HEIGHT_UNKNOWN, WIDTH_UNKNOWN), 0.1 ), 0.0);
|
||||
assertEquals(0.0, estimatePixelCount(img(HEIGHT_UNKNOWN, WIDTH_UNKNOWN), 16.0/9.0), 0.0);
|
||||
}
|
||||
// CHECKSTYLE:ON
|
||||
|
||||
|
||||
@Test
|
||||
public void testChoosePreferredImageAllKnown() {
|
||||
// the resolution level of the images is more important than the actual resolution
|
||||
assertChoosePreferredImage("a", "b", "c", List.of(
|
||||
img("a", 1, 1, ResolutionLevel.LOW),
|
||||
img("b", 200, 200, ResolutionLevel.MEDIUM),
|
||||
img("c", 10000, 10000, ResolutionLevel.HIGH)
|
||||
));
|
||||
assertChoosePreferredImage("a", "b", "c", List.of(
|
||||
img("a", 10000, 10000, ResolutionLevel.LOW),
|
||||
img("b", 200, 200, ResolutionLevel.MEDIUM),
|
||||
img("c", 1, 1, ResolutionLevel.HIGH)
|
||||
));
|
||||
|
||||
assertChoosePreferredImage("b", "c", "d", List.of(
|
||||
img("a", 2, 1, ResolutionLevel.LOW),
|
||||
img("b", 50, 25, ResolutionLevel.LOW),
|
||||
img("c", 200, 100, ResolutionLevel.LOW),
|
||||
img("d", 300, 150, ResolutionLevel.LOW)
|
||||
));
|
||||
|
||||
assertChoosePreferredImage("c", "d", "d", List.of(
|
||||
img("a", 2, 1, ResolutionLevel.MEDIUM),
|
||||
img("b", 50, 25, ResolutionLevel.MEDIUM),
|
||||
img("c", 60, 30, ResolutionLevel.MEDIUM),
|
||||
img("d", 300, 150, ResolutionLevel.MEDIUM)
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChoosePreferredImageSomeKnown() {
|
||||
// the resolution level of the images is more important than the actual resolution
|
||||
assertChoosePreferredImage("a", "b", "c", List.of(
|
||||
img("a", 1, WIDTH_UNKNOWN, ResolutionLevel.LOW),
|
||||
img("b", HEIGHT_UNKNOWN, 200, ResolutionLevel.MEDIUM),
|
||||
img("c", 10000, WIDTH_UNKNOWN, ResolutionLevel.HIGH)
|
||||
));
|
||||
assertChoosePreferredImage("a", "b", "c", List.of(
|
||||
img("a", HEIGHT_UNKNOWN, 10000, ResolutionLevel.LOW),
|
||||
img("b", 200, WIDTH_UNKNOWN, ResolutionLevel.MEDIUM),
|
||||
img("c", HEIGHT_UNKNOWN, 1, ResolutionLevel.HIGH)
|
||||
));
|
||||
|
||||
assertChoosePreferredImage("b", "c", "d", List.of(
|
||||
img("a", HEIGHT_UNKNOWN, 1, ResolutionLevel.HIGH),
|
||||
img("b", 50, WIDTH_UNKNOWN, ResolutionLevel.HIGH),
|
||||
img("c", HEIGHT_UNKNOWN, 120, ResolutionLevel.HIGH),
|
||||
img("d", 340, WIDTH_UNKNOWN, ResolutionLevel.HIGH)
|
||||
));
|
||||
|
||||
assertChoosePreferredImage("c", "d", "d", List.of(
|
||||
img("a", 2, WIDTH_UNKNOWN, ResolutionLevel.MEDIUM),
|
||||
img("b", HEIGHT_UNKNOWN, 50, ResolutionLevel.MEDIUM),
|
||||
img("c", 60, WIDTH_UNKNOWN, ResolutionLevel.MEDIUM),
|
||||
img("d", HEIGHT_UNKNOWN, 340, ResolutionLevel.MEDIUM)
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChoosePreferredImageMixed() {
|
||||
for (final ResolutionLevel resolutionLevel : RESOLUTION_LEVELS) {
|
||||
assertChoosePreferredImage("d", "b", "c", List.of(
|
||||
img("a", ResolutionLevel.UNKNOWN),
|
||||
img("b", 200, 100, resolutionLevel),
|
||||
img("c", 400, WIDTH_UNKNOWN, resolutionLevel),
|
||||
img("d", HEIGHT_UNKNOWN, 50, resolutionLevel),
|
||||
img("e", resolutionLevel)
|
||||
));
|
||||
}
|
||||
for (final ResolutionLevel resolutionLevel : RESOLUTION_LEVELS) {
|
||||
assertChoosePreferredImage("b", "b", "b", List.of(
|
||||
img("a", ResolutionLevel.UNKNOWN),
|
||||
img("b", 200, 100, resolutionLevel),
|
||||
img("e", resolutionLevel)
|
||||
));
|
||||
}
|
||||
assertChoosePreferredImage("b", "b", "e", List.of(
|
||||
img("a", ResolutionLevel.UNKNOWN),
|
||||
img("b", 200, 100, ResolutionLevel.LOW),
|
||||
img("e", ResolutionLevel.HIGH)
|
||||
));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChoosePreferredImageAllUnknown() {
|
||||
assertChoosePreferredImage("b", "c", "d", List.of(
|
||||
img("a", ResolutionLevel.UNKNOWN),
|
||||
img("b", ResolutionLevel.LOW),
|
||||
img("c", ResolutionLevel.MEDIUM),
|
||||
img("d", ResolutionLevel.HIGH)
|
||||
));
|
||||
assertChoosePreferredImage("c", "c", "d", List.of(
|
||||
img("a", ResolutionLevel.UNKNOWN),
|
||||
img("c", ResolutionLevel.MEDIUM),
|
||||
img("d", ResolutionLevel.HIGH)
|
||||
));
|
||||
assertChoosePreferredImage("b", "c", "c", List.of(
|
||||
img("a", ResolutionLevel.UNKNOWN),
|
||||
img("b", ResolutionLevel.LOW),
|
||||
img("c", ResolutionLevel.MEDIUM)
|
||||
));
|
||||
|
||||
// UNKNOWN is avoided as much as possible
|
||||
assertChoosePreferredImage("d", "d", "d", List.of(
|
||||
img("a", ResolutionLevel.UNKNOWN),
|
||||
img("d", ResolutionLevel.HIGH)
|
||||
));
|
||||
assertChoosePreferredImage("b", "b", "b", List.of(
|
||||
img("a", ResolutionLevel.UNKNOWN),
|
||||
img("b", ResolutionLevel.LOW)
|
||||
));
|
||||
assertChoosePreferredImage("a", "a", "a", List.of(
|
||||
img("a", ResolutionLevel.UNKNOWN)
|
||||
));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user