summaryrefslogtreecommitdiffstats
path: root/src/testlib/doc/snippets
diff options
context:
space:
mode:
authorNico Vertriest <nico.vertriest@qt.io>2020-02-27 12:58:26 +0100
committerNico Vertriest <nico.vertriest@qt.io>2020-04-03 13:13:55 +0000
commit713cd83200f3c60eac5d389dfabc44be1446e2ac (patch)
tree5f5eb19254e661022d8db88f3cc772bdc7a60e29 /src/testlib/doc/snippets
parent0c2d6c163f6e7908a7cc9a626f027cb38a5d7786 (diff)
Doc: Make Qt Test snippets compilable
Task-number: QTBUG-81498 Change-Id: I22f07cd539e5e317b6cf15eb369d59915146bd13 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'src/testlib/doc/snippets')
-rw-r--r--src/testlib/doc/snippets/code/doc_src_qtestevent.cpp18
-rw-r--r--src/testlib/doc/snippets/code/doc_src_qtestlib.cpp6
-rw-r--r--src/testlib/doc/snippets/code/doc_src_qtqskip.cpp16
-rw-r--r--src/testlib/doc/snippets/code/doc_src_qtqskip_snippet.cpp53
-rw-r--r--src/testlib/doc/snippets/code/src_corelib_kernel_qtestsupport_core.cpp24
-rw-r--r--src/testlib/doc/snippets/code/src_corelib_kernel_qtestsupport_core_snippet.cpp57
-rw-r--r--src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp227
-rw-r--r--src/testlib/doc/snippets/code/src_qtestlib_qtestcase_snippet.cpp168
-rw-r--r--src/testlib/doc/snippets/snippets.pro10
9 files changed, 396 insertions, 183 deletions
diff --git a/src/testlib/doc/snippets/code/doc_src_qtestevent.cpp b/src/testlib/doc/snippets/code/doc_src_qtestevent.cpp
index df9aa9b558..8d125f60b7 100644
--- a/src/testlib/doc/snippets/code/doc_src_qtestevent.cpp
+++ b/src/testlib/doc/snippets/code/doc_src_qtestevent.cpp
@@ -48,14 +48,28 @@
**
****************************************************************************/
+#include <QtTest/QtTest>
+#include <QLineEdit>
+
+// dummy
+class TestGui: public QObject
+{
+ Q_OBJECT
+public:
+ void testGui_data();
+};
+
+void TestGui::testGui_data()
+{
+QWidget *myParent = nullptr;
//! [0]
QTestEventList events;
events.addKeyClick('a');
events.addKeyClick(Qt::Key_Backspace);
events.addDelay(200);
-
QLineEdit *lineEdit = new QLineEdit(myParent);
-...
+// ...
events.simulate(lineEdit);
events.simulate(lineEdit);
//! [0]
+}
diff --git a/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp b/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp
index de301b8df9..8938a15911 100644
--- a/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp
+++ b/src/testlib/doc/snippets/code/doc_src_qtestlib.cpp
@@ -49,7 +49,7 @@
****************************************************************************/
#include <QtTest>
-
+#include "src_qtestlib_qtestcase.cpp"
//! [0]
class MyFirstTest: public QObject
{
@@ -95,13 +95,15 @@ void TestQString::toUpper()
}
//! [8]
-
+void TestQString::Compare()
+{
//! [11]
QCOMPARE(QString("hello").toUpper(), QString("HELLO"));
QCOMPARE(QString("Hello").toUpper(), QString("HELLO"));
QCOMPARE(QString("HellO").toUpper(), QString("HELLO"));
QCOMPARE(QString("HELLO").toUpper(), QString("HELLO"));
//! [11]
+}
//! [12]
class MyFirstBenchmark: public QObject
diff --git a/src/testlib/doc/snippets/code/doc_src_qtqskip.cpp b/src/testlib/doc/snippets/code/doc_src_qtqskip.cpp
index d261e87e4c..550f85dd8a 100644
--- a/src/testlib/doc/snippets/code/doc_src_qtqskip.cpp
+++ b/src/testlib/doc/snippets/code/doc_src_qtqskip.cpp
@@ -47,20 +47,22 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <QTest>
-//! [0]
+//dummy class
+class tst_Skip
+{
+ public:
+ void test_data();
+};
-if ( tst_Databases::getMySqlVersion( db ).section( QChar('.'), 0, 0 ).toInt()<5 )
- QSKIP( "Test requires MySQL >= 5.0");
-//! [0]
-//! [1]
void tst_Skip::test_data()
{
+//! [1]
QTest::addColumn<bool>("bool");
QTest::newRow("local 1") << false;
QTest::newRow("local 2") << true;
QSKIP("skipping all");
-}
//! [1]
-void tst_Skip::test_data()
+}
diff --git a/src/testlib/doc/snippets/code/doc_src_qtqskip_snippet.cpp b/src/testlib/doc/snippets/code/doc_src_qtqskip_snippet.cpp
new file mode 100644
index 0000000000..98a209d4bb
--- /dev/null
+++ b/src/testlib/doc/snippets/code/doc_src_qtqskip_snippet.cpp
@@ -0,0 +1,53 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+//! [0]
+if (tst_Databases::getMySqlVersion(db).section(QChar('.'), 0, 0).toInt() < 5)
+ QSKIP("Test requires MySQL >= 5.0");
+//! [0]
diff --git a/src/testlib/doc/snippets/code/src_corelib_kernel_qtestsupport_core.cpp b/src/testlib/doc/snippets/code/src_corelib_kernel_qtestsupport_core.cpp
index e793cb1f55..33b0e19be0 100644
--- a/src/testlib/doc/snippets/code/src_corelib_kernel_qtestsupport_core.cpp
+++ b/src/testlib/doc/snippets/code/src_corelib_kernel_qtestsupport_core.cpp
@@ -47,17 +47,27 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <QtTest>
-//! [0]
- MyObject obj;
- obj.startup();
- QTest::qWaitFor([&]() {
- return obj.isReady();
- }, 3000);
-//! [0]
+// dummy class
+class MyObject
+{
+ public:
+ int isReady();
+};
+// dummy function
+int myNetworkServerNotResponding()
+{
+ return 1;
+}
+
+int MyObject::isReady()
+{
//! [1]
int i = 0;
while (myNetworkServerNotResponding() && i++ < 50)
QTest::qWait(250);
//! [1]
+return 1;
+}
diff --git a/src/testlib/doc/snippets/code/src_corelib_kernel_qtestsupport_core_snippet.cpp b/src/testlib/doc/snippets/code/src_corelib_kernel_qtestsupport_core_snippet.cpp
new file mode 100644
index 0000000000..435ffa0754
--- /dev/null
+++ b/src/testlib/doc/snippets/code/src_corelib_kernel_qtestsupport_core_snippet.cpp
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+/! [0]
+ MyObject obj;
+ obj.startup();
+ QTest::qWaitFor([&]() {
+ return obj.isReady();
+ }, 3000);
+//! [0]
diff --git a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp
index 2dc4fe49ef..eda0f430a1 100644
--- a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp
+++ b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp
@@ -47,25 +47,50 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+#include <QTest>
+#include <QSqlDatabase>
-
-void wrapInFunction()
+// dummy
+class TestBenchmark : public QObject
{
+ Q_OBJECT
+private slots:
+ void simple();
+};
-//! [0]
- QVERIFY(spy.isValid())
-//! [0]
+// dummy
+class MyTestClass : public QObject
+{
+ public:
+ void cleanup();
+ void addSingleStringRows();
+ void addMultStringRows();
+ void addDataRow();
+};
+// dummy
+void closeAllDatabases()
+{
+};
+class TestQString : public QObject
+{
+ public:
+ void toInt_data();
+ void toInt();
+ void toUpper();
+ void Compare();
+};
+void wrapInFunction()
+{
//! [1]
QVERIFY2(qIsNaN(0.0 / 0.0), "Ill-defined division produced unambiguous result.");
//! [1]
-
//! [2]
QCOMPARE(QString("hello").toUpper(), QString("HELLO"));
//! [2]
-
+}
//! [3]
void TestQString::toInt_data()
@@ -79,7 +104,6 @@ void TestQString::toInt_data()
}
//! [3]
-
//! [4]
void TestQString::toInt()
{
@@ -90,109 +114,69 @@ void TestQString::toInt()
}
//! [4]
-
+void testInt()
+{
+// dummy
+int i = 0, j = 0;
//! [5]
if (sizeof(int) != 4)
QFAIL("This test has not been ported to this platform yet.");
//! [5]
-
//! [6]
QFETCH(QString, myString);
QCOMPARE(QString("hello").toUpper(), myString);
//! [6]
-
//! [7]
QTEST(QString("hello").toUpper(), "myString");
//! [7]
-
//! [8]
if (!QSqlDatabase::drivers().contains("SQLITE"))
QSKIP("This test requires the SQLITE database driver");
//! [8]
-
//! [9]
QEXPECT_FAIL("", "Will fix in the next release", Continue);
QCOMPARE(i, 42);
QCOMPARE(j, 43);
//! [9]
-
//! [10]
QEXPECT_FAIL("data27", "Oh my, this is soooo broken", Abort);
QCOMPARE(i, 42);
//! [10]
-
+}
//! [11]
-class TestQString: public QObject { ... };
QTEST_MAIN(TestQString)
//! [11]
-
-//! [13]
-QTest::keyClick(myWidget, 'a');
-//! [13]
-
-
-//! [14]
-QTest::keyClick(myWidget, Qt::Key_Escape);
-
-QTest::keyClick(myWidget, Qt::Key_Escape, Qt::ShiftModifier, 200);
-//! [14]
-
-
-//! [15]
-QTest::keyClicks(myWidget, "hello world");
-//! [15]
-
-
-//! [16]
-namespace QTest {
- template<>
- char *toString(const MyPoint &point)
- {
- QByteArray ba = "MyPoint(";
- ba += QByteArray::number(point.x()) + ", " + QByteArray::number(point.y());
- ba += ')';
- return qstrdup(ba.data());
- }
-}
-//! [16]
-
-//! [toString-overload]
-namespace MyNamespace {
- char *toString(const MyPoint &point)
- {
- // bring QTest::toString overloads into scope:
- using QTest::toString;
- // delegate char* handling to QTest::toString(QByteArray):
- return toString("MyPoint(" +
- QByteArray::number(point.x()) + ", " +
- QByteArray::number(point.y()) + ')');
- }
-}
-//! [toString-overload]
-
+void testObject()
+{
+class MyTestObject: public QObject
+{
+ public:
+ void toString();
+};
//! [18]
MyTestObject test1;
QTest::qExec(&test1);
//! [18]
+}
-
+void tstQDir()
+{
//! [19]
QDir dir;
-
QTest::ignoreMessage(QtWarningMsg, "QDir::mkdir: Empty or null file name(s)");
dir.mkdir("");
//! [19]
-
+}
//! [20]
-void myTestFunction_data()
+void MyTestClass::addSingleStringRows()
{
QTest::addColumn<QString>("aString");
QTest::newRow("just hello") << QString("hello");
@@ -200,152 +184,65 @@ void myTestFunction_data()
}
//! [20]
-
-//! [addRow]
-void myTestFunction_data()
+void MyTestClass::addMultStringRows()
{
+//! [addRow]
QTest::addColumn<int>("input");
QTest::addColumn<QString>("output");
QTest::addRow("%d", 0) << 0 << QString("0");
QTest::addRow("%d", 1) << 1 << QString("1");
-}
//! [addRow]
+}
-
+void MyTestClass::addDataRow()
+{
//! [21]
-void myTestFunction_data() {
QTest::addColumn<int>("intval");
QTest::addColumn<QString>("str");
QTest::addColumn<double>("dbl");
-
QTest::newRow("row1") << 1 << "hello" << 1.5;
-}
//! [21]
-
+}
//! [22]
void MyTestClass::cleanup()
{
- if (qstrcmp(currentTestFunction(), "myDatabaseTest") == 0) {
+ if (qstrcmp(QTest::currentTestFunction(), "myDatabaseTest") == 0) {
// clean up all database connections
closeAllDatabases();
}
}
//! [22]
-
+void mySleep()
+{
//! [23]
QTest::qSleep(250);
//! [23]
-
-
-//! [25]
-QTouchDevice *dev = QTest::createTouchDevice();
-QWidget widget;
-
-QTest::touchEvent(&widget, dev)
- .press(0, QPoint(10, 10));
-QTest::touchEvent(&widget, dev)
- .stationary(0)
- .press(1, QPoint(40, 10));
-QTest::touchEvent(&widget, dev)
- .move(0, QPoint(12, 12))
- .move(1, QPoint(45, 5));
-QTest::touchEvent(&widget, dev)
- .release(0, QPoint(12, 12))
- .release(1, QPoint(45, 5));
-//! [25]
-
-
-//! [26]
-// Source: /home/user/sources/myxmlparser/tests/tst_myxmlparser/tst_myxmlparser.cpp
-// Build: /home/user/build/myxmlparser/tests/tst_myxmlparser
-// Qt: /usr/local/Qt-5.0.0
-void tst_MyXmlParser::parse()
-{
- MyXmlParser parser;
- QString input = QFINDTESTDATA("testxml/simple1.xml");
- QVERIFY(parser.parse(input));
}
-//! [26]
//! [27]
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);
}
}
//! [27]
-//! [28]
-QTest::keyClick(myWindow, 'a');
-//! [28]
-
-
-//! [29]
-QTest::keyClick(myWindow, Qt::Key_Escape);
-
-QTest::keyClick(myWindow, Qt::Key_Escape, Qt::ShiftModifier, 200);
-//! [29]
-
-}
-
-//! [30]
-void TestQLocale::initTestCase_data()
-{
- QTest::addColumn<QLocale>("locale");
- QTest::newRow("C") << QLocale::c();
- QTest::newRow("UKish") << QLocale("en_GB");
- QTest::newRow("USAish") << QLocale(QLocale::English);
-}
-
-void TestQLocale::roundTripInt_data()
+void verifyString()
{
- QTest::addColumn<int>("number");
- QTest::newRow("one") << 1;
- QTest::newRow("two") << 2;
- QTest::newRow("ten") << 10;
-}
-//! [30]
-
-//! [31]
-void TestQLocale::roundTripInt()
-{
- QFETCH_GLOBAL(QLocale, locale);
- QFETCH(int, number);
- bool ok;
- QCOMPARE(locale.toInt(locale.toString(number), &ok), number);
- QVERIFY(ok);
-}
-//! [31]
-
-
+QFile file;
//! [32]
bool opened = file.open(QIODevice::WriteOnly);
QVERIFY(opened);
//! [32]
-
-
//! [33]
QVERIFY2(file.open(QIODevice::WriteOnly),
- qPrintable(QString("open %1: %2").arg(file.fileName()).arg(file.errorString()));
+ qPrintable(QString("open %1: %2")
+ .arg(file.fileName()).arg(file.errorString())));
//! [33]
-
-//! [34]
-QT_BEGIN_NAMESPACE
-namespace QTest {
- template <> char *toString<MyType>(const MyType &t)
- {
- char *repr = new char[t.reprSize()];
- t.writeRepr(repr);
- return repr;
- }
}
-QT_END_NAMESPACE
-//! [34]
diff --git a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase_snippet.cpp b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase_snippet.cpp
new file mode 100644
index 0000000000..f414ee4252
--- /dev/null
+++ b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase_snippet.cpp
@@ -0,0 +1,168 @@
+/****************************************************************************
+**
+** Copyright (C) 2020 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the documentation of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:BSD$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** BSD License Usage
+** Alternatively, you may use this file under the terms of the BSD license
+** as follows:
+**
+** "Redistribution and use in source and binary forms, with or without
+** modification, are permitted provided that the following conditions are
+** met:
+** * Redistributions of source code must retain the above copyright
+** notice, this list of conditions and the following disclaimer.
+** * Redistributions in binary form must reproduce the above copyright
+** notice, this list of conditions and the following disclaimer in
+** the documentation and/or other materials provided with the
+** distribution.
+** * Neither the name of The Qt Company Ltd nor the names of its
+** contributors may be used to endorse or promote products derived
+** from this software without specific prior written permission.
+**
+**
+** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+//! [0]
+QVERIFY(spy.isValid());
+//! [0]
+
+//! [13]
+QTest::keyClick(myWidget, 'a');
+//! [13]
+
+//! [14]
+QTest::keyClick(myWidget, Qt::Key_Escape);
+
+QTest::keyClick(myWidget, Qt::Key_Escape, Qt::ShiftModifier, 200);
+//! [14]
+
+//! [15]
+QTest::keyClicks(myWidget, "hello world");
+//! [15]
+
+//! [16]
+namespace QTest {
+ template<>
+ char *toString(const MyPoint &point)
+ {
+ const QByteArray ba("MyPoint("
+ + QByteArray::number(point.x()) + ", "
+ + QByteArray::number(point.y()) + ')');
+ return qstrdup(ba.data());
+ }
+}
+//! [16]
+
+//! [toString-overload]
+namespace {
+ char *toString(const MyPoint &point)
+ {
+ return QTest::toString("MyPoint(" +
+ QByteArray::number(point.x()) + ", " +
+ QByteArray::number(point.y()) + ')');
+ }
+}
+//! [toString-overload]
+
+void processTouchEvent()
+{
+//! [25]
+QTouchDevice *dev = QTest::createTouchDevice();
+QWidget widget;
+
+QTest::touchEvent(&widget, dev)
+ .press(0, QPoint(10, 10));
+QTest::touchEvent(&widget, dev)
+ .stationary(0)
+ .press(1, QPoint(40, 10));
+QTest::touchEvent(&widget, dev)
+ .move(0, QPoint(12, 12))
+ .move(1, QPoint(45, 5));
+QTest::touchEvent(&widget, dev)
+ .release(0, QPoint(12, 12))
+ .release(1, QPoint(45, 5));
+//! [25]
+}
+
+//! [26]
+bool tst_MyXmlParser::parse()
+{
+ MyXmlParser parser;
+ QString input = QFINDTESTDATA("testxml/simple1.xml");
+ QVERIFY(parser.parse(input));
+}
+//! [26]
+
+//! [28]
+QWidget myWindow;
+QTest::keyClick(&myWindow, Qt::Key_Tab);
+//! [28]
+
+//! [29]
+QTest::keyClick(&myWindow, Qt::Key_Escape);
+QTest::keyClick(&myWindow, Qt::Key_Escape, Qt::ShiftModifier, 200);
+//! [29]
+
+//! [30]
+void TestQLocale::initTestCase_data()
+{
+ QTest::addColumn<QLocale>("locale");
+ QTest::newRow("C") << QLocale::c();
+ QTest::newRow("UKish") << QLocale("en_GB");
+ QTest::newRow("USAish") << QLocale(QLocale::English, QLocale::UnitedStates);
+}
+
+void TestQLocale::roundTripInt_data()
+{
+ QTest::addColumn<int>("number");
+ QTest::newRow("zero") << 0;
+ QTest::newRow("one") << 1;
+ QTest::newRow("two") << 2;
+ QTest::newRow("ten") << 10;
+}
+//! [30]
+
+//! [31]
+void TestQLocale::roundTripInt()
+{
+ QFETCH_GLOBAL(QLocale, locale);
+ QFETCH(int, number);
+ bool ok;
+ QCOMPARE(locale.toInt(locale.toString(number), &ok), number);
+ QVERIFY(ok);
+}
+//! [31]
+
+//! [34]
+char *toString(const MyType &t)
+{
+ char *repr = new char[t.reprSize()];
+ t.writeRepr(repr);
+ return repr;
+}
+//! [34]
diff --git a/src/testlib/doc/snippets/snippets.pro b/src/testlib/doc/snippets/snippets.pro
new file mode 100644
index 0000000000..28b6682b72
--- /dev/null
+++ b/src/testlib/doc/snippets/snippets.pro
@@ -0,0 +1,10 @@
+TEMPLATE = app
+TARGET = testlib_cppsnippet
+QT = core testlib sql widgets
+
+SOURCES += code/src_qtestlib_qtestcase.cpp \
+ code/doc_src_qtestlib.cpp \
+ code/doc_src_qtestevent.cpp \
+ code/doc_src_qtqskip.cpp \
+ code/doc_src_qttest.cpp \
+ code/src_corelib_kernel_qtestsupport_core.cpp