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.

375 lines
7.7 KiB

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