SceneObjectUndoRedoTests.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /*
  2. * Copyright (c) Contributors, http://opensimulator.org/
  3. * See CONTRIBUTORS.TXT for a full list of copyright holders.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. * * Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * * Neither the name of the OpenSimulator Project nor the
  13. * names of its contributors may be used to endorse or promote products
  14. * derived from this software without specific prior written permission.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
  17. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  18. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  19. * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
  20. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  21. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  23. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  24. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  25. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. */
  27. using System;
  28. using System.Reflection;
  29. using NUnit.Framework;
  30. using OpenMetaverse;
  31. using OpenSim.Framework;
  32. using OpenSim.Framework.Communications;
  33. using OpenSim.Region.Framework.Scenes;
  34. using OpenSim.Tests.Common;
  35. using OpenSim.Tests.Common.Mock;
  36. namespace OpenSim.Region.Framework.Scenes.Tests
  37. {
  38. /// <summary>
  39. /// Tests for undo/redo
  40. /// </summary>
  41. public class SceneObjectUndoRedoTests : OpenSimTestCase
  42. {
  43. [Test]
  44. public void TestUndoRedoResizeSceneObject()
  45. {
  46. TestHelpers.InMethod();
  47. // TestHelpers.EnableLogging();
  48. Vector3 firstSize = new Vector3(2, 3, 4);
  49. Vector3 secondSize = new Vector3(5, 6, 7);
  50. Scene scene = new SceneHelpers().SetupScene();
  51. scene.MaxUndoCount = 20;
  52. SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene);
  53. // TODO: It happens to be the case that we are not storing undo states for SOPs which are not yet in a SOG,
  54. // which is the way that AddSceneObject() sets up the object (i.e. it creates the SOP first). However,
  55. // this is somewhat by chance. Really, we shouldn't be storing undo states at all if the object is not
  56. // in a scene.
  57. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0));
  58. g1.GroupResize(firstSize);
  59. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(1));
  60. g1.GroupResize(secondSize);
  61. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(2));
  62. g1.RootPart.Undo();
  63. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(1));
  64. Assert.That(g1.GroupScale, Is.EqualTo(firstSize));
  65. g1.RootPart.Redo();
  66. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(2));
  67. Assert.That(g1.GroupScale, Is.EqualTo(secondSize));
  68. }
  69. [Test]
  70. public void TestUndoLimit()
  71. {
  72. TestHelpers.InMethod();
  73. Vector3 firstSize = new Vector3(2, 3, 4);
  74. Vector3 secondSize = new Vector3(5, 6, 7);
  75. Vector3 thirdSize = new Vector3(8, 9, 10);
  76. Vector3 fourthSize = new Vector3(11, 12, 13);
  77. Scene scene = new SceneHelpers().SetupScene();
  78. scene.MaxUndoCount = 2;
  79. SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene);
  80. g1.GroupResize(firstSize);
  81. g1.GroupResize(secondSize);
  82. g1.GroupResize(thirdSize);
  83. g1.GroupResize(fourthSize);
  84. g1.RootPart.Undo();
  85. g1.RootPart.Undo();
  86. g1.RootPart.Undo();
  87. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0));
  88. Assert.That(g1.GroupScale, Is.EqualTo(secondSize));
  89. }
  90. [Test]
  91. public void TestNoUndoOnObjectsNotInScene()
  92. {
  93. TestHelpers.InMethod();
  94. Vector3 firstSize = new Vector3(2, 3, 4);
  95. Vector3 secondSize = new Vector3(5, 6, 7);
  96. // Vector3 thirdSize = new Vector3(8, 9, 10);
  97. // Vector3 fourthSize = new Vector3(11, 12, 13);
  98. Scene scene = new SceneHelpers().SetupScene();
  99. scene.MaxUndoCount = 20;
  100. SceneObjectGroup g1 = SceneHelpers.CreateSceneObject(1, TestHelpers.ParseTail(0x1));
  101. g1.GroupResize(firstSize);
  102. g1.GroupResize(secondSize);
  103. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0));
  104. g1.RootPart.Undo();
  105. Assert.That(g1.GroupScale, Is.EqualTo(secondSize));
  106. }
  107. [Test]
  108. public void TestUndoBeyondAvailable()
  109. {
  110. TestHelpers.InMethod();
  111. Vector3 newSize = new Vector3(2, 3, 4);
  112. Scene scene = new SceneHelpers().SetupScene();
  113. scene.MaxUndoCount = 20;
  114. SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene);
  115. Vector3 originalSize = g1.GroupScale;
  116. g1.RootPart.Undo();
  117. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0));
  118. Assert.That(g1.GroupScale, Is.EqualTo(originalSize));
  119. g1.GroupResize(newSize);
  120. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(1));
  121. Assert.That(g1.GroupScale, Is.EqualTo(newSize));
  122. g1.RootPart.Undo();
  123. g1.RootPart.Undo();
  124. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0));
  125. Assert.That(g1.GroupScale, Is.EqualTo(originalSize));
  126. }
  127. [Test]
  128. public void TestRedoBeyondAvailable()
  129. {
  130. TestHelpers.InMethod();
  131. Vector3 newSize = new Vector3(2, 3, 4);
  132. Scene scene = new SceneHelpers().SetupScene();
  133. scene.MaxUndoCount = 20;
  134. SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene);
  135. Vector3 originalSize = g1.GroupScale;
  136. g1.RootPart.Redo();
  137. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0));
  138. Assert.That(g1.GroupScale, Is.EqualTo(originalSize));
  139. g1.GroupResize(newSize);
  140. g1.RootPart.Undo();
  141. g1.RootPart.Redo();
  142. g1.RootPart.Redo();
  143. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(1));
  144. Assert.That(g1.GroupScale, Is.EqualTo(newSize));
  145. }
  146. }
  147. }