tst_QCryptographicHash: Extract Method ensureLargeData()

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

Pick-to: 6.5 6.5.0 6.4 6.4.3 6.2
Change-Id: I302070121a8bb49f373c7711bc3ab9e6418874ef
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Marc Mutz 2023-03-09 07:46:11 +01:00
parent 6626578036
commit f7ea9b36b7

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;
}; };
@ -447,12 +448,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 &) {
@ -461,7 +464,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) {