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