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 ****************************************************************************/
43 #include <QtTest/QtTest>
45 class tst_QGlobal: public QObject
50 void qInternalCallbacks();
57 void tst_QGlobal::qIsNull()
62 QVERIFY(::qIsNull(d));
63 QVERIFY(::qIsNull(f));
68 QVERIFY(!::qIsNull(d));
69 QVERIFY(!::qIsNull(f));
78 sender = receiver = 0;
79 signal = slot = QString();
84 bool disconnect_callback(void **data)
86 connect_info.sender = (QObject *)(data[0]);
87 connect_info.receiver = (QObject *)(data[2]);
88 connect_info.signal = QString::fromLatin1((const char *) data[1]);
89 connect_info.slot = QString::fromLatin1((const char *) data[3]);
93 bool connect_callback(void **data)
95 disconnect_callback(data);
96 connect_info.type = *(int *) data[4];
100 void tst_QGlobal::qInternalCallbacks()
102 QInternal::registerCallback(QInternal::ConnectCallback, connect_callback);
103 QInternal::registerCallback(QInternal::DisconnectCallback, disconnect_callback);
106 QString signal = QLatin1String("2mysignal(x)");
107 QString slot = QLatin1String("1myslot(x)");
109 // Test that connect works as expected...
110 connect_info.reset();
111 bool ok = QObject::connect(&a, signal.toLatin1(), &b, slot.toLatin1(), Qt::AutoConnection);
113 QCOMPARE(&a, connect_info.sender);
114 QCOMPARE(&b, connect_info.receiver);
115 QCOMPARE(signal, connect_info.signal);
116 QCOMPARE(slot, connect_info.slot);
117 QCOMPARE((int) Qt::AutoConnection, connect_info.type);
119 // Test that disconnect works as expected
120 connect_info.reset();
121 ok = QObject::disconnect(&a, signal.toLatin1(), &b, slot.toLatin1());
123 QCOMPARE(&a, connect_info.sender);
124 QCOMPARE(&b, connect_info.receiver);
125 QCOMPARE(signal, connect_info.signal);
126 QCOMPARE(slot, connect_info.slot);
128 // Unregister callbacks and verify that they are not triggered...
129 QInternal::unregisterCallback(QInternal::ConnectCallback, connect_callback);
130 QInternal::unregisterCallback(QInternal::DisconnectCallback, disconnect_callback);
132 connect_info.reset();
133 QTest::ignoreMessage(QtWarningMsg, "Object::connect: No such signal QObject::mysignal(x)");
134 ok = QObject::connect(&a, signal.toLatin1(), &b, slot.toLatin1(), Qt::AutoConnection);
136 QCOMPARE(connect_info.sender, (QObject *) 0);
138 QTest::ignoreMessage(QtWarningMsg, "Object::disconnect: No such signal QObject::mysignal(x)");
139 ok = QObject::disconnect(&a, signal.toLatin1(), &b, slot.toLatin1());
141 QCOMPARE(connect_info.sender, (QObject *) 0);
144 void tst_QGlobal::for_each()
147 list << 0 << 1 << 2 << 3 << 4 << 5;
150 foreach(int i, list) {
151 QCOMPARE(i, counter++);
153 QCOMPARE(counter, list.count());
155 // do it again, to make sure we don't have any for-scoping
156 // problems with older compilers
158 foreach(int i, list) {
159 QCOMPARE(i, counter++);
161 QCOMPARE(counter, list.count());
164 void tst_QGlobal::qassert()
176 Q_ASSERT_X(false, "tst_QGlobal", "qassert");
191 Q_ASSERT_X(false, "tst_QGlobal", "qassert");
197 void tst_QGlobal::qtry()
208 #ifdef QT_NO_EXCEPTIONS
214 // check propper if/else scoping
258 void tst_QGlobal::checkptr()
261 QCOMPARE(q_check_ptr(&i), &i);
263 const char *c = "hello";
264 QCOMPARE(q_check_ptr(c), c);
267 QTEST_MAIN(tst_QGlobal)
268 #include "tst_qglobal.moc"