diff options
Diffstat (limited to 'tests/auto')
27 files changed, 843 insertions, 300 deletions
diff --git a/tests/auto/android/runtests_androiddeployqt.pl b/tests/auto/android/runtests_androiddeployqt.pl index 1cc52d0495..3d57dcfd65 100755 --- a/tests/auto/android/runtests_androiddeployqt.pl +++ b/tests/auto/android/runtests_androiddeployqt.pl @@ -217,6 +217,10 @@ sub startTest print "Someone should kill $packageName\n"; return 1; } + + # Wait for three seconds to allow process to write all data + sleep(3); + system("$adb_tool $device_serial pull /data/data/$packageName/output.xml $output_dir/$output_file.xml") if ($get_xml); system("$adb_tool $device_serial pull /data/data/$packageName/output.txt $output_dir/$output_file.txt") if ($get_txt); return 1; diff --git a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp index 79df4b7055..0b4f0e3c4b 100644 --- a/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp +++ b/tests/auto/corelib/global/qnumeric/tst_qnumeric.cpp @@ -167,7 +167,7 @@ void tst_QNumeric::floatDistance() QFETCH(float, val1); QFETCH(float, val2); QFETCH(quint32, expectedDistance); -#ifdef Q_OS_BLACKBERRY +#ifdef Q_OS_QNX QEXPECT_FAIL("denormal", "See QTBUG-37094", Continue); #endif QCOMPARE(qFloatDistance(val1, val2), expectedDistance); @@ -214,7 +214,7 @@ void tst_QNumeric::floatDistance_double() QFETCH(double, val1); QFETCH(double, val2); QFETCH(quint64, expectedDistance); -#ifdef Q_OS_BLACKBERRY +#ifdef Q_OS_QNX QEXPECT_FAIL("denormal", "See QTBUG-37094", Continue); #endif QCOMPARE(qFloatDistance(val1, val2), expectedDistance); diff --git a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp index b681cec802..a58c7dfb4b 100644 --- a/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp +++ b/tests/auto/corelib/io/qfilesystemwatcher/tst_qfilesystemwatcher.cpp @@ -324,6 +324,9 @@ void tst_QFileSystemWatcher::watchDirectory() fileName = changedSpy.at(1).at(0).toString(); QCOMPARE(fileName, testDir.absolutePath()); + // flush pending signals (like the one from the rmdir above) + timer.start(5000); + eventLoop.exec(); changedSpy.clear(); // recreate the file, we should not get any notification diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index f5aa2c2412..b67166272b 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -1069,7 +1069,7 @@ void tst_QProcess::softExitInSlots() SoftExitProcess proc(i); proc.writeAfterStart("OLEBOLE", 8); // include the \0 proc.start(appName); - QTRY_VERIFY(proc.waitedForFinished); + QTRY_VERIFY_WITH_TIMEOUT(proc.waitedForFinished, 10000); QCOMPARE(proc.state(), QProcess::NotRunning); } } diff --git a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp index 42c360f2d8..501ad6f415 100644 --- a/tests/auto/corelib/io/qsettings/tst_qsettings.cpp +++ b/tests/auto/corelib/io/qsettings/tst_qsettings.cpp @@ -50,6 +50,7 @@ #include <QtCore/QString> #include <QtCore/QDir> #include <QtCore/QThread> +#include <QtCore/QSysInfo> #include <QtGui/QKeySequence> #include <cctype> @@ -73,10 +74,30 @@ Q_DECLARE_METATYPE(QSettings::Format) QT_FORWARD_DECLARE_CLASS(QSettings) +static inline bool canWriteNativeSystemSettings() +{ +#if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) + HKEY key; + const LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, L"Software", 0, KEY_WRITE, &key); + if (result == ERROR_SUCCESS) + RegCloseKey(key); + else + qErrnoWarning(result, "RegOpenKeyEx failed"); + return result == ERROR_SUCCESS; +#else // Q_OS_WIN && !Q_OS_WINRT + return true; +#endif +} + +static const char insufficientPermissionSkipMessage[] = "Insufficient permissions for this test."; + class tst_QSettings : public QObject { Q_OBJECT +public: + tst_QSettings() : m_canWriteNativeSystemSettings(canWriteNativeSystemSettings()) {} + public slots: void initTestCase(); void init(); @@ -145,6 +166,9 @@ private slots: void testByteArray_data(); void testByteArray(); + +private: + const bool m_canWriteNativeSystemSettings; }; // Testing get/set functions @@ -259,6 +283,8 @@ static void populateWithFormats() void tst_QSettings::initTestCase() { + if (!m_canWriteNativeSystemSettings) + qWarning("The test is not running with administrative rights. Some tests will be skipped."); QSettings::Format custom1 = QSettings::registerFormat("custom1", readCustom1File, writeCustom1File); QSettings::Format custom2 = QSettings::registerFormat("custom2", readCustom2File, writeCustom2File #ifndef QT_QSETTINGS_ALWAYS_CASE_SENSITIVE_AND_FORGET_ORIGINAL_KEY_ORDER @@ -276,17 +302,19 @@ void tst_QSettings::init() #if defined(Q_OS_WIN) && !defined(Q_OS_WINRT) QSettings("HKEY_CURRENT_USER\\Software\\software.org", QSettings::NativeFormat).clear(); - QSettings("HKEY_LOCAL_MACHINE\\Software\\software.org", QSettings::NativeFormat).clear(); QSettings("HKEY_CURRENT_USER\\Software\\other.software.org", QSettings::NativeFormat).clear(); - QSettings("HKEY_LOCAL_MACHINE\\Software\\other.software.org", QSettings::NativeFormat).clear(); QSettings("HKEY_CURRENT_USER\\Software\\foo", QSettings::NativeFormat).clear(); QSettings("HKEY_CURRENT_USER\\Software\\bar", QSettings::NativeFormat).clear(); QSettings("HKEY_CURRENT_USER\\Software\\bat", QSettings::NativeFormat).clear(); QSettings("HKEY_CURRENT_USER\\Software\\baz", QSettings::NativeFormat).clear(); - QSettings("HKEY_LOCAL_MACHINE\\Software\\foo", QSettings::NativeFormat).clear(); - QSettings("HKEY_LOCAL_MACHINE\\Software\\bar", QSettings::NativeFormat).clear(); - QSettings("HKEY_LOCAL_MACHINE\\Software\\bat", QSettings::NativeFormat).clear(); - QSettings("HKEY_LOCAL_MACHINE\\Software\\baz", QSettings::NativeFormat).clear(); + if (m_canWriteNativeSystemSettings) { + QSettings("HKEY_LOCAL_MACHINE\\Software\\software.org", QSettings::NativeFormat).clear(); + QSettings("HKEY_LOCAL_MACHINE\\Software\\other.software.org", QSettings::NativeFormat).clear(); + QSettings("HKEY_LOCAL_MACHINE\\Software\\foo", QSettings::NativeFormat).clear(); + QSettings("HKEY_LOCAL_MACHINE\\Software\\bar", QSettings::NativeFormat).clear(); + QSettings("HKEY_LOCAL_MACHINE\\Software\\bat", QSettings::NativeFormat).clear(); + QSettings("HKEY_LOCAL_MACHINE\\Software\\baz", QSettings::NativeFormat).clear(); + } if (QDir(settingsPath()).exists()) { #if defined(Q_OS_WINCE) removePath(settingsPath()); @@ -334,6 +362,9 @@ void tst_QSettings::ctor() { QFETCH(QSettings::Format, format); + if (!m_canWriteNativeSystemSettings && format == QSettings::NativeFormat) + QSKIP(insufficientPermissionSkipMessage); + { QSettings settings1(format, QSettings::UserScope, "software.org", "KillerAPP"); QSettings settings2(format, QSettings::UserScope, "software.org"); @@ -1263,43 +1294,55 @@ void tst_QSettings::remove() QSettings settings1(QSettings::UserScope, "software.org", "KillerAPP"); QSettings settings2(QSettings::UserScope, "software.org"); - QSettings settings3(QSettings::SystemScope, "software.org", "KillerAPP"); - QSettings settings4(QSettings::SystemScope, "software.org"); - settings4.setValue("key 1", "doodah"); - settings3.setValue("key 1", "blah"); + QScopedPointer<QSettings> settings3; + QScopedPointer<QSettings> settings4; + + if (m_canWriteNativeSystemSettings) { + settings3.reset(new QSettings(QSettings::SystemScope, "software.org", "KillerAPP")); + settings4.reset(new QSettings(QSettings::SystemScope, "software.org")); + settings3->setValue("key 1", "blah"); + settings4->setValue("key 1", "doodah"); + } + settings2.setValue("key 1", "whoa"); settings1.setValue("key 1", "gurgle"); QCOMPARE(settings1.value("key 1").toString(), QString("gurgle")); QCOMPARE(settings2.value("key 1").toString(), QString("whoa")); #if !defined(Q_OS_BLACKBERRY) - QCOMPARE(settings3.value("key 1").toString(), QString("blah")); - QCOMPARE(settings4.value("key 1").toString(), QString("doodah")); + if (m_canWriteNativeSystemSettings) { + QCOMPARE(settings3->value("key 1").toString(), QString("blah")); + QCOMPARE(settings4->value("key 1").toString(), QString("doodah")); + } settings1.remove("key 1"); QCOMPARE(settings1.value("key 1").toString(), QString("whoa")); QCOMPARE(settings2.value("key 1").toString(), QString("whoa")); - QCOMPARE(settings3.value("key 1").toString(), QString("blah")); - QCOMPARE(settings4.value("key 1").toString(), QString("doodah")); + if (m_canWriteNativeSystemSettings) { + QCOMPARE(settings3->value("key 1").toString(), QString("blah")); + QCOMPARE(settings4->value("key 1").toString(), QString("doodah")); + } - settings2.remove("key 1"); - QCOMPARE(settings1.value("key 1").toString(), QString("blah")); - QCOMPARE(settings2.value("key 1").toString(), QString("doodah")); - QCOMPARE(settings3.value("key 1").toString(), QString("blah")); - QCOMPARE(settings4.value("key 1").toString(), QString("doodah")); - - settings3.remove("key 1"); - QCOMPARE(settings1.value("key 1").toString(), QString("doodah")); - QCOMPARE(settings2.value("key 1").toString(), QString("doodah")); - QCOMPARE(settings3.value("key 1").toString(), QString("doodah")); - QCOMPARE(settings4.value("key 1").toString(), QString("doodah")); - - settings4.remove("key 1"); - QVERIFY(!settings1.contains("key 1")); - QVERIFY(!settings2.contains("key 1")); - QVERIFY(!settings3.contains("key 1")); - QVERIFY(!settings4.contains("key 1")); + if (m_canWriteNativeSystemSettings) { + settings2.remove("key 1"); + QCOMPARE(settings1.value("key 1").toString(), QString("blah")); + QCOMPARE(settings2.value("key 1").toString(), QString("doodah")); + QCOMPARE(settings3->value("key 1").toString(), QString("blah")); + QCOMPARE(settings4->value("key 1").toString(), QString("doodah")); + + settings3->remove("key 1"); + QCOMPARE(settings1.value("key 1").toString(), QString("doodah")); + QCOMPARE(settings2.value("key 1").toString(), QString("doodah")); + QCOMPARE(settings3->value("key 1").toString(), QString("doodah")); + QCOMPARE(settings4->value("key 1").toString(), QString("doodah")); + + settings4->remove("key 1"); + QVERIFY(!settings1.contains("key 1")); + QVERIFY(!settings2.contains("key 1")); + QVERIFY(!settings3->contains("key 1")); + QVERIFY(!settings4->contains("key 1")); + } #else settings1.remove("key 1"); QCOMPARE(settings2.value("key 1").toString(), QString("whoa")); @@ -1315,13 +1358,18 @@ void tst_QSettings::remove() settings1.clear(); settings2.clear(); - settings3.clear(); - settings4.clear(); + if (m_canWriteNativeSystemSettings) { + settings3->clear(); + settings4->clear(); + } settings1.sync(); settings2.sync(); - settings3.sync(); - settings4.sync(); + + if (m_canWriteNativeSystemSettings) { + settings3->sync(); + settings4->sync(); + } /* Check that recursive removes work correctly when some of the @@ -1556,6 +1604,9 @@ void tst_QSettings::setFallbacksEnabled() { QFETCH(QSettings::Format, format); + if (!m_canWriteNativeSystemSettings && format == QSettings::NativeFormat) + QSKIP(insufficientPermissionSkipMessage); + QSettings settings1(format, QSettings::UserScope, "software.org", "KillerAPP"); QSettings settings2(format, QSettings::UserScope, "software.org"); QSettings settings3(format, QSettings::SystemScope, "software.org", "KillerAPP"); @@ -2747,10 +2798,30 @@ void tst_QSettings::isWritable() QSettings s1(format, QSettings::SystemScope, "software.org", "KillerAPP"); QSettings s2(format, QSettings::SystemScope, "software.org", "Something Different"); QSettings s3(format, QSettings::SystemScope, "foo.org", "Something Different"); + if (s1.contains("foo")) { - QVERIFY(s1.isWritable()); - QVERIFY(s2.isWritable()); - QVERIFY(s3.isWritable()); +#if defined(Q_OS_MACX) + if (QSysInfo::macVersion() >= QSysInfo::MV_10_9) { + QVERIFY(s1.isWritable()); + if (format == QSettings::NativeFormat) { + QVERIFY(!s2.isWritable()); + QVERIFY(!s3.isWritable()); + } else { + QVERIFY(s2.isWritable()); + QVERIFY(s3.isWritable()); + } + } else if (QSysInfo::macVersion() >= QSysInfo::MV_10_7 && + format == QSettings::NativeFormat) { + QVERIFY(!s1.isWritable()); + QVERIFY(!s2.isWritable()); + QVERIFY(!s3.isWritable()); + } else +#endif + { + QVERIFY(s1.isWritable()); + QVERIFY(s2.isWritable()); + QVERIFY(s3.isWritable()); + } } else { QVERIFY(!s1.isWritable()); QVERIFY(!s2.isWritable()); @@ -2771,8 +2842,10 @@ void tst_QSettings::childGroups() { QFETCH(QSettings::Format, format); + const QSettings::Scope scope = m_canWriteNativeSystemSettings ? QSettings::SystemScope : QSettings::UserScope; + { - QSettings settings(format, QSettings::SystemScope, "software.org"); + QSettings settings(format, scope, "software.org"); settings.setValue("alpha", "1"); settings.setValue("alpha/a", "2"); settings.setValue("alpha/b", "3"); @@ -2789,7 +2862,7 @@ void tst_QSettings::childGroups() for (int pass = 0; pass < 3; ++pass) { QConfFile::clearCache(); - QSettings settings(format, QSettings::SystemScope, "software.org"); + QSettings settings(format, scope, "software.org"); settings.setFallbacksEnabled(false); if (pass == 1) { settings.value("gamma/d"); @@ -2837,8 +2910,10 @@ void tst_QSettings::childKeys() { QFETCH(QSettings::Format, format); + const QSettings::Scope scope = m_canWriteNativeSystemSettings ? QSettings::SystemScope : QSettings::UserScope; + { - QSettings settings(format, QSettings::SystemScope, "software.org"); + QSettings settings(format, scope, "software.org"); settings.setValue("alpha", "1"); settings.setValue("alpha/a", "2"); settings.setValue("alpha/b", "3"); @@ -2855,7 +2930,7 @@ void tst_QSettings::childKeys() for (int pass = 0; pass < 3; ++pass) { QConfFile::clearCache(); - QSettings settings(format, QSettings::SystemScope, "software.org"); + QSettings settings(format, scope, "software.org"); settings.setFallbacksEnabled(false); if (pass == 1) { settings.value("gamma/d"); @@ -2907,15 +2982,17 @@ void tst_QSettings::allKeys() allKeys << "alpha" << "alpha/a" << "alpha/b" << "alpha/c" << "beta" << "gamma" << "gamma/d" << "gamma/d/e" << "gamma/f/g" << "omicron/h/i/j/x" << "omicron/h/i/k/y" << "zeta/z"; + const QSettings::Scope scope = m_canWriteNativeSystemSettings ? QSettings::SystemScope : QSettings::UserScope; + { - QSettings settings(format, QSettings::SystemScope, "software.org"); + QSettings settings(format, scope, "software.org"); for (int i = 0; i < allKeys.size(); ++i) settings.setValue(allKeys.at(i), QString::number(i + 1)); } for (int pass = 0; pass < 3; ++pass) { QConfFile::clearCache(); - QSettings settings(format, QSettings::SystemScope, "software.org"); + QSettings settings(format, scope, "software.org"); settings.setFallbacksEnabled(false); if (pass == 1) { diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index 2f75ad631f..a17fe7561a 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -347,7 +347,7 @@ void tst_QtJson::testNumbers_2() QJsonDocument jDocument2(QJsonDocument::fromJson(ba)); for (int power = 0; power <= 1075; power++) { floatValues_1[power] = jDocument2.object().value(QString::number(power)).toDouble(); -#ifdef Q_OS_BLACKBERRY +#ifdef Q_OS_QNX if (power >= 970) QEXPECT_FAIL("", "See QTBUG-37066", Abort); #endif @@ -1346,7 +1346,7 @@ void tst_QtJson::toJsonLargeNumericValues() " ]\n" "}\n"; -#ifdef Q_OS_BLACKBERRY +#ifdef Q_OS_QNX QEXPECT_FAIL("", "See QTBUG-37066", Continue); #endif QCOMPARE(json, expected); @@ -1354,7 +1354,7 @@ void tst_QtJson::toJsonLargeNumericValues() QJsonDocument doc; doc.setObject(object); json = doc.toJson(); -#ifdef Q_OS_BLACKBERRY +#ifdef Q_OS_QNX QEXPECT_FAIL("", "See QTBUG-37066", Continue); #endif QCOMPARE(json, expected); @@ -1758,7 +1758,7 @@ void tst_QtJson::parseNumbers() json += numbers[i].str; json += " ]"; QJsonDocument doc = QJsonDocument::fromJson(json); -#ifdef Q_OS_BLACKBERRY +#ifdef Q_OS_QNX if (0 == QString::compare(numbers[i].str, "1.1e-308")) QEXPECT_FAIL("", "See QTBUG-37066", Abort); #endif diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 629a095f9d..5655d9f529 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -4876,10 +4876,8 @@ void tst_QString::localeAwareCompare() DWORD oldLcid = GetUserDefaultLCID(); SetUserDefaultLCID(locale); QCOMPARE(locale, GetUserDefaultLCID()); -#elif defined (Q_OS_MAC) - QSKIP("Setting the locale is not supported on OS X (you can set the C locale, but that won't affect CFStringCompare which is used to compare strings)"); -#elif defined(QT_USE_ICU) - QLocale::setDefault(QLocale(locale)); +#elif defined (Q_OS_MAC) || defined(QT_USE_ICU) + QSKIP("Setting the locale is not supported on OS X or ICU (you can set the C locale, but that won't affect localeAwareCompare)"); #else if (!locale.isEmpty()) { const char *newLocale = setlocale(LC_ALL, locale.toLatin1()); diff --git a/tests/auto/gui/image/qimage/tst_qimage.cpp b/tests/auto/gui/image/qimage/tst_qimage.cpp index 01a56883bf..95a9b142ec 100644 --- a/tests/auto/gui/image/qimage/tst_qimage.cpp +++ b/tests/auto/gui/image/qimage/tst_qimage.cpp @@ -168,6 +168,8 @@ private slots: void convertOverUnPreMul(); + void scaled_QTBUG35972(); + void cleanupFunctions(); }; @@ -2439,6 +2441,25 @@ void tst_QImage::convertOverUnPreMul() } } +void tst_QImage::scaled_QTBUG35972() +{ + QImage src(532,519,QImage::Format_ARGB32_Premultiplied); + src.fill(QColor(Qt::white)); + QImage dest(1000,1000,QImage::Format_ARGB32_Premultiplied); + dest.fill(QColor(Qt::white)); + QPainter painter1(&dest); + const QTransform trf(1.25, 0, + 0, 1.25, + /*dx */ 15.900000000000034, /* dy */ 72.749999999999986); + painter1.setTransform(trf); + painter1.drawImage(QRectF(-2.6, -2.6, 425.6, 415.20000000000005), src, QRectF(0,0,532,519)); + + const quint32 *pixels = reinterpret_cast<const quint32 *>(dest.constBits()); + int size = dest.width()*dest.height(); + for (int i = 0; i < size; ++i) + QCOMPARE(pixels[i], 0xffffffff); +} + static void cleanupFunction(void* info) { bool *called = static_cast<bool*>(info); diff --git a/tests/auto/gui/kernel/qevent/tst_qevent.cpp b/tests/auto/gui/kernel/qevent/tst_qevent.cpp index 3865eb00da..73f9486752 100644 --- a/tests/auto/gui/kernel/qevent/tst_qevent.cpp +++ b/tests/auto/gui/kernel/qevent/tst_qevent.cpp @@ -55,9 +55,14 @@ public: private slots: void registerEventType_data(); void registerEventType(); + void exhaustEventTypeRegistration(); // keep behind registerEventType() test + +private: + bool registerEventTypeSucceeded; // track success of registerEventType for use by exhaustEventTypeRegistration() }; tst_QEvent::tst_QEvent() + : registerEventTypeSucceeded(true) { } tst_QEvent::~tst_QEvent() @@ -72,17 +77,40 @@ void tst_QEvent::registerEventType_data() QTest::newRow("default") << -1 << int(QEvent::MaxUser); // hint not valid QTest::newRow("User-1") << int(QEvent::User - 1) << int(QEvent::MaxUser - 1); + // hint not valid II + QTest::newRow("MaxUser+1") << int(QEvent::MaxUser + 1) << int(QEvent::MaxUser - 2); // hint valid, but already taken - QTest::newRow("MaxUser-1") << int(QEvent::MaxUser - 1) << int(QEvent::MaxUser - 2); + QTest::newRow("MaxUser-1") << int(QEvent::MaxUser - 1) << int(QEvent::MaxUser - 3); // hint valid, but not taken QTest::newRow("User + 1000") << int(QEvent::User + 1000) << int(QEvent::User + 1000); } void tst_QEvent::registerEventType() { + const bool oldRegisterEventTypeSucceeded = registerEventTypeSucceeded; + registerEventTypeSucceeded = false; QFETCH(int, hint); QFETCH(int, expected); QCOMPARE(QEvent::registerEventType(hint), expected); + registerEventTypeSucceeded = oldRegisterEventTypeSucceeded; +} + +void tst_QEvent::exhaustEventTypeRegistration() +{ + if (!registerEventTypeSucceeded) + QSKIP("requires the previous test (registerEventType) to have finished successfully"); + + int i = QEvent::User; + int result; + while ((result = QEvent::registerEventType(i)) == i) + ++i; + QCOMPARE(i, int(QEvent::User + 1000)); + QCOMPARE(result, int(QEvent::MaxUser - 4)); + i = QEvent::User + 1001; + while ((result = QEvent::registerEventType(i)) == i) + ++i; + QCOMPARE(result, -1); + QCOMPARE(i, int(QEvent::MaxUser - 4)); } QTEST_MAIN(tst_QEvent) diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index da142c80a6..eefa85a745 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -49,6 +49,10 @@ #include <QEvent> #include <QStyleHints> +#if defined(Q_OS_QNX) +#include <QOpenGLContext> +#endif + // For QSignalSpy slot connections. Q_DECLARE_METATYPE(Qt::ScreenOrientation) Q_DECLARE_METATYPE(QWindow::Visibility) @@ -122,6 +126,9 @@ public: { reset(); setFlags(flags); +#if defined(Q_OS_QNX) + setSurfaceType(QSurface::OpenGLSurface); +#endif } void reset() @@ -187,7 +194,12 @@ void tst_QWindow::resizeEventAfterResize() // Make sure we get a resizeEvent after calling resize window.resize(400, 100); +#if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen + // so we only expect one resize event + QTRY_COMPARE(window.received(QEvent::Resize), 1); +#else QTRY_COMPARE(window.received(QEvent::Resize), 2); +#endif } void tst_QWindow::positioning_data() @@ -244,13 +256,24 @@ void tst_QWindow::positioning() window.setWindowState(Qt::WindowFullScreen); QCoreApplication::processEvents(); +#if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen + // so we only expect one resize event + Q_UNUSED(resizecount); + QTRY_COMPARE(window.received(QEvent::Resize), 1); +#else QTRY_COMPARE(window.received(QEvent::Resize), 2); +#endif QTest::qWait(2000); window.setWindowState(Qt::WindowNoState); QCoreApplication::processEvents(); +#if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen + // so we only expect one resize event + QTRY_COMPARE(window.received(QEvent::Resize), 1); +#else QTRY_COMPARE(window.received(QEvent::Resize), resizecount); +#endif QTRY_COMPARE(originalPos, window.position()); QTRY_COMPARE(originalFramePos, window.framePosition()); @@ -309,6 +332,13 @@ void tst_QWindow::isActive() QCoreApplication::processEvents(); QTRY_VERIFY(window.isExposed()); +#if defined(Q_OS_QNX) // We either need to create a eglSurface or a create a backing store + // and then post the window in order for screen to show the window + QOpenGLContext context; + context.create(); + context.makeCurrent(&window); + context.swapBuffers(&window); +#endif QTRY_COMPARE(window.received(QEvent::Resize), 1); QTRY_VERIFY(QGuiApplication::focusWindow() == &window); QVERIFY(window.isActive()); @@ -511,7 +541,7 @@ void tst_QWindow::testInputEvents() // Now with null pointer as window. local param should not be utilized: // handleMouseEvent() with tlw == 0 means the event is in global coords only. window.mousePressButton = window.mouseReleaseButton = 0; - QPointF nonWindowGlobal(500, 500); // not inside the window + QPointF nonWindowGlobal(2000, 500); // not inside the window QWindowSystemInterface::handleMouseEvent(0, nonWindowGlobal, nonWindowGlobal, Qt::LeftButton); QWindowSystemInterface::handleMouseEvent(0, nonWindowGlobal, nonWindowGlobal, Qt::NoButton); QCoreApplication::processEvents(); @@ -913,10 +943,21 @@ void tst_QWindow::activateAndClose() { for (int i = 0; i < 10; ++i) { QWindow window; +#if defined(Q_OS_QNX) + window.setSurfaceType(QSurface::OpenGLSurface); +#endif // qWaitForWindowActive will block for the duration of // of the timeout if the window is at 0,0 window.setGeometry(QGuiApplication::primaryScreen()->availableGeometry().adjusted(1, 1, -1, -1)); window.showNormal(); +#if defined(Q_OS_QNX) // We either need to create a eglSurface or a create a backing store + // and then post the window in order for screen to show the window + QTest::qWaitForWindowExposed(&window); + QOpenGLContext context; + context.create(); + context.makeCurrent(&window); + context.swapBuffers(&window); +#endif window.requestActivate(); QVERIFY(QTest::qWaitForWindowActive(&window)); QCOMPARE(qGuiApp->focusWindow(), &window); @@ -1252,15 +1293,26 @@ void tst_QWindow::initialSize() Window w; w.setWidth(200); w.show(); +#if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen + // so we only expect one resize event + QTRY_COMPARE(w.width(), qGuiApp->primaryScreen()->availableGeometry().width()); +#else QTRY_COMPARE(w.width(), 200); +#endif QTRY_VERIFY(w.height() > 0); } { Window w; w.resize(200, 42); w.show(); +#if defined(Q_OS_BLACKBERRY) // "window" is the "root" window and will always be shown fullscreen + // so we only expect one resize event + QTRY_COMPARE(w.width(), qGuiApp->primaryScreen()->availableGeometry().width()); + QTRY_COMPARE(w.height(), qGuiApp->primaryScreen()->availableGeometry().height()); +#else QTRY_COMPARE(w.width(), 200); QTRY_COMPARE(w.height(), 42); +#endif } } diff --git a/tests/auto/gui/qopengl/tst_qopengl.cpp b/tests/auto/gui/qopengl/tst_qopengl.cpp index 4018c00a38..63fe8b9693 100644 --- a/tests/auto/gui/qopengl/tst_qopengl.cpp +++ b/tests/auto/gui/qopengl/tst_qopengl.cpp @@ -157,7 +157,22 @@ static QSurface *createSurface(int surfaceClass) window->create(); return window; } else if (surfaceClass == int(QSurface::Offscreen)) { + // Create a window and get the format from that. For example, if an EGL + // implementation provides 565 and 888 configs for PBUFFER_BIT but only + // 888 for WINDOW_BIT, we may end up with a pbuffer surface that is + // incompatible with the context since it could choose the 565 while the + // window and the context uses a config with 888. + static QSurfaceFormat format; + if (format.redBufferSize() == -1) { + QWindow *window = new QWindow; + window->setSurfaceType(QWindow::OpenGLSurface); + window->setGeometry(0, 0, 10, 10); + window->create(); + format = window->format(); + delete window; + } QOffscreenSurface *offscreenSurface = new QOffscreenSurface; + offscreenSurface->setFormat(format); offscreenSurface->create(); return offscreenSurface; } @@ -392,6 +407,10 @@ void qt_opengl_check_test_pattern(const QImage& img) // As we're doing more than trivial painting, we can't just compare to // an image rendered with raster. Instead, we sample at well-defined // test-points: + QVERIFY(!img.isNull()); + QVERIFY2(img.width() > 217, QByteArray::number(img.width())); + QVERIFY2(img.height() > 90, QByteArray::number(img.height())); + QFUZZY_COMPARE_PIXELS(img.pixel(39, 64), QColor(Qt::red).rgb()); QFUZZY_COMPARE_PIXELS(img.pixel(89, 64), QColor(Qt::red).rgb()); QFUZZY_COMPARE_PIXELS(img.pixel(64, 39), QColor(Qt::blue).rgb()); @@ -415,7 +434,7 @@ void tst_QOpenGL::fboSimpleRendering() QOpenGLContext ctx; QVERIFY(ctx.create()); - ctx.makeCurrent(surface.data()); + QVERIFY(ctx.makeCurrent(surface.data())); if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) QSKIP("QOpenGLFramebufferObject not supported on this platform"); @@ -424,21 +443,21 @@ void tst_QOpenGL::fboSimpleRendering() QOpenGLFramebufferObjectFormat fboFormat; fboFormat.setAttachment(QOpenGLFramebufferObject::NoAttachment); - QOpenGLFramebufferObject *fbo = new QOpenGLFramebufferObject(200, 100, fboFormat); + const QSize size(200, 100); + QScopedPointer<QOpenGLFramebufferObject> fbo(new QOpenGLFramebufferObject(size, fboFormat)); - fbo->bind(); + QVERIFY(fbo->bind()); glClearColor(1.0, 0.0, 0.0, 1.0); glClear(GL_COLOR_BUFFER_BIT); glFinish(); - QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32); - QImage reference(fb.size(), QImage::Format_RGB32); + const QImage fb = fbo->toImage().convertToFormat(QImage::Format_RGB32); + QCOMPARE(fb.size(), size); + QImage reference(size, QImage::Format_RGB32); reference.fill(0xffff0000); QFUZZY_COMPARE_IMAGES(fb, reference); - - delete fbo; } void tst_QOpenGL::fboTextureOwnership_data() @@ -511,7 +530,7 @@ void tst_QOpenGL::fboRendering() QOpenGLContext ctx; QVERIFY(ctx.create()); - ctx.makeCurrent(surface.data()); + QVERIFY(ctx.makeCurrent(surface.data())); if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) QSKIP("QOpenGLFramebufferObject not supported on this platform"); @@ -521,12 +540,13 @@ void tst_QOpenGL::fboRendering() fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil); // Uncomplicate things by using NPOT: - QOpenGLFramebufferObject fbo(256, 128, fboFormat); + const QSize size(256, 128); + QOpenGLFramebufferObject fbo(size, fboFormat); if (fbo.attachment() != QOpenGLFramebufferObject::CombinedDepthStencil) QSKIP("FBOs missing combined depth~stencil support"); - fbo.bind(); + QVERIFY(fbo.bind()); QPainter fboPainter; QOpenGLPaintDevice device(fbo.width(), fbo.height()); @@ -537,7 +557,8 @@ void tst_QOpenGL::fboRendering() fboPainter.end(); - QImage fb = fbo.toImage().convertToFormat(QImage::Format_RGB32); + const QImage fb = fbo.toImage().convertToFormat(QImage::Format_RGB32); + QCOMPARE(fb.size(), size); qt_opengl_check_test_pattern(fb); } @@ -588,9 +609,11 @@ void tst_QOpenGL::openGLPaintDevice() QSurfaceFormat format = ctx.format(); if (format.majorVersion() < 2) QSKIP("This test requires at least OpenGL 2.0"); - ctx.makeCurrent(surface.data()); + QVERIFY(ctx.makeCurrent(surface.data())); - QImage image(128, 128, QImage::Format_RGB32); + const QSize size(128, 128); + + QImage image(size, QImage::Format_RGB32); QPainter p(&image); p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red); p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green); @@ -598,32 +621,38 @@ void tst_QOpenGL::openGLPaintDevice() p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white); p.end(); - QOpenGLFramebufferObject fbo(128, 128); - fbo.bind(); + QOpenGLFramebufferObject fbo(size); + QVERIFY(fbo.bind()); - QOpenGLPaintDevice device(128, 128); - p.begin(&device); + QOpenGLPaintDevice device(size); + QVERIFY(p.begin(&device)); p.fillRect(0, 0, image.width() / 2, image.height() / 2, Qt::red); p.fillRect(image.width() / 2, 0, image.width() / 2, image.height() / 2, Qt::green); p.fillRect(image.width() / 2, image.height() / 2, image.width() / 2, image.height() / 2, Qt::blue); p.fillRect(0, image.height() / 2, image.width() / 2, image.height() / 2, Qt::white); p.end(); - QCOMPARE(image, fbo.toImage().convertToFormat(QImage::Format_RGB32)); + QImage actual = fbo.toImage().convertToFormat(QImage::Format_RGB32); + QCOMPARE(image.size(), actual.size()); + QCOMPARE(image, actual); - p.begin(&device); + QVERIFY(p.begin(&device)); p.fillRect(0, 0, image.width(), image.height(), Qt::black); p.drawImage(0, 0, image); p.end(); - QCOMPARE(image, fbo.toImage().convertToFormat(QImage::Format_RGB32)); + actual = fbo.toImage().convertToFormat(QImage::Format_RGB32); + QCOMPARE(image.size(), actual.size()); + QCOMPARE(image, actual); - p.begin(&device); + QVERIFY(p.begin(&device)); p.fillRect(0, 0, image.width(), image.height(), Qt::black); p.fillRect(0, 0, image.width(), image.height(), QBrush(image)); p.end(); - QCOMPARE(image, fbo.toImage().convertToFormat(QImage::Format_RGB32)); + actual = fbo.toImage().convertToFormat(QImage::Format_RGB32); + QCOMPARE(image.size(), actual.size()); + QCOMPARE(image, actual); } void tst_QOpenGL::aboutToBeDestroyed() @@ -689,9 +718,11 @@ void tst_QOpenGL::QTBUG15621_triangulatingStrokerDivZero() QSKIP("QTBUG-22617"); #endif + const QSize size(128, 128); + QWindow window; window.setSurfaceType(QWindow::OpenGLSurface); - window.setGeometry(0, 0, 128, 128); + window.setGeometry(QRect(QPoint(0, 0), size)); window.create(); QOpenGLContext ctx; @@ -701,10 +732,10 @@ void tst_QOpenGL::QTBUG15621_triangulatingStrokerDivZero() if (!QOpenGLFramebufferObject::hasOpenGLFramebufferObjects()) QSKIP("QOpenGLFramebufferObject not supported on this platform"); - QOpenGLFramebufferObject fbo(128, 128); - fbo.bind(); + QOpenGLFramebufferObject fbo(size); + QVERIFY(fbo.bind()); - QOpenGLPaintDevice device(128, 128); + QOpenGLPaintDevice device(size); // QTBUG-15621 is only a problem when qreal is double, but do the test anyway. qreal delta = sizeof(qreal) == sizeof(float) ? 1e-4 : 1e-8; @@ -731,10 +762,11 @@ void tst_QOpenGL::QTBUG15621_triangulatingStrokerDivZero() QPen pen(Qt::red, 28, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin); QPainter p(&device); - p.fillRect(QRect(0, 0, 128, 128), Qt::blue); + p.fillRect(QRect(QPoint(0, 0), size), Qt::blue); p.strokePath(path, pen); p.end(); - QImage image = fbo.toImage().convertToFormat(QImage::Format_RGB32); + const QImage image = fbo.toImage().convertToFormat(QImage::Format_RGB32); + QCOMPARE(image.size(), size); const QRgb red = 0xffff0000; const QRgb blue = 0xff0000ff; diff --git a/tests/auto/gui/text/qfont/tst_qfont.cpp b/tests/auto/gui/text/qfont/tst_qfont.cpp index 8406e843cf..6f75a1f8bb 100644 --- a/tests/auto/gui/text/qfont/tst_qfont.cpp +++ b/tests/auto/gui/text/qfont/tst_qfont.cpp @@ -74,7 +74,6 @@ private slots: void resetFont(); #endif void isCopyOf(); - void setFontRaw(); void italicOblique(); void insertAndRemoveSubstitutions(); void serialize_data(); @@ -418,15 +417,6 @@ void tst_QFont::compare() QVERIFY(font == font2); QVERIFY(!(font < font2)); } - -#if defined(Q_WS_X11) - { - QFont font1, font2; - font1.setRawName("-Adobe-Helvetica-medium-r-normal--12-120-75-75-p-67-iso8859-1"); - font2.setRawName("-Adobe-Helvetica-medium-r-normal--24-240-75-75-p-130-iso8859-1"); - QVERIFY(font1 != font2); - } -#endif } void tst_QFont::resolve() @@ -520,30 +510,6 @@ void tst_QFont::isCopyOf() QVERIFY(!font3.isCopyOf(font)); } -void tst_QFont::setFontRaw() -{ -#ifndef Q_WS_X11 - QSKIP("Only tested on X11"); -#else - QFont f; - f.setRawName("-*-fixed-bold-r-normal--0-0-*-*-*-0-iso8859-1"); -// qDebug("font family: %s", f.family().utf8()); - QFontDatabase fdb; - QStringList families = fdb.families(); - bool found = false; - for (int i = 0; i < families.size(); ++i) { - QString str = families.at(i); - if (str.contains('[')) - str = str.left(str.indexOf('[')-1); - if (str.toLower() == "fixed") - found = true; - } - if (!found) - QSKIP("Fixed font not available."); - QCOMPARE(QFontInfo(f).family().left(5).toLower(), QString("fixed")); -#endif -} - void tst_QFont::insertAndRemoveSubstitutions() { QFont::removeSubstitution("BogusFontFamily"); diff --git a/tests/auto/gui/text/qfontdatabase/FreeMono.ttf b/tests/auto/gui/text/qfontdatabase/FreeMono.ttf Binary files differdeleted file mode 100644 index d7ce52ddc7..0000000000 --- a/tests/auto/gui/text/qfontdatabase/FreeMono.ttf +++ /dev/null diff --git a/tests/auto/gui/text/qfontdatabase/LED_REAL.TTF b/tests/auto/gui/text/qfontdatabase/LED_REAL.TTF Binary files differnew file mode 100644 index 0000000000..f87ea95e0e --- /dev/null +++ b/tests/auto/gui/text/qfontdatabase/LED_REAL.TTF diff --git a/tests/auto/gui/text/qfontdatabase/LED_REAL_readme.txt b/tests/auto/gui/text/qfontdatabase/LED_REAL_readme.txt new file mode 100644 index 0000000000..06a5b40313 --- /dev/null +++ b/tests/auto/gui/text/qfontdatabase/LED_REAL_readme.txt @@ -0,0 +1,34 @@ +Font: LED Real (led_real.ttf) +Created By: Matthew Welch +E-Mail: daffy-duck@worldnet.att.net +Web Address: http://home.att.net/~daffy-duck + (PGP public key available here) + +LED Real, like all of my fonts, is free. You can use it for most +personal or business uses you'd like, and I ask for no money. I +would, however, like to hear from you. If you use my fonts for +something please send me a postcard or e-mail letting me know how +you used it. Send me a copy if you can or let me know where I can +find your work. + +You may use this font for graphical or printed work, but you may not +sell it or include it in a collection of fonts (on CD or otherwise) +being sold. You can redistribute this font as long as you charge +nothing to receive it. If you redistribute it include this text file +with it as is (without modifications). + +If you use this font for commercial purposes please credit me in +at least some little way. + +About the font: + +Unlike most LED/LCD style fonts mine could be recreated with an +actual LED. I created this font working from memories of the good +old Speak and Spell display. Since I don't have an actual Speak +and Spell to work from I had to just do as well as I could in its +spirit. Be warned that some characters look just like others. The +( and the <, for instance. Also C and [. Most of these will be +pretty clear in context. To see all the sections of the LED "lit +up" at once use character 127 (hold down alt and type 0127 on the +numeric keypad). This font is, of course, monospaced. + diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index fa5c81a2f0..28db0ba291 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -83,7 +83,7 @@ private: }; tst_QFontDatabase::tst_QFontDatabase() - : m_testFont(QFINDTESTDATA("FreeMono.ttf")) + : m_testFont(QFINDTESTDATA("LED_REAL.TTF")) { } diff --git a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp index 74802c3217..c4db669695 100644 --- a/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp +++ b/tests/auto/gui/text/qtextscriptengine/tst_qtextscriptengine.cpp @@ -86,12 +86,13 @@ private slots: void greek_data(); void greek(); - void controlInSyllable_qtbug14204(); - void combiningMarks_qtbug15675(); - void mirroredChars_data(); void mirroredChars(); + void controlInSyllable_qtbug14204(); + void combiningMarks_qtbug15675_data(); + void combiningMarks_qtbug15675(); + void thaiIsolatedSaraAm(); void thaiWithZWJ(); void thaiMultipleVowels(); @@ -1051,87 +1052,18 @@ void tst_QTextScriptEngine::greek() doShapingTests(); } -void tst_QTextScriptEngine::controlInSyllable_qtbug14204() -{ -#if 0 && defined(Q_OS_UNIX) - // ### the test is incorrect -> disable for now - QString s; - s.append(QChar(0x0915)); - s.append(QChar(0x094d)); - s.append(QChar(0x200d)); - s.append(QChar(0x0915)); - - QTextLayout layout(s); - QTextEngine *e = layout.engine(); - e->itemize(); - e->shape(0); - - QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(2)); - QVERIFY(e->layoutData->glyphLayout.advances[1].toInt() != 0); -#endif -} - -void tst_QTextScriptEngine::combiningMarks_qtbug15675() -{ -#if defined(Q_OS_MAC) - QString s; - s.append(QChar(0x0061)); - s.append(QChar(0x0062)); - s.append(QChar(0x0300)); - s.append(QChar(0x0063)); - - QFont font("Monaco"); - QTextLayout layout(s, font); - QTextEngine *e = layout.engine(); - e->itemize(); - e->shape(0); - - QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(4)); - QCOMPARE(e->layoutData->glyphLayout.advances[2].toInt(), 0); -#else - QFontDatabase db; - - if (!db.families().contains("DejaVu Sans Mono")) - QSKIP("Required font (DejaVu Sans Mono) doesn't exist, skip test."); - - QString s; - s.append(QChar(0x0062)); - s.append(QChar(0x0332)); - s.append(QChar(0x0063)); - - QTextLayout layout(s, QFont("DejaVu Sans Mono")); - QTextEngine *e = layout.engine(); - e->itemize(); - e->shape(0); - - QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(3)); - QCOMPARE(e->layoutData->glyphLayout.advances[1].toInt(), 0); -#endif -} - void tst_QTextScriptEngine::mirroredChars_data() { - QTest::addColumn<int>("hintingPreference"); + QTest::addColumn<QString>("s"); - QTest::newRow("Default hinting") << int(QFont::PreferDefaultHinting); - QTest::newRow("No hinting") << int(QFont::PreferNoHinting); - QTest::newRow("Vertical hinting") << int(QFont::PreferVerticalHinting); - QTest::newRow("Full hinting") << int(QFont::PreferFullHinting); + QTest::newRow("()") << QStringLiteral("()"); + QTest::newRow("[]") << QStringLiteral("[]"); + QTest::newRow("{}") << QStringLiteral("{}"); } void tst_QTextScriptEngine::mirroredChars() { -#if defined(Q_OS_MAC) - QSKIP("Not supported on Mac"); -#endif - QFETCH(int, hintingPreference); - - QFont font; - font.setHintingPreference(QFont::HintingPreference(hintingPreference)); - - QString s; - s.append(QLatin1Char('(')); - s.append(QLatin1Char(')')); + QFETCH(QString, s); glyph_t leftParenthesis; glyph_t rightParenthesis; @@ -1144,10 +1076,12 @@ void tst_QTextScriptEngine::mirroredChars() QTextEngine *e = layout.engine(); e->itemize(); + QCOMPARE(e->layoutData->items.size(), 1); + e->shape(0); QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(2)); - const QGlyphLayout &glyphLayout = e->layoutData->glyphLayout; + const QGlyphLayout glyphLayout = e->shapedGlyphs(&e->layoutData->items[0]); leftParenthesis = glyphLayout.glyphs[0]; rightParenthesis = glyphLayout.glyphs[1]; } @@ -1158,61 +1092,170 @@ void tst_QTextScriptEngine::mirroredChars() QTextEngine *e = layout.engine(); e->itemize(); + QCOMPARE(e->layoutData->items.size(), 1); + e->shape(0); QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(2)); - const QGlyphLayout &glyphLayout = e->layoutData->glyphLayout; + const QGlyphLayout glyphLayout = e->shapedGlyphs(&e->layoutData->items[0]); QCOMPARE(glyphLayout.glyphs[0], rightParenthesis); QCOMPARE(glyphLayout.glyphs[1], leftParenthesis); } } +void tst_QTextScriptEngine::controlInSyllable_qtbug14204() +{ + QFontDatabase db; + if (!db.families().contains(QStringLiteral("Aparajita"))) + QSKIP("couldn't find 'Aparajita' font"); + + QFont font(QStringLiteral("Aparajita")); + font.setStyleStrategy(QFont::NoFontMerging); + + QString s; + s.append(QChar(0x0915)); + s.append(QChar(0x094d)); + s.append(QChar(0x200d)); + s.append(QChar(0x0915)); + + QTextLayout layout(s, font); + QTextEngine *e = layout.engine(); + e->itemize(); + QCOMPARE(e->layoutData->items.size(), 1); + + QFontEngine *fe = e->fontEngine(e->layoutData->items[0]); + if (fe->type() == QFontEngine::Box) + QSKIP("OpenType support missing for script"); + QCOMPARE(fe->fontDef.family, font.family()); + + e->shape(0); + QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(2)); + + const ushort *log_clusters = e->logClusters(&e->layoutData->items[0]); + QCOMPARE(log_clusters[0], ushort(0)); + QCOMPARE(log_clusters[1], ushort(0)); + QCOMPARE(log_clusters[2], ushort(0)); + QCOMPARE(log_clusters[3], ushort(0)); +} + +void tst_QTextScriptEngine::combiningMarks_qtbug15675_data() +{ + QTest::addColumn<QFont>("font"); + QTest::addColumn<QString>("string"); + + bool hasTests = false; + + QStringList families; + families << QStringLiteral("Monaco"); + families << QStringLiteral("DejaVu Sans Mono"); + + foreach (const QString &family, families) { + QFont font(family); + font.setStyleStrategy(QFont::NoFontMerging); + if (QFontInfo(font).family() != family) + continue; + + hasTests = true; + + QString s(QStringLiteral("ab cd")); + for (ushort uc = 0x0300; uc < 0x0370; ++uc) { + s[2] = QChar(uc); + QByteArray testName = family.toLatin1() + ": ab<U+" + QByteArray::number(uc, 16).rightJustified(4, '0') + ">cd"; + QTest::newRow(testName.constData()) << font << s; + } + } + + if (!hasTests) + QSKIP("Couldn't find required fonts, skip test."); +} + +void tst_QTextScriptEngine::combiningMarks_qtbug15675() +{ + QFETCH(QFont, font); + QFETCH(QString, string); + + QTextLayout layout(string, font); + QTextEngine *e = layout.engine(); + e->itemize(); + QCOMPARE(e->layoutData->items.size(), 1); + + QFontEngine *fe = e->fontEngine(e->layoutData->items[0]); + if (fe->type() == QFontEngine::Box) + QSKIP("OpenType support missing for script"); + QCOMPARE(fe->fontDef.family, font.family()); + + e->shape(0); + const int diff = e->layoutData->items[0].num_glyphs - string.size(); + QVERIFY(diff >= -1 && diff <= 1); // could compose or decompose exactly one character + + const ushort *log_clusters = e->logClusters(&e->layoutData->items[0]); + QCOMPARE(log_clusters[0], ushort(0)); + QCOMPARE(log_clusters[1], ushort(1)); + QCOMPARE(log_clusters[2], ushort(1)); + QCOMPARE(log_clusters[3], ushort(3 + diff)); + QCOMPARE(log_clusters[4], ushort(4 + diff)); + + const QGlyphLayout glyphLayout = e->shapedGlyphs(&e->layoutData->items[0]); + for (int i = 0; i < glyphLayout.numGlyphs; ++i) { + if ((diff >= 0 && i == 2) || (diff > 0 && i == 2 + diff)) + QCOMPARE(glyphLayout.advances[i].toInt(), 0); + else + QVERIFY(glyphLayout.advances[i].toInt() != 0); + } +} + void tst_QTextScriptEngine::thaiIsolatedSaraAm() { - if (QFontDatabase().families(QFontDatabase::Any).contains("Waree")) { - QString s; - s.append(QChar(0x0e33)); + QFontDatabase db; + if (!db.families().contains("Waree")) + QSKIP("couldn't find 'Waree' font"); - QTextLayout layout(s, QFont("Waree")); - layout.setCacheEnabled(true); - layout.beginLayout(); - layout.createLine(); - layout.endLayout(); + QFont font(QStringLiteral("Waree")); + font.setStyleStrategy(QFont::NoFontMerging); - QTextEngine *e = layout.engine(); - e->itemize(); - e->shape(0); - QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(3)); + QString s; + s.append(QChar(0x0e33)); - unsigned short *logClusters = e->logClusters(&e->layoutData->items[0]); - QCOMPARE(logClusters[0], ushort(0)); - } else - QSKIP("Cannot find Waree."); + QTextLayout layout(s, font); + QTextEngine *e = layout.engine(); + e->itemize(); + QCOMPARE(e->layoutData->items.size(), 1); + + QFontEngine *fe = e->fontEngine(e->layoutData->items[0]); + if (fe->type() == QFontEngine::Box) + QSKIP("OpenType support missing for script"); + QCOMPARE(fe->fontDef.family, font.family()); + + e->shape(0); + QVERIFY(e->layoutData->items[0].num_glyphs > 0); + + const ushort *log_clusters = e->logClusters(&e->layoutData->items[0]); + QCOMPARE(log_clusters[0], ushort(0)); } void tst_QTextScriptEngine::thaiWithZWJ() { -#ifdef Q_OS_WIN - QSKIP("This test currently fails on Windows - QTBUG-24565"); -#endif + QFontDatabase db; + if (!db.families().contains("Waree")) + QSKIP("couldn't find 'Waree' font"); + + QFont font(QStringLiteral("Waree")); + font.setStyleStrategy(QFont::NoFontMerging); + QString s(QString::fromUtf8("\xe0\xb8\xa3\xe2\x80\x8d\xe0\xb8\xa3\xe2\x80" "\x8c\x2e\xe0\xb8\xa3\x2e\xe2\x80\x9c\xe0\xb8" "\xa3\xe2\x80\xa6\xe0\xb8\xa3\xe2\x80\x9d\xe0" "\xb8\xa3\xa0\xe0\xb8\xa3\xe6\x9c\xac\xe0\xb8\xa3") + QChar(0x0363)/*superscript 'a', for testing Inherited class*/); - QTextLayout layout(s); - layout.setCacheEnabled(true); - layout.beginLayout(); - layout.createLine(); - layout.endLayout(); + QTextLayout layout(s, font); QTextEngine *e = layout.engine(); - e->width(0, s.length()); //force itemize and shape - - // A thai implementation could either remove the ZWJ and ZWNJ characters, or hide them. - // The current implementation hides them, so we test for that. - // But make sure that we don't hide anything else + e->itemize(); QCOMPARE(e->layoutData->items.size(), 11); + + for (int item = 0; item < e->layoutData->items.size(); ++item) + e->shape(item); + QCOMPARE(e->layoutData->items[0].num_glyphs, ushort(7)); // Thai: The ZWJ and ZWNJ characters are inherited, so should be part of the thai script QCOMPARE(e->layoutData->items[1].num_glyphs, ushort(1)); // Common: The smart quotes cannot be handled by thai, so should be a separate item QCOMPARE(e->layoutData->items[2].num_glyphs, ushort(1)); // Thai: Thai character @@ -1231,15 +1274,18 @@ void tst_QTextScriptEngine::thaiWithZWJ() QCOMPARE(logClusters[i], ushort(i)); for (int i = 0; i < 10; i++) QCOMPARE(logClusters[i+7], ushort(0)); -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-23064", Abort); -#endif QCOMPARE(logClusters[17], ushort(1)); - // The only characters that we should be hiding are the ZWJ and ZWNJ characters in position 1 - // and 3. - for (int i = 0; i < 18; i++) - QCOMPARE((bool)e->layoutData->glyphLayout.attributes[i].dontPrint, (i == 1 || i == 3)); + // A thai implementation could either remove the ZWJ and ZWNJ characters, or hide them. + // The current implementation hides them, so we test for that. + // The only characters that we should be hiding are the ZWJ and ZWNJ characters in position 1 and 3. + const QGlyphLayout glyphLayout = e->layoutData->glyphLayout; + for (int i = 0; i < 18; i++) { + if (i == 1 || i == 3) + QCOMPARE(glyphLayout.advances[i].toInt(), 0); + else + QVERIFY(glyphLayout.advances[i].toInt() != 0); + } } void tst_QTextScriptEngine::thaiMultipleVowels() @@ -1253,14 +1299,13 @@ void tst_QTextScriptEngine::thaiMultipleVowels() for (int i = 0; i < 10; i++) s += s; //Repeat the string to make it more likely to crash if we have a buffer overflow - QTextLayout layout(s); - layout.setCacheEnabled(true); - layout.beginLayout(); - layout.createLine(); - layout.endLayout(); + QTextLayout layout(s); QTextEngine *e = layout.engine(); - e->width(0, s.length()); //force itemize and shape + e->itemize(); + + for (int item = 0; item < e->layoutData->items.size(); ++item) + e->shape(item); // If we haven't crashed at this point, then the test has passed. } diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp index 6eb20dd1f5..ded3966992 100644 --- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp +++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp @@ -271,6 +271,9 @@ void tst_QSslSocket::initTestCase_data() void tst_QSslSocket::initTestCase() { + qDebug("Using SSL library %s (%ld)", + qPrintable(QSslSocket::sslLibraryVersionString()), + QSslSocket::sslLibraryVersionNumber()); QVERIFY(QtNetworkSettings::verifyTestNetworkSettings()); } @@ -347,6 +350,9 @@ void tst_QSslSocket::proxyAuthenticationRequired(const QNetworkProxy &, QAuthent void tst_QSslSocket::constructing() { + const char readNotOpenMessage[] = "QIODevice::read: device not open"; + const char writeNotOpenMessage[] = "QIODevice::write: device not open"; + if (!QSslSocket::supportsSsl()) return; @@ -363,6 +369,7 @@ void tst_QSslSocket::constructing() QCOMPARE(socket.sslConfiguration(), QSslConfiguration::defaultConfiguration()); QCOMPARE(socket.errorString(), QString("Unknown error")); char c = '\0'; + QTest::ignoreMessage(QtWarningMsg, readNotOpenMessage); QVERIFY(!socket.getChar(&c)); QCOMPARE(c, '\0'); QVERIFY(!socket.isOpen()); @@ -371,11 +378,16 @@ void tst_QSslSocket::constructing() QVERIFY(!socket.isTextModeEnabled()); QVERIFY(!socket.isWritable()); QCOMPARE(socket.openMode(), QIODevice::NotOpen); + QTest::ignoreMessage(QtWarningMsg, readNotOpenMessage); QVERIFY(socket.peek(2).isEmpty()); QCOMPARE(socket.pos(), qint64(0)); + QTest::ignoreMessage(QtWarningMsg, writeNotOpenMessage); QVERIFY(!socket.putChar('c')); + QTest::ignoreMessage(QtWarningMsg, readNotOpenMessage); QVERIFY(socket.read(2).isEmpty()); + QTest::ignoreMessage(QtWarningMsg, readNotOpenMessage); QCOMPARE(socket.read(0, 0), qint64(-1)); + QTest::ignoreMessage(QtWarningMsg, readNotOpenMessage); QVERIFY(socket.readAll().isEmpty()); QTest::ignoreMessage(QtWarningMsg, "QIODevice::readLine: Called with maxSize < 2"); QCOMPARE(socket.readLine(0, 0), qint64(-1)); @@ -388,7 +400,9 @@ void tst_QSslSocket::constructing() QCOMPARE(socket.size(), qint64(0)); QVERIFY(!socket.waitForBytesWritten(10)); QVERIFY(!socket.waitForReadyRead(10)); + QTest::ignoreMessage(QtWarningMsg, writeNotOpenMessage); QCOMPARE(socket.write(0, 0), qint64(-1)); + QTest::ignoreMessage(QtWarningMsg, writeNotOpenMessage); QCOMPARE(socket.write(QByteArray()), qint64(-1)); QCOMPARE(socket.error(), QAbstractSocket::UnknownSocketError); QVERIFY(!socket.flush()); @@ -672,7 +686,7 @@ void tst_QSslSocket::sessionCipher() connect(socket.data(), SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(ignoreErrorSlot())); QVERIFY(socket->sessionCipher().isNull()); socket->connectToHost(QtNetworkSettings::serverName(), 443 /* https */); - QVERIFY(socket->waitForConnected(10000)); + QVERIFY2(socket->waitForConnected(10000), qPrintable(socket->errorString())); QVERIFY(socket->sessionCipher().isNull()); socket->startClientEncryption(); if (!socket->waitForEncrypted(5000)) @@ -775,7 +789,7 @@ void tst_QSslSocket::peerCertificateChain() socket->connectToHost(QtNetworkSettings::serverName(), 443); QCOMPARE(socket->mode(), QSslSocket::UnencryptedMode); QVERIFY(socket->peerCertificateChain().isEmpty()); - QVERIFY2(socket->waitForConnected(10000), "Network timeout"); + QVERIFY2(socket->waitForConnected(10000), qPrintable(socket->errorString())); socket->startClientEncryption(); if (setProxy && !socket->waitForEncrypted(10000)) @@ -1334,7 +1348,7 @@ void tst_QSslSocket::waitForConnectedEncryptedReadyRead() connect(this->socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(ignoreErrorSlot())); socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 993); - QVERIFY(socket->waitForConnected(10000)); + QVERIFY2(socket->waitForConnected(10000), qPrintable(socket->errorString())); QFETCH_GLOBAL(bool, setProxy); if (setProxy && !socket->waitForEncrypted(10000)) QSKIP("Skipping flaky test - See QTBUG-29941"); @@ -1679,7 +1693,7 @@ void tst_QSslSocket::setReadBufferSize_task_250027() socket->ignoreSslErrors(); socket->connectToHostEncrypted(QtNetworkSettings::serverName(), 443); socket->ignoreSslErrors(); - QVERIFY(socket->waitForConnected(10*1000)); + QVERIFY2(socket->waitForConnected(10*1000), qPrintable(socket->errorString())); if (setProxy && !socket->waitForEncrypted(10*1000)) QSKIP("Skipping flaky test - See QTBUG-29941"); diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index 2bf8a40451..9f0540173a 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -1415,19 +1415,19 @@ void tst_QAccessibility::menuTest() iFile->actionInterface()->doAction(QAccessibleActionInterface::showMenuAction()); if(menuFade) QTest::qWait(menuFadeDelay); - QVERIFY(file->isVisible() && !edit->isVisible() && !help->isVisible()); + QTRY_VERIFY(file->isVisible() && !edit->isVisible() && !help->isVisible()); iEdit->actionInterface()->doAction(QAccessibleActionInterface::showMenuAction()); if(menuFade) QTest::qWait(menuFadeDelay); - QVERIFY(!file->isVisible() && edit->isVisible() && !help->isVisible()); + QTRY_VERIFY(!file->isVisible() && edit->isVisible() && !help->isVisible()); iHelp->actionInterface()->doAction(QAccessibleActionInterface::showMenuAction()); if(menuFade) QTest::qWait(menuFadeDelay); - QVERIFY(!file->isVisible() && !edit->isVisible() && help->isVisible()); + QTRY_VERIFY(!file->isVisible() && !edit->isVisible() && help->isVisible()); iAction->actionInterface()->doAction(QAccessibleActionInterface::showMenuAction()); if(menuFade) QTest::qWait(menuFadeDelay); - QVERIFY(!file->isVisible() && !edit->isVisible() && !help->isVisible()); + QTRY_VERIFY(!file->isVisible() && !edit->isVisible() && !help->isVisible()); QVERIFY(interface->actionInterface()); QCOMPARE(interface->actionInterface()->actionNames(), QStringList()); @@ -1500,8 +1500,8 @@ void tst_QAccessibility::menuTest() iFile->actionInterface()->doAction(QAccessibleActionInterface::showMenuAction()); iFileNew->actionInterface()->doAction(QAccessibleActionInterface::showMenuAction()); - QVERIFY(file->isVisible()); - QVERIFY(fileNew->isVisible()); + QTRY_VERIFY(file->isVisible()); + QTRY_VERIFY(fileNew->isVisible()); QVERIFY(!edit->isVisible()); QVERIFY(!help->isVisible()); diff --git a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp index 25dd0d39dd..25b47ee836 100644 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp +++ b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac.cpp @@ -79,6 +79,7 @@ private slots: void init(); void cleanup(); + void singleWidgetTest(); void lineEditTest(); void hierarchyTest(); private: @@ -101,6 +102,16 @@ void tst_QAccessibilityMac::cleanup() delete m_window; } +void tst_QAccessibilityMac::singleWidgetTest() +{ + if (!macNativeAccessibilityEnabled()) + return; + + delete m_window; + m_window = 0; + + QVERIFY(singleWidget()); +} void tst_QAccessibilityMac::lineEditTest() { @@ -122,14 +133,19 @@ void tst_QAccessibilityMac::hierarchyTest() QWidget *w = new QWidget(m_window); m_window->addWidget(w); - QPushButton *b = new QPushButton(w); + w->setLayout(new QVBoxLayout()); + QPushButton *b = new QPushButton(w); w->layout()->addWidget(b); b->setText("I am a button"); + QPushButton *b2 = new QPushButton(w); + w->layout()->addWidget(b2); + b2->setText("Button 2"); + QVERIFY(QTest::qWaitForWindowExposed(m_window)); QCoreApplication::processEvents(); - QVERIFY(testHierarchy()); + QVERIFY(testHierarchy(w)); } QTEST_MAIN(tst_QAccessibilityMac) diff --git a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.h b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.h index ec5beab125..635b6383ab 100644 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.h +++ b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.h @@ -48,4 +48,5 @@ bool macNativeAccessibilityEnabled(); bool trusted(); bool testLineEdit(); -bool testHierarchy(); +bool testHierarchy(QWidget *w); +bool singleWidget(); diff --git a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm index 8620b7dd2f..bc89ac858b 100644 --- a/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm +++ b/tests/auto/other/qaccessibilitymac/tst_qaccessibilitymac_helpers.mm @@ -43,8 +43,10 @@ #define QT_NO_KEYWORDS #include "tst_qaccessibilitymac_helpers.h" -#include <QApplication> -#include <QDebug> +#include <QtWidgets/qapplication.h> +#include <QtWidgets/qlineedit.h> +#include <QtWidgets/qpushbutton.h> +#include <QtTest> #include <unistd.h> #import <Cocoa/Cocoa.h> @@ -148,9 +150,41 @@ bool trusted() return p; } ++ (TestAXObject *) getApplicationAXObject +{ + pid_t pid = getpid(); + AXUIElementRef appRef = AXUIElementCreateApplication(pid); + TestAXObject *appObject = [[TestAXObject alloc] initWithAXUIElementRef: appRef]; + return appObject; +} + @end +bool singleWidget() +{ + QLineEdit le; + le.setText("button"); + le.show(); + EXPECT(QTest::qWaitForWindowExposed(&le)); + QCoreApplication::processEvents(); + + TestAXObject *appObject = [TestAXObject getApplicationAXObject]; + EXPECT(appObject); + + NSArray *windows = [appObject windowList]; + EXPECT([windows count] == 1); + + AXUIElementRef windowRef = (AXUIElementRef) [windows objectAtIndex: 0]; + EXPECT(windowRef != nil); + TestAXObject *window = [[TestAXObject alloc] initWithAXUIElementRef: windowRef]; + + AXUIElementRef lineEdit = [window findDirectChildByRole: kAXTextFieldRole]; + EXPECT(lineEdit != nil); + + return true; +} + bool testLineEdit() { // not sure if this is needed. on my machine the calls succeed. @@ -159,10 +193,8 @@ bool testLineEdit() // AXError e = AXMakeProcessTrusted((CFStringRef) path); // NSLog(@"error: %i", e); - pid_t pid = getpid(); - AXUIElementRef app = AXUIElementCreateApplication(pid); - EXPECT(app != nil); - TestAXObject *appObject = [[TestAXObject alloc] initWithAXUIElementRef: app]; + TestAXObject *appObject = [TestAXObject getApplicationAXObject]; + EXPECT(appObject); NSArray *windowList = [appObject windowList]; // one window @@ -184,12 +216,10 @@ bool testLineEdit() return true; } -bool testHierarchy() +bool testHierarchy(QWidget *w) { - pid_t pid = getpid(); - AXUIElementRef app = AXUIElementCreateApplication(pid); - EXPECT(app != nil); - TestAXObject *appObject = [[TestAXObject alloc] initWithAXUIElementRef: app]; + TestAXObject *appObject = [TestAXObject getApplicationAXObject]; + EXPECT(appObject); NSArray *windowList = [appObject windowList]; // one window @@ -207,7 +237,36 @@ bool testHierarchy() TestAXObject *parentObject = [[TestAXObject alloc] initWithAXUIElementRef: [buttonObject parent]]; // check that the parent is a window - EXPECT([[parentObject role] isEqualToString: (NSString *)kAXWindowRole]); + EXPECT([[parentObject role] isEqualToString: NSAccessibilityWindowRole]); + + // test the focus + // child 0 is the layout, then button1 and 2 + QPushButton *button1 = qobject_cast<QPushButton*>(w->children().at(1)); + EXPECT(button1); + QPushButton *button2 = qobject_cast<QPushButton*>(w->children().at(2)); + EXPECT(button2); + button2->setFocus(); + + AXUIElementRef systemWideElement = AXUIElementCreateSystemWide(); + AXUIElementRef focussedElement = NULL; + AXError error = AXUIElementCopyAttributeValue(systemWideElement, + (CFStringRef)NSAccessibilityFocusedUIElementAttribute, (CFTypeRef*)&focussedElement); + EXPECT(!error); + EXPECT(focussedElement); + TestAXObject *focusButton2 = [[TestAXObject alloc] initWithAXUIElementRef: focussedElement]; + + EXPECT([[focusButton2 role] isEqualToString: NSAccessibilityButtonRole]); + EXPECT([[focusButton2 description] isEqualToString: @"Button 2"]); + + + button1->setFocus(); + error = AXUIElementCopyAttributeValue(systemWideElement, + (CFStringRef)NSAccessibilityFocusedUIElementAttribute, (CFTypeRef*)&focussedElement); + EXPECT(!error); + EXPECT(focussedElement); + TestAXObject *focusButton1 = [[TestAXObject alloc] initWithAXUIElementRef: focussedElement]; + EXPECT([[focusButton1 role] isEqualToString: NSAccessibilityButtonRole]); + EXPECT([[focusButton1 description] isEqualToString: @"I am a button"]); return true; } diff --git a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp index 5f1eb99524..a497fac79a 100644 --- a/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp +++ b/tests/auto/sql/kernel/qsqlquery/tst_qsqlquery.cpp @@ -1069,6 +1069,18 @@ void tst_QSqlQuery::numRowsAffected() QCOMPARE( q.numRowsAffected(), i ); QCOMPARE( q.numRowsAffected(), i ); // yes, we check twice + QVERIFY_SQL( q, prepare( "update " + qtest + " set id = id + :newid" ) ); + q.bindValue(":newid", 100); + QVERIFY_SQL( q, exec() ); + QCOMPARE( q.numRowsAffected(), i ); + QCOMPARE( q.numRowsAffected(), i ); // yes, we check twice + + QVERIFY_SQL( q, prepare( "update " + qtest + " set id = id + :newid where NOT(1 = 1)" ) ); + q.bindValue(":newid", 100); + QVERIFY_SQL( q, exec() ); + QCOMPARE( q.numRowsAffected(), 0 ); + QCOMPARE( q.numRowsAffected(), 0 ); // yes, we check twice + QVERIFY_SQL( q, exec( "insert into " + qtest + " values (42000, 'homer', 'marge')" ) ); QCOMPARE( q.numRowsAffected(), 1 ); QCOMPARE( q.numRowsAffected(), 1 ); // yes, we check twice diff --git a/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp b/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp index 6eb36115cb..c5717a808c 100644 --- a/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp +++ b/tests/auto/widgets/dialogs/qfontdialog/tst_qfontdialog.cpp @@ -66,6 +66,7 @@ public slots: void postKeyReturn(); void testGetFont(); void testSetFont(); + void testNonStandardFontSize(); public slots: void initTestCase(); @@ -76,6 +77,7 @@ private slots: void defaultOkButton(); void setFont(); void task256466_wrongStyle(); + void setNonStandardFontSize(); private: void runSlotWithFailsafeTimer(const char *member); @@ -203,8 +205,38 @@ void tst_QFontDialog::task256466_wrongStyle() } } +void tst_QFontDialog::setNonStandardFontSize() +{ + runSlotWithFailsafeTimer(SLOT(testNonStandardFontSize())); +} +void tst_QFontDialog::testNonStandardFontSize() +{ + QList<int> standardSizesList = QFontDatabase::standardSizes(); + int nonStandardFontSize; + if (!standardSizesList.isEmpty()) { + nonStandardFontSize = standardSizesList.at(standardSizesList.count()-1); // get the maximum standard size. + nonStandardFontSize += 1; // the increment of 1 to mock a non-standard font size. + } else { + QSKIP("QFontDatabase::standardSizes() is empty."); + } + QFont testFont; + testFont.setPointSize(nonStandardFontSize); + + bool accepted = false; + QTimer::singleShot(2000, this, SLOT(postKeyReturn())); + QFont resultFont = QFontDialog::getFont(&accepted, testFont, + QApplication::activeWindow(), + QLatin1String("QFontDialog - NonStandardFontSize Test"), + QFontDialog::DontUseNativeDialog); + QVERIFY(accepted); + + if (accepted) + QCOMPARE(testFont.pointSize(), resultFont.pointSize()); + else + QWARN("Fail using a non-standard font size."); +} QTEST_MAIN(tst_QFontDialog) #include "tst_qfontdialog.moc" diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index d3f6c2db00..5b178903cf 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -3065,21 +3065,30 @@ void tst_QGraphicsProxyWidget::createProxyForChildWidget() delete boxProxy; } -class ContextMenuWidget : public QWidget +class ContextMenuWidget : public QLabel { Q_OBJECT public: ContextMenuWidget() - : embeddedPopup(false), - gotContextMenuEvent(false) + : QLabel(QStringLiteral("ContextMenuWidget")) + , embeddedPopup(false) + , gotContextMenuEvent(false) + , m_embeddedPopupSet(false) + , m_timer(0) { } bool embeddedPopup; bool gotContextMenuEvent; protected: bool event(QEvent *event) { - if (event->type() == QEvent::ContextMenu) - QTimer::singleShot(0, this, SLOT(checkMenu())); + if (event->type() == QEvent::ContextMenu) { + if (!m_timer) { + m_timer = new QTimer(this); + m_timer->setInterval(10); + connect(m_timer, SIGNAL(timeout()), this, SLOT(checkMenu())); + m_timer->start(); + } + } return QWidget::event(event); } void contextMenuEvent(QContextMenuEvent *) @@ -3090,10 +3099,19 @@ protected: private slots: void checkMenu() { - if (this->findChild<QMenu *>()) - embeddedPopup = true; + QMenu *menu = findChild<QMenu *>(); + if (!m_embeddedPopupSet) { + m_embeddedPopupSet = true; + embeddedPopup = menu != 0; + } + if (menu && menu->isVisible()) + menu->hide(); hide(); } + +private: + bool m_embeddedPopupSet; + QTimer *m_timer; }; void tst_QGraphicsProxyWidget::actionsContextMenu_data() @@ -3120,8 +3138,11 @@ void tst_QGraphicsProxyWidget::actionsContextMenu() widget->setContextMenuPolicy(Qt::ActionsContextMenu); } QGraphicsScene scene; - + QGraphicsProxyWidget *proxyWidget = scene.addWidget(widget); QGraphicsView view(&scene); + view.setWindowTitle(QStringLiteral("actionsContextMenu")); + view.resize(200, 200); + view.move(QGuiApplication::primaryScreen()->geometry().center() - QPoint(100, 100)); view.show(); QApplication::setActiveWindow(&view); QVERIFY(QTest::qWaitForWindowActive(&view)); @@ -3129,9 +3150,9 @@ void tst_QGraphicsProxyWidget::actionsContextMenu() QTRY_VERIFY(view.hasFocus()); if (hasFocus) - scene.addWidget(widget)->setFocus(); + proxyWidget->setFocus(); else - scene.addWidget(widget)->clearFocus(); + proxyWidget->clearFocus(); QApplication::processEvents(); diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index c3aaf6be16..1005bf6b3c 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -60,6 +60,7 @@ #include <qlineedit.h> #include <qscreen.h> #include <qscopedpointer.h> +#include <qstyleditemdelegate.h> static inline void setFrameless(QWidget *w) { @@ -244,6 +245,9 @@ private slots: void testChangeEditorState(); void deselectInSingleSelection(); void testNoActivateOnDisabledItem(); + void testFocusPolicy_data(); + void testFocusPolicy(); + void QTBUG31411_noSelection(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -1728,5 +1732,97 @@ void tst_QAbstractItemView::testNoActivateOnDisabledItem() QCOMPARE(activatedSpy.count(), 0); } +void tst_QAbstractItemView::testFocusPolicy_data() +{ + QTest::addColumn<QAbstractItemDelegate*>("delegate"); + + QAbstractItemDelegate *styledItemDelegate = new QStyledItemDelegate(this); + QAbstractItemDelegate *itemDelegate = new QItemDelegate(this); + + QTest::newRow("QStyledItemDelegate") << styledItemDelegate; + QTest::newRow("QItemDelegate") << itemDelegate; +} + +void tst_QAbstractItemView::testFocusPolicy() +{ + QFETCH(QAbstractItemDelegate*, delegate); + + QWidget window; + QTableView *table = new QTableView(&window); + table->setItemDelegate(delegate); + QVBoxLayout *layout = new QVBoxLayout(&window); + layout->addWidget(table); + + QStandardItemModel model; + model.setRowCount(10); + model.setColumnCount(10); + table->setModel(&model); + table->setCurrentIndex(model.index(1, 1)); + + centerOnScreen(&window); + moveCursorAway(&window); + + window.show(); + QApplication::setActiveWindow(&window); + QVERIFY(QTest::qWaitForWindowActive(&window)); + + // itemview accepts focus => editor is closed => return focus to the itemview + QPoint clickpos = table->visualRect(model.index(1, 1)).center(); + QTest::mouseDClick(table->viewport(), Qt::LeftButton, Qt::NoModifier, clickpos); + QWidget *editor = qApp->focusWidget(); + QVERIFY(editor); + QTest::keyClick(editor, Qt::Key_Escape, Qt::NoModifier); + QCOMPARE(qApp->focusWidget(), table); + + // itemview doesn't accept focus => editor is closed => clear the focus + table->setFocusPolicy(Qt::NoFocus); + QTest::mouseDClick(table->viewport(), Qt::LeftButton, Qt::NoModifier, clickpos); + editor = qApp->focusWidget(); + QVERIFY(editor); + QTest::keyClick(editor, Qt::Key_Escape, Qt::NoModifier); + QVERIFY(!qApp->focusWidget()); +} + +Q_DECLARE_METATYPE(QItemSelection) +void tst_QAbstractItemView::QTBUG31411_noSelection() +{ + QWidget window; + QTableView *table = new QTableView(&window); + table->setSelectionMode(QAbstractItemView::NoSelection); + QVBoxLayout *layout = new QVBoxLayout(&window); + layout->addWidget(table); + + QStandardItemModel model; + model.setRowCount(10); + model.setColumnCount(10); + table->setModel(&model); + table->setCurrentIndex(model.index(1, 1)); + + centerOnScreen(&window); + moveCursorAway(&window); + + window.show(); + QApplication::setActiveWindow(&window); + QVERIFY(QTest::qWaitForWindowActive(&window)); + + qRegisterMetaType<QItemSelection>(); + QSignalSpy selectionChangeSpy(table->selectionModel(), SIGNAL(selectionChanged(QItemSelection,QItemSelection))); + QVERIFY(selectionChangeSpy.isValid()); + + QPoint clickpos = table->visualRect(model.index(1, 1)).center(); + QTest::mouseClick(table->viewport(), Qt::LeftButton, Qt::NoModifier, clickpos); + QTest::mouseDClick(table->viewport(), Qt::LeftButton, Qt::NoModifier, clickpos); + + QPointer<QWidget> editor1 = qApp->focusWidget(); + QVERIFY(editor1); + QTest::keyClick(editor1, Qt::Key_Tab, Qt::NoModifier); + + QPointer<QWidget> editor2 = qApp->focusWidget(); + QVERIFY(editor2); + QTest::keyClick(editor2, Qt::Key_Escape, Qt::NoModifier); + + QCOMPARE(selectionChangeSpy.count(), 0); +} + QTEST_MAIN(tst_QAbstractItemView) #include "tst_qabstractitemview.moc" diff --git a/tests/auto/widgets/widgets/qtoolbutton/tst_qtoolbutton.cpp b/tests/auto/widgets/widgets/qtoolbutton/tst_qtoolbutton.cpp index aaff322c4b..168a17773e 100644 --- a/tests/auto/widgets/widgets/qtoolbutton/tst_qtoolbutton.cpp +++ b/tests/auto/widgets/widgets/qtoolbutton/tst_qtoolbutton.cpp @@ -48,6 +48,8 @@ #include <qmenu.h> #include <qaction.h> #include <qstyleoption.h> +#include <qscreen.h> +#include <qlabel.h> class tst_QToolButton : public QObject { @@ -68,7 +70,7 @@ private slots: protected slots: void sendMouseClick(); private: - QWidget *w; + QPointer<QWidget> m_menu; }; tst_QToolButton::tst_QToolButton() @@ -121,29 +123,39 @@ void tst_QToolButton::getSetCheck() void tst_QToolButton::triggered() { qRegisterMetaType<QAction *>("QAction *"); - QToolButton tb; - tb.show(); - QSignalSpy spy(&tb,SIGNAL(triggered(QAction*))); - QMenu *menu = new QMenu("Menu"); + QWidget mainWidget; + mainWidget.setWindowTitle(QStringLiteral("triggered")); + mainWidget.resize(200, 200); + mainWidget.move(QGuiApplication::primaryScreen()->availableGeometry().center() - QPoint(100, 100)); + QToolButton *toolButton = new QToolButton(&mainWidget); + QSignalSpy spy(toolButton,SIGNAL(triggered(QAction*))); + QScopedPointer<QMenu> menu(new QMenu(QStringLiteral("Menu"))); QAction *one = menu->addAction("one"); menu->addAction("two"); - QAction *def = new QAction("def", this); + QAction *defaultAction = new QAction(QStringLiteral("def"), this); - tb.setMenu(menu); - tb.setDefaultAction(def); + toolButton->setMenu(menu.data()); + toolButton->setDefaultAction(defaultAction); + mainWidget.show(); + QApplication::setActiveWindow(&mainWidget); + QVERIFY(QTest::qWaitForWindowActive(&mainWidget)); - def->trigger(); + defaultAction->trigger(); QCOMPARE(spy.count(),1); - QCOMPARE(qvariant_cast<QAction *>(spy.at(0).at(0)), def); + QCOMPARE(qvariant_cast<QAction *>(spy.at(0).at(0)), defaultAction); - w = menu; - QTimer::singleShot(30, this, SLOT(sendMouseClick())); - tb.showMenu(); + m_menu = menu.data(); + + QTimer *timer = new QTimer(this); + timer->setInterval(50); + connect(timer, SIGNAL(timeout()), this, SLOT(sendMouseClick())); + timer->start(); + QTimer::singleShot(10000, &mainWidget, SLOT(close())); // Emergency bail-out + toolButton->showMenu(); QTest::qWait(20); QCOMPARE(spy.count(),2); QCOMPARE(qvariant_cast<QAction *>(spy.at(1).at(0)), one); - delete menu; } void tst_QToolButton::collapseTextOnPriority() @@ -195,20 +207,30 @@ void tst_QToolButton::task230994_iconSize() void tst_QToolButton::task176137_autoRepeatOfAction() { QAction action(0); - QToolButton tb; - tb.setDefaultAction (&action); - tb.show(); + QWidget mainWidget; + mainWidget.setWindowTitle(QStringLiteral("task176137_autoRepeatOfAction")); + mainWidget.resize(200, 200); + mainWidget.move(QGuiApplication::primaryScreen()->availableGeometry().center() - QPoint(100, 100)); + QToolButton *toolButton = new QToolButton(&mainWidget); + toolButton->setDefaultAction (&action); + QLabel *label = new QLabel(QStringLiteral("This test takes a while."), &mainWidget); + label->move(0, 50); + + mainWidget.show(); + QApplication::setActiveWindow(&mainWidget); + QVERIFY(QTest::qWaitForWindowActive(&mainWidget)); + QSignalSpy spy(&action,SIGNAL(triggered())); - QTest::mousePress ( &tb, Qt::LeftButton); - QTest::mouseRelease ( &tb, Qt::LeftButton, 0, QPoint (), 2000); + QTest::mousePress (toolButton, Qt::LeftButton); + QTest::mouseRelease (toolButton, Qt::LeftButton, 0, QPoint (), 2000); QCOMPARE(spy.count(),1); // try again with auto repeat - tb.setAutoRepeat (true); + toolButton->setAutoRepeat (true); QSignalSpy repeatSpy(&action,SIGNAL(triggered())); // new spy - QTest::mousePress ( &tb, Qt::LeftButton); - QTest::mouseRelease ( &tb, Qt::LeftButton, 0, QPoint (), 3000); - qreal expected = (3000 - tb.autoRepeatDelay()) / tb.autoRepeatInterval() + 1; + QTest::mousePress (toolButton, Qt::LeftButton); + QTest::mouseRelease (toolButton, Qt::LeftButton, 0, QPoint (), 3000); + const qreal expected = (3000 - toolButton->autoRepeatDelay()) / toolButton->autoRepeatInterval() + 1; //we check that the difference is small (on some systems timers are not super accurate) qreal diff = (expected - repeatSpy.count()) / expected; QVERIFY2(qAbs(diff) < 0.2, qPrintable( @@ -221,7 +243,17 @@ void tst_QToolButton::task176137_autoRepeatOfAction() void tst_QToolButton::sendMouseClick() { - QTest::mouseClick(w, Qt::LeftButton, 0, QPoint(7,7)); + if (m_menu.isNull()) { + qWarning("m_menu is NULL"); + return; + } + if (!m_menu->isVisible()) + return; + QTest::mouseClick(m_menu.data(), Qt::LeftButton, 0, QPoint(7, 7)); + if (QTimer *timer = qobject_cast<QTimer *>(sender())) { + timer->stop(); + timer->deleteLater(); + } } void tst_QToolButton::qtbug_26956_popupTimerDone() |