summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-12-03 06:55:21 +0100
committerLiang Qi <liang.qi@qt.io>2019-12-03 06:57:05 +0100
commite62d04b933a91c2bdd347aa97dc15ba210a04d2a (patch)
tree67c67af5f59d9b71522738da8a8d2d803e3ff44f /tests
parentf81f21151d30a37f955aa4af2398a96507626b15 (diff)
parent9ac156c90b92a981f70929e081c64083b14e9a57 (diff)
Merge remote-tracking branch 'origin/5.14' into 5.15
Conflicts: src/corelib/serialization/qcborvalue.cpp Change-Id: I675a3029955c96e81a33ed9d98b72b55b6784b52
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp74
-rw-r--r--tests/auto/corelib/time/qdate/tst_qdate.cpp58
-rw-r--r--tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp65
-rw-r--r--tests/auto/corelib/time/qtime/tst_qtime.cpp52
-rw-r--r--tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp9
-rw-r--r--tests/auto/network/ssl/qsslcertificate/BLACKLIST13
-rw-r--r--tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp10
-rw-r--r--tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp18
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp34
-rw-r--r--tests/manual/highdpi/dragwidget.cpp15
-rw-r--r--tests/manual/highdpi/dragwidget.h5
-rw-r--r--tests/manual/highdpi/main.cpp331
12 files changed, 479 insertions, 205 deletions
diff --git a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
index c6733205e5..47ad328d64 100644
--- a/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
+++ b/tests/auto/corelib/serialization/qcborvalue/tst_qcborvalue.cpp
@@ -40,6 +40,7 @@
#include <QtCore/qcborvalue.h>
#include <QtTest>
+Q_DECLARE_METATYPE(QCborKnownTags)
Q_DECLARE_METATYPE(QCborValue)
Q_DECLARE_METATYPE(QCborValue::EncodingOptions)
@@ -294,34 +295,77 @@ void tst_QCborValue::tagged()
void tst_QCborValue::extendedTypes_data()
{
QTest::addColumn<QCborValue>("extended");
- QTest::addColumn<QCborValue>("tagged");
+ QTest::addColumn<QCborKnownTags>("tag");
+ QTest::addColumn<QCborValue>("taggedValue");
+ QTest::addColumn<QCborValue>("correctedTaggedValue");
+ QCborValue v(QCborValue::Invalid);
QDateTime dt = QDateTime::currentDateTimeUtc();
+ QDateTime dtTzOffset(dt.date(), dt.time(), Qt::OffsetFromUTC, dt.offsetFromUtc());
QUuid uuid = QUuid::createUuid();
+ // non-correcting extended types (tagged value remains unchanged)
QTest::newRow("DateTime") << QCborValue(dt)
- << QCborValue(QCborKnownTags::DateTimeString, dt.toString(Qt::ISODateWithMs));
+ << QCborKnownTags::DateTimeString << QCborValue(dt.toString(Qt::ISODateWithMs)) << v;
+ QTest::newRow("DateTime:TzOffset") << QCborValue(dtTzOffset)
+ << QCborKnownTags::DateTimeString << QCborValue(dtTzOffset.toString(Qt::ISODateWithMs)) << v;
QTest::newRow("Url:Empty") << QCborValue(QUrl())
- << QCborValue(QCborKnownTags::Url, QString());
+ << QCborKnownTags::Url << QCborValue(QString()) << v;
QTest::newRow("Url:Authority") << QCborValue(QUrl("https://example.com"))
- << QCborValue(QCborKnownTags::Url, "https://example.com");
+ << QCborKnownTags::Url << QCborValue("https://example.com") << v;
QTest::newRow("Url:Path") << QCborValue(QUrl("file:///tmp/none"))
- << QCborValue(QCborKnownTags::Url, "file:///tmp/none");
+ << QCborKnownTags::Url << QCborValue("file:///tmp/none") << v;
QTest::newRow("Url:QueryFragment") << QCborValue(QUrl("whatever:?a=b&c=d#e"))
- << QCborValue(QCborKnownTags::Url, "whatever:?a=b&c=d#e");
+ << QCborKnownTags::Url << QCborValue("whatever:?a=b&c=d#e") << v;
QTest::newRow("Regex:Empty") << QCborValue(QRegularExpression())
- << QCborValue(QCborKnownTags::RegularExpression, QString());
+ << QCborKnownTags::RegularExpression << QCborValue(QString()) << v;
QTest::newRow("Regex") << QCborValue(QRegularExpression("^.*$"))
- << QCborValue(QCborKnownTags::RegularExpression, QString("^.*$"));
+ << QCborKnownTags::RegularExpression << QCborValue(QString("^.*$")) << v;
QTest::newRow("Uuid") << QCborValue(uuid)
- << QCborValue(QCborKnownTags::Uuid, uuid.toRfc4122());
+ << QCborKnownTags::Uuid << QCborValue(uuid.toRfc4122()) << v;
+
+ // correcting extended types
+ QDateTime dtNoMsecs = dt.fromSecsSinceEpoch(dt.toSecsSinceEpoch(), Qt::UTC);
+ QUrl url("https://example.com/\xc2\xa9 ");
+ QTest::newRow("UnixTime_t:Integer") << QCborValue(dtNoMsecs) << QCborKnownTags::UnixTime_t
+ << QCborValue(dtNoMsecs.toSecsSinceEpoch())
+ << QCborValue(dtNoMsecs.toString(Qt::ISODateWithMs));
+ QTest::newRow("UnixTime_t:Double") << QCborValue(dt) << QCborKnownTags::UnixTime_t
+ << QCborValue(dt.toMSecsSinceEpoch() / 1000.)
+ << QCborValue(dt.toString(Qt::ISODateWithMs));
+ QTest::newRow("DateTime::JustDate") << QCborValue(QDateTime({2018, 1, 1}, {}))
+ << QCborKnownTags::DateTimeString
+ << QCborValue("2018-01-01") << QCborValue("2018-01-01T00:00:00.000");
+ QTest::newRow("DateTime::TzOffset") << QCborValue(QDateTime({2018, 1, 1}, {9, 0, 0}, Qt::UTC))
+ << QCborKnownTags::DateTimeString
+ << QCborValue("2018-01-01T09:00:00.000+00:00")
+ << QCborValue("2018-01-01T09:00:00.000Z");
+ QTest::newRow("Url:NotNormalized") << QCborValue(url) << QCborKnownTags::Url
+ << QCborValue("HTTPS://EXAMPLE.COM/%c2%a9%20")
+ << QCborValue(url.toString());
+ QTest::newRow("Uuid:Zero") << QCborValue(QUuid()) << QCborKnownTags::Uuid
+ << QCborValue(QByteArray())
+ << QCborValue(QByteArray(sizeof(QUuid), 0));
+ QTest::newRow("Uuid:TooShort") << QCborValue(QUuid(0x12345678, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))
+ << QCborKnownTags::Uuid
+ << QCborValue(raw("\x12\x34\x56\x78"))
+ << QCborValue(raw("\x12\x34\x56\x78" "\0\0\0\0" "\0\0\0\0" "\0\0\0\0"));
+ QTest::newRow("Uuid:TooLong") << QCborValue(uuid) << QCborKnownTags::Uuid
+ << QCborValue(uuid.toRfc4122() + "\1\2\3\4") << QCborValue(uuid.toRfc4122());
}
void tst_QCborValue::extendedTypes()
{
QFETCH(QCborValue, extended);
- QFETCH(QCborValue, tagged);
+ QFETCH(QCborKnownTags, tag);
+ QFETCH(QCborValue, taggedValue);
+ QFETCH(QCborValue, correctedTaggedValue);
+ if (correctedTaggedValue.isInvalid())
+ correctedTaggedValue = taggedValue;
+
+ QCborValue tagged(tag, taggedValue);
QVERIFY(extended.isTag());
QVERIFY(tagged.isTag());
+ QCOMPARE(tagged.taggedValue(), correctedTaggedValue);
QVERIFY(extended == tagged);
QVERIFY(tagged == extended);
@@ -1224,8 +1268,11 @@ void tst_QCborValue::sorting()
QCborValue va1(QCborValue::Array), va2(QCborArray{1}), va3(QCborArray{0, 0});
QCborValue vm1(QCborValue::Map), vm2(QCborMap{{1, 0}}), vm3(QCborMap{{0, 0}, {1, 0}});
QCborValue vdt1(QDateTime::fromMSecsSinceEpoch(0, Qt::UTC)), vdt2(QDateTime::currentDateTimeUtc());
- QCborValue vtagged1(QCborKnownTags::UnixTime_t, 0), vtagged2(QCborKnownTags::UnixTime_t, 0.0),
- vtagged3(QCborKnownTags::Signature, 0), vtagged4(QCborTag(-2), 0), vtagged5(QCborTag(-1), 0);
+ QCborValue vtagged1(QCborKnownTags::PositiveBignum, QByteArray()),
+ vtagged2(QCborKnownTags::PositiveBignum, 0.0), // bignums are supposed to have byte arrays...
+ vtagged3(QCborKnownTags::Signature, 0),
+ vtagged4(QCborTag(-2), 0),
+ vtagged5(QCborTag(-1), 0);
QCborValue vurl1(QUrl("https://example.net")), vurl2(QUrl("https://example.com/"));
QCborValue vuuid1{QUuid()}, vuuid2(QUuid::createUuid());
QCborValue vsimple1(QCborSimpleType(1)), vsimple32(QCborSimpleType(32)), vsimple255(QCborSimpleType(255));
@@ -1391,6 +1438,9 @@ static void addCommonCborData()
QTest::newRow("Url") << QCborValue(QUrl("HTTPS://example.com/{%30%31}?q=%3Ca+b%20%C2%A9%3E&%26"))
<< raw("\xd8\x20\x78\x27" "https://example.com/{01}?q=<a+b \xC2\xA9>&%26")
<< noxfrm;
+ QTest::newRow("Url:NonAscii") << QCborValue(QUrl("https://example.com/\xc2\xa0"))
+ << raw("\xd8\x20\x76" "https://example.com/\xc2\xa0")
+ << noxfrm;
QTest::newRow("Regex:Empty") << QCborValue(QRegularExpression()) << raw("\xd8\x23\x60") << noxfrm;
QTest::newRow("Regex") << QCborValue(QRegularExpression("^.*$"))
<< raw("\xd8\x23\x64" "^.*$") << noxfrm;
diff --git a/tests/auto/corelib/time/qdate/tst_qdate.cpp b/tests/auto/corelib/time/qdate/tst_qdate.cpp
index 73384c35f4..dd2cb3eea8 100644
--- a/tests/auto/corelib/time/qdate/tst_qdate.cpp
+++ b/tests/auto/corelib/time/qdate/tst_qdate.cpp
@@ -1136,8 +1136,14 @@ void tst_QDate::fromStringDateFormat_data()
// Test Qt::RFC2822Date format (RFC 2822).
QTest::newRow("RFC 2822") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100")
<< Qt::RFC2822Date << QDate(1987, 2, 13);
+ QTest::newRow("RFC 2822 after space")
+ << QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100")
+ << Qt::RFC2822Date << QDate(1987, 2, 13);
QTest::newRow("RFC 2822 with day") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000")
<< Qt::RFC2822Date << QDate(1970, 1, 1);
+ QTest::newRow("RFC 2822 with day after space")
+ << QString::fromLatin1(" Thu, 01 Jan 1970 00:12:34 +0000")
+ << Qt::RFC2822Date << QDate(1970, 1, 1);
// No timezone
QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34")
<< Qt::RFC2822Date << QDate(1970, 1, 1);
@@ -1153,38 +1159,56 @@ void tst_QDate::fromStringDateFormat_data()
<< Qt::RFC2822Date << QDate();
QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Fev 0000 13:24:51 +0100")
<< Qt::RFC2822Date << QDate();
- // Test invalid characters (should ignore invalid characters at end of string).
- QTest::newRow("RFC 2822 invalid character at end") << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!")
+ // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038).
+ QTest::newRow("RFC 2822 invalid character at end")
+ << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!")
+ << Qt::RFC2822Date << QDate(2012, 1, 1);
+ QTest::newRow("RFC 2822 invalid character at front")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << QDate();
+ QTest::newRow("RFC 2822 invalid character both ends")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100!") << Qt::RFC2822Date << QDate();
+ QTest::newRow("RFC 2822 invalid character at front, 2 at back")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100..") << Qt::RFC2822Date << QDate();
+ QTest::newRow("RFC 2822 invalid character 2 at front")
+ << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0100") << Qt::RFC2822Date << QDate();
+ // The common date text used by the "invalid character" tests, just to be
+ // sure *it's* not what's invalid:
+ QTest::newRow("RFC 2822 (not invalid)")
+ << QString::fromLatin1("01 Jan 2012 08:00:00 +0100")
<< Qt::RFC2822Date << QDate(2012, 1, 1);
- QTest::newRow("RFC 2822 invalid character at front") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000")
- << Qt::RFC2822Date << QDate();
- QTest::newRow("RFC 2822 invalid character both ends") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000!")
- << Qt::RFC2822Date << QDate();
- QTest::newRow("RFC 2822 invalid character at front, 2 at back") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000..")
- << Qt::RFC2822Date << QDate();
- QTest::newRow("RFC 2822 invalid character 2 at front") << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0000")
- << Qt::RFC2822Date << QDate();
- // Test Qt::RFC2822Date format (RFC 850 and 1036).
+ // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive).
QTest::newRow("RFC 850 and 1036") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100")
<< Qt::RFC2822Date << QDate(1987, 2, 13);
+ QTest::newRow("RFC 850 and 1036 after space")
+ << QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100")
+ << Qt::RFC2822Date << QDate(1987, 2, 13);
// No timezone
QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970")
<< Qt::RFC2822Date << QDate(1970, 1, 1);
// No time specified
QTest::newRow("RFC 850 and 1036 date only") << QString::fromLatin1("Fri Nov 01 2002")
<< Qt::RFC2822Date << QDate(2002, 11, 1);
- // Test invalid characters (should ignore invalid characters at end of string).
- QTest::newRow("RFC 850 and 1036 invalid character at end") << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!")
+ // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038).
+ QTest::newRow("RFC 850 and 1036 invalid character at end")
+ << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!")
<< Qt::RFC2822Date << QDate(2012, 1, 1);
- QTest::newRow("RFC 850 and 1036 invalid character at front") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000")
+ QTest::newRow("RFC 850 and 1036 invalid character at front")
+ << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100")
<< Qt::RFC2822Date << QDate();
- QTest::newRow("RFC 850 and 1036 invalid character both ends") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000!")
+ QTest::newRow("RFC 850 and 1036 invalid character both ends")
+ << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100!")
<< Qt::RFC2822Date << QDate();
- QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000..")
+ QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back")
+ << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100..")
<< Qt::RFC2822Date << QDate();
- QTest::newRow("RFC 850 and 1036 invalid character 2 at front") << QString::fromLatin1("!!Sun Jan 01 08:00:00 2012 +0000")
+ QTest::newRow("RFC 850 and 1036 invalid character 2 at front")
+ << QString::fromLatin1("!!Sun Jan 01 08:00:00 2012 +0100")
<< Qt::RFC2822Date << QDate();
+ // Again, check the text in the "invalid character" tests isn't the source of invalidity:
+ QTest::newRow("RFC 850 and 1036 (not invalid)")
+ << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100")
+ << Qt::RFC2822Date << QDate(2012, 1, 1);
QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << QDate();
}
diff --git a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
index 216ae1f79e..7f13fd0aa5 100644
--- a/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
+++ b/tests/auto/corelib/time/qdatetime/tst_qdatetime.cpp
@@ -1003,8 +1003,9 @@ void tst_QDateTime::toString_rfcDate()
// Set to non-English locale to confirm still uses English
QLocale oldLocale;
QLocale::setDefault(QLocale("de_DE"));
- QCOMPARE(dt.toString(Qt::RFC2822Date), formatted);
+ QString actual(dt.toString(Qt::RFC2822Date));
QLocale::setDefault(oldLocale);
+ QCOMPARE(actual, formatted);
}
void tst_QDateTime::toString_enumformat()
@@ -2310,8 +2311,14 @@ void tst_QDateTime::fromStringDateFormat_data()
// Test Qt::RFC2822Date format (RFC 2822).
QTest::newRow("RFC 2822 +0100") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100")
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
+ QTest::newRow("RFC 2822 after space +0100")
+ << QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100")
+ << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
QTest::newRow("RFC 2822 with day +0100") << QString::fromLatin1("Fri, 13 Feb 1987 13:24:51 +0100")
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
+ QTest::newRow("RFC 2822 with day after space +0100")
+ << QString::fromLatin1(" Fri, 13 Feb 1987 13:24:51 +0100")
+ << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
QTest::newRow("RFC 2822 -0100") << QString::fromLatin1("13 Feb 1987 13:24:51 -0100")
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), Qt::UTC);
QTest::newRow("RFC 2822 with day -0100") << QString::fromLatin1("Fri, 13 Feb 1987 13:24:51 -0100")
@@ -2324,6 +2331,11 @@ void tst_QDateTime::fromStringDateFormat_data()
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC);
QTest::newRow("RFC 2822 with day +0000") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000")
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC);
+ // Should be invalid, but current implementation would just ignore the
+ // offset as trailing junk if we insist on the space:
+ QTest::newRow("RFC 2822 missing space before +0100")
+ << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34+0100") << Qt::RFC2822Date
+ << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::OffsetFromUTC, 3600);
// No timezone assume UTC
QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34")
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC);
@@ -2339,21 +2351,34 @@ void tst_QDateTime::fromStringDateFormat_data()
<< Qt::RFC2822Date << invalidDateTime();
QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Fev 0000 13:24:51 +0100")
<< Qt::RFC2822Date << invalidDateTime();
- // Test invalid characters (should ignore invalid characters at end of string).
- QTest::newRow("RFC 2822 invalid character at end") << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!")
+ // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038).
+ QTest::newRow("RFC 2822 invalid character at end")
+ << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!")
<< Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC);
- QTest::newRow("RFC 2822 invalid character at front") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000")
+ QTest::newRow("RFC 2822 invalid character at front")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100")
<< Qt::RFC2822Date << invalidDateTime();
- QTest::newRow("RFC 2822 invalid character both ends") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000!")
+ QTest::newRow("RFC 2822 invalid character both ends")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100!")
<< Qt::RFC2822Date << invalidDateTime();
- QTest::newRow("RFC 2822 invalid character at front, 2 at back") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000..")
+ QTest::newRow("RFC 2822 invalid character at front, 2 at back")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100..")
<< Qt::RFC2822Date << invalidDateTime();
- QTest::newRow("RFC 2822 invalid character 2 at front") << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0000")
+ QTest::newRow("RFC 2822 invalid character 2 at front")
+ << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0100")
<< Qt::RFC2822Date << invalidDateTime();
+ // The common date text used by the "invalid character" tests, just to be
+ // sure *it's* not what's invalid:
+ QTest::newRow("RFC 2822 (not invalid)")
+ << QString::fromLatin1("01 Jan 2012 08:00:00 +0100")
+ << Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC);
- // Test Qt::RFC2822Date format (RFC 850 and 1036).
+ // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive).
QTest::newRow("RFC 850 and 1036 +0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100")
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
+ QTest::newRow("RFC 1036 after space +0100")
+ << QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100")
+ << Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(12, 24, 51), Qt::UTC);
QTest::newRow("RFC 850 and 1036 -0100") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 -0100")
<< Qt::RFC2822Date << QDateTime(QDate(1987, 2, 13), QTime(14, 24, 51), Qt::UTC);
QTest::newRow("RFC 850 and 1036 +0000") << QString::fromLatin1("Thu Jan 01 00:12:34 1970 +0000")
@@ -2364,19 +2389,29 @@ void tst_QDateTime::fromStringDateFormat_data()
QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970")
<< Qt::RFC2822Date << QDateTime(QDate(1970, 1, 1), QTime(0, 12, 34), Qt::UTC);
// No time specified
- QTest::newRow("RFC 850 and 1036 date only") << QString::fromLatin1("Fri Nov 01 2002")
+ QTest::newRow("RFC 850 and 1036 date only")
+ << QString::fromLatin1("Fri Nov 01 2002")
<< Qt::RFC2822Date << invalidDateTime();
- // Test invalid characters (should ignore invalid characters at end of string).
- QTest::newRow("RFC 850 and 1036 invalid character at end") << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!")
+ // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038).
+ QTest::newRow("RFC 850 and 1036 invalid character at end")
+ << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!")
<< Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC);
- QTest::newRow("RFC 850 and 1036 invalid character at front") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000")
+ QTest::newRow("RFC 850 and 1036 invalid character at front")
+ << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100")
<< Qt::RFC2822Date << invalidDateTime();
- QTest::newRow("RFC 850 and 1036 invalid character both ends") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000!")
+ QTest::newRow("RFC 850 and 1036 invalid character both ends")
+ << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100!")
<< Qt::RFC2822Date << invalidDateTime();
- QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000..")
+ QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back")
+ << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100..")
<< Qt::RFC2822Date << invalidDateTime();
- QTest::newRow("RFC 850 and 1036 invalid character 2 at front") << QString::fromLatin1("!!Sun Jan 01 08:00:00 2012 +0000")
+ QTest::newRow("RFC 850 and 1036 invalid character 2 at front")
+ << QString::fromLatin1("!!Sun Jan 01 08:00:00 2012 +0100")
<< Qt::RFC2822Date << invalidDateTime();
+ // Again, check the text in the "invalid character" tests isn't the source of invalidity:
+ QTest::newRow("RFC 850 and 1036 (not invalid)")
+ << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100")
+ << Qt::RFC2822Date << QDateTime(QDate(2012, 1, 1), QTime(7, 0, 0, 0), Qt::UTC);
QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << invalidDateTime();
}
diff --git a/tests/auto/corelib/time/qtime/tst_qtime.cpp b/tests/auto/corelib/time/qtime/tst_qtime.cpp
index 3403c5bf7f..d8de6e585d 100644
--- a/tests/auto/corelib/time/qtime/tst_qtime.cpp
+++ b/tests/auto/corelib/time/qtime/tst_qtime.cpp
@@ -619,8 +619,14 @@ void tst_QTime::fromStringDateFormat_data()
// Test Qt::RFC2822Date format (RFC 2822).
QTest::newRow("RFC 2822") << QString::fromLatin1("13 Feb 1987 13:24:51 +0100")
<< Qt::RFC2822Date << QTime(13, 24, 51);
+ QTest::newRow("RFC 2822 after space")
+ << QString::fromLatin1(" 13 Feb 1987 13:24:51 +0100")
+ << Qt::RFC2822Date << QTime(13, 24, 51);
QTest::newRow("RFC 2822 with day") << QString::fromLatin1("Thu, 01 Jan 1970 00:12:34 +0000")
<< Qt::RFC2822Date << QTime(0, 12, 34);
+ QTest::newRow("RFC 2822 with day after space")
+ << QString::fromLatin1(" Thu, 01 Jan 1970 00:12:34 +0000")
+ << Qt::RFC2822Date << QTime(0, 12, 34);
// No timezone
QTest::newRow("RFC 2822 no timezone") << QString::fromLatin1("01 Jan 1970 00:12:34")
<< Qt::RFC2822Date << QTime(0, 12, 34);
@@ -636,36 +642,58 @@ void tst_QTime::fromStringDateFormat_data()
<< Qt::RFC2822Date << QTime(13, 24, 51);
QTest::newRow("RFC 2822 invalid year") << QString::fromLatin1("13 Fev 0000 13:24:51 +0100")
<< Qt::RFC2822Date << QTime(13, 24, 51);
- // Test invalid characters (should ignore invalid characters at end of string).
- QTest::newRow("RFC 2822 invalid character at end") << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!")
+ // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038).
+ QTest::newRow("RFC 2822 invalid character at end")
+ << QString::fromLatin1("01 Jan 2012 08:00:00 +0100!")
<< Qt::RFC2822Date << QTime(8, 0, 0);
- QTest::newRow("RFC 2822 invalid character at front") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000")
+ QTest::newRow("RFC 2822 invalid character at front")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100")
<< Qt::RFC2822Date << invalidTime();
- QTest::newRow("RFC 2822 invalid character both ends") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000!")
+ QTest::newRow("RFC 2822 invalid character both ends")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100!")
<< Qt::RFC2822Date << invalidTime();
- QTest::newRow("RFC 2822 invalid character at front, 2 at back") << QString::fromLatin1("!01 Jan 2012 08:00:00 +0000..")
+ QTest::newRow("RFC 2822 invalid character at front, 2 at back")
+ << QString::fromLatin1("!01 Jan 2012 08:00:00 +0100..")
<< Qt::RFC2822Date << invalidTime();
- QTest::newRow("RFC 2822 invalid character 2 at front") << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0000")
+ QTest::newRow("RFC 2822 invalid character 2 at front")
+ << QString::fromLatin1("!!01 Jan 2012 08:00:00 +0100")
<< Qt::RFC2822Date << invalidTime();
+ // The common date text used by the "invalid character" tests, just to be
+ // sure *it's* not what's invalid:
+ QTest::newRow("RFC 2822 invalid character at end")
+ << QString::fromLatin1("01 Jan 2012 08:00:00 +0100")
+ << Qt::RFC2822Date << QTime(8, 0, 0);
- // Test Qt::RFC2822Date format (RFC 850 and 1036).
+ // Test Qt::RFC2822Date format (RFC 850 and 1036, permissive).
QTest::newRow("RFC 850 and 1036") << QString::fromLatin1("Fri Feb 13 13:24:51 1987 +0100")
<< Qt::RFC2822Date << QTime(13, 24, 51);
+ QTest::newRow("RFC 850 and 1036 after space")
+ << QString::fromLatin1(" Fri Feb 13 13:24:51 1987 +0100")
+ << Qt::RFC2822Date << QTime(13, 24, 51);
// No timezone
QTest::newRow("RFC 850 and 1036 no timezone") << QString::fromLatin1("Thu Jan 01 00:12:34 1970")
<< Qt::RFC2822Date << QTime(0, 12, 34);
// No time specified
QTest::newRow("RFC 850 and 1036 date only") << QString::fromLatin1("Fri Nov 01 2002")
<< Qt::RFC2822Date << invalidTime();
- // Test invalid characters (should ignore invalid characters at end of string).
- QTest::newRow("RFC 850 and 1036 invalid character at end") << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!")
+ // Test invalid characters (currently ignoring trailing junk, but see QTBUG-80038).
+ QTest::newRow("RFC 850 and 1036 invalid character at end")
+ << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100!")
<< Qt::RFC2822Date << QTime(8, 0, 0);
- QTest::newRow("RFC 850 and 1036 invalid character at front") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000")
+ QTest::newRow("RFC 850 and 1036 invalid character at front")
+ << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100")
<< Qt::RFC2822Date << invalidTime();
- QTest::newRow("RFC 850 and 1036 invalid character both ends") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000!")
+ QTest::newRow("RFC 850 and 1036 invalid character both ends")
+ << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100!")
<< Qt::RFC2822Date << invalidTime();
- QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back") << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0000..")
+ QTest::newRow("RFC 850 and 1036 invalid character at front, 2 at back")
+ << QString::fromLatin1("!Sun Jan 01 08:00:00 2012 +0100..")
<< Qt::RFC2822Date << invalidTime();
+ // The common date text used by the "invalid character" tests, just to be
+ // sure *it's* not what's invalid:
+ QTest::newRow("RFC 850 and 1036 invalid character at end")
+ << QString::fromLatin1("Sun Jan 01 08:00:00 2012 +0100")
+ << Qt::RFC2822Date << QTime(8, 0, 0);
QTest::newRow("RFC empty") << QString::fromLatin1("") << Qt::RFC2822Date << invalidTime();
}
diff --git a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
index d0ef8023b9..332a00efb5 100644
--- a/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
+++ b/tests/auto/corelib/time/qtimezone/tst_qtimezone.cpp
@@ -46,6 +46,7 @@ private slots:
// Public class default system tests
void createTest();
void nullTest();
+ void systemZone();
void dataStreamTest();
void isTimeZoneIdAvailable();
void availableTimeZoneIds();
@@ -317,6 +318,14 @@ void tst_QTimeZone::nullTest()
QCOMPARE(data.daylightTimeOffset, std::numeric_limits<int>::min());
}
+void tst_QTimeZone::systemZone()
+{
+ const QTimeZone zone = QTimeZone::systemTimeZone();
+ QVERIFY(zone.isValid());
+ QCOMPARE(zone.id(), QTimeZone::systemTimeZoneId());
+ QCOMPARE(zone, QTimeZone(QTimeZone::systemTimeZoneId()));
+}
+
void tst_QTimeZone::dataStreamTest()
{
// Test the OffsetFromUtc backend serialization. First with a custom timezone:
diff --git a/tests/auto/network/ssl/qsslcertificate/BLACKLIST b/tests/auto/network/ssl/qsslcertificate/BLACKLIST
deleted file mode 100644
index 9494ee2278..0000000000
--- a/tests/auto/network/ssl/qsslcertificate/BLACKLIST
+++ /dev/null
@@ -1,13 +0,0 @@
-# OpenSSL version is too new. Rich will fix :)
-[subjectAndIssuerAttributes]
-ubuntu-16.04
-rhel-7.6
-opensuse-leap
-windows-7sp1
-ubuntu-18.04
-rhel-7.4
-b2qt
-windows-10 msvc-2017
-windows-10 msvc-2015
-opensuse-42.3
-
diff --git a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp
index efc0c26076..14718ad373 100644
--- a/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp
+++ b/tests/auto/network/ssl/qsslcertificate/tst_qsslcertificate.cpp
@@ -33,6 +33,10 @@
#include <qsslsocket.h>
#include <qsslcertificateextension.h>
+#ifndef QT_NO_OPENSSL
+#include <openssl/obj_mac.h>
+#endif
+
class tst_QSslCertificate : public QObject
{
Q_OBJECT
@@ -960,8 +964,12 @@ void tst_QSslCertificate::subjectAndIssuerAttributes()
certList = QSslCertificate::fromPath(testDataDir + "more-certificates/natwest-banking.pem");
QVERIFY(certList.count() > 0);
+ QByteArray shortName("1.3.6.1.4.1.311.60.2.1.3");
+#if !defined(QT_NO_OPENSSL) && defined(SN_jurisdictionCountryName)
+ shortName = SN_jurisdictionCountryName;
+#endif
attributes = certList[0].subjectInfoAttributes();
- QVERIFY(attributes.contains(QByteArray("1.3.6.1.4.1.311.60.2.1.3")));
+ QVERIFY(attributes.contains(shortName));
}
void tst_QSslCertificate::verify()
diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
index 23e2ec8516..8396fd4ec7 100644
--- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
+++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp
@@ -4922,13 +4922,27 @@ void tst_QTreeView::taskQTBUG_61476()
const QPoint pos = rect.center();
QTest::mousePress(tv.viewport(), Qt::LeftButton, {}, pos);
- if (tv.style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, nullptr, &tv) ==
- QEvent::MouseButtonPress)
+ const bool expandsOnPress =
+ (tv.style()->styleHint(QStyle::SH_ListViewExpand_SelectMouseType, nullptr, &tv) == QEvent::MouseButtonPress);
+ if (expandsOnPress)
QTRY_VERIFY(!tv.isExpanded(mi));
QTest::mouseRelease(tv.viewport(), Qt::LeftButton, {}, pos);
QTRY_VERIFY(!tv.isExpanded(mi));
QCOMPARE(lastTopLevel->checkState(), Qt::Checked);
+
+ // Test that it does not toggle the check state of a previously selected item when collapsing an
+ // item causes it to position the item under the mouse to be the decoration for the selected item
+ tv.expandAll();
+ tv.verticalScrollBar()->setValue(tv.verticalScrollBar()->maximum());
+ // It is not enough to programmatically select the item, we need to have it clicked on
+ QTest::mouseClick(tv.viewport(), Qt::LeftButton, {}, tv.visualRect(lastTopLevel->index()).center());
+ QTest::mousePress(tv.viewport(), Qt::LeftButton, {}, pos);
+ if (expandsOnPress)
+ QTRY_VERIFY(!tv.isExpanded(mi));
+ QTest::mouseRelease(tv.viewport(), Qt::LeftButton, nullptr, pos);
+ QTRY_VERIFY(!tv.isExpanded(mi));
+ QCOMPARE(lastTopLevel->checkState(), Qt::Checked);
}
QTEST_MAIN(tst_QTreeView)
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index 07f84595fd..6f8fd5dcbe 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -53,6 +53,7 @@
#include <qmainwindow.h>
#include <qdockwidget.h>
#include <qrandom.h>
+#include <qstylehints.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <QtCore/qoperatingsystemversion.h>
@@ -198,6 +199,7 @@ private slots:
void hideWhenFocusWidgetIsChild();
void normalGeometry();
void setGeometry();
+ void setGeometryHidden();
void windowOpacity();
void raise();
void lower();
@@ -2946,6 +2948,38 @@ void tst_QWidget::setGeometry()
QCOMPARE(tlw.geometry(), tr);
}
+void tst_QWidget::setGeometryHidden()
+{
+ if (QGuiApplication::styleHints()->showIsMaximized())
+ QSKIP("Platform does not support QWidget::setGeometry() - skipping");
+
+ QWidget tlw;
+ tlw.setWindowTitle(QLatin1String(QTest::currentTestFunction()));
+ QWidget child(&tlw);
+
+ const QRect tr(m_availableTopLeft + QPoint(100, 100), 2 * m_testWidgetSize);
+ const QRect cr(QPoint(50, 50), m_testWidgetSize);
+ tlw.setGeometry(tr);
+ child.setGeometry(cr);
+ tlw.showNormal();
+
+ tlw.hide();
+ QTRY_VERIFY(tlw.isHidden());
+ tlw.setGeometry(cr);
+ QVERIFY(tlw.testAttribute(Qt::WA_PendingMoveEvent));
+ QVERIFY(tlw.testAttribute(Qt::WA_PendingResizeEvent));
+ QImage img(tlw.size(), QImage::Format_ARGB32); // just needed to call QWidget::render()
+ tlw.render(&img);
+ QVERIFY(!tlw.testAttribute(Qt::WA_PendingMoveEvent));
+ QVERIFY(!tlw.testAttribute(Qt::WA_PendingResizeEvent));
+ tlw.setGeometry(cr);
+ QVERIFY(!tlw.testAttribute(Qt::WA_PendingMoveEvent));
+ QVERIFY(!tlw.testAttribute(Qt::WA_PendingResizeEvent));
+ tlw.resize(cr.size());
+ QVERIFY(!tlw.testAttribute(Qt::WA_PendingMoveEvent));
+ QVERIFY(!tlw.testAttribute(Qt::WA_PendingResizeEvent));
+}
+
void tst_QWidget::windowOpacity()
{
QWidget widget;
diff --git a/tests/manual/highdpi/dragwidget.cpp b/tests/manual/highdpi/dragwidget.cpp
index 11bbc1d127..8ad3d3ca47 100644
--- a/tests/manual/highdpi/dragwidget.cpp
+++ b/tests/manual/highdpi/dragwidget.cpp
@@ -42,7 +42,7 @@ public:
};
DragWidget::DragWidget(QString text, QWidget *parent)
- : QWidget(parent), otherWindow(nullptr)
+ : QWidget(parent)
{
int x = 5;
int y = 5;
@@ -52,9 +52,9 @@ DragWidget::DragWidget(QString text, QWidget *parent)
text = "You can drag from this window and drop text here";
QStringList words = text.split(' ');
- foreach (QString word, words) {
+ for (const QString &word : words) {
if (!word.isEmpty()) {
- FramedLabel *wordLabel = new FramedLabel(word, this);
+ auto wordLabel = new FramedLabel(word, this);
wordLabel->move(x, y);
wordLabel->show();
x += wordLabel->width() + 2;
@@ -105,7 +105,6 @@ void DragWidget::dragLeaveEvent(QDragLeaveEvent *)
update();
}
-
void DragWidget::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasText()) {
@@ -141,9 +140,9 @@ void DragWidget::dropEvent(QDropEvent *event)
} else {
event->ignore();
}
- foreach (QObject *child, children()) {
- if (child->inherits("QWidget")) {
- QWidget *widget = static_cast<QWidget *>(child);
+ for (QObject *child : children()) {
+ if (child->isWidgetType()) {
+ auto widget = static_cast<QWidget *>(child);
if (!widget->isVisible())
widget->deleteLater();
}
@@ -170,7 +169,7 @@ void DragWidget::mousePressEvent(QMouseEvent *event)
pixmap.setDevicePixelRatio(dpr);
child->render(&pixmap);
- QDrag *drag = new QDrag(this);
+ auto drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setPixmap(pixmap);
drag->setHotSpot(hotSpot);
diff --git a/tests/manual/highdpi/dragwidget.h b/tests/manual/highdpi/dragwidget.h
index 8b67b20410..06663fc74a 100644
--- a/tests/manual/highdpi/dragwidget.h
+++ b/tests/manual/highdpi/dragwidget.h
@@ -40,7 +40,7 @@ QT_END_NAMESPACE
class DragWidget : public QWidget
{
public:
- DragWidget(QString text = QString(), QWidget *parent = 0);
+ DragWidget(QString text = QString(), QWidget *parent = nullptr);
protected:
void dragEnterEvent(QDragEnterEvent *event) override;
@@ -52,12 +52,13 @@ protected:
void timerEvent(QTimerEvent *event) override;
void showEvent(QShowEvent *event) override;
void hideEvent(QHideEvent *event) override;
+
private:
QPoint dragPos;
QPoint dropPos;
QBasicTimer dragTimer;
QBasicTimer dropTimer;
- QWidget *otherWindow;
+ QWidget *otherWindow = nullptr;
};
#endif // DRAGWIDGET_H
diff --git a/tests/manual/highdpi/main.cpp b/tests/manual/highdpi/main.cpp
index 51a7026e85..0d4d3beef7 100644
--- a/tests/manual/highdpi/main.cpp
+++ b/tests/manual/highdpi/main.cpp
@@ -30,6 +30,7 @@
#include <QMenuBar>
#include <QLabel>
#include <QHBoxLayout>
+#include <QFormLayout>
#include <QApplication>
#include <QAction>
#include <QStyle>
@@ -61,27 +62,38 @@
#include "dragwidget.h"
+#include <utility>
+
static QTextStream &operator<<(QTextStream &str, const QRect &r)
{
str << r.width() << 'x' << r.height() << forcesign << r.x() << r.y() << noforcesign;
return str;
}
+static QString formatWindowTitle(const QString &title)
+{
+ QString result;
+ QTextStream(&result) << title << ' ' << QT_VERSION_STR << " ("
+ << QGuiApplication::platformName()
+ << '/' << QApplication::style()->objectName() << ')';
+ return result;
+}
+
class DemoContainerBase
{
public:
- DemoContainerBase() : m_widget(nullptr) {}
- virtual ~DemoContainerBase() {}
- QString name() { return option().names().first(); }
+ DemoContainerBase() = default;
+ virtual ~DemoContainerBase() = default;
+ QString name() { return option().names().constFirst(); }
virtual QCommandLineOption &option() = 0;
virtual void makeVisible(bool visible, QWidget *parent) = 0;
- QWidget *widget() { return m_widget; }
+ QWidget *widget() const { return m_widget; }
+
protected:
- QWidget *m_widget;
+ QWidget *m_widget = nullptr;
};
-typedef QList<DemoContainerBase*> DemoContainerList ;
-
+using DemoContainerList = QVector<DemoContainerBase*>;
template <class T>
class DemoContainer : public DemoContainerBase
@@ -93,16 +105,25 @@ public:
}
~DemoContainer() { delete m_widget; }
- QCommandLineOption &option() { return m_option; }
+ QCommandLineOption &option() override { return m_option; }
- void makeVisible(bool visible, QWidget *parent) {
+ void makeVisible(bool visible, QWidget *parent) override
+ {
if (visible && !m_widget) {
m_widget = new T;
+ if (m_widget->windowTitle().isEmpty()) {
+ QString title = m_option.description();
+ if (title.startsWith("Test ", Qt::CaseInsensitive))
+ title.remove(0, 5);
+ title[0] = title.at(0).toUpper();
+ m_widget->setWindowTitle(formatWindowTitle(title));
+ }
m_widget->installEventFilter(parent);
}
if (m_widget)
m_widget->setVisible(visible);
}
+
private:
QCommandLineOption m_option;
};
@@ -134,12 +155,15 @@ public:
connect(m_slider, &QSlider::sliderMoved, this, &LabelSlider::updateLabel);
connect(m_slider, &QSlider::valueChanged, this, &LabelSlider::valueChanged);
}
- void setValue(int scaleFactor) {
+ void setValue(int scaleFactor)
+ {
m_slider->setValue(scaleFactor);
updateLabel(scaleFactor);
}
+
private slots:
- void updateLabel(int scaleFactor) {
+ void updateLabel(int scaleFactor)
+ {
// slider value is scale factor times ten;
qreal scalefactorF = qreal(scaleFactor) / 10.0;
@@ -149,8 +173,10 @@ private slots:
number.append(".0");
m_label->setText(number);
}
+
signals:
void valueChanged(int scaleFactor);
+
private:
QSlider *m_slider;
QLabel *m_label;
@@ -172,31 +198,35 @@ static inline qreal getGlobalScaleFactor()
class DemoController : public QWidget
{
-Q_OBJECT
+ Q_OBJECT
public:
- DemoController(DemoContainerList *demos, QCommandLineParser *parser);
+ DemoController(DemoContainerList demos, QCommandLineParser *parser);
~DemoController();
+
protected:
- bool eventFilter(QObject *object, QEvent *event);
- void closeEvent(QCloseEvent *) { qApp->quit(); }
+ bool eventFilter(QObject *object, QEvent *event) override;
+ void closeEvent(QCloseEvent *) override { QCoreApplication::quit(); }
+
private slots:
void handleButton(int id, bool toggled);
+
private:
- DemoContainerList *m_demos;
+ DemoContainerList m_demos;
QButtonGroup *m_group;
};
-DemoController::DemoController(DemoContainerList *demos, QCommandLineParser *parser)
- : m_demos(demos)
+DemoController::DemoController(DemoContainerList demos, QCommandLineParser *parser)
+ : m_demos(std::move(demos))
{
- setWindowTitle("screen scale factors");
+ setWindowTitle(formatWindowTitle("Screen Scale Factors"));
setObjectName("controller"); // make WindowScaleFactorSetter skip this window
- QGridLayout *layout = new QGridLayout;
- setLayout(layout);
+ auto mainLayout = new QVBoxLayout(this);
+ auto scaleLayout = new QGridLayout;
+ mainLayout->addLayout(scaleLayout);
int layoutRow = 0;
- LabelSlider *globalScaleSlider = new LabelSlider(this, "Global scale factor", layout, layoutRow++);
+ LabelSlider *globalScaleSlider = new LabelSlider(this, "Global scale factor", scaleLayout, layoutRow++);
globalScaleSlider->setValue(int(getGlobalScaleFactor() * 10));
connect(globalScaleSlider, &LabelSlider::valueChanged, [](int scaleFactor){
// slider value is scale factor times ten;
@@ -205,13 +235,13 @@ DemoController::DemoController(DemoContainerList *demos, QCommandLineParser *par
});
// set up one scale control line per screen
- QList<QScreen *> screens = QGuiApplication::screens();
- foreach (QScreen *screen, screens) {
+ const auto screens = QGuiApplication::screens();
+ for (QScreen *screen : screens) {
// create scale control line
QSize screenSize = screen->geometry().size();
QString screenId = screen->name() + QLatin1Char(' ') + QString::number(screenSize.width())
+ QLatin1Char(' ') + QString::number(screenSize.height());
- LabelSlider *slider = new LabelSlider(this, screenId, layout, layoutRow++);
+ LabelSlider *slider = new LabelSlider(this, screenId, scaleLayout, layoutRow++);
slider->setValue(getScreenFactorWithoutPixelDensity(screen) * 10);
// handle slider value change
@@ -228,15 +258,18 @@ DemoController::DemoController(DemoContainerList *demos, QCommandLineParser *par
});
}
+ auto demoLayout = new QFormLayout;
+ mainLayout->addLayout(demoLayout);
m_group = new QButtonGroup(this);
m_group->setExclusive(false);
- for (int i = 0; i < m_demos->size(); ++i) {
- DemoContainerBase *demo = m_demos->at(i);
- QPushButton *button = new QPushButton(demo->name());
- button->setToolTip(demo->option().description());
+ for (int i = 0; i < m_demos.size(); ++i) {
+ DemoContainerBase *demo = m_demos.at(i);
+ QString name = demo->name();
+ name[0] = name.at(0).toUpper();
+ auto button = new QPushButton(name);
button->setCheckable(true);
- layout->addWidget(button, layoutRow++, 0, 1, -1);
+ demoLayout->addRow(demo->option().description(), button);
m_group->addButton(button, i);
if (parser->isSet(demo->option())) {
@@ -244,19 +277,20 @@ DemoController::DemoController(DemoContainerList *demos, QCommandLineParser *par
button->setChecked(true);
}
}
- connect(m_group, SIGNAL(buttonToggled(int, bool)), this, SLOT(handleButton(int, bool)));
+ connect(m_group, QOverload<int,bool>::of(&QButtonGroup::buttonToggled),
+ this, &DemoController::handleButton);
}
DemoController::~DemoController()
{
- qDeleteAll(*m_demos);
+ qDeleteAll(m_demos);
}
bool DemoController::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::Close) {
- for (int i = 0; i < m_demos->size(); ++i) {
- DemoContainerBase *demo = m_demos->at(i);
+ for (int i = 0; i < m_demos.size(); ++i) {
+ DemoContainerBase *demo = m_demos.at(i);
if (demo->widget() == object) {
m_group->button(i)->setChecked(false);
break;
@@ -268,15 +302,17 @@ bool DemoController::eventFilter(QObject *object, QEvent *event)
void DemoController::handleButton(int id, bool toggled)
{
- m_demos->at(id)->makeVisible(toggled, this);
+ m_demos.at(id)->makeVisible(toggled, this);
}
class PixmapPainter : public QWidget
{
public:
PixmapPainter();
- void paintEvent(QPaintEvent *event);
+ void paintEvent(QPaintEvent *event) override;
+
+private:
QPixmap pixmap1X;
QPixmap pixmap2X;
QPixmap pixmapLarge;
@@ -348,12 +384,14 @@ void PixmapPainter::paintEvent(QPaintEvent *)
class TiledPixmapPainter : public QWidget
{
public:
+ TiledPixmapPainter();
+
+ void paintEvent(QPaintEvent *event) override;
+
+private:
QPixmap pixmap1X;
QPixmap pixmap2X;
QPixmap pixmapLarge;
-
- TiledPixmapPainter();
- void paintEvent(QPaintEvent *event);
};
TiledPixmapPainter::TiledPixmapPainter()
@@ -404,6 +442,7 @@ class Labels : public QWidget
public:
Labels();
+private:
QPixmap pixmap1X;
QPixmap pixmap2X;
QPixmap pixmapLarge;
@@ -419,7 +458,7 @@ Labels::Labels()
qtIcon.addFile(":/qticon32.png");
qtIcon.addFile(":/qticon32@2x.png");
setWindowIcon(qtIcon);
- setWindowTitle("Labels");
+ setWindowTitle(formatWindowTitle("Labels"));
QLabel *label1x = new QLabel();
label1x->setPixmap(pixmap1X);
@@ -454,18 +493,17 @@ private:
QIcon qtIcon2x;
QToolBar *fileToolBar;
- int menuCount;
QAction *m_maskAction;
+ int menuCount = 0;
};
MainWindow::MainWindow()
- :menuCount(0)
{
// beware that QIcon auto-loads the @2x versions.
qtIcon1x.addFile(":/qticon16.png");
qtIcon2x.addFile(":/qticon32.png");
setWindowIcon(qtIcon);
- setWindowTitle("MainWindow");
+ setWindowTitle(formatWindowTitle("MainWindow"));
fileToolBar = addToolBar(tr("File"));
// fileToolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
@@ -484,7 +522,6 @@ MainWindow::MainWindow()
addNewMenu("&Help", 2);
}
-
QMenu *MainWindow::addNewMenu(const QString &title, int itemCount)
{
QMenu *menu = menuBar()->addMenu(title);
@@ -516,7 +553,7 @@ void MainWindow::maskActionToggled(bool t)
class StandardIcons : public QWidget
{
public:
- void paintEvent(QPaintEvent *)
+ void paintEvent(QPaintEvent *) override
{
int x = 10;
int y = 10;
@@ -538,7 +575,7 @@ public:
class Caching : public QWidget
{
public:
- void paintEvent(QPaintEvent *)
+ void paintEvent(QPaintEvent *) override
{
QSize layoutSize(75, 75);
@@ -576,16 +613,12 @@ public:
}
};
-class Style : public QWidget {
+class Style : public QWidget
+{
public:
- QPushButton *button;
- QLineEdit *lineEdit;
- QSlider *slider;
- QHBoxLayout *row1;
-
- Style() {
- row1 = new QHBoxLayout();
- setLayout(row1);
+ Style()
+ {
+ row1 = new QHBoxLayout(this);
button = new QPushButton();
button->setText("Test Button");
@@ -601,17 +634,23 @@ public:
row1->addWidget(new QSpinBox);
row1->addWidget(new QScrollBar);
- QTabBar *tab = new QTabBar();
+ auto tab = new QTabBar();
tab->addTab("Foo");
tab->addTab("Bar");
row1->addWidget(tab);
}
+
+private:
+ QPushButton *button;
+ QLineEdit *lineEdit;
+ QSlider *slider;
+ QHBoxLayout *row1;
};
class Fonts : public QWidget
{
public:
- void paintEvent(QPaintEvent *)
+ void paintEvent(QPaintEvent *) override
{
QPainter painter(this);
@@ -690,7 +729,7 @@ public:
iconNormalDpi.reset(new QIcon(path32_2)); // does not have a 2x version.
}
- void paintEvent(QPaintEvent *)
+ void paintEvent(QPaintEvent *) override
{
int x = 10;
int y = 10;
@@ -782,7 +821,7 @@ public:
tab->move(10, 100);
tab->show();
- QToolBar *toolBar = new QToolBar(this);
+ auto toolBar = new QToolBar(this);
toolBar->addAction(QIcon(":/qticon16.png"), "16");
toolBar->addAction(QIcon(":/qticon16@2x.png"), "16@2x");
toolBar->addAction(QIcon(":/qticon32.png"), "32");
@@ -796,11 +835,12 @@ public:
class LinePainter : public QWidget
{
public:
- void paintEvent(QPaintEvent *event);
- void mousePressEvent(QMouseEvent *event);
- void mouseReleaseEvent(QMouseEvent *event);
- void mouseMoveEvent(QMouseEvent *event);
+ void paintEvent(QPaintEvent *event) override;
+ void mousePressEvent(QMouseEvent *event) override;
+ void mouseReleaseEvent(QMouseEvent *event) override;
+ void mouseMoveEvent(QMouseEvent *event) override;
+private:
QPoint lastMousePoint;
QVector<QPoint> linePoints;
};
@@ -855,17 +895,15 @@ void LinePainter::mouseMoveEvent(QMouseEvent *event)
class CursorTester : public QWidget
{
public:
- CursorTester()
- :moveLabel(nullptr), moving(false)
- {
- }
+ CursorTester() = default;
inline QRect getRect(int idx) const
{
int h = height() / 2;
return QRect(10, 10 + h * (idx - 1), width() - 20, h - 20);
}
- void paintEvent(QPaintEvent *)
+
+ void paintEvent(QPaintEvent *) override
{
QPainter p(this);
QRect r1 = getRect(1);
@@ -899,7 +937,7 @@ public:
}
}
- void mousePressEvent(QMouseEvent *e)
+ void mousePressEvent(QMouseEvent *e) override
{
if (moving)
return;
@@ -923,7 +961,7 @@ public:
moveLabel->show();
}
- void mouseReleaseEvent(QMouseEvent *)
+ void mouseReleaseEvent(QMouseEvent *) override
{
if (moveLabel)
moveLabel->hide();
@@ -931,7 +969,7 @@ public:
moving = false;
}
- void mouseMoveEvent(QMouseEvent *e)
+ void mouseMoveEvent(QMouseEvent *e) override
{
if (!moving)
return;
@@ -943,32 +981,32 @@ public:
}
private:
- QLabel *moveLabel;
- bool useCursorPos;
- bool moving;
+ QLabel *moveLabel = nullptr;
QPoint mousePos;
+ bool useCursorPos = false;
+ bool moving = false;
};
-
class ScreenDisplayer : public QWidget
{
public:
- ScreenDisplayer()
- : QWidget(), moveLabel(nullptr), scaleFactor(1.0)
- {
- }
+ ScreenDisplayer() = default;
- void timerEvent(QTimerEvent *) {
+ void timerEvent(QTimerEvent *) override
+ {
update();
}
- void mousePressEvent(QMouseEvent *) {
+ void mousePressEvent(QMouseEvent *) override
+ {
if (!moveLabel)
moveLabel = new QLabel(this,Qt::BypassWindowManagerHint|Qt::FramelessWindowHint|Qt::Window );
moveLabel->setText("Hello, Qt this is a label\nwith some text");
moveLabel->show();
}
- void mouseMoveEvent(QMouseEvent *e) {
+
+ void mouseMoveEvent(QMouseEvent *e) override
+ {
if (!moveLabel)
return;
moveLabel->move(e->pos() / scaleFactor);
@@ -978,23 +1016,30 @@ public:
dbg << moveLabel->geometry();
moveLabel->setText(str);
}
- void mouseReleaseEvent(QMouseEvent *) {
+
+ void mouseReleaseEvent(QMouseEvent *) override
+ {
if (moveLabel)
moveLabel->hide();
}
- void showEvent(QShowEvent *) {
+
+ void showEvent(QShowEvent *) override
+ {
refreshTimer.start(300, this);
}
- void hideEvent(QHideEvent *) {
+
+ void hideEvent(QHideEvent *) override
+ {
refreshTimer.stop();
}
- void paintEvent(QPaintEvent *) {
+
+ void paintEvent(QPaintEvent *) override
+ {
QPainter p(this);
QRectF total;
- QList<QScreen*> screens = qApp->screens();
- foreach (QScreen *screen, screens) {
+ const auto screens = QGuiApplication::screens();
+ for (const QScreen *screen : screens)
total |= screen->geometry();
- }
if (total.isEmpty())
return;
@@ -1006,8 +1051,7 @@ public:
p.setPen(QPen(Qt::white, 10));
p.setBrush(Qt::gray);
-
- foreach (QScreen *screen, screens) {
+ for (const QScreen *screen : screens) {
p.drawRect(screen->geometry());
QFont f = font();
f.setPixelSize(screen->geometry().height() / 8);
@@ -1015,7 +1059,9 @@ public:
p.drawText(screen->geometry(), Qt::AlignCenter, screen->name());
}
p.setBrush(QColor(200,220,255,127));
- foreach (QWidget *widget, QApplication::topLevelWidgets()) {
+
+ const auto topLevels = QApplication::topLevelWidgets();
+ for (QWidget *widget : topLevels) {
if (!widget->isHidden())
p.drawRect(widget->geometry());
}
@@ -1028,42 +1074,51 @@ public:
cursorShape.translate(QCursor::pos());
p.drawPolygon(cursorShape);
}
+
private:
- QLabel *moveLabel;
+ QLabel *moveLabel = nullptr;
+ qreal scaleFactor = 1;
QBasicTimer refreshTimer;
- qreal scaleFactor;
};
class PhysicalSizeTest : public QWidget
{
-Q_OBJECT
+ Q_OBJECT
public:
- PhysicalSizeTest() : QWidget(), m_ignoreResize(false) {}
- void paintEvent(QPaintEvent *event);
- void resizeEvent(QResizeEvent *) {
+ PhysicalSizeTest() = default;
+
+ void paintEvent(QPaintEvent *event) override;
+
+ void resizeEvent(QResizeEvent *) override
+ {
qreal ppi = window()->windowHandle()->screen()->physicalDotsPerInchX();
QSizeF s = size();
if (!m_ignoreResize)
m_physicalSize = s / ppi;
}
- bool event(QEvent *event) {
+
+ bool event(QEvent *event) override
+ {
if (event->type() == QEvent::ScreenChangeInternal) {
// we will get resize events when the scale factor changes
m_ignoreResize = true;
- QTimer::singleShot(100, this, SLOT(handleScreenChange()));
+ QTimer::singleShot(100, this, &PhysicalSizeTest::handleScreenChange);
}
return QWidget::event(event);
}
+
public slots:
- void handleScreenChange() {
+ void handleScreenChange()
+ {
qreal ppi = window()->windowHandle()->screen()->physicalDotsPerInchX();
QSizeF newSize = m_physicalSize * ppi;
resize(newSize.toSize());
m_ignoreResize = false;
}
+
private:
QSizeF m_physicalSize;
- bool m_ignoreResize;
+ bool m_ignoreResize = false;
};
void PhysicalSizeTest::paintEvent(QPaintEvent *)
@@ -1166,8 +1221,9 @@ void PhysicalSizeTest::paintEvent(QPaintEvent *)
class GraphicsViewCaching : public QGraphicsView
{
public:
- GraphicsViewCaching() {
- QGraphicsScene *scene = new QGraphicsScene(0, 0, 400, 400);
+ GraphicsViewCaching()
+ {
+ auto scene = new QGraphicsScene(0, 0, 400, 400);
QGraphicsTextItem *item = scene->addText("NoCache");
item->setCacheMode(QGraphicsItem::NoCache);
@@ -1187,14 +1243,13 @@ public:
class MetricsTest : public QWidget
{
- QPlainTextEdit *m_textEdit;
-
+ Q_OBJECT
public:
MetricsTest()
{
- qDebug() << R"(
-MetricsTest
-Relevant environment variables are:
+ qDebug().noquote().nospace() << "MetricsTest " << QT_VERSION_STR
+ << ' ' << QGuiApplication::platformName() << '\n'
+<< R"(Relevant environment variables are:
QT_FONT_DPI=N
QT_SCALE_FACTOR=n
QT_ENABLE_HIGHDPI_SCALING=0|1
@@ -1205,12 +1260,23 @@ QT_DPI_ADJUSTMENT_POLICY=AdjustDpi|DontAdjustDpi|AdjustUpOnly)";
resize(480, 360);
- QVBoxLayout *layout = new QVBoxLayout();
- setLayout(layout);
+ auto layout = new QVBoxLayout(this);
m_textEdit = new QPlainTextEdit;
m_textEdit->setReadOnly(true);
layout->addWidget(m_textEdit);
+ setWindowTitle(formatWindowTitle("Screens"));
+ }
+
+ void setVisible(bool visible) override
+ {
+ QWidget::setVisible(visible);
+ if (visible && !m_screenChangedConnected) {
+ m_screenChangedConnected = true;
+ QObject::connect(windowHandle(), &QWindow::screenChanged,
+ this, &MetricsTest::screenChanged);
+ updateMetrics();
+ }
}
void updateMetrics()
@@ -1254,24 +1320,42 @@ QT_DPI_ADJUSTMENT_POLICY=AdjustDpi|DontAdjustDpi|AdjustUpOnly)";
m_textEdit->setPlainText(text);
}
- void paintEvent(QPaintEvent *ev)
+private slots:
+ void screenChanged()
{
- // We get a paint event on screen change, so this is a convenient place
- // to update the metrics, at the possible risk of doing something else
- // than painting in a paint event.
+ qDebug().noquote() << __FUNCTION__ << windowHandle()->screen()->name();
updateMetrics();
- QWidget::paintEvent(ev);
}
+
+private:
+ QPlainTextEdit *m_textEdit;
+ bool m_screenChangedConnected = false;
};
int main(int argc, char **argv)
{
+#define NOSCALINGOPTION "noscaling"
+#define SCALINGOPTION "scaling"
+
+ qInfo("High DPI tester %s", QT_VERSION_STR);
+
+ int preAppOptionCount = 0;
+ for (int a = 1; a < argc; ++a) {
+ if (qstrcmp(argv[a], "--" NOSCALINGOPTION) == 0) {
+ QCoreApplication::setAttribute(Qt::AA_DisableHighDpiScaling);
+ preAppOptionCount++;
+ qInfo("AA_DisableHighDpiScaling");
+ } else if (qstrcmp(argv[a], "--" SCALINGOPTION) == 0) {
+ QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
+ preAppOptionCount++;
+ qInfo("AA_EnableHighDpiScaling");
+ }
+ }
+
QApplication app(argc, argv);
QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
- int argumentCount = QCoreApplication::arguments().count();
-
QCommandLineParser parser;
parser.setApplicationDescription("High DPI tester. Pass one or more of the options to\n"
"test various high-dpi aspects. \n"
@@ -1281,7 +1365,8 @@ int main(int argc, char **argv)
parser.addVersionOption();
QCommandLineOption controllerOption("interactive", "Show configuration window.");
parser.addOption(controllerOption);
-
+ parser.addOption(QCommandLineOption(NOSCALINGOPTION, "Set AA_DisableHighDpiScaling"));
+ parser.addOption(QCommandLineOption(SCALINGOPTION, "Set AA_EnableHighDpiScaling"));
DemoContainerList demoList;
demoList << new DemoContainer<PixmapPainter>("pixmap", "Test pixmap painter");
@@ -1300,17 +1385,17 @@ int main(int argc, char **argv)
demoList << new DemoContainer<ScreenDisplayer>("screens", "Test screen and window positioning");
demoList << new DemoContainer<PhysicalSizeTest>("physicalsize", "Test manual highdpi support using physicalDotsPerInch");
demoList << new DemoContainer<GraphicsViewCaching>("graphicsview", "Test QGraphicsView caching");
- demoList << new DemoContainer<MetricsTest>("metrics", "Show display metrics");
+ demoList << new DemoContainer<MetricsTest>("metrics", "Show screen metrics");
- foreach (DemoContainerBase *demo, demoList)
+ for (DemoContainerBase *demo : qAsConst(demoList))
parser.addOption(demo->option());
parser.process(app);
//controller takes ownership of all demos
- DemoController controller(&demoList, &parser);
+ DemoController controller(demoList, &parser);
- if (parser.isSet(controllerOption) || argumentCount <= 1)
+ if (parser.isSet(controllerOption) || (QCoreApplication::arguments().count() - preAppOptionCount) <= 1)
controller.show();
if (QApplication::topLevelWidgets().isEmpty())