1 // 2001-08-15 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 *-*-* } }
32 typedef std::collate<char>::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<char>& coll_c = use_facet<collate<char> >(loc_c);
48 const collate<char>& coll_us = use_facet<collate<char> >(loc_us);
49 const collate<char>& coll_fr = use_facet<collate<char> >(loc_fr);
50 const collate<char>& coll_de = use_facet<collate<char> >(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 char* strlit1 = "monkey picked tikuanyin oolong";
58 const char* strlit2 = "imperial tea court green oolong";
61 int size1 = strlen(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 = strlen(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 string str1 = coll_c.transform(strlit1, strlit1 + size1);
88 string str2 = coll_c.transform(strlit2, strlit2 + size2);
89 i1 = coll_c.compare(str1.c_str(), str1.c_str() + size1,
90 str2.c_str(), str2.c_str() + size2);
91 i2 = coll_c.compare(strlit1, strlit1 + size1, strlit2, strlit2 + size2);
94 // Check German "de_DE" locale.
95 const char* strlit3 = "Äuglein Augment"; // "C" == "Augment Äuglein"
96 const char* strlit4 = "Base baß Baß Bast"; // "C" == "Base baß Baß Bast"
98 int size3 = strlen(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 = strlen(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 string str3 = coll_de.transform(strlit3, strlit3 + size3);
125 string str4 = coll_de.transform(strlit4, strlit4 + size4);
126 i1 = coll_de.compare(str3.c_str(), str3.c_str() + size3,
127 str4.c_str(), str4.c_str() + size4);
128 i2 = coll_de.compare(strlit3, strlit3 + size3, strlit4, strlit4 + size4);
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, 1);