]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/22_locale/collate/compare/wchar_t/3.cc
*: Change __gnu_cxx_test to __gnu_test.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 22_locale / collate / compare / wchar_t / 3.cc
CommitLineData
5040d691
PR
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// Test handling of strings containing nul characters
27void test03()
28{
29 using namespace std;
30 typedef std::collate<wchar_t>::string_type string_type;
31
32 bool test = true;
33
34 // basic construction
35 locale loc_c = locale::classic();
aecf642c 36 locale loc_de = __gnu_test::try_named_locale("de_DE");
5040d691
PR
37 VERIFY( loc_c != loc_de );
38
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);
42
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";
50
51 int i;
52 i = coll_c.compare(strlit1, strlit1 + 3, strlit2, strlit2 + 3);
53 VERIFY( i == -1 );
54
55 i = coll_de.compare(strlit1, strlit1 + 3, strlit2, strlit2 + 3);
56 VERIFY( i == -1 );
57
58 i = coll_c.compare(strlit3, strlit3 + 3, strlit4, strlit4 + 3);
59 VERIFY( i == 1 );
60
61 i = coll_de.compare(strlit3, strlit3 + 3, strlit4, strlit4 + 3);
62 VERIFY( i == -1 );
63
64 i = coll_c.compare(strlit1, strlit1 + 3, strlit1, strlit1 + 4);
65 VERIFY( i == -1 );
66
67 i = coll_de.compare(strlit3, strlit3 + 4, strlit3, strlit3 + 3);
68 VERIFY( i == 1 );
69
70 i = coll_c.compare(strlit1, strlit1 + 4, strlit4, strlit4 + 1);
71 VERIFY( i == 1 );
72
73 i = coll_de.compare(strlit3, strlit3 + 3, strlit3, strlit3 + 3);
74 VERIFY( i == 0 );
75
76 i = coll_c.compare(strlit1, strlit1 + 2, strlit1, strlit1 + 4);
77 VERIFY( i == -1 );
78
79 i = coll_de.compare(strlit1, strlit1 + 3, strlit5, strlit5 + 3);
80 VERIFY( i == -1 );
81
82 i = coll_c.compare(strlit6, strlit6 + 3, strlit1, strlit1 + 3);
83 VERIFY( i == 1 );
84}
85
86int main()
87{
88 test03();
89 return 0;
90}