Ejemplo n.º 1
0
        public void TestBinaryBitmap()
        {
            MessageFactory <IsoMessage> mf = new MessageFactory <IsoMessage>();

            ConfigParser.ConfigureFromClasspathConfig(mf, @"/Resources/issue4.xml");
            IsoMessage bm = mf.GetMessageTemplate(0x800);

            bm.BinBitmap = true;
            var bb = bm.WriteToBuffer(2);

            Assert.Equal(62, bb.Length); //"Wrong message length for new BIN"

            var memStream = new MemoryStream();
            var binWriter = new BinaryWriter(memStream);

            foreach (var @sbyte in bb)
            {
                binWriter.Write(@sbyte);
            }
            var binReader = new BinaryReader(memStream);

            memStream.Position = 0;
            var buf = binReader.ReadBytes(2);

            Array.Reverse(buf); // due to the Big Endianness of Java
            Assert.Equal(60,
                         BitConverter.ToInt16(buf,
                                              0));

            MessageFactory <IsoMessage> mfp = new MessageFactory <IsoMessage> {
                UseBinaryBitmap = true
            };

            ConfigParser.ConfigureFromClasspathConfig(mfp, @"/Resources/issue4.xml");

            var buf2 = binReader.ReadBytes((int)(memStream.Length - memStream.Position));

            bm = mfp.ParseMessage(buf2.ToSignedBytes(), 0);
            Assert.True(bm.BinBitmap, "Parsed message should have binary bitmap flag set");
            Assert.False(bm.Binary);
            var bbp = bm.WriteToBuffer(2);

            Assert.Equal(bb,
                         bbp); // "Parsed-reencoded BIN differs from original"
        }