Ejemplo n.º 1
0
        public bool RunTest(System.Xml.XmlNode seeflawNode, XmlElement bodyElement, RunnerDetails runDetails)
        {
            XmlDocument doc = bodyElement.OwnerDocument;
            ResultParser parser = new ResultParser(doc, errParser, onlyTest);
            Runner defaultRunner = new Runner(onlyTest, runDetails);

            for (int i = 0; i < seeflawNode.ChildNodes.Count; i++)
            {
                XmlNode childNode = seeflawNode.ChildNodes[i];
                switch (childNode.LocalName)
                {
                    case ActionType.TEXT:
                        // Gather all text nodes that follows each other
                        List<XmlNode> textNodes = GetSelectedNodes(seeflawNode.ChildNodes, ActionType.TEXT, i);
                        XmlElement textElement = bodyElement.OwnerDocument.CreateElement("text");
                        bodyElement.AppendChild(textElement);
                        foreach (XmlNode rowNode in textNodes)
                        {
                            XmlElement rowElement = bodyElement.OwnerDocument.CreateElement("row");
                            rowElement.InnerText = rowNode.InnerText;
                            textElement.AppendChild(rowElement);
                        }
                        i += textNodes.Count - 1;
                        break;
                    case ActionType.PARAM:
                        // Gather all param nodes that follows each other
                        List<XmlNode> paramNodes = GetParamNodes(seeflawNode.ChildNodes, i);
                        if (paramNodes.Count > 0)
                        {
                            ResultHolder paramData = defaultRunner.RunFixtureParam(paramNodes);
                            AppendResultTable(bodyElement, paramData, parser);
                            i += paramNodes.Count - 1;
                        }
                        else
                        {
                            // This is a fixture param node
                            Runner paramRunner = new Runner(childNode, runDetails);
                            Thread paramRunnerThread = new Thread(new ThreadStart(paramRunner.ThreadRun));
                            paramRunnerThread.Start();
                            ResultHolder paramAbortData = HandleRunnerThread(paramRunnerThread, paramRunner);
                            ResultHolder paramCallData = paramRunner.GetThreadRunResult();
                            AppendResultTable(bodyElement, paramCallData, parser);
                            AppendResultTable(bodyElement, paramAbortData, parser);
                        }
                        break;
                    case ActionType.INIT:
                        // Gather all init nodes that follows each other
                        List<XmlNode> initNodes = GetSelectedNodes(seeflawNode.ChildNodes, ActionType.INIT, i);
                        ResultHolder initData = defaultRunner.RunFixtureInit(initNodes);
                        AppendResultTable(bodyElement, initData, parser);
                        i += initNodes.Count - 1;
                        break;
                    case ActionType.CALL:
                        Runner runner = new Runner(childNode, runDetails);
                        Thread runnerThread = new Thread(new ThreadStart(runner.ThreadRun));
                        runnerThread.Start();
                        ResultHolder abortData = HandleRunnerThread(runnerThread, runner);
                        ResultHolder callData = runner.GetThreadRunResult();
                        AppendResultTable(bodyElement, callData, parser);
                        AppendResultTable(bodyElement, abortData, parser);
                        break;
                    case ActionType.SAVE:
                        XmlNode saveInputNode = childNode.OwnerDocument.ImportNode(testResultSaveInput, true);
                        XmlElement htmlResultNode = TransformToHtml(testResultSaveInput, childNode.OwnerDocument);
                        bool inputNodesExist = false;
                        if (childNode.ChildNodes.Count > 0)
                        {
                            foreach (XmlNode inputChildNode in childNode.ChildNodes)
                            {
                                if (inputChildNode.LocalName == "input")
                                {
                                    if (inputChildNode.ChildNodes.Count > 0)
                                    {
                                        inputChildNode.InsertBefore(htmlResultNode.Clone(), inputChildNode.FirstChild);
                                        inputChildNode.InsertBefore(saveInputNode.Clone(), inputChildNode.FirstChild);
                                    }
                                    else
                                    {
                                        inputChildNode.AppendChild(saveInputNode.Clone());
                                        inputChildNode.AppendChild(htmlResultNode.Clone());
                                    }
                                    inputNodesExist = true;
                                }
                            }
                        }
                        if (!inputNodesExist)
                        {
                            XmlNode inputNode = childNode.OwnerDocument.CreateElement("input");
                            inputNode.AppendChild(saveInputNode);
                            inputNode.AppendChild(htmlResultNode);
                            childNode.AppendChild(inputNode);
                        }
                        goto case ActionType.CALL;
                    case ActionType.LOAD:
                        XmlAttribute fileLoadAttr = GetAttributeByName(childNode, "file");
                        XmlNode loadTestNode = null;
                        if(loadDic.TryGetValue(fileLoadAttr.Value, out loadTestNode))
                        {
                            XmlElement loadBodyNode = doc.CreateElement("load");
                            loadBodyNode.SetAttribute("file", fileLoadAttr.Value);
                            RunnerDetails loadRunDetails = runDetails.LoadCopy(fileLoadAttr.Value);
                            RunTest(loadTestNode, loadBodyNode, loadRunDetails);
                            bodyElement.AppendChild(loadBodyNode);
                        }
                        break;
                    case ActionType.ASYNC:
                        List<ThreadRunnerInfo> asyncPairList = new List<ThreadRunnerInfo>();
                        foreach (XmlNode fixtureNode in childNode.ChildNodes)
                        {
                            if (fixtureNode.LocalName == "fixture")
                            {
                                XmlAttribute fixId = GetAttributeByName(fixtureNode, "id");
                                Object asyncFixture = runDetails.GetInitiatedFixture(fixId.Value);
                                if (asyncFixture != null)
                                {
                                    Runner asyncRunner = new Runner(fixtureNode, asyncFixture, runDetails);
                                    Thread asyncThread = new Thread(new ThreadStart(asyncRunner.ThreadAsyncRun));
                                    asyncThread.Start();
                                    asyncPairList.Add(new ThreadRunnerInfo(asyncThread, asyncRunner, fixId.Value));
                                }
                            }
                        }
                        XmlElement asyncNode = doc.CreateElement("async");
                        foreach (ThreadRunnerInfo asyncInfo in asyncPairList)
                        {
                            XmlElement asyncFixtureNode = doc.CreateElement("fixture");
                            asyncFixtureNode.SetAttribute("id", asyncInfo.fixtureId);
                            ResultHolder abortAsyncData = HandleRunnerThread(asyncInfo.thread, asyncInfo.runner);
                            foreach (ResultHolder asyncData in asyncInfo.runner.GetThreadAsyncRunResult())
                            {
                                AppendResultTable(asyncFixtureNode, asyncData, parser);
                            }
                            AppendResultTable(asyncFixtureNode, abortAsyncData, parser);
                            asyncNode.AppendChild(asyncFixtureNode);
                        }
                        bodyElement.AppendChild(asyncNode);
                        break;
                    default:
                        // TODO error message
                        break;
                }
                if (bgRunner != null && bgRunner.KillPending)
                {
                    break;
                }
            }
            return runSuccessful;
        }