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// REQUIRES: locale.zh_CN.UTF-8
11
12// XFAIL: availability-char8_t_support-missing
13
14// This test runs in C++20, but we have deprecated codecvt<char(16|32), char, mbstate_t> in C++20.
15// ADDITIONAL_COMPILE_FLAGS: -D_LIBCPP_DISABLE_DEPRECATION_WARNINGS
16
17// <locale>
18
19// explicit locale(const string& std_name);
20
21#include <locale>
22#include <new>
23#include <cassert>
24
25#include "count_new.h"
26#include "test_macros.h"
27#include "platform_support.h" // locale name macros
28
29template<class CharT>
30void 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
52void 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
67int main(int, char**)
68{
69 {
70 std::locale loc(std::string(LOCALE_ru_RU_UTF_8));
71 check(loc);
72 std::locale loc2(std::string(LOCALE_ru_RU_UTF_8));
73 check(loc2);
74 assert(loc == loc2);
75 std::locale loc3(std::string(LOCALE_zh_CN_UTF_8));
76 check(loc3);
77 assert(!(loc == loc3));
78 assert(loc != loc3);
79 }
80 assert(globalMemCounter.checkOutstandingNewEq(0));
81
82 return 0;
83}
84

source code of libcxx/test/std/localization/locales/locale/locale.cons/string.pass.cpp