summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp')
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp37
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