File: test_std_convert.cpp

package info (click to toggle)
boost1.90 1.90.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 593,156 kB
  • sloc: cpp: 4,190,642; xml: 196,648; python: 34,618; ansic: 23,145; asm: 5,468; sh: 3,776; makefile: 1,161; perl: 1,020; sql: 728; ruby: 676; yacc: 478; java: 77; lisp: 24; csh: 6
file content (102 lines) | stat: -rw-r--r-- 3,830 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
//
// Distributed under the Boost Software License, Version 1.0.
// https://www.boost.org/LICENSE_1_0.txt

#include <boost/locale/conversion.hpp>
#include <boost/locale/generator.hpp>
#include <boost/locale/info.hpp>
#include <boost/locale/localization_backend.hpp>
#include "boostLocale/test/tools.hpp"
#include "boostLocale/test/unit_test.hpp"
#include "case_convert_test.hpp"
#include <iomanip>
#include <iostream>

template<typename CharType>
void test_char()
{
    using boost::locale::case_convert_test::test_one;

    boost::locale::generator gen;

    std::cout << "- Testing at least C" << std::endl;
    std::locale l = gen("C");
    test_one<CharType>(l, "Hello World i", "hello world i", "HELLO WORLD I");
    boost::locale::case_convert_test::test_no_op_title_case<CharType>(l, "Hello world i");

    std::string name, real_name;

    name = "en_US.UTF-8";
    if(get_std_name(name, &real_name).empty())
        std::cout << "- " << name << " is not supported, skipping" << std::endl; // LCOV_EXCL_LINE
    else {
        std::cout << "- Testing " << name << std::endl;
        l = gen(name);
        test_one<CharType>(l, "Façade", "façade", "FAÇADE");
        boost::locale::case_convert_test::test_no_op_title_case<CharType>(l, "Hello world i");
    }

    name = "en_US.ISO8859-1";
    if(get_std_name(name, &real_name).empty())
        std::cout << "- " << name << " is not supported, skipping" << std::endl; // LCOV_EXCL_LINE
    else {
        std::cout << "- Testing " << name << std::endl;
        l = gen(name);
        test_one<CharType>(l, "Hello World", "hello world", "HELLO WORLD");
        // Check that ç can be converted to Ç by the stdlib (fails on e.g. FreeBSD libstd++)
        if(std::toupper('\xe7', std::locale(real_name)) == '\xc7')
            test_one<CharType>(l, "Façade", "façade", "FAÇADE");
        else {
            std::cout << "- " << name << " (" << real_name << ") is not well supported. "; // LCOV_EXCL_LINE
            std::cout << "  Skipping conv test" << std::endl;                              // LCOV_EXCL_LINE
        }
        boost::locale::case_convert_test::test_no_op_title_case<CharType>(l, "Hello world i");
    }

    name = "tr_TR.UTF-8";
    if(get_std_name(name, &real_name).empty())
        std::cout << "- " << name << " is not supported, skipping" << std::endl; // LCOV_EXCL_LINE
    else {
        std::cout << "- Testing " << name << std::endl;
        if(std::use_facet<std::ctype<wchar_t>>(std::locale(real_name)).toupper(L'i') != L'I') {
            l = gen(name);
            test_one<CharType>(l, "i", "i", "İ");
        } else {
            std::cout << "- " << name << " (" << real_name << ") is not well supported. "; // LCOV_EXCL_LINE
            std::cout << "  Skipping conv test" << std::endl;                              // LCOV_EXCL_LINE
        }
    }
}

BOOST_LOCALE_DISABLE_UNREACHABLE_CODE_WARNING
void test_main(int /*argc*/, char** /*argv*/)
{
#ifdef BOOST_LOCALE_NO_STD_BACKEND
    std::cout << "STD Backend is not build... Skipping\n";
    return;
#endif
    boost::locale::localization_backend_manager mgr = boost::locale::localization_backend_manager::global();
    mgr.select("std");
    boost::locale::localization_backend_manager::global(mgr);

    std::cout << "Testing char" << std::endl;
    test_char<char>();
    std::cout << "Testing wchar_t" << std::endl;
    test_char<wchar_t>();
#ifdef __cpp_lib_char8_t
    std::cout << "Testing char8_t" << std::endl;
    test_char<char8_t>();
#endif
#ifdef BOOST_LOCALE_ENABLE_CHAR16_T
    std::cout << "Testing char16_t" << std::endl;
    test_char<char16_t>();
#endif
#ifdef BOOST_LOCALE_ENABLE_CHAR32_T
    std::cout << "Testing char32_t" << std::endl;
    test_char<char32_t>();
#endif
}

// boostinspect:noascii