libi2ncommon: (gerd) html encoding for all unicode chars
[libi2ncommon] / test / stringfunc.cpp
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
18 using namespace std;
19 using namespace CppUnit;
20
21 class 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);
34     CPPUNIT_TEST(html_entities1);
35     CPPUNIT_TEST(html_entities2);
36     CPPUNIT_TEST(html_entities3);
37
38     CPPUNIT_TEST_SUITE_END();
39
40     public:
41         void smart_html_entites1()
42         {
43             string output = smart_html_entities("Test");
44
45             CPPUNIT_ASSERT_EQUAL(string("Test"), output);
46         }
47
48         void smart_html_entites2()
49         {
50             string output = smart_html_entities("Täst");
51
52             CPPUNIT_ASSERT_EQUAL(string("T&auml;st"), output);
53         }
54
55         void smart_html_entites3()
56         {
57             string output = smart_html_entities("<>");
58
59             CPPUNIT_ASSERT_EQUAL(string("<>"), output);
60         }
61
62         void smart_html_entites4()
63         {
64             string output = smart_html_entities("<ümlaut>");
65
66             CPPUNIT_ASSERT_EQUAL(string("<ümlaut>"), output);
67         }
68
69         void smart_html_entites5()
70         {
71             string output = smart_html_entities("Test<ümlaut>Blä");
72
73             CPPUNIT_ASSERT_EQUAL(string("Test<ümlaut>Bl&auml;"), output);
74         }
75
76         void smart_html_entites6()
77         {
78             string output = smart_html_entities("System > Einstellungen");
79
80             CPPUNIT_ASSERT_EQUAL(string("System &gt; Einstellungen"), output);
81         }
82
83         void smart_html_entites7()
84         {
85             string output = smart_html_entities("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">\"System > Einstellungen\"</a>. Oder etwa nicht?");
86
87             CPPUNIT_ASSERT_EQUAL(string("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">&quot;System &gt; Einstellungen&quot;</a>. Oder etwa nicht?"), output);
88         }
89
90         void strip_html_tags1()
91         {
92             string output = strip_html_tags("Was für ein schöner Tag, finden Sie nicht?");
93
94             CPPUNIT_ASSERT_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
95         }
96
97         void strip_html_tags2()
98         {
99             string output = strip_html_tags("Was für ein <a href=\"wikipedia\" target=\"new\">schöner Tag</a>, finden Sie nicht?");
100
101             CPPUNIT_ASSERT_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
102         }
103
104         void html_entities1()
105         {
106             string output = html_entities("\xC3\xA4\xC3\xB6\xC3\xBC");
107             CPPUNIT_ASSERT_EQUAL(string("&auml;&ouml;&uuml;"), output);
108         }
109
110         void html_entities2()
111         {
112             string output = html_entities("\xC3\xA5 \xC3\xB5 \xC3\xBF");
113             CPPUNIT_ASSERT_EQUAL(string("&#229; &#245; &#255;"), output);
114         }
115
116         void html_entities3()
117         {
118             string output = html_entities("\xC4\x8E \xE0\xBC\xB1 \xE8\x82\x88");
119             CPPUNIT_ASSERT_EQUAL(string("&#270; &#3889; &#32904;"), output);
120         }
121 };
122
123 CPPUNIT_TEST_SUITE_REGISTRATION(stringfunc);