1 /***************************************************************************
2 * Copyright (C) 2006 by Intra2net AG *
5 ***************************************************************************/
10 // #include <stdexcept>
12 #include <cppunit/extensions/TestFactoryRegistry.h>
13 #include <cppunit/ui/text/TestRunner.h>
14 #include <cppunit/extensions/HelperMacros.h>
16 #include <stringfunc.hxx>
19 using namespace CppUnit;
21 class stringfunc : public TestFixture
23 CPPUNIT_TEST_SUITE(stringfunc);
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);
38 CPPUNIT_TEST_SUITE_END();
41 void smart_html_entites1()
43 string output = smart_html_entities("Test");
45 CPPUNIT_ASSERT_EQUAL(string("Test"), output);
48 void smart_html_entites2()
50 string output = smart_html_entities("Täst");
52 CPPUNIT_ASSERT_EQUAL(string("Täst"), output);
55 void smart_html_entites3()
57 string output = smart_html_entities("<>");
59 CPPUNIT_ASSERT_EQUAL(string("<>"), output);
62 void smart_html_entites4()
64 string output = smart_html_entities("<ümlaut>");
66 CPPUNIT_ASSERT_EQUAL(string("<ümlaut>"), output);
69 void smart_html_entites5()
71 string output = smart_html_entities("Test<ümlaut>Blä");
73 CPPUNIT_ASSERT_EQUAL(string("Test<ümlaut>Blä"), output);
76 void smart_html_entites6()
78 string output = smart_html_entities("System > Einstellungen");
80 CPPUNIT_ASSERT_EQUAL(string("System > Einstellungen"), output);
83 void smart_html_entites7()
85 string output = smart_html_entities("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">\"System > Einstellungen\"</a>. Oder etwa nicht?");
87 CPPUNIT_ASSERT_EQUAL(string("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">"System > Einstellungen"</a>. Oder etwa nicht?"), output);
90 void strip_html_tags1()
92 string output = strip_html_tags("Was für ein schöner Tag, finden Sie nicht?");
94 CPPUNIT_ASSERT_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
97 void strip_html_tags2()
99 string output = strip_html_tags("Was für ein <a href=\"wikipedia\" target=\"new\">schöner Tag</a>, finden Sie nicht?");
101 CPPUNIT_ASSERT_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
104 void html_entities1()
106 string output = html_entities("\xC3\xA4\xC3\xB6\xC3\xBC");
107 CPPUNIT_ASSERT_EQUAL(string("äöü"), output);
110 void html_entities2()
112 string output = html_entities("\xC3\xA5 \xC3\xB5 \xC3\xBF");
113 CPPUNIT_ASSERT_EQUAL(string("å õ ÿ"), output);
116 void html_entities3()
118 string output = html_entities("\xC4\x8E \xE0\xBC\xB1 \xE8\x82\x88");
119 CPPUNIT_ASSERT_EQUAL(string("Ď ༱ 肈"), output);
123 CPPUNIT_TEST_SUITE_REGISTRATION(stringfunc);