5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2006 Novell, Inc.
13 namespace MonoTests.System.Text
16 public class DecoderTest
19 [ExpectedException (typeof (ArgumentNullException))]
20 public void ConvertNullChars ()
22 int charsUsed, bytesUsed;
24 Encoding.UTF8.GetDecoder ().Convert (
25 null, 0, 100, new char [100], 0, 100, false,
26 out charsUsed, out bytesUsed, out done);
30 [ExpectedException (typeof (ArgumentNullException))]
31 public void ConvertNullBytes ()
33 int charsUsed, bytesUsed;
35 Encoding.UTF8.GetDecoder ().Convert (
36 new byte [100], 0, 100, null, 0, 100, false,
37 out charsUsed, out bytesUsed, out done);
41 public void ConvertLimitedDestination ()
43 char [] chars = new char [10000];
44 byte [] bytes = new byte [10000];
46 Decoder conv = new ExposedDecoder ();
47 int charsUsed, bytesUsed;
50 conv.Convert (bytes, 0, 10000, chars, 0, 1000, true,
51 out charsUsed, out bytesUsed, out done);
53 Assert.IsFalse (done, "#1");
54 Assert.AreEqual (625, charsUsed, "#2");
55 Assert.AreEqual (625, bytesUsed, "#3");
59 public void ConvertLimitedDestinationUTF8 ()
61 char [] chars = new char [10000];
62 byte [] bytes = new byte [10000];
64 Decoder conv = Encoding.UTF8.GetDecoder ();
65 int charsUsed, bytesUsed;
68 conv.Convert (bytes, 0, 10000, chars, 0, 1000, true,
69 out charsUsed, out bytesUsed, out done);
71 Assert.IsFalse (done, "#1");
72 Assert.AreEqual (1000, charsUsed, "#2");
73 Assert.AreEqual (1000, bytesUsed, "#3");
78 public void CustomEncodingGetDecoder ()
80 var encoding = new CustomEncoding ();
81 var decoder = encoding.GetDecoder ();
82 Assert.IsNotNull (decoder);
85 class ExposedDecoder : Decoder {
86 public override int GetCharCount (byte [] bytes, int index, int count)
88 return Encoding.UTF8.GetDecoder ().GetCharCount (bytes, index, count);
91 public override int GetChars (byte [] bytes, int byteIndex, int byteCount, char [] chars, int charIndex)
93 return Encoding.UTF8.GetDecoder ().GetChars (bytes, byteIndex, byteCount, chars, charIndex);
97 class CustomEncoding : Encoding {
99 public override int GetByteCount (char [] chars, int index, int count)
101 throw new NotSupportedException ();
104 public override int GetBytes (char [] chars, int charIndex, int charCount, byte [] bytes, int byteIndex)
106 throw new NotSupportedException ();
109 public override int GetCharCount (byte [] bytes, int index, int count)
111 throw new NotSupportedException ();
114 public override int GetChars (byte [] bytes, int byteIndex, int byteCount, char [] chars, int charIndex)
116 throw new NotSupportedException ();
119 public override int GetMaxByteCount (int charCount)
121 throw new NotSupportedException ();
124 public override int GetMaxCharCount (int byteCount)
126 throw new NotSupportedException ();
131 public void Bug10789 ()
133 byte[] bytes = new byte[100];
134 char[] chars = new char[100];
136 Decoder conv = Encoding.UTF8.GetDecoder ();
137 int charsUsed, bytesUsed;
140 conv.Convert (bytes, 0, 0, chars, 100, 0, false, out bytesUsed, out charsUsed, out completed);
142 Assert.IsTrue (completed, "#1");
143 Assert.AreEqual (0, charsUsed, "#2");
144 Assert.AreEqual (0, bytesUsed, "#3");