aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/Environment
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs134
1 files changed, 126 insertions, 8 deletions
diff --git a/OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs b/OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs
index 4049dfc..c15bd46 100644
--- a/OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs
+++ b/OpenSim/Region/Environment/Modules/Agent/TextureSender/Tests/TextureSenderTests.cs
@@ -25,9 +25,13 @@
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */ 26 */
27 27
28using System;
29using System.Collections;
28using NUnit.Framework; 30using NUnit.Framework;
31using NUnit.Framework.SyntaxHelpers;
29using OpenMetaverse; 32using OpenMetaverse;
30using OpenSim.Framework; 33using OpenSim.Framework;
34
31using OpenSim.Tests.Common.Mock; 35using OpenSim.Tests.Common.Mock;
32 36
33namespace OpenSim.Region.Environment.Modules.Agent.TextureSender 37namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
@@ -35,11 +39,17 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
35 [TestFixture] 39 [TestFixture]
36 public class UserTextureSenderTests 40 public class UserTextureSenderTests
37 { 41 {
38 [Test] 42 public UUID uuid1;
39 /// <summary> 43 public UUID uuid2;
40 /// More a placeholder, really 44 public UUID uuid3;
41 /// </summary> 45 public UUID uuid4;
42 public void DummyTest() 46 public int npackets, testsize;
47 public TestClient client;
48 public TextureSender ts;
49 public static Random random = new Random();
50
51 [TestFixtureSetUp]
52 public void Init()
43 { 53 {
44 AgentCircuitData agent = new AgentCircuitData(); 54 AgentCircuitData agent = new AgentCircuitData();
45 agent.AgentID = UUID.Random(); 55 agent.AgentID = UUID.Random();
@@ -52,8 +62,116 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
52 agent.InventoryFolder = UUID.Zero; 62 agent.InventoryFolder = UUID.Zero;
53 agent.startpos = Vector3.Zero; 63 agent.startpos = Vector3.Zero;
54 agent.CapsPath = "http://wibble.com"; 64 agent.CapsPath = "http://wibble.com";
55 65 client = new TestClient(agent);
56 new TextureSender(new TestClient(agent), 0, 0); 66 ts = new TextureSender(client, 0, 0);
67 testsize = random.Next(5000,15000);
68 npackets = CalculateNumPackets(testsize);
69 uuid1 = UUID.Random();
70 uuid2 = UUID.Random();
71 uuid3 = UUID.Random();
72 uuid4 = UUID.Random();
73 }
74
75 /// <summary>
76 /// Test sending package
77 /// </summary>
78 [Test]
79 public void T010_SendPkg()
80 {
81 // Normal sending
82 AssetBase abase = new AssetBase(uuid1, "asset one");
83 byte[] abdata = new byte[testsize];
84 random.NextBytes(abdata);
85 abase.Data = abdata;
86 bool isdone = false;
87 ts.TextureReceived(abase);
88 for (int i = 0; i < npackets; i++) {
89 isdone = ts.SendTexturePacket();
90 }
91
92 Assert.That(isdone,Is.False);
93 isdone = ts.SendTexturePacket();
94 Assert.That(isdone,Is.True);
95 }
96
97 [Test]
98 public void T011_UpdateReq()
99 {
100 // Test packet number start
101 AssetBase abase = new AssetBase(uuid2, "asset two");
102 byte[] abdata = new byte[testsize];
103 random.NextBytes(abdata);
104 abase.Data = abdata;
105
106 bool isdone = false;
107 ts.TextureReceived(abase);
108 ts.UpdateRequest(0,3);
109
110 for (int i = 0; i < npackets-3; i++) {
111 isdone = ts.SendTexturePacket();
112 }
113
114 Assert.That(isdone,Is.False);
115 isdone = ts.SendTexturePacket();
116 Assert.That(isdone,Is.True);
117
118 // Test discard level
119 abase = new AssetBase(uuid3, "asset three");
120 abdata = new byte[testsize];
121 random.NextBytes(abdata);
122 abase.Data = abdata;
123 isdone = false;
124 ts.TextureReceived(abase);
125 ts.UpdateRequest(-1,0);
126
127 Assert.That(ts.SendTexturePacket(),Is.True);
128
129 abase = new AssetBase(uuid4, "asset four");
130 abdata = new byte[testsize];
131 random.NextBytes(abdata);
132 abase.Data = abdata;
133 isdone = false;
134 ts.TextureReceived(abase);
135 ts.UpdateRequest(0,5);
136
137 for (int i = 0; i < npackets-5; i++) {
138 isdone = ts.SendTexturePacket();
139 }
140 Assert.That(isdone,Is.False);
141 isdone = ts.SendTexturePacket();
142 Assert.That(isdone,Is.True);
143 }
144
145 [Test]
146 public void T999_FinishStatus()
147 {
148 // Of the 4 assets "sent", only 2 sent the first part.
149 Assert.That(client.sentdatapkt.Count,Is.EqualTo(2));
150
151 // Sum of all packets sent:
152 int totalpkts = (npackets) + (npackets - 2) + (npackets - 4);
153 Assert.That(client.sentpktpkt.Count,Is.EqualTo(totalpkts));
154 }
155 /// <summary>
156 /// Calculate the number of packets that will be required to send the texture loaded into this sender
157 /// This is actually the number of 1000 byte packets not including an initial 600 byte packet...
158 /// Borrowed from TextureSender.cs
159 /// </summary>
160 /// <param name="length"></param>
161 /// <returns></returns>
162 private int CalculateNumPackets(int length)
163 {
164 int numPackets = 0;
165
166 if (length > 600)
167 {
168 //over 600 bytes so split up file
169 int restData = (length - 600);
170 int restPackets = ((restData + 999) / 1000);
171 numPackets = restPackets;
172 }
173
174 return numPackets;
57 } 175 }
58 } 176 }
59} \ No newline at end of file 177}