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