diff options
author | Linus Jahn <lnj@kaidan.im> | 2022-09-10 19:40:51 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-09-12 18:47:23 +0000 |
commit | 358248b4950131711ae408da9aa30d41c5143e4f (patch) | |
tree | 02c19a20d30b85d09ba622fa2f2c5254fcac89c4 /tests/auto/corelib/tools | |
parent | 553185e8c3a71d74be368745c3c6a3d5bcffe7e1 (diff) |
Make QCryptographicHash move constructible
This adds a move constructor, a move assignment operator and a swap
function to QCryptographicHash. This can (to name one example) be useful
when you want to store multiple hashes in a vector.
[ChangeLog][QtCore][QCryptographicHash] Added move constructor, move
assignment operator and swap() function.
Change-Id: Id54594fa69104ec25ad78581f962a021e85531c2
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r-- | tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp index 5e2e854067..5445963be8 100644 --- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp +++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp @@ -31,6 +31,8 @@ private slots: void files(); void hashLength_data(); void hashLength(); + void move(); + void swap(); // keep last void moreThan4GiBOfData_data(); void moreThan4GiBOfData(); @@ -401,6 +403,41 @@ void tst_QCryptographicHash::hashLength() QCOMPARE(QCryptographicHash::hashLength(algorithm), output.length()); } +void tst_QCryptographicHash::move() +{ + QCryptographicHash hash1(QCryptographicHash::Sha1); + hash1.addData("a"); + + // move constructor + auto hash2(std::move(hash1)); + hash2.addData("b"); + + // move assign operator + QCryptographicHash hash3(QCryptographicHash::Sha256); + hash3.addData("no effect on the end result"); + hash3 = std::move(hash2); + hash3.addData("c"); + + QCOMPARE(hash3.resultView(), QByteArray::fromHex("A9993E364706816ABA3E25717850C26C9CD0D89D")); +} + +void tst_QCryptographicHash::swap() +{ + QCryptographicHash hash1(QCryptographicHash::Sha1); + QCryptographicHash hash2(QCryptographicHash::Sha256); + + hash1.addData("da"); + hash2.addData("te"); + + hash1.swap(hash2); + + hash2.addData("ta"); + hash1.addData("st"); + + QCOMPARE(hash2.result(), QCryptographicHash::hash("data", QCryptographicHash::Sha1)); + QCOMPARE(hash1.result(), QCryptographicHash::hash("test", QCryptographicHash::Sha256)); +} + void tst_QCryptographicHash::moreThan4GiBOfData_data() { #if QT_POINTER_SIZE > 4 |