1/*
2 STRXFRM: size_t strxfrm (char *s1, const char *s2, size_t n)
3*/
4
5#define TST_FUNCTION strxfrm
6
7#include "tsp_common.c"
8#include "dat_strxfrm.c"
9
10
11int
12tst_strxfrm (FILE * fp, int debug_flg)
13{
14 TST_DECL_VARS (size_t);
15 const char *org1, *org2;
16 char frm1[MBSSIZE], frm2[MBSSIZE];
17 size_t n1, n2;
18 int ret_coll, ret_cmp;
19
20 TST_DO_TEST (strxfrm)
21 {
22 TST_HEAD_LOCALE (strxfrm, S_STRXFRM);
23 TST_DO_REC (strxfrm)
24 {
25 TST_GET_ERRET (strxfrm);
26 org1 = TST_INPUT (strxfrm).org1;
27 org2 = TST_INPUT (strxfrm).org2;
28 n1 = TST_INPUT (strxfrm).n1;
29 n2 = TST_INPUT (strxfrm).n2;
30
31 if (n1 < 0 || sizeof (frm1) < n1 || sizeof (frm2) < n2)
32 {
33 warn_count++;
34 Result (C_IGNORED, S_STRXFRM, CASE_9,
35 "input data n1 or n2 is invalid");
36 continue;
37 }
38
39 /* An errno and a return value are checked
40 only for 2nd strxfrm() call.
41 A result of 1st call is used for comparing
42 those 2 values by using strcmp().
43 */
44
45 /*-- First call --*/
46
47 TST_CLEAR_ERRNO;
48 ret = strxfrm (dest: frm1, src: org1, n: n1);
49 TST_SAVE_ERRNO;
50
51 if (debug_flg)
52 {
53 fprintf (stdout, "strxfrm() [ %s : %d ] ( 1st call )\n", locale,
54 rec + 1);
55 fprintf (stdout, " : err = %d | %s\n", errno_save,
56 strerror (errno));
57 fprintf (stdout, " : ret = %zu\n", ret);
58 fprintf (stdout, " : org = %s\n", org1);
59 }
60
61 if (ret >= n1 || errno != 0)
62 {
63 warn_count++;
64 Result (C_INVALID, S_STRXFRM, CASE_8,
65 "got an error in fist strxfrm() call");
66 continue;
67 }
68
69 /*-- Second call --*/
70
71 TST_CLEAR_ERRNO;
72 ret = strxfrm (dest: ((n2 == 0) ? NULL : frm2), src: org2, n: n2);
73 TST_SAVE_ERRNO;
74
75 if (debug_flg)
76 {
77 fprintf (stderr, " ..............( 2nd call )\n");
78 fprintf (stdout, " : err = %d | %s\n", errno,
79 strerror (errno));
80 fprintf (stdout, " : ret = %zu\n", ret);
81 fprintf (stdout, " : org = %s\n", org2);
82 }
83
84 TST_IF_RETURN (S_STRXFRM)
85 {
86 };
87
88 if (n2 == 0 || ret >= n2 || errno != 0)
89 {
90#if 0
91 warn_count++;
92 Result (C_IGNORED, S_STRXFRM, CASE_7, "did not get a result");
93#endif
94 continue;
95 }
96
97 /*-- strcoll & strcmp --*/
98
99 TST_CLEAR_ERRNO;
100 /* Depends on strcoll() ... not good though ... */
101 ret_coll = strcoll (org1, org2);
102
103 if (errno != 0)
104 {
105 /* bug * bug may get correct results ... */
106 warn_count++;
107 Result (C_INVALID, S_STRXFRM, CASE_6,
108 "got an error in strcoll() call");
109 continue;
110 }
111
112 ret_cmp = strcmp (frm1, frm2);
113
114 if ((ret_coll == 0 && ret_cmp == 0)
115 || (ret_coll < 0 && ret_cmp < 0) || (ret_coll > 0 && ret_cmp > 0))
116 {
117 Result (C_SUCCESS, S_STRXFRM, CASE_3,
118 MS_PASSED "(depends on strcoll & strcmp)");
119 }
120 else
121 {
122 err_count++;
123 Result (C_FAILURE, S_STRXFRM, CASE_3,
124 "results from strcoll & strcmp() do not match");
125 }
126
127 if (debug_flg)
128 {
129 fprintf (stdout, ".......... strcoll = %d <-> %d = strcmp\n",
130 ret_coll, ret_cmp);
131 }
132 }
133 }
134
135 return err_count;
136}
137

source code of glibc/localedata/tests-mbwc/tst_strxfrm.c