コード例 #1
0
ファイル: ruleItemTests.cs プロジェクト: randomdude/Lavalamp
 public void testProcessRuleItems()
 {
     rule targetRule = new rule();
     ruleItem_runexe runexe = (ruleItem_runexe)targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_runexe)));
     ruleItem_isProcessRunning isRunning = (ruleItem_isProcessRunning)targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_isProcessRunning)));
     ruleItem_killProcess killProcess = (ruleItem_killProcess)targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_killProcess)));
     runexe.fileToRun = @"C:\Windows\system32\cmd.exe";
     isRunning.processName = "cmd";
     killProcess.name = "cmd";
     runexe.pinInfo["input1"].value.data = true;
     targetRule.start();
     runexe.evaluate();
     targetRule.advanceDelta();
     isRunning.pinInfo["trigger"].value.data = true;
     isRunning.evaluate();
     targetRule.advanceDelta();
     bool running = isRunning.pinInfo["output1"].value.asBoolean();
     for(int i = 0; i < 20 && !running;i++ )
     {
         isRunning.evaluate();
         targetRule.advanceDelta();
         running = isRunning.pinInfo["output1"].value.asBoolean();
         if (!running)
             Thread.Sleep(20);
     }
     Assert.AreEqual(running, true);
     killProcess.pinInfo["input1"].value.data = true;
     killProcess.evaluate();
     targetRule.advanceDelta();
     isRunning.evaluate();
     targetRule.advanceDelta();
     running = isRunning.pinInfo["output1"].value.asBoolean();
     Assert.AreEqual(running, false);
 }
コード例 #2
0
ファイル: ruleItemTests.cs プロジェクト: randomdude/Lavalamp
 public void testRssReader()
 {
     rule targetRule = new rule();
     ruleItemRss rss = (ruleItemRss) targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItemRss)));
     rss._options.url = "file://" + Path.GetFullPath(Properties.Settings.Default.testDataPath) + @"\test.rss";
     rss.pinInfo["trigger"].value.data = true;
     targetRule.start();
     rss.evaluate();
     targetRule.advanceDelta();
     Assert.AreEqual("hi <3", rss.pinInfo["feed Title"].value.data);
     Assert.AreEqual("Hello World", rss.pinInfo["feed Content"].value.data);
     rss.pinInfo["trigger"].value.data = true;
     rss.evaluate();
     targetRule.advanceDelta();
     Assert.AreEqual("test entry", rss.pinInfo["feed Title"].value.data);
     Assert.AreEqual("Test 'details'", rss.pinInfo["feed Content"].value.data);
     targetRule.stop();
     rss._options.url = "file://" + Path.GetFullPath(Properties.Settings.Default.testDataPath) + @"\test.atom";
     targetRule.start();
     rss.evaluate();
     targetRule.advanceDelta();
     Assert.AreEqual("Atom-Powered Robots Run Amok", rss.pinInfo["feed Title"].value.data);
     Assert.AreEqual("Some text.", rss.pinInfo["feed Content"].value.data);
     rss.evaluate();
     targetRule.advanceDelta();
     Assert.AreEqual("lol", rss.pinInfo["feed Title"].value.data);
     Assert.AreEqual("test", rss.pinInfo["feed Content"].value.data);
     targetRule.stop();
 }
コード例 #3
0
ファイル: ruleItemTests.cs プロジェクト: randomdude/Lavalamp
 public void testHTMLStripper()
 {
     string html = @"<p><style>font{blah: x }</style>llololol<b>bolded</b><script>alert('x');</script></p>";
     rule targetRule = new rule();
     ruleItem_HTMLStripper htmlStripper = (ruleItem_HTMLStripper)targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_HTMLStripper)));
     htmlStripper.pinInfo["input"].value.data = html;
     htmlStripper.evaluate();
     targetRule.advanceDelta();
     string value = (string) htmlStripper.pinInfo["output"].value.data;
     Assert.AreEqual(value,"llolololbolded");
 }
コード例 #4
0
ファイル: ruleTests.cs プロジェクト: randomdude/Lavalamp
        public void testStartRunRuleItemLinkedToDebugItem()
        {
            rule targetRule = new rule();
            ruleItemBase startItem = targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_startRun)));
            ruleItemBase debugItem = targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_debug)));

            lineChain newChain = new lineChain();
            startItem.pinInfo["StartOfSim"].connectTo(newChain.serial, debugItem.pinInfo["input"]);
            targetRule.AddLineChainToGlobalPool(newChain);

            targetRule.start();
            Assert.AreEqual(false, startItem.pinInfo["StartOfSim"].value.data);
            Assert.AreEqual(tristate.noValue, debugItem.pinInfo["input"].value.data);
            targetRule.advanceDelta();
            Assert.AreEqual(true, startItem.pinInfo["StartOfSim"].value.data);
            Assert.AreEqual(tristate.yes, debugItem.pinInfo["input"].value.data);
            targetRule.advanceDelta();
            Assert.AreEqual(false, startItem.pinInfo["StartOfSim"].value.data);
            Assert.AreEqual(tristate.no, debugItem.pinInfo["input"].value.data);
            targetRule.stop();
        }
コード例 #5
0
ファイル: ruleTests.cs プロジェクト: randomdude/Lavalamp
        public void testStartRunRuleItem()
        {
            rule foo = new rule();
            ruleItemBase newItem = foo.addRuleItem(new ruleItemInfo(typeof(ruleItem_startRun)));

            foo.start();
            Assert.AreEqual(false, newItem.pinInfo["StartOfSim"].value.data);
            foo.advanceDelta();
            Assert.AreEqual(true, newItem.pinInfo["StartOfSim"].value.data);
            foo.advanceDelta();
            Assert.AreEqual(false, newItem.pinInfo["StartOfSim"].value.data);
            foo.stop();
        }
コード例 #6
0
ファイル: ruleItemTests.cs プロジェクト: randomdude/Lavalamp
        public void testSwitchRuleItem()
        {
            rule targetRule = new rule();
            ruleItem_switch switchRule = (ruleItem_switch)targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_switch)));

            targetRule.start();
            //test bools
            switchRule.pinInfo["inputTrue"].value.data = true;
            switchRule.pinInfo["inputFalse"].value.data = false;
            switchRule.pinInfo["switch"].value.data = false;
            //must start as tristate and noValue
            Assert.IsInstanceOfType(switchRule.pinInfo["output"].value.data, typeof(tristate));
            Assert.AreEqual(switchRule.pinInfo["output"].value.data,tristate.noValue);
            switchRule.evaluate();
            targetRule.advanceDelta();
            Assert.IsInstanceOfType(switchRule.pinInfo["output"].value.data, typeof(bool));
            Assert.IsFalse((bool) switchRule.pinInfo["output"].value.data);
            switchRule.pinInfo["switch"].value.data = true;
            switchRule.evaluate();
            targetRule.advanceDelta();
            Assert.IsTrue((bool) switchRule.pinInfo["output"].value.data);
            //test string and bool
            switchRule.pinInfo["inputFalse"].valueType = typeof(pinDataString);
            switchRule.pinInfo["inputFalse"].recreateValue();
            switchRule.pinInfo["inputFalse"].value.data = "True";
            switchRule.pinInfo["switch"].value.data = false;
            switchRule.evaluate();
            targetRule.advanceDelta();
            Assert.IsInstanceOfType(switchRule.pinInfo["output"].value.data, typeof(string));
            Assert.AreEqual(switchRule.pinInfo["output"].value.data, "True");
            switchRule.pinInfo["switch"].value.data = true;
            switchRule.evaluate();
            targetRule.advanceDelta();
            Assert.IsInstanceOfType(switchRule.pinInfo["output"].value.data, typeof(bool));
            Assert.IsTrue((bool) switchRule.pinInfo["output"].value.data);
            //test int and bool
            switchRule.pinInfo["inputFalse"].valueType = typeof(pinDataNumber);
            switchRule.pinInfo["inputFalse"].recreateValue();
            switchRule.pinInfo["inputFalse"].value.data = new GenericNumber<short>(255);
            switchRule.pinInfo["switch"].value.data = false;
            switchRule.evaluate();
            targetRule.advanceDelta();
            Assert.IsInstanceOfType(switchRule.pinInfo["output"].value.data, typeof(INumber));
            Assert.AreEqual(switchRule.pinInfo["output"].value.data, new GenericNumber<short>(255));
            switchRule.pinInfo["switch"].value.data = true;
            switchRule.evaluate();
            targetRule.advanceDelta();
            Assert.IsInstanceOfType(switchRule.pinInfo["output"].value.data, typeof(bool));
            Assert.AreEqual(switchRule.pinInfo["output"].value.data, true);
            //bool and tristate
            switchRule.pinInfo["inputFalse"].valueType = typeof(pinDataTristate);
            switchRule.pinInfo["inputFalse"].recreateValue();
            switchRule.pinInfo["inputFalse"].value.data = tristate.yes;
            switchRule.pinInfo["switch"].value.data = false;
            switchRule.evaluate();
            targetRule.advanceDelta();
            Assert.IsInstanceOfType(switchRule.pinInfo["output"].value.data, typeof(tristate));
            Assert.AreEqual(switchRule.pinInfo["output"].value.data, tristate.yes);
            targetRule.stop();
        }
コード例 #7
0
ファイル: ruleItemTests.cs プロジェクト: randomdude/Lavalamp
        public void testStartRunRuleItemSplitter()
        {
            rule targetRule = new rule();
            ruleItemBase spliter = targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_splitter)));
            targetRule.start();

            spliter.pinInfo["input1"].value.data = false;
            spliter.evaluate();
            targetRule.advanceDelta();

            Assert.AreEqual(false, spliter.pinInfo["output1"].value.data);
            Assert.AreEqual(false, spliter.pinInfo["output2"].value.data);

            spliter.pinInfo["input1"].value.data = true;
            spliter.evaluate();
            targetRule.advanceDelta();

            Assert.AreEqual(true, spliter.pinInfo["output1"].value.data);
            Assert.AreEqual(true, spliter.pinInfo["output2"].value.data);

            spliter.pinInfo["input1"].valueType = typeof(pinDataString);
            spliter.pinInfo["input1"].recreateValue();
            spliter.pinInfo["input1"].value.data = "lol";
            spliter.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual("lol", spliter.pinInfo["output1"].value.data);
            Assert.AreEqual("lol", spliter.pinInfo["output2"].value.data);

            spliter.pinInfo["input1"].valueType = typeof(pinDataTristate);
            spliter.pinInfo["input1"].recreateValue();
            spliter.pinInfo["input1"].value.data = tristate.yes;
            spliter.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual(tristate.yes, spliter.pinInfo["output1"].value.data);
            Assert.AreEqual(tristate.yes, spliter.pinInfo["output2"].value.data);
        }
コード例 #8
0
ファイル: ruleItemTests.cs プロジェクト: randomdude/Lavalamp
        public void testStartRunRuleItemOr()
        {
            rule targetRule = new rule();
            ruleItemBase orGate = targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_or)));
            targetRule.start();

            orGate.pinInfo["input1"].value.data = false;
            orGate.pinInfo["input2"].value.data = false;
            orGate.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual(false, orGate.pinInfo["output1"].value.asBoolean());

            orGate.pinInfo["input1"].value.data = true;
            orGate.pinInfo["input2"].value.data = false;
            orGate.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual(true, orGate.pinInfo["output1"].value.asBoolean());

            orGate.pinInfo["input1"].value.data = false;
            orGate.pinInfo["input2"].value.data = true;
            orGate.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual(true, orGate.pinInfo["output1"].value.asBoolean());

            orGate.pinInfo["input1"].value.data = true;
            orGate.pinInfo["input2"].value.data = true;
            orGate.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual(true, orGate.pinInfo["output1"].value.asBoolean());
        }
コード例 #9
0
ファイル: ruleItemTests.cs プロジェクト: randomdude/Lavalamp
        public void testStartRunRuleItemNot()
        {
            rule targetRule = new rule();
            ruleItemBase debugItem = targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_not)));

            targetRule.start();
            debugItem.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual(tristate.noValue, debugItem.pinInfo["output1"].value.data);

            debugItem.pinInfo["input1"].value.data = false;
            debugItem.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual(tristate.yes, debugItem.pinInfo["output1"].value.data);

            debugItem.pinInfo["input1"].value.data = true;
            debugItem.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual(tristate.no, debugItem.pinInfo["output1"].value.data);
        }
コード例 #10
0
ファイル: ruleItemTests.cs プロジェクト: randomdude/Lavalamp
        public void testStartRunRuleItemAnd()
        {
            rule targetRule = new rule();

            ruleItemBase andGate = targetRule.addRuleItem(new ruleItemInfo(typeof(ruleItem_and)));
            targetRule.start();
            andGate.pinInfo["input1"].value.data = false;
            andGate.pinInfo["input2"].value.data = false;
            andGate.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual(false, andGate.pinInfo["output1"].value.data);

            andGate.pinInfo["input1"].value.data = true;
            andGate.pinInfo["input2"].value.data = false;
            andGate.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual(false, andGate.pinInfo["output1"].value.data);

            andGate.pinInfo["input1"].value.data = false;
            andGate.pinInfo["input2"].value.data = true;
            andGate.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual(false, andGate.pinInfo["output1"].value.data);

            andGate.pinInfo["input1"].value.data = true;
            andGate.pinInfo["input2"].value.data = true;
            andGate.evaluate();
            targetRule.advanceDelta();
            Assert.AreEqual(true, andGate.pinInfo["output1"].value.data);
        }
コード例 #11
0
        public void testSerialisationOfRuleWithTwoRuleItemWithPinsConnected()
        {
            rule rule = new rule("test");
            lineChain line = new lineChain();

            ruleItemInfo myInfo = new ruleItemInfo();
            myInfo.itemType = ruleItemType.RuleItem;
            myInfo.ruleItemBaseType = typeof(ruleItem_and);
            ruleItemBase andItem = rule.addRuleItem(myInfo);
            ruleItemGuid andGuid = andItem.serial;

            ruleItemInfo myInfo2 = new ruleItemInfo();
            myInfo2.itemType = ruleItemType.RuleItem;
            myInfo2.ruleItemBaseType = typeof(ruleItem_desktopMessage);
            ruleItemBase messageItem = rule.addRuleItem(myInfo2);
            ruleItemGuid messageGuid = messageItem.serial;

            messageItem.pinInfo["trigger"].parentRuleItem = messageGuid;
            messageItem.pinInfo["trigger"].connectTo(line.serial,andItem.pinInfo["output1"]);
            andItem.pinInfo["output1"].connectTo(line.serial, messageItem.pinInfo["trigger"]);
            andItem.pinInfo["output1"].parentRuleItem = andGuid;
            rule.AddLineChainToGlobalPool(line);

            String serialised = rule.serialise();

            rule = rule.deserialise(serialised);

            Assert.AreEqual("test", rule.name);
            Assert.AreEqual(1, rule.lineChainCount);
            Assert.AreEqual(2, rule.ruleItems.Count);
            andItem = rule.ruleItems[andGuid.id.ToString()];
            messageItem = rule.ruleItems[messageGuid.id.ToString()];
            Assert.IsInstanceOfType(andItem, typeof(ruleItem_and));
            Assert.IsInstanceOfType(messageItem, typeof(ruleItem_desktopMessage));
            Assert.AreEqual(1, messageItem.pinInfo.Count);
            Assert.AreEqual(3, andItem.pinInfo.Count);
            Assert.AreEqual(line.serial.id.ToString(), messageItem.pinInfo["trigger"].parentLineChain.id.ToString());
            Assert.AreEqual(line.serial.id.ToString(), andItem.pinInfo["output1"].parentLineChain.id.ToString());
            Assert.AreEqual(andItem.pinInfo["output1"].serial.id.ToString(), messageItem.pinInfo["trigger"].linkedTo.id.ToString());
            Assert.AreEqual(messageItem.pinInfo["trigger"].serial.id.ToString(), andItem.pinInfo["output1"].linkedTo.id.ToString());
            Assert.AreEqual(typeof(pinDataBool), andItem.pinInfo["output1"].valueType);
            Assert.AreEqual(typeof(pinDataBool), messageItem.pinInfo["trigger"].valueType) ;
        }