Added:
/trunk/tests/libs/TkUtil/FindFilesTests
Deleted:
/trunk/tests/libs/TkUtil/tests
Modified:
/trunk/libs/TkUtil/FindFiles.cpp
/trunk/libs/TkUtil/FindFiles.h
/trunk/quarkplayer-plugins/FileBrowser/FileSearchModel.cpp
/trunk/quarkplayer-plugins/FileBrowser/FileSearchModel.h
/trunk/quarkplayer-plugins/Playlist/PlaylistModel.cpp
/trunk/tests/libs/TkUtil/FindFilesTest.cpp
/trunk/tests/libs/TkUtil/FindFilesTest.h
=======================================
--- /trunk/libs/TkUtil/FindFiles.cpp Fri Aug 13 02:18:04 2010
+++ /trunk/libs/TkUtil/FindFiles.cpp Tue May 31 13:58:07 2011
@@ -28,7 +28,6 @@
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QTime>
-#include <QtCore/QMetaType>
#ifdef Q_WS_WIN
#include <windows.h>
@@ -44,8 +43,6 @@
FindFiles::FindFiles(QObject * parent)
: QThread(parent) {
- qRegisterMetaType<QUuid>("QUuid");
-
_findDirs = false;
_recursiveSearch = true;
_filesFoundLimit = DEFAULT_FILES_FOUND_LIMIT;
@@ -88,19 +85,17 @@
_stop = true;
wait();
}
-
-void FindFiles::start(const QUuid & uuid) {
- _uuid = uuid;
- QThread::start();
-}
void FindFiles::run() {
Q_ASSERT(!_path.isEmpty());
+#ifdef Q_WS_WIN
+ //Remove the last / under Windows
//C:/ -> C:
if (_path.endsWith('/') || _path.endsWith('\\')) {
_path = _path.left(_path.length() - 1);
}
+#endif //Q_WS_WIN
//Converts to native separators, otherwise FindFirstFile()
//under Windows won't work if '/' separators are found
@@ -133,13 +128,12 @@
if (!_stop) {
//Emits the signal for the remaining files found
if (!_files.isEmpty()) {
- emit filesFound(_files, _uuid);
+ emit filesFound(_files);
_files.clear();
}
-
- //Emits the last signal
- emit finished(timeElapsed.elapsed(), _uuid);
- }
+ }
+
+ emit finished(timeElapsed.elapsed());
}
void FindFiles::findAllFilesQt(const QString & path) {
@@ -156,7 +150,13 @@
break;
}
- QString fileName(path + QDir::separator() + name);
+ QString fileName;
+ if (path.endsWith(QDir::separator())) {
+ //Avoids / (or \) to be doubled in case path == "/"
+ fileName = path + name;
+ } else {
+ fileName = path + QDir::separator() + name;
+ }
if (TkFile::isDir(fileName)) {
//Filter directory matching the given pattern
@@ -179,7 +179,7 @@
if (_files.size() > _filesFoundLimit) {
//Emits the signal every _filesFoundLimit files found
if (!_stop) {
- emit filesFound(_files, _uuid);
+ emit filesFound(_files);
}
_files.clear();
}
@@ -221,7 +221,14 @@
}
QString name(QString::fromUtf16(reinterpret_cast<const unsigned short
*>(fileData.cFileName)));
- QString fileName(path + QDir::separator() + name);
+
+ QString fileName;
+ if (path.endsWith(QDir::separator())) {
+ //Avoids / (or \) to be doubled in case path == "/"
+ fileName = path + name;
+ } else {
+ fileName = path + QDir::separator() + name;
+ }
//Check if the object is a directory or not
if (fileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
@@ -249,7 +256,7 @@
if (_files.size() > _filesFoundLimit) {
//Emits the signal every _filesFoundLimit files found
if (!_stop) {
- emit filesFound(_files, _uuid);
+ emit filesFound(_files);
}
_files.clear();
}
@@ -298,7 +305,13 @@
//Avoid '.', '..' and other hidden files
if (!name.startsWith('.')) {
- QString fileName(path + QDir::separator() + name);
+ QString fileName;
+ if (path.endsWith(QDir::separator())) {
+ //Avoids / (or \) to be doubled in case path == "/"
+ fileName = path + name;
+ } else {
+ fileName = path + QDir::separator() + name;
+ }
if (TkFile::isDir(fileName)) {
//Filter directory matching the given pattern
@@ -321,7 +334,7 @@
if (_files.size() > _filesFoundLimit) {
//Emits the signal every _filesFoundLimit files found
if (!_stop) {
- emit filesFound(_files, _uuid);
+ emit filesFound(_files);
}
_files.clear();
}
=======================================
--- /trunk/libs/TkUtil/FindFiles.h Fri Aug 13 02:18:04 2010
+++ /trunk/libs/TkUtil/FindFiles.h Tue May 31 13:58:07 2011
@@ -22,7 +22,6 @@
#include <TkUtil/TkUtilExport.h>
#include <QtCore/QThread>
-#include <QtCore/QUuid>
#include <QtCore/QStringList>
#include <QtCore/QRegExp>
@@ -135,26 +134,23 @@
*/
void stop();
-public slots:
-
- void start(const QUuid & uuid);
-
signals:
/**
* Sends the signal every _filesFoundLimit files found.
*
* @param files list of files (full path fileName)
- * @param uuid each search has its own unique id
*/
- void filesFound(const QStringList & files, const QUuid & uuid);
+ void filesFound(const QStringList & files);
/**
* Sends the signal after all filesFound() signals, this is the last
signal sent.
*
- * Guaranteed to be sent only once.
+ * Guaranteed to be sent only once even if stop() has been called.
+ *
+ * @param timeElapsed number of milliseconds that have elapsed since the
last time start()
*/
- void finished(int timeElapsed, const QUuid & uuid);
+ void finished(int timeElapsed);
private:
@@ -227,8 +223,6 @@
*/
volatile bool _stop;
- QUuid _uuid;
-
/**
* Backend to use to search files, native or Qt way.
*/
=======================================
--- /trunk/quarkplayer-plugins/FileBrowser/FileSearchModel.cpp Mon Feb 21
09:03:06 2011
+++ /trunk/quarkplayer-plugins/FileBrowser/FileSearchModel.cpp Tue May 31
13:58:07 2011
@@ -385,9 +385,9 @@
//Lazy initialization
_findFiles = new FindFiles(this);
- connect(_findFiles, SIGNAL(filesFound(const QStringList &, const QUuid
&)),
- SLOT(filesFound(const QStringList &, const QUuid &)),
Qt::QueuedConnection);
- connect(_findFiles, SIGNAL(finished(int, const QUuid &)),
+ connect(_findFiles, SIGNAL(filesFound(const QStringList &)),
+ SLOT(filesFound(const QStringList &)), Qt::QueuedConnection);
+ connect(_findFiles, SIGNAL(finished(int)),
SIGNAL(searchFinished(int)), Qt::QueuedConnection);
}
@@ -409,8 +409,7 @@
Config::instance().value(Config::FINDFILES_BACKEND_KEY).toInt()));
//Starts a new search
- _currentSearchUuid = QUuid::createUuid();
- _findFiles->start(_currentSearchUuid);
+ _findFiles->start();
}
void FileSearchModel::stop() {
@@ -419,12 +418,7 @@
}
}
-void FileSearchModel::filesFound(const QStringList & files, const QUuid &
uuid) {
- if (_currentSearchUuid != uuid) {
- //filesFound() signal from a previous _findFiles, let's discards it
- return;
- }
-
+void FileSearchModel::filesFound(const QStringList & files) {
emit layoutAboutToBeChanged();
//Append the files
=======================================
--- /trunk/quarkplayer-plugins/FileBrowser/FileSearchModel.h Fri Aug 13
02:18:04 2010
+++ /trunk/quarkplayer-plugins/FileBrowser/FileSearchModel.h Tue May 31
13:58:07 2011
@@ -140,7 +140,7 @@
private slots:
- void filesFound(const QStringList & files, const QUuid & uuid);
+ void filesFound(const QStringList & files);
void updateMediaInfo(const MediaInfo & mediaInfo);
@@ -175,8 +175,6 @@
/** Used internally for tooltips. */
QString _rootSearchPath;
- QUuid _currentSearchUuid;
-
/** Icon provider: gives us the icons matching a file extension. */
QFileIconProvider _iconProvider;
=======================================
--- /trunk/quarkplayer-plugins/Playlist/PlaylistModel.cpp Wed Feb 23
17:15:29 2011
+++ /trunk/quarkplayer-plugins/Playlist/PlaylistModel.cpp Tue May 31
13:58:07 2011
@@ -360,16 +360,16 @@
//FIXME Use QSharedPointer here?
FindFiles * findFiles = new FindFiles(this);
- connect(findFiles, SIGNAL(filesFound(const QStringList &, const QUuid
&)),
+ connect(findFiles, SIGNAL(filesFound(const QStringList &)),
SLOT(filesFound(const QStringList &)));
- connect(findFiles, SIGNAL(finished(int, const QUuid &)),
+ connect(findFiles, SIGNAL(finished(int)),
SLOT(searchFinished(int)));
findFiles->setSearchPath(fileName);
findFiles->setFilesFoundLimit(500);
findFiles->setFindDirs(false);
FindFiles::setBackend(static_cast<FindFiles::Backend>(
Config::instance().value(Config::FINDFILES_BACKEND_KEY).toInt()));
- findFiles->start(QUuid::createUuid());
+ findFiles->start();
}
//Is a multimedia file?
=======================================
--- /trunk/tests/libs/TkUtil/FindFilesTest.cpp Tue Feb 22 06:23:18 2011
+++ /trunk/tests/libs/TkUtil/FindFilesTest.cpp Tue May 31 13:58:07 2011
@@ -26,54 +26,133 @@
QTEST_MAIN(FindFilesTest)
void FindFilesTest::initTestCase() {
- _findFiles = new FindFiles(this);
- connect(_findFiles, SIGNAL(filesFound(const QStringList &, const QUuid
&)),
- SLOT(filesFound(const QStringList &, const QUuid &)));
- connect(_findFiles, SIGNAL(finished(int, const QUuid &)),
- SLOT(finished(int, const QUuid &)));
}
void FindFilesTest::cleanupTestCase() {
}
-void FindFilesTest::test() {
- _findFiles->setSearchPath("../../tests/libs/TkUtil/tests");
-
- QSignalSpy spyFilesFound(_findFiles, SIGNAL(filesFound(const QStringList
&, const QUuid &)));
- QSignalSpy spyFinished(_findFiles, SIGNAL(finished(int, const QUuid &)));
-
- TkUtilDebug() << spyFinished.count();
-
- QUuid uuid = QUuid::createUuid();
- _findFiles->start(uuid);
-
- TkUtilDebug() << spyFilesFound.count();
- TkUtilDebug() << spyFinished.count();
-
- //if (spyFinished.count() == 0) {
- QTestEventLoop::instance().enterLoop(30);
- QVERIFY(!QTestEventLoop::instance().timeout());
- //}
+void FindFilesTest::init() {
+}
+
+void FindFilesTest::cleanup() {
+}
+
+void FindFilesTest::testUTF8() {
+ FindFiles * findFiles = new FindFiles(this);
+ connect(findFiles, SIGNAL(filesFound(const QStringList &)),
+ SLOT(filesFound(const QStringList &)));
+ connect(findFiles, SIGNAL(finished(int)),
+ SLOT(finished(int)));
+
+ QSignalSpy spyFilesFound(findFiles, SIGNAL(filesFound(const QStringList
&)));
+ QVERIFY(spyFilesFound.isValid());
+ QSignalSpy spyFinished(findFiles, SIGNAL(finished(int)));
+ QVERIFY(spyFinished.isValid());
+
+ findFiles->setSearchPath("../../tests/libs/TkUtil/FindFilesTests");
+ findFiles->start();
+
+ //Wait a bit...
+ while (spyFinished.count() == 0) {
+ QTest::qWait(200);
+ }
+
+ QCOMPARE(spyFilesFound.count(), 1);
+ QCOMPARE(spyFinished.count(), 1);
/*
- _findFiles->setFilesFoundLimit();
- _findFiles->setPattern();
- _findFiles->setExtensions();
- _findFiles->setFindDirs();
- _findFiles->setRecursiveSearch();
- _findFiles->stop();
+ findFiles->setFilesFoundLimit();
+ findFiles->setPattern();
+ findFiles->setExtensions();
+ findFiles->setFindDirs();
+ findFiles->setRecursiveSearch();
+ findFiles->stop();
*/
}
-void FindFilesTest::filesFound(const QStringList & files, const QUuid &
uuid) {
- TkUtilDebug() << files << uuid;
- QTextEdit * textEdit = new QTextEdit(NULL);
+void FindFilesTest::filesFoundUTF8(const QStringList & files) {
+ TkUtilDebug() << "Files found:" << files.size();
+
+ static QTextEdit * textEdit = NULL;
+ if (!textEdit) {
+ textEdit = new QTextEdit(NULL);
+ }
textEdit->setText(files.join("\n"));
textEdit->show();
+
+ QCOMPARE(files.size(), 4);
}
-void FindFilesTest::finished(int timeElapsed, const QUuid & uuid) {
- TkUtilDebug() << timeElapsed << uuid;
-
- //QTestEventLoop::instance().exitLoop();
-}
+
+void FindFilesTest::testStartStop() {
+ FindFiles * findFiles = new FindFiles(this);
+ connect(findFiles, SIGNAL(filesFound(const QStringList &)),
+ SLOT(filesFound(const QStringList &)));
+ connect(findFiles, SIGNAL(finished(int)),
+ SLOT(finished(int)));
+
+ QSignalSpy spyFilesFound(findFiles, SIGNAL(filesFound(const QStringList
&)));
+ QVERIFY(spyFilesFound.isValid());
+ QSignalSpy spyFinished(findFiles, SIGNAL(finished(int)));
+ QVERIFY(spyFinished.isValid());
+
+ findFiles->setSearchPath("/");
+ findFiles->start();
+
+ //Waits 10s before to stop
+ QTest::qWait(10000);
+ findFiles->stop();
+
+ //Wait a bit otherwise finished() signal is never catched
+ QTest::qWait(200);
+
+ QVERIFY(spyFilesFound.count() > 0);
+ TkUtilDebug() << "filesFound() signals:" << spyFilesFound.count();
+ QCOMPARE(spyFinished.count(), 1);
+}
+
+void FindFilesTest::finishedStartStop(int timeElapsed) {
+ QVERIFY(timeElapsed > 10000);
+ QVERIFY(timeElapsed < 11000);
+}
+
+
+void FindFilesTest::testRecursionOff() {
+ FindFiles * findFiles = new FindFiles(this);
+ connect(findFiles, SIGNAL(filesFound(const QStringList &)),
+ SLOT(filesFound(const QStringList &)));
+ connect(findFiles, SIGNAL(finished(int)),
+ SLOT(finished(int)));
+
+ QSignalSpy spyFilesFound(findFiles, SIGNAL(filesFound(const QStringList
&)));
+ QVERIFY(spyFilesFound.isValid());
+ QSignalSpy spyFinished(findFiles, SIGNAL(finished(int)));
+ QVERIFY(spyFinished.isValid());
+
+ findFiles->setSearchPath("../../tests/libs/TkUtil/FindFilesTests");
+ findFiles->setRecursiveSearch(false); //Default is true
+ findFiles->start();
+
+ //Wait a bit...
+ while (spyFinished.count() == 0) {
+ QTest::qWait(200);
+ }
+
+ QCOMPARE(spyFilesFound.count(), 0);
+ QCOMPARE(spyFinished.count(), 1);
+}
+
+void FindFilesTest::filesFound(const QStringList & files) {
+ TkUtilDebug() << "Files found:" << files.size();
+
+ static QTextEdit * textEdit = NULL;
+ if (!textEdit) {
+ textEdit = new QTextEdit(NULL);
+ }
+ textEdit->setText(files.join("\n"));
+ textEdit->show();
+}
+
+void FindFilesTest::finished(int timeElapsed) {
+ TkUtilDebug() << timeElapsed;
+}
=======================================
--- /trunk/tests/libs/TkUtil/FindFilesTest.h Sat Aug 28 02:34:02 2010
+++ /trunk/tests/libs/TkUtil/FindFilesTest.h Tue May 31 13:58:07 2011
@@ -23,8 +23,6 @@
#include <QtCore/QStringList>
-class FindFiles;
-
/**
* Test for FindFiles.
*
@@ -41,15 +39,30 @@
/** Called after the last testfunction was executed. */
void cleanupTestCase();
- void test();
-
- void filesFound(const QStringList & files, const QUuid & uuid);
-
- void finished(int timeElapsed, const QUuid & uuid);
-
-private:
-
- FindFiles * _findFiles;
+ /** Called before each testfunction is executed. */
+ void init();
+
+ /** Called after every testfunction. */
+ void cleanup();
+
+
+ void testUTF8();
+
+ void testStartStop();
+
+ void testRecursionOff();
+
+protected slots:
+
+ void filesFoundUTF8(const QStringList & files);
+
+ void finishedStartStop(int timeElapsed);
+
+ void filesFound(const QStringList & files);
+
+ void finished(int timeElapsed);
+
+private:
};
#endif //FINDFILESTEST_H