1
/**************************************************************************
3
* Copyright 2014 Canonical Ltd.
4
* Copyright 2014 Carlos J Mazieri <carlos.mazieri@gmail.com>
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU Lesser General Public License as published by
8
* the Free Software Foundation; version 3.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU Lesser General Public License for more details.
15
* You should have received a copy of the GNU Lesser General Public License
16
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
* File: testqsambasuite.cpp
22
#include "testqsambasuite.h"
23
#include "smbusershare.h"
24
#include "smbiteminfo.h"
25
#include "smbplaces.h"
26
#include "locationurl.h"
28
#include "smblocationdiriterator.h"
29
#include "smblocationitemfile.h"
30
#include "smblocationitemdir.h"
36
#include <QTemporaryDir>
41
#define RETURN_SHARE_STATUS_WHEN_FALSE(x,y) if (! (x == y) ) { \
42
qDebug() << "ERROR:" << Q_FUNC_INFO << "line:" << __LINE__ << "compare failed"; \
46
ShareCreationStatus::ShareCreationStatus(const QString& dirNameMask) :
48
tempDir(new QTemporaryDir(QDir::tempPath() + QDir::separator() + dirNameMask))
50
sharedDirPath = tempDir->path();
53
ShareCreationStatus::ShareCreationStatus(const ShareCreationStatus & o)
59
ShareCreationStatus::~ShareCreationStatus()
68
ShareCreationStatus::operator=(const ShareCreationStatus & o)
70
ShareCreationStatus *other = const_cast<ShareCreationStatus*> (&o);
76
ShareCreationStatus::operator=(ShareCreationStatus & o)
79
sharedDirPath = o.sharedDirPath;
80
shareName = o.shareName;
81
fileContent.diskPathname = o.fileContent.diskPathname;
87
tempDir->setAutoRemove(true);
94
ShareCreationStatus::createPathForItem(const QString &item)
96
SmbSharedPathAccess pathItem;
97
pathItem.diskPathname = sharedDirPath + QLatin1Char('/') + item;
98
pathItem.smbUrl = url + QLatin1Char('/') + item;
103
ShareCreationStatus::createPathForItems(const QStringList &items)
105
SmbSharedPathAccess pathItem;
106
pathItem.diskPathname = sharedDirPath;
107
pathItem.smbUrl = url;
108
for (int counter=0; counter < items.count(); ++counter)
110
pathItem.diskPathname += QLatin1Char('/') + items.at(counter);
111
pathItem.smbUrl += QLatin1Char('/') + items.at(counter);
117
TestQSambaSuite::TestQSambaSuite(QObject *parent) :
119
,m_smbShares( new SmbPlaces() )
125
TestQSambaSuite::~TestQSambaSuite()
128
if (!m_curShareName.isEmpty())
130
SmbUserShare::removeShare(m_curShareName);
135
void TestQSambaSuite::initTestCase()
137
QCOMPARE(SmbUserShare::canCreateShares(), true);
138
m_curUmask = umask(0);
142
void TestQSambaSuite::cleanupTestCase()
148
void TestQSambaSuite::init()
150
m_curShareName.clear();
154
* \brief TestQSambaSuite::cleanup()
156
* It is called after every test case, removes the shared indicated by m_curShareName
157
* and checks if it was removed
160
void TestQSambaSuite::cleanup()
162
if (!m_curShareName.isEmpty())
164
SmbUserShare::removeShare(m_curShareName);
165
SmbUserShare::UserShareFile share = SmbUserShare::search(m_curShareName);
166
m_curShareName.clear();
167
QCOMPARE(share.exists() , false);
171
// ============== utils
174
* \brief TestQSambaSuite::createTempFile() creates a file \a name inside \a path
177
* \param content some content or nothing
179
* \return fullpath of the file if it was able to create
181
QString TestQSambaSuite::createTempFile(const QString &path,
183
const QByteArray &content)
187
QFile f( path + QDir::separator() + name );
188
if (f.open(QFile::WriteOnly))
190
if (f.write(content) == content.size())
201
* \brief TestQSambaSuite::existShare(0 checks is share name exist in a such list of shares
202
* \param sharesFullPathList someting like ("smb://localhost/samba-devel", "smb://localhost/mac-devel")
203
* \param shareName e.g. "samba-devel"
204
* \return true if exists
206
bool TestQSambaSuite::existsShare(const QStringList& sharesFullPathList, const QString &shareName)
209
int counter = sharesFullPathList.count();
212
if (sharesFullPathList.at(counter).contains(shareName))
222
ShareCreationStatus TestQSambaSuite::createTempShare(const QString &maskName,
227
ShareCreationStatus ret(maskName);
228
QTemporaryDir * shareDir = ret.tempDir;
229
RETURN_SHARE_STATUS_WHEN_FALSE(shareDir->isValid(), true);
231
m_curShareName = QFileInfo(shareDir->path()).fileName();
233
//put some content in it
234
QString fileContentName("somecontent.txt");
235
QString filename = createTempFile(shareDir->path(), fileContentName, "hello Samba");
236
RETURN_SHARE_STATUS_WHEN_FALSE(filename.isEmpty(), false);
238
//save current samba shares list
239
QStringList currentShares = m_smbShares->listPlacesSync();
241
//get the supposed share name that is going to be created
242
QString shareDirName = SmbUserShare::proposedName(shareDir->path());
243
ret.shareName = shareDirName;
245
//make sure shareDirName does not exist in the current samba share list
246
RETURN_SHARE_STATUS_WHEN_FALSE(shareDirName.isEmpty(), false);
247
RETURN_SHARE_STATUS_WHEN_FALSE(shareDirName, m_curShareName);
248
bool exists = existsShare(currentShares,shareDirName);
249
RETURN_SHARE_STATUS_WHEN_FALSE(exists, false);
251
//first remove the share if it already exists, perhaps due to a failure in a previous test
252
SmbUserShare::removeShare(shareDir->path());
254
bool created = SmbUserShare::createShareForFolder(shareDir->path(),
255
fullAccess ? SmbUserShare::ReadWrite : SmbUserShare::Readonly,
257
RETURN_SHARE_STATUS_WHEN_FALSE(created, true);
259
// now make sure the new share is created
260
QStringList moreOneShare = m_smbShares->listPlacesSync();
261
exists = existsShare(moreOneShare, shareDirName);
262
RETURN_SHARE_STATUS_WHEN_FALSE(exists, true);
267
//let the share be removed by its path instead of the name
268
m_curShareName = shareDir->path();
269
ret.url = LocationUrl::SmbURL + "localhost/" + ret.shareName;
270
ret.fileContent = ret.createPathForItem(fileContentName);
276
//================ test cases==================
277
void TestQSambaSuite::positive_createReadOnlyUserShare()
279
//create a directory to share its content
280
QTemporaryDir shareDir (QDir::tempPath() + QDir::separator() + "positive_createReadOnlyUserShare");
281
m_curShareName = QFileInfo(shareDir.path()).fileName();
282
QCOMPARE(shareDir.isValid(), true);
284
//put some content in it
285
QString filename = createTempFile(shareDir.path(), "sometext.xt", "hello Samba");
286
QCOMPARE(filename.isEmpty(), false);
288
//save current samba shares list
289
QStringList currentShares = m_smbShares->listPlacesSync();
290
qDebug() << "currentShares:" << currentShares;
292
//get the supposed share name that is going to be created
293
QString shareDirName = SmbUserShare::proposedName(shareDir.path());
295
//make sure shareDirName does not exist in the current samba share list
296
QCOMPARE(shareDirName.isEmpty(), false);
297
QCOMPARE(shareDirName, m_curShareName);
298
bool exists = existsShare(currentShares,shareDirName);
299
QCOMPARE(exists, false);
302
bool created = SmbUserShare::createShareForFolder(shareDir.path());
303
QCOMPARE(created, true);
305
// now make sure the new share is created
306
QStringList moreOneShare = m_smbShares->listPlacesSync();
307
exists = existsShare(moreOneShare, shareDirName);
308
qDebug() << "moreOneShare:" << moreOneShare;
309
QCOMPARE(exists, true);
312
SmbUserShare::Access readAccess = SmbUserShare::getEveryoneAccess(m_curShareName);
313
bool isReadOnlyAccess = readAccess == SmbUserShare::Readonly;
314
QCOMPARE(isReadOnlyAccess, true);
319
void TestQSambaSuite::positive_createFullAccessUserShare()
321
//create a directory to share its content
322
QTemporaryDir shareDir (QDir::tempPath() + QDir::separator() + "positive_createFullAccessUserShare");
323
m_curShareName = QFileInfo(shareDir.path()).fileName();
324
QCOMPARE(shareDir.isValid(), true);
326
//put some content in it
327
QString filename = createTempFile(shareDir.path(), "sometext.xt", "hello Samba");
328
QCOMPARE(filename.isEmpty(), false);
330
//save current samba shares list
331
QStringList currentShares = m_smbShares->listPlacesSync();
332
qDebug() << "currentShares:" << currentShares;
334
//get the supposed share name that is going to be created
335
QString shareDirName = SmbUserShare::proposedName(shareDir.path());
337
//make sure shareDirName does not exist in the current samba share list
338
QCOMPARE(shareDirName.isEmpty(), false);
339
QCOMPARE(shareDirName, m_curShareName);
340
bool exists = existsShare(currentShares,shareDirName);
341
QCOMPARE(exists, false);
344
bool created = SmbUserShare::createShareForFolder(shareDir.path(), SmbUserShare::ReadWrite);
345
QCOMPARE(created, true);
347
// now make sure the new share is created
348
QStringList moreOneShare = m_smbShares->listPlacesSync();
349
exists = existsShare(moreOneShare, shareDirName);
350
qDebug() << "moreOneShare:" << moreOneShare;
351
QCOMPARE(exists, true);
353
//using dir full path
354
SmbUserShare::Access readWrite = SmbUserShare::getEveryoneAccess(shareDir.path());
355
bool isReadOnlyAccess = readWrite == SmbUserShare::ReadWrite;
356
QCOMPARE(isReadOnlyAccess, true);
358
//let the share be removed by its path instead of the name
359
m_curShareName = shareDir.path();
363
void TestQSambaSuite::positive_itemInfoRoot()
365
SmbItemInfo root(LocationUrl::SmbURL);
366
QCOMPARE(root.isLocal() , false);
367
QCOMPARE(root.isHost(), false);
368
QCOMPARE(root.exists(), true);
369
QCOMPARE(root.isRelative(),false);
370
QCOMPARE(root.isAbsolute(), true);
371
QCOMPARE(root.isRoot(), true);
372
QCOMPARE(root.isSharedDir(), false);
373
QCOMPARE(root.isHost(), false);
374
QCOMPARE(root.isWorkGroup(), false);
375
QCOMPARE(root.isShare(), false);
376
QCOMPARE(root.absoluteFilePath(), LocationUrl::SmbURL);
377
QCOMPARE(root.fileName().isEmpty(), true);
378
QCOMPARE(root.absolutePath(), LocationUrl::SmbURL);
379
QCOMPARE(root.sharePath().isEmpty(), true);
383
void TestQSambaSuite::positive_itemInfoLocalHost()
385
SmbItemInfo localhost(LocationUrl::SmbURL + "localhost");
386
QCOMPARE(localhost.isLocal() , false);
387
QCOMPARE(localhost.isHost(), true);
388
QCOMPARE(localhost.exists(), true);
389
QCOMPARE(localhost.isRelative(),false);
390
QCOMPARE(localhost.isAbsolute(), true);
391
QCOMPARE(localhost.isRoot(), false);
392
QCOMPARE(localhost.isSharedDir(), false);
393
QCOMPARE(localhost.isWorkGroup(), false);
394
QCOMPARE(localhost.isShare(), false);
395
QCOMPARE(localhost.path(), LocationUrl::SmbURL);
396
QCOMPARE(localhost.filePath(), LocationUrl::SmbURL + "localhost");
397
QCOMPARE(localhost.absoluteFilePath(), LocationUrl::SmbURL + "localhost");
398
//for hosts sharePath() are the hostitself
399
QCOMPARE(localhost.sharePath(), localhost.absoluteFilePath());
403
void TestQSambaSuite::positive_itemInfoShare()
405
ShareCreationStatus share(createTempShare("positive_itemInfoShare"));
408
share.tempDir->setAutoRemove(true);
410
QCOMPARE(share.status, true);
411
QFileInfo file(share.fileContent.diskPathname);
412
QCOMPARE(file.exists(), true);
414
QString urlPath("smb://localhost/" + share.shareName);
415
//basic share/dir information
416
SmbItemInfo dirinfo(urlPath);
417
QCOMPARE(dirinfo.isLocal() , false);
418
QCOMPARE(dirinfo.isHost(), false);
419
QCOMPARE(dirinfo.exists(), true);
420
QCOMPARE(dirinfo.isRelative(),false);
421
QCOMPARE(dirinfo.isAbsolute(), true);
422
QCOMPARE(dirinfo.isDir(), true); // shares also are directories
423
QCOMPARE(dirinfo.isFile(), false);
424
QCOMPARE(dirinfo.isReadable(), true);
425
QCOMPARE(dirinfo.isWritable(), true);
426
QCOMPARE(dirinfo.isExecutable(), true);
427
QCOMPARE(dirinfo.isSelected(), false);
428
QCOMPARE(dirinfo.isSharedDir(), false);
429
QCOMPARE(dirinfo.isRoot(), false);
430
QCOMPARE(dirinfo.isHost(), false);
431
QCOMPARE(dirinfo.isWorkGroup(), false);
432
QCOMPARE(dirinfo.isShare(), true);
433
QCOMPARE(dirinfo.sharePath(), dirinfo.absoluteFilePath());
436
void TestQSambaSuite::positive_itemInfoCommonPermissions()
438
ShareCreationStatus share(createTempShare("iteminfoCommonPermission"));
441
share.tempDir->setAutoRemove(true);
443
QCOMPARE(share.status, true);
444
QFileInfo file(share.fileContent.diskPathname);
445
QCOMPARE(file.exists(), true);
447
//set a common permission to the file
448
QFile::Permissions myPermissions = QFile::ReadOwner | QFile::WriteOwner | QFile::ReadUser | QFile::WriteUser |
449
QFile::ReadGroup | QFile::ReadOther;
450
QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, myPermissions), true);
452
QString urlPath("smb://localhost/" + share.shareName);
453
QString url(urlPath + QDir::separator() + file.fileName());
454
//basic file information from share
455
SmbItemInfo fileinfo(url);
456
QCOMPARE(fileinfo.isLocal() , false);
457
QCOMPARE(fileinfo.isHost(), false);
458
QCOMPARE(fileinfo.exists(), true);
459
QCOMPARE(fileinfo.isRelative(),false);
460
QCOMPARE(fileinfo.isAbsolute(), true);
461
QCOMPARE(fileinfo.isDir(), false);
462
QCOMPARE(fileinfo.isFile(), true);
463
QCOMPARE(fileinfo.isReadable(), true);
464
QCOMPARE(fileinfo.isWritable(), true);
465
QCOMPARE(fileinfo.isExecutable(), false);
466
QCOMPARE(fileinfo.isSelected(), false);
467
QCOMPARE(fileinfo.isSharedDir(), false);
468
QCOMPARE(fileinfo.isRoot(), false);
469
QCOMPARE(fileinfo.isRemote(), true);
470
QCOMPARE(fileinfo.isSymLink(), false);
471
QCOMPARE(fileinfo.absolutePath(), urlPath);
472
QCOMPARE(fileinfo.filePath(), url);
473
QCOMPARE(fileinfo.fileName(), file.fileName());
474
QCOMPARE(fileinfo.absoluteFilePath(), url);
475
QCOMPARE(fileinfo.permissions(), myPermissions);
476
QCOMPARE(fileinfo.sharePath(), urlPath);
480
void TestQSambaSuite::negative_emptyItemInfo()
483
QCOMPARE(notSmb.isValid(), false);
484
QCOMPARE(notSmb.exists(), false);
485
QCOMPARE(notSmb.isHost(), false);
489
void TestQSambaSuite::negative_itemInfo()
491
SmbItemInfo notSmb("test://localhost");
492
QCOMPARE(notSmb.isValid(), false);
493
QCOMPARE(notSmb.exists(), false);
495
SmbItemInfo notHost("smb://__this_host_must_not_exist_");
496
QCOMPARE(notHost.isValid(), true);
497
QCOMPARE(notHost.exists(), false);
499
SmbItemInfo notShare("smb://localhost/__this_share_must_not_exist_");
500
QCOMPARE(notShare.isValid(), true);
501
QCOMPARE(notShare.exists(), false);
504
QStringList existentShares = shares.listPlacesSync();
505
if (existentShares.count() > 0)
507
SmbItemInfo parent(existentShares.at(0));
508
QCOMPARE(parent.isValid(), true);
509
QCOMPARE(parent.exists(), true);
510
// it may not have permission to access
511
if (parent.isReadable())
513
QCOMPARE(parent.isShare(), true);
514
SmbItemInfo dir(existentShares.at(0) +
516
"__this_dir_must_not_exist_");
517
QCOMPARE(dir.isValid(), true);
518
QCOMPARE(dir.exists(), false);
523
void TestQSambaSuite::negative_createShareDirDoesNotExist()
525
QDir d(QDir::homePath() + "___2323_hope_this_does_not_exist_");
528
d.setPath(d.path() + QChar('1'));
531
bool ret = SmbUserShare::createShareForFolder(d.path());
533
QCOMPARE(ret, false);
537
void TestQSambaSuite::negative_dirIterator()
539
SmbLocationDirIterator iterator1("Nome");
540
QCOMPARE(iterator1.hasNext() , false);
542
SmbLocationDirIterator iterator2("smb://localhost/_IT_MUST_NOT_EXIST_I_HOPE_");
543
QCOMPARE(iterator2.hasNext() , false);
547
void TestQSambaSuite::positive_dirIterator()
549
ShareCreationStatus share(createTempShare("positive_dirIterator"));
552
share.tempDir->setAutoRemove(true);
554
QCOMPARE(share.status, true);
555
QFileInfo file(share.fileContent.diskPathname);
556
QCOMPARE(file.exists(), true);
558
//create a second directory inside the temporary share
559
QString secondDirStr("secondDir");
560
QString secondElementPath = share.sharedDirPath + QDir::separator() + secondDirStr;
561
QCOMPARE(QDir().mkpath(secondElementPath), true);
563
//create a file inside secondElementPath
564
QString secondElementContent(secondElementPath + QDir::separator() + "test.readme");
565
QFile f(secondElementContent);
566
QCOMPARE(f.open(QFile::WriteOnly), true);
571
SmbLocationDirIterator tree(share.url, QDir::AllEntries, QDirIterator::Subdirectories);
572
for(counter=0; tree.hasNext() ; ++counter)
576
QCOMPARE(counter, 3);
579
QStringList nameFilter = QStringList() << "*.readme";
580
SmbLocationDirIterator onlyReadme(share.url, nameFilter,QDir::AllEntries, QDirIterator::Subdirectories);
581
for(counter=0; onlyReadme.hasNext() ; ++counter)
585
QCOMPARE(counter, 1);
588
SmbLocationDirIterator lowLevelIterator(share.url);
589
for(counter=0; lowLevelIterator.hasNext() ; ++counter)
591
lowLevelIterator.next();
593
QCOMPARE(counter, 2);
596
SmbLocationDirIterator lowLevelIterator2(share.url,QDir::AllEntries | QDir::Hidden);
597
for(counter=0; lowLevelIterator2.hasNext() ; ++counter)
599
lowLevelIterator2.next();
601
QCOMPARE(counter, 4);
605
SmbLocationDirIterator lowLevelIterator3(share.url,QDir::AllEntries | QDir::Hidden | QDir::NoDot);
606
for(counter=0; lowLevelIterator3.hasNext() ; ++counter)
608
lowLevelIterator3.next();
609
if (lowLevelIterator3.fileName() == "..")
614
QCOMPARE(counter, 3);
615
QCOMPARE(dotdot, true);
619
SmbLocationDirIterator lowLevelIterator4(share.url,QDir::AllEntries | QDir::Hidden | QDir::NoDotDot);
620
for(counter=0; lowLevelIterator4.hasNext() ; ++counter)
622
lowLevelIterator4.next();
623
if (lowLevelIterator4.fileName() == ".")
628
QCOMPARE(counter, 3);
631
bool secondDir = false;
632
SmbLocationDirIterator dirOnly(share.url,QDir::Dirs | QDir::NoDotAndDotDot);
633
for(counter=0; dirOnly.hasNext() ; ++counter)
636
if (dirOnly.fileName() == secondDirStr)
641
QCOMPARE(counter, 1);
642
QCOMPARE(secondDir, true);
644
bool fileContent = false;
645
SmbLocationDirIterator fileOnly(share.url,QDir::Files);
646
for(counter=0; fileOnly.hasNext() ; ++counter)
649
if (fileOnly.fileName() == QFileInfo(share.fileContent.diskPathname).fileName())
654
QCOMPARE(counter, 1);
655
QCOMPARE(fileContent, true);
660
* This is not a test case
662
* It intends to create a real user share in the local host
664
bool TestQSambaSuite::createPermanentShare(const QString &path, bool fullAccess)
666
SmbUserShare::Access access = fullAccess ? SmbUserShare::ReadWrite
667
: SmbUserShare::Readonly;
668
SmbUserShare::createShareForFolder(path, access);
669
SmbUserShare::UserShareFile ret = SmbUserShare::search(path);
675
* \brief TestQSambaSuite::openPermanenteShare()
677
* It is not a test case, just shows some information about an URL
682
bool TestQSambaSuite::openPermanenteShare(const QString &smb_path)
686
bool ok = smb.getStatInfo(smb_path, &st) != -1;
687
qDebug() << st.st_mode
699
* \brief TestQSambaSuite::listLocalhost()
701
* It is not a test case
703
bool TestQSambaSuite::listLocalhost()
705
QString smb_path("smb://localhost");
706
SmbLocationDirIterator listIterator(smb_path);
708
while (listIterator.hasNext())
710
shares.append(listIterator.next());
713
return shares.count() > 0 ? true : false;
717
bool TestQSambaSuite::listRecursive()
720
QStringList all = smb.listContent(LocationUrl::SmbURL, true);
721
if (all.count() == 0)
725
for (int counter=0 ; counter < all.count(); ++ counter)
727
qDebug() << all.at(counter);
733
void TestQSambaSuite::unit_QFile_rename()
735
ShareCreationStatus share(createTempShare("unit_QFile_rename"));
738
share.tempDir->setAutoRemove(true);
740
QCOMPARE(share.status, true);
744
SmbLocationItemFile fileNameEmptyDoesNotExist;
745
QString newName("this_was_renamed.txt");
746
QCOMPARE(fileNameEmptyDoesNotExist.rename(newName), false);
747
QCOMPARE(fileNameEmptyDoesNotExist.rename(QLatin1String(0), newName), false);
748
//orig file does not exist
749
QString nameDoesNotExist("_it_must_not_exist");
750
SmbSharedPathAccess item = share.createPathForItem(nameDoesNotExist);
751
QFileInfo diskFileContent(item.diskPathname);
752
QCOMPARE(diskFileContent.exists(), false);
753
SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
754
QCOMPARE(fileNameDoesNotExist.rename(newName), false);
755
QCOMPARE(fileNameDoesNotExist.rename(nameDoesNotExist, newName), false);
758
SmbSharedPathAccess newItem = share.createPathForItem(newName);
759
QFileInfo newFileInfo(newItem.diskPathname);
760
//make sure target does not exist
761
QCOMPARE(newFileInfo.exists(), false);
763
SmbLocationItemFile fileNameExists(share.fileContent.smbUrl);
764
QCOMPARE(fileNameExists.rename(newItem.smbUrl), true);
765
//now target must exist in local file system
766
QCOMPARE(newFileInfo.exists(), true);
767
diskFileContent.setFile(share.fileContent.diskPathname);
768
//make sure orignal file no longer exist
769
QCOMPARE(diskFileContent.exists(), false);
770
//now back to original name using an empty object
771
SmbLocationItemFile empty;
772
QCOMPARE(empty.rename(newItem.smbUrl, share.fileContent.smbUrl), true);
773
//make sure orignal exists again
774
QCOMPARE(diskFileContent.exists(), true);
778
void TestQSambaSuite::unit_QFile_remove()
780
ShareCreationStatus share(createTempShare("unit_QFile_remove"));
783
share.tempDir->setAutoRemove(true);
785
QCOMPARE(share.status, true);
789
SmbLocationItemFile fileNameEmptyDoesNotExist;
790
QCOMPARE(fileNameEmptyDoesNotExist.remove(), false);
791
//file name does not exist
792
SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
793
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
794
SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
795
QCOMPARE(fileNameDoesNotExist.remove(), false);
796
QFileInfo diskFileInfo(share.fileContent.diskPathname);
797
// //now try to remove a file which does not have write permission
798
// QCOMPARE(diskFileInfo.exists(), true);
799
// QFile::Permissions originalPermissions = diskFileInfo.permissions();
800
// QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther), true);
801
// SmbLocationItemFile existentFileButNoWritePermission(share.fileContent.smbUrl);
802
// //remove must fail
803
// QCOMPARE(existentFileButNoWritePermission.remove(), false);
804
// QCOMPARE(errno, EPERM);
805
// QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, originalPermissions), true);
807
//positive test, remove fileContent
808
SmbLocationItemFile existentFile(share.fileContent.smbUrl);
809
SmbItemInfo smbExistentItem(share.fileContent.smbUrl);
810
QCOMPARE(smbExistentItem.exists(), true);
811
QCOMPARE(existentFile.remove(), true);
812
SmbItemInfo smbItem(share.fileContent.smbUrl);
813
//samba url for this file must not exist
814
QCOMPARE(smbItem.exists(), false);
815
//now origin file in file system must no longer exist
816
QCOMPARE(diskFileInfo.exists(), false);
820
void TestQSambaSuite::unit_QFile_open()
822
ShareCreationStatus share(createTempShare("unit_QFile_open"));
825
share.tempDir->setAutoRemove(true);
827
QCOMPARE(share.status, true);
830
SmbLocationItemFile fileNameEmptyDoesNotExist;
831
QCOMPARE(fileNameEmptyDoesNotExist.open(QFile::WriteOnly), false);
832
SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
833
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
834
SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
835
QCOMPARE(fileNameDoesNotExist.open(QFile::ReadOnly), false);
837
// ---- positive tests
838
//create a smb file using open
839
item = share.createPathForItem("now_it_must_be_created");
840
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
841
SmbLocationItemFile fileCreated(item.smbUrl);
842
QCOMPARE(fileCreated.open(QFile::WriteOnly), true);
843
if (QFileInfo(item.diskPathname).exists() == false)
845
fileCreated.close(); // force to close if necessary
847
QCOMPARE(fileCreated.isOpen(), true);
848
//now check in the local disk to see if it was really created
849
QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
850
//as QFile it closes itself in the destructor
854
void TestQSambaSuite::unit_QFile_read()
856
ShareCreationStatus share(createTempShare("unit_QFile_read"));
859
share.tempDir->setAutoRemove(true);
861
QCOMPARE(share.status, true);
864
SmbLocationItemFile fileNameEmptyDoesNotExist;
867
//get Qt read return when there is no file
868
qint64 qt_read_no_file = QFile().read(buffer, sizeof(buffer));
870
QCOMPARE(fileNameEmptyDoesNotExist.read(buffer, sizeof(buffer)), qt_read_no_file);
871
SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
872
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
873
SmbLocationItemFile fileMustNotExist(item.smbUrl);
874
QCOMPARE(fileMustNotExist.read(buffer, sizeof(buffer)), qt_read_no_file);
877
//create a file in the local folder which is shared by Samba
878
item = share.createPathForItem("created_in_the_disk.txt");
879
QFile inDisk(item.diskPathname);
880
QCOMPARE(inDisk.open(QFile::WriteOnly), true);
881
QByteArray diskContent("This a simple content used to test reading files from samba: ");
882
QByteArray initialDiskContent(diskContent);
883
QByteArray moreDiskContent(100, 'a');
884
diskContent += moreDiskContent;
885
QCOMPARE(inDisk.write(diskContent), (qint64)diskContent.size());
887
//now read from Samba
888
SmbLocationItemFile existentFile(item.smbUrl);
889
QCOMPARE(existentFile.open(QFile::ReadOnly), true);
890
char smbBuffer [diskContent.size() + 100];
892
QCOMPARE(existentFile.atEnd(), false);
893
qint64 bytesRead = existentFile.read(smbBuffer, (qint64)initialDiskContent.size());
894
qint64 expectedRead = (qint64)initialDiskContent.size();
895
QCOMPARE(bytesRead, expectedRead);
896
QByteArray smbContent(smbBuffer,initialDiskContent.size());
897
//compare the intial content
898
QCOMPARE(smbContent, initialDiskContent);
900
QCOMPARE(existentFile.atEnd(), false);
901
expectedRead = (qint64) (diskContent.size() - initialDiskContent.size());
902
//read remaining data in the file
903
bytesRead = existentFile.read(smbBuffer, expectedRead);
904
QCOMPARE(bytesRead, expectedRead);
905
QByteArray moreSmbContent(smbBuffer, expectedRead);
906
smbContent += moreSmbContent;
907
//now compare the whole content
908
QCOMPARE(smbContent, diskContent);
909
//now atEnd() must be true
910
QCOMPARE(existentFile.atEnd(), true);
914
void TestQSambaSuite::unit_QFile_write()
916
ShareCreationStatus share(createTempShare("unit_QFile_write"));
919
share.tempDir->setAutoRemove(true);
921
QCOMPARE(share.status, true);
924
SmbLocationItemFile fileNameEmptyDoesNotExist;
925
QByteArray someContent("This is a simple content\n");
926
//get Qt write return when there is no file
927
qint64 qt_write_no_file = QFile().write(someContent.constData(), (qint64)someContent.size());
928
QCOMPARE(fileNameEmptyDoesNotExist.write(someContent.constData(), (qint64)someContent.size()), qt_write_no_file);
929
SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
930
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
931
SmbLocationItemFile fileMustNotExist(item.smbUrl);
932
QCOMPARE(fileMustNotExist.write(someContent.constData(), (qint64)someContent.size()), qt_write_no_file);
935
//work with 2 items saving in Samba and saving in local file system
936
SmbSharedPathAccess items[2];
937
items[0] = share.createPathForItem("first_item.txt");
938
items[1] = share.createPathForItem("second_item.txt");
939
QByteArray content; // starts empty
940
QFile::OpenMode openMode = QFile::WriteOnly; //after first write it receives Append mode
941
const int diskIndex = 0;
942
const int smbindex = 1;
943
QByteArray savedContent;
944
for(int counter = 0; counter < 4; ++counter, content += someContent)
946
QFile diskFile(items[diskIndex].diskPathname);
947
SmbLocationItemFile smbFile(items[smbindex].smbUrl);
949
QCOMPARE(diskFile.open(openMode), true);
950
QCOMPARE(smbFile.open(openMode), true);
951
//first write should return 0 as content is empty
952
qint64 toSave = content.size();
953
qint64 wrote = diskFile.write(content.constData(), toSave);
954
QCOMPARE(wrote, toSave);
955
wrote = smbFile.write(content.constData(), toSave);
956
QCOMPARE(wrote, toSave);
957
savedContent += content;
962
openMode = QFile::Append;
965
//now check size and content
966
QFile diskFile(items[diskIndex].diskPathname);
967
SmbLocationItemFile smbFile(items[smbindex].smbUrl);
968
QCOMPARE(smbFile.size(), diskFile.size());
969
QCOMPARE(diskFile.open(QFile::ReadOnly), true);
970
QCOMPARE(smbFile.open(QFile::ReadOnly), true);
971
//read file from disk, check the content
973
qint64 gotBytes = diskFile.read(buffer, sizeof(buffer));
974
QCOMPARE((qint64)savedContent.size(), gotBytes);
975
QByteArray otherContent(buffer, (int)gotBytes);
976
QCOMPARE(otherContent, savedContent);
977
//read SMB file from disk, check the content
978
gotBytes = smbFile.read(buffer, sizeof(buffer));
979
QCOMPARE((qint64)savedContent.size(), gotBytes);
980
otherContent.setRawData(buffer, (int)gotBytes);
981
QCOMPARE(otherContent, savedContent);
985
void TestQSambaSuite::unit_QFile_atEnd()
987
ShareCreationStatus share(createTempShare("unit_QFile_atEnd"));
990
share.tempDir->setAutoRemove(true);
992
QCOMPARE(share.status, true);
995
SmbLocationItemFile fileNameEmptyDoesNotExist;
996
QCOMPARE(fileNameEmptyDoesNotExist.atEnd(), true);
997
SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
998
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
999
SmbLocationItemFile fileMustNotExist(item.smbUrl);
1000
QCOMPARE(fileMustNotExist.atEnd(), true);
1001
QFileInfo fileContentInfo(share.fileContent.diskPathname);
1002
QCOMPARE(fileContentInfo.exists(), true);
1003
SmbLocationItemFile existentFile(share.fileContent.smbUrl);
1004
//first at end when file is still closed
1005
QCOMPARE(existentFile.atEnd(), true);
1006
QCOMPARE(existentFile.open(QFile::ReadOnly), true);
1007
char buffer [fileContentInfo.size()];
1008
QCOMPARE(existentFile.read(buffer, (qint64)10), (qint64)10);
1009
//file is opened and not at end
1010
QCOMPARE(existentFile.atEnd(), false);
1011
QVERIFY(existentFile.read(buffer, fileContentInfo.size()) > 0);
1012
QCOMPARE(existentFile.atEnd(), true);
1016
void TestQSambaSuite::unit_QFile_size()
1018
ShareCreationStatus share(createTempShare("unit_QFile_size"));
1021
share.tempDir->setAutoRemove(true);
1023
QCOMPARE(share.status, true);
1027
qint64 qFile_size_for_disk = QFileInfo().size();
1028
SmbLocationItemFile fileNameEmptyDoesNotExist;
1029
QCOMPARE(fileNameEmptyDoesNotExist.size(), qFile_size_for_disk);
1030
//file does not exist
1031
SmbSharedPathAccess item = share.createPathForItem("it_must_not_exist.txt");
1032
QFileInfo diskFileInfo(item.diskPathname);
1033
QCOMPARE(diskFileInfo.exists(), false);
1034
qFile_size_for_disk = diskFileInfo.size();
1035
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1036
SmbLocationItemFile fileMustNotExist(item.smbUrl);
1037
QCOMPARE(fileMustNotExist.size(), qFile_size_for_disk);
1040
diskFileInfo.setFile(share.fileContent.diskPathname);
1041
QCOMPARE(diskFileInfo.exists(), true);
1042
qFile_size_for_disk = diskFileInfo.size();
1043
QVERIFY(qFile_size_for_disk > 0);
1044
SmbLocationItemFile existentFile(share.fileContent.smbUrl);
1045
//first time the file is closed
1046
QCOMPARE(existentFile.size(), qFile_size_for_disk);
1047
QCOMPARE(existentFile.open(QFile::ReadOnly), true);
1048
//second time the file is opened
1049
QCOMPARE(existentFile.size(), qFile_size_for_disk);
1050
//now append data using local file system
1051
QFile moreDataFile(share.fileContent.diskPathname);
1052
QCOMPARE(moreDataFile.open(QFile::Append), true);
1053
QByteArray moreData("just a more bytes");
1054
QCOMPARE(moreDataFile.write(moreData), (qint64)moreData.size());
1055
moreDataFile.close();
1056
//other QFileInfo object to get new information
1057
QFileInfo newDiskFileInfo(share.fileContent.diskPathname);
1058
QVERIFY(newDiskFileInfo.size() > qFile_size_for_disk); // has more data now
1059
QCOMPARE(existentFile.size(), newDiskFileInfo.size());
1063
void TestQSambaSuite::unit_QFile_isOpen()
1065
ShareCreationStatus share(createTempShare("unit_QFile_isOpen"));
1068
share.tempDir->setAutoRemove(true);
1070
QCOMPARE(share.status, true);
1073
SmbLocationItemFile fileNameEmptyDoesNotExist;
1074
QCOMPARE(fileNameEmptyDoesNotExist.isOpen(), false);
1075
SmbSharedPathAccess item = share.createPathForItem("_it_must_not_exist");
1076
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1077
SmbLocationItemFile fileMustNotExist(item.smbUrl);
1078
QCOMPARE(fileMustNotExist.isOpen(), false);
1081
SmbLocationDirIterator fileContentIterator(share.url, QDir::Files);
1082
QCOMPARE(fileContentIterator.hasNext(), true);
1083
fileContentIterator.next();
1084
DirItemInfo iteminfo = fileContentIterator.fileInfo();
1085
QCOMPARE(iteminfo.exists(), true);
1086
SmbLocationItemFile smbFile(iteminfo.urlPath());
1087
QCOMPARE(smbFile.isOpen(), false);
1088
QCOMPARE(smbFile.open(QFile::ReadOnly), true);
1089
QCOMPARE(smbFile.isOpen(), true);
1093
void TestQSambaSuite::unit_QFile_permissions()
1095
ShareCreationStatus share(createTempShare("unit_QFile_permissions"));
1098
share.tempDir->setAutoRemove(true);
1100
QCOMPARE(share.status, true);
1104
QFile::Permissions qt_empty_permissions = QFileInfo().permissions();
1105
SmbLocationItemFile fileNameEmptyDoesNotExist;
1106
QCOMPARE(fileNameEmptyDoesNotExist.permissions(), qt_empty_permissions);
1107
//file does not exist
1108
SmbSharedPathAccess item = share.createPathForItem("it_must_not_exist.txt");
1109
QFileInfo diskFileInfo(item.diskPathname);
1110
QCOMPARE(diskFileInfo.exists() ,false);
1111
SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
1112
QCOMPARE(fileNameDoesNotExist.permissions(), qt_empty_permissions);
1114
//positive test, change in the local disk , check for permission in Samba
1115
QFile::Permissions perm_readOnly = QFile::ReadOwner | QFile::ReadGroup | QFile::ReadOther | QFile::ReadUser;
1117
QFileInfo diskExistentFile(share.fileContent.diskPathname);
1118
QCOMPARE(diskExistentFile.exists(), true);
1119
//first make sure permissions are different
1120
QVERIFY(diskExistentFile.permissions() != perm_readOnly);
1121
//set permission using file in the local file system
1122
QCOMPARE(QFile::setPermissions(share.fileContent.diskPathname, perm_readOnly), true);
1123
//check the permission in the local file system
1125
QFile::Permissions curr_permissions = QFile(share.fileContent.diskPathname).permissions();
1126
QCOMPARE(curr_permissions, perm_readOnly);
1127
//now the same permission must come using Samba
1128
SmbLocationItemFile smbExistentFile(share.fileContent.smbUrl);
1129
QFile::Permissions curr_smb_ermissions = smbExistentFile.permissions();
1130
QCOMPARE(curr_smb_ermissions, perm_readOnly);
1134
void TestQSambaSuite::unit_QFile_setPermissions()
1136
ShareCreationStatus share(createTempShare("unit_QFile_setPermissions"));
1139
share.tempDir->setAutoRemove(true);
1141
QCOMPARE(share.status, true);
1145
QFile::Permissions qt_permissions = QFile::ReadOwner | QFile::ReadUser | QFile::WriteOwner | QFile::WriteUser;
1146
SmbLocationItemFile fileNameEmptyDoesNotExist;
1147
QCOMPARE(fileNameEmptyDoesNotExist.setPermissions(qt_permissions), false);
1148
//file does not exist
1149
SmbSharedPathAccess item = share.createPathForItem("it_must_not_exist.txt");
1150
QFileInfo diskFileInfo(item.diskPathname);
1151
QCOMPARE(diskFileInfo.exists() ,false);
1152
SmbLocationItemFile fileNameDoesNotExist(item.smbUrl);
1153
QCOMPARE(fileNameDoesNotExist.setPermissions(qt_permissions), false);
1155
QCOMPARE(fileNameDoesNotExist.setPermissions(share.fileContent.smbUrl, qt_permissions), true);
1156
SmbLocationItemFile smbFile(share.fileContent.smbUrl);
1157
QCOMPARE(smbFile.setPermissions(qt_permissions), true);
1161
void TestQSambaSuite::unit_QDir_exists()
1163
ShareCreationStatus share(createTempShare("unit_QDir_mkdir"));
1166
share.tempDir->setAutoRemove(true);
1168
QCOMPARE(share.status, true);
1171
SmbLocationItemDir directoryEmptyName;
1172
QCOMPARE(directoryEmptyName.exists(), false);
1173
SmbSharedPathAccess item = share.createPathForItem("dirName");
1174
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1175
SmbLocationItemDir directoryDoesNotExist(item.smbUrl);
1176
QCOMPARE(directoryDoesNotExist.exists(), false);
1179
//item.smbUrl does not exist, check above
1180
//create it in the disk
1181
QCOMPARE(QDir().mkpath(item.diskPathname), true);
1182
QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1183
SmbLocationItemDir directoyExists(item.smbUrl);
1184
QCOMPARE(directoyExists.exists(), true);
1190
void TestQSambaSuite::unit_QDir_mkdir()
1192
ShareCreationStatus share(createTempShare("unit_QDir_mkdir"));
1195
share.tempDir->setAutoRemove(true);
1197
QCOMPARE(share.status, true);
1200
SmbLocationItemDir directoryDoesNotExist;
1201
QCOMPARE(directoryDoesNotExist.mkdir("relativeDir"), false);
1202
QCOMPARE(directoryDoesNotExist.mkdir("smb://localhost/share_does_not_exist"), false);
1203
QCOMPARE(directoryDoesNotExist.mkdir("smb://localhost/share_does_not_exist/invalid_share"), false);
1207
//create relative directory
1208
QString relativeName("relativeDir");
1209
SmbSharedPathAccess item = share.createPathForItem(relativeName);
1210
SmbLocationItemDir testRelative(share.url);
1211
SmbItemInfo smbDirBeforeCreation(item.smbUrl);
1212
//make sure directory does not exist
1213
QCOMPARE(smbDirBeforeCreation.exists(), false);
1214
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1215
//create directory using Samba
1216
QCOMPARE(testRelative.mkdir(relativeName), true);
1217
//make sure it exists now
1218
QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1219
SmbItemInfo smbDirAfterCreation(item.smbUrl);
1220
QCOMPARE(smbDirAfterCreation.exists(), true);
1222
//directory already exists, should return true
1223
QCOMPARE(testRelative.mkdir(relativeName), true);
1225
//mkdir using absolute path
1226
item = share.createPathForItem("using_absolute_path");
1227
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1228
SmbLocationItemDir testAbsoluteDir;
1229
QCOMPARE(testAbsoluteDir.mkdir(item.smbUrl), true);
1230
QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1235
void TestQSambaSuite::unit_QDir_mkpath()
1237
ShareCreationStatus share(createTempShare("unit_QDir_mkpath"));
1240
share.tempDir->setAutoRemove(true);
1242
QCOMPARE(share.status, true);
1244
//create multiple paths
1245
QStringList paths("path1");
1246
paths.append("path2");
1247
paths.append("path3");
1248
//item will have smbUrl=smb://localhost/shareName/path1/path2/path3 and diskPathname=/tmp/tmpdir/path1/path2/path3
1249
//using absolute path
1250
SmbSharedPathAccess item = share.createPathForItems(paths);
1251
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1252
SmbLocationItemDir testAbsoluteDir;
1253
QCOMPARE(testAbsoluteDir.mkpath(item.smbUrl), true);
1254
QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1255
//test when it already exists
1256
QCOMPARE(testAbsoluteDir.mkpath(item.smbUrl), true);
1260
paths.append("relative1");
1261
paths.append("relative2");
1262
item = share.createPathForItems(paths);
1263
SmbLocationItemDir relativeDir(share.url);
1264
QString multiplePaths = paths.join(QDir::separator());
1265
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1266
QCOMPARE(relativeDir.mkpath(multiplePaths), true);
1267
QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1272
void TestQSambaSuite::unit_QDir_rmdir()
1274
ShareCreationStatus share(createTempShare("unit_QDir_rmdir"));
1277
share.tempDir->setAutoRemove(true);
1279
QCOMPARE(share.status, true);
1282
SmbLocationItemDir directoryEmptyName;
1283
QCOMPARE(directoryEmptyName.rmdir("none"), false);
1284
QString dirName("dirName");
1285
SmbSharedPathAccess item = share.createPathForItem(dirName);
1286
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1287
SmbLocationItemDir directoryDoesNotExist(share.url);
1288
QCOMPARE(directoryDoesNotExist.rmdir(dirName), false);
1290
//create a directory
1291
SmbLocationItemDir directory(share.url);
1292
//create using relative
1293
QCOMPARE(directory.mkdir(dirName), true);
1294
QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1295
//remove the relative directory
1296
QCOMPARE(directory.rmdir(dirName), true);
1297
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1298
//create it again and now remove using absolute url
1299
QCOMPARE(directory.mkdir(dirName), true);
1300
QCOMPARE(QFileInfo(item.diskPathname).exists(), true);
1301
SmbLocationItemDir emptyObject;
1302
QCOMPARE(emptyObject.rmdir(item.smbUrl), true);
1303
QCOMPARE(QFileInfo(item.diskPathname).exists(), false);
1307
void TestQSambaSuite::unit_QDirIterator_path()
1309
ShareCreationStatus share(createTempShare("unit_QDirIterator_path"));
1312
share.tempDir->setAutoRemove(true);
1314
QCOMPARE(share.status, true);
1315
QStringList paths = QStringList() << "path1" << "anotherPath" << "testdir" << "passThru" << "haha";
1316
QStringList files = QStringList() << "text.txt" << "hiper.html" << "document.odf" << "spread.odx" << "tx.list";
1318
QStringList curPath;
1319
for (int counter=0; counter < paths.count() && counter < files.count(); ++counter)
1321
curPath.append(paths.at(counter));
1322
SmbSharedPathAccess item = share.createPathForItems(curPath);
1323
QCOMPARE(QDir().mkpath(item.diskPathname), true);
1324
QString fileFullPath = item.diskPathname + QDir::separator() + files.at(counter);
1325
QFile file(fileFullPath);
1326
QCOMPARE(file.open(QFile::WriteOnly), true);
1330
QDir::Filters dirFilter = QDir::NoDotAndDotDot;
1331
QDir::Filters moreFilter[] = { QDir::AllEntries, QDir::Hidden, QDir::System };
1333
for (uint counter=0; counter < sizeof(moreFilter)/sizeof(moreFilter[0]); ++counter)
1335
dirFilter |= moreFilter[counter];
1336
QDirIterator dirIterator(share.sharedDirPath, dirFilter, QDirIterator::Subdirectories);
1337
SmbLocationDirIterator smbIterator(share.url, dirFilter, QDirIterator::Subdirectories);
1338
QStringList listDir;
1339
QStringList listSmb;
1340
qDebug() << "\n=================";
1341
while (dirIterator.hasNext() && smbIterator.hasNext())
1343
qDebug() << dirIterator.next() << smbIterator.next();
1344
listDir.append(dirIterator.fileName());
1345
listSmb.append(smbIterator.fileName());
1347
QCOMPARE(listDir, listSmb);
1352
void TestQSambaSuite::positive_statvfs()
1354
ShareCreationStatus share(createTempShare("positive_statvfs"));
1357
share.tempDir->setAutoRemove(true);
1359
QCOMPARE(share.status, true);
1361
struct statvfs diskVfs;
1362
struct statvfs smbVfs;
1363
::memset(&diskVfs, 0, sizeof(struct statvfs));
1364
::memset(&smbVfs, 0, sizeof(struct statvfs));
1366
//using a file that exists
1368
QCOMPARE((int)smb.getStatvfsInfo(share.fileContent.smbUrl, &smbVfs), 0);
1369
QCOMPARE(::statvfs(share.fileContent.diskPathname.toLocal8Bit().constData(), &diskVfs), 0);
1370
QCOMPARE(smbVfs.f_blocks, diskVfs.f_blocks);
1371
QCOMPARE(smbVfs.f_ffree, diskVfs.f_ffree);
1372
QCOMPARE(smbVfs.f_files, diskVfs.f_files);
1373
QCOMPARE(smbVfs.f_bsize, diskVfs.f_bsize);
1374
QVERIFY( qAbs(smbVfs.f_bfree - diskVfs.f_bfree) < 10 );
1377
::memset(&diskVfs, 0, sizeof(struct statvfs));
1378
::memset(&smbVfs, 0, sizeof(struct statvfs));
1379
QCOMPARE((int)smb.getStatvfsInfo(share.url, &smbVfs), 0);
1380
QCOMPARE(::statvfs(share.sharedDirPath.toLocal8Bit().constData(), &diskVfs), 0);
1381
QCOMPARE(smbVfs.f_blocks, diskVfs.f_blocks);
1382
QCOMPARE(smbVfs.f_ffree, diskVfs.f_ffree);
1383
QCOMPARE(smbVfs.f_files, diskVfs.f_files);
1384
QCOMPARE(smbVfs.f_bsize, diskVfs.f_bsize);
1385
QVERIFY( qAbs(smbVfs.f_bfree - diskVfs.f_bfree) < 10 );