xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
beast
beast_PropertyStream_test.cpp
1
#include <xrpl/beast/unit_test/suite.h>
2
#include <xrpl/beast/utility/PropertyStream.h>
3
4
#include <
string
>
5
6
namespace
beast
{
7
8
class
PropertyStream_test
:
public
unit_test::Suite
9
{
10
public
:
11
using
Source
=
PropertyStream::Source
;
12
13
void
14
testPeelName
(
std::string
s,
std::string
const
& expected,
std::string
const
& expectedRemainder)
15
{
16
try
17
{
18
std::string
const
peeledName =
Source::peelName
(&s);
19
BEAST_EXPECT(peeledName == expected);
20
BEAST_EXPECT(s == expectedRemainder);
21
}
22
catch
(...)
23
{
24
fail
(
"unhandled exception"
);
25
;
26
}
27
}
28
29
void
30
testPeelLeadingSlash
(
std::string
s,
std::string
const
& expected,
bool
shouldBeFound)
31
{
32
try
33
{
34
bool
const
found(
Source::peelLeadingSlash
(&s));
35
BEAST_EXPECT(found == shouldBeFound);
36
BEAST_EXPECT(s == expected);
37
}
38
catch
(...)
39
{
40
fail
(
"unhandled exception"
);
41
;
42
}
43
}
44
45
void
46
testPeelTrailingSlashstar
(
47
std::string
s,
48
std::string
const
& expectedRemainder,
49
bool
shouldBeFound)
50
{
51
try
52
{
53
bool
const
found(
Source::peelTrailingSlashstar
(&s));
54
BEAST_EXPECT(found == shouldBeFound);
55
BEAST_EXPECT(s == expectedRemainder);
56
}
57
catch
(...)
58
{
59
fail
(
"unhandled exception"
);
60
;
61
}
62
}
63
64
void
65
testFindOne
(
Source
& root,
Source
* expected,
std::string
const
& name)
66
{
67
try
68
{
69
Source
const
* source(root.findOne(name));
70
BEAST_EXPECT(source == expected);
71
}
72
catch
(...)
73
{
74
fail
(
"unhandled exception"
);
75
;
76
}
77
}
78
79
void
80
testFindPath
(
Source
& root,
std::string
const
& path,
Source
* expected)
81
{
82
try
83
{
84
Source
const
* source(root.findPath(path));
85
BEAST_EXPECT(source == expected);
86
}
87
catch
(...)
88
{
89
fail
(
"unhandled exception"
);
90
;
91
}
92
}
93
94
void
95
testFindOneDeep
(
Source
& root,
std::string
const
& name,
Source
* expected)
96
{
97
try
98
{
99
Source
const
* source(root.findOneDeep(name));
100
BEAST_EXPECT(source == expected);
101
}
102
catch
(...)
103
{
104
fail
(
"unhandled exception"
);
105
;
106
}
107
}
108
109
void
110
testFind
(
Source
& root,
std::string
path,
Source
* expected,
bool
expectedStar)
111
{
112
try
113
{
114
auto
const
result(root.find(path));
115
BEAST_EXPECT(result.first == expected);
116
BEAST_EXPECT(result.second == expectedStar);
117
}
118
catch
(...)
119
{
120
fail
(
"unhandled exception"
);
121
;
122
}
123
}
124
125
void
126
run
()
override
127
{
128
Source
a(
"a"
);
129
Source
b(
"b"
);
130
Source
c(
"c"
);
131
Source
d(
"d"
);
132
Source
e(
"e"
);
133
Source
f(
"f"
);
134
Source
g(
"g"
);
135
136
//
137
// a { b { d { f }, e }, c { g } }
138
//
139
140
a.
add
(b);
141
a.
add
(c);
142
c.
add
(g);
143
b.
add
(d);
144
b.
add
(e);
145
d.
add
(f);
146
147
testcase
(
"peel_name"
);
148
testPeelName
(
"a"
,
"a"
,
""
);
149
testPeelName
(
"foo/bar"
,
"foo"
,
"bar"
);
150
testPeelName
(
"foo/goo/bar"
,
"foo"
,
"goo/bar"
);
151
testPeelName
(
""
,
""
,
""
);
152
153
testcase
(
"peel_leading_slash"
);
154
testPeelLeadingSlash
(
"foo/"
,
"foo/"
,
false
);
155
testPeelLeadingSlash
(
"foo"
,
"foo"
,
false
);
156
testPeelLeadingSlash
(
"/foo/"
,
"foo/"
,
true
);
157
testPeelLeadingSlash
(
"/foo"
,
"foo"
,
true
);
158
159
testcase
(
"peel_trailing_slashstar"
);
160
testPeelTrailingSlashstar
(
"/foo/goo/*"
,
"/foo/goo"
,
true
);
161
testPeelTrailingSlashstar
(
"foo/goo/*"
,
"foo/goo"
,
true
);
162
testPeelTrailingSlashstar
(
"/foo/goo/"
,
"/foo/goo"
,
false
);
163
testPeelTrailingSlashstar
(
"foo/goo"
,
"foo/goo"
,
false
);
164
testPeelTrailingSlashstar
(
""
,
""
,
false
);
165
testPeelTrailingSlashstar
(
"/"
,
""
,
false
);
166
testPeelTrailingSlashstar
(
"/*"
,
""
,
true
);
167
testPeelTrailingSlashstar
(
"//"
,
"/"
,
false
);
168
testPeelTrailingSlashstar
(
"**"
,
"*"
,
true
);
169
testPeelTrailingSlashstar
(
"*/"
,
"*"
,
false
);
170
171
testcase
(
"find_one"
);
172
testFindOne
(a, &b,
"b"
);
173
testFindOne
(a,
nullptr
,
"d"
);
174
testFindOne
(b, &e,
"e"
);
175
testFindOne
(d, &f,
"f"
);
176
177
testcase
(
"find_path"
);
178
testFindPath
(a,
"a"
,
nullptr
);
179
testFindPath
(a,
"e"
,
nullptr
);
180
testFindPath
(a,
"a/b"
,
nullptr
);
181
testFindPath
(a,
"a/b/e"
,
nullptr
);
182
testFindPath
(a,
"b/e/g"
,
nullptr
);
183
testFindPath
(a,
"b/e/f"
,
nullptr
);
184
testFindPath
(a,
"b"
, &b);
185
testFindPath
(a,
"b/e"
, &e);
186
testFindPath
(a,
"b/d/f"
, &f);
187
188
testcase
(
"find_one_deep"
);
189
testFindOneDeep
(a,
"z"
,
nullptr
);
190
testFindOneDeep
(a,
"g"
, &g);
191
testFindOneDeep
(a,
"b"
, &b);
192
testFindOneDeep
(a,
"d"
, &d);
193
testFindOneDeep
(a,
"f"
, &f);
194
195
testcase
(
"find"
);
196
testFind
(a,
""
, &a,
false
);
197
testFind
(a,
"*"
, &a,
true
);
198
testFind
(a,
"/b"
, &b,
false
);
199
testFind
(a,
"b"
, &b,
false
);
200
testFind
(a,
"d"
, &d,
false
);
201
testFind
(a,
"/b*"
, &b,
true
);
202
testFind
(a,
"b*"
, &b,
true
);
203
testFind
(a,
"d*"
, &d,
true
);
204
testFind
(a,
"/b/*"
, &b,
true
);
205
testFind
(a,
"b/*"
, &b,
true
);
206
testFind
(a,
"d/*"
, &d,
true
);
207
testFind
(a,
"a"
,
nullptr
,
false
);
208
testFind
(a,
"/d"
,
nullptr
,
false
);
209
testFind
(a,
"/d*"
,
nullptr
,
true
);
210
testFind
(a,
"/d/*"
,
nullptr
,
true
);
211
}
212
};
213
214
BEAST_DEFINE_TESTSUITE
(
PropertyStream
,
beast
,
beast
);
215
}
// namespace beast
std::string
beast::PropertyStream::Source
Subclasses can be called to write to a stream and have children.
Definition
PropertyStream.h:315
beast::PropertyStream::Source::peelTrailingSlashstar
static bool peelTrailingSlashstar(std::string *path)
Definition
beast_PropertyStream.cpp:277
beast::PropertyStream::Source::peelName
static std::string peelName(std::string *path)
Definition
beast_PropertyStream.cpp:293
beast::PropertyStream::Source::add
void add(Source &source)
Add a child source.
Definition
beast_PropertyStream.cpp:174
beast::PropertyStream::Source::peelLeadingSlash
static bool peelLeadingSlash(std::string *path)
Definition
beast_PropertyStream.cpp:266
beast::PropertyStream_test
Definition
beast_PropertyStream_test.cpp:9
beast::PropertyStream_test::testFindOne
void testFindOne(Source &root, Source *expected, std::string const &name)
Definition
beast_PropertyStream_test.cpp:65
beast::PropertyStream_test::run
void run() override
Runs the suite.
Definition
beast_PropertyStream_test.cpp:126
beast::PropertyStream_test::testPeelName
void testPeelName(std::string s, std::string const &expected, std::string const &expectedRemainder)
Definition
beast_PropertyStream_test.cpp:14
beast::PropertyStream_test::testFindPath
void testFindPath(Source &root, std::string const &path, Source *expected)
Definition
beast_PropertyStream_test.cpp:80
beast::PropertyStream_test::testPeelLeadingSlash
void testPeelLeadingSlash(std::string s, std::string const &expected, bool shouldBeFound)
Definition
beast_PropertyStream_test.cpp:30
beast::PropertyStream_test::testFindOneDeep
void testFindOneDeep(Source &root, std::string const &name, Source *expected)
Definition
beast_PropertyStream_test.cpp:95
beast::PropertyStream_test::Source
PropertyStream::Source Source
Definition
beast_PropertyStream_test.cpp:11
beast::PropertyStream_test::testPeelTrailingSlashstar
void testPeelTrailingSlashstar(std::string s, std::string const &expectedRemainder, bool shouldBeFound)
Definition
beast_PropertyStream_test.cpp:46
beast::PropertyStream_test::testFind
void testFind(Source &root, std::string path, Source *expected, bool expectedStar)
Definition
beast_PropertyStream_test.cpp:110
beast::PropertyStream
Abstract stream with RAII containers that produce a property tree.
Definition
PropertyStream.h:19
beast::unit_test::Suite
A testsuite class.
Definition
suite.h:52
beast::unit_test::Suite::fail
void fail(String const &reason, char const *file, int line)
Record a failure.
Definition
suite.h:554
beast::unit_test::Suite::testcase
TestcaseT testcase
Memberspace for declaring test cases.
Definition
suite.h:155
beast
Definition
base_uint.h:697
beast::BEAST_DEFINE_TESTSUITE
BEAST_DEFINE_TESTSUITE(aged_set, beast, beast)
string
Generated by
1.17.0