MockScriptEngine.cs 8.4 KB

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