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. /* undo has changed, this tests dont apply without large changes
  28. using System;
  29. using System.Reflection;
  30. using NUnit.Framework;
  31. using OpenMetaverse;
  32. using OpenSim.Framework;
  33. using OpenSim.Region.Framework.Scenes;
  34. using OpenSim.Tests.Common;
  35. namespace OpenSim.Region.Framework.Scenes.Tests
  36. {
  37. /// <summary>
  38. /// Tests for undo/redo
  39. /// </summary>
  40. public class SceneObjectUndoRedoTests : OpenSimTestCase
  41. {
  42. [Test]
  43. public void TestUndoRedoResizeSceneObject()
  44. {
  45. TestHelpers.InMethod();
  46. // TestHelpers.EnableLogging();
  47. Vector3 firstSize = new Vector3(2, 3, 4);
  48. Vector3 secondSize = new Vector3(5, 6, 7);
  49. Scene scene = new SceneHelpers().SetupScene();
  50. scene.MaxUndoCount = 20;
  51. SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene);
  52. // TODO: It happens to be the case that we are not storing undo states for SOPs which are not yet in a SOG,
  53. // which is the way that AddSceneObject() sets up the object (i.e. it creates the SOP first). However,
  54. // this is somewhat by chance. Really, we shouldn't be storing undo states at all if the object is not
  55. // in a scene.
  56. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0));
  57. g1.GroupResize(firstSize);
  58. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(1));
  59. g1.GroupResize(secondSize);
  60. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(2));
  61. g1.RootPart.Undo();
  62. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(1));
  63. Assert.That(g1.GroupScale, Is.EqualTo(firstSize));
  64. g1.RootPart.Redo();
  65. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(2));
  66. Assert.That(g1.GroupScale, Is.EqualTo(secondSize));
  67. }
  68. [Test]
  69. public void TestUndoLimit()
  70. {
  71. TestHelpers.InMethod();
  72. Vector3 firstSize = new Vector3(2, 3, 4);
  73. Vector3 secondSize = new Vector3(5, 6, 7);
  74. Vector3 thirdSize = new Vector3(8, 9, 10);
  75. Vector3 fourthSize = new Vector3(11, 12, 13);
  76. Scene scene = new SceneHelpers().SetupScene();
  77. scene.MaxUndoCount = 2;
  78. SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene);
  79. g1.GroupResize(firstSize);
  80. g1.GroupResize(secondSize);
  81. g1.GroupResize(thirdSize);
  82. g1.GroupResize(fourthSize);
  83. g1.RootPart.Undo();
  84. g1.RootPart.Undo();
  85. g1.RootPart.Undo();
  86. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0));
  87. Assert.That(g1.GroupScale, Is.EqualTo(secondSize));
  88. }
  89. [Test]
  90. public void TestNoUndoOnObjectsNotInScene()
  91. {
  92. TestHelpers.InMethod();
  93. Vector3 firstSize = new Vector3(2, 3, 4);
  94. Vector3 secondSize = new Vector3(5, 6, 7);
  95. // Vector3 thirdSize = new Vector3(8, 9, 10);
  96. // Vector3 fourthSize = new Vector3(11, 12, 13);
  97. Scene scene = new SceneHelpers().SetupScene();
  98. scene.MaxUndoCount = 20;
  99. SceneObjectGroup g1 = SceneHelpers.CreateSceneObject(1, TestHelpers.ParseTail(0x1));
  100. g1.GroupResize(firstSize);
  101. g1.GroupResize(secondSize);
  102. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0));
  103. g1.RootPart.Undo();
  104. Assert.That(g1.GroupScale, Is.EqualTo(secondSize));
  105. }
  106. [Test]
  107. public void TestUndoBeyondAvailable()
  108. {
  109. TestHelpers.InMethod();
  110. Vector3 newSize = new Vector3(2, 3, 4);
  111. Scene scene = new SceneHelpers().SetupScene();
  112. scene.MaxUndoCount = 20;
  113. SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene);
  114. Vector3 originalSize = g1.GroupScale;
  115. g1.RootPart.Undo();
  116. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0));
  117. Assert.That(g1.GroupScale, Is.EqualTo(originalSize));
  118. g1.GroupResize(newSize);
  119. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(1));
  120. Assert.That(g1.GroupScale, Is.EqualTo(newSize));
  121. g1.RootPart.Undo();
  122. g1.RootPart.Undo();
  123. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0));
  124. Assert.That(g1.GroupScale, Is.EqualTo(originalSize));
  125. }
  126. [Test]
  127. public void TestRedoBeyondAvailable()
  128. {
  129. TestHelpers.InMethod();
  130. Vector3 newSize = new Vector3(2, 3, 4);
  131. Scene scene = new SceneHelpers().SetupScene();
  132. scene.MaxUndoCount = 20;
  133. SceneObjectGroup g1 = SceneHelpers.AddSceneObject(scene);
  134. Vector3 originalSize = g1.GroupScale;
  135. g1.RootPart.Redo();
  136. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(0));
  137. Assert.That(g1.GroupScale, Is.EqualTo(originalSize));
  138. g1.GroupResize(newSize);
  139. g1.RootPart.Undo();
  140. g1.RootPart.Redo();
  141. g1.RootPart.Redo();
  142. Assert.That(g1.RootPart.UndoCount, Is.EqualTo(1));
  143. Assert.That(g1.GroupScale, Is.EqualTo(newSize));
  144. }
  145. }
  146. }
  147. */