Changeset View
Changeset View
Standalone View
Standalone View
autotests/kfileplacesmodeltest.cpp
Show All 13 Lines | 1 | /* This file is part of the KDE project | |||
---|---|---|---|---|---|
14 | along with this program; if not, write to the Free Software | 14 | along with this program; if not, write to the Free Software | ||
15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | 15 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
16 | 02110-1301, USA. | 16 | 02110-1301, USA. | ||
17 | 17 | | |||
18 | */ | 18 | */ | ||
19 | 19 | | |||
20 | #include <QObject> | 20 | #include <QObject> | ||
21 | #include <QDBusInterface> | 21 | #include <QDBusInterface> | ||
22 | #include <QTemporaryDir> | ||||
22 | 23 | | |||
23 | #include <kbookmarkmanager.h> | 24 | #include <kbookmarkmanager.h> | ||
24 | #include <kbookmark.h> | 25 | #include <kbookmark.h> | ||
25 | #include <QDebug> | 26 | #include <QDebug> | ||
26 | #include <kfileplacesmodel.h> | 27 | #include <kfileplacesmodel.h> | ||
27 | #include <solid/device.h> | 28 | #include <solid/device.h> | ||
28 | #include <kconfig.h> | 29 | #include <kconfig.h> | ||
29 | #include <kconfiggroup.h> | 30 | #include <kconfiggroup.h> | ||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 94 | private: | |||
96 | QDBusInterface *fakeDevice(const QString &udi); | 97 | QDBusInterface *fakeDevice(const QString &udi); | ||
97 | 98 | | |||
98 | KFilePlacesModel *m_places; | 99 | KFilePlacesModel *m_places; | ||
99 | KFilePlacesModel *m_places2; // To check that they always stay in sync | 100 | KFilePlacesModel *m_places2; // To check that they always stay in sync | ||
100 | // actually supposed to work across processes, | 101 | // actually supposed to work across processes, | ||
101 | // but much harder to test | 102 | // but much harder to test | ||
102 | 103 | | |||
103 | QMap<QString, QDBusInterface *> m_interfacesMap; | 104 | QMap<QString, QDBusInterface *> m_interfacesMap; | ||
105 | QTemporaryDir m_tmpHome; | ||||
104 | }; | 106 | }; | ||
105 | 107 | | |||
106 | static QString bookmarksFile() | 108 | static QString bookmarksFile() | ||
107 | { | 109 | { | ||
108 | return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/user-places.xbel"); | 110 | return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/user-places.xbel"); | ||
109 | } | 111 | } | ||
110 | 112 | | |||
111 | void KFilePlacesModelTest::initTestCase() | 113 | void KFilePlacesModelTest::initTestCase() | ||
112 | { | 114 | { | ||
115 | QVERIFY(m_tmpHome.isValid()); | ||||
116 | qputenv("HOME", m_tmpHome.path().toUtf8()); // use a empty home dir | ||||
113 | qputenv("KDE_FORK_SLAVES", "yes"); // to avoid a runtime dependency on klauncher | 117 | qputenv("KDE_FORK_SLAVES", "yes"); // to avoid a runtime dependency on klauncher | ||
118 | | ||||
114 | QStandardPaths::setTestModeEnabled(true); | 119 | QStandardPaths::setTestModeEnabled(true); | ||
115 | 120 | | |||
116 | // Ensure we'll have a clean bookmark file to start | 121 | // Ensure we'll have a clean bookmark file to start | ||
117 | QFile::remove(bookmarksFile()); | 122 | QFile::remove(bookmarksFile()); | ||
118 | 123 | | |||
119 | // disable baloo by default | 124 | // disable baloo by default | ||
120 | KConfig config(QStringLiteral("baloofilerc")); | 125 | KConfig config(QStringLiteral("baloofilerc")); | ||
121 | KConfigGroup basicSettings = config.group("Basic Settings"); | 126 | KConfigGroup basicSettings = config.group("Basic Settings"); | ||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Line(s) | |||||
204 | 209 | | |||
205 | static const QStringList initialListOfPlaces() | 210 | static const QStringList initialListOfPlaces() | ||
206 | { | 211 | { | ||
207 | return QStringList() << QDir::homePath() << QStringLiteral(KDE_ROOT_PATH) << QStringLiteral("trash:/"); | 212 | return QStringList() << QDir::homePath() << QStringLiteral(KDE_ROOT_PATH) << QStringLiteral("trash:/"); | ||
208 | } | 213 | } | ||
209 | 214 | | |||
210 | static const QStringList initialListOfShared() | 215 | static const QStringList initialListOfShared() | ||
211 | { | 216 | { | ||
212 | return QStringList() << QStringLiteral("remote:/"); | 217 | return QStringList() << QStringLiteral("remote:/") << QStringLiteral("/media/nfs"); | ||
213 | } | 218 | } | ||
214 | 219 | | |||
215 | static const QStringList initialListOfDevices() | 220 | static const QStringList initialListOfDevices() | ||
216 | { | 221 | { | ||
217 | return QStringList() << QStringLiteral("/media/nfs") << QStringLiteral("/foreign"); | 222 | return QStringList() << QStringLiteral("/foreign"); | ||
218 | } | 223 | } | ||
219 | 224 | | |||
220 | static const QStringList initialListOfRemovableDevices() | 225 | static const QStringList initialListOfRemovableDevices() | ||
221 | { | 226 | { | ||
222 | return QStringList() << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | 227 | return QStringList() << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | ||
223 | } | 228 | } | ||
224 | 229 | | |||
225 | static const QStringList initialListOfUrls() | 230 | static const QStringList initialListOfUrls() | ||
▲ Show 20 Lines • Show All 581 Lines • ▼ Show 20 Line(s) | 805 | { | |||
807 | QStringList urls; | 812 | QStringList urls; | ||
808 | for (int row = 0; row < places_with_baloo.rowCount(); ++row) { | 813 | for (int row = 0; row < places_with_baloo.rowCount(); ++row) { | ||
809 | QModelIndex index = places_with_baloo.index(row, 0); | 814 | QModelIndex index = places_with_baloo.index(row, 0); | ||
810 | urls << places_with_baloo.url(index).toDisplayString(QUrl::PreferLocalFile); | 815 | urls << places_with_baloo.url(index).toDisplayString(QUrl::PreferLocalFile); | ||
811 | } | 816 | } | ||
812 | 817 | | |||
813 | QVERIFY(urls.contains("timeline:/today")); | 818 | QVERIFY(urls.contains("timeline:/today")); | ||
814 | QVERIFY(urls.contains("timeline:/yesterday")); | 819 | QVERIFY(urls.contains("timeline:/yesterday")); | ||
815 | QVERIFY(urls.contains("timeline:/thismonth")); | | |||
816 | QVERIFY(urls.contains("timeline:/lastmonth")); | | |||
817 | 820 | | |||
818 | QVERIFY(urls.contains("search:/documents")); | 821 | QVERIFY(urls.contains("search:/documents")); | ||
819 | QVERIFY(urls.contains("search:/images")); | 822 | QVERIFY(urls.contains("search:/images")); | ||
820 | QVERIFY(urls.contains("search:/audio")); | 823 | QVERIFY(urls.contains("search:/audio")); | ||
821 | QVERIFY(urls.contains("search:/videos")); | 824 | QVERIFY(urls.contains("search:/videos")); | ||
822 | } | 825 | } | ||
823 | 826 | | |||
824 | void KFilePlacesModelTest::testRemoteUrls_data() | 827 | void KFilePlacesModelTest::testRemoteUrls_data() | ||
825 | { | 828 | { | ||
826 | QTest::addColumn<QUrl>("url"); | 829 | QTest::addColumn<QUrl>("url"); | ||
827 | QTest::addColumn<int>("expectedRow"); | 830 | QTest::addColumn<int>("expectedRow"); | ||
828 | QTest::addColumn<QString>("expectedGroup"); | 831 | QTest::addColumn<QString>("expectedGroup"); | ||
829 | 832 | | |||
830 | QTest::newRow("Ftp") << QUrl(QStringLiteral("ftp://192.168.1.1/ftp")) << 4 << QStringLiteral("Remote"); | 833 | QTest::newRow("Ftp") << QUrl(QStringLiteral("ftp://192.168.1.1/ftp")) << 5 << QStringLiteral("Remote"); | ||
831 | QTest::newRow("Samba") << QUrl(QStringLiteral("smb://192.168.1.1/share")) << 4 << QStringLiteral("Remote"); | 834 | QTest::newRow("Samba") << QUrl(QStringLiteral("smb://192.168.1.1/share")) << 5 << QStringLiteral("Remote"); | ||
832 | QTest::newRow("Sftp") << QUrl(QStringLiteral("sftp://192.168.1.1/share")) << 4 << QStringLiteral("Remote"); | 835 | QTest::newRow("Sftp") << QUrl(QStringLiteral("sftp://192.168.1.1/share")) << 5 << QStringLiteral("Remote"); | ||
833 | QTest::newRow("Fish") << QUrl(QStringLiteral("fish://192.168.1.1/share")) << 4 << QStringLiteral("Remote"); | 836 | QTest::newRow("Fish") << QUrl(QStringLiteral("fish://192.168.1.1/share")) << 5 << QStringLiteral("Remote"); | ||
834 | QTest::newRow("Webdav") << QUrl(QStringLiteral("webdav://192.168.1.1/share")) << 4 << QStringLiteral("Remote"); | 837 | QTest::newRow("Webdav") << QUrl(QStringLiteral("webdav://192.168.1.1/share")) << 5 << QStringLiteral("Remote"); | ||
835 | } | 838 | } | ||
836 | 839 | | |||
837 | void KFilePlacesModelTest::testRemoteUrls() | 840 | void KFilePlacesModelTest::testRemoteUrls() | ||
838 | { | 841 | { | ||
839 | QFETCH(QUrl, url); | 842 | QFETCH(QUrl, url); | ||
840 | QFETCH(int, expectedRow); | 843 | QFETCH(int, expectedRow); | ||
841 | QFETCH(QString, expectedGroup); | 844 | QFETCH(QString, expectedGroup); | ||
842 | 845 | | |||
843 | QList<QVariant> args; | 846 | QList<QVariant> args; | ||
844 | QSignalSpy spy_inserted(m_places, SIGNAL(rowsInserted(QModelIndex,int,int))); | 847 | QSignalSpy spy_inserted(m_places, SIGNAL(rowsInserted(QModelIndex,int,int))); | ||
845 | 848 | | |||
846 | // insert a new network url | 849 | // insert a new network url | ||
847 | m_places->addPlace(QStringLiteral("My Shared"), url, QString(), QString(), QModelIndex()); | 850 | m_places->addPlace(QStringLiteral("My Shared"), url, QString(), QString(), QModelIndex()); | ||
848 | 851 | | |||
849 | // check if url list is correct after insertion | 852 | // check if url list is correct after insertion | ||
850 | QStringList urls; | 853 | QStringList urls; | ||
851 | urls << QDir::homePath() << QStringLiteral(KDE_ROOT_PATH) << QStringLiteral("trash:/") // places | 854 | urls << QDir::homePath() << QStringLiteral(KDE_ROOT_PATH) << QStringLiteral("trash:/") // places | ||
852 | << QStringLiteral("remote:/") << url.toString() | 855 | << QStringLiteral("remote:/") << QStringLiteral("/media/nfs") | ||
853 | << QStringLiteral("/media/nfs") << QStringLiteral("/foreign") | 856 | << url.toString() << QStringLiteral("/foreign") | ||
854 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | 857 | << QStringLiteral("/media/floppy0") << QStringLiteral("/media/XO-Y4") << QStringLiteral("/media/cdrom"); | ||
855 | CHECK_PLACES_URLS(urls); | 858 | CHECK_PLACES_URLS(urls); | ||
856 | 859 | | |||
857 | // check if the new url was inserted in the right position (end of "Remote" section) | 860 | // check if the new url was inserted in the right position (end of "Remote" section) | ||
858 | QTRY_COMPARE(spy_inserted.count(), 1); | 861 | QTRY_COMPARE(spy_inserted.count(), 1); | ||
859 | args = spy_inserted.takeFirst(); | 862 | args = spy_inserted.takeFirst(); | ||
860 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | 863 | QCOMPARE(args.at(0).toModelIndex(), QModelIndex()); | ||
861 | QCOMPARE(args.at(1).toInt(), expectedRow); | 864 | QCOMPARE(args.at(1).toInt(), expectedRow); | ||
▲ Show 20 Lines • Show All 113 Lines • ▼ Show 20 Line(s) | 976 | { | |||
975 | QTest::addColumn<QString>("expectedIconName"); | 978 | QTest::addColumn<QString>("expectedIconName"); | ||
976 | 979 | | |||
977 | // places | 980 | // places | ||
978 | QTest::newRow("Places - Home") << m_places->index(0, 0) | 981 | QTest::newRow("Places - Home") << m_places->index(0, 0) | ||
979 | << QStringLiteral("user-home"); | 982 | << QStringLiteral("user-home"); | ||
980 | QTest::newRow("Places - Root") << m_places->index(1, 0) | 983 | QTest::newRow("Places - Root") << m_places->index(1, 0) | ||
981 | << QStringLiteral("folder-red"); | 984 | << QStringLiteral("folder-red"); | ||
982 | QTest::newRow("Places - Trash") << m_places->index(2, 0) | 985 | QTest::newRow("Places - Trash") << m_places->index(2, 0) | ||
983 | << QStringLiteral("user-trash-full"); | 986 | << QStringLiteral("user-trash"); | ||
984 | QTest::newRow("Remote - Network") << m_places->index(3, 0) | 987 | QTest::newRow("Remote - Network") << m_places->index(3, 0) | ||
985 | << QStringLiteral("network-workgroup"); | 988 | << QStringLiteral("network-workgroup"); | ||
986 | QTest::newRow("Devices - Nfs") << m_places->index(4, 0) | 989 | QTest::newRow("Devices - Nfs") << m_places->index(4, 0) | ||
987 | << QStringLiteral("hwinfo"); | 990 | << QStringLiteral("hwinfo"); | ||
988 | QTest::newRow("Devices - foreign") << m_places->index(5, 0) | 991 | QTest::newRow("Devices - foreign") << m_places->index(5, 0) | ||
989 | << QStringLiteral("blockdevice"); | 992 | << QStringLiteral("blockdevice"); | ||
990 | QTest::newRow("Devices - Floppy") << m_places->index(6, 0) | 993 | QTest::newRow("Devices - Floppy") << m_places->index(6, 0) | ||
991 | << QStringLiteral("blockdevice"); | 994 | << QStringLiteral("blockdevice"); | ||
992 | QTest::newRow("Devices - cdrom") << m_places->index(7, 0) | 995 | QTest::newRow("Devices - cdrom") << m_places->index(7, 0) | ||
993 | << QStringLiteral("blockdevice"); | 996 | << QStringLiteral("blockdevice"); | ||
994 | } | 997 | } | ||
995 | 998 | | |||
996 | void KFilePlacesModelTest::testIconRole() | 999 | void KFilePlacesModelTest::testIconRole() | ||
997 | { | 1000 | { | ||
998 | QFETCH(QModelIndex, index); | 1001 | QFETCH(QModelIndex, index); | ||
999 | QFETCH(QString, expectedIconName); | 1002 | QFETCH(QString, expectedIconName); | ||
1000 | 1003 | | |||
1001 | QCOMPARE(index.data(KFilePlacesModel::IconNameRole).toString(), expectedIconName); | 1004 | QVERIFY(index.data(KFilePlacesModel::IconNameRole).toString().startsWith(expectedIconName)); | ||
1002 | } | 1005 | } | ||
1003 | 1006 | | |||
1004 | void KFilePlacesModelTest::testMoveFunction() | 1007 | void KFilePlacesModelTest::testMoveFunction() | ||
1005 | { | 1008 | { | ||
1006 | QList<QVariant> args; | 1009 | QList<QVariant> args; | ||
1007 | QStringList urls = initialListOfUrls(); | 1010 | QStringList urls = initialListOfUrls(); | ||
1008 | QSignalSpy rowsMoved(m_places, &KFilePlacesModel::rowsMoved); | 1011 | QSignalSpy rowsMoved(m_places, &KFilePlacesModel::rowsMoved); | ||
1009 | 1012 | | |||
▲ Show 20 Lines • Show All 299 Lines • Show Last 20 Lines |