From f4ad99f89d4d04f71852e2ebadd36b9a993123f8 Mon Sep 17 00:00:00 2001 From: Justin Clarke Casey Date: Thu, 23 Oct 2008 19:08:54 +0000 Subject: * Introduce a basic udp circuit test for adding a client * Temporarily disabled assert because it just picked up an existing bug. Yay for tests! --- .../LindenUDP/Tests/BasicCircuitTests.cs | 33 +++++++++-- .../ClientStack/LindenUDP/Tests/TestLLUDPServer.cs | 66 +++++++++++++++++++++- 2 files changed, 91 insertions(+), 8 deletions(-) (limited to 'OpenSim/Region/ClientStack/LindenUDP') diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs index cf24e58..e32e423 100644 --- a/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/BasicCircuitTests.cs @@ -26,6 +26,7 @@ */ using System.Net; +using log4net; using NUnit.Framework; using OpenMetaverse.Packets; using OpenSim.Framework; @@ -33,7 +34,7 @@ using OpenSim.Framework.Communications; using OpenSim.Region.ClientStack; using OpenSim.Region.ClientStack.LindenUDP; -namespace OpenSim.Region.ClientStack.LindenUDP +namespace OpenSim.Region.ClientStack.LindenUDP.Tests { /// /// This will contain basic tests for the LindenUDP client stack @@ -44,13 +45,35 @@ namespace OpenSim.Region.ClientStack.LindenUDP [Test] public void TestAddClient() { - TestLLUDPServer testLLUDPServer = new TestLLUDPServer(); + try + { + log4net.Config.XmlConfigurator.Configure(); + } + catch + { + // I don't care, just leave log4net off + } + + TestLLUDPServer testLLUDPServer = new TestLLUDPServer(); + ClientStackUserSettings userSettings = new ClientStackUserSettings(); uint port = 666; - testLLUDPServer.Initialise(null, ref port, -1, false, new ClientStackUserSettings(), null, null); + testLLUDPServer.Initialise(null, ref port, 0, false, userSettings, null, null); + LLPacketServer packetServer = new LLPacketServer(testLLUDPServer, userSettings); + testLLUDPServer.LocalScene = new MockScene(); + + UseCircuitCodePacket uccp = new UseCircuitCodePacket(); + UseCircuitCodePacket.CircuitCodeBlock uccpCcBlock + = new OpenMetaverse.Packets.UseCircuitCodePacket.CircuitCodeBlock(); + uccpCcBlock.Code = 123456; + uccp.CircuitCode = uccpCcBlock; + + EndPoint testEp = new IPEndPoint(IPAddress.Loopback, 999); + + testLLUDPServer.LoadReceive(uccp, testEp); + testLLUDPServer.ReceiveData(null); - //UseCircuitCodePacket uccp = new UseCircuitCodePacket(); - //llUdpServer.epS + //Assert.IsTrue(testLLUDPServer.HasCircuit(123456)); } } } diff --git a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs index 5e7cbca..bd5b282 100755 --- a/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs +++ b/OpenSim/Region/ClientStack/LindenUDP/Tests/TestLLUDPServer.cs @@ -26,11 +26,13 @@ */ using System; +using System.Collections.Generic; using System.Net; +using OpenMetaverse.Packets; using OpenSim.Framework; using OpenSim.Framework.Communications.Cache; -namespace OpenSim.Region.ClientStack.LindenUDP +namespace OpenSim.Region.ClientStack.LindenUDP.Tests { /// /// This class enables synchronous testing of the LLUDPServer by allowing us to load our own data into the end @@ -38,6 +40,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// public class TestLLUDPServer : LLUDPServer { + /// + /// The chunks of data to pass to the LLUDPServer when it calls EndReceive + /// + protected Queue m_chunksToLoad = new Queue(); + protected override void BeginReceive() { // Do nothing @@ -45,10 +52,63 @@ namespace OpenSim.Region.ClientStack.LindenUDP protected override bool EndReceive(out int numBytes, IAsyncResult result, ref EndPoint epSender) { - // TODO: Return a packet loaded in by a test numBytes = 0; + if (m_chunksToLoad.Count <= 0) + return false; + + ChunkSenderTuple tuple = m_chunksToLoad.Dequeue(); + RecvBuffer = tuple.Data; + numBytes = tuple.Data.Length; + epSender = tuple.Sender; + return true; } + + /// + /// Load a packet to be received by the LLUDPServer on the next receive call + /// + /// + public void LoadReceive(Packet packet, EndPoint epSender) + { + m_chunksToLoad.Enqueue(new ChunkSenderTuple(packet.ToBytes(), epSender)); + } + + /// + /// Calls the protected asynchronous result method + /// + /// + public void ReceiveData(IAsyncResult result) + { + OnReceivedData(result); + } + + /// + /// Has a circuit with the given code been established? + /// + /// + /// + public bool HasCircuit(uint circuitCode) + { + lock (clientCircuits_reverse) + { + return clientCircuits_reverse.ContainsKey(circuitCode); + } + } + } + + /// + /// Record the data and sender tuple + /// + public class ChunkSenderTuple + { + public byte[] Data; + public EndPoint Sender; + + public ChunkSenderTuple(byte[] data, EndPoint sender) + { + Data = data; + Sender = sender; + } } -} +} \ No newline at end of file -- cgit v1.1