Code

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