1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*/
#include "common/encoding.h"
#include "common/system.h"
#include "engines/testbed/encoding.h"
namespace Testbed {
TestExitStatus Encodingtests::testConversionUnicodeMachineEndian() {
Testsuite::displayMessage("Encoding conversion tests.\nTo test iconv conversion, compile with --enable-iconv.\nTo test backend conversion, compile with --disable-iconv.\nSome tests may fail without iconv, because some backends support only a handful of conversions.");
Common::String info = "Unicode conversion test. Multiple conversions between UTF-8, UTF-16 and UTF-32 in the default machinge endian will be performed.";
Common::Point pt(0, 100);
Testsuite::writeOnScreen("Testing unicode conversion in machine native endianness.", pt);
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
Testsuite::logPrintf("Info! Skipping test : testConversionUnicodeMachineEndian\n");
return kTestSkipped;
}
// |dolar| cent | euro |
unsigned char utf8[] = {0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0};
#ifdef SCUMM_BIG_ENDIAN
//| dolar | cent | euro |
unsigned char utf16be[] = {0, 0x24, 0, 0xA2, 0x20, 0xAC, 0, 0};
//| dolar | cent | euro
unsigned char utf32be[] = {0, 0, 0, 0x24, 0, 0, 0, 0xA2, 0, 0, 0x20, 0xAC, 0, 0, 0, 0};
unsigned char *utf16 = utf16be;
unsigned char *utf32 = utf32be;
#else
//| dolar | cent | euro |
unsigned char utf16le[] = {0x24, 0, 0xA2, 0, 0xAC, 0x20, 0, 0};
//| dolar | cent | euro
unsigned char utf32le[] = {0x24, 0, 0, 0, 0xA2, 0, 0, 0, 0xAC, 0x20, 0, 0, 0, 0, 0, 0};
unsigned char *utf16 = utf16le;
unsigned char *utf32 = utf32le;
#endif
// UTF16 to UTF8
Common::Encoding converter("UTF-8", "UTF-16");
char *result = converter.convert((char *) utf16, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-16 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 7)) {
Testsuite::logPrintf("UTF-16 to UTF-8 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-8", "UTF-16", (char *) utf16, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-16 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 7)) {
Testsuite::logPrintf("UTF-16 to UTF-8 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF32 to UTF8
converter.setFrom("UTF-32");
result = converter.convert((char *) utf32, 12);
if (result == NULL) {
Testsuite::logPrintf("UTF-32 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 7)) {
Testsuite::logPrintf("UTF-32 to UTF-8 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-8", "UTF-32", (char *) utf32, 12);
if (result == NULL) {
Testsuite::logPrintf("UTF-32 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 7)) {
Testsuite::logPrintf("UTF-32 to UTF-8 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF32 to UTF16
converter.setTo("UTF-16");
result = converter.convert((char *) utf32, 12);
if (result == NULL) {
Testsuite::logPrintf("UTF-32 to UTF-16 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf16, 8)) {
Testsuite::logPrintf("UTF-32 to UTF-16 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-16", "UTF-32", (char *) utf32, 12);
if (result == NULL) {
Testsuite::logPrintf("UTF-32 to UTF-16 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf16, 8)) {
Testsuite::logPrintf("UTF-32 to UTF-16 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF8 to UTF16
converter.setFrom("UTF-8");
result = converter.convert((char *) utf8, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to UTF-16 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf16, 8)) {
Testsuite::logPrintf("UTF-8 to UTF-16 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-16", "UTF-8", (char *) utf8, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to UTF-16 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf16, 8)) {
Testsuite::logPrintf("UTF-8 to UTF-16 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF8 to UTF32
converter.setTo("UTF-32");
result = converter.convert((char *) utf8, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to UTF-32 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf32, 16)) {
Testsuite::logPrintf("UTF-8 to UTF-32 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-32", "UTF-8", (char *) utf8, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to UTF-32 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf32, 16)) {
Testsuite::logPrintf("UTF-8 to UTF-32 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF16 to UTF32
converter.setFrom("UTF-16");
result = converter.convert((char *) utf16, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-16 to UTF-32 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf32, 16)) {
Testsuite::logPrintf("UTF-16 to UTF-32 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-32", "UTF-16", (char *) utf16, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-16 to UTF-32 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf32, 16)) {
Testsuite::logPrintf("UTF-16 to UTF-32 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
return kTestPassed;
}
TestExitStatus Encodingtests::testConversionUnicodeBigEndian() {
Common::String info = "Unicode conversion test. Multiple conversions between UTF-8, UTF-16 and UTF-32 in big endian will be performed.";
Common::Point pt(0, 100);
Testsuite::writeOnScreen("Testing unicode conversion in big endian.", pt);
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
Testsuite::logPrintf("Info! Skipping test : testConversionUnicodeBigEndian\n");
return kTestSkipped;
}
// |dolar| cent | euro |
unsigned char utf8[] = {0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0};
//| dolar | cent | euro |
unsigned char utf16be[] = {0, 0x24, 0, 0xA2, 0x20, 0xAC, 0, 0};
//| dolar | cent | euro
unsigned char utf32be[] = {0, 0, 0, 0x24, 0, 0, 0, 0xA2, 0, 0, 0x20, 0xAC, 0, 0, 0, 0};
// UTF16 to UTF8
Common::Encoding converter("UTF-8", "UTF-16BE");
char *result = converter.convert((char *) utf16be, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-16 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 7)) {
Testsuite::logPrintf("UTF-16 to UTF-8 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-8", "UTF-16BE", (char *) utf16be, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-16 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 7)) {
Testsuite::logPrintf("UTF-16 to UTF-8 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF32 to UTF8
converter.setFrom("UTF-32BE");
result = converter.convert((char *) utf32be, 12);
if (result == NULL) {
Testsuite::logPrintf("UTF-32 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 7)) {
Testsuite::logPrintf("UTF-32 to UTF-8 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-8", "UTF-32BE", (char *) utf32be, 12);
if (result == NULL) {
Testsuite::logPrintf("UTF-32 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 7)) {
Testsuite::logPrintf("UTF-32 to UTF-8 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF32 to UTF16
converter.setTo("UTF-16BE");
result = converter.convert((char *) utf32be, 12);
if (result == NULL) {
Testsuite::logPrintf("UTF-32 to UTF-16 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf16be, 8)) {
Testsuite::logPrintf("UTF-32 to UTF-16 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-16BE", "UTF-32BE", (char *) utf32be, 12);
if (result == NULL) {
Testsuite::logPrintf("UTF-32 to UTF-16 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf16be, 8)) {
Testsuite::logPrintf("UTF-32 to UTF-16 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF8 to UTF16
converter.setFrom("UTF-8");
result = converter.convert((char *) utf8, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to UTF-16 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf16be, 8)) {
Testsuite::logPrintf("UTF-8 to UTF-16 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-16BE", "UTF-8", (char *) utf8, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to UTF-16 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf16be, 8)) {
Testsuite::logPrintf("UTF-8 to UTF-16 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF8 to UTF32
converter.setTo("UTF-32BE");
result = converter.convert((char *) utf8, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to UTF-32 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf32be, 16)) {
Testsuite::logPrintf("UTF-8 to UTF-32 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-32BE", "UTF-8", (char *) utf8, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to UTF-32 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf32be, 16)) {
Testsuite::logPrintf("UTF-8 to UTF-32 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF16 to UTF32
converter.setFrom("UTF-16BE");
result = converter.convert((char *) utf16be, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-16 to UTF-32 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf32be, 16)) {
Testsuite::logPrintf("UTF-16 to UTF-32 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-32BE", "UTF-16BE", (char *) utf16be, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-16 to UTF-32 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf32be, 16)) {
Testsuite::logPrintf("UTF-16 to UTF-32 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
return kTestPassed;
}
TestExitStatus Encodingtests::testConversionUnicodeLittleEndian() {
Common::String info = "Unicode conversion test. Multiple conversions between UTF-8, UTF-16 and UTF-32 in little endian will be performed.";
Common::Point pt(0, 100);
Testsuite::writeOnScreen("Testing unicode conversion in little endianness.", pt);
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
Testsuite::logPrintf("Info! Skipping test : testConversionUnicodeLittleEndian\n");
return kTestSkipped;
}
// |dolar| cent | euro |
unsigned char utf8[] = {0x24, 0xC2, 0xA2, 0xE2, 0x82, 0xAC, 0};
//| dolar | cent | euro |
unsigned char utf16le[] = {0x24, 0, 0xA2, 0, 0xAC, 0x20, 0, 0};
//| dolar | cent | euro
unsigned char utf32le[] = {0x24, 0, 0, 0, 0xA2, 0, 0, 0, 0xAC, 0x20, 0, 0, 0, 0, 0, 0};
// UTF16 to UTF8
Common::Encoding converter("UTF-8", "UTF-16LE");
char *result = converter.convert((char *) utf16le, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-16 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 7)) {
Testsuite::logPrintf("UTF-16 to UTF-8 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-8", "UTF-16LE", (char *) utf16le, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-16 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 7)) {
Testsuite::logPrintf("UTF-16 to UTF-8 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF32 to UTF8
converter.setFrom("UTF-32LE");
result = converter.convert((char *) utf32le, 12);
if (result == NULL) {
Testsuite::logPrintf("UTF-32 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 7)) {
Testsuite::logPrintf("UTF-32 to UTF-8 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-8", "UTF-32LE", (char *) utf32le, 12);
if (result == NULL) {
Testsuite::logPrintf("UTF-32 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 7)) {
Testsuite::logPrintf("UTF-32 to UTF-8 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF32 to UTF16
converter.setTo("UTF-16LE");
result = converter.convert((char *) utf32le, 12);
if (result == NULL) {
Testsuite::logPrintf("UTF-32 to UTF-16 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf16le, 8)) {
Testsuite::logPrintf("UTF-32 to UTF-16 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-16LE", "UTF-32LE", (char *) utf32le, 12);
if (result == NULL) {
Testsuite::logPrintf("UTF-32 to UTF-16 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf16le, 8)) {
Testsuite::logPrintf("UTF-32 to UTF-16 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF8 to UTF16
converter.setFrom("UTF-8");
result = converter.convert((char *) utf8, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to UTF-16 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf16le, 8)) {
Testsuite::logPrintf("UTF-8 to UTF-16 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-16LE", "UTF-8", (char *) utf8, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to UTF-16 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf16le, 8)) {
Testsuite::logPrintf("UTF-8 to UTF-16 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF8 to UTF32
converter.setTo("UTF-32LE");
result = converter.convert((char *) utf8, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to UTF-32 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf32le, 16)) {
Testsuite::logPrintf("UTF-8 to UTF-32 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-32LE", "UTF-8", (char *) utf8, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to UTF-32 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf32le, 16)) {
Testsuite::logPrintf("UTF-8 to UTF-32 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// UTF16 to UTF32
converter.setFrom("UTF-16LE");
result = converter.convert((char *) utf16le, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-16 to UTF-32 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf32le, 16)) {
Testsuite::logPrintf("UTF-16 to UTF-32 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-32LE", "UTF-16LE", (char *) utf16le, 6);
if (result == NULL) {
Testsuite::logPrintf("UTF-16 to UTF-32 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf32le, 16)) {
Testsuite::logPrintf("UTF-16 to UTF-32 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
return kTestPassed;
}
TestExitStatus Encodingtests::testCyrillicTransliteration() {
Common::String info = "Cyrillic transliteration test. Multiple conversions between unicode, iso-8859-5 and ASCII will be performed.";
Common::Point pt(0, 100);
Testsuite::writeOnScreen("Testing Cyrillic transliteration", pt);
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
Testsuite::logPrintf("Info! Skipping test : testCyrillicTransliteration\n");
return kTestSkipped;
}
unsigned char utf8[] = {/* Z */0xD0, 0x97, /* d */ 0xD0, 0xB4, /* r */ 0xD1, 0x80, /* a */ 0xD0, 0xB0, /* v */ 0xD0, 0xB2, /* s */ 0xD1, 0x81, /* t */ 0xD1, 0x82, /* v */ 0xD0, 0xB2, /* u */ 0xD1, 0x83, /* j */ 0xD0, 0xB9, /* t */ 0xD1, 0x82, /* e */ 0xD0, 0xB5, 0};
unsigned char iso_8859_5[] = {0xB7, 0xD4, 0xE0, 0xD0, 0xD2, 0xE1, 0xE2, 0xD2, 0xE3, 0xD9, 0xE2, 0xD5, 0};
unsigned char ascii[] = "Zdravstvujte";
Common::Encoding converter("ASCII", "UTF-8");
char *result = converter.convert((char *)utf8, 24);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to ASCII conversion isn't available");
return kTestFailed;
}
if (memcmp(result, ascii, 13)) {
Testsuite::logPrintf("UTF-8 to ASCII conversion isn'differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
converter.setFrom("iso-8859-5");
result = converter.convert((char *)iso_8859_5, 12);
if (result == NULL) {
Testsuite::logPrintf("iso-8859-5 to ASCII conversion isn't available");
return kTestFailed;
}
if (memcmp(result, ascii, 13)) {
Testsuite::logPrintf("iso-8859-5 to ASCII conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
converter.setTo("UTF-8");
result = converter.convert((char *)iso_8859_5, 12);
if (result == NULL) {
Testsuite::logPrintf("iso-8859-5 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8, 25)) {
Testsuite::logPrintf("iso-8859-5 to UTF-differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
converter.setTo("iso-8859-5");
converter.setFrom("UTF-8");
result = converter.convert((char *)utf8, 24);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to iso-8859-5 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, iso_8859_5, 13)) {
Testsuite::logPrintf("UTF-8 to iso-8859-differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
// this should stay the same
converter.setFrom("ASCII");
result = converter.convert((char *)ascii, 12);
if (result == NULL) {
Testsuite::logPrintf("ASCII to iso-8859-5 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, ascii, 13)) {
Testsuite::logPrintf("ASCII to iso-8859-5 conversion differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
return kTestPassed;
}
TestExitStatus Encodingtests::testOtherConversions() {
Common::String info = "Other conversions test. Some regular encoding conversions will be performed.";
Common::Point pt(0, 100);
Testsuite::writeOnScreen("Testing other encoding conversions", pt);
if (Testsuite::handleInteractiveInput(info, "OK", "Skip", kOptionRight)) {
Testsuite::logPrintf("Info! Skipping test : testOtherConversions\n");
return kTestSkipped;
}
unsigned char cp850[] = {0x99, 0xE0, 0xEA, 0x41, 0x64, 0};
unsigned char utf8_1[] = {0xC3, 0x96, 0xC3, 0x93, 0xC3, 0x9B, 0x41, 0x64, 0};
unsigned char iso_8859_2[] = {0xA9, 0xE1, 0x6C, 0x65, 0xE8, 0x65, 0x6B, 0};
unsigned char utf8_2[] = {0xC5, 0xA0, 0xC3, 0xA1, 0x6C, 0x65, 0xC4, 0x8D, 0x65, 0x6B, 0};
char *result = Common::Encoding::convert("UTF-8", "CP850", (char *)cp850, 5);
if (result == NULL) {
Testsuite::logPrintf("CP850 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8_1, 9)) {
Testsuite::logPrintf("CP850 to UTF-8 conversion isn'differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("CP850", "UTF-8", (char *)utf8_1, 8);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to CP850 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, cp850, 6)) {
Testsuite::logPrintf("UTF-8 to CP850 conversion isn'differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("UTF-8", "iso-8859-2", (char *)iso_8859_2, 7);
if (result == NULL) {
Testsuite::logPrintf("iso-8859-2 to UTF-8 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, utf8_2, 11)) {
Testsuite::logPrintf("iso-8859-2 to UTF-differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
result = Common::Encoding::convert("iso-8859-2", "UTF-8", (char *)utf8_2, 11);
if (result == NULL) {
Testsuite::logPrintf("UTF-8 to iso-8859-2 conversion isn't available");
return kTestFailed;
}
if (memcmp(result, iso_8859_2, 8)) {
Testsuite::logPrintf("UTF-8 to iso-8859-differs from the expected result.");
free(result);
return kTestFailed;
}
free(result);
return kTestPassed;
}
EncodingTestSuite::EncodingTestSuite() {
addTest("testConversionUnicodeMachineEndian", &Encodingtests::testConversionUnicodeMachineEndian, true);
addTest("testConversionUnicodeBigEndian", &Encodingtests::testConversionUnicodeBigEndian, true);
addTest("testConversionUnicodeLittleEndian", &Encodingtests::testConversionUnicodeLittleEndian, true);
addTest("testCyrillicTransliteration", &Encodingtests::testCyrillicTransliteration, true);
addTest("testOtherConversions", &Encodingtests::testOtherConversions, true);
}
} // End of namespace Testbed
|