2021-11-02 21:46:44 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using BililiveRecorder.Flv.Grouping;
|
|
|
|
using BililiveRecorder.Flv.Pipeline;
|
|
|
|
using BililiveRecorder.Flv.Writer;
|
|
|
|
using BililiveRecorder.Flv.Xml;
|
|
|
|
using VerifyTests;
|
|
|
|
using VerifyXunit;
|
|
|
|
using Xunit;
|
|
|
|
|
2021-11-13 02:01:03 +08:00
|
|
|
namespace BililiveRecorder.Flv.Tests.RuleTests
|
2021-11-02 21:46:44 +08:00
|
|
|
{
|
|
|
|
[UsesVerify]
|
|
|
|
[ExpectationPath("Good")]
|
|
|
|
public class IntegratedGoodTests : IntegratedTestBase
|
|
|
|
{
|
2022-06-17 17:42:50 +08:00
|
|
|
[Theory()]
|
2021-11-02 21:46:44 +08:00
|
|
|
[Expectation("StandardTest")]
|
2022-06-07 19:50:34 +08:00
|
|
|
[SampleFileTestData("../data/flv/TestData/Good", "*.xml")]
|
2021-11-02 21:46:44 +08:00
|
|
|
public async Task StrictTestsAsync(string path)
|
|
|
|
{
|
|
|
|
// Arrange
|
2021-11-13 02:01:03 +08:00
|
|
|
var originalTags = SampleFileLoader.LoadXmlFlv(path).Tags;
|
|
|
|
var reader = new TagGroupReader(new FlvTagListReader(SampleFileLoader.LoadXmlFlv(path).Tags));
|
2021-11-02 21:46:44 +08:00
|
|
|
var flvTagListWriter = new FlvTagListWriter();
|
|
|
|
var comments = new List<ProcessingComment>();
|
|
|
|
|
|
|
|
// Act
|
|
|
|
await RunPipeline(reader, flvTagListWriter, comments).ConfigureAwait(false);
|
|
|
|
|
|
|
|
// Assert
|
2022-06-17 17:42:50 +08:00
|
|
|
comments.RemoveAll(x => !x.ActionRequired);
|
2021-11-02 21:46:44 +08:00
|
|
|
|
|
|
|
Assert.Empty(comments);
|
|
|
|
|
|
|
|
Assert.Empty(flvTagListWriter.AlternativeHeaders);
|
|
|
|
|
|
|
|
var outputTags = Assert.Single(flvTagListWriter.Files);
|
|
|
|
Assert.Equal(originalTags.Count, outputTags.Count);
|
|
|
|
|
|
|
|
AssertTags.ShouldHaveLinearTimestamps(outputTags);
|
|
|
|
AssertTags.ShouldHaveFullHeaderTags(outputTags);
|
|
|
|
AssertTags.ShouldHaveSingleHeaderTagPerType(outputTags);
|
|
|
|
AssertTags.ShouldAlmostEqual(originalTags, outputTags);
|
|
|
|
|
|
|
|
await AssertTagsByRerunPipeline(outputTags).ConfigureAwait(false);
|
|
|
|
|
2021-11-13 02:01:03 +08:00
|
|
|
var xmlStr = outputTags.SerializeXml();
|
2021-11-02 21:46:44 +08:00
|
|
|
await Verifier.Verify(xmlStr).UseExtension("xml").UseParameters(path);
|
|
|
|
}
|
|
|
|
|
2022-06-17 17:42:50 +08:00
|
|
|
[Theory()]
|
2021-11-02 21:46:44 +08:00
|
|
|
[Expectation("WithOffsetTest")]
|
2022-06-07 19:50:34 +08:00
|
|
|
[SampleFileTestData("../data/flv/TestData/Good", "*.xml")]
|
2021-11-02 21:46:44 +08:00
|
|
|
public async Task StrictWithArtificalOffsetTestsAsync(string path)
|
|
|
|
{
|
|
|
|
// Arrange
|
2021-11-13 02:01:03 +08:00
|
|
|
var originalTags = SampleFileLoader.LoadXmlFlv(path).Tags;
|
2021-11-02 21:46:44 +08:00
|
|
|
|
|
|
|
var random = new System.Random();
|
|
|
|
var offset = random.Next(51, 9999);
|
|
|
|
if (random.Next(2) == 1)
|
|
|
|
offset = -offset;
|
|
|
|
|
2021-11-13 02:01:03 +08:00
|
|
|
var inputTagsWithOffset = SampleFileLoader.LoadXmlFlv(path).Tags;
|
2021-11-02 21:46:44 +08:00
|
|
|
foreach (var tag in inputTagsWithOffset)
|
|
|
|
tag.Timestamp += offset;
|
|
|
|
var reader = new TagGroupReader(new FlvTagListReader(inputTagsWithOffset));
|
|
|
|
|
|
|
|
var output = new FlvTagListWriter();
|
|
|
|
var comments = new List<ProcessingComment>();
|
|
|
|
|
|
|
|
// Act
|
|
|
|
await RunPipeline(reader, output, comments).ConfigureAwait(false);
|
|
|
|
|
|
|
|
// Assert
|
2022-06-17 17:42:50 +08:00
|
|
|
comments.RemoveAll(x => !x.ActionRequired);
|
|
|
|
Assert.Equal(CommentType.TimestampJump, Assert.Single(comments).Type);
|
2021-11-02 21:46:44 +08:00
|
|
|
|
|
|
|
Assert.Empty(output.AlternativeHeaders);
|
|
|
|
|
|
|
|
var outputTags = Assert.Single(output.Files);
|
|
|
|
Assert.Equal(originalTags.Count, outputTags.Count);
|
|
|
|
|
|
|
|
AssertTags.ShouldHaveLinearTimestamps(outputTags);
|
|
|
|
AssertTags.ShouldHaveFullHeaderTags(outputTags);
|
|
|
|
AssertTags.ShouldHaveSingleHeaderTagPerType(outputTags);
|
|
|
|
AssertTags.ShouldAlmostEqual(originalTags, outputTags);
|
|
|
|
|
|
|
|
await AssertTagsByRerunPipeline(outputTags).ConfigureAwait(false);
|
|
|
|
|
2021-11-13 02:01:03 +08:00
|
|
|
var xmlStr = outputTags.SerializeXml();
|
2021-11-02 21:46:44 +08:00
|
|
|
await Verifier.Verify(xmlStr).UseExtension("xml").UseParameters(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|