┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrank Reininghaus <[email protected]>2011-01-22 20:39:20 +0000
committerFrank Reininghaus <[email protected]>2011-01-22 20:39:20 +0000
commit8653fc7f874137791f93b609b5196cbd99457331 (patch)
tree0c2eec16f50b4bbd1a73705c1eadd4ca72678d7b
parent51a4c273a0ff8b8bc27f4ecb3ab155e18361955a (diff)
Add a unit test that checks the DolphinView functionality that is
related to the folder view properties. svn path=/trunk/KDE/kdebase/apps/; revision=1216359
-rw-r--r--src/tests/dolphinviewtest_allviewmodes.cpp140
-rw-r--r--src/tests/dolphinviewtest_allviewmodes.h37
-rw-r--r--src/tests/testbase.cpp85
-rw-r--r--src/tests/testbase.h48
4 files changed, 233 insertions, 77 deletions
diff --git a/src/tests/dolphinviewtest_allviewmodes.cpp b/src/tests/dolphinviewtest_allviewmodes.cpp
index d1557be05..3eb78c0d2 100644
--- a/src/tests/dolphinviewtest_allviewmodes.cpp
+++ b/src/tests/dolphinviewtest_allviewmodes.cpp
@@ -1,21 +1,21 @@
-/***************************************************************************
- * Copyright (C) 2010 by Frank Reininghaus ([email protected]) *
- * *
- * 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 *
- ***************************************************************************/
+/*****************************************************************************
+ * Copyright (C) 2010-2011 by Frank Reininghaus ([email protected]) *
+ * *
+ * 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 "dolphinviewtest_allviewmodes.h"
@@ -110,6 +110,110 @@ void DolphinViewTest_AllViewModes::testSelection() {
}
/**
+ * Check that setting the directory view properties works.
+ */
+
+void DolphinViewTest_AllViewModes::testViewPropertySettings()
+{
+ // Create some files with different sizes and modification times to check the different sorting options
+ QDateTime now = QDateTime::currentDateTime();
+
+ createFile("a", "A file", now.addDays(-3));
+ createFile("b", "A larger file", now.addDays(0));
+ createDir("c", now.addDays(-2));
+ createFile("d", "The largest file in this directory", now.addDays(-1));
+ createFile("e", "An even larger file", now.addDays(-4));
+ createFile(".f");
+
+ reloadViewAndWait();
+
+ // First set all settings to the default.
+ m_view->setSorting(DolphinView::SortByName);
+ QCOMPARE(m_view->sorting(), DolphinView::SortByName);
+
+ m_view->setSortOrder(Qt::AscendingOrder);
+ QCOMPARE(m_view->sortOrder(), Qt::AscendingOrder);
+
+ m_view->setSortFoldersFirst(true);
+ QVERIFY(m_view->sortFoldersFirst());
+
+ m_view->setShowPreview(false);
+ QVERIFY(!m_view->showPreview());
+
+ m_view->setShowHiddenFiles(false);
+ QVERIFY(!m_view->showHiddenFiles());
+
+ if (mode() == DolphinView::ColumnView) {
+ // If the columns view is used, the view is empty before calling qApp->sendPostedEvents.
+ // It seems that some event needs to be processed to see the items in the view.
+ // TODO: Find out why this is needed for the columns view, but not for the other view modes.
+ qApp->sendPostedEvents();
+ }
+
+ /** Check that the sort order is correct for different kinds of settings */
+
+ // Sort by Name, ascending
+ QCOMPARE(m_view->sorting(), DolphinView::SortByName);
+ QCOMPARE(m_view->sortOrder(), Qt::AscendingOrder);
+ QCOMPARE(viewItems(), QStringList() << "c" << "a" << "b" << "d" << "e");
+
+ // Sort by Name, descending
+ m_view->setSortOrder(Qt::DescendingOrder);
+ QCOMPARE(m_view->sorting(), DolphinView::SortByName);
+ QCOMPARE(m_view->sortOrder(), Qt::DescendingOrder);
+ QCOMPARE(viewItems(), QStringList() << "c" << "e" << "d" << "b" << "a");
+
+ // Sort by Size, descending
+ m_view->setSorting(DolphinView::SortBySize);
+ QCOMPARE(m_view->sorting(), DolphinView::SortBySize);
+ QCOMPARE(m_view->sortOrder(), Qt::DescendingOrder);
+ QCOMPARE(viewItems(), QStringList() << "c" << "d" << "e" << "b" << "a");
+
+ // Sort by Size, ascending
+ m_view->setSortOrder(Qt::AscendingOrder);
+ QCOMPARE(m_view->sorting(), DolphinView::SortBySize);
+ QCOMPARE(m_view->sortOrder(), Qt::AscendingOrder);
+ QCOMPARE(viewItems(), QStringList() << "c" << "a" << "b" << "e" << "d");
+
+ // Sort by Date, ascending
+ m_view->setSorting(DolphinView::SortByDate);
+ QCOMPARE(m_view->sorting(), DolphinView::SortByDate);
+ QCOMPARE(m_view->sortOrder(), Qt::AscendingOrder);
+ QCOMPARE(viewItems(), QStringList() << "c" << "e" << "a" << "d" << "b");
+
+ // Sort by Date, descending
+ m_view->setSortOrder(Qt::DescendingOrder);
+ QCOMPARE(m_view->sorting(), DolphinView::SortByDate);
+ QCOMPARE(m_view->sortOrder(), Qt::DescendingOrder);
+ QCOMPARE(viewItems(), QStringList() << "c" << "b" << "d" << "a" << "e");
+
+ // Disable "Sort Folders First"
+ m_view->setSortFoldersFirst(false);
+ QVERIFY(!m_view->sortFoldersFirst());
+ QCOMPARE(viewItems(), QStringList()<< "b" << "d" << "c" << "a" << "e");
+
+ // Try again with Sort by Name, ascending
+ m_view->setSorting(DolphinView::SortByName);
+ m_view->setSortOrder(Qt::AscendingOrder);
+ QCOMPARE(m_view->sorting(), DolphinView::SortByName);
+ QCOMPARE(m_view->sortOrder(), Qt::AscendingOrder);
+ QCOMPARE(viewItems(), QStringList() << "a" << "b" << "c" << "d" << "e");
+
+ // Show hidden files. This triggers the dir lister
+ // -> we have to wait until loading the hidden files is finished
+ m_view->setShowHiddenFiles(true);
+ QVERIFY(QTest::kWaitForSignal(m_view, SIGNAL(finishedPathLoading(const KUrl&)), 2000));
+ QVERIFY(m_view->showHiddenFiles());
+ QCOMPARE(viewItems(), QStringList() << ".f" << "a" << "b" << "c" << "d" << "e");
+
+ // Previews
+ m_view->setShowPreview(true);
+ QVERIFY(m_view->showPreview());
+
+ // TODO: Check that the view properties are restored correctly when changing the folder and then going back.
+}
+
+/**
* testKeyboardFocus() checks whether a view grabs the keyboard focus.
*
* A view may never grab the keyboard focus itself and must respect the focus-state
diff --git a/src/tests/dolphinviewtest_allviewmodes.h b/src/tests/dolphinviewtest_allviewmodes.h
index feaa9d9fc..690459584 100644
--- a/src/tests/dolphinviewtest_allviewmodes.h
+++ b/src/tests/dolphinviewtest_allviewmodes.h
@@ -1,21 +1,21 @@
-/***************************************************************************
- * Copyright (C) 2010 by Frank Reininghaus ([email protected]) *
- * *
- * 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 *
- ***************************************************************************/
+/*****************************************************************************
+ * Copyright (C) 2010-2011 by Frank Reininghaus ([email protected]) *
+ * *
+ * 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 DOLPHINVIEWTEST_ALLVIEWMODES
#define DOLPHINVIEWTEST_ALLVIEWMODES
@@ -49,6 +49,7 @@ private slots:
void cleanup();
void testSelection();
+ void testViewPropertySettings();
void testKeyboardFocus();
diff --git a/src/tests/testbase.cpp b/src/tests/testbase.cpp
index db71fa48c..1cb326766 100644
--- a/src/tests/testbase.cpp
+++ b/src/tests/testbase.cpp
@@ -1,21 +1,21 @@
-/***************************************************************************
- * Copyright (C) 2010 by Frank Reininghaus ([email protected]) *
- * *
- * 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 *
- ***************************************************************************/
+/*****************************************************************************
+ * Copyright (C) 2010-2011 by Frank Reininghaus ([email protected]) *
+ * *
+ * 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 "testbase.h"
@@ -33,6 +33,12 @@
#include <kdebug.h>
+#ifdef Q_OS_UNIX
+#include <utime.h>
+#else
+#include <sys/utime.h>
+#endif
+
TestBase::TestBase()
{
m_tempDir = new KTempDir;
@@ -49,7 +55,7 @@ TestBase::~TestBase()
delete m_tempDir;
}
-QAbstractItemView* TestBase::itemView () const
+QAbstractItemView* TestBase::itemView() const
{
return m_view->m_viewAccessor.itemView();
}
@@ -65,7 +71,24 @@ KUrl TestBase::testDirUrl() const
return KUrl(m_path);
}
-void TestBase::createFile(const QString& path, const QByteArray& data)
+/** The following function is taken from kdelibs/kio/tests/kiotesthelper.h, copyright (C) 2006 by David Faure */
+
+static void setTimeStamp(const QString& path, const QDateTime& mtime)
+{
+#ifdef Q_OS_UNIX
+ struct utimbuf utbuf;
+ utbuf.actime = mtime.toTime_t();
+ utbuf.modtime = utbuf.actime;
+ utime(QFile::encodeName(path), &utbuf);
+#elif defined(Q_OS_WIN)
+ struct _utimbuf utbuf;
+ utbuf.actime = mtime.toTime_t();
+ utbuf.modtime = utbuf.actime;
+ _wutime(reinterpret_cast<const wchar_t *>(path.utf16()), &utbuf);
+#endif
+}
+
+void TestBase::createFile(const QString& path, const QByteArray& data, const QDateTime& time)
{
QString absolutePath = path;
makePathAbsoluteAndCreateParents(absolutePath);
@@ -75,6 +98,10 @@ void TestBase::createFile(const QString& path, const QByteArray& data)
f.write(data);
f.close();
+ if (time.isValid()) {
+ setTimeStamp(absolutePath, time);
+ }
+
Q_ASSERT(QFile::exists(absolutePath));
}
@@ -85,15 +112,31 @@ void TestBase::createFiles(const QStringList& files)
}
}
-void TestBase::createDir(const QString& path)
+void TestBase::createDir(const QString& path, const QDateTime& time)
{
QString absolutePath = path;
makePathAbsoluteAndCreateParents(absolutePath);
m_dir->mkdir(absolutePath);
+ if (time.isValid()) {
+ setTimeStamp(absolutePath, time);
+ }
+
Q_ASSERT(QFile::exists(absolutePath));
}
+QStringList TestBase::viewItems() const
+{
+ QStringList itemList;
+ const QAbstractItemModel* model = itemView()->model();
+
+ for (int row = 0; row < model->rowCount(); row++) {
+ itemList << model->data(model->index(row, 0), Qt::DisplayRole).toString();
+ }
+
+ return itemList;
+}
+
void TestBase::makePathAbsoluteAndCreateParents(QString& path)
{
QFileInfo fileInfo(path);
diff --git a/src/tests/testbase.h b/src/tests/testbase.h
index 70e2ae8a7..d197a3f92 100644
--- a/src/tests/testbase.h
+++ b/src/tests/testbase.h
@@ -1,27 +1,29 @@
-/***************************************************************************
- * Copyright (C) 2010 by Frank Reininghaus ([email protected]) *
- * *
- * 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 *
- ***************************************************************************/
+/*****************************************************************************
+ * Copyright (C) 2010-2011 by Frank Reininghaus ([email protected]) *
+ * *
+ * 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>
+#include <QtCore/QDateTime>
+
class KTempDir;
class QAbstractItemView;
class QDir;
@@ -62,9 +64,15 @@ public:
* directories will be created automatically.
*/
- void createFile(const QString& path, const QByteArray& data = QByteArray("test"));
+ void createFile(const QString& path, const QByteArray& data = QByteArray("test"), const QDateTime& time = QDateTime());
void createFiles(const QStringList& files);
- void createDir(const QString& path);
+ void createDir(const QString& path, const QDateTime& time = QDateTime());
+
+ /**
+ * Returns the items shown in the view. The order corresponds to the sort order of the view.
+ */
+
+ QStringList viewItems() const;
/**
* Remove the test directory and create an empty one.