/// <summary> /// Creates a section for a given test case /// </summary> /// <param name="runner">The runner to be used to execute the tests</param> /// <param name="aFrame">Frame to be displayed</param> /// <param name="aReportConfig">The report configuration containing display details</param> /// <param name="activatedRuleConditions">The list that will contain the rules activated by this test case</param> /// <returns></returns> public void CreateTestCaseSection(DataDictionary.Tests.Runner.Runner runner, TestCase aTestCase, TestsCoverageReportHandler aReportConfig, HashSet <RuleCondition> activatedRuleConditions, bool createPdf) { AddSubParagraph("Test case " + aTestCase.Name); if (aTestCase.Requirements.Count > 0) { AddParagraph("This test case verifies the following requirements"); foreach (DataDictionary.ReqRef reqRef in aTestCase.Requirements) { string text = "Requirement " + reqRef.Name; if (!Utils.Utils.isEmpty(reqRef.Comment)) { text = text + " : " + reqRef.Comment; } AddListItem(text); } } runner.RunUntilStep(null); activatedRuleConditions.UnionWith(runner.EventTimeLine.GetActivatedRules()); string title = "Test case " + aTestCase.Name; CreateTable(title, runner.EventTimeLine.GetActivatedRules(), aReportConfig.Dictionary.ImplementedRules, aReportConfig.AddActivatedRulesInTestCases, aReportConfig.AddNonCoveredRulesInTestCases); if (createPdf && aReportConfig.AddSteps) { foreach (Step step in aTestCase.Steps) { if (step.SubSteps.Count > 0) { AddSubParagraph(String.Format("Step {0}", step.Name)); DataDictionary.Tests.SubStep firstSubStep = step.SubSteps[0] as DataDictionary.Tests.SubStep; DataDictionary.Tests.SubStep lastSubStep = step.SubSteps[step.SubSteps.Count - 1] as DataDictionary.Tests.SubStep; double start = runner.EventTimeLine.GetSubStepActivationTime(firstSubStep); double end = runner.EventTimeLine.GetNextSubStepActivationTime(lastSubStep); List <RuleCondition> activatedRules = runner.EventTimeLine.GetActivatedRulesInRange(start, end); CreateStepTable(runner, step, aTestCase.Dictionary.ImplementedRules.Count, activatedRules, aReportConfig); if (aReportConfig.AddLog) { List <DataDictionary.Tests.Runner.Events.ModelEvent> events = runner.EventTimeLine.GetEventsInRange((uint)start, (uint)end); foreach (ModelEvent ev in events) { AddCode(ev.ToString()); } } CloseSubParagraph(); } } } CloseSubParagraph(); }
/// <summary> /// Executes the tests in the background thread /// </summary> /// <param name="arg"></param> public override void ExecuteWork() { if (Window != null) { DataDictionary.Tests.SubSequence subSequence = TestCase.Enclosing as DataDictionary.Tests.SubSequence; if (subSequence != null) { DataDictionary.Tests.Runner.Runner runner = new DataDictionary.Tests.Runner.Runner(subSequence); runner.RunUntilStep(null); } } }
/// <summary> /// Creates a table for a given step of a test /// </summary> /// <param name="aStep">The step to be displayed</param> /// <param name="totalNumberOfRules">The total number of implemented rules in the dictionary</param> /// <param name="aReportConfig">The report config</param> /// <returns></returns> private void CreateStepTable(DataDictionary.Tests.Runner.Runner runner, Step aStep, int totalNumberOfRules, List <RuleCondition> activatedRules, TestsCoverageReportHandler aReportConfig) { AddParagraph(aStep.Name); AddTable(new string[] { "", "Statistics" }, new int[] { 40, 100 }); double implementedPercentage = (double)((double)activatedRules.Count / (double)totalNumberOfRules) * 100; AddRow("Number of activated rules", String.Format("{0} ({1:0.##}%)", activatedRules.Count.ToString(), implementedPercentage)); if (aReportConfig.AddActivatedRulesInSteps && activatedRules.Count > 0) { AddRow("Activated rules", null); foreach (RuleCondition ruleCondition in activatedRules) { AppendToRow(null, ruleCondition.Name); } } }
/// <summary> /// Handles a run event on this step /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void RunForExpectationsHandler(object sender, EventArgs args) { CheckRunner(); Window window = BaseForm as Window; if (window != null) { DataDictionary.Tests.Runner.Runner runner = window.getRunner(Item.TestCase.SubSequence); runner.RunUntilStep(Item); foreach (DataDictionary.Tests.SubStep subStep in Item.SubSteps) { runner.SetupSubStep(subStep); if (!subStep.getSkipEngine()) { runner.RunForBlockingExpectations(true); } } window.MDIWindow.Refresh(); } }
/// <summary> /// Perform all functional tests defined in the .EFS file provided /// </summary> /// <param name="args"></param> /// <returns>the error code of the program</returns> static int Main(string[] args) { int retVal = 0; try { Console.Out.WriteLine("EFS Tester"); // Load the dictionaries provided as parameters EFSSystem efsSystem = EFSSystem.INSTANCE; foreach (string arg in args) { Console.Out.WriteLine("Loading dictionary " + arg); Dictionary dictionary = Util.load(arg, efsSystem); if (dictionary == null) { Console.Out.WriteLine("Cannot load dictionary " + arg); return(-1); } } // Perform functional test for each loaded dictionary foreach (Dictionary dictionary in efsSystem.Dictionaries) { Console.Out.WriteLine("Processing tests from dictionary " + dictionary.Name); foreach (DataDictionary.Tests.Frame frame in dictionary.Tests) { Console.Out.WriteLine("Executing frame " + frame.FullName); foreach (DataDictionary.Tests.SubSequence subSequence in frame.SubSequences) { Console.Out.WriteLine("Executing sub sequence " + subSequence.FullName); DataDictionary.Tests.Runner.Runner runner = new DataDictionary.Tests.Runner.Runner(subSequence); runner.RunUntilStep(null); bool failed = false; foreach (DataDictionary.Tests.Runner.Events.Expect expect in runner.FailedExpectations()) { Console.Out.WriteLine(" failed : " + expect.Message); DataDictionary.Tests.TestCase testCase = Utils.EnclosingFinder <DataDictionary.Tests.TestCase> .find(expect.Expectation); if (testCase.ImplementationCompleted) { Console.Out.WriteLine(" !Unexpected failed expectation: " + expect.Message); failed = true; } else { Console.Out.WriteLine(" .Expected failed expectation: " + expect.Message); } } if (failed) { Console.Out.WriteLine(" -> Failed"); retVal = -1; } else { Console.Out.WriteLine(" -> Success"); } } } } } finally { DataDictionary.Util.UnlockAllFiles(); } return(retVal); }
/// <summary> /// Perform all functional tests defined in the .EFS file provided /// </summary> /// <param name="args"></param> /// <returns>the error code of the program</returns> static int Main(string[] args) { int retVal = 0; try { Console.Out.WriteLine("EFS Tester"); // Load the dictionaries provided as parameters EFSSystem efsSystem = EFSSystem.INSTANCE; foreach (string arg in args) { Console.Out.WriteLine("Loading dictionary " + arg); Dictionary dictionary = Util.load(arg, efsSystem); if (dictionary == null) { Console.Out.WriteLine("Cannot load dictionary " + arg); return -1; } } // Perform functional test for each loaded dictionary foreach (Dictionary dictionary in efsSystem.Dictionaries) { Console.Out.WriteLine("Processing tests from dictionary " + dictionary.Name); foreach (DataDictionary.Tests.Frame frame in dictionary.Tests) { Console.Out.WriteLine("Executing frame " + frame.FullName); foreach (DataDictionary.Tests.SubSequence subSequence in frame.SubSequences) { Console.Out.WriteLine("Executing sub sequence " + subSequence.FullName); DataDictionary.Tests.Runner.Runner runner = new DataDictionary.Tests.Runner.Runner(subSequence); runner.RunUntilStep(null); bool failed = false; foreach (DataDictionary.Tests.Runner.Events.Expect expect in runner.FailedExpectations()) { Console.Out.WriteLine(" failed : " + expect.Message); DataDictionary.Tests.TestCase testCase = Utils.EnclosingFinder<DataDictionary.Tests.TestCase>.find(expect.Expectation); if (testCase.ImplementationCompleted) { Console.Out.WriteLine(" !Unexpected failed expectation: " + expect.Message); failed = true; } else { Console.Out.WriteLine(" .Expected failed expectation: " + expect.Message); } } if (failed) { Console.Out.WriteLine(" -> Failed"); retVal = -1; } else { Console.Out.WriteLine(" -> Success"); } } } } } finally { DataDictionary.Util.UnlockAllFiles(); } return retVal; }
/// <summary> /// Draws the transition within the state panel /// </summary> /// <param name="e"></param> public void PaintInStatePanel(PaintEventArgs e) { if (Visible) { double angle = Angle; Point start = StartLocation; Point target = TargetLocation; // Select the pen used to draw the arrow Pen pen = NORMAL_PEN; SetColor(NORMAL_COLOR); if (Name.CompareTo("Initial State") != 0) { StateMachine transitionStateMachine = Utils.EnclosingFinder <StateMachine> .find(Transition.RuleCondition); if (transitionStateMachine == null && Name.CompareTo("Initial State") != 0) { // A degraded case is a transition that is not defined in any state machine pen = DEGRADED_CASE_PEN; SetColor(DEGRADED_CASE_COLOR); } else { if (Transition.RuleCondition != null && Panel.StateMachine.Rules.Contains(Transition.RuleCondition.EnclosingRule)) { // A degraded case is a transition that is defined in the rules of the state machines (not in its states) pen = DEGRADED_CASE_PEN; SetColor(DEGRADED_CASE_COLOR); } } } if (Transition.RuleCondition != null) { if (Transition.RuleCondition.IsDisabled()) { pen = DISABLED_PEN; SetColor(DISABLED_COLOR); } else { DataDictionary.Tests.Runner.Runner runner = Transition.RuleCondition.EFSSystem.Runner; if (runner != null) { if (runner.RuleActivatedAtTime(Transition.RuleCondition, runner.LastActivationTime, Panel.StateMachineVariable)) { pen = ACTIVATED_PEN; SetColor(ACTIVATED_COLOR); } } } } if (Panel.isSelected(this)) { // Change the pen when the transition is selected pen = new Pen(pen.Color, 4); } // Draw the arrow e.Graphics.DrawLine(pen, start, target); { int x = target.X - (int)(Math.Cos(angle + ARROW_ANGLE) * ARROW_LENGTH); int y = target.Y - (int)(Math.Sin(angle + ARROW_ANGLE) * ARROW_LENGTH); e.Graphics.DrawLine(pen, target, new Point(x, y)); } { int x = target.X - (int)(Math.Cos(angle - ARROW_ANGLE) * ARROW_LENGTH); int y = target.Y - (int)(Math.Sin(angle - ARROW_ANGLE) * ARROW_LENGTH); e.Graphics.DrawLine(pen, target, new Point(x, y)); } if (TargetStateControl == null) { Font boldFont = new Font(Font, FontStyle.Bold); string targetStateName = transition.getTargetStateName(); SizeF size = e.Graphics.MeasureString(targetStateName, boldFont); int x = target.X - (int)(size.Width / 2); int y = target.Y + 10; e.Graphics.DrawString(targetStateName, boldFont, EXTERNAL_STATE_PEN.Brush, new Point(x, y)); } } }