aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
diff options
context:
space:
mode:
authorTom2011-09-04 07:06:36 -0700
committerTom2011-09-04 07:06:36 -0700
commit66dec3b8742eff04fbbcc6e3249fe4ba87986500 (patch)
tree76cc708a821d35fac5cdbbce2de304b47064e732 /OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
parentGuard another nullref (diff)
parentFixed BulletSim config files for Linux *.so libraries. (diff)
downloadopensim-SC-66dec3b8742eff04fbbcc6e3249fe4ba87986500.zip
opensim-SC-66dec3b8742eff04fbbcc6e3249fe4ba87986500.tar.gz
opensim-SC-66dec3b8742eff04fbbcc6e3249fe4ba87986500.tar.bz2
opensim-SC-66dec3b8742eff04fbbcc6e3249fe4ba87986500.tar.xz
Resolve merge commits, stage 1
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs108
1 files changed, 99 insertions, 9 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
index 899e721..78296a4 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
@@ -27,11 +27,14 @@
27 27
28using System; 28using System;
29using System.Reflection; 29using System.Reflection;
30using log4net;
30using Nini.Config; 31using Nini.Config;
31using NUnit.Framework; 32using NUnit.Framework;
32using OpenMetaverse; 33using OpenMetaverse;
33using OpenSim.Framework; 34using OpenSim.Framework;
34using OpenSim.Framework.Communications; 35using OpenSim.Framework.Communications;
36using OpenSim.Region.CoreModules.Avatar.AvatarFactory;
37using OpenSim.Region.CoreModules.Framework.UserManagement;
35using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar; 38using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar;
36using OpenSim.Region.Framework.Interfaces; 39using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes; 40using OpenSim.Region.Framework.Scenes;
@@ -47,25 +50,112 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
47 [Test] 50 [Test]
48 public void TestCreate() 51 public void TestCreate()
49 { 52 {
50 TestHelper.InMethod(); 53 TestHelpers.InMethod();
51// log4net.Config.XmlConfigurator.Configure(); 54// log4net.Config.XmlConfigurator.Configure();
52 55
53 IConfigSource config = new IniConfigSource(); 56 IConfigSource config = new IniConfigSource();
57 config.AddConfig("NPC");
58 config.Configs["NPC"].Set("Enabled", "true");
54 59
55 config.AddConfig("Modules"); 60 AvatarFactoryModule afm = new AvatarFactoryModule();
56 config.Configs["Modules"].Set("AvatarServices", "LocalAvatarServicesConnector"); 61 UserManagementModule umm = new UserManagementModule();
57 config.AddConfig("AvatarService");
58 config.Configs["AvatarService"].Set("LocalServiceModule", "OpenSim.Services.AvatarService.dll:AvatarService");
59 config.Configs["AvatarService"].Set("StorageProvider", "OpenSim.Data.Null.dll");
60 62
61 TestScene scene = SceneSetupHelpers.SetupScene(); 63 TestScene scene = SceneHelpers.SetupScene();
62 SceneSetupHelpers.SetupSceneModules(scene, config, new NPCModule(), new LocalAvatarServicesConnector()); 64 SceneHelpers.SetupSceneModules(scene, config, afm, umm, new NPCModule());
65 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
66// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
67
68 // 8 is the index of the first baked texture in AvatarAppearance
69 UUID originalFace8TextureId = TestHelpers.ParseTail(0x10);
70 Primitive.TextureEntry originalTe = new Primitive.TextureEntry(UUID.Zero);
71 Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8);
72 originalTef.TextureID = originalFace8TextureId;
73
74 // We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell
75 // ScenePresence.SendInitialData() to reset our entire appearance.
76 scene.AssetService.Store(AssetHelpers.CreateAsset(originalFace8TextureId));
77
78 afm.SetAppearanceFromClient(sp.ControllingClient, originalTe, null);
63 79
64 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); 80 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
65 UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, UUID.Zero); 81 UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, sp.Appearance);
66 82
67 ScenePresence npc = scene.GetScenePresence(npcId); 83 ScenePresence npc = scene.GetScenePresence(npcId);
84
68 Assert.That(npc, Is.Not.Null); 85 Assert.That(npc, Is.Not.Null);
86 Assert.That(npc.Appearance.Texture.FaceTextures[8].TextureID, Is.EqualTo(originalFace8TextureId));
87 Assert.That(umm.GetUserName(npc.UUID), Is.EqualTo(string.Format("{0} {1}", npc.Firstname, npc.Lastname)));
88 }
89
90 [Test]
91 public void TestMove()
92 {
93 TestHelpers.InMethod();
94// log4net.Config.XmlConfigurator.Configure();
95
96 IConfigSource config = new IniConfigSource();
97
98 config.AddConfig("NPC");
99 config.Configs["NPC"].Set("Enabled", "true");
100
101 TestScene scene = SceneHelpers.SetupScene();
102 SceneHelpers.SetupSceneModules(scene, config, new NPCModule());
103 ScenePresence sp = SceneHelpers.AddScenePresence(scene, TestHelpers.ParseTail(0x1));
104// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
105
106 Vector3 startPos = new Vector3(128, 128, 30);
107 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
108 UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, sp.Appearance);
109
110 ScenePresence npc = scene.GetScenePresence(npcId);
111 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
112
113 // For now, we'll make the scene presence fly to simplify this test, but this needs to change.
114 npc.PhysicsActor.Flying = true;
115
116 scene.Update();
117 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
118
119 Vector3 targetPos = startPos + new Vector3(0, 0, 10);
120 npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false);
121
122 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
123
124 scene.Update();
125
126 // We should really check the exact figure.
127 Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X));
128 Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y));
129 Assert.That(npc.AbsolutePosition.Z, Is.GreaterThan(startPos.Z));
130 Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.Z));
131
132 for (int i = 0; i < 10; i++)
133 scene.Update();
134
135 double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
136 Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move");
137 Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
138 Assert.That(npc.AgentControlFlags, Is.EqualTo((uint)AgentManager.ControlFlags.NONE));
139
140 // Try a second movement
141 startPos = npc.AbsolutePosition;
142 targetPos = startPos + new Vector3(10, 0, 0);
143 npcModule.MoveToTarget(npc.UUID, scene, targetPos, false, false);
144
145 scene.Update();
146
147 // We should really check the exact figure.
148 Assert.That(npc.AbsolutePosition.X, Is.GreaterThan(startPos.X));
149 Assert.That(npc.AbsolutePosition.X, Is.LessThan(targetPos.X));
150 Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y));
151 Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
152
153 for (int i = 0; i < 10; i++)
154 scene.Update();
155
156 distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
157 Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move");
158 Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
69 } 159 }
70 } 160 }
71} \ No newline at end of file 161} \ No newline at end of file