LSL_ApiListTests.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 NUnit.Framework;
  30. using OpenSim.Framework;
  31. using OpenSim.Tests.Common;
  32. using OpenSim.Region.ScriptEngine.Shared;
  33. using OpenSim.Region.Framework.Scenes;
  34. using Nini.Config;
  35. using OpenSim.Region.ScriptEngine.Shared.Api;
  36. using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
  37. using OpenMetaverse;
  38. using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
  39. using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
  40. using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
  41. using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
  42. namespace OpenSim.Region.ScriptEngine.Shared.Tests
  43. {
  44. [TestFixture]
  45. public class LSL_ApiListTests : OpenSimTestCase
  46. {
  47. private LSL_Api m_lslApi;
  48. [SetUp]
  49. public override void SetUp()
  50. {
  51. base.SetUp();
  52. IConfigSource initConfigSource = new IniConfigSource();
  53. IConfig config = initConfigSource.AddConfig("XEngine");
  54. config.Set("Enabled", "true");
  55. config = initConfigSource.AddConfig("OSSL");
  56. config.Set("DebuggerSafe", false);
  57. config.Set("AllowOSFunctions", "true");
  58. config.Set("OSFunctionThreatLevel", "Severe");
  59. Scene scene = new SceneHelpers().SetupScene();
  60. SceneObjectPart part = SceneHelpers.AddSceneObject(scene).RootPart;
  61. XEngine.XEngine engine = new XEngine.XEngine();
  62. engine.Initialise(initConfigSource);
  63. engine.AddRegion(scene);
  64. m_lslApi = new LSL_Api();
  65. m_lslApi.Initialize(engine, part, null);
  66. }
  67. [Test]
  68. public void TestllListFindList()
  69. {
  70. TestHelpers.InMethod();
  71. LSL_List src = new LSL_List(new LSL_Integer(1), new LSL_Integer(2), new LSL_Integer(3));
  72. {
  73. // Test for a single item that should be found
  74. int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(4)));
  75. Assert.That(result, Is.EqualTo(-1));
  76. }
  77. {
  78. // Test for a single item that should be found
  79. int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(2)));
  80. Assert.That(result, Is.EqualTo(1));
  81. }
  82. {
  83. // Test for a constant that should be found
  84. int result = m_lslApi.llListFindList(src, new LSL_List(ScriptBaseClass.AGENT));
  85. Assert.That(result, Is.EqualTo(0));
  86. }
  87. {
  88. // Test for a list that should be found
  89. int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(2), new LSL_Integer(3)));
  90. Assert.That(result, Is.EqualTo(1));
  91. }
  92. {
  93. // Test for a single item not in the list
  94. int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(4)));
  95. Assert.That(result, Is.EqualTo(-1));
  96. }
  97. {
  98. // Test for something that should not be cast
  99. int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_String("4")));
  100. Assert.That(result, Is.EqualTo(-1));
  101. }
  102. {
  103. // Test for a list not in the list
  104. int result
  105. = m_lslApi.llListFindList(
  106. src, new LSL_List(new LSL_Integer(2), new LSL_Integer(3), new LSL_Integer(4)));
  107. Assert.That(result, Is.EqualTo(-1));
  108. }
  109. {
  110. LSL_List srcWithConstants
  111. = new LSL_List(new LSL_Integer(3), ScriptBaseClass.AGENT, ScriptBaseClass.OS_NPC_LAND_AT_TARGET);
  112. // Test for constants that appears in the source list that should be found
  113. int result
  114. = m_lslApi.llListFindList(srcWithConstants, new LSL_List(new LSL_Integer(1), new LSL_Integer(2)));
  115. Assert.That(result, Is.EqualTo(1));
  116. }
  117. }
  118. }
  119. }