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 // XFAIL: darwin
10 //
11 // NetBSD does not support LC_MONETARY at the moment
12 // XFAIL: netbsd
13 
14 // REQUIRES: locale.en_US.UTF-8
15 // REQUIRES: locale.fr_FR.UTF-8
16 // REQUIRES: locale.ru_RU.UTF-8
17 // REQUIRES: locale.zh_CN.UTF-8
18 
19 // <locale>
20 
21 // class moneypunct_byname<charT, International>
22 
23 // string_type curr_symbol() const;
24 
25 #include <locale>
26 #include <limits>
27 #include <cassert>
28 
29 #include "test_macros.h"
30 #include "platform_support.h" // locale name macros
31 
32 class Fnf
33     : public std::moneypunct_byname<char, false>
34 {
35 public:
Fnf(const std::string & nm,std::size_t refs=0)36     explicit Fnf(const std::string& nm, std::size_t refs = 0)
37         : std::moneypunct_byname<char, false>(nm, refs) {}
38 };
39 
40 class Fnt
41     : public std::moneypunct_byname<char, true>
42 {
43 public:
Fnt(const std::string & nm,std::size_t refs=0)44     explicit Fnt(const std::string& nm, std::size_t refs = 0)
45         : std::moneypunct_byname<char, true>(nm, refs) {}
46 };
47 
48 class Fwf
49     : public std::moneypunct_byname<wchar_t, false>
50 {
51 public:
Fwf(const std::string & nm,std::size_t refs=0)52     explicit Fwf(const std::string& nm, std::size_t refs = 0)
53         : std::moneypunct_byname<wchar_t, false>(nm, refs) {}
54 };
55 
56 class Fwt
57     : public std::moneypunct_byname<wchar_t, true>
58 {
59 public:
Fwt(const std::string & nm,std::size_t refs=0)60     explicit Fwt(const std::string& nm, std::size_t refs = 0)
61         : std::moneypunct_byname<wchar_t, true>(nm, refs) {}
62 };
63 
main(int,char **)64 int main(int, char**)
65 {
66     {
67         Fnf f("C", 1);
68         assert(f.curr_symbol() == std::string());
69     }
70     {
71         Fnt f("C", 1);
72         assert(f.curr_symbol() == std::string());
73     }
74     {
75         Fwf f("C", 1);
76         assert(f.curr_symbol() == std::wstring());
77     }
78     {
79         Fwt f("C", 1);
80         assert(f.curr_symbol() == std::wstring());
81     }
82 
83     {
84         Fnf f(LOCALE_en_US_UTF_8, 1);
85         assert(f.curr_symbol() == "$");
86     }
87     {
88         Fnt f(LOCALE_en_US_UTF_8, 1);
89         assert(f.curr_symbol() == "USD ");
90     }
91     {
92         Fwf f(LOCALE_en_US_UTF_8, 1);
93         assert(f.curr_symbol() == L"$");
94     }
95     {
96         Fwt f(LOCALE_en_US_UTF_8, 1);
97         assert(f.curr_symbol() == L"USD ");
98     }
99 
100     {
101         Fnf f(LOCALE_fr_FR_UTF_8, 1);
102         assert(f.curr_symbol() == " \u20ac");
103     }
104     {
105         Fnt f(LOCALE_fr_FR_UTF_8, 1);
106         assert(f.curr_symbol() == " EUR");
107     }
108     {
109         Fwf f(LOCALE_fr_FR_UTF_8, 1);
110         assert(f.curr_symbol() == L" \u20ac");
111     }
112     {
113         Fwt f(LOCALE_fr_FR_UTF_8, 1);
114         assert(f.curr_symbol() == L" EUR");
115     }
116 
117     {
118         Fnf f(LOCALE_ru_RU_UTF_8, 1);
119 #if defined(_CS_GNU_LIBC_VERSION)
120         // GLIBC <= 2.23 uses currency_symbol="<U0440><U0443><U0431>"
121         // GLIBC >= 2.24 uses currency_symbol="<U20BD>"
122         // See also: http://www.fileformat.info/info/unicode/char/20bd/index.htm
123         if (!glibc_version_less_than("2.24"))
124           assert(f.curr_symbol() == " \u20BD");
125         else
126           assert(f.curr_symbol() == " \xD1\x80\xD1\x83\xD0\xB1");
127 #else
128         assert(f.curr_symbol() == " \xD1\x80\xD1\x83\xD0\xB1");
129 #endif
130     }
131     {
132         Fnt f(LOCALE_ru_RU_UTF_8, 1);
133         assert(f.curr_symbol() == " RUB");
134     }
135     {
136         Fwf f(LOCALE_ru_RU_UTF_8, 1);
137 #if defined(_CS_GNU_LIBC_VERSION)
138         if (!glibc_version_less_than("2.24"))
139           assert(f.curr_symbol() == L" \u20BD");
140         else
141           assert(f.curr_symbol() == L" \x440\x443\x431");
142 #else
143         assert(f.curr_symbol() == L" \x440\x443\x431");
144 #endif
145     }
146 
147     {
148         Fwt f(LOCALE_ru_RU_UTF_8, 1);
149         assert(f.curr_symbol() == L" RUB");
150     }
151 
152     {
153         Fnf f(LOCALE_zh_CN_UTF_8, 1);
154         assert(f.curr_symbol() == "\xEF\xBF\xA5");
155     }
156     {
157         Fnt f(LOCALE_zh_CN_UTF_8, 1);
158         assert(f.curr_symbol() == "CNY ");
159     }
160     {
161         Fwf f(LOCALE_zh_CN_UTF_8, 1);
162         assert(f.curr_symbol() == L"\xFFE5");
163     }
164     {
165         Fwt f(LOCALE_zh_CN_UTF_8, 1);
166         assert(f.curr_symbol() == L"CNY ");
167     }
168 
169   return 0;
170 }
171