public void PartialReadTest() { // read the whole thing as one tag TestFiles.AssertValueTest(PartialReadTestInternal(new NbtFile(TestFiles.MakeValueTest()))); TestFiles.AssertNbtSmallFile(PartialReadTestInternal(TestFiles.MakeSmallFile())); TestFiles.AssertNbtBigFile(PartialReadTestInternal(new NbtFile(TestFiles.Big))); }
public void LoadingBigFileZLib() { var file = new NbtFile(); long length = file.LoadFromFile(TestFiles.BigZLib); TestFiles.AssertNbtBigFile(file); Assert.AreEqual(length, new FileInfo(TestFiles.BigZLib).Length); }
public void PartialBatchReadTest() { // read the whole thing as one tag, in batches of 4 bytes // Verifies fix for https://github.com/fragmer/fNbt/issues/26 TestFiles.AssertValueTest(PartialReadTestInternal(new NbtFile(TestFiles.MakeValueTest()), 4)); TestFiles.AssertNbtSmallFile(PartialReadTestInternal(TestFiles.MakeSmallFile(), 4)); TestFiles.AssertNbtBigFile(PartialReadTestInternal(new NbtFile(TestFiles.Big), 4)); }
public void LoadingBigFileStream() { byte[] fileBytes = File.ReadAllBytes(TestFiles.Big); using (var ms = new MemoryStream(fileBytes)) { using (var nss = new NonSeekableStream(ms)) { var file = new NbtFile(); long length = file.LoadFromStream(nss, NbtCompression.None, NbtVersion.Legacy, null); TestFiles.AssertNbtBigFile(file); Assert.AreEqual(length, new FileInfo(TestFiles.Big).Length); } } }
public void LoadingBigFileBuffer() { byte[] fileBytes = File.ReadAllBytes(TestFiles.Big); var file = new NbtFile(); Assert.Throws <ArgumentNullException>( () => file.LoadFromBuffer(null, 0, fileBytes.Length, NbtCompression.AutoDetect, null)); long length = file.LoadFromBuffer(fileBytes, 0, fileBytes.Length, NbtCompression.AutoDetect, null); TestFiles.AssertNbtBigFile(file); Assert.AreEqual(length, new FileInfo(TestFiles.Big).Length); }
public void ReloadNonSeekableStream() { var loadedFile = new NbtFile(TestFiles.Big); using (var ms = new MemoryStream()) { using (var nss = new NonSeekableStream(ms)) { long bytesWritten = loadedFile.SaveToStream(nss, NbtCompression.None); ms.Position = 0; Assert.Throws <NotSupportedException>(() => loadedFile.LoadFromStream(nss, NbtCompression.AutoDetect)); ms.Position = 0; Assert.Throws <InvalidDataException>(() => loadedFile.LoadFromStream(nss, NbtCompression.ZLib, NbtVersion.Legacy)); ms.Position = 0; long bytesRead = loadedFile.LoadFromStream(nss, NbtCompression.None, NbtVersion.Legacy); Assert.AreEqual(bytesWritten, bytesRead); TestFiles.AssertNbtBigFile(loadedFile); } } }
void ReloadFileInternal(String fileName, NbtCompression compression, bool bigEndian, bool buffered) { var loadedFile = new NbtFile(Path.Combine(TestFiles.DirName, fileName)) { BigEndian = bigEndian }; if (!buffered) { loadedFile.BufferSize = 0; } long bytesWritten = loadedFile.SaveToFile(Path.Combine(TestDirName, fileName), compression); long bytesRead = loadedFile.LoadFromFile(Path.Combine(TestDirName, fileName), NbtCompression.AutoDetect, null); Assert.AreEqual(bytesWritten, bytesRead); TestFiles.AssertNbtBigFile(loadedFile); }