From c853ffb5b2f75f5a889ed2e3ef89b818a736e87a Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 13:50:49 +0200 Subject: Adding upstream version 1.3+ds. Signed-off-by: Daniel Baumann --- testfiles/src/xml-test.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 testfiles/src/xml-test.cpp (limited to 'testfiles/src/xml-test.cpp') diff --git a/testfiles/src/xml-test.cpp b/testfiles/src/xml-test.cpp new file mode 100644 index 0000000..dee272d --- /dev/null +++ b/testfiles/src/xml-test.cpp @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/** + * @file + * Test xml node + */ +/* + * Authors: + * Ted Gould + * + * Copyright (C) 2020 Authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include "gtest/gtest.h" +#include "xml/repr.h" + +TEST(XmlTest, nodeiter) +{ + auto testdoc = std::shared_ptr(sp_repr_read_buf("", SP_SVG_NS_URI)); + ASSERT_TRUE(testdoc); + + auto count = 0; + for (auto &child : *testdoc->root()) { + ASSERT_STREQ(child.name(), "svg:g"); + count++; + } + ASSERT_EQ(count, 1); + + testdoc = + std::shared_ptr(sp_repr_read_buf("", SP_SVG_NS_URI)); + ASSERT_TRUE(testdoc); + + count = 0; + for (auto &child : *testdoc->root()) { + ASSERT_STREQ(child.name(), "svg:g"); + count++; + } + ASSERT_EQ(count, 3); + + testdoc = std::shared_ptr(sp_repr_read_buf(R"""( + + + + + + + + + + + + +)""", SP_SVG_NS_URI)); + ASSERT_TRUE(testdoc); + + auto path = std::list{"svg:g", "svg:path"}; + auto found = testdoc->root()->findChildPath(path); + ASSERT_NE(found, nullptr); + ASSERT_STREQ(found->attribute("id"), "b"); + + // no such second element + path = {"svg:g", "svg:g"}; + ASSERT_EQ(testdoc->root()->findChildPath(path), nullptr); + + // no such first element + path = {"svg:symbol", "svg:path"}; + ASSERT_EQ(testdoc->root()->findChildPath(path), nullptr); + + // root with no children + testdoc = std::shared_ptr(sp_repr_read_buf("", SP_SVG_NS_URI)); + ASSERT_EQ(testdoc->root()->findChildPath(path), nullptr); +} + +/* + 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 : -- cgit v1.2.3