[Pkg-owncloud-commits] [owncloud-client] 59/175: Checksum Calculation: Add unit test.

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Aug 8 10:36:27 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 823f9fa0d1e42e8acfaad3132c0bd0c0a8e847e1
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Tue May 12 15:49:01 2015 +0200

    Checksum Calculation: Add unit test.
---
 test/CMakeLists.txt   |  1 +
 test/testfilesystem.h | 93 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 94 insertions(+)

diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index f1d4406..ac3b34e 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -33,4 +33,5 @@ owncloud_add_test(SyncFileItem "")
 owncloud_add_test(ConcatUrl "")
 
 owncloud_add_test(XmlParse "")
+owncloud_add_test(FileSystem "")
 
diff --git a/test/testfilesystem.h b/test/testfilesystem.h
new file mode 100644
index 0000000..e824edc
--- /dev/null
+++ b/test/testfilesystem.h
@@ -0,0 +1,93 @@
+/*
+   This software is in the public domain, furnished "as is", without technical
+   support, and with no warranty, express or implied, as to its usefulness for
+   any purpose.
+*/
+
+#ifndef MIRALL_TESTFILESYSTEM_H
+#define MIRALL_TESTFILESYSTEM_H
+
+#include <QtTest>
+#include <QDebug>
+
+#include "filesystem.h"
+#include "utility.h"
+
+using namespace OCC::Utility;
+using namespace OCC::FileSystem;
+
+class TestFileSystem : public QObject
+{
+    Q_OBJECT
+
+    QString _root;
+
+
+    QByteArray shellSum( const QByteArray& cmd, const QString& file )
+    {
+       QProcess md5;
+       QStringList args;
+       args.append(file);
+       md5.start(cmd, args);
+       QByteArray sumShell;
+       qDebug() << "File: "<< file;
+
+       if( md5.waitForFinished()  ) {
+
+         sumShell = md5.readAll();
+         sumShell = sumShell.left( sumShell.indexOf(' '));
+       }
+       return sumShell;
+    }
+
+private slots:
+    void initTestCase() {
+        qsrand(QTime::currentTime().msec());
+
+        QString subdir("test_"+QString::number(qrand()));
+        _root = QDir::tempPath() + "/" + subdir;
+
+        QDir dir("/tmp");
+        dir.mkdir(subdir);
+        qDebug() << "creating test directory " << _root;
+    }
+
+    void cleanupTestCase()
+    {
+      if( !_root.isEmpty() )
+        system(QString("rm -rf "+_root).toUtf8());
+    }
+
+    void testMd5Calc()
+    {
+       QString file( _root+"/file_a.bin");
+       writeRandomFile(file);
+       QFileInfo fi(file);
+       QVERIFY(fi.exists());
+       QByteArray sum = calcMd5(file);
+
+       QByteArray sSum = shellSum("/usr/bin/md5sum", file);
+       qDebug() << "calulated" << sum << "versus md5sum:"<< sSum;
+       QVERIFY(!sSum.isEmpty());
+       QVERIFY(!sum.isEmpty());
+       QVERIFY(sSum == sum );
+    }
+
+    void testSha1Calc()
+    {
+       QString file( _root+"/file_b.bin");
+       writeRandomFile(file);
+       QFileInfo fi(file);
+       QVERIFY(fi.exists());
+       QByteArray sum = calcSha1(file);
+
+       QByteArray sSum = shellSum("/usr/bin/sha1sum", file);
+       qDebug() << "calulated" << sum << "versus sha1sum:"<< sSum;
+       QVERIFY(!sSum.isEmpty());
+       QVERIFY(!sum.isEmpty());
+       QVERIFY(sSum == sum );
+    }
+
+};
+
+#endif

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list