dat_mblen.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * TEST SUITE FOR MB/WC FUNCTIONS IN C LIBRARY
  3. *
  4. * FILE: dat_mblen.c
  5. *
  6. * MBLEN: int mblen (char *s, size_t n);
  7. */
  8. /*
  9. * NOTE:
  10. * int mblen (char *s, size_t n);
  11. *
  12. * where n: a maximum number of bytes
  13. *
  14. * return - the number of bytes
  15. *
  16. * CAUTION:
  17. *
  18. * o When you feed a null pointer for a string (s) to the function,
  19. * set s_flg=0 instead of putting just a 'NULL' there.
  20. * Even if you set a 'NULL', it doens't mean a NULL pointer.
  21. *
  22. * o When s is a null pointer, the function checks state dependency.
  23. *
  24. * state-dependent encoding - return NON-zero
  25. * state-independent encoding - return 0
  26. *
  27. * If state-dependent encoding is expected, set
  28. *
  29. * s_flg = 0, ret_flg = 0, ret_val = +1
  30. *
  31. * If state-independent encoding is expected, set
  32. *
  33. * s_flg = 0, ret_flg = 0, ret_val = 0
  34. *
  35. *
  36. * When you set ret_flg=1, the test program simply compares an
  37. * actual return value with an expected value. You can check
  38. * state-independent case (return value is 0) in that way, but
  39. * you can not check state-dependent case. So when you check
  40. * state- dependency in this test function: tst_mblen(), set
  41. * ret_flg=0 always. It's a special case, and the test
  42. * function takes care of it.
  43. *
  44. * s_flg=0 ret_flg=0
  45. * | |
  46. * { 0, 0 }, { 0, 0, 0, x }
  47. * | |
  48. * not used ret_val: 0/+1
  49. * (expected val) */
  50. TST_MBLEN tst_mblen_loc [] = {
  51. {
  52. { Tmblen, TST_LOC_de },
  53. {
  54. /* 01: a character. */
  55. { { 1, "\300", USE_MBCURMAX }, { 0, 1, 1 } },
  56. /* 02: a character. */
  57. { { 1, "\309", USE_MBCURMAX }, { 0, 1, 1 } },
  58. /* 03: a character + an invalid byte. */
  59. { { 1, "Z\204", USE_MBCURMAX }, { 0, 1, +1 } },
  60. /* 04: control/invalid characters. */
  61. { { 1, "\177\000", USE_MBCURMAX }, { 0, 1, +1 } },
  62. /* 05: a null string. */
  63. { { 1, "", USE_MBCURMAX }, { 0, 1, 0 } },
  64. /* 06: a null pointer. */
  65. { { 0, "", USE_MBCURMAX }, { 0, 0, 0 } },
  66. /* Last element. */
  67. { .is_last = 1 }
  68. }
  69. },
  70. {
  71. { Tmblen, TST_LOC_enUS },
  72. {
  73. /* 01: a character. */
  74. { { 1, "A", USE_MBCURMAX }, { 0, 1, 1 } },
  75. /* 02: a character. */
  76. { { 1, "a", USE_MBCURMAX }, { 0, 1, 1 } },
  77. /* 03: a character + an invalid byte. */
  78. { { 1, "Z\204", USE_MBCURMAX }, { 0, 1, +1 } },
  79. /* 04: control/invalid characters. */
  80. { { 1, "\177\000", USE_MBCURMAX }, { 0, 1, +1 } },
  81. /* 05: a null string. */
  82. { { 1, "", USE_MBCURMAX }, { 0, 1, 0 } },
  83. /* 06: a null pointer. */
  84. { { 0, "", USE_MBCURMAX }, { 0, 0, 0 } },
  85. /* Last element. */
  86. { .is_last = 1 }
  87. }
  88. },
  89. #if 0
  90. {
  91. { Tmblen, TST_LOC_eucJP },
  92. {
  93. /* 01: a character. */
  94. { { 1, "\264\301", USE_MBCURMAX }, { 0, 1, 2 } },
  95. /* 02: a character. */
  96. { { 1, "\216\261", USE_MBCURMAX }, { 0, 1, 2 } },
  97. /* 03: a character + an invalid byte. */
  98. { { 1, "\260\241\200", USE_MBCURMAX }, { 0, 1, 2 } },
  99. /* 04: control/invalid characters. */
  100. { { 1, "\377\202", USE_MBCURMAX }, { EILSEQ, 1, -1 } },
  101. /* 05: a null string. */
  102. { { 1, "", USE_MBCURMAX }, { 0, 1, 0 } },
  103. /* 06: a null pointer. */
  104. { { 0, "", USE_MBCURMAX }, { 0, 0, 0 } },
  105. /* Last element. */
  106. { .is_last = 1 }
  107. }
  108. },
  109. #else
  110. {
  111. { Tmblen, TST_LOC_ja_UTF8 },
  112. {
  113. /* 01: a character. */
  114. { { 1, "\346\274\242", USE_MBCURMAX }, { 0, 1, 3 } },
  115. /* 02: a character. */
  116. { { 1, "\357\275\261", USE_MBCURMAX }, { 0, 1, 3 } },
  117. /* 03: a character + an invalid byte. */
  118. { { 1, "\345\272\234\200", USE_MBCURMAX }, { 0, 1, 3 } },
  119. /* 04: control/invalid characters. */
  120. { { 1, "\377\202", USE_MBCURMAX }, { EILSEQ, 1, -1 } },
  121. /* 05: a null string. */
  122. { { 1, "", USE_MBCURMAX }, { 0, 1, 0 } },
  123. /* 06: a null pointer. */
  124. { { 0, "", USE_MBCURMAX }, { 0, 0, 0 } },
  125. /* Last element. */
  126. { .is_last = 1 }
  127. }
  128. },
  129. #endif
  130. {
  131. { Tmblen, TST_LOC_end}
  132. }
  133. };