summary refs log tree commit diff
path: root/localedata/tests-mbwc/tst_wcstok.c
blob: 1222b97855dca8b91632f470cd05b467edce8583 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
  WCSTOK: wchar_t *wcstok (wchar_t *ws, const wchar_t *dlm, wchar_t **pt);
*/


#define TST_FUNCTION wcstok

#include "tsp_common.c"
#include "dat_wcstok.c"

int
tst_wcstok (FILE * fp, int debug_flg)
{
  TST_DECL_VARS (wchar_t *);
  char w_flg;
  wchar_t *ws;
  wchar_t *dt, *pt;
  wchar_t *ws_ex;
  int err, i;

  TST_DO_TEST (wcstok)
  {
    TST_HEAD_LOCALE (wcstok, S_WCSTOK);
    TST_DO_REC (wcstok)
    {
      TST_DO_SEQ (WCSTOK_SEQNUM)
      {
	TST_GET_ERRET_SEQ (wcstok);
	w_flg = TST_INPUT_SEQ (wcstok).w_flg;
	ws = (w_flg) ? TST_INPUT_SEQ (wcstok).ws : NULL;
	dt = TST_INPUT_SEQ (wcstok).dt;

	ret = wcstok (ws, dt, &pt);

	if (debug_flg)
	  {
	    fprintf (stdout, "wcstok() [ %s : %d : %d ] *ret  = 0x%lx\n",
		     locale, rec + 1, seq_num + 1, (unsigned long int) *ret);
	    if (pt && *pt)
	      {
		fprintf (stdout, "			 *pt   = 0x%lx\n",
			 (unsigned long int) *pt);
	      }
	  }

	TST_IF_RETURN (S_WCSTOK)
	{
	};

	if (ret != NULL)
	  {
	    ws_ex = TST_EXPECT_SEQ (wcstok).ws;

	    /* XXX: REVISIT : insufficient conditions */
	    for (err = 0, i = 0; i < WCSSIZE; i++)
	      {
		if (ret[i] == L'\0' && ws_ex[i] == L'\0')
		  {
		    break;
		  }

		if (debug_flg)
		  {
		    fprintf (stderr,
			     "			      ret[%d] = 0x%lx <-> "
			     "0x%lx = ws_ex[%d]\n",
			     i, (unsigned long int) ret[i],
			     (unsigned long int) ws_ex[i], i);
		  }

		if (ret[i] != ws_ex[i])
		  {
		    err++;
		    err_count++;
		    Result (C_FAILURE, S_WCSTOK, CASE_3,
			    "the token is different from an expected string");
		    break;
		  }

		if (ret[i] == L'\0' || ws_ex[i] == L'\0')
		  {
		    break;
		  }
	      }

	    if (!err)
	      {
		Result (C_SUCCESS, S_WCSTOK, CASE_3, MS_PASSED);
	      }
	  }
      }
    }
  }

  return err_count;
}