5 // Atsushi Enomoto <atsushi@ximian.com>
7 // (C) 2006 Novell, Inc.
13 namespace MonoTests.System.Text
16 public class EncoderTest
20 [ExpectedException (typeof (ArgumentNullException))]
21 public void ConvertNullChars ()
23 int bytesUsed, charsUsed;
25 Encoding.UTF8.GetEncoder ().Convert (
26 null, 0, 100, new byte [100], 0, 100, false,
27 out bytesUsed, out charsUsed, out done);
31 [ExpectedException (typeof (ArgumentNullException))]
32 public void ConvertNullBytes ()
34 int bytesUsed, charsUsed;
36 Encoding.UTF8.GetEncoder ().Convert (
37 new char [100], 0, 100, null, 0, 100, false,
38 out bytesUsed, out charsUsed, out done);
42 public void ConvertLimitedDestination ()
44 byte [] bytes = new byte [10000];
45 char [] chars = new char [10000];
47 Encoder conv = Encoding.UTF8.GetEncoder ();
48 int bytesUsed, charsUsed;
51 conv.Convert (chars, 0, 10000, bytes, 0, 1000, true,
52 out bytesUsed, out charsUsed, out done);
54 Assert.IsFalse (done, "#1");
55 Assert.AreEqual (625, bytesUsed, "#2");
56 Assert.AreEqual (625, charsUsed, "#3");
60 public void CustomEncodingGetEncoder ()
62 var encoding = new CustomEncoding ();
63 var encoder = encoding.GetEncoder ();
64 Assert.IsNotNull (encoder);
67 class CustomEncoding : Encoding {
69 public override int GetByteCount (char [] chars, int index, int count)
71 throw new NotSupportedException ();
74 public override int GetBytes (char [] chars, int charIndex, int charCount, byte [] bytes, int byteIndex)
76 throw new NotSupportedException ();
79 public override int GetCharCount (byte [] bytes, int index, int count)
81 throw new NotSupportedException ();
84 public override int GetChars (byte [] bytes, int byteIndex, int byteCount, char [] chars, int charIndex)
86 throw new NotSupportedException ();
89 public override int GetMaxByteCount (int charCount)
91 throw new NotSupportedException ();
94 public override int GetMaxCharCount (int byteCount)
96 throw new NotSupportedException ();