Esempio n. 1
0
        public void GetEncodedLength()
        {
            BcdBinaryEncoder encoder;

            for (int i = 0; i < 16; i++)
            {
                encoder = BcdBinaryEncoder.GetInstance(false, ( byte)i);

                Assert.IsTrue(encoder.GetEncodedLength(0) == 0);
                Assert.IsTrue(encoder.GetEncodedLength(1) == 1);
                Assert.IsTrue(encoder.GetEncodedLength(2) == 1);
                Assert.IsTrue(encoder.GetEncodedLength(10) == 5);
                Assert.IsTrue(encoder.GetEncodedLength(11) == 6);
                Assert.IsFalse(encoder.GetEncodedLength(8) == 5);

                encoder = BcdBinaryEncoder.GetInstance(true, ( byte)i);

                Assert.IsTrue(encoder.GetEncodedLength(0) == 0);
                Assert.IsTrue(encoder.GetEncodedLength(1) == 1);
                Assert.IsTrue(encoder.GetEncodedLength(2) == 1);
                Assert.IsTrue(encoder.GetEncodedLength(10) == 5);
                Assert.IsTrue(encoder.GetEncodedLength(11) == 6);
                Assert.IsFalse(encoder.GetEncodedLength(8) == 5);
            }
        }
Esempio n. 2
0
        public void Decode()
        {
            ParserContext parserContext = new ParserContext(
                ParserContext.DefaultBufferSize);
            BcdBinaryEncoder encoder;

            encoder = BcdBinaryEncoder.GetInstance(true, 0xF);
            parserContext.Write(new byte[] { 0xF1, 0x2D, 0x45 }, 0, 3);
            Assert.IsTrue(Encoding.UTF7.GetString(encoder.Decode(ref parserContext, 5)).Equals("12D45"));
            Assert.IsTrue(parserContext.DataLength == 0);

            encoder = BcdBinaryEncoder.GetInstance(false, 0);
            parserContext.Write(new byte[] { 0xF1, 0x2D, 0x45, 0x20, 0x20 }, 0, 5);
            string data = Encoding.UTF7.GetString(encoder.Decode(ref parserContext, 5));

            Assert.IsTrue(data.Equals("F12D4"));
            Assert.IsTrue(parserContext.DataLength == 2);
            parserContext.Clear();

            parserContext.Write(new byte[] { 0xF1, 0x2D, 0x45 }, 0, 3);
            Assert.IsTrue(Encoding.UTF7.GetString(encoder.Decode(ref parserContext, 6)).Equals("F12D45"));
            Assert.IsTrue(parserContext.DataLength == 0);

            try {
                encoder.Decode(ref parserContext, 6);
                Assert.Fail();
            } catch (ArgumentException e) {
                Assert.IsTrue(e.ParamName.Equals("length"));
            }
        }
Esempio n. 3
0
        public void GetInstance()
        {
            BcdBinaryEncoder encoder;

            for (int i = 0; i < 16; i++)
            {
                encoder = BcdBinaryEncoder.GetInstance(false, ( byte)i);
                Assert.IsNotNull(encoder);
                Assert.IsFalse(encoder.LeftPadded);
                Assert.IsTrue(encoder.Pad == ( byte)i);
                Assert.IsTrue(encoder == BcdBinaryEncoder.GetInstance(false, ( byte)i));

                encoder = BcdBinaryEncoder.GetInstance(true, ( byte)i);
                Assert.IsNotNull(encoder);
                Assert.IsTrue(encoder.LeftPadded);
                Assert.IsTrue(encoder.Pad == ( byte)i);
                Assert.IsTrue(encoder == BcdBinaryEncoder.GetInstance(true, ( byte)i));
            }
        }
Esempio n. 4
0
        public void Encode()
        {
            FormatterContext formatterContext = new FormatterContext(
                FormatterContext.DefaultBufferSize);

            BcdBinaryEncoder encoder;

            encoder = BcdBinaryEncoder.GetInstance(true, 0xF);
            encoder.Encode(Encoding.UTF7.GetBytes("12D45"), ref formatterContext);
            Assert.IsTrue(formatterContext.GetDataAsString().Equals(
                              Encoding.UTF7.GetString(new byte[] { 0xF1, 0x2D, 0x45 })));

            formatterContext.Clear();

            encoder = BcdBinaryEncoder.GetInstance(false, 0xE);
            encoder.Encode(Encoding.UTF7.GetBytes("12D45"), ref formatterContext);
            Assert.IsTrue(formatterContext.GetDataAsString().Equals(
                              Encoding.UTF7.GetString(new byte[] { 0x12, 0xD4, 0x5E })));

            formatterContext.Clear();

            encoder = BcdBinaryEncoder.GetInstance(true, 4);
            encoder.Encode(Encoding.UTF7.GetBytes("12a45"), ref formatterContext);
            Assert.IsTrue(formatterContext.GetDataAsString().Equals(
                              Encoding.UTF7.GetString(new byte[] { 0x41, 0x2a, 0x45 })));

            formatterContext.Clear();

            encoder = BcdBinaryEncoder.GetInstance(true, 0);
            encoder.Encode(Encoding.UTF7.GetBytes("1245"), ref formatterContext);
            Assert.IsTrue(formatterContext.GetDataAsString().Equals(
                              Encoding.UTF7.GetString(new byte[] { 0x12, 0x45 })));

            formatterContext.Clear();

            encoder = BcdBinaryEncoder.GetInstance(true, 0xf);
            encoder.Encode(Encoding.UTF7.GetBytes("1245"), ref formatterContext);
            Assert.IsTrue(formatterContext.GetDataAsString().Equals(
                              Encoding.UTF7.GetString(new byte[] { 0x12, 0x45 })));
        }