summaryrefslogtreecommitdiffstats
path: root/tests/auto/corelib
diff options
context:
space:
mode:
authorSune Vuorela <sune@vuorela.dk>2011-12-20 19:46:28 +0100
committerQt by Nokia <qt-info@nokia.com>2011-12-22 19:47:47 +0100
commitef03396072e3959e7d03f55d91c2ffa1faa51d8d (patch)
treedf07f15b52e8e44f151c3b856c3b15c0bc8587bb /tests/auto/corelib
parenteff09a2794bcb4b5373fcee85faa498b36fac27c (diff)
QCryptographicHash: allow to hash the content of a QIODevice
This adds a new function (and tests) to give the possibility of doing a QCryptographicHash of a QIODevice, like a QFile or whatever people needs. It is a quite handy overload in many cases. Change-Id: I22fd272f05571844641b3daefcc6746be4e5c7c3 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/auto/corelib')
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/data/2c1517dad3678f03917f15849b052fd5.md5bin0 -> 8375 bytes
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/data/d41d8cd98f00b204e9800998ecf8427e.md50
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/qcryptographichash.pro12
-rw-r--r--tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp32
4 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/corelib/tools/qcryptographichash/data/2c1517dad3678f03917f15849b052fd5.md5 b/tests/auto/corelib/tools/qcryptographichash/data/2c1517dad3678f03917f15849b052fd5.md5
new file mode 100644
index 0000000000..dd5c63cce1
--- /dev/null
+++ b/tests/auto/corelib/tools/qcryptographichash/data/2c1517dad3678f03917f15849b052fd5.md5
Binary files differ
diff --git a/tests/auto/corelib/tools/qcryptographichash/data/d41d8cd98f00b204e9800998ecf8427e.md5 b/tests/auto/corelib/tools/qcryptographichash/data/d41d8cd98f00b204e9800998ecf8427e.md5
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/auto/corelib/tools/qcryptographichash/data/d41d8cd98f00b204e9800998ecf8427e.md5
diff --git a/tests/auto/corelib/tools/qcryptographichash/qcryptographichash.pro b/tests/auto/corelib/tools/qcryptographichash/qcryptographichash.pro
index 39987bac35..fddd67fbd6 100644
--- a/tests/auto/corelib/tools/qcryptographichash/qcryptographichash.pro
+++ b/tests/auto/corelib/tools/qcryptographichash/qcryptographichash.pro
@@ -2,3 +2,15 @@ CONFIG += testcase parallel_test
TARGET = tst_qcryptographichash
QT = core testlib
SOURCES = tst_qcryptographichash.cpp
+
+
+wince* {
+ addFiles.files = data/*
+ addFiles.path = data/
+ DEPLOYMENT += addFiles
+
+ DEFINES += SRCDIR=\\\".\\\"
+}
+else {
+ DEFINES += SRCDIR=\\\"$$PWD/\\\"
+} \ No newline at end of file
diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
index b8592e1850..8ca13ff244 100644
--- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
+++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp
@@ -51,6 +51,8 @@ private slots:
void intermediary_result_data();
void intermediary_result();
void sha1();
+ void files_data();
+ void files();
};
#include <QtCore>
@@ -150,5 +152,35 @@ void tst_QCryptographicHash::sha1()
}
+Q_DECLARE_METATYPE(QCryptographicHash::Algorithm);
+
+void tst_QCryptographicHash::files_data() {
+ QTest::addColumn<QString>("filename");
+ QTest::addColumn<QCryptographicHash::Algorithm>("algorithm");
+ QTest::addColumn<QByteArray>("md5sum");
+ QTest::newRow("Line") << QString::fromAscii("data/2c1517dad3678f03917f15849b052fd5.md5") << QCryptographicHash::Md5 << QByteArray("2c1517dad3678f03917f15849b052fd5");
+ QTest::newRow("Line") << QString::fromAscii("data/d41d8cd98f00b204e9800998ecf8427e.md5") << QCryptographicHash::Md5 << QByteArray("d41d8cd98f00b204e9800998ecf8427e");
+}
+
+
+void tst_QCryptographicHash::files()
+{
+ QFETCH(QString, filename);
+ QFETCH(QCryptographicHash::Algorithm, algorithm);
+ QFETCH(QByteArray, md5sum);
+ {
+ QFile f(QString::fromLocal8Bit(SRCDIR) + filename);
+ QCryptographicHash hash(algorithm);
+ QVERIFY(! hash.addData(&f)); // file is not open for reading;
+ if (f.open(QIODevice::ReadOnly)) {
+ QVERIFY(hash.addData(&f));
+ QCOMPARE(hash.result().toHex(),md5sum);
+ } else {
+ QFAIL("Failed to open file for testing. should not happen");
+ }
+ }
+}
+
+
QTEST_MAIN(tst_QCryptographicHash)
#include "tst_qcryptographichash.moc"