a6255afb6c36725500a502ad441f12d66005b0f9
[gcc.git] / libstdc++-v3 / testsuite / 22_locale / collate / transform / char / 3.cc
1 // 2003-02-24 Petur Runolfsson <peturr02@ru.is>
2
3 // Copyright (C) 2003 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 void test03()
27 {
28 using namespace std;
29 typedef std::collate<char>::string_type string_type;
30
31 bool test = true;
32
33 // basic construction
34 locale loc_c = locale::classic();
35 locale loc_de("de_DE");
36 VERIFY( loc_c != loc_de );
37
38 // cache the collate facets
39 const collate<char>& coll_c = use_facet<collate<char> >(loc_c);
40 const collate<char>& coll_de = use_facet<collate<char> >(loc_de);
41
42 const char* strlit1 = "a\0a\0";
43 const char* strlit2 = "a\0b\0";
44 const char* strlit3 = "a\0\xc4\0";
45 const char* strlit4 = "a\0B\0";
46 const char* strlit5 = "aa\0";
47 const char* strlit6 = "b\0a\0";
48
49 int i;
50 string_type str1;
51 string_type str2;
52
53 str1 = coll_c.transform(strlit1, strlit1 + 3);
54 str2 = coll_c.transform(strlit2, strlit2 + 3);
55 i = str1.compare(str2);
56 VERIFY( i < 0 );
57
58 str1 = coll_de.transform(strlit1, strlit1 + 3);
59 str2 = coll_de.transform(strlit2, strlit2 + 3);
60 i = str1.compare(str2);
61 VERIFY( i < 0 );
62
63 str1 = coll_c.transform(strlit3, strlit3 + 3);
64 str2 = coll_c.transform(strlit4, strlit4 + 3);
65 i = str1.compare(str2);
66 VERIFY( i > 0 );
67
68 str1 = coll_de.transform(strlit3, strlit3 + 3);
69 str2 = coll_de.transform(strlit4, strlit4 + 3);
70 i = str1.compare(str2);
71 VERIFY( i < 0 );
72
73 str1 = coll_c.transform(strlit1, strlit1 + 1);
74 str2 = coll_c.transform(strlit5, strlit5 + 1);
75 i = str1.compare(str2);
76 VERIFY( i == 0 );
77
78 str1 = coll_de.transform(strlit6, strlit6 + 3);
79 str2 = coll_de.transform(strlit1, strlit1 + 3);
80 i = str1.compare(str2);
81 VERIFY( i > 0 );
82
83 str1 = coll_c.transform(strlit1, strlit1 + 3);
84 str2 = coll_c.transform(strlit5, strlit5 + 3);
85 i = str1.compare(str2);
86 VERIFY( i < 0 );
87 }
88
89 int main()
90 {
91 test03();
92 return 0;
93 }