1 // SPDX-License-Identifier: GPL-2.0-or-later
10 * Copyright (C) 2020 Authors
12 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
18 #include <gtest/gtest.h>
21 TEST(XmlTest
, nodeiter
)
23 auto testdoc
= std::shared_ptr
<Inkscape::XML::Document
>(sp_repr_read_buf("<svg><g/></svg>", SP_SVG_NS_URI
));
27 for (auto &child
: *testdoc
->root()) {
28 ASSERT_STREQ(child
.name(), "svg:g");
34 std::shared_ptr
<Inkscape::XML::Document
>(sp_repr_read_buf("<svg><g/><g/><g><g/></g></svg>", SP_SVG_NS_URI
));
38 for (auto &child
: *testdoc
->root()) {
39 ASSERT_STREQ(child
.name(), "svg:g");
44 testdoc
= std::shared_ptr
<Inkscape::XML::Document
>(sp_repr_read_buf(R
"""(
57 )""", SP_SVG_NS_URI
));
60 auto path
= std::list
<std::string
>{"svg:g", "svg:path"};
61 auto found
= testdoc
->root()->findChildPath(path
);
62 ASSERT_NE(found
, nullptr);
63 ASSERT_STREQ(found
->attribute("id"), "b");
65 // no such second element
66 path
= {"svg:g", "svg:g"};
67 ASSERT_EQ(testdoc
->root()->findChildPath(path
), nullptr);
69 // no such first element
70 path
= {"svg:symbol", "svg:path"};
71 ASSERT_EQ(testdoc
->root()->findChildPath(path
), nullptr);
73 // root with no children
74 testdoc
= std::shared_ptr
<Inkscape::XML::Document
>(sp_repr_read_buf("<svg/>", SP_SVG_NS_URI
));
75 ASSERT_EQ(testdoc
->root()->findChildPath(path
), nullptr);
78 TEST(XmlQuoteTest
, nodeiter
)
80 auto testdoc
= std::shared_ptr
<Inkscape::XML::Document
>(sp_repr_read_buf("<svg attr='<foo bar\n"amp&>'>\nTEXT\n NODE\n<g><![CDATA[TEST CDATA]]></g></svg>", SP_SVG_NS_URI
));
81 ASSERT_STREQ(testdoc
->root()->attribute("attr"), "<foo\nbar \"amp&>");
83 for (auto &child
: *testdoc
->root()) {
84 ASSERT_STREQ(child
.content(), "\nTEXT\n\nNODE\n");
88 auto content
= sp_repr_save_buf(testdoc
.get());
89 ASSERT_STREQ(content
.c_str(), R
"""(<?xml version="1.0" encoding="UTF
-8" standalone="no
"?>
91 attr="<
;foo
bar "amp&>"
92 xmlns:svg="http://www.w3.org/2000/svg">
96 <svg
:g
><![CDATA
[TEST
CDATA]]></svg:g>
104 c-file-style:"stroustrup
"
105 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
110 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :