Esempio n. 1
0
 /// <summary>
 /// Called to finish construction when an instruction has been instantiated by
 /// a factory and had its properties set.
 /// This can check the integrity of the instruction or perform other initialization tasks.
 /// </summary>
 /// <param name="xn">XML node describing the instruction</param>
 /// <param name="con">Parent xml node instruction</param>
 /// <returns></returns>
 public override bool finishCreation(XmlNode xn, Context con)
 {
     // finish factory construction
     m_log.isNotNull(Path, makeNameTag() + "Hover-over instruction must have a path.");
     m_log.isTrue(Path != "", makeNameTag() + "Hover-over instruction must have a non-empty path.");
     return true;
 }
Esempio n. 2
0
		public override void Execute()
		{
			base.Execute();
			Context con = (Context)Ancestor(typeof(Context));
			isNotNull(con, makeNameTag() + " must occur in some context");
			m_Result = Condition.EvaluateList(m_conditions);
			if (m_Result == true)
			{
				XmlNode xThen = m_elt.SelectSingleNode("then");
				if (xThen != null)
				{ // then may have been created via do-once before this
					if (m_then == null)
					{ // not created yet
						Context thenCon = new Context();
						thenCon.ModelNode = con.ModelNode;
						thenCon.Parent = this;
						string rest = XmlFiler.getAttribute(xThen, "wait");
						if (rest != null) thenCon.Rest = Convert.ToInt32(rest);
						foreach (XmlNode child in xThen.ChildNodes)
						{ // MakeShell adds the ins to thenCon
							XmlInstructionBuilder.MakeShell(child, thenCon);
						}
						SetThen(thenCon);
					}
					m_then.Execute();
				}
			}
			else
			{
				XmlNode xElse = m_elt.SelectSingleNode("else");
				if (xElse != null)
				{ // else may have been created via do-once before this
					if (m_else == null)
					{ // not created yet
						Context elseCon = new Context();
						elseCon.ModelNode = con.ModelNode;
						elseCon.Parent = this;
						string rest = XmlFiler.getAttribute(xElse, "wait");
						if (rest != null) elseCon.Rest = Convert.ToInt32(rest);
						foreach (XmlNode child in xElse.ChildNodes)
						{ // MakeShell adds the ins to elseCon
							XmlInstructionBuilder.MakeShell(child, elseCon);
						}
						SetElse(elseCon);
					}
					m_else.Execute();
				}
			}
			Logger.getOnly().result(this);
			Finished = true; // tell do-once it's done
		}
 /// <summary>
 /// Creates a variable to be referenced by other instruction attributes.
 /// </summary>
 /// <param name="xn">The XML repersentation of the instruction to be checked</param>
 /// <param name="con">The current context object</param>
 public static Var CreateVar(XmlNode xn, Context con)
 {
     Var var  = new Var();
     var.Id   = XmlFiler.getAttribute(xn, "id");
     Logger.getOnly().isNotNull(var.Id, "Var instruction must have a id.");
     Logger.getOnly().isTrue(var.Id != "", "Var instruction must have a non-empty id.");
     string s = XmlFiler.getAttribute(xn, "set");
     // select should be move to var.execute so it is dynamic!
     string select = XmlFiler.getAttribute(xn, "select");
     if (select != null && select != "")
     { // the variable can only have one text node or one other node assigned to it.
         XmlNodeList pathNodes = selectNodes(con, select, "var"+var.Id);
         Logger.getOnly().isNotNull(pathNodes, "var " + var.Id + " select='" + select + "' returned no result");
         if (pathNodes.Count > 0)
         { // append first node to set string
             XmlNode modNode = pathNodes.Item(0);
             // which property of the node to get?
             string prop = null;
             string propName = XmlFiler.getAttribute(xn, "prop");
             if (propName == null && modNode is XmlElement) propName = "path";
             if (propName == null) propName = "value";
             if (propName != null && propName == "value") prop = XmlPath.ResolveModelPath(modNode, modNode.Value);
             if (propName != null && propName == "name") prop = modNode.Name;
             if (propName != null && propName == "type") prop = modNode.NodeType.ToString();
             if (propName != null && propName == "path")
             {
                 XmlPath xp = new XmlPath(modNode);
                 if (xp.isValid()) prop = xp.Path;
                 else prop = null;
             }
             s += prop;
         }
         else s += "#NoSelection#";
     }
     var.Set = s;
     string when = XmlFiler.getAttribute(xn, "when");
     string add = XmlFiler.getAttribute(xn, "add");
     if (add != null) var.Add = add;
     if (var.Set == null && when == null)
     { // if there is a select/when then don't complain if the select found nothing
         Logger.getOnly().isNotNull(var.Add, "Var " + var.Id +
             @" set, select or add must result in a string or number value unless when=""exists"" is set.");
         if (select != null && select != "") var.Set = @"#not-"+when+@"#";
     }
     string exists = XmlFiler.getAttribute(xn, "file-exists");
     if (exists != null) var.FileExists = exists;
     string rest = XmlFiler.getAttribute(xn, "wait");
     if (rest != null) var.Rest = Convert.ToInt32(rest);
     AddInstruction(xn, var, con);
     return var;
 }
Esempio n. 4
0
        /// <summary>
        /// Called to finish construction when an instruction has been instantiated by
        /// a factory and had its properties set.
        /// This can check the integrity of the instruction or perform other initialization tasks.
        /// </summary>
        /// <param name="xn">XML node describing the instruction</param>
        /// <param name="con">Parent xml node instruction</param>
        /// <returns></returns>
        public override bool finishCreation(XmlNode xn, Context con)
        {
            // finish factory construction
            Logger.getOnly().isNotNull(m_pathName, @"include must have a 'from' path.");
            Logger.getOnly().isTrue(m_pathName != "", @"include must have a 'from' path.");

            string pathname = TestState.getOnly().getScriptPath() + @"\" + m_pathName;
            XmlDocument doc = new XmlDocument();
            doc.PreserveWhitespace = true; // allows <insert> </insert>
            try { doc.Load(pathname); }
            catch (System.IO.FileNotFoundException ioe)
            {
                Logger.getOnly().fail(@"include '" + pathname + "' not found: " + ioe.Message);
            }
            catch (System.Xml.XmlException xme)
            {
                Logger.getOnly().fail(@"include '" + pathname + "' not loadable: " + xme.Message);
            }
            XmlNode include = doc["include"];
            Logger.getOnly().isNotNull(include, "Missing document element 'include'.");
            XmlElement conEl = con.Element;
            // clone insert and add it before so there's an insert before and after
            // after adding elements, delete the "after" one
            XmlDocumentFragment df = xn.OwnerDocument.CreateDocumentFragment();
            df.InnerXml = xn.OuterXml;
            conEl.InsertBefore(df, xn);
            foreach (XmlNode xnode in include.ChildNodes)
            {
                string image = xnode.OuterXml;
                if (image.StartsWith("<"))
                {
                    XmlDocumentFragment dfrag = xn.OwnerDocument.CreateDocumentFragment();
                    dfrag.InnerXml = xnode.OuterXml;
                    conEl.InsertBefore(dfrag, xn);
                }
            }
            conEl.RemoveChild(xn);
            //Logger.getOnly().paragraph(Utilities.attrText(textImage));
            return true;
        }
Esempio n. 5
0
 /// <summary>
 /// Called to finish construction when an instruction has been instantiated by
 /// a factory and had its properties set.
 /// This can check the integrity of the instruction or perform other initialization tasks.
 /// </summary>
 /// <param name="xn">XML node describing the instruction</param>
 /// <param name="con">Parent xml node instruction</param>
 /// <returns></returns>
 public override bool finishCreation(XmlNode xn, Context con)
 {
     // finish factory construction
     m_log.isNotNull(Id, makeNameTag() + " instruction must have a id.");
     m_log.isTrue(Id != "", makeNameTag() + " instruction must have a non-empty id.");
     if (m_select != null && m_select != "")
     { // the variable can only have one text node or one other node assigned to it.
         m_log.isNotNull(con, "makeNameTag() + select has no context.");
         XmlNodeList pathNodes = Instructionator.selectNodes(con, m_select, "var" + Id);
         m_log.isNotNull(pathNodes, makeNameTag() + "var " + Id + " select='" + m_select + "' returned no result");
         if (pathNodes.Count > 0)
         { // append first node to set string
             XmlNode modNode = pathNodes.Item(0);
             string prop = null;
             // which property of the node to get?
             if (m_prop == null && modNode is XmlElement) m_prop = "path";
             if (m_prop == null) m_prop = "value";
             if (m_prop != null && m_prop == "value") prop = XmlPath.ResolveModelPath(modNode, modNode.Value);
             if (m_prop != null && m_prop == "name") prop = modNode.Name;
             if (m_prop != null && m_prop == "type") prop = modNode.NodeType.ToString();
             if (m_prop != null && m_prop == "path")
             {
                 XmlPath xp = new XmlPath(modNode);
                 if (xp.isValid()) prop = xp.Path;
                 else prop = null;
             }
             m_set += prop;
         }
         else m_set += "#NoSelection#";
     }
     if (Set == null && m_when == null)
     { // if there is a select/when then don't complain if the select found nothing
         m_log.isNotNull(Add, makeNameTag() + Id +
             @" set, select or add must result in a string or number value unless when=""exists"" is set.");
         if (m_select != null && m_select != "") Set = @"#not-" + m_when + @"#";
     }
     return true;
 }
Esempio n. 6
0
		public void SetThen (Context thenCon)
		{
			isNotNull(thenCon,"A then clause is null");
			m_then = thenCon;
		}
Esempio n. 7
0
		/// <summary>
		/// Creates a match-strings instruction and parses its content.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static MatchStrings CreateMatchStrings(XmlNode xn, Context con)
		{
			MatchStrings ms = new MatchStrings();
			ms.Of = XmlFiler.getAttribute(xn, "of");
			Logger.getOnly().isNotNull(ms.Of, "Match-strings instruction must have an 'of'.");
			Logger.getOnly().isTrue(ms.Of != "", "Match-strings instruction must have a non-empty 'of'.");
			ms.To  = XmlFiler.getAttribute(xn, "to");
			Logger.getOnly().isNotNull(ms.To, "Match-strings instruction must have a 'to'.");
			Logger.getOnly().isTrue(ms.To != "", "Match-strings instruction must have a non-empty 'to'.");
			ms.Expect = XmlFiler.getAttribute(xn, "expect");
			ms.OnPass = XmlFiler.getAttribute(xn, "on-pass");
			ms.OnFail = XmlFiler.getAttribute(xn, "on-fail");
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null) ms.Rest = Convert.ToInt32(rest);
			InterpretMessage(ms,xn.ChildNodes);
			AddInstruction(xn, ms, con);
			return ms;
		}
Esempio n. 8
0
		/// <summary>
		/// Creates a sound instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static Sound CreateSound(XmlNode xn, Context con)
		{
			Sound sound = CreateSound(xn);
			AddInstruction(xn, sound, con);
			return sound;
		}
Esempio n. 9
0
		/// <summary>
		/// Creates a select-text instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static SelectText CreateSelectText(XmlNode xn, Context con)
		{
			SelectText sel = new SelectText();
			sel.Path = XmlFiler.getAttribute(xn, "path");
			Logger.getOnly().isNotNull(sel.Path, "Select-text instruction must have a path.");
			Logger.getOnly().isTrue(sel.Path != "", "Select-text instruction must have a non-empty path.");
			sel.Loc = XmlFiler.getAttribute(xn, "loc");
			string sAt = XmlFiler.getAttribute(xn, "at");
			if (sAt == null) sel.At = 0;
			else             sel.At = Convert.ToInt32(sAt);
			string sRun = XmlFiler.getAttribute(xn, "run");
			if (sRun == null) sel.Run = 0;
			else              sel.Run = Convert.ToInt32(sRun);
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null) sel.Rest = Convert.ToInt32(rest);
			AddInstruction(xn, sel, con);
			return sel;
		}
Esempio n. 10
0
		/// <summary>
		/// Creates a glimpse-extra instruction and parses its content.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static GlimpseExtra CreateGlimpseExtra(XmlNode xn, Context con)
		{
			GlimpseExtra glimpse = new GlimpseExtra();
			glimpse.Path = XmlFiler.getAttribute(xn, "path");
			glimpse.SelectPath = XmlFiler.getAttribute(xn, "select-path");
			glimpse.Names = XmlFiler.getAttribute(xn, "names");
			glimpse.Select = XmlFiler.getAttribute(xn, "select");
			glimpse.OnPass = XmlFiler.getAttribute(xn, "on-pass");
			glimpse.OnFail = XmlFiler.getAttribute(xn, "on-fail");
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null) glimpse.Rest = Convert.ToInt32(rest);
			InterpretMessage(glimpse,xn.ChildNodes);
			AddInstruction(xn, glimpse, con);
			return glimpse;
		}
Esempio n. 11
0
		/// <summary>
		/// Creates a time context instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static TimeContext CreateTime(XmlNode xn, Context con)
		{
			string expect = XmlFiler.getAttribute(xn, "expect");
			TimeContext timeIt = new TimeContext(Convert.ToInt32(expect));
			string desc = XmlFiler.getAttribute(xn, "desc");
			timeIt.Decsription = desc;
/*			foreach (XmlNode xnChild in xn.ChildNodes)
			{
				InterpretChild(xnChild, timeIt);
			}
*/
			timeIt.ModelNode = con.ModelNode;
			AddInstruction(xn, timeIt, con);
			return timeIt;
		}
Esempio n. 12
0
		/// <summary>
		/// Creates a doOnce context instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static DoOnceContext CreateDoOnceContext(XmlNode xn, Context con)
		{
			string maxWait = XmlFiler.getAttribute(xn, "until");
//			Assert.IsTrue(maxWait == null || maxWait.Length == 0, "Do-Once context must have an until attribute.");

			Logger.getOnly().isNotNull(maxWait, "Do-Once context must have an until attribute.");
			Logger.getOnly().isTrue(maxWait != "", "Do-Once context must have a non-empty 'until' attribute.");

			DoOnceContext doOnce = new DoOnceContext(Convert.ToInt32(maxWait));
			doOnce.WaitingFor = XmlFiler.getAttribute(xn, "waiting-for");
			doOnce.OnPass = XmlFiler.getAttribute(xn, "on-pass");
			doOnce.OnFail = XmlFiler.getAttribute(xn, "on-fail");
			doOnce.ModelNode = con.ModelNode;
			AddInstruction(xn, doOnce, con);
/*			foreach (XmlNode xnChild in xn.ChildNodes)
			{
				InterpretChild(xnChild, doOnce);
			}
*/
			return doOnce;
		}
Esempio n. 13
0
		/// <summary>
		/// Creates a startup context instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static StartUpContext CreateStartUpContext(XmlNode xn, Context con)
		{
			StartUpContext su = new StartUpContext();
			su.OnPass = XmlFiler.getAttribute(xn, "on-pass");
			su.OnFail = XmlFiler.getAttribute(xn, "on-fail");
			su.ModelNode = con.ModelNode;
			AddInstruction(xn, su, con);
/*			foreach (XmlNode xnChild in xn.ChildNodes)
			{
				InterpretChild(xnChild, su);
			}
*/
			return su;
		}
Esempio n. 14
0
		static Model CreateModelContext(XmlNode xn, Context con)
		{ // check select and path attributes
			Model model = new Model();
			model.Select = XmlFiler.getAttribute(xn, "select");
			Logger.getOnly().isTrue(model.Select != null, "Model instruction must have a select attribute.");
			Logger.getOnly().isTrue(model.Select != "", "Model instruction must have a non-empty select.");
			model.When = XmlFiler.getAttribute(xn, "when");
			model.OnPass = XmlFiler.getAttribute(xn, "on-pass");
			model.OnFail = XmlFiler.getAttribute(xn, "on-fail");
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null) model.Rest = Convert.ToInt32(rest);
			AddInstruction(xn, model, con);
			return model;
		}
Esempio n. 15
0
		/// <summary>
		/// Creates an application context instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static ApplicationContext CreateApplicationContext(XmlNode xn, Context con)
		{
			ApplicationContext ac = new ApplicationContext();
			ac.Run = XmlFiler.getAttribute(xn, "run");
			if (ac.Run == null || ac.Run == "") ac.Run = "ok";
			ac.Gui   = XmlFiler.getAttribute(xn, "gui");
			ac.Path  = XmlFiler.getAttribute(xn, "path");
			ac.Exe   = XmlFiler.getAttribute(xn, "exe");
			ac.Args  = XmlFiler.getAttribute(xn, "args");
			ac.Work  = XmlFiler.getAttribute(xn, "work");
			ac.Title = XmlFiler.getAttribute(xn, "title");
			string src = XmlFiler.getAttribute(xn, "source");
			if (src != null) ac.SetSource(src);
			ac.Close  = XmlFiler.getAttribute(xn, "close");
			ac.OnPass = XmlFiler.getAttribute(xn, "on-pass");
			ac.OnFail = XmlFiler.getAttribute(xn, "on-fail");
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null) ac.Rest = Convert.ToInt32(rest);
			ac.Configure(); // set model root for use by children
			ac.ModelNode = con.ModelNode;
			AddInstruction(xn, ac, con);
			return ac;
		}
Esempio n. 16
0
		/// <summary>
		/// Creates an insert instruction and parses its content.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static Insert CreateInsert(XmlNode xn, Context con)
		{
			Insert insert = new Insert();
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null) insert.Rest = Convert.ToInt32(rest);
			string pause = XmlFiler.getAttribute(xn, "pause");
			if (pause != null) insert.Pause = Convert.ToInt32(pause);
			foreach (XmlNode node in xn.ChildNodes)
			{
				switch (node.Name)
				{
					case "#text":
					case "#whitespace":
					case "#significant-whitespace": // a nameless text node
						insert.Text = node.Value;
						break;
					default:
						Logger.getOnly().fail("Insert instruction must have something to insert.");
						break;
				}
			}
			Logger.getOnly().isNotNull(insert.Text, "Insert instruction must have some content.");
			Logger.getOnly().isTrue(insert.Text != "", "Insert instruction must have non-empty content.");
			AddInstruction(xn, insert, con);
			return insert;
		}
Esempio n. 17
0
		/// <summary>
		/// Creates a desktop context instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be created</param>
		/// <param name="con">The current context object</param>
		static Desktop CreateDesktopContext(XmlNode xn, Context con)
		{
			Desktop dt = new Desktop();
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null) dt.Rest = Convert.ToInt32(rest);
			dt.OnPass = XmlFiler.getAttribute(xn, "on-pass");
			dt.OnFail = XmlFiler.getAttribute(xn, "on-fail");
			dt.ModelNode = con.ModelNode;
			AddInstruction(xn, dt, con);
/*			foreach (XmlNode xnChild in xn.ChildNodes)
			{
				InterpretChild(xnChild, dt);
			}
*/
			return dt;
		}
Esempio n. 18
0
		/// <summary>
		/// Creates an if instruction and parses its content.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="ts">The TestState containing the named instruction list</param>
		/// <param name="con">The current context object</param>
		static If CreateIf(XmlNode xn, Context con)
		{
			Logger.getOnly().isNotNull(xn["condition"], "If instruction must have a condition.");
			If ifIns = new If();
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null) ifIns.Rest = Convert.ToInt32(rest);
			AddInstruction(xn, ifIns, con);
			foreach (XmlNode elt in xn.ChildNodes)
			{
				switch (elt.Name)
				{
					case "condition":
						Condition cond = CreateCondition(elt);
						ifIns.AddCondition(cond);
						break;
				}
			}
			return ifIns;
		}
Esempio n. 19
0
		/// <summary>
		/// Creates a dialog context instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be created</param>
		/// <param name="con">The current context object</param>
		static DialogContext CreateDialogContext(XmlNode xn, Context con)
		{
			DialogContext dc = new DialogContext();
			dc.Name  = XmlFiler.getAttribute(xn, "name");
			dc.Title = XmlFiler.getAttribute(xn, "title");
			dc.Select = XmlFiler.getAttribute(xn, "select");
			Logger.getOnly().isTrue(dc.Title != null || dc.Select != null, "Dialog context '" + dc.Name + "' has no Title or selected model.");
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null) dc.Rest = Convert.ToInt32(rest);
			string until = XmlFiler.getAttribute(xn, "until");
			if (until != null) dc.Until = Convert.ToInt32(until);
			dc.OnPass = XmlFiler.getAttribute(xn, "on-pass");
			dc.OnFail = XmlFiler.getAttribute(xn, "on-fail");
			dc.ModelNode = con.ModelNode;
			AddInstruction(xn, dc, con);
/*			foreach (XmlNode xnChild in xn.ChildNodes)
			{
				InterpretChild(xnChild, dc);
			}
*/
			return dc;
		}
Esempio n. 20
0
		/// <summary>
		/// Creates a registry instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static Registry CreateRegistry(XmlNode xn, Context con)
		{
			string key = XmlFiler.getAttribute(xn, "key");
			string data = XmlFiler.getAttribute(xn, "data");
			Logger.getOnly().isTrue(key != null && data != null, "Registry instruction must have a key and data.");
			Registry reg = new Registry(key, data);
			AddInstruction(xn, reg, con);
			return reg;
		}
Esempio n. 21
0
		/// <summary>
		/// Creates a beep instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be created</param>
		/// <param name="con">The current context object</param>
		static Beep CreateBeep(XmlNode xn, Context con)
		{
			Beep beep = CreateBeep(xn);
			AddInstruction(xn, beep, con);
			return beep;
		}
Esempio n. 22
0
		/// <summary>
		/// Creates a file-comp instruction and parses its content.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static FileComp CreateFileComp(XmlNode xn, Context con)
		{
			FileComp fc = new FileComp();
			fc.Of = XmlFiler.getAttribute(xn, "of");
			Logger.getOnly().isNotNull(fc.Of, "File-Comp instruction must have an 'of'.");
			Logger.getOnly().isTrue(fc.Of != "", "File-Comp instruction must have a non-empty 'of'.");
			fc.To  = XmlFiler.getAttribute(xn, "to");
			Logger.getOnly().isNotNull(fc.To, "File-Comp instruction must have a 'to'.");
			Logger.getOnly().isTrue(fc.To != "", "File-Comp instruction must have a non-empty 'to'.");
			fc.OnPass = XmlFiler.getAttribute(xn, "on-pass");
			fc.OnFail = XmlFiler.getAttribute(xn, "on-fail");
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null) fc.Rest = Convert.ToInt32(rest);
			InterpretMessage(fc,xn.ChildNodes);
			AddInstruction(xn, fc, con);
			return fc;
		}
Esempio n. 23
0
		/// <summary>
		/// Creates a garbage instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be created</param>
		/// <param name="con">The current context object</param>
		static Garbage CreateGarbage(XmlNode xn, Context con)
		{
			Garbage gc = CreateGarbage(xn);
			AddInstruction(xn, gc, con);
			return gc;
		}
Esempio n. 24
0
 /// <summary>
 /// Called to finish construction when an instruction has been instantiated by
 /// a factory and had its properties set.
 /// This can check the integrity of the instruction or perform other initialization tasks.
 /// </summary>
 /// <param name="xn">XML node describing the instruction</param>
 /// <param name="con">Parent xml node instruction</param>
 /// <returns></returns>
 public override bool finishCreation(XmlNode xn, Context con)
 {
     // finish factory construction
     m_log.isNotNull(Of, "Match-strings instruction must have an 'of'.");
     m_log.isTrue(Of != "", "Match-strings instruction must have a non-empty 'of'.");
     m_log.isNotNull(To, "Match-strings instruction must have a 'to'.");
     m_log.isTrue(To != "", "Match-strings instruction must have a non-empty 'to'.");
     InterpretMessage(xn.ChildNodes);
     return true;
 }
Esempio n. 25
0
		/// <summary>
		/// Creates a click instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be created</param>
		/// <param name="con">The current context object</param>
		static Click CreateClick(XmlNode xn, Context con)
		{ // check select and path attributes
			Click click = new Click();
			click.Select = XmlFiler.getAttribute(xn, "select");
			click.Path = XmlFiler.getAttribute(xn, "path");
			Logger.getOnly().isTrue(click.Path != null || click.Select != null, "Click instruction must have a path or select.");
			Logger.getOnly().isTrue(click.Path != "" || click.Select != "", "Click instruction must have a non-empty path or select.");
			click.When = XmlFiler.getAttribute(xn, "when");
			string until = XmlFiler.getAttribute(xn, "until");
			if (until != null) click.Until = Convert.ToInt32(until);
			string repeat = XmlFiler.getAttribute(xn, "repeat");
			if (repeat != null) click.Repeat = Convert.ToInt32(repeat);
			click.Side = XmlFiler.getAttribute(xn, "side");
			click.For = XmlFiler.getAttribute(xn, "for");
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null)
			{
				if (rest.ToLower().Equals("no")) click.Rest = -1;
				else click.Rest = Convert.ToInt32(rest);
			}
			string dx = XmlFiler.getAttribute(xn, "dx");
			if (dx != null) click.Dx = Convert.ToInt32(dx);
			string dy = XmlFiler.getAttribute(xn, "dy");
			if (dy != null) click.Dy = Convert.ToInt32(dy);
			AddInstruction(xn, click, con);
			return click;
		}
Esempio n. 26
0
		public void SetElse (Context elseCon)
		{
			isNotNull(elseCon,"An else clause is null");
			m_else = elseCon;
		}
Esempio n. 27
0
		/// <summary>
		/// Creates a hover-over instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static HoverOver CreateHoverOver(XmlNode xn, Context con)
		{
			HoverOver hover = new HoverOver();
			hover.Path = XmlFiler.getAttribute(xn, "path");
			Logger.getOnly().isNotNull(hover.Path, "Hover-over instruction must have a path.");
			Logger.getOnly().isTrue(hover.Path != "", "Hover-over instruction must have a non-empty path.");
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null) hover.Rest = Convert.ToInt32(rest);
			AddInstruction(xn, hover, con);
			return hover;
		}
Esempio n. 28
0
		/// <summary>
		/// Interpret a node as some kind of Instruction.
		/// Make the class but don't process its child instructions if any.
		/// Don't execute the instruction.
		/// Some instructions do not return objects:
		///   bug - a bug annotation element
		///	  #comment
		///	  #significant-whitespace
		///	  #whitespace
		/// The ones with '#' are generated by the XML parser.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		/// <returns>Returns an unexecuted instruction or null</returns>
		static public Instruction MakeShell(XmlNode xn, Context con)
		{
			// number the context if it doesn't have one yet to avoid depth-first numbering.
			if (con != null && con.Number == -1) con.Number = TestState.getOnly().IncInstructionCount;
			switch(xn.Name)
			{ // cases listed in ascending alphabetical order
				case "beep":
					return CreateBeep(xn, con);
				case "click":
					return CreateClick(xn, con);
				case "do-once":
					return CreateDoOnceContext(xn, con);
				case "file-comp":
					return CreateFileComp(xn, con);
				case "garbage":
					return CreateGarbage(xn, con);
				case "glimpse":
					return CreateGlimpse(xn, con);
				case "glimpse-extra":
					return CreateGlimpseExtra(xn, con);
				case "hover-over":
					return CreateHoverOver(xn, con);
				case "include":
					return CreateInclude(xn, con);
				case "insert":
					return CreateInsert(xn, con);
				case "if":
					return CreateIf(xn, con);
				case "match-strings":
					return CreateMatchStrings(xn, con);
				case "model":
					return CreateModelContext(xn, con);
				case "monitor-time":
					return CreateTime(xn, con);
				case "on-application":
					return CreateApplicationContext(xn, con);
				case "on-desktop":
					return CreateDesktopContext(xn, con);
				case "on-dialog":
					return CreateDialogContext(xn, con);
				case "on-startup":
					return CreateStartUpContext(xn, con);
				case "registry":
					return CreateRegistry(xn, con);
				case "skip":
					return new Skip();
				case "sound":
					return CreateSound(xn, con);
				case "select-text":
					return CreateSelectText(xn, con);
				case "var":
					return CreateVar(xn, con);
				case "bug": // bug annotation element
				case "#comment": // ignore comments, etc..
				case "#significant-whitespace":
				case "#whitespace":
					return null;
				default:
					Logger.getOnly().fail("Unexpected instruction <"+xn.Name+"> found");
					break;
			}
			return null;
		}
Esempio n. 29
0
		/// <summary>
		/// Creates a glimpse instruction and parses its content.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		static Glimpse CreateGlimpse(XmlNode xn, Context con)
		{
			Glimpse glimpse = new Glimpse();
			glimpse.Path   = XmlFiler.getAttribute(xn, "path");
			glimpse.Select = XmlFiler.getAttribute(xn, "select");
			Logger.getOnly().isTrue(glimpse.Path != null || glimpse.Select != null, "Glimpse instruction must have a path or select.");
			Logger.getOnly().isTrue(glimpse.Path != "" || glimpse.Select != "", "Glimpse instruction must have a non-empty path or select.");
			glimpse.Prop   = XmlFiler.getAttribute(xn, "prop");
			glimpse.Expect = XmlFiler.getAttribute(xn, "expect");
			glimpse.OnPass = XmlFiler.getAttribute(xn, "on-pass");
			glimpse.OnFail = XmlFiler.getAttribute(xn, "on-fail");
			string rest = XmlFiler.getAttribute(xn, "wait");
			if (rest != null) glimpse.Rest = Convert.ToInt32(rest);
			InterpretMessage(glimpse, xn.ChildNodes);
			AddInstruction(xn, glimpse, con);
			return glimpse;
		}
Esempio n. 30
0
 /// <summary>
 /// Called to finish construction when an instruction has been instantiated by
 /// a factory and had its properties set.
 /// This can check the integrity of the instruction or perform other initialization tasks.
 /// </summary>
 /// <param name="xn">XML node describing the instruction</param>
 /// <param name="con">Parent xml node instruction</param>
 /// <returns></returns>
 public override bool finishCreation(XmlNode xn, Context con)
 {
     // finish factory construction
     m_log.isTrue(Path != null || Select != null, makeNameTag() + "Click instruction must have a path or select.");
     m_log.isTrue(Path != "" || Select != "", makeNameTag() + "Click instruction must have a non-empty path or select.");
     return true;
 }
Esempio n. 31
0
		/// <summary>
		/// Read instruction file.
		/// Interpret script nodes according to tne instruction file.
		/// Make the class but don't process its child instructions if any.
		/// Don't execute the instruction.
		/// </summary>
		/// <param name="xn">The XML repersentation of the instruction to be checked</param>
		/// <param name="con">The current context object</param>
		/// <returns>Returns an unexecuted instruction or null</returns>
		static public Instruction MakeShell(XmlNode xn, Context con)
		{
			Logger.getOnly().isNotNull(xn, "Instruction can't be created from nothing!");
			if (m_actPrototypes == null) {
				Logger.getOnly().fail("Can not create: No instruction prototypes loaded.");
				return null;
			}

			Instruction FluffedInstruction = null;

			// number the context if it doesn't have one yet to avoid depth-first numbering.
			if (con != null && con.Number == -1) con.Number = TestState.getOnly().IncInstructionCount;

			// figure out what to do with this node
			switch (xn.Name)
			{
			case "#comment": // ignore comments, etc..
			case "#significant-whitespace":
			case "#whitespace":
			case "#text":
				break;
			default: // Find the instruction prototype based on node name.
				InsPrototype prototype = findPrototype(xn.Name, m_actPrototypes);
				if (prototype != null)
				{
					var AtValues = new ArrayList();
					ArrayList atts = prototype.Attributes;

					Logger.getOnly().startList("Instruction " + prototype.Name);

					XmlAttributeCollection atNodes = xn.Attributes;
					if (atNodes != null && atts != null)
					{
						foreach (XmlAttribute atx in atNodes)
						{ // find each attribute in the prototype
							string atValue = null;
							foreach (Attribute at in atts)
							{
								if (at.Name == atx.Name)
								{ // its this one
									atValue = XmlFiler.getAttribute(xn, at.Name);
									if (atValue != null && at.Name != "log")
									{ // log is dealt with in AddInstruction()
										var atVar = new Attribute(at.Name, atValue, at.Value);
										AtValues.Add(atVar);
										Logger.getOnly().listItem(" " + atx.Name + "=" + atValue);
										break;
									}
								}
							}
							if (atValue == null)
							{ // This attribute is not expected: make it a variable
								// Add it as a var instruction so it gets bound at the right time
								// Use <var id="atx.Name" set="atValue"/>
								var var = new Var();
								var.Id = atx.Name;
								var.Set = XmlFiler.getAttribute(xn, atx.Name);
								// Add the var to the growing list of instructions
								AddInstruction(xn, var, con);
								Logger.getOnly().paragraph("Added <var id=\"" + var.Id + "\" set=\"" + var.Set + "\"/>");
							}
						}
					}

					Logger.getOnly().endList();

					// Create the instruction using prototype.Name, AtValues.Name and AtValues.Value
					string protoName = XmlNameToCName(prototype.Name);
					string protoNameQ = prefix + protoName;
					Assembly assem = Assembly.GetExecutingAssembly();
					// All instruction classes must have empty constructors
					Object protoInstruction = null;
					try { protoInstruction = assem.CreateInstance(protoNameQ, true,
								   BindingFlags.CreateInstance, null, null, null, null);}
					catch (Exception e) { Logger.getOnly().fail("Instruction " + protoName + " not created: " + e.Message); }
					Logger.getOnly().isNotNull(protoInstruction, "Instruction " + protoName + " is DOA");
					FluffedInstruction = (Instruction)protoInstruction;
					foreach (Attribute at in AtValues)
					{ // Call each setter to set the instruction properties.
						int number = 0;
						UInt32 unsigned = 0;
						string primative = "string";
						if (at.Type == "msec" || at.Type == "int" || at.Type.Contains("[0-10]"))
						{
							try
							{
								number = Convert.ToInt32(at.Value);
								primative = "int";
							}
							catch (FormatException) { }
						}
						if (at.Type == "m-sec" || at.Type == "hz")
						{
							try
							{
								unsigned = Convert.ToUInt32(at.Value, 10);
								primative = "UInt32";
							}
							catch (FormatException) { }
						}
						if (primative == "string" && at.Type.Contains("|"))
						{
							string[] enumList = makeEnumList(at.Type);
							foreach (string value in enumList)
							{
								if (value == at.Value)
								{
									primative = value;
									break;
								}
							}
							if (primative == "string")
								Logger.getOnly().fail("Invalid enum {" + at.Value + "} for " + protoNameQ + "." + at.Name + "(" + at.Type + ")");
						}
						string propName = XmlNameToCName(at.Name);
						string propNameQ = protoNameQ + "." + XmlNameToCName(at.Name);
						PropertyInfo pi = null;
						MethodInfo m = null;
						try
						{
							if (primative == "int")
							{
								pi = assem.GetType(protoNameQ).GetProperty(propName, typeof(int));
								m = pi.GetSetMethod();
								m.Invoke(protoInstruction, new Object[] { number });
							}
							else if (primative == "UInt32")
							{
								pi = assem.GetType(protoNameQ).GetProperty(propName, typeof(UInt32));
								m = pi.GetSetMethod();
								m.Invoke(protoInstruction, new Object[] { unsigned });
							}
							else
							{
								Type t = assem.GetType(protoNameQ);
								pi = t.GetProperty(propName, typeof(string));
								m = pi.GetSetMethod();
								m.Invoke(protoInstruction, new Object[] { at.Value });
							}
						}
						catch
						{ Logger.getOnly().fail(" Can't find setter: " + protoNameQ + "." + propName + "(" + at.Type + ") using value {" + at.Value + "}"); }
						if (at.Name == "id" && protoName != "Var")
							TestState.getOnly().AddNamedInstruction(at.Value, FluffedInstruction);
					} // end of process attributes
					// Call the finishCreation method
					FluffedInstruction.finishCreation(xn, con);
					//if (prototype.Name != "if" &&
					//	prototype.Name != "then" && prototype.Name != "else")
					// Add the instruction to the growing list of instructions
					AddInstruction(xn, FluffedInstruction, con);
				}
				else
				{
					bool unknown = true;
					if (m_pasPrototypes != null)
					{
						InsPrototype IgnoredPrototype = findPrototype(xn.Name, m_pasPrototypes);
						if (IgnoredPrototype != null) unknown = false;
					}
					if (unknown) Logger.getOnly().fail("Can't make <" + xn.Name + "> instruction");
				}
				break;
			}
			return FluffedInstruction;
		}