Merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-final into lp:ubuntu-filemanager-app

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 449
Merged at revision: 457
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-final
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-17
Diff against target: 816 lines (+686/-15)
2 files modified
src/plugin/test_folderlistmodel/regression/tempfiles.cpp (+27/-2)
src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp (+659/-13)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-final
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+265217@code.launchpad.net

Commit message

Created Samba tests for File Manager
Integrated specific Samba Tests from qsambaclient module into File Manager tests.

Description of the change

Created Samba tests for File Manager

TODO Next:
==========

1. Create a UI dialog for the signal: DirModel::needsAuthentication(user, url), and:
   * ask User (the user that comes from signal can be changed)
   * ask Password
   * ask if the user wants to save the password
   * UI must be closed and released to avoid consecutives needsAuthentication() signals
   * call DirModel::setPath(url, user, password ,savePassword)

2 Change Places plugin and put there some "Network" accesss like "smb://" or use the SmbPlaces class which provides the list of Samba Shares in the network.

3. The UI also needs to be changed to have the "Create User Share" action in place when browsing local disk.

4. The plugin also misses implementation for the property item "isSharedDir", it requires another QFileSystemWatcher for /var/lib/samba/usershares

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) :
review: Approve

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/tempfiles.cpp'
2--- src/plugin/test_folderlistmodel/regression/tempfiles.cpp 2015-06-20 17:27:13 +0000
3+++ src/plugin/test_folderlistmodel/regression/tempfiles.cpp 2015-07-19 17:07:33 +0000
4@@ -37,8 +37,23 @@
5
6 bool TempFiles::addSubDirLevel(const QString &dir)
7 {
8- QFileInfo d( m_dir + QDir::separator() + QFileInfo(dir).fileName() );
9- if (d.exists() || QDir().mkpath(d.absoluteFilePath()))
10+ QFileInfo d;
11+ QFileInfo dirInfo(dir);
12+ if (dirInfo.isRelative())
13+ {
14+ d.setFile(m_dir, dir); //append a single directory
15+ }
16+ else
17+ {
18+ d.setFile(dir); //use already made temp path
19+ }
20+ if (!d.exists() && QDir().mkpath(d.absoluteFilePath()))
21+ {
22+ QFile::setPermissions(d.absoluteFilePath(), QFile::WriteOwner | QFile::ReadOwner | QFile::ExeOwner
23+ | QFile::WriteGroup | QFile::ReadGroup | QFile::ExeGroup
24+ | QFile::WriteOther | QFile::ReadOther | QFile::ExeOther);
25+ }
26+ if (d.exists())
27 {
28 m_dir = d.absoluteFilePath();
29 return true;
30@@ -163,6 +178,11 @@
31 totalFiles(0),
32 totalItems(0)
33 {
34+ QFileInfo rootDirInfo(rootDir);
35+ if (rootDirInfo.isAbsolute())
36+ {
37+ root = rootDir;
38+ }
39 if (!rootDir.isEmpty())
40 {
41 remove(); // clear
42@@ -200,6 +220,11 @@
43 {
44 QString cmd("/bin/rm -rf " + root);
45 ret = ::system(cmd.toLocal8Bit().constData()) == 0 ;
46+ if (!ret)
47+ {
48+ qWarning("*** Could not remove %s, if it refers to Samba try to configure Samba using: 'force user' or 'create mask' plus 'directory mask'",
49+ qPrintable(root));
50+ }
51 }
52 return ret;
53 }
54
55=== modified file 'src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp'
56--- src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp 2015-07-19 17:07:33 +0000
57+++ src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp 2015-07-19 17:07:33 +0000
58@@ -12,6 +12,7 @@
59 #include "smbiteminfo.h"
60 #include "testqsambasuite.h"
61 #include "smbusershare.h"
62+#include "smblocationitemfile.h"
63
64 #if defined(Q_OS_UNIX)
65 #include <stdio.h>
66@@ -55,6 +56,7 @@
67
68 #define TIME_TO_PROCESS 2300
69 #define TIME_TO_REFRESH_DIR 90
70+#define TIME_TO_REFRESH_REMOTE_DIR (TIME_TO_REFRESH_DIR * 25) // samba RPC may take longer compared with local disk access even working on localhost
71
72 #if QT_VERSION >= 0x050000
73 #define QSKIP_ALL_TESTS(statement) QSKIP(statement)
74@@ -62,6 +64,8 @@
75 #define QSKIP_ALL_TESTS(statement) QSKIP(statement,SkipAll)
76 #endif
77
78+#define CHECK_IF_CAN_CREATE_SHARES() if (!SmbUserShare::canCreateShares()) \
79+ { qWarning() << Q_FUNC_INFO << "cannot be performed, it requires a Samba Server to create user shares"; return;}
80
81 QByteArray md5FromIcon(const QIcon& icon);
82 QString createFileInTempDir(const QString& name, const char *content, qint64 size);
83@@ -122,9 +126,7 @@
84 void diskCdIntoPathRelative();
85 void diskCdIntoPathAbsolute();
86 void trashCdIntoPathRelative();
87- void trashCdIntoPathAbsolute();
88- void smbCdIntoPathRelative();
89- void smbCdIntoPathAbsolute();
90+ void trashCdIntoPathAbsolute();
91 void fileIconProvider();
92 void getThemeIcons();
93 #ifndef DO_NOT_USE_TAG_LIB
94@@ -161,6 +163,26 @@
95 void restoreTrashWithMultipleSources();
96 void emptyTrash();
97
98+// Samba test cases
99+private Q_SLOTS:
100+ void smbCdIntoPathRelative();
101+ void smbCdIntoPathAbsolute();
102+ //tests for high level helper functions
103+ void smbExistsDir();
104+ void smbCanReadDir();
105+ void smbExistsFile();
106+ void smbCanReadFile();
107+ //common filemanager tests for Samba
108+ void smbMkdir();
109+ void smbMakeBackupNameForCurrentItem();
110+ void smbCopyFromSmb2Smb();
111+ void smbCopyFromSmb2LocalDisk();
112+ void smbCopyFromLocalDisk2Smb();
113+ void smbRemoveDirectory();
114+ void smbCutFromSmb2Smb();
115+ void smbCutFromSmb2LocalDisk();
116+ void smbCutFromLocalDisk2Smb();
117+
118 private:
119 bool createTempHomeTrashDir(const QString& existentDir);
120 void initDeepDirs();
121@@ -168,7 +190,7 @@
122 void initModels();
123 void cleanModels();
124 bool compareDirectories(const QString& d1,
125- const QString& d2);
126+ const QString& d2, bool comparePermissions = true);
127
128 bool createLink(const QString& fullSouce,
129 const QString& link,
130@@ -313,7 +335,7 @@
131 return ret;
132 }
133
134-bool TestDirModel::compareDirectories(const QString &d1, const QString &d2)
135+bool TestDirModel::compareDirectories(const QString &d1, const QString &d2, bool comparePermissions )
136 {
137 QDirIterator d1Info(d1,
138 QDir::Files | QDir::Hidden | QDir::System,
139@@ -337,7 +359,7 @@
140 << d2Info.fileName() << d2Info.size();
141 return false;
142 }
143- if (d1Info.fileInfo().permissions() != d2Info.permissions())
144+ if (comparePermissions && d1Info.fileInfo().permissions() != d2Info.permissions())
145 {
146 qDebug() << "false permissions" << d1Info.fileName() << d2Info.fileName();
147 return false;
148@@ -1437,8 +1459,10 @@
149 createTempHomeTrashDir(m_deepDir_01->path());
150
151 QTrashDir tempTrash;
152- QCOMPARE(files.addSubDirLevel(tempTrash.homeTrash()), true);
153- QCOMPARE(files.addSubDirLevel(QTrashUtilInfo::filesTrashDir(tempTrash.homeTrash())), true);
154+ QString homeTrashDir = tempTrash.homeTrash();
155+ QCOMPARE(files.addSubDirLevel(homeTrashDir), true);
156+ QString filesHomeTrashDir = QTrashUtilInfo::filesTrashDir(homeTrashDir);
157+ QCOMPARE(files.addSubDirLevel(filesHomeTrashDir), true);
158
159 QString level1("Level1");
160 QCOMPARE(files.addSubDirLevel(level1), true);
161@@ -1558,11 +1582,11 @@
162 QCOMPARE(m_dirModel_01->canReadDir(orig), true);
163
164 //check permissions from canReadDir()
165- bool ok = QFile::setPermissions(m_deepDir_01->path(),
166- QFileDevice::ReadOwner | QFileDevice::WriteOwner);
167+ bool ok = QFile::setPermissions(m_deepDir_01->path(), QFileDevice::WriteOwner);
168 QCOMPARE(ok, true);
169 QCOMPARE(m_dirModel_01->existsDir(orig), true);
170 QCOMPARE(m_dirModel_01->canReadDir(orig), false);
171+ QFile::setPermissions(m_deepDir_01->path(), QFileDevice::ReadOwner | QFileDevice::WriteOwner);
172
173 ok = QFile::setPermissions(m_deepDir_01->path(),
174 QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner );
175@@ -2961,6 +2985,621 @@
176 }
177 }
178
179+/*!
180+ * \brief TestDirModel::smbExistsDir() Tests for DirModel::existsDir() regarding Samba
181+ */
182+void TestDirModel::smbExistsDir()
183+{
184+ CHECK_IF_CAN_CREATE_SHARES();
185+
186+ QString shareName("smbExistsDir");
187+ TestQSambaSuite smbTest(this);
188+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
189+ if (tmpShare.tempDir)
190+ {
191+ tmpShare.tempDir->setAutoRemove(true);
192+ }
193+ QCOMPARE(tmpShare.status, true);
194+
195+ //create a folder inside this share
196+ QString folderName("folder");
197+ SmbSharedPathAccess folder = tmpShare.createPathForItem(folderName);
198+ QCOMPARE(QDir().mkpath(folder.diskPathname), true);
199+ QCOMPARE(QFileInfo(folder.diskPathname).exists(), true);
200+ //set file mananer to browse the temp share
201+ m_dirModel_01->setPath(tmpShare.url);
202+ QTest::qWait(TIME_TO_REFRESH_DIR);
203+ QCOMPARE(m_dirModel_01->rowCount() , 2); //temp shares are created with a file in it
204+ // check if the folder exists using relative name only
205+ QCOMPARE(m_dirModel_01->existsDir(folderName), true);
206+ // check it again using the full samba url
207+ QCOMPARE(m_dirModel_01->existsDir(folder.smbUrl), true);
208+ //negative tests
209+ // check for a relative folder that does not exist
210+ QString notExist("_I_Hope_it_does_not_exist");
211+ QCOMPARE(m_dirModel_01->existsDir(notExist), false);
212+ QString fullSmbUrl(tmpShare.url + QDir::separator() + notExist);
213+ QCOMPARE(m_dirModel_01->existsDir(fullSmbUrl), false);
214+}
215+
216+/*!
217+ * \brief TestDirModel::smbCanReadDir() Tests for DirModel::canReadDir() regading Samba
218+ */
219+void TestDirModel::smbCanReadDir()
220+{
221+ CHECK_IF_CAN_CREATE_SHARES();
222+
223+ QString shareName("smbCanReadDir");
224+ TestQSambaSuite smbTest(this);
225+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
226+ if (tmpShare.tempDir)
227+ {
228+ tmpShare.tempDir->setAutoRemove(true);
229+ }
230+ QCOMPARE(tmpShare.status, true);
231+
232+ //create a folder inside this share
233+ QString folderName("folder");
234+ SmbSharedPathAccess folder = tmpShare.createPathForItem(folderName);
235+ QCOMPARE(QDir().mkpath(folder.diskPathname), true);
236+ QCOMPARE(QFileInfo(folder.diskPathname).exists(), true);
237+ //set file mananer to browse the temp share
238+ m_dirModel_01->setPath(tmpShare.url);
239+ QTest::qWait(TIME_TO_REFRESH_DIR);
240+ QCOMPARE(m_dirModel_01->rowCount() , 2); //temp shares are created with a file in it
241+ QFile::Permissions folderOriginalPermissions = QFileInfo(folder.diskPathname).permissions();
242+ //first negative tests
243+ //change the permission to No Read
244+ bool ok = QFile::setPermissions(folder.diskPathname, QFile::WriteOwner | QFile::ExeOwner);
245+ QCOMPARE(ok, true);
246+ // check using relative name only
247+ QCOMPARE(m_dirModel_01->canReadDir(folderName), false);
248+ // check it again using the full samba url
249+ QCOMPARE(m_dirModel_01->canReadDir(folder.smbUrl), false);
250+ //negative tests
251+ // check for a relative folder that does not exist
252+ QString notExist("_I_Hope_it_does_not_exist");
253+ QCOMPARE(m_dirModel_01->canReadDir(notExist), false);
254+ QString fullSmbUrl(tmpShare.url + QDir::separator() + notExist);
255+ QCOMPARE(m_dirModel_01->canReadDir(fullSmbUrl), false);
256+ //now positive tests
257+ //give Read permission
258+ ok = QFile::setPermissions(folder.diskPathname, folderOriginalPermissions);
259+ QCOMPARE(ok, true);
260+ // check using relative name only
261+ QCOMPARE(m_dirModel_01->canReadDir(folderName), true);
262+ // check it again using the full samba url
263+ QCOMPARE(m_dirModel_01->canReadDir(folder.smbUrl), true);
264+}
265+
266+
267+/*!
268+ * \brief TestDirModel::smbExistsFile() Tests for DirModel::existsFile() regading Samba
269+ */
270+void TestDirModel::smbExistsFile()
271+{
272+ CHECK_IF_CAN_CREATE_SHARES();
273+
274+ QString shareName("smbExistsFile");
275+ TestQSambaSuite smbTest(this);
276+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
277+ if (tmpShare.tempDir)
278+ {
279+ tmpShare.tempDir->setAutoRemove(true);
280+ }
281+ QCOMPARE(tmpShare.status, true);
282+ //create a file inside this share
283+ QString fileName("fileTest.txt");
284+ SmbSharedPathAccess file = tmpShare.createPathForItem(fileName);
285+ QCOMPARE(QFileInfo(file.diskPathname).exists(), false);
286+ //set file mananer to browse the temp share
287+ m_dirModel_01->setPath(tmpShare.url);
288+ QTest::qWait(TIME_TO_REFRESH_DIR);
289+ QCOMPARE(m_dirModel_01->rowCount() , 1); //temp shares are created with a file in it
290+ //negative tests, file does not exist
291+ //using relative path
292+ QCOMPARE(m_dirModel_01->existsFile(fileName), false);
293+ //using absolute path
294+ QCOMPARE(m_dirModel_01->existsFile(file.smbUrl), false);
295+ //positive tests, file exists
296+ m_dirModel_01->goHome();
297+ QTest::qWait(TIME_TO_REFRESH_DIR);
298+ //now create the file
299+ QFile f(file.diskPathname);
300+ QCOMPARE(f.open(QFile::WriteOnly), true);
301+ f.close();
302+ //set file mananer to browse the temp share
303+ m_dirModel_01->setPath(tmpShare.url);
304+ QTest::qWait(TIME_TO_REFRESH_DIR);
305+ QCOMPARE(m_dirModel_01->rowCount() , 2); //temp shares are created with a file in it
306+ //using relative path
307+ QCOMPARE(m_dirModel_01->existsFile(fileName), true);
308+ //using absolute path
309+ QCOMPARE(m_dirModel_01->existsFile(file.smbUrl), true);
310+}
311+
312+
313+void TestDirModel::smbCanReadFile()
314+{
315+ CHECK_IF_CAN_CREATE_SHARES();
316+
317+ QString shareName("smbCanReadFile");
318+ TestQSambaSuite smbTest(this);
319+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
320+ if (tmpShare.tempDir)
321+ {
322+ tmpShare.tempDir->setAutoRemove(true);
323+ }
324+ QCOMPARE(tmpShare.status, true);
325+
326+ //create a file inside this share
327+ QString fileName("fileTest.txt");
328+ SmbSharedPathAccess file = tmpShare.createPathForItem(fileName);
329+ QFile f(file.diskPathname);
330+ QCOMPARE(f.open(QFile::WriteOnly), true);
331+ f.close();
332+ QCOMPARE(QFileInfo(file.diskPathname).exists(), true);
333+ //set file mananer to browse the temp share
334+ m_dirModel_01->setPath(tmpShare.url);
335+ QTest::qWait(TIME_TO_REFRESH_DIR);
336+ QCOMPARE(m_dirModel_01->rowCount() , 2); //temp shares are created with a file in it
337+ QFile::Permissions fileOriginalPermissions = QFileInfo(file.diskPathname).permissions();
338+ //first negative tests
339+ //change the permission to No Read
340+ bool ok = QFile::setPermissions(file.diskPathname, QFile::WriteOwner | QFile::ExeOwner);
341+ QCOMPARE(ok, true);
342+ // check using relative name only
343+ QCOMPARE(m_dirModel_01->canReadFile(fileName), false);
344+ // check it again using the full samba url
345+ QCOMPARE(m_dirModel_01->canReadFile(file.smbUrl), false);
346+ //negative tests
347+ // check for a relative folder that does not exist
348+ QString notExist("_I_Hope_it_does_not_exist");
349+ QCOMPARE(m_dirModel_01->canReadFile(notExist), false);
350+ QString fullSmbUrl(tmpShare.url + QDir::separator() + notExist);
351+ QCOMPARE(m_dirModel_01->canReadFile(fullSmbUrl), false);
352+ //now positive tests
353+ //give Read permission
354+ ok = QFile::setPermissions(file.diskPathname, fileOriginalPermissions);
355+ QCOMPARE(ok, true);
356+ // check using relative name only
357+ QCOMPARE(m_dirModel_01->canReadFile(fileName), true);
358+ // check it again using the full samba url
359+ QCOMPARE(m_dirModel_01->canReadFile(file.smbUrl), true);
360+}
361+
362+/*!
363+ * \brief TestDirModel::smbMkdir() Tests for DirModel::mkdir() regarding Samba
364+ */
365+void TestDirModel::smbMkdir()
366+{
367+ CHECK_IF_CAN_CREATE_SHARES();
368+
369+ QString shareName("smbMkdir");
370+ TestQSambaSuite smbTest(this);
371+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
372+ if (tmpShare.tempDir)
373+ {
374+ tmpShare.tempDir->setAutoRemove(true);
375+ }
376+ QCOMPARE(tmpShare.status, true);
377+ //set file mananer to browse the temp share
378+ m_dirModel_01->setPath(tmpShare.url);
379+ QTest::qWait(TIME_TO_REFRESH_DIR);
380+ QCOMPARE(m_dirModel_01->rowCount() , 1);
381+
382+ QString folder1Str("folder1");
383+ QString folder2Str("folder2");
384+ SmbSharedPathAccess folder1 = tmpShare.createPathForItem(folder1Str);
385+ SmbSharedPathAccess folder2 = tmpShare.createPathForItem(folder2Str);
386+ //using disk make sure folder1 does not exist
387+ QCOMPARE(QFileInfo(folder1.diskPathname).exists(), false);
388+ //create folder1 using relative path
389+ QCOMPARE(m_dirModel_01->mkdir(folder1Str), true);
390+ QTest::qWait(TIME_TO_REFRESH_DIR);
391+ QCOMPARE(m_dirModel_01->rowCount() , 2);
392+ QCOMPARE(QFileInfo(folder1.diskPathname).isDir(), true);
393+ //folder2 is created using full url
394+ QCOMPARE(QFileInfo(folder2.diskPathname).exists(), false);
395+ //create folder2 using full Samba URL
396+ QCOMPARE(m_dirModel_01->mkdir(folder2.smbUrl), true);
397+ QTest::qWait(TIME_TO_REFRESH_DIR);
398+ QCOMPARE(m_dirModel_01->rowCount() , 3);
399+ QCOMPARE(QFileInfo(folder2.diskPathname).isDir(), true);
400+ //check for full URL in the model items
401+ int counter = m_dirModel_01->rowCount() ;
402+ int found = 0; // look for folder1 and folder2 full url
403+ while (counter--)
404+ {
405+ const DirItemInfo & item = m_dirModel_01->mDirectoryContents[counter];
406+ if (item.urlPath() == folder1.smbUrl || item.urlPath() == folder2.smbUrl)
407+ {
408+ ++found;
409+ }
410+ }
411+ QCOMPARE(found, 2); //both folder1 and folder2 URLs are present
412+}
413+
414+/*!
415+ * \brief TestDirModel::smbMakeBackupNameForCurrentItem() Tests making backup of items using copy
416+ *
417+ * The similar test for item in local disk is modelCopyAndPasteToBackupFiles()
418+ */
419+void TestDirModel::smbMakeBackupNameForCurrentItem()
420+{
421+ CHECK_IF_CAN_CREATE_SHARES();
422+
423+ QString shareName("smbMakeBackupNameForCurrentItem");
424+ TestQSambaSuite smbTest(this);
425+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
426+ if (tmpShare.tempDir)
427+ {
428+ tmpShare.tempDir->setAutoRemove(true);
429+ }
430+ QCOMPARE(tmpShare.status, true);
431+ //set file mananer to browse the temp share
432+ m_dirModel_01->setPath(tmpShare.url);
433+ QTest::qWait(TIME_TO_REFRESH_DIR);
434+ QCOMPARE(m_dirModel_01->rowCount() , 1);
435+ //copy existent file in the Samba share, index 0 refers to tmpShare.fileContent.smbUrl
436+ m_dirModel_01->copyIndex(0);
437+ //pasting in the same directory must create item to Copy(1)
438+ m_dirModel_01->paste();
439+ QTest::qWait(TIME_TO_REFRESH_DIR);
440+ QCOMPARE(m_dirModel_01->rowCount() , 2);
441+ //pasting again must create item to Copy(2)
442+ m_dirModel_01->paste();
443+ QTest::qWait(TIME_TO_REFRESH_DIR);
444+ QCOMPARE(m_dirModel_01->rowCount() , 3);
445+ int counter = m_dirModel_01->rowCount() ;
446+ int found = 0;
447+ QFile fileContent(tmpShare.fileContent.diskPathname);
448+ QCOMPARE(fileContent.open(QFile::ReadOnly), true);
449+ QByteArray fileContentBytes(fileContent.readAll());
450+ fileContent.close();
451+ char smbBuffer [fileContentBytes.size()];
452+ qint64 size = (qint64)fileContentBytes.size();
453+ while (counter--)
454+ {
455+ const DirItemInfo & item = m_dirModel_01->mDirectoryContents[counter];
456+ //compare size content with the original file
457+ QCOMPARE(item.size(), size);
458+ SmbLocationItemFile smbFile(item.urlPath());
459+ QCOMPARE(smbFile.open(QFile::ReadOnly), true);
460+ QCOMPARE(smbFile.read(smbBuffer, size), size);
461+ smbFile.close();
462+ QByteArray smbContentBytes((const char*)&smbBuffer, fileContentBytes.size());
463+ //files must have the same content
464+ QCOMPARE(smbContentBytes, fileContentBytes);
465+ //look for backuped names
466+ if (item.urlPath().contains("Copy(1)") || item.urlPath().contains("Copy(2)"))
467+ {
468+ ++found;
469+ }
470+ }
471+ QCOMPARE(found, 2); //both backuped files were found
472+}
473+
474+/*!
475+ * \brief TestDirModel::smbCopyFromSmb2Smb()
476+ *
477+ * Creates a Samba Share in the local disk
478+ * Creates a directory tree with some files under smb://localhost/<tempShareName>/source
479+ * Copy its content to smb://localhost/<tempShareName>/target
480+ * Compares both directories using local disk correspondent path
481+ */
482+void TestDirModel::smbCopyFromSmb2Smb()
483+{
484+ CHECK_IF_CAN_CREATE_SHARES();
485+
486+ QString shareName("smbCopyFromSmb2Smb");
487+ TestQSambaSuite smbTest(this);
488+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
489+ if (tmpShare.tempDir)
490+ {
491+ tmpShare.tempDir->setAutoRemove(true);
492+ }
493+ QCOMPARE(tmpShare.status, true);
494+ QString sourceFolderName("source");
495+ QString targetFolderName("target");
496+ SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem(sourceFolderName);
497+ SmbSharedPathAccess targeFolder = tmpShare.createPathForItem(targetFolderName);
498+ //create a soruce directory tree in the share
499+ DeepDir sdir(sourceFolder.diskPathname, 3);
500+ //create the destination folder
501+ DeepDir tdir(targeFolder.diskPathname, 0); // 0 level, just create the root directory
502+ Q_UNUSED(sdir);
503+ Q_UNUSED(tdir);
504+ /*
505+ * set file mananer to browse the source directory using Samba url
506+ */
507+ m_dirModel_01->setPath(sourceFolder.smbUrl);
508+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
509+ QVERIFY(m_dirModel_01->rowCount() != 0);
510+ DirSelection *selection = m_dirModel_01->selectionObject();
511+ QVERIFY(selection != 0);
512+ selection->selectAll();
513+ QVERIFY(selection->counter() != 0);
514+ //copy the source folder using Samba URL
515+ m_dirModel_01->copySelection();
516+ //change directory to the target folder
517+ m_dirModel_01->setPath(targeFolder.smbUrl);
518+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
519+ QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
520+ m_dirModel_01->paste();
521+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
522+ QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
523+ //now compare directories source and target, permissions are not the same due to Samba Configuration
524+ QCOMPARE(compareDirectories(sourceFolder.diskPathname, targeFolder.diskPathname, false), true);
525+}
526+
527+
528+void TestDirModel::smbCopyFromSmb2LocalDisk()
529+{
530+ CHECK_IF_CAN_CREATE_SHARES();
531+
532+ QString shareName("smbCopyFromSmb2LocalDisk");
533+ TestQSambaSuite smbTest(this);
534+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
535+ if (tmpShare.tempDir)
536+ {
537+ tmpShare.tempDir->setAutoRemove(true);
538+ }
539+ QCOMPARE(tmpShare.status, true);
540+ QString sourceFolderName("source");
541+ QString targetFolderName("target");
542+ SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem(sourceFolderName);
543+ //create a soruce directory tree in the share
544+ DeepDir sdir(sourceFolder.diskPathname, 3);
545+ //create the destination folder in the /tmp
546+ DeepDir targetLocalDisk(targetFolderName, 0); // 0 level, just create the root directory
547+ Q_UNUSED(sdir);
548+ /*
549+ * set file mananer to browse the source directory using Samba url
550+ */
551+ m_dirModel_01->setPath(sourceFolder.smbUrl);
552+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
553+ QVERIFY(m_dirModel_01->rowCount() != 0);
554+ DirSelection *selection = m_dirModel_01->selectionObject();
555+ QVERIFY(selection != 0);
556+ selection->selectAll();
557+ QVERIFY(selection->counter() != 0);
558+ //copy the source folder using Samba URL
559+ m_dirModel_01->copySelection();
560+ //change directory to the target folder in the local disk
561+ m_dirModel_01->setPath(targetLocalDisk.path());
562+ QTest::qWait(TIME_TO_REFRESH_DIR);
563+ QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
564+ m_dirModel_01->paste();
565+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
566+ QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
567+ //now compare directories source and target, permissions are not the same due to Samba Configuration
568+ QCOMPARE(compareDirectories(sourceFolder.diskPathname, targetLocalDisk.path(), false), true);
569+}
570+
571+
572+void TestDirModel::smbCopyFromLocalDisk2Smb()
573+{
574+ CHECK_IF_CAN_CREATE_SHARES();
575+
576+ QString shareName("smbCopyFromLocalDisk2Smb");
577+ TestQSambaSuite smbTest(this);
578+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
579+ if (tmpShare.tempDir)
580+ {
581+ tmpShare.tempDir->setAutoRemove(true);
582+ }
583+ QCOMPARE(tmpShare.status, true);
584+ QString sourceFolderName("source");
585+ QString targetFolderName("target");
586+ SmbSharedPathAccess targeFolder = tmpShare.createPathForItem(targetFolderName);
587+ //create a soruce directory tree in /tmp
588+ DeepDir diskDir(sourceFolderName, 3);
589+ //create the destination folder in the share
590+ DeepDir tdir(targeFolder.diskPathname, 0); // 0 level, just create the root directory
591+ Q_UNUSED(tdir);
592+ /*
593+ * set file mananer to browse the source in the /tmp
594+ */
595+ m_dirModel_01->setPath(diskDir.path());
596+ QTest::qWait(TIME_TO_REFRESH_DIR);
597+ QVERIFY(m_dirModel_01->rowCount() != 0);
598+ DirSelection *selection = m_dirModel_01->selectionObject();
599+ QVERIFY(selection != 0);
600+ selection->selectAll();
601+ QVERIFY(selection->counter() != 0);
602+ //copy the source folder using file:// URLs
603+ m_dirModel_01->copySelection();
604+ //change directory to the target folder
605+ m_dirModel_01->setPath(targeFolder.smbUrl);
606+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
607+ QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
608+ m_dirModel_01->paste();
609+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
610+ QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
611+ //now compare directories source and target, permissions are not the same due to Samba Configuration
612+ QCOMPARE(compareDirectories(diskDir.path(), targeFolder.diskPathname, false), true);
613+}
614+
615+
616+void TestDirModel::smbRemoveDirectory()
617+{
618+ CHECK_IF_CAN_CREATE_SHARES();
619+
620+ QString shareName("smbRemoveDirectory");
621+ TestQSambaSuite smbTest(this);
622+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
623+ if (tmpShare.tempDir)
624+ {
625+ tmpShare.tempDir->setAutoRemove(true);
626+ }
627+ QCOMPARE(tmpShare.status, true);
628+ SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem("source");
629+ //create a directory tree with items in the local disk shared as Samba share
630+ DeepDir diskDir(sourceFolder.diskPathname, 3);
631+ Q_UNUSED(diskDir);
632+ /*
633+ * set file mananer to browse the source in the Samba share
634+ */
635+ m_dirModel_01->setPath(sourceFolder.smbUrl);
636+ QTest::qWait(TIME_TO_REFRESH_DIR);
637+ QVERIFY(m_dirModel_01->rowCount() != 0);
638+ DirSelection *selection = m_dirModel_01->selectionObject();
639+ QVERIFY(selection != 0);
640+ selection->selectAll();
641+ QVERIFY(selection->counter() != 0);
642+ m_dirModel_01->removeSelection();
643+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
644+ QCOMPARE(m_dirModel_01->rowCount() , 0); // now it is empty
645+}
646+
647+
648+void TestDirModel::smbCutFromSmb2Smb()
649+{
650+ CHECK_IF_CAN_CREATE_SHARES();
651+
652+ QString shareName("smbCutFromSmb2Smb");
653+ TestQSambaSuite smbTest(this);
654+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
655+ if (tmpShare.tempDir)
656+ {
657+ tmpShare.tempDir->setAutoRemove(true);
658+ }
659+ QCOMPARE(tmpShare.status, true);
660+ QString sourceFolderName("source");
661+ QString targetFolderName("target");
662+ SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem(sourceFolderName);
663+ SmbSharedPathAccess targeFolder = tmpShare.createPathForItem(targetFolderName);
664+ //create a soruce directory tree in the share
665+ DeepDir sdir(sourceFolder.diskPathname, 3);
666+ //create the destination folder
667+ DeepDir tdir(targeFolder.diskPathname, 0); // 0 level, just create the root directory
668+ Q_UNUSED(sdir);
669+ Q_UNUSED(tdir);
670+ /*
671+ * set file mananer to browse the source directory using Samba url
672+ */
673+ m_dirModel_01->setPath(sourceFolder.smbUrl);
674+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
675+ QVERIFY(m_dirModel_01->rowCount() != 0);
676+ DirSelection *selection = m_dirModel_01->selectionObject();
677+ QVERIFY(selection != 0);
678+ selection->selectAll();
679+ QVERIFY(selection->counter() != 0);
680+ //cut the source folder using Samba URL
681+ m_dirModel_01->cutSelection();
682+ //change directory to the target folder
683+ m_dirModel_01->setPath(targeFolder.smbUrl);
684+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
685+ QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
686+ //paste
687+ m_dirModel_01->paste();
688+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
689+ //check target directory is not empty
690+ QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
691+ //go back to the source samba url to make sure it is empty
692+ m_dirModel_01->setPath(sourceFolder.smbUrl);
693+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
694+ QCOMPARE(m_dirModel_01->rowCount(), 0);
695+}
696+
697+
698+void TestDirModel::smbCutFromSmb2LocalDisk()
699+{
700+ CHECK_IF_CAN_CREATE_SHARES();
701+
702+ QString shareName("smbCutFromSmb2LocalDisk");
703+ TestQSambaSuite smbTest(this);
704+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
705+ if (tmpShare.tempDir)
706+ {
707+ tmpShare.tempDir->setAutoRemove(true);
708+ }
709+ QCOMPARE(tmpShare.status, true);
710+ QString sourceFolderName("source");
711+ QString targetFolderName("diskTarget");
712+ SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem(sourceFolderName);
713+ //create a soruce directory tree in the share
714+ DeepDir sdir(sourceFolder.diskPathname, 3);
715+ //create the destination folder
716+ DeepDir diskTarget(targetFolderName, 0); // 0 level, just create the root directory
717+ Q_UNUSED(sdir);
718+ /*
719+ * set file mananer to browse the source directory using Samba url
720+ */
721+ m_dirModel_01->setPath(sourceFolder.smbUrl);
722+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
723+ QVERIFY(m_dirModel_01->rowCount() != 0);
724+ DirSelection *selection = m_dirModel_01->selectionObject();
725+ QVERIFY(selection != 0);
726+ selection->selectAll();
727+ QVERIFY(selection->counter() != 0);
728+ //cut the source folder using Samba URL
729+ m_dirModel_01->cutSelection();
730+ //change directory to the target folder in the local disk
731+ m_dirModel_01->setPath(diskTarget.path());
732+ QTest::qWait(TIME_TO_REFRESH_DIR);
733+ QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
734+ //paste
735+ m_dirModel_01->paste();
736+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR); //removes from Samba, needs more time
737+ //check target directory is not empty
738+ QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
739+ //go back to the source samba url to make sure it is empty
740+ m_dirModel_01->setPath(sourceFolder.smbUrl);
741+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
742+ QCOMPARE(m_dirModel_01->rowCount(), 0);
743+}
744+
745+
746+void TestDirModel::smbCutFromLocalDisk2Smb()
747+{
748+ CHECK_IF_CAN_CREATE_SHARES();
749+
750+ QString shareName("smbCutFromLocalDisk2Smb");
751+ TestQSambaSuite smbTest(this);
752+ ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
753+ if (tmpShare.tempDir)
754+ {
755+ tmpShare.tempDir->setAutoRemove(true);
756+ }
757+ QCOMPARE(tmpShare.status, true);
758+ QString sourceFolderName("source");
759+ QString targetFolderName("sambaTarget");
760+ SmbSharedPathAccess targetFolder = tmpShare.createPathForItem(targetFolderName);
761+ //create a soruce directory tree in the share
762+ DeepDir sdir(sourceFolderName, 3);
763+ //create the destination folder
764+ DeepDir smbTarget(targetFolder.diskPathname, 0); // 0 level, just create the root directory
765+ Q_UNUSED(smbTarget);
766+ /*
767+ * set file mananer to browse the source directory in the local disk
768+ */
769+ m_dirModel_01->setPath(sdir.path());
770+ QTest::qWait(TIME_TO_REFRESH_DIR);
771+ QVERIFY(m_dirModel_01->rowCount() != 0);
772+ DirSelection *selection = m_dirModel_01->selectionObject();
773+ QVERIFY(selection != 0);
774+ selection->selectAll();
775+ QVERIFY(selection->counter() != 0);
776+ //cut the source folder using local disk
777+ m_dirModel_01->cutSelection();
778+ //change directory to the target folder in Samba share
779+ m_dirModel_01->setPath(targetFolder.smbUrl);
780+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
781+ QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
782+ //paste
783+ m_dirModel_01->paste();
784+ QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
785+ //check target directory is not empty
786+ QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
787+ //go back to the source local disk make sure it is empty
788+ m_dirModel_01->setPath(sdir.path());
789+ QTest::qWait(TIME_TO_REFRESH_DIR);
790+ QCOMPARE(m_dirModel_01->rowCount(), 0);
791+}
792+
793+
794
795 int main(int argc, char *argv[])
796 {
797@@ -2981,9 +3620,16 @@
798 //if not running specific tests, run Samba test suite
799 if (args.count() == 1)
800 {
801- printf("\n********* Samba tests ********\n");
802- TestQSambaSuite smbTest;
803- ret |= QTest::qExec(&smbTest, args);
804+ if (SmbUserShare::canCreateShares())
805+ {
806+ printf("\n********* Samba tests ********\n");
807+ TestQSambaSuite smbTest;
808+ ret |= QTest::qExec(&smbTest, args);
809+ }
810+ else
811+ {
812+ printf("\n\n********* Make sure Samba server is installed and up to run specific Samba tests ********\n");
813+ }
814 }
815 return ret;
816 }

Subscribers

People subscribed via source and target branches