Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        public void CreateItem()
        {
            Assert.IsNull(KmlItem.CreateItem(null));
            Assert.IsNull(KmlItem.CreateItem("{xy"));
            Assert.IsNull(KmlItem.CreateItem("x{y"));
            Assert.IsNull(KmlItem.CreateItem("xy{"));
            Assert.IsNull(KmlItem.CreateItem("}xy"));
            Assert.IsNull(KmlItem.CreateItem("x}y"));
            Assert.IsNull(KmlItem.CreateItem("xy}"));

            KmlItem test;

            test = KmlItem.CreateItem("attrib = value");
            Assert.IsTrue(test is KmlAttrib);
            test = KmlItem.CreateItem("node");
            Assert.IsTrue(test is KmlNode);
            test = KmlItem.CreateItem("vessel");
            Assert.IsTrue(test is KmlVessel);
            test = KmlItem.CreateItem("kerbal");
            Assert.IsTrue(test is KmlKerbal);
            test = KmlItem.CreateItem("part");
            Assert.IsTrue(test is KmlPart);
            test = KmlItem.CreateItem("resource");
            Assert.IsTrue(test is KmlResource);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        public void MixedInsert()
        {
            KmlNode root  = data.Root2;
            KmlNode node1 = KmlItem.CreateItem("node1") as KmlNode;

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

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

            root.InsertBefore(node1, unknown);
            KmlNode node2 = KmlItem.CreateItem("node2") as KmlNode;

            root.InsertBefore(node1, node2);
            KmlAttrib attrib2 = KmlItem.CreateItem("attrib2 = value2") as KmlAttrib;

            root.InsertBefore(attrib1, 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(attrib2, root.Attribs[0]);
            Assert.AreEqual(attrib1, root.Attribs[1]);
            Assert.AreEqual(unknown, root.Unknown[0]);
            Assert.AreEqual(node2, root.Children[0]);
            Assert.AreEqual(node1, root.Children[1]);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 7
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]);
        }
Ejemplo n.º 8
0
        public void AttribInsertBeforeNotContained()
        {
            KmlAttrib attrib = KmlItem.CreateItem("attrib = value") as KmlAttrib;

            data.Node1.InsertBefore(data.Node2Attrib1, attrib);

            Assert.AreEqual(data.Node1AttribCount + 1, data.Node1.Attribs.Count);
            Assert.AreEqual(data.Node1AttribCount + data.Node1ChildCount + 1, data.Node1.AllItems.Count);
            Assert.AreEqual(attrib, data.Node1.Attribs[data.Node1AttribCount]);
        }
Ejemplo n.º 9
0
        public void AttribInsertAfterEmpty()
        {
            KmlAttrib attrib = KmlItem.CreateItem("attrib = value") as KmlAttrib;

            data.Node1.InsertAfter(null, attrib);

            Assert.AreEqual(data.Node1AttribCount + 1, data.Node1.Attribs.Count);
            Assert.AreEqual(data.Node1AttribCount + data.Node1ChildCount + 1, data.Node1.AllItems.Count);
            Assert.AreEqual(attrib, data.Node1.Attribs[data.Node1AttribCount]);
        }
Ejemplo n.º 10
0
        private KmlNode NewNode(string tag, string name)
        {
            KmlNode node = KmlItem.CreateItem(tag) as KmlNode;

            if (name != null)
            {
                Add(node, NewAttrib("name", name));
            }
            return(node);
        }
Ejemplo n.º 11
0
        public void ChildInsertBeforeNotContained()
        {
            KmlNode child = KmlItem.CreateItem("child") as KmlNode;

            data.Node1.InsertBefore(data.Node2Child1, child);

            Assert.AreEqual(data.Node1ChildCount + 1, data.Node1.Children.Count);
            Assert.AreEqual(data.Node1AttribCount + data.Node1ChildCount + 1, data.Node1.AllItems.Count);
            Assert.AreEqual(child, data.Node1.Children[data.Node1ChildCount]);
        }
Ejemplo n.º 12
0
        public void ChildInsertAfterEmpty()
        {
            KmlNode child = KmlItem.CreateItem("child") as KmlNode;

            data.Node1.InsertAfter(null, child);

            Assert.AreEqual(data.Node1ChildCount + 1, data.Node1.Children.Count);
            Assert.AreEqual(data.Node1AttribCount + data.Node1ChildCount + 1, data.Node1.AllItems.Count);
            Assert.AreEqual(child, data.Node1.Children[data.Node1ChildCount]);
        }
Ejemplo n.º 13
0
        public void AttribChangeName()
        {
            KmlAttrib attrib = KmlItem.CreateItem("name = rootname") as KmlAttrib;

            data.Root1.Add(attrib);

            Assert.AreEqual("rootname", data.Root1.Name);
            attrib.Value = "newname";
            Assert.AreEqual("newname", data.Root1.Name);
        }
Ejemplo n.º 14
0
        public void ChildrenChangedEvent()
        {
            data.Root1.ChildrenChanged += TestEventHandler;
            _testEventHandlerVisited    = false;
            KmlNode child = KmlItem.CreateItem("child") as KmlNode;

            data.Root1.Add(child);
            Assert.IsTrue(_testEventHandlerVisited);
            _testEventHandlerVisited = false;
            data.Root1.Delete(child);
            Assert.IsTrue(_testEventHandlerVisited);
        }
Ejemplo n.º 15
0
        public void WarningAttribAddAfterNode()
        {
            // Syntax.Messages are static, there may be some from other tests
            int messageCount = Syntax.Messages.Count;

            KmlAttrib attrib = KmlItem.CreateItem("attrib = value") as KmlAttrib;

            data.Root1.Add(attrib);

            Assert.AreEqual(messageCount + 1, Syntax.Messages.Count);
            Assert.AreEqual(attrib, Syntax.Messages[Syntax.Messages.Count - 1].Source);
        }
Ejemplo n.º 16
0
        public void AttribInsertBefore()
        {
            KmlAttrib attrib = KmlItem.CreateItem("attrib = value") as KmlAttrib;

            data.Node1.InsertBefore(data.Node1Attrib1, attrib);

            Assert.AreEqual(data.Node1AttribCount + 1, data.Node1.Attribs.Count);
            Assert.AreEqual(data.Node1AttribCount + data.Node1ChildCount + 1, data.Node1.AllItems.Count);
            // data.Node1.Attribs[0] is name attrib
            Assert.AreEqual(attrib, data.Node1.Attribs[1]);
            Assert.AreEqual(data.Node1Attrib1, data.Node1.Attribs[2]);
        }
Ejemplo n.º 17
0
        public void ChildInsertAfter()
        {
            KmlNode child3 = KmlItem.CreateItem("child3") as KmlNode;

            data.Node1.InsertAfter(data.Node1Child1, child3);

            Assert.AreEqual(data.Node1ChildCount + 1, data.Node1.Children.Count);
            Assert.AreEqual(data.Node1AttribCount + data.Node1ChildCount + 1, data.Node1.AllItems.Count);
            Assert.AreEqual(data.Node1Child1, data.Node1.Children[0]);
            Assert.AreEqual(child3, data.Node1.Children[1]);
            Assert.AreEqual(data.Node1Child2, data.Node1.Children[2]);
        }
Ejemplo n.º 18
0
        public void AttribChangedEvent()
        {
            data.Root1.AttribChanged += TestEventHandler;
            _testEventHandlerVisited  = false;
            KmlAttrib attrib = KmlItem.CreateItem("attrib = value") as KmlAttrib;

            data.Root1.Add(attrib);
            Assert.IsTrue(_testEventHandlerVisited);
            _testEventHandlerVisited = false;
            data.Root1.Delete(attrib);
            Assert.IsTrue(_testEventHandlerVisited);
        }
Ejemplo n.º 19
0
        public void AssignParent()
        {
            KmlKerbal kerbal = KmlItem.CreateItem("KERBAL") as KmlKerbal;

            Assert.AreEqual(KmlKerbal.KerbalOrigin.Other, kerbal.Origin);
            Assert.IsNull(kerbal.Parent);
            data.Roster.Add(kerbal);
            Assert.AreEqual(KmlKerbal.KerbalOrigin.Roster, kerbal.Origin);
            Assert.AreEqual(data.Roster, kerbal.Parent);
            data.Root2.Add(kerbal);
            Assert.AreEqual(KmlKerbal.KerbalOrigin.Other, kerbal.Origin);
            Assert.AreEqual(data.Root2, kerbal.Parent);
        }
Ejemplo n.º 20
0
        public void AttribInsertAfter()
        {
            KmlAttrib attrib3 = KmlItem.CreateItem("attrib3 = value3") as KmlAttrib;

            data.Node1.InsertAfter(data.Node1Attrib1, attrib3);

            Assert.AreEqual(data.Node1AttribCount + 1, data.Node1.Attribs.Count);
            Assert.AreEqual(data.Node1AttribCount + data.Node1ChildCount + 1, data.Node1.AllItems.Count);
            // data.Node1.Attribs[0] is name attrib
            Assert.AreEqual(data.Node1Attrib1, data.Node1.Attribs[1]);
            Assert.AreEqual(attrib3, data.Node1.Attribs[2]);
            Assert.AreEqual(data.Node1Attrib2, data.Node1.Attribs[3]);
        }
Ejemplo n.º 21
0
        public void CreateItem()
        {
            KmlItem item = KmlItem.CreateItem("RESOURCE");

            Assert.IsNotNull(item);
            Assert.IsTrue(item is KmlResource);
            KmlResource res = (KmlResource)item;

            Assert.AreEqual("", res.Name);
            Assert.AreEqual("", res.Amount.Value);
            Assert.AreEqual("", res.MaxAmount.Value);
            Assert.AreEqual(1.0, res.AmountRatio);
        }
Ejemplo n.º 22
0
        public void AssignParent()
        {
            KmlPart part = KmlItem.CreateItem("PART") as KmlPart;

            Assert.AreEqual(KmlPart.PartOrigin.Other, part.Origin);
            Assert.IsNull(part.Parent);
            data.Vessel1.Add(part);
            Assert.AreEqual(KmlPart.PartOrigin.Vessel, part.Origin);
            Assert.AreEqual(data.Vessel1, part.Parent);
            data.Root2.Add(part);
            Assert.AreEqual(KmlPart.PartOrigin.Other, part.Origin);
            Assert.AreEqual(data.Root2, part.Parent);
        }
Ejemplo n.º 23
0
        public void AttribValueChanged()
        {
            KmlAttrib attrib = KmlItem.CreateItem("name =") as KmlAttrib;

            attrib.AttribValueChanged += TestEventHandler;

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

            _testEventHandlerVisited = false;
            attrib.Value             = "value2";
            Assert.IsTrue(_testEventHandlerVisited);
        }
Ejemplo n.º 24
0
        public void AttribAddToEnd()
        {
            KmlAttrib attrib1 = KmlItem.CreateItem("attrib1 = value1") as KmlAttrib;

            data.Root2.Add(attrib1);
            KmlAttrib attrib2 = KmlItem.CreateItem("attrib2 = value2") as KmlAttrib;

            data.Root2.Add(attrib2);

            Assert.AreEqual(2, data.Root2.Attribs.Count);
            Assert.AreEqual(2, data.Root2.AllItems.Count);
            Assert.AreEqual(attrib1, data.Root2.Attribs[0]);
            Assert.AreEqual(attrib2, data.Root2.Attribs[1]);
        }
Ejemplo n.º 25
0
        public void ChildAddToEnd()
        {
            KmlNode node1 = KmlItem.CreateItem("node1") as KmlNode;

            data.Root2.Add(node1);
            KmlNode node2 = KmlItem.CreateItem("node2") as KmlNode;

            data.Root2.Add(node2);

            Assert.AreEqual(2, data.Root2.Children.Count);
            Assert.AreEqual(2, data.Root2.AllItems.Count);
            Assert.AreEqual(node1, data.Root2.Children[0]);
            Assert.AreEqual(node2, data.Root2.Children[1]);
        }
Ejemplo n.º 26
0
        public void AttribAddRange()
        {
            List <KmlItem> list    = new List <KmlItem>();
            KmlAttrib      attrib1 = KmlItem.CreateItem("attrib1 = value1") as KmlAttrib;

            list.Add(attrib1);
            KmlAttrib attrib2 = KmlItem.CreateItem("attrib2 = value2") as KmlAttrib;

            list.Add(attrib2);
            data.Root2.AddRange(list);

            Assert.AreEqual(2, data.Root2.Attribs.Count);
            Assert.AreEqual(2, data.Root2.AllItems.Count);
            Assert.AreEqual(attrib1, data.Root2.Attribs[0]);
            Assert.AreEqual(attrib2, data.Root2.Attribs[1]);
        }
Ejemplo n.º 27
0
        public void ChildAddRange()
        {
            List <KmlItem> list  = new List <KmlItem>();
            KmlNode        node1 = KmlItem.CreateItem("node1") as KmlNode;

            list.Add(node1);
            KmlNode node2 = KmlItem.CreateItem("node2") as KmlNode;

            list.Add(node2);
            data.Root2.AddRange(list);

            Assert.AreEqual(2, data.Root2.Children.Count);
            Assert.AreEqual(2, data.Root2.AllItems.Count);
            Assert.AreEqual(node1, data.Root2.Children[0]);
            Assert.AreEqual(node2, data.Root2.Children[1]);
        }
Ejemplo n.º 28
0
        public void CreateItem()
        {
            KmlItem item = KmlItem.CreateItem("PART");

            Assert.IsNotNull(item);
            Assert.IsTrue(item is KmlPart);
            KmlPart part = (KmlPart)item;

            Assert.AreEqual("", part.Name);
            Assert.AreEqual("", part.Flag);
            Assert.IsFalse(part.HasResources);
            Assert.AreEqual(-1, part.ParentPartIndex);
            Assert.AreEqual(new System.Windows.Media.Media3D.Point3D(0.0, 0.0, 0.0),
                            part.Position);
            Assert.AreEqual(0, part.Resources.Count);
            Assert.AreEqual(0, part.ResourceTypes.Count);
            Assert.AreEqual("", part.Uid);
        }
Ejemplo n.º 29
0
        public void CreateItem()
        {
            KmlItem item = KmlItem.CreateItem("KERBAL");

            Assert.IsNotNull(item);
            Assert.IsTrue(item is KmlKerbal);
            KmlKerbal kerbal = (KmlKerbal)item;

            Assert.AreEqual("", kerbal.Name);
            Assert.AreEqual(KmlKerbal.KerbalOrigin.Other, kerbal.Origin);
            Assert.IsNull(kerbal.Parent);
            Assert.AreEqual("", kerbal.State);
            Assert.AreEqual("", kerbal.Type);
            Assert.AreEqual("", kerbal.Trait);
            Assert.AreEqual(0.0, kerbal.Brave);
            Assert.AreEqual(0.0, kerbal.Dumb);
            Assert.IsNull(kerbal.AssignedPart);
            Assert.IsNull(kerbal.AssignedVessel);
        }
Ejemplo n.º 30
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);
        }