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
1=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp'
2--- src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp 2015-06-20 17:27:13 +0000
3+++ src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp 2015-07-19 16:43:07 +0000
4@@ -27,6 +27,7 @@
5 #include "smbutil.h"
6 #include "smblocationdiriterator.h"
7 #include <sys/stat.h>
8+#include <errno.h>
9
10 #include <QTest>
11 #include <QFile>
12@@ -75,7 +76,7 @@
13
14 sharedDirPath = o.sharedDirPath;
15 shareName = o.shareName;
16- fileContent = o.fileContent;
17+ fileContent.diskPathname = o.fileContent.diskPathname;
18 status = o.status;
19 tempDir = o.tempDir;
20 url = o.url;
21@@ -87,10 +88,34 @@
22 return *this;
23 }
24
25+SmbSharedPathAccess
26+ShareCreationStatus::createPathForItem(const QString &item)
27+{
28+ SmbSharedPathAccess pathItem;
29+ pathItem.diskPathname = sharedDirPath + QLatin1Char('/') + item;
30+ pathItem.smbUrl = url + QLatin1Char('/') + item;
31+ return pathItem;
32+}
33+
34+SmbSharedPathAccess
35+ShareCreationStatus::createPathForItems(const QStringList &items)
36+{
37+ SmbSharedPathAccess pathItem;
38+ pathItem.diskPathname = sharedDirPath;
39+ pathItem.smbUrl = url;
40+ for (int counter=0; counter < items.count(); ++counter)
41+ {
42+ pathItem.diskPathname += QLatin1Char('/') + items.at(counter);
43+ pathItem.smbUrl += QLatin1Char('/') + items.at(counter);
44+ }
45+ return pathItem;
46+}
47+
48
49 TestQSambaSuite::TestQSambaSuite(QObject *parent) :
50 QObject(parent)
51 ,m_smbShares( new SmbPlaces() )
52+ ,m_curUmask(0)
53 {
54 }
55
56@@ -98,18 +123,23 @@
57 TestQSambaSuite::~TestQSambaSuite()
58 {
59 delete m_smbShares;
60+ if (!m_curShareName.isEmpty())
61+ {
62+ SmbUserShare::removeShare(m_curShareName);
63+ }
64 }
65
66
67 void TestQSambaSuite::initTestCase()
68 {
69 QCOMPARE(SmbUserShare::canCreateShares(), true);
70+ m_curUmask = umask(0);
71 }
72
73
74 void TestQSambaSuite::cleanupTestCase()
75 {
76-
77+ umask(m_curUmask);
78 }
79
80
81@@ -131,6 +161,7 @@
82 {
83 SmbUserShare::removeShare(m_curShareName);
84 SmbUserShare::UserShareFile share = SmbUserShare::search(m_curShareName);
85+ m_curShareName.clear();
86 QCOMPARE(share.exists() , false);
87 }
88 }
89@@ -198,11 +229,10 @@
90 m_curShareName = QFileInfo(shareDir->path()).fileName();
91
92 //put some content in it
93- QString filename = createTempFile(shareDir->path(), "somecontent.txt", "hello Samba");
94+ QString fileContentName("somecontent.txt");
95+ QString filename = createTempFile(shareDir->path(), fileContentName, "hello Samba");
96 RETURN_SHARE_STATUS_WHEN_FALSE(filename.isEmpty(), false);
97
98- ret.fileContent = filename;
99-
100 //save current samba shares list
101 QStringList currentShares = m_smbShares->listPlacesSync();
102
103@@ -216,6 +246,8 @@
104 bool exists = existsShare(currentShares,shareDirName);
105 RETURN_SHARE_STATUS_WHEN_FALSE(exists, false);
106
107+ //first remove the share if it already exists, perhaps due to a failure in a previous test
108+ SmbUserShare::removeShare(shareDir->path());
109 //create the share
110 bool created = SmbUserShare::createShareForFolder(shareDir->path(),
111 fullAccess ? SmbUserShare::ReadWrite : SmbUserShare::Readonly,
112@@ -233,10 +265,7 @@
113 //let the share be removed by its path instead of the name
114 m_curShareName = shareDir->path();
115 ret.url = LocationUrl::SmbURL + "localhost/" + ret.shareName;
116-
117- //remove this
118- //=============================================================
119- m_curShareName.clear();
120+ ret.fileContent = ret.createPathForItem(fileContentName);
121
122 return ret;
123 }
124@@ -377,7 +406,7 @@
125 share.tempDir->setAutoRemove(true);
126 }
127 QCOMPARE(share.status, true);
128- QFileInfo file(share.fileContent);
129+ QFileInfo file(share.fileContent.diskPathname);
130 QCOMPARE(file.exists(), true);
131
132 QString urlPath("smb://localhost/" + share.shareName);
133@@ -410,13 +439,13 @@
134 share.tempDir->setAutoRemove(true);
135 }
136 QCOMPARE(share.status, true);
137- QFileInfo file(share.fileContent);
138+ QFileInfo file(share.fileContent.diskPathname);
139 QCOMPARE(file.exists(), true);
140
141 //set a common permission to the file
142- QFile::Permissions myPermissions = QFile::ReadOwner | QFile::WriteOwner |
143+ QFile::Permissions myPermissions = QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser | QFile::WriteUser |
144 QFile::ReadGroup | QFile::ReadOther;
145- QCOMPARE(QFile::setPermissions(share.fileContent, myPermissions), true);
146+ QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, myPermissions), true);
147
148 QString urlPath("smb://localhost/" + share.shareName);
149 QString url(urlPath + QDir::separator() + file.fileName());
150@@ -521,7 +550,7 @@
151 share.tempDir->setAutoRemove(true);
152 }
153 QCOMPARE(share.status, true);
154- QFileInfo file(share.fileContent);
155+ QFileInfo file(share.fileContent.diskPathname);
156 QCOMPARE(file.exists(), true);
157
158 //create a second directory inside the temporary share
159@@ -615,15 +644,13 @@
160 for(counter=0; fileOnly.hasNext() ; ++counter)
161 {
162 fileOnly.next();
163- if (fileOnly.fileName() == QFileInfo(share.fileContent).fileName())
164+ if (fileOnly.fileName() == QFileInfo(share.fileContent.diskPathname).fileName())
165 {
166 fileContent = true;
167 }
168 }
169 QCOMPARE(counter, 1);
170 QCOMPARE(fileContent, true);
171-
172-
173 }
174
175
176
177=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h'
178--- src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h 2015-06-20 17:27:13 +0000
179+++ src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h 2015-07-19 16:43:07 +0000
180@@ -27,6 +27,13 @@
181 class SmbPlaces;
182 class QTemporaryDir;
183
184+//for a local share in the localhost
185+struct SmbSharedPathAccess
186+{
187+ QString diskPathname; //full path name for disk access
188+ QString smbUrl; //full path name for smb access
189+};
190+
191 struct ShareCreationStatus
192 {
193 ShareCreationStatus(const QString& dirNameMask);
194@@ -35,10 +42,12 @@
195 ~ShareCreationStatus();
196 ShareCreationStatus &operator=(const ShareCreationStatus & o);
197 ShareCreationStatus &operator=(ShareCreationStatus & o);
198- QString sharedDirPath;
199- QString shareName;
200- QString fileContent;
201- QString url;
202+ SmbSharedPathAccess createPathForItem(const QString& item);
203+ SmbSharedPathAccess createPathForItems(const QStringList& items);
204+ SmbSharedPathAccess fileContent; // a simple file is created in evey share
205+ QString sharedDirPath; //share path in the localhost
206+ QString shareName; //share name
207+ QString url; //share url
208 bool status;
209 QTemporaryDir * tempDir;
210 private:
211@@ -90,6 +99,7 @@
212 private:
213 SmbPlaces *m_smbShares;
214 QString m_curShareName;
215+ mode_t m_curUmask;
216
217 };
218

Subscribers

People subscribed via source and target branches