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 // XFAIL: apple-darwin 11 12 // <locale> 13 14 // class money_put<charT, OutputIterator> 15 16 // iter_type put(iter_type s, bool intl, ios_base& f, char_type fill, 17 // long double units) const; 18 19 #include <locale> 20 #include <ios> 21 #include <streambuf> 22 #include <cassert> 23 #include "test_iterators.h" 24 25 #include "platform_support.h" // locale name macros 26 27 typedef std::money_put<char, output_iterator<char*> > Fn; 28 29 class my_facet 30 : public Fn 31 { 32 public: 33 explicit my_facet(std::size_t refs = 0) 34 : Fn(refs) {} 35 }; 36 37 typedef std::money_put<wchar_t, output_iterator<wchar_t*> > Fw; 38 39 class my_facetw 40 : public Fw 41 { 42 public: 43 explicit my_facetw(std::size_t refs = 0) 44 : Fw(refs) {} 45 }; 46 47 int main() 48 { 49 std::ios ios(0); 50 std::string loc_name(LOCALE_ru_RU_UTF_8); 51 ios.imbue(std::locale(ios.getloc(), 52 new std::moneypunct_byname<char, false>(loc_name))); 53 ios.imbue(std::locale(ios.getloc(), 54 new std::moneypunct_byname<char, true>(loc_name))); 55 ios.imbue(std::locale(ios.getloc(), 56 new std::moneypunct_byname<wchar_t, false>(loc_name))); 57 ios.imbue(std::locale(ios.getloc(), 58 new std::moneypunct_byname<wchar_t, true>(loc_name))); 59 { 60 const my_facet f(1); 61 // char, national 62 { // zero 63 long double v = 0; 64 char str[100]; 65 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 66 false, ios, '*', v); 67 std::string ex(str, iter.base()); 68 assert(ex == "0,00 "); 69 } 70 { // negative one 71 long double v = -1; 72 char str[100]; 73 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 74 false, ios, '*', v); 75 std::string ex(str, iter.base()); 76 assert(ex == "-0,01 "); 77 } 78 { // positive 79 long double v = 123456789; 80 char str[100]; 81 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 82 false, ios, '*', v); 83 std::string ex(str, iter.base()); 84 assert(ex == "1 234 567,89 "); 85 } 86 { // negative 87 long double v = -123456789; 88 char str[100]; 89 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 90 false, ios, '*', v); 91 std::string ex(str, iter.base()); 92 assert(ex == "-1 234 567,89 "); 93 } 94 { // zero, showbase 95 long double v = 0; 96 showbase(ios); 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 == "0,00 \xD1\x80\xD1\x83\xD0\xB1""."); 102 } 103 { // negative one, showbase 104 long double v = -1; 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,01 \xD1\x80\xD1\x83\xD0\xB1""."); 111 } 112 { // positive, showbase 113 long double v = 123456789; 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 == "1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); 120 } 121 { // negative, 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, left 131 long double v = -123456789; 132 showbase(ios); 133 ios.width(20); 134 left(ios); 135 char str[100]; 136 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 137 false, ios, ' ', v); 138 std::string ex(str, iter.base()); 139 assert(ex == "-1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); 140 assert(ios.width() == 0); 141 } 142 { // negative, showbase, internal 143 long double v = -123456789; 144 showbase(ios); 145 ios.width(20); 146 internal(ios); 147 char str[100]; 148 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 149 false, ios, ' ', v); 150 std::string ex(str, iter.base()); 151 assert(ex == "-1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); 152 assert(ios.width() == 0); 153 } 154 { // negative, showbase, right 155 long double v = -123456789; 156 showbase(ios); 157 ios.width(20); 158 right(ios); 159 char str[100]; 160 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 161 false, ios, ' ', v); 162 std::string ex(str, iter.base()); 163 assert(ex == "-1 234 567,89 \xD1\x80\xD1\x83\xD0\xB1""."); 164 assert(ios.width() == 0); 165 } 166 167 // char, international 168 noshowbase(ios); 169 ios.unsetf(std::ios_base::adjustfield); 170 { // zero 171 long double v = 0; 172 char str[100]; 173 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 174 true, ios, '*', v); 175 std::string ex(str, iter.base()); 176 assert(ex == "0,00 "); 177 } 178 { // negative one 179 long double v = -1; 180 char str[100]; 181 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 182 true, ios, '*', v); 183 std::string ex(str, iter.base()); 184 assert(ex == "-0,01 "); 185 } 186 { // positive 187 long double v = 123456789; 188 char str[100]; 189 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 190 true, ios, '*', v); 191 std::string ex(str, iter.base()); 192 assert(ex == "1 234 567,89 "); 193 } 194 { // negative 195 long double v = -123456789; 196 char str[100]; 197 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 198 true, ios, '*', v); 199 std::string ex(str, iter.base()); 200 assert(ex == "-1 234 567,89 "); 201 } 202 { // zero, showbase 203 long double v = 0; 204 showbase(ios); 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 == "0,00 RUB "); 210 } 211 { // negative one, showbase 212 long double v = -1; 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,01 RUB "); 219 } 220 { // positive, showbase 221 long double v = 123456789; 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 == "1 234 567,89 RUB "); 228 } 229 { // negative, 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, left 239 long double v = -123456789; 240 showbase(ios); 241 ios.width(20); 242 left(ios); 243 char str[100]; 244 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 245 true, ios, ' ', v); 246 std::string ex(str, iter.base()); 247 assert(ex == "-1 234 567,89 RUB "); 248 assert(ios.width() == 0); 249 } 250 { // negative, showbase, internal 251 long double v = -123456789; 252 showbase(ios); 253 ios.width(20); 254 internal(ios); 255 char str[100]; 256 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 257 true, ios, ' ', v); 258 std::string ex(str, iter.base()); 259 assert(ex == "-1 234 567,89 RUB "); 260 assert(ios.width() == 0); 261 } 262 { // negative, showbase, right 263 long double v = -123456789; 264 showbase(ios); 265 ios.width(20); 266 right(ios); 267 char str[100]; 268 output_iterator<char*> iter = f.put(output_iterator<char*>(str), 269 true, ios, ' ', v); 270 std::string ex(str, iter.base()); 271 assert(ex == " -1 234 567,89 RUB "); 272 assert(ios.width() == 0); 273 } 274 } 275 { 276 const my_facetw f(1); 277 // wchar_t, national 278 noshowbase(ios); 279 ios.unsetf(std::ios_base::adjustfield); 280 { // zero 281 long double v = 0; 282 wchar_t str[100]; 283 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 284 false, ios, '*', v); 285 std::wstring ex(str, iter.base()); 286 assert(ex == L"0,00 "); 287 } 288 { // negative one 289 long double v = -1; 290 wchar_t str[100]; 291 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 292 false, ios, '*', v); 293 std::wstring ex(str, iter.base()); 294 assert(ex == L"-0,01 "); 295 } 296 { // positive 297 long double v = 123456789; 298 wchar_t str[100]; 299 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 300 false, ios, '*', v); 301 std::wstring ex(str, iter.base()); 302 assert(ex == L"1 234 567,89 "); 303 } 304 { // negative 305 long double v = -123456789; 306 wchar_t str[100]; 307 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 308 false, ios, '*', v); 309 std::wstring ex(str, iter.base()); 310 assert(ex == L"-1 234 567,89 "); 311 } 312 { // zero, showbase 313 long double v = 0; 314 showbase(ios); 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"0,00 \x440\x443\x431""."); 320 } 321 { // negative one, showbase 322 long double v = -1; 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,01 \x440\x443\x431""."); 329 } 330 { // positive, showbase 331 long double v = 123456789; 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"1 234 567,89 \x440\x443\x431""."); 338 } 339 { // negative, 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, left 349 long double v = -123456789; 350 showbase(ios); 351 ios.width(20); 352 left(ios); 353 wchar_t str[100]; 354 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 355 false, ios, ' ', v); 356 std::wstring ex(str, iter.base()); 357 assert(ex == L"-1 234 567,89 \x440\x443\x431"". "); 358 assert(ios.width() == 0); 359 } 360 { // negative, showbase, internal 361 long double v = -123456789; 362 showbase(ios); 363 ios.width(20); 364 internal(ios); 365 wchar_t str[100]; 366 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 367 false, ios, ' ', v); 368 std::wstring ex(str, iter.base()); 369 assert(ex == L"-1 234 567,89 \x440\x443\x431""."); 370 assert(ios.width() == 0); 371 } 372 { // negative, showbase, right 373 long double v = -123456789; 374 showbase(ios); 375 ios.width(20); 376 right(ios); 377 wchar_t str[100]; 378 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 379 false, ios, ' ', v); 380 std::wstring ex(str, iter.base()); 381 assert(ex == L" -1 234 567,89 \x440\x443\x431""."); 382 assert(ios.width() == 0); 383 } 384 385 // wchar_t, international 386 noshowbase(ios); 387 ios.unsetf(std::ios_base::adjustfield); 388 { // zero 389 long double v = 0; 390 wchar_t str[100]; 391 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 392 true, ios, '*', v); 393 std::wstring ex(str, iter.base()); 394 assert(ex == L"0,00 "); 395 } 396 { // negative one 397 long double v = -1; 398 wchar_t str[100]; 399 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 400 true, ios, '*', v); 401 std::wstring ex(str, iter.base()); 402 assert(ex == L"-0,01 "); 403 } 404 { // positive 405 long double v = 123456789; 406 wchar_t str[100]; 407 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 408 true, ios, '*', v); 409 std::wstring ex(str, iter.base()); 410 assert(ex == L"1 234 567,89 "); 411 } 412 { // negative 413 long double v = -123456789; 414 wchar_t str[100]; 415 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 416 true, ios, '*', v); 417 std::wstring ex(str, iter.base()); 418 assert(ex == L"-1 234 567,89 "); 419 } 420 { // zero, showbase 421 long double v = 0; 422 showbase(ios); 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"0,00 RUB "); 428 } 429 { // negative one, showbase 430 long double v = -1; 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,01 RUB "); 437 } 438 { // positive, showbase 439 long double v = 123456789; 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"1 234 567,89 RUB "); 446 } 447 { // negative, 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, left 457 long double v = -123456789; 458 showbase(ios); 459 ios.width(20); 460 left(ios); 461 wchar_t str[100]; 462 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 463 true, ios, ' ', v); 464 std::wstring ex(str, iter.base()); 465 assert(ex == L"-1 234 567,89 RUB "); 466 assert(ios.width() == 0); 467 } 468 { // negative, showbase, internal 469 long double v = -123456789; 470 showbase(ios); 471 ios.width(20); 472 internal(ios); 473 wchar_t str[100]; 474 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 475 true, ios, ' ', v); 476 std::wstring ex(str, iter.base()); 477 assert(ex == L"-1 234 567,89 RUB "); 478 assert(ios.width() == 0); 479 } 480 { // negative, showbase, right 481 long double v = -123456789; 482 showbase(ios); 483 ios.width(20); 484 right(ios); 485 wchar_t str[100]; 486 output_iterator<wchar_t*> iter = f.put(output_iterator<wchar_t*>(str), 487 true, ios, ' ', v); 488 std::wstring ex(str, iter.base()); 489 assert(ex == L" -1 234 567,89 RUB "); 490 assert(ios.width() == 0); 491 } 492 } 493 } 494