• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 //  Copyright (c) 2009-2011 Artyom Beilis (Tonkikh)
3 //
4 //  Distributed under the Boost Software License, Version 1.0. (See
5 //  accompanying file LICENSE_1_0.txt or copy at
6 //  http://www.boost.org/LICENSE_1_0.txt)
7 //
8 
9 #ifdef BOOST_LOCALE_NO_STD_BACKEND
10 #include <iostream>
main()11 int main()
12 {
13         std::cout << "STD Backend is not build... Skipping" << std::endl;
14 }
15 #else
16 
17 
18 
19 #include <boost/locale/conversion.hpp>
20 #include <boost/locale/localization_backend.hpp>
21 #include <boost/locale/generator.hpp>
22 #include <boost/locale/info.hpp>
23 #include <iomanip>
24 #include "test_locale.hpp"
25 #include "test_locale_tools.hpp"
26 #include <iostream>
27 
28 template<typename CharType>
test_one(std::locale const & l,std::string src,std::string tgtl,std::string tgtu)29 void test_one(std::locale const &l,std::string src,std::string tgtl,std::string tgtu)
30 {
31     TEST(boost::locale::to_upper(to_correct_string<CharType>(src,l),l) == to_correct_string<CharType>(tgtu,l));
32     TEST(boost::locale::to_lower(to_correct_string<CharType>(src,l),l) == to_correct_string<CharType>(tgtl,l));
33     TEST(boost::locale::fold_case(to_correct_string<CharType>(src,l),l) == to_correct_string<CharType>(tgtl,l));
34 }
35 
36 template<typename CharType>
test_char()37 void test_char()
38 {
39     boost::locale::generator gen;
40 
41     std::cout << "- Testing at least C" << std::endl;
42 
43     std::locale l = gen("en_US.UTF-8");
44 
45     test_one<CharType>(l,"Hello World i","hello world i","HELLO WORLD I");
46 
47     std::string name;
48 
49     name = get_std_name("en_US.UTF-8");
50     if(!name.empty()) {
51         std::cout << "- Testing " << name << std::endl;
52         std::locale l=gen(name);
53         test_one<CharType>(l,"Façade","façade","FAÇADE");
54     }
55     else {
56         std::cout << "- en_US.UTF-8 is not supported, skipping" << std::endl;
57     }
58 
59     name = get_std_name("en_US.ISO8859-1");
60     if(!name.empty()) {
61         std::cout << "Testing " << name << std::endl;
62         std::locale l=gen(name);
63         test_one<CharType>(l,"Hello World","hello world","HELLO WORLD");
64         test_one<CharType>(l,"Façade","façade","FAÇADE");
65     }
66     else {
67         std::cout << "- en_US.ISO8859-1 is not supported, skipping" << std::endl;
68     }
69     std::string real_name;
70     name = get_std_name("tr_TR.UTF-8",&real_name);
71     if(!name.empty()) {
72         std::cout << "Testing " << name << std::endl;
73         if(std::use_facet<std::ctype<wchar_t> >(std::locale(real_name.c_str())).toupper(L'i')!=L'I') {
74             std::locale l=gen(name);
75             test_one<CharType>(l,"i","i","İ");
76         }
77         else {
78             std::cout << "Standard library does not support this locale's case conversion correctly" << std::endl;
79         }
80     }
81     else
82     {
83         std::cout << "- tr_TR.UTF-8 is not supported, skipping" << std::endl;
84     }
85 }
86 
87 
main()88 int main()
89 {
90     try {
91         boost::locale::localization_backend_manager mgr = boost::locale::localization_backend_manager::global();
92         mgr.select("std");
93         boost::locale::localization_backend_manager::global(mgr);
94 
95         std::cout << "Testing char" << std::endl;
96         test_char<char>();
97         std::cout << "Testing wchar_t" << std::endl;
98         test_char<wchar_t>();
99         #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
100         std::cout << "Testing char16_t" << std::endl;
101         test_char<char16_t>();
102         #endif
103         #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
104         std::cout << "Testing char32_t" << std::endl;
105         test_char<char32_t>();
106         #endif
107     }
108     catch(std::exception const &e) {
109         std::cerr << "Failed " << e.what() << std::endl;
110         return EXIT_FAILURE;
111     }
112     FINALIZE();
113 
114 }
115 
116 #endif // no std
117 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
118 
119 
120 // boostinspect:noascii
121