aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region
diff options
context:
space:
mode:
authorDiva Canto2012-09-21 16:45:35 -0700
committerDiva Canto2012-09-21 16:45:35 -0700
commitb0da4b8d138fe7d4f5c118a06adb6e9ee078e7cb (patch)
tree3d3b961b97fed3e98b7365771b2ffdb518b69d04 /OpenSim/Region
parentMoved the small HGUuidGatherer class to the file where its parent class is. N... (diff)
parentMerge branch 'master' of ssh://opensimulator.org/var/git/opensim (diff)
downloadopensim-SC-b0da4b8d138fe7d4f5c118a06adb6e9ee078e7cb.zip
opensim-SC-b0da4b8d138fe7d4f5c118a06adb6e9ee078e7cb.tar.gz
opensim-SC-b0da4b8d138fe7d4f5c118a06adb6e9ee078e7cb.tar.bz2
opensim-SC-b0da4b8d138fe7d4f5c118a06adb6e9ee078e7cb.tar.xz
Merge branch 'master' of ssh://opensimulator.org/var/git/opensim
Diffstat (limited to 'OpenSim/Region')
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs24
-rw-r--r--OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs134
2 files changed, 150 insertions, 8 deletions
diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
index 11826bd..52d96bc 100644
--- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
+++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/LSL_Api.cs
@@ -5465,27 +5465,36 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5465 /// Returns the index of the first occurrence of test 5465 /// Returns the index of the first occurrence of test
5466 /// in src. 5466 /// in src.
5467 /// </summary> 5467 /// </summary>
5468 5468 /// <param name="src">Source list</param>
5469 /// <param name="test">List to search for</param>
5470 /// <returns>
5471 /// The index number of the point in src where test was found if it was found.
5472 /// Otherwise returns -1
5473 /// </returns>
5469 public LSL_Integer llListFindList(LSL_List src, LSL_List test) 5474 public LSL_Integer llListFindList(LSL_List src, LSL_List test)
5470 { 5475 {
5471
5472 int index = -1; 5476 int index = -1;
5473 int length = src.Length - test.Length + 1; 5477 int length = src.Length - test.Length + 1;
5474 5478
5475 m_host.AddScriptLPS(1); 5479 m_host.AddScriptLPS(1);
5476 5480
5477 // If either list is empty, do not match 5481 // If either list is empty, do not match
5478
5479 if (src.Length != 0 && test.Length != 0) 5482 if (src.Length != 0 && test.Length != 0)
5480 { 5483 {
5481 for (int i = 0; i < length; i++) 5484 for (int i = 0; i < length; i++)
5482 { 5485 {
5483 if (src.Data[i].Equals(test.Data[0])) 5486 // Why this piece of insanity? This is because most script constants are C# value types (e.g. int)
5487 // rather than wrapped LSL types. Such a script constant does not have int.Equal(LSL_Integer) code
5488 // and so the comparison fails even if the LSL_Integer conceptually has the same value.
5489 // Therefore, here we test Equals on both the source and destination objects.
5490 // However, a future better approach may be use LSL struct script constants (e.g. LSL_Integer(1)).
5491 if (src.Data[i].Equals(test.Data[0]) || test.Data[0].Equals(src.Data[i]))
5484 { 5492 {
5485 int j; 5493 int j;
5486 for (j = 1; j < test.Length; j++) 5494 for (j = 1; j < test.Length; j++)
5487 if (!src.Data[i+j].Equals(test.Data[j])) 5495 if (!(src.Data[i+j].Equals(test.Data[j]) || test.Data[j].Equals(src.Data[i+j])))
5488 break; 5496 break;
5497
5489 if (j == test.Length) 5498 if (j == test.Length)
5490 { 5499 {
5491 index = i; 5500 index = i;
@@ -5496,19 +5505,18 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api
5496 } 5505 }
5497 5506
5498 return index; 5507 return index;
5499
5500 } 5508 }
5501 5509
5502 public LSL_String llGetObjectName() 5510 public LSL_String llGetObjectName()
5503 { 5511 {
5504 m_host.AddScriptLPS(1); 5512 m_host.AddScriptLPS(1);
5505 return m_host.Name!=null?m_host.Name:String.Empty; 5513 return m_host.Name !=null ? m_host.Name : String.Empty;
5506 } 5514 }
5507 5515
5508 public void llSetObjectName(string name) 5516 public void llSetObjectName(string name)
5509 { 5517 {
5510 m_host.AddScriptLPS(1); 5518 m_host.AddScriptLPS(1);
5511 m_host.Name = name!=null?name:String.Empty; 5519 m_host.Name = name != null ? name : String.Empty;
5512 } 5520 }
5513 5521
5514 public LSL_String llGetDate() 5522 public LSL_String llGetDate()
diff --git a/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs
new file mode 100644
index 0000000..dd23be8
--- /dev/null
+++ b/OpenSim/Region/ScriptEngine/Shared/Tests/LSL_ApiListTests.cs
@@ -0,0 +1,134 @@
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
28using System;
29using System.Collections.Generic;
30using NUnit.Framework;
31using OpenSim.Framework;
32using OpenSim.Tests.Common;
33using OpenSim.Region.ScriptEngine.Shared;
34using OpenSim.Region.Framework.Scenes;
35using Nini.Config;
36using OpenSim.Region.ScriptEngine.Shared.Api;
37using OpenSim.Region.ScriptEngine.Shared.ScriptBase;
38using OpenMetaverse;
39using OpenSim.Tests.Common.Mock;
40
41using LSL_Float = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLFloat;
42using LSL_Integer = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLInteger;
43using LSL_List = OpenSim.Region.ScriptEngine.Shared.LSL_Types.list;
44using LSL_String = OpenSim.Region.ScriptEngine.Shared.LSL_Types.LSLString;
45
46namespace OpenSim.Region.ScriptEngine.Shared.Tests
47{
48 [TestFixture]
49 public class LSL_ApiListTests
50 {
51 private LSL_Api m_lslApi;
52
53 [SetUp]
54 public void SetUp()
55 {
56 IConfigSource initConfigSource = new IniConfigSource();
57 IConfig config = initConfigSource.AddConfig("XEngine");
58 config.Set("Enabled", "true");
59
60 Scene scene = new SceneHelpers().SetupScene();
61 SceneObjectPart part = SceneHelpers.AddSceneObject(scene).RootPart;
62
63 XEngine.XEngine engine = new XEngine.XEngine();
64 engine.Initialise(initConfigSource);
65 engine.AddRegion(scene);
66
67 m_lslApi = new LSL_Api();
68 m_lslApi.Initialize(engine, part, null);
69 }
70
71 [Test]
72 public void TestllListFindList()
73 {
74 TestHelpers.InMethod();
75
76 LSL_List src = new LSL_List(new LSL_Integer(1), new LSL_Integer(2), new LSL_Integer(3));
77
78 {
79 // Test for a single item that should be found
80 int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(4)));
81 Assert.That(result, Is.EqualTo(-1));
82 }
83
84 {
85 // Test for a single item that should be found
86 int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(2)));
87 Assert.That(result, Is.EqualTo(1));
88 }
89
90 {
91 // Test for a constant that should be found
92 int result = m_lslApi.llListFindList(src, new LSL_List(ScriptBaseClass.AGENT));
93 Assert.That(result, Is.EqualTo(0));
94 }
95
96 {
97 // Test for a list that should be found
98 int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(2), new LSL_Integer(3)));
99 Assert.That(result, Is.EqualTo(1));
100 }
101
102 {
103 // Test for a single item not in the list
104 int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_Integer(4)));
105 Assert.That(result, Is.EqualTo(-1));
106 }
107
108 {
109 // Test for something that should not be cast
110 int result = m_lslApi.llListFindList(src, new LSL_List(new LSL_String("4")));
111 Assert.That(result, Is.EqualTo(-1));
112 }
113
114 {
115 // Test for a list not in the list
116 int result
117 = m_lslApi.llListFindList(
118 src, new LSL_List(new LSL_Integer(2), new LSL_Integer(3), new LSL_Integer(4)));
119 Assert.That(result, Is.EqualTo(-1));
120 }
121
122 {
123 LSL_List srcWithConstants
124 = new LSL_List(new LSL_Integer(3), ScriptBaseClass.AGENT, ScriptBaseClass.OS_NPC_LAND_AT_TARGET);
125
126 // Test for constants that appears in the source list that should be found
127 int result
128 = m_lslApi.llListFindList(srcWithConstants, new LSL_List(new LSL_Integer(1), new LSL_Integer(2)));
129
130 Assert.That(result, Is.EqualTo(1));
131 }
132 }
133 }
134 } \ No newline at end of file