File: test_winapi_convert.cpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (85 lines) | stat: -rw-r--r-- 3,107 bytes parent folder | download | duplicates (3)
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
//
// 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.UTF-8");

    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 = "en_US.UTF-8";

    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 = "tr_TR.UTF-8";
    std::cout << "Testing " << name << std::endl;
    test_one<CharType>(gen(name), "i", "i", "İ");
}

template<typename Char>
void test_normc(const std::basic_string<Char>& orig, // LCOV_EXCL_LINE
                const std::basic_string<Char>& normal,
                const boost::locale::norm_type type)
{
    std::locale l = boost::locale::generator().generate("en_US.UTF-8");
    TEST_EQ(boost::locale::normalize(orig, type, l), normal);
    TEST_EQ(boost::locale::normalize(orig.c_str(), type, l), normal);
    TEST_EQ(boost::locale::normalize(orig.c_str(), orig.c_str() + orig.size(), type, l), normal);
} // LCOV_EXCL_LINE

void test_norm(const std::string orig, const std::string normal, const boost::locale::norm_type type) // LCOV_EXCL_LINE
{
    test_normc<char>(orig, normal, type);
    test_normc<wchar_t>(to<wchar_t>(orig), to<wchar_t>(normal), type);
} // LCOV_EXCL_LINE

BOOST_LOCALE_DISABLE_UNREACHABLE_CODE_WARNING
void test_main(int /*argc*/, char** /*argv*/)
{
#ifdef BOOST_LOCALE_NO_WINAPI_BACKEND
    std::cout << "WinAPI Backend is not build... Skipping\n";
    return;
#endif
    boost::locale::localization_backend_manager mgr = boost::locale::localization_backend_manager::global();
    mgr.select("winapi");
    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>();

    std::cout << "Testing Unicode normalization" << std::endl;
    test_norm("\xEF\xAC\x81", "\xEF\xAC\x81", boost::locale::norm_nfd); // ligature fi
    test_norm("\xEF\xAC\x81", "\xEF\xAC\x81", boost::locale::norm_nfc);
    test_norm("\xEF\xAC\x81", "fi", boost::locale::norm_nfkd);
    test_norm("\xEF\xAC\x81", "fi", boost::locale::norm_nfkc);
    test_norm("ä", "ä", boost::locale::norm_nfd); // ä to a and accent
    test_norm("ä", "ä", boost::locale::norm_nfc);
}

// boostinspect:noascii