summaryrefslogtreecommitdiff
path: root/test/locale-mbwc/tst_strxfrm.c
diff options
context:
space:
mode:
authorCarmelo Amoroso <carmelo.amoroso@st.com>2008-07-10 10:30:28 +0000
committerCarmelo Amoroso <carmelo.amoroso@st.com>2008-07-10 10:30:28 +0000
commitbb9231c8402e9ae99f98a868429e73c6340da304 (patch)
treed7ed637099fba4ab6db1cc4c009cad8485dcdb66 /test/locale-mbwc/tst_strxfrm.c
parenta691312d8794d5516402bb6bb0d3e90c40ba188b (diff)
Added missing tests for locale with multibyte encoding
Diffstat (limited to 'test/locale-mbwc/tst_strxfrm.c')
-rw-r--r--test/locale-mbwc/tst_strxfrm.c136
1 files changed, 136 insertions, 0 deletions
diff --git a/test/locale-mbwc/tst_strxfrm.c b/test/locale-mbwc/tst_strxfrm.c
new file mode 100644
index 000000000..fdfeffc89
--- /dev/null
+++ b/test/locale-mbwc/tst_strxfrm.c
@@ -0,0 +1,136 @@
+/*
+ STRXFRM: size_t strxfrm (char *s1, const char *s2, size_t n)
+*/
+
+#define TST_FUNCTION strxfrm
+
+#include "tsp_common.c"
+#include "dat_strxfrm.c"
+
+
+int
+tst_strxfrm (FILE * fp, int debug_flg)
+{
+ TST_DECL_VARS (size_t);
+ const char *org1, *org2;
+ char frm1[MBSSIZE], frm2[MBSSIZE];
+ size_t n1, n2;
+ int ret_coll, ret_cmp;
+
+ TST_DO_TEST (strxfrm)
+ {
+ TST_HEAD_LOCALE (strxfrm, S_STRXFRM);
+ TST_DO_REC (strxfrm)
+ {
+ TST_GET_ERRET (strxfrm);
+ org1 = TST_INPUT (strxfrm).org1;
+ org2 = TST_INPUT (strxfrm).org2;
+ n1 = TST_INPUT (strxfrm).n1;
+ n2 = TST_INPUT (strxfrm).n2;
+
+ if (n1 < 0 || sizeof (frm1) < n1 || sizeof (frm2) < n2)
+ {
+ warn_count++;
+ Result (C_IGNORED, S_STRXFRM, CASE_9,
+ "input data n1 or n2 is invalid");
+ continue;
+ }
+
+ /* An errno and a return value are checked
+ only for 2nd strxfrm() call.
+ A result of 1st call is used for comparing
+ those 2 values by using strcmp().
+ */
+
+ /*-- First call --*/
+
+ TST_CLEAR_ERRNO;
+ ret = strxfrm (frm1, org1, n1);
+ TST_SAVE_ERRNO;
+
+ if (debug_flg)
+ {
+ fprintf (stdout, "strxfrm() [ %s : %d ] ( 1st call )\n", locale,
+ rec + 1);
+ fprintf (stdout, " : err = %d | %s\n", errno_save,
+ strerror (errno));
+ fprintf (stdout, " : ret = %zu\n", ret);
+ fprintf (stdout, " : org = %s\n", org1);
+ }
+
+ if (ret >= n1 || errno != 0)
+ {
+ warn_count++;
+ Result (C_INVALID, S_STRXFRM, CASE_8,
+ "got an error in fist strxfrm() call");
+ continue;
+ }
+
+ /*-- Second call --*/
+
+ TST_CLEAR_ERRNO;
+ ret = strxfrm (((n2 == 0) ? NULL : frm2), org2, n2);
+ TST_SAVE_ERRNO;
+
+ if (debug_flg)
+ {
+ fprintf (stderr, " ..............( 2nd call )\n");
+ fprintf (stdout, " : err = %d | %s\n", errno,
+ strerror (errno));
+ fprintf (stdout, " : ret = %zu\n", ret);
+ fprintf (stdout, " : org = %s\n", org2);
+ }
+
+ TST_IF_RETURN (S_STRXFRM)
+ {
+ };
+
+ if (n2 == 0 || ret >= n2 || errno != 0)
+ {
+#if 0
+ warn_count++;
+ Result (C_IGNORED, S_STRXFRM, CASE_7, "did not get a result");
+#endif
+ continue;
+ }
+
+ /*-- strcoll & strcmp --*/
+
+ TST_CLEAR_ERRNO;
+ /* Depends on strcoll() ... not good though ... */
+ ret_coll = strcoll (org1, org2);
+
+ if (errno != 0)
+ {
+ /* bug * bug may get correct results ... */
+ warn_count++;
+ Result (C_INVALID, S_STRXFRM, CASE_6,
+ "got an error in strcoll() call");
+ continue;
+ }
+
+ ret_cmp = strcmp (frm1, frm2);
+
+ if ((ret_coll == 0 && ret_cmp == 0)
+ || (ret_coll < 0 && ret_cmp < 0) || (ret_coll > 0 && ret_cmp > 0))
+ {
+ Result (C_SUCCESS, S_STRXFRM, CASE_3,
+ MS_PASSED "(depends on strcoll & strcmp)");
+ }
+ else
+ {
+ err_count++;
+ Result (C_FAILURE, S_STRXFRM, CASE_3,
+ "results from strcoll & strcmp() do not match");
+ }
+
+ if (debug_flg)
+ {
+ fprintf (stdout, ".......... strcoll = %d <-> %d = strcmp\n",
+ ret_coll, ret_cmp);
+ }
+ }
+ }
+
+ return err_count;
+}