]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // (c) Copyright Juergen Hunold 2012 |
2 | // Use, modification and distribution is subject to the Boost Software | |
1e59de90 TL |
3 | // License, Version 1.0. (See accompanying file LICENSE.txt or copy at |
4 | // https://www.bfgroup.xyz/b2/LICENSE.txt) | |
7c673cae FG |
5 | |
6 | #define BOOST_TEST_MODULE QtXmlPatterns | |
7 | ||
8 | #include <QXmlQuery> | |
9 | #include <QXmlSerializer> | |
10 | ||
11 | #include <QCoreApplication> | |
12 | #include <QString> | |
13 | #include <QTextStream> | |
14 | #include <QBuffer> | |
15 | ||
16 | #include <boost/test/unit_test.hpp> | |
17 | ||
18 | ||
19 | struct Fixture | |
20 | { | |
21 | Fixture() | |
22 | : application(boost::unit_test::framework::master_test_suite().argc, | |
23 | boost::unit_test::framework::master_test_suite().argv) | |
24 | { | |
25 | BOOST_TEST_MESSAGE( "setup QCoreApplication fixture" ); | |
26 | } | |
27 | ||
28 | ~Fixture() | |
29 | { | |
30 | BOOST_TEST_MESSAGE( "teardown QCoreApplication fixture" ); | |
31 | } | |
32 | ||
33 | QCoreApplication application; | |
34 | }; | |
35 | ||
36 | BOOST_GLOBAL_FIXTURE( Fixture ); | |
37 | ||
38 | QByteArray doc("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | |
39 | "<html xmlns=\"http://www.w3.org/1999/xhtml/\" xml:lang=\"en\" lang=\"en\">" | |
40 | " <head>" | |
41 | " <title>Global variables report for globals.gccxml</title>" | |
42 | " </head>" | |
43 | "<body><p>Some Test text</p></body></html>"); | |
44 | ||
45 | BOOST_AUTO_TEST_CASE( defines) | |
46 | { | |
47 | BOOST_CHECK_EQUAL(BOOST_IS_DEFINED(QT_CORE_LIB), true); | |
48 | BOOST_CHECK_EQUAL(BOOST_IS_DEFINED(QT_XMLPATTERNS_LIB), true); | |
49 | ||
50 | BOOST_CHECK_EQUAL(BOOST_IS_DEFINED(QT_XML_LIB), false); | |
51 | } | |
52 | ||
53 | BOOST_AUTO_TEST_CASE( extract ) | |
54 | { | |
55 | ||
56 | QBuffer buffer(&doc); // This is a QIODevice. | |
57 | buffer.open(QIODevice::ReadOnly); | |
58 | QXmlQuery query; | |
59 | query.bindVariable("myDocument", &buffer); | |
60 | query.setQuery("declare variable $myDocument external;" | |
61 | "doc($myDocument)");///p[1]"); | |
62 | ||
63 | BOOST_CHECK_EQUAL(query.isValid(), true); | |
64 | ||
65 | QByteArray result; | |
66 | QBuffer out(&result); | |
67 | out.open(QIODevice::WriteOnly); | |
68 | ||
69 | QXmlSerializer serializer(query, &out); | |
70 | BOOST_CHECK_EQUAL(query.evaluateTo(&serializer), true); | |
71 | ||
72 | QTextStream stream(stdout); | |
73 | BOOST_CHECK_EQUAL(result.isEmpty(), false); | |
74 | stream << "hallo" << result << endl; | |
75 | } | |
76 |