///<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); }
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); }