VectorRenderModuleTests.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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. 0);
  73. Assert.That(originalTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  74. }
  75. [Test]
  76. public void TestRepeatSameDraw()
  77. {
  78. TestHelpers.InMethod();
  79. string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;";
  80. SetupScene(false);
  81. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  82. m_dtm.AddDynamicTextureData(
  83. m_scene.RegionInfo.RegionID,
  84. so.UUID,
  85. m_vrm.GetContentType(),
  86. dtText,
  87. "",
  88. 0);
  89. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  90. m_dtm.AddDynamicTextureData(
  91. m_scene.RegionInfo.RegionID,
  92. so.UUID,
  93. m_vrm.GetContentType(),
  94. dtText,
  95. "",
  96. 0);
  97. Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  98. }
  99. [Test]
  100. public void TestRepeatSameDrawDifferentExtraParams()
  101. {
  102. TestHelpers.InMethod();
  103. string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;";
  104. SetupScene(false);
  105. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  106. m_dtm.AddDynamicTextureData(
  107. m_scene.RegionInfo.RegionID,
  108. so.UUID,
  109. m_vrm.GetContentType(),
  110. dtText,
  111. "",
  112. 0);
  113. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  114. m_dtm.AddDynamicTextureData(
  115. m_scene.RegionInfo.RegionID,
  116. so.UUID,
  117. m_vrm.GetContentType(),
  118. dtText,
  119. "alpha:250",
  120. 0);
  121. Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  122. }
  123. [Test]
  124. public void TestRepeatSameDrawContainingImage()
  125. {
  126. TestHelpers.InMethod();
  127. string dtText
  128. = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World; Image http://0.0.0.0/shouldnotexist.png";
  129. SetupScene(false);
  130. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  131. m_dtm.AddDynamicTextureData(
  132. m_scene.RegionInfo.RegionID,
  133. so.UUID,
  134. m_vrm.GetContentType(),
  135. dtText,
  136. "",
  137. 0);
  138. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  139. m_dtm.AddDynamicTextureData(
  140. m_scene.RegionInfo.RegionID,
  141. so.UUID,
  142. m_vrm.GetContentType(),
  143. dtText,
  144. "",
  145. 0);
  146. Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  147. }
  148. [Test]
  149. public void TestDrawReusingTexture()
  150. {
  151. TestHelpers.InMethod();
  152. SetupScene(true);
  153. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  154. UUID originalTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  155. m_dtm.AddDynamicTextureData(
  156. m_scene.RegionInfo.RegionID,
  157. so.UUID,
  158. m_vrm.GetContentType(),
  159. "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;",
  160. "",
  161. 0);
  162. Assert.That(originalTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  163. }
  164. [Test]
  165. public void TestRepeatSameDrawReusingTexture()
  166. {
  167. TestHelpers.InMethod();
  168. // TestHelpers.EnableLogging();
  169. string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;";
  170. SetupScene(true);
  171. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  172. m_dtm.AddDynamicTextureData(
  173. m_scene.RegionInfo.RegionID,
  174. so.UUID,
  175. m_vrm.GetContentType(),
  176. dtText,
  177. "",
  178. 0);
  179. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  180. m_dtm.AddDynamicTextureData(
  181. m_scene.RegionInfo.RegionID,
  182. so.UUID,
  183. m_vrm.GetContentType(),
  184. dtText,
  185. "",
  186. 0);
  187. Assert.That(firstDynamicTextureID, Is.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  188. }
  189. /// <summary>
  190. /// Test a low data dynamically generated texture such that it is treated as a low data texture that causes
  191. /// problems for current viewers.
  192. /// </summary>
  193. /// <remarks>
  194. /// As we do not set DynamicTextureModule.ReuseLowDataTextures = true in this test, it should not reuse the
  195. /// texture
  196. /// </remarks>
  197. [Test]
  198. public void TestRepeatSameDrawLowDataTexture()
  199. {
  200. TestHelpers.InMethod();
  201. // TestHelpers.EnableLogging();
  202. string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;";
  203. SetupScene(true);
  204. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  205. m_dtm.AddDynamicTextureData(
  206. m_scene.RegionInfo.RegionID,
  207. so.UUID,
  208. m_vrm.GetContentType(),
  209. dtText,
  210. "1024",
  211. 0);
  212. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  213. m_dtm.AddDynamicTextureData(
  214. m_scene.RegionInfo.RegionID,
  215. so.UUID,
  216. m_vrm.GetContentType(),
  217. dtText,
  218. "1024",
  219. 0);
  220. Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  221. }
  222. [Test]
  223. public void TestRepeatSameDrawDifferentExtraParamsReusingTexture()
  224. {
  225. TestHelpers.InMethod();
  226. string dtText = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World;";
  227. SetupScene(true);
  228. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  229. m_dtm.AddDynamicTextureData(
  230. m_scene.RegionInfo.RegionID,
  231. so.UUID,
  232. m_vrm.GetContentType(),
  233. dtText,
  234. "",
  235. 0);
  236. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  237. m_dtm.AddDynamicTextureData(
  238. m_scene.RegionInfo.RegionID,
  239. so.UUID,
  240. m_vrm.GetContentType(),
  241. dtText,
  242. "alpha:250",
  243. 0);
  244. Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  245. }
  246. [Test]
  247. public void TestRepeatSameDrawContainingImageReusingTexture()
  248. {
  249. TestHelpers.InMethod();
  250. string dtText
  251. = "PenColour BLACK; MoveTo 40,220; FontSize 32; Text Hello World; Image http://0.0.0.0/shouldnotexist.png";
  252. SetupScene(true);
  253. SceneObjectGroup so = SceneHelpers.AddSceneObject(m_scene);
  254. m_dtm.AddDynamicTextureData(
  255. m_scene.RegionInfo.RegionID,
  256. so.UUID,
  257. m_vrm.GetContentType(),
  258. dtText,
  259. "",
  260. 0);
  261. UUID firstDynamicTextureID = so.RootPart.Shape.Textures.GetFace(0).TextureID;
  262. m_dtm.AddDynamicTextureData(
  263. m_scene.RegionInfo.RegionID,
  264. so.UUID,
  265. m_vrm.GetContentType(),
  266. dtText,
  267. "",
  268. 0);
  269. Assert.That(firstDynamicTextureID, Is.Not.EqualTo(so.RootPart.Shape.Textures.GetFace(0).TextureID));
  270. }
  271. }
  272. }