Merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-ui-02 into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 461
Merged at revision: 467
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-ui-02
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-ui-01
Diff against target: 593 lines (+394/-40)
4 files modified
src/plugin/placesmodel/placesmodel.cpp (+143/-34)
src/plugin/placesmodel/placesmodel.h (+23/-6)
src/plugin/test_placesmodel/placesmodeltest.cpp (+193/-0)
src/plugin/test_placesmodel/test_placesmodel.pro (+35/-0)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-ui-02
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
David Planella Pending
Review via email: mp+270335@code.launchpad.net

Commit message

    1. Added Samba Location as Network
    2. Removed default locations from setting files, it allows adding new default locations in source code
    3. Kept user added and removed locations in settings file.
    4. Created a regression test for PlacesModel.

    User can remove a default Location and then add it again.

Description of the change

Added Samba location as Network

Improved settings file content to allow add/remove places without affecting default places which are handled in the source code.

Added a regression testing for PlacesModel.

Added "/media/<user>" as watched directory because "/etc/mtab" was failing to fire changes.

To post a comment you must log in.
Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) wrote :

Several inlined comments. The one about removing all keys but the new ones introduced in this change is the one that needs attention, others are more minor.

review: Needs Fixing
Revision history for this message
Carlos Jose Mazieri (carlos-mazieri) wrote :

I agree with your comments and I will modify that according to that.

Thanks.

461. By Carlos Jose Mazieri

PlacesModel::addLocationWithoutStoring() renamed to PlacesModel::addLocationNotRemovedWithoutStoring()
Documented both PlacesModel::addLocation() and PlacesModel::addLocationNotRemovedWithoutStoring()

Revision history for this message
Ubuntu Phone Apps Jenkins Bot (ubuntu-phone-apps-jenkins-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
Arto Jalkanen (ajalkane) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/plugin/placesmodel/placesmodel.cpp'
--- src/plugin/placesmodel/placesmodel.cpp 2015-02-11 19:22:08 +0000
+++ src/plugin/placesmodel/placesmodel.cpp 2015-09-19 22:49:08 +0000
@@ -15,6 +15,7 @@
15 *15 *
16 * Author : David Planella <david.planella@ubuntu.com>16 * Author : David Planella <david.planella@ubuntu.com>
17 * Arto Jalkanen <ajalkane@gmail.com>17 * Arto Jalkanen <ajalkane@gmail.com>
18 * Carlos Mazieri <carlos.mazieri@gmail.com>
18 */19 */
1920
20#include "placesmodel.h"21#include "placesmodel.h"
@@ -25,14 +26,20 @@
25#include <QStandardPaths>26#include <QStandardPaths>
26#include <QDebug>27#include <QDebug>
2728
29namespace
30{
31 const QString userSavedLocationsName("userSavedLocations");
32 const QString userRemovedLocationsName("userRemovedLocations");
33}
34
28PlacesModel::PlacesModel(QObject *parent) :35PlacesModel::PlacesModel(QObject *parent) :
29 QAbstractListModel(parent)36 QAbstractListModel(parent)
37 , m_going_to_rescanMtab(false)
30{38{
31 m_userMountLocation = "/media/" + qgetenv("USER");39 m_userMountLocation = "/media/" + qgetenv("USER");
32 // For example /run/user/100040 // For example /run/user/1000
33 m_runtimeLocations = QStandardPaths::standardLocations(QStandardPaths::RuntimeLocation);41 m_runtimeLocations = QStandardPaths::standardLocations(QStandardPaths::RuntimeLocation);
3442
35 QStringList defaultLocations;
36 // Set the storage location to a path that works well43 // Set the storage location to a path that works well
37 // with app isolation44 // with app isolation
38 QString settingsLocation =45 QString settingsLocation =
@@ -40,29 +47,41 @@
40 + "/" + QCoreApplication::applicationName() + "/" + "places.conf";47 + "/" + QCoreApplication::applicationName() + "/" + "places.conf";
41 m_settings = new QSettings(settingsLocation, QSettings::IniFormat, this);48 m_settings = new QSettings(settingsLocation, QSettings::IniFormat, this);
4249
50 m_userSavedLocations = m_settings->value(userSavedLocationsName).toStringList();
51 m_userRemovedLocations = m_settings->value(userRemovedLocationsName).toStringList();
52
53 //remove old key "storedLocations" which is no longer used
54 QLatin1String oldStoredLocations("storedLocations");
55 if (m_settings->contains(oldStoredLocations)) {
56 m_settings->remove(oldStoredLocations);
57 }
58
43 // Prepopulate the model with the user locations59 // Prepopulate the model with the user locations
44 // for the first time it's used60 // for the first time it's used
45 defaultLocations.append(locationHome());61 addDefaultLocation(locationHome());
46 defaultLocations.append(locationDocuments());62 addDefaultLocation(locationDocuments());
47 defaultLocations.append(locationDownloads());63 addDefaultLocation(locationDownloads());
48 defaultLocations.append(locationMusic());64 addDefaultLocation(locationMusic());
49 defaultLocations.append(locationPictures());65 addDefaultLocation(locationPictures());
50 defaultLocations.append(locationVideos());66 addDefaultLocation(locationVideos());
51 // Add root also67
52 defaultLocations.append("/");68 //Network locations
5369 addDefaultLocation(locationSamba());
54 if (!m_settings->contains("storedLocations")) {70
55 m_locations.append(defaultLocations);71 //mounted locations
56 } else {72 addDefaultLocation("/");
57 m_locations = m_settings->value("storedLocations").toStringList();73 initNewUserMountsWatcher();
74 rescanMtab();
75
76 //other user saved locations
77 foreach (const QString& userLocation, m_userSavedLocations) {
78 addLocationNotRemovedWithoutStoring(userLocation);
58 }79 }
80 m_settings->sync();
5981
60 foreach (const QString &location, m_locations) {82 foreach (const QString &location, m_locations) {
61 qDebug() << "Location: " << location;83 qDebug() << "Location: " << location;
62 }84 }
63
64 initNewUserMountsWatcher();
65 rescanMtab();
66}85}
6786
68PlacesModel::~PlacesModel() {87PlacesModel::~PlacesModel() {
@@ -73,17 +92,29 @@
73PlacesModel::initNewUserMountsWatcher() {92PlacesModel::initNewUserMountsWatcher() {
74 m_newUserMountsWatcher = new QFileSystemWatcher(this);93 m_newUserMountsWatcher = new QFileSystemWatcher(this);
7594
76 qDebug() << Q_FUNC_INFO << "Start watching mtab file for new mounts" << m_mtabParser.path();95 connect(m_newUserMountsWatcher, SIGNAL(fileChanged(QString)), this, SLOT(mtabChanged(QString)));
96 connect(m_newUserMountsWatcher, SIGNAL(directoryChanged(QString)), this, SLOT(mtabChanged(QString)));
7797
78 m_newUserMountsWatcher->addPath(m_mtabParser.path());98 m_newUserMountsWatcher->addPath(m_mtabParser.path());
99 /*
100 it looks like QFileSystemWatcher does not work for /etc/mtab sometimes, lets use /media/<user> as well
101 See:
102 https://forum.qt.io/topic/8566/qfilesystemwatcher-not-working-with-etc-mtab
103 https://bugs.launchpad.net/ubuntu-filemanager-app/+bug/1444367
104 */
105 m_newUserMountsWatcher->addPath(m_userMountLocation);
79106
80 connect(m_newUserMountsWatcher, &QFileSystemWatcher::fileChanged, this, &PlacesModel::mtabChanged);107 qDebug() << Q_FUNC_INFO << "Start watching mtab file for new mounts, using:"
108 << m_newUserMountsWatcher->files() << "and" << m_newUserMountsWatcher->directories();
81}109}
82110
83void111void
84PlacesModel::mtabChanged(const QString &path) {112PlacesModel::mtabChanged(const QString &path) {
85 qDebug() << Q_FUNC_INFO << "file changed in " << path;113 qDebug() << Q_FUNC_INFO << "file changed in " << path;
86 rescanMtab();114 if (!m_going_to_rescanMtab) {
115 m_going_to_rescanMtab = true;
116 QTimer::singleShot(100, this, SLOT(rescanMtab()));
117 }
87 // Since old mtab file is replaced with new contents, must readd filesystem watcher118 // Since old mtab file is replaced with new contents, must readd filesystem watcher
88 m_newUserMountsWatcher->removePath(path);119 m_newUserMountsWatcher->removePath(path);
89 m_newUserMountsWatcher->addPath(path);120 m_newUserMountsWatcher->addPath(path);
@@ -91,6 +122,7 @@
91122
92void123void
93PlacesModel::rescanMtab() {124PlacesModel::rescanMtab() {
125 m_going_to_rescanMtab = false;
94 const QString& path = m_mtabParser.path();126 const QString& path = m_mtabParser.path();
95 qDebug() << Q_FUNC_INFO << "rescanning mtab" << path;127 qDebug() << Q_FUNC_INFO << "rescanning mtab" << path;
96128
@@ -113,7 +145,7 @@
113145
114 foreach (QString addedMount, addedMounts) {146 foreach (QString addedMount, addedMounts) {
115 qDebug() << Q_FUNC_INFO << "user mount added: " << addedMount;147 qDebug() << Q_FUNC_INFO << "user mount added: " << addedMount;
116 addLocationWithoutStoring(addedMount);148 addLocationNotRemovedWithoutStoring(addedMount);
117 emit userMountAdded(addedMount);149 emit userMountAdded(addedMount);
118 }150 }
119151
@@ -203,6 +235,11 @@
203 return standardLocation(QStandardPaths::MoviesLocation);235 return standardLocation(QStandardPaths::MoviesLocation);
204}236}
205237
238QString PlacesModel::locationSamba() const
239{
240 return QLatin1Literal("smb://");
241}
242
206int PlacesModel::rowCount(const QModelIndex &parent) const243int PlacesModel::rowCount(const QModelIndex &parent) const
207{244{
208 Q_UNUSED(parent)245 Q_UNUSED(parent)
@@ -227,10 +264,30 @@
227264
228void PlacesModel::removeItem(int indexToRemove)265void PlacesModel::removeItem(int indexToRemove)
229{266{
230 removeItemWithoutStoring(indexToRemove);267 if (indexToRemove >= 0 && indexToRemove < m_locations.count())
231268 {
232 // Remove the location permanently269 bool sync_settings = false;
233 m_settings->setValue("storedLocations", m_locations);270 const QString & location = m_locations.at(indexToRemove);
271 //check if the index belongs to a user saved location
272 int index_user_location = m_userSavedLocations.indexOf(location);
273 if (index_user_location > -1)
274 {
275 // Remove the User saved location permanently
276 m_userSavedLocations.removeAt(index_user_location);
277 m_settings->setValue(userSavedLocationsName, m_userSavedLocations);
278 sync_settings = true;
279 }
280 //save it as removed location, even a default location can be removed
281 if (!m_userRemovedLocations.contains(location)) {
282 m_userRemovedLocations.append(location);
283 m_settings->setValue(userRemovedLocationsName, m_userRemovedLocations);
284 sync_settings = true;
285 }
286 removeItemWithoutStoring(indexToRemove);
287 if (sync_settings) {
288 m_settings->sync();
289 }
290 }
234}291}
235292
236void PlacesModel::removeItemWithoutStoring(int indexToRemove)293void PlacesModel::removeItemWithoutStoring(int indexToRemove)
@@ -250,18 +307,58 @@
250 endRemoveRows();307 endRemoveRows();
251}308}
252309
310/*!
311 * \brief PlacesModel::addLocation()
312 *
313 * Adds the location permanently in the settings file.
314 *
315 * If the location has already been deleted by the user it is first removed from the removed settings \a m_userRemovedLocations.
316 *
317 * The location is saved in settings file in \a m_userSavedLocations
318 *
319 * \param location
320 */
253void PlacesModel::addLocation(const QString &location)321void PlacesModel::addLocation(const QString &location)
254{322{
255 if (addLocationWithoutStoring(location)) {323 bool sync_settings = false;
256 // Store the location permanently324 //verify it the user had deleted it before and now is inserting it again
257 m_settings->setValue("storedLocations", m_locations);325 int indexRemoved = m_userRemovedLocations.indexOf(location);
326 if (indexRemoved > -1) {
327 m_userRemovedLocations.removeAt(indexRemoved);
328 m_settings->setValue(userRemovedLocationsName, m_userRemovedLocations);
329 sync_settings = true;
330 }
331 if (addLocationNotRemovedWithoutStoring(location)) {
332 // Store the location permanently if it is not default location
333 if (!isDefaultLocation(location) && !m_userSavedLocations.contains(location))
334 {
335 m_userSavedLocations.append(location);
336 m_settings->setValue(userSavedLocationsName, m_userSavedLocations);
337 sync_settings = true;
338 }
339 }
340 if (sync_settings) {
341 m_settings->sync();
258 }342 }
259}343}
260344
261bool PlacesModel::addLocationWithoutStoring(const QString &location)345/*!
346 * \brief PlacesModel::addLocationNotRemovedWithoutStoring()
347 *
348 * Add that location only if it was not removed before by the user.
349 *
350 * When the user removes a location from Places using \ref removeItem(int index) it is stored in settings file.
351 * The user must use \ref addLocation(const QString &location) to add back an already removed location.
352 *
353 * \param location
354 *
355 * \return true when the location was added (not existent in \a m_locations nor in \a m_userRemovedLocations),
356 * otherwise false
357 */
358bool PlacesModel::addLocationNotRemovedWithoutStoring(const QString &location)
262{359{
263 // Do not allow for duplicates360 // Do not allow for duplicates and look for removed locations from settings
264 if (!m_locations.contains(location)) {361 if (!m_locations.contains(location) && !m_userRemovedLocations.contains(location)) {
265 // Tell Qt that we're going to be changing the model362 // Tell Qt that we're going to be changing the model
266 // There's no tree-parent, first new item will be at363 // There's no tree-parent, first new item will be at
267 // m_locations.count(), and the last one too364 // m_locations.count(), and the last one too
@@ -270,7 +367,6 @@
270 // Append the actual location367 // Append the actual location
271 m_locations.append(location);368 m_locations.append(location);
272369
273
274 // Tell Qt we're done with modifying the model so that370 // Tell Qt we're done with modifying the model so that
275 // it can update the UI and everything else to reflect371 // it can update the UI and everything else to reflect
276 // the new state372 // the new state
@@ -279,3 +375,16 @@
279 }375 }
280 return false;376 return false;
281}377}
378
379void PlacesModel::addDefaultLocation(const QString &location)
380{
381 // a Default location can be removed by the user
382 if (addLocationNotRemovedWithoutStoring(location)) {
383 m_defaultLocations.append(location);
384 }
385}
386
387void PlacesModel::removeItem(const QString &location)
388{
389 removeItem(m_locations.indexOf(location));
390}
282391
=== modified file 'src/plugin/placesmodel/placesmodel.h'
--- src/plugin/placesmodel/placesmodel.h 2015-01-28 20:18:07 +0000
+++ src/plugin/placesmodel/placesmodel.h 2015-09-19 22:49:08 +0000
@@ -40,6 +40,7 @@
40 Q_PROPERTY(QString locationMusic READ locationMusic CONSTANT)40 Q_PROPERTY(QString locationMusic READ locationMusic CONSTANT)
41 Q_PROPERTY(QString locationPictures READ locationPictures CONSTANT)41 Q_PROPERTY(QString locationPictures READ locationPictures CONSTANT)
42 Q_PROPERTY(QString locationVideos READ locationVideos CONSTANT)42 Q_PROPERTY(QString locationVideos READ locationVideos CONSTANT)
43 Q_PROPERTY(QString locationSamba READ locationSamba CONSTANT)
4344
44public:45public:
45 explicit PlacesModel(QObject *parent = 0);46 explicit PlacesModel(QObject *parent = 0);
@@ -50,7 +51,8 @@
50 QString locationMusic() const;51 QString locationMusic() const;
51 QString locationPictures() const;52 QString locationPictures() const;
52 QString locationVideos() const;53 QString locationVideos() const;
53 int rowCount(const QModelIndex &parent) const override;54 QString locationSamba() const;
55 int rowCount(const QModelIndex &parent = QModelIndex() ) const override;
54 QVariant data(const QModelIndex &index, int role) const override;56 QVariant data(const QModelIndex &index, int role) const override;
55 QHash<int, QByteArray> roleNames() const override;57 QHash<int, QByteArray> roleNames() const override;
5658
@@ -61,20 +63,28 @@
61public slots:63public slots:
62 void addLocation(const QString &location);64 void addLocation(const QString &location);
63 void removeItem(int indexToRemove);65 void removeItem(int indexToRemove);
64 inline bool isUserMountDirectory(const QString location) {66 inline bool isUserMountDirectory(const QString& location) {
65 return m_userMounts.contains(location);67 return m_userMounts.contains(location);
66 }68 }
69 bool isDefaultLocation(const QString& location) const {
70 return m_defaultLocations.contains(location);
71 }
72 inline int indexOfLocation(const QString& location) const {
73 return m_locations.indexOf(location);
74 }
6775
68private slots:76private slots:
69 void mtabChanged(const QString &path);77 void mtabChanged(const QString &path);
70 void rescanMtab();78 void rescanMtab();
7179
72private:80private:
73 void initNewUserMountsWatcher();81 void initNewUserMountsWatcher();
74 // Returns true if location was not known before, and false if it was known82 bool addLocationNotRemovedWithoutStoring(const QString &location);
75 bool addLocationWithoutStoring(const QString &location);
76 // Returns true if location was not known before, and false if it was known83 // Returns true if location was not known before, and false if it was known
77 void removeItemWithoutStoring(int itemToRemove);84 void removeItemWithoutStoring(int itemToRemove);
85 //just add into m_locations, does not emit any signal
86 void addDefaultLocation(const QString& location);
87 void removeItem(const QString& location);
7888
79 QMtabParser m_mtabParser;89 QMtabParser m_mtabParser;
80 QStringList m_runtimeLocations;90 QStringList m_runtimeLocations;
@@ -82,10 +92,17 @@
82 bool isMtabEntryUserMount(const QMtabEntry &entry) const;92 bool isMtabEntryUserMount(const QMtabEntry &entry) const;
83 bool isSubDirectory(const QString &dir, const QString &path) const;93 bool isSubDirectory(const QString &dir, const QString &path) const;
84 QString standardLocation(QStandardPaths::StandardLocation location) const;94 QString standardLocation(QStandardPaths::StandardLocation location) const;
85 QStringList m_locations;95 QStringList m_locations; //<! m_locations = m_defaultLocations + m_userSavedLocations - m_userRemovedLocations
96 QStringList m_defaultLocations;
97 QStringList m_userSavedLocations;
98 QStringList m_userRemovedLocations;
86 QSettings *m_settings;99 QSettings *m_settings;
87 QFileSystemWatcher *m_newUserMountsWatcher;100 QFileSystemWatcher *m_newUserMountsWatcher;
88 QSet<QString> m_userMounts;101 QSet<QString> m_userMounts;
102 bool m_going_to_rescanMtab;
103#if defined(REGRESSION_TEST_PLACES_MODEL)
104 friend class PlacesmodelTest;
105#endif
89};106};
90107
91#endif // PLACESMODEL_H108#endif // PLACESMODEL_H
92109
=== added directory 'src/plugin/test_placesmodel'
=== added file 'src/plugin/test_placesmodel/placesmodeltest.cpp'
--- src/plugin/test_placesmodel/placesmodeltest.cpp 1970-01-01 00:00:00 +0000
+++ src/plugin/test_placesmodel/placesmodeltest.cpp 2015-09-19 22:49:08 +0000
@@ -0,0 +1,193 @@
1#include "placesmodel.h"
2
3#include <QString>
4#include <QtTest>
5#include <QSettings>
6#include <QFile>
7#include <QFileInfo>
8#include <QTemporaryFile>
9#include <QTemporaryDir>
10
11
12class SaveSettings: public QTemporaryFile
13{
14public:
15 SaveSettings(QObject *parent = 0) : QTemporaryFile(parent) {}
16 bool openReadOnly()
17 {
18 return open(QFile::ReadOnly);
19 }
20};
21
22class PlacesmodelTest : public QObject
23{
24 Q_OBJECT
25
26public:
27 PlacesmodelTest();
28
29private Q_SLOTS:
30 void init();
31 void cleanup();
32 void cleanupTestCase();
33 void addUserPlace();
34 void removeUserPlace();
35 void addExistentDefaultPlace(); // should fail
36 void removeDefaultPlace();
37 void addRemovedDefaultPlace();
38private:
39 SaveSettings *m_saved_settings;
40};
41
42
43PlacesmodelTest::PlacesmodelTest() : m_saved_settings(0)
44{
45
46}
47
48void PlacesmodelTest::init()
49{
50 PlacesModel places;
51 QFileInfo saved(places.m_settings->fileName());
52 if (saved.exists())
53 {
54 QFile settings(saved.absoluteFilePath());
55 QCOMPARE(settings.open(QFile::ReadOnly), true);
56 m_saved_settings = new SaveSettings(this);
57 QCOMPARE(m_saved_settings->open(), true);
58 QByteArray settings_data = settings.readAll();
59 QCOMPARE(m_saved_settings->write(settings_data), (qint64)settings_data.size());
60 m_saved_settings->close();
61 }
62}
63
64void PlacesmodelTest::cleanupTestCase()
65{
66 if (m_saved_settings)
67 {
68 QCOMPARE(m_saved_settings->openReadOnly(), true);
69 PlacesModel places;
70 QFile saved(places.m_settings->fileName());
71 QCOMPARE(saved.open(QFile::WriteOnly | QFile::Truncate), true);
72 QByteArray saved_data = m_saved_settings->readAll();
73 QCOMPARE(saved.write(saved_data), (qint64)saved_data.size());
74 }
75}
76
77void PlacesmodelTest::cleanup()
78{
79 cleanupTestCase();
80}
81
82void PlacesmodelTest::addUserPlace()
83{
84 QTemporaryDir tempDir;
85 PlacesModel places;
86 int locations_counter = places.rowCount();
87 QCOMPARE(places.indexOfLocation(tempDir.path()), -1);
88 places.addLocation(tempDir.path());
89 QTest::qWait(50);
90 QCOMPARE(places.rowCount(), locations_counter + 1);
91 QVERIFY(places.indexOfLocation(tempDir.path()) != -1);
92
93 //now try to add it again which must fail
94 places.addLocation(tempDir.path());
95 QTest::qWait(50);
96 QCOMPARE(places.rowCount(), locations_counter + 1);
97
98 //another model instance
99 PlacesModel places2;
100 QVERIFY(places2.indexOfLocation(tempDir.path()) != -1);
101 //added item must be in m_userSavedLocations
102 QVERIFY(places2.m_userSavedLocations.indexOf(tempDir.path()) != -1);
103 QCOMPARE(places2.rowCount(), locations_counter + 1);
104}
105
106void PlacesmodelTest::removeUserPlace()
107{
108 // first add a temporary place
109 QTemporaryDir tempDir;
110 PlacesModel places;
111 int locations_counter = places.rowCount();
112 QCOMPARE(places.indexOfLocation(tempDir.path()), -1);
113 places.addLocation(tempDir.path());
114 QTest::qWait(50);
115 QCOMPARE(places.rowCount(), locations_counter + 1);
116 QVERIFY(places.indexOfLocation(tempDir.path()) != -1);
117 //then remove it
118 places.removeItem(tempDir.path());
119 QTest::qWait(50);
120 QCOMPARE(places.rowCount(), locations_counter);
121 QCOMPARE(places.indexOfLocation(tempDir.path()), -1);
122
123 //another PlacesModel instance
124 PlacesModel places2;
125 QCOMPARE(places2.rowCount(), locations_counter);
126 //item removed is not in the m_locations
127 QCOMPARE(places2.indexOfLocation(tempDir.path()), -1);
128 //item removed is in m_userRemovedLocations
129 QVERIFY(places2.m_userRemovedLocations.indexOf(tempDir.path()) != -1);
130}
131
132void PlacesmodelTest::addExistentDefaultPlace()
133{
134 PlacesModel places;
135 int home_index = places.indexOfLocation(QDir::homePath());
136 QVERIFY(home_index != -1);
137 int places_counter = places.rowCount();
138 places.addLocation(QDir::homePath());
139 QTest::qWait(50);
140 //counter must be the same which indicates nothing was added
141 QCOMPARE(places.rowCount(), places_counter);
142}
143
144void PlacesmodelTest::removeDefaultPlace()
145{
146 PlacesModel places;
147 int home_index = places.indexOfLocation(QDir::homePath());
148 QVERIFY(home_index != -1);
149 int places_counter = places.rowCount();
150 places.removeItem(home_index);
151 QTest::qWait(50);
152 QCOMPARE(places.rowCount(), places_counter - 1);
153 QCOMPARE(places.indexOfLocation(QDir::homePath()), -1);
154
155 //use another instance to check
156 PlacesModel places2;
157 QCOMPARE(places2.rowCount(), places_counter - 1);
158 QCOMPARE(places2.indexOfLocation(QDir::homePath()), -1);
159 //default place is in m_userRemovedLocations
160 QVERIFY(places2.m_userRemovedLocations.indexOf(QDir::homePath()) != -1);
161}
162
163void PlacesmodelTest::addRemovedDefaultPlace()
164{
165 //first remove a default place
166 PlacesModel places;
167 int home_index = places.indexOfLocation(QDir::homePath());
168 QVERIFY(home_index != -1);
169 int places_counter = places.rowCount();
170 places.removeItem(home_index);
171 QTest::qWait(50);
172 QCOMPARE(places.rowCount(), places_counter - 1);
173 QCOMPARE(places.indexOfLocation(QDir::homePath()), -1);
174
175 //now add the default location back
176 places.addLocation(QDir::homePath());
177 QTest::qWait(50);
178 QCOMPARE(places.rowCount(), places_counter);
179 QVERIFY(places.indexOfLocation(QDir::homePath()) != -1);
180 //it must not exist neither on m_userSavedLocations nor m_userRemovedLocations
181 QCOMPARE(places.m_userSavedLocations.indexOf(QDir::homePath()), -1);
182 QCOMPARE(places.m_userRemovedLocations.indexOf(QDir::homePath()), -1);
183
184 //check on a second instance
185 PlacesModel places2;
186 QVERIFY(places2.indexOfLocation(QDir::homePath()) != -1);
187 QCOMPARE(places2.m_userSavedLocations.indexOf(QDir::homePath()), -1);
188 QCOMPARE(places2.m_userRemovedLocations.indexOf(QDir::homePath()), -1);
189}
190
191QTEST_MAIN(PlacesmodelTest)
192
193#include "placesmodeltest.moc"
0194
=== added file 'src/plugin/test_placesmodel/test_placesmodel.pro'
--- src/plugin/test_placesmodel/test_placesmodel.pro 1970-01-01 00:00:00 +0000
+++ src/plugin/test_placesmodel/test_placesmodel.pro 2015-09-19 22:49:08 +0000
@@ -0,0 +1,35 @@
1#-------------------------------------------------
2#
3# Project created by QtCreator 2015-09-05T17:37:49
4#
5#-------------------------------------------------
6
7QT += testlib
8
9QT -= gui
10
11TARGET = tst_placesmodeltest
12CONFIG += console
13CONFIG += testcase
14CONFIG -= app_bundle
15
16TEMPLATE = app
17
18DEFINES += REGRESSION_TEST_PLACES_MODEL
19
20DEFINES += SRCDIR=\\\"$$PWD/\\\"
21
22QMAKE_CXXFLAGS += -std=c++11
23
24
25SOURCES += placesmodeltest.cpp \
26 ../placesmodel/placesmodel.cpp \
27 ../placesmodel/qmtabparser.cpp
28
29
30HEADERS += \
31 ../placesmodel/placesmodel.h \
32 ../placesmodel/qmtabparser.h
33
34
35INCLUDEPATH += ../placesmodel

Subscribers

People subscribed via source and target branches