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

Proposed by Carlos Jose Mazieri on 2015-07-19
Status: Merged
Approved by: Arto Jalkanen on 2015-08-11
Approved revision: 448
Merged at revision: 456
Proposed branch: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-17
Merge into: lp:ubuntu-filemanager-app
Prerequisite: lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-16
Diff against target: 706 lines (+681/-0)
2 files modified
src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp (+658/-0)
src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h (+23/-0)
To merge this branch: bzr merge lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-17
Reviewer Review Type Date Requested Status
Arto Jalkanen 2015-07-19 Approve on 2015-08-11
Ubuntu Phone Apps Jenkins Bot continuous-integration Approve on 2015-07-19
Review via email: mp+265216@code.launchpad.net

Commit message

Created Unit Tests for Samba Similar Qt Objects: SmbLocationItemFile, SmbLocationItemDir and SmbLocationItemDirIterator

Description of the change

Created Unit Tests for Samba Similar Qt Objects in "qsambaclient" module.

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-07-19 16:44:54 +0000
3+++ src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp 2015-07-19 16:44:54 +0000
4@@ -26,6 +26,8 @@
5 #include "locationurl.h"
6 #include "smbutil.h"
7 #include "smblocationdiriterator.h"
8+#include "smblocationitemfile.h"
9+#include "smblocationitemdir.h"
10 #include <sys/stat.h>
11 #include <errno.h>
12
13@@ -726,3 +728,659 @@
14 }
15 return true;
16 }
17+
18+
19+void TestQSambaSuite::unit_QFile_rename()
20+{
21+ ShareCreationStatus share(createTempShare("unit_QFile_rename"));
22+ if (share.tempDir)
23+ {
24+ share.tempDir->setAutoRemove(true);
25+ }
26+ QCOMPARE(share.status, true);
27+
28+ //negative tests
29+ //empty object
30+ SmbLocationItemFile fileNameEmptyDoesNotExist;
31+ QString newName("this_was_renamed.txt");
32+ QCOMPARE(fileNameEmptyDoesNotExist.rename(newName), false);
33+ QCOMPARE(fileNameEmptyDoesNotExist.rename(QLatin1String(0), newName), false);
34+ //orig file does not exist
35+ QString nameDoesNotExist("_it_must_not_exist");
36+ SmbSharedPathAccess item = share.createPathForItem(nameDoesNotExist);
37+ QFileInfo diskFileContent(item.diskPathname);
38+ QCOMPARE(diskFileContent.exists(), false);
39+ SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
40+ QCOMPARE(fileNameDoesNotExist.rename(newName), false);
41+ QCOMPARE(fileNameDoesNotExist.rename(nameDoesNotExist, newName), false);
42+
43+ //positive tests
44+ SmbSharedPathAccess newItem = share.createPathForItem(newName);
45+ QFileInfo newFileInfo(newItem.diskPathname);
46+ //make sure target does not exist
47+ QCOMPARE(newFileInfo.exists(), false);
48+ //now rename
49+ SmbLocationItemFile fileNameExists(share.fileContent.smbUrl);
50+ QCOMPARE(fileNameExists.rename(newItem.smbUrl), true);
51+ //now target must exist in local file system
52+ QCOMPARE(newFileInfo.exists(), true);
53+ diskFileContent.setFile(share.fileContent.diskPathname);
54+ //make sure orignal file no longer exist
55+ QCOMPARE(diskFileContent.exists(), false);
56+ //now back to original name using an empty object
57+ SmbLocationItemFile empty;
58+ QCOMPARE(empty.rename(newItem.smbUrl, share.fileContent.smbUrl), true);
59+ //make sure orignal exists again
60+ QCOMPARE(diskFileContent.exists(), true);
61+}
62+
63+
64+void TestQSambaSuite::unit_QFile_remove()
65+{
66+ ShareCreationStatus share(createTempShare("unit_QFile_remove"));
67+ if (share.tempDir)
68+ {
69+ share.tempDir->setAutoRemove(true);
70+ }
71+ QCOMPARE(share.status, true);
72+
73+ //negative tests
74+ //empty object
75+ SmbLocationItemFile fileNameEmptyDoesNotExist;
76+ QCOMPARE(fileNameEmptyDoesNotExist.remove(), false);
77+ //file name does not exist
78+ SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
79+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
80+ SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
81+ QCOMPARE(fileNameDoesNotExist.remove(), false);
82+ QFileInfo diskFileInfo(share.fileContent.diskPathname);
83+// //now try to remove a file which does not have write permission
84+// QCOMPARE(diskFileInfo.exists(), true);
85+// QFile::Permissions originalPermissions = diskFileInfo.permissions();
86+// QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther), true);
87+// SmbLocationItemFile existentFileButNoWritePermission(share.fileContent.smbUrl);
88+// //remove must fail
89+// QCOMPARE(existentFileButNoWritePermission.remove(), false);
90+// QCOMPARE(errno, EPERM);
91+// QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, originalPermissions), true);
92+
93+ //positive test, remove fileContent
94+ SmbLocationItemFile existentFile(share.fileContent.smbUrl);
95+ SmbItemInfo smbExistentItem(share.fileContent.smbUrl);
96+ QCOMPARE(smbExistentItem.exists(), true);
97+ QCOMPARE(existentFile.remove(), true);
98+ SmbItemInfo smbItem(share.fileContent.smbUrl);
99+ //samba url for this file must not exist
100+ QCOMPARE(smbItem.exists(), false);
101+ //now origin file in file system must no longer exist
102+ QCOMPARE(diskFileInfo.exists(), false);
103+}
104+
105+
106+void TestQSambaSuite::unit_QFile_open()
107+{
108+ ShareCreationStatus share(createTempShare("unit_QFile_open"));
109+ if (share.tempDir)
110+ {
111+ share.tempDir->setAutoRemove(true);
112+ }
113+ QCOMPARE(share.status, true);
114+
115+ //negative tests
116+ SmbLocationItemFile fileNameEmptyDoesNotExist;
117+ QCOMPARE(fileNameEmptyDoesNotExist.open(QFile::WriteOnly), false);
118+ SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
119+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
120+ SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
121+ QCOMPARE(fileNameDoesNotExist.open(QFile::ReadOnly), false);
122+
123+ // ---- positive tests
124+ //create a smb file using open
125+ item = share.createPathForItem("now_it_must_be_created");
126+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
127+ SmbLocationItemFile fileCreated(item.smbUrl);
128+ QCOMPARE(fileCreated.open(QFile::WriteOnly), true);
129+ if (QFileInfo(item.diskPathname).exists() == false)
130+ {
131+ fileCreated.close(); // force to close if necessary
132+ }
133+ QCOMPARE(fileCreated.isOpen(), true);
134+ //now check in the local disk to see if it was really created
135+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
136+ //as QFile it closes itself in the destructor
137+}
138+
139+
140+void TestQSambaSuite::unit_QFile_read()
141+{
142+ ShareCreationStatus share(createTempShare("unit_QFile_read"));
143+ if (share.tempDir)
144+ {
145+ share.tempDir->setAutoRemove(true);
146+ }
147+ QCOMPARE(share.status, true);
148+
149+ //negative tests
150+ SmbLocationItemFile fileNameEmptyDoesNotExist;
151+ char buffer[100];
152+
153+ //get Qt read return when there is no file
154+ qint64 qt_read_no_file = QFile().read(buffer, sizeof(buffer));
155+
156+ QCOMPARE(fileNameEmptyDoesNotExist.read(buffer, sizeof(buffer)), qt_read_no_file);
157+ SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
158+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
159+ SmbLocationItemFile fileMustNotExist(item.smbUrl);
160+ QCOMPARE(fileMustNotExist.read(buffer, sizeof(buffer)), qt_read_no_file);
161+
162+ //positive test
163+ //create a file in the local folder which is shared by Samba
164+ item = share.createPathForItem("created_in_the_disk.txt");
165+ QFile inDisk(item.diskPathname);
166+ QCOMPARE(inDisk.open(QFile::WriteOnly), true);
167+ QByteArray diskContent("This a simple content used to test reading files from samba: ");
168+ QByteArray initialDiskContent(diskContent);
169+ QByteArray moreDiskContent(100, 'a');
170+ diskContent += moreDiskContent;
171+ QCOMPARE(inDisk.write(diskContent), (qint64)diskContent.size());
172+ inDisk.close();
173+ //now read from Samba
174+ SmbLocationItemFile existentFile(item.smbUrl);
175+ QCOMPARE(existentFile.open(QFile::ReadOnly), true);
176+ char smbBuffer [diskContent.size() + 100];
177+ //before first read
178+ QCOMPARE(existentFile.atEnd(), false);
179+ qint64 bytesRead = existentFile.read(smbBuffer, (qint64)initialDiskContent.size());
180+ qint64 expectedRead = (qint64)initialDiskContent.size();
181+ QCOMPARE(bytesRead, expectedRead);
182+ QByteArray smbContent(smbBuffer,initialDiskContent.size());
183+ //compare the intial content
184+ QCOMPARE(smbContent, initialDiskContent);
185+ //before second read
186+ QCOMPARE(existentFile.atEnd(), false);
187+ expectedRead = (qint64) (diskContent.size() - initialDiskContent.size());
188+ //read remaining data in the file
189+ bytesRead = existentFile.read(smbBuffer, expectedRead);
190+ QCOMPARE(bytesRead, expectedRead);
191+ QByteArray moreSmbContent(smbBuffer, expectedRead);
192+ smbContent += moreSmbContent;
193+ //now compare the whole content
194+ QCOMPARE(smbContent, diskContent);
195+ //now atEnd() must be true
196+ QCOMPARE(existentFile.atEnd(), true);
197+}
198+
199+
200+void TestQSambaSuite::unit_QFile_write()
201+{
202+ ShareCreationStatus share(createTempShare("unit_QFile_write"));
203+ if (share.tempDir)
204+ {
205+ share.tempDir->setAutoRemove(true);
206+ }
207+ QCOMPARE(share.status, true);
208+
209+ //negative tests
210+ SmbLocationItemFile fileNameEmptyDoesNotExist;
211+ QByteArray someContent("This is a simple content\n");
212+ //get Qt write return when there is no file
213+ qint64 qt_write_no_file = QFile().write(someContent.constData(), (qint64)someContent.size());
214+ QCOMPARE(fileNameEmptyDoesNotExist.write(someContent.constData(), (qint64)someContent.size()), qt_write_no_file);
215+ SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
216+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
217+ SmbLocationItemFile fileMustNotExist(item.smbUrl);
218+ QCOMPARE(fileMustNotExist.write(someContent.constData(), (qint64)someContent.size()), qt_write_no_file);
219+
220+ //positive tests
221+ //work with 2 items saving in Samba and saving in local file system
222+ SmbSharedPathAccess items[2];
223+ items[0] = share.createPathForItem("first_item.txt");
224+ items[1] = share.createPathForItem("second_item.txt");
225+ QByteArray content; // starts empty
226+ QFile::OpenMode openMode = QFile::WriteOnly; //after first write it receives Append mode
227+ const int diskIndex = 0;
228+ const int smbindex = 1;
229+ QByteArray savedContent;
230+ for(int counter = 0; counter < 4; ++counter, content += someContent)
231+ {
232+ QFile diskFile(items[diskIndex].diskPathname);
233+ SmbLocationItemFile smbFile(items[smbindex].smbUrl);
234+ //open both files
235+ QCOMPARE(diskFile.open(openMode), true);
236+ QCOMPARE(smbFile.open(openMode), true);
237+ //first write should return 0 as content is empty
238+ qint64 toSave = content.size();
239+ qint64 wrote = diskFile.write(content.constData(), toSave);
240+ QCOMPARE(wrote, toSave);
241+ wrote = smbFile.write(content.constData(), toSave);
242+ QCOMPARE(wrote, toSave);
243+ savedContent += content;
244+ diskFile.close();
245+ smbFile.close();
246+ if (counter > 0)
247+ {
248+ openMode = QFile::Append;
249+ }
250+ }
251+ //now check size and content
252+ QFile diskFile(items[diskIndex].diskPathname);
253+ SmbLocationItemFile smbFile(items[smbindex].smbUrl);
254+ QCOMPARE(smbFile.size(), diskFile.size());
255+ QCOMPARE(diskFile.open(QFile::ReadOnly), true);
256+ QCOMPARE(smbFile.open(QFile::ReadOnly), true);
257+ //read file from disk, check the content
258+ char buffer [1024];
259+ qint64 gotBytes = diskFile.read(buffer, sizeof(buffer));
260+ QCOMPARE((qint64)savedContent.size(), gotBytes);
261+ QByteArray otherContent(buffer, (int)gotBytes);
262+ QCOMPARE(otherContent, savedContent);
263+ //read SMB file from disk, check the content
264+ gotBytes = smbFile.read(buffer, sizeof(buffer));
265+ QCOMPARE((qint64)savedContent.size(), gotBytes);
266+ otherContent.setRawData(buffer, (int)gotBytes);
267+ QCOMPARE(otherContent, savedContent);
268+}
269+
270+
271+void TestQSambaSuite::unit_QFile_atEnd()
272+{
273+ ShareCreationStatus share(createTempShare("unit_QFile_atEnd"));
274+ if (share.tempDir)
275+ {
276+ share.tempDir->setAutoRemove(true);
277+ }
278+ QCOMPARE(share.status, true);
279+
280+ //negative tests
281+ SmbLocationItemFile fileNameEmptyDoesNotExist;
282+ QCOMPARE(fileNameEmptyDoesNotExist.atEnd(), true);
283+ SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
284+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
285+ SmbLocationItemFile fileMustNotExist(item.smbUrl);
286+ QCOMPARE(fileMustNotExist.atEnd(), true);
287+ QFileInfo fileContentInfo(share.fileContent.diskPathname);
288+ QCOMPARE(fileContentInfo.exists(), true);
289+ SmbLocationItemFile existentFile(share.fileContent.smbUrl);
290+ //first at end when file is still closed
291+ QCOMPARE(existentFile.atEnd(), true);
292+ QCOMPARE(existentFile.open(QFile::ReadOnly), true);
293+ char buffer [fileContentInfo.size()];
294+ QCOMPARE(existentFile.read(buffer, (qint64)10), (qint64)10);
295+ //file is opened and not at end
296+ QCOMPARE(existentFile.atEnd(), false);
297+ QVERIFY(existentFile.read(buffer, fileContentInfo.size()) > 0);
298+ QCOMPARE(existentFile.atEnd(), true);
299+}
300+
301+
302+void TestQSambaSuite::unit_QFile_size()
303+{
304+ ShareCreationStatus share(createTempShare("unit_QFile_size"));
305+ if (share.tempDir)
306+ {
307+ share.tempDir->setAutoRemove(true);
308+ }
309+ QCOMPARE(share.status, true);
310+
311+ //negative tests
312+ //empty objects
313+ qint64 qFile_size_for_disk = QFileInfo().size();
314+ SmbLocationItemFile fileNameEmptyDoesNotExist;
315+ QCOMPARE(fileNameEmptyDoesNotExist.size(), qFile_size_for_disk);
316+ //file does not exist
317+ SmbSharedPathAccess item = share.createPathForItem("it_must_not_exist.txt");
318+ QFileInfo diskFileInfo(item.diskPathname);
319+ QCOMPARE(diskFileInfo.exists(), false);
320+ qFile_size_for_disk = diskFileInfo.size();
321+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
322+ SmbLocationItemFile fileMustNotExist(item.smbUrl);
323+ QCOMPARE(fileMustNotExist.size(), qFile_size_for_disk);
324+
325+ //positive tests
326+ diskFileInfo.setFile(share.fileContent.diskPathname);
327+ QCOMPARE(diskFileInfo.exists(), true);
328+ qFile_size_for_disk = diskFileInfo.size();
329+ QVERIFY(qFile_size_for_disk > 0);
330+ SmbLocationItemFile existentFile(share.fileContent.smbUrl);
331+ //first time the file is closed
332+ QCOMPARE(existentFile.size(), qFile_size_for_disk);
333+ QCOMPARE(existentFile.open(QFile::ReadOnly), true);
334+ //second time the file is opened
335+ QCOMPARE(existentFile.size(), qFile_size_for_disk);
336+ //now append data using local file system
337+ QFile moreDataFile(share.fileContent.diskPathname);
338+ QCOMPARE(moreDataFile.open(QFile::Append), true);
339+ QByteArray moreData("just a more bytes");
340+ QCOMPARE(moreDataFile.write(moreData), (qint64)moreData.size());
341+ moreDataFile.close();
342+ //other QFileInfo object to get new information
343+ QFileInfo newDiskFileInfo(share.fileContent.diskPathname);
344+ QVERIFY(newDiskFileInfo.size() > qFile_size_for_disk); // has more data now
345+ QCOMPARE(existentFile.size(), newDiskFileInfo.size());
346+}
347+
348+
349+void TestQSambaSuite::unit_QFile_isOpen()
350+{
351+ ShareCreationStatus share(createTempShare("unit_QFile_isOpen"));
352+ if (share.tempDir)
353+ {
354+ share.tempDir->setAutoRemove(true);
355+ }
356+ QCOMPARE(share.status, true);
357+
358+ //negative tests
359+ SmbLocationItemFile fileNameEmptyDoesNotExist;
360+ QCOMPARE(fileNameEmptyDoesNotExist.isOpen(), false);
361+ SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
362+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
363+ SmbLocationItemFile fileMustNotExist(item.smbUrl);
364+ QCOMPARE(fileMustNotExist.isOpen(), false);
365+
366+ //positive tests
367+ SmbLocationDirIterator fileContentIterator(share.url, QDir::Files);
368+ QCOMPARE(fileContentIterator.hasNext(), true);
369+ fileContentIterator.next();
370+ DirItemInfo iteminfo = fileContentIterator.fileInfo();
371+ QCOMPARE(iteminfo.exists(), true);
372+ SmbLocationItemFile smbFile(iteminfo.urlPath());
373+ QCOMPARE(smbFile.isOpen(), false);
374+ QCOMPARE(smbFile.open(QFile::ReadOnly), true);
375+ QCOMPARE(smbFile.isOpen(), true);
376+}
377+
378+
379+void TestQSambaSuite::unit_QFile_permissions()
380+{
381+ ShareCreationStatus share(createTempShare("unit_QFile_permissions"));
382+ if (share.tempDir)
383+ {
384+ share.tempDir->setAutoRemove(true);
385+ }
386+ QCOMPARE(share.status, true);
387+
388+ //negative tests
389+ //empty objects
390+ QFile::Permissions qt_empty_permissions = QFileInfo().permissions();
391+ SmbLocationItemFile fileNameEmptyDoesNotExist;
392+ QCOMPARE(fileNameEmptyDoesNotExist.permissions(), qt_empty_permissions);
393+ //file does not exist
394+ SmbSharedPathAccess item = share.createPathForItem("it_must_not_exist.txt");
395+ QFileInfo diskFileInfo(item.diskPathname);
396+ QCOMPARE(diskFileInfo.exists() ,false);
397+ SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
398+ QCOMPARE(fileNameDoesNotExist.permissions(), qt_empty_permissions);
399+
400+ //positive test, change in the local disk , check for permission in Samba
401+ QFile::Permissions perm_readOnly = QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther | QFile::ReadUser;
402+
403+ QFileInfo diskExistentFile(share.fileContent.diskPathname);
404+ QCOMPARE(diskExistentFile.exists(), true);
405+ //first make sure permissions are different
406+ QVERIFY(diskExistentFile.permissions() != perm_readOnly);
407+ //set permission using file in the local file system
408+ QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, perm_readOnly), true);
409+ //check the permission in the local file system
410+ QTest::qWait(100);
411+ QFile::Permissions curr_permissions = QFile(share.fileContent.diskPathname).permissions();
412+ QCOMPARE(curr_permissions, perm_readOnly);
413+ //now the same permission must come using Samba
414+ SmbLocationItemFile smbExistentFile(share.fileContent.smbUrl);
415+ QFile::Permissions curr_smb_ermissions = smbExistentFile.permissions();
416+ QCOMPARE(curr_smb_ermissions, perm_readOnly);
417+}
418+
419+
420+void TestQSambaSuite::unit_QFile_setPermissions()
421+{
422+ ShareCreationStatus share(createTempShare("unit_QFile_setPermissions"));
423+ if (share.tempDir)
424+ {
425+ share.tempDir->setAutoRemove(true);
426+ }
427+ QCOMPARE(share.status, true);
428+
429+ //negative tests
430+ //empty objects
431+ QFile::Permissions qt_permissions = QFile::ReadOwner | QFile::ReadUser | QFile::WriteOwner | QFile::WriteUser;
432+ SmbLocationItemFile fileNameEmptyDoesNotExist;
433+ QCOMPARE(fileNameEmptyDoesNotExist.setPermissions(qt_permissions), false);
434+ //file does not exist
435+ SmbSharedPathAccess item = share.createPathForItem("it_must_not_exist.txt");
436+ QFileInfo diskFileInfo(item.diskPathname);
437+ QCOMPARE(diskFileInfo.exists() ,false);
438+ SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
439+ QCOMPARE(fileNameDoesNotExist.setPermissions(qt_permissions), false);
440+
441+ QCOMPARE(fileNameDoesNotExist.setPermissions(share.fileContent.smbUrl, qt_permissions), true);
442+ SmbLocationItemFile smbFile(share.fileContent.smbUrl);
443+ QCOMPARE(smbFile.setPermissions(qt_permissions), true);
444+}
445+
446+
447+void TestQSambaSuite::unit_QDir_exists()
448+{
449+ ShareCreationStatus share(createTempShare("unit_QDir_mkdir"));
450+ if (share.tempDir)
451+ {
452+ share.tempDir->setAutoRemove(true);
453+ }
454+ QCOMPARE(share.status, true);
455+
456+ //negative tests
457+ SmbLocationItemDir directoryEmptyName;
458+ QCOMPARE(directoryEmptyName.exists(), false);
459+ SmbSharedPathAccess item = share.createPathForItem("dirName");
460+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
461+ SmbLocationItemDir directoryDoesNotExist(item.smbUrl);
462+ QCOMPARE(directoryDoesNotExist.exists(), false);
463+
464+ //positve test
465+ //item.smbUrl does not exist, check above
466+ //create it in the disk
467+ QCOMPARE(QDir().mkpath(item.diskPathname), true);
468+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
469+ SmbLocationItemDir directoyExists(item.smbUrl);
470+ QCOMPARE(directoyExists.exists(), true);
471+}
472+
473+
474+
475+
476+void TestQSambaSuite::unit_QDir_mkdir()
477+{
478+ ShareCreationStatus share(createTempShare("unit_QDir_mkdir"));
479+ if (share.tempDir)
480+ {
481+ share.tempDir->setAutoRemove(true);
482+ }
483+ QCOMPARE(share.status, true);
484+
485+ //negative tests
486+ SmbLocationItemDir directoryDoesNotExist;
487+ QCOMPARE(directoryDoesNotExist.mkdir("relativeDir"), false);
488+ QCOMPARE(directoryDoesNotExist.mkdir("smb://localhost/share_does_not_exist"), false);
489+ QCOMPARE(directoryDoesNotExist.mkdir("smb://localhost/share_does_not_exist/invalid_share"), false);
490+
491+ //positive tests
492+
493+ //create relative directory
494+ QString relativeName("relativeDir");
495+ SmbSharedPathAccess item = share.createPathForItem(relativeName);
496+ SmbLocationItemDir testRelative(share.url);
497+ SmbItemInfo smbDirBeforeCreation(item.smbUrl);
498+ //make sure directory does not exist
499+ QCOMPARE(smbDirBeforeCreation.exists(), false);
500+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
501+ //create directory using Samba
502+ QCOMPARE(testRelative.mkdir(relativeName), true);
503+ //make sure it exists now
504+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
505+ SmbItemInfo smbDirAfterCreation(item.smbUrl);
506+ QCOMPARE(smbDirAfterCreation.exists(), true);
507+
508+ //directory already exists, should return true
509+ QCOMPARE(testRelative.mkdir(relativeName), true);
510+
511+ //mkdir using absolute path
512+ item = share.createPathForItem("using_absolute_path");
513+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
514+ SmbLocationItemDir testAbsoluteDir;
515+ QCOMPARE(testAbsoluteDir.mkdir(item.smbUrl), true);
516+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
517+}
518+
519+
520+
521+void TestQSambaSuite::unit_QDir_mkpath()
522+{
523+ ShareCreationStatus share(createTempShare("unit_QDir_mkpath"));
524+ if (share.tempDir)
525+ {
526+ share.tempDir->setAutoRemove(true);
527+ }
528+ QCOMPARE(share.status, true);
529+
530+ //create multiple paths
531+ QStringList paths("path1");
532+ paths.append("path2");
533+ paths.append("path3");
534+ //item will have smbUrl=smb://localhost/shareName/path1/path2/path3 and diskPathname=/tmp/tmpdir/path1/path2/path3
535+ //using absolute path
536+ SmbSharedPathAccess item = share.createPathForItems(paths);
537+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
538+ SmbLocationItemDir testAbsoluteDir;
539+ QCOMPARE(testAbsoluteDir.mkpath(item.smbUrl), true);
540+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
541+ //test when it already exists
542+ QCOMPARE(testAbsoluteDir.mkpath(item.smbUrl), true);
543+
544+ //relative paths
545+ paths.clear();
546+ paths.append("relative1");
547+ paths.append("relative2");
548+ item = share.createPathForItems(paths);
549+ SmbLocationItemDir relativeDir(share.url);
550+ QString multiplePaths = paths.join(QDir::separator());
551+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
552+ QCOMPARE(relativeDir.mkpath(multiplePaths), true);
553+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
554+}
555+
556+
557+
558+void TestQSambaSuite::unit_QDir_rmdir()
559+{
560+ ShareCreationStatus share(createTempShare("unit_QDir_rmdir"));
561+ if (share.tempDir)
562+ {
563+ share.tempDir->setAutoRemove(true);
564+ }
565+ QCOMPARE(share.status, true);
566+
567+ //negative tests
568+ SmbLocationItemDir directoryEmptyName;
569+ QCOMPARE(directoryEmptyName.rmdir("none"), false);
570+ QString dirName("dirName");
571+ SmbSharedPathAccess item = share.createPathForItem(dirName);
572+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
573+ SmbLocationItemDir directoryDoesNotExist(share.url);
574+ QCOMPARE(directoryDoesNotExist.rmdir(dirName), false);
575+
576+ //create a directory
577+ SmbLocationItemDir directory(share.url);
578+ //create using relative
579+ QCOMPARE(directory.mkdir(dirName), true);
580+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
581+ //remove the relative directory
582+ QCOMPARE(directory.rmdir(dirName), true);
583+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
584+ //create it again and now remove using absolute url
585+ QCOMPARE(directory.mkdir(dirName), true);
586+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
587+ SmbLocationItemDir emptyObject;
588+ QCOMPARE(emptyObject.rmdir(item.smbUrl), true);
589+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
590+}
591+
592+
593+void TestQSambaSuite::unit_QDirIterator_path()
594+{
595+ ShareCreationStatus share(createTempShare("unit_QDirIterator_path"));
596+ if (share.tempDir)
597+ {
598+ share.tempDir->setAutoRemove(true);
599+ }
600+ QCOMPARE(share.status, true);
601+ QStringList paths = QStringList() << "path1" << "anotherPath" << "testdir" << "passThru" << "haha";
602+ QStringList files = QStringList() << "text.txt" << "hiper.html" << "document.odf" << "spread.odx" << "tx.list";
603+
604+ QStringList curPath;
605+ for (int counter=0; counter < paths.count() && counter < files.count(); ++counter)
606+ {
607+ curPath.append(paths.at(counter));
608+ SmbSharedPathAccess item = share.createPathForItems(curPath);
609+ QCOMPARE(QDir().mkpath(item.diskPathname), true);
610+ QString fileFullPath = item.diskPathname + QDir::separator() + files.at(counter);
611+ QFile file(fileFullPath);
612+ QCOMPARE(file.open(QFile::WriteOnly), true);
613+ file.close();
614+ }
615+
616+ QDir::Filters dirFilter = QDir::NoDotAndDotDot;
617+ QDir::Filters moreFilter[] = { QDir::AllEntries, QDir::Hidden, QDir::System };
618+
619+ for (uint counter=0; counter < sizeof(moreFilter)/sizeof(moreFilter[0]); ++counter)
620+ {
621+ dirFilter |= moreFilter[counter];
622+ QDirIterator dirIterator(share.sharedDirPath, dirFilter, QDirIterator::Subdirectories);
623+ SmbLocationDirIterator smbIterator(share.url, dirFilter, QDirIterator::Subdirectories);
624+ QStringList listDir;
625+ QStringList listSmb;
626+ qDebug() << "\n=================";
627+ while (dirIterator.hasNext() && smbIterator.hasNext())
628+ {
629+ qDebug() << dirIterator.next() << smbIterator.next();
630+ listDir.append(dirIterator.fileName());
631+ listSmb.append(smbIterator.fileName());
632+ }
633+ QCOMPARE(listDir, listSmb);
634+ }
635+}
636+
637+
638+void TestQSambaSuite::positive_statvfs()
639+{
640+ ShareCreationStatus share(createTempShare("positive_statvfs"));
641+ if (share.tempDir)
642+ {
643+ share.tempDir->setAutoRemove(true);
644+ }
645+ QCOMPARE(share.status, true);
646+
647+ struct statvfs diskVfs;
648+ struct statvfs smbVfs;
649+ ::memset(&diskVfs, 0, sizeof(struct statvfs));
650+ ::memset(&smbVfs, 0, sizeof(struct statvfs));
651+
652+ //using a file that exists
653+ SmbUtil smb;
654+ QCOMPARE((int)smb.getStatvfsInfo(share.fileContent.smbUrl, &smbVfs), 0);
655+ QCOMPARE(::statvfs(share.fileContent.diskPathname.toLocal8Bit().constData(), &diskVfs), 0);
656+ QCOMPARE(smbVfs.f_blocks, diskVfs.f_blocks);
657+ QCOMPARE(smbVfs.f_ffree, diskVfs.f_ffree);
658+ QCOMPARE(smbVfs.f_files, diskVfs.f_files);
659+ QCOMPARE(smbVfs.f_bsize, diskVfs.f_bsize);
660+ QVERIFY( qAbs(smbVfs.f_bfree - diskVfs.f_bfree) < 10 );
661+
662+ //using a directory
663+ ::memset(&diskVfs, 0, sizeof(struct statvfs));
664+ ::memset(&smbVfs, 0, sizeof(struct statvfs));
665+ QCOMPARE((int)smb.getStatvfsInfo(share.url, &smbVfs), 0);
666+ QCOMPARE(::statvfs(share.sharedDirPath.toLocal8Bit().constData(), &diskVfs), 0);
667+ QCOMPARE(smbVfs.f_blocks, diskVfs.f_blocks);
668+ QCOMPARE(smbVfs.f_ffree, diskVfs.f_ffree);
669+ QCOMPARE(smbVfs.f_files, diskVfs.f_files);
670+ QCOMPARE(smbVfs.f_bsize, diskVfs.f_bsize);
671+ QVERIFY( qAbs(smbVfs.f_bfree - diskVfs.f_bfree) < 10 );
672+}
673
674=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h'
675--- src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h 2015-07-19 16:44:54 +0000
676+++ src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h 2015-07-19 16:44:54 +0000
677@@ -90,6 +90,29 @@
678 void negative_emptyItemInfo();
679 void negative_dirIterator();
680
681+private Q_SLOTS: //unit test for SmbLocationItemFile class
682+ void unit_QFile_rename();
683+ void unit_QFile_remove();
684+ void unit_QFile_open();
685+ void unit_QFile_read();
686+ void unit_QFile_write();
687+ void unit_QFile_atEnd();
688+ void unit_QFile_size();
689+ void unit_QFile_isOpen();
690+ void unit_QFile_setPermissions();
691+ void unit_QFile_permissions();
692+
693+private Q_SLOTS: //unit test for SmbLocationItemDir class
694+ void unit_QDir_exists();
695+ void unit_QDir_mkdir();
696+ void unit_QDir_mkpath();
697+ void unit_QDir_rmdir();
698+
699+private Q_SLOTS: //unit test for SmbLocationItemDirIterator class
700+ void unit_QDirIterator_path();
701+
702+private Q_SLOTS:
703+ void positive_statvfs();
704
705 protected:
706 QString createTempFile(const QString& path,

Subscribers

People subscribed via source and target branches