summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global/qcompare
Commit message (Collapse)AuthorAgeFilesLines
* Change license for tests filesLucie Gérard2024-02-041-1/+1
| | | | | | | | | | | | 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>
* Add missing <=> 0 operator to Qt ordering typesMarc Mutz2023-12-071-0/+68
| | | | | | | | | | | | | | | It's required by the standard, see e.g. [1] and the eel.is links in the code. [ChangeLog][QtCore][QPartialOrdering] Added three-way comparison operator (<=>) against literal zero, available when compiling in C++20 mode. [1] https://en.cppreference.com/w/cpp/utility/compare/partial_ordering#Comparisons Change-Id: I8a3b76661400930c6e247cf5b138ff52bf784395 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QPartialOrdering: add lower-case flags for std/Qt:: compatibilityMarc Mutz2023-12-071-0/+5
| | | | | | | | | | | | The misspelt flags (Less, etc) make it hard to use QPartialOrdering interchangably with Qt or std ordering types, e.g. in generic code. [ChangeLog][QtCore][QPartialOrdering] Added a set of lower-case flags (::less, ::greater, etc) to improve source-compatibility with {Qt,std}::partial_ordering. Change-Id: I160600c01c4a2ab72c7b217a306d08045e363578 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QPartialOrdering: add missing conversions to/from Qt::_ordering typesMarc Mutz2023-12-071-0/+1
| | | | | | | | | | | | Since QPartialOrdering is supposed to be a drop-in-replacement for Qt::partial_ordering, it need to have the same conversions from Qt::_ordering types that Qt::partial_ordering has. Fix by adding the necessary conversion and relational operators and conversion constructors. Change-Id: Ib8e78c850b43c8bcb3bb15c5f7d25be9d0da7339 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* QPartialOrdering: add missing conversion from std::{weak,strong}_orderingMarc Mutz2023-12-071-0/+2
| | | | | | | | | | | | | | | QPartialOrdering is suppsed to be a drop-in replacement for std::partial_ordering, so it has to be convertible from all std::_ordering types. It was, however, only convertible from std::partial_ordering, and two user-defined conversions in a row are not allowed. Add the missing constructors. They, in turn, can then delegate to the partial_ordering constructor. Change-Id: I085d95677b258b4a61aabfd5468c1c43c2212766 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Long live qCompareThreeWay()Ivan Solovev2023-12-071-0/+113
| | | | | | | | | | | | | | | | | | | | | | | | | qCompareThreeWay() is a top-level wrapper around the helper three-way comparison methods, which is mostly convenient for generic client code. When implementing compareThreeWay() for Qt types, we normally provide the implementation only for (LeftType, RightType) pair, but not the reversed one. However, it is expected that qCompareThreeWay() would be available for both combinations, because the reversed result can be easily calculated. Solve it by providing a helper hasCompareThreeWay<LT, RT> variable and branching the implementation based on its value. The noexcept check is inspired by the old implementation of qSwap(). [ChangeLog][QtCore] Added qCompareThreeWay() as a public API for three-way comparison. Task-number: QTBUG-104113 Change-Id: I6f24494d968c336f3dcdf620004b4190769cbdb2 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* tst_QCompare: restore some test coverage to QPartialOrderingMarc Mutz2023-12-051-0/+22
| | | | | | | | | | | | | | | | | | | | | When I split Qt::partial_ordering off of QPartialOrdering, O duplicated the partialOrdering() test, but lost the conversion() part of the tests. This patch brings them back. Because we maintained the test coverage for Qt::partial_ordering, it suffices to check that QPartialOrdering::X correctly maps to std::partial_ordering::x. The rest follows from transtivity of equality. We're still lacking conversions of QPartialOrdering to Qt::_ordering types. That will be the subject of a follow-up patch. Amends 4b6f757020382ed157bf6beb572549f05e881359. Change-Id: I1938d09f696ed8d58143dbacccb72cfd54ca12dd Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Make Qt::partial_ordering binary-compatible to std::partial_orderingMarc Mutz2023-11-271-0/+39
| | | | | | | | | | | | | | | | | | | | | | | | | | In particular, match the value of ::unordered to each std library implementation. Legal disclaimer: The values were provided to this author in a comment on QTBUG-118913. This author hereby confirms he didn't look at any of the implementations himself. The stdlib detection macros are taken from existing code in qcompilerdetection.h. I didn't succeed in googling a corresponding marker for MSSTL, and I didn't look at the implementation or Boost.Config to find one, so this patch just assumes MSSTL as a fall-back, which is probably wrong, since we may still have Dinkumware and RougeWave STLs to deal with on embedded platforms. Add tests to ensure the values are the same on all platforms. To maximize coverage, rename qcompare.qdoc to qcompare.cpp and add a bunch of compile-time tests there. These depend in part on bit_cast, which we cannot depend on, so tst_qcompare contains the same tests using memcpy. Fixes: QTBUG-118913 Change-Id: I46c922c8e3ea37d7c01a71361c7a689340f9047d Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Rename Q*Ordering to Qt::*_orderingMarc Mutz2023-11-211-275/+386
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Since we cannot re-use the pre-existing QPartialOrdering type due to binary-compatibility issues (it's not BC to std::partial_ordering), we're no longer bound to copy its API for consistency. So copy std::*_ordering type API for consistency instead, to ease porting for users that can already use C++20 and everyone else come Qt 7. This patch is another step in that direction, renaming classes and their memmbers to std-compatible names. QPartialOrdering cannot change, as it's pre-existing. So add a completely new type Qt::partial_ordering. Adding conversions from QPartialOrdering is left for a follow-up patch. As a drive-by, change `\c Less` to `\l Less` in the \class documentation blocks of the new classes. Amending c6fe64b17c87ec985f17389bf08eee46606862d4, which didn't have a ChangeLog: [ChangeLog][QtCore] Added Qt::{partial,weak,strong}_ordering as drop-in C++17 stand-ins for C++20's std::{partial,weak,strong}_ordering. Task-number: QTBUG-119108 Change-Id: Ib1296de6b708571a6abca8843ba36c114f6fd34f Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
* Q*Ordering: supply is_{lt,gt,n,}eqMarc Mutz2023-11-211-0/+109
| | | | | | | | | | | | | | | | | | | | | std::is_eq etc work fine on our Q*Ordering types when C++20 is available. But in C++17 mode, they're absent. Plug the hole by providing them for our own types as hidden friends, so that users can use unqualified calls to transparently support both std::*ordering and Q*Ordering types, just like with comparison to literal zero. For some reason, we running here into https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100903, even though this wasn't seen in other commits of the chain that use comparisons to literal zero. Suppress the warning. Then at least is_eq etc provide a safe fall-back for compilers and users affected by this bogus warning. Fixes: QTBUG-119100 Change-Id: Ie8519c92363401a0c9c8efba6eb0b6e030a8e235 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Add QStrongOrdering and QWeakOrderingDennis Oberst2023-07-251-0/+272
| | | | | | | | | | | | | | These new classes align with the criteria of std::strong_ordering and std::weak_ordering and were the missing types required by the three-way comparison operator. References: https://en.cppreference.com/w/cpp/utility/compare/strong_ordering https://en.cppreference.com/w/cpp/utility/compare/weak_ordering Change-Id: Ie6620ca98103800fd5504810dc5689c1dd1c2972 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Marc Mutz <marc.mutz@qt.io>
* CMake: Make corelib tests standalone projectsAlexandru Croitor2023-07-051-0/+6
| | | | | | | | | | | | | | | | | | 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>
* tests: Remove remains of qmake conversion from CMakeLists.txt filesFriedemann Kleint2023-02-171-2/+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>
* Change the license of all CMakeLists.txt and *.cmake files to BSDLucie Gérard2022-08-231-1/+1
| | | | | | | Task-number: QTBUG-105718 Change-Id: I5d3ef70a31235868b9be6cb479b7621bf2a8ba39 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Add license headers to cmake filesLucie Gérard2022-08-031-0/+3
| | | | | | | | | | | | CMakeLists.txt and .cmake files of significant size (more than 2 lines according to our check in tst_license.pl) now have the copyright and license header. Existing copyright statements remain intact Task-number: QTBUG-88621 Change-Id: I3b98cdc55ead806ec81ce09af9271f9b95af97fa Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Use SPDX license identifiersLucie Gérard2022-05-161-38/+2
| | | | | | | | | | | | | Replace the current license disclaimer in files by a SPDX-License-Identifier. Files that have to be modified by hand are modified. License files are organized under LICENSES directory. Task-number: QTBUG-67283 Change-Id: Id880c92784c40f3bbde861c0d93f58151c18b9f1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Lars Knoll <lars.knoll@qt.io> Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
* Remove the qmake project filesJoerg Bornemann2021-01-071-8/+0
| | | | | | | | | | | | | | | | Remove the qmake project files for most of Qt. Leave the qmake project files for examples, because we still test those in the CI to ensure qmake does not regress. Also leave the qmake project files for utils and other minor parts that lack CMake project files. Task-number: QTBUG-88742 Change-Id: I6cdf059e6204816f617f9624f3ea9822703f73cc Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Kai Koehne <kai.koehne@qt.io>
* Fix QVariant/QMetaType::compare APIsGiuseppe D'Angelo2020-11-303-0/+155
std::optional<int> is the wrong datatype to use for compare. First and foremost, it can't be used in the idiomatic form of auto r = a.compare(b); if (r < 0) ~~~ // a is less than b if (r > 0) ~~~ // a is greater than b which we *already* feature in Qt (QString, QByteArray). Also, std::optional<int> (explicitly) converts to bool, which is a trap, because the result of the comparison can be accidentally tested as a bool: if (a.compare(b)) ~~~ // oops! does NOT mean a<b Not to mention extending this to algorithms: auto lessThan = [](QVariant a, QVariant b) { return a.compare(b); }; // oops! std::ranges::sort(vectorOfVariants, lessThan); which thankfully doesn't compile as is -- std::optional has an *explicit* operator bool, and the Compare concept requires an implicit conversion. However, the error the user is going to face will be "cannot convert to bool because the operator is explicit", which is deceiving because the fix is NOT supposed to be: auto lessThan = [](QVariant a, QVariant b) { return (bool)a.compare(b); }; // big oops! Instead: backport to Qt the required subset of C++20's <compare> API, and use that. This commits just adds the necessary parts for compare() (i.e. partial ordering), the rest of <compare> (classes, functions, conversions) can be added to 6.1. Change-Id: I2b5522da47854da39f79993e1207fad033786f00 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 3e59c97c3453926fc66479d9ceca03901df55f90) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>