| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
using System; |
| 11 |
using System.IO; |
| 12 |
using System.Text; |
| 13 |
using NUnit.Framework; |
| 14 |
|
| 15 |
using MonoTests.Helpers; |
| 16 |
|
| 17 |
namespace MonoTests.I18N.CJK |
| 18 |
{ |
| 19 |
[TestFixture] |
| 20 |
public class TestCJK |
| 21 |
{ |
| 22 |
private global::I18N.Common.Manager Manager = global::I18N.Common.Manager.PrimaryManager; |
| 23 |
|
| 24 |
void AssertEncode (string utf8file, string decfile, int codepage) |
| 25 |
{ |
| 26 |
string decoded = null; |
| 27 |
byte [] encoded = null; |
| 28 |
using (StreamReader sr = new StreamReader (utf8file, |
| 29 |
Encoding.UTF8)) { |
| 30 |
decoded = sr.ReadToEnd (); |
| 31 |
} |
| 32 |
using (FileStream fs = File.OpenRead (decfile)) { |
| 33 |
encoded = new byte [fs.Length]; |
| 34 |
fs.Read (encoded, 0, (int) fs.Length); |
| 35 |
} |
| 36 |
Encoding enc = Manager.GetEncoding (codepage); |
| 37 |
byte [] actual; |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
actual = enc.GetBytes (decoded); |
| 44 |
Assert.AreEqual (encoded, actual, |
| 45 |
"GetBytes(string)"); |
| 46 |
|
| 47 |
|
| 48 |
Assert.AreEqual (encoded.Length, |
| 49 |
enc.GetByteCount (decoded.ToCharArray (), 0, decoded.Length), |
| 50 |
"GetByteCount(char[], 0, len)"); |
| 51 |
actual = enc.GetBytes (decoded.ToCharArray (), 0, decoded.Length); |
| 52 |
Assert.AreEqual (encoded, actual, |
| 53 |
"GetBytes(char[], 0, len)"); |
| 54 |
} |
| 55 |
|
| 56 |
void AssertDecode (string utf8file, string decfile, int codepage) |
| 57 |
{ |
| 58 |
string decoded = null; |
| 59 |
byte [] encoded = null; |
| 60 |
using (StreamReader sr = new StreamReader (utf8file, |
| 61 |
Encoding.UTF8)) { |
| 62 |
decoded = sr.ReadToEnd (); |
| 63 |
} |
| 64 |
using (FileStream fs = File.OpenRead (decfile)) { |
| 65 |
encoded = new byte [fs.Length]; |
| 66 |
fs.Read (encoded, 0, (int) fs.Length); |
| 67 |
} |
| 68 |
Encoding enc = Manager.GetEncoding (codepage); |
| 69 |
char [] actual; |
| 70 |
|
| 71 |
Assert.AreEqual (decoded.Length, |
| 72 |
enc.GetCharCount (encoded, 0, encoded.Length), |
| 73 |
"GetCharCount(byte[], 0, len)"); |
| 74 |
actual = enc.GetChars (encoded, 0, encoded.Length); |
| 75 |
Assert.AreEqual (decoded.ToCharArray (), actual, |
| 76 |
"GetChars(byte[], 0, len)"); |
| 77 |
} |
| 78 |
|
| 79 |
#region Chinese |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
[Test] |
| 84 |
public void CP936_Encode () |
| 85 |
{ |
| 86 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese-936.txt"), 936); |
| 87 |
} |
| 88 |
|
| 89 |
[Test] |
| 90 |
public void CP936_Encode3 () |
| 91 |
{ |
| 92 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese3-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese3-936.txt"), 936); |
| 93 |
} |
| 94 |
|
| 95 |
[Test] |
| 96 |
public void CP936_Decode () |
| 97 |
{ |
| 98 |
AssertDecode (TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese-936.txt"), 936); |
| 99 |
} |
| 100 |
|
| 101 |
[Test] |
| 102 |
public void Bug_1531() |
| 103 |
{ |
| 104 |
string str = @"wqk="; |
| 105 |
byte[] utf8 = Convert.FromBase64String(str); |
| 106 |
char[] data = Encoding.UTF8.GetChars(utf8); |
| 107 |
|
| 108 |
var encoding = Manager.GetEncoding("GB2312"); |
| 109 |
var result = encoding.GetBytes(data); |
| 110 |
|
| 111 |
Assert.AreEqual(new byte[] { 63 }, result); |
| 112 |
} |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
[Test] |
| 117 |
public void CP950_Encode () |
| 118 |
{ |
| 119 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese2-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese2-950.txt"), 950); |
| 120 |
} |
| 121 |
|
| 122 |
[Test] |
| 123 |
public void CP950_Encode4 () |
| 124 |
{ |
| 125 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese4-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese4-950.txt"), 950); |
| 126 |
} |
| 127 |
|
| 128 |
[Test] |
| 129 |
public void CP950_Decode () |
| 130 |
{ |
| 131 |
AssertDecode (TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese2-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese2-950.txt"), 950); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
[Test] |
| 137 |
public void CP54936_Encode () |
| 138 |
{ |
| 139 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese-54936.txt"), 54936); |
| 140 |
} |
| 141 |
|
| 142 |
[Test] |
| 143 |
public void CP54936_Decode () |
| 144 |
{ |
| 145 |
AssertDecode (TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/chinese-54936.txt"), 54936); |
| 146 |
} |
| 147 |
|
| 148 |
#endregion |
| 149 |
|
| 150 |
#region Japanese |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
[Test] |
| 155 |
public void CP932_Encode () |
| 156 |
{ |
| 157 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-932.txt"), 932); |
| 158 |
} |
| 159 |
|
| 160 |
[Test] |
| 161 |
public void CP932_Decode () |
| 162 |
{ |
| 163 |
AssertDecode (TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-932.txt"), 932); |
| 164 |
} |
| 165 |
|
| 166 |
[Test] |
| 167 |
public void Bug28321 () |
| 168 |
{ |
| 169 |
var expected = "\u00D7\u00B4\u00B1\u00F7\u00B6\u00B0\u00A8\u00A7"; |
| 170 |
var text = Manager.GetEncoding ("shift_jis").GetString (Convert.FromBase64String ("gX6BTIF9gYCB94GLgU6BmA==")); |
| 171 |
|
| 172 |
Assert.AreEqual (expected, text); |
| 173 |
} |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
[Test] |
| 178 |
public void CP51932_Encode () |
| 179 |
{ |
| 180 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-51932.txt"), 51932); |
| 181 |
} |
| 182 |
|
| 183 |
[Test] |
| 184 |
public void CP51932_Decode () |
| 185 |
{ |
| 186 |
AssertDecode (TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-51932.txt"), 51932); |
| 187 |
} |
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
[Test] |
| 192 |
public void CP50220_Encode () |
| 193 |
{ |
| 194 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese2-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese2-50220.txt"), 50220); |
| 195 |
} |
| 196 |
|
| 197 |
[Test] |
| 198 |
public void CP50220_Encode_3 () |
| 199 |
{ |
| 200 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese3-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese3-50220.txt"), 50220); |
| 201 |
} |
| 202 |
|
| 203 |
[Test] |
| 204 |
public void CP50220_Decode () |
| 205 |
{ |
| 206 |
AssertDecode (TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese2-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese2-50220.txt"), 50220); |
| 207 |
} |
| 208 |
|
| 209 |
[Test] |
| 210 |
public void CP50221_Encode () |
| 211 |
{ |
| 212 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-50221.txt"), 50221); |
| 213 |
} |
| 214 |
|
| 215 |
[Test] |
| 216 |
public void CP50221_Encode_3() |
| 217 |
{ |
| 218 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese3-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese3-50221.txt"), 50221); |
| 219 |
} |
| 220 |
|
| 221 |
[Test] |
| 222 |
public void CP50221_Decode () |
| 223 |
{ |
| 224 |
AssertDecode (TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-50221.txt"), 50221); |
| 225 |
} |
| 226 |
|
| 227 |
[Test] |
| 228 |
public void CP50222_Encode () |
| 229 |
{ |
| 230 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-50222.txt"), 50222); |
| 231 |
} |
| 232 |
|
| 233 |
[Test] |
| 234 |
public void CP50222_Decode () |
| 235 |
{ |
| 236 |
AssertDecode (TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/japanese-50222.txt"), 50222); |
| 237 |
} |
| 238 |
|
| 239 |
[Test] |
| 240 |
public void CP50220BrokenESC () |
| 241 |
{ |
| 242 |
Assert.AreEqual ("\u001B$0", Manager.GetEncoding (50220).GetString (new byte [] {0x1B, 0x24, 0x30}), "#1"); |
| 243 |
} |
| 244 |
|
| 245 |
[Test] |
| 246 |
public void CP50220BrokenESC2 () |
| 247 |
{ |
| 248 |
|
| 249 |
Assert.AreEqual ("\u001B$0", Encoding.GetEncoding (50220, new EncoderReplacementFallback (), new DecoderReplacementFallback ("")).GetString (new byte [] {0x1B, 0x24, 0x30}), "#1"); |
| 250 |
} |
| 251 |
|
| 252 |
[Test] |
| 253 |
public void CP50220BrokenESC3 () |
| 254 |
{ |
| 255 |
|
| 256 |
Assert.AreEqual ("\u001B$0", Encoding.GetEncoding (50220, new EncoderExceptionFallback (), new DecoderExceptionFallback ()).GetString (new byte [] {0x1B, 0x24, 0x30}), "#2"); |
| 257 |
} |
| 258 |
|
| 259 |
[Test] |
| 260 |
public void Bug77723 () |
| 261 |
{ |
| 262 |
GetBytesAllSingleChars (51932); |
| 263 |
} |
| 264 |
|
| 265 |
[Test] |
| 266 |
public void Bug77724 () |
| 267 |
{ |
| 268 |
GetBytesAllSingleChars (932); |
| 269 |
} |
| 270 |
|
| 271 |
[Test] |
| 272 |
public void Bug77307 () |
| 273 |
{ |
| 274 |
GetBytesAllSingleChars (54936); |
| 275 |
} |
| 276 |
|
| 277 |
void GetBytesAllSingleChars (int enc) |
| 278 |
{ |
| 279 |
Encoding e = Manager.GetEncoding (enc); |
| 280 |
for (int i = 0; i < 0x10000; i++) |
| 281 |
e.GetBytes (new char [] { (char)i }); |
| 282 |
} |
| 283 |
|
| 284 |
void GetCharsAllBytePairs (int enc) |
| 285 |
{ |
| 286 |
Encoding e = Manager.GetEncoding (enc); |
| 287 |
byte [] bytes = new byte [2]; |
| 288 |
for (int i0 = 0; i0 < 0x100; i0++) { |
| 289 |
bytes [0] = (byte) i0; |
| 290 |
for (int i1 = 0; i1 < 0x100; i1++) { |
| 291 |
bytes [1] = (byte) i1; |
| 292 |
e.GetChars (bytes); |
| 293 |
} |
| 294 |
} |
| 295 |
} |
| 296 |
|
| 297 |
[Test] |
| 298 |
public void Bug77222 () |
| 299 |
{ |
| 300 |
GetCharsAllBytePairs (51932); |
| 301 |
} |
| 302 |
|
| 303 |
[Test] |
| 304 |
public void Bug77238 () |
| 305 |
{ |
| 306 |
GetCharsAllBytePairs (936); |
| 307 |
} |
| 308 |
|
| 309 |
[Test] |
| 310 |
public void Bug77306 () |
| 311 |
{ |
| 312 |
GetCharsAllBytePairs (54936); |
| 313 |
} |
| 314 |
|
| 315 |
[Test] |
| 316 |
public void Bug77298 () |
| 317 |
{ |
| 318 |
GetCharsAllBytePairs (949); |
| 319 |
} |
| 320 |
|
| 321 |
[Test] |
| 322 |
public void Bug77274 () |
| 323 |
{ |
| 324 |
GetCharsAllBytePairs (950); |
| 325 |
} |
| 326 |
|
| 327 |
[Test] |
| 328 |
public void Encoder54936Refresh () |
| 329 |
{ |
| 330 |
Encoding e = Manager.GetEncoding ("gb18030"); |
| 331 |
Encoder d = e.GetEncoder (); |
| 332 |
byte [] bytes; |
| 333 |
|
| 334 |
bytes = new byte [4]; |
| 335 |
Assert.AreEqual (0, d.GetBytes (new char [] {'\uD800'}, 0, 1, bytes, 0, false), "#1"); |
| 336 |
Assert.AreEqual (new byte [] {00, 00, 00, 00}, |
| 337 |
bytes, "#2"); |
| 338 |
|
| 339 |
bytes = new byte [4]; |
| 340 |
Assert.AreEqual (4, d.GetBytes (new char [] {'\uDC00'}, 0, 1, bytes, 0, true), "#3"); |
| 341 |
Assert.AreEqual (new byte [] {0x90, 0x30, 0x81, 0x30}, |
| 342 |
bytes, "#4"); |
| 343 |
|
| 344 |
bytes = new byte [4]; |
| 345 |
Assert.AreEqual (1, d.GetBytes (new char [] {'\uD800'}, 0, 1, bytes, 0, true), "#5"); |
| 346 |
Assert.AreEqual (new byte [] {0x3F, 00, 00, 00}, |
| 347 |
bytes, "#6"); |
| 348 |
} |
| 349 |
|
| 350 |
[Test] |
| 351 |
public void Bug491799 () |
| 352 |
{ |
| 353 |
Assert.AreEqual (new byte [] {0xEE, 0xFC}, |
| 354 |
Manager.GetEncoding (932).GetBytes ("\uFF02")); |
| 355 |
} |
| 356 |
|
| 357 |
[Test] |
| 358 |
public void Decoder932Refresh () |
| 359 |
{ |
| 360 |
Encoding e = Manager.GetEncoding (932); |
| 361 |
Decoder d = e.GetDecoder (); |
| 362 |
char [] chars; |
| 363 |
|
| 364 |
chars = new char [1]; |
| 365 |
Assert.AreEqual (0, d.GetChars (new byte [] {0x81}, 0, 1, chars, 0, false), "#1"); |
| 366 |
Assert.AreEqual (new char [] {'\0'}, chars, "#2"); |
| 367 |
|
| 368 |
chars = new char [1]; |
| 369 |
Assert.AreEqual (1, d.GetChars (new byte [] {0x81}, 0, 1, chars, 0, true), "#3"); |
| 370 |
Assert.AreEqual (new char [] {'\uFF1D'}, chars, "#4"); |
| 371 |
|
| 372 |
chars = new char [1]; |
| 373 |
Assert.AreEqual (1, d.GetChars (new byte [] {0x81}, 0, 1, chars, 0, true), "#5"); |
| 374 |
Assert.AreEqual (new char [] {'\u30FB'}, chars, "#6"); |
| 375 |
} |
| 376 |
|
| 377 |
[Test] |
| 378 |
public void Decoder51932Refresh () |
| 379 |
{ |
| 380 |
Encoding e = Manager.GetEncoding (51932); |
| 381 |
Decoder d = e.GetDecoder (); |
| 382 |
char [] chars; |
| 383 |
|
| 384 |
|
| 385 |
chars = new char [1]; |
| 386 |
Assert.AreEqual (1, d.GetChars (new byte [] {0x81}, 0, 1, chars, 0, false), "#0.1"); |
| 387 |
Assert.AreEqual (new char [] {'\u30FB'}, chars, "#0.2"); |
| 388 |
|
| 389 |
|
| 390 |
chars = new char [1]; |
| 391 |
Assert.AreEqual (0, d.GetChars (new byte [] {0xA1}, 0, 1, chars, 0, false), "#1"); |
| 392 |
Assert.AreEqual (new char [] {'\0'}, chars, "#2"); |
| 393 |
|
| 394 |
|
| 395 |
chars = new char [1]; |
| 396 |
Assert.AreEqual (1, d.GetChars (new byte [] {0xA1}, 0, 1, chars, 0, true), "#3"); |
| 397 |
Assert.AreEqual (new char [] {'\u3000'}, chars, "#4"); |
| 398 |
|
| 399 |
|
| 400 |
chars = new char [1]; |
| 401 |
Assert.AreEqual (1, d.GetChars (new byte [] {0xA1}, 0, 1, chars, 0, true), "#5"); |
| 402 |
Assert.AreEqual (new char [] {'\u30FB'}, chars, "#6"); |
| 403 |
} |
| 404 |
|
| 405 |
[Test] |
| 406 |
public void Decoder936Refresh () |
| 407 |
{ |
| 408 |
Encoding e = Manager.GetEncoding (936); |
| 409 |
Decoder d = e.GetDecoder (); |
| 410 |
char [] chars; |
| 411 |
|
| 412 |
|
| 413 |
chars = new char [1]; |
| 414 |
Assert.AreEqual (0, d.GetChars (new byte [] {0xB0}, 0, 1, chars, 0, false), "#1"); |
| 415 |
Assert.AreEqual (new char [] {'\0'}, chars, "#2"); |
| 416 |
|
| 417 |
|
| 418 |
chars = new char [1]; |
| 419 |
Assert.AreEqual (1, d.GetChars (new byte [] {0xA1}, 0, 1, chars, 0, false), "#3"); |
| 420 |
Assert.AreEqual (new char [] {'\u554A'}, chars, "#4"); |
| 421 |
|
| 422 |
|
| 423 |
chars = new char [1]; |
| 424 |
Assert.AreEqual (1, d.GetChars (new byte [] {0xB0}, 0, 1, chars, 0, true), "#5"); |
| 425 |
Assert.AreEqual (new char [] {'?'}, chars, "#6"); |
| 426 |
} |
| 427 |
|
| 428 |
[Test] |
| 429 |
public void Decoder949Refresh () |
| 430 |
{ |
| 431 |
Encoding e = Manager.GetEncoding (949); |
| 432 |
Decoder d = e.GetDecoder (); |
| 433 |
char [] chars; |
| 434 |
|
| 435 |
|
| 436 |
chars = new char [1]; |
| 437 |
Assert.AreEqual (0, d.GetChars (new byte [] {0x81}, 0, 1, chars, 0, false), "#1"); |
| 438 |
Assert.AreEqual (new char [] {'\0'}, chars, "#2"); |
| 439 |
|
| 440 |
|
| 441 |
chars = new char [1]; |
| 442 |
Assert.AreEqual (1, d.GetChars (new byte [] {0x41}, 0, 1, chars, 0, false), "#3"); |
| 443 |
Assert.AreEqual (new char [] {'\uAC02'}, chars, "#4"); |
| 444 |
|
| 445 |
|
| 446 |
chars = new char [1]; |
| 447 |
Assert.AreEqual (1, d.GetChars (new byte [] {0x81}, 0, 1, chars, 0, true), "#5"); |
| 448 |
Assert.AreEqual (new char [] {'?'}, chars, "#6"); |
| 449 |
} |
| 450 |
|
| 451 |
[Test] |
| 452 |
public void Decoder950Refresh () |
| 453 |
{ |
| 454 |
Encoding e = Manager.GetEncoding (950); |
| 455 |
Decoder d = e.GetDecoder (); |
| 456 |
char [] chars; |
| 457 |
|
| 458 |
|
| 459 |
chars = new char [1]; |
| 460 |
Assert.AreEqual (0, d.GetChars (new byte [] {0xF9}, 0, 1, chars, 0, false), "#1"); |
| 461 |
Assert.AreEqual (new char [] {'\0'}, chars, "#2"); |
| 462 |
|
| 463 |
|
| 464 |
chars = new char [1]; |
| 465 |
Assert.AreEqual (1, d.GetChars (new byte [] {0x40}, 0, 1, chars, 0, false), "#3"); |
| 466 |
Assert.AreEqual (new char [] {'\u7E98'}, chars, "#4"); |
| 467 |
|
| 468 |
|
| 469 |
chars = new char [1]; |
| 470 |
Assert.AreEqual (1, d.GetChars (new byte [] {0xF9}, 0, 1, chars, 0, true), "#5"); |
| 471 |
Assert.AreEqual (new char [] {'?'}, chars, "#6"); |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
[Test] |
| 476 |
public void Decoder51932NoRefresh () |
| 477 |
{ |
| 478 |
Encoding e = Manager.GetEncoding (51932); |
| 479 |
Decoder d = e.GetDecoder (); |
| 480 |
char [] chars; |
| 481 |
|
| 482 |
|
| 483 |
chars = new char [1]; |
| 484 |
Assert.AreEqual (0, d.GetChars (new byte [] {0xA1}, 0, 1, chars, 0), "#1"); |
| 485 |
Assert.AreEqual (new char [] {'\0'}, chars, "#2"); |
| 486 |
|
| 487 |
|
| 488 |
chars = new char [1]; |
| 489 |
Assert.AreEqual (1, d.GetChars (new byte [] {0xA1}, 0, 1, chars, 0), "#3"); |
| 490 |
Assert.AreEqual (new char [] {'\u3000'}, chars, "#4"); |
| 491 |
|
| 492 |
|
| 493 |
chars = new char [1]; |
| 494 |
Assert.AreEqual (0, d.GetChars (new byte [] {0xA1}, 0, 1, chars, 0), "#5"); |
| 495 |
Assert.AreEqual (new char [] {'\0'}, chars, "#6"); |
| 496 |
} |
| 497 |
|
| 498 |
[Test] |
| 499 |
public void Decoder936NoRefresh () |
| 500 |
{ |
| 501 |
Encoding e = Manager.GetEncoding (936); |
| 502 |
Decoder d = e.GetDecoder (); |
| 503 |
char [] chars; |
| 504 |
|
| 505 |
|
| 506 |
chars = new char [1]; |
| 507 |
Assert.AreEqual (0, d.GetChars (new byte [] {0xB0}, 0, 1, chars, 0), "#1"); |
| 508 |
Assert.AreEqual (new char [] {'\0'}, chars, "#2"); |
| 509 |
|
| 510 |
|
| 511 |
chars = new char [1]; |
| 512 |
Assert.AreEqual (1, d.GetChars (new byte [] {0xA1}, 0, 1, chars, 0), "#3"); |
| 513 |
Assert.AreEqual (new char [] {'\u554A'}, chars, "#4"); |
| 514 |
|
| 515 |
|
| 516 |
chars = new char [1]; |
| 517 |
Assert.AreEqual (0, d.GetChars (new byte [] {0xB0}, 0, 1, chars, 0), "#5"); |
| 518 |
Assert.AreEqual (new char [] {'\0'}, chars, "#6"); |
| 519 |
} |
| 520 |
|
| 521 |
[Test] |
| 522 |
public void Decoder949NoRefresh () |
| 523 |
{ |
| 524 |
Encoding e = Manager.GetEncoding (949); |
| 525 |
Decoder d = e.GetDecoder (); |
| 526 |
char [] chars; |
| 527 |
|
| 528 |
|
| 529 |
chars = new char [1]; |
| 530 |
Assert.AreEqual (0, d.GetChars (new byte [] {0x81}, 0, 1, chars, 0), "#1"); |
| 531 |
Assert.AreEqual (new char [] {'\0'}, chars, "#2"); |
| 532 |
|
| 533 |
|
| 534 |
chars = new char [1]; |
| 535 |
Assert.AreEqual (1, d.GetChars (new byte [] {0x41}, 0, 1, chars, 0), "#3"); |
| 536 |
Assert.AreEqual (new char [] {'\uAC02'}, chars, "#4"); |
| 537 |
|
| 538 |
|
| 539 |
chars = new char [1]; |
| 540 |
Assert.AreEqual (0, d.GetChars (new byte [] {0x81}, 0, 1, chars, 0), "#5"); |
| 541 |
Assert.AreEqual (new char [] {'\0'}, chars, "#6"); |
| 542 |
} |
| 543 |
|
| 544 |
[Test] |
| 545 |
public void Decoder950NoRefresh () |
| 546 |
{ |
| 547 |
Encoding e = Manager.GetEncoding (950); |
| 548 |
Decoder d = e.GetDecoder (); |
| 549 |
char [] chars; |
| 550 |
|
| 551 |
|
| 552 |
chars = new char [1]; |
| 553 |
Assert.AreEqual (0, d.GetChars (new byte [] {0xF9}, 0, 1, chars, 0), "#1"); |
| 554 |
Assert.AreEqual (new char [] {'\0'}, chars, "#2"); |
| 555 |
|
| 556 |
|
| 557 |
chars = new char [1]; |
| 558 |
Assert.AreEqual (1, d.GetChars (new byte [] {0x40}, 0, 1, chars, 0), "#3"); |
| 559 |
Assert.AreEqual (new char [] {'\u7E98'}, chars, "#4"); |
| 560 |
|
| 561 |
|
| 562 |
chars = new char [1]; |
| 563 |
Assert.AreEqual (0, d.GetChars (new byte [] {0xF9}, 0, 1, chars, 0), "#5"); |
| 564 |
Assert.AreEqual (new char [] {'\0'}, chars, "#6"); |
| 565 |
} |
| 566 |
|
| 567 |
[Test] |
| 568 |
public void HandleObsoletedESCJ () |
| 569 |
{ |
| 570 |
byte [] b = new byte [] {0x64, 0x6f, 0x6e, 0x1b, 0x24, 0x42, 0x21, 0x47, 0x1b, 0x28, 0x4a, 0x74}; |
| 571 |
string s = Manager.GetEncoding ("ISO-2022-JP").GetString (b); |
| 572 |
Assert.AreEqual ("don\u2019t", s); |
| 573 |
|
| 574 |
} |
| 575 |
|
| 576 |
[Test] |
| 577 |
public void Bug14591 () |
| 578 |
{ |
| 579 |
var expected = "\u4f50\u85e4\u8c4a"; |
| 580 |
var text = Encoding.GetEncoding ("iso-2022-jp").GetString (Convert.FromBase64String ("GyRAOjRGI0stGyhK")); |
| 581 |
Assert.AreEqual (expected, text, "#1"); |
| 582 |
} |
| 583 |
#endregion |
| 584 |
|
| 585 |
#region Korean |
| 586 |
|
| 587 |
[Test] |
| 588 |
public void CP949_Encode () |
| 589 |
{ |
| 590 |
AssertEncode (TestResourceHelper.GetFullPathOfResource ("Test/texts/korean-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/korean-949.txt"), 949); |
| 591 |
} |
| 592 |
|
| 593 |
[Test] |
| 594 |
public void CP949_Decode () |
| 595 |
{ |
| 596 |
AssertDecode (TestResourceHelper.GetFullPathOfResource ("Test/texts/korean-utf8.txt"), TestResourceHelper.GetFullPathOfResource ("Test/texts/korean-949.txt"), 949); |
| 597 |
} |
| 598 |
|
| 599 |
#endregion |
| 600 |
|
| 601 |
[Test] |
| 602 |
public void Bug13144 () |
| 603 |
{ |
| 604 |
var encoding = Encoding.GetEncoding ("GB18030"); |
| 605 |
var str = encoding.GetString (new byte[] { 0x84, 0x32, 0x81, 0x30 }); |
| 606 |
Assert.AreEqual ("?", str); |
| 607 |
} |
| 608 |
} |
| 609 |
} |