Changeset View
Changeset View
Standalone View
Standalone View
autotests/kfileplacesmodeltest.cpp
Show First 20 Lines • Show All 73 Lines • ▼ Show 20 Line(s) | 57 | private Q_SLOTS: | |||
---|---|---|---|---|---|
74 | void testRefresh(); | 74 | void testRefresh(); | ||
75 | void testConvertedUrl_data(); | 75 | void testConvertedUrl_data(); | ||
76 | void testConvertedUrl(); | 76 | void testConvertedUrl(); | ||
77 | void testBookmarkObject(); | 77 | void testBookmarkObject(); | ||
78 | void testDataChangedSignal(); | 78 | void testDataChangedSignal(); | ||
79 | void testIconRole_data(); | 79 | void testIconRole_data(); | ||
80 | void testIconRole(); | 80 | void testIconRole(); | ||
81 | void testMoveFunction(); | 81 | void testMoveFunction(); | ||
82 | void testPlaceGroupHidden(); | ||||
83 | void testPlaceGroupHiddenVsPlaceChildShown(); | ||||
84 | void testPlaceGroupHiddenAndShownWithHiddenChild(); | ||||
82 | 85 | | |||
83 | private: | 86 | private: | ||
84 | QStringList placesUrls() const; | 87 | QStringList placesUrls() const; | ||
85 | QDBusInterface *fakeManager(); | 88 | QDBusInterface *fakeManager(); | ||
86 | QDBusInterface *fakeDevice(const QString &udi); | 89 | QDBusInterface *fakeDevice(const QString &udi); | ||
87 | 90 | | |||
88 | KFilePlacesModel *m_places; | 91 | KFilePlacesModel *m_places; | ||
89 | KFilePlacesModel *m_places2; // To check that they always stay in sync | 92 | KFilePlacesModel *m_places2; // To check that they always stay in sync | ||
90 | // actually supposed to work across processes, | 93 | // actually supposed to work across processes, | ||
91 | // but much harder to test | 94 | // but much harder to test | ||
92 | 95 | | |||
93 | QMap<QString, QDBusInterface *> m_interfacesMap; | 96 | QMap<QString, QDBusInterface *> m_interfacesMap; | ||
mlaurent: m_isFileIndexingEnabled | |||||
94 | }; | 97 | }; | ||
95 | 98 | | |||
96 | static QString bookmarksFile() | 99 | static QString bookmarksFile() | ||
97 | { | 100 | { | ||
98 | return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + "/user-places.xbel"; | 101 | return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/user-places.xbel"); | ||
mlaurent: QStringLiteral("/user...") | |||||
99 | } | 102 | } | ||
100 | 103 | | |||
101 | void KFilePlacesModelTest::initTestCase() | 104 | void KFilePlacesModelTest::initTestCase() | ||
102 | { | 105 | { | ||
103 | qputenv("KDE_FORK_SLAVES", "yes"); // to avoid a runtime dependency on klauncher | 106 | qputenv("KDE_FORK_SLAVES", "yes"); // to avoid a runtime dependency on klauncher | ||
104 | QStandardPaths::setTestModeEnabled(true); | 107 | QStandardPaths::setTestModeEnabled(true); | ||
105 | 108 | | |||
106 | // Ensure we'll have a clean bookmark file to start | 109 | // Ensure we'll have a clean bookmark file to start | ||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Line(s) | |||||
163 | 166 | | |||
164 | QDBusInterface *KFilePlacesModelTest::fakeManager() | 167 | QDBusInterface *KFilePlacesModelTest::fakeManager() | ||
165 | { | 168 | { | ||
166 | return fakeDevice(QStringLiteral("/org/kde/solid/fakehw")); | 169 | return fakeDevice(QStringLiteral("/org/kde/solid/fakehw")); | ||
167 | } | 170 | } | ||
168 | 171 | | |||
169 | QDBusInterface *KFilePlacesModelTest::fakeDevice(const QString &udi) | 172 | QDBusInterface *KFilePlacesModelTest::fakeDevice(const QString &udi) | ||
170 | { | 173 | { | ||
171 | if (m_interfacesMap.contains(udi)) { | 174 | QDBusInterface *interface = m_interfacesMap[udi]; | ||
172 | return m_interfacesMap[udi]; | 175 | if (interface) { | ||
176 | return interface; | ||||
173 | } | 177 | } | ||
174 | 178 | | |||
175 | QDBusInterface *iface = new QDBusInterface(QDBusConnection::sessionBus().baseService(), udi); | 179 | QDBusInterface *iface = new QDBusInterface(QDBusConnection::sessionBus().baseService(), udi); | ||
176 | m_interfacesMap[udi] = iface; | 180 | m_interfacesMap[udi] = iface; | ||
177 | 181 | | |||
178 | return iface; | 182 | return iface; | ||
179 | } | 183 | } | ||
180 | 184 | | |||
▲ Show 20 Lines • Show All 311 Lines • ▼ Show 20 Line(s) | 439 | { | |||
492 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 2, 0, QModelIndex())); | 496 | QVERIFY(m_places->dropMimeData(mimeData, Qt::MoveAction, 2, 0, QModelIndex())); | ||
493 | 497 | | |||
494 | urls.clear(); | 498 | urls.clear(); | ||
495 | urls << initialListOfPlaces() | 499 | urls << initialListOfPlaces() | ||
496 | << initialListOfShared() | 500 | << initialListOfShared() | ||
497 | << initialListOfDevices() | 501 | << initialListOfDevices() | ||
498 | << initialListOfRemovableDevices(); | 502 | << initialListOfRemovableDevices(); | ||
499 | CHECK_PLACES_URLS(urls); | 503 | CHECK_PLACES_URLS(urls); | ||
500 | QCOMPARE(spy_inserted.count(), 0); | 504 | QCOMPARE(spy_inserted.count(), 0); | ||
All those unrelated connect style changes would have been better in a separate commit. ervin: All those unrelated connect style changes would have been better in a separate commit. | |||||
501 | QCOMPARE(spy_removed.count(), 0); | 505 | QCOMPARE(spy_removed.count(), 0); | ||
502 | QCOMPARE(spy_moved.count(), 1); | 506 | QCOMPARE(spy_moved.count(), 1); | ||
503 | args = spy_moved.takeFirst(); | 507 | args = spy_moved.takeFirst(); | ||
504 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 508 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
505 | QCOMPARE(args.at(1).toInt(), 0); | 509 | QCOMPARE(args.at(1).toInt(), 0); | ||
506 | QCOMPARE(args.at(2).toInt(), 0); | 510 | QCOMPARE(args.at(2).toInt(), 0); | ||
507 | QCOMPARE(args.at(3).toModelIndex(), QModelIndex()); | 511 | QCOMPARE(args.at(3).toModelIndex(), QModelIndex()); | ||
508 | QCOMPARE(args.at(4).toInt(), 2); | 512 | QCOMPARE(args.at(4).toInt(), 2); | ||
▲ Show 20 Lines • Show All 551 Lines • ▼ Show 20 Line(s) | 992 | { | |||
1060 | QVERIFY(!m_places->movePlace(100, 20)); | 1064 | QVERIFY(!m_places->movePlace(100, 20)); | ||
1061 | QCOMPARE(rowsMoved.count(), 0); | 1065 | QCOMPARE(rowsMoved.count(), 0); | ||
1062 | 1066 | | |||
1063 | //use same start and target position | 1067 | //use same start and target position | ||
1064 | QVERIFY(!m_places->movePlace(1, 1)); | 1068 | QVERIFY(!m_places->movePlace(1, 1)); | ||
1065 | QCOMPARE(rowsMoved.count(), 0); | 1069 | QCOMPARE(rowsMoved.count(), 0); | ||
1066 | } | 1070 | } | ||
1067 | 1071 | | |||
1072 | void KFilePlacesModelTest::testPlaceGroupHidden() | ||||
1073 | { | ||||
1074 | // GIVEN | ||||
1075 | QCOMPARE(m_places->hiddenCount(), 0); | ||||
1076 | | ||||
1077 | QStringList urls; | ||||
1078 | urls << initialListOfPlaces() << initialListOfShared() << initialListOfDevices() << initialListOfRemovableDevices(); | ||||
1079 | CHECK_PLACES_URLS(urls); | ||||
1080 | QVector<QModelIndex> indexesHidden; | ||||
1081 | | ||||
1082 | // WHEN | ||||
1083 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | ||||
1084 | | ||||
1085 | // THEN | ||||
1086 | for (int row = 0; row < m_places->rowCount(); ++row) { | ||||
1087 | QModelIndex index = m_places->index(row, 0); | ||||
1088 | if (m_places->groupType(index) == KFilePlacesModel::PlacesType) { | ||||
1089 | QVERIFY(m_places->isHidden(index)); | ||||
1090 | indexesHidden << index; | ||||
1091 | } | ||||
1092 | } | ||||
1093 | QCOMPARE(indexesHidden.count(), initialListOfPlaces().size()); | ||||
1094 | QCOMPARE(m_places->hiddenCount(), indexesHidden.size()); | ||||
1095 | | ||||
1096 | // and GIVEN | ||||
1097 | QVector<QModelIndex> indexesShown; | ||||
1098 | | ||||
1099 | // WHEN | ||||
1100 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, false); | ||||
1101 | | ||||
1102 | // THEN | ||||
1103 | for (int row = 0; row < m_places->rowCount(); ++row) { | ||||
1104 | QModelIndex index = m_places->index(row, 0); | ||||
1105 | if (m_places->groupType(index) == KFilePlacesModel::PlacesType) { | ||||
1106 | QVERIFY(!m_places->isHidden(index)); | ||||
1107 | indexesShown << index; | ||||
1108 | } | ||||
1109 | } | ||||
1110 | QCOMPARE(m_places->hiddenCount(), 0); | ||||
1111 | QCOMPARE(indexesShown.count(), initialListOfPlaces().size()); | ||||
1112 | } | ||||
1113 | | ||||
1114 | void KFilePlacesModelTest::testPlaceGroupHiddenVsPlaceChildShown() | ||||
1115 | { | ||||
1116 | // GIVEN | ||||
1117 | for (int row = 0; row < m_places->rowCount(); ++row) { | ||||
1118 | QModelIndex index = m_places->index(row, 0); | ||||
1119 | QVERIFY(!m_places->isHidden(index)); | ||||
1120 | } | ||||
1121 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | ||||
1122 | | ||||
1123 | QModelIndex firstIndex = m_places->index(0,0); | ||||
1124 | const int amountOfPlaces = initialListOfPlaces().size(); | ||||
1125 | for (int row = 0; row < amountOfPlaces; ++row) { | ||||
1126 | QModelIndex index = m_places->index(row, 0); | ||||
1127 | QVERIFY(m_places->isHidden(index)); | ||||
1128 | } | ||||
1129 | // WHEN | ||||
1130 | m_places->setPlaceHidden(firstIndex, false); | ||||
1131 | | ||||
1132 | // THEN | ||||
1133 | QVERIFY(m_places->isHidden(firstIndex)); // a child cannot show against its parent state | ||||
1134 | | ||||
1135 | // leaving in a clean state | ||||
1136 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, false); | ||||
1137 | } | ||||
1138 | | ||||
1139 | void KFilePlacesModelTest::testPlaceGroupHiddenAndShownWithHiddenChild() | ||||
1140 | { | ||||
1141 | // GIVEN | ||||
1142 | QCOMPARE(m_places->hiddenCount(), 0); | ||||
1143 | | ||||
1144 | QStringList urls; | ||||
1145 | urls << initialListOfPlaces() << initialListOfShared() << initialListOfDevices() << initialListOfRemovableDevices(); | ||||
1146 | CHECK_PLACES_URLS(urls); | ||||
1147 | | ||||
1148 | QModelIndex firstIndexHidden = m_places->index(0,0); | ||||
1149 | m_places->setPlaceHidden(firstIndexHidden, true); // first place index is hidden within an hidden parent | ||||
1150 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, true); | ||||
1151 | QCOMPARE(m_places->hiddenCount(), initialListOfPlaces().size()); | ||||
1152 | | ||||
1153 | // WHEN | ||||
1154 | m_places->setGroupHidden(KFilePlacesModel::PlacesType, false); | ||||
1155 | | ||||
1156 | // THEN | ||||
1157 | QVector<QModelIndex> indexesShown; | ||||
1158 | for (int row = 0; row < m_places->rowCount(); ++row) { | ||||
1159 | QModelIndex index = m_places->index(row, 0); | ||||
1160 | if (index == firstIndexHidden) { | ||||
1161 | QVERIFY(m_places->isHidden(firstIndexHidden)); | ||||
1162 | continue; | ||||
1163 | } | ||||
1164 | if (m_places->groupType(index) == KFilePlacesModel::PlacesType) { | ||||
1165 | QVERIFY(!m_places->isHidden(index)); | ||||
1166 | indexesShown << index; | ||||
1167 | } | ||||
1168 | } | ||||
1169 | QCOMPARE(m_places->hiddenCount(), 1); | ||||
1170 | QCOMPARE(indexesShown.count(), initialListOfPlaces().size() - 1 /*first child remains hidden*/); | ||||
1171 | | ||||
1172 | // leaving in a clean state | ||||
1173 | m_places->setPlaceHidden(firstIndexHidden, false); | ||||
1174 | } | ||||
1175 | | ||||
1068 | QTEST_MAIN(KFilePlacesModelTest) | 1176 | QTEST_MAIN(KFilePlacesModelTest) | ||
1069 | 1177 | | |||
1070 | #include "kfileplacesmodeltest.moc" | 1178 | #include "kfileplacesmodeltest.moc" |
m_isFileIndexingEnabled