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// TODO(mordante) Investigate
10// UNSUPPORTED: apple-clang
11
12// NetBSD does not support LC_MONETARY at the moment
13// XFAIL: netbsd
14
15// REQUIRES: locale.en_US.UTF-8
16// REQUIRES: locale.fr_FR.UTF-8
17// REQUIRES: locale.ru_RU.UTF-8
18// REQUIRES: locale.zh_CN.UTF-8
19
20// <locale>
21
22// class moneypunct_byname<charT, International>
23
24// string_type curr_symbol() const;
25
26#include <locale>
27#include <limits>
28#include <cassert>
29
30#include "test_macros.h"
31#include "locale_helpers.h"
32#include "platform_support.h" // locale name macros
33
34class Fnf
35 : public std::moneypunct_byname<char, false>
36{
37public:
38 explicit Fnf(const std::string& nm, std::size_t refs = 0)
39 : std::moneypunct_byname<char, false>(nm, refs) {}
40};
41
42class Fnt
43 : public std::moneypunct_byname<char, true>
44{
45public:
46 explicit Fnt(const std::string& nm, std::size_t refs = 0)
47 : std::moneypunct_byname<char, true>(nm, refs) {}
48};
49
50#ifndef TEST_HAS_NO_WIDE_CHARACTERS
51class Fwf
52 : public std::moneypunct_byname<wchar_t, false>
53{
54public:
55 explicit Fwf(const std::string& nm, std::size_t refs = 0)
56 : std::moneypunct_byname<wchar_t, false>(nm, refs) {}
57};
58
59class Fwt
60 : public std::moneypunct_byname<wchar_t, true>
61{
62public:
63 explicit Fwt(const std::string& nm, std::size_t refs = 0)
64 : std::moneypunct_byname<wchar_t, true>(nm, refs) {}
65};
66#endif // TEST_HAS_NO_WIDE_CHARACTERS
67
68int main(int, char**)
69{
70 {
71 Fnf f("C", 1);
72 assert(f.curr_symbol() == std::string());
73 }
74 {
75 Fnt f("C", 1);
76 assert(f.curr_symbol() == std::string());
77 }
78#ifndef TEST_HAS_NO_WIDE_CHARACTERS
79 {
80 Fwf f("C", 1);
81 assert(f.curr_symbol() == std::wstring());
82 }
83 {
84 Fwt f("C", 1);
85 assert(f.curr_symbol() == std::wstring());
86 }
87#endif
88
89#ifdef _WIN32
90 std::string curr_space = "";
91#else
92 std::string curr_space = " ";
93#endif
94 {
95 Fnf f(LOCALE_en_US_UTF_8, 1);
96 assert(f.curr_symbol() == "$");
97 }
98 {
99 Fnt f(LOCALE_en_US_UTF_8, 1);
100 assert(f.curr_symbol() == "USD" + curr_space);
101 }
102#ifndef TEST_HAS_NO_WIDE_CHARACTERS
103#ifdef _WIN32
104 std::wstring w_curr_space = L"";
105#else
106 std::wstring w_curr_space = L" ";
107#endif
108 {
109 Fwf f(LOCALE_en_US_UTF_8, 1);
110 assert(f.curr_symbol() == L"$");
111 }
112 {
113 Fwt f(LOCALE_en_US_UTF_8, 1);
114 assert(f.curr_symbol() == L"USD" + w_curr_space);
115 }
116#endif
117
118 {
119 Fnf f(LOCALE_fr_FR_UTF_8, 1);
120#ifdef __APPLE__
121 assert(f.curr_symbol() == " Eu");
122#else
123 assert(f.curr_symbol() == " \u20ac");
124#endif
125 }
126 {
127 Fnt f(LOCALE_fr_FR_UTF_8, 1);
128 assert(f.curr_symbol() == " EUR");
129 }
130#ifndef TEST_HAS_NO_WIDE_CHARACTERS
131 {
132 Fwf f(LOCALE_fr_FR_UTF_8, 1);
133#ifdef __APPLE__
134 assert(f.curr_symbol() == L" Eu");
135#else
136 assert(f.curr_symbol() == L" \u20ac");
137#endif
138 }
139 {
140 Fwt f(LOCALE_fr_FR_UTF_8, 1);
141 assert(f.curr_symbol() == L" EUR");
142 }
143#endif
144
145 {
146 Fnf f(LOCALE_ru_RU_UTF_8, 1);
147 assert(f.curr_symbol() == " " + static_cast<std::string>(LocaleHelpers::currency_symbol_ru_RU()));
148 }
149 {
150 Fnt f(LOCALE_ru_RU_UTF_8, 1);
151 assert(f.curr_symbol() == " RUB");
152 }
153#ifndef TEST_HAS_NO_WIDE_CHARACTERS
154 {
155 Fwf f(LOCALE_ru_RU_UTF_8, 1);
156 assert(f.curr_symbol() == L" " + static_cast<std::wstring>(LocaleHelpers::currency_symbol_ru_RU()));
157 }
158
159 {
160 Fwt f(LOCALE_ru_RU_UTF_8, 1);
161 assert(f.curr_symbol() == L" RUB");
162 }
163#endif // TEST_HAS_NO_WIDE_CHARACTERS
164
165 {
166 Fnf f(LOCALE_zh_CN_UTF_8, 1);
167#ifdef _WIN32
168 assert(f.curr_symbol() == "\xC2\xA5"); // \u00A5
169#else
170 assert(f.curr_symbol() == "\xEF\xBF\xA5"); // \uFFE5
171#endif
172 }
173 {
174 Fnt f(LOCALE_zh_CN_UTF_8, 1);
175 assert(f.curr_symbol() == "CNY" + curr_space);
176 }
177#ifndef TEST_HAS_NO_WIDE_CHARACTERS
178 {
179 Fwf f(LOCALE_zh_CN_UTF_8, 1);
180#ifdef _WIN32
181 assert(f.curr_symbol() == L"\u00A5");
182#else
183 assert(f.curr_symbol() == L"\uFFE5");
184#endif
185 }
186 {
187 Fwt f(LOCALE_zh_CN_UTF_8, 1);
188 assert(f.curr_symbol() == L"CNY" + w_curr_space);
189 }
190#endif // TEST_HAS_NO_WIDE_CHARACTERS
191
192 return 0;
193}
194

source code of libcxx/test/std/localization/locale.categories/category.monetary/locale.moneypunct.byname/curr_symbol.pass.cpp