Merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-12-new into lp:ubuntu-filemanager-app
- samba-browsing-12-new
- Merge into trunk
Proposed by
Carlos Jose Mazieri
Status: | Merged |
---|---|
Approved by: | Arto Jalkanen |
Approved revision: | 422 |
Merged at revision: | 422 |
Proposed branch: | lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-12-new |
Merge into: | lp:ubuntu-filemanager-app |
Prerequisite: | lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-11-new |
Diff against target: |
1459 lines (+1126/-151) 8 files modified
src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient_test.pro (+22/-0) src/plugin/folderlistmodel/smb/qsambaclient/test/main_testqsambaclient.cpp (+94/-0) src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp (+701/-0) src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h (+96/-0) src/plugin/folderlistmodel/smb/qsambaclient/test/testsuite.pri (+9/-0) src/plugin/test_folderlistmodel/regression/regression_folderlilstmodel.pro (+2/-0) src/plugin/test_folderlistmodel/regression/tempfiles.cpp (+3/-3) src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp (+199/-148) |
To merge this branch: | bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-browsing-12-new |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Ubuntu Phone Apps Jenkins Bot | continuous-integration | Approve | |
Ubuntu File Manager Developers | Pending | ||
Review via email: mp+262523@code.launchpad.net |
Commit message
It replaces the samba-browsing-12 MP https:/
Description of the change
It replaces the samba-browsing-12 MP https:/
The old MP is kept for comparing purposes.
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)
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added file 'src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient_test.pro' |
2 | --- src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient_test.pro 1970-01-01 00:00:00 +0000 |
3 | +++ src/plugin/folderlistmodel/smb/qsambaclient/qsambaclient_test.pro 2015-06-20 17:33:06 +0000 |
4 | @@ -0,0 +1,22 @@ |
5 | + |
6 | +TEMPLATE = app |
7 | +CONFIG += console |
8 | +CONFIG -= app_bundle |
9 | + |
10 | +DEFINES += REGRESSION_TEST_QSAMBACLIENT |
11 | + |
12 | +include (qsambaclient.pri) |
13 | + |
14 | +include(test/testsuite.pri) |
15 | + |
16 | +include (ubuntuFM/ubuntuFM_dependencies.pri) |
17 | + |
18 | +##main |
19 | +SOURCES += $$PWD/test/main_testqsambaclient.cpp |
20 | + |
21 | +OTHER_FILES += \ |
22 | + TODO.txt |
23 | + |
24 | + |
25 | + |
26 | + |
27 | |
28 | === added directory 'src/plugin/folderlistmodel/smb/qsambaclient/test' |
29 | === added file 'src/plugin/folderlistmodel/smb/qsambaclient/test/main_testqsambaclient.cpp' |
30 | --- src/plugin/folderlistmodel/smb/qsambaclient/test/main_testqsambaclient.cpp 1970-01-01 00:00:00 +0000 |
31 | +++ src/plugin/folderlistmodel/smb/qsambaclient/test/main_testqsambaclient.cpp 2015-06-20 17:33:06 +0000 |
32 | @@ -0,0 +1,94 @@ |
33 | +/************************************************************************** |
34 | + * |
35 | + * Copyright 2014 Canonical Ltd. |
36 | + * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com> |
37 | + * |
38 | + * This program is free software; you can redistribute it and/or modify |
39 | + * it under the terms of the GNU Lesser General Public License as published by |
40 | + * the Free Software Foundation; version 3. |
41 | + * |
42 | + * This program is distributed in the hope that it will be useful, |
43 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
44 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
45 | + * GNU Lesser General Public License for more details. |
46 | + * |
47 | + * You should have received a copy of the GNU Lesser General Public License |
48 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
49 | + * |
50 | + * File: main_qsamba.cpp |
51 | + * Date: 03/12/2014 |
52 | + */ |
53 | + |
54 | +#include "testqsambasuite.h" |
55 | + |
56 | +#include <QCoreApplication> |
57 | +#include <QStringList> |
58 | +#include <QTest> |
59 | + |
60 | +int main(int argc, char *argv[]) |
61 | +{ |
62 | + QCoreApplication app(argc, argv); |
63 | + TestQSambaSuite tc; |
64 | + QStringList args = QCoreApplication::arguments(); |
65 | + QString permanentShareToCreate; |
66 | + QString permanentShareToOpen; |
67 | + bool listAll = false; |
68 | + bool listLocal = false; |
69 | + int count = args.count(); |
70 | + while (count--) |
71 | + { |
72 | + //Ubuntu Touch parameter |
73 | + if (args.at(count).startsWith(QLatin1String("--desktop_file_hint"))) |
74 | + { |
75 | + args.removeAt(count); |
76 | + } |
77 | + else |
78 | + if (args.at(count).startsWith(QLatin1String("--create")) && count > 0) |
79 | + { |
80 | + permanentShareToCreate = args.at(count+1); |
81 | + args.removeAt(count+1); |
82 | + args.removeAt(count); |
83 | + } |
84 | + else |
85 | + if (args.at(count).startsWith(QLatin1String("--open")) && count > 0) |
86 | + { |
87 | + permanentShareToOpen = args.at(count+1); |
88 | + args.removeAt(count+1); |
89 | + args.removeAt(count); |
90 | + } |
91 | + else |
92 | + if (args.at(count).startsWith(QLatin1String("--lall")) && count > 0) |
93 | + { |
94 | + listAll = true; |
95 | + args.removeAt(count); |
96 | + } |
97 | + else |
98 | + if (args.at(count).startsWith(QLatin1String("--llocal")) && count > 0) |
99 | + { |
100 | + listLocal = true; |
101 | + args.removeAt(count); |
102 | + } |
103 | + } |
104 | + |
105 | + if (!permanentShareToOpen.isEmpty()) |
106 | + { |
107 | + return tc.openPermanenteShare(permanentShareToOpen) ? 0 : 1; |
108 | + } |
109 | + if (!permanentShareToCreate.isEmpty()) |
110 | + { |
111 | + return tc.createPermanentShare(permanentShareToCreate) ? 0 : 1; |
112 | + } |
113 | + if (listAll) |
114 | + { |
115 | + return tc.listRecursive(); |
116 | + } |
117 | + if (listLocal) |
118 | + { |
119 | + return tc.listLocalhost(); |
120 | + } |
121 | + |
122 | + return QTest::qExec(&tc, args); |
123 | +} |
124 | + |
125 | + |
126 | + |
127 | |
128 | === added file 'src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp' |
129 | --- src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp 1970-01-01 00:00:00 +0000 |
130 | +++ src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp 2015-06-20 17:33:06 +0000 |
131 | @@ -0,0 +1,701 @@ |
132 | +/************************************************************************** |
133 | + * |
134 | + * Copyright 2014 Canonical Ltd. |
135 | + * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com> |
136 | + * |
137 | + * This program is free software; you can redistribute it and/or modify |
138 | + * it under the terms of the GNU Lesser General Public License as published by |
139 | + * the Free Software Foundation; version 3. |
140 | + * |
141 | + * This program is distributed in the hope that it will be useful, |
142 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
143 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
144 | + * GNU Lesser General Public License for more details. |
145 | + * |
146 | + * You should have received a copy of the GNU Lesser General Public License |
147 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
148 | + * |
149 | + * File: testqsambasuite.cpp |
150 | + * Date: 03/12/2014 |
151 | + */ |
152 | + |
153 | +#include "testqsambasuite.h" |
154 | +#include "smbusershare.h" |
155 | +#include "smbiteminfo.h" |
156 | +#include "smbplaces.h" |
157 | +#include "locationurl.h" |
158 | +#include "smbutil.h" |
159 | +#include "smblocationdiriterator.h" |
160 | +#include <sys/stat.h> |
161 | + |
162 | +#include <QTest> |
163 | +#include <QFile> |
164 | +#include <QTemporaryDir> |
165 | +#include <QFileInfo> |
166 | +#include <QDebug> |
167 | + |
168 | + |
169 | +#define RETURN_SHARE_STATUS_WHEN_FALSE(x,y) if (! (x == y) ) { \ |
170 | + qDebug() << "ERROR:" << Q_FUNC_INFO << "line:" << __LINE__ << "compare failed"; \ |
171 | + return ret; \ |
172 | + } |
173 | + |
174 | +ShareCreationStatus::ShareCreationStatus(const QString& dirNameMask) : |
175 | + status(false), |
176 | + tempDir(new QTemporaryDir(QDir::tempPath() + QDir::separator() + dirNameMask)) |
177 | +{ |
178 | + sharedDirPath = tempDir->path(); |
179 | +} |
180 | + |
181 | +ShareCreationStatus::ShareCreationStatus(const ShareCreationStatus & o) |
182 | +{ |
183 | + *this = o; |
184 | +} |
185 | + |
186 | + |
187 | +ShareCreationStatus::~ShareCreationStatus() |
188 | +{ |
189 | + if (tempDir) |
190 | + { |
191 | + delete tempDir; |
192 | + } |
193 | +} |
194 | + |
195 | +ShareCreationStatus & |
196 | +ShareCreationStatus::operator=(const ShareCreationStatus & o) |
197 | +{ |
198 | + ShareCreationStatus *other = const_cast<ShareCreationStatus*> (&o); |
199 | + *this = *other; |
200 | + return *this; |
201 | +} |
202 | + |
203 | +ShareCreationStatus & |
204 | +ShareCreationStatus::operator=(ShareCreationStatus & o) |
205 | +{ |
206 | + |
207 | + sharedDirPath = o.sharedDirPath; |
208 | + shareName = o.shareName; |
209 | + fileContent = o.fileContent; |
210 | + status = o.status; |
211 | + tempDir = o.tempDir; |
212 | + url = o.url; |
213 | + if (tempDir) |
214 | + { |
215 | + tempDir->setAutoRemove(true); |
216 | + } |
217 | + o.tempDir = 0; |
218 | + return *this; |
219 | +} |
220 | + |
221 | + |
222 | +TestQSambaSuite::TestQSambaSuite(QObject *parent) : |
223 | + QObject(parent) |
224 | + ,m_smbShares( new SmbPlaces() ) |
225 | +{ |
226 | +} |
227 | + |
228 | + |
229 | +TestQSambaSuite::~TestQSambaSuite() |
230 | +{ |
231 | + delete m_smbShares; |
232 | +} |
233 | + |
234 | + |
235 | +void TestQSambaSuite::initTestCase() |
236 | +{ |
237 | + QCOMPARE(SmbUserShare::canCreateShares(), true); |
238 | +} |
239 | + |
240 | + |
241 | +void TestQSambaSuite::cleanupTestCase() |
242 | +{ |
243 | + |
244 | +} |
245 | + |
246 | + |
247 | +void TestQSambaSuite::init() |
248 | +{ |
249 | + m_curShareName.clear(); |
250 | +} |
251 | + |
252 | +/*! |
253 | + * \brief TestQSambaSuite::cleanup() |
254 | + * |
255 | + * It is called after every test case, removes the shared indicated by m_curShareName |
256 | + * and checks if it was removed |
257 | + * |
258 | + */ |
259 | +void TestQSambaSuite::cleanup() |
260 | +{ |
261 | + if (!m_curShareName.isEmpty()) |
262 | + { |
263 | + SmbUserShare::removeShare(m_curShareName); |
264 | + SmbUserShare::UserShareFile share = SmbUserShare::search(m_curShareName); |
265 | + QCOMPARE(share.exists() , false); |
266 | + } |
267 | +} |
268 | + |
269 | +// ============== utils |
270 | + |
271 | +/*! |
272 | + * \brief TestQSambaSuite::createTempFile() creates a file \a name inside \a path |
273 | + * \param path |
274 | + * \param name |
275 | + * \param content some content or nothing |
276 | + * |
277 | + * \return fullpath of the file if it was able to create |
278 | + */ |
279 | +QString TestQSambaSuite::createTempFile(const QString &path, |
280 | + const QString &name, |
281 | + const QByteArray &content) |
282 | + |
283 | +{ |
284 | + QString ret; |
285 | + QFile f( path + QDir::separator() + name ); |
286 | + if (f.open(QFile::WriteOnly)) |
287 | + { |
288 | + if (f.write(content) == content.size()) |
289 | + { |
290 | + ret = f.fileName(); |
291 | + } |
292 | + f.close(); |
293 | + } |
294 | + return ret; |
295 | +} |
296 | + |
297 | + |
298 | +/*! |
299 | + * \brief TestQSambaSuite::existShare(0 checks is share name exist in a such list of shares |
300 | + * \param sharesFullPathList someting like ("smb://localhost/samba-devel", "smb://localhost/mac-devel") |
301 | + * \param shareName e.g. "samba-devel" |
302 | + * \return true if exists |
303 | + */ |
304 | +bool TestQSambaSuite::existsShare(const QStringList& sharesFullPathList, const QString &shareName) |
305 | +{ |
306 | + bool ret = false; |
307 | + int counter = sharesFullPathList.count(); |
308 | + while (counter--) |
309 | + { |
310 | + if (sharesFullPathList.at(counter).contains(shareName)) |
311 | + { |
312 | + ret = true; |
313 | + break; |
314 | + } |
315 | + } |
316 | + return ret; |
317 | +} |
318 | + |
319 | + |
320 | +ShareCreationStatus TestQSambaSuite::createTempShare(const QString &maskName, |
321 | + bool fullAccess, |
322 | + bool allowGuests) |
323 | +{ |
324 | + |
325 | + ShareCreationStatus ret(maskName); |
326 | + QTemporaryDir * shareDir = ret.tempDir; |
327 | + RETURN_SHARE_STATUS_WHEN_FALSE(shareDir->isValid(), true); |
328 | + |
329 | + m_curShareName = QFileInfo(shareDir->path()).fileName(); |
330 | + |
331 | + //put some content in it |
332 | + QString filename = createTempFile(shareDir->path(), "somecontent.txt", "hello Samba"); |
333 | + RETURN_SHARE_STATUS_WHEN_FALSE(filename.isEmpty(), false); |
334 | + |
335 | + ret.fileContent = filename; |
336 | + |
337 | + //save current samba shares list |
338 | + QStringList currentShares = m_smbShares->listPlacesSync(); |
339 | + |
340 | + //get the supposed share name that is going to be created |
341 | + QString shareDirName = SmbUserShare::proposedName(shareDir->path()); |
342 | + ret.shareName = shareDirName; |
343 | + |
344 | + //make sure shareDirName does not exist in the current samba share list |
345 | + RETURN_SHARE_STATUS_WHEN_FALSE(shareDirName.isEmpty(), false); |
346 | + RETURN_SHARE_STATUS_WHEN_FALSE(shareDirName, m_curShareName); |
347 | + bool exists = existsShare(currentShares,shareDirName); |
348 | + RETURN_SHARE_STATUS_WHEN_FALSE(exists, false); |
349 | + |
350 | + //create the share |
351 | + bool created = SmbUserShare::createShareForFolder(shareDir->path(), |
352 | + fullAccess ? SmbUserShare::ReadWrite : SmbUserShare::Readonly, |
353 | + allowGuests); |
354 | + RETURN_SHARE_STATUS_WHEN_FALSE(created, true); |
355 | + |
356 | + // now make sure the new share is created |
357 | + QStringList moreOneShare = m_smbShares->listPlacesSync(); |
358 | + exists = existsShare(moreOneShare, shareDirName); |
359 | + RETURN_SHARE_STATUS_WHEN_FALSE(exists, true); |
360 | + |
361 | + //everything is OK |
362 | + ret.status = true; |
363 | + |
364 | + //let the share be removed by its path instead of the name |
365 | + m_curShareName = shareDir->path(); |
366 | + ret.url = LocationUrl::SmbURL + "localhost/" + ret.shareName; |
367 | + |
368 | + //remove this |
369 | + //============================================================= |
370 | + m_curShareName.clear(); |
371 | + |
372 | + return ret; |
373 | +} |
374 | + |
375 | + |
376 | +//================ test cases================== |
377 | +void TestQSambaSuite::positive_createReadOnlyUserShare() |
378 | +{ |
379 | + //create a directory to share its content |
380 | + QTemporaryDir shareDir (QDir::tempPath() + QDir::separator() + "positive_createReadOnlyUserShare"); |
381 | + m_curShareName = QFileInfo(shareDir.path()).fileName(); |
382 | + QCOMPARE(shareDir.isValid(), true); |
383 | + |
384 | + //put some content in it |
385 | + QString filename = createTempFile(shareDir.path(), "sometext.xt", "hello Samba"); |
386 | + QCOMPARE(filename.isEmpty(), false); |
387 | + |
388 | + //save current samba shares list |
389 | + QStringList currentShares = m_smbShares->listPlacesSync(); |
390 | + qDebug() << "currentShares:" << currentShares; |
391 | + |
392 | + //get the supposed share name that is going to be created |
393 | + QString shareDirName = SmbUserShare::proposedName(shareDir.path()); |
394 | + |
395 | + //make sure shareDirName does not exist in the current samba share list |
396 | + QCOMPARE(shareDirName.isEmpty(), false); |
397 | + QCOMPARE(shareDirName, m_curShareName); |
398 | + bool exists = existsShare(currentShares,shareDirName); |
399 | + QCOMPARE(exists, false); |
400 | + |
401 | + //create the share |
402 | + bool created = SmbUserShare::createShareForFolder(shareDir.path()); |
403 | + QCOMPARE(created, true); |
404 | + |
405 | + // now make sure the new share is created |
406 | + QStringList moreOneShare = m_smbShares->listPlacesSync(); |
407 | + exists = existsShare(moreOneShare, shareDirName); |
408 | + qDebug() << "moreOneShare:" << moreOneShare; |
409 | + QCOMPARE(exists, true); |
410 | + |
411 | + //using share name |
412 | + SmbUserShare::Access readAccess = SmbUserShare::getEveryoneAccess(m_curShareName); |
413 | + bool isReadOnlyAccess = readAccess == SmbUserShare::Readonly; |
414 | + QCOMPARE(isReadOnlyAccess, true); |
415 | +} |
416 | + |
417 | + |
418 | + |
419 | +void TestQSambaSuite::positive_createFullAccessUserShare() |
420 | +{ |
421 | + //create a directory to share its content |
422 | + QTemporaryDir shareDir (QDir::tempPath() + QDir::separator() + "positive_createFullAccessUserShare"); |
423 | + m_curShareName = QFileInfo(shareDir.path()).fileName(); |
424 | + QCOMPARE(shareDir.isValid(), true); |
425 | + |
426 | + //put some content in it |
427 | + QString filename = createTempFile(shareDir.path(), "sometext.xt", "hello Samba"); |
428 | + QCOMPARE(filename.isEmpty(), false); |
429 | + |
430 | + //save current samba shares list |
431 | + QStringList currentShares = m_smbShares->listPlacesSync(); |
432 | + qDebug() << "currentShares:" << currentShares; |
433 | + |
434 | + //get the supposed share name that is going to be created |
435 | + QString shareDirName = SmbUserShare::proposedName(shareDir.path()); |
436 | + |
437 | + //make sure shareDirName does not exist in the current samba share list |
438 | + QCOMPARE(shareDirName.isEmpty(), false); |
439 | + QCOMPARE(shareDirName, m_curShareName); |
440 | + bool exists = existsShare(currentShares,shareDirName); |
441 | + QCOMPARE(exists, false); |
442 | + |
443 | + //create the share |
444 | + bool created = SmbUserShare::createShareForFolder(shareDir.path(), SmbUserShare::ReadWrite); |
445 | + QCOMPARE(created, true); |
446 | + |
447 | + // now make sure the new share is created |
448 | + QStringList moreOneShare = m_smbShares->listPlacesSync(); |
449 | + exists = existsShare(moreOneShare, shareDirName); |
450 | + qDebug() << "moreOneShare:" << moreOneShare; |
451 | + QCOMPARE(exists, true); |
452 | + |
453 | + //using dir full path |
454 | + SmbUserShare::Access readWrite = SmbUserShare::getEveryoneAccess(shareDir.path()); |
455 | + bool isReadOnlyAccess = readWrite == SmbUserShare::ReadWrite; |
456 | + QCOMPARE(isReadOnlyAccess, true); |
457 | + |
458 | + //let the share be removed by its path instead of the name |
459 | + m_curShareName = shareDir.path(); |
460 | +} |
461 | + |
462 | + |
463 | +void TestQSambaSuite::positive_itemInfoRoot() |
464 | +{ |
465 | + SmbItemInfo root(LocationUrl::SmbURL); |
466 | + QCOMPARE(root.isLocal() , false); |
467 | + QCOMPARE(root.isHost(), false); |
468 | + QCOMPARE(root.exists(), true); |
469 | + QCOMPARE(root.isRelative(),false); |
470 | + QCOMPARE(root.isAbsolute(), true); |
471 | + QCOMPARE(root.isRoot(), true); |
472 | + QCOMPARE(root.isSharedDir(), false); |
473 | + QCOMPARE(root.isHost(), false); |
474 | + QCOMPARE(root.isWorkGroup(), false); |
475 | + QCOMPARE(root.isShare(), false); |
476 | + QCOMPARE(root.absoluteFilePath(), LocationUrl::SmbURL); |
477 | + QCOMPARE(root.fileName().isEmpty(), true); |
478 | + QCOMPARE(root.absolutePath(), LocationUrl::SmbURL); |
479 | + QCOMPARE(root.sharePath().isEmpty(), true); |
480 | +} |
481 | + |
482 | + |
483 | +void TestQSambaSuite::positive_itemInfoLocalHost() |
484 | +{ |
485 | + SmbItemInfo localhost(LocationUrl::SmbURL + "localhost"); |
486 | + QCOMPARE(localhost.isLocal() , false); |
487 | + QCOMPARE(localhost.isHost(), true); |
488 | + QCOMPARE(localhost.exists(), true); |
489 | + QCOMPARE(localhost.isRelative(),false); |
490 | + QCOMPARE(localhost.isAbsolute(), true); |
491 | + QCOMPARE(localhost.isRoot(), false); |
492 | + QCOMPARE(localhost.isSharedDir(), false); |
493 | + QCOMPARE(localhost.isWorkGroup(), false); |
494 | + QCOMPARE(localhost.isShare(), false); |
495 | + QCOMPARE(localhost.path(), LocationUrl::SmbURL); |
496 | + QCOMPARE(localhost.filePath(), LocationUrl::SmbURL + "localhost"); |
497 | + QCOMPARE(localhost.absoluteFilePath(), LocationUrl::SmbURL + "localhost"); |
498 | + //for hosts sharePath() are the hostitself |
499 | + QCOMPARE(localhost.sharePath(), localhost.absoluteFilePath()); |
500 | +} |
501 | + |
502 | + |
503 | +void TestQSambaSuite::positive_itemInfoShare() |
504 | +{ |
505 | + ShareCreationStatus share(createTempShare("positive_itemInfoShare")); |
506 | + if (share.tempDir) |
507 | + { |
508 | + share.tempDir->setAutoRemove(true); |
509 | + } |
510 | + QCOMPARE(share.status, true); |
511 | + QFileInfo file(share.fileContent); |
512 | + QCOMPARE(file.exists(), true); |
513 | + |
514 | + QString urlPath("smb://localhost/" + share.shareName); |
515 | + //basic share/dir information |
516 | + SmbItemInfo dirinfo(urlPath); |
517 | + QCOMPARE(dirinfo.isLocal() , false); |
518 | + QCOMPARE(dirinfo.isHost(), false); |
519 | + QCOMPARE(dirinfo.exists(), true); |
520 | + QCOMPARE(dirinfo.isRelative(),false); |
521 | + QCOMPARE(dirinfo.isAbsolute(), true); |
522 | + QCOMPARE(dirinfo.isDir(), true); // shares also are directories |
523 | + QCOMPARE(dirinfo.isFile(), false); |
524 | + QCOMPARE(dirinfo.isReadable(), true); |
525 | + QCOMPARE(dirinfo.isWritable(), true); |
526 | + QCOMPARE(dirinfo.isExecutable(), true); |
527 | + QCOMPARE(dirinfo.isSelected(), false); |
528 | + QCOMPARE(dirinfo.isSharedDir(), false); |
529 | + QCOMPARE(dirinfo.isRoot(), false); |
530 | + QCOMPARE(dirinfo.isHost(), false); |
531 | + QCOMPARE(dirinfo.isWorkGroup(), false); |
532 | + QCOMPARE(dirinfo.isShare(), true); |
533 | + QCOMPARE(dirinfo.sharePath(), dirinfo.absoluteFilePath()); |
534 | +} |
535 | + |
536 | +void TestQSambaSuite::positive_itemInfoCommonPermissions() |
537 | +{ |
538 | + ShareCreationStatus share(createTempShare("iteminfoCommonPermission")); |
539 | + if (share.tempDir) |
540 | + { |
541 | + share.tempDir->setAutoRemove(true); |
542 | + } |
543 | + QCOMPARE(share.status, true); |
544 | + QFileInfo file(share.fileContent); |
545 | + QCOMPARE(file.exists(), true); |
546 | + |
547 | + //set a common permission to the file |
548 | + QFile::Permissions myPermissions = QFile::ReadOwner | QFile::WriteOwner | |
549 | + QFile::ReadGroup | QFile::ReadOther; |
550 | + QCOMPARE(QFile::setPermissions(share.fileContent, myPermissions), true); |
551 | + |
552 | + QString urlPath("smb://localhost/" + share.shareName); |
553 | + QString url(urlPath + QDir::separator() + file.fileName()); |
554 | + //basic file information from share |
555 | + SmbItemInfo fileinfo(url); |
556 | + QCOMPARE(fileinfo.isLocal() , false); |
557 | + QCOMPARE(fileinfo.isHost(), false); |
558 | + QCOMPARE(fileinfo.exists(), true); |
559 | + QCOMPARE(fileinfo.isRelative(),false); |
560 | + QCOMPARE(fileinfo.isAbsolute(), true); |
561 | + QCOMPARE(fileinfo.isDir(), false); |
562 | + QCOMPARE(fileinfo.isFile(), true); |
563 | + QCOMPARE(fileinfo.isReadable(), true); |
564 | + QCOMPARE(fileinfo.isWritable(), true); |
565 | + QCOMPARE(fileinfo.isExecutable(), false); |
566 | + QCOMPARE(fileinfo.isSelected(), false); |
567 | + QCOMPARE(fileinfo.isSharedDir(), false); |
568 | + QCOMPARE(fileinfo.isRoot(), false); |
569 | + QCOMPARE(fileinfo.isRemote(), true); |
570 | + QCOMPARE(fileinfo.isSymLink(), false); |
571 | + QCOMPARE(fileinfo.absolutePath(), urlPath); |
572 | + QCOMPARE(fileinfo.filePath(), url); |
573 | + QCOMPARE(fileinfo.fileName(), file.fileName()); |
574 | + QCOMPARE(fileinfo.absoluteFilePath(), url); |
575 | + QCOMPARE(fileinfo.permissions(), myPermissions); |
576 | + QCOMPARE(fileinfo.sharePath(), urlPath); |
577 | +} |
578 | + |
579 | + |
580 | +void TestQSambaSuite::negative_emptyItemInfo() |
581 | +{ |
582 | + SmbItemInfo notSmb; |
583 | + QCOMPARE(notSmb.isValid(), false); |
584 | + QCOMPARE(notSmb.exists(), false); |
585 | + QCOMPARE(notSmb.isHost(), false); |
586 | +} |
587 | + |
588 | + |
589 | +void TestQSambaSuite::negative_itemInfo() |
590 | +{ |
591 | + SmbItemInfo notSmb("test://localhost"); |
592 | + QCOMPARE(notSmb.isValid(), false); |
593 | + QCOMPARE(notSmb.exists(), false); |
594 | + |
595 | + SmbItemInfo notHost("smb://__this_host_must_not_exist_"); |
596 | + QCOMPARE(notHost.isValid(), true); |
597 | + QCOMPARE(notHost.exists(), false); |
598 | + |
599 | + SmbItemInfo notShare("smb://localhost/__this_share_must_not_exist_"); |
600 | + QCOMPARE(notShare.isValid(), true); |
601 | + QCOMPARE(notShare.exists(), false); |
602 | + |
603 | + SmbPlaces shares; |
604 | + QStringList existentShares = shares.listPlacesSync(); |
605 | + if (existentShares.count() > 0) |
606 | + { |
607 | + SmbItemInfo parent(existentShares.at(0)); |
608 | + QCOMPARE(parent.isValid(), true); |
609 | + QCOMPARE(parent.exists(), true); |
610 | + // it may not have permission to access |
611 | + if (parent.isReadable()) |
612 | + { |
613 | + QCOMPARE(parent.isShare(), true); |
614 | + SmbItemInfo dir(existentShares.at(0) + |
615 | + QDir::separator() + |
616 | + "__this_dir_must_not_exist_"); |
617 | + QCOMPARE(dir.isValid(), true); |
618 | + QCOMPARE(dir.exists(), false); |
619 | + } |
620 | + } |
621 | +} |
622 | + |
623 | +void TestQSambaSuite::negative_createShareDirDoesNotExist() |
624 | +{ |
625 | + QDir d(QDir::homePath() + "___2323_hope_this_does_not_exist_"); |
626 | + while (d.exists()) |
627 | + { |
628 | + d.setPath(d.path() + QChar('1')); |
629 | + } |
630 | + |
631 | + bool ret = SmbUserShare::createShareForFolder(d.path()); |
632 | + |
633 | + QCOMPARE(ret, false); |
634 | +} |
635 | + |
636 | + |
637 | +void TestQSambaSuite::negative_dirIterator() |
638 | +{ |
639 | + SmbLocationDirIterator iterator1("Nome"); |
640 | + QCOMPARE(iterator1.hasNext() , false); |
641 | + |
642 | + SmbLocationDirIterator iterator2("smb://localhost/_IT_MUST_NOT_EXIST_I_HOPE_"); |
643 | + QCOMPARE(iterator2.hasNext() , false); |
644 | +} |
645 | + |
646 | + |
647 | +void TestQSambaSuite::positive_dirIterator() |
648 | +{ |
649 | + ShareCreationStatus share(createTempShare("positive_dirIterator")); |
650 | + if (share.tempDir) |
651 | + { |
652 | + share.tempDir->setAutoRemove(true); |
653 | + } |
654 | + QCOMPARE(share.status, true); |
655 | + QFileInfo file(share.fileContent); |
656 | + QCOMPARE(file.exists(), true); |
657 | + |
658 | + //create a second directory inside the temporary share |
659 | + QString secondDirStr("secondDir"); |
660 | + QString secondElementPath = share.sharedDirPath + QDir::separator() + secondDirStr; |
661 | + QCOMPARE(QDir().mkpath(secondElementPath), true); |
662 | + |
663 | + //create a file inside secondElementPath |
664 | + QString secondElementContent(secondElementPath + QDir::separator() + "test.readme"); |
665 | + QFile f(secondElementContent); |
666 | + QCOMPARE(f.open(QFile::WriteOnly), true); |
667 | + f.close(); |
668 | + |
669 | + //recursive 3 items |
670 | + int counter; |
671 | + SmbLocationDirIterator tree(share.url, QDir::AllEntries, QDirIterator::Subdirectories); |
672 | + for(counter=0; tree.hasNext() ; ++counter) |
673 | + { |
674 | + tree.next(); |
675 | + } |
676 | + QCOMPARE(counter, 3); |
677 | + |
678 | + //using a mask |
679 | + QStringList nameFilter = QStringList() << "*.readme"; |
680 | + SmbLocationDirIterator onlyReadme(share.url, nameFilter,QDir::AllEntries, QDirIterator::Subdirectories); |
681 | + for(counter=0; onlyReadme.hasNext() ; ++counter) |
682 | + { |
683 | + onlyReadme.next(); |
684 | + } |
685 | + QCOMPARE(counter, 1); |
686 | + |
687 | + //2 items |
688 | + SmbLocationDirIterator lowLevelIterator(share.url); |
689 | + for(counter=0; lowLevelIterator.hasNext() ; ++counter) |
690 | + { |
691 | + lowLevelIterator.next(); |
692 | + } |
693 | + QCOMPARE(counter, 2); |
694 | + |
695 | + //2 more "." and "." |
696 | + SmbLocationDirIterator lowLevelIterator2(share.url,QDir::AllEntries | QDir::Hidden); |
697 | + for(counter=0; lowLevelIterator2.hasNext() ; ++counter) |
698 | + { |
699 | + lowLevelIterator2.next(); |
700 | + } |
701 | + QCOMPARE(counter, 4); |
702 | + |
703 | + //2 more ".." |
704 | + bool dotdot = false; |
705 | + SmbLocationDirIterator lowLevelIterator3(share.url,QDir::AllEntries | QDir::Hidden | QDir::NoDot); |
706 | + for(counter=0; lowLevelIterator3.hasNext() ; ++counter) |
707 | + { |
708 | + lowLevelIterator3.next(); |
709 | + if (lowLevelIterator3.fileName() == "..") |
710 | + { |
711 | + dotdot = true; |
712 | + } |
713 | + } |
714 | + QCOMPARE(counter, 3); |
715 | + QCOMPARE(dotdot, true); |
716 | + |
717 | + //2 more "." |
718 | + bool dot = false; |
719 | + SmbLocationDirIterator lowLevelIterator4(share.url,QDir::AllEntries | QDir::Hidden | QDir::NoDotDot); |
720 | + for(counter=0; lowLevelIterator4.hasNext() ; ++counter) |
721 | + { |
722 | + lowLevelIterator4.next(); |
723 | + if (lowLevelIterator4.fileName() == ".") |
724 | + { |
725 | + dot = true; |
726 | + } |
727 | + } |
728 | + QCOMPARE(counter, 3); |
729 | + QCOMPARE(dot, true); |
730 | + |
731 | + bool secondDir = false; |
732 | + SmbLocationDirIterator dirOnly(share.url,QDir::Dirs | QDir::NoDotAndDotDot); |
733 | + for(counter=0; dirOnly.hasNext() ; ++counter) |
734 | + { |
735 | + dirOnly.next(); |
736 | + if (dirOnly.fileName() == secondDirStr) |
737 | + { |
738 | + secondDir = true; |
739 | + } |
740 | + } |
741 | + QCOMPARE(counter, 1); |
742 | + QCOMPARE(secondDir, true); |
743 | + |
744 | + bool fileContent = false; |
745 | + SmbLocationDirIterator fileOnly(share.url,QDir::Files); |
746 | + for(counter=0; fileOnly.hasNext() ; ++counter) |
747 | + { |
748 | + fileOnly.next(); |
749 | + if (fileOnly.fileName() == QFileInfo(share.fileContent).fileName()) |
750 | + { |
751 | + fileContent = true; |
752 | + } |
753 | + } |
754 | + QCOMPARE(counter, 1); |
755 | + QCOMPARE(fileContent, true); |
756 | + |
757 | + |
758 | +} |
759 | + |
760 | + |
761 | +/*! |
762 | + * This is not a test case |
763 | + * |
764 | + * It intends to create a real user share in the local host |
765 | + */ |
766 | +bool TestQSambaSuite::createPermanentShare(const QString &path, bool fullAccess) |
767 | +{ |
768 | + SmbUserShare::Access access = fullAccess ? SmbUserShare::ReadWrite |
769 | + : SmbUserShare::Readonly; |
770 | + SmbUserShare::createShareForFolder(path, access); |
771 | + SmbUserShare::UserShareFile ret = SmbUserShare::search(path); |
772 | + return ret.exists(); |
773 | +} |
774 | + |
775 | + |
776 | +/*! |
777 | + * \brief TestQSambaSuite::openPermanenteShare() |
778 | + * |
779 | + * It is not a test case, just shows some information about an URL |
780 | + * |
781 | + * \param smb_path |
782 | + * \return |
783 | + */ |
784 | +bool TestQSambaSuite::openPermanenteShare(const QString &smb_path) |
785 | +{ |
786 | + SmbUtil smb; |
787 | + struct stat st; |
788 | + bool ok = smb.getStatInfo(smb_path, &st) != -1; |
789 | + qDebug() << st.st_mode |
790 | + << st.st_size |
791 | + << st.st_rdev |
792 | + << st.st_mtime |
793 | + << st.st_uid |
794 | + << st.st_blocks |
795 | + << st.st_ino |
796 | + ; |
797 | + return ok; |
798 | +} |
799 | + |
800 | +/*! |
801 | + * \brief TestQSambaSuite::listLocalhost() |
802 | + * |
803 | + * It is not a test case |
804 | + */ |
805 | +bool TestQSambaSuite::listLocalhost() |
806 | +{ |
807 | + QString smb_path("smb://localhost"); |
808 | + SmbLocationDirIterator listIterator(smb_path); |
809 | + QStringList shares; |
810 | + while (listIterator.hasNext()) |
811 | + { |
812 | + shares.append(listIterator.next()); |
813 | + } |
814 | + qDebug() << shares; |
815 | + return shares.count() > 0 ? true : false; |
816 | +} |
817 | + |
818 | + |
819 | +bool TestQSambaSuite::listRecursive() |
820 | +{ |
821 | + SmbUtil smb; |
822 | + QStringList all = smb.listContent(LocationUrl::SmbURL, true); |
823 | + if (all.count() == 0) |
824 | + { |
825 | + return false; |
826 | + } |
827 | + for (int counter=0 ; counter < all.count(); ++ counter) |
828 | + { |
829 | + qDebug() << all.at(counter); |
830 | + } |
831 | + return true; |
832 | +} |
833 | |
834 | === added file 'src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h' |
835 | --- src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h 1970-01-01 00:00:00 +0000 |
836 | +++ src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h 2015-06-20 17:33:06 +0000 |
837 | @@ -0,0 +1,96 @@ |
838 | +/************************************************************************** |
839 | + * |
840 | + * Copyright 2014 Canonical Ltd. |
841 | + * Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com> |
842 | + * |
843 | + * This program is free software; you can redistribute it and/or modify |
844 | + * it under the terms of the GNU Lesser General Public License as published by |
845 | + * the Free Software Foundation; version 3. |
846 | + * |
847 | + * This program is distributed in the hope that it will be useful, |
848 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
849 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
850 | + * GNU Lesser General Public License for more details. |
851 | + * |
852 | + * You should have received a copy of the GNU Lesser General Public License |
853 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
854 | + * |
855 | + * File: testqsambasuite.h |
856 | + * Date: 03/12/2014 |
857 | + */ |
858 | + |
859 | +#ifndef TESTQSAMBASUITE_H |
860 | +#define TESTQSAMBASUITE_H |
861 | + |
862 | +#include <QObject> |
863 | + |
864 | +class SmbPlaces; |
865 | +class QTemporaryDir; |
866 | + |
867 | +struct ShareCreationStatus |
868 | +{ |
869 | + ShareCreationStatus(const QString& dirNameMask); |
870 | + ShareCreationStatus(const ShareCreationStatus & o); |
871 | + ShareCreationStatus(ShareCreationStatus & o); |
872 | + ~ShareCreationStatus(); |
873 | + ShareCreationStatus &operator=(const ShareCreationStatus & o); |
874 | + ShareCreationStatus &operator=(ShareCreationStatus & o); |
875 | + QString sharedDirPath; |
876 | + QString shareName; |
877 | + QString fileContent; |
878 | + QString url; |
879 | + bool status; |
880 | + QTemporaryDir * tempDir; |
881 | +private: |
882 | + ShareCreationStatus() {} // not allowed |
883 | +}; |
884 | + |
885 | + |
886 | + |
887 | +class TestQSambaSuite : public QObject |
888 | +{ |
889 | + Q_OBJECT |
890 | +public: |
891 | + explicit TestQSambaSuite(QObject *parent = 0); |
892 | + ~TestQSambaSuite(); |
893 | + |
894 | +public: |
895 | + bool createPermanentShare(const QString& path, bool fullAccess=true); |
896 | + bool openPermanenteShare(const QString& smb_path); |
897 | + bool listLocalhost(); |
898 | + bool listRecursive(); |
899 | + bool existsShare(const QStringList& sharesFullPathList, const QString& shareName); |
900 | + ShareCreationStatus createTempShare(const QString& maskName, bool fullAccess = true, bool allowGuests = true); |
901 | + |
902 | +private Q_SLOTS: |
903 | + void initTestCase(); //before all tests |
904 | + void cleanupTestCase(); //after all tests |
905 | + void init(); //before every test |
906 | + void cleanup(); //after every test |
907 | + |
908 | +private Q_SLOTS: // test cases |
909 | + void positive_createReadOnlyUserShare(); |
910 | + void positive_createFullAccessUserShare(); |
911 | + void positive_itemInfoRoot(); |
912 | + void positive_itemInfoLocalHost(); |
913 | + void positive_itemInfoShare(); |
914 | + void positive_itemInfoCommonPermissions(); |
915 | + void positive_dirIterator(); |
916 | + void negative_itemInfo(); |
917 | + void negative_createShareDirDoesNotExist(); |
918 | + void negative_emptyItemInfo(); |
919 | + void negative_dirIterator(); |
920 | + |
921 | + |
922 | +protected: |
923 | + QString createTempFile(const QString& path, |
924 | + const QString& name, |
925 | + const QByteArray& content = QByteArray(0)); |
926 | + |
927 | +private: |
928 | + SmbPlaces *m_smbShares; |
929 | + QString m_curShareName; |
930 | + |
931 | +}; |
932 | + |
933 | +#endif // TESTQSAMBASUITE_H |
934 | |
935 | === added file 'src/plugin/folderlistmodel/smb/qsambaclient/test/testsuite.pri' |
936 | --- src/plugin/folderlistmodel/smb/qsambaclient/test/testsuite.pri 1970-01-01 00:00:00 +0000 |
937 | +++ src/plugin/folderlistmodel/smb/qsambaclient/test/testsuite.pri 2015-06-20 17:33:06 +0000 |
938 | @@ -0,0 +1,9 @@ |
939 | +QT *= testlib |
940 | +TEMPLATE = app |
941 | +CONFIG *= test |
942 | + |
943 | +## this suite can be included in any Test Case main file |
944 | +SOURCES += $$PWD/testqsambasuite.cpp |
945 | +HEADERS += $$PWD/testqsambasuite.h |
946 | + |
947 | +INCLUDEPATH += $$PWD |
948 | |
949 | === modified file 'src/plugin/test_folderlistmodel/regression/regression_folderlilstmodel.pro' |
950 | --- src/plugin/test_folderlistmodel/regression/regression_folderlilstmodel.pro 2013-10-12 19:25:17 +0000 |
951 | +++ src/plugin/test_folderlistmodel/regression/regression_folderlilstmodel.pro 2015-06-20 17:33:06 +0000 |
952 | @@ -16,6 +16,8 @@ |
953 | |
954 | include (../../folderlistmodel/folderlistmodel.pri) |
955 | |
956 | +include (../../folderlistmodel/smb/qsambaclient/test/testsuite.pri) |
957 | + |
958 | HEADERS += \ |
959 | tempfiles.h |
960 | |
961 | |
962 | === modified file 'src/plugin/test_folderlistmodel/regression/tempfiles.cpp' |
963 | --- src/plugin/test_folderlistmodel/regression/tempfiles.cpp 2013-07-25 18:07:31 +0000 |
964 | +++ src/plugin/test_folderlistmodel/regression/tempfiles.cpp 2015-06-20 17:33:06 +0000 |
965 | @@ -109,9 +109,9 @@ |
966 | QString myName; |
967 | while(counter--) |
968 | { |
969 | - myName.sprintf("%s%c%s_%02d", m_dir.toLatin1().constData(), |
970 | + myName.sprintf("%s%c%s_%02d", m_dir.toLocal8Bit().constData(), |
971 | QDir::separator().toLatin1(), |
972 | - name.toLatin1().constData(), |
973 | + name.toLocal8Bit().constData(), |
974 | counter); |
975 | QFile file(myName); |
976 | if (file.open(QFile::WriteOnly)) |
977 | @@ -199,7 +199,7 @@ |
978 | if (!root.isEmpty() && QFileInfo(root).exists()) |
979 | { |
980 | QString cmd("/bin/rm -rf " + root); |
981 | - ret = ::system(cmd.toLatin1().constData()) == 0 ; |
982 | + ret = ::system(cmd.toLocal8Bit().constData()) == 0 ; |
983 | } |
984 | return ret; |
985 | } |
986 | |
987 | === modified file 'src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp' |
988 | --- src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp 2014-12-30 18:23:15 +0000 |
989 | +++ src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp 2015-06-20 17:33:06 +0000 |
990 | @@ -9,6 +9,9 @@ |
991 | #include "locationsfactory.h" |
992 | #include "disklocation.h" |
993 | #include "qtrashutilinfo.h" |
994 | +#include "smbiteminfo.h" |
995 | +#include "testqsambasuite.h" |
996 | +#include "smbusershare.h" |
997 | |
998 | #if defined(Q_OS_UNIX) |
999 | #include <stdio.h> |
1000 | @@ -108,7 +111,6 @@ |
1001 | void modelCutManyItemsPasteIntoAnotherModel(); |
1002 | void fsActionMoveItemsForcingCopyAndThenRemove(); |
1003 | void modelCancelRemoveAction(); |
1004 | - void modelCancelRemoveSelection(); |
1005 | void modelTestFileSize(); |
1006 | void modelRemoveDirWithHiddenFilesAndLinks(); |
1007 | void modelCancelCopyAction(); |
1008 | @@ -119,6 +121,12 @@ |
1009 | void modelCutAndPaste3Times(); |
1010 | void modelCutAndPasteInTheSamePlace(); |
1011 | void modelCopyAndPasteToBackupFiles(); |
1012 | + void diskCdIntoPathRelative(); |
1013 | + void diskCdIntoPathAbsolute(); |
1014 | + void trashCdIntoPathRelative(); |
1015 | + void trashCdIntoPathAbsolute(); |
1016 | + void smbCdIntoPathRelative(); |
1017 | + void smbCdIntoPathAbsolute(); |
1018 | void fileIconProvider(); |
1019 | void getThemeIcons(); |
1020 | #ifndef DO_NOT_USE_TAG_LIB |
1021 | @@ -200,7 +208,6 @@ |
1022 | int m_extFSWatcherPathModifiedCounter; |
1023 | int m_selectedItemsCounter; |
1024 | int m_selectionMode; |
1025 | - int m_minimumProgressToCancelAction; |
1026 | |
1027 | }; |
1028 | |
1029 | @@ -347,12 +354,11 @@ |
1030 | } |
1031 | |
1032 | void TestDirModel::cancel(int index, int, int percent) |
1033 | -{ |
1034 | - Q_UNUSED(index); |
1035 | - if (percent > m_minimumProgressToCancelAction) |
1036 | +{ |
1037 | + DirModel * model = static_cast<DirModel*> (sender()); |
1038 | + if (index > 1 || percent > 1) |
1039 | { |
1040 | - DirModel * model = static_cast<DirModel*> (sender()); |
1041 | - model->cancelAction(); |
1042 | + model->cancelAction(); |
1043 | } |
1044 | } |
1045 | |
1046 | @@ -456,7 +462,6 @@ |
1047 | m_extFSWatcherPathModifiedCounter = 0; |
1048 | m_selectedItemsCounter = 0; |
1049 | m_selectionMode = -1; |
1050 | - m_minimumProgressToCancelAction = 1; |
1051 | } |
1052 | |
1053 | |
1054 | @@ -479,7 +484,6 @@ |
1055 | m_extFSWatcherPathModifiedCounter = 0; |
1056 | m_selectedItemsCounter = 0; |
1057 | m_selectionMode = -1; |
1058 | - m_minimumProgressToCancelAction = 1; |
1059 | } |
1060 | |
1061 | |
1062 | @@ -936,23 +940,6 @@ |
1063 | QCOMPARE(totalCopied, m_progressTotalItems); |
1064 | } |
1065 | |
1066 | - |
1067 | -/*! |
1068 | - * \brief TestDirModel::modelCancelRemoveAction() |
1069 | - * |
1070 | - * It tests cancel on a remove operation |
1071 | - * |
1072 | - * Two directories with a deep tree of items are created |
1073 | - * |
1074 | - * The first directory is removed and the cancel is triggered after 10 percent of the all files be removed, |
1075 | - * then the first phase of the checks are performed |
1076 | - * |
1077 | - * The second phase consists in remove the same directory after the cancel operation |
1078 | - * then a new set of checks are performed |
1079 | - * |
1080 | - * The third phase consists in remove the second directory previously created |
1081 | - * |
1082 | - */ |
1083 | void TestDirModel::modelCancelRemoveAction() |
1084 | { |
1085 | const int level = 30; |
1086 | @@ -965,131 +952,17 @@ |
1087 | QCOMPARE(m_dirModel_01->rowCount(), 1); |
1088 | connect(m_dirModel_01, SIGNAL(progress(int,int,int)), |
1089 | this, SLOT(progress(int,int,int))); |
1090 | - |
1091 | - connect(m_dirModel_01, SIGNAL(error(QString,QString)), |
1092 | - this, SLOT(slotError(QString,QString))); |
1093 | - |
1094 | - //cancel only after removing some files |
1095 | - m_minimumProgressToCancelAction = 10; |
1096 | connect(m_dirModel_01, SIGNAL(progress(int,int,int)), |
1097 | this, SLOT(cancel(int,int,int))); |
1098 | |
1099 | - |
1100 | - //create a second directory |
1101 | - m_deepDir_02 = new DeepDir("modelCancelRemoveAction2", level); |
1102 | - QCOMPARE( QFileInfo(m_deepDir_02->path()).exists(), true); |
1103 | - |
1104 | - m_dirModel_02->setPath(m_deepDir_02->path()); |
1105 | - QTest::qWait(TIME_TO_REFRESH_DIR); |
1106 | - QCOMPARE(m_dirModel_02->rowCount(), 1); |
1107 | - |
1108 | - |
1109 | - //remove from first directory |
1110 | m_dirModel_01->removeIndex(0); |
1111 | QTest::qWait(TIME_TO_PROCESS); |
1112 | QTest::qWait(5); |
1113 | |
1114 | - // sub items do not emit removed() |
1115 | - QCOMPARE(m_filesRemoved.count(), 0); |
1116 | + QCOMPARE(m_filesRemoved.count() , 0); |
1117 | QCOMPARE(m_dirModel_01->rowCount(), 1); |
1118 | QVERIFY(m_progressCurrentItem > 0); // some file were performed |
1119 | QVERIFY(m_progressPercentDone < 100); // |
1120 | - QCOMPARE(m_receivedErrorSignal, false); |
1121 | - // high level item still exists |
1122 | - QDir a(m_deepDir_01->path(), QString(), QDir::NoSort, QDir::AllEntries | QDir::NoDotAndDotDot); |
1123 | - QCOMPARE(a.exists(), true); |
1124 | - QCOMPARE((int)a.count(), 1); |
1125 | - |
1126 | - //First phase OK cancel worked |
1127 | - //SECOND PHASE now remove everything |
1128 | - disconnect(m_dirModel_01, SIGNAL(progress(int,int,int)), |
1129 | - this, SLOT(cancel(int,int,int))); |
1130 | - |
1131 | - m_dirModel_01->removeIndex(0); |
1132 | - QTest::qWait(TIME_TO_PROCESS * 2); |
1133 | - QTest::qWait(5); |
1134 | - QCOMPARE(m_progressPercentDone, 100); |
1135 | - QCOMPARE(m_filesRemoved.count(), 1); |
1136 | - QCOMPARE(m_dirModel_01->rowCount(), 0); |
1137 | - QCOMPARE(m_receivedErrorSignal, false); |
1138 | - // high level item does NOT exist anymore |
1139 | - QDir b(m_deepDir_01->path(), QString(), QDir::NoSort, QDir::AllEntries | QDir::NoDotAndDotDot); |
1140 | - QCOMPARE(b.exists(), true); |
1141 | - QCOMPARE((int)b.count(), 0); |
1142 | - |
1143 | - //THIRD PHASE |
1144 | - //now remove the second directory |
1145 | - QDir c(m_deepDir_02->path(), QString(), QDir::NoSort, QDir::AllEntries | QDir::NoDotAndDotDot); |
1146 | - QCOMPARE(c.exists(), true); |
1147 | - QCOMPARE((int)c.count(), 1); |
1148 | - m_dirModel_02->removeIndex(0); |
1149 | - QTest::qWait(TIME_TO_PROCESS * 2); |
1150 | - QDir d(m_deepDir_02->path(), QString(), QDir::NoSort, QDir::AllEntries | QDir::NoDotAndDotDot); |
1151 | - QCOMPARE(d.exists(), true); |
1152 | - QCOMPARE((int)d.count(), 0); |
1153 | - QCOMPARE(m_receivedErrorSignal, false); |
1154 | - QCOMPARE(m_dirModel_02->rowCount(), 0); |
1155 | -} |
1156 | - |
1157 | - |
1158 | -void TestDirModel::modelCancelRemoveSelection() |
1159 | -{ |
1160 | - QString tmpDir("modelCancelRemoveSelection"); |
1161 | - m_deepDir_01 = new DeepDir(tmpDir, 0); |
1162 | - QCOMPARE( QFileInfo(m_deepDir_01->path()).exists(), true); |
1163 | - TempFiles tempFiles; |
1164 | - tempFiles.addSubDirLevel(tmpDir); |
1165 | - const int createdFiles = 250; |
1166 | - tempFiles.create(createdFiles); |
1167 | - m_dirModel_01->setPath(m_deepDir_01->path()); |
1168 | - QTest::qWait(TIME_TO_REFRESH_DIR); |
1169 | - |
1170 | - QCOMPARE(m_dirModel_01->rowCount(), createdFiles); |
1171 | - connect(m_dirModel_01, SIGNAL(progress(int,int,int)), |
1172 | - this, SLOT(progress(int,int,int))); |
1173 | - |
1174 | - connect(m_dirModel_01, SIGNAL(error(QString,QString)), |
1175 | - this, SLOT(slotError(QString,QString))); |
1176 | - |
1177 | - //cancel only after removing some files |
1178 | - m_minimumProgressToCancelAction = 20; |
1179 | - connect(m_dirModel_01, SIGNAL(progress(int,int,int)), |
1180 | - this, SLOT(cancel(int,int,int))); |
1181 | - |
1182 | - |
1183 | - DirSelection *selection = m_dirModel_01->selectionObject(); |
1184 | - QVERIFY(selection != 0); |
1185 | - |
1186 | - //remove all, but cancel will be triggered |
1187 | - selection->selectAll(); |
1188 | - m_dirModel_01->removeSelection(); |
1189 | - QTest::qWait(TIME_TO_PROCESS*2); |
1190 | - |
1191 | - QVERIFY( m_dirModel_01->rowCount() > 0 ); |
1192 | - QVERIFY( m_dirModel_01->rowCount() < createdFiles); |
1193 | - QVERIFY(m_filesRemoved.count() > 0); |
1194 | - |
1195 | - int notRemoved = createdFiles - m_filesRemoved.count(); |
1196 | - QVERIFY(notRemoved > 0); |
1197 | - |
1198 | - QDir c(m_deepDir_01->path(), QString(), QDir::NoSort, QDir::AllEntries | QDir::NoDotAndDotDot); |
1199 | - QCOMPARE(c.exists(), true); |
1200 | - QCOMPARE((int)c.count(), notRemoved); |
1201 | - |
1202 | - disconnect(m_dirModel_01, SIGNAL(progress(int,int,int)), |
1203 | - this, SLOT(cancel(int,int,int))); |
1204 | - |
1205 | - //now remove everything |
1206 | - selection->clear(); |
1207 | - selection->selectAll(); |
1208 | - QCOMPARE(selection->counter(), m_dirModel_01->rowCount()); |
1209 | - m_dirModel_01->removeSelection(); |
1210 | - QTest::qWait(TIME_TO_PROCESS*2); |
1211 | - |
1212 | - QCOMPARE(m_dirModel_01->rowCount() , 0); |
1213 | - QDir d(m_deepDir_01->path(), QString(), QDir::NoSort, QDir::AllEntries | QDir::NoDotAndDotDot); |
1214 | - QCOMPARE(d.exists(), true); |
1215 | - QCOMPARE((int)d.count(), 0); |
1216 | } |
1217 | |
1218 | void TestDirModel::modelTestFileSize() |
1219 | @@ -1788,8 +1661,8 @@ |
1220 | QFileDevice::ReadOwner | QFileDevice::ExeOwner | QFileDevice::WriteOwner); |
1221 | |
1222 | QCOMPARE(ok, true); |
1223 | - qWarning("created %s", m_dirModel_01->curPathCreatedDateLocaleShort().toLatin1().constData()); |
1224 | - qWarning("modified %s", m_dirModel_01->curPathModifiedDateLocaleShort().toLatin1().constData()); |
1225 | + qWarning("created %s", m_dirModel_01->curPathCreatedDateLocaleShort().toLocal8Bit().constData()); |
1226 | + qWarning("modified %s", m_dirModel_01->curPathModifiedDateLocaleShort().toLocal8Bit().constData()); |
1227 | |
1228 | } |
1229 | |
1230 | @@ -1949,7 +1822,7 @@ |
1231 | bool ret = !md5IconsTable.contains(md5); |
1232 | qWarning("%s icon using QIcon::fromTheme() for mime type %s", |
1233 | ret ? "GOOD" : "BAD ", |
1234 | - mimetype.name().toLatin1().constData()); |
1235 | + mimetype.name().toLocal8Bit().constData()); |
1236 | md5IconsTable.insert(md5, mimesToTest.at(counter)); |
1237 | } |
1238 | } |
1239 | @@ -2539,7 +2412,7 @@ |
1240 | |
1241 | //turn stick bit on |
1242 | QString cmd("chmod +t " + trashDir); |
1243 | - QCOMPARE(system(cmd.toLatin1().constData()), 0); |
1244 | + QCOMPARE(system(cmd.toLocal8Bit().constData()), 0); |
1245 | QCOMPARE(trash.isMountPointSharedWithStickBit((m_deepDir_01->path())), true); |
1246 | |
1247 | //test validate Trash Dir() |
1248 | @@ -2580,7 +2453,7 @@ |
1249 | } |
1250 | |
1251 | //test XDG Home Trash |
1252 | - ::setenv("XDG_DATA_HOME", m_deepDir_02->path().toLatin1().constData(), true ); |
1253 | + ::setenv("XDG_DATA_HOME", m_deepDir_02->path().toLocal8Bit().constData(), true ); |
1254 | QString xdgTrashDir(trash.homeTrash()); |
1255 | QCOMPARE(trash.validate(xdgTrashDir, false), true); |
1256 | QCOMPARE(trash.homeTrash() , xdgTrashDir); |
1257 | @@ -2714,7 +2587,7 @@ |
1258 | |
1259 | //create a Trash to have |
1260 | |
1261 | - ::setenv("XDG_DATA_HOME", m_deepDir_01->path().toLatin1().constData(), true ); |
1262 | + ::setenv("XDG_DATA_HOME", m_deepDir_01->path().toLocal8Bit().constData(), true ); |
1263 | QString xdgTrashDir(trash.homeTrash()); |
1264 | QCOMPARE(trash.validate(xdgTrashDir, true), true); |
1265 | QCOMPARE(trash.homeTrash() , xdgTrashDir); |
1266 | @@ -2925,6 +2798,184 @@ |
1267 | |
1268 | |
1269 | |
1270 | +void TestDirModel::diskCdIntoPathAbsolute() |
1271 | +{ |
1272 | + QString dirName("diskCdIntoPathAbsolute"); |
1273 | + m_deepDir_01 = new DeepDir(dirName,0); |
1274 | + m_dirModel_01->setPath(m_deepDir_01->path()); |
1275 | + QTest::qWait(TIME_TO_REFRESH_DIR); |
1276 | + bool ret = m_dirModel_01->cdIntoPath("/IT_MUST_NOT_EXIST/____IT_MUST_NOT_EXIST__"); |
1277 | + QCOMPARE(ret, false); |
1278 | + ret = m_dirModel_01->cdIntoPath(QDir::homePath()); |
1279 | + QCOMPARE(ret , true); |
1280 | + QCOMPARE(m_dirModel_01->path(), QDir::homePath()); |
1281 | +} |
1282 | + |
1283 | +void TestDirModel::diskCdIntoPathRelative() |
1284 | +{ |
1285 | + QString dirName("diskCdIntoPathRelative"); |
1286 | + m_deepDir_01 = new DeepDir(dirName,1); |
1287 | + m_dirModel_01->setPath(m_deepDir_01->path()); |
1288 | + QTest::qWait(TIME_TO_REFRESH_DIR); |
1289 | + |
1290 | + QModelIndex firstIdx = m_dirModel_01->index(0, 0); |
1291 | + QString subdir = m_dirModel_01->data(firstIdx).toString(); |
1292 | + QString fullSubdir = m_deepDir_01->path() + QDir::separator() + subdir; |
1293 | + bool ret = m_dirModel_01->cdIntoPath(subdir); |
1294 | + QTest::qWait(TIME_TO_REFRESH_DIR); |
1295 | + QCOMPARE(ret, true); |
1296 | + QCOMPARE(m_dirModel_01->path(), fullSubdir); |
1297 | + ret = m_dirModel_01->cdIntoPath(".."); |
1298 | + QTest::qWait(TIME_TO_REFRESH_DIR); |
1299 | + QCOMPARE(ret, true); |
1300 | + QCOMPARE(m_dirModel_01->path(), m_deepDir_01->path()); |
1301 | +} |
1302 | + |
1303 | + |
1304 | + |
1305 | +void TestDirModel::trashCdIntoPathAbsolute() |
1306 | +{ |
1307 | + QString orig("trashCdIntoPathAbsolute"); |
1308 | + m_deepDir_01 = new DeepDir(orig, 1); |
1309 | + m_dirModel_01->setPath(m_deepDir_01->path()); |
1310 | + QTest::qWait(TIME_TO_REFRESH_DIR); |
1311 | + QCOMPARE(m_dirModel_01->rowCount() , 1); |
1312 | + |
1313 | + QString tempTrash("tempTrashDir"); |
1314 | + m_deepDir_02 = new DeepDir(tempTrash, 0); |
1315 | + createTempHomeTrashDir(m_deepDir_02->path()); |
1316 | + |
1317 | + QModelIndex firstIdx = m_dirModel_01->index(0, 0); |
1318 | + |
1319 | + QString subdirInTrash = LocationUrl::TrashRootURL + |
1320 | + m_dirModel_01->data(firstIdx).toString(); |
1321 | + |
1322 | + // move item to Trash |
1323 | + m_dirModel_01->moveIndexToTrash(0); |
1324 | + QTest::qWait(TIME_TO_REFRESH_DIR); |
1325 | + |
1326 | + |
1327 | + bool ret = m_dirModel_01->cdIntoPath(subdirInTrash); |
1328 | + QTest::qWait(TIME_TO_REFRESH_DIR); |
1329 | + QCOMPARE(ret, true); |
1330 | + QCOMPARE(m_dirModel_01->path(), subdirInTrash); |
1331 | +} |
1332 | + |
1333 | + |
1334 | +void TestDirModel::trashCdIntoPathRelative() |
1335 | +{ |
1336 | + QString orig("trashCdIntoPathRelative"); |
1337 | + m_deepDir_01 = new DeepDir(orig, 1); |
1338 | + m_dirModel_01->setPath(m_deepDir_01->path()); |
1339 | + QTest::qWait(TIME_TO_REFRESH_DIR); |
1340 | + QCOMPARE(m_dirModel_01->rowCount() , 1); |
1341 | + |
1342 | + QString tempTrash("tempTrashDir"); |
1343 | + m_deepDir_02 = new DeepDir(tempTrash, 0); |
1344 | + createTempHomeTrashDir(m_deepDir_02->path()); |
1345 | + |
1346 | + QModelIndex firstIdx = m_dirModel_01->index(0, 0); |
1347 | + QString subdir = m_dirModel_01->data(firstIdx).toString(); |
1348 | + QString subdirInTrash = LocationUrl::TrashRootURL + subdir; |
1349 | + |
1350 | + |
1351 | + // move item to Trash |
1352 | + m_dirModel_01->moveIndexToTrash(0); |
1353 | + QTest::qWait(TIME_TO_REFRESH_DIR); |
1354 | + |
1355 | + bool ret = m_dirModel_01->cdIntoPath(LocationUrl::TrashRootURL); |
1356 | + QTest::qWait(TIME_TO_REFRESH_DIR); |
1357 | + QCOMPARE(ret, true); |
1358 | + QCOMPARE(m_dirModel_01->path(), LocationUrl::TrashRootURL); |
1359 | + |
1360 | + //cd relative |
1361 | + ret = m_dirModel_01->cdIntoPath(subdir); |
1362 | + QTest::qWait(TIME_TO_REFRESH_DIR); |
1363 | + QCOMPARE(ret, true); |
1364 | + QCOMPARE(m_dirModel_01->path(), subdirInTrash); |
1365 | +} |
1366 | + |
1367 | + |
1368 | + |
1369 | +void TestDirModel::smbCdIntoPathAbsolute() |
1370 | +{ |
1371 | + SmbItemInfo smbOK(LocationUrl::SmbURL); |
1372 | + QCOMPARE(smbOK.isValid(), true); |
1373 | + QCOMPARE(smbOK.isRoot(), true); |
1374 | + QCOMPARE(smbOK.needsAuthentication(), false); |
1375 | + QCOMPARE(smbOK.urlPath(), LocationUrl::SmbURL); |
1376 | + |
1377 | + if (SmbUserShare::canCreateShares()) |
1378 | + { |
1379 | + QString shareName("smbShareCdIntoPathAbsolute"); |
1380 | + |
1381 | + TestQSambaSuite smbTest(this); |
1382 | + |
1383 | + ShareCreationStatus tmpShare(smbTest.createTempShare(shareName)); |
1384 | + if (tmpShare.tempDir) |
1385 | + { |
1386 | + tmpShare.tempDir->setAutoRemove(true); |
1387 | + } |
1388 | + QString createdDir("createdDir"); |
1389 | + QString createDirFullPath = tmpShare.sharedDirPath + QDir::separator() + createdDir; |
1390 | + bool ret = QDir().mkdir(createDirFullPath); |
1391 | + QCOMPARE(ret , true); |
1392 | + QString absUrl = LocationUrl::SmbURL + "localhost" + |
1393 | + QDir::separator() + tmpShare.shareName + |
1394 | + QDir::separator() + createdDir; |
1395 | + |
1396 | + ret = m_dirModel_01->cdIntoPath(absUrl); |
1397 | + QTest::qWait(TIME_TO_PROCESS); |
1398 | + QCOMPARE(ret, true); |
1399 | + QCOMPARE(m_dirModel_01->path(), absUrl ); |
1400 | + } |
1401 | +} |
1402 | + |
1403 | +void TestDirModel::smbCdIntoPathRelative() |
1404 | +{ |
1405 | + SmbItemInfo smbOK(LocationUrl::SmbURL); |
1406 | + QCOMPARE(smbOK.isValid(), true); |
1407 | + QCOMPARE(smbOK.isRoot(), true); |
1408 | + QCOMPARE(smbOK.needsAuthentication(), false); |
1409 | + QCOMPARE(smbOK.urlPath(), LocationUrl::SmbURL); |
1410 | + if (SmbUserShare::canCreateShares()) |
1411 | + { |
1412 | + QString shareName("smbsmbCdIntoPathRelative"); |
1413 | + |
1414 | + TestQSambaSuite smbTest(this); |
1415 | + |
1416 | + ShareCreationStatus tmpShare(smbTest.createTempShare(shareName)); |
1417 | + if (tmpShare.tempDir) |
1418 | + { |
1419 | + tmpShare.tempDir->setAutoRemove(true); |
1420 | + } |
1421 | + QString createdDir1("createdDir1"); |
1422 | + QString createdDir2("createdDir2"); |
1423 | + QString createDirFullPath = tmpShare.sharedDirPath + QDir::separator() + createdDir1 |
1424 | + + QDir::separator() + createdDir2; |
1425 | + bool ret = QDir().mkpath(createDirFullPath); |
1426 | + QCOMPARE(ret , true); |
1427 | + QString absUrl = LocationUrl::SmbURL + "localhost" + |
1428 | + QDir::separator() + tmpShare.shareName + |
1429 | + QDir::separator() + createdDir1; |
1430 | + |
1431 | + ret = m_dirModel_01->cdIntoPath(absUrl); |
1432 | + QTest::qWait(TIME_TO_PROCESS); |
1433 | + QCOMPARE(ret, true); |
1434 | + QCOMPARE(m_dirModel_01->path(), absUrl ); |
1435 | + QCOMPARE(m_dirModel_01->rowCount() , 1); |
1436 | + |
1437 | + //cd relative |
1438 | + absUrl += QDir::separator() + createdDir2; |
1439 | + ret = m_dirModel_01->cdIntoPath(createdDir2); |
1440 | + QTest::qWait(TIME_TO_PROCESS); |
1441 | + QCOMPARE(ret, true); |
1442 | + QCOMPARE(m_dirModel_01->path(), absUrl ); |
1443 | + QCOMPARE(m_dirModel_01->rowCount() , 0); |
1444 | + } |
1445 | +} |
1446 | + |
1447 | + |
1448 | int main(int argc, char *argv[]) |
1449 | { |
1450 | QApplication app(argc, argv); |
1451 | @@ -2988,7 +3039,7 @@ |
1452 | if (existentDir.startsWith(QDir::tempPath()) && (d.exists() || d.mkpath(existentDir))) |
1453 | { |
1454 | QTrashDir trash; |
1455 | - ::setenv("XDG_DATA_HOME", existentDir.toLatin1().constData(), true ); |
1456 | + ::setenv("XDG_DATA_HOME", existentDir.toLocal8Bit().constData(), true ); |
1457 | QString xdgTrashDir(trash.homeTrash()); |
1458 | ret = trash.validate(xdgTrashDir, true); |
1459 | } |
PASSED: Continuous integration, rev:422 91.189. 93.70:8080/ job/ubuntu- filemanager- app-ci/ 497/ 91.189. 93.70:8080/ job/generic- mediumtests- utopic/ 2966 91.189. 93.70:8080/ job/generic- mediumtests- utopic/ 2966/artifact/ work/output/ *zip*/output. zip 91.189. 93.70:8080/ job/ubuntu- filemanager- app-utopic- amd64-ci/ 213 91.189. 93.70:8080/ job/ubuntu- filemanager- app-vivid- amd64-ci/ 119
http://
Executed test runs:
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
Click here to trigger a rebuild: 91.189. 93.70:8080/ job/ubuntu- filemanager- app-ci/ 497/rebuild
http://