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.

850 lines
22 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. edftest.c
  5. Abstract:
  6. Test module for NLS API EnumDateFormats.
  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 EDF_INVALID_FLAGS ((DWORD)(~(DATE_SHORTDATE | DATE_LONGDATE | \
  21. DATE_YEARMONTH)))
  22. #define NUM_SHORT_DATES_ENGLISH 7
  23. #define NUM_LONG_DATES_ENGLISH 4
  24. #define NUM_YEAR_MONTH_ENGLISH 1
  25. #define NUM_SHORT_DATES_JAPAN 20
  26. #define NUM_LONG_DATES_JAPAN 14
  27. #define NUM_YEAR_MONTH_JAPAN 3
  28. //
  29. // Global Variables.
  30. //
  31. int DateCtr;
  32. //
  33. // Forward Declarations.
  34. //
  35. BOOL
  36. InitEnumDateFormats();
  37. int
  38. EDF_BadParamCheck();
  39. int
  40. EDF_NormalCase();
  41. int
  42. EDF_Ansi();
  43. BOOL
  44. CALLBACK
  45. MyFuncDate(
  46. LPWSTR pStr);
  47. BOOL
  48. CALLBACK
  49. MyFuncDateA(
  50. LPSTR pStr);
  51. BOOL
  52. CALLBACK
  53. MyFuncDateEx(
  54. LPWSTR pStr,
  55. CALID CalId);
  56. BOOL
  57. CALLBACK
  58. MyFuncDateExA(
  59. LPSTR pStr,
  60. CALID CalId);
  61. //
  62. // Callback functions.
  63. //
  64. BOOL CALLBACK MyFuncDate(
  65. LPWSTR pStr)
  66. {
  67. if (Verbose)
  68. {
  69. while (*pStr)
  70. {
  71. printf((*pStr > 0xff) ? "(0x%x)" : "%wc", *pStr);
  72. pStr++;
  73. }
  74. printf("\n");
  75. }
  76. DateCtr++;
  77. return (TRUE);
  78. }
  79. BOOL CALLBACK MyFuncDateA(
  80. LPSTR pStr)
  81. {
  82. if (Verbose)
  83. {
  84. while (*pStr)
  85. {
  86. printf((*pStr > 0xff) ? "(0x%x)" : "%c", *pStr);
  87. pStr++;
  88. }
  89. printf("\n");
  90. }
  91. DateCtr++;
  92. return (TRUE);
  93. }
  94. //
  95. // Callback functions for EX version.
  96. //
  97. BOOL CALLBACK MyFuncDateEx(
  98. LPWSTR pStr,
  99. CALID CalId)
  100. {
  101. if (Verbose)
  102. {
  103. printf("CalId = %d\n", CalId);
  104. while (*pStr)
  105. {
  106. printf((*pStr > 0xff) ? "(0x%x)" : "%wc", *pStr);
  107. pStr++;
  108. }
  109. printf("\n");
  110. }
  111. DateCtr++;
  112. return (TRUE);
  113. }
  114. BOOL CALLBACK MyFuncDateExA(
  115. LPSTR pStr,
  116. CALID CalId)
  117. {
  118. if (Verbose)
  119. {
  120. printf("CalId = %d\n", CalId);
  121. while (*pStr)
  122. {
  123. printf((*pStr > 0xff) ? "(0x%x)" : "%c", *pStr);
  124. pStr++;
  125. }
  126. printf("\n");
  127. }
  128. DateCtr++;
  129. return (TRUE);
  130. }
  131. ////////////////////////////////////////////////////////////////////////////
  132. //
  133. // TestEnumDateFormats
  134. //
  135. // Test routine for EnumDateFormatsW API.
  136. //
  137. // 08-02-93 JulieB Created.
  138. ////////////////////////////////////////////////////////////////////////////
  139. int TestEnumDateFormats()
  140. {
  141. int ErrCount = 0; // error count
  142. //
  143. // Print out what's being done.
  144. //
  145. printf("\n\nTESTING EnumDateFormatsW...\n\n");
  146. //
  147. // Initialize global variables.
  148. //
  149. if (!InitEnumDateFormats())
  150. {
  151. printf("\nABORTED TestEnumDateFormats: Could not Initialize.\n");
  152. return (1);
  153. }
  154. //
  155. // Test bad parameters.
  156. //
  157. ErrCount += EDF_BadParamCheck();
  158. //
  159. // Test normal cases.
  160. //
  161. ErrCount += EDF_NormalCase();
  162. //
  163. // Test Ansi version.
  164. //
  165. ErrCount += EDF_Ansi();
  166. //
  167. // Print out result.
  168. //
  169. printf("\nEnumDateFormatsW: ERRORS = %d\n", ErrCount);
  170. //
  171. // Return total number of errors found.
  172. //
  173. return (ErrCount);
  174. }
  175. ////////////////////////////////////////////////////////////////////////////
  176. //
  177. // InitEnumDateFormats
  178. //
  179. // This routine initializes the global variables. If no errors were
  180. // encountered, then it returns TRUE. Otherwise, it returns FALSE.
  181. //
  182. // 08-02-93 JulieB Created.
  183. ////////////////////////////////////////////////////////////////////////////
  184. BOOL InitEnumDateFormats()
  185. {
  186. //
  187. // Initialize date counter.
  188. //
  189. DateCtr = 0;
  190. //
  191. // Return success.
  192. //
  193. return (TRUE);
  194. }
  195. ////////////////////////////////////////////////////////////////////////////
  196. //
  197. // EDF_BadParamCheck
  198. //
  199. // This routine passes in bad parameters to the API routines and checks to
  200. // be sure they are handled properly. The number of errors encountered
  201. // is returned to the caller.
  202. //
  203. // 08-02-93 JulieB Created.
  204. ////////////////////////////////////////////////////////////////////////////
  205. int EDF_BadParamCheck()
  206. {
  207. int NumErrors = 0; // error count - to be returned
  208. int rc; // return code
  209. //
  210. // Bad Function.
  211. //
  212. // Variation 1 - bad function
  213. DateCtr = 0;
  214. rc = EnumDateFormatsW( NULL,
  215. 0x0409,
  216. DATE_SHORTDATE );
  217. CheckReturnBadParamEnum( rc,
  218. FALSE,
  219. ERROR_INVALID_PARAMETER,
  220. "Function invalid",
  221. &NumErrors,
  222. DateCtr,
  223. 0 );
  224. DateCtr = 0;
  225. rc = EnumDateFormatsExW( NULL,
  226. 0x0409,
  227. DATE_SHORTDATE );
  228. CheckReturnBadParamEnum( rc,
  229. FALSE,
  230. ERROR_INVALID_PARAMETER,
  231. "Ex Function invalid",
  232. &NumErrors,
  233. DateCtr,
  234. 0 );
  235. //
  236. // Bad Locale.
  237. //
  238. // Variation 1 - bad locale
  239. DateCtr = 0;
  240. rc = EnumDateFormatsW( MyFuncDate,
  241. (LCID)333,
  242. DATE_SHORTDATE );
  243. CheckReturnBadParamEnum( rc,
  244. FALSE,
  245. ERROR_INVALID_PARAMETER,
  246. "Locale invalid",
  247. &NumErrors,
  248. DateCtr,
  249. 0 );
  250. DateCtr = 0;
  251. rc = EnumDateFormatsExW( MyFuncDateEx,
  252. (LCID)333,
  253. DATE_SHORTDATE );
  254. CheckReturnBadParamEnum( rc,
  255. FALSE,
  256. ERROR_INVALID_PARAMETER,
  257. "Ex Locale invalid",
  258. &NumErrors,
  259. DateCtr,
  260. 0 );
  261. //
  262. // Invalid Flag.
  263. //
  264. // Variation 1 - dwFlags = invalid
  265. DateCtr = 0;
  266. rc = EnumDateFormatsW( MyFuncDate,
  267. 0x0409,
  268. EDF_INVALID_FLAGS );
  269. CheckReturnBadParamEnum( rc,
  270. FALSE,
  271. ERROR_INVALID_FLAGS,
  272. "Flag invalid",
  273. &NumErrors,
  274. DateCtr,
  275. 0 );
  276. DateCtr = 0;
  277. rc = EnumDateFormatsExW( MyFuncDateEx,
  278. 0x0409,
  279. EDF_INVALID_FLAGS );
  280. CheckReturnBadParamEnum( rc,
  281. FALSE,
  282. ERROR_INVALID_FLAGS,
  283. "Ex Flag invalid",
  284. &NumErrors,
  285. DateCtr,
  286. 0 );
  287. // Variation 2 - dwFlags = both invalid
  288. DateCtr = 0;
  289. rc = EnumDateFormatsW( MyFuncDate,
  290. 0x0409,
  291. DATE_SHORTDATE | DATE_LONGDATE );
  292. CheckReturnBadParamEnum( rc,
  293. FALSE,
  294. ERROR_INVALID_FLAGS,
  295. "Flag both invalid",
  296. &NumErrors,
  297. DateCtr,
  298. 0 );
  299. DateCtr = 0;
  300. rc = EnumDateFormatsW( MyFuncDate,
  301. 0x0409,
  302. DATE_SHORTDATE | DATE_YEARMONTH );
  303. CheckReturnBadParamEnum( rc,
  304. FALSE,
  305. ERROR_INVALID_FLAGS,
  306. "Flag both invalid 2",
  307. &NumErrors,
  308. DateCtr,
  309. 0 );
  310. DateCtr = 0;
  311. rc = EnumDateFormatsExW( MyFuncDateEx,
  312. 0x0409,
  313. DATE_SHORTDATE | DATE_LONGDATE );
  314. CheckReturnBadParamEnum( rc,
  315. FALSE,
  316. ERROR_INVALID_FLAGS,
  317. "Ex Flag both invalid",
  318. &NumErrors,
  319. DateCtr,
  320. 0 );
  321. DateCtr = 0;
  322. rc = EnumDateFormatsExW( MyFuncDateEx,
  323. 0x0409,
  324. DATE_SHORTDATE | DATE_YEARMONTH );
  325. CheckReturnBadParamEnum( rc,
  326. FALSE,
  327. ERROR_INVALID_FLAGS,
  328. "Ex Flag both invalid 2",
  329. &NumErrors,
  330. DateCtr,
  331. 0 );
  332. // Variation 3 - dwFlags = 2 invalid and Use CP ACP
  333. DateCtr = 0;
  334. rc = EnumDateFormatsW( MyFuncDate,
  335. 0x0409,
  336. LOCALE_USE_CP_ACP |
  337. DATE_SHORTDATE | DATE_LONGDATE );
  338. CheckReturnBadParamEnum( rc,
  339. FALSE,
  340. ERROR_INVALID_FLAGS,
  341. "Flag 2 invalid, Use CP ACP",
  342. &NumErrors,
  343. DateCtr,
  344. 0 );
  345. DateCtr = 0;
  346. rc = EnumDateFormatsExW( MyFuncDateEx,
  347. 0x0409,
  348. LOCALE_USE_CP_ACP |
  349. DATE_SHORTDATE | DATE_LONGDATE );
  350. CheckReturnBadParamEnum( rc,
  351. FALSE,
  352. ERROR_INVALID_FLAGS,
  353. "Ex Flag 2 invalid, Use CP ACP",
  354. &NumErrors,
  355. DateCtr,
  356. 0 );
  357. //
  358. // Return total number of errors found.
  359. //
  360. return (NumErrors);
  361. }
  362. ////////////////////////////////////////////////////////////////////////////
  363. //
  364. // EDF_NormalCase
  365. //
  366. // This routine tests the normal cases of the API routine.
  367. //
  368. // 08-02-93 JulieB Created.
  369. ////////////////////////////////////////////////////////////////////////////
  370. int EDF_NormalCase()
  371. {
  372. int NumErrors = 0; // error count - to be returned
  373. int rc; // return code
  374. if (Verbose)
  375. {
  376. printf("\n---- W version ----\n\n");
  377. }
  378. // Variation 1 - short date
  379. DateCtr = 0;
  380. rc = EnumDateFormatsW( MyFuncDate,
  381. 0x0409,
  382. DATE_SHORTDATE );
  383. CheckReturnValidEnum( rc,
  384. TRUE,
  385. DateCtr,
  386. NUM_SHORT_DATES_ENGLISH,
  387. "short date English",
  388. &NumErrors );
  389. DateCtr = 0;
  390. rc = EnumDateFormatsExW( MyFuncDateEx,
  391. 0x0409,
  392. DATE_SHORTDATE );
  393. CheckReturnValidEnum( rc,
  394. TRUE,
  395. DateCtr,
  396. NUM_SHORT_DATES_ENGLISH,
  397. "Ex short date English",
  398. &NumErrors );
  399. // Variation 2 - short date
  400. DateCtr = 0;
  401. rc = EnumDateFormatsW( MyFuncDate,
  402. 0x0411,
  403. DATE_SHORTDATE );
  404. CheckReturnValidEnum( rc,
  405. TRUE,
  406. DateCtr,
  407. NUM_SHORT_DATES_JAPAN,
  408. "short date Japan",
  409. &NumErrors );
  410. DateCtr = 0;
  411. rc = EnumDateFormatsExW( MyFuncDateEx,
  412. 0x0411,
  413. DATE_SHORTDATE );
  414. CheckReturnValidEnum( rc,
  415. TRUE,
  416. DateCtr,
  417. NUM_SHORT_DATES_JAPAN,
  418. "Ex short date Japan",
  419. &NumErrors );
  420. // Variation 3 - long date
  421. DateCtr = 0;
  422. rc = EnumDateFormatsW( MyFuncDate,
  423. 0x0409,
  424. DATE_LONGDATE );
  425. CheckReturnValidEnum( rc,
  426. TRUE,
  427. DateCtr,
  428. NUM_LONG_DATES_ENGLISH,
  429. "long date English",
  430. &NumErrors );
  431. DateCtr = 0;
  432. rc = EnumDateFormatsExW( MyFuncDateEx,
  433. 0x0409,
  434. DATE_LONGDATE );
  435. CheckReturnValidEnum( rc,
  436. TRUE,
  437. DateCtr,
  438. NUM_LONG_DATES_ENGLISH,
  439. "Ex long date English",
  440. &NumErrors );
  441. // Variation 4 - long date
  442. DateCtr = 0;
  443. rc = EnumDateFormatsW( MyFuncDate,
  444. 0x0411,
  445. DATE_LONGDATE );
  446. CheckReturnValidEnum( rc,
  447. TRUE,
  448. DateCtr,
  449. NUM_LONG_DATES_JAPAN,
  450. "long date Japan",
  451. &NumErrors );
  452. DateCtr = 0;
  453. rc = EnumDateFormatsExW( MyFuncDateEx,
  454. 0x0411,
  455. DATE_LONGDATE );
  456. CheckReturnValidEnum( rc,
  457. TRUE,
  458. DateCtr,
  459. NUM_LONG_DATES_JAPAN,
  460. "Ex long date Japan",
  461. &NumErrors );
  462. // Variation 5 - year month
  463. DateCtr = 0;
  464. rc = EnumDateFormatsW( MyFuncDate,
  465. 0x0409,
  466. DATE_YEARMONTH );
  467. CheckReturnValidEnum( rc,
  468. TRUE,
  469. DateCtr,
  470. NUM_YEAR_MONTH_ENGLISH,
  471. "year month English",
  472. &NumErrors );
  473. DateCtr = 0;
  474. rc = EnumDateFormatsExW( MyFuncDateEx,
  475. 0x0409,
  476. DATE_YEARMONTH );
  477. CheckReturnValidEnum( rc,
  478. TRUE,
  479. DateCtr,
  480. NUM_YEAR_MONTH_ENGLISH,
  481. "Ex year month English",
  482. &NumErrors );
  483. // Variation 6 - year month
  484. DateCtr = 0;
  485. rc = EnumDateFormatsW( MyFuncDate,
  486. 0x0411,
  487. DATE_YEARMONTH );
  488. CheckReturnValidEnum( rc,
  489. TRUE,
  490. DateCtr,
  491. NUM_YEAR_MONTH_JAPAN,
  492. "year month Japan",
  493. &NumErrors );
  494. DateCtr = 0;
  495. rc = EnumDateFormatsExW( MyFuncDateEx,
  496. 0x0411,
  497. DATE_YEARMONTH );
  498. CheckReturnValidEnum( rc,
  499. TRUE,
  500. DateCtr,
  501. NUM_YEAR_MONTH_JAPAN,
  502. "Ex year month Japan",
  503. &NumErrors );
  504. //
  505. // Use CP ACP.
  506. //
  507. // Variation 1 - Use CP ACP
  508. DateCtr = 0;
  509. rc = EnumDateFormatsW( MyFuncDate,
  510. 0x0409,
  511. LOCALE_USE_CP_ACP | DATE_SHORTDATE );
  512. CheckReturnValidEnum( rc,
  513. TRUE,
  514. DateCtr,
  515. NUM_SHORT_DATES_ENGLISH,
  516. "Use CP ACP, short date English",
  517. &NumErrors );
  518. DateCtr = 0;
  519. rc = EnumDateFormatsExW( MyFuncDateEx,
  520. 0x0409,
  521. LOCALE_USE_CP_ACP | DATE_SHORTDATE );
  522. CheckReturnValidEnum( rc,
  523. TRUE,
  524. DateCtr,
  525. NUM_SHORT_DATES_ENGLISH,
  526. "Ex Use CP ACP, short date English",
  527. &NumErrors );
  528. //
  529. // Return total number of errors found.
  530. //
  531. return (NumErrors);
  532. }
  533. ////////////////////////////////////////////////////////////////////////////
  534. //
  535. // EDF_Ansi
  536. //
  537. // This routine tests the Ansi version of the API routine.
  538. //
  539. // 08-02-93 JulieB Created.
  540. ////////////////////////////////////////////////////////////////////////////
  541. int EDF_Ansi()
  542. {
  543. int NumErrors = 0; // error count - to be returned
  544. int rc; // return code
  545. if (Verbose)
  546. {
  547. printf("\n---- A version ----\n\n");
  548. }
  549. // Variation 1 - short date
  550. DateCtr = 0;
  551. rc = EnumDateFormatsA( MyFuncDateA,
  552. 0x0409,
  553. DATE_SHORTDATE );
  554. CheckReturnValidEnum( rc,
  555. TRUE,
  556. DateCtr,
  557. NUM_SHORT_DATES_ENGLISH,
  558. "A version short date English",
  559. &NumErrors );
  560. DateCtr = 0;
  561. rc = EnumDateFormatsExA( MyFuncDateExA,
  562. 0x0409,
  563. DATE_SHORTDATE );
  564. CheckReturnValidEnum( rc,
  565. TRUE,
  566. DateCtr,
  567. NUM_SHORT_DATES_ENGLISH,
  568. "Ex A version short date English",
  569. &NumErrors );
  570. // Variation 2 - short date
  571. DateCtr = 0;
  572. rc = EnumDateFormatsA( MyFuncDateA,
  573. 0x0411,
  574. DATE_SHORTDATE );
  575. CheckReturnValidEnum( rc,
  576. TRUE,
  577. DateCtr,
  578. NUM_SHORT_DATES_JAPAN,
  579. "A version short date Japan",
  580. &NumErrors );
  581. DateCtr = 0;
  582. rc = EnumDateFormatsExA( MyFuncDateExA,
  583. 0x0411,
  584. DATE_SHORTDATE );
  585. CheckReturnValidEnum( rc,
  586. TRUE,
  587. DateCtr,
  588. NUM_SHORT_DATES_JAPAN,
  589. "Ex A version short date Japan",
  590. &NumErrors );
  591. // Variation 3 - long date
  592. DateCtr = 0;
  593. rc = EnumDateFormatsA( MyFuncDateA,
  594. 0x0409,
  595. DATE_LONGDATE );
  596. CheckReturnValidEnum( rc,
  597. TRUE,
  598. DateCtr,
  599. NUM_LONG_DATES_ENGLISH,
  600. "A version short date English",
  601. &NumErrors );
  602. DateCtr = 0;
  603. rc = EnumDateFormatsExA( MyFuncDateExA,
  604. 0x0409,
  605. DATE_LONGDATE );
  606. CheckReturnValidEnum( rc,
  607. TRUE,
  608. DateCtr,
  609. NUM_LONG_DATES_ENGLISH,
  610. "Ex A version short date English",
  611. &NumErrors );
  612. // Variation 4 - long date
  613. DateCtr = 0;
  614. rc = EnumDateFormatsA( MyFuncDateA,
  615. 0x0411,
  616. DATE_LONGDATE );
  617. CheckReturnValidEnum( rc,
  618. TRUE,
  619. DateCtr,
  620. NUM_LONG_DATES_JAPAN,
  621. "A version long date Japan",
  622. &NumErrors );
  623. DateCtr = 0;
  624. rc = EnumDateFormatsExA( MyFuncDateExA,
  625. 0x0411,
  626. DATE_LONGDATE );
  627. CheckReturnValidEnum( rc,
  628. TRUE,
  629. DateCtr,
  630. NUM_LONG_DATES_JAPAN,
  631. "Ex A version long date Japan",
  632. &NumErrors );
  633. // Variation 5 - year month
  634. DateCtr = 0;
  635. rc = EnumDateFormatsA( MyFuncDateA,
  636. 0x0409,
  637. DATE_YEARMONTH );
  638. CheckReturnValidEnum( rc,
  639. TRUE,
  640. DateCtr,
  641. NUM_YEAR_MONTH_ENGLISH,
  642. "A version year month English",
  643. &NumErrors );
  644. DateCtr = 0;
  645. rc = EnumDateFormatsExA( MyFuncDateExA,
  646. 0x0409,
  647. DATE_YEARMONTH );
  648. CheckReturnValidEnum( rc,
  649. TRUE,
  650. DateCtr,
  651. NUM_YEAR_MONTH_ENGLISH,
  652. "Ex A version year month English",
  653. &NumErrors );
  654. // Variation 5 - year month
  655. DateCtr = 0;
  656. rc = EnumDateFormatsA( MyFuncDateA,
  657. 0x0411,
  658. DATE_YEARMONTH );
  659. CheckReturnValidEnum( rc,
  660. TRUE,
  661. DateCtr,
  662. NUM_YEAR_MONTH_JAPAN,
  663. "A version year month Japan",
  664. &NumErrors );
  665. DateCtr = 0;
  666. rc = EnumDateFormatsExA( MyFuncDateExA,
  667. 0x0411,
  668. DATE_YEARMONTH );
  669. CheckReturnValidEnum( rc,
  670. TRUE,
  671. DateCtr,
  672. NUM_YEAR_MONTH_JAPAN,
  673. "Ex A version year month Japan",
  674. &NumErrors );
  675. //
  676. // Use CP ACP.
  677. //
  678. // Variation 1 - Use CP ACP
  679. DateCtr = 0;
  680. rc = EnumDateFormatsA( MyFuncDateA,
  681. 0x0409,
  682. LOCALE_USE_CP_ACP | DATE_SHORTDATE );
  683. CheckReturnValidEnum( rc,
  684. TRUE,
  685. DateCtr,
  686. NUM_SHORT_DATES_ENGLISH,
  687. "A version Use CP ACP, short date English",
  688. &NumErrors );
  689. DateCtr = 0;
  690. rc = EnumDateFormatsExA( MyFuncDateExA,
  691. 0x0409,
  692. LOCALE_USE_CP_ACP | DATE_SHORTDATE );
  693. CheckReturnValidEnum( rc,
  694. TRUE,
  695. DateCtr,
  696. NUM_SHORT_DATES_ENGLISH,
  697. "Ex A version Use CP ACP, short date English",
  698. &NumErrors );
  699. //
  700. // Return total number of errors found.
  701. //
  702. return (NumErrors);
  703. }