corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * Copyright (c) 2006-2014, openmetaverse.org |
||
3 | * All rights reserved. |
||
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 | * |
||
8 | * - Redistributions of source code must retain the above copyright notice, this |
||
9 | * list of conditions and the following disclaimer. |
||
10 | * - Neither the name of the openmetaverse.org nor the names |
||
11 | * of its contributors may be used to endorse or promote products derived from |
||
12 | * this software without specific prior written permission. |
||
13 | * |
||
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
24 | * POSSIBILITY OF SUCH DAMAGE. |
||
25 | */ |
||
26 | |||
27 | using System; |
||
28 | using System.Collections.Generic; |
||
29 | using System.Net; |
||
30 | using OpenMetaverse; |
||
31 | using OpenMetaverse.Packets; |
||
32 | using NUnit.Framework; |
||
33 | |||
34 | namespace OpenMetaverse.Tests |
||
35 | { |
||
36 | [TestFixture] |
||
37 | [Category("Network")] |
||
38 | public class NetworkTests : Assert |
||
39 | { |
||
40 | GridClient Client; |
||
41 | |||
42 | //ulong CurrentRegionHandle = 0; |
||
43 | //ulong AhernRegionHandle = 1096213093149184; |
||
44 | //ulong MorrisRegionHandle = 1096213093149183; |
||
45 | //ulong DoreRegionHandle = 1095113581521408; |
||
46 | //ulong HooperRegionHandle = 1106108697797888; |
||
47 | bool DetectedObject = false; |
||
48 | |||
49 | public NetworkTests() |
||
50 | { |
||
51 | Client = new GridClient(); |
||
52 | Client.Self.Movement.Fly = true; |
||
53 | // Register callbacks |
||
54 | Client.Network.RegisterCallback(PacketType.ObjectUpdate, ObjectUpdateHandler); |
||
55 | //Client.Self.OnTeleport += new MainAvatar.TeleportCallback(OnTeleportHandler) |
||
56 | } |
||
57 | |||
58 | [TestFixtureSetUp] |
||
59 | public void Init() |
||
60 | { |
||
61 | Console.Write("Logging in Testing Anvil..."); |
||
62 | // Connect to the grid |
||
63 | string startLoc = NetworkManager.StartLocation("Hooper", 179, 18, 32); |
||
64 | Assert.IsTrue(Client.Network.Login("Testing", "Anvil", "testinganvil", "Unit Test Framework", startLoc, |
||
65 | "contact@OpenMetaverse.org"), "Client failed to login, reason: " + Client.Network.LoginMessage); |
||
66 | Console.WriteLine("Done"); |
||
67 | |||
68 | Assert.IsTrue(Client.Network.Connected, "Client is not connected to the grid"); |
||
69 | |||
70 | //int start = Environment.TickCount; |
||
71 | |||
72 | Assert.AreEqual("hooper", Client.Network.CurrentSim.Name.ToLower(), "Logged in to sim " + |
||
73 | Client.Network.CurrentSim.Name + " instead of hooper"); |
||
74 | } |
||
75 | |||
76 | [Test] |
||
77 | public void DetectObjects() |
||
78 | { |
||
79 | int start = Environment.TickCount; |
||
80 | while (!DetectedObject) |
||
81 | { |
||
82 | if (Environment.TickCount - start > 20000) |
||
83 | { |
||
84 | Assert.Fail("Timeout waiting for an ObjectUpdate packet"); |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | |||
89 | /* |
||
90 | [Test] |
||
91 | public void U64Receive() |
||
92 | { |
||
93 | int start = Environment.TickCount; |
||
94 | while (CurrentRegionHandle == 0) |
||
95 | { |
||
96 | if (Environment.TickCount - start > 10000) |
||
97 | { |
||
98 | Assert.Fail("Timeout waiting for an ObjectUpdate packet"); |
||
99 | } |
||
100 | } |
||
101 | |||
102 | Assert.IsTrue(CurrentRegionHandle == HooperRegionHandle, "Current region is " + |
||
103 | CurrentRegionHandle + " (" + Client.Network.CurrentSim.Name + ")" + " when we were expecting " + HooperRegionHandle + " (Dore), possible endian issue"); |
||
104 | } |
||
105 | */ |
||
106 | /*[Test] |
||
107 | public void Teleport() |
||
108 | { |
||
109 | // test in-sim teleports |
||
110 | Assert.IsTrue(CapsQueueRunning(), "CAPS Event queue is not running in " + Client.Network.CurrentSim.Name); |
||
111 | string localSimName = Client.Network.CurrentSim.Name; |
||
112 | Assert.IsTrue(Client.Self.Teleport(Client.Network.CurrentSim.Handle, new Vector3(121, 13, 41)), |
||
113 | "Teleport In-Sim Failed " + Client.Network.CurrentSim.Name); |
||
114 | |||
115 | // Assert that we really did make it to our scheduled destination |
||
116 | Assert.AreEqual(localSimName, Client.Network.CurrentSim.Name, |
||
117 | "Expected to teleport to " + localSimName + ", ended up in " + Client.Network.CurrentSim.Name + |
||
118 | ". Possibly region full or offline?"); |
||
119 | |||
120 | Assert.IsTrue(CapsQueueRunning(), "CAPS Event queue is not running in " + Client.Network.CurrentSim.Name); |
||
121 | Assert.IsTrue(Client.Self.Teleport(DoreRegionHandle, new Vector3(128, 128, 32)), |
||
122 | "Teleport to Dore failed"); |
||
123 | |||
124 | // Assert that we really did make it to our scheduled destination |
||
125 | Assert.AreEqual("dore", Client.Network.CurrentSim.Name.ToLower(), |
||
126 | "Expected to teleport to Dore, ended up in " + Client.Network.CurrentSim.Name + |
||
127 | ". Possibly region full or offline?"); |
||
128 | |||
129 | Assert.IsTrue(CapsQueueRunning(), "CAPS Event queue is not running in " + Client.Network.CurrentSim.Name); |
||
130 | Assert.IsTrue(Client.Self.Teleport(HooperRegionHandle, new Vector3(179, 18, 32)), |
||
131 | "Teleport to Hooper failed"); |
||
132 | |||
133 | // Assert that we really did make it to our scheduled destination |
||
134 | Assert.AreEqual("hooper", Client.Network.CurrentSim.Name.ToLower(), |
||
135 | "Expected to teleport to Hooper, ended up in " + Client.Network.CurrentSim.Name + |
||
136 | ". Possibly region full or offline?"); |
||
137 | }*/ |
||
138 | |||
139 | [Test] |
||
140 | public void CapsQueue() |
||
141 | { |
||
142 | Assert.IsTrue(CapsQueueRunning(), "CAPS Event Queue is not running and failed to start"); |
||
143 | } |
||
144 | |||
145 | public bool CapsQueueRunning() |
||
146 | { |
||
147 | if (Client.Network.CurrentSim.Caps.IsEventQueueRunning) |
||
148 | return true; |
||
149 | |||
150 | bool Success = false; |
||
151 | // make sure caps event queue is running |
||
152 | System.Threading.AutoResetEvent waitforCAPS = new System.Threading.AutoResetEvent(false); |
||
153 | EventHandler<EventQueueRunningEventArgs> capsRunning = delegate(object sender, EventQueueRunningEventArgs e) |
||
154 | { |
||
155 | waitforCAPS.Set(); |
||
156 | }; |
||
157 | |||
158 | Client.Network.EventQueueRunning += capsRunning; |
||
159 | if (waitforCAPS.WaitOne(10000, false)) |
||
160 | { |
||
161 | Success = true; |
||
162 | } |
||
163 | else |
||
164 | { |
||
165 | Success = false; |
||
166 | Assert.Fail("Timeout waiting for event Queue to startup"); |
||
167 | } |
||
168 | Client.Network.EventQueueRunning -= capsRunning; |
||
169 | return Success; |
||
170 | } |
||
171 | |||
172 | private void ObjectUpdateHandler(object sender, PacketReceivedEventArgs e) |
||
173 | { |
||
174 | //ObjectUpdatePacket update = (ObjectUpdatePacket)packet; |
||
175 | |||
176 | DetectedObject = true; |
||
177 | //CurrentRegionHandle = update.RegionData.RegionHandle; |
||
178 | } |
||
179 | |||
180 | [TestFixtureTearDown] |
||
181 | public void Shutdown() |
||
182 | { |
||
183 | Console.Write("Logging out..."); |
||
184 | Client.Network.Logout(); |
||
185 | Console.WriteLine("Done"); |
||
186 | } |
||
187 | } |
||
188 | } |