aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Framework/Tests
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Framework/Tests')
-rw-r--r--OpenSim/Framework/Tests/CacheTests.cs46
-rw-r--r--OpenSim/Framework/Tests/LocationTest.cs19
-rw-r--r--OpenSim/Framework/Tests/MundaneFrameworkTests.cs311
-rw-r--r--OpenSim/Framework/Tests/PrimeNumberHelperTests.cs146
-rw-r--r--OpenSim/Framework/Tests/UtilTest.cs114
5 files changed, 623 insertions, 13 deletions
diff --git a/OpenSim/Framework/Tests/CacheTests.cs b/OpenSim/Framework/Tests/CacheTests.cs
index 32c0c95..c3613e6 100644
--- a/OpenSim/Framework/Tests/CacheTests.cs
+++ b/OpenSim/Framework/Tests/CacheTests.cs
@@ -40,6 +40,7 @@ namespace OpenSim.Framework.Tests
40 public void Build() 40 public void Build()
41 { 41 {
42 cache = new Cache(); 42 cache = new Cache();
43 cache = new Cache(CacheMedium.Memory,CacheStrategy.Aggressive,CacheFlags.AllowUpdate);
43 cacheItemUUID = UUID.Random(); 44 cacheItemUUID = UUID.Random();
44 MemoryCacheItem cachedItem = new MemoryCacheItem(cacheItemUUID.ToString(),DateTime.Now + TimeSpan.FromDays(1)); 45 MemoryCacheItem cachedItem = new MemoryCacheItem(cacheItemUUID.ToString(),DateTime.Now + TimeSpan.FromDays(1));
45 byte[] foo = new byte[1]; 46 byte[] foo = new byte[1];
@@ -68,36 +69,55 @@ namespace OpenSim.Framework.Tests
68 Assert.That(citem == null, "Item should not be in Cache"); 69 Assert.That(citem == null, "Item should not be in Cache");
69 } 70 }
70 71
71 //NOTE: Test Case disabled until Cache is fixed 72
72 [Test] 73 [Test]
73 public void TestTTLExpiredEntry() 74 public void ExpireItemManually()
74 { 75 {
75 UUID ImmediateExpiryUUID = UUID.Random(); 76 UUID ImmediateExpiryUUID = UUID.Random();
76 MemoryCacheItem cachedItem = new MemoryCacheItem(ImmediateExpiryUUID.ToString(), TimeSpan.FromDays(-1)); 77 MemoryCacheItem cachedItem = new MemoryCacheItem(ImmediateExpiryUUID.ToString(), TimeSpan.FromDays(1));
77 byte[] foo = new byte[1]; 78 byte[] foo = new byte[1];
78 foo[0] = 1; 79 foo[0] = 1;
79 cachedItem.Store(foo); 80 cachedItem.Store(foo);
80 cache.Store(cacheItemUUID.ToString(), cachedItem); 81 cache.Store(cacheItemUUID.ToString(), cachedItem);
81 82 cache.Invalidate(cacheItemUUID.ToString());
82 cache.Get(cacheItemUUID.ToString()); 83 cache.Get(cacheItemUUID.ToString());
83 //object citem = cache.Get(cacheItemUUID.ToString()); 84 object citem = cache.Get(cacheItemUUID.ToString());
84 //Assert.That(citem == null, "Item should not be in Cache because the expiry time was before now"); 85 Assert.That(citem == null, "Item should not be in Cache because we manually invalidated it");
85 } 86 }
86 87
87 //NOTE: Test Case disabled until Cache is fixed
88 [Test] 88 [Test]
89 public void ExpireItemManually() 89 public void ClearCacheTest()
90 { 90 {
91 UUID ImmediateExpiryUUID = UUID.Random(); 91 UUID ImmediateExpiryUUID = UUID.Random();
92 MemoryCacheItem cachedItem = new MemoryCacheItem(ImmediateExpiryUUID.ToString(), TimeSpan.FromDays(1)); 92 MemoryCacheItem cachedItem = new MemoryCacheItem(ImmediateExpiryUUID.ToString(), DateTime.Now - TimeSpan.FromDays(1));
93 byte[] foo = new byte[1]; 93 byte[] foo = new byte[1];
94 foo[0] = 1; 94 foo[0] = 1;
95 cachedItem.Store(foo); 95 cachedItem.Store(foo);
96 cache.Store(cacheItemUUID.ToString(), cachedItem); 96 cache.Store(cacheItemUUID.ToString(), cachedItem);
97 cache.Invalidate(ImmediateExpiryUUID.ToString()); 97 cache.Clear();
98 cache.Get(cacheItemUUID.ToString()); 98
99 //object citem = cache.Get(cacheItemUUID.ToString()); 99 object citem = cache.Get(cacheItemUUID.ToString());
100 //Assert.That(citem == null, "Item should not be in Cache because we manually invalidated it"); 100 Assert.That(citem == null, "Item should not be in Cache because we manually invalidated it");
101 }
102
103 [Test]
104 public void CacheItemMundane()
105 {
106 UUID Random1 = UUID.Random();
107 UUID Random2 = UUID.Random();
108 byte[] data = new byte[0];
109 CacheItemBase cb1 = new CacheItemBase(Random1.ToString(), DateTime.Now + TimeSpan.FromDays(1));
110 CacheItemBase cb2 = new CacheItemBase(Random2.ToString(), DateTime.Now + TimeSpan.FromDays(1));
111 CacheItemBase cb3 = new CacheItemBase(Random1.ToString(), DateTime.Now + TimeSpan.FromDays(1));
112
113 cb1.Store(data);
114
115 Assert.That(cb1.Equals(cb3), "cb1 should equal cb3, their uuids are the same");
116 Assert.That(!cb2.Equals(cb1), "cb2 should not equal cb1, their uuids are NOT the same");
117 Assert.That(cb1.IsLocked() == false, "CacheItemBase default is false");
118 Assert.That(cb1.Retrieve() == null, "Virtual Retrieve method should return null");
119
120
101 } 121 }
102 122
103 } 123 }
diff --git a/OpenSim/Framework/Tests/LocationTest.cs b/OpenSim/Framework/Tests/LocationTest.cs
index 237568f..2707afa 100644
--- a/OpenSim/Framework/Tests/LocationTest.cs
+++ b/OpenSim/Framework/Tests/LocationTest.cs
@@ -54,9 +54,28 @@ namespace OpenSim.Framework.Tests
54 Location TestLocation2 = new Location(1099511628032000); 54 Location TestLocation2 = new Location(1099511628032000);
55 Assert.That(TestLocation1 == TestLocation2); 55 Assert.That(TestLocation1 == TestLocation2);
56 56
57 Assert.That(TestLocation2.X == 256000 && TestLocation2.Y == 256000, "Test xy location doesn't match regionhandle provided");
58
59 Assert.That(TestLocation2.RegionHandle == 1099511628032000,
60 "Location RegionHandle Property didn't match regionhandle provided in constructor");
61
62
57 TestLocation1 = new Location(256001, 256001); 63 TestLocation1 = new Location(256001, 256001);
58 TestLocation2 = new Location(1099511628032000); 64 TestLocation2 = new Location(1099511628032000);
59 Assert.That(TestLocation1 != TestLocation2); 65 Assert.That(TestLocation1 != TestLocation2);
66
67 Assert.That(TestLocation1.Equals(256001, 256001), "Equals(x,y) failed to match the position in the constructor");
68
69 Assert.That(TestLocation2.GetHashCode() == (TestLocation2.X.GetHashCode() ^ TestLocation2.Y.GetHashCode()), "GetHashCode failed to produce the expected hashcode");
70
71 Location TestLocation3;
72 object cln = TestLocation2.Clone();
73 TestLocation3 = (Location) cln;
74 Assert.That(TestLocation3.X == TestLocation2.X && TestLocation3.Y == TestLocation2.Y,
75 "Cloned Location values do not match");
76
77 Assert.That(TestLocation2.Equals(cln), "Cloned object failed .Equals(obj) Test");
78
60 } 79 }
61 80
62 } 81 }
diff --git a/OpenSim/Framework/Tests/MundaneFrameworkTests.cs b/OpenSim/Framework/Tests/MundaneFrameworkTests.cs
new file mode 100644
index 0000000..04be083
--- /dev/null
+++ b/OpenSim/Framework/Tests/MundaneFrameworkTests.cs
@@ -0,0 +1,311 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
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 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using NUnit.Framework;
29using OpenSim.Framework;
30using OpenMetaverse;
31using OpenMetaverse.StructuredData;
32using System;
33using System.Globalization;
34using System.Threading;
35
36namespace OpenSim.Framework.Tests
37{
38 [TestFixture]
39 public class MundaneFrameworkTests
40 {
41 private bool m_RegionSettingsOnSaveEventFired;
42 private bool m_RegionLightShareDataOnSaveEventFired;
43
44
45 [Test]
46 public void ChildAgentDataUpdate01()
47 {
48 // code coverage
49 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate();
50 Assert.IsFalse(cadu.alwaysrun, "Default is false");
51 }
52
53 [Test]
54 public void AgentPositionTest01()
55 {
56 UUID AgentId1 = UUID.Random();
57 UUID SessionId1 = UUID.Random();
58 uint CircuitCode1 = uint.MinValue;
59 Vector3 Size1 = Vector3.UnitZ;
60 Vector3 Position1 = Vector3.UnitX;
61 Vector3 LeftAxis1 = Vector3.UnitY;
62 Vector3 UpAxis1 = Vector3.UnitZ;
63 Vector3 AtAxis1 = Vector3.UnitX;
64
65 ulong RegionHandle1 = ulong.MinValue;
66 byte[] Throttles1 = new byte[] {0, 1, 0};
67
68 Vector3 Velocity1 = Vector3.Zero;
69 float Far1 = 256;
70
71 bool ChangedGrid1 = false;
72 Vector3 Center1 = Vector3.Zero;
73
74 AgentPosition position1 = new AgentPosition();
75 position1.AgentID = AgentId1;
76 position1.SessionID = SessionId1;
77 position1.CircuitCode = CircuitCode1;
78 position1.Size = Size1;
79 position1.Position = Position1;
80 position1.LeftAxis = LeftAxis1;
81 position1.UpAxis = UpAxis1;
82 position1.AtAxis = AtAxis1;
83 position1.RegionHandle = RegionHandle1;
84 position1.Throttles = Throttles1;
85 position1.Velocity = Velocity1;
86 position1.Far = Far1;
87 position1.ChangedGrid = ChangedGrid1;
88 position1.Center = Center1;
89
90 ChildAgentDataUpdate cadu = new ChildAgentDataUpdate();
91 cadu.AgentID = AgentId1.Guid;
92 cadu.ActiveGroupID = UUID.Zero.Guid;
93 cadu.throttles = Throttles1;
94 cadu.drawdistance = Far1;
95 cadu.Position = Position1;
96 cadu.Velocity = Velocity1;
97 cadu.regionHandle = RegionHandle1;
98 cadu.cameraPosition = Center1;
99 cadu.AVHeight = Size1.Z;
100
101 AgentPosition position2 = new AgentPosition();
102 position2.CopyFrom(cadu);
103
104 Assert.IsTrue(
105 position2.AgentID == position1.AgentID
106 && position2.Size == position1.Size
107 && position2.Position == position1.Position
108 && position2.Velocity == position1.Velocity
109 && position2.Center == position1.Center
110 && position2.RegionHandle == position1.RegionHandle
111 && position2.Far == position1.Far
112
113 ,"Copy From ChildAgentDataUpdate failed");
114
115 position2 = new AgentPosition();
116
117 Assert.IsFalse(position2.AgentID == position1.AgentID, "Test Error, position2 should be a blank uninitialized AgentPosition");
118 position2.Unpack(position1.Pack());
119
120 Assert.IsTrue(position2.AgentID == position1.AgentID, "Agent ID didn't unpack the same way it packed");
121 Assert.IsTrue(position2.Position == position1.Position, "Position didn't unpack the same way it packed");
122 Assert.IsTrue(position2.Velocity == position1.Velocity, "Velocity didn't unpack the same way it packed");
123 Assert.IsTrue(position2.SessionID == position1.SessionID, "SessionID didn't unpack the same way it packed");
124 Assert.IsTrue(position2.CircuitCode == position1.CircuitCode, "CircuitCode didn't unpack the same way it packed");
125 Assert.IsTrue(position2.LeftAxis == position1.LeftAxis, "LeftAxis didn't unpack the same way it packed");
126 Assert.IsTrue(position2.UpAxis == position1.UpAxis, "UpAxis didn't unpack the same way it packed");
127 Assert.IsTrue(position2.AtAxis == position1.AtAxis, "AtAxis didn't unpack the same way it packed");
128 Assert.IsTrue(position2.RegionHandle == position1.RegionHandle, "RegionHandle didn't unpack the same way it packed");
129 Assert.IsTrue(position2.ChangedGrid == position1.ChangedGrid, "ChangedGrid didn't unpack the same way it packed");
130 Assert.IsTrue(position2.Center == position1.Center, "Center didn't unpack the same way it packed");
131 Assert.IsTrue(position2.Size == position1.Size, "Size didn't unpack the same way it packed");
132
133 }
134
135 [Test]
136 public void RegionSettingsTest01()
137 {
138 RegionSettings settings = new RegionSettings();
139 settings.OnSave += RegionSaveFired;
140 settings.Save();
141 settings.OnSave -= RegionSaveFired;
142
143 string str = settings.LoadedCreationDate;
144 int dt = settings.LoadedCreationDateTime;
145 string id = settings.LoadedCreationID;
146 string time = settings.LoadedCreationTime;
147
148 Assert.That(m_RegionSettingsOnSaveEventFired, "RegionSettings Save Event didn't Fire");
149
150 }
151 public void RegionSaveFired(RegionSettings settings)
152 {
153 m_RegionSettingsOnSaveEventFired = true;
154 }
155
156 [Test]
157 public void InventoryItemBaseConstructorTest01()
158 {
159 InventoryItemBase b1 = new InventoryItemBase();
160 Assert.That(b1.ID == UUID.Zero, "void constructor should create an inventory item with ID = UUID.Zero");
161 Assert.That(b1.Owner == UUID.Zero, "void constructor should create an inventory item with Owner = UUID.Zero");
162
163 UUID ItemID = UUID.Random();
164 UUID OwnerID = UUID.Random();
165
166 InventoryItemBase b2 = new InventoryItemBase(ItemID);
167 Assert.That(b2.ID == ItemID, "ID constructor should create an inventory item with ID = ItemID");
168 Assert.That(b2.Owner == UUID.Zero, "ID constructor should create an inventory item with Owner = UUID.Zero");
169
170 InventoryItemBase b3 = new InventoryItemBase(ItemID,OwnerID);
171 Assert.That(b3.ID == ItemID, "ID,OwnerID constructor should create an inventory item with ID = ItemID");
172 Assert.That(b3.Owner == OwnerID, "ID,OwnerID constructor should create an inventory item with Owner = OwnerID");
173
174 }
175
176 [Test]
177 public void AssetMetaDataNonNullContentTypeTest01()
178 {
179 AssetMetadata assetMetadata = new AssetMetadata();
180 assetMetadata.ContentType = "image/jp2";
181 Assert.That(assetMetadata.Type == (sbyte)AssetType.Texture, "Content type should be AssetType.Texture");
182 Assert.That(assetMetadata.ContentType == "image/jp2", "Text of content type should be image/jp2");
183 UUID rndID = UUID.Random();
184 assetMetadata.ID = rndID.ToString();
185 Assert.That(assetMetadata.ID.ToLower() == rndID.ToString().ToLower(), "assetMetadata.ID Setter/Getter not Consistent");
186 DateTime fixedTime = DateTime.Now;
187 assetMetadata.CreationDate = fixedTime;
188 }
189
190 [Test]
191 public void RegionLightShareDataCloneSaveTest01()
192 {
193 RegionLightShareData rlsd = new RegionLightShareData();
194 rlsd.OnSave += RegionLightShareDataSaveFired;
195 rlsd.Save();
196 rlsd.OnSave -= RegionLightShareDataSaveFired;
197 Assert.IsTrue(m_RegionLightShareDataOnSaveEventFired, "OnSave Event Never Fired");
198
199 object o = rlsd.Clone();
200 RegionLightShareData dupe = (RegionLightShareData) o;
201 Assert.IsTrue(rlsd.sceneGamma == dupe.sceneGamma, "Memberwise Clone of RegionLightShareData failed");
202 }
203 public void RegionLightShareDataSaveFired(RegionLightShareData settings)
204 {
205 m_RegionLightShareDataOnSaveEventFired = true;
206 }
207
208 [Test]
209 public void EstateSettingsMundateTests()
210 {
211 EstateSettings es = new EstateSettings();
212 es.AddBan(null);
213 UUID bannedUserId = UUID.Random();
214 es.AddBan(new EstateBan()
215 { BannedHostAddress = string.Empty,
216 BannedHostIPMask = string.Empty,
217 BannedHostNameMask = string.Empty,
218 BannedUserID = bannedUserId}
219 );
220 Assert.IsTrue(es.IsBanned(bannedUserId), "User Should be banned but is not.");
221 Assert.IsFalse(es.IsBanned(UUID.Zero), "User Should not be banned but is.");
222
223 es.RemoveBan(bannedUserId);
224
225 Assert.IsFalse(es.IsBanned(bannedUserId), "User Should not be banned but is.");
226
227 es.AddEstateManager(UUID.Zero);
228
229 es.AddEstateManager(bannedUserId);
230 Assert.IsTrue(es.IsEstateManager(bannedUserId), "bannedUserId should be EstateManager but isn't.");
231
232 es.RemoveEstateManager(bannedUserId);
233 Assert.IsFalse(es.IsEstateManager(bannedUserId), "bannedUserID is estateManager but shouldn't be");
234
235 Assert.IsFalse(es.HasAccess(bannedUserId), "bannedUserID has access but shouldn't");
236
237 es.AddEstateUser(bannedUserId);
238
239 Assert.IsTrue(es.HasAccess(bannedUserId), "bannedUserID doesn't have access but should");
240 es.RemoveEstateUser(bannedUserId);
241
242 es.AddEstateManager(bannedUserId);
243
244 Assert.IsTrue(es.HasAccess(bannedUserId), "bannedUserID doesn't have access but should");
245
246 Assert.That(es.EstateGroups.Length == 0, "No Estate Groups Added.. so the array should be 0 length");
247
248 es.AddEstateGroup(bannedUserId);
249
250 Assert.That(es.EstateGroups.Length == 1, "1 Estate Groups Added.. so the array should be 1 length");
251
252 Assert.That(es.EstateGroups[0] == bannedUserId,"User ID should be in EstateGroups");
253
254 }
255
256 [Test]
257 public void InventoryFolderBaseConstructorTest01()
258 {
259 UUID uuid1 = UUID.Random();
260 UUID uuid2 = UUID.Random();
261
262 InventoryFolderBase fld = new InventoryFolderBase(uuid1);
263 Assert.That(fld.ID == uuid1, "ID constructor failed to save value in ID field.");
264
265 fld = new InventoryFolderBase(uuid1, uuid2);
266 Assert.That(fld.ID == uuid1, "ID,Owner constructor failed to save value in ID field.");
267 Assert.That(fld.Owner == uuid2, "ID,Owner constructor failed to save value in ID field.");
268 }
269
270 [Test]
271 public void AsssetBaseConstructorTest01()
272 {
273 AssetBase abase = new AssetBase();
274 Assert.IsNotNull(abase.Metadata, "void constructor of AssetBase should have created a MetaData element but didn't.");
275 UUID itemID = UUID.Random();
276 UUID creatorID = UUID.Random();
277 abase = new AssetBase(itemID.ToString(), "test item", (sbyte) AssetType.Texture, creatorID.ToString());
278
279 Assert.IsNotNull(abase.Metadata, "string,string,sbyte,string constructor of AssetBase should have created a MetaData element but didn't.");
280 Assert.That(abase.ID == itemID.ToString(), "string,string,sbyte,string constructor failed to set ID property");
281 Assert.That(abase.Metadata.CreatorID == creatorID.ToString(), "string,string,sbyte,string constructor failed to set Creator ID");
282
283
284 abase = new AssetBase(itemID.ToString(), "test item", -1, creatorID.ToString());
285 Assert.IsNotNull(abase.Metadata, "string,string,sbyte,string constructor of AssetBase with unknown type should have created a MetaData element but didn't.");
286 Assert.That(abase.Metadata.Type == -1, "Unknown Type passed to string,string,sbyte,string constructor and was a known type when it came out again");
287
288 AssetMetadata metts = new AssetMetadata();
289 metts.FullID = itemID;
290 metts.ID = string.Empty;
291 metts.Name = "test item";
292 abase.Metadata = metts;
293
294 Assert.That(abase.ToString() == itemID.ToString(), "ToString is overriden to be fullID.ToString()");
295 Assert.That(abase.ID == itemID.ToString(),"ID should be MetaData.FullID.ToString() when string.empty or null is provided to the ID property");
296 }
297
298 [Test]
299 public void CultureSetCultureTest01()
300 {
301 CultureInfo ci = new CultureInfo("en-US", false);
302 Culture.SetCurrentCulture();
303 Assert.That(Thread.CurrentThread.CurrentCulture.Name == ci.Name, "SetCurrentCulture failed to set thread culture to en-US");
304
305 }
306
307
308
309 }
310}
311
diff --git a/OpenSim/Framework/Tests/PrimeNumberHelperTests.cs b/OpenSim/Framework/Tests/PrimeNumberHelperTests.cs
new file mode 100644
index 0000000..d741f91
--- /dev/null
+++ b/OpenSim/Framework/Tests/PrimeNumberHelperTests.cs
@@ -0,0 +1,146 @@
1/*
2 * Copyright (c) Contributors, http://opensimulator.org/
3 * See CONTRIBUTORS.TXT for a full list of copyright holders.
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 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * * Neither the name of the OpenSimulator Project nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28using System;
29using System.Reflection;
30using NUnit.Framework;
31using NUnit.Framework.SyntaxHelpers;
32using OpenMetaverse;
33using OpenMetaverse.StructuredData;
34using OpenSim.Framework;
35
36namespace OpenSim.Framework.Tests
37{
38 [TestFixture]
39 public class PrimeNumberHelperTests
40 {
41
42
43 [Test]
44 public void TestGetPrime()
45 {
46 int prime1 = PrimeNumberHelper.GetPrime(7919);
47 Assert.That(prime1 == 8419, "Prime Number Get Prime Failed, 7919 is prime");
48 Assert.That(PrimeNumberHelper.IsPrime(prime1),"Prime1 should be prime");
49 Assert.That(PrimeNumberHelper.IsPrime(7919), "7919 is prime but is falsely failing the prime test");
50 prime1 = PrimeNumberHelper.GetPrime(Int32.MaxValue - 1);
51 Assert.That(prime1 == -1, "prime1 should have been -1 since there are no primes between Int32.MaxValue-1 and Int32.MaxValue");
52
53 }
54
55 [Test]
56 public void Test1000SmallPrimeNumbers()
57 {
58 int[] primes = {
59 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89,
60 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191
61 , 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283,
62 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401,
63 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509,
64 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631,
65 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751,
66 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877,
67 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009,
68 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, 1093, 1097,
69 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, 1201, 1213, 1217,
70 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, 1297, 1301, 1303, 1307,
71 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, 1427, 1429, 1433, 1439, 1447,
72 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, 1499, 1511, 1523, 1531, 1543, 1549,
73 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, 1607, 1609, 1613, 1619, 1621, 1627, 1637,
74 1657, 1663, 1667, 1669, 1693, 1697, 1699, 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759,
75 1777, 1783, 1787, 1789, 1801, 1811, 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879,
76 1889, 1901, 1907, 1913, 1931, 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003,
77 2011, 2017, 2027, 2029, 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113,
78 2129, 2131, 2137, 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243,
79 2251, 2267, 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351,
80 2357, 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459,
81 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, 2609,
82 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, 2699, 2707,
83 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, 2797, 2801, 2803,
84 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, 2909, 2917, 2927, 2939,
85 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, 3037, 3041, 3049, 3061, 3067,
86 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, 3169, 3181, 3187, 3191, 3203, 3209,
87 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, 3299, 3301, 3307, 3313, 3319, 3323, 3329,
88 3331, 3343, 3347, 3359, 3361, 3371, 3373, 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461,
89 3463, 3467, 3469, 3491, 3499, 3511, 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559,
90 3571, 3581, 3583, 3593, 3607, 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677,
91 3691, 3697, 3701, 3709, 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803,
92 3821, 3823, 3833, 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923,
93 3929, 3931, 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051,
94 4057, 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177,
95 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, 4289,
96 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, 4441, 4447,
97 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, 4549, 4561, 4567,
98 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, 4663, 4673, 4679, 4691,
99 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, 4793, 4799, 4801, 4813, 4817,
100 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, 4933, 4937, 4943, 4951, 4957, 4967,
101 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, 5021, 5023, 5039, 5051, 5059, 5077, 5081,
102 5087, 5099, 5101, 5107, 5113, 5119, 5147, 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227,
103 5231, 5233, 5237, 5261, 5273, 5279, 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381,
104 5387, 5393, 5399, 5407, 5413, 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479,
105 5483, 5501, 5503, 5507, 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623,
106 5639, 5641, 5647, 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737,
107 5741, 5743, 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851,
108 5857, 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007,
109 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, 6131,
110 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, 6257, 6263,
111 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, 6353, 6359, 6361,
112 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, 6481, 6491, 6521, 6529,
113 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, 6619, 6637, 6653, 6659, 6661,
114 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, 6737, 6761, 6763, 6779, 6781, 6791,
115 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, 6863, 6869, 6871, 6883, 6899, 6907, 6911,
116 6917, 6947, 6949, 6959, 6961, 6967, 6971, 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027,
117 7039, 7043, 7057, 7069, 7079, 7103, 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193,
118 7207, 7211, 7213, 7219, 7229, 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331,
119 7333, 7349, 7351, 7369, 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489,
120 7499, 7507, 7517, 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589,
121 7591, 7603, 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717,
122 7723, 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873,
123 7877, 7879, 7883, 7901, 7907, 7919
124 };
125 for (int i = 0; i < primes.Length; i++)
126 {
127 Assert.That(PrimeNumberHelper.IsPrime(primes[i]),primes[i] + " is prime but is erroniously failing the prime test");
128 }
129
130 int[] nonprimes = {
131 4, 6, 8, 10, 14, 16, 18, 22, 28, 30, 36, 40, 42, 46, 52, 58, 60, 66, 70, 72, 78, 82, 88,
132 96, 366, 372, 378, 382, 388, 396, 400, 408, 418, 420, 430, 432, 438, 442, 448, 456, 460, 462,
133 466, 478, 486, 490, 498, 502, 508, 856, 858, 862, 876, 880, 882, 886, 906, 910, 918, 928, 936,
134 940, 946, 952, 966, 970, 976, 982, 990, 996, 1008, 1740, 1746, 1752, 1758, 4650, 4656, 4662,
135 4672, 4678, 4690, 7740, 7752, 7756, 7758, 7788, 7792, 7816, 7822, 7828, 7840, 7852, 7866, 7872,
136 7876, 7878, 7882, 7900, 7906, 7918
137 };
138 for (int i = 0; i < nonprimes.Length; i++)
139 {
140 Assert.That(!PrimeNumberHelper.IsPrime(nonprimes[i]), nonprimes[i] + " is not prime but is erroniously passing the prime test");
141 }
142
143 Assert.That(PrimeNumberHelper.IsPrime(3));
144 }
145 }
146} \ No newline at end of file
diff --git a/OpenSim/Framework/Tests/UtilTest.cs b/OpenSim/Framework/Tests/UtilTest.cs
index 45d822c..89f5c0c 100644
--- a/OpenSim/Framework/Tests/UtilTest.cs
+++ b/OpenSim/Framework/Tests/UtilTest.cs
@@ -170,5 +170,119 @@ namespace OpenSim.Framework.Tests
170 // Varying secrets should not eqal the same 170 // Varying secrets should not eqal the same
171 Assert.AreNotEqual(Util.GetHashGuid(string1, "secret1"), Util.GetHashGuid(string1, "secret2")); 171 Assert.AreNotEqual(Util.GetHashGuid(string1, "secret1"), Util.GetHashGuid(string1, "secret2"));
172 } 172 }
173
174 [Test]
175 public void SLUtilTypeConvertTests()
176 {
177 int[] assettypes = new int[]{-1,0,1,2,3,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
178 ,23,24,25,46,47,48};
179 string[] contenttypes = new string[]
180 {
181 "application/octet-stream",
182 "image/x-j2c",
183 "audio/ogg",
184 "application/vnd.ll.callingcard",
185 "application/vnd.ll.landmark",
186 "application/vnd.ll.clothing",
187 "application/vnd.ll.primitive",
188 "application/vnd.ll.notecard",
189 "application/vnd.ll.folder",
190 "application/vnd.ll.rootfolder",
191 "application/vnd.ll.lsltext",
192 "application/vnd.ll.lslbyte",
193 "image/tga",
194 "application/vnd.ll.bodypart",
195 "application/vnd.ll.trashfolder",
196 "application/vnd.ll.snapshotfolder",
197 "application/vnd.ll.lostandfoundfolder",
198 "audio/x-wav",
199 "image/tga",
200 "image/jpeg",
201 "application/vnd.ll.animation",
202 "application/vnd.ll.gesture",
203 "application/x-metaverse-simstate",
204 "application/vnd.ll.favoritefolder",
205 "application/vnd.ll.link",
206 "application/vnd.ll.linkfolder",
207 "application/vnd.ll.currentoutfitfolder",
208 "application/vnd.ll.outfitfolder",
209 "application/vnd.ll.myoutfitsfolder"
210 };
211 for (int i=0;i<assettypes.Length;i++)
212 {
213 Assert.That(SLUtil.SLAssetTypeToContentType(assettypes[i]) == contenttypes[i], "Expecting {0} but got {1}", contenttypes[i], SLUtil.SLAssetTypeToContentType(assettypes[i]));
214 }
215
216 for (int i = 0; i < contenttypes.Length; i++)
217 {
218 if (SLUtil.ContentTypeToSLAssetType(contenttypes[i]) == 18)
219 {
220 Assert.That(contenttypes[i] == "image/tga");
221 }
222 else
223 {
224 Assert.That(SLUtil.ContentTypeToSLAssetType(contenttypes[i]) == assettypes[i],
225 "Expecting {0} but got {1}", assettypes[i],
226 SLUtil.ContentTypeToSLAssetType(contenttypes[i]));
227 }
228 }
229
230 int[] inventorytypes = new int[] {-1,0,1,2,3,6,7,8,9,10,15,17,18,20};
231 string[] invcontenttypes = new string[]
232 {
233 "application/octet-stream",
234 "image/x-j2c",
235 "audio/ogg",
236 "application/vnd.ll.callingcard",
237 "application/vnd.ll.landmark",
238 "application/vnd.ll.primitive",
239 "application/vnd.ll.notecard",
240 "application/vnd.ll.folder",
241 "application/octet-stream",
242 "application/vnd.ll.lsltext",
243 "image/x-j2c",
244 "application/vnd.ll.primitive",
245 "application/vnd.ll.clothing",
246 "application/vnd.ll.gesture"
247 };
248
249 for (int i=0;i<inventorytypes.Length;i++)
250 {
251 Assert.That(SLUtil.SLInvTypeToContentType(inventorytypes[i]) == invcontenttypes[i], "Expected {0}, Got {1}", invcontenttypes[i], SLUtil.SLInvTypeToContentType(inventorytypes[i]));
252 }
253
254 invcontenttypes = new string[]
255 {
256 "image/x-j2c","image/jp2","image/tga",
257 "image/jpeg","application/ogg","audio/ogg",
258 "audio/x-wav","application/vnd.ll.callingcard",
259 "application/x-metaverse-callingcard",
260 "application/vnd.ll.landmark",
261 "application/x-metaverse-landmark",
262 "application/vnd.ll.clothing",
263 "application/x-metaverse-clothing","application/vnd.ll.bodypart",
264 "application/x-metaverse-bodypart","application/vnd.ll.primitive",
265 "application/x-metaverse-primitive","application/vnd.ll.notecard",
266 "application/x-metaverse-notecard","application/vnd.ll.folder",
267 "application/vnd.ll.rootfolder","application/vnd.ll.lsltext",
268 "application/x-metaverse-lsl","application/vnd.ll.lslbyte",
269 "application/x-metaverse-lso","application/vnd.ll.trashfolder",
270 "application/vnd.ll.snapshotfolder",
271 "application/vnd.ll.lostandfoundfolder","application/vnd.ll.animation",
272 "application/x-metaverse-animation","application/vnd.ll.gesture",
273 "application/x-metaverse-gesture","application/x-metaverse-simstate",
274 "application/octet-stream"
275 };
276 sbyte[] invtypes = new sbyte[]
277 {
278 0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 3, 18, 18, 18, 18, 6, 6, 7, 7, 8, 9, 10, 10, 10, 10
279 , 8, 8, 8, 19, 19, 20, 20, 15, -1
280 };
281
282 for (int i = 0; i < invtypes.Length; i++)
283 {
284 Assert.That(SLUtil.ContentTypeToSLInvType(invcontenttypes[i]) == invtypes[i], "Expected {0}, Got {1}", invtypes[i], SLUtil.ContentTypeToSLInvType(invcontenttypes[i]));
285 }
286 }
173 } 287 }
174} 288}