MockScriptEngine.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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;
  29. using System.Collections.Generic;
  30. using System.Reflection;
  31. using Nini.Config;
  32. using OpenMetaverse;
  33. using OpenSim.Framework;
  34. using OpenSim.Region.Framework.Interfaces;
  35. using OpenSim.Region.Framework.Scenes;
  36. using OpenSim.Region.ScriptEngine.Interfaces;
  37. using OpenSim.Region.ScriptEngine.Shared;
  38. namespace OpenSim.Tests.Common
  39. {
  40. public class MockScriptEngine : INonSharedRegionModule, IScriptModule, IScriptEngine
  41. {
  42. public IConfigSource ConfigSource { get; private set; }
  43. public IConfig Config { get; private set; }
  44. private Scene m_scene;
  45. /// <summary>
  46. /// Expose posted events to tests.
  47. /// </summary>
  48. public Dictionary<UUID, List<EventParams>> PostedEvents { get; private set; }
  49. /// <summary>
  50. /// A very primitive way of hooking text cose to a posed event.
  51. /// </summary>
  52. /// <remarks>
  53. /// May be replaced with something that uses more original code in the future.
  54. /// </remarks>
  55. public event Action<UUID, EventParams> PostEventHook;
  56. public void Initialise(IConfigSource source)
  57. {
  58. ConfigSource = source;
  59. // Can set later on if required
  60. Config = new IniConfig("MockScriptEngine", ConfigSource);
  61. PostedEvents = new Dictionary<UUID, List<EventParams>>();
  62. }
  63. public void Close()
  64. {
  65. }
  66. public void AddRegion(Scene scene)
  67. {
  68. m_scene = scene;
  69. m_scene.StackModuleInterface<IScriptModule>(this);
  70. }
  71. public void RemoveRegion(Scene scene)
  72. {
  73. }
  74. public void RegionLoaded(Scene scene)
  75. {
  76. }
  77. public string Name { get { return "Mock Script Engine"; } }
  78. public string ScriptEngineName { get { return Name; } }
  79. public Type ReplaceableInterface { get { return null; } }
  80. #pragma warning disable 0067
  81. public event ScriptRemoved OnScriptRemoved;
  82. public event ObjectRemoved OnObjectRemoved;
  83. #pragma warning restore 0067
  84. public string GetXMLState (UUID itemID)
  85. {
  86. throw new System.NotImplementedException ();
  87. }
  88. public bool SetXMLState(UUID itemID, string xml)
  89. {
  90. throw new System.NotImplementedException ();
  91. }
  92. public void CancelScriptEvent(UUID itemID, string eventName)
  93. {
  94. }
  95. public bool PostScriptEvent(UUID itemID, string name, object[] args)
  96. {
  97. // Console.WriteLine("Posting event {0} for {1}", name, itemID);
  98. return PostScriptEvent(itemID, new EventParams(name, args, null));
  99. }
  100. public bool PostScriptEvent(UUID itemID, EventParams evParams)
  101. {
  102. List<EventParams> eventsForItem;
  103. if (!PostedEvents.ContainsKey(itemID))
  104. {
  105. eventsForItem = new List<EventParams>();
  106. PostedEvents.Add(itemID, eventsForItem);
  107. }
  108. else
  109. {
  110. eventsForItem = PostedEvents[itemID];
  111. }
  112. eventsForItem.Add(evParams);
  113. if (PostEventHook != null)
  114. PostEventHook(itemID, evParams);
  115. return true;
  116. }
  117. public bool PostObjectEvent(uint localID, EventParams evParams)
  118. {
  119. return PostObjectEvent(m_scene.GetSceneObjectPart(localID), evParams);
  120. }
  121. public bool PostObjectEvent(UUID itemID, string name, object[] args)
  122. {
  123. return PostObjectEvent(m_scene.GetSceneObjectPart(itemID), new EventParams(name, args, null));
  124. }
  125. private bool PostObjectEvent(SceneObjectPart part, EventParams evParams)
  126. {
  127. foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems(InventoryType.LSL))
  128. PostScriptEvent(item.ItemID, evParams);
  129. return true;
  130. }
  131. public bool SuspendScript(UUID itemID)
  132. {
  133. throw new System.NotImplementedException ();
  134. }
  135. public bool ResumeScript(UUID itemID)
  136. {
  137. throw new System.NotImplementedException ();
  138. }
  139. public ArrayList GetScriptErrors(UUID itemID)
  140. {
  141. throw new System.NotImplementedException ();
  142. }
  143. public bool HasScript(UUID itemID, out bool running)
  144. {
  145. throw new System.NotImplementedException ();
  146. }
  147. public bool GetScriptState(UUID itemID)
  148. {
  149. throw new System.NotImplementedException ();
  150. }
  151. public void SaveAllState()
  152. {
  153. throw new System.NotImplementedException ();
  154. }
  155. public void StartProcessing()
  156. {
  157. throw new System.NotImplementedException ();
  158. }
  159. public float GetScriptExecutionTime(List<UUID> itemIDs)
  160. {
  161. return 0;
  162. }
  163. public int GetScriptsMemory(List<UUID> itemIDs)
  164. {
  165. return 0;
  166. }
  167. public Dictionary<uint, float> GetObjectScriptsExecutionTimes()
  168. {
  169. throw new System.NotImplementedException ();
  170. }
  171. public IScriptWorkItem QueueEventHandler(object parms)
  172. {
  173. throw new System.NotImplementedException ();
  174. }
  175. public DetectParams GetDetectParams(UUID item, int number)
  176. {
  177. throw new System.NotImplementedException ();
  178. }
  179. public void SetMinEventDelay(UUID itemID, double delay)
  180. {
  181. throw new System.NotImplementedException ();
  182. }
  183. public int GetStartParameter(UUID itemID)
  184. {
  185. throw new System.NotImplementedException ();
  186. }
  187. public void SetScriptState(UUID itemID, bool state, bool self)
  188. {
  189. throw new System.NotImplementedException ();
  190. }
  191. public void SetState(UUID itemID, string newState)
  192. {
  193. throw new System.NotImplementedException ();
  194. }
  195. public void ApiResetScript(UUID itemID)
  196. {
  197. throw new System.NotImplementedException ();
  198. }
  199. public void ResetScript (UUID itemID)
  200. {
  201. throw new System.NotImplementedException ();
  202. }
  203. public IScriptApi GetApi(UUID itemID, string name)
  204. {
  205. throw new System.NotImplementedException ();
  206. }
  207. public Scene World { get { return m_scene; } }
  208. public IScriptModule ScriptModule { get { return this; } }
  209. public string ScriptEnginePath { get { throw new System.NotImplementedException (); }}
  210. public string ScriptClassName { get { throw new System.NotImplementedException (); } }
  211. public string ScriptBaseClassName { get { throw new System.NotImplementedException (); } }
  212. public string[] ScriptReferencedAssemblies { get { throw new System.NotImplementedException (); } }
  213. public ParameterInfo[] ScriptBaseClassParameters { get { throw new System.NotImplementedException (); } }
  214. public void ClearPostedEvents()
  215. {
  216. PostedEvents.Clear();
  217. }
  218. public void SleepScript(UUID itemID, int delay)
  219. {
  220. }
  221. public ICollection<ScriptTopStatsData> GetTopObjectStats(float mintime, int minmemory, out float totaltime, out float totalmemory)
  222. {
  223. totaltime = 0;
  224. totalmemory = 0;
  225. return null;
  226. }
  227. }
  228. }