Initialize Tizen 2.3
[framework/base/tizen-locale.git] / localedata / tests-mbwc / tst_mblen.c
1 /*
2   MBLEN: int mblen (char *s, size_t n)
3 */
4
5 #define TST_FUNCTION mblen
6
7 #include "tsp_common.c"
8 #include "dat_mblen.c"
9
10 int
11 tst_mblen (FILE * fp, int debug_flg)
12 {
13   TST_DECL_VARS (int);
14   char s_flg;
15   const char *s_in;
16   size_t n;
17
18   TST_DO_TEST (mblen)
19   {
20     TST_HEAD_LOCALE (mblen, S_MBLEN);
21     TST_DO_REC (mblen)
22     {
23       TST_GET_ERRET (mblen);
24       s_flg = TST_INPUT (mblen).s_flg;
25       s_in = TST_INPUT (mblen).s;
26       n = TST_INPUT (mblen).n;
27
28       if (s_flg == 0)
29         {
30           s_in = NULL;
31         }
32
33       if (n == USE_MBCURMAX)
34         {
35           n = MB_CUR_MAX;
36         }
37
38       TST_CLEAR_ERRNO;
39       ret = mblen (s_in, n);
40       TST_SAVE_ERRNO;
41
42       TST_IF_RETURN (S_MBLEN)
43       {
44         if (s_in == NULL)
45           {                     /* state dependency */
46             if (ret_exp == +1)
47               {                 /* state-dependent  */
48                 if (ret != 0)
49                   {
50                     /* non-zero: state-dependent encoding */
51                     Result (C_SUCCESS, S_MBLEN, CASE_3, MS_PASSED);
52                   }
53                 else
54                   {
55                     err_count++;
56                     Result (C_FAILURE, S_MBLEN, CASE_3,
57                             "should be state-dependent encoding, "
58                             "but the return value shows it is"
59                             " state-independent");
60                   }
61               }
62
63             if (ret_exp == 0)
64               {                 /* state-independent */
65                 if (ret == 0)
66                   {
67                     /* non-zero: state-dependent encoding */
68                     Result (C_SUCCESS, S_MBLEN, CASE_3, MS_PASSED);
69                   }
70                 else
71                   {
72                     err_count++;
73                     Result (C_FAILURE, S_MBLEN, CASE_3,
74                             "should be state-independent encoding, "
75                             "but the return value shows it is"
76                             " state-dependent");
77                   }
78               }
79           }
80       }
81     }
82   }
83
84   return err_count;
85 }