1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the test suite of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
44 #include <QtTest/QtTest>
46 /* We expect these headers to be available. */
47 #include <QtXmlPatterns/QAbstractMessageHandler>
48 #include <QtXmlPatterns/qabstractmessagehandler.h>
49 #include <QAbstractMessageHandler>
50 #include <qabstractmessagehandler.h>
53 \class tst_QAbstractMessageHandler
56 \brief Tests the QAbstractMessageHandler class.
58 class tst_QAbstractMessageHandler : public QObject
63 void constructor() const;
64 void constCorrectness() const;
66 void messageDefaultArguments() const;
67 void objectSize() const;
68 void hasQ_OBJECTMacro() const;
77 QSourceLocation sourceLocation;
79 bool operator==(const Received &other) const
81 return type == other.type
82 && description == other.description
83 && identifier == other.identifier
84 && sourceLocation == other.sourceLocation;
88 class TestMessageHandler : public QAbstractMessageHandler
91 QList<Received> received;
94 virtual void handleMessage(QtMsgType type, const QString &description, const QUrl &identifier, const QSourceLocation &sourceLocation);
97 void TestMessageHandler::handleMessage(QtMsgType type, const QString &description, const QUrl &identifier, const QSourceLocation &sourceLocation)
101 r.description = description;
102 r.identifier = identifier;
103 r.sourceLocation = sourceLocation;
107 void tst_QAbstractMessageHandler::constructor() const
109 /* Allocate instance. */
111 TestMessageHandler instance;
115 TestMessageHandler instance1;
116 TestMessageHandler instance2;
120 TestMessageHandler instance1;
121 TestMessageHandler instance2;
122 TestMessageHandler instance3;
126 void tst_QAbstractMessageHandler::constCorrectness() const
128 /* No members are supposed to be const. */
131 void tst_QAbstractMessageHandler::objectSize() const
133 /* We shouldn't be adding anything. */
134 QCOMPARE(sizeof(QAbstractMessageHandler), sizeof(QObject));
137 void tst_QAbstractMessageHandler::message() const
139 TestMessageHandler handler;
141 /* Check that the arguments comes out as expected. */
142 handler.message(QtDebugMsg,
143 QLatin1String("A description"),
144 QUrl(QLatin1String("http://example.com/ID")),
145 QSourceLocation(QUrl(QLatin1String("http://example.com/Location")), 4, 5));
148 expected.type = QtDebugMsg;
149 expected.description = QLatin1String("A description");
150 expected.identifier = QUrl(QLatin1String("http://example.com/ID"));
151 expected.sourceLocation = QSourceLocation(QUrl(QLatin1String("http://example.com/Location")), 4, 5);
153 QCOMPARE(expected, handler.received.first());
156 void tst_QAbstractMessageHandler::messageDefaultArguments() const
158 TestMessageHandler handler;
160 /* The three last arguments in message() are optional. Check that they are what we promise. */
161 handler.message(QtDebugMsg, QLatin1String("A description"));
164 expected.type = QtDebugMsg;
165 expected.description = QLatin1String("A description");
166 expected.identifier = QUrl();
167 expected.sourceLocation = QSourceLocation();
169 QCOMPARE(expected, handler.received.first());
172 void tst_QAbstractMessageHandler::hasQ_OBJECTMacro() const
174 TestMessageHandler messageHandler;
175 /* If this code fails to compile, the Q_OBJECT macro is missing in
176 * the class declaration. */
177 QAbstractMessageHandler *const secondPointer = qobject_cast<QAbstractMessageHandler *>(&messageHandler);
178 /* The static_cast is for compiling on broken compilers. */
179 QCOMPARE(static_cast<QAbstractMessageHandler *>(&messageHandler), secondPointer);
182 QTEST_MAIN(tst_QAbstractMessageHandler)
184 #include "tst_qabstractmessagehandler.moc"
186 // vim: et:ts=4:sw=4:sts=4