]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/22_locale/collate_byname/named_equivalence.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / collate_byname / named_equivalence.cc
1 // { dg-require-namedlocale "de_DE.ISO8859-15" }
2
3 // 2001-08-15 Benjamin Kosnik <bkoz@redhat.com>
4
5 // Copyright (C) 2001-2020 Free Software Foundation, Inc.
6 //
7 // This file is part of the GNU ISO C++ Library. This library is free
8 // software; you can redistribute it and/or modify it under the
9 // terms of the GNU General Public License as published by the
10 // Free Software Foundation; either version 3, or (at your option)
11 // any later version.
12
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 // GNU General Public License for more details.
17
18 // You should have received a copy of the GNU General Public License along
19 // with this library; see the file COPYING3. If not see
20 // <http://www.gnu.org/licenses/>.
21
22 // 22.2.4.2 Template class collate_byname
23
24 #include <locale>
25 #include <cstring>
26 #include <testsuite_hooks.h>
27
28 void test01()
29 {
30 using namespace std;
31 typedef std::collate<char>::string_type string_type;
32
33 string str;
34 locale loc_c = locale::classic();
35
36 locale loc_de = locale(ISO_8859(15,de_DE));
37 str = loc_de.name();
38
39 locale loc_byname(locale::classic(), new collate_byname<char>(ISO_8859(15,de_DE)));
40 str = loc_byname.name();
41
42 VERIFY( loc_de != loc_byname );
43
44 // cache the collate facets
45 const collate<char>& coll_de = use_facet<collate<char> >(loc_de);
46
47 // Check German "de_DE.ISO8859-15" locale.
48 int i1;
49 int i2;
50 long l1;
51 long l2;
52 const char* strlit3 = "Äuglein Augment"; // "C" == "Augment Äuglein"
53 const char* strlit4 = "Base baß Baß Bast"; // "C" == "Base baß Baß Bast"
54
55 int size3 = strlen(strlit3) - 1;
56 i1 = coll_de.compare(strlit3, strlit3 + size3, strlit3, strlit3 + 7);
57 VERIFY ( i1 == 1 );
58 i1 = coll_de.compare(strlit3, strlit3 + 7, strlit3, strlit3 + size3);
59 VERIFY ( i1 == -1 );
60 i1 = coll_de.compare(strlit3, strlit3 + 7, strlit3, strlit3 + 7);
61 VERIFY ( i1 == 0 );
62
63 i1 = coll_de.compare(strlit3, strlit3 + 6, strlit3 + 8, strlit3 + 14);
64 VERIFY ( i1 == -1 );
65
66 int size4 = strlen(strlit4) - 1;
67 i2 = coll_de.compare(strlit4, strlit4 + size4, strlit4, strlit4 + 13);
68 VERIFY ( i2 == 1 );
69 i2 = coll_de.compare(strlit4, strlit4 + 13, strlit4, strlit4 + size4);
70 VERIFY ( i2 == -1 );
71 i2 = coll_de.compare(strlit4, strlit4 + size4, strlit4, strlit4 + size4);
72 VERIFY ( i2 == 0 );
73
74 l1 = coll_de.hash(strlit3, strlit3 + size3);
75 l2 = coll_de.hash(strlit3, strlit3 + size3 - 1);
76 VERIFY ( l1 != l2 );
77 l1 = coll_de.hash(strlit3, strlit3 + size3);
78 l2 = coll_de.hash(strlit4, strlit4 + size4);
79 VERIFY ( l1 != l2 );
80
81 string str3 = coll_de.transform(strlit3, strlit3 + size3);
82 string str4 = coll_de.transform(strlit4, strlit4 + size4);
83 i1 = str3.compare(str4);
84 i2 = coll_de.compare(strlit3, strlit3 + size3, strlit4, strlit4 + size4);
85 VERIFY ( i2 == -1 );
86 VERIFY ( i1 * i2 > 0 );
87
88
89 // Check byname locale
90 int i3;
91 int i4;
92 long l3;
93 long l4;
94 size4 = strlen(strlit3) - 1;
95 i3 = coll_de.compare(strlit3, strlit3 + size4, strlit3, strlit3 + 7);
96 VERIFY ( i3 == 1 );
97 i3 = coll_de.compare(strlit3, strlit3 + 7, strlit3, strlit3 + size4);
98 VERIFY ( i3 == -1 );
99 i3 = coll_de.compare(strlit3, strlit3 + 7, strlit3, strlit3 + 7);
100 VERIFY ( i3 == 0 );
101
102 i3 = coll_de.compare(strlit3, strlit3 + 6, strlit3 + 8, strlit3 + 14);
103 VERIFY ( i3 == -1 );
104
105 size4 = strlen(strlit4) - 1;
106 i4 = coll_de.compare(strlit4, strlit4 + size4, strlit4, strlit4 + 13);
107 VERIFY ( i4 == 1 );
108 i4 = coll_de.compare(strlit4, strlit4 + 13, strlit4, strlit4 + size4);
109 VERIFY ( i4 == -1 );
110 i4 = coll_de.compare(strlit4, strlit4 + size4, strlit4, strlit4 + size4);
111 VERIFY ( i4 == 0 );
112
113 l3 = coll_de.hash(strlit3, strlit3 + size4);
114 l4 = coll_de.hash(strlit3, strlit3 + size4 - 1);
115 VERIFY ( l3 != l4 );
116 l3 = coll_de.hash(strlit3, strlit3 + size4);
117 l4 = coll_de.hash(strlit4, strlit4 + size4);
118 VERIFY ( l3 != l4 );
119
120 string str5 = coll_de.transform(strlit3, strlit3 + size3);
121 string str6 = coll_de.transform(strlit4, strlit4 + size4);
122 i3 = str5.compare(str6);
123 i4 = coll_de.compare(strlit3, strlit3 + size4, strlit4, strlit4 + size4);
124 VERIFY ( i4 == -1 );
125 VERIFY ( i3 * i4 > 0 );
126
127 // Verify byname == de
128 VERIFY ( str5 == str3 );
129 VERIFY ( str6 == str4 );
130 }
131
132 int main()
133 {
134 test01();
135 return 0;
136 }