Fix FileSystemTest on macOS

This commit is contained in:
Jocelyn Turcotte 2017-02-09 17:40:32 +01:00
parent 0be6cd3bf7
commit 0e3e9d5991

View file

@ -17,7 +17,7 @@ class TestFileSystem : public QObject
{ {
Q_OBJECT Q_OBJECT
QString _root; QTemporaryDir _root;
QByteArray shellSum( const QByteArray& cmd, const QString& file ) QByteArray shellSum( const QByteArray& cmd, const QString& file )
@ -38,51 +38,36 @@ class TestFileSystem : public QObject
} }
private slots: 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() void testMd5Calc()
{ {
QString file( _root+"/file_a.bin"); QString file( _root.path() + "/file_a.bin");
writeRandomFile(file); QVERIFY(writeRandomFile(file));
QFileInfo fi(file); QFileInfo fi(file);
QVERIFY(fi.exists()); QVERIFY(fi.exists());
QByteArray sum = calcMd5(file); QByteArray sum = calcMd5(file);
QByteArray sSum = shellSum("/usr/bin/md5sum", file); QByteArray sSum = shellSum("md5sum", file);
qDebug() << "calculated" << sum << "versus md5sum:"<< sSum; if (sSum.isEmpty())
QVERIFY(!sSum.isEmpty()); QSKIP("Couldn't execute md5sum to calculate checksum, executable missing?", SkipSingle);
QVERIFY(!sum.isEmpty()); QVERIFY(!sum.isEmpty());
QVERIFY(sSum == sum ); QCOMPARE(sSum, sum);
} }
void testSha1Calc() void testSha1Calc()
{ {
QString file( _root+"/file_b.bin"); QString file( _root.path() + "/file_b.bin");
writeRandomFile(file); writeRandomFile(file);
QFileInfo fi(file); QFileInfo fi(file);
QVERIFY(fi.exists()); QVERIFY(fi.exists());
QByteArray sum = calcSha1(file); QByteArray sum = calcSha1(file);
QByteArray sSum = shellSum("/usr/bin/sha1sum", file); QByteArray sSum = shellSum("sha1sum", file);
qDebug() << "calculated" << sum << "versus sha1sum:"<< sSum; if (sSum.isEmpty())
QVERIFY(!sSum.isEmpty()); QSKIP("Couldn't execute sha1sum to calculate checksum, executable missing?", SkipSingle);
QVERIFY(!sum.isEmpty()); QVERIFY(!sum.isEmpty());
QVERIFY(sSum == sum ); QCOMPARE(sSum, sum);
} }
}; };