From 01ed594061d64aa8ac2bbe58058f41111f844589 Mon Sep 17 00:00:00 2001 From: ForeverZer0 Date: Tue, 24 Aug 2021 08:30:11 -0400 Subject: [PATCH] Removed some obsolete tests --- SharpNBT.Tests/CompressionTest.cs | 50 ---------------------- SharpNBT.Tests/FormatConverters.cs | 44 -------------------- SharpNBT.Tests/PrettyPrint.cs | 26 ------------ SharpNBT.Tests/SharpNBT.Tests.csproj | 20 +++++---- SharpNBT.Tests/TagBuilderTest.cs | 62 ---------------------------- SharpNBT.Tests/ZLib.cs | 58 -------------------------- SharpNBT/VarIntUtil.cs | 12 +++--- 7 files changed, 17 insertions(+), 255 deletions(-) delete mode 100644 SharpNBT.Tests/CompressionTest.cs delete mode 100644 SharpNBT.Tests/FormatConverters.cs delete mode 100644 SharpNBT.Tests/PrettyPrint.cs delete mode 100644 SharpNBT.Tests/TagBuilderTest.cs delete mode 100644 SharpNBT.Tests/ZLib.cs diff --git a/SharpNBT.Tests/CompressionTest.cs b/SharpNBT.Tests/CompressionTest.cs deleted file mode 100644 index 442eb03..0000000 --- a/SharpNBT.Tests/CompressionTest.cs +++ /dev/null @@ -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(); - Assert.Equal("hello world", compound.Name); - } - - [Fact] - public void ReadCompressed() - { - using var stream = NbtFile.OpenRead("./Data/bigtest.nbt", FormatOptions.Java); - var compound = stream.ReadTag(); - Assert.Equal("Level", compound.Name); - } - } -} \ No newline at end of file diff --git a/SharpNBT.Tests/FormatConverters.cs b/SharpNBT.Tests/FormatConverters.cs deleted file mode 100644 index 9e39541..0000000 --- a/SharpNBT.Tests/FormatConverters.cs +++ /dev/null @@ -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(); - } - - [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); - } - } - } -} \ No newline at end of file diff --git a/SharpNBT.Tests/PrettyPrint.cs b/SharpNBT.Tests/PrettyPrint.cs deleted file mode 100644 index 3ed898d..0000000 --- a/SharpNBT.Tests/PrettyPrint.cs +++ /dev/null @@ -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(); - - output.WriteLine(topLevel.PrettyPrinted()); - } - } -} \ No newline at end of file diff --git a/SharpNBT.Tests/SharpNBT.Tests.csproj b/SharpNBT.Tests/SharpNBT.Tests.csproj index 0c1cb63..f8b48cf 100644 --- a/SharpNBT.Tests/SharpNBT.Tests.csproj +++ b/SharpNBT.Tests/SharpNBT.Tests.csproj @@ -19,17 +19,19 @@ - - - PreserveNewest - - - PreserveNewest - - - + + + + PreserveNewest + + + + PreserveNewest + + + diff --git a/SharpNBT.Tests/TagBuilderTest.cs b/SharpNBT.Tests/TagBuilderTest.cs deleted file mode 100644 index 645b8a8..0000000 --- a/SharpNBT.Tests/TagBuilderTest.cs +++ /dev/null @@ -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(); - output.WriteLine(compound.PrettyPrinted()); - } - } - } -} \ No newline at end of file diff --git a/SharpNBT.Tests/ZLib.cs b/SharpNBT.Tests/ZLib.cs deleted file mode 100644 index bbb2b93..0000000 --- a/SharpNBT.Tests/ZLib.cs +++ /dev/null @@ -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()); - - } - } - } - } -} \ No newline at end of file diff --git a/SharpNBT/VarIntUtil.cs b/SharpNBT/VarIntUtil.cs index 6bb64e0..3581317 100644 --- a/SharpNBT/VarIntUtil.cs +++ b/SharpNBT/VarIntUtil.cs @@ -59,7 +59,7 @@ namespace SharpNBT } [MethodImpl(MethodImplOptions.AggressiveInlining)] - public static ulong Decode(ReadOnlySpan buffer, int sizeBites, out int size) + public static ulong Decode(ReadOnlySpan 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;