Back to index

glibc  2.9
dat_mblen.c
Go to the documentation of this file.
00001 /*
00002  *  TEST SUITE FOR MB/WC FUNCTIONS IN C LIBRARY
00003  *
00004  *      FILE: dat_mblen.c
00005  *
00006  *      MBLEN:        int mblen (char *s, size_t n);
00007  */
00008 
00009 
00010 /*
00011  *  NOTE:
00012  *       int  mblen (char *s, size_t n);
00013  *
00014  *       where            n: a maximum number of bytes
00015  *
00016  *       return - the number of bytes
00017  *
00018  *  CAUTION:
00019  *
00020  *      o When you feed a null pointer for a string (s) to the function,
00021  *        set s_flg=0 instead of putting just a 'NULL' there.
00022  *        Even if you set a 'NULL', it doens't mean a NULL pointer.
00023  *
00024  *      o When s is a null pointer, the function checks state dependency.
00025  *
00026  *            state-dependent encoding         - return  NON-zero
00027  *            state-independent encoding    - return  0
00028  *
00029  *        If state-dependent encoding is expected, set
00030  *
00031  *            s_flg = 0,  ret_flg = 0,     ret_val = +1
00032  *
00033  *        If state-independent encoding is expected, set
00034  *
00035  *            s_flg = 0,  ret_flg = 0,     ret_val = 0
00036  *
00037  *
00038  *        When you set ret_flg=1, the test program simply compares an
00039  *        actual return value with an expected value. You can check
00040  *        state-independent case (return value is 0) in that way, but
00041  *        you can not check state-dependent case. So when you check
00042  *        state- dependency in this test function: tst_mblen(), set
00043  *        ret_flg=0 always. It's a special case, and the test
00044  *        function takes care of it.
00045  *
00046  *            s_flg=0               ret_flg=0
00047  *            |              |
00048  *          { 0, 0 },        { 0, 0, 0,  x }
00049  *              |                |
00050  *              not used         ret_val: 0/+1
00051  *                               (expected val) */
00052 
00053 
00054 TST_MBLEN tst_mblen_loc [] = {
00055   {
00056     { Tmblen, TST_LOC_de },
00057     {
00058       /* 01: a character.  */
00059       {        { 1, "\300",    USE_MBCURMAX }, { 0,     1,  1 }        },
00060       /* 02: a character.  */
00061       {        { 1, "\309",    USE_MBCURMAX }, { 0,     1,  1 }        },
00062       /* 03: a character + an invalid byte.  */
00063       {        { 1, "Z\204",          USE_MBCURMAX }, { 0,     1, +1 }        },
00064       /* 04: control/invalid characters.  */
00065       {        { 1, "\177\000",  USE_MBCURMAX }, { 0,   1, +1 }        },
00066       /* 05: a null string.  */
00067       {        { 1, "",        USE_MBCURMAX }, { 0,     1,  0 }        },
00068       /* 06: a null pointer.  */
00069       {        { 0, "",        USE_MBCURMAX }, { 0,     0,  0 }        },
00070       /* Last element.      */
00071       {        .is_last = 1 }
00072     }
00073   },
00074   {
00075     { Tmblen, TST_LOC_enUS },
00076     {
00077       /* 01: a character.  */
00078       {        { 1, "A",       USE_MBCURMAX }, { 0,     1,  1 }        },
00079       /* 02: a character.  */
00080       {        { 1, "a",       USE_MBCURMAX }, { 0,     1,  1 }        },
00081       /* 03: a character + an invalid byte.  */
00082       {        { 1, "Z\204",          USE_MBCURMAX }, { 0,     1, +1 }        },
00083       /* 04: control/invalid characters.  */ 
00084       {        { 1, "\177\000",  USE_MBCURMAX }, { 0,   1, +1 }        },
00085       /* 05: a null string.  */                
00086       {        { 1, "",        USE_MBCURMAX }, { 0,     1,  0 }        },
00087       /* 06: a null pointer.  */        
00088       {        { 0, "",        USE_MBCURMAX }, { 0,     0,  0 }        },
00089       /* Last element.      */
00090       {        .is_last = 1 }
00091     }
00092   },
00093   {
00094     { Tmblen, TST_LOC_eucJP },
00095     {
00096       /* 01: a character.  */
00097       {        { 1, "\264\301",       USE_MBCURMAX }, { 0, 1,  2 }     },
00098       /* 02: a character.  */                         
00099       {        { 1, "\216\261",       USE_MBCURMAX }, { 0, 1,  2 }  },
00100       /* 03: a character + an invalid byte.  */       
00101       {        { 1, "\260\241\200",          USE_MBCURMAX }, { 0, 1,  2 }     },
00102       /* 04: control/invalid characters.  */
00103       {        { 1, "\377\202",  USE_MBCURMAX }, { EILSEQ, 1, -1 }     },
00104       /* 05: a null string.  */                
00105       {        { 1, "",        USE_MBCURMAX }, { 0,     1,  0 }        },
00106       /* 06: a null pointer.  */        
00107       {        { 0, "",        USE_MBCURMAX }, { 0,     0,  0 }        },
00108       /* Last element.      */
00109       {        .is_last = 1 }
00110     }
00111   },
00112   {
00113     { Tmblen, TST_LOC_end}
00114   }
00115 };