From 58869e5aa09a292dc2159c73bada2c487151dda0 Mon Sep 17 00:00:00 2001
From: Justin Clark-Casey (justincc)
Date: Tue, 10 Jul 2012 23:03:52 +0100
Subject: Fix recent SOP.GetSittingAvatars() to return null if there are no
sitting avatars rather than throwing an exception.
Extends sitting avatar regression tests to test new sitters information
---
OpenSim/Region/Framework/Scenes/SceneObjectPart.cs | 14 +++++++++++--
.../Scenes/Tests/ScenePresenceSitTests.cs | 24 ++++++++++++++++++----
2 files changed, 32 insertions(+), 6 deletions(-)
(limited to 'OpenSim/Region/Framework')
diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
index 6518b84..6677dae 100644
--- a/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
+++ b/OpenSim/Region/Framework/Scenes/SceneObjectPart.cs
@@ -4556,10 +4556,20 @@ namespace OpenSim.Region.Framework.Scenes
/// Get a copy of the list of sitting avatars.
///
/// This applies to all sitting avatars whether there is a sit target set or not.
- ///
+ /// A hashset of the sitting avatars. Returns null if there are no sitting avatars.
public HashSet GetSittingAvatars()
{
- return new HashSet(m_sittingAvatars);
+ HashSet sittingAvatars = m_sittingAvatars;
+
+ if (sittingAvatars == null)
+ {
+ return null;
+ }
+ else
+ {
+ lock (sittingAvatars)
+ return new HashSet(sittingAvatars);
+ }
}
///
diff --git a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
index ed39be1..493ab70 100644
--- a/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
+++ b/OpenSim/Region/Framework/Scenes/Tests/ScenePresenceSitTests.cs
@@ -26,6 +26,7 @@
*/
using System;
+using System.Collections.Generic;
using System.Reflection;
using Nini.Config;
using NUnit.Framework;
@@ -69,6 +70,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests
m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
+ Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
+ Assert.That(part.GetSittingAvatars(), Is.Null);
Assert.That(m_sp.ParentID, Is.EqualTo(0));
}
@@ -86,7 +89,13 @@ namespace OpenSim.Region.Framework.Scenes.Tests
m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
+ Assert.That(m_sp.PhysicsActor, Is.Null);
+
Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
+ Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
+ HashSet sittingAvatars = part.GetSittingAvatars();
+ Assert.That(sittingAvatars.Count, Is.EqualTo(1));
+ Assert.That(sittingAvatars.Contains(m_sp.UUID));
Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
}
@@ -104,10 +113,6 @@ namespace OpenSim.Region.Framework.Scenes.Tests
m_sp.HandleAgentRequestSit(m_sp.ControllingClient, m_sp.UUID, part.UUID, Vector3.Zero);
- Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
- Assert.That(m_sp.ParentID, Is.EqualTo(part.LocalId));
- Assert.That(m_sp.PhysicsActor, Is.Null);
-
// FIXME: This is different for live avatars - z position is adjusted. This is half the height of the
// default avatar.
// Curiously, Vector3.ToString() will not display the last two places of the float. For example,
@@ -119,6 +124,8 @@ namespace OpenSim.Region.Framework.Scenes.Tests
m_sp.StandUp();
Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
+ Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
+ Assert.That(part.GetSittingAvatars(), Is.Null);
Assert.That(m_sp.ParentID, Is.EqualTo(0));
Assert.That(m_sp.PhysicsActor, Is.Not.Null);
}
@@ -145,11 +152,20 @@ namespace OpenSim.Region.Framework.Scenes.Tests
Is.EqualTo(part.AbsolutePosition + part.SitTargetPosition + ScenePresence.SIT_TARGET_ADJUSTMENT));
Assert.That(m_sp.PhysicsActor, Is.Null);
+ Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(1));
+ HashSet sittingAvatars = part.GetSittingAvatars();
+ Assert.That(sittingAvatars.Count, Is.EqualTo(1));
+ Assert.That(sittingAvatars.Contains(m_sp.UUID));
+
m_sp.StandUp();
Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
Assert.That(m_sp.ParentID, Is.EqualTo(0));
Assert.That(m_sp.PhysicsActor, Is.Not.Null);
+
+ Assert.That(part.SitTargetAvatar, Is.EqualTo(UUID.Zero));
+ Assert.That(part.GetSittingAvatarsCount(), Is.EqualTo(0));
+ Assert.That(part.GetSittingAvatars(), Is.Null);
}
[Test]
--
cgit v1.1