summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/io/largefile/tst_largefile.cpp4
-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
7 files changed, 14 insertions, 17 deletions
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/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 3a52c684d0..5ecdd92228 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 37b052bf1d..58bebe19ac 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() Q_DECL_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 442d4d089c..e1dcdb8407 100644
--- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
+++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp
@@ -1884,7 +1884,7 @@ class StrongThread: public QThread
protected:
void run()
{
- usleep(rand() % 2000);
+ usleep(QRandomGenerator::global()->bounded(2000));
ptr->ref();
ptr.clear();
}
@@ -1897,7 +1897,7 @@ class WeakThread: public QThread
protected:
void run()
{
- usleep(rand() % 2000);
+ usleep(QRandomGenerator::global()->bounded(2000));
QSharedPointer<ThreadData> ptr = weak;
if (ptr)
ptr->ref();
@@ -1959,7 +1959,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();