summaryrefslogtreecommitdiffstats
path: root/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2017-04-13 21:13:52 -0700
committerLars Knoll <lars.knoll@qt.io>2017-11-08 09:14:03 +0000
commit19b0ce5daa31e2ffebfcf2701143742302f1deb4 (patch)
tree730cccd80947c60ee4872e16f71d4d48d906c354 /tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
parent59c5f7bd9da63621887260fc45e6669282d71ecd (diff)
Change almost all other uses of qrand() to QRandomGenerator
The vast majority is actually switched to QRandomGenerator::bounded(), which gives a mostly uniform distribution over the [0, bound) range. There are very few floating point cases left, as many of those that did use floating point did not need to, after all. (I did leave some that were too ugly for me to understand) This commit also found a couple of calls to rand() instead of qrand(). This commit does not include changes to SSL code that continues to use qrand() (job for someone else): src/network/ssl/qsslkey_qt.cpp src/network/ssl/qsslsocket_mac.cpp tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp Change-Id: Icd0e0d4b27cb4e5eb892fffd14b5285d43f4afbf Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp')
-rw-r--r--tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
index 7340817ade..d7c8c8c378 100644
--- a/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
+++ b/tests/auto/network/socket/qtcpsocket/tst_qtcpsocket.cpp
@@ -1,7 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
+** Copyright (C) 2017 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
@@ -57,6 +57,7 @@
#if QT_CONFIG(process)
# include <QProcess>
#endif
+#include <QRandomGenerator>
#include <QStringList>
#include <QTcpServer>
#include <QTcpSocket>
@@ -305,8 +306,6 @@ public:
tst_QTcpSocket::tst_QTcpSocket()
: firstFailName("qt-test-server-first-fail")
{
- qsrand(time(NULL));
-
tmpSocket = 0;
//This code relates to the socketsConstructedBeforeEventLoop test case
@@ -581,8 +580,7 @@ void tst_QTcpSocket::bind()
// try to get a random port number
// we do this to ensure we're not trying to bind to the same port as we've just used in
// a previous run - race condition with the OS actually freeing the port
- Q_STATIC_ASSERT(RAND_MAX > 1024);
- port = qrand() & USHRT_MAX;
+ port = QRandomGenerator::global()->generate() & USHRT_MAX;
if (port < 1024)
continue;
}