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 // REQUIRES: locale.ru_RU.UTF-8 11 // REQUIRES: locale.zh_CN.UTF-8 12 // UNSUPPORTED: sanitizer-new-delete 13 14 // <locale> 15 16 // explicit locale(const char* std_name); 17 18 #include <locale> 19 #include <new> 20 #include <cassert> 21 22 #include "platform_support.h" // locale name macros 23 24 int new_called = 0; 25 operator new(std::size_t s)26void* operator new(std::size_t s) throw(std::bad_alloc) 27 { 28 ++new_called; 29 return std::malloc(s); 30 } 31 operator delete(void * p)32void operator delete(void* p) throw() 33 { 34 --new_called; 35 std::free(p); 36 } 37 check(const std::locale & loc)38void check(const std::locale& loc) 39 { 40 assert(std::has_facet<std::collate<char> >(loc)); 41 assert(std::has_facet<std::collate<wchar_t> >(loc)); 42 43 assert(std::has_facet<std::ctype<char> >(loc)); 44 assert(std::has_facet<std::ctype<wchar_t> >(loc)); 45 assert((std::has_facet<std::codecvt<char, char, std::mbstate_t> >(loc))); 46 assert((std::has_facet<std::codecvt<char16_t, char, std::mbstate_t> >(loc))); 47 assert((std::has_facet<std::codecvt<char32_t, char, std::mbstate_t> >(loc))); 48 assert((std::has_facet<std::codecvt<wchar_t, char, std::mbstate_t> >(loc))); 49 50 assert((std::has_facet<std::moneypunct<char> >(loc))); 51 assert((std::has_facet<std::moneypunct<wchar_t> >(loc))); 52 assert((std::has_facet<std::money_get<char> >(loc))); 53 assert((std::has_facet<std::money_get<wchar_t> >(loc))); 54 assert((std::has_facet<std::money_put<char> >(loc))); 55 assert((std::has_facet<std::money_put<wchar_t> >(loc))); 56 57 assert((std::has_facet<std::numpunct<char> >(loc))); 58 assert((std::has_facet<std::numpunct<wchar_t> >(loc))); 59 assert((std::has_facet<std::num_get<char> >(loc))); 60 assert((std::has_facet<std::num_get<wchar_t> >(loc))); 61 assert((std::has_facet<std::num_put<char> >(loc))); 62 assert((std::has_facet<std::num_put<wchar_t> >(loc))); 63 64 assert((std::has_facet<std::time_get<char> >(loc))); 65 assert((std::has_facet<std::time_get<wchar_t> >(loc))); 66 assert((std::has_facet<std::time_put<char> >(loc))); 67 assert((std::has_facet<std::time_put<wchar_t> >(loc))); 68 69 assert((std::has_facet<std::messages<char> >(loc))); 70 assert((std::has_facet<std::messages<wchar_t> >(loc))); 71 } 72 main()73int main() 74 { 75 { 76 std::locale loc(LOCALE_ru_RU_UTF_8); 77 check(loc); 78 std::locale loc2(LOCALE_ru_RU_UTF_8); 79 check(loc2); 80 assert(loc == loc2); 81 std::locale loc3(LOCALE_zh_CN_UTF_8); 82 check(loc3); 83 assert(!(loc == loc3)); 84 assert(loc != loc3); 85 try 86 { 87 std::locale((const char*)0); 88 assert(false); 89 } 90 catch (std::runtime_error&) 91 { 92 } 93 try 94 { 95 std::locale("spazbot"); 96 assert(false); 97 } 98 catch (std::runtime_error&) 99 { 100 } 101 std::locale ok(""); 102 } 103 assert(new_called == 0); 104 } 105