mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-02 22:08:27 +01:00
Merge pull request #5220 from Bond-009/hdhomerun
This commit is contained in:
33
tests/Jellyfin.Common.Tests/Crc32Tests.cs
Normal file
33
tests/Jellyfin.Common.Tests/Crc32Tests.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using MediaBrowser.Common;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Common.Tests
|
||||
{
|
||||
public static class Crc32Tests
|
||||
{
|
||||
[Fact]
|
||||
public static void Compute_Empty_Zero()
|
||||
{
|
||||
Assert.Equal<uint>(0, Crc32.Compute(Array.Empty<byte>()));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0x414fa339, "The quick brown fox jumps over the lazy dog")]
|
||||
public static void Compute_Valid_Success(uint expected, string data)
|
||||
{
|
||||
Assert.Equal(expected, Crc32.Compute(Encoding.UTF8.GetBytes(data)));
|
||||
}
|
||||
|
||||
[Theory]
|
||||
[InlineData(0x414fa339, "54686520717569636B2062726F776E20666F78206A756D7073206F76657220746865206C617A7920646F67")]
|
||||
[InlineData(0x190a55ad, "0000000000000000000000000000000000000000000000000000000000000000")]
|
||||
[InlineData(0xff6cab0b, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF")]
|
||||
[InlineData(0x91267e8a, "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F")]
|
||||
public static void Compute_ValidHex_Success(uint expected, string data)
|
||||
{
|
||||
Assert.Equal(expected, Crc32.Compute(Convert.FromHexString(data)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
using System;
|
||||
using Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun;
|
||||
using Xunit;
|
||||
|
||||
namespace Jellyfin.Server.Implementations.Tests.LiveTv
|
||||
{
|
||||
public class HdHomerunManagerTests
|
||||
{
|
||||
[Fact]
|
||||
public void WriteNullTerminatedString_Empty_Success()
|
||||
{
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[]
|
||||
{
|
||||
1, 0
|
||||
};
|
||||
|
||||
Span<byte> buffer = stackalloc byte[128];
|
||||
int len = HdHomerunManager.WriteNullTerminatedString(buffer, string.Empty);
|
||||
|
||||
Assert.Equal(expected.Length, len);
|
||||
Assert.True(expected.SequenceEqual(buffer.Slice(0, len)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteNullTerminatedString_Valid_Success()
|
||||
{
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[]
|
||||
{
|
||||
10, (byte)'T', (byte)'h', (byte)'e', (byte)' ', (byte)'q', (byte)'u', (byte)'i', (byte)'c', (byte)'k', 0
|
||||
};
|
||||
|
||||
Span<byte> buffer = stackalloc byte[128];
|
||||
int len = HdHomerunManager.WriteNullTerminatedString(buffer, "The quick");
|
||||
|
||||
Assert.Equal(expected.Length, len);
|
||||
Assert.True(expected.SequenceEqual(buffer.Slice(0, len)));
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void WriteGetMessage_Valid_Success()
|
||||
{
|
||||
ReadOnlySpan<byte> expected = stackalloc byte[]
|
||||
{
|
||||
0, 4,
|
||||
0, 12,
|
||||
3,
|
||||
10, (byte)'/', (byte)'t', (byte)'u', (byte)'n', (byte)'e', (byte)'r', (byte)'0', (byte)'/', (byte)'N', 0,
|
||||
0xc0, 0xc9, 0x87, 0x33
|
||||
};
|
||||
|
||||
Span<byte> buffer = stackalloc byte[128];
|
||||
int len = HdHomerunManager.WriteGetMessage(buffer, 0, "N");
|
||||
|
||||
Assert.Equal(expected.Length, len);
|
||||
Assert.True(expected.SequenceEqual(buffer.Slice(0, len)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user