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 OpenMetaverse; |
||
30 | using OpenMetaverse.Packets; |
||
31 | using NUnit.Framework; |
||
32 | |||
33 | namespace OpenMetaverse.Tests |
||
34 | { |
||
35 | [TestFixture] |
||
36 | public class PacketTests : Assert |
||
37 | { |
||
38 | [Test] |
||
39 | public void HeaderFlags() |
||
40 | { |
||
41 | TestMessagePacket packet = new TestMessagePacket(); |
||
42 | |||
43 | packet.Header.AppendedAcks = false; |
||
44 | packet.Header.Reliable = false; |
||
45 | packet.Header.Resent = false; |
||
46 | packet.Header.Zerocoded = false; |
||
47 | |||
48 | Assert.IsFalse(packet.Header.AppendedAcks, "AppendedAcks: Failed to initially set the flag to false"); |
||
49 | Assert.IsFalse(packet.Header.Reliable, "Reliable: Failed to initially set the flag to false"); |
||
50 | Assert.IsFalse(packet.Header.Resent, "Resent: Failed to initially set the flag to false"); |
||
51 | Assert.IsFalse(packet.Header.Zerocoded, "Zerocoded: Failed to initially set the flag to false"); |
||
52 | |||
53 | packet.Header.AppendedAcks = false; |
||
54 | packet.Header.Reliable = false; |
||
55 | packet.Header.Resent = false; |
||
56 | packet.Header.Zerocoded = false; |
||
57 | |||
58 | Assert.IsFalse(packet.Header.AppendedAcks, "AppendedAcks: Failed to set the flag to false a second time"); |
||
59 | Assert.IsFalse(packet.Header.Reliable, "Reliable: Failed to set the flag to false a second time"); |
||
60 | Assert.IsFalse(packet.Header.Resent, "Resent: Failed to set the flag to false a second time"); |
||
61 | Assert.IsFalse(packet.Header.Zerocoded, "Zerocoded: Failed to set the flag to false a second time"); |
||
62 | |||
63 | packet.Header.AppendedAcks = true; |
||
64 | packet.Header.Reliable = true; |
||
65 | packet.Header.Resent = true; |
||
66 | packet.Header.Zerocoded = true; |
||
67 | |||
68 | Assert.IsTrue(packet.Header.AppendedAcks, "AppendedAcks: Failed to set the flag to true"); |
||
69 | Assert.IsTrue(packet.Header.Reliable, "Reliable: Failed to set the flag to true"); |
||
70 | Assert.IsTrue(packet.Header.Resent, "Resent: Failed to set the flag to true"); |
||
71 | Assert.IsTrue(packet.Header.Zerocoded, "Zerocoded: Failed to set the flag to true"); |
||
72 | |||
73 | packet.Header.AppendedAcks = true; |
||
74 | packet.Header.Reliable = true; |
||
75 | packet.Header.Resent = true; |
||
76 | packet.Header.Zerocoded = true; |
||
77 | |||
78 | Assert.IsTrue(packet.Header.AppendedAcks, "AppendedAcks: Failed to set the flag to true a second time"); |
||
79 | Assert.IsTrue(packet.Header.Reliable, "Reliable: Failed to set the flag to true a second time"); |
||
80 | Assert.IsTrue(packet.Header.Resent, "Resent: Failed to set the flag to true a second time"); |
||
81 | Assert.IsTrue(packet.Header.Zerocoded, "Zerocoded: Failed to set the flag to true a second time"); |
||
82 | |||
83 | packet.Header.AppendedAcks = false; |
||
84 | packet.Header.Reliable = false; |
||
85 | packet.Header.Resent = false; |
||
86 | packet.Header.Zerocoded = false; |
||
87 | |||
88 | Assert.IsFalse(packet.Header.AppendedAcks, "AppendedAcks: Failed to set the flag back to false"); |
||
89 | Assert.IsFalse(packet.Header.Reliable, "Reliable: Failed to set the flag back to false"); |
||
90 | Assert.IsFalse(packet.Header.Resent, "Resent: Failed to set the flag back to false"); |
||
91 | Assert.IsFalse(packet.Header.Zerocoded, "Zerocoded: Failed to set the flag back to false"); |
||
92 | } |
||
93 | |||
94 | [Test] |
||
95 | public void ToBytesMultiple() |
||
96 | { |
||
97 | UUID testID = UUID.Random(); |
||
98 | |||
99 | DirPlacesReplyPacket bigPacket = new DirPlacesReplyPacket(); |
||
100 | bigPacket.Header.Zerocoded = false; |
||
101 | bigPacket.Header.Sequence = 42; |
||
102 | bigPacket.Header.AppendedAcks = true; |
||
103 | bigPacket.Header.AckList = new uint[50]; |
||
104 | for (int i = 0; i < bigPacket.Header.AckList.Length; i++) { bigPacket.Header.AckList[i] = (uint)i; } |
||
105 | bigPacket.AgentData.AgentID = testID; |
||
106 | bigPacket.QueryData = new DirPlacesReplyPacket.QueryDataBlock[100]; |
||
107 | for (int i = 0; i < bigPacket.QueryData.Length; i++) |
||
108 | { |
||
109 | bigPacket.QueryData[i] = new DirPlacesReplyPacket.QueryDataBlock(); |
||
110 | bigPacket.QueryData[i].QueryID = testID; |
||
111 | } |
||
112 | bigPacket.QueryReplies = new DirPlacesReplyPacket.QueryRepliesBlock[100]; |
||
113 | for (int i = 0; i < bigPacket.QueryReplies.Length; i++) |
||
114 | { |
||
115 | bigPacket.QueryReplies[i] = new DirPlacesReplyPacket.QueryRepliesBlock(); |
||
116 | bigPacket.QueryReplies[i].Auction = (i & 1) == 0; |
||
117 | bigPacket.QueryReplies[i].Dwell = (float)i; |
||
118 | bigPacket.QueryReplies[i].ForSale = (i & 1) == 0; |
||
119 | bigPacket.QueryReplies[i].Name = Utils.StringToBytes("DirPlacesReply Test String"); |
||
120 | bigPacket.QueryReplies[i].ParcelID = testID; |
||
121 | } |
||
122 | bigPacket.StatusData = new DirPlacesReplyPacket.StatusDataBlock[100]; |
||
123 | for (int i = 0; i < bigPacket.StatusData.Length; i++) |
||
124 | { |
||
125 | bigPacket.StatusData[i] = new DirPlacesReplyPacket.StatusDataBlock(); |
||
126 | bigPacket.StatusData[i].Status = (uint)i; |
||
127 | } |
||
128 | |||
129 | byte[][] splitPackets = bigPacket.ToBytesMultiple(); |
||
130 | |||
131 | int queryDataCount = 0; |
||
132 | int queryRepliesCount = 0; |
||
133 | int statusDataCount = 0; |
||
134 | for (int i = 0; i < splitPackets.Length; i++) |
||
135 | { |
||
136 | byte[] packetData = splitPackets[i]; |
||
137 | int len = packetData.Length - 1; |
||
138 | DirPlacesReplyPacket packet = (DirPlacesReplyPacket)Packet.BuildPacket(packetData, ref len, packetData); |
||
139 | |||
140 | Assert.IsTrue(packet.AgentData.AgentID == bigPacket.AgentData.AgentID); |
||
141 | |||
142 | for (int j = 0; j < packet.QueryReplies.Length; j++) |
||
143 | { |
||
144 | Assert.IsTrue(packet.QueryReplies[j].Dwell == (float)(queryRepliesCount + j), |
||
145 | "Expected Dwell of " + (float)(queryRepliesCount + j) + " but got " + packet.QueryReplies[j].Dwell); |
||
146 | Assert.IsTrue(packet.QueryReplies[j].ParcelID == testID); |
||
147 | } |
||
148 | |||
149 | queryDataCount += packet.QueryData.Length; |
||
150 | queryRepliesCount += packet.QueryReplies.Length; |
||
151 | statusDataCount += packet.StatusData.Length; |
||
152 | } |
||
153 | |||
154 | Assert.IsTrue(queryDataCount == bigPacket.QueryData.Length); |
||
155 | Assert.IsTrue(queryRepliesCount == bigPacket.QueryData.Length); |
||
156 | Assert.IsTrue(statusDataCount == bigPacket.StatusData.Length); |
||
157 | |||
158 | ScriptDialogPacket scriptDialogPacket = new ScriptDialogPacket(); |
||
159 | scriptDialogPacket.Data.ChatChannel = 0; |
||
160 | scriptDialogPacket.Data.FirstName = Utils.EmptyBytes; |
||
161 | scriptDialogPacket.Data.ImageID = UUID.Zero; |
||
162 | scriptDialogPacket.Data.LastName = Utils.EmptyBytes; |
||
163 | scriptDialogPacket.Data.Message = Utils.EmptyBytes; |
||
164 | scriptDialogPacket.Data.ObjectID = UUID.Zero; |
||
165 | scriptDialogPacket.Data.ObjectName = Utils.EmptyBytes; |
||
166 | scriptDialogPacket.Buttons = new ScriptDialogPacket.ButtonsBlock[0]; |
||
167 | scriptDialogPacket.OwnerData = new ScriptDialogPacket.OwnerDataBlock[1]; |
||
168 | scriptDialogPacket.OwnerData[0] = new ScriptDialogPacket.OwnerDataBlock(); |
||
169 | scriptDialogPacket.OwnerData[0].OwnerID = UUID.Zero; |
||
170 | |||
171 | byte[][] splitPacket = scriptDialogPacket.ToBytesMultiple(); |
||
172 | |||
173 | Assert.IsNotNull(splitPacket); |
||
174 | Assert.IsTrue(splitPacket.Length == 1, "Expected ScriptDialog packet to split into 1 packet but got " + splitPacket.Length); |
||
175 | |||
176 | ParcelReturnObjectsPacket proPacket = new ParcelReturnObjectsPacket(); |
||
177 | proPacket.AgentData.AgentID = UUID.Zero; |
||
178 | proPacket.AgentData.SessionID = UUID.Zero; |
||
179 | proPacket.ParcelData.LocalID = 0; |
||
180 | proPacket.ParcelData.ReturnType = 0; |
||
181 | proPacket.TaskIDs = new ParcelReturnObjectsPacket.TaskIDsBlock[0]; |
||
182 | proPacket.OwnerIDs = new ParcelReturnObjectsPacket.OwnerIDsBlock[1]; |
||
183 | proPacket.OwnerIDs[0] = new ParcelReturnObjectsPacket.OwnerIDsBlock(); |
||
184 | proPacket.OwnerIDs[0].OwnerID = UUID.Zero; |
||
185 | |||
186 | splitPacket = proPacket.ToBytesMultiple(); |
||
187 | |||
188 | Assert.IsNotNull(splitPacket); |
||
189 | Assert.IsTrue(splitPacket.Length == 1, "Expected ParcelReturnObjectsPacket packet to split into 1 packet but got " + splitPacket.Length); |
||
190 | |||
191 | InventoryDescendentsPacket invPacket = new InventoryDescendentsPacket(); |
||
192 | invPacket.FolderData = new InventoryDescendentsPacket.FolderDataBlock[1]; |
||
193 | invPacket.FolderData[0] = new InventoryDescendentsPacket.FolderDataBlock(); |
||
194 | invPacket.FolderData[0].Name = Utils.EmptyBytes; |
||
195 | invPacket.ItemData = new InventoryDescendentsPacket.ItemDataBlock[5]; |
||
196 | for (int i = 0; i < 5; i++) |
||
197 | { |
||
198 | invPacket.ItemData[i] = new InventoryDescendentsPacket.ItemDataBlock(); |
||
199 | invPacket.ItemData[i].Description = Utils.StringToBytes("Unit Test Item Description"); |
||
200 | invPacket.ItemData[i].Name = Utils.StringToBytes("Unit Test Item Name"); |
||
201 | } |
||
202 | |||
203 | splitPacket = invPacket.ToBytesMultiple(); |
||
204 | |||
205 | Assert.IsNotNull(splitPacket); |
||
206 | Assert.IsTrue(splitPacket.Length == 1, "Split InventoryDescendents packet into " + splitPacket.Length + " instead of 1 packet"); |
||
207 | |||
208 | int x = 0; |
||
209 | int y = splitPacket[0].Length - 1; |
||
210 | invPacket.FromBytes(splitPacket[0], ref x, ref y, null); |
||
211 | |||
212 | Assert.IsTrue(invPacket.FolderData.Length == 1, "InventoryDescendents packet came back with " + invPacket.FolderData.Length + " FolderData blocks"); |
||
213 | Assert.IsTrue(invPacket.ItemData.Length == 5, "InventoryDescendents packet came back with " + invPacket.ItemData.Length + " ItemData blocks"); |
||
214 | } |
||
215 | } |
||
216 | } |