// // 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("C.UTF-8"); test_one(l, "Hello World i", "hello world i", "HELLO WORLD I"); std::string name = "en_US.UTF-8"; std::cout << "- Testing " << name << std::endl; l = gen(name); test_one(l, "Façade", "façade", "FAÇADE"); name = "tr_TR.UTF-8"; std::cout << "Testing " << name << std::endl; test_one(gen(name), "i", "i", "İ"); } template void test_normc(std::basic_string orig, std::basic_string normal, boost::locale::norm_type type) { std::locale l = boost::locale::generator().generate("en_US.UTF-8"); TEST_EQ(boost::locale::normalize(orig, type, l), normal); TEST_EQ(boost::locale::normalize(orig.c_str(), type, l), normal); TEST_EQ(boost::locale::normalize(orig.c_str(), orig.c_str() + orig.size(), type, l), normal); } void test_norm(std::string orig, std::string normal, boost::locale::norm_type type) { test_normc(orig, normal, type); test_normc(to(orig), to(normal), type); } void test_main(int /*argc*/, char** /*argv*/) { #ifdef BOOST_LOCALE_NO_WINAPI_BACKEND std::cout << "WinAPI Backend is not build... Skipping\n"; return; #endif boost::locale::localization_backend_manager mgr = boost::locale::localization_backend_manager::global(); mgr.select("winapi"); boost::locale::localization_backend_manager::global(mgr); std::cout << "Testing char" << std::endl; test_char(); std::cout << "Testing wchar_t" << std::endl; test_char(); std::cout << "Testing Unicode normalization" << std::endl; test_norm("\xEF\xAC\x81", "\xEF\xAC\x81", boost::locale::norm_nfd); /// ligature fi test_norm("\xEF\xAC\x81", "\xEF\xAC\x81", boost::locale::norm_nfc); test_norm("\xEF\xAC\x81", "fi", boost::locale::norm_nfkd); test_norm("\xEF\xAC\x81", "fi", boost::locale::norm_nfkc); test_norm("ä", "ä", boost::locale::norm_nfd); // ä to a and accent test_norm("ä", "ä", boost::locale::norm_nfc); } // boostinspect:noascii