| 1 |
// 2000-08-31 Benjamin Kosnik <[email protected]> |
| 2 |
|
| 3 |
// Copyright (C) 2000-2025 Free Software Foundation, Inc. |
| 4 |
// |
| 5 |
// This file is part of the GNU ISO C++ Library. This library is free |
| 6 |
// software; you can redistribute it and/or modify it under the |
| 7 |
// terms of the GNU General Public License as published by the |
| 8 |
// Free Software Foundation; either version 3, or (at your option) |
| 9 |
// any later version. |
| 10 |
|
| 11 |
// This library is distributed in the hope that it will be useful, |
| 12 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
// GNU General Public License for more details. |
| 15 |
|
| 16 |
// You should have received a copy of the GNU General Public License along |
| 17 |
// with this library; see the file COPYING3. If not see |
| 18 |
// <http://www.gnu.org/licenses/>. |
| 19 |
|
| 20 |
// 22.1.1.1.2 - class locale::facet [lib.locale.facet] |
| 21 |
|
| 22 |
#include <cwchar> // for mbstate_t |
| 23 |
#include <locale> |
| 24 |
#include <stdexcept> |
| 25 |
#include <string> |
| 26 |
#include <iterator> |
| 27 |
#include <limits> |
| 28 |
#include <testsuite_hooks.h> |
| 29 |
|
| 30 |
// 1 a class if a facet if it is publicly derived from another facet |
| 31 |
typedef std::istreambuf_iterator<char> input_iterator; |
| 32 |
typedef std::ostreambuf_iterator<char> output_iterator; |
| 33 |
|
| 34 |
class gnu_collate: public std::collate<char> { }; |
| 35 |
class gnu_ctype: public std::ctype<char> { }; |
| 36 |
class gnu_codecvt: public std::codecvt<char, char, std::mbstate_t> { }; |
| 37 |
class gnu_moneypunct: public std::moneypunct<char> { }; |
| 38 |
class gnu_moneypunct_true: public std::moneypunct<char, true> { }; |
| 39 |
class gnu_money_get: public std::money_get<char> { }; |
| 40 |
class gnu_money_put: public std::money_put<char> { }; |
| 41 |
class gnu_numpunct: public std::numpunct<char> { }; |
| 42 |
class gnu_num_get: public std::num_get<char> { }; |
| 43 |
class gnu_num_put: public std::num_put<char> { }; |
| 44 |
class gnu_time_get: public std::time_get<char> { }; |
| 45 |
class gnu_time_put: public std::time_put<char> { }; |
| 46 |
class gnu_messages: public std::messages<char> { }; |
| 47 |
|
| 48 |
class gnu_collate_byname: public std::collate_byname<char> |
| 49 |
{ |
| 50 |
public: |
| 51 |
explicit |
| 52 |
gnu_collate_byname(const char* c, size_t refs = 0) |
| 53 |
: std::collate_byname<char>(c, refs) { } |
| 54 |
}; |
| 55 |
|
| 56 |
class gnu_ctype_byname: public std::ctype_byname<char> |
| 57 |
{ |
| 58 |
public: |
| 59 |
explicit |
| 60 |
gnu_ctype_byname(const char* c, size_t refs = 0) |
| 61 |
: std::ctype_byname<char>(c, refs) { } |
| 62 |
}; |
| 63 |
|
| 64 |
class gnu_moneypunct_byname_true: public std::moneypunct_byname<char, true> |
| 65 |
{ |
| 66 |
public: |
| 67 |
explicit |
| 68 |
gnu_moneypunct_byname_true(const char* c, size_t refs = 0) |
| 69 |
: std::moneypunct_byname<char, true>(c, refs) { } |
| 70 |
}; |
| 71 |
|
| 72 |
class gnu_moneypunct_byname_false: public std::moneypunct_byname<char, false> |
| 73 |
{ |
| 74 |
public: |
| 75 |
explicit |
| 76 |
gnu_moneypunct_byname_false(const char* c, size_t refs = 0) |
| 77 |
: std::moneypunct_byname<char, false>(c, refs) { } |
| 78 |
}; |
| 79 |
|
| 80 |
|
| 81 |
class gnu_money_get_in: public std::money_get<char, input_iterator> |
| 82 |
{ |
| 83 |
public: |
| 84 |
explicit |
| 85 |
gnu_money_get_in(size_t refs = 0) |
| 86 |
: std::money_get<char, input_iterator>(refs) { } |
| 87 |
}; |
| 88 |
|
| 89 |
class gnu_money_put_out: public std::money_put<char, output_iterator> |
| 90 |
{ |
| 91 |
public: |
| 92 |
explicit |
| 93 |
gnu_money_put_out(size_t refs = 0) |
| 94 |
: std::money_put<char, output_iterator>(refs) { } |
| 95 |
}; |
| 96 |
|
| 97 |
class gnu_numpunct_byname: public std::numpunct_byname<char> |
| 98 |
{ |
| 99 |
public: |
| 100 |
explicit |
| 101 |
gnu_numpunct_byname(const char* c, size_t refs = 0) |
| 102 |
: std::numpunct_byname<char>(c, refs) { } |
| 103 |
}; |
| 104 |
|
| 105 |
class gnu_num_get_in: public std::num_get<char, input_iterator> |
| 106 |
{ |
| 107 |
public: |
| 108 |
explicit |
| 109 |
gnu_num_get_in(size_t refs = 0) |
| 110 |
: std::num_get<char, input_iterator>(refs) { } |
| 111 |
}; |
| 112 |
|
| 113 |
class gnu_num_put_out: public std::num_put<char, output_iterator> |
| 114 |
{ |
| 115 |
public: |
| 116 |
explicit |
| 117 |
gnu_num_put_out(size_t refs = 0) |
| 118 |
: std::num_put<char, output_iterator>(refs) { } |
| 119 |
}; |
| 120 |
|
| 121 |
class gnu_time_get_byname: public std::time_get_byname<char> |
| 122 |
{ |
| 123 |
public: |
| 124 |
explicit |
| 125 |
gnu_time_get_byname(const char* c, size_t refs = 0) |
| 126 |
: std::time_get_byname<char>(c, refs) { } |
| 127 |
}; |
| 128 |
|
| 129 |
class gnu_time_get_in: public std::time_get<char, input_iterator> |
| 130 |
{ |
| 131 |
public: |
| 132 |
explicit |
| 133 |
gnu_time_get_in(size_t refs = 0) |
| 134 |
: std::time_get<char, input_iterator>(refs) { } |
| 135 |
}; |
| 136 |
|
| 137 |
class gnu_time_put_byname: public std::time_put_byname<char> |
| 138 |
{ |
| 139 |
public: |
| 140 |
explicit |
| 141 |
gnu_time_put_byname(const char* c, size_t refs = 0) |
| 142 |
: std::time_put_byname<char>(c, refs) { } |
| 143 |
}; |
| 144 |
|
| 145 |
class gnu_time_put_out: public std::time_put<char, output_iterator> |
| 146 |
{ |
| 147 |
public: |
| 148 |
explicit |
| 149 |
gnu_time_put_out(size_t refs = 0) |
| 150 |
: std::time_put<char, output_iterator>(refs) { } |
| 151 |
}; |
| 152 |
|
| 153 |
class gnu_messages_byname: public std::messages_byname<char> |
| 154 |
{ |
| 155 |
public: |
| 156 |
explicit |
| 157 |
gnu_messages_byname(const char* c, size_t refs = 0) |
| 158 |
: std::messages_byname<char>(c, refs) { } |
| 159 |
}; |
| 160 |
|
| 161 |
|
| 162 |
// 2 or if it is a class derived from locale:;facet and containing a |
| 163 |
// publicly-accessible declaration as follows: |
| 164 |
class gnu_facet: public std::locale::facet |
| 165 |
{ |
| 166 |
public: |
| 167 |
static std::locale::id id; |
| 168 |
}; |
| 169 |
|
| 170 |
std::locale::id gnu_facet::id; |
| 171 |
|
| 172 |
void test01() |
| 173 |
{ |
| 174 |
const std::string name_no("*"); |
| 175 |
const std::string name_c("C"); |
| 176 |
|
| 177 |
try |
| 178 |
{ |
| 179 |
gnu_collate obj01; |
| 180 |
gnu_ctype obj02; |
| 181 |
gnu_codecvt obj03; |
| 182 |
gnu_moneypunct obj04; |
| 183 |
gnu_moneypunct_true obj05; |
| 184 |
gnu_money_get obj06; |
| 185 |
gnu_money_put obj07; |
| 186 |
gnu_numpunct obj08; |
| 187 |
gnu_num_get obj09; |
| 188 |
gnu_num_put obj10; |
| 189 |
gnu_time_get obj11; |
| 190 |
gnu_time_put obj12; |
| 191 |
gnu_messages obj13; |
| 192 |
gnu_time_put_out obj14(0); |
| 193 |
gnu_time_put_byname obj15("C", 0); |
| 194 |
gnu_time_get_in obj16(0); |
| 195 |
gnu_time_get_byname obj17("C", 0); |
| 196 |
gnu_num_put_out obj18(0); |
| 197 |
gnu_num_get_in obj19(0); |
| 198 |
gnu_numpunct_byname obj20("C", 0); |
| 199 |
gnu_money_put_out obj21(0); |
| 200 |
gnu_money_get_in obj22(0); |
| 201 |
gnu_moneypunct_byname_false obj23("C", 0); |
| 202 |
gnu_moneypunct_byname_true obj24("C", 0); |
| 203 |
gnu_ctype_byname obj25("C", 0); |
| 204 |
gnu_collate_byname obj26("C", 0); |
| 205 |
gnu_messages_byname obj27("C", 0); |
| 206 |
} |
| 207 |
catch (std::runtime_error& obj) |
| 208 |
{ |
| 209 |
// named locale not valid |
| 210 |
VERIFY( false ); |
| 211 |
} |
| 212 |
catch (std::exception& obj) |
| 213 |
{ |
| 214 |
// some other error |
| 215 |
VERIFY( false ); |
| 216 |
} |
| 217 |
|
| 218 |
// 2 |
| 219 |
try |
| 220 |
{ |
| 221 |
gnu_facet obj28; |
| 222 |
} |
| 223 |
catch (std::runtime_error& obj) |
| 224 |
{ |
| 225 |
// named locale not valid |
| 226 |
VERIFY( false ); |
| 227 |
} |
| 228 |
catch (std::exception& obj) |
| 229 |
{ |
| 230 |
// some other error |
| 231 |
VERIFY( false ); |
| 232 |
} |
| 233 |
} |
| 234 |
|
| 235 |
int main () |
| 236 |
{ |
| 237 |
test01(); |
| 238 |
return 0; |
| 239 |
} |