Commit 15f15662 authored by Laurent Montel's avatar Laurent Montel 😁

Don't add same files

parent b1f555ab
......@@ -42,6 +42,12 @@ add_messageviewer_unittest( todoedittest.cpp )
add_messageviewer_unittest( eventedittest.cpp )
add_messageviewer_unittest( eventdatetimewidgettest.cpp )
add_messageviewer_unittest( messagedisplayformatattributetest.cpp )
set( messageviewer_attachmentdirs_SRCS attachmenttemporaryfilesdirstest.cpp ../viewer/attachmenttemporaryfilesdirs.cpp)
kde4_add_unit_test( messageviewer_attachmentdirstest ${messageviewer_attachmentdirs_SRCS})
target_link_libraries( messageviewer_attachmentdirstest ${QT_QTTEST_LIBRARY} ${KDE4_KDEUI_LIBS})
########### viewertest_gui ###############
......
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#include "attachmenttemporaryfilesdirstest.h"
#include "../viewer/attachmenttemporaryfilesdirs.h"
#include <qtest_kde.h>
AttachmentTemporaryFilesDirsTest::AttachmentTemporaryFilesDirsTest(QObject *parent)
: QObject(parent)
{
}
AttachmentTemporaryFilesDirsTest::~AttachmentTemporaryFilesDirsTest()
{
}
void AttachmentTemporaryFilesDirsTest::shouldHaveDefaultValue()
{
MessageViewer::AttachmentTemporaryFilesDirs attachmentDir;
QVERIFY(attachmentDir.temporaryFiles().isEmpty());
QVERIFY(attachmentDir.temporaryDirs().isEmpty());
}
void AttachmentTemporaryFilesDirsTest::shouldAddTemporaryFiles()
{
MessageViewer::AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempFile(QLatin1String("foo"));
QCOMPARE(attachmentDir.temporaryFiles().count(), 1);
attachmentDir.addTempFile(QLatin1String("foo1"));
QCOMPARE(attachmentDir.temporaryFiles().count(), 2);
}
void AttachmentTemporaryFilesDirsTest::shouldAddTemporaryDirs()
{
MessageViewer::AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempDir(QLatin1String("foo"));
QCOMPARE(attachmentDir.temporaryDirs().count(), 1);
attachmentDir.addTempDir(QLatin1String("foo1"));
QCOMPARE(attachmentDir.temporaryDirs().count(), 2);
}
void AttachmentTemporaryFilesDirsTest::shouldNotAddSameFiles()
{
MessageViewer::AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempFile(QLatin1String("foo"));
QCOMPARE(attachmentDir.temporaryFiles().count(), 1);
attachmentDir.addTempFile(QLatin1String("foo"));
QCOMPARE(attachmentDir.temporaryFiles().count(), 1);
}
void AttachmentTemporaryFilesDirsTest::shouldNotAddSameDirs()
{
MessageViewer::AttachmentTemporaryFilesDirs attachmentDir;
attachmentDir.addTempDir(QLatin1String("foo"));
QCOMPARE(attachmentDir.temporaryDirs().count(), 1);
attachmentDir.addTempDir(QLatin1String("foo"));
QCOMPARE(attachmentDir.temporaryDirs().count(), 1);
}
QTEST_KDEMAIN(AttachmentTemporaryFilesDirsTest, NoGUI)
/*
Copyright (c) 2014 Montel Laurent <montel@kde.org>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef ATTACHMENTTEMPORARYFILESDIRSTEST_H
#define ATTACHMENTTEMPORARYFILESDIRSTEST_H
#include <QObject>
class AttachmentTemporaryFilesDirsTest : public QObject
{
Q_OBJECT
public:
explicit AttachmentTemporaryFilesDirsTest(QObject *parent=0);
~AttachmentTemporaryFilesDirsTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldAddTemporaryFiles();
void shouldAddTemporaryDirs();
void shouldNotAddSameFiles();
void shouldNotAddSameDirs();
};
#endif // ATTACHMENTTEMPORARYFILESDIRSTEST_H
......@@ -68,12 +68,16 @@ void AttachmentTemporaryFilesDirs::slotRemoveTempFiles()
void AttachmentTemporaryFilesDirs::addTempFile( const QString &file )
{
mTempFiles.append( file );
if (!mTempFiles.contains(file)) {
mTempFiles.append( file );
}
}
void AttachmentTemporaryFilesDirs::addTempDir( const QString &dir )
{
mTempDirs.append( dir );
if (!mTempDirs.contains(dir)) {
mTempDirs.append( dir );
}
}
QStringList AttachmentTemporaryFilesDirs::temporaryFiles() const
......@@ -81,4 +85,8 @@ QStringList AttachmentTemporaryFilesDirs::temporaryFiles() const
return mTempFiles;
}
QStringList AttachmentTemporaryFilesDirs::temporaryDirs() const
{
return mTempDirs;
}
......@@ -39,6 +39,7 @@ public:
void removeTempFiles();
void forceCleanTempFiles();
QStringList temporaryDirs() const;
private Q_SLOTS:
void slotRemoveTempFiles();
......
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