Updated to fedora-glibc-20060807T1859
[glibc/history.git] / localedata / tests-mbwc / tst_swscanf.c
blob76445d75f4858d1b5f416832c9c1710f2850a45c
1 /*
2 SWSCANF: int swscanf (const wchar_t *ws, const wchar_t *fmt, ...);
3 */
5 #define TST_FUNCTION swscanf
7 #include "tsp_common.c"
8 #include "dat_swscanf.c"
10 int
11 tst_swscanf (FILE * fp, int debug_flg)
13 TST_DECL_VARS (int);
14 wchar_t *ws;
15 wchar_t *fmt;
16 int val_int1;
17 unsigned val_int2;
18 float val_flt;
19 char val_c;
20 char val_s[MBSSIZE * 3];
21 wchar_t val_S[WCSSIZE * 3], *exp_S;
22 int i;
24 TST_DO_TEST (swscanf)
26 TST_HEAD_LOCALE (swscanf, S_SWSCANF);
27 TST_DO_REC (swscanf)
29 TST_GET_ERRET (swscanf);
30 ws = TST_INPUT (swscanf).ws;
31 fmt = TST_INPUT (swscanf).fmt;
32 val_int1 = val_int2 = val_flt = val_c = 0;
33 memset (val_s, 0, sizeof (val_s));
34 memset (val_S, 0, sizeof (val_S));
36 TST_CLEAR_ERRNO;
38 if (TST_INPUT (swscanf).wch)
40 ret = swscanf (ws, fmt, val_S);
42 else
44 ret =
45 swscanf (ws, fmt, &val_int1, &val_int2, &val_flt, &val_c, val_s);
48 TST_SAVE_ERRNO;
50 if (debug_flg)
51 { /* seems fprintf doesn't update errno */
52 fprintf (stdout, "swscanf() [ %s : %d ] ret = %d\n", locale,
53 rec + 1, ret);
54 fprintf (stdout, " errno = %d\n",
55 errno_save);
56 fprintf (stdout, " collate = %s\n",
57 (setlocale (LC_COLLATE, NULL)) ? setlocale (LC_COLLATE,
58 NULL) : "");
60 if (TST_INPUT (swscanf).wch)
62 fprintf (stdout, " val_S[ 0 ] = 0x%lx\n",
63 (unsigned long int) val_S[0]);
65 else
67 fprintf (stdout, " val_int1 = %d\n",
68 val_int1);
69 fprintf (stdout, " val_int2 = %d\n",
70 val_int2);
71 fprintf (stdout, " val_flt = %f\n",
72 val_flt);
73 fprintf (stdout, " val_c = %c\n",
74 val_c);
75 fprintf (stdout, " val_s = %s\n",
76 val_s);
80 TST_IF_RETURN (S_SWSCANF)
84 if (errno == 0 && TST_INPUT (swscanf).wch)
86 for (exp_S = TST_EXPECT (swscanf).val_S, i = 0; i < WCSSIZE * 3;
87 i++)
89 if (val_S[i] == L'\0' || exp_S[i] == L'\0')
91 if (val_S[i] != exp_S[i] && TST_INPUT (swscanf).wch == 'C')
93 err_count++;
94 Result (C_FAILURE, S_SWSCANF, CASE_4,
95 "the converted wide-char string is different"
96 " from an expected value.");
98 break;
101 if (val_S[i] != exp_S[i])
103 err_count++;
104 Result (C_FAILURE, S_SWSCANF, CASE_4,
105 "the converted wide-char string is different from"
106 " an expected value.");
107 break;
109 else
111 Result (C_SUCCESS, S_SWSCANF, CASE_4, MS_PASSED);
116 if (errno == 0 && !TST_INPUT (swscanf).wch)
118 if (val_int1 != TST_EXPECT (swscanf).val_int ||
119 val_int2 != TST_EXPECT (swscanf).val_uns ||
120 val_flt != TST_EXPECT (swscanf).val_flt ||
121 val_c != TST_EXPECT (swscanf).val_c ||
122 strcmp (val_s, TST_EXPECT (swscanf).val_s))
124 err_count++;
125 Result (C_FAILURE, S_SWSCANF, CASE_3,
126 "the converted values are different from expected values.");
128 else
130 Result (C_SUCCESS, S_SWSCANF, CASE_3, MS_PASSED);
136 return err_count;