Beispiel #1
0
        public void TestStopOnFailure()
        {
            // make some scripts

            var a   = new TestAction("a");
            var b   = new TestAction("b");
            var c   = new TestAction("c");
            var abc = new TestScript("abc", a, b, c);
            var d   = new TestAction("d");
            var e   = new TestAction("e");
            var f   = new TestAction("f");
            var def = new TestScript("def", d, e, f);

            var q = new ScriptQueue();

            q.Enqueue(new List <Script>()
            {
                abc, def
            });

            q.OnUpdate();
            Assert.IsTrue(a.IsEnqueued && a.IsActive && a.IsStarted);

            // if we stop just action a with the failure flag set, it should stop the entire script
            // and advance to the next one
            abc.StopCurrentAction(false, null);

            Assert.IsTrue(!a.IsEnqueued && !a.IsActive);
            Assert.IsTrue(!abc.IsEnqueued && !abc.IsActive);
            Assert.IsTrue(def.IsActive && d.IsActive);

            // similary stopping the script will just remove it
            def.StopScript(false, null);
            Assert.IsTrue(!def.IsActive && !d.IsActive);
        }
Beispiel #2
0
        public void TestScriptsInQueue()
        {
            // make some scripts

            var a     = new TestAction("a");
            var b     = new TestAction("b");
            var c     = new TestAction("c");
            var abc   = new TestScript("abc", a, b, c);
            var empty = new TestScript("empty");
            var d     = new TestAction("d");
            var e     = new TestAction("e");
            var f     = new TestAction("f");
            var def   = new TestScript("def", d, e, f);

            var q = new ScriptQueue();

            q.Enqueue(new List <Script>()
            {
                abc, empty, def
            });

            // verify the first script and action are active
            Assert.IsTrue(!q.IsEmpty && q.Head == abc && q.Head.Head == a);
            Assert.IsTrue(abc.IsEnqueued && abc.IsActive);
            Assert.IsTrue(empty.IsEnqueued && !empty.IsActive);
            Assert.IsTrue(def.IsEnqueued && !def.IsActive);

            // stop the first action, keeps the same script active
            a.Stop(true);
            Assert.IsTrue(!q.IsEmpty && q.Head == abc && q.Head.Head == b);

            // finish off actions. this will remove ABC from the queue
            b.Stop(true);
            c.Stop(true);
            Assert.IsTrue(!q.IsEmpty && q.Head != abc);
            Assert.IsTrue(abc.countActivate == 1 && abc.countDeactivate == 1);

            // the Empty script was activated but then immediately removed, because it's empty
            Assert.IsTrue(!empty.IsEnqueued && !empty.IsActive);
            Assert.IsTrue(empty.countActivate == 1 && empty.countDeactivate == 1);

            // and let's make sure that DEF is the active one now
            Assert.IsTrue(!q.IsEmpty && q.Head == def && q.Head.Head == d);
            Assert.IsTrue(!abc.IsEnqueued && !abc.IsActive);
            Assert.IsTrue(!empty.IsEnqueued && !empty.IsActive);
            Assert.IsTrue(def.IsEnqueued && def.IsActive);
            Assert.IsTrue(def.countActivate == 1 && def.countDeactivate == 0);

            // then if we force-stop DEF, it should clean out of the queue completely
            def.StopScript(true, null);
            Assert.IsTrue(q.IsEmpty && q.Head == null);
            Assert.IsTrue(!def.IsEnqueued && !def.IsActive);
            Assert.IsTrue(def.countActivate == 1 && def.countDeactivate == 1);
        }
Beispiel #3
0
        public void TestQueueUpdate()
        {
            // make some scripts

            var a   = new TestAction("a");
            var b   = new TestAction("b");
            var c   = new TestAction("c");
            var abc = new TestScript("abc", a, b, c);
            var d   = new TestAction("d");
            var e   = new TestAction("e");
            var f   = new TestAction("f");
            var def = new TestScript("def", d, e, f);

            var q = new ScriptQueue();

            q.Enqueue(new List <Script>()
            {
                abc, def
            });

            Assert.IsTrue(a.IsEnqueued && a.IsActive && !a.IsStarted);

            // fake a queue update
            q.OnUpdate();

            Assert.IsTrue(a.IsEnqueued && a.IsActive && a.IsStarted);

            // stop the script. the first action in the next script
            // will be activated, but won't be started until another update
            q.StopCurrentScript(true, null);
            Assert.IsTrue(!abc.IsEnqueued && !abc.IsActive && !a.IsActive && !a.IsStarted);
            Assert.IsTrue(def.IsEnqueued && def.IsActive && d.IsActive && !d.IsStarted);

            q.OnUpdate();
            Assert.IsTrue(def.IsEnqueued && def.IsActive && d.IsActive && d.IsStarted);

            // clear everything. no more updates
            q.StopAllScripts(true, null);
            Assert.IsTrue(!def.IsEnqueued && !def.IsActive && !d.IsActive && !d.IsStarted);
            Assert.IsTrue(q.IsEmpty);
        }