2 // UTF8EncodingTest.cs - NUnit Test Cases for System.Text.UTF8Encoding
5 // Patrick Kalkman kalkman@cistron.nl
6 // Sebastien Pouliot (spouliot@motus.com)
8 // (C) 2003 Patrick Kalkman
9 // (C) 2004 Novell (http://www.novell.com)
12 using NUnit.Framework;
16 namespace MonoTests.System.Text {
19 public class UTF8EncodingTest : Assertion {
21 private UTF8Encoding utf8;
26 utf8 = new UTF8Encoding (true, true);
30 public void TestEncodingGetBytes1()
32 UTF8Encoding utf8Enc = new UTF8Encoding ();
33 string UniCode = "\u0041\u2262\u0391\u002E";
35 // "A<NOT IDENTICAL TO><ALPHA>." may be encoded as 41 E2 89 A2 CE 91 2E
37 byte[] utf8Bytes = utf8Enc.GetBytes (UniCode);
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]);
49 public void TestEncodingGetBytes2()
51 UTF8Encoding utf8Enc = new UTF8Encoding ();
52 string UniCode = "\u0048\u0069\u0020\u004D\u006F\u006D\u0020\u263A\u0021";
54 // "Hi Mom <WHITE SMILING FACE>!" may be encoded as 48 69 20 4D 6F 6D 20 E2 98 BA 21
56 byte[] utf8Bytes = new byte [11];
58 int ByteCnt = utf8Enc.GetBytes (UniCode.ToCharArray(), 0, UniCode.Length, utf8Bytes, 0);
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]);
75 public void TestDecodingGetChars1()
77 UTF8Encoding utf8Enc = new UTF8Encoding ();
78 // 41 E2 89 A2 CE 91 2E may be decoded as "A<NOT IDENTICAL TO><ALPHA>."
80 byte[] utf8Bytes = new byte [] {0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E};
81 char[] UniCodeChars = utf8Enc.GetChars(utf8Bytes);
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]);
90 public void TestMaxCharCount()
92 UTF8Encoding UTF8enc = new UTF8Encoding ();
93 Assertion.AssertEquals ("UTF #1", 50, UTF8enc.GetMaxCharCount(50));
97 public void TestMaxByteCount()
99 UTF8Encoding UTF8enc = new UTF8Encoding ();
100 Assertion.AssertEquals ("UTF #1", 200, UTF8enc.GetMaxByteCount(50));
103 // regression for bug #59648
105 public void TestThrowOnInvalid ()
107 UTF8Encoding u = new UTF8Encoding (true, false);
109 byte[] data = new byte [] { 0xC0, 0xAF };
110 string s = u.GetString (data);
111 AssertEquals (0, s.Length);
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]);
122 // UTF8 decoding tests from http://www.cl.cam.ac.uk/~mgk25/
125 public void T1_Correct_GreekWord_kosme ()
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)));
135 public void T2_Boundary_1_FirstPossibleSequence_Pass ()
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)));
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)));
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)));
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)));
161 [ExpectedException (typeof (ArgumentException))]
162 public void T2_Boundary_1_FirstPossibleSequence_Fail_5 ()
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)));
172 [ExpectedException (typeof (ArgumentException))]
173 public void T2_Boundary_1_FirstPossibleSequence_Fail_6 ()
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)));
182 public void T2_Boundary_2_LastPossibleSequence_Pass ()
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)));
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)));
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)));
203 [ExpectedException (typeof (ArgumentException))]
204 public void T2_Boundary_2_LastPossibleSequence_Fail_4 ()
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)));
214 [ExpectedException (typeof (ArgumentException))]
215 public void T2_Boundary_2_LastPossibleSequence_Fail_5 ()
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)));
225 [ExpectedException (typeof (ArgumentException))]
226 public void T2_Boundary_2_LastPossibleSequence_Fail_6 ()
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)));
235 public void T2_Boundary_3_Other_Pass ()
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)));
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)));
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)));
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)));
261 [ExpectedException (typeof (ArgumentException))]
262 public void T2_Boundary_3_Other_Fail_5 ()
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)));
271 [ExpectedException (typeof (ArgumentException))]
272 public void T3_Malformed_1_UnexpectedContinuation_311 ()
274 byte[] data = { 0x80 };
275 string s = utf8.GetString (data);
276 // exception is "really" expected here
280 [ExpectedException (typeof (ArgumentException))]
281 public void T3_Malformed_1_UnexpectedContinuation_312 ()
283 byte[] data = { 0xBF };
284 string s = utf8.GetString (data);
285 // exception is "really" expected here
289 [ExpectedException (typeof (ArgumentException))]
290 public void T3_Malformed_1_UnexpectedContinuation_313 ()
292 byte[] data = { 0x80, 0xBF };
293 string s = utf8.GetString (data);
294 // exception is "really" expected here
298 [ExpectedException (typeof (ArgumentException))]
299 public void T3_Malformed_1_UnexpectedContinuation_314 ()
301 byte[] data = { 0x80, 0xBF, 0x80 };
302 string s = utf8.GetString (data);
303 // exception is "really" expected here
307 [ExpectedException (typeof (ArgumentException))]
308 public void T3_Malformed_1_UnexpectedContinuation_315 ()
310 byte[] data = { 0x80, 0xBF, 0x80, 0xBF };
311 string s = utf8.GetString (data);
312 // exception is "really" expected here
316 [ExpectedException (typeof (ArgumentException))]
317 public void T3_Malformed_1_UnexpectedContinuation_316 ()
319 byte[] data = { 0x80, 0xBF, 0x80, 0xBF, 0x80 };
320 string s = utf8.GetString (data);
321 // exception is "really" expected here
325 [ExpectedException (typeof (ArgumentException))]
326 public void T3_Malformed_1_UnexpectedContinuation_317 ()
328 byte[] data = { 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF };
329 string s = utf8.GetString (data);
330 // exception is "really" expected here
334 [ExpectedException (typeof (ArgumentException))]
335 public void T3_Malformed_1_UnexpectedContinuation_318 ()
337 byte[] data = { 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF, 0x80 };
338 string s = utf8.GetString (data);
339 // exception is "really" expected here
343 [ExpectedException (typeof (ArgumentException))]
344 public void T3_Malformed_1_UnexpectedContinuation_319 ()
346 // 64 different continuation characters
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
357 [ExpectedException (typeof (ArgumentException))]
358 public void T3_Malformed_2_LonelyStart_321 ()
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
370 [ExpectedException (typeof (ArgumentException))]
371 public void T3_Malformed_2_LonelyStart_322 ()
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
381 [ExpectedException (typeof (ArgumentException))]
382 public void T3_Malformed_2_LonelyStart_323 ()
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
390 [ExpectedException (typeof (ArgumentException))]
391 public void T3_Malformed_2_LonelyStart_324 ()
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
399 [ExpectedException (typeof (ArgumentException))]
400 public void T3_Malformed_2_LonelyStart_325 ()
402 byte[] data = { 0xFC, 0x20, 0xFD, 0x20 };
403 string s = utf8.GetString (data);
404 // exception is "really" expected here
408 [ExpectedException (typeof (ArgumentException))]
409 public void T3_Malformed_3_LastContinuationMissing_331 ()
411 byte[] data = { 0xC0 };
412 string s = utf8.GetString (data);
413 // exception is "really" expected here
417 [ExpectedException (typeof (ArgumentException))]
418 public void T3_Malformed_3_LastContinuationMissing_332 ()
420 byte[] data = { 0xE0, 0x80 };
421 string s = utf8.GetString (data);
422 // exception is "really" expected here
426 [ExpectedException (typeof (ArgumentException))]
427 public void T3_Malformed_3_LastContinuationMissing_333 ()
429 byte[] data = { 0xF0, 0x80, 0x80 };
430 string s = utf8.GetString (data);
431 // exception is "really" expected here
435 [ExpectedException (typeof (ArgumentException))]
436 public void T3_Malformed_3_LastContinuationMissing_334 ()
438 byte[] data = { 0xF8, 0x80, 0x80, 0x80 };
439 string s = utf8.GetString (data);
440 // exception is "really" expected here
444 [ExpectedException (typeof (ArgumentException))]
445 public void T3_Malformed_3_LastContinuationMissing_335 ()
447 byte[] data = { 0xFC, 0x80, 0x80, 0x80, 0x80 };
448 string s = utf8.GetString (data);
449 // exception is "really" expected here
453 // MS Fx 1.1 accept this
454 // [ExpectedException (typeof (ArgumentException))]
455 public void T3_Malformed_3_LastContinuationMissing_336 ()
457 byte[] data = { 0xDF };
459 string s = utf8.GetString (data);
460 // exception is "really" expected here
461 AssertEquals ("MS FX 1.1 behaviour", String.Empty, s);
463 catch (ArgumentException) {
464 // but Mono doesn't - better stick to the standard
469 // MS Fx 1.1 accept this
470 // [ExpectedException (typeof (ArgumentException))]
471 public void T3_Malformed_3_LastContinuationMissing_337 ()
473 byte[] data = { 0xEF, 0xBF };
475 string s = utf8.GetString (data);
476 // exception is "really" expected here
477 AssertEquals ("MS FX 1.1 behaviour", String.Empty, s);
479 catch (ArgumentException) {
480 // but Mono doesn't - better stick to the standard
485 [ExpectedException (typeof (ArgumentException))]
486 public void T3_Malformed_3_LastContinuationMissing_338 ()
488 byte[] data = { 0xF7, 0xBF, 0xBF };
489 string s = utf8.GetString (data);
490 // exception is "really" expected here
494 [ExpectedException (typeof (ArgumentException))]
495 public void T3_Malformed_3_LastContinuationMissing_339 ()
497 byte[] data = { 0xF, 0xBF, 0xBF, 0xBF };
498 string s = utf8.GetString (data);
499 // exception is "really" expected here
503 [ExpectedException (typeof (ArgumentException))]
504 public void T3_Malformed_3_LastContinuationMissing_3310 ()
506 byte[] data = { 0xFD, 0xBF, 0xBF, 0xBF, 0xBF };
507 string s = utf8.GetString (data);
508 // exception is "really" expected here
512 [ExpectedException (typeof (ArgumentException))]
513 public void T3_Malformed_4_ConcatenationImcomplete ()
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
523 [ExpectedException (typeof (ArgumentException))]
524 public void T3_Malformed_5_ImpossibleBytes_351 ()
526 byte[] data = { 0xFE };
527 string s = utf8.GetString (data);
528 // exception is "really" expected here
532 [ExpectedException (typeof (ArgumentException))]
533 public void T3_Malformed_5_ImpossibleBytes_352 ()
535 byte[] data = { 0xFF };
536 string s = utf8.GetString (data);
537 // exception is "really" expected here
541 [ExpectedException (typeof (ArgumentException))]
542 public void T3_Malformed_5_ImpossibleBytes_353 ()
544 byte[] data = { 0xFE, 0xFE, 0xFF, 0xFF };
545 string s = utf8.GetString (data);
546 // exception is "really" expected here
549 // Overlong == dangereous -> "safe" decoder should reject them
552 [ExpectedException (typeof (ArgumentException))]
553 public void T4_Overlong_1_ASCII_Slash_411 ()
555 byte[] data = { 0xC0, 0xAF };
556 string s = utf8.GetString (data);
557 // exception is "really" expected here
561 [ExpectedException (typeof (ArgumentException))]
562 public void T4_Overlong_1_ASCII_Slash_412 ()
564 byte[] data = { 0xE0, 0x80, 0xAF };
565 string s = utf8.GetString (data);
566 // exception is "really" expected here
570 [ExpectedException (typeof (ArgumentException))]
571 public void T4_Overlong_1_ASCII_Slash_413 ()
573 byte[] data = { 0xF0, 0x80, 0x80, 0xAF };
574 string s = utf8.GetString (data);
575 // exception is "really" expected here
579 [ExpectedException (typeof (ArgumentException))]
580 public void T4_Overlong_1_ASCII_Slash_414 ()
582 byte[] data = { 0xF8, 0x80, 0x80, 0x80, 0xAF };
583 string s = utf8.GetString (data);
584 // exception is "really" expected here
588 [ExpectedException (typeof (ArgumentException))]
589 public void T4_Overlong_1_ASCII_Slash_415 ()
591 byte[] data = { 0xFC, 0x80, 0x80, 0x80, 0x80, 0xAF };
592 string s = utf8.GetString (data);
593 // exception is "really" expected here
597 [ExpectedException (typeof (ArgumentException))]
598 public void T4_Overlong_2_MaximumBoundary_421 ()
600 byte[] data = { 0xC1, 0xBF };
601 string s = utf8.GetString (data);
602 // exception is "really" expected here
606 [ExpectedException (typeof (ArgumentException))]
607 public void T4_Overlong_2_MaximumBoundary_422 ()
609 byte[] data = { 0xE0, 0x9F, 0xBF };
610 string s = utf8.GetString (data);
611 // exception is "really" expected here
615 [ExpectedException (typeof (ArgumentException))]
616 public void T4_Overlong_2_MaximumBoundary_423 ()
618 byte[] data = { 0xF0, 0x8F, 0xBF, 0xBF };
619 string s = utf8.GetString (data);
620 // exception is "really" expected here
624 [ExpectedException (typeof (ArgumentException))]
625 public void T4_Overlong_2_MaximumBoundary_424 ()
627 byte[] data = { 0xF8, 0x87, 0xBF, 0xBF, 0xBF };
628 string s = utf8.GetString (data);
629 // exception is "really" expected here
633 [ExpectedException (typeof (ArgumentException))]
634 public void T4_Overlong_2_MaximumBoundary_425 ()
636 byte[] data = { 0xFC, 0x83, 0xBF, 0xBF, 0xBF, 0xBF };
637 string s = utf8.GetString (data);
638 // exception is "really" expected here
642 [ExpectedException (typeof (ArgumentException))]
643 public void T4_Overlong_3_NUL_431 ()
645 byte[] data = { 0xC0, 0x80 };
646 string s = utf8.GetString (data);
647 // exception is "really" expected here
651 [ExpectedException (typeof (ArgumentException))]
652 public void T4_Overlong_3_NUL_432 ()
654 byte[] data = { 0xE0, 0x80, 0x80 };
655 string s = utf8.GetString (data);
656 // exception is "really" expected here
660 [ExpectedException (typeof (ArgumentException))]
661 public void T4_Overlong_3_NUL_433 ()
663 byte[] data = { 0xF0, 0x80, 0x80, 0x80 };
664 string s = utf8.GetString (data);
665 // exception is "really" expected here
669 [ExpectedException (typeof (ArgumentException))]
670 public void T4_Overlong_3_NUL_434 ()
672 byte[] data = { 0xF8, 0x80, 0x80, 0x80, 0x80 };
673 string s = utf8.GetString (data);
674 // exception is "really" expected here
678 [ExpectedException (typeof (ArgumentException))]
679 public void T4_Overlong_3_NUL_435 ()
681 byte[] data = { 0xFC, 0x80, 0x80, 0x80, 0x80, 0x80 };
682 string s = utf8.GetString (data);
683 // exception is "really" expected here
687 // MS Fx 1.1 accept this
688 // [ExpectedException (typeof (ArgumentException))]
689 public void T5_IllegalCodePosition_1_UTF16Surrogates_511 ()
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]);
698 // MS Fx 1.1 accept this
699 // [ExpectedException (typeof (ArgumentException))]
700 public void T5_IllegalCodePosition_1_UTF16Surrogates_512 ()
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]);
709 // MS Fx 1.1 accept this
710 // [ExpectedException (typeof (ArgumentException))]
711 public void T5_IllegalCodePosition_1_UTF16Surrogates_513 ()
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]);
720 // MS Fx 1.1 accept this
721 // [ExpectedException (typeof (ArgumentException))]
722 public void T5_IllegalCodePosition_1_UTF16Surrogates_514 ()
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]);
731 // MS Fx 1.1 accept this
732 // [ExpectedException (typeof (ArgumentException))]
733 public void T5_IllegalCodePosition_1_UTF16Surrogates_515 ()
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]);
742 // MS Fx 1.1 accept this
743 // [ExpectedException (typeof (ArgumentException))]
744 public void T5_IllegalCodePosition_1_UTF16Surrogates_516 ()
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]);
753 // MS Fx 1.1 accept this
754 // [ExpectedException (typeof (ArgumentException))]
755 public void T5_IllegalCodePosition_1_UTF16Surrogates_517 ()
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]);
764 // MS Fx 1.1 accept this
765 // [ExpectedException (typeof (ArgumentException))]
766 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_521 ()
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]);
776 // MS Fx 1.1 accept this
777 // [ExpectedException (typeof (ArgumentException))]
778 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_522 ()
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]);
788 // MS Fx 1.1 accept this
789 // [ExpectedException (typeof (ArgumentException))]
790 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_523 ()
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]);
800 // MS Fx 1.1 accept this
801 // [ExpectedException (typeof (ArgumentException))]
802 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_524 ()
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]);
812 // MS Fx 1.1 accept this
813 // [ExpectedException (typeof (ArgumentException))]
814 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_525 ()
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]);
824 // MS Fx 1.1 accept this
825 // [ExpectedException (typeof (ArgumentException))]
826 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_526 ()
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]);
836 // MS Fx 1.1 accept this
837 // [ExpectedException (typeof (ArgumentException))]
838 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_527 ()
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]);
848 // MS Fx 1.1 accept this
849 // [ExpectedException (typeof (ArgumentException))]
850 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_528 ()
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]);
860 // MS Fx 1.1 accept this
861 // [ExpectedException (typeof (ArgumentException))]
862 public void T5_IllegalCodePosition_3_Other_531 ()
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]);
871 // MS Fx 1.1 accept this
872 // [ExpectedException (typeof (ArgumentException))]
873 public void T5_IllegalCodePosition_3_Other_532 ()
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]);