QProcessEnvironment: Use new comparison helper macros
QProcessEnvironment had operator==() and operator!=() defined as public member functions, so use QT_CORE_REMOVED_SINCE and removed_api.cpp to get rid of these methods and replace them with a hidden friend. Use QT_TEST_ALL_EQUALITY_OPS macro in unit-tests. Use new \compares command in the documentation to describe the comparison operators provided by QProcessEnvironment. Task-number: QTBUG-120303 Change-Id: I4c57f6cfb9589e82a37eea6993e079212b34cecd Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
14b0580482
commit
22ebe86f15
@ -938,6 +938,15 @@ bool QFileInfo::operator==(const QFileInfo &fileinfo) const
|
|||||||
return comparesEqual(*this, fileinfo);
|
return comparesEqual(*this, fileinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if QT_CONFIG(processenvironment)
|
||||||
|
#include "qprocess.h" // inlined API
|
||||||
|
|
||||||
|
bool QProcessEnvironment::operator==(const QProcessEnvironment &other) const
|
||||||
|
{
|
||||||
|
return comparesEqual(*this, other);
|
||||||
|
}
|
||||||
|
#endif // QT_CONFIG(processenvironment)
|
||||||
|
|
||||||
// #include "qotherheader.h"
|
// #include "qotherheader.h"
|
||||||
// // implement removed functions from qotherheader.h
|
// // implement removed functions from qotherheader.h
|
||||||
// order sections alphabetically to reduce chances of merge conflicts
|
// order sections alphabetically to reduce chances of merge conflicts
|
||||||
|
@ -35,6 +35,8 @@ QT_BEGIN_NAMESPACE
|
|||||||
\reentrant
|
\reentrant
|
||||||
\since 4.6
|
\since 4.6
|
||||||
|
|
||||||
|
\compares equality
|
||||||
|
|
||||||
A process's environment is composed of a set of key=value pairs known as
|
A process's environment is composed of a set of key=value pairs known as
|
||||||
environment variables. The QProcessEnvironment class wraps that concept
|
environment variables. The QProcessEnvironment class wraps that concept
|
||||||
and allows easy manipulation of those variables. It's meant to be used
|
and allows easy manipulation of those variables. It's meant to be used
|
||||||
@ -184,15 +186,17 @@ QProcessEnvironment &QProcessEnvironment::operator=(const QProcessEnvironment &o
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\fn bool QProcessEnvironment::operator !=(const QProcessEnvironment &other) const
|
\fn bool QProcessEnvironment::operator!=(const QProcessEnvironment &lhs, const QProcessEnvironment &rhs)
|
||||||
|
|
||||||
Returns \c true if this and the \a other QProcessEnvironment objects are different.
|
Returns \c true if the process environment objects \a lhs and \a rhs are different.
|
||||||
|
|
||||||
\sa operator==()
|
\sa operator==()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
Returns \c true if this and the \a other QProcessEnvironment objects are equal.
|
\fn bool QProcessEnvironment::operator==(const QProcessEnvironment &lhs, const QProcessEnvironment &rhs)
|
||||||
|
|
||||||
|
Returns \c true if the process environment objects \a lhs and \a rhs are equal.
|
||||||
|
|
||||||
Two QProcessEnvironment objects are considered equal if they have the same
|
Two QProcessEnvironment objects are considered equal if they have the same
|
||||||
set of key=value pairs. The comparison of keys is done case-sensitive on
|
set of key=value pairs. The comparison of keys is done case-sensitive on
|
||||||
@ -200,12 +204,12 @@ QProcessEnvironment &QProcessEnvironment::operator=(const QProcessEnvironment &o
|
|||||||
|
|
||||||
\sa operator!=(), contains()
|
\sa operator!=(), contains()
|
||||||
*/
|
*/
|
||||||
bool QProcessEnvironment::operator==(const QProcessEnvironment &other) const
|
bool comparesEqual(const QProcessEnvironment &lhs, const QProcessEnvironment &rhs)
|
||||||
{
|
{
|
||||||
if (d == other.d)
|
if (lhs.d == rhs.d)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
return d && other.d && d->vars == other.d->vars;
|
return lhs.d && rhs.d && lhs.d->vars == rhs.d->vars;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#ifndef QPROCESS_H
|
#ifndef QPROCESS_H
|
||||||
#define QPROCESS_H
|
#define QPROCESS_H
|
||||||
|
|
||||||
|
#include <QtCore/qcompare.h>
|
||||||
#include <QtCore/qiodevice.h>
|
#include <QtCore/qiodevice.h>
|
||||||
#include <QtCore/qstringlist.h>
|
#include <QtCore/qstringlist.h>
|
||||||
#include <QtCore/qshareddata.h>
|
#include <QtCore/qshareddata.h>
|
||||||
@ -41,9 +42,11 @@ public:
|
|||||||
|
|
||||||
void swap(QProcessEnvironment &other) noexcept { d.swap(other.d); }
|
void swap(QProcessEnvironment &other) noexcept { d.swap(other.d); }
|
||||||
|
|
||||||
|
#if QT_CORE_REMOVED_SINCE(6, 8)
|
||||||
bool operator==(const QProcessEnvironment &other) const;
|
bool operator==(const QProcessEnvironment &other) const;
|
||||||
inline bool operator!=(const QProcessEnvironment &other) const
|
inline bool operator!=(const QProcessEnvironment &other) const
|
||||||
{ return !(*this == other); }
|
{ return !operator==(other); }
|
||||||
|
#endif
|
||||||
|
|
||||||
bool isEmpty() const;
|
bool isEmpty() const;
|
||||||
[[nodiscard]] bool inheritsFromParent() const;
|
[[nodiscard]] bool inheritsFromParent() const;
|
||||||
@ -63,6 +66,9 @@ public:
|
|||||||
static QProcessEnvironment systemEnvironment();
|
static QProcessEnvironment systemEnvironment();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
friend Q_CORE_EXPORT bool comparesEqual(const QProcessEnvironment &lhs,
|
||||||
|
const QProcessEnvironment &rhs);
|
||||||
|
Q_DECLARE_EQUALITY_COMPARABLE(QProcessEnvironment)
|
||||||
friend class QProcessPrivate;
|
friend class QProcessPrivate;
|
||||||
friend class QProcessEnvironmentPrivate;
|
friend class QProcessEnvironmentPrivate;
|
||||||
QSharedDataPointer<QProcessEnvironmentPrivate> d;
|
QSharedDataPointer<QProcessEnvironmentPrivate> d;
|
||||||
|
@ -14,4 +14,6 @@ endif()
|
|||||||
qt_internal_add_test(tst_qprocessenvironment
|
qt_internal_add_test(tst_qprocessenvironment
|
||||||
SOURCES
|
SOURCES
|
||||||
tst_qprocessenvironment.cpp
|
tst_qprocessenvironment.cpp
|
||||||
|
LIBRARIES
|
||||||
|
Qt::TestPrivate
|
||||||
)
|
)
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||||
|
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
|
#include <QtTest/private/qcomparisontesthelper_p.h>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QProcessEnvironment>
|
#include <QProcessEnvironment>
|
||||||
|
|
||||||
@ -9,6 +10,7 @@ class tst_QProcessEnvironment: public QObject
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
private slots:
|
private slots:
|
||||||
|
void compareCompiles();
|
||||||
void operator_eq();
|
void operator_eq();
|
||||||
void clearAndIsEmpty();
|
void clearAndIsEmpty();
|
||||||
void clearAndInheritsFromParent();
|
void clearAndInheritsFromParent();
|
||||||
@ -23,6 +25,11 @@ private slots:
|
|||||||
void putenv();
|
void putenv();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void tst_QProcessEnvironment::compareCompiles()
|
||||||
|
{
|
||||||
|
QTestPrivate::testEqualityOperatorsCompile<QProcessEnvironment>();
|
||||||
|
}
|
||||||
|
|
||||||
void tst_QProcessEnvironment::operator_eq()
|
void tst_QProcessEnvironment::operator_eq()
|
||||||
{
|
{
|
||||||
QProcessEnvironment e1;
|
QProcessEnvironment e1;
|
||||||
@ -35,8 +42,7 @@ void tst_QProcessEnvironment::operator_eq()
|
|||||||
QCOMPARE(e1, e2);
|
QCOMPARE(e1, e2);
|
||||||
|
|
||||||
auto parentEnv = QProcessEnvironment(QProcessEnvironment::InheritFromParent);
|
auto parentEnv = QProcessEnvironment(QProcessEnvironment::InheritFromParent);
|
||||||
QVERIFY(parentEnv != e2);
|
QT_TEST_EQUALITY_OPS(parentEnv, e2, false);
|
||||||
QVERIFY(e2 != parentEnv);
|
|
||||||
|
|
||||||
e1.clear();
|
e1.clear();
|
||||||
QCOMPARE(e1, e2);
|
QCOMPARE(e1, e2);
|
||||||
@ -45,16 +51,15 @@ void tst_QProcessEnvironment::operator_eq()
|
|||||||
QCOMPARE(e1, e2);
|
QCOMPARE(e1, e2);
|
||||||
|
|
||||||
e1.insert("FOO", "bar");
|
e1.insert("FOO", "bar");
|
||||||
QVERIFY(e1 != e2);
|
QT_TEST_EQUALITY_OPS(e1, e2, false);
|
||||||
|
|
||||||
e2.insert("FOO", "bar");
|
e2.insert("FOO", "bar");
|
||||||
QCOMPARE(e1, e2);
|
QCOMPARE(e1, e2);
|
||||||
|
|
||||||
e2.insert("FOO", "baz");
|
e2.insert("FOO", "baz");
|
||||||
QVERIFY(e1 != e2);
|
QT_TEST_EQUALITY_OPS(e1, e2, false);
|
||||||
|
|
||||||
QVERIFY(e2 != parentEnv);
|
QT_TEST_EQUALITY_OPS(e2, parentEnv, false);
|
||||||
QVERIFY(parentEnv != e2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void tst_QProcessEnvironment::clearAndIsEmpty()
|
void tst_QProcessEnvironment::clearAndIsEmpty()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user