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.

499 lines
13 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. scitest.c
  5. Abstract:
  6. Test module for NLS API SetCalendarInfo.
  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 100 // buffer size in wide chars
  21. #define CALTYPE_INVALID 0x0000002 // invalid CALTYPE
  22. //
  23. // Global Variables.
  24. //
  25. LCID Locale;
  26. WCHAR lpCalData[BUFSIZE];
  27. WCHAR pTwoDigitYearMax[BUFSIZE];
  28. //
  29. // Forward Declarations.
  30. //
  31. BOOL
  32. InitSetCalInfo();
  33. int
  34. SCI_BadParamCheck();
  35. int
  36. SCI_NormalCase();
  37. int
  38. SCI_Ansi();
  39. ////////////////////////////////////////////////////////////////////////////
  40. //
  41. // TestSetCalendarInfo
  42. //
  43. // Test routine for SetCalendarInfoW API.
  44. //
  45. // 03-10-98 JulieB Created.
  46. ////////////////////////////////////////////////////////////////////////////
  47. int TestSetCalendarInfo()
  48. {
  49. int ErrCount = 0; // error count
  50. //
  51. // Print out what's being done.
  52. //
  53. printf("\n\nTESTING SetCalendarInfoW...\n\n");
  54. //
  55. // Initialize global variables.
  56. //
  57. if (!InitSetCalInfo())
  58. {
  59. printf("\nABORTED TestSetCalendarInfo: Could not Initialize.\n");
  60. return (1);
  61. }
  62. //
  63. // Test bad parameters.
  64. //
  65. ErrCount += SCI_BadParamCheck();
  66. //
  67. // Test normal cases.
  68. //
  69. ErrCount += SCI_NormalCase();
  70. //
  71. // Test Ansi version.
  72. //
  73. ErrCount += SCI_Ansi();
  74. //
  75. // Print out result.
  76. //
  77. printf("\nSetCalendarInfoW: ERRORS = %d\n", ErrCount);
  78. //
  79. // Return total number of errors found.
  80. //
  81. return (ErrCount);
  82. }
  83. ////////////////////////////////////////////////////////////////////////////
  84. //
  85. // InitSetCalInfo
  86. //
  87. // This routine initializes the global variables. If no errors were
  88. // encountered, then it returns TRUE. Otherwise, it returns FALSE.
  89. //
  90. // 03-10-98 JulieB Created.
  91. ////////////////////////////////////////////////////////////////////////////
  92. BOOL InitSetCalInfo()
  93. {
  94. //
  95. // Make a Locale.
  96. //
  97. Locale = MAKELCID(0x0409, 0);
  98. //
  99. // Save the ITWODIGITYEARMAX value to be restored later.
  100. //
  101. if (!GetCalendarInfoW( Locale,
  102. CAL_GREGORIAN,
  103. CAL_ITWODIGITYEARMAX,
  104. pTwoDigitYearMax,
  105. BUFSIZE,
  106. NULL ))
  107. {
  108. printf("ERROR: Initialization ITWODIGITYEARMAX - error = %d\n", GetLastError());
  109. return (FALSE);
  110. }
  111. //
  112. // Return success.
  113. //
  114. return (TRUE);
  115. }
  116. ////////////////////////////////////////////////////////////////////////////
  117. //
  118. // SCI_BadParamCheck
  119. //
  120. // This routine passes in bad parameters to the API routines and checks to
  121. // be sure they are handled properly. The number of errors encountered
  122. // is returned to the caller.
  123. //
  124. // 03-10-98 JulieB Created.
  125. ////////////////////////////////////////////////////////////////////////////
  126. int SCI_BadParamCheck()
  127. {
  128. int NumErrors = 0; // error count - to be returned
  129. int rc; // return code
  130. //
  131. // Bad Locale.
  132. //
  133. // Variation 1 - Bad Locale
  134. rc = SetCalendarInfoW( (LCID)333,
  135. CAL_GREGORIAN,
  136. CAL_ITWODIGITYEARMAX,
  137. L"2029" );
  138. CheckReturnBadParam( rc,
  139. 0,
  140. ERROR_INVALID_PARAMETER,
  141. "Bad Locale",
  142. &NumErrors );
  143. //
  144. // Null Pointers.
  145. //
  146. // Variation 1 - lpCalData = NULL
  147. rc = SetCalendarInfoW( Locale,
  148. CAL_GREGORIAN,
  149. CAL_ITWODIGITYEARMAX,
  150. NULL );
  151. CheckReturnBadParam( rc,
  152. 0,
  153. ERROR_INVALID_PARAMETER,
  154. "lpCalData NULL",
  155. &NumErrors );
  156. //
  157. // Zero or Invalid Type.
  158. //
  159. // Variation 1 - CalType = invalid
  160. rc = SetCalendarInfoW( Locale,
  161. CAL_GREGORIAN,
  162. CALTYPE_INVALID,
  163. L"2029" );
  164. CheckReturnBadParam( rc,
  165. 0,
  166. ERROR_INVALID_FLAGS,
  167. "CalType invalid",
  168. &NumErrors );
  169. // Variation 2 - CalType = 0
  170. rc = SetCalendarInfoW( Locale,
  171. CAL_GREGORIAN,
  172. 0,
  173. L"2029" );
  174. CheckReturnBadParam( rc,
  175. 0,
  176. ERROR_INVALID_FLAGS,
  177. "CalType zero",
  178. &NumErrors );
  179. // Variation 1 - Use CP ACP, CalType = invalid
  180. rc = SetCalendarInfoW( Locale,
  181. CAL_GREGORIAN,
  182. CAL_USE_CP_ACP | CALTYPE_INVALID,
  183. L"2029" );
  184. CheckReturnBadParam( rc,
  185. 0,
  186. ERROR_INVALID_FLAGS,
  187. "Use CP ACP, CalType invalid",
  188. &NumErrors );
  189. //
  190. // Return total number of errors found.
  191. //
  192. return (NumErrors);
  193. }
  194. ////////////////////////////////////////////////////////////////////////////
  195. //
  196. // SCI_NormalCase
  197. //
  198. // This routine tests the normal cases of the API routine.
  199. //
  200. // 03-10-98 JulieB Created.
  201. ////////////////////////////////////////////////////////////////////////////
  202. int SCI_NormalCase()
  203. {
  204. int NumErrors = 0; // error count - to be returned
  205. int rc; // return code
  206. #ifdef PERF
  207. DbgBreakPoint();
  208. #endif
  209. //
  210. // Locales.
  211. //
  212. // Variation 1 - System Default Locale
  213. rc = SetCalendarInfoW( LOCALE_SYSTEM_DEFAULT,
  214. CAL_GREGORIAN,
  215. CAL_ITWODIGITYEARMAX,
  216. L"2035" );
  217. CheckReturnEqual( rc,
  218. FALSE,
  219. "SET - system default locale",
  220. &NumErrors );
  221. rc = GetCalendarInfoW( LOCALE_SYSTEM_DEFAULT,
  222. CAL_GREGORIAN,
  223. CAL_ITWODIGITYEARMAX,
  224. lpCalData,
  225. BUFSIZE,
  226. NULL );
  227. CheckReturnValidW( rc,
  228. -1,
  229. lpCalData,
  230. L"2035",
  231. "GET - system default locale",
  232. &NumErrors );
  233. // Variation 2 - Current User Locale
  234. rc = SetCalendarInfoW( LOCALE_USER_DEFAULT,
  235. CAL_GREGORIAN,
  236. CAL_ITWODIGITYEARMAX,
  237. L"2040" );
  238. CheckReturnEqual( rc,
  239. FALSE,
  240. "SET - current user locale",
  241. &NumErrors );
  242. rc = GetCalendarInfoW( LOCALE_USER_DEFAULT,
  243. CAL_GREGORIAN,
  244. CAL_ITWODIGITYEARMAX,
  245. lpCalData,
  246. BUFSIZE,
  247. NULL );
  248. CheckReturnValidW( rc,
  249. -1,
  250. lpCalData,
  251. L"2040",
  252. "GET - current user locale",
  253. &NumErrors );
  254. //
  255. // Use CP ACP.
  256. //
  257. // Variation 1 - Use CP ACP, System Default Locale
  258. rc = SetCalendarInfoW( LOCALE_SYSTEM_DEFAULT,
  259. CAL_GREGORIAN,
  260. CAL_USE_CP_ACP | CAL_ITWODIGITYEARMAX,
  261. L"2050" );
  262. CheckReturnEqual( rc,
  263. FALSE,
  264. "SET - Use CP ACP, system default locale",
  265. &NumErrors );
  266. rc = GetCalendarInfoW( LOCALE_SYSTEM_DEFAULT,
  267. CAL_GREGORIAN,
  268. CAL_USE_CP_ACP | CAL_ITWODIGITYEARMAX,
  269. lpCalData,
  270. BUFSIZE,
  271. NULL );
  272. CheckReturnValidW( rc,
  273. -1,
  274. lpCalData,
  275. L"2050",
  276. "GET - Use CP ACP, system default locale",
  277. &NumErrors );
  278. //
  279. // CALTYPE values.
  280. //
  281. // Variation 1 - ITWODIGITYEARMAX
  282. rc = SetCalendarInfoW( Locale,
  283. CAL_GREGORIAN,
  284. CAL_ITWODIGITYEARMAX,
  285. L"10000" );
  286. CheckReturnEqual( rc,
  287. TRUE,
  288. "SET - MAX ITWODIGITYEARMAX",
  289. &NumErrors );
  290. rc = SetCalendarInfoW( Locale,
  291. CAL_GREGORIAN,
  292. CAL_ITWODIGITYEARMAX,
  293. L"98" );
  294. CheckReturnEqual( rc,
  295. TRUE,
  296. "SET - MIN ITWODIGITYEARMAX",
  297. &NumErrors );
  298. rc = SetCalendarInfoW( Locale,
  299. CAL_GREGORIAN,
  300. CAL_ITWODIGITYEARMAX,
  301. L"3030" );
  302. CheckReturnEqual( rc,
  303. FALSE,
  304. "SET - ITWODIGITYEARMAX",
  305. &NumErrors );
  306. rc = GetCalendarInfoW( Locale,
  307. CAL_GREGORIAN,
  308. CAL_ITWODIGITYEARMAX,
  309. lpCalData,
  310. BUFSIZE,
  311. NULL );
  312. CheckReturnValidW( rc,
  313. -1,
  314. lpCalData,
  315. L"3030",
  316. "GET - ITWODIGITYEARMAX",
  317. &NumErrors );
  318. rc = SetCalendarInfoW( Locale,
  319. CAL_GREGORIAN,
  320. CAL_ITWODIGITYEARMAX,
  321. pTwoDigitYearMax );
  322. CheckReturnEqual( rc,
  323. FALSE,
  324. "ReSET - ITWODIGITYEARMAX",
  325. &NumErrors );
  326. //
  327. // Return total number of errors found.
  328. //
  329. return (NumErrors);
  330. }
  331. ////////////////////////////////////////////////////////////////////////////
  332. //
  333. // SCI_Ansi
  334. //
  335. // This routine tests the Ansi version of the API routine.
  336. //
  337. // 03-10-98 JulieB Created.
  338. ////////////////////////////////////////////////////////////////////////////
  339. int SCI_Ansi()
  340. {
  341. int NumErrors = 0; // error count - to be returned
  342. int rc; // return code
  343. //
  344. // SetCalendarInfoA.
  345. //
  346. // Variation 1 - ITWODIGITYEARMAX
  347. rc = SetCalendarInfoA( Locale,
  348. CAL_GREGORIAN,
  349. CAL_ITWODIGITYEARMAX,
  350. "4040" );
  351. CheckReturnEqual( rc,
  352. FALSE,
  353. "SET - system default locale",
  354. &NumErrors );
  355. rc = GetCalendarInfoW( Locale,
  356. CAL_GREGORIAN,
  357. CAL_ITWODIGITYEARMAX,
  358. lpCalData,
  359. BUFSIZE,
  360. NULL );
  361. CheckReturnValidW( rc,
  362. -1,
  363. lpCalData,
  364. L"4040",
  365. "GET - system default locale",
  366. &NumErrors );
  367. // Variation 2 - Use CP ACP, ITWODIGITYEARMAX
  368. rc = SetCalendarInfoA( Locale,
  369. CAL_GREGORIAN,
  370. CAL_USE_CP_ACP | CAL_ITWODIGITYEARMAX,
  371. "4141" );
  372. CheckReturnEqual( rc,
  373. FALSE,
  374. "SET - Use CP ACP, system default locale",
  375. &NumErrors );
  376. rc = GetCalendarInfoW( Locale,
  377. CAL_GREGORIAN,
  378. CAL_USE_CP_ACP | CAL_ITWODIGITYEARMAX,
  379. lpCalData,
  380. BUFSIZE,
  381. NULL );
  382. CheckReturnValidW( rc,
  383. -1,
  384. lpCalData,
  385. L"4141",
  386. "GET - Use CP ACP, system default locale",
  387. &NumErrors );
  388. //
  389. // Reset the ITWODIGITYEARMAX value.
  390. //
  391. rc = SetCalendarInfoW( Locale,
  392. CAL_GREGORIAN,
  393. CAL_ITWODIGITYEARMAX,
  394. pTwoDigitYearMax );
  395. CheckReturnEqual( rc,
  396. FALSE,
  397. "ReSET - ITWODIGITYEARMAX",
  398. &NumErrors );
  399. //
  400. // Return total number of errors found.
  401. //
  402. return (NumErrors);
  403. }