summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/dialogs/qfilesystemmodel
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2012-02-29 15:21:24 +0200
committerQt by Nokia <qt-info@nokia.com>2012-02-29 20:10:21 +0100
commit70784b9069fbd1c73eddbbfc83ffb44b2ca15854 (patch)
tree4343dc0799c56656f8042a7d026a155854d6b9a2 /tests/auto/widgets/dialogs/qfilesystemmodel
parent7d5b0e2b042c5f6c3074cd20ba9baf9dfd733203 (diff)
QFileSystemModel autotest fixes
For some reason, hiding files via executing "attrib +h filename" process didn't work realiably, so changed the file hiding to be done via Windows native API. Also changed the test to use QTemporaryDir to simplify temporary directory handling a bit. Task-number: QTBUG-24291 Change-Id: I4f02b16e2f9105bcf5e6c5bf136f55434a26e2f4 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
Diffstat (limited to 'tests/auto/widgets/dialogs/qfilesystemmodel')
-rw-r--r--tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro2
-rw-r--r--tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp90
2 files changed, 33 insertions, 59 deletions
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro b/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro
index 6e08e2d02b..166306757c 100644
--- a/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro
+++ b/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro
@@ -5,5 +5,3 @@ QT += core-private gui testlib
SOURCES += tst_qfilesystemmodel.cpp
TARGET = tst_qfilesystemmodel
-
-win32:CONFIG += insignificant_test # QTBUG-24291
diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
index 8724bf63c8..fe374b1e8d 100644
--- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
+++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp
@@ -51,6 +51,10 @@
#include <QTime>
#include <QStyle>
#include <QtGlobal>
+#include <QTemporaryDir>
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
+# include <qt_windows.h> // for SetFileAttributes
+#endif
#define WAITTIME 1000
@@ -69,13 +73,13 @@ class tst_QFileSystemModel : public QObject {
public:
tst_QFileSystemModel();
- virtual ~tst_QFileSystemModel();
public Q_SLOTS:
void init();
void cleanup();
private slots:
+ void initTestCase();
void indexPath();
void rootPath();
@@ -122,29 +126,17 @@ private slots:
void roleNames();
protected:
- bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList(), const QString &baseDir = QDir::temp().absolutePath());
+ bool createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount = 0, const QStringList &intial_dirs = QStringList());
private:
QFileSystemModel *model;
QString flatDirTestPath;
+ QTemporaryDir m_tempDir;
};
tst_QFileSystemModel::tst_QFileSystemModel() : model(0)
{
qRegisterMetaType<QModelIndex>("QModelIndex");
-
- QTime midnight(0, 0, 0);
- qsrand(midnight.secsTo(QTime::currentTime()));
- // generating unique temporary directory name
- flatDirTestPath = QDir::temp().path() + '/' + QString("flatdirtest.") + QString::number(qrand());
-}
-
-tst_QFileSystemModel::~tst_QFileSystemModel()
-{
- QString tmp = flatDirTestPath;
- QDir dir(tmp);
- if (dir.exists() && !dir.rmdir(tmp))
- qWarning("failed to remove tmp dir %s", dir.dirName().toAscii().data());
}
void tst_QFileSystemModel::init()
@@ -178,6 +170,12 @@ void tst_QFileSystemModel::cleanup()
}
}
+void tst_QFileSystemModel::initTestCase()
+{
+ QVERIFY(m_tempDir.isValid());
+ flatDirTestPath = m_tempDir.path();
+}
+
void tst_QFileSystemModel::indexPath()
{
#if !defined(Q_OS_WIN)
@@ -367,15 +365,8 @@ void tst_QFileSystemModel::iconProvider()
delete custom;
}
-bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount, const QStringList &initial_dirs, const QString &dir)
+bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringList &initial_files, int existingFileCount, const QStringList &initial_dirs)
{
- QDir baseDir(dir);
- if (!baseDir.exists(test_path)) {
- if (!baseDir.mkdir(test_path) && false) {
- qDebug() << "failed to create dir" << test_path;
- return false;
- }
- }
//qDebug() << (model->rowCount(model->index(test_path))) << existingFileCount << initial_files;
TRY_WAIT((model->rowCount(model->index(test_path)) == existingFileCount));
for (int i = 0; i < initial_dirs.count(); ++i) {
@@ -406,8 +397,21 @@ bool tst_QFileSystemModel::createFiles(const QString &test_path, const QStringLi
}
file.close();
#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
- if (initial_files.at(i)[0] == '.')
- QProcess::execute(QString("attrib +h %1").arg(file.fileName()));
+ if (initial_files.at(i)[0] == '.') {
+ QString hiddenFile = QDir::toNativeSeparators(file.fileName());
+ wchar_t nativeHiddenFile[MAX_PATH];
+ qMemSet(nativeHiddenFile, 0, sizeof(nativeHiddenFile));
+ hiddenFile.toWCharArray(nativeHiddenFile);
+ DWORD currentAttributes = ::GetFileAttributes(nativeHiddenFile);
+ if (currentAttributes == 0xFFFFFFFF) {
+ qErrnoWarning("failed to get file attributes: %s", qPrintable(hiddenFile));
+ return false;
+ }
+ if (!::SetFileAttributes(nativeHiddenFile, currentAttributes | FILE_ATTRIBUTE_HIDDEN)) {
+ qErrnoWarning("failed to set file hidden: %s", qPrintable(hiddenFile));
+ return false;
+ }
+ }
#endif
//qDebug() << test_path + '/' + initial_files.at(i) << (QFile::exists(test_path + '/' + initial_files.at(i)));
}
@@ -818,16 +822,8 @@ void tst_QFileSystemModel::sort()
myModel->d_func()->disableRecursiveSort = true;
#endif
- QDir dir(QDir::tempPath());
- //initialize the randomness
- qsrand(QDateTime::currentDateTime().toTime_t());
- QString tempName = QLatin1String("sortTemp.") + QString::number(qrand());
- dir.mkdir(tempName);
- dir.cd(tempName);
- QTRY_VERIFY(dir.exists());
-
+ QDir dir(flatDirTestPath);
const QString dirPath = dir.absolutePath();
- QVERIFY(dir.exists());
//Create a file that will be at the end when sorting by name (For Mac, the default)
//but if we sort by size descending it will be the first
@@ -889,14 +885,6 @@ void tst_QFileSystemModel::sort()
delete tree;
delete myModel;
-
- dir.setPath(QDir::tempPath());
- dir.cd(tempName);
- tempFile.remove();
- tempFile2.remove();
- dir.cdUp();
- dir.rmdir(tempName);
-
}
void tst_QFileSystemModel::mkdir()
@@ -978,29 +966,17 @@ void tst_QFileSystemModel::drives()
void tst_QFileSystemModel::dirsBeforeFiles()
{
- const QString dirPath = QString("%1/task221717_sortedOrder_test_dir").arg(QDir::tempPath());
- QDir dir(dirPath);
- // clean up from last time
- if (dir.exists()) {
- for (int i = 0; i < 3; ++i) {
- QLatin1Char c('a' + i);
- dir.rmdir(QString("%1-dir").arg(c));
- QFile::remove(dirPath + QString("/%1-file").arg(c));
- }
- dir.rmdir(dirPath);
- }
- QVERIFY(dir.mkpath(dirPath));
- QVERIFY(QDir(dirPath).exists());
+ QDir dir(flatDirTestPath);
for (int i = 0; i < 3; ++i) {
QLatin1Char c('a' + i);
dir.mkdir(QString("%1-dir").arg(c));
- QFile file(dirPath + QString("/%1-file").arg(c));
+ QFile file(flatDirTestPath + QString("/%1-file").arg(c));
file.open(QIODevice::ReadWrite);
file.close();
}
- QModelIndex root = model->setRootPath(dirPath);
+ QModelIndex root = model->setRootPath(flatDirTestPath);
QTest::qWait(1000); // allow model to be notified by the file system watcher
// ensure that no file occurs before a directory