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)
8 #ifdef BOOST_LOCALE_NO_POSIX_BACKEND
12 std::cout
<< "POSIX Backend is not build... Skipping" << std::endl
;
15 #include <boost/locale/config.hpp>
16 #include <boost/locale/conversion.hpp>
17 #include <boost/locale/localization_backend.hpp>
18 #include <boost/locale/generator.hpp>
19 #include <boost/locale/info.hpp>
21 #include "test_locale.hpp"
22 #include "test_locale_tools.hpp"
23 #include "test_posix_tools.hpp"
35 template<typename CharType
>
36 void test_one(std::locale
const &l
,std::string ia
,std::string ib
,int diff
)
38 std::basic_string
<CharType
> a
=to_correct_string
<CharType
>(ia
,l
);
39 std::basic_string
<CharType
> b
=to_correct_string
<CharType
>(ib
,l
);
53 std::collate
<CharType
> const &col
= std::use_facet
<std::collate
<CharType
> >(l
);
55 TEST(diff
== col
.compare(a
.c_str(),a
.c_str()+a
.size(),b
.c_str(),b
.c_str()+b
.size()));
56 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()))));
58 TEST(col
.hash(a
.c_str(),a
.c_str()+a
.size()) == col
.hash(b
.c_str(),b
.c_str()+b
.size()));
62 template<typename CharType
>
65 boost::locale::generator gen
;
67 std::cout
<< "- Testing at least C" << std::endl
;
69 std::locale l
= gen("en_US.UTF-8");
71 test_one
<CharType
>(l
,"a","b",-1);
72 test_one
<CharType
>(l
,"a","a",0);
77 #if !defined(__APPLE__) && !defined(__FreeBSD__)
78 std::string names
[] = { "en_US.UTF-8", "en_US.ISO8859-1" };
79 for(unsigned i
=0;i
<sizeof(names
)/sizeof(names
[0]);i
++) {
80 if(have_locale(names
[i
])) {
82 std::cout
<< "- Testing " << name
<< std::endl
;
83 std::locale l
=gen(name
);
84 test_one
<CharType
>(l
,"a","ç",-1);
85 test_one
<CharType
>(l
,"ç","d",-1);
88 std::cout
<< "- " << names
[i
] << " not supported, skipping" << std::endl
;
92 std::cout
<< "- Collation is broken on this OS C standard library, 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>();
109 catch(std::exception
const &e
) {
110 std::cerr
<< "Failed " << e
.what() << std::endl
;
117 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
120 // boostinspect:noascii