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/conversion.hpp>
16 #include <boost/locale/localization_backend.hpp>
17 #include <boost/locale/generator.hpp>
18 #include <boost/locale/info.hpp>
20 #include "test_locale.hpp"
21 #include "test_locale_tools.hpp"
22 #include "test_posix_tools.hpp"
28 template<typename CharType
>
29 void test_one(std::locale
const &l
,std::string src
,std::string tgtl
,std::string tgtu
)
31 TEST(boost::locale::to_upper(to_correct_string
<CharType
>(src
,l
),l
) == to_correct_string
<CharType
>(tgtu
,l
));
32 TEST(boost::locale::to_lower(to_correct_string
<CharType
>(src
,l
),l
) == to_correct_string
<CharType
>(tgtl
,l
));
33 TEST(boost::locale::fold_case(to_correct_string
<CharType
>(src
,l
),l
) == to_correct_string
<CharType
>(tgtl
,l
));
36 template<typename CharType
>
39 boost::locale::generator gen
;
41 std::cout
<< "- Testing at least C" << std::endl
;
43 std::locale l
= gen("en_US.UTF-8");
45 test_one
<CharType
>(l
,"Hello World i","hello world i","HELLO WORLD I");
47 std::string name
= "en_US.UTF-8";
48 if(have_locale(name
)) {
49 std::cout
<< "- Testing " << name
<< std::endl
;
50 std::locale l
=gen(name
);
51 test_one
<CharType
>(l
,"Façade","façade","FAÇADE");
54 std::cout
<< "- en_US.UTF-8 is not supported, skipping" << std::endl
;
57 name
= "en_US.ISO8859-1";
58 if(have_locale(name
)) {
59 std::cout
<< "Testing " << name
<< std::endl
;
60 std::locale l
=gen(name
);
61 test_one
<CharType
>(l
,"Hello World","hello world","HELLO WORLD");
62 #if defined(__APPLE__) || defined(__FreeBSD__)
63 if(sizeof(CharType
)!=1)
65 test_one
<CharType
>(l
,"Façade","façade","FAÇADE");
68 std::cout
<< "- en_US.ISO8859-1 is not supported, skipping" << std::endl
;
72 if(have_locale(name
)) {
73 std::cout
<< "Testing " << name
<< std::endl
;
74 locale_t cl
= newlocale(LC_ALL_MASK
,name
.c_str(),0);
77 if(towupper_l(L
'i',cl
) == 0x130) {
78 test_one
<CharType
>(gen(name
),"i","i","İ");
81 std::cout
<<" Turkish locale is not supported well" << std::endl
;
85 if(cl
) freelocale(cl
);
88 if(cl
) freelocale(cl
);
93 std::cout
<< "- tr_TR.UTF-8 is not supported, skipping" << std::endl
;
101 boost::locale::localization_backend_manager mgr
= boost::locale::localization_backend_manager::global();
103 boost::locale::localization_backend_manager::global(mgr
);
105 std::cout
<< "Testing char" << std::endl
;
107 std::cout
<< "Testing wchar_t" << std::endl
;
108 test_char
<wchar_t>();
110 catch(std::exception
const &e
) {
111 std::cerr
<< "Failed " << e
.what() << std::endl
;
119 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
122 // boostinspect:noascii