dat_wcstombs.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. /*
  2. * TEST SUITE FOR MB/WC FUNCTIONS IN C LIBRARY
  3. *
  4. * FILE: dat_wcstombs.c
  5. *
  6. * WCSTOMBS: size_t wcstombs (char *s, const wchar_t *ws, size_t n)
  7. */
  8. /*
  9. * CAUTION:
  10. * Do not use a value 0x01 for string data. The test program
  11. * uses it.
  12. *
  13. */
  14. TST_WCSTOMBS tst_wcstombs_loc [] = {
  15. {
  16. { Twcstombs, TST_LOC_de },
  17. {
  18. /* #01 : Any chars including a null char should not be stored in s. */
  19. { /*input.*/ { 1,1, { 0x00C4,0x00D6,0x00DC,0x0000 }, 0 },
  20. /*expect*/ { 0,1,0, "" },
  21. },
  22. /* #02 : Only one chars should be stored in s. No null termination. */
  23. { /*input.*/ { 1,1, { 0x00C4,0x00D6,0x00DC,0x0000 }, 1 },
  24. /*expect*/ { 0,1,1, "Ä" },
  25. },
  26. /* #03 : Only two chars should be stored in s. No null termination. */
  27. { /*input.*/ { 1,1, { 0x00C4,0x00D6,0x00DC,0x0000 }, 2 },
  28. /*expect*/ { 0,1,2, "ÄÖ" },
  29. },
  30. /* #04 : Only three chars should be stored in s. No null
  31. termination. */
  32. { /*input.*/ { 1,1, { 0x00C4,0x00D6,0x00DC,0x0000 }, 3 },
  33. /*expect*/ { 0,1,3, "ÄÖÜ" },
  34. },
  35. /* #05 : Only three chars should be stored in s with a null
  36. termination. */
  37. { /*input.*/ { 1,1, { 0x00C4,0x00D6,0x00DC,0x0000 }, 4 },
  38. /*expect*/ { 0,1,3, "ÄÖÜ" },
  39. },
  40. /* #06 : Only three chars should be stored in s with a null
  41. termination. */
  42. { /*input.*/ { 1,1, { 0x00C4,0x00D6,0x00DC,0x0000 }, 5 },
  43. /*expect*/ { 0,1,3, "ÄÖÜ" },
  44. },
  45. /* #07 : Invalid mb sequence. No chars should be stored in s. */
  46. { /*input.*/ { 1,1, { 0x0201,0x0221,0x0000,0x0000 }, 2 },
  47. /*expect*/ { EILSEQ,1,(size_t)-1, "" },
  48. },
  49. /* #08 : s is a null pointer, no chars should be stored in s. */
  50. { /*input.*/ { 0,1, { 0x00C4,0x00D6,0x00DC,0x0000 }, 0 },
  51. /*expect*/ { 0,1,3, "" },
  52. },
  53. /* #09 : s is a null pointer, no chars should be stored in s. */
  54. { /*input.*/ { 0,1, { 0x00C4,0x00D6,0x00DC,0x0000 }, 1 },
  55. /*expect*/ { 0,1,3, "" },
  56. },
  57. /* #10 : s is a null pointer, no chars should be stored in s. */
  58. { /*input.*/ { 0,1, { 0x00C4,0x00D6,0x00DC,0x0000 }, 5 },
  59. /*expect*/ { 0,1,3, "" },
  60. },
  61. /* #11 : s is a null pointer. No chars should be stored in s. */
  62. { /*input.*/ { 0,1, { 0x0201,0x0221,0x0000,0x0000 }, 5 },
  63. /*expect*/ { EILSEQ,1,(size_t)-1, "" },
  64. },
  65. /* #12 : ws is a null wc string, no chars should be stored in s. */
  66. { /*input.*/ { 1,1, { 0x0000 }, 5 },
  67. /*expect*/ { 0,1,0, "" },
  68. },
  69. /* #13 : s is a null pointer, no chars should be stored in s. */
  70. { /*input.*/ { 0,1, { 0x0000 }, 5 },
  71. /*expect*/ { 0,1,0, "" },
  72. },
  73. { .is_last = 1 }
  74. }
  75. },
  76. {
  77. { Twcstombs, TST_LOC_enUS },
  78. {
  79. /* #01 : Any chars including a null char should not be stored in s. */
  80. { /*input.*/ { 1,1, { 0x00C4,0x0042,0x0043,0x0000 }, 0 },
  81. /*expect*/ { 0,1,0, "" },
  82. },
  83. /* #02 : Only one chars should be stored in s. No null termination. */
  84. { /*input.*/ { 1,1, { 0x0041,0x0042,0x0043,0x0000 }, 1 },
  85. /*expect*/ { 0,1,1, "A" },
  86. },
  87. /* #03 : Only two chars should be stored in s. No null termination. */
  88. { /*input.*/ { 1,1, { 0x0041,0x0042,0x0043,0x0000 }, 2 },
  89. /*expect*/ { 0,1,2, "AB" },
  90. },
  91. /* #04 : Only three chars should be stored in s. No null
  92. termination. */
  93. { /*input.*/ { 1,1, { 0x0041,0x0042,0x0043,0x0000 }, 3 },
  94. /*expect*/ { 0,1,3, "ABC" },
  95. },
  96. /* #05 : Only three chars should be stored in s with a null
  97. termination. */
  98. { /*input.*/ { 1,1, { 0x0041,0x0042,0x0043,0x0000 }, 4 },
  99. /*expect*/ { 0,1,3, "ABC" },
  100. },
  101. /* #06 : Only three chars should be stored in s with a null
  102. termination. */
  103. { /*input.*/ { 1,1, { 0x0041,0x0042,0x0043,0x0000 }, 5 },
  104. /*expect*/ { 0,1,3, "ABC" },
  105. },
  106. /* #07 : Invalid mb sequence. No chars should be stored in s. */
  107. { /*input.*/ { 1,1, { 0x0201,0x0221,0x0000,0x0000 }, 2 },
  108. /*expect*/ { EILSEQ,1,(size_t)-1, "" },
  109. },
  110. /* #08 : s is a null pointer, no chars should be stored in s. */
  111. { /*input.*/ { 0,1, { 0x0041,0x0042,0x0043,0x0000 }, 0 },
  112. /*expect*/ { 0,1,3, "" },
  113. },
  114. /* #09 : s is a null pointer, no chars should be stored in s. */
  115. { /*input.*/ { 0,1, { 0x0041,0x0042,0x0043,0x0000 }, 1 },
  116. /*expect*/ { 0,1,3, "" },
  117. },
  118. /* #10 : s is a null pointer, no chars should be stored in s. */
  119. { /*input.*/ { 0,1, { 0x0041,0x0042,0x0043,0x0000 }, 5 },
  120. /*expect*/ { 0,1,3, "" },
  121. },
  122. /* #11 : s is a null pointer. No chars should be stored in s. */
  123. { /*input.*/ { 0,1, { 0x0201,0x0221,0x0000,0x0000 }, 5 },
  124. /*expect*/ { EILSEQ,1,(size_t)-1, "" },
  125. },
  126. /* #12 : ws is a null wc string, no chars should be stored in s. */
  127. { /*input.*/ { 1,1, { 0x0000 }, 5, },
  128. /*expect*/ { 0,1,0, "" },
  129. },
  130. /* #13 : s is a null pointer, no chars should be stored in s. */
  131. { /*input.*/ { 0,1, { 0x0000 }, 5 },
  132. /*expect*/ { 0,1,0, "" },
  133. },
  134. { .is_last = 1 }
  135. }
  136. },
  137. #if 0
  138. {
  139. { Twcstombs, TST_LOC_eucJP },
  140. {
  141. /* #01 : Any chars including a null char should not be stored in s. */
  142. { /*input.*/ { 1,1, { 0x3042,0x3044,0xFF73,0x0000 }, 0 },
  143. /*expect*/ { 0,1,0, "" },
  144. },
  145. /* #02 : Only one chars should be stored in s. No null termination. */
  146. { /*input.*/ { 1,1, { 0x3042,0x3044,0xFF73,0x0000 }, 2 },
  147. /*expect*/ { 0,1,2, "\244\242" },
  148. },
  149. /* #03 : Only two chars should be stored in s. No null termination. */
  150. { /*input.*/ { 1,1, { 0x3042,0x3044,0xFF73,0x0000 }, 4 },
  151. /*expect*/ { 0,1,4, "\244\242\244\244" },
  152. },
  153. /* #04 : Only three chars should be stored in s. No null
  154. termination. */
  155. { /*input.*/ { 1,1, { 0x3042,0x3044,0xFF73,0x0000 }, 6 },
  156. /*expect*/ { 0,1,6, "\244\242\244\244\216\263" },
  157. },
  158. /* #05 : Only three chars should be stored in s with a null
  159. termination. */
  160. { /*input.*/ { 1,1, { 0x3042,0x3044,0xFF73,0x0000 }, 7 },
  161. /*expect*/ { 0,1,6, "\244\242\244\244\216\263" },
  162. },
  163. /* #06 : Only three chars should be stored in s with a null
  164. termination. */
  165. { /*input.*/ { 1,1, { 0x3042,0x3044,0xFF73,0x0000 }, 8 },
  166. /*expect*/ { 0,1,6, "\244\242\244\244\216\263" },
  167. },
  168. /* #07 : Invalid mb sequence. No chars should be stored in s. */
  169. { /*input.*/ { 1,1, { 0x0201,0x0221,0x0000,0x0000 }, 2 },
  170. /*expect*/ { EILSEQ,1,-1, "" },
  171. },
  172. /* #08 : s is a null pointer, no chars should be stored in s. */
  173. { /*input.*/ { 0,1, { 0x3042,0x3044,0xFF73,0x0000 }, 0 },
  174. /*expect*/ { 0,1,6, "" },
  175. },
  176. /* #09 : s is a null pointer, no chars should be stored in s. */
  177. { /*input.*/ { 0,1, { 0x3042,0x3044,0xFF73,0x0000 }, 1 },
  178. /*expect*/ { 0,1,6, "" },
  179. },
  180. /* #10 : s is a null pointer, no chars should be stored in s. */
  181. { /*input.*/ { 0,1, { 0x3042,0x3044,0xFF73,0x0000 }, 8 },
  182. /*expect*/ { 0,1,6, "" },
  183. },
  184. /* #11 : s is a null pointer. No chars should be stored in s. */
  185. { /*input.*/ { 0,1, { 0x0201,0x0221,0x0000,0x0000 }, 5 },
  186. /*expect*/ { EILSEQ,1,(size_t)-1, "" },
  187. },
  188. /* #12 : ws is a null wc string, no chars should be stored in s. */
  189. { /*input.*/ { 1,1, { 0x0000 }, 5 },
  190. /*expect*/ { 0,1,0, "" },
  191. },
  192. /* #13 : s is a null pointer, no chars should be stored in s. */
  193. { /*input.*/ { 0,1, { 0x0000 }, 5 },
  194. /*expect*/ { 0,1,0, "" },
  195. },
  196. { .is_last = 1 }
  197. }
  198. },
  199. #else
  200. {
  201. { Twcstombs, TST_LOC_ja_UTF8 },
  202. {
  203. /* #01 : Any chars including a null char should not be stored in s. */
  204. { /*input.*/ { 1,1, { 0x3042,0x3044,0xFF73,0x0000 }, 0 },
  205. /*expect*/ { 0,1,0, "" },
  206. },
  207. /* #02 : Only one chars should be stored in s. No null termination. */
  208. { /*input.*/ { 1,1, { 0x3042,0x3044,0xFF73,0x0000 }, 3 },
  209. /*expect*/ { 0,1,3, "\343\201\202" },
  210. },
  211. /* #03 : Only two chars should be stored in s. No null termination. */
  212. { /*input.*/ { 1,1, { 0x3042,0x3044,0xFF73,0x0000 }, 6 },
  213. /*expect*/ { 0,1,6, "\343\201\202\343\201\204" },
  214. },
  215. /* #04 : Only three chars should be stored in s. No null
  216. termination. */
  217. { /*input.*/ { 1,1, { 0x3042,0x3044,0xFF73,0x0000 }, 9 },
  218. /*expect*/ { 0,1,9, "\343\201\202\343\201\204\357\275\263" },
  219. },
  220. /* #05 : Only three chars should be stored in s with a null
  221. termination. */
  222. { /*input.*/ { 1,1, { 0x3042,0x3044,0xFF73,0x0000 }, 10 },
  223. /*expect*/ { 0,1,9, "\343\201\202\343\201\204\357\275\263" },
  224. },
  225. /* #06 : Only three chars should be stored in s with a null
  226. termination. */
  227. { /*input.*/ { 1,1, { 0x3042,0x3044,0xFF73,0x0000 }, 11 },
  228. /*expect*/ { 0,1,9, "\343\201\202\343\201\204\357\275\263" },
  229. },
  230. /* #07 : Invalid mb sequence. No chars should be stored in s. */
  231. { /*input.*/ { 1,1, { 0x0201,0x0221,0x0000,0x0000 }, 2 },
  232. /*expect*/ { EILSEQ,1,-1, "" },
  233. },
  234. /* #08 : s is a null pointer, no chars should be stored in s. */
  235. { /*input.*/ { 0,1, { 0x3042,0x3044,0xFF73,0x0000 }, 0 },
  236. /*expect*/ { 0,1,9, "" },
  237. },
  238. /* #09 : s is a null pointer, no chars should be stored in s. */
  239. { /*input.*/ { 0,1, { 0x3042,0x3044,0xFF73,0x0000 }, 1 },
  240. /*expect*/ { 0,1,9, "" },
  241. },
  242. /* #10 : s is a null pointer, no chars should be stored in s. */
  243. { /*input.*/ { 0,1, { 0x3042,0x3044,0xFF73,0x0000 }, 8 },
  244. /*expect*/ { 0,1,9, "" },
  245. },
  246. /* #11 : s is a null pointer. No chars should be stored in s. */
  247. { /*input.*/ { 0,1, { 0x0201,0x0221,0x0000,0x0000 }, 5 },
  248. /*expect*/ { EILSEQ,1,(size_t)-1, "" },
  249. },
  250. /* #12 : ws is a null wc string, no chars should be stored in s. */
  251. { /*input.*/ { 1,1, { 0x0000 }, 5 },
  252. /*expect*/ { 0,1,0, "" },
  253. },
  254. /* #13 : s is a null pointer, no chars should be stored in s. */
  255. { /*input.*/ { 0,1, { 0x0000 }, 5 },
  256. /*expect*/ { 0,1,0, "" },
  257. },
  258. { .is_last = 1 }
  259. }
  260. },
  261. #endif
  262. {
  263. { Twcstombs, TST_LOC_end }
  264. }
  265. };