put_long_double_ru_RU.pass.cpp revision e2f2a15066552758a508e8a7325e0ccad4a5389b
1//===----------------------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is dual licensed under the MIT and the University of Illinois Open 6// Source Licenses. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9 10// <locale> 11 12// class money_put<charT, OutputIterator> 13 14// iter_type put(iter_type s, bool intl, ios_base& f, char_type fill, 15// long double units) const; 16 17#include <locale> 18#include <ios> 19#include <streambuf> 20#include <cassert> 21#include "iterators.h" 22 23typedef std::money_put<char, output_iterator<char*> > Fn; 24 25class my_facet 26 : public Fn 27{ 28public: 29 explicit my_facet(std::size_t refs = 0) 30 : Fn(refs) {} 31}; 32 33typedef std::money_put<wchar_t, output_iterator<wchar_t*> > Fw; 34 35class my_facetw 36 : public Fw 37{ 38public: 39 explicit my_facetw(std::size_t refs = 0) 40 : Fw(refs) {} 41}; 42 43int main() 44{ 45 std::ios ios(0); 46 std::string loc_name("ru_RU.UTF-8"); 47 ios.imbue(std::locale(ios.getloc(), 48 new std::moneypunct_byname<char, false>(loc_name))); 49 ios.imbue(std::locale(ios.getloc(), 50 new std::moneypunct_byname<char, true>(loc_name))); 51 ios.imbue(std::locale(ios.getloc(), 52 new std::moneypunct_byname<wchar_t, false>(loc_name))); 53 ios.imbue(std::locale(ios.getloc(), 54 new std::moneypunct_byname<wchar_t, true>(loc_name))); 55{ 56 const my_facet f(1); 57 // char, national 58 { // zero 59 long double v = 0; 60 char str[100]; 61 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 62 false, ios, '*', v); 63 std::string ex(str, iter.base()); 64 assert(ex == "0,00 "); 65 } 66 { // negative one 67 long double v = -1; 68 char str[100]; 69 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 70 false, ios, '*', v); 71 std::string ex(str, iter.base()); 72 assert(ex == "-0,01 "); 73 } 74 { // positive 75 long double v = 123456789; 76 char str[100]; 77 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 78 false, ios, '*', v); 79 std::string ex(str, iter.base()); 80 assert(ex == "1 234 567,89 "); 81 } 82 { // negative 83 long double v = -123456789; 84 char str[100]; 85 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 86 false, ios, '*', v); 87 std::string ex(str, iter.base()); 88 assert(ex == "-1 234 567,89 "); 89 } 90 { // zero, showbase 91 long double v = 0; 92 showbase(ios); 93 char str[100]; 94 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 95 false, ios, '*', v); 96 std::string ex(str, iter.base()); 97 assert(ex == "0,00 \xD1\x80\xD1\x83\xD0\xB1""."); 98 } 99 { // negative one, showbase 100 long double v = -1; 101 showbase(ios); 102 char str[100]; 103 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 104 false, ios, '*', v); 105 std::string ex(str, iter.base()); 106 assert(ex == "-0,01 \xD1\x80\xD1\x83\xD0\xB1""."); 107 } 108 { // positive, showbase 109 long double v = 123456789; 110 showbase(ios); 111 char str[100]; 112 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 113 false, ios, '*', v); 114 std::string ex(str, iter.base()); 115 assert(ex == "1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); 116 } 117 { // negative, showbase 118 long double v = -123456789; 119 showbase(ios); 120 char str[100]; 121 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 122 false, ios, '*', v); 123 std::string ex(str, iter.base()); 124 assert(ex == "-1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); 125 } 126 { // negative, showbase, left 127 long double v = -123456789; 128 showbase(ios); 129 ios.width(20); 130 left(ios); 131 char str[100]; 132 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 133 false, ios, ' ', v); 134 std::string ex(str, iter.base()); 135 assert(ex == "-1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); 136 assert(ios.width() == 0); 137 } 138 { // negative, showbase, internal 139 long double v = -123456789; 140 showbase(ios); 141 ios.width(20); 142 internal(ios); 143 char str[100]; 144 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 145 false, ios, ' ', v); 146 std::string ex(str, iter.base()); 147 assert(ex == "-1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); 148 assert(ios.width() == 0); 149 } 150 { // negative, showbase, right 151 long double v = -123456789; 152 showbase(ios); 153 ios.width(20); 154 right(ios); 155 char str[100]; 156 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 157 false, ios, ' ', v); 158 std::string ex(str, iter.base()); 159 assert(ex == "-1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); 160 assert(ios.width() == 0); 161 } 162 163 // char, international 164 noshowbase(ios); 165 ios.unsetf(std::ios_base::adjustfield); 166 { // zero 167 long double v = 0; 168 char str[100]; 169 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 170 true, ios, '*', v); 171 std::string ex(str, iter.base()); 172 assert(ex == "0,00 "); 173 } 174 { // negative one 175 long double v = -1; 176 char str[100]; 177 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 178 true, ios, '*', v); 179 std::string ex(str, iter.base()); 180 assert(ex == "-0,01 "); 181 } 182 { // positive 183 long double v = 123456789; 184 char str[100]; 185 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 186 true, ios, '*', v); 187 std::string ex(str, iter.base()); 188 assert(ex == "1 234 567,89 "); 189 } 190 { // negative 191 long double v = -123456789; 192 char str[100]; 193 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 194 true, ios, '*', v); 195 std::string ex(str, iter.base()); 196 assert(ex == "-1 234 567,89 "); 197 } 198 { // zero, showbase 199 long double v = 0; 200 showbase(ios); 201 char str[100]; 202 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 203 true, ios, '*', v); 204 std::string ex(str, iter.base()); 205 assert(ex == "0,00 RUB "); 206 } 207 { // negative one, showbase 208 long double v = -1; 209 showbase(ios); 210 char str[100]; 211 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 212 true, ios, '*', v); 213 std::string ex(str, iter.base()); 214 assert(ex == "-0,01 RUB "); 215 } 216 { // positive, showbase 217 long double v = 123456789; 218 showbase(ios); 219 char str[100]; 220 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 221 true, ios, '*', v); 222 std::string ex(str, iter.base()); 223 assert(ex == "1 234 567,89 RUB "); 224 } 225 { // negative, showbase 226 long double v = -123456789; 227 showbase(ios); 228 char str[100]; 229 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 230 true, ios, '*', v); 231 std::string ex(str, iter.base()); 232 assert(ex == "-1 234 567,89 RUB "); 233 } 234 { // negative, showbase, left 235 long double v = -123456789; 236 showbase(ios); 237 ios.width(20); 238 left(ios); 239 char str[100]; 240 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 241 true, ios, ' ', v); 242 std::string ex(str, iter.base()); 243 assert(ex == "-1 234 567,89 RUB "); 244 assert(ios.width() == 0); 245 } 246 { // negative, showbase, internal 247 long double v = -123456789; 248 showbase(ios); 249 ios.width(20); 250 internal(ios); 251 char str[100]; 252 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 253 true, ios, ' ', v); 254 std::string ex(str, iter.base()); 255 assert(ex == "-1 234 567,89 RUB "); 256 assert(ios.width() == 0); 257 } 258 { // negative, showbase, right 259 long double v = -123456789; 260 showbase(ios); 261 ios.width(20); 262 right(ios); 263 char str[100]; 264 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 265 true, ios, ' ', v); 266 std::string ex(str, iter.base()); 267 assert(ex == " -1 234 567,89 RUB "); 268 assert(ios.width() == 0); 269 } 270} 271{ 272 const my_facetw f(1); 273 // wchar_t, national 274 noshowbase(ios); 275 ios.unsetf(std::ios_base::adjustfield); 276 { // zero 277 long double v = 0; 278 wchar_t str[100]; 279 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 280 false, ios, '*', v); 281 std::wstring ex(str, iter.base()); 282 assert(ex == L"0,00 "); 283 } 284 { // negative one 285 long double v = -1; 286 wchar_t str[100]; 287 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 288 false, ios, '*', v); 289 std::wstring ex(str, iter.base()); 290 assert(ex == L"-0,01 "); 291 } 292 { // positive 293 long double v = 123456789; 294 wchar_t str[100]; 295 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 296 false, ios, '*', v); 297 std::wstring ex(str, iter.base()); 298 assert(ex == L"1 234 567,89 "); 299 } 300 { // negative 301 long double v = -123456789; 302 wchar_t str[100]; 303 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 304 false, ios, '*', v); 305 std::wstring ex(str, iter.base()); 306 assert(ex == L"-1 234 567,89 "); 307 } 308 { // zero, showbase 309 long double v = 0; 310 showbase(ios); 311 wchar_t str[100]; 312 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 313 false, ios, '*', v); 314 std::wstring ex(str, iter.base()); 315 assert(ex == L"0,00 \x440\x443\x431""."); 316 } 317 { // negative one, showbase 318 long double v = -1; 319 showbase(ios); 320 wchar_t str[100]; 321 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 322 false, ios, '*', v); 323 std::wstring ex(str, iter.base()); 324 assert(ex == L"-0,01 \x440\x443\x431""."); 325 } 326 { // positive, showbase 327 long double v = 123456789; 328 showbase(ios); 329 wchar_t str[100]; 330 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 331 false, ios, '*', v); 332 std::wstring ex(str, iter.base()); 333 assert(ex == L"1 234 567,89 \x440\x443\x431""."); 334 } 335 { // negative, showbase 336 long double v = -123456789; 337 showbase(ios); 338 wchar_t str[100]; 339 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 340 false, ios, '*', v); 341 std::wstring ex(str, iter.base()); 342 assert(ex == L"-1 234 567,89 \x440\x443\x431""."); 343 } 344 { // negative, showbase, left 345 long double v = -123456789; 346 showbase(ios); 347 ios.width(20); 348 left(ios); 349 wchar_t str[100]; 350 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 351 false, ios, ' ', v); 352 std::wstring ex(str, iter.base()); 353 assert(ex == L"-1 234 567,89 \x440\x443\x431"". "); 354 assert(ios.width() == 0); 355 } 356 { // negative, showbase, internal 357 long double v = -123456789; 358 showbase(ios); 359 ios.width(20); 360 internal(ios); 361 wchar_t str[100]; 362 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 363 false, ios, ' ', v); 364 std::wstring ex(str, iter.base()); 365 assert(ex == L"-1 234 567,89 \x440\x443\x431""."); 366 assert(ios.width() == 0); 367 } 368 { // negative, showbase, right 369 long double v = -123456789; 370 showbase(ios); 371 ios.width(20); 372 right(ios); 373 wchar_t str[100]; 374 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 375 false, ios, ' ', v); 376 std::wstring ex(str, iter.base()); 377 assert(ex == L" -1 234 567,89 \x440\x443\x431""."); 378 assert(ios.width() == 0); 379 } 380 381 // wchar_t, international 382 noshowbase(ios); 383 ios.unsetf(std::ios_base::adjustfield); 384 { // zero 385 long double v = 0; 386 wchar_t str[100]; 387 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 388 true, ios, '*', v); 389 std::wstring ex(str, iter.base()); 390 assert(ex == L"0,00 "); 391 } 392 { // negative one 393 long double v = -1; 394 wchar_t str[100]; 395 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 396 true, ios, '*', v); 397 std::wstring ex(str, iter.base()); 398 assert(ex == L"-0,01 "); 399 } 400 { // positive 401 long double v = 123456789; 402 wchar_t str[100]; 403 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 404 true, ios, '*', v); 405 std::wstring ex(str, iter.base()); 406 assert(ex == L"1 234 567,89 "); 407 } 408 { // negative 409 long double v = -123456789; 410 wchar_t str[100]; 411 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 412 true, ios, '*', v); 413 std::wstring ex(str, iter.base()); 414 assert(ex == L"-1 234 567,89 "); 415 } 416 { // zero, showbase 417 long double v = 0; 418 showbase(ios); 419 wchar_t str[100]; 420 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 421 true, ios, '*', v); 422 std::wstring ex(str, iter.base()); 423 assert(ex == L"0,00 RUB "); 424 } 425 { // negative one, showbase 426 long double v = -1; 427 showbase(ios); 428 wchar_t str[100]; 429 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 430 true, ios, '*', v); 431 std::wstring ex(str, iter.base()); 432 assert(ex == L"-0,01 RUB "); 433 } 434 { // positive, showbase 435 long double v = 123456789; 436 showbase(ios); 437 wchar_t str[100]; 438 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 439 true, ios, '*', v); 440 std::wstring ex(str, iter.base()); 441 assert(ex == L"1 234 567,89 RUB "); 442 } 443 { // negative, showbase 444 long double v = -123456789; 445 showbase(ios); 446 wchar_t str[100]; 447 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 448 true, ios, '*', v); 449 std::wstring ex(str, iter.base()); 450 assert(ex == L"-1 234 567,89 RUB "); 451 } 452 { // negative, showbase, left 453 long double v = -123456789; 454 showbase(ios); 455 ios.width(20); 456 left(ios); 457 wchar_t str[100]; 458 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 459 true, ios, ' ', v); 460 std::wstring ex(str, iter.base()); 461 assert(ex == L"-1 234 567,89 RUB "); 462 assert(ios.width() == 0); 463 } 464 { // negative, showbase, internal 465 long double v = -123456789; 466 showbase(ios); 467 ios.width(20); 468 internal(ios); 469 wchar_t str[100]; 470 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 471 true, ios, ' ', v); 472 std::wstring ex(str, iter.base()); 473 assert(ex == L"-1 234 567,89 RUB "); 474 assert(ios.width() == 0); 475 } 476 { // negative, showbase, right 477 long double v = -123456789; 478 showbase(ios); 479 ios.width(20); 480 right(ios); 481 wchar_t str[100]; 482 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 483 true, ios, ' ', v); 484 std::wstring ex(str, iter.base()); 485 assert(ex == L" -1 234 567,89 RUB "); 486 assert(ios.width() == 0); 487 } 488} 489} 490