using FluentAssertions; using System.Runtime.InteropServices; using Moq; using Vav1Player.Decoder; using Vav1Player.Native; namespace Vav1Player.Tests.Decoder; public class Dav1dDecoderTests : IDisposable { private readonly Dav1dDecoder _decoder; public Dav1dDecoderTests() { _decoder = new Dav1dDecoder(); } [Fact] public void Constructor_ShouldCreateInstance() { // Act & Assert _decoder.Should().NotBeNull(); } [Fact] public void Initialize_WithDefaultParameters_ShouldNotThrow() { // Act & Assert var action = () => _decoder.Initialize(); action.Should().NotThrow(); } [Fact] public void Initialize_WithSpecificThreadCount_ShouldNotThrow() { // Act & Assert var action = () => _decoder.Initialize(4); action.Should().NotThrow(); } [Theory] [InlineData(0)] [InlineData(1)] [InlineData(4)] [InlineData(8)] public void Initialize_WithVariousThreadCounts_ShouldHandle(int threadCount) { // Act & Assert var action = () => _decoder.Initialize(threadCount); action.Should().NotThrow(); } [Fact] public void DecodeFrame_WithNullData_ShouldReturnFalse() { // Arrange _decoder.Initialize(); // Act var result = _decoder.DecodeFrame(null!, out var frame); // Assert result.Should().BeFalse(); frame.Should().BeNull(); } [Fact] public void DecodeFrame_WithEmptyData_ShouldReturnFalse() { // Arrange _decoder.Initialize(); var emptyData = Array.Empty(); // Act var result = _decoder.DecodeFrame(emptyData, out var frame); // Assert result.Should().BeFalse(); frame.Should().BeNull(); } [Fact] public void DecodeFrame_WithoutInitialize_ShouldReturnFalse() { // Arrange var testData = new byte[] { 0x12, 0x00, 0x0A, 0x0A }; // Act var result = _decoder.DecodeFrame(testData, out var frame); // Assert result.Should().BeFalse(); frame.Should().BeNull(); } [Fact] public void DecodeFrame_WithInvalidData_ShouldHandleGracefully() { // Arrange _decoder.Initialize(); var invalidData = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF }; // Act var result = _decoder.DecodeFrame(invalidData, out var frame); // Assert result.Should().BeFalse(); frame.Should().BeNull(); } [Fact] public void Dispose_ShouldNotThrow() { // Arrange _decoder.Initialize(); // Act & Assert var action = () => _decoder.Dispose(); action.Should().NotThrow(); } [Fact] public void Dispose_CalledMultipleTimes_ShouldNotThrow() { // Arrange _decoder.Initialize(); // Act & Assert var action = () => { _decoder.Dispose(); _decoder.Dispose(); _decoder.Dispose(); }; action.Should().NotThrow(); } [Fact] public void DecodeFrame_AfterDispose_ShouldReturnFalse() { // Arrange _decoder.Initialize(); _decoder.Dispose(); var testData = new byte[] { 0x12, 0x00, 0x0A, 0x0A }; // Act var result = _decoder.DecodeFrame(testData, out var frame); // Assert result.Should().BeFalse(); frame.Should().BeNull(); } public void Dispose() { _decoder?.Dispose(); } } public class DecodedFrameTests { [Fact] public void DecodedFrame_ShouldHaveCorrectProperties() { // Arrange var frame = new DecodedFrame { Width = 1920, Height = 1080, PixelLayout = Dav1dPixelLayout.DAV1D_PIXEL_LAYOUT_I420, BitDepth = 8 }; // Assert frame.Width.Should().Be(1920); frame.Height.Should().Be(1080); frame.PixelLayout.Should().Be(Dav1dPixelLayout.DAV1D_PIXEL_LAYOUT_I420); frame.BitDepth.Should().Be(8); } [Fact] public void Release_ShouldNotThrow() { // Arrange var frame = new DecodedFrame(); // Act & Assert var action = () => frame.Release(); action.Should().NotThrow(); } }