mirror of
https://github.com/pocoproject/poco.git
synced 2025-02-21 14:42:51 +01:00
added basic tests for Latin2, Latin9, Windows-1250, Windows-1251, Windows-1252
This commit is contained in:
parent
11539da851
commit
fa49f5b850
@ -252,11 +252,11 @@ void CoreTest::testBuffer()
|
||||
Buffer<int> f = e;
|
||||
assert (f == e);
|
||||
|
||||
buffer<char> g;
|
||||
Buffer<char> g(0);
|
||||
g.append("hello", 5);
|
||||
assert (g.size() == 5);
|
||||
|
||||
g.append(g);
|
||||
g.append("hello", 5);
|
||||
assert (g.size() == 10);
|
||||
assert ( !memcmp(g.begin(), "hellohello", 10) );
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -50,6 +50,11 @@ public:
|
||||
void testIdentityUTF8();
|
||||
void testUTF8toASCII();
|
||||
void testLatin1toUTF8();
|
||||
void testLatin2toUTF8();
|
||||
void testLatin9toUTF8();
|
||||
void testCP1250toUTF8();
|
||||
void testCP1251toUTF8();
|
||||
void testCP1252toUTF8();
|
||||
void testErrors();
|
||||
|
||||
void setUp();
|
||||
|
@ -36,11 +36,13 @@
|
||||
#include "Poco/TextEncoding.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"
|
||||
|
||||
|
||||
using Poco::TextEncoding;
|
||||
using Poco::Latin1Encoding;
|
||||
using Poco::Latin2Encoding;
|
||||
using namespace Poco;
|
||||
|
||||
|
||||
TextEncodingTest::TextEncodingTest(const std::string& name): CppUnit::TestCase(name)
|
||||
@ -61,6 +63,22 @@ void TextEncodingTest::testTextEncoding()
|
||||
TextEncoding& latin1 = TextEncoding::byName("latin1");
|
||||
assert (std::string("ISO-8859-1") == latin1.canonicalName());
|
||||
|
||||
TextEncoding& latin2 = TextEncoding::byName("latin2");
|
||||
assert (std::string("ISO-8859-2") == latin2.canonicalName());
|
||||
|
||||
TextEncoding& latin9 = TextEncoding::byName("latin9");
|
||||
assert (std::string("ISO-8859-15") == latin9.canonicalName());
|
||||
|
||||
TextEncoding& cp1250 = TextEncoding::byName("CP1250");
|
||||
assert (std::string("Windows-1250") == cp1250.canonicalName());
|
||||
|
||||
TextEncoding& cp1251 = TextEncoding::byName("CP1251");
|
||||
assert (std::string("Windows-1251") == cp1251.canonicalName());
|
||||
|
||||
TextEncoding& cp1252 = TextEncoding::byName("CP1252");
|
||||
assert (std::string("Windows-1252") == cp1252.canonicalName());
|
||||
|
||||
|
||||
TextEncoding& glob = TextEncoding::global();
|
||||
assert (std::string("UTF-8") == glob.canonicalName());
|
||||
|
||||
@ -71,6 +89,22 @@ void TextEncodingTest::testTextEncoding()
|
||||
TextEncoding::global(new Latin2Encoding);
|
||||
TextEncoding& glob3 = TextEncoding::global();
|
||||
assert (std::string("ISO-8859-2") == glob3.canonicalName());
|
||||
|
||||
TextEncoding::global(new Latin9Encoding);
|
||||
TextEncoding& glob4 = TextEncoding::global();
|
||||
assert (std::string("ISO-8859-15") == glob4.canonicalName());
|
||||
|
||||
TextEncoding::global(new Windows1250Encoding);
|
||||
TextEncoding& glob5 = TextEncoding::global();
|
||||
assert (std::string("Windows-1250") == glob5.canonicalName());
|
||||
|
||||
TextEncoding::global(new Windows1251Encoding);
|
||||
TextEncoding& glob6 = TextEncoding::global();
|
||||
assert (std::string("Windows-1251") == glob6.canonicalName());
|
||||
|
||||
TextEncoding::global(new Windows1252Encoding);
|
||||
TextEncoding& glob7 = TextEncoding::global();
|
||||
assert (std::string("Windows-1252") == glob7.canonicalName());
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user