aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-06-12 15:28:13 -0700
committerSimon Hausmann <simon.hausmann@qt.io>2017-08-23 04:47:59 +0000
commit2b7b24a0e039a18db8ab23475fbab44718f758a2 (patch)
tree0cfb916871a7e48d843dcd371d723a7d6083f2a6 /tests
parent46ed14da325c6c0382c0bc54cacc347d2d7f2b0a (diff)
Use QRandomGenerator instead of q?rand
Change-Id: Icd0e0d4b27cb4e5eb892fffd14b5285d43f4afbf Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlchangeset/tst_qqmlchangeset.cpp29
-rw-r--r--tests/auto/quick/qquicklistview/randomsortmodel.cpp5
-rw-r--r--tests/auto/quick/shared/viewtestutil.cpp6
-rw-r--r--tests/benchmarks/qml/holistic/testtypes.h5
-rw-r--r--tests/benchmarks/qml/painting/paintbenchmark.cpp3
5 files changed, 24 insertions, 24 deletions
diff --git a/tests/auto/qml/qqmlchangeset/tst_qqmlchangeset.cpp b/tests/auto/qml/qqmlchangeset/tst_qqmlchangeset.cpp
index da7956a5fb..65ac1ef320 100644
--- a/tests/auto/qml/qqmlchangeset/tst_qqmlchangeset.cpp
+++ b/tests/auto/qml/qqmlchangeset/tst_qqmlchangeset.cpp
@@ -26,6 +26,7 @@
**
****************************************************************************/
#include <qtest.h>
+#include <qrandom.h>
#include <private/qqmlchangeset_p.h>
class tst_qqmlchangeset : public QObject
@@ -1462,23 +1463,19 @@ void tst_qqmlchangeset::debug()
void tst_qqmlchangeset::random_data()
{
- QTest::addColumn<int>("seed");
QTest::addColumn<int>("combinations");
QTest::addColumn<int>("depth");
- QTest::newRow("1*5") << 32 << 1 << 5;
- QTest::newRow("2*2") << 32 << 2 << 2;
- QTest::newRow("3*2") << 32 << 3 << 2;
- QTest::newRow("3*5") << 32 << 3 << 5;
+ QTest::newRow("1*5") << 1 << 5;
+ QTest::newRow("2*2") << 2 << 2;
+ QTest::newRow("3*2") << 3 << 2;
+ QTest::newRow("3*5") << 3 << 5;
}
void tst_qqmlchangeset::random()
{
- QFETCH(int, seed);
QFETCH(int, combinations);
QFETCH(int, depth);
- qsrand(seed);
-
int failures = 0;
for (int i = 0; i < 20000; ++i) {
QQmlChangeSet accumulatedSet;
@@ -1490,27 +1487,27 @@ void tst_qqmlchangeset::random()
for (int j = 0; j < combinations; ++j) {
QQmlChangeSet set;
for (int k = 0; k < depth; ++k) {
- switch (-(qrand() % 3)) {
+ switch (-QRandomGenerator::bounded(3)) {
case InsertOp: {
- int index = qrand() % (modelCount + 1);
- int count = qrand() % 5 + 1;
+ int index = QRandomGenerator::bounded(modelCount + 1);
+ int count = QRandomGenerator::bounded(5) + 1;
set.insert(index, count);
input.append(Insert(index, count));
modelCount += count;
break;
}
case RemoveOp: {
- const int index = qrand() % (modelCount + 1);
- const int count = qrand() % (modelCount - index + 1);
+ const int index = QRandomGenerator::bounded(modelCount + 1);
+ const int count = QRandomGenerator::bounded(modelCount - index + 1);
set.remove(index, count);
input.append(Remove(index, count));
modelCount -= count;
break;
}
case MoveOp: {
- const int from = qrand() % (modelCount + 1);
- const int count = qrand() % (modelCount - from + 1);
- const int to = qrand() % (modelCount - count + 1);
+ const int from = QRandomGenerator::bounded(modelCount + 1);
+ const int count = QRandomGenerator::bounded(modelCount - from + 1);
+ const int to = QRandomGenerator::bounded(modelCount - count + 1);
const int moveId = moveCount++;
set.move(from, to, count, moveId);
input.append(Move(from, to, count, moveId));
diff --git a/tests/auto/quick/qquicklistview/randomsortmodel.cpp b/tests/auto/quick/qquicklistview/randomsortmodel.cpp
index 7affb182c0..7c4bd5111c 100644
--- a/tests/auto/quick/qquicklistview/randomsortmodel.cpp
+++ b/tests/auto/quick/qquicklistview/randomsortmodel.cpp
@@ -27,6 +27,7 @@
****************************************************************************/
#include "randomsortmodel.h"
+#include <QRandomGenerator>
RandomSortModel::RandomSortModel(QObject* parent):
QAbstractListModel(parent)
@@ -73,14 +74,14 @@ QVariant RandomSortModel::data(const QModelIndex& index, int role) const
void RandomSortModel::randomize()
{
- const int row = qrand() % mData.count();
+ const int row = QRandomGenerator::bounded(mData.count());
int random;
bool exists = false;
// Make sure we won't end up with two items with the same weight, as that
// would make unit-testing much harder
do {
exists = false;
- random = qrand() % (mData.count() * 10);
+ random = QRandomGenerator::bounded(mData.count() * 10);
QList<QPair<QString, int> >::ConstIterator iter, end;
for (iter = mData.constBegin(), end = mData.constEnd(); iter != end; ++iter) {
if ((*iter).second == random) {
diff --git a/tests/auto/quick/shared/viewtestutil.cpp b/tests/auto/quick/shared/viewtestutil.cpp
index cb2b8be97a..a33c5eae96 100644
--- a/tests/auto/quick/shared/viewtestutil.cpp
+++ b/tests/auto/quick/shared/viewtestutil.cpp
@@ -28,6 +28,7 @@
#include "viewtestutil.h"
+#include <QtCore/QRandomGenerator>
#include <QtQuick/QQuickView>
#include <QtQuick/QQuickView>
#include <QtGui/QScreen>
@@ -356,7 +357,6 @@ QQuickViewTestUtil::StressTestModel::StressTestModel()
t->setInterval(500);
t->start();
- qsrand(qHash(QDateTime::currentDateTime()));
connect(t, &QTimer::timeout, this, &StressTestModel::updateModel);
}
@@ -374,7 +374,7 @@ void QQuickViewTestUtil::StressTestModel::updateModel()
{
if (m_rowCount > 10) {
for (int i = 0; i < 10; ++i) {
- int rnum = qrand() % m_rowCount;
+ int rnum = QRandomGenerator::bounded(m_rowCount);
beginRemoveRows(QModelIndex(), rnum, rnum);
m_rowCount--;
endRemoveRows();
@@ -382,7 +382,7 @@ void QQuickViewTestUtil::StressTestModel::updateModel()
}
if (m_rowCount < 20) {
for (int i = 0; i < 10; ++i) {
- int rnum = qrand() % m_rowCount;
+ int rnum = QRandomGenerator::bounded(m_rowCount);
beginInsertRows(QModelIndex(), rnum, rnum);
m_rowCount++;
endInsertRows();
diff --git a/tests/benchmarks/qml/holistic/testtypes.h b/tests/benchmarks/qml/holistic/testtypes.h
index a752a8585b..29ebe97f39 100644
--- a/tests/benchmarks/qml/holistic/testtypes.h
+++ b/tests/benchmarks/qml/holistic/testtypes.h
@@ -34,6 +34,7 @@
#include <QtCore/qpoint.h>
#include <QtCore/qsize.h>
#include <QtQml/qqmllist.h>
+#include <QtCore/qrandom.h>
#include <QtCore/qrect.h>
#include <QtGui/qmatrix.h>
#include <QtGui/qcolor.h>
@@ -223,7 +224,7 @@ public:
{
QPixmap pv(150, 150);
pv.fill(Qt::green);
- int choice = qrand() % 4;
+ int choice = QRandomGenerator::bounded(4);
switch (choice) {
case 0: setArbitraryVariant(QVariant(QString(QLatin1String("string variant value")))); break;
case 1: setArbitraryVariant(QVariant(QColor(110, 120, 130))); break;
@@ -253,7 +254,7 @@ public:
QVariant retn;
QPixmap pv(randomFactorOne % 300, randomFactorTwo % 300);
pv.fill(QColor(randomFactorOne % 256, randomFactorTwo % 256, randomFactorThree % 256));
- int choice = qrand() % 4;
+ int choice = QRandomGenerator::bounded(4);
switch (choice) {
case 0: retn = QVariant(QString(QLatin1String("string variant value"))); break;
case 1: retn = QVariant(QColor(randomFactorThree % 256, randomFactorTwo % 256, randomFactorOne % 256)); break;
diff --git a/tests/benchmarks/qml/painting/paintbenchmark.cpp b/tests/benchmarks/qml/painting/paintbenchmark.cpp
index 0a9dee4664..98d8d7c16a 100644
--- a/tests/benchmarks/qml/painting/paintbenchmark.cpp
+++ b/tests/benchmarks/qml/painting/paintbenchmark.cpp
@@ -36,6 +36,7 @@
#include <QVBoxLayout>
#include <QTime>
#include <QDebug>
+#include <QRandomGenerator>
#include <QStaticText>
int iterations = 20;
@@ -321,7 +322,7 @@ public:
int len = strlen(chars);
for (int i = 0; i < lines; ++i) {
for (int j = 0; j < 60; j++) {
- strings[i] += QChar(chars[rand() % len]);
+ strings[i] += QChar(chars[QRandomGenerator::bounded(len)]);
}
}
}