1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 // 10 // NetBSD does not support most of LC_* at the moment 11 // XFAIL: netbsd 12 13 // REQUIRES: locale.ru_RU.UTF-8 14 // REQUIRES: locale.zh_CN.UTF-8 15 16 // <locale> 17 18 // explicit locale(const char* std_name); 19 20 #include <locale> 21 #include <new> 22 #include <cassert> 23 24 #include "count_new.hpp" 25 #include "platform_support.h" // locale name macros 26 27 #include "test_macros.h" 28 29 check(const std::locale & loc)30void check(const std::locale& loc) 31 { 32 assert(std::has_facet<std::collate<char> >(loc)); 33 assert(std::has_facet<std::collate<wchar_t> >(loc)); 34 35 assert(std::has_facet<std::ctype<char> >(loc)); 36 assert(std::has_facet<std::ctype<wchar_t> >(loc)); 37 assert((std::has_facet<std::codecvt<char, char, std::mbstate_t> >(loc))); 38 assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc))); 39 assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc))); 40 assert((std::has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc))); 41 42 assert((std::has_facet<std::moneypunct<char> >(loc))); 43 assert((std::has_facet<std::moneypunct<wchar_t> >(loc))); 44 assert((std::has_facet<std::money_get<char> >(loc))); 45 assert((std::has_facet<std::money_get<wchar_t> >(loc))); 46 assert((std::has_facet<std::money_put<char> >(loc))); 47 assert((std::has_facet<std::money_put<wchar_t> >(loc))); 48 49 assert((std::has_facet<std::numpunct<char> >(loc))); 50 assert((std::has_facet<std::numpunct<wchar_t> >(loc))); 51 assert((std::has_facet<std::num_get<char> >(loc))); 52 assert((std::has_facet<std::num_get<wchar_t> >(loc))); 53 assert((std::has_facet<std::num_put<char> >(loc))); 54 assert((std::has_facet<std::num_put<wchar_t> >(loc))); 55 56 assert((std::has_facet<std::time_get<char> >(loc))); 57 assert((std::has_facet<std::time_get<wchar_t> >(loc))); 58 assert((std::has_facet<std::time_put<char> >(loc))); 59 assert((std::has_facet<std::time_put<wchar_t> >(loc))); 60 61 assert((std::has_facet<std::messages<char> >(loc))); 62 assert((std::has_facet<std::messages<wchar_t> >(loc))); 63 } 64 main()65int main() 66 { 67 { 68 std::locale loc(LOCALE_ru_RU_UTF_8); 69 check(loc); 70 std::locale loc2(LOCALE_ru_RU_UTF_8); 71 check(loc2); 72 assert(loc == loc2); 73 std::locale loc3(LOCALE_zh_CN_UTF_8); 74 check(loc3); 75 assert(!(loc == loc3)); 76 assert(loc != loc3); 77 #ifndef TEST_HAS_NO_EXCEPTIONS 78 try 79 { 80 std::locale((const char*)0); 81 assert(false); 82 } 83 catch (std::runtime_error&) 84 { 85 } 86 try 87 { 88 std::locale("spazbot"); 89 assert(false); 90 } 91 catch (std::runtime_error&) 92 { 93 } 94 #endif 95 std::locale ok(""); 96 } 97 assert(globalMemCounter.checkOutstandingNewEq(0)); 98 } 99