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.

442 lines
10 KiB

  1. /*++
  2. Copyright (c) 1991-1999, Microsoft Corporation All rights reserved.
  3. Module Name:
  4. dbtest.c
  5. Abstract:
  6. Test module for NLS API IsDBCSLeadByte and IsDBCSLeadByteEx.
  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. 06-14-91 JulieB Created.
  12. --*/
  13. //
  14. // Include Files.
  15. //
  16. #include "nlstest.h"
  17. //
  18. // Forward Declarations.
  19. //
  20. int
  21. DB_BadParamCheck();
  22. int
  23. DB_NormalCase();
  24. void
  25. CheckReturnIsDBCS(
  26. int CurrentReturn,
  27. int ExpectedReturn,
  28. LPSTR pErrString,
  29. int *pNumErrors);
  30. ////////////////////////////////////////////////////////////////////////////
  31. //
  32. // TestIsDBCSLeadByte
  33. //
  34. // Test routine for IsDBCSLeadByte API.
  35. //
  36. // 06-14-91 JulieB Created.
  37. ////////////////////////////////////////////////////////////////////////////
  38. int TestIsDBCSLeadByte()
  39. {
  40. int ErrCount = 0; // error count
  41. //
  42. // Print out what's being done.
  43. //
  44. printf("\n\nTESTING IsDBCSLeadByte and IsDBCSLeadByteEx...\n\n");
  45. //
  46. // Test bad parameters.
  47. //
  48. ErrCount += DB_BadParamCheck();
  49. //
  50. // Test normal cases.
  51. //
  52. ErrCount += DB_NormalCase();
  53. //
  54. // Print out result.
  55. //
  56. printf("\nIsDBCSLeadByte: ERRORS = %d\n", ErrCount);
  57. //
  58. // Return total number of errors found.
  59. //
  60. return (ErrCount);
  61. }
  62. ////////////////////////////////////////////////////////////////////////////
  63. //
  64. // DB_BadParamCheck
  65. //
  66. // This routine passes in bad parameters to the API routine and checks to
  67. // be sure they are handled properly. The number of errors encountered
  68. // is returned to the caller.
  69. //
  70. // 06-14-91 JulieB Created.
  71. ////////////////////////////////////////////////////////////////////////////
  72. int DB_BadParamCheck()
  73. {
  74. int NumErrors = 0; // error count - to be returned
  75. BYTE ch; // character to check
  76. BOOL rc; // return code
  77. //
  78. // Invalid Code Page.
  79. //
  80. // Variation 1 - CodePage = invalid
  81. ch = 0x00;
  82. rc = IsDBCSLeadByteEx(5, ch);
  83. CheckReturnBadParam( rc,
  84. FALSE,
  85. ERROR_INVALID_PARAMETER,
  86. "CodePage invalid",
  87. &NumErrors );
  88. //
  89. // Return total number of errors found.
  90. //
  91. return (NumErrors);
  92. }
  93. ////////////////////////////////////////////////////////////////////////////
  94. //
  95. // DB_NormalCase
  96. //
  97. // This routine tests the normal cases of the API routine.
  98. //
  99. // 06-14-91 JulieB Created.
  100. ////////////////////////////////////////////////////////////////////////////
  101. int DB_NormalCase()
  102. {
  103. int NumErrors = 0; // error count - to be returned
  104. BYTE ch; // character to check
  105. BOOL rc; // return code
  106. #ifdef PERF
  107. DbgBreakPoint();
  108. #endif
  109. //--------------------//
  110. // IsDBCSLeadByte //
  111. //--------------------//
  112. //
  113. // Different values for ch.
  114. //
  115. // Variation 1 - ch = 0x00
  116. ch = 0x00;
  117. rc = IsDBCSLeadByte(ch);
  118. CheckReturnIsDBCS( rc,
  119. FALSE,
  120. "ch = 0x00",
  121. &NumErrors );
  122. // Variation 2 - ch = 0x23
  123. ch = 0x23;
  124. rc = IsDBCSLeadByte(ch);
  125. CheckReturnIsDBCS( rc,
  126. FALSE,
  127. "ch = 0x23",
  128. &NumErrors );
  129. // Variation 3 - ch = 0xb3
  130. ch = 0xb3;
  131. rc = IsDBCSLeadByte(ch);
  132. CheckReturnIsDBCS( rc,
  133. FALSE,
  134. "ch = 0xb3",
  135. &NumErrors );
  136. // Variation 4 - ch = 0xff
  137. ch = 0xff;
  138. rc = IsDBCSLeadByte(ch);
  139. CheckReturnIsDBCS( rc,
  140. FALSE,
  141. "ch = 0xff",
  142. &NumErrors );
  143. #ifdef JDB
  144. //
  145. // DBCS Chars for Japanese - cp 932.
  146. //
  147. // Variation 1 - DBCS lead byte 0x81
  148. rc = IsDBCSLeadByte(0x81);
  149. CheckReturnIsDBCS( rc,
  150. TRUE,
  151. "DBCS 0x81",
  152. &NumErrors );
  153. // Variation 2 - DBCS lead byte 0x85
  154. rc = IsDBCSLeadByte(0x85);
  155. CheckReturnIsDBCS( rc,
  156. TRUE,
  157. "DBCS 0x85",
  158. &NumErrors );
  159. // Variation 3 - DBCS lead byte 0x9f
  160. rc = IsDBCSLeadByte(0x9f);
  161. CheckReturnIsDBCS( rc,
  162. TRUE,
  163. "DBCS 0x9f",
  164. &NumErrors );
  165. // Variation 4 - DBCS lead byte 0xe0
  166. rc = IsDBCSLeadByte(0xe0);
  167. CheckReturnIsDBCS( rc,
  168. TRUE,
  169. "DBCS 0xe0",
  170. &NumErrors );
  171. // Variation 5 - DBCS lead byte 0xfb
  172. rc = IsDBCSLeadByte(0xfb);
  173. CheckReturnIsDBCS( rc,
  174. TRUE,
  175. "DBCS 0xfb",
  176. &NumErrors );
  177. // Variation 6 - DBCS lead byte 0xfc
  178. rc = IsDBCSLeadByte(0xfc);
  179. CheckReturnIsDBCS( rc,
  180. TRUE,
  181. "DBCS 0xfc",
  182. &NumErrors );
  183. //
  184. // Non DBCS Chars for Japanese - cp 932.
  185. //
  186. // Variation 1 - Non DBCS lead byte 0x80
  187. CheckReturnIsDBCS( rc,
  188. FALSE,
  189. "Non DBCS lead byte 0x80",
  190. &NumErrors );
  191. // Variation 2 - Non DBCS lead byte 0xfd
  192. rc = IsDBCSLeadByte(0xfd);
  193. CheckReturnIsDBCS( rc,
  194. FALSE,
  195. "Non DBCS lead byte 0xfd",
  196. &NumErrors );
  197. // Variation 3 - Non DBCS lead byte 0xa0
  198. rc = IsDBCSLeadByte(0xa0);
  199. CheckReturnIsDBCS( rc,
  200. FALSE,
  201. "Non DBCS lead byte 0xa0",
  202. &NumErrors );
  203. // Variation 4 - Non DBCS lead byte 0xdf
  204. rc = IsDBCSLeadByte(0xdf);
  205. CheckReturnIsDBCS( rc,
  206. FALSE,
  207. "Non DBCS lead byte 0xdf",
  208. &NumErrors );
  209. #endif
  210. //--------------------//
  211. // IsDBCSLeadByteEx //
  212. //--------------------//
  213. //
  214. // Different values for ch.
  215. //
  216. // Variation 1 - ch = 0x00
  217. ch = 0x00;
  218. rc = IsDBCSLeadByteEx(1252, ch);
  219. CheckReturnIsDBCS( rc,
  220. FALSE,
  221. "Ex ch = 0x00",
  222. &NumErrors );
  223. // Variation 2 - ch = 0x23
  224. ch = 0x23;
  225. rc = IsDBCSLeadByteEx(1252, ch);
  226. CheckReturnIsDBCS( rc,
  227. FALSE,
  228. "Ex ch = 0x23",
  229. &NumErrors );
  230. // Variation 3 - ch = 0xb3
  231. ch = 0xb3;
  232. rc = IsDBCSLeadByteEx(1252, ch);
  233. CheckReturnIsDBCS( rc,
  234. FALSE,
  235. "Ex ch = 0xb3",
  236. &NumErrors );
  237. // Variation 4 - ch = 0xff
  238. ch = 0xff;
  239. rc = IsDBCSLeadByteEx(1252, ch);
  240. CheckReturnIsDBCS( rc,
  241. FALSE,
  242. "Ex ch = 0xff",
  243. &NumErrors );
  244. //
  245. // DBCS Chars for Japanese - cp 932.
  246. //
  247. // Variation 1 - DBCS lead byte 0x81
  248. rc = IsDBCSLeadByteEx(932, 0x81);
  249. CheckReturnIsDBCS( rc,
  250. TRUE,
  251. "Ex DBCS 0x81",
  252. &NumErrors );
  253. // Variation 2 - DBCS lead byte 0x85
  254. rc = IsDBCSLeadByteEx(932, 0x85);
  255. CheckReturnIsDBCS( rc,
  256. TRUE,
  257. "Ex DBCS 0x85",
  258. &NumErrors );
  259. // Variation 3 - DBCS lead byte 0x9f
  260. rc = IsDBCSLeadByteEx(932, 0x9f);
  261. CheckReturnIsDBCS( rc,
  262. TRUE,
  263. "Ex DBCS 0x9f",
  264. &NumErrors );
  265. // Variation 4 - DBCS lead byte 0xe0
  266. rc = IsDBCSLeadByteEx(932, 0xe0);
  267. CheckReturnIsDBCS( rc,
  268. TRUE,
  269. "Ex DBCS 0xe0",
  270. &NumErrors );
  271. // Variation 5 - DBCS lead byte 0xfb
  272. rc = IsDBCSLeadByteEx(932, 0xfb);
  273. CheckReturnIsDBCS( rc,
  274. TRUE,
  275. "Ex DBCS 0xfb",
  276. &NumErrors );
  277. // Variation 6 - DBCS lead byte 0xfc
  278. rc = IsDBCSLeadByteEx(932, 0xfc);
  279. CheckReturnIsDBCS( rc,
  280. TRUE,
  281. "Ex DBCS 0xfc",
  282. &NumErrors );
  283. //
  284. // Non DBCS Chars for Japanese - cp 932.
  285. //
  286. // Variation 1 - Non DBCS lead byte 0x80
  287. rc = IsDBCSLeadByteEx(932, 0x80);
  288. CheckReturnIsDBCS( rc,
  289. FALSE,
  290. "Ex Non DBCS lead byte 0x80",
  291. &NumErrors );
  292. // Variation 2 - Non DBCS lead byte 0xfd
  293. rc = IsDBCSLeadByteEx(932, 0xfd);
  294. CheckReturnIsDBCS( rc,
  295. FALSE,
  296. "Ex Non DBCS lead byte 0xfd",
  297. &NumErrors );
  298. // Variation 3 - Non DBCS lead byte 0xa0
  299. rc = IsDBCSLeadByteEx(932, 0xa0);
  300. CheckReturnIsDBCS( rc,
  301. FALSE,
  302. "Ex Non DBCS lead byte 0xa0",
  303. &NumErrors );
  304. // Variation 4 - Non DBCS lead byte 0xdf
  305. rc = IsDBCSLeadByteEx(932, 0xdf);
  306. CheckReturnIsDBCS( rc,
  307. FALSE,
  308. "Ex Non DBCS lead byte 0xdf",
  309. &NumErrors );
  310. //
  311. // Return total number of errors found.
  312. //
  313. return (NumErrors);
  314. }
  315. ////////////////////////////////////////////////////////////////////////////
  316. //
  317. // CheckReturnIsDBCS
  318. //
  319. // Checks the return code from the IsDBCSLeadByte call. It prints out
  320. // the appropriate error if the incorrect result is found.
  321. //
  322. // 06-14-91 JulieB Created.
  323. ////////////////////////////////////////////////////////////////////////////
  324. void CheckReturnIsDBCS(
  325. int CurrentReturn,
  326. int ExpectedReturn,
  327. LPSTR pErrString,
  328. int *pNumErrors)
  329. {
  330. if ( (CurrentReturn != ExpectedReturn) ||
  331. ( (CurrentReturn == FALSE) &&
  332. (GetLastError() == ERROR_FILE_NOT_FOUND) ) )
  333. {
  334. printf("ERROR: %s - \n", pErrString);
  335. printf(" Return = %d, Expected = %d\n", CurrentReturn, ExpectedReturn);
  336. (*pNumErrors)++;
  337. }
  338. }