diff options
author | teravus | 2012-11-15 10:05:16 -0500 |
---|---|---|
committer | teravus | 2012-11-15 10:05:16 -0500 |
commit | e9153e1d1aae50024d8cd05fe14a9bce34343a0e (patch) | |
tree | bc111d34f95a26b99c7e34d9e495dc14d1802cc3 /OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs | |
parent | Merge master into teravuswork (diff) | |
download | opensim-SC_OLD-e9153e1d1aae50024d8cd05fe14a9bce34343a0e.zip opensim-SC_OLD-e9153e1d1aae50024d8cd05fe14a9bce34343a0e.tar.gz opensim-SC_OLD-e9153e1d1aae50024d8cd05fe14a9bce34343a0e.tar.bz2 opensim-SC_OLD-e9153e1d1aae50024d8cd05fe14a9bce34343a0e.tar.xz |
Revert "Merge master into teravuswork", it should have been avination, not master.
This reverts commit dfac269032300872c4d0dc507f4f9062d102b0f4, reversing
changes made to 619c39e5144f15aca129d6d999bcc5c34133ee64.
Diffstat (limited to '')
-rw-r--r-- | OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs | 404 |
1 files changed, 64 insertions, 340 deletions
diff --git a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs index 82f49b0..5deaf52 100644 --- a/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs +++ b/OpenSim/Region/CoreModules/World/Archiver/Tests/ArchiverTests.cs | |||
@@ -47,41 +47,32 @@ using ArchiveConstants = OpenSim.Framework.Serialization.ArchiveConstants; | |||
47 | using TarArchiveReader = OpenSim.Framework.Serialization.TarArchiveReader; | 47 | using TarArchiveReader = OpenSim.Framework.Serialization.TarArchiveReader; |
48 | using TarArchiveWriter = OpenSim.Framework.Serialization.TarArchiveWriter; | 48 | using TarArchiveWriter = OpenSim.Framework.Serialization.TarArchiveWriter; |
49 | using RegionSettings = OpenSim.Framework.RegionSettings; | 49 | using RegionSettings = OpenSim.Framework.RegionSettings; |
50 | using OpenSim.Region.Framework.Interfaces; | ||
51 | 50 | ||
52 | namespace OpenSim.Region.CoreModules.World.Archiver.Tests | 51 | namespace OpenSim.Region.CoreModules.World.Archiver.Tests |
53 | { | 52 | { |
54 | [TestFixture] | 53 | [TestFixture] |
55 | public class ArchiverTests : OpenSimTestCase | 54 | public class ArchiverTests |
56 | { | 55 | { |
57 | private Guid m_lastRequestId; | 56 | private Guid m_lastRequestId; |
58 | private string m_lastErrorMessage; | 57 | private string m_lastErrorMessage; |
59 | 58 | ||
60 | protected SceneHelpers m_sceneHelpers; | ||
61 | protected TestScene m_scene; | 59 | protected TestScene m_scene; |
62 | protected ArchiverModule m_archiverModule; | 60 | protected ArchiverModule m_archiverModule; |
63 | protected SerialiserModule m_serialiserModule; | ||
64 | 61 | ||
65 | protected TaskInventoryItem m_soundItem; | 62 | protected TaskInventoryItem m_soundItem; |
66 | 63 | ||
67 | [SetUp] | 64 | [SetUp] |
68 | public override void SetUp() | 65 | public void SetUp() |
69 | { | 66 | { |
70 | base.SetUp(); | ||
71 | |||
72 | // FIXME: Do something about this - relying on statics in unit tests causes trouble sooner or later | ||
73 | new SceneManager(); | ||
74 | |||
75 | m_archiverModule = new ArchiverModule(); | 67 | m_archiverModule = new ArchiverModule(); |
76 | m_serialiserModule = new SerialiserModule(); | 68 | SerialiserModule serialiserModule = new SerialiserModule(); |
77 | TerrainModule terrainModule = new TerrainModule(); | 69 | TerrainModule terrainModule = new TerrainModule(); |
78 | 70 | ||
79 | m_sceneHelpers = new SceneHelpers(); | 71 | m_scene = new SceneHelpers().SetupScene(); |
80 | m_scene = m_sceneHelpers.SetupScene(); | 72 | SceneHelpers.SetupSceneModules(m_scene, m_archiverModule, serialiserModule, terrainModule); |
81 | SceneHelpers.SetupSceneModules(m_scene, m_archiverModule, m_serialiserModule, terrainModule); | ||
82 | } | 73 | } |
83 | 74 | ||
84 | private void LoadCompleted(Guid requestId, List<UUID> loadedScenes, string errorMessage) | 75 | private void LoadCompleted(Guid requestId, string errorMessage) |
85 | { | 76 | { |
86 | lock (this) | 77 | lock (this) |
87 | { | 78 | { |
@@ -137,10 +128,26 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
137 | TestHelpers.InMethod(); | 128 | TestHelpers.InMethod(); |
138 | // log4net.Config.XmlConfigurator.Configure(); | 129 | // log4net.Config.XmlConfigurator.Configure(); |
139 | 130 | ||
140 | SceneObjectGroup sog1; | 131 | SceneObjectPart part1 = CreateSceneObjectPart1(); |
141 | SceneObjectGroup sog2; | 132 | SceneObjectGroup sog1 = new SceneObjectGroup(part1); |
142 | UUID ncAssetUuid; | 133 | m_scene.AddNewSceneObject(sog1, false); |
143 | CreateTestObjects(m_scene, out sog1, out sog2, out ncAssetUuid); | 134 | |
135 | SceneObjectPart part2 = CreateSceneObjectPart2(); | ||
136 | |||
137 | AssetNotecard nc = new AssetNotecard(); | ||
138 | nc.BodyText = "Hello World!"; | ||
139 | nc.Encode(); | ||
140 | UUID ncAssetUuid = new UUID("00000000-0000-0000-1000-000000000000"); | ||
141 | UUID ncItemUuid = new UUID("00000000-0000-0000-1100-000000000000"); | ||
142 | AssetBase ncAsset | ||
143 | = AssetHelpers.CreateAsset(ncAssetUuid, AssetType.Notecard, nc.AssetData, UUID.Zero); | ||
144 | m_scene.AssetService.Store(ncAsset); | ||
145 | SceneObjectGroup sog2 = new SceneObjectGroup(part2); | ||
146 | TaskInventoryItem ncItem | ||
147 | = new TaskInventoryItem { Name = "ncItem", AssetID = ncAssetUuid, ItemID = ncItemUuid }; | ||
148 | part2.Inventory.AddInventoryItem(ncItem, true); | ||
149 | |||
150 | m_scene.AddNewSceneObject(sog2, false); | ||
144 | 151 | ||
145 | MemoryStream archiveWriteStream = new MemoryStream(); | 152 | MemoryStream archiveWriteStream = new MemoryStream(); |
146 | m_scene.EventManager.OnOarFileSaved += SaveCompleted; | 153 | m_scene.EventManager.OnOarFileSaved += SaveCompleted; |
@@ -179,7 +186,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
179 | Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH)); | 186 | Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH)); |
180 | 187 | ||
181 | ArchiveReadRequest arr = new ArchiveReadRequest(m_scene, (Stream)null, false, false, Guid.Empty); | 188 | ArchiveReadRequest arr = new ArchiveReadRequest(m_scene, (Stream)null, false, false, Guid.Empty); |
182 | arr.LoadControlFile(filePath, data, new DearchiveScenesInfo()); | 189 | arr.LoadControlFile(filePath, data); |
183 | 190 | ||
184 | Assert.That(arr.ControlFileLoaded, Is.True); | 191 | Assert.That(arr.ControlFileLoaded, Is.True); |
185 | 192 | ||
@@ -204,30 +211,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
204 | // TODO: Test presence of more files and contents of files. | 211 | // TODO: Test presence of more files and contents of files. |
205 | } | 212 | } |
206 | 213 | ||
207 | private void CreateTestObjects(Scene scene, out SceneObjectGroup sog1, out SceneObjectGroup sog2, out UUID ncAssetUuid) | ||
208 | { | ||
209 | SceneObjectPart part1 = CreateSceneObjectPart1(); | ||
210 | sog1 = new SceneObjectGroup(part1); | ||
211 | scene.AddNewSceneObject(sog1, false); | ||
212 | |||
213 | AssetNotecard nc = new AssetNotecard(); | ||
214 | nc.BodyText = "Hello World!"; | ||
215 | nc.Encode(); | ||
216 | ncAssetUuid = UUID.Random(); | ||
217 | UUID ncItemUuid = UUID.Random(); | ||
218 | AssetBase ncAsset | ||
219 | = AssetHelpers.CreateAsset(ncAssetUuid, AssetType.Notecard, nc.AssetData, UUID.Zero); | ||
220 | m_scene.AssetService.Store(ncAsset); | ||
221 | |||
222 | TaskInventoryItem ncItem | ||
223 | = new TaskInventoryItem { Name = "ncItem", AssetID = ncAssetUuid, ItemID = ncItemUuid }; | ||
224 | SceneObjectPart part2 = CreateSceneObjectPart2(); | ||
225 | sog2 = new SceneObjectGroup(part2); | ||
226 | part2.Inventory.AddInventoryItem(ncItem, true); | ||
227 | |||
228 | scene.AddNewSceneObject(sog2, false); | ||
229 | } | ||
230 | |||
231 | /// <summary> | 214 | /// <summary> |
232 | /// Test saving an OpenSim Region Archive with the no assets option | 215 | /// Test saving an OpenSim Region Archive with the no assets option |
233 | /// </summary> | 216 | /// </summary> |
@@ -287,7 +270,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
287 | Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH)); | 270 | Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH)); |
288 | 271 | ||
289 | ArchiveReadRequest arr = new ArchiveReadRequest(m_scene, (Stream)null, false, false, Guid.Empty); | 272 | ArchiveReadRequest arr = new ArchiveReadRequest(m_scene, (Stream)null, false, false, Guid.Empty); |
290 | arr.LoadControlFile(filePath, data, new DearchiveScenesInfo()); | 273 | arr.LoadControlFile(filePath, data); |
291 | 274 | ||
292 | Assert.That(arr.ControlFileLoaded, Is.True); | 275 | Assert.That(arr.ControlFileLoaded, Is.True); |
293 | 276 | ||
@@ -324,7 +307,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
324 | 307 | ||
325 | tar.WriteFile( | 308 | tar.WriteFile( |
326 | ArchiveConstants.CONTROL_FILE_PATH, | 309 | ArchiveConstants.CONTROL_FILE_PATH, |
327 | new ArchiveWriteRequest(m_scene, (Stream)null, Guid.Empty).CreateControlFile(new ArchiveScenesGroup())); | 310 | new ArchiveWriteRequestPreparation(null, (Stream)null, Guid.Empty).CreateControlFile(new Dictionary<string, Object>())); |
328 | 311 | ||
329 | SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ownerId, "obj1-", 0x11); | 312 | SceneObjectGroup sog1 = SceneHelpers.CreateSceneObject(1, ownerId, "obj1-", 0x11); |
330 | SceneObjectPart sop2 | 313 | SceneObjectPart sop2 |
@@ -379,10 +362,11 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
379 | // Also check that direct entries which will also have a file entry containing that directory doesn't | 362 | // Also check that direct entries which will also have a file entry containing that directory doesn't |
380 | // upset load | 363 | // upset load |
381 | tar.WriteDir(ArchiveConstants.TERRAINS_PATH); | 364 | tar.WriteDir(ArchiveConstants.TERRAINS_PATH); |
382 | 365 | ||
383 | tar.WriteFile( | 366 | tar.WriteFile( |
384 | ArchiveConstants.CONTROL_FILE_PATH, | 367 | ArchiveConstants.CONTROL_FILE_PATH, |
385 | new ArchiveWriteRequest(m_scene, (Stream)null, Guid.Empty).CreateControlFile(new ArchiveScenesGroup())); | 368 | new ArchiveWriteRequestPreparation(null, (Stream)null, Guid.Empty).CreateControlFile(new Dictionary<string, Object>())); |
369 | |||
386 | SceneObjectPart part1 = CreateSceneObjectPart1(); | 370 | SceneObjectPart part1 = CreateSceneObjectPart1(); |
387 | 371 | ||
388 | part1.SitTargetOrientation = new Quaternion(0.2f, 0.3f, 0.4f, 0.5f); | 372 | part1.SitTargetOrientation = new Quaternion(0.2f, 0.3f, 0.4f, 0.5f); |
@@ -405,12 +389,31 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
405 | Assert.That(soundDataResourceName, Is.Not.Null); | 389 | Assert.That(soundDataResourceName, Is.Not.Null); |
406 | 390 | ||
407 | byte[] soundData; | 391 | byte[] soundData; |
408 | UUID soundUuid; | 392 | Console.WriteLine("Loading " + soundDataResourceName); |
409 | CreateSoundAsset(tar, assembly, soundDataResourceName, out soundData, out soundUuid); | 393 | using (Stream resource = assembly.GetManifestResourceStream(soundDataResourceName)) |
410 | 394 | { | |
411 | TaskInventoryItem item1 | 395 | using (BinaryReader br = new BinaryReader(resource)) |
412 | = new TaskInventoryItem { AssetID = soundUuid, ItemID = soundItemUuid, Name = soundItemName }; | 396 | { |
413 | part1.Inventory.AddInventoryItem(item1, true); | 397 | // FIXME: Use the inspector instead |
398 | soundData = br.ReadBytes(99999999); | ||
399 | UUID soundUuid = UUID.Parse("00000000-0000-0000-0000-000000000001"); | ||
400 | string soundAssetFileName | ||
401 | = ArchiveConstants.ASSETS_PATH + soundUuid | ||
402 | + ArchiveConstants.ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SoundWAV]; | ||
403 | tar.WriteFile(soundAssetFileName, soundData); | ||
404 | |||
405 | /* | ||
406 | AssetBase soundAsset = AssetHelpers.CreateAsset(soundUuid, soundData); | ||
407 | scene.AssetService.Store(soundAsset); | ||
408 | asset1FileName = ArchiveConstants.ASSETS_PATH + soundUuid + ".wav"; | ||
409 | */ | ||
410 | |||
411 | TaskInventoryItem item1 | ||
412 | = new TaskInventoryItem { AssetID = soundUuid, ItemID = soundItemUuid, Name = soundItemName }; | ||
413 | part1.Inventory.AddInventoryItem(item1, true); | ||
414 | } | ||
415 | } | ||
416 | |||
414 | m_scene.AddNewSceneObject(object1, false); | 417 | m_scene.AddNewSceneObject(object1, false); |
415 | 418 | ||
416 | string object1FileName = string.Format( | 419 | string object1FileName = string.Format( |
@@ -432,34 +435,6 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
432 | 435 | ||
433 | Assert.That(m_lastErrorMessage, Is.Null); | 436 | Assert.That(m_lastErrorMessage, Is.Null); |
434 | 437 | ||
435 | TestLoadedRegion(part1, soundItemName, soundData); | ||
436 | } | ||
437 | |||
438 | private static void CreateSoundAsset(TarArchiveWriter tar, Assembly assembly, string soundDataResourceName, out byte[] soundData, out UUID soundUuid) | ||
439 | { | ||
440 | using (Stream resource = assembly.GetManifestResourceStream(soundDataResourceName)) | ||
441 | { | ||
442 | using (BinaryReader br = new BinaryReader(resource)) | ||
443 | { | ||
444 | // FIXME: Use the inspector instead | ||
445 | soundData = br.ReadBytes(99999999); | ||
446 | soundUuid = UUID.Parse("00000000-0000-0000-0000-000000000001"); | ||
447 | string soundAssetFileName | ||
448 | = ArchiveConstants.ASSETS_PATH + soundUuid | ||
449 | + ArchiveConstants.ASSET_TYPE_TO_EXTENSION[(sbyte)AssetType.SoundWAV]; | ||
450 | tar.WriteFile(soundAssetFileName, soundData); | ||
451 | |||
452 | /* | ||
453 | AssetBase soundAsset = AssetHelpers.CreateAsset(soundUuid, soundData); | ||
454 | scene.AssetService.Store(soundAsset); | ||
455 | asset1FileName = ArchiveConstants.ASSETS_PATH + soundUuid + ".wav"; | ||
456 | */ | ||
457 | } | ||
458 | } | ||
459 | } | ||
460 | |||
461 | private void TestLoadedRegion(SceneObjectPart part1, string soundItemName, byte[] soundData) | ||
462 | { | ||
463 | SceneObjectPart object1PartLoaded = m_scene.GetSceneObjectPart(part1.Name); | 438 | SceneObjectPart object1PartLoaded = m_scene.GetSceneObjectPart(part1.Name); |
464 | 439 | ||
465 | Assert.That(object1PartLoaded, Is.Not.Null, "object1 was not loaded"); | 440 | Assert.That(object1PartLoaded, Is.Not.Null, "object1 was not loaded"); |
@@ -479,6 +454,9 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
479 | Assert.That(loadedSoundAsset.Data, Is.EqualTo(soundData), "saved and loaded sound data do not match"); | 454 | Assert.That(loadedSoundAsset.Data, Is.EqualTo(soundData), "saved and loaded sound data do not match"); |
480 | 455 | ||
481 | Assert.Greater(m_scene.LandChannel.AllParcels().Count, 0, "incorrect number of parcels"); | 456 | Assert.Greater(m_scene.LandChannel.AllParcels().Count, 0, "incorrect number of parcels"); |
457 | |||
458 | // Temporary | ||
459 | Console.WriteLine("Successfully completed {0}", MethodBase.GetCurrentMethod()); | ||
482 | } | 460 | } |
483 | 461 | ||
484 | /// <summary> | 462 | /// <summary> |
@@ -538,8 +516,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
538 | SerialiserModule serialiserModule = new SerialiserModule(); | 516 | SerialiserModule serialiserModule = new SerialiserModule(); |
539 | TerrainModule terrainModule = new TerrainModule(); | 517 | TerrainModule terrainModule = new TerrainModule(); |
540 | 518 | ||
541 | m_sceneHelpers = new SceneHelpers(); | 519 | TestScene scene2 = new SceneHelpers().SetupScene(); |
542 | TestScene scene2 = m_sceneHelpers.SetupScene(); | ||
543 | SceneHelpers.SetupSceneModules(scene2, archiverModule, serialiserModule, terrainModule); | 520 | SceneHelpers.SetupSceneModules(scene2, archiverModule, serialiserModule, terrainModule); |
544 | 521 | ||
545 | // Make sure there's a valid owner for the owner we saved (this should have been wiped if the code is | 522 | // Make sure there's a valid owner for the owner we saved (this should have been wiped if the code is |
@@ -577,7 +554,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
577 | tar.WriteDir(ArchiveConstants.TERRAINS_PATH); | 554 | tar.WriteDir(ArchiveConstants.TERRAINS_PATH); |
578 | tar.WriteFile( | 555 | tar.WriteFile( |
579 | ArchiveConstants.CONTROL_FILE_PATH, | 556 | ArchiveConstants.CONTROL_FILE_PATH, |
580 | new ArchiveWriteRequest(m_scene, (Stream)null, Guid.Empty).CreateControlFile(new ArchiveScenesGroup())); | 557 | new ArchiveWriteRequestPreparation(null, (Stream)null, Guid.Empty).CreateControlFile(new Dictionary<string, Object>())); |
581 | 558 | ||
582 | RegionSettings rs = new RegionSettings(); | 559 | RegionSettings rs = new RegionSettings(); |
583 | rs.AgentLimit = 17; | 560 | rs.AgentLimit = 17; |
@@ -687,7 +664,7 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
687 | SerialiserModule serialiserModule = new SerialiserModule(); | 664 | SerialiserModule serialiserModule = new SerialiserModule(); |
688 | TerrainModule terrainModule = new TerrainModule(); | 665 | TerrainModule terrainModule = new TerrainModule(); |
689 | 666 | ||
690 | Scene scene = m_sceneHelpers.SetupScene(); | 667 | Scene scene = new SceneHelpers().SetupScene(); |
691 | SceneHelpers.SetupSceneModules(scene, archiverModule, serialiserModule, terrainModule); | 668 | SceneHelpers.SetupSceneModules(scene, archiverModule, serialiserModule, terrainModule); |
692 | 669 | ||
693 | m_scene.AddNewSceneObject(new SceneObjectGroup(part2), false); | 670 | m_scene.AddNewSceneObject(new SceneObjectGroup(part2), false); |
@@ -723,258 +700,5 @@ namespace OpenSim.Region.CoreModules.World.Archiver.Tests | |||
723 | Assert.That(object2PartMerged.GroupPosition, Is.EqualTo(part2.GroupPosition), "object2 group position not equal after merge"); | 700 | Assert.That(object2PartMerged.GroupPosition, Is.EqualTo(part2.GroupPosition), "object2 group position not equal after merge"); |
724 | } | 701 | } |
725 | } | 702 | } |
726 | |||
727 | /// <summary> | ||
728 | /// Test saving a multi-region OAR. | ||
729 | /// </summary> | ||
730 | [Test] | ||
731 | public void TestSaveMultiRegionOar() | ||
732 | { | ||
733 | TestHelpers.InMethod(); | ||
734 | |||
735 | // Create test regions | ||
736 | |||
737 | int WIDTH = 2; | ||
738 | int HEIGHT = 2; | ||
739 | |||
740 | List<Scene> scenes = new List<Scene>(); | ||
741 | |||
742 | // Maps (Directory in OAR file -> scene) | ||
743 | Dictionary<string, Scene> regionPaths = new Dictionary<string, Scene>(); | ||
744 | |||
745 | // Maps (Scene -> expected object paths) | ||
746 | Dictionary<UUID, List<string>> expectedPaths = new Dictionary<UUID, List<string>>(); | ||
747 | |||
748 | // List of expected assets | ||
749 | List<UUID> expectedAssets = new List<UUID>(); | ||
750 | |||
751 | for (uint y = 0; y < HEIGHT; y++) | ||
752 | { | ||
753 | for (uint x = 0; x < WIDTH; x++) | ||
754 | { | ||
755 | Scene scene; | ||
756 | if (x == 0 && y == 0) | ||
757 | { | ||
758 | scene = m_scene; // this scene was already created in SetUp() | ||
759 | } | ||
760 | else | ||
761 | { | ||
762 | scene = m_sceneHelpers.SetupScene(string.Format("Unit test region {0}", (y * WIDTH) + x + 1), UUID.Random(), 1000 + x, 1000 + y); | ||
763 | SceneHelpers.SetupSceneModules(scene, new ArchiverModule(), m_serialiserModule, new TerrainModule()); | ||
764 | } | ||
765 | scenes.Add(scene); | ||
766 | |||
767 | string dir = String.Format("{0}_{1}_{2}", x + 1, y + 1, scene.RegionInfo.RegionName.Replace(" ", "_")); | ||
768 | regionPaths[dir] = scene; | ||
769 | |||
770 | SceneObjectGroup sog1; | ||
771 | SceneObjectGroup sog2; | ||
772 | UUID ncAssetUuid; | ||
773 | |||
774 | CreateTestObjects(scene, out sog1, out sog2, out ncAssetUuid); | ||
775 | |||
776 | expectedPaths[scene.RegionInfo.RegionID] = new List<string>(); | ||
777 | expectedPaths[scene.RegionInfo.RegionID].Add(ArchiveHelpers.CreateObjectPath(sog1)); | ||
778 | expectedPaths[scene.RegionInfo.RegionID].Add(ArchiveHelpers.CreateObjectPath(sog2)); | ||
779 | |||
780 | expectedAssets.Add(ncAssetUuid); | ||
781 | } | ||
782 | } | ||
783 | |||
784 | |||
785 | // Save OAR | ||
786 | |||
787 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
788 | m_scene.EventManager.OnOarFileSaved += SaveCompleted; | ||
789 | |||
790 | Guid requestId = new Guid("00000000-0000-0000-0000-808080808080"); | ||
791 | |||
792 | Dictionary<string, Object> options = new Dictionary<string, Object>(); | ||
793 | options.Add("all", true); | ||
794 | |||
795 | lock (this) | ||
796 | { | ||
797 | m_archiverModule.ArchiveRegion(archiveWriteStream, requestId, options); | ||
798 | Monitor.Wait(this, 60000); | ||
799 | } | ||
800 | |||
801 | |||
802 | // Check that the OAR contains the expected data | ||
803 | |||
804 | Assert.That(m_lastRequestId, Is.EqualTo(requestId)); | ||
805 | |||
806 | byte[] archive = archiveWriteStream.ToArray(); | ||
807 | MemoryStream archiveReadStream = new MemoryStream(archive); | ||
808 | TarArchiveReader tar = new TarArchiveReader(archiveReadStream); | ||
809 | |||
810 | Dictionary<UUID, List<string>> foundPaths = new Dictionary<UUID, List<string>>(); | ||
811 | List<UUID> foundAssets = new List<UUID>(); | ||
812 | |||
813 | foreach (Scene scene in scenes) | ||
814 | { | ||
815 | foundPaths[scene.RegionInfo.RegionID] = new List<string>(); | ||
816 | } | ||
817 | |||
818 | string filePath; | ||
819 | TarArchiveReader.TarEntryType tarEntryType; | ||
820 | |||
821 | byte[] data = tar.ReadEntry(out filePath, out tarEntryType); | ||
822 | Assert.That(filePath, Is.EqualTo(ArchiveConstants.CONTROL_FILE_PATH)); | ||
823 | |||
824 | ArchiveReadRequest arr = new ArchiveReadRequest(m_scene, (Stream)null, false, false, Guid.Empty); | ||
825 | arr.LoadControlFile(filePath, data, new DearchiveScenesInfo()); | ||
826 | |||
827 | Assert.That(arr.ControlFileLoaded, Is.True); | ||
828 | |||
829 | while (tar.ReadEntry(out filePath, out tarEntryType) != null) | ||
830 | { | ||
831 | if (filePath.StartsWith(ArchiveConstants.ASSETS_PATH)) | ||
832 | { | ||
833 | // Assets are shared, so this file doesn't belong to any specific region. | ||
834 | string fileName = filePath.Remove(0, ArchiveConstants.ASSETS_PATH.Length); | ||
835 | if (fileName.EndsWith("_notecard.txt")) | ||
836 | foundAssets.Add(UUID.Parse(fileName.Substring(0, fileName.Length - "_notecard.txt".Length))); | ||
837 | } | ||
838 | else | ||
839 | { | ||
840 | // This file belongs to one of the regions. Find out which one. | ||
841 | Assert.IsTrue(filePath.StartsWith(ArchiveConstants.REGIONS_PATH)); | ||
842 | string[] parts = filePath.Split(new Char[] { '/' }, 3); | ||
843 | Assert.AreEqual(3, parts.Length); | ||
844 | string regionDirectory = parts[1]; | ||
845 | string relativePath = parts[2]; | ||
846 | Scene scene = regionPaths[regionDirectory]; | ||
847 | |||
848 | if (relativePath.StartsWith(ArchiveConstants.OBJECTS_PATH)) | ||
849 | { | ||
850 | foundPaths[scene.RegionInfo.RegionID].Add(relativePath); | ||
851 | } | ||
852 | } | ||
853 | } | ||
854 | |||
855 | Assert.AreEqual(scenes.Count, foundPaths.Count); | ||
856 | foreach (Scene scene in scenes) | ||
857 | { | ||
858 | Assert.That(foundPaths[scene.RegionInfo.RegionID], Is.EquivalentTo(expectedPaths[scene.RegionInfo.RegionID])); | ||
859 | } | ||
860 | |||
861 | Assert.That(foundAssets, Is.EquivalentTo(expectedAssets)); | ||
862 | } | ||
863 | |||
864 | /// <summary> | ||
865 | /// Test loading a multi-region OAR. | ||
866 | /// </summary> | ||
867 | [Test] | ||
868 | public void TestLoadMultiRegionOar() | ||
869 | { | ||
870 | TestHelpers.InMethod(); | ||
871 | |||
872 | // Create an ArchiveScenesGroup with the regions in the OAR. This is needed to generate the control file. | ||
873 | |||
874 | int WIDTH = 2; | ||
875 | int HEIGHT = 2; | ||
876 | |||
877 | for (uint y = 0; y < HEIGHT; y++) | ||
878 | { | ||
879 | for (uint x = 0; x < WIDTH; x++) | ||
880 | { | ||
881 | Scene scene; | ||
882 | if (x == 0 && y == 0) | ||
883 | { | ||
884 | scene = m_scene; // this scene was already created in SetUp() | ||
885 | } | ||
886 | else | ||
887 | { | ||
888 | scene = m_sceneHelpers.SetupScene(string.Format("Unit test region {0}", (y * WIDTH) + x + 1), UUID.Random(), 1000 + x, 1000 + y); | ||
889 | SceneHelpers.SetupSceneModules(scene, new ArchiverModule(), m_serialiserModule, new TerrainModule()); | ||
890 | } | ||
891 | } | ||
892 | } | ||
893 | |||
894 | ArchiveScenesGroup scenesGroup = new ArchiveScenesGroup(); | ||
895 | SceneManager.Instance.ForEachScene(delegate(Scene scene) | ||
896 | { | ||
897 | scenesGroup.AddScene(scene); | ||
898 | }); | ||
899 | scenesGroup.CalcSceneLocations(); | ||
900 | |||
901 | // Generate the OAR file | ||
902 | |||
903 | MemoryStream archiveWriteStream = new MemoryStream(); | ||
904 | TarArchiveWriter tar = new TarArchiveWriter(archiveWriteStream); | ||
905 | |||
906 | ArchiveWriteRequest writeRequest = new ArchiveWriteRequest(m_scene, (Stream)null, Guid.Empty); | ||
907 | writeRequest.MultiRegionFormat = true; | ||
908 | tar.WriteFile( | ||
909 | ArchiveConstants.CONTROL_FILE_PATH, writeRequest.CreateControlFile(scenesGroup)); | ||
910 | |||
911 | SceneObjectPart part1 = CreateSceneObjectPart1(); | ||
912 | part1.SitTargetOrientation = new Quaternion(0.2f, 0.3f, 0.4f, 0.5f); | ||
913 | part1.SitTargetPosition = new Vector3(1, 2, 3); | ||
914 | |||
915 | SceneObjectGroup object1 = new SceneObjectGroup(part1); | ||
916 | |||
917 | // Let's put some inventory items into our object | ||
918 | string soundItemName = "sound-item1"; | ||
919 | UUID soundItemUuid = UUID.Parse("00000000-0000-0000-0000-000000000002"); | ||
920 | Type type = GetType(); | ||
921 | Assembly assembly = type.Assembly; | ||
922 | string soundDataResourceName = null; | ||
923 | string[] names = assembly.GetManifestResourceNames(); | ||
924 | foreach (string name in names) | ||
925 | { | ||
926 | if (name.EndsWith(".Resources.test-sound.wav")) | ||
927 | soundDataResourceName = name; | ||
928 | } | ||
929 | Assert.That(soundDataResourceName, Is.Not.Null); | ||
930 | |||
931 | byte[] soundData; | ||
932 | UUID soundUuid; | ||
933 | CreateSoundAsset(tar, assembly, soundDataResourceName, out soundData, out soundUuid); | ||
934 | |||
935 | TaskInventoryItem item1 | ||
936 | = new TaskInventoryItem { AssetID = soundUuid, ItemID = soundItemUuid, Name = soundItemName }; | ||
937 | part1.Inventory.AddInventoryItem(item1, true); | ||
938 | m_scene.AddNewSceneObject(object1, false); | ||
939 | |||
940 | string object1FileName = string.Format( | ||
941 | "{0}_{1:000}-{2:000}-{3:000}__{4}.xml", | ||
942 | part1.Name, | ||
943 | Math.Round(part1.GroupPosition.X), Math.Round(part1.GroupPosition.Y), Math.Round(part1.GroupPosition.Z), | ||
944 | part1.UUID); | ||
945 | string path = "regions/1_1_Unit_test_region/" + ArchiveConstants.OBJECTS_PATH + object1FileName; | ||
946 | tar.WriteFile(path, SceneObjectSerializer.ToXml2Format(object1)); | ||
947 | |||
948 | tar.Close(); | ||
949 | |||
950 | |||
951 | // Delete the current objects, to test that they're loaded from the OAR and didn't | ||
952 | // just remain in the scene. | ||
953 | SceneManager.Instance.ForEachScene(delegate(Scene scene) | ||
954 | { | ||
955 | scene.DeleteAllSceneObjects(); | ||
956 | }); | ||
957 | |||
958 | // Create a "hole", to test that that the corresponding region isn't loaded from the OAR | ||
959 | SceneManager.Instance.CloseScene(SceneManager.Instance.Scenes[1]); | ||
960 | |||
961 | |||
962 | // Check thay the OAR file contains the expected data | ||
963 | |||
964 | MemoryStream archiveReadStream = new MemoryStream(archiveWriteStream.ToArray()); | ||
965 | |||
966 | lock (this) | ||
967 | { | ||
968 | m_scene.EventManager.OnOarFileLoaded += LoadCompleted; | ||
969 | m_archiverModule.DearchiveRegion(archiveReadStream); | ||
970 | } | ||
971 | |||
972 | Assert.That(m_lastErrorMessage, Is.Null); | ||
973 | |||
974 | Assert.AreEqual(3, SceneManager.Instance.Scenes.Count); | ||
975 | |||
976 | TestLoadedRegion(part1, soundItemName, soundData); | ||
977 | } | ||
978 | |||
979 | } | 703 | } |
980 | } | 704 | } |