Ejemplo n.º 1
0
        public static void Decode_InvalidBytes(byte[] bytes, int index, int count, string expected)
        {
            EncodingHelpers.Decode(new UTF8Encoding(true, false), bytes, index, count, expected);
            EncodingHelpers.Decode(new UTF8Encoding(false, false), bytes, index, count, expected);

            NegativeEncodingTests.Decode_Invalid(new UTF8Encoding(false, true), bytes, index, count);
            NegativeEncodingTests.Decode_Invalid(new UTF8Encoding(true, true), bytes, index, count);
        }
Ejemplo n.º 2
0
        public void Decode(byte[] bytes, int index, int count, string expected)
        {
            EncodingHelpers.Decode(new UTF8Encoding(true, false), bytes, index, count, expected);
            EncodingHelpers.Decode(new UTF8Encoding(false, false), bytes, index, count, expected);

            EncodingHelpers.Decode(new UTF8Encoding(false, true), bytes, index, count, expected);
            EncodingHelpers.Decode(new UTF8Encoding(true, true), bytes, index, count, expected);
        }
Ejemplo n.º 3
0
 public void GetChars(byte[] bytes, int index, int count)
 {
     char[] expectedChars = new char[count];
     for (int i = 0; i < count; i++)
     {
         expectedChars[i] = (char)bytes[i + index];
     }
     EncodingHelpers.Decode(new ASCIIEncoding(), bytes, index, count, expectedChars);
 }
Ejemplo n.º 4
0
        public void Decode_InvalidBytes(byte[] bytes, int index, int count)
        {
            string expected = GetString(bytes, index, count);

            EncodingHelpers.Decode(new ASCIIEncoding(), bytes, index, count, expected);

            // Decoding invalid bytes should throw with a DecoderExceptionFallback
            Encoding exceptionEncoding = Encoding.GetEncoding("ascii", new EncoderReplacementFallback("?"), new DecoderExceptionFallback());

            NegativeEncodingTests.Decode_Invalid(exceptionEncoding, bytes, index, count);
        }
Ejemplo n.º 5
0
        public void Decode(byte[] bytes, int index, int count)
        {
            string expected = GetString(bytes, index, count);

            EncodingHelpers.Decode(Encoding.GetEncoding("latin1"), bytes, index, count, expected);

            // Decoding valid bytes should not throw with a DecoderExceptionFallback
            Encoding exceptionEncoding = Encoding.GetEncoding("latin1", new EncoderReplacementFallback("?"), new DecoderExceptionFallback());

            EncodingHelpers.Decode(exceptionEncoding, bytes, index, count, expected);
        }
Ejemplo n.º 6
0
        public void Decode_InvalidBytes(byte[] littleEndianBytes, int index, int count, string expected)
        {
            byte[] bigEndianBytes = GetBigEndianBytes(littleEndianBytes);

            EncodingHelpers.Decode(new UTF32Encoding(true, true, false), bigEndianBytes, index, count, expected);
            EncodingHelpers.Decode(new UTF32Encoding(true, false, false), bigEndianBytes, index, count, expected);
            EncodingHelpers.Decode(new UTF32Encoding(false, true, false), littleEndianBytes, index, count, expected);
            EncodingHelpers.Decode(new UTF32Encoding(false, false, false), littleEndianBytes, index, count, expected);

            NegativeEncodingTests.Decode_Invalid(new UTF32Encoding(true, true, true), bigEndianBytes, index, count);
            NegativeEncodingTests.Decode_Invalid(new UTF32Encoding(true, false, true), bigEndianBytes, index, count);
            NegativeEncodingTests.Decode_Invalid(new UTF32Encoding(false, true, true), littleEndianBytes, index, count);
            NegativeEncodingTests.Decode_Invalid(new UTF32Encoding(false, false, true), littleEndianBytes, index, count);
        }
Ejemplo n.º 7
0
        public void Decode(byte[] littleEndianBytes, int index, int count, string expected)
        {
            byte[] bigEndianBytes = GetBigEndianBytes(littleEndianBytes, index, count);

            EncodingHelpers.Decode(new UnicodeEncoding(false, true, false), littleEndianBytes, index, count, expected);
            EncodingHelpers.Decode(new UnicodeEncoding(false, false, false), littleEndianBytes, index, count, expected);
            EncodingHelpers.Decode(new UnicodeEncoding(true, false, false), bigEndianBytes, index, count, expected);
            EncodingHelpers.Decode(new UnicodeEncoding(true, true, false), bigEndianBytes, index, count, expected);

            // Decoding valid bytes should throw with a DecoderExceptionFallback
            EncodingHelpers.Decode(new UnicodeEncoding(false, true, true), littleEndianBytes, index, count, expected);
            EncodingHelpers.Decode(new UnicodeEncoding(false, false, true), littleEndianBytes, index, count, expected);
            EncodingHelpers.Decode(new UnicodeEncoding(true, false, true), bigEndianBytes, index, count, expected);
            EncodingHelpers.Decode(new UnicodeEncoding(true, true, true), bigEndianBytes, index, count, expected);
        }
Ejemplo n.º 8
0
 public void Decode(byte[] bytes, int index, int count)
 {
     char[] expectedChars = new char[count];
     for (int i = 0; i < count; i++)
     {
         byte b = bytes[i + index];
         if (b <= 0x7F)
         {
             expectedChars[i] = (char)b;
         }
         else
         {
             expectedChars[i] = '?';
         }
     }
     EncodingHelpers.Decode(new ASCIIEncoding(), bytes, index, count, new string(expectedChars));
 }
Ejemplo n.º 9
0
 public void Decode_BigEndian(byte[] bytes, int index, int count, string expected)
 {
     EncodingHelpers.Decode(new UnicodeEncoding(true, false), bytes, index, count, expected);
     EncodingHelpers.Decode(new UnicodeEncoding(true, true), bytes, index, count, expected);
 }
Ejemplo n.º 10
0
 public void Decode(byte[] bytes, int index, int count, string expected)
 {
     EncodingHelpers.Decode(new UnicodeEncoding(), bytes, index, count, expected);
 }
Ejemplo n.º 11
0
 public void GetChars(byte[] bytes, int index, int count, char[] expected)
 {
     EncodingHelpers.Decode(new UTF8Encoding(), bytes, index, count, expected);
 }