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