test_std_convert.cpp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. #ifdef BOOST_LOCALE_NO_STD_BACKEND
  9. #include <iostream>
  10. int main()
  11. {
  12. std::cout << "STD Backend is not build... Skipping" << std::endl;
  13. }
  14. #else
  15. #include <boost/locale/conversion.hpp>
  16. #include <boost/locale/localization_backend.hpp>
  17. #include <boost/locale/generator.hpp>
  18. #include <boost/locale/info.hpp>
  19. #include <iomanip>
  20. #include "test_locale.hpp"
  21. #include "test_locale_tools.hpp"
  22. #include <iostream>
  23. template<typename CharType>
  24. void test_one(std::locale const &l,std::string src,std::string tgtl,std::string tgtu)
  25. {
  26. TEST(boost::locale::to_upper(to_correct_string<CharType>(src,l),l) == to_correct_string<CharType>(tgtu,l));
  27. TEST(boost::locale::to_lower(to_correct_string<CharType>(src,l),l) == to_correct_string<CharType>(tgtl,l));
  28. TEST(boost::locale::fold_case(to_correct_string<CharType>(src,l),l) == to_correct_string<CharType>(tgtl,l));
  29. }
  30. template<typename CharType>
  31. void test_char()
  32. {
  33. boost::locale::generator gen;
  34. std::cout << "- Testing at least C" << std::endl;
  35. std::locale l = gen("en_US.UTF-8");
  36. test_one<CharType>(l,"Hello World i","hello world i","HELLO WORLD I");
  37. std::string name;
  38. name = get_std_name("en_US.UTF-8");
  39. if(!name.empty()) {
  40. std::cout << "- Testing " << name << std::endl;
  41. std::locale l=gen(name);
  42. test_one<CharType>(l,"Façade","façade","FAÇADE");
  43. }
  44. else {
  45. std::cout << "- en_US.UTF-8 is not supported, skipping" << std::endl;
  46. }
  47. name = get_std_name("en_US.ISO8859-1");
  48. if(!name.empty()) {
  49. std::cout << "Testing " << name << std::endl;
  50. std::locale l=gen(name);
  51. test_one<CharType>(l,"Hello World","hello world","HELLO WORLD");
  52. test_one<CharType>(l,"Façade","façade","FAÇADE");
  53. }
  54. else {
  55. std::cout << "- en_US.ISO8859-1 is not supported, skipping" << std::endl;
  56. }
  57. std::string real_name;
  58. name = get_std_name("tr_TR.UTF-8",&real_name);
  59. if(!name.empty()) {
  60. std::cout << "Testing " << name << std::endl;
  61. if(std::use_facet<std::ctype<wchar_t> >(std::locale(real_name.c_str())).toupper(L'i')!=L'I') {
  62. std::locale l=gen(name);
  63. test_one<CharType>(l,"i","i","İ");
  64. }
  65. else {
  66. std::cout << "Standard library does not support this locale's case conversion correctly" << std::endl;
  67. }
  68. }
  69. else
  70. {
  71. std::cout << "- tr_TR.UTF-8 is not supported, skipping" << std::endl;
  72. }
  73. }
  74. int main()
  75. {
  76. try {
  77. boost::locale::localization_backend_manager mgr = boost::locale::localization_backend_manager::global();
  78. mgr.select("std");
  79. boost::locale::localization_backend_manager::global(mgr);
  80. std::cout << "Testing char" << std::endl;
  81. test_char<char>();
  82. std::cout << "Testing wchar_t" << std::endl;
  83. test_char<wchar_t>();
  84. #ifdef BOOST_LOCALE_ENABLE_CHAR16_T
  85. std::cout << "Testing char16_t" << std::endl;
  86. test_char<char16_t>();
  87. #endif
  88. #ifdef BOOST_LOCALE_ENABLE_CHAR32_T
  89. std::cout << "Testing char32_t" << std::endl;
  90. test_char<char32_t>();
  91. #endif
  92. }
  93. catch(std::exception const &e) {
  94. std::cerr << "Failed " << e.what() << std::endl;
  95. return EXIT_FAILURE;
  96. }
  97. FINALIZE();
  98. }
  99. #endif // no std
  100. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
  101. // boostinspect:noascii