Пример #1
0
        public void MixedAddWellOrdered()
        {
            KmlNode   root    = data.Root2;
            KmlAttrib attrib1 = KmlItem.CreateItem("attrib1 = value1") as KmlAttrib;

            root.Add(attrib1);
            KmlNode node1 = KmlItem.CreateItem("node1") as KmlNode;

            root.Add(node1);
            KmlAttrib attrib2 = KmlItem.CreateItem("attrib2 = value1") as KmlAttrib;

            root.Add(attrib2);
            KmlNode node2 = KmlItem.CreateItem("node2") as KmlNode;

            root.Add(node2);
            KmlAttrib attrib3 = KmlItem.CreateItem("attrib3 = value2") as KmlAttrib;

            root.Add(attrib3);

            Assert.AreEqual(3, root.Attribs.Count);
            Assert.AreEqual(2, root.Children.Count);
            Assert.AreEqual(5, root.AllItems.Count);
            Assert.AreEqual(attrib1, root.AllItems[0]);
            Assert.AreEqual(attrib2, root.AllItems[1]);
            Assert.AreEqual(attrib3, root.AllItems[2]);
            Assert.AreEqual(node1, root.AllItems[3]);
            Assert.AreEqual(node2, root.AllItems[4]);
        }
Пример #2
0
        public void PartIsDock()
        {
            Assert.IsFalse(KmlPartDock.PartIsDock(data.Vessel1Part1));
            Assert.IsFalse(KmlPartDock.PartIsDock(data.Vessel1Part2));

            KmlPart part = (KmlPart)KmlItem.CreateItem("PART");

            Assert.IsFalse(KmlPartDock.PartIsDock(part));

            KmlNode module = (KmlNode)KmlItem.CreateItem("WrongTag");

            part.Add(module);
            Assert.IsFalse(KmlPartDock.PartIsDock(part));
            module.Add(KmlItem.CreateItem("name = ModuleDockingNode"));
            Assert.IsFalse(KmlPartDock.PartIsDock(part));

            module = (KmlNode)KmlItem.CreateItem("MODULE");
            part.Add(module);
            Assert.IsFalse(KmlPartDock.PartIsDock(part));
            KmlAttrib name = (KmlAttrib)KmlItem.CreateItem("name = ModuleDockingNode");

            module.Add(name);
            Assert.IsTrue(KmlPartDock.PartIsDock(part));
            name.Value = "WrongName";
            Assert.IsFalse(KmlPartDock.PartIsDock(part));
            name.Value = "ModuleDockingNodeNamed";
            Assert.IsTrue(KmlPartDock.PartIsDock(part));
            name.Value = "ModuleGrappleNode";
            Assert.IsTrue(KmlPartDock.PartIsDock(part));
            name.Value = "KASModuleStrut";
            Assert.IsTrue(KmlPartDock.PartIsDock(part));
        }
Пример #3
0
        public void MixedAdd()
        {
            KmlNode root  = data.Root2;
            KmlNode node1 = KmlItem.CreateItem("node1") as KmlNode;

            root.Add(node1);
            KmlAttrib attrib1 = KmlItem.CreateItem("attrib1 = value1") as KmlAttrib;

            root.Add(attrib1);
            // KmlItem constructor is only way to create a KmlItem (unknown) instead of KmlNode or KmlAttrib
            KmlItem unknown = new KmlItem("unknown");

            root.Add(unknown);
            KmlNode node2 = KmlItem.CreateItem("node2") as KmlNode;

            root.Add(node2);
            KmlAttrib attrib2 = KmlItem.CreateItem("attrib2 = value2") as KmlAttrib;

            root.Add(attrib2);

            Assert.AreEqual(2, root.Attribs.Count);
            Assert.AreEqual(2, root.Children.Count);
            Assert.AreEqual(1, root.Unknown.Count);
            Assert.AreEqual(5, root.AllItems.Count);
            Assert.AreEqual(attrib1, root.Attribs[0]);
            Assert.AreEqual(attrib2, root.Attribs[1]);
            Assert.AreEqual(node1, root.Children[0]);
            Assert.AreEqual(node2, root.Children[1]);
            Assert.AreEqual(unknown, root.Unknown[0]);
        }
Пример #4
0
        public void ChildGetName()
        {
            KmlNode root  = data.Root2;
            KmlNode node1 = KmlItem.CreateItem("node") as KmlNode;

            node1.Add(KmlItem.CreateItem("name = name1"));
            root.Add(node1);
            KmlNode node2 = KmlItem.CreateItem("node") as KmlNode;

            node2.Add(KmlItem.CreateItem("name = name2"));
            root.Add(node2);
            KmlNode node3 = KmlItem.CreateItem("node") as KmlNode;

            node3.Add(KmlItem.CreateItem("name = name3"));
            root.Add(node3);

            KmlNode test = root.GetChildNode("node", "name2");

            Assert.AreEqual(node2, test);
            KmlNode badname = root.GetChildNode("node", "badname");

            Assert.IsNull(badname);
            KmlNode badtag = root.GetChildNode("badtag", "name2");

            Assert.IsNull(badtag);
            KmlNode nonsense = root.GetChildNode("non", "sense");

            Assert.IsNull(nonsense);
        }
Пример #5
0
        public void CreateItem()
        {
            KmlPart part = (KmlPart)KmlItem.CreateItem("PART");

            KmlNode module = (KmlNode)KmlItem.CreateItem("MODULE");

            part.Add(module);
            KmlAttrib name = (KmlAttrib)KmlItem.CreateItem("name = ModuleDockingNode");

            module.Add(name);
            Assert.IsTrue(KmlPartDock.PartIsDock(part));

            // Need to parse memory roots, to call identify and have the KmlPart
            // replaced by a KmlPartDock
            List <KmlItem> list = new List <KmlItem>();

            list.Add(part);
            list = KmlItem.ParseMemory(list);
            Assert.AreEqual(1, list.Count);
            Assert.AreNotEqual(part, list[0]);
            Assert.IsTrue(list[0] is KmlPartDock);
            KmlPartDock dock = (KmlPartDock)list[0];

            Assert.AreEqual(KmlPartDock.DockTypes.Dock, dock.DockType);
            Assert.AreEqual("", dock.DockName);
            Assert.AreEqual("", dock.DockState);
            Assert.AreEqual("", dock.DockedVesselName);
            Assert.AreEqual("", dock.DockedVesselType);
            Assert.AreEqual("", dock.DockedVesselOtherName);
            Assert.AreEqual("", dock.DockedVesselOtherType);
            Assert.AreEqual("", dock.DockUid);
            Assert.IsNull(dock.DockedPart);
            Assert.IsFalse(dock.NeedsRepair);
        }
Пример #6
0
        public void ToStringChangedEvent()
        {
            KmlNode root = data.Root2;

            root.ToStringChanged += TestEventHandler;

            //_testEventHandlerVisited = false;
            //root.Tag = "other";
            //Assert.IsTrue(_testEventHandlerVisited);

            _testEventHandlerVisited = false;
            KmlAttrib attrib = KmlItem.CreateItem("name = rootname") as KmlAttrib;

            root.Add(attrib);
            Assert.IsTrue(_testEventHandlerVisited);

            _testEventHandlerVisited = false;
            attrib.Value             = "other";
            Assert.IsTrue(_testEventHandlerVisited);

            // attrib.CanBeDeleted will be false
            _testEventHandlerVisited = false;
            Assert.IsFalse(root.Delete(attrib));
            Assert.IsFalse(_testEventHandlerVisited);
        }
Пример #7
0
        public void ChildGetOrCreate()
        {
            KmlNode root  = data.Root2;
            KmlNode node1 = KmlItem.CreateItem("node") as KmlNode;

            node1.Add(KmlItem.CreateItem("name = name1"));
            root.Add(node1);
            KmlNode node2 = KmlItem.CreateItem("node") as KmlNode;

            node2.Add(KmlItem.CreateItem("name = name2"));
            root.Add(node2);
            KmlNode node3 = KmlItem.CreateItem("node") as KmlNode;

            node3.Add(KmlItem.CreateItem("name = name3"));
            root.Add(node3);
            Assert.AreEqual(3, root.Children.Count);

            KmlNode test = root.GetOrCreateChildNode("node", "name2");

            Assert.AreEqual(node2, test);
            Assert.AreEqual(3, root.Children.Count);

            KmlNode badname = root.GetOrCreateChildNode("node", "badname");

            Assert.IsTrue(root.Children.Contains(badname));
            Assert.AreEqual("node", badname.Tag);
            Assert.AreEqual("badname", badname.Name);
            Assert.AreEqual(4, root.Children.Count);

            KmlNode badtag = root.GetOrCreateChildNode("badtag", "name2");

            Assert.IsTrue(root.Children.Contains(badtag));
            Assert.AreEqual("badtag", badtag.Tag);
            Assert.AreEqual("name2", badtag.Name);
            Assert.AreEqual(5, root.Children.Count);

            KmlNode nonsense = root.GetOrCreateChildNode("non", "sense");

            Assert.IsTrue(root.Children.Contains(nonsense));
            Assert.AreEqual("non", nonsense.Tag);
            Assert.AreEqual("sense", nonsense.Name);
            Assert.AreEqual(6, root.Children.Count);
        }
Пример #8
0
 private void Add(KmlNode parent, KmlItem child)
 {
     if (parent == null)
     {
         Roots.Add(child);
     }
     else
     {
         parent.Add(child);
     }
     Count(parent, child);
 }
Пример #9
0
        public void PathToString()
        {
            KmlNode root = new KmlNode("root");
            KmlNode node = new KmlNode("node");
            KmlItem item = new KmlNode("item");

            node.Add(item);
            root.Add(node);
            Assert.AreEqual("root", root.PathToString("-"));
            Assert.AreEqual("root-node", node.PathToString("-"));
            Assert.AreEqual("root/node/item", item.PathToString("/"));
        }
Пример #10
0
        public void Delete()
        {
            KmlItem item = new KmlItem("test");

            Assert.IsFalse(item.Delete());
            item.CanBeDeleted = false;
            Assert.IsFalse(item.Delete());

            KmlNode root = new KmlNode("root");

            root.Add(item);
            Assert.AreEqual(root, item.Parent);
            Assert.IsFalse(item.Delete());
            item.CanBeDeleted = true;
            Assert.IsTrue(item.Delete());
        }