Пример #1
0
		public void ReadList_ObjectDisposedException()
		{
			// Arrange
			NbtTagInfo tagInfo = (NbtTagInfo)new byte[] { 0x09, 0x00, 0x04 };
			byte[] data = new byte[] {
				0x61, 0x73, 0x64, 0x66, // name: "asdf"
				0x08, // type: TAG_String
				0x00, 0x00, 0x00, 0x04, // size: 4
				0x00, 0x05, 0x6A, 0x6B, 0x6C, 0x3B, 0x31, // "jkl;1"
				0x00, 0x05, 0x6A, 0x6B, 0x6C, 0x3B, 0x32, // "jkl;2"
				0x00, 0x05, 0x6A, 0x6B, 0x6C, 0x3B, 0x33, // "jkl;3"
				0x00, 0x05, 0x6A, 0x6B, 0x6C, 0x3B, 0x34  // "jkl;4"
			};

			MemoryStream stream = new MemoryStream(data);

			NbtReader reader = new NbtReader(stream);

			stream.Close();

			// Act
			NbtList result = reader.ReadList(tagInfo);
		}
Пример #2
0
		public void ReadList_EndOfStreamException()
		{
			// Arrange
			NbtTagInfo tagInfo = (NbtTagInfo)new byte[] { 0x09, 0x00, 0x04 };
			byte[] data = new byte[] { 0x61, 0x73 };

			MemoryStream stream = new MemoryStream(data);

			NbtReader reader = new NbtReader(stream);

			// Act
			NbtList result = reader.ReadList(tagInfo);
		}
Пример #3
0
		public void ReadList_Normal()
		{
			// Arrange
			NbtTagInfo tagInfo = (NbtTagInfo)new byte[] { 0x09, 0x00, 0x04 };
			byte[] data = new byte[] {
				0x61, 0x73, 0x64, 0x66, // name: "asdf"
				0x08, // type: TAG_String
				0x00, 0x00, 0x00, 0x04, // size: 4
				0x00, 0x05, 0x6A, 0x6B, 0x6C, 0x3B, 0x31, // "jkl;1"
				0x00, 0x05, 0x6A, 0x6B, 0x6C, 0x3B, 0x32, // "jkl;2"
				0x00, 0x05, 0x6A, 0x6B, 0x6C, 0x3B, 0x33, // "jkl;3"
				0x00, 0x05, 0x6A, 0x6B, 0x6C, 0x3B, 0x34  // "jkl;4"
			};

			MemoryStream stream = new MemoryStream(data);

			NbtReader reader = new NbtReader(stream);

			NbtTagType expectedTagType = NbtTagType.List;
			string expectedName = "asdf";
			NbtString[] expectedValue = new NbtString[] {
				new NbtString(string.Empty, "jkl;1"),
				new NbtString(string.Empty, "jkl;2"),
				new NbtString(string.Empty, "jkl;3"),
				new NbtString(string.Empty, "jkl;4")
			};

			// Act
			NbtList result = reader.ReadList(tagInfo);

			// Assert
			Assert.AreEqual(expectedName, result.Name);
			Assert.AreEqual(expectedTagType, result.Type);
			for (int i = 0; i < expectedValue.Length && i < result.Value.Length; i++)
			{
				Assert.AreEqual(expectedValue[i].Name, result.Value[i].Name);
				Assert.AreEqual(expectedValue[i].Type, result.Value[i].Type);
				Assert.AreEqual(expectedValue[i].Value, result.Value[i].GetValue());
			}
		}