Windows NT 4.0 source code leak
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.

718 lines
15 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1991-1996, 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. ////////////////////////////////////////////////////////////////////////////
  71. //
  72. // main
  73. //
  74. // Main Routine.
  75. //
  76. // 06-14-91 JulieB Created.
  77. ////////////////////////////////////////////////////////////////////////////
  78. int _cdecl main(
  79. int argc,
  80. char *argv[])
  81. {
  82. int NumErrs = 0; // number of errors
  83. //
  84. // Check for verbose switch.
  85. //
  86. if ( (argc > 1) && (_strcmpi(argv[1], "-v") == 0) )
  87. {
  88. Verbose = 1;
  89. }
  90. //
  91. // Print out what's being done.
  92. //
  93. printf("\nTesting NLS Component.\n");
  94. //
  95. // Test MultiByteToWideChar.
  96. //
  97. NumErrs += TestMBToWC();
  98. //
  99. // Test WideCharToMultiByte.
  100. //
  101. NumErrs += TestWCToMB();
  102. //
  103. // Test GetCPInfo.
  104. //
  105. NumErrs += TestGetCPInfo();
  106. //
  107. // Test CompareStringW.
  108. //
  109. NumErrs += TestCompareString();
  110. //
  111. // Test GetStringTypeW.
  112. //
  113. NumErrs += TestGetStringType();
  114. //
  115. // Test FoldStringW.
  116. //
  117. NumErrs += TestFoldString();
  118. //
  119. // Test LCMapStringW.
  120. //
  121. NumErrs += TestLCMapString();
  122. //
  123. // Test GetLocaleInfoW.
  124. //
  125. NumErrs += TestGetLocaleInfo();
  126. //
  127. // Test SetLocaleInfoW.
  128. //
  129. NumErrs += TestSetLocaleInfo();
  130. //
  131. // Test GetTimeFormatW.
  132. //
  133. NumErrs += TestGetTimeFormat();
  134. //
  135. // Test GetDateFormatW.
  136. //
  137. NumErrs += TestGetDateFormat();
  138. //
  139. // Test GetNumberFormatW.
  140. //
  141. NumErrs += TestGetNumberFormat();
  142. //
  143. // Test GetCurrencyFormatW.
  144. //
  145. NumErrs += TestGetCurrencyFormat();
  146. //
  147. // Test IsDBCSLeadByte.
  148. //
  149. NumErrs += TestIsDBCSLeadByte();
  150. //
  151. // Test IsValidCodePage.
  152. //
  153. NumErrs += TestIsValidCodePage();
  154. //
  155. // Test IsValidLocale.
  156. //
  157. NumErrs += TestIsValidLocale();
  158. //
  159. // Test GetACP, GetOEMCP,
  160. // GetSystemDefaultLangID, GetUserDefaultLangID,
  161. // GetSystemDefaultLCID, GetUserDefaultLCID,
  162. // GetThreadLocale, SetThreadLocale
  163. //
  164. NumErrs += TestUtilityAPIs();
  165. //
  166. // Test EnumSystemLocalesW.
  167. //
  168. NumErrs += TestEnumSystemLocales();
  169. //
  170. // Test EnumSystemCodePagesW.
  171. //
  172. NumErrs += TestEnumSystemCodePages();
  173. //
  174. // Test EnumCalendarInfoW.
  175. //
  176. NumErrs += TestEnumCalendarInfo();
  177. //
  178. // Test EnumTimeFormatsW.
  179. //
  180. NumErrs += TestEnumTimeFormats();
  181. //
  182. // Test EnumDateFormatsW.
  183. //
  184. NumErrs += TestEnumDateFormats();
  185. //
  186. // Print out final result.
  187. //
  188. if (NumErrs == 0)
  189. printf("\n\n\nNO Errors Found.\n\n");
  190. else
  191. printf("\n\n\n%d ERRORS FOUND.\n\n", NumErrs);
  192. //
  193. // Return number of errors found.
  194. //
  195. return (NumErrs);
  196. argc;
  197. argv;
  198. }
  199. ////////////////////////////////////////////////////////////////////////////
  200. //
  201. // CompStringsW
  202. //
  203. // Compares a wide character string to another wide character string.
  204. //
  205. // 06-14-91 JulieB Created.
  206. ////////////////////////////////////////////////////////////////////////////
  207. int CompStringsW(
  208. WCHAR *WCStr1,
  209. WCHAR *WCStr2,
  210. int size)
  211. {
  212. int ctr; // loop counter
  213. for (ctr = 0; WCStr1[ctr] == WCStr2[ctr]; ctr++)
  214. {
  215. if (ctr == (size - 1))
  216. return (0);
  217. }
  218. return (1);
  219. }
  220. ////////////////////////////////////////////////////////////////////////////
  221. //
  222. // CompStringsA
  223. //
  224. // Compares a multibyte string to another multibyte character string.
  225. //
  226. // 06-14-91 JulieB Created.
  227. ////////////////////////////////////////////////////////////////////////////
  228. int CompStringsA(
  229. BYTE *MBStr1,
  230. BYTE *MBStr2,
  231. int size)
  232. {
  233. int ctr; // loop counter
  234. for (ctr = 0; MBStr1[ctr] == MBStr2[ctr]; ctr++)
  235. {
  236. if (ctr == (size - 1))
  237. return (0);
  238. }
  239. return (1);
  240. }
  241. ////////////////////////////////////////////////////////////////////////////
  242. //
  243. // PrintWC
  244. //
  245. // Prints out a wide character string to the screen.
  246. // Need the size parameter because the string may not be zero terminated.
  247. //
  248. // 06-14-91 JulieB Created.
  249. ////////////////////////////////////////////////////////////////////////////
  250. void PrintWC(
  251. WCHAR *WCStr,
  252. int size)
  253. {
  254. int ctr; // loop counter
  255. //
  256. // Print the wide character string.
  257. //
  258. printf(" WC String => ");
  259. for (ctr = 0; ctr < size; ctr++)
  260. {
  261. printf(((WCStr[ctr] < 0x21) || (WCStr[ctr] > 0x7e)) ? "(0x%x)" : "%c",
  262. WCStr[ctr]);
  263. }
  264. printf("\n");
  265. }
  266. ////////////////////////////////////////////////////////////////////////////
  267. //
  268. // PrintMB
  269. //
  270. // Prints out a multibyte character string to the screen.
  271. // Need the size parameter because the string may not be zero terminated.
  272. //
  273. // 06-14-91 JulieB Created.
  274. ////////////////////////////////////////////////////////////////////////////
  275. void PrintMB(
  276. BYTE *MBStr,
  277. int size)
  278. {
  279. int ctr; // loop counter
  280. //
  281. // Print the multibyte character string.
  282. //
  283. printf(" MB String => ");
  284. for (ctr = 0; ctr < size; ctr++)
  285. {
  286. printf(((MBStr[ctr] < 0x21) || (MBStr[ctr] > 0x7e)) ? "(0x%x)" : "%c",
  287. MBStr[ctr]);
  288. }
  289. printf("\n");
  290. }
  291. ////////////////////////////////////////////////////////////////////////////
  292. //
  293. // CheckReturnBadParam
  294. //
  295. // Checks the return code from a call with a bad parameter. It prints out
  296. // the appropriate error if either the return code or the last error is
  297. // incorrect.
  298. //
  299. // 06-14-91 JulieB Created.
  300. ////////////////////////////////////////////////////////////////////////////
  301. void CheckReturnBadParam(
  302. int CurrentReturn,
  303. int ExpectedReturn,
  304. DWORD ExpectedLastError,
  305. LPSTR pErrString,
  306. int *pNumErrors)
  307. {
  308. DWORD CurrentLastError; // last error
  309. if ( (CurrentReturn != ExpectedReturn) ||
  310. ((CurrentLastError = GetLastError()) != ExpectedLastError) )
  311. {
  312. printf("ERROR: %s - \n", pErrString);
  313. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  314. printf(" LastError = %d, Expected = %d\n", CurrentLastError, ExpectedLastError);
  315. (*pNumErrors)++;
  316. }
  317. }
  318. ////////////////////////////////////////////////////////////////////////////
  319. //
  320. // CheckReturnBadParamEnum
  321. //
  322. // Checks the return code from an enumeration call with a bad parameter.
  323. // It prints out the appropriate error if either the return code, the last
  324. // error, or the enumeration counter is incorrect.
  325. //
  326. // 06-14-91 JulieB Created.
  327. ////////////////////////////////////////////////////////////////////////////
  328. void CheckReturnBadParamEnum(
  329. int CurrentReturn,
  330. int ExpectedReturn,
  331. DWORD ExpectedLastError,
  332. LPSTR pErrString,
  333. int *pNumErrors,
  334. int CurrentEnumCtr,
  335. int ExpectedEnumCtr)
  336. {
  337. DWORD CurrentLastError; // last error
  338. if ( (CurrentReturn != ExpectedReturn) ||
  339. ((CurrentLastError = GetLastError()) != ExpectedLastError) ||
  340. (CurrentEnumCtr != ExpectedEnumCtr) )
  341. {
  342. printf("ERROR: %s - \n", pErrString);
  343. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  344. printf(" LastError = %d, Expected = %d\n", CurrentLastError, ExpectedLastError);
  345. printf(" EnumCtr = %d, Expected = %d\n", CurrentEnumCtr, ExpectedEnumCtr);
  346. (*pNumErrors)++;
  347. }
  348. }
  349. ////////////////////////////////////////////////////////////////////////////
  350. //
  351. // CheckReturnEqual
  352. //
  353. // Checks the return code from the valid NLS api "A" call to be sure that
  354. // it does NOT equal a particular value. If it does equal that value,
  355. // then it prints out the appropriate error.
  356. //
  357. // 06-14-91 JulieB Created.
  358. ////////////////////////////////////////////////////////////////////////////
  359. void CheckReturnEqual(
  360. int CurrentReturn,
  361. int NonExpectedReturn,
  362. LPSTR pErrString,
  363. int *pNumErrors)
  364. {
  365. if (CurrentReturn == NonExpectedReturn)
  366. {
  367. printf("ERROR: %s - \n", pErrString);
  368. printf(" Unexpected Return = %d\n", CurrentReturn);
  369. printf(" Last Error = %d\n", GetLastError());
  370. (*pNumErrors)++;
  371. }
  372. }
  373. ////////////////////////////////////////////////////////////////////////////
  374. //
  375. // CheckReturnValidEnumLoop
  376. //
  377. // Checks the return code from the valid NLS api "Enum" call. It prints out
  378. // the appropriate error if the incorrect result is found.
  379. //
  380. // 06-14-91 JulieB Created.
  381. ////////////////////////////////////////////////////////////////////////////
  382. void CheckReturnValidEnumLoop(
  383. int CurrentReturn,
  384. int ExpectedReturn,
  385. int CurrentCtr,
  386. int ExpectedCtr,
  387. LPSTR pErrString,
  388. DWORD ItemValue,
  389. int *pNumErrors)
  390. {
  391. if ( (CurrentReturn != ExpectedReturn) ||
  392. (CurrentCtr != ExpectedCtr) )
  393. {
  394. printf("ERROR: %s %x - \n", pErrString, ItemValue);
  395. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  396. printf(" Counter = %d, Expected = %d\n", CurrentCtr, ExpectedCtr);
  397. (*pNumErrors)++;
  398. }
  399. if (Verbose)
  400. {
  401. printf("\n");
  402. }
  403. }
  404. ////////////////////////////////////////////////////////////////////////////
  405. //
  406. // CheckReturnValidEnum
  407. //
  408. // Checks the return code from the valid NLS api "Enum" call. It prints out
  409. // the appropriate error if the incorrect result is found.
  410. //
  411. // 06-14-91 JulieB Created.
  412. ////////////////////////////////////////////////////////////////////////////
  413. void CheckReturnValidEnum(
  414. int CurrentReturn,
  415. int ExpectedReturn,
  416. int CurrentCtr,
  417. int ExpectedCtr,
  418. LPSTR pErrString,
  419. int *pNumErrors)
  420. {
  421. if ( (CurrentReturn != ExpectedReturn) ||
  422. (CurrentCtr != ExpectedCtr) )
  423. {
  424. printf("ERROR: %s - \n", pErrString);
  425. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  426. printf(" Counter = %d, Expected = %d\n", CurrentCtr, ExpectedCtr);
  427. (*pNumErrors)++;
  428. }
  429. if (Verbose)
  430. {
  431. printf("\n");
  432. }
  433. }
  434. ////////////////////////////////////////////////////////////////////////////
  435. //
  436. // CheckReturnValidLoopW
  437. //
  438. // Checks the return code from the valid NLS api "W" call. It prints out
  439. // the appropriate error if the incorrect result is found.
  440. //
  441. // 06-14-91 JulieB Created.
  442. ////////////////////////////////////////////////////////////////////////////
  443. void CheckReturnValidLoopW(
  444. int CurrentReturn,
  445. int ExpectedReturn,
  446. LPWSTR pCurrentString,
  447. LPWSTR pExpectedString,
  448. LPSTR pErrString,
  449. DWORD ItemValue,
  450. int *pNumErrors)
  451. {
  452. if (ExpectedReturn == -1)
  453. {
  454. ExpectedReturn = WC_STRING_LEN_NULL(pExpectedString);
  455. }
  456. if ( (CurrentReturn != ExpectedReturn) ||
  457. ( (pCurrentString != NULL) &&
  458. (CompStringsW(pCurrentString, pExpectedString, CurrentReturn)) ) )
  459. {
  460. printf("ERROR: %s %x - \n", pErrString, ItemValue);
  461. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  462. if (pCurrentString != NULL)
  463. {
  464. PrintWC(pCurrentString, CurrentReturn);
  465. }
  466. (*pNumErrors)++;
  467. }
  468. }
  469. ////////////////////////////////////////////////////////////////////////////
  470. //
  471. // CheckReturnValidW
  472. //
  473. // Checks the return code from the valid NLS api "W" call. It prints out
  474. // the appropriate error if the incorrect result is found.
  475. //
  476. // 06-14-91 JulieB Created.
  477. ////////////////////////////////////////////////////////////////////////////
  478. void CheckReturnValidW(
  479. int CurrentReturn,
  480. int ExpectedReturn,
  481. LPWSTR pCurrentString,
  482. LPWSTR pExpectedString,
  483. LPSTR pErrString,
  484. int *pNumErrors)
  485. {
  486. if (ExpectedReturn == -1)
  487. {
  488. ExpectedReturn = WC_STRING_LEN_NULL(pExpectedString);
  489. }
  490. if ( (CurrentReturn != ExpectedReturn) ||
  491. ( (pCurrentString != NULL) &&
  492. (CompStringsW(pCurrentString, pExpectedString, CurrentReturn)) ) )
  493. {
  494. printf("ERROR: %s - \n", pErrString);
  495. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  496. if (pCurrentString != NULL)
  497. {
  498. PrintWC(pCurrentString, CurrentReturn);
  499. }
  500. (*pNumErrors)++;
  501. }
  502. }
  503. ////////////////////////////////////////////////////////////////////////////
  504. //
  505. // CheckReturnValidA
  506. //
  507. // Checks the return code from the valid NLS api "A" call. It prints out
  508. // the appropriate error if the incorrect result is found.
  509. //
  510. // 06-14-91 JulieB Created.
  511. ////////////////////////////////////////////////////////////////////////////
  512. void CheckReturnValidA(
  513. int CurrentReturn,
  514. int ExpectedReturn,
  515. LPSTR pCurrentString,
  516. LPSTR pExpectedString,
  517. LPBOOL pUsedDef,
  518. LPSTR pErrString,
  519. int *pNumErrors)
  520. {
  521. if (ExpectedReturn == -1)
  522. {
  523. ExpectedReturn = MB_STRING_LEN_NULL(pExpectedString);
  524. }
  525. if ( (CurrentReturn != ExpectedReturn) ||
  526. ( (pCurrentString != NULL) &&
  527. (CompStringsA(pCurrentString, pExpectedString, CurrentReturn)) ) ||
  528. ( (pUsedDef != NULL) &&
  529. (*pUsedDef != TRUE) ) )
  530. {
  531. printf("ERROR: %s - \n", pErrString);
  532. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  533. if (pUsedDef != NULL)
  534. {
  535. printf(" UsedDef = %d\n", *pUsedDef);
  536. }
  537. if (pCurrentString != NULL)
  538. {
  539. PrintMB(pCurrentString, CurrentReturn);
  540. }
  541. (*pNumErrors)++;
  542. }
  543. }
  544. ////////////////////////////////////////////////////////////////////////////
  545. //
  546. // CheckReturnValidInt
  547. //
  548. // Checks the return code from the valid NLS api "W" call. It prints out
  549. // the appropriate error if the incorrect result is found.
  550. //
  551. // 06-14-91 JulieB Created.
  552. ////////////////////////////////////////////////////////////////////////////
  553. void CheckReturnValidInt(
  554. int CurrentReturn,
  555. int ExpectedReturn,
  556. DWORD CurrentInt,
  557. DWORD ExpectedInt,
  558. LPSTR pErrString,
  559. int *pNumErrors)
  560. {
  561. if ( (CurrentReturn != ExpectedReturn) ||
  562. (CurrentInt != ExpectedInt) )
  563. {
  564. printf("ERROR: %s - \n", pErrString);
  565. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  566. printf(" Return Int = %d, Expected Int = %d\n", CurrentInt, ExpectedInt);
  567. (*pNumErrors)++;
  568. }
  569. }