jellyfin/MediaBrowser.Tests/MediaEncoding/Subtitles/AssParserTests.cs

86 lines
4.9 KiB
C#
Raw Normal View History

2015-03-26 04:44:24 +00:00
using System.Text;
using MediaBrowser.MediaEncoding.Subtitles;
2015-07-20 03:43:13 +00:00
using MediaBrowser.Model.MediaInfo;
2014-08-31 18:28:20 +00:00
using Microsoft.VisualStudio.TestTools.UnitTesting;
2014-05-11 04:23:16 +00:00
using System.Collections.Generic;
using System.IO;
using System.Threading;
using Emby.Server.MediaEncoding.Subtitles;
2014-05-11 04:23:16 +00:00
namespace MediaBrowser.Tests.MediaEncoding.Subtitles {
[TestClass]
2014-08-31 18:28:20 +00:00
public class AssParserTests {
2014-05-11 04:23:16 +00:00
[TestMethod]
public void TestParse() {
var expectedSubs =
new SubtitleTrackInfo {
TrackEvents = new List<SubtitleTrackEvent> {
new SubtitleTrackEvent {
Id = "1",
StartPositionTicks = 24000000,
EndPositionTicks = 72000000,
Text =
2014-08-31 18:28:20 +00:00
"Senator, we're "+ParserValues.NewLine+"making our final "+ParserValues.NewLine+"approach into Coruscant."
2014-05-11 04:23:16 +00:00
},
new SubtitleTrackEvent {
Id = "2",
StartPositionTicks = 97100000,
EndPositionTicks = 133900000,
Text =
"Very good, Lieutenant."
},
new SubtitleTrackEvent {
Id = "3",
StartPositionTicks = 150400000,
EndPositionTicks = 180400000,
2014-08-31 18:28:20 +00:00
Text = "It's "+ParserValues.NewLine+"a "+ParserValues.NewLine+"trap!"
2014-05-11 04:23:16 +00:00
}
}
};
2014-08-22 02:24:38 +00:00
var sut = new AssParser();
2014-05-11 04:23:16 +00:00
2014-08-31 18:28:20 +00:00
var stream = File.OpenRead(@"MediaEncoding\Subtitles\TestSubtitles\data.ass");
2014-05-11 04:23:16 +00:00
var result = sut.Parse(stream, CancellationToken.None);
2014-05-11 04:23:16 +00:00
Assert.IsNotNull(result);
Assert.AreEqual(expectedSubs.TrackEvents.Count,result.TrackEvents.Count);
for (int i = 0; i < expectedSubs.TrackEvents.Count; i++)
{
Assert.AreEqual(expectedSubs.TrackEvents[i].Id, result.TrackEvents[i].Id);
Assert.AreEqual(expectedSubs.TrackEvents[i].StartPositionTicks, result.TrackEvents[i].StartPositionTicks);
Assert.AreEqual(expectedSubs.TrackEvents[i].EndPositionTicks, result.TrackEvents[i].EndPositionTicks);
Assert.AreEqual(expectedSubs.TrackEvents[i].Text, result.TrackEvents[i].Text);
}
}
2015-03-26 04:44:24 +00:00
[TestMethod]
public void TestParse2()
{
var sut = new AssParser();
var stream = File.OpenRead(@"MediaEncoding\Subtitles\TestSubtitles\data2.ass");
var result = sut.Parse(stream, CancellationToken.None);
Assert.IsNotNull(result);
using (var ms = new MemoryStream())
{
var writer = new SrtWriter();
writer.Write(result, ms, CancellationToken.None);
ms.Position = 0;
var text = Encoding.UTF8.GetString(ms.ToArray());
var b = text;
}
}
2014-05-11 04:23:16 +00:00
}
}