summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools
Commit message (Collapse)AuthorAgeFilesLines
...
* Fix qHash(qfloat16) to match Qt 6.4 behaviorMarc Mutz2023-09-121-6/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There were two problems: - On platforms where QFLOAT16_IS_NATIVE == true, a qHash(qfloat16{}) call has become ambiguous between the three FP qHash() overloads (float, double, long double), where it was unambiguously calling the float one in Qt 6.4. This SiC was caused by the replacement of operator float() by operator __fp16() in 99c7f0419e66692260be56c0385badeacb3f6760, which is in Qt 6.5. - On platforms where QFLOAT16_IS_NATIVE == false, qHash(qfloat16{}) would produce a different value from qHash(float{}), and therefore Qt 6.4, when the seed was != 0, because the former would go via the one-arg-to-two-arg qHash adapter while the latter one would not. Since participating functions are inline, this causes old and new code to produce different hash values for the same qfloat16, leading to a BiC possibly corrupting QHash etc. Fix both by adding an explicit qHash(qfloat16). This function is inline, so it doesn't add a new symbol to 6.5.x. [ChangeLog][QtCore] Fixed qHash(qfloat16) which was broken from 6.5.0 to 6.5.3, inclusive. If you compiled against one of the affected Qt versions, you need to recompile against either Qt 6.4 or earlier or 6.5.4 or later, because the problematic code is inline. Pick-to: 6.6 6.5 Fixes: QTBUG-116064 Fixes: QTBUG-116076 Change-Id: Id02bc29a6c3ec463352f4bef314c040369081e9b Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* tst_QHashFunctions: fix std::pair test to use QFETCH_GLOBAL seedsMarc Mutz2023-09-081-6/+0
| | | | | | | | | | | | | | | | Because the local `seed` variable shadowed the member one, this test was run for each QFETCH_GLOBAL with the same data and seed. That doesn't make sense, so make the test use the member variable `seed`, as all other tests already do. Since zero is one of the seeds coming from QFETCH_GLOBAL, drop the seedless calls to qHash(), too. Amends 64bfc927b09b46bb7fc0dc6caf1bf1a4d4133ab4. Pick-to: 6.6 6.5 6.2 Change-Id: I1e22ec0b38341264bcf2d5c26146cbbcab6e0749 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* tst_QHashFunctions: test with actual 64-bit seedsMarc Mutz2023-09-081-12/+18
| | | | | | | | | | | | | | | | | | | The old code only tested with seed = 0 and seed = 1045982819, the latter being a "random number", which, however, fits into 32-bits. Since Qt 6.0 increased the seed from uint to size_t, amend the test to actually test a seed value with some of the upper half of bits set, too, also in 64-bit mode. While we're at it, also test with each seed's bits flipped for extra coverage. Remove a static assertion that prevented testing seeds with the MSB set. Pick-to: 6.6 6.5 6.2 Change-Id: I5ed6ffb5cabaaead0eb9c01f994d15dcbc622509 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QArrayDataPointer: remove Q_CHECK_PTR in assign(it, it) againDennis Oberst2023-09-071-0/+20
| | | | | | | | | | | | | | | | | | | | | | | This commit reverts 2d77051f9dfd11ae292ad4bac2f28c5f7a0e7f83. When requesting an allocation of size 0, we will actually get a nullptr. qarraydata.cpp: ~~~ if (capacity == 0) { *dptr = nullptr; return nullptr; } This will let the Q_CHECK_PTR trigger falsely. Such an occurrence was initially detected during the cmake_automoc_parser build-step. Found-by: Marc Mutz <marc.mutz@qt.io> Task-number: QTBUG-106196 Pick-to: 6.6 Change-Id: Icb68c5dd518c9623119a61d5c4fdcff43dc4ac5d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QArrayData: make calculateBlockSize() account for the extra null elementThiago Macieira2023-09-032-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of adding it after the block size was calculated. This makes no difference for non-growing (exact) blocks. For growing blocks, this means we take that extra element into account before rounding to the next power of two, instead of after. That results in a change of the thresholds of when a block grows and also what capacity it will contain. For example, for a QString growing to 22-25 elements: Request | Previously | Now | elements | bytes | malloc()ed | capacity() | malloc()ed | capacity() | 22 | 44 | 66 | 24 | 64 | 23 | 23 | 46 | 66 | 24 | 64 | 23 | 24 | 48 | 66 | 24 | 128 | 55 | 25 | 50 | 130 | 56 | 128 | 55 | To avoid wasting elementSize - 2 bytes in this footer, we only include this footer if elementSize <= 2. Thus, for a QList<int> growing to 11-13 elements: Request | Previously | Now | elements | bytes | malloc()ed | capacity() | malloc()ed | capacity() | 11 | 44 | 66 | 12 | 64 | 12 | 12 | 48 | 66 | 12 | 128 | 28 | 13 | 52 | 130 | 28 | 128 | 28 | In both cases, we now only allocate powers of two while growing, which may be beneficial to some allocators. Pick-to: 6.6 Change-Id: Ifa1111900d6945ea8e05fffd177dcb96e251d0a1 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* tst_QFreeList: build with QT_NO_FOREACHAhmad Samir2023-08-191-3/+1
| | | | | | | | | | The container is local to the function, but can't be made const due to the way it's filled. The loop clearly doesn't modify the container so use std::as_const and ranged-for. Task-number: QTBUG-115839 Change-Id: Ia9f01dfaccfca3225fe0487aafd0a386605cf466 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* tests/auto/: port Q_FOREACH to ranged-for, local const containersAhmad Samir2023-08-193-21/+14
| | | | | | | | | | | | | | | | | | | | These are local containers that are either: - Already const and didn't need Q_FOREACH to begin with - Can be simply made const, just by adding const keyword In one case the unittest checked that the container's size is 1, so use list.first() instead of a for-loop. In files where Q_FOREACH isn't used any more, remove "#undef QT_NO_FOREACH". Also remove those files from NO_PCH_SOURCES. Drive-by changes: - Remove parenthesis from one-line for-loops - Make the for-loop variable a const& where a copy isn't needed Task-number: QTBUG-115839 Change-Id: Ide34122b9cda798b80c4ca9d2d5af76024bc7a92 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* Mark all of Qt as free of Q_FOREACH, except where it isn'tMarc Mutz2023-08-195-0/+7
| | | | | | | | | | | | | | | | | | | | | | 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>
* tst_QHashFunctions: extend the consistency() test with int/FP typesMarc Mutz2023-08-161-0/+55
| | | | | | | | | | | | | | | It's ... broken. Found and filed lots of bugs. Add #ifdef'ery and QEXPECTED_FAIL() to document the state of affairs, hopefully reminding us to fix these things come Qt 7. Task-number: QTBUG-116064 Task-number: QTBUG-116076 Task-number: QTBUG-116077 Task-number: QTBUG-116079 Task-number: QTBUG-116080 Pick-to: 6.6 6.5 Change-Id: I29e89fdf995ddf60ef1e03c7af009e80980c9817 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* tst_QHashFunctions: use actual seed in consistent() test functionMarc Mutz2023-08-161-1/+1
| | | | | | | | | | | | | We were only ever testing with a 0 seed, even though the function was called for all QFETCH_GLOBAL seeds. Add the seed. Amends 5e93361888e3d2b03e7b6da19517b44e0239fb47. Pick-to: 6.6 6.5 6.2 5.15 Change-Id: I3c78714ad6fb3f94233789dd2c8884d9b157fa76 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* CMake: remove check for cxx11_futureThiago Macieira2023-08-022-14/+1
| | | | | | | | | | | Everyone must have this by now. This test was 1193 ms of CMake time. Since this was a PUBLIC feature, I've left it around with a constant condition. Change-Id: Ifbf974a4d10745b099b1fffd177754538bbff245 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* tst_QExplicitlySharedDataPointer: Remove stray commentAxel Spoerl2023-07-251-1/+0
| | | | | | | | Remove stray comment at the end of tst_qexplicitlyshareddatapointer.cpp Pick-to: 6.6 Change-Id: I31a6c38002e56e7c43e527864ba3d9324950079f Reviewed-by: Santhosh Kumar <santhosh.kumar.selvaraj@qt.io>
* Long live QSpan!Marc Mutz2023-07-213-0/+373
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | QSpan is Qt's version of std::span. While we usually try not to reimplement std functionality anymore, the situation is different with QSpan. Spans are non-owning containers, so the usual impedance mismatch between owning STL and Qt containers doesn't apply here: QSpan implicitly converts to std::span and vice versa, making STL and Qt APIs using spans completely interoperable. We add QSpan mainly for two reasons: First, we don't want to wait until we require C++20 in Qt and can use std::span. Second, in the view of this author, some design decisions in std::span hurt the primary use-case of spans: type-erasure for containers. This results in two major deviations of QSpan from std::span: First, any rvalue container is convertible to QSpan, allowing seamless passing of owning containers to functions taking spans: void sspan(std::span<T>); void qspan(QSpan<T>); std::vector<T> v(); sspan(v()); // ERROR: rvalue owning container auto tmp = v(); sspan(tmp); // OK, lvalue qspan(v()); // OK This author believes that it's more helpful to have compilers and static checkers warn about a particular wrong usage than to make perfectly valid use-cases impossible or needlessly verbose to code. The second deviation from std::span is that fixed-size span constructors are also implicit. This isn't as clear-cut, because an explicit QSpan{arg} isn't per-se bad. However, it means you can't transparently change from a function taking decltype(arg) to one taking QSpan and back. Since that's exactly what we intend to do in Qt going forward, in the interest of source-compatibility, the ctors are all implicit. Otherwise, the API of QSpan follows the std::span API very closely. Like std::span, QSpan isn't equality_comparable, because it's not clear what equality means for spans (element-wise equal, or (ptr, size)-wise equal?). The major API additions are Qt-ish versions of std API functions: isEmpty() on top of empty() and sliced() instead of subspan(). The (nullary) first()/last() functions (Qt speak for front()/back()) clash with the std::span function templates of the same name, so are not provided. This patch adds QSpan as private API. We intend to make it public API in the future. Pick-to: 6.6 Fixes: QTBUG-108124 Change-Id: I3f660be90eb408b9e66ff9eacf5da4cba17212a6 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Dennis Oberst <dennis.oberst@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QAtomicScopedValueRollback: fix CTAD for Q(Basic)AtomicPointerMarc Mutz2023-07-121-0/+7
| | | | | | | | | | | | | | | We need deduction guides to turn the AtomicPointer template argument (the pointee) into a pointer: QAtomicPointer<int> → QAtomicScopedValueRollback<int*> Extend a test to cover pointers, too. Fixes: QTBUG-115105 Pick-to: 6.6 6.5 Change-Id: Ib416c6a43e4da480b707a0bf6a10d186bbaad163 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* tst_QScopeGuard: test if and how guard in optional<> worksMarc Mutz2023-07-101-0/+21
| | | | | | | | | It's a bit cumbersome, but works, in principle, using CTAD. Pick-to: 6.6 6.5 6.2 Task-number: QTBUG-114200 Change-Id: Ib7354180e870a695a978edabf684aedfcf9d9ecc Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
* CMake: Make corelib tests standalone projectsAlexandru Croitor2023-07-0544-0/+264
| | | | | | | | | | | | | | | | | | 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: I28b6d3815c5f43d2c33ea65764f6f3f8f129eaf3 Reviewed-by: Amir Masoud Abdol <amir.abdol@qt.io> Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Add q20::erase_if(std::vector, pred) and erase(vector, val)Ahmad Samir2023-06-221-16/+8
| | | | | | | | | | INTEGRITY has a pre-P1115 implementation of std::erase/erase_if that returns void instead of the number of erased elements, so make q20's implementation more specialized, so the compiler will pick it over INTEGRITY's (Marc's idea from the code review). Change-Id: I88d025a3f90cdd65f5bb73beb8a39e32ccf12d9b Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* tst_containerapisymmetry: check that std::size() worksMarc Mutz2023-06-091-1/+1
| | | | | | | | | It does. Pick-to: 6.6 6.5 Task-number: QTBUG-112183 Change-Id: Ieddf7764dcb8e145e37e86b9fcd35c19d302ca4f Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QString: add STL-style assign() [2/4]: (it,it) overload for ↵Marc Mutz2023-06-071-0/+2
| | | | | | | | | | | | | | QChar-convertible *it Restrict the permissible value_types to those QStringView can take, plus QLatin1Char. All of these implicitly convert to QChar and give the correct result, even when converted char-by-char. Task-number: QTBUG-106198 Pick-to: 6.6 Change-Id: Icb44244cb08af391161c4309467d4e0d2d3d3d62 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Dennis Oberst <dennis.oberst@qt.io>
* QByteArray: add STL-style assign()Dennis Oberst2023-06-021-0/+1
| | | | | | | | | | | | | | | | | Implemented assign() methods for QByteArray to align with the criteria of std::basic_string, addressing the previously missing functionality. This is a subset of the overloads provided by the standard. Reference: https://en.cppreference.com/w/cpp/string/basic_string/assign [ChangeLog][QtCore][QByteArray] Added assign(). Fixes: QTBUG-106199 Change-Id: I899b14d74e8f774face8690303efb8610ead95b5 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* tst_ContainerApiSymmetry: make assign_impl() more robustDennis Oberst2023-06-011-22/+30
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Refactor the 'CHECK' macro to eliminate the capacity check and explicitly verify that no reallocation occurred. The previous implementation had to pass constants to suppress the issue arising from differing growth rates between implementations. Additionally, improve the 'std::stringstream' versions of the test by incorporating the correct values. In the previous implementation, the usage of: auto tData = V(9); ~~~ std::stringstream ss("9 9 "); had several issues. Firstly, it used the wrong test data since the container's value_type of '(char) 9' resulted in a tab character '\t', which was not accurately reflected in the stringstream assignment. Secondly, this value caused problems in how stringstreams interprets it. To address these issues, let's make the following improvements: 1. Use a default test value of 65 instead of (char) 9. This value, which represents the character 'A', is less likely to cause errors and is more intuitive. 2. Use the tData variable for the assignments in the stringstream. This ensures that the correct data from the container is used. 3. Change the test value between the assign() calls to verify that the container's contents are successfully overwritten. These changes ensure, that the test cases are more accurate and reliable. Amends: 3b0536bbe8d6782f79e1bcc2b4f1925547c14c0b. Change-Id: I9441c4818106bf93e93a1a5d2d2d54c89d80e7b0 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* QVarLengthArray/QList: make assign() return a reference to *thisMarc Mutz2023-05-171-4/+17
| | | | | | | | | | | | | While std::vector::assign() returns void, std::basic_string::assign() returns std::basic_string&. In Qt, we want to be consistent between {QVLA,QList,QString,QByteArray}::assign(), and returning *this is the more general solution, so do that. Task-number: QTBUG-106196 Task-number: QTBUG-106200 Change-Id: I2689b4af032ab6fb3f8fbcb4d825d5201ea5abeb Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QList: re-use the prepend buffer, if any, on assign()Marc Mutz2023-05-171-10/+95
| | | | | | | Task-number: QTBUG-106196 Change-Id: I62d8610529cab528ae1b114d29707133b4fc28dc Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QList: add STL-style assign()Dennis Oberst2023-05-162-0/+69
| | | | | | | | | | | | | | | Implemented assign() methods for QList to align with the criteria of std::vector, addressing the previously missing functionality. Reference: https://en.cppreference.com/w/cpp/container/vector/assign [ChangeLog][QtCore][QList] Added assign(). Fixes: QTBUG-106196 Change-Id: I5df8689c020dafde68d2cd7d09c769744fa8f137 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* tst_ContainerApiSymmetry: fix spacing of template <typenameMarc Mutz2023-05-161-1/+1
| | | | | | | | This file, like the majority of qtbase, uses a space between template and the opening of the template argument list. Add it. Change-Id: I927cb2b1b9620ae108e913343d995373493e8981 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Darwin: Remove QMacAutoReleasePool heap allocation detectionTor Arne Vestbø2023-05-151-21/+0
| | | | | | | | | | This is handled by the Objective-C runtime nowadays, where it will abort if the situation is detected, with the option to break on objc_autoreleasePoolInvalid to debug the situation. Pick-to: 6.5 Change-Id: Idf2c4aacc77e41a3deebf270303f4f13cfb0819b Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Clean up phrasing of --help-all and other help optionsEdward Welbourne2023-05-151-1/+1
| | | | | | | | | | | | | | | | | | The options included by --help-all, although they are "specific to Qt", are "specific" to all Qt applications, so - in the present context, of QCommandLineParser - not specific at all. It's the options described by -h that are specific, to the present command; the Qt options are generic (in the present context). So rework the help string for --help-all itself and the documentation of the function. It had, in any case, an overly-complex first line, that descended into too much detail. Updated test to match. Pick-to: 6.5 Task-number: QTBUG-111228 Change-Id: I06da0af41be60e6e1b7616984001ddb9ca33aad6 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: David Faure <david.faure@kdab.com>
* tst_ContainerApiSymmetry: make assign_impl() robust w.r.t. overallocationMarc Mutz2023-05-131-7/+11
| | | | | | | | | | | | | | The parameter passed to reserve() is just a hint. The container implementation is free to choose a larger capacity, and some do (e.g. QList in prepend optimization mode). Fix the test by querying the container for its post-make<>() capacity() and taking a larger-than-expected initial capacity() into account when later re-checking the capacity(). Change-Id: Id8f26f14e8df9d685ca2387ec4a52d74fea7cb9d Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* tst_ContainerApiSymmetry: make a comment more preciseMarc Mutz2023-05-131-1/+2
| | | | | | | | | | | | It took me a sec to figure out the relation between the comment and the code line following it. Make it easier for the next guy and add a bit more infos. Amends 7cbdc8abbda12488f51317313347bbc220b42fe0. Change-Id: I4ff2d9a52aef643a92339df32cc86f686a689a9a Reviewed-by: Dennis Oberst <dennis.oberst@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* tst_ContainerApiSymmetry: follow file's style for assign() testsMarc Mutz2023-05-131-4/+2
| | | | | | | | | | | | We use a single line per test slot everywhere else, ignoring even line-length limitations, to keep the function names aligned for easier parsing. Amends 7cbdc8abbda12488f51317313347bbc220b42fe0. Change-Id: Iaf2941aae88392d407d688fc4a7537fcdc0a5851 Reviewed-by: Dennis Oberst <dennis.oberst@qt.io> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* tst_ContainerApiSymmetry: fix mutable lambda anti-patternMarc Mutz2023-05-131-1/+2
| | | | | | | | | | | | | | | | | | | | | STL algorithms, in general, don't specify how often the function objects passed to them are copied during the run of the algorithm. While generate_n is above any reasonable suspicion of copying the function object after the first invocation, passing a mutable lambda containing the counter is still an anti-pattern we don't want people to copy. Fix in the usual way, by keeping the counter external to the lambda. As a drive-by, replace post- with pre-increment. Amends dc091e74431acbe66ae7921ba82d3eb34ae8cc55. Pick-to: 6.5 6.2 Change-Id: I9c44e769fd41e5f7157179a2be4c3534424cf913 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Remove unused variablesAmir Masoud Abdol2023-04-191-2/+0
| | | | | | | | | Removing a few unused variables in auto tests that were triggering `-Wunused-but-set-variable`. Pick-to: 6.5 Change-Id: I74bd0d7335d8bddeb18687b18c8a8be965f9fa20 Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
* QMultiHash: fix missing update to m_sizeThiago Macieira2023-04-041-0/+73
| | | | | | | | | | | | | | | | | | | | | QMultiHash has access to two sizes: one of them is shared with QHash, stored in QHashPrivate::Data::size, which counts keys; the other, which is what our public size() function returns, is stored in QMultiHash::m_size and counts plain (key,value) entries. We forgot to update it in the non-const operator[] that created a node. I've reviewed the rest of the code and can't find any more places where the item count may be changed and m_size isn't updated. [ChangeLog][QtCore][QMultiHash] Fixed a bug that caused an element that was created by operator[] to not be counted, resulting in a hash map with an incorrect element count and which could cause an assertion failure depending on how the hash was later mutated. Fixes: QTBUG-112534 Pick-to: 6.2 6.4 6.5 Change-Id: Idd5e1bb52be047d7b4fffffd17527ec274e1d99e Reviewed-by: Lars Knoll <lars@knoll.priv.no>
* Short live QT_ENABLE_P0846_SEMANTICS_FOR!Marc Mutz2023-03-225-0/+117
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | In C++17, unqualified lookup doesn't find function templates that require ADL from a call with explicit template arguments, unless another function template of that name is in scope (otherwise, the < is parsed as operator less-than instead). P0846, merged for C++20, fixes this to repeat the name lookup, parsing the < as indicating a template. We have API in Qt (Tuple Protocol for some types, e.g. QPoint) that work for the purpose of Structured Bindings, but don't work for manual unqualified calls when P0846 semantics are missing, and we're adding more, to QVariant, so add a macro to handle the issue. The macro simply declares a function template overload of the given name for a throw-away struct, thereby bringing, for that one name, P0846 semantics into C++17. When we require C++20, we can drop this again. Amends: - fb6b7869e8bdda94f7e791db7f281f3bb6e0e004 for QPoint(F) - 8ae9431c792f14a32909ac013a1383547d6bcfa8 for QMargins(F) - 0e22001a3bb070d4e9956e89543ec0e5ac6f23f8 for the rest [ChangeLog][QtCore][QSize/F, QMargins/F, QPoint/F] Fixed manual get<I>() calls (Tuple Protocol) in C++17 mode. Task-number: QTBUG-111598 Change-Id: I2ffaef12c5bb6d82f75ce78a7c03c6789dfa0691 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
* tst_QMessageAuthenticationCode: avoid setKey() callsMarc Mutz2023-03-201-4/+2
| | | | | | | | | | We test setKey() in repeated_setKey() these days, so speed up the test of the test suite ever so slightly by passing the key to the ctor instead of an explicit setKey() call. Pick-to: 6.5 Change-Id: Ia2378c0f59cbfa9d95a0f3665b06655332247e2c Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* QCryptographicHash: check addData() with null QByteArrayViewMarc Mutz2023-03-171-0/+23
| | | | | | | | | | | | | | When this code was using QByteArray, whose data() is never nullptr, the strings presented to the underlying C APIs were always valid NTSs (nullptr is not a valid NTS). With QByteArrayView, or with QT5_NULL_STRINGS != 1, this is no longer the case. Check that all implementations are fine with that. Pick-to: 6.5 6.4 Change-Id: I78251288a4784440af4a2daf095aed7c53867287 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QMessageAuthenticationCode: add move SMFs and swap()Marc Mutz2023-03-161-0/+45
| | | | | | | | | | | | QCryptographicHash is move-only these days, so QMessageAuthenticationCode should not be left behind. [ChangeLog][QtCore][QMessageAuthenticationCode] Added move constructor, move assignment operator and swap() function. Fixes: QTBUG-111677 Change-Id: I420f24c04828e8ad7043a9e8c9e7e2d47dd183e0 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Replace ushort*/uint* with char16_t*/char32_t* in private API [1]Ahmad Samir2023-03-151-1/+1
| | | | | | | Task-number: QTBUG-110403 Pick-to: 6.5 Change-Id: Ie20a831f22212d56659cf3c6940d17134ab5f2c5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix tst_qfreelist when build with unityAmir Masoud Abdol2023-03-142-9/+3
| | | | | | | | | | | | Previous setup of the test was failing in minimal static build if built using the unity build because of the explicit inclusion of the qtcore source files. In order to resolve this, I removed the inclusion of qtcore's headers and made the test private. Pick-to: 6.5 Task-number: QTBUG-109394 Change-Id: Id1c7b3b65ca2078354c235a718ff3e93a65362e6 Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
* QThread: add sleep(std::chrono::nanoseconds) overloadAhmad Samir2023-03-132-3/+3
| | | | | | | | | | | | | | All the other overloads are implemented using the new one. Windows change relies on the pre-check in the code review making sure it compiles. [ChangeLog][QtCore][QThread] Added sleep(std::chrono::nanoseconds) overload. Task-number: QTBUG-110059 Change-Id: I9a4f4bf09041788ec9275093b6b8d0386521e286 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* Fix overflow in SHA-3/KeccakMårten Nordheim2023-03-101-0/+29
| | | | | | | | | | | | state->rate is always larger than or equal to state->bitsInQueue; when bitsInQueue == rate the queue is consumed and bitsInQueue is set to 0 again. Done-with: Marc Mutz <marc.mutz@qt.io> Pick-to: 6.5.0 6.5 6.4.3 6.4 6.2 5.15 Change-Id: I56d268a19fb3cd542cc027edc962253f09d97a14 Reviewed-by: Marc Mutz <marc.mutz@qt.io> Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
* tst_QCryptographicHash: Extract Method ensureLargeData()Marc Mutz2023-03-091-1/+11
| | | | | | | | ... to make large data usable from other test functions. Pick-to: 6.5 6.5.0 6.4 6.4.3 6.2 Change-Id: I302070121a8bb49f373c7711bc3ab9e6418874ef Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* tst_qvarlengtharray: add test for QVLA(n) ctorMarc Mutz2023-03-011-0/+44
| | | | | | | | | | Also add one for types that are neither copy- nor move-constructible. In contrast to resize(n), the QVLA(n) ctor worked for such types, so make sure it stays that way. Pick-to: 6.5 6.4 6.4.3 6.2 5.15 Change-Id: If54fbc9dd6a4808175c4bcb0ffb492b33c879746 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Long live QMessageAuthenticationCode::resultView()!Marc Mutz2023-03-011-6/+6
| | | | | | | | | | | Use it in a few places. [ChangeLog][QtCore][QMessageAuthenticationCode] Added QCryptographicHash-style resultView(). Change-Id: I745d71f86f9c19c9a9aabb2021c6617775dab1cf Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* tst_QMessageAuthenticationCode: check that setKey() reset()sMarc Mutz2023-02-261-0/+46
| | | | | | | | | It's documented as such. Pick-to: 6.5 6.4 6.2 5.15 Change-Id: I7299d289117e52dcefe3c4ab917d7ecad6dd02be Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* QCryptographicHash: auto-calculate MaxHashLengthMarc Mutz2023-02-251-2/+9
| | | | | | | | | | | | | | | | | | | | | Add Algorithm::NumAlgorithms and use it to iterate over all statically-available algorithms, querying their hashLengthInternal(). This avoids having to statically_assert(<= MaxHashLength) everywhere, and auto-adjusts the buffer size in SHA1_ONLY builds. Yes, the extra case labels for NumAlgorithms are a nuisance, but at least the compiler will remind us when we forget, unlike a missing static_cast(<= MaxHashLength) that might easily be forgotten. Adjust the test (which iterates over the QMetaEnum for QCryptographicHash::Algorithm, so finds NumAlgorithms and tries to pass it to the hash() function which responds with a Q_UNREACHABLE(). Only test hashLength() == 0 for that enum value. Pick-to: 6.5 Change-Id: I70155d2460464f0b2094e136eb6bea185effc9d5 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
* QHash: fix GrowthPolicy::bucketsForCapacityThiago Macieira2023-02-232-8/+56
| | | | | | | | | | | | | | | | | | | | | | | It was confusing entry capacity with the bucket capacity. The value maxNumBuckets() returned was the maximum number of entries. This issue was harmless: we would just fail to cap the maximum to an allocatable size. But the array new[] in the Data constructors would have capped the maximum anyway (by way of throwing std::bad_alloc). So instead of trying to calculate what the maximum bucket count is so we can cap at that, simplify the calculation of the next power of 2 while preventing it from overflowing in our calculations. We continue to rely on new[] throwing when we return count that is larger than the maximum allocatable. This commit changes the load factor for QHashes containing exactly a number of elements that is exactly a power of two. Previously, it would be loaded at 50%, now it's at 25%. For this reason, tst_QSet::squeeze needed to be fixed to depend less on the implementation details. Pick-to: 6.5 Change-Id: I9671dee8ceb64aa9b9cafffd17415f3856c358a0 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* tests: Remove remains of qmake conversion from CMakeLists.txt filesFriedemann Kleint2023-02-1742-83/+0
| | | | | | | 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_ContainerApiSymmetry: fix -Wsign-compareMarc Mutz2023-02-161-1/+1
| | | | | | | Amends 7cbdc8abbda12488f51317313347bbc220b42fe0. Change-Id: Ieed5e771bb716475d6e0fe9566627f664e04a432 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* tst_qvarlengtharray: fix MyBase trackers for swap()Marc Mutz2023-02-101-0/+34
| | | | | | | | | | | | | | I don't begin to understand the semantics of the trackers here, but whatever they are, they break with the fallback std::swap() 3-moves implementation and lose track of alive objects, so provide an ADL swap that does the right thing. Amends dd58ddd5d97f0663d5fafb7e81bff4fc7db13ba7 (I think). Pick-to: 6.5 6.4 6.2 5.15 Change-Id: I1cd49c95dca2d103a26c2c7ac0a896929135a6c8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>