diff options
Diffstat (limited to 'OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs')
-rw-r--r-- | OpenSim/Region/OptionalModules/World/NPC/Tests/NPCModuleTests.cs | 108 |
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 | ||
28 | using System; | 28 | using System; |
29 | using System.Reflection; | 29 | using System.Reflection; |
30 | using log4net; | ||
30 | using Nini.Config; | 31 | using Nini.Config; |
31 | using NUnit.Framework; | 32 | using NUnit.Framework; |
32 | using OpenMetaverse; | 33 | using OpenMetaverse; |
33 | using OpenSim.Framework; | 34 | using OpenSim.Framework; |
34 | using OpenSim.Framework.Communications; | 35 | using OpenSim.Framework.Communications; |
36 | using OpenSim.Region.CoreModules.Avatar.AvatarFactory; | ||
37 | using OpenSim.Region.CoreModules.Framework.UserManagement; | ||
35 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar; | 38 | using OpenSim.Region.CoreModules.ServiceConnectorsOut.Avatar; |
36 | using OpenSim.Region.Framework.Interfaces; | 39 | using OpenSim.Region.Framework.Interfaces; |
37 | using OpenSim.Region.Framework.Scenes; | 40 | using 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 |