1 // 2001-08-17 Benjamin Kosnik <bkoz@redhat.com>
3 // Copyright (C) 2001, 2002 Free Software Foundation
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This 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
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // 22.2.4.1.1 collate members
24 #include <testsuite_hooks.h>
26 // XXX This may not work for non-glibc locale models.
27 // { dg-do run { xfail *-*-* } }
28 #ifdef _GLIBCPP_USE_WCHAR_T
32 typedef std::collate
<wchar_t>::string_type string_type
;
37 locale loc_c
= locale::classic();
38 locale
loc_us("en_US");
39 locale
loc_fr("fr_FR");
40 locale
loc_de("de_DE");
41 VERIFY( loc_c
!= loc_de
);
42 VERIFY( loc_us
!= loc_fr
);
43 VERIFY( loc_us
!= loc_de
);
44 VERIFY( loc_de
!= loc_fr
);
46 // cache the collate facets
47 const collate
<wchar_t>& coll_c
= use_facet
<collate
<wchar_t> >(loc_c
);
48 const collate
<wchar_t>& coll_us
= use_facet
<collate
<wchar_t> >(loc_us
);
49 const collate
<wchar_t>& coll_fr
= use_facet
<collate
<wchar_t> >(loc_fr
);
50 const collate
<wchar_t>& coll_de
= use_facet
<collate
<wchar_t> >(loc_de
);
52 // int compare(const charT*, const charT*, const charT*, const charT*) const
53 // long hash(const charT*, const charT*) cosnt
54 // string_type transform(const charT*, const charT*) const
57 const wchar_t* strlit1
= L
"monkey picked tikuanyin oolong";
58 const wchar_t* strlit2
= L
"imperial tea court green oolong";
61 int size1
= char_traits
<wchar_t>::length(strlit1
) - 1;
62 i1
= coll_c
.compare(strlit1
, strlit1
+ size1
, strlit1
, strlit1
+ 7);
64 i1
= coll_c
.compare(strlit1
, strlit1
+ 7, strlit1
, strlit1
+ size1
);
66 i1
= coll_c
.compare(strlit1
, strlit1
+ 7, strlit1
, strlit1
+ 7);
70 int size2
= char_traits
<wchar_t>::length(strlit2
) - 1;
71 i2
= coll_c
.compare(strlit2
, strlit2
+ size2
, strlit2
, strlit2
+ 13);
73 i2
= coll_c
.compare(strlit2
, strlit2
+ 13, strlit2
, strlit2
+ size2
);
75 i2
= coll_c
.compare(strlit2
, strlit2
+ size2
, strlit2
, strlit2
+ size2
);
80 l1
= coll_c
.hash(strlit1
, strlit1
+ size1
);
81 l2
= coll_c
.hash(strlit1
, strlit1
+ size1
- 1);
83 l1
= coll_c
.hash(strlit1
, strlit1
+ size1
);
84 l2
= coll_c
.hash(strlit2
, strlit2
+ size2
);
87 wstring str1
= coll_c
.transform(strlit1
, strlit1
+ size1
);
88 wstring str2
= coll_c
.transform(strlit2
, strlit2
+ size2
);
89 i1
= str1
.compare(str2
);
90 i2
= coll_c
.compare(strlit1
, strlit1
+ size1
, strlit2
, strlit2
+ size2
);
92 VERIFY ( i1
* i2
> 0 );
94 // Check German "de_DE" locale.
95 const wchar_t* strlit3
= L
"Äuglein Augment"; // "C" == "Augment Äuglein"
96 const wchar_t* strlit4
= L
"Base baß Baß Bast"; // "C" == "Base baß Baß Bast"
98 int size3
= char_traits
<wchar_t>::length(strlit3
) - 1;
99 i1
= coll_de
.compare(strlit3
, strlit3
+ size3
, strlit3
, strlit3
+ 7);
101 i1
= coll_de
.compare(strlit3
, strlit3
+ 7, strlit3
, strlit3
+ size1
);
103 i1
= coll_de
.compare(strlit3
, strlit3
+ 7, strlit3
, strlit3
+ 7);
106 i1
= coll_de
.compare(strlit3
, strlit3
+ 6, strlit3
+ 8, strlit3
+ 14);
109 int size4
= char_traits
<wchar_t>::length(strlit4
) - 1;
110 i2
= coll_de
.compare(strlit4
, strlit4
+ size4
, strlit4
, strlit4
+ 13);
112 i2
= coll_de
.compare(strlit4
, strlit4
+ 13, strlit4
, strlit4
+ size4
);
114 i2
= coll_de
.compare(strlit4
, strlit4
+ size4
, strlit4
, strlit4
+ size4
);
117 l1
= coll_de
.hash(strlit3
, strlit3
+ size3
);
118 l2
= coll_de
.hash(strlit3
, strlit3
+ size3
- 1);
120 l1
= coll_de
.hash(strlit3
, strlit3
+ size3
);
121 l2
= coll_de
.hash(strlit4
, strlit4
+ size4
);
124 wstring str3
= coll_de
.transform(strlit3
, strlit3
+ size3
);
125 wstring str4
= coll_de
.transform(strlit4
, strlit4
+ size4
);
126 i1
= str3
.compare(str4
);
127 i2
= coll_de
.compare(strlit3
, strlit3
+ size3
, strlit4
, strlit4
+ size4
);
129 VERIFY ( i1
* i2
> 0 );
135 #ifdef _GLIBCPP_HAVE_SETENV
136 // Set the global locale to non-"C".
137 std::locale
loc_de("de_DE");
138 std::locale::global(loc_de
);
140 // Set LANG environment variable to de_DE.
141 const char* oldLANG
= getenv("LANG");
142 if (!setenv("LANG", "de_DE", 1))
145 setenv("LANG", oldLANG
? oldLANG
: "", 1);
153 std::wstring
str1(L
"fffff");
154 std::wstring
str2(L
"ffffffffffff");
156 const std::locale cloc
= std::locale::classic();
157 const std::collate
<wchar_t> &col
= std::use_facet
<std::collate
<wchar_t> >(cloc
);
159 long l1
= col
.hash(str1
.c_str(), str1
.c_str() + str1
.size());
160 long l2
= col
.hash(str2
.c_str(), str2
.c_str() + str2
.size());
164 // http://gcc.gnu.org/ml/libstdc++/2002-05/msg00038.html
169 std::string loc1
= setlocale(LC_ALL
, "ja_JP.eucjp");
172 std::string loc2
= setlocale(LC_ALL
, NULL
);
173 VERIFY( loc1
== loc2
);
179 #if _GLIBCPP_USE_WCHAR_T