Exemplo n.º 1
0
        public void Pop()
        {
            InterpreterStream stream = new InterpreterStream();

            try {
                stream.Pop();
                Assert.Fail();
            } catch (InvalidOperationException) {
            }
            stream.Push(new byte[] { 0x10, 0x20 });
            Assert.AreEqual(2, stream.Length);
            Assert.AreEqual(0, stream.Position);
            Assert.AreEqual(1, stream.Depth);
            stream.Push(new byte[] { 0x30, 0x40, 0x50 });
            Assert.AreEqual(3, stream.Length);
            Assert.AreEqual(0, stream.Position);
            Assert.AreEqual(2, stream.Depth);
            stream.Pop();
            Assert.AreEqual(2, stream.Length);
            Assert.AreEqual(0, stream.Position);
            Assert.AreEqual(1, stream.Depth);
            stream.Pop();
            Assert.AreEqual(0, stream.Length);
            Assert.AreEqual(0, stream.Position);
            Assert.AreEqual(0, stream.Depth);
            try {
                stream.Pop();
                Assert.Fail();
            } catch (InvalidOperationException) {
            }
        }
Exemplo n.º 2
0
        public void PushCount()
        {
            InterpreterStream stream = new InterpreterStream();

            stream.Push(new byte[] { 0x10, 0x20 }, 0);
            Assert.AreEqual(0, stream.Length);
            Assert.AreEqual(0, stream.Position);
            Assert.AreEqual(0, stream.Depth);
            stream.Push(new byte[] { 0x10, 0x20 }, 5);
            Assert.AreEqual(2, stream.Length);
            Assert.AreEqual(0, stream.Position);
            Assert.AreEqual(5, stream.Depth);
        }
Exemplo n.º 3
0
        public void Push()
        {
            InterpreterStream stream = new InterpreterStream();

            stream.Push(new byte[] { 0x10, 0x20 });
            Assert.AreEqual(2, stream.Length);
            Assert.AreEqual(0, stream.Position);
            Assert.AreEqual(1, stream.Depth);
            stream.Push(new byte[] { 0x30, 0x40, 0x50 });
            Assert.AreEqual(3, stream.Length);
            Assert.AreEqual(0, stream.Position);
            Assert.AreEqual(2, stream.Depth);
        }
Exemplo n.º 4
0
        public void Length()
        {
            InterpreterStream stream = new InterpreterStream();

            Assert.AreEqual(0, stream.Length);
            stream.Push(new byte[] { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 });
            Assert.AreEqual(6, stream.Length);
            stream.Push(new byte[] { 0x10, 0x20, 0x30, 0x40 });
            Assert.AreEqual(4, stream.Length);
            stream.Pop();
            Assert.AreEqual(6, stream.Length);
            stream.Push(new byte[] { 0x10, 0x20 });
            Assert.AreEqual(2, stream.Length);
            stream.Pop();
            Assert.AreEqual(6, stream.Length);
            stream.Pop();
            Assert.AreEqual(0, stream.Length);
        }
Exemplo n.º 5
0
        public void Position()
        {
            InterpreterStream stream = new InterpreterStream();

            Assert.AreEqual(0, stream.Position);
            stream.Push(new byte[] { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 });
            Assert.AreEqual(0, stream.Position);
            stream.Next();
            Assert.AreEqual(1, stream.Position);
            stream.NextWord();
            Assert.AreEqual(3, stream.Position);
        }
Exemplo n.º 6
0
        public void HasNext()
        {
            InterpreterStream stream = new InterpreterStream();

            Assert.IsFalse(stream.HasNext());
            stream.Push(new byte[] { 0x10, 0x20 });
            Assert.IsTrue(stream.HasNext());
            stream.Next();
            Assert.IsTrue(stream.HasNext());
            stream.Next();
            Assert.IsFalse(stream.HasNext());
        }
Exemplo n.º 7
0
        public void JROT()
        {
            InterpreterStream stream = new InterpreterStream();

            Assert.AreEqual(0, stream.Next());
            stream.Push(new byte[] { 0x10, 0x20, 0x30, 0x40, 0x50, 0x60 });
            stream.JMPR(2);
            Assert.IsTrue(stream.HasNext());
            Assert.AreEqual(0x30, stream.Next());
            Assert.IsTrue(stream.HasNext());
            stream.JMPR(-3);
            Assert.AreEqual(0x10, stream.Next());
        }
Exemplo n.º 8
0
        public void Next()
        {
            InterpreterStream stream = new InterpreterStream();

            Assert.AreEqual(0, stream.Next());
            stream.Push(new byte[] { 0x10, 0x20 });
            Assert.AreEqual(0x10, stream.Next());
            Assert.AreEqual(0x20, stream.Next());
            Assert.IsFalse(stream.HasNext());
            Assert.AreEqual(0, stream.Next());
            stream.Pop();
            Assert.IsFalse(stream.HasNext());
            Assert.AreEqual(0, stream.Next());
        }
Exemplo n.º 9
0
        public void NextWord()
        {
            InterpreterStream stream = new InterpreterStream();

            Assert.AreEqual(0, stream.Next());
            stream.Push(new byte[] { 0x10, 0x20, 0xFF, 0xFF, 0x80, 0x00 });
            Assert.IsTrue(stream.HasNext());
            Assert.AreEqual(0x1020, stream.NextWord());
            Assert.IsTrue(stream.HasNext());
            Assert.AreEqual(-1, stream.NextWord());
            Assert.IsTrue(stream.HasNext());
            Assert.AreEqual(-0x8000, stream.NextWord());
            Assert.IsFalse(stream.HasNext());
            Assert.AreEqual(0, stream.NextWord());
        }
Exemplo n.º 10
0
        public void PushBytes()
        {
            InterpreterStack  stack  = new InterpreterStack();
            InterpreterStream stream = new InterpreterStream();

            stream.Push(new byte[] { 1, 2, 3, 4, 5 });
            int value;

            stack.Init(10);
            stack.PushBytes(stream, 3);
            Assert.AreEqual(3, stack.Depth);
            value = stack.Pop();
            Assert.AreEqual(3, value);
            value = stack.Pop();
            Assert.AreEqual(2, value);
            value = stack.Pop();
            Assert.AreEqual(1, value);
            Assert.AreEqual(0, stack.Depth);
        }
Exemplo n.º 11
0
        public void PushWords()
        {
            InterpreterStack  stack  = new InterpreterStack();
            InterpreterStream stream = new InterpreterStream();

            stream.Push(new byte[] { 0, 1, 0, 2, 3, 0, 0xFF, 0xFF });
            int value;

            stack.Init(10);
            stack.PushWords(stream, 4);
            Assert.AreEqual(4, stack.Depth);
            value = stack.Pop();
            Assert.AreEqual(-1, value);
            value = stack.Pop();
            Assert.AreEqual(0x300, value);
            value = stack.Pop();
            Assert.AreEqual(2, value);
            value = stack.Pop();
            Assert.AreEqual(1, value);
            Assert.AreEqual(0, stack.Depth);
        }