* Extended TextureSenderTests and modified TestClient.cs with new methods

From: Arthur Rodrigo S Valadares <arthursv@linux.vnet.ibm.com>
0.6.2-post-fixes
Sean Dague 2009-01-13 19:55:07 +00:00
parent 1baa921463
commit 9dff38ca14
2 changed files with 167 additions and 27 deletions

View File

@ -25,9 +25,13 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/ */
using System;
using System.Collections;
using NUnit.Framework; using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;
using OpenMetaverse; using OpenMetaverse;
using OpenSim.Framework; using OpenSim.Framework;
using OpenSim.Tests.Common.Mock; using OpenSim.Tests.Common.Mock;
namespace OpenSim.Region.Environment.Modules.Agent.TextureSender namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
@ -35,11 +39,17 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
[TestFixture] [TestFixture]
public class UserTextureSenderTests public class UserTextureSenderTests
{ {
[Test] public UUID uuid1;
/// <summary> public UUID uuid2;
/// More a placeholder, really public UUID uuid3;
/// </summary> public UUID uuid4;
public void DummyTest() public int npackets, testsize;
public TestClient client;
public TextureSender ts;
public static Random random = new Random();
[TestFixtureSetUp]
public void Init()
{ {
AgentCircuitData agent = new AgentCircuitData(); AgentCircuitData agent = new AgentCircuitData();
agent.AgentID = UUID.Random(); agent.AgentID = UUID.Random();
@ -52,8 +62,116 @@ namespace OpenSim.Region.Environment.Modules.Agent.TextureSender
agent.InventoryFolder = UUID.Zero; agent.InventoryFolder = UUID.Zero;
agent.startpos = Vector3.Zero; agent.startpos = Vector3.Zero;
agent.CapsPath = "http://wibble.com"; agent.CapsPath = "http://wibble.com";
client = new TestClient(agent);
new TextureSender(new TestClient(agent), 0, 0); ts = new TextureSender(client, 0, 0);
testsize = random.Next(5000,15000);
npackets = CalculateNumPackets(testsize);
uuid1 = UUID.Random();
uuid2 = UUID.Random();
uuid3 = UUID.Random();
uuid4 = UUID.Random();
}
/// <summary>
/// Test sending package
/// </summary>
[Test]
public void T010_SendPkg()
{
// Normal sending
AssetBase abase = new AssetBase(uuid1, "asset one");
byte[] abdata = new byte[testsize];
random.NextBytes(abdata);
abase.Data = abdata;
bool isdone = false;
ts.TextureReceived(abase);
for (int i = 0; i < npackets; i++) {
isdone = ts.SendTexturePacket();
}
Assert.That(isdone,Is.False);
isdone = ts.SendTexturePacket();
Assert.That(isdone,Is.True);
}
[Test]
public void T011_UpdateReq()
{
// Test packet number start
AssetBase abase = new AssetBase(uuid2, "asset two");
byte[] abdata = new byte[testsize];
random.NextBytes(abdata);
abase.Data = abdata;
bool isdone = false;
ts.TextureReceived(abase);
ts.UpdateRequest(0,3);
for (int i = 0; i < npackets-3; i++) {
isdone = ts.SendTexturePacket();
}
Assert.That(isdone,Is.False);
isdone = ts.SendTexturePacket();
Assert.That(isdone,Is.True);
// Test discard level
abase = new AssetBase(uuid3, "asset three");
abdata = new byte[testsize];
random.NextBytes(abdata);
abase.Data = abdata;
isdone = false;
ts.TextureReceived(abase);
ts.UpdateRequest(-1,0);
Assert.That(ts.SendTexturePacket(),Is.True);
abase = new AssetBase(uuid4, "asset four");
abdata = new byte[testsize];
random.NextBytes(abdata);
abase.Data = abdata;
isdone = false;
ts.TextureReceived(abase);
ts.UpdateRequest(0,5);
for (int i = 0; i < npackets-5; i++) {
isdone = ts.SendTexturePacket();
}
Assert.That(isdone,Is.False);
isdone = ts.SendTexturePacket();
Assert.That(isdone,Is.True);
}
[Test]
public void T999_FinishStatus()
{
// Of the 4 assets "sent", only 2 sent the first part.
Assert.That(client.sentdatapkt.Count,Is.EqualTo(2));
// Sum of all packets sent:
int totalpkts = (npackets) + (npackets - 2) + (npackets - 4);
Assert.That(client.sentpktpkt.Count,Is.EqualTo(totalpkts));
}
/// <summary>
/// Calculate the number of packets that will be required to send the texture loaded into this sender
/// This is actually the number of 1000 byte packets not including an initial 600 byte packet...
/// Borrowed from TextureSender.cs
/// </summary>
/// <param name="length"></param>
/// <returns></returns>
private int CalculateNumPackets(int length)
{
int numPackets = 0;
if (length > 600)
{
//over 600 bytes so split up file
int restData = (length - 600);
int restPackets = ((restData + 999) / 1000);
numPackets = restPackets;
}
return numPackets;
} }
} }
} }

View File

@ -39,6 +39,10 @@ namespace OpenSim.Tests.Common.Mock
{ {
private Scene m_scene; private Scene m_scene;
// Mock testing variables
public List<ImageDataPacket> sentdatapkt = new List<ImageDataPacket>();
public List<ImagePacketPacket> sentpktpkt = new List<ImagePacketPacket>();
// disable warning: public events, part of the public API // disable warning: public events, part of the public API
#pragma warning disable 67 #pragma warning disable 67
@ -215,7 +219,7 @@ namespace OpenSim.Tests.Common.Mock
public event ActivateGesture OnActivateGesture; public event ActivateGesture OnActivateGesture;
public event DeactivateGesture OnDeactivateGesture; public event DeactivateGesture OnDeactivateGesture;
public event ObjectOwner OnObjectOwner; public event ObjectOwner OnObjectOwner;
public event DirPlacesQuery OnDirPlacesQuery; public event DirPlacesQuery OnDirPlacesQuery;
public event DirFindQuery OnDirFindQuery; public event DirFindQuery OnDirFindQuery;
public event DirLandQuery OnDirLandQuery; public event DirLandQuery OnDirLandQuery;
@ -229,7 +233,7 @@ namespace OpenSim.Tests.Common.Mock
public event OfferCallingCard OnOfferCallingCard; public event OfferCallingCard OnOfferCallingCard;
public event AcceptCallingCard OnAcceptCallingCard; public event AcceptCallingCard OnAcceptCallingCard;
public event DeclineCallingCard OnDeclineCallingCard; public event DeclineCallingCard OnDeclineCallingCard;
public event SoundTrigger OnSoundTrigger; public event SoundTrigger OnSoundTrigger;
public event StartLure OnStartLure; public event StartLure OnStartLure;
@ -284,7 +288,7 @@ namespace OpenSim.Tests.Common.Mock
{ {
get { return m_firstName; } get { return m_firstName; }
} }
private string m_firstName; private string m_firstName;
public virtual string LastName public virtual string LastName
{ {
@ -359,7 +363,7 @@ namespace OpenSim.Tests.Common.Mock
{ {
myID = agentData.AgentID; myID = agentData.AgentID;
m_firstName = agentData.firstname; m_firstName = agentData.firstname;
m_lastName = agentData.lastname; m_lastName = agentData.lastname;
} }
public virtual void ActivateGesture(UUID assetId, UUID gestureId) public virtual void ActivateGesture(UUID assetId, UUID gestureId)
@ -420,12 +424,12 @@ namespace OpenSim.Tests.Common.Mock
public void SendInstantMessage(UUID fromAgent, string message, UUID toAgent, string fromName, byte dialog, uint timeStamp) public void SendInstantMessage(UUID fromAgent, string message, UUID toAgent, string fromName, byte dialog, uint timeStamp)
{ {
} }
public void SendInstantMessage(UUID fromAgent, string message, UUID toAgent, string fromName, byte dialog, uint timeStamp, UUID transactionID, bool fromGroup, byte[] binaryBucket) public void SendInstantMessage(UUID fromAgent, string message, UUID toAgent, string fromName, byte dialog, uint timeStamp, UUID transactionID, bool fromGroup, byte[] binaryBucket)
{ {
} }
public void SendGenericMessage(string method, List<string> message) public void SendGenericMessage(string method, List<string> message)
@ -563,7 +567,7 @@ namespace OpenSim.Tests.Common.Mock
public virtual void SendBulkUpdateInventory(InventoryItemBase item) public virtual void SendBulkUpdateInventory(InventoryItemBase item)
{ {
} }
public void SendBulkUpdateInventory(InventoryFolderBase folderBase) public void SendBulkUpdateInventory(InventoryFolderBase folderBase)
{} {}
@ -590,7 +594,7 @@ namespace OpenSim.Tests.Common.Mock
int PricePublicObjectDelete, int PriceRentLight, int PriceUpload, int TeleportMinPrice, float TeleportPriceExponent) int PricePublicObjectDelete, int PriceRentLight, int PriceUpload, int TeleportMinPrice, float TeleportPriceExponent)
{ {
} }
public virtual void SendNameReply(UUID profileId, string firstname, string lastname) public virtual void SendNameReply(UUID profileId, string firstname, string lastname)
{ {
} }
@ -660,16 +664,34 @@ namespace OpenSim.Tests.Common.Mock
public void SendImageFirstPart(ushort numParts, UUID ImageUUID, uint ImageSize, byte[] ImageData, byte imageCodec) public void SendImageFirstPart(ushort numParts, UUID ImageUUID, uint ImageSize, byte[] ImageData, byte imageCodec)
{ {
ImageDataPacket im = new ImageDataPacket();
im.Header.Reliable = false;
im.ImageID.Packets = numParts;
im.ImageID.ID = ImageUUID;
if (ImageSize > 0)
im.ImageID.Size = ImageSize;
im.ImageData.Data = ImageData;
im.ImageID.Codec = imageCodec;
im.Header.Zerocoded = true;
sentdatapkt.Add(im);
} }
public void SendImageNextPart(ushort partNumber, UUID imageUuid, byte[] imageData) public void SendImageNextPart(ushort partNumber, UUID imageUuid, byte[] imageData)
{ {
ImagePacketPacket im = new ImagePacketPacket();
im.Header.Reliable = false;
im.ImageID.Packet = partNumber;
im.ImageID.ID = imageUuid;
im.ImageData.Data = imageData;
sentpktpkt.Add(im);
} }
public void SendImageNotFound(UUID imageid) public void SendImageNotFound(UUID imageid)
{ {
} }
public void SendShutdownConnectionNotice() public void SendShutdownConnectionNotice()
{ {
} }
@ -726,10 +748,10 @@ namespace OpenSim.Tests.Common.Mock
public void SendSunPos(Vector3 sunPos, Vector3 sunVel, ulong time, uint dlen, uint ylen, float phase) public void SendSunPos(Vector3 sunPos, Vector3 sunVel, ulong time, uint dlen, uint ylen, float phase)
{ {
} }
public void SendViewerEffect(ViewerEffectPacket.EffectBlock[] effectBlocks) public void SendViewerEffect(ViewerEffectPacket.EffectBlock[] effectBlocks)
{ {
} }
public void SendViewerTime(int phase) public void SendViewerTime(int phase)
{ {
@ -804,11 +826,11 @@ namespace OpenSim.Tests.Common.Mock
public void SendRegionInfoToEstateMenu(RegionInfoForEstateMenuArgs args) public void SendRegionInfoToEstateMenu(RegionInfoForEstateMenuArgs args)
{ {
} }
public void SendEstateCovenantInformation(UUID covenant) public void SendEstateCovenantInformation(UUID covenant)
{ {
} }
public void SendDetailedEstateData(UUID invoice, string estateName, uint estateID, uint parentEstate, uint estateFlags, uint sunPosition, UUID covenant, string abuseEmail, UUID estateOwner) public void SendDetailedEstateData(UUID invoice, string estateName, uint estateID, uint parentEstate, uint estateFlags, uint sunPosition, UUID covenant, string abuseEmail, UUID estateOwner)
{ {
} }
@ -816,19 +838,19 @@ namespace OpenSim.Tests.Common.Mock
public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, LandData landData, float simObjectBonusFactor, int parcelObjectCapacity, int simObjectCapacity, uint regionFlags) public void SendLandProperties(int sequence_id, bool snap_selection, int request_result, LandData landData, float simObjectBonusFactor, int parcelObjectCapacity, int simObjectCapacity, uint regionFlags)
{ {
} }
public void SendLandAccessListData(List<UUID> avatars, uint accessFlag, int localLandID) public void SendLandAccessListData(List<UUID> avatars, uint accessFlag, int localLandID)
{ {
} }
public void SendForceClientSelectObjects(List<uint> objectIDs) public void SendForceClientSelectObjects(List<uint> objectIDs)
{ {
} }
public void SendLandObjectOwners(Dictionary<UUID, int> ownersAndCount) public void SendLandObjectOwners(Dictionary<UUID, int> ownersAndCount)
{ {
} }
public void SendLandParcelOverlay(byte[] data, int sequence_id) public void SendLandParcelOverlay(byte[] data, int sequence_id)
{ {
} }