Browse Source

2005-11-16 Atsushi Enomoto <[email protected]>

	* Decoder.cs : added FallbackBuffer property.
	* UTF8Encoding.cs : In NET_2_0, use DecoderFallbackBuffer instead of
	  "throwOnInvalid".

	* UTF8EncodingTest.cs : Simply replaced all ArgumentException with
	  switched alias (it is DecodefFallbackException in NET_2_0).


svn path=/trunk/mcs/; revision=53137
Atsushi Eno 20 years ago
parent
commit
e14f1bcad3

+ 6 - 0
mcs/class/corlib/System.Text/ChangeLog

@@ -1,3 +1,9 @@
+2005-11-16  Atsushi Enomoto  <[email protected]>
+
+	* Decoder.cs : added FallbackBuffer property.
+	* UTF8Encoding.cs : In NET_2_0, use DecoderFallbackBuffer instead of
+	  "throwOnInvalid".
+
 2005-11-15  Atsushi Enomoto  <[email protected]>
 
 	* DecoderReplacementFallbackBuffer.cs : it does not have to preserve

+ 10 - 0
mcs/class/corlib/System.Text/Decoder.cs

@@ -36,6 +36,7 @@ public abstract class Decoder
 
 #if NET_2_0
 	DecoderFallback fallback;
+	DecoderFallbackBuffer fallback_buffer;
 
 	public DecoderFallback Fallback {
 		get { return fallback; }
@@ -43,6 +44,15 @@ public abstract class Decoder
 			if (value == null)
 				throw new ArgumentNullException ();
 			fallback = value;
+			fallback_buffer = null;
+		}
+	}
+
+	public DecoderFallbackBuffer FallbackBuffer {
+		get {
+			if (fallback_buffer == null)
+				fallback_buffer = fallback.CreateFallbackBuffer ();
+			return fallback_buffer;
 		}
 	}
 #endif

+ 148 - 25
mcs/class/corlib/System.Text/UTF8Encoding.cs

@@ -30,6 +30,9 @@ using System;
 
 [Serializable]
 [MonoTODO ("Fix serialization compatibility with MS.NET")]
+#if NET_2_0
+[MonoTODO ("EncoderFallback is not handled")]
+#endif
 public class UTF8Encoding : Encoding
 {
 	// Magic number used by Windows for UTF-8.
@@ -37,7 +40,9 @@ public class UTF8Encoding : Encoding
 
 	// Internal state.
 	private bool emitIdentifier;
+#if !NET_2_0
 	private bool throwOnInvalid;
+#endif
 
 	// Constructors.
 	public UTF8Encoding () : this (false, false) {}
@@ -48,7 +53,14 @@ public class UTF8Encoding : Encoding
 		: base (UTF8_CODE_PAGE)
 	{
 		emitIdentifier = encoderShouldEmitUTF8Identifier;
+#if NET_2_0
+		if (throwOnInvalidBytes)
+			DecoderFallback = new DecoderExceptionFallback ();
+		else
+			DecoderFallback = new DecoderReplacementFallback (String.Empty);
+#else
 		throwOnInvalid = throwOnInvalidBytes;
+#endif
 
 		web_name = body_name = header_name = "utf-8";
 		encoding_name = "Unicode (UTF-8)";
@@ -358,10 +370,17 @@ public class UTF8Encoding : Encoding
 
 	// Internal version of "GetCharCount" which can handle a rolling
 	// state between multiple calls to this method.
-	private static int InternalGetCharCount (byte[] bytes, int index, int count,
-										   uint leftOverBits,
-										   uint leftOverCount,
-										   bool throwOnInvalid, bool flush)
+#if NET_2_0
+	// Internal version of "GetCharCount" which can handle a rolling
+	// state between multiple calls to this method.
+	private static int InternalGetCharCount (
+		byte[] bytes, int index, int count, uint leftOverBits,
+		uint leftOverCount, DecoderFallbackBuffer fallbackBuffer, bool flush)
+#else
+	private static int InternalGetCharCount (
+		byte[] bytes, int index, int count, uint leftOverBits,
+		uint leftOverCount, bool throwOnInvalid, bool flush)
+#endif
 	{
 		// Validate the parameters.
 		if (bytes == null) {
@@ -415,9 +434,12 @@ public class UTF8Encoding : Encoding
 					leftSize = 6;
 				} else {
 					// Invalid UTF-8 start character.
-					if (throwOnInvalid) {
+#if NET_2_0
+					length += Fallback (fallbackBuffer, bytes, index - 1);
+#else
+					if (throwOnInvalid)
 						throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-					}
+#endif
 				}
 			} else {
 				// Process an extra byte in a multi-byte sequence.
@@ -446,51 +468,96 @@ public class UTF8Encoding : Encoding
 								break;
 							}
 							if (overlong) {
+#if NET_2_0
+								length += Fallback (fallbackBuffer, bytes, index - 1);
+#else
 								if (throwOnInvalid)
 									throw new ArgumentException (_("Overlong"), leftBits.ToString ());
+#endif
 							}
 							else
 								++length;
 						} else if (leftBits < (uint)0x110000) {
 							length += 2;
-						} else if (throwOnInvalid) {
-							throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
+						} else {
+#if NET_2_0
+							length += Fallback (fallbackBuffer, bytes, index - 1);
+#else
+							if (throwOnInvalid)
+								throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
+#endif
 						}
 						leftSize = 0;
 					}
 				} else {
 					// Invalid UTF-8 sequence: clear and restart.
-					if (throwOnInvalid) {
+#if NET_2_0
+					length += Fallback (fallbackBuffer, bytes, index - 1);
+#else
+					if (throwOnInvalid)
 						throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-					}
+#endif
 					leftSize = 0;
 					--index;
 					++count;
 				}
 			}
 		}
-		if (flush && leftSize != 0 && throwOnInvalid) {
+		if (flush && leftSize != 0) {
 			// We had left-over bytes that didn't make up
 			// a complete UTF-8 character sequence.
-			throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
+#if NET_2_0
+			length += Fallback (fallbackBuffer, bytes, index - 1);
+#else
+			if (throwOnInvalid)
+				throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
+#endif
 		}
 
 		// Return the final length to the caller.
 		return length;
 	}
 
+#if NET_2_0
+	// for GetCharCount()
+	static int Fallback (DecoderFallbackBuffer buffer, byte [] bytes, int index)
+	{
+		buffer.Fallback (bytes, index - 1);
+		return buffer.Remaining;
+	}
+
+	// for GetChars()
+	static void Fallback (DecoderFallbackBuffer buffer, byte [] bytes, int byteIndex,
+		char [] chars, ref int charIndex)
+	{
+		buffer.Fallback (bytes, byteIndex - 1);
+		while (buffer.Remaining > 0)
+			chars [charIndex++] = buffer.GetNextChar ();
+	}
+#endif
+
 	// Get the number of characters needed to decode a byte buffer.
 	public override int GetCharCount (byte[] bytes, int index, int count)
 	{
+#if NET_2_0
+		return InternalGetCharCount (bytes, index, count, 0, 0, DecoderFallback.CreateFallbackBuffer (), true);
+#else
 		return InternalGetCharCount (bytes, index, count, 0, 0, throwOnInvalid, true);
+#endif
 	}
 
 	// Get the characters that result from decoding a byte buffer.
-	private static int InternalGetChars (byte[] bytes, int byteIndex,
-									   int byteCount, char[] chars,
-									   int charIndex, ref uint leftOverBits,
-									   ref uint leftOverCount,
-									   bool throwOnInvalid, bool flush)
+#if NET_2_0
+	private static int InternalGetChars (
+		byte[] bytes, int byteIndex, int byteCount, char[] chars,
+		int charIndex, ref uint leftOverBits, ref uint leftOverCount,
+		DecoderFallbackBuffer fallbackBuffer, bool flush)
+#else
+	private static int InternalGetChars (
+		byte[] bytes, int byteIndex, int byteCount, char[] chars,
+		int charIndex, ref uint leftOverBits, ref uint leftOverCount,
+		bool throwOnInvalid, bool flush)
+#endif
 	{
 		// Validate the parameters.
 		if (bytes == null) {
@@ -558,9 +625,12 @@ public class UTF8Encoding : Encoding
 					leftSize = 6;
 				} else {
 					// Invalid UTF-8 start character.
-					if (throwOnInvalid) {
+#if NET_2_0
+					Fallback (fallbackBuffer, bytes, byteIndex, chars, ref posn);
+#else
+					if (throwOnInvalid)
 						throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-					}
+#endif
 				}
 			} else {
 				// Process an extra byte in a multi-byte sequence.
@@ -589,8 +659,12 @@ public class UTF8Encoding : Encoding
 								break;
 							}
 							if (overlong) {
+#if NET_2_0
+								Fallback (fallbackBuffer, bytes, byteIndex, chars, ref posn);
+#else
 								if (throwOnInvalid)
 									throw new ArgumentException (_("Overlong"), leftBits.ToString ());
+#endif
 							}
 							else {
 								if (posn >= length) {
@@ -609,26 +683,39 @@ public class UTF8Encoding : Encoding
 												   (uint)0xD800);
 							chars[posn++] =
 								(char)((leftBits & (uint)0x3FF) + (uint)0xDC00);
-						} else if (throwOnInvalid) {
-							throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
+						} else {
+#if NET_2_0
+							Fallback (fallbackBuffer, bytes, byteIndex, chars, ref posn);
+#else
+							if (throwOnInvalid)
+								throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
+#endif
 						}
 						leftSize = 0;
 					}
 				} else {
 					// Invalid UTF-8 sequence: clear and restart.
-					if (throwOnInvalid) {
+#if NET_2_0
+					Fallback (fallbackBuffer, bytes, byteIndex, chars, ref posn);
+#else
+					if (throwOnInvalid)
 						throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
-					}
+#endif
 					leftSize = 0;
 					--byteIndex;
 					++byteCount;
 				}
 			}
 		}
-		if (flush && leftSize != 0 && throwOnInvalid) {
+		if (flush && leftSize != 0) {
 			// We had left-over bytes that didn't make up
 			// a complete UTF-8 character sequence.
-			throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
+#if NET_2_0
+			Fallback (fallbackBuffer, bytes, byteIndex, chars, ref posn);
+#else
+			if (throwOnInvalid)
+				throw new ArgumentException (_("Arg_InvalidUTF8"), "bytes");
+#endif
 		}
 		leftOverBits = leftBits;
 		leftOverCount = (leftSoFar | (leftSize << 4));
@@ -643,8 +730,13 @@ public class UTF8Encoding : Encoding
 	{
 		uint leftOverBits = 0;
 		uint leftOverCount = 0;
+#if NET_2_0
+		return InternalGetChars (bytes, byteIndex, byteCount, chars, 
+				charIndex, ref leftOverBits, ref leftOverCount, DecoderFallback.CreateFallbackBuffer (), true);
+#else
 		return InternalGetChars (bytes, byteIndex, byteCount, chars, 
 				charIndex, ref leftOverBits, ref leftOverCount, throwOnInvalid, true);
+#endif
 	}
 
 	// Get the maximum number of bytes needed to encode a
@@ -670,7 +762,13 @@ public class UTF8Encoding : Encoding
 	// Get a UTF8-specific decoder that is attached to this instance.
 	public override Decoder GetDecoder ()
 	{
+#if NET_2_0
+		UTF8Decoder ret = new UTF8Decoder ();
+		ret.Fallback = DecoderFallback;
+		return ret;
+#else
 		return new UTF8Decoder (throwOnInvalid);
+#endif
 	}
 
 	// Get a UTF8-specific encoder that is attached to this instance.
@@ -698,9 +796,16 @@ public class UTF8Encoding : Encoding
 	{
 		UTF8Encoding enc = (value as UTF8Encoding);
 		if (enc != null) {
+#if NET_2_0
+			return (codePage == enc.codePage &&
+					emitIdentifier == enc.emitIdentifier &&
+					DecoderFallback == enc.DecoderFallback &&
+					EncoderFallback == enc.EncoderFallback);
+#else
 			return (codePage == enc.codePage &&
 					emitIdentifier == enc.emitIdentifier &&
 					throwOnInvalid == enc.throwOnInvalid);
+#endif
 		} else {
 			return false;
 		}
@@ -727,14 +832,22 @@ public class UTF8Encoding : Encoding
 	[Serializable]
 	private class UTF8Decoder : Decoder
 	{
+#if !NET_2_0
 		private bool throwOnInvalid;
+#endif
 		private uint leftOverBits;
 		private uint leftOverCount;
 
 		// Constructor.
+#if NET_2_0
+		public UTF8Decoder ()
+#else
 		public UTF8Decoder (bool throwOnInvalid)
+#endif
 		{
+#if !NET_2_0
 			this.throwOnInvalid = throwOnInvalid;
+#endif
 			leftOverBits = 0;
 			leftOverCount = 0;
 		}
@@ -742,14 +855,24 @@ public class UTF8Encoding : Encoding
 		// Override inherited methods.
 		public override int GetCharCount (byte[] bytes, int index, int count)
 		{
+#if NET_2_0
+			return InternalGetCharCount (bytes, index, count,
+				leftOverBits, leftOverCount, FallbackBuffer, false);
+#else
 			return InternalGetCharCount (bytes, index, count,
 					leftOverBits, leftOverCount, throwOnInvalid, false);
+#endif
 		}
 		public override int GetChars (byte[] bytes, int byteIndex,
 						 int byteCount, char[] chars, int charIndex)
 		{
+#if NET_2_0
+			return InternalGetChars (bytes, byteIndex, byteCount,
+				chars, charIndex, ref leftOverBits, ref leftOverCount, FallbackBuffer, false);
+#else
 			return InternalGetChars (bytes, byteIndex, byteCount,
 				chars, charIndex, ref leftOverBits, ref leftOverCount, throwOnInvalid, false);
+#endif
 		}
 
 	} // class UTF8Decoder

+ 5 - 0
mcs/class/corlib/Test/System.Text/ChangeLog

@@ -1,3 +1,8 @@
+2005-11-16  Atsushi Enomoto  <[email protected]>
+
+	* UTF8EncodingTest.cs : Simply replaced all ArgumentException with
+	  switched alias (it is DecodefFallbackException in NET_2_0).
+
 2005-11-15  Atsushi Enomoto  <[email protected]>
 
 	* EncoderReplacementFallbackBufferTest.cs : new test (it's weird, but

+ 74 - 68
mcs/class/corlib/Test/System.Text/UTF8EncodingTest.cs

@@ -13,6 +13,12 @@ using NUnit.Framework;
 using System;
 using System.Text;
 
+#if NET_2_0
+using DecoderException = System.Text.DecoderFallbackException;
+#else
+using DecoderException = System.ArgumentException;
+#endif
+
 namespace MonoTests.System.Text {
 
 	[TestFixture]
@@ -158,7 +164,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 		// Fail on MS Fx 1.1
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T2_Boundary_1_FirstPossibleSequence_Fail_5 () 
 		{
 			byte[] data215 = { 0xF8, 0x88, 0x80, 0x80, 0x80 };
@@ -169,7 +175,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 		// Fail on MS Fx 1.1
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T2_Boundary_1_FirstPossibleSequence_Fail_6 () 
 		{
 			byte[] data216 = { 0xFC, 0x84, 0x80, 0x80, 0x80, 0x80 };
@@ -200,7 +206,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 		// Fail on MS Fx 1.1
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T2_Boundary_2_LastPossibleSequence_Fail_4 () 
 		{
 			byte[] data224 = { 0x7F, 0xBF, 0xBF, 0xBF };
@@ -211,7 +217,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 		// Fail on MS Fx 1.1
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T2_Boundary_2_LastPossibleSequence_Fail_5 () 
 		{
 			byte[] data225 = { 0xFB, 0xBF, 0xBF, 0xBF, 0xBF };
@@ -222,7 +228,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 		// Fail on MS Fx 1.1
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T2_Boundary_2_LastPossibleSequence_Fail_6 () 
 		{
 			byte[] data226 = { 0xFD, 0xBF, 0xBF, 0xBF, 0xBF, 0xBF };
@@ -258,7 +264,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 		// Fail on MS Fx 1.1
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T2_Boundary_3_Other_Fail_5 () 
 		{
 			byte[] data235 = { 0xF4, 0x90, 0x80, 0x80 };
@@ -268,7 +274,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_1_UnexpectedContinuation_311 () 
 		{
 			byte[] data = { 0x80 };
@@ -277,7 +283,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_1_UnexpectedContinuation_312 () 
 		{
 			byte[] data = { 0xBF };
@@ -286,7 +292,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_1_UnexpectedContinuation_313 () 
 		{
 			byte[] data = { 0x80, 0xBF };
@@ -295,7 +301,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_1_UnexpectedContinuation_314 () 
 		{
 			byte[] data = { 0x80, 0xBF, 0x80 };
@@ -304,7 +310,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_1_UnexpectedContinuation_315 () 
 		{
 			byte[] data = { 0x80, 0xBF, 0x80, 0xBF };
@@ -313,7 +319,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_1_UnexpectedContinuation_316 () 
 		{
 			byte[] data = { 0x80, 0xBF, 0x80, 0xBF, 0x80 };
@@ -322,7 +328,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_1_UnexpectedContinuation_317 () 
 		{
 			byte[] data = { 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF };
@@ -331,7 +337,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_1_UnexpectedContinuation_318 () 
 		{
 			byte[] data = { 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF, 0x80 };
@@ -340,7 +346,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_1_UnexpectedContinuation_319 () 
 		{
 			// 64 different continuation characters
@@ -354,7 +360,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_2_LonelyStart_321 ()
 		{
 			byte[] data = { 
@@ -367,7 +373,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_2_LonelyStart_322 () 
 		{
 			byte[] data = { 
@@ -378,7 +384,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_2_LonelyStart_323 () 
 		{
 			byte[] data = { 0xF0, 0x20, 0xF1, 0x20, 0xF2, 0x20, 0xF3, 0x20, 0xF4, 0x20, 0xF5, 0x20, 0xF6, 0x20, 0xF7, 0x20 };
@@ -387,7 +393,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_2_LonelyStart_324 () 
 		{
 			byte[] data = { 0xF0, 0x20, 0xF1, 0x20, 0xF2, 0x20, 0xF3, 0x20, 0xF4, 0x20, 0xF5, 0x20, 0xF6, 0x20, 0xF7, 0x20 };
@@ -396,7 +402,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_2_LonelyStart_325 () 
 		{
 			byte[] data = { 0xFC, 0x20, 0xFD, 0x20 };
@@ -405,7 +411,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_3_LastContinuationMissing_331 () 
 		{
 			byte[] data = { 0xC0 };
@@ -414,7 +420,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_3_LastContinuationMissing_332 () 
 		{
 			byte[] data = { 0xE0, 0x80 };
@@ -423,7 +429,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_3_LastContinuationMissing_333 () 
 		{
 			byte[] data = { 0xF0, 0x80, 0x80 };
@@ -432,7 +438,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_3_LastContinuationMissing_334 () 
 		{
 			byte[] data = { 0xF8, 0x80, 0x80, 0x80 };
@@ -441,7 +447,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_3_LastContinuationMissing_335 () 
 		{
 			byte[] data = { 0xFC, 0x80, 0x80, 0x80, 0x80 };
@@ -451,7 +457,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_3_LastContinuationMissing_336 () 
 		{
 			byte[] data = { 0xDF };
@@ -460,14 +466,14 @@ namespace MonoTests.System.Text {
 				// exception is "really" expected here
 				AssertEquals ("MS FX 1.1 behaviour", String.Empty, s);
 			}
-			catch (ArgumentException) {
+			catch (DecoderException) {
 				// but Mono doesn't - better stick to the standard
 			}
 		}
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_3_LastContinuationMissing_337 () 
 		{
 			byte[] data = { 0xEF, 0xBF };
@@ -476,13 +482,13 @@ namespace MonoTests.System.Text {
 				// exception is "really" expected here
 				AssertEquals ("MS FX 1.1 behaviour", String.Empty, s);
 			}
-			catch (ArgumentException) {
+			catch (DecoderException) {
 				// but Mono doesn't - better stick to the standard
 			}
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_3_LastContinuationMissing_338 () 
 		{
 			byte[] data = { 0xF7, 0xBF, 0xBF };
@@ -491,7 +497,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_3_LastContinuationMissing_339 () 
 		{
 			byte[] data = { 0xF, 0xBF, 0xBF, 0xBF };
@@ -500,7 +506,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_3_LastContinuationMissing_3310 () 
 		{
 			byte[] data = { 0xFD, 0xBF, 0xBF, 0xBF, 0xBF };
@@ -509,7 +515,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_4_ConcatenationImcomplete () 
 		{
 			byte[] data = {
@@ -520,7 +526,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_5_ImpossibleBytes_351 () 
 		{
 			byte[] data = { 0xFE };
@@ -529,7 +535,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_5_ImpossibleBytes_352 () 
 		{
 			byte[] data = { 0xFF };
@@ -538,7 +544,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T3_Malformed_5_ImpossibleBytes_353 () 
 		{
 			byte[] data = { 0xFE, 0xFE, 0xFF, 0xFF };
@@ -549,7 +555,7 @@ namespace MonoTests.System.Text {
 		// Overlong == dangereous -> "safe" decoder should reject them
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_1_ASCII_Slash_411 () 
 		{
 			byte[] data = { 0xC0, 0xAF };
@@ -558,7 +564,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_1_ASCII_Slash_412 () 
 		{
 			byte[] data = { 0xE0, 0x80, 0xAF };
@@ -567,7 +573,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_1_ASCII_Slash_413 () 
 		{
 			byte[] data = { 0xF0, 0x80, 0x80, 0xAF };
@@ -576,7 +582,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_1_ASCII_Slash_414 () 
 		{
 			byte[] data = { 0xF8, 0x80, 0x80, 0x80, 0xAF };
@@ -585,7 +591,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_1_ASCII_Slash_415 () 
 		{
 			byte[] data = { 0xFC, 0x80, 0x80, 0x80, 0x80, 0xAF };
@@ -594,7 +600,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_2_MaximumBoundary_421 () 
 		{
 			byte[] data = { 0xC1, 0xBF };
@@ -603,7 +609,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_2_MaximumBoundary_422 () 
 		{
 			byte[] data = { 0xE0, 0x9F, 0xBF };
@@ -612,7 +618,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_2_MaximumBoundary_423 () 
 		{
 			byte[] data = { 0xF0, 0x8F, 0xBF, 0xBF };
@@ -621,7 +627,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_2_MaximumBoundary_424 () 
 		{
 			byte[] data = { 0xF8, 0x87, 0xBF, 0xBF, 0xBF };
@@ -630,7 +636,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_2_MaximumBoundary_425 () 
 		{
 			byte[] data = { 0xFC, 0x83, 0xBF, 0xBF, 0xBF, 0xBF };
@@ -639,7 +645,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_3_NUL_431 () 
 		{
 			byte[] data = { 0xC0, 0x80 };
@@ -648,7 +654,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_3_NUL_432 () 
 		{
 			byte[] data = { 0xE0, 0x80, 0x80 };
@@ -657,7 +663,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_3_NUL_433 () 
 		{
 			byte[] data = { 0xF0, 0x80, 0x80, 0x80 };
@@ -666,7 +672,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_3_NUL_434 () 
 		{
 			byte[] data = { 0xF8, 0x80, 0x80, 0x80, 0x80 };
@@ -675,7 +681,7 @@ namespace MonoTests.System.Text {
 		}
 
 		[Test]
-		[ExpectedException (typeof (ArgumentException))]
+		[ExpectedException (typeof (DecoderException))]
 		public void T4_Overlong_3_NUL_435 () 
 		{
 			byte[] data = { 0xFC, 0x80, 0x80, 0x80, 0x80, 0x80 };
@@ -685,7 +691,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 			public void T5_IllegalCodePosition_1_UTF16Surrogates_511 () 
 		{
 			byte[] data = { 0xED, 0xA0, 0x80 };
@@ -696,7 +702,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_1_UTF16Surrogates_512 () 
 		{
 			byte[] data = { 0xED, 0xAD, 0xBF };
@@ -707,7 +713,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_1_UTF16Surrogates_513 ()
 		{
 			byte[] data = { 0xED, 0xAE, 0x80 };
@@ -718,7 +724,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_1_UTF16Surrogates_514 () 
 		{
 			byte[] data = { 0xED, 0xAF, 0xBF };
@@ -729,7 +735,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_1_UTF16Surrogates_515 ()
 		{
 			byte[] data = { 0xED, 0xB0, 0x80 };
@@ -740,7 +746,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_1_UTF16Surrogates_516 () 
 		{
 			byte[] data = { 0xED, 0xBE, 0x80 };
@@ -751,7 +757,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_1_UTF16Surrogates_517 () 
 		{
 			byte[] data = { 0xED, 0xBF, 0xBF };
@@ -762,7 +768,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_521 () 
 		{
 			byte[] data = { 0xED, 0xA0, 0x80, 0xED, 0xB0, 0x80 };
@@ -774,7 +780,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_522 () 
 		{
 			byte[] data = { 0xED, 0xA0, 0x80, 0xED, 0xBF, 0xBF };
@@ -786,7 +792,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_523 () 
 		{
 			byte[] data = { 0xED, 0xAD, 0xBF, 0xED, 0xB0, 0x80 };
@@ -798,7 +804,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_524 () 
 		{
 			byte[] data = { 0xED, 0xAD, 0xBF, 0xED, 0xBF, 0xBF };
@@ -810,7 +816,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_525 () 
 		{
 			byte[] data = { 0xED, 0xAE, 0x80, 0xED, 0xB0, 0x80 };
@@ -822,7 +828,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_526 () 
 		{
 			byte[] data = { 0xED, 0xAE, 0x80, 0xED, 0xBF, 0x8F };
@@ -834,7 +840,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_527 () 
 		{
 			byte[] data = { 0xED, 0xAF, 0xBF, 0xED, 0xB0, 0x80 };
@@ -846,7 +852,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_528 () 
 		{
 			byte[] data = { 0xED, 0xAF, 0xBF, 0xED, 0xBF, 0xBF };
@@ -858,7 +864,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_3_Other_531 () 
 		{
 			byte[] data = { 0xEF, 0xBF, 0xBE };
@@ -869,7 +875,7 @@ namespace MonoTests.System.Text {
 
 		[Test]
 // MS Fx 1.1 accept this
-//		[ExpectedException (typeof (ArgumentException))]
+//		[ExpectedException (typeof (DecoderException))]
 		public void T5_IllegalCodePosition_3_Other_532 () 
 		{
 			byte[] data = { 0xEF, 0xBF, 0xBF };