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);
68 public void ConvertZeroCharacters ()
70 int charsUsed, bytesUsed;
72 byte [] bytes = new byte [0];
74 Encoding.UTF8.GetEncoder ().Convert (
75 new char[0], 0, 0, bytes, 0, bytes.Length, true,
76 out charsUsed, out bytesUsed, out completed);
78 Assert.IsTrue (completed, "#1");
79 Assert.AreEqual (0, charsUsed, "#2");
80 Assert.AreEqual (0, bytesUsed, "#3");
83 class CustomEncoding : Encoding {
85 public override int GetByteCount (char [] chars, int index, int count)
87 throw new NotSupportedException ();
90 public override int GetBytes (char [] chars, int charIndex, int charCount, byte [] bytes, int byteIndex)
92 throw new NotSupportedException ();
95 public override int GetCharCount (byte [] bytes, int index, int count)
97 throw new NotSupportedException ();
100 public override int GetChars (byte [] bytes, int byteIndex, int byteCount, char [] chars, int charIndex)
102 throw new NotSupportedException ();
105 public override int GetMaxByteCount (int charCount)
107 throw new NotSupportedException ();
110 public override int GetMaxCharCount (int byteCount)
112 throw new NotSupportedException ();