]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/regex/test/regress/test_locale.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / regex / test / regress / test_locale.cpp
CommitLineData
7c673cae
FG
1/*
2 *
3 * Copyright (c) 2004
4 * John Maddock
5 *
6 * Use, modification and distribution are subject to the
7 * Boost Software License, Version 1.0. (See accompanying file
8 * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
9 *
10 */
11
12#include "test.hpp"
13#include <clocale>
14#if defined(BOOST_WINDOWS) && !defined(BOOST_DISABLE_WIN32)
15#include <boost/scoped_array.hpp>
16#include <windows.h>
17#endif
18#include <iostream>
19#include <iomanip>
20
21#ifdef BOOST_MSVC
22#pragma warning(disable:4127)
23#endif
24
25#ifdef BOOST_NO_STDC_NAMESPACE
26namespace std{ using ::setlocale; }
27#endif
28
29test_locale::test_locale(const char* c_name, boost::uint32_t lcid)
30{
31#ifndef UNDER_CE
32 // store the name:
33 m_old_name = m_name;
34 m_name = c_name;
35 // back up C locale and then set it's new name:
36 const char* pl = std::setlocale(LC_ALL, 0);
37 m_old_c_locale = pl ? pl : "";
38 m_old_c_state = s_c_locale;
39 if(std::setlocale(LC_ALL, c_name))
40 {
41 s_c_locale = test_with_locale;
42 std::cout << "Testing the global C locale: " << c_name << std::endl;
43 }
44 else
45 {
46 s_c_locale = no_test;
47 std::cout << "The global C locale: " << c_name << " is not available and will not be tested." << std::endl;
48 }
49#else
50 s_c_locale = no_test;
51#endif
52#if !defined(BOOST_NO_STD_LOCALE) && !defined(BOOST_NO_EXCEPTIONS)
53 // back up the C++ locale and create the new one:
54 m_old_cpp_locale = s_cpp_locale_inst;
55 m_old_cpp_state = s_cpp_locale;
56 try{
57 s_cpp_locale_inst = std::locale(c_name);
58 s_cpp_locale = test_with_locale;
59 std::cout << "Testing the C++ locale: " << c_name << std::endl;
60 }
61 catch(std::runtime_error const &)
62 {
63 s_cpp_locale = no_test;
64 std::cout << "The C++ locale: " << c_name << " is not available and will not be tested." << std::endl;
65 }
66#else
67 m_old_cpp_locale = s_cpp_locale_inst;
68 m_old_cpp_state = s_cpp_locale;
69 s_cpp_locale = no_test;
70#endif
71
72 // back up win locale and create the new one:
73 m_old_win_locale = s_win_locale_inst;
74 m_old_win_state = s_win_locale;
75 s_win_locale_inst = lcid;
76#if defined(BOOST_WINDOWS) && !defined(BOOST_DISABLE_WIN32)
77 //
78 // Start by geting the printable name of the locale.
79 // We use this for debugging purposes only:
80 //
81#ifndef BOOST_NO_ANSI_APIS
82 boost::scoped_array<char> p;
83 int r = ::GetLocaleInfoA(
84 lcid, // locale identifier
85 LOCALE_SCOUNTRY, // information type
86 0, // information buffer
87 0 // size of buffer
88 );
89 p.reset(new char[r+1]);
90 r = ::GetLocaleInfoA(
91 lcid, // locale identifier
92 LOCALE_SCOUNTRY, // information type
93 p.get(), // information buffer
94 r+1 // size of buffer
95 );
96#else
97 WCHAR code_page_string[7];
98 int r = ::GetLocaleInfoW(
99 lcid,
100 LOCALE_IDEFAULTANSICODEPAGE,
101 code_page_string,
102 7);
103 BOOST_ASSERT(r != 0);
104
105 UINT code_page = static_cast<UINT>(_wtol(code_page_string));
106
107 boost::scoped_array<wchar_t> wp;
108 r = ::GetLocaleInfoW(
109 lcid, // locale identifier
110 LOCALE_SCOUNTRY, // information type
111 0, // information buffer
112 0 // size of buffer
113 );
114 wp.reset(new wchar_t[r+1]);
115 r = ::GetLocaleInfoW(
116 lcid, // locale identifier
117 LOCALE_SCOUNTRY, // information type
118 wp.get(), // information buffer
119 r+1 // size of buffer
120 );
121
122 int name_size = (r+1) * 2;
123 boost::scoped_array<char> p(new char[name_size]);
124 int conv_r = ::WideCharToMultiByte(
125 code_page,
126 0,
127 wp.get(), r,
128 p.get(), name_size,
129 NULL, NULL
130 );
131 BOOST_ASSERT(conv_r != 0);
132#endif
133 //
134 // now see if locale is installed and behave accordingly:
135 //
136 if(::IsValidLocale(lcid, LCID_INSTALLED))
137 {
138 s_win_locale = test_with_locale;
139 std::cout << "Testing the Win32 locale: \"" << p.get() << "\" (0x" << std::hex << lcid << ")" << std::endl;
140 }
141 else
142 {
143 s_win_locale = no_test;
144 std::cout << "The Win32 locale: \"" << p.get() << "\" (0x" << std::hex << lcid << ") is not available and will not be tested." << std::endl;
145 }
146#else
147 s_win_locale = no_test;
148#endif
149}
150
151test_locale::~test_locale()
152{
153 // restore to previous state:
154#ifndef UNDER_CE
155 std::setlocale(LC_ALL, m_old_c_locale.c_str());
156 s_c_locale = m_old_c_state;
157#endif
158#ifndef BOOST_NO_STD_LOCALE
159 s_cpp_locale_inst = m_old_cpp_locale;
160#endif
161 s_cpp_locale = m_old_cpp_state;
162 s_win_locale_inst = m_old_win_locale;
163 s_win_locale = m_old_win_state;
164 m_name = m_old_name;
165}
166
167int test_locale::s_c_locale = test_no_locale;
168int test_locale::s_cpp_locale = test_no_locale;
169int test_locale::s_win_locale = test_no_locale;
170#ifndef BOOST_NO_STD_LOCALE
171std::locale test_locale::s_cpp_locale_inst;
172#endif
173boost::uint32_t test_locale::s_win_locale_inst = 0;
174std::string test_locale::m_name;
175
176
177void test_en_locale(const char* name, boost::uint32_t lcid)
178{
179 using namespace boost::regex_constants;
180 errors_as_warnings w;
181 test_locale l(name, lcid);
182 TEST_REGEX_SEARCH_L("[[:lower:]]+", perl, "\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xf7", match_default, make_array(1, 32, -2, -2));
183 TEST_REGEX_SEARCH_L("[[:upper:]]+", perl, "\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf", match_default, make_array(1, 31, -2, -2));
184// TEST_REGEX_SEARCH_L("[[:punct:]]+", perl, "\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0", match_default, make_array(0, 31, -2, -2));
185 TEST_REGEX_SEARCH_L("[[:print:]]+", perl, "\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe", match_default, make_array(0, 93, -2, -2));
186 TEST_REGEX_SEARCH_L("[[:graph:]]+", perl, "\xa1\xa2\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xae\xaf\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe", match_default, make_array(0, 93, -2, -2));
187 TEST_REGEX_SEARCH_L("[[:word:]]+", perl, "\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe", match_default, make_array(0, 61, -2, -2));
188 // collation sensitive ranges:
189#if !BOOST_WORKAROUND(__BORLANDC__, < 0x600)
190 // these tests are disabled for Borland C++: a bug in std::collate<wchar_t>
191 // causes these tests to crash (pointer overrun in std::collate<wchar_t>::do_transform).
192 TEST_REGEX_SEARCH_L("[a-z]+", perl|::boost::regex_constants::collate, "\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc", match_default, make_array(0, 28, -2, -2));
193 TEST_REGEX_SEARCH_L("[a-z]+", perl|::boost::regex_constants::collate, "\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc", match_default, make_array(1, 28, -2, -2));
b32b8144
FG
194 if (lcid != 0x09)
195 {
196 // and equivalence classes, these fail for locale "en" but pass for "en_UK" and "en_US":
197 TEST_REGEX_SEARCH_L("[[=a=]]+", perl, "aA\xe0\xe1\xe2\xe3\xe4\xe5\xc0\xc1\xc2\xc3\xc4\xc5", match_default, make_array(0, 14, -2, -2));
198 }
7c673cae
FG
199 // case mapping:
200 TEST_REGEX_SEARCH_L("[A-Z]+", perl|icase|::boost::regex_constants::collate, "\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc", match_default, make_array(0, 28, -2, -2));
201 TEST_REGEX_SEARCH_L("[a-z]+", perl|icase|::boost::regex_constants::collate, "\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc", match_default, make_array(1, 28, -2, -2));
202 TEST_REGEX_SEARCH_L("\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd", perl|icase, "\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe", match_default, make_array(1, 30, -2, -2));
203#endif
204}
205
206void test_en_locale()
207{
208 // VC6 seems to have problems with std::setlocale, I've never
209 // gotten to the bottem of this as the program runs fine under the
210 // debugger, but hangs when run from bjam:
211#if !BOOST_WORKAROUND(BOOST_MSVC, <1300) && !(defined(__ICL) && defined(_MSC_VER) && (_MSC_VER == 1200))
212 test_en_locale("en_US", 0x09 | 0x01 << 10);
213 test_en_locale("en_UK", 0x09 | 0x02 << 10);
214 test_en_locale("en", 0x09);
215#endif
216}
217
218