Beispiel #1
0
        private void VerifyReadTreeWithNestedLists(
            IDataNode node,
            TreeWithNestedLists.Class value,
            uint originalPosition1,
            uint originalPosition2,
            uint offsetPosition1,
            uint offsetPosition2
            )
        {
            node.Read(binaryReader);

            void verifyReadList <T>(IListNode listNode, IList <T> list, uint originalPosition, uint offset, Action <IDataNode> verifyReadValue)
            {
                listNode.ReadEntryCount(binaryReader);
                listNode.ReadOffset(binaryReader);

                binaryReader.VerifyDoAtPosition(originalPosition, offset, () =>
                {
                    foreach (var entry in list)
                    {
                        verifyReadValue(listNode.ChildNode);
                    }
                });
            }

            verifyReadList(node.Edges[0].ChildNode as IListNode, value.List1, originalPosition1, offsetPosition1, VerifyReadTreeWithHeight1);
            verifyReadList(node.Edges[1].ChildNode as IListNode, value.List2, originalPosition2, offsetPosition2, VerifyReadTreeWithHeight2);
        }
Beispiel #2
0
 private void VerifyReadTreeWithHeight1(IDataNode node)
 {
     node.Read(binaryReader);
     (node.Edges[0].ChildNode as IDataNode).Read(binaryReader);
     (node.Edges[1].ChildNode as IDataNode).Read(binaryReader);
     (node.Edges[2].ChildNode as IDataNode).Read(binaryReader);
 }
Beispiel #3
0
        public void Test_Reading_From_A_BinaryReader()
        {
            string expected = nameof(expected);

            childNode.Read(binaryReader).Returns(expected);

            object result = paddingNode.Read(binaryReader);

            Received.InOrder(() =>
            {
                childNode.Read(binaryReader);
                binaryReader.ReadBytes(PADDING_SIZE);
            });

            result.Should().Be(expected);
        }
Beispiel #4
0
        private void VerifyReadTreeWithNodeAtOffset(IDataNode node, uint originalPosition, uint offsetPosition)
        {
            node.Read(binaryReader);

            IOffsetNode offsetNode = node.Edges[0].ChildNode as IOffsetNode;

            offsetNode.ReadOffset(binaryReader);
            binaryReader.VerifyDoAtPosition(originalPosition, offsetPosition, () => offsetNode.ChildNode.Read(binaryReader));

            (node.Edges[1].ChildNode as IDataNode).Read(binaryReader);
        }
Beispiel #5
0
        private void SetupTreeWithNodeAtOffset(IDataNode node, TreeWithNodeAtOffset.Class expected, uint offset)
        {
            node.Read(binaryReader).Returns(_ => new TreeWithNodeAtOffset.Class());

            IOffsetNode offsetNode = node.Edges[0].ChildNode as IOffsetNode;

            offsetNode.ReadOffset(binaryReader).Returns(offset);
            offsetNode.ChildNode.Read(binaryReader).Returns(expected.ValueAtOffset);

            (node.Edges[1].ChildNode as IDataNode).Read(binaryReader).Returns(expected.ValueInline);
        }
Beispiel #6
0
        private object ProcessDataNode(IBinaryReader binaryReader, IDataNode node)
        {
            object value = node.Read(binaryReader);

            foreach (IEdge edge in node.Edges)
            {
                object childValue = ProcessNode(binaryReader, edge.ChildNode);

                edge.SetChildValue(value, childValue);
            }

            return(value);
        }
Beispiel #7
0
        private void SetupTreeWithHeight1(IDataNode node, TreeWithHeight1.Class expected, params TreeWithHeight1.Class[] otherExpected)
        {
            node.Read(binaryReader).Returns(_ => new TreeWithHeight1.Class());

            void setupDataNode(IDataNode dataNode, Func <TreeWithHeight1.Class, object> valueExtractor)
            {
                dataNode.Read(binaryReader).Returns(valueExtractor(expected), otherExpected.Select(e => valueExtractor(e)).ToArray());
            }

            setupDataNode(dataNode: node.Edges[0].ChildNode as IDataNode, valueExtractor: e => e.Int);
            setupDataNode(dataNode: node.Edges[1].ChildNode as IDataNode, valueExtractor: e => e.Float);
            setupDataNode(dataNode: node.Edges[2].ChildNode as IDataNode, valueExtractor: e => e.Byte);
        }
Beispiel #8
0
        private void VerifyReadTreeWithNestedLists(IDataNode node)
        {
            node.Read(binaryReader);

            void verifyReadList(IListNode listNode)
            {
                listNode.ReadEntryCount(binaryReader);
                listNode.ReadOffset(binaryReader);
            }

            verifyReadList(node.Edges[0].ChildNode as IListNode);
            verifyReadList(node.Edges[1].ChildNode as IListNode);
        }
Beispiel #9
0
        private void SetupTreeWithNestedLists(IDataNode node, TreeWithNestedLists.Class expected, uint offset1, uint offset2)
        {
            node.Read(binaryReader).Returns(_ => new TreeWithNestedLists.Class());

            void setupListNode <T>(IListNode listNode, IList <T> expectedList, uint offset, Action <IDataNode, T, T[]> setupValues)
            {
                listNode.ReadEntryCount(binaryReader).Returns(expectedList.Count);
                listNode.ReadOffset(binaryReader).Returns(offset);

                if (expectedList.IsNotEmpty())
                {
                    setupValues(listNode.ChildNode, expectedList[0], expectedList.Skip(1).ToArray());
                }
            }

            setupListNode(node.Edges[0].ChildNode as IListNode, expected.List1, offset1, SetupTreeWithHeight1);
            setupListNode(node.Edges[1].ChildNode as IListNode, expected.List2, offset2, SetupTreeWithHeight2);
        }
Beispiel #10
0
 private void SetupTreeWithHeight3(IDataNode node, TreeWithHeight3.Class expected)
 {
     node.Read(binaryReader).Returns(_ => new TreeWithHeight3.Class());
     SetupTreeWithHeight2(node.Edges[0].ChildNode as IDataNode, expected.Child1);
     SetupTreeWithHeight2(node.Edges[1].ChildNode as IDataNode, expected.Child2);
 }
Beispiel #11
0
 private void SetupTreeWithHeight2(IDataNode node, TreeWithHeight2.Class expected, params TreeWithHeight2.Class[] otherExpected)
 {
     node.Read(binaryReader).Returns(_ => new TreeWithHeight2.Class());
     (node.Edges[0].ChildNode as IDataNode).Read(binaryReader).Returns(expected.Long, otherExpected.Select(e => (object)e.Long).ToArray());
     SetupTreeWithHeight1(node.Edges[1].ChildNode as IDataNode, expected.Child, otherExpected.Select(e => e.Child).ToArray());
 }