diff options
author | Teravus Ovares (Dan Olivares) | 2010-09-17 18:41:12 -0400 |
---|---|---|
committer | Teravus Ovares (Dan Olivares) | 2010-09-17 18:41:12 -0400 |
commit | 94f35890e774d065c2db66e927dff61c823c4508 (patch) | |
tree | acb90ccaf5f4bcff0f39612e0adb1d63c3bbf51b /OpenSim | |
parent | * Add a few more tests to help our meager code coverage %. (diff) | |
download | opensim-SC_OLD-94f35890e774d065c2db66e927dff61c823c4508.zip opensim-SC_OLD-94f35890e774d065c2db66e927dff61c823c4508.tar.gz opensim-SC_OLD-94f35890e774d065c2db66e927dff61c823c4508.tar.bz2 opensim-SC_OLD-94f35890e774d065c2db66e927dff61c823c4508.tar.xz |
* Fixed and re-enabled CacheTests
* Added MundaneFrameworkTests.cs for the really mundane tests like testing properties,constructors, etc in OpenSim.Framework.
* Fixed LeftAxis and UpAxis unpacking from OSD to AgentPosition (copy and paste error caught while writing mundane test) (Good thing nobody uses the camera frustum from remote regions yet)
Diffstat (limited to 'OpenSim')
-rw-r--r-- | OpenSim/Framework/ChildAgentDataUpdate.cs | 4 | ||||
-rw-r--r-- | OpenSim/Framework/Tests/CacheTests.cs | 46 | ||||
-rw-r--r-- | OpenSim/Framework/Tests/MundaneFrameworkTests.cs | 131 |
3 files changed, 166 insertions, 15 deletions
diff --git a/OpenSim/Framework/ChildAgentDataUpdate.cs b/OpenSim/Framework/ChildAgentDataUpdate.cs index 89ee39c..0dc5dbc 100644 --- a/OpenSim/Framework/ChildAgentDataUpdate.cs +++ b/OpenSim/Framework/ChildAgentDataUpdate.cs | |||
@@ -150,10 +150,10 @@ namespace OpenSim.Framework | |||
150 | Vector3.TryParse(args["at_axis"].AsString(), out AtAxis); | 150 | Vector3.TryParse(args["at_axis"].AsString(), out AtAxis); |
151 | 151 | ||
152 | if (args["left_axis"] != null) | 152 | if (args["left_axis"] != null) |
153 | Vector3.TryParse(args["left_axis"].AsString(), out AtAxis); | 153 | Vector3.TryParse(args["left_axis"].AsString(), out LeftAxis); |
154 | 154 | ||
155 | if (args["up_axis"] != null) | 155 | if (args["up_axis"] != null) |
156 | Vector3.TryParse(args["up_axis"].AsString(), out AtAxis); | 156 | Vector3.TryParse(args["up_axis"].AsString(), out UpAxis); |
157 | 157 | ||
158 | if (args["changed_grid"] != null) | 158 | if (args["changed_grid"] != null) |
159 | ChangedGrid = args["changed_grid"].AsBoolean(); | 159 | ChangedGrid = args["changed_grid"].AsBoolean(); |
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/MundaneFrameworkTests.cs b/OpenSim/Framework/Tests/MundaneFrameworkTests.cs new file mode 100644 index 0000000..e2e08c0 --- /dev/null +++ b/OpenSim/Framework/Tests/MundaneFrameworkTests.cs | |||
@@ -0,0 +1,131 @@ | |||
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 | |||
28 | using NUnit.Framework; | ||
29 | using OpenSim.Framework; | ||
30 | using OpenMetaverse; | ||
31 | using OpenMetaverse.StructuredData; | ||
32 | |||
33 | namespace OpenSim.Framework.Tests | ||
34 | { | ||
35 | [TestFixture] | ||
36 | public class MundaneFrameworkTests | ||
37 | { | ||
38 | [Test] | ||
39 | public void ChildAgentDataUpdate01() | ||
40 | { | ||
41 | // code coverage | ||
42 | ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); | ||
43 | Assert.IsFalse(cadu.alwaysrun, "Default is false"); | ||
44 | } | ||
45 | |||
46 | [Test] | ||
47 | public void AgentPositionTest01() | ||
48 | { | ||
49 | UUID AgentId1 = UUID.Random(); | ||
50 | UUID SessionId1 = UUID.Random(); | ||
51 | uint CircuitCode1 = uint.MinValue; | ||
52 | Vector3 Size1 = Vector3.UnitZ; | ||
53 | Vector3 Position1 = Vector3.UnitX; | ||
54 | Vector3 LeftAxis1 = Vector3.UnitY; | ||
55 | Vector3 UpAxis1 = Vector3.UnitZ; | ||
56 | Vector3 AtAxis1 = Vector3.UnitX; | ||
57 | |||
58 | ulong RegionHandle1 = ulong.MinValue; | ||
59 | byte[] Throttles1 = new byte[] {0, 1, 0}; | ||
60 | |||
61 | Vector3 Velocity1 = Vector3.Zero; | ||
62 | float Far1 = 256; | ||
63 | |||
64 | bool ChangedGrid1 = false; | ||
65 | Vector3 Center1 = Vector3.Zero; | ||
66 | |||
67 | AgentPosition position1 = new AgentPosition(); | ||
68 | position1.AgentID = AgentId1; | ||
69 | position1.SessionID = SessionId1; | ||
70 | position1.CircuitCode = CircuitCode1; | ||
71 | position1.Size = Size1; | ||
72 | position1.Position = Position1; | ||
73 | position1.LeftAxis = LeftAxis1; | ||
74 | position1.UpAxis = UpAxis1; | ||
75 | position1.AtAxis = AtAxis1; | ||
76 | position1.RegionHandle = RegionHandle1; | ||
77 | position1.Throttles = Throttles1; | ||
78 | position1.Velocity = Velocity1; | ||
79 | position1.Far = Far1; | ||
80 | position1.ChangedGrid = ChangedGrid1; | ||
81 | position1.Center = Center1; | ||
82 | |||
83 | ChildAgentDataUpdate cadu = new ChildAgentDataUpdate(); | ||
84 | cadu.AgentID = AgentId1.Guid; | ||
85 | cadu.ActiveGroupID = UUID.Zero.Guid; | ||
86 | cadu.throttles = Throttles1; | ||
87 | cadu.drawdistance = Far1; | ||
88 | cadu.Position = Position1; | ||
89 | cadu.Velocity = Velocity1; | ||
90 | cadu.regionHandle = RegionHandle1; | ||
91 | cadu.cameraPosition = Center1; | ||
92 | cadu.AVHeight = Size1.Z; | ||
93 | |||
94 | AgentPosition position2 = new AgentPosition(); | ||
95 | position2.CopyFrom(cadu); | ||
96 | |||
97 | Assert.IsTrue( | ||
98 | position2.AgentID == position1.AgentID | ||
99 | && position2.Size == position1.Size | ||
100 | && position2.Position == position1.Position | ||
101 | && position2.Velocity == position1.Velocity | ||
102 | && position2.Center == position1.Center | ||
103 | && position2.RegionHandle == position1.RegionHandle | ||
104 | && position2.Far == position1.Far | ||
105 | |||
106 | ,"Copy From ChildAgentDataUpdate failed"); | ||
107 | |||
108 | position2 = new AgentPosition(); | ||
109 | |||
110 | Assert.IsFalse(position2.AgentID == position1.AgentID, "Test Error, position2 should be a blank uninitialized AgentPosition"); | ||
111 | position2.Unpack(position1.Pack()); | ||
112 | |||
113 | Assert.IsTrue(position2.AgentID == position1.AgentID, "Agent ID didn't unpack the same way it packed"); | ||
114 | Assert.IsTrue(position2.Position == position1.Position, "Position didn't unpack the same way it packed"); | ||
115 | Assert.IsTrue(position2.Velocity == position1.Velocity, "Velocity didn't unpack the same way it packed"); | ||
116 | Assert.IsTrue(position2.SessionID == position1.SessionID, "SessionID didn't unpack the same way it packed"); | ||
117 | Assert.IsTrue(position2.CircuitCode == position1.CircuitCode, "CircuitCode didn't unpack the same way it packed"); | ||
118 | Assert.IsTrue(position2.LeftAxis == position1.LeftAxis, "LeftAxis didn't unpack the same way it packed"); | ||
119 | Assert.IsTrue(position2.UpAxis == position1.UpAxis, "UpAxis didn't unpack the same way it packed"); | ||
120 | Assert.IsTrue(position2.AtAxis == position1.AtAxis, "AtAxis didn't unpack the same way it packed"); | ||
121 | Assert.IsTrue(position2.RegionHandle == position1.RegionHandle, "RegionHandle didn't unpack the same way it packed"); | ||
122 | Assert.IsTrue(position2.ChangedGrid == position1.ChangedGrid, "ChangedGrid didn't unpack the same way it packed"); | ||
123 | Assert.IsTrue(position2.Center == position1.Center, "Center didn't unpack the same way it packed"); | ||
124 | Assert.IsTrue(position2.Size == position1.Size, "Size didn't unpack the same way it packed"); | ||
125 | |||
126 | } | ||
127 | |||
128 | |||
129 | } | ||
130 | } | ||
131 | |||