Пример #1
0
        public void Decode_InvalidBytes()
        {
            foreach (var objectse in Decode_InvalidBytes_TestData())
            {
                byte[] littleEndianBytes = (byte[])objectse[0];
                int    index             = (int)objectse[1];
                int    count             = (int)objectse[2];
                string expected          = (string)objectse[3];

                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);
            }
        }
Пример #2
0
        //[Test]
        //Invalid bytes logic works unstable yet
        public static void Decode_InvalidBytes()
        {
            foreach (var objectse in UTF8EncodingDecodeTests.Decode_InvalidBytes_TestData())
            {
                byte[] bytes    = objectse[0] as byte[];
                int    index    = (int)objectse[1];
                int    count    = (int)objectse[2];
                string expected = objectse[3] as string;

                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);
            }
        }
Пример #3
0
        public void Encode_InvalidChars()
        {
            foreach (var objectse in UTF32EncodingEncodeTests.Encode_InvalidChars_TestData())
            {
                string chars = objectse[0] as string;
                int    index = (int)objectse[1];
                int    count = (int)objectse[2];
                byte[] littleEndianExpected = objectse[3] as byte[];

                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);
            }
        }
Пример #4
0
        public void Encode_InvalidChars()
        {
            foreach (var objectse in UTF8EncodingEncodeTests.Encode_InvalidChars_TestData())
            {
                string chars    = (string)objectse[0];
                int    index    = (int)objectse[1];
                int    count    = (int)objectse[2];
                byte[] expected = (byte[])objectse[3];

                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);
            }
        }
        public void Encode_InvalidChars()
        {
            foreach (var objectse in UnicodeEncodingEncodeTests.Encode_InvalidChars_TestData())
            {
                string source = (string)objectse[0];
                int    index  = (int)objectse[1];
                int    count  = (int)objectse[2];
                byte[] expectedLittleEndian = (byte[])objectse[3];

                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);
            }
        }