diff options
Diffstat (limited to 'tests/auto')
7 files changed, 259 insertions, 86 deletions
diff --git a/tests/auto/corelib/io/qfilesystemwatcher/BLACKLIST b/tests/auto/corelib/io/qfilesystemwatcher/BLACKLIST new file mode 100644 index 0000000000..3ac0b9dff4 --- /dev/null +++ b/tests/auto/corelib/io/qfilesystemwatcher/BLACKLIST @@ -0,0 +1,8 @@ +# QTBUG-33574 QTBUG-30943 +[signalsEmittedAfterFileMoved] +windows 32bit msvc-2010 +windows 64bit msvc +[watchFileAndItsDirectory:native backend-testfile] +osx +[watchFileAndItsDirectory:native backend-specialchars] +osx diff --git a/tests/auto/corelib/io/qfilesystemwatcher/qfilesystemwatcher.pro b/tests/auto/corelib/io/qfilesystemwatcher/qfilesystemwatcher.pro index 318e49a113..1faa089c6e 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/qfilesystemwatcher.pro +++ b/tests/auto/corelib/io/qfilesystemwatcher/qfilesystemwatcher.pro @@ -3,5 +3,3 @@ TARGET = tst_qfilesystemwatcher QT = core testlib SOURCES = tst_qfilesystemwatcher.cpp DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 - -CONFIG += insignificant_test # QTBUG-33574 diff --git a/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp b/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp index 3886051fdc..01bf16c295 100644 --- a/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp +++ b/tests/auto/corelib/kernel/qmimedata/tst_qmimedata.cpp @@ -297,9 +297,16 @@ void tst_QMimeData::setText() const QVERIFY(mimeData.hasText() == false); } +// Publish retrieveData for verifying content validity +class TstMetaData : public QMimeData +{ +public: + using QMimeData::retrieveData; +}; + void tst_QMimeData::setUrls() const { - QMimeData mimeData; + TstMetaData mimeData; QList<QUrl> shortUrlList; QList<QUrl> longUrlList; @@ -321,6 +328,14 @@ void tst_QMimeData::setUrls() const QCOMPARE(mimeData.urls(), longUrlList); QCOMPARE(mimeData.text(), QString("http://qt-project.org\nhttp://www.google.com\n")); + // test and verify that setData doesn't corrupt url content + foreach (const QString &format, mimeData.formats()) { + QVariant before = mimeData.retrieveData(format, QVariant::ByteArray); + mimeData.setData(format, mimeData.data(format)); + QVariant after = mimeData.retrieveData(format, QVariant::ByteArray); + QCOMPARE(after, before); + } + // clear, verify mimeData.clear(); QCOMPARE(mimeData.hasUrls(), false); diff --git a/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro b/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro index f5d06b3de9..5c6c56e389 100644 --- a/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro +++ b/tests/auto/corelib/plugin/qpluginloader/qpluginloader.pro @@ -5,7 +5,7 @@ SUBDIRS = lib \ theplugin \ tst !android: !win32: !mac: SUBDIRS += almostplugin -macx-*: SUBDIRS += machtest +macx-*: contains(QT_CONFIG, private_tests): SUBDIRS += machtest TARGET = tst_qpluginloader # no special install rule for subdir diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 5691a654d7..2931185c8b 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -41,6 +41,7 @@ #include <stdio.h> #include <qpainter.h> +#include <private/qimage_p.h> #include <private/qdrawhelper_p.h> Q_DECLARE_METATYPE(QImage::Format) @@ -160,8 +161,11 @@ private slots: void inplaceRgbMirrored(); - void inplaceConversion_data(); - void inplaceConversion(); + void genericRgbConversion_data(); + void genericRgbConversion(); + + void inplaceRgbConversion_data(); + void inplaceRgbConversion(); void deepCopyWhenPaintingActive(); void scaled_QTBUG19157(); @@ -183,11 +187,75 @@ private slots: void cleanupFunctions(); void devicePixelRatio(); + void rgb30Unpremul(); + + void metadataPassthrough(); private: const QString m_prefix; }; +static QString formatToString(QImage::Format format) +{ + switch (format) { + case QImage::Format_Invalid: + return QStringLiteral("Invalid"); + case QImage::Format_Mono: + return QStringLiteral("Mono"); + case QImage::Format_MonoLSB: + return QStringLiteral("MonoLSB"); + case QImage::Format_Indexed8: + return QStringLiteral("Indexed8"); + case QImage::Format_RGB32: + return QStringLiteral("RGB32"); + case QImage::Format_ARGB32: + return QStringLiteral("ARGB32"); + case QImage::Format_ARGB32_Premultiplied: + return QStringLiteral("ARGB32pm"); + case QImage::Format_RGB16: + return QStringLiteral("RGB16"); + case QImage::Format_ARGB8565_Premultiplied: + return QStringLiteral("ARGB8565pm"); + case QImage::Format_RGB666: + return QStringLiteral("RGB666"); + case QImage::Format_ARGB6666_Premultiplied: + return QStringLiteral("ARGB6666pm"); + case QImage::Format_RGB555: + return QStringLiteral("RGB555"); + case QImage::Format_ARGB8555_Premultiplied: + return QStringLiteral("ARGB8555pm"); + case QImage::Format_RGB888: + return QStringLiteral("RGB888"); + case QImage::Format_RGB444: + return QStringLiteral("RGB444"); + case QImage::Format_ARGB4444_Premultiplied: + return QStringLiteral("ARGB4444pm"); + case QImage::Format_RGBX8888: + return QStringLiteral("RGBx88888"); + case QImage::Format_RGBA8888: + return QStringLiteral("RGBA88888"); + case QImage::Format_RGBA8888_Premultiplied: + return QStringLiteral("RGBA88888pm"); + case QImage::Format_BGR30: + return QStringLiteral("BGR30"); + case QImage::Format_A2BGR30_Premultiplied: + return QStringLiteral("A2BGR30pm"); + case QImage::Format_RGB30: + return QStringLiteral("RGB30"); + case QImage::Format_A2RGB30_Premultiplied: + return QStringLiteral("A2RGB30pm"); + case QImage::Format_Alpha8: + return QStringLiteral("Alpha8"); + case QImage::Format_Grayscale8: + return QStringLiteral("Grayscale8"); + default: + break; + }; + Q_UNREACHABLE(); + qWarning("Unhandled image format"); + return QStringLiteral("unknown"); +} + tst_QImage::tst_QImage() : m_prefix(QFINDTESTDATA("images/")) { @@ -2159,23 +2227,9 @@ void tst_QImage::rgbSwapped_data() { QTest::addColumn<QImage::Format>("format"); - QTest::newRow("Format_Indexed8") << QImage::Format_Indexed8; - QTest::newRow("Format_RGB32") << QImage::Format_RGB32; - QTest::newRow("Format_ARGB32") << QImage::Format_ARGB32; - QTest::newRow("Format_ARGB32_Premultiplied") << QImage::Format_ARGB32_Premultiplied; - QTest::newRow("Format_RGB16") << QImage::Format_RGB16; - QTest::newRow("Format_ARGB8565_Premultiplied") << QImage::Format_ARGB8565_Premultiplied; - QTest::newRow("Format_ARGB6666_Premultiplied") << QImage::Format_ARGB6666_Premultiplied; - QTest::newRow("Format_ARGB4444_Premultiplied") << QImage::Format_ARGB4444_Premultiplied; - QTest::newRow("Format_RGB666") << QImage::Format_RGB666; - QTest::newRow("Format_RGB555") << QImage::Format_RGB555; - QTest::newRow("Format_ARGB8555_Premultiplied") << QImage::Format_ARGB8555_Premultiplied; - QTest::newRow("Format_RGB888") << QImage::Format_RGB888; - QTest::newRow("Format_RGB444") << QImage::Format_RGB444; - QTest::newRow("Format_RGBX8888") << QImage::Format_RGBX8888; - QTest::newRow("Format_RGBA8888_Premultiplied") << QImage::Format_RGBA8888_Premultiplied; - QTest::newRow("Format_A2BGR30_Premultiplied") << QImage::Format_A2BGR30_Premultiplied; - QTest::newRow("Format_RGB30") << QImage::Format_RGB30; + for (int i = QImage::Format_Indexed8; i < QImage::Format_Alpha8; ++i) { + QTest::newRow(qPrintable(formatToString(QImage::Format(i)))) << QImage::Format(i); + } } void tst_QImage::rgbSwapped() @@ -2395,23 +2449,18 @@ void tst_QImage::inplaceMirrored_data() QTest::addColumn<bool>("swap_vertical"); QTest::addColumn<bool>("swap_horizontal"); - QTest::newRow("Format_ARGB32, vertical") << QImage::Format_ARGB32 << true << false; - QTest::newRow("Format_RGB888, vertical") << QImage::Format_RGB888 << true << false; - QTest::newRow("Format_RGB16, vertical") << QImage::Format_RGB16 << true << false; - QTest::newRow("Format_Indexed8, vertical") << QImage::Format_Indexed8 << true << false; - QTest::newRow("Format_Mono, vertical") << QImage::Format_Mono << true << false; - - QTest::newRow("Format_ARGB32, horizontal") << QImage::Format_ARGB32 << false << true; - QTest::newRow("Format_RGB888, horizontal") << QImage::Format_RGB888 << false << true; - QTest::newRow("Format_RGB16, horizontal") << QImage::Format_RGB16 << false << true; - QTest::newRow("Format_Indexed8, horizontal") << QImage::Format_Indexed8 << false << true; - QTest::newRow("Format_Mono, horizontal") << QImage::Format_Mono << false << true; - - QTest::newRow("Format_ARGB32, horizontal+vertical") << QImage::Format_ARGB32 << true << true; - QTest::newRow("Format_RGB888, horizontal+vertical") << QImage::Format_RGB888 << true << true; - QTest::newRow("Format_RGB16, horizontal+vertical") << QImage::Format_RGB16 << true << true; - QTest::newRow("Format_Indexed8, horizontal+vertical") << QImage::Format_Indexed8 << true << true; - QTest::newRow("Format_Mono, horizontal+vertical") << QImage::Format_Mono << true << true; + for (int i = QImage::Format_Mono; i < QImage::NImageFormats; ++i) { + if (i == QImage::Format_Alpha8 || i == QImage::Format_Grayscale8) + continue; + if (i == QImage::Format_RGB444 || i == QImage::Format_ARGB4444_Premultiplied) + continue; + QTest::newRow(qPrintable(formatToString(QImage::Format(i)) + QStringLiteral(", vertical"))) + << QImage::Format(i) << true << false; + QTest::newRow(qPrintable(formatToString(QImage::Format(i)) + QStringLiteral(", horizontal"))) + << QImage::Format(i) << false << true; + QTest::newRow(qPrintable(formatToString(QImage::Format(i)) + QStringLiteral(", horizontal+vertical"))) + << QImage::Format(i) << true << true; + } } void tst_QImage::inplaceMirrored() @@ -2425,6 +2474,7 @@ void tst_QImage::inplaceMirrored() switch (format) { case QImage::Format_Mono: + case QImage::Format_MonoLSB: for (int i = 0; i < image.height(); ++i) { ushort* scanLine = (ushort*)image.scanLine(i); *scanLine = (i % 2) ? 0x0fffU : 0xf000U; @@ -2447,7 +2497,7 @@ void tst_QImage::inplaceMirrored() const uchar* originalPtr = image.constScanLine(0); QImage imageMirrored = std::move(image).mirrored(swap_horizontal, swap_vertical); - if (format != QImage::Format_Mono) { + if (format != QImage::Format_Mono && format != QImage::Format_MonoLSB) { for (int i = 0; i < imageMirrored.height(); ++i) { int mirroredI = swap_vertical ? (imageMirrored.height() - i - 1) : i; for (int j = 0; j < imageMirrored.width(); ++j) { @@ -2537,23 +2587,60 @@ void tst_QImage::inplaceRgbMirrored() #endif } -void tst_QImage::inplaceConversion_data() +void tst_QImage::genericRgbConversion_data() { QTest::addColumn<QImage::Format>("format"); QTest::addColumn<QImage::Format>("dest_format"); - QTest::newRow("Format_RGB32 -> RGB16") << QImage::Format_RGB32 << QImage::Format_RGB16; - QTest::newRow("Format_ARGB32 -> Format_RGBA8888") << QImage::Format_ARGB32 << QImage::Format_RGBA8888; - QTest::newRow("Format_RGB888 -> Format_ARGB6666_Premultiplied") << QImage::Format_RGB888 << QImage::Format_ARGB6666_Premultiplied; - QTest::newRow("Format_RGB16 -> Format_RGB555") << QImage::Format_RGB16 << QImage::Format_RGB555; - QTest::newRow("Format_RGB666 -> Format_RGB888") << QImage::Format_RGB666 << QImage::Format_RGB888; - QTest::newRow("Format_ARGB8565_Premultiplied, Format_ARGB8555_Premultiplied") << QImage::Format_ARGB8565_Premultiplied << QImage::Format_ARGB8555_Premultiplied; - QTest::newRow("Format_ARGB4444_Premultiplied, Format_RGB444") << QImage::Format_ARGB4444_Premultiplied << QImage::Format_RGB444; - QTest::newRow("Format_RGBA8888 -> RGB16") << QImage::Format_RGBA8888 << QImage::Format_RGB16; - QTest::newRow("Format_RGBA8888_Premultiplied -> RGB16") << QImage::Format_RGBA8888_Premultiplied << QImage::Format_RGB16; + for (int i = QImage::Format_RGB32; i < QImage::Format_Alpha8; ++i) { + for (int j = QImage::Format_RGB32; j < QImage::Format_Alpha8; ++j) { + if (i == j) + continue; + QString test = QString::fromLatin1("%1 -> %2").arg(formatToString(QImage::Format(i))).arg(formatToString(QImage::Format(j))); + QTest::newRow(qPrintable(test)) << QImage::Format(i) << QImage::Format(j); + } + } } -void tst_QImage::inplaceConversion() +void tst_QImage::genericRgbConversion() +{ + // Test that all RGB conversions work and maintain at least 4bit of color accuracy. + QFETCH(QImage::Format, format); + QFETCH(QImage::Format, dest_format); + + QImage image(16, 16, format); + + for (int i = 0; i < image.height(); ++i) + for (int j = 0; j < image.width(); ++j) + image.setPixel(j, i, qRgb(j*16, i*16, 0)); + + QImage imageConverted = image.convertToFormat(dest_format); + QCOMPARE(imageConverted.format(), dest_format); + for (int i = 0; i < imageConverted.height(); ++i) { + for (int j = 0; j < imageConverted.width(); ++j) { + QRgb convertedColor = imageConverted.pixel(j,i); + QCOMPARE(qRed(convertedColor) & 0xF0, j * 16); + QCOMPARE(qGreen(convertedColor) & 0xF0, i * 16); + } + } +} + +void tst_QImage::inplaceRgbConversion_data() +{ + QTest::addColumn<QImage::Format>("format"); + QTest::addColumn<QImage::Format>("dest_format"); + + for (int i = QImage::Format_RGB32; i < QImage::Format_Alpha8; ++i) { + for (int j = QImage::Format_RGB32; j < QImage::Format_Alpha8; ++j) { + if (i == j) + continue; + QString test = QString::fromLatin1("%1 -> %2").arg(formatToString(QImage::Format(i))).arg(formatToString(QImage::Format(j))); + QTest::newRow(qPrintable(test)) << QImage::Format(i) << QImage::Format(j); + } + } +} + +void tst_QImage::inplaceRgbConversion() { // Test that conversions between RGB formats of the same bitwidth can be done inplace. #if defined(Q_COMPILER_REF_QUALIFIERS) @@ -2582,8 +2669,8 @@ void tst_QImage::inplaceConversion() { // Test attempted inplace conversion of images created on existing buffer - static const quint32 readOnlyData[] = { 0x00010203U, 0x04050607U, 0x08091011U, 0x12131415U }; - quint32 readWriteData[] = { 0x00010203U, 0x04050607U, 0x08091011U, 0x12131415U }; + static const quint32 readOnlyData[] = { 0xff0102ffU, 0xff0506ffU, 0xff0910ffU, 0xff1314ffU }; + quint32 readWriteData[] = { 0xff0102ffU, 0xff0506ffU, 0xff0910ffU, 0xff1314ffU }; QImage roImage((const uchar *)readOnlyData, 2, 2, format); QImage roInplaceConverted = std::move(roImage).convertToFormat(dest_format); @@ -2705,18 +2792,9 @@ void tst_QImage::invertPixelsRGB_data() { QTest::addColumn<QImage::Format>("image_format"); - QTest::newRow("invertPixels RGB16") << QImage::Format_RGB16; - QTest::newRow("invertPixels RGB32") << QImage::Format_RGB32; - QTest::newRow("invertPixels BGR30") << QImage::Format_BGR30; - QTest::newRow("invertPixels RGB444") << QImage::Format_RGB444; - QTest::newRow("invertPixels RGB555") << QImage::Format_RGB555; - QTest::newRow("invertPixels RGB888") << QImage::Format_RGB888; - - QTest::newRow("invertPixels ARGB32") << QImage::Format_ARGB32; - QTest::newRow("invertPixels ARGB32pm") << QImage::Format_ARGB32_Premultiplied; - QTest::newRow("invertPixels RGBA8888") << QImage::Format_RGBA8888; - QTest::newRow("invertPixels RGBA8888pm") << QImage::Format_RGBA8888_Premultiplied; - QTest::newRow("invertPixels RGBA4444pm") << QImage::Format_ARGB4444_Premultiplied; + for (int i = QImage::Format_RGB32; i < QImage::Format_Alpha8; ++i) { + QTest::newRow(qPrintable(formatToString(QImage::Format(i)))) << QImage::Format(i); + } } void tst_QImage::invertPixelsRGB() @@ -2827,5 +2905,53 @@ void tst_QImage::devicePixelRatio() QCOMPARE(b.devicePixelRatio(), qreal(1.0)); } +void tst_QImage::rgb30Unpremul() +{ + QImage a(3, 1, QImage::Format_A2RGB30_Premultiplied); + ((uint*)a.bits())[0] = (3U << 30) | (128 << 20) | (256 << 10) | 512; + ((uint*)a.bits())[1] = (2U << 30) | (131 << 20) | (259 << 10) | 515; + ((uint*)a.bits())[2] = (1U << 30) | ( 67 << 20) | (131 << 10) | 259; + + QImage b = a.convertToFormat(QImage::Format_RGB30); + const uint* bbits = (const uint*)b.bits(); + QCOMPARE(bbits[0], (3U << 30) | (128 << 20) | (256 << 10) | 512); + QCOMPARE(bbits[1], (3U << 30) | (196 << 20) | (388 << 10) | 772); + QCOMPARE(bbits[2], (3U << 30) | (201 << 20) | (393 << 10) | 777); +} + +void tst_QImage::metadataPassthrough() +{ + QImage a(64, 64, QImage::Format_ARGB32); + a.fill(Qt::white); + a.setText(QStringLiteral("Test"), QStringLiteral("Text")); + a.setDotsPerMeterX(100); + a.setDotsPerMeterY(80); + a.setDevicePixelRatio(2.0); + + QImage scaled = a.scaled(QSize(32, 32), Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + QCOMPARE(scaled.text(QStringLiteral("Test")), a.text(QStringLiteral("Test"))); + QCOMPARE(scaled.dotsPerMeterX(), a.dotsPerMeterX()); + QCOMPARE(scaled.dotsPerMeterY(), a.dotsPerMeterY()); + QCOMPARE(scaled.devicePixelRatio(), a.devicePixelRatio()); + + scaled = a.scaled(QSize(128, 128), Qt::IgnoreAspectRatio, Qt::FastTransformation); + QCOMPARE(scaled.text(QStringLiteral("Test")), a.text(QStringLiteral("Test"))); + QCOMPARE(scaled.dotsPerMeterX(), a.dotsPerMeterX()); + QCOMPARE(scaled.dotsPerMeterY(), a.dotsPerMeterY()); + QCOMPARE(scaled.devicePixelRatio(), a.devicePixelRatio()); + + QImage mirrored = a.mirrored(); + QCOMPARE(mirrored.text(QStringLiteral("Test")), a.text(QStringLiteral("Test"))); + QCOMPARE(mirrored.dotsPerMeterX(), a.dotsPerMeterX()); + QCOMPARE(mirrored.dotsPerMeterY(), a.dotsPerMeterY()); + QCOMPARE(mirrored.devicePixelRatio(), a.devicePixelRatio()); + + QImage swapped = a.rgbSwapped(); + QCOMPARE(swapped.text(QStringLiteral("Test")), a.text(QStringLiteral("Test"))); + QCOMPARE(swapped.dotsPerMeterX(), a.dotsPerMeterX()); + QCOMPARE(swapped.dotsPerMeterY(), a.dotsPerMeterY()); + QCOMPARE(swapped.devicePixelRatio(), a.devicePixelRatio()); +} + QTEST_GUILESS_MAIN(tst_QImage) #include "tst_qimage.moc" diff --git a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp index e677891ce5..ffc000a418 100644 --- a/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog/tst_qfiledialog.cpp @@ -54,10 +54,10 @@ #include <qsortfilterproxymodel.h> #include <qlineedit.h> #include <qlayout.h> +#include <private/qfiledialog_p.h> #if defined QT_BUILD_INTERNAL #include <private/qsidebar_p.h> #include <private/qfilesystemmodel_p.h> -#include <private/qfiledialog_p.h> #endif #include <private/qguiapplication_p.h> #include <qpa/qplatformtheme.h> @@ -108,6 +108,7 @@ public: public slots: void initTestCase(); void init(); + void cleanup(); private slots: void currentChangedSignal(); @@ -166,7 +167,7 @@ private slots: void rejectModalDialogs(); private: - QByteArray userSettings; + void cleanupSettingsFile(); }; tst_QFiledialog::tst_QFiledialog() @@ -177,18 +178,27 @@ tst_QFiledialog::~tst_QFiledialog() { } +void tst_QFiledialog::cleanupSettingsFile() +{ + // clean up the sidebar between each test + QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); + settings.beginGroup(QLatin1String("FileDialog")); + settings.remove(QString()); + settings.endGroup(); + settings.beginGroup(QLatin1String("Qt")); // Compatibility settings + settings.remove(QLatin1String("filedialog")); + settings.endGroup(); +} + void tst_QFiledialog::initTestCase() { QStandardPaths::setTestModeEnabled(true); + cleanupSettingsFile(); } void tst_QFiledialog::init() { - // clean up the sidebar between each test - QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); - settings.beginGroup(QLatin1String("Qt")); - settings.remove(QLatin1String("filedialog")); - + QFileDialogPrivate::setLastVisitedDirectory(QUrl()); // populate the sidebar with some default settings QNonNativeFileDialog fd; #if defined(Q_OS_WINCE) @@ -196,6 +206,11 @@ void tst_QFiledialog::init() #endif } +void tst_QFiledialog::cleanup() +{ + cleanupSettingsFile(); +} + class MyAbstractItemDelegate : public QAbstractItemDelegate { public: diff --git a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp index 7af62cb2a1..ed34c67aad 100644 --- a/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp +++ b/tests/auto/widgets/dialogs/qfiledialog2/tst_qfiledialog2.cpp @@ -88,6 +88,7 @@ public: virtual ~tst_QFileDialog2(); public slots: + void initTestCase(); void init(); void cleanup(); @@ -135,13 +136,13 @@ private slots: void dontShowCompleterOnRoot(); private: - QByteArray userSettings; + void cleanupSettingsFile(); + QTemporaryDir tempDir; }; tst_QFileDialog2::tst_QFileDialog2() - : userSettings() - , tempDir(QDir::tempPath() + "/tst_qfiledialog2.XXXXXX") + : tempDir(QDir::tempPath() + "/tst_qfiledialog2.XXXXXX") { #if defined(Q_OS_WINCE) qApp->setAutoMaximizeThreshold(-1); @@ -152,17 +153,29 @@ tst_QFileDialog2::~tst_QFileDialog2() { } -void tst_QFileDialog2::init() +void tst_QFileDialog2::cleanupSettingsFile() { - QVERIFY(tempDir.isValid()); - - // Save the developers settings so they don't get mad when their sidebar folders are gone. + // clean up the sidebar between each test QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); - settings.beginGroup(QLatin1String("Qt")); - userSettings = settings.value(QLatin1String("filedialog")).toByteArray(); + settings.beginGroup(QLatin1String("FileDialog")); + settings.remove(QString()); + settings.endGroup(); + settings.beginGroup(QLatin1String("Qt")); // Compatibility settings settings.remove(QLatin1String("filedialog")); + settings.endGroup(); +} + +void tst_QFileDialog2::initTestCase() +{ + QVERIFY(tempDir.isValid()); + QStandardPaths::setTestModeEnabled(true); + cleanupSettingsFile(); +} - // populate it with some default settings +void tst_QFileDialog2::init() +{ + QFileDialogPrivate::setLastVisitedDirectory(QUrl()); + // populate the sidebar with some default settings QNonNativeFileDialog fd; #if defined(Q_OS_WINCE) QTest::qWait(1000); @@ -171,9 +184,7 @@ void tst_QFileDialog2::init() void tst_QFileDialog2::cleanup() { - QSettings settings(QSettings::UserScope, QLatin1String("QtProject")); - settings.beginGroup(QLatin1String("Qt")); - settings.setValue(QLatin1String("filedialog"), userSettings); + cleanupSettingsFile(); } #ifdef QT_BUILD_INTERNAL |