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.

431 lines
9.4 KiB

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