Esempio n. 1
0
        public void testSerialisationOfEmptyRule()
        {
            Form form = new Form();
            form.Width = 200;
            form.Height = 200;
            // Create a rule named 'magicName's;
            ctlRule ruleControl = new ctlRule { Parent = form };

            rule targetRule = ruleControl.getRule();
            targetRule.changeName("", "magicName");
            targetRule.state = ruleState.running;

            // Serialize it
            string serialised = ruleControl.serialiseRule();

            // verify that serialization hasn't broken anything
            Assert.IsTrue(targetRule.name == "magicName");
            Assert.IsTrue(targetRule.state == ruleState.running);
            Assert.IsTrue(targetRule.preferredHeight == 200);
            Assert.IsTrue(targetRule.preferredWidth == 200);

            // deserialise in to a new rule
            ctlRule deSerRuleControl = new ctlRule();
            deSerRuleControl.deserialiseRule(serialised);
            targetRule = deSerRuleControl.getRule();
            // Verify that de-serialised rule has correct settings
            Assert.IsTrue(targetRule.name == "magicName", "De-serialised rule did not have the expected name - got " + targetRule.name);
            Assert.IsTrue(targetRule.state == ruleState.running, "De-serialised rule did not have the expected state - got " + targetRule.state);
            Assert.IsTrue(targetRule.preferredWidth == 200, "De-serialised rule did not have the expected width - got " + targetRule.preferredWidth);
            Assert.IsTrue(targetRule.preferredHeight == 200, "De-serialised rule did not have the expected height - got " + targetRule.preferredHeight);
        }
Esempio n. 2
0
        public void testSerialisationOfDeletedLineChain()
        {
            ctlRule ruleControl = new ctlRule(){Parent = new Form()};

            lineChain newChain = new lineChain();
            rule targetRule = ruleControl.getRule();
            targetRule.AddLineChainToGlobalPool(newChain);

            // Delete the new chain
            newChain.requestDelete();

            // Ser and deser
            String serialized = ruleControl.serialiseRule();
            ctlRule deSerRuleControl = new ctlRule();
            deSerRuleControl.deserialiseRule(serialized);

            // Verify that our deleted linechain exists
            Assert.AreEqual(1, deSerRuleControl.getRule().lineChainCount);
            // and that it has been deleted
            Assert.AreEqual(true, deSerRuleControl.getRule().GetLineChainFromGuid(newChain.serial).isDeleted);
        }
Esempio n. 3
0
        private void testSerialisationOfRuleWithNamedRuleItem(Type targetType)
        {
            ctlRule ruleControl = new ctlRule();

            // Make a new rule with one RuleItem, of the specified type, and one lineChain.
            ruleItemInfo myInfo = new ruleItemInfo();
            myInfo.itemType = ruleItemType.RuleItem;
            myInfo.ruleItemBaseType = targetType;
            ruleControl.addRuleItem(myInfo);

            lineChain newChain = new lineChain();
            rule targetRule = ruleControl.getRule();
            targetRule.AddLineChainToGlobalPool(newChain);
            newChain.start.X = 10;
            newChain.start.Y = 20;
            newChain.end.X = 11;
            newChain.end.Y = 22;
            newChain.col = Color.CornflowerBlue;
            newChain.isdrawnbackwards = true;
            newChain.midPoints = new List<Point>();
            newChain.midPoints.Add(new Point(33, 44));

            // serialise it
            String serialised = ruleControl.serialiseRule();

            // Deserialise it!
            ctlRule deSerRuleControl = new ctlRule();
            deSerRuleControl.deserialiseRule(serialised);

            Assert.IsTrue(deSerRuleControl.getRule().lineChainCount == 1, "Deserialised rule did not have exactly one lineChain");
            Assert.IsTrue(deSerRuleControl.getRule().ruleItemCount == 1, "Deserialised rule did not have exactly one ruleItem");

            // Ensure that we can get the lineChain by the same GUID as we had before
            lineChain deSerLineChain = deSerRuleControl.getRule().GetLineChainFromGuid(newChain.serial);

            // Get the ruleItem. Note that we don't know its GUID yet so we must find it via its iterator.
            string ruleGuid = null;
            foreach (string indexer in deSerRuleControl.getRule().ruleItems.Keys)
                ruleGuid = indexer;

            Assert.IsNotNull(ruleGuid);

            rule deserialisedRule = deSerRuleControl.getRule();
            Assert.IsInstanceOfType(deserialisedRule.GetRuleItemFromGuid(new ruleItemGuid(ruleGuid)), targetType, "Deserialised rule did not preserve type of its ruleItem");
            Assert.IsTrue(deSerLineChain.start.X == 10);
            Assert.IsTrue(deSerLineChain.start.Y == 20);
            Assert.IsTrue(deSerLineChain.end.X == 11);
            Assert.IsTrue(deSerLineChain.end.Y == 22);
            Assert.IsTrue(deSerLineChain.col.R == Color.CornflowerBlue.R);
            Assert.IsTrue(deSerLineChain.col.G == Color.CornflowerBlue.G);
            Assert.IsTrue(deSerLineChain.col.B == Color.CornflowerBlue.B);
            Assert.IsFalse(deSerLineChain.isDeleted);
            Assert.IsTrue(deSerLineChain.isdrawnbackwards);
            Assert.IsTrue(deSerLineChain.midPoints.Count == 1);
            Assert.IsTrue(deSerLineChain.midPoints[0].X == 33);
            Assert.IsTrue(deSerLineChain.midPoints[0].Y == 44);
        }