summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-11-30 00:51:32 +0000
committerThe Qt Project <gerrit-noreply@qt-project.org>2017-11-30 00:51:32 +0000
commit498ef7f9d77fca75bcba2f657aaac38c8dc78aea (patch)
tree025636092945c4d8c0e9de6fa69db15da204b648 /tests/auto/corelib
parent4d0add31fd0a69aca7c7c852f22531dd98922c62 (diff)
parent153e8b49adfe210cb00490284a14c94c08e03c3f (diff)
Merge "Merge remote-tracking branch 'origin/5.10' into dev" into refs/staging/dev
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST2
-rw-r--r--tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp395
-rw-r--r--tests/auto/corelib/io/largefile/tst_largefile.cpp4
-rw-r--r--tests/auto/corelib/io/qfile/tst_qfile.cpp117
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+qnx/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+qnx/test20
-rw-r--r--tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test0
-rw-r--r--tests/auto/corelib/io/qfileselector/qfileselector.qrc3
-rw-r--r--tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp2
-rw-r--r--tests/auto/corelib/io/qstandardpaths/BLACKLIST3
-rw-r--r--tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro2
-rw-r--r--tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp13
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro2
-rw-r--r--tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp16
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp35
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp4
-rw-r--r--tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp1
-rw-r--r--tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp3
-rw-r--r--tests/auto/corelib/thread/qfuture/tst_qfuture.cpp3
-rw-r--r--tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp11
-rw-r--r--tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp5
21 files changed, 469 insertions, 152 deletions
diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST b/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST
index 391e3f67af..2a31afd735 100644
--- a/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST
+++ b/tests/auto/corelib/animation/qsequentialanimationgroup/BLACKLIST
@@ -3,3 +3,5 @@ windows
[finishWithUncontrolledAnimation]
windows
osx-10.12
+[groupWithZeroDurationAnimations]
+osx
diff --git a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
index 4b38d46317..220ec9a2f8 100644
--- a/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
+++ b/tests/auto/corelib/global/qrandomgenerator/tst_qrandomgenerator.cpp
@@ -43,8 +43,8 @@
#define COMMA ,
#define QVERIFY_3TIMES(statement) \
do {\
- if (!QTest::qVerify(static_cast<bool>(statement), #statement, "1st try", __FILE__, __LINE__))\
- if (!QTest::qVerify(static_cast<bool>(statement), #statement, "2nd try", __FILE__, __LINE__))\
+ if (!static_cast<bool>(statement))\
+ if (!static_cast<bool>(statement))\
if (!QTest::qVerify(static_cast<bool>(statement), #statement, "3rd try", __FILE__, __LINE__))\
return;\
} while (0)
@@ -71,6 +71,15 @@ public slots:
void cleanup() { setRNGControl(0); }
private slots:
+ void basics();
+ void knownSequence();
+ void discard();
+ void copying();
+ void copyingGlobal();
+ void copyingSystem();
+ void systemRng();
+ void securelySeeding();
+
void generate32_data();
void generate32();
void generate64_data() { generate32_data(); }
@@ -110,19 +119,212 @@ private slots:
void stdRandomDistributions();
};
+// The first 20 results of the sequence:
+static const quint32 defaultRngResults[] = {
+ 853323747U, 2396352728U, 3025954838U, 2985633182U, 2815751046U,
+ 340588426U, 3587208406U, 298087538U, 2912478009U, 3642122814U,
+ 3202916223U, 799257577U, 1872145992U, 639469699U, 3201121432U,
+ 2388658094U, 1735523408U, 2215232359U, 668106566U, 2554687763U
+};
+
+
using namespace std;
QT_WARNING_DISABLE_GCC("-Wfloat-equal")
QT_WARNING_DISABLE_CLANG("-Wfloat-equal")
+struct RandomGenerator : public QRandomGenerator
+{
+ RandomGenerator(uint control)
+ : QRandomGenerator(control ?
+ QRandomGenerator(control & RandomDataMask) :
+ *QRandomGenerator::global())
+ {
+ setRNGControl(control);
+ }
+};
+
+void tst_QRandomGenerator::basics()
+{
+ // default constructible
+ QRandomGenerator rng;
+
+ // copyable && movable
+ rng = rng;
+ rng = std::move(rng);
+
+ // 64-bit
+ QRandomGenerator64 rng64;
+ rng64 = rng64;
+ rng64 = std::move(rng64);
+
+ // 32- and 64-bit should be interchangeable:
+ rng = rng64;
+ rng64 = rng;
+ rng = std::move(rng64);
+ rng64 = std::move(rng);
+
+ rng = QRandomGenerator64::securelySeeded();
+ rng64 = QRandomGenerator::securelySeeded();
+
+ // access global
+ QRandomGenerator *global = QRandomGenerator::global();
+ QRandomGenerator globalCopy = *global;
+ globalCopy = *global;
+ QRandomGenerator64 *global64 = QRandomGenerator64::global();
+ QRandomGenerator64 globalCopy64 = *global64;
+ globalCopy64 = *global64;
+
+ // access system
+ QRandomGenerator *system = QRandomGenerator::system();
+ QRandomGenerator systemRng = *system;
+ systemRng = *system;
+
+ QRandomGenerator64 *system64 = QRandomGenerator64::system();
+ QRandomGenerator64 systemRng64 = *system64;
+ systemRng64 = *system64;
+
+ Q_STATIC_ASSERT(std::is_same<decltype(rng64.generate()) COMMA quint64>::value);
+ Q_STATIC_ASSERT(std::is_same<decltype(system64->generate()) COMMA quint64>::value);
+}
+
+void tst_QRandomGenerator::knownSequence()
+{
+ QRandomGenerator rng;
+ for (quint32 x : defaultRngResults)
+ QCOMPARE(rng(), x);
+
+ // should work again if we reseed it
+ rng.seed();
+ for (quint32 x : defaultRngResults)
+ QCOMPARE(rng(), x);
+}
+
+void tst_QRandomGenerator::discard()
+{
+ QRandomGenerator rng;
+ rng.discard(1);
+ QCOMPARE(rng(), defaultRngResults[1]);
+
+ rng.discard(9);
+ QCOMPARE(rng(), defaultRngResults[11]);
+}
+
+void tst_QRandomGenerator::copying()
+{
+ QRandomGenerator rng1;
+ QRandomGenerator rng2 = rng1;
+ QCOMPARE(rng1, rng2);
+
+ quint32 samples[20];
+ rng1.fillRange(samples);
+
+ // not equal anymore
+ QVERIFY(rng1 != rng2);
+
+ // should produce the same sequence, whichever it was
+ for (quint32 x : samples)
+ QCOMPARE(rng2(), x);
+
+ // now they should compare equal again
+ QCOMPARE(rng1, rng2);
+}
+
+void tst_QRandomGenerator::copyingGlobal()
+{
+ QRandomGenerator &global = *QRandomGenerator::global();
+ QRandomGenerator copy = global;
+ QCOMPARE(copy, global);
+ QCOMPARE(global, copy);
+
+ quint32 samples[20];
+ global.fillRange(samples);
+
+ // not equal anymore
+ QVERIFY(copy != global);
+
+ // should produce the same sequence, whichever it was
+ for (quint32 x : samples)
+ QCOMPARE(copy(), x);
+
+ // equal again
+ QCOMPARE(copy, global);
+ QCOMPARE(global, copy);
+}
+
+void tst_QRandomGenerator::copyingSystem()
+{
+ QRandomGenerator &system = *QRandomGenerator::system();
+ QRandomGenerator copy = system;
+ QRandomGenerator copy2 = copy;
+ copy2 = copy;
+ QCOMPARE(system, copy);
+ QCOMPARE(copy, copy2);
+
+ quint32 samples[20];
+ copy2.fillRange(samples);
+
+ // they still compre equally
+ QCOMPARE(system, copy);
+ QCOMPARE(copy, copy2);
+
+ // should NOT produce the same sequence, whichever it was
+ int sameCount = 0;
+ for (quint32 x : samples)
+ sameCount += (copy() == x);
+ QVERIFY(sameCount < 20);
+
+ QCOMPARE(system, copy);
+ QCOMPARE(copy, copy2);
+}
+
+void tst_QRandomGenerator::systemRng()
+{
+ QRandomGenerator *rng = QRandomGenerator::system();
+ rng->generate();
+ rng->generate64();
+ rng->generateDouble();
+ rng->bounded(100);
+ rng->bounded(100U);
+
+#ifdef QT_BUILD_INTERNAL
+ quint32 setpoint = std::numeric_limits<int>::max();
+ ++setpoint;
+ quint64 setpoint64 = quint64(setpoint) << 32 | setpoint;
+ setRNGControl(SetRandomData | setpoint);
+
+ QCOMPARE(rng->generate(), setpoint);
+ QCOMPARE(rng->generate64(), setpoint64);
+ QCOMPARE(rng->generateDouble(), ldexp(setpoint64, -64));
+ QCOMPARE(rng->bounded(100), 50);
+#endif
+}
+
+void tst_QRandomGenerator::securelySeeding()
+{
+ QRandomGenerator rng1 = QRandomGenerator::securelySeeded();
+ QRandomGenerator rng2 = QRandomGenerator::securelySeeded();
+
+ quint32 samples[20];
+ rng1.fillRange(samples);
+
+ // should NOT produce the same sequence, whichever it was
+ int sameCount = 0;
+ for (quint32 x : samples)
+ sameCount += (rng2() == x);
+ QVERIFY(sameCount < 20);
+}
+
void tst_QRandomGenerator::generate32_data()
{
QTest::addColumn<uint>("control");
- QTest::newRow("default") << 0U;
+ QTest::newRow("fixed") << (RandomValue32 & RandomDataMask);
+ QTest::newRow("global") << 0U;
#ifdef QT_BUILD_INTERNAL
- QTest::newRow("direct") << uint(SkipMemfill);
- QTest::newRow("system") << uint(SkipHWRNG);
+ if (qt_has_hwrng())
+ QTest::newRow("hwrng") << uint(UseSystemRNG);
+ QTest::newRow("system") << uint(UseSystemRNG | SkipHWRNG);
# ifdef HAVE_FALLBACK_ENGINE
- QTest::newRow("fallback") << uint(SkipHWRNG | SkipSystemRNG);
+ QTest::newRow("system-fallback") << uint(UseSystemRNG | SkipHWRNG | SkipSystemRNG);
# endif
#endif
}
@@ -130,39 +332,40 @@ void tst_QRandomGenerator::generate32_data()
void tst_QRandomGenerator::generate32()
{
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
- quint32 value = QRandomGenerator::generate();
+ QVERIFY_3TIMES([&] {
+ quint32 value = rng.generate();
return value != 0 && value != RandomValue32;
}());
}
// and should hopefully be different from repeated calls
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::generate() != QRandomGenerator::generate());
+ QVERIFY_3TIMES(rng.generate() != rng.generate());
}
void tst_QRandomGenerator::generate64()
{
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
+ QVERIFY_3TIMES(rng.generate64() > std::numeric_limits<quint32>::max());
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
- quint64 value = QRandomGenerator::generate();
+ QVERIFY_3TIMES([&] {
+ quint64 value = rng.generate64();
return value != 0 && value != RandomValue32 && value != RandomValue64;
}());
}
// and should hopefully be different from repeated calls
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::generate64() != QRandomGenerator::generate64());
+ QVERIFY_3TIMES(rng.generate64() != rng.generate64());
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::generate() != quint32(QRandomGenerator::generate64()));
+ QVERIFY_3TIMES(rng.generate() != quint32(rng.generate64()));
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::generate() != (QRandomGenerator::generate64() >> 32));
+ QVERIFY_3TIMES(rng.generate() != (rng.generate64() >> 32));
}
void tst_QRandomGenerator::quality()
@@ -191,7 +394,9 @@ void tst_QRandomGenerator::quality()
Q_STATIC_ASSERT(FailureThreshold > AcceptableThreshold);
QFETCH(uint, control);
- setRNGControl(control);
+ if (control & RandomDataMask)
+ return;
+ RandomGenerator rng(control);
int histogram[UCHAR_MAX + 1];
memset(histogram, 0, sizeof(histogram));
@@ -200,7 +405,7 @@ void tst_QRandomGenerator::quality()
// test the quality of the generator
quint32 buffer[BufferCount];
memset(buffer, 0xcc, sizeof(buffer));
- generate_n(buffer, +BufferCount, [] { return QRandomGenerator::generate(); });
+ generate_n(buffer, +BufferCount, [&] { return rng.generate(); });
quint8 *ptr = reinterpret_cast<quint8 *>(buffer);
quint8 *end = ptr + sizeof(buffer);
@@ -225,20 +430,20 @@ void tst_QRandomGenerator::quality()
template <typename T> void fillRange_template()
{
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
+ QVERIFY_3TIMES([&] {
T value[1] = { RandomValue32 };
- QRandomGenerator::fillRange(value);
+ rng.fillRange(value);
return value[0] != 0 && value[0] != RandomValue32;
}());
}
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
+ QVERIFY_3TIMES([&] {
T array[2] = {};
- QRandomGenerator::fillRange(array);
+ rng.fillRange(array);
return array[0] != array[1];
}());
}
@@ -246,18 +451,18 @@ template <typename T> void fillRange_template()
if (sizeof(T) > sizeof(quint32)) {
// just to shut up a warning about shifting uint more than the width
enum { Shift = sizeof(T) / 2 * CHAR_BIT };
- QVERIFY_3TIMES([] {
+ QVERIFY_3TIMES([&] {
T value[1] = { };
- QRandomGenerator::fillRange(value);
+ rng.fillRange(value);
return quint32(value[0] >> Shift) != quint32(value[0]);
}());
}
// fill in a longer range
- auto longerArrayCheck = [] {
+ auto longerArrayCheck = [&] {
T array[32];
memset(array, 0, sizeof(array));
- QRandomGenerator::fillRange(array);
+ rng.fillRange(array);
if (sizeof(T) == sizeof(RandomValue64)
&& find(begin(array), end(array), RandomValue64) != end(array))
return false;
@@ -274,11 +479,11 @@ void tst_QRandomGenerator::fillRangeULLong() { fillRange_template<qulonglong>();
template <typename T> void generate_template()
{
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
// almost the same as fillRange, but limited to 32 bits
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
+ QVERIFY_3TIMES([&] {
T value[1] = { RandomValue32 };
QRandomGenerator().generate(begin(value), end(value));
return value[0] != 0 && value[0] != RandomValue32
@@ -287,10 +492,10 @@ template <typename T> void generate_template()
}
// fill in a longer range
- auto longerArrayCheck = [] {
+ auto longerArrayCheck = [&] {
T array[72] = {}; // at least 256 bytes
QRandomGenerator().generate(begin(array), end(array));
- return find_if(begin(array), end(array), [](T cur) {
+ return find_if(begin(array), end(array), [&](T cur) {
return cur == 0 || cur == RandomValue32 ||
cur == RandomValue64 || cur > numeric_limits<quint32>::max();
}) == end(array);
@@ -304,12 +509,12 @@ void tst_QRandomGenerator::generateULLong() { generate_template<qulonglong>(); }
void tst_QRandomGenerator::generateNonContiguous()
{
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
QLinkedList<quint64> list = { 0, 0, 0, 0, 0, 0, 0, 0 };
auto longerArrayCheck = [&] {
QRandomGenerator().generate(list.begin(), list.end());
- return find_if(list.begin(), list.end(), [](quint64 cur) {
+ return find_if(list.begin(), list.end(), [&](quint64 cur) {
return cur == 0 || cur == RandomValue32 ||
cur == RandomValue64 || cur > numeric_limits<quint32>::max();
}) == list.end();
@@ -327,7 +532,7 @@ void tst_QRandomGenerator::bounded_data()
QTest::addColumn<quint32>("sup");
QTest::addColumn<quint32>("expected");
- auto newRow = [](quint32 val, quint32 sup) {
+ auto newRow = [&](quint32 val, quint32 sup) {
// calculate the scaled value
quint64 scaled = val;
scaled <<= 32;
@@ -353,31 +558,31 @@ void tst_QRandomGenerator::bounded()
QFETCH(uint, control);
QFETCH(quint32, sup);
QFETCH(quint32, expected);
- setRNGControl(control);
+ RandomGenerator rng(control);
- quint32 value = QRandomGenerator::bounded(sup);
+ quint32 value = rng.bounded(sup);
QVERIFY(value < sup);
QCOMPARE(value, expected);
- int ivalue = QRandomGenerator::bounded(sup);
+ int ivalue = rng.bounded(sup);
QVERIFY(ivalue < int(sup));
QCOMPARE(ivalue, int(expected));
// confirm only the bound now
- setRNGControl(control & (SkipHWRNG|SkipSystemRNG));
- value = QRandomGenerator::bounded(sup);
+ setRNGControl(control & (SkipHWRNG|SkipSystemRNG|UseSystemRNG));
+ value = rng.bounded(sup);
QVERIFY(value < sup);
- value = QRandomGenerator::bounded(sup / 2, 3 * sup / 2);
+ value = rng.bounded(sup / 2, 3 * sup / 2);
QVERIFY(value >= sup / 2);
QVERIFY(value < 3 * sup / 2);
- ivalue = QRandomGenerator::bounded(-int(sup), int(sup));
+ ivalue = rng.bounded(-int(sup), int(sup));
QVERIFY(ivalue >= -int(sup));
QVERIFY(ivalue < int(sup));
// wholly negative range
- ivalue = QRandomGenerator::bounded(-int(sup), 0);
+ ivalue = rng.bounded(-int(sup), 0);
QVERIFY(ivalue >= -int(sup));
QVERIFY(ivalue < 0);
}
@@ -408,7 +613,9 @@ void tst_QRandomGenerator::boundedQuality()
Q_STATIC_ASSERT(FailureThreshold > AcceptableThreshold);
QFETCH(uint, control);
- setRNGControl(control);
+ if (control & RandomDataMask)
+ return;
+ RandomGenerator rng(control);
int histogram[Bound];
memset(histogram, 0, sizeof(histogram));
@@ -416,7 +623,7 @@ void tst_QRandomGenerator::boundedQuality()
{
// test the quality of the generator
QVector<quint32> buffer(BufferCount, 0xcdcdcdcd);
- generate(buffer.begin(), buffer.end(), [] { return QRandomGenerator::bounded(Bound); });
+ generate(buffer.begin(), buffer.end(), [&] { return rng.bounded(Bound); });
for (quint32 value : qAsConst(buffer)) {
QVERIFY(value < Bound);
@@ -442,24 +649,26 @@ void tst_QRandomGenerator::boundedQuality()
void tst_QRandomGenerator::generateReal()
{
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
- qreal value = QRandomGenerator::generateDouble();
+ QVERIFY_3TIMES([&] {
+ qreal value = rng.generateDouble();
return value >= 0 && value < 1 && value != RandomValueFP;
}());
}
// and should hopefully be different from repeated calls
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(QRandomGenerator::generateDouble() != QRandomGenerator::generateDouble());
+ QVERIFY_3TIMES(rng.generateDouble() != rng.generateDouble());
}
void tst_QRandomGenerator::qualityReal()
{
QFETCH(uint, control);
- setRNGControl(control);
+ if (control & RandomDataMask)
+ return;
+ RandomGenerator rng(control);
enum {
SampleSize = 160,
@@ -475,7 +684,7 @@ void tst_QRandomGenerator::qualityReal()
};
double data[SampleSize];
- std::generate(std::begin(data), std::end(data), &QRandomGenerator::generateDouble);
+ std::generate(std::begin(data), std::end(data), [&rng] { return rng.generateDouble(); });
int aboveHalf = 0;
int belowOneEighth = 0;
@@ -504,12 +713,22 @@ void tst_QRandomGenerator::qualityReal()
template <typename Engine> void seedStdRandomEngine()
{
- QRandomGenerator rd;
- Engine e(rd);
- QVERIFY_3TIMES(e() != 0);
+ {
+ QRandomGenerator &rd = *QRandomGenerator::system();
+ Engine e(rd);
+ QVERIFY_3TIMES(e() != 0);
+
+ e.seed(rd);
+ QVERIFY_3TIMES(e() != 0);
+ }
+ {
+ QRandomGenerator64 &rd = *QRandomGenerator64::system();
+ Engine e(rd);
+ QVERIFY_3TIMES(e() != 0);
- e.seed(rd);
- QVERIFY_3TIMES(e() != 0);
+ e.seed(rd);
+ QVERIFY_3TIMES(e() != 0);
+ }
}
void tst_QRandomGenerator::seedStdRandomEngines()
@@ -534,12 +753,16 @@ void tst_QRandomGenerator::stdUniformIntDistribution_data()
QTest::addColumn<uint>("control");
QTest::addColumn<quint32>("max");
- auto newRow = [](quint32 max) {
- QTest::addRow("default:%u", max) << 0U << max;
- QTest::addRow("system:%u", max) << uint(SkipHWRNG) << max;
- #ifdef HAVE_FALLBACK_ENGINE
- QTest::addRow("fallback:%u", max) << uint(SkipHWRNG | SkipSystemRNG) << max;
- #endif
+ auto newRow = [&](quint32 max) {
+#ifdef QT_BUILD_INTERNAL
+ if (qt_has_hwrng())
+ QTest::addRow("hwrng:%u", max) << uint(UseSystemRNG) << max;
+ QTest::addRow("system:%u", max) << uint(UseSystemRNG | SkipHWRNG) << max;
+# ifdef HAVE_FALLBACK_ENGINE
+ QTest::addRow("system-fallback:%u", max) << uint(UseSystemRNG | SkipHWRNG | SkipSystemRNG) << max;
+# endif
+#endif
+ QTest::addRow("global:%u", max) << 0U << max;
};
// useless: we can only generate zeroes:
@@ -554,7 +777,7 @@ void tst_QRandomGenerator::stdUniformIntDistribution()
{
QFETCH(uint, control);
QFETCH(quint32, max);
- setRNGControl(control & (SkipHWRNG|SkipSystemRNG));
+ RandomGenerator rng(control);
{
QRandomGenerator rd;
@@ -622,21 +845,19 @@ void tst_QRandomGenerator::stdGenerateCanonical()
QSKIP("MSVC 2013's std::generate_canonical is broken");
#else
QFETCH(uint, control);
- setRNGControl(control);
+ RandomGenerator rng(control);
for (int i = 0; i < 4; ++i) {
- QVERIFY_3TIMES([] {
- QRandomGenerator rd;
- qreal value = std::generate_canonical<qreal COMMA 32>(rd);
+ QVERIFY_3TIMES([&] {
+ qreal value = std::generate_canonical<qreal COMMA 32>(rng);
return value > 0 && value < 1 && value != RandomValueFP;
}());
}
// and should hopefully be different from repeated calls
- QRandomGenerator rd;
for (int i = 0; i < 4; ++i)
- QVERIFY_3TIMES(std::generate_canonical<qreal COMMA 32>(rd) !=
- std::generate_canonical<qreal COMMA 32>(rd));
+ QVERIFY_3TIMES(std::generate_canonical<qreal COMMA 32>(rng) !=
+ std::generate_canonical<qreal COMMA 32>(rng));
#endif
}
@@ -650,12 +871,16 @@ void tst_QRandomGenerator::stdUniformRealDistribution_data()
QTest::addColumn<double>("min");
QTest::addColumn<double>("sup");
- auto newRow = [](double min, double sup) {
- QTest::addRow("default:%g-%g", min, sup) << 0U << min << sup;
- QTest::addRow("system:%g-%g", min, sup) << uint(SkipHWRNG) << min << sup;
- #ifdef HAVE_FALLBACK_ENGINE
- QTest::addRow("fallback:%g-%g", min, sup) << uint(SkipHWRNG | SkipSystemRNG) << min << sup;
- #endif
+ auto newRow = [&](double min, double sup) {
+#ifdef QT_BUILD_INTERNAL
+ if (qt_has_hwrng())
+ QTest::addRow("hwrng:%g-%g", min, sup) << uint(UseSystemRNG) << min << sup;
+ QTest::addRow("system:%g-%g", min, sup) << uint(UseSystemRNG | SkipHWRNG) << min << sup;
+# ifdef HAVE_FALLBACK_ENGINE
+ QTest::addRow("system-fallback:%g-%g", min, sup) << uint(UseSystemRNG | SkipHWRNG | SkipSystemRNG) << min << sup;
+# endif
+#endif
+ QTest::addRow("global:%g-%g", min, sup) << 0U << min << sup;
};
newRow(0, 0); // useless: we can only generate zeroes
@@ -671,7 +896,7 @@ void tst_QRandomGenerator::stdUniformRealDistribution()
QFETCH(uint, control);
QFETCH(double, min);
QFETCH(double, sup);
- setRNGControl(control & (SkipHWRNG|SkipSystemRNG));
+ RandomGenerator rng(control & (SkipHWRNG|SkipSystemRNG|UseSystemRNG));
{
QRandomGenerator rd;
@@ -696,13 +921,9 @@ void tst_QRandomGenerator::stdUniformRealDistribution()
}
}
-void tst_QRandomGenerator::stdRandomDistributions()
+template <typename Generator> void stdRandomDistributions_template()
{
- // just a compile check for some of the distributions, besides
- // std::uniform_int_distribution and std::uniform_real_distribution (tested
- // above)
-
- QRandomGenerator rd;
+ Generator rd;
std::bernoulli_distribution()(rd);
@@ -724,6 +945,16 @@ void tst_QRandomGenerator::stdRandomDistributions()
}
}
+void tst_QRandomGenerator::stdRandomDistributions()
+{
+ // just a compile check for some of the distributions, besides
+ // std::uniform_int_distribution and std::uniform_real_distribution (tested
+ // above)
+
+ stdRandomDistributions_template<QRandomGenerator>();
+ stdRandomDistributions_template<QRandomGenerator64>();
+}
+
QTEST_APPLESS_MAIN(tst_QRandomGenerator)
#include "tst_qrandomgenerator.moc"
diff --git a/tests/auto/corelib/io/largefile/tst_largefile.cpp b/tests/auto/corelib/io/largefile/tst_largefile.cpp
index 5975303ca6..2d13e6166d 100644
--- a/tests/auto/corelib/io/largefile/tst_largefile.cpp
+++ b/tests/auto/corelib/io/largefile/tst_largefile.cpp
@@ -31,6 +31,7 @@
#include <QtAlgorithms>
#include <QFile>
#include <QFileInfo>
+#include <QRandomGenerator>
#include <qplatformdefs.h>
#include <QDebug>
@@ -174,8 +175,7 @@ static inline QByteArray generateDataBlock(int blockSize, QString text, qint64 u
static qint64 counter = 0;
- qint64 randomBits = ((qint64)qrand() << 32)
- | ((qint64)qrand() & 0x00000000ffffffff);
+ qint64 randomBits = QRandomGenerator::global()->generate64();
appendRaw(block, randomBits);
appendRaw(block, userBits);
diff --git a/tests/auto/corelib/io/qfile/tst_qfile.cpp b/tests/auto/corelib/io/qfile/tst_qfile.cpp
index 372bca6ffd..06c3a9578f 100644
--- a/tests/auto/corelib/io/qfile/tst_qfile.cpp
+++ b/tests/auto/corelib/io/qfile/tst_qfile.cpp
@@ -107,6 +107,30 @@ QT_END_NAMESPACE
Q_DECLARE_METATYPE(QFile::FileError)
+
+class StdioFileGuard
+{
+ Q_DISABLE_COPY(StdioFileGuard)
+public:
+ explicit StdioFileGuard(FILE *f = nullptr) : m_file(f) {}
+ ~StdioFileGuard() { close(); }
+
+ operator FILE *() const { return m_file; }
+
+ void close();
+
+private:
+ FILE * m_file;
+};
+
+void StdioFileGuard::close()
+{
+ if (m_file != nullptr) {
+ fclose(m_file);
+ m_file = nullptr;
+ }
+}
+
class tst_QFile : public QObject
{
Q_OBJECT
@@ -379,6 +403,8 @@ void tst_QFile::cleanup()
QDir remainingDir(absoluteFilePath);
QVERIFY2(remainingDir.removeRecursively(), qPrintable(absoluteFilePath));
} else {
+ if (!(QFile::permissions(absoluteFilePath) & QFile::WriteUser))
+ QVERIFY2(QFile::setPermissions(absoluteFilePath, QFile::WriteUser), qPrintable(absoluteFilePath));
QVERIFY2(QFile::remove(absoluteFilePath), qPrintable(absoluteFilePath));
}
}
@@ -417,8 +443,6 @@ void tst_QFile::initTestCase()
m_stdinProcessDir = QFINDTESTDATA("stdinprocess");
QVERIFY(!m_stdinProcessDir.isEmpty());
#endif
- m_testSourceFile = QFINDTESTDATA("tst_qfile.cpp");
- QVERIFY(!m_testSourceFile.isEmpty());
m_testLogFile = QFINDTESTDATA("testlog.txt");
QVERIFY(!m_testLogFile.isEmpty());
m_dosFile = QFINDTESTDATA("dosfile.txt");
@@ -431,15 +455,19 @@ void tst_QFile::initTestCase()
QVERIFY(!m_twoDotsFile.isEmpty());
#ifndef BUILTIN_TESTDATA
+ m_testSourceFile = QFINDTESTDATA("tst_qfile.cpp");
+ QVERIFY(!m_testSourceFile.isEmpty());
m_testFile = QFINDTESTDATA("testfile.txt");
QVERIFY(!m_testFile.isEmpty());
+ m_resourcesDir = QFINDTESTDATA("resources");
+ QVERIFY(!m_resourcesDir.isEmpty());
#else
m_dataDir = QEXTRACTTESTDATA("/");
QVERIFY2(!m_dataDir.isNull(), qPrintable("Could not extract test data"));
m_testFile = m_dataDir->path() + "/testfile.txt";
+ m_testSourceFile = m_dataDir->path() + "/tst_qfile.cpp";
+ m_resourcesDir = m_dataDir->path() + "/resources";
#endif
- m_resourcesDir = QFINDTESTDATA("resources");
- QVERIFY(!m_resourcesDir.isEmpty());
m_noEndOfLineFile = QFINDTESTDATA("noendofline.txt");
QVERIFY(!m_noEndOfLineFile.isEmpty());
@@ -658,14 +686,13 @@ void tst_QFile::size()
}
{
- QFile f;
- FILE* stream = QT_FOPEN(filename.toLocal8Bit().constData(), "rb");
+ StdioFileGuard stream(QT_FOPEN(filename.toLocal8Bit().constData(), "rb"));
QVERIFY( stream );
+ QFile f;
QVERIFY( f.open(stream, QIODevice::ReadOnly) );
QCOMPARE( f.size(), size );
f.close();
- fclose(stream);
}
{
@@ -1590,12 +1617,34 @@ void tst_QFile::writeTextFile()
}
#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT)
+// Helper for executing QFile::open() with warning in QTRY_VERIFY(), which evaluates the condition
+// multiple times
+static bool qFileOpen(QFile &file, QIODevice::OpenMode ioFlags)
+{
+ const bool result = file.isOpen() || file.open(ioFlags);
+ if (!result)
+ qWarning() << "Cannot open" << file.fileName() << ':' << file.errorString();
+ return result;
+}
+
+// Helper for executing fopen() with warning in QTRY_VERIFY(), which evaluates the condition
+// multiple times
+static bool fOpen(const QByteArray &fileName, const char *mode, FILE **file)
+{
+ if (*file == nullptr)
+ *file = fopen(fileName.constData(), mode);
+ if (*file == nullptr)
+ qWarning("Cannot open %s: %s", fileName.constData(), strerror(errno));
+ return *file != nullptr;
+}
+
void tst_QFile::largeUncFileSupport()
{
qint64 size = Q_INT64_C(8589934592);
qint64 dataOffset = Q_INT64_C(8589914592);
QByteArray knownData("LargeFile content at offset 8589914592");
QString largeFile("//" + QtNetworkSettings::winServerName() + "/testsharelargefile/file.bin");
+ const QByteArray largeFileEncoded = QFile::encodeName(largeFile);
{
// 1) Native file handling.
@@ -1603,31 +1652,36 @@ void tst_QFile::largeUncFileSupport()
QVERIFY2(file.exists(), msgFileDoesNotExist(largeFile));
QCOMPARE(file.size(), size);
- QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData());
+ // Retry in case of sharing violation
+ QTRY_VERIFY2(qFileOpen(file, QIODevice::ReadOnly), msgOpenFailed(file).constData());
QCOMPARE(file.size(), size);
QVERIFY(file.seek(dataOffset));
QCOMPARE(file.read(knownData.size()), knownData);
}
{
// 2) stdlib file handling.
+ FILE *fhF = nullptr;
+ // Retry in case of sharing violation
+ QTRY_VERIFY(fOpen(largeFileEncoded, "rb", &fhF));
+ StdioFileGuard fh(fhF);
QFile file;
- FILE *fh = fopen(QFile::encodeName(largeFile).data(), "rb");
QVERIFY(file.open(fh, QIODevice::ReadOnly));
QCOMPARE(file.size(), size);
QVERIFY(file.seek(dataOffset));
QCOMPARE(file.read(knownData.size()), knownData);
- fclose(fh);
}
{
// 3) stdio file handling.
- QFile file;
- FILE *fh = fopen(QFile::encodeName(largeFile).data(), "rb");
+ FILE *fhF = nullptr;
+ // Retry in case of sharing violation
+ QTRY_VERIFY(fOpen(largeFileEncoded, "rb", &fhF));
+ StdioFileGuard fh(fhF);
int fd = int(_fileno(fh));
+ QFile file;
QVERIFY(file.open(fd, QIODevice::ReadOnly));
QCOMPARE(file.size(), size);
QVERIFY(file.seek(dataOffset));
QCOMPARE(file.read(knownData.size()), knownData);
- fclose(fh);
}
}
#endif
@@ -1668,7 +1722,7 @@ void tst_QFile::bufferedRead()
file.write("abcdef");
file.close();
- FILE *stdFile = fopen("stdfile.txt", "r");
+ StdioFileGuard stdFile(fopen("stdfile.txt", "r"));
QVERIFY(stdFile);
char c;
QCOMPARE(int(fread(&c, 1, 1, stdFile)), 1);
@@ -1683,8 +1737,6 @@ void tst_QFile::bufferedRead()
QCOMPARE(c, 'b');
QCOMPARE(file.pos(), qlonglong(2));
}
-
- fclose(stdFile);
}
#ifdef Q_OS_UNIX
@@ -1813,7 +1865,7 @@ void tst_QFile::FILEReadWrite()
f.close();
}
- FILE *fp = fopen("FILEReadWrite.txt", "r+b");
+ StdioFileGuard fp(fopen("FILEReadWrite.txt", "r+b"));
QVERIFY(fp);
QFile file;
QVERIFY2(file.open(fp, QFile::ReadWrite), msgOpenFailed(file).constData());
@@ -1848,7 +1900,7 @@ void tst_QFile::FILEReadWrite()
}
file.close();
- fclose(fp);
+ fp.close();
// check modified file
{
@@ -2135,12 +2187,20 @@ public:
if (fileName.startsWith(":!")) {
QDir dir;
- QString realFile = QFINDTESTDATA(fileName.mid(2));
+#ifndef BUILTIN_TESTDATA
+ const QString realFile = QFINDTESTDATA(fileName.mid(2));
+#else
+ const QString realFile = m_dataDir->filePath(fileName.mid(2));
+#endif
if (dir.exists(realFile))
return new QFSFileEngine(realFile);
}
return 0;
}
+
+#ifdef BUILTIN_TESTDATA
+ QSharedPointer<QTemporaryDir> m_dataDir;
+#endif
};
#endif
@@ -2149,6 +2209,9 @@ void tst_QFile::useQFileInAFileHandler()
{
// This test should not dead-lock
MyRecursiveHandler handler;
+#ifdef BUILTIN_TESTDATA
+ handler.m_dataDir = m_dataDir;
+#endif
QFile file(":!tst_qfile.cpp");
QVERIFY(file.exists());
}
@@ -2430,11 +2493,10 @@ void tst_QFile::virtualFile()
void tst_QFile::textFile()
{
-#if defined(Q_OS_WIN)
- FILE *fs = ::fopen("writeabletextfile", "wt");
-#else
- FILE *fs = ::fopen("writeabletextfile", "w");
-#endif
+ const char *openMode = QOperatingSystemVersion::current().type() != QOperatingSystemVersion::Windows
+ ? "w" : "wt";
+ StdioFileGuard fs(fopen("writeabletextfile", openMode));
+ QVERIFY(fs);
QFile f;
QByteArray part1("This\nis\na\nfile\nwith\nnewlines\n");
QByteArray part2("Add\nsome\nmore\nnewlines\n");
@@ -2443,7 +2505,7 @@ void tst_QFile::textFile()
f.write(part1);
f.write(part2);
f.close();
- ::fclose(fs);
+ fs.close();
QFile file("writeabletextfile");
QVERIFY2(file.open(QIODevice::ReadOnly), msgOpenFailed(file).constData());
@@ -2699,11 +2761,12 @@ void tst_QFile::handle()
//test round trip of adopted stdio file handle
QFile file2;
- FILE *fp = fopen(qPrintable(m_testSourceFile), "r");
+ StdioFileGuard fp(fopen(qPrintable(m_testSourceFile), "r"));
+ QVERIFY(fp);
file2.open(fp, QIODevice::ReadOnly);
QCOMPARE(int(file2.handle()), int(fileno(fp)));
QCOMPARE(int(file2.handle()), int(fileno(fp)));
- fclose(fp);
+ fp.close();
//test round trip of adopted posix file handle
#ifdef Q_OS_UNIX
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+qnx/test b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+qnx/test2 b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test2
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+qnx/test2
diff --git a/tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test b/tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/io/qfileselector/platforms/+unix/+qnx/test
diff --git a/tests/auto/corelib/io/qfileselector/qfileselector.qrc b/tests/auto/corelib/io/qfileselector/qfileselector.qrc
index ea9b8270e0..54b2e0a0e2 100644
--- a/tests/auto/corelib/io/qfileselector/qfileselector.qrc
+++ b/tests/auto/corelib/io/qfileselector/qfileselector.qrc
@@ -21,6 +21,7 @@
<file>platforms/+unix/+darwin/test</file>
<file>platforms/+unix/+haiku/test</file>
<file>platforms/+unix/+linux/test</file>
+ <file>platforms/+unix/+qnx/test</file>
<file>platforms/+unix/test</file>
<file>platforms/+windows/+wince/test</file>
<file>platforms/+windows/+winnt/test</file>
@@ -34,6 +35,7 @@
<file>platforms/+mac/test</file>
<file>platforms/+haiku/test</file>
<file>platforms/+linux/test</file>
+ <file>platforms/+qnx/test</file>
<file>platforms/+wince/test</file>
<file>platforms/+winrt/test</file>
@@ -44,6 +46,7 @@
<file>platforms/+macos/test2</file>
<file>platforms/+haiku/test2</file>
<file>platforms/+linux/test2</file>
+ <file>platforms/+qnx/test2</file>
<file>platforms/+wince/test2</file>
<file>platforms/+winnt/test2</file>
<file>platforms/+winrt/test2</file>
diff --git a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp
index c537e43802..c9f1e3d9f6 100644
--- a/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp
+++ b/tests/auto/corelib/io/qfileselector/tst_qfileselector.cpp
@@ -86,7 +86,7 @@ void tst_QFileSelector::basicTest_data()
QString expectedPlatform2File(""); //Only the last selector
QString expectedPlatform3File; // Only the first selector (the family)
#if defined(Q_OS_UNIX) && !defined(Q_OS_ANDROID) && \
- !defined(Q_OS_DARWIN) && !defined(Q_OS_LINUX) && !defined(Q_OS_HAIKU)
+ !defined(Q_OS_DARWIN) && !defined(Q_OS_LINUX) && !defined(Q_OS_HAIKU) && !defined(Q_OS_QNX)
/* We are only aware of specific unixes, and do not have test files for any of the others.
However those unixes can get a selector added from the result of a uname call, so this will
lead to a case where we don't have that file so we can't expect the concatenation of platform
diff --git a/tests/auto/corelib/io/qstandardpaths/BLACKLIST b/tests/auto/corelib/io/qstandardpaths/BLACKLIST
new file mode 100644
index 0000000000..d5ee9650cd
--- /dev/null
+++ b/tests/auto/corelib/io/qstandardpaths/BLACKLIST
@@ -0,0 +1,3 @@
+[testFindExecutable]
+# QTBUG-64404
+b2qt 64bit
diff --git a/tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro b/tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro
index 351e263093..5908648378 100644
--- a/tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro
+++ b/tests/auto/corelib/io/qtemporarydir/qtemporarydir.pro
@@ -4,4 +4,4 @@ SOURCES += tst_qtemporarydir.cpp
INCLUDEPATH += ../../../../shared/
HEADERS += ../../../../shared/emulationdetector.h
-QT = core testlib
+QT = core testlib testlib-private
diff --git a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
index fcd9133099..76462be376 100644
--- a/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
+++ b/tests/auto/corelib/io/qtemporarydir/tst_qtemporarydir.cpp
@@ -35,6 +35,7 @@
#include <qdir.h>
#include <qset.h>
#include <qtextcodec.h>
+#include <QtTest/private/qtesthelpers_p.h>
#ifdef Q_OS_WIN
# include <windows.h>
#endif
@@ -112,16 +113,6 @@ void tst_QTemporaryDir::getSetCheck()
QCOMPARE(true, obj1.autoRemove());
}
-static inline bool canHandleUnicodeFileNames()
-{
-#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
- return true;
-#else
- // Check for UTF-8 by converting the Euro symbol (see tst_utf8)
- return QFile::encodeName(QString(QChar(0x20AC))) == QByteArrayLiteral("\342\202\254");
-#endif
-}
-
static QString hanTestText()
{
QString text;
@@ -159,7 +150,7 @@ void tst_QTemporaryDir::fileTemplate_data()
QTest::newRow("4Xsuffix") << "qt_XXXXXX_XXXX" << "qt_" << "_XXXX";
QTest::newRow("4Xprefix") << "qt_XXXX" << "qt_XXXX" << "";
QTest::newRow("5Xprefix") << "qt_XXXXX" << "qt_XXXXX" << "";
- if (canHandleUnicodeFileNames()) {
+ if (QTestPrivate::canHandleUnicodeFileNames()) {
// Test Umlauts (contained in Latin1)
QString prefix = "qt_" + umlautTestText();
QTest::newRow("Umlauts") << (prefix + "XXXXXX") << prefix << "";
diff --git a/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro
index a89e5c66ff..e17cb05cd8 100644
--- a/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro
+++ b/tests/auto/corelib/io/qtemporaryfile/qtemporaryfile.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qtemporaryfile
-QT = core testlib
+QT = core testlib testlib-private
SOURCES = tst_qtemporaryfile.cpp
TESTDATA += tst_qtemporaryfile.cpp
RESOURCES += qtemporaryfile.qrc
diff --git a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
index 11c24ca86f..f3ce902bbd 100644
--- a/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
+++ b/tests/auto/corelib/io/qtemporaryfile/tst_qtemporaryfile.cpp
@@ -38,6 +38,8 @@
#include <qset.h>
#include <qtextcodec.h>
+#include <QtTest/private/qtesthelpers_p.h>
+
#if defined(Q_OS_WIN)
# include <windows.h>
#endif
@@ -143,16 +145,6 @@ void tst_QTemporaryFile::getSetCheck()
QCOMPARE(true, obj1.autoRemove());
}
-static inline bool canHandleUnicodeFileNames()
-{
-#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
- return true;
-#else
- // Check for UTF-8 by converting the Euro symbol (see tst_utf8)
- return QFile::encodeName(QString(QChar(0x20AC))) == QByteArrayLiteral("\342\202\254");
-#endif
-}
-
static QString hanTestText()
{
QString text;
@@ -201,7 +193,7 @@ void tst_QTemporaryFile::fileTemplate_data()
QTest::newRow("set template, with xxx") << "" << "qt_" << ".xxx" << "qt_XXXXXX.xxx";
QTest::newRow("set template, with >6 X's") << "" << "qt_" << ".xxx" << "qt_XXXXXXXXXXXXXX.xxx";
QTest::newRow("set template, with >6 X's, no suffix") << "" << "qt_" << "" << "qt_XXXXXXXXXXXXXX";
- if (canHandleUnicodeFileNames()) {
+ if (QTestPrivate::canHandleUnicodeFileNames()) {
// Test Umlauts (contained in Latin1)
QString prefix = "qt_" + umlautTestText();
QTest::newRow("Umlauts") << (prefix + "XXXXXX") << prefix << QString() << QString();
@@ -824,7 +816,7 @@ void tst_QTemporaryFile::QTBUG_4796_data()
QTest::newRow("XXXXXXbla") << QString() << QString("bla") << true;
QTest::newRow("does-not-exist/qt_temp.XXXXXX") << QString("does-not-exist/qt_temp") << QString() << false;
- if (canHandleUnicodeFileNames()) {
+ if (QTestPrivate::canHandleUnicodeFileNames()) {
QTest::newRow("XXXXXX<unicode>") << QString() << unicode << true;
QTest::newRow("<unicode>XXXXXX") << unicode << QString() << true;
QTest::newRow("<unicode>XXXXXX<unicode>") << unicode << unicode << true;
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 400a89c03f..20282068cb 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -2063,6 +2063,11 @@ void tst_QUrl::isValid()
QVERIFY(!url.isValid());
QVERIFY(url.toString().isEmpty());
QVERIFY(url.errorString().contains("Path component starts with '//' and authority is absent"));
+
+ // should disappear if we set a port
+ url.setPort(80);
+ QVERIFY(url.isValid());
+ QCOMPARE(url.toString(), QString("http://:80//example.com"));
}
{
@@ -2071,6 +2076,13 @@ void tst_QUrl::isValid()
QVERIFY(!url.isValid());
QVERIFY(url.toString().isEmpty());
QVERIFY(url.errorString().contains("':' before any '/'"));
+
+ // this specific error disappears if we set anything in the authority,
+ // but then we run into another error
+ url.setPort(80);
+ QVERIFY(!url.isValid());
+ QVERIFY(url.toString().isEmpty());
+ QVERIFY(url.errorString().contains("Path component is relative and authority is present"));
}
{
@@ -2810,6 +2822,29 @@ void tst_QUrl::setPort()
QCOMPARE(url.port(), -1);
QVERIFY(url.errorString().contains("out of range"));
}
+
+ {
+ QUrl reference("//:80");
+ QUrl piecewise;
+ piecewise.setPort(80);
+ QCOMPARE(piecewise, reference);
+ }
+
+ {
+ // setAuthority must clear the port
+ QUrl url("http://example.com:80");
+ url.setAuthority("example.org");
+ QCOMPARE(url.port(), -1);
+ QCOMPARE(url.toString(), QString("http://example.org"));
+ }
+
+ {
+ // setAuthority must clear the port
+ QUrl url("http://example.com:80");
+ url.setAuthority(QString());
+ QCOMPARE(url.port(), -1);
+ QCOMPARE(url.toString(), QString("http:"));
+ }
}
void tst_QUrl::port_data()
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index a3f3550307..f6feac29dc 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -2362,8 +2362,8 @@ void tst_QObject::testUserData()
// Randomize the table a bit
for (int i=0; i<100; ++i) {
- int p1 = rand() % USER_DATA_COUNT;
- int p2 = rand() % USER_DATA_COUNT;
+ int p1 = QRandomGenerator::global()->bounded(USER_DATA_COUNT);
+ int p2 = QRandomGenerator::global()->bounded(USER_DATA_COUNT);
int tmp = user_data_ids[p1];
user_data_ids[p1] = user_data_ids[p2];
diff --git a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
index 8a46bc1c55..8883b6360f 100644
--- a/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
+++ b/tests/auto/corelib/mimetypes/qmimedatabase/tst_qmimedatabase.cpp
@@ -115,7 +115,6 @@ Q_CONSTRUCTOR_FUNCTION(initializeLang)
static QString seedAndTemplate()
{
- qsrand(QDateTime::currentSecsSinceEpoch());
return QDir::tempPath() + "/tst_qmimedatabase-XXXXXX";
}
diff --git a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
index daf9b1579a..d1e138d8eb 100644
--- a/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
+++ b/tests/auto/corelib/plugin/quuid/testProcessUniqueness/main.cpp
@@ -35,9 +35,6 @@ int main(int argc, char **argv)
Q_UNUSED(argc)
Q_UNUSED(argv)
- // First, break QUuid.
- qrand();
-
// Now print a few uuids.
printf("%s", qPrintable(QUuid::createUuid().toString()));
printf("%s", qPrintable(QUuid::createUuid().toString()));
diff --git a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
index 408a90afc4..d4a3ee6054 100644
--- a/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
+++ b/tests/auto/corelib/thread/qfuture/tst_qfuture.cpp
@@ -36,6 +36,7 @@
#include <qresultstore.h>
#include <qthreadpool.h>
#include <qexception.h>
+#include <qrandom.h>
#include <private/qfutureinterface_p.h>
// COM interface macro.
@@ -1456,7 +1457,7 @@ void tst_QFuture::nonGlobalThreadPool()
void run() override
{
- const int ms = 100 + (qrand() % 100 - 100/2);
+ const int ms = 100 + (QRandomGenerator::global()->bounded(100) - 100/2);
QThread::msleep(ms);
reportResult(Answer);
reportFinished();
diff --git a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
index e13c2894af..72299402f0 100644
--- a/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
+++ b/tests/auto/corelib/tools/qalgorithms/tst_qalgorithms.cpp
@@ -37,6 +37,7 @@
#include <qalgorithms.h>
#include <QStringList>
#include <QString>
+#include <QRandomGenerator>
#include <QVector>
#define Q_TEST_PERFORMANCE 0
@@ -133,7 +134,7 @@ QVector<DataType> generateData(QString dataSetType, const int length)
QVector<DataType> container;
if (dataSetType == "Random") {
for (int i = 0; i < length; ++i)
- container.append(rand());
+ container.append(QRandomGenerator::global()->generate());
} else if (dataSetType == "Ascending") {
for (int i = 0; i < length; ++i)
container.append(i);
@@ -1082,12 +1083,12 @@ void tst_QAlgorithms::popCount_data_impl(size_t sizeof_T_Int)
// and some random ones:
if (sizeof_T_Int >= 8)
for (size_t i = 0; i < 1000; ++i) {
- const quint64 input = quint64(qrand()) << 32 | quint32(qrand());
+ const quint64 input = QRandomGenerator::global()->generate64();
QTest::addRow("0x%016llx", input) << input << bitsSetInInt64(input);
}
else if (sizeof_T_Int >= 2)
for (size_t i = 0; i < 1000 ; ++i) {
- const quint32 input = qrand();
+ const quint32 input = QRandomGenerator::global()->generate();
if (sizeof_T_Int >= 4)
QTest::addRow("0x%08x", input) << quint64(input) << bitsSetInInt(input);
else
@@ -1129,7 +1130,7 @@ void tst_QAlgorithms::countTrailing_data_impl(size_t sizeof_T_Int)
// and some random ones:
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary
- const quint64 r = quint64(qrand()) << 32 | quint32(qrand());
+ const quint64 r = QRandomGenerator::global()->generate64();
const quint64 b = Q_UINT64_C(1) << i;
const quint64 mask = ((~(b-1)) ^ b) & type_mask;
const quint64 input = (r&mask) | b;
@@ -1166,7 +1167,7 @@ void tst_QAlgorithms::countLeading_data_impl(size_t sizeof_T_Int)
// and some random ones:
for (uint i = 0; i < sizeof_T_Int*8; ++i) {
for (uint j = 0; j < sizeof_T_Int*3; ++j) { // 3 is arbitrary
- const quint64 r = quint64(qrand()) << 32 | quint32(qrand());
+ const quint64 r = QRandomGenerator::global()->generate64();
const quint64 b = Q_UINT64_C(1) << i;
const quint64 mask = b-1;
const quint64 input = (r&mask) | b;
diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
index c684af5418..203d9d8683 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -1898,7 +1898,7 @@ class StrongThread: public QThread
protected:
void run()
{
- usleep(rand() % 2000);
+ usleep(QRandomGenerator::global()->bounded(2000));
ptr->ref();
ptr.clear();
}
@@ -1911,7 +1911,7 @@ class WeakThread: public QThread
protected:
void run()
{
- usleep(rand() % 2000);
+ usleep(QRandomGenerator::global()->bounded(2000));
QSharedPointer<ThreadData> ptr = weak;
if (ptr)
ptr->ref();
@@ -1973,7 +1973,6 @@ void tst_QSharedPointer::threadStressTest()
base.clear();
- srand(time(NULL));
// start threads
for (int i = 0; i < allThreads.count(); ++i)
if (allThreads[i]) allThreads[i]->start();