diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2020-04-14 17:15:21 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-04-15 07:58:10 -0700 |
commit | 935b28c119b9019a0e0f94b7bf1c1a8d5322973c (patch) | |
tree | f321a20100454c45c8ef7c0d7ed3622fc5dd59eb /tests | |
parent | 20f0a82b4e5c746cd9c43a6eb21e7c293084aaf3 (diff) | |
download | subsurface-935b28c119b9019a0e0f94b7bf1c1a8d5322973c.tar.gz |
testing/git-storage: alternative random number generation for Qt 5.9
We still need to support Qt 5.9 for Ubuntu 18.04 / Bionic. This uses
deprecated calls to qrand() - but then qrand() wasn't deprecated in 5.9.
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/testgitstorage.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/tests/testgitstorage.cpp b/tests/testgitstorage.cpp index b89c58455..c5dc612f5 100644 --- a/tests/testgitstorage.cpp +++ b/tests/testgitstorage.cpp @@ -16,7 +16,9 @@ #include <QNetworkProxy> #include <QTextCodec> #include <QDebug> +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) #include <QRandomGenerator> +#endif // provide declarations for two local helper functions in git-access.c extern "C" char *get_local_dir(const char *remote, const char *branch); @@ -88,8 +90,15 @@ void TestGitStorage::initTestCase() email = qgetenv("SSRF_USER_EMAIL"); QString password = qgetenv("SSRF_USER_PASSWORD"); - if (email.isEmpty()) + if (email.isEmpty()) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) email = QString("gitstorage%1@hohndel.org").arg(QRandomGenerator::global()->bounded(10)); +#else + // on Qt 5.9 we go back to using qsrand()/qrand() + qsrand(time(NULL)); + email = QString("gitstorage%1@hohndel.org").arg(qrand() % 10); +#endif + } if (password.isEmpty()) password = "please-only-use-this-in-the-git-tests"; gitUrl = prefs.cloud_base_url; @@ -105,8 +114,15 @@ void TestGitStorage::initTestCase() // runs we'll use actually random branch names - yes, this still has a chance of // conflict, but I'm not going to implement a distributed locak manager for this if (email.startsWith("gitstorage")) { +#if QT_VERSION >= QT_VERSION_CHECK(5, 10, 0) randomBranch = QString::number(QRandomGenerator::global()->bounded(0x1000000), 16) + QString::number(QRandomGenerator::global()->bounded(0x1000000), 16); +#else + // on Qt 5.9 we go back to using qsrand()/qrand() -- if we get to this code, qsrand() was already called + // even on a 32bit system RAND_MAX is at least 32767 so this will also give us 12 random hex digits + randomBranch = QString::number(qrand() % 0x1000, 16) + QString::number(qrand() % 0x1000, 16) + + QString::number(qrand() % 0x1000, 16) + QString::number(qrand() % 0x1000, 16); +#endif } else { // user supplied their own credentials, fall back to the usual "email is branch" pattern randomBranch = email; |