1//
2// TextEncodingTest.cpp
3//
4// Copyright (c) 2004-2006, Applied Informatics Software Engineering GmbH.
5// and Contributors.
6//
7// SPDX-License-Identifier: BSL-1.0
8//
9
10
11#include "TextEncodingTest.h"
12#include "Poco/CppUnit/TestCaller.h"
13#include "Poco/CppUnit/TestSuite.h"
14#include "Poco/TextEncoding.h"
15#include "Poco/Latin1Encoding.h"
16#include "Poco/Latin2Encoding.h"
17#include "Poco/Latin9Encoding.h"
18#include "Poco/Windows1250Encoding.h"
19#include "Poco/Windows1251Encoding.h"
20#include "Poco/Windows1252Encoding.h"
21#include "Poco/UTF8Encoding.h"
22
23
24using namespace Poco;
25
26
27TextEncodingTest::TextEncodingTest(const std::string& rName): CppUnit::TestCase(rName)
28{
29}
30
31
32TextEncodingTest::~TextEncodingTest()
33{
34}
35
36
37void TextEncodingTest::testTextEncoding()
38{
39 TextEncoding& ascii = TextEncoding::byName("ASCII");
40 assertTrue (std::string("US-ASCII") == ascii.canonicalName());
41
42 TextEncoding& utf8 = TextEncoding::byName("utf8");
43 assertTrue (std::string("UTF-8") == utf8.canonicalName());
44
45 TextEncoding& latin1 = TextEncoding::byName("latin1");
46 assertTrue (std::string("ISO-8859-1") == latin1.canonicalName());
47
48 TextEncoding& latin2 = TextEncoding::byName("latin2");
49 assertTrue (std::string("ISO-8859-2") == latin2.canonicalName());
50
51 TextEncoding& latin9 = TextEncoding::byName("latin9");
52 assertTrue (std::string("ISO-8859-15") == latin9.canonicalName());
53
54 TextEncoding& cp1250 = TextEncoding::byName("CP1250");
55 assertTrue (std::string("windows-1250") == cp1250.canonicalName());
56
57 TextEncoding& cp1251 = TextEncoding::byName("CP1251");
58 assertTrue (std::string("windows-1251") == cp1251.canonicalName());
59
60 TextEncoding& cp1252 = TextEncoding::byName("CP1252");
61 assertTrue (std::string("windows-1252") == cp1252.canonicalName());
62
63
64 TextEncoding& glob = TextEncoding::global();
65 assertTrue (std::string("UTF-8") == glob.canonicalName());
66
67 TextEncoding::global(new Latin1Encoding);
68 TextEncoding& glob2 = TextEncoding::global();
69 assertTrue (std::string("ISO-8859-1") == glob2.canonicalName());
70
71 TextEncoding::global(new Latin2Encoding);
72 TextEncoding& glob3 = TextEncoding::global();
73 assertTrue (std::string("ISO-8859-2") == glob3.canonicalName());
74
75 TextEncoding::global(new Latin9Encoding);
76 TextEncoding& glob4 = TextEncoding::global();
77 assertTrue (std::string("ISO-8859-15") == glob4.canonicalName());
78
79 TextEncoding::global(new Windows1250Encoding);
80 TextEncoding& glob5 = TextEncoding::global();
81 assertTrue (std::string("windows-1250") == glob5.canonicalName());
82
83 TextEncoding::global(new Windows1251Encoding);
84 TextEncoding& glob6 = TextEncoding::global();
85 assertTrue (std::string("windows-1251") == glob6.canonicalName());
86
87 TextEncoding::global(new Windows1252Encoding);
88 TextEncoding& glob7 = TextEncoding::global();
89 assertTrue (std::string("windows-1252") == glob7.canonicalName());
90
91 TextEncoding::global(new UTF8Encoding);
92 TextEncoding& glob8 = TextEncoding::global();
93 assertTrue (std::string("UTF-8") == glob8.canonicalName());
94}
95
96
97void TextEncodingTest::testTextEncodingManager()
98{
99 TextEncodingRegistry registry;
100
101 assertTrue (registry.has("us-ascii"));
102 assertTrue (registry.has("US-ASCII"));
103 assertTrue (registry.has("ascii"));
104 assertTrue (registry.has("ASCII"));
105
106 assertTrue (registry.has("utf-8"));
107 assertTrue (registry.has("UTF-8"));
108
109 assertTrue (registry.has("utf-16"));
110 assertTrue (registry.has("UTF-16"));
111
112 assertTrue (registry.has("utf-32"));
113 assertTrue (registry.has("UTF-32"));
114
115 assertTrue (registry.has("iso-8859-1"));
116 assertTrue (registry.has("ISO-8859-1"));
117
118 assertTrue (registry.has("iso-8859-2"));
119 assertTrue (registry.has("ISO-8859-2"));
120
121 assertTrue (registry.has("iso-8859-15"));
122 assertTrue (registry.has("ISO-8859-15"));
123
124 assertTrue (registry.has("windows-1250"));
125 assertTrue (registry.has("WINDOWS-1250"));
126
127 assertTrue (registry.has("windows-1251"));
128 assertTrue (registry.has("WINDOWS-1251"));
129
130 assertTrue (registry.has("windows-1252"));
131 assertTrue (registry.has("WINDOWS-1252"));
132}
133
134
135void TextEncodingTest::setUp()
136{
137}
138
139
140void TextEncodingTest::tearDown()
141{
142}
143
144
145CppUnit::Test* TextEncodingTest::suite()
146{
147 CppUnit::TestSuite* pSuite = new CppUnit::TestSuite("TextEncodingTest");
148
149 CppUnit_addTest(pSuite, TextEncodingTest, testTextEncoding);
150 CppUnit_addTest(pSuite, TextEncodingTest, testTextEncodingManager);
151
152 return pSuite;
153}
154