summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/corelib.pro3
-rw-r--r--tests/auto/corelib/global/global.pro8
-rw-r--r--tests/auto/corelib/global/q_func_info/.gitignore1
-rw-r--r--tests/auto/corelib/global/q_func_info/q_func_info.pro4
-rw-r--r--tests/auto/corelib/global/q_func_info/tst_q_func_info.cpp145
-rw-r--r--tests/auto/corelib/global/qflags/.gitignore1
-rw-r--r--tests/auto/corelib/global/qflags/qflags.pro4
-rw-r--r--tests/auto/corelib/global/qflags/tst_qflags.cpp128
-rw-r--r--tests/auto/corelib/global/qgetputenv/.gitignore1
-rw-r--r--tests/auto/corelib/global/qgetputenv/qgetputenv.pro4
-rw-r--r--tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp84
-rw-r--r--tests/auto/corelib/global/qglobal/.gitignore1
-rw-r--r--tests/auto/corelib/global/qglobal/qglobal.pro4
-rw-r--r--tests/auto/corelib/global/qglobal/tst_qglobal.cpp268
-rw-r--r--tests/auto/corelib/global/qnumeric/.gitignore1
-rw-r--r--tests/auto/corelib/global/qnumeric/qnumeric.pro7
-rw-r--r--tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp124
-rw-r--r--tests/auto/corelib/global/qrand/.gitignore1
-rw-r--r--tests/auto/corelib/global/qrand/qrand.pro4
-rw-r--r--tests/auto/corelib/global/qrand/tst_qrand.cpp87
20 files changed, 879 insertions, 1 deletions
diff --git a/tests/auto/corelib/corelib.pro b/tests/auto/corelib/corelib.pro
index 122c834c63..bdb0231b32 100644
--- a/tests/auto/corelib/corelib.pro
+++ b/tests/auto/corelib/corelib.pro
@@ -2,4 +2,5 @@ TEMPLATE=subdirs
SUBDIRS=\
animation \
codecs \
- concurrent
+ concurrent \
+ global
diff --git a/tests/auto/corelib/global/global.pro b/tests/auto/corelib/global/global.pro
new file mode 100644
index 0000000000..e9b547be68
--- /dev/null
+++ b/tests/auto/corelib/global/global.pro
@@ -0,0 +1,8 @@
+TEMPLATE=subdirs
+SUBDIRS=\
+ qflags \
+ q_func_info \
+ qgetputenv \
+ qglobal \
+ qnumeric \
+ qrand
diff --git a/tests/auto/corelib/global/q_func_info/.gitignore b/tests/auto/corelib/global/q_func_info/.gitignore
new file mode 100644
index 0000000000..ff7d730764
--- /dev/null
+++ b/tests/auto/corelib/global/q_func_info/.gitignore
@@ -0,0 +1 @@
+tst_q_func_info
diff --git a/tests/auto/corelib/global/q_func_info/q_func_info.pro b/tests/auto/corelib/global/q_func_info/q_func_info.pro
new file mode 100644
index 0000000000..64f08d4d8d
--- /dev/null
+++ b/tests/auto/corelib/global/q_func_info/q_func_info.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+SOURCES += tst_q_func_info.cpp
+QT = core
+CONFIG += parallel_test
diff --git a/tests/auto/corelib/global/q_func_info/tst_q_func_info.cpp b/tests/auto/corelib/global/q_func_info/tst_q_func_info.cpp
new file mode 100644
index 0000000000..0a2a259462
--- /dev/null
+++ b/tests/auto/corelib/global/q_func_info/tst_q_func_info.cpp
@@ -0,0 +1,145 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QString>
+#include <QtTest/QtTest>
+#include <QtDebug>
+
+class tst_q_func_info : public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void callFunctions() const;
+ void isOfTypeConstChar() const;
+ void availableWithoutDebug() const;
+
+private:
+
+ static void staticMember();
+ void regularMember() const;
+ void memberWithArguments(const QString &string, int value, const int value2) const;
+};
+
+static void staticRegularFunction()
+{
+ qDebug() << Q_FUNC_INFO;
+}
+
+void regularFunction()
+{
+ qDebug() << Q_FUNC_INFO;
+}
+
+template<typename T>
+void templateFunction()
+{
+ qDebug() << Q_FUNC_INFO;
+}
+
+template<typename T, const int value>
+void valueTemplateFunction()
+{
+ qDebug() << Q_FUNC_INFO;
+}
+
+void tst_q_func_info::staticMember()
+{
+ qDebug() << Q_FUNC_INFO;
+}
+
+void tst_q_func_info::regularMember() const
+{
+ qDebug() << Q_FUNC_INFO;
+}
+
+void tst_q_func_info::memberWithArguments(const QString &, int, const int) const
+{
+ qDebug() << Q_FUNC_INFO;
+}
+
+/*! \internal
+ We don't do much here. We call different kinds of
+ functions to make sure we don't crash anything or that valgrind
+ is unhappy.
+ */
+void tst_q_func_info::callFunctions() const
+{
+ staticRegularFunction();
+ regularFunction();
+ templateFunction<char>();
+ valueTemplateFunction<int, 3>();
+
+ staticMember();
+ regularMember();
+ memberWithArguments(QString(), 3, 4);
+}
+
+void tst_q_func_info::isOfTypeConstChar() const
+{
+#ifndef QT_NO_DEBUG
+ QString::fromLatin1(Q_FUNC_INFO);
+#endif
+}
+
+/* \internal
+ Ensure that the macro is available even though QT_NO_DEBUG
+ is defined. We do this by undefining it, and turning it on again
+ backwards(just so we don't break stuff), if it was in fact defined.
+ */
+void tst_q_func_info::availableWithoutDebug() const
+{
+#ifndef QT_NO_DEBUG
+# define USE_DEBUG
+# define QT_NO_DEBUG
+#endif
+#undef QT_NO_DEBUG
+ QString::fromLatin1(Q_FUNC_INFO);
+#ifdef USE_DEBUG
+# undef QT_NO_DEBUG
+# undef USE_DEBUG
+#endif
+}
+
+QTEST_MAIN(tst_q_func_info)
+
+#include "tst_q_func_info.moc"
diff --git a/tests/auto/corelib/global/qflags/.gitignore b/tests/auto/corelib/global/qflags/.gitignore
new file mode 100644
index 0000000000..52e998ad15
--- /dev/null
+++ b/tests/auto/corelib/global/qflags/.gitignore
@@ -0,0 +1 @@
+tst_qflags
diff --git a/tests/auto/corelib/global/qflags/qflags.pro b/tests/auto/corelib/global/qflags/qflags.pro
new file mode 100644
index 0000000000..097a218a5a
--- /dev/null
+++ b/tests/auto/corelib/global/qflags/qflags.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+SOURCES += tst_qflags.cpp
+QT = core
+CONFIG += parallel_test
diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp
new file mode 100644
index 0000000000..85e64a6d63
--- /dev/null
+++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp
@@ -0,0 +1,128 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QtTest/QtTest>
+
+class tst_QFlags: public QObject
+{
+ Q_OBJECT
+private slots:
+ void testFlag() const;
+ void testFlagZeroFlag() const;
+ void testFlagMultiBits() const;
+ void constExpr();
+};
+
+void tst_QFlags::testFlag() const
+{
+ Qt::MouseButtons btn = Qt::LeftButton | Qt::RightButton;
+
+ QVERIFY(btn.testFlag(Qt::LeftButton));
+ QVERIFY(!btn.testFlag(Qt::MidButton));
+
+ btn = 0;
+ QVERIFY(!btn.testFlag(Qt::LeftButton));
+}
+
+void tst_QFlags::testFlagZeroFlag() const
+{
+ {
+ Qt::MouseButtons btn = Qt::LeftButton | Qt::RightButton;
+ /* Qt::NoButton has the value 0. */
+
+ QVERIFY(!btn.testFlag(Qt::NoButton));
+ }
+
+ {
+ /* A zero enum set should test true with zero. */
+ QVERIFY(Qt::MouseButtons().testFlag(Qt::NoButton));
+ }
+
+ {
+ Qt::MouseButtons btn = Qt::NoButton;
+ QVERIFY(btn.testFlag(Qt::NoButton));
+ }
+}
+
+void tst_QFlags::testFlagMultiBits() const
+{
+ /* Qt::Window is 0x00000001
+ * Qt::Dialog is 0x00000002 | Window
+ */
+ {
+ const Qt::WindowFlags onlyWindow(Qt::Window);
+ QVERIFY(!onlyWindow.testFlag(Qt::Dialog));
+ }
+
+ {
+ const Qt::WindowFlags hasDialog(Qt::Dialog);
+ QVERIFY(hasDialog.testFlag(Qt::Dialog));
+ }
+}
+
+template <int N, typename T> bool verifyConstExpr(T n) { return n == N; }
+
+void tst_QFlags::constExpr()
+{
+#ifdef Q_COMPILER_CONSTEXPR
+ Qt::MouseButtons btn = Qt::LeftButton | Qt::RightButton;
+ switch (btn) {
+ case Qt::LeftButton: QVERIFY(false); break;
+ case Qt::RightButton: QVERIFY(false); break;
+ case Qt::LeftButton | Qt::RightButton: QVERIFY(true); break;
+ default: QVERIFY(false);
+ }
+
+ QVERIFY(verifyConstExpr<(Qt::LeftButton | Qt::RightButton) & Qt::LeftButton>(Qt::LeftButton));
+ QVERIFY(verifyConstExpr<(Qt::LeftButton | Qt::RightButton) & Qt::MiddleButton>(0));
+ QVERIFY(verifyConstExpr<(Qt::LeftButton | Qt::RightButton) | Qt::MiddleButton>(Qt::LeftButton | Qt::RightButton | Qt::MiddleButton));
+ QVERIFY(verifyConstExpr<~(Qt::LeftButton | Qt::RightButton)>(~(Qt::LeftButton | Qt::RightButton)));
+ QVERIFY(verifyConstExpr<Qt::MouseButtons(Qt::LeftButton) ^ Qt::RightButton>(Qt::LeftButton ^ Qt::RightButton));
+ QVERIFY(verifyConstExpr<Qt::MouseButtons(0)>(0));
+ QVERIFY(verifyConstExpr<Qt::MouseButtons(Qt::RightButton) & 0xff>(Qt::RightButton));
+ QVERIFY(verifyConstExpr<Qt::MouseButtons(Qt::RightButton) | 0xff>(0xff));
+
+ QVERIFY(!verifyConstExpr<Qt::RightButton>(!Qt::MouseButtons(Qt::LeftButton)));
+#endif
+}
+
+
+QTEST_MAIN(tst_QFlags)
+#include "tst_qflags.moc"
diff --git a/tests/auto/corelib/global/qgetputenv/.gitignore b/tests/auto/corelib/global/qgetputenv/.gitignore
new file mode 100644
index 0000000000..c045a3cc03
--- /dev/null
+++ b/tests/auto/corelib/global/qgetputenv/.gitignore
@@ -0,0 +1 @@
+tst_qgetputenv
diff --git a/tests/auto/corelib/global/qgetputenv/qgetputenv.pro b/tests/auto/corelib/global/qgetputenv/qgetputenv.pro
new file mode 100644
index 0000000000..df94f14473
--- /dev/null
+++ b/tests/auto/corelib/global/qgetputenv/qgetputenv.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+SOURCES += tst_qgetputenv.cpp
+QT = core
+CONFIG += parallel_test
diff --git a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp
new file mode 100644
index 0000000000..9ad98122bc
--- /dev/null
+++ b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp
@@ -0,0 +1,84 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <qdebug.h>
+#include <QtTest/QtTest>
+
+#include <qglobal.h>
+
+//TESTED_CLASS=
+//TESTED_FILES=corelib/global/qglobal.h corelib/global/qglobal.cpp
+
+class tst_QGetPutEnv : public QObject
+{
+Q_OBJECT
+
+public:
+ tst_QGetPutEnv();
+ virtual ~tst_QGetPutEnv();
+
+private slots:
+ void getSetCheck();
+private:
+};
+
+void tst_QGetPutEnv::getSetCheck()
+{
+ const char* varName = "should_not_exist";
+ QByteArray result = qgetenv(varName);
+ QCOMPARE(result, QByteArray());
+ QVERIFY(qputenv(varName, QByteArray("supervalue")));
+ result = qgetenv(varName);
+ QVERIFY(result == "supervalue");
+ qputenv(varName,QByteArray());
+}
+
+tst_QGetPutEnv::tst_QGetPutEnv()
+{
+}
+
+tst_QGetPutEnv::~tst_QGetPutEnv()
+{
+}
+
+QTEST_MAIN(tst_QGetPutEnv)
+#include "tst_qgetputenv.moc"
diff --git a/tests/auto/corelib/global/qglobal/.gitignore b/tests/auto/corelib/global/qglobal/.gitignore
new file mode 100644
index 0000000000..5b3248d6cf
--- /dev/null
+++ b/tests/auto/corelib/global/qglobal/.gitignore
@@ -0,0 +1 @@
+tst_qglobal
diff --git a/tests/auto/corelib/global/qglobal/qglobal.pro b/tests/auto/corelib/global/qglobal/qglobal.pro
new file mode 100644
index 0000000000..a4dffac815
--- /dev/null
+++ b/tests/auto/corelib/global/qglobal/qglobal.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+SOURCES += tst_qglobal.cpp
+QT = core
+CONFIG += parallel_test
diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
new file mode 100644
index 0000000000..19a13f6ad0
--- /dev/null
+++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp
@@ -0,0 +1,268 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+
+class tst_QGlobal: public QObject
+{
+ Q_OBJECT
+private slots:
+ void qIsNull();
+ void qInternalCallbacks();
+ void for_each();
+ void qassert();
+ void qtry();
+ void checkptr();
+};
+
+void tst_QGlobal::qIsNull()
+{
+ double d = 0.0;
+ float f = 0.0f;
+
+ QVERIFY(::qIsNull(d));
+ QVERIFY(::qIsNull(f));
+
+ d += 0.000000001;
+ f += 0.0000001f;
+
+ QVERIFY(!::qIsNull(d));
+ QVERIFY(!::qIsNull(f));
+}
+
+struct ConnectInfo {
+ QObject *sender;
+ QObject *receiver;
+ QString signal, slot;
+ int type;
+ void reset() {
+ sender = receiver = 0;
+ signal = slot = QString();
+ type = -1;
+ }
+} connect_info;
+
+bool disconnect_callback(void **data)
+{
+ connect_info.sender = (QObject *)(data[0]);
+ connect_info.receiver = (QObject *)(data[2]);
+ connect_info.signal = QString::fromLatin1((const char *) data[1]);
+ connect_info.slot = QString::fromLatin1((const char *) data[3]);
+ return true;
+}
+
+bool connect_callback(void **data)
+{
+ disconnect_callback(data);
+ connect_info.type = *(int *) data[4];
+ return true;
+}
+
+void tst_QGlobal::qInternalCallbacks()
+{
+ QInternal::registerCallback(QInternal::ConnectCallback, connect_callback);
+ QInternal::registerCallback(QInternal::DisconnectCallback, disconnect_callback);
+
+ QObject a, b;
+ QString signal = QLatin1String("2mysignal(x)");
+ QString slot = QLatin1String("1myslot(x)");
+
+ // Test that connect works as expected...
+ connect_info.reset();
+ bool ok = QObject::connect(&a, signal.toLatin1(), &b, slot.toLatin1(), Qt::AutoConnection);
+ QVERIFY(ok);
+ QCOMPARE(&a, connect_info.sender);
+ QCOMPARE(&b, connect_info.receiver);
+ QCOMPARE(signal, connect_info.signal);
+ QCOMPARE(slot, connect_info.slot);
+ QCOMPARE((int) Qt::AutoConnection, connect_info.type);
+
+ // Test that disconnect works as expected
+ connect_info.reset();
+ ok = QObject::disconnect(&a, signal.toLatin1(), &b, slot.toLatin1());
+ QVERIFY(ok);
+ QCOMPARE(&a, connect_info.sender);
+ QCOMPARE(&b, connect_info.receiver);
+ QCOMPARE(signal, connect_info.signal);
+ QCOMPARE(slot, connect_info.slot);
+
+ // Unregister callbacks and verify that they are not triggered...
+ QInternal::unregisterCallback(QInternal::ConnectCallback, connect_callback);
+ QInternal::unregisterCallback(QInternal::DisconnectCallback, disconnect_callback);
+
+ connect_info.reset();
+ QTest::ignoreMessage(QtWarningMsg, "Object::connect: No such signal QObject::mysignal(x)");
+ ok = QObject::connect(&a, signal.toLatin1(), &b, slot.toLatin1(), Qt::AutoConnection);
+ QVERIFY(!ok);
+ QCOMPARE(connect_info.sender, (QObject *) 0);
+
+ QTest::ignoreMessage(QtWarningMsg, "Object::disconnect: No such signal QObject::mysignal(x)");
+ ok = QObject::disconnect(&a, signal.toLatin1(), &b, slot.toLatin1());
+ QVERIFY(!ok);
+ QCOMPARE(connect_info.sender, (QObject *) 0);
+}
+
+void tst_QGlobal::for_each()
+{
+ QList<int> list;
+ list << 0 << 1 << 2 << 3 << 4 << 5;
+
+ int counter = 0;
+ foreach(int i, list) {
+ QCOMPARE(i, counter++);
+ }
+ QCOMPARE(counter, list.count());
+
+ // do it again, to make sure we don't have any for-scoping
+ // problems with older compilers
+ counter = 0;
+ foreach(int i, list) {
+ QCOMPARE(i, counter++);
+ }
+ QCOMPARE(counter, list.count());
+}
+
+void tst_QGlobal::qassert()
+{
+ bool passed = false;
+ if (false) {
+ Q_ASSERT(false);
+ } else {
+ passed = true;
+ }
+ QVERIFY(passed);
+
+ passed = false;
+ if (false) {
+ Q_ASSERT_X(false, "tst_QGlobal", "qassert");
+ } else {
+ passed = true;
+ }
+ QVERIFY(passed);
+
+ passed = false;
+ if (false)
+ Q_ASSERT(false);
+ else
+ passed = true;
+ QVERIFY(passed);
+
+ passed = false;
+ if (false)
+ Q_ASSERT_X(false, "tst_QGlobal", "qassert");
+ else
+ passed = true;
+ QVERIFY(passed);
+}
+
+void tst_QGlobal::qtry()
+{
+ int i = 0;
+ QT_TRY {
+ i = 1;
+ QT_THROW(42);
+ i = 2;
+ } QT_CATCH(int) {
+ QCOMPARE(i, 1);
+ i = 7;
+ }
+#ifdef QT_NO_EXCEPTIONS
+ QCOMPARE(i, 2);
+#else
+ QCOMPARE(i, 7);
+#endif
+
+ // check propper if/else scoping
+ i = 0;
+ if (true)
+ QT_TRY {
+ i = 2;
+ QT_THROW(42);
+ i = 4;
+ } QT_CATCH(int) {
+ QCOMPARE(i, 2);
+ i = 4;
+ }
+ else
+ QCOMPARE(i, 0);
+ QCOMPARE(i, 4);
+
+ i = 0;
+ if (false)
+ QT_TRY {
+ i = 2;
+ QT_THROW(42);
+ i = 4;
+ } QT_CATCH(int) {
+ QCOMPARE(i, 2);
+ i = 2;
+ }
+ else
+ i = 8;
+ QCOMPARE(i, 8);
+
+ i = 0;
+ if (false)
+ i = 42;
+ else
+ QT_TRY {
+ i = 2;
+ QT_THROW(42);
+ i = 4;
+ } QT_CATCH(int) {
+ QCOMPARE(i, 2);
+ i = 4;
+ }
+ QCOMPARE(i, 4);
+}
+
+void tst_QGlobal::checkptr()
+{
+ int i;
+ QCOMPARE(q_check_ptr(&i), &i);
+
+ const char *c = "hello";
+ QCOMPARE(q_check_ptr(c), c);
+}
+
+QTEST_MAIN(tst_QGlobal)
+#include "tst_qglobal.moc"
diff --git a/tests/auto/corelib/global/qnumeric/.gitignore b/tests/auto/corelib/global/qnumeric/.gitignore
new file mode 100644
index 0000000000..c00531dd33
--- /dev/null
+++ b/tests/auto/corelib/global/qnumeric/.gitignore
@@ -0,0 +1 @@
+tst_qnumeric
diff --git a/tests/auto/corelib/global/qnumeric/qnumeric.pro b/tests/auto/corelib/global/qnumeric/qnumeric.pro
new file mode 100644
index 0000000000..c0af962a79
--- /dev/null
+++ b/tests/auto/corelib/global/qnumeric/qnumeric.pro
@@ -0,0 +1,7 @@
+load(qttest_p4)
+
+QT = core
+
+SOURCES += tst_qnumeric.cpp
+QT = core
+CONFIG += parallel_test
diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
new file mode 100644
index 0000000000..8eb4e468a1
--- /dev/null
+++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp
@@ -0,0 +1,124 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include <QtTest/QtTest>
+#include <QtGlobal>
+
+#include <math.h>
+
+class tst_QNumeric: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void fuzzyCompare_data();
+ void fuzzyCompare();
+ void qNan();
+};
+
+void tst_QNumeric::fuzzyCompare_data()
+{
+ QTest::addColumn<double>("val1");
+ QTest::addColumn<double>("val2");
+ QTest::addColumn<bool>("isEqual");
+
+ QTest::newRow("zero") << 0.0 << 0.0 << true;
+ QTest::newRow("ten") << 10.0 << 10.0 << true;
+ QTest::newRow("large") << 1000000000.0 << 1000000000.0 << true;
+ QTest::newRow("small") << 0.00000000001 << 0.00000000001 << true;
+ QTest::newRow("eps") << 10.000000000000001 << 10.00000000000002 << true;
+ QTest::newRow("eps2") << 10.000000000000001 << 10.000000000000009 << true;
+
+ QTest::newRow("mis1") << 0.0 << 1.0 << false;
+ QTest::newRow("mis2") << 0.0 << 10000000.0 << false;
+ QTest::newRow("mis3") << 0.0 << 0.000000001 << false;
+ QTest::newRow("mis4") << 100000000.0 << 0.000000001 << false;
+ QTest::newRow("mis4") << 0.0000000001 << 0.000000001 << false;
+}
+
+void tst_QNumeric::fuzzyCompare()
+{
+ QFETCH(double, val1);
+ QFETCH(double, val2);
+ QFETCH(bool, isEqual);
+
+ QCOMPARE(::qFuzzyCompare(val1, val2), isEqual);
+ QCOMPARE(::qFuzzyCompare(val2, val1), isEqual);
+ QCOMPARE(::qFuzzyCompare(-val1, -val2), isEqual);
+ QCOMPARE(::qFuzzyCompare(-val2, -val1), isEqual);
+}
+
+void tst_QNumeric::qNan()
+{
+ double nan = qQNaN();
+#if defined( __INTEL_COMPILER)
+ QCOMPARE((0 > nan), false);
+ QCOMPARE((0 < nan), false);
+ QSKIP("This fails due to a bug in the Intel Compiler", SkipAll);
+#else
+ if (0 > nan)
+ QFAIL("compiler thinks 0 > nan");
+
+# if defined(Q_CC_DIAB)
+ QWARN("!(0 < nan) would fail due to a bug in dcc");
+# else
+ if (0 < nan)
+ QFAIL("compiler thinks 0 < nan");
+# endif
+#endif
+ QVERIFY(qIsNaN(nan));
+ QVERIFY(qIsNaN(nan + 1));
+ QVERIFY(qIsNaN(-nan));
+ double inf = qInf();
+ QVERIFY(inf > 0);
+ QVERIFY(-inf < 0);
+ QVERIFY(qIsInf(inf));
+ QVERIFY(qIsInf(-inf));
+ QVERIFY(qIsInf(2*inf));
+ QCOMPARE(1/inf, 0.0);
+ QVERIFY(qIsNaN(0*nan));
+ QVERIFY(qIsNaN(0*inf));
+ QVERIFY(qFuzzyCompare(1/inf, 0.0));
+}
+
+QTEST_APPLESS_MAIN(tst_QNumeric)
+#include "tst_qnumeric.moc"
diff --git a/tests/auto/corelib/global/qrand/.gitignore b/tests/auto/corelib/global/qrand/.gitignore
new file mode 100644
index 0000000000..e8ec2ebfd1
--- /dev/null
+++ b/tests/auto/corelib/global/qrand/.gitignore
@@ -0,0 +1 @@
+tst_qrand
diff --git a/tests/auto/corelib/global/qrand/qrand.pro b/tests/auto/corelib/global/qrand/qrand.pro
new file mode 100644
index 0000000000..0db8af821c
--- /dev/null
+++ b/tests/auto/corelib/global/qrand/qrand.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+SOURCES += tst_qrand.cpp
+QT = core
+CONFIG += parallel_test
diff --git a/tests/auto/corelib/global/qrand/tst_qrand.cpp b/tests/auto/corelib/global/qrand/tst_qrand.cpp
new file mode 100644
index 0000000000..7ac778211c
--- /dev/null
+++ b/tests/auto/corelib/global/qrand/tst_qrand.cpp
@@ -0,0 +1,87 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** GNU Lesser General Public License Usage
+** This file may be used under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation and
+** appearing in the file LICENSE.LGPL included in the packaging of this
+** file. Please review the following information to ensure the GNU Lesser
+** General Public License version 2.1 requirements will be met:
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU General
+** Public License version 3.0 as published by the Free Software Foundation
+** and appearing in the file LICENSE.GPL included in the packaging of this
+** file. Please review the following information to ensure the GNU General
+** Public License version 3.0 requirements will be met:
+** http://www.gnu.org/copyleft/gpl.html.
+**
+** Other Usage
+** Alternatively, this file may be used in accordance with the terms and
+** conditions contained in a signed written agreement between you and Nokia.
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QtTest/QtTest>
+
+class tst_QRand: public QObject
+{
+ Q_OBJECT
+private slots:
+ void testqrand();
+};
+
+void tst_QRand::testqrand()
+{
+ const int numTestValues = 100;
+
+ int generatedNumbers[numTestValues];
+ bool generatesSameSequence = true;
+
+ // test without calling srand() first
+ // should give same sequence as with srand(1)
+
+ for (int i=0; i<numTestValues; ++i)
+ generatedNumbers[i] = qrand();
+
+ qsrand(1);
+ for (int i=0; i<numTestValues; ++i)
+ if (generatedNumbers[i] != qrand())
+ generatesSameSequence = false;
+
+ QVERIFY(generatesSameSequence);
+
+ for (unsigned int seed=1; seed < 10; seed+=100) {
+
+ qsrand(seed);
+ for (int i=0; i<numTestValues; ++i)
+ generatedNumbers[i] = qrand();
+
+ qsrand(seed);
+ generatesSameSequence = true;
+ for (int i=0; i<numTestValues; ++i)
+ if (generatedNumbers[i] != qrand())
+ generatesSameSequence = false;
+
+ QVERIFY(generatesSameSequence);
+ }
+}
+
+QTEST_MAIN(tst_QRand)
+#include "tst_qrand.moc"