///<summary> /// Enqueue a modeling action. If an actionTestCaseDelimiter is pass we incress the Amount of test cases (property) ///</summary> public void Enqueue(ModelTestCase action) { lock (_queue) { _queue.Enqueue(action); } }
/// <summary> /// Extract all the test cases specify on the constructor and return will all the cases /// </summary> public ActionsQueue CreateActionsQueue() { int currentCase; LogComment("**************************************************************"); LogComment("Start retrieving all the test cases from the XTC File"); LogComment((_lastCase - _firstCase + 1).ToString() + " test cases found"); //Go through each case specified for (currentCase = _firstCase; currentCase <= _lastCase; currentCase++) { LogStatus("Transitions for test case # " + (currentCase).ToString()); XmlNodeList currentStepsNodeList = SetCurrentStepsForTestIndex(currentCase); for (int iStep = 0; iStep < currentStepsNodeList.Count; iStep++) { ModelTestCase testCase; testCase = new ModelTestCase(); State lastEndState = null; XmlNodeList currentTransitionsList = SetCurrentTransitionFromStep(currentStepsNodeList, iStep); Model lastModel = null; LogStatus((currentTransitionsList.Count).ToString() + " transtions found for current test case"); for (int currentTransitionIndex = 0; currentTransitionIndex < currentTransitionsList.Count; currentTransitionIndex++) { lastModel = EnqueueCurrentTransition(currentTransitionsList, currentTransitionIndex, out lastEndState, testCase); } testCase.AddTransition(new ModelEndTransition(lastModel, lastEndState)); _queue.Enqueue(testCase); LogStatus("The transitions for test case # " + (currentCase).ToString() + " are retrieved"); } } LogComment("All information is enqueued and ready for execution"); LogComment("**************************************************************"); return(_queue); }
///<summary> /// Execute the traversals for the XTC passed to the constructor. /// Load the Xtc file, create the actions queue, and dispatch the actions. ///</summary> public bool Run() { LogStatus("* Model loader: Started..."); // Enqueue all model cases. Initialization(); LogStatus("* Model loader: Executing model cases..."); int totalCases = _asyncActions.AmountTestCases; //VariationContext vc = null; if (ShouldCreateTestLogs) { // vc = new VariationContext("Modeling"); } // Loop through each case in the queue. for (int testCaseIndex = 1; testCaseIndex <= totalCases; testCaseIndex++) { bool testResult = false; bool testLastActionResult = false; bool alreadyBegan = false; //TestLog testLog = null; if (ShouldCreateTestLogs) { //testLog = new TestLog(testCaseIndex.ToString()); } LogStatus("* Start model case #" + testCaseIndex.ToString()); _asyncActions.MoveToNextTestCase(); ModelTestCase modelTestCase = _asyncActions.CurrentModelTestCase; try { while (!modelTestCase.IsTestCaseCompleted) { ModelTransition currentAction = modelTestCase.GetModelTransition(); if (currentAction == null) { throw new InvalidOperationException("ModelTransition is expected"); } if (!alreadyBegan) { alreadyBegan = true; currentAction.CurrentModel.CurrStartState = currentAction.EndState; testResult = currentAction.CurrentModel.BeginCase(currentAction.EndState); } if (!String.IsNullOrEmpty(currentAction.ActionName)) { LogStatus("* Executing Action: " + currentAction.ActionName); testResult = currentAction.CurrentModel.ExecuteAction(currentAction.ActionName, currentAction.EndState, currentAction.InParams, currentAction.OutParams); currentAction.CurrentModel.CurrStartState = currentAction.EndState; if (modelTestCase.IsTestCasePassed == ModelTestCaseResult.Failed) { LogComment("* Action Failed: " + modelTestCase.ActionBeforeTransitionFailure + " Returned False"); break; } else if (testResult == false) { LogComment("* Action Failed: " + currentAction.ActionName + " Returned False"); break; } } } } catch (Exception e) { LogStatus("Exception occurred"); testResult = false; LogComment(e.ToString()); } finally { // We need to ensure that EndCase always will be called to clean up any resource that the test case // is holding on. LogStatus("* End model case: " + testCaseIndex.ToString()); ModelTransition lastAction = modelTestCase.GetModelTransition(); testLastActionResult = lastAction.CurrentModel.EndCase(lastAction.EndState); } if (testResult == false || !testLastActionResult || modelTestCase.IsTestCasePassed == ModelTestCaseResult.Failed) { LogComment("Model case #" + testCaseIndex.ToString() + " ended with an error"); if (ShouldCreateTestLogs) { //testLog.Result = TestResult.Fail; } TotalFailures.Add(testCaseIndex); } else { LogComment("Model case #" + testCaseIndex.ToString() + " completed"); if (ShouldCreateTestLogs) { //testLog.Result = TestResult.Pass; } } if (ShouldCreateTestLogs) { //testLog.Close(); } } LogStatus("* Model loader: All test cases were executed"); CleanUpModels(); LogStatus("* Model loader: Done"); if (ShouldCreateTestLogs) { //vc.Close(); } return(TotalFailures.Count == 0); }
/// <summary> /// Executes the Transition that is set by member variables /// </summary> /// <remarks>Check the Errors collection for errors</remarks> /// <returns>false if errors occur</returns> private Model EnqueueCurrentTransition(XmlNodeList currentTransitionsList, int transitionIndex, out State lastEndState, ModelTestCase testCase) { XmlNode actionNode, stateNode; string actionName; XmlNodeList inParams, outParams; State objInParams = null, objOutParams = null; State endState = null; XmlNode currTransition = null; Model currModel; //Get the transition Node currTransition = currentTransitionsList.Item(transitionIndex); //Find the model currModel = GetModel(currTransition); //Get the In action Params objInParams = null; inParams = currTransition.SelectNodes("curr:PARAM[@Type = 'In']", _nsmgr); if (inParams.Count > 0) { objInParams = this.GetActionParams(inParams); if (objInParams == null) { throw new ModelLoaderException("Failure getting Action IN Params"); } } //Get the Out action Params objOutParams = null; outParams = currTransition.SelectNodes("curr:PARAM[@Type = 'Out']", _nsmgr); if (outParams.Count > 0) { objOutParams = this.GetActionParams(outParams); if (objOutParams == null) { throw new ModelLoaderException("Failure getting Action OUT Params"); } } //Get the action Node & use it to get the action name actionNode = currTransition.SelectSingleNode("curr:ACTION", _nsmgr); int fileID = -1; actionName = this.GetAction(actionNode, out fileID); if (actionName == null) { throw new ModelLoaderException("Failure finding an action for this transition"); } //Get the state Node to create the object endState = null; stateNode = currTransition.SelectSingleNode("curr:STATE", _nsmgr); //In stateless model case there will not be a STATE node in the xtc if (stateNode != null) { endState = this.GetState(stateNode); if (endState == null) { throw new ModelLoaderException("Failure finding the state variables for this transition"); } } if ((actionName == null) || (actionName.Trim() == "") && transitionIndex == 0) { testCase.AddTransition(new ModelTransition(currModel, String.Empty, null, endState, null, null)); //_queue.Enqueue(new ModelTransition(currModel,String.Empty,null,endState,null,null)); } else { //Log transition information & execute the action LogStatus(currModel.GetType().Name + "." + actionName + "(" + objInParams + ")"); //_queue.Enqueue(new ModelTransition(currModel, actionName,null,endState,objInParams,objOutParams)); testCase.AddTransition(new ModelTransition(currModel, actionName, null, endState, objInParams, objOutParams)); } lastEndState = endState; return(currModel); }
private IntPtr _hwndHook(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled) { handled = false; if (hwnd == _hwnd.Handle && ActionwindowMessage == msg) { lock (_queue) { if (!_ignoreUntilStart || !_runningAsync) { ModelTestCase modelTestCase = _queue.CurrentTestCase; if (modelTestCase != null && modelTestCase.AmountTransitions > 0) { if (modelTestCase.IsTestCaseCompleted) { ModelTransition currentAction = modelTestCase.PeekModelTransition(); currentAction.CurrentModel.EndCaseOnNestedPump(); if (_runningAsync) { NativeMethods.PostMessage(new HandleRef(null, _hwnd.Handle), EndAsyncCaseExecution, IntPtr.Zero, IntPtr.Zero); } } else { bool isTransitionPassed = false; ModelTransition currentAction = modelTestCase.GetModelTransition(); handled = true; if (currentAction != null) { LogStatus("* ITE Executing " + currentAction.ActionName); try { isTransitionPassed = currentAction.CurrentModel.ExecuteAction(currentAction.ActionName, currentAction.EndState, currentAction.InParams, currentAction.OutParams); } catch (Exception e) { isTransitionPassed = false; LogComment("Expection was caught"); LogComment("Message:"); LogComment(e.Message.ToString()); LogComment("CallStack:"); LogComment(e.StackTrace.ToString()); } finally { currentAction.CurrentModel.CurrStartState = currentAction.EndState; } if (!isTransitionPassed) { modelTestCase.IsTestCasePassed = ModelTestCaseResult.Failed; modelTestCase.ActionBeforeTransitionFailure = String.Copy(currentAction.ActionName); modelTestCase.ClearTransitions(); } } else { throw new ModelLoaderException("Error: GetActionIntemState retrieve null"); } } } else { throw new ModelLoaderException("Error: Trying to dispatch an empty transition from a queue"); } } } } if (hwnd == _hwnd.Handle && StartAsyncCaseExecution == msg) { _ignoreUntilStart = false; _runningAsync = true; _caseOrderCount++; //TestLog testLog = new TestLog(_caseOrderCount.ToString()); LogComment("**********************"); LogComment("Executing TEST CASE # " + _caseOrderCount.ToString()); if (this.AmountTestCases > 0) { this.MoveToNextTestCase(); ModelTestCase testCase = this.CurrentModelTestCase; ModelTransition currentAction = testCase.GetModelTransition(); if (currentAction.ActionName == String.Empty) { currentAction.CurrentModel.CurrStartState = currentAction.EndState; currentAction.CurrentModel.BeginCase(currentAction.EndState); } else { throw new ModelLoaderException("Expecting a empty ActionName. The Testcase is init Async."); } } } if (hwnd == _hwnd.Handle && EndAsyncCaseExecution == msg) { _ignoreUntilStart = true; LogStatus("* ITE End Case: " + _caseOrderCount.ToString()); ModelTestCase testCase = this.CurrentModelTestCase; ModelTransition lastAction = testCase.GetModelTransition(); lastAction.CurrentModel.EndCase(lastAction.EndState); if (testCase.IsTestCasePassed == ModelTestCaseResult.Failed) { LogComment("* ITE Action Failed: " + testCase.ActionBeforeTransitionFailure + " Returned False"); LogComment("TEST CASE # " + _caseOrderCount.ToString() + " Ended with an Error"); //TestLog.Current.Result = TestResult.Fail; } else { LogComment("TEST CASE # " + _caseOrderCount.ToString() + " Completed"); //TestLog.Current.Result = TestResult.Pass; } LogComment("**********************"); //TestLog.Current.Close(); if (this.AmountTestCases > 0) { NativeMethods.PostMessage(new HandleRef(null, _hwnd.Handle), StartAsyncCaseExecution, IntPtr.Zero, IntPtr.Zero); } else { LogComment("All test cases were executed"); LogComment("**************************************************************"); _testcaseLoader.CleanUpModels(); LogComment("XTCTestCaseLoader ended..."); _testcaseLoader.OnRunCompleted(); } } return(IntPtr.Zero); }