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