1
#include "filesystemaction.h"
4
#include "externalfswatcher.h"
5
#include "dirselection.h"
8
#include "locationurl.h"
9
#include "locationsfactory.h"
10
#include "disklocation.h"
11
#include "qtrashutilinfo.h"
12
#include "smbiteminfo.h"
13
#include "testqsambasuite.h"
14
#include "smbusershare.h"
15
#include "smblocationitemfile.h"
17
#if defined(Q_OS_UNIX)
19
#include <sys/types.h>
24
#ifndef DO_NOT_USE_TAG_LIB
25
#include <taglib/attachedpictureframe.h>
26
#include <taglib/id3v2tag.h>
27
#include <taglib/fileref.h>
28
#include <taglib/mpegfile.h>
29
#include <taglib/tag.h>
30
#include <taglib/audioproperties.h>
33
#include <QApplication>
34
#include <QtCore/QString>
35
#include <QtTest/QtTest>
37
#include <QDirIterator>
40
#include <QFileIconProvider>
41
#include <QStandardPaths>
44
#include <QMimeDatabase>
45
#include <QCryptographicHash>
46
#include <QDesktopServices>
48
#include <QTemporaryDir>
49
#include <QTemporaryFile>
52
#include "testonly_pdf.h"
53
#include "sound_mp3.h"
54
#include "media_asx.h"
55
#include "media_xspf.h"
57
#define TIME_TO_PROCESS 2300
58
#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
61
#if QT_VERSION >= 0x050000
62
#define QSKIP_ALL_TESTS(statement) QSKIP(statement)
64
#define QSKIP_ALL_TESTS(statement) QSKIP(statement,SkipAll)
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;}
71
class FakeDirItemInfoBigSize: public DirItemInfo
74
FakeDirItemInfoBigSize(const DirItemInfo& original): DirItemInfo(original)
76
d_ptr->_size = 0x7fffffffffffffff; // higher qint64, 64 bits with huge size
81
QByteArray md5FromIcon(const QIcon& icon);
82
QString createFileInTempDir(const QString& name, const char *content, qint64 size);
84
class TestDirModel : public QObject
93
void slotFileAdded(const DirItemInfo& f) {m_filesAdded.append(f.absoluteFilePath()); }
94
void slotFileRemoved(const DirItemInfo& f) {m_filesRemoved.append(f.absoluteFilePath()); }
95
void slotPathChamged(QString path) { m_currentPath = path;}
96
void progress(int, int, int);
97
void slotRemoveFileWhenProgressArrive(int,int,int);
98
void cancel(int index, int, int percent);
99
void slotclipboardChanged();
100
void slotError(QString title, QString message);
101
void slotExtFsWatcherPathModified(const QString&) { ++m_extFSWatcherPathModifiedCounter; }
102
void slotSelectionChanged(int counter) { m_selectedItemsCounter = counter; }
103
void slotSelectionModeChanged(int m) { m_selectionMode = m;}
104
void onDownloadTemporaryComplete(const QString& name) {m_temporaryDownloadName = name;}
107
void initTestCase(); //before all tests
108
void cleanupTestCase(); //after all tests
109
void init(); //before every test
110
void cleanup(); //after every test
112
private Q_SLOTS: // test cases
113
void fsActionRemoveSingleFile();
114
void fsActionRemoveSingleDir();
115
void fsActionRemoveOneFileOneDir();
116
void fsActionRemoveTwoFilesTwoDirs();
117
void modelRemoveRecursiveDirByIndex();
118
void modelRemoveMultiItemsByFullPathname();
119
void modelRemoveMultiItemsByName();
120
void modelCopyDirPasteIntoAnotherModel();
121
void modelCopyManyItemsPasteIntoAnotherModel();
122
void modelCopyTwoEmptyFiles();
123
void modelCopyFileAndRemoveBeforePaste();
124
void modelCopyPasteFileAndRemoveWhenFirstProgressSignalArrives();
125
void modelCutManyItemsPasteIntoAnotherModel();
126
void fsActionMoveItemsForcingCopyAndThenRemove();
127
void modelCancelRemoveAction();
128
void modelTestFileSize();
129
void modelRemoveDirWithHiddenFilesAndLinks();
130
void modelCancelCopyAction();
131
void modelCopyPasteAndPasteAgain();
132
void modelCutPasteIntoExistentItems();
133
void modelCopyFileAndDirectoryLinks();
134
void modelCopyAndPaste3Times();
135
void modelCutAndPaste3Times();
136
void modelCutAndPasteInTheSamePlace();
137
void modelCopyAndPasteToBackupFiles();
138
void diskCdIntoPathRelative();
139
void diskCdIntoPathAbsolute();
140
void trashCdIntoPathRelative();
141
void trashCdIntoPathAbsolute();
142
void fileIconProvider();
143
void getThemeIcons();
144
#ifndef DO_NOT_USE_TAG_LIB
145
void verifyMP3Metadata();
147
void openPathAbsouluteAndRelative();
148
void existsDirAnCanReadDir();
149
void existsFileAndCanReadFile();
150
void pathProperties();
151
void watchExternalChanges();
152
void extFsWatcherChangePathManyTimesModifyAllPathsLessLast(); // no notification
153
void extFsWatcherModifySamePathManyTimesWithInInterval(); // just one notification
154
void extFsWatcherSetPathAndModifyManyTimesWithInInterval();// just one notification
155
void extFsWatcherChangePathManyTimesModifyManyTimes(); // many notifications
156
#if defined(Q_OS_UNIX)
157
void extFsWatcherNoticeChangesWithSameTimestamp();
160
//define TEST_OPENFILES to test QDesktopServices::openUrl() for some files
161
#if defined(TEST_OPENFILES)
167
void modelSingleSelection();
168
void modelMultiSelection();
169
void modelSelectionItemsRange();
171
void trashDiretories();
173
void locationFactory();
174
void moveOneFileToTrashAndRestore();
175
void restoreTrashWithMultipleSources();
180
void smbCdIntoPathRelative();
181
void smbCdIntoPathAbsolute();
182
//tests for high level helper functions
184
void smbCanReadDir();
185
void smbExistsFile();
186
void smbCanReadFile();
187
//common filemanager tests for Samba
189
void smbMakeBackupNameForCurrentItem();
190
void smbCopyFromSmb2Smb();
191
void smbCopyFromSmb2LocalDisk();
192
void smbCopyFromLocalDisk2Smb();
193
void smbRemoveDirectory();
194
void smbCutFromSmb2Smb();
195
void smbCutFromSmb2LocalDisk();
196
void smbCutFromLocalDisk2Smb();
198
private Q_SLOTS: // remote donwnload tests using samba
199
void smbDownloadEmptyFile();
200
void smbDownloadBigFileWithNoSpace();
201
void smbDownloadFile();
202
void smbDownloadAsTemporary();
203
void smbDownloadIntoStandardDownloadLocation();
207
bool createTempHomeTrashDir(const QString& existentDir);
209
void cleanDeepDirs();
212
bool compareDirectories(const QString& d1,
213
const QString& d2, bool comparePermissions = true);
215
bool createLink(const QString& fullSouce,
217
bool fullLink = false);
219
bool createFileAndCheckIfIconIsExclisive(const QString& termination,
220
const unsigned char *content,
224
FileSystemAction fsAction;
226
QStringList m_filesAdded;
227
QStringList m_filesRemoved;
229
DeepDir * m_deepDir_01;
230
DeepDir * m_deepDir_02;
231
DeepDir * m_deepDir_03;
233
DirModel * m_dirModel_01;
234
DirModel * m_dirModel_02;
236
int m_progressCounter;
237
int m_progressTotalItems;
238
int m_progressCurrentItem;
239
int m_progressPercentDone;
240
bool m_receivedClipboardChangesSignal;
241
bool m_receivedErrorSignal;
242
int m_progressNotificationsCounter;
243
bool m_visibleProgressMessages;
244
QHash<QByteArray, QString> m_md5IconsTable;
245
QFileIconProvider m_provider;
246
QString m_currentPath;
247
QString m_fileToRemoveInProgressSignal;
248
int m_extFSWatcherPathModifiedCounter;
249
int m_selectedItemsCounter;
251
QString m_temporaryDownloadName;
255
TestDirModel::TestDirModel() : fsAction(new LocationsFactory(this), this)
262
connect(&fsAction, SIGNAL(added(DirItemInfo)),
263
this, SLOT(slotFileAdded(DirItemInfo)));
264
connect(&fsAction, SIGNAL(removed(DirItemInfo)),
265
this, SLOT(slotFileRemoved(DirItemInfo)));
267
connect(&fsAction, SIGNAL(progress(int,int,int)),
268
this, SLOT(progress(int,int,int)));
271
void TestDirModel::progress(int cur, int total, int percent)
274
m_progressCurrentItem = cur;
275
m_progressTotalItems = total;
276
m_progressPercentDone = percent;
277
if (m_visibleProgressMessages)
280
p.sprintf("progress(cur=%d, total=%d, percent=%d)", cur,total,percent);
285
void TestDirModel::slotRemoveFileWhenProgressArrive(int cur, int total, int percent)
287
qDebug() << "removing file" << m_fileToRemoveInProgressSignal
288
<< "ret" << QFile::remove(m_fileToRemoveInProgressSignal);
289
progress(cur,total,percent);
292
bool TestDirModel::createLink(const QString &fullSouce, const QString &link, bool fullLink)
296
QFileInfo source(fullSouce);
302
ret = QFile::link(source.absoluteFilePath(), lnk.absoluteFilePath());
306
QString curDir = QDir::currentPath();
307
if (QDir::setCurrent(source.absolutePath()))
310
if (source.absolutePath() != lnk.absolutePath())
312
if (lnk.isAbsolute())
314
ret = QFile::link(source.absoluteFilePath(), link);
318
QDir relative(lnk.absolutePath());
319
if (relative.exists() || relative.mkpath(lnk.absolutePath()))
322
QStringList sourceDirs = source.absolutePath().
323
split(QDir::separator(), QString::SkipEmptyParts);
324
QStringList targetDirs = lnk.absolutePath().
325
split(QDir::separator(), QString::SkipEmptyParts);
326
while (diff < sourceDirs.count())
328
if (sourceDirs.at(diff) !=
335
QString relativePath = sourceDirs.at(diff);
336
QString gap(QLatin1String("..") + QDir::separator());
337
while (diff++ < targetDirs.count())
339
relativePath.prepend(gap);
341
ret = QFile::link(relativePath
350
ret = QFile::link(source.fileName(), link);
352
QDir::setCurrent(curDir);
359
bool TestDirModel::compareDirectories(const QString &d1, const QString &d2, bool comparePermissions )
361
QDirIterator d1Info(d1,
362
QDir::Files | QDir::Hidden | QDir::System,
363
QDirIterator::Subdirectories);
365
int len = d1.length();
367
while (d1Info.hasNext() && !d1Info.next().isEmpty())
369
QString target(d2 + d1Info.fileInfo().absoluteFilePath().mid(len));
371
QFileInfo d2Info(target);
372
if (d1Info.fileName() != d2Info.fileName())
374
qDebug() << "false name" << d1Info.fileName() << d2Info.fileName();
377
if (d1Info.fileInfo().size() != d2Info.size())
379
qDebug() << "false size" << d1Info.fileName() << d1Info.fileInfo().size()
380
<< d2Info.fileName() << d2Info.size();
383
if (comparePermissions && d1Info.fileInfo().permissions() != d2Info.permissions())
385
qDebug() << "false permissions" << d1Info.fileName() << d2Info.fileName();
393
void TestDirModel::cancel(int index, int, int percent)
395
DirModel * model = static_cast<DirModel*> (sender());
396
if (index > 1 || percent > 1)
398
model->cancelAction();
402
void TestDirModel::slotclipboardChanged()
404
m_receivedClipboardChangesSignal = true;
407
void TestDirModel::slotError(QString title, QString message)
409
qWarning("Received Error: [title: %s] [message: %s]", qPrintable(title), qPrintable(message));
410
m_receivedErrorSignal = true;
413
TestDirModel::~TestDirModel()
418
void TestDirModel::initDeepDirs()
424
void TestDirModel::cleanDeepDirs()
426
if (m_deepDir_01) delete m_deepDir_01;
427
if (m_deepDir_02) delete m_deepDir_02;
428
if (m_deepDir_03) delete m_deepDir_03;
435
void TestDirModel::initModels()
438
m_dirModel_01 = new DirModel();
439
m_dirModel_02 = new DirModel();
441
connect(m_dirModel_01->m_fsAction, SIGNAL(added(DirItemInfo)),
442
this, SLOT(slotFileAdded(DirItemInfo)));
443
connect(m_dirModel_01->m_fsAction, SIGNAL(removed(DirItemInfo)),
444
this, SLOT(slotFileRemoved(DirItemInfo)));
446
connect(m_dirModel_02->m_fsAction, SIGNAL(added(DirItemInfo)),
447
this, SLOT(slotFileAdded(DirItemInfo)));
448
connect(m_dirModel_02->m_fsAction, SIGNAL(removed(DirItemInfo)),
449
this, SLOT(slotFileRemoved(DirItemInfo)));
451
m_dirModel_01->setEnabledExternalFSWatcher(true);
452
m_dirModel_02->setEnabledExternalFSWatcher(true);
456
void TestDirModel::cleanModels()
458
if (m_dirModel_01) delete m_dirModel_01;
459
if (m_dirModel_02) delete m_dirModel_02;
464
void TestDirModel::initTestCase()
466
DirModel::registerMetaTypes();
470
void TestDirModel::cleanupTestCase()
477
void TestDirModel::init()
479
m_filesAdded.clear();
480
m_filesRemoved.clear();
483
m_progressCounter = 0;
484
m_progressTotalItems = 0;
485
m_progressCurrentItem = 0;
486
m_progressPercentDone = 0;
487
m_receivedClipboardChangesSignal = false;
488
m_receivedErrorSignal = false;
489
m_progressNotificationsCounter = 0;
490
m_visibleProgressMessages = false;
491
m_extFSWatcherPathModifiedCounter = 0;
492
m_selectedItemsCounter = 0;
493
m_selectionMode = -1;
498
void TestDirModel::cleanup()
502
m_filesAdded.clear();
503
m_filesRemoved.clear();
504
m_progressCounter = 0;
505
m_progressTotalItems = 0;
506
m_progressCurrentItem = 0;
507
m_progressPercentDone = 0;
508
m_receivedClipboardChangesSignal = false;
509
m_receivedErrorSignal = false;
510
m_fileToRemoveInProgressSignal.clear();
511
m_progressNotificationsCounter = 0;
512
m_visibleProgressMessages = false;
513
m_extFSWatcherPathModifiedCounter = 0;
514
m_selectedItemsCounter = 0;
515
m_selectionMode = -1;
519
void TestDirModel::fsActionRemoveSingleFile()
522
QCOMPARE(file.create("fsAtion_removeSingleFile") , true);
524
fsAction.remove(file.createdList());
525
QTest::qWait(TIME_TO_PROCESS);
526
QCOMPARE(m_filesRemoved.count() , 1);
528
QCOMPARE(m_filesRemoved.at(0), file.lastFileCreated());
529
QFileInfo now(file.lastFileCreated());
530
QCOMPARE(now.exists(), false);
535
void TestDirModel::fsActionRemoveSingleDir()
537
const int level = 10;
538
m_deepDir_01 = new DeepDir("removeSingleDir", level);
539
QCOMPARE( QFileInfo(m_deepDir_01->path()).exists(), true);
541
QStringList myDeepDir(m_deepDir_01->path());
542
fsAction.remove(myDeepDir);
543
QTest::qWait(TIME_TO_PROCESS);
545
QCOMPARE(m_filesRemoved.count() , 1);
546
QCOMPARE( QFileInfo(m_deepDir_01->path()).exists(), false);
547
QVERIFY(m_progressCounter > 2);
551
void TestDirModel::fsActionRemoveOneFileOneDir()
553
const int level = 10;
554
m_deepDir_01 = new DeepDir("removeSingleDir", level);
555
QCOMPARE( QFileInfo(m_deepDir_01->path()).exists(), true);
558
QCOMPARE(file.create("fsActionRemoveOneFileOneDir") , true);
560
QStringList twoItems(m_deepDir_01->path());
561
twoItems.append(file.lastFileCreated());
562
fsAction.remove(twoItems);
563
QTest::qWait(TIME_TO_PROCESS);
565
QCOMPARE(m_filesRemoved.count() , 2);
566
QCOMPARE( QFileInfo(m_deepDir_01->path()).exists(), false);
567
QCOMPARE(file.howManyExist(), 0);
568
QVERIFY(m_progressCounter > 2);
573
void TestDirModel::fsActionRemoveTwoFilesTwoDirs()
575
const int level = 12;
576
m_deepDir_01 = new DeepDir("fsActionRemoveTwoFilesTwoDirs_01", level);
577
QCOMPARE( QFileInfo(m_deepDir_01->path()).exists(), true);
579
m_deepDir_02 = new DeepDir("fsActionRemoveTwoFilesTwoDirs_02", level);
580
QCOMPARE( QFileInfo(m_deepDir_02->path()).exists(), true);
583
QCOMPARE(twoFiles.create(2) , true);
585
QStringList fourItems(m_deepDir_01->path());
586
fourItems.append(m_deepDir_02->path());
587
fourItems.append(twoFiles.createdList());
589
fsAction.remove(fourItems);
590
QTest::qWait(TIME_TO_PROCESS);
592
QCOMPARE(m_filesRemoved.count() , 4);
593
QCOMPARE(QFileInfo(m_deepDir_01->path()).exists(), false);
594
QCOMPARE(QFileInfo(m_deepDir_02->path()).exists(), false);
595
QCOMPARE(twoFiles.howManyExist(), 0);
596
QVERIFY(m_progressCounter > 2);
599
void TestDirModel::modelRemoveRecursiveDirByIndex()
602
m_deepDir_01 = new DeepDir("modelRemoveRecursiveDirByIndex", level);
603
QCOMPARE( QFileInfo(m_deepDir_01->path()).exists(), true);
605
m_dirModel_01->setPath(m_deepDir_01->path());
606
QTest::qWait(TIME_TO_REFRESH_DIR);
608
QCOMPARE(m_dirModel_01->rowCount(), 1);
609
m_dirModel_01->removeIndex(0);
612
QCOMPARE(m_filesRemoved.count() , 1);
613
QCOMPARE(m_dirModel_01->rowCount(), 0);
616
void TestDirModel::modelRemoveMultiItemsByFullPathname()
618
QString tmpDir("modelRemoveMultiItemsByFullPathame");
619
m_deepDir_01 = new DeepDir(tmpDir, 0);
620
QCOMPARE( QFileInfo(m_deepDir_01->path()).exists(), true);
622
const int filesToCreate = 2;
623
const int itemsToCreate = filesToCreate + 1;
626
files.addSubDirLevel(tmpDir);
627
files.create(filesToCreate);
629
QStringList items (files.createdList());
631
files.addSubDirLevel("subDir"); // + 1 item
633
items.append(files.lastPath());
635
connect(m_dirModel_01, SIGNAL(progress(int,int,int)),
636
this, SLOT(progress(int,int,int)));
637
m_dirModel_01->setPath(m_deepDir_01->path());
638
QTest::qWait(TIME_TO_REFRESH_DIR);
639
QCOMPARE(m_dirModel_01->rowCount(), itemsToCreate);
641
m_dirModel_01->rm(items);
642
int steps = m_dirModel_01->getProgressCounter();
645
QCOMPARE(m_filesRemoved.count() , itemsToCreate);
646
QCOMPARE(m_dirModel_01->rowCount(), 0);
647
QCOMPARE(files.howManyExist(), 0);
648
QCOMPARE(steps, m_progressCounter);
652
void TestDirModel::modelRemoveMultiItemsByName()
654
QString tmpDir("modelRemoveMultiItemsByName");
655
const int filesToCreate = 4;
658
files.addSubDirLevel(tmpDir);
660
QCOMPARE(files.howManyExist(), filesToCreate);
662
m_dirModel_01->setPath(files.lastPath());
663
QTest::qWait(TIME_TO_REFRESH_DIR);
665
QStringList items(files.createdNames());
666
m_dirModel_01->removePaths(items);
669
QCOMPARE(m_filesRemoved.count() , filesToCreate);
670
QCOMPARE(m_dirModel_01->rowCount(), 0);
671
QCOMPARE(files.howManyExist(), 0);
673
QDir().rmdir(m_dirModel_01->path());
677
void TestDirModel::modelCopyDirPasteIntoAnotherModel()
679
QString orig("modelCopyDirToAnotherModel_orig");
681
m_deepDir_01 = new DeepDir(orig, 1);
682
m_dirModel_01->setPath(m_deepDir_01->path());
683
connect(m_dirModel_01, SIGNAL(clipboardChanged()),
684
this, SLOT(slotclipboardChanged()));
685
QTest::qWait(TIME_TO_REFRESH_DIR);
686
QCOMPARE(m_dirModel_01->rowCount(), 1);
688
QString target("modelCopyDirToAnotherModel_target");
689
m_deepDir_02 = new DeepDir(target, 0);
690
connect(m_dirModel_02, SIGNAL(progress(int,int,int)),
691
this, SLOT(progress(int,int,int)));
692
m_dirModel_02->setPath(m_deepDir_02->path());
694
QTest::qWait(TIME_TO_REFRESH_DIR);
696
QCOMPARE( QFileInfo(m_deepDir_02->path()).exists(), true);
697
QCOMPARE(m_dirModel_02->rowCount(), 0);
699
m_dirModel_01->copyIndex(0);
700
m_visibleProgressMessages = true;
701
m_dirModel_02->paste();
702
int steps = m_dirModel_02->getProgressCounter();
703
QTest::qWait(TIME_TO_PROCESS);
705
QCOMPARE(m_dirModel_02->rowCount(), 1);
706
QCOMPARE(m_progressPercentDone, 100);
707
QCOMPARE(compareDirectories(m_deepDir_01->path(), m_deepDir_02->path()), true);
708
QCOMPARE(m_receivedClipboardChangesSignal, true);
709
QCOMPARE(steps, m_progressCounter);
713
void TestDirModel::modelCopyManyItemsPasteIntoAnotherModel()
715
QString orig("modelCopyManyItemstoAnotherModel_orig");
717
m_deepDir_01 = new DeepDir(orig, 5);
718
connect(m_dirModel_01, SIGNAL(clipboardChanged()),
719
this, SLOT(slotclipboardChanged()));
720
const int filesCreated = 10;
721
int itemsCreated = filesCreated + 1;
723
//create a big file to test copy loop
724
QByteArray buf(4096, 't');
725
QFile big(m_deepDir_01->path() + QDir::separator() + "big.txt");
726
QCOMPARE(big.open(QFile::WriteOnly), true);
727
for(int i=0; i < 106; i++)
729
int wrote = (int) big.write(buf);
730
QCOMPARE(wrote, buf.size());
731
buf += "sdfsdsedccw121222";
736
// create more temporary files
738
tempFiles.addSubDirLevel(orig);
739
tempFiles.create(filesCreated);
740
m_dirModel_01->setPath(m_deepDir_01->path());
741
QTest::qWait(TIME_TO_REFRESH_DIR);
742
QCOMPARE(m_dirModel_01->rowCount(), itemsCreated);
744
QString target("modelCopyManyItemstoAnotherModel_target");
745
m_deepDir_02 = new DeepDir(target, 0);
746
m_dirModel_02->setPath(m_deepDir_02->path());
747
connect(m_dirModel_02, SIGNAL(progress(int,int,int)),
748
this, SLOT(progress(int,int,int)));
749
QTest::qWait(TIME_TO_REFRESH_DIR);
751
QCOMPARE( QFileInfo(m_deepDir_02->path()).exists(), true);
752
QCOMPARE(m_dirModel_02->rowCount(), 0);
754
QStringList allFiles(m_deepDir_01->firstLevel());
755
allFiles.append(tempFiles.createdList());
756
allFiles.append(big.fileName());
758
m_dirModel_01->copyPaths(allFiles);
759
m_visibleProgressMessages = true;
760
m_dirModel_02->paste();
761
int steps = m_dirModel_02->m_fsAction->m_curAction->steps;
763
QTest::qWait(TIME_TO_PROCESS);
765
QCOMPARE(m_dirModel_02->rowCount(), itemsCreated);
766
QCOMPARE(m_dirModel_01->rowCount(), itemsCreated);
767
QCOMPARE(m_progressPercentDone, 100);
768
QCOMPARE(compareDirectories(m_deepDir_01->path(), m_deepDir_02->path()), true);
769
QCOMPARE(m_receivedClipboardChangesSignal, true);
771
QCOMPARE(steps, m_progressCounter);
775
void TestDirModel::modelCopyTwoEmptyFiles()
777
QString orig("modelCopyTwoEmptyFiles_orig");
778
const int itemsCreated = 2;
779
m_deepDir_01 = new DeepDir(orig, 0);
781
empty.addSubDirLevel(orig);
782
empty.touch(itemsCreated);
784
m_dirModel_01->setPath(m_deepDir_01->path());
785
QTest::qWait(TIME_TO_REFRESH_DIR);
786
QCOMPARE(m_dirModel_01->rowCount(), itemsCreated);
788
QString target("modelCopyTwoEmptyFiles_target");
789
m_deepDir_02 = new DeepDir(target, 0);
790
m_dirModel_02->setPath(m_deepDir_02->path());
791
connect(m_dirModel_02, SIGNAL(progress(int,int,int)),
792
this, SLOT(progress(int,int,int)));
793
QTest::qWait(TIME_TO_REFRESH_DIR);
796
m_dirModel_01->copyPaths(empty.createdList());
797
m_dirModel_02->paste();
798
QTest::qWait(TIME_TO_PROCESS);
800
QCOMPARE(m_dirModel_02->rowCount(), itemsCreated);
801
QCOMPARE(m_dirModel_01->rowCount(), itemsCreated);
802
QCOMPARE(m_progressPercentDone, 100);
803
QCOMPARE(m_progressCurrentItem, itemsCreated);
804
QCOMPARE(compareDirectories(m_deepDir_01->path(), m_deepDir_02->path()), true);
808
* \brief TestDirModel::modelCopyFileAndRemoveBeforePaste()
810
* The file is removed before paste, that means at the moment of building the list of files
811
* it does not exist anymore, so the list of items must be empty and no files are going to be performed
813
void TestDirModel::modelCopyFileAndRemoveBeforePaste()
815
QString orig("modelCopyFileAndRemoveBeforePaste_orig");
816
m_deepDir_01 = new DeepDir(orig, 0);
818
tempFile.addSubDirLevel(orig);
821
m_dirModel_01->setPath(m_deepDir_01->path());
822
QTest::qWait(TIME_TO_REFRESH_DIR);
823
QCOMPARE(m_dirModel_01->rowCount(), 1);
825
QString target("modelCopyFileAndRemoveBeforePaste_target");
826
m_deepDir_02 = new DeepDir(target, 0);
827
m_dirModel_02->setPath(m_deepDir_02->path());
828
connect(m_dirModel_02, SIGNAL(progress(int,int,int)),
829
this, SLOT(progress(int,int,int)));
830
connect(m_dirModel_02, SIGNAL(error(QString,QString)),
831
this, SLOT(slotError(QString,QString)));
832
QTest::qWait(TIME_TO_REFRESH_DIR);
834
m_dirModel_01->copyPaths(tempFile.createdList());
835
tempFile.removeAll();
836
m_dirModel_02->paste();
837
QTest::qWait(TIME_TO_PROCESS);
839
QCOMPARE(m_dirModel_02->rowCount(), 0);
840
QCOMPARE(m_receivedErrorSignal, true);
844
* \brief TestDirModel::modelCopyPasteFileAndRemoveWhenFirstProgressSignalArrives()
846
* The file is removed after pasting and before the copy itself starts.
847
* That means, the list of files to be copied is built, but at the moment of the open
848
* the file does not exist.
850
void TestDirModel::modelCopyPasteFileAndRemoveWhenFirstProgressSignalArrives()
852
QString orig("modelCopyPasteFileAndRemoveWhenFirstProgressSignalArrives_orig");
853
m_deepDir_01 = new DeepDir(orig, 0);
855
tempFile.addSubDirLevel(orig);
858
m_dirModel_01->setPath(m_deepDir_01->path());
859
QTest::qWait(TIME_TO_REFRESH_DIR);
860
QCOMPARE(m_dirModel_01->rowCount(), 1);
862
QString target("modelCopyPasteFileAndRemoveWhenFirstProgressSignalArrives_target");
863
m_deepDir_02 = new DeepDir(target, 0);
864
m_dirModel_02->setPath(m_deepDir_02->path());
865
connect(m_dirModel_02, SIGNAL(progress(int,int,int)),
866
this, SLOT(slotRemoveFileWhenProgressArrive(int,int,int)));
867
connect(m_dirModel_02, SIGNAL(error(QString,QString)),
868
this, SLOT(slotError(QString,QString)));
869
QTest::qWait(TIME_TO_REFRESH_DIR);
871
m_fileToRemoveInProgressSignal = tempFile.lastFileCreated();
872
m_dirModel_01->copyPaths(tempFile.createdList());
873
m_dirModel_02->paste();
874
QTest::qWait(TIME_TO_PROCESS);
876
QCOMPARE(m_dirModel_02->rowCount(), 0);
877
QCOMPARE(m_receivedErrorSignal, true);
878
QCOMPARE(m_progressTotalItems, 1);
879
QCOMPARE(m_progressCurrentItem, 0);
883
void TestDirModel::modelCutManyItemsPasteIntoAnotherModel()
885
QString orig("modelCutManyItemsPasteIntoAnotherModel_orig");
887
m_deepDir_01 = new DeepDir(orig, 5);
888
connect(m_dirModel_01, SIGNAL(clipboardChanged()),
889
this, SLOT(slotclipboardChanged()));
890
const int filesCreated = 10;
891
const int itemsCreated = filesCreated + 1;
894
tempFiles.addSubDirLevel(orig);
895
tempFiles.create(filesCreated);
896
m_dirModel_01->setPath(m_deepDir_01->path());
897
QTest::qWait(TIME_TO_REFRESH_DIR);
898
QCOMPARE(m_dirModel_01->rowCount(), itemsCreated);
900
QString target("modelCutManyItemsPasteIntoAnotherModel_target");
901
m_deepDir_02 = new DeepDir(target, 0);
902
connect(m_dirModel_02, SIGNAL(progress(int,int,int)),
903
this, SLOT(progress(int,int,int)));
904
connect(m_dirModel_02, SIGNAL(error(QString,QString)),
905
this, SLOT(slotError(QString,QString)));
906
m_dirModel_02->setPath(m_deepDir_02->path());
907
QTest::qWait(TIME_TO_REFRESH_DIR);
909
QCOMPARE( QFileInfo(m_deepDir_02->path()).exists(), true);
910
QCOMPARE(m_dirModel_02->rowCount(), 0);
912
QStringList allFiles(m_deepDir_01->firstLevel());
913
allFiles.append(tempFiles.createdList());
915
m_dirModel_01->cutPaths(allFiles);
916
m_visibleProgressMessages = true;
917
m_dirModel_02->paste();
918
int steps = m_dirModel_02->getProgressCounter();
919
QTest::qWait(TIME_TO_PROCESS);
921
QCOMPARE(m_dirModel_02->rowCount(), itemsCreated); //pasted into
922
QCOMPARE(m_dirModel_01->rowCount(), 0); //cut from
923
QCOMPARE(m_receivedClipboardChangesSignal, true);
924
QCOMPARE(steps, m_progressCounter);
927
void TestDirModel::fsActionMoveItemsForcingCopyAndThenRemove()
929
QString orig("fsActionMoveItemsForcingCopyAndThenRemove_orig");
931
m_deepDir_01 = new DeepDir(orig, 1);
933
const int filesCreated = 4;
934
const int itemsCreated = filesCreated +1;
937
tempFiles.addSubDirLevel(orig);
938
tempFiles.create(filesCreated);
939
m_dirModel_01->setPath(m_deepDir_01->path());
940
QTest::qWait(TIME_TO_REFRESH_DIR);
941
QCOMPARE(m_dirModel_01->rowCount(), itemsCreated);
943
QString target("fsActionMoveItemsForcingCopyAndThenRemove_target");
944
m_deepDir_02 = new DeepDir(target, 0);
946
m_dirModel_02->setPath(m_deepDir_02->path());
947
QTest::qWait(TIME_TO_REFRESH_DIR);
949
connect(m_dirModel_02, SIGNAL(progress(int,int,int)),
950
this, SLOT(progress(int,int,int)));
952
QCOMPARE( QFileInfo(m_deepDir_02->path()).exists(), true);
953
QCOMPARE(m_dirModel_02->rowCount(), 0);
955
QStringList allFiles(m_deepDir_01->firstLevel());
956
allFiles.append(tempFiles.createdList());
958
m_dirModel_02->m_fsAction->m_forceUsingOtherFS = true;
959
m_dirModel_02->m_fsAction->createAndProcessAction(FileSystemAction::ActionMove,
962
QTest::qWait(TIME_TO_PROCESS);
964
QCOMPARE(m_dirModel_02->rowCount(), itemsCreated); //pasted into
965
QCOMPARE(m_dirModel_01->rowCount(), 0); //cut from
967
int totalCopied = filesCreated + m_deepDir_01->itemsCreated();
968
QCOMPARE(itemsCreated, m_filesAdded.count());
969
QCOMPARE(totalCopied, m_progressTotalItems);
972
void TestDirModel::modelCancelRemoveAction()
974
const int level = 30;
975
m_deepDir_01 = new DeepDir("modelCancelRemoveAction", level);
976
QCOMPARE( QFileInfo(m_deepDir_01->path()).exists(), true);
978
m_dirModel_01->setPath(m_deepDir_01->path());
979
QTest::qWait(TIME_TO_REFRESH_DIR);
981
QCOMPARE(m_dirModel_01->rowCount(), 1);
982
connect(m_dirModel_01, SIGNAL(progress(int,int,int)),
983
this, SLOT(progress(int,int,int)));
984
connect(m_dirModel_01, SIGNAL(progress(int,int,int)),
985
this, SLOT(cancel(int,int,int)));
987
m_dirModel_01->removeIndex(0);
988
QTest::qWait(TIME_TO_PROCESS);
991
QCOMPARE(m_filesRemoved.count() , 0);
992
QCOMPARE(m_dirModel_01->rowCount(), 1);
993
QVERIFY(m_progressCurrentItem > 0); // some file were performed
994
QVERIFY(m_progressPercentDone < 100); //
997
void TestDirModel::modelTestFileSize()
999
QCOMPARE(m_dirModel_01->fileSize(0), QString("0 Bytes"));
1000
QCOMPARE(m_dirModel_01->fileSize(1023), QString("1023 Bytes"));
1001
QCOMPARE(m_dirModel_01->fileSize(1024), QString("1.0 kB"));
1002
QCOMPARE(m_dirModel_01->fileSize(1000*1000),
1004
QCOMPARE(m_dirModel_01->fileSize(1000*1000*1000),
1010
void TestDirModel::modelRemoveDirWithHiddenFilesAndLinks()
1012
const int level = 3;
1013
m_deepDir_01 = new DeepDir("modelRemoveDirWithHiddenFilesAndLinks", level);
1014
QCOMPARE( QFileInfo(m_deepDir_01->path()).exists(), true);
1016
m_dirModel_01->setShowHiddenFiles(true);
1017
m_dirModel_01->setPath(m_deepDir_01->path());
1018
QTest::qWait(TIME_TO_REFRESH_DIR);
1020
QCOMPARE(m_dirModel_01->rowCount(), 1);
1022
connect(m_dirModel_01, SIGNAL(progress(int,int,int)),
1023
this, SLOT(progress(int,int,int)));
1025
QModelIndex filepathIdx = m_dirModel_01->index(0, DirModel::FilePathRole - DirModel::FileNameRole);
1026
QString firstItemFullPath(m_dirModel_01->data(filepathIdx).toString());
1028
// hidden files and links are created under first item
1029
QFile hiddenFile(firstItemFullPath
1031
+ QLatin1String(".hidden.txt"));
1033
QCOMPARE(hiddenFile.open(QFile::WriteOnly) ,true);
1035
QString link_to_hiddenFile(firstItemFullPath
1037
+ QLatin1String("link_to_hiddenFile"));
1038
QCOMPARE(hiddenFile.link(link_to_hiddenFile), true);
1040
QString hiddenFolder(firstItemFullPath
1042
+ QLatin1String(".hiddenFolder"));
1044
QCOMPARE(QDir().mkdir(hiddenFolder) , true);
1045
QString link_to_hidden_folder(firstItemFullPath
1047
+ QLatin1String("link_to_hidden_folder"));
1048
QCOMPARE(QFile(hiddenFolder).link(link_to_hidden_folder), true);
1050
m_dirModel_01->removeIndex(0);
1051
QTest::qWait(TIME_TO_PROCESS);
1053
QCOMPARE(m_dirModel_01->rowCount(), 0);
1054
QCOMPARE(m_progressPercentDone, 100);
1058
void TestDirModel::modelCancelCopyAction()
1060
QString orig("modelCancelCopyAction_orig");
1061
m_deepDir_01 = new DeepDir(orig, 0);
1063
//create a big file to test copy loop
1064
QByteArray buf(4096, 't');
1065
QFile big(m_deepDir_01->path() + QDir::separator() + "big.txt");
1066
QCOMPARE(big.open(QFile::WriteOnly), true);
1067
for(int i=0; i < 186; i++)
1069
int wrote = (int) big.write(buf);
1070
QCOMPARE(wrote, buf.size());
1071
buf += "sdfsdsedccw121222";
1075
m_dirModel_01->setPath(m_deepDir_01->path());
1076
QTest::qWait(TIME_TO_REFRESH_DIR);
1077
QCOMPARE(m_dirModel_01->rowCount(), 1);
1079
QString target("modelCancelCopyAction_target");
1080
m_deepDir_02 = new DeepDir(target, 0);
1082
connect(m_dirModel_02, SIGNAL(progress(int,int,int)),
1083
this, SLOT(progress(int,int,int)));
1084
connect(m_dirModel_02, SIGNAL(progress(int,int,int)),
1085
this, SLOT(cancel(int,int,int)));
1086
m_dirModel_02->setPath(m_deepDir_02->path());
1087
QTest::qWait(TIME_TO_REFRESH_DIR);
1089
m_dirModel_01->copyIndex(0);
1090
m_dirModel_02->paste();
1091
QTest::qWait(TIME_TO_PROCESS);
1093
QCOMPARE( QFileInfo(m_deepDir_02->path()).exists(), true);
1094
QCOMPARE(m_dirModel_02->rowCount(), 0);
1097
void TestDirModel::modelCopyFileAndDirectoryLinks()
1099
QString orig("modelCopyFileAndDirectoryLinks_orig");
1100
m_deepDir_01 = new DeepDir(orig, 1);
1102
//create a link in the same directory to the directory created at first level
1103
QString firstDir = m_deepDir_01->lastLevel();
1104
QString link_to_firstDir = m_deepDir_01->path() + QDir::separator()
1105
+ QLatin1String("link_to_firstDir");
1106
QCOMPARE(createLink(firstDir, link_to_firstDir), true);
1109
QFileInfoList files = d.entryInfoList(QDir::Files);
1110
QVERIFY(files.count() > 0);
1111
QCOMPARE(createLink(files.at(0).absoluteFilePath(), QLatin1String("link_to_file")), true);
1113
m_dirModel_01->setPath(m_deepDir_01->path());
1114
QTest::qWait(TIME_TO_REFRESH_DIR);
1115
QCOMPARE(m_dirModel_01->rowCount(), 2);
1118
QString target("modelCopyFileAndDirectoryLinks_target");
1119
m_deepDir_02 = new DeepDir(target, 0);
1120
connect(m_dirModel_02, SIGNAL(progress(int,int,int)),
1121
this, SLOT(progress(int,int,int)));
1123
m_dirModel_02->setPath(m_deepDir_02->path());
1124
QTest::qWait(TIME_TO_REFRESH_DIR);
1126
QStringList items(firstDir);
1127
items.append(link_to_firstDir);
1129
m_dirModel_01->copyPaths(items);
1131
m_dirModel_02->paste();
1132
QTest::qWait(TIME_TO_PROCESS);
1134
QCOMPARE(m_dirModel_01->rowCount(), 2);
1135
QCOMPARE(m_dirModel_02->rowCount(), 2);
1136
QCOMPARE(compareDirectories(m_deepDir_01->path(), m_deepDir_02->path()), true);
1137
QCOMPARE(m_progressPercentDone, 100);
1138
QCOMPARE(m_progressCurrentItem, m_progressTotalItems);
1142
void TestDirModel::modelCutAndPasteInTheSamePlace()
1144
QString orig("modelCutAndPasteInTheSamePlace_orig");
1145
m_deepDir_01 = new DeepDir (orig,0); // just to be removed
1146
const int files_to_create = 4;
1149
files.addSubDirLevel(orig);
1150
files.create(files_to_create);
1152
QFileInfo info_before[files_to_create];
1153
QStringList created_files(files.createdList());
1155
QCOMPARE(created_files.count(), files_to_create);
1157
for(counter=0; counter < files_to_create; counter++)
1159
info_before[counter] = QFileInfo(created_files.at(counter));
1162
m_dirModel_01->setPath(files.lastPath());
1163
connect(m_dirModel_01, SIGNAL(error(QString,QString)),
1164
this, SLOT(slotError(QString,QString)));
1166
QTest::qWait(TIME_TO_REFRESH_DIR);
1167
QCOMPARE(m_dirModel_01->rowCount(), files_to_create);
1169
m_dirModel_01->cutPaths(created_files);
1170
m_dirModel_01->paste();
1171
QTest::qWait(TIME_TO_PROCESS);
1172
m_dirModel_01->refresh();
1173
QTest::qWait(TIME_TO_REFRESH_DIR);
1176
QCOMPARE(m_dirModel_01->rowCount(), files_to_create);
1177
for(counter=0; counter < files_to_create; counter++)
1179
//files exist and did not were touched
1180
QCOMPARE( QFileInfo(created_files.at(counter)).lastModified(),
1181
info_before[counter].lastModified()) ;
1184
QCOMPARE(m_receivedErrorSignal, true);
1188
void TestDirModel::modelCopyAndPasteToBackupFiles()
1190
QString orig("modelBackupFiles_orig");
1191
m_deepDir_01 = new DeepDir (orig,5); // just to be removed
1192
const int files_to_create = 12;
1195
files.addSubDirLevel(orig);
1196
files.create(files_to_create);
1198
QStringList created_files(files.createdList());
1199
QCOMPARE(created_files.count(), files_to_create);
1201
m_dirModel_01->setPath(files.lastPath());
1203
QTest::qWait(TIME_TO_REFRESH_DIR);
1204
QCOMPARE(m_dirModel_01->rowCount(), files_to_create + 1);
1205
created_files.append(m_deepDir_01->firstLevel());
1207
m_dirModel_01->copyPaths(created_files);
1208
connect(m_dirModel_02, SIGNAL(error(QString,QString)),
1209
this, SLOT(slotError(QString,QString)));
1211
m_dirModel_02->setPath(m_deepDir_01->path());
1212
QTest::qWait(TIME_TO_REFRESH_DIR);
1213
m_dirModel_02->paste();
1214
QTest::qWait(TIME_TO_PROCESS);
1216
QCOMPARE(m_dirModel_02->rowCount(), (files_to_create + 1) * 2);
1217
QCOMPARE(m_receivedErrorSignal, false);
1219
m_dirModel_02->paste();
1220
QTest::qWait(TIME_TO_PROCESS);
1222
QCOMPARE(m_dirModel_02->rowCount(), (files_to_create + 1) * 3);
1223
QCOMPARE(m_receivedErrorSignal, false);
1228
void TestDirModel::modelCopyAndPaste3Times()
1230
QString orig("modelCopyAndPaste3Times_orig");
1231
m_deepDir_01 = new DeepDir(orig, 5);
1233
TempFiles moreFiles;
1234
QCOMPARE(moreFiles.addSubDirLevel(orig), true);
1235
QCOMPARE(moreFiles.create(10), true);
1237
QStringList items(m_deepDir_01->firstLevel());
1238
items.append(moreFiles.createdList());
1240
QString target1("modelCopyAndPaste3Times_target1");
1241
QString target2("modelCopyAndPaste3Times_target2");
1242
QString target3("modelCopyAndPaste3Times_target3");
1244
DeepDir t1(target1,0);
1245
DeepDir t2(target2,0);
1246
DeepDir t3(target3,0);
1248
m_dirModel_01->setPath(m_deepDir_01->path());
1249
QTest::qWait(TIME_TO_REFRESH_DIR);
1250
QCOMPARE(items.count(), m_dirModel_01->rowCount());
1251
m_dirModel_01->copyPaths(items);
1254
model1.setPath(t1.path());
1255
QTest::qWait(TIME_TO_REFRESH_DIR);
1256
QCOMPARE(model1.rowCount() , 0);
1258
QTest::qWait(TIME_TO_PROCESS);
1259
QCOMPARE(model1.rowCount(), items.count());
1260
QCOMPARE(compareDirectories(m_deepDir_01->path(), t1.path()), true);
1263
model2.setPath(t2.path());
1264
QTest::qWait(TIME_TO_REFRESH_DIR);
1265
QCOMPARE(model2.rowCount() , 0);
1267
QTest::qWait(TIME_TO_PROCESS);
1268
QCOMPARE(model2.rowCount(), items.count());
1269
QCOMPARE(compareDirectories(m_deepDir_01->path(), t2.path()), true);
1272
model3.setPath(t3.path());
1273
QTest::qWait(TIME_TO_REFRESH_DIR);
1274
QCOMPARE(model3.rowCount() , 0);
1276
QTest::qWait(TIME_TO_PROCESS);
1277
QCOMPARE(model3.rowCount(), items.count());
1278
QCOMPARE(compareDirectories(m_deepDir_01->path(), t3.path()), true);
1282
void TestDirModel::modelCutAndPaste3Times()
1284
QString orig("modelCutAndPaste3Times_orig");
1285
m_deepDir_01 = new DeepDir(orig, 5);
1287
TempFiles moreFiles;
1288
QCOMPARE(moreFiles.addSubDirLevel(orig), true);
1289
QCOMPARE(moreFiles.create(10), true);
1291
QStringList items(m_deepDir_01->firstLevel());
1292
items.append(moreFiles.createdList());
1294
QString target1("modelCutAndPaste3Times_target1");
1295
QString target2("modelCutAndPaste3Times_target2");
1296
QString target3("modelCutAndPaste3Times_target3");
1298
DeepDir t1(target1,0);
1299
DeepDir t2(target2,0);
1300
DeepDir t3(target3,0);
1302
m_dirModel_01->setPath(m_deepDir_01->path());
1303
QTest::qWait(TIME_TO_REFRESH_DIR);
1304
QCOMPARE(items.count(), m_dirModel_01->rowCount());
1305
m_dirModel_01->cutPaths(items);
1308
model1.setPath(t1.path());
1309
QTest::qWait(TIME_TO_REFRESH_DIR);
1310
QCOMPARE(model1.rowCount() , 0);
1312
QTest::qWait(TIME_TO_PROCESS);
1313
QCOMPARE(model1.rowCount(), items.count());
1314
QCOMPARE(m_dirModel_01->rowCount() , 0 );
1317
model2.setPath(t2.path());
1318
QTest::qWait(TIME_TO_REFRESH_DIR);
1319
QCOMPARE(model2.rowCount() , 0);
1321
QTest::qWait(TIME_TO_PROCESS);
1322
QCOMPARE(model2.rowCount(), items.count());
1325
model3.setPath(t3.path());
1326
QTest::qWait(TIME_TO_REFRESH_DIR);
1327
QCOMPARE(model3.rowCount() , 0);
1329
QTest::qWait(TIME_TO_PROCESS);
1330
QCOMPARE(model3.rowCount(), items.count());
1334
void TestDirModel::modelCopyPasteAndPasteAgain()
1336
QString orig("modelCopyPasteAndPasteAgain_orig");
1337
m_deepDir_01 = new DeepDir(orig, 1);
1338
connect(m_dirModel_01, SIGNAL(error(QString,QString)),
1339
this, SLOT(slotError(QString,QString)));
1341
m_dirModel_01->setPath(m_deepDir_01->path());
1342
QTest::qWait(TIME_TO_REFRESH_DIR);
1343
QCOMPARE(m_dirModel_01->rowCount(), 1);
1346
QString target("modelCopyPasteAndPasteAgain_target");
1347
m_deepDir_02 = new DeepDir(target, 0);
1348
connect(m_dirModel_02, SIGNAL(error(QString,QString)),
1349
this, SLOT(slotError(QString,QString)));
1351
m_dirModel_02->setPath(m_deepDir_02->path());
1352
QTest::qWait(TIME_TO_REFRESH_DIR);
1353
QCOMPARE(m_dirModel_02->rowCount(), 0);
1355
m_dirModel_01->copyIndex(0);
1358
m_dirModel_02->paste();
1359
QTest::qWait(TIME_TO_PROCESS);
1360
QCOMPARE(m_filesRemoved.count(), 0);
1361
QCOMPARE(m_filesAdded.count(), 1);
1364
m_dirModel_02->paste();
1365
QTest::qWait(TIME_TO_PROCESS);
1367
QCOMPARE(compareDirectories(m_deepDir_01->path(), m_deepDir_02->path()), true);
1368
QCOMPARE(m_receivedErrorSignal, false);
1370
//when items already exist, changed signal is emitted
1371
QCOMPARE(m_filesRemoved.count(), 0);
1372
QCOMPARE(m_filesAdded.count(), 1);
1376
void TestDirModel::modelCutPasteIntoExistentItems()
1378
QString orig("modelCutPasteIntoExistentItems_orig");
1379
m_deepDir_01 = new DeepDir(orig, 0);
1380
QString moreOneLevel("MoreOneLevel");
1381
TempFiles tempFiles_01;
1382
TempFiles tempDir_01;
1384
const int createCounterTopLevel = 8;
1385
const int createCounterSubLevel = 2;
1387
tempFiles_01.addSubDirLevel(orig);
1388
tempFiles_01.create(createCounterTopLevel);
1389
tempDir_01.addSubDirLevel(orig);
1390
tempDir_01.addSubDirLevel(moreOneLevel);
1391
tempDir_01.create(2);
1393
connect(m_dirModel_01, SIGNAL(error(QString,QString)),
1394
this, SLOT(slotError(QString,QString)));
1395
m_dirModel_01->setPath(tempFiles_01.lastPath());
1396
QTest::qWait(TIME_TO_REFRESH_DIR);
1397
QCOMPARE(m_dirModel_01->rowCount(), createCounterTopLevel+1); //those created top level plus the subfolder
1399
QString target("modelCutPasteIntoExistentItems_target");
1400
m_deepDir_02 = new DeepDir(target, 0);
1401
TempFiles tempFiles_02;
1402
TempFiles tempDir_02;
1404
tempFiles_02.addSubDirLevel(target);
1405
tempFiles_02.create(createCounterTopLevel);
1406
tempDir_02.addSubDirLevel(target);
1407
tempDir_02.addSubDirLevel(moreOneLevel);
1408
tempDir_02.create(createCounterSubLevel);
1410
connect(m_dirModel_02, SIGNAL(error(QString,QString)),
1411
this, SLOT(slotError(QString,QString)));
1412
connect(m_dirModel_02, SIGNAL(progress(int,int,int)),
1413
this, SLOT(progress(int,int,int)));
1414
m_dirModel_02->setPath(tempFiles_02.lastPath());
1415
QTest::qWait(TIME_TO_REFRESH_DIR);
1417
QCOMPARE(m_dirModel_02->rowCount(), createCounterTopLevel+1); //those created top level plus the subfolder
1419
//both directories have the same content
1420
QCOMPARE(compareDirectories(tempFiles_01.lastPath(), tempFiles_02.lastPath()), true);
1422
//cut from first Model
1423
QStringList items(tempFiles_01.createdList());
1424
items.append(tempDir_01.lastPath());
1425
m_dirModel_01->cutPaths(items);
1426
//paste into the second model
1427
m_dirModel_02->paste();
1428
QTest::qWait(TIME_TO_PROCESS *3);
1430
QCOMPARE(m_receivedErrorSignal, false);
1432
//only one directory that already exists will be removed using another Action
1433
QCOMPARE(m_filesRemoved.count(), 1);
1434
//when items being copied from COPY or renamed from CUT already exist, they are not added
1435
QCOMPARE(m_filesAdded.count(), 0);
1439
void TestDirModel::openPathAbsouluteAndRelative()
1441
QString orig("openPathAbsouluteAndRelative");
1442
m_deepDir_01 = new DeepDir(orig, 1);
1444
connect(m_dirModel_01, SIGNAL(error(QString,QString)),
1445
this, SLOT(slotError(QString,QString)));
1447
connect(m_dirModel_01, SIGNAL(pathChanged(QString)),
1448
this, SLOT(slotPathChamged(QString)));
1450
m_currentPath.clear();
1451
bool ret = m_dirModel_01->openPath(QLatin1String("_ItDoesNotExist_"));
1452
QTest::qWait(TIME_TO_REFRESH_DIR);
1454
QCOMPARE(ret, false);
1455
QCOMPARE(m_currentPath.isEmpty(), true);
1457
ret = m_dirModel_01->openPath(m_deepDir_01->path());
1458
QTest::qWait(TIME_TO_REFRESH_DIR);
1459
QCOMPARE(ret, true);
1460
QCOMPARE(m_currentPath, m_deepDir_01->path());
1461
QCOMPARE(m_dirModel_01->rowCount(), 1);
1462
QCOMPARE(m_receivedErrorSignal, false);
1464
ret = m_dirModel_01->openPath(QLatin1String(".."));
1465
QTest::qWait(TIME_TO_REFRESH_DIR);
1466
QCOMPARE(ret, true);
1467
QCOMPARE(m_currentPath, QDir::tempPath());
1468
QCOMPARE(m_receivedErrorSignal, false);
1470
ret = m_dirModel_01->openPath(orig);
1471
QTest::qWait(TIME_TO_REFRESH_DIR);
1472
QCOMPARE(ret, true);
1473
QCOMPARE(m_currentPath, m_deepDir_01->path());
1474
QCOMPARE(m_receivedErrorSignal, false);
1476
// trash --------------------------------------
1478
QCOMPARE(files.addSubDirLevel(m_deepDir_01->path()), true);
1480
createTempHomeTrashDir(m_deepDir_01->path());
1482
QTrashDir tempTrash;
1483
QString homeTrashDir = tempTrash.homeTrash();
1484
QCOMPARE(files.addSubDirLevel(homeTrashDir), true);
1485
QString filesHomeTrashDir = QTrashUtilInfo::filesTrashDir(homeTrashDir);
1486
QCOMPARE(files.addSubDirLevel(filesHomeTrashDir), true);
1488
QString level1("Level1");
1489
QCOMPARE(files.addSubDirLevel(level1), true);
1491
QTrashUtilInfo trashInfo;
1492
trashInfo.setInfo(tempTrash.homeTrash(), level1);
1493
QCOMPARE(trashInfo.existsFile() , true);
1494
QFile infoFile(trashInfo.absInfo);
1495
QCOMPARE(infoFile.open(QFile::WriteOnly), true);
1498
//check if "Level1" is valid item under trash
1499
QCOMPARE(trashInfo.existsInfoFile() , true);
1501
QString level2("level2");
1502
QString level3("level3");
1504
QCOMPARE(files.addSubDirLevel(level2), true);
1505
QCOMPARE(files.addSubDirLevel(level3), true);
1510
ret = m_dirModel_01->openPath(LocationUrl::TrashRootURL);
1511
QTest::qWait(TIME_TO_REFRESH_DIR);
1512
QCOMPARE(ret, true);
1513
QCOMPARE(m_currentPath, LocationUrl::TrashRootURL);
1514
QCOMPARE(m_receivedErrorSignal, false);
1516
// using relative "Level1"
1517
ret = m_dirModel_01->openPath(level1);
1518
QTest::qWait(TIME_TO_REFRESH_DIR);
1519
QCOMPARE(ret, true);
1520
QCOMPARE(m_currentPath, QString(LocationUrl::TrashRootURL + level1) );
1521
QCOMPARE(m_receivedErrorSignal, false);
1523
//using trash:///Level1/Level2/Level3
1524
QString deep(LocationUrl::TrashRootURL + level1 + QDir::separator() + level2 + QDir::separator() + level3);
1525
ret = m_dirModel_01->openPath(deep);
1526
QTest::qWait(TIME_TO_REFRESH_DIR);
1527
QCOMPARE(ret, true);
1528
QCOMPARE(m_receivedErrorSignal, false);
1530
//using ../ to go up into Level2
1531
ret = m_dirModel_01->openPath("../");
1532
QTest::qWait(TIME_TO_REFRESH_DIR);
1533
QCOMPARE(ret, true);
1534
QCOMPARE(m_receivedErrorSignal, false);
1536
//using .. to go up into Level1
1537
ret = m_dirModel_01->openPath("..");
1538
QTest::qWait(TIME_TO_REFRESH_DIR);
1539
QCOMPARE(ret, true);
1540
QCOMPARE(m_receivedErrorSignal, false);
1543
ret = m_dirModel_01->openPath("..");
1544
QTest::qWait(TIME_TO_REFRESH_DIR);
1545
QCOMPARE(ret, true);
1546
QCOMPARE(m_currentPath, LocationUrl::TrashRootURL);
1547
QCOMPARE(m_receivedErrorSignal, false);
1550
ret = m_dirModel_01->openPath("..");
1551
QTest::qWait(TIME_TO_REFRESH_DIR);
1552
QCOMPARE(ret, false);
1553
QCOMPARE(m_receivedErrorSignal, false);
1555
ret = m_dirModel_01->openPath("file:///");
1556
QTest::qWait(TIME_TO_REFRESH_DIR);
1557
QCOMPARE(ret, true);
1558
QCOMPARE(m_currentPath, QDir::rootPath());
1559
QCOMPARE(m_receivedErrorSignal, false);
1561
ret = m_dirModel_01->openPath("file://");
1562
QTest::qWait(TIME_TO_REFRESH_DIR);
1563
QCOMPARE(ret, true);
1564
QCOMPARE(m_currentPath, QDir::rootPath());
1565
QCOMPARE(m_receivedErrorSignal, false);
1567
ret = m_dirModel_01->openPath("file:/");
1568
QTest::qWait(TIME_TO_REFRESH_DIR);
1569
QCOMPARE(ret, true);
1570
QCOMPARE(m_currentPath, QDir::rootPath());
1571
QCOMPARE(m_receivedErrorSignal, false);
1575
void TestDirModel::existsDirAnCanReadDir()
1577
QString orig("existsDirAnCanReadDir");
1578
m_deepDir_01 = new DeepDir(orig, 1);
1580
connect(m_dirModel_01, SIGNAL(error(QString,QString)),
1581
this, SLOT(slotError(QString,QString)));
1583
connect(m_dirModel_01, SIGNAL(pathChanged(QString)),
1584
this, SLOT(slotPathChamged(QString)));
1586
m_currentPath.clear();
1587
m_dirModel_01->goHome();
1588
QTest::qWait(TIME_TO_REFRESH_DIR);
1590
//test absoulute path
1591
QCOMPARE(m_dirModel_01->existsDir(QDir::tempPath()), true);
1592
QCOMPARE(m_dirModel_01->canReadDir(QDir::tempPath()), true);
1594
//relative does not exist
1595
QString relativeDoesNoEist("__IT_May_Not_Exist_in_Home__HAHA");
1596
QCOMPARE(m_dirModel_01->existsDir(relativeDoesNoEist), false);
1597
QCOMPARE(m_dirModel_01->canReadDir(relativeDoesNoEist), false);
1600
m_dirModel_01->setPath(QDir::tempPath());
1601
QTest::qWait(TIME_TO_REFRESH_DIR);
1602
QCOMPARE(m_dirModel_01->existsDir(orig), true);
1603
QCOMPARE(m_dirModel_01->canReadDir(orig), true);
1605
//check permissions from canReadDir()
1606
bool ok = QFile::setPermissions(m_deepDir_01->path(), QFileDevice::WriteOwner);
1608
QCOMPARE(m_dirModel_01->existsDir(orig), true);
1609
QCOMPARE(m_dirModel_01->canReadDir(orig), false);
1610
QFile::setPermissions(m_deepDir_01->path(), QFileDevice::ReadOwner | QFileDevice::WriteOwner);
1612
ok = QFile::setPermissions(m_deepDir_01->path(),
1613
QFileDevice::ReadOwner | QFileDevice::WriteOwner | QFileDevice::ExeOwner );
1615
QCOMPARE(m_dirModel_01->existsDir(orig), true);
1616
QCOMPARE(m_dirModel_01->canReadDir(orig), true);
1617
QCOMPARE(m_dirModel_01->existsFile(orig), false);
1620
void TestDirModel::existsFileAndCanReadFile()
1622
QString orig("existsFileAndCanReadFile");
1623
m_deepDir_01 = new DeepDir(orig, 1);
1625
m_dirModel_01->setPath(m_deepDir_01->path());
1626
QTest::qWait(TIME_TO_REFRESH_DIR);
1628
QString fileName("myFile.txt");
1629
QCOMPARE(m_dirModel_01->rowCount(), 1) ;
1630
QCOMPARE(m_dirModel_01->existsFile(fileName), false);
1631
QCOMPARE(m_dirModel_01->canReadFile(fileName), false);
1634
temp.addSubDirLevel(orig);
1635
temp.create(fileName,1);
1636
m_dirModel_01->refresh();
1637
QTest::qWait(TIME_TO_REFRESH_DIR);
1638
QCOMPARE(m_dirModel_01->rowCount(), 2) ;
1640
// it has a counter in the name like "myFile.txt_00
1641
fileName = temp.lastNameCreated();
1644
QCOMPARE(m_dirModel_01->existsFile(fileName), true);
1645
QCOMPARE(m_dirModel_01->canReadFile(fileName), true);
1646
QCOMPARE(m_dirModel_01->existsDir(fileName), false);
1649
QCOMPARE(m_dirModel_01->existsFile(temp.lastFileCreated()), true);
1650
QCOMPARE(m_dirModel_01->canReadFile(temp.lastFileCreated()), true);
1652
QCOMPARE(m_dirModel_01->existsDir(temp.lastFileCreated()), false);
1653
QCOMPARE(m_dirModel_01->canReadDir(temp.lastFileCreated()), false);
1655
bool ok = m_dirModel_01->cdIntoPath( m_deepDir_01->lastLevel());
1659
QString fileIsUp = QLatin1String("..") + QDir::separator() + fileName;
1660
QCOMPARE(m_dirModel_01->existsFile(fileIsUp), true);
1661
QCOMPARE(m_dirModel_01->canReadFile(fileIsUp), true);
1663
ok = QFile::setPermissions(temp.lastFileCreated(), QFileDevice::WriteOwner);
1665
QCOMPARE(m_dirModel_01->existsFile(fileIsUp), true);
1666
QCOMPARE(m_dirModel_01->canReadFile(fileIsUp), false);
1670
void TestDirModel::pathProperties()
1672
QString orig("pathProperties");
1673
m_deepDir_01 = new DeepDir(orig, 0);
1675
QTest::qWait(1000); // wait one second
1678
temp.addSubDirLevel(orig);
1681
m_dirModel_01->setPath(m_deepDir_01->path());
1682
QTest::qWait(TIME_TO_REFRESH_DIR);
1684
QCOMPARE(m_dirModel_01->curPathIsWritable(), true);
1685
bool ok = QFile::setPermissions(m_deepDir_01->path(),
1686
QFileDevice::ReadOwner | QFileDevice::ExeOwner );
1689
QCOMPARE(m_dirModel_01->curPathIsWritable(), false);
1691
ok = QFile::setPermissions(m_deepDir_01->path(),
1692
QFileDevice::ReadOwner | QFileDevice::ExeOwner | QFileDevice::WriteOwner);
1695
qWarning("created %s", m_dirModel_01->curPathCreatedDateLocaleShort().toLocal8Bit().constData());
1696
qWarning("modified %s", m_dirModel_01->curPathModifiedDateLocaleShort().toLocal8Bit().constData());
1703
* 1. 2 file managers in /tmp/watchExternalChanges, m_dirModel_01 and m_dirModel_02
1704
* 2. level_01 will be created under /tmp/watchExternalChanges,
1705
* so both m_dirModel_01 and m_dirModel_02 start with 1 item
1706
* 3. Under /tmp/watchExternalChanges/level_01 10 items "from_level_01.cut_nn" are created
1707
* 4 A third File manager is created pointing to /tmp/watchExternalChanges/level_01
1708
* 5 A loop is created to move all files under /tmp/watchExternalChanges/level_01
1709
* to /tmp/watchExternalChanges where there are the 2 File Manager instances /tmp/watchExternalChanges/level_01
1711
* 5.1 files are created using createdOutsideName which is a TemFiles object
1712
* 5.2 from m_dirModel_01 a file can be removed depending on the current time
1714
void TestDirModel::watchExternalChanges()
1716
QString orig("watchExternalChanges");
1717
m_deepDir_01 = new DeepDir(orig, 0);
1718
TempFiles tempUnderFirstLevel;
1719
tempUnderFirstLevel.addSubDirLevel(orig);
1720
tempUnderFirstLevel.addSubDirLevel(QLatin1String("level_01"));
1721
const int cut_items = 10;
1722
tempUnderFirstLevel.create("from_level_01.cut", cut_items);
1725
thirdFM.setPath(tempUnderFirstLevel.lastPath());
1728
connect(m_dirModel_01, SIGNAL(error(QString,QString)),
1729
this, SLOT(slotError(QString,QString)));
1730
m_dirModel_01->setPath(m_deepDir_01->path());
1732
QTest::qWait(TIME_TO_REFRESH_DIR);
1734
connect(m_dirModel_02, SIGNAL(error(QString,QString)),
1735
this, SLOT(slotError(QString,QString)));
1736
m_dirModel_02->setPath(m_deepDir_01->path());
1738
QTest::qWait(TIME_TO_REFRESH_DIR);
1740
QCOMPARE(thirdFM.rowCount(), cut_items);
1741
QCOMPARE(m_dirModel_01->rowCount(), 1);
1742
QCOMPARE(m_dirModel_02->rowCount(), 1);
1744
qDebug() << "dirModelObjs:" << m_dirModel_01 << m_dirModel_02 << &thirdFM;
1746
QString createdOutsideName;
1747
TempFiles createdOutsideFiles;
1748
createdOutsideFiles.addSubDirLevel(orig);
1749
int total_removed = 0;
1752
thirdFM.setEnabledExternalFSWatcher(true);
1754
for ( int counter = 0; counter < cut_items; ++counter )
1756
thirdFM.cutIndex(0);
1759
m_dirModel_01->paste();
1763
m_dirModel_02->paste();
1765
QTest::qWait(TIME_TO_PROCESS);
1766
//at least one file is removed
1767
if (m_dirModel_02->rowCount() > 1 &&
1768
(!total_removed || (QDateTime::currentDateTime().time().msec() % 100) == 0))
1770
//using index 1 because 0 is a directory and the items are being moved up
1771
m_dirModel_02->removeIndex(1);
1772
QTest::qWait(TIME_TO_PROCESS);
1775
createdOutsideName.sprintf("created_%d", counter);
1776
createdOutsideFiles.create(createdOutsideName);
1778
int total_created = 1 + cut_items + createdOutsideFiles.created() - total_removed;
1779
QTest::qWait(EX_FS_WATCHER_TIMER_INTERVAL * 2);
1780
qWarning("using 2 instances [cut_items]=%d [created outside]=%d, [removed outside]=%d", cut_items, createdOutsideFiles.created(), total_removed);
1782
QCOMPARE(m_dirModel_01->rowCount(), total_created);
1783
if (m_dirModel_02->getEnabledExternalFSWatcher())
1785
QCOMPARE(m_dirModel_02->rowCount(), total_created);
1790
void TestDirModel::getThemeIcons()
1792
QStringList mimesToTest = QStringList()
1796
<< "inode/directory"
1797
<< "application/msword"
1798
<< "application/octet-stream"
1799
<< "application/pdf"
1800
<< "application/postscript"
1801
<< "application/x-bzip-compressed-tar"
1802
<< "application/x-executable"
1803
<< "application/x-gzip"
1804
<< "application/x-shellscript"
1806
QMimeDatabase mimeBase;
1808
QHash<QByteArray, QString> md5IconsTable;
1810
qDebug() << "QIcon::themeSearchPaths()" << QIcon::themeSearchPaths();
1811
qDebug() << "QIcon::themeName()" << QIcon::themeName();
1814
for (int counter=0; counter < mimesToTest.count(); counter++)
1816
QMimeType mimetype = mimeBase.mimeTypeForName(mimesToTest.at(counter));
1818
msg = QLatin1String("invalid mimetype ") + mimesToTest.at(counter);
1819
if (!mimetype.isValid())
1821
QSKIP_ALL_TESTS(qPrintable(msg));
1823
QString iconName = mimetype.iconName();
1824
if (!QIcon::hasThemeIcon(iconName) && QIcon::hasThemeIcon(mimetype.genericIconName()))
1826
iconName = mimetype.genericIconName();
1828
QIcon icon = QIcon::fromTheme(iconName);
1829
msg = QLatin1String("invalid QIcon::fromTheme ") + iconName;
1832
QSKIP_ALL_TESTS(qPrintable(msg));
1835
QPixmap pix = icon.pixmap(QSize(48,48));
1836
msg = QLatin1String("invalid QPixmap from icon ") + iconName;
1839
QSKIP_ALL_TESTS(qPrintable(msg));
1842
QImage image = pix.toImage();
1843
msg = QLatin1String("invalid QImage from QPixmap/QIcon ") + iconName;
1846
QSKIP_ALL_TESTS(qPrintable(msg));
1849
const uchar *bits = image.bits();
1850
const char *bytes = reinterpret_cast<const char*> (bits);
1851
QByteArray bytesArray(bytes, image.byteCount());
1852
QByteArray md5 = QCryptographicHash::hash(bytesArray, QCryptographicHash::Md5);
1853
bool ret = !md5IconsTable.contains(md5);
1854
qWarning("%s icon using QIcon::fromTheme() for mime type %s",
1855
ret ? "GOOD" : "BAD ",
1856
mimetype.name().toLocal8Bit().constData());
1857
md5IconsTable.insert(md5, mimesToTest.at(counter));
1862
bool TestDirModel::createFileAndCheckIfIconIsExclisive(const QString& termination,
1863
const unsigned char *content,
1866
QString myFile = createFileInTempDir(QString("tst_folderlistmodel_test.") + termination,
1867
reinterpret_cast<const char*> (content),
1870
bool triedIcon = false;
1871
if (!myFile.isEmpty())
1873
QFileInfo myFileInfo(myFile);
1874
if (myFileInfo.exists())
1877
QIcon icon = m_provider.icon(myFileInfo);
1878
QFile::remove(myFile);
1879
QByteArray md5 = md5FromIcon(icon);
1880
ret = !m_md5IconsTable.contains(md5);
1881
qWarning("%s icon from QFileIconProvider::icon() for %s", ret ? "GOOD" : "QFileIconProvider::File or a BAD", qPrintable(myFile));
1886
qDebug() << "ERROR: could not get icon for" << myFile;
1892
//generate some files and test if there is a icon available in
1893
void TestDirModel::fileIconProvider()
1895
QIcon commonIcon = m_provider.icon(QFileIconProvider::File);
1896
if (commonIcon.isNull())
1898
QFAIL("No QFileIconProvider::File available");
1901
QByteArray commonIconMd5 = md5FromIcon(commonIcon);
1902
m_md5IconsTable.insert(commonIconMd5 , "commonIcon");
1905
createFileAndCheckIfIconIsExclisive("mp3", sound_44100_mp3_data, sound_44100_mp3_data_len);
1906
createFileAndCheckIfIconIsExclisive("pdf", testonly_pdf_data, testonly_pdf_len);
1907
createFileAndCheckIfIconIsExclisive("asx", media_asx, media_asx_len);
1908
createFileAndCheckIfIconIsExclisive("xspf", media_xspf, media_xspf_len);
1911
#ifndef DO_NOT_USE_TAG_LIB
1912
//generate mp3 and verify its metadata
1913
void TestDirModel::verifyMP3Metadata()
1915
QString mp3File = createFileInTempDir("tst_folderlistmodel_for_media_read.mp3",
1916
reinterpret_cast<const char*>(sound_44100_mp3_data),
1917
sound_44100_mp3_data_len);
1918
QCOMPARE(mp3File.isEmpty(), false);
1920
m_dirModel_01->setReadsMediaMetadata(true);
1921
QFileInfo fi(mp3File);
1923
QString title = m_dirModel_01->getAudioMetaData(fi, DirModel::TrackTitleRole).toString();
1924
QString artist = m_dirModel_01->getAudioMetaData(fi, DirModel::TrackArtistRole).toString();
1925
QString album = m_dirModel_01->getAudioMetaData(fi, DirModel::TrackAlbumRole).toString();
1926
QString year = m_dirModel_01->getAudioMetaData(fi, DirModel::TrackYearRole).toString();
1927
QString track = m_dirModel_01->getAudioMetaData(fi, DirModel::TrackNumberRole).toString();
1928
QString genre = m_dirModel_01->getAudioMetaData(fi, DirModel::TrackGenreRole).toString();
1930
QFile::remove(mp3File);
1932
QCOMPARE(title, QString("TitleTest"));
1933
QCOMPARE(artist, QString("ArtistTest"));
1934
QCOMPARE(album, QString("AlbumTest"));
1935
QCOMPARE(year, QString::number(2013));
1936
QCOMPARE(track, QString::number(99));
1937
QCOMPARE(genre, QString("GenreTest"));
1942
#if defined(TEST_OPENFILES)
1943
void TestDirModel::TestDirModel::openMP3()
1945
QString mp3File = createFileInTempDir("tst_folderlistmodel_for_open.mp3",
1946
reinterpret_cast<const char*>(sound_44100_mp3_data),
1947
sound_44100_mp3_data_len);
1948
QCOMPARE(mp3File.isEmpty(), false);
1949
QUrl mp3Url = QUrl::fromLocalFile(mp3File);
1950
bool ret = QDesktopServices::openUrl(mp3Url);
1953
QTest::qWait(TIME_TO_PROCESS *5);
1954
qWarning("GOOD: QDesktopServices::openUrl() works for MP3 files");
1957
qWarning("BAD: QDesktopServices::openUrl() does NOT work for MP3 files");
1959
QCOMPARE(QFile::remove(mp3File), true);
1962
void TestDirModel::openTXT()
1964
QByteArray text("This is a test only\n");
1965
QString txtFile = createFileInTempDir("tst_folderlistmodel_for_open.txt",
1968
QCOMPARE(txtFile.isEmpty(), false);
1969
QUrl txtUrl = QUrl::fromLocalFile(txtFile);
1970
bool ret = QDesktopServices::openUrl(txtUrl);
1973
QTest::qWait(TIME_TO_PROCESS *5);
1974
qWarning("GOOD: QDesktopServices::openUrl() works for TEXT files");
1977
qWarning("BAD: QDesktopServices::openUrl() does NOT work for TEXT files");
1979
QCOMPARE(QFile::remove(txtFile), true);
1982
void TestDirModel::openPDF()
1984
QString pdfFile = createFileInTempDir("tst_folderlistmodel_for_open.pdf",
1985
reinterpret_cast<const char*>(testonly_pdf_data),
1987
QCOMPARE(pdfFile.isEmpty(), false);
1988
QUrl pdfUrl = QUrl::fromLocalFile(pdfFile);
1989
bool ret = QDesktopServices::openUrl(pdfUrl);
1992
QTest::qWait(TIME_TO_PROCESS *5);
1993
("GOOD: QDesktopServices::openUrl() works for PDF files");
1996
qWarning("BAD: QDesktopServices::openUrl() does NOT work for PDF files");
1998
QCOMPARE(QFile::remove(pdfFile), true);
2004
* \brief TestDirModel::extFsWatcherChangePathManyTimesModifyAllPathsLessLast() expects no Notification
2006
* As the current path changes in a small interval of the time and the last path set
2007
* is not modified, the signal pathModified() MUST NOT be fired.
2009
void TestDirModel::extFsWatcherChangePathManyTimesModifyAllPathsLessLast()
2011
ExternalFSWatcher watcher;
2012
connect(&watcher, SIGNAL(pathModified(QString)),
2013
this, SLOT(slotExtFsWatcherPathModified(QString)));
2015
const int items = 150;
2016
QVector<DeepDir *> deepDirs;
2017
deepDirs.reserve(items);
2019
for (int counter=1; counter <= items ; ++counter)
2021
QString dirName(QString("extModifyAllLessLast") + QString::number(counter));
2022
DeepDir *d = new DeepDir(dirName,0);
2024
watcher.setCurrentPath(d->path());
2025
if (counter < items) // last dir does not receive a file
2028
file.addSubDirLevel(dirName);
2034
QTest::qWait(TIME_TO_PROCESS);
2035
qDeleteAll(deepDirs);
2037
QCOMPARE(m_extFSWatcherPathModifiedCounter, 0);
2042
* \brief TestDirModel::extFsWatcherChangePathManyTimesModifyManyTimes
2044
* Change path many times, force one notification at each path
2046
void TestDirModel::extFsWatcherChangePathManyTimesModifyManyTimes()
2048
ExternalFSWatcher watcher;
2049
connect(&watcher, SIGNAL(pathModified(QString)),
2050
this, SLOT(slotExtFsWatcherPathModified(QString)));
2052
const int items = 50;
2053
QVector<DeepDir *> deepDirs;
2054
deepDirs.reserve(items);
2056
for (int counter=0; counter < items ; ++counter)
2058
QString dirName(QString("extFsWatcherChangePathManyTimesModifyManyTimes")
2059
+ QString::number(counter));
2060
DeepDir *d = new DeepDir(dirName,0);
2061
watcher.setCurrentPath(d->path());
2063
file.addSubDirLevel(dirName);
2065
QTest::qWait(watcher.getIntervalToNotifyChanges() + 20);
2068
QTest::qWait(TIME_TO_PROCESS);
2069
qDeleteAll(deepDirs);
2071
QCOMPARE(m_extFSWatcherPathModifiedCounter, items);
2075
* \brief TestDirModel::extFsWatcherModifySamePathManyTimesWithInInterval() expects just one Notification
2077
* A path is modified many times in a small time interval than ExternalFSWatcher class notifies changes,
2078
* so only one Notification is expected.
2080
void TestDirModel::extFsWatcherModifySamePathManyTimesWithInInterval()
2082
ExternalFSWatcher watcher;
2083
connect(&watcher, SIGNAL(pathModified(QString)),
2084
this, SLOT(slotExtFsWatcherPathModified(QString)));
2086
QString dirName("extFsWatcher_expects_just_one_signal");
2087
m_deepDir_01 = new DeepDir(dirName,0);
2088
watcher.setCurrentPath(m_deepDir_01->path());
2090
int waitTime = watcher.getIntervalToNotifyChanges() / loop - 10;
2094
file.addSubDirLevel(dirName);
2095
file.create(QString("file_") + QString::number(loop), 1);
2096
QTest::qWait(waitTime);
2099
QTest::qWait(TIME_TO_PROCESS);
2100
QCOMPARE(m_extFSWatcherPathModifiedCounter, 1 );
2105
* \brief TestDirModel::extFsWatcherSetPathAndModifyManyTimesWithInInterval() expects just one Notification
2107
void TestDirModel::extFsWatcherSetPathAndModifyManyTimesWithInInterval()
2109
ExternalFSWatcher watcher;
2110
connect(&watcher, SIGNAL(pathModified(QString)),
2111
this, SLOT(slotExtFsWatcherPathModified(QString)));
2113
QList<DeepDir *> deepDirs;
2116
int waitTime = watcher.getIntervalToNotifyChanges() / loop - 5;
2118
for (int counter=1; counter <= loop ; ++counter)
2120
QString dirName(QString("extModifyAll") + QString::number(counter));
2121
DeepDir *d = new DeepDir(dirName,0);
2122
watcher.setCurrentPath(d->path());
2124
file.addSubDirLevel(dirName);
2126
QTest::qWait(waitTime);
2129
QTest::qWait(TIME_TO_PROCESS);
2130
qDeleteAll(deepDirs);
2132
QCOMPARE(m_extFSWatcherPathModifiedCounter, 1);
2135
#if defined(Q_OS_UNIX)
2137
* \brief TestDirModel::extFsWatcherNoticeChangesWithSameTimestamp()
2139
* Test if it gets notification from \ref ExternalFSWatcher for a file changed/created that generates the same
2140
* timestamp as the last modification which had generated previous notification.
2142
* \note To do this the "last modification time" is forced with utimes(2) system call.
2144
void TestDirModel::extFsWatcherNoticeChangesWithSameTimestamp()
2146
bool updateAndSetModificationTime(const QString& filename, QDateTime& desiredTime);
2148
connect( m_dirModel_01->getExternalFSWatcher(), SIGNAL(pathModified(QString)),
2149
this, SLOT(slotExtFsWatcherPathModified(QString)));
2151
QString dirName("extFsWatcher_generate_fileswithsameTimeStamp");
2152
m_deepDir_01 = new DeepDir(dirName,0);
2154
TempFiles tmp1, tmp2;
2155
tmp1.addSubDirLevel(dirName);
2156
tmp2.addSubDirLevel(dirName);
2157
tmp1.create(QLatin1String("first"), 1);
2158
tmp2.create(QLatin1String("second"), 1);
2159
QString firstPathName = tmp1.createdList().at(0);
2160
QString secondPathName = tmp2.createdList().at(0);
2162
m_dirModel_01->setPath(m_deepDir_01->path());
2163
QTest::qWait(TIME_TO_REFRESH_DIR);
2164
//make sure model has 2 files
2165
QCOMPARE(m_dirModel_01->rowCount(), 2) ;
2167
QDateTime timeStamp = QDateTime::currentDateTime();
2168
QTime time = timeStamp.time();
2170
time.setHMS(time.hour(), time.minute(), time.second());
2171
timeStamp.setTime(time);
2173
//wait some time to have a different timestamp
2176
//update first time and set its modification time to timeStamp
2177
bool ret = updateAndSetModificationTime(firstPathName, timeStamp);
2178
QCOMPARE(ret, true);
2179
QFileInfo firstFile(firstPathName);
2180
QCOMPARE(firstFile.lastModified(), timeStamp);
2182
const int maxWait = m_dirModel_01->getExternalFSWatcher()->getIntervalToNotifyChanges() + 10;
2185
//make sure ExternalFSWatcher has not notified any change
2186
QCOMPARE(m_extFSWatcherPathModifiedCounter, 0);
2187
//wait for notification on first file
2188
for (counter = 0; m_extFSWatcherPathModifiedCounter == 0 && counter < maxWait; ++counter)
2192
//make sure as notification was sent, it must be one
2193
QCOMPARE(m_extFSWatcherPathModifiedCounter, 1);
2195
//now update the second file and set the mofication time the same as the first file
2196
//this second file is one what matters because the first change has just been notified
2197
ret = updateAndSetModificationTime(secondPathName, timeStamp);
2198
QCOMPARE(ret, true);
2199
QFileInfo secondFile(secondPathName);
2200
QCOMPARE(secondFile.lastModified(), timeStamp);
2201
for (counter = 0; m_extFSWatcherPathModifiedCounter == 1 && counter < maxWait; ++counter)
2205
//make sure as notification was sent, it must be 2
2206
QCOMPARE(m_extFSWatcherPathModifiedCounter, 2);
2208
//this comparation is not necessary since both last modification files were compared to timeStamp
2209
QCOMPARE(secondFile.lastModified(), firstFile.lastModified());
2214
void TestDirModel::modelSingleSelection()
2216
DirSelection *selection = m_dirModel_01->selectionObject();
2217
QVERIFY(selection != 0);
2219
connect(selection, SIGNAL(selectionChanged(int)),
2220
this, SLOT(slotSelectionChanged(int)));
2222
connect(selection, SIGNAL(modeChanged(int)),
2223
this, SLOT(slotSelectionModeChanged(int)));
2225
QString dirName("modelSingleSelection");
2226
m_deepDir_01 = new DeepDir(dirName,0);
2228
TempFiles tmp1, tmp2, tmp3;
2229
tmp1.addSubDirLevel(dirName);
2230
tmp2.addSubDirLevel(dirName);
2231
tmp3.addSubDirLevel(dirName);
2232
tmp1.create(QLatin1String("01first"), 1);
2233
tmp2.create(QLatin1String("02second"), 1);
2234
tmp3.create(QLatin1String("03third"), 1);
2235
QString firstFile = tmp1.createdNames().at(0);
2236
QString secondFile = tmp2.createdList().at(0);
2237
QString thirdFile = tmp3.createdNames().at(0);
2239
m_dirModel_01->setPath(m_deepDir_01->path());
2240
QTest::qWait(TIME_TO_REFRESH_DIR);
2241
QCOMPARE(m_dirModel_01->rowCount(), 3) ;
2243
//relative path = name in the file manager
2244
QCOMPARE(QFileInfo(firstFile).isAbsolute() , false);
2246
QCOMPARE(QFileInfo(secondFile).isAbsolute(), true);
2248
selection->setMode(DirSelection::Multi);
2249
QTest::qWait(TIME_TO_REFRESH_DIR);
2250
QVERIFY(m_selectionMode != DirSelection::Single);
2251
selection->setMode(DirSelection::Single);
2252
QTest::qWait(TIME_TO_REFRESH_DIR);
2253
QCOMPARE(m_selectionMode, (int)DirSelection::Single);
2255
QModelIndex firstIdx = m_dirModel_01->index(0, DirModel::IsSelectedRole - DirModel::FileNameRole);
2256
QModelIndex secondIdx = m_dirModel_01->index(1, DirModel::IsSelectedRole - DirModel::FileNameRole);
2257
QModelIndex thirdIdx = m_dirModel_01->index(2, DirModel::IsSelectedRole - DirModel::FileNameRole);
2259
//toggle first item selection using index
2260
selection->toggleIndex(0);
2261
QTest::qWait(TIME_TO_REFRESH_DIR);
2262
QCOMPARE(m_dirModel_01->data(firstIdx).toBool(), true);
2263
QCOMPARE(m_dirModel_01->data(secondIdx).toBool(), false);
2264
QCOMPARE(m_dirModel_01->data(thirdIdx).toBool(), false);
2265
QCOMPARE(m_selectedItemsCounter, 1);
2267
//toggle second item selection
2268
selection->toggleIndex(1);
2269
QTest::qWait(TIME_TO_REFRESH_DIR);
2270
QCOMPARE(m_dirModel_01->data(firstIdx).toBool(), false);
2271
QCOMPARE(m_dirModel_01->data(secondIdx).toBool(), true);
2272
QCOMPARE(m_dirModel_01->data(thirdIdx).toBool(), false);
2273
QCOMPARE(m_selectedItemsCounter, 1);
2275
//toggle third item selection
2276
selection->toggleIndex(2);
2277
QTest::qWait(TIME_TO_REFRESH_DIR);
2278
QCOMPARE(m_dirModel_01->data(firstIdx).toBool(), false);
2279
QCOMPARE(m_dirModel_01->data(secondIdx).toBool(), false);
2280
QCOMPARE(m_dirModel_01->data(thirdIdx).toBool(), true);
2281
QCOMPARE(m_selectedItemsCounter, 1);
2283
selection->selectAll();
2284
QTest::qWait(TIME_TO_REFRESH_DIR);
2285
QCOMPARE(m_selectedItemsCounter, 3);
2287
//all items are selected, if one item is unselected, other 2 items remain selected
2288
selection->toggleIndex(0);
2289
QTest::qWait(TIME_TO_REFRESH_DIR);
2290
QCOMPARE(m_dirModel_01->data(firstIdx).toBool(), false);
2291
QCOMPARE(m_dirModel_01->data(secondIdx).toBool(), true);
2292
QCOMPARE(m_dirModel_01->data(thirdIdx).toBool(), true);
2293
QCOMPARE(m_selectedItemsCounter, 2);
2296
QList<int> selectedIndexes = selection->selectedIndexes();
2297
QCOMPARE(selectedIndexes.count(), 2);
2298
QCOMPARE(selectedIndexes.at(0), 1);
2299
QCOMPARE(selectedIndexes.at(1), 2);
2300
QStringList selectedNames = selection->selectedNames();
2301
QCOMPARE(selectedNames.count(), 2);
2302
// as secondFile is absolute path
2303
QCOMPARE(selectedNames.at(0), QFileInfo(secondFile).fileName());
2304
QCOMPARE(selectedNames.at(1), thirdFile);
2305
QStringList pathNames = selection->selectedAbsFilePaths();
2306
QCOMPARE(pathNames.count(), 2);
2307
QCOMPARE(pathNames.at(0), tmp2.createdList().first());
2308
QCOMPARE(pathNames.at(1), tmp3.createdList().first());
2310
//now as the first item is unselected, toggle
2311
selection->toggleIndex(0);
2312
QTest::qWait(TIME_TO_REFRESH_DIR);
2313
QCOMPARE(m_dirModel_01->data(firstIdx).toBool(), true);
2314
QCOMPARE(m_dirModel_01->data(secondIdx).toBool(), false);
2315
QCOMPARE(m_dirModel_01->data(thirdIdx).toBool(), false);
2316
QCOMPARE(m_selectedItemsCounter, 1);
2320
void TestDirModel::modelMultiSelection()
2322
DirSelection *selection = m_dirModel_01->selectionObject();
2323
QVERIFY(selection != 0);
2325
connect(selection, SIGNAL(selectionChanged(int)),
2326
this, SLOT(slotSelectionChanged(int)));
2328
connect(selection, SIGNAL(modeChanged(int)),
2329
this, SLOT(slotSelectionModeChanged(int)));
2331
QString dirName("modelMultiSelection");
2332
const int createdFiles = 10;
2334
m_deepDir_01 = new DeepDir(dirName,0);
2336
tmpFiles.addSubDirLevel(dirName);
2337
tmpFiles.create(createdFiles);
2339
m_dirModel_01->setPath(m_deepDir_01->path());
2340
QTest::qWait(TIME_TO_REFRESH_DIR);
2341
QCOMPARE(m_dirModel_01->rowCount(), createdFiles) ;
2343
selection->setMode(DirSelection::Multi);
2344
QTest::qWait(TIME_TO_REFRESH_DIR);
2345
QCOMPARE(selection->mode(), DirSelection::Multi);
2347
QStringList createdNames = tmpFiles.createdNames();
2348
QList<int> handledIndexes;
2349
handledIndexes << 0 << 3 << 5 << 8 << 4;
2350
int counter = handledIndexes.count();
2352
QCOMPARE(m_selectedItemsCounter, 0);
2355
int item = handledIndexes.at(counter);
2356
selection->setIndex(item, true);
2359
QCOMPARE(m_selectedItemsCounter, handledIndexes.count());
2361
counter = handledIndexes.count();
2364
int item = handledIndexes.at(counter);
2365
QModelIndex index = m_dirModel_01->index(item,
2366
DirModel::IsSelectedRole - DirModel::FileNameRole);
2367
QCOMPARE(m_dirModel_01->data(index).toBool(), true);
2370
//remove selected Items
2371
m_dirModel_01->removeIndex(handledIndexes.takeAt(2));
2372
QTest::qWait(TIME_TO_PROCESS);
2373
m_dirModel_01->removeIndex(handledIndexes.takeLast());
2374
QTest::qWait(TIME_TO_PROCESS);
2375
QCOMPARE(m_selectedItemsCounter, handledIndexes.count());
2377
selection->selectAll();
2378
QTest::qWait(TIME_TO_REFRESH_DIR);
2379
QCOMPARE(m_selectedItemsCounter, m_dirModel_01->rowCount());
2382
QTest::qWait(TIME_TO_REFRESH_DIR);
2383
QCOMPARE(m_selectedItemsCounter, 0);
2387
void TestDirModel::modelSelectionItemsRange()
2389
QString dirName("modelSelectionItemsRange");
2390
m_deepDir_01 = new DeepDir(dirName,0);
2392
const int createdFiles = 11;
2393
tmpFiles.addSubDirLevel(dirName);
2394
tmpFiles.create(createdFiles);
2396
m_dirModel_01->setPath(m_deepDir_01->path());
2397
QTest::qWait(TIME_TO_REFRESH_DIR);
2398
QCOMPARE(m_dirModel_01->rowCount(), createdFiles);
2400
DirSelection *selection = m_dirModel_01->selectionObject();
2401
QVERIFY(selection != 0);
2403
connect(selection, SIGNAL(selectionChanged(int)),
2404
this, SLOT(slotSelectionChanged(int)));
2407
selection->setIndex(3, true);
2408
QTest::qWait(TIME_TO_PROCESS);
2409
QCOMPARE(m_selectedItemsCounter, 1);
2411
//try to do range with same index (expected nothing to happen)
2412
selection->selectRange(3);
2413
QTest::qWait(TIME_TO_PROCESS);
2414
QCOMPARE(m_selectedItemsCounter, 1);
2416
//try item under selected item
2417
selection->selectRange(8);
2418
QTest::qWait(TIME_TO_PROCESS);
2419
QCOMPARE(m_selectedItemsCounter, 6);
2421
//try item above selected item
2422
selection->selectRange(0);
2423
QTest::qWait(TIME_TO_PROCESS);
2424
QCOMPARE(m_selectedItemsCounter, 9);
2427
void TestDirModel::trashDiretories()
2430
QString dirName("trashDiretories");
2431
m_deepDir_01 = new DeepDir(dirName,0);
2433
// there is not .Trash dir
2434
QCOMPARE(trash.isMountPointSharedWithStickBit(dirName), false);
2436
//create .Trash in it
2437
QString trashDir(m_deepDir_01->path() + QDir::separator() + ".Trash");
2438
QCOMPARE(QDir().mkpath(trashDir), true);
2442
QCOMPARE(trash.isMountPointSharedWithStickBit(dirName), false);
2445
QString cmd("chmod +t " + trashDir);
2446
QCOMPARE(system(cmd.toLocal8Bit().constData()), 0);
2447
QCOMPARE(trash.isMountPointSharedWithStickBit((m_deepDir_01->path())), true);
2449
//test validate Trash Dir()
2450
QCOMPARE(trash.validate(trashDir, false), false);
2454
bool permOk = f.setPermissions(QFile::ReadOwner |
2457
QCOMPARE(permOk, true);
2458
QCOMPARE(trash.checkUserDirPermissions(trashDir), true);
2460
//create files in Trash
2461
QCOMPARE(trash.createUserDir(QTrashUtilInfo::filesTrashDir(trashDir)), true);
2462
//create info in Trash
2463
QCOMPARE(trash.createUserDir(QTrashUtilInfo::infoTrashDir(trashDir)), true);
2464
//test validate Trash Dir(), now it MUST pass
2465
QCOMPARE(trash.validate(trashDir, false), true);
2467
//invalidate Trash dir
2468
QFile *f1 = new QFile(trashDir) ;
2469
permOk = f1->setPermissions(QFile::ReadOwner | QFile::ReadOther |
2470
QFile::WriteOwner | QFile::WriteGroup|
2472
QCOMPARE(permOk, true);
2475
QCOMPARE(trash.validate(trashDir, false), false);
2477
QString xdgTrash("xdg_Trash");
2478
m_deepDir_02 = new DeepDir(xdgTrash,0);
2480
if (::qgetenv("XDG_DATA_HOME").size() == 0)
2482
QString myTrash(QDir::homePath() + "/.local/share/Trash");
2483
QCOMPARE(trash.homeTrash(), myTrash);
2486
//test XDG Home Trash
2487
::setenv("XDG_DATA_HOME", m_deepDir_02->path().toLocal8Bit().constData(), true );
2488
QString xdgTrashDir(trash.homeTrash());
2489
QCOMPARE(trash.validate(xdgTrashDir, false), true);
2490
QCOMPARE(trash.homeTrash() , xdgTrashDir);
2492
QCOMPARE(trash.getMountPoint(QDir::rootPath()), QDir::rootPath());
2494
QStringList mountedPoints = trash.mountedPoints();
2495
foreach (const QString& mp, mountedPoints)
2497
//attemp to create a temporary folder inside the mount point
2498
QTemporaryDir dir(mp + QDir::separator() );
2501
QFileInfo fiDir(dir.path());
2504
qDebug() << "temp dir" << dir.path();
2505
QCOMPARE(trash.getMountPoint(fiDir.canonicalFilePath()), mp);
2506
//creates a temporary file inside temporary dir
2507
QTemporaryFile file (fiDir.canonicalFilePath() + QDir::separator());
2508
QCOMPARE(file.open(), true);
2510
QCOMPARE(trash.getMountPoint(file.fileName()), mp);
2516
QTemporaryFile homeFile (QDir::homePath() + QDir::separator());
2517
QCOMPARE(homeFile.open(), true);
2519
QString homeTrashDir = trash.suitableTrash(homeFile.fileName());
2520
QCOMPARE(homeTrashDir, trash.homeTrash());
2523
homeTrashDir = trash.suitableTrash(QDir::homePath());
2524
QVERIFY(homeTrashDir != trash.homeTrash());
2526
//file under home Trash
2527
QTemporaryFile cannotMoveTotrash(trash.homeTrash() + QDir::separator());
2528
QCOMPARE(cannotMoveTotrash.open(), true);
2529
cannotMoveTotrash.close();
2530
QCOMPARE(trash.suitableTrash(cannotMoveTotrash.fileName()).isEmpty(), true);
2532
QStringList trashes = trash.allTrashes();
2533
qWarning() << "return from allTrashes():" << trashes;
2535
QVERIFY(trashes.count() > 0);
2537
qDebug() << "QStandardPaths::CacheLocation" << QStandardPaths::standardLocations(QStandardPaths::CacheLocation);
2538
qDebug() << "QStandardPaths::DataLocation" << QStandardPaths::standardLocations(QStandardPaths::DataLocation);
2539
qDebug() << "QStandardPaths::GenericCacheLocation" << QStandardPaths::standardLocations(QStandardPaths::GenericCacheLocation);
2540
qDebug() << "QStandardPaths::GenericDataLocation" << QStandardPaths::standardLocations(QStandardPaths::GenericDataLocation);
2544
void TestDirModel::locationFactory()
2546
LocationsFactory factoryLocations(this);
2547
const Location *location = 0;
2549
QString validTrashURL(LocationUrl::TrashRootURL);
2551
#if 0 // "sheme:/" (single slash) is no longer supported
2552
location = factoryLocations.setNewPath("trash:/");
2554
QVERIFY(location->isTrashDisk());
2555
QCOMPARE(location->info()->absoluteFilePath(), validTrashURL);
2556
QCOMPARE(location->urlPath(), validTrashURL);
2557
QCOMPARE(location->isRoot(), true);
2560
location = factoryLocations.setNewPath("trash://");
2562
QVERIFY(location->isTrashDisk());
2563
QCOMPARE(location->info()->absoluteFilePath(), validTrashURL);
2564
QCOMPARE(location->urlPath(), validTrashURL);
2565
QCOMPARE(location->isRoot(), true);
2567
location = factoryLocations.setNewPath("trash:///");
2569
QVERIFY(location->isTrashDisk());
2570
QCOMPARE(location->info()->absoluteFilePath(), validTrashURL);
2571
QCOMPARE(location->urlPath(), validTrashURL);
2572
QCOMPARE(location->isRoot(), true);
2574
location = factoryLocations.setNewPath("trash://////");
2576
QVERIFY(location->isTrashDisk());
2577
QCOMPARE(location->info()->absoluteFilePath(), validTrashURL);
2578
QCOMPARE(location->urlPath(), validTrashURL);
2579
QCOMPARE(location->isRoot(), true);
2581
#if 0 // "sheme:/" (single slash) is no longer supported
2582
QString myDir("___myDir_must_NOT_EXIST___");
2583
location = factoryLocations.setNewPath(QString("trash:/") + myDir);
2584
QVERIFY(location == 0);
2587
location = factoryLocations.setNewPath("file://////");
2589
QVERIFY(location->isLocalDisk());
2590
QCOMPARE(location->info()->absoluteFilePath(), QDir::rootPath());
2591
QCOMPARE(location->urlPath(), QDir::rootPath());
2592
QCOMPARE(location->isRoot(), true);
2594
location = factoryLocations.setNewPath("/");
2596
QVERIFY(location->isLocalDisk());
2597
QCOMPARE(location->info()->absoluteFilePath(), QDir::rootPath());
2598
QCOMPARE(location->urlPath(), QDir::rootPath());
2599
QCOMPARE(location->isRoot(), true);
2601
location = factoryLocations.setNewPath("//");
2603
QVERIFY(location->isLocalDisk());
2604
QCOMPARE(location->info()->absoluteFilePath(), QDir::rootPath());
2605
QCOMPARE(location->urlPath(), QDir::rootPath());
2606
QCOMPARE(location->isRoot(), true);
2608
location = factoryLocations.setNewPath("//bin");
2610
QVERIFY(location->isLocalDisk());
2611
QCOMPARE(location->info()->absoluteFilePath(), QLatin1String("/bin"));
2612
QCOMPARE(location->urlPath(), QLatin1String("/bin"));
2613
QCOMPARE(location->isRoot(), false);
2616
QString dirName("trashDirectory");
2617
m_deepDir_01 = new DeepDir(dirName,0);
2619
//create a Trash to have
2621
::setenv("XDG_DATA_HOME", m_deepDir_01->path().toLocal8Bit().constData(), true );
2622
QString xdgTrashDir(trash.homeTrash());
2623
QCOMPARE(trash.validate(xdgTrashDir, true), true);
2624
QCOMPARE(trash.homeTrash() , xdgTrashDir);
2626
QString trash3("trash:///Dir1/Dir2/Dir3");
2627
QString trash2("trash:///Dir1/Dir2");
2628
QString trash1("trash:///Dir1");
2630
QCOMPARE(QDir().mkpath(QTrashUtilInfo::filesTrashDir(xdgTrashDir) + "/Dir1/Dir2/Dir3"), true);
2633
//create a empty .trashinfo file to validate the Trash
2634
QFile trashinfo (QTrashUtilInfo::infoTrashDir(xdgTrashDir) + "/Dir1.trashinfo");
2635
QCOMPARE(trashinfo.open(QFile::WriteOnly), true);
2638
location = factoryLocations.setNewPath(trash3);
2639
Location * myLocation = const_cast<Location*> (location);
2640
QCOMPARE(myLocation->becomeParent(), true);
2641
QCOMPARE(location->urlPath(), trash2);
2642
QCOMPARE(location->isRoot(), false);
2644
location = factoryLocations.setNewPath(trash2);
2645
myLocation = const_cast<Location*> (location);
2646
QCOMPARE(myLocation->becomeParent(), true);
2647
QCOMPARE(location->urlPath(), trash1);
2648
QCOMPARE(location->isRoot(), false);
2650
myLocation = const_cast<Location*> (location);
2651
QCOMPARE(myLocation->becomeParent(), true);
2652
QCOMPARE(location->urlPath(), LocationUrl::TrashRootURL);
2653
QCOMPARE(location->isRoot(), true);
2658
void TestDirModel::moveOneFileToTrashAndRestore()
2660
QString orig("moveFilesTrash");
2661
m_deepDir_01 = new DeepDir(orig, 0);
2662
const int createdFiles = 4;
2663
TempFiles tempfiles;
2664
tempfiles.addSubDirLevel(orig);
2665
tempfiles.create(createdFiles);
2667
m_dirModel_01->setPath(m_deepDir_01->path());
2668
QTest::qWait(TIME_TO_REFRESH_DIR);
2669
QCOMPARE(m_dirModel_01->rowCount(), createdFiles);
2671
QString tempTrash("tempTrashDir");
2672
m_deepDir_02 = new DeepDir(tempTrash, 0);
2673
createTempHomeTrashDir(m_deepDir_02->path());
2675
// move item to Trash
2676
m_dirModel_01->moveIndexToTrash(0);
2677
QTest::qWait(TIME_TO_REFRESH_DIR);
2678
QCOMPARE(m_dirModel_01->rowCount(), createdFiles -1);
2680
//use another DirModel instance and point it to Trash
2681
m_dirModel_02->goTrash();
2682
QTest::qWait(TIME_TO_REFRESH_DIR);
2683
QCOMPARE(m_dirModel_02->rowCount(), 1);
2685
// now restore from Trash
2686
m_dirModel_02->restoreIndexFromTrash(0);
2687
QTest::qWait(TIME_TO_REFRESH_DIR);
2688
QCOMPARE(m_dirModel_02->rowCount(), 0);
2690
//using refresh to not depend from External File System Watcher
2691
if (m_dirModel_01->rowCount() != createdFiles)
2693
qWarning("using refresh() external File System Watcher did not get it right");
2694
m_dirModel_01->refresh();
2695
QTest::qWait(TIME_TO_REFRESH_DIR);
2697
QCOMPARE(m_dirModel_01->rowCount(), createdFiles);
2701
void TestDirModel::restoreTrashWithMultipleSources()
2703
DeepDir d_01("folder_01", 0);
2704
DeepDir d_02("folder_02", 0);
2705
DeepDir d_03("folder_03", 0);
2707
//create a temp trash
2708
QString tempTrash("tempTrashDir");
2709
m_deepDir_02 = new DeepDir(tempTrash, 0);
2710
createTempHomeTrashDir(m_deepDir_02->path());
2712
const int dirsCounter = 3;
2713
DeepDir * dirs [dirsCounter] = {&d_01, &d_02, &d_03};
2716
//move items from different sources to trash
2717
for(counter = 0; counter < dirsCounter; counter++)
2720
files.addSubDirLevel(dirs[counter]->path());
2721
QString name = QString("file_from_dir%1.txt").arg(counter);
2722
files.create(name, 1);
2724
model.setPath(dirs[counter]->path());
2725
QTest::qWait(TIME_TO_REFRESH_DIR);
2726
QCOMPARE(model.rowCount(), 1);
2727
model.selectionObject()->selectAll();
2728
model.moveSelectionToTrash();
2729
QTest::qWait(TIME_TO_REFRESH_DIR);
2730
QCOMPARE(model.rowCount(), 0);
2733
//another model points to temporary Trash
2734
connect(m_dirModel_02, SIGNAL(error(QString,QString)),
2735
this, SLOT(slotError(QString,QString)));
2736
m_dirModel_02->goTrash();
2737
QTest::qWait(TIME_TO_REFRESH_DIR);
2738
QCOMPARE(m_dirModel_02->rowCount(), dirsCounter);
2739
m_dirModel_02->restoreTrash();
2740
QTest::qWait(TIME_TO_REFRESH_DIR);
2741
QCOMPARE(m_dirModel_02->rowCount(), 0);
2743
//now look into info directories from trash, check if it is empty
2744
m_dirModel_02->setPath(m_deepDir_02->path());
2745
QTest::qWait(TIME_TO_REFRESH_DIR);
2746
QCOMPARE(m_dirModel_02->rowCount(), 1);
2747
QCOMPARE(m_dirModel_02->openPath("Trash"), true);
2748
QTest::qWait(TIME_TO_REFRESH_DIR);
2749
QCOMPARE(m_dirModel_02->openPath("info"), true);
2750
QTest::qWait(TIME_TO_REFRESH_DIR);
2751
QCOMPARE(m_dirModel_02->rowCount(), 0);
2753
//test it items were moved back to their sources
2754
for(counter = 0; counter < dirsCounter; counter++)
2757
model.setPath(dirs[counter]->path());
2758
QTest::qWait(TIME_TO_REFRESH_DIR);
2759
QCOMPARE(model.rowCount(), 1);
2762
QCOMPARE(m_receivedErrorSignal, false);
2766
void TestDirModel::emptyTrash()
2768
DeepDir d_01("folder_01", 0);
2769
DeepDir d_02("folder_02", 0);
2770
DeepDir d_03("folder_03", 0);
2772
//create a temp trash
2773
QString tempTrash("tempTrashDir");
2774
m_deepDir_02 = new DeepDir(tempTrash, 0);
2775
createTempHomeTrashDir(m_deepDir_02->path());
2777
const int dirsCounter = 3;
2778
DeepDir * dirs [dirsCounter] = {&d_01, &d_02, &d_03};
2781
//move items from different sources to trash
2782
for(counter = 0; counter < dirsCounter; counter++)
2785
files.addSubDirLevel(dirs[counter]->path());
2786
QString name = QString("file_from_dir%1.txt").arg(counter);
2787
files.create(name, 1);
2789
model.setPath(dirs[counter]->path());
2790
QTest::qWait(TIME_TO_REFRESH_DIR);
2791
QCOMPARE(model.rowCount(), 1);
2792
model.selectionObject()->selectAll();
2793
model.moveSelectionToTrash();
2794
QTest::qWait(TIME_TO_REFRESH_DIR);
2795
QCOMPARE(model.rowCount(), 0);
2798
//another model points to temporary Trash
2799
connect(m_dirModel_02, SIGNAL(error(QString,QString)),
2800
this, SLOT(slotError(QString,QString)));
2801
m_dirModel_02->goTrash();
2802
QTest::qWait(TIME_TO_REFRESH_DIR);
2803
QCOMPARE(m_dirModel_02->rowCount(), dirsCounter);
2804
m_dirModel_02->emptyTrash();
2805
QTest::qWait(TIME_TO_REFRESH_DIR);
2806
QCOMPARE(m_dirModel_02->rowCount(), 0);
2808
//now look into info directories from trash, check if it is empty
2809
m_dirModel_02->setPath(m_deepDir_02->path());
2810
QTest::qWait(TIME_TO_REFRESH_DIR);
2811
QCOMPARE(m_dirModel_02->rowCount(), 1);
2812
QCOMPARE(m_dirModel_02->openPath("Trash"), true);
2813
QTest::qWait(TIME_TO_REFRESH_DIR);
2814
QCOMPARE(m_dirModel_02->openPath("info"), true);
2815
QTest::qWait(TIME_TO_REFRESH_DIR);
2816
QCOMPARE(m_dirModel_02->rowCount(), 0);
2818
//test if original items folder is still empty
2819
for(counter = 0; counter < dirsCounter; counter++)
2822
model.setPath(dirs[counter]->path());
2823
QTest::qWait(TIME_TO_REFRESH_DIR);
2824
QCOMPARE(model.rowCount(), 0);
2827
QCOMPARE(m_receivedErrorSignal, false);
2832
void TestDirModel::diskCdIntoPathAbsolute()
2834
QString dirName("diskCdIntoPathAbsolute");
2835
m_deepDir_01 = new DeepDir(dirName,0);
2836
m_dirModel_01->setPath(m_deepDir_01->path());
2837
QTest::qWait(TIME_TO_REFRESH_DIR);
2838
bool ret = m_dirModel_01->cdIntoPath("/IT_MUST_NOT_EXIST/____IT_MUST_NOT_EXIST__");
2839
QCOMPARE(ret, false);
2840
ret = m_dirModel_01->cdIntoPath(QDir::homePath());
2841
QCOMPARE(ret , true);
2842
QCOMPARE(m_dirModel_01->path(), QDir::homePath());
2845
void TestDirModel::diskCdIntoPathRelative()
2847
QString dirName("diskCdIntoPathRelative");
2848
m_deepDir_01 = new DeepDir(dirName,1);
2849
m_dirModel_01->setPath(m_deepDir_01->path());
2850
QTest::qWait(TIME_TO_REFRESH_DIR);
2852
QModelIndex firstIdx = m_dirModel_01->index(0, 0);
2853
QString subdir = m_dirModel_01->data(firstIdx).toString();
2854
QString fullSubdir = m_deepDir_01->path() + QDir::separator() + subdir;
2855
bool ret = m_dirModel_01->cdIntoPath(subdir);
2856
QTest::qWait(TIME_TO_REFRESH_DIR);
2857
QCOMPARE(ret, true);
2858
QCOMPARE(m_dirModel_01->path(), fullSubdir);
2859
ret = m_dirModel_01->cdIntoPath("..");
2860
QTest::qWait(TIME_TO_REFRESH_DIR);
2861
QCOMPARE(ret, true);
2862
QCOMPARE(m_dirModel_01->path(), m_deepDir_01->path());
2867
void TestDirModel::trashCdIntoPathAbsolute()
2869
QString orig("trashCdIntoPathAbsolute");
2870
m_deepDir_01 = new DeepDir(orig, 1);
2871
m_dirModel_01->setPath(m_deepDir_01->path());
2872
QTest::qWait(TIME_TO_REFRESH_DIR);
2873
QCOMPARE(m_dirModel_01->rowCount() , 1);
2875
QString tempTrash("tempTrashDir");
2876
m_deepDir_02 = new DeepDir(tempTrash, 0);
2877
createTempHomeTrashDir(m_deepDir_02->path());
2879
QModelIndex firstIdx = m_dirModel_01->index(0, 0);
2881
QString subdirInTrash = LocationUrl::TrashRootURL +
2882
m_dirModel_01->data(firstIdx).toString();
2884
// move item to Trash
2885
m_dirModel_01->moveIndexToTrash(0);
2886
QTest::qWait(TIME_TO_REFRESH_DIR);
2889
bool ret = m_dirModel_01->cdIntoPath(subdirInTrash);
2890
QTest::qWait(TIME_TO_REFRESH_DIR);
2891
QCOMPARE(ret, true);
2892
QCOMPARE(m_dirModel_01->path(), subdirInTrash);
2896
void TestDirModel::trashCdIntoPathRelative()
2898
QString orig("trashCdIntoPathRelative");
2899
m_deepDir_01 = new DeepDir(orig, 1);
2900
m_dirModel_01->setPath(m_deepDir_01->path());
2901
QTest::qWait(TIME_TO_REFRESH_DIR);
2902
QCOMPARE(m_dirModel_01->rowCount() , 1);
2904
QString tempTrash("tempTrashDir");
2905
m_deepDir_02 = new DeepDir(tempTrash, 0);
2906
createTempHomeTrashDir(m_deepDir_02->path());
2908
QModelIndex firstIdx = m_dirModel_01->index(0, 0);
2909
QString subdir = m_dirModel_01->data(firstIdx).toString();
2910
QString subdirInTrash = LocationUrl::TrashRootURL + subdir;
2913
// move item to Trash
2914
m_dirModel_01->moveIndexToTrash(0);
2915
QTest::qWait(TIME_TO_REFRESH_DIR);
2917
bool ret = m_dirModel_01->cdIntoPath(LocationUrl::TrashRootURL);
2918
QTest::qWait(TIME_TO_REFRESH_DIR);
2919
QCOMPARE(ret, true);
2920
QCOMPARE(m_dirModel_01->path(), LocationUrl::TrashRootURL);
2923
ret = m_dirModel_01->cdIntoPath(subdir);
2924
QTest::qWait(TIME_TO_REFRESH_DIR);
2925
QCOMPARE(ret, true);
2926
QCOMPARE(m_dirModel_01->path(), subdirInTrash);
2931
void TestDirModel::smbCdIntoPathAbsolute()
2933
SmbItemInfo smbOK(LocationUrl::SmbURL);
2934
QCOMPARE(smbOK.isValid(), true);
2935
QCOMPARE(smbOK.isRoot(), true);
2936
QCOMPARE(smbOK.needsAuthentication(), false);
2937
QCOMPARE(smbOK.urlPath(), LocationUrl::SmbURL);
2939
if (SmbUserShare::canCreateShares())
2941
QString shareName("smbShareCdIntoPathAbsolute");
2943
TestQSambaSuite smbTest(this);
2945
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
2946
if (tmpShare.tempDir)
2948
tmpShare.tempDir->setAutoRemove(true);
2950
QString createdDir("createdDir");
2951
QString createDirFullPath = tmpShare.sharedDirPath + QDir::separator() + createdDir;
2952
bool ret = QDir().mkdir(createDirFullPath);
2953
QCOMPARE(ret , true);
2954
QString absUrl = LocationUrl::SmbURL + "localhost" +
2955
QDir::separator() + tmpShare.shareName +
2956
QDir::separator() + createdDir;
2958
ret = m_dirModel_01->cdIntoPath(absUrl);
2959
QTest::qWait(TIME_TO_PROCESS);
2960
QCOMPARE(ret, true);
2961
QCOMPARE(m_dirModel_01->path(), absUrl );
2965
void TestDirModel::smbCdIntoPathRelative()
2967
SmbItemInfo smbOK(LocationUrl::SmbURL);
2968
QCOMPARE(smbOK.isValid(), true);
2969
QCOMPARE(smbOK.isRoot(), true);
2970
QCOMPARE(smbOK.needsAuthentication(), false);
2971
QCOMPARE(smbOK.urlPath(), LocationUrl::SmbURL);
2972
if (SmbUserShare::canCreateShares())
2974
QString shareName("smbsmbCdIntoPathRelative");
2976
TestQSambaSuite smbTest(this);
2978
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
2979
if (tmpShare.tempDir)
2981
tmpShare.tempDir->setAutoRemove(true);
2983
QString createdDir1("createdDir1");
2984
QString createdDir2("createdDir2");
2985
QString createDirFullPath = tmpShare.sharedDirPath + QDir::separator() + createdDir1
2986
+ QDir::separator() + createdDir2;
2987
bool ret = QDir().mkpath(createDirFullPath);
2988
QCOMPARE(ret , true);
2989
QString absUrl = LocationUrl::SmbURL + "localhost" +
2990
QDir::separator() + tmpShare.shareName +
2991
QDir::separator() + createdDir1;
2993
ret = m_dirModel_01->cdIntoPath(absUrl);
2994
QTest::qWait(TIME_TO_PROCESS);
2995
QCOMPARE(ret, true);
2996
QCOMPARE(m_dirModel_01->path(), absUrl );
2997
QCOMPARE(m_dirModel_01->rowCount() , 1);
3000
absUrl += QDir::separator() + createdDir2;
3001
ret = m_dirModel_01->cdIntoPath(createdDir2);
3002
QTest::qWait(TIME_TO_PROCESS);
3003
QCOMPARE(ret, true);
3004
QCOMPARE(m_dirModel_01->path(), absUrl );
3005
QCOMPARE(m_dirModel_01->rowCount() , 0);
3010
* \brief TestDirModel::smbExistsDir() Tests for DirModel::existsDir() regarding Samba
3012
void TestDirModel::smbExistsDir()
3014
CHECK_IF_CAN_CREATE_SHARES();
3016
QString shareName("smbExistsDir");
3017
TestQSambaSuite smbTest(this);
3018
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3019
if (tmpShare.tempDir)
3021
tmpShare.tempDir->setAutoRemove(true);
3023
QCOMPARE(tmpShare.status, true);
3025
//create a folder inside this share
3026
QString folderName("folder");
3027
SmbSharedPathAccess folder = tmpShare.createPathForItem(folderName);
3028
QCOMPARE(QDir().mkpath(folder.diskPathname), true);
3029
QCOMPARE(QFileInfo(folder.diskPathname).exists(), true);
3030
//set file mananer to browse the temp share
3031
m_dirModel_01->setPath(tmpShare.url);
3032
QTest::qWait(TIME_TO_REFRESH_DIR);
3033
QCOMPARE(m_dirModel_01->rowCount() , 2); //temp shares are created with a file in it
3034
// check if the folder exists using relative name only
3035
QCOMPARE(m_dirModel_01->existsDir(folderName), true);
3036
// check it again using the full samba url
3037
QCOMPARE(m_dirModel_01->existsDir(folder.smbUrl), true);
3039
// check for a relative folder that does not exist
3040
QString notExist("_I_Hope_it_does_not_exist");
3041
QCOMPARE(m_dirModel_01->existsDir(notExist), false);
3042
QString fullSmbUrl(tmpShare.url + QDir::separator() + notExist);
3043
QCOMPARE(m_dirModel_01->existsDir(fullSmbUrl), false);
3047
* \brief TestDirModel::smbCanReadDir() Tests for DirModel::canReadDir() regading Samba
3049
void TestDirModel::smbCanReadDir()
3051
CHECK_IF_CAN_CREATE_SHARES();
3053
QString shareName("smbCanReadDir");
3054
TestQSambaSuite smbTest(this);
3055
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3056
if (tmpShare.tempDir)
3058
tmpShare.tempDir->setAutoRemove(true);
3060
QCOMPARE(tmpShare.status, true);
3062
//create a folder inside this share
3063
QString folderName("folder");
3064
SmbSharedPathAccess folder = tmpShare.createPathForItem(folderName);
3065
QCOMPARE(QDir().mkpath(folder.diskPathname), true);
3066
QCOMPARE(QFileInfo(folder.diskPathname).exists(), true);
3067
//set file mananer to browse the temp share
3068
m_dirModel_01->setPath(tmpShare.url);
3069
QTest::qWait(TIME_TO_REFRESH_DIR);
3070
QCOMPARE(m_dirModel_01->rowCount() , 2); //temp shares are created with a file in it
3071
QFile::Permissions folderOriginalPermissions = QFileInfo(folder.diskPathname).permissions();
3072
//first negative tests
3073
//change the permission to No Read
3074
bool ok = QFile::setPermissions(folder.diskPathname, QFile::WriteOwner | QFile::ExeOwner);
3076
// check using relative name only
3077
QCOMPARE(m_dirModel_01->canReadDir(folderName), false);
3078
// check it again using the full samba url
3079
QCOMPARE(m_dirModel_01->canReadDir(folder.smbUrl), false);
3081
// check for a relative folder that does not exist
3082
QString notExist("_I_Hope_it_does_not_exist");
3083
QCOMPARE(m_dirModel_01->canReadDir(notExist), false);
3084
QString fullSmbUrl(tmpShare.url + QDir::separator() + notExist);
3085
QCOMPARE(m_dirModel_01->canReadDir(fullSmbUrl), false);
3086
//now positive tests
3087
//give Read permission
3088
ok = QFile::setPermissions(folder.diskPathname, folderOriginalPermissions);
3090
// check using relative name only
3091
QCOMPARE(m_dirModel_01->canReadDir(folderName), true);
3092
// check it again using the full samba url
3093
QCOMPARE(m_dirModel_01->canReadDir(folder.smbUrl), true);
3098
* \brief TestDirModel::smbExistsFile() Tests for DirModel::existsFile() regading Samba
3100
void TestDirModel::smbExistsFile()
3102
CHECK_IF_CAN_CREATE_SHARES();
3104
QString shareName("smbExistsFile");
3105
TestQSambaSuite smbTest(this);
3106
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3107
if (tmpShare.tempDir)
3109
tmpShare.tempDir->setAutoRemove(true);
3111
QCOMPARE(tmpShare.status, true);
3112
//create a file inside this share
3113
QString fileName("fileTest.txt");
3114
SmbSharedPathAccess file = tmpShare.createPathForItem(fileName);
3115
QCOMPARE(QFileInfo(file.diskPathname).exists(), false);
3116
//set file mananer to browse the temp share
3117
m_dirModel_01->setPath(tmpShare.url);
3118
QTest::qWait(TIME_TO_REFRESH_DIR);
3119
QCOMPARE(m_dirModel_01->rowCount() , 1); //temp shares are created with a file in it
3120
//negative tests, file does not exist
3121
//using relative path
3122
QCOMPARE(m_dirModel_01->existsFile(fileName), false);
3123
//using absolute path
3124
QCOMPARE(m_dirModel_01->existsFile(file.smbUrl), false);
3125
//positive tests, file exists
3126
m_dirModel_01->goHome();
3127
QTest::qWait(TIME_TO_REFRESH_DIR);
3128
//now create the file
3129
QFile f(file.diskPathname);
3130
QCOMPARE(f.open(QFile::WriteOnly), true);
3132
//set file mananer to browse the temp share
3133
m_dirModel_01->setPath(tmpShare.url);
3134
QTest::qWait(TIME_TO_REFRESH_DIR);
3135
QCOMPARE(m_dirModel_01->rowCount() , 2); //temp shares are created with a file in it
3136
//using relative path
3137
QCOMPARE(m_dirModel_01->existsFile(fileName), true);
3138
//using absolute path
3139
QCOMPARE(m_dirModel_01->existsFile(file.smbUrl), true);
3143
void TestDirModel::smbCanReadFile()
3145
CHECK_IF_CAN_CREATE_SHARES();
3147
QString shareName("smbCanReadFile");
3148
TestQSambaSuite smbTest(this);
3149
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3150
if (tmpShare.tempDir)
3152
tmpShare.tempDir->setAutoRemove(true);
3154
QCOMPARE(tmpShare.status, true);
3156
//create a file inside this share
3157
QString fileName("fileTest.txt");
3158
SmbSharedPathAccess file = tmpShare.createPathForItem(fileName);
3159
QFile f(file.diskPathname);
3160
QCOMPARE(f.open(QFile::WriteOnly), true);
3162
QCOMPARE(QFileInfo(file.diskPathname).exists(), true);
3163
//set file mananer to browse the temp share
3164
m_dirModel_01->setPath(tmpShare.url);
3165
QTest::qWait(TIME_TO_REFRESH_DIR);
3166
QCOMPARE(m_dirModel_01->rowCount() , 2); //temp shares are created with a file in it
3167
QFile::Permissions fileOriginalPermissions = QFileInfo(file.diskPathname).permissions();
3168
//first negative tests
3169
//change the permission to No Read
3170
bool ok = QFile::setPermissions(file.diskPathname, QFile::WriteOwner | QFile::ExeOwner);
3173
// this block was commented due to libsmbclient always bring "read" flag in its stat() functions
3175
// check using relative name only
3176
QCOMPARE(m_dirModel_01->canReadFile(fileName), false);
3177
// check it again using the full samba url
3178
QCOMPARE(m_dirModel_01->canReadFile(file.smbUrl), false);
3182
// check for a relative folder that does not exist
3183
QString notExist("_I_Hope_it_does_not_exist");
3184
QCOMPARE(m_dirModel_01->canReadFile(notExist), false);
3185
QString fullSmbUrl(tmpShare.url + QDir::separator() + notExist);
3186
QCOMPARE(m_dirModel_01->canReadFile(fullSmbUrl), false);
3187
//now positive tests
3188
//give Read permission
3189
ok = QFile::setPermissions(file.diskPathname, fileOriginalPermissions);
3191
// check using relative name only
3192
QCOMPARE(m_dirModel_01->canReadFile(fileName), true);
3193
// check it again using the full samba url
3194
QCOMPARE(m_dirModel_01->canReadFile(file.smbUrl), true);
3198
* \brief TestDirModel::smbMkdir() Tests for DirModel::mkdir() regarding Samba
3200
void TestDirModel::smbMkdir()
3202
CHECK_IF_CAN_CREATE_SHARES();
3204
QString shareName("smbMkdir");
3205
TestQSambaSuite smbTest(this);
3206
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3207
if (tmpShare.tempDir)
3209
tmpShare.tempDir->setAutoRemove(true);
3211
QCOMPARE(tmpShare.status, true);
3212
//set file mananer to browse the temp share
3213
m_dirModel_01->setPath(tmpShare.url);
3214
QTest::qWait(TIME_TO_REFRESH_DIR);
3215
QCOMPARE(m_dirModel_01->rowCount() , 1);
3217
QString folder1Str("folder1");
3218
QString folder2Str("folder2");
3219
SmbSharedPathAccess folder1 = tmpShare.createPathForItem(folder1Str);
3220
SmbSharedPathAccess folder2 = tmpShare.createPathForItem(folder2Str);
3221
//using disk make sure folder1 does not exist
3222
QCOMPARE(QFileInfo(folder1.diskPathname).exists(), false);
3223
//create folder1 using relative path
3224
QCOMPARE(m_dirModel_01->mkdir(folder1Str), true);
3225
QTest::qWait(TIME_TO_REFRESH_DIR);
3226
QCOMPARE(m_dirModel_01->rowCount() , 2);
3227
QCOMPARE(QFileInfo(folder1.diskPathname).isDir(), true);
3228
//folder2 is created using full url
3229
QCOMPARE(QFileInfo(folder2.diskPathname).exists(), false);
3230
//create folder2 using full Samba URL
3231
QCOMPARE(m_dirModel_01->mkdir(folder2.smbUrl), true);
3232
QTest::qWait(TIME_TO_REFRESH_DIR);
3233
QCOMPARE(m_dirModel_01->rowCount() , 3);
3234
QCOMPARE(QFileInfo(folder2.diskPathname).isDir(), true);
3235
//check for full URL in the model items
3236
int counter = m_dirModel_01->rowCount() ;
3237
int found = 0; // look for folder1 and folder2 full url
3240
const DirItemInfo & item = m_dirModel_01->mDirectoryContents[counter];
3241
if (item.urlPath() == folder1.smbUrl || item.urlPath() == folder2.smbUrl)
3246
QCOMPARE(found, 2); //both folder1 and folder2 URLs are present
3250
* \brief TestDirModel::smbMakeBackupNameForCurrentItem() Tests making backup of items using copy
3252
* The similar test for item in local disk is modelCopyAndPasteToBackupFiles()
3254
void TestDirModel::smbMakeBackupNameForCurrentItem()
3256
CHECK_IF_CAN_CREATE_SHARES();
3258
QString shareName("smbMakeBackupNameForCurrentItem");
3259
TestQSambaSuite smbTest(this);
3260
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3261
if (tmpShare.tempDir)
3263
tmpShare.tempDir->setAutoRemove(true);
3265
QCOMPARE(tmpShare.status, true);
3266
//set file mananer to browse the temp share
3267
m_dirModel_01->setPath(tmpShare.url);
3268
QTest::qWait(TIME_TO_REFRESH_DIR);
3269
QCOMPARE(m_dirModel_01->rowCount() , 1);
3270
//copy existent file in the Samba share, index 0 refers to tmpShare.fileContent.smbUrl
3271
m_dirModel_01->copyIndex(0);
3272
//pasting in the same directory must create item to Copy(1)
3273
m_dirModel_01->paste();
3274
QTest::qWait(TIME_TO_REFRESH_DIR);
3275
QCOMPARE(m_dirModel_01->rowCount() , 2);
3276
//pasting again must create item to Copy(2)
3277
m_dirModel_01->paste();
3278
QTest::qWait(TIME_TO_REFRESH_DIR);
3279
QCOMPARE(m_dirModel_01->rowCount() , 3);
3280
int counter = m_dirModel_01->rowCount() ;
3282
QFile fileContent(tmpShare.fileContent.diskPathname);
3283
QCOMPARE(fileContent.open(QFile::ReadOnly), true);
3284
QByteArray fileContentBytes(fileContent.readAll());
3285
fileContent.close();
3286
char smbBuffer [fileContentBytes.size()];
3287
qint64 size = (qint64)fileContentBytes.size();
3290
const DirItemInfo & item = m_dirModel_01->mDirectoryContents[counter];
3291
//compare size content with the original file
3292
QCOMPARE(item.size(), size);
3293
SmbLocationItemFile smbFile(item.urlPath());
3294
QCOMPARE(smbFile.open(QFile::ReadOnly), true);
3295
QCOMPARE(smbFile.read(smbBuffer, size), size);
3297
QByteArray smbContentBytes((const char*)&smbBuffer, fileContentBytes.size());
3298
//files must have the same content
3299
QCOMPARE(smbContentBytes, fileContentBytes);
3300
//look for backuped names
3301
if (item.urlPath().contains("Copy(1)") || item.urlPath().contains("Copy(2)"))
3306
QCOMPARE(found, 2); //both backuped files were found
3310
* \brief TestDirModel::smbCopyFromSmb2Smb()
3312
* Creates a Samba Share in the local disk
3313
* Creates a directory tree with some files under smb://localhost/<tempShareName>/source
3314
* Copy its content to smb://localhost/<tempShareName>/target
3315
* Compares both directories using local disk correspondent path
3317
void TestDirModel::smbCopyFromSmb2Smb()
3319
CHECK_IF_CAN_CREATE_SHARES();
3321
QString shareName("smbCopyFromSmb2Smb");
3322
TestQSambaSuite smbTest(this);
3323
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3324
if (tmpShare.tempDir)
3326
tmpShare.tempDir->setAutoRemove(true);
3328
QCOMPARE(tmpShare.status, true);
3329
QString sourceFolderName("source");
3330
QString targetFolderName("target");
3331
SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem(sourceFolderName);
3332
SmbSharedPathAccess targeFolder = tmpShare.createPathForItem(targetFolderName);
3333
//create a soruce directory tree in the share
3334
DeepDir sdir(sourceFolder.diskPathname, 3);
3335
//create the destination folder
3336
DeepDir tdir(targeFolder.diskPathname, 0); // 0 level, just create the root directory
3340
* set file mananer to browse the source directory using Samba url
3342
m_dirModel_01->setPath(sourceFolder.smbUrl);
3343
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3344
QVERIFY(m_dirModel_01->rowCount() != 0);
3345
DirSelection *selection = m_dirModel_01->selectionObject();
3346
QVERIFY(selection != 0);
3347
selection->selectAll();
3348
QVERIFY(selection->counter() != 0);
3349
//copy the source folder using Samba URL
3350
m_dirModel_01->copySelection();
3351
//change directory to the target folder
3352
m_dirModel_01->setPath(targeFolder.smbUrl);
3353
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3354
QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
3355
m_dirModel_01->paste();
3356
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3357
QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
3358
//now compare directories source and target, permissions are not the same due to Samba Configuration
3359
QCOMPARE(compareDirectories(sourceFolder.diskPathname, targeFolder.diskPathname, false), true);
3363
void TestDirModel::smbCopyFromSmb2LocalDisk()
3365
CHECK_IF_CAN_CREATE_SHARES();
3367
QString shareName("smbCopyFromSmb2LocalDisk");
3368
TestQSambaSuite smbTest(this);
3369
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3370
if (tmpShare.tempDir)
3372
tmpShare.tempDir->setAutoRemove(true);
3374
QCOMPARE(tmpShare.status, true);
3375
QString sourceFolderName("source");
3376
QString targetFolderName("target");
3377
SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem(sourceFolderName);
3378
//create a soruce directory tree in the share
3379
DeepDir sdir(sourceFolder.diskPathname, 3);
3380
//create the destination folder in the /tmp
3381
DeepDir targetLocalDisk(targetFolderName, 0); // 0 level, just create the root directory
3384
* set file mananer to browse the source directory using Samba url
3386
m_dirModel_01->setPath(sourceFolder.smbUrl);
3387
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3388
QVERIFY(m_dirModel_01->rowCount() != 0);
3389
DirSelection *selection = m_dirModel_01->selectionObject();
3390
QVERIFY(selection != 0);
3391
selection->selectAll();
3392
QVERIFY(selection->counter() != 0);
3393
//copy the source folder using Samba URL
3394
m_dirModel_01->copySelection();
3395
//change directory to the target folder in the local disk
3396
m_dirModel_01->setPath(targetLocalDisk.path());
3397
QTest::qWait(TIME_TO_REFRESH_DIR);
3398
QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
3399
m_dirModel_01->paste();
3400
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3401
QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
3402
//now compare directories source and target, permissions are not the same due to Samba Configuration
3403
QCOMPARE(compareDirectories(sourceFolder.diskPathname, targetLocalDisk.path(), false), true);
3407
void TestDirModel::smbCopyFromLocalDisk2Smb()
3409
CHECK_IF_CAN_CREATE_SHARES();
3411
QString shareName("smbCopyFromLocalDisk2Smb");
3412
TestQSambaSuite smbTest(this);
3413
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3414
if (tmpShare.tempDir)
3416
tmpShare.tempDir->setAutoRemove(true);
3418
QCOMPARE(tmpShare.status, true);
3419
QString sourceFolderName("source");
3420
QString targetFolderName("target");
3421
SmbSharedPathAccess targeFolder = tmpShare.createPathForItem(targetFolderName);
3422
//create a soruce directory tree in /tmp
3423
DeepDir diskDir(sourceFolderName, 3);
3424
//create the destination folder in the share
3425
DeepDir tdir(targeFolder.diskPathname, 0); // 0 level, just create the root directory
3428
* set file mananer to browse the source in the /tmp
3430
m_dirModel_01->setPath(diskDir.path());
3431
QTest::qWait(TIME_TO_REFRESH_DIR);
3432
QVERIFY(m_dirModel_01->rowCount() != 0);
3433
DirSelection *selection = m_dirModel_01->selectionObject();
3434
QVERIFY(selection != 0);
3435
selection->selectAll();
3436
QVERIFY(selection->counter() != 0);
3437
//copy the source folder using file:// URLs
3438
m_dirModel_01->copySelection();
3439
//change directory to the target folder
3440
m_dirModel_01->setPath(targeFolder.smbUrl);
3441
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3442
QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
3443
m_dirModel_01->paste();
3444
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3445
QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
3446
//now compare directories source and target, permissions are not the same due to Samba Configuration
3447
QCOMPARE(compareDirectories(diskDir.path(), targeFolder.diskPathname, false), true);
3451
void TestDirModel::smbRemoveDirectory()
3453
CHECK_IF_CAN_CREATE_SHARES();
3455
QString shareName("smbRemoveDirectory");
3456
TestQSambaSuite smbTest(this);
3457
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3458
if (tmpShare.tempDir)
3460
tmpShare.tempDir->setAutoRemove(true);
3462
QCOMPARE(tmpShare.status, true);
3463
SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem("source");
3464
//create a directory tree with items in the local disk shared as Samba share
3465
DeepDir diskDir(sourceFolder.diskPathname, 3);
3468
* set file mananer to browse the source in the Samba share
3470
m_dirModel_01->setPath(sourceFolder.smbUrl);
3471
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3472
QVERIFY(m_dirModel_01->rowCount() != 0);
3473
DirSelection *selection = m_dirModel_01->selectionObject();
3474
QVERIFY(selection != 0);
3475
selection->selectAll();
3476
QVERIFY(selection->counter() != 0);
3477
m_dirModel_01->removeSelection();
3478
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3479
QCOMPARE(m_dirModel_01->rowCount() , 0); // now it is empty
3483
void TestDirModel::smbCutFromSmb2Smb()
3485
CHECK_IF_CAN_CREATE_SHARES();
3487
QString shareName("smbCutFromSmb2Smb");
3488
TestQSambaSuite smbTest(this);
3489
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3490
if (tmpShare.tempDir)
3492
tmpShare.tempDir->setAutoRemove(true);
3494
QCOMPARE(tmpShare.status, true);
3495
QString sourceFolderName("source");
3496
QString targetFolderName("target");
3497
SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem(sourceFolderName);
3498
SmbSharedPathAccess targeFolder = tmpShare.createPathForItem(targetFolderName);
3499
//create a soruce directory tree in the share
3500
DeepDir sdir(sourceFolder.diskPathname, 3);
3501
//create the destination folder
3502
DeepDir tdir(targeFolder.diskPathname, 0); // 0 level, just create the root directory
3506
* set file mananer to browse the source directory using Samba url
3508
m_dirModel_01->setPath(sourceFolder.smbUrl);
3509
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3510
QVERIFY(m_dirModel_01->rowCount() != 0);
3511
DirSelection *selection = m_dirModel_01->selectionObject();
3512
QVERIFY(selection != 0);
3513
selection->selectAll();
3514
QVERIFY(selection->counter() != 0);
3515
//cut the source folder using Samba URL
3516
m_dirModel_01->cutSelection();
3517
//change directory to the target folder
3518
m_dirModel_01->setPath(targeFolder.smbUrl);
3519
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3520
QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
3522
m_dirModel_01->paste();
3523
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3524
//check target directory is not empty
3525
QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
3526
//go back to the source samba url to make sure it is empty
3527
m_dirModel_01->setPath(sourceFolder.smbUrl);
3528
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3529
QCOMPARE(m_dirModel_01->rowCount(), 0);
3533
void TestDirModel::smbCutFromSmb2LocalDisk()
3535
CHECK_IF_CAN_CREATE_SHARES();
3537
QString shareName("smbCutFromSmb2LocalDisk");
3538
TestQSambaSuite smbTest(this);
3539
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3540
if (tmpShare.tempDir)
3542
tmpShare.tempDir->setAutoRemove(true);
3544
QCOMPARE(tmpShare.status, true);
3545
QString sourceFolderName("source");
3546
QString targetFolderName("diskTarget");
3547
SmbSharedPathAccess sourceFolder = tmpShare.createPathForItem(sourceFolderName);
3548
//create a soruce directory tree in the share
3549
DeepDir sdir(sourceFolder.diskPathname, 3);
3550
//create the destination folder
3551
DeepDir diskTarget(targetFolderName, 0); // 0 level, just create the root directory
3554
* set file mananer to browse the source directory using Samba url
3556
m_dirModel_01->setPath(sourceFolder.smbUrl);
3557
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3558
QVERIFY(m_dirModel_01->rowCount() != 0);
3559
DirSelection *selection = m_dirModel_01->selectionObject();
3560
QVERIFY(selection != 0);
3561
selection->selectAll();
3562
QVERIFY(selection->counter() != 0);
3563
//cut the source folder using Samba URL
3564
m_dirModel_01->cutSelection();
3565
//change directory to the target folder in the local disk
3566
m_dirModel_01->setPath(diskTarget.path());
3567
QTest::qWait(TIME_TO_REFRESH_DIR);
3568
QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
3570
m_dirModel_01->paste();
3571
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR); //removes from Samba, needs more time
3572
//check target directory is not empty
3573
QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
3574
//go back to the source samba url to make sure it is empty
3575
m_dirModel_01->setPath(sourceFolder.smbUrl);
3576
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3577
QCOMPARE(m_dirModel_01->rowCount(), 0);
3581
void TestDirModel::smbCutFromLocalDisk2Smb()
3583
CHECK_IF_CAN_CREATE_SHARES();
3585
QString shareName("smbCutFromLocalDisk2Smb");
3586
TestQSambaSuite smbTest(this);
3587
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3588
if (tmpShare.tempDir)
3590
tmpShare.tempDir->setAutoRemove(true);
3592
QCOMPARE(tmpShare.status, true);
3593
QString sourceFolderName("source");
3594
QString targetFolderName("sambaTarget");
3595
SmbSharedPathAccess targetFolder = tmpShare.createPathForItem(targetFolderName);
3596
//create a soruce directory tree in the share
3597
DeepDir sdir(sourceFolderName, 3);
3598
//create the destination folder
3599
DeepDir smbTarget(targetFolder.diskPathname, 0); // 0 level, just create the root directory
3600
Q_UNUSED(smbTarget);
3602
* set file mananer to browse the source directory in the local disk
3604
m_dirModel_01->setPath(sdir.path());
3605
QTest::qWait(TIME_TO_REFRESH_DIR);
3606
QVERIFY(m_dirModel_01->rowCount() != 0);
3607
DirSelection *selection = m_dirModel_01->selectionObject();
3608
QVERIFY(selection != 0);
3609
selection->selectAll();
3610
QVERIFY(selection->counter() != 0);
3611
//cut the source folder using local disk
3612
m_dirModel_01->cutSelection();
3613
//change directory to the target folder in Samba share
3614
m_dirModel_01->setPath(targetFolder.smbUrl);
3615
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3616
QCOMPARE(m_dirModel_01->rowCount() , 0); // so far it is empty
3618
m_dirModel_01->paste();
3619
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3620
//check target directory is not empty
3621
QVERIFY(m_dirModel_01->rowCount() != 0); //no longer empty
3622
//go back to the source local disk make sure it is empty
3623
m_dirModel_01->setPath(sdir.path());
3624
QTest::qWait(TIME_TO_REFRESH_DIR);
3625
QCOMPARE(m_dirModel_01->rowCount(), 0);
3629
void TestDirModel::smbDownloadEmptyFile()
3631
CHECK_IF_CAN_CREATE_SHARES();
3633
QString shareName("smbDownloadEmptyFile");
3634
TestQSambaSuite smbTest(this);
3635
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3636
if (tmpShare.tempDir)
3638
tmpShare.tempDir->setAutoRemove(true);
3640
QCOMPARE(tmpShare.status, true);
3642
// temp shares are created with a unique file there with some content
3643
// this test just rewrite this file with no content
3644
QFile empty (tmpShare.fileContent.diskPathname) ;
3645
QCOMPARE(empty.open(QFile::WriteOnly | QFile::Truncate), true);
3647
//make sure the file is empty
3648
QFileInfo sourceInfo(tmpShare.fileContent.diskPathname);
3649
QCOMPARE(sourceInfo.size(), (qint64)0);
3651
m_dirModel_01->setPath(tmpShare.url);
3652
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3653
QVERIFY(m_dirModel_01->rowCount() != 0);
3655
const DirItemInfo & item = m_dirModel_01->mDirectoryContents.at(0);
3656
QCOMPARE(item.isFile(), true);
3657
QVERIFY(item.size() == 0);
3659
QString tmpFile(QDir::tempPath() + QDir::separator() + "_empty_file.ttt");
3661
QCOMPARE(m_dirModel_01->downloadAndSaveAs(0, tmpFile), true);
3662
QTest::qWait(TIME_TO_PROCESS);
3664
QFileInfo targetInfo(tmpFile);
3665
QCOMPARE(targetInfo.exists(), true);
3666
QCOMPARE(targetInfo.size(), (qint64)0);
3670
void TestDirModel::smbDownloadBigFileWithNoSpace()
3672
CHECK_IF_CAN_CREATE_SHARES();
3674
QString shareName("smbDownloadBigFileWithNoSpace");
3675
TestQSambaSuite smbTest(this);
3676
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3677
if (tmpShare.tempDir)
3679
tmpShare.tempDir->setAutoRemove(true);
3681
QCOMPARE(tmpShare.status, true);
3683
m_dirModel_01->setPath(tmpShare.url);
3684
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3685
QVERIFY(m_dirModel_01->rowCount() != 0);
3687
const DirItemInfo & item = m_dirModel_01->mDirectoryContents.at(0);
3688
QCOMPARE(item.isFile(), true);
3689
QVERIFY(item.size() > 0);
3691
FakeDirItemInfoBigSize bigSize(item);
3693
QString tmpFile(QDir::tempPath() + QDir::separator() + "_it_does_not_have_space.ttt");
3694
QCOMPARE(m_dirModel_01->m_fsAction->downloadAndSaveAs(bigSize, tmpFile) , false);
3698
void TestDirModel::smbDownloadFile()
3700
CHECK_IF_CAN_CREATE_SHARES();
3702
QString shareName("smbDownloadFile");
3703
TestQSambaSuite smbTest(this);
3704
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3705
if (tmpShare.tempDir)
3707
tmpShare.tempDir->setAutoRemove(true);
3709
QCOMPARE(tmpShare.status, true);
3711
// temp shares are created with a unique file there with some content
3712
QFileInfo sourceInfo(tmpShare.fileContent.diskPathname);
3714
m_dirModel_01->setPath(tmpShare.url);
3715
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3716
QVERIFY(m_dirModel_01->rowCount() != 0);
3718
const DirItemInfo & item = m_dirModel_01->mDirectoryContents.at(0);
3719
QCOMPARE(item.isFile(), true);
3720
QVERIFY(item.size() > 0);
3722
QString tmpFile(QDir::tempPath() + QDir::separator() + "_it_can_exist_always_overwritten.ttt");
3724
QCOMPARE(m_dirModel_01->downloadAndSaveAs(0, tmpFile), true);
3725
QTest::qWait(TIME_TO_PROCESS);
3727
QFileInfo targetInfo(tmpFile);
3728
QCOMPARE(targetInfo.exists(), true);
3730
QCOMPARE(sourceInfo.size(), targetInfo.size());
3734
void TestDirModel::smbDownloadAsTemporary()
3736
CHECK_IF_CAN_CREATE_SHARES();
3738
QString shareName("smbDownloadAsTemporary");
3739
TestQSambaSuite smbTest(this);
3740
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3741
if (tmpShare.tempDir)
3743
tmpShare.tempDir->setAutoRemove(true);
3745
QCOMPARE(tmpShare.status, true);
3747
// temp shares are created with a unique file there with some content
3748
QFileInfo sourceInfo(tmpShare.fileContent.diskPathname);
3750
m_temporaryDownloadName.clear();
3751
connect(m_dirModel_01, SIGNAL(downloadTemporaryComplete(QString)),
3752
this, SLOT(onDownloadTemporaryComplete(QString)));
3754
m_dirModel_01->setPath(tmpShare.url);
3755
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3756
QVERIFY(m_dirModel_01->rowCount() != 0);
3758
QCOMPARE(m_dirModel_01->downloadAsTemporaryFile(0), true);
3759
QTest::qWait(TIME_TO_PROCESS);
3761
QCOMPARE(m_temporaryDownloadName.isEmpty(), false);
3763
QFileInfo targetInfo(m_temporaryDownloadName);
3764
QCOMPARE(targetInfo.exists(), true);
3765
QCOMPARE(sourceInfo.size(), targetInfo.size());
3766
qDebug() << "downloaded temp file as:" << targetInfo.absoluteFilePath();
3770
void TestDirModel::smbDownloadIntoStandardDownloadLocation()
3772
CHECK_IF_CAN_CREATE_SHARES();
3774
QString shareName("smbDownloadIntoStandardDownloadLocation");
3775
TestQSambaSuite smbTest(this);
3776
ShareCreationStatus tmpShare(smbTest.createTempShare(shareName));
3777
if (tmpShare.tempDir)
3779
tmpShare.tempDir->setAutoRemove(true);
3781
QCOMPARE(tmpShare.status, true);
3783
// temp shares are created with a unique file there with some content
3784
QFileInfo sourceInfo(tmpShare.fileContent.diskPathname);
3786
QString dowloadFullPath(QStandardPaths::writableLocation(QStandardPaths::DownloadLocation) +
3787
QDir::separator() + sourceInfo.fileName() );
3789
QFile f(dowloadFullPath);
3792
//make sure target does not exist
3793
QCOMPARE(QFileInfo(dowloadFullPath).exists(), false);
3795
m_dirModel_01->setPath(tmpShare.url);
3796
QTest::qWait(TIME_TO_REFRESH_REMOTE_DIR);
3797
QVERIFY(m_dirModel_01->rowCount() != 0);
3799
QCOMPARE(m_dirModel_01->download(0), true);
3800
QTest::qWait(TIME_TO_PROCESS);
3802
QFileInfo targetInfo(dowloadFullPath);
3803
QCOMPARE(targetInfo.exists(), true);
3804
QCOMPARE(sourceInfo.size(), targetInfo.size());
3805
qDebug() << "downloaded:" << targetInfo.absoluteFilePath();
3808
int main(int argc, char *argv[])
3810
QApplication app(argc, argv);
3812
QStringList args = QCoreApplication::arguments();
3813
int count = args.count();
3816
//Ubuntu Touch parameter
3817
if (args.at(count).startsWith(QLatin1String("--desktop_file_hint")))
3819
args.removeAt(count);
3823
int ret = QTest::qExec(&tc, args);
3824
//if not running specific tests, run Samba test suite
3825
if (args.count() == 1)
3827
if (SmbUserShare::canCreateShares())
3829
printf("\n********* Samba tests ********\n");
3830
TestQSambaSuite smbTest;
3831
ret |= QTest::qExec(&smbTest, args);
3835
printf("\n\n********* Make sure Samba server is installed and up to run specific Samba tests ********\n");
3844
QByteArray md5FromIcon(const QIcon& icon)
3849
QPixmap pix = icon.pixmap(QSize(48,48));
3850
QImage image = pix.toImage();
3851
if (!image.isNull())
3853
const uchar *bits = image.bits();
3854
const char *bytes = reinterpret_cast<const char*> (bits);
3855
QByteArray bytesArray(bytes, image.byteCount());
3856
ret = QCryptographicHash::hash(bytesArray, QCryptographicHash::Md5);
3862
QString createFileInTempDir(const QString& name, const char *content, qint64 size)
3865
QString fullName(QDir::tempPath() + QDir::separator() + name);
3866
QFile file(fullName);
3867
if (file.open(QFile::WriteOnly))
3869
if (file.write(content, size) == size)
3879
bool TestDirModel::createTempHomeTrashDir(const QString& existentDir)
3881
QDir d(existentDir);
3883
if (existentDir.startsWith(QDir::tempPath()) && (d.exists() || d.mkpath(existentDir)))
3886
::setenv("XDG_DATA_HOME", existentDir.toLocal8Bit().constData(), true );
3887
QString xdgTrashDir(trash.homeTrash());
3888
ret = trash.validate(xdgTrashDir, true);
3893
#if defined(Q_OS_UNIX)
3895
* \brief updateAndSetModificationTime()
3896
* updates the file content and sets its last modification time to another time
3898
* \param desiredTime some time less than current time
3899
* \return true if it could be performed, false otherwise
3901
bool updateAndSetModificationTime(const QString& filename, QDateTime& desiredTime)
3905
if (f.open(QFile::Append))
3907
QByteArray data("1234");
3908
if (f.write(data) == (qint64)data.size())
3911
struct timeval times[2] =
3913
{(long)desiredTime.toTime_t(), (long)desiredTime.time().msec()},
3914
{(long)desiredTime.toTime_t(), (long)desiredTime.time().msec()}
3916
QFileInfo info(filename);
3917
qDebug() << "last modification of" << info.fileName() << info.lastModified()
3918
<< "forcing it to" << desiredTime;
3919
if (::utimes( QFile::encodeName(filename).constData(), times) == 0)
3929
#include "tst_folderlistmodel.moc"