Exemplo n.º 1
0
        public void TestEditingStackOperations()
        {
            var commands = new XTMFCommand[20];

            for (int i = 0; i < commands.Length; i++)
            {
                commands[i] = new TestCommand();
            }
            EditingStack stack = new EditingStack(10);

            Assert.AreEqual(0, stack.Count, "The stack's count is incorrect!");
            // fill the stack
            for (int i = 0; i < 10; i++)
            {
                stack.Add(commands[i]);
                Assert.AreEqual(i + 1, stack.Count, "The stack's count is incorrect!");
            }
            // over fill the stack
            for (int i = 10; i < 20; i++)
            {
                stack.Add(commands[i]);
                Assert.AreEqual(10, stack.Count, "The stack's count is incorrect!");
            }
            // Make sure the first don't exist anymore
            for (int i = 0; i < 10; i++)
            {
                Assert.AreEqual(false, stack.Contains(commands[i]), "The stack retained a command it should have lost!");
            }
            // Make sure the newer ones still exist
            for (int i = 10; i < 20; i++)
            {
                Assert.AreEqual(true, stack.Contains(commands[i]), "The stack lost a command it should have retained!");
            }
            XTMFCommand command;

            for (int i = 19; i >= 10; i--)
            {
                if (stack.TryPop(out command))
                {
                    Assert.AreEqual(commands[i], command, "While popping we popped an unexpected command!");
                }
                else
                {
                    Assert.Fail("A pop failed that should have succeeded!");
                }
            }
        }
Exemplo n.º 2
0
 public void TestEditingStackOperations()
 {
     var commands = new XTMFCommand[20];
     for ( int i = 0; i < commands.Length; i++ )
     {
         commands[i] = new TestCommand();
     }
     EditingStack stack = new EditingStack( 10 );
     Assert.AreEqual( 0, stack.Count, "The stack's count is incorrect!" );
     // fill the stack
     for ( int i = 0; i < 10; i++ )
     {
         stack.Add( commands[i] );
         Assert.AreEqual( i + 1, stack.Count, "The stack's count is incorrect!" );
     }
     // over fill the stack
     for ( int i = 10; i < 20; i++ )
     {
         stack.Add( commands[i] );
         Assert.AreEqual( 10, stack.Count, "The stack's count is incorrect!" );
     }
     // Make sure the first don't exist anymore
     for ( int i = 0; i < 10; i++ )
     {
         Assert.AreEqual( false, stack.Contains( commands[i] ), "The stack retained a command it should have lost!" );
     }
     // Make sure the newer ones still exist
     for ( int i = 10; i < 20; i++ )
     {
         Assert.AreEqual( true, stack.Contains( commands[i] ), "The stack lost a command it should have retained!" );
     }
     XTMFCommand command;
     for ( int i = 19; i >= 10; i-- )
     {
         if ( stack.TryPop( out command ) )
         {
             Assert.AreEqual( commands[i], command, "While popping we popped an unexpected command!" );
         }
         else
         {
             Assert.Fail( "A pop failed that should have succeeded!" );
         }
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Redo the last undone command
 /// </summary>
 /// <param name="error">The reason why it failed</param>
 public bool Redo(ref string error)
 {
     lock (SessionLock)
     {
         XTMFCommand command;
         if (RedoStack.TryPop(out command))
         {
             if (command != null)
             {
                 if (command.Redo(ref error))
                 {
                     HasChanged = true;
                     UndoStack.Add(command);
                     return(true);
                 }
                 return(false);
             }
         }
         error = "There was nothing to redo.";
         return(false);
     }
 }