Code

Super duper mega (fun!) commit: replaced encoding=utf-8 with fileencoding=utf-8 in...
[inkscape.git] / src / xml / quote-test.h
1 #include <cxxtest/TestSuite.h>
2 #include "streq.h"
4 /* Initial author: Peter Moulder.
5    Hereby released into the Public Domain. */
7 #include <cstring>
8 #include <functional>
10 /* mental disclaims all responsibility for this evil idea for testing
11    static functions.  The main disadvantages are that we retain any
12    #define's and `using' directives of the included file. */
13 #include "quote.cpp"
15 class XmlQuoteTest : public CxxTest::TestSuite
16 {
17 public:
19     XmlQuoteTest()
20     {
21     }
22     virtual ~XmlQuoteTest() {}
24 // createSuite and destroySuite get us per-suite setup and teardown
25 // without us having to worry about static initialization order, etc.
26     static XmlQuoteTest *createSuite() { return new XmlQuoteTest(); }
27     static void destroySuite( XmlQuoteTest *suite ) { delete suite; }
29     void testXmlQuotedStrlen()
30     {
31         struct {
32             char const *s;
33             size_t len;
34         } cases[] = {
35             {"", 0},
36             {"x", 1},
37             {"Foo", 3},
38             {"\"", 6},
39             {"&", 5},
40             {"<", 4},
41             {">", 4},
42             {"a\"b", 8},
43             {"a\"b<c>d;!@#$%^*(\\)?", 30}
44         };
45         for(size_t i=0; i<G_N_ELEMENTS(cases); i++) {
46             TS_ASSERT_EQUALS( xml_quoted_strlen(cases[i].s) , cases[i].len );
47         }
48     }
50     void testXmlQuoteStrdup()
51     {
52         struct {
53             char const * s1;
54             char const * s2;
55         } cases[] = {
56             {"", ""},
57             {"x", "x"},
58             {"Foo", "Foo"},
59             {"\"", "&quot;"},
60             {"&", "&amp;"},
61             {"<", "&lt;"},
62             {">", "&gt;"},
63             {"a\"b<c>d;!@#$%^*(\\)?", "a&quot;b&lt;c&gt;d;!@#$%^*(\\)?"}
64         };
65         for(size_t i=0; i<G_N_ELEMENTS(cases); i++) {
66             char* str = xml_quote_strdup(cases[i].s1);
67             TS_ASSERT_RELATION( streq_rel, cases[i].s2, str );
68             g_free(str);
69         }
70     }
71 };
73 /*
74   Local Variables:
75   mode:c++
76   c-file-style:"stroustrup"
77   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
78   indent-tabs-mode:nil
79   fill-column:99
80   End:
81 */
82 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :