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.en_US.UTF-8
10// REQUIRES: locale.zh_CN.UTF-8
11
12// <locale>
13
14// Test locale name construction for the following constructors:
15// locale(const locale& other, const char* std_name, category cat);
16// locale(const locale& other, const string& std_name, category cat);
17// locale(const locale& other, const locale& one, category cats);
18
19// This test exercises the fix for locale name construction (D119441), which
20// isn't in the dylib for some systems.
21// XFAIL: stdlib=apple-libc++ && target={{.+}}-apple-macosx{{10.9|10.10|10.11|10.12|10.13|10.14|10.15|11.0|12.0}}
22
23#include <locale>
24#include <cassert>
25#include "platform_support.h" // locale name macros
26
27int main(int, char**) {
28 std::locale en(LOCALE_en_US_UTF_8);
29 std::locale zh(LOCALE_zh_CN_UTF_8);
30 std::locale unnamed(std::locale(), new std::ctype<char>);
31 {
32 std::locale loc(unnamed, en, std::locale::time);
33 assert(loc.name() == "*");
34 }
35 {
36 std::locale loc(en, unnamed, std::locale::none);
37 assert(loc.name() == "*");
38 }
39 {
40 std::locale loc(en, "", std::locale::none);
41 assert(loc.name() == en.name());
42 }
43 {
44 std::locale loc(en, zh, std::locale::none);
45 assert(loc.name() == en.name());
46 }
47 {
48 std::locale loc(en, LOCALE_en_US_UTF_8, std::locale::time);
49 assert(loc.name() == en.name());
50 }
51 {
52 std::locale loc(en, std::string(LOCALE_en_US_UTF_8), std::locale::collate);
53 assert(loc.name() == en.name());
54 }
55 return 0;
56}
57

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