Back to index

glibc  2.9
dat_wctomb.c
Go to the documentation of this file.
00001 /*
00002  *  TEST SUITE FOR MB/WC FUNCTIONS IN C LIBRARY
00003  *
00004  *      FILE: dat_wctomb.c
00005  *
00006  *      WCTOMB:  int wctomb (char *s, wchar_t wc)
00007  */
00008 
00009 
00010 /*
00011  *  FUNCTION:
00012  *
00013  *       int  wctomb (char *s, wchar_t wc);
00014  *
00015  *            return: the number of bytes
00016  *
00017  *  NOTE:
00018  *
00019  *      o When you feed a null pointer for a string (s) to the function,
00020  *        set s_flg=0 instead of putting just a 'NULL' there.
00021  *        Even if you put a 'NULL', it means a null string as well as "".
00022  *
00023  *      o When s is a null pointer, the function checks state dependency.
00024  *
00025  *            state-dependent encoding         - return  NON-zero
00026  *            state-independent encoding    - return  0
00027  *
00028  *        If state-dependent encoding is expected, set
00029  *
00030  *            s_flg = 0,  ret_flg = 0,     ret_val = +1
00031  *
00032  *        If state-independent encoding is expected, set
00033  *
00034  *            s_flg = 0,  ret_flg = 0,     ret_val = 0
00035  *
00036  *
00037  *        When you set ret_flg=1, the test program simply compares an
00038  *        actual return value with an expected value. You can check
00039  *        state-independent case (return value is 0) in that way, but
00040  *        you can not check state-dependent case. So when you check
00041  *        state- dependency in this test function: tst_wctomb(), set
00042  *        ret_flg=0 always. It's a special case, and the test
00043  *        function takes care of it.
00044  *
00045  *           Input     Expect
00046  *
00047  *            s_flg=0                ret_flg=0
00048  *            |               |
00049  *           { 0, 0 },        { 0, 0, 0,  x,  "" }
00050  *               |                |
00051  *               not used         ret_val: 0/+1
00052  * (expected val)
00053  */
00054 
00055 
00056 TST_WCTOMB tst_wctomb_loc [] = {
00057   {
00058     { Twctomb, TST_LOC_de },
00059     {
00060       /* #01 : normal case            */
00061       { /*input.*/ { 1,        0x00C4  },
00062        /*expect*/ { 0,1,1,  ""       },
00063       },
00064       /* #02 : normal case            */
00065       { /*input.*/ { 1,        0x00DC  },
00066        /*expect*/ { 0,1,1,  ""       },
00067       },
00068       /* #03 : normal case            */
00069       { /*input.*/ { 1,        0x0092  },
00070        /*expect*/ { 0,1,1,  "\222"  },
00071       },
00072       /* #04 : error case             */
00073       { /*input.*/ { 1,        0x3041  },
00074        /*expect*/ { 0,1,-1, ""        },
00075       },
00076       /* #05 : state dependency       */
00077       { /*input.*/ { 0,        0x0000  },
00078        /*expect*/ { 0,0,0,  ""        },
00079       },
00080       { .is_last = 1 }
00081     }
00082   },
00083   {
00084     { Twctomb, TST_LOC_enUS },
00085     {
00086       /* #01 : normal case            */
00087       { /*input.*/ { 1,        0x0041  },
00088        /*expect*/ { 0,1,1,  "A"       },
00089       },
00090       /* #02 : normal case            */
00091       { /*input.*/ { 1,        0x0042  },
00092        /*expect*/ { 0,1,1,  "B"       },
00093       },
00094       /* #03 : error case             */
00095       /* <WAIVER> */
00096       { /*input.*/ { 1,        0x00C4  },
00097        /*expect*/ { 0,1,-1, ""        },
00098       },
00099       /* #04 : error case             */
00100       { /*input.*/ { 1,        0x30A4  },
00101        /*expect*/ { 0,1,-1, ""        },
00102       },
00103       /* #05 : state dependency       */
00104       { /*input.*/ { 0,        0x0000  },
00105        /*expect*/ { 0,0,0,  ""        },
00106       },
00107       { .is_last = 1 }
00108     }
00109   },
00110   {
00111     { Twctomb, TST_LOC_eucJP },
00112     {
00113       /* #01 : normal case            */
00114       { /*input.*/ { 1,        0x3042  },
00115        /*expect*/ { 0,1,2,  "\244\242"   },
00116       },
00117       /* #02 : normal case            */
00118       { /*input.*/ { 1,        0x3044  },
00119        /*expect*/ { 0,1,2,  "\244\244"   },
00120       },
00121       /* #03 : normal case            */
00122       { /*input.*/ { 1,        0x008E  },
00123        /*expect*/ { 0,1,-1, ""        },
00124       },
00125       /* #04 : jisX0212               */
00126       { /*input.*/ { 1,        0x00C4       },
00127        /*expect*/ { 0,1,3,  "\217\252\243" }, /* jisx0210  returns 3 */
00128       },
00129       /* #05 : state dependency       */
00130       { /*input.*/ { 0,        0x008E  },
00131        /*expect*/ { 0,0,0,  ""        },
00132       },
00133       { .is_last = 1 }
00134     }
00135   },
00136   {
00137     { Twctomb, TST_LOC_end }
00138   }
00139 };