Fix to UriTemplate.Match to properly handle query parameters without a value. No...
[mono.git] / mcs / class / corlib / Test / System.Text / UTF32EncodingTest.cs
1 using System;
2 using System.Text;
3
4 using NUnit.Framework;
5
6 namespace MonoTests.System.Text
7 {
8         [TestFixture]
9         public class UTF32EncodingTest
10         {
11                 [Test] // GetByteCount (Char [])
12                 [Category ("NotDotNet")] // A1/B1 return 24 on MS
13                 public void GetByteCount1 ()
14                 {
15                         char [] chars = new char[] { 'z', 'a', '\u0306',
16                                 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
17
18                         UTF32Encoding le = new UTF32Encoding (false, true);
19                         Assert.AreEqual (28, le.GetByteCount (chars), "#A1");
20                         Assert.AreEqual (0, le.GetByteCount (new char [0]), "#A2");
21
22                         UTF32Encoding be = new UTF32Encoding (true, true);
23                         Assert.AreEqual (28, be.GetByteCount (chars), "#B1");
24                         Assert.AreEqual (0, be.GetByteCount (new char [0]), "#B2");
25                 }
26
27                 [Test] // GetByteCount (Char [])
28                 public void GetByteCount1_Chars_Null ()
29                 {
30                         UTF32Encoding enc = new UTF32Encoding ();
31                         try {
32                                 enc.GetByteCount ((Char []) null);
33                                 Assert.Fail ("#1");
34                         } catch (ArgumentNullException ex) {
35                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
36                                 Assert.IsNull (ex.InnerException, "#3");
37                                 Assert.IsNotNull (ex.Message, "#4");
38                                 Assert.AreEqual ("chars", ex.ParamName, "#5");
39                         }
40                 }
41
42                 [Test] // GetByteCount (String)
43                 [Category ("NotDotNet")] // A1/B1 return 24 on MS
44                 public void GetByteCount2 ()
45                 {
46                         string s = "za\u0306\u01FD\u03B2\uD8FF\uDCFF";
47
48                         UTF32Encoding le = new UTF32Encoding (false, true);
49                         Assert.AreEqual (28, le.GetByteCount (s), "#A1");
50                         Assert.AreEqual (0, le.GetByteCount (string.Empty), "#A2");
51
52                         UTF32Encoding be = new UTF32Encoding (true, true);
53                         Assert.AreEqual (28, be.GetByteCount (s), "#B1");
54                         Assert.AreEqual (0, be.GetByteCount (string.Empty), "#B2");
55                 }
56
57                 [Test] // GetByteCount (String)
58                 public void GetByteCount2_S_Null ()
59                 {
60                         UTF32Encoding enc = new UTF32Encoding ();
61                         try {
62                                 enc.GetByteCount ((string) null);
63                                 Assert.Fail ("#1");
64                         } catch (ArgumentNullException ex) {
65                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
66                                 Assert.IsNull (ex.InnerException, "#3");
67                                 Assert.IsNotNull (ex.Message, "#4");
68                                 Assert.AreEqual ("s", ex.ParamName, "#5");
69                         }
70                 }
71
72                 [Test] // GetByteCount (Char *)
73                 public unsafe void GetByteCount3 ()
74                 {
75                         char [] chars = new char[] { 'z', 'a', '\u0306',
76                                 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
77
78                         fixed (char* cp = chars) {
79                                 UTF32Encoding le = new UTF32Encoding (false, true);
80                                 Assert.AreEqual (12, le.GetByteCount (cp, 3), "#A1");
81                                 Assert.AreEqual (4, le.GetByteCount (cp, 1), "#A2");
82                                 Assert.AreEqual (0, le.GetByteCount (cp, 0), "#A3");
83                                 Assert.AreEqual (24, le.GetByteCount (cp, 6), "#A4");
84                                 //Assert.AreEqual (24, le.GetByteCount (cp, 7), "#A5");
85
86                                 UTF32Encoding be = new UTF32Encoding (true, true);
87                                 Assert.AreEqual (12, be.GetByteCount (cp, 3), "#B1");
88                                 Assert.AreEqual (4, be.GetByteCount (cp, 1), "#B2");
89                                 Assert.AreEqual (0, be.GetByteCount (cp, 0), "#B3");
90                                 Assert.AreEqual (24, be.GetByteCount (cp, 6), "#B4");
91                                 //Assert.AreEqual (24, be.GetByteCount (cp, 7), "#B5");
92                         }
93                 }
94
95                 [Test] // GetByteCount (Char *)
96                 public unsafe void GetByteCount3_Chars_Null ()
97                 {
98                         UTF32Encoding enc = new UTF32Encoding ();
99                         try {
100                                 enc.GetByteCount ((char *) null, 1);
101                                 Assert.Fail ("#1");
102                         } catch (ArgumentNullException ex) {
103                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
104                                 Assert.IsNull (ex.InnerException, "#3");
105                                 Assert.IsNotNull (ex.Message, "#4");
106                                 Assert.AreEqual ("chars", ex.ParamName, "#5");
107                         }
108                 }
109
110                 [Test] // GetByteCount (Char [], Int32, Int32)
111                 public void GetByteCount4 ()
112                 {
113                         char [] chars = new char[] { 'z', 'a', '\u0306',
114                                 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
115
116                         UTF32Encoding le = new UTF32Encoding (false, true);
117                         Assert.AreEqual (12, le.GetByteCount (chars, 0, 3), "#A1");
118                         Assert.AreEqual (16, le.GetByteCount (chars, 2, 4), "#A2");
119                         Assert.AreEqual (4, le.GetByteCount (chars, 4, 1), "#A3");
120                         Assert.AreEqual (4, le.GetByteCount (chars, 6, 1), "#A4");
121                         Assert.AreEqual (0, le.GetByteCount (chars, 6, 0), "#A5");
122                         Assert.AreEqual (24, le.GetByteCount (chars, 0, 6), "#A6");
123                         //Assert.AreEqual (24, le.GetByteCount (chars, 0, 7), "#A7");
124
125                         UTF32Encoding be = new UTF32Encoding (true, true);
126                         Assert.AreEqual (12, be.GetByteCount (chars, 0, 3), "#B1");
127                         Assert.AreEqual (16, be.GetByteCount (chars, 2, 4), "#B2");
128                         Assert.AreEqual (4, be.GetByteCount (chars, 4, 1), "#B3");
129                         Assert.AreEqual (4, be.GetByteCount (chars, 6, 1), "#B4");
130                         Assert.AreEqual (0, be.GetByteCount (chars, 6, 0), "#B5");
131                         Assert.AreEqual (24, be.GetByteCount (chars, 0, 6), "#B6");
132                         //Assert.AreEqual (24, be.GetByteCount (chars, 0, 6), "#B7");
133                 }
134
135                 [Test] // GetByteCount (Char [], Int32, Int32)
136                 public void GetByteCount4_Chars_Null ()
137                 {
138                         UTF32Encoding enc = new UTF32Encoding ();
139                         try {
140                                 enc.GetByteCount ((Char []) null, 0, 1);
141                                 Assert.Fail ("#1");
142                         } catch (ArgumentNullException ex) {
143                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");
144                                 Assert.IsNull (ex.InnerException, "#3");
145                                 Assert.IsNotNull (ex.Message, "#4");
146                                 Assert.AreEqual ("chars", ex.ParamName, "#5");
147                         }
148                 }
149
150                 [Test] // GetByteCount (Char [], Int32, Int32)
151                 public void GetByteCount4_Count_Negative ()
152                 {
153                         char [] chars = new char[] { 'z', 'a', '\u0306',
154                                 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
155
156                         UTF32Encoding enc = new UTF32Encoding ();
157                         try {
158                                 enc.GetByteCount (chars, 1, -1);
159                                 Assert.Fail ("#1");
160                         } catch (ArgumentOutOfRangeException ex) {
161                                 // Non-negative number required
162                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
163                                 Assert.IsNull (ex.InnerException, "#3");
164                                 Assert.IsNotNull (ex.Message, "#4");
165                                 Assert.AreEqual ("count", ex.ParamName, "#5");
166                         }
167                 }
168
169                 [Test] // GetByteCount (Char [], Int32, Int32)
170                 public void GetByteCount4_Count_Overflow ()
171                 {
172                         char [] chars = new char[] { 'z', 'a', '\u0306',
173                                 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
174
175                         UTF32Encoding enc = new UTF32Encoding ();
176                         try {
177                                 enc.GetByteCount (chars, 6, 2);
178                                 Assert.Fail ("#1");
179                         } catch (ArgumentOutOfRangeException ex) {
180                                 // Index and count must refer to a location
181                                 // within the buffer
182                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
183                                 Assert.IsNull (ex.InnerException, "#3");
184                                 Assert.IsNotNull (ex.Message, "#4");
185                                 //Assert.AreEqual ("chars", ex.ParamName, "#5");
186                         }
187                 }
188
189                 [Test] // GetByteCount (Char [], Int32, Int32)
190                 public void GetByteCount4_Index_Negative ()
191                 {
192                         char [] chars = new char[] { 'z', 'a', '\u0306',
193                                 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
194
195                         UTF32Encoding enc = new UTF32Encoding ();
196                         try {
197                                 enc.GetByteCount (chars, -1, 1);
198                                 Assert.Fail ("#1");
199                         } catch (ArgumentOutOfRangeException ex) {
200                                 // Non-negative number required
201                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
202                                 Assert.IsNull (ex.InnerException, "#3");
203                                 Assert.IsNotNull (ex.Message, "#4");
204                                 Assert.AreEqual ("index", ex.ParamName, "#5");
205                         }
206                 }
207
208                 [Test] // GetByteCount (Char [], Int32, Int32)
209                 public void GetByteCount4_Index_Overflow ()
210                 {
211                         char [] chars = new char[] { 'z', 'a', '\u0306',
212                                 '\u01FD', '\u03B2', '\uD8FF', '\uDCFF' };
213
214                         UTF32Encoding enc = new UTF32Encoding ();
215                         try {
216                                 enc.GetByteCount (chars, 7, 1);
217                                 Assert.Fail ("#1");
218                         } catch (ArgumentOutOfRangeException ex) {
219                                 // Index and count must refer to a location
220                                 // within the buffer
221                                 Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#2");
222                                 Assert.IsNull (ex.InnerException, "#3");
223                                 Assert.IsNotNull (ex.Message, "#4");
224                                 //Assert.AreEqual ("chars", ex.ParamName, "#5");
225                         }
226                 }
227
228                 [Test]
229                 public void GetPreamble ()
230                 {
231                         byte[] lePreamble = new UTF32Encoding(false, true).GetPreamble();
232                         Assert.AreEqual (new byte [] { 0xff, 0xfe, 0, 0 }, lePreamble, "#1");
233
234                         byte[] bePreamble = new UTF32Encoding(true, true).GetPreamble();
235                         Assert.AreEqual (new byte [] { 0, 0, 0xfe, 0xff }, bePreamble, "#2");
236                 }
237
238                 [Test]
239                 public void IsBrowserDisplay ()
240                 {
241                         UTF32Encoding le = new UTF32Encoding (false, true);
242                         Assert.IsFalse (le.IsBrowserDisplay, "#1");
243
244                         UTF32Encoding be = new UTF32Encoding (true, true);
245                         Assert.IsFalse (be.IsBrowserDisplay, "#2");
246                 }
247
248                 [Test]
249                 public void IsBrowserSave ()
250                 {
251                         UTF32Encoding le = new UTF32Encoding (false, true);
252                         Assert.IsFalse (le.IsBrowserSave);
253
254                         UTF32Encoding be = new UTF32Encoding (true, true);
255                         Assert.IsFalse (be.IsBrowserSave, "#2");
256                 }
257
258                 [Test]
259                 public void IsMailNewsDisplay ()
260                 {
261                         UTF32Encoding le = new UTF32Encoding (false, true);
262                         Assert.IsFalse (le.IsMailNewsDisplay);
263
264                         UTF32Encoding be = new UTF32Encoding (true, true);
265                         Assert.IsFalse (be.IsMailNewsDisplay, "#2");
266                 }
267
268                 [Test]
269                 public void IsMailNewsSave ()
270                 {
271                         UTF32Encoding le = new UTF32Encoding (false, true);
272                         Assert.IsFalse (le.IsMailNewsSave);
273
274                         UTF32Encoding be = new UTF32Encoding (true, true);
275                         Assert.IsFalse (be.IsMailNewsSave, "#2");
276                 }
277         }
278 }