ubuntu-touch-coreapps-reviewers team mailing list archive
-
ubuntu-touch-coreapps-reviewers team
-
Mailing list archive
-
Message #03676
[Merge] lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-17 into lp:ubuntu-filemanager-app
Carlos Jose Mazieri has proposed merging lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-17 into lp:ubuntu-filemanager-app with lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-16 as a prerequisite.
Commit message:
Created Unit Tests for Samba Similar Qt Objects: SmbLocationItemFile, SmbLocationItemDir and SmbLocationItemDirIterator
Requested reviews:
Ubuntu File Manager Developers (ubuntu-filemanager-dev)
For more details, see:
https://code.launchpad.net/~carlos-mazieri/ubuntu-filemanager-app/samba-actions-17/+merge/265216
Created Unit Tests for Samba Similar Qt Objects in "qsambaclient" module.
--
Your team Ubuntu File Manager Developers is requested to review the proposed merge of lp:~carlos-mazieri/ubuntu-filemanager-app/samba-actions-17 into lp:ubuntu-filemanager-app.
=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp'
--- src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp 2015-07-19 16:44:54 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.cpp 2015-07-19 16:44:54 +0000
@@ -26,6 +26,8 @@
#include "locationurl.h"
#include "smbutil.h"
#include "smblocationdiriterator.h"
+#include "smblocationitemfile.h"
+#include "smblocationitemdir.h"
#include <sys/stat.h>
#include <errno.h>
@@ -726,3 +728,659 @@
}
return true;
}
+
+
+void TestQSambaSuite::unit_QFile_rename()
+{
+ ShareCreationStatus share(createTempShare("unit_QFile_rename"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ //empty object
+ SmbLocationItemFile fileNameEmptyDoesNotExist;
+ QString newName("this_was_renamed.txt");
+ QCOMPARE(fileNameEmptyDoesNotExist.rename(newName), false);
+ QCOMPARE(fileNameEmptyDoesNotExist.rename(QLatin1String(0), newName), false);
+ //orig file does not exist
+ QString nameDoesNotExist("_it_must_not_exist");
+ SmbSharedPathAccess item = share.createPathForItem(nameDoesNotExist);
+ QFileInfo diskFileContent(item.diskPathname);
+ QCOMPARE(diskFileContent.exists(), false);
+ SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
+ QCOMPARE(fileNameDoesNotExist.rename(newName), false);
+ QCOMPARE(fileNameDoesNotExist.rename(nameDoesNotExist, newName), false);
+
+ //positive tests
+ SmbSharedPathAccess newItem = share.createPathForItem(newName);
+ QFileInfo newFileInfo(newItem.diskPathname);
+ //make sure target does not exist
+ QCOMPARE(newFileInfo.exists(), false);
+ //now rename
+ SmbLocationItemFile fileNameExists(share.fileContent.smbUrl);
+ QCOMPARE(fileNameExists.rename(newItem.smbUrl), true);
+ //now target must exist in local file system
+ QCOMPARE(newFileInfo.exists(), true);
+ diskFileContent.setFile(share.fileContent.diskPathname);
+ //make sure orignal file no longer exist
+ QCOMPARE(diskFileContent.exists(), false);
+ //now back to original name using an empty object
+ SmbLocationItemFile empty;
+ QCOMPARE(empty.rename(newItem.smbUrl, share.fileContent.smbUrl), true);
+ //make sure orignal exists again
+ QCOMPARE(diskFileContent.exists(), true);
+}
+
+
+void TestQSambaSuite::unit_QFile_remove()
+{
+ ShareCreationStatus share(createTempShare("unit_QFile_remove"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ //empty object
+ SmbLocationItemFile fileNameEmptyDoesNotExist;
+ QCOMPARE(fileNameEmptyDoesNotExist.remove(), false);
+ //file name does not exist
+ SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
+ QCOMPARE(fileNameDoesNotExist.remove(), false);
+ QFileInfo diskFileInfo(share.fileContent.diskPathname);
+// //now try to remove a file which does not have write permission
+// QCOMPARE(diskFileInfo.exists(), true);
+// QFile::Permissions originalPermissions = diskFileInfo.permissions();
+// QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther), true);
+// SmbLocationItemFile existentFileButNoWritePermission(share.fileContent.smbUrl);
+// //remove must fail
+// QCOMPARE(existentFileButNoWritePermission.remove(), false);
+// QCOMPARE(errno, EPERM);
+// QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, originalPermissions), true);
+
+ //positive test, remove fileContent
+ SmbLocationItemFile existentFile(share.fileContent.smbUrl);
+ SmbItemInfo smbExistentItem(share.fileContent.smbUrl);
+ QCOMPARE(smbExistentItem.exists(), true);
+ QCOMPARE(existentFile.remove(), true);
+ SmbItemInfo smbItem(share.fileContent.smbUrl);
+ //samba url for this file must not exist
+ QCOMPARE(smbItem.exists(), false);
+ //now origin file in file system must no longer exist
+ QCOMPARE(diskFileInfo.exists(), false);
+}
+
+
+void TestQSambaSuite::unit_QFile_open()
+{
+ ShareCreationStatus share(createTempShare("unit_QFile_open"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ SmbLocationItemFile fileNameEmptyDoesNotExist;
+ QCOMPARE(fileNameEmptyDoesNotExist.open(QFile::WriteOnly), false);
+ SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
+ QCOMPARE(fileNameDoesNotExist.open(QFile::ReadOnly), false);
+
+ // ---- positive tests
+ //create a smb file using open
+ item = share.createPathForItem("now_it_must_be_created");
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ SmbLocationItemFile fileCreated(item.smbUrl);
+ QCOMPARE(fileCreated.open(QFile::WriteOnly), true);
+ if (QFileInfo(item.diskPathname).exists() == false)
+ {
+ fileCreated.close(); // force to close if necessary
+ }
+ QCOMPARE(fileCreated.isOpen(), true);
+ //now check in the local disk to see if it was really created
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
+ //as QFile it closes itself in the destructor
+}
+
+
+void TestQSambaSuite::unit_QFile_read()
+{
+ ShareCreationStatus share(createTempShare("unit_QFile_read"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ SmbLocationItemFile fileNameEmptyDoesNotExist;
+ char buffer[100];
+
+ //get Qt read return when there is no file
+ qint64 qt_read_no_file = QFile().read(buffer, sizeof(buffer));
+
+ QCOMPARE(fileNameEmptyDoesNotExist.read(buffer, sizeof(buffer)), qt_read_no_file);
+ SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ SmbLocationItemFile fileMustNotExist(item.smbUrl);
+ QCOMPARE(fileMustNotExist.read(buffer, sizeof(buffer)), qt_read_no_file);
+
+ //positive test
+ //create a file in the local folder which is shared by Samba
+ item = share.createPathForItem("created_in_the_disk.txt");
+ QFile inDisk(item.diskPathname);
+ QCOMPARE(inDisk.open(QFile::WriteOnly), true);
+ QByteArray diskContent("This a simple content used to test reading files from samba: ");
+ QByteArray initialDiskContent(diskContent);
+ QByteArray moreDiskContent(100, 'a');
+ diskContent += moreDiskContent;
+ QCOMPARE(inDisk.write(diskContent), (qint64)diskContent.size());
+ inDisk.close();
+ //now read from Samba
+ SmbLocationItemFile existentFile(item.smbUrl);
+ QCOMPARE(existentFile.open(QFile::ReadOnly), true);
+ char smbBuffer [diskContent.size() + 100];
+ //before first read
+ QCOMPARE(existentFile.atEnd(), false);
+ qint64 bytesRead = existentFile.read(smbBuffer, (qint64)initialDiskContent.size());
+ qint64 expectedRead = (qint64)initialDiskContent.size();
+ QCOMPARE(bytesRead, expectedRead);
+ QByteArray smbContent(smbBuffer,initialDiskContent.size());
+ //compare the intial content
+ QCOMPARE(smbContent, initialDiskContent);
+ //before second read
+ QCOMPARE(existentFile.atEnd(), false);
+ expectedRead = (qint64) (diskContent.size() - initialDiskContent.size());
+ //read remaining data in the file
+ bytesRead = existentFile.read(smbBuffer, expectedRead);
+ QCOMPARE(bytesRead, expectedRead);
+ QByteArray moreSmbContent(smbBuffer, expectedRead);
+ smbContent += moreSmbContent;
+ //now compare the whole content
+ QCOMPARE(smbContent, diskContent);
+ //now atEnd() must be true
+ QCOMPARE(existentFile.atEnd(), true);
+}
+
+
+void TestQSambaSuite::unit_QFile_write()
+{
+ ShareCreationStatus share(createTempShare("unit_QFile_write"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ SmbLocationItemFile fileNameEmptyDoesNotExist;
+ QByteArray someContent("This is a simple content\n");
+ //get Qt write return when there is no file
+ qint64 qt_write_no_file = QFile().write(someContent.constData(), (qint64)someContent.size());
+ QCOMPARE(fileNameEmptyDoesNotExist.write(someContent.constData(), (qint64)someContent.size()), qt_write_no_file);
+ SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ SmbLocationItemFile fileMustNotExist(item.smbUrl);
+ QCOMPARE(fileMustNotExist.write(someContent.constData(), (qint64)someContent.size()), qt_write_no_file);
+
+ //positive tests
+ //work with 2 items saving in Samba and saving in local file system
+ SmbSharedPathAccess items[2];
+ items[0] = share.createPathForItem("first_item.txt");
+ items[1] = share.createPathForItem("second_item.txt");
+ QByteArray content; // starts empty
+ QFile::OpenMode openMode = QFile::WriteOnly; //after first write it receives Append mode
+ const int diskIndex = 0;
+ const int smbindex = 1;
+ QByteArray savedContent;
+ for(int counter = 0; counter < 4; ++counter, content += someContent)
+ {
+ QFile diskFile(items[diskIndex].diskPathname);
+ SmbLocationItemFile smbFile(items[smbindex].smbUrl);
+ //open both files
+ QCOMPARE(diskFile.open(openMode), true);
+ QCOMPARE(smbFile.open(openMode), true);
+ //first write should return 0 as content is empty
+ qint64 toSave = content.size();
+ qint64 wrote = diskFile.write(content.constData(), toSave);
+ QCOMPARE(wrote, toSave);
+ wrote = smbFile.write(content.constData(), toSave);
+ QCOMPARE(wrote, toSave);
+ savedContent += content;
+ diskFile.close();
+ smbFile.close();
+ if (counter > 0)
+ {
+ openMode = QFile::Append;
+ }
+ }
+ //now check size and content
+ QFile diskFile(items[diskIndex].diskPathname);
+ SmbLocationItemFile smbFile(items[smbindex].smbUrl);
+ QCOMPARE(smbFile.size(), diskFile.size());
+ QCOMPARE(diskFile.open(QFile::ReadOnly), true);
+ QCOMPARE(smbFile.open(QFile::ReadOnly), true);
+ //read file from disk, check the content
+ char buffer [1024];
+ qint64 gotBytes = diskFile.read(buffer, sizeof(buffer));
+ QCOMPARE((qint64)savedContent.size(), gotBytes);
+ QByteArray otherContent(buffer, (int)gotBytes);
+ QCOMPARE(otherContent, savedContent);
+ //read SMB file from disk, check the content
+ gotBytes = smbFile.read(buffer, sizeof(buffer));
+ QCOMPARE((qint64)savedContent.size(), gotBytes);
+ otherContent.setRawData(buffer, (int)gotBytes);
+ QCOMPARE(otherContent, savedContent);
+}
+
+
+void TestQSambaSuite::unit_QFile_atEnd()
+{
+ ShareCreationStatus share(createTempShare("unit_QFile_atEnd"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ SmbLocationItemFile fileNameEmptyDoesNotExist;
+ QCOMPARE(fileNameEmptyDoesNotExist.atEnd(), true);
+ SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ SmbLocationItemFile fileMustNotExist(item.smbUrl);
+ QCOMPARE(fileMustNotExist.atEnd(), true);
+ QFileInfo fileContentInfo(share.fileContent.diskPathname);
+ QCOMPARE(fileContentInfo.exists(), true);
+ SmbLocationItemFile existentFile(share.fileContent.smbUrl);
+ //first at end when file is still closed
+ QCOMPARE(existentFile.atEnd(), true);
+ QCOMPARE(existentFile.open(QFile::ReadOnly), true);
+ char buffer [fileContentInfo.size()];
+ QCOMPARE(existentFile.read(buffer, (qint64)10), (qint64)10);
+ //file is opened and not at end
+ QCOMPARE(existentFile.atEnd(), false);
+ QVERIFY(existentFile.read(buffer, fileContentInfo.size()) > 0);
+ QCOMPARE(existentFile.atEnd(), true);
+}
+
+
+void TestQSambaSuite::unit_QFile_size()
+{
+ ShareCreationStatus share(createTempShare("unit_QFile_size"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ //empty objects
+ qint64 qFile_size_for_disk = QFileInfo().size();
+ SmbLocationItemFile fileNameEmptyDoesNotExist;
+ QCOMPARE(fileNameEmptyDoesNotExist.size(), qFile_size_for_disk);
+ //file does not exist
+ SmbSharedPathAccess item = share.createPathForItem("it_must_not_exist.txt");
+ QFileInfo diskFileInfo(item.diskPathname);
+ QCOMPARE(diskFileInfo.exists(), false);
+ qFile_size_for_disk = diskFileInfo.size();
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ SmbLocationItemFile fileMustNotExist(item.smbUrl);
+ QCOMPARE(fileMustNotExist.size(), qFile_size_for_disk);
+
+ //positive tests
+ diskFileInfo.setFile(share.fileContent.diskPathname);
+ QCOMPARE(diskFileInfo.exists(), true);
+ qFile_size_for_disk = diskFileInfo.size();
+ QVERIFY(qFile_size_for_disk > 0);
+ SmbLocationItemFile existentFile(share.fileContent.smbUrl);
+ //first time the file is closed
+ QCOMPARE(existentFile.size(), qFile_size_for_disk);
+ QCOMPARE(existentFile.open(QFile::ReadOnly), true);
+ //second time the file is opened
+ QCOMPARE(existentFile.size(), qFile_size_for_disk);
+ //now append data using local file system
+ QFile moreDataFile(share.fileContent.diskPathname);
+ QCOMPARE(moreDataFile.open(QFile::Append), true);
+ QByteArray moreData("just a more bytes");
+ QCOMPARE(moreDataFile.write(moreData), (qint64)moreData.size());
+ moreDataFile.close();
+ //other QFileInfo object to get new information
+ QFileInfo newDiskFileInfo(share.fileContent.diskPathname);
+ QVERIFY(newDiskFileInfo.size() > qFile_size_for_disk); // has more data now
+ QCOMPARE(existentFile.size(), newDiskFileInfo.size());
+}
+
+
+void TestQSambaSuite::unit_QFile_isOpen()
+{
+ ShareCreationStatus share(createTempShare("unit_QFile_isOpen"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ SmbLocationItemFile fileNameEmptyDoesNotExist;
+ QCOMPARE(fileNameEmptyDoesNotExist.isOpen(), false);
+ SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ SmbLocationItemFile fileMustNotExist(item.smbUrl);
+ QCOMPARE(fileMustNotExist.isOpen(), false);
+
+ //positive tests
+ SmbLocationDirIterator fileContentIterator(share.url, QDir::Files);
+ QCOMPARE(fileContentIterator.hasNext(), true);
+ fileContentIterator.next();
+ DirItemInfo iteminfo = fileContentIterator.fileInfo();
+ QCOMPARE(iteminfo.exists(), true);
+ SmbLocationItemFile smbFile(iteminfo.urlPath());
+ QCOMPARE(smbFile.isOpen(), false);
+ QCOMPARE(smbFile.open(QFile::ReadOnly), true);
+ QCOMPARE(smbFile.isOpen(), true);
+}
+
+
+void TestQSambaSuite::unit_QFile_permissions()
+{
+ ShareCreationStatus share(createTempShare("unit_QFile_permissions"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ //empty objects
+ QFile::Permissions qt_empty_permissions = QFileInfo().permissions();
+ SmbLocationItemFile fileNameEmptyDoesNotExist;
+ QCOMPARE(fileNameEmptyDoesNotExist.permissions(), qt_empty_permissions);
+ //file does not exist
+ SmbSharedPathAccess item = share.createPathForItem("it_must_not_exist.txt");
+ QFileInfo diskFileInfo(item.diskPathname);
+ QCOMPARE(diskFileInfo.exists() ,false);
+ SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
+ QCOMPARE(fileNameDoesNotExist.permissions(), qt_empty_permissions);
+
+ //positive test, change in the local disk , check for permission in Samba
+ QFile::Permissions perm_readOnly = QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther | QFile::ReadUser;
+
+ QFileInfo diskExistentFile(share.fileContent.diskPathname);
+ QCOMPARE(diskExistentFile.exists(), true);
+ //first make sure permissions are different
+ QVERIFY(diskExistentFile.permissions() != perm_readOnly);
+ //set permission using file in the local file system
+ QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, perm_readOnly), true);
+ //check the permission in the local file system
+ QTest::qWait(100);
+ QFile::Permissions curr_permissions = QFile(share.fileContent.diskPathname).permissions();
+ QCOMPARE(curr_permissions, perm_readOnly);
+ //now the same permission must come using Samba
+ SmbLocationItemFile smbExistentFile(share.fileContent.smbUrl);
+ QFile::Permissions curr_smb_ermissions = smbExistentFile.permissions();
+ QCOMPARE(curr_smb_ermissions, perm_readOnly);
+}
+
+
+void TestQSambaSuite::unit_QFile_setPermissions()
+{
+ ShareCreationStatus share(createTempShare("unit_QFile_setPermissions"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ //empty objects
+ QFile::Permissions qt_permissions = QFile::ReadOwner | QFile::ReadUser | QFile::WriteOwner | QFile::WriteUser;
+ SmbLocationItemFile fileNameEmptyDoesNotExist;
+ QCOMPARE(fileNameEmptyDoesNotExist.setPermissions(qt_permissions), false);
+ //file does not exist
+ SmbSharedPathAccess item = share.createPathForItem("it_must_not_exist.txt");
+ QFileInfo diskFileInfo(item.diskPathname);
+ QCOMPARE(diskFileInfo.exists() ,false);
+ SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
+ QCOMPARE(fileNameDoesNotExist.setPermissions(qt_permissions), false);
+
+ QCOMPARE(fileNameDoesNotExist.setPermissions(share.fileContent.smbUrl, qt_permissions), true);
+ SmbLocationItemFile smbFile(share.fileContent.smbUrl);
+ QCOMPARE(smbFile.setPermissions(qt_permissions), true);
+}
+
+
+void TestQSambaSuite::unit_QDir_exists()
+{
+ ShareCreationStatus share(createTempShare("unit_QDir_mkdir"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ SmbLocationItemDir directoryEmptyName;
+ QCOMPARE(directoryEmptyName.exists(), false);
+ SmbSharedPathAccess item = share.createPathForItem("dirName");
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ SmbLocationItemDir directoryDoesNotExist(item.smbUrl);
+ QCOMPARE(directoryDoesNotExist.exists(), false);
+
+ //positve test
+ //item.smbUrl does not exist, check above
+ //create it in the disk
+ QCOMPARE(QDir().mkpath(item.diskPathname), true);
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
+ SmbLocationItemDir directoyExists(item.smbUrl);
+ QCOMPARE(directoyExists.exists(), true);
+}
+
+
+
+
+void TestQSambaSuite::unit_QDir_mkdir()
+{
+ ShareCreationStatus share(createTempShare("unit_QDir_mkdir"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ SmbLocationItemDir directoryDoesNotExist;
+ QCOMPARE(directoryDoesNotExist.mkdir("relativeDir"), false);
+ QCOMPARE(directoryDoesNotExist.mkdir("smb://localhost/share_does_not_exist"), false);
+ QCOMPARE(directoryDoesNotExist.mkdir("smb://localhost/share_does_not_exist/invalid_share"), false);
+
+ //positive tests
+
+ //create relative directory
+ QString relativeName("relativeDir");
+ SmbSharedPathAccess item = share.createPathForItem(relativeName);
+ SmbLocationItemDir testRelative(share.url);
+ SmbItemInfo smbDirBeforeCreation(item.smbUrl);
+ //make sure directory does not exist
+ QCOMPARE(smbDirBeforeCreation.exists(), false);
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ //create directory using Samba
+ QCOMPARE(testRelative.mkdir(relativeName), true);
+ //make sure it exists now
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
+ SmbItemInfo smbDirAfterCreation(item.smbUrl);
+ QCOMPARE(smbDirAfterCreation.exists(), true);
+
+ //directory already exists, should return true
+ QCOMPARE(testRelative.mkdir(relativeName), true);
+
+ //mkdir using absolute path
+ item = share.createPathForItem("using_absolute_path");
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ SmbLocationItemDir testAbsoluteDir;
+ QCOMPARE(testAbsoluteDir.mkdir(item.smbUrl), true);
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
+}
+
+
+
+void TestQSambaSuite::unit_QDir_mkpath()
+{
+ ShareCreationStatus share(createTempShare("unit_QDir_mkpath"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //create multiple paths
+ QStringList paths("path1");
+ paths.append("path2");
+ paths.append("path3");
+ //item will have smbUrl=smb://localhost/shareName/path1/path2/path3 and diskPathname=/tmp/tmpdir/path1/path2/path3
+ //using absolute path
+ SmbSharedPathAccess item = share.createPathForItems(paths);
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ SmbLocationItemDir testAbsoluteDir;
+ QCOMPARE(testAbsoluteDir.mkpath(item.smbUrl), true);
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
+ //test when it already exists
+ QCOMPARE(testAbsoluteDir.mkpath(item.smbUrl), true);
+
+ //relative paths
+ paths.clear();
+ paths.append("relative1");
+ paths.append("relative2");
+ item = share.createPathForItems(paths);
+ SmbLocationItemDir relativeDir(share.url);
+ QString multiplePaths = paths.join(QDir::separator());
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ QCOMPARE(relativeDir.mkpath(multiplePaths), true);
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
+}
+
+
+
+void TestQSambaSuite::unit_QDir_rmdir()
+{
+ ShareCreationStatus share(createTempShare("unit_QDir_rmdir"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ //negative tests
+ SmbLocationItemDir directoryEmptyName;
+ QCOMPARE(directoryEmptyName.rmdir("none"), false);
+ QString dirName("dirName");
+ SmbSharedPathAccess item = share.createPathForItem(dirName);
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ SmbLocationItemDir directoryDoesNotExist(share.url);
+ QCOMPARE(directoryDoesNotExist.rmdir(dirName), false);
+
+ //create a directory
+ SmbLocationItemDir directory(share.url);
+ //create using relative
+ QCOMPARE(directory.mkdir(dirName), true);
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
+ //remove the relative directory
+ QCOMPARE(directory.rmdir(dirName), true);
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+ //create it again and now remove using absolute url
+ QCOMPARE(directory.mkdir(dirName), true);
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
+ SmbLocationItemDir emptyObject;
+ QCOMPARE(emptyObject.rmdir(item.smbUrl), true);
+ QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
+}
+
+
+void TestQSambaSuite::unit_QDirIterator_path()
+{
+ ShareCreationStatus share(createTempShare("unit_QDirIterator_path"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+ QStringList paths = QStringList() << "path1" << "anotherPath" << "testdir" << "passThru" << "haha";
+ QStringList files = QStringList() << "text.txt" << "hiper.html" << "document.odf" << "spread.odx" << "tx.list";
+
+ QStringList curPath;
+ for (int counter=0; counter < paths.count() && counter < files.count(); ++counter)
+ {
+ curPath.append(paths.at(counter));
+ SmbSharedPathAccess item = share.createPathForItems(curPath);
+ QCOMPARE(QDir().mkpath(item.diskPathname), true);
+ QString fileFullPath = item.diskPathname + QDir::separator() + files.at(counter);
+ QFile file(fileFullPath);
+ QCOMPARE(file.open(QFile::WriteOnly), true);
+ file.close();
+ }
+
+ QDir::Filters dirFilter = QDir::NoDotAndDotDot;
+ QDir::Filters moreFilter[] = { QDir::AllEntries, QDir::Hidden, QDir::System };
+
+ for (uint counter=0; counter < sizeof(moreFilter)/sizeof(moreFilter[0]); ++counter)
+ {
+ dirFilter |= moreFilter[counter];
+ QDirIterator dirIterator(share.sharedDirPath, dirFilter, QDirIterator::Subdirectories);
+ SmbLocationDirIterator smbIterator(share.url, dirFilter, QDirIterator::Subdirectories);
+ QStringList listDir;
+ QStringList listSmb;
+ qDebug() << "\n=================";
+ while (dirIterator.hasNext() && smbIterator.hasNext())
+ {
+ qDebug() << dirIterator.next() << smbIterator.next();
+ listDir.append(dirIterator.fileName());
+ listSmb.append(smbIterator.fileName());
+ }
+ QCOMPARE(listDir, listSmb);
+ }
+}
+
+
+void TestQSambaSuite::positive_statvfs()
+{
+ ShareCreationStatus share(createTempShare("positive_statvfs"));
+ if (share.tempDir)
+ {
+ share.tempDir->setAutoRemove(true);
+ }
+ QCOMPARE(share.status, true);
+
+ struct statvfs diskVfs;
+ struct statvfs smbVfs;
+ ::memset(&diskVfs, 0, sizeof(struct statvfs));
+ ::memset(&smbVfs, 0, sizeof(struct statvfs));
+
+ //using a file that exists
+ SmbUtil smb;
+ QCOMPARE((int)smb.getStatvfsInfo(share.fileContent.smbUrl, &smbVfs), 0);
+ QCOMPARE(::statvfs(share.fileContent.diskPathname.toLocal8Bit().constData(), &diskVfs), 0);
+ QCOMPARE(smbVfs.f_blocks, diskVfs.f_blocks);
+ QCOMPARE(smbVfs.f_ffree, diskVfs.f_ffree);
+ QCOMPARE(smbVfs.f_files, diskVfs.f_files);
+ QCOMPARE(smbVfs.f_bsize, diskVfs.f_bsize);
+ QVERIFY( qAbs(smbVfs.f_bfree - diskVfs.f_bfree) < 10 );
+
+ //using a directory
+ ::memset(&diskVfs, 0, sizeof(struct statvfs));
+ ::memset(&smbVfs, 0, sizeof(struct statvfs));
+ QCOMPARE((int)smb.getStatvfsInfo(share.url, &smbVfs), 0);
+ QCOMPARE(::statvfs(share.sharedDirPath.toLocal8Bit().constData(), &diskVfs), 0);
+ QCOMPARE(smbVfs.f_blocks, diskVfs.f_blocks);
+ QCOMPARE(smbVfs.f_ffree, diskVfs.f_ffree);
+ QCOMPARE(smbVfs.f_files, diskVfs.f_files);
+ QCOMPARE(smbVfs.f_bsize, diskVfs.f_bsize);
+ QVERIFY( qAbs(smbVfs.f_bfree - diskVfs.f_bfree) < 10 );
+}
=== modified file 'src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h'
--- src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h 2015-07-19 16:44:54 +0000
+++ src/plugin/folderlistmodel/smb/qsambaclient/test/testqsambasuite.h 2015-07-19 16:44:54 +0000
@@ -90,6 +90,29 @@
void negative_emptyItemInfo();
void negative_dirIterator();
+private Q_SLOTS: //unit test for SmbLocationItemFile class
+ void unit_QFile_rename();
+ void unit_QFile_remove();
+ void unit_QFile_open();
+ void unit_QFile_read();
+ void unit_QFile_write();
+ void unit_QFile_atEnd();
+ void unit_QFile_size();
+ void unit_QFile_isOpen();
+ void unit_QFile_setPermissions();
+ void unit_QFile_permissions();
+
+private Q_SLOTS: //unit test for SmbLocationItemDir class
+ void unit_QDir_exists();
+ void unit_QDir_mkdir();
+ void unit_QDir_mkpath();
+ void unit_QDir_rmdir();
+
+private Q_SLOTS: //unit test for SmbLocationItemDirIterator class
+ void unit_QDirIterator_path();
+
+private Q_SLOTS:
+ void positive_statvfs();
protected:
QString createTempFile(const QString& path,
Follow ups