diff options
Diffstat (limited to 'tests/benchmarks')
14 files changed, 33 insertions, 31 deletions
diff --git a/tests/benchmarks/corelib/tools/qalgorithms/tst_qalgorithms.cpp b/tests/benchmarks/corelib/tools/qalgorithms/tst_qalgorithms.cpp index 11e559a298..a4ad3a08a8 100644 --- a/tests/benchmarks/corelib/tools/qalgorithms/tst_qalgorithms.cpp +++ b/tests/benchmarks/corelib/tools/qalgorithms/tst_qalgorithms.cpp @@ -57,7 +57,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); diff --git a/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp b/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp index 507e2af708..1d414161d1 100644 --- a/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp +++ b/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 Intel Corporation. +** Copyright (C) 2017 Intel Corporation. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -29,6 +29,7 @@ #include <QByteArray> #include <QCryptographicHash> #include <QFile> +#include <QRandomGenerator> #include <QString> #include <QtTest> @@ -102,9 +103,8 @@ tst_bench_QCryptographicHash::tst_bench_QCryptographicHash() } else #endif { - qsrand(time(NULL)); for (int i = 0; i < MaxBlockSize; ++i) - blockOfData[i] = qrand(); + blockOfData[i] = QRandomGenerator::global()->generate(); } } diff --git a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/main.cpp b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/main.cpp index 55f2fd0dcc..87ab80d74f 100644 --- a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/main.cpp +++ b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/main.cpp @@ -326,7 +326,7 @@ void tst_GraphicsViewBenchmark::initTestCase() currentListSize = -1; currentListType = None; - QTest::qWaitForWindowShown(mMainView); + QVERIFY(QTest::qWaitForWindowShown(mMainView)); } void tst_GraphicsViewBenchmark::cleanupTestCase() diff --git a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/dummydatagen.cpp b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/dummydatagen.cpp index e3ee0f8e45..7809b38050 100644 --- a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/dummydatagen.cpp +++ b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/dummydatagen.cpp @@ -27,6 +27,7 @@ ****************************************************************************/ #include <QFile> +#include <QRandomGenerator> #include "theme.h" #include "dummydatagen.h" @@ -65,12 +66,11 @@ DummyDataGenerator::~DummyDataGenerator() void DummyDataGenerator::Reset() { - qsrand(100); } QString DummyDataGenerator::randomPhoneNumber(QString indexNumber) { - int index = qrand()%m_countryCodes.count(); + int index = QRandomGenerator::global()->bounded(m_countryCodes.count()); QString countryCode = m_countryCodes.at(index); QString areaCode = QString::number(index) + QString("0").repeated(2-QString::number(index).length()); QString beginNumber = QString::number(555-index*2); @@ -84,13 +84,13 @@ QString DummyDataGenerator::randomFirstName() { m_isMale = !m_isMale; if (m_isMale) - return m_firstNamesM.at(qrand()%m_firstNamesM.count()); - return m_firstNamesF.at(qrand()%m_firstNamesF.count()); + return m_firstNamesM.at(QRandomGenerator::global()->bounded(m_firstNamesM.count())); + return m_firstNamesF.at(QRandomGenerator::global()->bounded(m_firstNamesF.count())); } QString DummyDataGenerator::randomLastName() { - return m_lastNames.at(qrand()%m_lastNames.count()); + return m_lastNames.at(QRandomGenerator::global()->bounded(m_lastNames.count())); } QString DummyDataGenerator::randomName() @@ -101,8 +101,8 @@ QString DummyDataGenerator::randomName() QString DummyDataGenerator::randomIconItem() { QString avatar = Theme::p()->pixmapPath() + "contact_default_icon.svg"; - if (qrand()%4) { - int randVal = 1+qrand()%25; + if (QRandomGenerator::global()->bounded(4)) { + int randVal = 1+QRandomGenerator::global()->bounded(25); if (m_isMale && randVal > 15) { randVal -= 15; @@ -118,7 +118,7 @@ QString DummyDataGenerator::randomIconItem() QString DummyDataGenerator::randomStatusItem() { - switch (qrand()%3) { + switch (QRandomGenerator::global()->bounded(3)) { case 0: return Theme::p()->pixmapPath() + "contact_status_online.svg"; case 1: return Theme::p()->pixmapPath() + "contact_status_offline.svg"; case 2: return Theme::p()->pixmapPath() + "contact_status_idle.svg"; diff --git a/tests/benchmarks/gui/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp b/tests/benchmarks/gui/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp index b1a54a831d..1db130203a 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicslayout/tst_qgraphicslayout.cpp @@ -110,7 +110,7 @@ void tst_QGraphicsLayout::invalidate() view->show(); - QTest::qWaitForWindowShown(view); + QVERIFY(QTest::qWaitForWindowShown(view)); // ...then measure... diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp index 6c97f94683..e0cc0f8eb4 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp @@ -82,7 +82,7 @@ int main(int argc, char *argv[]) for (int i = 0; i < atoi(argv[1]); ++i) { QGraphicsRectItem *child = scene.addRect(-5, -5, 10, 10, QPen(Qt::NoPen), QBrush(Qt::blue)); - child->setPos(-50 + qrand() % 100, -50 + qrand() % 100); + child->setPos(-50 + QRandomGenerator::global()->bounded(100), -50 + QRandomGenerator::global()->bounded(100)); child->setParentItem(item); } diff --git a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp index cdec833f4e..9bb5231528 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicsview/tst_qgraphicsview.cpp @@ -160,7 +160,7 @@ void tst_QGraphicsView::initTestCase() mView.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); mView.tryResize(100, 100); mView.show(); - QTest::qWaitForWindowExposed(&mView); + QVERIFY(QTest::qWaitForWindowExposed(&mView)); QTest::qWait(300); processEvents(); } @@ -409,7 +409,7 @@ void tst_QGraphicsView::chipTester() tester.setOpenGL(opengl); tester.setOperation(ChipTester::Operation(operation)); tester.show(); - QTest::qWaitForWindowExposed(&tester); + QVERIFY(QTest::qWaitForWindowExposed(&tester)); QTest::qWait(250); processEvents(); diff --git a/tests/benchmarks/gui/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/benchmarks/gui/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp index c2f41a7557..d9bc7f21b6 100644 --- a/tests/benchmarks/gui/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/benchmarks/gui/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp @@ -31,6 +31,7 @@ #include <QGraphicsScene> #include <QGraphicsView> #include <QGraphicsWidget> +#include <QRandomGenerator> class tst_QGraphicsWidget : public QObject { @@ -72,7 +73,9 @@ void tst_QGraphicsWidget::move() QGraphicsView view(&scene); view.show(); QBENCHMARK { - widget->setPos(qrand(),qrand()); + // truncate the random values to 24 bits to + // avoid overflowing + widget->setPos(QRandomGenerator::global()->generate() & 0xffffff, QRandomGenerator::global()->generate() & 0xffffff); } } diff --git a/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp b/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp index aeec0624e8..b9af7a55cd 100644 --- a/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp +++ b/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp @@ -122,7 +122,7 @@ private: void tst_QWidget::initTestCase() { widget.show(); - QTest::qWaitForWindowExposed(&widget); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); QTest::qWait(300); processEvents(); } diff --git a/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp b/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp index ea08af7608..f2e6973e27 100644 --- a/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp +++ b/tests/benchmarks/gui/painting/qpainter/tst_qpainter.cpp @@ -33,10 +33,7 @@ #include <QImage> #include <QPaintEngine> #include <QTileRules> -#include <math.h> -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif +#include <qmath.h> #include <private/qpixmap_raster_p.h> @@ -1232,7 +1229,7 @@ QTransform tst_QPainter::transformForAngle(qreal angle) QTransform rotTrans2; rotTrans2.translate(40, 0); - qreal rad = angle * 2. * M_PI / 360.; + qreal rad = qDegreesToRadians(angle); qreal c = ::cos(rad); qreal s = ::sin(rad); diff --git a/tests/benchmarks/gui/painting/qtbench/benchmarktests.h b/tests/benchmarks/gui/painting/qtbench/benchmarktests.h index e4b98336c7..42b06778f9 100644 --- a/tests/benchmarks/gui/painting/qtbench/benchmarktests.h +++ b/tests/benchmarks/gui/painting/qtbench/benchmarktests.h @@ -37,6 +37,7 @@ #include <QDebug> #include <QStaticText> #include <QPainter> +#include <QRandomGenerator> class Benchmark { @@ -47,9 +48,9 @@ public: : m_size(size) { for (int i=0; i<16; ++i) { - m_colors[i] = QColor::fromRgbF((rand() % 4) / 3.0, - (rand() % 4) / 3.0, - (rand() % 4) / 3.0, + m_colors[i] = QColor::fromRgbF((QRandomGenerator::global()->bounded(4)) / 3.0, + (QRandomGenerator::global()->bounded(4)) / 3.0, + (QRandomGenerator::global()->bounded(4)) / 3.0, 1); } } @@ -142,7 +143,7 @@ public: ImageFillRectBenchmark(int size) : Benchmark(QSize(size, size)) { - int s = rand() % 24 + 8; + int s = QRandomGenerator::global()->bounded(24) + 8; m_content = QImage(s, s, QImage::Format_ARGB32_Premultiplied); QPainter p(&m_content); p.fillRect(0, 0, s, s, Qt::white); diff --git a/tests/benchmarks/gui/painting/qtbench/tst_qtbench.cpp b/tests/benchmarks/gui/painting/qtbench/tst_qtbench.cpp index 62a9096b7e..c2ce15f720 100644 --- a/tests/benchmarks/gui/painting/qtbench/tst_qtbench.cpp +++ b/tests/benchmarks/gui/painting/qtbench/tst_qtbench.cpp @@ -224,7 +224,7 @@ void tst_QtBench::qtBench() BenchWidget widget(reinterpret_cast<Benchmark *>(benchmark)); widget.show(); - QTest::qWaitForWindowExposed(&widget); + QVERIFY(QTest::qWaitForWindowExposed(&widget)); while (!widget.done()) { widget.update(); diff --git a/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp b/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp index c1e6d780ba..9dbf618dd9 100644 --- a/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp +++ b/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp @@ -168,7 +168,7 @@ void tst_qstylesheetstyle::grid() w->setStyleSheet("/* */"); if(show) { w->show(); - QTest::qWaitForWindowExposed(w); + QVERIFY(QTest::qWaitForWindowExposed(w)); QApplication::processEvents(); QTest::qWait(30); QApplication::processEvents(); diff --git a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp index dfa658df11..b2f4cbd7ba 100644 --- a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -30,6 +30,7 @@ #include <QDebug> #include <qtest.h> #include <QtTest/QtTest> +#include <QtCore/qrandom.h> #include <QtNetwork/qnetworkreply.h> #include <QtNetwork/qnetworkrequest.h> #include <QtNetwork/qnetworkaccessmanager.h> @@ -525,7 +526,7 @@ void tst_qnetworkreply::echoPerformance() data.resize(1024*1024*10); // 10 MB // init with garbage. needed so ssl cannot compress it in an efficient way. for (size_t i = 0; i < data.size() / sizeof(int); i++) { - int r = qrand(); + char r = char(QRandomGenerator::global()->generate()); data.data()[i*sizeof(int)] = r; } |