Fix warnings in fwscanf / rewind tests.
[glibc.git] / localedata / tests-mbwc / tst_wcsxfrm.c
blob6fb8a1c28d6f942a4eefbc0bd6a36c7535038a6d
1 /*
2 WCSXFRM: size_t wcsxfrm (wchar_t *ws1, const wchar_t *ws2, size_t n);
3 */
5 #define TST_FUNCTION wcsxfrm
7 #include "tsp_common.c"
8 #include "dat_wcsxfrm.c"
10 int
11 tst_wcsxfrm (FILE * fp, int debug_flg)
13 TST_DECL_VARS (size_t);
14 wchar_t *org1, *org2;
15 wchar_t frm1[MBSSIZE], frm2[MBSSIZE];
16 size_t n1, n2;
17 int ret_coll, ret_cmp;
19 TST_DO_TEST (wcsxfrm)
21 TST_HEAD_LOCALE (wcsxfrm, S_WCSXFRM);
22 TST_DO_REC (wcsxfrm)
24 TST_GET_ERRET (wcsxfrm);
25 org1 = TST_INPUT (wcsxfrm).org1;
26 org2 = TST_INPUT (wcsxfrm).org2;
27 n1 = TST_INPUT (wcsxfrm).n1;
28 n2 = TST_INPUT (wcsxfrm).n2;
29 if (n1 < 0 || sizeof (frm1) < n1 || sizeof (frm2) < n2)
31 warn_count++;
32 Result (C_IGNORED, S_WCSXFRM, CASE_9,
33 "input data n1 or n2 is invalid");
34 continue;
37 /* an errno and a return value are checked
38 only for 2nd wcsxfrm() call.
39 A result of 1st call is used to compare
40 those 2 values by using wcscmp().
43 TST_CLEAR_ERRNO;
44 ret = wcsxfrm (frm1, org1, n1); /* First call */
45 TST_SAVE_ERRNO;
47 if (debug_flg)
49 fprintf (stdout, "tst_wcsxfrm() : REC = %d\n", rec + 1);
50 fprintf (stdout, "tst_wcsxfrm() : 1st ret = %zu\n", ret);
53 if (ret == -1 || ret >= n1 || errno_save != 0)
55 warn_count++;
56 Result (C_INVALID, S_WCSXFRM, CASE_8,
57 "got an error in fist wcsxfrm() call");
58 continue;
61 TST_CLEAR_ERRNO;
62 /* Second call */
63 ret = wcsxfrm (((n2 == 0) ? NULL : frm2), org2, n2);
64 TST_SAVE_ERRNO;
66 TST_IF_RETURN (S_WCSXFRM)
70 if (n2 == 0 || ret >= n2 || errno != 0)
72 #if 0
73 warn_count++;
74 Result (C_IGNORED, S_WCSXFRM, CASE_7, "did not get a result");
75 #endif
76 continue;
79 if (debug_flg)
81 fprintf (stdout, "tst_wcsxfrm() : 2nd ret = %zu\n", ret);
84 /* wcscoll() */
85 TST_CLEAR_ERRNO;
86 /* depends on wcscoll() ... not good though ... */
87 ret_coll = wcscoll (org1, org2);
88 TST_SAVE_ERRNO;
90 if (errno != 0) /* bugs * bugs may got correct results ... */
92 warn_count++;
93 Result (C_INVALID, S_WCSXFRM, CASE_6,
94 "got an error in wcscoll() call");
95 continue;
97 /* wcscmp() */
98 ret_cmp = wcscmp (frm1, frm2);
100 if ((ret_coll == ret_cmp) || (ret_coll > 0 && ret_cmp > 0)
101 || (ret_coll < 0 && ret_cmp < 0))
103 Result (C_SUCCESS, S_WCSXFRM, CASE_3,
104 MS_PASSED " (depends on wcscoll & wcscmp)");
106 else
108 err_count++;
109 Result (C_FAILURE, S_WCSXFRM, CASE_3,
110 "results from wcscoll & wcscmp() do not match");
113 if (debug_flg)
115 fprintf (stdout, "tst_wcsxfrm() : coll = %d <-> %d = cmp\n",
116 ret_coll, ret_cmp);
121 return err_count;