PlacesItemModelTest: use helper method to increase indexes

Instead of duplicating the logic all over the place.
This commit is contained in:
Elvis Angelaccio 2020-11-23 00:36:50 +01:00
parent 760700819c
commit a218b2ce51

View file

@ -82,6 +82,7 @@ private:
void schedulePlaceRemoval(int index); void schedulePlaceRemoval(int index);
void cancelPlaceRemoval(int index); void cancelPlaceRemoval(int index);
QMimeData *createMimeData(const QList<int> &indexes) const; QMimeData *createMimeData(const QList<int> &indexes) const;
void increaseIndexIfNeeded(int &index) const;
QTemporaryDir m_tempHomeDir; QTemporaryDir m_tempHomeDir;
}; };
@ -215,6 +216,19 @@ QMimeData *PlacesItemModelTest::createMimeData(const QList<int> &indexes) const
return mimeData; return mimeData;
} }
void PlacesItemModelTest::increaseIndexIfNeeded(int &index) const
{
if (m_hasDesktopFolder) {
index++;
}
if (m_hasDocumentsFolder) {
index++;
}
if (m_hasDownloadsFolder) {
index++;
}
}
void PlacesItemModelTest::init() void PlacesItemModelTest::init()
{ {
m_model = new PlacesItemModel(); m_model = new PlacesItemModel();
@ -289,15 +303,7 @@ void PlacesItemModelTest::testGroups()
{ {
const auto groups = m_model->groups(); const auto groups = m_model->groups();
int expectedRemoteIndex = 2; int expectedRemoteIndex = 2;
if (m_hasDesktopFolder) { increaseIndexIfNeeded(expectedRemoteIndex);
expectedRemoteIndex++;
}
if (m_hasDocumentsFolder) {
expectedRemoteIndex++;
}
if (m_hasDownloadsFolder) {
expectedRemoteIndex++;
}
QCOMPARE(groups.size(), 6); QCOMPARE(groups.size(), 6);
@ -366,15 +372,7 @@ void PlacesItemModelTest::testDeletePlace()
PlacesItemModel *model = new PlacesItemModel(); PlacesItemModel *model = new PlacesItemModel();
int tempDirIndex = 2; int tempDirIndex = 2;
if (m_hasDesktopFolder) { increaseIndexIfNeeded(tempDirIndex);
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
// create a new place // create a new place
createPlaceItem(QStringLiteral("Temporary Dir"), tempUrl, QString()); createPlaceItem(QStringLiteral("Temporary Dir"), tempUrl, QString());
@ -539,15 +537,7 @@ void PlacesItemModelTest::testHideItem()
void PlacesItemModelTest::testSystemItems() void PlacesItemModelTest::testSystemItems()
{ {
int tempDirIndex = 2; int tempDirIndex = 2;
if (m_hasDesktopFolder) { increaseIndexIfNeeded(tempDirIndex);
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
QCOMPARE(m_model->count(), m_expectedModelCount); QCOMPARE(m_model->count(), m_expectedModelCount);
for (int r = 0; r < m_model->count(); r++) { for (int r = 0; r < m_model->count(); r++) {
@ -590,15 +580,7 @@ void PlacesItemModelTest::testSystemItems()
void PlacesItemModelTest::testEditBookmark() void PlacesItemModelTest::testEditBookmark()
{ {
int tempDirIndex = 2; int tempDirIndex = 2;
if (m_hasDesktopFolder) { increaseIndexIfNeeded(tempDirIndex);
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
QScopedPointer<PlacesItemModel> other(new PlacesItemModel()); QScopedPointer<PlacesItemModel> other(new PlacesItemModel());
@ -631,15 +613,7 @@ void PlacesItemModelTest::testEditBookmark()
void PlacesItemModelTest::testEditAfterCreation() void PlacesItemModelTest::testEditAfterCreation()
{ {
int tempDirIndex = 2; int tempDirIndex = 2;
if (m_hasDesktopFolder) { increaseIndexIfNeeded(tempDirIndex);
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted); QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
@ -671,15 +645,7 @@ void PlacesItemModelTest::testEditAfterCreation()
void PlacesItemModelTest::testEditMetadata() void PlacesItemModelTest::testEditMetadata()
{ {
int tempDirIndex = 2; int tempDirIndex = 2;
if (m_hasDesktopFolder) { increaseIndexIfNeeded(tempDirIndex);
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted); QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
@ -713,15 +679,7 @@ void PlacesItemModelTest::testEditMetadata()
void PlacesItemModelTest::testRefresh() void PlacesItemModelTest::testRefresh()
{ {
int tempDirIndex = 2; int tempDirIndex = 2;
if (m_hasDesktopFolder) { increaseIndexIfNeeded(tempDirIndex);
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted); QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
@ -784,15 +742,7 @@ void PlacesItemModelTest::testIcons()
void PlacesItemModelTest::testDragAndDrop() void PlacesItemModelTest::testDragAndDrop()
{ {
int lastIndex = 1; // last index of places group int lastIndex = 1; // last index of places group
if (m_hasDesktopFolder) { increaseIndexIfNeeded(lastIndex);
lastIndex++;
}
if (m_hasDocumentsFolder) {
lastIndex++;
}
if (m_hasDownloadsFolder) {
lastIndex++;
}
QList<QVariant> args; QList<QVariant> args;
KItemRangeList range; KItemRangeList range;
@ -907,15 +857,7 @@ void PlacesItemModelTest::testDuplicatedEntries()
void PlacesItemModelTest::renameAfterCreation() void PlacesItemModelTest::renameAfterCreation()
{ {
int tempDirIndex = 2; int tempDirIndex = 2;
if (m_hasDesktopFolder) { increaseIndexIfNeeded(tempDirIndex);
tempDirIndex++;
}
if (m_hasDocumentsFolder) {
tempDirIndex++;
}
if (m_hasDownloadsFolder) {
tempDirIndex++;
}
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation)); const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QStringList urls = initialUrls(); QStringList urls = initialUrls();