e6c9ca91182f7810e74ce2b5addbbce994bfd1db
[mono.git] / mcs / class / corlib / Test / System.Text / UTF8EncodingTest.cs
1 //
2 // UTF8EncodingTest.cs - NUnit Test Cases for System.Text.UTF8Encoding
3 //
4 // Authors:
5 //      Patrick Kalkman  kalkman@cistron.nl
6 //      Sebastien Pouliot (spouliot@motus.com)
7 //
8 // (C) 2003 Patrick Kalkman
9 // (C) 2004 Novell (http://www.novell.com)
10 //
11
12 using NUnit.Framework;
13 using System;
14 using System.Text;
15
16 namespace MonoTests.System.Text {
17
18         [TestFixture]
19         public class UTF8EncodingTest : Assertion {
20
21                 private UTF8Encoding utf8;
22
23                 [SetUp]
24                 public void Create () 
25                 {
26                         utf8 = new UTF8Encoding (true, true);
27                 }
28
29                 [Test]
30                 public void TestEncodingGetBytes1()
31                 {
32                         UTF8Encoding utf8Enc = new UTF8Encoding ();
33                         string UniCode = "\u0041\u2262\u0391\u002E";
34                         
35                         // "A<NOT IDENTICAL TO><ALPHA>." may be encoded as 41 E2 89 A2 CE 91 2E 
36                         // see (RFC 2044)
37                         byte[] utf8Bytes = utf8Enc.GetBytes (UniCode);
38                         
39                         Assertion.AssertEquals ("UTF #1", 0x41, utf8Bytes [0]);
40                         Assertion.AssertEquals ("UTF #2", 0xE2, utf8Bytes [1]);
41                         Assertion.AssertEquals ("UTF #3", 0x89, utf8Bytes [2]);
42                         Assertion.AssertEquals ("UTF #4", 0xA2, utf8Bytes [3]);
43                         Assertion.AssertEquals ("UTF #5", 0xCE, utf8Bytes [4]);
44                         Assertion.AssertEquals ("UTF #6", 0x91, utf8Bytes [5]);
45                         Assertion.AssertEquals ("UTF #7", 0x2E, utf8Bytes [6]);
46                 }
47         
48                 [Test]
49                 public void TestEncodingGetBytes2()
50                 {
51                         UTF8Encoding utf8Enc = new UTF8Encoding ();
52                         string UniCode = "\u0048\u0069\u0020\u004D\u006F\u006D\u0020\u263A\u0021";
53                         
54                         // "Hi Mom <WHITE SMILING FACE>!" may be encoded as 48 69 20 4D 6F 6D 20 E2 98 BA 21 
55                         // see (RFC 2044)
56                         byte[] utf8Bytes = new byte [11];
57                         
58                         int ByteCnt = utf8Enc.GetBytes (UniCode.ToCharArray(), 0, UniCode.Length, utf8Bytes, 0);
59                         
60                         Assertion.AssertEquals ("UTF #1", 11, ByteCnt);
61                         Assertion.AssertEquals ("UTF #2", 0x48, utf8Bytes [0]);
62                         Assertion.AssertEquals ("UTF #3", 0x69, utf8Bytes [1]);
63                         Assertion.AssertEquals ("UTF #4", 0x20, utf8Bytes [2]);
64                         Assertion.AssertEquals ("UTF #5", 0x4D, utf8Bytes [3]);
65                         Assertion.AssertEquals ("UTF #6", 0x6F, utf8Bytes [4]);
66                         Assertion.AssertEquals ("UTF #7", 0x6D, utf8Bytes [5]);
67                         Assertion.AssertEquals ("UTF #8", 0x20, utf8Bytes [6]);
68                         Assertion.AssertEquals ("UTF #9", 0xE2, utf8Bytes [7]);
69                         Assertion.AssertEquals ("UTF #10", 0x98, utf8Bytes [8]);
70                         Assertion.AssertEquals ("UTF #11", 0xBA, utf8Bytes [9]);
71                         Assertion.AssertEquals ("UTF #12", 0x21, utf8Bytes [10]);
72                 }
73         
74                 [Test]
75                 public void TestDecodingGetChars1()
76                 {
77                         UTF8Encoding utf8Enc = new UTF8Encoding ();
78                         // 41 E2 89 A2 CE 91 2E may be decoded as "A<NOT IDENTICAL TO><ALPHA>." 
79                         // see (RFC 2044)
80                         byte[] utf8Bytes = new byte [] {0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E};
81                         char[] UniCodeChars = utf8Enc.GetChars(utf8Bytes);
82                              
83                         Assertion.AssertEquals ("UTF #1", 0x0041, UniCodeChars [0]);
84                         Assertion.AssertEquals ("UTF #2", 0x2262, UniCodeChars [1]);
85                         Assertion.AssertEquals ("UTF #3", 0x0391, UniCodeChars [2]);
86                         Assertion.AssertEquals ("UTF #4", 0x002E, UniCodeChars [3]);
87                 }
88                 
89                 [Test]
90                 public void TestMaxCharCount()
91                 {
92                         UTF8Encoding UTF8enc = new UTF8Encoding ();
93                         Assertion.AssertEquals ("UTF #1", 50, UTF8enc.GetMaxCharCount(50));
94                 }
95         
96                 [Test]
97                 public void TestMaxByteCount()
98                 {
99                         UTF8Encoding UTF8enc = new UTF8Encoding ();
100                         Assertion.AssertEquals ("UTF #1", 200, UTF8enc.GetMaxByteCount(50));
101                 }
102
103                 // regression for bug #59648
104                 [Test]
105                 public void TestThrowOnInvalid ()
106                 {
107                         UTF8Encoding u = new UTF8Encoding (true, false);
108
109                         byte[] data = new byte [] { 0xC0, 0xAF };
110                         string s = u.GetString (data);
111                         AssertEquals (0, s.Length);
112
113                         data = new byte [] { 0x30, 0x31, 0xC0, 0xAF, 0x30, 0x32 };
114                         s = u.GetString (data);
115                         AssertEquals (4, s.Length);
116                         AssertEquals (0x30, (int) s [0]);
117                         AssertEquals (0x31, (int) s [1]);
118                         AssertEquals (0x30, (int) s [2]);
119                         AssertEquals (0x32, (int) s [3]);
120                 }
121
122                 // UTF8 decoding tests from http://www.cl.cam.ac.uk/~mgk25/
123
124                 [Test]
125                 public void T1_Correct_GreekWord_kosme () 
126                 {
127                         byte[] data = { 0xCE, 0xBA, 0xE1, 0xBD, 0xB9, 0xCF, 0x83, 0xCE, 0xBC, 0xCE, 0xB5 };
128                         string s = utf8.GetString (data);
129                         // cute but saving source code in unicode can be problematic
130                         // so we just ensure we can re-encode this
131                         AssertEquals ("Reconverted", BitConverter.ToString (data), BitConverter.ToString (utf8.GetBytes (s)));
132                 }
133
134                 [Test]
135                 public void T2_Boundary_1_FirstPossibleSequence_Pass () 
136                 {
137                         byte[] data211 = { 0x00 };
138                         string s = utf8.GetString (data211);
139                         AssertEquals ("1 byte  (U-00000000)", "\0", s);
140                         AssertEquals ("Reconverted-1", BitConverter.ToString (data211), BitConverter.ToString (utf8.GetBytes (s)));
141
142                         byte[] data212 = { 0xC2, 0x80 };
143                         s = utf8.GetString (data212);
144                         AssertEquals ("2 bytes (U-00000080)", 128, s [0]);
145                         AssertEquals ("Reconverted-2", BitConverter.ToString (data212), BitConverter.ToString (utf8.GetBytes (s)));
146
147                         byte[] data213 = { 0xE0, 0xA0, 0x80 };
148                         s = utf8.GetString (data213);
149                         AssertEquals ("3 bytes (U-00000800)", 2048, s [0]);
150                         AssertEquals ("Reconverted-3", BitConverter.ToString (data213), BitConverter.ToString (utf8.GetBytes (s)));
151
152                         byte[] data214 = { 0xF0, 0x90, 0x80, 0x80 };
153                         s = utf8.GetString (data214);
154                         AssertEquals ("4 bytes (U-00010000)-0", 55296, s [0]);
155                         AssertEquals ("4 bytes (U-00010000)-1", 56320, s [1]);
156                         AssertEquals ("Reconverted-4", BitConverter.ToString (data214), BitConverter.ToString (utf8.GetBytes (s)));
157                 }
158
159                 [Test]
160                 // Fail on MS Fx 1.1
161                 [ExpectedException (typeof (ArgumentException))]
162                 public void T2_Boundary_1_FirstPossibleSequence_Fail_5 () 
163                 {
164                         byte[] data215 = { 0xF8, 0x88, 0x80, 0x80, 0x80 };
165                         string s = utf8.GetString (data215);
166                         AssertNull ("5 bytes (U-00200000)", s);
167                         AssertEquals ("Reconverted-5", BitConverter.ToString (data215), BitConverter.ToString (utf8.GetBytes (s)));
168                 }
169
170                 [Test]
171                 // Fail on MS Fx 1.1
172                 [ExpectedException (typeof (ArgumentException))]
173                 public void T2_Boundary_1_FirstPossibleSequence_Fail_6 () 
174                 {
175                         byte[] data216 = { 0xFC, 0x84, 0x80, 0x80, 0x80, 0x80 };
176                         string s = utf8.GetString (data216);
177                         AssertNull ("6 bytes (U-04000000)", s);
178                         AssertEquals ("Reconverted-6", BitConverter.ToString (data216), BitConverter.ToString (utf8.GetBytes (s)));
179                 }
180
181                 [Test]
182                 public void T2_Boundary_2_LastPossibleSequence_Pass () 
183                 {
184                         byte[] data221 = { 0x7F };
185                         string s = utf8.GetString (data221);
186                         AssertEquals ("1 byte  (U-0000007F)", 127, s [0]);
187                         AssertEquals ("Reconverted-1", BitConverter.ToString (data221), BitConverter.ToString (utf8.GetBytes (s)));
188
189                         byte[] data222 = { 0xDF, 0xBF };
190                         s = utf8.GetString (data222);
191                         AssertEquals ("2 bytes (U-000007FF)", 2047, s [0]);
192                         AssertEquals ("Reconverted-2", BitConverter.ToString (data222), BitConverter.ToString (utf8.GetBytes (s)));
193
194                         byte[] data223 = { 0xEF, 0xBF, 0xBF };
195                         s = utf8.GetString (data223);
196                         AssertEquals ("3 bytes (U-0000FFFF)", 65535, s [0]);
197                         AssertEquals ("Reconverted-3", BitConverter.ToString (data223), BitConverter.ToString (utf8.GetBytes (s)));
198
199                 }
200
201                 [Test]
202                 // Fail on MS Fx 1.1
203                 [ExpectedException (typeof (ArgumentException))]
204                 public void T2_Boundary_2_LastPossibleSequence_Fail_4 () 
205                 {
206                         byte[] data224 = { 0x7F, 0xBF, 0xBF, 0xBF };
207                         string s = utf8.GetString (data224);
208                         AssertNull ("4 bytes (U-001FFFFF)", s);
209                         AssertEquals ("Reconverted-4", BitConverter.ToString (data224), BitConverter.ToString (utf8.GetBytes (s)));
210                 }
211
212                 [Test]
213                 // Fail on MS Fx 1.1
214                 [ExpectedException (typeof (ArgumentException))]
215                 public void T2_Boundary_2_LastPossibleSequence_Fail_5 () 
216                 {
217                         byte[] data225 = { 0xFB, 0xBF, 0xBF, 0xBF, 0xBF };
218                         string s = utf8.GetString (data225);
219                         AssertNull ("5 bytes (U-03FFFFFF)", s);
220                         AssertEquals ("Reconverted-5", BitConverter.ToString (data225), BitConverter.ToString (utf8.GetBytes (s)));
221                 }
222
223                 [Test]
224                 // Fail on MS Fx 1.1
225                 [ExpectedException (typeof (ArgumentException))]
226                 public void T2_Boundary_2_LastPossibleSequence_Fail_6 () 
227                 {
228                         byte[] data226 = { 0xFD, 0xBF, 0xBF, 0xBF, 0xBF, 0xBF };
229                         string s = utf8.GetString (data226);
230                         AssertNull ("6 bytes (U-7FFFFFFF)", s);
231                         AssertEquals ("Reconverted-6", BitConverter.ToString (data226), BitConverter.ToString (utf8.GetBytes (s)));
232                 }
233
234                 [Test]
235                 public void T2_Boundary_3_Other_Pass () 
236                 {
237                         byte[] data231 = { 0xED, 0x9F, 0xBF };
238                         string s = utf8.GetString (data231);
239                         AssertEquals ("U-0000D7FF", 55295, s [0]);
240                         AssertEquals ("Reconverted-1", BitConverter.ToString (data231), BitConverter.ToString (utf8.GetBytes (s)));
241
242                         byte[] data232 = { 0xEE, 0x80, 0x80 };
243                         s = utf8.GetString (data232);
244                         AssertEquals ("U-0000E000", 57344, s [0]);
245                         AssertEquals ("Reconverted-2", BitConverter.ToString (data232), BitConverter.ToString (utf8.GetBytes (s)));
246
247                         byte[] data233 = { 0xEF, 0xBF, 0xBD };
248                         s = utf8.GetString (data233);
249                         AssertEquals ("U-0000FFFD", 65533, s [0]);
250                         AssertEquals ("Reconverted-3", BitConverter.ToString (data233), BitConverter.ToString (utf8.GetBytes (s)));
251
252                         byte[] data234 = { 0xF4, 0x8F, 0xBF, 0xBF };
253                         s = utf8.GetString (data234);
254                         AssertEquals ("U-0010FFFF-0", 56319, s [0]);
255                         AssertEquals ("U-0010FFFF-1", 57343, s [1]);
256                         AssertEquals ("Reconverted-4", BitConverter.ToString (data234), BitConverter.ToString (utf8.GetBytes (s)));
257                 }
258
259                 [Test]
260                 // Fail on MS Fx 1.1
261                 [ExpectedException (typeof (ArgumentException))]
262                 public void T2_Boundary_3_Other_Fail_5 () 
263                 {
264                         byte[] data235 = { 0xF4, 0x90, 0x80, 0x80 };
265                         string s = utf8.GetString (data235);
266                         AssertNull ("U-00110000", s);
267                         AssertEquals ("Reconverted-5", BitConverter.ToString (data235), BitConverter.ToString (utf8.GetBytes (s)));
268                 }
269
270                 [Test]
271                 [ExpectedException (typeof (ArgumentException))]
272                 public void T3_Malformed_1_UnexpectedContinuation_311 () 
273                 {
274                         byte[] data = { 0x80 };
275                         string s = utf8.GetString (data);
276                         // exception is "really" expected here
277                 }
278
279                 [Test]
280                 [ExpectedException (typeof (ArgumentException))]
281                 public void T3_Malformed_1_UnexpectedContinuation_312 () 
282                 {
283                         byte[] data = { 0xBF };
284                         string s = utf8.GetString (data);
285                         // exception is "really" expected here
286                 }
287
288                 [Test]
289                 [ExpectedException (typeof (ArgumentException))]
290                 public void T3_Malformed_1_UnexpectedContinuation_313 () 
291                 {
292                         byte[] data = { 0x80, 0xBF };
293                         string s = utf8.GetString (data);
294                         // exception is "really" expected here
295                 }
296
297                 [Test]
298                 [ExpectedException (typeof (ArgumentException))]
299                 public void T3_Malformed_1_UnexpectedContinuation_314 () 
300                 {
301                         byte[] data = { 0x80, 0xBF, 0x80 };
302                         string s = utf8.GetString (data);
303                         // exception is "really" expected here
304                 }
305
306                 [Test]
307                 [ExpectedException (typeof (ArgumentException))]
308                 public void T3_Malformed_1_UnexpectedContinuation_315 () 
309                 {
310                         byte[] data = { 0x80, 0xBF, 0x80, 0xBF };
311                         string s = utf8.GetString (data);
312                         // exception is "really" expected here
313                 }
314
315                 [Test]
316                 [ExpectedException (typeof (ArgumentException))]
317                 public void T3_Malformed_1_UnexpectedContinuation_316 () 
318                 {
319                         byte[] data = { 0x80, 0xBF, 0x80, 0xBF, 0x80 };
320                         string s = utf8.GetString (data);
321                         // exception is "really" expected here
322                 }
323
324                 [Test]
325                 [ExpectedException (typeof (ArgumentException))]
326                 public void T3_Malformed_1_UnexpectedContinuation_317 () 
327                 {
328                         byte[] data = { 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF };
329                         string s = utf8.GetString (data);
330                         // exception is "really" expected here
331                 }
332
333                 [Test]
334                 [ExpectedException (typeof (ArgumentException))]
335                 public void T3_Malformed_1_UnexpectedContinuation_318 () 
336                 {
337                         byte[] data = { 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF, 0x80 };
338                         string s = utf8.GetString (data);
339                         // exception is "really" expected here
340                 }
341
342                 [Test]
343                 [ExpectedException (typeof (ArgumentException))]
344                 public void T3_Malformed_1_UnexpectedContinuation_319 () 
345                 {
346                         // 64 different continuation characters
347                         byte[] data = {
348                                 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F, 
349                                 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F, 
350                                 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF, 
351                                 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF };
352                         string s = utf8.GetString (data);
353                         // exception is "really" expected here
354                 }
355
356                 [Test]
357                 [ExpectedException (typeof (ArgumentException))]
358                 public void T3_Malformed_2_LonelyStart_321 ()
359                 {
360                         byte[] data = { 
361                                 0xC0, 0x20, 0xC1, 0x20, 0xC2, 0x20, 0xC3, 0x20, 0xC4, 0x20, 0xC5, 0x20, 0xC6, 0x20, 0xC7, 0x20, 
362                                 0xC8, 0x20, 0xC9, 0x20, 0xCA, 0x20, 0xCB, 0x20, 0xCC, 0x20, 0xCD, 0x20, 0xCE, 0x20, 0xCF, 0x20, 
363                                 0xD0, 0x20, 0xD1, 0x20, 0xD2, 0x20, 0xD3, 0x20, 0xD4, 0x20, 0xD5, 0x20, 0xD6, 0x20, 0xD7, 0x20, 
364                                 0xD8, 0x20, 0xD9, 0x20, 0xDA, 0x20, 0xDB, 0x20, 0xDC, 0x20, 0xDD, 0x20, 0xDE, 0x20, 0xDF, 0x20 };
365                         string s = utf8.GetString (data);
366                         // exception is "really" expected here
367                 }
368
369                 [Test]
370                 [ExpectedException (typeof (ArgumentException))]
371                 public void T3_Malformed_2_LonelyStart_322 () 
372                 {
373                         byte[] data = { 
374                                 0xE0, 0x20, 0xE1, 0x20, 0xE2, 0x20, 0xE3, 0x20, 0xE4, 0x20, 0xE5, 0x20, 0xE6, 0x20, 0xE7, 0x20, 
375                                 0xE8, 0x20, 0xE9, 0x20, 0xEA, 0x20, 0xEB, 0x20, 0xEC, 0x20, 0xED, 0x20, 0xEE, 0x20, 0xEF, 0x20 };
376                         string s = utf8.GetString (data);
377                         // exception is "really" expected here
378                 }
379
380                 [Test]
381                 [ExpectedException (typeof (ArgumentException))]
382                 public void T3_Malformed_2_LonelyStart_323 () 
383                 {
384                         byte[] data = { 0xF0, 0x20, 0xF1, 0x20, 0xF2, 0x20, 0xF3, 0x20, 0xF4, 0x20, 0xF5, 0x20, 0xF6, 0x20, 0xF7, 0x20 };
385                         string s = utf8.GetString (data);
386                         // exception is "really" expected here
387                 }
388
389                 [Test]
390                 [ExpectedException (typeof (ArgumentException))]
391                 public void T3_Malformed_2_LonelyStart_324 () 
392                 {
393                         byte[] data = { 0xF0, 0x20, 0xF1, 0x20, 0xF2, 0x20, 0xF3, 0x20, 0xF4, 0x20, 0xF5, 0x20, 0xF6, 0x20, 0xF7, 0x20 };
394                         string s = utf8.GetString (data);
395                         // exception is "really" expected here
396                 }
397
398                 [Test]
399                 [ExpectedException (typeof (ArgumentException))]
400                 public void T3_Malformed_2_LonelyStart_325 () 
401                 {
402                         byte[] data = { 0xFC, 0x20, 0xFD, 0x20 };
403                         string s = utf8.GetString (data);
404                         // exception is "really" expected here
405                 }
406
407                 [Test]
408                 [ExpectedException (typeof (ArgumentException))]
409                 public void T3_Malformed_3_LastContinuationMissing_331 () 
410                 {
411                         byte[] data = { 0xC0 };
412                         string s = utf8.GetString (data);
413                         // exception is "really" expected here
414                 }
415
416                 [Test]
417                 [ExpectedException (typeof (ArgumentException))]
418                 public void T3_Malformed_3_LastContinuationMissing_332 () 
419                 {
420                         byte[] data = { 0xE0, 0x80 };
421                         string s = utf8.GetString (data);
422                         // exception is "really" expected here
423                 }
424
425                 [Test]
426                 [ExpectedException (typeof (ArgumentException))]
427                 public void T3_Malformed_3_LastContinuationMissing_333 () 
428                 {
429                         byte[] data = { 0xF0, 0x80, 0x80 };
430                         string s = utf8.GetString (data);
431                         // exception is "really" expected here
432                 }
433
434                 [Test]
435                 [ExpectedException (typeof (ArgumentException))]
436                 public void T3_Malformed_3_LastContinuationMissing_334 () 
437                 {
438                         byte[] data = { 0xF8, 0x80, 0x80, 0x80 };
439                         string s = utf8.GetString (data);
440                         // exception is "really" expected here
441                 }
442
443                 [Test]
444                 [ExpectedException (typeof (ArgumentException))]
445                 public void T3_Malformed_3_LastContinuationMissing_335 () 
446                 {
447                         byte[] data = { 0xFC, 0x80, 0x80, 0x80, 0x80 };
448                         string s = utf8.GetString (data);
449                         // exception is "really" expected here
450                 }
451
452                 [Test]
453 // MS Fx 1.1 accept this
454 //              [ExpectedException (typeof (ArgumentException))]
455                 public void T3_Malformed_3_LastContinuationMissing_336 () 
456                 {
457                         byte[] data = { 0xDF };
458                         try {
459                                 string s = utf8.GetString (data);
460                                 // exception is "really" expected here
461                                 AssertEquals ("MS FX 1.1 behaviour", String.Empty, s);
462                         }
463                         catch (ArgumentException) {
464                                 // but Mono doesn't - better stick to the standard
465                         }
466                 }
467
468                 [Test]
469 // MS Fx 1.1 accept this
470 //              [ExpectedException (typeof (ArgumentException))]
471                 public void T3_Malformed_3_LastContinuationMissing_337 () 
472                 {
473                         byte[] data = { 0xEF, 0xBF };
474                         try {
475                                 string s = utf8.GetString (data);
476                                 // exception is "really" expected here
477                                 AssertEquals ("MS FX 1.1 behaviour", String.Empty, s);
478                         }
479                         catch (ArgumentException) {
480                                 // but Mono doesn't - better stick to the standard
481                         }
482                 }
483
484                 [Test]
485                 [ExpectedException (typeof (ArgumentException))]
486                 public void T3_Malformed_3_LastContinuationMissing_338 () 
487                 {
488                         byte[] data = { 0xF7, 0xBF, 0xBF };
489                         string s = utf8.GetString (data);
490                         // exception is "really" expected here
491                 }
492
493                 [Test]
494                 [ExpectedException (typeof (ArgumentException))]
495                 public void T3_Malformed_3_LastContinuationMissing_339 () 
496                 {
497                         byte[] data = { 0xF, 0xBF, 0xBF, 0xBF };
498                         string s = utf8.GetString (data);
499                         // exception is "really" expected here
500                 }
501
502                 [Test]
503                 [ExpectedException (typeof (ArgumentException))]
504                 public void T3_Malformed_3_LastContinuationMissing_3310 () 
505                 {
506                         byte[] data = { 0xFD, 0xBF, 0xBF, 0xBF, 0xBF };
507                         string s = utf8.GetString (data);
508                         // exception is "really" expected here
509                 }
510
511                 [Test]
512                 [ExpectedException (typeof (ArgumentException))]
513                 public void T3_Malformed_4_ConcatenationImcomplete () 
514                 {
515                         byte[] data = {
516                                 0xC0, 0xE0, 0x80, 0xF0, 0x80, 0x80, 0xF8, 0x80, 0x80, 0x80, 0xFC, 0x80, 0x80, 0x80, 0x80, 0xDF, 
517                                 0xEF, 0xBF, 0xF7, 0xBF, 0xBF, 0xFB, 0xBF, 0xBF, 0xBF, 0xFD, 0xBF, 0xBF, 0xBF, 0xBF };
518                         string s = utf8.GetString (data);
519                         // exception is "really" expected here
520                 }
521
522                 [Test]
523                 [ExpectedException (typeof (ArgumentException))]
524                 public void T3_Malformed_5_ImpossibleBytes_351 () 
525                 {
526                         byte[] data = { 0xFE };
527                         string s = utf8.GetString (data);
528                         // exception is "really" expected here
529                 }
530
531                 [Test]
532                 [ExpectedException (typeof (ArgumentException))]
533                 public void T3_Malformed_5_ImpossibleBytes_352 () 
534                 {
535                         byte[] data = { 0xFF };
536                         string s = utf8.GetString (data);
537                         // exception is "really" expected here
538                 }
539
540                 [Test]
541                 [ExpectedException (typeof (ArgumentException))]
542                 public void T3_Malformed_5_ImpossibleBytes_353 () 
543                 {
544                         byte[] data = { 0xFE, 0xFE, 0xFF, 0xFF };
545                         string s = utf8.GetString (data);
546                         // exception is "really" expected here
547                 }
548
549                 // Overlong == dangereous -> "safe" decoder should reject them
550
551                 [Test]
552                 [ExpectedException (typeof (ArgumentException))]
553                 public void T4_Overlong_1_ASCII_Slash_411 () 
554                 {
555                         byte[] data = { 0xC0, 0xAF };
556                         string s = utf8.GetString (data);
557                         // exception is "really" expected here
558                 }
559
560                 [Test]
561                 [ExpectedException (typeof (ArgumentException))]
562                 public void T4_Overlong_1_ASCII_Slash_412 () 
563                 {
564                         byte[] data = { 0xE0, 0x80, 0xAF };
565                         string s = utf8.GetString (data);
566                         // exception is "really" expected here
567                 }
568
569                 [Test]
570                 [ExpectedException (typeof (ArgumentException))]
571                 public void T4_Overlong_1_ASCII_Slash_413 () 
572                 {
573                         byte[] data = { 0xF0, 0x80, 0x80, 0xAF };
574                         string s = utf8.GetString (data);
575                         // exception is "really" expected here
576                 }
577
578                 [Test]
579                 [ExpectedException (typeof (ArgumentException))]
580                 public void T4_Overlong_1_ASCII_Slash_414 () 
581                 {
582                         byte[] data = { 0xF8, 0x80, 0x80, 0x80, 0xAF };
583                         string s = utf8.GetString (data);
584                         // exception is "really" expected here
585                 }
586
587                 [Test]
588                 [ExpectedException (typeof (ArgumentException))]
589                 public void T4_Overlong_1_ASCII_Slash_415 () 
590                 {
591                         byte[] data = { 0xFC, 0x80, 0x80, 0x80, 0x80, 0xAF };
592                         string s = utf8.GetString (data);
593                         // exception is "really" expected here
594                 }
595
596                 [Test]
597                 [ExpectedException (typeof (ArgumentException))]
598                 public void T4_Overlong_2_MaximumBoundary_421 () 
599                 {
600                         byte[] data = { 0xC1, 0xBF };
601                         string s = utf8.GetString (data);
602                         // exception is "really" expected here
603                 }
604
605                 [Test]
606                 [ExpectedException (typeof (ArgumentException))]
607                 public void T4_Overlong_2_MaximumBoundary_422 () 
608                 {
609                         byte[] data = { 0xE0, 0x9F, 0xBF };
610                         string s = utf8.GetString (data);
611                         // exception is "really" expected here
612                 }
613
614                 [Test]
615                 [ExpectedException (typeof (ArgumentException))]
616                 public void T4_Overlong_2_MaximumBoundary_423 () 
617                 {
618                         byte[] data = { 0xF0, 0x8F, 0xBF, 0xBF };
619                         string s = utf8.GetString (data);
620                         // exception is "really" expected here
621                 }
622
623                 [Test]
624                 [ExpectedException (typeof (ArgumentException))]
625                 public void T4_Overlong_2_MaximumBoundary_424 () 
626                 {
627                         byte[] data = { 0xF8, 0x87, 0xBF, 0xBF, 0xBF };
628                         string s = utf8.GetString (data);
629                         // exception is "really" expected here
630                 }
631
632                 [Test]
633                 [ExpectedException (typeof (ArgumentException))]
634                 public void T4_Overlong_2_MaximumBoundary_425 () 
635                 {
636                         byte[] data = { 0xFC, 0x83, 0xBF, 0xBF, 0xBF, 0xBF };
637                         string s = utf8.GetString (data);
638                         // exception is "really" expected here
639                 }
640
641                 [Test]
642                 [ExpectedException (typeof (ArgumentException))]
643                 public void T4_Overlong_3_NUL_431 () 
644                 {
645                         byte[] data = { 0xC0, 0x80 };
646                         string s = utf8.GetString (data);
647                         // exception is "really" expected here
648                 }
649
650                 [Test]
651                 [ExpectedException (typeof (ArgumentException))]
652                 public void T4_Overlong_3_NUL_432 () 
653                 {
654                         byte[] data = { 0xE0, 0x80, 0x80 };
655                         string s = utf8.GetString (data);
656                         // exception is "really" expected here
657                 }
658
659                 [Test]
660                 [ExpectedException (typeof (ArgumentException))]
661                 public void T4_Overlong_3_NUL_433 () 
662                 {
663                         byte[] data = { 0xF0, 0x80, 0x80, 0x80 };
664                         string s = utf8.GetString (data);
665                         // exception is "really" expected here
666                 }
667
668                 [Test]
669                 [ExpectedException (typeof (ArgumentException))]
670                 public void T4_Overlong_3_NUL_434 () 
671                 {
672                         byte[] data = { 0xF8, 0x80, 0x80, 0x80, 0x80 };
673                         string s = utf8.GetString (data);
674                         // exception is "really" expected here
675                 }
676
677                 [Test]
678                 [ExpectedException (typeof (ArgumentException))]
679                 public void T4_Overlong_3_NUL_435 () 
680                 {
681                         byte[] data = { 0xFC, 0x80, 0x80, 0x80, 0x80, 0x80 };
682                         string s = utf8.GetString (data);
683                         // exception is "really" expected here
684                 }
685
686                 [Test]
687 // MS Fx 1.1 accept this
688 //              [ExpectedException (typeof (ArgumentException))]
689                         public void T5_IllegalCodePosition_1_UTF16Surrogates_511 () 
690                 {
691                         byte[] data = { 0xED, 0xA0, 0x80 };
692                         string s = utf8.GetString (data);
693                         // exception is "really" expected here
694                         AssertEquals ("MS FX 1.1 behaviour", 55296, s [0]);
695                 }
696
697                 [Test]
698 // MS Fx 1.1 accept this
699 //              [ExpectedException (typeof (ArgumentException))]
700                 public void T5_IllegalCodePosition_1_UTF16Surrogates_512 () 
701                 {
702                         byte[] data = { 0xED, 0xAD, 0xBF };
703                         string s = utf8.GetString (data);
704                         // exception is "really" expected here
705                         AssertEquals ("MS FX 1.1 behaviour", 56191, s [0]);
706                 }
707
708                 [Test]
709 // MS Fx 1.1 accept this
710 //              [ExpectedException (typeof (ArgumentException))]
711                 public void T5_IllegalCodePosition_1_UTF16Surrogates_513 ()
712                 {
713                         byte[] data = { 0xED, 0xAE, 0x80 };
714                         string s = utf8.GetString (data);
715                         // exception is "really" expected here
716                         AssertEquals ("MS FX 1.1 behaviour", 56192, s [0]);
717                 }
718
719                 [Test]
720 // MS Fx 1.1 accept this
721 //              [ExpectedException (typeof (ArgumentException))]
722                 public void T5_IllegalCodePosition_1_UTF16Surrogates_514 () 
723                 {
724                         byte[] data = { 0xED, 0xAF, 0xBF };
725                         string s = utf8.GetString (data);
726                         // exception is "really" expected here
727                         AssertEquals ("MS FX 1.1 behaviour", 56319, s [0]);
728                 }
729
730                 [Test]
731 // MS Fx 1.1 accept this
732 //              [ExpectedException (typeof (ArgumentException))]
733                 public void T5_IllegalCodePosition_1_UTF16Surrogates_515 ()
734                 {
735                         byte[] data = { 0xED, 0xB0, 0x80 };
736                         string s = utf8.GetString (data);
737                         // exception is "really" expected here
738                         AssertEquals ("MS FX 1.1 behaviour", 56320, s [0]);
739                 }
740
741                 [Test]
742 // MS Fx 1.1 accept this
743 //              [ExpectedException (typeof (ArgumentException))]
744                 public void T5_IllegalCodePosition_1_UTF16Surrogates_516 () 
745                 {
746                         byte[] data = { 0xED, 0xBE, 0x80 };
747                         string s = utf8.GetString (data);
748                         // exception is "really" expected here
749                         AssertEquals ("MS FX 1.1 behaviour", 57216, s [0]);
750                 }
751
752                 [Test]
753 // MS Fx 1.1 accept this
754 //              [ExpectedException (typeof (ArgumentException))]
755                 public void T5_IllegalCodePosition_1_UTF16Surrogates_517 () 
756                 {
757                         byte[] data = { 0xED, 0xBF, 0xBF };
758                         string s = utf8.GetString (data);
759                         // exception is "really" expected here
760                         AssertEquals ("MS FX 1.1 behaviour", 57343, s [0]);
761                 }
762
763                 [Test]
764 // MS Fx 1.1 accept this
765 //              [ExpectedException (typeof (ArgumentException))]
766                 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_521 () 
767                 {
768                         byte[] data = { 0xED, 0xA0, 0x80, 0xED, 0xB0, 0x80 };
769                         string s = utf8.GetString (data);
770                         // exception is "really" expected here
771                         AssertEquals ("MS FX 1.1 behaviour", 55296, s [0]);
772                         AssertEquals ("MS FX 1.1 behaviour", 56320, s [1]);
773                 }
774
775                 [Test]
776 // MS Fx 1.1 accept this
777 //              [ExpectedException (typeof (ArgumentException))]
778                 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_522 () 
779                 {
780                         byte[] data = { 0xED, 0xA0, 0x80, 0xED, 0xBF, 0xBF };
781                         string s = utf8.GetString (data);
782                         // exception is "really" expected here
783                         AssertEquals ("MS FX 1.1 behaviour", 55296, s [0]);
784                         AssertEquals ("MS FX 1.1 behaviour", 57343, s [1]);
785                 }
786
787                 [Test]
788 // MS Fx 1.1 accept this
789 //              [ExpectedException (typeof (ArgumentException))]
790                 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_523 () 
791                 {
792                         byte[] data = { 0xED, 0xAD, 0xBF, 0xED, 0xB0, 0x80 };
793                         string s = utf8.GetString (data);
794                         // exception is "really" expected here
795                         AssertEquals ("MS FX 1.1 behaviour", 56191, s [0]);
796                         AssertEquals ("MS FX 1.1 behaviour", 56320, s [1]);
797                 }
798
799                 [Test]
800 // MS Fx 1.1 accept this
801 //              [ExpectedException (typeof (ArgumentException))]
802                 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_524 () 
803                 {
804                         byte[] data = { 0xED, 0xAD, 0xBF, 0xED, 0xBF, 0xBF };
805                         string s = utf8.GetString (data);
806                         // exception is "really" expected here
807                         AssertEquals ("MS FX 1.1 behaviour", 56191, s [0]);
808                         AssertEquals ("MS FX 1.1 behaviour", 57343, s [1]);
809                 }
810
811                 [Test]
812 // MS Fx 1.1 accept this
813 //              [ExpectedException (typeof (ArgumentException))]
814                 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_525 () 
815                 {
816                         byte[] data = { 0xED, 0xAE, 0x80, 0xED, 0xB0, 0x80 };
817                         string s = utf8.GetString (data);
818                         // exception is "really" expected here
819                         AssertEquals ("MS FX 1.1 behaviour", 56192, s [0]);
820                         AssertEquals ("MS FX 1.1 behaviour", 56320, s [1]);
821                 }
822
823                 [Test]
824 // MS Fx 1.1 accept this
825 //              [ExpectedException (typeof (ArgumentException))]
826                 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_526 () 
827                 {
828                         byte[] data = { 0xED, 0xAE, 0x80, 0xED, 0xBF, 0x8F };
829                         string s = utf8.GetString (data);
830                         // exception is "really" expected here
831                         AssertEquals ("MS FX 1.1 behaviour", 56192, s [0]);
832                         AssertEquals ("MS FX 1.1 behaviour", 57295, s [1]);
833                 }
834
835                 [Test]
836 // MS Fx 1.1 accept this
837 //              [ExpectedException (typeof (ArgumentException))]
838                 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_527 () 
839                 {
840                         byte[] data = { 0xED, 0xAF, 0xBF, 0xED, 0xB0, 0x80 };
841                         string s = utf8.GetString (data);
842                         // exception is "really" expected here
843                         AssertEquals ("MS FX 1.1 behaviour", 56319, s [0]);
844                         AssertEquals ("MS FX 1.1 behaviour", 56320, s [1]);
845                 }
846
847                 [Test]
848 // MS Fx 1.1 accept this
849 //              [ExpectedException (typeof (ArgumentException))]
850                 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_528 () 
851                 {
852                         byte[] data = { 0xED, 0xAF, 0xBF, 0xED, 0xBF, 0xBF };
853                         string s = utf8.GetString (data);
854                         // exception is "really" expected here
855                         AssertEquals ("MS FX 1.1 behaviour", 56319, s [0]);
856                         AssertEquals ("MS FX 1.1 behaviour", 57343, s [1]);
857                 }
858
859                 [Test]
860 // MS Fx 1.1 accept this
861 //              [ExpectedException (typeof (ArgumentException))]
862                 public void T5_IllegalCodePosition_3_Other_531 () 
863                 {
864                         byte[] data = { 0xEF, 0xBF, 0xBE };
865                         string s = utf8.GetString (data);
866                         // exception is "really" expected here
867                         AssertEquals ("MS FX 1.1 behaviour", 65534, s [0]);
868                 }
869
870                 [Test]
871 // MS Fx 1.1 accept this
872 //              [ExpectedException (typeof (ArgumentException))]
873                 public void T5_IllegalCodePosition_3_Other_532 () 
874                 {
875                         byte[] data = { 0xEF, 0xBF, 0xBF };
876                         string s = utf8.GetString (data);
877                         // exception is "really" expected here
878                         AssertEquals ("MS FX 1.1 behaviour", 65535, s [0]);
879                 }
880         }
881 }