OSDN Git Service

* c-lex.c (yyparse): Call debug_hooks->start_source_file for
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / 22_locale / collate_members_char.cc
1 // 2001-08-15 Benjamin Kosnik  <bkoz@redhat.com>
2
3 // Copyright (C) 2001, 2002 Free Software Foundation
4 //
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)
9 // any later version.
10
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.
15
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,
19 // USA.
20
21 // 22.2.4.1.1 collate members
22
23 #include <locale>
24 #include <testsuite_hooks.h>
25
26 // XXX This may not work for non-glibc locale models.
27 // { dg-do run { xfail *-*-* } }
28
29 void test01()
30 {
31   using namespace std;
32   typedef std::collate<char>::string_type string_type;
33
34   bool test = true;
35
36   // basic construction
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 );
45
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); 
51
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
55
56   // Check "C" locale.
57   const char* strlit1 = "monkey picked tikuanyin oolong";
58   const char* strlit2 = "imperial tea court green oolong";
59
60   int i1;
61   int size1 = strlen(strlit1) - 1;
62   i1 = coll_c.compare(strlit1, strlit1 + size1, strlit1, strlit1 + 7);
63   VERIFY ( i1 > 0 );
64   i1 = coll_c.compare(strlit1, strlit1 + 7, strlit1, strlit1 + size1);
65   VERIFY ( i1 < 0 );
66   i1 = coll_c.compare(strlit1, strlit1 + 7, strlit1, strlit1 + 7);
67   VERIFY ( i1 == 0 );
68
69   int i2;
70   int size2 = strlen(strlit2) - 1;
71   i2 = coll_c.compare(strlit2, strlit2 + size2, strlit2, strlit2 + 13);
72   VERIFY ( i2 > 0 );
73   i2 = coll_c.compare(strlit2, strlit2 + 13, strlit2, strlit2 + size2);
74   VERIFY ( i2 < 0 );
75   i2 = coll_c.compare(strlit2, strlit2 + size2, strlit2, strlit2 + size2);
76   VERIFY ( i2 == 0 );
77
78   long l1;
79   long l2;
80   l1 = coll_c.hash(strlit1, strlit1 + size1);
81   l2 = coll_c.hash(strlit1, strlit1 + size1 - 1);
82   VERIFY ( l1 != l2 );
83   l1 = coll_c.hash(strlit1, strlit1 + size1);
84   l2 = coll_c.hash(strlit2, strlit2 + size2);
85   VERIFY ( l1 != l2 );
86
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);
92   VERIFY(i1 == i2);
93
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"
97
98   int size3 = strlen(strlit3) - 1;
99   i1 = coll_de.compare(strlit3, strlit3 + size3, strlit3, strlit3 + 7);
100   VERIFY ( i1 > 0 );
101   i1 = coll_de.compare(strlit3, strlit3 + 7, strlit3, strlit3 + size1);
102   VERIFY ( i1 < 0 );
103   i1 = coll_de.compare(strlit3, strlit3 + 7, strlit3, strlit3 + 7);
104   VERIFY ( i1 == 0 );
105
106   i1 = coll_de.compare(strlit3, strlit3 + 6, strlit3 + 8, strlit3 + 14);
107   VERIFY ( i1 < 0 );
108
109   int size4 = strlen(strlit4) - 1;
110   i2 = coll_de.compare(strlit4, strlit4 + size4, strlit4, strlit4 + 13);
111   VERIFY ( i2 > 0 );
112   i2 = coll_de.compare(strlit4, strlit4 + 13, strlit4, strlit4 + size4);
113   VERIFY ( i2 < 0 );
114   i2 = coll_de.compare(strlit4, strlit4 + size4, strlit4, strlit4 + size4);
115   VERIFY ( i2 == 0 );
116
117   l1 = coll_de.hash(strlit3, strlit3 + size3);
118   l2 = coll_de.hash(strlit3, strlit3 + size3 - 1);
119   VERIFY ( l1 != l2 );
120   l1 = coll_de.hash(strlit3, strlit3 + size3);
121   l2 = coll_de.hash(strlit4, strlit4 + size4);
122   VERIFY ( l1 != l2 );
123
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);
129   VERIFY(i1 == i2);
130 }
131
132 // libstdc++/5280
133 void test02()
134 {
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);
139
140   // Set LANG environment variable to de_DE.
141   const char* oldLANG = getenv("LANG");
142   if (!setenv("LANG", "de_DE", 1))
143     {
144       test01();
145       setenv("LANG", oldLANG, 1);
146     }
147 #endif
148 }
149
150 int main()
151 {
152   test01();
153   test02();
154   return 0;
155 }
156
157
158