Code

fix combo enum, to handle enums of all types (not only the ones that range from 0...
[inkscape.git] / src / xml / quote-test.cpp
1 /* Initial author: Peter Moulder.
2    Hereby released into the Public Domain. */
4 #include <cstring>
5 #include <functional>
7 #include "utest/test-1ary-cases.h"
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)
16     {
17         bool const ret = (strcmp(exp, got) == 0);
18         g_free(got);
19         return ret;
20     }
21 };
23 static bool
24 test_xml_quoted_strlen()
25 {
26     utest_start("xml_quoted_strlen");
27     struct Case1<char const *, size_t> cases[] = {
28         {"", 0},
29         {"x", 1},
30         {"Foo", 3},
31         {"\"", 6},
32         {"&", 5},
33         {"<", 4},
34         {">", 4},
35         {"a\"b", 8},
36         {"a\"b<c>d;!@#$%^*(\\)?", 30}
37     };
38     test_1ary_cases<size_t, char const *, size_t, std::equal_to<size_t> >("xml_quoted_strlen",
39                                                                           xml_quoted_strlen,
40                                                                           G_N_ELEMENTS(cases),
41                                                                           cases);
42     return utest_end();
43 }
45 static bool
46 test_xml_quote_strdup()
47 {
48     utest_start("xml_quote_strdup");
49     struct Case1<char const *, char const *> cases[] = {
50         {"", ""},
51         {"x", "x"},
52         {"Foo", "Foo"},
53         {"\"", "&quot;"},
54         {"&", "&amp;"},
55         {"<", "&lt;"},
56         {">", "&gt;"},
57         {"a\"b<c>d;!@#$%^*(\\)?", "a&quot;b&lt;c&gt;d;!@#$%^*(\\)?"}
58     };
59     test_1ary_cases<char *, char const *, char const *, streq_free2>("xml_quote_strdup",
60                                                                      xml_quote_strdup,
61                                                                      G_N_ELEMENTS(cases),
62                                                                      cases);
63     return utest_end();
64 }
66 int main() {
67     bool const succ = (test_xml_quoted_strlen()
68                        && test_xml_quote_strdup());
69     return ( succ
70              ? EXIT_SUCCESS
71              : EXIT_FAILURE );
72 }
75 /*
76   Local Variables:
77   mode:c++
78   c-file-style:"stroustrup"
79   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
80   indent-tabs-mode:nil
81   fill-column:99
82   End:
83 */
84 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :