dat_wctomb.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. * TEST SUITE FOR MB/WC FUNCTIONS IN C LIBRARY
  3. *
  4. * FILE: dat_wctomb.c
  5. *
  6. * WCTOMB: int wctomb (char *s, wchar_t wc)
  7. */
  8. /*
  9. * FUNCTION:
  10. *
  11. * int wctomb (char *s, wchar_t wc);
  12. *
  13. * return: the number of bytes
  14. *
  15. * NOTE:
  16. *
  17. * o When you feed a null pointer for a string (s) to the function,
  18. * set s_flg=0 instead of putting just a 'NULL' there.
  19. * Even if you put a 'NULL', it means a null string as well as "".
  20. *
  21. * o When s is a null pointer, the function checks state dependency.
  22. *
  23. * state-dependent encoding - return NON-zero
  24. * state-independent encoding - return 0
  25. *
  26. * If state-dependent encoding is expected, set
  27. *
  28. * s_flg = 0, ret_flg = 0, ret_val = +1
  29. *
  30. * If state-independent encoding is expected, set
  31. *
  32. * s_flg = 0, ret_flg = 0, ret_val = 0
  33. *
  34. *
  35. * When you set ret_flg=1, the test program simply compares an
  36. * actual return value with an expected value. You can check
  37. * state-independent case (return value is 0) in that way, but
  38. * you can not check state-dependent case. So when you check
  39. * state- dependency in this test function: tst_wctomb(), set
  40. * ret_flg=0 always. It's a special case, and the test
  41. * function takes care of it.
  42. *
  43. * Input Expect
  44. *
  45. * s_flg=0 ret_flg=0
  46. * | |
  47. * { 0, 0 }, { 0, 0, 0, x, "" }
  48. * | |
  49. * not used ret_val: 0/+1
  50. * (expected val)
  51. */
  52. TST_WCTOMB tst_wctomb_loc [] = {
  53. {
  54. { Twctomb, TST_LOC_de },
  55. {
  56. /* #01 : normal case */
  57. { /*input.*/ { 1, 0x00C4 },
  58. /*expect*/ { 0,1,1, "Ä" },
  59. },
  60. /* #02 : normal case */
  61. { /*input.*/ { 1, 0x00DC },
  62. /*expect*/ { 0,1,1, "Ü" },
  63. },
  64. /* #03 : normal case */
  65. { /*input.*/ { 1, 0x0092 },
  66. /*expect*/ { 0,1,1, "\222" },
  67. },
  68. /* #04 : error case */
  69. { /*input.*/ { 1, 0x3041 },
  70. /*expect*/ { 0,1,-1, "" },
  71. },
  72. /* #05 : state dependency */
  73. { /*input.*/ { 0, 0x0000 },
  74. /*expect*/ { 0,0,0, "" },
  75. },
  76. { .is_last = 1 }
  77. }
  78. },
  79. {
  80. { Twctomb, TST_LOC_enUS },
  81. {
  82. /* #01 : normal case */
  83. { /*input.*/ { 1, 0x0041 },
  84. /*expect*/ { 0,1,1, "A" },
  85. },
  86. /* #02 : normal case */
  87. { /*input.*/ { 1, 0x0042 },
  88. /*expect*/ { 0,1,1, "B" },
  89. },
  90. /* #03 : error case */
  91. /* <WAIVER> */
  92. { /*input.*/ { 1, 0x00C4 },
  93. /*expect*/ { 0,1,-1, "" },
  94. },
  95. /* #04 : error case */
  96. { /*input.*/ { 1, 0x30A4 },
  97. /*expect*/ { 0,1,-1, "" },
  98. },
  99. /* #05 : state dependency */
  100. { /*input.*/ { 0, 0x0000 },
  101. /*expect*/ { 0,0,0, "" },
  102. },
  103. { .is_last = 1 }
  104. }
  105. },
  106. #if 0
  107. {
  108. { Twctomb, TST_LOC_eucJP },
  109. {
  110. /* #01 : normal case */
  111. { /*input.*/ { 1, 0x3042 },
  112. /*expect*/ { 0,1,2, "\244\242" },
  113. },
  114. /* #02 : normal case */
  115. { /*input.*/ { 1, 0x3044 },
  116. /*expect*/ { 0,1,2, "\244\244" },
  117. },
  118. /* #03 : normal case */
  119. { /*input.*/ { 1, 0x008E },
  120. /*expect*/ { 0,1,-1, "" },
  121. },
  122. /* #04 : jisX0212 */
  123. { /*input.*/ { 1, 0x00C4 },
  124. /*expect*/ { 0,1,3, "\217\252\243" }, /* jisx0210 returns 3 */
  125. },
  126. /* #05 : state dependency */
  127. { /*input.*/ { 0, 0x008E },
  128. /*expect*/ { 0,0,0, "" },
  129. },
  130. { .is_last = 1 }
  131. }
  132. },
  133. #else
  134. {
  135. { Twctomb, TST_LOC_ja_UTF8 },
  136. {
  137. /* #01 : normal case */
  138. { /*input.*/ { 1, 0x3042 },
  139. /*expect*/ { 0,1,3, "\343\201\202" },
  140. },
  141. /* #02 : normal case */
  142. { /*input.*/ { 1, 0x3044 },
  143. /*expect*/ { 0,1,3, "\343\201\204" },
  144. },
  145. /* #03 : normal case */
  146. { /*input.*/ { 1, 0x008E },
  147. /*expect*/ { 0,1,2, "\302\216" },
  148. },
  149. /* #04 : jisX0212 */
  150. { /*input.*/ { 1, 0x00C4 },
  151. /*expect*/ { 0,1,2, "\303\204" }, /* jisx0210 returns 3 */
  152. },
  153. /* #05 : state dependency */
  154. { /*input.*/ { 0, 0x008E },
  155. /*expect*/ { 0,0,0, "" },
  156. },
  157. { .is_last = 1 }
  158. }
  159. },
  160. #endif
  161. {
  162. { Twctomb, TST_LOC_end }
  163. }
  164. };