Fix macplist autotest
[qt-netbsd.git] / tests / auto / qxml / tst_qxml.cpp
blobdc1974e35a2ad6abd5a10d07c849626227323258
1 /****************************************************************************
2 **
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
6 **
7 ** This file is part of the test suite of the Qt Toolkit.
8 **
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
38 ** $QT_END_LICENSE$
40 ****************************************************************************/
43 #include <QtTest/QtTest>
45 #include <qcoreapplication.h>
46 #include <qdebug.h>
47 #include <qxml.h>
50 //TESTED_CLASS=
51 //TESTED_FILES=
53 class tst_QXml : public QObject
55 Q_OBJECT
57 private slots:
58 void getSetCheck();
59 void interpretedAs0D() const;
60 void exception();
63 class MyXmlEntityResolver : public QXmlEntityResolver
65 public:
66 MyXmlEntityResolver() : QXmlEntityResolver() {}
67 QString errorString() const { return QString(); }
68 bool resolveEntity(const QString &, const QString &, QXmlInputSource *&) { return false; }
71 class MyXmlContentHandler : public QXmlContentHandler
73 public:
74 MyXmlContentHandler() : QXmlContentHandler() {}
75 bool characters(const QString &) { return false; }
76 bool endDocument() { return false; }
77 bool endElement(const QString &, const QString &, const QString &) { return false; }
78 bool endPrefixMapping(const QString &) { return false; }
79 QString errorString() const { return QString(); }
80 bool ignorableWhitespace(const QString &) { return false; }
81 bool processingInstruction(const QString &, const QString &) { return false; }
82 void setDocumentLocator(QXmlLocator *) { }
83 bool skippedEntity(const QString &) { return false; }
84 bool startDocument() { return false; }
85 bool startElement(const QString &, const QString &, const QString &, const QXmlAttributes &) { return false; }
86 bool startPrefixMapping(const QString &, const QString &) { return false; }
89 class MyXmlErrorHandler : public QXmlErrorHandler
91 public:
92 MyXmlErrorHandler() : QXmlErrorHandler() {}
93 QString errorString() const { return QString(); }
94 bool error(const QXmlParseException &) { return false; }
95 bool fatalError(const QXmlParseException &) { return false; }
96 bool warning(const QXmlParseException &) { return false; }
99 class MyXmlLexicalHandler : public QXmlLexicalHandler
101 public:
102 MyXmlLexicalHandler() : QXmlLexicalHandler() {}
103 bool comment(const QString &) { return false; }
104 bool endCDATA() { return false; }
105 bool endDTD() { return false; }
106 bool endEntity(const QString &) { return false; }
107 QString errorString() const { return QString(); }
108 bool startCDATA() { return false; }
109 bool startDTD(const QString &, const QString &, const QString &) { return false; }
110 bool startEntity(const QString &) { return false; }
113 class MyXmlDeclHandler : public QXmlDeclHandler
115 public:
116 MyXmlDeclHandler() : QXmlDeclHandler() {}
117 bool attributeDecl(const QString &, const QString &, const QString &, const QString &, const QString &) { return false; }
118 QString errorString() const { return QString(); }
119 bool externalEntityDecl(const QString &, const QString &, const QString &) { return false; }
120 bool internalEntityDecl(const QString &, const QString &) { return false; }
123 // Testing get/set functions
124 void tst_QXml::getSetCheck()
126 QXmlSimpleReader obj1;
127 // QXmlEntityResolver* QXmlSimpleReader::entityResolver()
128 // void QXmlSimpleReader::setEntityResolver(QXmlEntityResolver*)
129 MyXmlEntityResolver *var1 = new MyXmlEntityResolver;
130 obj1.setEntityResolver(var1);
131 QCOMPARE(static_cast<QXmlEntityResolver *>(var1), obj1.entityResolver());
132 obj1.setEntityResolver((QXmlEntityResolver *)0);
133 QCOMPARE((QXmlEntityResolver *)0, obj1.entityResolver());
134 delete var1;
136 // QXmlContentHandler* QXmlSimpleReader::contentHandler()
137 // void QXmlSimpleReader::setContentHandler(QXmlContentHandler*)
138 MyXmlContentHandler *var2 = new MyXmlContentHandler;
139 obj1.setContentHandler(var2);
140 QCOMPARE(static_cast<QXmlContentHandler *>(var2), obj1.contentHandler());
141 obj1.setContentHandler((QXmlContentHandler *)0);
142 QCOMPARE((QXmlContentHandler *)0, obj1.contentHandler());
143 delete var2;
145 // QXmlErrorHandler* QXmlSimpleReader::errorHandler()
146 // void QXmlSimpleReader::setErrorHandler(QXmlErrorHandler*)
147 MyXmlErrorHandler *var3 = new MyXmlErrorHandler;
148 obj1.setErrorHandler(var3);
149 QCOMPARE(static_cast<QXmlErrorHandler *>(var3), obj1.errorHandler());
150 obj1.setErrorHandler((QXmlErrorHandler *)0);
151 QCOMPARE((QXmlErrorHandler *)0, obj1.errorHandler());
152 delete var3;
154 // QXmlLexicalHandler* QXmlSimpleReader::lexicalHandler()
155 // void QXmlSimpleReader::setLexicalHandler(QXmlLexicalHandler*)
156 MyXmlLexicalHandler *var4 = new MyXmlLexicalHandler;
157 obj1.setLexicalHandler(var4);
158 QCOMPARE(static_cast<QXmlLexicalHandler *>(var4), obj1.lexicalHandler());
159 obj1.setLexicalHandler((QXmlLexicalHandler *)0);
160 QCOMPARE((QXmlLexicalHandler *)0, obj1.lexicalHandler());
161 delete var4;
163 // QXmlDeclHandler* QXmlSimpleReader::declHandler()
164 // void QXmlSimpleReader::setDeclHandler(QXmlDeclHandler*)
165 MyXmlDeclHandler *var5 = new MyXmlDeclHandler;
166 obj1.setDeclHandler(var5);
167 QCOMPARE(static_cast<QXmlDeclHandler *>(var5), obj1.declHandler());
168 obj1.setDeclHandler((QXmlDeclHandler *)0);
169 QCOMPARE((QXmlDeclHandler *)0, obj1.declHandler());
170 delete var5;
173 void tst_QXml::interpretedAs0D() const
175 /* See task 172632. */
177 class MyHandler : public QXmlDefaultHandler
179 public:
180 virtual bool startElement(const QString &namespaceURI,
181 const QString &localName,
182 const QString &qName,
183 const QXmlAttributes &atts)
185 Q_UNUSED(namespaceURI);
186 Q_UNUSED(localName);
187 Q_UNUSED(qName);
188 attrName = atts.qName(0);
189 attrCount = atts.count();
190 return true;
193 QString attrName;
194 int attrCount;
197 const QString document(QLatin1String("<element ") +
198 QChar(0x010D) +
199 QLatin1String("reated-by=\"an attr value\"/>"));
201 QFile f("0x010D.xml");
202 QVERIFY(f.open(QIODevice::ReadOnly));
203 QXmlInputSource data(&f);
205 QXmlSimpleReader reader;
207 MyHandler myHandler;
208 reader.setContentHandler(&myHandler);
209 reader.setErrorHandler(&myHandler);
211 QVERIFY(reader.parse(&data));
213 QCOMPARE(myHandler.attrCount, 1);
214 QCOMPARE(myHandler.attrName, QChar(0x010D) + QString::fromLatin1("reated-by"));
217 void tst_QXml::exception()
219 #ifndef QT_NO_EXCEPTIONS
220 QString message = QString::fromLatin1("message");
221 int column = 3;
222 int line = 2;
223 QString publicId = QString::fromLatin1("publicId");
224 QString systemId = QString::fromLatin1("systemId");
226 try {
227 QXmlParseException e(message, column, line, publicId, systemId);
228 throw e;
230 catch (QXmlParseException e) {
231 QCOMPARE(e.message(), message);
232 QCOMPARE(e.columnNumber(), column);
233 QCOMPARE(e.lineNumber(), line);
234 QCOMPARE(e.publicId(), publicId);
235 QCOMPARE(e.systemId(), systemId);
237 #else
238 QSKIP("Exceptions not available", SkipAll);
239 #endif
242 QTEST_MAIN(tst_QXml)
243 #include "tst_qxml.moc"