2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libstdc++-v3 / testsuite / 22_locale / collate / compare / wchar_t / 3.cc
blob209f7f835e3194636ed42cd9735cb5e58fb9b9e6
1 // 2003-02-24 Petur Runolfsson <peturr02@ru.is>
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.
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,
19 // USA.
21 // 22.2.4.1.1 collate members
23 #include <locale>
24 #include <testsuite_hooks.h>
26 // Test handling of strings containing nul characters
27 void test03()
29 using namespace std;
30 typedef std::collate<wchar_t>::string_type string_type;
32 bool test __attribute__((unused)) = true;
34 // basic construction
35 locale loc_c = locale::classic();
36 locale loc_de = __gnu_test::try_named_locale("de_DE");
37 VERIFY( loc_c != loc_de );
39 // cache the collate facets
40 const collate<wchar_t>& coll_c = use_facet<collate<wchar_t> >(loc_c);
41 const collate<wchar_t>& coll_de = use_facet<collate<wchar_t> >(loc_de);
43 // int compare(const charT*, const charT*, const charT*, const charT*) const
44 const wchar_t* strlit1 = L"a\0a\0";
45 const wchar_t* strlit2 = L"a\0b\0";
46 const wchar_t* strlit3 = L"a\0\xc4\0";
47 const wchar_t* strlit4 = L"a\0B\0";
48 const wchar_t* strlit5 = L"aa\0";
49 const wchar_t* strlit6 = L"b\0a\0";
51 int i;
52 i = coll_c.compare(strlit1, strlit1 + 3, strlit2, strlit2 + 3);
53 VERIFY( i == -1 );
55 i = coll_de.compare(strlit1, strlit1 + 3, strlit2, strlit2 + 3);
56 VERIFY( i == -1 );
58 i = coll_c.compare(strlit3, strlit3 + 3, strlit4, strlit4 + 3);
59 VERIFY( i == 1 );
61 i = coll_de.compare(strlit3, strlit3 + 3, strlit4, strlit4 + 3);
62 VERIFY( i == -1 );
64 i = coll_c.compare(strlit1, strlit1 + 3, strlit1, strlit1 + 4);
65 VERIFY( i == -1 );
67 i = coll_de.compare(strlit3, strlit3 + 4, strlit3, strlit3 + 3);
68 VERIFY( i == 1 );
70 i = coll_c.compare(strlit1, strlit1 + 4, strlit4, strlit4 + 1);
71 VERIFY( i == 1 );
73 i = coll_de.compare(strlit3, strlit3 + 3, strlit3, strlit3 + 3);
74 VERIFY( i == 0 );
76 i = coll_c.compare(strlit1, strlit1 + 2, strlit1, strlit1 + 4);
77 VERIFY( i == -1 );
79 i = coll_de.compare(strlit1, strlit1 + 3, strlit5, strlit5 + 3);
80 VERIFY( i == -1 );
82 i = coll_c.compare(strlit6, strlit6 + 3, strlit1, strlit1 + 3);
83 VERIFY( i == 1 );
86 int main()
88 test03();
89 return 0;