12 void write(std::span<const char> buf) {
13 ss.write(buf.data(), buf.size());
18 void check(
bool condition)
const {
20 throw std::logic_error(
"assertion failed");
24 std::stringstream& ss;
34 CHECK(ss.str().empty());
36 SECTION(
"2 nested tags, inner tag empty") {
41 CHECK(ss.str() ==
"<abc>\n <def/>\n</abc>\n");
43 SECTION(
"2 nested tags, inner tag with data") {
49 CHECK(ss.str() ==
"<abc>\n <def>foobar</def>\n</abc>\n");
51 SECTION(
"2 nested tags, inner tag with attribute, no data") {
57 CHECK(ss.str() ==
"<abc>\n <def foo=\"bar\"/>\n</abc>\n");
59 SECTION(
"2 nested tags, inner tag with attribute and data") {
66 CHECK(ss.str() ==
"<abc>\n <def foo=\"bar\">qux</def>\n</abc>\n");
76 xml.
begin(
"settings");
77 xml.
begin(
"settings");
83 xml.
begin(
"bindings");
86 xml.
data(
"cycle \"videosource\"");
91 std::string expected =
94 " <setting id=\"noise\">3.0</setting>\n"
97 " <bind key=\"keyb F6\">cycle "videosource"</bind>\n"
100 CHECK(ss.str() == expected);
105 std::stringstream ss;
109 SECTION(
"more end than begin") {
112 CHECK_THROWS(xml.
end(
"bla"));
114 SECTION(
"attribute after data") {
117 CHECK_THROWS(xml.
attribute(
"foo",
"bar"));
120 SECTION(
"attribute after end") {
124 CHECK_THROWS(xml.
attribute(
"foo",
"bar"));
127 SECTION(
"begin after data") {
130 CHECK_THROWS(xml.
begin(
"bla"));
134 SECTION(
"data after end") {
138 CHECK_THROWS(xml.
data(
"qux"));
141 SECTION(
"data after data") {
145 CHECK_THROWS(xml.
data(
"qux"));
150 SECTION(
"non-matching begin/end") {
155 CHECK_THROWS(xml.
end(
"err"));
TEST_CASE("XMLOutputStream: simple")
void check(bool condition) const
void write(std::span< const char > buf)
TestWriter(std::stringstream &ss_)
'XMLOutputStream' is a helper to write an XML file in a streaming way.
void attribute(std::string_view name, std::string_view value)
void begin(std::string_view tag)
void end(std::string_view tag)
void data(std::string_view value)