libi2ncommon: (reinhard) disabled old to_lower/to_upper funcs and imported new ones...
[libi2ncommon] / test / stringfunc.cpp
CommitLineData
118e216e
TJ
1/***************************************************************************
2 * Copyright (C) 2006 by Intra2net AG *
3 * info@intra2net.com *
4 * *
5 ***************************************************************************/
6
7// #include <iostream>
8#include <string>
9// #include <sstream>
10// #include <stdexcept>
11
12#include <cppunit/extensions/TestFactoryRegistry.h>
13#include <cppunit/ui/text/TestRunner.h>
14#include <cppunit/extensions/HelperMacros.h>
15
16#include <stringfunc.hxx>
17
18using namespace std;
19using namespace CppUnit;
20
21class stringfunc : public TestFixture
22{
23 CPPUNIT_TEST_SUITE(stringfunc);
24
25 CPPUNIT_TEST(smart_html_entites1);
26 CPPUNIT_TEST(smart_html_entites2);
27 CPPUNIT_TEST(smart_html_entites3);
28 CPPUNIT_TEST(smart_html_entites4);
29 CPPUNIT_TEST(smart_html_entites5);
30 CPPUNIT_TEST(smart_html_entites6);
31 CPPUNIT_TEST(smart_html_entites7);
32 CPPUNIT_TEST(strip_html_tags1);
33 CPPUNIT_TEST(strip_html_tags2);
a5f3af6e
GE
34 CPPUNIT_TEST(html_entities1);
35 CPPUNIT_TEST(html_entities2);
36 CPPUNIT_TEST(html_entities3);
6a2b6dd1
TJ
37 CPPUNIT_TEST(imaputf7_to_utf8);
38 CPPUNIT_TEST(utf8_to_imaputf7);
118e216e
TJ
39
40 CPPUNIT_TEST_SUITE_END();
41
42 public:
43 void smart_html_entites1()
44 {
45 string output = smart_html_entities("Test");
46
47 CPPUNIT_ASSERT_EQUAL(string("Test"), output);
48 }
49
50 void smart_html_entites2()
51 {
52 string output = smart_html_entities("Täst");
53
54 CPPUNIT_ASSERT_EQUAL(string("T&auml;st"), output);
55 }
56
57 void smart_html_entites3()
58 {
59 string output = smart_html_entities("<>");
60
61 CPPUNIT_ASSERT_EQUAL(string("<>"), output);
62 }
63
64 void smart_html_entites4()
65 {
66 string output = smart_html_entities("<ümlaut>");
67
68 CPPUNIT_ASSERT_EQUAL(string("<ümlaut>"), output);
69 }
70
71 void smart_html_entites5()
72 {
73 string output = smart_html_entities("Test<ümlaut>Blä");
74
75 CPPUNIT_ASSERT_EQUAL(string("Test<ümlaut>Bl&auml;"), output);
76 }
77
78 void smart_html_entites6()
79 {
80 string output = smart_html_entities("System > Einstellungen");
81
82 CPPUNIT_ASSERT_EQUAL(string("System &gt; Einstellungen"), output);
83 }
84
85 void smart_html_entites7()
86 {
87 string output = smart_html_entities("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">\"System > Einstellungen\"</a>. Oder etwa nicht?");
88
89 CPPUNIT_ASSERT_EQUAL(string("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">&quot;System &gt; Einstellungen&quot;</a>. Oder etwa nicht?"), output);
90 }
91
92 void strip_html_tags1()
93 {
94 string output = strip_html_tags("Was für ein schöner Tag, finden Sie nicht?");
95
96 CPPUNIT_ASSERT_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
97 }
98
99 void strip_html_tags2()
100 {
101 string output = strip_html_tags("Was für ein <a href=\"wikipedia\" target=\"new\">schöner Tag</a>, finden Sie nicht?");
102
103 CPPUNIT_ASSERT_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
104 }
a5f3af6e
GE
105
106 void html_entities1()
107 {
108 string output = html_entities("\xC3\xA4\xC3\xB6\xC3\xBC");
109 CPPUNIT_ASSERT_EQUAL(string("&auml;&ouml;&uuml;"), output);
110 }
111
112 void html_entities2()
113 {
114 string output = html_entities("\xC3\xA5 \xC3\xB5 \xC3\xBF");
115 CPPUNIT_ASSERT_EQUAL(string("&#229; &#245; &#255;"), output);
116 }
117
118 void html_entities3()
119 {
120 string output = html_entities("\xC4\x8E \xE0\xBC\xB1 \xE8\x82\x88");
121 CPPUNIT_ASSERT_EQUAL(string("&#270; &#3889; &#32904;"), output);
122 }
6a2b6dd1
TJ
123
124 void imaputf7_to_utf8()
125 {
126 string output = utf7imap_to_utf8("Sp&AOQ-m");
127 CPPUNIT_ASSERT_EQUAL(string("Späm"), output);
128 }
129
130 void utf8_to_imaputf7()
131 {
132 string output = utf8_to_utf7imap("Späm");
133 CPPUNIT_ASSERT_EQUAL(string("Sp&AOQ-m"), output);
134 }
118e216e
TJ
135};
136
137CPPUNIT_TEST_SUITE_REGISTRATION(stringfunc);