summaryrefslogtreecommitdiffstats
path: root/tests/auto/testlib
Commit message (Collapse)AuthorAgeFilesLines
* QTest: rip out qxp::function_ref from reportResult()Thiago Macieira9 days7-14/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is causing huge code bloat because everything is a local lambda. Instead, pass direct type-erased function and data pointers to the replacement function. Testing with tst_qcborvalue, this reduces the compilation time and the output binary size significantly: Before After Compiler Time Size Time Size GCC 13.2 136.99 s 202.3 MB 13.88 s 14.3 MB GCC 14.0 131.49 s 202.7 MB 14.69 s 14.4 MB Clang 17 77.2 s 146.7 MB 13.62 s 12.2 MB Clang 18 141.9 s 187.1 MB 13.62 s 12.4 MB This causes a difference in how toString() overloads are found. Previously it would match far more overloads because the toString() calls were expanded by the macro. Now, we depend on Argument-Dependent Lookup and associated namespaces, so toString() overloads should not be in the QTest namespace any more. With this patch applied, the testlib testcase of tst_selftest started failing, because nullptr is now handled differently. However, I consider it as a bugfix, because previously it was falling back to a default implementation, and now it is using the QTest::toString(std::nullptr_t) overload, which is a desired behavior. Update the reference files for tst_selftest with the new expected output. Task-number: QTBUG-124272 Change-Id: Ie28eadac333c4bcd8c08fffd17c5484186accdf6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QSignalSpy: separate messages for invalid and non-signal meta-methodsMarc Mutz2024-03-221-2/+2
| | | | | | | | | | | | | | | If a signal was invalid, the code still called messageSignature(), which returns a null QByteArray, and passed its constData() to qWarning("%s"). That probably worked in our implementation, because it falls back to QString::asprintf(), but it raised eyebrows, so avoid calling messageSignature() on invalid QMetaMethod. This changes the warning output, so adjust the test. Task-number: QTBUG-123544 Change-Id: I41bc6650de091f61354ff91ee45659668f0e0223 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* tst_QSignalSpy: check (thereby suppress) intended runtime warningsMarc Mutz2024-03-191-0/+6
| | | | | | | | | | | Use QTest::ignoreMessage() to prevent the runtime warnings being printed, cleaning up the test log, and to document that they're intended. Pick-to: 6.7 6.6 6.5 Change-Id: Ia0ba888cce83529217642be0e7e321d9406ba386 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QSignalSpy: fix data race between wait() and emit from another threadDavid Faure2024-03-191-1/+31
| | | | | | | | | | | Detected by TSAN in tst_QThread::terminateAndPrematureDestruction() but better have a dedicated unittest, with values emitted by the signal and recorded in the spy. Pick-to: 6.7 6.6 6.5 Change-Id: I141d47b0ea0b63188f8a4f9d056f72df3457bda5 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port two tests' QAbstractEventDispatcher overrides to V2Thiago Macieira2024-03-131-8/+5
| | | | | Change-Id: I83dda2d36c904517b3c0fffd17b52c421bf08d5b Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
* Correct license for tools filesLucie Gérard2024-03-051-1/+1
| | | | | | | | | | | | According to QUIP-18 [1], all tools file should be LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Task-number: QTBUG-121787 Change-Id: Icd5d5be2e04819617e68ff142924de1773bebbad Reviewed-by: Kai Köhne <kai.koehne@qt.io>
* QTest: allow passing chrono literal as QTRY_ timeoutMarc Mutz2024-02-071-4/+4
| | | | | | | | | | | | | | | | | | | By wrapping the use of the timeout value in QTRY_IMPL in a lambda that feeds the user input through the std::chrono::milliseconds constructor with std::chrono_literals in-scope, the macros continue to work with raw integral values as well as chrono literals not finer than millisecond granularity. Port all higher-level macros to pass a chrono literal and port some uses in tst_selftests. [ChangeLog][QtTest] The QTRY_*_WITH_TIMEOUT macros now also accept chrono literals (was: int milliseconds). Fixes: QTBUG-121746 Change-Id: Ib38406fc005a0a2c4ae3fd009760f73ad8bed355 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Change license for tests filesLucie Gérard2024-02-0470-70/+70
| | | | | | | | | | | | According to QUIP-18 [1], all tests file should be LicenseRef-Qt-Commercial OR GPL-3.0-only [1]: https://contribute.qt-project.org/quips/18 Pick-to: 6.7 Task-number: QTBUG-121787 Change-Id: I9657df5d660820e56c96d511ea49d321c54682e8 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
* QTest: add -[no]throwon{fail,skip} command line argumentsMarc Mutz2024-01-271-4/+15
| | | | | | | | | | | | ... to complement QTEST_THROW_ON_FAIl/SKIP environment variables. This allows to conveniently test both modes by running each test twice. Task-number: QTBUG-66320 Change-Id: I8b2810e8345061c98472d846017de910a11e0657 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QTest: add opt-in changing QCOMPARE etc to exit with throw, not returnMarc Mutz2024-01-2766-1/+74
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Add exception classes and use them to change the control flow for QTEST_{FAIL,SKIP}_ACTION from return'ing from just the immediate function to the full way to the QTestLib infrastructure, here we filter them out. There are three modes: - If QT_NO_EXCEPTION, then we return - If QTEST_THROW_ON_... is also defined, #error out - Otherwise, if QTEST_THROW_ON_... is defined, always throw - Otherwise, the decision is made at runtime (with defaults read from QTEST_THROW_ON_... environment variables). Three selftests depend on the old behavior, as they explicitly check that multiple FAIL SKIP etc emerge, which the new framework, of course, prevents. Locally disable throwing at the test function level. Add initial docs and enable exceptions in all of the selftest subprograms to facilitate switching between the two runtime-selectable modes. [ChangeLog][QtTest] Added QTEST_THROW_ON_FAIL and QTEST_THROW_ON_SKIP C++ macros and environment variables that, when defined, change how QCOMPARE/QVERIFY/QSKIP etc exit the test function on failure. Instead of a return, exiting only the immediately-surrounding function, they throw a special exception instead, thereby exiting from subfunctions of the test function, all the way to QtTestLib. Fixes: QTBUG-66320 Change-Id: I96c38d2a1dcdd9de84942cf448a8bbf3ab6d3679 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Fix some -Wunused-* warnings on MinGWMarc Mutz2024-01-101-3/+3
| | | | | | | | | | | | Found while inspecting a recent MingWG log file from the CI. Amends a2551c45d496c23045eb8451e080e75b2f8b42c1. Amends f992402f15fd117bb5ccf9a484bf31fd4f4967e2. Pick-to: 6.7 6.6 Change-Id: Icf56ddc19ac7b40718ec3f429d14cbcb1a2e164f Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Long live QDebug::operator<<(q(u)int128)!Marc Mutz2023-12-091-0/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Replace the ad-hoc implementation of QTest::toString() in tst_qglobal.cpp with a QDebug stream operator, so the QTest::toString() fall-back to QDebug::toString() kicks in. Since the ABI issues revolving around the new int128 types are not known, yet, avoid baking the types into the ABI by a) making the operators constrained templates¹ and b) passing though void* to the exported helpers. These functions return an error message if Qt was compiled without support for int128. Use the Thiago Trick™ (leaving obviouly dead code around for the compiler to remove without warning) to expose more code to more compilers. This appears to work elsewhere in Qt, so I hope it does here, too. This completes the minimum qint128 support so we're able to debug code and write tests that use these types. ¹ Templates, unlike inline member functions of wholly-exported classes, never² become part of the ABI. ² <insert here the convoluted scenario under which this is false> Fixes: QTBUG-117011 Change-Id: Ia4e56d26c6ffd18b7d69a7ceaed65b2211d258b2 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* tst_tostring: support computed expected valuesMarc Mutz2023-12-061-3/+12
| | | | | | | | | | | | | | | | | | | | | We need an owning container to keep the data alive when the _data function computes the expected value instead of passing it as a literal string, so replace the QByteArrayView we used so far with a const QByteArray. If a test failed, print the tail ends of the failing strings. This is useful when toString() implementations printing the operands of the failed toString()-under-test result comparison decide to truncate the output. It works around the fact that we both test toString() and use toString() to report any failure. As a drive-by, add a missing blank line between function definitions. Amends a2551c45d496c23045eb8451e080e75b2f8b42c1. Pick-to: 6.6 Change-Id: I0b217aeb1a6d475df8e8b9fb821046f1cceb1a3e Reviewed-by: Jason McDonald <macadder1@gmail.com>
* QTest: make failOnWarning() functional on temp objects destructionVladimir Belyavsky2023-11-227-6/+61
| | | | | | | | | | | | | | | | | | | | | | | | | | We need to be able to handle warnings that may occur when temporary objects, that were created in a test function, are destroyed. For example, now we miss all warnings that might be triggered from the object destructor, if the object's deletion was delayed (e.g. via deleteLater()). Also we miss all the warnings that were triggered on the test's cleanup() call. To fix this we need simply move QTestLog::clearFailOnWarnings() from QTestResult::finishedCurrentTestData() to the later stage, i.e. into QTestLog::clearCurrentTestState() which is actually called in appropriate time from QTestResult::finishedCurrentTestDataCleanup(). Same for QTestLog::clearIgnoreMessages(), since they are interrelated, so we need to clear them at the same time. We need this change for QML tests in particularly, to be able fail on warnings that might be triggered from Component.onDestruction() of some temporary test object. Pick-to: 6.6 6.5 Change-Id: I58a57691f20761619f56bd1bea3a862f2c26f569 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* qtestlib: Add option to skip blacklisted testsKalle Viironen2023-11-2211-4/+216
| | | | | | | | | | | | | | | Add a command-line option "-skipblacklisted" to testlib to skip blacklisted test cases. Currently, blacklisted test cases are run, but results are ignored. For test code coverage measurements, it's important to see the code coverage of the actually tested code in comparison to the code that was run but not actually tested. The default approach remains unchanged, meaning that blacklisted tests are run with the results ignored. Fixes: QTBUG-112793 Change-Id: I6fe0a6353cb1c021e0232c79bb4f404632fb0bce Reviewed-by: Jason McDonald <macadder1@gmail.com>
* Add QTest option for repeating the entire test executionJøger Hansegård2023-11-151-0/+10
| | | | | | | | | | | | | | | | | Repeated test execution can be useful, under a debugger, to catch an intermittent failure or, under memory instrumentation, to make memory leaks easier to recognize. The new -repeat flag allows running the entire test suite multiple times within the same process. It works by executing all tests sequentially before repeating the execution again. This switch is a developer tool, and is not intended for CI. It can only be used with the plain text logger. Change-Id: I2439462c5c44d1c8aa3d3b5656de3eef44898c68 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* Increase QTest failure message limitMitch Curtis2023-10-197-13/+155
| | | | | | | | | | | | | | QPalette specifically has quite a large amount of output (1363 characters) when toString is called on it. We should make sure that we can fit that in our failure messages. This patch does that by increasing the limit from 1024 characters to 4096. Fixes: QTBUG-5903 Fixes: QTBUG-87039 Pick-to: 6.5 6.6 Change-Id: I1dc5078ad05858bb6542c3a06c6b84711af79e4f Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* selftests: document how to run subtests from Windows' cmd.exeMitch Curtis2023-10-171-0/+7
| | | | | | | | | | It deoesn't like single quotes, which must be replaced with doubled-up double quotes. Pick-to: 6.2 6.5 6.6 Change-Id: I8e5f8047e72e4433926a9f4f2044407a4d823682 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* selftests: respect ASAN_OPTIONSMitch Curtis2023-10-162-2/+3
| | | | | | | | | | | | | Ensure that this environment variable is respected, as ASAN errors (e.g. memory leaks) can cause the selftests to fail since they expect no errors in their output. Fix an incorrect function name in a comment, while we're at it. Fixes: QTBUG-118041 Pick-to: 6.5 6.6 Change-Id: I07502101aabd8743df898ae8fe4a693c4733c4af Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* tst_QAbstractItemModelTester: fix unittestChristian Ehrlicher2023-09-081-21/+22
| | | | | | | | | | | | | | | | rowsAboutToBeMoved() and rowsMoved() signals aren't emitted for QSortFilterProxyModel, which meant the two connections in the ObservingObject's constructor didn't trigger the slots, which let the test pass (the store/checkPersistentFailureCount stayed at 0). - Instead connect to layoutAboutToBeChanged() and layoutChanged() respectively, these two are emitted for QSFPM - Use PMF syntax - Verify m_persistent{Proxy,Source}Indexes aren't empty Change-Id: I8b83989de02c2bfb22bde9b230cb5b68814f74b6 Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* tst_selftests: split the qFatal() test away from tst_SilentThiago Macieira2023-09-068-19/+63
| | | | | | | | | | This allows us to control whether to run this particular test in ASan mode or with specific loggers or not. Adding the expected log output for tst_silent for other loggers is left as an exercise to the reader. Change-Id: Ifa1111900d6945ea8e05fffd177f1548c8c8e714 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Revert "Dodge qFatal() so as to get coverage results despite it"Thiago Macieira2023-09-061-20/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This reverts commit f20adcde3079227b063b747e6bd91f8fd94c4866. The implementation had the right idea, but this is not expected to work reliably in C++. It's jumping out of several frames without cleaning them out properly and our ASan-based memory leak-checker has started complaining (the next commit will move this test elsewhere). ==19313==ERROR: LeakSanitizer: detected memory leaks Direct leak of 258 byte(s) in 1 object(s) allocated from: #0 0x7ffa505c8e48 in __interceptor_malloc (/usr/lib64/libasan.so.5+0x109e48) #1 0x7ffa4f2d7ff9 (/home/qt/work/install/lib/libQt6Core.so.6+0x896ff9) #2 0x7ffa4f2d834d in QArrayData::allocate(QArrayData**, long long, long long, long long, QArrayData::AllocationOption) (/home/qt/work/install/lib/libQt6Core.so.6+0x89734d) #3 0x7ffa4f23b700 (/home/qt/work/install/lib/libQt6Core.so.6+0x7fa700) #4 0x7ffa4f1f6cc8 in QString::reallocData(long long, QArrayData::AllocationOption) (/home/qt/work/install/lib/libQt6Core.so.6+0x7b5cc8) #5 0x7ffa4f1f68a7 in QString::resize(long long) (/home/qt/work/install/lib/libQt6Core.so.6+0x7b58a7) #6 0x7ffa4f2092ff (/home/qt/work/install/lib/libQt6Core.so.6+0x7c82ff) #7 0x7ffa4f209e09 in QString::vasprintf(char const*, __va_list_tag*) (/home/qt/work/install/lib/libQt6Core.so.6+0x7c8e09) #8 0x7ffa4ed0d83d (/home/qt/work/install/lib/libQt6Core.so.6+0x2cc83d) #9 0x7ffa4ed114a9 in QMessageLogger::fatal(char const*, ...) const (/home/qt/work/install/lib/libQt6Core.so.6+0x2d04a9) #10 0x5641d2604c40 in tst_Silent::messages() /home/qt/work/qt/qtbase/tests/auto/testlib/selftests/silent/tst_silent.cpp:77 #11 0x5641d26050fb in tst_Silent::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) tests/auto/testlib/selftests/silent/silent_autogen/include/tst_silent.moc:118 The restoration of the signal handler (which QtTest now has) is also wrong: this needed to use sigaction() instead. Change-Id: Ifa1111900d6945ea8e05fffd177f14fbc09a1d7d Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* tst_selftests: add a way to run a subset of all subprogramsThiago Macieira2023-08-311-0/+2
| | | | | | | This functionality was lost when we switched to Catch2. Change-Id: I2b24e1d3cad44897906efffd177fb4cff641546f Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
* tst_selftests: deduplicate the Unix/Linux conditionsThiago Macieira2023-08-301-9/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Amends 118f2210c6279803b9a4103a796ce75e88f8beb2. That commit added #ifdef Q_OS_UNIX if (test == "assert" || test == "crashes" || test == "failfetchtype" || test == "faildatatype") return; // Outputs "Received signal 6 (SIGABRT)" #endif Which duplicated 4 out of the 5 tests in the block: #ifdef Q_OS_LINUX // QEMU outputs to stderr about uncaught signals if (QTestPrivate::isRunningArmOnX86() && (test == "assert" || test == "crashes" || test == "faildatatype" || test == "failfetchtype" || test == "silent" )) return; #endif But as Linux is Unix, we never got to that second block for those 4 tests. Pick-to: 6.6 Change-Id: I2b24e1d3cad44897906efffd177fb4b5507d190a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* tst_selftests: compile with QT_NO_FOREACHAhmad Samir2023-08-191-3/+2
| | | | | | | | | | The loop was iterating over a temporary container, so it couldn't have changed it. Use a const auto variable to hold the container and port to ranged-for Task-number: QTBUG-115839 Change-Id: I66e7cbdb811666ca352cdf064b1228caa346d876 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* selftests/badxml/tst_badxml: compile with QT_NO_FOREACHAhmad Samir2023-08-191-14/+10
| | | | | | | | | | | | | | | | | badString(): const'ify the static QList, this is both faster as the compiler doesn't need to check if it has been already initialized, and it means we can use it directly in ranged-for as the method returns const QList&. Drive-by change: don't go the long way around to get a const char*: qPrintable(QString("fail %1").arg(ba)) instead use: QTest::addRow("fail %s", ba.constData()) (thanks to dfaure for pointing it out in review). Task-number: QTBUG-115839 Change-Id: I6e8efa6df47ee94f1d71a63e22ab121647e6bf20 Reviewed-by: David Faure <david.faure@kdab.com>
* Mark all of Qt as free of Q_FOREACH, except where it isn'tMarc Mutz2023-08-195-0/+9
| | | | | | | | | | | | | | | | | | | | | | The density of Q_FOREACH uses in this and some other modules is still extremely high, too high for anyone to tackle in a short amount of time. Even if they're not concentrated in just a few TUs, we need to make progress on a global QT_NO_FOREACH default, so grab the nettle and stick to our strategy: Mark the whole of Qt with QT_NO_FOREACH, to prevent new uses from creeping in, and whitelist the affected TUs by #undef'ing QT_NO_FOREACH locally, at the top of each file. For TUs that are part of a larger executable, this requires these files to be compiled separately, so add them to NO_PCH_SOURCES (which implies NO_UNITY_BUILD_SOURCES, too). In tst_qglobal.cpp and tst_qcollections.cpp change the comment on the #undef QT_NO_FOREACH to indicate that these actually test the macro. Task-number: QTBUG-115839 Change-Id: Iecc444eb7d43d7e4d037f6e155abe0e14a00a5d6 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Correct some testlib selftest data: blacklisted does not qFatal()Edward Welbourne2023-07-312-6/+3
| | | | | | | | | The blacklisted test does not crash, as its expected output indeed shows. Pick-to: 6.5 6.6 Change-Id: I07522a7d065b5f39620975a3546bcd156024c41d Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* tst_selftests: Fix mistaken early return when checking error outputTor Arne Vestbø2023-07-311-1/+9
| | | | | | | | | | | | | | | | | | In porting the selftest machinery to Catch2 in 24e83de8d192 we accidentally added an unconditional early return when determining whether to check for unexpected stderr output, resulting in not checking error output on any platform. The return statement has now been moved into the Q_CC_MINGW condition, but as we now seem to have similar issues on macOS and Linux with some of the tests outputting "Received signal 6 (SIGABRT)" as we do for QEMU, we need to add a few more explicit early return conditions to the function. Pick-to: 6.5 6.6 Change-Id: I7a25f000843b5f1003a5db883f08285185046b46 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* tst_QAbstractItemModelTester: fix mem-leakMarc Mutz2023-07-181-0/+1
| | | | | | | | | | | | | QThreeWidgetItems that have been removed from their parents (or the widget) must be deleted manually. The treeWidgetModel() test forgot that, driving asan nuts. Code predates the beginning of the public history, so picking to all active branches. Pick-to: 6.6 6.5 6.2 5.15 Change-Id: I139549b0bd8baf4abfb90f926f6290119471046f Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QCOMPARE: restore compatibility with braced-init-listsGiuseppe D'Angelo2023-07-077-37/+71
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | a611a9f537f1187825339c2a2214c8ec4a23680f (in Qt 5) added support for mixed-type comparisons through QCOMPARE. That commit added a new overload for qCompare taking two types, T1 and T2; but it also left the same-type qCompare(T, T) overload around, guarded by a Qt 6 version check. The mixed-type version is however not a generalization of the same-type one, because it won't work if one of the arguments doesn't participate in FTAD. Case in point: braced-init-lists. In Qt 5 this worked: QCOMPARE(some_container, {42}); but in Qt 6 it does not work any more. The mixed-type overload fails deduction (can't deduce T2); in Qt 5 the same-type overload deduced T=SomeContainer, and {42} was used to select a constructor for SomeContainer. -- There's a partial, straightforward workaround for this: default T2 to T1 in the mized-type overload. In that case T2 has a "fallback" if it cannot be deduced. This is partial because of course doesn't address the case in which T1 cannot be deduced, but I don't think that is common at all. QList is special here, because it has qCompare overloads that makes it comparable with arrays, initializer lists and more. I don't like that very much -- we should probably have a qCompare(input_range, input_range) overload, but that's an exercise for C++20. Change-Id: I344ba33167829984978cd8d649a1904349a9edab Pick-to: 6.5 6.6 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Milian Wolff <milian.wolff@kdab.com> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* CMake: Make qtbase tests standalone projectsAlexandru Croitor2023-07-054-0/+24
| | | | | | | | | | | | | | | | | Add the boilerplate standalone test prelude to each test, so that they can be opened with an IDE without the qt-cmake-standalone-test script, but directly with qt-cmake or cmake. Boilerplate was added using the following scripts: https://git.qt.io/alcroito/cmake_refactor Manual adjustments were made where the code was inserted in the wrong location. Task-number: QTBUG-93020 Change-Id: I77299f990692b4fe4721a9bc35071608d0d23982 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io>
* selftests: tst_sleep, don't start timer twiceAhmad Samir2023-06-301-1/+0
| | | | | | | Typo from a previous commit. Change-Id: I88cd5c4497d17393615a390428134fd1c710e1f8 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTest: add qSleep(std::chrono::milliseconds) overloadAhmad Samir2023-06-302-7/+12
| | | | | | | | | Using chrono means one can write 10s instead of 10'000. [ChangeLog][QTest] Added qSleep(std::chrono::milliseconds) overload. Change-Id: Iac1b12a3fc3f692b557e2d459e6f3bc565f20e93 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QTest: port qSleep() to std::this_thread::sleep_forAhmad Samir2023-06-272-7/+18
| | | | | | | | | | | As requested in code review. Big improvement, code-wise. tst_Sleep::wait() was failing on the CI, so be more accurate by using QElapsedTimer::durationElapsed(), which returns nanoseconds. Pick-to: 6.6 Change-Id: I5bed6d6bd768adfdecab2475e6cbe245c20aabd7 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Move the formatting of <chrono> durations to QDebug & QtTestThiago Macieira2023-05-063-0/+158
| | | | | | | | | | | | [ChangeLog][QtCore][QDebug] Added pretty formatting of C++ <chrono> durations. [ChangeLog][QtTest] Added pretty formatting of C++ <chrono> durations for QCOMPARE expressions. Change-Id: I3b169860d8bd41e9be6bfffd1757cc087ba957fa Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Suppress a redundant GCC warningAhmad Samir2023-05-041-0/+4
| | | | | | | The test is accessing an out of bounds index into an array on purpose. Change-Id: I23cce4093fdfabd177eb34639f26fcd6752c8b34 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* Rid of 'special case' markersAlexey Edelev2023-04-132-2/+2
| | | | | | | | | | | It's unlikely we will ever use pro2cmake at this project stage, so it doesn't make any sense to keep the 'special case' markers in the CMake scripts. Remove them and replace with TODO where needed. Change-Id: I84290c20679dabbfdec3c5937ce0428fecb3e5a7 Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* Testlib: fix the last few s/Q_OS_MAC/Q_OS_DARWIN/wEdward Welbourne2023-03-201-2/+2
| | | | | Change-Id: I6fe6a865aea37c6a2d153bd2c3aace5242362c88 Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de>
* Silence some conversion warningsAmir Masoud Abdol2023-03-104-4/+4
| | | | | | Change-Id: I3087bff60e77c0eaa5818a5405c97628ce7f6b79 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QTest: Rename QCOMPARE_XX parameters to add meaningMårten Nordheim2023-03-086-1080/+1080
| | | | | | | | | | | | | | | The parameter names were previously "lhs" and "rhs", which is incredibly abstract for a testing framework. One of the parameters will tend to be a baseline value to compare against while the other is the result of some action we want to test. Thus I suggest they be renamed "computed" and "baseline". This way we can, hopefully, retain the semantic that the 'left'/first argument is the computed ('actual' in QCOMPARE) value while the 'right'/second argument is the baseline ('expected' in QCOMPARE.) Change-Id: I3e0fdce2a3f1faca06fdf7184ef6e0eb9724d990 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Doc: fix link to QTest::failOnWarningVolker Hilsheimer2023-03-051-1/+1
| | | | | | | | | Also fix incorrect failOnWarning*s* elsewhere in comments. Pick-to: 6.5 6.5.0 Change-Id: I0bbc5e71060348153876f3d9a7c77c67f3c2e00d Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* QTestEventLoop: add enterLoop(std::chrono::milliseconds) overloadAhmad Samir2023-03-031-4/+6
| | | | | | | Task-number: QTBUG-110059 Change-Id: Ibf1d76afd313e390103be4a22e44af7fb41ace1b Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* tst_benchlibcallgrind: silence a compiler warningAhmad Samir2023-02-261-1/+1
| | | | | Change-Id: I68cc530fa8eaf941a6ddb7e6987ff37ec270bc4d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* tests: Remove remains of qmake conversion from CMakeLists.txt filesFriedemann Kleint2023-02-1760-345/+112
| | | | | | | Pick-to: 6.5 Change-Id: I8d106554bb86ac1ec9bb7a4083de4c376bcbab1d Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* tst_Selftests: rewrite this with templates instead of macroThiago Macieira2023-01-121-33/+41
| | | | | | | Otherwise it's undebuggable. Change-Id: I3c79b7e08fa346988dfefffd171ee81fefde63b0 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Adapt to QTimeZone replacing Qt::TimeSpec usageEdward Welbourne2022-12-101-2/+5
| | | | | | | | | | | | In the process actually handle all time-spec cases in various places that only handled UTC or LocalTime, or at least note that they don't where that's not practical. Also tidy up header ordering and ensure QDateTime's header is included wherever it's used, while adding the include for QTimeZone where needed. Task-number: QTBUG-108199 Change-Id: Ic1a5cdf0aaf737bf1396aa8ac58ce2004cef7e19 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Use QString/QByteArray range erase()Ahmad Samir2022-12-071-5/+7
| | | | | Change-Id: I0fb81306ebe8fc7acd63bb62dc6720c734461da0 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Port from container::count() and length() to size() - V5Marc Mutz2022-11-032-28/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This is a semantic patch using ClangTidyTransformator as in qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to handle typedefs and accesses through pointers, too: const std::string o = "object"; auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); }; auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) { auto exprOfDeclaredType = [&](auto decl) { return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o); }; return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes)))); }; auto renameMethod = [&] (ArrayRef<StringRef> classes, StringRef from, StringRef to) { return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)), callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))), changeTo(cat(access(o, cat(to)), "()")), cat("use '", to, "' instead of '", from, "'")); }; renameMethod(<classes>, "count", "size"); renameMethod(<classes>, "length", "size"); except that the on() matcher has been replaced by one that doesn't ignoreParens(). a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'. Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache, to avoid porting calls that explicitly test count(). Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Update Catch2 to v2.13.10Marc Mutz2022-10-172-12/+18
| | | | | | | | | | | Two patches applied to upstream release. Pick-to: 6.4 6.2 Fixes: QTBUG-103321 Task-number: QTBUG-99122 Change-Id: Ief451a21e5f61851cb03a9ca94ffe0f864e4b1f8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>