New test.
[mono.git] / mcs / class / corlib / Test / System.Text / EncoderTest.cs
1 //
2 // EncoderTest.cs
3 //
4 // Author:
5 //      Atsushi Enomoto  <atsushi@ximian.com>
6 //
7 // (C) 2006 Novell, Inc.
8 // 
9 using NUnit.Framework;
10 using System;
11 using System.Text;
12
13 namespace MonoTests.System.Text
14 {
15         [TestFixture]
16         public class EncoderTest
17         {
18 #if NET_2_0
19                 [Test]
20                 [ExpectedException (typeof (ArgumentNullException))]
21                 public void ConvertNullChars ()
22                 {
23                         int bytesUsed, charsUsed;
24                         bool done;
25                         Encoding.UTF8.GetEncoder ().Convert (
26                                 null, 0, 100, new byte [100], 0, 100, false,
27                                 out bytesUsed, out charsUsed, out done);
28                 }
29
30                 [Test]
31                 [ExpectedException (typeof (ArgumentNullException))]
32                 public void ConvertNullBytes ()
33                 {
34                         int bytesUsed, charsUsed;
35                         bool done;
36                         Encoding.UTF8.GetEncoder ().Convert (
37                                 new char [100], 0, 100, null, 0, 100, false,
38                                 out bytesUsed, out charsUsed, out done);
39                 }
40
41                 [Test]
42                 public void ConvertLimitedDestination ()
43                 {
44                         byte [] bytes = new byte [10000];
45                         char [] chars = new char [10000];
46
47                         Encoder conv = Encoding.UTF8.GetEncoder ();
48                         int bytesUsed, charsUsed;
49                         bool done;
50
51                         conv.Convert (chars, 0, 10000, bytes, 0, 1000, true,
52                                       out bytesUsed, out charsUsed, out done);
53
54                         Assert.IsFalse (done, "#1");
55                         Assert.AreEqual (625, bytesUsed, "#2");
56                         Assert.AreEqual (625, charsUsed, "#3");
57                 }
58 #endif
59         }
60 }