Removed some obsolete tests

This commit is contained in:
ForeverZer0 2021-08-24 08:30:11 -04:00
parent 96e888179f
commit 01ed594061
7 changed files with 17 additions and 255 deletions

View File

@ -1,50 +0,0 @@
using System;
using System.IO;
using System.IO.Compression;
using Xunit;
namespace SharpNBT.Tests
{
public class CompressionTest
{
[Fact]
public void WriteUncompressed()
{
var compound = new CompoundTag("Top-Level Compound");
compound.Add(new ByteTag("Child Byte", 255));
compound.Add(new StringTag("Child String", "Hello World!"));
using var stream = NbtFile.OpenWrite("./Data/write-test-uncompressed.nbt", FormatOptions.Java, CompressionType.None);
stream.WriteTag(compound);
}
[Fact]
public void WriteCompressed()
{
var compound = new CompoundTag("Top-Level Compound");
compound.Add(new ByteTag("Child Byte", 255));
compound.Add(new StringTag("Child String", "Hello World!"));
using var stream = NbtFile.OpenWrite("./Data/write-test-compressed.nbt", FormatOptions.Java, CompressionType.GZip, CompressionLevel.Optimal);
stream.WriteTag(compound);
}
[Fact]
public void ReadUncompressed()
{
using var stream = NbtFile.OpenRead("./Data/hello_world.nbt", FormatOptions.Java);
var compound = stream.ReadTag<CompoundTag>();
Assert.Equal("hello world", compound.Name);
}
[Fact]
public void ReadCompressed()
{
using var stream = NbtFile.OpenRead("./Data/bigtest.nbt", FormatOptions.Java);
var compound = stream.ReadTag<CompoundTag>();
Assert.Equal("Level", compound.Name);
}
}
}

View File

@ -1,44 +0,0 @@
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Text;
using Newtonsoft.Json;
using Xunit;
using Xunit.Abstractions;
namespace SharpNBT.Tests
{
public class FormatConverters
{
private readonly ITestOutputHelper output;
private readonly CompoundTag compoundTag;
public FormatConverters(ITestOutputHelper output)
{
this.output = output;
using var stream = NbtFile.OpenRead("./Data/bigtest.nbt", FormatOptions.Java);
compoundTag = stream.ReadTag<CompoundTag>();
}
[Fact]
public void JsonTest()
{
using (var stream = File.OpenWrite("./Data/bigtest.json"))
{
var json = Encoding.UTF8.GetBytes(compoundTag.ToJsonString(true));
stream.Write(json, 0, json.Length);
}
}
[Fact]
public void XmlTest()
{
using (var stream = File.OpenWrite("./Data/bigtest.xml"))
{
var xml = Encoding.UTF8.GetBytes(compoundTag.ToXmlString());
stream.Write(xml, 0, xml.Length);
}
}
}
}

View File

@ -1,26 +0,0 @@
using System;
using Xunit;
using Xunit.Abstractions;
using Xunit.Sdk;
namespace SharpNBT.Tests
{
public class PrettyPrint
{
private readonly ITestOutputHelper output;
public PrettyPrint(ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void PrettyPrintToStdout()
{
using var stream = NbtFile.OpenRead("./Data/bigtest.nbt", FormatOptions.Java);
var topLevel = stream.ReadTag<CompoundTag>();
output.WriteLine(topLevel.PrettyPrinted());
}
}
}

View File

@ -19,17 +19,19 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<None Update="Data\bigtest.nbt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="Data\hello_world.nbt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SharpNBT\SharpNBT.csproj" />
</ItemGroup>
<ItemGroup>
<None Remove="Data\bigtest.nbt" />
<EmbeddedResource Include="Data\bigtest.nbt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
<None Remove="Data\hello_world.nbt" />
<EmbeddedResource Include="Data\hello_world.nbt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</EmbeddedResource>
</ItemGroup>
</Project>

View File

@ -1,62 +0,0 @@
using System;
using Xunit;
using Xunit.Abstractions;
namespace SharpNBT.Tests
{
public class TagBuilderTest
{
private const string FILE_PATH = "./Data/tagbuilder-test.nbt";
private readonly ITestOutputHelper output;
public TagBuilderTest(ITestOutputHelper output)
{
this.output = output;
}
[Fact]
public void Build()
{
var byteArray = new sbyte[] { sbyte.MinValue, -1, 0, 1, sbyte.MaxValue };
var intArray = new int[] { int.MinValue, -1, 0, 1, int.MaxValue };
var longArray = new long[] { long.MinValue, -1, 0, 1, long.MaxValue };
var builder = new TagBuilder("Created with TagBuilder")
.BeginCompound("nested compound test")
.BeginCompound("egg").AddString("name", "Eggbert").AddFloat("value", 0.5f).EndCompound()
.BeginCompound("ham").AddString("name", "Hampus").AddFloat("value", 0.75f).EndCompound()
.EndCompound()
.AddInt("integer test", 2147483647)
.AddByte("byte test", 127)
.AddString("string test", "HELLO WORLD THIS IS A TEST STRING \xc5\xc4\xd6!")
.BeginList(TagType.Long, "List Test").AddLong(11).AddLong(12).AddLong(13).AddLong(14).AddLong(15).EndList()
.AddDouble("Double test", 0.49312871321823148)
.AddFloat("Float Test", 0.49823147058486938f)
.AddLong("Long Test", 9223372036854775807L)
.BeginList(TagType.Compound,"List Test (compound)")
.BeginCompound().AddLong("created-on", 1264099775885L).AddString("name", "tag1").EndCompound()
.BeginCompound().AddLong("created-on", 1264099775885L).AddString("name", "tag2").EndCompound()
.EndList()
.AddByteArray("byte array", new byte[] { 4, 127 })
.AddShort("short test", 32767)
.AddByteArray("Byte Array Test", byteArray)
.AddIntArray("Int Array Test", intArray)
.AddLongArray("Long Array Test", longArray);
output.WriteLine("**** PRE-SERIALIZATION ****\n");
var temp = builder.Create();
output.WriteLine(temp.PrettyPrinted());
using (var stream = NbtFile.OpenWrite(FILE_PATH, FormatOptions.Java))
stream.WriteTag(temp);
output.WriteLine("\n**** POST SERIALIZATION/DESERIALIZATION ****\n");
using (var stream = NbtFile.OpenRead(FILE_PATH, FormatOptions.Java))
{
var compound = stream.ReadTag<CompoundTag>();
output.WriteLine(compound.PrettyPrinted());
}
}
}
}

View File

@ -1,58 +0,0 @@
using System.IO;
using System.IO.Compression;
using System.Text;
using SharpNBT.ZLib;
using Xunit;
using Xunit.Abstractions;
namespace SharpNBT.Tests
{
public class ZLib
{
private readonly ITestOutputHelper console;
public ZLib(ITestOutputHelper output)
{
console = output;
}
[Fact]
public void Compress()
{
var text = File.ReadAllText("./Data/bigtest.json");
using (var output = File.OpenWrite("./Data/bigtest.zlib"))
{
using (var zlib = new ZLibStream(output, CompressionLevel.Fastest, true))
{
var bytes = Encoding.UTF8.GetBytes(text);
zlib.Write(bytes, 0, bytes.Length);
}
}
using (var input = File.OpenRead("./Data/bigtest.zlib"))
{
using (var zlib = new ZLibStream(input, CompressionMode.Decompress))
{
var sb = new StringBuilder();
var buffer = new byte[1024];
while (true)
{
var read = zlib.Read(buffer, 0, 1024);
sb.Append(Encoding.UTF8.GetString(buffer, 0, read));
if (read < 1024)
break;
}
console.WriteLine(sb.ToString());
}
}
}
}
}

View File

@ -59,7 +59,7 @@ namespace SharpNBT
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong Decode(ReadOnlySpan<byte> buffer, int sizeBites, out int size)
public static ulong Decode(ReadOnlySpan<byte> buffer, int bits, out int size)
{
var shift = 0;
ulong result = 0;
@ -69,8 +69,8 @@ namespace SharpNBT
{
ulong tmp = byteValue & 0x7f;
result |= tmp << shift;
if (shift > sizeBites)
throw new OverflowException($"Value too large to be stored in a {sizeBites} integer.");
if (shift > bits)
throw new OverflowException($"Value too large to be stored in a {bits} integer.");
size++;
if ((byteValue & 0x80) != 0x80)
return result;
@ -81,7 +81,7 @@ namespace SharpNBT
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong Decode(Stream stream, int sizeBites, out int size)
public static ulong Decode(Stream stream, int bits, out int size)
{
var shift = 0;
ulong result = 0;
@ -94,8 +94,8 @@ namespace SharpNBT
ulong tmp = byteValue & 0x7f;
result |= tmp << shift;
if (shift > sizeBites)
throw new OverflowException($"Value too large to be stored in a {sizeBites} integer.");
if (shift > bits)
throw new OverflowException($"Value too large to be stored in a {bits}-bit integer.");
if ((byteValue & 0x80) != 0x80)
return result;