]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/locale/test/test_collate.cpp
2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_LOCALE_WITH_ICU
13 std::cout
<< "ICU is not build... Skipping" << std::endl
;
17 #include <boost/locale/collator.hpp>
18 #include <boost/locale/generator.hpp>
20 #include "test_locale.hpp"
23 template<typename Char
>
24 void test_comp(std::locale l
,std::basic_string
<Char
> left
,std::basic_string
<Char
> right
,int ilevel
,int expected
)
26 typedef std::basic_string
<Char
> string_type
;
27 boost::locale::collator_base::level_type level
= static_cast<boost::locale::collator_base::level_type
>(ilevel
);
28 TEST(boost::locale::comparator
<Char
>(l
,level
)(left
,right
) == (expected
< 0));
30 std::collate
<Char
> const &coll
=std::use_facet
<std::collate
<Char
> >(l
);
31 string_type lt
=coll
.transform(left
.c_str(),left
.c_str()+left
.size());
32 string_type rt
=coll
.transform(right
.c_str(),right
.c_str()+right
.size());
35 else if(expected
== 0) {
40 long lh
=coll
.hash(left
.c_str(),left
.c_str()+left
.size());
41 long rh
=coll
.hash(right
.c_str(),right
.c_str()+right
.size());
47 boost::locale::collator
<Char
> const &coll
=std::use_facet
<boost::locale::collator
<Char
> >(l
);
48 string_type lt
=coll
.transform(level
,left
.c_str(),left
.c_str()+left
.size());
49 TEST(lt
==coll
.transform(level
,left
));
50 string_type rt
=coll
.transform(level
,right
.c_str(),right
.c_str()+right
.size());
51 TEST(rt
==coll
.transform(level
,right
));
54 else if(expected
== 0)
58 long lh
=coll
.hash(level
,left
.c_str(),left
.c_str()+left
.size());
59 TEST(lh
==coll
.hash(level
,left
));
60 long rh
=coll
.hash(level
,right
.c_str(),right
.c_str()+right
.size());
61 TEST(rh
==coll
.hash(level
,right
));
69 #define TEST_COMP(c,_l,_r) test_comp<c>(l,_l,_r,level,expected)
72 void compare(std::string left
,std::string right
,int level
,int expected
)
74 boost::locale::generator gen
;
75 std::locale l
=gen("en_US.UTF-8");
77 TEST(l(left
,right
) == (expected
< 0));
78 TEST_COMP(char,left
,right
);
79 TEST_COMP(wchar_t,to
<wchar_t>(left
),to
<wchar_t>(right
));
80 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
81 TEST_COMP(char16_t
,to
<char16_t
>(left
),to
<char16_t
>(right
));
83 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
84 TEST_COMP(char32_t
,to
<char32_t
>(left
),to
<char32_t
>(right
));
86 l
=gen("en_US.ISO8859-1");
88 TEST(l(to
<char>(left
),to
<char>(right
)) == (expected
< 0));
89 TEST_COMP(char,to
<char>(left
),to
<char>(right
));
101 int le
= -1,gt
= 1,eq
= 0;
104 compare("a","A",primary
,eq
);
105 compare("a","A",secondary
,eq
);
106 compare("A","a",tertiary
,gt
);
107 compare("a","A",tertiary
,le
);
108 compare("a","A",quaternary
,le
);
109 compare("A","a",quaternary
,gt
);
110 compare("a","A",identical
,le
);
111 compare("A","a",identical
,gt
);
112 compare("a","ä",primary
,eq
); // a , ä
113 compare("a","ä",secondary
,le
); // a , ä
114 compare("ä","a",secondary
,gt
); // a , ä
115 compare("a","ä",quaternary
,le
); // a , ä
116 compare("ä","a",quaternary
,gt
); // a , ä
117 compare("a","ä",identical
,le
); // a , ä
118 compare("ä","a",identical
,gt
); // a , ä
129 catch(std::exception
const &e
) {
130 std::cerr
<< "Failed " << e
.what() << std::endl
;
138 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
139 // boostinspect:noascii