]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/locale/test/test_winapi_convert.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / locale / test / test_winapi_convert.cpp
1 //
2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 //
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)
7 //
8 #ifdef BOOST_LOCALE_NO_WINAPI_BACKEND
9 #include <iostream>
10 int main()
11 {
12 std::cout << "WinAPI Backend is not build... Skipping" << std::endl;
13 }
14 #else
15
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>
20 #include <iomanip>
21 #include "test_locale.hpp"
22 #include "test_locale_tools.hpp"
23 #include <iostream>
24
25 template<typename CharType>
26 void test_one(std::locale const &l,std::string src,std::string tgtl,std::string tgtu)
27 {
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));
31 }
32
33 template<typename CharType>
34 void test_char()
35 {
36 boost::locale::generator gen;
37
38 std::cout << "- Testing at least C" << std::endl;
39
40
41 std::locale l = gen("en_US.UTF-8");
42
43 test_one<CharType>(l,"Hello World i","hello world i","HELLO WORLD I");
44
45 std::string name = "en_US.UTF-8";
46
47 std::cout << "- Testing " << name << std::endl;
48 l=gen(name);
49 test_one<CharType>(l,"Façade","façade","FAÇADE");
50
51
52 name = "tr_TR.UTF-8";
53 std::cout << "Testing " << name << std::endl;
54 test_one<CharType>(gen(name),"i","i","İ");
55
56 }
57
58 template<typename Char>
59 void test_normc(std::basic_string<Char> orig,std::basic_string<Char> normal,boost::locale::norm_type type)
60 {
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);
65 }
66
67
68 void test_norm(std::string orig,std::string normal,boost::locale::norm_type type)
69 {
70 test_normc<char>(orig,normal,type);
71 test_normc<wchar_t>(to<wchar_t>(orig),to<wchar_t>(normal),type);
72 }
73
74 int main()
75 {
76 try {
77 boost::locale::localization_backend_manager mgr = boost::locale::localization_backend_manager::global();
78 mgr.select("winapi");
79 boost::locale::localization_backend_manager::global(mgr);
80
81 std::cout << "Testing char" << std::endl;
82 test_char<char>();
83 std::cout << "Testing wchar_t" << std::endl;
84 test_char<wchar_t>();
85
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);
92 #endif
93 test_norm("ä","ä",boost::locale::norm_nfd); // ä to a and accent
94 test_norm("ä","ä",boost::locale::norm_nfc);
95 }
96 catch(std::exception const &e) {
97 std::cerr << "Failed " << e.what() << std::endl;
98 return EXIT_FAILURE;
99 }
100 FINALIZE();
101
102 }
103
104 #endif // no winapi
105 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
106
107
108 // boostinspect:noascii