LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
domchildrenrangetest.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
10#include <QDomDocument>
11#include <QString>
12#include <QtTest>
13#include <domchildrenrange.h>
14
16
17namespace LC
18{
19namespace Util
20{
21 namespace
22 {
23 auto MakeDocument (const QString& str)
24 {
26 doc.setContent (str);
27 return doc.firstChildElement ("root");
28 }
29 }
30
31 void DomChildrenRangeTest::testEmpty ()
32 {
33 const auto& parent = MakeDocument (R"(
34 <root>
35 </root>
36 )");
37
39 for (const auto& elem : DomChildren (parent, "child"))
40 texts << elem.text ();
42 }
43
44 void DomChildrenRangeTest::testSingle ()
45 {
46 const auto& parent = MakeDocument (R"(
47 <root>
48 <child>foo</child>
49 </root>
50 )");
51
53 for (const auto& elem : DomChildren (parent, "child"))
54 texts << elem.text ();
55 QCOMPARE (texts, QStringList { "foo" });
56 }
57
58 void DomChildrenRangeTest::testMultiple ()
59 {
60 const auto& parent = MakeDocument (R"(
61 <root>
62 <child>foo</child>
63 <child>bar</child>
64 <child>baz</child>
65 </root>
66 )");
67
69 for (const auto& elem : DomChildren (parent, "child"))
70 texts << elem.text ();
71 QCOMPARE (texts, (QStringList { "foo", "bar", "baz" }));
72 }
73}
74}
Container< T > Filter(const Container< T > &c, F f)
Definition prelude.h:118
auto DomChildren(const QDomNode &parent, const QString &tag)
Creates a range iterating over direct children named tag.
Definition constants.h:15