Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2116 lines
68 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. mbtest.c
  5. Abstract:
  6. Test module for NLS API MultiByteToWideChar.
  7. NOTE: This code was simply hacked together quickly in order to
  8. test the different code modules of the NLS component.
  9. This is NOT meant to be a formal regression test.
  10. Revision History:
  11. 06-14-91 JulieB Created.
  12. --*/
  13. //
  14. // Include Files.
  15. //
  16. #include "nlstest.h"
  17. //
  18. // Constant Declarations.
  19. //
  20. #define BUFSIZE 1024 // buffer size in chars
  21. #define MB_INVALID_FLAGS ((DWORD)(~(MB_PRECOMPOSED | MB_COMPOSITE)))
  22. //
  23. // Global Variables.
  24. //
  25. #define mbMBStr "This Is A String."
  26. BYTE mbMBStr2[] = "This Is A String."; // this could get overwritten
  27. #define wcMBStr L"This Is A String."
  28. WCHAR wcMBDest[BUFSIZE];
  29. //
  30. // Forward Declarations.
  31. //
  32. int
  33. MB_BadParamCheck();
  34. int
  35. MB_NormalCase();
  36. int
  37. MB_TestFlags();
  38. int
  39. MB_TestDBCS();
  40. int
  41. DoUTF7FunctionTests();
  42. ////////////////////////////////////////////////////////////////////////////
  43. //
  44. // DoTestMultiByteToWideChar
  45. //
  46. // This routine help to test the MultiByteToWideChar() function.
  47. //
  48. // lpErrorString The title to be printed when the test case fails.
  49. // CodePage The code page for the byte to be converted to Unicode.
  50. // dwFlags The flag to be passed into MultiByteToWideChar()
  51. // lpMultiByteStr
  52. // StartIndex The start index of lpMultiByteStr
  53. // Count The char count of lpMultiByteStr
  54. // bTestNegativeLength Flag to indicate if the test of passing length as -1 should run or not.
  55. // ExpectReturn The expected return value of MultiByteToWideChar().
  56. // If error is expected, the value should be 0.
  57. // lpExpectWdieCharStr The expected conversion result.
  58. // dwExpectError The expecter value of GetLastError(). If no error is expected,
  59. // this value should be 0.
  60. //
  61. // This rountine will test the following cases and verify them with the expected result.
  62. //
  63. // 1. Pass the count of lpMulitByteStr in to MB2WC() to get the expected return
  64. // char count.
  65. // 2. Pass -1 as length of lpMulitByteStr to MB2WC() to get the expected return
  66. // char count.
  67. // 3. Pass the length of lpMulitByteStr in to MB2WC() to get the conversion result.
  68. // 4. Pass -1 as the length of lpMulitByteStr to MB2WC() to get the conversion result.
  69. //
  70. // 04-30-01 YSLin Created.
  71. ////////////////////////////////////////////////////////////////////////////
  72. int DoTestMultiByteToWideChar(
  73. LPSTR lpErrorString, UINT CodePage, DWORD dwFlags, LPCSTR lpMultiByteStr, UINT StartIndex, UINT Count,
  74. BOOL bTestNegativeLength,
  75. LPWSTR lpWideCharStr, int cchWideChar, int ExpectReturn, LPWSTR lpExpectWideCharStr, DWORD dwExpectError)
  76. {
  77. DWORD dwLastError;
  78. int NumErrors = 0;
  79. CHAR TempString[BUFSIZE];
  80. CHAR ErrorString[BUFSIZE];
  81. // Check the WCHAR count first.
  82. int Result = MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr + StartIndex, Count,
  83. NULL, 0);
  84. sprintf(ErrorString, "%s (MultiByteToWideChar(%d, 0x%x, \"%s\", %d, NULL, 0)",
  85. lpErrorString,
  86. CodePage,
  87. dwFlags,
  88. GetAnsiString((LPSTR)lpMultiByteStr + StartIndex, Count),
  89. Count);
  90. if (dwExpectError == 0)
  91. {
  92. CheckReturnValidW( Result,
  93. ExpectReturn,
  94. NULL,
  95. NULL,
  96. ErrorString,
  97. &NumErrors);
  98. } else
  99. {
  100. CheckLastError(dwExpectError, lpErrorString, &NumErrors);
  101. }
  102. if (bTestNegativeLength) {
  103. // Check the WCHAR count first (lenght = -1).
  104. Result = MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr + StartIndex, -1, NULL, 0);
  105. sprintf(ErrorString, "%s (MultiByteToWideChar(%d, 0x%x, \"%s\", %d, NULL, 0)",
  106. lpErrorString,
  107. CodePage,
  108. dwFlags,
  109. GetAnsiString((LPSTR)lpMultiByteStr + StartIndex, -1),
  110. -1);
  111. if (dwExpectError == 0)
  112. {
  113. CheckReturnValidW( Result,
  114. ExpectReturn + 1,
  115. NULL,
  116. NULL,
  117. ErrorString,
  118. &NumErrors);
  119. } else
  120. {
  121. CheckLastError(dwExpectError, lpErrorString, &NumErrors);
  122. }
  123. }
  124. // Do the real conversion.
  125. Result = MultiByteToWideChar(CodePage, dwFlags, lpMultiByteStr + StartIndex, Count,
  126. lpWideCharStr, cchWideChar);
  127. sprintf(ErrorString, "%s (MultiByteToWideChar(%d, 0x%x, \"%s\", %d)",
  128. lpErrorString,
  129. CodePage,
  130. dwFlags,
  131. GetAnsiString((LPSTR)lpMultiByteStr + StartIndex, Count),
  132. Count);
  133. if (dwExpectError == 0)
  134. {
  135. CheckReturnValidW( Result,
  136. ExpectReturn,
  137. lpWideCharStr,
  138. lpExpectWideCharStr,
  139. ErrorString,
  140. &NumErrors);
  141. } else
  142. {
  143. CheckLastError(dwExpectError, lpErrorString, &NumErrors);
  144. }
  145. // Do the real conversion with length -1.
  146. if (bTestNegativeLength)
  147. {
  148. strncpy(TempString, lpMultiByteStr + StartIndex, Count);
  149. TempString[Count] = '\0';
  150. Count = -1;
  151. sprintf(ErrorString, "%s (MultiByteToWideChar(%d, 0x%x, \"%s\", %d)",
  152. lpErrorString,
  153. CodePage,
  154. dwFlags,
  155. GetAnsiString((LPSTR)lpMultiByteStr + StartIndex, Count),
  156. Count);
  157. Result = MultiByteToWideChar(CodePage, dwFlags, TempString, Count,
  158. lpWideCharStr, cchWideChar);
  159. if (dwExpectError == 0)
  160. {
  161. CheckReturnValidW( Result,
  162. ExpectReturn + 1,
  163. lpWideCharStr,
  164. lpExpectWideCharStr,
  165. ErrorString,
  166. &NumErrors);
  167. } else
  168. {
  169. CheckLastError(dwExpectError, lpErrorString, &NumErrors);
  170. }
  171. }
  172. return (NumErrors);
  173. }
  174. //
  175. // 376403 Client RC1 2 Active Fix Ready
  176. // *Improper handling of invalid non-direct codes in UTF-7
  177. //
  178. int Regress376403()
  179. {
  180. int rc;
  181. int NumErrors = 0;
  182. printf("\n ---- Regress 376403 ----\n");
  183. rc = MultiByteToWideChar( CP_UTF7,
  184. 0,
  185. "\x80\x81",
  186. -1,
  187. wcMBDest,
  188. BUFSIZE );
  189. CheckReturnValidW( rc,
  190. 3,
  191. wcMBDest,
  192. L"\x0080\x0081",
  193. "CodePage CP_UTF7 - Invalid byte input",
  194. &NumErrors );
  195. rc = MultiByteToWideChar( CP_UTF7,
  196. 0,
  197. "\x2B\x80\x81\x82\x83\x2D",
  198. -1,
  199. wcMBDest,
  200. BUFSIZE);
  201. CheckReturnValidW( rc,
  202. 6,
  203. wcMBDest,
  204. L"\x0080\x0081\x0082\x0083\x002d",
  205. "CodePage CP_UTF7 - Invalid byte input 2",
  206. &NumErrors );
  207. return (NumErrors);
  208. }
  209. //
  210. // 381323 Client RC1 2 Active Fix Ready
  211. // *NLS: bad decoded multibyte sequences after unfinished multibyte sequences in UTF-8
  212. //
  213. int Regress381323()
  214. {
  215. int rc;
  216. int NumErrors = 0;
  217. printf("\n ---- Regress 381323 ----\n");
  218. NumErrors += DoTestMultiByteToWideChar(
  219. "Test UTF8 - Leading byte before end of sequence 1" ,
  220. CP_UTF8, 0, "\xe1\x80\xe1\x80\x80", 0, 5, TRUE, wcMBDest, BUFSIZE, 1, L"\x1000", 0);
  221. NumErrors += DoTestMultiByteToWideChar(
  222. "Test UTF8 - Leading byte before end of sequence 2" ,
  223. CP_UTF8, 0, "\xEF\xBF\xEF\xBF\xAE", 0, 5, TRUE, wcMBDest, BUFSIZE, 1, L"\xffee", 0);
  224. NumErrors += DoTestMultiByteToWideChar(
  225. "Test UTF8 - Leading byte before end of sequence 3" ,
  226. CP_UTF8, 0, "\xF0\xC4\x80", 0, 3, TRUE, wcMBDest, BUFSIZE, 1, L"\x0100", 0);
  227. NumErrors += DoTestMultiByteToWideChar(
  228. "Test UTF8 - Invalid byte - 1",
  229. CP_UTF8, 0, "\xEF\xFF\xEE", 0, 3, TRUE, wcMBDest, BUFSIZE, 0, L"", ERROR_NO_UNICODE_TRANSLATION) ;
  230. NumErrors += DoTestMultiByteToWideChar(
  231. "Test UTF8 - Invalid byte - 2",
  232. CP_UTF8, 0, "\xEF\xFF\xAE", 0, 3, TRUE, wcMBDest, BUFSIZE, 0, L"", ERROR_NO_UNICODE_TRANSLATION) ;
  233. NumErrors += DoTestMultiByteToWideChar(
  234. "Test UTF8 - Invalid byte - 3",
  235. CP_UTF8, 0, "\xEF\xBF\xAE", 0, 3, TRUE, wcMBDest, BUFSIZE, 0, L"", ERROR_NO_UNICODE_TRANSLATION) ;
  236. NumErrors += DoTestMultiByteToWideChar(
  237. "Test UTF8 - Invalid byte - 4",
  238. CP_UTF8, 0, "\xEF\xBF\xC0\xBF", 0, 4, TRUE, wcMBDest, BUFSIZE, 0, L"", ERROR_NO_UNICODE_TRANSLATION) ;
  239. return (NumErrors);
  240. }
  241. //
  242. // 381433 Client RC1 2 Active Fix Ready
  243. // *NLS: disparity decoding invalid (too high) scalar value
  244. //
  245. int Regress381433()
  246. {
  247. int rc;
  248. int NumErrors = 0;
  249. printf("\n ---- Regress 381433 ----\n");
  250. NumErrors += DoTestMultiByteToWideChar(
  251. "Test UTF8 - Too high Unicode scalar value",
  252. CP_UTF8, 0, "\xF4\x90\x80\x80" , 0, 4, TRUE, wcMBDest, BUFSIZE, 0, L"", ERROR_NO_UNICODE_TRANSLATION);
  253. NumErrors += DoTestMultiByteToWideChar(
  254. "Test UTF8 - Too high Unicode scalar value",
  255. CP_UTF8, 0, "\xF4\x90\x80\x80\x41\x42\x43" , 0, 7, TRUE, wcMBDest, BUFSIZE, 3, L"ABC", 0);
  256. return (NumErrors);
  257. }
  258. //
  259. // 371215 Client RC1 2 Active Fix Ready
  260. // *NLS: UTF-8 MultiByteToWideChar does should support the MB_ERR_INVALID_BYTES flag
  261. //
  262. int Regress371215()
  263. {
  264. int rc;
  265. int NumErrors = 0;
  266. printf("\n ---- Regress 371215 ----\n");
  267. // Test MB_ERR_INVALID_CHARS flag for UTF8.
  268. // Trailing byte without leading byte.
  269. NumErrors += DoTestMultiByteToWideChar(
  270. "Test UTF8 with MB_ERR_INVALID_CHARS - Trailing with leading",
  271. CP_UTF8, MB_ERR_INVALID_CHARS, "\x80", 0, 1, TRUE, wcMBDest, BUFSIZE, 0, NULL, ERROR_NO_UNICODE_TRANSLATION);
  272. NumErrors += DoTestMultiByteToWideChar(
  273. "Test UTF8 - Trailing with leading",
  274. CP_UTF8, 0, "\x80", 0, 1, TRUE, wcMBDest, BUFSIZE, 0, L"", ERROR_NO_UNICODE_TRANSLATION);
  275. // Leading byte before end of sequence
  276. NumErrors += DoTestMultiByteToWideChar(
  277. "Test UTF8 with MB_ERR_INVALID_CHARS - Leading byte before end of sequence 1" ,
  278. CP_UTF8, 0, "\xe1\x80\xe1\x80\x80", 0, 5, TRUE, wcMBDest, BUFSIZE, 1, L"", ERROR_NO_UNICODE_TRANSLATION);
  279. NumErrors += DoTestMultiByteToWideChar(
  280. "Test UTF8 with MB_ERR_INVALID_CHARS - Leading byte before end of sequence 2" ,
  281. CP_UTF8, MB_ERR_INVALID_CHARS, "\xEF\xBF\xEF\xBF\xAE", 0, 5, TRUE, wcMBDest, BUFSIZE, 0, NULL, ERROR_NO_UNICODE_TRANSLATION);
  282. NumErrors += DoTestMultiByteToWideChar(
  283. "Test UTF8 with MB_ERR_INVALID_CHARS - Leading byte before end of sequence 3" ,
  284. CP_UTF8, MB_ERR_INVALID_CHARS, "\xF0\xC4\x80", 0, 3, TRUE, wcMBDest, BUFSIZE, 1, NULL, ERROR_NO_UNICODE_TRANSLATION);
  285. // Too high Unicode value (over U+10FFFF)
  286. NumErrors += DoTestMultiByteToWideChar(
  287. "Test UTF8 - Too high Unicode scalar value with MB_ERR_INVALID_CHARS",
  288. CP_UTF8, MB_ERR_INVALID_CHARS, "\xF4\x90\x80\x80" , 0, 4, TRUE, wcMBDest, BUFSIZE, 0, NULL, ERROR_NO_UNICODE_TRANSLATION);
  289. // Test invalid flags for UTF8.
  290. NumErrors += DoTestMultiByteToWideChar(
  291. "Verify UTF8 will signal error on invalid flags",
  292. CP_UTF8, MB_PRECOMPOSED, "\x80", 0, 1, TRUE, wcMBDest, BUFSIZE, 0, NULL, ERROR_INVALID_FLAGS);
  293. NumErrors += DoTestMultiByteToWideChar(
  294. "Verify UTF8 will signal error on invalid flags",
  295. CP_UTF8, MB_COMPOSITE, "\x80", 0, 1, TRUE, wcMBDest, BUFSIZE, 0, NULL, ERROR_INVALID_FLAGS);
  296. NumErrors += DoTestMultiByteToWideChar(
  297. "Verify UTF8 will signal error on invalid flags",
  298. CP_UTF8, MB_USEGLYPHCHARS, "\x80", 0, 1, TRUE, wcMBDest, BUFSIZE, 0, NULL, ERROR_INVALID_FLAGS);
  299. NumErrors += DoTestMultiByteToWideChar(
  300. "Verify UTF8 will signal error on invalid flags",
  301. CP_UTF8, MB_PRECOMPOSED | MB_ERR_INVALID_CHARS, "\x80", 0, 1, TRUE, wcMBDest, BUFSIZE, 0, NULL, ERROR_INVALID_FLAGS);
  302. // Test MB_ERR_INVALID_CHARS flag for UTF7.
  303. // Verify that UTF7 does not support this flag.
  304. NumErrors += DoTestMultiByteToWideChar(
  305. "Verify UTF7 does not support MB_ERR_INVALID_CHARS",
  306. CP_UTF7, MB_ERR_INVALID_CHARS, "\x80", 0, 1, TRUE, wcMBDest, BUFSIZE, 0, NULL, ERROR_INVALID_FLAGS);
  307. return (NumErrors);
  308. }
  309. //
  310. //385490 Client RC1 1 Active Fix Ready
  311. //*NLS: broken decoding of correct sequences in UTF-8
  312. //
  313. BOOL Regress385490() {
  314. BOOL bPassed = TRUE;
  315. int NumErrors = 0;
  316. printf("\n ---- Regress 385490 ----\n");
  317. NumErrors += DoTestMultiByteToWideChar(
  318. "Bug 385490 - 1",
  319. CP_UTF8, 0, "\x1f\x10\x00\x09", 0, 4, FALSE, wcMBDest, BUFSIZE, 4, L"\x001f\x0010\x0000\x0009", 0);
  320. NumErrors += DoTestMultiByteToWideChar(
  321. "Bug 385490 - 2 Normal surrogate pair (lowset)",
  322. CP_UTF8, 0, "\xf0\x90\x80\x80", 0, 4, TRUE, wcMBDest, BUFSIZE, 2, L"\xd800\xdc00", 0);
  323. NumErrors += DoTestMultiByteToWideChar(
  324. "Bug 385490 - 3 Normal surrogate pair",
  325. CP_UTF8, 0, "\xf3\xb0\x80\x80", 0, 4, TRUE, wcMBDest, BUFSIZE, 2, L"\xdb80\xdc00", 0);
  326. NumErrors += DoTestMultiByteToWideChar(
  327. "Bug 385490 - 2 Normal surrogate pair (highest)",
  328. CP_UTF8, 0, "\xf4\x8f\xbf\xbf", 0, 4, TRUE, wcMBDest, BUFSIZE, 2, L"\xdbff\xdfff", 0);
  329. return (NumErrors);
  330. }
  331. //
  332. //389547 Client RC1 3 Active
  333. //NLS, UTF-8 , WideCharToMultiBytes() returns wrong value for not finished code sequence
  334. //
  335. BOOL Regress389547() {
  336. int NumErrors = 0;
  337. printf("\n ---- Regress 389547 ----\n");
  338. // 3-byte sequence
  339. NumErrors += DoTestMultiByteToWideChar(
  340. "Bug 389547 - Three byte UTF8",
  341. CP_UTF8, 0, "\xef\xbf\xae", 0, 3, FALSE, wcMBDest, BUFSIZE, 1, L"\xffee", 0);
  342. // Just a trailing byte.
  343. NumErrors += DoTestMultiByteToWideChar(
  344. "Bug 389547 - Trailing byte only",
  345. CP_UTF8, 0, "\xaa", 0, 1, FALSE, wcMBDest, BUFSIZE, 0, L"", ERROR_NO_UNICODE_TRANSLATION);
  346. // Unfinished 2 byte sequence
  347. NumErrors += DoTestMultiByteToWideChar(
  348. "Bug 389547 - Unfinished 2 byte sequence 1",
  349. CP_UTF8, 0, "\xc2", 0, 1, FALSE, wcMBDest, BUFSIZE, 0, L"", ERROR_NO_UNICODE_TRANSLATION);
  350. NumErrors += DoTestMultiByteToWideChar(
  351. "Bug 389547 - Unfinished 2 byte sequence 2",
  352. CP_UTF8, 0, "\xc2\x41\xc2\x41", 0, 4, FALSE, wcMBDest, BUFSIZE, 2, L"AA", 0);
  353. // Unfinished 3 byte sequence
  354. NumErrors += DoTestMultiByteToWideChar(
  355. "Bug 389547 - Unfinished 3 byte sequence 1",
  356. CP_UTF8, 0, "\xef\xbf", 0, 2, FALSE, wcMBDest, BUFSIZE, 0, L"", ERROR_NO_UNICODE_TRANSLATION);
  357. NumErrors += DoTestMultiByteToWideChar(
  358. "Bug 389547 - Unfinished 3 byte sequence 2",
  359. CP_UTF8, 0, "A\xef\xbf", 0, 2, FALSE, wcMBDest, BUFSIZE, 1, L"A", 0);
  360. // Unfinished 4 byte sequence
  361. NumErrors += DoTestMultiByteToWideChar(
  362. "Bug 389547 - Unfinished 4 byte sequence 1",
  363. CP_UTF8, 0, "\xf0\x90\x80", 0, 3, FALSE, wcMBDest, BUFSIZE, 0, L"", ERROR_NO_UNICODE_TRANSLATION);
  364. NumErrors += DoTestMultiByteToWideChar(
  365. "Bug 389547 - Unfinished 4 byte sequence 2",
  366. CP_UTF8, 0, "\xf4\x8f\xbf", 0, 3, FALSE, wcMBDest, BUFSIZE, 0, L"", ERROR_NO_UNICODE_TRANSLATION);
  367. NumErrors += DoTestMultiByteToWideChar(
  368. "Bug 389547 - Unfinished 4 byte sequence 3",
  369. CP_UTF8, 0, "\xf4\x8f\xbf\x41", 0, 4, FALSE, wcMBDest, BUFSIZE, 1, L"A", 0);
  370. return (NumErrors);
  371. }
  372. ////////////////////////////////////////////////////////////////////////////
  373. //
  374. // TestMBToWC
  375. //
  376. // Test routine for MultiByteToWideChar API.
  377. //
  378. // 06-14-91 JulieB Created.
  379. ////////////////////////////////////////////////////////////////////////////
  380. int TestMBToWC()
  381. {
  382. int ErrCount = 0; // error count
  383. //
  384. // Print out what's being done.
  385. //
  386. printf("\n\nTESTING MultiByteToWideChar...\n\n");
  387. //
  388. // Test bad parameters.
  389. //
  390. ErrCount += MB_BadParamCheck();
  391. //
  392. // Test normal cases.
  393. //
  394. ErrCount += MB_NormalCase();
  395. //
  396. // Test flags.
  397. //
  398. ErrCount += MB_TestFlags();
  399. //
  400. // Test DBCS.
  401. //
  402. ErrCount += MB_TestDBCS();
  403. ErrCount += DoUTF7FunctionTests();
  404. ErrCount += Regress376403();
  405. ErrCount += Regress381323();
  406. ErrCount += Regress381433();
  407. ErrCount += Regress371215();
  408. ErrCount += Regress385490();
  409. ErrCount += Regress389547();
  410. //
  411. // Print out result.
  412. //
  413. printf("\nMultiByteToWideChar: ERRORS = %d\n", ErrCount);
  414. //
  415. // Return total number of errors found.
  416. //
  417. return (ErrCount);
  418. }
  419. ////////////////////////////////////////////////////////////////////////////
  420. //
  421. // MB_BadParamCheck
  422. //
  423. // This routine passes in bad parameters to the API routine and checks to
  424. // be sure they are handled properly. The number of errors encountered
  425. // is returned to the caller.
  426. //
  427. // 06-14-91 JulieB Created.
  428. ////////////////////////////////////////////////////////////////////////////
  429. int MB_BadParamCheck()
  430. {
  431. int NumErrors = 0; // error count - to be returned
  432. int rc; // return code
  433. //
  434. // Null Pointers and Equal Pointers.
  435. //
  436. // Variation 1 - lpMultiByteStr = NULL
  437. rc = MultiByteToWideChar( 1252,
  438. MB_PRECOMPOSED,
  439. NULL,
  440. -1,
  441. wcMBDest,
  442. BUFSIZE );
  443. CheckReturnBadParam( rc,
  444. 0,
  445. ERROR_INVALID_PARAMETER,
  446. "lpMultiByteStr NULL",
  447. &NumErrors );
  448. // Variation 2 - lpWideCharStr = NULL
  449. rc = MultiByteToWideChar( 1252,
  450. MB_PRECOMPOSED,
  451. mbMBStr,
  452. -1,
  453. NULL,
  454. BUFSIZE );
  455. CheckReturnBadParam( rc,
  456. 0,
  457. ERROR_INVALID_PARAMETER,
  458. "lpWideCharStr NULL",
  459. &NumErrors );
  460. // Variation 3 - equal pointers
  461. rc = MultiByteToWideChar( 1252,
  462. 0,
  463. mbMBStr2,
  464. -1,
  465. (LPWSTR)mbMBStr2,
  466. sizeof(mbMBStr2) / sizeof(WCHAR) );
  467. CheckReturnBadParam( rc,
  468. 0,
  469. ERROR_INVALID_PARAMETER,
  470. "equal pointers",
  471. &NumErrors );
  472. //
  473. // Negative or Zero Lengths.
  474. //
  475. // Variation 1 - cchMultiByte = 0
  476. rc = MultiByteToWideChar( 1252,
  477. MB_PRECOMPOSED,
  478. mbMBStr,
  479. 0,
  480. wcMBDest,
  481. BUFSIZE );
  482. CheckReturnBadParam( rc,
  483. 0,
  484. ERROR_INVALID_PARAMETER,
  485. "cchMultiByte zero",
  486. &NumErrors );
  487. // Variation 2 - cchWideChar = negative
  488. rc = MultiByteToWideChar( 1252,
  489. MB_PRECOMPOSED,
  490. mbMBStr,
  491. -1,
  492. wcMBDest,
  493. -1 );
  494. CheckReturnBadParam( rc,
  495. 0,
  496. ERROR_INVALID_PARAMETER,
  497. "cchWideChar zero",
  498. &NumErrors );
  499. //
  500. // Invalid Code Page.
  501. //
  502. // Variation 1 - CodePage = invalid
  503. rc = MultiByteToWideChar( 8,
  504. MB_PRECOMPOSED,
  505. mbMBStr,
  506. -1,
  507. wcMBDest,
  508. BUFSIZE );
  509. CheckReturnBadParam( rc,
  510. 0,
  511. ERROR_INVALID_PARAMETER,
  512. "CodePage invalid",
  513. &NumErrors );
  514. // Variation 2 - CodePage = invalid
  515. rc = MultiByteToWideChar( 65002,
  516. MB_PRECOMPOSED,
  517. mbMBStr,
  518. -1,
  519. wcMBDest,
  520. BUFSIZE );
  521. CheckReturnBadParam( rc,
  522. 0,
  523. ERROR_INVALID_PARAMETER,
  524. "CodePage invalid 2",
  525. &NumErrors );
  526. //
  527. // Zero or Invalid Flag Values.
  528. //
  529. // Variation 1 - wFlags = 0
  530. rc = MultiByteToWideChar( 1252,
  531. 0,
  532. mbMBStr,
  533. -1,
  534. wcMBDest,
  535. BUFSIZE );
  536. CheckReturnValidW( rc,
  537. -1,
  538. wcMBDest,
  539. wcMBStr,
  540. "wFlags zero",
  541. &NumErrors );
  542. // Variation 2 - wFlags = invalid
  543. rc = MultiByteToWideChar( 1252,
  544. MB_INVALID_FLAGS,
  545. mbMBStr,
  546. -1,
  547. wcMBDest,
  548. BUFSIZE );
  549. CheckReturnBadParam( rc,
  550. 0,
  551. ERROR_INVALID_FLAGS,
  552. "wFlags invalid",
  553. &NumErrors );
  554. // Variation 3 - precomp | comp
  555. rc = MultiByteToWideChar( 1252,
  556. MB_PRECOMPOSED | MB_COMPOSITE,
  557. mbMBStr,
  558. -1,
  559. wcMBDest,
  560. BUFSIZE );
  561. CheckReturnBadParam( rc,
  562. 0,
  563. ERROR_INVALID_FLAGS,
  564. "precomp | comp",
  565. &NumErrors );
  566. //
  567. // Buffer Too Small.
  568. //
  569. // Variation 1 - cchWideChar = too small
  570. rc = MultiByteToWideChar( 1252,
  571. MB_PRECOMPOSED,
  572. mbMBStr,
  573. -1,
  574. wcMBDest,
  575. 2 );
  576. CheckReturnBadParam( rc,
  577. 0,
  578. ERROR_INSUFFICIENT_BUFFER,
  579. "cchWideChar too small",
  580. &NumErrors );
  581. //
  582. // No Unicode Translation - using MB_ERR_INVALID_CHARS flag.
  583. //
  584. #if 0
  585. // Variation 1 - cp 875
  586. rc = MultiByteToWideChar( 875,
  587. MB_ERR_INVALID_CHARS,
  588. "fa\x30",
  589. -1,
  590. wcMBDest,
  591. BUFSIZE );
  592. CheckReturnBadParam( rc,
  593. 0,
  594. ERROR_NO_UNICODE_TRANSLATION,
  595. "invalid char flag (875)",
  596. &NumErrors );
  597. // Variation 2 - cp 875
  598. rc = MultiByteToWideChar( 875,
  599. MB_ERR_INVALID_CHARS,
  600. "\x30",
  601. -1,
  602. wcMBDest,
  603. BUFSIZE );
  604. CheckReturnBadParam( rc,
  605. 0,
  606. ERROR_NO_UNICODE_TRANSLATION,
  607. "invalid char flag (875) 2",
  608. &NumErrors );
  609. #endif
  610. // Variation 3 - cp 857
  611. rc = MultiByteToWideChar( 857,
  612. MB_ERR_INVALID_CHARS,
  613. "fa\xd5",
  614. -1,
  615. wcMBDest,
  616. BUFSIZE );
  617. CheckReturnBadParam( rc,
  618. 0,
  619. ERROR_NO_UNICODE_TRANSLATION,
  620. "invalid char flag (857)",
  621. &NumErrors );
  622. // Variation 4 - cp 857
  623. rc = MultiByteToWideChar( 857,
  624. MB_ERR_INVALID_CHARS,
  625. "\xd5",
  626. -1,
  627. wcMBDest,
  628. BUFSIZE );
  629. CheckReturnBadParam( rc,
  630. 0,
  631. ERROR_NO_UNICODE_TRANSLATION,
  632. "invalid char flag (857) 2",
  633. &NumErrors );
  634. // Variation 5 - cp 857
  635. rc = MultiByteToWideChar( 857,
  636. MB_ERR_INVALID_CHARS,
  637. "fa\xd5t",
  638. -1,
  639. wcMBDest,
  640. BUFSIZE );
  641. CheckReturnBadParam( rc,
  642. 0,
  643. ERROR_NO_UNICODE_TRANSLATION,
  644. "invalid char flag (857) 3",
  645. &NumErrors );
  646. // Variation 6 - cp 857
  647. rc = MultiByteToWideChar( 857,
  648. MB_ERR_INVALID_CHARS | MB_COMPOSITE,
  649. "\xd5",
  650. -1,
  651. wcMBDest,
  652. BUFSIZE );
  653. CheckReturnBadParam( rc,
  654. 0,
  655. ERROR_NO_UNICODE_TRANSLATION,
  656. "invalid char/composite flag (857)",
  657. &NumErrors );
  658. // Variation 7 - cp 857
  659. rc = MultiByteToWideChar( 857,
  660. MB_ERR_INVALID_CHARS | MB_COMPOSITE,
  661. "fa\xd5t",
  662. -1,
  663. wcMBDest,
  664. BUFSIZE );
  665. CheckReturnBadParam( rc,
  666. 0,
  667. ERROR_NO_UNICODE_TRANSLATION,
  668. "invalid char/composite flag (857) 2",
  669. &NumErrors );
  670. // Variation 8 - cp 857
  671. rc = MultiByteToWideChar( 857,
  672. MB_ERR_INVALID_CHARS | MB_COMPOSITE | MB_USEGLYPHCHARS,
  673. "\xd5",
  674. -1,
  675. wcMBDest,
  676. BUFSIZE );
  677. CheckReturnBadParam( rc,
  678. 0,
  679. ERROR_NO_UNICODE_TRANSLATION,
  680. "invalid char/composite/glyph flag (857)",
  681. &NumErrors );
  682. // Variation 9 - cp 857
  683. rc = MultiByteToWideChar( 857,
  684. MB_ERR_INVALID_CHARS | MB_COMPOSITE | MB_USEGLYPHCHARS,
  685. "fa\xd5t",
  686. -1,
  687. wcMBDest,
  688. BUFSIZE );
  689. CheckReturnBadParam( rc,
  690. 0,
  691. ERROR_NO_UNICODE_TRANSLATION,
  692. "invalid char/composite/glyph flag (857) 2",
  693. &NumErrors );
  694. // Variation 10 - cp 857
  695. rc = MultiByteToWideChar( 857,
  696. MB_ERR_INVALID_CHARS | MB_USEGLYPHCHARS,
  697. "\xd5",
  698. -1,
  699. wcMBDest,
  700. BUFSIZE );
  701. CheckReturnBadParam( rc,
  702. 0,
  703. ERROR_NO_UNICODE_TRANSLATION,
  704. "invalid char/glyph flag (857)",
  705. &NumErrors );
  706. // Variation 10 - cp 857
  707. rc = MultiByteToWideChar( 857,
  708. MB_ERR_INVALID_CHARS | MB_USEGLYPHCHARS,
  709. "fa\xd5t",
  710. -1,
  711. wcMBDest,
  712. BUFSIZE );
  713. CheckReturnBadParam( rc,
  714. 0,
  715. ERROR_NO_UNICODE_TRANSLATION,
  716. "invalid char/glyph flag (857) 2",
  717. &NumErrors );
  718. //
  719. // DBCS - No Unicode Translation - using MB_ERR_INVALID_CHARS flag.
  720. //
  721. // Variation 1 - cp 932
  722. rc = MultiByteToWideChar( 932,
  723. MB_ERR_INVALID_CHARS,
  724. "\x81\x30",
  725. -1,
  726. wcMBDest,
  727. BUFSIZE );
  728. CheckReturnBadParam( rc,
  729. 0,
  730. ERROR_NO_UNICODE_TRANSLATION,
  731. "invalid char flag (932)",
  732. &NumErrors );
  733. // Variation 2 - cp 932
  734. rc = MultiByteToWideChar( 932,
  735. MB_ERR_INVALID_CHARS,
  736. "\x81",
  737. -1,
  738. wcMBDest,
  739. BUFSIZE );
  740. CheckReturnBadParam( rc,
  741. 0,
  742. ERROR_NO_UNICODE_TRANSLATION,
  743. "invalid char flag (932) 2",
  744. &NumErrors );
  745. // Variation 3 - cp 932
  746. rc = MultiByteToWideChar( 932,
  747. MB_ERR_INVALID_CHARS | MB_COMPOSITE,
  748. "\x81\x30",
  749. -1,
  750. wcMBDest,
  751. BUFSIZE );
  752. CheckReturnBadParam( rc,
  753. 0,
  754. ERROR_NO_UNICODE_TRANSLATION,
  755. "invalid char flag (932) 3",
  756. &NumErrors );
  757. // Variation 4 - cp 932
  758. rc = MultiByteToWideChar( 932,
  759. MB_ERR_INVALID_CHARS | MB_COMPOSITE,
  760. "\x81",
  761. -1,
  762. wcMBDest,
  763. BUFSIZE );
  764. CheckReturnBadParam( rc,
  765. 0,
  766. ERROR_NO_UNICODE_TRANSLATION,
  767. "invalid char/composite flag (932)",
  768. &NumErrors );
  769. // Variation 5 - cp 932
  770. rc = MultiByteToWideChar( 932,
  771. MB_ERR_INVALID_CHARS | MB_COMPOSITE | MB_USEGLYPHCHARS,
  772. "\x81\x30",
  773. -1,
  774. wcMBDest,
  775. BUFSIZE );
  776. CheckReturnBadParam( rc,
  777. 0,
  778. ERROR_NO_UNICODE_TRANSLATION,
  779. "invalid char/composite/glyph flag (932)",
  780. &NumErrors );
  781. // Variation 6 - cp 932
  782. rc = MultiByteToWideChar( 932,
  783. MB_ERR_INVALID_CHARS | MB_COMPOSITE | MB_USEGLYPHCHARS,
  784. "\x81",
  785. -1,
  786. wcMBDest,
  787. BUFSIZE );
  788. CheckReturnBadParam( rc,
  789. 0,
  790. ERROR_NO_UNICODE_TRANSLATION,
  791. "invalid char/composite/glyph flag (932) 2",
  792. &NumErrors );
  793. // Variation 7 - cp 932
  794. rc = MultiByteToWideChar( 932,
  795. MB_ERR_INVALID_CHARS | MB_USEGLYPHCHARS,
  796. "\x81\x30",
  797. -1,
  798. wcMBDest,
  799. BUFSIZE );
  800. CheckReturnBadParam( rc,
  801. 0,
  802. ERROR_NO_UNICODE_TRANSLATION,
  803. "invalid char/glyph flag (932)",
  804. &NumErrors );
  805. // Variation 8 - cp 932
  806. rc = MultiByteToWideChar( 932,
  807. MB_ERR_INVALID_CHARS | MB_USEGLYPHCHARS,
  808. "\x81",
  809. -1,
  810. wcMBDest,
  811. BUFSIZE );
  812. CheckReturnBadParam( rc,
  813. 0,
  814. ERROR_NO_UNICODE_TRANSLATION,
  815. "invalid char/glyph flag (932) 2",
  816. &NumErrors );
  817. //
  818. // Return total number of errors found.
  819. //
  820. return (NumErrors);
  821. }
  822. ////////////////////////////////////////////////////////////////////////////
  823. //
  824. // MB_NormalCase
  825. //
  826. // This routine tests the normal cases of the API routine.
  827. //
  828. // 06-14-91 JulieB Created.
  829. ////////////////////////////////////////////////////////////////////////////
  830. int MB_NormalCase()
  831. {
  832. int NumErrors = 0; // error count - to be returned
  833. int rc; // return code
  834. BYTE Ch; // buffer for one character
  835. WCHAR CheckBuf; // return buffer for one character
  836. LPWSTR pBogus = NULL; // bogus, uninitialized pointer
  837. LCID Locale; // save the old locale
  838. #ifdef PERF
  839. DbgBreakPoint();
  840. #endif
  841. //
  842. // cchWideChar.
  843. //
  844. // Variation 1 - cchWideChar = length of wcMBDest
  845. rc = MultiByteToWideChar( 1252,
  846. MB_PRECOMPOSED,
  847. mbMBStr,
  848. -1,
  849. wcMBDest,
  850. BUFSIZE );
  851. CheckReturnValidW( rc,
  852. -1,
  853. wcMBDest,
  854. wcMBStr,
  855. "cchWideChar (length)",
  856. &NumErrors );
  857. // Variation 2 - cchWideChar = 0
  858. wcMBDest[0] = 0x0005;
  859. rc = MultiByteToWideChar( 1252,
  860. MB_PRECOMPOSED,
  861. mbMBStr,
  862. -1,
  863. wcMBDest,
  864. 0 );
  865. CheckReturnValidW( rc,
  866. -1,
  867. NULL,
  868. wcMBStr,
  869. "cchWideChar zero",
  870. &NumErrors );
  871. // Variation 3 - cchWideChar = 0, wcMBDest = NULL
  872. rc = MultiByteToWideChar( 1252,
  873. MB_PRECOMPOSED,
  874. mbMBStr,
  875. -1,
  876. NULL,
  877. 0 );
  878. CheckReturnValidW( rc,
  879. -1,
  880. NULL,
  881. wcMBStr,
  882. "cchWideChar (NULL ptr)",
  883. &NumErrors );
  884. // Variation 4 - cchWideChar = 0, wcMBDest = uninitialized ptr
  885. rc = MultiByteToWideChar( 1252,
  886. MB_PRECOMPOSED,
  887. mbMBStr,
  888. -1,
  889. pBogus,
  890. 0 );
  891. CheckReturnValidW( rc,
  892. -1,
  893. NULL,
  894. wcMBStr,
  895. "cchWideChar (bogus ptr)",
  896. &NumErrors );
  897. //
  898. // cchMultiByte.
  899. //
  900. // Variation 1 - cchMultiByte = length of mbMBStr
  901. rc = MultiByteToWideChar( 1252,
  902. MB_PRECOMPOSED,
  903. mbMBStr,
  904. MB_STRING_LEN(mbMBStr),
  905. wcMBDest,
  906. BUFSIZE );
  907. CheckReturnValidW( rc,
  908. WC_STRING_LEN(wcMBStr),
  909. wcMBDest,
  910. wcMBStr,
  911. "cchMultiByte (length)",
  912. &NumErrors );
  913. // Variation 2 - cchMultiByte = -1
  914. rc = MultiByteToWideChar( 1252,
  915. MB_PRECOMPOSED,
  916. mbMBStr,
  917. -1,
  918. wcMBDest,
  919. BUFSIZE );
  920. CheckReturnValidW( rc,
  921. -1,
  922. wcMBDest,
  923. wcMBStr,
  924. "cchMultiByte (-1)",
  925. &NumErrors );
  926. // Variation 3 - cchMultiByte = length of mbMBStr, no wcMBDest
  927. rc = MultiByteToWideChar( 1252,
  928. MB_PRECOMPOSED,
  929. mbMBStr,
  930. MB_STRING_LEN(mbMBStr),
  931. NULL,
  932. 0 );
  933. CheckReturnValidW( rc,
  934. WC_STRING_LEN(wcMBStr),
  935. NULL,
  936. wcMBStr,
  937. "cchMultiByte (length), no wcMBDest",
  938. &NumErrors );
  939. // Variation 4 - cchMultiByte = -1, no wcMBDest
  940. rc = MultiByteToWideChar( 1252,
  941. MB_PRECOMPOSED,
  942. mbMBStr,
  943. -1,
  944. NULL,
  945. 0 );
  946. CheckReturnValidW( rc,
  947. -1,
  948. NULL,
  949. wcMBStr,
  950. "cchMultiByte (-1), no wcMBDest",
  951. &NumErrors );
  952. //
  953. // CodePage.
  954. //
  955. // Variation 1 - CodePage = CP_ACP
  956. rc = MultiByteToWideChar( CP_ACP,
  957. MB_PRECOMPOSED,
  958. mbMBStr,
  959. -1,
  960. wcMBDest,
  961. BUFSIZE );
  962. CheckReturnValidW( rc,
  963. -1,
  964. wcMBDest,
  965. wcMBStr,
  966. "CodePage CP_ACP",
  967. &NumErrors );
  968. // Variation 2 - CodePage = CP_ACP, no wcMBDest
  969. rc = MultiByteToWideChar( CP_ACP,
  970. MB_PRECOMPOSED,
  971. mbMBStr,
  972. -1,
  973. NULL,
  974. 0 );
  975. CheckReturnValidW( rc,
  976. -1,
  977. NULL,
  978. wcMBStr,
  979. "CodePage CP_ACP, no wcMBDest",
  980. &NumErrors );
  981. // Variation 3 - CodePage = CP_OEMCP
  982. rc = MultiByteToWideChar( CP_OEMCP,
  983. MB_PRECOMPOSED,
  984. mbMBStr,
  985. -1,
  986. wcMBDest,
  987. BUFSIZE );
  988. CheckReturnValidW( rc,
  989. -1,
  990. wcMBDest,
  991. wcMBStr,
  992. "CodePage CP_OEMCP",
  993. &NumErrors );
  994. // Variation 4 - CodePage = CP_OEMCP, no wcMBDest
  995. rc = MultiByteToWideChar( CP_OEMCP,
  996. MB_PRECOMPOSED,
  997. mbMBStr,
  998. -1,
  999. NULL,
  1000. 0 );
  1001. CheckReturnValidW( rc,
  1002. -1,
  1003. NULL,
  1004. wcMBStr,
  1005. "CodePage CP_OEMCP, no wcMBDest",
  1006. &NumErrors );
  1007. // Variation 5 - CodePage = CP_MACCP
  1008. rc = MultiByteToWideChar( CP_MACCP,
  1009. MB_PRECOMPOSED,
  1010. mbMBStr,
  1011. -1,
  1012. wcMBDest,
  1013. BUFSIZE );
  1014. CheckReturnValidW( rc,
  1015. -1,
  1016. wcMBDest,
  1017. wcMBStr,
  1018. "CodePage CP_MACCP",
  1019. &NumErrors );
  1020. // Variation 6 - CodePage = CP_MACCP, no wcMBDest
  1021. rc = MultiByteToWideChar( CP_MACCP,
  1022. MB_PRECOMPOSED,
  1023. mbMBStr,
  1024. -1,
  1025. NULL,
  1026. 0 );
  1027. CheckReturnValidW( rc,
  1028. -1,
  1029. NULL,
  1030. wcMBStr,
  1031. "CodePage CP_MACCP, no wcMBDest",
  1032. &NumErrors );
  1033. // Variation 7 - CodePage = 437
  1034. rc = MultiByteToWideChar( 437,
  1035. MB_PRECOMPOSED,
  1036. mbMBStr,
  1037. -1,
  1038. wcMBDest,
  1039. BUFSIZE );
  1040. CheckReturnValidW( rc,
  1041. -1,
  1042. wcMBDest,
  1043. wcMBStr,
  1044. "CodePage 437",
  1045. &NumErrors );
  1046. // Variation 8 - CodePage = 437, no wcMBDest
  1047. rc = MultiByteToWideChar( 437,
  1048. MB_PRECOMPOSED,
  1049. mbMBStr,
  1050. -1,
  1051. NULL,
  1052. 0 );
  1053. CheckReturnValidW( rc,
  1054. -1,
  1055. NULL,
  1056. wcMBStr,
  1057. "CodePage 437, no wcMBDest",
  1058. &NumErrors );
  1059. // Variation 9 - CodePage = 850
  1060. rc = MultiByteToWideChar( 850,
  1061. MB_PRECOMPOSED,
  1062. mbMBStr,
  1063. -1,
  1064. wcMBDest,
  1065. BUFSIZE );
  1066. CheckReturnValidW( rc,
  1067. -1,
  1068. wcMBDest,
  1069. wcMBStr,
  1070. "CodePage 850",
  1071. &NumErrors );
  1072. // Variation 10 - CodePage = 850, no wcMBDest
  1073. rc = MultiByteToWideChar( 850,
  1074. MB_PRECOMPOSED,
  1075. mbMBStr,
  1076. -1,
  1077. NULL,
  1078. 0 );
  1079. CheckReturnValidW( rc,
  1080. -1,
  1081. NULL,
  1082. wcMBStr,
  1083. "CodePage 850, no wcMBDest",
  1084. &NumErrors );
  1085. // Variation 11 - CodePage = 10000
  1086. rc = MultiByteToWideChar( 10000,
  1087. MB_PRECOMPOSED,
  1088. mbMBStr,
  1089. -1,
  1090. wcMBDest,
  1091. BUFSIZE );
  1092. CheckReturnValidW( rc,
  1093. -1,
  1094. wcMBDest,
  1095. wcMBStr,
  1096. "CodePage 10000",
  1097. &NumErrors );
  1098. // Variation 12 - CodePage = 10000, no wcMBDest
  1099. rc = MultiByteToWideChar( 10000,
  1100. MB_PRECOMPOSED,
  1101. mbMBStr,
  1102. -1,
  1103. NULL,
  1104. 0 );
  1105. CheckReturnValidW( rc,
  1106. -1,
  1107. NULL,
  1108. wcMBStr,
  1109. "CodePage 10000, no wcMBDest",
  1110. &NumErrors );
  1111. // Variation 13 - CodePage = CP_THREAD_ACP
  1112. rc = MultiByteToWideChar( CP_THREAD_ACP,
  1113. 0,
  1114. mbMBStr,
  1115. -1,
  1116. wcMBDest,
  1117. BUFSIZE );
  1118. CheckReturnValidW( rc,
  1119. -1,
  1120. wcMBDest,
  1121. wcMBStr,
  1122. "CodePage CP_THREAD_ACP",
  1123. &NumErrors );
  1124. // Variation 14 - CodePage = CP_THREAD_ACP, no wcMBDest
  1125. rc = MultiByteToWideChar( CP_THREAD_ACP,
  1126. 0,
  1127. mbMBStr,
  1128. -1,
  1129. NULL,
  1130. 0 );
  1131. CheckReturnValidW( rc,
  1132. -1,
  1133. NULL,
  1134. wcMBStr,
  1135. "CodePage CP_THREAD_ACP, no wcMBDest",
  1136. &NumErrors );
  1137. // Variation 15 - CodePage = CP_THREAD_ACP
  1138. Locale = GetThreadLocale();
  1139. SetThreadLocale(0x00000405); // Czech - cp 1250
  1140. rc = MultiByteToWideChar( CP_THREAD_ACP,
  1141. 0,
  1142. "\x9d\x9f",
  1143. -1,
  1144. wcMBDest,
  1145. BUFSIZE );
  1146. CheckReturnValidW( rc,
  1147. -1,
  1148. wcMBDest,
  1149. L"\x0165\x017a",
  1150. "CodePage CP_THREAD_ACP - Czech cp 1250",
  1151. &NumErrors );
  1152. SetThreadLocale(Locale); // US - cp 1252
  1153. rc = MultiByteToWideChar( CP_THREAD_ACP,
  1154. 0,
  1155. "\x9d\x9f",
  1156. -1,
  1157. wcMBDest,
  1158. BUFSIZE );
  1159. CheckReturnValidW( rc,
  1160. -1,
  1161. wcMBDest,
  1162. L"\x009d\x0178",
  1163. "CodePage CP_THREAD_ACP - US cp 1252",
  1164. &NumErrors );
  1165. // Variation 16 - CodePage = CP_SYMBOL
  1166. rc = MultiByteToWideChar( CP_SYMBOL,
  1167. 0,
  1168. "\x20\x33\xca\x00",
  1169. -1,
  1170. wcMBDest,
  1171. BUFSIZE );
  1172. CheckReturnValidW( rc,
  1173. -1,
  1174. wcMBDest,
  1175. L"\xf020\xf033\xf0ca\x0000",
  1176. "CodePage CP_SYMBOL",
  1177. &NumErrors );
  1178. // Variation 17 - CodePage = CP_SYMBOL, no wcMBDest
  1179. rc = MultiByteToWideChar( CP_SYMBOL,
  1180. 0,
  1181. "\x20\x33\xca\x00",
  1182. -1,
  1183. NULL,
  1184. 0 );
  1185. CheckReturnValidW( rc,
  1186. -1,
  1187. NULL,
  1188. L"\xf020\xf033\xf0ca\x0000",
  1189. "CodePage CP_SYMBOL, no wcMBDest",
  1190. &NumErrors );
  1191. // Variation 18 - CodePage = CP_SYMBOL
  1192. rc = MultiByteToWideChar( CP_SYMBOL,
  1193. 0,
  1194. "\x20\x33\xca\x00",
  1195. 5,
  1196. wcMBDest,
  1197. BUFSIZE );
  1198. CheckReturnValidW( rc,
  1199. 5,
  1200. wcMBDest,
  1201. L"\xf020\xf033\xf0ca\x0000",
  1202. "CodePage CP_SYMBOL, size",
  1203. &NumErrors );
  1204. //
  1205. // UTF 7.
  1206. //
  1207. // Variation 1 - CodePage = CP_UTF7
  1208. rc = MultiByteToWideChar( CP_UTF7,
  1209. 0,
  1210. "\x2b\x55\x78\x64\x4f\x72\x41\x2d", // +UxdOrA-
  1211. -1,
  1212. wcMBDest,
  1213. BUFSIZE );
  1214. CheckReturnValidW( rc,
  1215. -1,
  1216. wcMBDest,
  1217. L"\x5317\x4eac",
  1218. "CodePage CP_UTF7 - 1",
  1219. &NumErrors );
  1220. // Variation 2 - CodePage = CP_UTF7
  1221. rc = MultiByteToWideChar( CP_UTF7, // +Ti1XC2b4Xpc-
  1222. 0,
  1223. "\x2b\x54\x69\x31\x58\x43\x32\x62\x34\x58\x70\x63\x2d",
  1224. -1,
  1225. wcMBDest,
  1226. BUFSIZE );
  1227. CheckReturnValidW( rc,
  1228. -1,
  1229. wcMBDest,
  1230. L"\x4e2d\x570b\x66f8\x5e97",
  1231. "CodePage CP_UTF7 - 2",
  1232. &NumErrors );
  1233. // Variation 3 - CodePage = CP_UTF7
  1234. rc = MultiByteToWideChar( CP_UTF7,
  1235. 0,
  1236. "\x2b\x41\x44\x73\x2d", // +ADs-
  1237. -1,
  1238. wcMBDest,
  1239. BUFSIZE );
  1240. CheckReturnValidW( rc,
  1241. -1,
  1242. wcMBDest,
  1243. L"\x003b",
  1244. "CodePage CP_UTF7 - 3",
  1245. &NumErrors );
  1246. // Variation 4 - CodePage = CP_UTF7
  1247. rc = MultiByteToWideChar( CP_UTF7, // +XrdxmVtXUXg-
  1248. 0,
  1249. "\x2b\x58\x72\x64\x78\x6d\x56\x74\x58\x55\x58\x67\x2d",
  1250. -1,
  1251. wcMBDest,
  1252. BUFSIZE );
  1253. CheckReturnValidW( rc,
  1254. -1,
  1255. wcMBDest,
  1256. L"\x5eb7\x7199\x5b57\x5178",
  1257. "CodePage CP_UTF7 - 4",
  1258. &NumErrors );
  1259. // Variation 5 - CodePage = CP_UTF7
  1260. rc = MultiByteToWideChar( CP_UTF7, // +TpVPXGBG-
  1261. 0,
  1262. "\x2b\x54\x70\x56\x50\x58\x47\x42\x47\x2d",
  1263. -1,
  1264. wcMBDest,
  1265. BUFSIZE );
  1266. CheckReturnValidW( rc,
  1267. -1,
  1268. wcMBDest,
  1269. L"\x4e95\x4f5c\x6046",
  1270. "CodePage CP_UTF7 - 5",
  1271. &NumErrors );
  1272. // Variation 6 - CodePage = CP_UTF7
  1273. rc = MultiByteToWideChar( CP_UTF7,
  1274. 0,
  1275. "\x2b\x41\x46\x38\x2d", // +AF8-
  1276. -1,
  1277. wcMBDest,
  1278. BUFSIZE );
  1279. CheckReturnValidW( rc,
  1280. -1,
  1281. wcMBDest,
  1282. L"\x005f",
  1283. "CodePage CP_UTF7 - 6",
  1284. &NumErrors );
  1285. // Variation 7 - CodePage = CP_UTF7
  1286. rc = MultiByteToWideChar( CP_UTF7,
  1287. 0,
  1288. "\x2b\x41\x45\x41\x2d", // +AEA-
  1289. -1,
  1290. wcMBDest,
  1291. BUFSIZE );
  1292. CheckReturnValidW( rc,
  1293. -1,
  1294. wcMBDest,
  1295. L"\x0040",
  1296. "CodePage CP_UTF7 - 7",
  1297. &NumErrors );
  1298. // Variation 8 - CodePage = CP_UTF7
  1299. rc = MultiByteToWideChar( CP_UTF7,
  1300. 0,
  1301. "\x2b\x2d", // +-
  1302. -1,
  1303. wcMBDest,
  1304. BUFSIZE );
  1305. CheckReturnValidW( rc,
  1306. -1,
  1307. wcMBDest,
  1308. L"\x002b",
  1309. "CodePage CP_UTF7 - 8",
  1310. &NumErrors );
  1311. // Variation 9 - CodePage = CP_UTF7
  1312. rc = MultiByteToWideChar( CP_UTF7,
  1313. 0,
  1314. "\x41\x2b\x2d", // A+-
  1315. -1,
  1316. wcMBDest,
  1317. BUFSIZE );
  1318. CheckReturnValidW( rc,
  1319. -1,
  1320. wcMBDest,
  1321. L"\x0041\x002b",
  1322. "CodePage CP_UTF7 - 9",
  1323. &NumErrors );
  1324. // Variation 10 - CodePage = CP_UTF7
  1325. rc = MultiByteToWideChar( CP_UTF7,
  1326. 0,
  1327. "\x2b\x41\x45\x41\x2d\x2b\x2d", // +AEA-+-
  1328. -1,
  1329. wcMBDest,
  1330. BUFSIZE );
  1331. CheckReturnValidW( rc,
  1332. -1,
  1333. wcMBDest,
  1334. L"\x0040\x002b",
  1335. "CodePage CP_UTF7 - 10",
  1336. &NumErrors );
  1337. // Variation 11 - CodePage = CP_UTF7
  1338. rc = MultiByteToWideChar( CP_UTF7,
  1339. 0,
  1340. "\x61\x62\x2b",
  1341. 3,
  1342. wcMBDest,
  1343. BUFSIZE );
  1344. CheckReturnValidW( rc,
  1345. 2,
  1346. wcMBDest,
  1347. L"\x0061\x0062",
  1348. "CodePage CP_UTF7 - 11",
  1349. &NumErrors );
  1350. //
  1351. // UTF 8.
  1352. //
  1353. // Variation 1 - CodePage = CP_UTF8
  1354. rc = MultiByteToWideChar( CP_UTF8,
  1355. 0,
  1356. "\xe5\x8c\x97\xe4\xba\xac",
  1357. -1,
  1358. wcMBDest,
  1359. BUFSIZE );
  1360. CheckReturnValidW( rc,
  1361. -1,
  1362. wcMBDest,
  1363. L"\x5317\x4eac",
  1364. "CodePage CP_UTF8 - 1",
  1365. &NumErrors );
  1366. // Variation 2 - CodePage = CP_UTF8
  1367. rc = MultiByteToWideChar( CP_UTF8,
  1368. 0,
  1369. "\xe4\xb8\xad\xe5\x9c\x8b\xe6\x9b\xb8\xe5\xba\x97",
  1370. -1,
  1371. wcMBDest,
  1372. BUFSIZE );
  1373. CheckReturnValidW( rc,
  1374. -1,
  1375. wcMBDest,
  1376. L"\x4e2d\x570b\x66f8\x5e97",
  1377. "CodePage CP_UTF8 - 2",
  1378. &NumErrors );
  1379. // Variation 3 - CodePage = CP_UTF8
  1380. rc = MultiByteToWideChar( CP_UTF8,
  1381. 0,
  1382. "\x3b",
  1383. -1,
  1384. wcMBDest,
  1385. BUFSIZE );
  1386. CheckReturnValidW( rc,
  1387. -1,
  1388. wcMBDest,
  1389. L"\x003b",
  1390. "CodePage CP_UTF8 - 3",
  1391. &NumErrors );
  1392. // Variation 4 - CodePage = CP_UTF8
  1393. rc = MultiByteToWideChar( CP_UTF8,
  1394. 0,
  1395. "\xe5\xba\xb7\xe7\x86\x99\xe5\xad\x97\xe5\x85\xb8",
  1396. -1,
  1397. wcMBDest,
  1398. BUFSIZE );
  1399. CheckReturnValidW( rc,
  1400. -1,
  1401. wcMBDest,
  1402. L"\x5eb7\x7199\x5b57\x5178",
  1403. "CodePage CP_UTF8 - 4",
  1404. &NumErrors );
  1405. // Variation 5 - CodePage = CP_UTF8
  1406. rc = MultiByteToWideChar( CP_UTF8,
  1407. 0,
  1408. "\xe4\xba\x95\xe4\xbd\x9c\xe6\x81\x86",
  1409. -1,
  1410. wcMBDest,
  1411. BUFSIZE );
  1412. CheckReturnValidW( rc,
  1413. -1,
  1414. wcMBDest,
  1415. L"\x4e95\x4f5c\x6046",
  1416. "CodePage CP_UTF8 - 5",
  1417. &NumErrors );
  1418. // Variation 6 - CodePage = CP_UTF8
  1419. rc = MultiByteToWideChar( CP_UTF8,
  1420. 0,
  1421. "\x5f",
  1422. -1,
  1423. wcMBDest,
  1424. BUFSIZE );
  1425. CheckReturnValidW( rc,
  1426. -1,
  1427. wcMBDest,
  1428. L"\x005f",
  1429. "CodePage CP_UTF8 - 6",
  1430. &NumErrors );
  1431. // Variation 7 - CodePage = CP_UTF8
  1432. rc = MultiByteToWideChar( CP_UTF8,
  1433. 0,
  1434. "\x40",
  1435. -1,
  1436. wcMBDest,
  1437. BUFSIZE );
  1438. CheckReturnValidW( rc,
  1439. -1,
  1440. wcMBDest,
  1441. L"\x0040",
  1442. "CodePage CP_UTF8 - 7",
  1443. &NumErrors );
  1444. // Variation 8 - CodePage = CP_UTF8
  1445. rc = MultiByteToWideChar( CP_UTF8,
  1446. 0,
  1447. "\x2b",
  1448. -1,
  1449. wcMBDest,
  1450. BUFSIZE );
  1451. CheckReturnValidW( rc,
  1452. -1,
  1453. wcMBDest,
  1454. L"\x002b",
  1455. "CodePage CP_UTF8 - 8",
  1456. &NumErrors );
  1457. //
  1458. // Check 0xb3 by itself (to make sure not sign extended).
  1459. //
  1460. Ch = (BYTE)0xb3;
  1461. rc = MultiByteToWideChar( 1252,
  1462. MB_PRECOMPOSED,
  1463. &Ch,
  1464. 1,
  1465. &CheckBuf,
  1466. 1 );
  1467. CheckReturnValidW( rc,
  1468. 1,
  1469. &CheckBuf,
  1470. L"\x00b3",
  1471. "Check Buffer",
  1472. &NumErrors );
  1473. //
  1474. // Return total number of errors found.
  1475. //
  1476. return (NumErrors);
  1477. }
  1478. ////////////////////////////////////////////////////////////////////////////
  1479. //
  1480. // MB_TestFlags
  1481. //
  1482. // This routine tests the different flags of the API routine.
  1483. //
  1484. // 06-14-91 JulieB Created.
  1485. ////////////////////////////////////////////////////////////////////////////
  1486. int MB_TestFlags()
  1487. {
  1488. int NumErrors = 0; // error count - to be returned
  1489. int rc; // return code
  1490. BYTE Ch; // buffer for one character
  1491. WCHAR CheckBuf; // return buffer for one character
  1492. //
  1493. // MB_PRECOMPOSED flag.
  1494. //
  1495. // Variation 1 - normal
  1496. rc = MultiByteToWideChar( 1252,
  1497. MB_PRECOMPOSED,
  1498. mbMBStr,
  1499. -1,
  1500. wcMBDest,
  1501. BUFSIZE );
  1502. CheckReturnValidW( rc,
  1503. -1,
  1504. wcMBDest,
  1505. wcMBStr,
  1506. "MB_PRECOMPOSED",
  1507. &NumErrors );
  1508. // Variation 2 - normal, no wcMBDest
  1509. rc = MultiByteToWideChar( 1252,
  1510. MB_PRECOMPOSED,
  1511. mbMBStr,
  1512. -1,
  1513. NULL,
  1514. 0 );
  1515. CheckReturnValidW( rc,
  1516. -1,
  1517. NULL,
  1518. wcMBStr,
  1519. "MB_PRECOMPOSED, no wcMBDest",
  1520. &NumErrors );
  1521. // Variation 3 - normal
  1522. rc = MultiByteToWideChar( 1252,
  1523. MB_PRECOMPOSED,
  1524. "\x6e\x7e",
  1525. -1,
  1526. wcMBDest,
  1527. BUFSIZE );
  1528. CheckReturnValidW( rc,
  1529. -1,
  1530. wcMBDest,
  1531. L"\x006e\x007e",
  1532. "MB_PRECOMPOSED (n tilde)",
  1533. &NumErrors );
  1534. // Variation 4 - normal, no wcMBDest
  1535. rc = MultiByteToWideChar( 1252,
  1536. MB_PRECOMPOSED,
  1537. "\x6e\x7e",
  1538. -1,
  1539. NULL,
  1540. 0 );
  1541. CheckReturnValidW( rc,
  1542. -1,
  1543. NULL,
  1544. L"\x006e\x007e",
  1545. "MB_PRECOMPOSED (n tilde), no wcMBDest",
  1546. &NumErrors );
  1547. //
  1548. // MB_COMPOSITE flag.
  1549. //
  1550. // Variation 1 - normal
  1551. rc = MultiByteToWideChar( 1252,
  1552. MB_COMPOSITE,
  1553. mbMBStr,
  1554. -1,
  1555. wcMBDest,
  1556. BUFSIZE );
  1557. CheckReturnValidW( rc,
  1558. -1,
  1559. wcMBDest,
  1560. wcMBStr,
  1561. "MB_COMPOSITE",
  1562. &NumErrors );
  1563. // Variation 2 - normal, no wcMBDest
  1564. rc = MultiByteToWideChar( 1252,
  1565. MB_COMPOSITE,
  1566. mbMBStr,
  1567. -1,
  1568. NULL,
  1569. 0 );
  1570. CheckReturnValidW( rc,
  1571. -1,
  1572. NULL,
  1573. wcMBStr,
  1574. "MB_COMPOSITE, no wcMBDest",
  1575. &NumErrors );
  1576. // Variation 3 - normal
  1577. rc = MultiByteToWideChar( 1252,
  1578. MB_COMPOSITE,
  1579. "\xfc\xf5",
  1580. -1,
  1581. wcMBDest,
  1582. BUFSIZE );
  1583. CheckReturnValidW( rc,
  1584. -1,
  1585. wcMBDest,
  1586. L"\x0075\x0308\x006f\x0303",
  1587. "MB_COMPOSITE (u diaeresis, o tilde)",
  1588. &NumErrors );
  1589. // Variation 4 - normal, no wcMBDest
  1590. rc = MultiByteToWideChar( 1252,
  1591. MB_COMPOSITE,
  1592. "\xfc\xf5",
  1593. -1,
  1594. NULL,
  1595. 0 );
  1596. CheckReturnValidW( rc,
  1597. -1,
  1598. NULL,
  1599. L"\x0075\x0308\x006f\x0303",
  1600. "MB_COMPOSITE (u diaeresis, o tilde), no wcMBDest",
  1601. &NumErrors );
  1602. //
  1603. // MB_USEGLYPHCHARS flag.
  1604. //
  1605. // Variation 1 - Use Glyph
  1606. Ch = (BYTE)0x0D;
  1607. CheckBuf = (WCHAR)0;
  1608. rc = MultiByteToWideChar( 437,
  1609. MB_USEGLYPHCHARS,
  1610. &Ch,
  1611. 1,
  1612. &CheckBuf,
  1613. 1 );
  1614. CheckReturnValidW( rc,
  1615. 1,
  1616. &CheckBuf,
  1617. L"\x266a",
  1618. "Use Glyph",
  1619. &NumErrors );
  1620. // Variation 2 - Do NOT Use Glyph
  1621. Ch = (BYTE)0x0D;
  1622. CheckBuf = (WCHAR)0;
  1623. rc = MultiByteToWideChar( 437,
  1624. 0,
  1625. &Ch,
  1626. 1,
  1627. &CheckBuf,
  1628. 1 );
  1629. CheckReturnValidW( rc,
  1630. 1,
  1631. &CheckBuf,
  1632. L"\x000d",
  1633. "Do NOT Use Glyph",
  1634. &NumErrors );
  1635. // Variation 3 - Use Glyph, Composite
  1636. Ch = (BYTE)0x0D;
  1637. CheckBuf = (WCHAR)0;
  1638. rc = MultiByteToWideChar( 437,
  1639. MB_USEGLYPHCHARS | MB_COMPOSITE,
  1640. &Ch,
  1641. 1,
  1642. &CheckBuf,
  1643. 1 );
  1644. CheckReturnValidW( rc,
  1645. 1,
  1646. &CheckBuf,
  1647. L"\x266a",
  1648. "Use Glyph, Composite",
  1649. &NumErrors );
  1650. // Variation 4 - Do NOT Use Glyph, Composite
  1651. Ch = (BYTE)0x0D;
  1652. CheckBuf = (WCHAR)0;
  1653. rc = MultiByteToWideChar( 437,
  1654. MB_COMPOSITE,
  1655. &Ch,
  1656. 1,
  1657. &CheckBuf,
  1658. 1 );
  1659. CheckReturnValidW( rc,
  1660. 1,
  1661. &CheckBuf,
  1662. L"\x000d",
  1663. "Do NOT Use Glyph, Composite",
  1664. &NumErrors );
  1665. //
  1666. // Return total number of errors found.
  1667. //
  1668. return (NumErrors);
  1669. }
  1670. ////////////////////////////////////////////////////////////////////////////
  1671. //
  1672. // MB_TestDBCS
  1673. //
  1674. // This routine tests the DBCS code of the API routine.
  1675. //
  1676. // 06-14-91 JulieB Created.
  1677. ////////////////////////////////////////////////////////////////////////////
  1678. int MB_TestDBCS()
  1679. {
  1680. int NumErrors = 0; // error count - to be returned
  1681. int rc; // return code
  1682. //
  1683. // No trail byte with lead byte.
  1684. //
  1685. // Variation 1 - 1 char
  1686. wcMBDest[0] = 0;
  1687. rc = MultiByteToWideChar( 932,
  1688. 0,
  1689. "\x81",
  1690. -1,
  1691. wcMBDest,
  1692. BUFSIZE );
  1693. CheckReturnValidW( rc,
  1694. 1,
  1695. wcMBDest,
  1696. L"\x0000",
  1697. "no trail byte 1 char",
  1698. &NumErrors );
  1699. // Variation 2 - 1 char
  1700. wcMBDest[0] = 0;
  1701. rc = MultiByteToWideChar( 932,
  1702. 0,
  1703. "\x81",
  1704. 1,
  1705. wcMBDest,
  1706. BUFSIZE );
  1707. CheckReturnValidW( rc,
  1708. 1,
  1709. wcMBDest,
  1710. L"\x0000",
  1711. "no trail byte 1 char 2",
  1712. &NumErrors );
  1713. // Variation 3 - 2 chars
  1714. wcMBDest[0] = 0;
  1715. rc = MultiByteToWideChar( 932,
  1716. 0,
  1717. "\xdf\x81",
  1718. -1,
  1719. wcMBDest,
  1720. BUFSIZE );
  1721. CheckReturnValidW( rc,
  1722. -1,
  1723. wcMBDest,
  1724. L"\xff9f",
  1725. "no trail byte 2 chars",
  1726. &NumErrors );
  1727. // Variation 4 - 2 chars
  1728. wcMBDest[0] = 0;
  1729. rc = MultiByteToWideChar( 932,
  1730. 0,
  1731. "\xdf\x81",
  1732. 2,
  1733. wcMBDest,
  1734. BUFSIZE );
  1735. CheckReturnValidW( rc,
  1736. -1,
  1737. wcMBDest,
  1738. L"\xff9f",
  1739. "no trail byte 2 chars 2",
  1740. &NumErrors );
  1741. //
  1742. // Invalid trail byte with lead byte.
  1743. //
  1744. // Variation 1 - 2 chars
  1745. wcMBDest[0] = 0;
  1746. rc = MultiByteToWideChar( 932,
  1747. 0,
  1748. "\x81\x30",
  1749. -1,
  1750. wcMBDest,
  1751. BUFSIZE );
  1752. CheckReturnValidW( rc,
  1753. -1,
  1754. wcMBDest,
  1755. L"\x30fb",
  1756. "invalid trail byte 2 chars",
  1757. &NumErrors );
  1758. // Variation 2 - 3 chars
  1759. wcMBDest[0] = 0;
  1760. rc = MultiByteToWideChar( 932,
  1761. 0,
  1762. "\x81\x30\xdf",
  1763. -1,
  1764. wcMBDest,
  1765. BUFSIZE );
  1766. CheckReturnValidW( rc,
  1767. -1,
  1768. wcMBDest,
  1769. L"\x30fb\xff9f",
  1770. "invalid trail byte 3 chars",
  1771. &NumErrors );
  1772. //
  1773. // Valid Double byte string.
  1774. //
  1775. // Variation 1 - 2 chars
  1776. wcMBDest[0] = 0;
  1777. rc = MultiByteToWideChar( 932,
  1778. 0,
  1779. "\x81\x40",
  1780. -1,
  1781. wcMBDest,
  1782. BUFSIZE );
  1783. CheckReturnValidW( rc,
  1784. -1,
  1785. wcMBDest,
  1786. L"\x3000",
  1787. "valid trail byte 2 chars",
  1788. &NumErrors );
  1789. // Variation 2 - 3 chars
  1790. wcMBDest[0] = 0;
  1791. rc = MultiByteToWideChar( 932,
  1792. 0,
  1793. "\x81\x40\xdf",
  1794. -1,
  1795. wcMBDest,
  1796. BUFSIZE );
  1797. CheckReturnValidW( rc,
  1798. -1,
  1799. wcMBDest,
  1800. L"\x3000\xff9f",
  1801. "valid trail byte 3 chars",
  1802. &NumErrors );
  1803. //
  1804. // Return total number of errors found.
  1805. //
  1806. return (NumErrors);
  1807. }
  1808. int DoUTF7FunctionTests()
  1809. {
  1810. int NumErrors = 0; // error count - to be returned
  1811. printf("\n ---- DoUTF7FunctionTests ----\n");
  1812. NumErrors += DoTestMultiByteToWideChar(
  1813. "DoUTF7FunctionTests - 1",
  1814. CP_UTF7, 0, "\x2B\x41\x43\x45\x41\x66\x51\x2D", 0, 8, TRUE, wcMBDest, BUFSIZE, 2, L"\x0021\x007D", 0);
  1815. NumErrors += DoTestMultiByteToWideChar(
  1816. "DoUTF7FunctionTests - 2",
  1817. CP_UTF7, 0, "\x2B\x44\x6C\x6B\x46\x30\x51\x2D", 0, 8, TRUE, wcMBDest, BUFSIZE, 2, L"\x0E59\x05D1", 0);
  1818. //
  1819. // Return total number of errors found.
  1820. //
  1821. return (NumErrors);
  1822. }