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 moneyT> T7 get_money(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 <cassert>
19#include <iomanip>
20#include <istream>
21#include <streambuf>
22
23#include "test_macros.h"
24#include "platform_support.h" // locale name macros
25
26template <class CharT>
27struct testbuf
28 : public std::basic_streambuf<CharT>
29{
30 typedef std::basic_string<CharT> string_type;
31 typedef std::basic_streambuf<CharT> base;
32private:
33 string_type str_;
34public:
35
36 testbuf() {}
37 testbuf(const string_type& str)
38 : str_(str)
39 {
40 base::setg(const_cast<CharT*>(str_.data()),
41 const_cast<CharT*>(str_.data()),
42 const_cast<CharT*>(str_.data()) + str_.size());
43 }
44};
45
46int main(int, char**)
47{
48 {
49#if defined(_WIN32)
50 testbuf<char> sb(" ($1,234,567.89)");
51#else
52 testbuf<char> sb(" -$1,234,567.89");
53#endif
54 std::istream is(&sb);
55 is.imbue(std::locale(LOCALE_en_US_UTF_8));
56 long double x = 0;
57 is >> std::get_money(mon&: x, intl: false);
58 assert(x == -123456789);
59 }
60 {
61#if defined(_WIN32)
62 testbuf<char> sb(" (USD 1,234,567.89)");
63#else
64 testbuf<char> sb(" -USD 1,234,567.89");
65#endif
66 std::istream is(&sb);
67 is.imbue(std::locale(LOCALE_en_US_UTF_8));
68 long double x = 0;
69 is >> std::get_money(mon&: x, intl: true);
70 assert(x == -123456789);
71 }
72#ifndef TEST_HAS_NO_WIDE_CHARACTERS
73 {
74#if defined(_WIN32)
75 testbuf<wchar_t> sb(L" ($1,234,567.89)");
76#else
77 testbuf<wchar_t> sb(L" -$1,234,567.89");
78#endif
79 std::wistream is(&sb);
80 is.imbue(std::locale(LOCALE_en_US_UTF_8));
81 long double x = 0;
82 is >> std::get_money(mon&: x, intl: false);
83 assert(x == -123456789);
84 }
85 {
86#if defined(_WIN32)
87 testbuf<wchar_t> sb(L" (USD 1,234,567.89)");
88#else
89 testbuf<wchar_t> sb(L" -USD 1,234,567.89");
90#endif
91 std::wistream is(&sb);
92 is.imbue(std::locale(LOCALE_en_US_UTF_8));
93 long double x = 0;
94 is >> std::get_money(mon&: x, intl: true);
95 assert(x == -123456789);
96 }
97#endif
98
99 return 0;
100}
101

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