using AmiReel.Services;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace AmiReel.Tests.Services;

[TestClass]
public class FfmpegOutputFilterTests
{
    [TestMethod]
    [DataRow("ffmpeg version 6.0-full_build-www.gyan.dev")]
    [DataRow("built with gcc 12.2.0")]
    [DataRow("configuration: --enable-gpl")]
    [DataRow("libavutil      58.  2.100 / 58.  2.100")]
    [DataRow("Input #0, avi, from 'clip.avi':")]
    [DataRow("Output #0, mp4, to 'out.mp4':")]
    [DataRow("Stream #0:0: Video: mjpeg")]
    [DataRow("Duration: 00:01:00.00, start: 0.000000, bitrate: 128 kb/s")]
    [DataRow("video:1024kB audio:128kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.5%")]
    public void IsBoilerplateLine_WithKnownFfmpegBanner_ReturnsTrue(string line)
    {
        // Act
        bool result = FfmpegOutputFilter.IsBoilerplateLine(line);

        // Assert
        Assert.IsTrue(result);
    }

    [TestMethod]
    [DataRow("Error while opening encoder for output stream #0:0")]
    [DataRow("Cannot load nvcuda.dll")]
    [DataRow("Unknown encoder 'h264_nvenc'")]
    public void IsBoilerplateLine_WithRealErrorText_ReturnsFalse(string line)
    {
        // Act
        bool result = FfmpegOutputFilter.IsBoilerplateLine(line);

        // Assert
        Assert.IsFalse(result);
    }

    [TestMethod]
    public void IsBoilerplateLine_IsCaseInsensitive()
    {
        // Act & Assert
        Assert.IsTrue(FfmpegOutputFilter.IsBoilerplateLine("DURATION: 00:00:01.00"));
        Assert.IsTrue(FfmpegOutputFilter.IsBoilerplateLine("duration: 00:00:01.00"));
    }
}
