Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
quote-test.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
/*
5 * Authors: see git history
6 * Initial author: Peter Moulder.
7 *
8 * Copyright (C) 2013 Authors
9 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
10 */
11#include <cxxtest/TestSuite.h>
12#include "streq.h"
13
14
15#include <cstring>
16#include <functional>
17
18#include "quote.h"
19
20class XmlQuoteTest : public CxxTest::TestSuite
21{
22public:
23
25 {
26 }
27 virtual ~XmlQuoteTest() {}
28
29// createSuite and destroySuite get us per-suite setup and teardown
30// without us having to worry about static initialization order, etc.
31 static XmlQuoteTest *createSuite() { return new XmlQuoteTest(); }
32 static void destroySuite( XmlQuoteTest *suite ) { delete suite; }
33
35 {
36 struct {
37 char const *s;
38 size_t len;
39 } cases[] = {
40 {"", 0},
41 {"x", 1},
42 {"Foo", 3},
43 {"\"", 6},
44 {"&", 5},
45 {"<", 4},
46 {">", 4},
47 {"a\"b", 8},
48 {"a\"b<c>d;!@#$%^*(\\)?", 30}
49 };
50 for(size_t i=0; i<G_N_ELEMENTS(cases); i++) {
51 TS_ASSERT_EQUALS( xml_quoted_strlen(cases[i].s) , cases[i].len );
52 }
53 }
54
56 {
57 struct {
58 char const * s1;
59 char const * s2;
60 } cases[] = {
61 {"", ""},
62 {"x", "x"},
63 {"Foo", "Foo"},
64 {"\"", "&quot;"},
65 {"&", "&amp;"},
66 {"<", "&lt;"},
67 {">", "&gt;"},
68 {"a\"b<c>d;!@#$%^*(\\)?", "a&quot;b&lt;c&gt;d;!@#$%^*(\\)?"}
69 };
70 for(size_t i=0; i<G_N_ELEMENTS(cases); i++) {
71 char* str = xml_quote_strdup(cases[i].s1);
72 TS_ASSERT_RELATION( streq_rel, cases[i].s2, str );
73 g_free(str);
74 }
75 }
76};
77
78/*
79 Local Variables:
80 mode:c++
81 c-file-style:"stroustrup"
82 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
83 indent-tabs-mode:nil
84 fill-column:99
85 End:
86*/
87// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
static XmlQuoteTest * createSuite()
Definition quote-test.h:31
virtual ~XmlQuoteTest()
Definition quote-test.h:27
static void destroySuite(XmlQuoteTest *suite)
Definition quote-test.h:32
void testXmlQuoteStrdup()
Definition quote-test.h:55
void testXmlQuotedStrlen()
Definition quote-test.h:34
char * xml_quote_strdup(char const *src)
Definition quote.cpp:43
size_t xml_quoted_strlen(char const *val)
Returns the length of the string after quoting the characters "&<>.
Definition quote.cpp:18
TODO: insert short description here.
auto len
Definition safe-printf.h:21
TODO: insert short description here.