Beispiel #1
0
    public void ReadToFollowingNotFound()
    {
        var reader = new NbtReader(TestFiles.MakeReaderTest());

        Assert.True(reader.ReadToFollowing()); // at "root"
        Assert.False(reader.ReadToFollowing("no such tag"));
        Assert.False(reader.ReadToFollowing("not this one either"));
        Assert.True(reader.IsAtStreamEnd);
    }
Beispiel #2
0
    public void NonSeekableStreamSkip2()
    {
        using var ms  = TestFiles.MakeReaderTest();
        using var nss = new NonSeekableStream(ms);

        var reader = new NbtReader(nss);

        reader.ReadToFollowing();
        reader.Skip();
    }
Beispiel #3
0
    public void ReadToSiblingTest2()
    {
        var reader = new NbtReader(TestFiles.MakeReaderTest());

        Assert.True(reader.ReadToFollowing("inComp1"));
        // Expect all siblings to be read while we search for a non-existent one
        Assert.False(reader.ReadToNextSibling("no such tag"));
        // Expect to pop out of "third-comp" by now
        Assert.Equal("fourth-list", reader.TagName);
    }
        public void ReadAsTagTest1()
        {
            // read various lists/compounds as tags
            var reader = new NbtReader(TestFiles.MakeReaderTest());

            reader.ReadToFollowing(); // skip root
            while (!reader.IsAtStreamEnd)
            {
                reader.ReadAsTag();
            }
            Assert.Throws <EndOfStreamException>(() => reader.ReadAsTag());
        }
        public void SkipTest()
        {
            var reader = new NbtReader(TestFiles.MakeReaderTest());

            reader.ReadToFollowing(); // at root
            reader.ReadToFollowing(); // at first
            reader.ReadToFollowing(); // at second
            reader.ReadToFollowing(); // at third-comp
            reader.ReadToFollowing(); // at inComp1
            Assert.Equal("inComp1", reader.TagName);
            Assert.Equal(2, reader.Skip());
            Assert.Equal("fourth-list", reader.TagName);
            Assert.Equal(11, reader.Skip());
            Assert.False(reader.ReadToFollowing());
            Assert.Equal(0, reader.Skip());
        }
        public void ReadToDescendantTest()
        {
            var reader = new NbtReader(TestFiles.MakeReaderTest());

            Assert.True(reader.ReadToDescendant("third-comp"));
            Assert.Equal("third-comp", reader.TagName);
            Assert.True(reader.ReadToDescendant("inComp2"));
            Assert.Equal("inComp2", reader.TagName);
            Assert.False(reader.ReadToDescendant("derp"));
            Assert.Equal("inComp3", reader.TagName);
            reader.ReadToFollowing(); // at fourth-list
            Assert.True(reader.ReadToDescendant("inList2"));
            Assert.Equal("inList2", reader.TagName);

            // Ensure ReadToDescendant returns false when at end-of-stream
            while (reader.ReadToFollowing())
            {
            }
            Assert.False(reader.ReadToDescendant("*"));
        }
        public void ReadToSiblingTest()
        {
            var reader = new NbtReader(TestFiles.MakeReaderTest());

            Assert.True(reader.ReadToFollowing());
            Assert.Equal("root", reader.TagName);
            Assert.True(reader.ReadToFollowing());
            Assert.Equal("first", reader.TagName);
            Assert.True(reader.ReadToNextSibling("third-comp"));
            Assert.Equal("third-comp", reader.TagName);
            Assert.True(reader.ReadToNextSibling());
            Assert.Equal("fourth-list", reader.TagName);
            Assert.True(reader.ReadToNextSibling());
            Assert.Equal("fifth", reader.TagName);
            Assert.True(reader.ReadToNextSibling());
            Assert.Equal("hugeArray", reader.TagName);
            Assert.False(reader.ReadToNextSibling());
            // Test twice, since we hit different paths through the code
            Assert.False(reader.ReadToNextSibling());
        }
        public void PropertiesTest()
        {
            var reader = new NbtReader(TestFiles.MakeReaderTest());

            Assert.Equal(0, reader.Depth);
            Assert.Equal(0, reader.TagsRead);

            Assert.True(reader.ReadToFollowing());
            Assert.Equal("root", reader.TagName);
            Assert.Equal(NbtTagType.Compound, reader.TagType);
            Assert.Equal(NbtTagType.Unknown, reader.ListType);
            Assert.False(reader.HasValue);
            Assert.True(reader.IsCompound);
            Assert.False(reader.IsList);
            Assert.False(reader.IsListElement);
            Assert.False(reader.HasLength);
            Assert.Equal(0, reader.ListIndex);
            Assert.Equal(1, reader.Depth);
            Assert.Equal(null, reader.ParentName);
            Assert.Equal(NbtTagType.Unknown, reader.ParentTagType);
            Assert.Equal(0, reader.ParentTagLength);
            Assert.Equal(0, reader.TagLength);
            Assert.Equal(1, reader.TagsRead);

            Assert.True(reader.ReadToFollowing());
            Assert.Equal("first", reader.TagName);
            Assert.Equal(NbtTagType.Int, reader.TagType);
            Assert.Equal(NbtTagType.Unknown, reader.ListType);
            Assert.True(reader.HasValue);
            Assert.False(reader.IsCompound);
            Assert.False(reader.IsList);
            Assert.False(reader.IsListElement);
            Assert.False(reader.HasLength);
            Assert.Equal(0, reader.ListIndex);
            Assert.Equal(2, reader.Depth);
            Assert.Equal("root", reader.ParentName);
            Assert.Equal(NbtTagType.Compound, reader.ParentTagType);
            Assert.Equal(0, reader.ParentTagLength);
            Assert.Equal(0, reader.TagLength);
            Assert.Equal(2, reader.TagsRead);

            Assert.True(reader.ReadToFollowing("fourth-list"));
            Assert.Equal("fourth-list", reader.TagName);
            Assert.Equal(NbtTagType.List, reader.TagType);
            Assert.Equal(NbtTagType.List, reader.ListType);
            Assert.False(reader.HasValue);
            Assert.False(reader.IsCompound);
            Assert.True(reader.IsList);
            Assert.False(reader.IsListElement);
            Assert.True(reader.HasLength);
            Assert.Equal(0, reader.ListIndex);
            Assert.Equal(2, reader.Depth);
            Assert.Equal("root", reader.ParentName);
            Assert.Equal(NbtTagType.Compound, reader.ParentTagType);
            Assert.Equal(0, reader.ParentTagLength);
            Assert.Equal(3, reader.TagLength);
            Assert.Equal(8, reader.TagsRead);

            Assert.True(reader.ReadToFollowing()); // first list element, itself a list
            Assert.Equal(null, reader.TagName);
            Assert.Equal(NbtTagType.List, reader.TagType);
            Assert.Equal(NbtTagType.Compound, reader.ListType);
            Assert.False(reader.HasValue);
            Assert.False(reader.IsCompound);
            Assert.True(reader.IsList);
            Assert.True(reader.IsListElement);
            Assert.True(reader.HasLength);
            Assert.Equal(0, reader.ListIndex);
            Assert.Equal(3, reader.Depth);
            Assert.Equal("fourth-list", reader.ParentName);
            Assert.Equal(NbtTagType.List, reader.ParentTagType);
            Assert.Equal(3, reader.ParentTagLength);
            Assert.Equal(1, reader.TagLength);
            Assert.Equal(9, reader.TagsRead);

            Assert.True(reader.ReadToFollowing()); // first nested list element, compound
            Assert.Equal(null, reader.TagName);
            Assert.Equal(NbtTagType.Compound, reader.TagType);
            Assert.Equal(NbtTagType.Unknown, reader.ListType);
            Assert.False(reader.HasValue);
            Assert.True(reader.IsCompound);
            Assert.False(reader.IsList);
            Assert.True(reader.IsListElement);
            Assert.False(reader.HasLength);
            Assert.Equal(0, reader.ListIndex);
            Assert.Equal(4, reader.Depth);
            Assert.Equal(null, reader.ParentName);
            Assert.Equal(NbtTagType.List, reader.ParentTagType);
            Assert.Equal(1, reader.ParentTagLength);
            Assert.Equal(0, reader.TagLength);
            Assert.Equal(10, reader.TagsRead);

            Assert.True(reader.ReadToFollowing("fifth"));
            Assert.Equal("fifth", reader.TagName);
            Assert.Equal(NbtTagType.Int, reader.TagType);
            Assert.Equal(NbtTagType.Unknown, reader.ListType);
            Assert.True(reader.HasValue);
            Assert.False(reader.IsCompound);
            Assert.False(reader.IsList);
            Assert.False(reader.IsListElement);
            Assert.False(reader.HasLength);
            Assert.Equal(0, reader.ListIndex);
            Assert.Equal(2, reader.Depth);
            Assert.Equal("root", reader.ParentName);
            Assert.Equal(NbtTagType.Compound, reader.ParentTagType);
            Assert.Equal(0, reader.ParentTagLength);
            Assert.Equal(0, reader.TagLength);
            Assert.Equal(18, reader.TagsRead);

            Assert.True(reader.ReadToFollowing());
            Assert.Equal("hugeArray", reader.TagName);
            Assert.Equal(NbtTagType.ByteArray, reader.TagType);
            Assert.Equal(NbtTagType.Unknown, reader.ListType);
            Assert.True(reader.HasValue);
            Assert.False(reader.IsCompound);
            Assert.False(reader.IsList);
            Assert.False(reader.IsListElement);
            Assert.True(reader.HasLength);
            Assert.Equal(0, reader.ListIndex);
            Assert.Equal(2, reader.Depth);
            Assert.Equal("root", reader.ParentName);
            Assert.Equal(NbtTagType.Compound, reader.ParentTagType);
            Assert.Equal(0, reader.ParentTagLength);
            Assert.Equal(1024 * 1024, reader.TagLength);
            Assert.Equal(19, reader.TagsRead);
        }