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 // NetBSD does not support most of LC_* at the moment
10 // XFAIL: netbsd
11
12 // REQUIRES: locale.ru_RU.UTF-8
13 // REQUIRES: locale.zh_CN.UTF-8
14
15 // This test relies on P0482 being fixed, which isn't in
16 // older Apple dylibs
17 //
18 // XFAIL: with_system_cxx_lib=macosx10.15
19 // XFAIL: with_system_cxx_lib=macosx10.14
20 // XFAIL: with_system_cxx_lib=macosx10.13
21 // XFAIL: with_system_cxx_lib=macosx10.12
22 // XFAIL: with_system_cxx_lib=macosx10.11
23 // XFAIL: with_system_cxx_lib=macosx10.10
24 // XFAIL: with_system_cxx_lib=macosx10.9
25
26 // This test runs in C++20, but we have deprecated codecvt<char(16|32), char, mbstate_t> in C++20.
27 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
28
29 // <locale>
30
31 // explicit locale(const char* std_name);
32
33 #include <locale>
34 #include <new>
35 #include <cassert>
36
37 #include "count_new.h"
38 #include "platform_support.h" // locale name macros
39
40 #include "test_macros.h"
41
42
check(const std::locale & loc)43 void check(const std::locale& loc)
44 {
45 assert(std::has_facet<std::collate<char> >(loc));
46 assert(std::has_facet<std::collate<wchar_t> >(loc));
47
48 assert(std::has_facet<std::ctype<char> >(loc));
49 assert(std::has_facet<std::ctype<wchar_t> >(loc));
50 assert((std::has_facet<std::codecvt<char, char, std::mbstate_t> >(loc)));
51 assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc)));
52 assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc)));
53 #if TEST_STD_VER > 17
54 assert((std::has_facet<std::codecvt<char16_t, char8_t, std::mbstate_t> >(loc)));
55 assert((std::has_facet<std::codecvt<char32_t, char8_t, std::mbstate_t> >(loc)));
56 #endif
57 assert((std::has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc)));
58
59 assert((std::has_facet<std::moneypunct<char> >(loc)));
60 assert((std::has_facet<std::moneypunct<wchar_t> >(loc)));
61 assert((std::has_facet<std::money_get<char> >(loc)));
62 assert((std::has_facet<std::money_get<wchar_t> >(loc)));
63 assert((std::has_facet<std::money_put<char> >(loc)));
64 assert((std::has_facet<std::money_put<wchar_t> >(loc)));
65
66 assert((std::has_facet<std::numpunct<char> >(loc)));
67 assert((std::has_facet<std::numpunct<wchar_t> >(loc)));
68 assert((std::has_facet<std::num_get<char> >(loc)));
69 assert((std::has_facet<std::num_get<wchar_t> >(loc)));
70 assert((std::has_facet<std::num_put<char> >(loc)));
71 assert((std::has_facet<std::num_put<wchar_t> >(loc)));
72
73 assert((std::has_facet<std::time_get<char> >(loc)));
74 assert((std::has_facet<std::time_get<wchar_t> >(loc)));
75 assert((std::has_facet<std::time_put<char> >(loc)));
76 assert((std::has_facet<std::time_put<wchar_t> >(loc)));
77
78 assert((std::has_facet<std::messages<char> >(loc)));
79 assert((std::has_facet<std::messages<wchar_t> >(loc)));
80 }
81
main(int,char **)82 int main(int, char**)
83 {
84 {
85 std::locale loc(LOCALE_ru_RU_UTF_8);
86 check(loc);
87 std::locale loc2(LOCALE_ru_RU_UTF_8);
88 check(loc2);
89 assert(loc == loc2);
90 std::locale loc3(LOCALE_zh_CN_UTF_8);
91 check(loc3);
92 assert(!(loc == loc3));
93 assert(loc != loc3);
94 #ifndef TEST_HAS_NO_EXCEPTIONS
95 try
96 {
97 std::locale((const char*)0);
98 assert(false);
99 }
100 catch (std::runtime_error&)
101 {
102 }
103 try
104 {
105 std::locale("spazbot");
106 assert(false);
107 }
108 catch (std::runtime_error&)
109 {
110 }
111 #endif
112 std::locale ok("");
113 }
114 assert(globalMemCounter.checkOutstandingNewEq(0));
115
116 return 0;
117 }
118