예제 #1
0
        public void InstantiationAndProperties()
        {
            BinaryConstantExpression bce = new BinaryConstantExpression();

            Assert.IsTrue(bce.Constant == null);
            Assert.IsTrue(bce.GetValue() == null);

            bce = new BinaryConstantExpression("303020");
            Assert.IsTrue(bce.Constant == "303020");
            Assert.IsTrue(MessagesProvider.CompareByteArrays(bce.GetValue(),
                                                             new byte[] { 0x30, 0x30, 0x20 }));

            bce.Constant = null;
            Assert.IsTrue(bce.Constant == null);
            Assert.IsTrue(bce.GetValue() == null);

            bce.Constant = "203020";
            Assert.IsTrue(bce.Constant == "203020");
            Assert.IsTrue(MessagesProvider.CompareByteArrays(bce.GetValue(),
                                                             new byte[] { 0x20, 0x30, 0x20 }));

            bce.Constant = "2030A";
            Assert.IsTrue(bce.Constant == "2030A");
            Assert.IsTrue(MessagesProvider.CompareByteArrays(bce.GetValue(),
                                                             new byte[] { 0x20, 0x30, 0xA0 }));
        }
        public void GetLeafFieldValueBytes()
        {
            Message          msg = MessagesProvider.GetMessage();
            ParserContext    pc  = new ParserContext(ParserContext.DefaultBufferSize);
            FormatterContext fc  = new FormatterContext(FormatterContext.DefaultBufferSize);

            SubMessageExpression sme = new SubMessageExpression(24, null);

            // Sub field of a field isn't an inner message.
            try {
                sme.GetLeafFieldValueString(ref fc, msg);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }
            sme = new SubMessageExpression(61, null);
            msg.Fields.Add(new InnerMessageField(61));
            try {
                sme.GetLeafFieldValueString(ref fc, msg);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }

            sme = new SubMessageExpression(62, new MessageExpression(7));

            // Passing null message (as parameter and in the contexts).
            try {
                sme.GetLeafFieldValueBytes(ref fc, null);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }
            try {
                sme.GetLeafFieldValueBytes(ref pc, null);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }

            msg = MessagesProvider.GetMessage();
            Message anotherMsg = MessagesProvider.GetAnotherMessage();

            Assert.IsTrue(MessagesProvider.CompareByteArrays(sme.GetLeafFieldValueBytes(ref fc, msg),
                                                             new byte[] { 0x75, 0xB0, 0xB5 }));
            fc.CurrentMessage = anotherMsg;
            Assert.IsTrue(MessagesProvider.CompareByteArrays(sme.GetLeafFieldValueBytes(ref fc, msg),
                                                             new byte[] { 0x75, 0xB0, 0xB5 }));
            Assert.IsTrue(MessagesProvider.CompareByteArrays(sme.GetLeafFieldValueBytes(ref fc, null),
                                                             new byte[] { 0x95, 0xA0, 0xA5 }));

            Assert.IsTrue(MessagesProvider.CompareByteArrays(sme.GetLeafFieldValueBytes(ref pc, msg),
                                                             new byte[] { 0x75, 0xB0, 0xB5 }));
            pc.CurrentMessage = anotherMsg;
            Assert.IsTrue(MessagesProvider.CompareByteArrays(sme.GetLeafFieldValueBytes(ref pc, msg),
                                                             new byte[] { 0x75, 0xB0, 0xB5 }));
            Assert.IsTrue(MessagesProvider.CompareByteArrays(sme.GetLeafFieldValueBytes(ref pc, null),
                                                             new byte[] { 0x95, 0xA0, 0xA5 }));
        }
예제 #3
0
        public void GetLeafFieldValueBytes()
        {
            Message          msg = MessagesProvider.GetMessage();
            ParserContext    pc  = new ParserContext(ParserContext.DefaultBufferSize);
            FormatterContext fc  = new FormatterContext(FormatterContext.DefaultBufferSize);

            ParentMessageExpression pme = new ParentMessageExpression(
                new MessageExpression(52));

            // Parent of a message without one.
            try {
                pme.GetLeafFieldValueString(ref fc, msg);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }

            // Passing null message (as parameter and in the contexts).
            try {
                pme.GetLeafFieldValueString(ref fc, null);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }
            try {
                pme.GetLeafFieldValueString(ref pc, null);
                Assert.Fail();
            }
            catch (ExpressionEvaluationException) {
            }

            msg = msg[62].Value as Message;
            Message anotherMsg = MessagesProvider.GetAnotherMessage();

            anotherMsg = anotherMsg[61].Value as Message;

            Assert.IsTrue(MessagesProvider.CompareByteArrays(pme.GetLeafFieldValueBytes(ref fc, msg),
                                                             new byte[] { 0x15, 0x20, 0x25, 0x30, 0x35, 0x40, 0x45, 0x50 }));
            fc.CurrentMessage = anotherMsg;
            Assert.IsTrue(MessagesProvider.CompareByteArrays(pme.GetLeafFieldValueBytes(ref fc, msg),
                                                             new byte[] { 0x15, 0x20, 0x25, 0x30, 0x35, 0x40, 0x45, 0x50 }));
            Assert.IsTrue(MessagesProvider.CompareByteArrays(pme.GetLeafFieldValueBytes(ref fc, null),
                                                             new byte[] { 0x55, 0x60, 0x65, 0x70, 0x75, 0x80, 0x85, 0x90 }));

            Assert.IsTrue(MessagesProvider.CompareByteArrays(pme.GetLeafFieldValueBytes(ref pc, msg),
                                                             new byte[] { 0x15, 0x20, 0x25, 0x30, 0x35, 0x40, 0x45, 0x50 }));
            pc.CurrentMessage = anotherMsg;
            Assert.IsTrue(MessagesProvider.CompareByteArrays(pme.GetLeafFieldValueBytes(ref pc, msg),
                                                             new byte[] { 0x15, 0x20, 0x25, 0x30, 0x35, 0x40, 0x45, 0x50 }));
            Assert.IsTrue(MessagesProvider.CompareByteArrays(pme.GetLeafFieldValueBytes(ref pc, null),
                                                             new byte[] { 0x55, 0x60, 0x65, 0x70, 0x75, 0x80, 0x85, 0x90 }));
        }