Code

added fix from Dale Harvey to expand incomplete JIDs specified in user
[inkscape.git] / src / xml / quote-test.cpp
1 /* Initial author: Peter Moulder.
2    Hereby released into the Public Domain. */
4 #include <functional>
5 #include "utest/test-1ary-cases.h"
7 /* mental disclaims all responsibility for this evil idea for testing
8    static functions.  The main disadvantages are that we retain any
9    #define's and `using' directives of the included file. */
10 #include "quote.cpp"
12 struct streq_free2 {
13     bool operator()(char const *exp, char *got)
14     {
15         bool const ret = (strcmp(exp, got) == 0);
16         g_free(got);
17         return ret;
18     }
19 };
21 static bool
22 test_xml_quoted_strlen()
23 {
24     utest_start("xml_quoted_strlen");
25     struct Case1<char const *, size_t> cases[] = {
26         {"", 0},
27         {"x", 1},
28         {"Foo", 3},
29         {"\"", 6},
30         {"&", 5},
31         {"<", 4},
32         {">", 4},
33         {"a\"b", 8},
34         {"a\"b<c>d;!@#$%^*(\\)?", 30}
35     };
36     test_1ary_cases<size_t, char const *, size_t, std::equal_to<size_t> >("xml_quoted_strlen",
37                                                                           xml_quoted_strlen,
38                                                                           G_N_ELEMENTS(cases),
39                                                                           cases);
40     return utest_end();
41 }
43 static bool
44 test_xml_quote_strdup()
45 {
46     utest_start("xml_quote_strdup");
47     struct Case1<char const *, char const *> cases[] = {
48         {"", ""},
49         {"x", "x"},
50         {"Foo", "Foo"},
51         {"\"", "&quot;"},
52         {"&", "&amp;"},
53         {"<", "&lt;"},
54         {">", "&gt;"},
55         {"a\"b<c>d;!@#$%^*(\\)?", "a&quot;b&lt;c&gt;d;!@#$%^*(\\)?"}
56     };
57     test_1ary_cases<char *, char const *, char const *, streq_free2>("xml_quote_strdup",
58                                                                      xml_quote_strdup,
59                                                                      G_N_ELEMENTS(cases),
60                                                                      cases);
61     return utest_end();
62 }
64 int main() {
65     bool const succ = (test_xml_quoted_strlen()
66                        && test_xml_quote_strdup());
67     return ( succ
68              ? EXIT_SUCCESS
69              : EXIT_FAILURE );
70 }
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:encoding=utf-8:textwidth=99 :