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 #include <iostream>
10 #include <iomanip>
11 #include <stdlib.h>
12 #include <locale.h>
13 #include <locale>
14 #include <time.h>
15 #include <stdexcept>
16
17 #include <boost/locale.hpp>
18 #ifdef BOOST_LOCALE_WITH_ICU
19 #include <unicode/uversion.h>
20 #endif
21
22
env(char const * s)23 char const *env(char const *s)
24 {
25 char const *r=getenv(s);
26 if(r)
27 return r;
28 return "";
29 }
30
check_locale(char const ** names)31 void check_locale(char const **names)
32 {
33 std::cout << " " << std::setw(32) << "locale" << std::setw(4) << "C" << std::setw(4) << "C++" << std::endl;
34 while(*names) {
35 char const *name = *names;
36 std::cout << " " << std::setw(32) << name << std::setw(4);
37 if(setlocale(LC_ALL,name)!=0)
38 std::cout << "Yes";
39 else
40 std::cout << "No";
41 std::cout << std::setw(4);
42 try {
43 std::locale l(name);
44 std::cout << "Yes";
45 }
46 catch(std::exception const &) {
47 std::cout << "No";
48 }
49 std::cout << std::endl;
50 names++;
51 }
52 }
53
main()54 int main()
55 {
56 std::cout << "- Backends: ";
57 #ifdef BOOST_LOCALE_WITH_ICU
58 std::cout << "icu:" << U_ICU_VERSION << " ";
59 #endif
60 #ifndef BOOST_LOCALE_NO_STD_BACKEND
61 std::cout << "std ";
62 #endif
63 #ifndef BOOST_LOCALE_NO_POSIX_BACKEND
64 std::cout << "posix ";
65 #endif
66 #ifndef BOOST_LOCALE_NO_WINAPI_BACKEND
67 std::cout << "winapi";
68 #endif
69 std::cout << std::endl;
70 #ifdef BOOST_LOCALE_WITH_ICONV
71 std::cout << "- With iconv" << std::endl;
72 #else
73 std::cout << "- Without iconv" << std::endl;
74 #endif
75 std::cout << "- Environment " << std::endl;
76 std::cout << " LANG="<< env("LANG") << std::endl;
77 std::cout << " LC_ALL="<< env("LC_ALL") << std::endl;
78 std::cout << " LC_CTYPE="<< env("LC_CTYPE") << std::endl;
79 std::cout << " TZ="<< env("TZ") << std::endl;
80
81 char const *clocale=setlocale(LC_ALL,"");
82 if(!clocale)
83 clocale= "undetected";
84 std::cout <<"- C locale: " << clocale << std::endl;
85
86 try {
87 std::locale loc("");
88 std::cout << "- C++ locale: " << loc.name() << std::endl;
89 }
90 catch(std::exception const &) {
91 std::cout << "- C++ locale: is not supported" << std::endl;
92 }
93
94 char const *locales_to_check[] = {
95 "en_US.UTF-8", "en_US.ISO8859-1", "English_United States.1252",
96 "he_IL.UTF-8", "he_IL.ISO8859-8", "Hebrew_Israel.1255",
97 "ru_RU.UTF-8", "Russian_Russia.1251",
98 "tr_TR.UTF-8", "Turkish_Turkey.1254",
99 "ja_JP.UTF-8", "ja_JP.SJIS", "Japanese_Japan.932",
100 0
101 };
102 std::cout << "- Testing locales availability on the operation system:" << std::endl;
103 check_locale(locales_to_check);
104
105 std::cout << "- Testing timezone and time " << std::endl;
106 {
107 setlocale(LC_ALL,"C");
108 time_t now = time(0);
109 char buf[1024];
110 strftime(buf,sizeof(buf),"%%c=%c; %%Z=%Z; %%z=%z",localtime(&now));
111 std::cout << " Local Time :" << buf << std::endl;
112 strftime(buf,sizeof(buf),"%%c=%c; %%Z=%Z; %%z=%z",gmtime(&now));
113 std::cout << " Universal Time:" << buf << std::endl;
114 }
115 std::cout << "- Boost.Locale's locale: ";
116 try {
117 boost::locale::generator gen;
118 std::locale l = gen("");
119 std::cout << std::use_facet<boost::locale::info>(l).name() << std::endl;
120 }
121 catch(std::exception const &) {
122 std::cout << " undetected" << std::endl;
123 return EXIT_FAILURE;
124 }
125 return EXIT_SUCCESS;
126
127 }
128
129 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
130 // boostinspect:noascii
131