public static void Ctor3() { string message = "Test message."; string innerMsg = "Invalid Op Message."; Exception innerException = new InvalidOperationException(innerMsg); EncoderFallbackException ex = new EncoderFallbackException(message, innerException); Assert.Equal(default(char), ex.CharUnknown); Assert.Equal(default(char), ex.CharUnknownHigh); Assert.Equal(default(char), ex.CharUnknownLow); Assert.Equal(default(int), ex.Index); Assert.Null(ex.StackTrace); Assert.Equal(0, ex.Data.Count); Assert.Equal(innerException, ex.InnerException); Assert.Equal(innerMsg, ex.InnerException.Message); Assert.Equal(message, ex.Message); message = ""; ex = new EncoderFallbackException(message, null); Assert.Equal(default(char), ex.CharUnknown); Assert.Equal(default(char), ex.CharUnknownHigh); Assert.Equal(default(char), ex.CharUnknownLow); Assert.Equal(default(int), ex.Index); Assert.Equal(message, ex.Message); Assert.Null(ex.InnerException); }
public static void Ctor3() { string message = "Test message."; string innerMsg = "Invalid Op Message."; Exception innerException = new InvalidOperationException(innerMsg); EncoderFallbackException ex = new EncoderFallbackException(message, innerException); Assert.Equal(default(char), ex.CharUnknown); Assert.Equal(default(char), ex.CharUnknownHigh); Assert.Equal(default(char), ex.CharUnknownLow); Assert.Equal(default(int), ex.Index); Assert.Null(ex.StackTrace); Assert.Equal(0, ex.Data.Count); Assert.Equal(innerException, ex.InnerException); Assert.Equal(innerMsg, ex.InnerException.Message); Assert.Equal(message, ex.Message); message = ""; ex = new EncoderFallbackException(message, null); Assert.Equal(default(char), ex.CharUnknown); Assert.Equal(default(char), ex.CharUnknownHigh); Assert.Equal(default(char), ex.CharUnknownLow); Assert.Equal(default(int), ex.Index); Assert.Equal(message, ex.Message); Assert.Null(ex.InnerException); }
public static void Ctor2() { string message = "Test message."; EncoderFallbackException ex = new EncoderFallbackException(message); Assert.Equal(default(char), ex.CharUnknown); Assert.Equal(default(char), ex.CharUnknownHigh); Assert.Equal(default(char), ex.CharUnknownLow); Assert.Equal(default(int), ex.Index); Assert.Null(ex.StackTrace); Assert.Null(ex.InnerException); Assert.Equal(0, ex.Data.Count); Assert.Equal(message, ex.Message); message = ""; ex = new EncoderFallbackException(message); Assert.Equal(default(char), ex.CharUnknown); Assert.Equal(default(char), ex.CharUnknownHigh); Assert.Equal(default(char), ex.CharUnknownLow); Assert.Equal(default(int), ex.Index); Assert.Equal(message, ex.Message); }
public static Exception /*!*/ CreateInvalidByteSequenceError(EncoderFallbackException /*!*/ e, RubyEncoding /*!*/ encoding) { return(new InvalidByteSequenceError( FormatMessage( "character U+{0:X4} can't be encoded in {1}", e.CharUnknownHigh != '\0' ? Tokenizer.ToCodePoint(e.CharUnknownHigh, e.CharUnknownLow) : (int)e.CharUnknown, encoding ) )); }
public static Exception /*!*/ CreateTranscodingError(EncoderFallbackException /*!*/ e, RubyEncoding /*!*/ fromEncoding, RubyEncoding /*!*/ toEncoding) { return(new UndefinedConversionError( FormatMessage( "\"{0}\" to UTF-8 in conversion from {1} to UTF-8 to {2}", e.CharUnknown, fromEncoding, toEncoding ) )); }
public static void Ctor_String_Exception(string message, Exception innerException) { EncoderFallbackException encoderFallbackException = new EncoderFallbackException(message, innerException); Assert.Equal(default(char), encoderFallbackException.CharUnknown); Assert.Equal(default(char), encoderFallbackException.CharUnknownHigh); Assert.Equal(default(char), encoderFallbackException.CharUnknownLow); Assert.Equal(0, encoderFallbackException.Index); Assert.Null(encoderFallbackException.StackTrace); Assert.Equal(0, encoderFallbackException.Data.Count); Assert.Same(innerException, encoderFallbackException.InnerException); Assert.Equal(message, encoderFallbackException.Message); }
public static void Ctor() { EncoderFallbackException ex = new EncoderFallbackException(); Assert.Equal(default(char), ex.CharUnknown); Assert.Equal(default(char), ex.CharUnknownHigh); Assert.Equal(default(char), ex.CharUnknownLow); Assert.Equal(default(int), ex.Index); Assert.Null(ex.StackTrace); Assert.Null(ex.InnerException); Assert.Equal(0, ex.Data.Count); ArgumentException arg = new ArgumentException(); Assert.Equal(arg.Message, ex.Message); }
public static void Ctor_String_Exception(string message, Exception innerException) { EncoderFallbackException encoderFallbackException = new EncoderFallbackException(message, innerException); Assert.Equal(default(char), encoderFallbackException.CharUnknown); Assert.Equal(default(char), encoderFallbackException.CharUnknownHigh); Assert.Equal(default(char), encoderFallbackException.CharUnknownLow); Assert.Equal(0, encoderFallbackException.Index); Assert.Null(encoderFallbackException.StackTrace); Assert.Equal(0, encoderFallbackException.Data.Count); Assert.Same(innerException, encoderFallbackException.InnerException); Assert.Equal(message, encoderFallbackException.Message); }
public void CreateFallbackBuffer() { EncoderFallbackBuffer buffer = new EncoderExceptionFallback().CreateFallbackBuffer(); Assert.Equal((char)0, buffer.GetNextChar()); Assert.False(buffer.MovePrevious()); Assert.Equal(0, buffer.Remaining); EncoderFallbackException ex = Assert.Throws <EncoderFallbackException>(() => buffer.Fallback('a', 0)); Assert.Equal('a', ex.CharUnknown); ex = Assert.Throws <EncoderFallbackException>(() => buffer.Fallback('\uD800', '\uDC00', 0)); Assert.Equal('\uD800', ex.CharUnknownHigh); Assert.Equal('\uDC00', ex.CharUnknownLow); }
public static void Ctor() { EncoderFallbackException ex = new EncoderFallbackException(); Assert.Equal(default(char), ex.CharUnknown); Assert.Equal(default(char), ex.CharUnknownHigh); Assert.Equal(default(char), ex.CharUnknownLow); Assert.Equal(default(int), ex.Index); Assert.Null(ex.StackTrace); Assert.Null(ex.InnerException); Assert.Equal(0, ex.Data.Count); ArgumentException arg = new ArgumentException(); Assert.Equal(arg.Message, ex.Message); }
public static bool ValidateUnicodeEncoding(string text) { UnicodeEncoding encoding = Encoding.GetEncoding(Encoding.Unicode.CodePage, EncoderFallback.ExceptionFallback, DecoderFallback.ExceptionFallback) as UnicodeEncoding; try { encoding.GetByteCount(text); } catch (EncoderFallbackException encoderFallbackException1) { EncoderFallbackException encoderFallbackException = encoderFallbackException1; CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] index = new object[] { encoderFallbackException.Index }; throw new FormatException(string.Format(invariantCulture, "Character at index {0} is not valid Unicode", index), encoderFallbackException); } return(true); }
public static void Validate(string text) { if (text == null) { throw new ArgumentNullException("text"); } try { MetadataEncoding.CreateAsciiEncoder().GetByteCount(text); } catch (EncoderFallbackException encoderFallbackException1) { EncoderFallbackException encoderFallbackException = encoderFallbackException1; CultureInfo invariantCulture = CultureInfo.InvariantCulture; object[] index = new object[] { encoderFallbackException.Index }; throw new FormatException(string.Format(invariantCulture, "Character at index {0} is not valid ASCII", index), encoderFallbackException); } }
public static int GetMetadataLengthWithAsciiEncoding(NameValueCollection metadata) { int byteCount = 0; int num = 1; Encoding encoding = MetadataEncoding.CreateAsciiEncoder(); string[] allKeys = metadata.AllKeys; for (int i = 0; i < (int)allKeys.Length; i++) { string str = allKeys[i]; try { byteCount = byteCount + encoding.GetByteCount(str) + num + encoding.GetByteCount(metadata[str]) + Environment.NewLine.Length; } catch (EncoderFallbackException encoderFallbackException1) { EncoderFallbackException encoderFallbackException = encoderFallbackException1; throw new MetadataFormatException(string.Format("Metadata pair {0}:{1} has an invalid char:{2}", str, metadata[str], encoderFallbackException.CharUnknown), encoderFallbackException); } } return(byteCount); }
public static void EncoderFallbackExceptionIndexTests(char[] firstPayload, char[] secondPayload, int expectedIndex) { UTF8Encoding encoding = new UTF8Encoding(encoderShouldEmitUTF8Identifier: false, throwOnInvalidBytes: true); // First test GetBytes / GetBytes Encoder encoder = encoding.GetEncoder(); Assert.Equal(0, encoder.GetBytes(firstPayload, 0, firstPayload.Length, new byte[0], 0, flush: false)); EncoderFallbackException ex = Assert.Throws <EncoderFallbackException>( () => encoder.GetBytes(secondPayload, 0, secondPayload.Length, new byte[8], 0, flush: true)); Assert.Equal(expectedIndex, ex.Index); // Then test GetBytes / GetByteCount encoder = encoding.GetEncoder(); Assert.Equal(0, encoder.GetBytes(firstPayload, 0, firstPayload.Length, new byte[0], 0, flush: false)); ex = Assert.Throws <EncoderFallbackException>( () => encoder.GetByteCount(secondPayload, 0, secondPayload.Length, flush: true)); Assert.Equal(expectedIndex, ex.Index); }
public static void Ctor2() { string message = "Test message."; EncoderFallbackException ex = new EncoderFallbackException(message); Assert.Equal(default(char), ex.CharUnknown); Assert.Equal(default(char), ex.CharUnknownHigh); Assert.Equal(default(char), ex.CharUnknownLow); Assert.Equal(default(int), ex.Index); Assert.Null(ex.StackTrace); Assert.Null(ex.InnerException); Assert.Equal(0, ex.Data.Count); Assert.Equal(message, ex.Message); message = ""; ex = new EncoderFallbackException(message); Assert.Equal(default(char), ex.CharUnknown); Assert.Equal(default(char), ex.CharUnknownHigh); Assert.Equal(default(char), ex.CharUnknownLow); Assert.Equal(default(int), ex.Index); Assert.Equal(message, ex.Message); }
public static ArgumentException GetArgumentException_ReadInvalidUTF16(EncoderFallbackException innerException) { return(new ArgumentException(SR.CannotTranscodeInvalidUtf16, innerException)); }
public static Exception /*!*/ CreateArgumentError(EncoderFallbackException /*!*/ e, RubyEncoding /*!*/ encoding) { return(RubyExceptions.CreateArgumentError(String.Format("character U+{0:X4} can't be encoded in {1}", e.CharUnknownHigh != '\0' ? Tokenizer.ToCodePoint(e.CharUnknownHigh, e.CharUnknownLow) : (int)e.CharUnknown, encoding))); }