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