diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-03-02 15:00:31 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-03-16 17:27:29 +0100 |
commit | c5d4dde67896611e171db778f2bff23e614b9d14 (patch) | |
tree | aef158b20e3c2807da3545c400339beb463eb94d /tests/auto/corelib/tools | |
parent | 41fea4f5fa16d4dab96f0585848b0cf60284dd95 (diff) |
QMessageAuthenticationCode: add move SMFs and swap()
QCryptographicHash is move-only these days, so
QMessageAuthenticationCode should not be left behind.
[ChangeLog][QtCore][QMessageAuthenticationCode] Added move
constructor, move assignment operator and swap() function.
Fixes: QTBUG-111677
Change-Id: I420f24c04828e8ad7043a9e8c9e7e2d47dd183e0
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/auto/corelib/tools')
-rw-r--r-- | tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp index 002f6f587a..85138a6402 100644 --- a/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp +++ b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp @@ -20,6 +20,8 @@ private slots: void result_incremental(); void addData_overloads_data(); void addData_overloads(); + void move(); + void swap(); }; Q_DECLARE_METATYPE(QCryptographicHash::Algorithm) @@ -219,5 +221,48 @@ void tst_QMessageAuthenticationCode::addData_overloads() } } +void tst_QMessageAuthenticationCode::move() +{ + const QByteArray key = "123"; + + QMessageAuthenticationCode src(QCryptographicHash::Sha1, key); + src.addData("a"); + + // move constructor + auto intermediary = std::move(src); + intermediary.addData("b"); + + // move assign operator + QMessageAuthenticationCode dst(QCryptographicHash::Sha256, key); + dst.addData("no effect on the end result"); + dst = std::move(intermediary); + dst.addData("c"); + + QCOMPARE(dst.resultView(), + QMessageAuthenticationCode::hash("abc", key, QCryptographicHash::Sha1)); +} + +void tst_QMessageAuthenticationCode::swap() +{ + const QByteArray key1 = "123"; + const QByteArray key2 = "abcdefg"; + + QMessageAuthenticationCode mac1(QCryptographicHash::Sha1, key1); + QMessageAuthenticationCode mac2(QCryptographicHash::Sha256, key2); + + mac1.addData("da"); + mac2.addData("te"); + + mac1.swap(mac2); + + mac2.addData("ta"); + mac1.addData("st"); + + QCOMPARE(mac2.resultView(), + QMessageAuthenticationCode::hash("data", key1, QCryptographicHash::Sha1)); + QCOMPARE(mac1.resultView(), + QMessageAuthenticationCode::hash("test", key2, QCryptographicHash::Sha256)); +} + QTEST_MAIN(tst_QMessageAuthenticationCode) #include "tst_qmessageauthenticationcode.moc" |