public unsafe void Test_ReadWriteFDA() { int nodesCount = 1 + 4 + 4 * 4 + 4 * 4 * 4; TestTree tree = new TestTree(nodesCount); int idx = 0; CreateTestTree(tree, ref idx, 0, 3, 4); tree.Version.Major = 4; tree.Version.Minor = 2; tree.UserData = 1234567; string fileName = Path.Combine(_outDir, "uftree.dat"); tree.Write(fileName); TestTree tree1 = TestTree.ReadFDA <TestTree>(fileName); Assert.AreEqual(tree.Version, tree1.Version); // Do not check the user data, it is not supported by FDA Assert.AreEqual(tree.NodesCount, tree1.NodesCount); for (int i = 0; i < tree.NodesCount; ++i) { Assert.AreEqual(tree.GetDepth(i), tree1.GetDepth(i), i.ToString()); TestNode n, n1; tree.GetNode(i, (byte *)&n); tree1.GetNode(i, (byte *)&n1); Assert.AreEqual(n.Id, n1.Id, i.ToString()); } }
public unsafe void Test_ReadWrite() { int nodesCount = 1 + 4 + 4 * 4 + 4 * 4 * 4; TestTree tree = new TestTree(nodesCount); int idx = 0; CreateTestTree(tree, ref idx, 0, 3, 4); tree.Version.Major = 4; tree.Version.Minor = 2; tree.UserData = 1234567; MemoryStream ms = new MemoryStream(); BinaryWriter w = new BinaryWriter(ms); tree.Write(w); byte[] buffer = ms.ToArray(); ms = new MemoryStream(buffer); BinaryReader r = new BinaryReader(ms); TestTree tree1 = TestTree.Read <TestTree>(r); Assert.AreEqual(tree.Version, tree1.Version); Assert.AreEqual(tree.UserData, tree1.UserData); Assert.AreEqual(tree.NodesCount, tree1.NodesCount); for (int i = 0; i < tree.NodesCount; ++i) { Assert.AreEqual(tree.GetDepth(i), tree1.GetDepth(i)); Assert.AreEqual(tree.Nodes[i].Id, tree1.Nodes[i].Id); } }