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
17template<typename CharType>
18void 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 std::locale l = gen("en_US.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;
30
31 name = get_std_name(name: "en_US.UTF-8");
32 if(!name.empty()) {
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 } else
38 std::cout << "- en_US.UTF-8 is not supported, skipping" << std::endl; // LCOV_EXCL_LINE
39
40 name = get_std_name(name: "en_US.ISO8859-1");
41 if(!name.empty()) {
42 std::cout << "Testing " << name << std::endl;
43 l = gen(name);
44 test_one<CharType>(l, "Hello World", "hello world", "HELLO WORLD");
45#if BOOST_LOCALE_USE_WIN32_API
46 name = "English_United States";
47#endif
48 // Check that ç can be converted to Ç by the stdlib (fails on e.g. FreeBSD libstd++)
49 if(std::toupper(c: '\xe7', loc: std::locale(name)) == '\xc7')
50 test_one<CharType>(l, "Façade", "façade", "FAÇADE");
51 else {
52 std::cout << "- en_US.ISO8859-1 (" << name << ") not well supported. "; // LCOV_EXCL_LINE
53 std::cout << "Skipping conv test" << std::endl; // LCOV_EXCL_LINE
54 }
55 boost::locale::case_convert_test::test_no_op_title_case<CharType>(l, "Hello world i");
56 } else
57 std::cout << "- en_US.ISO8859-1 is not supported, skipping" << std::endl; // LCOV_EXCL_LINE
58
59 std::string real_name;
60 name = get_std_name(name: "tr_TR.UTF-8", real_name: &real_name);
61 if(!name.empty()) {
62 std::cout << "Testing " << name << std::endl;
63 if(std::use_facet<std::ctype<wchar_t>>(loc: std::locale(real_name)).toupper(c: L'i') != L'I') {
64 l = gen(name);
65 test_one<CharType>(l, "i", "i", "İ");
66 } else
67 std::cout << "Standard library does not support this locale's case conversion correctly" << std::endl;
68 } else
69 std::cout << "- tr_TR.UTF-8 is not supported, skipping" << std::endl; // LCOV_EXCL_LINE
70}
71
72BOOST_LOCALE_DISABLE_UNREACHABLE_CODE_WARNING
73void test_main(int /*argc*/, char** /*argv*/)
74{
75#ifdef BOOST_LOCALE_NO_STD_BACKEND
76 std::cout << "STD Backend is not build... Skipping\n";
77 return;
78#endif
79 boost::locale::localization_backend_manager mgr = boost::locale::localization_backend_manager::global();
80 mgr.select(backend_name: "std");
81 boost::locale::localization_backend_manager::global(mgr);
82
83 std::cout << "Testing char" << std::endl;
84 test_char<char>();
85 std::cout << "Testing wchar_t" << std::endl;
86 test_char<wchar_t>();
87#ifndef BOOST_LOCALE_NO_CXX20_STRING8
88 std::cout << "Testing char8_t" << std::endl;
89 test_char<char8_t>();
90#endif
91#ifdef BOOST_LOCALE_ENABLE_CHAR16_T
92 std::cout << "Testing char16_t" << std::endl;
93 test_char<char16_t>();
94#endif
95#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
96 std::cout << "Testing char32_t" << std::endl;
97 test_char<char32_t>();
98#endif
99}
100
101// boostinspect:noascii
102

source code of boost/libs/locale/test/test_std_convert.cpp