LeechCraft  0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
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 
9 #include "domchildrenrangetest.h"
10 #include <QDomDocument>
11 #include <QString>
12 #include <QtTest>
13 #include <domchildrenrange.h>
14 
16 
17 namespace LC
18 {
19 namespace Util
20 {
21  namespace
22  {
23  auto MakeDocument (const QString& str)
24  {
25  QDomDocument doc;
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 
38  QStringList texts;
39  for (const auto& elem : DomChildren (parent, "child"))
40  texts << elem.text ();
41  QCOMPARE (texts, QStringList {});
42  }
43 
44  void DomChildrenRangeTest::testSingle ()
45  {
46  const auto& parent = MakeDocument (R"(
47  <root>
48  <child>foo</child>
49  </root>
50  )");
51 
52  QStringList texts;
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 
68  QStringList texts;
69  for (const auto& elem : DomChildren (parent, "child"))
70  texts << elem.text ();
71  QCOMPARE (texts, (QStringList { "foo", "bar", "baz" }));
72  }
73 }
74 }
LC::Util::DomChildrenRangeTest
Definition: domchildrenrangetest.h:29
LC::Util::DomChildren
auto DomChildren(const QDomNode &parent, const QString &tag)
Creates a range iterating over direct children named tag.
Definition: domchildrenrange.h:96
LC
Definition: constants.h:14
domchildrenrange.h
domchildrenrangetest.h