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.

862 lines
22 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. gettest.c
  5. Abstract:
  6. Test module for NLS API IsValidCodePage, IsValidLocale, IsValidLanguageGroup,
  7. GetACP, GetOEMCP,
  8. GetSystemDefaultUILanguage, GetUserDefaultUILanguage,
  9. GetSystemDefaultLangID, GetUserDefaultLangID,
  10. GetSystemDefaultLCID, GetUserDefaultLCID,
  11. GetThreadLocale, SetThreadLocale.
  12. NOTE: This code was simply hacked together quickly in order to
  13. test the different code modules of the NLS component.
  14. This is NOT meant to be a formal regression test.
  15. Revision History:
  16. 06-14-91 JulieB Created.
  17. --*/
  18. //
  19. // Include Files.
  20. //
  21. #include "nlstest.h"
  22. //
  23. // Forward Declarations.
  24. //
  25. int
  26. IVCP_NormalCase();
  27. int
  28. IVLC_NormalCase();
  29. int
  30. IVLG_NormalCase();
  31. int
  32. GUAPI_NormalCase();
  33. ////////////////////////////////////////////////////////////////////////////
  34. //
  35. // TestIsValidCodePage
  36. //
  37. // Test routine for IsValidCodePage API.
  38. //
  39. // 06-14-91 JulieB Created.
  40. ////////////////////////////////////////////////////////////////////////////
  41. int TestIsValidCodePage()
  42. {
  43. int ErrCount = 0; // error count
  44. //
  45. // Print out what's being done.
  46. //
  47. printf("\n\nTESTING IsValidCodePage...\n\n");
  48. //
  49. // Test normal cases.
  50. //
  51. ErrCount += IVCP_NormalCase();
  52. //
  53. // Print out result.
  54. //
  55. printf("\nIsValidCodePage: ERRORS = %d\n", ErrCount);
  56. //
  57. // Return total number of errors found.
  58. //
  59. return (ErrCount);
  60. }
  61. ////////////////////////////////////////////////////////////////////////////
  62. //
  63. // IVCP_NormalCase
  64. //
  65. // This routine tests the normal cases of the API routine.
  66. //
  67. // 06-14-91 JulieB Created.
  68. ////////////////////////////////////////////////////////////////////////////
  69. int IVCP_NormalCase()
  70. {
  71. int NumErrors = 0; // error count - to be returned
  72. BOOL rc; // return code
  73. //
  74. // Different values for CodePage.
  75. //
  76. // Variation 1 - CP_ACP
  77. rc = IsValidCodePage( CP_ACP );
  78. CheckReturnValidW( rc,
  79. FALSE,
  80. NULL,
  81. NULL,
  82. "CP_ACP",
  83. &NumErrors );
  84. // Variation 2 - CP_OEMCP
  85. rc = IsValidCodePage( CP_OEMCP );
  86. CheckReturnValidW( rc,
  87. FALSE,
  88. NULL,
  89. NULL,
  90. "CP_OEMCP",
  91. &NumErrors );
  92. // Variation 3 - CP 6
  93. rc = IsValidCodePage( 6 );
  94. CheckReturnValidW( rc,
  95. FALSE,
  96. NULL,
  97. NULL,
  98. "CP 6",
  99. &NumErrors );
  100. // Variation 4 - CP 1252
  101. rc = IsValidCodePage( 1252 );
  102. CheckReturnValidW( rc,
  103. TRUE,
  104. NULL,
  105. NULL,
  106. "CP 1252",
  107. &NumErrors );
  108. // Variation 5 - CP 437
  109. rc = IsValidCodePage( 437 );
  110. CheckReturnValidW( rc,
  111. TRUE,
  112. NULL,
  113. NULL,
  114. "CP 437",
  115. &NumErrors );
  116. // Variation 6 - CP 37
  117. rc = IsValidCodePage( 37 );
  118. CheckReturnValidW( rc,
  119. TRUE,
  120. NULL,
  121. NULL,
  122. "CP 37",
  123. &NumErrors );
  124. // Variation 7 - CP 65000 (UTF-7)
  125. rc = IsValidCodePage( 65000 );
  126. CheckReturnValidW( rc,
  127. TRUE,
  128. NULL,
  129. NULL,
  130. "CP 65000",
  131. &NumErrors );
  132. // Variation 8 - CP 65001 (UTF-8)
  133. rc = IsValidCodePage( 65001 );
  134. CheckReturnValidW( rc,
  135. TRUE,
  136. NULL,
  137. NULL,
  138. "CP 65001",
  139. &NumErrors );
  140. //
  141. // Return total number of errors found.
  142. //
  143. return (NumErrors);
  144. }
  145. ////////////////////////////////////////////////////////////////////////////
  146. //
  147. // TestIsValidLocale
  148. //
  149. // Test routine for IsValidLocale API.
  150. //
  151. // 07-26-93 JulieB Created.
  152. ////////////////////////////////////////////////////////////////////////////
  153. int TestIsValidLocale()
  154. {
  155. int ErrCount = 0; // error count
  156. //
  157. // Print out what's being done.
  158. //
  159. printf("\n\nTESTING IsValidLocale...\n\n");
  160. //
  161. // Test normal cases.
  162. //
  163. ErrCount += IVLC_NormalCase();
  164. //
  165. // Print out result.
  166. //
  167. printf("\nIsValidLocale: ERRORS = %d\n", ErrCount);
  168. //
  169. // Return total number of errors found.
  170. //
  171. return (ErrCount);
  172. }
  173. ////////////////////////////////////////////////////////////////////////////
  174. //
  175. // IVLC_NormalCase
  176. //
  177. // This routine tests the normal cases of the API routine.
  178. //
  179. // 07-26-93 JulieB Created.
  180. ////////////////////////////////////////////////////////////////////////////
  181. int IVLC_NormalCase()
  182. {
  183. int NumErrors = 0; // error count - to be returned
  184. BOOL rc; // return code
  185. //
  186. // Invalid values for Locale.
  187. //
  188. // Variation 1 - Neutral Locale
  189. rc = IsValidLocale( 0x00000000,
  190. LCID_SUPPORTED );
  191. CheckReturnValidW( rc,
  192. FALSE,
  193. NULL,
  194. NULL,
  195. "LOCALE_NEUTRAL",
  196. &NumErrors );
  197. // Variation 2 - System Default Locale
  198. rc = IsValidLocale( LOCALE_SYSTEM_DEFAULT,
  199. LCID_SUPPORTED );
  200. CheckReturnValidW( rc,
  201. FALSE,
  202. NULL,
  203. NULL,
  204. "LOCALE_SYSTEM_DEFAULT",
  205. &NumErrors );
  206. // Variation 3 - User Default Locale
  207. rc = IsValidLocale( LOCALE_USER_DEFAULT,
  208. LCID_SUPPORTED );
  209. CheckReturnValidW( rc,
  210. FALSE,
  211. NULL,
  212. NULL,
  213. "LOCALE_USER_DEFAULT",
  214. &NumErrors );
  215. // Variation 4 - LCID 01000409
  216. rc = IsValidLocale( 0x01000409,
  217. LCID_SUPPORTED );
  218. CheckReturnValidW( rc,
  219. FALSE,
  220. NULL,
  221. NULL,
  222. "invalid (0x01000409)",
  223. &NumErrors );
  224. // Variation 5 - invalid flag
  225. rc = IsValidLocale( 0x00000409,
  226. 0x10000000 );
  227. CheckReturnValidW( rc,
  228. FALSE,
  229. NULL,
  230. NULL,
  231. "invalid flag",
  232. &NumErrors );
  233. // Variation 6 - LCID 00010407
  234. rc = IsValidLocale( 0x00010407,
  235. LCID_SUPPORTED );
  236. CheckReturnValidW( rc,
  237. TRUE,
  238. NULL,
  239. NULL,
  240. "sort bit (0x00010407)",
  241. &NumErrors );
  242. // Variation 7 - LCID 00010409
  243. rc = IsValidLocale( 0x00010409,
  244. LCID_SUPPORTED );
  245. CheckReturnValidW( rc,
  246. FALSE,
  247. NULL,
  248. NULL,
  249. "sort bit (0x00010409)",
  250. &NumErrors );
  251. //
  252. // Valid values for locale.
  253. //
  254. // Variation 1 - LCID 00000409 supported
  255. rc = IsValidLocale( 0x00000409,
  256. LCID_SUPPORTED );
  257. CheckReturnValidW( rc,
  258. TRUE,
  259. NULL,
  260. NULL,
  261. "supported 0x0409",
  262. &NumErrors );
  263. // Variation 2 - LCID 00000409 installed
  264. rc = IsValidLocale( 0x00000409,
  265. LCID_INSTALLED );
  266. CheckReturnValidW( rc,
  267. TRUE,
  268. NULL,
  269. NULL,
  270. "installed 0x0409",
  271. &NumErrors );
  272. // Variation 3 - LCID 0000041f supported
  273. rc = IsValidLocale( 0x0000041f,
  274. LCID_SUPPORTED );
  275. CheckReturnValidW( rc,
  276. TRUE,
  277. NULL,
  278. NULL,
  279. "supported 0x041f",
  280. &NumErrors );
  281. // Variation 4 - LCID 0000041f installed
  282. rc = IsValidLocale( 0x0000041f,
  283. LCID_INSTALLED );
  284. CheckReturnValidW( rc,
  285. TRUE,
  286. NULL,
  287. NULL,
  288. "installed 0x041f",
  289. &NumErrors );
  290. // Variation 5 - LCID 00000408 supported
  291. rc = IsValidLocale( 0x00000408,
  292. LCID_SUPPORTED );
  293. CheckReturnValidW( rc,
  294. TRUE,
  295. NULL,
  296. NULL,
  297. "supported 0x0408",
  298. &NumErrors );
  299. // Variation 6 - LCID 00000408 installed
  300. rc = IsValidLocale( 0x00000408,
  301. LCID_INSTALLED );
  302. CheckReturnValidW( rc,
  303. TRUE,
  304. NULL,
  305. NULL,
  306. "installed 0x0408",
  307. &NumErrors );
  308. // Variation 7 - LCID 00000411 installed
  309. rc = IsValidLocale( 0x00000411,
  310. LCID_INSTALLED );
  311. CheckReturnValidW( rc,
  312. TRUE,
  313. NULL,
  314. NULL,
  315. "installed (0x00000411)",
  316. &NumErrors );
  317. //
  318. // Return total number of errors found.
  319. //
  320. return (NumErrors);
  321. }
  322. ////////////////////////////////////////////////////////////////////////////
  323. //
  324. // TestIsValidLanguageGroup
  325. //
  326. // Test routine for IsValidLanguageGroup API.
  327. //
  328. // 03-10-98 JulieB Created.
  329. ////////////////////////////////////////////////////////////////////////////
  330. int TestIsValidLanguageGroup()
  331. {
  332. int ErrCount = 0; // error count
  333. //
  334. // Print out what's being done.
  335. //
  336. printf("\n\nTESTING IsValidLanguageGroup...\n\n");
  337. //
  338. // Test normal cases.
  339. //
  340. ErrCount += IVLG_NormalCase();
  341. //
  342. // Print out result.
  343. //
  344. printf("\nIsValidLanguageGroup: ERRORS = %d\n", ErrCount);
  345. //
  346. // Return total number of errors found.
  347. //
  348. return (ErrCount);
  349. }
  350. ////////////////////////////////////////////////////////////////////////////
  351. //
  352. // IVLG_NormalCase
  353. //
  354. // This routine tests the normal cases of the API routine.
  355. //
  356. // 03-10-98 JulieB Created.
  357. ////////////////////////////////////////////////////////////////////////////
  358. int IVLG_NormalCase()
  359. {
  360. int NumErrors = 0; // error count - to be returned
  361. BOOL rc; // return code
  362. //
  363. // Invalid values for Language Groups.
  364. //
  365. // Variation 1 - Neutral Language Group
  366. rc = IsValidLanguageGroup( 0x0,
  367. LGRPID_SUPPORTED );
  368. CheckReturnValidW( rc,
  369. FALSE,
  370. NULL,
  371. NULL,
  372. "Language Group NEUTRAL",
  373. &NumErrors );
  374. // Variation 2 - Invalid Language Group
  375. rc = IsValidLanguageGroup( 0x12,
  376. LGRPID_SUPPORTED );
  377. CheckReturnValidW( rc,
  378. FALSE,
  379. NULL,
  380. NULL,
  381. "Invalid (0x12)",
  382. &NumErrors );
  383. // Variation 3 - Invalid Language Group
  384. rc = IsValidLanguageGroup( 18,
  385. LGRPID_SUPPORTED );
  386. CheckReturnValidW( rc,
  387. FALSE,
  388. NULL,
  389. NULL,
  390. "Invalid (18)",
  391. &NumErrors );
  392. // Variation 4 - Invalid Language Group
  393. rc = IsValidLanguageGroup( 0x0100,
  394. LGRPID_SUPPORTED );
  395. CheckReturnValidW( rc,
  396. FALSE,
  397. NULL,
  398. NULL,
  399. "invalid (0x0100)",
  400. &NumErrors );
  401. // Variation 5 - invalid flag
  402. rc = IsValidLanguageGroup( 1,
  403. 0x10000000 );
  404. CheckReturnValidW( rc,
  405. FALSE,
  406. NULL,
  407. NULL,
  408. "invalid flag",
  409. &NumErrors );
  410. //
  411. // Valid values for language groups.
  412. //
  413. // Variation 1 - LGRPID 1 supported
  414. rc = IsValidLanguageGroup( 1,
  415. LGRPID_SUPPORTED );
  416. CheckReturnValidW( rc,
  417. TRUE,
  418. NULL,
  419. NULL,
  420. "supported 1",
  421. &NumErrors );
  422. // Variation 2 - LGRPID 1 installed
  423. rc = IsValidLanguageGroup( 1,
  424. LGRPID_INSTALLED );
  425. CheckReturnValidW( rc,
  426. TRUE,
  427. NULL,
  428. NULL,
  429. "installed 0x0409",
  430. &NumErrors );
  431. // Variation 3 - LGRPID 0x1 supported
  432. rc = IsValidLanguageGroup( 0x1,
  433. LGRPID_SUPPORTED );
  434. CheckReturnValidW( rc,
  435. TRUE,
  436. NULL,
  437. NULL,
  438. "supported 0x1",
  439. &NumErrors );
  440. // Variation 4 - LGRPID 0x1 installed
  441. rc = IsValidLanguageGroup( 0x1,
  442. LGRPID_INSTALLED );
  443. CheckReturnValidW( rc,
  444. TRUE,
  445. NULL,
  446. NULL,
  447. "installed 0x1",
  448. &NumErrors );
  449. // Variation 5 - LGRPID 0x4 supported
  450. rc = IsValidLanguageGroup( 0x4,
  451. LGRPID_SUPPORTED );
  452. CheckReturnValidW( rc,
  453. TRUE,
  454. NULL,
  455. NULL,
  456. "supported 0x4",
  457. &NumErrors );
  458. // Variation 6 - LGRPID 0x4 installed
  459. rc = IsValidLanguageGroup( 0x4,
  460. LGRPID_INSTALLED );
  461. CheckReturnValidW( rc,
  462. TRUE,
  463. NULL,
  464. NULL,
  465. "installed 0x4",
  466. &NumErrors );
  467. // Variation 7 - LGRPID 0xe supported
  468. rc = IsValidLanguageGroup( 0xe,
  469. LGRPID_SUPPORTED );
  470. CheckReturnValidW( rc,
  471. TRUE,
  472. NULL,
  473. NULL,
  474. "supported (0xe)",
  475. &NumErrors );
  476. // Variation 8 - LGRPID 0xe installed
  477. rc = IsValidLanguageGroup( 0xe,
  478. LGRPID_INSTALLED );
  479. CheckReturnValidW( rc,
  480. TRUE,
  481. NULL,
  482. NULL,
  483. "installed (0xe)",
  484. &NumErrors );
  485. //
  486. // Return total number of errors found.
  487. //
  488. return (NumErrors);
  489. }
  490. ////////////////////////////////////////////////////////////////////////////
  491. //
  492. // TestUtilityAPIs
  493. //
  494. // Test routine for Utility APIs.
  495. //
  496. // 06-14-91 JulieB Created.
  497. ////////////////////////////////////////////////////////////////////////////
  498. int TestUtilityAPIs()
  499. {
  500. int ErrCount = 0; // error count
  501. //
  502. // Print out what's being done.
  503. //
  504. printf("\n\nTESTING GetACP, GetOEMCP,\n");
  505. printf(" GetSystemDefaultUILanguage, GetUserDefaultUILanguage,\n");
  506. printf(" GetSystemDefaultLangID, GetUserDefaultLangID,\n");
  507. printf(" GetSystemDefaultLCID, GetUserDefaultLCID,\n");
  508. printf(" GetThreadLocale, SetThreadLocale...\n\n");
  509. //
  510. // Test normal cases.
  511. //
  512. ErrCount += GUAPI_NormalCase();
  513. //
  514. // Print out result.
  515. //
  516. printf("\nGetUtilityAPIs: ERRORS = %d\n", ErrCount);
  517. //
  518. // Return total number of errors found.
  519. //
  520. return (ErrCount);
  521. }
  522. DWORD GetRegistryString(HKEY hRootKey, LPWSTR szKeyPath, LPWSTR szKeyName, LPWSTR pBuffer, DWORD dwBufferLen)
  523. {
  524. HKEY hKey;
  525. DWORD cbData;
  526. DWORD result = 0;
  527. DWORD dwType;
  528. if (RegOpenKeyW(hRootKey, szKeyPath, &hKey) == ERROR_SUCCESS)
  529. {
  530. if (pBuffer == NULL)
  531. {
  532. if (RegQueryValueExW(hKey, szKeyName, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS)
  533. {
  534. result = cbData;
  535. }
  536. } else
  537. {
  538. cbData = dwBufferLen;
  539. if (RegQueryValueExW(hKey, szKeyName, NULL, &dwType, (LPBYTE)pBuffer, &cbData) == ERROR_SUCCESS)
  540. {
  541. if (dwType == REG_SZ)
  542. {
  543. result = cbData;
  544. }
  545. }
  546. }
  547. }
  548. RegCloseKey(hRootKey);
  549. return (result);
  550. }
  551. ////////////////////////////////////////////////////////////////////////////
  552. //
  553. // PrivateGetUserDefaultUILanguage
  554. //
  555. // This routine reads HKCU\Control Panel\Desktop\MultiUILanguageId
  556. // If that key is not available, return GetSystemDefaultUILanguage();
  557. //
  558. // 06-14-91 JulieB Created.
  559. ////////////////////////////////////////////////////////////////////////////
  560. LANGID PrivateGetUserDefaultUILanguage()
  561. {
  562. WCHAR szValue[256];
  563. BOOL bSuccess = FALSE;
  564. LANGID result;
  565. if (GetRegistryString(HKEY_CURRENT_USER, L"Control Panel\\Desktop", L"MultiUILanguageId", szValue, sizeof(szValue)*sizeof(WCHAR)) > 0) {
  566. if (swscanf(szValue, L"%x", &result) > 0)
  567. {
  568. return (result);
  569. }
  570. }
  571. if (Verbose)
  572. {
  573. printf("....Failed to read HKCU\\Control Panel\\Desktop\\MultiUILanguageId\n");
  574. }
  575. return (GetSystemDefaultUILanguage());
  576. }
  577. ////////////////////////////////////////////////////////////////////////////
  578. //
  579. // GUAPI_NormalCase
  580. //
  581. // This routine tests the normal cases of the API routine.
  582. //
  583. // 06-14-91 JulieB Created.
  584. ////////////////////////////////////////////////////////////////////////////
  585. int GUAPI_NormalCase()
  586. {
  587. int NumErrors = 0; // error count - to be returned
  588. UINT rcInt; // return code
  589. LANGID rcLang; // return code
  590. LCID rcLoc; // return code
  591. LCID rcLoc2; // return code
  592. BOOL rc; // return code
  593. LANGID expectedUILanguage;
  594. #ifdef PERF
  595. DbgBreakPoint();
  596. #endif
  597. // Variation 1 - GetACP
  598. rcInt = GetACP();
  599. CheckReturnValidW( rcInt,
  600. 1252,
  601. NULL,
  602. NULL,
  603. "GetACP",
  604. &NumErrors );
  605. // Variation 2 - GetOEMCP
  606. rcInt = GetOEMCP();
  607. CheckReturnValidW( rcInt,
  608. 437,
  609. NULL,
  610. NULL,
  611. "GetOEMCP",
  612. &NumErrors );
  613. // Variation 3 - GetSystemDefaultUILanguage
  614. rcLang = GetSystemDefaultUILanguage();
  615. CheckReturnValidW( rcLang,
  616. 0x0409,
  617. NULL,
  618. NULL,
  619. "GetSystemDefaultUILanguage",
  620. &NumErrors );
  621. // Variation 4 - GetUserDefaultUILanguage
  622. rcLang = GetUserDefaultUILanguage();
  623. expectedUILanguage = PrivateGetUserDefaultUILanguage();
  624. CheckReturnValidW( rcLang,
  625. expectedUILanguage,
  626. NULL,
  627. NULL,
  628. "GetUserDefaultUILanguage",
  629. &NumErrors );
  630. // Variation 5 - GetSystemDefaultLangID
  631. rcLang = GetSystemDefaultLangID();
  632. CheckReturnValidW( rcLang,
  633. 0x0409,
  634. NULL,
  635. NULL,
  636. "GetSystemDefaultLangID",
  637. &NumErrors );
  638. // Variation 6 - GetUserDefaultLangID
  639. rcLang = GetUserDefaultLangID();
  640. CheckReturnValidW( rcLang,
  641. 0x0409,
  642. NULL,
  643. NULL,
  644. "GetUserDefaultLangID",
  645. &NumErrors );
  646. // Variation 7 - GetSystemDefaultLCID
  647. rcLoc = GetSystemDefaultLCID();
  648. CheckReturnValidW( rcLoc,
  649. 0x00000409,
  650. NULL,
  651. NULL,
  652. "GetSystemDefaultLCID",
  653. &NumErrors );
  654. // Variation 8 - GetUserDefaultLCID
  655. rcLoc = GetUserDefaultLCID();
  656. CheckReturnValidW( rcLoc,
  657. 0x00000409,
  658. NULL,
  659. NULL,
  660. "GetUserDefaultLCID",
  661. &NumErrors );
  662. // Variation 9 - GetThreadLocale and SetThreadLocale
  663. rcLoc = GetThreadLocale();
  664. CheckReturnValidW( rcLoc,
  665. 0x00000409,
  666. NULL,
  667. NULL,
  668. "GetThreadLocale",
  669. &NumErrors );
  670. rc = SetThreadLocale( 0x0000040a );
  671. CheckReturnValidW( rc,
  672. TRUE,
  673. NULL,
  674. NULL,
  675. "SetThreadLocale 040a",
  676. &NumErrors );
  677. rc = SetThreadLocale( 0x0000080b );
  678. CheckReturnValidW( rc,
  679. FALSE,
  680. NULL,
  681. NULL,
  682. "SetThreadLocale invalid",
  683. &NumErrors );
  684. rc = SetThreadLocale( 0x0100040a );
  685. CheckReturnValidW( rc,
  686. FALSE,
  687. NULL,
  688. NULL,
  689. "SetThreadLocale invalid 2",
  690. &NumErrors );
  691. rcLoc2 = GetThreadLocale();
  692. CheckReturnValidW( rcLoc2,
  693. 0x0000040a,
  694. NULL,
  695. NULL,
  696. "GetThreadLocale 040a",
  697. &NumErrors );
  698. rc = SetThreadLocale( rcLoc );
  699. CheckReturnValidW( rc,
  700. TRUE,
  701. NULL,
  702. NULL,
  703. "SetThreadLocale back to original",
  704. &NumErrors );
  705. //
  706. // Return total number of errors found.
  707. //
  708. return (NumErrors);
  709. }