OpenSim
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Macros
LSL_ApiListTests.cs
Go to the documentation of this file.
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 
28 using System;
29 using System.Collections.Generic;
30 using NUnit.Framework;
31 using OpenSim.Framework;
32 using OpenSim.Tests.Common;
33 using OpenSim.Region.ScriptEngine.Shared;
34 using OpenSim.Region.Framework.Scenes;
35 using Nini.Config;
36 using OpenSim.Region.ScriptEngine.Shared.Api;
37 using OpenSim.Region.ScriptEngine.Shared.Instance;
38 using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
39 using OpenMetaverse;
40 
45 
46 namespace OpenSim.Region.ScriptEngine.Shared.Tests
47 {
48  [TestFixture]
50  {
51  private LSL_Api m_lslApi;
52 
53  [SetUp]
54  public override void SetUp()
55  {
56  base.SetUp();
57 
58  IConfigSource initConfigSource = new IniConfigSource();
59  IConfig config = initConfigSource.AddConfig("XEngine");
60  config.Set("Enabled", "true");
61 
62  Scene scene = new SceneHelpers().SetupScene();
63  SceneObjectPart part = SceneHelpers.AddSceneObject(scene).RootPart;
64 
65  XEngine.XEngine engine = new XEngine.XEngine();
66  engine.Initialise(initConfigSource);
67  engine.AddRegion(scene);
68 
69  m_lslApi = new LSL_Api();
70  m_lslApi.Initialize(engine, part, null);
71  }
72 
73  [Test]
74  public void TestllListFindList()
75  {
76  TestHelpers.InMethod();
77 
78  LSL_List src = new LSL_List(new LSL_Integer(1), new LSL_Integer(2), new LSL_Integer(3));
79 
80  {
81  // Test for a single item that should be found
82  int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(4)));
83  Assert.That(result, Is.EqualTo(-1));
84  }
85 
86  {
87  // Test for a single item that should be found
88  int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(2)));
89  Assert.That(result, Is.EqualTo(1));
90  }
91 
92  {
93  // Test for a constant that should be found
94  int result = m_lslApi.llListFindList(src, new LSL_List(ScriptBaseClass.AGENT));
95  Assert.That(result, Is.EqualTo(0));
96  }
97 
98  {
99  // Test for a list that should be found
100  int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(2), new LSL_Integer(3)));
101  Assert.That(result, Is.EqualTo(1));
102  }
103 
104  {
105  // Test for a single item not in the list
106  int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(4)));
107  Assert.That(result, Is.EqualTo(-1));
108  }
109 
110  {
111  // Test for something that should not be cast
112  int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_String("4")));
113  Assert.That(result, Is.EqualTo(-1));
114  }
115 
116  {
117  // Test for a list not in the list
118  int result
119  = m_lslApi.llListFindList(
120  src, new LSL_List(new LSL_Integer(2), new LSL_Integer(3), new LSL_Integer(4)));
121  Assert.That(result, Is.EqualTo(-1));
122  }
123 
124  {
125  LSL_List srcWithConstants
127 
128  // Test for constants that appears in the source list that should be found
129  int result
130  = m_lslApi.llListFindList(srcWithConstants, new LSL_List(new LSL_Integer(1), new LSL_Integer(2)));
131 
132  Assert.That(result, Is.EqualTo(1));
133  }
134  }
135  }
136  }
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_String
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat LSL_Float
Definition: CM_Api.cs:48
OpenSim.Region.ScriptEngine.Shared.LSL_Types.list LSL_List
Definition: CM_Api.cs:51
Contains all LSL ll-functions. This class will be in Default AppDomain.
Definition: LSL_Api.cs:95
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSL_Integer
OpenSim.Region.ScriptEngine.Shared.LSL_Types.list LSL_List
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSL_Integer
Definition: CM_Api.cs:49
Helpers for setting up scenes.
Definition: SceneHelpers.cs:60
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger LSLInteger
Definition: CM_Constants.cs:31
OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString LSL_String
Definition: CM_Api.cs:53