Пример #1
0
        protected void WriteDocumentTest <T, T2>(Func <Stream, T> createWriter, Func <Stream, T2> createReader)
            where T : TagWriter where T2 : TagReader
        {
            // arrange
            Stream stream = new MemoryStream();

            var expected = CreateComplexData();

            TagWriter target = createWriter(stream);

            // act
            target.WriteStartDocument();
            target.WriteTag(expected);
            target.WriteEndDocument();

            // assert
            stream.Seek(0, SeekOrigin.Begin);
            TagReader reader = createReader(stream);
            var       actual = reader.ReadDocument();

            NbtAssert.Equal(expected, actual);
        }
Пример #2
0
        protected void WriteTest <T, T2>(Func <Stream, T> createWriter, Func <Stream, T2> createReader)
            where T : TagWriter where T2 : TagReader
        {
            // arrange
            Stream stream = new MemoryStream();

            var expected = CreateComplexData();

            TagWriter target = createWriter(stream);

            // act
            target.WriteStartDocument();
            target.WriteStartTag("Level", TagType.Compound);
            target.WriteTag("longTest", 9223372036854775807);
            target.WriteTag("shortTest", (short)32767);
            target.WriteTag("stringTest", "HELLO WORLD THIS IS A TEST STRING ÅÄÖ!");
            target.WriteTag("floatTest", (float)0.498231471);
            target.WriteTag("intTest", 2147483647);
            target.WriteStartTag("nested compound test", TagType.Compound);
            target.WriteStartTag("ham", TagType.Compound);
            target.WriteTag("name", "Hampus");
            target.WriteTag("value", 0.75F);
            target.WriteEndTag();
            target.WriteStartTag("egg", TagType.Compound);
            target.WriteTag("name", "Eggbert");
            target.WriteTag("value", 0.5F);
            target.WriteEndTag();
            target.WriteEndTag();
            target.WriteStartTag("listTest (long)", TagType.List, TagType.Long, 5);
            target.WriteTag((long)11);
            target.WriteTag((long)12);
            target.WriteTag((long)13);
            target.WriteTag((long)14);
            target.WriteTag((long)15);
            target.WriteEndTag();
            target.WriteStartTag("listTest (compound)", TagType.List, TagType.Compound, 2);
            target.WriteStartTag(TagType.Compound);
            target.WriteTag("name", "Compound tag #0");
            target.WriteTag("created-on", 1264099775885);
            target.WriteEndTag();
            target.WriteStartTag(TagType.Compound);
            target.WriteTag("name", "Compound tag #1");
            target.WriteTag("created-on", 1264099775885);
            target.WriteEndTag();
            target.WriteEndTag();
            target.WriteTag("byteTest", (byte)127);
            target.WriteTag(
                "byteArrayTest (the first 1000 values of (n*n*255+n*7)%100, starting with n=0 (0, 62, 34, 16, 8, ...))",
                ComplexData.SampleByteArray);
            target.WriteTag("doubleTest", 0.49312871321823148);
            target.WriteEndTag();
            target.WriteEndDocument();

            // assert
            stream.Seek(0, SeekOrigin.Begin);
            TagReader reader = createReader(stream);
            var       actual = reader.ReadDocument();

            NbtAssert.Equal(expected, actual);
        }