kde4_add_unit_test(dolphintreeviewtest TEST dolphintreeviewtest.cpp)
target_link_libraries(dolphintreeviewtest dolphinprivate ${QT_QTCORE_LIBRARY} ${KDE4_KDEUI_LIBS} ${QT_QTTEST_LIBRARY})
+
+kde4_add_unit_test(dolphindetailsviewtest TEST dolphindetailsviewtest.cpp testhelper.cpp ../views/zoomlevelinfo.cpp)
+target_link_libraries(dolphindetailsviewtest dolphinprivate ${QT_QTCORE_LIBRARY} ${KDE4_KDEUI_LIBS} ${QT_QTTEST_LIBRARY})
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2010 by Frank Reininghaus (frank78ac@googlemail.com) *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#include <qtest_kde.h>
+
+#include "testhelper.h"
+
+#include "views/dolphindetailsview.h"
+#include "views/dolphinview.h"
+#include "views/dolphinmodel.h"
+#include "views/dolphindirlister.h"
+#include "views/dolphinsortfilterproxymodel.h"
+#include "views/zoomlevelinfo.h"
+
+#include <KTempDir>
+
+#include <QtCore/QDir>
+
+#include "kdebug.h"
+
+class DolphinDetailsViewTest : public QObject
+{
+ Q_OBJECT
+
+private slots:
+
+ void initTestCase();
+ void cleanupTestCase();
+
+ void bug234600_overlappingIconsWhenZooming();
+
+private:
+
+ TestHelper* m_helper;
+ DolphinView* m_view;
+};
+
+void DolphinDetailsViewTest::initTestCase()
+{
+ m_helper = new TestHelper;
+ m_view = m_helper->view();
+}
+
+void DolphinDetailsViewTest::cleanupTestCase()
+{
+ delete m_helper;
+}
+
+/**
+ * When the icon size is changed, we have to make sure that the maximumSize given
+ * to KFileItemDelegate for rendering each item is updated correctly. If this is not
+ * done, the visualRects are clipped by the incorrect maximum size, and the icons
+ * may overlap, see
+ *
+ * https://bugs.kde.org/show_bug.cgi?id=234600
+ */
+
+void DolphinDetailsViewTest::bug234600_overlappingIconsWhenZooming()
+{
+ QStringList files;
+ files << "a" << "b" << "c" << "d";
+ m_helper->createFiles(files);
+
+ m_view->setMode(DolphinView::DetailsView);
+ DolphinDetailsView* detailsView = qobject_cast<DolphinDetailsView*>(m_helper->itemView());
+ QVERIFY(detailsView);
+ m_view->resize(400, 400);
+ m_view->show();
+ QTest::qWaitForWindowShown(m_view);
+
+ // We have to make sure that the view has loaded the directory before we start the test.
+ // TODO: This will be needed frequently. Maybe move to TestHelper.
+ QSignalSpy finished(m_view, SIGNAL(finishedPathLoading(const KUrl&)));
+ m_view->reload();
+ while (finished.count() != 1) {
+ QTest::qWait(50);
+ }
+
+ QModelIndex index0 = detailsView->model()->index(0, 0);
+ detailsView->setCurrentIndex(index0);
+ QCOMPARE(detailsView->currentIndex(), index0);
+
+ // Setting the zoom level to the minimum value and triggering DolphinDetailsView::currentChanged(...)
+ // should make sure that the bug is triggered.
+ int zoomLevel = ZoomLevelInfo::minimumLevel();
+ m_view->setZoomLevel(zoomLevel);
+
+ QModelIndex index1 = detailsView->model()->index(1, 0);
+ detailsView->setCurrentIndex(index1);
+ QCOMPARE(detailsView->currentIndex(), index1);
+
+ // Increase the zoom level successively to the maximum.
+ while(zoomLevel < ZoomLevelInfo::maximumLevel()) {
+ zoomLevel++;
+ m_view->setZoomLevel(zoomLevel);
+
+ //Check for each zoom level that the height of each item is at least the icon size.
+ QVERIFY(detailsView->visualRect(index1).height() >= ZoomLevelInfo::iconSizeForZoomLevel(zoomLevel));
+ }
+
+ m_view->hide();
+ m_helper->cleanupTestDir();
+}
+
+QTEST_KDEMAIN(DolphinDetailsViewTest, GUI)
+
+#include "dolphindetailsviewtest.moc"
\ No newline at end of file
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2010 by Frank Reininghaus (frank78ac@googlemail.com) *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#include "testhelper.h"
+
+#include "views/dolphinview.h"
+#include "views/dolphinmodel.h"
+#include "views/dolphindirlister.h"
+#include "views/dolphinsortfilterproxymodel.h"
+
+#include <KTempDir>
+
+#include <QtCore/QDir>
+#include <QtGui/QAbstractItemView>
+
+TestHelper::TestHelper()
+{
+ m_tempDir = new KTempDir;
+ Q_ASSERT(m_tempDir->exists());
+ m_path = m_tempDir->name();
+ m_dir = new QDir(m_path);
+ m_dirLister = new DolphinDirLister();
+ m_dirLister->setAutoUpdate(true);
+ m_dolphinModel = new DolphinModel();
+ m_dolphinModel->setDirLister(m_dirLister);
+ m_proxyModel = new DolphinSortFilterProxyModel(0);
+ m_proxyModel->setSourceModel(m_dolphinModel);
+ m_proxyModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
+ m_view = new DolphinView(0, KUrl(m_path), m_proxyModel);
+}
+
+TestHelper::~TestHelper()
+{
+ delete m_view;
+ delete m_proxyModel;
+ // m_dolphinModel owns m_dirLister -> do not delete it here!
+ delete m_dolphinModel;
+ delete m_dir;
+ delete m_tempDir;
+}
+
+QAbstractItemView* TestHelper::itemView () const
+{
+ return m_view->m_viewAccessor.itemView();
+}
+
+
+KUrl TestHelper::testDirUrl() const
+{
+ return KUrl(m_path);
+}
+
+void TestHelper::createFile(const QString& path, const QByteArray& data)
+{
+ QString absolutePath = path;
+ makePathAbsoluteAndCreateParents(absolutePath);
+
+ QFile f(absolutePath);
+ f.open(QIODevice::WriteOnly);
+ f.write(data);
+ f.close();
+
+ Q_ASSERT(QFile::exists(absolutePath));
+}
+
+void TestHelper::createFiles(const QStringList& files)
+{
+ foreach(const QString& path, files) {
+ createFile(path);
+ }
+}
+
+void TestHelper::createDir(const QString& path)
+{
+ QString absolutePath = path;
+ makePathAbsoluteAndCreateParents(absolutePath);
+ m_dir->mkdir(absolutePath);
+
+ Q_ASSERT(QFile::exists(absolutePath));
+}
+
+void TestHelper::makePathAbsoluteAndCreateParents(QString& path)
+{
+ QFileInfo fileInfo(path);
+ if (!fileInfo.isAbsolute()) {
+ path = m_path + path;
+ fileInfo.setFile(path);
+ }
+
+ const QDir dir = fileInfo.dir();
+ if (!dir.exists()) {
+ createDir(dir.absolutePath());
+ }
+
+ Q_ASSERT(dir.exists());
+}
+
+void TestHelper::cleanupTestDir()
+{
+ delete m_tempDir;
+ m_tempDir = new KTempDir;
+ Q_ASSERT(m_tempDir->exists());
+ m_path = m_tempDir->name();
+ m_dir->setPath(m_path);
+ m_view->setUrl(m_path);
+}
--- /dev/null
+/***************************************************************************
+ * Copyright (C) 2010 by Frank Reininghaus (frank78ac@googlemail.com) *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program 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 General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
+ ***************************************************************************/
+
+#ifndef TESTHELPER_H
+#define TESTHELPER_H
+
+#include <KUrl>
+
+class KTempDir;
+class QAbstractItemView;
+class QDir;
+class DolphinDirLister;
+class DolphinModel;
+class DolphinSortFilterProxyModel;
+class DolphinView;
+
+/*
+ * The class TestHelper aims to make writing Dolphin unit tests easier.
+ * It provides functionality that almost every unit test needs: setup of the DolphinView and
+ * easy creation of test files and subfolders in a temporary directory which is removed in
+ * the TestHelper destructor.
+ *
+ * TODO: TestHelper should also backup the DolphinSettings and restore them later!
+ */
+
+class TestHelper
+{
+
+public:
+
+ TestHelper();
+ ~TestHelper();
+
+ DolphinView* view() const { return m_view; }
+ DolphinSortFilterProxyModel* proxyModel() const { return m_proxyModel; }
+
+ // Returns the item view (icons, details, or columns)
+ QAbstractItemView* itemView () const;
+
+ KUrl testDirUrl() const;
+
+ /*
+ * The following functions create either a file, a list of files, or a directory.
+ * The paths may be absolute or relative to the test directory. Any missing parent
+ * directories will be created automatically.
+ */
+
+ void createFile(const QString& path, const QByteArray& data = QByteArray("test"));
+ void createFiles(const QStringList& files);
+ void createDir(const QString& path);
+
+ /*
+ * Remove the test directory and create an empty one.
+ */
+
+ void cleanupTestDir();
+
+private:
+
+ void makePathAbsoluteAndCreateParents(QString& path);
+
+ KTempDir* m_tempDir;
+ QString m_path;
+ QDir* m_dir;
+ DolphinDirLister* m_dirLister;
+ DolphinModel* m_dolphinModel;
+ DolphinSortFilterProxyModel* m_proxyModel;
+ DolphinView* m_view;
+
+};
+
+#endif
\ No newline at end of file
*/
QSet<KUrl> expandedUrls() const;
+public:
+ virtual QRect visualRect(const QModelIndex& index) const;
+
protected:
virtual bool event(QEvent* event);
virtual QStyleOptionViewItem viewOptions() const;
virtual void wheelEvent(QWheelEvent* event);
virtual void currentChanged(const QModelIndex& current, const QModelIndex& previous);
virtual bool eventFilter(QObject* watched, QEvent* event);
- virtual QRect visualRect(const QModelIndex& index) const;
virtual bool acceptsDrop(const QModelIndex& index) const;
protected slots:
* slotDirListerCompleted().
*/
QSet<QString> m_newFileNames;
+
+ // For unit tests
+ friend class TestHelper;
};
/// Allow using DolphinView::Mode in QVariant