summaryrefslogtreecommitdiffstats
path: root/examples/qtestlib
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@nokia.com>2009-03-23 09:18:55 (GMT)
committerSimon Hausmann <simon.hausmann@nokia.com>2009-03-23 09:18:55 (GMT)
commite5fcad302d86d316390c6b0f62759a067313e8a9 (patch)
treec2afbf6f1066b6ce261f14341cf6d310e5595bc1 /examples/qtestlib
downloadQt-e5fcad302d86d316390c6b0f62759a067313e8a9.zip
Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.gz
Qt-e5fcad302d86d316390c6b0f62759a067313e8a9.tar.bz2
Long live Qt 4.5!
Diffstat (limited to 'examples/qtestlib')
-rw-r--r--examples/qtestlib/README38
-rw-r--r--examples/qtestlib/qtestlib.pro8
-rw-r--r--examples/qtestlib/tutorial1/testqstring.cpp65
-rw-r--r--examples/qtestlib/tutorial1/tutorial1.pro8
-rw-r--r--examples/qtestlib/tutorial2/testqstring.cpp81
-rw-r--r--examples/qtestlib/tutorial2/tutorial2.pro8
-rw-r--r--examples/qtestlib/tutorial3/testgui.cpp71
-rw-r--r--examples/qtestlib/tutorial3/tutorial3.pro8
-rw-r--r--examples/qtestlib/tutorial4/testgui.cpp91
-rw-r--r--examples/qtestlib/tutorial4/tutorial4.pro8
-rw-r--r--examples/qtestlib/tutorial5/benchmarking.cpp135
-rw-r--r--examples/qtestlib/tutorial5/tutorial5.pro8
12 files changed, 529 insertions, 0 deletions
diff --git a/examples/qtestlib/README b/examples/qtestlib/README
new file mode 100644
index 0000000..e89bf5d
--- /dev/null
+++ b/examples/qtestlib/README
@@ -0,0 +1,38 @@
+The QTestLib framework is a tool for unit testing Qt based applications
+and libraries. QTestLib provides all the functionality commonly found
+in unit testing frameworks as well as extensions for testing graphical
+user interfaces.
+
+
+The examples in this directory should be run from the command line so
+that output printed to the console can be examined.
+
+Documentation for these examples can be found via the "Tutorial and Examples"
+link in the main Qt documentation.
+
+Finding the Qt Examples and Demos launcher
+==========================================
+
+On Windows:
+
+The launcher can be accessed via the Windows Start menu. Select the menu
+entry entitled "Qt Examples and Demos" entry in the submenu containing
+the Qt tools.
+
+On Mac OS X:
+
+For the binary distribution, the qtdemo executable is installed in the
+/Developer/Applications/Qt directory. For the source distribution, it is
+installed alongside the other Qt tools on the path specified when Qt is
+configured.
+
+On Unix/Linux:
+
+The qtdemo executable is installed alongside the other Qt tools on the path
+specified when Qt is configured.
+
+On all platforms:
+
+The source code for the launcher can be found in the demos/qtdemo directory
+in the Qt package. This example is built at the same time as the Qt libraries,
+tools, examples, and demonstrations.
diff --git a/examples/qtestlib/qtestlib.pro b/examples/qtestlib/qtestlib.pro
new file mode 100644
index 0000000..8addbcb
--- /dev/null
+++ b/examples/qtestlib/qtestlib.pro
@@ -0,0 +1,8 @@
+TEMPLATE = subdirs
+SUBDIRS = tutorial1 tutorial2 tutorial3 tutorial4 tutorial5
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib
+sources.files = $$SOURCES $$HEADERS $$RESOURCES $$FORMS qtestlib.pro README
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib
+INSTALLS += target sources
diff --git a/examples/qtestlib/tutorial1/testqstring.cpp b/examples/qtestlib/tutorial1/testqstring.cpp
new file mode 100644
index 0000000..cc2e7ca
--- /dev/null
+++ b/examples/qtestlib/tutorial1/testqstring.cpp
@@ -0,0 +1,65 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QtTest/QtTest>
+
+class TestQString: public QObject
+{
+ Q_OBJECT
+private slots:
+ void toUpper();
+};
+//! [0]
+
+//! [1]
+void TestQString::toUpper()
+{
+ QString str = "Hello";
+ QCOMPARE(str.toUpper(), QString("HELLO"));
+}
+//! [1]
+
+//! [2]
+QTEST_MAIN(TestQString)
+#include "testqstring.moc"
+//! [2]
+
diff --git a/examples/qtestlib/tutorial1/tutorial1.pro b/examples/qtestlib/tutorial1/tutorial1.pro
new file mode 100644
index 0000000..baa15b2
--- /dev/null
+++ b/examples/qtestlib/tutorial1/tutorial1.pro
@@ -0,0 +1,8 @@
+SOURCES = testqstring.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial1
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial1
+INSTALLS += target sources
diff --git a/examples/qtestlib/tutorial2/testqstring.cpp b/examples/qtestlib/tutorial2/testqstring.cpp
new file mode 100644
index 0000000..1c1f6f7
--- /dev/null
+++ b/examples/qtestlib/tutorial2/testqstring.cpp
@@ -0,0 +1,81 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+
+//! [0]
+class TestQString: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void toUpper_data();
+ void toUpper();
+};
+//! [0]
+
+//! [1]
+void TestQString::toUpper_data()
+{
+ QTest::addColumn<QString>("string");
+ QTest::addColumn<QString>("result");
+
+ QTest::newRow("all lower") << "hello" << "HELLO";
+ QTest::newRow("mixed") << "Hello" << "HELLO";
+ QTest::newRow("all upper") << "HELLO" << "HELLO";
+}
+//! [1]
+
+//! [2]
+void TestQString::toUpper()
+{
+ QFETCH(QString, string);
+ QFETCH(QString, result);
+
+ QCOMPARE(string.toUpper(), result);
+}
+//! [2]
+
+//! [3]
+QTEST_MAIN(TestQString)
+#include "testqstring.moc"
+//! [3]
+
diff --git a/examples/qtestlib/tutorial2/tutorial2.pro b/examples/qtestlib/tutorial2/tutorial2.pro
new file mode 100644
index 0000000..44211d8
--- /dev/null
+++ b/examples/qtestlib/tutorial2/tutorial2.pro
@@ -0,0 +1,8 @@
+SOURCES = testqstring.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial2
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial2
+INSTALLS += target sources
diff --git a/examples/qtestlib/tutorial3/testgui.cpp b/examples/qtestlib/tutorial3/testgui.cpp
new file mode 100644
index 0000000..8e116f8
--- /dev/null
+++ b/examples/qtestlib/tutorial3/testgui.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+//! [0]
+#include <QtGui>
+#include <QtTest/QtTest>
+
+class TestGui: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testGui();
+
+};
+//! [0]
+
+//! [1]
+void TestGui::testGui()
+{
+ QLineEdit lineEdit;
+
+ QTest::keyClicks(&lineEdit, "hello world");
+
+ QCOMPARE(lineEdit.text(), QString("hello world"));
+}
+//! [1]
+
+//! [2]
+QTEST_MAIN(TestGui)
+#include "testgui.moc"
+//! [2]
+
diff --git a/examples/qtestlib/tutorial3/tutorial3.pro b/examples/qtestlib/tutorial3/tutorial3.pro
new file mode 100644
index 0000000..b494ba8
--- /dev/null
+++ b/examples/qtestlib/tutorial3/tutorial3.pro
@@ -0,0 +1,8 @@
+SOURCES = testgui.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial3
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial3
+INSTALLS += target sources
diff --git a/examples/qtestlib/tutorial4/testgui.cpp b/examples/qtestlib/tutorial4/testgui.cpp
new file mode 100644
index 0000000..f392fec
--- /dev/null
+++ b/examples/qtestlib/tutorial4/testgui.cpp
@@ -0,0 +1,91 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <QtTest/QtTest>
+
+//! [0]
+class TestGui: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void testGui_data();
+ void testGui();
+};
+//! [0]
+
+//! [1]
+void TestGui::testGui_data()
+{
+ QTest::addColumn<QTestEventList>("events");
+ QTest::addColumn<QString>("expected");
+
+ QTestEventList list1;
+ list1.addKeyClick('a');
+ QTest::newRow("char") << list1 << "a";
+
+ QTestEventList list2;
+ list2.addKeyClick('a');
+ list2.addKeyClick(Qt::Key_Backspace);
+ QTest::newRow("there and back again") << list2 << "";
+}
+//! [1]
+
+//! [2]
+void TestGui::testGui()
+{
+ QFETCH(QTestEventList, events);
+ QFETCH(QString, expected);
+
+ QLineEdit lineEdit;
+
+ events.simulate(&lineEdit);
+
+ QCOMPARE(lineEdit.text(), expected);
+}
+//! [2]
+
+//! [3]
+QTEST_MAIN(TestGui)
+#include "testgui.moc"
+//! [3]
+
diff --git a/examples/qtestlib/tutorial4/tutorial4.pro b/examples/qtestlib/tutorial4/tutorial4.pro
new file mode 100644
index 0000000..0777d48
--- /dev/null
+++ b/examples/qtestlib/tutorial4/tutorial4.pro
@@ -0,0 +1,8 @@
+SOURCES = testgui.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial4
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial4
+INSTALLS += target sources
diff --git a/examples/qtestlib/tutorial5/benchmarking.cpp b/examples/qtestlib/tutorial5/benchmarking.cpp
new file mode 100644
index 0000000..05ca266
--- /dev/null
+++ b/examples/qtestlib/tutorial5/benchmarking.cpp
@@ -0,0 +1,135 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, 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.0, 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.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtGui>
+#include <qtest.h>
+
+class TestBenchmark : public QObject
+{
+ Q_OBJECT
+private slots:
+ void simple();
+ void multiple_data();
+ void multiple();
+ void series_data();
+ void series();
+};
+
+//! [0]
+void TestBenchmark::simple()
+{
+ QString str1 = QLatin1String("This is a test string");
+ QString str2 = QLatin1String("This is a test string");
+
+ QCOMPARE(str1.localeAwareCompare(str2), 0);
+
+ QBENCHMARK {
+ str1.localeAwareCompare(str2);
+ }
+}
+//! [0]
+
+//! [1]
+void TestBenchmark::multiple_data()
+{
+ QTest::addColumn<bool>("useLocaleCompare");
+ QTest::newRow("locale aware compare") << true;
+ QTest::newRow("standard compare") << false;
+}
+//! [1]
+
+//! [2]
+void TestBenchmark::multiple()
+{
+ QFETCH(bool, useLocaleCompare);
+ QString str1 = QLatin1String("This is a test string");
+ QString str2 = QLatin1String("This is a test string");
+
+ int result;
+ if (useLocaleCompare) {
+ QBENCHMARK {
+ result = str1.localeAwareCompare(str2);
+ }
+ } else {
+ QBENCHMARK {
+ result = (str1 == str2);
+ }
+ }
+}
+//! [2]
+
+//! [3]
+void TestBenchmark::series_data()
+{
+ QTest::addColumn<bool>("useLocaleCompare");
+ QTest::addColumn<int>("stringSize");
+
+ for (int i = 1; i < 10000; i += 2000) {
+ QByteArray size = QByteArray::number(i);
+ QTest::newRow(("locale aware compare--" + size).constData()) << true << i;
+ QTest::newRow(("standard compare--" + size).constData()) << false << i;
+ }
+}
+//! [4]
+
+//! [5]
+void TestBenchmark::series()
+{
+ QFETCH(bool, useLocaleCompare);
+ QFETCH(int, stringSize);
+
+ QString str1 = QString().fill('A', stringSize);
+ QString str2 = QString().fill('A', stringSize);
+ int result;
+ if (useLocaleCompare) {
+ QBENCHMARK {
+ result = str1.localeAwareCompare(str2);
+ }
+ } else {
+ QBENCHMARK {
+ result = (str1 == str2);
+ }
+ }
+}
+//! [5]
+
+QTEST_MAIN(TestBenchmark)
+#include "benchmarking.moc"
diff --git a/examples/qtestlib/tutorial5/tutorial5.pro b/examples/qtestlib/tutorial5/tutorial5.pro
new file mode 100644
index 0000000..0310916
--- /dev/null
+++ b/examples/qtestlib/tutorial5/tutorial5.pro
@@ -0,0 +1,8 @@
+SOURCES = benchmarking.cpp
+CONFIG += qtestlib
+
+# install
+target.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial5
+sources.files = $$SOURCES *.pro
+sources.path = $$[QT_INSTALL_EXAMPLES]/qtestlib/tutorial5
+INSTALLS += target sources