Debian Codegraph @

libcxx/test/std/localization/locales/locale/locale.cons/char_pointer.pass.cpp

raw
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 // XFAIL: availability-char8_t_support-missing
16
17 // This test runs in C++20, but we have deprecated codecvt<char(16|32), char, mbstate_t> in C++20.
18 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
19
20 // <locale>
21
22 // explicit locale(const char* std_name);
23
24 #include <locale>
25 #include <new>
26 #include <cassert>
27
28 #include "count_new.h"
29 #include "platform_support.h" // locale name macros
30
31 #include "test_macros.h"
32
33 template<class CharT>
34 void check_for(const std::locale& loc)
35 {
36 assert(std::has_facet<std::collate<CharT> >(loc));
37
38 assert(std::has_facet<std::ctype<CharT> >(loc));
39
40 assert((std::has_facet<std::codecvt<CharT, char, std::mbstate_t> >(loc)));
41
42 assert(std::has_facet<std::moneypunct<CharT> >(loc));
43 assert(std::has_facet<std::money_get<CharT> >(loc));
44 assert(std::has_facet<std::money_put<CharT> >(loc));
45
46 assert(std::has_facet<std::numpunct<CharT> >(loc));
47 assert(std::has_facet<std::num_get<CharT> >(loc));
48 assert(std::has_facet<std::num_put<CharT> >(loc));
49
50 assert(std::has_facet<std::time_get<CharT> >(loc));
51 assert(std::has_facet<std::time_put<CharT> >(loc));
52
53 assert(std::has_facet<std::messages<CharT> >(loc));
54 }
55
56 void check(const std::locale& loc)
57 {
58 check_for<char>(loc);
59 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
60 check_for<wchar_t>(loc);
61 #endif
62
63 assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc)));
64 assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc)));
65 #if TEST_STD_VER > 17
66 assert((std::has_facet<std::codecvt<char16_t, char8_t, std::mbstate_t> >(loc)));
67 assert((std::has_facet<std::codecvt<char32_t, char8_t, std::mbstate_t> >(loc)));
68 #endif
69 }
70
71 int main(int, char**)
72 {
73 {
74 std::locale loc(LOCALE_ru_RU_UTF_8);
75 check(loc);
76 std::locale loc2(LOCALE_ru_RU_UTF_8);
77 check(loc2);
78 assert(loc == loc2);
79 std::locale loc3(LOCALE_zh_CN_UTF_8);
80 check(loc3);
81 assert(!(loc == loc3));
82 assert(loc != loc3);
83 #ifndef TEST_HAS_NO_EXCEPTIONS
84 try {
85 std::locale((const char*)0);
86 assert(false);
87 } catch (std::runtime_error&) {
88 // pass
89 }
90
91 try {
92 std::locale(nullptr);
93 assert(false);
94 } catch (std::runtime_error&) {
95 // pass
96 }
97
98 try {
99 std::locale("spazbot");
100 assert(false);
101 } catch (std::runtime_error&) {
102 // pass
103 }
104 #endif
105 std::locale ok("");
106 }
107 assert(globalMemCounter.checkOutstandingNewEq(0));
108
109 return 0;
110 }