1 | /* |
2 | WCTOMB: int wctomb (char *s, wchar_t wc) |
3 | */ |
4 | |
5 | #define TST_FUNCTION wctomb |
6 | |
7 | #include "tsp_common.c" |
8 | #include "dat_wctomb.c" |
9 | |
10 | int |
11 | tst_wctomb (FILE * fp, int debug_flg) |
12 | { |
13 | TST_DECL_VARS (int); |
14 | wchar_t wc; |
15 | char s[MBSSIZE], *s_in, *s_ex; |
16 | int err, i; |
17 | |
18 | TST_DO_TEST (wctomb) |
19 | { |
20 | TST_HEAD_LOCALE (wctomb, S_WCTOMB); |
21 | TST_DO_REC (wctomb) |
22 | { |
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); |
27 | |
28 | if (debug_flg) |
29 | { |
30 | fprintf (stdout, "wctomb() [ %s : %d ] ret = %d\n" , locale, |
31 | rec + 1, ret); |
32 | } |
33 | |
34 | TST_IF_RETURN (S_WCTOMB) |
35 | { |
36 | if (s_in == NULL) /* state dependency */ |
37 | { |
38 | if (ret_exp == +1) /* state-dependent */ |
39 | { |
40 | if (ret != 0) |
41 | { |
42 | /* Non-zero means state-dependent encoding. */ |
43 | Result (C_SUCCESS, S_WCTOMB, CASE_3, MS_PASSED); |
44 | } |
45 | else |
46 | { |
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" ); |
52 | } |
53 | } |
54 | |
55 | if (ret_exp == 0) /* state-independent */ |
56 | { |
57 | if (ret == 0) |
58 | { |
59 | /* Non-zero means state-dependent encoding. */ |
60 | Result (C_SUCCESS, S_WCTOMB, CASE_3, MS_PASSED); |
61 | } |
62 | else |
63 | { |
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" ); |
68 | } |
69 | } |
70 | } |
71 | } |
72 | |
73 | s_ex = TST_EXPECT (wctomb).s; |
74 | |
75 | if (s_in) |
76 | { |
77 | for (i = 0, err = 0; *(s_ex + i) != 0 && i < MBSSIZE; i++) |
78 | { |
79 | if (s_in[i] != s_ex[i]) |
80 | { |
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; |
87 | } |
88 | } |
89 | |
90 | if (!err) |
91 | { |
92 | Result (C_SUCCESS, S_WCTOMB, CASE_4, MS_PASSED); |
93 | } |
94 | } |
95 | } |
96 | } |
97 | |
98 | return err_count; |
99 | } |
100 | |