TaskInventoryHelpers.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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 OpenMetaverse;
  29. using OpenMetaverse.Assets;
  30. using OpenSim.Framework;
  31. using OpenSim.Region.Framework.Scenes;
  32. using OpenSim.Services.Interfaces;
  33. namespace OpenSim.Tests.Common
  34. {
  35. /// <summary>
  36. /// Utility functions for carrying out task inventory tests.
  37. /// </summary>
  38. ///
  39. public static class TaskInventoryHelpers
  40. {
  41. /// <summary>
  42. /// Add a notecard item to the given part.
  43. /// </summary>
  44. /// <param name="scene"></param>
  45. /// <param name="part"></param>
  46. /// <param name="itemName"></param>
  47. /// <param name="itemID"></param>
  48. /// <param name="assetID"></param>
  49. /// <returns>The item that was added</returns>
  50. public static TaskInventoryItem AddNotecard(Scene scene, SceneObjectPart part, string itemName, UUID itemID, UUID assetID)
  51. {
  52. AssetNotecard nc = new AssetNotecard();
  53. nc.BodyText = "Hello World!";
  54. nc.Encode();
  55. AssetBase ncAsset
  56. = AssetHelpers.CreateAsset(assetID, AssetType.Notecard, nc.AssetData, UUID.Zero);
  57. scene.AssetService.Store(ncAsset);
  58. TaskInventoryItem ncItem
  59. = new TaskInventoryItem
  60. { Name = itemName, AssetID = assetID, ItemID = itemID,
  61. Type = (int)AssetType.Notecard, InvType = (int)InventoryType.Notecard };
  62. part.Inventory.AddInventoryItem(ncItem, true);
  63. return ncItem;
  64. }
  65. /// <summary>
  66. /// Add a simple script to the given part.
  67. /// </summary>
  68. /// <remarks>
  69. /// TODO: Accept input for item and asset IDs to avoid mysterious script failures that try to use any of these
  70. /// functions more than once in a test.
  71. /// </remarks>
  72. /// <param name="scene"></param>
  73. /// <param name="part"></param>
  74. /// <returns>The item that was added</returns>
  75. public static TaskInventoryItem AddScript(Scene scene, SceneObjectPart part)
  76. {
  77. return AddScript(scene, part, "scriptItem", "default { state_entry() { llSay(0, \"Hello World\"); } }");
  78. }
  79. /// <summary>
  80. /// Add a simple script to the given part.
  81. /// </summary>
  82. /// <remarks>
  83. /// TODO: Accept input for item and asset IDs to avoid mysterious script failures that try to use any of these
  84. /// functions more than once in a test.
  85. /// </remarks>
  86. /// <param name="scene"></param>
  87. /// <param name="part"></param>
  88. /// <param name="scriptName">Name of the script to add</param>
  89. /// <param name="scriptSource">LSL script source</param>
  90. /// <returns>The item that was added</returns>
  91. public static TaskInventoryItem AddScript(
  92. Scene scene, SceneObjectPart part, string scriptName, string scriptSource)
  93. {
  94. AssetScriptText ast = new AssetScriptText();
  95. ast.Source = scriptSource;
  96. ast.Encode();
  97. UUID assetUuid = new UUID("00000000-0000-0000-1000-000000000000");
  98. UUID itemUuid = new UUID("00000000-0000-0000-1100-000000000000");
  99. AssetBase asset
  100. = AssetHelpers.CreateAsset(assetUuid, AssetType.LSLText, ast.AssetData, UUID.Zero);
  101. scene.AssetService.Store(asset);
  102. TaskInventoryItem item
  103. = new TaskInventoryItem
  104. { Name = scriptName, AssetID = assetUuid, ItemID = itemUuid,
  105. Type = (int)AssetType.LSLText, InvType = (int)InventoryType.LSL };
  106. part.Inventory.AddInventoryItem(item, true);
  107. return item;
  108. }
  109. /// <summary>
  110. /// Add a scene object item to the given part.
  111. /// </summary>
  112. /// <remarks>
  113. /// TODO: Accept input for item and asset IDs to avoid mysterious script failures that try to use any of these
  114. /// functions more than once in a test.
  115. /// </remarks>
  116. ///
  117. /// <param name="scene"></param>
  118. /// <param name="sop"></param>
  119. /// <param name="itemName"></param>
  120. /// <param name="id"></param>
  121. /// <param name="userId"></param>
  122. public static TaskInventoryItem AddSceneObject(
  123. Scene scene, SceneObjectPart sop, string itemName, UUID id, UUID userId)
  124. {
  125. SceneObjectGroup taskSceneObject = SceneHelpers.CreateSceneObject(1, UUID.Zero);
  126. AssetBase taskSceneObjectAsset = AssetHelpers.CreateAsset(0x10, taskSceneObject);
  127. scene.AssetService.Store(taskSceneObjectAsset);
  128. TaskInventoryItem taskSceneObjectItem
  129. = new TaskInventoryItem
  130. { Name = itemName,
  131. AssetID = taskSceneObjectAsset.FullID,
  132. ItemID = id,
  133. OwnerID = userId,
  134. Type = (int)AssetType.Object,
  135. InvType = (int)InventoryType.Object };
  136. sop.Inventory.AddInventoryItem(taskSceneObjectItem, true);
  137. return taskSceneObjectItem;
  138. }
  139. }
  140. }