Merge pull request #201 from QuickJack/master
[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
59                 [Test]
60                 public void CustomEncodingGetEncoder ()
61                 {
62                         var encoding = new CustomEncoding ();
63                         var encoder = encoding.GetEncoder ();
64                         Assert.IsNotNull (encoder);
65                 }
66
67                 class CustomEncoding : Encoding {
68
69                         public override int GetByteCount (char [] chars, int index, int count)
70                         {
71                                 throw new NotSupportedException ();
72                         }
73
74                         public override int GetBytes (char [] chars, int charIndex, int charCount, byte [] bytes, int byteIndex)
75                         {
76                                 throw new NotSupportedException ();
77                         }
78
79                         public override int GetCharCount (byte [] bytes, int index, int count)
80                         {
81                                 throw new NotSupportedException ();
82                         }
83
84                         public override int GetChars (byte [] bytes, int byteIndex, int byteCount, char [] chars, int charIndex)
85                         {
86                                 throw new NotSupportedException ();
87                         }
88
89                         public override int GetMaxByteCount (int charCount)
90                         {
91                                 throw new NotSupportedException ();
92                         }
93
94                         public override int GetMaxCharCount (int byteCount)
95                         {
96                                 throw new NotSupportedException ();
97                         }
98                 }
99 #endif
100         }
101 }