Debian Codegraph @

libcxx/test/std/localization/locales/locale/locale.cons/locale_facetptr.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 // REQUIRES: locale.ru_RU.UTF-8
10
11 // XFAIL: availability-char8_t_support-missing
12
13 // This test runs in C++20, but we have deprecated codecvt<char(16|32), char, mbstate_t> in C++20.
14 // ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
15
16 // <locale>
17
18 // template <class Facet> locale(const locale& other, Facet* f);
19
20 #include <locale>
21 #include <new>
22 #include <cassert>
23
24 #include "count_new.h"
25 #include "test_macros.h"
26 #include "platform_support.h" // locale name macros
27
28
29 template<class CharT>
30 void check_for(const std::locale& loc)
31 {
32 assert(std::has_facet<std::collate<CharT> >(loc));
33
34 assert(std::has_facet<std::ctype<CharT> >(loc));
35
36 assert((std::has_facet<std::codecvt<CharT, char, std::mbstate_t> >(loc)));
37
38 assert(std::has_facet<std::moneypunct<CharT> >(loc));
39 assert(std::has_facet<std::money_get<CharT> >(loc));
40 assert(std::has_facet<std::money_put<CharT> >(loc));
41
42 assert(std::has_facet<std::numpunct<CharT> >(loc));
43 assert(std::has_facet<std::num_get<CharT> >(loc));
44 assert(std::has_facet<std::num_put<CharT> >(loc));
45
46 assert(std::has_facet<std::time_get<CharT> >(loc));
47 assert(std::has_facet<std::time_put<CharT> >(loc));
48
49 assert(std::has_facet<std::messages<CharT> >(loc));
50 }
51
52 void check(const std::locale& loc)
53 {
54 check_for<char>(loc);
55 #ifndef TEST_HAS_NO_WIDE_CHARACTERS
56 check_for<wchar_t>(loc);
57 #endif
58
59 assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc)));
60 assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc)));
61 #if TEST_STD_VER > 17
62 assert((std::has_facet<std::codecvt<char16_t, char8_t, std::mbstate_t> >(loc)));
63 assert((std::has_facet<std::codecvt<char32_t, char8_t, std::mbstate_t> >(loc)));
64 #endif
65 }
66
67 struct my_facet
68 : public std::locale::facet
69 {
70 int test() const {return 5;}
71
72 static std::locale::id id;
73 };
74
75 std::locale::id my_facet::id;
76
77 int main(int, char**)
78 {
79 {
80 std::locale loc(LOCALE_ru_RU_UTF_8);
81 check(loc);
82 std::locale loc2(loc, new my_facet);
83 check(loc2);
84 assert((std::has_facet<my_facet>(loc2)));
85 const my_facet& f = std::use_facet<my_facet>(loc2);
86 assert(f.test() == 5);
87 }
88 assert(globalMemCounter.checkOutstandingNewEq(0));
89 {
90 std::locale loc;
91 check(loc);
92 std::locale loc2(loc, (std::ctype<char>*)0);
93 check(loc2);
94 assert(loc == loc2);
95 }
96 assert(globalMemCounter.checkOutstandingNewEq(0));
97
98 return 0;
99 }