MockScriptEngine.cs 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. public event ScriptRemoved OnScriptRemoved;
  81. public event ObjectRemoved OnObjectRemoved;
  82. public string GetXMLState (UUID itemID)
  83. {
  84. throw new System.NotImplementedException ();
  85. }
  86. public bool SetXMLState(UUID itemID, string xml)
  87. {
  88. throw new System.NotImplementedException ();
  89. }
  90. public bool PostScriptEvent(UUID itemID, string name, object[] args)
  91. {
  92. // Console.WriteLine("Posting event {0} for {1}", name, itemID);
  93. return PostScriptEvent(itemID, new EventParams(name, args, null));
  94. }
  95. public bool PostScriptEvent(UUID itemID, EventParams evParams)
  96. {
  97. List<EventParams> eventsForItem;
  98. if (!PostedEvents.ContainsKey(itemID))
  99. {
  100. eventsForItem = new List<EventParams>();
  101. PostedEvents.Add(itemID, eventsForItem);
  102. }
  103. else
  104. {
  105. eventsForItem = PostedEvents[itemID];
  106. }
  107. eventsForItem.Add(evParams);
  108. if (PostEventHook != null)
  109. PostEventHook(itemID, evParams);
  110. return true;
  111. }
  112. public bool PostObjectEvent(uint localID, EventParams evParams)
  113. {
  114. return PostObjectEvent(m_scene.GetSceneObjectPart(localID), evParams);
  115. }
  116. public bool PostObjectEvent(UUID itemID, string name, object[] args)
  117. {
  118. return PostObjectEvent(m_scene.GetSceneObjectPart(itemID), new EventParams(name, args, null));
  119. }
  120. private bool PostObjectEvent(SceneObjectPart part, EventParams evParams)
  121. {
  122. foreach (TaskInventoryItem item in part.Inventory.GetInventoryItems(InventoryType.LSL))
  123. PostScriptEvent(item.ItemID, evParams);
  124. return true;
  125. }
  126. public void SuspendScript(UUID itemID)
  127. {
  128. throw new System.NotImplementedException ();
  129. }
  130. public void ResumeScript(UUID itemID)
  131. {
  132. throw new System.NotImplementedException ();
  133. }
  134. public ArrayList GetScriptErrors(UUID itemID)
  135. {
  136. throw new System.NotImplementedException ();
  137. }
  138. public bool HasScript(UUID itemID, out bool running)
  139. {
  140. throw new System.NotImplementedException ();
  141. }
  142. public bool GetScriptState(UUID itemID)
  143. {
  144. throw new System.NotImplementedException ();
  145. }
  146. public void SaveAllState()
  147. {
  148. throw new System.NotImplementedException ();
  149. }
  150. public void StartProcessing()
  151. {
  152. throw new System.NotImplementedException ();
  153. }
  154. public float GetScriptExecutionTime(List<UUID> itemIDs)
  155. {
  156. throw new System.NotImplementedException ();
  157. }
  158. public Dictionary<uint, float> GetObjectScriptsExecutionTimes()
  159. {
  160. throw new System.NotImplementedException ();
  161. }
  162. public IScriptWorkItem QueueEventHandler(object parms)
  163. {
  164. throw new System.NotImplementedException ();
  165. }
  166. public DetectParams GetDetectParams(UUID item, int number)
  167. {
  168. throw new System.NotImplementedException ();
  169. }
  170. public void SetMinEventDelay(UUID itemID, double delay)
  171. {
  172. throw new System.NotImplementedException ();
  173. }
  174. public int GetStartParameter(UUID itemID)
  175. {
  176. throw new System.NotImplementedException ();
  177. }
  178. public void SetScriptState(UUID itemID, bool state)
  179. {
  180. throw new System.NotImplementedException ();
  181. }
  182. public void SetState(UUID itemID, string newState)
  183. {
  184. throw new System.NotImplementedException ();
  185. }
  186. public void ApiResetScript(UUID itemID)
  187. {
  188. throw new System.NotImplementedException ();
  189. }
  190. public void ResetScript (UUID itemID)
  191. {
  192. throw new System.NotImplementedException ();
  193. }
  194. public IScriptApi GetApi(UUID itemID, string name)
  195. {
  196. throw new System.NotImplementedException ();
  197. }
  198. public Scene World { get { return m_scene; } }
  199. public IScriptModule ScriptModule { get { return this; } }
  200. public string ScriptEnginePath { get { throw new System.NotImplementedException (); }}
  201. public string ScriptClassName { get { throw new System.NotImplementedException (); } }
  202. public string ScriptBaseClassName { get { throw new System.NotImplementedException (); } }
  203. public string[] ScriptReferencedAssemblies { get { throw new System.NotImplementedException (); } }
  204. public ParameterInfo[] ScriptBaseClassParameters { get { throw new System.NotImplementedException (); } }
  205. public void ClearPostedEvents()
  206. {
  207. PostedEvents.Clear();
  208. }
  209. }
  210. }