Merge pull request #7682 from 1337joe/test-preferred-audio-language

This commit is contained in:
Bond-009 2022-06-14 15:23:40 +02:00 committed by GitHub
commit a881733377
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 8 deletions

View File

@ -13,11 +13,11 @@ namespace Emby.Server.Implementations.Library
{
public static int? GetDefaultAudioStreamIndex(IReadOnlyList<MediaStream> streams, IReadOnlyList<string> preferredLanguages, bool preferDefaultTrack)
{
var sortedStreams = GetSortedStreams(streams, MediaStreamType.Audio, preferredLanguages);
var sortedStreams = GetSortedStreams(streams, MediaStreamType.Audio, preferredLanguages).ToList();
if (preferDefaultTrack)
{
var defaultStream = streams.FirstOrDefault(i => i.IsDefault);
var defaultStream = sortedStreams.FirstOrDefault(i => i.IsDefault);
if (defaultStream != null)
{

View File

@ -16,15 +16,39 @@ public class MediaStreamSelectorTests
}
[Theory]
[InlineData(true)]
[InlineData(false)]
public void GetDefaultAudioStreamIndex_WithoutDefault_NotNull(bool preferDefaultTrack)
[InlineData(new string[0], false, 1)]
[InlineData(new string[0], true, 1)]
[InlineData(new[] { "eng" }, false, 2)]
[InlineData(new[] { "eng" }, true, 1)]
[InlineData(new[] { "eng", "fre" }, false, 2)]
[InlineData(new[] { "fre", "eng" }, false, 1)]
[InlineData(new[] { "eng", "fre" }, true, 1)]
public void GetDefaultAudioStreamIndex_PreferredLanguage_SelectsCorrect(string[] preferredLanguages, bool preferDefaultTrack, int expectedIndex)
{
var streams = new[]
var streams = new MediaStream[]
{
new MediaStream()
new()
{
Index = 0,
Type = MediaStreamType.Video,
IsDefault = true
},
new()
{
Index = 1,
Type = MediaStreamType.Audio,
Language = "fre",
IsDefault = true
},
new()
{
Index = 2,
Type = MediaStreamType.Audio,
Language = "eng",
IsDefault = false
}
};
Assert.NotNull(MediaStreamSelector.GetDefaultAudioStreamIndex(streams, Array.Empty<string>(), preferDefaultTrack));
Assert.Equal(expectedIndex, MediaStreamSelector.GetDefaultAudioStreamIndex(streams, preferredLanguages, preferDefaultTrack));
}
}