┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/tests/placesitemmodeltest.cpp
diff options
context:
space:
mode:
authorElvis Angelaccio <[email protected]>2020-11-23 00:36:50 +0100
committerElvis Angelaccio <[email protected]>2020-11-23 00:36:50 +0100
commita218b2ce51d22a1d1ea8ab38ab5a2834ed598b55 (patch)
tree6fe460528c564efe5544f3378cf2f9d31b9d0960 /src/tests/placesitemmodeltest.cpp
parent760700819cfdcb767efe0af5a26b385f41c38aae (diff)
PlacesItemModelTest: use helper method to increase indexes
Instead of duplicating the logic all over the place.
Diffstat (limited to 'src/tests/placesitemmodeltest.cpp')
-rw-r--r--src/tests/placesitemmodeltest.cpp104
1 files changed, 23 insertions, 81 deletions
diff --git a/src/tests/placesitemmodeltest.cpp b/src/tests/placesitemmodeltest.cpp
index bac89bc61..9d2f74175 100644
--- a/src/tests/placesitemmodeltest.cpp
+++ b/src/tests/placesitemmodeltest.cpp
@@ -82,6 +82,7 @@ private:
void schedulePlaceRemoval(int index);
void cancelPlaceRemoval(int index);
QMimeData *createMimeData(const QList<int> &indexes) const;
+ void increaseIndexIfNeeded(int &index) const;
QTemporaryDir m_tempHomeDir;
};
@@ -215,6 +216,19 @@ QMimeData *PlacesItemModelTest::createMimeData(const QList<int> &indexes) const
return mimeData;
}
+void PlacesItemModelTest::increaseIndexIfNeeded(int &index) const
+{
+ if (m_hasDesktopFolder) {
+ index++;
+ }
+ if (m_hasDocumentsFolder) {
+ index++;
+ }
+ if (m_hasDownloadsFolder) {
+ index++;
+ }
+}
+
void PlacesItemModelTest::init()
{
m_model = new PlacesItemModel();
@@ -289,15 +303,7 @@ void PlacesItemModelTest::testGroups()
{
const auto groups = m_model->groups();
int expectedRemoteIndex = 2;
- if (m_hasDesktopFolder) {
- expectedRemoteIndex++;
- }
- if (m_hasDocumentsFolder) {
- expectedRemoteIndex++;
- }
- if (m_hasDownloadsFolder) {
- expectedRemoteIndex++;
- }
+ increaseIndexIfNeeded(expectedRemoteIndex);
QCOMPARE(groups.size(), 6);
@@ -366,15 +372,7 @@ void PlacesItemModelTest::testDeletePlace()
PlacesItemModel *model = new PlacesItemModel();
int tempDirIndex = 2;
- if (m_hasDesktopFolder) {
- tempDirIndex++;
- }
- if (m_hasDocumentsFolder) {
- tempDirIndex++;
- }
- if (m_hasDownloadsFolder) {
- tempDirIndex++;
- }
+ increaseIndexIfNeeded(tempDirIndex);
// create a new place
createPlaceItem(QStringLiteral("Temporary Dir"), tempUrl, QString());
@@ -539,15 +537,7 @@ void PlacesItemModelTest::testHideItem()
void PlacesItemModelTest::testSystemItems()
{
int tempDirIndex = 2;
- if (m_hasDesktopFolder) {
- tempDirIndex++;
- }
- if (m_hasDocumentsFolder) {
- tempDirIndex++;
- }
- if (m_hasDownloadsFolder) {
- tempDirIndex++;
- }
+ increaseIndexIfNeeded(tempDirIndex);
QCOMPARE(m_model->count(), m_expectedModelCount);
for (int r = 0; r < m_model->count(); r++) {
@@ -590,15 +580,7 @@ void PlacesItemModelTest::testSystemItems()
void PlacesItemModelTest::testEditBookmark()
{
int tempDirIndex = 2;
- if (m_hasDesktopFolder) {
- tempDirIndex++;
- }
- if (m_hasDocumentsFolder) {
- tempDirIndex++;
- }
- if (m_hasDownloadsFolder) {
- tempDirIndex++;
- }
+ increaseIndexIfNeeded(tempDirIndex);
QScopedPointer<PlacesItemModel> other(new PlacesItemModel());
@@ -631,15 +613,7 @@ void PlacesItemModelTest::testEditBookmark()
void PlacesItemModelTest::testEditAfterCreation()
{
int tempDirIndex = 2;
- if (m_hasDesktopFolder) {
- tempDirIndex++;
- }
- if (m_hasDocumentsFolder) {
- tempDirIndex++;
- }
- if (m_hasDownloadsFolder) {
- tempDirIndex++;
- }
+ increaseIndexIfNeeded(tempDirIndex);
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
@@ -671,15 +645,7 @@ void PlacesItemModelTest::testEditAfterCreation()
void PlacesItemModelTest::testEditMetadata()
{
int tempDirIndex = 2;
- if (m_hasDesktopFolder) {
- tempDirIndex++;
- }
- if (m_hasDocumentsFolder) {
- tempDirIndex++;
- }
- if (m_hasDownloadsFolder) {
- tempDirIndex++;
- }
+ increaseIndexIfNeeded(tempDirIndex);
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
@@ -713,15 +679,7 @@ void PlacesItemModelTest::testEditMetadata()
void PlacesItemModelTest::testRefresh()
{
int tempDirIndex = 2;
- if (m_hasDesktopFolder) {
- tempDirIndex++;
- }
- if (m_hasDocumentsFolder) {
- tempDirIndex++;
- }
- if (m_hasDownloadsFolder) {
- tempDirIndex++;
- }
+ increaseIndexIfNeeded(tempDirIndex);
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QSignalSpy itemsInsertedSpy(m_model, &PlacesItemModel::itemsInserted);
@@ -784,15 +742,7 @@ void PlacesItemModelTest::testIcons()
void PlacesItemModelTest::testDragAndDrop()
{
int lastIndex = 1; // last index of places group
- if (m_hasDesktopFolder) {
- lastIndex++;
- }
- if (m_hasDocumentsFolder) {
- lastIndex++;
- }
- if (m_hasDownloadsFolder) {
- lastIndex++;
- }
+ increaseIndexIfNeeded(lastIndex);
QList<QVariant> args;
KItemRangeList range;
@@ -907,15 +857,7 @@ void PlacesItemModelTest::testDuplicatedEntries()
void PlacesItemModelTest::renameAfterCreation()
{
int tempDirIndex = 2;
- if (m_hasDesktopFolder) {
- tempDirIndex++;
- }
- if (m_hasDocumentsFolder) {
- tempDirIndex++;
- }
- if (m_hasDownloadsFolder) {
- tempDirIndex++;
- }
+ increaseIndexIfNeeded(tempDirIndex);
const QUrl tempUrl = QUrl::fromLocalFile(QStandardPaths::writableLocation(QStandardPaths::TempLocation));
QStringList urls = initialUrls();