Beispiel #1
0
        public void PassFailContext(string PassIn, string FailIn, out string onPass, out string onFail)
        {
            // Set up a typical instruction tree.
            TestState ts   = TestState.getOnly("LT");
            NoOp      op1  = new NoOp();
            NoOp      op2  = new NoOp();
            NoOp      op3  = new NoOp();
            Desktop   Desk = new Desktop();

            Desk.Add(op1);
            op1.Parent = Desk;
            Desk.Add(op2);
            op2.Parent = Desk;
            Desk.Add(op3);
            op3.Parent = Desk;
            ApplicationContext ac = MakeAppContext();

            ts.AddNamedInstruction("Find me", ac);
            ApplicationContext AppCon = new ApplicationContext();

            AppCon.SetSource("Find me");
            Assert.AreEqual(ac, (ApplicationContext)AppCon.TestGetOfSource(), "Context source not set right");
            Desk.Add(AppCon);
            NoOp ins1 = new NoOp();
            NoOp ins2 = new NoOp();
            NoOp ins3 = new NoOp();

            AppCon.Add(ins1);
            ins1.Parent = AppCon;
            AppCon.Add(ins2);
            ins2.Parent = AppCon;
            AppCon.Add(ins3);
            ins3.Parent = AppCon;
            ins2.PassFailInContext(PassIn, FailIn, out onPass, out onFail);
        }
Beispiel #2
0
 /// <summary>
 /// Constructor that uses a parent instruction instead if the id is null.
 /// </summary>
 /// <param name="id">Instruction name or id, can be null</param>
 /// <param name="parent">Parent instruction of this DataRef</param>
 public DataRef(string id, Instruction parent)
 {
     m_ts = TestState.getOnly();
     //Assert.IsNotNull(id,"Null id passed for constructing a DataRef");
     //Assert.IsFalse(id == "","Empty id passed for constructing a DataRef");
     Assert.IsNotNull(m_ts,"Null TestState passed for constructing a DataRef");
     Assert.IsNotNull(parent,"Non-null parent instruction expected for constructing a DataRef");
     // the id can be $id.data or $id or $.data or $ (parent default data)
     // these may occur with suffix ';' or space
     // replace all '$.' with '$genid.data'
     if (id == null || id.Equals("")) id = "$";
     m_id = id;
     int dol = m_id.IndexOf('$');
     if (dol >= 0)
     { // there are data references
         string genId = "Internal#Data#Ref"+sm_next_id.ToString();
         string dgenId = "$"+genId;
         sm_next_id += 1;
         m_id = m_id.Replace("$.",dgenId+".");
         m_id = m_id.Replace("$;",dgenId+";");
         m_id = m_id.Replace("$ ",dgenId+" ");
         if (m_id == "$") m_id = dgenId;
         if (m_id[m_id.Length-1] == '$') // last char
             m_id = m_id.Substring(0,m_id.Length-1) + dgenId;
         // if dgenId was substituted, add the parent to the ts list
         if (-1 < m_id.IndexOf(dgenId))
             m_ts.AddNamedInstruction(genId,parent);
     }
     else Assert.IsNotNull(id,"A DataRef has no ref prefixed with '$'. Read: "+id);
 }
Beispiel #3
0
        public Instruction AddNamedInstruction(string name)
        {
            NoOp ins = new NoOp();

            Assert.IsNotNull(ins, "Instruction " + name + " not created.");
            m_ts.AddNamedInstruction(name, ins);
            return(ins);
        }
Beispiel #4
0
        public void evalFunction()
        {
            TestState ts = TestState.getOnly("LT");

            ts.Script = "UtilitiesTest.xml";
            SelectText ins1 = new SelectText();

            ts.AddNamedInstruction("one", ins1);
            ins1.Path = "window:cleaner/item:dust";
            // note: ins1 has no default data set (ie. $one.text = null)
            Var ins2 = new Var();

            ts.AddNamedInstruction("_two", ins2);
            ins2.Set = " how's this??";
            Var ins3 = new Var();

            ts.AddNamedInstruction("thr-ee", ins3);
            ins3.Set = "And $_two; this should be ignored?";

            ins2.Execute();
            ins3.Execute();

            string result = Utilities.evalExpr("$random()");

            Assert.IsTrue(result == "0" || result == "1", "default random not 0 or 1");
            result = Utilities.evalExpr("$random(,)");
            Assert.IsTrue(result == "$random(,)", "random can't just have a comma for an argument");
            result = Utilities.evalExpr("$random(,4)");
            Assert.IsTrue(result == "$random(,4)", "random has to have a max argument");
            result = Utilities.evalExpr("$random(4,)");
            Assert.IsTrue(result == "$random(4,)", "random has to have a min argument when there's a comma");
            result = Utilities.evalExpr("$random(45,50)");
            Assert.IsTrue(result == "$random(45,50)", "min has to be less than max");
            result = Utilities.evalExpr("$random(50,45)");
            Assert.IsTrue(result == "45" || result == "46" || result == "47" ||
                          result == "48" || result == "49" || result == "50",
                          "Random must be between 45 and 50");
            result = Utilities.evalExpr("$random(-6,-10)");
            Assert.IsTrue(result == "-6" || result == "-7" || result == "-8" ||
                          result == "-9" || result == "-10",
                          "Random must be between -10 and -6");
            result = Utilities.evalExpr("$random(3,-2)");
            Assert.IsTrue(result == "-2" || result == "-1" || result == "0" ||
                          result == "1" || result == "2" || result == "3",
                          "Random must be between -2 and 3");
        }
Beispiel #5
0
        public void CreateAppContextFromSource()
        {
            TestState          ts = TestState.getOnly("LT");
            ApplicationContext ac = MakeAppContext();

            ts.AddNamedInstruction("Find me", ac);
            ApplicationContext ac2 = new ApplicationContext();

            ac2.SetSource("Find me");
            Assert.AreEqual(ac, (ApplicationContext)ac2.TestGetOfSource(), "Context source not set right");
        }
Beispiel #6
0
        public void ParseVarTest()
        {
            TestState ts = TestState.getOnly("LT");

            ts.Script = "UtilitiesTest.xml";
            Var ins2 = new Var();

            ts.AddNamedInstruction("one", ins2);
            ins2.Set = "4";
            ins2.Execute();
            Assert.IsTrue(GuiPath.parseIndexTesting("stuff[$hi]", "stuff[$hi]", 0, null));
            Assert.IsTrue(GuiPath.parseIndexTesting("stuff[$one]", "stuff", 4, null));
            Assert.IsTrue(GuiPath.parseIndexTesting("stuff3[$one;3]", "stuff3", 43, null));
            Assert.IsTrue(GuiPath.parseIndexTesting("stuff[3$one]", "stuff[3$one]", 0, null));
        }
Beispiel #7
0
        public void DataRefDefaulted()
        {
            TestState ts = TestState.getOnly("LT");

            ts.Script = "MessageTest.xml";
            NoOp nop1 = new NoOp();

            nop1.Data = 123;
            ts.AddNamedInstruction("niceId", nop1);
            NoOp nop2 = new NoOp();

            nop2.Data = 456;
            ts.AddNamedInstruction("greatId", nop2);
            Message message = new Message();

            message.AddText("Let's count, '");
            message.AddDataRef("$niceId", nop1);
            message.AddText("' and '");
            message.AddDataRef("$greatId.data", nop2);
            message.AddText("' to see it work!");
            string result = message.Read();

            Assert.AreEqual("Let's count, '123' and '456' to see it work!", result, "Message not relayed intact!");
        }
Beispiel #8
0
        /// <summary>
        /// Constructor that uses a parent instruction instead if the id is null.
        /// </summary>
        /// <param name="id">Instruction name or id, can be null</param>
        /// <param name="parent">Parent instruction of this DataRef</param>
        public DataRef(string id, Instruction parent)
        {
            m_ts = TestState.getOnly();
            //Assert.IsNotNull(id,"Null id passed for constructing a DataRef");
            //Assert.IsFalse(id == "","Empty id passed for constructing a DataRef");
            Assert.IsNotNull(m_ts, "Null TestState passed for constructing a DataRef");
            Assert.IsNotNull(parent, "Non-null parent instruction expected for constructing a DataRef");
            // the id can be $id.data or $id or $.data or $ (parent default data)
            // these may occur with suffix ';' or space
            // replace all '$.' with '$genid.data'
            if (id == null || id.Equals(""))
            {
                id = "$";
            }
            m_id = id;
            int dol = m_id.IndexOf('$');

            if (dol >= 0)
            {             // there are data references
                string genId  = "Internal#Data#Ref" + sm_next_id.ToString();
                string dgenId = "$" + genId;
                sm_next_id += 1;
                m_id        = m_id.Replace("$.", dgenId + ".");
                m_id        = m_id.Replace("$;", dgenId + ";");
                m_id        = m_id.Replace("$ ", dgenId + " ");
                if (m_id == "$")
                {
                    m_id = dgenId;
                }
                if (m_id[m_id.Length - 1] == '$')               // last char
                {
                    m_id = m_id.Substring(0, m_id.Length - 1) + dgenId;
                }
                // if dgenId was substituted, add the parent to the ts list
                if (-1 < m_id.IndexOf(dgenId))
                {
                    m_ts.AddNamedInstruction(genId, parent);
                }
            }
            else
            {
                Assert.IsNotNull(id, "A DataRef has no ref prefixed with '$'. Read: " + id);
            }
        }
Beispiel #9
0
        /// <summary>
        /// Execute method.
        /// If not already bound, this variable will be assigned a vaule.
        /// The variable may be bound when it is "built" or "interpreted".
        /// If bound when built, the variable may only reference preceding
        /// instruction settings (not results) and other built-bound vars.
        ///
        /// When there is reg, env or set data, it replaces the old data.
        /// When there is add data, it is added if old and add are numbers,
        /// or it is appended to the old data.
        /// When there is set and add data, set replaces the old data and
        /// add is added or appended.
        /// @env and @reg get values from the environment and the registry.
        /// The order of concatenation is @reg, @env, @set then @add.
        /// </summary>
        public override void Execute()
        {                                 // Bind the variable to a value if not already bound
            if (!m_bound)
            {                             // not already bound.
                m_log = Logger.getOnly(); // the log set in Instruction creation may be in another TestState
                TestState   ts  = TestState.getOnly();
                Instruction ins = ts.Instruction(m_id);
                if (ins != null)
                {                 // already one with this name
                    m_val = ins.GetDataImage(null);
                    m_log.paragraph("Found var " + m_id + " with value=" + m_val);
                    // remove the old ins from ts
                    ts.RemoveInstruction(m_id);
                    if (m_reg != null || m_env != null || m_set != null)
                    {
                        m_val = null;                         // don't use previous value
                    }
                }
                if (m_reg != null)
                {
                    string      value = null;
                    string      key;
                    RegistryKey regkey = Utilities.parseRegKey(m_reg, out key);
                    if (regkey != null)
                    {
                        RegistryValueKind rvk = regkey.GetValueKind(key);
                        switch (rvk)
                        {
                        case RegistryValueKind.Binary:
                            m_log.paragraph("Reg key is Binary");
                            value = Convert.ToString(regkey.GetValue(key));
                            break;

                        case RegistryValueKind.DWord:
                            m_log.paragraph("Reg key is DWord");
                            value = Convert.ToString(regkey.GetValue(key));
                            break;

                        case RegistryValueKind.ExpandString:
                            m_log.paragraph("Reg key is ExpandString");
                            value = Convert.ToString(regkey.GetValue(key));
                            break;

                        case RegistryValueKind.MultiString:
                            m_log.paragraph("Reg key is MultiString");
                            value = Convert.ToString(regkey.GetValue(key));
                            break;

                        case RegistryValueKind.QWord:
                            m_log.paragraph("Reg key is QWord");
                            value = Convert.ToString(regkey.GetValue(key));
                            break;

                        case RegistryValueKind.String:
                            value = (string)regkey.GetValue(key);
                            break;

                        case RegistryValueKind.Unknown:
                            m_log.paragraph("Reg key is Unknown");
                            break;
                        }
                        regkey.Close();
                    }
                    else
                    {
                        m_log.paragraph("Invalid Reisitry path: " + m_reg);
                    }
                    if (value != null)
                    {
                        m_val += value;
                    }
                }
                if (m_env != null)
                {                 // try the process then the user then the machine environment variables.
                    string value = Environment.GetEnvironmentVariable(m_env, EnvironmentVariableTarget.Process);
                    if (value == null)
                    {
                        value = Environment.GetEnvironmentVariable(m_env, EnvironmentVariableTarget.User);
                    }
                    if (value == null)
                    {
                        value = Environment.GetEnvironmentVariable(m_env, EnvironmentVariableTarget.Machine);
                    }
                    if (value != null)
                    {
                        m_val += value;
                    }
                }
                if (m_set != null)
                {
                    m_val += Utilities.evalExpr(m_set);
                }
                if (m_add != null)
                {                 // add the old and new
                    string newVal = Utilities.evalExpr(m_add);
                    if (Utilities.IsNumber(newVal) && Utilities.IsNumber(m_val))
                    {
                        try
                        {
                            double old = double.Parse(m_val);
                            double add = double.Parse(newVal);
                            double sum = old + add;
                            m_log.paragraph("Variable(" + m_id + ") = " + old + " + " + add + " = " + sum);
                            m_val = System.Convert.ToString(sum);
                        }
                        catch
                        {
                            fail("Variable(" + m_id + ") = " + m_val + " + " + m_add + " does not compute!");
                        }
                    }
                    else
                    {
                        m_log.paragraph("Text add: Variable(" + m_id + ") = " + m_val + " + " + newVal);
                        m_val += newVal;                         // append as strings
                    }
                }
                else
                // even if there was a previous var, but m_add was null,
                // then m_val is null if nothing was m_set!
                if (m_set == null)
                {
                    m_val = null;
                }
                if (m_file_exists != null && m_val != null)
                {                 // append the file name to the reg and/or env value.
                    if (File.Exists(m_val))
                    {
                        m_val = m_file_exists;
                    }
                    else
                    {
                        m_val = "#not-exists#";
                    }
                }
                ts.AddNamedInstruction(m_id, this);
            }
            m_bound = true;
            base.Execute();
            Finished = true;             // tell do-once it's done
        }
Beispiel #10
0
        public void evalExpr()
        {
            TestState ts = TestState.getOnly("LT");

            ts.Script = "UtilitiesTest.xml";
            SelectText ins1 = new SelectText();

            ts.AddNamedInstruction("one", ins1);
            ins1.Path = "window:cleaner/item:dust";
            // note: ins1 has no default data set (ie. $one.text = null)
            Var ins2 = new Var();

            ts.AddNamedInstruction("_two", ins2);
            ins2.Set = " how's this??";
            Var ins3 = new Var();

            ts.AddNamedInstruction("thr-ee", ins3);
            ins3.Set = "And $_two; this should be ignored?";

            ins2.Execute();
            ins3.Execute();

            string result = Utilities.evalExpr("$one");

            Assert.AreEqual(null, result);
            result = Utilities.evalExpr("$one;");
            Assert.AreEqual(null, result);
            result = Utilities.evalExpr("$one ");
            Assert.AreEqual(" ", result);
            result = Utilities.evalExpr(" $one");
            Assert.AreEqual(" ", result);
            result = Utilities.evalExpr("$one; ");
            Assert.AreEqual(" ", result);
            result = Utilities.evalExpr(";$one; ");
            Assert.AreEqual("; ", result);
            result = Utilities.evalExpr(";$one;;");
            Assert.AreEqual(";;", result);
            result = Utilities.evalExpr("$one1");
            Assert.AreEqual("$one1", result);
            result = Utilities.evalExpr("$on;e");
            Assert.AreEqual("$on;e", result);

            result = Utilities.evalExpr("$_two");
            Assert.AreEqual(" how's this??", result);
            result = Utilities.evalExpr("$_two;");
            Assert.AreEqual(" how's this??", result);
            result = Utilities.evalExpr("$_two ");
            Assert.AreEqual(" how's this?? ", result);
            result = Utilities.evalExpr(" $_two");
            Assert.AreEqual("  how's this??", result);
            result = Utilities.evalExpr("$_two; ");
            Assert.AreEqual(" how's this?? ", result);
            result = Utilities.evalExpr(";$_two; ");
            Assert.AreEqual("; how's this?? ", result);
            result = Utilities.evalExpr(";$_two;;");
            Assert.AreEqual("; how's this??;", result);
            result = Utilities.evalExpr("$_two1");
            Assert.AreEqual("$_two1", result);
            result = Utilities.evalExpr("$_tw;o");
            Assert.AreEqual("$_tw;o", result);

            result = Utilities.evalExpr("$one.;");
            Assert.AreEqual(null, result);
            result = Utilities.evalExpr("$one..;");
            Assert.AreEqual("[select-text-1 does not have data for '.']", result);
            result = Utilities.evalExpr("$one.path");
            Assert.AreEqual("window:cleaner/item:dust", result);
            result = Utilities.evalExpr("$one.path;");
            Assert.AreEqual("window:cleaner/item:dust", result);
            result = Utilities.evalExpr("$one.path.;");
            Assert.AreEqual("[select-text-1 does not have data for 'path.']", result);

            result = Utilities.evalExpr("text$one;$_two;$thr-ee");
            Assert.AreEqual("text how's this??And  how's this?? this should be ignored?", result);
            result = Utilities.evalExpr("text$one;$_two;$thr-ee");
            Assert.AreEqual("text how's this??And  how's this?? this should be ignored?", result);
            result = Utilities.evalExpr("text$one.path;$_two;$thr-ee OK");
            Assert.AreEqual("textwindow:cleaner/item:dust how's this??And  how's this?? this should be ignored? OK", result);
            result = Utilities.evalExpr("text $_two $one.path OK");
            Assert.AreEqual("text  how's this?? window:cleaner/item:dust OK", result);
        }