summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/corelib/compat/removed_api.cpp7
-rw-r--r--src/corelib/mimetypes/qmimetype.cpp15
-rw-r--r--src/corelib/mimetypes/qmimetype.h8
-rw-r--r--tests/auto/corelib/mimetypes/qmimetype/CMakeLists.txt1
-rw-r--r--tests/auto/corelib/mimetypes/qmimetype/tst_qmimetype.cpp31
5 files changed, 50 insertions, 12 deletions
diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp
index 6101e71f79..7d3d3b5bd6 100644
--- a/src/corelib/compat/removed_api.cpp
+++ b/src/corelib/compat/removed_api.cpp
@@ -1006,6 +1006,13 @@ bool QJsonValue::operator!=(const QJsonValue &other) const
return !comparesEqual(*this, other);
}
+#include "qmimetype.h"
+
+bool QMimeType::operator==(const QMimeType &other) const
+{
+ return comparesEqual(*this, other);
+}
+
#include "qobject.h"
int QObject::startTimer(std::chrono::milliseconds time, Qt::TimerType timerType)
diff --git a/src/corelib/mimetypes/qmimetype.cpp b/src/corelib/mimetypes/qmimetype.cpp
index ad3c484f30..e26c8b898d 100644
--- a/src/corelib/mimetypes/qmimetype.cpp
+++ b/src/corelib/mimetypes/qmimetype.cpp
@@ -24,6 +24,7 @@ using namespace Qt::StringLiterals;
\brief The QMimeType class describes types of file or data, represented by a MIME type string.
\since 5.0
+ \compares equality
For instance a file named "readme.txt" has the MIME type "text/plain".
The MIME type can be determined from the file name, or from the file
@@ -111,14 +112,15 @@ QMimeType::~QMimeType()
}
/*!
- \fn bool QMimeType::operator==(const QMimeType &other) const;
- Returns \c true if \a other equals this QMimeType object, otherwise returns \c false.
+ \fn bool QMimeType::operator==(const QMimeType &lhs, const QMimeType &rhs);
+ Returns \c true if \a lhs equals to the \a rhs QMimeType object, otherwise
+ returns \c false.
The name is the unique identifier for a mimetype, so two mimetypes with
the same name, are equal.
*/
-bool QMimeType::operator==(const QMimeType &other) const
+bool comparesEqual(const QMimeType &lhs, const QMimeType &rhs) noexcept
{
- return d == other.d || d->name == other.d->name;
+ return lhs.d == rhs.d || lhs.d->name == rhs.d->name;
}
/*!
@@ -134,8 +136,9 @@ size_t qHash(const QMimeType &key, size_t seed) noexcept
}
/*!
- \fn bool QMimeType::operator!=(const QMimeType &other) const;
- Returns \c true if \a other does not equal this QMimeType object, otherwise returns \c false.
+ \fn bool QMimeType::operator!=(const QMimeType &lhs, const QMimeType &rhs);
+ Returns \c true if QMimeType \a lhs is not equal to QMimeType \a rhs,
+ otherwise returns \c false.
*/
/*!
diff --git a/src/corelib/mimetypes/qmimetype.h b/src/corelib/mimetypes/qmimetype.h
index 3421638f5b..508a5cfb53 100644
--- a/src/corelib/mimetypes/qmimetype.h
+++ b/src/corelib/mimetypes/qmimetype.h
@@ -49,14 +49,14 @@ public:
}
explicit QMimeType(const QMimeTypePrivate &dd);
~QMimeType();
-
+#if QT_CORE_REMOVED_SINCE(6, 8)
bool operator==(const QMimeType &other) const;
inline bool operator!=(const QMimeType &other) const
{
return !operator==(other);
}
-
+#endif
bool isValid() const;
bool isDefault() const;
@@ -86,6 +86,10 @@ protected:
friend Q_CORE_EXPORT size_t qHash(const QMimeType &key, size_t seed) noexcept;
QExplicitlySharedDataPointer<QMimeTypePrivate> d;
+
+private:
+ friend Q_CORE_EXPORT bool comparesEqual(const QMimeType &lhs, const QMimeType &rhs) noexcept;
+ Q_DECLARE_EQUALITY_COMPARABLE(QMimeType)
};
Q_DECLARE_SHARED(QMimeType)
diff --git a/tests/auto/corelib/mimetypes/qmimetype/CMakeLists.txt b/tests/auto/corelib/mimetypes/qmimetype/CMakeLists.txt
index e1781d450e..605cdccc3f 100644
--- a/tests/auto/corelib/mimetypes/qmimetype/CMakeLists.txt
+++ b/tests/auto/corelib/mimetypes/qmimetype/CMakeLists.txt
@@ -16,4 +16,5 @@ qt_internal_add_test(tst_qmimetype
tst_qmimetype.cpp
LIBRARIES
Qt::CorePrivate
+ Qt::TestPrivate
)
diff --git a/tests/auto/corelib/mimetypes/qmimetype/tst_qmimetype.cpp b/tests/auto/corelib/mimetypes/qmimetype/tst_qmimetype.cpp
index 79304e4420..b96e8feffa 100644
--- a/tests/auto/corelib/mimetypes/qmimetype/tst_qmimetype.cpp
+++ b/tests/auto/corelib/mimetypes/qmimetype/tst_qmimetype.cpp
@@ -8,7 +8,7 @@
#include <QVariantMap>
#include <QTest>
-
+#include <QtTest/private/qcomparisontesthelper_p.h>
class tst_qmimetype : public QObject
{
@@ -17,7 +17,9 @@ class tst_qmimetype : public QObject
private slots:
void initTestCase();
+ void compareCompiles();
void isValid();
+ void compareQMimetypes();
void name();
void genericIconName();
void iconName();
@@ -41,6 +43,28 @@ static QString qMimeTypeName()
// ------------------------------------------------------------------------------------------------
+void tst_qmimetype::compareCompiles()
+{
+ QTestPrivate::testEqualityOperatorsCompile<QMimeType>();
+}
+
+// ------------------------------------------------------------------------------------------------
+
+void tst_qmimetype::compareQMimetypes()
+{
+ QMimeType instantiatedQMimeType{ QMimeTypePrivate(qMimeTypeName()) };
+ QMimeType otherQMimeType (instantiatedQMimeType);
+ QMimeType defaultQMimeType;
+
+ QVERIFY(!defaultQMimeType.isValid());
+ QT_TEST_EQUALITY_OPS(defaultQMimeType, QMimeType(), true);
+ QT_TEST_EQUALITY_OPS(QMimeType(), QMimeType(), true);
+ QT_TEST_EQUALITY_OPS(instantiatedQMimeType, QMimeType(), false);
+ QT_TEST_EQUALITY_OPS(otherQMimeType, defaultQMimeType, false);
+}
+
+// ------------------------------------------------------------------------------------------------
+
void tst_qmimetype::isValid()
{
QMimeType instantiatedQMimeType{ QMimeTypePrivate(qMimeTypeName()) };
@@ -49,7 +73,7 @@ void tst_qmimetype::isValid()
QMimeType otherQMimeType (instantiatedQMimeType);
QVERIFY(otherQMimeType.isValid());
- QCOMPARE(instantiatedQMimeType, otherQMimeType);
+ QT_TEST_EQUALITY_OPS(instantiatedQMimeType, otherQMimeType, true);
QMimeType defaultQMimeType;
@@ -66,8 +90,7 @@ void tst_qmimetype::name()
// Verify that the Name is part of the equality test:
QCOMPARE(instantiatedQMimeType.name(), qMimeTypeName());
- QVERIFY(instantiatedQMimeType != otherQMimeType);
- QVERIFY(!(instantiatedQMimeType == otherQMimeType));
+ QT_TEST_EQUALITY_OPS(instantiatedQMimeType, otherQMimeType, false);
}
// ------------------------------------------------------------------------------------------------