Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 534fdff9 authored by Laurent Montel's avatar Laurent Montel 😁

improve unittest

parent f3700ec8
......@@ -20,7 +20,9 @@
#include "attachmenttemporaryfilesdirstest.h"
#include "../attachmenttemporaryfilesdirs.h"
#include <KTempDir>
#include <qtest_kde.h>
#include <KDebug>
using namespace PimCommon;
......@@ -78,4 +80,43 @@ void AttachmentTemporaryFilesDirsTest::shouldNotAddSameDirs()
QCOMPARE(attachmentDir.temporaryDirs().count(), 1);
}
void AttachmentTemporaryFilesDirsTest::shouldForceRemoveTemporaryDirs()
{
AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempDir(QLatin1String("foo"));
attachmentDir.addTempDir(QLatin1String("foo1"));
QCOMPARE(attachmentDir.temporaryDirs().count(), 2);
attachmentDir.forceCleanTempFiles();
QCOMPARE(attachmentDir.temporaryDirs().count(), 0);
}
void AttachmentTemporaryFilesDirsTest::shouldForceRemoveTemporaryFiles()
{
AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempFile(QLatin1String("foo"));
attachmentDir.addTempFile(QLatin1String("foo2"));
QCOMPARE(attachmentDir.temporaryFiles().count(), 2);
attachmentDir.forceCleanTempFiles();
QCOMPARE(attachmentDir.temporaryFiles().count(), 0);
}
void AttachmentTemporaryFilesDirsTest::shouldCreateDeleteTemporaryFiles()
{
KTempDir tmpDir;
QVERIFY(tmpDir.exists());
QFile file(tmpDir.name() + QLatin1String("/foo"));
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
kDebug()<<"Can open file";
return;
}
file.close();
QVERIFY(file.exists());
AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempFile(file.fileName());
QVERIFY(!attachmentDir.temporaryFiles().isEmpty());
QCOMPARE(attachmentDir.temporaryFiles().first(), file.fileName());
attachmentDir.forceCleanTempFiles();
QCOMPARE(attachmentDir.temporaryFiles().count(), 0);
}
QTEST_KDEMAIN(AttachmentTemporaryFilesDirsTest, NoGUI)
......@@ -35,6 +35,9 @@ private Q_SLOTS:
void shouldAddTemporaryDirs();
void shouldNotAddSameFiles();
void shouldNotAddSameDirs();
void shouldForceRemoveTemporaryDirs();
void shouldForceRemoveTemporaryFiles();
void shouldCreateDeleteTemporaryFiles();
};
#endif // ATTACHMENTTEMPORARYFILESDIRSTEST_H
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment