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;
17 using DecoderException = System.Text.DecoderFallbackException;
19 using DecoderException = System.ArgumentException;
22 namespace MonoTests.System.Text {
25 public class UTF8EncodingTest : Assertion {
27 private UTF8Encoding utf8;
32 utf8 = new UTF8Encoding (true, true);
36 public void TestEncodingGetBytes1()
38 UTF8Encoding utf8Enc = new UTF8Encoding ();
39 string UniCode = "\u0041\u2262\u0391\u002E";
41 // "A<NOT IDENTICAL TO><ALPHA>." may be encoded as 41 E2 89 A2 CE 91 2E
43 byte[] utf8Bytes = utf8Enc.GetBytes (UniCode);
45 Assertion.AssertEquals ("UTF #1", 0x41, utf8Bytes [0]);
46 Assertion.AssertEquals ("UTF #2", 0xE2, utf8Bytes [1]);
47 Assertion.AssertEquals ("UTF #3", 0x89, utf8Bytes [2]);
48 Assertion.AssertEquals ("UTF #4", 0xA2, utf8Bytes [3]);
49 Assertion.AssertEquals ("UTF #5", 0xCE, utf8Bytes [4]);
50 Assertion.AssertEquals ("UTF #6", 0x91, utf8Bytes [5]);
51 Assertion.AssertEquals ("UTF #7", 0x2E, utf8Bytes [6]);
55 public void TestEncodingGetBytes2()
57 UTF8Encoding utf8Enc = new UTF8Encoding ();
58 string UniCode = "\u0048\u0069\u0020\u004D\u006F\u006D\u0020\u263A\u0021";
60 // "Hi Mom <WHITE SMILING FACE>!" may be encoded as 48 69 20 4D 6F 6D 20 E2 98 BA 21
62 byte[] utf8Bytes = new byte [11];
64 int ByteCnt = utf8Enc.GetBytes (UniCode.ToCharArray(), 0, UniCode.Length, utf8Bytes, 0);
66 Assertion.AssertEquals ("UTF #1", 11, ByteCnt);
67 Assertion.AssertEquals ("UTF #2", 0x48, utf8Bytes [0]);
68 Assertion.AssertEquals ("UTF #3", 0x69, utf8Bytes [1]);
69 Assertion.AssertEquals ("UTF #4", 0x20, utf8Bytes [2]);
70 Assertion.AssertEquals ("UTF #5", 0x4D, utf8Bytes [3]);
71 Assertion.AssertEquals ("UTF #6", 0x6F, utf8Bytes [4]);
72 Assertion.AssertEquals ("UTF #7", 0x6D, utf8Bytes [5]);
73 Assertion.AssertEquals ("UTF #8", 0x20, utf8Bytes [6]);
74 Assertion.AssertEquals ("UTF #9", 0xE2, utf8Bytes [7]);
75 Assertion.AssertEquals ("UTF #10", 0x98, utf8Bytes [8]);
76 Assertion.AssertEquals ("UTF #11", 0xBA, utf8Bytes [9]);
77 Assertion.AssertEquals ("UTF #12", 0x21, utf8Bytes [10]);
81 public void TestDecodingGetChars1()
83 UTF8Encoding utf8Enc = new UTF8Encoding ();
84 // 41 E2 89 A2 CE 91 2E may be decoded as "A<NOT IDENTICAL TO><ALPHA>."
86 byte[] utf8Bytes = new byte [] {0x41, 0xE2, 0x89, 0xA2, 0xCE, 0x91, 0x2E};
87 char[] UniCodeChars = utf8Enc.GetChars(utf8Bytes);
89 Assertion.AssertEquals ("UTF #1", 0x0041, UniCodeChars [0]);
90 Assertion.AssertEquals ("UTF #2", 0x2262, UniCodeChars [1]);
91 Assertion.AssertEquals ("UTF #3", 0x0391, UniCodeChars [2]);
92 Assertion.AssertEquals ("UTF #4", 0x002E, UniCodeChars [3]);
97 [Category ("NotWorking")]
99 public void TestMaxCharCount()
101 UTF8Encoding UTF8enc = new UTF8Encoding ();
103 // hmm, where is this extra 1 coming from?
104 Assertion.AssertEquals ("UTF #1", 51, UTF8enc.GetMaxCharCount(50));
106 Assertion.AssertEquals ("UTF #1", 50, UTF8enc.GetMaxCharCount(50));
112 [Category ("NotWorking")]
114 public void TestMaxByteCount()
116 UTF8Encoding UTF8enc = new UTF8Encoding ();
118 // maybe under .NET 2.0 insufficient surrogate pair is just not handled, and 3 is Preamble size.
119 Assertion.AssertEquals ("UTF #1", 153, UTF8enc.GetMaxByteCount(50));
121 Assertion.AssertEquals ("UTF #1", 200, UTF8enc.GetMaxByteCount(50));
125 // regression for bug #59648
127 public void TestThrowOnInvalid ()
129 UTF8Encoding u = new UTF8Encoding (true, false);
131 byte[] data = new byte [] { 0xC0, 0xAF };
132 string s = u.GetString (data);
133 AssertEquals (0, s.Length);
135 data = new byte [] { 0x30, 0x31, 0xC0, 0xAF, 0x30, 0x32 };
136 s = u.GetString (data);
137 AssertEquals (4, s.Length);
138 AssertEquals (0x30, (int) s [0]);
139 AssertEquals (0x31, (int) s [1]);
140 AssertEquals (0x30, (int) s [2]);
141 AssertEquals (0x32, (int) s [3]);
144 // UTF8 decoding tests from http://www.cl.cam.ac.uk/~mgk25/
147 public void T1_Correct_GreekWord_kosme ()
149 byte[] data = { 0xCE, 0xBA, 0xE1, 0xBD, 0xB9, 0xCF, 0x83, 0xCE, 0xBC, 0xCE, 0xB5 };
150 string s = utf8.GetString (data);
151 // cute but saving source code in unicode can be problematic
152 // so we just ensure we can re-encode this
153 AssertEquals ("Reconverted", BitConverter.ToString (data), BitConverter.ToString (utf8.GetBytes (s)));
157 public void T2_Boundary_1_FirstPossibleSequence_Pass ()
159 byte[] data211 = { 0x00 };
160 string s = utf8.GetString (data211);
161 AssertEquals ("1 byte (U-00000000)", "\0", s);
162 AssertEquals ("Reconverted-1", BitConverter.ToString (data211), BitConverter.ToString (utf8.GetBytes (s)));
164 byte[] data212 = { 0xC2, 0x80 };
165 s = utf8.GetString (data212);
166 AssertEquals ("2 bytes (U-00000080)", 128, s [0]);
167 AssertEquals ("Reconverted-2", BitConverter.ToString (data212), BitConverter.ToString (utf8.GetBytes (s)));
169 byte[] data213 = { 0xE0, 0xA0, 0x80 };
170 s = utf8.GetString (data213);
171 AssertEquals ("3 bytes (U-00000800)", 2048, s [0]);
172 AssertEquals ("Reconverted-3", BitConverter.ToString (data213), BitConverter.ToString (utf8.GetBytes (s)));
174 byte[] data214 = { 0xF0, 0x90, 0x80, 0x80 };
175 s = utf8.GetString (data214);
176 AssertEquals ("4 bytes (U-00010000)-0", 55296, s [0]);
177 AssertEquals ("4 bytes (U-00010000)-1", 56320, s [1]);
178 AssertEquals ("Reconverted-4", BitConverter.ToString (data214), BitConverter.ToString (utf8.GetBytes (s)));
183 [ExpectedException (typeof (DecoderException))]
184 public void T2_Boundary_1_FirstPossibleSequence_Fail_5 ()
186 byte[] data215 = { 0xF8, 0x88, 0x80, 0x80, 0x80 };
187 string s = utf8.GetString (data215);
188 AssertNull ("5 bytes (U-00200000)", s);
189 AssertEquals ("Reconverted-5", BitConverter.ToString (data215), BitConverter.ToString (utf8.GetBytes (s)));
194 [ExpectedException (typeof (DecoderException))]
195 public void T2_Boundary_1_FirstPossibleSequence_Fail_6 ()
197 byte[] data216 = { 0xFC, 0x84, 0x80, 0x80, 0x80, 0x80 };
198 string s = utf8.GetString (data216);
199 AssertNull ("6 bytes (U-04000000)", s);
200 AssertEquals ("Reconverted-6", BitConverter.ToString (data216), BitConverter.ToString (utf8.GetBytes (s)));
204 public void T2_Boundary_2_LastPossibleSequence_Pass ()
206 byte[] data221 = { 0x7F };
207 string s = utf8.GetString (data221);
208 AssertEquals ("1 byte (U-0000007F)", 127, s [0]);
209 AssertEquals ("Reconverted-1", BitConverter.ToString (data221), BitConverter.ToString (utf8.GetBytes (s)));
211 byte[] data222 = { 0xDF, 0xBF };
212 s = utf8.GetString (data222);
213 AssertEquals ("2 bytes (U-000007FF)", 2047, s [0]);
214 AssertEquals ("Reconverted-2", BitConverter.ToString (data222), BitConverter.ToString (utf8.GetBytes (s)));
216 byte[] data223 = { 0xEF, 0xBF, 0xBF };
217 s = utf8.GetString (data223);
218 AssertEquals ("3 bytes (U-0000FFFF)", 65535, s [0]);
219 AssertEquals ("Reconverted-3", BitConverter.ToString (data223), BitConverter.ToString (utf8.GetBytes (s)));
225 [ExpectedException (typeof (DecoderException))]
226 public void T2_Boundary_2_LastPossibleSequence_Fail_4 ()
228 byte[] data224 = { 0x7F, 0xBF, 0xBF, 0xBF };
229 string s = utf8.GetString (data224);
230 AssertNull ("4 bytes (U-001FFFFF)", s);
231 AssertEquals ("Reconverted-4", BitConverter.ToString (data224), BitConverter.ToString (utf8.GetBytes (s)));
236 [ExpectedException (typeof (DecoderException))]
237 public void T2_Boundary_2_LastPossibleSequence_Fail_5 ()
239 byte[] data225 = { 0xFB, 0xBF, 0xBF, 0xBF, 0xBF };
240 string s = utf8.GetString (data225);
241 AssertNull ("5 bytes (U-03FFFFFF)", s);
242 AssertEquals ("Reconverted-5", BitConverter.ToString (data225), BitConverter.ToString (utf8.GetBytes (s)));
247 [ExpectedException (typeof (DecoderException))]
248 public void T2_Boundary_2_LastPossibleSequence_Fail_6 ()
250 byte[] data226 = { 0xFD, 0xBF, 0xBF, 0xBF, 0xBF, 0xBF };
251 string s = utf8.GetString (data226);
252 AssertNull ("6 bytes (U-7FFFFFFF)", s);
253 AssertEquals ("Reconverted-6", BitConverter.ToString (data226), BitConverter.ToString (utf8.GetBytes (s)));
257 public void T2_Boundary_3_Other_Pass ()
259 byte[] data231 = { 0xED, 0x9F, 0xBF };
260 string s = utf8.GetString (data231);
261 AssertEquals ("U-0000D7FF", 55295, s [0]);
262 AssertEquals ("Reconverted-1", BitConverter.ToString (data231), BitConverter.ToString (utf8.GetBytes (s)));
264 byte[] data232 = { 0xEE, 0x80, 0x80 };
265 s = utf8.GetString (data232);
266 AssertEquals ("U-0000E000", 57344, s [0]);
267 AssertEquals ("Reconverted-2", BitConverter.ToString (data232), BitConverter.ToString (utf8.GetBytes (s)));
269 byte[] data233 = { 0xEF, 0xBF, 0xBD };
270 s = utf8.GetString (data233);
271 AssertEquals ("U-0000FFFD", 65533, s [0]);
272 AssertEquals ("Reconverted-3", BitConverter.ToString (data233), BitConverter.ToString (utf8.GetBytes (s)));
274 byte[] data234 = { 0xF4, 0x8F, 0xBF, 0xBF };
275 s = utf8.GetString (data234);
276 AssertEquals ("U-0010FFFF-0", 56319, s [0]);
277 AssertEquals ("U-0010FFFF-1", 57343, s [1]);
278 AssertEquals ("Reconverted-4", BitConverter.ToString (data234), BitConverter.ToString (utf8.GetBytes (s)));
283 [ExpectedException (typeof (DecoderException))]
284 public void T2_Boundary_3_Other_Fail_5 ()
286 byte[] data235 = { 0xF4, 0x90, 0x80, 0x80 };
287 string s = utf8.GetString (data235);
288 AssertNull ("U-00110000", s);
289 AssertEquals ("Reconverted-5", BitConverter.ToString (data235), BitConverter.ToString (utf8.GetBytes (s)));
293 [ExpectedException (typeof (DecoderException))]
294 public void T3_Malformed_1_UnexpectedContinuation_311 ()
296 byte[] data = { 0x80 };
297 string s = utf8.GetString (data);
298 // exception is "really" expected here
302 [ExpectedException (typeof (DecoderException))]
303 public void T3_Malformed_1_UnexpectedContinuation_312 ()
305 byte[] data = { 0xBF };
306 string s = utf8.GetString (data);
307 // exception is "really" expected here
311 [ExpectedException (typeof (DecoderException))]
312 public void T3_Malformed_1_UnexpectedContinuation_313 ()
314 byte[] data = { 0x80, 0xBF };
315 string s = utf8.GetString (data);
316 // exception is "really" expected here
320 [ExpectedException (typeof (DecoderException))]
321 public void T3_Malformed_1_UnexpectedContinuation_314 ()
323 byte[] data = { 0x80, 0xBF, 0x80 };
324 string s = utf8.GetString (data);
325 // exception is "really" expected here
329 [ExpectedException (typeof (DecoderException))]
330 public void T3_Malformed_1_UnexpectedContinuation_315 ()
332 byte[] data = { 0x80, 0xBF, 0x80, 0xBF };
333 string s = utf8.GetString (data);
334 // exception is "really" expected here
338 [ExpectedException (typeof (DecoderException))]
339 public void T3_Malformed_1_UnexpectedContinuation_316 ()
341 byte[] data = { 0x80, 0xBF, 0x80, 0xBF, 0x80 };
342 string s = utf8.GetString (data);
343 // exception is "really" expected here
347 [ExpectedException (typeof (DecoderException))]
348 public void T3_Malformed_1_UnexpectedContinuation_317 ()
350 byte[] data = { 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF };
351 string s = utf8.GetString (data);
352 // exception is "really" expected here
356 [ExpectedException (typeof (DecoderException))]
357 public void T3_Malformed_1_UnexpectedContinuation_318 ()
359 byte[] data = { 0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF, 0x80 };
360 string s = utf8.GetString (data);
361 // exception is "really" expected here
365 [ExpectedException (typeof (DecoderException))]
366 public void T3_Malformed_1_UnexpectedContinuation_319 ()
368 // 64 different continuation characters
370 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
371 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
372 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
373 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF };
374 string s = utf8.GetString (data);
375 // exception is "really" expected here
379 [ExpectedException (typeof (DecoderException))]
380 public void T3_Malformed_2_LonelyStart_321 ()
383 0xC0, 0x20, 0xC1, 0x20, 0xC2, 0x20, 0xC3, 0x20, 0xC4, 0x20, 0xC5, 0x20, 0xC6, 0x20, 0xC7, 0x20,
384 0xC8, 0x20, 0xC9, 0x20, 0xCA, 0x20, 0xCB, 0x20, 0xCC, 0x20, 0xCD, 0x20, 0xCE, 0x20, 0xCF, 0x20,
385 0xD0, 0x20, 0xD1, 0x20, 0xD2, 0x20, 0xD3, 0x20, 0xD4, 0x20, 0xD5, 0x20, 0xD6, 0x20, 0xD7, 0x20,
386 0xD8, 0x20, 0xD9, 0x20, 0xDA, 0x20, 0xDB, 0x20, 0xDC, 0x20, 0xDD, 0x20, 0xDE, 0x20, 0xDF, 0x20 };
387 string s = utf8.GetString (data);
388 // exception is "really" expected here
392 [ExpectedException (typeof (DecoderException))]
393 public void T3_Malformed_2_LonelyStart_322 ()
396 0xE0, 0x20, 0xE1, 0x20, 0xE2, 0x20, 0xE3, 0x20, 0xE4, 0x20, 0xE5, 0x20, 0xE6, 0x20, 0xE7, 0x20,
397 0xE8, 0x20, 0xE9, 0x20, 0xEA, 0x20, 0xEB, 0x20, 0xEC, 0x20, 0xED, 0x20, 0xEE, 0x20, 0xEF, 0x20 };
398 string s = utf8.GetString (data);
399 // exception is "really" expected here
403 [ExpectedException (typeof (DecoderException))]
404 public void T3_Malformed_2_LonelyStart_323 ()
406 byte[] data = { 0xF0, 0x20, 0xF1, 0x20, 0xF2, 0x20, 0xF3, 0x20, 0xF4, 0x20, 0xF5, 0x20, 0xF6, 0x20, 0xF7, 0x20 };
407 string s = utf8.GetString (data);
408 // exception is "really" expected here
412 [ExpectedException (typeof (DecoderException))]
413 public void T3_Malformed_2_LonelyStart_324 ()
415 byte[] data = { 0xF0, 0x20, 0xF1, 0x20, 0xF2, 0x20, 0xF3, 0x20, 0xF4, 0x20, 0xF5, 0x20, 0xF6, 0x20, 0xF7, 0x20 };
416 string s = utf8.GetString (data);
417 // exception is "really" expected here
421 [ExpectedException (typeof (DecoderException))]
422 public void T3_Malformed_2_LonelyStart_325 ()
424 byte[] data = { 0xFC, 0x20, 0xFD, 0x20 };
425 string s = utf8.GetString (data);
426 // exception is "really" expected here
430 [ExpectedException (typeof (DecoderException))]
431 public void T3_Malformed_3_LastContinuationMissing_331 ()
433 byte[] data = { 0xC0 };
434 string s = utf8.GetString (data);
435 // exception is "really" expected here
439 [ExpectedException (typeof (DecoderException))]
440 public void T3_Malformed_3_LastContinuationMissing_332 ()
442 byte[] data = { 0xE0, 0x80 };
443 string s = utf8.GetString (data);
444 // exception is "really" expected here
448 [ExpectedException (typeof (DecoderException))]
449 public void T3_Malformed_3_LastContinuationMissing_333 ()
451 byte[] data = { 0xF0, 0x80, 0x80 };
452 string s = utf8.GetString (data);
453 // exception is "really" expected here
457 [ExpectedException (typeof (DecoderException))]
458 public void T3_Malformed_3_LastContinuationMissing_334 ()
460 byte[] data = { 0xF8, 0x80, 0x80, 0x80 };
461 string s = utf8.GetString (data);
462 // exception is "really" expected here
466 [ExpectedException (typeof (DecoderException))]
467 public void T3_Malformed_3_LastContinuationMissing_335 ()
469 byte[] data = { 0xFC, 0x80, 0x80, 0x80, 0x80 };
470 string s = utf8.GetString (data);
471 // exception is "really" expected here
475 // MS Fx 1.1 accept this
476 // [ExpectedException (typeof (DecoderException))]
477 public void T3_Malformed_3_LastContinuationMissing_336 ()
479 byte[] data = { 0xDF };
481 string s = utf8.GetString (data);
482 // exception is "really" expected here
483 AssertEquals ("MS FX 1.1 behaviour", String.Empty, s);
485 catch (DecoderException) {
486 // but Mono doesn't - better stick to the standard
491 // MS Fx 1.1 accept this
492 // [ExpectedException (typeof (DecoderException))]
493 public void T3_Malformed_3_LastContinuationMissing_337 ()
495 byte[] data = { 0xEF, 0xBF };
497 string s = utf8.GetString (data);
498 // exception is "really" expected here
499 AssertEquals ("MS FX 1.1 behaviour", String.Empty, s);
501 catch (DecoderException) {
502 // but Mono doesn't - better stick to the standard
507 [ExpectedException (typeof (DecoderException))]
508 public void T3_Malformed_3_LastContinuationMissing_338 ()
510 byte[] data = { 0xF7, 0xBF, 0xBF };
511 string s = utf8.GetString (data);
512 // exception is "really" expected here
516 [ExpectedException (typeof (DecoderException))]
517 public void T3_Malformed_3_LastContinuationMissing_339 ()
519 byte[] data = { 0xF, 0xBF, 0xBF, 0xBF };
520 string s = utf8.GetString (data);
521 // exception is "really" expected here
525 [ExpectedException (typeof (DecoderException))]
526 public void T3_Malformed_3_LastContinuationMissing_3310 ()
528 byte[] data = { 0xFD, 0xBF, 0xBF, 0xBF, 0xBF };
529 string s = utf8.GetString (data);
530 // exception is "really" expected here
534 [ExpectedException (typeof (DecoderException))]
535 public void T3_Malformed_4_ConcatenationImcomplete ()
538 0xC0, 0xE0, 0x80, 0xF0, 0x80, 0x80, 0xF8, 0x80, 0x80, 0x80, 0xFC, 0x80, 0x80, 0x80, 0x80, 0xDF,
539 0xEF, 0xBF, 0xF7, 0xBF, 0xBF, 0xFB, 0xBF, 0xBF, 0xBF, 0xFD, 0xBF, 0xBF, 0xBF, 0xBF };
540 string s = utf8.GetString (data);
541 // exception is "really" expected here
545 [ExpectedException (typeof (DecoderException))]
546 public void T3_Malformed_5_ImpossibleBytes_351 ()
548 byte[] data = { 0xFE };
549 string s = utf8.GetString (data);
550 // exception is "really" expected here
554 [ExpectedException (typeof (DecoderException))]
555 public void T3_Malformed_5_ImpossibleBytes_352 ()
557 byte[] data = { 0xFF };
558 string s = utf8.GetString (data);
559 // exception is "really" expected here
563 [ExpectedException (typeof (DecoderException))]
564 public void T3_Malformed_5_ImpossibleBytes_353 ()
566 byte[] data = { 0xFE, 0xFE, 0xFF, 0xFF };
567 string s = utf8.GetString (data);
568 // exception is "really" expected here
571 // Overlong == dangereous -> "safe" decoder should reject them
574 [ExpectedException (typeof (DecoderException))]
575 public void T4_Overlong_1_ASCII_Slash_411 ()
577 byte[] data = { 0xC0, 0xAF };
578 string s = utf8.GetString (data);
579 // exception is "really" expected here
583 [ExpectedException (typeof (DecoderException))]
584 public void T4_Overlong_1_ASCII_Slash_412 ()
586 byte[] data = { 0xE0, 0x80, 0xAF };
587 string s = utf8.GetString (data);
588 // exception is "really" expected here
592 [ExpectedException (typeof (DecoderException))]
593 public void T4_Overlong_1_ASCII_Slash_413 ()
595 byte[] data = { 0xF0, 0x80, 0x80, 0xAF };
596 string s = utf8.GetString (data);
597 // exception is "really" expected here
601 [ExpectedException (typeof (DecoderException))]
602 public void T4_Overlong_1_ASCII_Slash_414 ()
604 byte[] data = { 0xF8, 0x80, 0x80, 0x80, 0xAF };
605 string s = utf8.GetString (data);
606 // exception is "really" expected here
610 [ExpectedException (typeof (DecoderException))]
611 public void T4_Overlong_1_ASCII_Slash_415 ()
613 byte[] data = { 0xFC, 0x80, 0x80, 0x80, 0x80, 0xAF };
614 string s = utf8.GetString (data);
615 // exception is "really" expected here
619 [ExpectedException (typeof (DecoderException))]
620 public void T4_Overlong_2_MaximumBoundary_421 ()
622 byte[] data = { 0xC1, 0xBF };
623 string s = utf8.GetString (data);
624 // exception is "really" expected here
628 [ExpectedException (typeof (DecoderException))]
629 public void T4_Overlong_2_MaximumBoundary_422 ()
631 byte[] data = { 0xE0, 0x9F, 0xBF };
632 string s = utf8.GetString (data);
633 // exception is "really" expected here
637 [ExpectedException (typeof (DecoderException))]
638 public void T4_Overlong_2_MaximumBoundary_423 ()
640 byte[] data = { 0xF0, 0x8F, 0xBF, 0xBF };
641 string s = utf8.GetString (data);
642 // exception is "really" expected here
646 [ExpectedException (typeof (DecoderException))]
647 public void T4_Overlong_2_MaximumBoundary_424 ()
649 byte[] data = { 0xF8, 0x87, 0xBF, 0xBF, 0xBF };
650 string s = utf8.GetString (data);
651 // exception is "really" expected here
655 [ExpectedException (typeof (DecoderException))]
656 public void T4_Overlong_2_MaximumBoundary_425 ()
658 byte[] data = { 0xFC, 0x83, 0xBF, 0xBF, 0xBF, 0xBF };
659 string s = utf8.GetString (data);
660 // exception is "really" expected here
664 [ExpectedException (typeof (DecoderException))]
665 public void T4_Overlong_3_NUL_431 ()
667 byte[] data = { 0xC0, 0x80 };
668 string s = utf8.GetString (data);
669 // exception is "really" expected here
673 [ExpectedException (typeof (DecoderException))]
674 public void T4_Overlong_3_NUL_432 ()
676 byte[] data = { 0xE0, 0x80, 0x80 };
677 string s = utf8.GetString (data);
678 // exception is "really" expected here
682 [ExpectedException (typeof (DecoderException))]
683 public void T4_Overlong_3_NUL_433 ()
685 byte[] data = { 0xF0, 0x80, 0x80, 0x80 };
686 string s = utf8.GetString (data);
687 // exception is "really" expected here
691 [ExpectedException (typeof (DecoderException))]
692 public void T4_Overlong_3_NUL_434 ()
694 byte[] data = { 0xF8, 0x80, 0x80, 0x80, 0x80 };
695 string s = utf8.GetString (data);
696 // exception is "really" expected here
700 [ExpectedException (typeof (DecoderException))]
701 public void T4_Overlong_3_NUL_435 ()
703 byte[] data = { 0xFC, 0x80, 0x80, 0x80, 0x80, 0x80 };
704 string s = utf8.GetString (data);
705 // exception is "really" expected here
710 [ExpectedException (typeof (DecoderFallbackException))]
711 [Category ("NotWorking")]
713 // MS Fx 1.1 accept this
714 // [ExpectedException (typeof (DecoderException))]
715 public void T5_IllegalCodePosition_1_UTF16Surrogates_511 ()
717 byte[] data = { 0xED, 0xA0, 0x80 };
718 string s = utf8.GetString (data);
719 // exception is "really" expected here
720 AssertEquals ("MS FX 1.1 behaviour", 55296, s [0]);
725 [ExpectedException (typeof (DecoderFallbackException))]
726 [Category ("NotWorking")]
728 // MS Fx 1.1 accept this
729 // [ExpectedException (typeof (DecoderException))]
730 public void T5_IllegalCodePosition_1_UTF16Surrogates_512 ()
732 byte[] data = { 0xED, 0xAD, 0xBF };
733 string s = utf8.GetString (data);
734 // exception is "really" expected here
735 AssertEquals ("MS FX 1.1 behaviour", 56191, s [0]);
740 [ExpectedException (typeof (DecoderFallbackException))]
741 [Category ("NotWorking")]
743 // MS Fx 1.1 accept this
744 // [ExpectedException (typeof (DecoderException))]
745 public void T5_IllegalCodePosition_1_UTF16Surrogates_513 ()
747 byte[] data = { 0xED, 0xAE, 0x80 };
748 string s = utf8.GetString (data);
749 // exception is "really" expected here
750 AssertEquals ("MS FX 1.1 behaviour", 56192, s [0]);
755 [ExpectedException (typeof (DecoderFallbackException))]
756 [Category ("NotWorking")]
758 // MS Fx 1.1 accept this
759 // [ExpectedException (typeof (DecoderException))]
760 public void T5_IllegalCodePosition_1_UTF16Surrogates_514 ()
762 byte[] data = { 0xED, 0xAF, 0xBF };
763 string s = utf8.GetString (data);
764 // exception is "really" expected here
765 AssertEquals ("MS FX 1.1 behaviour", 56319, s [0]);
770 [ExpectedException (typeof (DecoderFallbackException))]
771 [Category ("NotWorking")]
773 // MS Fx 1.1 accept this
774 // [ExpectedException (typeof (DecoderException))]
775 public void T5_IllegalCodePosition_1_UTF16Surrogates_515 ()
777 byte[] data = { 0xED, 0xB0, 0x80 };
778 string s = utf8.GetString (data);
779 // exception is "really" expected here
780 AssertEquals ("MS FX 1.1 behaviour", 56320, s [0]);
785 [ExpectedException (typeof (DecoderFallbackException))]
786 [Category ("NotWorking")]
788 // MS Fx 1.1 accept this
789 // [ExpectedException (typeof (DecoderException))]
790 public void T5_IllegalCodePosition_1_UTF16Surrogates_516 ()
792 byte[] data = { 0xED, 0xBE, 0x80 };
793 string s = utf8.GetString (data);
794 // exception is "really" expected here
795 AssertEquals ("MS FX 1.1 behaviour", 57216, s [0]);
800 [ExpectedException (typeof (DecoderFallbackException))]
801 [Category ("NotWorking")]
803 // MS Fx 1.1 accept this
804 // [ExpectedException (typeof (DecoderException))]
805 public void T5_IllegalCodePosition_1_UTF16Surrogates_517 ()
807 byte[] data = { 0xED, 0xBF, 0xBF };
808 string s = utf8.GetString (data);
809 // exception is "really" expected here
810 AssertEquals ("MS FX 1.1 behaviour", 57343, s [0]);
815 [ExpectedException (typeof (DecoderFallbackException))]
816 [Category ("NotWorking")]
818 // MS Fx 1.1 accept this
819 // [ExpectedException (typeof (DecoderException))]
820 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_521 ()
822 byte[] data = { 0xED, 0xA0, 0x80, 0xED, 0xB0, 0x80 };
823 string s = utf8.GetString (data);
824 // exception is "really" expected here
825 AssertEquals ("MS FX 1.1 behaviour", 55296, s [0]);
826 AssertEquals ("MS FX 1.1 behaviour", 56320, s [1]);
831 [ExpectedException (typeof (DecoderFallbackException))]
832 [Category ("NotWorking")]
834 // MS Fx 1.1 accept this
835 // [ExpectedException (typeof (DecoderException))]
836 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_522 ()
838 byte[] data = { 0xED, 0xA0, 0x80, 0xED, 0xBF, 0xBF };
839 string s = utf8.GetString (data);
840 // exception is "really" expected here
841 AssertEquals ("MS FX 1.1 behaviour", 55296, s [0]);
842 AssertEquals ("MS FX 1.1 behaviour", 57343, s [1]);
847 [ExpectedException (typeof (DecoderFallbackException))]
848 [Category ("NotWorking")]
850 // MS Fx 1.1 accept this
851 // [ExpectedException (typeof (DecoderException))]
852 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_523 ()
854 byte[] data = { 0xED, 0xAD, 0xBF, 0xED, 0xB0, 0x80 };
855 string s = utf8.GetString (data);
856 // exception is "really" expected here
857 AssertEquals ("MS FX 1.1 behaviour", 56191, s [0]);
858 AssertEquals ("MS FX 1.1 behaviour", 56320, s [1]);
863 [ExpectedException (typeof (DecoderFallbackException))]
864 [Category ("NotWorking")]
866 // MS Fx 1.1 accept this
867 // [ExpectedException (typeof (DecoderException))]
868 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_524 ()
870 byte[] data = { 0xED, 0xAD, 0xBF, 0xED, 0xBF, 0xBF };
871 string s = utf8.GetString (data);
872 // exception is "really" expected here
873 AssertEquals ("MS FX 1.1 behaviour", 56191, s [0]);
874 AssertEquals ("MS FX 1.1 behaviour", 57343, s [1]);
879 [ExpectedException (typeof (DecoderFallbackException))]
880 [Category ("NotWorking")]
882 // MS Fx 1.1 accept this
883 // [ExpectedException (typeof (DecoderException))]
884 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_525 ()
886 byte[] data = { 0xED, 0xAE, 0x80, 0xED, 0xB0, 0x80 };
887 string s = utf8.GetString (data);
888 // exception is "really" expected here
889 AssertEquals ("MS FX 1.1 behaviour", 56192, s [0]);
890 AssertEquals ("MS FX 1.1 behaviour", 56320, s [1]);
895 [ExpectedException (typeof (DecoderFallbackException))]
896 [Category ("NotWorking")]
898 // MS Fx 1.1 accept this
899 // [ExpectedException (typeof (DecoderException))]
900 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_526 ()
902 byte[] data = { 0xED, 0xAE, 0x80, 0xED, 0xBF, 0x8F };
903 string s = utf8.GetString (data);
904 // exception is "really" expected here
905 AssertEquals ("MS FX 1.1 behaviour", 56192, s [0]);
906 AssertEquals ("MS FX 1.1 behaviour", 57295, s [1]);
911 [ExpectedException (typeof (DecoderFallbackException))]
912 [Category ("NotWorking")]
914 // MS Fx 1.1 accept this
915 // [ExpectedException (typeof (DecoderException))]
916 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_527 ()
918 byte[] data = { 0xED, 0xAF, 0xBF, 0xED, 0xB0, 0x80 };
919 string s = utf8.GetString (data);
920 // exception is "really" expected here
921 AssertEquals ("MS FX 1.1 behaviour", 56319, s [0]);
922 AssertEquals ("MS FX 1.1 behaviour", 56320, s [1]);
927 [ExpectedException (typeof (DecoderFallbackException))]
928 [Category ("NotWorking")]
930 // MS Fx 1.1 accept this
931 // [ExpectedException (typeof (DecoderException))]
932 public void T5_IllegalCodePosition_2_PairedUTF16Surrogates_528 ()
934 byte[] data = { 0xED, 0xAF, 0xBF, 0xED, 0xBF, 0xBF };
935 string s = utf8.GetString (data);
936 // exception is "really" expected here
937 AssertEquals ("MS FX 1.1 behaviour", 56319, s [0]);
938 AssertEquals ("MS FX 1.1 behaviour", 57343, s [1]);
942 // MS Fx 1.1 accept this
943 // [ExpectedException (typeof (DecoderException))]
944 public void T5_IllegalCodePosition_3_Other_531 ()
946 byte[] data = { 0xEF, 0xBF, 0xBE };
947 string s = utf8.GetString (data);
948 // exception is "really" expected here
949 AssertEquals ("MS FX 1.1 behaviour", 65534, s [0]);
953 // MS Fx 1.1 accept this
954 // [ExpectedException (typeof (DecoderException))]
955 public void T5_IllegalCodePosition_3_Other_532 ()
957 byte[] data = { 0xEF, 0xBF, 0xBF };
958 string s = utf8.GetString (data);
959 // exception is "really" expected here
960 AssertEquals ("MS FX 1.1 behaviour", 65535, s [0]);
964 // bug #75065 and #73086.
965 public void GetCharsFEFF ()
967 byte [] data = new byte [] {0xEF, 0xBB, 0xBF};
968 Encoding enc = new UTF8Encoding (false, true);
969 string s = enc.GetString (data);
970 AssertEquals ("\uFEFF", s);
972 Encoding utf = Encoding.UTF8;
973 char[] testChars = {'\uFEFF','A'};
975 byte[] bytes = utf.GetBytes(testChars);
976 char[] chars = utf.GetChars(bytes);
977 AssertEquals ("#1", '\uFEFF', chars [0]);
978 AssertEquals ("#2", 'A', chars [1]);