tst_QCryptographicHash: Extract Method ensureLargeData()

... to make large data usable from other test functions.

Change-Id: I302070121a8bb49f373c7711bc3ab9e6418874ef
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
(cherry picked from commit f7ea9b36b7c56bb288f3ea55f587d2ccb8a9b7fa)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-03-09 07:46:11 +01:00 committed by Qt Cherry-pick Bot
parent def0024f98
commit 42612b0180

View File

@ -37,6 +37,7 @@ private slots:
void moreThan4GiBOfData_data(); void moreThan4GiBOfData_data();
void moreThan4GiBOfData(); void moreThan4GiBOfData();
private: private:
void ensureLargeData();
std::vector<char> large; std::vector<char> large;
}; };
@ -440,12 +441,14 @@ void tst_QCryptographicHash::swap()
QCOMPARE(hash1.result(), QCryptographicHash::hash("test", QCryptographicHash::Sha256)); QCOMPARE(hash1.result(), QCryptographicHash::hash("test", QCryptographicHash::Sha256));
} }
void tst_QCryptographicHash::moreThan4GiBOfData_data() void tst_QCryptographicHash::ensureLargeData()
{ {
#if QT_POINTER_SIZE > 4 #if QT_POINTER_SIZE > 4
QElapsedTimer timer; QElapsedTimer timer;
timer.start(); timer.start();
const size_t GiB = 1024 * 1024 * 1024; const size_t GiB = 1024 * 1024 * 1024;
if (large.size() == 4 * GiB + 1)
return;
try { try {
large.resize(4 * GiB + 1, '\0'); large.resize(4 * GiB + 1, '\0');
} catch (const std::bad_alloc &) { } catch (const std::bad_alloc &) {
@ -454,7 +457,14 @@ void tst_QCryptographicHash::moreThan4GiBOfData_data()
QCOMPARE(large.size(), 4 * GiB + 1); QCOMPARE(large.size(), 4 * GiB + 1);
large.back() = '\1'; large.back() = '\1';
qDebug("created dataset in %lld ms", timer.elapsed()); qDebug("created dataset in %lld ms", timer.elapsed());
#endif
}
void tst_QCryptographicHash::moreThan4GiBOfData_data()
{
#if QT_POINTER_SIZE > 4
if (ensureLargeData(); large.empty())
return;
QTest::addColumn<QCryptographicHash::Algorithm>("algorithm"); QTest::addColumn<QCryptographicHash::Algorithm>("algorithm");
auto me = QMetaEnum::fromType<QCryptographicHash::Algorithm>(); auto me = QMetaEnum::fromType<QCryptographicHash::Algorithm>();
auto row = [me] (QCryptographicHash::Algorithm algo) { auto row = [me] (QCryptographicHash::Algorithm algo) {