1 // 2 // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See 5 // accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 // 8 9 #include <boost/locale/generator.hpp> 10 #include <boost/locale/info.hpp> 11 #include <boost/locale/message.hpp> 12 #include <iomanip> 13 #include "test_locale.hpp" 14 15 has_message(std::locale const & l)16bool has_message(std::locale const &l) 17 { 18 return std::has_facet<boost::locale::message_format<char> >(l); 19 } 20 21 struct test_facet : public std::locale::facet { test_facettest_facet22 test_facet() : std::locale::facet(0) {} 23 static std::locale::id id; 24 }; 25 26 std::locale::id test_facet::id; 27 28 main()29int main() 30 { 31 try { 32 boost::locale::generator g; 33 std::locale l=g("en_US.UTF-8"); 34 TEST(has_message(l)); 35 36 g.categories(g.categories() ^ boost::locale::message_facet); 37 g.locale_cache_enabled(true); 38 g("en_US.UTF-8"); 39 g.categories(g.categories() | boost::locale::message_facet); 40 l=g("en_US.UTF-8"); 41 TEST(!has_message(l)); 42 g.clear_cache(); 43 g.locale_cache_enabled(false); 44 l=g("en_US.UTF-8"); 45 TEST(has_message(l)); 46 g.characters(g.characters() ^ boost::locale::char_facet); 47 l=g("en_US.UTF-8"); 48 TEST(!has_message(l)); 49 g.characters(g.characters() | boost::locale::char_facet); 50 l=g("en_US.UTF-8"); 51 TEST(has_message(l)); 52 53 l=g("en_US.ISO8859-1"); 54 TEST(std::use_facet<boost::locale::info>(l).language()=="en"); 55 TEST(std::use_facet<boost::locale::info>(l).country()=="US"); 56 TEST(!std::use_facet<boost::locale::info>(l).utf8()); 57 TEST(std::use_facet<boost::locale::info>(l).encoding()=="iso8859-1"); 58 59 l=g("en_US.UTF-8"); 60 TEST(std::use_facet<boost::locale::info>(l).language()=="en"); 61 TEST(std::use_facet<boost::locale::info>(l).country()=="US"); 62 TEST(std::use_facet<boost::locale::info>(l).utf8()); 63 64 l=g("en_US.ISO8859-1"); 65 TEST(std::use_facet<boost::locale::info>(l).language()=="en"); 66 TEST(std::use_facet<boost::locale::info>(l).country()=="US"); 67 TEST(!std::use_facet<boost::locale::info>(l).utf8()); 68 TEST(std::use_facet<boost::locale::info>(l).encoding()=="iso8859-1"); 69 70 l=g("en_US.ISO8859-1"); 71 TEST(std::use_facet<boost::locale::info>(l).language()=="en"); 72 TEST(std::use_facet<boost::locale::info>(l).country()=="US"); 73 TEST(!std::use_facet<boost::locale::info>(l).utf8()); 74 TEST(std::use_facet<boost::locale::info>(l).encoding()=="iso8859-1"); 75 76 std::locale l_wt(std::locale::classic(),new test_facet); 77 78 TEST(std::has_facet<test_facet>(g.generate(l_wt,"en_US.UTF-8"))); 79 TEST(std::has_facet<test_facet>(g.generate(l_wt,"en_US.ISO8859-1"))); 80 TEST(!std::has_facet<test_facet>(g("en_US.UTF-8"))); 81 TEST(!std::has_facet<test_facet>(g("en_US.ISO8859-1"))); 82 83 g.locale_cache_enabled(true); 84 g.generate(l_wt,"en_US.UTF-8"); 85 g.generate(l_wt,"en_US.ISO8859-1"); 86 TEST(std::has_facet<test_facet>(g("en_US.UTF-8"))); 87 TEST(std::has_facet<test_facet>(g("en_US.ISO8859-1"))); 88 TEST(std::use_facet<boost::locale::info>(g("en_US.UTF-8")).utf8()); 89 TEST(!std::use_facet<boost::locale::info>(g("en_US.ISO8859-1")).utf8()); 90 91 } 92 catch(std::exception const &e) { 93 std::cerr << "Failed " << e.what() << std::endl; 94 return EXIT_FAILURE; 95 } 96 FINALIZE(); 97 98 } 99 // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 100 // boostinspect:noascii 101