Ejemplo n.º 1
0
        public void TestDetachScriptedAttachmentToInventory()
        {
            TestHelpers.InMethod();
//            TestHelpers.EnableLogging();

            Scene         scene = CreateScriptingEnabledTestScene();
            UserAccount   ua1   = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
            ScenePresence sp    = SceneHelpers.AddScenePresence(scene, ua1);

            SceneObjectGroup  so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10);
            TaskInventoryItem scriptTaskItem
                = TaskInventoryHelpers.AddScript(
                      scene.AssetService,
                      so.RootPart,
                      "scriptItem",
                      "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }");

            InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000);

            // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running.
            // In the future, we need to be able to do this programatically more predicably.
            scene.EventManager.OnChatFromWorld += OnChatFromWorld;

            m_chatEvent.Reset();
            SceneObjectGroup rezzedSo
                = (SceneObjectGroup)(scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest));

            // Wait for chat to signal rezzed script has been started.
            m_chatEvent.WaitOne(60000);

            scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, rezzedSo);

            InventoryItemBase userItemUpdated = scene.InventoryService.GetItem(userItem);
            AssetBase         asset           = scene.AssetService.Get(userItemUpdated.AssetID.ToString());

            // TODO: It would probably be better here to check script state via the saving and retrieval of state
            // information at a higher level, rather than having to inspect the serialization.
            XmlDocument soXml = new XmlDocument();

            soXml.LoadXml(Encoding.UTF8.GetString(asset.Data));

            XmlNodeList scriptStateNodes = soXml.GetElementsByTagName("ScriptState");

            Assert.That(scriptStateNodes.Count, Is.EqualTo(1));

            // Re-rez the attachment to check script running state
            SceneObjectGroup reRezzedSo = (SceneObjectGroup)(scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest));

            // Wait for chat to signal rezzed script has been started.
            m_chatEvent.WaitOne(60000);

            TaskInventoryItem reRezzedScriptItem = reRezzedSo.RootPart.Inventory.GetInventoryItem(scriptTaskItem.Name);
            IScriptModule     xengine            = scene.RequestModuleInterface <IScriptModule>();

            Assert.That(xengine.GetScriptState(reRezzedScriptItem.ItemID), Is.True);

//            Console.WriteLine(soXml.OuterXml);
        }
        public void TestScriptedAttachmentPersistence()
        {
            TestHelpers.InMethod();
//                        TestHelpers.EnableLogging();

            XEngine.XEngine xEngine = new XEngine.XEngine();
            Scene           scene   = CreateScriptingEnabledTestScene(xEngine);
            UserAccount     ua1     = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
            ScenePresence   sp      = SceneHelpers.AddScenePresence(scene, ua1);

            SceneObjectGroup so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10);

            TaskInventoryHelpers.AddScript(
                scene.AssetService,
                so.RootPart,
                "scriptItem",
                "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }");

            InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000);

            // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running.
            // In the future, we need to be able to do this programatically more predicably.
            scene.EventManager.OnChatFromWorld += OnChatFromWorld;

            SceneObjectGroup rezzedSo
                = scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest);
            TaskInventoryItem rezzedScriptItem = rezzedSo.RootPart.Inventory.GetInventoryItem("scriptItem");

            // Wait for chat to signal rezzed script has been started.
            m_chatEvent.WaitOne(60000);

            // Force save
            xEngine.DoBackup(new Object[] { 0 });

//            Console.WriteLine("ItemID {0}", rezzedScriptItem.ItemID);
//
//            foreach (
//                string s in Directory.EnumerateFileSystemEntries(
//                    string.Format("ScriptEngines/{0}", scene.RegionInfo.RegionID)))
//                Console.WriteLine(s);

            Assert.IsFalse(
                File.Exists(
                    string.Format("ScriptEngines/{0}/{1}.state", scene.RegionInfo.RegionID, rezzedScriptItem.ItemID)));

            scene.AttachmentsModule.DetachSingleAttachmentToInv(sp, rezzedSo);
        }
Ejemplo n.º 3
0
        public void TestRezScriptedAttachmentFromInventory()
        {
            TestHelpers.InMethod();

            Scene         scene = CreateScriptingEnabledTestScene();
            UserAccount   ua1   = UserAccountHelpers.CreateUserWithInventory(scene, 0x1);
            ScenePresence sp    = SceneHelpers.AddScenePresence(scene, ua1);

            SceneObjectGroup  so = SceneHelpers.CreateSceneObject(1, sp.UUID, "att-name", 0x10);
            TaskInventoryItem scriptItem
                = TaskInventoryHelpers.AddScript(
                      scene.AssetService,
                      so.RootPart,
                      "scriptItem",
                      "default { attach(key id) { if (id != NULL_KEY) { llSay(0, \"Hello World\"); } } }");

            InventoryItemBase userItem = UserInventoryHelpers.AddInventoryItem(scene, so, 0x100, 0x1000);

            // FIXME: Right now, we have to do a tricksy chat listen to make sure we know when the script is running.
            // In the future, we need to be able to do this programatically more predicably.
            scene.EventManager.OnChatFromWorld += OnChatFromWorld;

            m_chatEvent.Reset();
            scene.AttachmentsModule.RezSingleAttachmentFromInventory(sp, userItem.ID, (uint)AttachmentPoint.Chest);

            m_chatEvent.WaitOne(60000);

            // TODO: Need to have a test that checks the script is actually started but this involves a lot more
            // plumbing of the script engine and either pausing for events or more infrastructure to turn off various
            // script engine delays/asychronicity that isn't helpful in an automated regression testing context.
            SceneObjectGroup attSo = scene.GetSceneObjectGroup(so.Name);

            Assert.That(attSo.ContainsScripts(), Is.True);

            TaskInventoryItem reRezzedScriptItem = attSo.RootPart.Inventory.GetInventoryItem(scriptItem.Name);
            IScriptModule     xengine            = scene.RequestModuleInterface <IScriptModule>();

            Assert.That(xengine.GetScriptState(reRezzedScriptItem.ItemID), Is.True);
        }
Ejemplo n.º 4
0
        public void TestSaveNonRootFolderToIar()
        {
            TestHelpers.InMethod();
//            TestHelpers.EnableLogging();

            string userFirstName = "Jock";
            string userLastName  = "Stirrup";
            string userPassword  = "******";
            UUID   userId        = TestHelpers.ParseTail(0x20);

            UserAccountHelpers.CreateUserWithInventory(m_scene, userFirstName, userLastName, userId, userPassword);

            // Create base folder
            InventoryFolderBase f1
                = UserInventoryHelpers.CreateInventoryFolder(m_scene.InventoryService, userId, "f1", true);

            // Create item1
            SceneObjectGroup  so1 = SceneHelpers.CreateSceneObject(1, userId, "My Little Dog Object", 0x5);
            InventoryItemBase i1  = UserInventoryHelpers.AddInventoryItem(m_scene, so1, 0x50, 0x60, "f1");

            // Create embedded folder
            InventoryFolderBase f1_1
                = UserInventoryHelpers.CreateInventoryFolder(m_scene.InventoryService, userId, "f1/f1.1", true);

            // Create embedded item
            SceneObjectGroup  so1_1 = SceneHelpers.CreateSceneObject(1, userId, "My Little Cat Object", 0x6);
            InventoryItemBase i2    = UserInventoryHelpers.AddInventoryItem(m_scene, so1_1, 0x500, 0x600, "f1/f1.1");

            MemoryStream archiveWriteStream = new MemoryStream();

            m_archiverModule.OnInventoryArchiveSaved += SaveCompleted;

            mre.Reset();
            m_archiverModule.ArchiveInventory(
                Guid.NewGuid(), userFirstName, userLastName, "f1", userPassword, archiveWriteStream);
            mre.WaitOne(60000, false);

            // Test created iar
            byte[]           archive           = archiveWriteStream.ToArray();
            MemoryStream     archiveReadStream = new MemoryStream(archive);
            TarArchiveReader tar = new TarArchiveReader(archiveReadStream);

//            InventoryArchiveUtils.
            bool gotf1 = false, gotf1_1 = false, gotso1 = false, gotso2 = false;

            string f1FileName
                = string.Format("{0}{1}", ArchiveConstants.INVENTORY_PATH, InventoryArchiveWriteRequest.CreateArchiveFolderName(f1));
            string f1_1FileName
                = string.Format("{0}{1}", f1FileName, InventoryArchiveWriteRequest.CreateArchiveFolderName(f1_1));
            string so1FileName
                = string.Format("{0}{1}", f1FileName, InventoryArchiveWriteRequest.CreateArchiveItemName(i1));
            string so2FileName
                = string.Format("{0}{1}", f1_1FileName, InventoryArchiveWriteRequest.CreateArchiveItemName(i2));

            string filePath;

            TarArchiveReader.TarEntryType tarEntryType;

            while (tar.ReadEntry(out filePath, out tarEntryType) != null)
            {
//                Console.WriteLine("Got {0}", filePath);

                if (filePath == f1FileName)
                {
                    gotf1 = true;
                }
                else if (filePath == f1_1FileName)
                {
                    gotf1_1 = true;
                }
                else if (filePath == so1FileName)
                {
                    gotso1 = true;
                }
                else if (filePath == so2FileName)
                {
                    gotso2 = true;
                }
            }

//            Assert.That(gotControlFile, Is.True, "No control file in archive");
            Assert.That(gotf1, Is.True);
            Assert.That(gotf1_1, Is.True);
            Assert.That(gotso1, Is.True);
            Assert.That(gotso2, Is.True);

            // TODO: Test presence of more files and contents of files.
        }