some UTF8 tests
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14771 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -90,7 +90,7 @@
|
|||||||
#undef TEST_ALL
|
#undef TEST_ALL
|
||||||
static const bool TEST_ALL = TRUE;
|
static const bool TEST_ALL = TRUE;
|
||||||
#else
|
#else
|
||||||
#define TEST_ARRAYS
|
#define TEST_WCHAR
|
||||||
|
|
||||||
static const bool TEST_ALL = FALSE;
|
static const bool TEST_ALL = FALSE;
|
||||||
#endif
|
#endif
|
||||||
@@ -3309,10 +3309,6 @@ static void TestVCardWrite()
|
|||||||
#include "wx/encconv.h"
|
#include "wx/encconv.h"
|
||||||
#include "wx/buffer.h"
|
#include "wx/buffer.h"
|
||||||
|
|
||||||
static void TestUtf8()
|
|
||||||
{
|
|
||||||
puts("*** Testing UTF8 support ***\n");
|
|
||||||
|
|
||||||
static const char textInUtf8[] =
|
static const char textInUtf8[] =
|
||||||
{
|
{
|
||||||
208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
|
208, 157, 208, 181, 209, 129, 208, 186, 208, 176, 208, 183, 208, 176,
|
||||||
@@ -3324,6 +3320,10 @@ static void TestUtf8()
|
|||||||
178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
|
178, 208, 190, 209, 129, 209, 130, 209, 140, 209, 142, 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static void TestUtf8()
|
||||||
|
{
|
||||||
|
puts("*** Testing UTF8 support ***\n");
|
||||||
|
|
||||||
char buf[1024];
|
char buf[1024];
|
||||||
wchar_t wbuf[1024];
|
wchar_t wbuf[1024];
|
||||||
if ( wxConvUTF8.MB2WC(wbuf, textInUtf8, WXSIZEOF(textInUtf8)) <= 0 )
|
if ( wxConvUTF8.MB2WC(wbuf, textInUtf8, WXSIZEOF(textInUtf8)) <= 0 )
|
||||||
@@ -3332,24 +3332,51 @@ static void TestUtf8()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// using wxEncodingConverter
|
|
||||||
#if 0
|
|
||||||
wxEncodingConverter ec;
|
|
||||||
ec.Init(wxFONTENCODING_UNICODE, wxFONTENCODING_KOI8);
|
|
||||||
ec.Convert(wbuf, buf);
|
|
||||||
#else // using wxCSConv
|
|
||||||
wxCSConv conv(_T("koi8-r"));
|
wxCSConv conv(_T("koi8-r"));
|
||||||
if ( conv.WC2MB(buf, wbuf, 0 /* not needed wcslen(wbuf) */) <= 0 )
|
if ( conv.WC2MB(buf, wbuf, 0 /* not needed wcslen(wbuf) */) <= 0 )
|
||||||
{
|
{
|
||||||
puts("ERROR: conversion to KOI8-R failed.");
|
puts("ERROR: conversion to KOI8-R failed.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
{
|
||||||
|
printf("The resulting string (in KOI8-R): %s\n", buf);
|
||||||
printf("The resulting string (in koi8-r): %s\n", buf);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( wxConvUTF8.WC2MB(buf, L"<EFBFBD> la", WXSIZEOF(buf)) <= 0 )
|
||||||
|
{
|
||||||
|
puts("ERROR: conversion to UTF-8 failed.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("The string in UTF-8: %s\n", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
puts("");
|
||||||
|
}
|
||||||
|
|
||||||
|
static void TestEncodingConverter()
|
||||||
|
{
|
||||||
|
wxPuts(_T("*** Testing wxEncodingConverter ***\n"));
|
||||||
|
|
||||||
|
// using wxEncodingConverter should give the same result as above
|
||||||
|
char buf[1024];
|
||||||
|
wchar_t wbuf[1024];
|
||||||
|
if ( wxConvUTF8.MB2WC(wbuf, textInUtf8, WXSIZEOF(textInUtf8)) <= 0 )
|
||||||
|
{
|
||||||
|
puts("ERROR: UTF-8 decoding failed.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxEncodingConverter ec;
|
||||||
|
ec.Init(wxFONTENCODING_UNICODE, wxFONTENCODING_KOI8);
|
||||||
|
ec.Convert(wbuf, buf);
|
||||||
|
printf("The same string obtained using wxEC: %s\n", buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
puts("");
|
||||||
|
}
|
||||||
|
|
||||||
#endif // TEST_WCHAR
|
#endif // TEST_WCHAR
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -5805,6 +5832,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
#ifdef TEST_WCHAR
|
#ifdef TEST_WCHAR
|
||||||
TestUtf8();
|
TestUtf8();
|
||||||
|
TestEncodingConverter();
|
||||||
#endif // TEST_WCHAR
|
#endif // TEST_WCHAR
|
||||||
|
|
||||||
#ifdef TEST_ZIP
|
#ifdef TEST_ZIP
|
||||||
|
Reference in New Issue
Block a user