ChipMaster's trial hacks on C++CMS starting with v1.2.1. Not sure I'll follow on with the v2 since it looks to be breaking and mostly frivolous.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

134 lines
3.9 KiB

  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. #include <iostream>
  9. #include <iomanip>
  10. #include <stdlib.h>
  11. #include <locale.h>
  12. #include <locale>
  13. #include <time.h>
  14. #include <booster/backtrace.h>
  15. #include <booster/locale.h>
  16. #ifdef BOOSTER_LOCALE_WITH_ICU
  17. #include <unicode/uversion.h>
  18. #endif
  19. #include "test_locale_tools.h"
  20. char const *env(char const *s)
  21. {
  22. char const *r=getenv(s);
  23. if(r)
  24. return r;
  25. return "";
  26. }
  27. void check_locale(char const **names)
  28. {
  29. std::cout << " " << std::setw(32) << "locale" << std::setw(4) << "C" << std::setw(4) << "C++" << std::endl;
  30. while(*names) {
  31. char const *name = *names;
  32. std::cout << " " << std::setw(32) << name << std::setw(4);
  33. if(setlocale(LC_ALL,name)!=0)
  34. std::cout << "Yes";
  35. else
  36. std::cout << "No";
  37. std::cout << std::setw(4);
  38. try {
  39. std::locale l(name);
  40. std::cout << "Yes";
  41. }
  42. catch(std::exception const &) {
  43. std::cout << "No";
  44. }
  45. std::cout << std::endl;
  46. names++;
  47. }
  48. }
  49. int main()
  50. {
  51. std::cout << "- Backends: ";
  52. #ifdef BOOSTER_LOCALE_WITH_ICU
  53. std::cout << "icu:" << U_ICU_VERSION << " ";
  54. #endif
  55. #ifndef BOOSTER_LOCALE_NO_STD_BACKEND
  56. std::cout << "std ";
  57. #endif
  58. #ifndef BOOSTER_LOCALE_NO_POSIX_BACKEND
  59. std::cout << "posix ";
  60. #endif
  61. #ifndef BOOSTER_LOCALE_NO_WINAPI_BACKEND
  62. std::cout << "winapi";
  63. #endif
  64. std::cout << std::endl;
  65. #ifdef BOOSTER_LOCALE_WITH_ICONV
  66. std::cout << "- With iconv" << std::endl;
  67. #else
  68. std::cout << "- Without iconv" << std::endl;
  69. #endif
  70. std::cout << "- Environment " << std::endl;
  71. std::cout << " LANG="<< env("LANG") << std::endl;
  72. std::cout << " LC_ALL="<< env("LC_ALL") << std::endl;
  73. std::cout << " LC_CTYPE="<< env("LC_CTYPE") << std::endl;
  74. std::cout << " TZ="<< env("TZ") << std::endl;
  75. char const *clocale=setlocale(LC_ALL,"");
  76. if(!clocale)
  77. clocale= "undetected";
  78. std::cout <<"- C locale: " << clocale << std::endl;
  79. try {
  80. std::locale loc("");
  81. std::cout << "- C++ locale: " << loc.name() << std::endl;
  82. }
  83. catch(std::exception const &) {
  84. std::cout << "- C++ locale: is not supported" << std::endl;
  85. }
  86. char const *locales_to_check[] = {
  87. "en_US.UTF-8", "en_US.ISO8859-1", "English_United States.1252",
  88. "he_IL.UTF-8", "he_IL.ISO8859-8", "Hebrew_Israel.1255",
  89. "ru_RU.UTF-8", "Russian_Russia.1251",
  90. "tr_TR.UTF-8", "Turkish_Turkey.1254",
  91. "ja_JP.UTF-8", "ja_JP.SJIS", "Japanese_Japan.932",
  92. 0
  93. };
  94. std::cout << "- Testing locales availability on the operation system:" << std::endl;
  95. check_locale(locales_to_check);
  96. std::cout << "--- Testing Japanese_Japan.932 is working: " << test_std_supports_SJIS_codecvt("Japanese_Japan.932") << std::endl;
  97. std::cout << "- Testing timezone and time " << std::endl;
  98. {
  99. setlocale(LC_ALL,"C");
  100. time_t now = time(0);
  101. char buf[1024];
  102. strftime(buf,sizeof(buf),"%%c=%c; %%Z=%Z; %%z=%z",localtime(&now));
  103. std::cout << " Local Time :" << buf << std::endl;
  104. strftime(buf,sizeof(buf),"%%c=%c; %%Z=%Z; %%z=%z",gmtime(&now));
  105. std::cout << " Universal Time:" << buf << std::endl;
  106. }
  107. std::cout << "- Boost.Locale's locale: ";
  108. try {
  109. booster::locale::generator gen;
  110. std::locale l = gen("");
  111. std::cout << std::use_facet<booster::locale::info>(l).name() << std::endl;
  112. }
  113. catch(std::exception const &) {
  114. std::cout << " undetected" << std::endl;
  115. return EXIT_FAILURE;
  116. }
  117. return EXIT_SUCCESS;
  118. }
  119. // vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4
  120. // boostinspect:noascii