mirror of
https://github.com/rosenbjerg/FFMpegCore.git
synced 2025-12-14 10:05:44 +00:00
Merge pull request #578 from rosenbjerg/clean-up-unit-tests
Clean up unit tests
This commit is contained in:
commit
70668ce623
4 changed files with 61 additions and 44 deletions
|
|
@ -1,20 +1,10 @@
|
|||
using System.Reflection;
|
||||
using FFMpegCore.Arguments;
|
||||
using FluentAssertions;
|
||||
using FFMpegCore.Arguments;
|
||||
|
||||
namespace FFMpegCore.Test;
|
||||
|
||||
[TestClass]
|
||||
public class FFMpegArgumentProcessorTest
|
||||
{
|
||||
[TestCleanup]
|
||||
public void TestInitialize()
|
||||
|
||||
{
|
||||
// After testing reset global configuration to null, to be not wrong for other test relying on configuration
|
||||
typeof(GlobalFFOptions).GetField("_current", BindingFlags.NonPublic | BindingFlags.Static)!.SetValue(GlobalFFOptions.Current, null);
|
||||
}
|
||||
|
||||
private static FFMpegArgumentProcessor CreateArgumentProcessor()
|
||||
{
|
||||
return FFMpegArguments
|
||||
|
|
@ -26,11 +16,20 @@ public class FFMpegArgumentProcessorTest
|
|||
public void Processor_GlobalOptions_GetUsed()
|
||||
{
|
||||
var globalWorkingDir = "Whatever";
|
||||
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = globalWorkingDir });
|
||||
|
||||
var processor = CreateArgumentProcessor();
|
||||
var options2 = processor.GetConfiguredOptions(null);
|
||||
options2.WorkingDirectory.Should().Be(globalWorkingDir);
|
||||
|
||||
try
|
||||
{
|
||||
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = globalWorkingDir });
|
||||
|
||||
var options = processor.GetConfiguredOptions(null);
|
||||
|
||||
Assert.AreEqual(globalWorkingDir, options.WorkingDirectory);
|
||||
}
|
||||
finally
|
||||
{
|
||||
GlobalFFOptions.Configure(new FFOptions());
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
|
|
@ -42,63 +41,81 @@ public class FFMpegArgumentProcessorTest
|
|||
processor.Configure(options => options.WorkingDirectory = sessionWorkingDir);
|
||||
var options = processor.GetConfiguredOptions(null);
|
||||
|
||||
options.WorkingDirectory.Should().Be(sessionWorkingDir);
|
||||
Assert.AreEqual(sessionWorkingDir, options.WorkingDirectory);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Processor_Options_CanBeOverridden_And_Configured()
|
||||
{
|
||||
var globalConfig = "Whatever";
|
||||
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = globalConfig, TemporaryFilesFolder = globalConfig, BinaryFolder = globalConfig });
|
||||
|
||||
var processor = CreateArgumentProcessor();
|
||||
try
|
||||
{
|
||||
var processor = CreateArgumentProcessor();
|
||||
|
||||
var sessionTempDir = "./CurrentRunWorkingDir";
|
||||
processor.Configure(options => options.TemporaryFilesFolder = sessionTempDir);
|
||||
var sessionTempDir = "./CurrentRunWorkingDir";
|
||||
processor.Configure(options => options.TemporaryFilesFolder = sessionTempDir);
|
||||
|
||||
var overrideOptions = new FFOptions { WorkingDirectory = "override" };
|
||||
var options = processor.GetConfiguredOptions(overrideOptions);
|
||||
var overrideOptions = new FFOptions { WorkingDirectory = "override" };
|
||||
|
||||
options.Should().BeEquivalentTo(overrideOptions);
|
||||
options.TemporaryFilesFolder.Should().BeEquivalentTo(sessionTempDir);
|
||||
options.BinaryFolder.Should().NotBeEquivalentTo(globalConfig);
|
||||
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = globalConfig, TemporaryFilesFolder = globalConfig, BinaryFolder = globalConfig });
|
||||
var options = processor.GetConfiguredOptions(overrideOptions);
|
||||
|
||||
Assert.AreEqual(options.WorkingDirectory, overrideOptions.WorkingDirectory);
|
||||
Assert.AreEqual(options.TemporaryFilesFolder, overrideOptions.TemporaryFilesFolder);
|
||||
Assert.AreEqual(options.BinaryFolder, overrideOptions.BinaryFolder);
|
||||
|
||||
Assert.AreEqual(sessionTempDir, options.TemporaryFilesFolder);
|
||||
Assert.AreNotEqual(globalConfig, options.BinaryFolder);
|
||||
}
|
||||
finally
|
||||
{
|
||||
GlobalFFOptions.Configure(new FFOptions());
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Options_Global_And_Session_Options_Can_Differ()
|
||||
{
|
||||
var globalWorkingDir = "Whatever";
|
||||
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = globalWorkingDir });
|
||||
|
||||
var processor1 = CreateArgumentProcessor();
|
||||
var sessionWorkingDir = "./CurrentRunWorkingDir";
|
||||
processor1.Configure(options => options.WorkingDirectory = sessionWorkingDir);
|
||||
var options1 = processor1.GetConfiguredOptions(null);
|
||||
options1.WorkingDirectory.Should().Be(sessionWorkingDir);
|
||||
try
|
||||
{
|
||||
var processor1 = CreateArgumentProcessor();
|
||||
var sessionWorkingDir = "./CurrentRunWorkingDir";
|
||||
processor1.Configure(options => options.WorkingDirectory = sessionWorkingDir);
|
||||
var options1 = processor1.GetConfiguredOptions(null);
|
||||
Assert.AreEqual(sessionWorkingDir, options1.WorkingDirectory);
|
||||
|
||||
var processor2 = CreateArgumentProcessor();
|
||||
var options2 = processor2.GetConfiguredOptions(null);
|
||||
options2.WorkingDirectory.Should().Be(globalWorkingDir);
|
||||
var processor2 = CreateArgumentProcessor();
|
||||
GlobalFFOptions.Configure(new FFOptions { WorkingDirectory = globalWorkingDir });
|
||||
var options2 = processor2.GetConfiguredOptions(null);
|
||||
Assert.AreEqual(globalWorkingDir, options2.WorkingDirectory);
|
||||
}
|
||||
finally
|
||||
{
|
||||
GlobalFFOptions.Configure(new FFOptions());
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Concat_Escape()
|
||||
{
|
||||
var arg = new DemuxConcatArgument(new[] { @"Heaven's River\05 - Investigation.m4b" });
|
||||
arg.Values.Should().BeEquivalentTo(@"file 'Heaven'\''s River\05 - Investigation.m4b'");
|
||||
var arg = new DemuxConcatArgument([@"Heaven's River\05 - Investigation.m4b"]);
|
||||
CollectionAssert.AreEquivalent(new[] { @"file 'Heaven'\''s River\05 - Investigation.m4b'" }, arg.Values.ToArray());
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Audible_Aaxc_Test()
|
||||
{
|
||||
var arg = new AudibleEncryptionKeyArgument("123", "456");
|
||||
arg.Text.Should().Be("-audible_key 123 -audible_iv 456");
|
||||
Assert.AreEqual("-audible_key 123 -audible_iv 456", arg.Text);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Audible_Aax_Test()
|
||||
{
|
||||
var arg = new AudibleEncryptionKeyArgument("62689101");
|
||||
arg.Text.Should().Be("-activation_bytes 62689101");
|
||||
Assert.AreEqual("-activation_bytes 62689101", arg.Text);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@
|
|||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="FluentAssertions" Version="8.7.1"/>
|
||||
<PackageReference Include="GitHubActionsTestLogger" Version="2.4.1">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ namespace FFMpegCore.Test;
|
|||
[TestClass]
|
||||
public class FFProbeTests
|
||||
{
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
public async Task Audio_FromStream_Duration()
|
||||
{
|
||||
|
|
@ -97,7 +99,8 @@ public class FFProbeTests
|
|||
[Ignore("Consistently fails on GitHub Workflow ubuntu agents")]
|
||||
public async Task Uri_Duration()
|
||||
{
|
||||
var fileAnalysis = await FFProbe.AnalyseAsync(new Uri("https://github.com/rosenbjerg/FFMpegCore/raw/master/FFMpegCore.Test/Resources/input_3sec.webm"), cancellationToken: TestContext.CancellationToken);
|
||||
var fileAnalysis = await FFProbe.AnalyseAsync(new Uri("https://github.com/rosenbjerg/FFMpegCore/raw/master/FFMpegCore.Test/Resources/input_3sec.webm"),
|
||||
cancellationToken: TestContext.CancellationToken);
|
||||
Assert.IsNotNull(fileAnalysis);
|
||||
}
|
||||
|
||||
|
|
@ -282,6 +285,4 @@ public class FFProbeTests
|
|||
var info = FFProbe.Analyse(TestResources.Mp4Video, customArguments: "-headers \"Hello: World\"");
|
||||
Assert.AreEqual(3, info.Duration.Seconds);
|
||||
}
|
||||
|
||||
public TestContext TestContext { get; set; }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@ public class VideoTest
|
|||
{
|
||||
private const int BaseTimeoutMilliseconds = 15_000;
|
||||
|
||||
public TestContext TestContext { get; set; }
|
||||
|
||||
[TestMethod]
|
||||
[Timeout(BaseTimeoutMilliseconds, CooperativeCancellation = true)]
|
||||
public void Video_ToOGV()
|
||||
|
|
@ -1072,6 +1074,4 @@ public class VideoTest
|
|||
Assert.AreEqual("h264", outputInfo.PrimaryVideoStream.CodecName);
|
||||
Assert.AreEqual("aac", outputInfo.PrimaryAudioStream!.CodecName);
|
||||
}
|
||||
|
||||
public TestContext TestContext { get; set; }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue