• 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 #ifdef BOOST_LOCALE_NO_POSIX_BACKEND
9 #include <iostream>
main()10 int main()
11 {
12         std::cout << "POSIX Backend is not build... Skipping" << std::endl;
13 }
14 #else
15 #include <boost/locale/conversion.hpp>
16 #include <boost/locale/localization_backend.hpp>
17 #include <boost/locale/generator.hpp>
18 #include <boost/locale/info.hpp>
19 #include <iomanip>
20 #include "test_locale.hpp"
21 #include "test_locale_tools.hpp"
22 #include "test_posix_tools.hpp"
23 #include <iostream>
24 
25 #include <wctype.h>
26 
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 = "en_US.UTF-8";
48     if(have_locale(name)) {
49         std::cout << "- Testing " << name << std::endl;
50         std::locale l=gen(name);
51         test_one<CharType>(l,"Façade","façade","FAÇADE");
52     }
53     else {
54         std::cout << "- en_US.UTF-8 is not supported, skipping" << std::endl;
55     }
56 
57     name = "en_US.ISO8859-1";
58     if(have_locale(name)) {
59         std::cout << "Testing " << name << std::endl;
60         std::locale l=gen(name);
61         test_one<CharType>(l,"Hello World","hello world","HELLO WORLD");
62         #if defined(__APPLE__) || defined(__FreeBSD__)
63         if(sizeof(CharType)!=1)
64         #endif
65             test_one<CharType>(l,"Façade","façade","FAÇADE");
66     }
67     else {
68         std::cout << "- en_US.ISO8859-1 is not supported, skipping" << std::endl;
69     }
70 
71     name = "tr_TR.UTF-8";
72     if(have_locale(name)) {
73         std::cout << "Testing " << name << std::endl;
74         locale_t cl = newlocale(LC_ALL_MASK,name.c_str(),0);
75         try {
76             TEST(cl);
77             if(towupper_l(L'i',cl) == 0x130) {
78                 test_one<CharType>(gen(name),"i","i","İ");
79             }
80             else {
81                 std::cout <<"  Turkish locale is not supported well" << std::endl;
82             }
83         }
84         catch(...) {
85             if(cl) freelocale(cl);
86             throw;
87         }
88         if(cl) freelocale(cl);
89 
90     }
91     else
92     {
93         std::cout << "- tr_TR.UTF-8 is not supported, skipping" << std::endl;
94     }
95 }
96 
97 
main()98 int main()
99 {
100     try {
101         boost::locale::localization_backend_manager mgr = boost::locale::localization_backend_manager::global();
102         mgr.select("posix");
103         boost::locale::localization_backend_manager::global(mgr);
104 
105         std::cout << "Testing char" << std::endl;
106         test_char<char>();
107         std::cout << "Testing wchar_t" << std::endl;
108         test_char<wchar_t>();
109     }
110     catch(std::exception const &e) {
111         std::cerr << "Failed " << e.what() << std::endl;
112         return EXIT_FAILURE;
113     }
114     FINALIZE();
115 
116 }
117 
118 #endif // POSIX
119 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
120 
121 
122 // boostinspect:noascii
123