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
9.2 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. etftest.c
  5. Abstract:
  6. Test module for NLS API EnumTimeFormats.
  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 ETF_INVALID_FLAGS ((DWORD)(~(0)))
  21. #define NUM_TIME_ENGLISH 4
  22. #define NUM_TIME_JAPAN 4
  23. #define NUM_TIME_GERMAN 4
  24. //
  25. // Global Variables.
  26. //
  27. int TimeCtr;
  28. //
  29. // Forward Declarations.
  30. //
  31. BOOL
  32. InitEnumTimeFormats();
  33. int
  34. ETF_BadParamCheck();
  35. int
  36. ETF_NormalCase();
  37. int
  38. ETF_Ansi();
  39. BOOL
  40. CALLBACK
  41. MyFuncTime(
  42. LPWSTR pStr);
  43. BOOL
  44. CALLBACK
  45. MyFuncTimeA(
  46. LPSTR pStr);
  47. //
  48. // Callback function
  49. //
  50. BOOL CALLBACK MyFuncTime(
  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. TimeCtr++;
  63. return (TRUE);
  64. }
  65. BOOL CALLBACK MyFuncTimeA(
  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. TimeCtr++;
  78. return (TRUE);
  79. }
  80. ////////////////////////////////////////////////////////////////////////////
  81. //
  82. // TestEnumTimeFormats
  83. //
  84. // Test routine for EnumTimeFormatsW API.
  85. //
  86. // 08-02-93 JulieB Created.
  87. ////////////////////////////////////////////////////////////////////////////
  88. int TestEnumTimeFormats()
  89. {
  90. int ErrCount = 0; // error count
  91. //
  92. // Print out what's being done.
  93. //
  94. printf("\n\nTESTING EnumTimeFormatsW...\n\n");
  95. //
  96. // Initialize global variables.
  97. //
  98. if (!InitEnumTimeFormats())
  99. {
  100. printf("\nABORTED TestEnumTimeFormats: Could not Initialize.\n");
  101. return (1);
  102. }
  103. //
  104. // Test bad parameters.
  105. //
  106. ErrCount += ETF_BadParamCheck();
  107. //
  108. // Test normal cases.
  109. //
  110. ErrCount += ETF_NormalCase();
  111. //
  112. // Test Ansi version.
  113. //
  114. ErrCount += ETF_Ansi();
  115. //
  116. // Print out result.
  117. //
  118. printf("\nEnumTimeFormatsW: ERRORS = %d\n", ErrCount);
  119. //
  120. // Return total number of errors found.
  121. //
  122. return (ErrCount);
  123. }
  124. ////////////////////////////////////////////////////////////////////////////
  125. //
  126. // InitEnumTimeFormats
  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 InitEnumTimeFormats()
  134. {
  135. //
  136. // Initialize date counter.
  137. //
  138. TimeCtr = 0;
  139. //
  140. // Return success.
  141. //
  142. return (TRUE);
  143. }
  144. ////////////////////////////////////////////////////////////////////////////
  145. //
  146. // ETF_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 ETF_BadParamCheck()
  155. {
  156. int NumErrors = 0; // error count - to be returned
  157. int rc; // return code
  158. //
  159. // Bad Function.
  160. //
  161. // Variation 1 - bad function
  162. TimeCtr = 0;
  163. rc = EnumTimeFormatsW( NULL,
  164. 0x0409,
  165. 0 );
  166. CheckReturnBadParamEnum( rc,
  167. FALSE,
  168. ERROR_INVALID_PARAMETER,
  169. "Function invalid",
  170. &NumErrors,
  171. TimeCtr,
  172. 0 );
  173. //
  174. // Bad Locale.
  175. //
  176. // Variation 1 - bad locale
  177. TimeCtr = 0;
  178. rc = EnumTimeFormatsW( MyFuncTime,
  179. (LCID)333,
  180. 0 );
  181. CheckReturnBadParamEnum( rc,
  182. FALSE,
  183. ERROR_INVALID_PARAMETER,
  184. "Locale invalid",
  185. &NumErrors,
  186. TimeCtr,
  187. 0 );
  188. //
  189. // Invalid Flag.
  190. //
  191. // Variation 1 - dwFlags = invalid
  192. TimeCtr = 0;
  193. rc = EnumTimeFormatsW( MyFuncTime,
  194. 0x0409,
  195. ETF_INVALID_FLAGS );
  196. CheckReturnBadParamEnum( rc,
  197. FALSE,
  198. ERROR_INVALID_FLAGS,
  199. "Flag invalid",
  200. &NumErrors,
  201. TimeCtr,
  202. 0 );
  203. //
  204. // Return total number of errors found.
  205. //
  206. return (NumErrors);
  207. }
  208. ////////////////////////////////////////////////////////////////////////////
  209. //
  210. // ETF_NormalCase
  211. //
  212. // This routine tests the normal cases of the API routine.
  213. //
  214. // 08-02-93 JulieB Created.
  215. ////////////////////////////////////////////////////////////////////////////
  216. int ETF_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 - english
  225. TimeCtr = 0;
  226. rc = EnumTimeFormatsW( MyFuncTime,
  227. 0x0409,
  228. 0 );
  229. CheckReturnValidEnum( rc,
  230. TRUE,
  231. TimeCtr,
  232. NUM_TIME_ENGLISH,
  233. "English",
  234. &NumErrors );
  235. // Variation 2 - japan
  236. TimeCtr = 0;
  237. rc = EnumTimeFormatsW( MyFuncTime,
  238. 0x0411,
  239. 0 );
  240. CheckReturnValidEnum( rc,
  241. TRUE,
  242. TimeCtr,
  243. NUM_TIME_JAPAN,
  244. "Japan",
  245. &NumErrors );
  246. // Variation 3 - german
  247. TimeCtr = 0;
  248. rc = EnumTimeFormatsW( MyFuncTime,
  249. 0x0407,
  250. 0 );
  251. CheckReturnValidEnum( rc,
  252. TRUE,
  253. TimeCtr,
  254. NUM_TIME_GERMAN,
  255. "German",
  256. &NumErrors );
  257. //
  258. // Use CP ACP.
  259. //
  260. // Variation 1 - Use CP ACP
  261. TimeCtr = 0;
  262. rc = EnumTimeFormatsW( MyFuncTime,
  263. 0x0409,
  264. LOCALE_USE_CP_ACP );
  265. CheckReturnValidEnum( rc,
  266. TRUE,
  267. TimeCtr,
  268. NUM_TIME_ENGLISH,
  269. "Use CP ACP, English",
  270. &NumErrors );
  271. //
  272. // Return total number of errors found.
  273. //
  274. return (NumErrors);
  275. }
  276. ////////////////////////////////////////////////////////////////////////////
  277. //
  278. // ETF_Ansi
  279. //
  280. // This routine tests the Ansi version of the API routine.
  281. //
  282. // 08-02-93 JulieB Created.
  283. ////////////////////////////////////////////////////////////////////////////
  284. int ETF_Ansi()
  285. {
  286. int NumErrors = 0; // error count - to be returned
  287. int rc; // return code
  288. if (Verbose)
  289. {
  290. printf("\n---- A version ----\n\n");
  291. }
  292. // Variation 1 - english
  293. TimeCtr = 0;
  294. rc = EnumTimeFormatsA( MyFuncTimeA,
  295. 0x0409,
  296. 0 );
  297. CheckReturnValidEnum( rc,
  298. TRUE,
  299. TimeCtr,
  300. NUM_TIME_ENGLISH,
  301. "A version English",
  302. &NumErrors );
  303. // Variation 2 - japan
  304. TimeCtr = 0;
  305. rc = EnumTimeFormatsA( MyFuncTimeA,
  306. 0x0411,
  307. 0 );
  308. CheckReturnValidEnum( rc,
  309. TRUE,
  310. TimeCtr,
  311. NUM_TIME_JAPAN,
  312. "A version Japan",
  313. &NumErrors );
  314. // Variation 3 - german
  315. TimeCtr = 0;
  316. rc = EnumTimeFormatsA( MyFuncTimeA,
  317. 0x0407,
  318. 0 );
  319. CheckReturnValidEnum( rc,
  320. TRUE,
  321. TimeCtr,
  322. NUM_TIME_GERMAN,
  323. "A version German",
  324. &NumErrors );
  325. //
  326. // Use CP ACP.
  327. //
  328. // Variation 1 - Use CP ACP
  329. TimeCtr = 0;
  330. rc = EnumTimeFormatsA( MyFuncTimeA,
  331. 0x0409,
  332. LOCALE_USE_CP_ACP );
  333. CheckReturnValidEnum( rc,
  334. TRUE,
  335. TimeCtr,
  336. NUM_TIME_ENGLISH,
  337. "A version Use CP ACP, English",
  338. &NumErrors );
  339. //
  340. // Return total number of errors found.
  341. //
  342. return (NumErrors);
  343. }