예제 #1
0
        public void GenerateUpdateDeleteEquivalence()
        {
            CompoundEdit ce = new CompoundEdit();

            IGenerator gen = new PermutationCombinationsGenerator(dep, 80000, CombinationsGenerationOption.OVERWRITE);

            ce.AddEdit(gen.Generate());
            //deleting an equivalence
            IGenerator genUpdater = new PermutationCombinationsGenerator(dep, 80000, CombinationsGenerationOption.UPDATE);

            ce.AddEdit(EditFactory.instance.CreateRemoveEquivalenceClassEdit(dep, eq12));
            dep.RemoveEquivalenceClass(eq12);
            ce.AddEdit(genUpdater.Generate());
            Assert.AreEqual(18, dep.Combinations.Count);

            Assert.AreEqual(10, dep.Combinations[9].Position);
            Assert.IsTrue(dep.Combinations[9].EquivalenceClasses.Contains(eq13));
            Assert.IsTrue(dep.Combinations[9].EquivalenceClasses.Contains(eq21));
            Assert.IsTrue(dep.Combinations[9].EquivalenceClasses.Contains(eq31));
            //add a new equivalence
            ce.AddEdit(EditFactory.instance.CreateRemoveEquivalenceClassEdit(dep, eq24));
            dep.AddEquivalenceClass(eq24);
            ce.AddEdit(genUpdater.Generate());
            Assert.AreEqual(24, dep.Combinations.Count);
            Assert.AreEqual(10, dep.Combinations[9].Position);
            Assert.IsTrue(dep.Combinations[9].EquivalenceClasses.Contains(eq11));
            Assert.IsTrue(dep.Combinations[9].EquivalenceClasses.Contains(eq24));
            Assert.IsTrue(dep.Combinations[9].EquivalenceClasses.Contains(eq31));
            ce.EndAllEdits();
            ce.Undo();
            Assert.IsTrue(dep.Combinations.Count == 0);
        }
        public void GenerateOverwrite()
        {
            CompoundEdit           ce  = new CompoundEdit();
            ICombinationsGenerator gen = new AllPairsCombinationsGenerator(dep, 80000, CombinationsGenerationOption.OVERWRITE);

            ce.AddEdit(gen.Generate());

            Assert.AreEqual(10, dep.Combinations.Count);
            Assert.AreEqual(1, dep.Combinations[0].Position);
            Assert.IsTrue(dep.Combinations[0].EquivalenceClasses.Contains(eq11));
            Assert.IsTrue(dep.Combinations[0].EquivalenceClasses.Contains(eq21));
            Assert.IsTrue(dep.Combinations[0].EquivalenceClasses.Contains(eq31));

            Assert.AreEqual(2, dep.Combinations[1].Position);
            Assert.IsTrue(dep.Combinations[1].EquivalenceClasses.Contains(eq11));
            Assert.IsTrue(dep.Combinations[1].EquivalenceClasses.Contains(eq22));
            Assert.IsTrue(dep.Combinations[1].EquivalenceClasses.Contains(eq32));

            //Assert.AreEqual(3, dep.Combinations[2].Position);
            //Assert.IsTrue(dep.Combinations[2].EquivalenceClasses.Contains(eq11));
            //Assert.IsTrue(dep.Combinations[2].EquivalenceClasses.Contains(eq23));
            //Assert.IsTrue(dep.Combinations[2].EquivalenceClasses.Contains(eq33));

            //Assert.AreEqual(7, dep.Combinations[6].Position);
            //Assert.IsTrue(dep.Combinations[6].EquivalenceClasses.Contains(eq12));
            //Assert.IsTrue(dep.Combinations[6].EquivalenceClasses.Contains(eq22));
            //Assert.IsTrue(dep.Combinations[6].EquivalenceClasses.Contains(eq33));

            ce.EndAllEdits();
            ce.Undo();
            Assert.IsTrue(dep.Combinations.Count == 0);
        }
예제 #3
0
        public void GenerateOverwrite()
        {
            CompoundEdit ce  = new CompoundEdit();
            IGenerator   gen = new PermutationCombinationsGenerator(dep, 80000, CombinationsGenerationOption.OVERWRITE);

            ce.AddEdit(gen.Generate());

            Assert.AreEqual(27, dep.Combinations.Count);
            Assert.AreEqual(1, dep.Combinations[0].Position);
            Assert.IsTrue(dep.Combinations[0].EquivalenceClasses.Contains(eq11));
            Assert.IsTrue(dep.Combinations[0].EquivalenceClasses.Contains(eq21));
            Assert.IsTrue(dep.Combinations[0].EquivalenceClasses.Contains(eq31));

            Assert.AreEqual(2, dep.Combinations[1].Position);
            Assert.IsTrue(dep.Combinations[1].EquivalenceClasses.Contains(eq11));
            Assert.IsTrue(dep.Combinations[1].EquivalenceClasses.Contains(eq21));
            Assert.IsTrue(dep.Combinations[1].EquivalenceClasses.Contains(eq32));

            Assert.AreEqual(19, dep.Combinations[18].Position);
            Assert.IsTrue(dep.Combinations[18].EquivalenceClasses.Contains(eq13));
            Assert.IsTrue(dep.Combinations[18].EquivalenceClasses.Contains(eq21));
            Assert.IsTrue(dep.Combinations[18].EquivalenceClasses.Contains(eq31));

            ce.EndAllEdits();
            ce.Undo();
            Assert.IsTrue(dep.Combinations.Count == 0);
        }
예제 #4
0
        public void BasicFunctionality()
        {
            IEditFactory fact = EditFactory.instance;
            Element      elem = new Element();

            EquivalenceClass equivalenceClass = new EquivalenceClass();
            Effect           effect           = new Effect();

            ce.AddEdit(fact.CreateAddEquivalenceClassEdit(elem, equivalenceClass));
            elem.AddEquivalenceClass(equivalenceClass);
            ce.AddEdit(fact.CreateAddEffectEdit(equivalenceClass, effect));
            equivalenceClass.AddEffect(effect);
            Assert.IsFalse(ce.CanUndo());
            Assert.IsFalse(ce.CanRedo());
            //finalize all edits so it can be undoed
            ce.EndAllEdits();
            Assert.IsTrue(ce.CanUndo());
            Assert.IsFalse(ce.CanRedo());
            ce.Undo();
            Assert.IsFalse(equivalenceClass.Effects.Contains(effect));
            Assert.IsFalse(elem.EquivalenceClasses.Contains(equivalenceClass));
            ce.Redo();
            Assert.IsTrue(equivalenceClass.Effects.Contains(effect));
            Assert.IsTrue(elem.EquivalenceClasses.Contains(equivalenceClass));

            ce.Die();
            Assert.IsFalse(ce.CanUndo());
            Assert.IsFalse(ce.CanRedo());
        }
        public virtual IUndoableEdit Generate()
        {
            ValidateModel();
            CompoundEdit     ce    = new CompoundEdit();
            IPolicyFactory   pfact = new PolicyFactory();
            IList <TestCase> generatedTestCases = new List <TestCase>();

            //generate the test cases
            ce.AddEdit(FillTestCases(generatedTestCases));
            //delete the common test cases from the structure
            ce.AddEdit(pfact.DeleteCommonTestCasesPolicy(structure, genState, dependencies));
            if (generatedTestCases.Count + structure.GetTestCases(genState).Count > maxTestCases)
            {
                ce.EndAllEdits();
                ce.Undo();
                throw new Exception("Maximal number of " + EntityWithEvents.GetDescription(genState) + " Test Cases reached");
            }

            //add the new generated test cases
            foreach (TestCase tc in generatedTestCases)
            {
                //check if the structure has the same test cases before insert
                if (!structure.ContainsSameTestCaseByRelations(tc))
                {
                    ce.AddEdit(EditFactory.instance.CreateChangePropertyEdit(tc, "Position", structure.GetNewTestCasePosition()));
                    tc.Position = structure.GetNewTestCasePosition();
                    ce.AddEdit(EditFactory.instance.CreateAddTestCaseEdit(structure, tc));
                    structure.AddTestCase(tc);
                }
            }
            return(ce);
        }
예제 #6
0
        public void DeleteCombination()
        {
            CombinationManager man = new CombinationManager(combi4);
            CompoundEdit       ce  = (CompoundEdit)man.DeleteCombination(structure);

            ce.EndAllEdits();
            Assert.IsFalse(test1.Combinations.Contains(combi4));
            Assert.IsFalse(test2.Combinations.Contains(combi4));
            Assert.IsFalse(dep.Combinations.Contains(combi4));
            ce.Undo();
            Assert.IsTrue(test1.Combinations.Contains(combi4));
            Assert.IsTrue(test2.Combinations.Contains(combi4));
            Assert.IsTrue(dep.Combinations.Contains(combi4));
        }
        public void DeleteCommonTestCases()
        {
            StructureManager  man  = new StructureManager(structure);
            List <Dependency> deps = new List <Dependency>();

            deps.Add(dep3);
            deps.Add(dep2);
            CompoundEdit ce = (CompoundEdit)man.DeleteCommonTestCases(State.POSITIVE, deps);

            Assert.IsTrue(structure.TestCases.Contains(test4));
            Assert.AreEqual(structure.TestCases.Count, 1);
            ce.EndAllEdits();
            ce.Undo();
        }
        public void DeleteAllCombinations()
        {
            DependencyManager man = new DependencyManager(dep);
            CompoundEdit      ce  = (CompoundEdit)man.DeleteAllCombinations();

            ce.EndAllEdits();
            Assert.IsFalse(test1.Combinations.Contains(combi4));
            Assert.IsFalse(test2.Combinations.Contains(combi3));
            Assert.IsFalse(dep.Combinations.Contains(combi4));
            Assert.IsFalse(dep.Combinations.Contains(combi2));
            Assert.IsFalse(dep.Combinations.Contains(combi1));
            Assert.IsFalse(dep.Combinations.Contains(combi3));
            ce.Undo();
            Assert.IsTrue(test1.Combinations.Contains(combi4));
            Assert.IsTrue(test2.Combinations.Contains(combi3));
            Assert.IsTrue(dep.Combinations.Contains(combi4));
            Assert.IsTrue(dep.Combinations.Contains(combi2));
            Assert.IsTrue(dep.Combinations.Contains(combi1));
            Assert.IsTrue(dep.Combinations.Contains(combi3));
        }
예제 #9
0
        /// <summary>
        /// Stop the current transaction, either rolling it back or committing it.
        /// </summary>
        /// <param name="commit">true to terminate the transaction normally;
        /// false to abort it and rollback the existing edits</param>
        /// <param name="tname">the internal locale-neutral name for the transaction</param>
        /// <returns>true for a committed top-level transaction</returns>
        /// <remarks>
        /// <para>
        /// If this call stops a top-level transaction, a value of false for
        /// <paramref name="commit"/> just undoes and discards the information in the
        /// <see cref="CurrentEdit"/>.
        /// If <paramref name="commit"/> is true for a top-level transaction,
        /// we mark the <see cref="CurrentEdit"/> complete,
        /// call <see cref="CommitCompoundEdit"/>,
        /// and add the resulting <see cref="UndoManager.CompoundEdit"/>
        /// to the list of compound edits that this undo manager is recording.
        /// </para>
        /// <para>
        /// Committing a transaction when there have been some undos without
        /// corresponding redos will throw away the compound edits holding
        /// changes that happened after the current state, before adding this
        /// new compound edit to the undo manager's list of edits.
        /// </para>
        /// <para>
        /// This method raises a <see cref="IDiagramModel.Changed"/> event
        /// for each of this undo manager's <see cref="Models"/>,
        /// with a hint of <see cref="ModelChange.CommittedTransaction"/>,
        /// and with a <see cref="ModelChangedEventArgs.OldValue"/>
        /// that is the <see cref="UndoManager.CompoundEdit"/>
        /// that has been added to the list of <see cref="CompoundEdits"/>.
        /// Similarly, if the transaction is aborted, either because <paramref name="commit"/>
        /// is false or because there is no <see cref="CurrentEdit"/> to commit,
        /// all of the <see cref="Models"/> get a <see cref="ModelChange.RolledBackTransaction"/>
        /// Changed event.  The values passed in the <see cref="ModelChangedEventArgs"/>
        /// may all be null, however.
        /// </para>
        /// </remarks>
        protected virtual bool EndTransaction(bool commit, String tname)
        {
            if (this.IsUndoingRedoing)
            {
                return(false);
            }
            bool toplevel = (this.TransactionLevel == 1);
            int  start    = 0;

            // decrement the transaction level, but not below zero
            if (this.TransactionLevel > 0)
            {
                this.TransactionLevel--;
                int numnames = this.NestedTransactionNames.Count;
                if (numnames > 0)
                {
                    if (tname == null)
                    {
                        tname = this.NestedTransactionNames[0];
                    }
                    this.NestedTransactionNames.RemoveAt(numnames - 1);
                }
                int numstarts = this.NestedTransactionStarts.Count;
                if (numstarts > 0)
                {
                    start = this.NestedTransactionStarts[numstarts - 1];
                    this.NestedTransactionStarts.RemoveAt(numstarts - 1);
                }
            }
            if (tname == null)
            {
                tname = "";
            }
            CompoundEdit current = this.CurrentEdit;

            //Diagram.Debug(this.TransactionLevel, (commit ? "commit: " : "rollback: ") + (tname != "" ? tname : "(unknown)") + " " +
            //  (current != null ? current.Edits.Count.ToString() : "(no CEdit)") + " " + this.CompoundEdits.Count.ToString());
            if (toplevel)
            {
                if (commit)
                {
                    // finish the current edit
                    CompoundEdit cedit = CommitCompoundEdit(current);
                    if (cedit != null)
                    {
                        cedit.IsComplete = true;
                        cedit.Name       = tname;
                        // throw away any compound edits following the current index
                        for (int i = this.CompoundEdits.Count - 1; i > this.UndoEditIndex; i--)
                        {
                            this.CompoundEdits[i].Clear();
                            this.CompoundEdits.RemoveAt(i);
                        }
                        // if there is a limit, just throw away the oldest edit
                        int max = this.MaximumEditCount;
                        if (max == 0)
                        {
                            max = 1;
                        }
                        if (max > 0)
                        {
                            if (this.CompoundEdits.Count >= max)
                            {
                                this.CompoundEdits[0].Clear();
                                this.CompoundEdits.RemoveAt(0);
                                this.UndoEditIndex--;
                            }
                        }
                        // add to CompoundEdits list
                        this.CompoundEdits.Add(cedit);
                        this.UndoEditIndex++;
                    }
                    // notify all models
                    foreach (IDiagramModel model in this.ModelsList)
                    {
                        RaiseChanged(model, ModelChange.CommittedTransaction, tname, cedit, null);
                    }
                }
                else // !commit
                // rollback the current compound edit by undoing all of its edits
                {
                    if (current != null)
                    {
                        try {
                            current.IsComplete    = true;
                            this.IsUndoingRedoing = true;
                            current.Undo();
                        } finally {
                            this.IsUndoingRedoing = false;
                        }
                    }
                    foreach (IDiagramModel model in this.ModelsList)
                    {
                        RaiseChanged(model, ModelChange.RolledBackTransaction, tname, current, null);
                    }
                    // now we can throw away all those undone edits
                    if (current != null)
                    {
                        current.Clear();
                    }
                }
                this.CurrentEdit = null;
                return(true);
            }
            else // !toplevel
            // rollback the current edit by undoing all of its edits, but not of parent edits
            {
                if (!commit && current != null)
                {
                    current.RollbackTo(start);
                }
                return(false);
            }
        }
예제 #10
0
        public void CreateChangePropertyEditTest()
        {
            Element element = new Element();
            string  name2   = "Name 2";

            element.Name = "Name 1";
            ce.AddEdit(EditFactory.instance.CreateChangePropertyEdit(element, "Name", name2));
            element.Name = name2;
            ce.End();
            ce.Undo();
            Assert.AreEqual(element.Name, "Name 1");
            ce.Redo();
            Assert.AreEqual(element.Name, "Name 2");
        }