clockwerk-opensim-stable – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 vero 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 Nini.Config;
31 using NUnit.Framework;
32 using OpenMetaverse;
33 using OpenSim.Data.Null;
34 using OpenSim.Framework;
35 using OpenSim.Region.CoreModules.Avatar.Friends;
36 using OpenSim.Region.Framework.Scenes;
37 using OpenSim.Tests.Common;
38 using OpenSim.Tests.Common.Mock;
39  
40 namespace OpenSim.Region.CoreModules.Avatar.Friends.Tests
41 {
42 [TestFixture]
43 public class FriendsModuleTests : OpenSimTestCase
44 {
45 private FriendsModule m_fm;
46 private TestScene m_scene;
47  
48 [TestFixtureSetUp]
49 public void FixtureInit()
50 {
51 // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread.
52 Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest;
53 }
54  
55 [TestFixtureTearDown]
56 public void TearDown()
57 {
58 // We must set this back afterwards, otherwise later tests will fail since they're expecting multiple
59 // threads. Possibly, later tests should be rewritten so none of them require async stuff (which regression
60 // tests really shouldn't).
61 Util.FireAndForgetMethod = Util.DefaultFireAndForgetMethod;
62 }
63  
64 [SetUp]
65 public void Init()
66 {
67 // We must clear friends data between tests since Data.Null holds it in static properties. This is necessary
68 // so that different services and simulator can share the data in standalone mode. This is pretty horrible
69 // effectively the statics are global variables.
70 NullFriendsData.Clear();
71  
72 IConfigSource config = new IniConfigSource();
73 config.AddConfig("Modules");
74 // Not strictly necessary since FriendsModule assumes it is the default (!)
75 config.Configs["Modules"].Set("FriendsModule", "FriendsModule");
76 config.AddConfig("Friends");
77 config.Configs["Friends"].Set("Connector", "OpenSim.Services.FriendsService.dll");
78 config.AddConfig("FriendsService");
79 config.Configs["FriendsService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
80  
81 m_scene = new SceneHelpers().SetupScene();
82 m_fm = new FriendsModule();
83 SceneHelpers.SetupSceneModules(m_scene, config, m_fm);
84 }
85  
86 [Test]
87 public void TestLoginWithNoFriends()
88 {
89 TestHelpers.InMethod();
90 // log4net.Config.XmlConfigurator.Configure();
91  
92 UUID userId = TestHelpers.ParseTail(0x1);
93  
94 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
95  
96 Assert.That(((TestClient)sp.ControllingClient).ReceivedOfflineNotifications.Count, Is.EqualTo(0));
97 Assert.That(((TestClient)sp.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(0));
98 }
99  
100 [Test]
101 public void TestLoginWithOfflineFriends()
102 {
103 TestHelpers.InMethod();
104 // log4net.Config.XmlConfigurator.Configure();
105  
106 UUID user1Id = TestHelpers.ParseTail(0x1);
107 UUID user2Id = TestHelpers.ParseTail(0x2);
108  
109 // UserAccountHelpers.CreateUserWithInventory(m_scene, user1Id);
110 // UserAccountHelpers.CreateUserWithInventory(m_scene, user2Id);
111 //
112 // m_fm.AddFriendship(user1Id, user2Id);
113  
114 ScenePresence sp1 = SceneHelpers.AddScenePresence(m_scene, user1Id);
115 ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, user2Id);
116  
117 m_fm.AddFriendship(sp1.ControllingClient, user2Id);
118  
119 // Not necessary for this test. CanSeeOnline is automatically granted.
120 // m_fm.GrantRights(sp1.ControllingClient, user2Id, (int)FriendRights.CanSeeOnline);
121  
122 // We must logout from the client end so that the presence service is correctly updated by the presence
123 // detector. This is listening to the OnConnectionClosed event on the client.
124 ((TestClient)sp1.ControllingClient).Logout();
125 ((TestClient)sp2.ControllingClient).Logout();
126 // m_scene.RemoveClient(sp1.UUID, true);
127 // m_scene.RemoveClient(sp2.UUID, true);
128  
129 ScenePresence sp1Redux = SceneHelpers.AddScenePresence(m_scene, user1Id);
130  
131 // We don't expect to receive notifications of offline friends on login, just online.
132 Assert.That(((TestClient)sp1Redux.ControllingClient).ReceivedOfflineNotifications.Count, Is.EqualTo(0));
133 Assert.That(((TestClient)sp1Redux.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(0));
134 }
135  
136 [Test]
137 public void TestLoginWithOnlineFriends()
138 {
139 TestHelpers.InMethod();
140 // log4net.Config.XmlConfigurator.Configure();
141  
142 UUID user1Id = TestHelpers.ParseTail(0x1);
143 UUID user2Id = TestHelpers.ParseTail(0x2);
144  
145 // UserAccountHelpers.CreateUserWithInventory(m_scene, user1Id);
146 // UserAccountHelpers.CreateUserWithInventory(m_scene, user2Id);
147 //
148 // m_fm.AddFriendship(user1Id, user2Id);
149  
150 ScenePresence sp1 = SceneHelpers.AddScenePresence(m_scene, user1Id);
151 ScenePresence sp2 = SceneHelpers.AddScenePresence(m_scene, user2Id);
152  
153 m_fm.AddFriendship(sp1.ControllingClient, user2Id);
154  
155 // Not necessary for this test. CanSeeOnline is automatically granted.
156 // m_fm.GrantRights(sp1.ControllingClient, user2Id, (int)FriendRights.CanSeeOnline);
157  
158 // We must logout from the client end so that the presence service is correctly updated by the presence
159 // detector. This is listening to the OnConnectionClosed event on the client.
160 // ((TestClient)sp1.ControllingClient).Logout();
161 ((TestClient)sp2.ControllingClient).Logout();
162 // m_scene.RemoveClient(user2Id, true);
163  
164 ScenePresence sp2Redux = SceneHelpers.AddScenePresence(m_scene, user2Id);
165  
166 Assert.That(((TestClient)sp2Redux.ControllingClient).ReceivedOfflineNotifications.Count, Is.EqualTo(0));
167 Assert.That(((TestClient)sp2Redux.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(1));
168 }
169  
170 [Test]
171 public void TestAddFriendshipWhileOnline()
172 {
173 TestHelpers.InMethod();
174 // log4net.Config.XmlConfigurator.Configure();
175  
176 UUID userId = TestHelpers.ParseTail(0x1);
177 UUID user2Id = TestHelpers.ParseTail(0x2);
178  
179 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, userId);
180 SceneHelpers.AddScenePresence(m_scene, user2Id);
181  
182 // This fiendship is two-way but without a connector, only the first user will receive the online
183 // notification.
184 m_fm.AddFriendship(sp.ControllingClient, user2Id);
185  
186 Assert.That(((TestClient)sp.ControllingClient).ReceivedOfflineNotifications.Count, Is.EqualTo(0));
187 Assert.That(((TestClient)sp.ControllingClient).ReceivedOnlineNotifications.Count, Is.EqualTo(1));
188 }
189  
190 [Test]
191 public void TestRemoveFriendshipWhileOnline()
192 {
193 TestHelpers.InMethod();
194 // log4net.Config.XmlConfigurator.Configure();
195  
196 UUID user1Id = TestHelpers.ParseTail(0x1);
197 UUID user2Id = TestHelpers.ParseTail(0x2);
198  
199 ScenePresence sp = SceneHelpers.AddScenePresence(m_scene, user1Id);
200 SceneHelpers.AddScenePresence(m_scene, user2Id);
201  
202 m_fm.AddFriendship(sp.ControllingClient, user2Id);
203 m_fm.RemoveFriendship(sp.ControllingClient, user2Id);
204  
205 TestClient user1Client = sp.ControllingClient as TestClient;
206 Assert.That(user1Client.ReceivedFriendshipTerminations.Count, Is.EqualTo(1));
207 Assert.That(user1Client.ReceivedFriendshipTerminations[0], Is.EqualTo(user2Id));
208 }
209 }
210 }