mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-20 09:04:42 +01:00
Rewrite packet writing code for HdHomerun
This commit is contained in:
23
tests/Jellyfin.Common.Tests/Crc32Tests.cs
Normal file
23
tests/Jellyfin.Common.Tests/Crc32Tests.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
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)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user