Back to index

glibc  2.9
dat_mbtowc.c
Go to the documentation of this file.
00001 /*
00002  *  TEST SUITE FOR MB/WC FUNCTIONS IN C LIBRARY
00003  *
00004  *      FILE: dat_mbtowc.c
00005  *
00006  *      MBTOWC:  int  mbtowc (wchar_t *wp, char *s, size_t n);
00007  */
00008 
00009 /*  NOTE:
00010  *
00011  *      int  mbtowc (wchar_t *wp, char *s, size_t n);
00012  *
00013  *      where      n: a maximum number of bytes
00014  *            return: the number of bytes
00015  *
00016  *
00017  *       o When you feed a null pointer for a string (s) to the function,
00018  *         set s_flg=0 instead of putting just a 'NULL' there.
00019  *         Even if you put a 'NULL', it means a null string as well as "".
00020  *
00021  *       o When s is a null pointer, the function checks state dependency.
00022  *
00023  *            state-dependent encoding      - return    NON-zero
00024  *            state-independent encoding    - return    0
00025  *
00026  *         If state-dependent encoding is expected, set
00027  *
00028  *            s_flg = 0,  ret_flg = 0,  ret_val = +1
00029  *
00030  *         If state-independent encoding is expected, set
00031  *
00032  *            s_flg = 0,  ret_flg = 0,  ret_val = 0
00033  *
00034  *
00035  *         When you set ret_flg=1, the test program simply compares
00036  *         an actual return value with an expected value. You can
00037  *         check state-independent case (return value is 0) in that
00038  *         way, but you can not check state-dependent case. So when
00039  *         you check state- dependency in this test function:
00040  *         tst_mbtowc(), set ret_flg=0 always. It's a special case
00041  *         and the test function takes care of it.
00042  *
00043  *                     w_flg
00044  *                     |    s: (a null string; can't be (char *)NULL)
00045  *                     |    |
00046  *            input. { 1, 0, (char)NULL, MB_LEN_MAX     },
00047  *                        |
00048  *                        s_flg=0: makes _s_ a null pointer.
00049  *
00050  *            expect { 0,0,0,x,     0x0000         },
00051  *                         | |
00052  *                         | ret_val: 0/+1
00053  *                         ret_flg=0
00054  *
00055  *
00056  *    Test data for State dependent encodings:
00057  *
00058  *       mbtowc( NULL, NULL, 0 );   ... first  data
00059  *       mbtowc( &wc,       s1,  n1 );     ... second data
00060  *       mbtowc( &wc,       s2,  n2 );     ... third  data
00061  * */
00062 
00063 #include <limits.h>
00064 
00065 TST_MBTOWC tst_mbtowc_loc [] = {
00066   {
00067     { Tmbtowc, TST_LOC_de },
00068     {
00069       { /*----------------- #01 -----------------*/
00070        {
00071          {
00072            { 1, 1, "\xfc\xe4\xf6",     1         },
00073            { 1, 1, "\xfc\xe4\xf6",     2         },
00074            { 1, 1, "\xfc\xe4\xf6",     MB_LEN_MAX },
00075          }
00076        },
00077        {
00078          {
00079            { 0,  1,  1,   0x00FC },
00080            { 0,  1,  1,   0x00FC },
00081            { 0,  1,  1,   0x00FC },
00082          }
00083        }
00084       },
00085       { /*----------------- #02 -----------------*/
00086        {
00087          {
00088            { 1, 1, "\177",      MB_LEN_MAX },
00089            { 1, 1, "\200",      MB_LEN_MAX },
00090            { 1, 1, "\201",      MB_LEN_MAX },
00091          }
00092        },
00093        {
00094          {
00095            { 0,  1,  1,   0x007F },
00096            { 0,  1,  1,   0x0080 },
00097            { 0,  1,  1,   0x0081 },
00098          }
00099        }
00100       },
00101       { /*----------------- #03 -----------------*/
00102        {
00103          {
00104            { 1, 1, "",                        MB_LEN_MAX },
00105            { 0, 1, "\xfc\xe4\xf6",     1         },
00106            { 0, 1, "\xfc\xe4\xf6",     2         },
00107          }
00108        },
00109        {
00110          {
00111            { 0,  1,  0,   0x0000 },
00112            { 0,  1,  1,   0x0000 },
00113            { 0,  1,  1,   0x0000 },
00114          }
00115        }
00116       },
00117       { /*----------------- #04 -----------------*/
00118        {
00119          {
00120            { 0, 1, "\xfc\xe4\xf6",     MB_LEN_MAX },
00121            { 0, 1, "\177",             MB_LEN_MAX },
00122            { 0, 1, "",                       MB_LEN_MAX },
00123          }
00124        },
00125        {
00126          {
00127            { 0,  1,  1,   0x0000 },
00128            { 0,  1,  1,   0x0000 },
00129            { 0,  1,  0,   0x0000 },
00130          }
00131        }
00132       },
00133       { /*----------------- #05 -----------------*/
00134        {
00135          {
00136            { 0, 1, "\xfc\xe4\xf6", MB_LEN_MAX },
00137            { 0, 1, "\177",         MB_LEN_MAX },
00138            { 0, 0, NULL,           MB_LEN_MAX },
00139          }
00140        },
00141        {
00142          {
00143            { 0,  1,  1,   0x0000 },
00144            { 0,  1,  1,   0x0000 },
00145            { 0,  0,  0,   0x0000 },
00146          }
00147        }
00148       },
00149       { .is_last = 1 }
00150     }
00151   },
00152   {
00153     { Tmbtowc, TST_LOC_enUS },
00154     {
00155       { /*----------------- #01 -----------------*/
00156        {
00157          {
00158            { 1, 1, "ABC",       1         },
00159            { 1, 1, "ABC",       2         },
00160            { 1, 1, "ABC",       MB_LEN_MAX },
00161          }
00162        },
00163        {
00164          {
00165            { 0,  1,  1,   0x0041 },
00166            { 0,  1,  1,   0x0041 },
00167            { 0,  1,  1,   0x0041 },
00168          }
00169        }
00170       },
00171       { /*----------------- #02 -----------------*/
00172        {
00173          {
00174            { 1, 1, "\177",      MB_LEN_MAX },
00175            { 1, 1, "\200",      MB_LEN_MAX },
00176            { 1, 1, "\201",      MB_LEN_MAX },
00177          }
00178        },
00179        {
00180          {
00181            { 0,  1,  1,   0x007F },
00182            { EILSEQ,  1, -1,   0x0000 },
00183            { EILSEQ,  1, -1,   0x0000 },
00184          }
00185        }
00186       },
00187       { /*----------------- #03 -----------------*/
00188        {
00189          {
00190            { 1, 1, "",          MB_LEN_MAX },
00191            { 0, 1, "ABC",       1         },
00192            { 0, 1, "ABC",       2         },
00193          }
00194        },
00195        {
00196          {
00197            { 0,  1,  0,   0x0000 },
00198            { 0,  1,  1,   0x0000 },
00199            { 0,  1,  1,   0x0000 },
00200          }
00201        }
00202       },
00203       { /*----------------- #04 -----------------*/
00204        {
00205          {
00206            { 0, 1, "ABC",       MB_LEN_MAX },
00207            { 0, 1, "\177",      MB_LEN_MAX },
00208            { 0, 1, "",          MB_LEN_MAX },
00209          }
00210        },
00211        {
00212          {
00213            { 0,  1,  1,   0x0000 },
00214            { 0,  1,  1,   0x0000 },
00215            { 0,  1,  0,   0x0000 },
00216          }
00217        }
00218       },
00219       { /*----------------- #05 -----------------*/
00220        {
00221          {
00222            { 0, 1, "ABC",       MB_LEN_MAX },
00223            { 0, 1, "\177",      MB_LEN_MAX },
00224            { 0, 0, NULL,        MB_LEN_MAX },
00225          }
00226        },
00227        {
00228          {
00229            { 0,  1,  1,   0x0000 },
00230            { 0,  1,  1,   0x0000 },
00231            { 0,  0,  0,   0x0000 },
00232          }
00233        }
00234       },
00235       { .is_last = 1 }
00236     }
00237   },
00238   {
00239     { Tmbtowc, TST_LOC_eucJP },
00240     {
00241       { /*----------------- #01 -----------------*/
00242        {
00243          {
00244            { 1, 1, "\244\242A",      1          },
00245            { 1, 1, "\244\242A",      2          },
00246            { 1, 1, "\244\242A",      MB_LEN_MAX },
00247          }
00248        },
00249        {
00250          {
00251 #ifdef SHOJI_IS_RIGHT
00252            { EILSEQ,  1, -1,   0x0000 },
00253 #else
00254            /* XXX EILSEQ was introduced in ISO C99.  */
00255            { 0,        1, -1,   0x0000 },
00256 #endif
00257            { 0,       1,  2,   0x3042 },
00258            { 0,       1,  2,   0x3042 },
00259          }
00260        }
00261       },
00262       { /*----------------- #02 -----------------*/
00263        {
00264          {
00265            { 1, 1, "\177\244\242",   MB_LEN_MAX },
00266            { 1, 1, "\377\244\242",   MB_LEN_MAX },
00267            { 1, 1, "\201\244\242",   MB_LEN_MAX },
00268          }
00269        },
00270        {
00271          {
00272            { 0,  1, +1,   0x007F },
00273 #ifdef SHOJI_IS_RIGHT
00274            { EILSEQ,  1, -1,   0x0000 },
00275 #else
00276            { 0,  1, -1,   0x0000 },
00277 #endif
00278            { 0,  1, +1,   0x0081 },
00279          }
00280        }
00281       },
00282       { /*----------------- #03 -----------------*/
00283        {
00284          {
00285            { 1, 1, "",         MB_LEN_MAX },
00286            { 0, 1, "\244\242A",      1          },
00287            { 0, 1, "\244\242A",      2          },
00288          }
00289        },
00290        {
00291          {
00292            { 0,  1,  0,   0x0000 },
00293 #ifdef SHOJI_IS_RIGHT
00294            { EILSEQ,  1, -1,   0x0000 },
00295 #else
00296            /* XXX EILSEQ was introduced in ISO C99.  */
00297            { 0,       1, -1,   0x0000 },
00298 #endif
00299            { 0,  1,  2,   0x0000 },
00300          }
00301        }
00302       },
00303       { /*----------------- #04 -----------------*/
00304        {
00305          {
00306            { 0, 1, "\244\242A",      MB_LEN_MAX },
00307            { 0, 1, "\177\244\242",   MB_LEN_MAX },
00308            { 0, 1, "",                   MB_LEN_MAX },
00309          }
00310        },
00311        {
00312          {
00313            { 0,  1,  2,   0x0000 },
00314            { 0,  1, +1,   0x0000 },
00315            { 0,  1,  0,   0x0000 },
00316          }
00317        }
00318       },
00319       { /*----------------- #05 -----------------*/
00320        {
00321          {
00322            { 0, 1, "\244\242A",      MB_LEN_MAX },
00323            { 0, 1, "\177\244\242",   MB_LEN_MAX },
00324            { 0, 0, NULL,          MB_LEN_MAX },
00325          }
00326        },
00327        {
00328          {
00329            { 0,  1,  2,   0x0000 },
00330            { 0,  1, +1,   0x0000 },
00331            { 0,  0,  0,   0x0000 },
00332          }
00333        }
00334       },
00335       { .is_last = 1 }
00336     }
00337   },
00338   {
00339     { Tmbtowc, TST_LOC_end }
00340   }
00341 };