tst_QCryptographicHash: make hashLength() data-driven

Change-Id: I44bf73e15b53b8d93d116f4114bc667c4c94b7b4
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
(cherry picked from commit 09d0fc068d4b32aa9cd00d38171e62fddf82c83a)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2021-07-05 09:37:40 +02:00 committed by Qt Cherry-pick Bot
parent 0f7b68218f
commit d2546c4daf

View File

@ -49,6 +49,7 @@ private slots:
void blake2();
void files_data();
void files();
void hashLength_data();
void hashLength();
};
@ -400,15 +401,23 @@ void tst_QCryptographicHash::files()
}
}
void tst_QCryptographicHash::hashLength()
void tst_QCryptographicHash::hashLength_data()
{
QTest::addColumn<QCryptographicHash::Algorithm>("algorithm");
auto metaEnum = QMetaEnum::fromType<QCryptographicHash::Algorithm>();
for (int i = 0, value = metaEnum.value(i); value != -1; value = metaEnum.value(++i)) {
auto algorithm = QCryptographicHash::Algorithm(value);
QByteArray output = QCryptographicHash::hash(QByteArrayLiteral("test"), algorithm);
QCOMPARE(QCryptographicHash::hashLength(algorithm), output.length());
QTest::addRow("%s", metaEnum.valueToKey(value)) << algorithm;
}
}
void tst_QCryptographicHash::hashLength()
{
QFETCH(const QCryptographicHash::Algorithm, algorithm);
QByteArray output = QCryptographicHash::hash(QByteArrayLiteral("test"), algorithm);
QCOMPARE(QCryptographicHash::hashLength(algorithm), output.length());
}
QTEST_MAIN(tst_QCryptographicHash)
#include "tst_qcryptographichash.moc"