コード例 #1
0
        public void testParseIntcBlock()
        {
            byte[] data = { 0x20, 0x05, 0x00, 0x01, (byte)0xc8, 0x03, 0x7b, 0x02 };

            IntConstBlock results = Logic.ReadIntConstBlock(data, 0);

            Assert.AreEqual(results.size, data.Length);
            TestUtil.ContainsExactlyElementsOf(results.results, new List <int>(new int[] { 0, 1, 456, 123, 2 }));
        }
コード例 #2
0
        public void testParseBytecBlock()
        {
            byte[]        data   = { 0x026, 0x02, 0x0d, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x02, 0x01, 0x02 };
            List <byte[]> values = new List <byte[]>()
            {
                new byte[] { 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33 },
                new byte[] { 0x1, 0x2 }
            };

            var results = Logic.ReadByteConstBlock(data, 0);

            Assert.AreEqual(results.size, data.Length);
            CollectionAssert.AreEqual(results.results, values);
            TestUtil.ContainsExactlyElementsOf(results.results, values);
        }
コード例 #3
0
        public void testCheckProgramValid()
        {
            byte[] program = { 0x01, 0x20, 0x01, 0x01, 0x22  // int 1
            };

            // Null argument
            ProgramData programData = Logic.ReadProgram(program, null);

            Assert.IsTrue(programData.good);
            TestUtil.ContainsExactlyElementsOf(programData.intBlock, new List <int>(new int[] { 1 }));
            Assert.IsEmpty(programData.byteBlock);

            // No argument
            List <byte[]> args = new List <byte[]>();

            programData = Logic.ReadProgram(program, args);
            Assert.IsTrue(programData.good);
            TestUtil.ContainsExactlyElementsOf(programData.intBlock, new List <int>(new int[] { 1 }));
            Assert.IsEmpty(programData.byteBlock);

            // Unused argument
            byte[] arg = Enumerable.Repeat((byte)0x31, 10).ToArray();
            args.Add(arg);

            programData = Logic.ReadProgram(program, args);
            Assert.IsTrue(programData.good);
            TestUtil.ContainsExactlyElementsOf(programData.intBlock, new List <int>(new int[] { 1 }));
            Assert.IsEmpty(programData.byteBlock);

            // Repeated int constants parsing
            byte[] int1 = Enumerable.Repeat((byte)0x22, 10).ToArray();
            //byte[] int1 = new byte[10];
            //Arrays.fill(int1, (byte)0x22);
            var program2 = program.ToList();

            program2.AddRange(int1);
            //byte[] program2 = program.ToList().AddRange(int1);

            //JavaHelper<byte>.SyatemArrayCopy(program, 0, program2, 0, program.Length);
            //JavaHelper<byte>.SyatemArrayCopy(int1, 0, program2, program.Length, int1.Length);
            programData = Logic.ReadProgram(program2.ToArray(), args);
            Assert.IsTrue(programData.good);
            TestUtil.ContainsExactlyElementsOf(programData.intBlock, new List <int>(new int[] { 1 }));
            Assert.IsEmpty(programData.byteBlock);
        }