summaryrefslogtreecommitdiff
path: root/test/locale-mbwc/tst_mbtowc.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_mbtowc.c
parenta691312d8794d5516402bb6bb0d3e90c40ba188b (diff)
Added missing tests for locale with multibyte encoding
Diffstat (limited to 'test/locale-mbwc/tst_mbtowc.c')
-rw-r--r--test/locale-mbwc/tst_mbtowc.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/test/locale-mbwc/tst_mbtowc.c b/test/locale-mbwc/tst_mbtowc.c
new file mode 100644
index 000000000..7c274f66c
--- /dev/null
+++ b/test/locale-mbwc/tst_mbtowc.c
@@ -0,0 +1,130 @@
+/*
+ MBTOWC: int mbtowc (wchar_t *wc, char *s, size_t n)
+*/
+
+#define TST_FUNCTION mbtowc
+
+#include "tsp_common.c"
+#include "dat_mbtowc.c"
+
+
+int
+tst_mbtowc (FILE * fp, int debug_flg)
+{
+ TST_DECL_VARS (int);
+ char w_flg, s_flg;
+ const char *s_in;
+ size_t n;
+ wchar_t wc, wc_ex, *wp;
+
+ TST_DO_TEST (mbtowc)
+ {
+ TST_HEAD_LOCALE (mbtowc, S_MBTOWC);
+ TST_DO_REC (mbtowc)
+ {
+ if (mbstowcs (NULL, "", 0) != 0)
+ {
+ err_count++;
+ Result (C_FAILURE, S_MBSTOWCS, CASE_3,
+ "Initialization failed - skipping this test case.");
+ continue;
+ }
+
+ TST_DO_SEQ (MBTOWC_SEQNUM)
+ {
+ TST_GET_ERRET_SEQ (mbtowc);
+ w_flg = TST_INPUT_SEQ (mbtowc).w_flg;
+ s_flg = TST_INPUT_SEQ (mbtowc).s_flg;
+ n = TST_INPUT_SEQ (mbtowc).n;
+
+ if (n == USE_MBCURMAX)
+ {
+ n = MB_CUR_MAX;
+ }
+
+ if (s_flg == 0)
+ s_in = NULL;
+ else
+ s_in = TST_INPUT_SEQ (mbtowc).s;
+
+ wp = (wchar_t *) ((w_flg == 0) ? NULL : &wc);
+
+ /* XXX Clear the internal state. We should probably have
+ a flag for this. */
+ mbtowc (NULL, NULL, 0);
+
+ TST_CLEAR_ERRNO;
+ ret = mbtowc (wp, s_in, n);
+ TST_SAVE_ERRNO;
+
+ if (debug_flg)
+ {
+ fprintf (stdout, "mbtowc() [ %s : %d ] ret = %d\n", locale,
+ rec + 1, ret);
+ fprintf (stdout, " errno = %d\n",
+ errno_save);
+ }
+
+ TST_IF_RETURN (S_MBTOWC)
+ {
+ if (s_in == NULL)
+ { /* state dependency */
+ if (ret_exp == +1)
+ { /* state-dependent */
+ if (ret != 0)
+ {
+ /* Non-zero: state-dependent encoding. */
+ Result (C_SUCCESS, S_MBTOWC, CASE_3, MS_PASSED);
+ }
+ else
+ {
+ err_count++;
+ Result (C_FAILURE, S_MBTOWC, CASE_3,
+ "should be state-dependent encoding, "
+ "but a return value shows it is "
+ "state-independent");
+ }
+ }
+
+ if (ret_exp == 0)
+ { /* state-independent */
+ if (ret == 0)
+ {
+ /* Non-zero: state-dependent encoding. */
+ Result (C_SUCCESS, S_MBTOWC, CASE_3, MS_PASSED);
+ }
+ else
+ {
+ err_count++;
+ Result (C_FAILURE, S_MBTOWC, CASE_3,
+ "should be state-independent encoding, "
+ "but a return value shows it is "
+ "state-dependent");
+ }
+ }
+ }
+ }
+
+ if ((wp == NULL || s_in == NULL || s_in[0] == 0) || ret <= 0)
+ {
+ continue;
+ }
+
+ wc_ex = TST_EXPECT_SEQ (mbtowc).wc;
+
+ if (wc_ex == wc)
+ {
+ Result (C_SUCCESS, S_MBTOWC, CASE_4, MS_PASSED);
+ }
+ else
+ {
+ err_count++;
+ Result (C_FAILURE, S_MBTOWC, CASE_4,
+ "converted wc is different from an expected wc");
+ }
+ }
+ }
+ }
+
+ return err_count;
+}