diff options
| author | Linus Jahn <lnj@kaidan.im> | 2022-09-10 18:43:57 +0200 |
|---|---|---|
| committer | Linus Jahn <lnj@kaidan.im> | 2022-09-16 21:26:29 +0200 |
| commit | 9f474d28ffeb6e2a55fe1fb688463e1156c8fcb6 (patch) | |
| tree | 4350efbf7332063f033b265f6d60365e079d0c90 /tests/qxmpputils/tst_qxmpputils.cpp | |
| parent | 0b6842abd2877886dcb0ca4154e93d9bae1ef80c (diff) | |
| download | qxmpp-9f474d28ffeb6e2a55fe1fb688463e1156c8fcb6.tar.gz | |
Add multithreaded hashing functions
Diffstat (limited to 'tests/qxmpputils/tst_qxmpputils.cpp')
| -rw-r--r-- | tests/qxmpputils/tst_qxmpputils.cpp | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/qxmpputils/tst_qxmpputils.cpp b/tests/qxmpputils/tst_qxmpputils.cpp index 1bcfaa7c..032e9957 100644 --- a/tests/qxmpputils/tst_qxmpputils.cpp +++ b/tests/qxmpputils/tst_qxmpputils.cpp @@ -3,11 +3,19 @@ // // SPDX-License-Identifier: LGPL-2.1-or-later +#include "QXmppError.h" +#include "QXmppHash.h" +#include "QXmppHashing_p.h" #include "QXmppUtils.h" #include "util.h" #include <QObject> +using namespace QXmpp; +using namespace QXmpp::Private; + +Q_DECLARE_METATYPE(QXmpp::HashAlgorithm); + class tst_QXmppUtils : public QObject { Q_OBJECT @@ -19,6 +27,10 @@ private slots: void testMime(); void testTimezoneOffset(); void testStanzaHash(); + +private: + Q_SLOT void testCalculateHashes_data(); + Q_SLOT void testCalculateHashes(); }; void tst_QXmppUtils::testCrc32() @@ -125,5 +137,71 @@ void tst_QXmppUtils::testStanzaHash() QCOMPARE(hash.count('-'), 4); } +void tst_QXmppUtils::testCalculateHashes_data() +{ + QTest::addColumn<QString>("filePath"); + QTest::addColumn<QByteArray>("hash"); + QTest::addColumn<QXmpp::HashAlgorithm>("algorithm"); + + QTest::newRow("svg/md5") + << QStringLiteral(":/test.svg") + << QByteArray::fromHex("cf7ab33aca717ed632c32296c8426043") + << HashAlgorithm::Md5; + QTest::newRow("svg/sha-1") + << QStringLiteral(":/test.svg") + << QByteArray::fromHex("89d8cf114e4ec0758638ee8199af85d0974834bb") + << HashAlgorithm::Sha1; + QTest::newRow("svg/sha-224") + << QStringLiteral(":/test.svg") + << QByteArray::fromHex("f7f29e8e228a0b7529f6a4bc97b0e6bd080a8a91e8386bc1304ececc") + << HashAlgorithm::Sha224; + QTest::newRow("svg/sha-256") + << QStringLiteral(":/test.svg") + << QByteArray::fromHex("4736d79aa2912a2693cc17c5548612e1474dd1dfca2e8ddff917358482fd309f") + << HashAlgorithm::Sha256; + QTest::newRow("svg/sha-384") + << QStringLiteral(":/test.svg") + << QByteArray::fromHex("2f2572eac288d92a6f8ba09ae6e91c12f4ebaedc00df8bbbd284c4d60a483cfb21bbae417ec0688d71aa5a940637f11c") + << HashAlgorithm::Sha384; + QTest::newRow("svg/sha-512") + << QStringLiteral(":/test.svg") + << QByteArray::fromHex("85d34de6e549895d3c62773f589bb93b19c0bae62681f3fd0f3dba7262c96e87f771db4053ff7c9d0305b72222ccfe182596373917c0d109260973c258058196") + << HashAlgorithm::Sha512; + QTest::newRow("svg/sha3-256") + << QStringLiteral(":/test.svg") + << QByteArray::fromHex("4079f2effb8968e1540ce7c684a01266175c1af8cb15342fa19b7f7926de9f14") + << HashAlgorithm::Sha3_256; + QTest::newRow("svg/sha3-512") + << QStringLiteral(":/test.svg") + << QByteArray::fromHex("4c374d4c52fb57311761877a31a160703e5b67c0d3838758fa3698ae5bce10438145478116e3885cd9a8c30cf30391e7cd579d1c4c5b9c3ea8dba50930417931") + << HashAlgorithm::Sha3_512; +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + QTest::newRow("svg/blake2b-512") + << QStringLiteral(":/test.svg") + << QByteArray::fromHex("a5e86044842e4c8306e9e2ee041fc26d57d172d5cb32346d5ee467c97c5a0b0b2350bc5a4a3dc76b92c48585c2ebbb01cf47fa59a88420fe7bba8f2a18af6f07") + << HashAlgorithm::Blake2b_512; +#endif + QTest::newRow("bmp/sha3-256") + << QStringLiteral(":/test.bmp") + << QByteArray::fromHex("e50ffd13bb279932923ee10ba6847bec7546f77747074d1a7eeeb82228daf257") + << HashAlgorithm::Sha3_256; +} + +void tst_QXmppUtils::testCalculateHashes() +{ + using Algorithm = QXmpp::HashAlgorithm; + QFETCH(QString, filePath); + QFETCH(QByteArray, hash); + QFETCH(QXmpp::HashAlgorithm, algorithm); + + auto file = std::make_unique<QFile>(filePath); + QVERIFY(file->open(QFile::ReadOnly)); + auto resultPtr = wait(calculateHashes(std::move(file), { algorithm, Algorithm::Md5, Algorithm::Sha3_512 })); + auto &[result, _] = *resultPtr; + auto hashes = expectVariant<std::vector<QXmppHash>>(std::move(result)); + QCOMPARE(int(hashes.size()), int(3)); + QCOMPARE(hashes.front().hash(), hash); +} + QTEST_MAIN(tst_QXmppUtils) #include "tst_qxmpputils.moc" |
