Merge lp:~carlos-mazieri/ubuntu-filemanager-app/trash-operations-4 into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Carlos Jose Mazieri
Approved revision: 189
Merged at revision: 207
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/trash-operations-4
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/trash-operations-3
Diff against target: 194 lines (+177/-0)
1 file modified
src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp (+177/-0)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/trash-operations-4
Reviewer Review Type Date Requested Status
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Arto Jalkanen Approve
Review via email: mp+219946@code.launchpad.net

Commit message

some tests

Description of the change

Some automated tests for Trash operations

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 :

This is a matter of style preference, so I'm going to approve anyway, but you can consider if you want to change:

IMO it'd be more modern C++ if instead of doing

#define DIRS 3
...
#undef DIRS

It would be:

const int dirs = 3;

Then you'd get the the scoping correct automatically too without using #undef.

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

Thanks, just changed that define on revision 189.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp'
2--- src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp 2014-05-17 17:16:54 +0000
3+++ src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp 2014-06-02 17:59:16 +0000
4@@ -150,6 +150,9 @@
5 void trashDiretories();
6
7 void locationFactory();
8+ void moveOneFileToTrashAndRestore();
9+ void restoreTrashWithMultipleSources();
10+ void emptyTrash();
11
12 private:
13 bool createTempHomeTrashDir(const QString& existentDir);
14@@ -2610,6 +2613,180 @@
15 QCOMPARE(location->isRoot(), true);
16 }
17
18+
19+
20+void TestDirModel::moveOneFileToTrashAndRestore()
21+{
22+ QString orig("moveFilesTrash");
23+ m_deepDir_01 = new DeepDir(orig, 0);
24+ const int createdFiles = 4;
25+ TempFiles tempfiles;
26+ tempfiles.addSubDirLevel(orig);
27+ tempfiles.create(createdFiles);
28+
29+ m_dirModel_01->setPath(m_deepDir_01->path());
30+ QTest::qWait(TIME_TO_REFRESH_DIR);
31+ QCOMPARE(m_dirModel_01->rowCount(), createdFiles);
32+
33+ QString tempTrash("tempTrashDir");
34+ m_deepDir_02 = new DeepDir(tempTrash, 0);
35+ createTempHomeTrashDir(m_deepDir_02->path());
36+
37+ // move item to Trash
38+ m_dirModel_01->moveIndexToTrash(0);
39+ QTest::qWait(TIME_TO_REFRESH_DIR);
40+ QCOMPARE(m_dirModel_01->rowCount(), createdFiles -1);
41+
42+ //use another DirModel instance and point it to Trash
43+ m_dirModel_02->goTrash();
44+ QTest::qWait(TIME_TO_REFRESH_DIR);
45+ QCOMPARE(m_dirModel_02->rowCount(), 1);
46+
47+ // now restore from Trash
48+ m_dirModel_02->restoreIndexFromTrash(0);
49+ QTest::qWait(TIME_TO_REFRESH_DIR);
50+ QCOMPARE(m_dirModel_02->rowCount(), 0);
51+
52+ //using refresh to not depend from External File System Watcher
53+ if (m_dirModel_01->rowCount() != createdFiles)
54+ {
55+ qWarning("using refresh() external File System Watcher did not get it right");
56+ m_dirModel_01->refresh();
57+ QTest::qWait(TIME_TO_REFRESH_DIR);
58+ }
59+ QCOMPARE(m_dirModel_01->rowCount(), createdFiles);
60+}
61+
62+
63+void TestDirModel::restoreTrashWithMultipleSources()
64+{
65+ DeepDir d_01("folder_01", 0);
66+ DeepDir d_02("folder_02", 0);
67+ DeepDir d_03("folder_03", 0);
68+
69+ //create a temp trash
70+ QString tempTrash("tempTrashDir");
71+ m_deepDir_02 = new DeepDir(tempTrash, 0);
72+ createTempHomeTrashDir(m_deepDir_02->path());
73+
74+ const int dirsCounter = 3;
75+ DeepDir * dirs [dirsCounter] = {&d_01, &d_02, &d_03};
76+ int counter = 0;
77+
78+ //move items from different sources to trash
79+ for(counter = 0; counter < dirsCounter; counter++)
80+ {
81+ TempFiles files;
82+ files.addSubDirLevel(dirs[counter]->path());
83+ QString name = QString("file_from_dir%1.txt").arg(counter);
84+ files.create(name, 1);
85+ DirModel model;
86+ model.setPath(dirs[counter]->path());
87+ QTest::qWait(TIME_TO_REFRESH_DIR);
88+ QCOMPARE(model.rowCount(), 1);
89+ model.moveIndexToTrash(0);
90+ QTest::qWait(TIME_TO_REFRESH_DIR);
91+ QCOMPARE(model.rowCount(), 0);
92+ }
93+
94+ //another model points to temporary Trash
95+ connect(m_dirModel_02, SIGNAL(error(QString,QString)),
96+ this, SLOT(slotError(QString,QString)));
97+ m_dirModel_02->goTrash();
98+ QTest::qWait(TIME_TO_REFRESH_DIR);
99+ QCOMPARE(m_dirModel_02->rowCount(), dirsCounter);
100+ m_dirModel_02->restoreTrash();
101+ QTest::qWait(TIME_TO_REFRESH_DIR);
102+ QCOMPARE(m_dirModel_02->rowCount(), 0);
103+
104+ //now look into info directories from trash, check if it is empty
105+ m_dirModel_02->setPath(m_deepDir_02->path());
106+ QTest::qWait(TIME_TO_REFRESH_DIR);
107+ QCOMPARE(m_dirModel_02->rowCount(), 1);
108+ QCOMPARE(m_dirModel_02->openPath("Trash"), true);
109+ QTest::qWait(TIME_TO_REFRESH_DIR);
110+ QCOMPARE(m_dirModel_02->openPath("info"), true);
111+ QTest::qWait(TIME_TO_REFRESH_DIR);
112+ QCOMPARE(m_dirModel_02->rowCount(), 0);
113+
114+ //test it items were moved back to their sources
115+ for(counter = 0; counter < dirsCounter; counter++)
116+ {
117+ DirModel model;
118+ model.setPath(dirs[counter]->path());
119+ QTest::qWait(TIME_TO_REFRESH_DIR);
120+ QCOMPARE(model.rowCount(), 1);
121+ }
122+
123+ QCOMPARE(m_receivedErrorSignal, false);
124+}
125+
126+
127+void TestDirModel::emptyTrash()
128+{
129+ DeepDir d_01("folder_01", 0);
130+ DeepDir d_02("folder_02", 0);
131+ DeepDir d_03("folder_03", 0);
132+
133+ //create a temp trash
134+ QString tempTrash("tempTrashDir");
135+ m_deepDir_02 = new DeepDir(tempTrash, 0);
136+ createTempHomeTrashDir(m_deepDir_02->path());
137+
138+ const int dirsCounter = 3;
139+ DeepDir * dirs [dirsCounter] = {&d_01, &d_02, &d_03};
140+ int counter = 0;
141+
142+ //move items from different sources to trash
143+ for(counter = 0; counter < dirsCounter; counter++)
144+ {
145+ TempFiles files;
146+ files.addSubDirLevel(dirs[counter]->path());
147+ QString name = QString("file_from_dir%1.txt").arg(counter);
148+ files.create(name, 1);
149+ DirModel model;
150+ model.setPath(dirs[counter]->path());
151+ QTest::qWait(TIME_TO_REFRESH_DIR);
152+ QCOMPARE(model.rowCount(), 1);
153+ model.moveIndexToTrash(0);
154+ QTest::qWait(TIME_TO_REFRESH_DIR);
155+ QCOMPARE(model.rowCount(), 0);
156+ }
157+
158+ //another model points to temporary Trash
159+ connect(m_dirModel_02, SIGNAL(error(QString,QString)),
160+ this, SLOT(slotError(QString,QString)));
161+ m_dirModel_02->goTrash();
162+ QTest::qWait(TIME_TO_REFRESH_DIR);
163+ QCOMPARE(m_dirModel_02->rowCount(), dirsCounter);
164+ m_dirModel_02->emptyTrash();
165+ QTest::qWait(TIME_TO_REFRESH_DIR);
166+ QCOMPARE(m_dirModel_02->rowCount(), 0);
167+
168+ //now look into info directories from trash, check if it is empty
169+ m_dirModel_02->setPath(m_deepDir_02->path());
170+ QTest::qWait(TIME_TO_REFRESH_DIR);
171+ QCOMPARE(m_dirModel_02->rowCount(), 1);
172+ QCOMPARE(m_dirModel_02->openPath("Trash"), true);
173+ QTest::qWait(TIME_TO_REFRESH_DIR);
174+ QCOMPARE(m_dirModel_02->openPath("info"), true);
175+ QTest::qWait(TIME_TO_REFRESH_DIR);
176+ QCOMPARE(m_dirModel_02->rowCount(), 0);
177+
178+ //test if original items folder is still empty
179+ for(counter = 0; counter < dirsCounter; counter++)
180+ {
181+ DirModel model;
182+ model.setPath(dirs[counter]->path());
183+ QTest::qWait(TIME_TO_REFRESH_DIR);
184+ QCOMPARE(model.rowCount(), 0);
185+ }
186+
187+ QCOMPARE(m_receivedErrorSignal, false);
188+}
189+
190+
191+
192 int main(int argc, char *argv[])
193 {
194 QApplication app(argc, argv);

Subscribers

People subscribed via source and target branches