corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
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 public class PrimObjectTests : Assert
38 {
39 [Test]
40 public void PathBegin()
41 {
42 for (byte i = 0; i < byte.MaxValue; i++)
43 {
44 float floatValue = Primitive.UnpackBeginCut(i);
45 ushort result = Primitive.PackBeginCut(floatValue);
46  
47 Assert.IsTrue(result == i, "Started with " + i + ", float value was " + floatValue +
48 ", and ended up with " + result);
49 }
50 }
51  
52 [Test]
53 public void PathEnd()
54 {
55 for (byte i = 0; i < byte.MaxValue; i++)
56 {
57 float floatValue = Primitive.UnpackEndCut(i);
58 ushort result = Primitive.PackEndCut(floatValue);
59  
60 Assert.IsTrue(result == i, "Started with " + i + ", float value was " + floatValue +
61 ", and ended up with " + result);
62 }
63 }
64  
65 [Test]
66 public void PathRevolutions()
67 {
68 for (byte i = 0; i < byte.MaxValue; i++)
69 {
70 float floatValue = Primitive.UnpackPathRevolutions(i);
71 byte result = Primitive.PackPathRevolutions(floatValue);
72  
73 Assert.IsTrue(result == i, "Started with " + i + ", float value was " + floatValue +
74 ", and ended up with " + result);
75 }
76 }
77  
78 [Test]
79 public void PathScale()
80 {
81 for (byte i = 0; i < byte.MaxValue; i++)
82 {
83 float floatValue = Primitive.UnpackPathScale(i);
84 byte result = Primitive.PackPathScale(floatValue);
85  
86 Assert.IsTrue(result == i, "Started with " + i + ", float value was " + floatValue +
87 ", and ended up with " + result);
88 }
89 }
90  
91 //[Test]
92 //public void PathShear()
93 //{
94 // for (byte i = 0; i < byte.MaxValue; i++)
95 // {
96 // float floatValue = Primitive.UnpackPathShear(i);
97 // byte result = Primitive.PackPathShear(floatValue);
98  
99 // Assert.IsTrue(result == i, "Started with " + i + ", float value was " + floatValue +
100 // ", and ended up with " + result);
101 // }
102 //}
103  
104 [Test]
105 public void PathTaper()
106 {
107 for (sbyte i = sbyte.MinValue; i < sbyte.MaxValue; i++)
108 {
109 float floatValue = Primitive.UnpackPathTaper(i);
110 sbyte result = Primitive.PackPathTaper(floatValue);
111  
112 Assert.IsTrue(result == i, "Started with " + i + ", float value was " + floatValue +
113 ", and ended up with " + result);
114 }
115 }
116  
117 [Test]
118 public void TextureEntryOffsets()
119 {
120 for (float i = -1.0f; i <= 1.0f; i += 0.001f)
121 {
122 i = (float)Math.Round(i, 3);
123  
124 short offset = Helpers.TEOffsetShort(i);
125 float foffset = Helpers.TEOffsetFloat(BitConverter.GetBytes(offset), 0);
126 foffset = (float)Math.Round(foffset, 3);
127  
128 Assert.IsTrue(foffset - i < Single.Epsilon, foffset + " is not equal to " + i);
129 }
130 }
131  
132 [Test]
133 public void TextureEntry()
134 {
135 Primitive.TextureEntry te = new Primitive.TextureEntry(UUID.Random());
136 Primitive.TextureEntryFace face = te.CreateFace(0);
137 face.Bump = Bumpiness.Concrete;
138 face.Fullbright = true;
139 face.MediaFlags = true;
140 face.OffsetU = 0.5f;
141 face.OffsetV = -0.5f;
142 face.RepeatU = 3.0f;
143 face.RepeatV = 4.0f;
144 face.RGBA = new Color4(0f, 0.25f, 0.75f, 1f);
145 face.Rotation = 1.5f;
146 face.Shiny = Shininess.Medium;
147 face.TexMapType = MappingType.Planar;
148 face.TextureID = UUID.Random();
149  
150 byte[] teBytes = te.GetBytes();
151  
152 Primitive.TextureEntry te2 = new Primitive.TextureEntry(teBytes, 0, teBytes.Length);
153  
154 byte[] teBytes2 = te2.GetBytes();
155  
156 Assert.IsTrue(teBytes.Length == teBytes2.Length);
157  
158 for (int i = 0; i < teBytes.Length; i++)
159 {
160 Assert.IsTrue(teBytes[i] == teBytes2[i], "Byte " + i + " is not equal");
161 }
162 }
163 }
164 }