// // Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) // // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #include #include #include #include #include "boostLocale/test/tools.hpp" #include "boostLocale/test/unit_test.hpp" #include #include template void test_one(const std::locale& l, std::string src, std::string tgtl, std::string tgtu) { TEST_EQ(boost::locale::to_upper(to_correct_string(src, l), l), to_correct_string(tgtu, l)); TEST_EQ(boost::locale::to_lower(to_correct_string(src, l), l), to_correct_string(tgtl, l)); TEST_EQ(boost::locale::fold_case(to_correct_string(src, l), l), to_correct_string(tgtl, l)); } template void test_char() { boost::locale::generator gen; std::cout << "- Testing at least C" << std::endl; std::locale l = gen("en_US.UTF-8"); test_one(l, "Hello World i", "hello world i", "HELLO WORLD I"); std::string name; name = get_std_name("en_US.UTF-8"); if(!name.empty()) { std::cout << "- Testing " << name << std::endl; l = gen(name); test_one(l, "Façade", "façade", "FAÇADE"); } else { std::cout << "- en_US.UTF-8 is not supported, skipping" << std::endl; } name = get_std_name("en_US.ISO8859-1"); if(!name.empty()) { std::cout << "Testing " << name << std::endl; l = gen(name); test_one(l, "Hello World", "hello world", "HELLO WORLD"); test_one(l, "Façade", "façade", "FAÇADE"); } else { std::cout << "- en_US.ISO8859-1 is not supported, skipping" << std::endl; } std::string real_name; name = get_std_name("tr_TR.UTF-8", &real_name); if(!name.empty()) { std::cout << "Testing " << name << std::endl; if(std::use_facet>(std::locale(real_name.c_str())).toupper(L'i') != L'I') { l = gen(name); test_one(l, "i", "i", "İ"); } else { std::cout << "Standard library does not support this locale's case conversion correctly" << std::endl; } } else { std::cout << "- tr_TR.UTF-8 is not supported, skipping" << std::endl; } } void test_main(int /*argc*/, char** /*argv*/) { #ifdef BOOST_LOCALE_NO_STD_BACKEND std::cout << "STD Backend is not build... Skipping\n"; return; #endif boost::locale::localization_backend_manager mgr = boost::locale::localization_backend_manager::global(); mgr.select("std"); boost::locale::localization_backend_manager::global(mgr); std::cout << "Testing char" << std::endl; test_char(); std::cout << "Testing wchar_t" << std::endl; test_char(); #ifdef BOOST_LOCALE_ENABLE_CHAR16_T std::cout << "Testing char16_t" << std::endl; test_char(); #endif #ifdef BOOST_LOCALE_ENABLE_CHAR32_T std::cout << "Testing char32_t" << std::endl; test_char(); #endif } // boostinspect:noascii