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.

448 lines
10 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. esltest.c
  5. Abstract:
  6. Test module for NLS API EnumSystemLocales.
  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. 08-02-93 JulieB Created.
  12. --*/
  13. //
  14. // Include Files.
  15. //
  16. #include "nlstest.h"
  17. //
  18. // Constant Declarations.
  19. //
  20. #define BUFSIZE 50 // buffer size in wide chars
  21. #define ESL_INVALID_FLAGS ((DWORD)(~(LCID_INSTALLED | LCID_SUPPORTED)))
  22. #define NUM_INSTALLED_LCIDS 135
  23. #define NUM_SUPPORTED_LCIDS 135
  24. #define NUM_ALTERNATE_SORTS 7
  25. //
  26. // Global Variables.
  27. //
  28. int LocaleCtr;
  29. //
  30. // Forward Declarations.
  31. //
  32. BOOL
  33. InitEnumSystemLocales();
  34. int
  35. ESL_BadParamCheck();
  36. int
  37. ESL_NormalCase();
  38. int
  39. ESL_Ansi();
  40. BOOL
  41. CALLBACK
  42. MyFuncLocale(
  43. LPWSTR pStr);
  44. BOOL
  45. CALLBACK
  46. MyFuncLocaleA(
  47. LPSTR pStr);
  48. //
  49. // Callback function
  50. //
  51. BOOL CALLBACK MyFuncLocale(
  52. LPWSTR pStr)
  53. {
  54. if (Verbose)
  55. {
  56. while (*pStr)
  57. {
  58. // printf((*pStr > 0xff) ? "(0x%x)" : "%wc", *pStr);
  59. printf("%wc", *pStr);
  60. pStr++;
  61. }
  62. printf("\n");
  63. }
  64. LocaleCtr++;
  65. return (TRUE);
  66. }
  67. BOOL CALLBACK MyFuncLocaleA(
  68. LPSTR pStr)
  69. {
  70. if (Verbose)
  71. {
  72. while (*pStr)
  73. {
  74. printf((*pStr > 0xff) ? "(0x%x)" : "%c", *pStr);
  75. pStr++;
  76. }
  77. printf("\n");
  78. }
  79. LocaleCtr++;
  80. return (TRUE);
  81. }
  82. ////////////////////////////////////////////////////////////////////////////
  83. //
  84. // TestEnumSystemLocales
  85. //
  86. // Test routine for EnumSystemLocalesW API.
  87. //
  88. // 08-02-93 JulieB Created.
  89. ////////////////////////////////////////////////////////////////////////////
  90. int TestEnumSystemLocales()
  91. {
  92. int ErrCount = 0; // error count
  93. //
  94. // Print out what's being done.
  95. //
  96. printf("\n\nTESTING EnumSystemLocalesW...\n\n");
  97. //
  98. // Initialize global variables.
  99. //
  100. if (!InitEnumSystemLocales())
  101. {
  102. printf("\nABORTED TestEnumSystemLocales: Could not Initialize.\n");
  103. return (1);
  104. }
  105. //
  106. // Test bad parameters.
  107. //
  108. ErrCount += ESL_BadParamCheck();
  109. //
  110. // Test normal cases.
  111. //
  112. ErrCount += ESL_NormalCase();
  113. //
  114. // Test Ansi version.
  115. //
  116. ErrCount += ESL_Ansi();
  117. //
  118. // Print out result.
  119. //
  120. printf("\nEnumSystemLocalesW: ERRORS = %d\n", ErrCount);
  121. //
  122. // Return total number of errors found.
  123. //
  124. return (ErrCount);
  125. }
  126. ////////////////////////////////////////////////////////////////////////////
  127. //
  128. // InitEnumSystemLocales
  129. //
  130. // This routine initializes the global variables. If no errors were
  131. // encountered, then it returns TRUE. Otherwise, it returns FALSE.
  132. //
  133. // 08-02-93 JulieB Created.
  134. ////////////////////////////////////////////////////////////////////////////
  135. BOOL InitEnumSystemLocales()
  136. {
  137. //
  138. // Initialize locale counter.
  139. //
  140. LocaleCtr = 0;
  141. //
  142. // Return success.
  143. //
  144. return (TRUE);
  145. }
  146. ////////////////////////////////////////////////////////////////////////////
  147. //
  148. // ESL_BadParamCheck
  149. //
  150. // This routine passes in bad parameters to the API routines and checks to
  151. // be sure they are handled properly. The number of errors encountered
  152. // is returned to the caller.
  153. //
  154. // 08-02-93 JulieB Created.
  155. ////////////////////////////////////////////////////////////////////////////
  156. int ESL_BadParamCheck()
  157. {
  158. int NumErrors = 0; // error count - to be returned
  159. int rc; // return code
  160. //
  161. // Invalid Function.
  162. //
  163. // Variation 1 - Function = invalid
  164. LocaleCtr = 0;
  165. rc = EnumSystemLocalesW( NULL,
  166. LCID_INSTALLED );
  167. CheckReturnBadParamEnum( rc,
  168. FALSE,
  169. ERROR_INVALID_PARAMETER,
  170. "Function invalid",
  171. &NumErrors,
  172. LocaleCtr,
  173. 0 );
  174. //
  175. // Invalid Flag.
  176. //
  177. // Variation 1 - dwFlags = invalid
  178. LocaleCtr = 0;
  179. rc = EnumSystemLocalesW(MyFuncLocale, ESL_INVALID_FLAGS);
  180. CheckReturnBadParamEnum( rc,
  181. FALSE,
  182. ERROR_INVALID_FLAGS,
  183. "Flag invalid",
  184. &NumErrors,
  185. LocaleCtr,
  186. 0 );
  187. // Variation 2 - dwFlags = both invalid
  188. LocaleCtr = 0;
  189. rc = EnumSystemLocalesW(MyFuncLocale, LCID_INSTALLED | LCID_SUPPORTED);
  190. CheckReturnBadParamEnum( rc,
  191. FALSE,
  192. ERROR_INVALID_FLAGS,
  193. "Flag both invalid",
  194. &NumErrors,
  195. LocaleCtr,
  196. 0 );
  197. //
  198. // Return total number of errors found.
  199. //
  200. return (NumErrors);
  201. }
  202. ////////////////////////////////////////////////////////////////////////////
  203. //
  204. // ESL_NormalCase
  205. //
  206. // This routine tests the normal cases of the API routine.
  207. //
  208. // 08-02-93 JulieB Created.
  209. ////////////////////////////////////////////////////////////////////////////
  210. int ESL_NormalCase()
  211. {
  212. int NumErrors = 0; // error count - to be returned
  213. int rc; // return code
  214. if (Verbose)
  215. {
  216. printf("\n---- W version ----\n\n");
  217. }
  218. // Variation 1 - Installed
  219. LocaleCtr = 0;
  220. rc = EnumSystemLocalesW( MyFuncLocale,
  221. LCID_INSTALLED );
  222. CheckReturnValidEnum( rc,
  223. TRUE,
  224. LocaleCtr,
  225. NUM_INSTALLED_LCIDS,
  226. "Flag installed",
  227. &NumErrors );
  228. // Variation 2 - Supported
  229. LocaleCtr = 0;
  230. rc = EnumSystemLocalesW( MyFuncLocale,
  231. LCID_SUPPORTED );
  232. CheckReturnValidEnum( rc,
  233. TRUE,
  234. LocaleCtr,
  235. NUM_SUPPORTED_LCIDS,
  236. "Flag supported",
  237. &NumErrors );
  238. // Variation 3 - Alternate Sorts
  239. LocaleCtr = 0;
  240. rc = EnumSystemLocalesW( MyFuncLocale,
  241. LCID_ALTERNATE_SORTS );
  242. CheckReturnValidEnum( rc,
  243. TRUE,
  244. LocaleCtr,
  245. NUM_ALTERNATE_SORTS,
  246. "Flag alternate sorts",
  247. &NumErrors );
  248. // Variation 4 - Installed, Alternate Sorts
  249. LocaleCtr = 0;
  250. rc = EnumSystemLocalesW( MyFuncLocale,
  251. LCID_INSTALLED | LCID_ALTERNATE_SORTS );
  252. CheckReturnValidEnum( rc,
  253. TRUE,
  254. LocaleCtr,
  255. NUM_INSTALLED_LCIDS + NUM_ALTERNATE_SORTS,
  256. "Flag installed, alternate sorts",
  257. &NumErrors );
  258. // Variation 5 - Supported, Alternate Sorts
  259. LocaleCtr = 0;
  260. rc = EnumSystemLocalesW( MyFuncLocale,
  261. LCID_SUPPORTED | LCID_ALTERNATE_SORTS );
  262. CheckReturnValidEnum( rc,
  263. TRUE,
  264. LocaleCtr,
  265. NUM_SUPPORTED_LCIDS + NUM_ALTERNATE_SORTS,
  266. "Flag supported, alternate sorts",
  267. &NumErrors );
  268. //
  269. // Return total number of errors found.
  270. //
  271. return (NumErrors);
  272. }
  273. ////////////////////////////////////////////////////////////////////////////
  274. //
  275. // ESL_Ansi
  276. //
  277. // This routine tests the Ansi version of the API routine.
  278. //
  279. // 08-02-93 JulieB Created.
  280. ////////////////////////////////////////////////////////////////////////////
  281. int ESL_Ansi()
  282. {
  283. int NumErrors = 0; // error count - to be returned
  284. int rc; // return code
  285. if (Verbose)
  286. {
  287. printf("\n---- A version ----\n\n");
  288. }
  289. // Variation 1 - installed
  290. LocaleCtr = 0;
  291. rc = EnumSystemLocalesA( MyFuncLocaleA,
  292. LCID_INSTALLED );
  293. CheckReturnValidEnum( rc,
  294. TRUE,
  295. LocaleCtr,
  296. NUM_INSTALLED_LCIDS,
  297. "A version Flag installed",
  298. &NumErrors );
  299. // Variation 2 - Supported
  300. LocaleCtr = 0;
  301. rc = EnumSystemLocalesA( MyFuncLocaleA,
  302. LCID_SUPPORTED );
  303. CheckReturnValidEnum( rc,
  304. TRUE,
  305. LocaleCtr,
  306. NUM_SUPPORTED_LCIDS,
  307. "A version Flag supported",
  308. &NumErrors );
  309. // Variation 3 - Alternate Sorts
  310. LocaleCtr = 0;
  311. rc = EnumSystemLocalesA( MyFuncLocaleA,
  312. LCID_ALTERNATE_SORTS );
  313. CheckReturnValidEnum( rc,
  314. TRUE,
  315. LocaleCtr,
  316. NUM_ALTERNATE_SORTS,
  317. "A version Flag alternate sorts",
  318. &NumErrors );
  319. // Variation 4 - Installed, Alternate Sorts
  320. LocaleCtr = 0;
  321. rc = EnumSystemLocalesA( MyFuncLocaleA,
  322. LCID_INSTALLED | LCID_ALTERNATE_SORTS );
  323. CheckReturnValidEnum( rc,
  324. TRUE,
  325. LocaleCtr,
  326. NUM_INSTALLED_LCIDS + NUM_ALTERNATE_SORTS,
  327. "A version Flag installed, alternate sorts",
  328. &NumErrors );
  329. // Variation 5 - Supported, Alternate Sorts
  330. LocaleCtr = 0;
  331. rc = EnumSystemLocalesA( MyFuncLocaleA,
  332. LCID_SUPPORTED | LCID_ALTERNATE_SORTS );
  333. CheckReturnValidEnum( rc,
  334. TRUE,
  335. LocaleCtr,
  336. NUM_SUPPORTED_LCIDS + NUM_ALTERNATE_SORTS,
  337. "A version Flag supported, alternate sorts",
  338. &NumErrors );
  339. //
  340. // Return total number of errors found.
  341. //
  342. return (NumErrors);
  343. }