public void TestRefactorStructureName() { Dictionary test = CreateDictionary("Test"); NameSpace n1 = CreateNameSpace(test, "N1"); Collection collection = CreateCollection(n1, "Col", "Integer", 10); Variable v = CreateVariable(n1, "V", "Col"); v.setDefaultValue("[]"); RuleCondition rc1 = CreateRuleAndCondition(n1, "Rule1"); Action a1 = CreateAction(rc1, "INSERT 1 IN V"); RuleCondition rc2 = CreateRuleAndCondition(n1, "Rule2"); Action a2 = CreateAction(rc2, "INSERT 2 IN V"); // ReSharper disable once UseObjectOrCollectionInitializer Runner runner = new Runner(false); runner.CheckForCompatibleChanges = true; runner.Cycle(); ListValue listValue = v.Value as ListValue; Assert.IsNotNull(listValue); Assert.AreEqual(2, listValue.Val.Count); Assert.AreEqual(0, a1.Messages.Count); Assert.AreEqual(0, a2.Messages.Count); }
/// <summary> /// Adds an action for this sub-step /// </summary> /// <param name="sender"></param> /// <param name="args"></param> public void AddActionHandler(object sender, EventArgs args) { DataDictionary.Rules.Action action = (DataDictionary.Rules.Action)DataDictionary.Generated.acceptor.getFactory().createAction(); action.Enclosing = Item; action.Name = "Action" + actions.Nodes.Count; createAction(action); }
public void TestSubRulesPriority() { Dictionary test = CreateDictionary("Test"); NameSpace n1 = CreateNameSpace(test, "N1"); Variable v1 = CreateVariable(n1, "V", "Integer"); v1.setDefaultValue("0"); Variable v2 = CreateVariable(n1, "V2", "Integer"); v2.setDefaultValue("0"); // Priority is Processing RuleCondition rc1 = CreateRuleAndCondition(n1, "Rule1"); Action a1 = CreateAction(rc1, "V2 <- V2 + 1"); // Priority is Update out RuleCondition rc2 = CreateRuleAndCondition(rc1, "Rule2"); rc2.EnclosingRule.setPriority(acceptor.RulePriority.aUpdateOUT); Action a2 = CreateAction(rc2, "V <- V + 1"); // ReSharper disable once UseObjectOrCollectionInitializer Runner runner = new Runner(false); runner.Cycle(); IntValue value = v1.Value as IntValue; Assert.IsNotNull(value); Assert.AreEqual(1, value.Val); value = v2.Value as IntValue; Assert.IsNotNull(value); Assert.AreEqual(1, value.Val); }
/// <summary> /// Adds the given action to the list of actions /// </summary> /// <param name="action"></param> public void addAction(DataDictionary.Rules.Action action) { action.Enclosing = Item; DataDictionaryView.ActionTreeNode actionNode = new DataDictionaryView.ActionTreeNode(action); Item.appendActions(action); Nodes.Add(actionNode); SortSubNodes(); }
private void openStructureEditorToolStripMenuItem_Click(object sender, EventArgs e) { bool dialogShown = false; ExplanationPart part = Instance as ExplanationPart; if (part != null) { IValue value = part.RightPart as IValue; if (value != null) { StructureEditor.Window window = new StructureEditor.Window(); window.SetModel(value); window.ShowDialog(); dialogShown = true; } Action action = part.Element as Action; if (!dialogShown && action != null) { VisitStatement(action.Statement); dialogShown = true; } Expectation expectation = part.Element as Expectation; if (!dialogShown && expectation != null) { VisitExpression(expectation.Expression); dialogShown = true; } } if (!dialogShown) { const bool doSemanticalAnalysis = true; const bool silent = true; ModelElement root = Instance as ModelElement; if (root == null) { root = EfsSystem.Instance.Dictionaries[0]; } string text = EditionTextBox.Text; Expression expression = new Parser().Expression(root, text, AllMatches.INSTANCE, doSemanticalAnalysis, null, silent); if (expression != null) { expression = VisitExpression(expression); EditionTextBox.Text = expression.ToString(); } Statement statement = new Parser().Statement(root, text, silent); if (statement != null) { statement = VisitStatement(statement); EditionTextBox.Text = statement.ToString(); } } }
/// <summary> /// Creates an action in the enclosing rule condition /// </summary> /// <param name="enclosing"></param> /// <param name="expression"></param> /// <returns></returns> protected Action CreateAction(RuleCondition enclosing, string expression) { Action retVal = (Action)Factory.createAction(); enclosing.appendActions(retVal); retVal.ExpressionText = expression; return(retVal); }
/// <summary> /// Creates a new action /// </summary> /// <param name="testCase"></param> /// <returns></returns> public DataDictionaryView.ActionTreeNode createAction(DataDictionary.Rules.Action action) { DataDictionaryView.ActionTreeNode retVal = new DataDictionaryView.ActionTreeNode(action); Item.appendActions(action); actions.Nodes.Add(retVal); return(retVal); }
/// <summary> /// Executes the action /// </summary> /// <param name="e"></param> protected override void OnClick(EventArgs e) { if (SubStep != null) { Action action = (Action)acceptor.getFactory().createAction(); action.Name = ""; SubStep.appendActions(action); } base.OnClick(e); }
/// <summary> /// Review the expressions associated to this action /// </summary> /// <param name="action"></param> private void Review(Action action) { try { action.ExpressionText = ReviewExpression(action.Step, action.ExpressionText); } catch (Exception e) { action.AddException(e); } }
/// <summary> /// Handles a drop event /// </summary> /// <param name="SourceNode"></param> public override void AcceptDrop(BaseTreeNode SourceNode) { if (SourceNode is ActionTreeNode) { if (MessageBox.Show("Are you sure you want to move the corresponding action ?", "Move action", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { ActionTreeNode actionTreeNode = (ActionTreeNode)SourceNode; DataDictionary.Rules.Action action = actionTreeNode.Item; actionTreeNode.Delete(); AddAction(action); } } }
public override ActionTreeNode AddAction(DataDictionary.Rules.Action action) { ActionTreeNode retVal = new ActionTreeNode(action); Item.appendActions(action); Nodes.Add(retVal); if (Item.EnclosingRule != null && !Item.EnclosingRule.BelongsToAProcedure()) { SortSubNodes(); } Item.setVerified(false); return(retVal); }
private void Btn_AddActions_Click(object sender, EventArgs e) { foreach (Control control in GrB_Procedures.Controls) { if (control is CheckBox) { // For each selected check box an action is created CheckBox aCheckBox = control as CheckBox; if (aCheckBox.Checked == true) { DataDictionary.Rules.Action anAction = (DataDictionary.Rules.Action)DataDictionary.Generated.acceptor.getFactory().createAction(); anAction.ExpressionText = aCheckBox.Text + " <- " + aCheckBox.Text + "." + CbB_StateName.SelectedItem.ToString(); CreateCustomAction(anAction); } } } this.Hide(); }
/// <summary> /// Adds a model element in this model element /// </summary> /// <param name="element"></param> public override void AddModelElement(IModelElement element) { if (element is Action) { Action item = element as Action; if (item != null) { appendActions(item); } } else if (element is Expectation) { Expectation item = element as Expectation; if (item != null) { appendExpectations(item); } } }
public void AddHandler(object sender, EventArgs args) { Item.appendActions(Action.CreateDefault(Item.Actions)); }
/// <summary> /// Review the expressions associated to this action /// </summary> /// <param name="action"></param> private void Review(Action action) { try { action.ExpressionText = ReviewExpression(action.Step, action.ExpressionText); } catch (Exception e) { action.AddException(e); } }
/// <summary> /// Handles a drop event /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TimeLineControl_DragDrop(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("WindowsForms10PersistentObject", false)) { BaseTreeNode sourceNode = e.Data.GetData("WindowsForms10PersistentObject") as BaseTreeNode; if (sourceNode != null) { VariableTreeNode variableNode = sourceNode as VariableTreeNode; if (variableNode != null) { SubStep subStep = SubStepRelatedToMousePosition(); if (subStep != null) { // Create the default value IValue value = null; Expression expression = null; string defaultValue = variableNode.Item.Default; if (defaultValue != null) { const bool doSemanticalAnalysis = true; const bool silent = true; expression = new Parser().Expression(variableNode.Item, defaultValue, AllMatches.INSTANCE, doSemanticalAnalysis, null, silent); } if (expression != null) { InterpretationContext context = new InterpretationContext { UseDefaultValue = false }; value = expression.GetExpressionValue(context, null); } if (value == null || value is EmptyValue) { Structure structureType = variableNode.Item.Type as Structure; if (structureType != null) { const bool setDefaultValue = false; value = new StructureValue(structureType, setDefaultValue); } } // Create the action or the expectation according to the keyboard modifier keys if (value != null) { if ((e.KeyState & Ctrl) != 0) { Expectation expectation = (Expectation)acceptor.getFactory().createExpectation(); expectation.ExpressionText = variableNode.Item.FullName + " == " + value.FullName; subStep.appendExpectations(expectation); } else { Action action = (Action)acceptor.getFactory().createAction(); action.ExpressionText = variableNode.Item.FullName + " <- " + value.FullName; subStep.appendActions(action); } } else { MessageBox.Show( Resources .StaticTimeLineControl_TimeLineControl_DragDrop_Cannot_evaluate_variable_default_value, Resources.StaticTimeLineControl_TimeLineControl_DragDrop_Cannot_create_event, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } } }
/// <summary> /// Updates the step according to this translation /// </summary> /// <param name="step"></param> public void UpdateStep(Step step) { Step previousStep = step.PreviousStep; foreach (ReqRef reqRef in Requirements) { if (!IsRequirementPresent(step, reqRef)) { step.appendRequirements((ReqRef)reqRef.Duplicate()); } } int subStepCounter = 1; foreach (SubStep subStep in SubSteps) { bool addSubStep = true; if (subStep.ReferencesMessages()) { addSubStep = step.Messages.Count > 0; } if (addSubStep) { SubStep newSubStep = (SubStep)acceptor.getFactory().createSubStep(); newSubStep.setSkipEngine(subStep.getSkipEngine()); newSubStep.Comment = subStep.Comment; newSubStep.Name = subStep.Name; step.appendSubSteps(newSubStep); if (previousStep != null && previousStep.Distance != step.Distance && subStepCounter == 1) { Action newAct = (Action)acceptor.getFactory().createAction(); string distance = step.getDistance(); if (!distance.Contains(".")) { distance = distance + ".0"; } newAct.ExpressionText = "OdometryInterface.UpdateDistance ( " + distance + " )"; newSubStep.setSkipEngine(false); newSubStep.appendActions(newAct); } foreach (Action action in subStep.Actions) { Action newAct = (Action)action.Duplicate(); newSubStep.appendActions(newAct); Review(newAct); } foreach (Expectation expectation in subStep.Expectations) { Expectation newExp = (Expectation)expectation.Duplicate(); newSubStep.appendExpectations(newExp); Review(newExp); } } subStepCounter++; } }
private void intializeEFS(TestCase aTestCase, Workbook workbook) { Step aStep = new Step(); aStep.Name = "Step1 - Setup"; aTestCase.AddModelElement(aStep); SubStep aSubStep = new SubStep(); aSubStep.Name = "SubStep1 - Setup"; aSubStep.setSkipEngine(true); aStep.AddModelElement(aSubStep); TestAction powerOn = new TestAction(); powerOn.ExpressionText = "Kernel.PowerOn <- True"; aSubStep.AddModelElement(powerOn); TestAction modeInitialization = new TestAction(); modeInitialization.ExpressionText = "Kernel.Mode <- Mode.FS"; aSubStep.AddModelElement(modeInitialization); TestAction levelInitialization = new TestAction(); levelInitialization.ExpressionText = "Kernel.Level <- Kernel.LevelData\n{\n Value => LevelDataStruct { Value => Level.L1 },\n DataState => DataState.Valid\n}"; aSubStep.AddModelElement(levelInitialization); TestAction odometryInitialization = new TestAction(); odometryInitialization.ExpressionText = "Odometry.NominalDistance <- 0.0"; aSubStep.AddModelElement(odometryInitialization); TestAction LRBGInitialization = new TestAction(); LRBGInitialization.ExpressionText = "BTM.LRBG <- BTM.BaliseGroupStruct{\n" + " NID => 0,\n" + " Orientation => Default.Orientation.Nominal,\n" + " Position => BTM.Position{\n" + " Position => 0.0,\n" + " UnderReadingAmountOdo => 0.0,\n" + " OverReadingAmountOdo => 0.0\n" + " },\n" + " Timestamp => Default.DateAndTime{\n" + " Year => 2012,\n" + " Month => 12,\n" + " Day => 20,\n" + " Hour => 20,\n" + " Minute => 12,\n" + " Second => 20,\n" + " TTS => 600\n" + " }\n" + "}"; aSubStep.AddModelElement(LRBGInitialization); }
private void addAction(SubStep aSubStep, string expression) { TestAction anAction = new TestAction(); anAction.ExpressionText = expression; aSubStep.AddModelElement(anAction); }
public void AddHandler(object sender, EventArgs args) { DataDictionary.Rules.Action action = (DataDictionary.Rules.Action)DataDictionary.Generated.acceptor.getFactory().createAction(); action.Expression = ""; AddAction(action); }
/// <summary> /// Adds an action /// </summary> /// <param name="action"></param> /// <returns></returns> public virtual ActionTreeNode AddAction(DataDictionary.Rules.Action action) { return(Actions.AddAction(action)); }
private void intializeEFS(TestCase aTestCase, Workbook workbook) { Step aStep = new Step(); aStep.Name = "Step1 - Setup"; aTestCase.AddModelElement(aStep); SubStep aSubStep = new SubStep(); aSubStep.Name = "SubStep1 - Setup"; aSubStep.setSkipEngine(true); aStep.AddModelElement(aSubStep); TestAction levelInitialization = new TestAction(); levelInitialization.Expression = "Kernel.Level <- Kernel.LevelData\n{\n Value => Level.L1,\n DataState => DataState.Valid\n}"; aSubStep.AddModelElement(levelInitialization); TestAction odometryInitialization = new TestAction(); odometryInitialization.Expression = "Odometry.NominalDistance <- 0.0"; aSubStep.AddModelElement(odometryInitialization); }