diff options
Diffstat (limited to 'src/testlib/doc/snippets/code')
10 files changed, 49 insertions, 41 deletions
diff --git a/src/testlib/doc/snippets/code/CMakeLists.txt b/src/testlib/doc/snippets/code/CMakeLists.txt index 34e362668d..54c655a521 100644 --- a/src/testlib/doc/snippets/code/CMakeLists.txt +++ b/src/testlib/doc/snippets/code/CMakeLists.txt @@ -1,9 +1,8 @@ # Copyright (C) 2022 The Qt Company Ltd. -# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause add_library(testlib_code_snippets OBJECT doc_src_qtqskip.cpp - doc_src_qttest.cpp src_corelib_kernel_qtestsupport_core.cpp ) diff --git a/src/testlib/doc/snippets/code/doc_src_cmakelists.txt b/src/testlib/doc/snippets/code/doc_src_cmakelists.txt index 6e19597775..946f09c09f 100644 --- a/src/testlib/doc/snippets/code/doc_src_cmakelists.txt +++ b/src/testlib/doc/snippets/code/doc_src_cmakelists.txt @@ -8,7 +8,7 @@ set(CMAKE_AUTOMOC ON) enable_testing(true) -add_executable(mytest tst_mytest.cpp) +qt_add_executable(mytest tst_mytest.cpp) add_test(NAME mytest COMMAND mytest) target_link_libraries(mytest PRIVATE Qt::Test) diff --git a/src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp b/src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp index 20459f9eb4..99760ea730 100644 --- a/src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp +++ b/src/testlib/doc/snippets/code/doc_src_qsignalspy.cpp @@ -43,9 +43,6 @@ SomeStruct result = qvariant_cast<SomeStruct>(spy.at(0).at(0)); QSignalSpy spy(myPushButton, SIGNAL(clicked(bool))); //! [4] -//! [5] -QVERIFY(spy.wait(1000)); -//! [5] //! [6] QSignalSpy spy(myPushButton, &QPushButton::clicked); diff --git a/src/testlib/doc/snippets/code/doc_src_qtestlib.qdoc b/src/testlib/doc/snippets/code/doc_src_qtestlib.qdoc index 93bf5111a0..9b592bdb6a 100644 --- a/src/testlib/doc/snippets/code/doc_src_qtestlib.qdoc +++ b/src/testlib/doc/snippets/code/doc_src_qtestlib.qdoc @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only //! [2] testname [options] [testfunctions[:testdata]]... @@ -54,9 +54,9 @@ Totals: 3 passed, 0 failed, 0 skipped ********* Start testing of TestQString ********* Config: Using QtTest library %VERSION%, Qt %VERSION% PASS : TestQString::initTestCase() -PASS : TestQString::toUpper(all lower) +PASS : TestQString::toUpper(all-lower) PASS : TestQString::toUpper(mixed) -PASS : TestQString::toUpper(all upper) +PASS : TestQString::toUpper(all-upper) PASS : TestQString::cleanupTestCase() Totals: 5 passed, 0 failed, 0 skipped, 0 blacklisted, 0ms ********* Finished testing of TestQString ********* @@ -77,7 +77,7 @@ Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted, 20ms Config: Using QtTest library %VERSION%, Qt %VERSION% PASS : TestGui::initTestCase() PASS : TestGui::testGui(char) -PASS : TestGui::testGui(there and back again) +PASS : TestGui::testGui(there+back-again) PASS : TestGui::cleanupTestCase() Totals: 4 passed, 0 failed, 0 skipped, 0 blacklisted, 18ms ********* Finished testing of TestGui ********* @@ -90,12 +90,12 @@ PASS : TestBenchmark::initTestCase() PASS : TestBenchmark::simple() RESULT : TestBenchmark::simple(): 0.00030 msecs per iteration (total: 79, iterations: 262144) -PASS : TestBenchmark::multiple(locale aware compare) -RESULT : TestBenchmark::multiple():"locale aware compare": +PASS : TestBenchmark::multiple(locale-aware-compare) +RESULT : TestBenchmark::multiple():"locale-aware-compare": 0.00029 msecs per iteration (total: 78, iterations: 262144) ..... -PASS : TestBenchmark::series(locale aware compare--8001) -RESULT : TestBenchmark::series():"locale aware compare--8001": +PASS : TestBenchmark::series(locale-aware-compare:8001) +RESULT : TestBenchmark::series():"locale-aware-compare:8001": 0.039 msecs per iteration (total: 81, iterations: 2048) Totals: 15 passed, 0 failed, 0 skipped, 0 blacklisted, 3971ms ********* Finished testing of TestBenchmark ********* diff --git a/src/testlib/doc/snippets/code/doc_src_qtqskip.cpp b/src/testlib/doc/snippets/code/doc_src_qtqskip.cpp index 14f5085dd4..85aed2870d 100644 --- a/src/testlib/doc/snippets/code/doc_src_qtqskip.cpp +++ b/src/testlib/doc/snippets/code/doc_src_qtqskip.cpp @@ -13,8 +13,8 @@ void tst_Skip::test_data() { //! [1] QTest::addColumn<bool>("bool"); - QTest::newRow("local 1") << false; - QTest::newRow("local 2") << true; + QTest::newRow("local.1") << false; + QTest::newRow("local.2") << true; QSKIP("skipping all"); //! [1] diff --git a/src/testlib/doc/snippets/code/doc_src_qttest.cpp b/src/testlib/doc/snippets/code/doc_src_qttest.cpp deleted file mode 100644 index 06b4588268..0000000000 --- a/src/testlib/doc/snippets/code/doc_src_qttest.cpp +++ /dev/null @@ -1,6 +0,0 @@ -// Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -//! [0] -#include <QTest> -//! [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 906a88b20f..7faf40d9b7 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 @@ -5,8 +5,9 @@ // dummy class class MyObject { - public: - int isReady(); +public: + int isReady(); + void startup() {} }; // dummy function @@ -18,9 +19,22 @@ int myNetworkServerNotResponding() int MyObject::isReady() { //! [1] + using namespace std::chrono_literals; int i = 0; while (myNetworkServerNotResponding() && i++ < 50) - QTest::qWait(250); + QTest::qWait(250ms); //! [1] return 1; } + +[[maybe_unused]] static bool startup() +{ +//! [2] + MyObject obj; + obj.startup(); + using namespace std::chrono_literals; + const bool result = QTest::qWaitFor([&obj]() { return obj.isReady(); }, + QDeadlineTimer(3s)); +//! [2] + return result; +} 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 deleted file mode 100644 index f2ba321a67..0000000000 --- a/src/testlib/doc/snippets/code/src_corelib_kernel_qtestsupport_core_snippet.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (C) 2020 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause - -//! [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 63d0b992fc..4716d06e55 100644 --- a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp +++ b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase.cpp @@ -56,8 +56,8 @@ void TestQString::toInt_data() QTest::addColumn<QString>("aString"); QTest::addColumn<int>("expected"); - QTest::newRow("positive value") << "42" << 42; - QTest::newRow("negative value") << "-42" << -42; + QTest::newRow("positive+value") << "42" << 42; + QTest::newRow("negative-value") << "-42" << -42; QTest::newRow("zero") << "0" << 0; } //! [3] @@ -135,8 +135,8 @@ dir.mkdir(""); void MyTestClass::addSingleStringRows() { QTest::addColumn<QString>("aString"); - QTest::newRow("just hello") << QString("hello"); - QTest::newRow("a null string") << QString(); + QTest::newRow("just.hello") << QString("hello"); + QTest::newRow("a.null.string") << QString(); } //! [20] @@ -170,10 +170,11 @@ void MyTestClass::cleanup() } //! [22] -void mySleep() +void quarterSecondSleep() { //! [23] -QTest::qSleep(250); +using namespace std::chrono_literals; +QTest::qSleep(250ms); //! [23] } diff --git a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase_snippet.cpp b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase_snippet.cpp index e64e9daecf..aa24746522 100644 --- a/src/testlib/doc/snippets/code/src_qtestlib_qtestcase_snippet.cpp +++ b/src/testlib/doc/snippets/code/src_qtestlib_qtestcase_snippet.cpp @@ -119,3 +119,16 @@ char *toString(const MyType &t) return repr; } //! [34] + +//! [35] +QSignalSpy doubleClickSpy(target, &TargetClass::doubleClicked); +const QPoint p(1, 2); +QTest::mousePress(&myWindow, Qt::LeftButton, Qt::NoModifier, p); +QVERIFY(target.isPressed()); +QTest::mouseRelease(&myWindow, Qt::LeftButton, Qt::NoModifier, p, 10); +QCOMPARE(target.isPressed(), false); +QTest::mousePress(&myWindow, Qt::LeftButton, Qt::NoModifier, p, 10); +QCOMPARE(target.pressCount(), 2); +QTest::mouseRelease(&myWindow, Qt::LeftButton, Qt::NoModifier, p, 10); +QCOMPARE(doubleClickSpy.count(), 1); +//! [35] |