diff options
Diffstat (limited to 'tests')
112 files changed, 4485 insertions, 382 deletions
diff --git a/tests/auto/cmake/CMakeLists.txt b/tests/auto/cmake/CMakeLists.txt index 6da0c9bfa6..677e6a6330 100644 --- a/tests/auto/cmake/CMakeLists.txt +++ b/tests/auto/cmake/CMakeLists.txt @@ -51,9 +51,11 @@ if(NOT ${CMAKE_VERSION} VERSION_LESS 2.8.9) # Requires INCLUDE_DIRECTORIES target property in CMake 2.8.8 # and POSITION_INDEPENDENT_CODE target property in 2.8.9 expect_pass(test_use_modules_function) + expect_pass(test_umbrella_config) else() - message("CMake version older than 2.8.9 (Found ${CMAKE_VERSION}). Not running test \"test_use_modules_function\"") + message("CMake version older than 2.8.9 (Found ${CMAKE_VERSION}). Not running test \"test_use_modules_function\" or \"test_umbrella_config\"") endif() + expect_pass(test_wrap_cpp_and_resources) expect_pass(test_dependent_modules) expect_fail(test_add_resource_options) diff --git a/tests/auto/cmake/test_umbrella_config/CMakeLists.txt b/tests/auto/cmake/test_umbrella_config/CMakeLists.txt new file mode 100644 index 0000000000..a8fc2b53ed --- /dev/null +++ b/tests/auto/cmake/test_umbrella_config/CMakeLists.txt @@ -0,0 +1,20 @@ + +cmake_minimum_required(VERSION 2.8) + +project(test_umbrella_config) + +add_subdirectory(components_found) + +if (Qt5_FOUND) + message(SEND_ERROR "Qt5_FOUND variable leaked!") +endif() + +if (Qt5Core_FOUND) + message(SEND_ERROR "Qt5Core_FOUND variable leaked!") +endif() + +if (TARGET Qt5::Core) + message(SEND_ERROR "Qt5::Core target leaked!") +endif() + +add_subdirectory(components_not_found) diff --git a/tests/auto/cmake/test_umbrella_config/components_found/CMakeLists.txt b/tests/auto/cmake/test_umbrella_config/components_found/CMakeLists.txt new file mode 100644 index 0000000000..91cb623deb --- /dev/null +++ b/tests/auto/cmake/test_umbrella_config/components_found/CMakeLists.txt @@ -0,0 +1,18 @@ + +# The module finds its dependencies +find_package(Qt5 + COMPONENTS Core + OPTIONAL_COMPONENTS DoesNotExist +) + +if (NOT Qt5_FOUND) + message(SEND_ERROR "Qt5 umbrella package not found!") +endif() + +if (NOT Qt5Core_FOUND) + message(SEND_ERROR "Qt5Core package not found!") +endif() + +if (Qt5DoesNotExist_FOUND) + message(SEND_ERROR "Non-existent package found!") +endif() diff --git a/tests/auto/cmake/test_umbrella_config/components_not_found/CMakeLists.txt b/tests/auto/cmake/test_umbrella_config/components_not_found/CMakeLists.txt new file mode 100644 index 0000000000..424c3e3445 --- /dev/null +++ b/tests/auto/cmake/test_umbrella_config/components_not_found/CMakeLists.txt @@ -0,0 +1,17 @@ + +# The module finds its dependencies +find_package(Qt5 + COMPONENTS Core DoesNotExist +) + +if (Qt5_FOUND) + message(SEND_ERROR "Qt5 umbrella package found, though it should not be!") +endif() + +if (NOT Qt5Core_FOUND) + message(SEND_ERROR "Qt5Core package not found!") +endif() + +if (Qt5DoesNotExist_FOUND) + message(SEND_ERROR "Non-existent package found!") +endif() diff --git a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp index ccc23851b7..51f07993cd 100644 --- a/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp +++ b/tests/auto/corelib/animation/qsequentialanimationgroup/tst_qsequentialanimationgroup.cpp @@ -44,7 +44,6 @@ #include <QtCore/qsequentialanimationgroup.h> Q_DECLARE_METATYPE(QAbstractAnimation::State) -Q_DECLARE_METATYPE(QAbstractAnimation*) class tst_QSequentialAnimationGroup : public QObject { @@ -84,7 +83,6 @@ private slots: void tst_QSequentialAnimationGroup::initTestCase() { qRegisterMetaType<QAbstractAnimation::State>("QAbstractAnimation::State"); - qRegisterMetaType<QAbstractAnimation*>("QAbstractAnimation*"); } void tst_QSequentialAnimationGroup::construction() diff --git a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp index 6c566e017b..b5f736cfbb 100644 --- a/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp +++ b/tests/auto/corelib/codecs/qtextcodec/tst_qtextcodec.cpp @@ -84,6 +84,7 @@ private slots: void utfHeaders_data(); void utfHeaders(); + void codecForHtml_data(); void codecForHtml(); void codecForUtfText_data(); @@ -1853,23 +1854,81 @@ void tst_QTextCodec::utfHeaders() } } -void tst_QTextCodec::codecForHtml() +void tst_QTextCodec::codecForHtml_data() { - QByteArray html("<html><head></head><body>blah</body></html>"); + QTest::addColumn<QByteArray>("html"); + QTest::addColumn<int>("defaultCodecMib"); + QTest::addColumn<int>("expectedMibEnum"); - QCOMPARE(QTextCodec::codecForHtml(html)->mibEnum(), 4); // latin 1 + int noDefault = -1; + int fallback = 4; // latin 1 + QByteArray html = "<html><head></head><body>blah</body></html>"; + QTest::newRow("no charset, latin 1") << html << noDefault << fallback; - QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 106); // UTF-8 + QTest::newRow("no charset, default UTF-8") << html << 106 << 106; html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=ISO-8859-15\" /></head></html>"; - QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 111); // latin 15 + QTest::newRow("latin 15, default UTF-8") << html << 106 << 111; html = "<html><head><meta content=\"text/html; charset=ISO-8859-15\" http-equiv=\"content-type\" /></head></html>"; - QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 111); // latin 15 + QTest::newRow("latin 15, default UTF-8 (#2)") << html << 106 << 111; + + html = "<!DOCTYPE html><html><head><meta charset=\"utf-8\"><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9,chrome=1\"><title>Test</title></head>"; + QTest::newRow("UTF-8, no default") << html << noDefault << 106; + + html = "<!DOCTYPE html><html><head><meta charset=\"ISO_8859-1:1987\"><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9,chrome=1\"><title>Test</title></head>"; + QTest::newRow("latin 1, no default") << html << noDefault << 4; + + html = "<!DOCTYPE html><html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9,chrome=1\"><meta charset=\"utf-8\"><title>Test</title></head>"; + QTest::newRow("UTF-8, no default (#2)") << html << noDefault << 106; + + html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8/></head></html>"; + QTest::newRow("UTF-8, no quotes") << html << noDefault << 106; + + html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset='UTF-8'/></head></html>"; + QTest::newRow("UTF-8, single quotes") << html << noDefault << 106; + + html = "<!DOCTYPE html><html><head><meta charset=utf-8><title>Test</title></head>"; + QTest::newRow("UTF-8, > terminator") << html << noDefault << 106; + + html = "<!DOCTYPE html><html><head><meta charset= utf-8 ><title>Test</title></head>"; + QTest::newRow("UTF-8, > terminator with spaces") << html << noDefault << 106; + + html = "<!DOCTYPE html><html><head><meta charset= utf/8 ><title>Test</title></head>"; + QTest::newRow("UTF-8, > teminator with early backslash)") << html << noDefault << 106; + // Test invalid charsets. html = "<html><head><meta http-equiv=\"content-type\" content=\"text/html; charset=invalid-foo\" /></head></html>"; - QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(106))->mibEnum(), 106); // UTF-8 - QCOMPARE(QTextCodec::codecForHtml(html)->mibEnum(), 4); // latin 1 + QTest::newRow("invalid charset, no default") << html << noDefault << fallback; + QTest::newRow("invalid charset, default UTF-8") << html << 106 << 106; + + html = "<!DOCTYPE html><html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9,chrome=1\"><meta charset=\""; + html.prepend(QByteArray().fill(' ', 512 - html.size())); + QTest::newRow("invalid charset (large header)") << html << noDefault << fallback; + + html = "<!DOCTYPE html><html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9,chrome=1\"><meta charset=\"utf-8"; + QTest::newRow("invalid charset (no closing double quote)") << html << noDefault << fallback; + + html = "<!DOCTYPE html><html><head><meta http-equiv=\"X-UA-Compatible\" content=\"IE=9,chrome=1\"><meta charset='utf-8"; + QTest::newRow("invalid charset (no closing single quote)") << html << noDefault << fallback; + + html = "<!DOCTYPE html><html><head><meta charset=utf-8 foo=bar><title>Test</title></head>"; + QTest::newRow("invalid (space terminator)") << html << noDefault << fallback; + + html = "<!DOCTYPE html><html><head><meta charset=\" utf' 8 /><title>Test</title></head>"; + QTest::newRow("invalid charset, early terminator (')") << html << noDefault << fallback; +} + +void tst_QTextCodec::codecForHtml() +{ + QFETCH(QByteArray, html); + QFETCH(int, defaultCodecMib); + QFETCH(int, expectedMibEnum); + + if (defaultCodecMib != -1) + QCOMPARE(QTextCodec::codecForHtml(html, QTextCodec::codecForMib(defaultCodecMib))->mibEnum(), expectedMibEnum); + else // Test one parameter version when there is no default codec. + QCOMPARE(QTextCodec::codecForHtml(html)->mibEnum(), expectedMibEnum); } void tst_QTextCodec::codecForUtfText_data() diff --git a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp index a4aca82aa9..ef41ef8801 100644 --- a/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp +++ b/tests/auto/corelib/global/qgetputenv/tst_qgetputenv.cpp @@ -75,6 +75,13 @@ void tst_QGetPutEnv::getSetCheck() QVERIFY(result == "supervalue"); qputenv(varName,QByteArray()); + + // Now test qunsetenv + QVERIFY(qunsetenv(varName)); + QVERIFY(!qEnvironmentVariableIsSet(varName)); + QVERIFY(qEnvironmentVariableIsEmpty(varName)); + result = qgetenv(varName); + QCOMPARE(result, QByteArray()); } QTEST_MAIN(tst_QGetPutEnv) diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index f54af657c0..3696ee264f 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -55,6 +55,8 @@ private slots: void checkptr(); void qstaticassert(); void qConstructorFunction(); + void qCoreAppStartupFunction(); + void qCoreAppStartupFunctionRestart(); void isEnum(); void qAlignOf(); }; @@ -303,6 +305,33 @@ void tst_QGlobal::qConstructorFunction() QCOMPARE(qConstructorFunctionValue, 123); } +static int qStartupFunctionValue; +static void myStartupFunc() +{ + Q_ASSERT(QCoreApplication::instance()); + if (QCoreApplication::instance()) + qStartupFunctionValue += 124; +} + +Q_COREAPP_STARTUP_FUNCTION(myStartupFunc) + +void tst_QGlobal::qCoreAppStartupFunction() +{ + QCOMPARE(qStartupFunctionValue, 0); + int argc = 1; + char *argv[] = { const_cast<char*>("tst_qglobal") }; + QCoreApplication app(argc, argv); + QCOMPARE(qStartupFunctionValue, 124); +} + +void tst_QGlobal::qCoreAppStartupFunctionRestart() +{ + qStartupFunctionValue = 0; + qCoreAppStartupFunction(); + qStartupFunctionValue = 0; + qCoreAppStartupFunction(); +} + struct isEnum_A { int n_; }; @@ -532,5 +561,5 @@ void tst_QGlobal::qAlignOf() #undef TEST_AlignOf_RValueRef #undef TEST_AlignOf_impl -QTEST_MAIN(tst_QGlobal) +QTEST_APPLESS_MAIN(tst_QGlobal) #include "tst_qglobal.moc" diff --git a/tests/auto/corelib/global/qglobalstatic/qglobalstatic.pro b/tests/auto/corelib/global/qglobalstatic/qglobalstatic.pro new file mode 100644 index 0000000000..21cab8f67d --- /dev/null +++ b/tests/auto/corelib/global/qglobalstatic/qglobalstatic.pro @@ -0,0 +1,12 @@ +QT += testlib core-private + +QT -= gui + +TARGET = tst_qglobalstatic +CONFIG += console +CONFIG -= app_bundle +CONFIG += exceptions + +SOURCES += tst_qglobalstatic.cpp +DEFINES += SRCDIR=\\\"$$PWD/\\\" +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp b/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp new file mode 100644 index 0000000000..b9aa70fe80 --- /dev/null +++ b/tests/auto/corelib/global/qglobalstatic/tst_qglobalstatic.cpp @@ -0,0 +1,214 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Thiago Macieira <thiago@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** You may use this file under the terms of the BSD license as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names +** of its contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore/QThread> +#include <QtTest/QtTest> + +class tst_QGlobalStatic : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void beforeInitialization(); + void api(); + void constVolatile(); + void exception(); + void threadStressTest(); + void afterDestruction(); +}; + +Q_GLOBAL_STATIC_WITH_ARGS(const int, constInt, (42)) +Q_GLOBAL_STATIC_WITH_ARGS(volatile int, volatileInt, (-47)) + +void otherFunction() +{ + // never called + constInt(); + volatileInt(); +} + +// do not initialize the following Q_GLOBAL_STATIC +Q_GLOBAL_STATIC(int, checkedBeforeInitialization) +void tst_QGlobalStatic::beforeInitialization() +{ + QVERIFY(!checkedBeforeInitialization.exists()); + QVERIFY(!checkedBeforeInitialization.isDestroyed()); +} + +struct Type { + int i; +}; + +Q_GLOBAL_STATIC(Type, checkedAfterInitialization) +void tst_QGlobalStatic::api() +{ + // check the API + QVERIFY((Type *)checkedAfterInitialization); + QVERIFY(checkedAfterInitialization()); + *checkedAfterInitialization = Type(); + *checkedAfterInitialization() = Type(); + + checkedAfterInitialization()->i = 47; + checkedAfterInitialization->i = 42; + QCOMPARE(checkedAfterInitialization()->i, 42); + checkedAfterInitialization()->i = 47; + QCOMPARE(checkedAfterInitialization->i, 47); + + QVERIFY(checkedAfterInitialization.exists()); + QVERIFY(!checkedAfterInitialization.isDestroyed()); +} + +void tst_QGlobalStatic::constVolatile() +{ + QCOMPARE(*constInt(), 42); + QCOMPARE((int)*volatileInt(), -47); + QCOMPARE(*constInt(), 42); + QCOMPARE((int)*volatileInt(), -47); +} + +struct ThrowingType +{ + static QBasicAtomicInt constructedCount; + static QBasicAtomicInt destructedCount; + ThrowingType(QBasicAtomicInt &throwControl) + { + constructedCount.ref(); + if (throwControl.fetchAndAddRelaxed(-1) != 0) + throw 0; + } + ~ThrowingType() { destructedCount.ref(); } +}; +QBasicAtomicInt ThrowingType::constructedCount = Q_BASIC_ATOMIC_INITIALIZER(0); +QBasicAtomicInt ThrowingType::destructedCount = Q_BASIC_ATOMIC_INITIALIZER(0); + +QBasicAtomicInt exceptionControlVar = Q_BASIC_ATOMIC_INITIALIZER(1); +Q_GLOBAL_STATIC_WITH_ARGS(ThrowingType, exceptionGS, (exceptionControlVar)) +void tst_QGlobalStatic::exception() +{ + if (exceptionControlVar.load() != 1) + QSKIP("This test cannot be run more than once"); + ThrowingType::constructedCount.store(0); + ThrowingType::destructedCount.store(0); + + bool exceptionCaught = false; + try { + exceptionGS(); + } catch (int) { + exceptionCaught = true; + } + QCOMPARE(ThrowingType::constructedCount.load(), 1); + QVERIFY(exceptionCaught); + + exceptionGS(); + QCOMPARE(ThrowingType::constructedCount.load(), 2); +} + +QBasicAtomicInt threadStressTestControlVar = Q_BASIC_ATOMIC_INITIALIZER(5); +Q_GLOBAL_STATIC_WITH_ARGS(ThrowingType, threadStressTestGS, (threadStressTestControlVar)) + + +void tst_QGlobalStatic::threadStressTest() +{ + class ThreadStressTestThread: public QThread + { + public: + QReadWriteLock *lock; + void run() + { + QReadLocker l(lock); + //usleep(qrand() * 200 / RAND_MAX); + // thundering herd + try { + threadStressTestGS(); + } catch (int) { + } + } + }; + + ThrowingType::constructedCount.store(0); + ThrowingType::destructedCount.store(0); + int expectedConstructionCount = threadStressTestControlVar.load() + 1; + if (expectedConstructionCount <= 0) + QSKIP("This test cannot be run more than once"); + + const int numThreads = 200; + ThreadStressTestThread threads[numThreads]; + QReadWriteLock lock; + lock.lockForWrite(); + for (int i = 0; i < numThreads; ++i) { + threads[i].lock = &lock; + threads[i].start(); + } + + // wait for all threads + // release the herd + lock.unlock(); + + for (int i = 0; i < numThreads; ++i) + threads[i].wait(); + + QCOMPARE(ThrowingType::constructedCount.loadAcquire(), expectedConstructionCount); + QCOMPARE(ThrowingType::destructedCount.loadAcquire(), 0); +} + +Q_GLOBAL_STATIC(int, checkedAfterDestruction) +void tst_QGlobalStatic::afterDestruction() +{ + // this test will not produce results now + // it will simply run some code on destruction (after the global statics have been deleted) + // if that fails, this will cause a crash + + // static destruction is LIFO: so we must add our exit-time code before the + // global static is used for the first time + static struct RunAtExit { + ~RunAtExit() { + int *ptr = checkedAfterDestruction(); + if (ptr) + qFatal("Global static is not null as was expected"); + } + } runAtExit; + (void) runAtExit; + + *checkedAfterDestruction = 42; +} + +QTEST_APPLESS_MAIN(tst_QGlobalStatic); + +#include "tst_qglobalstatic.moc" diff --git a/tests/auto/corelib/io/io.pro b/tests/auto/corelib/io/io.pro index 03b42a2cbb..948e9dec5f 100644 --- a/tests/auto/corelib/io/io.pro +++ b/tests/auto/corelib/io/io.pro @@ -20,6 +20,7 @@ SUBDIRS=\ qprocessenvironment \ qresourceengine \ qsettings \ + qsavefile \ qstandardpaths \ qtemporarydir \ qtemporaryfile \ diff --git a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp index 333ccc8e49..f452efc1b3 100644 --- a/tests/auto/corelib/io/qdebug/tst_qdebug.cpp +++ b/tests/auto/corelib/io/qdebug/tst_qdebug.cpp @@ -52,7 +52,8 @@ private slots: void warningWithoutDebug() const; void criticalWithoutDebug() const; void debugWithBool() const; - void debugNoSpaces() const; + void debugSpaceHandling() const; + void stateSaver() const; void veryLongWarningMessage() const; void qDebugQStringRef() const; void qDebugQLatin1String() const; @@ -150,7 +151,36 @@ void tst_QDebug::debugWithBool() const QCOMPARE(QString::fromLatin1(s_function), function); } -void tst_QDebug::debugNoSpaces() const +class MyPoint +{ +public: + MyPoint(int val1, int val2) + : v1(val1), v2(val2) {} + int v1; + int v2; +}; +QDebug operator<< (QDebug s, const MyPoint& point) +{ + const QDebugStateSaver saver(s); + return s.nospace() << "MyPoint(" << point.v1 << ", " << point.v2 << ")"; +} + +class MyLine +{ +public: + MyLine(const MyPoint& point1, const MyPoint& point2) + : p1(point1), p2(point2) {} + MyPoint p1; + MyPoint p2; +}; +QDebug operator<< (QDebug s, const MyLine& line) +{ + const QDebugStateSaver saver(s); + s.nospace() << "MyLine(" << line.p1 << ", " << line.p2 << ")"; + return s; +} + +void tst_QDebug::debugSpaceHandling() const { MessageHandlerSetter mhs(myMessageHandler); { @@ -166,8 +196,26 @@ void tst_QDebug::debugNoSpaces() const d << "key=" << "value"; d.space(); d << 1 << 2; + MyLine line(MyPoint(10, 11), MyPoint (12, 13)); + d << line; + // With the old implementation of MyPoint doing dbg.nospace() << ...; dbg.space() we ended up with + // MyLine(MyPoint(10, 11) , MyPoint(12, 13) ) + } + QCOMPARE(s_msg, QString::fromLatin1(" foo key=value 1 2 MyLine(MyPoint(10, 11), MyPoint(12, 13))")); +} + +void tst_QDebug::stateSaver() const +{ + MessageHandlerSetter mhs(myMessageHandler); + { + QDebug d = qDebug(); + { + QDebugStateSaver saver(d); + d.nospace() << hex << right << qSetFieldWidth(3) << qSetPadChar('0') << 42; + } + d.space() << 42; } - QCOMPARE(s_msg, QString::fromLatin1(" foo key=value 1 2 ")); + QCOMPARE(s_msg, QString::fromLatin1("02a 42 ")); } void tst_QDebug::veryLongWarningMessage() const diff --git a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp index ded77c649f..06f7c35f3a 100644 --- a/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp +++ b/tests/auto/corelib/io/qfileinfo/tst_qfileinfo.cpp @@ -46,6 +46,7 @@ #include <qcoreapplication.h> #include <qlibrary.h> #include <qtemporaryfile.h> +#include <qtemporarydir.h> #include <qdir.h> #include <qfileinfo.h> #ifdef Q_OS_UNIX @@ -57,7 +58,6 @@ #include <pwd.h> #endif #ifdef Q_OS_WIN -#define _WIN32_WINNT 0x500 #include <qt_windows.h> #include <qlibrary.h> #if !defined(Q_OS_WINCE) @@ -80,7 +80,11 @@ class tst_QFileInfo : public QObject { Q_OBJECT +public: + tst_QFileInfo() : m_currentDir(QDir::currentPath()) {} + private slots: + void initTestCase(); void cleanupTestCase(); void getSetCheck(); @@ -190,32 +194,27 @@ private slots: void invalidState(); void nonExistingFileDates(); + +private: + const QString m_currentDir; + QString m_sourceFile; + QString m_resourcesDir; + QTemporaryDir m_dir; }; -void tst_QFileInfo::cleanupTestCase() +void tst_QFileInfo::initTestCase() { - QFile::remove("brokenlink.lnk"); - QFile::remove("link.lnk"); - QFile::remove("file1"); - QFile::remove("dummyfile"); - QFile::remove("simplefile.txt"); - QFile::remove("longFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileNamelongFileName.txt"); - QFile::remove("tempfile.txt"); + m_sourceFile = QFINDTESTDATA("tst_qfileinfo.cpp"); + QVERIFY(!m_sourceFile.isEmpty()); + m_resourcesDir = QFINDTESTDATA("resources"); + QVERIFY(!m_resourcesDir.isEmpty()); + QVERIFY(m_dir.isValid()); + QVERIFY(QDir::setCurrent(m_dir.path())); +} -#if defined(Q_OS_UNIX) - QDir().rmdir("./.hidden-directory"); - QFile::remove("link_to_tst_qfileinfo"); -#endif -#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) - QDir().rmdir("./hidden-directory"); - QDir().rmdir("abs_symlink"); - QDir().rmdir("rel_symlink"); - QDir().rmdir("junction_pwd"); - QDir().rmdir("junction_root"); - QDir().rmdir("mountpoint"); - QFile::remove("abs_symlink.cpp"); - QFile::remove("rel_symlink.cpp"); -#endif +void tst_QFileInfo::cleanupTestCase() +{ + QDir::setCurrent(m_currentDir); // Release temporary directory so that it can be deleted on Windows } // Testing get/set functions @@ -237,10 +236,9 @@ static QFileInfoPrivate* getPrivate(QFileInfo &info) void tst_QFileInfo::copy() { - QTemporaryFile *t; - t = new QTemporaryFile; - t->open(); - QFileInfo info(t->fileName()); + QTemporaryFile t; + t.open(); + QFileInfo info(t.fileName()); QVERIFY(info.exists()); //copy constructor @@ -287,7 +285,7 @@ void tst_QFileInfo::isFile_data() QTest::addColumn<bool>("expected"); QTest::newRow("data0") << QDir::currentPath() << false; - QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << true; + QTest::newRow("data1") << m_sourceFile << true; QTest::newRow("data2") << ":/tst_qfileinfo/resources/" << false; QTest::newRow("data3") << ":/tst_qfileinfo/resources/file1" << true; QTest::newRow("data4") << ":/tst_qfileinfo/resources/afilethatshouldnotexist" << false; @@ -320,13 +318,13 @@ void tst_QFileInfo::isDir_data() QTest::addColumn<bool>("expected"); QTest::newRow("data0") << QDir::currentPath() << true; - QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << false; + QTest::newRow("data1") << m_sourceFile << false; QTest::newRow("data2") << ":/tst_qfileinfo/resources/" << true; QTest::newRow("data3") << ":/tst_qfileinfo/resources/file1" << false; QTest::newRow("data4") << ":/tst_qfileinfo/resources/afilethatshouldnotexist" << false; - QTest::newRow("simple dir") << QFINDTESTDATA("resources") << true; - QTest::newRow("simple dir with slash") << QFINDTESTDATA("resources/") << true; + QTest::newRow("simple dir") << m_resourcesDir << true; + QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << true; QTest::newRow("broken link") << "brokenlink.lnk" << false; @@ -366,8 +364,8 @@ void tst_QFileInfo::isRoot_data() QTest::newRow("data4") << ":/tst_qfileinfo/resources/" << false; QTest::newRow("data5") << ":/" << true; - QTest::newRow("simple dir") << QFINDTESTDATA("resources") << false; - QTest::newRow("simple dir with slash") << QFINDTESTDATA("resources/") << false; + QTest::newRow("simple dir") << m_resourcesDir << false; + QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << false; #if (defined(Q_OS_WIN) && !defined(Q_OS_WINCE)) QTest::newRow("drive 1") << "c:" << false; QTest::newRow("drive 2") << "c:/" << true; @@ -398,21 +396,21 @@ void tst_QFileInfo::exists_data() QTest::addColumn<bool>("expected"); QTest::newRow("data0") << QDir::currentPath() << true; - QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << true; + QTest::newRow("data1") << m_sourceFile << true; QTest::newRow("data2") << "/I/do_not_expect_this_path_to_exist/" << false; QTest::newRow("data3") << ":/tst_qfileinfo/resources/" << true; QTest::newRow("data4") << ":/tst_qfileinfo/resources/file1" << true; QTest::newRow("data5") << ":/I/do_not_expect_this_path_to_exist/" << false; - QTest::newRow("data6") << (QFINDTESTDATA("resources/") + "*") << false; - QTest::newRow("data7") << (QFINDTESTDATA("resources/") + "*.foo") << false; - QTest::newRow("data8") << (QFINDTESTDATA("resources/") + "*.ext1") << false; - QTest::newRow("data9") << (QFINDTESTDATA("resources/") + "file?.ext1") << false; + QTest::newRow("data6") << (m_resourcesDir + "/*") << false; + QTest::newRow("data7") << (m_resourcesDir + "/*.foo") << false; + QTest::newRow("data8") << (m_resourcesDir + "/*.ext1") << false; + QTest::newRow("data9") << (m_resourcesDir + "/file?.ext1") << false; QTest::newRow("data10") << "." << true; QTest::newRow("data11") << ". " << false; QTest::newRow("empty") << "" << false; - QTest::newRow("simple dir") << QFINDTESTDATA("resources") << true; - QTest::newRow("simple dir with slash") << QFINDTESTDATA("resources/") << true; + QTest::newRow("simple dir") << m_resourcesDir << true; + QTest::newRow("simple dir with slash") << (m_resourcesDir + QLatin1Char('/')) << true; #if defined(Q_OS_WIN) && !defined(Q_OS_WINCE) QTest::newRow("unc 1") << "//" + QtNetworkSettings::winServerName() << true; @@ -561,7 +559,7 @@ void tst_QFileInfo::canonicalFilePath() // test symlinks QFile::remove("link.lnk"); { - QFile file(QFINDTESTDATA("tst_qfileinfo.cpp")); + QFile file(m_sourceFile); if (file.link("link.lnk")) { QFileInfo info1(file); QFileInfo info2("link.lnk"); @@ -587,7 +585,7 @@ void tst_QFileInfo::canonicalFilePath() QCOMPARE(info1.canonicalFilePath(), info2.canonicalFilePath()); QFileInfo info3(link + QDir::separator() + "link.lnk"); - QFileInfo info4(QFINDTESTDATA("tst_qfileinfo.cpp")); + QFileInfo info4(m_sourceFile); QVERIFY(!info3.canonicalFilePath().isEmpty()); QCOMPARE(info4.canonicalFilePath(), info3.canonicalFilePath()); @@ -621,20 +619,21 @@ void tst_QFileInfo::canonicalFilePath() // CreateSymbolicLink can return TRUE & still fail to create the link, // the error code in that case is ERROR_PRIVILEGE_NOT_HELD (1314) SetLastError(0); - BOOL ret = ptrCreateSymbolicLink((wchar_t*)QString("res").utf16(), (wchar_t*)QString("resources").utf16(), 1); + const QString linkTarget = QStringLiteral("res"); + BOOL ret = ptrCreateSymbolicLink((wchar_t*)linkTarget.utf16(), (wchar_t*)m_resourcesDir.utf16(), 1); DWORD dwErr = GetLastError(); if (!ret) QSKIP("Symbolic links aren't supported by FS"); QString currentPath = QDir::currentPath(); - bool is_res_Current = QDir::setCurrent("res"); + bool is_res_Current = QDir::setCurrent(linkTarget); if (!is_res_Current && dwErr == 1314) QSKIP("Not enough privilages to create Symbolic links"); QCOMPARE(is_res_Current, true); + const QString actualCanonicalPath = QFileInfo("file1").canonicalFilePath(); + QVERIFY(QDir::setCurrent(currentPath)); + QCOMPARE(actualCanonicalPath, m_resourcesDir + QStringLiteral("/file1")); - QCOMPARE(QFileInfo("file1").canonicalFilePath(), currentPath + "/resources/file1"); - - QCOMPARE(QDir::setCurrent(currentPath), true); - QDir::current().rmdir("res"); + QDir::current().rmdir(linkTarget); } #endif } @@ -855,7 +854,7 @@ void tst_QFileInfo::permission_data() QTest::addColumn<bool>("expected"); QTest::newRow("data0") << QCoreApplication::instance()->applicationFilePath() << int(QFile::ExeUser) << true; - QTest::newRow("data1") << QFINDTESTDATA("tst_qfileinfo.cpp") << int(QFile::ReadUser) << true; + QTest::newRow("data1") << m_sourceFile << int(QFile::ReadUser) << true; QTest::newRow("resource1") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ReadUser) << true; QTest::newRow("resource2") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::WriteUser) << false; QTest::newRow("resource3") << ":/tst_qfileinfo/resources/file1.ext1" << int(QFile::ExeUser) << false; @@ -921,13 +920,15 @@ void tst_QFileInfo::compare_data() if (QSysInfo::MacintoshVersion >= QSysInfo::MV_10_6) caseSensitiveOnMac = false; #endif + QString caseChangedSource = m_sourceFile; + caseChangedSource.replace("info", "Info"); QTest::newRow("data0") - << QFINDTESTDATA("tst_qfileinfo.cpp") - << QFINDTESTDATA("tst_qfileinfo.cpp") + << m_sourceFile + << m_sourceFile << true; QTest::newRow("data1") - << QFINDTESTDATA("tst_qfileinfo.cpp") + << m_sourceFile << QString::fromLatin1("/tst_qfileinfo.cpp") << false; QTest::newRow("data2") @@ -935,8 +936,8 @@ void tst_QFileInfo::compare_data() << QDir::currentPath() + QString::fromLatin1("/tst_qfileinfo.cpp") << true; QTest::newRow("casesense1") - << QFINDTESTDATA("tst_qfileinfo.cpp").replace("info", "Info") - << QFINDTESTDATA("tst_qfileinfo.cpp") + << caseChangedSource + << m_sourceFile #if defined(Q_OS_WIN) << true; #elif defined(Q_OS_MAC) @@ -1140,7 +1141,7 @@ void tst_QFileInfo::isSymLink_data() QFile::remove("brokenlink.lnk"); QFile::remove("dummyfile"); - QFile file1(QFINDTESTDATA("tst_qfileinfo.cpp")); + QFile file1(m_sourceFile); QVERIFY(file1.link("link.lnk")); QFile file2("dummyfile"); @@ -1152,8 +1153,8 @@ void tst_QFileInfo::isSymLink_data() QTest::addColumn<bool>("isSymLink"); QTest::addColumn<QString>("linkTarget"); - QTest::newRow("existent file") << QFINDTESTDATA("tst_qfileinfo.cpp") << false << ""; - QTest::newRow("link") << "link.lnk" << true << QFileInfo(QFINDTESTDATA("tst_qfileinfo.cpp")).absoluteFilePath(); + QTest::newRow("existent file") << m_sourceFile << false << ""; + QTest::newRow("link") << "link.lnk" << true << QFileInfo(m_sourceFile).absoluteFilePath(); QTest::newRow("broken link") << "brokenlink.lnk" << true << QFileInfo("dummyfile").absoluteFilePath(); } @@ -1390,7 +1391,7 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks_data() } { //File symlinks - QFileInfo target(QFINDTESTDATA("tst_qfileinfo.cpp")); + QFileInfo target(m_sourceFile); QString absTarget = QDir::toNativeSeparators(target.absoluteFilePath()); QString absSymlink = QDir::toNativeSeparators(pwd.absolutePath()).append("\\abs_symlink.cpp"); QString relTarget = QDir::toNativeSeparators(pwd.relativeFilePath(target.absoluteFilePath())); @@ -1447,10 +1448,22 @@ void tst_QFileInfo::ntfsJunctionPointsAndSymlinks() QFETCH(QString, canonicalFilePath); QFileInfo fi(path); - QCOMPARE(fi.isSymLink(), isSymLink); + const bool actualIsSymLink = fi.isSymLink(); + const QString actualSymLinkTarget = isSymLink ? fi.symLinkTarget() : QString(); + const QString actualCanonicalFilePath = isSymLink ? fi.canonicalFilePath() : QString(); + // Ensure that junctions, mountpoints are removed. If this fails, do not remove + // temporary directory to prevent it from trashing the system. + if (fi.isDir()) { + if (!QDir().rmdir(fi.fileName())) { + qWarning("Unable to remove NTFS junction '%s'', keeping '%s'.", + qPrintable(fi.fileName()), qPrintable(QDir::toNativeSeparators(m_dir.path()))); + m_dir.setAutoRemove(false); + } + } + QCOMPARE(actualIsSymLink, isSymLink); if (isSymLink) { - QCOMPARE(fi.symLinkTarget(), linkTarget); - QCOMPARE(fi.canonicalFilePath(), canonicalFilePath); + QCOMPARE(actualSymLinkTarget, linkTarget); + QCOMPARE(actualCanonicalFilePath, canonicalFilePath); } } diff --git a/tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro b/tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro index 271c7ead13..45b498c32a 100644 --- a/tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro +++ b/tests/auto/corelib/io/qprocess/testForwarding/testForwarding.pro @@ -2,3 +2,4 @@ SOURCES = main.cpp CONFIG -= app_bundle CONFIG += console DESTDIR = ./ +QT = core diff --git a/tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro b/tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro index f7c57abc37..f7bb0985a3 100644 --- a/tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro +++ b/tests/auto/corelib/io/qprocess/testProcessNormal/testProcessNormal.pro @@ -4,3 +4,4 @@ CONFIG -= qt app_bundle DESTDIR = ./ DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +QT = core diff --git a/tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro b/tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro index 3940ddbf98..2de4534896 100644 --- a/tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro +++ b/tests/auto/corelib/io/qprocess/testProcessOutput/testProcessOutput.pro @@ -3,3 +3,4 @@ CONFIG -= qt app_bundle CONFIG += console DESTDIR = ./ DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +QT = core diff --git a/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro b/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro index 43db95e675..8b16f65e34 100644 --- a/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro +++ b/tests/auto/corelib/io/qprocess/testProcessSpacesArgs/twospaces.pro @@ -6,3 +6,4 @@ OBJECTS_DIR = $${OBJECTS_DIR}-twospaces TARGET = "two space s" DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +QT = core diff --git a/tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro b/tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro index 86d26c2c4a..d425d5569e 100644 --- a/tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro +++ b/tests/auto/corelib/io/qprocess/testSetWorkingDirectory/testSetWorkingDirectory.pro @@ -3,3 +3,4 @@ CONFIG += console CONFIG -= app_bundle DESTDIR = ./ DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +QT = core diff --git a/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro b/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro index c5fb286d0c..7f3b8ade3e 100644 --- a/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro +++ b/tests/auto/corelib/io/qprocess/testSoftExit/testSoftExit.pro @@ -10,3 +10,4 @@ CONFIG -= qt app_bundle CONFIG += console DESTDIR = ./ DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +QT = core diff --git a/tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro b/tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro index d0848e3303..b7213ae507 100644 --- a/tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro +++ b/tests/auto/corelib/io/qprocess/testSpaceInName/testSpaceInName.pro @@ -7,3 +7,4 @@ mac { CONFIG -= app_bundle } DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 +QT = core diff --git a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp index 7965d1d431..11824f4ab6 100644 --- a/tests/auto/corelib/io/qprocess/tst_qprocess.cpp +++ b/tests/auto/corelib/io/qprocess/tst_qprocess.cpp @@ -1256,7 +1256,6 @@ void tst_QProcess::waitForBytesWrittenInABytesWrittenSlot() process->start("testProcessEcho/testProcessEcho"); QVERIFY(process->waitForStarted(5000)); - qRegisterMetaType<qint64>("qint64"); QSignalSpy spy(process, SIGNAL(bytesWritten(qint64))); QVERIFY(spy.isValid()); process->write("f"); diff --git a/tests/auto/corelib/io/qsavefile/qsavefile.pro b/tests/auto/corelib/io/qsavefile/qsavefile.pro new file mode 100644 index 0000000000..36db000fa7 --- /dev/null +++ b/tests/auto/corelib/io/qsavefile/qsavefile.pro @@ -0,0 +1,5 @@ +CONFIG += testcase parallel_test +TARGET = tst_qsavefile +QT = core testlib +SOURCES = tst_qsavefile.cpp +TESTDATA += tst_qsavefile.cpp diff --git a/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp new file mode 100644 index 0000000000..5ef4b11e8a --- /dev/null +++ b/tests/auto/corelib/io/qsavefile/tst_qsavefile.cpp @@ -0,0 +1,272 @@ +/**************************************************************************** +** +** Copyright (C) 2012 David Faure <faure@kde.org> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtCore module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <qcoreapplication.h> +#include <qstring.h> +#include <qtemporaryfile.h> +#include <qfile.h> +#include <qdir.h> +#include <qset.h> + +#if defined(Q_OS_UNIX) +# include <unistd.h> // for geteuid +# include <sys/types.h> +#endif + +#if defined(Q_OS_WIN) +# include <windows.h> +#endif + +class tst_QSaveFile : public QObject +{ + Q_OBJECT +public slots: + +private slots: + void transactionalWrite(); + void textStreamManualFlush(); + void textStreamAutoFlush(); + void saveTwice(); + void transactionalWriteNoPermissionsOnDir(); + void transactionalWriteNoPermissionsOnFile(); + void transactionalWriteCanceled(); + void transactionalWriteErrorRenaming(); +}; + +void tst_QSaveFile::transactionalWrite() +{ + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QFile::remove(targetFile); + QSaveFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + QVERIFY(file.isOpen()); + QCOMPARE(file.fileName(), targetFile); + QVERIFY(!QFile::exists(targetFile)); + + QCOMPARE(file.write("Hello"), Q_INT64_C(5)); + QCOMPARE(file.error(), QFile::NoError); + QVERIFY(!QFile::exists(targetFile)); + + QVERIFY(file.commit()); + QVERIFY(QFile::exists(targetFile)); + QCOMPARE(file.fileName(), targetFile); + + QFile reader(targetFile); + QVERIFY(reader.open(QIODevice::ReadOnly)); + QCOMPARE(QString::fromLatin1(reader.readAll()), QString::fromLatin1("Hello")); +} + +void tst_QSaveFile::saveTwice() +{ + // Check that we can reuse a QSaveFile object + // (and test the case of an existing target file) + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QSaveFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + QCOMPARE(file.write("Hello"), Q_INT64_C(5)); + QVERIFY2(file.commit(), qPrintable(file.errorString())); + + QVERIFY(file.open(QIODevice::WriteOnly)); + QCOMPARE(file.write("World"), Q_INT64_C(5)); + QVERIFY2(file.commit(), qPrintable(file.errorString())); + + QFile reader(targetFile); + QVERIFY(reader.open(QIODevice::ReadOnly)); + QCOMPARE(QString::fromLatin1(reader.readAll()), QString::fromLatin1("World")); +} + +void tst_QSaveFile::textStreamManualFlush() +{ + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QSaveFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + + QTextStream ts(&file); + ts << "Manual flush"; + ts.flush(); + QCOMPARE(file.error(), QFile::NoError); + QVERIFY(!QFile::exists(targetFile)); + + QVERIFY(file.commit()); + QFile reader(targetFile); + QVERIFY(reader.open(QIODevice::ReadOnly)); + QCOMPARE(QString::fromLatin1(reader.readAll().constData()), QString::fromLatin1("Manual flush")); + QFile::remove(targetFile); +} + +void tst_QSaveFile::textStreamAutoFlush() +{ + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QSaveFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + + QTextStream ts(&file); + ts << "Auto-flush."; + // no flush + QVERIFY(file.commit()); // QIODevice::close will emit aboutToClose, which will flush the stream + QFile reader(targetFile); + QVERIFY(reader.open(QIODevice::ReadOnly)); + QCOMPARE(QString::fromLatin1(reader.readAll().constData()), QString::fromLatin1("Auto-flush.")); + QFile::remove(targetFile); +} + +void tst_QSaveFile::transactionalWriteNoPermissionsOnDir() +{ +#ifdef Q_OS_UNIX + if (::geteuid() == 0) + QSKIP("not valid running this test as root"); + + // You can write into /dev/zero, but you can't create a /dev/zero.XXXXXX temp file. + QSaveFile file("/dev/zero"); + if (!QDir("/dev").exists()) + QSKIP("/dev doesn't exist on this system"); + + QVERIFY(!file.open(QIODevice::WriteOnly)); + QCOMPARE((int)file.error(), (int)QFile::OpenError); + QVERIFY(!file.commit()); +#endif +} + +void tst_QSaveFile::transactionalWriteNoPermissionsOnFile() +{ + // Setup an existing but readonly file + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + QCOMPARE(file.write("Hello"), Q_INT64_C(5)); + file.close(); + file.setPermissions(QFile::ReadOwner); + QVERIFY(!file.open(QIODevice::WriteOnly)); + + // Try saving into it + { + QSaveFile saveFile(targetFile); + QVERIFY(!saveFile.open(QIODevice::WriteOnly)); // just like QFile + } + QVERIFY(file.exists()); +} + +void tst_QSaveFile::transactionalWriteCanceled() +{ + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QFile::remove(targetFile); + QSaveFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + + QTextStream ts(&file); + ts << "This writing operation will soon be canceled.\n"; + ts.flush(); + QCOMPARE(file.error(), QFile::NoError); + QVERIFY(!QFile::exists(targetFile)); + + // We change our mind, let's abort writing + file.cancelWriting(); + + QVERIFY(!file.commit()); + + QVERIFY(!QFile::exists(targetFile)); // temp file was discarded + QCOMPARE(file.fileName(), targetFile); +} + +void tst_QSaveFile::transactionalWriteErrorRenaming() +{ + QTemporaryDir dir; + const QString targetFile = dir.path() + QString::fromLatin1("/outfile"); + QSaveFile file(targetFile); + QVERIFY(file.open(QIODevice::WriteOnly)); + QCOMPARE(file.write("Hello"), qint64(5)); + QVERIFY(!QFile::exists(targetFile)); + + // Restore permissions so that the QTemporaryDir cleanup can happen + class PermissionRestorer + { + public: + PermissionRestorer(const QString& path) + : m_path(path) + {} + + ~PermissionRestorer() + { + QFile file(m_path); +#ifdef Q_OS_UNIX + file.setPermissions(QFile::Permissions(QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner)); +#else + file.setPermissions(QFile::WriteOwner); + file.remove(); +#endif + } + + private: + QString m_path; + }; + +#ifdef Q_OS_UNIX + // Make rename() fail for lack of permissions in the directory + QFile dirAsFile(dir.path()); // yay, I have to use QFile to change a dir's permissions... + QVERIFY(dirAsFile.setPermissions(QFile::Permissions(0))); // no permissions + PermissionRestorer permissionRestorer(dir.path()); +#else + // Windows: Make rename() fail for lack of permissions on an existing target file + QFile existingTargetFile(targetFile); + QVERIFY(existingTargetFile.open(QIODevice::WriteOnly)); + QCOMPARE(file.write("Target"), qint64(6)); + existingTargetFile.close(); + QVERIFY(existingTargetFile.setPermissions(QFile::ReadOwner)); + PermissionRestorer permissionRestorer(targetFile); +#endif + + // The saving should fail. + QVERIFY(!file.commit()); +#ifdef Q_OS_UNIX + QVERIFY(!QFile::exists(targetFile)); // renaming failed +#endif + QCOMPARE(file.error(), QFile::RenameError); +} + +QTEST_MAIN(tst_QSaveFile) +#include "tst_qsavefile.moc" diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp index 1f59336fc6..cdd631b437 100644 --- a/tests/auto/corelib/io/qurl/tst_qurl.cpp +++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp @@ -79,6 +79,8 @@ private slots: void toString(); void toString_constructed_data(); void toString_constructed(); + void toAndFromStringList_data(); + void toAndFromStringList(); void isParentOf_data(); void isParentOf(); void toLocalFile_data(); @@ -948,6 +950,25 @@ void tst_QUrl::toString() QCOMPARE(url.toString(QUrl::FormattingOptions(options)), string); } +void tst_QUrl::toAndFromStringList_data() +{ + QTest::addColumn<QStringList>("strings"); + + QTest::newRow("empty") << QStringList(); + QTest::newRow("local") << (QStringList() << "file:///tmp" << "file:///"); + QTest::newRow("remote") << (QStringList() << "http://qt-project.org"); +} + +void tst_QUrl::toAndFromStringList() +{ + QFETCH(QStringList, strings); + + const QList<QUrl> urls = QUrl::fromStringList(strings); + QCOMPARE(urls.count(), strings.count()); + const QStringList converted = QUrl::toStringList(urls); + QCOMPARE(converted, strings); +} + //### more tests ... what do we expect ... void tst_QUrl::isParentOf_data() { @@ -2796,6 +2817,12 @@ void tst_QUrl::effectiveTLDs_data() QTest::newRow("yes6") << QUrl::fromEncoded("http://www.com.com.cn") << ".com.cn"; QTest::newRow("yes7") << QUrl::fromEncoded("http://www.test.org.ws") << ".org.ws"; QTest::newRow("yes9") << QUrl::fromEncoded("http://www.com.co.uk.wallonie.museum") << ".wallonie.museum"; + QTest::newRow("yes10") << QUrl::fromEncoded("http://www.com.evje-og-hornnes.no") << ".evje-og-hornnes.no"; + QTest::newRow("yes11") << QUrl::fromEncoded("http://www.bla.kamijima.ehime.jp") << ".kamijima.ehime.jp"; + QTest::newRow("yes12") << QUrl::fromEncoded("http://www.bla.kakuda.miyagi.jp") << ".kakuda.miyagi.jp"; + QTest::newRow("yes13") << QUrl::fromEncoded("http://mypage.betainabox.com") << ".betainabox.com"; + QTest::newRow("yes14") << QUrl::fromEncoded("http://mypage.rhcloud.com") << ".rhcloud.com"; + QTest::newRow("yes15") << QUrl::fromEncoded("http://mypage.int.az") << ".int.az"; } void tst_QUrl::effectiveTLDs() diff --git a/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp b/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp index 6e2eeced05..bad77b1e06 100644 --- a/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp +++ b/tests/auto/corelib/io/qwinoverlappedionotifier/tst_qwinoverlappedionotifier.cpp @@ -251,21 +251,24 @@ void tst_QWinOverlappedIoNotifier::multipleOperations() // start async read on client QByteArray clientReadBuffer(377, Qt::Uninitialized); - OVERLAPPED clientReadOverlapped = {0}; + OVERLAPPED clientReadOverlapped; + ZeroMemory(&clientReadOverlapped, sizeof(clientReadOverlapped)); BOOL readSuccess = ReadFile(hClient, clientReadBuffer.data(), clientReadBuffer.size(), NULL, &clientReadOverlapped); QVERIFY(readSuccess || GetLastError() == ERROR_IO_PENDING); // start async write client -> server QByteArray clientDataToWrite(233, 'B'); - OVERLAPPED clientWriteOverlapped = {0}; + OVERLAPPED clientWriteOverlapped; + ZeroMemory(&clientWriteOverlapped, sizeof(clientWriteOverlapped)); BOOL writeSuccess = WriteFile(hClient, clientDataToWrite.data(), clientDataToWrite.size(), NULL, &clientWriteOverlapped); QVERIFY(writeSuccess || GetLastError() == ERROR_IO_PENDING); // start async write server -> client QByteArray serverDataToWrite(144, 'A'); - OVERLAPPED serverOverlapped = {0}; + OVERLAPPED serverOverlapped; + ZeroMemory(&serverOverlapped, sizeof(serverOverlapped)); writeSuccess = WriteFile(hServer, serverDataToWrite.data(), serverDataToWrite.size(), NULL, &serverOverlapped); QVERIFY(writeSuccess || GetLastError() == ERROR_IO_PENDING); @@ -284,9 +287,9 @@ void tst_QWinOverlappedIoNotifier::multipleOperations() QTRY_COMPARE(sink.notifications.count(), 2); foreach (const NotifierSink::IOResult &r, sink.notifications) { QCOMPARE(r.errorCode, DWORD(ERROR_SUCCESS)); - if (r.bytes == serverDataToWrite.count()) + if (r.bytes == DWORD(serverDataToWrite.count())) QCOMPARE(r.overlapped, &clientReadOverlapped); - else if (r.bytes == clientDataToWrite.count()) + else if (r.bytes == DWORD(clientDataToWrite.count())) QCOMPARE(r.overlapped, &clientWriteOverlapped); else QVERIFY2(false, "Unexpected number of bytes received."); diff --git a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp index 20bd4fa433..d2fb56ce02 100644 --- a/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractitemmodel/tst_qabstractitemmodel.cpp @@ -467,9 +467,6 @@ typedef QPair<int, int> Position; typedef QVector<QPair<int, int> > Selection; typedef QVector<QVector<QString> > StringTable; typedef QVector<QString> StringTableRow; -Q_DECLARE_METATYPE(Position) -Q_DECLARE_METATYPE(Selection) -Q_DECLARE_METATYPE(StringTable) static StringTableRow qStringTableRow(const QString &s1, const QString &s2, const QString &s3) { @@ -1922,8 +1919,6 @@ public: void tst_QAbstractItemModel::testDataChanged() { - qRegisterMetaType<QVector<int> >(); - CustomRoleModel model; QSignalSpy withRoles(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>))); diff --git a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp index c8cbacf76e..c385a02b9c 100644 --- a/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qabstractproxymodel/tst_qabstractproxymodel.cpp @@ -281,8 +281,6 @@ void tst_QAbstractProxyModel::revert() // public void setSourceModel(QAbstractItemModel* sourceModel) void tst_QAbstractProxyModel::setSourceModel() { - qRegisterMetaType<QAbstractItemModel*>(); - SubQAbstractProxyModel model; QCOMPARE(model.property("sourceModel"), QVariant::fromValue<QAbstractItemModel*>(0)); diff --git a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp index 02a4824c4b..4578bcdab6 100644 --- a/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ b/tests/auto/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp @@ -54,6 +54,8 @@ typedef QList<int> IntList; typedef QPair<int, int> IntPair; typedef QList<IntPair> IntPairList; +Q_DECLARE_METATYPE(QList<QPersistentModelIndex>) + class tst_QSortFilterProxyModel : public QObject { Q_OBJECT @@ -134,6 +136,7 @@ private slots: void testMultipleProxiesWithSelection(); void mapSelectionFromSource(); + void testResetInternalData(); void filteredColumns(); void headerDataChanged(); @@ -143,6 +146,8 @@ private slots: void hierarchyFilterInvalidation(); void simpleFilterInvalidation(); + void chainedProxyModelRoleNames(); + protected: void buildHierarchy(const QStringList &data, QAbstractItemModel *model); void checkHierarchy(const QStringList &data, const QAbstractItemModel *model); @@ -174,9 +179,7 @@ tst_QSortFilterProxyModel::tst_QSortFilterProxyModel() void tst_QSortFilterProxyModel::initTestCase() { - qRegisterMetaType<IntList>("IntList"); - qRegisterMetaType<IntPair>("IntPair"); - qRegisterMetaType<IntPairList>("IntPairList"); + qRegisterMetaType<QList<QPersistentModelIndex> >(); m_model = new QStandardItemModel(0, 1); m_proxy = new QSortFilterProxyModel(); m_proxy->setSourceModel(m_model); @@ -3242,7 +3245,142 @@ void tst_QSortFilterProxyModel::resetInvalidate() QCOMPARE(ok, works); } -Q_DECLARE_METATYPE(QList<QPersistentModelIndex>) +/** + * A proxy which changes the background color for items ending in 'y' or 'r' + */ +class CustomDataProxy : public QSortFilterProxyModel +{ + Q_OBJECT + +public: + CustomDataProxy(QObject *parent = 0) + : QSortFilterProxyModel(parent) + { + setDynamicSortFilter(true); + } + + void setSourceModel(QAbstractItemModel *sourceModel) + { + // It would be possible to use only the modelReset signal of the source model to clear + // the data in *this, however, this requires that the slot is connected + // before QSortFilterProxyModel::setSourceModel is called, and even then depends + // on the order of invocation of slots being the same as the order of connection. + // ie, not reliable. +// connect(sourceModel, SIGNAL(modelReset()), SLOT(resetInternalData())); + QSortFilterProxyModel::setSourceModel(sourceModel); + // Making the connect after the setSourceModel call clears the data too late. +// connect(sourceModel, SIGNAL(modelReset()), SLOT(resetInternalData())); + + // This could be done in data(), but the point is to need to cache something in the proxy + // which needs to be cleared on reset. + for (int i = 0; i < sourceModel->rowCount(); ++i) + { + if (sourceModel->index(i, 0).data().toString().endsWith(QLatin1Char('y'))) + { + m_backgroundColours.insert(i, Qt::blue); + } else if (sourceModel->index(i, 0).data().toString().endsWith(QLatin1Char('r'))) + { + m_backgroundColours.insert(i, Qt::red); + } + } + } + + QVariant data(const QModelIndex &index, int role) const + { + if (role != Qt::BackgroundRole) + return QSortFilterProxyModel::data(index, role); + return m_backgroundColours.value(index.row()); + } + +private slots: + void resetInternalData() + { + m_backgroundColours.clear(); + } + +private: + QHash<int, QColor> m_backgroundColours; +}; + +class ModelObserver : public QObject +{ + Q_OBJECT +public: + ModelObserver(QAbstractItemModel *model, QObject *parent = 0) + : QObject(parent), m_model(model) + { + connect(m_model, SIGNAL(modelAboutToBeReset()), SLOT(modelAboutToBeReset())); + connect(m_model, SIGNAL(modelReset()), SLOT(modelReset())); + } + +public slots: + void modelAboutToBeReset() + { + int reds = 0, blues = 0; + for (int i = 0; i < m_model->rowCount(); ++i) + { + QColor color = m_model->index(i, 0).data(Qt::BackgroundRole).value<QColor>(); + if (color == Qt::blue) + ++blues; + if (color == Qt::red) + ++reds; + } + QCOMPARE(blues, 11); + QCOMPARE(reds, 4); + } + + void modelReset() + { + int reds = 0, blues = 0; + for (int i = 0; i < m_model->rowCount(); ++i) + { + QColor color = m_model->index(i, 0).data(Qt::BackgroundRole).value<QColor>(); + if (color == Qt::blue) + ++blues; + if (color == Qt::red) + ++reds; + } + QCOMPARE(reds, 0); + QCOMPARE(blues, 0); + } + +private: + QAbstractItemModel * const m_model; + +}; + +void tst_QSortFilterProxyModel::testResetInternalData() +{ + + QStringListModel model(QStringList() << "Monday" + << "Tuesday" + << "Wednesday" + << "Thursday" + << "Friday" + << "January" + << "February" + << "March" + << "April" + << "May" + << "Saturday" + << "June" + << "Sunday" + << "July" + << "August" + << "September" + << "October" + << "November" + << "December"); + + CustomDataProxy proxy; + proxy.setSourceModel(&model); + + ModelObserver observer(&proxy); + + // Cause the source model to reset. + model.setStringList(QStringList() << "Spam" << "Eggs"); + +} void tst_QSortFilterProxyModel::testParentLayoutChanged() { @@ -3276,8 +3414,6 @@ void tst_QSortFilterProxyModel::testParentLayoutChanged() proxy2.setSourceModel(&proxy); proxy2.setObjectName("proxy2"); - qRegisterMetaType<QList<QPersistentModelIndex> >(); - QSignalSpy dataChangedSpy(&model, SIGNAL(dataChanged(QModelIndex,QModelIndex))); QVERIFY(dataChangedSpy.isValid()); @@ -3411,8 +3547,6 @@ private: void tst_QSortFilterProxyModel::moveSourceRows() { - qRegisterMetaType<QList<QPersistentModelIndex> >(); - DynamicTreeModel model; { @@ -3635,6 +3769,45 @@ void tst_QSortFilterProxyModel::simpleFilterInvalidation() model.insertRow(0, new QStandardItem("extra")); } +class CustomRoleNameModel : public QAbstractListModel +{ + Q_OBJECT +public: + CustomRoleNameModel(QObject *parent = 0) : QAbstractListModel(parent) {} + + QVariant data(const QModelIndex &index, int role) const + { + Q_UNUSED(index); + Q_UNUSED(role); + return QVariant(); + } + + int rowCount(const QModelIndex &parent = QModelIndex()) const + { + Q_UNUSED(parent); + return 0; + } + + QHash<int, QByteArray> roleNames() const + { + QHash<int, QByteArray> rn = QAbstractListModel::roleNames(); + rn[Qt::UserRole + 1] = "custom"; + return rn; + } +}; + +void tst_QSortFilterProxyModel::chainedProxyModelRoleNames() +{ + QSortFilterProxyModel proxy1; + QSortFilterProxyModel proxy2; + CustomRoleNameModel customModel; + + proxy2.setSourceModel(&proxy1); + + // changing the sourceModel of proxy1 must also update roleNames of proxy2 + proxy1.setSourceModel(&customModel); + QVERIFY(proxy2.roleNames().value(Qt::UserRole + 1) == "custom"); +} QTEST_MAIN(tst_QSortFilterProxyModel) #include "tst_qsortfilterproxymodel.moc" diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index a692b79fe9..6811551769 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -1003,49 +1003,81 @@ void tst_QtJson::toVariantList() void tst_QtJson::toJson() { - QJsonObject object; - object.insert("\\Key\n", QString("Value")); - object.insert("null", QJsonValue()); - QJsonArray array; - array.append(true); - array.append(999.); - array.append(QLatin1String("string")); - array.append(QJsonValue()); - array.append(QLatin1String("\\\a\n\r\b\tabcABC\"")); - object.insert("Array", array); + // Test QJsonDocument::Indented format + { + QJsonObject object; + object.insert("\\Key\n", QString("Value")); + object.insert("null", QJsonValue()); + QJsonArray array; + array.append(true); + array.append(999.); + array.append(QLatin1String("string")); + array.append(QJsonValue()); + array.append(QLatin1String("\\\a\n\r\b\tabcABC\"")); + object.insert("Array", array); + + QByteArray json = QJsonDocument(object).toJson(); + + QByteArray expected = + "{\n" + " \"Array\": [\n" + " true,\n" + " 999,\n" + " \"string\",\n" + " null,\n" + " \"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"\n" + " ],\n" + " \"\\\\Key\\n\": \"Value\",\n" + " \"null\": null\n" + "}\n"; + QCOMPARE(json, expected); - QByteArray json = QJsonDocument(object).toJson(); - - QByteArray expected = - "{\n" - " \"Array\": [\n" - " true,\n" - " 999,\n" - " \"string\",\n" - " null,\n" - " \"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"\n" - " ],\n" - " \"\\\\Key\\n\": \"Value\",\n" - " \"null\": null\n" - "}\n"; - QCOMPARE(json, expected); + QJsonDocument doc; + doc.setObject(object); + json = doc.toJson(); + QCOMPARE(json, expected); - QJsonDocument doc; - doc.setObject(object); - json = doc.toJson(); - QCOMPARE(json, expected); + doc.setArray(array); + json = doc.toJson(); + expected = + "[\n" + " true,\n" + " 999,\n" + " \"string\",\n" + " null,\n" + " \"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"\n" + "]\n"; + QCOMPARE(json, expected); + } - doc.setArray(array); - json = doc.toJson(); - expected = - "[\n" - " true,\n" - " 999,\n" - " \"string\",\n" - " null,\n" - " \"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"\n" - "]\n"; - QCOMPARE(json, expected); + // Test QJsonDocument::Compact format + { + QJsonObject object; + object.insert("\\Key\n", QString("Value")); + object.insert("null", QJsonValue()); + QJsonArray array; + array.append(true); + array.append(999.); + array.append(QLatin1String("string")); + array.append(QJsonValue()); + array.append(QLatin1String("\\\a\n\r\b\tabcABC\"")); + object.insert("Array", array); + + QByteArray json = QJsonDocument(object).toJson(QJsonDocument::Compact); + QByteArray expected = + "{\"Array\": [true,999,\"string\",null,\"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"],\"\\\\Key\\n\": \"Value\",\"null\": null}"; + QCOMPARE(json, expected); + + QJsonDocument doc; + doc.setObject(object); + json = doc.toJson(QJsonDocument::Compact); + QCOMPARE(json, expected); + + doc.setArray(array); + json = doc.toJson(QJsonDocument::Compact); + expected = "[true,999,\"string\",null,\"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"]"; + QCOMPARE(json, expected); + } } void tst_QtJson::fromJson() @@ -1135,6 +1167,30 @@ void tst_QtJson::fromJson() QCOMPARE(object.value("6").type(), QJsonValue::Object); QCOMPARE(object.value("6").toObject().size(), 0); } + { + QByteArray compactJson = "{\"Array\": [true,999,\"string\",null,\"\\\\\\u0007\\n\\r\\b\\tabcABC\\\"\"],\"\\\\Key\\n\": \"Value\",\"null\": null}"; + QJsonDocument doc = QJsonDocument::fromJson(compactJson); + QVERIFY(!doc.isEmpty()); + QCOMPARE(doc.isArray(), false); + QCOMPARE(doc.isObject(), true); + QJsonObject object = doc.object(); + QCOMPARE(object.size(), 3); + QCOMPARE(object.value("\\Key\n").isString(), true); + QCOMPARE(object.value("\\Key\n").toString(), QString("Value")); + QCOMPARE(object.value("null").isNull(), true); + QCOMPARE(object.value("Array").isArray(), true); + QJsonArray array = object.value("Array").toArray(); + QCOMPARE(array.size(), 5); + QCOMPARE(array.at(0).isBool(), true); + QCOMPARE(array.at(0).toBool(), true); + QCOMPARE(array.at(1).isDouble(), true); + QCOMPARE(array.at(1).toDouble(), 999.); + QCOMPARE(array.at(2).isString(), true); + QCOMPARE(array.at(2).toString(), QLatin1String("string")); + QCOMPARE(array.at(3).isNull(), true); + QCOMPARE(array.at(4).isString(), true); + QCOMPARE(array.at(4).toString(), QLatin1String("\\\a\n\r\b\tabcABC\"")); + } } void tst_QtJson::fromJsonErrors() diff --git a/tests/auto/corelib/kernel/qmath/tst_qmath.cpp b/tests/auto/corelib/kernel/qmath/tst_qmath.cpp index 0d977317ca..a1ca2ca8cb 100644 --- a/tests/auto/corelib/kernel/qmath/tst_qmath.cpp +++ b/tests/auto/corelib/kernel/qmath/tst_qmath.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Copyright (C) 2013 Laszlo Papp <lpapp@kde.org> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -49,6 +50,10 @@ class tst_QMath : public QObject Q_OBJECT private slots: void fastSinCos(); + void degreesToRadians_data(); + void degreesToRadians(); + void radiansToDegrees_data(); + void radiansToDegrees(); }; void tst_QMath::fastSinCos() @@ -62,6 +67,76 @@ void tst_QMath::fastSinCos() } } +void tst_QMath::degreesToRadians_data() +{ + QTest::addColumn<float>("degreesFloat"); + QTest::addColumn<float>("radiansFloat"); + QTest::addColumn<double>("degreesDouble"); + QTest::addColumn<double>("radiansDouble"); + + QTest::newRow( "pi" ) << 180.0f << float(M_PI) << 180.0 << PI; + QTest::newRow( "doublepi" ) << 360.0f << float(2*M_PI) << 360.0 << 2*PI; + QTest::newRow( "halfpi" ) << 90.0f << float(M_PI_2) << 90.0 << PI/2; + + QTest::newRow( "random" ) << 123.1234567f << 2.1489097058516724f << 123.123456789123456789 << 2.148909707407169856192285627; + QTest::newRow( "bigrandom" ) << 987654321.9876543f << 17237819.79023679f << 987654321987654321.987654321987654321 << 17237819790236794.0; + + QTest::newRow( "zero" ) << 0.0f << 0.0f << 0.0 << 0.0; + + QTest::newRow( "minuspi" ) << -180.0f << float(-M_PI) << 180.0 << PI; + QTest::newRow( "minusdoublepi" ) << -360.0f << float(-2*M_PI) << -360.0 << -2*PI; + QTest::newRow( "minushalfpi" ) << -90.0f << float(-M_PI_2) << -90.0 << -PI/2; + + QTest::newRow( "minusrandom" ) << -123.1234567f << -2.1489097058516724f << -123.123456789123456789 << -2.148909707407169856192285627; + QTest::newRow( "minusbigrandom" ) << -987654321.9876543f << -17237819.79023679f << -987654321987654321.987654321987654321 << -17237819790236794.0; +} + +void tst_QMath::degreesToRadians() +{ + QFETCH(float, degreesFloat); + QFETCH(float, radiansFloat); + QFETCH(double, degreesDouble); + QFETCH(double, radiansDouble); + + QCOMPARE(qDegreesToRadians(degreesFloat), radiansFloat); + QCOMPARE(qDegreesToRadians(degreesDouble), radiansDouble); +} + +void tst_QMath::radiansToDegrees_data() +{ + QTest::addColumn<float>("radiansFloat"); + QTest::addColumn<float>("degreesFloat"); + QTest::addColumn<double>("radiansDouble"); + QTest::addColumn<double>("degreesDouble"); + + QTest::newRow( "pi" ) << float(M_PI) << 180.0f << PI << 180.0; + QTest::newRow( "doublepi" ) << float(2*M_PI) << 360.0f << 2*PI << 360.0; + QTest::newRow( "halfpi" ) << float(M_PI_2) << 90.0f<< PI/2 << 90.0; + + QTest::newRow( "random" ) << 123.1234567f << 7054.454427971739f << 123.123456789123456789 << 7054.4544330781363896676339209079742431640625; + QTest::newRow( "bigrandom" ) << 987654321.9876543f << 56588424267.74745f << 987654321987654321.987654321987654321 << 56588424267747450880.0; + + QTest::newRow( "zero" ) << 0.0f << 0.0f << 0.0 << 0.0; + + QTest::newRow( "minuspi" ) << float(-M_PI) << -180.0f << -PI << -180.0; + QTest::newRow( "minusdoublepi" ) << float(-2*M_PI) << -360.0f << -2*PI << -360.0; + QTest::newRow( "minushalfpi" ) << float(-M_PI_2) << -90.0f << -PI/2 << -90.0; + + QTest::newRow( "minusrandom" ) << -123.1234567f << -7054.454427971739f << -123.123456789123456789 << -7054.4544330781363896676339209079742431640625; + QTest::newRow( "minusbigrandom" ) << -987654321.9876543f << -56588424267.74745f << -987654321987654321.987654321987654321 << -56588424267747450880.0; +} + +void tst_QMath::radiansToDegrees() +{ + QFETCH(float, radiansFloat); + QFETCH(float, degreesFloat); + QFETCH(double, radiansDouble); + QFETCH(double, degreesDouble); + + QCOMPARE(qRadiansToDegrees(radiansFloat), degreesFloat); + QCOMPARE(qRadiansToDegrees(radiansDouble), degreesDouble); +} + QTEST_APPLESS_MAIN(tst_QMath) #include "tst_qmath.moc" diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index 865264c43a..a6d1d9f14d 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -144,6 +144,16 @@ private slots: void disconnectDoesNotLeakFunctor(); }; +struct QObjectCreatedOnShutdown +{ + QObjectCreatedOnShutdown() {} + ~QObjectCreatedOnShutdown() + { + QObject(); + } +}; +static QObjectCreatedOnShutdown s_qobjectCreatedOnShutdown; + class SenderObject : public QObject { Q_OBJECT diff --git a/tests/auto/corelib/thread/qthreadonce/qthreadonce.h b/tests/auto/corelib/thread/qthreadonce/qthreadonce.h index eff7924410..5e04a16bb9 100644 --- a/tests/auto/corelib/thread/qthreadonce/qthreadonce.h +++ b/tests/auto/corelib/thread/qthreadonce/qthreadonce.h @@ -46,8 +46,6 @@ #include <QtCore/qglobal.h> #include <QtCore/qatomic.h> -QT_BEGIN_HEADER - #ifndef QT_NO_THREAD @@ -108,6 +106,4 @@ public: #endif // QT_NO_THREAD -QT_END_HEADER - #endif diff --git a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp index a586f81ccc..57a43a2b33 100644 --- a/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ b/tests/auto/corelib/thread/qthreadpool/tst_qthreadpool.cpp @@ -64,6 +64,12 @@ QRunnable *createTask(FunctionPointer pointer) class tst_QThreadPool : public QObject { Q_OBJECT +public: + tst_QThreadPool(); + ~tst_QThreadPool(); + + static QMutex *functionTestMutex; + private slots: void runFunction(); void createThreadRunFunction(); @@ -92,8 +98,24 @@ private slots: void waitForDoneTimeout(); void destroyingWaitsForTasksToFinish(); void stressTest(); + +private: + QMutex m_functionTestMutex; }; + +QMutex *tst_QThreadPool::functionTestMutex = 0; + +tst_QThreadPool::tst_QThreadPool() +{ + tst_QThreadPool::functionTestMutex = &m_functionTestMutex; +} + +tst_QThreadPool::~tst_QThreadPool() +{ + tst_QThreadPool::functionTestMutex = 0; +} + int testFunctionCount; void sleepTestFunction() @@ -114,19 +136,19 @@ void noSleepTestFunction() void sleepTestFunctionMutex() { - static QMutex testMutex; + Q_ASSERT(tst_QThreadPool::functionTestMutex); QTest::qSleep(1000); - testMutex.lock(); + tst_QThreadPool::functionTestMutex->lock(); ++testFunctionCount; - testMutex.unlock(); + tst_QThreadPool::functionTestMutex->unlock(); } void noSleepTestFunctionMutex() { - static QMutex testMutex; - testMutex.lock(); + Q_ASSERT(tst_QThreadPool::functionTestMutex); + tst_QThreadPool::functionTestMutex->lock(); ++testFunctionCount; - testMutex.unlock(); + tst_QThreadPool::functionTestMutex->unlock(); } void tst_QThreadPool::runFunction() diff --git a/tests/auto/corelib/tools/qchar/tst_qchar.cpp b/tests/auto/corelib/tools/qchar/tst_qchar.cpp index 478747bf15..c89d553112 100644 --- a/tests/auto/corelib/tools/qchar/tst_qchar.cpp +++ b/tests/auto/corelib/tools/qchar/tst_qchar.cpp @@ -709,40 +709,40 @@ void tst_QChar::lineBreakClass() void tst_QChar::script() { - QVERIFY(QUnicodeTables::script(0x0020u) == QUnicodeTables::Common); - QVERIFY(QUnicodeTables::script(0x0041u) == QUnicodeTables::Common); // ### Latin - QVERIFY(QUnicodeTables::script(0x0375u) == QUnicodeTables::Greek); - QVERIFY(QUnicodeTables::script(0x0400u) == QUnicodeTables::Cyrillic); - QVERIFY(QUnicodeTables::script(0x0531u) == QUnicodeTables::Armenian); - QVERIFY(QUnicodeTables::script(0x0591u) == QUnicodeTables::Hebrew); - QVERIFY(QUnicodeTables::script(0x0600u) == QUnicodeTables::Arabic); - QVERIFY(QUnicodeTables::script(0x0700u) == QUnicodeTables::Syriac); - QVERIFY(QUnicodeTables::script(0x0780u) == QUnicodeTables::Thaana); - QVERIFY(QUnicodeTables::script(0x07c0u) == QUnicodeTables::Nko); - QVERIFY(QUnicodeTables::script(0x0900u) == QUnicodeTables::Devanagari); - QVERIFY(QUnicodeTables::script(0x0981u) == QUnicodeTables::Bengali); - QVERIFY(QUnicodeTables::script(0x0a01u) == QUnicodeTables::Gurmukhi); - QVERIFY(QUnicodeTables::script(0x0a81u) == QUnicodeTables::Gujarati); - QVERIFY(QUnicodeTables::script(0x0b01u) == QUnicodeTables::Oriya); - QVERIFY(QUnicodeTables::script(0x0b82u) == QUnicodeTables::Tamil); - QVERIFY(QUnicodeTables::script(0x0c01u) == QUnicodeTables::Telugu); - QVERIFY(QUnicodeTables::script(0x0c82u) == QUnicodeTables::Kannada); - QVERIFY(QUnicodeTables::script(0x0d02u) == QUnicodeTables::Malayalam); - QVERIFY(QUnicodeTables::script(0x0d82u) == QUnicodeTables::Sinhala); - QVERIFY(QUnicodeTables::script(0x0e01u) == QUnicodeTables::Thai); - QVERIFY(QUnicodeTables::script(0x0e81u) == QUnicodeTables::Lao); - QVERIFY(QUnicodeTables::script(0x0f00u) == QUnicodeTables::Tibetan); - QVERIFY(QUnicodeTables::script(0x1000u) == QUnicodeTables::Myanmar); - QVERIFY(QUnicodeTables::script(0x10a0u) == QUnicodeTables::Georgian); - QVERIFY(QUnicodeTables::script(0x1100u) == QUnicodeTables::Hangul); - QVERIFY(QUnicodeTables::script(0x1680u) == QUnicodeTables::Ogham); - QVERIFY(QUnicodeTables::script(0x16a0u) == QUnicodeTables::Runic); - QVERIFY(QUnicodeTables::script(0x1780u) == QUnicodeTables::Khmer); - QVERIFY(QUnicodeTables::script(0x200cu) == QUnicodeTables::Inherited); - QVERIFY(QUnicodeTables::script(0x200du) == QUnicodeTables::Inherited); - QVERIFY(QUnicodeTables::script(0x1018au) == QUnicodeTables::Greek); - QVERIFY(QUnicodeTables::script(0x1f130u) == QUnicodeTables::Common); - QVERIFY(QUnicodeTables::script(0xe0100u) == QUnicodeTables::Inherited); + QVERIFY(QChar::script(0x0020u) == QChar::Script_Common); + QVERIFY(QChar::script(0x0041u) == QChar::Script_Latin); + QVERIFY(QChar::script(0x0375u) == QChar::Script_Greek); + QVERIFY(QChar::script(0x0400u) == QChar::Script_Cyrillic); + QVERIFY(QChar::script(0x0531u) == QChar::Script_Armenian); + QVERIFY(QChar::script(0x0591u) == QChar::Script_Hebrew); + QVERIFY(QChar::script(0x0600u) == QChar::Script_Arabic); + QVERIFY(QChar::script(0x0700u) == QChar::Script_Syriac); + QVERIFY(QChar::script(0x0780u) == QChar::Script_Thaana); + QVERIFY(QChar::script(0x07c0u) == QChar::Script_Nko); + QVERIFY(QChar::script(0x0900u) == QChar::Script_Devanagari); + QVERIFY(QChar::script(0x0981u) == QChar::Script_Bengali); + QVERIFY(QChar::script(0x0a01u) == QChar::Script_Gurmukhi); + QVERIFY(QChar::script(0x0a81u) == QChar::Script_Gujarati); + QVERIFY(QChar::script(0x0b01u) == QChar::Script_Oriya); + QVERIFY(QChar::script(0x0b82u) == QChar::Script_Tamil); + QVERIFY(QChar::script(0x0c01u) == QChar::Script_Telugu); + QVERIFY(QChar::script(0x0c82u) == QChar::Script_Kannada); + QVERIFY(QChar::script(0x0d02u) == QChar::Script_Malayalam); + QVERIFY(QChar::script(0x0d82u) == QChar::Script_Sinhala); + QVERIFY(QChar::script(0x0e01u) == QChar::Script_Thai); + QVERIFY(QChar::script(0x0e81u) == QChar::Script_Lao); + QVERIFY(QChar::script(0x0f00u) == QChar::Script_Tibetan); + QVERIFY(QChar::script(0x1000u) == QChar::Script_Myanmar); + QVERIFY(QChar::script(0x10a0u) == QChar::Script_Georgian); + QVERIFY(QChar::script(0x1100u) == QChar::Script_Hangul); + QVERIFY(QChar::script(0x1680u) == QChar::Script_Ogham); + QVERIFY(QChar::script(0x16a0u) == QChar::Script_Runic); + QVERIFY(QChar::script(0x1780u) == QChar::Script_Khmer); + QVERIFY(QChar::script(0x200cu) == QChar::Script_Inherited); + QVERIFY(QChar::script(0x200du) == QChar::Script_Inherited); + QVERIFY(QChar::script(0x1018au) == QChar::Script_Greek); + QVERIFY(QChar::script(0x1f130u) == QChar::Script_Common); + QVERIFY(QChar::script(0xe0100u) == QChar::Script_Inherited); } void tst_QChar::normalization_data() diff --git a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp index 5ba2f2920a..e941ceb456 100644 --- a/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp +++ b/tests/auto/corelib/tools/qcryptographichash/tst_qcryptographichash.cpp @@ -52,6 +52,7 @@ private slots: void intermediary_result_data(); void intermediary_result(); void sha1(); + void sha3(); void files_data(); void files(); }; @@ -118,6 +119,23 @@ void tst_QCryptographicHash::intermediary_result_data() << QByteArray("abc") << QByteArray("abc") << QByteArray::fromHex("DDAF35A193617ABACC417349AE20413112E6FA4E89A97EA20A9EEEE64B55D39A2192992A274FC1A836BA3C23A3FEEBBD454D4423643CE80E2A9AC94FA54CA49F") << QByteArray::fromHex("F3C41E7B63EE869596FC28BAD64120612C520F65928AB4D126C72C6998B551B8FF1CEDDFED4373E6717554DC89D1EEE6F0AB22FD3675E561ABA9AE26A3EEC53B"); + + QTest::newRow("sha3_224") << int(QCryptographicHash::Sha3_224) + << QByteArray("abc") << QByteArray("abc") + << QByteArray::fromHex("C30411768506EBE1C2871B1EE2E87D38DF342317300A9B97A95EC6A8") + << QByteArray::fromHex("048330E7C7C8B4A41AB713B3A6F958D77B8CF3EE969930F1584DD550"); + QTest::newRow("sha3_256") << int(QCryptographicHash::Sha3_256) + << QByteArray("abc") << QByteArray("abc") + << QByteArray::fromHex("4E03657AEA45A94FC7D47BA826C8D667C0D1E6E33A64A036EC44F58FA12D6C45") + << QByteArray::fromHex("9F0ADAD0A59B05D2E04A1373342B10B9EB16C57C164C8A3BFCBF46DCCEE39A21"); + QTest::newRow("sha3_384") << int(QCryptographicHash::Sha3_384) + << QByteArray("abc") << QByteArray("abc") + << QByteArray::fromHex("F7DF1165F033337BE098E7D288AD6A2F74409D7A60B49C36642218DE161B1F99F8C681E4AFAF31A34DB29FB763E3C28E") + << QByteArray::fromHex("D733B87D392D270889D3DA23AE113F349E25574B445F319CDE4CD3F877C753E9E3C65980421339B3A131457FF393939F"); + QTest::newRow("sha3_512") << int(QCryptographicHash::Sha3_512) + << QByteArray("abc") << QByteArray("abc") + << QByteArray::fromHex("18587DC2EA106B9A1563E32B3312421CA164C7F1F07BC922A9C83D77CEA3A1E5D0C69910739025372DC14AC9642629379540C17E2A65B19D77AA511A9D00BB96") + << QByteArray::fromHex("A7C392D2A42155761CA76BDDDE1C47D55486B007EDF465397BFB9DFA74D11C8F0D7C86CD29415283F1B5E7F655CEC25B869C9E9C33A8986F0B38542FB12BFB93"); } void tst_QCryptographicHash::intermediary_result() @@ -167,6 +185,55 @@ void tst_QCryptographicHash::sha1() QByteArray("34AA973CD4C4DAA4F61EEB2BDBAD27316534016F")); } +void tst_QCryptographicHash::sha3() +{ + // SHA3-224("The quick brown fox jumps over the lazy dog") + // 10aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe + QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog", + QCryptographicHash::Sha3_224).toHex(), + QByteArray("310aee6b30c47350576ac2873fa89fd190cdc488442f3ef654cf23fe")); + // SHA3-224("The quick brown fox jumps over the lazy dog.") + // c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab + QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog.", + QCryptographicHash::Sha3_224).toHex(), + QByteArray("c59d4eaeac728671c635ff645014e2afa935bebffdb5fbd207ffdeab")); + + // SHA3-256("The quick brown fox jumps over the lazy dog") + // 4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15 + QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog", + QCryptographicHash::Sha3_256).toHex(), + QByteArray("4d741b6f1eb29cb2a9b9911c82f56fa8d73b04959d3d9d222895df6c0b28aa15")); + + // SHA3-256("The quick brown fox jumps over the lazy dog.") + // 578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d + QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog.", + QCryptographicHash::Sha3_256).toHex(), + QByteArray("578951e24efd62a3d63a86f7cd19aaa53c898fe287d2552133220370240b572d")); + + // SHA3-384("The quick brown fox jumps over the lazy dog") + // 283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3 + QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog", + QCryptographicHash::Sha3_384).toHex(), + QByteArray("283990fa9d5fb731d786c5bbee94ea4db4910f18c62c03d173fc0a5e494422e8a0b3da7574dae7fa0baf005e504063b3")); + + // SHA3-384("The quick brown fox jumps over the lazy dog.") + // 9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b + QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog.", + QCryptographicHash::Sha3_384).toHex(), + QByteArray("9ad8e17325408eddb6edee6147f13856ad819bb7532668b605a24a2d958f88bd5c169e56dc4b2f89ffd325f6006d820b")); + + // SHA3-512("The quick brown fox jumps over the lazy dog") + // d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609 + QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog", + QCryptographicHash::Sha3_512).toHex(), + QByteArray("d135bb84d0439dbac432247ee573a23ea7d3c9deb2a968eb31d47c4fb45f1ef4422d6c531b5b9bd6f449ebcc449ea94d0a8f05f62130fda612da53c79659f609")); + + // SHA3-512("The quick brown fox jumps over the lazy dog.") + // ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760 + QCOMPARE(QCryptographicHash::hash("The quick brown fox jumps over the lazy dog.", + QCryptographicHash::Sha3_512).toHex(), + QByteArray("ab7192d2b11f51c7dd744e7b3441febf397ca07bf812cceae122ca4ded6387889064f8db9230f173f6d1ab6e24b6e50f065b039f799f5592360a6558eb52d760")); +} Q_DECLARE_METATYPE(QCryptographicHash::Algorithm); diff --git a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp index 05a6c6b252..4e5b0a3555 100644 --- a/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp +++ b/tests/auto/corelib/tools/qdatetime/tst_qdatetime.cpp @@ -145,6 +145,8 @@ private: QDateTime invalidDateTime() const { return QDateTime(invalidDate(), invalidTime()); } QDate invalidDate() const { return QDate(); } QTime invalidTime() const { return QTime(-1, -1, -1); } + qint64 minJd() const { return QDateTimePrivate::minJd(); } + qint64 maxJd() const { return QDateTimePrivate::maxJd(); } }; Q_DECLARE_METATYPE(Qt::TimeSpec) @@ -462,14 +464,25 @@ void tst_QDateTime::setMSecsSinceEpoch_data() << (Q_INT64_C(123456) << 32) << QDateTime(QDate(18772, 8, 15), QTime(1, 8, 14, 976), Qt::UTC) << QDateTime(QDate(18772, 8, 15), QTime(3, 8, 14, 976)); - QTest::newRow("min_date") // julian day 0 is an invalid date for QDate + QTest::newRow("old min (Tue Nov 25 00:00:00 -4714)") << Q_INT64_C(-210866716800000) << QDateTime(QDate::fromJulianDay(1), QTime(), Qt::UTC) << QDateTime(QDate::fromJulianDay(1), QTime(1, 0)); - QTest::newRow("max_date") // technically jd is unsigned, but fromJulianDay takes int + QTest::newRow("old max (Tue Jun 3 21:59:59 5874898)") << Q_INT64_C(185331720376799999) << QDateTime(QDate::fromJulianDay(0x7fffffff), QTime(21, 59, 59, 999), Qt::UTC) << QDateTime(QDate::fromJulianDay(0x7fffffff), QTime(23, 59, 59, 999)); + QTest::newRow("min") + // + 1 because, in the reference check below, calling addMSecs(qint64min) + // will internally apply unary minus to -qint64min, resulting in a + // positive value 1 too big for qint64max, causing an overflow. + << std::numeric_limits<qint64>::min() + 1 + << QDateTime(QDate(-292275056, 5, 16), QTime(16, 47, 4, 193), Qt::UTC) + << QDateTime(QDate(-292275056, 5, 16), QTime(17, 47, 4, 193), Qt::LocalTime); + QTest::newRow("max") + << std::numeric_limits<qint64>::max() + << QDateTime(QDate(292278994, 8, 17), QTime(7, 12, 55, 807), Qt::UTC) + << QDateTime(QDate(292278994, 8, 17), QTime(9, 12, 55, 807), Qt::LocalTime); } void tst_QDateTime::setMSecsSinceEpoch() @@ -821,6 +834,29 @@ void tst_QDateTime::toTimeSpec_data() QTest::newRow("winter4") << QDateTime(QDate(6000, 2, 29), utcTime, Qt::UTC) << QDateTime(QDate(6000, 2, 29), localStandardTime, Qt::LocalTime); + // Test mktime boundaries (1970 - 2038) and adjustDate(). + QTest::newRow("1969/12/31 23:00 UTC") + << QDateTime(QDate(1969, 12, 31), QTime(23, 0, 0), Qt::UTC) + << QDateTime(QDate(1970, 1, 1), QTime(0, 0, 0), Qt::LocalTime); + QTest::newRow("2037/12/31 23:00 UTC") + << QDateTime(QDate(2037, 12, 31), QTime(23, 0, 0), Qt::UTC) + << QDateTime(QDate(2038, 1, 1), QTime(0, 0, 0), Qt::LocalTime); + + QTest::newRow("-271821/4/20 00:00 UTC (JavaScript min date, start of day)") + << QDateTime(QDate(-271821, 4, 20), QTime(0, 0, 0), Qt::UTC) + << QDateTime(QDate(-271821, 4, 20), QTime(1, 0, 0), Qt::LocalTime); + QTest::newRow("-271821/4/20 23:00 UTC (JavaScript min date, end of day)") + << QDateTime(QDate(-271821, 4, 20), QTime(23, 0, 0), Qt::UTC) + << QDateTime(QDate(-271821, 4, 21), QTime(0, 0, 0), Qt::LocalTime); + + QTest::newRow("QDate min") + << QDateTime(QDate::fromJulianDay(minJd()), QTime(0, 0, 0), Qt::UTC) + << QDateTime(QDate::fromJulianDay(minJd()), QTime(1, 0, 0), Qt::LocalTime); + + QTest::newRow("QDate max") + << QDateTime(QDate::fromJulianDay(maxJd()), QTime(22, 59, 59), Qt::UTC) + << QDateTime(QDate::fromJulianDay(maxJd()), QTime(23, 59, 59), Qt::LocalTime); + if (europeanTimeZone) { QTest::newRow("summer1") << QDateTime(QDate(2004, 6, 30), utcTime, Qt::UTC) << QDateTime(QDate(2004, 6, 30), localDaylightTime, Qt::LocalTime); @@ -835,6 +871,14 @@ void tst_QDateTime::toTimeSpec_data() #endif QTest::newRow("summer3") << QDateTime(QDate(4000, 6, 30), utcTime, Qt::UTC) << QDateTime(QDate(4000, 6, 30), localDaylightTime, Qt::LocalTime); + + QTest::newRow("275760/9/23 00:00 UTC (JavaScript max date, start of day)") + << QDateTime(QDate(275760, 9, 23), QTime(0, 0, 0), Qt::UTC) + << QDateTime(QDate(275760, 9, 23), QTime(2, 0, 0), Qt::LocalTime); + + QTest::newRow("275760/9/23 22:00 UTC (JavaScript max date, end of day)") + << QDateTime(QDate(275760, 9, 23), QTime(22, 0, 0), Qt::UTC) + << QDateTime(QDate(275760, 9, 24), QTime(0, 0, 0), Qt::LocalTime); } QTest::newRow("msec") << QDateTime(QDate(4000, 6, 30), utcTime.addMSecs(1), Qt::UTC) diff --git a/tests/auto/corelib/tools/qhash/tst_qhash.cpp b/tests/auto/corelib/tools/qhash/tst_qhash.cpp index 6df84e6363..903a4e1012 100644 --- a/tests/auto/corelib/tools/qhash/tst_qhash.cpp +++ b/tests/auto/corelib/tools/qhash/tst_qhash.cpp @@ -74,6 +74,7 @@ private slots: void const_shared_null(); void twoArguments_qHash(); + void initializerList(); }; struct Foo { @@ -1300,5 +1301,34 @@ void tst_QHash::twoArguments_qHash() QCOMPARE(wrongqHashOverload, 0); } +void tst_QHash::initializerList() +{ +#ifdef Q_COMPILER_INITIALIZER_LISTS + QHash<int, QString> hash{{1, "hello"}, {2, "initializer_list"}}; + QCOMPARE(hash.count(), 2); + QVERIFY(hash[1] == "hello"); + QVERIFY(hash[2] == "initializer_list"); + + QMultiHash<QString, int> multiHash{{"il", 1}, {"il", 2}, {"il", 3}}; + QCOMPARE(multiHash.count(), 3); + QList<int> values = multiHash.values("il"); + QCOMPARE(values.count(), 3); + + QHash<int, int> emptyHash{}; + QVERIFY(emptyHash.isEmpty()); + + QHash<int, char> emptyPairs{{}, {}}; + QVERIFY(!emptyPairs.isEmpty()); + + QMultiHash<QString, double> emptyMultiHash{}; + QVERIFY(emptyMultiHash.isEmpty()); + + QMultiHash<int, float> emptyPairs2{{}, {}}; + QVERIFY(!emptyPairs2.isEmpty()); +#else + QSKIP("Compiler doesn't support initializer lists"); +#endif +} + QTEST_APPLESS_MAIN(tst_QHash) #include "tst_qhash.moc" diff --git a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp index f28ddec199..4138795973 100644 --- a/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp +++ b/tests/auto/corelib/tools/qlocale/tst_qlocale.cpp @@ -42,7 +42,7 @@ #include <QtTest/QtTest> #include <math.h> -#include <qglobal.h> +#include <qdebug.h> #include <qdir.h> #include <qfileinfo.h> #include <QScopedArrayPointer> @@ -1281,7 +1281,7 @@ static QString getWinLocaleInfo(LCTYPE type) int cnt = GetLocaleInfo(id, type, 0, 0) * 2; if (cnt == 0) { - qWarning("QLocale: empty windows locale info (%d)", type); + qWarning().nospace() << "QLocale: empty windows locale info (" << type << ')'; return QString(); } cnt /= sizeof(wchar_t); @@ -1289,7 +1289,7 @@ static QString getWinLocaleInfo(LCTYPE type) cnt = GetLocaleInfo(id, type, buf.data(), cnt); if (cnt == 0) { - qWarning("QLocale: empty windows locale info (%d)", type); + qWarning().nospace() << "QLocale: empty windows locale info (" << type << ')'; return QString(); } return QString::fromWCharArray(buf.data()); diff --git a/tests/auto/corelib/tools/qmap/tst_qmap.cpp b/tests/auto/corelib/tools/qmap/tst_qmap.cpp index 5069b805bf..801656e1c3 100644 --- a/tests/auto/corelib/tools/qmap/tst_qmap.cpp +++ b/tests/auto/corelib/tools/qmap/tst_qmap.cpp @@ -84,6 +84,7 @@ private slots: void insert(); void checkMostLeftNode(); + void initializerList(); }; typedef QMap<QString, QString> StringMap; @@ -1129,5 +1130,34 @@ void tst_QMap::checkMostLeftNode() sanityCheckTree(map, __LINE__); } +void tst_QMap::initializerList() +{ +#ifdef Q_COMPILER_INITIALIZER_LISTS + QMap<int, QString> map{{1, "hello"}, {2, "initializer_list"}}; + QCOMPARE(map.count(), 2); + QVERIFY(map[1] == "hello"); + QVERIFY(map[2] == "initializer_list"); + + QMultiMap<QString, int> multiMap{{"il", 1}, {"il", 2}, {"il", 3}}; + QCOMPARE(multiMap.count(), 3); + QList<int> values = multiMap.values("il"); + QCOMPARE(values.count(), 3); + + QMap<int, int> emptyMap{}; + QVERIFY(emptyMap.isEmpty()); + + QMap<char, char> emptyPairs{{}, {}}; + QVERIFY(!emptyPairs.isEmpty()); + + QMultiMap<double, double> emptyMultiMap{}; + QVERIFY(emptyMultiMap.isEmpty()); + + QMultiMap<float, float> emptyPairs2{{}, {}}; + QVERIFY(!emptyPairs2.isEmpty()); +#else + QSKIP("Compiler doesn't support initializer lists"); +#endif +} + QTEST_APPLESS_MAIN(tst_QMap) #include "tst_qmap.moc" diff --git a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp index 9700f91128..80311079d4 100644 --- a/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp +++ b/tests/auto/corelib/tools/qmargins/tst_qmargins.cpp @@ -50,6 +50,7 @@ class tst_QMargins : public QObject private slots: void getSetCheck(); void dataStreamCheck(); + void operators(); }; // Testing get/set functions @@ -75,6 +76,49 @@ void tst_QMargins::getSetCheck() QCOMPARE(margins, QMargins(5, 0, 5, 0)); } +void tst_QMargins::operators() +{ + const QMargins m1(12, 14, 16, 18); + const QMargins m2(2, 3, 4, 5); + + const QMargins added = m1 + m2; + QCOMPARE(added, QMargins(14, 17, 20, 23)); + QMargins a = m1; + a += m2; + QCOMPARE(a, added); + + const QMargins subtracted = m1 - m2; + QCOMPARE(subtracted, QMargins(10, 11, 12, 13)); + a = m1; + a -= m2; + QCOMPARE(a, subtracted); + + const QMargins doubled = m1 * 2; + QCOMPARE(doubled, QMargins(24, 28, 32, 36)); + QCOMPARE(2 * m1, doubled); + QCOMPARE(qreal(2) * m1, doubled); + QCOMPARE(m1 * qreal(2), doubled); + + a = m1; + a *= 2; + QCOMPARE(a, doubled); + a = m1; + a *= qreal(2); + QCOMPARE(a, doubled); + + const QMargins halved = m1 / 2; + QCOMPARE(halved, QMargins(6, 7, 8, 9)); + + a = m1; + a /= 2; + QCOMPARE(a, halved); + a = m1; + a /= qreal(2); + QCOMPARE(a, halved); + + QCOMPARE(m1 + (-m1), QMargins()); +} + // Testing QDataStream operators void tst_QMargins::dataStreamCheck() { diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore b/tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore new file mode 100644 index 0000000000..bfd53f437b --- /dev/null +++ b/tests/auto/corelib/tools/qmessageauthenticationcode/.gitignore @@ -0,0 +1 @@ +tst_qmessageauthenticationcode diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro b/tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro new file mode 100644 index 0000000000..1ea23915b7 --- /dev/null +++ b/tests/auto/corelib/tools/qmessageauthenticationcode/qmessageauthenticationcode.pro @@ -0,0 +1,7 @@ +CONFIG += testcase parallel_test +TARGET = tst_qmessageauthenticationcode +QT = core testlib +SOURCES = tst_qmessageauthenticationcode.cpp + +TESTDATA += data/* +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp new file mode 100644 index 0000000000..0e243988e2 --- /dev/null +++ b/tests/auto/corelib/tools/qmessageauthenticationcode/tst_qmessageauthenticationcode.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Ruslan Nigmatullin <euroelessar@yandex.ru> +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtCore/QCoreApplication> +#include <QtTest/QtTest> + +class tst_QMessageAuthenticationCode : public QObject +{ + Q_OBJECT +private slots: + void result_data(); + void result(); + void result_incremental_data(); + void result_incremental(); +}; + +Q_DECLARE_METATYPE(QCryptographicHash::Algorithm) + +void tst_QMessageAuthenticationCode::result_data() +{ + QTest::addColumn<QCryptographicHash::Algorithm>("algo"); + QTest::addColumn<QByteArray>("key"); + QTest::addColumn<QByteArray>("message"); + QTest::addColumn<QByteArray>("code"); + + // Empty values + QTest::newRow("md5-empty") << QCryptographicHash::Md5 + << QByteArray() + << QByteArray() + << QByteArray::fromHex("74e6f7298a9c2d168935f58c001bad88"); + QTest::newRow("sha1-empty") << QCryptographicHash::Sha1 + << QByteArray() + << QByteArray() + << QByteArray::fromHex("fbdb1d1b18aa6c08324b7d64b71fb76370690e1d"); + QTest::newRow("sha256-empty") << QCryptographicHash::Sha256 + << QByteArray() + << QByteArray() + << QByteArray::fromHex("b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad"); + + // Some not-empty + QTest::newRow("md5") << QCryptographicHash::Md5 + << QByteArray("key") + << QByteArray("The quick brown fox jumps over the lazy dog") + << QByteArray::fromHex("80070713463e7749b90c2dc24911e275"); + QTest::newRow("sha1") << QCryptographicHash::Sha1 + << QByteArray("key") + << QByteArray("The quick brown fox jumps over the lazy dog") + << QByteArray::fromHex("de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9"); + QTest::newRow("sha256") << QCryptographicHash::Sha256 + << QByteArray("key") + << QByteArray("The quick brown fox jumps over the lazy dog") + << QByteArray::fromHex("f7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8"); + + // Some from rfc-2104 + QTest::newRow("rfc-md5-1") << QCryptographicHash::Md5 + << QByteArray::fromHex("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b") + << QByteArray("Hi There") + << QByteArray::fromHex("9294727a3638bb1c13f48ef8158bfc9d"); + QTest::newRow("rfc-md5-2") << QCryptographicHash::Md5 + << QByteArray("Jefe") + << QByteArray("what do ya want for nothing?") + << QByteArray::fromHex("750c783e6ab0b503eaa86e310a5db738"); + QTest::newRow("rfc-md5-3") << QCryptographicHash::Md5 + << QByteArray::fromHex("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") + << QByteArray(50, 0xdd) + << QByteArray::fromHex("56be34521d144c88dbb8c733f0e8b3f6"); +} + +void tst_QMessageAuthenticationCode::result() +{ + QFETCH(QCryptographicHash::Algorithm, algo); + QFETCH(QByteArray, key); + QFETCH(QByteArray, message); + QFETCH(QByteArray, code); + + QMessageAuthenticationCode mac(algo); + mac.setKey(key); + mac.addData(message); + QByteArray result = mac.result(); + + QCOMPARE(result, code); +} + +void tst_QMessageAuthenticationCode::result_incremental_data() +{ + result_data(); +} + +void tst_QMessageAuthenticationCode::result_incremental() +{ + QFETCH(QCryptographicHash::Algorithm, algo); + QFETCH(QByteArray, key); + QFETCH(QByteArray, message); + QFETCH(QByteArray, code); + + int index = message.length() / 2; + QByteArray leftPart(message.mid(0, index)); + QByteArray rightPart(message.mid(index)); + + QCOMPARE(leftPart + rightPart, message); + + QMessageAuthenticationCode mac(algo); + mac.setKey(key); + mac.addData(leftPart); + mac.addData(rightPart); + QByteArray result = mac.result(); + + QCOMPARE(result, code); +} + +QTEST_MAIN(tst_QMessageAuthenticationCode) +#include "tst_qmessageauthenticationcode.moc" diff --git a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp index 924cac292e..3231469261 100644 --- a/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp +++ b/tests/auto/corelib/tools/qpoint/tst_qpoint.cpp @@ -70,6 +70,9 @@ private slots: void operator_divide_data(); void operator_divide(); + void dotProduct_data(); + void dotProduct(); + void operator_unary_plus_data(); void operator_unary_plus(); @@ -271,6 +274,28 @@ void tst_QPoint::operator_divide() QCOMPARE(point, expected); } +void tst_QPoint::dotProduct_data() +{ + QTest::addColumn<QPoint>("point1"); + QTest::addColumn<QPoint>("point2"); + QTest::addColumn<int>("expected"); + + QTest::newRow("(0, 0) dot (0, 0)") << QPoint(0, 0) << QPoint(0, 0)<< 0; + QTest::newRow("(10, 0) dot (0, 10)") << QPoint(10, 0) << QPoint(0, 10) << 0; + QTest::newRow("(0, 10) dot (10, 0)") << QPoint(0, 10) << QPoint(10, 0) << 0; + QTest::newRow("(10, 20) dot (-10, -20)") << QPoint(10, 20) << QPoint(-10, -20) << -500; + QTest::newRow("(-10, -20) dot (10, 20)") << QPoint(-10, -20) << QPoint(10, 20) << -500; +} + +void tst_QPoint::dotProduct() +{ + QFETCH(QPoint, point1); + QFETCH(QPoint, point2); + QFETCH(int, expected); + + QCOMPARE(QPoint::dotProduct(point1, point2), expected); +} + void tst_QPoint::operator_unary_plus_data() { operator_unary_minus_data(); diff --git a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp index 0f2e74e68e..fc79b40a18 100644 --- a/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp +++ b/tests/auto/corelib/tools/qpointf/tst_qpointf.cpp @@ -75,6 +75,9 @@ private slots: void operator_divide(); void division(); + void dotProduct_data(); + void dotProduct(); + void operator_unary_plus_data(); void operator_unary_plus(); @@ -290,6 +293,29 @@ void tst_QPointF::division() } } +void tst_QPointF::dotProduct_data() +{ + QTest::addColumn<QPointF>("point1"); + QTest::addColumn<QPointF>("point2"); + QTest::addColumn<qreal>("expected"); + + QTest::newRow("(0, 0) dot (0, 0)") << QPointF(0, 0) << QPointF(0, 0) << qreal(0); + QTest::newRow("(10, 0) dot (0, 10)") << QPointF(10, 0) << QPointF(0, 10)<< qreal(0); + QTest::newRow("(0, 10) dot (10, 0)") << QPointF(0, 10) << QPointF(10, 0) << qreal(0); + QTest::newRow("(10, 20) dot (-10, -20)") << QPointF(10, 20) << QPointF(-10, -20) << qreal(-500); + QTest::newRow("(10.1, 20.2) dot (-10.1, -20.2)") << QPointF(10.1, 20.2) << QPointF(-10.1, -20.2) << qreal(-510.05); + QTest::newRow("(-10.1, -20.2) dot (10.1, 20.2)") << QPointF(-10.1, -20.2) << QPointF(10.1, 20.2) << qreal(-510.05); +} + +void tst_QPointF::dotProduct() +{ + QFETCH(QPointF, point1); + QFETCH(QPointF, point2); + QFETCH(qreal, expected); + + QCOMPARE(QPointF::dotProduct(point1, point2), expected); +} + void tst_QPointF::operator_unary_plus_data() { operator_unary_minus_data(); diff --git a/tests/auto/corelib/tools/qrect/tst_qrect.cpp b/tests/auto/corelib/tools/qrect/tst_qrect.cpp index b3fc8b0759..1b11673bd1 100644 --- a/tests/auto/corelib/tools/qrect/tst_qrect.cpp +++ b/tests/auto/corelib/tools/qrect/tst_qrect.cpp @@ -41,6 +41,7 @@ #include <QtTest/QtTest> #include <qrect.h> +#include <qmargins.h> #include <limits.h> #include <qdebug.h> @@ -133,6 +134,7 @@ private slots: void newMoveTopLeft(); void newMoveBottomRight_data(); void newMoveBottomRight(); + void margins(); void translate_data(); void translate(); @@ -3484,6 +3486,25 @@ void tst_QRect::newMoveBottomRight() QCOMPARE(r,nr); } +void tst_QRect::margins() +{ + const QRect rectangle = QRect(QPoint(10, 10), QSize(50 ,50)); + const QMargins margins = QMargins(2, 3, 4, 5); + + const QRect added = rectangle + margins; + QCOMPARE(added, QRect(QPoint(8, 7), QSize(56, 58))); + QCOMPARE(added, margins + rectangle); + QCOMPARE(added, rectangle.marginsAdded(margins)); + + QRect a = rectangle; + a += margins; + QCOMPARE(added, a); + + a = rectangle; + a -= margins; + QCOMPARE(a, QRect(QPoint(12, 13), QSize(44, 42))); + QCOMPARE(a, rectangle.marginsRemoved(margins)); +} void tst_QRect::translate_data() { diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp index 7073805db4..909725f4b8 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.cpp @@ -1,6 +1,7 @@ /**************************************************************************** ** ** Copyright (C) 2012 Giuseppe D'Angelo <dangelog@gmail.com>. +** Copyright (C) 2013 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> ** Contact: http://www.qt-project.org/legal ** ** This file is part of the test suite of the Qt Toolkit. @@ -126,8 +127,6 @@ bool operator!=(const Match &m, const QRegularExpressionMatch &rem) bool operator==(const QRegularExpressionMatchIterator &iterator, const QList<Match> &expectedMatchList) { QRegularExpressionMatchIterator i = iterator; - if (i.isValid() != (!expectedMatchList.isEmpty())) - return false; foreach (const Match &expectedMatch, expectedMatchList) { @@ -293,6 +292,31 @@ void tst_QRegularExpression::provideRegularExpressions() | QRegularExpression::InvertedGreedinessOption); } +void tst_QRegularExpression::defaultConstructors() +{ + QRegularExpression re; + QCOMPARE(re.pattern(), QString()); + QCOMPARE(re.patternOptions(), QRegularExpression::NoPatternOption); + + QRegularExpressionMatch match; + QCOMPARE(match.regularExpression(), QRegularExpression()); + QCOMPARE(match.regularExpression(), re); + QCOMPARE(match.matchType(), QRegularExpression::NoMatch); + QCOMPARE(match.matchOptions(), QRegularExpression::NoMatchOption); + QCOMPARE(match.hasMatch(), false); + QCOMPARE(match.hasPartialMatch(), false); + QCOMPARE(match.isValid(), true); + QCOMPARE(match.lastCapturedIndex(), -1); + + QRegularExpressionMatchIterator iterator; + QCOMPARE(iterator.regularExpression(), QRegularExpression()); + QCOMPARE(iterator.regularExpression(), re); + QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch); + QCOMPARE(iterator.matchOptions(), QRegularExpression::NoMatchOption); + QCOMPARE(iterator.isValid(), true); + QCOMPARE(iterator.hasNext(), false); +} + void tst_QRegularExpression::gettersSetters_data() { provideRegularExpressions(); @@ -693,12 +717,31 @@ void tst_QRegularExpression::normalMatch() QFETCH(QRegularExpression::MatchOptions, matchOptions); QFETCH(Match, match); - QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions); - consistencyCheck(m); - QVERIFY(m == match); + { + QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NormalMatch, matchOptions); + consistencyCheck(m); + QVERIFY(m == match); + QCOMPARE(m.regularExpression(), regexp); + QCOMPARE(m.matchType(), QRegularExpression::NormalMatch); + QCOMPARE(m.matchOptions(), matchOptions); + } + { + // ignore the expected results provided by the match object -- + // we'll never get any result when testing the NoMatch type. + // Just check the validity of the match here. + Match realMatch; + realMatch.clear(); + realMatch.isValid = match.isValid; + + QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions); + consistencyCheck(m); + QVERIFY(m == realMatch); + QCOMPARE(m.regularExpression(), regexp); + QCOMPARE(m.matchType(), QRegularExpression::NoMatch); + QCOMPARE(m.matchOptions(), matchOptions); + } } - void tst_QRegularExpression::partialMatch_data() { QTest::addColumn<QRegularExpression>("regexp"); @@ -952,9 +995,29 @@ void tst_QRegularExpression::partialMatch() QFETCH(QRegularExpression::MatchOptions, matchOptions); QFETCH(Match, match); - QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions); - consistencyCheck(m); - QVERIFY(m == match); + { + QRegularExpressionMatch m = regexp.match(subject, offset, matchType, matchOptions); + consistencyCheck(m); + QVERIFY(m == match); + QCOMPARE(m.regularExpression(), regexp); + QCOMPARE(m.matchType(), matchType); + QCOMPARE(m.matchOptions(), matchOptions); + } + { + // ignore the expected results provided by the match object -- + // we'll never get any result when testing the NoMatch type. + // Just check the validity of the match here. + Match realMatch; + realMatch.clear(); + realMatch.isValid = match.isValid; + + QRegularExpressionMatch m = regexp.match(subject, offset, QRegularExpression::NoMatch, matchOptions); + consistencyCheck(m); + QVERIFY(m == realMatch); + QCOMPARE(m.regularExpression(), regexp); + QCOMPARE(m.matchType(), QRegularExpression::NoMatch); + QCOMPARE(m.matchOptions(), matchOptions); + } } void tst_QRegularExpression::globalMatch_data() @@ -1223,10 +1286,28 @@ void tst_QRegularExpression::globalMatch() QFETCH(QRegularExpression::MatchType, matchType); QFETCH(QRegularExpression::MatchOptions, matchOptions); QFETCH(QList<Match>, matchList); + { + QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions); + consistencyCheck(iterator); + QVERIFY(iterator == matchList); + QCOMPARE(iterator.regularExpression(), regexp); + QCOMPARE(iterator.matchType(), matchType); + QCOMPARE(iterator.matchOptions(), matchOptions); + } + { + // ignore the expected results provided by the match object -- + // we'll never get any result when testing the NoMatch type. + // Just check the validity of the match here. + QList<Match> realMatchList; + + QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, QRegularExpression::NoMatch, matchOptions); + consistencyCheck(iterator); + QVERIFY(iterator == realMatchList); + QCOMPARE(iterator.regularExpression(), regexp); + QCOMPARE(iterator.matchType(), QRegularExpression::NoMatch); + QCOMPARE(iterator.matchOptions(), matchOptions); + } - QRegularExpressionMatchIterator iterator = regexp.globalMatch(subject, offset, matchType, matchOptions); - consistencyCheck(iterator); - QVERIFY(iterator == matchList); } void tst_QRegularExpression::serialize_data() @@ -1338,6 +1419,86 @@ void tst_QRegularExpression::captureCount() QCOMPARE(re.captureCount(), -1); } +// the comma in the template breaks QFETCH... +typedef QMultiHash<QString, int> StringToIntMap; +Q_DECLARE_METATYPE(StringToIntMap) + +void tst_QRegularExpression::captureNames_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<StringToIntMap>("namedCapturesIndexMap"); + StringToIntMap map; + + QTest::newRow("captureNames01") << "a pattern" << map; + QTest::newRow("captureNames02") << "a.*pattern" << map; + QTest::newRow("captureNames03") << "(a) pattern" << map; + QTest::newRow("captureNames04") << "(a).*(pattern)" << map; + + map.clear(); + map.replace("named", 1); + QTest::newRow("captureNames05") << "a.*(?<named>pattern)" << map; + + map.clear(); + map.replace("named", 2); + QTest::newRow("captureNames06") << "(a).*(?<named>pattern)" << map; + + map.clear(); + map.replace("name1", 1); + map.replace("name2", 2); + QTest::newRow("captureNames07") << "(?<name1>a).*(?<name2>pattern)" << map; + + map.clear(); + map.replace("name1", 2); + map.replace("name2", 1); + QTest::newRow("captureNames08") << "(?<name2>a).*(?<name1>pattern)" << map; + + map.clear(); + map.replace("date", 1); + map.replace("month", 2); + map.replace("year", 3); + QTest::newRow("captureNames09") << "^(?<date>\\d\\d)/(?<month>\\d\\d)/(?<year>\\d\\d\\d\\d)$" << map; + + map.clear(); + map.replace("date", 2); + map.replace("month", 1); + map.replace("year", 3); + QTest::newRow("captureNames10") << "^(?<month>\\d\\d)/(?<date>\\d\\d)/(?<year>\\d\\d\\d\\d)$" << map; + + map.clear(); + map.replace("noun", 2); + QTest::newRow("captureNames11") << "(a)(?|(?<noun>b)|(?<noun>c))(d)" << map; + + map.clear(); + QTest::newRow("captureNames_invalid01") << "(.*" << map; + QTest::newRow("captureNames_invalid02") << "\\" << map; + QTest::newRow("captureNames_invalid03") << "(?<noun)" << map; + QTest::newRow("captureNames_invalid04") << "(?|(?<noun1>a)|(?<noun2>b))" << map; +} + +void tst_QRegularExpression::captureNames() +{ + QFETCH(QString, pattern); + QFETCH(StringToIntMap, namedCapturesIndexMap); + + const QRegularExpression re(pattern); + QStringList namedCaptureGroups = re.namedCaptureGroups(); + int namedCaptureGroupsCount = namedCaptureGroups.size(); + + QCOMPARE(namedCaptureGroupsCount, re.captureCount() + 1); + + for (int i = 0; i < namedCaptureGroupsCount; ++i) { + const QString &name = namedCaptureGroups.at(i); + + if (name.isEmpty()) { + QVERIFY(!namedCapturesIndexMap.contains(name)); + } else { + QVERIFY(namedCapturesIndexMap.contains(name)); + QCOMPARE(i, namedCapturesIndexMap.value(name)); + } + } + +} + void tst_QRegularExpression::pcreJitStackUsage_data() { QTest::addColumn<QString>("pattern"); @@ -1389,3 +1550,35 @@ void tst_QRegularExpression::regularExpressionMatch() QTest::ignoreMessage(QtWarningMsg, "QRegularExpressionMatch::captured: empty capturing group name passed"); QCOMPARE(match.captured(QString()).isNull(), true); } + +void tst_QRegularExpression::JOptionUsage_data() +{ + QTest::addColumn<QString>("pattern"); + QTest::addColumn<bool>("isValid"); + QTest::addColumn<bool>("JOptionUsed"); + + QTest::newRow("joption-notused-01") << "a.*b" << true << false; + QTest::newRow("joption-notused-02") << "^a(b)(c)$" << true << false; + QTest::newRow("joption-notused-03") << "a(b)(?<c>d)|e" << true << false; + QTest::newRow("joption-notused-04") << "(?<a>.)(?<a>.)" << false << false; + + QTest::newRow("joption-used-01") << "(?J)a.*b" << true << true; + QTest::newRow("joption-used-02") << "(?-J)a.*b" << true << true; + QTest::newRow("joption-used-03") << "(?J)(?<a>.)(?<a>.)" << true << true; + QTest::newRow("joption-used-04") << "(?-J)(?<a>.)(?<a>.)" << false << true; + +} + +void tst_QRegularExpression::JOptionUsage() +{ + QFETCH(QString, pattern); + QFETCH(bool, isValid); + QFETCH(bool, JOptionUsed); + + const QString warningMessage = QStringLiteral("QRegularExpressionPrivate::getPatternInfo(): the pattern '%1'\n is using the (?J) option; duplicate capturing group names are not supported by Qt"); + + QRegularExpression re(pattern); + if (isValid && JOptionUsed) + QTest::ignoreMessage(QtWarningMsg, qPrintable(warningMessage.arg(pattern))); + QCOMPARE(re.isValid(), isValid); +} diff --git a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h index d6f9312411..0f62570114 100644 --- a/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h +++ b/tests/auto/corelib/tools/qregularexpression/tst_qregularexpression.h @@ -51,6 +51,7 @@ class tst_QRegularExpression : public QObject Q_OBJECT private slots: + void defaultConstructors(); void gettersSetters_data(); void gettersSetters(); void escape_data(); @@ -71,10 +72,14 @@ private slots: void operatoreq(); void captureCount_data(); void captureCount(); + void captureNames_data(); + void captureNames(); void pcreJitStackUsage_data(); void pcreJitStackUsage(); void regularExpressionMatch_data(); void regularExpressionMatch(); + void JOptionUsage_data(); + void JOptionUsage(); private: void provideRegularExpressions(); diff --git a/tests/auto/corelib/tools/qset/tst_qset.cpp b/tests/auto/corelib/tools/qset/tst_qset.cpp index a3232d05c3..eaa1c018ba 100644 --- a/tests/auto/corelib/tools/qset/tst_qset.cpp +++ b/tests/auto/corelib/tools/qset/tst_qset.cpp @@ -79,6 +79,7 @@ private slots: void javaIterator(); void javaMutableIterator(); void makeSureTheComfortFunctionsCompile(); + void initializerList(); }; void tst_QSet::operator_eq() @@ -918,6 +919,27 @@ void tst_QSet::makeSureTheComfortFunctionsCompile() set1 = set2 - set3; } +void tst_QSet::initializerList() +{ +#ifdef Q_COMPILER_INITIALIZER_LISTS + QSet<int> set{1, 2, 3, 4, 5}; + QCOMPARE(set.count(), 5); + QVERIFY(set.contains(1)); + QVERIFY(set.contains(2)); + QVERIFY(set.contains(3)); + QVERIFY(set.contains(4)); + QVERIFY(set.contains(5)); + + QSet<int> emptySet{}; + QVERIFY(emptySet.isEmpty()); + + QSet<int> set3{{}, {}, {}}; + QVERIFY(!set3.isEmpty()); +#else + QSKIP("Compiler doesn't support initializer lists"); +#endif +} + QTEST_APPLESS_MAIN(tst_QSet) #include "tst_qset.moc" diff --git a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp index 8e10b757c8..5b1a2cf076 100644 --- a/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp +++ b/tests/auto/corelib/tools/qsharedpointer/tst_qsharedpointer.cpp @@ -97,6 +97,7 @@ private slots: void lambdaCustomDeleter(); #endif void creating(); + void creatingVariadic(); void creatingQObject(); void mixTrackingPointerCode(); void reentrancyWhileDestructing(); @@ -176,6 +177,49 @@ public: int Data::generationCounter = 0; int Data::destructorCounter = 0; +struct NoDefaultConstructor1 +{ + int i; + NoDefaultConstructor1(int i) : i(i) {} + NoDefaultConstructor1(uint j) : i(j + 42) {} +}; + +struct NoDefaultConstructorRef1 +{ + int &i; + NoDefaultConstructorRef1(int &i) : i(i) {} +}; + +struct NoDefaultConstructor2 +{ + void *ptr; + int i; + NoDefaultConstructor2(void *ptr, int i) : ptr(ptr), i(i) {} +}; + +struct NoDefaultConstructorRef2 +{ + QString str; + int i; + NoDefaultConstructorRef2(QString &str, int i) : str(str), i(i) {} +}; + +struct NoDefaultConstructorConstRef2 +{ + QString str; + int i; + NoDefaultConstructorConstRef2(const QString &str, int i) : str(str), i(i) {} + NoDefaultConstructorConstRef2(const QByteArray &ba, int i = 42) : str(QString::fromLatin1(ba)), i(i) {} +}; + +#ifdef Q_COMPILER_RVALUE_REFS +struct NoDefaultConstructorRRef1 +{ + int &i; + NoDefaultConstructorRRef1(int &&i) : i(i) {} +}; +#endif + void tst_QSharedPointer::basics_data() { QTest::addColumn<bool>("isNull"); @@ -1436,6 +1480,82 @@ void tst_QSharedPointer::creating() safetyCheck(); } +void tst_QSharedPointer::creatingVariadic() +{ +#if !defined(Q_COMPILER_RVALUE_REFS) || !defined(Q_COMPILER_VARIADIC_TEMPLATES) + QSKIP("This compiler is not in C++11 mode or it doesn't support rvalue refs and variadic templates"); +#else + int i = 42; + + { + NoDefaultConstructor1(1); // control check + QSharedPointer<NoDefaultConstructor1> ptr = QSharedPointer<NoDefaultConstructor1>::create(1); + QCOMPARE(ptr->i, 1); + + NoDefaultConstructor1(0u); // control check + ptr = QSharedPointer<NoDefaultConstructor1>::create(0u); + QCOMPARE(ptr->i, 42); + + NoDefaultConstructor1 x(i); // control check + ptr = QSharedPointer<NoDefaultConstructor1>::create(i); + QCOMPARE(ptr->i, i); + } + { + NoDefaultConstructor2((void*)0, 1); // control check + QSharedPointer<NoDefaultConstructor2> ptr = QSharedPointer<NoDefaultConstructor2>::create((void*)0, 1); + QCOMPARE(ptr->i, 1); + QCOMPARE(ptr->ptr, (void*)0); + + int *null = 0; + NoDefaultConstructor2(null, 2); // control check + ptr = QSharedPointer<NoDefaultConstructor2>::create(null, 2); + QCOMPARE(ptr->i, 2); + QCOMPARE(ptr->ptr, (void*)0); + +#ifdef Q_COMPILER_NULLPTR + NoDefaultConstructor2(nullptr, 3); // control check + ptr = QSharedPointer<NoDefaultConstructor2>::create(nullptr, 3); + QCOMPARE(ptr->i, 3); + QCOMPARE(ptr->ptr, (void*)nullptr); +#endif + } + { + NoDefaultConstructorRef1 x(i); // control check + QSharedPointer<NoDefaultConstructorRef1> ptr = QSharedPointer<NoDefaultConstructorRef1>::create(i); + QCOMPARE(ptr->i, i); + QCOMPARE(&ptr->i, &i); + } + { + NoDefaultConstructorRRef1(1); // control check + QSharedPointer<NoDefaultConstructorRRef1> ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(1); + QCOMPARE(ptr->i, 1); + + NoDefaultConstructorRRef1(std::move(i)); // control check + ptr = QSharedPointer<NoDefaultConstructorRRef1>::create(std::move(i)); + QCOMPARE(ptr->i, i); + } + { + QString text("Hello, World"); + NoDefaultConstructorRef2(text, 1); // control check + QSharedPointer<NoDefaultConstructorRef2> ptr = QSharedPointer<NoDefaultConstructorRef2>::create(text, 1); + QCOMPARE(ptr->str, text); + QCOMPARE(ptr->i, 1); + } + { + QSharedPointer<NoDefaultConstructorConstRef2> ptr; + NoDefaultConstructorConstRef2(QLatin1String("string"), 1); // control check + ptr = QSharedPointer<NoDefaultConstructorConstRef2>::create(QLatin1String("string"), 1); + QCOMPARE(ptr->str, QString("string")); + QCOMPARE(ptr->i, 1); + + NoDefaultConstructorConstRef2(QByteArray("bytearray")); // control check + ptr = QSharedPointer<NoDefaultConstructorConstRef2>::create(QByteArray("bytearray")); + QCOMPARE(ptr->str, QString("bytearray")); + QCOMPARE(ptr->i, 42); + } +#endif +} + void tst_QSharedPointer::creatingQObject() { { @@ -1876,7 +1996,7 @@ void tst_QSharedPointer::invalidConstructs() QByteArray body = code.toLatin1(); bool result = (test.*testFunction)(body); - if (qgetenv("QTEST_EXTERNAL_DEBUG").toInt() > 0) { + if (!result || qgetenv("QTEST_EXTERNAL_DEBUG").toInt() > 0) { qDebug("External test output:"); #ifdef Q_CC_MSVC // MSVC prints errors to stdout diff --git a/tests/auto/corelib/tools/qstring/tst_qstring.cpp b/tests/auto/corelib/tools/qstring/tst_qstring.cpp index 8e30a66d6f..c902d421ed 100644 --- a/tests/auto/corelib/tools/qstring/tst_qstring.cpp +++ b/tests/auto/corelib/tools/qstring/tst_qstring.cpp @@ -238,7 +238,7 @@ private slots: #ifdef QT_USE_ICU void toUpperLower_icu(); #endif -#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU)) +#if !defined(QT_NO_UNICODE_LITERAL) && defined(Q_COMPILER_LAMBDA) void literals(); #endif void eightBitLiterals_data(); @@ -1003,10 +1003,12 @@ void tst_QString::sprintf() a.sprintf("%s%n%s", "hello", &n1, "goodbye"); QCOMPARE(n1, 5); QCOMPARE(a, QString("hellogoodbye")); +#ifndef Q_CC_MINGW // does not know %ll qlonglong n2; a.sprintf("%s%s%lln%s", "foo", "bar", &n2, "whiz"); QCOMPARE((int)n2, 6); QCOMPARE(a, QString("foobarwhiz")); +#endif } /* @@ -1425,6 +1427,55 @@ void tst_QString::contains() QVERIFY(a.contains(QRegularExpression("[FG][HI]"))); QVERIFY(a.contains(QRegularExpression("[G][HE]"))); + { + QRegularExpressionMatch match; + QVERIFY(!match.hasMatch()); + + QVERIFY(a.contains(QRegularExpression("[FG][HI]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 6); + QCOMPARE(match.capturedEnd(), 8); + QCOMPARE(match.captured(), QStringLiteral("GH")); + + QVERIFY(a.contains(QRegularExpression("[G][HE]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 6); + QCOMPARE(match.capturedEnd(), 8); + QCOMPARE(match.captured(), QStringLiteral("GH")); + + QVERIFY(a.contains(QRegularExpression("[f](.*)[FG]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 10); + QCOMPARE(match.capturedEnd(), 15); + QCOMPARE(match.captured(), QString("fGEFG")); + QCOMPARE(match.capturedStart(1), 11); + QCOMPARE(match.capturedEnd(1), 14); + QCOMPARE(match.captured(1), QStringLiteral("GEF")); + + QVERIFY(a.contains(QRegularExpression("[f](.*)[F]"), &match)); + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 10); + QCOMPARE(match.capturedEnd(), 14); + QCOMPARE(match.captured(), QString("fGEF")); + QCOMPARE(match.capturedStart(1), 11); + QCOMPARE(match.capturedEnd(1), 13); + QCOMPARE(match.captured(1), QStringLiteral("GE")); + + QVERIFY(!a.contains(QRegularExpression("ZZZ"), &match)); + // doesn't match, but ensure match didn't change + QVERIFY(match.hasMatch()); + QCOMPARE(match.capturedStart(), 10); + QCOMPARE(match.capturedEnd(), 14); + QCOMPARE(match.captured(), QStringLiteral("fGEF")); + QCOMPARE(match.capturedStart(1), 11); + QCOMPARE(match.capturedEnd(1), 13); + QCOMPARE(match.captured(1), QStringLiteral("GE")); + + // don't crash with a null pointer + QVERIFY(a.contains(QRegularExpression("[FG][HI]"), 0)); + QVERIFY(!a.contains(QRegularExpression("ZZZ"), 0)); + } + CREATE_REF(QLatin1String("FG")); QVERIFY(a.contains(ref)); QVERIFY(a.contains(ref, Qt::CaseInsensitive)); @@ -5187,6 +5238,9 @@ void tst_QString::QCharRefDetaching() const void tst_QString::sprintfZU() const { +#ifdef Q_CC_MINGW + QSKIP("MinGW does not support '%zu'."); +#else { QString string; size_t s = 6; @@ -5215,6 +5269,7 @@ void tst_QString::sprintfZU() const string.sprintf("%zu %s\n", s, "foo"); QCOMPARE(string, QString::fromLatin1("6 foo\n")); } +#endif // !Q_CC_MINGW } void tst_QString::repeatedSignature() const @@ -5382,7 +5437,7 @@ void tst_QString::toUpperLower_icu() } #endif -#if defined(QT_UNICODE_LITERAL) && (defined(Q_COMPILER_LAMBDA) || defined(Q_CC_GNU)) +#if !defined(QT_NO_UNICODE_LITERAL) && defined(Q_COMPILER_LAMBDA) // Only tested on c++0x compliant compiler or gcc void tst_QString::literals() { diff --git a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp index 66f40e05cb..3494f48603 100644 --- a/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp +++ b/tests/auto/corelib/tools/qstringref/tst_qstringref.cpp @@ -69,6 +69,7 @@ private slots: void compare_data(); void compare(); void operator_eqeq_nullstring(); + void trimmed(); }; static QStringRef emptyRef() @@ -840,6 +841,27 @@ void tst_QStringRef::compare() } } +void tst_QStringRef::trimmed() +{ + QString a; + QStringRef b; + a = "Text"; + b = a.leftRef(-1); + QCOMPARE(b.compare(QStringLiteral("Text")), 0); + QCOMPARE(b.trimmed().compare(QStringLiteral("Text")), 0); + a = " "; + b = a.leftRef(-1); + QCOMPARE(b.compare(QStringLiteral(" ")), 0); + QCOMPARE(b.trimmed().compare(QStringLiteral("")), 0); + a = " a "; + b = a.leftRef(-1); + QCOMPARE(b.trimmed().compare(QStringLiteral("a")), 0); + a = "Text a "; + b = a.midRef(4); + QCOMPARE(b.compare(QStringLiteral(" a ")), 0); + QCOMPARE(b.trimmed().compare(QStringLiteral("a")), 0); +} + QTEST_APPLESS_MAIN(tst_QStringRef) #include "tst_qstringref.moc" diff --git a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp index bda3a2596f..c19080e345 100644 --- a/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp +++ b/tests/auto/corelib/tools/qvarlengtharray/tst_qvarlengtharray.cpp @@ -58,6 +58,7 @@ private slots: void count(); void first(); void last(); + void squeeze(); }; int fooCtor = 0; @@ -653,5 +654,28 @@ void tst_QVarLengthArray::last() QCOMPARE(list.length(), 1); } +void tst_QVarLengthArray::squeeze() +{ + QVarLengthArray<int> list; + int sizeOnStack = list.capacity(); + int sizeOnHeap = sizeOnStack * 2; + list.resize(0); + QCOMPARE(list.capacity(), sizeOnStack); + list.resize(sizeOnHeap); + QCOMPARE(list.capacity(), sizeOnHeap); + list.resize(sizeOnStack); + QCOMPARE(list.capacity(), sizeOnHeap); + list.resize(0); + QCOMPARE(list.capacity(), sizeOnHeap); + list.squeeze(); + QCOMPARE(list.capacity(), sizeOnStack); + list.resize(sizeOnStack); + list.squeeze(); + QCOMPARE(list.capacity(), sizeOnStack); + list.resize(sizeOnHeap); + list.squeeze(); + QCOMPARE(list.capacity(), sizeOnHeap); +} + QTEST_APPLESS_MAIN(tst_QVarLengthArray) #include "tst_qvarlengtharray.moc" diff --git a/tests/auto/corelib/tools/tools.pro b/tests/auto/corelib/tools/tools.pro index 100409e58b..f8b2437d35 100644 --- a/tests/auto/corelib/tools/tools.pro +++ b/tests/auto/corelib/tools/tools.pro @@ -22,6 +22,7 @@ SUBDIRS=\ qlocale \ qmap \ qmargins \ + qmessageauthenticationcode \ qpair \ qpoint \ qpointf \ diff --git a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp index c56a47bbc6..1da7f8a92a 100644 --- a/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp +++ b/tests/auto/dbus/qdbusconnection/tst_qdbusconnection.cpp @@ -1200,6 +1200,19 @@ void tst_QDBusConnection::registerVirtualObject() QVERIFY(!con.registerVirtualObject(path, &obj, QDBusConnection::SubPath)); QCOMPARE(con.objectRegisteredAt(path), static_cast<QObject *>(0)); } + + { + // Register object, make sure no SubPath handling object can be registered on a parent path. + // (same as above, but deeper) + QObject objectAtSubPath; + QVERIFY(con.registerObject(childChildPath, &objectAtSubPath)); + QCOMPARE(con.objectRegisteredAt(childChildPath), static_cast<QObject *>(&objectAtSubPath)); + + VirtualObject obj; + QVERIFY(!con.registerVirtualObject(path, &obj, QDBusConnection::SubPath)); + QCOMPARE(con.objectRegisteredAt(path), static_cast<QObject *>(0)); + } + QCOMPARE(con.objectRegisteredAt(path), static_cast<QObject *>(0)); QCOMPARE(con.objectRegisteredAt(childPath), static_cast<QObject *>(0)); QCOMPARE(con.objectRegisteredAt(childChildPath), static_cast<QObject *>(0)); diff --git a/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp b/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp index 841e09c865..a45a0fefbb 100644 --- a/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp +++ b/tests/auto/dbus/qdbuspendingreply/tst_qdbuspendingreply.cpp @@ -572,6 +572,8 @@ void tst_QDBusPendingReply::errors() QVERIFY(rint.isError()); error = rint.error(); VERIFY_ERROR(error); + int dummyint = rint; + QCOMPARE(dummyint, int()); QDBusPendingReply<int,int> rintint(iface->asyncCall("sendError")); rintint.waitForFinished(); @@ -579,6 +581,9 @@ void tst_QDBusPendingReply::errors() QVERIFY(rintint.isError()); error = rintint.error(); VERIFY_ERROR(error); + dummyint = rintint; + QCOMPARE(dummyint, int()); + QCOMPARE(rintint.argumentAt<1>(), int()); QDBusPendingReply<QString> rstring(iface->asyncCall("sendError")); rstring.waitForFinished(); @@ -586,6 +591,8 @@ void tst_QDBusPendingReply::errors() QVERIFY(rstring.isError()); error = rstring.error(); VERIFY_ERROR(error); + QString dummystring = rstring; + QCOMPARE(dummystring, QString()); } QTEST_MAIN(tst_QDBusPendingReply) diff --git a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp index 4b3db26685..b684231e10 100644 --- a/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp +++ b/tests/auto/gui/image/qimagereader/tst_qimagereader.cpp @@ -94,6 +94,7 @@ private slots: void multiWordNamedColorXPM(); void supportedFormats(); + void supportedMimeTypes(); void readFromDevice_data(); void readFromDevice(); @@ -571,6 +572,26 @@ void tst_QImageReader::supportedFormats() QCOMPARE(formatSet.size(), formats.size()); } +void tst_QImageReader::supportedMimeTypes() +{ + QList<QByteArray> mimeTypes = QImageReader::supportedMimeTypes(); + QList<QByteArray> sortedMimeTypes = mimeTypes; + qSort(sortedMimeTypes); + + // check that the list is sorted + QCOMPARE(mimeTypes, sortedMimeTypes); + + QSet<QByteArray> mimeTypeSet; + foreach (QByteArray mimeType, mimeTypes) + mimeTypeSet << mimeType; + + // check the list as a minimum contains image/bmp + QVERIFY(mimeTypeSet.contains("image/bmp")); + + // check that the list does not contain duplicates + QCOMPARE(mimeTypeSet.size(), mimeTypes.size()); +} + void tst_QImageReader::setBackgroundColor_data() { QTest::addColumn<QString>("fileName"); diff --git a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp index 3c36482d62..f1d0e227f6 100644 --- a/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp +++ b/tests/auto/gui/image/qimagewriter/tst_qimagewriter.cpp @@ -81,6 +81,7 @@ private slots: void writeImage2_data(); void writeImage2(); void supportedFormats(); + void supportedMimeTypes(); void writeToInvalidDevice(); @@ -352,6 +353,26 @@ void tst_QImageWriter::supportedFormats() QCOMPARE(formatSet.size(), formats.size()); } +void tst_QImageWriter::supportedMimeTypes() +{ + QList<QByteArray> mimeTypes = QImageWriter::supportedMimeTypes(); + QList<QByteArray> sortedMimeTypes = mimeTypes; + qSort(sortedMimeTypes); + + // check that the list is sorted + QCOMPARE(mimeTypes, sortedMimeTypes); + + QSet<QByteArray> mimeTypeSet; + foreach (QByteArray mimeType, mimeTypes) + mimeTypeSet << mimeType; + + // check the list as a minimum contains image/bmp + QVERIFY(mimeTypeSet.contains("image/bmp")); + + // check that the list does not contain duplicates + QCOMPARE(mimeTypeSet.size(), mimeTypes.size()); +} + void tst_QImageWriter::writeToInvalidDevice() { QLatin1String fileName("/these/directories/do/not/exist/001.png"); diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index f5298a1690..b9b61425da 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -114,6 +114,7 @@ private slots: void convertFromImageNoDetach(); void convertFromImageDetach(); + void convertFromImageCacheKey(); #if defined(Q_OS_WIN) void toWinHBITMAP_data(); @@ -780,6 +781,28 @@ void tst_QPixmap::convertFromImageDetach() QVERIFY(copy.isDetached()); } +void tst_QPixmap::convertFromImageCacheKey() +{ + QPixmap randomPixmap(10, 10); + if (randomPixmap.handle()->classId() != QPlatformPixmap::RasterClass) + QSKIP("Test only valid for raster pixmaps"); + + //first get the screen format + QImage::Format screenFormat = randomPixmap.toImage().format(); + QVERIFY(screenFormat != QImage::Format_Invalid); + + QImage orig(100,100, screenFormat); + orig.fill(0); + + QPixmap pix = QPixmap::fromImage(orig); + QImage copy = pix.toImage(); + + QVERIFY(copy.format() == screenFormat); + + QCOMPARE(orig.cacheKey(), pix.cacheKey()); + QCOMPARE(copy.cacheKey(), pix.cacheKey()); +} + #if defined(Q_OS_WIN) QT_BEGIN_NAMESPACE diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro index 7e3f25d377..85a81de632 100644 --- a/tests/auto/gui/kernel/kernel.pro +++ b/tests/auto/gui/kernel/kernel.pro @@ -15,6 +15,7 @@ SUBDIRS=\ qmouseevent_modal \ qpalette \ qscreen \ + qsurfaceformat \ qtouchevent \ qwindow \ qguiapplication \ diff --git a/tests/auto/gui/kernel/qsurfaceformat/qsurfaceformat.pro b/tests/auto/gui/kernel/qsurfaceformat/qsurfaceformat.pro new file mode 100644 index 0000000000..dabffde77b --- /dev/null +++ b/tests/auto/gui/kernel/qsurfaceformat/qsurfaceformat.pro @@ -0,0 +1,8 @@ +CONFIG += testcase +CONFIG += parallel_test +TARGET = tst_qsurfaceformat + +QT += core-private gui-private testlib + +SOURCES += tst_qsurfaceformat.cpp +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 diff --git a/tests/auto/gui/kernel/qsurfaceformat/tst_qsurfaceformat.cpp b/tests/auto/gui/kernel/qsurfaceformat/tst_qsurfaceformat.cpp new file mode 100644 index 0000000000..bd4fc88b3c --- /dev/null +++ b/tests/auto/gui/kernel/qsurfaceformat/tst_qsurfaceformat.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qsurfaceformat.h> + +#include <QtTest/QtTest> + +class tst_QSurfaceFormat: public QObject +{ + Q_OBJECT + +private slots: + void versionCheck_data(); + void versionCheck(); +}; + +void tst_QSurfaceFormat::versionCheck_data() +{ + QTest::addColumn<int>("formatMajor"); + QTest::addColumn<int>("formatMinor"); + QTest::addColumn<int>("compareMajor"); + QTest::addColumn<int>("compareMinor"); + QTest::addColumn<bool>("expected"); + + QTest::newRow("lower major, lower minor") + << 3 << 2 << 2 << 1 << true; + QTest::newRow("lower major, same minor") + << 3 << 2 << 2 << 2 << true; + QTest::newRow("lower major, greater minor") + << 3 << 2 << 2 << 3 << true; + QTest::newRow("same major, lower minor") + << 3 << 2 << 3 << 1 << true; + QTest::newRow("same major, same minor") + << 3 << 2 << 3 << 2 << true; + QTest::newRow("same major, greater minor") + << 3 << 2 << 3 << 3 << false; + QTest::newRow("greater major, lower minor") + << 3 << 2 << 4 << 1 << false; + QTest::newRow("greater major, same minor") + << 3 << 2 << 4 << 2 << false; + QTest::newRow("greater major, greater minor") + << 3 << 2 << 4 << 3 << false; +} + +void tst_QSurfaceFormat::versionCheck() +{ + QFETCH( int, formatMajor ); + QFETCH( int, formatMinor ); + QFETCH( int, compareMajor ); + QFETCH( int, compareMinor ); + QFETCH( bool, expected ); + + QSurfaceFormat format; + format.setMinorVersion(formatMinor); + format.setMajorVersion(formatMajor); + + QCOMPARE(format.version() >= qMakePair(compareMajor, compareMinor), expected); + + format.setVersion(formatMajor, formatMinor); + QCOMPARE(format.version() >= qMakePair(compareMajor, compareMinor), expected); +} + +#include <tst_qsurfaceformat.moc> +QTEST_MAIN(tst_QSurfaceFormat); diff --git a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp index 30666aaf2a..02f8584f72 100644 --- a/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp +++ b/tests/auto/gui/kernel/qwindow/tst_qwindow.cpp @@ -49,6 +49,7 @@ // For QSignalSpy slot connections. Q_DECLARE_METATYPE(Qt::ScreenOrientation) +Q_DECLARE_METATYPE(QWindow::Visibility) class tst_QWindow: public QObject { @@ -75,6 +76,7 @@ private slots: void inputReentrancy(); void tabletEvents(); void windowModality_QTBUG27039(); + void visibility(); void initTestCase() { @@ -1079,6 +1081,44 @@ void tst_QWindow::windowModality_QTBUG27039() QCOMPARE(modalA.mousePressedCount, 1); } +void tst_QWindow::visibility() +{ + qRegisterMetaType<Qt::WindowModality>("QWindow::Visibility"); + + QWindow window; + QSignalSpy spy(&window, SIGNAL(visibilityChanged(QWindow::Visibility))); + + window.setVisibility(QWindow::AutomaticVisibility); + QVERIFY(window.isVisible()); + QVERIFY(window.visibility() != QWindow::Hidden); + QVERIFY(window.visibility() != QWindow::AutomaticVisibility); + QCOMPARE(spy.count(), 1); + spy.clear(); + + window.setVisibility(QWindow::Hidden); + QVERIFY(!window.isVisible()); + QCOMPARE(window.visibility(), QWindow::Hidden); + QCOMPARE(spy.count(), 1); + spy.clear(); + + window.setVisibility(QWindow::FullScreen); + QVERIFY(window.isVisible()); + QCOMPARE(window.windowState(), Qt::WindowFullScreen); + QCOMPARE(window.visibility(), QWindow::FullScreen); + QCOMPARE(spy.count(), 1); + spy.clear(); + + window.setWindowState(Qt::WindowNoState); + QCOMPARE(window.visibility(), QWindow::Windowed); + QCOMPARE(spy.count(), 1); + spy.clear(); + + window.setVisible(false); + QCOMPARE(window.visibility(), QWindow::Hidden); + QCOMPARE(spy.count(), 1); + spy.clear(); +} + #include <tst_qwindow.moc> QTEST_MAIN(tst_QWindow) diff --git a/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp b/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp index cd4f808c4e..4c73676329 100644 --- a/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp +++ b/tests/auto/gui/painting/qwmatrix/tst_qwmatrix.cpp @@ -154,7 +154,7 @@ void tst_QWMatrix::mapping_data() << QRect( 0, 0, 30, 40 ) << QPolygon( QRect( -300, -400, 300, 400 ) ); -#if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) +#if (defined(Q_OS_WIN) || defined(Q_OS_WINCE)) && !defined(M_PI) #define M_PI 3.14159265897932384626433832795f #endif diff --git a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp index 15e8c2ee90..cddec5b6e7 100644 --- a/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp +++ b/tests/auto/gui/text/qfontmetrics/tst_qfontmetrics.cpp @@ -281,7 +281,7 @@ void tst_QFontMetrics::inFontUcs4() } { - QFontEngine *engine = QFontPrivate::get(font)->engineForScript(QUnicodeTables::Common); + QFontEngine *engine = QFontPrivate::get(font)->engineForScript(QChar::Script_Common); QGlyphLayout glyphs; glyphs.numGlyphs = 3; uint buf[3]; diff --git a/tests/auto/gui/util/qregularexpressionvalidator/.gitignore b/tests/auto/gui/util/qregularexpressionvalidator/.gitignore new file mode 100644 index 0000000000..a4022144d5 --- /dev/null +++ b/tests/auto/gui/util/qregularexpressionvalidator/.gitignore @@ -0,0 +1 @@ +tst_qregularexpressionvalidator diff --git a/tests/auto/gui/util/qregularexpressionvalidator/qregularexpressionvalidator.pro b/tests/auto/gui/util/qregularexpressionvalidator/qregularexpressionvalidator.pro new file mode 100644 index 0000000000..1e8e50563e --- /dev/null +++ b/tests/auto/gui/util/qregularexpressionvalidator/qregularexpressionvalidator.pro @@ -0,0 +1,4 @@ +CONFIG += testcase parallel_test +TARGET = tst_qregularexpressionvalidator +SOURCES += tst_qregularexpressionvalidator.cpp +QT += testlib diff --git a/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp b/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp new file mode 100644 index 0000000000..61d26104bd --- /dev/null +++ b/tests/auto/gui/util/qregularexpressionvalidator/tst_qregularexpressionvalidator.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui/QRegularExpressionValidator> +#include <QtTest/QtTest> + +class tst_QRegularExpressionValidator : public QObject +{ + Q_OBJECT + +private slots: + void validate_data(); + void validate(); +}; + +Q_DECLARE_METATYPE(QValidator::State) + +void tst_QRegularExpressionValidator::validate_data() +{ + QTest::addColumn<QRegularExpression>("re"); + QTest::addColumn<QString>("value"); + QTest::addColumn<QValidator::State>("state"); + + QTest::newRow("data0") << QRegularExpression("[1-9]\\d{0,3}") << QString("0") << QValidator::Invalid; + QTest::newRow("data1") << QRegularExpression("[1-9]\\d{0,3}") << QString("12345") << QValidator::Invalid; + QTest::newRow("data2") << QRegularExpression("[1-9]\\d{0,3}") << QString("1") << QValidator::Acceptable; + + QTest::newRow("data3") << QRegularExpression("\\S+") << QString("myfile.txt") << QValidator::Acceptable; + QTest::newRow("data4") << QRegularExpression("\\S+") << QString("my file.txt") << QValidator::Invalid; + + QTest::newRow("data5") << QRegularExpression("[A-C]\\d{5}[W-Z]") << QString("a12345Z") << QValidator::Invalid; + QTest::newRow("data6") << QRegularExpression("[A-C]\\d{5}[W-Z]") << QString("A12345Z") << QValidator::Acceptable; + QTest::newRow("data7") << QRegularExpression("[A-C]\\d{5}[W-Z]") << QString("B12") << QValidator::Intermediate; + + QTest::newRow("data8") << QRegularExpression("read\\S?me(\\.(txt|asc|1st))?") << QString("readme") << QValidator::Acceptable; + QTest::newRow("data9") << QRegularExpression("read\\S?me(\\.(txt|asc|1st))?") << QString("read me.txt") << QValidator::Invalid; + QTest::newRow("data10") << QRegularExpression("read\\S?me(\\.(txt|asc|1st))?") << QString("readm") << QValidator::Intermediate; + + QTest::newRow("data11") << QRegularExpression("read\\S?me(\\.(txt|asc|1st))?") << QString("read me.txt") << QValidator::Invalid; + QTest::newRow("data12") << QRegularExpression("read\\S?me(\\.(txt|asc|1st))?") << QString("readm") << QValidator::Intermediate; + + QTest::newRow("data13") << QRegularExpression("\\w\\d\\d") << QString("A57") << QValidator::Acceptable; + QTest::newRow("data14") << QRegularExpression("\\w\\d\\d") << QString("E5") << QValidator::Intermediate; + QTest::newRow("data15") << QRegularExpression("\\w\\d\\d") << QString("+9") << QValidator::Invalid; + + QTest::newRow("empty01") << QRegularExpression() << QString() << QValidator::Acceptable; + QTest::newRow("empty02") << QRegularExpression() << QString("test") << QValidator::Acceptable; +} + +void tst_QRegularExpressionValidator::validate() +{ + QFETCH(QRegularExpression, re); + QFETCH(QString, value); + + QRegularExpressionValidator rv; + + // setting the same regexp won't emit signals + const int signalCount = (rv.regularExpression() == re) ? 0 : 1; + + QSignalSpy spy(&rv, SIGNAL(regularExpressionChanged(QRegularExpression))); + QSignalSpy changedSpy(&rv, SIGNAL(changed())); + + rv.setRegularExpression(re); + QCOMPARE(rv.regularExpression(), re); + + int pos = -1; + QValidator::State result = rv.validate(value, pos); + + QTEST(result, "state"); + if (result == QValidator::Invalid) + QCOMPARE(pos, value.length()); + else + QCOMPARE(pos, -1); // ensure pos is not modified if validate returned Acceptable or Intermediate + + QCOMPARE(spy.count(), signalCount); + QCOMPARE(changedSpy.count(), signalCount); +} + +QTEST_GUILESS_MAIN(tst_QRegularExpressionValidator) + +#include "tst_qregularexpressionvalidator.moc" diff --git a/tests/auto/gui/util/util.pro b/tests/auto/gui/util/util.pro index a0963980c9..f2c4515dc2 100644 --- a/tests/auto/gui/util/util.pro +++ b/tests/auto/gui/util/util.pro @@ -4,4 +4,5 @@ SUBDIRS= \ qdoublevalidator \ qintvalidator \ qregexpvalidator \ + qregularexpressionvalidator \ diff --git a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp index 284201db29..4ee4b67ec0 100644 --- a/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp +++ b/tests/auto/network/access/qnetworkcookiejar/tst_qnetworkcookiejar.cpp @@ -451,7 +451,7 @@ void tst_QNetworkCookieJar::effectiveTLDs_data() QTest::newRow("yes-wildcard1.5") << "anything.jm" << true; QTest::newRow("yes-wildcard2") << "something.kh" << true; QTest::newRow("yes-wildcard3") << "whatever.uk" << true; - QTest::newRow("yes-wildcard4") << "anything.shizuoka.jp" << true; + QTest::newRow("yes-wildcard4") << "anything.sendai.jp" << true; QTest::newRow("yes-wildcard5") << "foo.sch.uk" << true; } diff --git a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp index 624ce5e800..075735295c 100644 --- a/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/auto/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -71,6 +71,9 @@ #ifndef QT_NO_SSL #include <QtNetwork/qsslerror.h> #include <QtNetwork/qsslconfiguration.h> +#ifdef QT_BUILD_INTERNAL +#include <QtNetwork/private/qsslconfiguration_p.h> +#endif #endif #ifndef QT_NO_BEARERMANAGEMENT #include <QtNetwork/qnetworkconfigmanager.h> @@ -173,6 +176,9 @@ public Q_SLOTS: void sslErrors(QNetworkReply*,const QList<QSslError> &); void storeSslConfiguration(); void ignoreSslErrorListSlot(QNetworkReply *reply, const QList<QSslError> &); +#ifdef QT_BUILD_INTERNAL + void sslSessionSharingHelperSlot(); +#endif #endif protected Q_SLOTS: @@ -357,6 +363,10 @@ private Q_SLOTS: void ignoreSslErrorsListWithSlot(); void sslConfiguration_data(); void sslConfiguration(); +#ifdef QT_BUILD_INTERNAL + void sslSessionSharing_data(); + void sslSessionSharing(); +#endif #endif void getAndThenDeleteObject_data(); @@ -5871,6 +5881,73 @@ void tst_QNetworkReply::sslConfiguration() QCOMPARE(reply->error(), expectedError); } +#ifdef QT_BUILD_INTERNAL + +void tst_QNetworkReply::sslSessionSharing_data() +{ + QTest::addColumn<bool>("sessionSharingEnabled"); + QTest::newRow("enabled") << true; + QTest::newRow("disabled") << false; +} + +void tst_QNetworkReply::sslSessionSharing() +{ + QString urlString("https://" + QtNetworkSettings::serverName() + "/qtest/mediumfile"); + QList<QNetworkReplyPtr> replies; + + // warm up SSL session cache + QNetworkRequest warmupRequest(urlString); + QFETCH(bool, sessionSharingEnabled); + warmupRequest.setAttribute(QNetworkRequest::User, sessionSharingEnabled); // so we can read it from the slot + if (! sessionSharingEnabled) { + QSslConfiguration configuration(QSslConfiguration::defaultConfiguration()); + configuration.setSslOption(QSsl::SslOptionDisableSessionTickets, true); + warmupRequest.setSslConfiguration(configuration); + } + QNetworkReply *reply = manager.get(warmupRequest); + reply->ignoreSslErrors(); + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); + QTestEventLoop::instance().enterLoop(20); + QVERIFY(!QTestEventLoop::instance().timeout()); + QCOMPARE(reply->error(), QNetworkReply::NoError); + reply->deleteLater(); + + // now send several requests at the same time, so we open more sockets and reuse the SSL session + for (int a = 0; a < 6; a++) { + QNetworkRequest request(warmupRequest); + replies.append(QNetworkReplyPtr(manager.get(request))); + connect(replies.at(a), SIGNAL(finished()), this, SLOT(sslSessionSharingHelperSlot())); + } + QTestEventLoop::instance().enterLoop(20); + QVERIFY(!QTestEventLoop::instance().timeout()); +} + +void tst_QNetworkReply::sslSessionSharingHelperSlot() +{ + static int count = 0; + + // check that SSL session sharing was used in at least one of the replies + static bool sslSessionSharingWasUsed = false; + QNetworkReply *reply = qobject_cast<QNetworkReply *>(sender()); + bool sslSessionSharingWasUsedInReply = QSslConfigurationPrivate::peerSessionWasShared(reply->sslConfiguration()); + if (sslSessionSharingWasUsedInReply) + sslSessionSharingWasUsed = true; + + QString urlQueryString = reply->url().query(); + QCOMPARE(reply->error(), QNetworkReply::NoError); + + count++; + + if (count == 6) { // all replies have finished + QTestEventLoop::instance().exitLoop(); + bool sessionSharingWasEnabled = reply->request().attribute(QNetworkRequest::User).toBool(); + QCOMPARE(sslSessionSharingWasUsed, sessionSharingWasEnabled); + count = 0; // reset for next row + sslSessionSharingWasUsed = false; // reset for next row + } +} + +#endif // QT_BUILD_INTERNAL #endif // QT_NO_SSL void tst_QNetworkReply::getAndThenDeleteObject_data() diff --git a/tests/auto/other/lancelot/lancelot.pro b/tests/auto/other/lancelot/lancelot.pro index b577e0dbc9..ef557691e3 100644 --- a/tests/auto/other/lancelot/lancelot.pro +++ b/tests/auto/other/lancelot/lancelot.pro @@ -1,5 +1,6 @@ CONFIG += testcase CONFIG += parallel_test +CONFIG -= app_bundle TARGET = tst_lancelot QT += xml widgets testlib diff --git a/tests/auto/other/lancelot/scripts/statictext.qps b/tests/auto/other/lancelot/scripts/statictext.qps index b62b623462..c5ddda197f 100644 --- a/tests/auto/other/lancelot/scripts/statictext.qps +++ b/tests/auto/other/lancelot/scripts/statictext.qps @@ -50,7 +50,25 @@ save drawStaticText 0 80 "scaled sansserif 10pt, bold italic" restore - translate 0 100 + translate 200 200 + setPen black + save + scale -1 -1 + + setFont "sansserif" 10 normal + drawStaticText 0 20 "flipped sansserif 10pt, normal" + + setFont "sansserif" 12 normal + drawStaticText 0 40 "flipped sansserif 12pt, normal" + + setFont "sansserif" 10 bold + drawStaticText 0 60 "flipped sansserif 12pt, bold" + + setFont "sansserif" 10 bold italic + drawStaticText 0 80 "flipped sansserif 10pt, bold italic" + restore + + translate -200 20 setPen black save translate 200 90 @@ -91,26 +109,26 @@ restore end_block translate 250 0 -drawStaticText 25 520 "clipped to rectangle" +drawStaticText 25 640 "clipped to rectangle" save setPen #3f000000 setBrush nobrush - drawRect 20 0 100 500 - setClipRect 20 0 100 500 + drawRect 20 0 100 620 + setClipRect 20 0 100 620 setPen black repeat_block text_drawing restore translate 150 0 -drawStaticText 25 520 "clipped to path" +drawStaticText 25 640 "clipped to path" save path_moveTo clip 20 0 path_cubicTo clip 0 200 40 400 20 400 - path_lineTo clip 30 500 + path_lineTo clip 30 620 path_lineTo clip 30 0 path_lineTo clip 40 0 - path_lineTo clip 40 500 - path_lineTo clip 120 500 + path_lineTo clip 40 620 + path_lineTo clip 120 620 path_lineTo clip 120 0 path_lineTo clip 20 0 setPen #3f000000 diff --git a/tests/auto/other/lancelot/scripts/text.qps b/tests/auto/other/lancelot/scripts/text.qps index d7ee83290b..88c8690ca0 100644 --- a/tests/auto/other/lancelot/scripts/text.qps +++ b/tests/auto/other/lancelot/scripts/text.qps @@ -52,7 +52,25 @@ save drawText 0 80 "scaled sansserif 10pt, bold italic" restore - translate 0 100 + translate 200 200 + setPen black + save + scale -1 -1 + + setFont "sansserif" 10 normal + drawStaticText 0 20 "flipped sansserif 10pt, normal" + + setFont "sansserif" 12 normal + drawStaticText 0 40 "flipped sansserif 12pt, normal" + + setFont "sansserif" 10 bold + drawStaticText 0 60 "flipped sansserif 12pt, bold" + + setFont "sansserif" 10 bold italic + drawStaticText 0 80 "flipped sansserif 10pt, bold italic" + restore + + translate -200 20 setPen black save translate 200 90 @@ -93,26 +111,26 @@ restore end_block translate 250 0 -drawText 25 520 "clipped to rectangle" +drawText 25 640 "clipped to rectangle" save setPen #3f000000 setBrush nobrush - drawRect 20 0 100 500 - setClipRect 20 0 100 500 + drawRect 20 0 100 620 + setClipRect 20 0 100 620 setPen black repeat_block text_drawing restore translate 150 0 -drawText 25 520 "clipped to path" +drawText 25 640 "clipped to path" save path_moveTo clip 20 0 path_cubicTo clip 0 200 40 400 20 400 - path_lineTo clip 30 500 + path_lineTo clip 30 620 path_lineTo clip 30 0 path_lineTo clip 40 0 - path_lineTo clip 40 500 - path_lineTo clip 120 500 + path_lineTo clip 40 620 + path_lineTo clip 120 620 path_lineTo clip 120 0 path_lineTo clip 20 0 setPen #3f000000 diff --git a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp index b0d0459326..202843f5a8 100644 --- a/tests/auto/other/qaccessibility/tst_qaccessibility.cpp +++ b/tests/auto/other/qaccessibility/tst_qaccessibility.cpp @@ -768,12 +768,40 @@ void tst_QAccessibility::actionTest() void tst_QAccessibility::applicationTest() { + { QLatin1String name = QLatin1String("My Name"); qApp->setApplicationName(name); - QAccessibleInterface *interface = QAccessible::queryAccessibleInterface(qApp); + QAIPtr interface(QAccessible::queryAccessibleInterface(qApp)); QCOMPARE(interface->text(QAccessible::Name), name); + QCOMPARE(interface->text(QAccessible::Description), qApp->applicationFilePath()); + QCOMPARE(interface->text(QAccessible::Value), QString()); QCOMPARE(interface->role(), QAccessible::Application); - delete interface; + QCOMPARE(interface->window(), static_cast<QWindow*>(0)); + QCOMPARE(interface->parent(), static_cast<QAccessibleInterface*>(0)); + QCOMPARE(interface->focusChild(), static_cast<QAccessibleInterface*>(0)); + QCOMPARE(interface->indexOfChild(0), -1); + QCOMPARE(interface->child(0), static_cast<QAccessibleInterface*>(0)); + QCOMPARE(interface->child(-1), static_cast<QAccessibleInterface*>(0)); + QCOMPARE(interface->child(1), static_cast<QAccessibleInterface*>(0)); + QCOMPARE(interface->childCount(), 0); + + QWidget widget; + widget.show(); + qApp->setActiveWindow(&widget); + QVERIFY(QTest::qWaitForWindowActive(&widget)); + + QAIPtr widgetIface(QAccessible::queryAccessibleInterface(&widget)); + QCOMPARE(interface->childCount(), 1); + QAIPtr focus(interface->focusChild()); + QCOMPARE(focus->object(), &widget); + QCOMPARE(interface->indexOfChild(0), -1); + QCOMPARE(interface->indexOfChild(widgetIface.data()), 0); + QAIPtr child(interface->child(0)); + QCOMPARE(child->object(), &widget); + QCOMPARE(interface->child(-1), static_cast<QAccessibleInterface*>(0)); + QCOMPARE(interface->child(1), static_cast<QAccessibleInterface*>(0)); + } + QTestAccessibility::clearEvents(); } void tst_QAccessibility::mainWindowTest() @@ -2702,6 +2730,76 @@ void tst_QAccessibility::tableTest() QCOMPARE(table2->rowDescription(1), QString("v2")); QCOMPARE(table2->rowDescription(2), QString("v3")); + tableView->clearSelection(); + tableView->setSelectionBehavior(QAbstractItemView::SelectItems); + tableView->setSelectionMode(QAbstractItemView::SingleSelection); + QVERIFY(!table2->selectRow(0)); + QVERIFY(!table2->isRowSelected(0)); + tableView->setSelectionBehavior(QAbstractItemView::SelectRows); + QVERIFY(table2->selectRow(0)); + QVERIFY(table2->selectRow(1)); + QVERIFY(!table2->isRowSelected(0)); + tableView->setSelectionMode(QAbstractItemView::MultiSelection); + QVERIFY(table2->selectRow(0)); + QVERIFY(table2->isRowSelected(1)); + QVERIFY(table2->unselectRow(0)); + QVERIFY(!table2->isRowSelected(0)); + tableView->setSelectionBehavior(QAbstractItemView::SelectColumns); + QVERIFY(!table2->selectRow(0)); + QVERIFY(!table2->isRowSelected(0)); + tableView->clearSelection(); + QCOMPARE(table2->selectedColumnCount(), 0); + QCOMPARE(table2->selectedRowCount(), 0); + QVERIFY(table2->selectColumn(1)); + QVERIFY(table2->isColumnSelected(1)); + tableView->clearSelection(); + tableView->setSelectionMode(QAbstractItemView::ContiguousSelection); + table2->selectColumn(0); + table2->selectColumn(2); + QVERIFY(!(table2->isColumnSelected(2) && table2->isColumnSelected(0))); + tableView->clearSelection(); + tableView->setSelectionBehavior(QAbstractItemView::SelectItems); + tableView->setSelectionMode(QAbstractItemView::MultiSelection); + table2->selectColumn(1); + table2->selectRow(1); + QVERIFY(table2->isColumnSelected(1)); + QVERIFY(table2->isRowSelected(1)); + + QAIPtr cell4(table2->cellAt(2,2)); + QVERIFY(cell1->actionInterface()); + QVERIFY(cell1->tableCellInterface()); + + tableView->clearSelection(); + tableView->setSelectionBehavior(QAbstractItemView::SelectRows); + tableView->setSelectionMode(QAbstractItemView::SingleSelection); + QVERIFY(!cell1->tableCellInterface()->isSelected()); + QVERIFY(cell1->actionInterface()->actionNames().contains(QAccessibleActionInterface::toggleAction())); + cell1->actionInterface()->doAction(QAccessibleActionInterface::toggleAction()); + QVERIFY(cell2->tableCellInterface()->isSelected()); + + tableView->clearSelection(); + tableView->setSelectionBehavior(QAbstractItemView::SelectColumns); + cell3->actionInterface()->doAction(QAccessibleActionInterface::toggleAction()); + QVERIFY(cell4->tableCellInterface()->isSelected()); + + tableView->clearSelection(); + tableView->setSelectionBehavior(QAbstractItemView::SelectItems); + tableView->setSelectionMode(QAbstractItemView::SingleSelection); + cell1->actionInterface()->doAction(QAccessibleActionInterface::toggleAction()); + QVERIFY(cell1->tableCellInterface()->isSelected()); + cell2->actionInterface()->doAction(QAccessibleActionInterface::toggleAction()); + QVERIFY(!cell1->tableCellInterface()->isSelected()); + + tableView->clearSelection(); + tableView->setSelectionMode(QAbstractItemView::MultiSelection); + cell1->actionInterface()->doAction(QAccessibleActionInterface::toggleAction()); + cell2->actionInterface()->doAction(QAccessibleActionInterface::toggleAction()); + QVERIFY(cell1->tableCellInterface()->isSelected()); + QVERIFY(cell2->tableCellInterface()->isSelected()); + cell2->actionInterface()->doAction(QAccessibleActionInterface::toggleAction()); + QVERIFY(cell1->tableCellInterface()->isSelected()); + QVERIFY(!cell2->tableCellInterface()->isSelected()); + delete tableView; QTestAccessibility::clearEvents(); diff --git a/tests/auto/sql/kernel/qsqlresult/testsqldriver.h b/tests/auto/sql/kernel/qsqlresult/testsqldriver.h index 720b819839..93f4978ea6 100644 --- a/tests/auto/sql/kernel/qsqlresult/testsqldriver.h +++ b/tests/auto/sql/kernel/qsqlresult/testsqldriver.h @@ -81,6 +81,8 @@ public: case QSqlDriver::PreparedQueries: case QSqlDriver::NamedPlaceholders: return true; + default: + break; } return false; } diff --git a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp index 6506479d1d..e9ad1778fa 100644 --- a/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp +++ b/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp @@ -136,6 +136,8 @@ private slots: void compare_tostring_data(); void compareQStringLists(); void compareQStringLists_data(); + void compareQListInt(); + void compareQListDouble(); void compareQPixmaps(); void compareQPixmaps_data(); void compareQImages(); @@ -307,6 +309,20 @@ void tst_Cmptest::compareQStringLists() QCOMPARE(opA, opB); } +void tst_Cmptest::compareQListInt() +{ + QList<int> int1; int1 << 1 << 2 << 3; + QList<int> int2; int2 << 1 << 2 << 4; + QCOMPARE(int1, int2); +} + +void tst_Cmptest::compareQListDouble() +{ + QList<double> double1; double1 << 1.5 << 2 << 3; + QList<double> double2; double2 << 1 << 2 << 4; + QCOMPARE(double1, double2); +} + void tst_Cmptest::compareQPixmaps_data() { QTest::addColumn<QPixmap>("opA"); diff --git a/tests/auto/testlib/selftests/expected_cmptest.lightxml b/tests/auto/testlib/selftests/expected_cmptest.lightxml index 83b2e6e137..54c5bb85f0 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.lightxml +++ b/tests/auto/testlib/selftests/expected_cmptest.lightxml @@ -49,35 +49,49 @@ </Incident> <Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="308"> <DataTag><![CDATA[last item different]]></DataTag> - <Description><![CDATA[Compared QStringLists differ at index 2. + <Description><![CDATA[Compared lists differ at index 2. Actual (opA): 'string3' Expected (opB): 'DIFFERS']]></Description> </Incident> <Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="308"> <DataTag><![CDATA[second-last item different]]></DataTag> - <Description><![CDATA[Compared QStringLists differ at index 2. + <Description><![CDATA[Compared lists differ at index 2. Actual (opA): 'string3' Expected (opB): 'DIFFERS']]></Description> </Incident> <Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="308"> <DataTag><![CDATA[prefix]]></DataTag> - <Description><![CDATA[Compared QStringLists have different sizes. + <Description><![CDATA[Compared lists have different sizes. Actual (opA) size: '2' Expected (opB) size: '1']]></Description> </Incident> <Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="308"> <DataTag><![CDATA[short list second]]></DataTag> - <Description><![CDATA[Compared QStringLists have different sizes. + <Description><![CDATA[Compared lists have different sizes. Actual (opA) size: '12' Expected (opB) size: '1']]></Description> </Incident> <Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="308"> <DataTag><![CDATA[short list first]]></DataTag> - <Description><![CDATA[Compared QStringLists have different sizes. + <Description><![CDATA[Compared lists have different sizes. Actual (opA) size: '1' Expected (opB) size: '12']]></Description> </Incident> </TestFunction> +<TestFunction name="compareQListInt"> +<Incident type="fail" file="tst_cmptest.cpp" line="316"> + <Description><![CDATA[Compared lists differ at index 2. + Actual (int1): '3' + Expected (int2): '4']]></Description> +</Incident> +</TestFunction> +<TestFunction name="compareQListDouble"> +<Incident type="fail" file="tst_cmptest.cpp" line="323"> + <Description><![CDATA[Compared lists differ at index 0. + Actual (double1): '1.5' + Expected (double2): '1']]></Description> +</Incident> +</TestFunction> <TestFunction name="compareQPixmaps"> <Incident type="pass" file="" line="0"> <DataTag><![CDATA[both null]]></DataTag> diff --git a/tests/auto/testlib/selftests/expected_cmptest.txt b/tests/auto/testlib/selftests/expected_cmptest.txt index de666ed8b1..d41da53b06 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.txt +++ b/tests/auto/testlib/selftests/expected_cmptest.txt @@ -22,26 +22,34 @@ FAIL! : tst_Cmptest::compare_tostring(both non-null user type) Compared values Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(214)] PASS : tst_Cmptest::compareQStringLists(empty lists) PASS : tst_Cmptest::compareQStringLists(equal lists) -FAIL! : tst_Cmptest::compareQStringLists(last item different) Compared QStringLists differ at index 2. +FAIL! : tst_Cmptest::compareQStringLists(last item different) Compared lists differ at index 2. Actual (opA): 'string3' Expected (opB): 'DIFFERS' Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(308)] -FAIL! : tst_Cmptest::compareQStringLists(second-last item different) Compared QStringLists differ at index 2. +FAIL! : tst_Cmptest::compareQStringLists(second-last item different) Compared lists differ at index 2. Actual (opA): 'string3' Expected (opB): 'DIFFERS' Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(308)] -FAIL! : tst_Cmptest::compareQStringLists(prefix) Compared QStringLists have different sizes. +FAIL! : tst_Cmptest::compareQStringLists(prefix) Compared lists have different sizes. Actual (opA) size: '2' Expected (opB) size: '1' Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(308)] -FAIL! : tst_Cmptest::compareQStringLists(short list second) Compared QStringLists have different sizes. +FAIL! : tst_Cmptest::compareQStringLists(short list second) Compared lists have different sizes. Actual (opA) size: '12' Expected (opB) size: '1' Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(308)] -FAIL! : tst_Cmptest::compareQStringLists(short list first) Compared QStringLists have different sizes. +FAIL! : tst_Cmptest::compareQStringLists(short list first) Compared lists have different sizes. Actual (opA) size: '1' Expected (opB) size: '12' Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(308)] +FAIL! : tst_Cmptest::compareQListInt() Compared lists differ at index 2. + Actual (int1): '3' + Expected (int2): '4' + Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(316)] +FAIL! : tst_Cmptest::compareQListDouble() Compared lists differ at index 0. + Actual (double1): '1.5' + Expected (double2): '1' + Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(323)] PASS : tst_Cmptest::compareQPixmaps(both null) FAIL! : tst_Cmptest::compareQPixmaps(one null) Compared QPixmaps differ. Actual (opA).isNull(): 1 @@ -79,5 +87,5 @@ FAIL! : tst_Cmptest::compareQImages(different format) Compared QImages differ i FAIL! : tst_Cmptest::compareQImages(different pixels) Compared values are not the same Loc: [/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp(360)] PASS : tst_Cmptest::cleanupTestCase() -Totals: 11 passed, 18 failed, 0 skipped +Totals: 11 passed, 20 failed, 0 skipped ********* Finished testing of tst_Cmptest ********* diff --git a/tests/auto/testlib/selftests/expected_cmptest.xml b/tests/auto/testlib/selftests/expected_cmptest.xml index 0e5b6de335..ccab93d7c0 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.xml +++ b/tests/auto/testlib/selftests/expected_cmptest.xml @@ -51,35 +51,49 @@ </Incident> <Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="308"> <DataTag><![CDATA[last item different]]></DataTag> - <Description><![CDATA[Compared QStringLists differ at index 2. + <Description><![CDATA[Compared lists differ at index 2. Actual (opA): 'string3' Expected (opB): 'DIFFERS']]></Description> </Incident> <Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="308"> <DataTag><![CDATA[second-last item different]]></DataTag> - <Description><![CDATA[Compared QStringLists differ at index 2. + <Description><![CDATA[Compared lists differ at index 2. Actual (opA): 'string3' Expected (opB): 'DIFFERS']]></Description> </Incident> <Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="308"> <DataTag><![CDATA[prefix]]></DataTag> - <Description><![CDATA[Compared QStringLists have different sizes. + <Description><![CDATA[Compared lists have different sizes. Actual (opA) size: '2' Expected (opB) size: '1']]></Description> </Incident> <Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="308"> <DataTag><![CDATA[short list second]]></DataTag> - <Description><![CDATA[Compared QStringLists have different sizes. + <Description><![CDATA[Compared lists have different sizes. Actual (opA) size: '12' Expected (opB) size: '1']]></Description> </Incident> <Incident type="fail" file="/home/user/dev/qt5/qtbase/tests/auto/testlib/selftests/cmptest/tst_cmptest.cpp" line="308"> <DataTag><![CDATA[short list first]]></DataTag> - <Description><![CDATA[Compared QStringLists have different sizes. + <Description><![CDATA[Compared lists have different sizes. Actual (opA) size: '1' Expected (opB) size: '12']]></Description> </Incident> </TestFunction> +<TestFunction name="compareQListInt"> +<Incident type="fail" file="tst_cmptest.cpp" line="316"> + <Description><![CDATA[Compared lists differ at index 2. + Actual (int1): '3' + Expected (int2): '4']]></Description> +</Incident> +</TestFunction> +<TestFunction name="compareQListDouble"> +<Incident type="fail" file="tst_cmptest.cpp" line="323"> + <Description><![CDATA[Compared lists differ at index 0. + Actual (double1): '1.5' + Expected (double2): '1']]></Description> +</Incident> +</TestFunction> <TestFunction name="compareQPixmaps"> <Incident type="pass" file="" line="0"> <DataTag><![CDATA[both null]]></DataTag> diff --git a/tests/auto/testlib/selftests/expected_cmptest.xunitxml b/tests/auto/testlib/selftests/expected_cmptest.xunitxml index 33e78a5290..0cb88147b0 100644 --- a/tests/auto/testlib/selftests/expected_cmptest.xunitxml +++ b/tests/auto/testlib/selftests/expected_cmptest.xunitxml @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8" ?> -<testsuite errors="0" failures="18" tests="8" name="tst_Cmptest"> +<testsuite errors="0" failures="20" tests="10" name="tst_Cmptest"> <properties> <property value="@INSERT_QT_VERSION_HERE@" name="QTestVersion"/> <property value="@INSERT_QT_VERSION_HERE@" name="QtVersion"/> @@ -22,22 +22,32 @@ Expected (expected): QVariant(PhonyClass,<value not representable as string>)" result="fail"/> </testcase> <testcase result="fail" name="compareQStringLists"> - <failure tag="last item different" message="Compared QStringLists differ at index 2. + <failure tag="last item different" message="Compared lists differ at index 2. Actual (opA): 'string3' Expected (opB): 'DIFFERS'" result="fail"/> - <failure tag="second-last item different" message="Compared QStringLists differ at index 2. + <failure tag="second-last item different" message="Compared lists differ at index 2. Actual (opA): 'string3' Expected (opB): 'DIFFERS'" result="fail"/> - <failure tag="prefix" message="Compared QStringLists have different sizes. + <failure tag="prefix" message="Compared lists have different sizes. Actual (opA) size: '2' Expected (opB) size: '1'" result="fail"/> - <failure tag="short list second" message="Compared QStringLists have different sizes. + <failure tag="short list second" message="Compared lists have different sizes. Actual (opA) size: '12' Expected (opB) size: '1'" result="fail"/> - <failure tag="short list first" message="Compared QStringLists have different sizes. + <failure tag="short list first" message="Compared lists have different sizes. Actual (opA) size: '1' Expected (opB) size: '12'" result="fail"/> </testcase> + <testcase result="fail" name="compareQListInt"> + <failure message="Compared lists differ at index 2. + Actual (int1): '3' + Expected (int2): '4'" result="fail"/> + </testcase> + <testcase result="fail" name="compareQListDouble"> + <failure message="Compared lists differ at index 0. + Actual (double1): '1.5' + Expected (double2): '1'" result="fail"/> + </testcase> <testcase result="fail" name="compareQPixmaps"> <failure tag="one null" message="Compared QPixmaps differ. Actual (opA).isNull(): 1 diff --git a/tests/auto/testlib/selftests/tst_selftests.cpp b/tests/auto/testlib/selftests/tst_selftests.cpp index 4b19ee57ea..441254c126 100644 --- a/tests/auto/testlib/selftests/tst_selftests.cpp +++ b/tests/auto/testlib/selftests/tst_selftests.cpp @@ -563,6 +563,9 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& logge && subdir != QLatin1String("cmptest") // QImage comparison requires QGuiApplication && subdir != QLatin1String("fetchbogus") && subdir != QLatin1String("xunit") +#ifdef Q_CC_MINGW + && subdir != QLatin1String("silent") // calls qFatal() +#endif && subdir != QLatin1String("benchlibcallgrind")) QVERIFY2(err.isEmpty(), err.constData()); @@ -570,8 +573,8 @@ void tst_Selftests::doRunSubTest(QString const& subdir, QStringList const& logge QString logger = loggers[n]; QList<QByteArray> res = splitLines(actualOutputs[n]); QList<QByteArray> exp = expectedResult(subdir, logger); -#ifdef Q_CC_MSVC - // MSVC formats double numbers differently +#if defined (Q_CC_MSVC) || defined(Q_CC_MINGW) + // MSVC, MinGW format double numbers differently if (n == 0 && subdir == QStringLiteral("float")) { for (int i = 0; i < exp.size(); ++i) { exp[i].replace("e-07", "e-007"); diff --git a/tests/auto/tools/moc/moc.pro b/tests/auto/tools/moc/moc.pro index 772086d3c4..8d08d9a8c0 100644 --- a/tests/auto/tools/moc/moc.pro +++ b/tests/auto/tools/moc/moc.pro @@ -11,7 +11,6 @@ TARGET = tst_moc INCLUDEPATH += testproject/include testproject -DEFINES += SRCDIR=\\\"$$PWD\\\" cross_compile: DEFINES += MOC_CROSS_COMPILED HEADERS += using-namespaces.h no-keywords.h task87883.h c-comments.h backslash-newlines.h oldstyle-casts.h \ diff --git a/tests/auto/tools/moc/tst_moc.cpp b/tests/auto/tools/moc/tst_moc.cpp index 15e1bc0620..8d180ce20b 100644 --- a/tests/auto/tools/moc/tst_moc.cpp +++ b/tests/auto/tools/moc/tst_moc.cpp @@ -447,15 +447,6 @@ public: #endif #endif -static QString srcify(const char *path) -{ -#ifndef Q_OS_IRIX - return QString(SRCDIR) + QLatin1Char('/') + QLatin1String(path); -#else - return QString(QLatin1String(path)); -#endif -} - class CtorTestClass : public QObject { Q_OBJECT @@ -480,6 +471,8 @@ CtorTestClass::CtorTestClass(QObject *parent) CtorTestClass::CtorTestClass(int, int, int) {} +class PrivatePropertyTest; + class tst_Moc : public QObject { Q_OBJECT @@ -487,9 +480,15 @@ class tst_Moc : public QObject Q_PROPERTY(bool user1 READ user1 USER true ) Q_PROPERTY(bool user2 READ user2 USER false) Q_PROPERTY(bool user3 READ user3 USER userFunction()) + Q_PROPERTY(QString member1 MEMBER sMember) + Q_PROPERTY(QString member2 MEMBER sMember READ member2) + Q_PROPERTY(QString member3 MEMBER sMember WRITE setMember3) + Q_PROPERTY(QString member4 MEMBER sMember NOTIFY member4Changed) + Q_PROPERTY(QString member5 MEMBER sMember NOTIFY member5Changed) + Q_PROPERTY(QString member6 MEMBER sConst CONSTANT) public: - inline tst_Moc() {} + inline tst_Moc() : sConst("const") {} private slots: void initTestCase(); @@ -546,6 +545,9 @@ private slots: void cxx11Enums_data(); void cxx11Enums(); void returnRefs(); + void memberProperties_data(); + void memberProperties(); + void privateSignalConnection(); void finalClasses_data(); void finalClasses(); @@ -553,6 +555,7 @@ private slots: void explicitOverrideControl(); void autoPropertyMetaTypeRegistration(); void autoMethodArgumentMetaTypeRegistration(); + void autoSignalSpyMetaTypeRegistration(); void parseDefines(); void preprocessorOnly(); @@ -564,6 +567,8 @@ signals: void sigWithCustomType(const MyStruct); void constSignal1() const; void constSignal2(int arg) const; + void member4Changed(); + void member5Changed(const QString &newVal); private: bool user1() { return true; }; @@ -571,14 +576,23 @@ private: bool user3() { return false; }; bool userFunction(){ return false; }; template <class T> void revisions_T(); + QString member2() const { return sMember; } + void setMember3( const QString &sVal ) { sMember = sVal; } private: + QString m_sourceDirectory; QString qtIncludePath; class PrivateClass; + QString sMember; + const QString sConst; + PrivatePropertyTest *pPPTest; }; void tst_Moc::initTestCase() { + const QString testHeader = QFINDTESTDATA("backslash-newlines.h"); + QVERIFY(!testHeader.isEmpty()); + m_sourceDirectory = QFileInfo(testHeader).absolutePath(); #if defined(Q_OS_UNIX) && !defined(QT_NO_PROCESS) QProcess proc; proc.start("qmake", QStringList() << "-query" << "QT_INSTALL_HEADERS"); @@ -625,7 +639,7 @@ void tst_Moc::oldStyleCasts() #endif #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) QProcess proc; - proc.start("moc", QStringList(srcify("/oldstyle-casts.h"))); + proc.start("moc", QStringList(m_sourceDirectory + QStringLiteral("/oldstyle-casts.h"))); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); QByteArray mocOut = proc.readAllStandardOutput(); @@ -655,15 +669,16 @@ void tst_Moc::warnOnExtraSignalSlotQualifiaction() #endif #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) QProcess proc; - proc.start("moc", QStringList(srcify("extraqualification.h"))); + const QString header = m_sourceDirectory + QStringLiteral("/extraqualification.h"); + proc.start("moc", QStringList(header)); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); QByteArray mocOut = proc.readAllStandardOutput(); QVERIFY(!mocOut.isEmpty()); QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError()); - QCOMPARE(mocWarning, QString(SRCDIR) + - QString("/extraqualification.h:53: Warning: Function declaration Test::badFunctionDeclaration contains extra qualification. Ignoring as signal or slot.\n") + - QString(SRCDIR) + QString("/extraqualification.h:56: Warning: parsemaybe: Function declaration Test::anotherOne contains extra qualification. Ignoring as signal or slot.\n")); + QCOMPARE(mocWarning, header + + QString(":53: Warning: Function declaration Test::badFunctionDeclaration contains extra qualification. Ignoring as signal or slot.\n") + + header + QString(":56: Warning: parsemaybe: Function declaration Test::anotherOne contains extra qualification. Ignoring as signal or slot.\n")); #else QSKIP("Only tested on linux/gcc"); #endif @@ -693,7 +708,7 @@ void tst_Moc::inputFileNameWithDotsButNoExtension() #endif #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) QProcess proc; - proc.setWorkingDirectory(QString(SRCDIR) + "/task71021"); + proc.setWorkingDirectory(m_sourceDirectory + QStringLiteral("/task71021")); proc.start("moc", QStringList("../Header")); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); @@ -932,16 +947,16 @@ void tst_Moc::warnOnMultipleInheritance() #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) QProcess proc; QStringList args; - args << "-I" << qtIncludePath + "/QtGui" - << srcify("warn-on-multiple-qobject-subclasses.h"); + const QString header = m_sourceDirectory + QStringLiteral("/warn-on-multiple-qobject-subclasses.h"); + args << "-I" << qtIncludePath + "/QtGui" << header; proc.start("moc", args); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); QByteArray mocOut = proc.readAllStandardOutput(); QVERIFY(!mocOut.isEmpty()); QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError()); - QCOMPARE(mocWarning, QString(SRCDIR) + - QString("/warn-on-multiple-qobject-subclasses.h:53: Warning: Class Bar inherits from two QObject subclasses QWindow and Foo. This is not supported!\n")); + QCOMPARE(mocWarning, header + + QString(":53: Warning: Class Bar inherits from two QObject subclasses QWindow and Foo. This is not supported!\n")); #else QSKIP("Only tested on linux/gcc"); #endif @@ -955,16 +970,16 @@ void tst_Moc::forgottenQInterface() #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) QProcess proc; QStringList args; - args << "-I" << qtIncludePath + "/QtCore" - << srcify("forgotten-qinterface.h"); + const QString header = m_sourceDirectory + QStringLiteral("/forgotten-qinterface.h"); + args << "-I" << qtIncludePath + "/QtCore" << header; proc.start("moc", args); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); QByteArray mocOut = proc.readAllStandardOutput(); QVERIFY(!mocOut.isEmpty()); QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError()); - QCOMPARE(mocWarning, QString(SRCDIR) + - QString("/forgotten-qinterface.h:55: Warning: Class Test implements the interface MyInterface but does not list it in Q_INTERFACES. qobject_cast to MyInterface will not work!\n")); + QCOMPARE(mocWarning, header + + QString(":55: Warning: Class Test implements the interface MyInterface but does not list it in Q_INTERFACES. qobject_cast to MyInterface will not work!\n")); #else QSKIP("Only tested on linux/gcc"); #endif @@ -975,7 +990,7 @@ void tst_Moc::os9Newline() #if !defined(SKIP_NEWLINE_TEST) const QMetaObject &mo = Os9Newlines::staticMetaObject; QVERIFY(mo.indexOfSlot("testSlot()") != -1); - QFile f(srcify("os9-newlines.h")); + QFile f(m_sourceDirectory + QStringLiteral("/os9-newlines.h")); QVERIFY(f.open(QIODevice::ReadOnly)); // no QIODevice::Text! QByteArray data = f.readAll(); f.close(); @@ -989,7 +1004,7 @@ void tst_Moc::winNewline() #if !defined(SKIP_NEWLINE_TEST) const QMetaObject &mo = WinNewlines::staticMetaObject; QVERIFY(mo.indexOfSlot("testSlot()") != -1); - QFile f(srcify("win-newlines.h")); + QFile f(m_sourceDirectory + QStringLiteral("/win-newlines.h")); QVERIFY(f.open(QIODevice::ReadOnly)); // no QIODevice::Text! QByteArray data = f.readAll(); f.close(); @@ -1036,8 +1051,8 @@ void tst_Moc::frameworkSearchPath() #endif #if defined(Q_OS_UNIX) && !defined(QT_NO_PROCESS) QStringList args; - args << "-F" << srcify(".") - << srcify("interface-from-framework.h") + args << "-F" << m_sourceDirectory + QStringLiteral("/.") + << m_sourceDirectory + QStringLiteral("/interface-from-framework.h") ; QProcess proc; @@ -1074,7 +1089,7 @@ void tst_Moc::templateGtGt() #endif #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) QProcess proc; - proc.start("moc", QStringList(srcify("template-gtgt.h"))); + proc.start("moc", QStringList(m_sourceDirectory + QStringLiteral("/template-gtgt.h"))); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); QByteArray mocOut = proc.readAllStandardOutput(); @@ -1093,7 +1108,7 @@ void tst_Moc::defineMacroViaCmdline() QStringList args; args << "-DFOO"; - args << srcify("macro-on-cmdline.h"); + args << m_sourceDirectory + QStringLiteral("/macro-on-cmdline.h"); proc.start("moc", args); QVERIFY(proc.waitForFinished()); @@ -1163,25 +1178,38 @@ class PrivatePropertyTest : public QObject Q_PRIVATE_PROPERTY(d, int bar READ bar WRITE setBar) Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, int plop READ plop WRITE setPlop) Q_PRIVATE_PROPERTY(PrivatePropertyTest::d_func(), int baz READ baz WRITE setBaz) + Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QString blub MEMBER mBlub) + Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QString blub2 MEMBER mBlub READ blub) + Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QString blub3 MEMBER mBlub WRITE setBlub) + Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QString blub4 MEMBER mBlub NOTIFY blub4Changed) + Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QString blub5 MEMBER mBlub NOTIFY blub5Changed) + Q_PRIVATE_PROPERTY(PrivatePropertyTest::d, QString blub6 MEMBER mConst CONSTANT) class MyDPointer { public: - MyDPointer() : mBar(0), mPlop(0) {} + MyDPointer() : mConst("const"), mBar(0), mPlop(0) {} int bar() { return mBar ; } void setBar(int value) { mBar = value; } int plop() { return mPlop ; } void setPlop(int value) { mPlop = value; } int baz() { return mBaz ; } void setBaz(int value) { mBaz = value; } + QString blub() const { return mBlub; } + void setBlub(const QString &value) { mBlub = value; } + QString mBlub; + const QString mConst; private: int mBar; int mPlop; int mBaz; }; public: - PrivatePropertyTest() : mFoo(0), d (new MyDPointer) {} + PrivatePropertyTest(QObject *parent = 0) : QObject(parent), mFoo(0), d (new MyDPointer) {} int foo() { return mFoo ; } void setFoo(int value) { mFoo = value; } MyDPointer *d_func() {return d;} +signals: + void blub4Changed(); + void blub5Changed(const QString &newBlub); private: int mFoo; MyDPointer *d; @@ -1228,14 +1256,15 @@ void tst_Moc::warnOnPropertyWithoutREAD() #endif #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) QProcess proc; - proc.start("moc", QStringList(srcify("warn-on-property-without-read.h"))); + const QString header = m_sourceDirectory + QStringLiteral("/warn-on-property-without-read.h"); + proc.start("moc", QStringList(header)); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); QByteArray mocOut = proc.readAllStandardOutput(); QVERIFY(!mocOut.isEmpty()); QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError()); - QCOMPARE(mocWarning, QString(SRCDIR) + - QString("/warn-on-property-without-read.h:46: Warning: Property declaration foo has no READ accessor function. The property will be invalid.\n")); + QCOMPARE(mocWarning, header + + QString(":46: Warning: Property declaration foo has no READ accessor function or associated MEMBER variable. The property will be invalid.\n")); #else QSKIP("Only tested on linux/gcc"); #endif @@ -1338,14 +1367,15 @@ void tst_Moc::warnOnVirtualSignal() #endif #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) QProcess proc; - proc.start("moc", QStringList(srcify("pure-virtual-signals.h"))); + const QString header = m_sourceDirectory + QStringLiteral("/pure-virtual-signals.h"); + proc.start("moc", QStringList(header)); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); QByteArray mocOut = proc.readAllStandardOutput(); QVERIFY(!mocOut.isEmpty()); QString mocWarning = QString::fromLocal8Bit(proc.readAllStandardError()); - QCOMPARE(mocWarning, QString(SRCDIR) + QString("/pure-virtual-signals.h:48: Warning: Signals cannot be declared virtual\n") + - QString(SRCDIR) + QString("/pure-virtual-signals.h:50: Warning: Signals cannot be declared virtual\n")); + QCOMPARE(mocWarning, header + QString(":48: Warning: Signals cannot be declared virtual\n") + + header + QString(":50: Warning: Signals cannot be declared virtual\n")); #else QSKIP("Only tested on linux/gcc"); #endif @@ -1450,15 +1480,16 @@ void tst_Moc::notifyError() #endif #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) QProcess proc; - proc.start("moc", QStringList(srcify("error-on-wrong-notify.h"))); + const QString header = m_sourceDirectory + QStringLiteral("/error-on-wrong-notify.h"); + proc.start("moc", QStringList(header)); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 1); QCOMPARE(proc.exitStatus(), QProcess::NormalExit); QByteArray mocOut = proc.readAllStandardOutput(); QVERIFY(mocOut.isEmpty()); QString mocError = QString::fromLocal8Bit(proc.readAllStandardError()); - QCOMPARE(mocError, QString(SRCDIR) + - QString("/error-on-wrong-notify.h:52: Error: NOTIFY signal 'fooChanged' of property 'foo' does not exist in class ClassWithWrongNOTIFY.\n")); + QCOMPARE(mocError, header + + QString(":52: Error: NOTIFY signal 'fooChanged' of property 'foo' does not exist in class ClassWithWrongNOTIFY.\n")); #else QSKIP("Only tested on linux/gcc"); #endif @@ -1639,7 +1670,7 @@ void tst_Moc::warnings_data() << QStringList() << 0 << QString("IGNORE_ALL_STDOUT") - << QString("standard input:1: Warning: Property declaration x has no READ accessor function. The property will be invalid."); + << QString("standard input:1: Warning: Property declaration x has no READ accessor function or associated MEMBER variable. The property will be invalid."); // Passing "-nn" should NOT suppress the warning QTest::newRow("Invalid property warning with -nn") @@ -1647,7 +1678,7 @@ void tst_Moc::warnings_data() << (QStringList() << "-nn") << 0 << QString("IGNORE_ALL_STDOUT") - << QString("standard input:1: Warning: Property declaration x has no READ accessor function. The property will be invalid."); + << QString("standard input:1: Warning: Property declaration x has no READ accessor function or associated MEMBER variable. The property will be invalid."); // Passing "-nw" should suppress the warning QTest::newRow("Invalid property warning with -nw") @@ -1781,6 +1812,86 @@ void tst_Moc::returnRefs() // they used to cause miscompilation of the moc generated file. } +void tst_Moc::memberProperties_data() +{ + QTest::addColumn<int>("object"); + QTest::addColumn<QString>("property"); + QTest::addColumn<QString>("signal"); + QTest::addColumn<QString>("writeValue"); + QTest::addColumn<bool>("expectedWriteResult"); + QTest::addColumn<QString>("expectedReadResult"); + + pPPTest = new PrivatePropertyTest( this ); + + QTest::newRow("MEMBER property") + << 0 << "member1" << "" << "abc" << true << "abc"; + QTest::newRow("MEMBER property with READ function") + << 0 << "member2" << "" << "def" << true << "def"; + QTest::newRow("MEMBER property with WRITE function") + << 0 << "member3" << "" << "ghi" << true << "ghi"; + QTest::newRow("MEMBER property with NOTIFY") + << 0 << "member4" << "member4Changed()" << "lmn" << true << "lmn"; + QTest::newRow("MEMBER property with NOTIFY(value)") + << 0 << "member5" << "member5Changed(const QString&)" << "opq" << true << "opq"; + QTest::newRow("MEMBER property with CONSTANT") + << 0 << "member6" << "" << "test" << false << "const"; + QTest::newRow("private MEMBER property") + << 1 << "blub" << "" << "abc" << true << "abc"; + QTest::newRow("private MEMBER property with READ function") + << 1 << "blub2" << "" << "def" << true << "def"; + QTest::newRow("private MEMBER property with WRITE function") + << 1 << "blub3" << "" << "ghi" << true << "ghi"; + QTest::newRow("private MEMBER property with NOTIFY") + << 1 << "blub4" << "blub4Changed()" << "jkl" << true << "jkl"; + QTest::newRow("private MEMBER property with NOTIFY(value)") + << 1 << "blub5" << "blub5Changed(const QString&)" << "mno" << true << "mno"; + QTest::newRow("private MEMBER property with CONSTANT") + << 1 << "blub6" << "" << "test" << false << "const"; +} + +void tst_Moc::memberProperties() +{ + QFETCH(int, object); + QFETCH(QString, property); + QFETCH(QString, signal); + QFETCH(QString, writeValue); + QFETCH(bool, expectedWriteResult); + QFETCH(QString, expectedReadResult); + + QObject *pObj = (object == 0) ? this : static_cast<QObject*>(pPPTest); + + QString sSignalDeclaration; + if (!signal.isEmpty()) + sSignalDeclaration = QString(SIGNAL(%1)).arg(signal); + else + QTest::ignoreMessage(QtWarningMsg, "QSignalSpy: Not a valid signal, use the SIGNAL macro"); + QSignalSpy notifySpy(pObj, sSignalDeclaration.toLatin1().constData()); + + int index = pObj->metaObject()->indexOfProperty(property.toLatin1().constData()); + QVERIFY(index != -1); + QMetaProperty prop = pObj->metaObject()->property(index); + + QCOMPARE(prop.write(pObj, writeValue), expectedWriteResult); + + QVariant readValue = prop.read(pObj); + QCOMPARE(readValue.toString(), expectedReadResult); + + if (!signal.isEmpty()) + { + QCOMPARE(notifySpy.count(), 1); + if (prop.notifySignal().parameterNames().size() > 0) { + QList<QVariant> arguments = notifySpy.takeFirst(); + QCOMPARE(arguments.size(), 1); + QCOMPARE(arguments.at(0).toString(), expectedReadResult); + } + + notifySpy.clear(); + // a second write with the same value should not cause the signal to be emitted again + QCOMPARE(prop.write(pObj, writeValue), expectedWriteResult); + QCOMPARE(notifySpy.count(), 0); + } +} + class SignalConnectionTester : public QObject { Q_OBJECT @@ -2388,6 +2499,7 @@ struct CustomObject8 {}; struct CustomObject9 {}; struct CustomObject10 {}; struct CustomObject11 {}; +struct CustomObject12 {}; Q_DECLARE_METATYPE(CustomObject3) Q_DECLARE_METATYPE(CustomObject4) @@ -2398,6 +2510,7 @@ Q_DECLARE_METATYPE(CustomObject8) Q_DECLARE_METATYPE(CustomObject9) Q_DECLARE_METATYPE(CustomObject10) Q_DECLARE_METATYPE(CustomObject11) +Q_DECLARE_METATYPE(CustomObject12) class AutoRegistrationObject : public QObject { @@ -2520,6 +2633,9 @@ public slots: void ref2(QList<int>&) {} void ref3(CustomQObject2&) {} void ref4(QSharedPointer<CustomQObject2>&) {} + +signals: + void someSignal(CustomObject12); }; void tst_Moc::autoPropertyMetaTypeRegistration() @@ -2583,6 +2699,16 @@ void tst_Moc::autoMethodArgumentMetaTypeRegistration() int i = metaObject->methodOffset(); // Start after QObject built-in slots; + while (i < metaObject->methodCount()) { + // Skip over signals so we start at the first slot. + const QMetaMethod method = metaObject->method(i); + if (method.methodType() == QMetaMethod::Signal) + ++i; + else + break; + + } + #define TYPE_LOOP(TYPE) \ { \ const QMetaMethod method = metaObject->method(i); \ @@ -2709,6 +2835,26 @@ void tst_Moc::autoMethodArgumentMetaTypeRegistration() } +void tst_Moc::autoSignalSpyMetaTypeRegistration() +{ + AutoRegistrationObject aro; + + QVector<int> methodArgMetaTypeIds; + + const QMetaObject *metaObject = aro.metaObject(); + + int i = metaObject->indexOfSignal(QMetaObject::normalizedSignature("someSignal(CustomObject12)")); + + QVERIFY(i > 0); + + QCOMPARE(QMetaType::type("CustomObject12"), (int)QMetaType::UnknownType); + + QSignalSpy spy(&aro, SIGNAL(someSignal(CustomObject12))); + + QVERIFY(QMetaType::type("CustomObject12") != QMetaType::UnknownType); + QCOMPARE(QMetaType::type("CustomObject12"), qMetaTypeId<CustomObject12>()); +} + void tst_Moc::parseDefines() { const QMetaObject *mo = &PD_NAMESPACE::PD_CLASSNAME::staticMetaObject; @@ -2789,7 +2935,7 @@ void tst_Moc::preprocessorOnly() #endif #if defined(Q_OS_LINUX) && defined(Q_CC_GNU) && !defined(QT_NO_PROCESS) QProcess proc; - proc.start("moc", QStringList() << "-E" << srcify("/pp-dollar-signs.h")); + proc.start("moc", QStringList() << "-E" << m_sourceDirectory + QStringLiteral("/pp-dollar-signs.h")); QVERIFY(proc.waitForFinished()); QCOMPARE(proc.exitCode(), 0); QByteArray mocOut = proc.readAllStandardOutput(); diff --git a/tests/auto/widgets/dialogs/dialogs.pro b/tests/auto/widgets/dialogs/dialogs.pro index 034f37c6e0..e767c9767e 100644 --- a/tests/auto/widgets/dialogs/dialogs.pro +++ b/tests/auto/widgets/dialogs/dialogs.pro @@ -20,3 +20,4 @@ wince*:SUBDIRS -= qabstractprintdialog qsidebar \ mac:qinputdialog.CONFIG += no_check_target # QTBUG-25496 +win32-g++*: SUBDIRS -= qfilesystemmodel # QTBUG-29403 diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro b/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro index 5606033240..78639e87a5 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/qfilesystemmodel.pro @@ -1,6 +1,6 @@ CONFIG += testcase -CONFIG += parallel_test -win32:testcase.timeout = 900 # this testcase can be slow on Windows +# This testcase can be slow on Windows and may interfere with other file system tests. +win32:testcase.timeout = 900 QT += widgets widgets-private QT += core-private gui testlib diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index db80aa1b22..e36eaa5af2 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -48,6 +48,7 @@ #include <QFileIconProvider> #include <QTreeView> #include <QHeaderView> +#include <QStandardPaths> #include <QTime> #include <QStyle> #include <QtGlobal> @@ -109,6 +110,7 @@ private slots: void setData_data(); void setData(); + void sortPersistentIndex(); void sort_data(); void sort(); @@ -207,27 +209,30 @@ void tst_QFileSystemModel::rootPath() QCOMPARE(rootChanged.count(), 0); QString oldRootPath = model->rootPath(); - root = model->setRootPath(QDir::homePath()); + const QStringList documentPaths = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); + QVERIFY(!documentPaths.isEmpty()); + const QString documentPath = documentPaths.front(); + root = model->setRootPath(documentPath); QTRY_VERIFY(model->rowCount(root) >= 0); - QCOMPARE(model->rootPath(), QString(QDir::homePath())); + QCOMPARE(model->rootPath(), QString(documentPath)); QCOMPARE(rootChanged.count(), oldRootPath == model->rootPath() ? 0 : 1); - QCOMPARE(model->rootDirectory().absolutePath(), QDir::homePath()); + QCOMPARE(model->rootDirectory().absolutePath(), documentPath); model->setRootPath(QDir::rootPath()); int oldCount = rootChanged.count(); oldRootPath = model->rootPath(); - root = model->setRootPath(QDir::homePath() + QLatin1String("/.")); + root = model->setRootPath(documentPath + QLatin1String("/.")); QTRY_VERIFY(model->rowCount(root) >= 0); - QCOMPARE(model->rootPath(), QDir::homePath()); + QCOMPARE(model->rootPath(), documentPath); QCOMPARE(rootChanged.count(), oldRootPath == model->rootPath() ? oldCount : oldCount + 1); - QCOMPARE(model->rootDirectory().absolutePath(), QDir::homePath()); + QCOMPARE(model->rootDirectory().absolutePath(), documentPath); - QDir newdir = QDir::home(); + QDir newdir = documentPath; if (newdir.cdUp()) { oldCount = rootChanged.count(); oldRootPath = model->rootPath(); - root = model->setRootPath(QDir::homePath() + QLatin1String("/..")); + root = model->setRootPath(documentPath + QLatin1String("/..")); QTRY_VERIFY(model->rowCount(root) >= 0); QCOMPARE(model->rootPath(), newdir.path()); QCOMPARE(rootChanged.count(), oldCount + 1); @@ -310,9 +315,9 @@ void tst_QFileSystemModel::naturalCompare() void tst_QFileSystemModel::readOnly() { QCOMPARE(model->isReadOnly(), true); - QTemporaryFile file; + QTemporaryFile file(flatDirTestPath + QStringLiteral("/XXXXXX.dat")); file.open(); - QModelIndex root = model->setRootPath(QDir::tempPath()); + QModelIndex root = model->setRootPath(flatDirTestPath); QTRY_VERIFY(model->rowCount(root) > 0); QVERIFY(!(model->flags(model->index(file.fileName())) & Qt::ItemIsEditable)); @@ -358,7 +363,10 @@ void tst_QFileSystemModel::iconProvider() delete p; QFileSystemModel *myModel = new QFileSystemModel(); - myModel->setRootPath(QDir::homePath()); + const QStringList documentPaths = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation); + QVERIFY(!documentPaths.isEmpty()); + const QString documentPath = documentPaths.front(); + myModel->setRootPath(documentPath); //Let's wait to populate the model QTest::qWait(250); //We change the provider, icons must me updated @@ -791,6 +799,19 @@ void tst_QFileSystemModel::setData() QTRY_COMPARE(model->rowCount(root), files.count()); } +void tst_QFileSystemModel::sortPersistentIndex() +{ + QTemporaryFile file(flatDirTestPath + QStringLiteral("/XXXXXX.dat")); + file.open(); + QModelIndex root = model->setRootPath(flatDirTestPath); + QTRY_VERIFY(model->rowCount(root) > 0); + + QPersistentModelIndex idx = model->index(0, 1, root); + model->sort(0, Qt::AscendingOrder); + model->sort(0, Qt::DescendingOrder); + QVERIFY(idx.column() != 0); +} + class MyFriendFileSystemModel : public QFileSystemModel { friend class tst_QFileSystemModel; @@ -806,18 +827,6 @@ void tst_QFileSystemModel::sort_data() void tst_QFileSystemModel::sort() { - QTemporaryFile file; - file.open(); - QModelIndex root = model->setRootPath(QDir::tempPath()); - QTRY_VERIFY(model->rowCount(root) > 0); - - QPersistentModelIndex idx = model->index(0, 1, root); - model->sort(0, Qt::AscendingOrder); - model->sort(0, Qt::DescendingOrder); - QVERIFY(idx.column() != 0); - - model->setRootPath(QDir::homePath()); - QFETCH(bool, fileDialogMode); MyFriendFileSystemModel *myModel = new MyFriendFileSystemModel(); diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index b14e68951b..56cf27155d 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -424,6 +424,7 @@ private slots: void activate(); void setActivePanelOnInactiveScene(); void activationOnShowHide(); + void deactivateInactivePanel(); void moveWhileDeleting(); void ensureDirtySceneTransform(); void focusScope(); @@ -2204,7 +2205,6 @@ void tst_QGraphicsItem::sceneMatrix() void tst_QGraphicsItem::setMatrix() { QGraphicsScene scene; - qRegisterMetaType<QList<QRectF> >("QList<QRectF>"); QSignalSpy spy(&scene, SIGNAL(changed(QList<QRectF>))); QRectF unrotatedRect(-12, -34, 56, 78); QGraphicsRectItem item(unrotatedRect, 0); @@ -9030,6 +9030,40 @@ public: } }; +void tst_QGraphicsItem::deactivateInactivePanel() +{ + QGraphicsScene scene; + QGraphicsItem *panel1 = scene.addRect(QRectF(0, 0, 10, 10)); + panel1->setFlag(QGraphicsItem::ItemIsPanel); + + QGraphicsItem *panel2 = scene.addRect(QRectF(0, 0, 10, 10)); + panel2->setFlag(QGraphicsItem::ItemIsPanel); + + QEvent event(QEvent::WindowActivate); + qApp->sendEvent(&scene, &event); + + panel1->setActive(true); + QVERIFY(scene.isActive()); + QVERIFY(panel1->isActive()); + QVERIFY(!panel2->isActive()); + QCOMPARE(scene.activePanel(), panel1); + + panel2->setActive(true); + QVERIFY(panel2->isActive()); + QVERIFY(!panel1->isActive()); + QCOMPARE(scene.activePanel(), panel2); + + panel2->setActive(false); + QVERIFY(panel1->isActive()); + QVERIFY(!panel2->isActive()); + QCOMPARE(scene.activePanel(), panel1); + + panel2->setActive(false); + QVERIFY(panel1->isActive()); + QVERIFY(!panel2->isActive()); + QCOMPARE(scene.activePanel(), panel1); +} + void tst_QGraphicsItem::moveWhileDeleting() { QGraphicsScene scene; @@ -10333,23 +10367,24 @@ void tst_QGraphicsItem::modality_clickFocus() EventSpy2 rect1Spy(&scene, rect1); EventSpy2 rect2Spy(&scene, rect2); - // activate rect1, it should not get focus + // activate rect1, it should get focus rect1->setActive(true); - QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0); + QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1); - // focus stays unset when rect2 becomes modal + // focus stays when rect2 becomes modal rect2->setPanelModality(QGraphicsItem::SceneModal); - QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); + QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1); + QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1); QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 0); QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 0); // clicking on rect1 should not set it's focus item + rect1->clearFocus(); sendMouseClick(&scene, QPointF(-25, -25)); QCOMPARE(rect1->focusItem(), (QGraphicsItem *) 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); + QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1); + QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 0); QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 0); @@ -10357,33 +10392,34 @@ void tst_QGraphicsItem::modality_clickFocus() rect2->setActive(true); sendMouseClick(&scene, QPointF(75, 75)); QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect2); - QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); + QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1); + QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 0); // clicking on rect1 does *not* give it focus rect1->setActive(true); + rect1->clearFocus(); sendMouseClick(&scene, QPointF(-25, -25)); QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); + QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 2); + QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 2); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 1); // focus doesn't change when leaving modality either rect2->setPanelModality(QGraphicsItem::NonModal); QCOMPARE(scene.focusItem(), (QGraphicsItem *) 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 0); - QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); + QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 2); + QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 2); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 1); // click on rect1, it should get focus now sendMouseClick(&scene, QPointF(-25, -25)); QCOMPARE(scene.focusItem(), (QGraphicsItem *) rect1); - QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 1); - QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 0); + QCOMPARE(rect1Spy.counts[QEvent::FocusIn], 3); + QCOMPARE(rect1Spy.counts[QEvent::FocusOut], 2); QCOMPARE(rect2Spy.counts[QEvent::FocusIn], 1); QCOMPARE(rect2Spy.counts[QEvent::FocusOut], 1); } diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 7a5f7319bc..b80c00e88e 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -266,6 +266,7 @@ private slots: void siblingIndexAlwaysValid(); void removeFullyTransparentItem(); void zeroScale(); + void focusItemChangedSignal(); // task specific tests below me void task139710_bspTreeCrash(); @@ -3883,11 +3884,11 @@ void tst_QGraphicsScene::initialFocus_data() QTest::addColumn<bool>("shouldHaveFocus"); QTest::newRow("inactive scene, normal item") << false << false << false << false; - QTest::newRow("inactive scene, panel item") << false << false << true << false; + QTest::newRow("inactive scene, panel item") << false << false << true << true; QTest::newRow("inactive scene, normal item, explicit focus") << false << true << false << true; QTest::newRow("inactive scene, panel, explicit focus") << false << true << true << true; QTest::newRow("active scene, normal item") << true << false << false << false; - QTest::newRow("active scene, panel item") << true << false << true << false; + QTest::newRow("active scene, panel item") << true << false << true << true; QTest::newRow("active scene, normal item, explicit focus") << true << true << false << true; QTest::newRow("active scene, panel, explicit focus") << true << true << true << true; } @@ -4561,6 +4562,119 @@ void tst_QGraphicsScene::zeroScale() QTRY_COMPARE(cl.changes.count(), 2); } +void tst_QGraphicsScene::focusItemChangedSignal() +{ + qRegisterMetaType<QGraphicsItem *>("QGraphicsItem *"); + qRegisterMetaType<Qt::FocusReason>("Qt::FocusReason"); + + QGraphicsScene scene; + QSignalSpy spy(&scene, SIGNAL(focusItemChanged(QGraphicsItem *, QGraphicsItem *, Qt::FocusReason))); + QVERIFY(spy.isValid()); + QCOMPARE(spy.count(), 0); + scene.setFocus(); + QCOMPARE(spy.count(), 0); + QEvent activateEvent(QEvent::WindowActivate); + qApp->sendEvent(&scene, &activateEvent); + QCOMPARE(spy.count(), 0); + + QGraphicsRectItem *topLevelItem1 = new QGraphicsRectItem; + topLevelItem1->setFlag(QGraphicsItem::ItemIsFocusable); + scene.addItem(topLevelItem1); + QCOMPARE(spy.count(), 0); + QVERIFY(!topLevelItem1->hasFocus()); + + QGraphicsRectItem *topLevelItem2 = new QGraphicsRectItem; + topLevelItem2->setFlag(QGraphicsItem::ItemIsFocusable); + topLevelItem2->setFocus(); + QVERIFY(!topLevelItem2->hasFocus()); + scene.addItem(topLevelItem2); + QCOMPARE(spy.count(), 1); + QList<QVariant> arguments = spy.takeFirst(); + QCOMPARE(arguments.size(), 3); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)0); + QCOMPARE(qVariantValue<Qt::FocusReason>(arguments.at(2)), Qt::OtherFocusReason); + QVERIFY(topLevelItem2->hasFocus()); + + scene.clearFocus(); + QCOMPARE(spy.count(), 1); + arguments = spy.takeFirst(); + QCOMPARE(arguments.size(), 3); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)0); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qVariantValue<Qt::FocusReason>(arguments.at(2)), Qt::OtherFocusReason); + + scene.setFocus(Qt::MenuBarFocusReason); + QCOMPARE(spy.count(), 1); + arguments = spy.takeFirst(); + QCOMPARE(arguments.size(), 3); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)0); + QCOMPARE(qVariantValue<Qt::FocusReason>(arguments.at(2)), Qt::MenuBarFocusReason); + + for (int i = 0; i < 3; ++i) { + topLevelItem1->setFocus(Qt::TabFocusReason); + arguments = spy.takeFirst(); + QCOMPARE(arguments.size(), 3); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)topLevelItem1); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qVariantValue<Qt::FocusReason>(arguments.at(2)), Qt::TabFocusReason); + + topLevelItem2->setFocus(Qt::TabFocusReason); + arguments = spy.takeFirst(); + QCOMPARE(arguments.size(), 3); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)topLevelItem1); + QCOMPARE(qVariantValue<Qt::FocusReason>(arguments.at(2)), Qt::TabFocusReason); + } + + // The following two are unexpected, but fixing this (i.e., losing and gaining focus + // when the scene activation changes) breaks quite a few tests so leave this fix + // for some future release. See QTBUG-28346. + QEvent deactivateEvent(QEvent::WindowDeactivate); + qApp->sendEvent(&scene, &deactivateEvent); + QEXPECT_FAIL("", "QTBUG-28346", Continue); + QCOMPARE(spy.count(), 1); + qApp->sendEvent(&scene, &activateEvent); + QEXPECT_FAIL("", "QTBUG-28346", Continue); + QCOMPARE(spy.count(), 1); + + QGraphicsRectItem *panel1 = new QGraphicsRectItem; + panel1->setFlags(QGraphicsItem::ItemIsPanel | QGraphicsItem::ItemIsFocusable); + panel1->setFocus(); + scene.addItem(panel1); + QCOMPARE(spy.count(), 1); + arguments = spy.takeFirst(); + QCOMPARE(arguments.size(), 3); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)panel1); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)topLevelItem2); + QCOMPARE(qVariantValue<Qt::FocusReason>(arguments.at(2)), Qt::ActiveWindowFocusReason); + + QGraphicsRectItem *panel2 = new QGraphicsRectItem; + panel2->setFlags(QGraphicsItem::ItemIsPanel | QGraphicsItem::ItemIsFocusable); + scene.addItem(panel2); + QCOMPARE(spy.count(), 0); + + for (int i = 0; i < 3; ++i) { + scene.setActivePanel(panel2); + QCOMPARE(spy.count(), 1); + arguments = spy.takeFirst(); + QCOMPARE(arguments.size(), 3); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)panel2); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)panel1); + QCOMPARE(qVariantValue<Qt::FocusReason>(arguments.at(2)), Qt::ActiveWindowFocusReason); + + scene.setActivePanel(panel1); + QCOMPARE(spy.count(), 1); + arguments = spy.takeFirst(); + QCOMPARE(arguments.size(), 3); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(0)), (QGraphicsItem *)panel1); + QCOMPARE(qVariantValue<QGraphicsItem *>(arguments.at(1)), (QGraphicsItem *)panel2); + QCOMPARE(qVariantValue<Qt::FocusReason>(arguments.at(2)), Qt::ActiveWindowFocusReason); + } + +} + void tst_QGraphicsScene::taskQTBUG_15977_renderWithDeviceCoordinateCache() { QGraphicsScene scene; diff --git a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp index 69665572f7..4cfdfccd63 100644 --- a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp @@ -172,12 +172,12 @@ private slots: void initialShow2(); void itemChangeEvents(); void itemSendGeometryPosChangesDeactivated(); - void fontPropagatesResolveToChildren(); void fontPropagatesResolveToGrandChildren(); void fontPropagatesResolveInParentChange(); void fontPropagatesResolveViaNonWidget(); void fontPropagatesResolveFromScene(); + void tabFocus(); // Task fixes void task236127_bspTreeIndexFails(); @@ -3302,6 +3302,103 @@ void tst_QGraphicsWidget::itemSendGeometryPosChangesDeactivated() QCOMPARE(item->geometry(), QRectF(10, 10, 60, 60)); } +class TabFocusWidget : public QGraphicsWidget +{ + Q_OBJECT +public: + TabFocusWidget(const QString &name, QGraphicsItem *parent = 0) + : QGraphicsWidget(parent) + { setFocusPolicy(Qt::TabFocus); setData(0, name); } +}; + +void verifyTabFocus(QGraphicsScene *scene, const QList<QGraphicsWidget *> &chain, bool wrapsAround) +{ + QKeyEvent tabEvent(QEvent::KeyPress, Qt::Key_Tab, 0); + QKeyEvent backtabEvent(QEvent::KeyPress, Qt::Key_Backtab, 0); + + for (int i = 0; i < chain.size(); ++i) + chain.at(i)->clearFocus(); + + int n = chain.size() * (wrapsAround ? 3 : 1); + for (int i = 0; i < n; ++i) + { + qApp->sendEvent(scene, &tabEvent); + QVERIFY(chain.at(i % chain.size())->hasFocus()); + QCOMPARE(scene->focusItem(), chain.at(i % chain.size())); + } + for (int i = n - 2; i >= 0; --i) + { + qApp->sendEvent(scene, &backtabEvent); + QVERIFY(chain.at(i % chain.size())->hasFocus()); + QCOMPARE(scene->focusItem(), chain.at(i % chain.size())); + } +} + +void tst_QGraphicsWidget::tabFocus() +{ + QGraphicsScene scene; + scene.setFocus(); + + QEvent activate(QEvent::WindowActivate); + qApp->sendEvent(&scene, &activate); + + TabFocusWidget *widget = new TabFocusWidget("1"); + scene.addItem(widget); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget, false); + + TabFocusWidget *widget2 = new TabFocusWidget("2"); + scene.addItem(widget2); + scene.setFocusItem(0); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget << widget2, false); + + TabFocusWidget *widget3 = new TabFocusWidget("3"); + widget3->setFlag(QGraphicsItem::ItemIsPanel); + scene.addItem(widget3); + QCOMPARE(scene.activePanel(), (QGraphicsItem *)widget3); + scene.setActivePanel(0); + scene.setFocusItem(0); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget << widget2, false); + + scene.setActivePanel(widget3); + QCOMPARE(scene.focusItem(), (QGraphicsItem *)widget3); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3, true); + + TabFocusWidget *widget4 = new TabFocusWidget("4"); + widget4->setParentItem(widget3); + QVERIFY(widget3->hasFocus()); + widget3->clearFocus(); + QVERIFY(!widget3->focusItem()); + QCOMPARE(scene.activePanel(), (QGraphicsItem *)widget3); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4, true); + + QGraphicsWidget *widget5 = new QGraphicsWidget; widget5->setData(0, QLatin1String("5")); + widget5->setParentItem(widget3); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4, true); + + widget5->setFocusPolicy(Qt::TabFocus); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget5, true); + + TabFocusWidget *widget6 = new TabFocusWidget("6"); + widget6->setParentItem(widget4); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget6 << widget5, true); + + TabFocusWidget *widget7 = new TabFocusWidget("7", widget6); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget6 << widget7 << widget5, true); + + TabFocusWidget *widget8 = new TabFocusWidget("8", widget6); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget6 << widget7 << widget8 << widget5, true); + widget6->setFlag(QGraphicsItem::ItemIsPanel); + widget6->setActive(true); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget6 << widget7 << widget8, true); + widget3->setActive(true); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget5, true); + widget6->setFlag(QGraphicsItem::ItemIsPanel, false); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget6 << widget7 << widget8 << widget5, true); + scene.removeItem(widget6); + verifyTabFocus(&scene, QList<QGraphicsWidget *>() << widget3 << widget4 << widget5, true); + delete widget6; +} + void tst_QGraphicsWidget::QT_BUG_6544_tabFocusFirstUnsetWhenRemovingItems() { QGraphicsScene scene; diff --git a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp index 2d95c9d3a4..f0731eb3a6 100644 --- a/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp +++ b/tests/auto/widgets/itemviews/qabstractitemview/tst_qabstractitemview.cpp @@ -235,6 +235,8 @@ private slots: void testDelegateDestroyEditor(); void testClickedSignal(); void testChangeEditorState(); + void deselectInSingleSelection(); + void testNoActivateOnDisabledItem(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -1599,5 +1601,70 @@ void tst_QAbstractItemView::testChangeEditorState() // No segfault - the test passes. } +void tst_QAbstractItemView::deselectInSingleSelection() +{ + QTableView view; + QStandardItemModel s; + s.setRowCount(10); + s.setColumnCount(10); + view.setModel(&s); + view.show(); + view.setSelectionMode(QAbstractItemView::SingleSelection); + view.setEditTriggers(QAbstractItemView::NoEditTriggers); + QApplication::setActiveWindow(&view); + QVERIFY(QTest::qWaitForWindowExposed(&view)); + // mouse + QModelIndex index22 = s.index(2, 2); + QRect rect22 = view.visualRect(index22); + QPoint clickpos = rect22.center(); + QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::NoModifier, clickpos); + QCOMPARE(view.currentIndex(), index22); + QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1); + QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, clickpos); + QCOMPARE(view.currentIndex(), index22); + QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0); + + // second click with modifier however does select + QTest::mouseClick(view.viewport(), Qt::LeftButton, Qt::ControlModifier, clickpos); + QCOMPARE(view.currentIndex(), index22); + QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1); + + // keyboard + QTest::keyClick(&view, Qt::Key_Space, Qt::NoModifier); + QCOMPARE(view.currentIndex(), index22); + QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1); + QTest::keyClick(&view, Qt::Key_Space, Qt::ControlModifier); + QCOMPARE(view.currentIndex(), index22); + QCOMPARE(view.selectionModel()->selectedIndexes().count(), 0); + + // second keypress with modifier however does select + QTest::keyClick(&view, Qt::Key_Space, Qt::ControlModifier); + QCOMPARE(view.currentIndex(), index22); + QCOMPARE(view.selectionModel()->selectedIndexes().count(), 1); +} + +void tst_QAbstractItemView::testNoActivateOnDisabledItem() +{ + QTreeView treeView; + QStandardItemModel model(1, 1); + QStandardItem *item = new QStandardItem("item"); + model.setItem(0, 0, item); + item->setFlags(Qt::NoItemFlags); + treeView.setModel(&model); + treeView.show(); + + QApplication::setActiveWindow(&treeView); + QVERIFY(QTest::qWaitForWindowActive(&treeView)); + + QSignalSpy activatedSpy(&treeView, SIGNAL(activated(QModelIndex))); + + // Ensure clicking on a disabled item doesn't emit itemActivated. + QModelIndex itemIndex = treeView.model()->index(0, 0); + QPoint clickPos = treeView.visualRect(itemIndex).center(); + QTest::mouseClick(treeView.viewport(), Qt::LeftButton, 0, clickPos); + + QCOMPARE(activatedSpy.count(), 0); +} + QTEST_MAIN(tst_QAbstractItemView) #include "tst_qabstractitemview.moc" diff --git a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp index 0f69e951bf..d914142e13 100644 --- a/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp +++ b/tests/auto/widgets/itemviews/qtreeview/tst_qtreeview.cpp @@ -177,6 +177,7 @@ private slots: void emptyModel(); void removeRows(); void removeCols(); + void limitedExpand(); void expandAndCollapse_data(); void expandAndCollapse(); void expandAndCollapseAll(); @@ -256,6 +257,7 @@ private slots: void taskQTBUG_13567_removeLastItemRegression(); void taskQTBUG_25333_adjustViewOptionsForIndex(); void taskQTBUG_18539_emitLayoutChanged(); + void taskQTBUG_8176_emitOnExpandAll(); }; class QtTestModel: public QAbstractItemModel @@ -1414,6 +1416,45 @@ void tst_QTreeView::removeCols() QCOMPARE(view.header()->count(), model.cols); } +void tst_QTreeView::limitedExpand() +{ + { + QStandardItemModel model; + QStandardItem *parentItem = model.invisibleRootItem(); + parentItem->appendRow(new QStandardItem); + parentItem->appendRow(new QStandardItem); + parentItem->appendRow(new QStandardItem); + + QStandardItem *firstItem = model.item(0, 0); + firstItem->setFlags(firstItem->flags() | Qt::ItemNeverHasChildren); + + QTreeView view; + view.setModel(&model); + + QSignalSpy spy(&view, SIGNAL(expanded(QModelIndex))); + QVERIFY(spy.isValid()); + + view.expand(model.index(0, 0)); + QCOMPARE(spy.count(), 0); + + view.expand(model.index(1, 0)); + QCOMPARE(spy.count(), 1); + } + { + QStringListModel model(QStringList() << "one" << "two"); + QTreeView view; + view.setModel(&model); + + QSignalSpy spy(&view, SIGNAL(expanded(QModelIndex))); + QVERIFY(spy.isValid()); + + view.expand(model.index(0, 0)); + QCOMPARE(spy.count(), 0); + view.expandAll(); + QCOMPARE(spy.count(), 0); + } +} + void tst_QTreeView::expandAndCollapse_data() { QTest::addColumn<bool>("animationEnabled"); @@ -1581,13 +1622,10 @@ void tst_QTreeView::expandAndCollapseAll() for (int r = 0; r < rows; ++r) parents.push(model.index(r, 0, p)); } -// ### why is expanded() signal not emitted? -// QCOMPARE(expandedSpy.count(), count); + QCOMPARE(expandedSpy.count(), 12); // == (3+1)*(2+1) from QtTestModel model(3, 2); view.collapseAll(); - QCOMPARE(expandedSpy.count(), 0); - parents.push(QModelIndex()); count = 0; while (!parents.isEmpty()) { @@ -1599,8 +1637,7 @@ void tst_QTreeView::expandAndCollapseAll() for (int r = 0; r < rows; ++r) parents.push(model.index(r, 0, p)); } -// ### why is collapsed() signal not emitted? -// QCOMPARE(collapsedSpy.count(), count); + QCOMPARE(collapsedSpy.count(), 12); } void tst_QTreeView::expandWithNoChildren() @@ -4158,6 +4195,47 @@ void tst_QTreeView::taskQTBUG_18539_emitLayoutChanged() QCOMPARE(afterRISpy.size(), 0); } +void tst_QTreeView::taskQTBUG_8176_emitOnExpandAll() +{ + QTreeWidget tw; + QTreeWidgetItem *item = new QTreeWidgetItem(&tw, QStringList(QString("item 1"))); + QTreeWidgetItem *item2 = new QTreeWidgetItem(item, QStringList(QString("item 2"))); + new QTreeWidgetItem(item2, QStringList(QString("item 3"))); + new QTreeWidgetItem(item2, QStringList(QString("item 4"))); + QTreeWidgetItem *item5 = new QTreeWidgetItem(&tw, QStringList(QString("item 5"))); + new QTreeWidgetItem(item5, QStringList(QString("item 6"))); + QSignalSpy spy(&tw, SIGNAL(expanded(const QModelIndex&))); + + // expand all + tw.expandAll(); + QCOMPARE(spy.size(), 6); + spy.clear(); + tw.collapseAll(); + item2->setExpanded(true); + spy.clear(); + tw.expandAll(); + QCOMPARE(spy.size(), 5); + + // collapse all + QSignalSpy spy2(&tw, SIGNAL(collapsed(const QModelIndex&))); + tw.collapseAll(); + QCOMPARE(spy2.size(), 6); + tw.expandAll(); + item2->setExpanded(false); + spy2.clear(); + tw.collapseAll(); + QCOMPARE(spy2.size(), 5); + + // expand to depth + item2->setExpanded(true); + spy.clear(); + spy2.clear(); + tw.expandToDepth(0); + + QCOMPARE(spy.size(), 2); // item and item5 are expanded + QCOMPARE(spy2.size(), 1); // item2 is collapsed +} + #ifndef QT_NO_ANIMATION void tst_QTreeView::quickExpandCollapse() { diff --git a/tests/auto/widgets/kernel/kernel.pro b/tests/auto/widgets/kernel/kernel.pro index b280f44f05..20720dc928 100644 --- a/tests/auto/widgets/kernel/kernel.pro +++ b/tests/auto/widgets/kernel/kernel.pro @@ -15,6 +15,7 @@ SUBDIRS=\ qwidgetaction \ qwidgetmetatype \ qwidgetsvariant \ + qwindowcontainer \ qshortcut \ qsizepolicy diff --git a/tests/auto/widgets/kernel/qwindowcontainer/.gitignore b/tests/auto/widgets/kernel/qwindowcontainer/.gitignore new file mode 100644 index 0000000000..038f477220 --- /dev/null +++ b/tests/auto/widgets/kernel/qwindowcontainer/.gitignore @@ -0,0 +1 @@ +tst_qwindowcontainer diff --git a/tests/auto/widgets/kernel/qwindowcontainer/qwindowcontainer.pro b/tests/auto/widgets/kernel/qwindowcontainer/qwindowcontainer.pro new file mode 100644 index 0000000000..4ff05eb04a --- /dev/null +++ b/tests/auto/widgets/kernel/qwindowcontainer/qwindowcontainer.pro @@ -0,0 +1,6 @@ +CONFIG += testcase +mac:CONFIG -= app_bundle +# CONFIG += parallel_test // Cannot be parallel due to the activation test +TARGET = tst_qwindowcontainer +QT += widgets testlib +SOURCES += tst_qwindowcontainer.cpp diff --git a/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp b/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp new file mode 100644 index 0000000000..440639cd49 --- /dev/null +++ b/tests/auto/widgets/kernel/qwindowcontainer/tst_qwindowcontainer.cpp @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtTest/QtTest> + +#include <qapplication.h> +#include <qwindow.h> +#include <qwidget.h> + + + +class Window : public QWindow +{ +public: + Window() + : numberOfExposes(0) + , numberOfObscures(0) + { + } + + void exposeEvent(QExposeEvent *) { + if (isExposed()) + ++numberOfExposes; + else + ++numberOfObscures; + } + + int numberOfExposes; + int numberOfObscures; +}; + + + +class tst_QWindowContainer: public QObject +{ + Q_OBJECT +private slots: + void testShow(); + void testPositionAndSize(); + void testExposeObscure(); + void testOwnership(); + void testBehindTheScenesDeletion(); + void testUnparenting(); + void testActivation(); +}; + + + +void tst_QWindowContainer::testShow() +{ + QWidget root; + root.setGeometry(100, 100, 400, 400); + + Window *window = new Window(); + QWidget *container = QWidget::createWindowContainer(window, &root); + + container->setGeometry(50, 50, 200, 200); + + root.show(); + + QVERIFY(QTest::qWaitForWindowExposed(window)); +} + + + +void tst_QWindowContainer::testPositionAndSize() +{ + QWindow *window = new QWindow(); + window->setGeometry(300, 400, 500, 600); + + QWidget *container = QWidget::createWindowContainer(window); + container->setGeometry(50, 50, 200, 200); + + + container->show(); + QVERIFY(QTest::qWaitForWindowExposed(container)); + + QCOMPARE(window->x(), 0); + QCOMPARE(window->y(), 0); + QCOMPARE(window->width(), container->width()); + QCOMPARE(window->height(), container->height()); +} + + + +void tst_QWindowContainer::testExposeObscure() +{ + Window *window = new Window(); + + QWidget *container = QWidget::createWindowContainer(window); + container->setGeometry(50, 50, 200, 200); + + container->show(); + QVERIFY(QTest::qWaitForWindowExposed(container)); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QVERIFY(window->numberOfExposes > 0); + + container->hide(); + + QElapsedTimer timer; + timer.start(); + while (window->numberOfObscures == 0 && timer.elapsed() < 5000) { + QTest::qWait(10); + } + + QVERIFY(window->numberOfObscures > 0); +} + + + +void tst_QWindowContainer::testOwnership() +{ + QPointer<QWindow> window(new QWindow()); + QWidget *container = QWidget::createWindowContainer(window); + + delete container; + + QCOMPARE(window.data(), (QWindow *) 0); +} + + + +void tst_QWindowContainer::testBehindTheScenesDeletion() +{ + QWindow *window = new QWindow(); + QWidget *container = QWidget::createWindowContainer(window); + + delete window; + + // The child got removed, showing not should not have any side effects, + // such as for instance, crashing... + container->show(); + QVERIFY(QTest::qWaitForWindowExposed(container)); + delete container; +} + + + +void tst_QWindowContainer::testActivation() +{ + QWidget root; + + QWindow *window = new QWindow(); + QWidget *container = QWidget::createWindowContainer(window, &root); + + container->setGeometry(100, 100, 200, 100); + root.setGeometry(100, 100, 400, 300); + + root.show(); + root.activateWindow(); + + QVERIFY(QTest::qWaitForWindowActive(root.windowHandle())); + QVERIFY(QGuiApplication::focusWindow() == root.windowHandle()); + + // Under KDE (ubuntu 12.10), we experience that doing two activateWindow in a row + // does not work. The second gets ignored by the window manager, even though the + // timestamp in the xcb connection is unique for both. + if (QGuiApplication::platformName() == "xcb") + QTest::qWait(100); + + window->requestActivate(); + QVERIFY(QTest::qWaitForWindowActive(window)); + QVERIFY(QGuiApplication::focusWindow() == window); +} + + + +void tst_QWindowContainer::testUnparenting() +{ + QWindow *window = new QWindow(); + QWidget *container = QWidget::createWindowContainer(window); + container->setGeometry(100, 100, 200, 100); + + window->setParent(0); + + container->show(); + + QVERIFY(QTest::qWaitForWindowExposed(container)); + + // Window should not be made visible by container.. + QVERIFY(!window->isVisible()); +} + +QTEST_MAIN(tst_QWindowContainer) + +#include "tst_qwindowcontainer.moc" diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp index 9ecb0650c5..e7d62f8c0c 100644 --- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp +++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp @@ -316,7 +316,6 @@ void tst_QDateTimeEdit::getSetCheck() tst_QDateTimeEdit::tst_QDateTimeEdit() { - qRegisterMetaType<QList<int> >("QList<int>"); } tst_QDateTimeEdit::~tst_QDateTimeEdit() @@ -759,6 +758,11 @@ void tst_QDateTimeEdit::displayFormat() void tst_QDateTimeEdit::selectAndScrollWithKeys() { +#ifdef Q_OS_MAC + QSKIP("QTBUG-23674"); + return; +#endif + qApp->setActiveWindow(testWidget); testWidget->setDate(QDate(2004, 05, 11)); testWidget->setDisplayFormat("dd/MM/yyyy"); @@ -769,9 +773,6 @@ void tst_QDateTimeEdit::selectAndScrollWithKeys() QTest::keyClick(testWidget, Qt::Key_Home); #endif QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier); -#ifdef Q_OS_MAC - QEXPECT_FAIL("", "QTBUG-23674", Abort); -#endif QCOMPARE(testWidget->lineEdit()->selectedText(), QString("1")); QTest::keyClick(testWidget, Qt::Key_Right, Qt::ShiftModifier); QCOMPARE(testWidget->lineEdit()->selectedText(), QString("11")); diff --git a/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp b/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp index c7c9980f13..59be9bd659 100644 --- a/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp +++ b/tests/auto/widgets/widgets/qdialogbuttonbox/tst_qdialogbuttonbox.cpp @@ -68,8 +68,8 @@ public slots: private slots: void standardButtons(); void testConstructor1(); - void testConstrurtor2(); - void testConstrurtor2_data(); + void testConstructor2(); + void testConstructor2_data(); void testConstructor3(); void testConstructor3_data(); void setOrientation_data(); @@ -146,7 +146,7 @@ void tst_QDialogButtonBox::layoutReuse() delete box; } -void tst_QDialogButtonBox::testConstrurtor2_data() +void tst_QDialogButtonBox::testConstructor2_data() { QTest::addColumn<int>("orientation"); @@ -154,7 +154,7 @@ void tst_QDialogButtonBox::testConstrurtor2_data() QTest::newRow("vertical") << int(Qt::Vertical); } -void tst_QDialogButtonBox::testConstrurtor2() +void tst_QDialogButtonBox::testConstructor2() { QFETCH(int, orientation); Qt::Orientation orient = Qt::Orientation(orientation); diff --git a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp index 354ccea06c..519aa61061 100644 --- a/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp +++ b/tests/auto/widgets/widgets/qmenubar/tst_qmenubar.cpp @@ -1122,7 +1122,6 @@ void tst_QMenuBar::check_menuPosition() void tst_QMenuBar::task223138_triggered() { - qRegisterMetaType<QAction *>("QAction *"); //we create a window with submenus and we check that both menubar and menus get the triggered signal QMainWindow win; QMenu *menu = win.menuBar()->addMenu("test"); diff --git a/tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.h b/tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.h index 3c23a4d85b..d59678823d 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.h +++ b/tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.h @@ -44,8 +44,6 @@ #include <QtCore/qdir.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -93,6 +91,4 @@ Q_DECLARE_OPERATORS_FOR_FLAGS(QFileSystemIterator::IteratorFlags) QT_END_NAMESPACE -QT_END_HEADER - #endif diff --git a/tests/benchmarks/corelib/tools/qvector/qrawvector.h b/tests/benchmarks/corelib/tools/qvector/qrawvector.h index 1bfc107d39..3f0d72a231 100644 --- a/tests/benchmarks/corelib/tools/qvector/qrawvector.h +++ b/tests/benchmarks/corelib/tools/qvector/qrawvector.h @@ -55,8 +55,6 @@ #include <stdlib.h> #include <string.h> -QT_BEGIN_HEADER - QT_BEGIN_NAMESPACE @@ -752,6 +750,4 @@ Q_DECLARE_MUTABLE_SEQUENTIAL_ITERATOR(RawVector) QT_END_NAMESPACE -QT_END_HEADER - #endif // QRAWVECTOR_H diff --git a/tests/manual/dialogs/colordialogpanel.cpp b/tests/manual/dialogs/colordialogpanel.cpp new file mode 100644 index 0000000000..695e37a4c7 --- /dev/null +++ b/tests/manual/dialogs/colordialogpanel.cpp @@ -0,0 +1,261 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "colordialogpanel.h" + +#include <QGroupBox> +#include <QCheckBox> +#include <QPushButton> +#include <QVBoxLayout> +#include <QHBoxLayout> +#include <QMessageBox> +#include <QSortFilterProxyModel> +#include <QComboBox> +#include <QTimer> +#include <QDebug> + +// SVG color keyword names provided by the World Wide Web Consortium +static inline QStringList svgColorNames() +{ + return QStringList() + << "aliceblue" << "antiquewhite" << "aqua" << "aquamarine" << "azure" << "beige" << "bisque" + << "black" << "blanchedalmond" << "blue" << "blueviolet" << "brown" << "burlywood" << "cadetblue" + << "chartreuse" << "chocolate" << "coral" << "cornflowerblue" << "cornsilk" << "crimson" << "cyan" + << "darkblue" << "darkcyan" << "darkgoldenrod" << "darkgray" << "darkgreen" << "darkgrey" + << "darkkhaki" << "darkmagenta" << "darkolivegreen" << "darkorange" << "darkorchid" << "darkred" + << "darksalmon" << "darkseagreen" << "darkslateblue" << "darkslategray" << "darkslategrey" + << "darkturquoise" << "darkviolet" << "deeppink" << "deepskyblue" << "dimgray" << "dimgrey" + << "dodgerblue" << "firebrick" << "floralwhite" << "forestgreen" << "fuchsia" << "gainsboro" + << "ghostwhite" << "gold" << "goldenrod" << "gray" << "grey" << "green" << "greenyellow" + << "honeydew" << "hotpink" << "indianred" << "indigo" << "ivory" << "khaki" << "lavender" + << "lavenderblush" << "lawngreen" << "lemonchiffon" << "lightblue" << "lightcoral" << "lightcyan" + << "lightgoldenrodyellow" << "lightgray" << "lightgreen" << "lightgrey" << "lightpink" + << "lightsalmon" << "lightseagreen" << "lightskyblue" << "lightslategray" << "lightslategrey" + << "lightsteelblue" << "lightyellow" << "lime" << "limegreen" << "linen" << "magenta" + << "maroon" << "mediumaquamarine" << "mediumblue" << "mediumorchid" << "mediumpurple" + << "mediumseagreen" << "mediumslateblue" << "mediumspringgreen" << "mediumturquoise" + << "mediumvioletred" << "midnightblue" << "mintcream" << "mistyrose" << "moccasin" + << "navajowhite" << "navy" << "oldlace" << "olive" << "olivedrab" << "orange" << "orangered" + << "orchid" << "palegoldenrod" << "palegreen" << "paleturquoise" << "palevioletred" + << "papayawhip" << "peachpuff" << "peru" << "pink" << "plum" << "powderblue" << "purple" << "red" + << "rosybrown" << "royalblue" << "saddlebrown" << "salmon" << "sandybrown" << "seagreen" + << "seashell" << "sienna" << "silver" << "skyblue" << "slateblue" << "slategray" << "slategrey" + << "snow" << "springgreen" << "steelblue" << "tan" << "teal" << "thistle" << "tomato" + << "turquoise" << "violet" << "wheat" << "white" << "whitesmoke" << "yellow" << "yellowgreen"; +} + +static inline QPushButton *addButton(const QString &description, QVBoxLayout *layout, + QObject *receiver, const char *slotFunc) +{ + QPushButton *button = new QPushButton(description); + QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc); + layout->addWidget(button); + return button; +} + +class ColorProxyModel : public QSortFilterProxyModel +{ +public: + ColorProxyModel(QObject *parent = 0) : QSortFilterProxyModel(parent) + { + } + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const + { + if (role == Qt::DisplayRole) { + QString name = data(index, Qt::EditRole).toString(); + return tr("%1 (%2)").arg(name, QColor(name).name()); + } + if (role == Qt::DecorationRole) + return QColor(data(index, Qt::EditRole).toString()); + return QSortFilterProxyModel::data(index, role); + } +}; + +ColorDialogPanel::ColorDialogPanel(QWidget *parent) + : QWidget(parent) + , m_colorComboBox(new QComboBox) + , m_showAlphaChannel(new QCheckBox(tr("Show alpha channel"))) + , m_noButtons(new QCheckBox(tr("Don't display OK/Cancel buttons"))) + , m_dontUseNativeDialog(new QCheckBox(tr("Don't use native dialog"))) +{ + // Options + QGroupBox *optionsGroupBox = new QGroupBox(tr("Options"), this); + QVBoxLayout *optionsLayout = new QVBoxLayout(optionsGroupBox); + optionsLayout->addWidget(m_showAlphaChannel); + optionsLayout->addWidget(m_noButtons); + optionsLayout->addWidget(m_dontUseNativeDialog); + + // Color + QGroupBox *colorGroupBox = new QGroupBox(tr("Color"), this); + QVBoxLayout *colorLayout = new QVBoxLayout(colorGroupBox); + colorLayout->addWidget(m_colorComboBox); + m_colorComboBox->addItems(svgColorNames()); + m_colorComboBox->setEditable(true); + + QAbstractItemModel *sourceModel = m_colorComboBox->model(); + ColorProxyModel* proxyModel = new ColorProxyModel(m_colorComboBox); + proxyModel->setSourceModel(sourceModel); + sourceModel->setParent(proxyModel); + m_colorComboBox->setModel(proxyModel); + + // Buttons + QGroupBox *buttonsGroupBox = new QGroupBox(tr("Show")); + QVBoxLayout *buttonsLayout = new QVBoxLayout(buttonsGroupBox); + addButton(tr("Exec modal"), buttonsLayout, this, SLOT(execModal())); + addButton(tr("Show modal"), buttonsLayout, this, SLOT(showModal())); + m_deleteModalDialogButton = + addButton(tr("Delete modal"), buttonsLayout, this, SLOT(deleteModalDialog())); + addButton(tr("Show non-modal"), buttonsLayout, this, SLOT(showNonModal())); + m_deleteNonModalDialogButton = + addButton(tr("Delete non-modal"), buttonsLayout, this, SLOT(deleteNonModalDialog())); + addButton(tr("Restore defaults"), buttonsLayout, this, SLOT(restoreDefaults())); + buttonsLayout->addStretch(); + + // Main layout + QHBoxLayout *mainLayout = new QHBoxLayout(this); + QVBoxLayout *leftLayout = new QVBoxLayout; + leftLayout->addWidget(optionsGroupBox); + leftLayout->addWidget(colorGroupBox); + leftLayout->addStretch(); + mainLayout->addLayout(leftLayout); + mainLayout->addWidget(buttonsGroupBox); + + enableDeleteModalDialogButton(); + enableDeleteNonModalDialogButton(); + restoreDefaults(); +} + +void ColorDialogPanel::execModal() +{ + QColorDialog dialog(this); + applySettings(&dialog); + connect(&dialog, SIGNAL(accepted()), this, SLOT(accepted())); + dialog.setWindowTitle(tr("Modal Color Dialog Qt %1").arg(QLatin1String(QT_VERSION_STR))); + dialog.exec(); +} + +void ColorDialogPanel::showModal() +{ + if (m_modalDialog.isNull()) { + static int n = 0; + m_modalDialog = new QColorDialog(this); + m_modalDialog->setModal(true); + connect(m_modalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_modalDialog->setWindowTitle(tr("Modal Color Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + enableDeleteModalDialogButton(); + } + applySettings(m_modalDialog); + m_modalDialog->show(); +} + +void ColorDialogPanel::showNonModal() +{ + if (m_nonModalDialog.isNull()) { + static int n = 0; + m_nonModalDialog = new QColorDialog(this); + connect(m_nonModalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_nonModalDialog->setWindowTitle(tr("Non-Modal Color Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + enableDeleteNonModalDialogButton(); + } + applySettings(m_nonModalDialog); + m_nonModalDialog->show(); +} + +void ColorDialogPanel::deleteNonModalDialog() +{ + if (!m_nonModalDialog.isNull()) + delete m_nonModalDialog; + enableDeleteNonModalDialogButton(); +} + +void ColorDialogPanel::deleteModalDialog() +{ + if (!m_modalDialog.isNull()) + delete m_modalDialog; + enableDeleteModalDialogButton(); +} + +void ColorDialogPanel::accepted() +{ + const QColorDialog *d = qobject_cast<const QColorDialog *>(sender()); + Q_ASSERT(d); + m_result.clear(); + QDebug(&m_result).nospace() + << "Current color: " << d->currentColor() + << "\nSelected color: " << d->selectedColor(); + QTimer::singleShot(0, this, SLOT(showAcceptedResult())); // Avoid problems with the closing (modal) dialog as parent. +} + +void ColorDialogPanel::showAcceptedResult() +{ + QMessageBox::information(this, tr("Color Dialog Accepted"), m_result, QMessageBox::Ok); +} + +void ColorDialogPanel::restoreDefaults() +{ + QColorDialog d; + m_showAlphaChannel->setChecked(d.testOption(QColorDialog::ShowAlphaChannel)); + m_noButtons->setChecked(d.testOption(QColorDialog::NoButtons)); + m_dontUseNativeDialog->setChecked(d.testOption(QColorDialog::DontUseNativeDialog)); +} + +void ColorDialogPanel::enableDeleteNonModalDialogButton() +{ + m_deleteNonModalDialogButton->setEnabled(!m_nonModalDialog.isNull()); +} + +void ColorDialogPanel::enableDeleteModalDialogButton() +{ + m_deleteModalDialogButton->setEnabled(!m_modalDialog.isNull()); +} + +void ColorDialogPanel::applySettings(QColorDialog *d) const +{ + d->setOption(QColorDialog::ShowAlphaChannel, m_showAlphaChannel->isChecked()); + d->setOption(QColorDialog::NoButtons, m_noButtons->isChecked()); + d->setOption(QColorDialog::DontUseNativeDialog, m_dontUseNativeDialog->isChecked()); + d->setCurrentColor(QColor(m_colorComboBox->itemData(m_colorComboBox->currentIndex(), Qt::EditRole).toString())); +} diff --git a/tests/manual/dialogs/colordialogpanel.h b/tests/manual/dialogs/colordialogpanel.h new file mode 100644 index 0000000000..bcd2cf6e52 --- /dev/null +++ b/tests/manual/dialogs/colordialogpanel.h @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef COLORDIALOGPANEL_H +#define COLORDIALOGPANEL_H + +#include <QPointer> +#include <QColorDialog> + +class QComboBox; +class QCheckBox; +class QPushButton; + +class ColorDialogPanel : public QWidget +{ + Q_OBJECT +public: + explicit ColorDialogPanel(QWidget *parent = 0); + +public slots: + void execModal(); + void showModal(); + void showNonModal(); + void deleteNonModalDialog(); + void deleteModalDialog(); + void accepted(); + void showAcceptedResult(); + void restoreDefaults(); + +private slots: + void enableDeleteNonModalDialogButton(); + void enableDeleteModalDialogButton(); + +private: + void applySettings(QColorDialog *d) const; + + QComboBox *m_colorComboBox; + QCheckBox *m_showAlphaChannel; + QCheckBox *m_noButtons; + QCheckBox *m_dontUseNativeDialog; + QPushButton *m_deleteNonModalDialogButton; + QPushButton *m_deleteModalDialogButton; + QString m_result; + QPointer<QColorDialog> m_modalDialog; + QPointer<QColorDialog> m_nonModalDialog; +}; + +#endif // COLORDIALOGPANEL_H diff --git a/tests/manual/dialogs/dialogs.pro b/tests/manual/dialogs/dialogs.pro index ff916d3854..fe40994241 100644 --- a/tests/manual/dialogs/dialogs.pro +++ b/tests/manual/dialogs/dialogs.pro @@ -4,5 +4,5 @@ greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = dialogs TEMPLATE = app -SOURCES += main.cpp filedialogpanel.cpp -HEADERS += filedialogpanel.h +SOURCES += main.cpp filedialogpanel.cpp colordialogpanel.cpp fontdialogpanel.cpp +HEADERS += filedialogpanel.h colordialogpanel.h fontdialogpanel.h diff --git a/tests/manual/dialogs/filedialogpanel.cpp b/tests/manual/dialogs/filedialogpanel.cpp index 66a5201db0..56bd2c1da8 100644 --- a/tests/manual/dialogs/filedialogpanel.cpp +++ b/tests/manual/dialogs/filedialogpanel.cpp @@ -44,6 +44,7 @@ #include <QGridLayout> #include <QVBoxLayout> #include <QHBoxLayout> +#include <QGridLayout> #include <QFormLayout> #include <QSpacerItem> #include <QGroupBox> @@ -105,11 +106,13 @@ inline void setComboBoxValue(QComboBox *c, int v) c->setCurrentIndex(c->findData(QVariant(v))); } -static inline void addButton(const QString &description, QBoxLayout *layout, QObject *receiver, const char *slotFunc) +static inline QPushButton *addButton(const QString &description, QGridLayout *layout, + int &row, int column, QObject *receiver, const char *slotFunc) { QPushButton *button = new QPushButton(description); QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc); - layout->addWidget(button); + layout->addWidget(button, row++, column); + return button; } // A line edit for editing the label fields of the dialog, keeping track of whether it has @@ -159,6 +162,8 @@ FileDialogPanel::FileDialogPanel(QWidget *parent) , m_selectedFileName(new QLineEdit(this)) , m_nameFilters(new QPlainTextEdit) , m_selectedNameFilter(new QLineEdit(this)) + , m_deleteNonModalDialogButton(0) + , m_deleteModalDialogButton(0) { // Options QGroupBox *optionsGroupBox = new QGroupBox(tr("Options")); @@ -197,19 +202,24 @@ FileDialogPanel::FileDialogPanel(QWidget *parent) labelsLayout->addRow(tr("Reject label:"), m_labelLineEdits.back()); // Buttons - QVBoxLayout *buttonLayout = new QVBoxLayout; - buttonLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::Ignored, QSizePolicy::MinimumExpanding)); - addButton(tr("Show modal"), buttonLayout, this, SLOT(showModal())); - addButton(tr("Show non-modal"), buttonLayout, this, SLOT(showNonModal())); - addButton(tr("getOpenFileName"), buttonLayout, this, SLOT(getOpenFileName())); - addButton(tr("getOpenFileNames"), buttonLayout, this, SLOT(getOpenFileNames())); - addButton(tr("getSaveFileName"), buttonLayout, this, SLOT(getSaveFileName())); - addButton(tr("getExistingDirectory"), buttonLayout, this, SLOT(getExistingDirectory())); - addButton(tr("Restore defaults"), buttonLayout, this, SLOT(restoreDefaults())); QGroupBox *buttonsGroupBox = new QGroupBox(tr("Show")); - QHBoxLayout *buttonsGroupLayout = new QHBoxLayout(buttonsGroupBox); - buttonsGroupLayout->addSpacerItem(new QSpacerItem(0, 0, QSizePolicy::MinimumExpanding, QSizePolicy::Ignored)); - buttonsGroupLayout->addLayout(buttonLayout); + QGridLayout *buttonLayout = new QGridLayout(buttonsGroupBox); + int row = 0; + int column = 0; + addButton(tr("Exec modal"), buttonLayout, row, column, this, SLOT(execModal())); + addButton(tr("Show modal"), buttonLayout, row, column, this, SLOT(showModal())); + m_deleteModalDialogButton = + addButton(tr("Delete modal"), buttonLayout, row, column, this, SLOT(deleteModalDialog())); + addButton(tr("Show non-modal"), buttonLayout, row, column, this, SLOT(showNonModal())); + m_deleteNonModalDialogButton = + addButton(tr("Delete non-modal"), buttonLayout, row, column, this, SLOT(deleteNonModalDialog())); + row = 0; + column++; + addButton(tr("getOpenFileName"), buttonLayout, row, column, this, SLOT(getOpenFileName())); + addButton(tr("getOpenFileNames"), buttonLayout, row, column, this, SLOT(getOpenFileNames())); + addButton(tr("getSaveFileName"), buttonLayout, row, column, this, SLOT(getSaveFileName())); + addButton(tr("getExistingDirectory"), buttonLayout, row, column, this, SLOT(getExistingDirectory())); + addButton(tr("Restore defaults"), buttonLayout, row, column, this, SLOT(restoreDefaults())); // Main layout QGridLayout *gridLayout = new QGridLayout(this); @@ -218,26 +228,76 @@ FileDialogPanel::FileDialogPanel(QWidget *parent) gridLayout->addWidget(labelsGroupBox, 1, 0); gridLayout->addWidget(buttonsGroupBox, 1, 1); + enableDeleteModalDialogButton(); + enableDeleteNonModalDialogButton(); restoreDefaults(); } -void FileDialogPanel::showModal() +void FileDialogPanel::execModal() { QFileDialog dialog(this); applySettings(&dialog); + connect(&dialog, SIGNAL(accepted()), this, SLOT(accepted())); dialog.setWindowTitle(tr("Modal File Dialog Qt %1").arg(QLatin1String(QT_VERSION_STR))); dialog.exec(); } +void FileDialogPanel::showModal() +{ + if (m_modalDialog.isNull()) { + static int n = 0; + m_modalDialog = new QFileDialog(this); + m_modalDialog->setModal(true); + connect(m_modalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_modalDialog->setWindowTitle(tr("Modal File Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + enableDeleteModalDialogButton(); + } + applySettings(m_modalDialog); + m_modalDialog->show(); +} + void FileDialogPanel::showNonModal() { - QFileDialog *dialog = new QFileDialog(this); - dialog->setAttribute(Qt::WA_DeleteOnClose); - applySettings(dialog); - dialog->setWindowTitle(tr("Non-Modal File Dialog Qt %1").arg(QLatin1String(QT_VERSION_STR))); - dialog->show(); + if (m_nonModalDialog.isNull()) { + static int n = 0; + m_nonModalDialog = new QFileDialog(this); + connect(m_nonModalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_nonModalDialog->setWindowTitle(tr("Non-Modal File Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + enableDeleteNonModalDialogButton(); + } + applySettings(m_nonModalDialog); + m_nonModalDialog->show(); +} + +void FileDialogPanel::deleteNonModalDialog() +{ + if (!m_nonModalDialog.isNull()) + delete m_nonModalDialog; + enableDeleteNonModalDialogButton(); } +void FileDialogPanel::deleteModalDialog() +{ + if (!m_modalDialog.isNull()) + delete m_modalDialog; + enableDeleteModalDialogButton(); +} + +void FileDialogPanel::enableDeleteNonModalDialogButton() +{ + m_deleteNonModalDialogButton->setEnabled(!m_nonModalDialog.isNull()); +} + +void FileDialogPanel::enableDeleteModalDialogButton() +{ + m_deleteModalDialogButton->setEnabled(!m_modalDialog.isNull()); +} + + QString FileDialogPanel::filterString() const { return m_nameFilters->toPlainText().trimmed().replace(QLatin1String("\n"), QLatin1String(";;")); @@ -350,7 +410,6 @@ void FileDialogPanel::applySettings(QFileDialog *d) const d->selectNameFilter(filter); foreach (LabelLineEdit *l, m_labelLineEdits) l->apply(d); - connect(d, SIGNAL(accepted()), this, SLOT(accepted())); } void FileDialogPanel::accepted() diff --git a/tests/manual/dialogs/filedialogpanel.h b/tests/manual/dialogs/filedialogpanel.h index 699d917e4d..7ee7cb3f60 100644 --- a/tests/manual/dialogs/filedialogpanel.h +++ b/tests/manual/dialogs/filedialogpanel.h @@ -44,7 +44,9 @@ #include <QGroupBox> #include <QFileDialog> +#include <QPointer> +class QPushButton; class QCheckBox; class QComboBox; class QLineEdit; @@ -58,8 +60,11 @@ public: explicit FileDialogPanel(QWidget *parent = 0); public slots: + void execModal(); void showModal(); void showNonModal(); + void deleteNonModalDialog(); + void deleteModalDialog(); void getOpenFileNames(); void getOpenFileName(); void getSaveFileName(); @@ -68,6 +73,10 @@ public slots: void showAcceptedResult(); void restoreDefaults(); +private slots: + void enableDeleteNonModalDialogButton(); + void enableDeleteModalDialogButton(); + private: QString filterString() const; QFileDialog::Options options() const; @@ -87,7 +96,11 @@ private: QList<LabelLineEdit *> m_labelLineEdits; QPlainTextEdit *m_nameFilters; QLineEdit *m_selectedNameFilter; + QPushButton *m_deleteNonModalDialogButton; + QPushButton *m_deleteModalDialogButton; QString m_result; + QPointer<QFileDialog> m_modalDialog; + QPointer<QFileDialog> m_nonModalDialog; }; #endif // FILEDIALOGPANEL_H diff --git a/tests/manual/dialogs/fontdialogpanel.cpp b/tests/manual/dialogs/fontdialogpanel.cpp new file mode 100644 index 0000000000..2bdbb0625a --- /dev/null +++ b/tests/manual/dialogs/fontdialogpanel.cpp @@ -0,0 +1,208 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "fontdialogpanel.h" + +#include <QGroupBox> +#include <QCheckBox> +#include <QPushButton> +#include <QVBoxLayout> +#include <QHBoxLayout> +#include <QMessageBox> +#include <QFontComboBox> +#include <QDoubleSpinBox> +#include <QTimer> +#include <QDebug> + +static inline QPushButton *addButton(const QString &description, QVBoxLayout *layout, + QObject *receiver, const char *slotFunc) +{ + QPushButton *button = new QPushButton(description); + QObject::connect(button, SIGNAL(clicked()), receiver, slotFunc); + layout->addWidget(button); + return button; +} + +FontDialogPanel::FontDialogPanel(QWidget *parent) + : QWidget(parent) + , m_fontFamilyBox(new QFontComboBox) + , m_fontSizeBox(new QDoubleSpinBox) + , m_noButtons(new QCheckBox(tr("Don't display OK/Cancel buttons"))) + , m_dontUseNativeDialog(new QCheckBox(tr("Don't use native dialog"))) +{ + // Options + QGroupBox *optionsGroupBox = new QGroupBox(tr("Options"), this); + QVBoxLayout *optionsLayout = new QVBoxLayout(optionsGroupBox); + optionsLayout->addWidget(m_noButtons); + optionsLayout->addWidget(m_dontUseNativeDialog); + + // Font + QGroupBox *fontGroupBox = new QGroupBox(tr("Font"), this); + QHBoxLayout *fontLayout = new QHBoxLayout(fontGroupBox); + fontLayout->addWidget(m_fontFamilyBox); + fontLayout->addWidget(m_fontSizeBox); + m_fontSizeBox->setValue(QFont().pointSizeF()); + + // Buttons + QGroupBox *buttonsGroupBox = new QGroupBox(tr("Show")); + QVBoxLayout *buttonsLayout = new QVBoxLayout(buttonsGroupBox); + addButton(tr("Exec modal"), buttonsLayout, this, SLOT(execModal())); + addButton(tr("Show modal"), buttonsLayout, this, SLOT(showModal())); + m_deleteModalDialogButton = + addButton(tr("Delete modal"), buttonsLayout, this, SLOT(deleteModalDialog())); + addButton(tr("Show non-modal"), buttonsLayout, this, SLOT(showNonModal())); + m_deleteNonModalDialogButton = + addButton(tr("Delete non-modal"), buttonsLayout, this, SLOT(deleteNonModalDialog())); + addButton(tr("Restore defaults"), buttonsLayout, this, SLOT(restoreDefaults())); + buttonsLayout->addStretch(); + + // Main layout + QHBoxLayout *mainLayout = new QHBoxLayout(this); + QVBoxLayout *leftLayout = new QVBoxLayout; + leftLayout->addWidget(optionsGroupBox); + leftLayout->addWidget(fontGroupBox); + leftLayout->addStretch(); + mainLayout->addLayout(leftLayout); + mainLayout->addWidget(buttonsGroupBox); + + enableDeleteModalDialogButton(); + enableDeleteNonModalDialogButton(); + restoreDefaults(); +} + +void FontDialogPanel::execModal() +{ + QFontDialog dialog(this); + applySettings(&dialog); + connect(&dialog, SIGNAL(accepted()), this, SLOT(accepted())); + dialog.setWindowTitle(tr("Modal Font Dialog Qt %1").arg(QLatin1String(QT_VERSION_STR))); + dialog.exec(); +} + +void FontDialogPanel::showModal() +{ + if (m_modalDialog.isNull()) { + static int n = 0; + m_modalDialog = new QFontDialog(this); + m_modalDialog->setModal(true); + connect(m_modalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_modalDialog->setWindowTitle(tr("Modal Font Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + enableDeleteModalDialogButton(); + } + applySettings(m_modalDialog); + m_modalDialog->show(); +} + +void FontDialogPanel::showNonModal() +{ + if (m_nonModalDialog.isNull()) { + static int n = 0; + m_nonModalDialog = new QFontDialog(this); + connect(m_nonModalDialog.data(), SIGNAL(accepted()), this, SLOT(accepted())); + m_nonModalDialog->setWindowTitle(tr("Non-Modal Font Dialog #%1 Qt %2") + .arg(++n) + .arg(QLatin1String(QT_VERSION_STR))); + enableDeleteNonModalDialogButton(); + } + applySettings(m_nonModalDialog); + m_nonModalDialog->show(); +} + +void FontDialogPanel::deleteNonModalDialog() +{ + if (!m_nonModalDialog.isNull()) + delete m_nonModalDialog; + enableDeleteNonModalDialogButton(); +} + +void FontDialogPanel::deleteModalDialog() +{ + if (!m_modalDialog.isNull()) + delete m_modalDialog; + enableDeleteModalDialogButton(); +} + +void FontDialogPanel::accepted() +{ + const QFontDialog *d = qobject_cast<const QFontDialog *>(sender()); + Q_ASSERT(d); + m_result.clear(); + QDebug(&m_result).nospace() + << "Current font: " << d->currentFont() + << "\nSelected font: " << d->selectedFont(); + QTimer::singleShot(0, this, SLOT(showAcceptedResult())); // Avoid problems with the closing (modal) dialog as parent. +} + +void FontDialogPanel::showAcceptedResult() +{ + QMessageBox::information(this, tr("Color Dialog Accepted"), m_result, QMessageBox::Ok); +} + +void FontDialogPanel::restoreDefaults() +{ + QFontDialog d; + m_noButtons->setChecked(d.testOption(QFontDialog::NoButtons)); + m_dontUseNativeDialog->setChecked(d.testOption(QFontDialog::DontUseNativeDialog)); + m_fontFamilyBox->setCurrentFont(QFont()); + m_fontSizeBox->setValue(QFont().pointSizeF()); +} + +void FontDialogPanel::enableDeleteNonModalDialogButton() +{ + m_deleteNonModalDialogButton->setEnabled(!m_nonModalDialog.isNull()); +} + +void FontDialogPanel::enableDeleteModalDialogButton() +{ + m_deleteModalDialogButton->setEnabled(!m_modalDialog.isNull()); +} + +void FontDialogPanel::applySettings(QFontDialog *d) const +{ + d->setOption(QFontDialog::NoButtons, m_noButtons->isChecked()); + d->setOption(QFontDialog::DontUseNativeDialog, m_dontUseNativeDialog->isChecked()); + + QFont font = m_fontFamilyBox->currentFont(); + font.setPointSizeF(m_fontSizeBox->value()); + d->setCurrentFont(font); +} diff --git a/tests/manual/dialogs/fontdialogpanel.h b/tests/manual/dialogs/fontdialogpanel.h new file mode 100644 index 0000000000..92f2b7313f --- /dev/null +++ b/tests/manual/dialogs/fontdialogpanel.h @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the examples of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef FONTDIALOGPANEL_H +#define FONTDIALOGPANEL_H + +#include <QPointer> +#include <QFontDialog> + +class QCheckBox; +class QPushButton; +class QFontComboBox; +class QDoubleSpinBox; + +class FontDialogPanel : public QWidget +{ + Q_OBJECT +public: + explicit FontDialogPanel(QWidget *parent = 0); + +public slots: + void execModal(); + void showModal(); + void showNonModal(); + void deleteNonModalDialog(); + void deleteModalDialog(); + void accepted(); + void showAcceptedResult(); + void restoreDefaults(); + +private slots: + void enableDeleteNonModalDialogButton(); + void enableDeleteModalDialogButton(); + +private: + void applySettings(QFontDialog *d) const; + + QFontComboBox *m_fontFamilyBox; + QDoubleSpinBox *m_fontSizeBox; + QCheckBox *m_noButtons; + QCheckBox *m_dontUseNativeDialog; + QPushButton *m_deleteNonModalDialogButton; + QPushButton *m_deleteModalDialogButton; + QString m_result; + QPointer<QFontDialog> m_modalDialog; + QPointer<QFontDialog> m_nonModalDialog; +}; + +#endif // FONTDIALOGPANEL_H diff --git a/tests/manual/dialogs/main.cpp b/tests/manual/dialogs/main.cpp index c1ea7b0d8f..f137df1f49 100644 --- a/tests/manual/dialogs/main.cpp +++ b/tests/manual/dialogs/main.cpp @@ -40,6 +40,8 @@ ****************************************************************************/ #include "filedialogpanel.h" +#include "colordialogpanel.h" +#include "fontdialogpanel.h" #include <QMainWindow> #include <QApplication> @@ -50,7 +52,6 @@ #include <QKeySequence> // Test for dialogs, allowing to play with all dialog options for implementing native dialogs. -// Currently, only QFileDialog is implemented. // Compiles with Qt 4.8 and Qt 5. class MainWindow : public QMainWindow { @@ -68,6 +69,8 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit())); QTabWidget *tabWidget = new QTabWidget; tabWidget->addTab(new FileDialogPanel, tr("QFileDialog")); + tabWidget->addTab(new ColorDialogPanel, tr("QColorDialog")); + tabWidget->addTab(new FontDialogPanel, tr("QFontDialog")); setCentralWidget(tabWidget); } diff --git a/tests/manual/lance/lance.pro b/tests/manual/lance/lance.pro index 177ca0e40e..430c9196e6 100644 --- a/tests/manual/lance/lance.pro +++ b/tests/manual/lance/lance.pro @@ -1,5 +1,6 @@ LANCELOT_DIR = $$PWD/../../auto/other/lancelot CONFIG+=console moc +CONFIG -= app_bundle TEMPLATE = app INCLUDEPATH += . $$LANCELOT_DIR QT += core-private gui-private widgets printsupport diff --git a/tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp b/tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp index 7a8c1d159d..b5aeb023f4 100644 --- a/tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp +++ b/tests/manual/widgets/itemviews/qheaderview/qheaderviewtest1.cpp @@ -99,6 +99,9 @@ int main(int argc, char *argv[]) m.setRowCount(500); m.setColumnCount(250); tv.setModel(&m); + tv.setSelectionMode(QAbstractItemView::SingleSelection); + // Comment in the line below to test selection with keyboard (space) + // tv.setEditTriggers(QAbstractItemView::NoEditTriggers); SomeHandler handler(tv.horizontalHeader(), &tv); tv.horizontalHeader()->setDefaultSectionSize(30); tv.show(); diff --git a/tests/manual/windowflags/controls.cpp b/tests/manual/windowflags/controls.cpp index cad84617fc..422656ff03 100644 --- a/tests/manual/windowflags/controls.cpp +++ b/tests/manual/windowflags/controls.cpp @@ -123,8 +123,10 @@ Qt::WindowFlags HintControl::hints() const flags |= Qt::WindowMinimizeButtonHint; if (windowMaximizeButtonCheckBox->isChecked()) flags |= Qt::WindowMaximizeButtonHint; +#if QT_VERSION >= 0x050000 if (windowFullscreenButtonCheckBox->isChecked()) flags |= Qt::WindowFullscreenButtonHint; +#endif if (windowCloseButtonCheckBox->isChecked()) flags |= Qt::WindowCloseButtonHint; if (windowContextHelpButtonCheckBox->isChecked()) @@ -153,7 +155,9 @@ void HintControl::setHints(Qt::WindowFlags flags) windowSystemMenuCheckBox->setChecked(flags & Qt::WindowSystemMenuHint); windowMinimizeButtonCheckBox->setChecked(flags & Qt::WindowMinimizeButtonHint); windowMaximizeButtonCheckBox->setChecked(flags & Qt::WindowMaximizeButtonHint); +#if QT_VERSION >= 0x050000 windowFullscreenButtonCheckBox->setChecked(flags & Qt::WindowFullscreenButtonHint); +#endif windowCloseButtonCheckBox->setChecked(flags & Qt::WindowCloseButtonHint); windowContextHelpButtonCheckBox->setChecked(flags & Qt::WindowContextHelpButtonHint); windowShadeButtonCheckBox->setChecked(flags & Qt::WindowShadeButtonHint); |