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.

384 lines
7.9 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. euiltest.c
  5. Abstract:
  6. Test module for NLS API EnumUILanguages.
  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 EUIL_INVALID_FLAGS ((DWORD)(~(0)))
  22. #define NUM_UI_LANGS 1
  23. //
  24. // Global Variables.
  25. //
  26. int UILanguageCtr;
  27. //
  28. // Forward Declarations.
  29. //
  30. BOOL
  31. InitEnumUILanguages();
  32. int
  33. EUIL_BadParamCheck();
  34. int
  35. EUIL_NormalCase();
  36. int
  37. EUIL_Ansi();
  38. BOOL
  39. CALLBACK
  40. MyFuncUILanguage(
  41. LPWSTR pStr,
  42. LONG_PTR lParam);
  43. BOOL
  44. CALLBACK
  45. MyFuncUILanguageA(
  46. LPSTR pStr,
  47. LONG_PTR lParam);
  48. //
  49. // Callback function
  50. //
  51. BOOL CALLBACK MyFuncUILanguage(
  52. LPWSTR pStr,
  53. LONG_PTR lParam)
  54. {
  55. if (Verbose)
  56. {
  57. while (*pStr)
  58. {
  59. printf((*pStr > 0xff) ? "(0x%x)" : "%wc", *pStr);
  60. pStr++;
  61. }
  62. printf("\n");
  63. }
  64. UILanguageCtr++;
  65. return (TRUE);
  66. }
  67. BOOL CALLBACK MyFuncUILanguageA(
  68. LPSTR pStr,
  69. LONG_PTR lParam)
  70. {
  71. if (Verbose)
  72. {
  73. while (*pStr)
  74. {
  75. printf((*pStr > 0xff) ? "(0x%x)" : "%c", *pStr);
  76. pStr++;
  77. }
  78. printf("\n");
  79. }
  80. UILanguageCtr++;
  81. return (TRUE);
  82. }
  83. ////////////////////////////////////////////////////////////////////////////
  84. //
  85. // TestEnumUILanguages
  86. //
  87. // Test routine for EnumUILanguagesW API.
  88. //
  89. // 03-10-98 JulieB Created.
  90. ////////////////////////////////////////////////////////////////////////////
  91. int TestEnumUILanguages()
  92. {
  93. int ErrCount = 0; // error count
  94. //
  95. // Print out what's being done.
  96. //
  97. printf("\n\nTESTING EnumUILanguagesW...\n\n");
  98. //
  99. // Initialize global variables.
  100. //
  101. if (!InitEnumUILanguages())
  102. {
  103. printf("\nABORTED TestEnumUILanguages: Could not Initialize.\n");
  104. return (1);
  105. }
  106. //
  107. // Test bad parameters.
  108. //
  109. ErrCount += EUIL_BadParamCheck();
  110. //
  111. // Test normal cases.
  112. //
  113. ErrCount += EUIL_NormalCase();
  114. //
  115. // Test Ansi version.
  116. //
  117. ErrCount += EUIL_Ansi();
  118. //
  119. // Print out result.
  120. //
  121. printf("\nEnumUILanguagesW: ERRORS = %d\n", ErrCount);
  122. //
  123. // Return total number of errors found.
  124. //
  125. return (ErrCount);
  126. }
  127. ////////////////////////////////////////////////////////////////////////////
  128. //
  129. // InitEnumUILanguages
  130. //
  131. // This routine initializes the global variables. If no errors were
  132. // encountered, then it returns TRUE. Otherwise, it returns FALSE.
  133. //
  134. // 03-10-98 JulieB Created.
  135. ////////////////////////////////////////////////////////////////////////////
  136. BOOL InitEnumUILanguages()
  137. {
  138. //
  139. // Initialize locale counter.
  140. //
  141. UILanguageCtr = 0;
  142. //
  143. // Return success.
  144. //
  145. return (TRUE);
  146. }
  147. ////////////////////////////////////////////////////////////////////////////
  148. //
  149. // EUIL_BadParamCheck
  150. //
  151. // This routine passes in bad parameters to the API routines and checks to
  152. // be sure they are handled properly. The number of errors encountered
  153. // is returned to the caller.
  154. //
  155. // 03-10-98 JulieB Created.
  156. ////////////////////////////////////////////////////////////////////////////
  157. int EUIL_BadParamCheck()
  158. {
  159. int NumErrors = 0; // error count - to be returned
  160. int rc; // return code
  161. //
  162. // Invalid Function.
  163. //
  164. // Variation 1 - Function = invalid
  165. UILanguageCtr = 0;
  166. rc = EnumUILanguagesW( NULL,
  167. 0,
  168. 0 );
  169. CheckReturnBadParamEnum( rc,
  170. FALSE,
  171. ERROR_INVALID_PARAMETER,
  172. "Function invalid",
  173. &NumErrors,
  174. UILanguageCtr,
  175. 0 );
  176. //
  177. // Invalid Flag.
  178. //
  179. // Variation 1 - dwFlags = invalid
  180. UILanguageCtr = 0;
  181. rc = EnumUILanguagesW( MyFuncUILanguage,
  182. EUIL_INVALID_FLAGS,
  183. 0 );
  184. CheckReturnBadParamEnum( rc,
  185. FALSE,
  186. ERROR_INVALID_FLAGS,
  187. "Flag invalid",
  188. &NumErrors,
  189. UILanguageCtr,
  190. 0 );
  191. // Variation 2 - dwFlags = both invalid
  192. UILanguageCtr = 0;
  193. rc = EnumUILanguagesW( MyFuncUILanguage,
  194. LGRPID_INSTALLED | LGRPID_SUPPORTED,
  195. 0 );
  196. CheckReturnBadParamEnum( rc,
  197. FALSE,
  198. ERROR_INVALID_FLAGS,
  199. "Flag both invalid",
  200. &NumErrors,
  201. UILanguageCtr,
  202. 0 );
  203. //
  204. // Return total number of errors found.
  205. //
  206. return (NumErrors);
  207. }
  208. ////////////////////////////////////////////////////////////////////////////
  209. //
  210. // EUIL_NormalCase
  211. //
  212. // This routine tests the normal cases of the API routine.
  213. //
  214. // 03-10-98 JulieB Created.
  215. ////////////////////////////////////////////////////////////////////////////
  216. int EUIL_NormalCase()
  217. {
  218. int NumErrors = 0; // error count - to be returned
  219. int rc; // return code
  220. if (Verbose)
  221. {
  222. printf("\n---- W version ----\n\n");
  223. }
  224. // Variation 1 - valid
  225. UILanguageCtr = 0;
  226. rc = EnumUILanguagesW( MyFuncUILanguage,
  227. 0,
  228. 0 );
  229. if (UILanguageCtr == 0)
  230. {
  231. printf(">>>>ERROR: EnumUILanguagesW() returns no language.");
  232. NumErrors++;
  233. }
  234. //
  235. // TODO: YSLin Write a function to enumerate HKLM\System\CurrentControlSet\Contorl\Nls\MUILanguages for
  236. // the correct answer of UI languages. For now, just assume that this function is doing the right thing.
  237. //
  238. CheckReturnValidEnum( rc,
  239. TRUE,
  240. UILanguageCtr,
  241. UILanguageCtr,
  242. "Valid",
  243. &NumErrors );
  244. //
  245. // Return total number of errors found.
  246. //
  247. return (NumErrors);
  248. }
  249. ////////////////////////////////////////////////////////////////////////////
  250. //
  251. // EUIL_Ansi
  252. //
  253. // This routine tests the Ansi version of the API routine.
  254. //
  255. // 03-10-98 JulieB Created.
  256. ////////////////////////////////////////////////////////////////////////////
  257. int EUIL_Ansi()
  258. {
  259. int NumErrors = 0; // error count - to be returned
  260. int rc; // return code
  261. if (Verbose)
  262. {
  263. printf("\n---- A version ----\n\n");
  264. }
  265. // Variation 1 - valid
  266. UILanguageCtr = 0;
  267. rc = EnumUILanguagesA( MyFuncUILanguageA,
  268. 0,
  269. 0 );
  270. if (UILanguageCtr == 0)
  271. {
  272. printf(">>>>ERROR: EnumUILanguagesA() returns no language.");
  273. NumErrors++;
  274. }
  275. //
  276. // TODO: YSLin Write a function to enumerate HKLM\System\CurrentControlSet\Contorl\Nls\MUILanguages for
  277. // the correct answer of UI languages. For now, just assume that this function is doing the right thing.
  278. //
  279. CheckReturnValidEnum( rc,
  280. TRUE,
  281. UILanguageCtr,
  282. UILanguageCtr,
  283. "A version Valid",
  284. &NumErrors );
  285. //
  286. // Return total number of errors found.
  287. //
  288. return (NumErrors);
  289. }