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
=== modified file 'src/plugin/test_folderlistmodel/regression/tempfiles.cpp'
--- src/plugin/test_folderlistmodel/regression/tempfiles.cpp 2015-06-20 17:27:13 +0000
+++ src/plugin/test_folderlistmodel/regression/tempfiles.cpp 2015-07-19 17:07:33 +0000
@@ -37,8 +37,23 @@
3737
38bool TempFiles::addSubDirLevel(const QString &dir)38bool TempFiles::addSubDirLevel(const QString &dir)
39{39{
40 QFileInfo d( m_dir + QDir::separator() + QFileInfo(dir).fileName() );40 QFileInfo d;
41 if (d.exists() || QDir().mkpath(d.absoluteFilePath()))41 QFileInfo dirInfo(dir);
42 if (dirInfo.isRelative())
43 {
44 d.setFile(m_dir, dir); //append a single directory
45 }
46 else
47 {
48 d.setFile(dir); //use already made temp path
49 }
50 if (!d.exists() && QDir().mkpath(d.absoluteFilePath()))
51 {
52 QFile::setPermissions(d.absoluteFilePath(), QFile::WriteOwner | QFile::ReadOwner | QFile::ExeOwner
53 | QFile::WriteGroup | QFile::ReadGroup | QFile::ExeGroup
54 | QFile::WriteOther | QFile::ReadOther | QFile::ExeOther);
55 }
56 if (d.exists())
42 {57 {
43 m_dir = d.absoluteFilePath();58 m_dir = d.absoluteFilePath();
44 return true;59 return true;
@@ -163,6 +178,11 @@
163 totalFiles(0),178 totalFiles(0),
164 totalItems(0)179 totalItems(0)
165{180{
181 QFileInfo rootDirInfo(rootDir);
182 if (rootDirInfo.isAbsolute())
183 {
184 root = rootDir;
185 }
166 if (!rootDir.isEmpty())186 if (!rootDir.isEmpty())
167 {187 {
168 remove(); // clear188 remove(); // clear
@@ -200,6 +220,11 @@
200 {220 {
201 QString cmd("/bin/rm -rf " + root);221 QString cmd("/bin/rm -rf " + root);
202 ret = ::system(cmd.toLocal8Bit().constData()) == 0 ;222 ret = ::system(cmd.toLocal8Bit().constData()) == 0 ;
223 if (!ret)
224 {
225 qWarning("*** Could not remove %s, if it refers to Samba try to configure Samba using: 'force user' or 'create mask' plus 'directory mask'",
226 qPrintable(root));
227 }
203 }228 }
204 return ret;229 return ret;
205}230}
206231
=== modified file 'src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp'
--- src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp 2015-07-19 17:07:33 +0000
+++ src/plugin/test_folderlistmodel/regression/tst_folderlistmodel.cpp 2015-07-19 17:07:33 +0000
@@ -12,6 +12,7 @@
12#include "smbiteminfo.h"12#include "smbiteminfo.h"
13#include "testqsambasuite.h"13#include "testqsambasuite.h"
14#include "smbusershare.h"14#include "smbusershare.h"
15#include "smblocationitemfile.h"
1516
16#if defined(Q_OS_UNIX)17#if defined(Q_OS_UNIX)
17#include <stdio.h>18#include <stdio.h>
@@ -55,6 +56,7 @@
5556
56#define TIME_TO_PROCESS 230057#define TIME_TO_PROCESS 2300
57#define TIME_TO_REFRESH_DIR 9058#define TIME_TO_REFRESH_DIR 90
59#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
5860
59#if QT_VERSION >= 0x05000061#if QT_VERSION >= 0x050000
60#define QSKIP_ALL_TESTS(statement) QSKIP(statement)62#define QSKIP_ALL_TESTS(statement) QSKIP(statement)
@@ -62,6 +64,8 @@
62#define QSKIP_ALL_TESTS(statement) QSKIP(statement,SkipAll)64#define QSKIP_ALL_TESTS(statement) QSKIP(statement,SkipAll)
63#endif65#endif
6466
67#define CHECK_IF_CAN_CREATE_SHARES() if (!SmbUserShare::canCreateShares()) \
68 { qWarning() << Q_FUNC_INFO << "cannot be performed, it requires a Samba Server to create user shares"; return;}
6569
66QByteArray md5FromIcon(const QIcon& icon);70QByteArray md5FromIcon(const QIcon& icon);
67QString createFileInTempDir(const QString& name, const char *content, qint64 size);71QString createFileInTempDir(const QString& name, const char *content, qint64 size);
@@ -122,9 +126,7 @@
122 void diskCdIntoPathRelative();126 void diskCdIntoPathRelative();
123 void diskCdIntoPathAbsolute();127 void diskCdIntoPathAbsolute();
124 void trashCdIntoPathRelative();128 void trashCdIntoPathRelative();
125 void trashCdIntoPathAbsolute();129 void trashCdIntoPathAbsolute();
126 void smbCdIntoPathRelative();
127 void smbCdIntoPathAbsolute();
128 void fileIconProvider();130 void fileIconProvider();
129 void getThemeIcons();131 void getThemeIcons();
130#ifndef DO_NOT_USE_TAG_LIB132#ifndef DO_NOT_USE_TAG_LIB
@@ -161,6 +163,26 @@
161 void restoreTrashWithMultipleSources();163 void restoreTrashWithMultipleSources();
162 void emptyTrash();164 void emptyTrash();
163165
166// Samba test cases
167private Q_SLOTS:
168 void smbCdIntoPathRelative();
169 void smbCdIntoPathAbsolute();
170 //tests for high level helper functions
171 void smbExistsDir();
172 void smbCanReadDir();
173 void smbExistsFile();
174 void smbCanReadFile();
175 //common filemanager tests for Samba
176 void smbMkdir();
177 void smbMakeBackupNameForCurrentItem();
178 void smbCopyFromSmb2Smb();
179 void smbCopyFromSmb2LocalDisk();
180 void smbCopyFromLocalDisk2Smb();
181 void smbRemoveDirectory();
182 void smbCutFromSmb2Smb();
183 void smbCutFromSmb2LocalDisk();
184 void smbCutFromLocalDisk2Smb();
185
164private:186private:
165 bool createTempHomeTrashDir(const QString& existentDir);187 bool createTempHomeTrashDir(const QString& existentDir);
166 void initDeepDirs();188 void initDeepDirs();
@@ -168,7 +190,7 @@
168 void initModels();190 void initModels();
169 void cleanModels();191 void cleanModels();
170 bool compareDirectories(const QString& d1,192 bool compareDirectories(const QString& d1,
171 const QString& d2);193 const QString& d2, bool comparePermissions = true);
172194
173 bool createLink(const QString& fullSouce,195 bool createLink(const QString& fullSouce,
174 const QString& link,196 const QString& link,
@@ -313,7 +335,7 @@
313 return ret;335 return ret;
314}336}
315337
316bool TestDirModel::compareDirectories(const QString &d1, const QString &d2)338bool TestDirModel::compareDirectories(const QString &d1, const QString &d2, bool comparePermissions )
317{339{
318 QDirIterator d1Info(d1,340 QDirIterator d1Info(d1,
319 QDir::Files | QDir::Hidden | QDir::System,341 QDir::Files | QDir::Hidden | QDir::System,
@@ -337,7 +359,7 @@
337 << d2Info.fileName() << d2Info.size();359 << d2Info.fileName() << d2Info.size();
338 return false;360 return false;
339 }361 }
340 if (d1Info.fileInfo().permissions() != d2Info.permissions())362 if (comparePermissions && d1Info.fileInfo().permissions() != d2Info.permissions())
341 {363 {
342 qDebug() << "false permissions" << d1Info.fileName() << d2Info.fileName();364 qDebug() << "false permissions" << d1Info.fileName() << d2Info.fileName();
343 return false;365 return false;
@@ -1437,8 +1459,10 @@
1437 createTempHomeTrashDir(m_deepDir_01->path());1459 createTempHomeTrashDir(m_deepDir_01->path());
14381460
1439 QTrashDir tempTrash;1461 QTrashDir tempTrash;
1440 QCOMPARE(files.addSubDirLevel(tempTrash.homeTrash()), true);1462 QString homeTrashDir = tempTrash.homeTrash();
1441 QCOMPARE(files.addSubDirLevel(QTrashUtilInfo::filesTrashDir(tempTrash.homeTrash())), true);1463 QCOMPARE(files.addSubDirLevel(homeTrashDir), true);
1464 QString filesHomeTrashDir = QTrashUtilInfo::filesTrashDir(homeTrashDir);
1465 QCOMPARE(files.addSubDirLevel(filesHomeTrashDir), true);
14421466
1443 QString level1("Level1");1467 QString level1("Level1");
1444 QCOMPARE(files.addSubDirLevel(level1), true);1468 QCOMPARE(files.addSubDirLevel(level1), true);
@@ -1558,11 +1582,11 @@
1558 QCOMPARE(m_dirModel_01->canReadDir(orig), true);1582 QCOMPARE(m_dirModel_01->canReadDir(orig), true);
15591583
1560 //check permissions from canReadDir()1584 //check permissions from canReadDir()
1561 bool ok = QFile::setPermissions(m_deepDir_01->path(),1585 bool ok = QFile::setPermissions(m_deepDir_01->path(), QFileDevice::WriteOwner);
1562 QFileDevice::ReadOwner | QFileDevice::WriteOwner);
1563 QCOMPARE(ok, true);1586 QCOMPARE(ok, true);
1564 QCOMPARE(m_dirModel_01->existsDir(orig), true);1587 QCOMPARE(m_dirModel_01->existsDir(orig), true);
1565 QCOMPARE(m_dirModel_01->canReadDir(orig), false);1588 QCOMPARE(m_dirModel_01->canReadDir(orig), false);
1589 QFile::setPermissions(m_deepDir_01->path(), QFileDevice::ReadOwner | QFileDevice::WriteOwner);
15661590
1567 ok = QFile::setPermissions(m_deepDir_01->path(),1591 ok = QFile::setPermissions(m_deepDir_01->path(),
1568 QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner );1592 QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner );
@@ -2961,6 +2985,621 @@
2961 }2985 }
2962}2986}
29632987
2988/*!
2989 * \brief TestDirModel::smbExistsDir() Tests for DirModel::existsDir() regarding Samba
2990 */
2991void TestDirModel::smbExistsDir()
2992{
2993 CHECK_IF_CAN_CREATE_SHARES();
2994
2995 QString shareName("smbExistsDir");
2996 TestQSambaSuite smbTest(this);
2997 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
2998 if (tmpShare.tempDir)
2999 {
3000 tmpShare.tempDir->setAutoRemove(true);
3001 }
3002 QCOMPARE(tmpShare.status, true);
3003
3004 //create a folder inside this share
3005 QString folderName("folder");
3006 SmbSharedPathAccess folder = tmpShare.createPathForItem(folderName);
3007 QCOMPARE(QDir().mkpath(folder.diskPathname), true);
3008 QCOMPARE(QFileInfo(folder.diskPathname).exists(), true);
3009 //set file mananer to browse the temp share
3010 m_dirModel_01->setPath(tmpShare.url);
3011 QTest::qWait(TIME_TO_REFRESH_DIR);
3012 QCOMPARE(m_dirModel_01->rowCount() , 2); //temp shares are created with a file in it
3013 // check if the folder exists using relative name only
3014 QCOMPARE(m_dirModel_01->existsDir(folderName), true);
3015 // check it again using the full samba url
3016 QCOMPARE(m_dirModel_01->existsDir(folder.smbUrl), true);
3017 //negative tests
3018 // check for a relative folder that does not exist
3019 QString notExist("_I_Hope_it_does_not_exist");
3020 QCOMPARE(m_dirModel_01->existsDir(notExist), false);
3021 QString fullSmbUrl(tmpShare.url + QDir::separator() + notExist);
3022 QCOMPARE(m_dirModel_01->existsDir(fullSmbUrl), false);
3023}
3024
3025/*!
3026 * \brief TestDirModel::smbCanReadDir() Tests for DirModel::canReadDir() regading Samba
3027 */
3028void TestDirModel::smbCanReadDir()
3029{
3030 CHECK_IF_CAN_CREATE_SHARES();
3031
3032 QString shareName("smbCanReadDir");
3033 TestQSambaSuite smbTest(this);
3034 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3035 if (tmpShare.tempDir)
3036 {
3037 tmpShare.tempDir->setAutoRemove(true);
3038 }
3039 QCOMPARE(tmpShare.status, true);
3040
3041 //create a folder inside this share
3042 QString folderName("folder");
3043 SmbSharedPathAccess folder = tmpShare.createPathForItem(folderName);
3044 QCOMPARE(QDir().mkpath(folder.diskPathname), true);
3045 QCOMPARE(QFileInfo(folder.diskPathname).exists(), true);
3046 //set file mananer to browse the temp share
3047 m_dirModel_01->setPath(tmpShare.url);
3048 QTest::qWait(TIME_TO_REFRESH_DIR);
3049 QCOMPARE(m_dirModel_01->rowCount() , 2); //temp shares are created with a file in it
3050 QFile::Permissions folderOriginalPermissions = QFileInfo(folder.diskPathname).permissions();
3051 //first negative tests
3052 //change the permission to No Read
3053 bool ok = QFile::setPermissions(folder.diskPathname, QFile::WriteOwner | QFile::ExeOwner);
3054 QCOMPARE(ok, true);
3055 // check using relative name only
3056 QCOMPARE(m_dirModel_01->canReadDir(folderName), false);
3057 // check it again using the full samba url
3058 QCOMPARE(m_dirModel_01->canReadDir(folder.smbUrl), false);
3059 //negative tests
3060 // check for a relative folder that does not exist
3061 QString notExist("_I_Hope_it_does_not_exist");
3062 QCOMPARE(m_dirModel_01->canReadDir(notExist), false);
3063 QString fullSmbUrl(tmpShare.url + QDir::separator() + notExist);
3064 QCOMPARE(m_dirModel_01->canReadDir(fullSmbUrl), false);
3065 //now positive tests
3066 //give Read permission
3067 ok = QFile::setPermissions(folder.diskPathname, folderOriginalPermissions);
3068 QCOMPARE(ok, true);
3069 // check using relative name only
3070 QCOMPARE(m_dirModel_01->canReadDir(folderName), true);
3071 // check it again using the full samba url
3072 QCOMPARE(m_dirModel_01->canReadDir(folder.smbUrl), true);
3073}
3074
3075
3076/*!
3077 * \brief TestDirModel::smbExistsFile() Tests for DirModel::existsFile() regading Samba
3078 */
3079void TestDirModel::smbExistsFile()
3080{
3081 CHECK_IF_CAN_CREATE_SHARES();
3082
3083 QString shareName("smbExistsFile");
3084 TestQSambaSuite smbTest(this);
3085 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3086 if (tmpShare.tempDir)
3087 {
3088 tmpShare.tempDir->setAutoRemove(true);
3089 }
3090 QCOMPARE(tmpShare.status, true);
3091 //create a file inside this share
3092 QString fileName("fileTest.txt");
3093 SmbSharedPathAccess file = tmpShare.createPathForItem(fileName);
3094 QCOMPARE(QFileInfo(file.diskPathname).exists(), false);
3095 //set file mananer to browse the temp share
3096 m_dirModel_01->setPath(tmpShare.url);
3097 QTest::qWait(TIME_TO_REFRESH_DIR);
3098 QCOMPARE(m_dirModel_01->rowCount() , 1); //temp shares are created with a file in it
3099 //negative tests, file does not exist
3100 //using relative path
3101 QCOMPARE(m_dirModel_01->existsFile(fileName), false);
3102 //using absolute path
3103 QCOMPARE(m_dirModel_01->existsFile(file.smbUrl), false);
3104 //positive tests, file exists
3105 m_dirModel_01->goHome();
3106 QTest::qWait(TIME_TO_REFRESH_DIR);
3107 //now create the file
3108 QFile f(file.diskPathname);
3109 QCOMPARE(f.open(QFile::WriteOnly), true);
3110 f.close();
3111 //set file mananer to browse the temp share
3112 m_dirModel_01->setPath(tmpShare.url);
3113 QTest::qWait(TIME_TO_REFRESH_DIR);
3114 QCOMPARE(m_dirModel_01->rowCount() , 2); //temp shares are created with a file in it
3115 //using relative path
3116 QCOMPARE(m_dirModel_01->existsFile(fileName), true);
3117 //using absolute path
3118 QCOMPARE(m_dirModel_01->existsFile(file.smbUrl), true);
3119}
3120
3121
3122void TestDirModel::smbCanReadFile()
3123{
3124 CHECK_IF_CAN_CREATE_SHARES();
3125
3126 QString shareName("smbCanReadFile");
3127 TestQSambaSuite smbTest(this);
3128 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3129 if (tmpShare.tempDir)
3130 {
3131 tmpShare.tempDir->setAutoRemove(true);
3132 }
3133 QCOMPARE(tmpShare.status, true);
3134
3135 //create a file inside this share
3136 QString fileName("fileTest.txt");
3137 SmbSharedPathAccess file = tmpShare.createPathForItem(fileName);
3138 QFile f(file.diskPathname);
3139 QCOMPARE(f.open(QFile::WriteOnly), true);
3140 f.close();
3141 QCOMPARE(QFileInfo(file.diskPathname).exists(), true);
3142 //set file mananer to browse the temp share
3143 m_dirModel_01->setPath(tmpShare.url);
3144 QTest::qWait(TIME_TO_REFRESH_DIR);
3145 QCOMPARE(m_dirModel_01->rowCount() , 2); //temp shares are created with a file in it
3146 QFile::Permissions fileOriginalPermissions = QFileInfo(file.diskPathname).permissions();
3147 //first negative tests
3148 //change the permission to No Read
3149 bool ok = QFile::setPermissions(file.diskPathname, QFile::WriteOwner | QFile::ExeOwner);
3150 QCOMPARE(ok, true);
3151 // check using relative name only
3152 QCOMPARE(m_dirModel_01->canReadFile(fileName), false);
3153 // check it again using the full samba url
3154 QCOMPARE(m_dirModel_01->canReadFile(file.smbUrl), false);
3155 //negative tests
3156 // check for a relative folder that does not exist
3157 QString notExist("_I_Hope_it_does_not_exist");
3158 QCOMPARE(m_dirModel_01->canReadFile(notExist), false);
3159 QString fullSmbUrl(tmpShare.url + QDir::separator() + notExist);
3160 QCOMPARE(m_dirModel_01->canReadFile(fullSmbUrl), false);
3161 //now positive tests
3162 //give Read permission
3163 ok = QFile::setPermissions(file.diskPathname, fileOriginalPermissions);
3164 QCOMPARE(ok, true);
3165 // check using relative name only
3166 QCOMPARE(m_dirModel_01->canReadFile(fileName), true);
3167 // check it again using the full samba url
3168 QCOMPARE(m_dirModel_01->canReadFile(file.smbUrl), true);
3169}
3170
3171/*!
3172 * \brief TestDirModel::smbMkdir() Tests for DirModel::mkdir() regarding Samba
3173 */
3174void TestDirModel::smbMkdir()
3175{
3176 CHECK_IF_CAN_CREATE_SHARES();
3177
3178 QString shareName("smbMkdir");
3179 TestQSambaSuite smbTest(this);
3180 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3181 if (tmpShare.tempDir)
3182 {
3183 tmpShare.tempDir->setAutoRemove(true);
3184 }
3185 QCOMPARE(tmpShare.status, true);
3186 //set file mananer to browse the temp share
3187 m_dirModel_01->setPath(tmpShare.url);
3188 QTest::qWait(TIME_TO_REFRESH_DIR);
3189 QCOMPARE(m_dirModel_01->rowCount() , 1);
3190
3191 QString folder1Str("folder1");
3192 QString folder2Str("folder2");
3193 SmbSharedPathAccess folder1 = tmpShare.createPathForItem(folder1Str);
3194 SmbSharedPathAccess folder2 = tmpShare.createPathForItem(folder2Str);
3195 //using disk make sure folder1 does not exist
3196 QCOMPARE(QFileInfo(folder1.diskPathname).exists(), false);
3197 //create folder1 using relative path
3198 QCOMPARE(m_dirModel_01->mkdir(folder1Str), true);
3199 QTest::qWait(TIME_TO_REFRESH_DIR);
3200 QCOMPARE(m_dirModel_01->rowCount() , 2);
3201 QCOMPARE(QFileInfo(folder1.diskPathname).isDir(), true);
3202 //folder2 is created using full url
3203 QCOMPARE(QFileInfo(folder2.diskPathname).exists(), false);
3204 //create folder2 using full Samba URL
3205 QCOMPARE(m_dirModel_01->mkdir(folder2.smbUrl), true);
3206 QTest::qWait(TIME_TO_REFRESH_DIR);
3207 QCOMPARE(m_dirModel_01->rowCount() , 3);
3208 QCOMPARE(QFileInfo(folder2.diskPathname).isDir(), true);
3209 //check for full URL in the model items
3210 int counter = m_dirModel_01->rowCount() ;
3211 int found = 0; // look for folder1 and folder2 full url
3212 while (counter--)
3213 {
3214 const DirItemInfo & item = m_dirModel_01->mDirectoryContents[counter];
3215 if (item.urlPath() == folder1.smbUrl || item.urlPath() == folder2.smbUrl)
3216 {
3217 ++found;
3218 }
3219 }
3220 QCOMPARE(found, 2); //both folder1 and folder2 URLs are present
3221}
3222
3223/*!
3224 * \brief TestDirModel::smbMakeBackupNameForCurrentItem() Tests making backup of items using copy
3225 *
3226 * The similar test for item in local disk is modelCopyAndPasteToBackupFiles()
3227 */
3228void TestDirModel::smbMakeBackupNameForCurrentItem()
3229{
3230 CHECK_IF_CAN_CREATE_SHARES();
3231
3232 QString shareName("smbMakeBackupNameForCurrentItem");
3233 TestQSambaSuite smbTest(this);
3234 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3235 if (tmpShare.tempDir)
3236 {
3237 tmpShare.tempDir->setAutoRemove(true);
3238 }
3239 QCOMPARE(tmpShare.status, true);
3240 //set file mananer to browse the temp share
3241 m_dirModel_01->setPath(tmpShare.url);
3242 QTest::qWait(TIME_TO_REFRESH_DIR);
3243 QCOMPARE(m_dirModel_01->rowCount() , 1);
3244 //copy existent file in the Samba share, index 0 refers to tmpShare.fileContent.smbUrl
3245 m_dirModel_01->copyIndex(0);
3246 //pasting in the same directory must create item to Copy(1)
3247 m_dirModel_01->paste();
3248 QTest::qWait(TIME_TO_REFRESH_DIR);
3249 QCOMPARE(m_dirModel_01->rowCount() , 2);
3250 //pasting again must create item to Copy(2)
3251 m_dirModel_01->paste();
3252 QTest::qWait(TIME_TO_REFRESH_DIR);
3253 QCOMPARE(m_dirModel_01->rowCount() , 3);
3254 int counter = m_dirModel_01->rowCount() ;
3255 int found = 0;
3256 QFile fileContent(tmpShare.fileContent.diskPathname);
3257 QCOMPARE(fileContent.open(QFile::ReadOnly), true);
3258 QByteArray fileContentBytes(fileContent.readAll());
3259 fileContent.close();
3260 char smbBuffer [fileContentBytes.size()];
3261 qint64 size = (qint64)fileContentBytes.size();
3262 while (counter--)
3263 {
3264 const DirItemInfo & item = m_dirModel_01->mDirectoryContents[counter];
3265 //compare size content with the original file
3266 QCOMPARE(item.size(), size);
3267 SmbLocationItemFile smbFile(item.urlPath());
3268 QCOMPARE(smbFile.open(QFile::ReadOnly), true);
3269 QCOMPARE(smbFile.read(smbBuffer, size), size);
3270 smbFile.close();
3271 QByteArray smbContentBytes((const char*)&smbBuffer, fileContentBytes.size());
3272 //files must have the same content
3273 QCOMPARE(smbContentBytes, fileContentBytes);
3274 //look for backuped names
3275 if (item.urlPath().contains("Copy(1)") || item.urlPath().contains("Copy(2)"))
3276 {
3277 ++found;
3278 }
3279 }
3280 QCOMPARE(found, 2); //both backuped files were found
3281}
3282
3283/*!
3284 * \brief TestDirModel::smbCopyFromSmb2Smb()
3285 *
3286 * Creates a Samba Share in the local disk
3287 * Creates a directory tree with some files under smb://localhost/<tempShareName>/source
3288 * Copy its content to smb://localhost/<tempShareName>/target
3289 * Compares both directories using local disk correspondent path
3290 */
3291void TestDirModel::smbCopyFromSmb2Smb()
3292{
3293 CHECK_IF_CAN_CREATE_SHARES();
3294
3295 QString shareName("smbCopyFromSmb2Smb");
3296 TestQSambaSuite smbTest(this);
3297 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3298 if (tmpShare.tempDir)
3299 {
3300 tmpShare.tempDir->setAutoRemove(true);
3301 }
3302 QCOMPARE(tmpShare.status, true);
3303 QString sourceFolderName("source");
3304 QString targetFolderName("target");
3305 SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem(sourceFolderName);
3306 SmbSharedPathAccess targeFolder = tmpShare.createPathForItem(targetFolderName);
3307 //create a soruce directory tree in the share
3308 DeepDir sdir(sourceFolder.diskPathname, 3);
3309 //create the destination folder
3310 DeepDir tdir(targeFolder.diskPathname, 0); // 0 level, just create the root directory
3311 Q_UNUSED(sdir);
3312 Q_UNUSED(tdir);
3313 /*
3314 * set file mananer to browse the source directory using Samba url
3315 */
3316 m_dirModel_01->setPath(sourceFolder.smbUrl);
3317 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3318 QVERIFY(m_dirModel_01->rowCount() != 0);
3319 DirSelection *selection = m_dirModel_01->selectionObject();
3320 QVERIFY(selection != 0);
3321 selection->selectAll();
3322 QVERIFY(selection->counter() != 0);
3323 //copy the source folder using Samba URL
3324 m_dirModel_01->copySelection();
3325 //change directory to the target folder
3326 m_dirModel_01->setPath(targeFolder.smbUrl);
3327 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3328 QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
3329 m_dirModel_01->paste();
3330 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3331 QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
3332 //now compare directories source and target, permissions are not the same due to Samba Configuration
3333 QCOMPARE(compareDirectories(sourceFolder.diskPathname, targeFolder.diskPathname, false), true);
3334}
3335
3336
3337void TestDirModel::smbCopyFromSmb2LocalDisk()
3338{
3339 CHECK_IF_CAN_CREATE_SHARES();
3340
3341 QString shareName("smbCopyFromSmb2LocalDisk");
3342 TestQSambaSuite smbTest(this);
3343 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3344 if (tmpShare.tempDir)
3345 {
3346 tmpShare.tempDir->setAutoRemove(true);
3347 }
3348 QCOMPARE(tmpShare.status, true);
3349 QString sourceFolderName("source");
3350 QString targetFolderName("target");
3351 SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem(sourceFolderName);
3352 //create a soruce directory tree in the share
3353 DeepDir sdir(sourceFolder.diskPathname, 3);
3354 //create the destination folder in the /tmp
3355 DeepDir targetLocalDisk(targetFolderName, 0); // 0 level, just create the root directory
3356 Q_UNUSED(sdir);
3357 /*
3358 * set file mananer to browse the source directory using Samba url
3359 */
3360 m_dirModel_01->setPath(sourceFolder.smbUrl);
3361 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3362 QVERIFY(m_dirModel_01->rowCount() != 0);
3363 DirSelection *selection = m_dirModel_01->selectionObject();
3364 QVERIFY(selection != 0);
3365 selection->selectAll();
3366 QVERIFY(selection->counter() != 0);
3367 //copy the source folder using Samba URL
3368 m_dirModel_01->copySelection();
3369 //change directory to the target folder in the local disk
3370 m_dirModel_01->setPath(targetLocalDisk.path());
3371 QTest::qWait(TIME_TO_REFRESH_DIR);
3372 QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
3373 m_dirModel_01->paste();
3374 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3375 QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
3376 //now compare directories source and target, permissions are not the same due to Samba Configuration
3377 QCOMPARE(compareDirectories(sourceFolder.diskPathname, targetLocalDisk.path(), false), true);
3378}
3379
3380
3381void TestDirModel::smbCopyFromLocalDisk2Smb()
3382{
3383 CHECK_IF_CAN_CREATE_SHARES();
3384
3385 QString shareName("smbCopyFromLocalDisk2Smb");
3386 TestQSambaSuite smbTest(this);
3387 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3388 if (tmpShare.tempDir)
3389 {
3390 tmpShare.tempDir->setAutoRemove(true);
3391 }
3392 QCOMPARE(tmpShare.status, true);
3393 QString sourceFolderName("source");
3394 QString targetFolderName("target");
3395 SmbSharedPathAccess targeFolder = tmpShare.createPathForItem(targetFolderName);
3396 //create a soruce directory tree in /tmp
3397 DeepDir diskDir(sourceFolderName, 3);
3398 //create the destination folder in the share
3399 DeepDir tdir(targeFolder.diskPathname, 0); // 0 level, just create the root directory
3400 Q_UNUSED(tdir);
3401 /*
3402 * set file mananer to browse the source in the /tmp
3403 */
3404 m_dirModel_01->setPath(diskDir.path());
3405 QTest::qWait(TIME_TO_REFRESH_DIR);
3406 QVERIFY(m_dirModel_01->rowCount() != 0);
3407 DirSelection *selection = m_dirModel_01->selectionObject();
3408 QVERIFY(selection != 0);
3409 selection->selectAll();
3410 QVERIFY(selection->counter() != 0);
3411 //copy the source folder using file:// URLs
3412 m_dirModel_01->copySelection();
3413 //change directory to the target folder
3414 m_dirModel_01->setPath(targeFolder.smbUrl);
3415 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3416 QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
3417 m_dirModel_01->paste();
3418 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3419 QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
3420 //now compare directories source and target, permissions are not the same due to Samba Configuration
3421 QCOMPARE(compareDirectories(diskDir.path(), targeFolder.diskPathname, false), true);
3422}
3423
3424
3425void TestDirModel::smbRemoveDirectory()
3426{
3427 CHECK_IF_CAN_CREATE_SHARES();
3428
3429 QString shareName("smbRemoveDirectory");
3430 TestQSambaSuite smbTest(this);
3431 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3432 if (tmpShare.tempDir)
3433 {
3434 tmpShare.tempDir->setAutoRemove(true);
3435 }
3436 QCOMPARE(tmpShare.status, true);
3437 SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem("source");
3438 //create a directory tree with items in the local disk shared as Samba share
3439 DeepDir diskDir(sourceFolder.diskPathname, 3);
3440 Q_UNUSED(diskDir);
3441 /*
3442 * set file mananer to browse the source in the Samba share
3443 */
3444 m_dirModel_01->setPath(sourceFolder.smbUrl);
3445 QTest::qWait(TIME_TO_REFRESH_DIR);
3446 QVERIFY(m_dirModel_01->rowCount() != 0);
3447 DirSelection *selection = m_dirModel_01->selectionObject();
3448 QVERIFY(selection != 0);
3449 selection->selectAll();
3450 QVERIFY(selection->counter() != 0);
3451 m_dirModel_01->removeSelection();
3452 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3453 QCOMPARE(m_dirModel_01->rowCount() , 0); // now it is empty
3454}
3455
3456
3457void TestDirModel::smbCutFromSmb2Smb()
3458{
3459 CHECK_IF_CAN_CREATE_SHARES();
3460
3461 QString shareName("smbCutFromSmb2Smb");
3462 TestQSambaSuite smbTest(this);
3463 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3464 if (tmpShare.tempDir)
3465 {
3466 tmpShare.tempDir->setAutoRemove(true);
3467 }
3468 QCOMPARE(tmpShare.status, true);
3469 QString sourceFolderName("source");
3470 QString targetFolderName("target");
3471 SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem(sourceFolderName);
3472 SmbSharedPathAccess targeFolder = tmpShare.createPathForItem(targetFolderName);
3473 //create a soruce directory tree in the share
3474 DeepDir sdir(sourceFolder.diskPathname, 3);
3475 //create the destination folder
3476 DeepDir tdir(targeFolder.diskPathname, 0); // 0 level, just create the root directory
3477 Q_UNUSED(sdir);
3478 Q_UNUSED(tdir);
3479 /*
3480 * set file mananer to browse the source directory using Samba url
3481 */
3482 m_dirModel_01->setPath(sourceFolder.smbUrl);
3483 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3484 QVERIFY(m_dirModel_01->rowCount() != 0);
3485 DirSelection *selection = m_dirModel_01->selectionObject();
3486 QVERIFY(selection != 0);
3487 selection->selectAll();
3488 QVERIFY(selection->counter() != 0);
3489 //cut the source folder using Samba URL
3490 m_dirModel_01->cutSelection();
3491 //change directory to the target folder
3492 m_dirModel_01->setPath(targeFolder.smbUrl);
3493 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3494 QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
3495 //paste
3496 m_dirModel_01->paste();
3497 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3498 //check target directory is not empty
3499 QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
3500 //go back to the source samba url to make sure it is empty
3501 m_dirModel_01->setPath(sourceFolder.smbUrl);
3502 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3503 QCOMPARE(m_dirModel_01->rowCount(), 0);
3504}
3505
3506
3507void TestDirModel::smbCutFromSmb2LocalDisk()
3508{
3509 CHECK_IF_CAN_CREATE_SHARES();
3510
3511 QString shareName("smbCutFromSmb2LocalDisk");
3512 TestQSambaSuite smbTest(this);
3513 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3514 if (tmpShare.tempDir)
3515 {
3516 tmpShare.tempDir->setAutoRemove(true);
3517 }
3518 QCOMPARE(tmpShare.status, true);
3519 QString sourceFolderName("source");
3520 QString targetFolderName("diskTarget");
3521 SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem(sourceFolderName);
3522 //create a soruce directory tree in the share
3523 DeepDir sdir(sourceFolder.diskPathname, 3);
3524 //create the destination folder
3525 DeepDir diskTarget(targetFolderName, 0); // 0 level, just create the root directory
3526 Q_UNUSED(sdir);
3527 /*
3528 * set file mananer to browse the source directory using Samba url
3529 */
3530 m_dirModel_01->setPath(sourceFolder.smbUrl);
3531 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3532 QVERIFY(m_dirModel_01->rowCount() != 0);
3533 DirSelection *selection = m_dirModel_01->selectionObject();
3534 QVERIFY(selection != 0);
3535 selection->selectAll();
3536 QVERIFY(selection->counter() != 0);
3537 //cut the source folder using Samba URL
3538 m_dirModel_01->cutSelection();
3539 //change directory to the target folder in the local disk
3540 m_dirModel_01->setPath(diskTarget.path());
3541 QTest::qWait(TIME_TO_REFRESH_DIR);
3542 QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
3543 //paste
3544 m_dirModel_01->paste();
3545 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR); //removes from Samba, needs more time
3546 //check target directory is not empty
3547 QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
3548 //go back to the source samba url to make sure it is empty
3549 m_dirModel_01->setPath(sourceFolder.smbUrl);
3550 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3551 QCOMPARE(m_dirModel_01->rowCount(), 0);
3552}
3553
3554
3555void TestDirModel::smbCutFromLocalDisk2Smb()
3556{
3557 CHECK_IF_CAN_CREATE_SHARES();
3558
3559 QString shareName("smbCutFromLocalDisk2Smb");
3560 TestQSambaSuite smbTest(this);
3561 ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3562 if (tmpShare.tempDir)
3563 {
3564 tmpShare.tempDir->setAutoRemove(true);
3565 }
3566 QCOMPARE(tmpShare.status, true);
3567 QString sourceFolderName("source");
3568 QString targetFolderName("sambaTarget");
3569 SmbSharedPathAccess targetFolder = tmpShare.createPathForItem(targetFolderName);
3570 //create a soruce directory tree in the share
3571 DeepDir sdir(sourceFolderName, 3);
3572 //create the destination folder
3573 DeepDir smbTarget(targetFolder.diskPathname, 0); // 0 level, just create the root directory
3574 Q_UNUSED(smbTarget);
3575 /*
3576 * set file mananer to browse the source directory in the local disk
3577 */
3578 m_dirModel_01->setPath(sdir.path());
3579 QTest::qWait(TIME_TO_REFRESH_DIR);
3580 QVERIFY(m_dirModel_01->rowCount() != 0);
3581 DirSelection *selection = m_dirModel_01->selectionObject();
3582 QVERIFY(selection != 0);
3583 selection->selectAll();
3584 QVERIFY(selection->counter() != 0);
3585 //cut the source folder using local disk
3586 m_dirModel_01->cutSelection();
3587 //change directory to the target folder in Samba share
3588 m_dirModel_01->setPath(targetFolder.smbUrl);
3589 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3590 QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
3591 //paste
3592 m_dirModel_01->paste();
3593 QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3594 //check target directory is not empty
3595 QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
3596 //go back to the source local disk make sure it is empty
3597 m_dirModel_01->setPath(sdir.path());
3598 QTest::qWait(TIME_TO_REFRESH_DIR);
3599 QCOMPARE(m_dirModel_01->rowCount(), 0);
3600}
3601
3602
29643603
2965int main(int argc, char *argv[])3604int main(int argc, char *argv[])
2966{3605{
@@ -2981,9 +3620,16 @@
2981 //if not running specific tests, run Samba test suite3620 //if not running specific tests, run Samba test suite
2982 if (args.count() == 1)3621 if (args.count() == 1)
2983 {3622 {
2984 printf("\n********* Samba tests ********\n");3623 if (SmbUserShare::canCreateShares())
2985 TestQSambaSuite smbTest;3624 {
2986 ret |= QTest::qExec(&smbTest, args);3625 printf("\n********* Samba tests ********\n");
3626 TestQSambaSuite smbTest;
3627 ret |= QTest::qExec(&smbTest, args);
3628 }
3629 else
3630 {
3631 printf("\n\n********* Make sure Samba server is installed and up to run specific Samba tests ********\n");
3632 }
2987 }3633 }
2988 return ret;3634 return ret;
2989}3635}

Subscribers

People subscribed via source and target branches