1//===----------------------------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <iomanip>
10
11// template <class charT, class moneyT> T8 put_money(const moneyT& mon, bool intl = false);
12
13// Bionic has minimal locale support, investigate this later.
14// XFAIL: LIBCXX-ANDROID-FIXME
15
16// REQUIRES: locale.en_US.UTF-8
17
18#include <iomanip>
19#include <ostream>
20#include <cassert>
21
22#include "test_macros.h"
23#include "platform_support.h" // locale name macros
24
25template <class CharT>
26class testbuf
27 : public std::basic_streambuf<CharT>
28{
29 typedef std::basic_streambuf<CharT> base;
30 std::basic_string<CharT> str_;
31public:
32 testbuf()
33 {
34 }
35
36 std::basic_string<CharT> str() const
37 {return std::basic_string<CharT>(base::pbase(), base::pptr());}
38
39protected:
40
41 virtual typename base::int_type
42 overflow(typename base::int_type ch = base::traits_type::eof())
43 {
44 if (ch != base::traits_type::eof())
45 {
46 int n = str_.size();
47 str_.push_back(static_cast<CharT>(ch));
48 str_.resize(str_.capacity());
49 base::setp(const_cast<CharT*>(str_.data()),
50 const_cast<CharT*>(str_.data() + str_.size()));
51 base::pbump(n+1);
52 }
53 return ch;
54 }
55};
56
57int main(int, char**)
58{
59 {
60 testbuf<char> sb;
61 std::ostream os(&sb);
62 os.imbue(std::locale(LOCALE_en_US_UTF_8));
63 std::showbase(base&: os);
64 long double x = -123456789;
65 os << std::put_money(mon: x, intl: false);
66#if defined(_WIN32)
67 assert(sb.str() == "($1,234,567.89)");
68#else
69 assert(sb.str() == "-$1,234,567.89");
70#endif
71 }
72 {
73 testbuf<char> sb;
74 std::ostream os(&sb);
75 os.imbue(std::locale(LOCALE_en_US_UTF_8));
76 std::showbase(base&: os);
77 long double x = -123456789;
78 os << std::put_money(mon: x, intl: true);
79#if defined(_WIN32)
80 assert(sb.str() == "(USD1,234,567.89)");
81#else
82 assert(sb.str() == "-USD 1,234,567.89");
83#endif
84 }
85#ifndef TEST_HAS_NO_WIDE_CHARACTERS
86 {
87 testbuf<wchar_t> sb;
88 std::wostream os(&sb);
89 os.imbue(std::locale(LOCALE_en_US_UTF_8));
90 std::showbase(base&: os);
91 long double x = -123456789;
92 os << std::put_money(mon: x, intl: false);
93#if defined(_WIN32)
94 assert(sb.str() == L"($1,234,567.89)");
95#else
96 assert(sb.str() == L"-$1,234,567.89");
97#endif
98 }
99 {
100 testbuf<wchar_t> sb;
101 std::wostream os(&sb);
102 os.imbue(std::locale(LOCALE_en_US_UTF_8));
103 std::showbase(base&: os);
104 long double x = -123456789;
105 os << std::put_money(mon: x, intl: true);
106#if defined(_WIN32)
107 assert(sb.str() == L"(USD1,234,567.89)");
108#else
109 assert(sb.str() == L"-USD 1,234,567.89");
110#endif
111 }
112#endif
113
114 return 0;
115}
116

source code of libcxx/test/std/input.output/iostream.format/ext.manip/put_money.pass.cpp