Beispiel #1
0
 public void TestBinaryHeader()
 {
     IsoMessage m = mf.NewMessage(0x280);
     Assert.NotNull(m.BinIsoHeader);
     sbyte[] buf = m.WriteData();
     Assert.Equal(4 + 4 + 16 + 2, buf.Length);
     for (int i = 0; i < 4; i++)
     {
         Assert.Equal(buf[i], unchecked((sbyte) 0xff));
     }
     Assert.Equal(buf[4], 0x30);
     Assert.Equal(buf[5], 0x32);
     Assert.Equal(buf[6], 0x38);
     Assert.Equal(buf[7], 0x30);
     //Then parse and check the header is binary 0xffffffff
     m = mf.ParseMessage(buf, 4, true);
     Assert.Null(m.IsoHeader);
     buf = m.BinIsoHeader;
     Assert.NotNull(buf);
     for (int i = 0; i < 4; i++)
     {
         Assert.Equal(buf[i], unchecked((sbyte) 0xff));
     }
     Assert.Equal(0x280, m.Type);
     Assert.True(m.HasField(3));
 }
Beispiel #2
0
        public void TestMessageType()
        {
            var msg = new IsoMessage
            {
                Type      = 0x1100,
                Encoding  = CodePagesEncodingProvider.Instance.GetEncoding(1047),
                BinBitmap = true
            };
            var enc = msg.WriteData();

            Assert.Equal(12,
                         enc.Length);
            Assert.Equal(unchecked ((sbyte)241),
                         enc[0]);
            Assert.Equal(unchecked ((sbyte)241),
                         enc[1]);
            Assert.Equal(unchecked ((sbyte)240),
                         enc[2]);
            Assert.Equal(unchecked ((sbyte)240),
                         enc[3]);
            var mf   = new MessageFactory <IsoMessage>();
            var pmap = new Dictionary <int, FieldParseInfo>();

            mf.ForceStringEncoding = true;
            mf.UseBinaryBitmap     = true;
            mf.Encoding            = CodePagesEncodingProvider.Instance.GetEncoding(1047);
            mf.SetParseMap(0x1100,
                           pmap);
            var m2 = mf.ParseMessage(enc,
                                     0);

            Assert.Equal(msg.Type,
                         m2.Type);

            //Now with text bitmap
            msg.BinBitmap           = false;
            msg.ForceStringEncoding = true;
            var enc2 = msg.WriteData();

            Assert.Equal(20,
                         enc2.Length);
            mf.UseBinaryBitmap = false;
            m2 = mf.ParseMessage(enc2,
                                 0);
            Assert.Equal(msg.Type,
                         m2.Type);
        }
Beispiel #3
0
        public void TestEmptyLllbin()
        {
            IsoMessage t = txtfact.NewMessage(0x100);
            IsoMessage b = binfact.NewMessage(0x100);

            t.SetValue(6, new sbyte[0], IsoType.LLLBIN, 0);
            b.SetValue(6, new sbyte[0], IsoType.LLLBIN, 0);
            CheckBin(t.WriteData(), b.WriteData(), 6);
        }
Beispiel #4
0
        public void TestEmptyLlllvar()
        {
            IsoMessage t = txtfact.NewMessage(0x100);
            IsoMessage b = binfact.NewMessage(0x100);

            t.SetValue(4, "", IsoType.LLLLVAR, 0);
            b.SetValue(4, "", IsoType.LLLLVAR, 0);
            CheckString(t.WriteData(), b.WriteData(), 4);
        }
Beispiel #5
0
        public void TestTemplate()
        {
            IsoMessage m = mfact.NewMessage(0x100);

            Assert.Equal("010060000000000000000001X0002FF", m.DebugString());
            m.Binary = true;
            Assert.Equal(new sbyte[]
            {
                1, 0, (sbyte)0x60, 0, 0, 0, 0, 0, 0, 0,
                0, 1, (sbyte)'X', 0, 1, unchecked ((sbyte)0xff)
            }, m.WriteData());
        }
Beispiel #6
0
        public void TestNewMessage()
        {
            IsoMessage m = mfact.NewMessage(0x200);

            m.SetValue(2, "Variable length text", IsoType.LLLLVAR, 0);
            m.SetValue(3, "FFFF", IsoType.LLLLBIN, 0);
            Assert.Equal("020060000000000000000020Variable length text0004FFFF", m.DebugString());
            m.Binary = (true);
            m.SetValue(2, "XX", IsoType.LLLLVAR, 0);
            m.SetValue(3, new sbyte[] { unchecked ((sbyte)0xff) }, IsoType.LLLLBIN, 0);
            Assert.Equal(new sbyte[]
            {
                2, 0, (sbyte)0x60, 0, 0, 0, 0, 0, 0, 0,
                0, 2, (sbyte)'X', (sbyte)'X', 0, 1, unchecked ((sbyte)0xff)
            }, m.WriteData());
        }
Beispiel #7
0
        public void TestL4bin()
        {
            sbyte[] fieldData = new sbyte[1000];
            mfact.UseBinaryMessages = true;
            IsoMessage m = mfact.NewMessage(0x100);

            m.SetValue(3, fieldData, IsoType.LLLLBIN, 0);
            fieldData = m.WriteData();
            //2 for message header
            //8 bitmap
            //3 for field 2 (from template)
            //1002 for field 3
            Assert.Equal(1015, fieldData.Length);
            m = mfact.ParseMessage(fieldData, 0);
            Assert.True(m.HasField(3));
            fieldData = m.GetObjectValue(3) as sbyte[];
            Assert.Equal(1000, fieldData.Length);
        }
        private void TestFieldType(IsoType type,
                                   FieldParseInfo fieldParser,
                                   int offset1,
                                   int offset2)
        {
            var bigintCodec = new BigIntBcdCodec();
            var longCodec   = new LongBcdCodec();
            var mfact       = new MessageFactory <IsoMessage>();
            var tmpl        = new IsoMessage
            {
                Binary = true,
                Type   = 0x200
            };

            tmpl.SetValue(2,
                          1234567890L,
                          longCodec,
                          type,
                          0);
            tmpl.SetValue(3,
                          b29,
                          bigintCodec,
                          type,
                          0);
            mfact.AddMessageTemplate(tmpl);
            mfact.SetCustomField(2,
                                 longCodec);
            mfact.SetCustomField(3,
                                 bigintCodec);
            var parser = new Dictionary <int, FieldParseInfo>
            {
                { 2, fieldParser },
                { 3, fieldParser }
            };

            mfact.SetParseMap(0x200,
                              parser);
            mfact.UseBinaryMessages = true;

            //Test encoding
            tmpl = mfact.NewMessage(0x200);
            var buf     = tmpl.WriteData();
            var message = HexCodec.HexEncode(buf,
                                             0,
                                             buf.Length);

            Console.WriteLine("MESSAGE: " + message);
            for (var i = 0; i < 5; i++)
            {
                var b = longData2[i];
                Assert.Equal(b,
                             buf[i + offset1]);
            }

            for (var i = 0; i < 15; i++)
            {
                Assert.Equal(bigintData1[i],
                             buf[i + offset2]);
            }

            //Test parsing
            tmpl = mfact.ParseMessage(buf,
                                      0);
            Assert.Equal(1234567890L,
                         tmpl.GetObjectValue(2));
            Assert.Equal(b29,
                         tmpl.GetObjectValue(3));
        }