1 | // |
2 | // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) |
3 | // |
4 | // Distributed under the Boost Software License, Version 1.0. |
5 | // https://www.boost.org/LICENSE_1_0.txt |
6 | |
7 | #include <boost/locale/conversion.hpp> |
8 | #include <boost/locale/generator.hpp> |
9 | #include <boost/locale/info.hpp> |
10 | #include <boost/locale/localization_backend.hpp> |
11 | #include "boostLocale/test/tools.hpp" |
12 | #include "boostLocale/test/unit_test.hpp" |
13 | #include "case_convert_test.hpp" |
14 | #include <iomanip> |
15 | #include <iostream> |
16 | |
17 | template<typename CharType> |
18 | void test_char() |
19 | { |
20 | using boost::locale::case_convert_test::test_one; |
21 | |
22 | boost::locale::generator gen; |
23 | |
24 | std::cout << "- Testing at least C" << std::endl; |
25 | |
26 | std::locale l = gen("C.UTF-8" ); |
27 | |
28 | test_one<CharType>(l, "Hello World i" , "hello world i" , "HELLO WORLD I" ); |
29 | boost::locale::case_convert_test::test_no_op_title_case<CharType>(l, "Hello world i" ); |
30 | |
31 | std::string name = "en_US.UTF-8" ; |
32 | |
33 | std::cout << "- Testing " << name << std::endl; |
34 | l = gen(name); |
35 | test_one<CharType>(l, "Façade" , "façade" , "FAÇADE" ); |
36 | boost::locale::case_convert_test::test_no_op_title_case<CharType>(l, "Hello world i" ); |
37 | |
38 | name = "tr_TR.UTF-8" ; |
39 | std::cout << "Testing " << name << std::endl; |
40 | test_one<CharType>(gen(name), "i" , "i" , "İ" ); |
41 | } |
42 | |
43 | template<typename Char> |
44 | void test_normc(const std::basic_string<Char>& orig, // LCOV_EXCL_LINE |
45 | const std::basic_string<Char>& normal, |
46 | const boost::locale::norm_type type) |
47 | { |
48 | std::locale l = boost::locale::generator().generate(id: "en_US.UTF-8" ); |
49 | TEST_EQ(boost::locale::normalize(orig, type, l), normal); |
50 | TEST_EQ(boost::locale::normalize(orig.c_str(), type, l), normal); |
51 | TEST_EQ(boost::locale::normalize(orig.c_str(), orig.c_str() + orig.size(), type, l), normal); |
52 | } // LCOV_EXCL_LINE |
53 | |
54 | void test_norm(const std::string orig, const std::string normal, const boost::locale::norm_type type) // LCOV_EXCL_LINE |
55 | { |
56 | test_normc<char>(orig, normal, type); |
57 | test_normc<wchar_t>(orig: to<wchar_t>(utf8: orig), normal: to<wchar_t>(utf8: normal), type); |
58 | } // LCOV_EXCL_LINE |
59 | |
60 | BOOST_LOCALE_DISABLE_UNREACHABLE_CODE_WARNING |
61 | void test_main(int /*argc*/, char** /*argv*/) |
62 | { |
63 | #ifdef BOOST_LOCALE_NO_WINAPI_BACKEND |
64 | std::cout << "WinAPI Backend is not build... Skipping\n" ; |
65 | return; |
66 | #endif |
67 | boost::locale::localization_backend_manager mgr = boost::locale::localization_backend_manager::global(); |
68 | mgr.select(backend_name: "winapi" ); |
69 | boost::locale::localization_backend_manager::global(mgr); |
70 | |
71 | std::cout << "Testing char" << std::endl; |
72 | test_char<char>(); |
73 | std::cout << "Testing wchar_t" << std::endl; |
74 | test_char<wchar_t>(); |
75 | |
76 | std::cout << "Testing Unicode normalization" << std::endl; |
77 | test_norm(orig: "\xEF\xAC\x81" , normal: "\xEF\xAC\x81" , type: boost::locale::norm_nfd); // ligature fi |
78 | test_norm(orig: "\xEF\xAC\x81" , normal: "\xEF\xAC\x81" , type: boost::locale::norm_nfc); |
79 | test_norm(orig: "\xEF\xAC\x81" , normal: "fi" , type: boost::locale::norm_nfkd); |
80 | test_norm(orig: "\xEF\xAC\x81" , normal: "fi" , type: boost::locale::norm_nfkc); |
81 | test_norm(orig: "ä" , normal: "ä" , type: boost::locale::norm_nfd); // ä to a and accent |
82 | test_norm(orig: "ä" , normal: "ä" , type: boost::locale::norm_nfc); |
83 | } |
84 | |
85 | // boostinspect:noascii |
86 | |