Updated to fedora-glibc-20061128T1037
[glibc/history.git] / localedata / tests-mbwc / tst_wctomb.c
blobaea89fed8b9f0e3bcf6add10285637a61a508608
1 /*
2 WCTOMB: int wctomb (char *s, wchar_t wc)
3 */
5 #define TST_FUNCTION wctomb
7 #include "tsp_common.c"
8 #include "dat_wctomb.c"
10 int
11 tst_wctomb (FILE * fp, int debug_flg)
13 TST_DECL_VARS (int);
14 wchar_t wc;
15 char s[MBSSIZE], *s_in, *s_ex;
16 int err, i;
18 TST_DO_TEST (wctomb)
20 TST_HEAD_LOCALE (wctomb, S_WCTOMB);
21 TST_DO_REC (wctomb)
23 TST_GET_ERRET (wctomb);
24 wc = TST_INPUT (wctomb).wc;
25 s_in = ((TST_INPUT (wctomb).s_flg) == 0) ? (char *) NULL : s;
26 ret = wctomb (s_in, wc);
28 if (debug_flg)
30 fprintf (stdout, "wctomb() [ %s : %d ] ret = %d\n", locale,
31 rec + 1, ret);
34 TST_IF_RETURN (S_WCTOMB)
36 if (s_in == NULL) /* state dependency */
38 if (ret_exp == +1) /* state-dependent */
40 if (ret != 0)
42 /* Non-zero means state-dependent encoding. */
43 Result (C_SUCCESS, S_WCTOMB, CASE_3, MS_PASSED);
45 else
47 err_count++;
48 Result (C_FAILURE, S_WCTOMB, CASE_3,
49 "should be state-dependent encoding, "
50 "but a return value shows it is "
51 "state-independent");
55 if (ret_exp == 0) /* state-independent */
57 if (ret == 0)
59 /* Non-zero means state-dependent encoding. */
60 Result (C_SUCCESS, S_WCTOMB, CASE_3, MS_PASSED);
62 else
64 err_count++;
65 Result (C_FAILURE, S_WCTOMB, CASE_3,
66 "should be state-independent encoding, "
67 "but a return value shows it is state-dependent");
73 s_ex = TST_EXPECT (wctomb).s;
75 if (s_in)
77 for (i = 0, err = 0; *(s_ex + i) != 0 && i < MBSSIZE; i++)
79 if (s_in[i] != s_ex[i])
81 err++;
82 err_count++;
83 Result (C_FAILURE, S_WCTOMB, CASE_4,
84 "copied string is different from an"
85 " expected string");
86 break;
90 if (!err)
92 Result (C_SUCCESS, S_WCTOMB, CASE_4, MS_PASSED);
98 return err_count;