forked from owncloud/client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestfilesystem.cpp
76 lines (59 loc) · 1.8 KB
/
testfilesystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
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.
*/
#include <QtTest>
#include <QDebug>
#include "filesystem.h"
#include "utility.h"
using namespace OCC::Utility;
using namespace OCC::FileSystem;
class TestFileSystem : public QObject
{
Q_OBJECT
QTemporaryDir _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 testMd5Calc()
{
QString file( _root.path() + "/file_a.bin");
QVERIFY(writeRandomFile(file));
QFileInfo fi(file);
QVERIFY(fi.exists());
QByteArray sum = calcMd5(file);
QByteArray sSum = shellSum("md5sum", file);
if (sSum.isEmpty())
QSKIP("Couldn't execute md5sum to calculate checksum, executable missing?", SkipSingle);
QVERIFY(!sum.isEmpty());
QCOMPARE(sSum, sum);
}
void testSha1Calc()
{
QString file( _root.path() + "/file_b.bin");
writeRandomFile(file);
QFileInfo fi(file);
QVERIFY(fi.exists());
QByteArray sum = calcSha1(file);
QByteArray sSum = shellSum("sha1sum", file);
if (sSum.isEmpty())
QSKIP("Couldn't execute sha1sum to calculate checksum, executable missing?", SkipSingle);
QVERIFY(!sum.isEmpty());
QCOMPARE(sSum, sum);
}
};
QTEST_APPLESS_MAIN(TestFileSystem)
#include "testfilesystem.moc"