mirror of
https://github.com/pocoproject/poco.git
synced 2025-10-28 11:31:53 +01:00
added basic tests for Latin2, Latin9, Windows-1250, Windows-1251, Windows-1252
This commit is contained in:
@@ -36,13 +36,15 @@
|
||||
#include "Poco/TextConverter.h"
|
||||
#include "Poco/ASCIIEncoding.h"
|
||||
#include "Poco/Latin1Encoding.h"
|
||||
#include "Poco/Latin2Encoding.h"
|
||||
#include "Poco/Latin9Encoding.h"
|
||||
#include "Poco/Windows1250Encoding.h"
|
||||
#include "Poco/Windows1251Encoding.h"
|
||||
#include "Poco/Windows1252Encoding.h"
|
||||
#include "Poco/UTF8Encoding.h"
|
||||
|
||||
|
||||
using Poco::TextConverter;
|
||||
using Poco::Latin1Encoding;
|
||||
using Poco::UTF8Encoding;
|
||||
using Poco::ASCIIEncoding;
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
TextConverterTest::TextConverterTest(const std::string& name): CppUnit::TestCase(name)
|
||||
@@ -193,14 +195,144 @@ void TextConverterTest::testLatin1toUTF8()
|
||||
int errors = converter.convert(latin1Text, result0);
|
||||
assert (result0 == utf8Text);
|
||||
assert (errors == 0);
|
||||
assertEqual (result0.size(), 7);
|
||||
|
||||
std::string result1;
|
||||
errors = converter.convert(latin1Chars, 6, result1);
|
||||
assert (result0 == utf8Text);
|
||||
assert (result1 == utf8Text);
|
||||
assert (errors == 0);
|
||||
}
|
||||
|
||||
|
||||
void TextConverterTest::testLatin2toUTF8()
|
||||
{
|
||||
Latin2Encoding latinEncoding;
|
||||
UTF8Encoding utf8Encoding;
|
||||
TextConverter converter(latinEncoding, utf8Encoding);
|
||||
|
||||
const unsigned char latinChars[26] = { 0xb5, 0xb9, 0xe8, 0xbb, 0xbe, 0xfd, 0xe1, 0xed, 0xe9, 0xfa, 0xe4, 0xf4,
|
||||
0x20, 0xa5, 0xa9, 0xc8, 0xab, 0xae, 0xdd, 0xc1, 0xcd, 0xc9, 0xda, 0xc4, 0xd4, 0x00 };
|
||||
const unsigned char utf8Chars[] = "ľščťžýáíéúäô ĽŠČŤŽÝÁÍÉÚÄÔ";
|
||||
std::string latinText((const char*) latinChars);
|
||||
std::string utf8Text((const char*) utf8Chars);
|
||||
|
||||
std::string result0;
|
||||
int errors = converter.convert(latinText, result0);
|
||||
assertEqual (result0, utf8Text);
|
||||
assertEqual (errors, 0);
|
||||
assertEqual (result0.size(), 49);
|
||||
|
||||
std::string result1;
|
||||
errors = converter.convert(latinChars, 25, result1);
|
||||
assertEqual (result1, utf8Text);
|
||||
assertEqual (errors, 0);
|
||||
assertEqual (result1.size(), 49);
|
||||
}
|
||||
|
||||
|
||||
void TextConverterTest::testLatin9toUTF8()
|
||||
{
|
||||
Latin9Encoding latinEncoding;
|
||||
UTF8Encoding utf8Encoding;
|
||||
TextConverter converter(latinEncoding, utf8Encoding);
|
||||
|
||||
const unsigned char latinChars[26] = { 0x3f, 0xa8, 0x3f, 0x3f, 0xb8, 0xfd, 0xe1, 0xed, 0xe9, 0xfa, 0xe4, 0xf4,
|
||||
0x20, 0x3f, 0xa6, 0x3f, 0x3f, 0xb4, 0xdd, 0xc1, 0xcd, 0xc9, 0xda, 0xc4, 0xd4, 0x00 };
|
||||
const unsigned char utf8Chars[] = "?š??žýáíéúäô ?Š??ŽÝÁÍÉÚÄÔ";
|
||||
std::string latinText((const char*) latinChars);
|
||||
std::string utf8Text((const char*) utf8Chars);
|
||||
|
||||
std::string result0;
|
||||
int errors = converter.convert(latinText, result0);
|
||||
assertEqual (result0, utf8Text);
|
||||
assertEqual (errors, 0);
|
||||
assertEqual (result0.size(), 43);
|
||||
|
||||
std::string result1;
|
||||
errors = converter.convert(latinChars, 25, result1);
|
||||
assertEqual (result1, utf8Text);
|
||||
assertEqual (errors, 0);
|
||||
assertEqual (result1.size(), 43);
|
||||
}
|
||||
|
||||
|
||||
void TextConverterTest::testCP1250toUTF8()
|
||||
{
|
||||
Windows1250Encoding latinEncoding;
|
||||
UTF8Encoding utf8Encoding;
|
||||
TextConverter converter(latinEncoding, utf8Encoding);
|
||||
|
||||
const unsigned char latinChars[26] = { 0xbe, 0x9a, 0xe8, 0x9d, 0x9e, 0xfd, 0xe1, 0xed, 0xe9, 0xfa, 0xe4, 0xf4,
|
||||
0x20, 0xbc, 0x8a, 0xc8, 0x8d, 0x8e, 0xdd, 0xc1, 0xcd, 0xc9, 0xda, 0xc4, 0xd4, 0x00 };
|
||||
const unsigned char utf8Chars[] = "ľščťžýáíéúäô ĽŠČŤŽÝÁÍÉÚÄÔ";
|
||||
std::string latinText((const char*) latinChars);
|
||||
std::string utf8Text((const char*) utf8Chars);
|
||||
|
||||
std::string result0;
|
||||
int errors = converter.convert(latinText, result0);
|
||||
assertEqual (result0, utf8Text);
|
||||
assertEqual (errors, 0);
|
||||
assertEqual (result0.size(), 49);
|
||||
|
||||
std::string result1;
|
||||
errors = converter.convert(latinChars, 25, result1);
|
||||
assertEqual (result1, utf8Text);
|
||||
assertEqual (errors, 0);
|
||||
assertEqual (result1.size(), 49);
|
||||
}
|
||||
|
||||
|
||||
void TextConverterTest::testCP1251toUTF8()
|
||||
{
|
||||
Windows1251Encoding latinEncoding;
|
||||
UTF8Encoding utf8Encoding;
|
||||
TextConverter converter(latinEncoding, utf8Encoding);
|
||||
|
||||
const unsigned char latinChars[32] = { 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef, 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff, 0x00 };
|
||||
const unsigned char utf8Chars[] = "бвгдежзийклмнопрстуфхцчшщъыьэюя";
|
||||
std::string latinText((const char*) latinChars);
|
||||
std::string utf8Text((const char*) utf8Chars);
|
||||
|
||||
std::string result0;
|
||||
int errors = converter.convert(latinText, result0);
|
||||
assertEqual (result0, utf8Text);
|
||||
assertEqual (errors, 0);
|
||||
assertEqual (result0.size(), 62);
|
||||
|
||||
std::string result1;
|
||||
errors = converter.convert(latinChars, 31, result1);
|
||||
assertEqual (result1, utf8Text);
|
||||
assertEqual (errors, 0);
|
||||
assertEqual (result1.size(), 62);
|
||||
}
|
||||
|
||||
|
||||
void TextConverterTest::testCP1252toUTF8()
|
||||
{
|
||||
Windows1252Encoding latinEncoding;
|
||||
UTF8Encoding utf8Encoding;
|
||||
TextConverter converter(latinEncoding, utf8Encoding);
|
||||
|
||||
const unsigned char latinChars[26] = { 0x3f, 0x9a, 0x3f, 0x3f, 0x9e, 0xfd, 0xe1, 0xed, 0xe9, 0xfa, 0xe4, 0xf4,
|
||||
0x20, 0x3f, 0x8a, 0x3f, 0x3f, 0x8e, 0xdd, 0xc1, 0xcd, 0xc9, 0xda, 0xc4, 0xd4, 0x00 };
|
||||
const unsigned char utf8Chars[] = "?š??žýáíéúäô ?Š??ŽÝÁÍÉÚÄÔ";
|
||||
std::string latinText((const char*) latinChars);
|
||||
std::string utf8Text((const char*) utf8Chars);
|
||||
|
||||
std::string result0;
|
||||
int errors = converter.convert(latinText, result0);
|
||||
assertEqual (result0, utf8Text);
|
||||
assertEqual (errors, 0);
|
||||
assertEqual (result0.size(), 43);
|
||||
|
||||
std::string result1;
|
||||
errors = converter.convert(latinChars, 25, result1);
|
||||
assertEqual (result1, utf8Text);
|
||||
assertEqual (errors, 0);
|
||||
assertEqual (result1.size(), 43);
|
||||
}
|
||||
|
||||
|
||||
void TextConverterTest::testErrors()
|
||||
{
|
||||
UTF8Encoding utf8Encoding;
|
||||
@@ -234,6 +366,11 @@ CppUnit::Test* TextConverterTest::suite()
|
||||
CppUnit_addTest(pSuite, TextConverterTest, testIdentityUTF8);
|
||||
CppUnit_addTest(pSuite, TextConverterTest, testUTF8toASCII);
|
||||
CppUnit_addTest(pSuite, TextConverterTest, testLatin1toUTF8);
|
||||
CppUnit_addTest(pSuite, TextConverterTest, testLatin2toUTF8);
|
||||
CppUnit_addTest(pSuite, TextConverterTest, testLatin9toUTF8);
|
||||
CppUnit_addTest(pSuite, TextConverterTest, testCP1250toUTF8);
|
||||
CppUnit_addTest(pSuite, TextConverterTest, testCP1251toUTF8);
|
||||
CppUnit_addTest(pSuite, TextConverterTest, testCP1252toUTF8);
|
||||
CppUnit_addTest(pSuite, TextConverterTest, testErrors);
|
||||
|
||||
return pSuite;
|
||||
|
||||
Reference in New Issue
Block a user