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

Proposed by Carlos Jose Mazieri
Status: Merged
Approved by: Arto Jalkanen
Approved revision: 447
Merged at revision: 455
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-16
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-15
Diff against target: 217 lines (+58/-21)
2 files modified
src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp (+44/-17)
src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h (+14/-4)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-16
Reviewer Review Type Date Requested Status
Arto Jalkanen Approve
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve
Review via email: mp+265215@code.launchpad.net

Commit message

Improved Samba Specific tests

Description of the change

Improved Samba Specific tests, they are kept separated as "qsambaclient" is intended to be a Qt Samba Client standalone library.

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
=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp'
--- src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp 2015-06-20 17:27:13 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp 2015-07-19 16:43:07 +0000
@@ -27,6 +27,7 @@
27#include "smbutil.h"27#include "smbutil.h"
28#include "smblocationdiriterator.h"28#include "smblocationdiriterator.h"
29#include <sys/stat.h>29#include <sys/stat.h>
30#include <errno.h>
3031
31#include <QTest>32#include <QTest>
32#include <QFile>33#include <QFile>
@@ -75,7 +76,7 @@
7576
76 sharedDirPath = o.sharedDirPath;77 sharedDirPath = o.sharedDirPath;
77 shareName = o.shareName;78 shareName = o.shareName;
78 fileContent = o.fileContent;79 fileContent.diskPathname = o.fileContent.diskPathname;
79 status = o.status;80 status = o.status;
80 tempDir = o.tempDir;81 tempDir = o.tempDir;
81 url = o.url;82 url = o.url;
@@ -87,10 +88,34 @@
87 return *this;88 return *this;
88}89}
8990
91SmbSharedPathAccess
92ShareCreationStatus::createPathForItem(const QString &item)
93{
94 SmbSharedPathAccess pathItem;
95 pathItem.diskPathname = sharedDirPath + QLatin1Char('/') + item;
96 pathItem.smbUrl = url + QLatin1Char('/') + item;
97 return pathItem;
98}
99
100SmbSharedPathAccess
101ShareCreationStatus::createPathForItems(const QStringList &items)
102{
103 SmbSharedPathAccess pathItem;
104 pathItem.diskPathname = sharedDirPath;
105 pathItem.smbUrl = url;
106 for (int counter=0; counter < items.count(); ++counter)
107 {
108 pathItem.diskPathname += QLatin1Char('/') + items.at(counter);
109 pathItem.smbUrl += QLatin1Char('/') + items.at(counter);
110 }
111 return pathItem;
112}
113
90114
91TestQSambaSuite::TestQSambaSuite(QObject *parent) :115TestQSambaSuite::TestQSambaSuite(QObject *parent) :
92 QObject(parent)116 QObject(parent)
93 ,m_smbShares( new SmbPlaces() )117 ,m_smbShares( new SmbPlaces() )
118 ,m_curUmask(0)
94{119{
95}120}
96121
@@ -98,18 +123,23 @@
98TestQSambaSuite::~TestQSambaSuite()123TestQSambaSuite::~TestQSambaSuite()
99{124{
100 delete m_smbShares;125 delete m_smbShares;
126 if (!m_curShareName.isEmpty())
127 {
128 SmbUserShare::removeShare(m_curShareName);
129 }
101}130}
102131
103132
104void TestQSambaSuite::initTestCase()133void TestQSambaSuite::initTestCase()
105{ 134{
106 QCOMPARE(SmbUserShare::canCreateShares(), true);135 QCOMPARE(SmbUserShare::canCreateShares(), true);
136 m_curUmask = umask(0);
107}137}
108138
109139
110void TestQSambaSuite::cleanupTestCase()140void TestQSambaSuite::cleanupTestCase()
111{141{
112142 umask(m_curUmask);
113}143}
114144
115145
@@ -131,6 +161,7 @@
131 {161 {
132 SmbUserShare::removeShare(m_curShareName);162 SmbUserShare::removeShare(m_curShareName);
133 SmbUserShare::UserShareFile share = SmbUserShare::search(m_curShareName);163 SmbUserShare::UserShareFile share = SmbUserShare::search(m_curShareName);
164 m_curShareName.clear();
134 QCOMPARE(share.exists() , false);165 QCOMPARE(share.exists() , false);
135 }166 }
136}167}
@@ -198,11 +229,10 @@
198 m_curShareName = QFileInfo(shareDir->path()).fileName();229 m_curShareName = QFileInfo(shareDir->path()).fileName();
199230
200 //put some content in it231 //put some content in it
201 QString filename = createTempFile(shareDir->path(), "somecontent.txt", "hello Samba");232 QString fileContentName("somecontent.txt");
233 QString filename = createTempFile(shareDir->path(), fileContentName, "hello Samba");
202 RETURN_SHARE_STATUS_WHEN_FALSE(filename.isEmpty(), false);234 RETURN_SHARE_STATUS_WHEN_FALSE(filename.isEmpty(), false);
203235
204 ret.fileContent = filename;
205
206 //save current samba shares list236 //save current samba shares list
207 QStringList currentShares = m_smbShares->listPlacesSync();237 QStringList currentShares = m_smbShares->listPlacesSync();
208238
@@ -216,6 +246,8 @@
216 bool exists = existsShare(currentShares,shareDirName);246 bool exists = existsShare(currentShares,shareDirName);
217 RETURN_SHARE_STATUS_WHEN_FALSE(exists, false);247 RETURN_SHARE_STATUS_WHEN_FALSE(exists, false);
218248
249 //first remove the share if it already exists, perhaps due to a failure in a previous test
250 SmbUserShare::removeShare(shareDir->path());
219 //create the share251 //create the share
220 bool created = SmbUserShare::createShareForFolder(shareDir->path(),252 bool created = SmbUserShare::createShareForFolder(shareDir->path(),
221 fullAccess ? SmbUserShare::ReadWrite : SmbUserShare::Readonly,253 fullAccess ? SmbUserShare::ReadWrite : SmbUserShare::Readonly,
@@ -233,10 +265,7 @@
233 //let the share be removed by its path instead of the name265 //let the share be removed by its path instead of the name
234 m_curShareName = shareDir->path();266 m_curShareName = shareDir->path();
235 ret.url = LocationUrl::SmbURL + "localhost/" + ret.shareName;267 ret.url = LocationUrl::SmbURL + "localhost/" + ret.shareName;
236268 ret.fileContent = ret.createPathForItem(fileContentName);
237 //remove this
238 //=============================================================
239 m_curShareName.clear();
240269
241 return ret;270 return ret;
242}271}
@@ -377,7 +406,7 @@
377 share.tempDir->setAutoRemove(true);406 share.tempDir->setAutoRemove(true);
378 }407 }
379 QCOMPARE(share.status, true);408 QCOMPARE(share.status, true);
380 QFileInfo file(share.fileContent);409 QFileInfo file(share.fileContent.diskPathname);
381 QCOMPARE(file.exists(), true);410 QCOMPARE(file.exists(), true);
382411
383 QString urlPath("smb://localhost/" + share.shareName);412 QString urlPath("smb://localhost/" + share.shareName);
@@ -410,13 +439,13 @@
410 share.tempDir->setAutoRemove(true);439 share.tempDir->setAutoRemove(true);
411 }440 }
412 QCOMPARE(share.status, true);441 QCOMPARE(share.status, true);
413 QFileInfo file(share.fileContent);442 QFileInfo file(share.fileContent.diskPathname);
414 QCOMPARE(file.exists(), true);443 QCOMPARE(file.exists(), true);
415444
416 //set a common permission to the file445 //set a common permission to the file
417 QFile::Permissions myPermissions = QFile::ReadOwner | QFile::WriteOwner |446 QFile::Permissions myPermissions = QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser | QFile::WriteUser |
418 QFile::ReadGroup | QFile::ReadOther;447 QFile::ReadGroup | QFile::ReadOther;
419 QCOMPARE(QFile::setPermissions(share.fileContent, myPermissions), true);448 QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, myPermissions), true);
420449
421 QString urlPath("smb://localhost/" + share.shareName);450 QString urlPath("smb://localhost/" + share.shareName);
422 QString url(urlPath + QDir::separator() + file.fileName());451 QString url(urlPath + QDir::separator() + file.fileName());
@@ -521,7 +550,7 @@
521 share.tempDir->setAutoRemove(true);550 share.tempDir->setAutoRemove(true);
522 }551 }
523 QCOMPARE(share.status, true);552 QCOMPARE(share.status, true);
524 QFileInfo file(share.fileContent);553 QFileInfo file(share.fileContent.diskPathname);
525 QCOMPARE(file.exists(), true);554 QCOMPARE(file.exists(), true);
526555
527 //create a second directory inside the temporary share556 //create a second directory inside the temporary share
@@ -615,15 +644,13 @@
615 for(counter=0; fileOnly.hasNext() ; ++counter)644 for(counter=0; fileOnly.hasNext() ; ++counter)
616 {645 {
617 fileOnly.next();646 fileOnly.next();
618 if (fileOnly.fileName() == QFileInfo(share.fileContent).fileName())647 if (fileOnly.fileName() == QFileInfo(share.fileContent.diskPathname).fileName())
619 {648 {
620 fileContent = true;649 fileContent = true;
621 }650 }
622 }651 }
623 QCOMPARE(counter, 1);652 QCOMPARE(counter, 1);
624 QCOMPARE(fileContent, true);653 QCOMPARE(fileContent, true);
625
626
627}654}
628655
629656
630657
=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h'
--- src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h 2015-06-20 17:27:13 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h 2015-07-19 16:43:07 +0000
@@ -27,6 +27,13 @@
27class SmbPlaces;27class SmbPlaces;
28class QTemporaryDir;28class QTemporaryDir;
2929
30//for a local share in the localhost
31struct SmbSharedPathAccess
32{
33 QString diskPathname; //full path name for disk access
34 QString smbUrl; //full path name for smb access
35};
36
30struct ShareCreationStatus37struct ShareCreationStatus
31{38{
32 ShareCreationStatus(const QString& dirNameMask);39 ShareCreationStatus(const QString& dirNameMask);
@@ -35,10 +42,12 @@
35 ~ShareCreationStatus();42 ~ShareCreationStatus();
36 ShareCreationStatus &operator=(const ShareCreationStatus & o);43 ShareCreationStatus &operator=(const ShareCreationStatus & o);
37 ShareCreationStatus &operator=(ShareCreationStatus & o);44 ShareCreationStatus &operator=(ShareCreationStatus & o);
38 QString sharedDirPath;45 SmbSharedPathAccess createPathForItem(const QString& item);
39 QString shareName;46 SmbSharedPathAccess createPathForItems(const QStringList& items);
40 QString fileContent;47 SmbSharedPathAccess fileContent; // a simple file is created in evey share
41 QString url;48 QString sharedDirPath; //share path in the localhost
49 QString shareName; //share name
50 QString url; //share url
42 bool status;51 bool status;
43 QTemporaryDir * tempDir;52 QTemporaryDir * tempDir;
44private:53private:
@@ -90,6 +99,7 @@
90private:99private:
91 SmbPlaces *m_smbShares;100 SmbPlaces *m_smbShares;
92 QString m_curShareName;101 QString m_curShareName;
102 mode_t m_curUmask;
93103
94};104};
95105

Subscribers

People subscribed via source and target branches