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 | /* |
||
28 | * |
||
29 | * This tests are based upon the description at |
||
30 | * |
||
31 | * http://wiki.secondlife.com/wiki/SD |
||
32 | * |
||
33 | * and (partially) generated by the (supposed) reference implementation at |
||
34 | * |
||
35 | * http://svn.secondlife.com/svn/linden/release/indra/lib/python/indra/base/llsd.py |
||
36 | * |
||
37 | */ |
||
38 | |||
39 | using System; |
||
40 | using System.IO; |
||
41 | using System.Text; |
||
42 | using System.Xml; |
||
43 | using NUnit.Framework; |
||
44 | using OpenMetaverse.StructuredData; |
||
45 | |||
46 | namespace OpenMetaverse.Tests |
||
47 | { |
||
48 | |||
49 | [TestFixture()] |
||
50 | public class NotationSDTests |
||
51 | { |
||
52 | [Test()] |
||
53 | public void HelperFunctions() |
||
54 | { |
||
55 | StringReader reader = new StringReader("test1tast2test3"); |
||
56 | |||
57 | char[] charsOne = { 't', 'e', 's', 't' }; |
||
58 | int resultOne = OSDParser.BufferCharactersEqual(reader, charsOne, 0); |
||
59 | Assert.AreEqual(charsOne.Length, resultOne); |
||
60 | |||
61 | char[] charsTwo = { '1', 't', 'e' }; |
||
62 | int resultTwo = OSDParser.BufferCharactersEqual(reader, charsTwo, 0); |
||
63 | Assert.AreEqual(2, resultTwo); |
||
64 | |||
65 | char[] charsThree = { 'a', 's', 't', '2', 't', 'e', 's' }; |
||
66 | int resultThree = OSDParser.BufferCharactersEqual(reader, charsThree, 1); |
||
67 | Assert.AreEqual(1, resultThree); |
||
68 | |||
69 | int resultFour = OSDParser.BufferCharactersEqual(reader, charsThree, 0); |
||
70 | Assert.AreEqual(charsThree.Length, resultFour); |
||
71 | |||
72 | char[] charsFive = { 't', '3', 'a', 'a' }; |
||
73 | int resultFive = OSDParser.BufferCharactersEqual(reader, charsFive, 0); |
||
74 | Assert.AreEqual(2, resultFive); |
||
75 | |||
76 | |||
77 | } |
||
78 | |||
79 | [Test()] |
||
80 | public void DeserializeUndef() |
||
81 | { |
||
82 | String s = "!"; |
||
83 | OSD llsd = OSDParser.DeserializeLLSDNotation(s); |
||
84 | Assert.AreEqual(OSDType.Unknown, llsd.Type); |
||
85 | } |
||
86 | |||
87 | [Test()] |
||
88 | public void SerializeUndef() |
||
89 | { |
||
90 | OSD llsd = new OSD(); |
||
91 | string s = OSDParser.SerializeLLSDNotation(llsd); |
||
92 | |||
93 | OSD llsdDS = OSDParser.DeserializeLLSDNotation(s); |
||
94 | Assert.AreEqual(OSDType.Unknown, llsdDS.Type); |
||
95 | } |
||
96 | |||
97 | [Test()] |
||
98 | public void DeserializeBoolean() |
||
99 | { |
||
100 | String t = "true"; |
||
101 | OSD llsdT = OSDParser.DeserializeLLSDNotation(t); |
||
102 | Assert.AreEqual(OSDType.Boolean, llsdT.Type); |
||
103 | Assert.AreEqual(true, llsdT.AsBoolean()); |
||
104 | |||
105 | String tTwo = "t"; |
||
106 | OSD llsdTTwo = OSDParser.DeserializeLLSDNotation(tTwo); |
||
107 | Assert.AreEqual(OSDType.Boolean, llsdTTwo.Type); |
||
108 | Assert.AreEqual(true, llsdTTwo.AsBoolean()); |
||
109 | |||
110 | String tThree = "TRUE"; |
||
111 | OSD llsdTThree = OSDParser.DeserializeLLSDNotation(tThree); |
||
112 | Assert.AreEqual(OSDType.Boolean, llsdTThree.Type); |
||
113 | Assert.AreEqual(true, llsdTThree.AsBoolean()); |
||
114 | |||
115 | String tFour = "T"; |
||
116 | OSD llsdTFour = OSDParser.DeserializeLLSDNotation(tFour); |
||
117 | Assert.AreEqual(OSDType.Boolean, llsdTFour.Type); |
||
118 | Assert.AreEqual(true, llsdTFour.AsBoolean()); |
||
119 | |||
120 | String tFive = "1"; |
||
121 | OSD llsdTFive = OSDParser.DeserializeLLSDNotation(tFive); |
||
122 | Assert.AreEqual(OSDType.Boolean, llsdTFive.Type); |
||
123 | Assert.AreEqual(true, llsdTFive.AsBoolean()); |
||
124 | |||
125 | String f = "false"; |
||
126 | OSD llsdF = OSDParser.DeserializeLLSDNotation(f); |
||
127 | Assert.AreEqual(OSDType.Boolean, llsdF.Type); |
||
128 | Assert.AreEqual(false, llsdF.AsBoolean()); |
||
129 | |||
130 | String fTwo = "f"; |
||
131 | OSD llsdFTwo = OSDParser.DeserializeLLSDNotation(fTwo); |
||
132 | Assert.AreEqual(OSDType.Boolean, llsdFTwo.Type); |
||
133 | Assert.AreEqual(false, llsdFTwo.AsBoolean()); |
||
134 | |||
135 | String fThree = "FALSE"; |
||
136 | OSD llsdFThree = OSDParser.DeserializeLLSDNotation(fThree); |
||
137 | Assert.AreEqual(OSDType.Boolean, llsdFThree.Type); |
||
138 | Assert.AreEqual(false, llsdFThree.AsBoolean()); |
||
139 | |||
140 | String fFour = "F"; |
||
141 | OSD llsdFFour = OSDParser.DeserializeLLSDNotation(fFour); |
||
142 | Assert.AreEqual(OSDType.Boolean, llsdFFour.Type); |
||
143 | Assert.AreEqual(false, llsdFFour.AsBoolean()); |
||
144 | |||
145 | String fFive = "0"; |
||
146 | OSD llsdFFive = OSDParser.DeserializeLLSDNotation(fFive); |
||
147 | Assert.AreEqual(OSDType.Boolean, llsdFFive.Type); |
||
148 | Assert.AreEqual(false, llsdFFive.AsBoolean()); |
||
149 | } |
||
150 | |||
151 | [Test()] |
||
152 | public void SerializeBoolean() |
||
153 | { |
||
154 | OSD llsdTrue = OSD.FromBoolean(true); |
||
155 | string sTrue = OSDParser.SerializeLLSDNotation(llsdTrue); |
||
156 | OSD llsdTrueDS = OSDParser.DeserializeLLSDNotation(sTrue); |
||
157 | Assert.AreEqual(OSDType.Boolean, llsdTrueDS.Type); |
||
158 | Assert.AreEqual(true, llsdTrueDS.AsBoolean()); |
||
159 | |||
160 | OSD llsdFalse = OSD.FromBoolean(false); |
||
161 | string sFalse = OSDParser.SerializeLLSDNotation(llsdFalse); |
||
162 | OSD llsdFalseDS = OSDParser.DeserializeLLSDNotation(sFalse); |
||
163 | Assert.AreEqual(OSDType.Boolean, llsdFalseDS.Type); |
||
164 | Assert.AreEqual(false, llsdFalseDS.AsBoolean()); |
||
165 | } |
||
166 | |||
167 | [Test()] |
||
168 | public void DeserializeInteger() |
||
169 | { |
||
170 | string integerOne = "i12319423"; |
||
171 | OSD llsdOne = OSDParser.DeserializeLLSDNotation(integerOne); |
||
172 | Assert.AreEqual(OSDType.Integer, llsdOne.Type); |
||
173 | Assert.AreEqual(12319423, llsdOne.AsInteger()); |
||
174 | |||
175 | string integerTwo = "i-489234"; |
||
176 | OSD llsdTwo = OSDParser.DeserializeLLSDNotation(integerTwo); |
||
177 | Assert.AreEqual(OSDType.Integer, llsdTwo.Type); |
||
178 | Assert.AreEqual(-489234, llsdTwo.AsInteger()); |
||
179 | } |
||
180 | |||
181 | [Test()] |
||
182 | public void SerializeInteger() |
||
183 | { |
||
184 | OSD llsdOne = OSD.FromInteger(12319423); |
||
185 | string sOne = OSDParser.SerializeLLSDNotation(llsdOne); |
||
186 | OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne); |
||
187 | Assert.AreEqual(OSDType.Integer, llsdOneDS.Type); |
||
188 | Assert.AreEqual(12319423, llsdOne.AsInteger()); |
||
189 | |||
190 | OSD llsdTwo = OSD.FromInteger(-71892034); |
||
191 | string sTwo = OSDParser.SerializeLLSDNotation(llsdTwo); |
||
192 | OSD llsdTwoDS = OSDParser.DeserializeLLSDNotation(sTwo); |
||
193 | Assert.AreEqual(OSDType.Integer, llsdTwoDS.Type); |
||
194 | Assert.AreEqual(-71892034, llsdTwoDS.AsInteger()); |
||
195 | } |
||
196 | |||
197 | [Test()] |
||
198 | public void DeserializeReal() |
||
199 | { |
||
200 | String realOne = "r1123412345.465711"; |
||
201 | OSD llsdOne = OSDParser.DeserializeLLSDNotation(realOne); |
||
202 | Assert.AreEqual(OSDType.Real, llsdOne.Type); |
||
203 | Assert.AreEqual(1123412345.465711d, llsdOne.AsReal()); |
||
204 | |||
205 | String realTwo = "r-11234684.923411"; |
||
206 | OSD llsdTwo = OSDParser.DeserializeLLSDNotation(realTwo); |
||
207 | Assert.AreEqual(OSDType.Real, llsdTwo.Type); |
||
208 | Assert.AreEqual(-11234684.923411d, llsdTwo.AsReal()); |
||
209 | |||
210 | String realThree = "r1"; |
||
211 | OSD llsdThree = OSDParser.DeserializeLLSDNotation(realThree); |
||
212 | Assert.AreEqual(OSDType.Real, llsdThree.Type); |
||
213 | Assert.AreEqual(1d, llsdThree.AsReal()); |
||
214 | |||
215 | String realFour = "r2.0193899999999998204e-06"; |
||
216 | OSD llsdFour = OSDParser.DeserializeLLSDNotation(realFour); |
||
217 | Assert.AreEqual(OSDType.Real, llsdFour.Type); |
||
218 | Assert.AreEqual(2.0193899999999998204e-06d, llsdFour.AsReal()); |
||
219 | |||
220 | String realFive = "r0"; |
||
221 | OSD llsdFive = OSDParser.DeserializeLLSDNotation(realFive); |
||
222 | Assert.AreEqual(OSDType.Real, llsdFive.Type); |
||
223 | Assert.AreEqual(0d, llsdFive.AsReal()); |
||
224 | } |
||
225 | |||
226 | [Test()] |
||
227 | public void SerializeReal() |
||
228 | { |
||
229 | OSD llsdOne = OSD.FromReal(12987234.723847d); |
||
230 | string sOne = OSDParser.SerializeLLSDNotation(llsdOne); |
||
231 | OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne); |
||
232 | Assert.AreEqual(OSDType.Real, llsdOneDS.Type); |
||
233 | Assert.AreEqual(12987234.723847d, llsdOneDS.AsReal()); |
||
234 | |||
235 | OSD llsdTwo = OSD.FromReal(-32347892.234234d); |
||
236 | string sTwo = OSDParser.SerializeLLSDNotation(llsdTwo); |
||
237 | OSD llsdTwoDS = OSDParser.DeserializeLLSDNotation(sTwo); |
||
238 | Assert.AreEqual(OSDType.Real, llsdTwoDS.Type); |
||
239 | Assert.AreEqual(-32347892.234234d, llsdTwoDS.AsReal()); |
||
240 | |||
241 | OSD llsdThree = OSD.FromReal( Double.MaxValue ); |
||
242 | string sThree = OSDParser.SerializeLLSDNotation( llsdThree ); |
||
243 | OSD llsdThreeDS = OSDParser.DeserializeLLSDNotation( sThree ); |
||
244 | Assert.AreEqual( OSDType.Real, llsdThreeDS.Type ); |
||
245 | Assert.AreEqual( Double.MaxValue, llsdThreeDS.AsReal()); |
||
246 | |||
247 | OSD llsdFour = OSD.FromReal(Double.MinValue); |
||
248 | string sFour = OSDParser.SerializeLLSDNotation(llsdFour); |
||
249 | OSD llsdFourDS = OSDParser.DeserializeLLSDNotation(sFour); |
||
250 | Assert.AreEqual(OSDType.Real, llsdFourDS.Type); |
||
251 | Assert.AreEqual(Double.MinValue, llsdFourDS.AsReal()); |
||
252 | |||
253 | OSD llsdFive = OSD.FromReal(-1.1123123E+50d); |
||
254 | string sFive = OSDParser.SerializeLLSDNotation(llsdFive); |
||
255 | OSD llsdFiveDS = OSDParser.DeserializeLLSDNotation(sFive); |
||
256 | Assert.AreEqual(OSDType.Real, llsdFiveDS.Type); |
||
257 | Assert.AreEqual(-1.1123123E+50d, llsdFiveDS.AsReal()); |
||
258 | |||
259 | OSD llsdSix = OSD.FromReal(2.0193899999999998204e-06); |
||
260 | string sSix = OSDParser.SerializeLLSDNotation(llsdSix); |
||
261 | OSD llsdSixDS = OSDParser.DeserializeLLSDNotation(sSix); |
||
262 | Assert.AreEqual(OSDType.Real, llsdSixDS.Type); |
||
263 | Assert.AreEqual(2.0193899999999998204e-06, llsdSixDS.AsReal()); |
||
264 | } |
||
265 | |||
266 | [Test()] |
||
267 | public void DeserializeUUID() |
||
268 | { |
||
269 | String uuidOne = "u97f4aeca-88a1-42a1-b385-b97b18abb255"; |
||
270 | OSD llsdOne = OSDParser.DeserializeLLSDNotation(uuidOne); |
||
271 | Assert.AreEqual(OSDType.UUID, llsdOne.Type); |
||
272 | Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdOne.AsString()); |
||
273 | |||
274 | String uuidTwo = "u00000000-0000-0000-0000-000000000000"; |
||
275 | OSD llsdTwo = OSDParser.DeserializeLLSDNotation(uuidTwo); |
||
276 | Assert.AreEqual(OSDType.UUID, llsdTwo.Type); |
||
277 | Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdTwo.AsString()); |
||
278 | } |
||
279 | |||
280 | [Test()] |
||
281 | public void SerializeUUID() |
||
282 | { |
||
283 | OSD llsdOne = OSD.FromUUID(new UUID("97f4aeca-88a1-42a1-b385-b97b18abb255")); |
||
284 | string sOne = OSDParser.SerializeLLSDNotation(llsdOne); |
||
285 | OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne); |
||
286 | Assert.AreEqual(OSDType.UUID, llsdOneDS.Type); |
||
287 | Assert.AreEqual("97f4aeca-88a1-42a1-b385-b97b18abb255", llsdOneDS.AsString()); |
||
288 | |||
289 | OSD llsdTwo = OSD.FromUUID(new UUID("00000000-0000-0000-0000-000000000000")); |
||
290 | string sTwo = OSDParser.SerializeLLSDNotation(llsdTwo); |
||
291 | OSD llsdTwoDS = OSDParser.DeserializeLLSDNotation(sTwo); |
||
292 | Assert.AreEqual(OSDType.UUID, llsdTwoDS.Type); |
||
293 | Assert.AreEqual("00000000-0000-0000-0000-000000000000", llsdTwoDS.AsString()); |
||
294 | } |
||
295 | |||
296 | public void DeserializeString() |
||
297 | { |
||
298 | string sOne = "''"; |
||
299 | OSD llsdOne = OSDParser.DeserializeLLSDNotation(sOne); |
||
300 | Assert.AreEqual(OSDType.String, llsdOne.Type); |
||
301 | Assert.AreEqual("", llsdOne.AsString()); |
||
302 | |||
303 | // This is double escaping. Once for the encoding, and once for csharp. |
||
304 | string sTwo = "'test\\'\"test'"; |
||
305 | OSD llsdTwo = OSDParser.DeserializeLLSDNotation(sTwo); |
||
306 | Assert.AreEqual(OSDType.String, llsdTwo.Type); |
||
307 | Assert.AreEqual("test'\"test", llsdTwo.AsString()); |
||
308 | |||
309 | // "test \\lest" |
||
310 | char[] cThree = { (char)0x27, (char)0x74, (char)0x65, (char)0x73, (char)0x74, (char)0x20, (char)0x5c, |
||
311 | (char)0x5c, (char)0x6c, (char)0x65, (char)0x73, (char)0x74, (char)0x27 }; |
||
312 | string sThree = new string(cThree); |
||
313 | |||
314 | OSD llsdThree = OSDParser.DeserializeLLSDNotation(sThree); |
||
315 | Assert.AreEqual(OSDType.String, llsdThree.Type); |
||
316 | Assert.AreEqual("test \\lest", llsdThree.AsString()); |
||
317 | |||
318 | string sFour = "'aa\t la'"; |
||
319 | OSD llsdFour = OSDParser.DeserializeLLSDNotation(sFour); |
||
320 | Assert.AreEqual(OSDType.String, llsdFour.Type); |
||
321 | Assert.AreEqual("aa\t la", llsdFour.AsString()); |
||
322 | |||
323 | char[] cFive = { (char)0x27, (char)0x5c, (char)0x5c, (char)0x27 }; |
||
324 | string sFive = new String(cFive); |
||
325 | OSD llsdFive = OSDParser.DeserializeLLSDNotation(sFive); |
||
326 | Assert.AreEqual(OSDType.String, llsdFive.Type); |
||
327 | Assert.AreEqual("\\", llsdFive.AsString()); |
||
328 | |||
329 | |||
330 | string sSix = "s(10)\"1234567890\""; |
||
331 | OSD llsdSix = OSDParser.DeserializeLLSDNotation(sSix); |
||
332 | Assert.AreEqual(OSDType.String, llsdSix.Type); |
||
333 | Assert.AreEqual("1234567890", llsdSix.AsString()); |
||
334 | |||
335 | string sSeven = "s(5)\"\\\\\\\\\\\""; |
||
336 | OSD llsdSeven = OSDParser.DeserializeLLSDNotation(sSeven); |
||
337 | Assert.AreEqual(OSDType.String, llsdSeven.Type); |
||
338 | Assert.AreEqual("\\\\\\\\\\", llsdSeven.AsString()); |
||
339 | |||
340 | string sEight = "\"aouAOUhsdjklfghskldjfghqeiurtzwieortzaslxfjkgh\""; |
||
341 | OSD llsdEight = OSDParser.DeserializeLLSDNotation(sEight); |
||
342 | Assert.AreEqual(OSDType.String, llsdEight.Type); |
||
343 | Assert.AreEqual("aouAOUhsdjklfghskldjfghqeiurtzwieortzaslxfjkgh", llsdEight.AsString()); |
||
344 | |||
345 | |||
346 | |||
347 | } |
||
348 | |||
349 | public void DoSomeStringSerializingActionsAndAsserts(string s) |
||
350 | { |
||
351 | OSD llsdOne = OSD.FromString(s); |
||
352 | string sOne = OSDParser.SerializeLLSDNotation(llsdOne); |
||
353 | OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sOne); |
||
354 | Assert.AreEqual(OSDType.String, llsdOne.Type); |
||
355 | Assert.AreEqual(s, llsdOneDS.AsString()); |
||
356 | } |
||
357 | |||
358 | |||
359 | [Test()] |
||
360 | public void SerializeString() |
||
361 | { |
||
362 | DoSomeStringSerializingActionsAndAsserts(""); |
||
363 | |||
364 | DoSomeStringSerializingActionsAndAsserts("\\"); |
||
365 | |||
366 | DoSomeStringSerializingActionsAndAsserts("\"\""); |
||
367 | |||
368 | DoSomeStringSerializingActionsAndAsserts("ÄÖÜäöü-these-should-be-some-german-umlauts"); |
||
369 | |||
370 | DoSomeStringSerializingActionsAndAsserts("\t\n\r"); |
||
371 | |||
372 | DoSomeStringSerializingActionsAndAsserts("asdkjfhaksldjfhalskdjfhaklsjdfhaklsjdhjgzqeuiowrtzserghsldfg" + |
||
373 | "asdlkfhqeiortzsdkfjghslkdrjtzsoidklghuisoehiguhsierughaishdl" + |
||
374 | "asdfkjhueiorthsgsdkfughaslkdfjshldkfjghsldkjghsldkfghsdklghs" + |
||
375 | "wopeighisdjfghklasdfjghsdklfgjhsdklfgjshdlfkgjshdlfkgjshdlfk"); |
||
376 | |||
377 | DoSomeStringSerializingActionsAndAsserts("all is N\"\\'othing and n'oting is all"); |
||
378 | |||
379 | DoSomeStringSerializingActionsAndAsserts("very\"british is this."); |
||
380 | |||
381 | // We test here also for 4byte characters |
||
382 | string xml = "<x>𐄷</x>"; |
||
383 | byte[] bytes = Encoding.UTF8.GetBytes(xml); |
||
384 | XmlTextReader xtr = new XmlTextReader(new MemoryStream(bytes, false)); |
||
385 | xtr.Read(); |
||
386 | xtr.Read(); |
||
387 | string content = xtr.ReadString(); |
||
388 | |||
389 | DoSomeStringSerializingActionsAndAsserts(content); |
||
390 | |||
391 | } |
||
392 | |||
393 | [Test()] |
||
394 | public void DeserializeURI() |
||
395 | { |
||
396 | string sUriOne = "l\"http://test.com/test test>\\\"/&yes\""; |
||
397 | OSD llsdOne = OSDParser.DeserializeLLSDNotation(sUriOne); |
||
398 | Assert.AreEqual(OSDType.URI, llsdOne.Type); |
||
399 | Assert.AreEqual("http://test.com/test%20test%3E%22/&yes", llsdOne.AsString()); |
||
400 | |||
401 | string sUriTwo = "l\"test/test/test?test=1&toast=2\""; |
||
402 | OSD llsdTwo = OSDParser.DeserializeLLSDNotation(sUriTwo); |
||
403 | Assert.AreEqual(OSDType.URI, llsdTwo.Type); |
||
404 | Assert.AreEqual("test/test/test?test=1&toast=2", llsdTwo.AsString()); |
||
405 | } |
||
406 | |||
407 | [Test()] |
||
408 | public void SerializeURI() |
||
409 | { |
||
410 | Uri uriOne = new Uri("http://test.org/test test>\\\"/&yes\"", UriKind.RelativeOrAbsolute); |
||
411 | OSD llsdOne = OSD.FromUri(uriOne); |
||
412 | string sUriOne = OSDParser.SerializeLLSDNotation(llsdOne); |
||
413 | OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sUriOne); |
||
414 | Assert.AreEqual(OSDType.URI, llsdOneDS.Type); |
||
415 | Assert.AreEqual(uriOne, llsdOneDS.AsUri()); |
||
416 | |||
417 | Uri uriTwo = new Uri("test/test/near/the/end?test=1", UriKind.RelativeOrAbsolute); |
||
418 | OSD llsdTwo = OSD.FromUri(uriTwo); |
||
419 | string sUriTwo = OSDParser.SerializeLLSDNotation(llsdTwo); |
||
420 | OSD llsdTwoDS = OSDParser.DeserializeLLSDNotation(sUriTwo); |
||
421 | Assert.AreEqual(OSDType.URI, llsdTwoDS.Type); |
||
422 | Assert.AreEqual(uriTwo, llsdTwoDS.AsUri()); |
||
423 | } |
||
424 | |||
425 | [Test()] |
||
426 | public void DeserializeDate() |
||
427 | { |
||
428 | string sDateOne = "d\"2007-12-31T20:49:10Z\""; |
||
429 | OSD llsdOne = OSDParser.DeserializeLLSDNotation(sDateOne); |
||
430 | Assert.AreEqual(OSDType.Date, llsdOne.Type); |
||
431 | DateTime dt = new DateTime(2007, 12, 31, 20, 49, 10, 0, DateTimeKind.Utc); |
||
432 | DateTime dtDS = llsdOne.AsDate(); |
||
433 | Assert.AreEqual(dt, dtDS.ToUniversalTime()); |
||
434 | } |
||
435 | |||
436 | [Test()] |
||
437 | public void SerializeDate() |
||
438 | { |
||
439 | DateTime dtOne = new DateTime(2005, 8, 10, 11, 23, 4, DateTimeKind.Utc); |
||
440 | OSD llsdOne = OSD.FromDate(dtOne); |
||
441 | string sDtOne = OSDParser.SerializeLLSDNotation(llsdOne); |
||
442 | OSD llsdOneDS = OSDParser.DeserializeLLSDNotation(sDtOne); |
||
443 | Assert.AreEqual(OSDType.Date, llsdOneDS.Type); |
||
444 | DateTime dtOneDS = llsdOneDS.AsDate(); |
||
445 | Assert.AreEqual(dtOne, dtOneDS.ToUniversalTime()); |
||
446 | |||
447 | DateTime dtTwo = new DateTime(2010, 10, 11, 23, 00, 10, 100, DateTimeKind.Utc); |
||
448 | OSD llsdTwo = OSD.FromDate(dtTwo); |
||
449 | string sDtTwo = OSDParser.SerializeLLSDNotation(llsdTwo); |
||
450 | OSD llsdTwoDS = OSDParser.DeserializeLLSDNotation(sDtTwo); |
||
451 | Assert.AreEqual(OSDType.Date, llsdTwoDS.Type); |
||
452 | DateTime dtTwoDS = llsdTwoDS.AsDate(); |
||
453 | Assert.AreEqual(dtTwo, dtTwoDS.ToUniversalTime()); |
||
454 | |||
455 | // check if a *local* time can be serialized and deserialized |
||
456 | DateTime dtThree = new DateTime(2009, 12, 30, 8, 25, 10, DateTimeKind.Local); |
||
457 | OSD llsdDateThree = OSD.FromDate(dtThree); |
||
458 | string sDateThreeSerialized = OSDParser.SerializeLLSDNotation(llsdDateThree); |
||
459 | OSD llsdDateThreeDS = OSDParser.DeserializeLLSDNotation(sDateThreeSerialized); |
||
460 | Assert.AreEqual(OSDType.Date, llsdDateThreeDS.Type); |
||
461 | Assert.AreEqual(dtThree, llsdDateThreeDS.AsDate()); |
||
462 | } |
||
463 | |||
464 | [Test()] |
||
465 | public void SerializeBinary() |
||
466 | { |
||
467 | byte[] binary = { 0x0, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0b, |
||
468 | 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }; |
||
469 | |||
470 | OSD llsdBinary = OSD.FromBinary(binary); |
||
471 | string sBinarySerialized = OSDParser.SerializeLLSDNotation(llsdBinary); |
||
472 | OSD llsdBinaryDS = OSDParser.DeserializeLLSDNotation(sBinarySerialized); |
||
473 | Assert.AreEqual(OSDType.Binary, llsdBinaryDS.Type); |
||
474 | Assert.AreEqual(binary, llsdBinaryDS.AsBinary()); |
||
475 | } |
||
476 | |||
477 | [Test()] |
||
478 | public void DeserializeArray() |
||
479 | { |
||
480 | string sArrayOne = "[]"; |
||
481 | OSDArray llsdArrayOne = (OSDArray)OSDParser.DeserializeLLSDNotation(sArrayOne); |
||
482 | Assert.AreEqual(OSDType.Array, llsdArrayOne.Type); |
||
483 | Assert.AreEqual(0, llsdArrayOne.Count); |
||
484 | |||
485 | string sArrayTwo = "[ i0 ]"; |
||
486 | OSDArray llsdArrayTwo = (OSDArray)OSDParser.DeserializeLLSDNotation(sArrayTwo); |
||
487 | Assert.AreEqual(OSDType.Array, llsdArrayTwo.Type); |
||
488 | Assert.AreEqual(1, llsdArrayTwo.Count); |
||
489 | OSDInteger llsdIntOne = (OSDInteger)llsdArrayTwo[0]; |
||
490 | Assert.AreEqual(OSDType.Integer, llsdIntOne.Type); |
||
491 | Assert.AreEqual(0, llsdIntOne.AsInteger()); |
||
492 | |||
493 | string sArrayThree = "[ i0, i1 ]"; |
||
494 | OSDArray llsdArrayThree = (OSDArray)OSDParser.DeserializeLLSDNotation(sArrayThree); |
||
495 | Assert.AreEqual(OSDType.Array, llsdArrayThree.Type); |
||
496 | Assert.AreEqual(2, llsdArrayThree.Count); |
||
497 | OSDInteger llsdIntTwo = (OSDInteger)llsdArrayThree[0]; |
||
498 | Assert.AreEqual(OSDType.Integer, llsdIntTwo.Type); |
||
499 | Assert.AreEqual(0, llsdIntTwo.AsInteger()); |
||
500 | OSDInteger llsdIntThree = (OSDInteger)llsdArrayThree[1]; |
||
501 | Assert.AreEqual(OSDType.Integer, llsdIntThree.Type); |
||
502 | Assert.AreEqual(1, llsdIntThree.AsInteger()); |
||
503 | |||
504 | string sArrayFour = " [ \"testtest\", \"aha\",t,f,i1, r1.2, [ i1] ] "; |
||
505 | OSDArray llsdArrayFour = (OSDArray)OSDParser.DeserializeLLSDNotation(sArrayFour); |
||
506 | Assert.AreEqual(OSDType.Array, llsdArrayFour.Type); |
||
507 | Assert.AreEqual(7, llsdArrayFour.Count); |
||
508 | Assert.AreEqual("testtest", llsdArrayFour[0].AsString()); |
||
509 | Assert.AreEqual("aha", llsdArrayFour[1].AsString()); |
||
510 | Assert.AreEqual(true, llsdArrayFour[2].AsBoolean()); |
||
511 | Assert.AreEqual(false, llsdArrayFour[3].AsBoolean()); |
||
512 | Assert.AreEqual(1, llsdArrayFour[4].AsInteger()); |
||
513 | Assert.AreEqual(1.2d, llsdArrayFour[5].AsReal()); |
||
514 | Assert.AreEqual(OSDType.Array, llsdArrayFour[6].Type); |
||
515 | OSDArray llsdArrayFive = (OSDArray)llsdArrayFour[6]; |
||
516 | Assert.AreEqual(1, llsdArrayFive[0].AsInteger()); |
||
517 | |||
518 | } |
||
519 | |||
520 | [Test()] |
||
521 | public void SerializeArray() |
||
522 | { |
||
523 | OSDArray llsdOne = new OSDArray(); |
||
524 | string sOne = OSDParser.SerializeLLSDNotation(llsdOne); |
||
525 | OSDArray llsdOneDS = (OSDArray)OSDParser.DeserializeLLSDNotation(sOne); |
||
526 | Assert.AreEqual(OSDType.Array, llsdOneDS.Type); |
||
527 | Assert.AreEqual(0, llsdOneDS.Count); |
||
528 | |||
529 | OSD llsdTwo = OSD.FromInteger(123234); |
||
530 | OSD llsdThree = OSD.FromString("asedkfjhaqweiurohzasdf"); |
||
531 | OSDArray llsdFour = new OSDArray(); |
||
532 | llsdFour.Add(llsdTwo); |
||
533 | llsdFour.Add(llsdThree); |
||
534 | |||
535 | llsdOne.Add(llsdTwo); |
||
536 | llsdOne.Add(llsdThree); |
||
537 | llsdOne.Add(llsdFour); |
||
538 | |||
539 | string sFive = OSDParser.SerializeLLSDNotation(llsdOne); |
||
540 | OSDArray llsdFive = (OSDArray)OSDParser.DeserializeLLSDNotation(sFive); |
||
541 | Assert.AreEqual(OSDType.Array, llsdFive.Type); |
||
542 | Assert.AreEqual(3, llsdFive.Count); |
||
543 | Assert.AreEqual(OSDType.Integer, llsdFive[0].Type); |
||
544 | Assert.AreEqual(123234, llsdFive[0].AsInteger()); |
||
545 | Assert.AreEqual(OSDType.String, llsdFive[1].Type); |
||
546 | Assert.AreEqual("asedkfjhaqweiurohzasdf", llsdFive[1].AsString()); |
||
547 | |||
548 | OSDArray llsdSix = (OSDArray)llsdFive[2]; |
||
549 | Assert.AreEqual(OSDType.Array, llsdSix.Type); |
||
550 | Assert.AreEqual(2, llsdSix.Count); |
||
551 | Assert.AreEqual(OSDType.Integer, llsdSix[0].Type); |
||
552 | Assert.AreEqual(123234, llsdSix[0].AsInteger()); |
||
553 | Assert.AreEqual(OSDType.String, llsdSix[1].Type); |
||
554 | Assert.AreEqual("asedkfjhaqweiurohzasdf", llsdSix[1].AsString()); |
||
555 | } |
||
556 | |||
557 | [Test()] |
||
558 | public void DeserializeMap() |
||
559 | { |
||
560 | string sMapOne = " { } "; |
||
561 | OSDMap llsdMapOne = (OSDMap)OSDParser.DeserializeLLSDNotation(sMapOne); |
||
562 | Assert.AreEqual(OSDType.Map, llsdMapOne.Type); |
||
563 | Assert.AreEqual(0, llsdMapOne.Count); |
||
564 | |||
565 | string sMapTwo = " { \"test\":i2 } "; |
||
566 | OSDMap llsdMapTwo = (OSDMap)OSDParser.DeserializeLLSDNotation(sMapTwo); |
||
567 | Assert.AreEqual(OSDType.Map, llsdMapTwo.Type); |
||
568 | Assert.AreEqual(1, llsdMapTwo.Count); |
||
569 | Assert.AreEqual(OSDType.Integer, llsdMapTwo["test"].Type); |
||
570 | Assert.AreEqual(2, llsdMapTwo["test"].AsInteger()); |
||
571 | |||
572 | string sMapThree = " { 'test':\"testtesttest\", 'aha':\"muahahaha\" , \"anywhere\":! } "; |
||
573 | OSDMap llsdMapThree = (OSDMap)OSDParser.DeserializeLLSDNotation(sMapThree); |
||
574 | Assert.AreEqual(OSDType.Map, llsdMapThree.Type); |
||
575 | Assert.AreEqual(3, llsdMapThree.Count); |
||
576 | Assert.AreEqual(OSDType.String, llsdMapThree["test"].Type); |
||
577 | Assert.AreEqual("testtesttest", llsdMapThree["test"].AsString()); |
||
578 | Assert.AreEqual(OSDType.String, llsdMapThree["test"].Type); |
||
579 | Assert.AreEqual("muahahaha", llsdMapThree["aha"].AsString()); |
||
580 | Assert.AreEqual(OSDType.Unknown, llsdMapThree["self"].Type); |
||
581 | |||
582 | string sMapFour = " { 'test' : { 'test' : i1, 't0st' : r2.5 }, 'tist' : \"hello world!\", 'tast' : \"last\" } "; |
||
583 | OSDMap llsdMapFour = (OSDMap)OSDParser.DeserializeLLSDNotation(sMapFour); |
||
584 | Assert.AreEqual(OSDType.Map, llsdMapFour.Type); |
||
585 | Assert.AreEqual(3, llsdMapFour.Count); |
||
586 | Assert.AreEqual("hello world!", llsdMapFour["tist"].AsString()); |
||
587 | Assert.AreEqual("last", llsdMapFour["tast"].AsString()); |
||
588 | OSDMap llsdMapFive = (OSDMap)llsdMapFour["test"]; |
||
589 | Assert.AreEqual(OSDType.Map, llsdMapFive.Type); |
||
590 | Assert.AreEqual(2, llsdMapFive.Count); |
||
591 | Assert.AreEqual(OSDType.Integer, llsdMapFive["test"].Type); |
||
592 | Assert.AreEqual(1, llsdMapFive["test"].AsInteger()); |
||
593 | Assert.AreEqual(OSDType.Real, llsdMapFive["t0st"].Type); |
||
594 | Assert.AreEqual(2.5d, llsdMapFive["t0st"].AsReal()); |
||
595 | |||
596 | } |
||
597 | |||
598 | [Test()] |
||
599 | public void SerializeMap() |
||
600 | { |
||
601 | OSDMap llsdOne = new OSDMap(); |
||
602 | string sOne = OSDParser.SerializeLLSDNotation(llsdOne); |
||
603 | OSDMap llsdOneDS = (OSDMap)OSDParser.DeserializeLLSDNotation(sOne); |
||
604 | Assert.AreEqual(OSDType.Map, llsdOneDS.Type); |
||
605 | Assert.AreEqual(0, llsdOneDS.Count); |
||
606 | |||
607 | OSD llsdTwo = OSD.FromInteger(123234); |
||
608 | OSD llsdThree = OSD.FromString("asedkfjhaqweiurohzasdf"); |
||
609 | OSDMap llsdFour = new OSDMap(); |
||
610 | llsdFour["test0"] = llsdTwo; |
||
611 | llsdFour["test1"] = llsdThree; |
||
612 | |||
613 | llsdOne["test0"] = llsdTwo; |
||
614 | llsdOne["test1"] = llsdThree; |
||
615 | llsdOne["test2"] = llsdFour; |
||
616 | |||
617 | string sFive = OSDParser.SerializeLLSDNotation(llsdOne); |
||
618 | OSDMap llsdFive = (OSDMap)OSDParser.DeserializeLLSDNotation(sFive); |
||
619 | Assert.AreEqual(OSDType.Map, llsdFive.Type); |
||
620 | Assert.AreEqual(3, llsdFive.Count); |
||
621 | Assert.AreEqual(OSDType.Integer, llsdFive["test0"].Type); |
||
622 | Assert.AreEqual(123234, llsdFive["test0"].AsInteger()); |
||
623 | Assert.AreEqual(OSDType.String, llsdFive["test1"].Type); |
||
624 | Assert.AreEqual("asedkfjhaqweiurohzasdf", llsdFive["test1"].AsString()); |
||
625 | |||
626 | OSDMap llsdSix = (OSDMap)llsdFive["test2"]; |
||
627 | Assert.AreEqual(OSDType.Map, llsdSix.Type); |
||
628 | Assert.AreEqual(2, llsdSix.Count); |
||
629 | Assert.AreEqual(OSDType.Integer, llsdSix["test0"].Type); |
||
630 | Assert.AreEqual(123234, llsdSix["test0"].AsInteger()); |
||
631 | Assert.AreEqual(OSDType.String, llsdSix["test1"].Type); |
||
632 | Assert.AreEqual("asedkfjhaqweiurohzasdf", llsdSix["test1"].AsString()); |
||
633 | |||
634 | // We test here also for 4byte characters as map keys |
||
635 | string xml = "<x>𐄷</x>"; |
||
636 | byte[] bytes = Encoding.UTF8.GetBytes(xml); |
||
637 | XmlTextReader xtr = new XmlTextReader(new MemoryStream(bytes, false)); |
||
638 | xtr.Read(); |
||
639 | xtr.Read(); |
||
640 | string content = xtr.ReadString(); |
||
641 | |||
642 | OSDMap llsdSeven = new OSDMap(); |
||
643 | llsdSeven[content] = OSD.FromString(content); |
||
644 | string sSeven = OSDParser.SerializeLLSDNotation(llsdSeven); |
||
645 | OSDMap llsdSevenDS = (OSDMap)OSDParser.DeserializeLLSDNotation(sSeven); |
||
646 | Assert.AreEqual(OSDType.Map, llsdSevenDS.Type); |
||
647 | Assert.AreEqual(1, llsdSevenDS.Count); |
||
648 | Assert.AreEqual(content, llsdSevenDS[content].AsString()); |
||
649 | } |
||
650 | |||
651 | [Test()] |
||
652 | public void DeserializeRealWorldExamples() |
||
653 | { |
||
654 | string realWorldExample = @" |
||
655 | [ |
||
656 | {'destination':'http://secondlife.com'}, |
||
657 | {'version':i1}, |
||
658 | { |
||
659 | 'agent_id':u3c115e51-04f4-523c-9fa6-98aff1034730, |
||
660 | 'session_id':u2c585cec-038c-40b0-b42e-a25ebab4d132, |
||
661 | 'circuit_code':i1075, |
||
662 | 'first_name':'Phoenix', |
||
663 | 'last_name':'Linden', |
||
664 | 'position':[r70.9247,r254.378,r38.7304], |
||
665 | 'look_at':[r-0.043753,r-0.999042,r0], |
||
666 | 'granters':[ua2e76fcd-9360-4f6d-a924-000000000003], |
||
667 | 'attachment_data': |
||
668 | [ |
||
669 | { |
||
670 | 'attachment_point':i2, |
||
671 | 'item_id':ud6852c11-a74e-309a-0462-50533f1ef9b3, |
||
672 | 'asset_id':uc69b29b1-8944-58ae-a7c5-2ca7b23e22fb |
||
673 | }, |
||
674 | { |
||
675 | 'attachment_point':i10, |
||
676 | 'item_id':uff852c22-a74e-309a-0462-50533f1ef900, |
||
677 | 'asset_id':u5868dd20-c25a-47bd-8b4c-dedc99ef9479 |
||
678 | } |
||
679 | ] |
||
680 | } |
||
681 | ]"; |
||
682 | // We dont do full testing here. We are fine if a few values are right |
||
683 | // and the parser doesnt throw an exception |
||
684 | OSDArray llsdArray = (OSDArray)OSDParser.DeserializeLLSDNotation(realWorldExample); |
||
685 | Assert.AreEqual(OSDType.Array, llsdArray.Type); |
||
686 | Assert.AreEqual(3, llsdArray.Count); |
||
687 | |||
688 | OSDMap llsdMapOne = (OSDMap)llsdArray[0]; |
||
689 | Assert.AreEqual(OSDType.Map, llsdMapOne.Type); |
||
690 | Assert.AreEqual("http://secondlife.com", llsdMapOne["destination"].AsString()); |
||
691 | |||
692 | OSDMap llsdMapTwo = (OSDMap)llsdArray[1]; |
||
693 | Assert.AreEqual(OSDType.Map, llsdMapTwo.Type); |
||
694 | Assert.AreEqual(OSDType.Integer, llsdMapTwo["version"].Type); |
||
695 | Assert.AreEqual(1, llsdMapTwo["version"].AsInteger()); |
||
696 | |||
697 | OSDMap llsdMapThree = (OSDMap)llsdArray[2]; |
||
698 | Assert.AreEqual(OSDType.UUID, llsdMapThree["session_id"].Type); |
||
699 | Assert.AreEqual("2c585cec-038c-40b0-b42e-a25ebab4d132", llsdMapThree["session_id"].AsString()); |
||
700 | Assert.AreEqual(OSDType.UUID, llsdMapThree["agent_id"].Type); |
||
701 | Assert.AreEqual("3c115e51-04f4-523c-9fa6-98aff1034730", llsdMapThree["agent_id"].AsString()); |
||
702 | |||
703 | } |
||
704 | |||
705 | [Test()] |
||
706 | public void SerializeFormattedTest() |
||
707 | { |
||
708 | // This is not a real test. Instead look at the console.out tab for how formatted notation looks like. |
||
709 | OSDArray llsdArray = new OSDArray(); |
||
710 | OSD llsdOne = OSD.FromInteger(1); |
||
711 | OSD llsdTwo = OSD.FromInteger(1); |
||
712 | llsdArray.Add(llsdOne); |
||
713 | llsdArray.Add(llsdTwo); |
||
714 | |||
715 | OSDMap llsdMap = new OSDMap(); |
||
716 | OSD llsdThree = OSD.FromInteger(2); |
||
717 | llsdMap["test1"] = llsdThree; |
||
718 | OSD llsdFour = OSD.FromInteger(2); |
||
719 | llsdMap["test2"] = llsdFour; |
||
720 | |||
721 | llsdArray.Add(llsdMap); |
||
722 | |||
723 | OSDArray llsdArrayTwo = new OSDArray(); |
||
724 | OSD llsdFive = OSD.FromString("asdflkhjasdhj"); |
||
725 | OSD llsdSix = OSD.FromString("asdkfhasjkldfghsd"); |
||
726 | llsdArrayTwo.Add(llsdFive); |
||
727 | llsdArrayTwo.Add(llsdSix); |
||
728 | |||
729 | llsdMap["test3"] = llsdArrayTwo; |
||
730 | |||
731 | string sThree = OSDParser.SerializeLLSDNotationFormatted(llsdArray); |
||
732 | |||
733 | // we also try to parse this... and look a little at the results |
||
734 | OSDArray llsdSeven = (OSDArray)OSDParser.DeserializeLLSDNotation(sThree); |
||
735 | Assert.AreEqual(OSDType.Array, llsdSeven.Type); |
||
736 | Assert.AreEqual(3, llsdSeven.Count); |
||
737 | Assert.AreEqual(OSDType.Integer, llsdSeven[0].Type); |
||
738 | Assert.AreEqual(1, llsdSeven[0].AsInteger()); |
||
739 | Assert.AreEqual(OSDType.Integer, llsdSeven[1].Type); |
||
740 | Assert.AreEqual(1, llsdSeven[1].AsInteger()); |
||
741 | |||
742 | Assert.AreEqual(OSDType.Map, llsdSeven[2].Type); |
||
743 | // thats enough for now. |
||
744 | } |
||
745 | } |
||
746 | } |