Commit Graph

1613 Commits (ce33e476670c82bdf50344f4ab9bdbb17e6feaea)

Author SHA1 Message Date
Aleix Pol 244964d06a testlib: Integrate the new object type in the unit testing system
It seems like all subclasses of QAccessibleEvent need to be registered
here, otherwise tests explode.

Change-Id: I924961f351bda1f50e2c73d54abe4b51162dc82a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-05-31 05:13:50 +02:00
Jesus Fernandez 7c128f8866 Add -Wweak-vtables to headersclean
This requires some fixes in several classes that are also included
in this patch.

The QTestEvent hierarchy is all-inline and changes layout depending on
QT_GUI_LIB and QT_WIDGETS_LIB, so we can't just export it. Suppress the
warning in that header for now. Created QTBUG-104486 to track a fix for
the real issue.

The QFutureInterface hierarchy is also all-inline, but templates, so
doesn't trigger, except the <void> specialization. Created
QTBUG-125115 to track a fix for the real issue.

Done-with: Marc Mutz <marc.mutz@qt.io>
Task-number: QTBUG-45582
Change-Id: I96b3e109aa989b70e0d4809b90bd53a369e50d55
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2024-05-19 15:56:17 +00:00
Marc Mutz 672afb13ca QSignalSpy: make sig member const
Previously, the sig member was used to indicate successful
construction of the QSignalSpy (incl. successful connection to the
monitored signal), so it was set only after all other initialization
had taken place, preventing it from being marked as const, which would
indicate that accesses to it need not be protected by the mutex.

Now that we have it, we can instead use the d_ptr's value to indicate
success, and mark sig const.

[ChangeLog][QtTest][Important Behavior Changes][QSignalSpy] The
signal() method no longer necessarily returns an empty byte array when
the connection failed. Use the existing isValid() method to determine
whether a given QSignalSpy object listens to a valid signal on a valid
object.

Change-Id: Ia08fe3b383681f3f203cf1a121c0e1ce08ad268b
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2024-05-16 17:12:14 +02:00
Marc Mutz 46e53117c5 QSignalSpy: make makeArgs() file-static
Now that the private ctor that calls this function is finally
out-of-line, this function need no longer be part of the ABI.

Task-number: QTBUG-123544
Change-Id: Ia4656bf8bfd4d68d6925f93ef150593cd2de6ddf
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2024-05-15 18:22:39 +02:00
Edward Welbourne a2566e139f Extend QTest::failOnWarning() to a no-parameter fail-on-any-warning
Many users (albeit mostly in qtdeclarative) of failOnWarning() are
passing a catch-all regexp, which is only supported when regular
expression support is enabled. Make their lives easier and those
checks independent of the feature by adding a third overload, taking
no parameter, that fails on any (unanticipated) warning.

Implementation is trivial - just put a null QVariant in
failOnWarningList; it won't match either check on the entry that might
exempt a test from failing on a warning, so any warning at all will
trigger failure.

[ChangeLog][QtTest] QTest::failOnWarning() now has a no-parameter
overload to support the common case of fail-on-any-warning, without
needing to construct a match-everything regular expression.

Change-Id: Ic693f1c8619fd6e495543b85737d566134cf9d20
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
2024-05-06 20:27:41 +02:00
Andreas Eliasson f8bc0e7c3b Doc: Remove \note that indicates you can access the source code
There used to be an examples page; this is no longer the case. Thus,
remove the \note that indicates you can access the source code.

Fixes: QTBUG-122166
Pick-to: 6.7 6.6 6.5
Change-Id: I1abe88000ae406e8d2cc9cc1deed42664607626b
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
2024-04-29 17:38:52 +02:00
Marc Mutz ab0b2a490e QSignalSpy: fix -Wweak-vtable by removing the QObject inheritance
Normally, we'd fix -Wweak-vtable by exporting the class and making at
least one virtual method out-of-line (typically the dtor), thereby
pinning the vtable to exactly one TU.

We can't export QSignalSpy, though, because it also inherits QList,
and we don't want to export QList subclasses to avoid QList API
becoming part of the ABI.

So remove the vtable, and therefore its being a weak symbol, by moving
the qt_metacall implementation from QSignalSpy into its newly-added
Private, at the cost of an additional memory allocation at
construction (though there was already the wish to make this class
pimpl'ed for extensibility, and this patch accomplishes exactly that).

This class used to be one of few places left that prevents adding
-Wweak-vtable to headersclean, so while this is a breaking change,
QSignalSpy doesn't really model is-a QObject. It uses QObject to
reuse, not to be reused. In fact, no external code should use the
QObject-ness of QSignalSpy, so it should be an acceptable SC break to
drop the inheritance.

We don't need to care about BC here, as we don't promise BC for
QtTest.

This now also allows (and requires) to make the dtor and the private
ctor out-of-line, avoiding the need for the init() hack.

[ChangeLog][QtTest][Potentially Source-Incompatible Changes]
QSignalSpy no longer inherits from QObject. If your code uses the fact
that QSignalSpy is-a QObject, you need to redesign around this now.

Task-number: QTBUG-45582
Fixes: QTBUG-123544
Change-Id: Id93ba0ee6bbb811455d3744a045e38e1b9f9c584
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Jason McDonald <macadder1@gmail.com>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2024-04-29 09:23:50 +02:00
Thiago Macieira 15eb9dccae QTest::test*Operators: test reverse order too
There's no need to condition that comparison only for heterogeneous
types. The reverse comparisons will compile if the types are homogeneous
(it's what we had already tested), but this now ensures the results are
also the expected ones.

Change-Id: If1bf59ecbe014b569ba1fffd17c4a2dd756157b2
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2024-04-27 21:35:38 +00:00
Thiago Macieira f7e9bb7783 QTest: replace the majority of the ugly QCOMPARE_xx macro
Using templates to make the code look nicer and be more debuggable.
Previously, if you tried to step into the QCOMPARE_xx, you'd have the
creations of qxp::function_ref from the lambdas before you got to the
actual comparison. And all of this was in-place from macro expansion, so
you couldn't tell what was happening.

Now, if you step into QCOMPARE_xx, you go to qCompareOp. There are 5
frames between that point and the actual comparison (four std::forward()
and the Compare::compare()) and debuggers could step over std::forward.
Even if they can't, both libstdc++ and libc++ implementations are simple
casts, so there's nothing more to step into.

Change-Id: I12a088d1ae424825abd3fffd171dbbf7adb7e7e2
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-04-26 18:19:36 +02:00
Thiago Macieira 0756cc1eae QTest: rip out qxp::function_ref from compare_helper()
[ChangeLog][QtTest] The QCOMPARE_xx macros can now only find
QTest::toString() expansions that are either found via Argument
Dependent Lookup on the type in question or are an instatiation of the
QTest::toString<T>() template. This matches the behavior of the
QCOMPARE() macro.

This changes the way how the toString() overloads are selected, so
we need to explicilty constraint the main QTest::toString() template
in order to pick the free functions when they exist.

Change-Id: Ie28eadac333c4bcd8c08fffd17c54e768c5cffd0
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2024-04-26 18:19:36 +02:00
Thiago Macieira c14f399d2a QTest: rip out qxp::function_ref from reportResult()
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>
2024-04-26 18:19:36 +02:00
Thiago Macieira 4ae6f40b3a QTest: group all the toString() functionality in a single header
It was split between qtest.h and qtestcase.h, so the QTest::toString()
specializations were not available in qtestcase.h. And it was confusing.

Change-Id: Ie28eadac333c4bcd8c08fffd17c54fafc8014cc7
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-04-26 18:19:36 +02:00
Thiago Macieira b7fb9d8150 QTest: add removed_api.cpp and move deprecated functions to it
QtTest is not under the same Binary Compatibility guarantees as the
other modules, but let's try and do it where it's easy.

The toString() method can simply be removed from the header because it's
not a member function. Its deprecation wasn't marked with a version
number, so it starts now with 6.8.

Change-Id: Ie28eadac333c4bcd8c08fffd17c54faca7057b9c
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2024-04-26 18:19:36 +02:00
Lucie Gérard ecc9516d15 Correct license of qsignalspy.cpp
When 7bff20c9f5 renamed the file from
.qdoc to .cpp, it failed to adjust the license header from GFDL
(documentation license) to the QtTest default.

Copy the license from qsignalspy.h, whence the code originally came
from.

Task-number: QTBUG-121787
Change-Id: I969ddc2b92882107581bbd514a28af7337e0fb9a
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2024-04-26 15:37:55 +00:00
Marc Mutz e061491209 QSignalSpy: inline connectToSignal() into its only caller
Following the verify() Extract Method refactorings, this function has
only one caller left, so it doesn't pull its weight anymore.

Task-number: QTBUG-123544
Change-Id: I93a296a9be81ef9c3b702065e76ecc4b822a0a43
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-26 01:45:56 +02:00
Marc Mutz 51e0a33a54 QSignalSpy: de-inline most of the private ctor
... by moving its body into an out-of-line init() function.

This allows to drop the exporting of connectToSignal().

We can't de-inline the whole ctor (yet), because that would pin the
vtable to the qsignalspy.cpp TU, which would require us to export the
class wholesale to make the vtable accessible to users of the class,
but we can't export the class because it inherits QList.

Task-number: QTBUG-123544
Change-Id: Ieffd6d2f542daa20e876c6114cb5dc8150870bb4
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2024-04-26 01:45:55 +02:00
Marc Mutz 46ad7fe966 QSignalSpy: make args member const
This means it's implicitly thread-safe now and we don't need to
protect accesses to it with the mutex.

Task-number: QTBUG-123544
Change-Id: I9f826003dca6fb81e7a75e283482c81ecff09be0
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2024-04-24 22:34:14 +02:00
Marc Mutz 951bf6e3ec QSignalSpy: make two private static helpers file-static
... because they can be.

As a drive-by, fix clazy-function-args-by-value by taking QMetaMethod
by value.

Task-number: QTBUG-123544
Change-Id: Icdad68b91850d284c918e6180f3ce841de2af016
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2024-04-24 22:34:01 +02:00
Marc Mutz 47f5c21e1b QSignalSpy: pull makeArgs() out of ctor critical section
First store the result in a temporary, and, in the critical section,
only move it into place. This minimizes the amount of code in the
critical section (Amdahl's Law) and also means we don't need to
permanently drop the mutex when we call unbounded code using
metacall(). That, in turn, makes sure the args member is only ever
seen empty or fully populated.

Since makeArgs() no longer accesses member functions now, we can make
it static.

Task-number: QTBUG-123544
Change-Id: If19db53f85d7c9eb18d4fb2c61e1aa3d4b9c2e00
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: David Faure <david.faure@kdab.com>
2024-04-24 20:32:35 +00:00
Marc Mutz d6c7b0c2bc QSignalSpy: make initArgs() return the result
... instead of working directly on the member variable.

This is in preparation of making said member variable const, so it
need no longer be protected by the mutex.

Task-number: QTBUG-123544
Change-Id: Ifc407502ec2c5c52dc3b42edea18be7fc672a968
Reviewed-by: David Faure <david.faure@kdab.com>
2024-04-24 22:32:15 +02:00
Marc Mutz 8ab63278ef QSignalSpy: de-inline chrono wait()
Because we can now that there's a .cpp file.

Task-number: QTBUG-123544
Change-Id: Ie525e157016cb3c0c7a273fba3fadb13d54c1877
Reviewed-by: David Faure <david.faure@kdab.com>
2024-04-24 21:36:49 +02:00
Marc Mutz ad755020e1 QSignalSpy: de-inline verify() helper functions
Now that we're moving the code anyway, also move their declarations
into the general private: section of the class.

Task-number: QTBUG-123544
Change-Id: I6b1e7006b73b710daa4b511b2fd643293a3d4844
Reviewed-by: David Faure <david.faure@kdab.com>
2024-04-24 21:36:49 +02:00
Marc Mutz 88b5b1bce9 QSignalSpy: de-inline private helpers
Reduces the code a compiler including qsignalspy.h needs to parse and
codegen.

The order of the functions in the .cpp file is chosen to minimize the
diffs to follow-up changes.

We can't de-inline the private ctor, because that would pin the vtable
to the qsignalspy.cpp TU, which would require us to export the class
wholesale to make the vtable accessible to users of the class, but we
can't export the class because it inherits QList.

Task-number: QTBUG-123544
Change-Id: Ib26fdb68e1fc0e6f6919e4cd25759b7047f9977c
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-24 21:36:49 +02:00
Marc Mutz d2436f7294 QSignalSpy: make verify() methods static
... because they can be. We call them without a value object and while
they don't touch *this, ubsan complained (rightfully):

  qsignalspy.h:29:28: runtime error: member call on address 0x7ffdfaab2b20 which does not point to an object of type 'QSignalSpy'
   0x7ffdfaab2b20: note: object has invalid vptr
    00 00 00 00  00 00 00 00 00 00 00 00  00 2b 00 00 c0 60 00 00  60 14 00 00 60 60 00 00  70 14 00 00
                 ^~~~~~~~~~~~~~~~~~~~~~~
                 invalid vptr

Amends e68edd6a07.

Task-number: QTBUG-123544
Change-Id: I8e9ba3270a35777a704e68130d2f2bccb658a536
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2024-04-18 11:31:01 +02:00
Tor Arne Vestbø d5bf42f75b Add preliminary support for Qt for visionOS
Qt already runs on Vision Pro as "Designed for iPad", using Qt
for iOS. This change enables building Qt for visionOS directly,
which opens the door to visionOS specific APIs and use-cases
such as volumes and immersive spaces.

The platform removes some APIs we depend on, notably UIScreen,
so some code paths have been disabled or mocked to get something
up and running.

As our current window management approach on UIKit platforms
depends on UIWindow and UIScreen there is currently no way to
bring up QWindows. This will improve once we refactor our
window management to use window scenes.

To configure for visionOS, pass -platform macx-visionos-clang,
and optionally add -sdk xrsimulator to build for the simulator.

Change-Id: I4eda55fc3fd06e12d30a188928487cf68940ee07
Reviewed-by:  Alexey Edelev <alexey.edelev@qt.io>
2024-04-18 05:00:57 +02:00
Giuseppe D'Angelo 7466831509 Long live [[nodiscard]] QFile::open
Having already caught some bugs in real code because of unchecked calls
to QFile::open, this commit marks QFile::open (and open() in other
file-I/O classes) as [[nodiscard]].

Since it's going to raise warnings, the plan is to keep the existing
behavior up to and including the next LTS. Then the warnings will switch
on by default. All of this is protected by system of macros to opt-in or
opt-out the behavioral change at any time.

A possible counter-argument for doing this is that QFile::open is also
used for opening files in the the resource system, and that opening
"cannot fail". It clearly can, if the resource is moved away or renamed;
code should at a minimum use a Q_ASSERT in debug builds. Another
counter-argument is the opening of file handles or descriptors; but
again, that opening may fail in case the handle has been closed or if
the flags are incompatible.

---

Why not marking *every* open() override? Because some are not meant to
be called directly -- for instance sockets are supposed to be open via
calls to `connectToHost` or similar.

One notable exception is QIODevice::open() itself. Although rarely
called directly by user code (which just calls open() on a specific
subclass, which likely has an override), it may be called:

1) By code that just takes a `QIODevice *` and does something with it.
   That code is arguably more rare than code using QFile directly.
   Still, being "generic" code, they have an extra responsibility when
   making sure to handle a possible opening failure.

2) By QIODevice subclasses, which are even more rare. However, they
   usually ignore the return from QIODevice::open() as it's
   unconditionally true. (QIODevice::open() doesn't use the protected
   virtual pattern.)

I'll try and tackle QIODevice in a future commit.

[ChangeLog][QtCore][QFileDevice] The open() functions of file-related
I/O classes (such as QFile, QSaveFile, QTemporaryFile) can now be marked
with the "nodiscard" attribute, in order to prevent a category of bugs
where the return value of open() is not checked and the file is then
used. In order to avoid warnings in existing code, the marking can be
opted in or out, by defining QT_USE_NODISCARD_FILE_OPEN or the
QT_NO_USE_NODISCARD_FILE_OPEN macros. By default, Qt will automatically
enable nodiscard on these functions starting from Qt 6.10.

Change-Id: Ied940e1c0a37344f5200b2c51b05cd1afcb2557d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2024-04-17 20:07:47 +02:00
Marc Mutz 7bff20c9f5 QSignalSpy: prepare for de-inlining
Rename qsignalspy.qdoc to .cpp, include qsignalspy.h and add the
namespace macros.

Task-number: QTBUG-123544
Change-Id: Ibd89844018afc277e6a69e7200cdbd08befd4da2
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-16 11:01:31 +02:00
Giuseppe D'Angelo 62e91d0025 QBenchmark: abort if we can't open the output file
Change-Id: I6391bb8e6fb0a336d1df82c30eb07ec931cfc053
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2024-04-04 12:24:18 +01:00
Mitch Curtis d72d7945d4 QTest: expose API needed for Qt Quick Test to print crash backtraces
As discussed in QTQAINFRA-6146, there were two potential approaches to
enabling backtraces in Qt Quick tests:

- Either via a thorough refactoring of quicktest.cpp so that each
testcase is a Slot in a programmatically-created QObject-derived class,
which will be executed via QTest::qExec() similar to the documented
QTest way. This way the pre-existing code in QTest::qRun() will setup
the fatal signal handler.
- Or as a quick fix, modify quick_test_main_with_setup() to setup a
FatalSignalHandler class and invoke prepareStackTrace() like it's
already done in QTest::qRun(). This would require exporting these
symbols in the private header.

This patch enables the implementation of the latter, as it has a
fairly light footprint, is easily revertable (should we need to),
and allows us to immediately gain insight into crashes in CI.

Task-number: QTQAINFRA-6146
Change-Id: Iedffc968acb3e570214df34884ab0afcb6b30850
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2024-04-04 14:09:03 +08:00
Mitch Curtis c0014becca QTest: move crash-handling code out into qtestcrashhandler_p.h
In preparation for reusing it in Qt Quick, which currently doesn't
print backtraces upon crashes.

Task-number: QTQAINFRA-6146
Change-Id: Ib0384f514b348a398f53529ff3bcc7d4ac2daba7
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
2024-04-04 14:08:57 +08:00
Marc Mutz b4c5887939 QSignalSpy: inline verify(obj, func) into the only caller
First, realize that we don't need the isObjectValid() call, because
that's done by verify(QObject*,QMetaMethod) later.

That leaves said fromSignal() and verify(QObject*, QMetaMethod) calls,
which we can just inline into the (QObject*, Func) ctor, thus making
said constructor SCARY, having extracted all template-independent code
into other functions/ctors.

Task-number: QTBUG-123544
Change-Id: I6b8afc541f75936045e2d28cfde51a34f98a1fdd
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-03-22 15:31:40 +01:00
Marc Mutz d2dbe2d7f7 QSignalSpy: separate messages for invalid and non-signal meta-methods
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>
2024-03-22 15:31:39 +01:00
Marc Mutz fa5cb84069 QSignalSpy: inline init() into its only caller
Following the verify() Extract Method refactorings, this function has
only one caller left, so it doesn't pull its weight anymore,
esp. considering that it'll be exported soon.

Task-number: QTBUG-123544
Change-Id: I1690b4b6e5a0e0c56fcc9c34544fca3b34e2f9a6
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2024-03-22 15:31:39 +01:00
Marc Mutz 2f39027232 QSignalSpy: move signal verification from init() to verify()
... where it belongs.

Amends e68edd6a07.

Task-number: QTBUG-123544
Change-Id: Ic0e5128555465485b579607a61925cefa5f4716d
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2024-03-22 15:31:39 +01:00
Marc Mutz e68edd6a07 QSignalSpy: share more code
Add per-ctor verify() functions that take care of the warnings for
invalid inputs, and return a struct { QObject*; QMetaMethod; } to feed
into a delegatee constructor.

This solves the problem that the varying parts between the ctors are
at the beginning, not the end, using another level of indirection, and
will eventually allow to make the `args` and `sig` members const, and
therefore remove the need to protect either with the mutex.

This patch tries to keep the diff minimal. I'm planning to de-inline
most of the class in a future commit, so it doesn't matter that
private and public sections are interleaved, that will be cleaned up
when the code is moved to a .cpp file later.

Task-number: QTBUG-123544
Change-Id: Idc628c927736880a8fd580089ed5177361c94ed9
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-03-22 02:44:50 +01:00
Marc Mutz edb8bac39b QSignalSpy: Extract Method init() from three ctors
Ideally, this wouldn't be a named function, but a delegatee
constructor, but the current structure of the three constructors
doesn't, yet, lend itself to extracting a delegatee constructor (the
tail is copied, not the head). To get there, we need more work (coming
up in follow-up commits).

Task-number: QTBUG-123544
Change-Id: I46dd030e314d67c2ab624279d669db76e58bc569
Reviewed-by: David Faure <david.faure@kdab.com>
2024-03-21 17:47:32 +01:00
Marc Mutz d5d2688acb QSignalSpy::appendArgs(): move-append the QVariantList
Using the rvalue overload of append() is more efficient, since we skip
the alias check and the appendee's atomic ref-count ping-pong inside
lvalue append().

Pick-to: 6.7
Task-number: QTBUG-123544
Change-Id: Ia76fdf28cba13d524fbbe894658a86a45a1ebe79
Reviewed-by: David Faure <david.faure@kdab.com>
2024-03-21 11:20:49 +01:00
Marc Mutz 3a36fe91ab QSignalSpy: fix clazy-function-args-by-value
Clazy complains that QMetaMethod should be passed by value, so do
that.

Change-Id: I42afda5af6910eefc8783b1feac00fd11e1f017e
Reviewed-by: David Faure <david.faure@kdab.com>
2024-03-21 11:20:49 +01:00
Marc Mutz b97bcdd774 QSignalSpy: use NSDMI for m_waiting
One step closer to DRYing the ctors.

Pick-to: 6.7 6.6 6.5
Task-number: QTBUG-123544
Change-Id: Iff73fe70e3d2de52548d10b2f38a7ba2bd7029cd
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-03-21 02:00:19 +01:00
Marc Mutz a90c3cc3c7 QSignalSpy: fix indexed loop (int instead of qsizetype)
While a signal with more than 2Gi arguments is only a theoretical
possibility, still use the correct index variable for the indexed loop
over this QList<int>.

Pick-to: 6.7 6.6 6.5
Change-Id: I2ed33238c2cd9d2d1c39cd29c988a2adfd821897
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-03-20 21:23:39 +01:00
David Faure e46f99fdaa QSignalSpy: make the mutex a member variable
The static inline was only a workaround for maintaining BC within
minor releases while backporting the fix. Since we don't promise BC for
QtTest between minor releases, we can make the mutex a proper member
variable for Qt 6.8.

Amends c837cd7593.

Change-Id: I0d6353bdd6a11daa4f927139abf9a867d8c9f95f
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2024-03-19 20:09:37 +00:00
Marc Mutz 7565034aad QSignalSpy: fix C'n'P mistake in a qWarning()
The warning for the new-style signal constructor was copied from the
old-style signal constructor, but not adjusted to its new home. The
signal pointer passed here is not the signal "name", but a signal
"pointer" (-to-member-function, but no need to go into that much
detail).

Amends 6fc7d76e73, but not picking to
very strict LTS branches, just in case someone has a
QTest::ignoreMsg() installed on it.

Pick-to: 6.7 6.6 6.5
Change-Id: Ia1f6b7001f38202ac72f9945c4a822d81562cdbf
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-03-19 21:09:37 +01:00
David Faure c837cd7593 QSignalSpy: fix data race between wait() and emit from another thread
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>
2024-03-19 00:55:15 +01:00
Paul Wicking 08e6d4b43d QDoc: Drop default arguments from some \fn documentation strings
In the \fn commands for a limited number of methods in the
documentation for Testlib and Widgets, `= 0` is passed as default
argument instead of `= Qt::KeyboardModifiers()`. Until QDoc with Clang
17, inclusive, QDoc generated the correct signature. However, with
Clang 18, QDoc outputs `= 0` in the documentation. While strictly
speaking still correct, this change impacts the documentation
negatively in terms of readability.

Dropping the default argument from the \fn command ensures that QDoc
generates the right signature with both Clang 17 and Clang 18.

Task-number: QTBUG-123130
Pick-to: 6.7
Change-Id: I94ccec2f2c9a02241095fb5b18feb74aa55f97e1
Reviewed-by: Andreas Eliasson <andreas.eliasson@qt.io>
Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
2024-03-13 15:43:10 +01:00
Ahmad Samir 7cf39bd785 Port to QDirListing
Use QDirListing in the Bootstrap build instead of QDirIterator.

Drive-by changes:
- more const variables
- use emplace_back() instead of append() where appropriate

Change-Id: Ie1f0d03856e557c4bfabfff38a87edc7da86d091
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2024-03-03 14:02:07 +02:00
Lucie Gérard 1556a3a5eb Correct doc snippet license
All file under doc/snippet should be
license as Documentation snippets
and according to QUIP-18 [1]
this is LicenseRef-Qt-Commercial OR BSD-3-Clause

[1]: https://contribute.qt-project.org/quips/18

Pick-to: 6.7
Task-number: QTBUG-121787
Change-Id: I76eedfb6b15c4091f726a5652e3530001d7cdaf7
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-02-28 19:15:51 +01:00
Lucie Gérard 0fd636d7cc Change license in files to avoid LGPL and non-LGPL license mix
According to QUIP-18 [1], all module files should be
LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
or
LicenseRef-Qt-Commercial OR GPL-3.0-only
LGPD and non-LGPL licenses should not be mixed in a
given directory.
The files in this patch are the only ones in their directory
with non-LGPL license.
The license is changed to that of the other module files
in the same directory.

[1]: https://contribute.qt-project.org/quips/18

Pick-to: 6.7
Task-number: QTBUG-121787
Change-Id: Id58248a6f60438e01e77e9448f07e3057d173260
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2024-02-20 16:22:28 +01:00
Volker Hilsheimer a8da9829dc QTest: rename local `timeout` variable in QTRY_IMPL macro
`timeout` is a likely name for a variable in the scope in which a
QTRY_ macro is used, so don't use that name in the macro itself. The
other variables are all prefixed with `qt_test_`, so do that here as
well, and be explicit about what the variable stores.

Amends d4bb448cdd.

Task-number: QTBUG-121746
Change-Id: If05dccdc24a66e95a08156b820d185f184783ad6
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2024-02-09 15:11:50 +01:00
Ahmad Samir 9e64088729 Qttestlib-manual.qdoc: fix typo in API docs
Change-Id: I7865afbdaed266edfb54866cddacc6d6e5ab725c
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2024-02-08 13:03:50 +02:00
Marc Mutz d4bb448cdd QTest: allow passing chrono literal as QTRY_ timeout
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>
2024-02-07 12:15:09 +00:00