1 /****************************************************************************
3 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the test suite of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** GNU Lesser General Public License Usage
11 ** This file may be used under the terms of the GNU Lesser General Public
12 ** License version 2.1 as published by the Free Software Foundation and
13 ** appearing in the file LICENSE.LGPL included in the packaging of this
14 ** file. Please review the following information to ensure the GNU Lesser
15 ** General Public License version 2.1 requirements will be met:
16 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
18 ** In addition, as a special exception, Nokia gives you certain additional
19 ** rights. These rights are described in the Nokia Qt LGPL Exception
20 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
22 ** GNU General Public License Usage
23 ** Alternatively, this file may be used under the terms of the GNU General
24 ** Public License version 3.0 as published by the Free Software Foundation
25 ** and appearing in the file LICENSE.GPL included in the packaging of this
26 ** file. Please review the following information to ensure the GNU General
27 ** Public License version 3.0 requirements will be met:
28 ** http://www.gnu.org/copyleft/gpl.html.
31 ** Alternatively, this file may be used in accordance with the terms and
32 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 #include <QtTest/QtTest>
46 #ifdef QTEST_XMLPATTERNS
47 #include <QtXmlPatterns/QAbstractMessageHandler>
49 /* We expect these headers to be available. */
50 #include <QtXmlPatterns/QAbstractMessageHandler>
51 #include <QtXmlPatterns/qabstractmessagehandler.h>
52 #include <QAbstractMessageHandler>
53 #include <qabstractmessagehandler.h>
56 \class tst_QAbstractMessageHandler
59 \brief Tests the QAbstractMessageHandler class.
61 class tst_QAbstractMessageHandler : public QObject
66 void constructor() const;
67 void constCorrectness() const;
69 void messageDefaultArguments() const;
70 void objectSize() const;
71 void hasQ_OBJECTMacro() const;
80 QSourceLocation sourceLocation;
82 bool operator==(const Received &other) const
84 return type == other.type
85 && description == other.description
86 && identifier == other.identifier
87 && sourceLocation == other.sourceLocation;
91 class TestMessageHandler : public QAbstractMessageHandler
94 QList<Received> received;
97 virtual void handleMessage(QtMsgType type, const QString &description, const QUrl &identifier, const QSourceLocation &sourceLocation);
100 void TestMessageHandler::handleMessage(QtMsgType type, const QString &description, const QUrl &identifier, const QSourceLocation &sourceLocation)
104 r.description = description;
105 r.identifier = identifier;
106 r.sourceLocation = sourceLocation;
110 void tst_QAbstractMessageHandler::constructor() const
112 /* Allocate instance. */
114 TestMessageHandler instance;
118 TestMessageHandler instance1;
119 TestMessageHandler instance2;
123 TestMessageHandler instance1;
124 TestMessageHandler instance2;
125 TestMessageHandler instance3;
129 void tst_QAbstractMessageHandler::constCorrectness() const
131 /* No members are supposed to be const. */
134 void tst_QAbstractMessageHandler::objectSize() const
136 /* We shouldn't be adding anything. */
137 QCOMPARE(sizeof(QAbstractMessageHandler), sizeof(QObject));
140 void tst_QAbstractMessageHandler::message() const
142 TestMessageHandler handler;
144 /* Check that the arguments comes out as expected. */
145 handler.message(QtDebugMsg,
146 QLatin1String("A description"),
147 QUrl(QLatin1String("http://example.com/ID")),
148 QSourceLocation(QUrl(QLatin1String("http://example.com/Location")), 4, 5));
151 expected.type = QtDebugMsg;
152 expected.description = QLatin1String("A description");
153 expected.identifier = QUrl(QLatin1String("http://example.com/ID"));
154 expected.sourceLocation = QSourceLocation(QUrl(QLatin1String("http://example.com/Location")), 4, 5);
156 QCOMPARE(expected, handler.received.first());
159 void tst_QAbstractMessageHandler::messageDefaultArguments() const
161 TestMessageHandler handler;
163 /* The three last arguments in message() are optional. Check that they are what we promise. */
164 handler.message(QtDebugMsg, QLatin1String("A description"));
167 expected.type = QtDebugMsg;
168 expected.description = QLatin1String("A description");
169 expected.identifier = QUrl();
170 expected.sourceLocation = QSourceLocation();
172 QCOMPARE(expected, handler.received.first());
175 void tst_QAbstractMessageHandler::hasQ_OBJECTMacro() const
177 TestMessageHandler messageHandler;
178 /* If this code fails to compile, the Q_OBJECT macro is missing in
179 * the class declaration. */
180 QAbstractMessageHandler *const secondPointer = qobject_cast<QAbstractMessageHandler *>(&messageHandler);
181 /* The static_cast is for compiling on broken compilers. */
182 QCOMPARE(static_cast<QAbstractMessageHandler *>(&messageHandler), secondPointer);
185 QTEST_MAIN(tst_QAbstractMessageHandler)
187 #include "tst_qabstractmessagehandler.moc"
192 // vim: et:ts=4:sw=4:sts=4