diff options
Diffstat (limited to 'OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs')
-rw-r--r-- | OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs | 232 |
1 files changed, 126 insertions, 106 deletions
diff --git a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs index 9d37cdf..a575e36 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/Tests/BasicCircuitTests.cs | |||
@@ -25,6 +25,7 @@ | |||
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | 26 | */ |
27 | 27 | ||
28 | using System; | ||
28 | using System.Net; | 29 | using System.Net; |
29 | using log4net.Config; | 30 | using log4net.Config; |
30 | using Nini.Config; | 31 | using Nini.Config; |
@@ -32,6 +33,7 @@ using NUnit.Framework; | |||
32 | using OpenMetaverse; | 33 | using OpenMetaverse; |
33 | using OpenMetaverse.Packets; | 34 | using OpenMetaverse.Packets; |
34 | using OpenSim.Framework; | 35 | using OpenSim.Framework; |
36 | using OpenSim.Region.Framework.Scenes; | ||
35 | using OpenSim.Tests.Common; | 37 | using OpenSim.Tests.Common; |
36 | using OpenSim.Tests.Common.Mock; | 38 | using OpenSim.Tests.Common.Mock; |
37 | 39 | ||
@@ -43,19 +45,22 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
43 | [TestFixture] | 45 | [TestFixture] |
44 | public class BasicCircuitTests | 46 | public class BasicCircuitTests |
45 | { | 47 | { |
46 | [SetUp] | 48 | [TestFixtureSetUp] |
47 | public void Init() | 49 | public void FixtureInit() |
48 | { | 50 | { |
49 | try | 51 | // Don't allow tests to be bamboozled by asynchronous events. Execute everything on the same thread. |
50 | { | 52 | Util.FireAndForgetMethod = FireAndForgetMethod.RegressionTest; |
51 | XmlConfigurator.Configure(); | ||
52 | } | ||
53 | catch | ||
54 | { | ||
55 | // I don't care, just leave log4net off | ||
56 | } | ||
57 | } | 53 | } |
58 | 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 | |||
59 | // /// <summary> | 64 | // /// <summary> |
60 | // /// Add a client for testing | 65 | // /// Add a client for testing |
61 | // /// </summary> | 66 | // /// </summary> |
@@ -78,54 +83,54 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
78 | // testLLUDPServer.LocalScene = scene; | 83 | // testLLUDPServer.LocalScene = scene; |
79 | // } | 84 | // } |
80 | 85 | ||
81 | /// <summary> | 86 | // /// <summary> |
82 | /// Set up a client for tests which aren't concerned with this process itself and where only one client is being | 87 | // /// Set up a client for tests which aren't concerned with this process itself and where only one client is being |
83 | /// tested | 88 | // /// tested |
84 | /// </summary> | 89 | // /// </summary> |
85 | /// <param name="circuitCode"></param> | 90 | // /// <param name="circuitCode"></param> |
86 | /// <param name="epSender"></param> | 91 | // /// <param name="epSender"></param> |
87 | /// <param name="testLLUDPServer"></param> | 92 | // /// <param name="testLLUDPServer"></param> |
88 | /// <param name="acm"></param> | 93 | // /// <param name="acm"></param> |
89 | protected void AddClient( | 94 | // protected void AddClient( |
90 | uint circuitCode, EndPoint epSender, TestLLUDPServer testLLUDPServer, AgentCircuitManager acm) | 95 | // uint circuitCode, EndPoint epSender, TestLLUDPServer testLLUDPServer, AgentCircuitManager acm) |
91 | { | 96 | // { |
92 | UUID myAgentUuid = UUID.Parse("00000000-0000-0000-0000-000000000001"); | 97 | // UUID myAgentUuid = UUID.Parse("00000000-0000-0000-0000-000000000001"); |
93 | UUID mySessionUuid = UUID.Parse("00000000-0000-0000-0000-000000000002"); | 98 | // UUID mySessionUuid = UUID.Parse("00000000-0000-0000-0000-000000000002"); |
94 | 99 | // | |
95 | AddClient(circuitCode, epSender, myAgentUuid, mySessionUuid, testLLUDPServer, acm); | 100 | // AddClient(circuitCode, epSender, myAgentUuid, mySessionUuid, testLLUDPServer, acm); |
96 | } | 101 | // } |
97 | 102 | ||
98 | /// <summary> | 103 | // /// <summary> |
99 | /// Set up a client for tests which aren't concerned with this process itself | 104 | // /// Set up a client for tests which aren't concerned with this process itself |
100 | /// </summary> | 105 | // /// </summary> |
101 | /// <param name="circuitCode"></param> | 106 | // /// <param name="circuitCode"></param> |
102 | /// <param name="epSender"></param> | 107 | // /// <param name="epSender"></param> |
103 | /// <param name="agentId"></param> | 108 | // /// <param name="agentId"></param> |
104 | /// <param name="sessionId"></param> | 109 | // /// <param name="sessionId"></param> |
105 | /// <param name="testLLUDPServer"></param> | 110 | // /// <param name="testLLUDPServer"></param> |
106 | /// <param name="acm"></param> | 111 | // /// <param name="acm"></param> |
107 | protected void AddClient( | 112 | // protected void AddClient( |
108 | uint circuitCode, EndPoint epSender, UUID agentId, UUID sessionId, | 113 | // uint circuitCode, EndPoint epSender, UUID agentId, UUID sessionId, |
109 | TestLLUDPServer testLLUDPServer, AgentCircuitManager acm) | 114 | // TestLLUDPServer testLLUDPServer, AgentCircuitManager acm) |
110 | { | 115 | // { |
111 | AgentCircuitData acd = new AgentCircuitData(); | 116 | // AgentCircuitData acd = new AgentCircuitData(); |
112 | acd.AgentID = agentId; | 117 | // acd.AgentID = agentId; |
113 | acd.SessionID = sessionId; | 118 | // acd.SessionID = sessionId; |
114 | 119 | // | |
115 | UseCircuitCodePacket uccp = new UseCircuitCodePacket(); | 120 | // UseCircuitCodePacket uccp = new UseCircuitCodePacket(); |
116 | 121 | // | |
117 | UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock | 122 | // UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock |
118 | = new UseCircuitCodePacket.CircuitCodeBlock(); | 123 | // = new UseCircuitCodePacket.CircuitCodeBlock(); |
119 | uccpCcBlock.Code = circuitCode; | 124 | // uccpCcBlock.Code = circuitCode; |
120 | uccpCcBlock.ID = agentId; | 125 | // uccpCcBlock.ID = agentId; |
121 | uccpCcBlock.SessionID = sessionId; | 126 | // uccpCcBlock.SessionID = sessionId; |
122 | uccp.CircuitCode = uccpCcBlock; | 127 | // uccp.CircuitCode = uccpCcBlock; |
123 | 128 | // | |
124 | acm.AddNewCircuit(circuitCode, acd); | 129 | // acm.AddNewCircuit(circuitCode, acd); |
125 | 130 | // | |
126 | testLLUDPServer.LoadReceive(uccp, epSender); | 131 | // testLLUDPServer.LoadReceive(uccp, epSender); |
127 | testLLUDPServer.ReceiveData(null); | 132 | // testLLUDPServer.ReceiveData(null); |
128 | } | 133 | // } |
129 | 134 | ||
130 | /// <summary> | 135 | /// <summary> |
131 | /// Build an object name packet for test purposes | 136 | /// Build an object name packet for test purposes |
@@ -144,54 +149,69 @@ namespace OpenSim.Region.ClientStack.LindenUDP.Tests | |||
144 | return onp; | 149 | return onp; |
145 | } | 150 | } |
146 | 151 | ||
147 | // /// <summary> | 152 | /// <summary> |
148 | // /// Test adding a client to the stack | 153 | /// Test adding a client to the stack |
149 | // /// </summary> | 154 | /// </summary> |
150 | // [Test] | 155 | [Test] |
151 | // public void TestAddClient() | 156 | public void TestAddClient() |
152 | // { | 157 | { |
153 | // TestHelper.InMethod(); | 158 | TestHelpers.InMethod(); |
154 | // | 159 | // XmlConfigurator.Configure(); |
155 | // uint myCircuitCode = 123456; | 160 | |
156 | // UUID myAgentUuid = UUID.Parse("00000000-0000-0000-0000-000000000001"); | 161 | TestScene scene = SceneHelpers.SetupScene(); |
157 | // UUID mySessionUuid = UUID.Parse("00000000-0000-0000-0000-000000000002"); | 162 | uint myCircuitCode = 123456; |
158 | // | 163 | UUID myAgentUuid = TestHelpers.ParseTail(0x1); |
159 | // TestLLUDPServer testLLUDPServer; | 164 | UUID mySessionUuid = TestHelpers.ParseTail(0x2); |
160 | // TestLLPacketServer testLLPacketServer; | 165 | IPEndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999); |
161 | // AgentCircuitManager acm; | 166 | |
162 | // SetupStack(new MockScene(), out testLLUDPServer, out testLLPacketServer, out acm); | 167 | uint port = 0; |
163 | // | 168 | AgentCircuitManager acm = scene.AuthenticateHandler; |
164 | // AgentCircuitData acd = new AgentCircuitData(); | 169 | |
165 | // acd.AgentID = myAgentUuid; | 170 | TestLLUDPServer llUdpServer |
166 | // acd.SessionID = mySessionUuid; | 171 | = new TestLLUDPServer(IPAddress.Any, ref port, 0, false, new IniConfigSource(), acm); |
167 | // | 172 | llUdpServer.AddScene(scene); |
168 | // UseCircuitCodePacket uccp = new UseCircuitCodePacket(); | 173 | |
169 | // | 174 | UseCircuitCodePacket uccp = new UseCircuitCodePacket(); |
170 | // UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock | 175 | |
171 | // = new UseCircuitCodePacket.CircuitCodeBlock(); | 176 | UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock |
172 | // uccpCcBlock.Code = myCircuitCode; | 177 | = new UseCircuitCodePacket.CircuitCodeBlock(); |
173 | // uccpCcBlock.ID = myAgentUuid; | 178 | uccpCcBlock.Code = myCircuitCode; |
174 | // uccpCcBlock.SessionID = mySessionUuid; | 179 | uccpCcBlock.ID = myAgentUuid; |
175 | // uccp.CircuitCode = uccpCcBlock; | 180 | uccpCcBlock.SessionID = mySessionUuid; |
176 | // | 181 | uccp.CircuitCode = uccpCcBlock; |
177 | // EndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999); | 182 | |
178 | // | 183 | byte[] uccpBytes = uccp.ToBytes(); |
179 | // testLLUDPServer.LoadReceive(uccp, testEp); | 184 | UDPPacketBuffer upb = new UDPPacketBuffer(testEp, uccpBytes.Length); |
180 | // testLLUDPServer.ReceiveData(null); | 185 | upb.DataLength = uccpBytes.Length; // God knows why this isn't set by the constructor. |
181 | // | 186 | Buffer.BlockCopy(uccpBytes, 0, upb.Data, 0, uccpBytes.Length); |
182 | // // Circuit shouildn't exist since the circuit manager doesn't know about this circuit for authentication yet | 187 | |
183 | // Assert.IsFalse(testLLUDPServer.HasCircuit(myCircuitCode)); | 188 | llUdpServer.PacketReceived(upb); |
184 | // | 189 | |
185 | // acm.AddNewCircuit(myCircuitCode, acd); | 190 | // Presence shouldn't exist since the circuit manager doesn't know about this circuit for authentication yet |
186 | // | 191 | Assert.That(scene.GetScenePresence(myAgentUuid), Is.Null); |
187 | // testLLUDPServer.LoadReceive(uccp, testEp); | 192 | |
188 | // testLLUDPServer.ReceiveData(null); | 193 | AgentCircuitData acd = new AgentCircuitData(); |
189 | // | 194 | acd.AgentID = myAgentUuid; |
190 | // // Should succeed now | 195 | acd.SessionID = mySessionUuid; |
191 | // Assert.IsTrue(testLLUDPServer.HasCircuit(myCircuitCode)); | 196 | |
192 | // Assert.IsFalse(testLLUDPServer.HasCircuit(101)); | 197 | acm.AddNewCircuit(myCircuitCode, acd); |
193 | // } | 198 | |
194 | // | 199 | llUdpServer.PacketReceived(upb); |
200 | |||
201 | // Should succeed now | ||
202 | ScenePresence sp = scene.GetScenePresence(myAgentUuid); | ||
203 | Assert.That(sp.UUID, Is.EqualTo(myAgentUuid)); | ||
204 | |||
205 | Assert.That(llUdpServer.PacketsSent.Count, Is.EqualTo(1)); | ||
206 | |||
207 | Packet packet = llUdpServer.PacketsSent[0]; | ||
208 | Assert.That(packet, Is.InstanceOf(typeof(PacketAckPacket))); | ||
209 | |||
210 | PacketAckPacket ackPacket = packet as PacketAckPacket; | ||
211 | Assert.That(ackPacket.Packets.Length, Is.EqualTo(1)); | ||
212 | Assert.That(ackPacket.Packets[0].ID, Is.EqualTo(0)); | ||
213 | } | ||
214 | |||
195 | // /// <summary> | 215 | // /// <summary> |
196 | // /// Test removing a client from the stack | 216 | // /// Test removing a client from the stack |
197 | // /// </summary> | 217 | // /// </summary> |