1 /* 2 * Copyright 2011, Oliver Tappe, zooey@hirschkaefer.de 3 * Distributed under the terms of the MIT License. 4 */ 5 6 #define __USE_GNU 7 // for wmempcpy() and wcschrnul() 8 9 #include <errno.h> 10 #include <locale.h> 11 #include <stdio.h> 12 #include <stdlib.h> 13 #include <string.h> 14 #include <time.h> 15 #include <wchar.h> 16 17 18 static int sign (int a) 19 { 20 if (a < 0) 21 return -1; 22 if (a > 0) 23 return 1; 24 return 0; 25 } 26 27 28 // #pragma mark - wcslen ------------------------------------------------------- 29 30 31 void 32 test_wcslen() 33 { 34 printf("wcslen()/wcsnlen()\n"); 35 36 int problemCount = 0; 37 errno = 0; 38 39 { 40 const wchar_t* string = L""; 41 size_t result = wcslen(string); 42 size_t expected = 0; 43 if (result != expected || errno != 0) { 44 printf("\tPROBLEM: result for wcslen(\"%ls\") = %lu (expected %lu)," 45 " errno = %x (expected %x)\n", string, result, expected, 46 errno, 0); 47 problemCount++; 48 } 49 } 50 51 { 52 const wchar_t* string = L"test"; 53 size_t result = wcslen(string); 54 size_t expected = 4; 55 if (result != expected || errno != 0) { 56 printf("\tPROBLEM: result for wcslen(\"%ls\") = %lu (expected %lu)," 57 " errno = %x (expected %x)\n", string, result, expected, 58 errno, 0); 59 problemCount++; 60 } 61 } 62 63 { 64 const wchar_t* string = L"t\xE4st"; 65 size_t result = wcslen(string); 66 size_t expected = 4; 67 if (result != expected || errno != 0) { 68 printf("\tPROBLEM: result for wcslen(\"%ls\") = %lu (expected %lu)," 69 " errno = %x (expected %x)\n", string, result, expected, 70 errno, 0); 71 problemCount++; 72 } 73 } 74 75 { 76 const wchar_t* string = L"te\x00st"; 77 size_t result = wcslen(string); 78 size_t expected = 2; 79 if (result != expected || errno != 0) { 80 printf("\tPROBLEM: result for wcslen(\"%ls\") = %lu (expected %lu)," 81 " errno = %x (expected %x)\n", string, result, expected, 82 errno, 0); 83 problemCount++; 84 } 85 } 86 87 { 88 const wchar_t* string = L"test"; 89 size_t result = wcsnlen(string, 0); 90 size_t expected = 0; 91 if (result != expected || errno != 0) { 92 printf("\tPROBLEM: result for wcsnlen(\"%ls\", 0) = %lu " 93 "(expected %lu), errno = %x (expected %x)\n", 94 string, result, expected, errno, 0); 95 problemCount++; 96 } 97 } 98 99 { 100 const wchar_t* string = L"test"; 101 size_t result = wcsnlen(string, 4); 102 size_t expected = 4; 103 if (result != expected || errno != 0) { 104 printf("\tPROBLEM: result for wcsnlen(\"%ls\", 4) = %lu " 105 "(expected %lu), errno = %x (expected %x)\n", 106 string, result, expected, errno, 0); 107 problemCount++; 108 } 109 } 110 111 { 112 const wchar_t* string = L"test"; 113 size_t result = wcsnlen(string, 6); 114 size_t expected = 4; 115 if (result != expected || errno != 0) { 116 printf("\tPROBLEM: result for wcsnlen(\"%ls\", 6) = %lu " 117 "(expected %lu), errno = %x (expected %x)\n", 118 string, result, expected, errno, 0); 119 problemCount++; 120 } 121 } 122 123 if (problemCount) 124 printf("\t%d problem(s) found!\n", problemCount); 125 else 126 printf("\tall fine\n"); 127 } 128 129 130 // #pragma mark - wcscmp ------------------------------------------------------- 131 132 133 void 134 test_wcscmp() 135 { 136 printf("wcscmp()/wcsncmp()\n"); 137 138 int problemCount = 0; 139 errno = 0; 140 141 { 142 const wchar_t* a = L""; 143 const wchar_t* b = L""; 144 int result = sign(wcscmp(a, b)); 145 int expected = 0; 146 if (result != expected || errno != 0) { 147 printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 148 "(expected %d), errno = %x (expected 0)\n", a, b, result, 149 expected, errno); 150 problemCount++; 151 } 152 } 153 154 { 155 const wchar_t* a = L"a"; 156 const wchar_t* b = L"b"; 157 int result = sign(wcscmp(a, b)); 158 int expected = -1; 159 if (result != expected || errno != 0) { 160 printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 161 "(expected %d), errno = %x (expected 0)\n", a, b, result, 162 expected, errno); 163 problemCount++; 164 } 165 } 166 167 { 168 const wchar_t* a = L"b"; 169 const wchar_t* b = L"a"; 170 int result = sign(wcscmp(a, b)); 171 int expected = 1; 172 if (result != expected || errno != 0) { 173 printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 174 "(expected %d), errno = %x (expected 0)\n", a, b, result, 175 expected, errno); 176 problemCount++; 177 } 178 } 179 180 { 181 const wchar_t* a = L"a"; 182 const wchar_t* b = L"A"; 183 int result = sign(wcscmp(a, b)); 184 int expected = 1; 185 if (result != expected || errno != 0) { 186 printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 187 "(expected %d), errno = %x (expected 0)\n", a, b, result, 188 expected, errno); 189 problemCount++; 190 } 191 } 192 193 { 194 const wchar_t* a = L"täst"; 195 const wchar_t* b = L"täst"; 196 int result = sign(wcscmp(a, b)); 197 int expected = 0; 198 if (result != expected || errno != 0) { 199 printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 200 "(expected %d), errno = %x (expected 0)\n", a, b, result, 201 expected, errno); 202 problemCount++; 203 } 204 } 205 206 { 207 const wchar_t* a = L"täst"; 208 const wchar_t* b = L"täst "; 209 int result = sign(wcscmp(a, b)); 210 int expected = -1; 211 if (result != expected || errno != 0) { 212 printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 213 "(expected %d), errno = %x (expected 0)\n", a, b, result, 214 expected, errno); 215 problemCount++; 216 } 217 } 218 219 { 220 const wchar_t* a = L"täSt"; 221 const wchar_t* b = L"täs"; 222 int result = sign(wcscmp(a, b)); 223 int expected = -1; 224 if (result != expected || errno != 0) { 225 printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 226 "(expected %d), errno = %x (expected 0)\n", a, b, result, 227 expected, errno); 228 problemCount++; 229 } 230 } 231 232 { 233 const wchar_t* a = L"täst1"; 234 const wchar_t* b = L"täst0"; 235 int result = sign(wcsncmp(a, b, 0)); 236 int expected = 0; 237 if (result != expected || errno != 0) { 238 printf("\tPROBLEM: result for wcsncmp(\"%ls\", \"%ls\", 0) = %d " 239 "(expected %d), errno = %x (expected 0)\n", a, b, result, 240 expected, errno); 241 problemCount++; 242 } 243 } 244 245 { 246 const wchar_t* a = L"täst1"; 247 const wchar_t* b = L"täst0"; 248 int result = sign(wcsncmp(a, b, 4)); 249 int expected = 0; 250 if (result != expected || errno != 0) { 251 printf("\tPROBLEM: result for wcsncmp(\"%ls\", \"%ls\", 4) = %d " 252 "(expected %d), errno = %x (expected 0)\n", a, b, result, 253 expected, errno); 254 problemCount++; 255 } 256 } 257 258 { 259 const wchar_t* a = L"täst1"; 260 const wchar_t* b = L"täst0"; 261 int result = sign(wcsncmp(a, b, 5)); 262 int expected = 1; 263 if (result != expected || errno != 0) { 264 printf("\tPROBLEM: result for wcsncmp(\"%ls\", \"%ls\", 5) = %d " 265 "(expected %d), errno = %x (expected 0)\n", a, b, result, 266 expected, errno); 267 problemCount++; 268 } 269 } 270 271 { 272 const wchar_t* a = L"täs"; 273 const wchar_t* b = L"täst123"; 274 int result = sign(wcsncmp(a, b, (size_t)-1)); 275 int expected = -1; 276 if (result != expected || errno != 0) { 277 printf("\tPROBLEM: result for wcsncmp(\"%ls\", \"%ls\", -1) = %d " 278 "(expected %d), errno = %x (expected 0)\n", a, b, result, 279 expected, errno); 280 problemCount++; 281 } 282 } 283 284 if (problemCount) 285 printf("\t%d problem(s) found!\n", problemCount); 286 else 287 printf("\tall fine\n"); 288 } 289 290 291 // #pragma mark - wcscasecmp --------------------------------------------------- 292 293 294 void 295 test_wcscasecmp() 296 { 297 printf("wcscasecmp()/wcsncasecmp()\n"); 298 299 int problemCount = 0; 300 errno = 0; 301 302 { 303 const wchar_t* a = L""; 304 const wchar_t* b = L""; 305 int result = sign(wcscasecmp(a, b)); 306 int expected = 0; 307 if (result != expected || errno != 0) { 308 printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 309 "(expected %d), errno = %x (expected 0)\n", a, b, result, 310 expected, errno); 311 problemCount++; 312 } 313 } 314 315 { 316 const wchar_t* a = L"a"; 317 const wchar_t* b = L"b"; 318 int result = sign(wcscasecmp(a, b)); 319 int expected = -1; 320 if (result != expected || errno != 0) { 321 printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 322 "(expected %d), errno = %x (expected 0)\n", a, b, result, 323 expected, errno); 324 problemCount++; 325 } 326 } 327 328 { 329 const wchar_t* a = L"B"; 330 const wchar_t* b = L"a"; 331 int result = sign(wcscasecmp(a, b)); 332 int expected = 1; 333 if (result != expected || errno != 0) { 334 printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 335 "(expected %d), errno = %x (expected 0)\n", a, b, result, 336 expected, errno); 337 problemCount++; 338 } 339 } 340 341 { 342 const wchar_t* a = L"a"; 343 const wchar_t* b = L"A"; 344 int result = sign(wcscasecmp(a, b)); 345 int expected = 0; 346 if (result != expected || errno != 0) { 347 printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 348 "(expected %d), errno = %x (expected 0)\n", a, b, result, 349 expected, errno); 350 problemCount++; 351 } 352 } 353 354 { 355 const wchar_t* a = L"TÄST"; 356 const wchar_t* b = L"täst"; 357 int result = sign(wcscasecmp(a, b)); 358 int expected = 0; 359 if (result != expected || errno != 0) { 360 printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 361 "(expected %d), errno = %x (expected 0)\n", a, b, result, 362 expected, errno); 363 problemCount++; 364 } 365 } 366 367 { 368 const wchar_t* a = L"tÄst"; 369 const wchar_t* b = L"täst "; 370 int result = sign(wcscasecmp(a, b)); 371 int expected = -1; 372 if (result != expected || errno != 0) { 373 printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 374 "(expected %d), errno = %x (expected 0)\n", a, b, result, 375 expected, errno); 376 problemCount++; 377 } 378 } 379 380 { 381 const wchar_t* a = L"TäSt"; 382 const wchar_t* b = L"täs"; 383 int result = sign(wcscasecmp(a, b)); 384 int expected = 1; 385 if (result != expected || errno != 0) { 386 printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 387 "(expected %d), errno = %x (expected 0)\n", a, b, result, 388 expected, errno); 389 problemCount++; 390 } 391 } 392 393 { 394 const wchar_t* a = L"tÄst1"; 395 const wchar_t* b = L"täst0"; 396 int result = sign(wcsncasecmp(a, b, 0)); 397 int expected = 0; 398 if (result != expected || errno != 0) { 399 printf("\tPROBLEM: result for wcscasencmp(\"%ls\", \"%ls\", 0) = %d" 400 " (expected %d), errno = %x (expected 0)\n", a, b, result, 401 expected, errno); 402 problemCount++; 403 } 404 } 405 406 { 407 const wchar_t* a = L"täst1"; 408 const wchar_t* b = L"täSt0"; 409 int result = sign(wcsncasecmp(a, b, 4)); 410 int expected = 0; 411 if (result != expected || errno != 0) { 412 printf("\tPROBLEM: result for wcsncasecmp(\"%ls\", \"%ls\", 4) = %d" 413 " (expected %d), errno = %x (expected 0)\n", a, b, result, 414 expected, errno); 415 problemCount++; 416 } 417 } 418 419 { 420 const wchar_t* a = L"täsT1"; 421 const wchar_t* b = L"täst0"; 422 int result = sign(wcsncasecmp(a, b, 5)); 423 int expected = 1; 424 if (result != expected || errno != 0) { 425 printf("\tPROBLEM: result for wcsncasecmp(\"%ls\", \"%ls\", 5) = %d" 426 " (expected %d), errno = %x (expected 0)\n", a, b, result, 427 expected, errno); 428 problemCount++; 429 } 430 } 431 432 { 433 const wchar_t* a = L"täs"; 434 const wchar_t* b = L"täSt123"; 435 int result = sign(wcsncasecmp(a, b, (size_t)-1)); 436 int expected = -1; 437 if (result != expected || errno != 0) { 438 printf("\tPROBLEM: result for wcsncasecmp(\"%ls\", \"%ls\", -1) = " 439 "%d (expected %d), errno = %x (expected 0)\n", a, b, result, 440 expected, errno); 441 problemCount++; 442 } 443 } 444 445 if (problemCount) 446 printf("\t%d problem(s) found!\n", problemCount); 447 else 448 printf("\tall fine\n"); 449 } 450 451 452 // #pragma mark - wcschr ------------------------------------------------------- 453 454 455 void 456 test_wcschr() 457 { 458 printf("wcschr()/wcschrnul()/wcsrchr()\n"); 459 460 int problemCount = 0; 461 errno = 0; 462 463 { 464 const wchar_t* string = L""; 465 const wchar_t ch = L' '; 466 const wchar_t* result = wcschr(string, ch); 467 const wchar_t* expected = NULL; 468 if (result != expected || errno != 0) { 469 printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 470 "(expected %p), errno = %x (expected 0)\n", string, ch, 471 result, expected, errno); 472 problemCount++; 473 } 474 } 475 476 { 477 const wchar_t* string = L""; 478 const wchar_t ch = L'\0'; 479 const wchar_t* result = wcschr(string, ch); 480 const wchar_t* expected = string; 481 if (result != expected || errno != 0) { 482 printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 483 "(expected %p), errno = %x (expected 0)\n", string, ch, 484 result, expected, errno); 485 problemCount++; 486 } 487 } 488 489 { 490 const wchar_t* string = L"sometext"; 491 const wchar_t ch = L' '; 492 const wchar_t* result = wcschr(string, ch); 493 const wchar_t* expected = NULL; 494 if (result != expected || errno != 0) { 495 printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 496 "(expected %p), errno = %x (expected 0)\n", string, ch, 497 result, expected, errno); 498 problemCount++; 499 } 500 } 501 502 { 503 const wchar_t* string = L"some more text"; 504 const wchar_t ch = L' '; 505 const wchar_t* result = wcschr(string, ch); 506 const wchar_t* expected = string + 4; 507 if (result != expected || errno != 0) { 508 printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 509 "(expected %p), errno = %x (expected 0)\n", string, ch, 510 result, expected, errno); 511 problemCount++; 512 } 513 } 514 515 { 516 const wchar_t* string = L"some more text"; 517 const wchar_t ch = L's'; 518 const wchar_t* result = wcschr(string, ch); 519 const wchar_t* expected = string; 520 if (result != expected || errno != 0) { 521 printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 522 "(expected %p), errno = %x (expected 0)\n", string, ch, 523 result, expected, errno); 524 problemCount++; 525 } 526 } 527 528 { 529 const wchar_t* string = L"some more text"; 530 const wchar_t ch = L'S'; 531 const wchar_t* result = wcschr(string, ch); 532 const wchar_t* expected = NULL; 533 if (result != expected || errno != 0) { 534 printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 535 "(expected %p), errno = %x (expected 0)\n", string, ch, 536 result, expected, errno); 537 problemCount++; 538 } 539 } 540 541 { 542 const wchar_t* string = L"some more text"; 543 const wchar_t ch = L'\0'; 544 const wchar_t* result = wcschr(string, ch); 545 const wchar_t* expected = string + 14; 546 if (result != expected || errno != 0) { 547 printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 548 "(expected %p), errno = %x (expected 0)\n", string, ch, 549 result, expected, errno); 550 problemCount++; 551 } 552 } 553 554 { 555 const wchar_t* string = L""; 556 const wchar_t ch = L' '; 557 const wchar_t* result = wcschrnul(string, ch); 558 const wchar_t* expected = string; 559 if (result != expected || errno != 0) { 560 printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 561 "(expected %p), errno = %x (expected 0)\n", string, ch, 562 result, expected, errno); 563 problemCount++; 564 } 565 } 566 567 { 568 const wchar_t* string = L""; 569 const wchar_t ch = L'\0'; 570 const wchar_t* result = wcschrnul(string, ch); 571 const wchar_t* expected = string; 572 if (result != expected || errno != 0) { 573 printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 574 "(expected %p), errno = %x (expected 0)\n", string, ch, 575 result, expected, errno); 576 problemCount++; 577 } 578 } 579 580 { 581 const wchar_t* string = L"sometext"; 582 const wchar_t ch = L' '; 583 const wchar_t* result = wcschrnul(string, ch); 584 const wchar_t* expected = string + wcslen(string); 585 if (result != expected || errno != 0) { 586 printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 587 "(expected %p), errno = %x (expected 0)\n", string, ch, 588 result, expected, errno); 589 problemCount++; 590 } 591 } 592 593 { 594 const wchar_t* string = L"some more text"; 595 const wchar_t ch = L' '; 596 const wchar_t* result = wcschrnul(string, ch); 597 const wchar_t* expected = string + 4; 598 if (result != expected || errno != 0) { 599 printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 600 "(expected %p), errno = %x (expected 0)\n", string, ch, 601 result, expected, errno); 602 problemCount++; 603 } 604 } 605 606 { 607 const wchar_t* string = L"some more text"; 608 const wchar_t ch = L's'; 609 const wchar_t* result = wcschrnul(string, ch); 610 const wchar_t* expected = string; 611 if (result != expected || errno != 0) { 612 printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 613 "(expected %p), errno = %x (expected 0)\n", string, ch, 614 result, expected, errno); 615 problemCount++; 616 } 617 } 618 619 { 620 const wchar_t* string = L"some more text"; 621 const wchar_t ch = L'S'; 622 const wchar_t* result = wcschrnul(string, ch); 623 const wchar_t* expected = string + wcslen(string); 624 if (result != expected || errno != 0) { 625 printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 626 "(expected %p), errno = %x (expected 0)\n", string, ch, 627 result, expected, errno); 628 problemCount++; 629 } 630 } 631 632 { 633 const wchar_t* string = L"some more text"; 634 const wchar_t ch = L'\0'; 635 const wchar_t* result = wcschrnul(string, ch); 636 const wchar_t* expected = string + 14; 637 if (result != expected || errno != 0) { 638 printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 639 "(expected %p), errno = %x (expected 0)\n", string, ch, 640 result, expected, errno); 641 problemCount++; 642 } 643 } 644 645 { 646 const wchar_t* string = L""; 647 const wchar_t ch = L' '; 648 const wchar_t* result = wcsrchr(string, ch); 649 const wchar_t* expected = NULL; 650 if (result != expected || errno != 0) { 651 printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 652 "(expected %p), errno = %x (expected 0)\n", string, ch, 653 result, expected, errno); 654 problemCount++; 655 } 656 } 657 658 { 659 const wchar_t* string = L""; 660 const wchar_t ch = L'\0'; 661 const wchar_t* result = wcsrchr(string, ch); 662 const wchar_t* expected = string; 663 if (result != expected || errno != 0) { 664 printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 665 "(expected %p), errno = %x (expected 0)\n", string, ch, 666 result, expected, errno); 667 problemCount++; 668 } 669 } 670 671 { 672 const wchar_t* string = L"sometext"; 673 const wchar_t ch = L' '; 674 const wchar_t* result = wcsrchr(string, ch); 675 const wchar_t* expected = NULL; 676 if (result != expected || errno != 0) { 677 printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 678 "(expected %p), errno = %x (expected 0)\n", string, ch, 679 result, expected, errno); 680 problemCount++; 681 } 682 } 683 684 { 685 const wchar_t* string = L"some more text"; 686 const wchar_t ch = L' '; 687 const wchar_t* result = wcsrchr(string, ch); 688 const wchar_t* expected = string + 9; 689 if (result != expected || errno != 0) { 690 printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 691 "(expected %p), errno = %x (expected 0)\n", string, ch, 692 result, expected, errno); 693 problemCount++; 694 } 695 } 696 697 { 698 const wchar_t* string = L"some more text"; 699 const wchar_t ch = L's'; 700 const wchar_t* result = wcsrchr(string, ch); 701 const wchar_t* expected = string; 702 if (result != expected || errno != 0) { 703 printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 704 "(expected %p), errno = %x (expected 0)\n", string, ch, 705 result, expected, errno); 706 problemCount++; 707 } 708 } 709 710 { 711 const wchar_t* string = L"some more text"; 712 const wchar_t ch = L'S'; 713 const wchar_t* result = wcsrchr(string, ch); 714 const wchar_t* expected = NULL; 715 if (result != expected || errno != 0) { 716 printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 717 "(expected %p), errno = %x (expected 0)\n", string, ch, 718 result, expected, errno); 719 problemCount++; 720 } 721 } 722 723 { 724 const wchar_t* string = L"some more text"; 725 const wchar_t ch = L'\0'; 726 const wchar_t* result = wcsrchr(string, ch); 727 const wchar_t* expected = string + 14; 728 if (result != expected || errno != 0) { 729 printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 730 "(expected %p), errno = %x (expected 0)\n", string, ch, 731 result, expected, errno); 732 problemCount++; 733 } 734 } 735 736 if (problemCount) 737 printf("\t%d problem(s) found!\n", problemCount); 738 else 739 printf("\tall fine\n"); 740 } 741 742 743 // #pragma mark - wcsdup ------------------------------------------------------- 744 745 746 void 747 test_wcsdup() 748 { 749 printf("wcsdup()\n"); 750 751 int problemCount = 0; 752 errno = 0; 753 754 #ifdef __HAIKU__ 755 { 756 const wchar_t* string = NULL; 757 wchar_t* result = wcsdup(string); 758 if (result != NULL || errno != 0) { 759 printf("\tPROBLEM: result for wcsdup(%p) = \"%ls\", errno = %x" 760 " (expected 0)\n", string, result, errno); 761 problemCount++; 762 } 763 } 764 #endif 765 766 { 767 const wchar_t* string = L""; 768 wchar_t* result = wcsdup(string); 769 if (result == NULL || wcscmp(result, string) != 0 || errno != 0) { 770 printf("\tPROBLEM: result for wcsdup(\"%ls\") = \"%ls\", errno = %x" 771 " (expected 0)\n", string, result, errno); 772 problemCount++; 773 } 774 } 775 776 { 777 const wchar_t* string = L"tÄstdata with some charäcters"; 778 wchar_t* result = wcsdup(string); 779 if (result == NULL || wcscmp(result, string) != 0 || errno != 0) { 780 printf("\tPROBLEM: result for wcsdup(\"%ls\") = \"%ls\", errno = %x" 781 " (expected 0)\n", string, result, errno); 782 problemCount++; 783 } 784 } 785 786 if (problemCount) 787 printf("\t%d problem(s) found!\n", problemCount); 788 else 789 printf("\tall fine\n"); 790 } 791 792 793 // #pragma mark - wcscpy ------------------------------------------------------- 794 795 796 void 797 test_wcscpy() 798 { 799 printf("wcscpy()/wcsncpy()\n"); 800 801 int problemCount = 0; 802 errno = 0; 803 804 { 805 const wchar_t* source = L""; 806 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 807 wchar_t* result = wcscpy(destination, source); 808 if (result != destination) { 809 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> result=%p, " 810 "expected %p\n", source, result, destination); 811 problemCount++; 812 } 813 if (errno != 0) { 814 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> errno=%d, " 815 "expected 0\n", source, errno); 816 problemCount++; 817 } 818 if (wcslen(destination) != 0) { 819 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 820 "wcslen(destination)=%lu, expected 0\n", source, 821 wcslen(destination)); 822 problemCount++; 823 } 824 if (destination[0] != L'\0') { 825 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 826 "destination[0]=%x, expected %x\n", source, destination[0], 827 L'\0'); 828 problemCount++; 829 } 830 if (destination[1] != L'X') { 831 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 832 "destination[1]=%x, expected %x\n", source, destination[1], 833 L'X'); 834 problemCount++; 835 } 836 } 837 838 { 839 const wchar_t* source = L"test"; 840 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 841 wchar_t* result = wcscpy(destination, source); 842 if (result != destination) { 843 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> result=%p, " 844 "expected %p\n", source, result, destination); 845 problemCount++; 846 } 847 if (errno != 0) { 848 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> errno=%d, " 849 "expected 0\n", source, errno); 850 problemCount++; 851 } 852 if (wcslen(destination) != 4) { 853 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 854 "wcslen(destination)=%lu, expected 4\n", source, 855 wcslen(destination)); 856 problemCount++; 857 } 858 if (destination[0] != L't') { 859 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 860 "destination[0]=%x, expected %x\n", source, destination[0], 861 L't'); 862 problemCount++; 863 } 864 if (destination[1] != L'e') { 865 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 866 "destination[1]=%x, expected %x\n", source, destination[1], 867 L'e'); 868 problemCount++; 869 } 870 if (destination[2] != L's') { 871 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 872 "destination[2]=%x, expected %x\n", source, destination[2], 873 L's'); 874 problemCount++; 875 } 876 if (destination[3] != L't') { 877 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 878 "destination[3]=%x, expected %x\n", source, destination[3], 879 L't'); 880 problemCount++; 881 } 882 if (destination[4] != L'\0') { 883 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 884 "destination[4]=%x, expected %x\n", source, destination[4], 885 L'\0'); 886 problemCount++; 887 } 888 if (destination[5] != L'X') { 889 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 890 "destination[5]=%x, expected %x\n", source, destination[5], 891 L'X'); 892 problemCount++; 893 } 894 } 895 896 { 897 const wchar_t* source = L"t\xE4st"; 898 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 899 wchar_t* result = wcscpy(destination, source); 900 if (result != destination) { 901 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> result=%p, " 902 "expected %p\n", source, result, destination); 903 problemCount++; 904 } 905 if (errno != 0) { 906 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> errno=%d, " 907 "expected 0\n", source, errno); 908 problemCount++; 909 } 910 if (wcslen(destination) != 4) { 911 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 912 "wcslen(destination)=%lu, expected 4\n", source, 913 wcslen(destination)); 914 problemCount++; 915 } 916 if (destination[0] != L't') { 917 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 918 "destination[0]=%x, expected %x\n", source, destination[0], 919 L't'); 920 problemCount++; 921 } 922 if (destination[1] != L'\xE4') { 923 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 924 "destination[1]=%x, expected %x\n", source, destination[1], 925 L'\xE4'); 926 problemCount++; 927 } 928 if (destination[2] != L's') { 929 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 930 "destination[2]=%x, expected %x\n", source, destination[2], 931 L's'); 932 problemCount++; 933 } 934 if (destination[3] != L't') { 935 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 936 "destination[3]=%x, expected %x\n", source, destination[3], 937 L't'); 938 problemCount++; 939 } 940 if (destination[4] != L'\0') { 941 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 942 "destination[4]=%x, expected %x\n", source, destination[4], 943 L'\0'); 944 problemCount++; 945 } 946 if (destination[5] != L'X') { 947 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 948 "destination[5]=%x, expected %x\n", source, destination[5], 949 L'X'); 950 problemCount++; 951 } 952 } 953 954 { 955 const wchar_t* source = L"te\x00st"; 956 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 957 wchar_t* result = wcscpy(destination, source); 958 if (result != destination) { 959 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> result=%p, " 960 "expected %p\n", source, result, destination); 961 problemCount++; 962 } 963 if (errno != 0) { 964 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> errno=%d, " 965 "expected 0\n", source, errno); 966 problemCount++; 967 } 968 if (wcslen(destination) != 2) { 969 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 970 "wcslen(destination)=%lu, expected 2\n", source, 971 wcslen(destination)); 972 problemCount++; 973 } 974 if (destination[0] != L't') { 975 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 976 "destination[0]=%x, expected %x\n", source, destination[0], 977 L't'); 978 problemCount++; 979 } 980 if (destination[1] != L'e') { 981 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 982 "destination[1]=%x, expected %x\n", source, destination[1], 983 L'e'); 984 problemCount++; 985 } 986 if (destination[2] != L'\0') { 987 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 988 "destination[2]=%x, expected %x\n", source, destination[2], 989 L'\0'); 990 problemCount++; 991 } 992 if (destination[3] != L'X') { 993 printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 994 "destination[3]=%x, expected %x\n", source, destination[3], 995 L'X'); 996 problemCount++; 997 } 998 } 999 1000 { 1001 const wchar_t* source = L"t\xE4st"; 1002 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1003 wchar_t* result = wcsncpy(destination, source, 0); 1004 if (result != destination) { 1005 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 0) -> result=%p, " 1006 "expected %p\n", source, result, destination); 1007 problemCount++; 1008 } 1009 if (errno != 0) { 1010 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 0) -> errno=%d, " 1011 "expected 0\n", source, errno); 1012 problemCount++; 1013 } 1014 if (destination[0] != L'X') { 1015 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 0) -> " 1016 "destination[0]=%x, expected %x\n", source, destination[0], 1017 L'X'); 1018 problemCount++; 1019 } 1020 } 1021 1022 { 1023 const wchar_t* source = L"t\xE4st"; 1024 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1025 wchar_t* result = wcsncpy(destination, source, 2); 1026 if (result != destination) { 1027 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> result=%p, " 1028 "expected %p\n", source, result, destination); 1029 problemCount++; 1030 } 1031 if (errno != 0) { 1032 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> errno=%d, " 1033 "expected 0\n", source, errno); 1034 problemCount++; 1035 } 1036 if (destination[0] != L't') { 1037 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> " 1038 "destination[0]=%x, expected %x\n", source, destination[0], 1039 L't'); 1040 problemCount++; 1041 } 1042 if (destination[1] != L'\xE4') { 1043 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> " 1044 "destination[1]=%x, expected %x\n", source, destination[1], 1045 L'\xE4'); 1046 problemCount++; 1047 } 1048 if (destination[2] != L'X') { 1049 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> " 1050 "destination[2]=%x, expected %x\n", source, destination[2], 1051 L'X'); 1052 problemCount++; 1053 } 1054 } 1055 1056 { 1057 const wchar_t* source = L"t\xE4st"; 1058 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1059 wchar_t* result = wcsncpy(destination, source, 4); 1060 if (result != destination) { 1061 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> result=%p, " 1062 "expected %p\n", source, result, destination); 1063 problemCount++; 1064 } 1065 if (errno != 0) { 1066 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> errno=%d, " 1067 "expected 0\n", source, errno); 1068 problemCount++; 1069 } 1070 if (destination[0] != L't') { 1071 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> " 1072 "destination[0]=%x, expected %x\n", source, destination[0], 1073 L't'); 1074 problemCount++; 1075 } 1076 if (destination[1] != L'\xE4') { 1077 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> " 1078 "destination[1]=%x, expected %x\n", source, destination[1], 1079 L'\xE4'); 1080 problemCount++; 1081 } 1082 if (destination[2] != L's') { 1083 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> " 1084 "destination[2]=%x, expected %x\n", source, destination[2], 1085 L's'); 1086 problemCount++; 1087 } 1088 if (destination[3] != L't') { 1089 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> " 1090 "destination[3]=%x, expected %x\n", source, destination[3], 1091 L't'); 1092 problemCount++; 1093 } 1094 if (destination[4] != L'X') { 1095 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> " 1096 "destination[4]=%x, expected %x\n", source, destination[4], 1097 L'X'); 1098 problemCount++; 1099 } 1100 } 1101 1102 { 1103 const wchar_t* source = L"t\xE4st"; 1104 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1105 wchar_t* result = wcsncpy(destination, source, 8); 1106 if (result != destination) { 1107 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> result=%p, " 1108 "expected %p\n", source, result, destination); 1109 problemCount++; 1110 } 1111 if (errno != 0) { 1112 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> errno=%d, " 1113 "expected 0\n", source, errno); 1114 problemCount++; 1115 } 1116 if (wcslen(destination) != 4) { 1117 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1118 "wcslen(destination)=%lu, expected 4\n", source, 1119 wcslen(destination)); 1120 problemCount++; 1121 } 1122 if (destination[0] != L't') { 1123 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1124 "destination[0]=%x, expected %x\n", source, destination[0], 1125 L't'); 1126 problemCount++; 1127 } 1128 if (destination[1] != L'\xE4') { 1129 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1130 "destination[1]=%x, expected %x\n", source, destination[1], 1131 L'\xE4'); 1132 problemCount++; 1133 } 1134 if (destination[2] != L's') { 1135 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1136 "destination[2]=%x, expected %x\n", source, destination[2], 1137 L's'); 1138 problemCount++; 1139 } 1140 if (destination[3] != L't') { 1141 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1142 "destination[3]=%x, expected %x\n", source, destination[3], 1143 L't'); 1144 problemCount++; 1145 } 1146 if (destination[4] != L'\0') { 1147 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1148 "destination[4]=%x, expected %x\n", source, destination[4], 1149 L'\0'); 1150 problemCount++; 1151 } 1152 if (destination[5] != L'\0') { 1153 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1154 "destination[5]=%x, expected %x\n", source, destination[5], 1155 L'\0'); 1156 problemCount++; 1157 } 1158 if (destination[6] != L'\0') { 1159 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1160 "destination[6]=%x, expected %x\n", source, destination[6], 1161 L'\0'); 1162 problemCount++; 1163 } 1164 if (destination[7] != L'\0') { 1165 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1166 "destination[7]=%x, expected %x\n", source, destination[7], 1167 L'\0'); 1168 problemCount++; 1169 } 1170 if (destination[8] != L'X') { 1171 printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1172 "destination[8]=%x, expected %x\n", source, destination[8], 1173 L'X'); 1174 problemCount++; 1175 } 1176 } 1177 1178 if (problemCount) 1179 printf("\t%d problem(s) found!\n", problemCount); 1180 else 1181 printf("\tall fine\n"); 1182 } 1183 1184 1185 // #pragma mark - wcpcpy ------------------------------------------------------- 1186 1187 1188 void 1189 test_wcpcpy() 1190 { 1191 printf("wcpcpy()/wcpncpy()\n"); 1192 1193 int problemCount = 0; 1194 errno = 0; 1195 1196 { 1197 const wchar_t* source = L""; 1198 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1199 wchar_t* result = wcpcpy(destination, source); 1200 if (result != destination) { 1201 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> result=%p, " 1202 "expected %p\n", source, result, destination); 1203 problemCount++; 1204 } 1205 if (errno != 0) { 1206 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> errno=%d, " 1207 "expected 0\n", source, errno); 1208 problemCount++; 1209 } 1210 if (wcslen(destination) != 0) { 1211 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1212 "wcslen(destination)=%lu, expected 0\n", source, 1213 wcslen(destination)); 1214 problemCount++; 1215 } 1216 if (destination[0] != L'\0') { 1217 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1218 "destination[0]=%x, expected %x\n", source, destination[0], 1219 L'\0'); 1220 problemCount++; 1221 } 1222 if (destination[1] != L'X') { 1223 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1224 "destination[1]=%x, expected %x\n", source, destination[1], 1225 L'X'); 1226 problemCount++; 1227 } 1228 } 1229 1230 { 1231 const wchar_t* source = L"test"; 1232 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1233 wchar_t* result = wcpcpy(destination, source); 1234 if (result != destination + 4) { 1235 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> result=%p, " 1236 "expected %p\n", source, result, destination + 4); 1237 problemCount++; 1238 } 1239 if (errno != 0) { 1240 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> errno=%d, " 1241 "expected 0\n", source, errno); 1242 problemCount++; 1243 } 1244 if (wcslen(destination) != 4) { 1245 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1246 "wcslen(destination)=%lu, expected 4\n", source, 1247 wcslen(destination)); 1248 problemCount++; 1249 } 1250 if (destination[0] != L't') { 1251 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1252 "destination[0]=%x, expected %x\n", source, destination[0], 1253 L't'); 1254 problemCount++; 1255 } 1256 if (destination[1] != L'e') { 1257 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1258 "destination[1]=%x, expected %x\n", source, destination[1], 1259 L'e'); 1260 problemCount++; 1261 } 1262 if (destination[2] != L's') { 1263 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1264 "destination[2]=%x, expected %x\n", source, destination[2], 1265 L's'); 1266 problemCount++; 1267 } 1268 if (destination[3] != L't') { 1269 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1270 "destination[3]=%x, expected %x\n", source, destination[3], 1271 L't'); 1272 problemCount++; 1273 } 1274 if (destination[4] != L'\0') { 1275 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1276 "destination[4]=%x, expected %x\n", source, destination[4], 1277 L'\0'); 1278 problemCount++; 1279 } 1280 if (destination[5] != L'X') { 1281 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1282 "destination[5]=%x, expected %x\n", source, destination[5], 1283 L'X'); 1284 problemCount++; 1285 } 1286 } 1287 1288 { 1289 const wchar_t* source = L"t\xE4st"; 1290 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1291 wchar_t* result = wcpcpy(destination, source); 1292 if (result != destination + 4) { 1293 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> result=%p, " 1294 "expected %p\n", source, result, destination + 4); 1295 problemCount++; 1296 } 1297 if (errno != 0) { 1298 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> errno=%d, " 1299 "expected 0\n", source, errno); 1300 problemCount++; 1301 } 1302 if (wcslen(destination) != 4) { 1303 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1304 "wcslen(destination)=%lu, expected 4\n", source, 1305 wcslen(destination)); 1306 problemCount++; 1307 } 1308 if (destination[0] != L't') { 1309 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1310 "destination[0]=%x, expected %x\n", source, destination[0], 1311 L't'); 1312 problemCount++; 1313 } 1314 if (destination[1] != L'\xE4') { 1315 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1316 "destination[1]=%x, expected %x\n", source, destination[1], 1317 L'\xE4'); 1318 problemCount++; 1319 } 1320 if (destination[2] != L's') { 1321 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1322 "destination[2]=%x, expected %x\n", source, destination[2], 1323 L's'); 1324 problemCount++; 1325 } 1326 if (destination[3] != L't') { 1327 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1328 "destination[3]=%x, expected %x\n", source, destination[3], 1329 L't'); 1330 problemCount++; 1331 } 1332 if (destination[4] != L'\0') { 1333 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1334 "destination[4]=%x, expected %x\n", source, destination[4], 1335 L'\0'); 1336 problemCount++; 1337 } 1338 if (destination[5] != L'X') { 1339 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1340 "destination[5]=%x, expected %x\n", source, destination[5], 1341 L'X'); 1342 problemCount++; 1343 } 1344 } 1345 1346 { 1347 const wchar_t* source = L"te\x00st"; 1348 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1349 wchar_t* result = wcpcpy(destination, source); 1350 if (result != destination + 2) { 1351 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> result=%p, " 1352 "expected %p\n", source, result, destination + 2); 1353 problemCount++; 1354 } 1355 if (errno != 0) { 1356 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> errno=%d, " 1357 "expected 0\n", source, errno); 1358 problemCount++; 1359 } 1360 if (wcslen(destination) != 2) { 1361 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1362 "wcslen(destination)=%lu, expected 2\n", source, 1363 wcslen(destination)); 1364 problemCount++; 1365 } 1366 if (destination[0] != L't') { 1367 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1368 "destination[0]=%x, expected %x\n", source, destination[0], 1369 L't'); 1370 problemCount++; 1371 } 1372 if (destination[1] != L'e') { 1373 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1374 "destination[1]=%x, expected %x\n", source, destination[1], 1375 L'e'); 1376 problemCount++; 1377 } 1378 if (destination[2] != L'\0') { 1379 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1380 "destination[2]=%x, expected %x\n", source, destination[2], 1381 L'\0'); 1382 problemCount++; 1383 } 1384 if (destination[3] != L'X') { 1385 printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1386 "destination[3]=%x, expected %x\n", source, destination[3], 1387 L'X'); 1388 problemCount++; 1389 } 1390 } 1391 1392 { 1393 const wchar_t* source = L"t\xE4st"; 1394 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1395 wchar_t* result = wcpncpy(destination, source, 0); 1396 if (result != destination) { 1397 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 0) -> result=%p, " 1398 "expected %p\n", source, result, destination); 1399 problemCount++; 1400 } 1401 if (errno != 0) { 1402 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 0) -> errno=%d, " 1403 "expected 0\n", source, errno); 1404 problemCount++; 1405 } 1406 if (destination[0] != L'X') { 1407 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 0) -> " 1408 "destination[0]=%x, expected %x\n", source, destination[0], 1409 L'X'); 1410 problemCount++; 1411 } 1412 } 1413 1414 { 1415 const wchar_t* source = L"t\xE4st"; 1416 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1417 wchar_t* result = wcpncpy(destination, source, 2); 1418 if (result != destination + 2) { 1419 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> result=%p, " 1420 "expected %p\n", source, result, destination + 2); 1421 problemCount++; 1422 } 1423 if (errno != 0) { 1424 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> errno=%d, " 1425 "expected 0\n", source, errno); 1426 problemCount++; 1427 } 1428 if (destination[0] != L't') { 1429 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> " 1430 "destination[0]=%x, expected %x\n", source, destination[0], 1431 L't'); 1432 problemCount++; 1433 } 1434 if (destination[1] != L'\xE4') { 1435 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> " 1436 "destination[1]=%x, expected %x\n", source, destination[1], 1437 L'\xE4'); 1438 problemCount++; 1439 } 1440 if (destination[2] != L'X') { 1441 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> " 1442 "destination[2]=%x, expected %x\n", source, destination[2], 1443 L'X'); 1444 problemCount++; 1445 } 1446 } 1447 1448 { 1449 const wchar_t* source = L"t\xE4st"; 1450 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1451 wchar_t* result = wcpncpy(destination, source, 4); 1452 if (result != destination + 4) { 1453 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> result=%p, " 1454 "expected %p\n", source, result, destination + 4); 1455 problemCount++; 1456 } 1457 if (errno != 0) { 1458 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> errno=%d, " 1459 "expected 0\n", source, errno); 1460 problemCount++; 1461 } 1462 if (destination[0] != L't') { 1463 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> " 1464 "destination[0]=%x, expected %x\n", source, destination[0], 1465 L't'); 1466 problemCount++; 1467 } 1468 if (destination[1] != L'\xE4') { 1469 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> " 1470 "destination[1]=%x, expected %x\n", source, destination[1], 1471 L'\xE4'); 1472 problemCount++; 1473 } 1474 if (destination[2] != L's') { 1475 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> " 1476 "destination[2]=%x, expected %x\n", source, destination[2], 1477 L's'); 1478 problemCount++; 1479 } 1480 if (destination[3] != L't') { 1481 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> " 1482 "destination[3]=%x, expected %x\n", source, destination[3], 1483 L't'); 1484 problemCount++; 1485 } 1486 if (destination[4] != L'X') { 1487 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> " 1488 "destination[4]=%x, expected %x\n", source, destination[4], 1489 L'X'); 1490 problemCount++; 1491 } 1492 } 1493 1494 { 1495 const wchar_t* source = L"t\xE4st"; 1496 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1497 wchar_t* result = wcpncpy(destination, source, 8); 1498 if (result != destination + 4) { 1499 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> result=%p, " 1500 "expected %p\n", source, result, destination + 4); 1501 problemCount++; 1502 } 1503 if (errno != 0) { 1504 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> errno=%d, " 1505 "expected 0\n", source, errno); 1506 problemCount++; 1507 } 1508 if (wcslen(destination) != 4) { 1509 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1510 "wcslen(destination)=%lu, expected 4\n", source, 1511 wcslen(destination)); 1512 problemCount++; 1513 } 1514 if (destination[0] != L't') { 1515 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1516 "destination[0]=%x, expected %x\n", source, destination[0], 1517 L't'); 1518 problemCount++; 1519 } 1520 if (destination[1] != L'\xE4') { 1521 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1522 "destination[1]=%x, expected %x\n", source, destination[1], 1523 L'\xE4'); 1524 problemCount++; 1525 } 1526 if (destination[2] != L's') { 1527 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1528 "destination[2]=%x, expected %x\n", source, destination[2], 1529 L's'); 1530 problemCount++; 1531 } 1532 if (destination[3] != L't') { 1533 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1534 "destination[3]=%x, expected %x\n", source, destination[3], 1535 L't'); 1536 problemCount++; 1537 } 1538 if (destination[4] != L'\0') { 1539 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1540 "destination[4]=%x, expected %x\n", source, destination[4], 1541 L'\0'); 1542 problemCount++; 1543 } 1544 if (destination[5] != L'\0') { 1545 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1546 "destination[5]=%x, expected %x\n", source, destination[5], 1547 L'\0'); 1548 problemCount++; 1549 } 1550 if (destination[6] != L'\0') { 1551 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1552 "destination[6]=%x, expected %x\n", source, destination[6], 1553 L'\0'); 1554 problemCount++; 1555 } 1556 if (destination[7] != L'\0') { 1557 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1558 "destination[7]=%x, expected %x\n", source, destination[7], 1559 L'\0'); 1560 problemCount++; 1561 } 1562 if (destination[8] != L'X') { 1563 printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1564 "destination[8]=%x, expected %x\n", source, destination[8], 1565 L'X'); 1566 problemCount++; 1567 } 1568 } 1569 1570 if (problemCount) 1571 printf("\t%d problem(s) found!\n", problemCount); 1572 else 1573 printf("\tall fine\n"); 1574 } 1575 1576 1577 // #pragma mark - wcscat ------------------------------------------------------- 1578 1579 1580 void 1581 test_wcscat() 1582 { 1583 printf("wcscat()/wcsncat()\n"); 1584 1585 int problemCount = 0; 1586 errno = 0; 1587 wchar_t destination[] = L"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 1588 destination[0] = L'\0'; 1589 wchar_t backup[33]; 1590 1591 { 1592 wcscpy(backup, destination); 1593 const wchar_t* source = L""; 1594 wchar_t* result = wcscat(destination, source); 1595 if (result != destination) { 1596 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> result=%p, " 1597 "expected %p\n", backup, source, result, destination); 1598 problemCount++; 1599 } 1600 if (errno != 0) { 1601 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> errno=%d, " 1602 "expected 0\n", backup, source, errno); 1603 problemCount++; 1604 } 1605 if (wcslen(destination) != 0) { 1606 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> " 1607 "wcslen(destination)=%lu, expected 0\n", backup, source, 1608 wcslen(destination)); 1609 problemCount++; 1610 } 1611 if (destination[0] != L'\0') { 1612 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[0]=%x, " 1613 "expected %x\n", backup, source, destination[0], L'\0'); 1614 problemCount++; 1615 } 1616 if (destination[1] != L'X') { 1617 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[1]=%x, " 1618 "expected %x\n", backup, source, destination[1], L'X'); 1619 problemCount++; 1620 } 1621 } 1622 1623 { 1624 wcscpy(backup, destination); 1625 const wchar_t* source = L"test"; 1626 wchar_t* result = wcscat(destination, source); 1627 if (result != destination) { 1628 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> result=%p, " 1629 "expected %p\n", backup, source, result, destination); 1630 problemCount++; 1631 } 1632 if (errno != 0) { 1633 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> errno=%d, " 1634 "expected 0\n", backup, source, errno); 1635 problemCount++; 1636 } 1637 if (wcslen(destination) != 4) { 1638 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> " 1639 "wcslen(destination)=%lu, expected 4\n", backup, source, 1640 wcslen(destination)); 1641 problemCount++; 1642 } 1643 if (destination[0] != L't') { 1644 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[0]=%x, " 1645 "expected %x\n", backup, source, destination[0], L't'); 1646 problemCount++; 1647 } 1648 if (destination[1] != L'e') { 1649 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[1]=%x, " 1650 "expected %x\n", backup, source, destination[1], L'e'); 1651 problemCount++; 1652 } 1653 if (destination[2] != L's') { 1654 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[2]=%x, " 1655 "expected %x\n", backup, source, destination[2], L's'); 1656 problemCount++; 1657 } 1658 if (destination[3] != L't') { 1659 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[3]=%x, " 1660 "expected %x\n", backup, source, destination[3], L't'); 1661 problemCount++; 1662 } 1663 if (destination[4] != L'\0') { 1664 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[4]=%x, " 1665 "expected %x\n", backup, source, destination[4], L'\0'); 1666 problemCount++; 1667 } 1668 if (destination[5] != L'X') { 1669 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[5]=%x, " 1670 "expected %x\n", backup, source, destination[5], L'X'); 1671 problemCount++; 1672 } 1673 } 1674 1675 { 1676 wcscpy(backup, destination); 1677 const wchar_t* source = L"t\xE4st"; 1678 wchar_t* result = wcscat(destination, source); 1679 if (result != destination) { 1680 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> result=%p, " 1681 "expected %p\n", backup, source, result, destination); 1682 problemCount++; 1683 } 1684 if (errno != 0) { 1685 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> errno=%d, " 1686 "expected 0\n", backup, source, errno); 1687 problemCount++; 1688 } 1689 if (wcslen(destination) != 8) { 1690 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> " 1691 "wcslen(destination)=%lu, expected 8\n", backup, source, 1692 wcslen(destination)); 1693 problemCount++; 1694 } 1695 if (destination[0] != L't') { 1696 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[0]=%x, " 1697 "expected %x\n", backup, source, destination[0], L't'); 1698 problemCount++; 1699 } 1700 if (destination[1] != L'e') { 1701 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[1]=%x, " 1702 "expected %x\n", backup, source, destination[1], L'e'); 1703 problemCount++; 1704 } 1705 if (destination[2] != L's') { 1706 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[2]=%x, " 1707 "expected %x\n", backup, source, destination[2], L's'); 1708 problemCount++; 1709 } 1710 if (destination[3] != L't') { 1711 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[3]=%x, " 1712 "expected %x\n", backup, source, destination[3], L't'); 1713 problemCount++; 1714 } 1715 if (destination[4] != L't') { 1716 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[4]=%x, " 1717 "expected %x\n", backup, source, destination[4], L't'); 1718 problemCount++; 1719 } 1720 if (destination[5] != L'\xE4') { 1721 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[5]=%x, " 1722 "expected %x\n", backup, source, destination[5], L'\xE4'); 1723 problemCount++; 1724 } 1725 if (destination[6] != L's') { 1726 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[6]=%x, " 1727 "expected %x\n", backup, source, destination[6], L's'); 1728 problemCount++; 1729 } 1730 if (destination[7] != L't') { 1731 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[7]=%x, " 1732 "expected %x\n", backup, source, destination[7], L't'); 1733 problemCount++; 1734 } 1735 if (destination[8] != L'\0') { 1736 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[8]=%x, " 1737 "expected %x\n", backup, source, destination[8], L'\0'); 1738 problemCount++; 1739 } 1740 if (destination[9] != L'X') { 1741 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[9]=%x, " 1742 "expected %x\n", backup, source, destination[9], L'X'); 1743 problemCount++; 1744 } 1745 } 1746 1747 { 1748 wcscpy(backup, destination); 1749 const wchar_t* source = L"te\x00st"; 1750 wchar_t* result = wcscat(destination, source); 1751 if (result != destination) { 1752 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> result=%p, " 1753 "expected %p\n", backup, source, result, destination); 1754 problemCount++; 1755 } 1756 if (errno != 0) { 1757 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> errno=%d, " 1758 "expected 0\n", backup, source, errno); 1759 problemCount++; 1760 } 1761 if (wcslen(destination) != 10) { 1762 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> " 1763 "wcslen(destination)=%lu, expected 10\n", backup, source, 1764 wcslen(destination)); 1765 problemCount++; 1766 } 1767 if (destination[0] != L't') { 1768 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[0]=%x, " 1769 "expected %x\n", backup, source, destination[0], L't'); 1770 problemCount++; 1771 } 1772 if (destination[1] != L'e') { 1773 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[1]=%x, " 1774 "expected %x\n", backup, source, destination[1], L'e'); 1775 problemCount++; 1776 } 1777 if (destination[2] != L's') { 1778 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[2]=%x, " 1779 "expected %x\n", backup, source, destination[2], L's'); 1780 problemCount++; 1781 } 1782 if (destination[3] != L't') { 1783 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[3]=%x, " 1784 "expected %x\n", backup, source, destination[3], L't'); 1785 problemCount++; 1786 } 1787 if (destination[4] != L't') { 1788 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[4]=%x, " 1789 "expected %x\n", backup, source, destination[4], L't'); 1790 problemCount++; 1791 } 1792 if (destination[5] != L'\xE4') { 1793 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[5]=%x, " 1794 "expected %x\n", backup, source, destination[5], L'\xE4'); 1795 problemCount++; 1796 } 1797 if (destination[6] != L's') { 1798 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[6]=%x, " 1799 "expected %x\n", backup, source, destination[6], L's'); 1800 problemCount++; 1801 } 1802 if (destination[7] != L't') { 1803 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[7]=%x, " 1804 "expected %x\n", backup, source, destination[7], L't'); 1805 problemCount++; 1806 } 1807 if (destination[8] != L't') { 1808 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[8]=%x, " 1809 "expected %x\n", backup, source, destination[8], L't'); 1810 problemCount++; 1811 } 1812 if (destination[9] != L'e') { 1813 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[9]=%x, " 1814 "expected %x\n", backup, source, destination[9], L'e'); 1815 problemCount++; 1816 } 1817 if (destination[10] != L'\0') { 1818 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[10]=%x, " 1819 "expected %x\n", backup, source, destination[10], L'\0'); 1820 problemCount++; 1821 } 1822 if (destination[11] != L'X') { 1823 printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[11]=%x, " 1824 "expected %x\n", backup, source, destination[11], L'X'); 1825 problemCount++; 1826 } 1827 } 1828 1829 { 1830 wcscpy(destination, L"some"); 1831 wcscpy(backup, destination); 1832 const wchar_t* source = L" other text"; 1833 wchar_t* result = wcsncat(destination, source, 0); 1834 if (result != destination) { 1835 printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 0) -> result=%p, " 1836 "expected %p\n", backup, source, result, destination); 1837 problemCount++; 1838 } 1839 if (errno != 0) { 1840 printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 0) -> errno=%d, " 1841 "expected 0\n", backup, source, errno); 1842 problemCount++; 1843 } 1844 if (wcslen(destination) != 4) { 1845 printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 0) -> " 1846 "wcslen(destination)=%lu, expected 4\n", backup, source, 1847 wcslen(destination)); 1848 problemCount++; 1849 } 1850 if (wcscmp(destination, L"some") != 0) { 1851 printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 0) -> \"%ls\"\n", 1852 backup, source, destination); 1853 problemCount++; 1854 } 1855 } 1856 1857 { 1858 wcscpy(destination, L"some"); 1859 wcscpy(backup, destination); 1860 const wchar_t* source = L" other text"; 1861 wchar_t* result = wcsncat(destination, source, 6); 1862 if (result != destination) { 1863 printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 6) -> result=%p, " 1864 "expected %p\n", backup, source, result, destination); 1865 problemCount++; 1866 } 1867 if (errno != 0) { 1868 printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 6) -> errno=%d, " 1869 "expected 0\n", backup, source, errno); 1870 problemCount++; 1871 } 1872 if (wcslen(destination) != 10) { 1873 printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 6) -> " 1874 "wcslen(destination)=%lu, expected 10\n", backup, source, 1875 wcslen(destination)); 1876 problemCount++; 1877 } 1878 if (wcscmp(destination, L"some other") != 0) { 1879 printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 6) -> \"%ls\"\n", 1880 backup, source, destination); 1881 problemCount++; 1882 } 1883 } 1884 1885 { 1886 wcscpy(destination, L"some"); 1887 wcscpy(backup, destination); 1888 const wchar_t* source = L" other text"; 1889 wchar_t* result = wcsncat(destination, source, 20); 1890 if (result != destination) { 1891 printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 20) -> result=%p, " 1892 "expected %p\n", backup, source, result, destination); 1893 problemCount++; 1894 } 1895 if (errno != 0) { 1896 printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 20) -> errno=%d, " 1897 "expected 0\n", backup, source, errno); 1898 problemCount++; 1899 } 1900 if (wcslen(destination) != 15) { 1901 printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 20) -> " 1902 "wcslen(destination)=%lu, expected 15\n", backup, source, 1903 wcslen(destination)); 1904 problemCount++; 1905 } 1906 if (wcscmp(destination, L"some other text") != 0) { 1907 printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 20) -> \"%ls\"\n", 1908 backup, source, destination); 1909 problemCount++; 1910 } 1911 } 1912 1913 if (problemCount) 1914 printf("\t%d problem(s) found!\n", problemCount); 1915 else 1916 printf("\tall fine\n"); 1917 } 1918 1919 1920 // #pragma mark - wcslcat ------------------------------------------------------ 1921 1922 1923 #ifdef __HAIKU__ 1924 1925 void 1926 test_wcslcat() 1927 { 1928 printf("wcslcat()\n"); 1929 1930 int problemCount = 0; 1931 errno = 0; 1932 wchar_t destination[] = L"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 1933 wchar_t backup[33]; 1934 1935 { 1936 wcscpy(backup, destination); 1937 const wchar_t* source = L""; 1938 size_t result = wcslcat(destination, source, 0); 1939 size_t expectedResult = 0; 1940 if (result != expectedResult) { 1941 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 0) -> result=%ld, " 1942 "expected %ld\n", backup, source, result, expectedResult); 1943 problemCount++; 1944 } 1945 if (errno != 0) { 1946 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 0) -> errno=%d, " 1947 "expected 0\n", backup, source, errno); 1948 problemCount++; 1949 } 1950 if (wcslen(destination) != 32) { 1951 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 0) -> " 1952 "wcslen(destination)=%lu, expected 32\n", backup, source, 1953 wcslen(destination)); 1954 problemCount++; 1955 } 1956 if (destination[0] != L'X') { 1957 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 0) -> destination[0]=" 1958 "%x, expected %x\n", backup, source, destination[0], L'X'); 1959 problemCount++; 1960 } 1961 } 1962 1963 { 1964 destination[0] = L'\0'; 1965 wcscpy(backup, destination); 1966 const wchar_t* source = L""; 1967 size_t result = wcslcat(destination, source, 32); 1968 size_t expectedResult = 0; 1969 if (result != expectedResult) { 1970 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> result=%ld, " 1971 "expected %ld\n", backup, source, result, expectedResult); 1972 problemCount++; 1973 } 1974 if (errno != 0) { 1975 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> errno=%d, " 1976 "expected 0\n", backup, source, errno); 1977 problemCount++; 1978 } 1979 if (wcslen(destination) != 0) { 1980 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> " 1981 "wcslen(destination)=%lu, expected 0\n", backup, source, 1982 wcslen(destination)); 1983 problemCount++; 1984 } 1985 if (destination[0] != L'\0') { 1986 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[0]=" 1987 "%x, expected %x\n", backup, source, destination[0], L'\0'); 1988 problemCount++; 1989 } 1990 if (destination[1] != L'X') { 1991 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[1]=" 1992 "%x, expected %x\n", backup, source, destination[1], L'X'); 1993 problemCount++; 1994 } 1995 } 1996 1997 { 1998 wcscpy(backup, destination); 1999 const wchar_t* source = L"test"; 2000 size_t result = wcslcat(destination, source, 3); 2001 size_t expectedResult = 4; 2002 if (result != expectedResult) { 2003 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> result=%ld, " 2004 "expected %ld\n", backup, source, result, expectedResult); 2005 problemCount++; 2006 } 2007 if (errno != 0) { 2008 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> errno=%d, " 2009 "expected 0\n", backup, source, errno); 2010 problemCount++; 2011 } 2012 if (wcslen(destination) != 2) { 2013 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> " 2014 "wcslen(destination)=%lu, expected 2\n", backup, source, 2015 wcslen(destination)); 2016 problemCount++; 2017 } 2018 if (destination[0] != L't') { 2019 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> destination[0]=" 2020 "%x, expected %x\n", backup, source, destination[0], L't'); 2021 problemCount++; 2022 } 2023 if (destination[1] != L'e') { 2024 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> destination[1]=" 2025 "%x, expected %x\n", backup, source, destination[1], L'e'); 2026 problemCount++; 2027 } 2028 if (destination[2] != L'\0') { 2029 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> destination[2]=" 2030 "%x, expected %x\n", backup, source, destination[2], L'\0'); 2031 problemCount++; 2032 } 2033 if (destination[3] != L'X') { 2034 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 3) -> destination[3]=" 2035 "%x, expected %x\n", backup, source, destination[3], L'X'); 2036 problemCount++; 2037 } 2038 } 2039 2040 { 2041 wcscpy(backup, destination); 2042 const wchar_t* source = L"st"; 2043 size_t result = wcslcat(destination, source, 4); 2044 size_t expectedResult = 4; 2045 if (result != expectedResult) { 2046 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> result=%ld, " 2047 "expected %ld\n", backup, source, result, expectedResult); 2048 problemCount++; 2049 } 2050 if (errno != 0) { 2051 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> errno=%d, " 2052 "expected 0\n", backup, source, errno); 2053 problemCount++; 2054 } 2055 if (wcslen(destination) != 3) { 2056 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> " 2057 "wcslen(destination)=%lu, expected 3\n", backup, source, 2058 wcslen(destination)); 2059 problemCount++; 2060 } 2061 if (destination[0] != L't') { 2062 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> destination[0]=" 2063 "%x, expected %x\n", backup, source, destination[0], L't'); 2064 problemCount++; 2065 } 2066 if (destination[1] != L'e') { 2067 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> destination[1]=" 2068 "%x, expected %x\n", backup, source, destination[1], L'e'); 2069 problemCount++; 2070 } 2071 if (destination[2] != L's') { 2072 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> destination[2]=" 2073 "%x, expected %x\n", backup, source, destination[2], L's'); 2074 problemCount++; 2075 } 2076 if (destination[3] != L'\0') { 2077 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> destination[3]=" 2078 "%x, expected %x\n", backup, source, destination[3], L'\0'); 2079 problemCount++; 2080 } 2081 if (destination[4] != L'X') { 2082 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 4) -> destination[4]=" 2083 "%x, expected %x\n", backup, source, destination[4], L'X'); 2084 problemCount++; 2085 } 2086 } 2087 2088 { 2089 wcscpy(backup, destination); 2090 const wchar_t* source = L"t"; 2091 size_t result = wcslcat(destination, source, 5); 2092 size_t expectedResult = 4; 2093 if (result != expectedResult) { 2094 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> result=%ld, " 2095 "expected %ld\n", backup, source, result, expectedResult); 2096 problemCount++; 2097 } 2098 if (errno != 0) { 2099 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> errno=%d, " 2100 "expected 0\n", backup, source, errno); 2101 problemCount++; 2102 } 2103 if (wcslen(destination) != 4) { 2104 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> " 2105 "wcslen(destination)=%lu, expected 4\n", backup, source, 2106 wcslen(destination)); 2107 problemCount++; 2108 } 2109 if (destination[0] != L't') { 2110 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> destination[0]=" 2111 "%x, expected %x\n", backup, source, destination[0], L't'); 2112 problemCount++; 2113 } 2114 if (destination[1] != L'e') { 2115 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> destination[1]=" 2116 "%x, expected %x\n", backup, source, destination[1], L'e'); 2117 problemCount++; 2118 } 2119 if (destination[2] != L's') { 2120 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> destination[2]=" 2121 "%x, expected %x\n", backup, source, destination[2], L's'); 2122 problemCount++; 2123 } 2124 if (destination[3] != L't') { 2125 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> destination[3]=" 2126 "%x, expected %x\n", backup, source, destination[3], L't'); 2127 problemCount++; 2128 } 2129 if (destination[4] != L'\0') { 2130 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> destination[4]=" 2131 "%x, expected %x\n", backup, source, destination[4], L'\0'); 2132 problemCount++; 2133 } 2134 if (destination[5] != L'X') { 2135 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 5) -> destination[5]=" 2136 "%x, expected %x\n", backup, source, destination[5], L'X'); 2137 problemCount++; 2138 } 2139 } 2140 2141 { 2142 wcscpy(backup, destination); 2143 const wchar_t* source = L"t\xE4st"; 2144 size_t result = wcslcat(destination, source, 32); 2145 size_t expectedResult = 8; 2146 if (result != expectedResult) { 2147 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> result=%ld, " 2148 "expected %ld\n", backup, source, result, expectedResult); 2149 problemCount++; 2150 } 2151 if (errno != 0) { 2152 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> errno=%d, " 2153 "expected 0\n", backup, source, errno); 2154 problemCount++; 2155 } 2156 if (wcslen(destination) != 8) { 2157 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> " 2158 "wcslen(destination)=%lu, expected 8\n", backup, source, 2159 wcslen(destination)); 2160 problemCount++; 2161 } 2162 if (destination[0] != L't') { 2163 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[0]=" 2164 "%x, expected %x\n", backup, source, destination[0], L't'); 2165 problemCount++; 2166 } 2167 if (destination[1] != L'e') { 2168 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[1]=" 2169 "%x, expected %x\n", backup, source, destination[1], L'e'); 2170 problemCount++; 2171 } 2172 if (destination[2] != L's') { 2173 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[2]=" 2174 "%x, expected %x\n", backup, source, destination[2], L's'); 2175 problemCount++; 2176 } 2177 if (destination[3] != L't') { 2178 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[3]=" 2179 "%x, expected %x\n", backup, source, destination[3], L't'); 2180 problemCount++; 2181 } 2182 if (destination[4] != L't') { 2183 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[4]=" 2184 "%x, expected %x\n", backup, source, destination[4], L't'); 2185 problemCount++; 2186 } 2187 if (destination[5] != L'\xE4') { 2188 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[5]=" 2189 "%x, expected %x\n", backup, source, destination[5], 2190 L'\xE4'); 2191 problemCount++; 2192 } 2193 if (destination[6] != L's') { 2194 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[6]=" 2195 "%x, expected %x\n", backup, source, destination[6], L's'); 2196 problemCount++; 2197 } 2198 if (destination[7] != L't') { 2199 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[7]=" 2200 "%x, expected %x\n", backup, source, destination[7], L't'); 2201 problemCount++; 2202 } 2203 if (destination[8] != L'\0') { 2204 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[8]=" 2205 "%x, expected %x\n", backup, source, destination[8], L'\0'); 2206 problemCount++; 2207 } 2208 if (destination[9] != L'X') { 2209 printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[9]=" 2210 "%x, expected %x\n", backup, source, destination[9], L'X'); 2211 problemCount++; 2212 } 2213 } 2214 2215 if (problemCount) 2216 printf("\t%d problem(s) found!\n", problemCount); 2217 else 2218 printf("\tall fine\n"); 2219 } 2220 2221 #endif 2222 2223 2224 // #pragma mark - wcslcpy ------------------------------------------------------ 2225 2226 2227 #ifdef __HAIKU__ 2228 2229 void 2230 test_wcslcpy() 2231 { 2232 printf("wcslcpy()\n"); 2233 2234 int problemCount = 0; 2235 errno = 0; 2236 2237 { 2238 const wchar_t* source = L""; 2239 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 2240 2241 size_t result = wcslcpy(destination, source, 0); 2242 size_t expectedResult = 0; 2243 if (result != expectedResult) { 2244 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 0) -> result=%ld, " 2245 "expected %ld\n", source, result, expectedResult); 2246 problemCount++; 2247 } 2248 if (errno != 0) { 2249 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 0) -> errno=%d, " 2250 "expected 0\n", source, errno); 2251 problemCount++; 2252 } 2253 if (wcslen(destination) != 16) { 2254 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 0) -> " 2255 "wcslen(destination)=%lu, expected 16\n", source, 2256 wcslen(destination)); 2257 problemCount++; 2258 } 2259 if (destination[0] != L'X') { 2260 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 0) -> " 2261 "destination[0]=%x, expected %x\n", source, destination[0], 2262 L'X'); 2263 problemCount++; 2264 } 2265 } 2266 2267 { 2268 const wchar_t* source = L""; 2269 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 2270 size_t result = wcslcpy(destination, source, 16); 2271 size_t expectedResult = 0; 2272 if (result != expectedResult) { 2273 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> result=%ld," 2274 " expected %ld\n", source, result, expectedResult); 2275 problemCount++; 2276 } 2277 if (errno != 0) { 2278 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> errno=%d, " 2279 "expected 0\n", source, errno); 2280 problemCount++; 2281 } 2282 if (wcslen(destination) != 0) { 2283 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> " 2284 "wcslen(destination)=%lu, expected 0\n", source, 2285 wcslen(destination)); 2286 problemCount++; 2287 } 2288 if (destination[0] != L'\0') { 2289 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> " 2290 "destination[0]=%x, expected %x\n", source, destination[0], 2291 L'\0'); 2292 problemCount++; 2293 } 2294 if (destination[1] != L'X') { 2295 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> " 2296 "destination[1]=%x, expected %x\n", source, destination[1], 2297 L'X'); 2298 problemCount++; 2299 } 2300 } 2301 2302 { 2303 const wchar_t* source = L"test"; 2304 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 2305 size_t result = wcslcpy(destination, source, 3); 2306 size_t expectedResult = 4; 2307 if (result != expectedResult) { 2308 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 3) -> result=%ld, " 2309 "expected %ld\n", source, result, expectedResult); 2310 problemCount++; 2311 } 2312 if (errno != 0) { 2313 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 3) -> errno=%d, " 2314 "expected 0\n", source, errno); 2315 problemCount++; 2316 } 2317 if (wcslen(destination) != 2) { 2318 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 2) -> " 2319 "wcslen(destination)=%lu, expected 3\n", source, 2320 wcslen(destination)); 2321 problemCount++; 2322 } 2323 if (destination[0] != L't') { 2324 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 3) -> " 2325 "destination[0]=%x, expected %x\n", source, destination[0], 2326 L't'); 2327 problemCount++; 2328 } 2329 if (destination[1] != L'e') { 2330 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 3) -> " 2331 "destination[1]=%x, expected %x\n", source, destination[1], 2332 L'e'); 2333 problemCount++; 2334 } 2335 if (destination[2] != L'\0') { 2336 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 3) -> " 2337 "destination[2]=%x, expected %x\n", source, destination[2], 2338 L'\0'); 2339 problemCount++; 2340 } 2341 if (destination[3] != L'X') { 2342 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 3) -> " 2343 "destination[3]=%x, expected %x\n", source, destination[3], 2344 L'X'); 2345 problemCount++; 2346 } 2347 } 2348 2349 { 2350 const wchar_t* source = L"test"; 2351 wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 2352 size_t result = wcslcpy(destination, source, 16); 2353 size_t expectedResult = 4; 2354 if (result != expectedResult) { 2355 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> result=%ld, " 2356 "expected %ld\n", source, result, expectedResult); 2357 problemCount++; 2358 } 2359 if (errno != 0) { 2360 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> errno=%d, " 2361 "expected 0\n", source, errno); 2362 problemCount++; 2363 } 2364 if (wcslen(destination) != 4) { 2365 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> " 2366 "wcslen(destination)=%lu, expected 4\n", source, 2367 wcslen(destination)); 2368 problemCount++; 2369 } 2370 if (destination[0] != L't') { 2371 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> " 2372 "destination[0]=%x, expected %x\n", source, destination[0], 2373 L't'); 2374 problemCount++; 2375 } 2376 if (destination[1] != L'e') { 2377 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> " 2378 "destination[1]=%x, expected %x\n", source, destination[1], 2379 L'e'); 2380 problemCount++; 2381 } 2382 if (destination[2] != L's') { 2383 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> " 2384 "destination[2]=%x, expected %x\n", source, destination[2], 2385 L's'); 2386 problemCount++; 2387 } 2388 if (destination[3] != L't') { 2389 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> " 2390 "destination[3]=%x, expected %x\n", source, destination[3], 2391 L't'); 2392 problemCount++; 2393 } 2394 if (destination[4] != L'\0') { 2395 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> " 2396 "destination[4]=%x, expected %x\n", source, destination[4], 2397 L'\0'); 2398 problemCount++; 2399 } 2400 if (destination[5] != L'X') { 2401 printf("\tPROBLEM: wcslcpy(destination, \"%ls\", 16) -> " 2402 "destination[5]=%x, expected %x\n", source, destination[5], 2403 L'X'); 2404 problemCount++; 2405 } 2406 } 2407 if (problemCount) 2408 printf("\t%d problem(s) found!\n", problemCount); 2409 else 2410 printf("\tall fine\n"); 2411 } 2412 2413 #endif 2414 2415 2416 // #pragma mark - collation ---------------------------------------------------- 2417 2418 2419 struct coll_data { 2420 const wchar_t* a; 2421 const wchar_t* b; 2422 int result; 2423 int err; 2424 }; 2425 2426 2427 void 2428 test_coll(bool useWcsxfrm, const char* locale, const coll_data coll[]) 2429 { 2430 setlocale(LC_COLLATE, locale); 2431 printf("%s in %s locale\n", useWcsxfrm ? "wcsxfrm" : "wcscoll", locale); 2432 2433 int problemCount = 0; 2434 for (unsigned int i = 0; coll[i].a != NULL; ++i) { 2435 errno = 0; 2436 int result; 2437 char funcCall[256]; 2438 if (useWcsxfrm) { 2439 wchar_t sortKeyA[100], sortKeyB[100]; 2440 wcsxfrm(sortKeyA, coll[i].a, 100); 2441 wcsxfrm(sortKeyB, coll[i].b, 100); 2442 result = sign(wcscmp(sortKeyA, sortKeyB)); 2443 sprintf(funcCall, "wcscmp(wcsxfrm(\"%ls\"), wcsxfrm(\"%ls\"))", 2444 coll[i].a, coll[i].b); 2445 } else { 2446 result = sign(wcscoll(coll[i].a, coll[i].b)); 2447 sprintf(funcCall, "wcscoll(\"%ls\", \"%ls\")", coll[i].a, 2448 coll[i].b); 2449 } 2450 2451 if (result != coll[i].result || errno != coll[i].err) { 2452 printf( 2453 "\tPROBLEM: %s = %d (expected %d), errno = %x (expected %x)\n", 2454 funcCall, result, coll[i].result, errno, coll[i].err); 2455 problemCount++; 2456 } 2457 } 2458 2459 if (problemCount) 2460 printf("\t%d problem(s) found!\n", problemCount); 2461 else 2462 printf("\tall fine\n"); 2463 } 2464 2465 2466 void 2467 test_collation() 2468 { 2469 const coll_data coll_posix[] = { 2470 { L"", L"", 0, 0 }, 2471 { L"test", L"test", 0, 0 }, 2472 { L"tester", L"test", 1, 0 }, 2473 { L"tEst", L"teSt", -1, 0 }, 2474 { L"test", L"tester", -1, 0 }, 2475 { L"tast", L"t\xE4st", -1, EINVAL }, 2476 { L"t\xE6st", L"test", 1, EINVAL }, 2477 { NULL, NULL, 0, 0 } 2478 }; 2479 test_coll(0, "POSIX", coll_posix); 2480 test_coll(1, "POSIX", coll_posix); 2481 2482 const coll_data coll_en[] = { 2483 { L"", L"", 0, 0 }, 2484 { L"test", L"test", 0, 0 }, 2485 { L"tester", L"test", 1, 0 }, 2486 { L"tEst", L"test", 1, 0 }, 2487 { L"test", L"tester", -1, 0 }, 2488 { L"t\xE4st", L"t\xE4st", 0, 0 }, 2489 { L"tast", L"t\xE4st", -1, 0 }, 2490 { L"tbst", L"t\xE4st", 1, 0 }, 2491 { L"tbst", L"t\xE6st", 1, 0 }, 2492 { L"t\xE4st", L"t\xC4st", -1, 0 }, 2493 { L"tBst", L"t\xC4st", 1, 0 }, 2494 { L"tBst", L"t\xE4st", 1, 0 }, 2495 { L"taest", L"t\xE6st", -1, 0 }, 2496 { L"tafst", L"t\xE6st", 1, 0 }, 2497 { L"taa", L"t\xE4"L"a", -1, 0 }, 2498 { L"tab", L"t\xE4"L"b", -1, 0 }, 2499 { L"tad", L"t\xE4"L"d", -1, 0 }, 2500 { L"tae", L"t\xE4"L"e", -1, 0 }, 2501 { L"taf", L"t\xE4"L"f", -1, 0 }, 2502 { L"cote", L"cot\xE9", -1, 0 }, 2503 { L"cot\xE9", L"c\xF4te", -1, 0 }, 2504 { L"c\xF4te", L"c\xF4t\xE9", -1, 0 }, 2505 { NULL, NULL, 0, 0 } 2506 }; 2507 test_coll(0, "en_US.UTF-8", coll_en); 2508 test_coll(1, "en_US.UTF-8", coll_en); 2509 2510 const coll_data coll_de[] = { 2511 { L"", L"", 0, 0 }, 2512 { L"test", L"test", 0, 0 }, 2513 { L"tester", L"test", 1, 0 }, 2514 { L"tEst", L"test", 1, 0 }, 2515 { L"test", L"tester", -1, 0 }, 2516 { L"t\xE4st", L"t\xE4st", 0, 0 }, 2517 { L"tast", L"t\xE4st", -1, 0 }, 2518 { L"tbst", L"t\xE4st", 1, 0 }, 2519 { L"tbst", L"t\xE6st", 1, 0 }, 2520 { L"t\xE4st", L"t\xC4st", -1, 0 }, 2521 { L"tBst", L"t\xC4st", 1, 0 }, 2522 { L"tBst", L"t\xE4st", 1, 0 }, 2523 { L"taest", L"t\xE6st", -1, 0 }, 2524 { L"tafst", L"t\xE6st", 1, 0 }, 2525 { L"taa", L"t\xE4", 1, 0 }, 2526 { L"tab", L"t\xE4", 1, 0 }, 2527 { L"tad", L"t\xE4", 1, 0 }, 2528 { L"tae", L"t\xE4", 1, 0 }, 2529 { L"taf", L"t\xE4", 1, 0 }, 2530 { L"cote", L"cot\xE9", -1, 0 }, 2531 { L"cot\xE9", L"c\xF4te", -1, 0 }, 2532 { L"c\xF4te", L"c\xF4t\xE9", -1, 0 }, 2533 { NULL, NULL, 0, 0 } 2534 }; 2535 test_coll(0, "de_DE.UTF-8", coll_de); 2536 test_coll(1, "de_DE.UTF-8", coll_de); 2537 2538 const coll_data coll_de_phonebook[] = { 2539 { L"", L"", 0, 0 }, 2540 { L"test", L"test", 0, 0 }, 2541 { L"tester", L"test", 1, 0 }, 2542 { L"tEst", L"test", 1, 0 }, 2543 { L"test", L"tester", -1, 0 }, 2544 { L"t\xE4st", L"t\xE4st", 0, 0 }, 2545 { L"tast", L"t\xE4st", 1, 0 }, 2546 { L"tbst", L"t\xE4st", 1, 0 }, 2547 { L"tbst", L"t\xE6st", 1, 0 }, 2548 { L"t\xE4st", L"t\xC4st", -1, 0 }, 2549 { L"tBst", L"t\xC4st", 1, 0 }, 2550 { L"tBst", L"t\xE4st", 1, 0 }, 2551 { L"taest", L"t\xE6st", -1, 0 }, 2552 { L"tafst", L"t\xE6st", 1, 0 }, 2553 { L"taa", L"t\xE4", -1, 0 }, 2554 { L"tab", L"t\xE4", -1, 0 }, 2555 { L"tad", L"t\xE4", -1, 0 }, 2556 { L"tae", L"t\xE4", -1, 0 }, 2557 { L"taf", L"t\xE4", 1, 0 }, 2558 { L"cote", L"cot\xE9", -1, 0 }, 2559 { L"cot\xE9", L"c\xF4te", -1, 0 }, 2560 { L"c\xF4te", L"c\xF4t\xE9", -1, 0 }, 2561 { NULL, NULL, 0, 0 } 2562 }; 2563 test_coll(0, "de_DE.UTF-8@collation=phonebook", coll_de_phonebook); 2564 test_coll(1, "de_DE.UTF-8@collation=phonebook", coll_de_phonebook); 2565 2566 const coll_data coll_fr[] = { 2567 { L"", L"", 0, 0 }, 2568 { L"test", L"test", 0, 0 }, 2569 { L"tester", L"test", 1, 0 }, 2570 { L"tEst", L"test", 1, 0 }, 2571 { L"test", L"tester", -1, 0 }, 2572 { L"t\xE4st", L"t\xE4st", 0, 0 }, 2573 { L"tast", L"t\xE4st", -1, 0 }, 2574 { L"tbst", L"t\xE4st", 1, 0 }, 2575 { L"tbst", L"t\xE6st", 1, 0 }, 2576 { L"t\xE4st", L"t\xC4st", -1, 0 }, 2577 { L"tBst", L"t\xC4st", 1, 0 }, 2578 { L"tBst", L"t\xE4st", 1, 0 }, 2579 { L"taest", L"t\xE6st", -1, 0 }, 2580 { L"tafst", L"t\xE6st", 1, 0 }, 2581 { L"taa", L"t\xE4", 1, 0 }, 2582 { L"tab", L"t\xE4", 1, 0 }, 2583 { L"tad", L"t\xE4", 1, 0 }, 2584 { L"tae", L"t\xE4", 1, 0 }, 2585 { L"taf", L"t\xE4", 1, 0 }, 2586 { L"cote", L"cot\xE9", -1, 0 }, 2587 { L"cot\xE9", L"c\xF4te", 1, 0 }, 2588 { L"c\xF4te", L"c\xF4t\xE9", -1, 0 }, 2589 { NULL, NULL, 0, 0 } 2590 }; 2591 // CLDR-1.9 has adjusted the defaults of fr_FR to no longer do reverse 2592 // ordering of secondary differences (accents), but fr_CA still does that 2593 // by default 2594 test_coll(0, "fr_CA.UTF-8", coll_fr); 2595 test_coll(1, "fr_CA.UTF-8", coll_fr); 2596 } 2597 2598 2599 // #pragma mark - wcsftime ----------------------------------------------------- 2600 2601 2602 struct wcsftime_data { 2603 const wchar_t* format; 2604 const wchar_t* result; 2605 }; 2606 2607 2608 void 2609 test_wcsftime(const char* locale, const wcsftime_data data[]) 2610 { 2611 setlocale(LC_TIME, locale); 2612 printf("wcsftime for '%s'\n", locale); 2613 2614 time_t nowSecs = 1279391169; // pure magic 2615 tm* now = localtime(&nowSecs); 2616 int problemCount = 0; 2617 for(int i = 0; data[i].format != NULL; ++i) { 2618 wchar_t buf[100]; 2619 wcsftime(buf, 100, data[i].format, now); 2620 if (wcscmp(buf, data[i].result) != 0) { 2621 printf( 2622 "\tPROBLEM: wcsftime(\"%ls\") = \"%ls\" (expected \"%ls\")\n", 2623 data[i].format, buf, data[i].result); 2624 problemCount++; 2625 } 2626 } 2627 if (problemCount) 2628 printf("\t%d problem(s) found!\n", problemCount); 2629 else 2630 printf("\tall fine\n"); 2631 } 2632 2633 2634 void 2635 test_wcsftime() 2636 { 2637 setenv("TZ", "GMT", 1); 2638 2639 const wcsftime_data wcsftime_posix[] = { 2640 { L"%c", L"Sat Jul 17 18:26:09 2010" }, 2641 { L"%x", L"07/17/10" }, 2642 { L"%X", L"18:26:09" }, 2643 { L"%a", L"Sat" }, 2644 { L"%A", L"Saturday" }, 2645 { L"%b", L"Jul" }, 2646 { L"%B", L"July" }, 2647 { NULL, NULL } 2648 }; 2649 test_wcsftime("POSIX", wcsftime_posix); 2650 2651 const wcsftime_data wcsftime_de[] = { 2652 { L"%c", L"Samstag, 17. Juli 2010 18:26:09 GMT" }, 2653 { L"%x", L"17.07.2010" }, 2654 { L"%X", L"18:26:09" }, 2655 { L"%a", L"Sa." }, 2656 { L"%A", L"Samstag" }, 2657 { L"%b", L"Jul" }, 2658 { L"%B", L"Juli" }, 2659 { NULL, NULL } 2660 }; 2661 test_wcsftime("de_DE.UTF-8", wcsftime_de); 2662 2663 const wcsftime_data wcsftime_hr[] = { 2664 { L"%c", L"subota, 17. srpnja 2010. 18:26:09 GMT" }, 2665 { L"%x", L"17. 07. 2010." }, 2666 { L"%X", L"18:26:09" }, 2667 { L"%a", L"sub" }, 2668 { L"%A", L"subota" }, 2669 { L"%b", L"srp" }, 2670 { L"%B", L"srpnja" }, 2671 { NULL, NULL } 2672 }; 2673 test_wcsftime("hr_HR.ISO8859-2", wcsftime_hr); 2674 2675 const wcsftime_data wcsftime_gu[] = { 2676 { L"%c", L"શનિવાર, 17 જુલાઈ, 2010 06:26:09 PM GMT" }, 2677 { L"%x", L"17 જુલાઈ, 2010" }, 2678 { L"%X", L"06:26:09 PM" }, 2679 { L"%a", L"શનિ" }, 2680 { L"%A", L"શનિવાર" }, 2681 { L"%b", L"જુલાઈ" }, 2682 { L"%B", L"જુલાઈ" }, 2683 { NULL, NULL } 2684 }; 2685 test_wcsftime("gu_IN", wcsftime_gu); 2686 2687 const wcsftime_data wcsftime_it[] = { 2688 { L"%c", L"sabato 17 luglio 2010 18:26:09 GMT" }, 2689 { L"%x", L"17/lug/2010" }, 2690 { L"%X", L"18:26:09" }, 2691 { L"%a", L"sab" }, 2692 { L"%A", L"sabato" }, 2693 { L"%b", L"lug" }, 2694 { L"%B", L"luglio" }, 2695 { NULL, NULL } 2696 }; 2697 test_wcsftime("it_IT", wcsftime_it); 2698 2699 const wcsftime_data wcsftime_nl[] = { 2700 { L"%c", L"zaterdag 17 juli 2010 18:26:09 GMT" }, 2701 { L"%x", L"17 jul. 2010" }, 2702 { L"%X", L"18:26:09" }, 2703 { L"%a", L"za" }, 2704 { L"%A", L"zaterdag" }, 2705 { L"%b", L"jul." }, 2706 { L"%B", L"juli" }, 2707 { NULL, NULL } 2708 }; 2709 test_wcsftime("nl_NL", wcsftime_nl); 2710 2711 const wcsftime_data wcsftime_nb[] = { 2712 { L"%c", L"kl. 18:26:09 GMT lørdag 17. juli 2010" }, 2713 { L"%x", L"17. juli 2010" }, 2714 { L"%X", L"18:26:09" }, 2715 { L"%a", L"lør." }, 2716 { L"%A", L"lørdag" }, 2717 { L"%b", L"juli" }, 2718 { L"%B", L"juli" }, 2719 { NULL, NULL } 2720 }; 2721 test_wcsftime("nb_NO", wcsftime_nb); 2722 } 2723 2724 2725 // #pragma mark - wcspbrk ------------------------------------------------------ 2726 2727 2728 void 2729 test_wcspbrk() 2730 { 2731 printf("wcspbrk()\n"); 2732 2733 int problemCount = 0; 2734 errno = 0; 2735 2736 { 2737 const wchar_t* string = L""; 2738 const wchar_t* accept = L" "; 2739 const wchar_t* result = wcspbrk(string, accept); 2740 const wchar_t* expected = NULL; 2741 if (result != expected || errno != 0) { 2742 printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p " 2743 "(expected %p), errno = %x (expected 0)\n", string, accept, 2744 result, expected, errno); 2745 problemCount++; 2746 } 2747 } 2748 2749 { 2750 const wchar_t* string = L"sometext"; 2751 const wchar_t* accept = L" "; 2752 const wchar_t* result = wcspbrk(string, accept); 2753 const wchar_t* expected = NULL; 2754 if (result != expected || errno != 0) { 2755 printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p " 2756 "(expected %p), errno = %x (expected 0)\n", string, accept, 2757 result, expected, errno); 2758 problemCount++; 2759 } 2760 } 2761 2762 { 2763 const wchar_t* string = L"some more text"; 2764 const wchar_t* accept = L" "; 2765 const wchar_t* result = wcspbrk(string, accept); 2766 const wchar_t* expected = string + 4; 2767 if (result != expected || errno != 0) { 2768 printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p " 2769 "(expected %p), errno = %x (expected 0)\n", string, accept, 2770 result, expected, errno); 2771 problemCount++; 2772 } 2773 } 2774 2775 { 2776 const wchar_t* string = L"some more text"; 2777 const wchar_t* accept = L"UY\xE4 "; 2778 const wchar_t* result = wcspbrk(string, accept); 2779 const wchar_t* expected = string + 4; 2780 if (result != expected || errno != 0) { 2781 printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p " 2782 "(expected %p), errno = %x (expected 0)\n", string, accept, 2783 result, expected, errno); 2784 problemCount++; 2785 } 2786 } 2787 2788 { 2789 const wchar_t* string = L"some more text"; 2790 const wchar_t* accept = L" emorstx"; 2791 const wchar_t* result = wcspbrk(string, accept); 2792 const wchar_t* expected = string; 2793 if (result != expected || errno != 0) { 2794 printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p " 2795 "(expected %p), errno = %x (expected 0)\n", string, accept, 2796 result, expected, errno); 2797 problemCount++; 2798 } 2799 } 2800 2801 { 2802 const wchar_t* string = L"some more text"; 2803 const wchar_t* accept = L"EMORSTX\xA0"; 2804 const wchar_t* result = wcspbrk(string, accept); 2805 const wchar_t* expected = NULL; 2806 if (result != expected || errno != 0) { 2807 printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p " 2808 "(expected %p), errno = %x (expected 0)\n", string, accept, 2809 result, expected, errno); 2810 problemCount++; 2811 } 2812 } 2813 2814 if (problemCount) 2815 printf("\t%d problem(s) found!\n", problemCount); 2816 else 2817 printf("\tall fine\n"); 2818 } 2819 2820 2821 // #pragma mark - wcscspn ------------------------------------------------------- 2822 2823 2824 void 2825 test_wcscspn() 2826 { 2827 printf("wcscspn()\n"); 2828 2829 int problemCount = 0; 2830 errno = 0; 2831 2832 { 2833 const wchar_t* string = L""; 2834 const wchar_t* reject = L" "; 2835 size_t result = wcscspn(string, reject); 2836 size_t expected = 0; 2837 if (result != expected || errno != 0) { 2838 printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld " 2839 "(expected %ld), errno = %x (expected 0)\n", string, reject, 2840 result, expected, errno); 2841 problemCount++; 2842 } 2843 } 2844 2845 { 2846 const wchar_t* string = L"sometext"; 2847 const wchar_t* reject = L" "; 2848 size_t result = wcscspn(string, reject); 2849 size_t expected = 8; 2850 if (result != expected || errno != 0) { 2851 printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld " 2852 "(expected %ld), errno = %x (expected 0)\n", string, reject, 2853 result, expected, errno); 2854 problemCount++; 2855 } 2856 } 2857 2858 { 2859 const wchar_t* string = L"some more text"; 2860 const wchar_t* reject = L" mos"; 2861 size_t result = wcscspn(string, reject); 2862 size_t expected = 0; 2863 if (result != expected || errno != 0) { 2864 printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld " 2865 "(expected %ld), errno = %x (expected 0)\n", string, reject, 2866 result, expected, errno); 2867 problemCount++; 2868 } 2869 } 2870 2871 { 2872 const wchar_t* string = L"some more text"; 2873 const wchar_t* reject = L"t"; 2874 size_t result = wcscspn(string, reject); 2875 size_t expected = 10; 2876 if (result != expected || errno != 0) { 2877 printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld " 2878 "(expected %ld), errno = %x (expected 0)\n", string, reject, 2879 result, expected, errno); 2880 problemCount++; 2881 } 2882 } 2883 2884 { 2885 const wchar_t* string = L"some more text"; 2886 const wchar_t* reject = L"abcdfghijklnpquvwyz\t"; 2887 size_t result = wcscspn(string, reject); 2888 size_t expected = wcslen(string); 2889 if (result != expected || errno != 0) { 2890 printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld " 2891 "(expected %ld), errno = %x (expected 0)\n", string, reject, 2892 result, expected, errno); 2893 problemCount++; 2894 } 2895 } 2896 2897 { 2898 const wchar_t* string = L"some more text"; 2899 const wchar_t* reject = L""; 2900 size_t result = wcscspn(string, reject); 2901 size_t expected = wcslen(string); 2902 if (result != expected || errno != 0) { 2903 printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld " 2904 "(expected %ld), errno = %x (expected 0)\n", string, reject, 2905 result, expected, errno); 2906 problemCount++; 2907 } 2908 } 2909 2910 if (problemCount) 2911 printf("\t%d problem(s) found!\n", problemCount); 2912 else 2913 printf("\tall fine\n"); 2914 } 2915 2916 2917 // #pragma mark - wcsspn ------------------------------------------------------- 2918 2919 2920 void 2921 test_wcsspn() 2922 { 2923 printf("wcsspn()\n"); 2924 2925 int problemCount = 0; 2926 errno = 0; 2927 2928 { 2929 const wchar_t* string = L""; 2930 const wchar_t* accept = L" "; 2931 size_t result = wcsspn(string, accept); 2932 size_t expected = 0; 2933 if (result != expected || errno != 0) { 2934 printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld " 2935 "(expected %ld), errno = %x (expected 0)\n", string, accept, 2936 result, expected, errno); 2937 problemCount++; 2938 } 2939 } 2940 2941 { 2942 const wchar_t* string = L"sometext"; 2943 const wchar_t* accept = L" "; 2944 size_t result = wcsspn(string, accept); 2945 size_t expected = 0; 2946 if (result != expected || errno != 0) { 2947 printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld " 2948 "(expected %ld), errno = %x (expected 0)\n", string, accept, 2949 result, expected, errno); 2950 problemCount++; 2951 } 2952 } 2953 2954 { 2955 const wchar_t* string = L"some more text"; 2956 const wchar_t* accept = L" emo"; 2957 size_t result = wcsspn(string, accept); 2958 size_t expected = 0; 2959 if (result != expected || errno != 0) { 2960 printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld " 2961 "(expected %ld), errno = %x (expected 0)\n", string, accept, 2962 result, expected, errno); 2963 problemCount++; 2964 } 2965 } 2966 2967 { 2968 const wchar_t* string = L"some more text"; 2969 const wchar_t* accept = L" emorstx"; 2970 size_t result = wcsspn(string, accept); 2971 size_t expected = wcslen(string); 2972 if (result != expected || errno != 0) { 2973 printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld " 2974 "(expected %ld), errno = %x (expected 0)\n", string, accept, 2975 result, expected, errno); 2976 problemCount++; 2977 } 2978 } 2979 2980 { 2981 const wchar_t* string = L"some more text"; 2982 const wchar_t* accept = L""; 2983 size_t result = wcsspn(string, accept); 2984 size_t expected = 0; 2985 if (result != expected || errno != 0) { 2986 printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld " 2987 "(expected %ld), errno = %x (expected 0)\n", string, accept, 2988 result, expected, errno); 2989 problemCount++; 2990 } 2991 } 2992 2993 if (problemCount) 2994 printf("\t%d problem(s) found!\n", problemCount); 2995 else 2996 printf("\tall fine\n"); 2997 } 2998 2999 3000 // #pragma mark - wcsstr ------------------------------------------------------ 3001 3002 3003 void 3004 test_wcsstr() 3005 { 3006 printf("wcsstr()\n"); 3007 3008 int problemCount = 0; 3009 errno = 0; 3010 3011 { 3012 const wchar_t* string = L""; 3013 const wchar_t* sought = L" "; 3014 const wchar_t* result = wcsstr(string, sought); 3015 const wchar_t* expected = NULL; 3016 if (result != expected || errno != 0) { 3017 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3018 "(expected %p), errno = %x (expected 0)\n", string, sought, 3019 result, expected, errno); 3020 problemCount++; 3021 } 3022 } 3023 3024 { 3025 const wchar_t* string = L"sometext"; 3026 const wchar_t* sought = L"som "; 3027 const wchar_t* result = wcsstr(string, sought); 3028 const wchar_t* expected = NULL; 3029 if (result != expected || errno != 0) { 3030 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3031 "(expected %p), errno = %x (expected 0)\n", string, sought, 3032 result, expected, errno); 3033 problemCount++; 3034 } 3035 } 3036 3037 { 3038 const wchar_t* string = L"sometext"; 3039 const wchar_t* sought = L"soMe"; 3040 const wchar_t* result = wcsstr(string, sought); 3041 const wchar_t* expected = NULL; 3042 if (result != expected || errno != 0) { 3043 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3044 "(expected %p), errno = %x (expected 0)\n", string, sought, 3045 result, expected, errno); 3046 problemCount++; 3047 } 3048 } 3049 3050 { 3051 const wchar_t* string = L"some more text"; 3052 const wchar_t* sought = L"some "; 3053 const wchar_t* result = wcsstr(string, sought); 3054 const wchar_t* expected = string; 3055 if (result != expected || errno != 0) { 3056 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3057 "(expected %p), errno = %x (expected 0)\n", string, sought, 3058 result, expected, errno); 3059 problemCount++; 3060 } 3061 } 3062 3063 { 3064 const wchar_t* string = L"some more text"; 3065 const wchar_t* sought = L" more"; 3066 const wchar_t* result = wcsstr(string, sought); 3067 const wchar_t* expected = string + 4; 3068 if (result != expected || errno != 0) { 3069 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3070 "(expected %p), errno = %x (expected 0)\n", string, sought, 3071 result, expected, errno); 3072 problemCount++; 3073 } 3074 } 3075 3076 { 3077 const wchar_t* string = L"some more text"; 3078 const wchar_t* sought = L"some more text"; 3079 const wchar_t* result = wcsstr(string, sought); 3080 const wchar_t* expected = string; 3081 if (result != expected || errno != 0) { 3082 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3083 "(expected %p), errno = %x (expected 0)\n", string, sought, 3084 result, expected, errno); 3085 problemCount++; 3086 } 3087 } 3088 3089 { 3090 const wchar_t* string = L"some more text"; 3091 const wchar_t* sought = L"some more text "; 3092 const wchar_t* result = wcsstr(string, sought); 3093 const wchar_t* expected = NULL; 3094 if (result != expected || errno != 0) { 3095 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3096 "(expected %p), errno = %x (expected 0)\n", string, sought, 3097 result, expected, errno); 3098 problemCount++; 3099 } 3100 } 3101 3102 if (problemCount) 3103 printf("\t%d problem(s) found!\n", problemCount); 3104 else 3105 printf("\tall fine\n"); 3106 } 3107 3108 3109 // #pragma mark - wcstok ------------------------------------------------------ 3110 3111 3112 void 3113 test_wcstok() 3114 { 3115 printf("wcstok()\n"); 3116 3117 int problemCount = 0; 3118 3119 { 3120 wchar_t string[] = L""; 3121 const wchar_t* delim = L" \t\n"; 3122 wchar_t* state; 3123 wchar_t* result = wcstok(string, delim, &state); 3124 wchar_t* expected = NULL; 3125 wchar_t* expectedState = NULL; 3126 if (result != expected || state != expectedState) { 3127 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3128 "(expected %p), state = %p (expected %p)\n", string, delim, 3129 &state, result, expected, state, expectedState); 3130 problemCount++; 3131 } 3132 3133 result = wcstok(NULL, delim, &state); 3134 expected = NULL; 3135 expectedState = NULL; 3136 if (result != expected || state != expectedState) { 3137 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3138 "(expected %p), state = %p (expected %p)\n", string, delim, 3139 &state, result, expected, state, expectedState); 3140 problemCount++; 3141 } 3142 } 3143 3144 { 3145 wchar_t string[] = L"\t\t\t\n \t"; 3146 const wchar_t* delim = L" \t\n"; 3147 wchar_t* state; 3148 wchar_t* result = wcstok(string, delim, &state); 3149 wchar_t* expected = NULL; 3150 wchar_t* expectedState = NULL; 3151 if (result != expected || state != expectedState) { 3152 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3153 "(expected %p), state = %p (expected %p)\n", string, delim, 3154 &state, result, expected, state, expectedState); 3155 problemCount++; 3156 } 3157 3158 result = wcstok(NULL, delim, &state); 3159 expected = NULL; 3160 expectedState = NULL; 3161 if (result != expected || state != expectedState) { 3162 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3163 "(expected %p), state = %p (expected %p)\n", string, delim, 3164 &state, result, expected, state, expectedState); 3165 problemCount++; 3166 } 3167 } 3168 3169 { 3170 wchar_t string[] = L"just some text here!"; 3171 const wchar_t* delim = L" "; 3172 wchar_t* state; 3173 wchar_t* result = wcstok(string, delim, &state); 3174 wchar_t* expected = string; 3175 wchar_t* expectedState = string + 5; 3176 if (result != expected || state != expectedState) { 3177 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3178 "(expected %p), state = %p (expected %p)\n", string, delim, 3179 &state, result, expected, state, expectedState); 3180 problemCount++; 3181 } 3182 3183 result = wcstok(NULL, delim, &state); 3184 expected = string + 5; 3185 expectedState = string + 10; 3186 if (result != expected || state != expectedState) { 3187 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3188 "(expected %p), state = %p (expected %p)\n", string, delim, 3189 &state, result, expected, state, expectedState); 3190 problemCount++; 3191 } 3192 3193 result = wcstok(NULL, delim, &state); 3194 expected = string + 10; 3195 expectedState = string + 15; 3196 if (result != expected || state != expectedState) { 3197 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3198 "(expected %p), state = %p (expected %p)\n", string, delim, 3199 &state, result, expected, state, expectedState); 3200 problemCount++; 3201 } 3202 3203 result = wcstok(NULL, delim, &state); 3204 expected = string + 15; 3205 expectedState = NULL; 3206 if (result != expected || state != expectedState) { 3207 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3208 "(expected %p), state = %p (expected %p)\n", string, delim, 3209 &state, result, expected, state, expectedState); 3210 problemCount++; 3211 } 3212 3213 result = wcstok(NULL, delim, &state); 3214 expected = NULL; 3215 expectedState = NULL; 3216 if (result != expected || state != expectedState) { 3217 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3218 "(expected %p), state = %p (expected %p)\n", string, delim, 3219 &state, result, expected, state, expectedState); 3220 problemCount++; 3221 } 3222 } 3223 3224 { 3225 wchar_t string[] = L" just \t\nsome\t\t\ttext\n\n\nhere!"; 3226 const wchar_t* delim = L"\n\t "; 3227 wchar_t* state; 3228 wchar_t* result = wcstok(string, delim, &state); 3229 wchar_t* expected = string + 1; 3230 wchar_t* expectedState = string + 6; 3231 if (result != expected || state != expectedState) { 3232 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3233 "(expected %p), state = %p (expected %p)\n", string, delim, 3234 &state, result, expected, state, expectedState); 3235 problemCount++; 3236 } 3237 if (wcscmp(result, L"just") != 0) { 3238 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %ls " 3239 "(expected %ls)\n", string, delim, &state, result, L"just"); 3240 problemCount++; 3241 } 3242 3243 result = wcstok(NULL, delim, &state); 3244 expected = string + 8; 3245 expectedState = string + 13; 3246 if (result != expected || state != expectedState) { 3247 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3248 "(expected %p), state = %p (expected %p)\n", string, delim, 3249 &state, result, expected, state, expectedState); 3250 problemCount++; 3251 } 3252 if (wcscmp(result, L"some") != 0) { 3253 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %ls " 3254 "(expected %ls)\n", string, delim, &state, result, L"some"); 3255 problemCount++; 3256 } 3257 3258 result = wcstok(NULL, delim, &state); 3259 expected = string + 15; 3260 expectedState = string + 20; 3261 if (result != expected || state != expectedState) { 3262 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3263 "(expected %p), state = %p (expected %p)\n", string, delim, 3264 &state, result, expected, state, expectedState); 3265 problemCount++; 3266 } 3267 if (wcscmp(result, L"text") != 0) { 3268 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %ls " 3269 "(expected %ls)\n", string, delim, &state, result, L"text"); 3270 problemCount++; 3271 } 3272 3273 result = wcstok(NULL, delim, &state); 3274 expected = string + 22; 3275 expectedState = NULL; 3276 if (result != expected || state != expectedState) { 3277 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3278 "(expected %p), state = %p (expected %p)\n", string, delim, 3279 &state, result, expected, state, expectedState); 3280 problemCount++; 3281 } 3282 if (wcscmp(result, L"here!") != 0) { 3283 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %ls " 3284 "(expected %ls)\n", string, delim, &state, result, L"here!"); 3285 problemCount++; 3286 } 3287 3288 result = wcstok(NULL, delim, &state); 3289 expected = NULL; 3290 expectedState = NULL; 3291 if (result != expected || state != expectedState) { 3292 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3293 "(expected %p), state = %p (expected %p)\n", string, delim, 3294 &state, result, expected, state, expectedState); 3295 problemCount++; 3296 } 3297 } 3298 3299 if (problemCount) 3300 printf("\t%d problem(s) found!\n", problemCount); 3301 else 3302 printf("\tall fine\n"); 3303 } 3304 3305 3306 // #pragma mark - wmemchr ------------------------------------------------------ 3307 3308 3309 void 3310 test_wmemchr() 3311 { 3312 printf("wmemchr()\n"); 3313 3314 int problemCount = 0; 3315 errno = 0; 3316 3317 { 3318 const wchar_t* string = L""; 3319 const wchar_t ch = L' '; 3320 const wchar_t* result = wmemchr(string, ch, 0); 3321 const wchar_t* expected = NULL; 3322 if (result != expected || errno != 0) { 3323 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 0) = %p " 3324 "(expected %p), errno = %x (expected 0)\n", string, ch, 3325 result, expected, errno); 3326 problemCount++; 3327 } 3328 } 3329 3330 { 3331 const wchar_t* string = L""; 3332 const wchar_t ch = L'\0'; 3333 const wchar_t* result = wmemchr(string, ch, 0); 3334 const wchar_t* expected = NULL; 3335 if (result != expected || errno != 0) { 3336 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 0) = %p " 3337 "(expected %p), errno = %x (expected 0)\n", string, ch, 3338 result, expected, errno); 3339 problemCount++; 3340 } 3341 } 3342 3343 { 3344 const wchar_t* string = L""; 3345 const wchar_t ch = L'\0'; 3346 const wchar_t* result = wmemchr(string, ch, 1); 3347 const wchar_t* expected = string; 3348 if (result != expected || errno != 0) { 3349 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p " 3350 "(expected %p), errno = %x (expected 0)\n", string, ch, 3351 result, expected, errno); 3352 problemCount++; 3353 } 3354 } 3355 3356 { 3357 const wchar_t* string = L"sometext"; 3358 const wchar_t ch = L' '; 3359 const wchar_t* result = wmemchr(string, ch, 8); 3360 const wchar_t* expected = NULL; 3361 if (result != expected || errno != 0) { 3362 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p " 3363 "(expected %p), errno = %x (expected 0)\n", string, ch, 3364 result, expected, errno); 3365 problemCount++; 3366 } 3367 } 3368 3369 { 3370 const wchar_t* string = L"some text"; 3371 const wchar_t ch = L' '; 3372 const wchar_t* result = wmemchr(string, ch, 9); 3373 const wchar_t* expected = string + 4; 3374 if (result != expected || errno != 0) { 3375 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p " 3376 "(expected %p), errno = %x (expected 0)\n", string, ch, 3377 result, expected, errno); 3378 problemCount++; 3379 } 3380 } 3381 3382 { 3383 const wchar_t* string = L"some text"; 3384 const wchar_t ch = L'M'; 3385 const wchar_t* result = wmemchr(string, ch, 9); 3386 const wchar_t* expected = NULL; 3387 if (result != expected || errno != 0) { 3388 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p " 3389 "(expected %p), errno = %x (expected 0)\n", string, ch, 3390 result, expected, errno); 3391 problemCount++; 3392 } 3393 } 3394 3395 { 3396 const wchar_t* string = L"some\0text"; 3397 const wchar_t ch = L't'; 3398 const wchar_t* result = wmemchr(string, ch, 4); 3399 const wchar_t* expected = NULL; 3400 if (result != expected || errno != 0) { 3401 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p " 3402 "(expected %p), errno = %x (expected 0)\n", string, ch, 3403 result, expected, errno); 3404 problemCount++; 3405 } 3406 } 3407 3408 { 3409 const wchar_t* string = L"some\0text"; 3410 const wchar_t ch = L't'; 3411 const wchar_t* result = wmemchr(string, ch, 9); 3412 const wchar_t* expected = string + 5; 3413 if (result != expected || errno != 0) { 3414 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p " 3415 "(expected %p), errno = %x (expected 0)\n", string, ch, 3416 result, expected, errno); 3417 problemCount++; 3418 } 3419 } 3420 3421 if (problemCount) 3422 printf("\t%d problem(s) found!\n", problemCount); 3423 else 3424 printf("\tall fine\n"); 3425 } 3426 3427 3428 // #pragma mark - wmemcmp ------------------------------------------------------ 3429 3430 3431 void 3432 test_wmemcmp() 3433 { 3434 printf("wmemcmp()\n"); 3435 3436 int problemCount = 0; 3437 errno = 0; 3438 3439 { 3440 const wchar_t* a = L""; 3441 const wchar_t* b = L""; 3442 int result = sign(wmemcmp(a, b, 0)); 3443 int expected = 0; 3444 if (result != expected || errno != 0) { 3445 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 0) = %d " 3446 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3447 expected, errno); 3448 problemCount++; 3449 } 3450 } 3451 3452 { 3453 const wchar_t* a = L""; 3454 const wchar_t* b = L""; 3455 int result = sign(wmemcmp(a, b, 1)); 3456 int expected = 0; 3457 if (result != expected || errno != 0) { 3458 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 0) = %d " 3459 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3460 expected, errno); 3461 problemCount++; 3462 } 3463 } 3464 3465 { 3466 const wchar_t* a = L"a"; 3467 const wchar_t* b = L"b"; 3468 int result = sign(wmemcmp(a, b, 0)); 3469 int expected = 0; 3470 if (result != expected || errno != 0) { 3471 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 0) = %d " 3472 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3473 expected, errno); 3474 problemCount++; 3475 } 3476 } 3477 3478 { 3479 const wchar_t* a = L"a"; 3480 const wchar_t* b = L"b"; 3481 int result = sign(wmemcmp(a, b, 1)); 3482 int expected = -1; 3483 if (result != expected || errno != 0) { 3484 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 1) = %d " 3485 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3486 expected, errno); 3487 problemCount++; 3488 } 3489 } 3490 3491 { 3492 const wchar_t* a = L"b"; 3493 const wchar_t* b = L"a"; 3494 int result = sign(wmemcmp(a, b, 2)); 3495 int expected = 1; 3496 if (result != expected || errno != 0) { 3497 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 2) = %d " 3498 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3499 expected, errno); 3500 problemCount++; 3501 } 3502 } 3503 3504 { 3505 const wchar_t* a = L"a"; 3506 const wchar_t* b = L"A"; 3507 int result = sign(wmemcmp(a, b, 2)); 3508 int expected = 1; 3509 if (result != expected || errno != 0) { 3510 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 2) = %d " 3511 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3512 expected, errno); 3513 problemCount++; 3514 } 3515 } 3516 3517 { 3518 const wchar_t* a = L"täst"; 3519 const wchar_t* b = L"täst"; 3520 int result = sign(wmemcmp(a, b, 5)); 3521 int expected = 0; 3522 if (result != expected || errno != 0) { 3523 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 5) = %d " 3524 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3525 expected, errno); 3526 problemCount++; 3527 } 3528 } 3529 3530 { 3531 const wchar_t* a = L"täst"; 3532 const wchar_t* b = L"täst "; 3533 int result = sign(wmemcmp(a, b, 5)); 3534 int expected = -1; 3535 if (result != expected || errno != 0) { 3536 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 5) = %d " 3537 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3538 expected, errno); 3539 problemCount++; 3540 } 3541 } 3542 3543 { 3544 const wchar_t* a = L"täSt"; 3545 const wchar_t* b = L"täs"; 3546 int result = sign(wmemcmp(a, b, 2)); 3547 int expected = 0; 3548 if (result != expected || errno != 0) { 3549 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 2) = %d " 3550 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3551 expected, errno); 3552 problemCount++; 3553 } 3554 } 3555 3556 if (problemCount) 3557 printf("\t%d problem(s) found!\n", problemCount); 3558 else 3559 printf("\tall fine\n"); 3560 } 3561 3562 3563 // #pragma mark - wmemcpy ------------------------------------------------------ 3564 3565 3566 void 3567 test_wmemcpy() 3568 { 3569 printf("wmemcpy()\n"); 3570 3571 int problemCount = 0; 3572 errno = 0; 3573 3574 { 3575 const wchar_t* source = L""; 3576 wchar_t destination[] = L"XXXX"; 3577 wchar_t* result = wmemcpy(destination, source, 0); 3578 if (result != destination || errno != 0) { 3579 printf("\tPROBLEM: result for wmemcpy(destination, \"%ls\", 0) = " 3580 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3581 result, destination, errno); 3582 problemCount++; 3583 } 3584 if (destination[0] != L'X') { 3585 printf("\tPROBLEM: wmemcpy(destination, \"%ls\", 0) -> " 3586 "destination[0]=%x, expected %x\n", source, destination[0], 3587 L'X'); 3588 problemCount++; 3589 } 3590 } 3591 3592 { 3593 const wchar_t* source = L""; 3594 wchar_t destination[] = L"XXXX"; 3595 wchar_t* result = wmemcpy(destination, source, 1); 3596 if (result != destination || wmemcmp(destination, source, 1) != 0 3597 || errno != 0) { 3598 printf("\tPROBLEM: result for wmemcpy(destination, \"%ls\", 1) = " 3599 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3600 result, destination, errno); 3601 problemCount++; 3602 } 3603 if (destination[1] != L'X') { 3604 printf("\tPROBLEM: wmemcpy(destination, \"%ls\", 1) -> " 3605 "destination[1]=%x, expected %x\n", source, destination[1], 3606 L'X'); 3607 problemCount++; 3608 } 3609 } 3610 3611 { 3612 const wchar_t* source = L"tÄstdata \0with some charäcters"; 3613 wchar_t destination[64]; 3614 wchar_t* result = wmemcpy(destination, source, 31); 3615 if (result != destination || wmemcmp(destination, source, 31) != 0 3616 || errno != 0) { 3617 printf("\tPROBLEM: result for wmemcpy(destination, \"%ls\", 31) = " 3618 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3619 result, destination, errno); 3620 problemCount++; 3621 } 3622 } 3623 3624 if (problemCount) 3625 printf("\t%d problem(s) found!\n", problemCount); 3626 else 3627 printf("\tall fine\n"); 3628 } 3629 3630 3631 // #pragma mark - wmempcpy ------------------------------------------------------ 3632 3633 3634 void 3635 test_wmempcpy() 3636 { 3637 printf("wmempcpy()\n"); 3638 3639 int problemCount = 0; 3640 errno = 0; 3641 3642 { 3643 const wchar_t* source = L""; 3644 wchar_t destination[] = L"XXXX"; 3645 wchar_t* result = wmempcpy(destination, source, 0); 3646 if (result != destination || errno != 0) { 3647 printf("\tPROBLEM: result for wmempcpy(destination, \"%ls\", 0) = " 3648 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3649 result, destination, errno); 3650 problemCount++; 3651 } 3652 if (destination[0] != L'X') { 3653 printf("\tPROBLEM: wmempcpy(destination, \"%ls\", 0) -> " 3654 "destination[0]=%x, expected %x\n", source, destination[0], 3655 L'X'); 3656 problemCount++; 3657 } 3658 } 3659 3660 { 3661 const wchar_t* source = L""; 3662 wchar_t destination[] = L"XXXX"; 3663 wchar_t* result = wmempcpy(destination, source, 1); 3664 if (result != destination + 1 || wmemcmp(destination, source, 1) != 0 3665 || errno != 0) { 3666 printf("\tPROBLEM: result for wmempcpy(destination, \"%ls\", 1) = " 3667 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3668 result, destination, errno); 3669 problemCount++; 3670 } 3671 if (destination[1] != L'X') { 3672 printf("\tPROBLEM: wmempcpy(destination, \"%ls\", 1) -> " 3673 "destination[1]=%x, expected %x\n", source, destination[1], 3674 L'X'); 3675 problemCount++; 3676 } 3677 } 3678 3679 { 3680 const wchar_t* source = L"tÄstdata \0with some charäcters"; 3681 wchar_t destination[64]; 3682 wchar_t* result = wmempcpy(destination, source, 31); 3683 if (result != destination + 31 || wmemcmp(destination, source, 31) != 0 3684 || errno != 0) { 3685 printf("\tPROBLEM: result for wmempcpy(destination, \"%ls\", 31) = " 3686 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3687 result, destination, errno); 3688 problemCount++; 3689 } 3690 } 3691 3692 if (problemCount) 3693 printf("\t%d problem(s) found!\n", problemCount); 3694 else 3695 printf("\tall fine\n"); 3696 } 3697 3698 3699 // #pragma mark - wmemmove ------------------------------------------------------ 3700 3701 3702 void 3703 test_wmemmove() 3704 { 3705 printf("wmemmove()\n"); 3706 3707 int problemCount = 0; 3708 errno = 0; 3709 3710 { 3711 const wchar_t* source = L""; 3712 wchar_t destination[] = L"XXXX"; 3713 wchar_t* result = wmemmove(destination, source, 0); 3714 if (result != destination || errno != 0) { 3715 printf("\tPROBLEM: result for wmemmove(destination, \"%ls\", 0) = " 3716 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3717 result, destination, errno); 3718 problemCount++; 3719 } 3720 if (destination[0] != L'X') { 3721 printf("\tPROBLEM: wmemmove(destination, \"%ls\", 0) -> " 3722 "destination[0]=%x, expected %x\n", source, destination[0], 3723 L'X'); 3724 problemCount++; 3725 } 3726 } 3727 3728 { 3729 const wchar_t* source = L""; 3730 wchar_t destination[] = L"XXXX"; 3731 wchar_t* result = wmemmove(destination, source, 1); 3732 if (result != destination || wmemcmp(destination, source, 1) != 0 3733 || errno != 0) { 3734 printf("\tPROBLEM: result for wmemmove(destination, \"%ls\", 1) = " 3735 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3736 result, destination, errno); 3737 problemCount++; 3738 } 3739 if (destination[1] != L'X') { 3740 printf("\tPROBLEM: wmemmove(destination, \"%ls\", 1) -> " 3741 "destination[1]=%x, expected %x\n", source, destination[1], 3742 L'X'); 3743 problemCount++; 3744 } 3745 } 3746 3747 { 3748 const wchar_t* source = L"tÄstdata \0with some charäcters"; 3749 wchar_t destination[64]; 3750 wmemcpy(destination, source, 31); 3751 wchar_t* result = wmemmove(destination, destination + 4, 27); 3752 if (result != destination || wmemcmp(destination, source + 4, 27) != 0 3753 || errno != 0) { 3754 printf("\tPROBLEM: result for wmemmove(destination, \"%ls\", 27) = " 3755 "\"%ls\" (expected %p), errno = %x (expected 0)\n", 3756 source + 4, result, destination, errno); 3757 problemCount++; 3758 } 3759 } 3760 3761 { 3762 const wchar_t* source = L"tÄstdata \0with some charäcters"; 3763 wchar_t destination[64]; 3764 wmemcpy(destination, source, 31); 3765 wchar_t* result = wmemmove(destination + 2, destination, 8); 3766 if (result != destination + 2 3767 || wmemcmp(destination, L"tÄtÄstdatawith some charäcters", 31) != 0 3768 || errno != 0) { 3769 printf("\tPROBLEM: result for wmemmove(destination + 9, \"%ls\", 8)" 3770 " = \"%ls\" (expected %p), errno = %x (expected 0)\n", 3771 source, result, destination, errno); 3772 problemCount++; 3773 } 3774 } 3775 3776 if (problemCount) 3777 printf("\t%d problem(s) found!\n", problemCount); 3778 else 3779 printf("\tall fine\n"); 3780 } 3781 3782 3783 // #pragma mark - wmemset ------------------------------------------------------ 3784 3785 3786 void 3787 test_wmemset() 3788 { 3789 printf("wmemset()\n"); 3790 3791 int problemCount = 0; 3792 errno = 0; 3793 3794 { 3795 wchar_t source = L'\0'; 3796 wchar_t destination[] = L"XXXX"; 3797 wchar_t* result = wmemset(destination, source, 0); 3798 if (result != destination || errno != 0) { 3799 printf("\tPROBLEM: result for wmemset(destination, '%lc', 0) = " 3800 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3801 result, destination, errno); 3802 problemCount++; 3803 } 3804 if (destination[0] != L'X') { 3805 printf("\tPROBLEM: wmemset(destination, '%lc', 0) -> " 3806 "destination[0]=%x, expected %x\n", source, destination[0], 3807 L'X'); 3808 problemCount++; 3809 } 3810 } 3811 3812 { 3813 wchar_t source = L'M'; 3814 wchar_t destination[] = L"some text"; 3815 wchar_t* result = wmemset(destination, source, 1); 3816 if (result != destination || errno != 0) { 3817 printf("\tPROBLEM: result for wmemset(destination, '%lc', 1) = " 3818 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3819 result, destination, errno); 3820 problemCount++; 3821 } 3822 if (destination[0] != L'M') { 3823 printf("\tPROBLEM: wmemset(destination, '%lc', 1) -> " 3824 "destination[0]=%x, expected %x\n", source, destination[0], 3825 L'M'); 3826 problemCount++; 3827 } 3828 if (destination[1] != L'o') { 3829 printf("\tPROBLEM: wmemset(destination, '%lc', 1) -> " 3830 "destination[1]=%x, expected %x\n", source, destination[1], 3831 L'o'); 3832 problemCount++; 3833 } 3834 } 3835 3836 { 3837 wchar_t source = L'M'; 3838 wchar_t destination[] = L"some text"; 3839 wchar_t* result = wmemset(destination, source, 9); 3840 if (result != destination || errno != 0) { 3841 printf("\tPROBLEM: result for wmemset(destination, '%lc', 9) = " 3842 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3843 result, destination, errno); 3844 problemCount++; 3845 } 3846 for (int i = 0; i < 9; ++i) { 3847 if (destination[i] != L'M') { 3848 printf("\tPROBLEM: wmemset(destination, '%lc', 9) -> " 3849 "destination[%d]=%x, expected %x\n", source, i, 3850 destination[i], L'M'); 3851 problemCount++; 3852 } 3853 } 3854 } 3855 3856 if (problemCount) 3857 printf("\t%d problem(s) found!\n", problemCount); 3858 else 3859 printf("\tall fine\n"); 3860 } 3861 3862 3863 // #pragma mark - main --------------------------------------------------------- 3864 3865 3866 /* 3867 * Test several different aspects of the wchar-string functions. 3868 */ 3869 int 3870 main(void) 3871 { 3872 setlocale(LC_ALL, "de_DE"); 3873 3874 test_collation(); 3875 3876 test_wcpcpy(); 3877 test_wcscasecmp(); 3878 test_wcscat(); 3879 test_wcschr(); 3880 test_wcscmp(); 3881 test_wcscpy(); 3882 test_wcscspn(); 3883 test_wcsdup(); 3884 test_wcsftime(); 3885 #ifdef __HAIKU__ 3886 test_wcslcat(); 3887 test_wcslcpy(); 3888 #endif 3889 test_wcslen(); 3890 test_wcspbrk(); 3891 test_wcsspn(); 3892 test_wcsstr(); 3893 test_wcstok(); 3894 3895 test_wmemchr(); 3896 test_wmemcmp(); 3897 test_wmemcpy(); 3898 test_wmemmove(); 3899 test_wmempcpy(); 3900 test_wmemset(); 3901 3902 return 0; 3903 } 3904