From 120c731a3b3e055cd6786deef2bf3a1ca0fceb8c Mon Sep 17 00:00:00 2001
From: Teravus Ovares (Dan Olivares)
Date: Fri, 30 Oct 2009 17:04:10 -0400
Subject: * Moving A test from the OpenSim.Framework.ACL object to the
OpenSim.Framework.Tests assembly. Fixing the test.
---
OpenSim/Framework/Tests/ACLTest.cs | 41 ++++++++++++++++++++++++++++++++++++++
1 file changed, 41 insertions(+)
create mode 100644 OpenSim/Framework/Tests/ACLTest.cs
(limited to 'OpenSim/Framework/Tests')
diff --git a/OpenSim/Framework/Tests/ACLTest.cs b/OpenSim/Framework/Tests/ACLTest.cs
new file mode 100644
index 0000000..2428b64
--- /dev/null
+++ b/OpenSim/Framework/Tests/ACLTest.cs
@@ -0,0 +1,41 @@
+using System;
+using NUnit.Framework;
+
+
+namespace OpenSim.Framework.Tests
+{
+ [TestFixture]
+ public class ACLTest
+ {
+ #region Tests
+
+ ///
+ /// ACL Test class
+ ///
+ [Test]
+ public void ACLTest01()
+ {
+ ACL acl = new ACL();
+
+ Role Guests = new Role("Guests");
+ acl.AddRole(Guests);
+
+ Role[] parents = new Role[1];
+ parents[0] = Guests;
+
+ Role JoeGuest = new Role("JoeGuest", parents);
+ acl.AddRole(JoeGuest);
+
+ Resource CanBuild = new Resource("CanBuild");
+ acl.AddResource(CanBuild);
+
+
+ acl.GrantPermission("Guests", "CanBuild");
+
+ acl.HasPermission("JoeGuest", "CanBuild");
+
+ }
+
+ #endregion
+ }
+}
--
cgit v1.1
From 4563f00852e9a393b28bd98925b14bbbf699e8ae Mon Sep 17 00:00:00 2001
From: Teravus Ovares (Dan Olivares)
Date: Fri, 30 Oct 2009 17:27:44 -0400
Subject: * Another ACL Test
---
OpenSim/Framework/Tests/ACLTest.cs | 59 +++++++++++++++++++++++++++++++++++++-
1 file changed, 58 insertions(+), 1 deletion(-)
(limited to 'OpenSim/Framework/Tests')
diff --git a/OpenSim/Framework/Tests/ACLTest.cs b/OpenSim/Framework/Tests/ACLTest.cs
index 2428b64..d11f307 100644
--- a/OpenSim/Framework/Tests/ACLTest.cs
+++ b/OpenSim/Framework/Tests/ACLTest.cs
@@ -1,5 +1,6 @@
using System;
using NUnit.Framework;
+using System.Collections.Generic;
namespace OpenSim.Framework.Tests
@@ -32,8 +33,64 @@ namespace OpenSim.Framework.Tests
acl.GrantPermission("Guests", "CanBuild");
- acl.HasPermission("JoeGuest", "CanBuild");
+ Permission perm = acl.HasPermission("JoeGuest", "CanBuild");
+ Assert.That(perm == Permission.Allow, "JoeGuest should have permission to build");
+ perm = Permission.None;
+ try
+ {
+ perm = acl.HasPermission("unknownGuest", "CanBuild");
+
+ }
+ catch (KeyNotFoundException)
+ {
+
+
+ }
+ catch (Exception)
+ {
+ Assert.That(false,"Exception thrown should have been KeyNotFoundException");
+ }
+ Assert.That(perm == Permission.None,"Permission None should be set because exception should have been thrown");
+
+ }
+
+ [Test]
+ public void KnownButPermissionDenyAndPermissionNoneUserTest()
+ {
+ ACL acl = new ACL();
+
+ Role Guests = new Role("Guests");
+ acl.AddRole(Guests);
+ Role Administrators = new Role("Administrators");
+ acl.AddRole(Administrators);
+ Role[] Guestparents = new Role[1];
+ Role[] Adminparents = new Role[1];
+
+ Guestparents[0] = Guests;
+ Adminparents[0] = Administrators;
+
+ Role JoeGuest = new Role("JoeGuest", Guestparents);
+ acl.AddRole(JoeGuest);
+
+ Resource CanBuild = new Resource("CanBuild");
+ acl.AddResource(CanBuild);
+
+ Resource CanScript = new Resource("CanScript");
+ acl.AddResource(CanScript);
+
+ Resource CanRestart = new Resource("CanRestart");
+ acl.AddResource(CanRestart);
+
+ acl.GrantPermission("Guests", "CanBuild");
+ acl.DenyPermission("Guests", "CanRestart");
+
+ acl.GrantPermission("Administrators", "CanScript");
+ acl.GrantPermission("Administrators", "CanRestart");
+ Permission setPermission = acl.HasPermission("JoeGuest", "CanRestart");
+ Assert.That(setPermission == Permission.Deny, "Guests Should not be able to restart");
+ Assert.That(acl.HasPermission("JoeGuest", "CanScript") == Permission.None,
+ "No Explicit Permissions set so should be Permission.None");
}
#endregion
--
cgit v1.1
From 2e81acec48c02e54843b2a33ce9c542d0a0fb68d Mon Sep 17 00:00:00 2001
From: Teravus Ovares (Dan Olivares)
Date: Fri, 30 Oct 2009 18:13:58 -0400
Subject: * Adding Tests for OpenSim.Framework.Cache. Some test cases disabled
until mantis resolutions.
---
OpenSim/Framework/Tests/CacheTests.cs | 75 +++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
create mode 100644 OpenSim/Framework/Tests/CacheTests.cs
(limited to 'OpenSim/Framework/Tests')
diff --git a/OpenSim/Framework/Tests/CacheTests.cs b/OpenSim/Framework/Tests/CacheTests.cs
new file mode 100644
index 0000000..8e97232
--- /dev/null
+++ b/OpenSim/Framework/Tests/CacheTests.cs
@@ -0,0 +1,75 @@
+using System;
+using NUnit.Framework;
+using OpenMetaverse;
+
+namespace OpenSim.Framework.Tests
+{
+ [TestFixture]
+ public class CacheTests
+ {
+ private Cache cache;
+ private UUID cacheItemUUID;
+ [SetUp]
+ public void Build()
+ {
+ cache = new Cache();
+ cacheItemUUID = UUID.Random();
+ MemoryCacheItem cachedItem = new MemoryCacheItem(cacheItemUUID.ToString(),DateTime.Now + TimeSpan.FromDays(1));
+ byte[] foo = new byte[1];
+ foo[0] = 255;
+ cachedItem.Store(foo);
+ cache.Store(cacheItemUUID.ToString(), cachedItem);
+ }
+ [Test]
+ public void TestRetreive()
+ {
+ CacheItemBase citem = (CacheItemBase)cache.Get(cacheItemUUID.ToString());
+ byte[] data = (byte[]) citem.Retrieve();
+ Assert.That(data.Length == 1, "Cached Item should have one byte element");
+ Assert.That(data[0] == 255, "Cached Item element should be 255");
+ }
+
+ [Test]
+ public void TestNotInCache()
+ {
+ UUID randomNotIn = UUID.Random();
+ while (randomNotIn == cacheItemUUID)
+ {
+ randomNotIn = UUID.Random();
+ }
+ object citem = cache.Get(randomNotIn.ToString());
+ Assert.That(citem == null, "Item should not be in Cache" );
+ }
+
+ //NOTE: Test Case disabled until Cache is fixed
+ [Test]
+ public void TestTTLExpiredEntry()
+ {
+ UUID ImmediateExpiryUUID = UUID.Random();
+ MemoryCacheItem cachedItem = new MemoryCacheItem(ImmediateExpiryUUID.ToString(), TimeSpan.FromDays(-1));
+ byte[] foo = new byte[1];
+ foo[0] = 1;
+ cachedItem.Store(foo);
+ cache.Store(cacheItemUUID.ToString(), cachedItem);
+
+ object citem = cache.Get(cacheItemUUID.ToString());
+ //Assert.That(citem == null, "Item should not be in Cache because the expiry time was before now");
+ }
+
+ //NOTE: Test Case disabled until Cache is fixed
+ [Test]
+ public void ExpireItemManually()
+ {
+ UUID ImmediateExpiryUUID = UUID.Random();
+ MemoryCacheItem cachedItem = new MemoryCacheItem(ImmediateExpiryUUID.ToString(), TimeSpan.FromDays(1));
+ byte[] foo = new byte[1];
+ foo[0] = 1;
+ cachedItem.Store(foo);
+ cache.Store(cacheItemUUID.ToString(), cachedItem);
+ cache.Invalidate(ImmediateExpiryUUID.ToString());
+ object citem = cache.Get(cacheItemUUID.ToString());
+ //Assert.That(citem == null, "Item should not be in Cache because we manually invalidated it");
+ }
+
+ }
+}
--
cgit v1.1
From 5101f688ee887d5fa67a573591ec3b6a43c4e50b Mon Sep 17 00:00:00 2001
From: Teravus Ovares (Dan Olivares)
Date: Fri, 30 Oct 2009 19:13:57 -0400
Subject: * Add LocklessQueueTests. One Test is commented out because it
fails. It should probably work.. but I'm awaiting clarification.
---
OpenSim/Framework/Tests/LocklessQueueTests.cs | 147 ++++++++++++++++++++++++++
1 file changed, 147 insertions(+)
create mode 100644 OpenSim/Framework/Tests/LocklessQueueTests.cs
(limited to 'OpenSim/Framework/Tests')
diff --git a/OpenSim/Framework/Tests/LocklessQueueTests.cs b/OpenSim/Framework/Tests/LocklessQueueTests.cs
new file mode 100644
index 0000000..e34f767
--- /dev/null
+++ b/OpenSim/Framework/Tests/LocklessQueueTests.cs
@@ -0,0 +1,147 @@
+using System;
+using NUnit.Framework;
+using System.Threading;
+
+namespace OpenSim.Framework.Tests
+{
+ [TestFixture]
+ public class LocklessQueueTests
+ {
+ public LocklessQueue sharedQueue;
+ [SetUp]
+ public void build()
+ {
+ sharedQueue = new LocklessQueue();
+
+ }
+
+ [Test]
+ public void EnqueueDequeueTest()
+ {
+ sharedQueue.Enqueue(1);
+ int dequeue;
+ sharedQueue.Dequeue(out dequeue);
+ Assert.That(dequeue == 1, "Enqueued 1. Dequeue should also be 1");
+ Assert.That(sharedQueue.Count == 0, "We Dequeued the last item, count should be 0");
+
+ }
+
+ [Test]
+ public void ThreadedSimpleEnqueueDequeueTest()
+ {
+ int loopamountA = 5000;
+ int loopamountB = 5000;
+ int loopamountC = 5000;
+ int loopamountD = 5000;
+
+ threadObject1 obj1 = new threadObject1(this, loopamountA);
+ threadObject1 obj2 = new threadObject1(this, loopamountB);
+ threadObject1 obj3 = new threadObject1(this, loopamountC);
+ threadObject1 obj4 = new threadObject1(this, loopamountD);
+ for (int i=0;i<1;i++)
+ {
+ sharedQueue.Enqueue(i);
+ }
+
+ Thread thr = new Thread(obj1.thread1Action);
+ Thread thr2 = new Thread(obj2.thread1Action);
+ Thread thr3 = new Thread(obj3.thread1Action);
+ Thread thr4 = new Thread(obj4.thread1Action);
+ thr.Start();
+ thr2.Start();
+ thr3.Start();
+ thr4.Start();
+
+ thr.Join();
+ thr2.Join();
+ thr3.Join();
+ thr4.Join();
+
+ Assert.That(sharedQueue.Count == 1);
+ int result = 0;
+ sharedQueue.Dequeue(out result);
+ Assert.That(result == loopamountD + loopamountC + loopamountB + loopamountA, "Threaded Result test failed. Expected the sum of all of the threads adding to the item in the queue. Got {0}, Expected {1}", result, loopamountD + loopamountC + loopamountB + loopamountA);
+
+ }
+
+ /* This test fails. Need clarification if this should work
+ [Test]
+ public void ThreadedAdvancedEnqueueDequeueTest()
+ {
+ int loopamountA = 5000;
+ int loopamountB = 5000;
+ int loopamountC = 5000;
+ int loopamountD = 5000;
+
+ threadObject1 obj1 = new threadObject1(this, loopamountA);
+ threadObject2 obj2 = new threadObject2(this, loopamountB);
+ threadObject1 obj3 = new threadObject1(this, loopamountC);
+ threadObject2 obj4 = new threadObject2(this, loopamountD);
+ for (int i = 0; i < 1; i++)
+ {
+ sharedQueue.Enqueue(i);
+ }
+
+ Thread thr = new Thread(obj1.thread1Action);
+ Thread thr2 = new Thread(obj2.thread1Action);
+ Thread thr3 = new Thread(obj3.thread1Action);
+ Thread thr4 = new Thread(obj4.thread1Action);
+ thr.Start();
+ thr2.Start();
+ thr3.Start();
+ thr4.Start();
+
+ thr.Join();
+ thr2.Join();
+ thr3.Join();
+ thr4.Join();
+
+ Assert.That(sharedQueue.Count == 1);
+ int result = 0;
+ sharedQueue.Dequeue(out result);
+ Assert.That(result == loopamountA - loopamountB + loopamountC - loopamountD, "Threaded Result test failed. Expected the sum of all of the threads adding to the item in the queue. Got {0}, Expected {1}", result, loopamountA - loopamountB + loopamountC - loopamountD);
+
+ }
+ */
+ }
+ // Dequeue one from the locklessqueue add one to it and enqueue it again.
+ public class threadObject1
+ {
+ private LocklessQueueTests m_tests;
+ private int m_loopamount = 0;
+ public threadObject1(LocklessQueueTests tst, int loopamount)
+ {
+ m_tests = tst;
+ m_loopamount = loopamount;
+ }
+ public void thread1Action(object o)
+ {
+ for (int i=0;i sharedQueue;
- [SetUp]
- public void build()
- {
- sharedQueue = new LocklessQueue();
-
- }
-
- [Test]
- public void EnqueueDequeueTest()
- {
- sharedQueue.Enqueue(1);
- int dequeue;
- sharedQueue.Dequeue(out dequeue);
- Assert.That(dequeue == 1, "Enqueued 1. Dequeue should also be 1");
- Assert.That(sharedQueue.Count == 0, "We Dequeued the last item, count should be 0");
-
- }
-
- [Test]
- public void ThreadedSimpleEnqueueDequeueTest()
- {
- int loopamountA = 5000;
- int loopamountB = 5000;
- int loopamountC = 5000;
- int loopamountD = 5000;
-
- threadObject1 obj1 = new threadObject1(this, loopamountA);
- threadObject1 obj2 = new threadObject1(this, loopamountB);
- threadObject1 obj3 = new threadObject1(this, loopamountC);
- threadObject1 obj4 = new threadObject1(this, loopamountD);
- for (int i=0;i<1;i++)
- {
- sharedQueue.Enqueue(i);
- }
-
- Thread thr = new Thread(obj1.thread1Action);
- Thread thr2 = new Thread(obj2.thread1Action);
- Thread thr3 = new Thread(obj3.thread1Action);
- Thread thr4 = new Thread(obj4.thread1Action);
- thr.Start();
- thr2.Start();
- thr3.Start();
- thr4.Start();
-
- thr.Join();
- thr2.Join();
- thr3.Join();
- thr4.Join();
-
- Assert.That(sharedQueue.Count == 1);
- int result = 0;
- sharedQueue.Dequeue(out result);
- Assert.That(result == loopamountD + loopamountC + loopamountB + loopamountA, "Threaded Result test failed. Expected the sum of all of the threads adding to the item in the queue. Got {0}, Expected {1}", result, loopamountD + loopamountC + loopamountB + loopamountA);
-
- }
-
- /* This test fails. Need clarification if this should work
- [Test]
- public void ThreadedAdvancedEnqueueDequeueTest()
- {
- int loopamountA = 5000;
- int loopamountB = 5000;
- int loopamountC = 5000;
- int loopamountD = 5000;
-
- threadObject1 obj1 = new threadObject1(this, loopamountA);
- threadObject2 obj2 = new threadObject2(this, loopamountB);
- threadObject1 obj3 = new threadObject1(this, loopamountC);
- threadObject2 obj4 = new threadObject2(this, loopamountD);
- for (int i = 0; i < 1; i++)
- {
- sharedQueue.Enqueue(i);
- }
-
- Thread thr = new Thread(obj1.thread1Action);
- Thread thr2 = new Thread(obj2.thread1Action);
- Thread thr3 = new Thread(obj3.thread1Action);
- Thread thr4 = new Thread(obj4.thread1Action);
- thr.Start();
- thr2.Start();
- thr3.Start();
- thr4.Start();
-
- thr.Join();
- thr2.Join();
- thr3.Join();
- thr4.Join();
-
- Assert.That(sharedQueue.Count == 1);
- int result = 0;
- sharedQueue.Dequeue(out result);
- Assert.That(result == loopamountA - loopamountB + loopamountC - loopamountD, "Threaded Result test failed. Expected the sum of all of the threads adding to the item in the queue. Got {0}, Expected {1}", result, loopamountA - loopamountB + loopamountC - loopamountD);
-
- }
- */
- }
- // Dequeue one from the locklessqueue add one to it and enqueue it again.
- public class threadObject1
- {
- private LocklessQueueTests m_tests;
- private int m_loopamount = 0;
- public threadObject1(LocklessQueueTests tst, int loopamount)
- {
- m_tests = tst;
- m_loopamount = loopamount;
- }
- public void thread1Action(object o)
- {
- for (int i=0;i