about summary refs log tree commit diff
path: root/localedata/tests-mbwc/tst_strxfrm.c
blob: 837ee8c94703fb5e09c3ebe20a7b0cc7f5e74879 (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
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
123
124
125
126
127
128
129
130
131
132
133
/*
  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)
	{
	  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)
	{
	  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 ...	  */
	  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;
}