dat_mbtowc.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. /*
  2. * TEST SUITE FOR MB/WC FUNCTIONS IN C LIBRARY
  3. *
  4. * FILE: dat_mbtowc.c
  5. *
  6. * MBTOWC: int mbtowc (wchar_t *wp, char *s, size_t n);
  7. */
  8. /* NOTE:
  9. *
  10. * int mbtowc (wchar_t *wp, char *s, size_t n);
  11. *
  12. * where n: a maximum number of bytes
  13. * return: the number of bytes
  14. *
  15. *
  16. * o When you feed a null pointer for a string (s) to the function,
  17. * set s_flg=0 instead of putting just a 'NULL' there.
  18. * Even if you put a 'NULL', it means a null string as well as "".
  19. *
  20. * o When s is a null pointer, the function checks state dependency.
  21. *
  22. * state-dependent encoding - return NON-zero
  23. * state-independent encoding - return 0
  24. *
  25. * If state-dependent encoding is expected, set
  26. *
  27. * s_flg = 0, ret_flg = 0, ret_val = +1
  28. *
  29. * If state-independent encoding is expected, set
  30. *
  31. * s_flg = 0, ret_flg = 0, ret_val = 0
  32. *
  33. *
  34. * When you set ret_flg=1, the test program simply compares
  35. * an actual return value with an expected value. You can
  36. * check state-independent case (return value is 0) in that
  37. * way, but you can not check state-dependent case. So when
  38. * you check state- dependency in this test function:
  39. * tst_mbtowc(), set ret_flg=0 always. It's a special case
  40. * and the test function takes care of it.
  41. *
  42. * w_flg
  43. * | s: (a null string; can't be (char *)NULL)
  44. * | |
  45. * input. { 1, 0, (char)NULL, MB_LEN_MAX },
  46. * |
  47. * s_flg=0: makes _s_ a null pointer.
  48. *
  49. * expect { 0,0,0,x, 0x0000 },
  50. * | |
  51. * | ret_val: 0/+1
  52. * ret_flg=0
  53. *
  54. *
  55. * Test data for State dependent encodings:
  56. *
  57. * mbtowc( NULL, NULL, 0 ); ... first data
  58. * mbtowc( &wc, s1, n1 ); ... second data
  59. * mbtowc( &wc, s2, n2 ); ... third data
  60. * */
  61. #include <limits.h>
  62. TST_MBTOWC tst_mbtowc_loc [] = {
  63. {
  64. { Tmbtowc, TST_LOC_de },
  65. {
  66. { /*----------------- #01 -----------------*/
  67. {
  68. {
  69. { 1, 1, "\xfc\xe4\xf6", 1 },
  70. { 1, 1, "\xfc\xe4\xf6", 2 },
  71. { 1, 1, "\xfc\xe4\xf6", MB_LEN_MAX },
  72. }
  73. },
  74. {
  75. {
  76. { 0, 1, 1, 0x00FC },
  77. { 0, 1, 1, 0x00FC },
  78. { 0, 1, 1, 0x00FC },
  79. }
  80. }
  81. },
  82. { /*----------------- #02 -----------------*/
  83. {
  84. {
  85. { 1, 1, "\177", MB_LEN_MAX },
  86. { 1, 1, "\200", MB_LEN_MAX },
  87. { 1, 1, "\201", MB_LEN_MAX },
  88. }
  89. },
  90. {
  91. {
  92. { 0, 1, 1, 0x007F },
  93. { 0, 1, 1, 0x0080 },
  94. { 0, 1, 1, 0x0081 },
  95. }
  96. }
  97. },
  98. { /*----------------- #03 -----------------*/
  99. {
  100. {
  101. { 1, 1, "", MB_LEN_MAX },
  102. { 0, 1, "\xfc\xe4\xf6", 1 },
  103. { 0, 1, "\xfc\xe4\xf6", 2 },
  104. }
  105. },
  106. {
  107. {
  108. { 0, 1, 0, 0x0000 },
  109. { 0, 1, 1, 0x0000 },
  110. { 0, 1, 1, 0x0000 },
  111. }
  112. }
  113. },
  114. { /*----------------- #04 -----------------*/
  115. {
  116. {
  117. { 0, 1, "\xfc\xe4\xf6", MB_LEN_MAX },
  118. { 0, 1, "\177", MB_LEN_MAX },
  119. { 0, 1, "", MB_LEN_MAX },
  120. }
  121. },
  122. {
  123. {
  124. { 0, 1, 1, 0x0000 },
  125. { 0, 1, 1, 0x0000 },
  126. { 0, 1, 0, 0x0000 },
  127. }
  128. }
  129. },
  130. { /*----------------- #05 -----------------*/
  131. {
  132. {
  133. { 0, 1, "\xfc\xe4\xf6", MB_LEN_MAX },
  134. { 0, 1, "\177", MB_LEN_MAX },
  135. { 0, 0, NULL, MB_LEN_MAX },
  136. }
  137. },
  138. {
  139. {
  140. { 0, 1, 1, 0x0000 },
  141. { 0, 1, 1, 0x0000 },
  142. { 0, 0, 0, 0x0000 },
  143. }
  144. }
  145. },
  146. { .is_last = 1 }
  147. }
  148. },
  149. {
  150. { Tmbtowc, TST_LOC_enUS },
  151. {
  152. { /*----------------- #01 -----------------*/
  153. {
  154. {
  155. { 1, 1, "ABC", 1 },
  156. { 1, 1, "ABC", 2 },
  157. { 1, 1, "ABC", MB_LEN_MAX },
  158. }
  159. },
  160. {
  161. {
  162. { 0, 1, 1, 0x0041 },
  163. { 0, 1, 1, 0x0041 },
  164. { 0, 1, 1, 0x0041 },
  165. }
  166. }
  167. },
  168. { /*----------------- #02 -----------------*/
  169. {
  170. {
  171. { 1, 1, "\177", MB_LEN_MAX },
  172. { 1, 1, "\200", MB_LEN_MAX },
  173. { 1, 1, "\201", MB_LEN_MAX },
  174. }
  175. },
  176. {
  177. {
  178. { 0, 1, 1, 0x007F },
  179. { EILSEQ, 1, -1, 0x0000 },
  180. { EILSEQ, 1, -1, 0x0000 },
  181. }
  182. }
  183. },
  184. { /*----------------- #03 -----------------*/
  185. {
  186. {
  187. { 1, 1, "", MB_LEN_MAX },
  188. { 0, 1, "ABC", 1 },
  189. { 0, 1, "ABC", 2 },
  190. }
  191. },
  192. {
  193. {
  194. { 0, 1, 0, 0x0000 },
  195. { 0, 1, 1, 0x0000 },
  196. { 0, 1, 1, 0x0000 },
  197. }
  198. }
  199. },
  200. { /*----------------- #04 -----------------*/
  201. {
  202. {
  203. { 0, 1, "ABC", MB_LEN_MAX },
  204. { 0, 1, "\177", MB_LEN_MAX },
  205. { 0, 1, "", MB_LEN_MAX },
  206. }
  207. },
  208. {
  209. {
  210. { 0, 1, 1, 0x0000 },
  211. { 0, 1, 1, 0x0000 },
  212. { 0, 1, 0, 0x0000 },
  213. }
  214. }
  215. },
  216. { /*----------------- #05 -----------------*/
  217. {
  218. {
  219. { 0, 1, "ABC", MB_LEN_MAX },
  220. { 0, 1, "\177", MB_LEN_MAX },
  221. { 0, 0, NULL, MB_LEN_MAX },
  222. }
  223. },
  224. {
  225. {
  226. { 0, 1, 1, 0x0000 },
  227. { 0, 1, 1, 0x0000 },
  228. { 0, 0, 0, 0x0000 },
  229. }
  230. }
  231. },
  232. { .is_last = 1 }
  233. }
  234. },
  235. #if 0
  236. {
  237. { Tmbtowc, TST_LOC_eucJP },
  238. {
  239. { /*----------------- #01 -----------------*/
  240. {
  241. {
  242. { 1, 1, "\244\242A", 1 },
  243. { 1, 1, "\244\242A", 2 },
  244. { 1, 1, "\244\242A", MB_LEN_MAX },
  245. }
  246. },
  247. {
  248. {
  249. #ifdef SHOJI_IS_RIGHT
  250. { EILSEQ, 1, -1, 0x0000 },
  251. #else
  252. /* XXX EILSEQ was introduced in ISO C99. */
  253. { 0, 1, -1, 0x0000 },
  254. #endif
  255. { 0, 1, 2, 0x3042 },
  256. { 0, 1, 2, 0x3042 },
  257. }
  258. }
  259. },
  260. { /*----------------- #02 -----------------*/
  261. {
  262. {
  263. { 1, 1, "\177\244\242", MB_LEN_MAX },
  264. { 1, 1, "\377\244\242", MB_LEN_MAX },
  265. { 1, 1, "\201\244\242", MB_LEN_MAX },
  266. }
  267. },
  268. {
  269. {
  270. { 0, 1, +1, 0x007F },
  271. #ifdef SHOJI_IS_RIGHT
  272. { EILSEQ, 1, -1, 0x0000 },
  273. #else
  274. { 0, 1, -1, 0x0000 },
  275. #endif
  276. { 0, 1, +1, 0x0081 },
  277. }
  278. }
  279. },
  280. { /*----------------- #03 -----------------*/
  281. {
  282. {
  283. { 1, 1, "", MB_LEN_MAX },
  284. { 0, 1, "\244\242A", 1 },
  285. { 0, 1, "\244\242A", 2 },
  286. }
  287. },
  288. {
  289. {
  290. { 0, 1, 0, 0x0000 },
  291. #ifdef SHOJI_IS_RIGHT
  292. { EILSEQ, 1, -1, 0x0000 },
  293. #else
  294. /* XXX EILSEQ was introduced in ISO C99. */
  295. { 0, 1, -1, 0x0000 },
  296. #endif
  297. { 0, 1, 2, 0x0000 },
  298. }
  299. }
  300. },
  301. { /*----------------- #04 -----------------*/
  302. {
  303. {
  304. { 0, 1, "\244\242A", MB_LEN_MAX },
  305. { 0, 1, "\177\244\242", MB_LEN_MAX },
  306. { 0, 1, "", MB_LEN_MAX },
  307. }
  308. },
  309. {
  310. {
  311. { 0, 1, 2, 0x0000 },
  312. { 0, 1, +1, 0x0000 },
  313. { 0, 1, 0, 0x0000 },
  314. }
  315. }
  316. },
  317. { /*----------------- #05 -----------------*/
  318. {
  319. {
  320. { 0, 1, "\244\242A", MB_LEN_MAX },
  321. { 0, 1, "\177\244\242", MB_LEN_MAX },
  322. { 0, 0, NULL, MB_LEN_MAX },
  323. }
  324. },
  325. {
  326. {
  327. { 0, 1, 2, 0x0000 },
  328. { 0, 1, +1, 0x0000 },
  329. { 0, 0, 0, 0x0000 },
  330. }
  331. }
  332. },
  333. { .is_last = 1 }
  334. }
  335. },
  336. #else
  337. {
  338. { Tmbtowc, TST_LOC_ja_UTF8 },
  339. {
  340. { /*----------------- #01 -----------------*/
  341. {
  342. {
  343. { 1, 1, "\343\201\202A", 1 },
  344. { 1, 1, "\343\201\202A", 3 },
  345. { 1, 1, "\343\201\202A", MB_LEN_MAX },
  346. }
  347. },
  348. {
  349. {
  350. #ifdef SHOJI_IS_RIGHT
  351. { EILSEQ, 1, -1, 0x0000 },
  352. #else
  353. /* XXX EILSEQ was introduced in ISO C99. */
  354. { 0, 1, -1, 0x0000 },
  355. #endif
  356. { 0, 1, 3, 0x3042 },
  357. { 0, 1, 3, 0x3042 },
  358. }
  359. }
  360. },
  361. { /*----------------- #02 -----------------*/
  362. {
  363. {
  364. { 1, 1, "\177\343\201\202", MB_LEN_MAX },
  365. { 1, 1, "\377\343\201\202", MB_LEN_MAX },
  366. { 1, 1, "\302\201\343\201\202", MB_LEN_MAX },
  367. }
  368. },
  369. {
  370. {
  371. { 0, 1, +1, 0x007F },
  372. #ifdef SHOJI_IS_RIGHT
  373. { EILSEQ, 1, -1, 0x0000 },
  374. #else
  375. { 0, 1, -1, 0x0000 },
  376. #endif
  377. { 0, 1, +2, 0x0081 },
  378. }
  379. }
  380. },
  381. { /*----------------- #03 -----------------*/
  382. {
  383. {
  384. { 1, 1, "", MB_LEN_MAX },
  385. { 0, 1, "\343\201\202A", 1 },
  386. { 0, 1, "\343\201\202A", 3 },
  387. }
  388. },
  389. {
  390. {
  391. { 0, 1, 0, 0x0000 },
  392. #ifdef SHOJI_IS_RIGHT
  393. { EILSEQ, 1, -1, 0x0000 },
  394. #else
  395. /* XXX EILSEQ was introduced in ISO C99. */
  396. { 0, 1, -1, 0x0000 },
  397. #endif
  398. { 0, 1, 3, 0x0000 },
  399. }
  400. }
  401. },
  402. { /*----------------- #04 -----------------*/
  403. {
  404. {
  405. { 0, 1, "\343\201\202A", MB_LEN_MAX },
  406. { 0, 1, "\177\343\201\202", MB_LEN_MAX },
  407. { 0, 1, "", MB_LEN_MAX },
  408. }
  409. },
  410. {
  411. {
  412. { 0, 1, 3, 0x0000 },
  413. { 0, 1, +1, 0x0000 },
  414. { 0, 1, 0, 0x0000 },
  415. }
  416. }
  417. },
  418. { /*----------------- #05 -----------------*/
  419. {
  420. {
  421. { 0, 1, "\343\201\202A", MB_LEN_MAX },
  422. { 0, 1, "\177\343\201\202", MB_LEN_MAX },
  423. { 0, 0, NULL, MB_LEN_MAX },
  424. }
  425. },
  426. {
  427. {
  428. { 0, 1, 3, 0x0000 },
  429. { 0, 1, +1, 0x0000 },
  430. { 0, 0, 0, 0x0000 },
  431. }
  432. }
  433. },
  434. { .is_last = 1 }
  435. }
  436. },
  437. #endif
  438. {
  439. { Tmbtowc, TST_LOC_end }
  440. }
  441. };