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.

868 lines
19 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. nlstest.c
  5. Abstract:
  6. Test module for NLS API.
  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. // Global Variables.
  19. //
  20. BOOL Verbose = 0; // verbose flag
  21. LCID pAllLocales[] = // all supported locale ids
  22. {
  23. 0x0402,
  24. 0x0404,
  25. 0x0804,
  26. 0x0c04,
  27. 0x1004,
  28. 0x0405,
  29. 0x0406,
  30. 0x0407,
  31. 0x0807,
  32. 0x0c07,
  33. 0x0408,
  34. 0x0409,
  35. 0x0809,
  36. 0x0c09,
  37. 0x1009,
  38. 0x1409,
  39. 0x1809,
  40. 0x040a,
  41. 0x080a,
  42. 0x0c0a,
  43. 0x040b,
  44. 0x040c,
  45. 0x080c,
  46. 0x0c0c,
  47. 0x100c,
  48. 0x040e,
  49. 0x040f,
  50. 0x0410,
  51. 0x0810,
  52. 0x0411,
  53. 0x0412,
  54. 0x0413,
  55. 0x0813,
  56. 0x0414,
  57. 0x0814,
  58. 0x0415,
  59. 0x0416,
  60. 0x0816,
  61. 0x0418,
  62. 0x0419,
  63. 0x041a,
  64. 0x041b,
  65. 0x041d,
  66. 0x041f,
  67. 0x0424
  68. };
  69. int NumLocales = ( sizeof(pAllLocales) / sizeof(LCID) );
  70. // Buffer used in GetUnicodeString()/GetAnsiString()
  71. CHAR TempStringBuffer[1024];
  72. ////////////////////////////////////////////////////////////////////////////
  73. //
  74. // main
  75. //
  76. // Main Routine.
  77. //
  78. // 06-14-91 JulieB Created.
  79. ////////////////////////////////////////////////////////////////////////////
  80. int _cdecl main(
  81. int argc,
  82. char *argv[])
  83. {
  84. int NumErrs = 0; // number of errors
  85. //
  86. // Check for verbose switch.
  87. //
  88. if ( (argc > 1) && (_stricmp(argv[1], "-v") == 0) )
  89. {
  90. Verbose = 1;
  91. }
  92. //
  93. // Print out what's being done.
  94. //
  95. printf("\nTesting NLS Component.\n");
  96. //
  97. // Test MultiByteToWideChar.
  98. //
  99. NumErrs += TestMBToWC();
  100. //
  101. // Test WideCharToMultiByte.
  102. //
  103. NumErrs += TestWCToMB();
  104. //
  105. // Test GetCPInfo.
  106. //
  107. NumErrs += TestGetCPInfo();
  108. //
  109. // Test CompareString.
  110. //
  111. NumErrs += TestCompareString();
  112. //
  113. // Test GetStringType.
  114. //
  115. NumErrs += TestGetStringType();
  116. //
  117. // Test FoldString.
  118. //
  119. NumErrs += TestFoldString();
  120. //
  121. // Test LCMapString.
  122. //
  123. NumErrs += TestLCMapString();
  124. //
  125. // Test GetLocaleInfo.
  126. //
  127. NumErrs += TestGetLocaleInfo();
  128. //
  129. // Test SetLocaleInfo.
  130. //
  131. NumErrs += TestSetLocaleInfo();
  132. //
  133. // Test GetCalendarInfo.
  134. //
  135. NumErrs += TestGetCalendarInfo();
  136. //
  137. // Test SetCalendarInfo.
  138. //
  139. NumErrs += TestSetCalendarInfo();
  140. //
  141. // Test GetGeoInfo.
  142. //
  143. NumErrs += TestGetGeoInfo();
  144. //
  145. // Test GetTimeFormat.
  146. //
  147. NumErrs += TestGetTimeFormat();
  148. //
  149. // Test GetDateFormat.
  150. //
  151. NumErrs += TestGetDateFormat();
  152. //
  153. // Test GetNumberFormat.
  154. //
  155. NumErrs += TestGetNumberFormat();
  156. //
  157. // Test GetCurrencyFormat.
  158. //
  159. NumErrs += TestGetCurrencyFormat();
  160. //
  161. // Test IsDBCSLeadByte.
  162. //
  163. NumErrs += TestIsDBCSLeadByte();
  164. //
  165. // Test IsValidCodePage.
  166. //
  167. NumErrs += TestIsValidCodePage();
  168. //
  169. // Test IsValidLanguageGroup.
  170. //
  171. NumErrs += TestIsValidLanguageGroup();
  172. //
  173. // Test IsValidLocale.
  174. //
  175. NumErrs += TestIsValidLocale();
  176. //
  177. // Test GetACP, GetOEMCP,
  178. // GetSystemDefaultUILanguage, GetUserDefaultUILanguage,
  179. // GetSystemDefaultLangID, GetUserDefaultLangID,
  180. // GetSystemDefaultLCID, GetUserDefaultLCID,
  181. // GetThreadLocale, SetThreadLocale
  182. //
  183. NumErrs += TestUtilityAPIs();
  184. //
  185. // Test EnumUILanguages.
  186. //
  187. NumErrs += TestEnumUILanguages();
  188. //
  189. // Test EnumSystemLanguageGroups.
  190. //
  191. NumErrs += TestEnumSystemLanguageGroups();
  192. //
  193. // Test EnumLanguageGroupLocales.
  194. //
  195. NumErrs += TestEnumLanguageGroupLocales();
  196. //
  197. // Test EnumSystemLocales.
  198. //
  199. NumErrs += TestEnumSystemLocales();
  200. //
  201. // Test EnumSystemCodePages.
  202. //
  203. NumErrs += TestEnumSystemCodePages();
  204. //
  205. // Test EnumCalendarInfo.
  206. //
  207. NumErrs += TestEnumCalendarInfo();
  208. //
  209. // Test EnumTimeFormats.
  210. //
  211. NumErrs += TestEnumTimeFormats();
  212. //
  213. // Test EnumDateFormats.
  214. //
  215. NumErrs += TestEnumDateFormats();
  216. //
  217. // Test EnumSystemGeoID.
  218. //
  219. NumErrs += TestEnumSystemGeoID();
  220. //
  221. // Print out final result.
  222. //
  223. if (NumErrs == 0)
  224. printf("\n\n\nNO Errors Found.\n\n");
  225. else
  226. printf("\n\n\n%d ERRORS FOUND.\n\n", NumErrs);
  227. //
  228. // Return number of errors found.
  229. //
  230. return (NumErrs);
  231. argc;
  232. argv;
  233. }
  234. ////////////////////////////////////////////////////////////////////////////
  235. //
  236. // CompStringsW
  237. //
  238. // Compares a wide character string to another wide character string.
  239. //
  240. // 06-14-91 JulieB Created.
  241. ////////////////////////////////////////////////////////////////////////////
  242. int CompStringsW(
  243. WCHAR *WCStr1,
  244. WCHAR *WCStr2,
  245. int size)
  246. {
  247. int ctr; // loop counter
  248. for (ctr = 0; WCStr1[ctr] == WCStr2[ctr]; ctr++)
  249. {
  250. if (ctr == (size - 1))
  251. return (0);
  252. }
  253. return (1);
  254. }
  255. ////////////////////////////////////////////////////////////////////////////
  256. //
  257. // CompStringsA
  258. //
  259. // Compares a multibyte string to another multibyte character string.
  260. //
  261. // 06-14-91 JulieB Created.
  262. ////////////////////////////////////////////////////////////////////////////
  263. int CompStringsA(
  264. BYTE *MBStr1,
  265. BYTE *MBStr2,
  266. int size)
  267. {
  268. int ctr; // loop counter
  269. for (ctr = 0; MBStr1[ctr] == MBStr2[ctr]; ctr++)
  270. {
  271. if (ctr == (size - 1))
  272. return (0);
  273. }
  274. return (1);
  275. }
  276. ////////////////////////////////////////////////////////////////////////////
  277. //
  278. // PrintWC
  279. //
  280. // Prints out a wide character string to the screen.
  281. // Need the size parameter because the string may not be zero terminated.
  282. //
  283. // 06-14-91 JulieB Created.
  284. ////////////////////////////////////////////////////////////////////////////
  285. void PrintWC(
  286. WCHAR *WCStr,
  287. int size)
  288. {
  289. int ctr; // loop counter
  290. //
  291. // Print the wide character string.
  292. //
  293. printf(" WC String => [%s]\n", GetUnicodeString(WCStr, size));
  294. }
  295. ////////////////////////////////////////////////////////////////////////////
  296. //
  297. // PrintMB
  298. //
  299. // Prints out a multibyte character string to the screen.
  300. // Need the size parameter because the string may not be zero terminated.
  301. //
  302. // 06-14-91 JulieB Created.
  303. ////////////////////////////////////////////////////////////////////////////
  304. void PrintMB(
  305. BYTE *MBStr,
  306. int size)
  307. {
  308. int ctr; // loop counter
  309. //
  310. // Print the multibyte character string.
  311. //
  312. printf(" MB String => [");
  313. for (ctr = 0; ctr < size; ctr++)
  314. {
  315. printf(((MBStr[ctr] < 0x21) || (MBStr[ctr] > 0x7e)) ? "(0x%x)" : "%c",
  316. MBStr[ctr]);
  317. }
  318. printf("]\n");
  319. }
  320. LPSTR GetUnicodeString(LPWSTR wstr, int count)
  321. {
  322. int i;
  323. LPSTR lpResult = TempStringBuffer;
  324. if (count == -1)
  325. {
  326. count = wcslen(wstr) + 1;
  327. }
  328. for (i = 0; i < count; i++)
  329. {
  330. lpResult += sprintf(lpResult, "\\x%04x", (int)wstr[i]);
  331. }
  332. lpResult = L'\0';
  333. return (TempStringBuffer);
  334. }
  335. LPSTR GetAnsiString(LPSTR str, int count)
  336. {
  337. int i;
  338. LPSTR lpResult = TempStringBuffer;
  339. if (count == -1)
  340. {
  341. count = strlen(str);
  342. }
  343. for (i = 0; i < count; i++)
  344. {
  345. lpResult += sprintf(lpResult, "\\x%02x", (unsigned char)str[i]);
  346. }
  347. lpResult = L'\0';
  348. return (TempStringBuffer);
  349. }
  350. ////////////////////////////////////////////////////////////////////////////
  351. //
  352. // CheckLastError
  353. //
  354. // Checks the last error value.
  355. //
  356. // 06-14-91 JulieB Created.
  357. ////////////////////////////////////////////////////////////////////////////
  358. void CheckLastError(
  359. DWORD ExpectedLastError,
  360. LPSTR pErrString,
  361. int *pNumErrors)
  362. {
  363. DWORD CurrentLastError; // last error
  364. WCHAR Buffer[512];
  365. if ((CurrentLastError = GetLastError()) != ExpectedLastError)
  366. {
  367. printf(">>>>ERROR: %s - \n", pErrString);
  368. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, CurrentLastError, 0, Buffer, 512, NULL);
  369. wprintf(L" LastError = %x, String: %s\n", CurrentLastError, Buffer);
  370. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, ExpectedLastError, 0, Buffer, 512, NULL);
  371. wprintf(L" Expected = %x, String: %s\n", ExpectedLastError, Buffer);
  372. (*pNumErrors)++;
  373. }
  374. }
  375. ////////////////////////////////////////////////////////////////////////////
  376. //
  377. // CheckReturnBadParam
  378. //
  379. // Checks the return code from a call with a bad parameter. It prints out
  380. // the appropriate error if either the return code or the last error is
  381. // incorrect.
  382. //
  383. // 06-14-91 JulieB Created.
  384. ////////////////////////////////////////////////////////////////////////////
  385. void CheckReturnBadParam(
  386. int CurrentReturn,
  387. int ExpectedReturn,
  388. DWORD ExpectedLastError,
  389. LPSTR pErrString,
  390. int *pNumErrors)
  391. {
  392. DWORD CurrentLastError; // last error
  393. if ( (CurrentReturn != ExpectedReturn) ||
  394. ((CurrentLastError = GetLastError()) != ExpectedLastError) )
  395. {
  396. printf("ERROR: %s - \n", pErrString);
  397. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  398. printf(" LastError = %d, Expected = %d\n", CurrentLastError, ExpectedLastError);
  399. (*pNumErrors)++;
  400. }
  401. }
  402. ////////////////////////////////////////////////////////////////////////////
  403. //
  404. // CheckReturnBadParamEnum
  405. //
  406. // Checks the return code from an enumeration call with a bad parameter.
  407. // It prints out the appropriate error if either the return code, the last
  408. // error, or the enumeration counter is incorrect.
  409. //
  410. // 06-14-91 JulieB Created.
  411. ////////////////////////////////////////////////////////////////////////////
  412. void CheckReturnBadParamEnum(
  413. int CurrentReturn,
  414. int ExpectedReturn,
  415. DWORD ExpectedLastError,
  416. LPSTR pErrString,
  417. int *pNumErrors,
  418. int CurrentEnumCtr,
  419. int ExpectedEnumCtr)
  420. {
  421. DWORD CurrentLastError; // last error
  422. if ( (CurrentReturn != ExpectedReturn) ||
  423. ((CurrentLastError = GetLastError()) != ExpectedLastError) ||
  424. (CurrentEnumCtr != ExpectedEnumCtr) )
  425. {
  426. printf("ERROR: %s - \n", pErrString);
  427. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  428. printf(" LastError = %d, Expected = %d\n", CurrentLastError, ExpectedLastError);
  429. printf(" EnumCtr = %d, Expected = %d\n", CurrentEnumCtr, ExpectedEnumCtr);
  430. (*pNumErrors)++;
  431. }
  432. }
  433. ////////////////////////////////////////////////////////////////////////////
  434. //
  435. // CheckReturnEqual
  436. //
  437. // Checks the return code from the valid NLS api "A" call to be sure that
  438. // it does NOT equal a particular value. If it does equal that value,
  439. // then it prints out the appropriate error.
  440. //
  441. // 06-14-91 JulieB Created.
  442. ////////////////////////////////////////////////////////////////////////////
  443. void CheckReturnEqual(
  444. int CurrentReturn,
  445. int NonExpectedReturn,
  446. LPSTR pErrString,
  447. int *pNumErrors)
  448. {
  449. if (CurrentReturn == NonExpectedReturn)
  450. {
  451. printf("ERROR: %s - \n", pErrString);
  452. printf(" Unexpected Return = %d\n", CurrentReturn);
  453. printf(" Last Error = %d\n", GetLastError());
  454. (*pNumErrors)++;
  455. }
  456. }
  457. ////////////////////////////////////////////////////////////////////////////
  458. //
  459. // CheckReturnValidEnumLoop
  460. //
  461. // Checks the return code from the valid NLS api "Enum" call. It prints out
  462. // the appropriate error if the incorrect result is found.
  463. //
  464. // 06-14-91 JulieB Created.
  465. ////////////////////////////////////////////////////////////////////////////
  466. void CheckReturnValidEnumLoop(
  467. int CurrentReturn,
  468. int ExpectedReturn,
  469. int CurrentCtr,
  470. int ExpectedCtr,
  471. LPSTR pErrString,
  472. DWORD ItemValue,
  473. int *pNumErrors)
  474. {
  475. if ( (CurrentReturn != ExpectedReturn) ||
  476. (CurrentCtr != ExpectedCtr) )
  477. {
  478. printf("ERROR: %s %x - \n", pErrString, ItemValue);
  479. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  480. printf(" Counter = %d, Expected = %d\n", CurrentCtr, ExpectedCtr);
  481. (*pNumErrors)++;
  482. }
  483. if (Verbose)
  484. {
  485. printf("\n");
  486. }
  487. }
  488. ////////////////////////////////////////////////////////////////////////////
  489. //
  490. // CheckReturnValidEnum
  491. //
  492. // Checks the return code from the valid NLS api "Enum" call. It prints out
  493. // the appropriate error if the incorrect result is found.
  494. //
  495. // 06-14-91 JulieB Created.
  496. ////////////////////////////////////////////////////////////////////////////
  497. void CheckReturnValidEnum(
  498. int CurrentReturn,
  499. int ExpectedReturn,
  500. int CurrentCtr,
  501. int ExpectedCtr,
  502. LPSTR pErrString,
  503. int *pNumErrors)
  504. {
  505. if ( (CurrentReturn != ExpectedReturn) ||
  506. (CurrentCtr != ExpectedCtr) )
  507. {
  508. printf("ERROR: %s - \n", pErrString);
  509. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  510. printf(" Counter = %d, Expected = %d\n", CurrentCtr, ExpectedCtr);
  511. (*pNumErrors)++;
  512. }
  513. if (Verbose)
  514. {
  515. printf("\n");
  516. }
  517. }
  518. ////////////////////////////////////////////////////////////////////////////
  519. //
  520. // CheckReturnValidLoopW
  521. //
  522. // Checks the return code from the valid NLS api "W" call. It prints out
  523. // the appropriate error if the incorrect result is found.
  524. //
  525. // 06-14-91 JulieB Created.
  526. ////////////////////////////////////////////////////////////////////////////
  527. void CheckReturnValidLoopW(
  528. int CurrentReturn,
  529. int ExpectedReturn,
  530. LPWSTR pCurrentString,
  531. LPWSTR pExpectedString,
  532. LPSTR pErrString,
  533. DWORD ItemValue,
  534. int *pNumErrors)
  535. {
  536. if ((ExpectedReturn == -1) && (pExpectedString != NULL))
  537. {
  538. ExpectedReturn = WC_STRING_LEN_NULL(pExpectedString);
  539. }
  540. if ( (CurrentReturn != ExpectedReturn) ||
  541. ( (pCurrentString != NULL) &&
  542. (CompStringsW(pCurrentString, pExpectedString, CurrentReturn)) ) )
  543. {
  544. printf("ERROR: %s %x - \n", pErrString, ItemValue);
  545. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  546. if (pCurrentString != NULL)
  547. {
  548. PrintWC(pCurrentString, CurrentReturn);
  549. }
  550. (*pNumErrors)++;
  551. }
  552. }
  553. ////////////////////////////////////////////////////////////////////////////
  554. //
  555. // CheckReturnValidLoopA
  556. //
  557. // Checks the return code from the valid NLS api "A" call. It prints out
  558. // the appropriate error if the incorrect result is found.
  559. //
  560. // 06-14-91 JulieB Created.
  561. ////////////////////////////////////////////////////////////////////////////
  562. void CheckReturnValidLoopA(
  563. int CurrentReturn,
  564. int ExpectedReturn,
  565. LPSTR pCurrentString,
  566. LPSTR pExpectedString,
  567. LPSTR pErrString,
  568. DWORD ItemValue,
  569. int *pNumErrors)
  570. {
  571. if ((ExpectedReturn == -1) && (pExpectedString != NULL))
  572. {
  573. ExpectedReturn = MB_STRING_LEN_NULL(pExpectedString);
  574. }
  575. if ( (CurrentReturn != ExpectedReturn) ||
  576. ( (pCurrentString != NULL) &&
  577. (CompStringsA(pCurrentString, pExpectedString, CurrentReturn)) ) )
  578. {
  579. printf("ERROR: %s %x - \n", pErrString, ItemValue);
  580. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  581. if (pCurrentString != NULL)
  582. {
  583. PrintMB(pCurrentString, CurrentReturn);
  584. }
  585. (*pNumErrors)++;
  586. }
  587. }
  588. ////////////////////////////////////////////////////////////////////////////
  589. //
  590. // CheckReturnValidW
  591. //
  592. // Checks the return code from the valid NLS api "W" call. It prints out
  593. // the appropriate error if the incorrect result is found.
  594. //
  595. // 06-14-91 JulieB Created.
  596. ////////////////////////////////////////////////////////////////////////////
  597. void CheckReturnValidW(
  598. int CurrentReturn,
  599. int ExpectedReturn,
  600. LPWSTR pCurrentString,
  601. LPWSTR pExpectedString,
  602. LPSTR pErrString,
  603. int *pNumErrors)
  604. {
  605. if ((ExpectedReturn == -1) && (pExpectedString != NULL))
  606. {
  607. ExpectedReturn = WC_STRING_LEN_NULL(pExpectedString);
  608. }
  609. if ( (CurrentReturn != ExpectedReturn) ||
  610. ( (pCurrentString != NULL) &&
  611. (CompStringsW(pCurrentString, pExpectedString, CurrentReturn)) ) )
  612. {
  613. printf(">>>>ERROR: %s - \n", pErrString);
  614. printf(" Return = %d\n", CurrentReturn);
  615. printf(" Expected = %d\n", ExpectedReturn);
  616. if (pCurrentString != NULL)
  617. {
  618. PrintWC(pCurrentString, CurrentReturn);
  619. }
  620. (*pNumErrors)++;
  621. }
  622. }
  623. ////////////////////////////////////////////////////////////////////////////
  624. //
  625. // CheckReturnValidA
  626. //
  627. // Checks the return code from the valid NLS api "A" call. It prints out
  628. // the appropriate error if the incorrect result is found.
  629. //
  630. // 06-14-91 JulieB Created.
  631. ////////////////////////////////////////////////////////////////////////////
  632. void CheckReturnValidA(
  633. int CurrentReturn,
  634. int ExpectedReturn,
  635. LPSTR pCurrentString,
  636. LPSTR pExpectedString,
  637. LPBOOL pUsedDef,
  638. LPSTR pErrString,
  639. int *pNumErrors)
  640. {
  641. if ((ExpectedReturn == -1) && (pExpectedString != NULL))
  642. {
  643. ExpectedReturn = MB_STRING_LEN_NULL(pExpectedString);
  644. }
  645. if ( (CurrentReturn != ExpectedReturn) ||
  646. ( (pCurrentString != NULL) &&
  647. (CompStringsA(pCurrentString, pExpectedString, CurrentReturn)) ) ||
  648. ( (pUsedDef != NULL) &&
  649. (*pUsedDef != TRUE) ) )
  650. {
  651. printf("ERROR: %s - \n", pErrString);
  652. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  653. if (pUsedDef != NULL)
  654. {
  655. printf(" UsedDef = %d\n", *pUsedDef);
  656. }
  657. if (pCurrentString != NULL)
  658. {
  659. PrintMB(pCurrentString, CurrentReturn);
  660. }
  661. (*pNumErrors)++;
  662. }
  663. }
  664. ////////////////////////////////////////////////////////////////////////////
  665. //
  666. // CheckReturnValidInt
  667. //
  668. // Checks the return code from the valid NLS api "W" call. It prints out
  669. // the appropriate error if the incorrect result is found.
  670. //
  671. // 06-14-91 JulieB Created.
  672. ////////////////////////////////////////////////////////////////////////////
  673. void CheckReturnValidInt(
  674. int CurrentReturn,
  675. int ExpectedReturn,
  676. DWORD CurrentInt,
  677. DWORD ExpectedInt,
  678. LPSTR pErrString,
  679. int *pNumErrors)
  680. {
  681. if ( (CurrentReturn != ExpectedReturn) ||
  682. (CurrentInt != ExpectedInt) )
  683. {
  684. printf("ERROR: %s - \n", pErrString);
  685. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  686. printf(" Return Int = %d, Expected Int = %d\n", CurrentInt, ExpectedInt);
  687. (*pNumErrors)++;
  688. }
  689. }