VectorRenderModuleTests.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  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.Collections.Generic;
  29. using System.IO;
  30. using System.Reflection;
  31. using System.Threading;
  32. using log4net.Config;
  33. using NUnit.Framework;
  34. using OpenMetaverse;
  35. using OpenMetaverse.Assets;
  36. using OpenSim.Framework;
  37. using OpenSim.Region.CoreModules.Scripting.DynamicTexture;
  38. using OpenSim.Region.CoreModules.Scripting.VectorRender;
  39. using OpenSim.Region.Framework.Scenes;
  40. using OpenSim.Region.Framework.Scenes.Serialization;
  41. using OpenSim.Tests.Common;
  42. namespace OpenSim.Region.CoreModules.Scripting.VectorRender.Tests
  43. {
  44. [TestFixture]
  45. public class VectorRenderModuleTests : OpenSimTestCase
  46. {
  47. Scene m_scene;
  48. DynamicTextureModule m_dtm;
  49. VectorRenderModule m_vrm;
  50. private void SetupScene(bool reuseTextures)
  51. {
  52. m_scene = new SceneHelpers().SetupScene();
  53. m_dtm = new DynamicTextureModule();
  54. m_dtm.ReuseTextures = reuseTextures;
  55. // m_dtm.ReuseLowDataTextures = reuseTextures;
  56. m_vrm = new VectorRenderModule();
  57. SceneHelpers.SetupSceneModules(m_scene, m_dtm, m_vrm);
  58. }
  59. [Test]
  60. public void TestDraw()
  61. {
  62. TestHelpers.InMethod();
  63. SetupScene(false);
  64. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  65. UUID originalTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  66. m_dtm.AddDynamicTextureData(
  67. m_scene.RegionInfo.RegionID,
  68. so.UUID,
  69. m_vrm.GetContentType(),
  70. "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;",
  71. "");
  72. Assert.That(originalTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  73. }
  74. [Test]
  75. public void TestRepeatSameDraw()
  76. {
  77. TestHelpers.InMethod();
  78. string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;";
  79. SetupScene(false);
  80. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  81. m_dtm.AddDynamicTextureData(
  82. m_scene.RegionInfo.RegionID,
  83. so.UUID,
  84. m_vrm.GetContentType(),
  85. dtText,
  86. "");
  87. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  88. m_dtm.AddDynamicTextureData(
  89. m_scene.RegionInfo.RegionID,
  90. so.UUID,
  91. m_vrm.GetContentType(),
  92. dtText,
  93. "");
  94. Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  95. }
  96. [Test]
  97. public void TestRepeatSameDrawDifferentExtraParams()
  98. {
  99. TestHelpers.InMethod();
  100. string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;";
  101. SetupScene(false);
  102. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  103. m_dtm.AddDynamicTextureData(
  104. m_scene.RegionInfo.RegionID,
  105. so.UUID,
  106. m_vrm.GetContentType(),
  107. dtText,
  108. "");
  109. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  110. m_dtm.AddDynamicTextureData(
  111. m_scene.RegionInfo.RegionID,
  112. so.UUID,
  113. m_vrm.GetContentType(),
  114. dtText,
  115. "alpha:250");
  116. Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  117. }
  118. [Test]
  119. public void TestRepeatSameDrawContainingImage()
  120. {
  121. TestHelpers.InMethod();
  122. string dtText
  123. = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World; Image http://0.0.0.0/shouldnotexist.png";
  124. SetupScene(false);
  125. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  126. m_dtm.AddDynamicTextureData(
  127. m_scene.RegionInfo.RegionID,
  128. so.UUID,
  129. m_vrm.GetContentType(),
  130. dtText,
  131. "");
  132. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  133. m_dtm.AddDynamicTextureData(
  134. m_scene.RegionInfo.RegionID,
  135. so.UUID,
  136. m_vrm.GetContentType(),
  137. dtText,
  138. "");
  139. Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  140. }
  141. [Test]
  142. public void TestDrawReusingTexture()
  143. {
  144. TestHelpers.InMethod();
  145. SetupScene(true);
  146. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  147. UUID originalTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  148. m_dtm.AddDynamicTextureData(
  149. m_scene.RegionInfo.RegionID,
  150. so.UUID,
  151. m_vrm.GetContentType(),
  152. "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;",
  153. "");
  154. Assert.That(originalTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  155. }
  156. [Test]
  157. public void TestRepeatSameDrawReusingTexture()
  158. {
  159. TestHelpers.InMethod();
  160. // TestHelpers.EnableLogging();
  161. string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;";
  162. SetupScene(true);
  163. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  164. m_dtm.AddDynamicTextureData(
  165. m_scene.RegionInfo.RegionID,
  166. so.UUID,
  167. m_vrm.GetContentType(),
  168. dtText,
  169. "");
  170. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  171. m_dtm.AddDynamicTextureData(
  172. m_scene.RegionInfo.RegionID,
  173. so.UUID,
  174. m_vrm.GetContentType(),
  175. dtText,
  176. "");
  177. Assert.That(firstDynamicTextureID, Is.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  178. }
  179. /// <summary>
  180. /// Test a low data dynamically generated texture such that it is treated as a low data texture that causes
  181. /// problems for current viewers.
  182. /// </summary>
  183. /// <remarks>
  184. /// As we do not set DynamicTextureModule.ReuseLowDataTextures = true in this test, it should not reuse the
  185. /// texture
  186. /// </remarks>
  187. [Test]
  188. public void TestRepeatSameDrawLowDataTexture()
  189. {
  190. TestHelpers.InMethod();
  191. // TestHelpers.EnableLogging();
  192. string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;";
  193. SetupScene(true);
  194. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  195. m_dtm.AddDynamicTextureData(
  196. m_scene.RegionInfo.RegionID,
  197. so.UUID,
  198. m_vrm.GetContentType(),
  199. dtText,
  200. "1024");
  201. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  202. m_dtm.AddDynamicTextureData(
  203. m_scene.RegionInfo.RegionID,
  204. so.UUID,
  205. m_vrm.GetContentType(),
  206. dtText,
  207. "1024");
  208. Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  209. }
  210. [Test]
  211. public void TestRepeatSameDrawDifferentExtraParamsReusingTexture()
  212. {
  213. TestHelpers.InMethod();
  214. string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;";
  215. SetupScene(true);
  216. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  217. m_dtm.AddDynamicTextureData(
  218. m_scene.RegionInfo.RegionID,
  219. so.UUID,
  220. m_vrm.GetContentType(),
  221. dtText,
  222. "");
  223. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  224. m_dtm.AddDynamicTextureData(
  225. m_scene.RegionInfo.RegionID,
  226. so.UUID,
  227. m_vrm.GetContentType(),
  228. dtText,
  229. "alpha:250");
  230. Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  231. }
  232. [Test]
  233. public void TestRepeatSameDrawContainingImageReusingTexture()
  234. {
  235. TestHelpers.InMethod();
  236. string dtText
  237. = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World; Image http://0.0.0.0/shouldnotexist.png";
  238. SetupScene(true);
  239. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  240. m_dtm.AddDynamicTextureData(
  241. m_scene.RegionInfo.RegionID,
  242. so.UUID,
  243. m_vrm.GetContentType(),
  244. dtText,
  245. "");
  246. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  247. m_dtm.AddDynamicTextureData(
  248. m_scene.RegionInfo.RegionID,
  249. so.UUID,
  250. m_vrm.GetContentType(),
  251. dtText,
  252. "");
  253. Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  254. }
  255. }
  256. }