summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/global
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/global')
-rw-r--r--tests/auto/corelib/global/qflags/tst_qflags.cpp69
-rw-r--r--tests/auto/corelib/global/qlogging/tst_qlogging.cpp20
2 files changed, 87 insertions, 2 deletions
diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp
index c679fbd8e3..fdbd95c64c 100644
--- a/tests/auto/corelib/global/qflags/tst_qflags.cpp
+++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp
@@ -31,6 +31,8 @@ class tst_QFlags: public QObject
{
Q_OBJECT
private slots:
+ void boolCasts() const;
+ void operators() const;
void testFlag() const;
void testFlagZeroFlag() const;
void testFlagMultiBits() const;
@@ -42,6 +44,73 @@ private slots:
void adl();
};
+void tst_QFlags::boolCasts() const
+{
+ // This tests that the operator overloading is sufficient so that common
+ // idioms involving flags -> bool casts work as expected:
+
+ const Qt::Alignment nonNull = Qt::AlignCenter;
+ const Qt::Alignment null = {};
+
+ // basic premiss:
+ QVERIFY(bool(nonNull));
+ QVERIFY(!bool(null));
+
+ // The rest is just checking that stuff compiles:
+
+ // QVERIFY should compile:
+ QVERIFY(nonNull);
+ QVERIFY(!null);
+
+ // ifs should compile:
+ if (null) QFAIL("Can't contextually convert QFlags to bool!");
+ if (!nonNull) QFAIL("Missing operator! on QFlags (shouldn't be necessary).");
+
+ // ternary should compile:
+ QVERIFY(nonNull ? true : false);
+ QVERIFY(!null ? true : false);
+
+ // logical operators should compile:
+ QVERIFY(nonNull && true);
+ QVERIFY(nonNull || false);
+ QVERIFY(!null && true);
+ QVERIFY(!null || false);
+
+ // ... in both directions:
+ QVERIFY(true && nonNull);
+ QVERIFY(false || nonNull);
+ QVERIFY(true && !null);
+ QVERIFY(false || !null);
+
+ // ... and mixed:
+ QVERIFY(null || nonNull);
+ QVERIFY(!(null && nonNull));
+}
+
+void tst_QFlags::operators() const
+{
+#define CHECK(op, LHS, RHS, RES) \
+ do { \
+ using LFlags = QFlags<decltype(LHS)>; \
+ using RFlags = QFlags<decltype(RHS)>; \
+ QCOMPARE((LHS op RHS), (RES)); \
+ QCOMPARE((LFlags(LHS) op RHS), (RES)); \
+ QCOMPARE((LHS op RFlags(RHS)), (RES)); \
+ QCOMPARE((LFlags(LHS) op RFlags(RHS)), (RES)); \
+ QCOMPARE((LFlags(LHS) op ## = RHS), (RES)); \
+ QCOMPARE((LFlags(LHS) op ## = RFlags(RHS)), (RES)); \
+ } while (false)
+
+ CHECK(|, Qt::AlignHCenter, Qt::AlignVCenter, Qt::AlignCenter);
+ CHECK(|, Qt::AlignHCenter, Qt::AlignHCenter, Qt::AlignHCenter);
+ CHECK(&, Qt::AlignHCenter, Qt::AlignVCenter, Qt::Alignment());
+ CHECK(&, Qt::AlignHCenter, Qt::AlignHCenter, Qt::AlignHCenter);
+ CHECK(^, Qt::AlignHCenter, Qt::AlignVCenter, Qt::AlignCenter);
+ CHECK(^, Qt::AlignHCenter, Qt::AlignHCenter, Qt::Alignment());
+
+#undef CHECK
+}
+
void tst_QFlags::testFlag() const
{
Qt::MouseButtons btn = Qt::LeftButton | Qt::RightButton;
diff --git a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
index 3af637d13a..0f27901f94 100644
--- a/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
+++ b/tests/auto/corelib/global/qlogging/tst_qlogging.cpp
@@ -34,6 +34,8 @@
#endif
#include <QtTest/QTest>
+#include <QtCore/QScopeGuard>
+
class tst_qmessagehandler : public QObject
{
Q_OBJECT
@@ -819,7 +821,17 @@ void tst_qmessagehandler::qMessagePattern()
QFETCH(QList<QByteArray>, expected);
QProcess process;
-#ifndef Q_OS_ANDROID
+
+ // Add the executable's directory to path so that we can find the test helper next to it
+ // in a cross-platform way. We must do this because the CWD is not pointing to this directory
+ // in debug-and-release builds.
+ QByteArray path = qgetenv("PATH");
+ qputenv("PATH",
+ path + QDir::listSeparator().toLatin1()
+ + QCoreApplication::applicationDirPath().toLocal8Bit());
+ auto restore = qScopeGuard([&] { qputenv("PATH", path); });
+
+#if !defined(Q_OS_ANDROID)
const QString appExe(QLatin1String("helper"));
#else
const QString appExe(QCoreApplication::applicationDirPath() + QLatin1String("/libhelper.so"));
@@ -869,8 +881,12 @@ void tst_qmessagehandler::setMessagePattern()
//
QProcess process;
-#ifndef Q_OS_ANDROID
+#ifdef Q_OS_WIN
+ // On Windows the CWD is not the same directory as the helper, so we cannot use "./"
+ // Instead we rely on CreateProcess to find the executable.
const QString appExe(QLatin1String("helper"));
+#elif !defined(Q_OS_ANDROID)
+ const QString appExe(QLatin1String("./helper"));
#else
const QString appExe(QCoreApplication::applicationDirPath() + QLatin1String("/libhelper.so"));
#endif