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 #ifdef BOOST_LOCALE_NO_STD_BACKEND
13 std::cout
<< "STD Backend is not build... Skipping" << std::endl
;
17 #include <boost/locale/config.hpp>
18 #include <boost/locale/conversion.hpp>
19 #include <boost/locale/localization_backend.hpp>
20 #include <boost/locale/generator.hpp>
21 #include <boost/locale/info.hpp>
23 #include "test_locale.hpp"
24 #include "test_locale_tools.hpp"
36 template<typename CharType
>
37 void test_one(std::locale
const &l
,std::string ia
,std::string ib
,int diff
)
39 std::basic_string
<CharType
> a
=to_correct_string
<CharType
>(ia
,l
);
40 std::basic_string
<CharType
> b
=to_correct_string
<CharType
>(ib
,l
);
54 std::collate
<CharType
> const &col
= std::use_facet
<std::collate
<CharType
> >(l
);
56 TEST(diff
== col
.compare(a
.c_str(),a
.c_str()+a
.size(),b
.c_str(),b
.c_str()+b
.size()));
57 TEST(diff
== get_sign(col
.transform(a
.c_str(),a
.c_str()+a
.size()).compare(col
.transform(b
.c_str(),b
.c_str()+b
.size()))));
59 TEST(col
.hash(a
.c_str(),a
.c_str()+a
.size()) == col
.hash(b
.c_str(),b
.c_str()+b
.size()));
63 template<typename CharType
>
66 boost::locale::generator gen
;
68 std::cout
<< "- Testing at least C" << std::endl
;
70 std::locale l
= gen("en_US.UTF-8");
72 test_one
<CharType
>(l
,"a","b",-1);
73 test_one
<CharType
>(l
,"a","a",0);
77 #if defined(_LIBCPP_VERSION) && (defined(__APPLE__) || defined(__FreeBSD__))
78 std::cout
<< "- Collation is broken on this OS's standard C++ library, skipping" << std::endl
;
80 std::string names
[] = { "en_US.UTF-8", "en_US.ISO8859-1" };
81 for(unsigned i
=0;i
<sizeof(names
)/sizeof(names
[0]);i
++) {
82 name
= get_std_name(names
[i
]);
84 std::cout
<< "- Testing " << name
<< std::endl
;
85 std::locale l
=gen(name
);
86 test_one
<CharType
>(l
,"a","ç",-1);
87 test_one
<CharType
>(l
,"ç","d",-1);
90 std::cout
<< "- " << names
[i
] << " not supported, skipping" << std::endl
;
100 boost::locale::localization_backend_manager mgr
= boost::locale::localization_backend_manager::global();
102 boost::locale::localization_backend_manager::global(mgr
);
104 std::cout
<< "Testing char" << std::endl
;
106 std::cout
<< "Testing wchar_t" << std::endl
;
107 test_char
<wchar_t>();
108 #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
109 std::cout
<< "Testing char16_t" << std::endl
;
110 test_char
<char16_t
>();
112 #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
113 std::cout
<< "Testing char32_t" << std::endl
;
114 test_char
<char32_t
>();
117 catch(std::exception
const &e
) {
118 std::cerr
<< "Failed " << e
.what() << std::endl
;
127 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
129 // boostinspect:noascii