@@ -598,13 +598,14 @@ add_booster_param_test(locale message "${CMAKE_CURRENT_SOURCE_DIR}/lib/locale/te | |||
add_booster_test(locale ios_prop) | |||
add_booster_test(locale codepage_converter) | |||
add_booster_test(locale date_time) | |||
add_booster_test(locale generator) | |||
add_booster_test(locale config) | |||
if(NOT DISABLE_ICU_LOCALE) | |||
add_booster_test(locale collate) | |||
add_booster_test(locale convert) | |||
add_booster_test(locale boundary) | |||
add_booster_test(locale formatting) | |||
add_booster_test(locale generator) | |||
add_booster_test(locale icu_vs_os_timezone) | |||
if(CMAKE_COMPILER_IS_GNUCXX) | |||
set_target_properties(test_locale_formatting PROPERTIES COMPILE_FLAGS "-O0") | |||
@@ -0,0 +1,123 @@ | |||
// | |||
// Copyright (c) 2009-2011 Artyom Beilis (Tonkikh) | |||
// | |||
// Distributed under the Boost Software License, Version 1.0. (See | |||
// accompanying file LICENSE_1_0.txt or copy at | |||
// http://www.boost.org/LICENSE_1_0.txt) | |||
// | |||
#include <iostream> | |||
#include <iomanip> | |||
#include <stdlib.h> | |||
#include <locale.h> | |||
#include <locale> | |||
#include <time.h> | |||
#include <booster/backtrace.h> | |||
#include <booster/locale.h> | |||
#ifdef BOOSTER_LOCALE_WITH_ICU | |||
#include <unicode/uversion.h> | |||
#endif | |||
char const *env(char const *s) | |||
{ | |||
char const *r=getenv(s); | |||
if(r) | |||
return r; | |||
return ""; | |||
} | |||
void check_locale(char const **names) | |||
{ | |||
std::cout << " " << std::setw(32) << "locale" << std::setw(4) << "C" << std::setw(4) << "C++" << std::endl; | |||
while(*names) { | |||
char const *name = *names; | |||
std::cout << " " << std::setw(32) << name << std::setw(4); | |||
if(setlocale(LC_ALL,name)!=0) | |||
std::cout << "Yes"; | |||
else | |||
std::cout << "No"; | |||
std::cout << std::setw(4); | |||
try { | |||
std::locale l(name); | |||
std::cout << "Yes"; | |||
} | |||
catch(std::exception const &) { | |||
std::cout << "No"; | |||
} | |||
std::cout << std::endl; | |||
names++; | |||
} | |||
} | |||
int main() | |||
{ | |||
std::cout << "- Backends: "; | |||
#ifdef BOOSTER_LOCALE_WITH_ICU | |||
std::cout << "icu:" << U_ICU_VERSION << " "; | |||
#endif | |||
#ifndef BOOSTER_LOCALE_NO_STD_BACKEND | |||
std::cout << "std "; | |||
#endif | |||
#ifndef BOOSTER_LOCALE_NO_POSIX_BACKEND | |||
std::cout << "posix "; | |||
#endif | |||
#ifndef BOOSTER_LOCALE_NO_WINAPI_BACKEND | |||
std::cout << "winapi"; | |||
#endif | |||
std::cout << std::endl; | |||
#ifdef BOOSTER_LOCALE_WITH_ICONV | |||
std::cout << "- With iconv" << std::endl; | |||
#else | |||
std::cout << "- Without iconv" << std::endl; | |||
#endif | |||
std::cout << "- Environment " << std::endl; | |||
std::cout << " LANG="<< env("LANG") << std::endl; | |||
std::cout << " LC_ALL="<< env("LC_ALL") << std::endl; | |||
std::cout << " LC_CTYPE="<< env("LC_CTYPE") << std::endl; | |||
std::cout << " TZ="<< env("TZ") << std::endl; | |||
std::cout << "- Detected Boost locale: "; | |||
try { | |||
booster::locale::generator gen; | |||
std::locale l = gen(""); | |||
std::cout << std::use_facet<booster::locale::info>(l).name() << std::endl; | |||
} | |||
catch(std::exception const &) { | |||
std::cout << " undetected" << std::endl; | |||
} | |||
char const *clocale=setlocale(LC_ALL,""); | |||
if(!clocale) | |||
clocale= "undetected"; | |||
std::cout <<"- Detected C locale: " << clocale << std::endl; | |||
try { | |||
std::locale loc(""); | |||
std::cout << "- Detected C++ locale: " << loc.name() << std::endl; | |||
} | |||
catch(std::exception const &) { | |||
std::cout << "- Detected C++ locale: is not supported" << std::endl; | |||
} | |||
char const *locales_to_check[] = { | |||
"en_US.UTF-8", "en_US.ISO8859-1", "English_United States.1252", | |||
"he_IL.UTF-8", "he_IL.ISO8859-8", "Hebrew_Israel.1255", | |||
"ru_RU.UTF-8", "Russian_Russia.1251", | |||
"tr_TR.UTF-8", "Turkish_Turkey.1254", | |||
"ja_JP.UTF-8", "ja_JP.SJIS", "Japanese_Japan.932", | |||
0 | |||
}; | |||
std::cout << "- Testing locales availability on the operation system:" << std::endl; | |||
check_locale(locales_to_check); | |||
std::cout << "- Testing timezone and time " << std::endl; | |||
{ | |||
setlocale(LC_ALL,"C"); | |||
time_t now = time(0); | |||
char buf[1024]; | |||
strftime(buf,sizeof(buf),"%%c=%c; %%Z=%Z; %%z=%z",localtime(&now)); | |||
std::cout << " Local Time :" << buf << std::endl; | |||
strftime(buf,sizeof(buf),"%%c=%c; %%Z=%Z; %%z=%z",gmtime(&now)); | |||
std::cout << " Universal Time:" << buf << std::endl; | |||
} | |||
} | |||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 |
@@ -5,25 +5,17 @@ | |||
// accompanying file LICENSE_1_0.txt or copy at | |||
// http://www.boost.org/LICENSE_1_0.txt) | |||
// | |||
#ifndef BOOSTER_LOCALE_WITH_ICU | |||
#include <iostream> | |||
int main() | |||
{ | |||
std::cout << "ICU is not build... Skipping" << std::endl; | |||
} | |||
#else | |||
#include <booster/locale/generator.h> | |||
#include <booster/locale/info.h> | |||
#include <booster/locale/collator.h> | |||
#include <booster/locale/message.h> | |||
#include <iomanip> | |||
#include "test_locale.h" | |||
bool has_collator(std::locale const &l) | |||
bool has_message(std::locale const &l) | |||
{ | |||
return std::has_facet<std::collate<char> >(l) | |||
&& dynamic_cast<booster::locale::collator<char> const *>(&std::use_facet<std::collate<char> >(l)); | |||
return std::has_facet<booster::locale::message_format<char> >(l); | |||
} | |||
struct test_facet : public std::locale::facet { | |||
@@ -39,24 +31,24 @@ int main() | |||
try { | |||
booster::locale::generator g; | |||
std::locale l=g("en_US.UTF-8"); | |||
TEST(has_collator(l)); | |||
TEST(has_message(l)); | |||
g.categories(g.categories() ^ booster::locale::collation_facet); | |||
g.categories(g.categories() ^ booster::locale::message_facet); | |||
g.locale_cache_enabled(true); | |||
g("en_US.UTF-8"); | |||
g.categories(g.categories() | booster::locale::collation_facet); | |||
g.categories(g.categories() | booster::locale::message_facet); | |||
l=g("en_US.UTF-8"); | |||
TEST(!has_collator(l)); | |||
TEST(!has_message(l)); | |||
g.clear_cache(); | |||
g.locale_cache_enabled(false); | |||
l=g("en_US.UTF-8"); | |||
TEST(has_collator(l)); | |||
TEST(has_message(l)); | |||
g.characters(g.characters() ^ booster::locale::char_facet); | |||
l=g("en_US.UTF-8"); | |||
TEST(!has_collator(l)); | |||
TEST(!has_message(l)); | |||
g.characters(g.characters() | booster::locale::char_facet); | |||
l=g("en_US.UTF-8"); | |||
TEST(has_collator(l)); | |||
TEST(has_message(l)); | |||
l=g("en_US.ISO8859-1"); | |||
TEST(std::use_facet<booster::locale::info>(l).language()=="en"); | |||
@@ -104,5 +96,4 @@ int main() | |||
FINALIZE(); | |||
} | |||
#endif // NOICU | |||
// vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 |
@@ -25,6 +25,7 @@ find boost_locale -regextype posix-extended -regex '.*\.(cpp|h|ipp)' -exec sed - | |||
find boost_locale -regextype posix-extended -regex '.*\.(cpp|h|ipp)' -exec sed -i 's/.hpp>/.h>/' '{}' \; | |||
find boost_locale -regextype posix-extended -regex '.*\.(cpp|h|ipp)' -exec sed -i 's/.hpp"/.h"/' '{}' \; | |||
find boost_locale -regextype posix-extended -regex '.*\.(cpp|h|ipp)' -exec sed -i 's/booster\/locale\/config.h/booster\/config.h/' '{}' \; | |||
find boost_locale -regextype posix-extended -regex '.*\.(cpp|h|ipp)' -exec sed -i 's/booster\/thread\/mutex.h/booster\/thread.h/' '{}' \; | |||
find boost_locale -regextype posix-extended -regex '.*\.(cpp|h|ipp)' -exec sed -i 's/BOOSTER_LOCALE_DECL/BOOSTER_API/' '{}' \; | |||
find boost_locale -regextype posix-extended -regex '.*\.(cpp|h|ipp)' -exec sed -i 's/BOOSTER_LOCALE_SOURCE/BOOSTER_SOURCE/' '{}' \; | |||
find boost_locale -regextype posix-extended -regex '.*\.(cpp|h|ipp)' -exec sed -i 's/BOOSTER_WINDOWS/BOOSTER_WIN_NATIVE/' '{}' \; | |||