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);
37 CPPUNIT_TEST(imaputf7_to_utf8);
38 CPPUNIT_TEST(utf8_to_imaputf7);
40 CPPUNIT_TEST_SUITE_END();
43 void smart_html_entites1()
45 string output = smart_html_entities("Test");
47 CPPUNIT_ASSERT_EQUAL(string("Test"), output);
50 void smart_html_entites2()
52 string output = smart_html_entities("Täst");
54 CPPUNIT_ASSERT_EQUAL(string("Täst"), output);
57 void smart_html_entites3()
59 string output = smart_html_entities("<>");
61 CPPUNIT_ASSERT_EQUAL(string("<>"), output);
64 void smart_html_entites4()
66 string output = smart_html_entities("<ümlaut>");
68 CPPUNIT_ASSERT_EQUAL(string("<ümlaut>"), output);
71 void smart_html_entites5()
73 string output = smart_html_entities("Test<ümlaut>Blä");
75 CPPUNIT_ASSERT_EQUAL(string("Test<ümlaut>Blä"), output);
78 void smart_html_entites6()
80 string output = smart_html_entities("System > Einstellungen");
82 CPPUNIT_ASSERT_EQUAL(string("System > Einstellungen"), output);
85 void smart_html_entites7()
87 string output = smart_html_entities("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">\"System > Einstellungen\"</a>. Oder etwa nicht?");
89 CPPUNIT_ASSERT_EQUAL(string("Finden Sie <b>auf</b> der Seite <a href=\"fdslfsl\">"System > Einstellungen"</a>. Oder etwa nicht?"), output);
92 void strip_html_tags1()
94 string output = strip_html_tags("Was für ein schöner Tag, finden Sie nicht?");
96 CPPUNIT_ASSERT_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
99 void strip_html_tags2()
101 string output = strip_html_tags("Was für ein <a href=\"wikipedia\" target=\"new\">schöner Tag</a>, finden Sie nicht?");
103 CPPUNIT_ASSERT_EQUAL(string("Was für ein schöner Tag, finden Sie nicht?"), output);
106 void html_entities1()
108 string output = html_entities("\xC3\xA4\xC3\xB6\xC3\xBC");
109 CPPUNIT_ASSERT_EQUAL(string("äöü"), output);
112 void html_entities2()
114 string output = html_entities("\xC3\xA5 \xC3\xB5 \xC3\xBF");
115 CPPUNIT_ASSERT_EQUAL(string("å õ ÿ"), output);
118 void html_entities3()
120 string output = html_entities("\xC4\x8E \xE0\xBC\xB1 \xE8\x82\x88");
121 CPPUNIT_ASSERT_EQUAL(string("Ď ༱ 肈"), output);
124 void imaputf7_to_utf8()
126 string output = utf7imap_to_utf8("Sp&AOQ-m");
127 CPPUNIT_ASSERT_EQUAL(string("Späm"), output);
130 void utf8_to_imaputf7()
132 string output = utf8_to_utf7imap("Späm");
133 CPPUNIT_ASSERT_EQUAL(string("Sp&AOQ-m"), output);
137 CPPUNIT_TEST_SUITE_REGISTRATION(stringfunc);