brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · bd0693a Raw
111 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// NetBSD does not support most of LC_* at the moment10// XFAIL: netbsd11 12// REQUIRES: locale.ru_RU.UTF-813// REQUIRES: locale.zh_CN.UTF-814 15// XFAIL: availability-char8_t_support-missing16 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_WARNINGS19 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 macros30 31#include "test_macros.h"32 33template<class CharT>34void 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 56void check(const std::locale& loc)57{58    check_for<char>(loc);59#ifndef TEST_HAS_NO_WIDE_CHARACTERS60    check_for<wchar_t>(loc);61#endif62 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 > 1766    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#endif69}70 71int 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_EXCEPTIONS84        try {85            std::locale((const char*)0);86            assert(false);87        } catch (std::runtime_error&) {88            // pass89        }90 91        try {92            std::locale(nullptr);93            assert(false);94        } catch (std::runtime_error&) {95            // pass96        }97 98        try {99            std::locale("spazbot");100            assert(false);101        } catch (std::runtime_error&) {102            // pass103        }104#endif105        std::locale ok("");106    }107    assert(globalMemCounter.checkOutstandingNewEq(0));108 109  return 0;110}111