Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser unit tests #485

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/N_m3u8DL-RE.Parser.Tests/Extractor/MSSExtractorTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System.Reflection;
using FluentAssertions;
using N_m3u8DL_RE.Parser.Config;
using N_m3u8DL_RE.Parser.Extractor;


namespace N_m3u8DL_RE.Parser.Tests.Extractor;

[TestClass]
public class MSSExtractorTest
{
[TestMethod]
public void TestMethod1()
{
var uri = getResourceUri("Extractor/SuperSpeedway_720.ism.manifest.xml");
var rawText = File.ReadAllText(uri.LocalPath);
var parserConfig = new ParserConfig
{
Url = uri.AbsoluteUri,
OriginalUrl = uri.AbsoluteUri
};
var extractor = new MSSExtractor(parserConfig);
var streamSpecs = extractor.ExtractStreamsAsync(rawText).Result;
streamSpecs.Should().HaveCount(9);
var streamSpec0 = streamSpecs[0];
streamSpec0.PeriodId.Should().Be("0");
streamSpec0.GroupId.Should().Be("video");
streamSpec0.Bandwidth.Should().Be(2962000);
streamSpec0.Codecs.Should().Be("avc1.64001F");
streamSpec0.Resolution.Should().Be("1280x720");
streamSpec0.Channels.Should().Be(null);
streamSpec0.MSSData!.SamplingRate.Should().Be(48000);
streamSpec0.MSSData.BitsPerSample.Should().Be(16);
streamSpec0.MSSData.NalUnitLengthField.Should().Be(4);
streamSpec0.MSSData.Duration.Should().Be(1209510000L);
streamSpec0.MSSData.Timesacle.Should().Be(10000000);
streamSpec0.Playlist!.IsLive.Should().BeFalse();
streamSpec0.Playlist!.MediaParts[0].MediaSegments.Should().HaveCount(61);

var streamSpec1 = streamSpecs[1];
streamSpec1.PeriodId.Should().Be("1");
streamSpec1.GroupId.Should().Be("video");
streamSpec1.Bandwidth.Should().Be(2056000);
streamSpec1.Codecs.Should().Be("avc1.64001F");
streamSpec1.Resolution.Should().Be("992x560");
streamSpec1.Channels.Should().Be(null);
streamSpec1.MSSData!.SamplingRate.Should().Be(48000);
streamSpec1.MSSData.BitsPerSample.Should().Be(16);
streamSpec1.MSSData.NalUnitLengthField.Should().Be(4);
streamSpec1.MSSData.Duration.Should().Be(1209510000L);
streamSpec1.MSSData.Timesacle.Should().Be(10000000);

var streamSpec5 = streamSpecs[5];
streamSpec5.PeriodId.Should().Be("5");
streamSpec5.GroupId.Should().Be("video");
streamSpec5.Bandwidth.Should().Be(477000);
streamSpec5.Codecs.Should().Be("avc1.64000D");
streamSpec5.Resolution.Should().Be("368x208");
streamSpec5.Channels.Should().Be(null);
streamSpec5.MSSData!.SamplingRate.Should().Be(48000);
streamSpec5.MSSData.BitsPerSample.Should().Be(16);
streamSpec5.MSSData.NalUnitLengthField.Should().Be(4);
streamSpec5.MSSData.Duration.Should().Be(1209510000L);
streamSpec5.MSSData.Timesacle.Should().Be(10000000);

var streamSpec8 = streamSpecs[8];
streamSpec8.PeriodId.Should().Be(null);
streamSpec8.GroupId.Should().Be("audio");
streamSpec8.Bandwidth.Should().Be(128000);
streamSpec8.Codecs.Should().Be("mp4a.40.2");
streamSpec8.Resolution.Should().Be(null);
streamSpec8.Channels.Should().Be("2");
streamSpec8.MSSData!.SamplingRate.Should().Be(44100);
streamSpec8.MSSData.BitsPerSample.Should().Be(16);
streamSpec8.MSSData.NalUnitLengthField.Should().Be(4);
streamSpec8.MSSData.Duration.Should().Be(1209510000L);
streamSpec8.MSSData.Timesacle.Should().Be(10000000);
}

private Uri getResourceUri(string resourceName)
{
var directory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
var path = System.IO.Path.Combine(directory, resourceName);
return new Uri("file://" + path);
}
}
Binary file not shown.
1 change: 1 addition & 0 deletions src/N_m3u8DL-RE.Parser.Tests/GlobalUsings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
global using Microsoft.VisualStudio.TestTools.UnitTesting;
31 changes: 31 additions & 0 deletions src/N_m3u8DL-RE.Parser.Tests/N_m3u8DL-RE.Parser.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RootNamespace>N_m3u8DL_RE.Parser.Tests</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.12.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.0"/>
<PackageReference Include="MSTest.TestAdapter" Version="3.0.4"/>
<PackageReference Include="MSTest.TestFramework" Version="3.0.4"/>
<PackageReference Include="coverlet.collector" Version="6.0.0"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\N_m3u8DL-RE.Parser\N_m3u8DL-RE.Parser.csproj" />
</ItemGroup>

<ItemGroup>
<None Update="Extractor\SuperSpeedway_720.ism.manifest.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions src/N_m3u8DL-RE.Parser/N_m3u8DL-RE.Parser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,10 @@
<ItemGroup>
<ProjectReference Include="..\N_m3u8DL-RE.Common\N_m3u8DL-RE.Common.csproj" />
</ItemGroup>
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>$(AssemblyName).Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions src/N_m3u8DL-RE.sln
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N_m3u8DL-RE.Common", "N_m3u
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "N_m3u8DL-RE.Parser", "N_m3u8DL-RE.Parser\N_m3u8DL-RE.Parser.csproj", "{0DA02925-AF3A-4598-AF01-91AE5539FCA1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "N_m3u8DL-RE.Parser.Tests", "N_m3u8DL-RE.Parser.Tests\N_m3u8DL-RE.Parser.Tests.csproj", "{EA47AA74-8D22-48B8-8FD1-3E0F92B98AEE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -27,6 +29,10 @@ Global
{0DA02925-AF3A-4598-AF01-91AE5539FCA1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0DA02925-AF3A-4598-AF01-91AE5539FCA1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0DA02925-AF3A-4598-AF01-91AE5539FCA1}.Release|Any CPU.Build.0 = Release|Any CPU
{EA47AA74-8D22-48B8-8FD1-3E0F92B98AEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EA47AA74-8D22-48B8-8FD1-3E0F92B98AEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EA47AA74-8D22-48B8-8FD1-3E0F92B98AEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EA47AA74-8D22-48B8-8FD1-3E0F92B98AEE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down