aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs')
-rw-r--r--OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs101
1 files changed, 93 insertions, 8 deletions
diff --git a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
index 899e721..c9dddba 100644
--- a/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
+++ b/OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs
@@ -27,11 +27,13 @@
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;
35using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar; 37using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar;
36using OpenSim.Region.Framework.Interfaces; 38using OpenSim.Region.Framework.Interfaces;
37using OpenSim.Region.Framework.Scenes; 39using OpenSim.Region.Framework.Scenes;
@@ -51,21 +53,104 @@ namespace OpenSim.Region.OptionalModules.World.NPC.Tests
51// log4net.Config.XmlConfigurator.Configure(); 53// log4net.Config.XmlConfigurator.Configure();
52 54
53 IConfigSource config = new IniConfigSource(); 55 IConfigSource config = new IniConfigSource();
56 config.AddConfig("NPC");
57 config.Configs["NPC"].Set("Enabled", "true");
54 58
55 config.AddConfig("Modules"); 59 AvatarFactoryModule afm = new AvatarFactoryModule();
56 config.Configs["Modules"].Set("AvatarServices", "LocalAvatarServicesConnector");
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
61 TestScene scene = SceneSetupHelpers.SetupScene(); 60 TestScene scene = SceneSetupHelpers.SetupScene();
62 SceneSetupHelpers.SetupSceneModules(scene, config, new NPCModule(), new LocalAvatarServicesConnector()); 61 SceneSetupHelpers.SetupSceneModules(scene, config, afm, new NPCModule());
62 TestClient originalClient = SceneSetupHelpers.AddClient(scene, TestHelper.ParseTail(0x1));
63// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
64
65 // 8 is the index of the first baked texture in AvatarAppearance
66 UUID originalFace8TextureId = TestHelper.ParseTail(0x10);
67 Primitive.TextureEntry originalTe = new Primitive.TextureEntry(UUID.Zero);
68 Primitive.TextureEntryFace originalTef = originalTe.CreateFace(8);
69 originalTef.TextureID = originalFace8TextureId;
70
71 // We also need to add the texture to the asset service, otherwise the AvatarFactoryModule will tell
72 // ScenePresence.SendInitialData() to reset our entire appearance.
73 scene.AssetService.Store(AssetHelpers.CreateAsset(originalFace8TextureId));
74
75 afm.SetAppearance(originalClient, originalTe, null);
63 76
64 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>(); 77 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
65 UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, UUID.Zero); 78 UUID npcId = npcModule.CreateNPC("John", "Smith", new Vector3(128, 128, 30), scene, originalClient.AgentId);
66 79
67 ScenePresence npc = scene.GetScenePresence(npcId); 80 ScenePresence npc = scene.GetScenePresence(npcId);
81
68 Assert.That(npc, Is.Not.Null); 82 Assert.That(npc, Is.Not.Null);
83 Assert.That(npc.Appearance.Texture.FaceTextures[8].TextureID, Is.EqualTo(originalFace8TextureId));
84 }
85
86 [Test]
87 public void TestMove()
88 {
89 TestHelper.InMethod();
90// log4net.Config.XmlConfigurator.Configure();
91
92 IConfigSource config = new IniConfigSource();
93
94 config.AddConfig("NPC");
95 config.Configs["NPC"].Set("Enabled", "true");
96
97 TestScene scene = SceneSetupHelpers.SetupScene();
98 SceneSetupHelpers.SetupSceneModules(scene, config, new NPCModule());
99 TestClient originalClient = SceneSetupHelpers.AddClient(scene, TestHelper.ParseTail(0x1));
100// ScenePresence originalAvatar = scene.GetScenePresence(originalClient.AgentId);
101
102 Vector3 startPos = new Vector3(128, 128, 30);
103 INPCModule npcModule = scene.RequestModuleInterface<INPCModule>();
104 UUID npcId = npcModule.CreateNPC("John", "Smith", startPos, scene, originalClient.AgentId);
105
106 ScenePresence npc = scene.GetScenePresence(npcId);
107 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
108
109 // For now, we'll make the scene presence fly to simplify this test, but this needs to change.
110 npc.PhysicsActor.Flying = true;
111
112 scene.Update();
113 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
114
115 Vector3 targetPos = startPos + new Vector3(0, 0, 10);
116 npcModule.MoveToTarget(npc.UUID, scene, targetPos);
117
118 Assert.That(npc.AbsolutePosition, Is.EqualTo(startPos));
119
120 scene.Update();
121
122 // We should really check the exact figure.
123 Assert.That(npc.AbsolutePosition.X, Is.EqualTo(startPos.X));
124 Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y));
125 Assert.That(npc.AbsolutePosition.Z, Is.GreaterThan(startPos.Z));
126 Assert.That(npc.AbsolutePosition.Z, Is.LessThan(targetPos.Z));
127
128 for (int i = 0; i < 10; i++)
129 scene.Update();
130
131 double distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
132 Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on first move");
133 Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
134
135 // Try a second movement
136 startPos = npc.AbsolutePosition;
137 targetPos = startPos + new Vector3(10, 0, 0);
138 npcModule.MoveToTarget(npc.UUID, scene, targetPos);
139
140 scene.Update();
141
142 // We should really check the exact figure.
143 Assert.That(npc.AbsolutePosition.X, Is.GreaterThan(startPos.X));
144 Assert.That(npc.AbsolutePosition.X, Is.LessThan(targetPos.X));
145 Assert.That(npc.AbsolutePosition.Y, Is.EqualTo(startPos.Y));
146 Assert.That(npc.AbsolutePosition.Z, Is.EqualTo(startPos.Z));
147
148 for (int i = 0; i < 10; i++)
149 scene.Update();
150
151 distanceToTarget = Util.GetDistanceTo(npc.AbsolutePosition, targetPos);
152 Assert.That(distanceToTarget, Is.LessThan(1), "NPC not within 1 unit of target position on second move");
153 Assert.That(npc.AbsolutePosition, Is.EqualTo(targetPos));
69 } 154 }
70 } 155 }
71} \ No newline at end of file 156} \ No newline at end of file