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 | #include <wctype.h> |
17 | |
18 | template<typename CharType> |
19 | void test_char() |
20 | { |
21 | using boost::locale::case_convert_test::test_one; |
22 | boost::locale::generator gen; |
23 | |
24 | std::cout << "- Testing at least C" << std::endl; |
25 | std::locale l = gen("C.UTF-8" ); |
26 | test_one<CharType>(l, "Hello World i" , "hello world i" , "HELLO WORLD I" ); |
27 | boost::locale::case_convert_test::test_no_op_title_case<CharType>(l, "Hello world i" ); |
28 | |
29 | std::string name = "en_US.UTF-8" ; |
30 | if(has_posix_locale(name)) { |
31 | std::cout << "- Testing " << name << std::endl; |
32 | l = gen(name); |
33 | test_one<CharType>(l, "Façade" , "façade" , "FAÇADE" ); |
34 | boost::locale::case_convert_test::test_no_op_title_case<CharType>(l, "Hello world i" ); |
35 | } |
36 | |
37 | name = "en_US.ISO8859-1" ; |
38 | if(has_posix_locale(name)) { |
39 | std::cout << "Testing " << name << std::endl; |
40 | l = gen(name); |
41 | test_one<CharType>(l, "Hello World" , "hello world" , "HELLO WORLD" ); |
42 | boost::locale::case_convert_test::test_no_op_title_case<CharType>(l, "Hello world i" ); |
43 | #if defined(__APPLE__) || defined(__FreeBSD__) |
44 | if(sizeof(CharType) != 1) |
45 | #endif |
46 | test_one<CharType>(l, "Façade" , "façade" , "FAÇADE" ); |
47 | } |
48 | |
49 | name = "tr_TR.UTF-8" ; |
50 | if(!has_posix_locale(name)) |
51 | std::cout << "- " << name << " is not supported, skipping" << std::endl; // LCOV_EXCL_LINE |
52 | else { |
53 | std::cout << "Testing " << name << std::endl; |
54 | locale_holder cl(newlocale(LC_ALL_MASK, locale: name.c_str(), base: nullptr)); |
55 | TEST_REQUIRE(cl); |
56 | #ifndef BOOST_LOCALE_NO_POSIX_BACKEND |
57 | if(towupper_l(wc: L'i', locale: cl) == 0x130) |
58 | test_one<CharType>(gen(name), "i" , "i" , "İ" ); |
59 | else |
60 | std::cout << " Turkish locale is not supported well" << std::endl; // LCOV_EXCL_LINE |
61 | #endif |
62 | } |
63 | } |
64 | |
65 | BOOST_LOCALE_DISABLE_UNREACHABLE_CODE_WARNING |
66 | void test_main(int /*argc*/, char** /*argv*/) |
67 | { |
68 | #ifdef BOOST_LOCALE_NO_POSIX_BACKEND |
69 | std::cout << "POSIX Backend is not build... Skipping\n" ; |
70 | return; |
71 | #endif |
72 | boost::locale::localization_backend_manager mgr = boost::locale::localization_backend_manager::global(); |
73 | mgr.select(backend_name: "posix" ); |
74 | boost::locale::localization_backend_manager::global(mgr); |
75 | |
76 | std::cout << "Testing char" << std::endl; |
77 | test_char<char>(); |
78 | std::cout << "Testing wchar_t" << std::endl; |
79 | test_char<wchar_t>(); |
80 | } |
81 | |
82 | // boostinspect:noascii |
83 | |