| 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 (http://llvm.org/D119441 aka 643b7bcdb404), |
| 20 | // which isn't in the dylib for some systems. |
| 21 | // XFAIL: using-built-library-before-llvm-17 |
| 22 | |
| 23 | #include <locale> |
| 24 | #include <cassert> |
| 25 | #include "platform_support.h" // locale name macros |
| 26 | |
| 27 | int 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 | |