Пример #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);
        }
Пример #2
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);
        }
Пример #3
0
        public void Encode_InvalidChars(string source, int index, int count)
        {
            byte[] expected = GetBytes(source, index, count);
            EncodingHelpers.Encode(new ASCIIEncoding(), source, index, count, expected);

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

            NegativeEncodingTests.Encode_Invalid(exceptionEncoding, source, index, count);
        }
Пример #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);
        }
Пример #5
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);
        }
Пример #6
0
        public void Encode_InvalidChars(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);

            NegativeEncodingTests.Encode_Invalid(new UnicodeEncoding(false, true, true), source, index, count);
            NegativeEncodingTests.Encode_Invalid(new UnicodeEncoding(false, false, true), source, index, count);
            NegativeEncodingTests.Encode_Invalid(new UnicodeEncoding(true, true, true), source, index, count);
            NegativeEncodingTests.Encode_Invalid(new UnicodeEncoding(true, false, true), source, index, count);
        }
Пример #7
0
        public void Encode_InvalidChars(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);

            NegativeEncodingTests.Encode_Invalid(new UTF32Encoding(true, true, true), chars, index, count);
            NegativeEncodingTests.Encode_Invalid(new UTF32Encoding(true, false, true), chars, index, count);
            NegativeEncodingTests.Encode_Invalid(new UTF32Encoding(false, true, true), chars, index, count);
            NegativeEncodingTests.Encode_Invalid(new UTF32Encoding(false, false, true), chars, index, count);
        }
Пример #8
0
        public void Decode_InvalidBytes(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 invalid bytes should throw with a DecoderExceptionFallback
            NegativeEncodingTests.Decode_Invalid(new UnicodeEncoding(false, true, true), littleEndianBytes, index, count);
            NegativeEncodingTests.Decode_Invalid(new UnicodeEncoding(false, false, true), littleEndianBytes, index, count);
            NegativeEncodingTests.Decode_Invalid(new UnicodeEncoding(true, false, true), bigEndianBytes, index, count);
            NegativeEncodingTests.Decode_Invalid(new UnicodeEncoding(true, true, true), bigEndianBytes, index, count);
        }
        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);
            }
        }
Пример #10
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);
        }