libi2ncommon: (tomj) smart HTML entities engine
[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
35     CPPUNIT_TEST_SUITE_END();
36
37     public:
38         void smart_html_entites1()
39         {
40             string output = smart_html_entities("Test");
41
42             CPPUNIT_ASSERT_EQUAL(string("Test"), output);
43         }
44
45         void smart_html_entites2()
46         {
47             string output = smart_html_entities("Täst");
48
49             CPPUNIT_ASSERT_EQUAL(string("T&auml;st"), output);
50         }
51
52         void smart_html_entites3()
53         {
54             string output = smart_html_entities("<>");
55
56             CPPUNIT_ASSERT_EQUAL(string("<>"), output);
57         }
58
59         void smart_html_entites4()
60         {
61             string output = smart_html_entities("<ümlaut>");
62
63             CPPUNIT_ASSERT_EQUAL(string("<ümlaut>"), output);
64         }
65
66         void smart_html_entites5()
67         {
68             string output = smart_html_entities("Test<ümlaut>Blä");
69
70             CPPUNIT_ASSERT_EQUAL(string("Test<ümlaut>Bl&auml;"), output);
71         }
72
73         void smart_html_entites6()
74         {
75             string output = smart_html_entities("System > Einstellungen");
76
77             CPPUNIT_ASSERT_EQUAL(string("System &gt; Einstellungen"), output);
78         }
79
80         void smart_html_entites7()
81         {
82             string output = smart_html_entities("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">\"System > Einstellungen\"</a>. Oder etwa nicht?");
83
84             CPPUNIT_ASSERT_EQUAL(string("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">&quot;System &gt; Einstellungen&quot;</a>. Oder etwa nicht?"), output);
85         }
86
87         void strip_html_tags1()
88         {
89             string output = strip_html_tags("Was für ein schöner Tag, finden Sie nicht?");
90
91             CPPUNIT_ASSERT_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
92         }
93
94         void strip_html_tags2()
95         {
96             string output = strip_html_tags("Was für ein <a href=\"wikipedia\" target=\"new\">schöner Tag</a>, finden Sie nicht?");
97
98             CPPUNIT_ASSERT_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
99         }
100 };
101
102 CPPUNIT_TEST_SUITE_REGISTRATION(stringfunc);