1 /* Test collation function via transformation using real data.
2 Copyright (C) 1997, 1998, 2000, 2003 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
35 static int xstrcmp (const void *, const void *);
38 main (int argc, char *argv[])
41 size_t nstrings, nstrings_max;
42 struct lines *strings;
48 error (1, 0, "usage: %s <random seed>", argv[0]);
50 setlocale (LC_ALL, "");
54 strings = (struct lines *) malloc (nstrings_max * sizeof (struct lines));
66 if (getline (&line, &len, stdin) < 0)
69 if (nstrings == nstrings_max)
71 strings = (struct lines *) realloc (strings,
80 strings[nstrings].line = strdup (line);
81 l = strcspn (line, ":(;");
82 while (l > 0 && isspace (line[l - 1]))
87 needed = strxfrm (NULL, line, 0);
88 newp = malloc (needed + 1);
89 strxfrm (newp, line, needed + 1);
90 strings[nstrings].xfrm = newp;
97 srandom (atoi (argv[1]));
98 for (n = 0; n < 10 * nstrings; ++n)
101 size_t idx1 = random () % nstrings;
102 size_t idx2 = random () % nstrings;
103 struct lines tmp = strings[idx1];
104 strings[idx1] = strings[idx2];
107 /* While we are at it a first little test. */
108 r1 = strcmp (strings[idx1].xfrm, strings[idx2].xfrm);
109 r2 = strcmp (strings[idx2].xfrm, strings[idx1].xfrm);
114 if (r < 0 || (r == 0 && (r1 != 0 || r2 != 0))
115 || (r > 0 && (r1 ^ r2) >= 0))
116 printf ("collate wrong: %d vs. %d\n", r1, r2);
120 qsort (strings, nstrings, sizeof (struct lines), xstrcmp);
122 /* Print the result. */
123 for (n = 0; n < nstrings; ++n)
125 fputs (strings[n].line, stdout);
126 free (strings[n].line);
127 free (strings[n].xfrm);
140 const struct lines *l1 = (const struct lines *) ptr1;
141 const struct lines *l2 = (const struct lines *) ptr2;
143 return strcmp (l1->xfrm, l2->xfrm);