aboutsummaryrefslogtreecommitdiff
blob: 6fb8a1c28d6f942a4eefbc0bd6a36c7535038a6d (plain)
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
  WCSXFRM: size_t wcsxfrm (wchar_t *ws1, const wchar_t *ws2, size_t n);
*/

#define TST_FUNCTION wcsxfrm

#include "tsp_common.c"
#include "dat_wcsxfrm.c"

int
tst_wcsxfrm (FILE * fp, int debug_flg)
{
  TST_DECL_VARS (size_t);
  wchar_t *org1, *org2;
  wchar_t frm1[MBSSIZE], frm2[MBSSIZE];
  size_t n1, n2;
  int ret_coll, ret_cmp;

  TST_DO_TEST (wcsxfrm)
  {
    TST_HEAD_LOCALE (wcsxfrm, S_WCSXFRM);
    TST_DO_REC (wcsxfrm)
    {
      TST_GET_ERRET (wcsxfrm);
      org1 = TST_INPUT (wcsxfrm).org1;
      org2 = TST_INPUT (wcsxfrm).org2;
      n1 = TST_INPUT (wcsxfrm).n1;
      n2 = TST_INPUT (wcsxfrm).n2;
      if (n1 < 0 || sizeof (frm1) < n1 || sizeof (frm2) < n2)
	{
	  warn_count++;
	  Result (C_IGNORED, S_WCSXFRM, CASE_9,
		  "input data n1 or n2 is invalid");
	  continue;
	}

      /* an errno and a return value are checked
	 only for 2nd wcsxfrm() call.
	 A result of 1st call is used to compare
	 those 2 values by using wcscmp().
       */

      TST_CLEAR_ERRNO;
      ret = wcsxfrm (frm1, org1, n1);	/* First call */
      TST_SAVE_ERRNO;

      if (debug_flg)
	{
	  fprintf (stdout, "tst_wcsxfrm() : REC = %d\n", rec + 1);
	  fprintf (stdout, "tst_wcsxfrm() : 1st ret = %zu\n", ret);
	}

      if (ret == -1 || ret >= n1 || errno_save != 0)
	{
	  warn_count++;
	  Result (C_INVALID, S_WCSXFRM, CASE_8,
		  "got an error in fist wcsxfrm() call");
	  continue;
	}

      TST_CLEAR_ERRNO;
      /* Second call */
      ret = wcsxfrm (((n2 == 0) ? NULL : frm2), org2, n2);
      TST_SAVE_ERRNO;

      TST_IF_RETURN (S_WCSXFRM)
      {
      };

      if (n2 == 0 || ret >= n2 || errno != 0)
	{
#if 0
	  warn_count++;
	  Result (C_IGNORED, S_WCSXFRM, CASE_7, "did not get a result");
#endif
	  continue;
	}

      if (debug_flg)
	{
	  fprintf (stdout, "tst_wcsxfrm() : 2nd ret = %zu\n", ret);
	}

      /* wcscoll() */
      TST_CLEAR_ERRNO;
      /* depends on wcscoll() ... not good though ... */
      ret_coll = wcscoll (org1, org2);
      TST_SAVE_ERRNO;

      if (errno != 0)		/* bugs * bugs may got correct results ... */
	{
	  warn_count++;
	  Result (C_INVALID, S_WCSXFRM, CASE_6,
		  "got an error in wcscoll() call");
	  continue;
	}
      /* wcscmp() */
      ret_cmp = wcscmp (frm1, frm2);

      if ((ret_coll == ret_cmp) || (ret_coll > 0 && ret_cmp > 0)
	  || (ret_coll < 0 && ret_cmp < 0))
	{
	  Result (C_SUCCESS, S_WCSXFRM, CASE_3,
		  MS_PASSED " (depends on wcscoll & wcscmp)");
	}
      else
	{
	  err_count++;
	  Result (C_FAILURE, S_WCSXFRM, CASE_3,
		  "results from wcscoll & wcscmp() do not match");
	}

      if (debug_flg)
	{
	  fprintf (stdout, "tst_wcsxfrm() : coll = %d <-> %d = cmp\n",
		   ret_coll, ret_cmp);
	}
    }
  }

  return err_count;
}