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_WINAPI_BACKEND
12 std::cout
<< "WinAPI Backend is not build... Skipping" << std::endl
;
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"
25 template<typename CharType
>
26 void test_one(std::locale
const &l
,std::string src
,std::string tgtl
,std::string tgtu
)
28 TEST(boost::locale::to_upper(to_correct_string
<CharType
>(src
,l
),l
) == to_correct_string
<CharType
>(tgtu
,l
));
29 TEST(boost::locale::to_lower(to_correct_string
<CharType
>(src
,l
),l
) == to_correct_string
<CharType
>(tgtl
,l
));
30 TEST(boost::locale::fold_case(to_correct_string
<CharType
>(src
,l
),l
) == to_correct_string
<CharType
>(tgtl
,l
));
33 template<typename CharType
>
36 boost::locale::generator gen
;
38 std::cout
<< "- Testing at least C" << std::endl
;
41 std::locale l
= gen("en_US.UTF-8");
43 test_one
<CharType
>(l
,"Hello World i","hello world i","HELLO WORLD I");
45 std::string name
= "en_US.UTF-8";
47 std::cout
<< "- Testing " << name
<< std::endl
;
49 test_one
<CharType
>(l
,"Façade","façade","FAÇADE");
53 std::cout
<< "Testing " << name
<< std::endl
;
54 test_one
<CharType
>(gen(name
),"i","i","İ");
58 template<typename Char
>
59 void test_normc(std::basic_string
<Char
> orig
,std::basic_string
<Char
> normal
,boost::locale::norm_type type
)
61 std::locale l
= boost::locale::generator().generate("en_US.UTF-8");
62 TEST(boost::locale::normalize(orig
,type
,l
)==normal
);
63 TEST(boost::locale::normalize(orig
.c_str(),type
,l
)==normal
);
64 TEST(boost::locale::normalize(orig
.c_str(),orig
.c_str()+orig
.size(),type
,l
)==normal
);
68 void test_norm(std::string orig
,std::string normal
,boost::locale::norm_type type
)
70 test_normc
<char>(orig
,normal
,type
);
71 test_normc
<wchar_t>(to
<wchar_t>(orig
),to
<wchar_t>(normal
),type
);
77 boost::locale::localization_backend_manager mgr
= boost::locale::localization_backend_manager::global();
79 boost::locale::localization_backend_manager::global(mgr
);
81 std::cout
<< "Testing char" << std::endl
;
83 std::cout
<< "Testing wchar_t" << std::endl
;
86 std::cout
<< "Testing Unicode normalization" << std::endl
;
87 test_norm("\xEF\xAC\x81","\xEF\xAC\x81",boost::locale::norm_nfd
); /// ligature fi
88 test_norm("\xEF\xAC\x81","\xEF\xAC\x81",boost::locale::norm_nfc
);
89 #if defined(_WIN32_NT) && _WIN32_NT >= 0x600
90 test_norm("\xEF\xAC\x81","fi",boost::locale::norm_nfkd
);
91 test_norm("\xEF\xAC\x81","fi",boost::locale::norm_nfkc
);
93 test_norm("ä","ä",boost::locale::norm_nfd
); // ä to a and accent
94 test_norm("ä","ä",boost::locale::norm_nfc
);
96 catch(std::exception
const &e
) {
97 std::cerr
<< "Failed " << e
.what() << std::endl
;
105 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
108 // boostinspect:noascii