1169689Skan/* 2169689Skan * Copyright 2011, Oliver Tappe, zooey@hirschkaefer.de 3169689Skan * Distributed under the terms of the MIT License. 4169689Skan */ 5169689Skan 6169689Skan#define _GNU_SOURCE 7169689Skan // for wmempcpy() and wcschrnul() 8169689Skan 9169689Skan#include <errno.h> 10169689Skan#include <locale.h> 11169689Skan#include <stdio.h> 12169689Skan#include <stdlib.h> 13169689Skan#include <string.h> 14169689Skan#include <time.h> 15169689Skan#include <wchar.h> 16169689Skan 17169689Skan 18169689Skanstatic int sign (int a) 19169689Skan{ 20169689Skan if (a < 0) 21169689Skan return -1; 22169689Skan if (a > 0) 23169689Skan return 1; 24169689Skan return 0; 25169689Skan} 26169689Skan 27169689Skan 28169689Skan// #pragma mark - wcslen ------------------------------------------------------- 29169689Skan 30169689Skan 31169689Skanvoid 32169689Skantest_wcslen() 33169689Skan{ 34169689Skan printf("wcslen()/wcsnlen()\n"); 35169689Skan 36169689Skan int problemCount = 0; 37169689Skan errno = 0; 38169689Skan 39169689Skan { 40169689Skan const wchar_t* string = L""; 41169689Skan size_t result = wcslen(string); 42169689Skan size_t expected = 0; 43169689Skan if (result != expected || errno != 0) { 44169689Skan printf("\tPROBLEM: result for wcslen(\"%ls\") = %lu (expected %lu)," 45169689Skan " errno = %x (expected %x)\n", string, result, expected, 46169689Skan errno, 0); 47169689Skan problemCount++; 48169689Skan } 49169689Skan } 50169689Skan 51169689Skan { 52169689Skan const wchar_t* string = L"test"; 53169689Skan size_t result = wcslen(string); 54169689Skan size_t expected = 4; 55169689Skan if (result != expected || errno != 0) { 56169689Skan printf("\tPROBLEM: result for wcslen(\"%ls\") = %lu (expected %lu)," 57169689Skan " errno = %x (expected %x)\n", string, result, expected, 58169689Skan errno, 0); 59169689Skan problemCount++; 60169689Skan } 61169689Skan } 62169689Skan 63169689Skan { 64169689Skan const wchar_t* string = L"t\xE4st"; 65169689Skan size_t result = wcslen(string); 66169689Skan size_t expected = 4; 67169689Skan if (result != expected || errno != 0) { 68169689Skan printf("\tPROBLEM: result for wcslen(\"%ls\") = %lu (expected %lu)," 69169689Skan " errno = %x (expected %x)\n", string, result, expected, 70169689Skan errno, 0); 71169689Skan problemCount++; 72169689Skan } 73169689Skan } 74169689Skan 75169689Skan { 76169689Skan const wchar_t* string = L"te\x00st"; 77169689Skan size_t result = wcslen(string); 78169689Skan size_t expected = 2; 79169689Skan if (result != expected || errno != 0) { 80169689Skan printf("\tPROBLEM: result for wcslen(\"%ls\") = %lu (expected %lu)," 81169689Skan " errno = %x (expected %x)\n", string, result, expected, 82169689Skan errno, 0); 83169689Skan problemCount++; 84169689Skan } 85169689Skan } 86169689Skan 87169689Skan { 88169689Skan const wchar_t* string = L"test"; 89169689Skan size_t result = wcsnlen(string, 0); 90169689Skan size_t expected = 0; 91169689Skan if (result != expected || errno != 0) { 92169689Skan printf("\tPROBLEM: result for wcsnlen(\"%ls\", 0) = %lu " 93169689Skan "(expected %lu), errno = %x (expected %x)\n", 94169689Skan string, result, expected, errno, 0); 95169689Skan problemCount++; 96169689Skan } 97169689Skan } 98169689Skan 99169689Skan { 100169689Skan const wchar_t* string = L"test"; 101169689Skan size_t result = wcsnlen(string, 4); 102169689Skan size_t expected = 4; 103169689Skan if (result != expected || errno != 0) { 104169689Skan printf("\tPROBLEM: result for wcsnlen(\"%ls\", 4) = %lu " 105169689Skan "(expected %lu), errno = %x (expected %x)\n", 106169689Skan string, result, expected, errno, 0); 107169689Skan problemCount++; 108169689Skan } 109169689Skan } 110169689Skan 111169689Skan { 112169689Skan const wchar_t* string = L"test"; 113169689Skan size_t result = wcsnlen(string, 6); 114169689Skan size_t expected = 4; 115169689Skan if (result != expected || errno != 0) { 116169689Skan printf("\tPROBLEM: result for wcsnlen(\"%ls\", 6) = %lu " 117169689Skan "(expected %lu), errno = %x (expected %x)\n", 118169689Skan string, result, expected, errno, 0); 119169689Skan problemCount++; 120169689Skan } 121169689Skan } 122169689Skan 123169689Skan if (problemCount) 124169689Skan printf("\t%d problem(s) found!\n", problemCount); 125169689Skan else 126169689Skan printf("\tall fine\n"); 127169689Skan} 128169689Skan 129169689Skan 130169689Skan// #pragma mark - wcscmp ------------------------------------------------------- 131169689Skan 132169689Skan 133169689Skanvoid 134169689Skantest_wcscmp() 135169689Skan{ 136169689Skan printf("wcscmp()/wcsncmp()\n"); 137169689Skan 138169689Skan int problemCount = 0; 139169689Skan errno = 0; 140169689Skan 141169689Skan { 142169689Skan const wchar_t* a = L""; 143169689Skan const wchar_t* b = L""; 144169689Skan int result = sign(wcscmp(a, b)); 145169689Skan int expected = 0; 146169689Skan if (result != expected || errno != 0) { 147169689Skan printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 148169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 149169689Skan expected, errno); 150169689Skan problemCount++; 151169689Skan } 152169689Skan } 153169689Skan 154169689Skan { 155169689Skan const wchar_t* a = L"a"; 156169689Skan const wchar_t* b = L"b"; 157169689Skan int result = sign(wcscmp(a, b)); 158169689Skan int expected = -1; 159169689Skan if (result != expected || errno != 0) { 160169689Skan printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 161169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 162169689Skan expected, errno); 163169689Skan problemCount++; 164169689Skan } 165169689Skan } 166169689Skan 167169689Skan { 168169689Skan const wchar_t* a = L"b"; 169169689Skan const wchar_t* b = L"a"; 170169689Skan int result = sign(wcscmp(a, b)); 171169689Skan int expected = 1; 172169689Skan if (result != expected || errno != 0) { 173169689Skan printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 174169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 175169689Skan expected, errno); 176169689Skan problemCount++; 177169689Skan } 178169689Skan } 179169689Skan 180169689Skan { 181169689Skan const wchar_t* a = L"a"; 182169689Skan const wchar_t* b = L"A"; 183169689Skan int result = sign(wcscmp(a, b)); 184169689Skan int expected = 1; 185169689Skan if (result != expected || errno != 0) { 186169689Skan printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 187169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 188169689Skan expected, errno); 189169689Skan problemCount++; 190169689Skan } 191169689Skan } 192169689Skan 193169689Skan { 194169689Skan const wchar_t* a = L"t��st"; 195169689Skan const wchar_t* b = L"t��st"; 196169689Skan int result = sign(wcscmp(a, b)); 197169689Skan int expected = 0; 198169689Skan if (result != expected || errno != 0) { 199169689Skan printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 200169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 201169689Skan expected, errno); 202169689Skan problemCount++; 203169689Skan } 204169689Skan } 205169689Skan 206169689Skan { 207169689Skan const wchar_t* a = L"t��st"; 208169689Skan const wchar_t* b = L"t��st "; 209169689Skan int result = sign(wcscmp(a, b)); 210169689Skan int expected = -1; 211169689Skan if (result != expected || errno != 0) { 212169689Skan printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 213169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 214169689Skan expected, errno); 215169689Skan problemCount++; 216169689Skan } 217169689Skan } 218169689Skan 219169689Skan { 220169689Skan const wchar_t* a = L"t��St"; 221169689Skan const wchar_t* b = L"t��s"; 222169689Skan int result = sign(wcscmp(a, b)); 223169689Skan int expected = -1; 224169689Skan if (result != expected || errno != 0) { 225169689Skan printf("\tPROBLEM: result for wcscmp(\"%ls\", \"%ls\") = %d " 226169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 227169689Skan expected, errno); 228169689Skan problemCount++; 229169689Skan } 230169689Skan } 231169689Skan 232169689Skan { 233169689Skan const wchar_t* a = L"t��st1"; 234169689Skan const wchar_t* b = L"t��st0"; 235169689Skan int result = sign(wcsncmp(a, b, 0)); 236169689Skan int expected = 0; 237169689Skan if (result != expected || errno != 0) { 238169689Skan printf("\tPROBLEM: result for wcsncmp(\"%ls\", \"%ls\", 0) = %d " 239169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 240169689Skan expected, errno); 241169689Skan problemCount++; 242169689Skan } 243169689Skan } 244169689Skan 245169689Skan { 246169689Skan const wchar_t* a = L"t��st1"; 247169689Skan const wchar_t* b = L"t��st0"; 248169689Skan int result = sign(wcsncmp(a, b, 4)); 249169689Skan int expected = 0; 250169689Skan if (result != expected || errno != 0) { 251169689Skan printf("\tPROBLEM: result for wcsncmp(\"%ls\", \"%ls\", 4) = %d " 252169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 253169689Skan expected, errno); 254169689Skan problemCount++; 255169689Skan } 256169689Skan } 257169689Skan 258169689Skan { 259169689Skan const wchar_t* a = L"t��st1"; 260169689Skan const wchar_t* b = L"t��st0"; 261169689Skan int result = sign(wcsncmp(a, b, 5)); 262169689Skan int expected = 1; 263169689Skan if (result != expected || errno != 0) { 264169689Skan printf("\tPROBLEM: result for wcsncmp(\"%ls\", \"%ls\", 5) = %d " 265169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 266169689Skan expected, errno); 267169689Skan problemCount++; 268169689Skan } 269169689Skan } 270169689Skan 271169689Skan { 272169689Skan const wchar_t* a = L"t��s"; 273169689Skan const wchar_t* b = L"t��st123"; 274169689Skan int result = sign(wcsncmp(a, b, (size_t)-1)); 275169689Skan int expected = -1; 276169689Skan if (result != expected || errno != 0) { 277169689Skan printf("\tPROBLEM: result for wcsncmp(\"%ls\", \"%ls\", -1) = %d " 278169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 279169689Skan expected, errno); 280169689Skan problemCount++; 281169689Skan } 282169689Skan } 283169689Skan 284169689Skan if (problemCount) 285169689Skan printf("\t%d problem(s) found!\n", problemCount); 286169689Skan else 287169689Skan printf("\tall fine\n"); 288169689Skan} 289169689Skan 290169689Skan 291169689Skan// #pragma mark - wcscasecmp --------------------------------------------------- 292169689Skan 293169689Skan 294169689Skanvoid 295169689Skantest_wcscasecmp() 296169689Skan{ 297169689Skan printf("wcscasecmp()/wcsncasecmp()\n"); 298169689Skan 299169689Skan int problemCount = 0; 300169689Skan errno = 0; 301169689Skan 302169689Skan { 303169689Skan const wchar_t* a = L""; 304169689Skan const wchar_t* b = L""; 305169689Skan int result = sign(wcscasecmp(a, b)); 306169689Skan int expected = 0; 307169689Skan if (result != expected || errno != 0) { 308169689Skan printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 309169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 310169689Skan expected, errno); 311169689Skan problemCount++; 312169689Skan } 313169689Skan } 314169689Skan 315169689Skan { 316169689Skan const wchar_t* a = L"a"; 317169689Skan const wchar_t* b = L"b"; 318169689Skan int result = sign(wcscasecmp(a, b)); 319169689Skan int expected = -1; 320169689Skan if (result != expected || errno != 0) { 321169689Skan printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 322169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 323169689Skan expected, errno); 324169689Skan problemCount++; 325169689Skan } 326169689Skan } 327169689Skan 328169689Skan { 329169689Skan const wchar_t* a = L"B"; 330169689Skan const wchar_t* b = L"a"; 331169689Skan int result = sign(wcscasecmp(a, b)); 332169689Skan int expected = 1; 333169689Skan if (result != expected || errno != 0) { 334169689Skan printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 335169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 336169689Skan expected, errno); 337169689Skan problemCount++; 338169689Skan } 339169689Skan } 340169689Skan 341169689Skan { 342169689Skan const wchar_t* a = L"a"; 343169689Skan const wchar_t* b = L"A"; 344169689Skan int result = sign(wcscasecmp(a, b)); 345169689Skan int expected = 0; 346169689Skan if (result != expected || errno != 0) { 347169689Skan printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 348169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 349169689Skan expected, errno); 350169689Skan problemCount++; 351169689Skan } 352169689Skan } 353169689Skan 354169689Skan { 355169689Skan const wchar_t* a = L"T��ST"; 356169689Skan const wchar_t* b = L"t��st"; 357169689Skan int result = sign(wcscasecmp(a, b)); 358169689Skan int expected = 0; 359169689Skan if (result != expected || errno != 0) { 360169689Skan printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 361169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 362169689Skan expected, errno); 363169689Skan problemCount++; 364169689Skan } 365169689Skan } 366169689Skan 367169689Skan { 368169689Skan const wchar_t* a = L"t��st"; 369169689Skan const wchar_t* b = L"t��st "; 370169689Skan int result = sign(wcscasecmp(a, b)); 371169689Skan int expected = -1; 372169689Skan if (result != expected || errno != 0) { 373169689Skan printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 374169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 375169689Skan expected, errno); 376169689Skan problemCount++; 377169689Skan } 378169689Skan } 379169689Skan 380169689Skan { 381169689Skan const wchar_t* a = L"T��St"; 382169689Skan const wchar_t* b = L"t��s"; 383169689Skan int result = sign(wcscasecmp(a, b)); 384169689Skan int expected = 1; 385169689Skan if (result != expected || errno != 0) { 386169689Skan printf("\tPROBLEM: result for wcscasecmp(\"%ls\", \"%ls\") = %d " 387169689Skan "(expected %d), errno = %x (expected 0)\n", a, b, result, 388169689Skan expected, errno); 389169689Skan problemCount++; 390169689Skan } 391169689Skan } 392169689Skan 393169689Skan { 394169689Skan const wchar_t* a = L"t��st1"; 395169689Skan const wchar_t* b = L"t��st0"; 396169689Skan int result = sign(wcsncasecmp(a, b, 0)); 397169689Skan int expected = 0; 398169689Skan if (result != expected || errno != 0) { 399169689Skan printf("\tPROBLEM: result for wcscasencmp(\"%ls\", \"%ls\", 0) = %d" 400169689Skan " (expected %d), errno = %x (expected 0)\n", a, b, result, 401169689Skan expected, errno); 402169689Skan problemCount++; 403169689Skan } 404169689Skan } 405169689Skan 406169689Skan { 407169689Skan const wchar_t* a = L"t��st1"; 408169689Skan const wchar_t* b = L"t��St0"; 409169689Skan int result = sign(wcsncasecmp(a, b, 4)); 410169689Skan int expected = 0; 411169689Skan if (result != expected || errno != 0) { 412169689Skan printf("\tPROBLEM: result for wcsncasecmp(\"%ls\", \"%ls\", 4) = %d" 413169689Skan " (expected %d), errno = %x (expected 0)\n", a, b, result, 414169689Skan expected, errno); 415169689Skan problemCount++; 416169689Skan } 417169689Skan } 418169689Skan 419169689Skan { 420169689Skan const wchar_t* a = L"t��sT1"; 421169689Skan const wchar_t* b = L"t��st0"; 422169689Skan int result = sign(wcsncasecmp(a, b, 5)); 423169689Skan int expected = 1; 424169689Skan if (result != expected || errno != 0) { 425169689Skan printf("\tPROBLEM: result for wcsncasecmp(\"%ls\", \"%ls\", 5) = %d" 426169689Skan " (expected %d), errno = %x (expected 0)\n", a, b, result, 427169689Skan expected, errno); 428169689Skan problemCount++; 429169689Skan } 430169689Skan } 431169689Skan 432169689Skan { 433169689Skan const wchar_t* a = L"t��s"; 434169689Skan const wchar_t* b = L"t��St123"; 435169689Skan int result = sign(wcsncasecmp(a, b, (size_t)-1)); 436169689Skan int expected = -1; 437169689Skan if (result != expected || errno != 0) { 438169689Skan printf("\tPROBLEM: result for wcsncasecmp(\"%ls\", \"%ls\", -1) = " 439169689Skan "%d (expected %d), errno = %x (expected 0)\n", a, b, result, 440169689Skan expected, errno); 441169689Skan problemCount++; 442169689Skan } 443169689Skan } 444169689Skan 445169689Skan if (problemCount) 446169689Skan printf("\t%d problem(s) found!\n", problemCount); 447169689Skan else 448169689Skan printf("\tall fine\n"); 449169689Skan} 450169689Skan 451169689Skan 452169689Skan// #pragma mark - wcschr ------------------------------------------------------- 453169689Skan 454169689Skan 455169689Skanvoid 456169689Skantest_wcschr() 457169689Skan{ 458169689Skan printf("wcschr()/wcschrnul()/wcsrchr()\n"); 459169689Skan 460169689Skan int problemCount = 0; 461169689Skan errno = 0; 462169689Skan 463169689Skan { 464169689Skan const wchar_t* string = L""; 465169689Skan const wchar_t ch = L' '; 466169689Skan const wchar_t* result = wcschr(string, ch); 467169689Skan const wchar_t* expected = NULL; 468169689Skan if (result != expected || errno != 0) { 469169689Skan printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 470169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 471169689Skan result, expected, errno); 472169689Skan problemCount++; 473169689Skan } 474169689Skan } 475169689Skan 476169689Skan { 477169689Skan const wchar_t* string = L""; 478169689Skan const wchar_t ch = L'\0'; 479169689Skan const wchar_t* result = wcschr(string, ch); 480169689Skan const wchar_t* expected = string; 481169689Skan if (result != expected || errno != 0) { 482169689Skan printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 483169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 484169689Skan result, expected, errno); 485169689Skan problemCount++; 486169689Skan } 487169689Skan } 488169689Skan 489169689Skan { 490169689Skan const wchar_t* string = L"sometext"; 491169689Skan const wchar_t ch = L' '; 492169689Skan const wchar_t* result = wcschr(string, ch); 493169689Skan const wchar_t* expected = NULL; 494169689Skan if (result != expected || errno != 0) { 495169689Skan printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 496169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 497169689Skan result, expected, errno); 498169689Skan problemCount++; 499169689Skan } 500169689Skan } 501169689Skan 502169689Skan { 503169689Skan const wchar_t* string = L"some more text"; 504169689Skan const wchar_t ch = L' '; 505169689Skan const wchar_t* result = wcschr(string, ch); 506169689Skan const wchar_t* expected = string + 4; 507169689Skan if (result != expected || errno != 0) { 508169689Skan printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 509169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 510169689Skan result, expected, errno); 511169689Skan problemCount++; 512169689Skan } 513169689Skan } 514169689Skan 515169689Skan { 516169689Skan const wchar_t* string = L"some more text"; 517169689Skan const wchar_t ch = L's'; 518169689Skan const wchar_t* result = wcschr(string, ch); 519169689Skan const wchar_t* expected = string; 520169689Skan if (result != expected || errno != 0) { 521169689Skan printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 522169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 523169689Skan result, expected, errno); 524169689Skan problemCount++; 525169689Skan } 526169689Skan } 527169689Skan 528169689Skan { 529169689Skan const wchar_t* string = L"some more text"; 530169689Skan const wchar_t ch = L'S'; 531169689Skan const wchar_t* result = wcschr(string, ch); 532169689Skan const wchar_t* expected = NULL; 533169689Skan if (result != expected || errno != 0) { 534169689Skan printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 535169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 536169689Skan result, expected, errno); 537169689Skan problemCount++; 538169689Skan } 539169689Skan } 540169689Skan 541169689Skan { 542169689Skan const wchar_t* string = L"some more text"; 543169689Skan const wchar_t ch = L'\0'; 544169689Skan const wchar_t* result = wcschr(string, ch); 545169689Skan const wchar_t* expected = string + 14; 546169689Skan if (result != expected || errno != 0) { 547169689Skan printf("\tPROBLEM: result for wcschr(\"%ls\", '%lc') = %p " 548169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 549169689Skan result, expected, errno); 550169689Skan problemCount++; 551169689Skan } 552169689Skan } 553169689Skan 554169689Skan { 555169689Skan const wchar_t* string = L""; 556169689Skan const wchar_t ch = L' '; 557169689Skan const wchar_t* result = wcschrnul(string, ch); 558169689Skan const wchar_t* expected = string; 559169689Skan if (result != expected || errno != 0) { 560169689Skan printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 561169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 562169689Skan result, expected, errno); 563169689Skan problemCount++; 564169689Skan } 565169689Skan } 566169689Skan 567169689Skan { 568169689Skan const wchar_t* string = L""; 569169689Skan const wchar_t ch = L'\0'; 570169689Skan const wchar_t* result = wcschrnul(string, ch); 571169689Skan const wchar_t* expected = string; 572169689Skan if (result != expected || errno != 0) { 573169689Skan printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 574169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 575169689Skan result, expected, errno); 576169689Skan problemCount++; 577169689Skan } 578169689Skan } 579169689Skan 580169689Skan { 581169689Skan const wchar_t* string = L"sometext"; 582169689Skan const wchar_t ch = L' '; 583169689Skan const wchar_t* result = wcschrnul(string, ch); 584169689Skan const wchar_t* expected = string + wcslen(string); 585169689Skan if (result != expected || errno != 0) { 586169689Skan printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 587169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 588169689Skan result, expected, errno); 589169689Skan problemCount++; 590169689Skan } 591169689Skan } 592169689Skan 593169689Skan { 594169689Skan const wchar_t* string = L"some more text"; 595169689Skan const wchar_t ch = L' '; 596169689Skan const wchar_t* result = wcschrnul(string, ch); 597169689Skan const wchar_t* expected = string + 4; 598169689Skan if (result != expected || errno != 0) { 599169689Skan printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 600169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 601169689Skan result, expected, errno); 602169689Skan problemCount++; 603169689Skan } 604169689Skan } 605169689Skan 606169689Skan { 607169689Skan const wchar_t* string = L"some more text"; 608169689Skan const wchar_t ch = L's'; 609169689Skan const wchar_t* result = wcschrnul(string, ch); 610169689Skan const wchar_t* expected = string; 611169689Skan if (result != expected || errno != 0) { 612169689Skan printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 613169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 614169689Skan result, expected, errno); 615169689Skan problemCount++; 616169689Skan } 617169689Skan } 618169689Skan 619169689Skan { 620169689Skan const wchar_t* string = L"some more text"; 621169689Skan const wchar_t ch = L'S'; 622169689Skan const wchar_t* result = wcschrnul(string, ch); 623169689Skan const wchar_t* expected = string + wcslen(string); 624169689Skan if (result != expected || errno != 0) { 625169689Skan printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 626169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 627169689Skan result, expected, errno); 628169689Skan problemCount++; 629169689Skan } 630169689Skan } 631169689Skan 632169689Skan { 633169689Skan const wchar_t* string = L"some more text"; 634169689Skan const wchar_t ch = L'\0'; 635169689Skan const wchar_t* result = wcschrnul(string, ch); 636169689Skan const wchar_t* expected = string + 14; 637169689Skan if (result != expected || errno != 0) { 638169689Skan printf("\tPROBLEM: result for wcschrnul(\"%ls\", '%lc') = %p " 639169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 640169689Skan result, expected, errno); 641169689Skan problemCount++; 642169689Skan } 643169689Skan } 644169689Skan 645169689Skan { 646169689Skan const wchar_t* string = L""; 647169689Skan const wchar_t ch = L' '; 648169689Skan const wchar_t* result = wcsrchr(string, ch); 649169689Skan const wchar_t* expected = NULL; 650169689Skan if (result != expected || errno != 0) { 651169689Skan printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 652169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 653169689Skan result, expected, errno); 654169689Skan problemCount++; 655169689Skan } 656169689Skan } 657169689Skan 658169689Skan { 659169689Skan const wchar_t* string = L""; 660169689Skan const wchar_t ch = L'\0'; 661169689Skan const wchar_t* result = wcsrchr(string, ch); 662169689Skan const wchar_t* expected = string; 663169689Skan if (result != expected || errno != 0) { 664169689Skan printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 665169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 666169689Skan result, expected, errno); 667169689Skan problemCount++; 668169689Skan } 669169689Skan } 670169689Skan 671169689Skan { 672169689Skan const wchar_t* string = L"sometext"; 673169689Skan const wchar_t ch = L' '; 674169689Skan const wchar_t* result = wcsrchr(string, ch); 675169689Skan const wchar_t* expected = NULL; 676169689Skan if (result != expected || errno != 0) { 677169689Skan printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 678169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 679169689Skan result, expected, errno); 680169689Skan problemCount++; 681169689Skan } 682169689Skan } 683169689Skan 684169689Skan { 685169689Skan const wchar_t* string = L"some more text"; 686169689Skan const wchar_t ch = L' '; 687169689Skan const wchar_t* result = wcsrchr(string, ch); 688169689Skan const wchar_t* expected = string + 9; 689169689Skan if (result != expected || errno != 0) { 690169689Skan printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 691169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 692169689Skan result, expected, errno); 693169689Skan problemCount++; 694169689Skan } 695169689Skan } 696169689Skan 697169689Skan { 698169689Skan const wchar_t* string = L"some more text"; 699169689Skan const wchar_t ch = L's'; 700169689Skan const wchar_t* result = wcsrchr(string, ch); 701169689Skan const wchar_t* expected = string; 702169689Skan if (result != expected || errno != 0) { 703169689Skan printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 704169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 705169689Skan result, expected, errno); 706169689Skan problemCount++; 707169689Skan } 708169689Skan } 709169689Skan 710169689Skan { 711169689Skan const wchar_t* string = L"some more text"; 712169689Skan const wchar_t ch = L'S'; 713169689Skan const wchar_t* result = wcsrchr(string, ch); 714169689Skan const wchar_t* expected = NULL; 715169689Skan if (result != expected || errno != 0) { 716169689Skan printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 717169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 718169689Skan result, expected, errno); 719169689Skan problemCount++; 720169689Skan } 721169689Skan } 722169689Skan 723169689Skan { 724169689Skan const wchar_t* string = L"some more text"; 725169689Skan const wchar_t ch = L'\0'; 726169689Skan const wchar_t* result = wcsrchr(string, ch); 727169689Skan const wchar_t* expected = string + 14; 728169689Skan if (result != expected || errno != 0) { 729169689Skan printf("\tPROBLEM: result for wcsrchr(\"%ls\", '%lc') = %p " 730169689Skan "(expected %p), errno = %x (expected 0)\n", string, ch, 731169689Skan result, expected, errno); 732169689Skan problemCount++; 733169689Skan } 734169689Skan } 735169689Skan 736169689Skan if (problemCount) 737169689Skan printf("\t%d problem(s) found!\n", problemCount); 738169689Skan else 739169689Skan printf("\tall fine\n"); 740169689Skan} 741169689Skan 742169689Skan 743169689Skan// #pragma mark - wcsdup ------------------------------------------------------- 744169689Skan 745169689Skan 746169689Skanvoid 747169689Skantest_wcsdup() 748169689Skan{ 749169689Skan printf("wcsdup()\n"); 750169689Skan 751169689Skan int problemCount = 0; 752169689Skan errno = 0; 753223715Suqs 754169689Skan#ifdef __HAIKU__ 755169689Skan { 756169689Skan const wchar_t* string = NULL; 757169689Skan wchar_t* result = wcsdup(string); 758169689Skan if (result != NULL || errno != 0) { 759169689Skan printf("\tPROBLEM: result for wcsdup(%p) = \"%ls\", errno = %x" 760169689Skan " (expected 0)\n", string, result, errno); 761169689Skan problemCount++; 762169689Skan } 763169689Skan } 764169689Skan#endif 765169689Skan 766169689Skan { 767169689Skan const wchar_t* string = L""; 768169689Skan wchar_t* result = wcsdup(string); 769169689Skan if (result == NULL || wcscmp(result, string) != 0 || errno != 0) { 770169689Skan printf("\tPROBLEM: result for wcsdup(\"%ls\") = \"%ls\", errno = %x" 771169689Skan " (expected 0)\n", string, result, errno); 772169689Skan problemCount++; 773169689Skan } 774169689Skan } 775169689Skan 776169689Skan { 777169689Skan const wchar_t* string = L"t��stdata with some char��cters"; 778169689Skan wchar_t* result = wcsdup(string); 779169689Skan if (result == NULL || wcscmp(result, string) != 0 || errno != 0) { 780169689Skan printf("\tPROBLEM: result for wcsdup(\"%ls\") = \"%ls\", errno = %x" 781169689Skan " (expected 0)\n", string, result, errno); 782169689Skan problemCount++; 783169689Skan } 784169689Skan } 785169689Skan 786169689Skan if (problemCount) 787169689Skan printf("\t%d problem(s) found!\n", problemCount); 788169689Skan else 789169689Skan printf("\tall fine\n"); 790169689Skan} 791169689Skan 792169689Skan 793169689Skan// #pragma mark - wcscpy ------------------------------------------------------- 794169689Skan 795169689Skan 796169689Skanvoid 797169689Skantest_wcscpy() 798169689Skan{ 799169689Skan printf("wcscpy()/wcsncpy()\n"); 800169689Skan 801169689Skan int problemCount = 0; 802169689Skan errno = 0; 803169689Skan 804169689Skan { 805169689Skan const wchar_t* source = L""; 806169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 807169689Skan wchar_t* result = wcscpy(destination, source); 808169689Skan if (result != destination) { 809169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> result=%p, " 810169689Skan "expected %p\n", source, result, destination); 811169689Skan problemCount++; 812169689Skan } 813169689Skan if (errno != 0) { 814169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> errno=%d, " 815169689Skan "expected 0\n", source, errno); 816169689Skan problemCount++; 817169689Skan } 818169689Skan if (wcslen(destination) != 0) { 819169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 820169689Skan "wcslen(destination)=%lu, expected 0\n", source, 821169689Skan wcslen(destination)); 822169689Skan problemCount++; 823169689Skan } 824169689Skan if (destination[0] != L'\0') { 825169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 826169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 827169689Skan L'\0'); 828169689Skan problemCount++; 829169689Skan } 830169689Skan if (destination[1] != L'X') { 831169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 832169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 833169689Skan L'X'); 834169689Skan problemCount++; 835169689Skan } 836169689Skan } 837169689Skan 838169689Skan { 839169689Skan const wchar_t* source = L"test"; 840169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 841169689Skan wchar_t* result = wcscpy(destination, source); 842169689Skan if (result != destination) { 843169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> result=%p, " 844169689Skan "expected %p\n", source, result, destination); 845169689Skan problemCount++; 846169689Skan } 847169689Skan if (errno != 0) { 848169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> errno=%d, " 849169689Skan "expected 0\n", source, errno); 850169689Skan problemCount++; 851169689Skan } 852169689Skan if (wcslen(destination) != 4) { 853169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 854169689Skan "wcslen(destination)=%lu, expected 4\n", source, 855169689Skan wcslen(destination)); 856169689Skan problemCount++; 857169689Skan } 858169689Skan if (destination[0] != L't') { 859169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 860169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 861169689Skan L't'); 862169689Skan problemCount++; 863169689Skan } 864169689Skan if (destination[1] != L'e') { 865169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 866169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 867169689Skan L'e'); 868169689Skan problemCount++; 869169689Skan } 870169689Skan if (destination[2] != L's') { 871169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 872169689Skan "destination[2]=%x, expected %x\n", source, destination[2], 873169689Skan L's'); 874169689Skan problemCount++; 875169689Skan } 876169689Skan if (destination[3] != L't') { 877169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 878169689Skan "destination[3]=%x, expected %x\n", source, destination[3], 879169689Skan L't'); 880169689Skan problemCount++; 881169689Skan } 882169689Skan if (destination[4] != L'\0') { 883169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 884169689Skan "destination[4]=%x, expected %x\n", source, destination[4], 885169689Skan L'\0'); 886169689Skan problemCount++; 887169689Skan } 888169689Skan if (destination[5] != L'X') { 889169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 890169689Skan "destination[5]=%x, expected %x\n", source, destination[5], 891169689Skan L'X'); 892169689Skan problemCount++; 893169689Skan } 894169689Skan } 895169689Skan 896169689Skan { 897169689Skan const wchar_t* source = L"t\xE4st"; 898169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 899169689Skan wchar_t* result = wcscpy(destination, source); 900169689Skan if (result != destination) { 901169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> result=%p, " 902169689Skan "expected %p\n", source, result, destination); 903169689Skan problemCount++; 904169689Skan } 905169689Skan if (errno != 0) { 906169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> errno=%d, " 907169689Skan "expected 0\n", source, errno); 908169689Skan problemCount++; 909169689Skan } 910169689Skan if (wcslen(destination) != 4) { 911169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 912169689Skan "wcslen(destination)=%lu, expected 4\n", source, 913169689Skan wcslen(destination)); 914169689Skan problemCount++; 915169689Skan } 916169689Skan if (destination[0] != L't') { 917169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 918169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 919169689Skan L't'); 920169689Skan problemCount++; 921169689Skan } 922169689Skan if (destination[1] != L'\xE4') { 923169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 924169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 925169689Skan L'\xE4'); 926169689Skan problemCount++; 927169689Skan } 928169689Skan if (destination[2] != L's') { 929169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 930169689Skan "destination[2]=%x, expected %x\n", source, destination[2], 931169689Skan L's'); 932169689Skan problemCount++; 933169689Skan } 934169689Skan if (destination[3] != L't') { 935169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 936169689Skan "destination[3]=%x, expected %x\n", source, destination[3], 937169689Skan L't'); 938169689Skan problemCount++; 939169689Skan } 940169689Skan if (destination[4] != L'\0') { 941169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 942169689Skan "destination[4]=%x, expected %x\n", source, destination[4], 943169689Skan L'\0'); 944169689Skan problemCount++; 945169689Skan } 946169689Skan if (destination[5] != L'X') { 947169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 948169689Skan "destination[5]=%x, expected %x\n", source, destination[5], 949169689Skan L'X'); 950169689Skan problemCount++; 951169689Skan } 952169689Skan } 953169689Skan 954169689Skan { 955169689Skan const wchar_t* source = L"te\x00st"; 956169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 957169689Skan wchar_t* result = wcscpy(destination, source); 958169689Skan if (result != destination) { 959169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> result=%p, " 960169689Skan "expected %p\n", source, result, destination); 961169689Skan problemCount++; 962169689Skan } 963169689Skan if (errno != 0) { 964169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> errno=%d, " 965169689Skan "expected 0\n", source, errno); 966169689Skan problemCount++; 967169689Skan } 968169689Skan if (wcslen(destination) != 2) { 969169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 970169689Skan "wcslen(destination)=%lu, expected 2\n", source, 971169689Skan wcslen(destination)); 972169689Skan problemCount++; 973169689Skan } 974169689Skan if (destination[0] != L't') { 975169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 976169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 977169689Skan L't'); 978169689Skan problemCount++; 979169689Skan } 980169689Skan if (destination[1] != L'e') { 981169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 982169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 983169689Skan L'e'); 984169689Skan problemCount++; 985169689Skan } 986169689Skan if (destination[2] != L'\0') { 987169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 988169689Skan "destination[2]=%x, expected %x\n", source, destination[2], 989169689Skan L'\0'); 990169689Skan problemCount++; 991169689Skan } 992169689Skan if (destination[3] != L'X') { 993169689Skan printf("\tPROBLEM: wcscpy(destination, \"%ls\") -> " 994169689Skan "destination[3]=%x, expected %x\n", source, destination[3], 995169689Skan L'X'); 996169689Skan problemCount++; 997169689Skan } 998169689Skan } 999169689Skan 1000169689Skan { 1001169689Skan const wchar_t* source = L"t\xE4st"; 1002169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1003169689Skan wchar_t* result = wcsncpy(destination, source, 0); 1004169689Skan if (result != destination) { 1005169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 0) -> result=%p, " 1006169689Skan "expected %p\n", source, result, destination); 1007169689Skan problemCount++; 1008169689Skan } 1009169689Skan if (errno != 0) { 1010169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 0) -> errno=%d, " 1011169689Skan "expected 0\n", source, errno); 1012169689Skan problemCount++; 1013169689Skan } 1014169689Skan if (destination[0] != L'X') { 1015169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 0) -> " 1016169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 1017169689Skan L'X'); 1018169689Skan problemCount++; 1019169689Skan } 1020169689Skan } 1021169689Skan 1022169689Skan { 1023169689Skan const wchar_t* source = L"t\xE4st"; 1024169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1025169689Skan wchar_t* result = wcsncpy(destination, source, 2); 1026169689Skan if (result != destination) { 1027169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> result=%p, " 1028169689Skan "expected %p\n", source, result, destination); 1029169689Skan problemCount++; 1030169689Skan } 1031169689Skan if (errno != 0) { 1032169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> errno=%d, " 1033169689Skan "expected 0\n", source, errno); 1034169689Skan problemCount++; 1035169689Skan } 1036169689Skan if (destination[0] != L't') { 1037169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> " 1038169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 1039169689Skan L't'); 1040169689Skan problemCount++; 1041169689Skan } 1042169689Skan if (destination[1] != L'\xE4') { 1043169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> " 1044169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 1045169689Skan L'\xE4'); 1046169689Skan problemCount++; 1047169689Skan } 1048169689Skan if (destination[2] != L'X') { 1049169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 2) -> " 1050169689Skan "destination[2]=%x, expected %x\n", source, destination[2], 1051169689Skan L'X'); 1052169689Skan problemCount++; 1053169689Skan } 1054169689Skan } 1055169689Skan 1056169689Skan { 1057169689Skan const wchar_t* source = L"t\xE4st"; 1058169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1059169689Skan wchar_t* result = wcsncpy(destination, source, 4); 1060169689Skan if (result != destination) { 1061169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> result=%p, " 1062169689Skan "expected %p\n", source, result, destination); 1063169689Skan problemCount++; 1064169689Skan } 1065169689Skan if (errno != 0) { 1066169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> errno=%d, " 1067169689Skan "expected 0\n", source, errno); 1068169689Skan problemCount++; 1069169689Skan } 1070169689Skan if (destination[0] != L't') { 1071169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> " 1072169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 1073169689Skan L't'); 1074169689Skan problemCount++; 1075169689Skan } 1076169689Skan if (destination[1] != L'\xE4') { 1077169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> " 1078169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 1079169689Skan L'\xE4'); 1080169689Skan problemCount++; 1081169689Skan } 1082169689Skan if (destination[2] != L's') { 1083169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> " 1084169689Skan "destination[2]=%x, expected %x\n", source, destination[2], 1085169689Skan L's'); 1086169689Skan problemCount++; 1087169689Skan } 1088169689Skan if (destination[3] != L't') { 1089169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> " 1090169689Skan "destination[3]=%x, expected %x\n", source, destination[3], 1091169689Skan L't'); 1092169689Skan problemCount++; 1093169689Skan } 1094169689Skan if (destination[4] != L'X') { 1095169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 4) -> " 1096169689Skan "destination[4]=%x, expected %x\n", source, destination[4], 1097169689Skan L'X'); 1098169689Skan problemCount++; 1099169689Skan } 1100169689Skan } 1101169689Skan 1102169689Skan { 1103169689Skan const wchar_t* source = L"t\xE4st"; 1104169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1105169689Skan wchar_t* result = wcsncpy(destination, source, 8); 1106169689Skan if (result != destination) { 1107169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> result=%p, " 1108169689Skan "expected %p\n", source, result, destination); 1109169689Skan problemCount++; 1110169689Skan } 1111169689Skan if (errno != 0) { 1112169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> errno=%d, " 1113169689Skan "expected 0\n", source, errno); 1114169689Skan problemCount++; 1115169689Skan } 1116169689Skan if (wcslen(destination) != 4) { 1117169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1118169689Skan "wcslen(destination)=%lu, expected 4\n", source, 1119169689Skan wcslen(destination)); 1120169689Skan problemCount++; 1121169689Skan } 1122169689Skan if (destination[0] != L't') { 1123169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1124169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 1125169689Skan L't'); 1126169689Skan problemCount++; 1127169689Skan } 1128169689Skan if (destination[1] != L'\xE4') { 1129169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1130169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 1131169689Skan L'\xE4'); 1132169689Skan problemCount++; 1133169689Skan } 1134169689Skan if (destination[2] != L's') { 1135169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1136169689Skan "destination[2]=%x, expected %x\n", source, destination[2], 1137169689Skan L's'); 1138169689Skan problemCount++; 1139169689Skan } 1140169689Skan if (destination[3] != L't') { 1141169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1142169689Skan "destination[3]=%x, expected %x\n", source, destination[3], 1143169689Skan L't'); 1144169689Skan problemCount++; 1145169689Skan } 1146169689Skan if (destination[4] != L'\0') { 1147169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1148169689Skan "destination[4]=%x, expected %x\n", source, destination[4], 1149169689Skan L'\0'); 1150169689Skan problemCount++; 1151169689Skan } 1152169689Skan if (destination[5] != L'\0') { 1153169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1154169689Skan "destination[5]=%x, expected %x\n", source, destination[5], 1155169689Skan L'\0'); 1156169689Skan problemCount++; 1157169689Skan } 1158169689Skan if (destination[6] != L'\0') { 1159169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1160169689Skan "destination[6]=%x, expected %x\n", source, destination[6], 1161169689Skan L'\0'); 1162169689Skan problemCount++; 1163169689Skan } 1164169689Skan if (destination[7] != L'\0') { 1165169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1166169689Skan "destination[7]=%x, expected %x\n", source, destination[7], 1167169689Skan L'\0'); 1168169689Skan problemCount++; 1169169689Skan } 1170169689Skan if (destination[8] != L'X') { 1171169689Skan printf("\tPROBLEM: wcsncpy(destination, \"%ls\", 8) -> " 1172169689Skan "destination[8]=%x, expected %x\n", source, destination[8], 1173169689Skan L'X'); 1174169689Skan problemCount++; 1175169689Skan } 1176169689Skan } 1177169689Skan 1178169689Skan if (problemCount) 1179169689Skan printf("\t%d problem(s) found!\n", problemCount); 1180169689Skan else 1181169689Skan printf("\tall fine\n"); 1182169689Skan} 1183169689Skan 1184169689Skan 1185169689Skan// #pragma mark - wcpcpy ------------------------------------------------------- 1186169689Skan 1187169689Skan 1188169689Skanvoid 1189169689Skantest_wcpcpy() 1190169689Skan{ 1191169689Skan printf("wcpcpy()/wcpncpy()\n"); 1192169689Skan 1193169689Skan int problemCount = 0; 1194169689Skan errno = 0; 1195169689Skan 1196169689Skan { 1197169689Skan const wchar_t* source = L""; 1198169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1199169689Skan wchar_t* result = wcpcpy(destination, source); 1200169689Skan if (result != destination) { 1201169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> result=%p, " 1202169689Skan "expected %p\n", source, result, destination); 1203169689Skan problemCount++; 1204169689Skan } 1205169689Skan if (errno != 0) { 1206169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> errno=%d, " 1207169689Skan "expected 0\n", source, errno); 1208169689Skan problemCount++; 1209169689Skan } 1210169689Skan if (wcslen(destination) != 0) { 1211169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1212169689Skan "wcslen(destination)=%lu, expected 0\n", source, 1213169689Skan wcslen(destination)); 1214169689Skan problemCount++; 1215169689Skan } 1216169689Skan if (destination[0] != L'\0') { 1217169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1218169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 1219169689Skan L'\0'); 1220169689Skan problemCount++; 1221169689Skan } 1222169689Skan if (destination[1] != L'X') { 1223169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1224169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 1225169689Skan L'X'); 1226169689Skan problemCount++; 1227169689Skan } 1228169689Skan } 1229169689Skan 1230169689Skan { 1231169689Skan const wchar_t* source = L"test"; 1232169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1233169689Skan wchar_t* result = wcpcpy(destination, source); 1234169689Skan if (result != destination + 4) { 1235169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> result=%p, " 1236169689Skan "expected %p\n", source, result, destination + 4); 1237169689Skan problemCount++; 1238169689Skan } 1239169689Skan if (errno != 0) { 1240169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> errno=%d, " 1241169689Skan "expected 0\n", source, errno); 1242169689Skan problemCount++; 1243169689Skan } 1244169689Skan if (wcslen(destination) != 4) { 1245169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1246169689Skan "wcslen(destination)=%lu, expected 4\n", source, 1247169689Skan wcslen(destination)); 1248169689Skan problemCount++; 1249169689Skan } 1250169689Skan if (destination[0] != L't') { 1251169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1252169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 1253169689Skan L't'); 1254169689Skan problemCount++; 1255169689Skan } 1256169689Skan if (destination[1] != L'e') { 1257169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1258169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 1259169689Skan L'e'); 1260169689Skan problemCount++; 1261169689Skan } 1262169689Skan if (destination[2] != L's') { 1263169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1264169689Skan "destination[2]=%x, expected %x\n", source, destination[2], 1265169689Skan L's'); 1266169689Skan problemCount++; 1267169689Skan } 1268169689Skan if (destination[3] != L't') { 1269169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1270169689Skan "destination[3]=%x, expected %x\n", source, destination[3], 1271169689Skan L't'); 1272169689Skan problemCount++; 1273169689Skan } 1274169689Skan if (destination[4] != L'\0') { 1275169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1276169689Skan "destination[4]=%x, expected %x\n", source, destination[4], 1277169689Skan L'\0'); 1278169689Skan problemCount++; 1279169689Skan } 1280169689Skan if (destination[5] != L'X') { 1281169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1282169689Skan "destination[5]=%x, expected %x\n", source, destination[5], 1283169689Skan L'X'); 1284169689Skan problemCount++; 1285169689Skan } 1286169689Skan } 1287169689Skan 1288169689Skan { 1289169689Skan const wchar_t* source = L"t\xE4st"; 1290169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1291169689Skan wchar_t* result = wcpcpy(destination, source); 1292169689Skan if (result != destination + 4) { 1293169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> result=%p, " 1294169689Skan "expected %p\n", source, result, destination + 4); 1295169689Skan problemCount++; 1296169689Skan } 1297169689Skan if (errno != 0) { 1298169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> errno=%d, " 1299169689Skan "expected 0\n", source, errno); 1300169689Skan problemCount++; 1301169689Skan } 1302169689Skan if (wcslen(destination) != 4) { 1303169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1304169689Skan "wcslen(destination)=%lu, expected 4\n", source, 1305169689Skan wcslen(destination)); 1306169689Skan problemCount++; 1307169689Skan } 1308169689Skan if (destination[0] != L't') { 1309169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1310169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 1311169689Skan L't'); 1312169689Skan problemCount++; 1313169689Skan } 1314169689Skan if (destination[1] != L'\xE4') { 1315169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1316169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 1317169689Skan L'\xE4'); 1318169689Skan problemCount++; 1319169689Skan } 1320169689Skan if (destination[2] != L's') { 1321169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1322169689Skan "destination[2]=%x, expected %x\n", source, destination[2], 1323169689Skan L's'); 1324169689Skan problemCount++; 1325169689Skan } 1326169689Skan if (destination[3] != L't') { 1327169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1328169689Skan "destination[3]=%x, expected %x\n", source, destination[3], 1329169689Skan L't'); 1330169689Skan problemCount++; 1331169689Skan } 1332169689Skan if (destination[4] != L'\0') { 1333169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1334169689Skan "destination[4]=%x, expected %x\n", source, destination[4], 1335169689Skan L'\0'); 1336169689Skan problemCount++; 1337169689Skan } 1338169689Skan if (destination[5] != L'X') { 1339169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1340169689Skan "destination[5]=%x, expected %x\n", source, destination[5], 1341169689Skan L'X'); 1342169689Skan problemCount++; 1343169689Skan } 1344169689Skan } 1345169689Skan 1346169689Skan { 1347169689Skan const wchar_t* source = L"te\x00st"; 1348169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1349169689Skan wchar_t* result = wcpcpy(destination, source); 1350169689Skan if (result != destination + 2) { 1351169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> result=%p, " 1352169689Skan "expected %p\n", source, result, destination + 2); 1353169689Skan problemCount++; 1354169689Skan } 1355169689Skan if (errno != 0) { 1356169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> errno=%d, " 1357169689Skan "expected 0\n", source, errno); 1358169689Skan problemCount++; 1359169689Skan } 1360169689Skan if (wcslen(destination) != 2) { 1361169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1362169689Skan "wcslen(destination)=%lu, expected 2\n", source, 1363169689Skan wcslen(destination)); 1364169689Skan problemCount++; 1365169689Skan } 1366169689Skan if (destination[0] != L't') { 1367169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1368169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 1369169689Skan L't'); 1370169689Skan problemCount++; 1371169689Skan } 1372169689Skan if (destination[1] != L'e') { 1373169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1374169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 1375169689Skan L'e'); 1376169689Skan problemCount++; 1377169689Skan } 1378169689Skan if (destination[2] != L'\0') { 1379169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1380169689Skan "destination[2]=%x, expected %x\n", source, destination[2], 1381169689Skan L'\0'); 1382169689Skan problemCount++; 1383169689Skan } 1384169689Skan if (destination[3] != L'X') { 1385169689Skan printf("\tPROBLEM: wcpcpy(destination, \"%ls\") -> " 1386169689Skan "destination[3]=%x, expected %x\n", source, destination[3], 1387169689Skan L'X'); 1388169689Skan problemCount++; 1389169689Skan } 1390169689Skan } 1391169689Skan 1392169689Skan { 1393169689Skan const wchar_t* source = L"t\xE4st"; 1394169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1395169689Skan wchar_t* result = wcpncpy(destination, source, 0); 1396169689Skan if (result != destination) { 1397169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 0) -> result=%p, " 1398169689Skan "expected %p\n", source, result, destination); 1399169689Skan problemCount++; 1400169689Skan } 1401169689Skan if (errno != 0) { 1402169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 0) -> errno=%d, " 1403169689Skan "expected 0\n", source, errno); 1404169689Skan problemCount++; 1405169689Skan } 1406169689Skan if (destination[0] != L'X') { 1407169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 0) -> " 1408169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 1409169689Skan L'X'); 1410169689Skan problemCount++; 1411169689Skan } 1412169689Skan } 1413169689Skan 1414169689Skan { 1415169689Skan const wchar_t* source = L"t\xE4st"; 1416169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1417169689Skan wchar_t* result = wcpncpy(destination, source, 2); 1418169689Skan if (result != destination + 2) { 1419169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> result=%p, " 1420169689Skan "expected %p\n", source, result, destination + 2); 1421169689Skan problemCount++; 1422169689Skan } 1423169689Skan if (errno != 0) { 1424169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> errno=%d, " 1425169689Skan "expected 0\n", source, errno); 1426169689Skan problemCount++; 1427169689Skan } 1428169689Skan if (destination[0] != L't') { 1429169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> " 1430169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 1431169689Skan L't'); 1432169689Skan problemCount++; 1433169689Skan } 1434169689Skan if (destination[1] != L'\xE4') { 1435169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> " 1436169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 1437169689Skan L'\xE4'); 1438169689Skan problemCount++; 1439169689Skan } 1440169689Skan if (destination[2] != L'X') { 1441169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 2) -> " 1442169689Skan "destination[2]=%x, expected %x\n", source, destination[2], 1443169689Skan L'X'); 1444169689Skan problemCount++; 1445169689Skan } 1446169689Skan } 1447169689Skan 1448169689Skan { 1449169689Skan const wchar_t* source = L"t\xE4st"; 1450169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1451169689Skan wchar_t* result = wcpncpy(destination, source, 4); 1452169689Skan if (result != destination + 4) { 1453169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> result=%p, " 1454169689Skan "expected %p\n", source, result, destination + 4); 1455169689Skan problemCount++; 1456169689Skan } 1457169689Skan if (errno != 0) { 1458169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> errno=%d, " 1459169689Skan "expected 0\n", source, errno); 1460169689Skan problemCount++; 1461169689Skan } 1462169689Skan if (destination[0] != L't') { 1463169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> " 1464169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 1465169689Skan L't'); 1466169689Skan problemCount++; 1467169689Skan } 1468169689Skan if (destination[1] != L'\xE4') { 1469169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> " 1470169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 1471169689Skan L'\xE4'); 1472169689Skan problemCount++; 1473169689Skan } 1474169689Skan if (destination[2] != L's') { 1475169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> " 1476169689Skan "destination[2]=%x, expected %x\n", source, destination[2], 1477169689Skan L's'); 1478169689Skan problemCount++; 1479169689Skan } 1480169689Skan if (destination[3] != L't') { 1481169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> " 1482169689Skan "destination[3]=%x, expected %x\n", source, destination[3], 1483169689Skan L't'); 1484169689Skan problemCount++; 1485169689Skan } 1486169689Skan if (destination[4] != L'X') { 1487169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 4) -> " 1488169689Skan "destination[4]=%x, expected %x\n", source, destination[4], 1489169689Skan L'X'); 1490169689Skan problemCount++; 1491169689Skan } 1492169689Skan } 1493169689Skan 1494169689Skan { 1495169689Skan const wchar_t* source = L"t\xE4st"; 1496169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXX"; 1497169689Skan wchar_t* result = wcpncpy(destination, source, 8); 1498169689Skan if (result != destination + 4) { 1499169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> result=%p, " 1500169689Skan "expected %p\n", source, result, destination + 4); 1501169689Skan problemCount++; 1502169689Skan } 1503169689Skan if (errno != 0) { 1504169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> errno=%d, " 1505169689Skan "expected 0\n", source, errno); 1506169689Skan problemCount++; 1507169689Skan } 1508169689Skan if (wcslen(destination) != 4) { 1509169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1510169689Skan "wcslen(destination)=%lu, expected 4\n", source, 1511169689Skan wcslen(destination)); 1512169689Skan problemCount++; 1513169689Skan } 1514169689Skan if (destination[0] != L't') { 1515169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1516169689Skan "destination[0]=%x, expected %x\n", source, destination[0], 1517169689Skan L't'); 1518169689Skan problemCount++; 1519169689Skan } 1520169689Skan if (destination[1] != L'\xE4') { 1521169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1522169689Skan "destination[1]=%x, expected %x\n", source, destination[1], 1523169689Skan L'\xE4'); 1524169689Skan problemCount++; 1525169689Skan } 1526169689Skan if (destination[2] != L's') { 1527169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1528169689Skan "destination[2]=%x, expected %x\n", source, destination[2], 1529169689Skan L's'); 1530169689Skan problemCount++; 1531169689Skan } 1532169689Skan if (destination[3] != L't') { 1533169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1534169689Skan "destination[3]=%x, expected %x\n", source, destination[3], 1535169689Skan L't'); 1536169689Skan problemCount++; 1537169689Skan } 1538169689Skan if (destination[4] != L'\0') { 1539169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1540169689Skan "destination[4]=%x, expected %x\n", source, destination[4], 1541169689Skan L'\0'); 1542169689Skan problemCount++; 1543169689Skan } 1544169689Skan if (destination[5] != L'\0') { 1545169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1546169689Skan "destination[5]=%x, expected %x\n", source, destination[5], 1547169689Skan L'\0'); 1548169689Skan problemCount++; 1549169689Skan } 1550169689Skan if (destination[6] != L'\0') { 1551169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1552169689Skan "destination[6]=%x, expected %x\n", source, destination[6], 1553169689Skan L'\0'); 1554169689Skan problemCount++; 1555169689Skan } 1556169689Skan if (destination[7] != L'\0') { 1557169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1558169689Skan "destination[7]=%x, expected %x\n", source, destination[7], 1559169689Skan L'\0'); 1560169689Skan problemCount++; 1561169689Skan } 1562169689Skan if (destination[8] != L'X') { 1563169689Skan printf("\tPROBLEM: wcpncpy(destination, \"%ls\", 8) -> " 1564169689Skan "destination[8]=%x, expected %x\n", source, destination[8], 1565169689Skan L'X'); 1566169689Skan problemCount++; 1567169689Skan } 1568169689Skan } 1569169689Skan 1570169689Skan if (problemCount) 1571169689Skan printf("\t%d problem(s) found!\n", problemCount); 1572169689Skan else 1573169689Skan printf("\tall fine\n"); 1574169689Skan} 1575169689Skan 1576169689Skan 1577169689Skan// #pragma mark - wcscat ------------------------------------------------------- 1578169689Skan 1579169689Skan 1580169689Skanvoid 1581169689Skantest_wcscat() 1582169689Skan{ 1583169689Skan printf("wcscat()/wcsncat()\n"); 1584169689Skan 1585169689Skan int problemCount = 0; 1586169689Skan errno = 0; 1587169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 1588169689Skan destination[0] = L'\0'; 1589169689Skan wchar_t backup[33]; 1590169689Skan 1591169689Skan { 1592169689Skan wcscpy(backup, destination); 1593169689Skan const wchar_t* source = L""; 1594169689Skan wchar_t* result = wcscat(destination, source); 1595169689Skan if (result != destination) { 1596169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> result=%p, " 1597169689Skan "expected %p\n", backup, source, result, destination); 1598169689Skan problemCount++; 1599169689Skan } 1600169689Skan if (errno != 0) { 1601169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> errno=%d, " 1602169689Skan "expected 0\n", backup, source, errno); 1603169689Skan problemCount++; 1604169689Skan } 1605169689Skan if (wcslen(destination) != 0) { 1606169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> " 1607169689Skan "wcslen(destination)=%lu, expected 0\n", backup, source, 1608169689Skan wcslen(destination)); 1609169689Skan problemCount++; 1610169689Skan } 1611169689Skan if (destination[0] != L'\0') { 1612169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[0]=%x, " 1613169689Skan "expected %x\n", backup, source, destination[0], L'\0'); 1614169689Skan problemCount++; 1615169689Skan } 1616169689Skan if (destination[1] != L'X') { 1617169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[1]=%x, " 1618169689Skan "expected %x\n", backup, source, destination[1], L'X'); 1619169689Skan problemCount++; 1620169689Skan } 1621169689Skan } 1622169689Skan 1623169689Skan { 1624223715Suqs wcscpy(backup, destination); 1625223715Suqs const wchar_t* source = L"test"; 1626223715Suqs wchar_t* result = wcscat(destination, source); 1627223715Suqs if (result != destination) { 1628169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> result=%p, " 1629169689Skan "expected %p\n", backup, source, result, destination); 1630169689Skan problemCount++; 1631169689Skan } 1632169689Skan if (errno != 0) { 1633169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> errno=%d, " 1634169689Skan "expected 0\n", backup, source, errno); 1635169689Skan problemCount++; 1636169689Skan } 1637169689Skan if (wcslen(destination) != 4) { 1638169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> " 1639169689Skan "wcslen(destination)=%lu, expected 4\n", backup, source, 1640169689Skan wcslen(destination)); 1641169689Skan problemCount++; 1642169689Skan } 1643169689Skan if (destination[0] != L't') { 1644169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[0]=%x, " 1645169689Skan "expected %x\n", backup, source, destination[0], L't'); 1646169689Skan problemCount++; 1647169689Skan } 1648169689Skan if (destination[1] != L'e') { 1649169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[1]=%x, " 1650169689Skan "expected %x\n", backup, source, destination[1], L'e'); 1651169689Skan problemCount++; 1652169689Skan } 1653169689Skan if (destination[2] != L's') { 1654169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[2]=%x, " 1655169689Skan "expected %x\n", backup, source, destination[2], L's'); 1656169689Skan problemCount++; 1657169689Skan } 1658169689Skan if (destination[3] != L't') { 1659169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[3]=%x, " 1660169689Skan "expected %x\n", backup, source, destination[3], L't'); 1661169689Skan problemCount++; 1662169689Skan } 1663169689Skan if (destination[4] != L'\0') { 1664169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[4]=%x, " 1665169689Skan "expected %x\n", backup, source, destination[4], L'\0'); 1666169689Skan problemCount++; 1667169689Skan } 1668169689Skan if (destination[5] != L'X') { 1669169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[5]=%x, " 1670169689Skan "expected %x\n", backup, source, destination[5], L'X'); 1671169689Skan problemCount++; 1672169689Skan } 1673169689Skan } 1674169689Skan 1675169689Skan { 1676169689Skan wcscpy(backup, destination); 1677169689Skan const wchar_t* source = L"t\xE4st"; 1678169689Skan wchar_t* result = wcscat(destination, source); 1679169689Skan if (result != destination) { 1680169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> result=%p, " 1681169689Skan "expected %p\n", backup, source, result, destination); 1682169689Skan problemCount++; 1683169689Skan } 1684169689Skan if (errno != 0) { 1685169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> errno=%d, " 1686169689Skan "expected 0\n", backup, source, errno); 1687169689Skan problemCount++; 1688169689Skan } 1689169689Skan if (wcslen(destination) != 8) { 1690169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> " 1691169689Skan "wcslen(destination)=%lu, expected 8\n", backup, source, 1692169689Skan wcslen(destination)); 1693169689Skan problemCount++; 1694169689Skan } 1695169689Skan if (destination[0] != L't') { 1696169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[0]=%x, " 1697169689Skan "expected %x\n", backup, source, destination[0], L't'); 1698169689Skan problemCount++; 1699169689Skan } 1700169689Skan if (destination[1] != L'e') { 1701169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[1]=%x, " 1702169689Skan "expected %x\n", backup, source, destination[1], L'e'); 1703169689Skan problemCount++; 1704169689Skan } 1705169689Skan if (destination[2] != L's') { 1706169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[2]=%x, " 1707169689Skan "expected %x\n", backup, source, destination[2], L's'); 1708169689Skan problemCount++; 1709169689Skan } 1710169689Skan if (destination[3] != L't') { 1711169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[3]=%x, " 1712169689Skan "expected %x\n", backup, source, destination[3], L't'); 1713169689Skan problemCount++; 1714169689Skan } 1715169689Skan if (destination[4] != L't') { 1716169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[4]=%x, " 1717169689Skan "expected %x\n", backup, source, destination[4], L't'); 1718169689Skan problemCount++; 1719169689Skan } 1720169689Skan if (destination[5] != L'\xE4') { 1721169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[5]=%x, " 1722169689Skan "expected %x\n", backup, source, destination[5], L'\xE4'); 1723169689Skan problemCount++; 1724169689Skan } 1725169689Skan if (destination[6] != L's') { 1726169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[6]=%x, " 1727169689Skan "expected %x\n", backup, source, destination[6], L's'); 1728169689Skan problemCount++; 1729169689Skan } 1730169689Skan if (destination[7] != L't') { 1731169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[7]=%x, " 1732169689Skan "expected %x\n", backup, source, destination[7], L't'); 1733169689Skan problemCount++; 1734169689Skan } 1735169689Skan if (destination[8] != L'\0') { 1736169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[8]=%x, " 1737169689Skan "expected %x\n", backup, source, destination[8], L'\0'); 1738169689Skan problemCount++; 1739169689Skan } 1740169689Skan if (destination[9] != L'X') { 1741169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[9]=%x, " 1742169689Skan "expected %x\n", backup, source, destination[9], L'X'); 1743169689Skan problemCount++; 1744169689Skan } 1745169689Skan } 1746169689Skan 1747169689Skan { 1748169689Skan wcscpy(backup, destination); 1749169689Skan const wchar_t* source = L"te\x00st"; 1750169689Skan wchar_t* result = wcscat(destination, source); 1751169689Skan if (result != destination) { 1752169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> result=%p, " 1753169689Skan "expected %p\n", backup, source, result, destination); 1754169689Skan problemCount++; 1755169689Skan } 1756169689Skan if (errno != 0) { 1757169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> errno=%d, " 1758169689Skan "expected 0\n", backup, source, errno); 1759169689Skan problemCount++; 1760169689Skan } 1761169689Skan if (wcslen(destination) != 10) { 1762169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> " 1763169689Skan "wcslen(destination)=%lu, expected 10\n", backup, source, 1764169689Skan wcslen(destination)); 1765169689Skan problemCount++; 1766169689Skan } 1767169689Skan if (destination[0] != L't') { 1768169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[0]=%x, " 1769169689Skan "expected %x\n", backup, source, destination[0], L't'); 1770169689Skan problemCount++; 1771169689Skan } 1772169689Skan if (destination[1] != L'e') { 1773169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[1]=%x, " 1774169689Skan "expected %x\n", backup, source, destination[1], L'e'); 1775169689Skan problemCount++; 1776169689Skan } 1777169689Skan if (destination[2] != L's') { 1778169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[2]=%x, " 1779169689Skan "expected %x\n", backup, source, destination[2], L's'); 1780169689Skan problemCount++; 1781169689Skan } 1782169689Skan if (destination[3] != L't') { 1783169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[3]=%x, " 1784169689Skan "expected %x\n", backup, source, destination[3], L't'); 1785169689Skan problemCount++; 1786169689Skan } 1787169689Skan if (destination[4] != L't') { 1788169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[4]=%x, " 1789169689Skan "expected %x\n", backup, source, destination[4], L't'); 1790169689Skan problemCount++; 1791169689Skan } 1792169689Skan if (destination[5] != L'\xE4') { 1793169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[5]=%x, " 1794169689Skan "expected %x\n", backup, source, destination[5], L'\xE4'); 1795169689Skan problemCount++; 1796169689Skan } 1797169689Skan if (destination[6] != L's') { 1798169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[6]=%x, " 1799169689Skan "expected %x\n", backup, source, destination[6], L's'); 1800169689Skan problemCount++; 1801169689Skan } 1802169689Skan if (destination[7] != L't') { 1803169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[7]=%x, " 1804169689Skan "expected %x\n", backup, source, destination[7], L't'); 1805169689Skan problemCount++; 1806169689Skan } 1807169689Skan if (destination[8] != L't') { 1808169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[8]=%x, " 1809169689Skan "expected %x\n", backup, source, destination[8], L't'); 1810169689Skan problemCount++; 1811169689Skan } 1812169689Skan if (destination[9] != L'e') { 1813169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[9]=%x, " 1814169689Skan "expected %x\n", backup, source, destination[9], L'e'); 1815169689Skan problemCount++; 1816169689Skan } 1817169689Skan if (destination[10] != L'\0') { 1818169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[10]=%x, " 1819169689Skan "expected %x\n", backup, source, destination[10], L'\0'); 1820169689Skan problemCount++; 1821169689Skan } 1822169689Skan if (destination[11] != L'X') { 1823169689Skan printf("\tPROBLEM: wcscat(\"%ls\", \"%ls\") -> destination[11]=%x, " 1824169689Skan "expected %x\n", backup, source, destination[11], L'X'); 1825169689Skan problemCount++; 1826169689Skan } 1827169689Skan } 1828169689Skan 1829169689Skan { 1830169689Skan wcscpy(destination, L"some"); 1831169689Skan wcscpy(backup, destination); 1832169689Skan const wchar_t* source = L" other text"; 1833169689Skan wchar_t* result = wcsncat(destination, source, 0); 1834169689Skan if (result != destination) { 1835169689Skan printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 0) -> result=%p, " 1836169689Skan "expected %p\n", backup, source, result, destination); 1837169689Skan problemCount++; 1838169689Skan } 1839169689Skan if (errno != 0) { 1840169689Skan printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 0) -> errno=%d, " 1841169689Skan "expected 0\n", backup, source, errno); 1842169689Skan problemCount++; 1843169689Skan } 1844169689Skan if (wcslen(destination) != 4) { 1845169689Skan printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 0) -> " 1846169689Skan "wcslen(destination)=%lu, expected 4\n", backup, source, 1847169689Skan wcslen(destination)); 1848169689Skan problemCount++; 1849169689Skan } 1850169689Skan if (wcscmp(destination, L"some") != 0) { 1851169689Skan printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 0) -> \"%ls\"\n", 1852169689Skan backup, source, destination); 1853169689Skan problemCount++; 1854169689Skan } 1855169689Skan } 1856169689Skan 1857169689Skan { 1858169689Skan wcscpy(destination, L"some"); 1859169689Skan wcscpy(backup, destination); 1860169689Skan const wchar_t* source = L" other text"; 1861169689Skan wchar_t* result = wcsncat(destination, source, 6); 1862169689Skan if (result != destination) { 1863169689Skan printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 6) -> result=%p, " 1864169689Skan "expected %p\n", backup, source, result, destination); 1865169689Skan problemCount++; 1866169689Skan } 1867169689Skan if (errno != 0) { 1868169689Skan printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 6) -> errno=%d, " 1869169689Skan "expected 0\n", backup, source, errno); 1870169689Skan problemCount++; 1871169689Skan } 1872169689Skan if (wcslen(destination) != 10) { 1873169689Skan printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 6) -> " 1874169689Skan "wcslen(destination)=%lu, expected 10\n", backup, source, 1875169689Skan wcslen(destination)); 1876169689Skan problemCount++; 1877169689Skan } 1878169689Skan if (wcscmp(destination, L"some other") != 0) { 1879169689Skan printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 6) -> \"%ls\"\n", 1880169689Skan backup, source, destination); 1881169689Skan problemCount++; 1882169689Skan } 1883169689Skan } 1884169689Skan 1885169689Skan { 1886169689Skan wcscpy(destination, L"some"); 1887169689Skan wcscpy(backup, destination); 1888169689Skan const wchar_t* source = L" other text"; 1889169689Skan wchar_t* result = wcsncat(destination, source, 20); 1890169689Skan if (result != destination) { 1891169689Skan printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 20) -> result=%p, " 1892169689Skan "expected %p\n", backup, source, result, destination); 1893169689Skan problemCount++; 1894169689Skan } 1895169689Skan if (errno != 0) { 1896169689Skan printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 20) -> errno=%d, " 1897169689Skan "expected 0\n", backup, source, errno); 1898169689Skan problemCount++; 1899169689Skan } 1900169689Skan if (wcslen(destination) != 15) { 1901169689Skan printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 20) -> " 1902169689Skan "wcslen(destination)=%lu, expected 15\n", backup, source, 1903169689Skan wcslen(destination)); 1904169689Skan problemCount++; 1905169689Skan } 1906169689Skan if (wcscmp(destination, L"some other text") != 0) { 1907169689Skan printf("\tPROBLEM: wcsncat(\"%ls\", \"%ls\", 20) -> \"%ls\"\n", 1908169689Skan backup, source, destination); 1909169689Skan problemCount++; 1910169689Skan } 1911169689Skan } 1912169689Skan 1913169689Skan if (problemCount) 1914169689Skan printf("\t%d problem(s) found!\n", problemCount); 1915169689Skan else 1916169689Skan printf("\tall fine\n"); 1917169689Skan} 1918169689Skan 1919169689Skan 1920169689Skan// #pragma mark - wcslcat ------------------------------------------------------ 1921169689Skan 1922169689Skan 1923169689Skan#ifdef __HAIKU__ 1924169689Skan 1925169689Skanvoid 1926169689Skantest_wcslcat() 1927169689Skan{ 1928169689Skan printf("wcslcat()\n"); 1929169689Skan 1930169689Skan int problemCount = 0; 1931169689Skan errno = 0; 1932169689Skan wchar_t destination[] = L"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"; 1933169689Skan wchar_t backup[33]; 1934169689Skan 1935169689Skan { 1936169689Skan wcscpy(backup, destination); 1937169689Skan const wchar_t* source = L""; 1938169689Skan size_t result = wcslcat(destination, source, 0); 1939169689Skan size_t expectedResult = 0; 1940169689Skan if (result != expectedResult) { 1941169689Skan printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 0) -> result=%ld, " 1942169689Skan "expected %ld\n", backup, source, result, expectedResult); 1943169689Skan problemCount++; 1944169689Skan } 1945169689Skan if (errno != 0) { 1946169689Skan printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 0) -> errno=%d, " 1947169689Skan "expected 0\n", backup, source, errno); 1948169689Skan problemCount++; 1949169689Skan } 1950169689Skan if (wcslen(destination) != 32) { 1951169689Skan printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 0) -> " 1952169689Skan "wcslen(destination)=%lu, expected 32\n", backup, source, 1953169689Skan wcslen(destination)); 1954169689Skan problemCount++; 1955169689Skan } 1956169689Skan if (destination[0] != L'X') { 1957169689Skan printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 0) -> destination[0]=" 1958169689Skan "%x, expected %x\n", backup, source, destination[0], L'X'); 1959169689Skan problemCount++; 1960169689Skan } 1961169689Skan } 1962169689Skan 1963169689Skan { 1964169689Skan destination[0] = L'\0'; 1965169689Skan wcscpy(backup, destination); 1966169689Skan const wchar_t* source = L""; 1967169689Skan size_t result = wcslcat(destination, source, 32); 1968169689Skan size_t expectedResult = 0; 1969169689Skan if (result != expectedResult) { 1970169689Skan printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> result=%ld, " 1971169689Skan "expected %ld\n", backup, source, result, expectedResult); 1972169689Skan problemCount++; 1973260311Spfg } 1974260311Spfg if (errno != 0) { 1975169689Skan printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> errno=%d, " 1976169689Skan "expected 0\n", backup, source, errno); 1977169689Skan problemCount++; 1978169689Skan } 1979169689Skan if (wcslen(destination) != 0) { 1980169689Skan printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> " 1981169689Skan "wcslen(destination)=%lu, expected 0\n", backup, source, 1982169689Skan wcslen(destination)); 1983169689Skan problemCount++; 1984260311Spfg } 1985260311Spfg if (destination[0] != L'\0') { 1986260311Spfg printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[0]=" 1987260311Spfg "%x, expected %x\n", backup, source, destination[0], L'\0'); 1988260311Spfg problemCount++; 1989260311Spfg } 1990260311Spfg if (destination[1] != L'X') { 1991169689Skan printf("\tPROBLEM: wcslcat(\"%ls\", \"%ls\", 32) -> destination[1]=" 1992169689Skan "%x, expected %x\n", backup, source, destination[1], L'X'); 1993169689Skan problemCount++; 1994169689Skan } 1995169689Skan } 1996169689Skan 1997169689Skan { 1998169689Skan wcscpy(backup, destination); 1999169689Skan const wchar_t* source = L"test"; 2000169689Skan size_t result = wcslcat(destination, source, 3); 2001169689Skan size_t expectedResult = 4; 2002169689Skan 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 2229void 2230test_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 2419struct coll_data { 2420 const wchar_t* a; 2421 const wchar_t* b; 2422 int result; 2423 int err; 2424}; 2425 2426 2427void 2428test_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 2466void 2467test_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 2602struct wcsftime_data { 2603 const wchar_t* format; 2604 const wchar_t* result; 2605}; 2606 2607 2608void 2609test_wcsftime(const char* locale, const wcsftime_data data[]) 2610{ 2611 setlocale(LC_TIME, locale); 2612 setlocale(LC_CTYPE, locale); 2613 printf("wcsftime for '%s'\n", locale); 2614 2615 time_t nowSecs = 1279391169; // pure magic 2616 tm* now = localtime(&nowSecs); 2617 int problemCount = 0; 2618 for (int i = 0; data[i].format != NULL; ++i) { 2619 wchar_t buf[100]; 2620 wcsftime(buf, 100, data[i].format, now); 2621 if (wcscmp(buf, data[i].result) != 0) { 2622 printf( 2623 "\tPROBLEM: wcsftime(\"%ls\") = \"%ls\" (expected \"%ls\")\n", 2624 data[i].format, buf, data[i].result); 2625 problemCount++; 2626 } 2627 } 2628 if (problemCount) 2629 printf("\t%d problem(s) found!\n", problemCount); 2630 else 2631 printf("\tall fine\n"); 2632} 2633 2634 2635void 2636test_wcsftime() 2637{ 2638 setenv("TZ", "GMT", 1); 2639 2640 const wcsftime_data wcsftime_posix[] = { 2641 { L"%c", L"Sat Jul 17 18:26:09 2010" }, 2642 { L"%x", L"07/17/10" }, 2643 { L"%X", L"18:26:09" }, 2644 { L"%a", L"Sat" }, 2645 { L"%A", L"Saturday" }, 2646 { L"%b", L"Jul" }, 2647 { L"%B", L"July" }, 2648 { NULL, NULL } 2649 }; 2650 test_wcsftime("POSIX", wcsftime_posix); 2651 2652 const wcsftime_data wcsftime_de[] = { 2653 { L"%c", L"Samstag, 17. Juli 2010 18:26:09 GMT" }, 2654 { L"%x", L"17.07.2010" }, 2655 { L"%X", L"18:26:09" }, 2656 { L"%a", L"Sa." }, 2657 { L"%A", L"Samstag" }, 2658 { L"%b", L"Jul" }, 2659 { L"%B", L"Juli" }, 2660 { NULL, NULL } 2661 }; 2662 test_wcsftime("de_DE.UTF-8", wcsftime_de); 2663 2664 const wcsftime_data wcsftime_hr[] = { 2665 { L"%c", L"subota, 17. srpnja 2010. 18:26:09 GMT" }, 2666 { L"%x", L"17. 07. 2010." }, 2667 { L"%X", L"18:26:09" }, 2668 { L"%a", L"sub" }, 2669 { L"%A", L"subota" }, 2670 { L"%b", L"srp" }, 2671 { L"%B", L"srpnja" }, 2672 { NULL, NULL } 2673 }; 2674 test_wcsftime("hr_HR.ISO8859-2", wcsftime_hr); 2675 2676 const wcsftime_data wcsftime_gu[] = { 2677 { L"%c", L"������������������, 17 ���������������, 2010 06:26:09 PM GMT" }, 2678 { L"%x", L"17 ���������������, 2010" }, 2679 { L"%X", L"06:26:09 PM" }, 2680 { L"%a", L"���������" }, 2681 { L"%A", L"������������������" }, 2682 { L"%b", L"���������������" }, 2683 { L"%B", L"���������������" }, 2684 { NULL, NULL } 2685 }; 2686 test_wcsftime("gu_IN", wcsftime_gu); 2687 2688 const wcsftime_data wcsftime_it[] = { 2689 { L"%c", L"sabato 17 luglio 2010 18:26:09 GMT" }, 2690 { L"%x", L"17/lug/2010" }, 2691 { L"%X", L"18:26:09" }, 2692 { L"%a", L"sab" }, 2693 { L"%A", L"sabato" }, 2694 { L"%b", L"lug" }, 2695 { L"%B", L"luglio" }, 2696 { NULL, NULL } 2697 }; 2698 test_wcsftime("it_IT", wcsftime_it); 2699 2700 const wcsftime_data wcsftime_nl[] = { 2701 { L"%c", L"zaterdag 17 juli 2010 18:26:09 GMT" }, 2702 { L"%x", L"17 jul. 2010" }, 2703 { L"%X", L"18:26:09" }, 2704 { L"%a", L"za" }, 2705 { L"%A", L"zaterdag" }, 2706 { L"%b", L"jul." }, 2707 { L"%B", L"juli" }, 2708 { NULL, NULL } 2709 }; 2710 test_wcsftime("nl_NL", wcsftime_nl); 2711 2712 const wcsftime_data wcsftime_nb[] = { 2713 { L"%c", L"kl. 18:26:09 GMT l\xF8rdag 17. juli 2010" }, 2714 { L"%x", L"17. juli 2010" }, 2715 { L"%X", L"18:26:09" }, 2716 { L"%a", L"l��r." }, 2717 { L"%A", L"l��rdag" }, 2718 { L"%b", L"juli" }, 2719 { L"%B", L"juli" }, 2720 { NULL, NULL } 2721 }; 2722 test_wcsftime("nb_NO", wcsftime_nb); 2723} 2724 2725 2726// #pragma mark - wcspbrk ------------------------------------------------------ 2727 2728 2729void 2730test_wcspbrk() 2731{ 2732 printf("wcspbrk()\n"); 2733 2734 int problemCount = 0; 2735 errno = 0; 2736 2737 { 2738 const wchar_t* string = L""; 2739 const wchar_t* accept = L" "; 2740 const wchar_t* result = wcspbrk(string, accept); 2741 const wchar_t* expected = NULL; 2742 if (result != expected || errno != 0) { 2743 printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p " 2744 "(expected %p), errno = %x (expected 0)\n", string, accept, 2745 result, expected, errno); 2746 problemCount++; 2747 } 2748 } 2749 2750 { 2751 const wchar_t* string = L"sometext"; 2752 const wchar_t* accept = L" "; 2753 const wchar_t* result = wcspbrk(string, accept); 2754 const wchar_t* expected = NULL; 2755 if (result != expected || errno != 0) { 2756 printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p " 2757 "(expected %p), errno = %x (expected 0)\n", string, accept, 2758 result, expected, errno); 2759 problemCount++; 2760 } 2761 } 2762 2763 { 2764 const wchar_t* string = L"some more text"; 2765 const wchar_t* accept = L" "; 2766 const wchar_t* result = wcspbrk(string, accept); 2767 const wchar_t* expected = string + 4; 2768 if (result != expected || errno != 0) { 2769 printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p " 2770 "(expected %p), errno = %x (expected 0)\n", string, accept, 2771 result, expected, errno); 2772 problemCount++; 2773 } 2774 } 2775 2776 { 2777 const wchar_t* string = L"some more text"; 2778 const wchar_t* accept = L"UY\xE4 "; 2779 const wchar_t* result = wcspbrk(string, accept); 2780 const wchar_t* expected = string + 4; 2781 if (result != expected || errno != 0) { 2782 printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p " 2783 "(expected %p), errno = %x (expected 0)\n", string, accept, 2784 result, expected, errno); 2785 problemCount++; 2786 } 2787 } 2788 2789 { 2790 const wchar_t* string = L"some more text"; 2791 const wchar_t* accept = L" emorstx"; 2792 const wchar_t* result = wcspbrk(string, accept); 2793 const wchar_t* expected = string; 2794 if (result != expected || errno != 0) { 2795 printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p " 2796 "(expected %p), errno = %x (expected 0)\n", string, accept, 2797 result, expected, errno); 2798 problemCount++; 2799 } 2800 } 2801 2802 { 2803 const wchar_t* string = L"some more text"; 2804 const wchar_t* accept = L"EMORSTX\xA0"; 2805 const wchar_t* result = wcspbrk(string, accept); 2806 const wchar_t* expected = NULL; 2807 if (result != expected || errno != 0) { 2808 printf("\tPROBLEM: result for wcspbrk(\"%ls\", \"%ls\") = %p " 2809 "(expected %p), errno = %x (expected 0)\n", string, accept, 2810 result, expected, errno); 2811 problemCount++; 2812 } 2813 } 2814 2815 if (problemCount) 2816 printf("\t%d problem(s) found!\n", problemCount); 2817 else 2818 printf("\tall fine\n"); 2819} 2820 2821 2822// #pragma mark - wcscspn ------------------------------------------------------- 2823 2824 2825void 2826test_wcscspn() 2827{ 2828 printf("wcscspn()\n"); 2829 2830 int problemCount = 0; 2831 errno = 0; 2832 2833 { 2834 const wchar_t* string = L""; 2835 const wchar_t* reject = L" "; 2836 size_t result = wcscspn(string, reject); 2837 size_t expected = 0; 2838 if (result != expected || errno != 0) { 2839 printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld " 2840 "(expected %ld), errno = %x (expected 0)\n", string, reject, 2841 result, expected, errno); 2842 problemCount++; 2843 } 2844 } 2845 2846 { 2847 const wchar_t* string = L"sometext"; 2848 const wchar_t* reject = L" "; 2849 size_t result = wcscspn(string, reject); 2850 size_t expected = 8; 2851 if (result != expected || errno != 0) { 2852 printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld " 2853 "(expected %ld), errno = %x (expected 0)\n", string, reject, 2854 result, expected, errno); 2855 problemCount++; 2856 } 2857 } 2858 2859 { 2860 const wchar_t* string = L"some more text"; 2861 const wchar_t* reject = L" mos"; 2862 size_t result = wcscspn(string, reject); 2863 size_t expected = 0; 2864 if (result != expected || errno != 0) { 2865 printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld " 2866 "(expected %ld), errno = %x (expected 0)\n", string, reject, 2867 result, expected, errno); 2868 problemCount++; 2869 } 2870 } 2871 2872 { 2873 const wchar_t* string = L"some more text"; 2874 const wchar_t* reject = L"t"; 2875 size_t result = wcscspn(string, reject); 2876 size_t expected = 10; 2877 if (result != expected || errno != 0) { 2878 printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld " 2879 "(expected %ld), errno = %x (expected 0)\n", string, reject, 2880 result, expected, errno); 2881 problemCount++; 2882 } 2883 } 2884 2885 { 2886 const wchar_t* string = L"some more text"; 2887 const wchar_t* reject = L"abcdfghijklnpquvwyz\t"; 2888 size_t result = wcscspn(string, reject); 2889 size_t expected = wcslen(string); 2890 if (result != expected || errno != 0) { 2891 printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld " 2892 "(expected %ld), errno = %x (expected 0)\n", string, reject, 2893 result, expected, errno); 2894 problemCount++; 2895 } 2896 } 2897 2898 { 2899 const wchar_t* string = L"some more text"; 2900 const wchar_t* reject = L""; 2901 size_t result = wcscspn(string, reject); 2902 size_t expected = wcslen(string); 2903 if (result != expected || errno != 0) { 2904 printf("\tPROBLEM: result for wcscspn(\"%ls\", \"%ls\") = %ld " 2905 "(expected %ld), errno = %x (expected 0)\n", string, reject, 2906 result, expected, errno); 2907 problemCount++; 2908 } 2909 } 2910 2911 if (problemCount) 2912 printf("\t%d problem(s) found!\n", problemCount); 2913 else 2914 printf("\tall fine\n"); 2915} 2916 2917 2918// #pragma mark - wcsspn ------------------------------------------------------- 2919 2920 2921void 2922test_wcsspn() 2923{ 2924 printf("wcsspn()\n"); 2925 2926 int problemCount = 0; 2927 errno = 0; 2928 2929 { 2930 const wchar_t* string = L""; 2931 const wchar_t* accept = L" "; 2932 size_t result = wcsspn(string, accept); 2933 size_t expected = 0; 2934 if (result != expected || errno != 0) { 2935 printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld " 2936 "(expected %ld), errno = %x (expected 0)\n", string, accept, 2937 result, expected, errno); 2938 problemCount++; 2939 } 2940 } 2941 2942 { 2943 const wchar_t* string = L"sometext"; 2944 const wchar_t* accept = L" "; 2945 size_t result = wcsspn(string, accept); 2946 size_t expected = 0; 2947 if (result != expected || errno != 0) { 2948 printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld " 2949 "(expected %ld), errno = %x (expected 0)\n", string, accept, 2950 result, expected, errno); 2951 problemCount++; 2952 } 2953 } 2954 2955 { 2956 const wchar_t* string = L"some more text"; 2957 const wchar_t* accept = L" emo"; 2958 size_t result = wcsspn(string, accept); 2959 size_t expected = 0; 2960 if (result != expected || errno != 0) { 2961 printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld " 2962 "(expected %ld), errno = %x (expected 0)\n", string, accept, 2963 result, expected, errno); 2964 problemCount++; 2965 } 2966 } 2967 2968 { 2969 const wchar_t* string = L"some more text"; 2970 const wchar_t* accept = L" emorstx"; 2971 size_t result = wcsspn(string, accept); 2972 size_t expected = wcslen(string); 2973 if (result != expected || errno != 0) { 2974 printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld " 2975 "(expected %ld), errno = %x (expected 0)\n", string, accept, 2976 result, expected, errno); 2977 problemCount++; 2978 } 2979 } 2980 2981 { 2982 const wchar_t* string = L"some more text"; 2983 const wchar_t* accept = L""; 2984 size_t result = wcsspn(string, accept); 2985 size_t expected = 0; 2986 if (result != expected || errno != 0) { 2987 printf("\tPROBLEM: result for wcsspn(\"%ls\", \"%ls\") = %ld " 2988 "(expected %ld), errno = %x (expected 0)\n", string, accept, 2989 result, expected, errno); 2990 problemCount++; 2991 } 2992 } 2993 2994 if (problemCount) 2995 printf("\t%d problem(s) found!\n", problemCount); 2996 else 2997 printf("\tall fine\n"); 2998} 2999 3000 3001// #pragma mark - wcsstr ------------------------------------------------------ 3002 3003 3004void 3005test_wcsstr() 3006{ 3007 printf("wcsstr()\n"); 3008 3009 int problemCount = 0; 3010 errno = 0; 3011 3012 { 3013 const wchar_t* string = L""; 3014 const wchar_t* sought = L" "; 3015 const wchar_t* result = wcsstr(string, sought); 3016 const wchar_t* expected = NULL; 3017 if (result != expected || errno != 0) { 3018 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3019 "(expected %p), errno = %x (expected 0)\n", string, sought, 3020 result, expected, errno); 3021 problemCount++; 3022 } 3023 } 3024 3025 { 3026 const wchar_t* string = L"sometext"; 3027 const wchar_t* sought = L"som "; 3028 const wchar_t* result = wcsstr(string, sought); 3029 const wchar_t* expected = NULL; 3030 if (result != expected || errno != 0) { 3031 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3032 "(expected %p), errno = %x (expected 0)\n", string, sought, 3033 result, expected, errno); 3034 problemCount++; 3035 } 3036 } 3037 3038 { 3039 const wchar_t* string = L"sometext"; 3040 const wchar_t* sought = L"soMe"; 3041 const wchar_t* result = wcsstr(string, sought); 3042 const wchar_t* expected = NULL; 3043 if (result != expected || errno != 0) { 3044 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3045 "(expected %p), errno = %x (expected 0)\n", string, sought, 3046 result, expected, errno); 3047 problemCount++; 3048 } 3049 } 3050 3051 { 3052 const wchar_t* string = L"some more text"; 3053 const wchar_t* sought = L"some "; 3054 const wchar_t* result = wcsstr(string, sought); 3055 const wchar_t* expected = string; 3056 if (result != expected || errno != 0) { 3057 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3058 "(expected %p), errno = %x (expected 0)\n", string, sought, 3059 result, expected, errno); 3060 problemCount++; 3061 } 3062 } 3063 3064 { 3065 const wchar_t* string = L"some more text"; 3066 const wchar_t* sought = L" more"; 3067 const wchar_t* result = wcsstr(string, sought); 3068 const wchar_t* expected = string + 4; 3069 if (result != expected || errno != 0) { 3070 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3071 "(expected %p), errno = %x (expected 0)\n", string, sought, 3072 result, expected, errno); 3073 problemCount++; 3074 } 3075 } 3076 3077 { 3078 const wchar_t* string = L"some more text"; 3079 const wchar_t* sought = L"some more text"; 3080 const wchar_t* result = wcsstr(string, sought); 3081 const wchar_t* expected = string; 3082 if (result != expected || errno != 0) { 3083 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3084 "(expected %p), errno = %x (expected 0)\n", string, sought, 3085 result, expected, errno); 3086 problemCount++; 3087 } 3088 } 3089 3090 { 3091 const wchar_t* string = L"some more text"; 3092 const wchar_t* sought = L"some more text "; 3093 const wchar_t* result = wcsstr(string, sought); 3094 const wchar_t* expected = NULL; 3095 if (result != expected || errno != 0) { 3096 printf("\tPROBLEM: result for wcsstr(\"%ls\", \"%ls\") = %p " 3097 "(expected %p), errno = %x (expected 0)\n", string, sought, 3098 result, expected, errno); 3099 problemCount++; 3100 } 3101 } 3102 3103 if (problemCount) 3104 printf("\t%d problem(s) found!\n", problemCount); 3105 else 3106 printf("\tall fine\n"); 3107} 3108 3109 3110// #pragma mark - wcstok ------------------------------------------------------ 3111 3112 3113void 3114test_wcstok() 3115{ 3116 printf("wcstok()\n"); 3117 3118 int problemCount = 0; 3119 3120 { 3121 wchar_t string[] = L""; 3122 const wchar_t* delim = L" \t\n"; 3123 wchar_t* state; 3124 wchar_t* result = wcstok(string, delim, &state); 3125 wchar_t* expected = NULL; 3126 wchar_t* expectedState = NULL; 3127 if (result != expected || state != expectedState) { 3128 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3129 "(expected %p), state = %p (expected %p)\n", string, delim, 3130 &state, result, expected, state, expectedState); 3131 problemCount++; 3132 } 3133 3134 result = wcstok(NULL, delim, &state); 3135 expected = NULL; 3136 expectedState = NULL; 3137 if (result != expected || state != expectedState) { 3138 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3139 "(expected %p), state = %p (expected %p)\n", string, delim, 3140 &state, result, expected, state, expectedState); 3141 problemCount++; 3142 } 3143 } 3144 3145 { 3146 wchar_t string[] = L"\t\t\t\n \t"; 3147 const wchar_t* delim = L" \t\n"; 3148 wchar_t* state; 3149 wchar_t* result = wcstok(string, delim, &state); 3150 wchar_t* expected = NULL; 3151 wchar_t* expectedState = NULL; 3152 if (result != expected || state != expectedState) { 3153 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3154 "(expected %p), state = %p (expected %p)\n", string, delim, 3155 &state, result, expected, state, expectedState); 3156 problemCount++; 3157 } 3158 3159 result = wcstok(NULL, delim, &state); 3160 expected = NULL; 3161 expectedState = NULL; 3162 if (result != expected || state != expectedState) { 3163 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3164 "(expected %p), state = %p (expected %p)\n", string, delim, 3165 &state, result, expected, state, expectedState); 3166 problemCount++; 3167 } 3168 } 3169 3170 { 3171 wchar_t string[] = L"just some text here!"; 3172 const wchar_t* delim = L" "; 3173 wchar_t* state; 3174 wchar_t* result = wcstok(string, delim, &state); 3175 wchar_t* expected = string; 3176 wchar_t* expectedState = string + 5; 3177 if (result != expected || state != expectedState) { 3178 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3179 "(expected %p), state = %p (expected %p)\n", string, delim, 3180 &state, result, expected, state, expectedState); 3181 problemCount++; 3182 } 3183 3184 result = wcstok(NULL, delim, &state); 3185 expected = string + 5; 3186 expectedState = string + 10; 3187 if (result != expected || state != expectedState) { 3188 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3189 "(expected %p), state = %p (expected %p)\n", string, delim, 3190 &state, result, expected, state, expectedState); 3191 problemCount++; 3192 } 3193 3194 result = wcstok(NULL, delim, &state); 3195 expected = string + 10; 3196 expectedState = string + 15; 3197 if (result != expected || state != expectedState) { 3198 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3199 "(expected %p), state = %p (expected %p)\n", string, delim, 3200 &state, result, expected, state, expectedState); 3201 problemCount++; 3202 } 3203 3204 result = wcstok(NULL, delim, &state); 3205 expected = string + 15; 3206 expectedState = NULL; 3207 if (result != expected || state != expectedState) { 3208 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3209 "(expected %p), state = %p (expected %p)\n", string, delim, 3210 &state, result, expected, state, expectedState); 3211 problemCount++; 3212 } 3213 3214 result = wcstok(NULL, delim, &state); 3215 expected = NULL; 3216 expectedState = NULL; 3217 if (result != expected || state != expectedState) { 3218 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3219 "(expected %p), state = %p (expected %p)\n", string, delim, 3220 &state, result, expected, state, expectedState); 3221 problemCount++; 3222 } 3223 } 3224 3225 { 3226 wchar_t string[] = L" just \t\nsome\t\t\ttext\n\n\nhere!"; 3227 const wchar_t* delim = L"\n\t "; 3228 wchar_t* state; 3229 wchar_t* result = wcstok(string, delim, &state); 3230 wchar_t* expected = string + 1; 3231 wchar_t* expectedState = string + 6; 3232 if (result != expected || state != expectedState) { 3233 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3234 "(expected %p), state = %p (expected %p)\n", string, delim, 3235 &state, result, expected, state, expectedState); 3236 problemCount++; 3237 } 3238 if (wcscmp(result, L"just") != 0) { 3239 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %ls " 3240 "(expected %ls)\n", string, delim, &state, result, L"just"); 3241 problemCount++; 3242 } 3243 3244 result = wcstok(NULL, delim, &state); 3245 expected = string + 8; 3246 expectedState = string + 13; 3247 if (result != expected || state != expectedState) { 3248 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3249 "(expected %p), state = %p (expected %p)\n", string, delim, 3250 &state, result, expected, state, expectedState); 3251 problemCount++; 3252 } 3253 if (wcscmp(result, L"some") != 0) { 3254 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %ls " 3255 "(expected %ls)\n", string, delim, &state, result, L"some"); 3256 problemCount++; 3257 } 3258 3259 result = wcstok(NULL, delim, &state); 3260 expected = string + 15; 3261 expectedState = string + 20; 3262 if (result != expected || state != expectedState) { 3263 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3264 "(expected %p), state = %p (expected %p)\n", string, delim, 3265 &state, result, expected, state, expectedState); 3266 problemCount++; 3267 } 3268 if (wcscmp(result, L"text") != 0) { 3269 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %ls " 3270 "(expected %ls)\n", string, delim, &state, result, L"text"); 3271 problemCount++; 3272 } 3273 3274 result = wcstok(NULL, delim, &state); 3275 expected = string + 22; 3276 expectedState = NULL; 3277 if (result != expected || state != expectedState) { 3278 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3279 "(expected %p), state = %p (expected %p)\n", string, delim, 3280 &state, result, expected, state, expectedState); 3281 problemCount++; 3282 } 3283 if (wcscmp(result, L"here!") != 0) { 3284 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %ls " 3285 "(expected %ls)\n", string, delim, &state, result, L"here!"); 3286 problemCount++; 3287 } 3288 3289 result = wcstok(NULL, delim, &state); 3290 expected = NULL; 3291 expectedState = NULL; 3292 if (result != expected || state != expectedState) { 3293 printf("\tPROBLEM: result for wcstok(\"%ls\", \"%ls\", %p) = %p " 3294 "(expected %p), state = %p (expected %p)\n", string, delim, 3295 &state, result, expected, state, expectedState); 3296 problemCount++; 3297 } 3298 } 3299 3300 if (problemCount) 3301 printf("\t%d problem(s) found!\n", problemCount); 3302 else 3303 printf("\tall fine\n"); 3304} 3305 3306 3307// #pragma mark - wmemchr ------------------------------------------------------ 3308 3309 3310void 3311test_wmemchr() 3312{ 3313 printf("wmemchr()\n"); 3314 3315 int problemCount = 0; 3316 errno = 0; 3317 3318 { 3319 const wchar_t* string = L""; 3320 const wchar_t ch = L' '; 3321 const wchar_t* result = wmemchr(string, ch, 0); 3322 const wchar_t* expected = NULL; 3323 if (result != expected || errno != 0) { 3324 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 0) = %p " 3325 "(expected %p), errno = %x (expected 0)\n", string, ch, 3326 result, expected, errno); 3327 problemCount++; 3328 } 3329 } 3330 3331 { 3332 const wchar_t* string = L""; 3333 const wchar_t ch = L'\0'; 3334 const wchar_t* result = wmemchr(string, ch, 0); 3335 const wchar_t* expected = NULL; 3336 if (result != expected || errno != 0) { 3337 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 0) = %p " 3338 "(expected %p), errno = %x (expected 0)\n", string, ch, 3339 result, expected, errno); 3340 problemCount++; 3341 } 3342 } 3343 3344 { 3345 const wchar_t* string = L""; 3346 const wchar_t ch = L'\0'; 3347 const wchar_t* result = wmemchr(string, ch, 1); 3348 const wchar_t* expected = string; 3349 if (result != expected || errno != 0) { 3350 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p " 3351 "(expected %p), errno = %x (expected 0)\n", string, ch, 3352 result, expected, errno); 3353 problemCount++; 3354 } 3355 } 3356 3357 { 3358 const wchar_t* string = L"sometext"; 3359 const wchar_t ch = L' '; 3360 const wchar_t* result = wmemchr(string, ch, 8); 3361 const wchar_t* expected = NULL; 3362 if (result != expected || errno != 0) { 3363 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p " 3364 "(expected %p), errno = %x (expected 0)\n", string, ch, 3365 result, expected, errno); 3366 problemCount++; 3367 } 3368 } 3369 3370 { 3371 const wchar_t* string = L"some text"; 3372 const wchar_t ch = L' '; 3373 const wchar_t* result = wmemchr(string, ch, 9); 3374 const wchar_t* expected = string + 4; 3375 if (result != expected || errno != 0) { 3376 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p " 3377 "(expected %p), errno = %x (expected 0)\n", string, ch, 3378 result, expected, errno); 3379 problemCount++; 3380 } 3381 } 3382 3383 { 3384 const wchar_t* string = L"some text"; 3385 const wchar_t ch = L'M'; 3386 const wchar_t* result = wmemchr(string, ch, 9); 3387 const wchar_t* expected = NULL; 3388 if (result != expected || errno != 0) { 3389 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p " 3390 "(expected %p), errno = %x (expected 0)\n", string, ch, 3391 result, expected, errno); 3392 problemCount++; 3393 } 3394 } 3395 3396 { 3397 const wchar_t* string = L"some\0text"; 3398 const wchar_t ch = L't'; 3399 const wchar_t* result = wmemchr(string, ch, 4); 3400 const wchar_t* expected = NULL; 3401 if (result != expected || errno != 0) { 3402 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p " 3403 "(expected %p), errno = %x (expected 0)\n", string, ch, 3404 result, expected, errno); 3405 problemCount++; 3406 } 3407 } 3408 3409 { 3410 const wchar_t* string = L"some\0text"; 3411 const wchar_t ch = L't'; 3412 const wchar_t* result = wmemchr(string, ch, 9); 3413 const wchar_t* expected = string + 5; 3414 if (result != expected || errno != 0) { 3415 printf("\tPROBLEM: result for wmemchr(\"%ls\", '%lc', 1) = %p " 3416 "(expected %p), errno = %x (expected 0)\n", string, ch, 3417 result, expected, errno); 3418 problemCount++; 3419 } 3420 } 3421 3422 if (problemCount) 3423 printf("\t%d problem(s) found!\n", problemCount); 3424 else 3425 printf("\tall fine\n"); 3426} 3427 3428 3429// #pragma mark - wmemcmp ------------------------------------------------------ 3430 3431 3432void 3433test_wmemcmp() 3434{ 3435 printf("wmemcmp()\n"); 3436 3437 int problemCount = 0; 3438 errno = 0; 3439 3440 { 3441 const wchar_t* a = L""; 3442 const wchar_t* b = L""; 3443 int result = sign(wmemcmp(a, b, 0)); 3444 int expected = 0; 3445 if (result != expected || errno != 0) { 3446 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 0) = %d " 3447 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3448 expected, errno); 3449 problemCount++; 3450 } 3451 } 3452 3453 { 3454 const wchar_t* a = L""; 3455 const wchar_t* b = L""; 3456 int result = sign(wmemcmp(a, b, 1)); 3457 int expected = 0; 3458 if (result != expected || errno != 0) { 3459 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 0) = %d " 3460 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3461 expected, errno); 3462 problemCount++; 3463 } 3464 } 3465 3466 { 3467 const wchar_t* a = L"a"; 3468 const wchar_t* b = L"b"; 3469 int result = sign(wmemcmp(a, b, 0)); 3470 int expected = 0; 3471 if (result != expected || errno != 0) { 3472 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 0) = %d " 3473 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3474 expected, errno); 3475 problemCount++; 3476 } 3477 } 3478 3479 { 3480 const wchar_t* a = L"a"; 3481 const wchar_t* b = L"b"; 3482 int result = sign(wmemcmp(a, b, 1)); 3483 int expected = -1; 3484 if (result != expected || errno != 0) { 3485 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 1) = %d " 3486 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3487 expected, errno); 3488 problemCount++; 3489 } 3490 } 3491 3492 { 3493 const wchar_t* a = L"b"; 3494 const wchar_t* b = L"a"; 3495 int result = sign(wmemcmp(a, b, 2)); 3496 int expected = 1; 3497 if (result != expected || errno != 0) { 3498 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 2) = %d " 3499 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3500 expected, errno); 3501 problemCount++; 3502 } 3503 } 3504 3505 { 3506 const wchar_t* a = L"a"; 3507 const wchar_t* b = L"A"; 3508 int result = sign(wmemcmp(a, b, 2)); 3509 int expected = 1; 3510 if (result != expected || errno != 0) { 3511 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 2) = %d " 3512 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3513 expected, errno); 3514 problemCount++; 3515 } 3516 } 3517 3518 { 3519 const wchar_t* a = L"t��st"; 3520 const wchar_t* b = L"t��st"; 3521 int result = sign(wmemcmp(a, b, 5)); 3522 int expected = 0; 3523 if (result != expected || errno != 0) { 3524 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 5) = %d " 3525 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3526 expected, errno); 3527 problemCount++; 3528 } 3529 } 3530 3531 { 3532 const wchar_t* a = L"t��st"; 3533 const wchar_t* b = L"t��st "; 3534 int result = sign(wmemcmp(a, b, 5)); 3535 int expected = -1; 3536 if (result != expected || errno != 0) { 3537 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 5) = %d " 3538 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3539 expected, errno); 3540 problemCount++; 3541 } 3542 } 3543 3544 { 3545 const wchar_t* a = L"t��St"; 3546 const wchar_t* b = L"t��s"; 3547 int result = sign(wmemcmp(a, b, 2)); 3548 int expected = 0; 3549 if (result != expected || errno != 0) { 3550 printf("\tPROBLEM: result for wmemcmp(\"%ls\", \"%ls\", 2) = %d " 3551 "(expected %d), errno = %x (expected 0)\n", a, b, result, 3552 expected, errno); 3553 problemCount++; 3554 } 3555 } 3556 3557 if (problemCount) 3558 printf("\t%d problem(s) found!\n", problemCount); 3559 else 3560 printf("\tall fine\n"); 3561} 3562 3563 3564// #pragma mark - wmemcpy ------------------------------------------------------ 3565 3566 3567void 3568test_wmemcpy() 3569{ 3570 printf("wmemcpy()\n"); 3571 3572 int problemCount = 0; 3573 errno = 0; 3574 3575 { 3576 const wchar_t* source = L""; 3577 wchar_t destination[] = L"XXXX"; 3578 wchar_t* result = wmemcpy(destination, source, 0); 3579 if (result != destination || errno != 0) { 3580 printf("\tPROBLEM: result for wmemcpy(destination, \"%ls\", 0) = " 3581 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3582 result, destination, errno); 3583 problemCount++; 3584 } 3585 if (destination[0] != L'X') { 3586 printf("\tPROBLEM: wmemcpy(destination, \"%ls\", 0) -> " 3587 "destination[0]=%x, expected %x\n", source, destination[0], 3588 L'X'); 3589 problemCount++; 3590 } 3591 } 3592 3593 { 3594 const wchar_t* source = L""; 3595 wchar_t destination[] = L"XXXX"; 3596 wchar_t* result = wmemcpy(destination, source, 1); 3597 if (result != destination || wmemcmp(destination, source, 1) != 0 3598 || errno != 0) { 3599 printf("\tPROBLEM: result for wmemcpy(destination, \"%ls\", 1) = " 3600 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3601 result, destination, errno); 3602 problemCount++; 3603 } 3604 if (destination[1] != L'X') { 3605 printf("\tPROBLEM: wmemcpy(destination, \"%ls\", 1) -> " 3606 "destination[1]=%x, expected %x\n", source, destination[1], 3607 L'X'); 3608 problemCount++; 3609 } 3610 } 3611 3612 { 3613 const wchar_t* source = L"t��stdata \0with some char��cters"; 3614 wchar_t destination[64]; 3615 wchar_t* result = wmemcpy(destination, source, 31); 3616 if (result != destination || wmemcmp(destination, source, 31) != 0 3617 || errno != 0) { 3618 printf("\tPROBLEM: result for wmemcpy(destination, \"%ls\", 31) = " 3619 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3620 result, destination, errno); 3621 problemCount++; 3622 } 3623 } 3624 3625 if (problemCount) 3626 printf("\t%d problem(s) found!\n", problemCount); 3627 else 3628 printf("\tall fine\n"); 3629} 3630 3631 3632// #pragma mark - wmempcpy ------------------------------------------------------ 3633 3634 3635void 3636test_wmempcpy() 3637{ 3638 printf("wmempcpy()\n"); 3639 3640 int problemCount = 0; 3641 errno = 0; 3642 3643 { 3644 const wchar_t* source = L""; 3645 wchar_t destination[] = L"XXXX"; 3646 wchar_t* result = wmempcpy(destination, source, 0); 3647 if (result != destination || errno != 0) { 3648 printf("\tPROBLEM: result for wmempcpy(destination, \"%ls\", 0) = " 3649 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3650 result, destination, errno); 3651 problemCount++; 3652 } 3653 if (destination[0] != L'X') { 3654 printf("\tPROBLEM: wmempcpy(destination, \"%ls\", 0) -> " 3655 "destination[0]=%x, expected %x\n", source, destination[0], 3656 L'X'); 3657 problemCount++; 3658 } 3659 } 3660 3661 { 3662 const wchar_t* source = L""; 3663 wchar_t destination[] = L"XXXX"; 3664 wchar_t* result = wmempcpy(destination, source, 1); 3665 if (result != destination + 1 || wmemcmp(destination, source, 1) != 0 3666 || errno != 0) { 3667 printf("\tPROBLEM: result for wmempcpy(destination, \"%ls\", 1) = " 3668 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3669 result, destination, errno); 3670 problemCount++; 3671 } 3672 if (destination[1] != L'X') { 3673 printf("\tPROBLEM: wmempcpy(destination, \"%ls\", 1) -> " 3674 "destination[1]=%x, expected %x\n", source, destination[1], 3675 L'X'); 3676 problemCount++; 3677 } 3678 } 3679 3680 { 3681 const wchar_t* source = L"t��stdata \0with some char��cters"; 3682 wchar_t destination[64]; 3683 wchar_t* result = wmempcpy(destination, source, 31); 3684 if (result != destination + 31 || wmemcmp(destination, source, 31) != 0 3685 || errno != 0) { 3686 printf("\tPROBLEM: result for wmempcpy(destination, \"%ls\", 31) = " 3687 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3688 result, destination, errno); 3689 problemCount++; 3690 } 3691 } 3692 3693 if (problemCount) 3694 printf("\t%d problem(s) found!\n", problemCount); 3695 else 3696 printf("\tall fine\n"); 3697} 3698 3699 3700// #pragma mark - wmemmove ------------------------------------------------------ 3701 3702 3703void 3704test_wmemmove() 3705{ 3706 printf("wmemmove()\n"); 3707 3708 int problemCount = 0; 3709 errno = 0; 3710 3711 { 3712 const wchar_t* source = L""; 3713 wchar_t destination[] = L"XXXX"; 3714 wchar_t* result = wmemmove(destination, source, 0); 3715 if (result != destination || errno != 0) { 3716 printf("\tPROBLEM: result for wmemmove(destination, \"%ls\", 0) = " 3717 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3718 result, destination, errno); 3719 problemCount++; 3720 } 3721 if (destination[0] != L'X') { 3722 printf("\tPROBLEM: wmemmove(destination, \"%ls\", 0) -> " 3723 "destination[0]=%x, expected %x\n", source, destination[0], 3724 L'X'); 3725 problemCount++; 3726 } 3727 } 3728 3729 { 3730 const wchar_t* source = L""; 3731 wchar_t destination[] = L"XXXX"; 3732 wchar_t* result = wmemmove(destination, source, 1); 3733 if (result != destination || wmemcmp(destination, source, 1) != 0 3734 || errno != 0) { 3735 printf("\tPROBLEM: result for wmemmove(destination, \"%ls\", 1) = " 3736 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3737 result, destination, errno); 3738 problemCount++; 3739 } 3740 if (destination[1] != L'X') { 3741 printf("\tPROBLEM: wmemmove(destination, \"%ls\", 1) -> " 3742 "destination[1]=%x, expected %x\n", source, destination[1], 3743 L'X'); 3744 problemCount++; 3745 } 3746 } 3747 3748 { 3749 const wchar_t* source = L"t��stdata \0with some char��cters"; 3750 wchar_t destination[64]; 3751 wmemcpy(destination, source, 31); 3752 wchar_t* result = wmemmove(destination, destination + 4, 27); 3753 if (result != destination || wmemcmp(destination, source + 4, 27) != 0 3754 || errno != 0) { 3755 printf("\tPROBLEM: result for wmemmove(destination, \"%ls\", 27) = " 3756 "\"%ls\" (expected %p), errno = %x (expected 0)\n", 3757 source + 4, result, destination, errno); 3758 problemCount++; 3759 } 3760 } 3761 3762 { 3763 const wchar_t* source = L"t��stdata \0with some char��cters"; 3764 wchar_t destination[64]; 3765 wmemcpy(destination, source, 31); 3766 wchar_t* result = wmemmove(destination + 2, destination, 8); 3767 if (result != destination + 2 3768 || wmemcmp(destination, L"t��t��stdatawith some char��cters", 31) != 0 3769 || errno != 0) { 3770 printf("\tPROBLEM: result for wmemmove(destination + 9, \"%ls\", 8)" 3771 " = \"%ls\" (expected %p), errno = %x (expected 0)\n", 3772 source, result, destination, errno); 3773 problemCount++; 3774 } 3775 } 3776 3777 if (problemCount) 3778 printf("\t%d problem(s) found!\n", problemCount); 3779 else 3780 printf("\tall fine\n"); 3781} 3782 3783 3784// #pragma mark - wmemset ------------------------------------------------------ 3785 3786 3787void 3788test_wmemset() 3789{ 3790 printf("wmemset()\n"); 3791 3792 int problemCount = 0; 3793 errno = 0; 3794 3795 { 3796 wchar_t source = L'\0'; 3797 wchar_t destination[] = L"XXXX"; 3798 wchar_t* result = wmemset(destination, source, 0); 3799 if (result != destination || errno != 0) { 3800 printf("\tPROBLEM: result for wmemset(destination, '%lc', 0) = " 3801 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3802 result, destination, errno); 3803 problemCount++; 3804 } 3805 if (destination[0] != L'X') { 3806 printf("\tPROBLEM: wmemset(destination, '%lc', 0) -> " 3807 "destination[0]=%x, expected %x\n", source, destination[0], 3808 L'X'); 3809 problemCount++; 3810 } 3811 } 3812 3813 { 3814 wchar_t source = L'M'; 3815 wchar_t destination[] = L"some text"; 3816 wchar_t* result = wmemset(destination, source, 1); 3817 if (result != destination || errno != 0) { 3818 printf("\tPROBLEM: result for wmemset(destination, '%lc', 1) = " 3819 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3820 result, destination, errno); 3821 problemCount++; 3822 } 3823 if (destination[0] != L'M') { 3824 printf("\tPROBLEM: wmemset(destination, '%lc', 1) -> " 3825 "destination[0]=%x, expected %x\n", source, destination[0], 3826 L'M'); 3827 problemCount++; 3828 } 3829 if (destination[1] != L'o') { 3830 printf("\tPROBLEM: wmemset(destination, '%lc', 1) -> " 3831 "destination[1]=%x, expected %x\n", source, destination[1], 3832 L'o'); 3833 problemCount++; 3834 } 3835 } 3836 3837 { 3838 wchar_t source = L'M'; 3839 wchar_t destination[] = L"some text"; 3840 wchar_t* result = wmemset(destination, source, 9); 3841 if (result != destination || errno != 0) { 3842 printf("\tPROBLEM: result for wmemset(destination, '%lc', 9) = " 3843 "\"%ls\" (expected %p), errno = %x (expected 0)\n", source, 3844 result, destination, errno); 3845 problemCount++; 3846 } 3847 for (int i = 0; i < 9; ++i) { 3848 if (destination[i] != L'M') { 3849 printf("\tPROBLEM: wmemset(destination, '%lc', 9) -> " 3850 "destination[%d]=%x, expected %x\n", source, i, 3851 destination[i], L'M'); 3852 problemCount++; 3853 } 3854 } 3855 } 3856 3857 if (problemCount) 3858 printf("\t%d problem(s) found!\n", problemCount); 3859 else 3860 printf("\tall fine\n"); 3861} 3862 3863 3864// #pragma mark - sprintf ------------------------------------------------------ 3865 3866 3867struct sprintf_data { 3868 const char* format; 3869 const void* value; 3870 const char* result; 3871}; 3872 3873 3874void 3875test_sprintf(const char* locale, const sprintf_data data[]) 3876{ 3877 setlocale(LC_ALL, locale); 3878 printf("sprintf for '%s'\n", locale); 3879 3880 int problemCount = 0; 3881 for (int i = 0; data[i].format != NULL; ++i) { 3882 char buf[100]; 3883 if (strstr(data[i].format, "%ls") != NULL) 3884 sprintf(buf, data[i].format, (wchar_t*)data[i].value); 3885 else if (strstr(data[i].format, "%s") != NULL) 3886 sprintf(buf, data[i].format, (char*)data[i].value); 3887 if (strcmp(buf, data[i].result) != 0) { 3888 printf("\tPROBLEM: sprintf(\"%s\") = \"%s\" (expected \"%s\")\n", 3889 data[i].format, buf, data[i].result); 3890 problemCount++; 3891 } 3892 } 3893 if (problemCount) 3894 printf("\t%d problem(s) found!\n", problemCount); 3895 else 3896 printf("\tall fine\n"); 3897} 3898 3899 3900void 3901test_sprintf() 3902{ 3903 const sprintf_data sprintf_posix[] = { 3904 { "%s", (const void*)"test", "test" }, 3905 { "%ls", (const void*)L"test", "test" }, 3906 { NULL, NULL, NULL } 3907 }; 3908 test_sprintf("POSIX", sprintf_posix); 3909 3910 const sprintf_data sprintf_de[] = { 3911 { "%s", "test", "test" }, 3912 { "%ls", L"test", "test" }, 3913 { "%s", "t\xC3\xA4st", "t\xC3\xA4st" }, 3914 { "%ls", L"t\xE4st", "t\xC3\xA4st" }, 3915 { NULL, NULL, NULL } 3916 }; 3917 test_sprintf("de_DE.UTF-8", sprintf_de); 3918 3919 const sprintf_data sprintf_de_iso[] = { 3920 { "%s", "test", "test" }, 3921 { "%ls", L"test", "test" }, 3922 { "%s", "t\xC3\xA4st", "t\xC3\xA4st" }, 3923 { "%s", "t\xE4st", "t\xE4st" }, 3924 { "%ls", L"t\xE4st", "t\xE4st" }, 3925 { NULL, NULL, NULL } 3926 }; 3927 test_sprintf("de_DE.ISO8859-1", sprintf_de_iso); 3928} 3929 3930 3931// #pragma mark - swprintf ---------------------------------------------------- 3932 3933 3934struct swprintf_data { 3935 const wchar_t* format; 3936 const void* value; 3937 const wchar_t* result; 3938}; 3939 3940 3941void 3942test_swprintf(const char* locale, const swprintf_data data[]) 3943{ 3944 setlocale(LC_ALL, locale); 3945 printf("swprintf for '%s'\n", locale); 3946 3947 int problemCount = 0; 3948 for (int i = 0; data[i].format != NULL; ++i) { 3949 wchar_t buf[100]; 3950 if (wcsstr(data[i].format, L"%ls") != NULL) 3951 swprintf(buf, 100, data[i].format, (wchar_t*)data[i].value); 3952 else if (wcsstr(data[i].format, L"%s") != NULL) 3953 swprintf(buf, 100, data[i].format, (char*)data[i].value); 3954 if (wcscmp(buf, data[i].result) != 0) { 3955 printf("\tPROBLEM: swprintf(\"%ls\") = \"%ls\" (expected \"%ls\")\n", 3956 data[i].format, buf, data[i].result); 3957 problemCount++; 3958 } 3959 } 3960 if (problemCount) 3961 printf("\t%d problem(s) found!\n", problemCount); 3962 else 3963 printf("\tall fine\n"); 3964} 3965 3966 3967void 3968test_swprintf() 3969{ 3970 const swprintf_data swprintf_posix[] = { 3971 { L"%s", (const void*)"test", L"test" }, 3972 { L"%ls", (const void*)L"test", L"test" }, 3973 { NULL, NULL, NULL } 3974 }; 3975 test_swprintf("POSIX", swprintf_posix); 3976 3977 const swprintf_data swprintf_de[] = { 3978 { L"%s", "test", L"test" }, 3979 { L"%ls", L"test", L"test" }, 3980 { L"%s", "t\xC3\xA4st", L"t\xE4st" }, 3981 { L"%ls", L"t\xE4st", L"t\xE4st" }, 3982 { NULL, NULL, NULL } 3983 }; 3984 test_swprintf("de_DE.UTF-8", swprintf_de); 3985 3986 const swprintf_data swprintf_de_iso[] = { 3987 { L"%s", "test", L"test" }, 3988 { L"%ls", L"test", L"test" }, 3989 { L"%s", "t\xC3\xA4st", L"t\xC3\xA4st" }, 3990 { L"%s", "t\xE4st", L"t\xE4st" }, 3991 { L"%ls", L"t\xE4st", L"t\xE4st" }, 3992 { NULL, NULL, NULL } 3993 }; 3994 test_swprintf("de_DE.ISO8859-1", swprintf_de_iso); 3995} 3996 3997 3998// #pragma mark - main --------------------------------------------------------- 3999 4000 4001/* 4002 * Test several different aspects of the wchar-string functions. 4003 */ 4004int 4005main(void) 4006{ 4007 setlocale(LC_ALL, "de_DE"); 4008 4009 test_collation(); 4010 4011 test_sprintf(); 4012 test_swprintf(); 4013 4014 test_wcsftime(); 4015 4016 test_wcpcpy(); 4017 test_wcscasecmp(); 4018 test_wcscat(); 4019 test_wcschr(); 4020 test_wcscmp(); 4021 test_wcscpy(); 4022 test_wcscspn(); 4023 test_wcsdup(); 4024#ifdef __HAIKU__ 4025 test_wcslcat(); 4026 test_wcslcpy(); 4027#endif 4028 test_wcslen(); 4029 test_wcspbrk(); 4030 test_wcsspn(); 4031 test_wcsstr(); 4032 test_wcstok(); 4033 4034 test_wmemchr(); 4035 test_wmemcmp(); 4036 test_wmemcpy(); 4037 test_wmemmove(); 4038 test_wmempcpy(); 4039 test_wmemset(); 4040 4041 return 0; 4042} 4043