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.

1341 lines
40 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. gtftest.c
  5. Abstract:
  6. Test module for NLS API GetTimeFormat.
  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. 04-30-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 GTF_INVALID_FLAGS ((DWORD)(~(LOCALE_NOUSEROVERRIDE | \
  22. TIME_NOMINUTESORSECONDS | \
  23. TIME_NOSECONDS | \
  24. TIME_NOTIMEMARKER | \
  25. TIME_FORCE24HOURFORMAT)))
  26. #define ENGLISH_US L"3:45:25 AM"
  27. #define CZECH L"3:45:25"
  28. #define DANISH L"03.45.25"
  29. #define US_NOMINSEC L"3 AM"
  30. #define US_NOSEC L"3:45 AM"
  31. #define US_NOTM L"3:45:25"
  32. #define US_NOTM_NOMINSEC L"3"
  33. #define US_NOTM_NOSEC L"3:45"
  34. #define CZECH_NOMINSEC L"3"
  35. #define CZECH_NOSEC L"3:45"
  36. #define CZECH_NOTM L"3:45:25"
  37. #define CZECH_NOTM_NOMINSEC L"3"
  38. #define CZECH_NOTM_NOSEC L"3:45"
  39. #define US_24HR L"3:45:25 AM"
  40. #define US_24HR_2 L"15:45:25 PM"
  41. #define CZECH_24HR L"3:45:25"
  42. #define CZECH_24HR_2 L"15:45:25"
  43. //
  44. // Global Variables.
  45. //
  46. LCID Locale;
  47. SYSTEMTIME SysTime;
  48. SYSTEMTIME SysTime2;
  49. WCHAR lpTimeStr[BUFSIZE];
  50. //
  51. // Time format buffers must be in line with the pAllLocales global
  52. // buffer.
  53. //
  54. LPWSTR pTimeAM[] =
  55. {
  56. L"03:45:25", // 0x0402
  57. L"\x4e0a\x5348 03:45:25", // 0x0404
  58. L"3:45:25", // 0x0804
  59. L"3:45:25", // 0x0c04
  60. L"AM 3:45:25", // 0x1004
  61. L"3:45:25", // 0x0405
  62. L"03:45:25", // 0x0406
  63. L"03:45:25", // 0x0407
  64. L"03:45:25", // 0x0807
  65. L"03:45:25", // 0x0c07
  66. L"3:45:25 \x03c0\x03bc", // 0x0408
  67. L"3:45:25 AM", // 0x0409
  68. L"03:45:25", // 0x0809
  69. L"3:45:25 AM", // 0x0c09
  70. L"3:45:25 AM", // 0x1009
  71. L"3:45:25 a.m.", // 0x1409
  72. L"03:45:25", // 0x1809
  73. L"3:45:25", // 0x040a
  74. L"03:45:25 a.m.", // 0x080a
  75. L"3:45:25", // 0x0c0a
  76. L"3:45:25", // 0x040b
  77. L"03:45:25", // 0x040c
  78. L"3:45:25", // 0x080c
  79. L"03:45:25", // 0x0c0c
  80. L"03:45:25", // 0x100c
  81. L"3:45:25", // 0x040e
  82. L"03:45:25", // 0x040f
  83. L"3.45.25", // 0x0410
  84. L"03:45:25", // 0x0810
  85. L"3:45:25", // 0x0411
  86. L"\xc624\xc804 3:45:25", // 0x0412
  87. L"3:45:25", // 0x0413
  88. L"3:45:25", // 0x0813
  89. L"03:45:25", // 0x0414
  90. L"03:45:25", // 0x0814
  91. L"03:45:25", // 0x0415
  92. L"03:45:25", // 0x0416
  93. L"3:45:25", // 0x0816
  94. L"03:45:25", // 0x0418
  95. L"3:45:25", // 0x0419
  96. L"3:45:25", // 0x041a
  97. L"3:45:25", // 0x041b
  98. L"03:45:25", // 0x041d
  99. L"03:45:25", // 0x041f
  100. L"3:45:25" // 0x0424
  101. };
  102. LPWSTR pTimePM[] =
  103. {
  104. L"15:45:25", // 0x0402
  105. L"\x4e0b\x5348 03:45:25", // 0x0404
  106. L"15:45:25", // 0x0804
  107. L"15:45:25", // 0x0c04
  108. L"PM 3:45:25", // 0x1004
  109. L"15:45:25", // 0x0405
  110. L"15:45:25", // 0x0406
  111. L"15:45:25", // 0x0407
  112. L"15:45:25", // 0x0807
  113. L"15:45:25", // 0x0c07
  114. L"3:45:25 \x03bc\x03bc", // 0x0408
  115. L"3:45:25 PM", // 0x0409
  116. L"15:45:25", // 0x0809
  117. L"3:45:25 PM", // 0x0c09
  118. L"3:45:25 PM", // 0x1009
  119. L"3:45:25 p.m.", // 0x1409
  120. L"15:45:25", // 0x1809
  121. L"15:45:25", // 0x040a
  122. L"03:45:25 p.m.", // 0x080a
  123. L"15:45:25", // 0x0c0a
  124. L"15:45:25", // 0x040b
  125. L"15:45:25", // 0x040c
  126. L"15:45:25", // 0x080c
  127. L"15:45:25", // 0x0c0c
  128. L"15:45:25", // 0x100c
  129. L"15:45:25", // 0x040e
  130. L"15:45:25", // 0x040f
  131. L"15.45.25", // 0x0410
  132. L"15:45:25", // 0x0810
  133. L"15:45:25", // 0x0411
  134. L"\xc624\xd6c4 3:45:25", // 0x0412
  135. L"15:45:25", // 0x0413
  136. L"15:45:25", // 0x0813
  137. L"15:45:25", // 0x0414
  138. L"15:45:25", // 0x0814
  139. L"15:45:25", // 0x0415
  140. L"15:45:25", // 0x0416
  141. L"15:45:25", // 0x0816
  142. L"15:45:25", // 0x0418
  143. L"15:45:25", // 0x0419
  144. L"15:45:25", // 0x041a
  145. L"15:45:25", // 0x041b
  146. L"15:45:25", // 0x041d
  147. L"15:45:25", // 0x041f
  148. L"15:45:25" // 0x0424
  149. };
  150. //
  151. // Forward Declarations.
  152. //
  153. BOOL
  154. InitGetTimeFormat();
  155. int
  156. GTF_BadParamCheck();
  157. int
  158. GTF_NormalCase();
  159. int
  160. GTF_Ansi();
  161. ////////////////////////////////////////////////////////////////////////////
  162. //
  163. // TestGetTimeFormat
  164. //
  165. // Test routine for GetTimeFormatW API.
  166. //
  167. // 04-30-93 JulieB Created.
  168. ////////////////////////////////////////////////////////////////////////////
  169. int TestGetTimeFormat()
  170. {
  171. int ErrCount = 0; // error count
  172. //
  173. // Print out what's being done.
  174. //
  175. printf("\n\nTESTING GetTimeFormatW...\n\n");
  176. //
  177. // Initialize global variables.
  178. //
  179. if (!InitGetTimeFormat())
  180. {
  181. printf("\nABORTED TestGetTimeFormat: Could not Initialize.\n");
  182. return (1);
  183. }
  184. //
  185. // Test bad parameters.
  186. //
  187. ErrCount += GTF_BadParamCheck();
  188. //
  189. // Test normal cases.
  190. //
  191. ErrCount += GTF_NormalCase();
  192. //
  193. // Test Ansi version.
  194. //
  195. ErrCount += GTF_Ansi();
  196. //
  197. // Print out result.
  198. //
  199. printf("\nGetTimeFormatW: ERRORS = %d\n", ErrCount);
  200. //
  201. // Return total number of errors found.
  202. //
  203. return (ErrCount);
  204. }
  205. ////////////////////////////////////////////////////////////////////////////
  206. //
  207. // InitGetTimeFormat
  208. //
  209. // This routine initializes the global variables. If no errors were
  210. // encountered, then it returns TRUE. Otherwise, it returns FALSE.
  211. //
  212. // 04-30-93 JulieB Created.
  213. ////////////////////////////////////////////////////////////////////////////
  214. BOOL InitGetTimeFormat()
  215. {
  216. //
  217. // Make a Locale.
  218. //
  219. Locale = MAKELCID(0x0409, 0);
  220. //
  221. // Initialize the system time.
  222. //
  223. SysTime.wYear = 1993;
  224. SysTime.wMonth = 5;
  225. SysTime.wDayOfWeek = 6;
  226. SysTime.wDay = 1;
  227. SysTime.wHour = 3;
  228. SysTime.wMinute = 45;
  229. SysTime.wSecond = 25;
  230. SysTime.wMilliseconds = 13;
  231. SysTime2.wYear = 1993;
  232. SysTime2.wMonth = 5;
  233. SysTime2.wDayOfWeek = 6;
  234. SysTime2.wDay = 1;
  235. SysTime2.wHour = 15;
  236. SysTime2.wMinute = 45;
  237. SysTime2.wSecond = 25;
  238. SysTime2.wMilliseconds = 13;
  239. //
  240. // Return success.
  241. //
  242. return (TRUE);
  243. }
  244. ////////////////////////////////////////////////////////////////////////////
  245. //
  246. // GTF_BadParamCheck
  247. //
  248. // This routine passes in bad parameters to the API routines and checks to
  249. // be sure they are handled properly. The number of errors encountered
  250. // is returned to the caller.
  251. //
  252. // 04-30-93 JulieB Created.
  253. ////////////////////////////////////////////////////////////////////////////
  254. int GTF_BadParamCheck()
  255. {
  256. int NumErrors = 0; // error count - to be returned
  257. int rc; // return code
  258. SYSTEMTIME MyTime; // structure to hold custom time
  259. //
  260. // Bad Locale.
  261. //
  262. // Variation 1 - Bad Locale
  263. rc = GetTimeFormatW( (LCID)333,
  264. 0,
  265. NULL,
  266. NULL,
  267. lpTimeStr,
  268. BUFSIZE );
  269. CheckReturnBadParam( rc,
  270. 0,
  271. ERROR_INVALID_PARAMETER,
  272. "Bad Locale",
  273. &NumErrors );
  274. //
  275. // Null Pointers.
  276. //
  277. // Variation 1 - lpTimeStr = NULL
  278. rc = GetTimeFormatW( Locale,
  279. 0,
  280. NULL,
  281. NULL,
  282. NULL,
  283. BUFSIZE );
  284. CheckReturnBadParam( rc,
  285. 0,
  286. ERROR_INVALID_PARAMETER,
  287. "lpTimeStr NULL",
  288. &NumErrors );
  289. //
  290. // Bad Count.
  291. //
  292. // Variation 1 - cchTime < 0
  293. rc = GetTimeFormatW( Locale,
  294. 0,
  295. NULL,
  296. NULL,
  297. lpTimeStr,
  298. -1 );
  299. CheckReturnBadParam( rc,
  300. 0,
  301. ERROR_INVALID_PARAMETER,
  302. "cchTime < 0",
  303. &NumErrors );
  304. //
  305. // Invalid Flag.
  306. //
  307. // Variation 1 - LCType = invalid
  308. rc = GetTimeFormatW( Locale,
  309. GTF_INVALID_FLAGS,
  310. NULL,
  311. NULL,
  312. lpTimeStr,
  313. BUFSIZE );
  314. CheckReturnBadParam( rc,
  315. 0,
  316. ERROR_INVALID_FLAGS,
  317. "Flag invalid",
  318. &NumErrors );
  319. // Variation 2 - lpFormat and NoUserOverride
  320. rc = GetTimeFormatW( Locale,
  321. LOCALE_NOUSEROVERRIDE,
  322. NULL,
  323. L"tt hh:mm:ss",
  324. lpTimeStr,
  325. BUFSIZE );
  326. CheckReturnBadParam( rc,
  327. 0,
  328. ERROR_INVALID_FLAGS,
  329. "lpFormat and NoUserOverride",
  330. &NumErrors );
  331. // Variation 3 - Use CP ACP, lpFormat and NoUserOverride
  332. rc = GetTimeFormatW( Locale,
  333. LOCALE_USE_CP_ACP | LOCALE_NOUSEROVERRIDE,
  334. NULL,
  335. L"tt hh:mm:ss",
  336. lpTimeStr,
  337. BUFSIZE );
  338. CheckReturnBadParam( rc,
  339. 0,
  340. ERROR_INVALID_FLAGS,
  341. "Use CP ACP, lpFormat and NoUserOverride",
  342. &NumErrors );
  343. //
  344. // Buffer Too Small.
  345. //
  346. // Variation 1 - cchTime = too small
  347. rc = GetTimeFormatW( Locale,
  348. 0,
  349. NULL,
  350. NULL,
  351. lpTimeStr,
  352. 2 );
  353. CheckReturnBadParam( rc,
  354. 0,
  355. ERROR_INSUFFICIENT_BUFFER,
  356. "cchTime too small",
  357. &NumErrors );
  358. //
  359. // Bad time passed in.
  360. //
  361. // Variation 1 - bad wHour
  362. MyTime.wYear = 1993;
  363. MyTime.wMonth = 5;
  364. MyTime.wDayOfWeek = 6;
  365. MyTime.wDay = 1;
  366. MyTime.wHour = 24;
  367. MyTime.wMinute = 45;
  368. MyTime.wSecond = 25;
  369. MyTime.wMilliseconds = 13;
  370. rc = GetTimeFormatW( Locale,
  371. 0,
  372. &MyTime,
  373. NULL,
  374. lpTimeStr,
  375. BUFSIZE );
  376. CheckReturnBadParam( rc,
  377. 0,
  378. ERROR_INVALID_PARAMETER,
  379. "bad wHour",
  380. &NumErrors );
  381. // Variation 2 - bad wMinute
  382. MyTime.wYear = 1993;
  383. MyTime.wMonth = 5;
  384. MyTime.wDayOfWeek = 6;
  385. MyTime.wDay = 1;
  386. MyTime.wHour = 15;
  387. MyTime.wMinute = 60;
  388. MyTime.wSecond = 25;
  389. MyTime.wMilliseconds = 13;
  390. rc = GetTimeFormatW( Locale,
  391. 0,
  392. &MyTime,
  393. NULL,
  394. lpTimeStr,
  395. BUFSIZE );
  396. CheckReturnBadParam( rc,
  397. 0,
  398. ERROR_INVALID_PARAMETER,
  399. "bad wMinute",
  400. &NumErrors );
  401. // Variation 3 - bad wSecond
  402. MyTime.wYear = 1993;
  403. MyTime.wMonth = 5;
  404. MyTime.wDayOfWeek = 6;
  405. MyTime.wDay = 1;
  406. MyTime.wHour = 15;
  407. MyTime.wMinute = 45;
  408. MyTime.wSecond = 60;
  409. MyTime.wMilliseconds = 13;
  410. rc = GetTimeFormatW( Locale,
  411. 0,
  412. &MyTime,
  413. NULL,
  414. lpTimeStr,
  415. BUFSIZE );
  416. CheckReturnBadParam( rc,
  417. 0,
  418. ERROR_INVALID_PARAMETER,
  419. "bad wSecond",
  420. &NumErrors );
  421. // Variation 4 - bad wMilliseconds
  422. MyTime.wYear = 1993;
  423. MyTime.wMonth = 5;
  424. MyTime.wDayOfWeek = 6;
  425. MyTime.wDay = 1;
  426. MyTime.wHour = 15;
  427. MyTime.wMinute = 45;
  428. MyTime.wSecond = 25;
  429. MyTime.wMilliseconds = 1000;
  430. rc = GetTimeFormatW( Locale,
  431. 0,
  432. &MyTime,
  433. NULL,
  434. lpTimeStr,
  435. BUFSIZE );
  436. CheckReturnBadParam( rc,
  437. 0,
  438. ERROR_INVALID_PARAMETER,
  439. "bad wMilliseconds",
  440. &NumErrors );
  441. //
  442. // Return total number of errors found.
  443. //
  444. return (NumErrors);
  445. }
  446. ////////////////////////////////////////////////////////////////////////////
  447. //
  448. // GTF_NormalCase
  449. //
  450. // This routine tests the normal cases of the API routine.
  451. //
  452. // 04-30-93 JulieB Created.
  453. ////////////////////////////////////////////////////////////////////////////
  454. int GTF_NormalCase()
  455. {
  456. int NumErrors = 0; // error count - to be returned
  457. int rc; // return code
  458. SYSTEMTIME MyTime; // structure to hold custom time
  459. int ctr; // loop counter
  460. #ifdef PERF
  461. DbgBreakPoint();
  462. #endif
  463. //
  464. // Locales.
  465. //
  466. // Variation 1 - System Default Locale
  467. rc = GetTimeFormatW( LOCALE_SYSTEM_DEFAULT,
  468. 0,
  469. NULL,
  470. NULL,
  471. lpTimeStr,
  472. BUFSIZE );
  473. CheckReturnEqual( rc,
  474. 0,
  475. "system default locale",
  476. &NumErrors );
  477. // Variation 2 - Current User Locale
  478. rc = GetTimeFormatW( LOCALE_USER_DEFAULT,
  479. 0,
  480. NULL,
  481. NULL,
  482. lpTimeStr,
  483. BUFSIZE );
  484. CheckReturnEqual( rc,
  485. 0,
  486. "current user locale",
  487. &NumErrors );
  488. //
  489. // Language Neutral.
  490. //
  491. // Variation 1 - neutral
  492. rc = GetTimeFormatW( 0x0000,
  493. 0,
  494. &SysTime,
  495. NULL,
  496. lpTimeStr,
  497. BUFSIZE );
  498. CheckReturnValidW( rc,
  499. -1,
  500. lpTimeStr,
  501. ENGLISH_US,
  502. "neutral locale",
  503. &NumErrors );
  504. // Variation 2 - sys default
  505. rc = GetTimeFormatW( 0x0400,
  506. 0,
  507. &SysTime,
  508. NULL,
  509. lpTimeStr,
  510. BUFSIZE );
  511. CheckReturnValidW( rc,
  512. -1,
  513. lpTimeStr,
  514. ENGLISH_US,
  515. "sys default locale",
  516. &NumErrors );
  517. // Variation 3 - user default
  518. rc = GetTimeFormatW( 0x0800,
  519. 0,
  520. &SysTime,
  521. NULL,
  522. lpTimeStr,
  523. BUFSIZE );
  524. CheckReturnValidW( rc,
  525. -1,
  526. lpTimeStr,
  527. ENGLISH_US,
  528. "user default locale",
  529. &NumErrors );
  530. // Variation 4 - sub lang neutral US
  531. rc = GetTimeFormatW( 0x0009,
  532. 0,
  533. &SysTime,
  534. NULL,
  535. lpTimeStr,
  536. BUFSIZE );
  537. CheckReturnValidW( rc,
  538. -1,
  539. lpTimeStr,
  540. ENGLISH_US,
  541. "sub lang neutral US",
  542. &NumErrors );
  543. // Variation 5 - sub lang neutral Czech
  544. rc = GetTimeFormatW( 0x0005,
  545. 0,
  546. &SysTime,
  547. NULL,
  548. lpTimeStr,
  549. BUFSIZE );
  550. CheckReturnValidW( rc,
  551. -1,
  552. lpTimeStr,
  553. CZECH,
  554. "sub lang neutral Czech",
  555. &NumErrors );
  556. //
  557. // Use CP ACP.
  558. //
  559. // Variation 1 - Use CP ACP, System Default Locale
  560. rc = GetTimeFormatW( LOCALE_SYSTEM_DEFAULT,
  561. LOCALE_USE_CP_ACP,
  562. NULL,
  563. NULL,
  564. lpTimeStr,
  565. BUFSIZE );
  566. CheckReturnEqual( rc,
  567. 0,
  568. "Use CP ACP, system default locale",
  569. &NumErrors );
  570. //
  571. // cchTime.
  572. //
  573. // Variation 1 - cchTime = size of lpTimeStr buffer
  574. rc = GetTimeFormatW( Locale,
  575. 0,
  576. &SysTime,
  577. NULL,
  578. lpTimeStr,
  579. BUFSIZE );
  580. CheckReturnValidW( rc,
  581. -1,
  582. lpTimeStr,
  583. ENGLISH_US,
  584. "cchTime = bufsize",
  585. &NumErrors );
  586. // Variation 2 - cchTime = 0
  587. lpTimeStr[0] = 0x0000;
  588. rc = GetTimeFormatW( Locale,
  589. 0,
  590. &SysTime,
  591. NULL,
  592. lpTimeStr,
  593. 0 );
  594. CheckReturnValidW( rc,
  595. -1,
  596. NULL,
  597. ENGLISH_US,
  598. "cchTime zero",
  599. &NumErrors );
  600. // Variation 3 - cchTime = 0, lpTimeStr = NULL
  601. rc = GetTimeFormatW( Locale,
  602. 0,
  603. &SysTime,
  604. NULL,
  605. NULL,
  606. 0 );
  607. CheckReturnValidW( rc,
  608. -1,
  609. NULL,
  610. ENGLISH_US,
  611. "cchTime (NULL ptr)",
  612. &NumErrors );
  613. //
  614. // lpFormat.
  615. //
  616. // Variation 1 - AM/PM
  617. rc = GetTimeFormatW( 0x0409,
  618. 0,
  619. &SysTime,
  620. L"tt hh:mm:ss",
  621. lpTimeStr,
  622. BUFSIZE );
  623. CheckReturnValidW( rc,
  624. -1,
  625. lpTimeStr,
  626. L"AM 03:45:25",
  627. "lpFormat AM/PM (tt hh:mm:ss)",
  628. &NumErrors );
  629. // Variation 2 - AM/PM
  630. rc = GetTimeFormatW( 0x0409,
  631. TIME_NOTIMEMARKER,
  632. &SysTime,
  633. L"tt hh:mm:ss",
  634. lpTimeStr,
  635. BUFSIZE );
  636. CheckReturnValidW( rc,
  637. -1,
  638. lpTimeStr,
  639. L"03:45:25",
  640. "lpFormat NoTimeMarker (tt hh:mm:ss)",
  641. &NumErrors );
  642. // Variation 3 - AM/PM
  643. rc = GetTimeFormatW( 0x0409,
  644. TIME_NOTIMEMARKER | TIME_NOSECONDS,
  645. &SysTime,
  646. L"tt hh:mm:ss",
  647. lpTimeStr,
  648. BUFSIZE );
  649. CheckReturnValidW( rc,
  650. -1,
  651. lpTimeStr,
  652. L"03:45",
  653. "lpFormat NoTimeMarker, NoSeconds (tt hh:mm:ss)",
  654. &NumErrors );
  655. // Variation 4 - AM/PM
  656. rc = GetTimeFormatW( 0x0409,
  657. TIME_NOTIMEMARKER | TIME_NOMINUTESORSECONDS,
  658. &SysTime,
  659. L"tt hh:mm:ss",
  660. lpTimeStr,
  661. BUFSIZE );
  662. CheckReturnValidW( rc,
  663. -1,
  664. lpTimeStr,
  665. L"03",
  666. "lpFormat NoTimeMarker, NoMinutesOrSeconds (tt hh:mm:ss)",
  667. &NumErrors );
  668. // Variation 5 - AM/PM
  669. rc = GetTimeFormatW( 0x0409,
  670. TIME_NOMINUTESORSECONDS,
  671. &SysTime,
  672. L"tt hh:mm:ss",
  673. lpTimeStr,
  674. BUFSIZE );
  675. CheckReturnValidW( rc,
  676. -1,
  677. lpTimeStr,
  678. L"AM 03",
  679. "lpFormat NoMinutesOrSeconds (tt hh:mm:ss)",
  680. &NumErrors );
  681. // Variation 6 - Extra h, m, s
  682. rc = GetTimeFormatW( 0x0409,
  683. 0,
  684. &SysTime,
  685. L"hhh:mmm:sss",
  686. lpTimeStr,
  687. BUFSIZE );
  688. CheckReturnValidW( rc,
  689. -1,
  690. lpTimeStr,
  691. L"03:45:25",
  692. "lpFormat (hhh:mmm:sss)",
  693. &NumErrors );
  694. // Variation 7 - Extra H, m, s
  695. rc = GetTimeFormatW( 0x0409,
  696. 0,
  697. &SysTime2,
  698. L"HHH:mmm:sss",
  699. lpTimeStr,
  700. BUFSIZE );
  701. CheckReturnValidW( rc,
  702. -1,
  703. lpTimeStr,
  704. L"15:45:25",
  705. "lpFormat (HHH:mmm:sss)",
  706. &NumErrors );
  707. // Variation 8 - h:m:s
  708. MyTime.wHour = 15;
  709. MyTime.wMinute = 4;
  710. MyTime.wSecond = 5;
  711. MyTime.wMilliseconds = 13;
  712. rc = GetTimeFormatW( 0x0409,
  713. 0,
  714. &MyTime,
  715. L"h:m:s",
  716. lpTimeStr,
  717. BUFSIZE );
  718. CheckReturnValidW( rc,
  719. -1,
  720. lpTimeStr,
  721. L"3:4:5",
  722. "lpFormat (h:m:s)",
  723. &NumErrors );
  724. // Variation 9 - H:m:s
  725. MyTime.wHour = 15;
  726. MyTime.wMinute = 4;
  727. MyTime.wSecond = 5;
  728. MyTime.wMilliseconds = 13;
  729. rc = GetTimeFormatW( 0x0409,
  730. 0,
  731. &MyTime,
  732. L"H:m:s",
  733. lpTimeStr,
  734. BUFSIZE );
  735. CheckReturnValidW( rc,
  736. -1,
  737. lpTimeStr,
  738. L"15:4:5",
  739. "lpFormat (H:m:s)",
  740. &NumErrors );
  741. // Variation 10 - single quote
  742. MyTime.wHour = 15;
  743. MyTime.wMinute = 4;
  744. MyTime.wSecond = 5;
  745. MyTime.wMilliseconds = 13;
  746. rc = GetTimeFormatW( 0x0409,
  747. 0,
  748. &MyTime,
  749. L"h 'oclock'",
  750. lpTimeStr,
  751. BUFSIZE );
  752. CheckReturnValidW( rc,
  753. -1,
  754. lpTimeStr,
  755. L"3 oclock",
  756. "lpFormat (h 'oclock')",
  757. &NumErrors );
  758. // Variation 11 - single quote
  759. MyTime.wHour = 15;
  760. MyTime.wMinute = 4;
  761. MyTime.wSecond = 5;
  762. MyTime.wMilliseconds = 13;
  763. rc = GetTimeFormatW( 0x0409,
  764. 0,
  765. &MyTime,
  766. L"h 'o''clock' tt",
  767. lpTimeStr,
  768. BUFSIZE );
  769. CheckReturnValidW( rc,
  770. -1,
  771. lpTimeStr,
  772. L"3 o'clock PM",
  773. "lpFormat (h 'o''clock' tt)",
  774. &NumErrors );
  775. //
  776. // Flag values.
  777. //
  778. // Variation 1 - NOUSEROVERRIDE
  779. rc = GetTimeFormatW( Locale,
  780. LOCALE_NOUSEROVERRIDE,
  781. &SysTime,
  782. NULL,
  783. lpTimeStr,
  784. BUFSIZE );
  785. CheckReturnValidW( rc,
  786. -1,
  787. lpTimeStr,
  788. ENGLISH_US,
  789. "NoUserOverride",
  790. &NumErrors );
  791. // Variation 2 - US NOMINUTESORSECONDS
  792. rc = GetTimeFormatW( Locale,
  793. TIME_NOMINUTESORSECONDS,
  794. &SysTime,
  795. NULL,
  796. lpTimeStr,
  797. BUFSIZE );
  798. CheckReturnValidW( rc,
  799. -1,
  800. lpTimeStr,
  801. US_NOMINSEC,
  802. "US NoMinutesOrSeconds",
  803. &NumErrors );
  804. // Variation 3 - US NOSECONDS
  805. rc = GetTimeFormatW( Locale,
  806. TIME_NOSECONDS,
  807. &SysTime,
  808. NULL,
  809. lpTimeStr,
  810. BUFSIZE );
  811. CheckReturnValidW( rc,
  812. -1,
  813. lpTimeStr,
  814. US_NOSEC,
  815. "US NoSeconds",
  816. &NumErrors );
  817. // Variation 4 - US NOMINUTESORSECONDS and NOSECONDS
  818. rc = GetTimeFormatW( Locale,
  819. TIME_NOMINUTESORSECONDS | TIME_NOSECONDS,
  820. &SysTime,
  821. NULL,
  822. lpTimeStr,
  823. BUFSIZE );
  824. CheckReturnValidW( rc,
  825. -1,
  826. lpTimeStr,
  827. US_NOMINSEC,
  828. "US NoMinutesOrSeconds, NoSeconds",
  829. &NumErrors );
  830. // Variation 5 - US NOTIMEMARKER
  831. rc = GetTimeFormatW( Locale,
  832. TIME_NOTIMEMARKER,
  833. &SysTime,
  834. NULL,
  835. lpTimeStr,
  836. BUFSIZE );
  837. CheckReturnValidW( rc,
  838. -1,
  839. lpTimeStr,
  840. US_NOTM,
  841. "US NoTimeMarker",
  842. &NumErrors );
  843. // Variation 6 - US NOTIMEMARKER and NOMINUTESORSECONDS
  844. rc = GetTimeFormatW( Locale,
  845. TIME_NOTIMEMARKER | TIME_NOMINUTESORSECONDS,
  846. &SysTime,
  847. NULL,
  848. lpTimeStr,
  849. BUFSIZE );
  850. CheckReturnValidW( rc,
  851. -1,
  852. lpTimeStr,
  853. US_NOTM_NOMINSEC,
  854. "US NoTimeMarker, NoMinutesOrSeconds",
  855. &NumErrors );
  856. // Variation 7 - US NOTIMEMARKER and NOSECONDS
  857. rc = GetTimeFormatW( Locale,
  858. TIME_NOTIMEMARKER | TIME_NOSECONDS,
  859. &SysTime,
  860. NULL,
  861. lpTimeStr,
  862. BUFSIZE );
  863. CheckReturnValidW( rc,
  864. -1,
  865. lpTimeStr,
  866. US_NOTM_NOSEC,
  867. "US NoTimeMarker, NoSeconds",
  868. &NumErrors );
  869. // Variation 8 - US NOTIMEMARKER and NOMINUTESORSECONDS and NOSECONDS
  870. rc = GetTimeFormatW( Locale,
  871. TIME_NOTIMEMARKER | TIME_NOMINUTESORSECONDS | TIME_NOSECONDS,
  872. &SysTime,
  873. NULL,
  874. lpTimeStr,
  875. BUFSIZE );
  876. CheckReturnValidW( rc,
  877. -1,
  878. lpTimeStr,
  879. US_NOTM_NOMINSEC,
  880. "US NoTimeMarker, NoMinutesOrSeconds, NoSeconds",
  881. &NumErrors );
  882. // Variation 9 - CZECH NOMINUTESORSECONDS
  883. rc = GetTimeFormatW( 0x0405,
  884. TIME_NOMINUTESORSECONDS,
  885. &SysTime,
  886. NULL,
  887. lpTimeStr,
  888. BUFSIZE );
  889. CheckReturnValidW( rc,
  890. -1,
  891. lpTimeStr,
  892. CZECH_NOMINSEC,
  893. "Czech NoMinutesOrSeconds",
  894. &NumErrors );
  895. // Variation 10 - CZECH NOSECONDS
  896. rc = GetTimeFormatW( 0x0405,
  897. TIME_NOSECONDS,
  898. &SysTime,
  899. NULL,
  900. lpTimeStr,
  901. BUFSIZE );
  902. CheckReturnValidW( rc,
  903. -1,
  904. lpTimeStr,
  905. CZECH_NOSEC,
  906. "Czech NoSeconds",
  907. &NumErrors );
  908. // Variation 11 - CZECH NOMINUTESORSECONDS and NOSECONDS
  909. rc = GetTimeFormatW( 0x0405,
  910. TIME_NOMINUTESORSECONDS | TIME_NOSECONDS,
  911. &SysTime,
  912. NULL,
  913. lpTimeStr,
  914. BUFSIZE );
  915. CheckReturnValidW( rc,
  916. -1,
  917. lpTimeStr,
  918. CZECH_NOMINSEC,
  919. "Czech NoMinutesOrSeconds, NoSeconds",
  920. &NumErrors );
  921. // Variation 12 - CZECH NOTIMEMARKER
  922. rc = GetTimeFormatW( 0x0405,
  923. TIME_NOTIMEMARKER,
  924. &SysTime,
  925. NULL,
  926. lpTimeStr,
  927. BUFSIZE );
  928. CheckReturnValidW( rc,
  929. -1,
  930. lpTimeStr,
  931. CZECH_NOTM,
  932. "Czech NoTimeMarker",
  933. &NumErrors );
  934. // Variation 13 - CZECH NOTIMEMARKER and NOMINUTESORSECONDS
  935. rc = GetTimeFormatW( 0x0405,
  936. TIME_NOTIMEMARKER | TIME_NOMINUTESORSECONDS,
  937. &SysTime,
  938. NULL,
  939. lpTimeStr,
  940. BUFSIZE );
  941. CheckReturnValidW( rc,
  942. -1,
  943. lpTimeStr,
  944. CZECH_NOTM_NOMINSEC,
  945. "Czech NoTimeMarker, NoMinutesOrSeconds",
  946. &NumErrors );
  947. // Variation 14 - CZECH NOTIMEMARKER and NOSECONDS
  948. rc = GetTimeFormatW( 0x0405,
  949. TIME_NOTIMEMARKER | TIME_NOSECONDS,
  950. &SysTime,
  951. NULL,
  952. lpTimeStr,
  953. BUFSIZE );
  954. CheckReturnValidW( rc,
  955. -1,
  956. lpTimeStr,
  957. CZECH_NOTM_NOSEC,
  958. "Czech NoTimeMarker, NoSeconds",
  959. &NumErrors );
  960. // Variation 15 - CZECH NOTIMEMARKER and NOMINUTESORSECONDS and NOSECONDS
  961. rc = GetTimeFormatW( 0x0405,
  962. TIME_NOTIMEMARKER | TIME_NOMINUTESORSECONDS | TIME_NOSECONDS,
  963. &SysTime,
  964. NULL,
  965. lpTimeStr,
  966. BUFSIZE );
  967. CheckReturnValidW( rc,
  968. -1,
  969. lpTimeStr,
  970. CZECH_NOTM_NOMINSEC,
  971. "Czech NoTimeMarker, NoMinutesOrSeconds, NoSeconds",
  972. &NumErrors );
  973. // Variation 16 - US FORCE24HOURFORMAT
  974. rc = GetTimeFormatW( Locale,
  975. TIME_FORCE24HOURFORMAT,
  976. &SysTime,
  977. NULL,
  978. lpTimeStr,
  979. BUFSIZE );
  980. CheckReturnValidW( rc,
  981. -1,
  982. lpTimeStr,
  983. US_24HR,
  984. "US Force24HourFormat 1",
  985. &NumErrors );
  986. // Variation 17 - US FORCE24HOURFORMAT
  987. rc = GetTimeFormatW( Locale,
  988. TIME_FORCE24HOURFORMAT,
  989. &SysTime2,
  990. NULL,
  991. lpTimeStr,
  992. BUFSIZE );
  993. CheckReturnValidW( rc,
  994. -1,
  995. lpTimeStr,
  996. US_24HR_2,
  997. "US Force24HourFormat 2",
  998. &NumErrors );
  999. // Variation 18 - CZECH FORCE24HOURFORMAT
  1000. rc = GetTimeFormatW( 0x0405,
  1001. TIME_FORCE24HOURFORMAT,
  1002. &SysTime,
  1003. NULL,
  1004. lpTimeStr,
  1005. BUFSIZE );
  1006. CheckReturnValidW( rc,
  1007. -1,
  1008. lpTimeStr,
  1009. CZECH_24HR,
  1010. "Czech Force24HourFormat",
  1011. &NumErrors );
  1012. // Variation 19 - CZECH FORCE24HOURFORMAT
  1013. rc = GetTimeFormatW( 0x0405,
  1014. TIME_FORCE24HOURFORMAT,
  1015. &SysTime2,
  1016. NULL,
  1017. lpTimeStr,
  1018. BUFSIZE );
  1019. CheckReturnValidW( rc,
  1020. -1,
  1021. lpTimeStr,
  1022. CZECH_24HR_2,
  1023. "Czech Force24HourFormat 2",
  1024. &NumErrors );
  1025. //
  1026. // Test all locales - 3:45:25 AM
  1027. //
  1028. for (ctr = 0; ctr < NumLocales; ctr++)
  1029. {
  1030. rc = GetTimeFormatW( pAllLocales[ctr],
  1031. 0,
  1032. &SysTime,
  1033. NULL,
  1034. lpTimeStr,
  1035. BUFSIZE );
  1036. CheckReturnValidLoopW( rc,
  1037. -1,
  1038. lpTimeStr,
  1039. pTimeAM[ctr],
  1040. "Time AM",
  1041. pAllLocales[ctr],
  1042. &NumErrors );
  1043. }
  1044. //
  1045. // Test all locales - 3:45:25 PM
  1046. //
  1047. for (ctr = 0; ctr < NumLocales; ctr++)
  1048. {
  1049. rc = GetTimeFormatW( pAllLocales[ctr],
  1050. 0,
  1051. &SysTime2,
  1052. NULL,
  1053. lpTimeStr,
  1054. BUFSIZE );
  1055. CheckReturnValidLoopW( rc,
  1056. -1,
  1057. lpTimeStr,
  1058. pTimePM[ctr],
  1059. "Time PM",
  1060. pAllLocales[ctr],
  1061. &NumErrors );
  1062. }
  1063. //
  1064. // System Time.
  1065. //
  1066. // NOTE: For this test, must use a locale that has the same length
  1067. // for both the AM and PM, since I don't check if the test
  1068. // is run in the AM or PM.
  1069. //
  1070. // Variation 1 - Danish system time
  1071. rc = GetTimeFormatW( 0x0406,
  1072. 0,
  1073. NULL,
  1074. NULL,
  1075. lpTimeStr,
  1076. BUFSIZE );
  1077. CheckReturnValidW( rc,
  1078. -1,
  1079. NULL,
  1080. DANISH,
  1081. "Danish System Time",
  1082. &NumErrors );
  1083. //
  1084. // Return total number of errors found.
  1085. //
  1086. return (NumErrors);
  1087. }
  1088. ////////////////////////////////////////////////////////////////////////////
  1089. //
  1090. // GTF_Ansi
  1091. //
  1092. // This routine tests the Ansi version of the API routine.
  1093. //
  1094. // 04-30-93 JulieB Created.
  1095. ////////////////////////////////////////////////////////////////////////////
  1096. int GTF_Ansi()
  1097. {
  1098. int NumErrors = 0; // error count - to be returned
  1099. int rc; // return code
  1100. SYSTEMTIME MyTime; // structure to hold custom time
  1101. BYTE pTimeStrA[BUFSIZE]; // ptr to time string
  1102. MyTime.wYear = 1993;
  1103. MyTime.wMonth = 5;
  1104. MyTime.wDayOfWeek = 6;
  1105. MyTime.wDay = 1;
  1106. MyTime.wHour = 15;
  1107. MyTime.wMinute = 4;
  1108. MyTime.wSecond = 5;
  1109. MyTime.wMilliseconds = 13;
  1110. //
  1111. // GetTimeFormatA
  1112. //
  1113. // Variation 1 - AM/PM
  1114. rc = GetTimeFormatA( 0x0409,
  1115. 0,
  1116. &MyTime,
  1117. "tt hh:mm:ss",
  1118. pTimeStrA,
  1119. BUFSIZE );
  1120. CheckReturnValidA( rc,
  1121. -1,
  1122. pTimeStrA,
  1123. "PM 03:04:05",
  1124. NULL,
  1125. "A version (tt hh:mm:ss)",
  1126. &NumErrors );
  1127. // Variation 2 - AM/PM (no dest)
  1128. rc = GetTimeFormatA( 0x0409,
  1129. 0,
  1130. &MyTime,
  1131. "tt hh:mm:ss",
  1132. NULL,
  1133. 0 );
  1134. CheckReturnValidA( rc,
  1135. -1,
  1136. NULL,
  1137. "PM 03:04:05",
  1138. NULL,
  1139. "A version (tt hh:mm:ss), no Dest",
  1140. &NumErrors );
  1141. //
  1142. // Use CP ACP.
  1143. //
  1144. // Variation 1 - Use CP ACP, AM/PM
  1145. rc = GetTimeFormatA( 0x0409,
  1146. LOCALE_USE_CP_ACP,
  1147. &MyTime,
  1148. "tt hh:mm:ss",
  1149. pTimeStrA,
  1150. BUFSIZE );
  1151. CheckReturnValidA( rc,
  1152. -1,
  1153. pTimeStrA,
  1154. "PM 03:04:05",
  1155. NULL,
  1156. "A version Use CP ACP (tt hh:mm:ss)",
  1157. &NumErrors );
  1158. //
  1159. // Return total number of errors found.
  1160. //
  1161. return (NumErrors);
  1162. }