Browse Source

Added test workaround for 932 codepage issue under MS Windows MSVC

master
Artyom Beilis 6 years ago
parent
commit
3bf725666b
3 changed files with 39 additions and 0 deletions
  1. +5
    -0
      booster/lib/locale/test/test_codepage.cpp
  2. +3
    -0
      booster/lib/locale/test/test_config.cpp
  3. +31
    -0
      booster/lib/locale/test/test_locale_tools.h

+ 5
- 0
booster/lib/locale/test/test_codepage.cpp View File

@@ -413,6 +413,11 @@ int main()
en_us_8bit = get_std_name("en_US.ISO8859-1");
he_il_8bit = get_std_name("he_IL.ISO8859-8");
ja_jp_shiftjis = get_std_name("ja_JP.SJIS");
if(!test_std_supports_SJIS_codecvt(ja_jp_shiftjis))
{
std::cout << "Warning: detected unproper support of " << ja_jp_shiftjis << " locale, disableling it" << std::endl;
ja_jp_shiftjis = "";
}
}
else {
en_us_8bit = "en_US.ISO8859-1";


+ 3
- 0
booster/lib/locale/test/test_config.cpp View File

@@ -19,6 +19,8 @@
#include <unicode/uversion.h>
#endif

#include "test_locale_tools.h"


char const *env(char const *s)
{
@@ -101,6 +103,7 @@ int main()
};
std::cout << "- Testing locales availability on the operation system:" << std::endl;
check_locale(locales_to_check);
std::cout << "--- Testing Japanese_Japan.932 is working: " << test_std_supports_SJIS_codecvt("Japanese_Japan.932") << std::endl;

std::cout << "- Testing timezone and time " << std::endl;
{


+ 31
- 0
booster/lib/locale/test/test_locale_tools.h View File

@@ -11,6 +11,9 @@

#include <booster/locale/encoding.h>

#include <fstream>
#include <stdlib.h>

template<typename Char>
std::basic_string<Char> to_correct_string(std::string const &e,std::locale /*l*/)
{
@@ -35,6 +38,34 @@ bool has_std_locale(std::string const &name)
}
}

inline bool test_std_supports_SJIS_codecvt(std::string const &locale_name)
{
bool res = true;
{
// Japan in Shift JIS/cp932
char const *japan_932 = "\x93\xfa\x96\x7b";
std::ofstream f("test-siftjis.txt");
f<<japan_932;
f.close();
}
try {
std::wfstream test;
test.imbue(std::locale(locale_name.c_str()));
test.open("test-siftjis.txt");
// Japan in Unicode
std::wstring cmp = L"\u65e5\u672c";
std::wstring ref;
test >> ref;
res = ref == cmp;
}
catch(std::exception const &)
{
res = false;
}
remove("test-siftjis.txt");
return res;
}

std::string get_std_name(std::string const &name,std::string *real_name = 0)
{
if(has_std_locale(name)) {


Loading…
Cancel
Save