From eac394648c29a385156a33168721207d8eab53ff Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 9 Mar 2023 07:46:11 +0100 Subject: tst_QCryptographicHash: Extract Method ensureLargeData() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ... to make large data usable from other test functions. Change-Id: I302070121a8bb49f373c7711bc3ab9e6418874ef Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit f7ea9b36b7c56bb288f3ea55f587d2ccb8a9b7fa) Reviewed-by: Qt Cherry-pick Bot --- .../tools/qcryptographichash/tst_qcryptographichash.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp index 5e2e854067..2bfe353a91 100644 --- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp +++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp @@ -35,6 +35,7 @@ private slots: void moreThan4GiBOfData_data(); void moreThan4GiBOfData(); private: + void ensureLargeData(); std::vector large; }; @@ -401,12 +402,14 @@ void tst_QCryptographicHash::hashLength() QCOMPARE(QCryptographicHash::hashLength(algorithm), output.length()); } -void tst_QCryptographicHash::moreThan4GiBOfData_data() +void tst_QCryptographicHash::ensureLargeData() { #if QT_POINTER_SIZE > 4 QElapsedTimer timer; timer.start(); const size_t GiB = 1024 * 1024 * 1024; + if (large.size() == 4 * GiB + 1) + return; try { large.resize(4 * GiB + 1, '\0'); } catch (const std::bad_alloc &) { @@ -415,7 +418,14 @@ void tst_QCryptographicHash::moreThan4GiBOfData_data() QCOMPARE(large.size(), 4 * GiB + 1); large.back() = '\1'; 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("algorithm"); auto me = QMetaEnum::fromType(); auto row = [me] (QCryptographicHash::Algorithm algo) { -- cgit v1.2.1