0
|
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.
|
|
15 |
**
|
|
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.
|
|
23 |
**
|
|
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.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QFile>
|
|
44 |
#include <QtTest/QtTest>
|
|
45 |
|
|
46 |
#ifdef QTEST_XMLPATTERNS
|
|
47 |
#include <QtXmlPatterns/QAbstractMessageHandler>
|
|
48 |
|
|
49 |
/* We expect these headers to be available. */
|
|
50 |
#include <QtXmlPatterns/QAbstractMessageHandler>
|
|
51 |
#include <QtXmlPatterns/qabstractmessagehandler.h>
|
|
52 |
#include <QAbstractMessageHandler>
|
|
53 |
#include <qabstractmessagehandler.h>
|
|
54 |
|
|
55 |
/*!
|
|
56 |
\class tst_QAbstractMessageHandler
|
|
57 |
\internal
|
|
58 |
\since 4.4
|
|
59 |
\brief Tests the QAbstractMessageHandler class.
|
|
60 |
*/
|
|
61 |
class tst_QAbstractMessageHandler : public QObject
|
|
62 |
{
|
|
63 |
Q_OBJECT
|
|
64 |
|
|
65 |
private Q_SLOTS:
|
|
66 |
void constructor() const;
|
|
67 |
void constCorrectness() const;
|
|
68 |
void message() const;
|
|
69 |
void messageDefaultArguments() const;
|
|
70 |
void objectSize() const;
|
|
71 |
void hasQ_OBJECTMacro() const;
|
|
72 |
};
|
|
73 |
|
|
74 |
class Received
|
|
75 |
{
|
|
76 |
public:
|
|
77 |
QtMsgType type;
|
|
78 |
QString description;
|
|
79 |
QUrl identifier;
|
|
80 |
QSourceLocation sourceLocation;
|
|
81 |
|
|
82 |
bool operator==(const Received &other) const
|
|
83 |
{
|
|
84 |
return type == other.type
|
|
85 |
&& description == other.description
|
|
86 |
&& identifier == other.identifier
|
|
87 |
&& sourceLocation == other.sourceLocation;
|
|
88 |
}
|
|
89 |
};
|
|
90 |
|
|
91 |
class TestMessageHandler : public QAbstractMessageHandler
|
|
92 |
{
|
|
93 |
public:
|
|
94 |
QList<Received> received;
|
|
95 |
|
|
96 |
protected:
|
|
97 |
virtual void handleMessage(QtMsgType type, const QString &description, const QUrl &identifier, const QSourceLocation &sourceLocation);
|
|
98 |
};
|
|
99 |
|
|
100 |
void TestMessageHandler::handleMessage(QtMsgType type, const QString &description, const QUrl &identifier, const QSourceLocation &sourceLocation)
|
|
101 |
{
|
|
102 |
Received r;
|
|
103 |
r.type = type;
|
|
104 |
r.description = description;
|
|
105 |
r.identifier = identifier;
|
|
106 |
r.sourceLocation = sourceLocation;
|
|
107 |
received.append(r);
|
|
108 |
}
|
|
109 |
|
|
110 |
void tst_QAbstractMessageHandler::constructor() const
|
|
111 |
{
|
|
112 |
/* Allocate instance. */
|
|
113 |
{
|
|
114 |
TestMessageHandler instance;
|
|
115 |
}
|
|
116 |
|
|
117 |
{
|
|
118 |
TestMessageHandler instance1;
|
|
119 |
TestMessageHandler instance2;
|
|
120 |
}
|
|
121 |
|
|
122 |
{
|
|
123 |
TestMessageHandler instance1;
|
|
124 |
TestMessageHandler instance2;
|
|
125 |
TestMessageHandler instance3;
|
|
126 |
}
|
|
127 |
}
|
|
128 |
|
|
129 |
void tst_QAbstractMessageHandler::constCorrectness() const
|
|
130 |
{
|
|
131 |
/* No members are supposed to be const. */
|
|
132 |
}
|
|
133 |
|
|
134 |
void tst_QAbstractMessageHandler::objectSize() const
|
|
135 |
{
|
|
136 |
/* We shouldn't be adding anything. */
|
|
137 |
QCOMPARE(sizeof(QAbstractMessageHandler), sizeof(QObject));
|
|
138 |
}
|
|
139 |
|
|
140 |
void tst_QAbstractMessageHandler::message() const
|
|
141 |
{
|
|
142 |
TestMessageHandler handler;
|
|
143 |
|
|
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));
|
|
149 |
|
|
150 |
Received expected;
|
|
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);
|
|
155 |
|
|
156 |
QCOMPARE(expected, handler.received.first());
|
|
157 |
}
|
|
158 |
|
|
159 |
void tst_QAbstractMessageHandler::messageDefaultArguments() const
|
|
160 |
{
|
|
161 |
TestMessageHandler handler;
|
|
162 |
|
|
163 |
/* The three last arguments in message() are optional. Check that they are what we promise. */
|
|
164 |
handler.message(QtDebugMsg, QLatin1String("A description"));
|
|
165 |
|
|
166 |
Received expected;
|
|
167 |
expected.type = QtDebugMsg;
|
|
168 |
expected.description = QLatin1String("A description");
|
|
169 |
expected.identifier = QUrl();
|
|
170 |
expected.sourceLocation = QSourceLocation();
|
|
171 |
|
|
172 |
QCOMPARE(expected, handler.received.first());
|
|
173 |
}
|
|
174 |
|
|
175 |
void tst_QAbstractMessageHandler::hasQ_OBJECTMacro() const
|
|
176 |
{
|
|
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);
|
|
183 |
}
|
|
184 |
|
|
185 |
QTEST_MAIN(tst_QAbstractMessageHandler)
|
|
186 |
|
|
187 |
#include "tst_qabstractmessagehandler.moc"
|
|
188 |
#else
|
|
189 |
QTEST_NOOP_MAIN
|
|
190 |
#endif
|
|
191 |
|
|
192 |
// vim: et:ts=4:sw=4:sts=4
|