Ejemplo n.º 1
0
        public void Encode_InvalidChars(string chars, int index, int count, byte[] expected)
        {
            EncodingHelpers.Encode(new UTF8Encoding(true, false), chars, index, count, expected);
            EncodingHelpers.Encode(new UTF8Encoding(false, false), chars, index, count, expected);

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

            EncodingHelpers.Encode(new UTF8Encoding(false, true), chars, index, count, expected);
            EncodingHelpers.Encode(new UTF8Encoding(true, true), chars, index, count, expected);
        }
Ejemplo n.º 3
0
        public void Encode(string source, int index, int count)
        {
            byte[] expected = GetBytes(source, index, count);
            EncodingHelpers.Encode(new ASCIIEncoding(), source, index, count, expected);

            // Encoding valid chars should not throw with an EncoderExceptionFallback
            Encoding exceptionEncoding = Encoding.GetEncoding("ascii", new EncoderExceptionFallback(), new DecoderReplacementFallback("?"));

            EncodingHelpers.Encode(exceptionEncoding, source, index, count, expected);
        }
Ejemplo n.º 4
0
        public void Encode(string source, int index, int count, byte[] expectedLittleEndian)
        {
            byte[] expectedBigEndian = GetBigEndianBytes(expectedLittleEndian);

            EncodingHelpers.Encode(new UnicodeEncoding(false, true, false), source, index, count, expectedLittleEndian);
            EncodingHelpers.Encode(new UnicodeEncoding(false, false, false), source, index, count, expectedLittleEndian);
            EncodingHelpers.Encode(new UnicodeEncoding(true, true, false), source, index, count, expectedBigEndian);
            EncodingHelpers.Encode(new UnicodeEncoding(true, false, false), source, index, count, expectedBigEndian);

            EncodingHelpers.Encode(new UnicodeEncoding(false, true, true), source, index, count, expectedLittleEndian);
            EncodingHelpers.Encode(new UnicodeEncoding(false, false, true), source, index, count, expectedLittleEndian);
            EncodingHelpers.Encode(new UnicodeEncoding(true, true, true), source, index, count, expectedBigEndian);
            EncodingHelpers.Encode(new UnicodeEncoding(true, false, true), source, index, count, expectedBigEndian);
        }
Ejemplo n.º 5
0
        public void Encode(string chars, int index, int count, byte[] littleEndianExpected)
        {
            byte[] bigEndianExpected = GetBigEndianBytes(littleEndianExpected);

            EncodingHelpers.Encode(new UTF32Encoding(true, true, false), chars, index, count, bigEndianExpected);
            EncodingHelpers.Encode(new UTF32Encoding(true, false, false), chars, index, count, bigEndianExpected);
            EncodingHelpers.Encode(new UTF32Encoding(false, true, false), chars, index, count, littleEndianExpected);
            EncodingHelpers.Encode(new UTF32Encoding(false, false, false), chars, index, count, littleEndianExpected);

            EncodingHelpers.Encode(new UTF32Encoding(true, true, true), chars, index, count, bigEndianExpected);
            EncodingHelpers.Encode(new UTF32Encoding(true, false, true), chars, index, count, bigEndianExpected);
            EncodingHelpers.Encode(new UTF32Encoding(false, true, true), chars, index, count, littleEndianExpected);
            EncodingHelpers.Encode(new UTF32Encoding(false, false, true), chars, index, count, littleEndianExpected);
        }
Ejemplo n.º 6
0
        public void Encode_Basic(string source, int index, int count, byte[] expected)
        {
            Encode_Advanced(true, source, index, count, expected);
            Encode_Advanced(false, source, index, count, expected);

            // UTF7Encoding performs no error checking, so even encoding invalid chars with
            // a custom fallback should never throw
            Encoding exceptionEncoding = Encoding.GetEncoding("utf-7", new EncoderExceptionFallback(), new DecoderReplacementFallback("\uFFFD"));

            EncodingHelpers.Encode(exceptionEncoding, source, index, count, expected);

            Encoding replacementEncoding = Encoding.GetEncoding("utf-7", new EncoderReplacementFallback(string.Empty), new DecoderReplacementFallback("\uFFFD"));

            EncodingHelpers.Encode(replacementEncoding, source, index, count, expected);
        }
        private static void Encode(string source, int index, int count, byte[] expected, bool valid)
        {
            EncodingHelpers.Encode(Encoding.GetEncoding("latin1"), source, index, count, expected);

            Encoding exceptionEncoding = Encoding.GetEncoding("latin1", new EncoderExceptionFallback(), new DecoderReplacementFallback("?"));

            if (valid)
            {
                EncodingHelpers.Encode(exceptionEncoding, source, index, count, expected);
            }
            else
            {
                NegativeEncodingTests.Encode_Invalid(exceptionEncoding, source, index, count);
            }
        }
Ejemplo n.º 8
0
        public void Encode_InvalidChars(string chars, int index, int count, byte[] expected)
        {
            EncodingHelpers.Encode(
                new UTF8Encoding(encoderShouldEmitUTF8Identifier: true, throwOnInvalidBytes: false),
                chars, index, count, expected);
            EncodingHelpers.Encode(
                new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: false),
                chars, index, count, expected);

            NegativeEncodingTests.Encode_Invalid(
                new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true),
                chars, index, count);
            NegativeEncodingTests.Encode_Invalid(
                new UTF8Encoding(encoderShouldEmitUTF8Identifier: true, throwOnInvalidBytes: true),
                chars, index, count);
        }
Ejemplo n.º 9
0
 public void GetBytes(string source, int index, int count)
 {
     byte[] expectedBytes = new byte[count];
     for (int i = 0; i < expectedBytes.Length; i++)
     {
         if (source[i] <= 0x7f)
         {
             expectedBytes[i] = (byte)source[i + index];
         }
         else
         {
             // Verify the fallback character for non-ASCII chars
             expectedBytes[i] = (byte)'?';
         }
     }
     EncodingHelpers.Encode(new ASCIIEncoding(), source, index, count, expectedBytes);
 }
Ejemplo n.º 10
0
        public void Encode(string source, int index, int count, byte[] expectedLittleEndian)
        {
            EncodingHelpers.Encode(new UnicodeEncoding(false, true), source, index, count, expectedLittleEndian);
            EncodingHelpers.Encode(new UnicodeEncoding(false, false), source, index, count, expectedLittleEndian);

            byte[] expectedBigEndian = (byte[])expectedLittleEndian.Clone();
            for (int i = 0; i < expectedBigEndian.Length; i += 2)
            {
                byte b1 = expectedBigEndian[i];
                byte b2 = expectedBigEndian[i + 1];

                expectedBigEndian[i]     = b2;
                expectedBigEndian[i + 1] = b1;
            }

            EncodingHelpers.Encode(new UnicodeEncoding(true, true), source, index, count, expectedBigEndian);
            EncodingHelpers.Encode(new UnicodeEncoding(true, false), source, index, count, expectedBigEndian);
        }
Ejemplo n.º 11
0
 public void Encode_Advanced(bool allowOptionals, string source, int index, int count, byte[] expected)
 {
     EncodingHelpers.Encode(new UTF7Encoding(allowOptionals), source, index, count, expected);
 }
Ejemplo n.º 12
0
 public void GetBytes(string source, int index, int count, byte[] expected)
 {
     EncodingHelpers.Encode(new UnicodeEncoding(), source, index, count, expected);
 }
Ejemplo n.º 13
0
 public void GetBytes(string chars, int index, int count, byte[] expected)
 {
     EncodingHelpers.Encode(new UTF8Encoding(), chars, index, count, expected);
 }