mirror of
https://invent.kde.org/system/dolphin
synced 2024-08-21 17:30:15 +00:00
Ported tests away from KRandomSequence, QTest::kWaitForSignal and KTempDir.
All tests passed!
This commit is contained in:
parent
95220eebae
commit
d19d94e60a
|
@ -52,7 +52,7 @@ set(kitemlistcontrollertest_SRCS
|
|||
../kitemviews/kitemlistview.cpp
|
||||
../kitemviews/kitemlistcontainer.cpp
|
||||
../kitemviews/kitemlistwidget.cpp
|
||||
# ../kitemviews/kitemlistviewaccessible.cpp # TODO: enable once accessibility is ported to Qt5
|
||||
../kitemviews/kitemlistviewaccessible.cpp
|
||||
../kitemviews/kitemset.cpp
|
||||
../kitemviews/kstandarditemlistview.cpp
|
||||
../kitemviews/kstandarditemlistwidget.cpp
|
||||
|
@ -71,7 +71,7 @@ set(kfileitemlistviewtest_SRCS
|
|||
../kitemviews/kfileitemlistview.cpp
|
||||
../kitemviews/kitemmodelbase.cpp
|
||||
../kitemviews/kitemlistview.cpp
|
||||
# ../kitemviews/kitemlistviewaccessible.cpp # TODO: enable once accessibility is ported to Qt5
|
||||
../kitemviews/kitemlistviewaccessible.cpp
|
||||
../kitemviews/kitemlistcontainer.cpp
|
||||
../kitemviews/kitemlistwidget.cpp
|
||||
../kitemviews/kitemset.cpp
|
||||
|
|
|
@ -17,10 +17,9 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qtest.h>
|
||||
|
||||
#include "search/dolphinsearchbox.h"
|
||||
#include <qtestkeyboard.h>
|
||||
|
||||
#include <QTest>
|
||||
|
||||
class DolphinSearchBoxTest : public QObject
|
||||
{
|
||||
|
|
|
@ -17,18 +17,14 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qtest.h>
|
||||
#include <QSignalSpy>
|
||||
#include "kitemviews/kfileitemlistview.h"
|
||||
#include "kitemviews/kfileitemmodel.h"
|
||||
#include "kitemviews/private/kfileitemmodeldirlister.h"
|
||||
#include "testdir.h"
|
||||
|
||||
#include <QGraphicsView>
|
||||
|
||||
namespace {
|
||||
const int DefaultTimeout = 2000;
|
||||
};
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
|
||||
class KFileItemListViewTest : public QObject
|
||||
{
|
||||
|
@ -91,27 +87,24 @@ void KFileItemListViewTest::cleanup()
|
|||
*/
|
||||
void KFileItemListViewTest::testGroupedItemChanges()
|
||||
{
|
||||
QSignalSpy itemsInsertedSpy(m_model, &KFileItemModel::itemsInserted);
|
||||
QSignalSpy itemsRemovedSpy(m_model, &KFileItemModel::itemsRemoved);
|
||||
|
||||
m_model->setGroupedSorting(true);
|
||||
|
||||
m_testDir->createFiles({"1", "3", "5"});
|
||||
|
||||
m_model->loadDirectory(m_testDir->url());
|
||||
QSignalSpy psy(m_model, SIGNAL(itemsInserted(KItemRangeList)));
|
||||
QVERIFY(psy.wait(DefaultTimeout));
|
||||
QVERIFY(itemsInsertedSpy.wait());
|
||||
QCOMPARE(m_model->count(), 3);
|
||||
|
||||
m_testDir->createFiles({"2", "4"});
|
||||
m_model->m_dirLister->updateDirectory(m_testDir->url());
|
||||
QSignalSpy psyItemsInserted(m_model, SIGNAL(itemsInserted(KItemRangeList)));
|
||||
QVERIFY(psyItemsInserted.wait(DefaultTimeout));
|
||||
QVERIFY(itemsInsertedSpy.wait());
|
||||
QCOMPARE(m_model->count(), 5);
|
||||
|
||||
m_testDir->removeFile("1");
|
||||
m_testDir->removeFile("3");
|
||||
m_testDir->removeFile("5");
|
||||
m_testDir->removeFiles({"1", "3", "5"});
|
||||
m_model->m_dirLister->updateDirectory(m_testDir->url());
|
||||
QSignalSpy psyItemsRemoved(m_model, SIGNAL(itemsRemoved(KItemRangeList)));
|
||||
QVERIFY(psyItemsRemoved.wait(DefaultTimeout));
|
||||
QVERIFY(itemsRemovedSpy.wait());
|
||||
QCOMPARE(m_model->count(), 2);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,15 +18,17 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qtest.h>
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
|
||||
#include <algorithm>
|
||||
#include <random>
|
||||
|
||||
#include "kitemviews/kfileitemmodel.h"
|
||||
#include "kitemviews/private/kfileitemmodelsortalgorithm.h"
|
||||
|
||||
#include "testdir.h"
|
||||
|
||||
#include <KRandomSequence>
|
||||
|
||||
void myMessageOutput(QtMsgType type, const char* msg)
|
||||
{
|
||||
switch (type) {
|
||||
|
@ -45,10 +47,6 @@ void myMessageOutput(QtMsgType type, const char* msg)
|
|||
}
|
||||
}
|
||||
|
||||
namespace {
|
||||
const int DefaultTimeout = 5000;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(KFileItemList)
|
||||
Q_DECLARE_METATYPE(KItemRangeList)
|
||||
|
||||
|
@ -294,8 +292,9 @@ void KFileItemModelBenchmark::insertManyChildItems()
|
|||
}
|
||||
|
||||
// Bring the items into random order.
|
||||
KRandomSequence randomSequence(0);
|
||||
randomSequence.randomize(newItems);
|
||||
std::random_device rd;
|
||||
std::mt19937 g(rd());
|
||||
std::shuffle(newItems.begin(), newItems.end(), g);
|
||||
|
||||
// Measure how long it takes to insert and then remove all files.
|
||||
QBENCHMARK {
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -17,10 +17,6 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qtest.h>
|
||||
#include <qtestmouse.h>
|
||||
#include <qtestkeyboard.h>
|
||||
|
||||
#include "kitemviews/kitemlistcontainer.h"
|
||||
#include "kitemviews/kfileitemlistview.h"
|
||||
#include "kitemviews/kfileitemmodel.h"
|
||||
|
@ -32,13 +28,10 @@
|
|||
#include <KConfigGroup>
|
||||
#include <KGlobalSettings>
|
||||
|
||||
#include <QTest>
|
||||
#include <QGraphicsSceneMouseEvent>
|
||||
#include <QSignalSpy>
|
||||
|
||||
namespace {
|
||||
const int DefaultTimeout = 2000;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(KFileItemListView::ItemLayout);
|
||||
Q_DECLARE_METATYPE(Qt::Orientation);
|
||||
Q_DECLARE_METATYPE(KItemListController::SelectionBehavior);
|
||||
|
@ -104,7 +97,7 @@ void KItemListControllerTest::initTestCase()
|
|||
m_testDir->createFiles(files);
|
||||
m_model->loadDirectory(m_testDir->url());
|
||||
QSignalSpy spyDirectoryLoadingCompleted(m_model, SIGNAL(directoryLoadingCompleted()));
|
||||
QVERIFY(spyDirectoryLoadingCompleted.wait(DefaultTimeout));
|
||||
QVERIFY(spyDirectoryLoadingCompleted.wait());
|
||||
|
||||
m_container->show();
|
||||
QTest::qWaitForWindowShown(m_container);
|
||||
|
@ -567,7 +560,7 @@ void KItemListControllerTest::testMouseClickActivation()
|
|||
|
||||
if (!KGlobalSettings::singleClick()) {
|
||||
// TODO: Try to find a way to make sure that changing the global setting works.
|
||||
QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle);
|
||||
QSKIP("Failed to change the KGlobalSettings::singleClick() setting!");
|
||||
}
|
||||
|
||||
m_view->event(&mousePressEvent);
|
||||
|
@ -588,7 +581,7 @@ void KItemListControllerTest::testMouseClickActivation()
|
|||
|
||||
if (KGlobalSettings::singleClick()) {
|
||||
// TODO: Try to find a way to make sure that changing the global setting works.
|
||||
QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle);
|
||||
QSKIP("Failed to change the KGlobalSettings::singleClick() setting!");
|
||||
}
|
||||
|
||||
m_view->event(&mousePressEvent);
|
||||
|
@ -623,7 +616,7 @@ void KItemListControllerTest::testMouseClickActivation()
|
|||
|
||||
if (!KGlobalSettings::singleClick()) {
|
||||
// TODO: Try to find a way to make sure that changing the global setting works.
|
||||
QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle);
|
||||
QSKIP("Failed to change the KGlobalSettings::singleClick() setting!");
|
||||
}
|
||||
|
||||
m_view->event(&mousePressEvent);
|
||||
|
@ -652,7 +645,7 @@ void KItemListControllerTest::testMouseClickActivation()
|
|||
|
||||
if (KGlobalSettings::singleClick() != restoreKGlobalSettingsSingleClick) {
|
||||
// TODO: Try to find a way to make sure that changing the global setting works.
|
||||
QSKIP("Failed to change the KGlobalSettings::singleClick() setting!", SkipSingle);
|
||||
QSKIP("Failed to change the KGlobalSettings::singleClick() setting!");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,10 +17,11 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qtest.h>
|
||||
#include <QSignalSpy>
|
||||
#include "kitemviews/private/kitemlistkeyboardsearchmanager.h"
|
||||
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
|
||||
class KItemListKeyboardSearchManagerTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
@ -45,7 +46,7 @@ void KItemListKeyboardSearchManagerTest::init()
|
|||
|
||||
void KItemListKeyboardSearchManagerTest::testBasicKeyboardSearch()
|
||||
{
|
||||
QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString,bool)));
|
||||
QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem);
|
||||
|
||||
m_keyboardSearchManager.addKeys("f");
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
@ -70,7 +71,7 @@ void KItemListKeyboardSearchManagerTest::testAbortedKeyboardSearch()
|
|||
// to save time when running this test.
|
||||
m_keyboardSearchManager.setTimeout(100);
|
||||
|
||||
QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString,bool)));
|
||||
QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem);
|
||||
|
||||
m_keyboardSearchManager.addKeys("f");
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
@ -101,7 +102,7 @@ void KItemListKeyboardSearchManagerTest::testRepeatedKeyPress()
|
|||
// 1. the string contains the repeated key only once, and
|
||||
// 2. the bool searchFromNextItem is true.
|
||||
|
||||
QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString,bool)));
|
||||
QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem);
|
||||
|
||||
m_keyboardSearchManager.addKeys("p");
|
||||
QCOMPARE(spy.count(), 1);
|
||||
|
@ -128,7 +129,7 @@ void KItemListKeyboardSearchManagerTest::testPressShift()
|
|||
// string. Make sure that this does not reset the current search. See
|
||||
// https://bugs.kde.org/show_bug.cgi?id=321286
|
||||
|
||||
QSignalSpy spy(&m_keyboardSearchManager, SIGNAL(changeCurrentItem(QString,bool)));
|
||||
QSignalSpy spy(&m_keyboardSearchManager, &KItemListKeyboardSearchManager::changeCurrentItem);
|
||||
|
||||
// Simulate that the user enters "a_b".
|
||||
m_keyboardSearchManager.addKeys("a");
|
||||
|
|
|
@ -18,11 +18,12 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qtest.h>
|
||||
#include <QSignalSpy>
|
||||
#include "kitemviews/kitemmodelbase.h"
|
||||
#include "kitemviews/kitemlistselectionmanager.h"
|
||||
|
||||
#include <QTest>
|
||||
#include <QSignalSpy>
|
||||
|
||||
class DummyModel : public KItemModelBase
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -17,10 +17,9 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qtest.h>
|
||||
|
||||
#include "kitemviews/kitemrange.h"
|
||||
|
||||
#include <QTest>
|
||||
#include <QVector>
|
||||
|
||||
Q_DECLARE_METATYPE(QVector<int>);
|
||||
|
|
|
@ -17,10 +17,9 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qtest.h>
|
||||
|
||||
#include "kitemviews/kitemset.h"
|
||||
|
||||
#include <QTest>
|
||||
#include <QVector>
|
||||
|
||||
Q_DECLARE_METATYPE(KItemRangeList);
|
||||
|
|
|
@ -18,11 +18,11 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qtest.h>
|
||||
|
||||
#include "kitemviews/kstandarditem.h"
|
||||
#include "kitemviews/kstandarditemmodel.h"
|
||||
|
||||
#include <QTest>
|
||||
|
||||
class KStandardItemModelTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#endif
|
||||
|
||||
TestDir::TestDir(const QString& directoryPrefix) :
|
||||
KTempDir(directoryPrefix)
|
||||
QTemporaryDir(directoryPrefix)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ TestDir::~TestDir()
|
|||
|
||||
QUrl TestDir::url() const
|
||||
{
|
||||
return QUrl::fromLocalFile(name());
|
||||
return QUrl::fromLocalFile(path());
|
||||
}
|
||||
|
||||
/** The following function is taken from kdelibs/kio/tests/kiotesthelper.h, copyright (C) 2006 by David Faure */
|
||||
|
@ -85,7 +85,7 @@ void TestDir::createDir(const QString& path, const QDateTime& time)
|
|||
{
|
||||
QString absolutePath = path;
|
||||
makePathAbsoluteAndCreateParents(absolutePath);
|
||||
QDir(name()).mkdir(absolutePath);
|
||||
QDir(TestDir::path()).mkdir(absolutePath);
|
||||
|
||||
if (time.isValid()) {
|
||||
setTimeStamp(absolutePath, time);
|
||||
|
@ -94,12 +94,19 @@ void TestDir::createDir(const QString& path, const QDateTime& time)
|
|||
Q_ASSERT(QFile::exists(absolutePath));
|
||||
}
|
||||
|
||||
void TestDir::removeFiles(const QStringList& files)
|
||||
{
|
||||
foreach (const QString& path, files) {
|
||||
removeFile(path);
|
||||
}
|
||||
}
|
||||
|
||||
void TestDir::removeFile(const QString& path)
|
||||
{
|
||||
QString absolutePath = path;
|
||||
QFileInfo fileInfo(absolutePath);
|
||||
if (!fileInfo.isAbsolute()) {
|
||||
absolutePath = name() + path;
|
||||
absolutePath = TestDir::path() + QLatin1Char('/') + path;
|
||||
}
|
||||
QFile::remove(absolutePath);
|
||||
}
|
||||
|
@ -108,7 +115,7 @@ void TestDir::makePathAbsoluteAndCreateParents(QString& path)
|
|||
{
|
||||
QFileInfo fileInfo(path);
|
||||
if (!fileInfo.isAbsolute()) {
|
||||
path = name() + path;
|
||||
path = TestDir::path() + QLatin1Char('/') + path;
|
||||
fileInfo.setFile(path);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,16 +20,15 @@
|
|||
#ifndef TESTDIR_H
|
||||
#define TESTDIR_H
|
||||
|
||||
#include <KTempDir>
|
||||
#include <QUrl>
|
||||
|
||||
#include <QTemporaryDir>
|
||||
#include <QDateTime>
|
||||
|
||||
/**
|
||||
* TestDir provides a temporary directory. In addition to KTempDir, it has
|
||||
* TestDir provides a temporary directory. In addition to QTemporaryDir, it has
|
||||
* methods that create files and subdirectories inside the directory.
|
||||
*/
|
||||
class TestDir : public KTempDir
|
||||
class TestDir : public QTemporaryDir
|
||||
{
|
||||
|
||||
public:
|
||||
|
@ -50,6 +49,7 @@ public:
|
|||
void createDir(const QString& path, const QDateTime& time = QDateTime());
|
||||
|
||||
void removeFile(const QString& path);
|
||||
void removeFiles(const QStringList& files);
|
||||
|
||||
private:
|
||||
void makePathAbsoluteAndCreateParents(QString& path);
|
||||
|
|
|
@ -17,12 +17,11 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
|
||||
***************************************************************************/
|
||||
|
||||
#include <qtest.h>
|
||||
|
||||
#include "dolphin_generalsettings.h"
|
||||
#include "views/viewproperties.h"
|
||||
#include "testdir.h"
|
||||
|
||||
#include <QTest>
|
||||
#include <QDir>
|
||||
|
||||
class ViewPropertiesTest : public QObject
|
||||
|
@ -68,29 +67,27 @@ void ViewPropertiesTest::cleanup()
|
|||
*/
|
||||
void ViewPropertiesTest::testReadOnlyBehavior()
|
||||
{
|
||||
QString dotDirectoryFile = m_testDir->url().toLocalFile() + ".directory";
|
||||
QString dotDirectoryFile = m_testDir->url().toLocalFile() + "/.directory";
|
||||
QVERIFY(!QFile::exists(dotDirectoryFile));
|
||||
|
||||
ViewProperties* props = new ViewProperties(m_testDir->url());
|
||||
QScopedPointer<ViewProperties> props(new ViewProperties(m_testDir->url()));
|
||||
QVERIFY(props->isAutoSaveEnabled());
|
||||
const QByteArray sortRole = props->sortRole();
|
||||
Q_UNUSED(sortRole);
|
||||
delete props;
|
||||
props = 0;
|
||||
props.reset();
|
||||
|
||||
QVERIFY(!QFile::exists(dotDirectoryFile));
|
||||
}
|
||||
|
||||
void ViewPropertiesTest::testAutoSave()
|
||||
{
|
||||
QString dotDirectoryFile = m_testDir->url().toLocalFile() + ".directory";
|
||||
QString dotDirectoryFile = m_testDir->url().toLocalFile() + "/.directory";
|
||||
QVERIFY(!QFile::exists(dotDirectoryFile));
|
||||
|
||||
ViewProperties* props = new ViewProperties(m_testDir->url());
|
||||
QScopedPointer<ViewProperties> props(new ViewProperties(m_testDir->url()));
|
||||
QVERIFY(props->isAutoSaveEnabled());
|
||||
props->setSortRole("someNewSortRole");
|
||||
delete props;
|
||||
props = 0;
|
||||
props.reset();
|
||||
|
||||
QVERIFY(QFile::exists(dotDirectoryFile));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue