diff options
Diffstat (limited to 'tests')
57 files changed, 669 insertions, 191 deletions
diff --git a/tests/auto/corelib/global/qflags/tst_qflags.cpp b/tests/auto/corelib/global/qflags/tst_qflags.cpp index 10902b6f55..634d9a2df3 100644 --- a/tests/auto/corelib/global/qflags/tst_qflags.cpp +++ b/tests/auto/corelib/global/qflags/tst_qflags.cpp @@ -134,11 +134,11 @@ void tst_QFlags::signedness() // underlying type is implementation-defined, we need to allow for // a different signedness, so we only check that the relative // signedness of the types matches: - Q_STATIC_ASSERT((QtPrivate::is_unsigned<Qt::MouseButton>::value == - QtPrivate::is_unsigned<Qt::MouseButtons::Int>::value)); + Q_STATIC_ASSERT((QtPrivate::QIsUnsignedEnum<Qt::MouseButton>::value == + QtPrivate::QIsUnsignedEnum<Qt::MouseButtons::Int>::value)); - Q_STATIC_ASSERT((QtPrivate::is_signed<Qt::AlignmentFlag>::value == - QtPrivate::is_signed<Qt::Alignment::Int>::value)); + Q_STATIC_ASSERT((QtPrivate::QIsSignedEnum<Qt::AlignmentFlag>::value == + QtPrivate::QIsSignedEnum<Qt::Alignment::Int>::value)); } #if defined(Q_COMPILER_CLASS_ENUM) diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 9b92a4ff15..bb6ec1c8e7 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -28,7 +28,6 @@ #include <QtTest/QtTest> -#include <QtCore/qtypetraits.h> #include <QPair> #include <QTextCodec> @@ -49,7 +48,6 @@ private slots: void qConstructorFunction(); void qCoreAppStartupFunction(); void qCoreAppStartupFunctionRestart(); - void isEnum(); void qAlignOf(); void integerForSize(); void qprintable(); @@ -366,100 +364,6 @@ public: enum AnEnum {}; }; -#if defined (Q_COMPILER_CLASS_ENUM) -enum class isEnum_G : qint64 {}; -#endif - -void tst_QGlobal::isEnum() -{ -#if defined (Q_CC_MSVC) -#define IS_ENUM_TRUE(x) (Q_IS_ENUM(x) == true) -#define IS_ENUM_FALSE(x) (Q_IS_ENUM(x) == false) -#else -#define IS_ENUM_TRUE(x) (Q_IS_ENUM(x) == true && QtPrivate::is_enum<x>::value == true) -#define IS_ENUM_FALSE(x) (Q_IS_ENUM(x) == false && QtPrivate::is_enum<x>::value == false) -#endif - - QVERIFY(IS_ENUM_TRUE(isEnum_B_Byte)); - QVERIFY(IS_ENUM_TRUE(const isEnum_B_Byte)); - QVERIFY(IS_ENUM_TRUE(volatile isEnum_B_Byte)); - QVERIFY(IS_ENUM_TRUE(const volatile isEnum_B_Byte)); - - QVERIFY(IS_ENUM_TRUE(isEnum_B_Short)); - QVERIFY(IS_ENUM_TRUE(const isEnum_B_Short)); - QVERIFY(IS_ENUM_TRUE(volatile isEnum_B_Short)); - QVERIFY(IS_ENUM_TRUE(const volatile isEnum_B_Short)); - - QVERIFY(IS_ENUM_TRUE(isEnum_B_Int)); - QVERIFY(IS_ENUM_TRUE(const isEnum_B_Int)); - QVERIFY(IS_ENUM_TRUE(volatile isEnum_B_Int)); - QVERIFY(IS_ENUM_TRUE(const volatile isEnum_B_Int)); - - QVERIFY(IS_ENUM_TRUE(isEnum_F::AnEnum)); - QVERIFY(IS_ENUM_TRUE(const isEnum_F::AnEnum)); - QVERIFY(IS_ENUM_TRUE(volatile isEnum_F::AnEnum)); - QVERIFY(IS_ENUM_TRUE(const volatile isEnum_F::AnEnum)); - - QVERIFY(IS_ENUM_FALSE(void)); - QVERIFY(IS_ENUM_FALSE(isEnum_B_Byte &)); - QVERIFY(IS_ENUM_FALSE(isEnum_B_Byte[1])); - QVERIFY(IS_ENUM_FALSE(const isEnum_B_Byte[1])); - QVERIFY(IS_ENUM_FALSE(isEnum_B_Byte[])); - QVERIFY(IS_ENUM_FALSE(int)); - QVERIFY(IS_ENUM_FALSE(float)); - QVERIFY(IS_ENUM_FALSE(isEnum_A)); - QVERIFY(IS_ENUM_FALSE(isEnum_A *)); - QVERIFY(IS_ENUM_FALSE(const isEnum_A)); - QVERIFY(IS_ENUM_FALSE(isEnum_C)); - QVERIFY(IS_ENUM_FALSE(isEnum_D)); - QVERIFY(IS_ENUM_FALSE(isEnum_E)); - QVERIFY(IS_ENUM_FALSE(void())); - QVERIFY(IS_ENUM_FALSE(void(*)())); - QVERIFY(IS_ENUM_FALSE(int isEnum_A::*)); - QVERIFY(IS_ENUM_FALSE(void (isEnum_A::*)())); - - QVERIFY(IS_ENUM_FALSE(size_t)); - QVERIFY(IS_ENUM_FALSE(bool)); - QVERIFY(IS_ENUM_FALSE(wchar_t)); - - QVERIFY(IS_ENUM_FALSE(char)); - QVERIFY(IS_ENUM_FALSE(unsigned char)); - QVERIFY(IS_ENUM_FALSE(short)); - QVERIFY(IS_ENUM_FALSE(unsigned short)); - QVERIFY(IS_ENUM_FALSE(int)); - QVERIFY(IS_ENUM_FALSE(unsigned int)); - QVERIFY(IS_ENUM_FALSE(long)); - QVERIFY(IS_ENUM_FALSE(unsigned long)); - - QVERIFY(IS_ENUM_FALSE(qint8)); - QVERIFY(IS_ENUM_FALSE(quint8)); - QVERIFY(IS_ENUM_FALSE(qint16)); - QVERIFY(IS_ENUM_FALSE(quint16)); - QVERIFY(IS_ENUM_FALSE(qint32)); - QVERIFY(IS_ENUM_FALSE(quint32)); - QVERIFY(IS_ENUM_FALSE(qint64)); - QVERIFY(IS_ENUM_FALSE(quint64)); - - QVERIFY(IS_ENUM_FALSE(void *)); - QVERIFY(IS_ENUM_FALSE(int *)); - -#if defined (Q_COMPILER_UNICODE_STRINGS) - QVERIFY(IS_ENUM_FALSE(char16_t)); - QVERIFY(IS_ENUM_FALSE(char32_t)); -#endif - -#if defined (Q_COMPILER_CLASS_ENUM) - // Strongly type class enums are not handled by the - // fallback type traits implementation. Any compiler - // supported by Qt that supports C++0x class enums - // should also support the __is_enum intrinsic. - QVERIFY(Q_IS_ENUM(isEnum_G)); -#endif - -#undef IS_ENUM_TRUE -#undef IS_ENUM_FALSE -} - struct Empty {}; template <class T> struct AlignmentInStruct { T dummy; }; diff --git a/tests/auto/corelib/json/invalidBinaryData/10.bjson b/tests/auto/corelib/json/invalidBinaryData/10.bjson Binary files differnew file mode 100644 index 0000000000..12b29b7aa5 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/10.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/11.bjson b/tests/auto/corelib/json/invalidBinaryData/11.bjson Binary files differnew file mode 100644 index 0000000000..cf2b612111 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/11.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/12.bjson b/tests/auto/corelib/json/invalidBinaryData/12.bjson Binary files differnew file mode 100644 index 0000000000..9c2403350e --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/12.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/13.bjson b/tests/auto/corelib/json/invalidBinaryData/13.bjson Binary files differnew file mode 100644 index 0000000000..db6308b1fd --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/13.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/14.bjson b/tests/auto/corelib/json/invalidBinaryData/14.bjson Binary files differnew file mode 100644 index 0000000000..347da4572c --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/14.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/15.bjson b/tests/auto/corelib/json/invalidBinaryData/15.bjson Binary files differnew file mode 100644 index 0000000000..c6c5558934 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/15.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/16.bjson b/tests/auto/corelib/json/invalidBinaryData/16.bjson Binary files differnew file mode 100644 index 0000000000..ae8b57446d --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/16.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/17.bjson b/tests/auto/corelib/json/invalidBinaryData/17.bjson Binary files differnew file mode 100644 index 0000000000..32f0cc0e23 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/17.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/18.bjson b/tests/auto/corelib/json/invalidBinaryData/18.bjson Binary files differnew file mode 100644 index 0000000000..50c89169eb --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/18.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/19.bjson b/tests/auto/corelib/json/invalidBinaryData/19.bjson Binary files differnew file mode 100644 index 0000000000..b922212f45 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/19.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/20.bjson b/tests/auto/corelib/json/invalidBinaryData/20.bjson Binary files differnew file mode 100644 index 0000000000..c965a0d294 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/20.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/21.bjson b/tests/auto/corelib/json/invalidBinaryData/21.bjson Binary files differnew file mode 100644 index 0000000000..98165ee40c --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/21.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/22.bjson b/tests/auto/corelib/json/invalidBinaryData/22.bjson Binary files differnew file mode 100644 index 0000000000..151f773a81 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/22.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/23.bjson b/tests/auto/corelib/json/invalidBinaryData/23.bjson Binary files differnew file mode 100644 index 0000000000..6eb5269470 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/23.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/24.bjson b/tests/auto/corelib/json/invalidBinaryData/24.bjson Binary files differnew file mode 100644 index 0000000000..c55a2a3e3b --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/24.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/25.bjson b/tests/auto/corelib/json/invalidBinaryData/25.bjson Binary files differnew file mode 100644 index 0000000000..6c619f2ae1 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/25.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/26.bjson b/tests/auto/corelib/json/invalidBinaryData/26.bjson Binary files differnew file mode 100644 index 0000000000..3bf303215a --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/26.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/27.bjson b/tests/auto/corelib/json/invalidBinaryData/27.bjson Binary files differnew file mode 100644 index 0000000000..d2656c2287 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/27.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/28.bjson b/tests/auto/corelib/json/invalidBinaryData/28.bjson Binary files differnew file mode 100644 index 0000000000..6797cf8c40 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/28.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/29.bjson b/tests/auto/corelib/json/invalidBinaryData/29.bjson Binary files differnew file mode 100644 index 0000000000..0645dfc3b2 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/29.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/30.bjson b/tests/auto/corelib/json/invalidBinaryData/30.bjson Binary files differnew file mode 100644 index 0000000000..f77fe1efd0 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/30.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/31.bjson b/tests/auto/corelib/json/invalidBinaryData/31.bjson Binary files differnew file mode 100644 index 0000000000..d9840b6582 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/31.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/32.bjson b/tests/auto/corelib/json/invalidBinaryData/32.bjson Binary files differnew file mode 100644 index 0000000000..1de4cb829f --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/32.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/33.bjson b/tests/auto/corelib/json/invalidBinaryData/33.bjson Binary files differnew file mode 100644 index 0000000000..532a31dc08 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/33.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/34.bjson b/tests/auto/corelib/json/invalidBinaryData/34.bjson Binary files differnew file mode 100644 index 0000000000..f498558eff --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/34.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/35.bjson b/tests/auto/corelib/json/invalidBinaryData/35.bjson Binary files differnew file mode 100644 index 0000000000..8701210755 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/35.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/36.bjson b/tests/auto/corelib/json/invalidBinaryData/36.bjson Binary files differnew file mode 100644 index 0000000000..ef5864e911 --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/36.bjson diff --git a/tests/auto/corelib/json/invalidBinaryData/37.bjson b/tests/auto/corelib/json/invalidBinaryData/37.bjson Binary files differnew file mode 100644 index 0000000000..f4dd4ae12f --- /dev/null +++ b/tests/auto/corelib/json/invalidBinaryData/37.bjson diff --git a/tests/auto/corelib/json/tst_qtjson.cpp b/tests/auto/corelib/json/tst_qtjson.cpp index 1194260efa..6aa5165e24 100644 --- a/tests/auto/corelib/json/tst_qtjson.cpp +++ b/tests/auto/corelib/json/tst_qtjson.cpp @@ -93,6 +93,7 @@ private Q_SLOTS: void fromBinary(); void toAndFromBinary_data(); void toAndFromBinary(); + void invalidBinaryData(); void parseNumbers(); void parseStrings(); void parseDuplicateKeys(); @@ -139,6 +140,9 @@ private Q_SLOTS: void removeNonLatinKey(); void documentFromVariant(); + void parseErrorOffset_data(); + void parseErrorOffset(); + private: QString testDataDir; }; @@ -1103,6 +1107,7 @@ void tst_QtJson::fromVariant() jsonObject["string"] = stringValue; jsonObject["array"] = jsonArray_variant; + QCOMPARE(QJsonValue::fromVariant(QVariant::fromValue(nullptr)), QJsonValue(QJsonValue::Null)); QCOMPARE(QJsonValue::fromVariant(QVariant(boolValue)), QJsonValue(boolValue)); QCOMPARE(QJsonValue::fromVariant(QVariant(intValue)), QJsonValue(intValue)); QCOMPARE(QJsonValue::fromVariant(QVariant(uintValue)), QJsonValue(static_cast<double>(uintValue))); @@ -1179,7 +1184,7 @@ void tst_QtJson::toVariantMap() array.append(true); array.append(999.); array.append(QLatin1String("string")); - array.append(QJsonValue()); + array.append(QJsonValue::Null); object.insert("Array", array); map = object.toVariantMap(); @@ -1203,12 +1208,12 @@ void tst_QtJson::toVariantHash() QVERIFY(hash.isEmpty()); object.insert("Key", QString("Value")); - object.insert("null", QJsonValue()); + object.insert("null", QJsonValue::Null); QJsonArray array; array.append(true); array.append(999.); array.append(QLatin1String("string")); - array.append(QJsonValue()); + array.append(QJsonValue::Null); object.insert("Array", array); hash = object.toVariantHash(); @@ -1766,6 +1771,21 @@ void tst_QtJson::toAndFromBinary() QCOMPARE(doc, outdoc); } +void tst_QtJson::invalidBinaryData() +{ + QDir dir(testDataDir + "/invalidBinaryData"); + QFileInfoList files = dir.entryInfoList(); + for (int i = 0; i < files.size(); ++i) { + if (!files.at(i).isFile()) + continue; + QFile file(files.at(i).filePath()); + file.open(QIODevice::ReadOnly); + QByteArray bytes = file.readAll(); + QJsonDocument document = QJsonDocument::fromRawData(bytes.constData(), bytes.size()); + QVERIFY(document.isNull()); + } +} + void tst_QtJson::parseNumbers() { { @@ -2829,5 +2849,35 @@ void tst_QtJson::documentFromVariant() QCOMPARE(do1.object(), do2.object()); } +void tst_QtJson::parseErrorOffset_data() +{ + QTest::addColumn<QByteArray>("json"); + QTest::addColumn<int>("errorOffset"); + + QTest::newRow("Trailing comma in object") << QByteArray("{ \"value\": false, }") << 19; + QTest::newRow("Trailing comma in object plus whitespace") << QByteArray("{ \"value\": false, } ") << 19; + QTest::newRow("Trailing comma in array") << QByteArray("[ false, ]") << 10; + QTest::newRow("Trailing comma in array plus whitespace") << QByteArray("[ false, ] ") << 10; + QTest::newRow("Missing value in object") << QByteArray("{ \"value\": , } ") << 12; + QTest::newRow("Missing value in array") << QByteArray("[ \"value\" , , ] ") << 13; + QTest::newRow("Leading comma in object") << QByteArray("{ , \"value\": false}") << 3; + QTest::newRow("Leading comma in array") << QByteArray("[ , false]") << 3; + QTest::newRow("Stray ,") << QByteArray(" , ") << 3; + QTest::newRow("Stray [") << QByteArray(" [ ") << 5; + QTest::newRow("Stray }") << QByteArray(" } ") << 3; +} + +void tst_QtJson::parseErrorOffset() +{ + QFETCH(QByteArray, json); + QFETCH(int, errorOffset); + + QJsonParseError error; + QJsonDocument::fromJson(json, &error); + + QVERIFY(error.error != QJsonParseError::NoError); + QCOMPARE(error.offset, errorOffset); +} + QTEST_MAIN(tst_QtJson) #include "tst_qtjson.moc" diff --git a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp index caceda86be..7d9f56ef38 100644 --- a/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/auto/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -712,7 +712,7 @@ void tst_QMetaType::flags_data() << bool(!QTypeInfo<RealType>::isStatic) \ << bool(QTypeInfo<RealType>::isComplex) \ << bool(QtPrivate::IsPointerToTypeDerivedFromQObject<RealType>::Value) \ - << bool(Q_IS_ENUM(RealType)); + << bool(std::is_enum<RealType>::value); QT_FOR_EACH_STATIC_CORE_CLASS(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_PRIMITIVE_POINTER(ADD_METATYPE_TEST_ROW) QT_FOR_EACH_STATIC_CORE_POINTER(ADD_METATYPE_TEST_ROW) diff --git a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp index 1a70ac5e75..0c890eafbc 100644 --- a/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp +++ b/tests/auto/corelib/tools/qhashfunctions/tst_qhashfunctions.cpp @@ -29,7 +29,6 @@ #include <QtTest/QtTest> #include <qhash.h> -#include <qtypetraits.h> #include <iterator> #include <sstream> @@ -197,7 +196,7 @@ void tst_QHashFunctions::range() { // verify that the input iterator category suffices: std::stringstream sstream; - Q_STATIC_ASSERT((QtPrivate::is_same<std::input_iterator_tag, std::istream_iterator<int>::iterator_category>::value)); + Q_STATIC_ASSERT((std::is_same<std::input_iterator_tag, std::istream_iterator<int>::iterator_category>::value)); std::copy(ints, ints + numInts, std::ostream_iterator<int>(sstream, " ")); sstream.seekg(0); std::istream_iterator<int> it(sstream), end; diff --git a/tests/auto/gui/gui.pro b/tests/auto/gui/gui.pro index 8d8a2df393..2fd3024afe 100644 --- a/tests/auto/gui/gui.pro +++ b/tests/auto/gui/gui.pro @@ -13,4 +13,4 @@ SUBDIRS = \ util \ itemmodels \ -!qtConfig(opengl(es2)?): SUBDIRS -= qopengl qopenglconfig +!qtConfig(opengl): SUBDIRS -= qopengl qopenglconfig diff --git a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp index 895f68bbd7..ad7de09c48 100644 --- a/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/auto/gui/image/qpixmap/tst_qpixmap.cpp @@ -162,6 +162,7 @@ private: const QString m_prefix; const QString m_convertFromImage; const QString m_loadFromData; + const QTemporaryDir m_tempDir; }; static bool lenientCompare(const QPixmap &actual, const QPixmap &expected) @@ -209,11 +210,11 @@ void tst_QPixmap::initTestCase() QVERIFY(!m_prefix.isEmpty()); QVERIFY(!m_convertFromImage.isEmpty()); QVERIFY(!m_loadFromData.isEmpty()); + QVERIFY2(m_tempDir.isValid(), qPrintable(m_tempDir.errorString())); } void tst_QPixmap::cleanupTestCase() { - QFile::remove(QLatin1String("temp_image.png")); } void tst_QPixmap::swap() @@ -1442,18 +1443,18 @@ void tst_QPixmap::preserveDepth() void tst_QPixmap::loadAsBitmapOrPixmap() { QImage tmp(10, 10, QImage::Format_RGB32); - tmp.save("temp_image.png"); + tmp.save(m_tempDir.path() + "/temp_image.png"); bool ok; // Check that we can load the pixmap as a pixmap and that it then turns into a pixmap - QPixmap pixmap("temp_image.png"); + QPixmap pixmap(m_tempDir.path() + "/temp_image.png"); QVERIFY(!pixmap.isNull()); QVERIFY(pixmap.depth() > 1); QVERIFY(!pixmap.isQBitmap()); pixmap = QPixmap(); - ok = pixmap.load("temp_image.png"); + ok = pixmap.load(m_tempDir.path() + "/temp_image.png"); QVERIFY(ok); QVERIFY(!pixmap.isNull()); QVERIFY(pixmap.depth() > 1); @@ -1461,20 +1462,20 @@ void tst_QPixmap::loadAsBitmapOrPixmap() //now we can try to load it without an extension pixmap = QPixmap(); - ok = pixmap.load("temp_image"); + ok = pixmap.load(m_tempDir.path() + "/temp_image"); QVERIFY(ok); QVERIFY(!pixmap.isNull()); QVERIFY(pixmap.depth() > 1); QVERIFY(!pixmap.isQBitmap()); // The do the same check for bitmaps.. - QBitmap bitmap("temp_image.png"); + QBitmap bitmap(m_tempDir.path() + "/temp_image.png"); QVERIFY(!bitmap.isNull()); QCOMPARE(bitmap.depth(), 1); QVERIFY(bitmap.isQBitmap()); bitmap = QBitmap(); - ok = bitmap.load("temp_image.png"); + ok = bitmap.load(m_tempDir.path() + "/temp_image.png"); QVERIFY(ok); QVERIFY(!bitmap.isNull()); QCOMPARE(bitmap.depth(), 1); diff --git a/tests/auto/gui/kernel/kernel.pro b/tests/auto/gui/kernel/kernel.pro index 631962ad34..559395a9ae 100644 --- a/tests/auto/gui/kernel/kernel.pro +++ b/tests/auto/gui/kernel/kernel.pro @@ -34,6 +34,6 @@ win32:!winrt:qtHaveModule(network): SUBDIRS += noqteventloop !qtHaveModule(network): SUBDIRS -= \ qguieventloop -!qtConfig(opengl(es2)?): SUBDIRS -= qopenglwindow +!qtConfig(opengl): SUBDIRS -= qopenglwindow uikit: SUBDIRS -= qclipboard diff --git a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp index c53792da99..8c26f8a91f 100644 --- a/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp +++ b/tests/auto/gui/text/qfontdatabase/tst_qfontdatabase.cpp @@ -67,6 +67,9 @@ private slots: void condensedFontWidth(); void condensedFontMatching(); + void rasterFonts(); + void smoothFonts(); + private: QString m_ledFont; QString m_testFont; @@ -334,5 +337,30 @@ void tst_QFontDatabase::condensedFontMatching() QFontMetrics(tfcBySubfamilyName).width(testString())); } +void tst_QFontDatabase::rasterFonts() +{ + QFont font(QLatin1String("Fixedsys"), 1000); + QFontInfo fontInfo(font); + + if (fontInfo.family() != font.family()) + QSKIP("Fixedsys font not available."); + + QVERIFY(!QFontDatabase().isSmoothlyScalable(font.family())); + QVERIFY(fontInfo.pointSize() != font.pointSize()); +} + +void tst_QFontDatabase::smoothFonts() +{ + QFont font(QLatin1String("Arial"), 1000); + QFontInfo fontInfo(font); + + if (fontInfo.family() != font.family()) + QSKIP("Arial font not available."); + + // Smooth and bitmap scaling are mutually exclusive + QVERIFY(QFontDatabase().isSmoothlyScalable(font.family())); + QVERIFY(!QFontDatabase().isBitmapScalable(font.family())); +} + QTEST_MAIN(tst_QFontDatabase) #include "tst_qfontdatabase.moc" diff --git a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp index 0d1d0f1ae1..b8af5271ea 100644 --- a/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp +++ b/tests/auto/gui/text/qtextlayout/tst_qtextlayout.cpp @@ -134,6 +134,7 @@ private slots: void xToCursorForLigatures(); void cursorInNonStopChars(); void nbsp(); + void nbspWithFormat(); void noModificationOfInputString(); void superscriptCrash_qtbug53911(); @@ -2254,5 +2255,41 @@ void tst_QTextLayout::superscriptCrash_qtbug53911() qDeleteAll(textLayouts); } +void tst_QTextLayout::nbspWithFormat() +{ + QString s1 = QLatin1String("ABCDEF "); + QString s2 = QLatin1String("GHI"); + QChar nbsp(QChar::Nbsp); + QString s3 = QLatin1String("JKLMNOPQRSTUVWXYZ"); + + QTextLayout layout; + layout.setText(s1 + s2 + nbsp + s3); + + QTextLayout::FormatRange formatRange; + formatRange.start = s1.length() + s2.length(); + formatRange.length = 1; + formatRange.format.setFontUnderline(true); + + QList<QTextLayout::FormatRange> overrides; + overrides.append(formatRange); + + layout.setAdditionalFormats(overrides); + + layout.beginLayout(); + forever { + QTextLine line = layout.createLine(); + if (!line.isValid()) + break; + line.setLineWidth(1); + } + layout.endLayout(); + + QCOMPARE(layout.lineCount(), 2); + QCOMPARE(layout.lineAt(0).textStart(), 0); + QCOMPARE(layout.lineAt(0).textLength(), s1.length()); + QCOMPARE(layout.lineAt(1).textStart(), s1.length()); + QCOMPARE(layout.lineAt(1).textLength(), s2.length() + 1 + s3.length()); +} + QTEST_MAIN(tst_QTextLayout) #include "tst_qtextlayout.moc" diff --git a/tests/auto/opengl/qgl/tst_qgl.cpp b/tests/auto/opengl/qgl/tst_qgl.cpp index 4dec107f1e..af0248b432 100644 --- a/tests/auto/opengl/qgl/tst_qgl.cpp +++ b/tests/auto/opengl/qgl/tst_qgl.cpp @@ -739,16 +739,14 @@ void tst_QGL::openGLVersionCheck() // However, the complicated parts are in openGLVersionFlags(const QString &versionString) // tested above -#if defined(QT_OPENGL_ES_1) - QVERIFY(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Common_Version_1_0); -#elif defined(QT_OPENGL_ES_2) +#if defined(QT_OPENGL_ES_2) QVERIFY(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Version_2_0); #else if (QOpenGLContext::currentContext()->isOpenGLES()) QVERIFY(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_ES_Version_2_0); else QVERIFY(QGLFormat::openGLVersionFlags() & QGLFormat::OpenGL_Version_1_1); -#endif //defined(QT_OPENGL_ES_1) +#endif //defined(QT_OPENGL_ES_2) } #endif //QT_BUILD_INTERNAL diff --git a/tests/auto/tools/qmakelib/evaltest.cpp b/tests/auto/tools/qmakelib/evaltest.cpp index 62fcedddb9..e3be294e5f 100644 --- a/tests/auto/tools/qmakelib/evaltest.cpp +++ b/tests/auto/tools/qmakelib/evaltest.cpp @@ -1265,8 +1265,8 @@ void tst_qmakelib::addReplaceFunctions(const QString &qindir) QTest::newRow("$$section(): bad number of arguments") << "VAR = $$section(1, 2) \\\n$$section(1, 2, 3, 4, 5)" << "VAR =" - << "##:1: section(var) section(var, sep, begin, end) requires three or four arguments.\n" - "##:2: section(var) section(var, sep, begin, end) requires three or four arguments." + << "##:1: section(var, sep, begin, end) requires three or four arguments.\n" + "##:2: section(var, sep, begin, end) requires three or four arguments." << true; QTest::newRow("$$find()") @@ -2259,7 +2259,7 @@ void tst_qmakelib::addTestFunctions(const QString &qindir) << "jsontext = not good\n" "parseJson(jsontext, json): OK = 1" << "OK = UNDEF" - << "##:2: Error parsing json at offset 1: illegal value" + << "##:2: Error parsing JSON at 1:1: illegal value" << true; QTest::newRow("parseJson(): bad number of arguments") @@ -2326,8 +2326,16 @@ void tst_qmakelib::addTestFunctions(const QString &qindir) << true; QTest::newRow("discard_from()") - << "HERE = 1\nPLUS = one\ninclude(include/inc.pri)\ndiscard_from(include/inc.pri): OK = 1" - << "OK = 1\nHERE = 1\nPLUS = one\nVAR = UNDEF" + << "HERE = 1\nPLUS = one\n" + "defineTest(tfunc) {}\ndefineReplace(rfunc) {}\n" + "include(include/inc.pri)\n" + "contains(QMAKE_INTERNAL_INCLUDED_FILES, .*/include/inc\\\\.pri): PRE = 1\n" + "discard_from(include/inc.pri): OK = 1\n" + "!contains(QMAKE_INTERNAL_INCLUDED_FILES, .*/include/inc\\\\.pri): POST = 1\n" + "defined(tfunc, test): TDEF = 1\ndefined(rfunc, replace): RDEF = 1\n" + "defined(func, test): DTDEF = 1\ndefined(func, replace): DRDEF = 1\n" + << "PRE = 1\nPOST = 1\nOK = 1\nHERE = 1\nPLUS = one\nVAR = UNDEF\n" + "TDEF = 1\nRDEF = 1\nDTDEF = UNDEF\nDRDEF = UNDEF" << "" << true; diff --git a/tests/auto/tools/qmakelib/testdata/include/inc.pri b/tests/auto/tools/qmakelib/testdata/include/inc.pri index f9a4ec1bfa..5c570f49e5 100644 --- a/tests/auto/tools/qmakelib/testdata/include/inc.pri +++ b/tests/auto/tools/qmakelib/testdata/include/inc.pri @@ -8,3 +8,7 @@ fake-*: MATCH = 1 defineTest(func) { message("say hi!") } + +defineReplace(func) { + return("say hi!") +} diff --git a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp index 00693ba6f7..0bb2c50b9d 100644 --- a/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp +++ b/tests/auto/widgets/dialogs/qfilesystemmodel/tst_qfilesystemmodel.cpp @@ -1057,6 +1057,10 @@ static QSet<QString> fileListUnderIndex(const QFileSystemModel *model, const QMo void tst_QFileSystemModel::specialFiles() { +#ifndef Q_OS_UNIX + QSKIP("Not implemented"); +#endif + QFileSystemModel model; model.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); @@ -1065,23 +1069,8 @@ void tst_QFileSystemModel::specialFiles() // as it will always return a valid index for existing files, // even if the file is not visible with the given filter. -#if defined(Q_OS_UNIX) const QModelIndex rootIndex = model.setRootPath(QStringLiteral("/dev/")); const QString testFileName = QStringLiteral("null"); -#elif defined(Q_OS_WIN) - const QModelIndex rootIndex = model.setRootPath(flatDirTestPath); - - const QString testFileName = QStringLiteral("linkSource.lnk"); - - QFile file(flatDirTestPath + QLatin1String("/linkTarget.txt")); - QVERIFY(file.open(QIODevice::WriteOnly)); - file.close(); - QVERIFY(file.link(flatDirTestPath + '/' + testFileName)); -#else - QSKIP("Not implemented"); - QModelIndex rootIndex; - QString testFileName; -#endif QTRY_VERIFY(fileListUnderIndex(&model, rootIndex).contains(testFileName)); diff --git a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp index 816fe1faba..edaf033678 100644 --- a/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp +++ b/tests/auto/widgets/widgets/qcombobox/tst_qcombobox.cpp @@ -62,6 +62,7 @@ #include <qstyleditemdelegate.h> #include <qstandarditemmodel.h> #include <qproxystyle.h> +#include <qfont.h> static inline void setFrameless(QWidget *w) { @@ -160,6 +161,7 @@ private slots: void respectChangedOwnershipOfItemView(); void task_QTBUG_39088_inputMethodHints(); void task_QTBUG_49831_scrollerNotActivated(); + void task_QTBUG_56693_itemFontFromModel(); }; class MyAbstractItemDelegate : public QAbstractItemDelegate @@ -3250,5 +3252,77 @@ void tst_QComboBox::task_QTBUG_49831_scrollerNotActivated() } } +class QTBUG_56693_Model : public QStandardItemModel +{ +public: + QTBUG_56693_Model(QObject *parent = Q_NULLPTR) + : QStandardItemModel(parent) + { } + + QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override + { + if (role == Qt::FontRole) { + if (index.row() < 5) { + QFont font = QApplication::font(); + font.setItalic(true); + return font; + } else { + return QApplication::font(); + } + } + return QStandardItemModel::data(index, role); + } +}; + +class QTBUG_56693_ProxyStyle : public QProxyStyle +{ +public: + QTBUG_56693_ProxyStyle(QStyle *style) + : QProxyStyle(style), italicItemsNo(0) + { + + } + + void drawControl(ControlElement element, const QStyleOption *opt, QPainter *p, const QWidget *w = Q_NULLPTR) const override + { + if (element == CE_MenuItem) + if (const QStyleOptionMenuItem *menuItem = qstyleoption_cast<const QStyleOptionMenuItem *>(opt)) + if (menuItem->font.italic()) + italicItemsNo++; + + baseStyle()->drawControl(element, opt, p, w); + } + + mutable int italicItemsNo; +}; + +void tst_QComboBox::task_QTBUG_56693_itemFontFromModel() +{ + QComboBox box; + if (!qobject_cast<QComboMenuDelegate *>(box.itemDelegate())) + QSKIP("Only for combo boxes using QComboMenuDelegate"); + + QTBUG_56693_Model model; + box.setModel(&model); + + QTBUG_56693_ProxyStyle *proxyStyle = new QTBUG_56693_ProxyStyle(box.style()); + box.setStyle(proxyStyle); + box.setFont(QApplication::font()); + + for (int i = 0; i < 10; i++) + box.addItem(QLatin1String("Item ") + QString::number(i)); + + box.show(); + QTest::qWaitForWindowExposed(&box); + box.showPopup(); + QFrame *container = box.findChild<QComboBoxPrivateContainer *>(); + QVERIFY(container); + QTest::qWaitForWindowExposed(container); + + QCOMPARE(proxyStyle->italicItemsNo, 5); + + box.hidePopup(); +} + QTEST_MAIN(tst_QComboBox) #include "tst_qcombobox.moc" diff --git a/tests/auto/widgets/widgets/qlabel/red@2x.png b/tests/auto/widgets/widgets/qlabel/red@2x.png Binary files differnew file mode 100644 index 0000000000..4a843e744f --- /dev/null +++ b/tests/auto/widgets/widgets/qlabel/red@2x.png diff --git a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp index ad971c6b5f..6363d0c673 100644 --- a/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp +++ b/tests/auto/widgets/widgets/qlabel/tst_qlabel.cpp @@ -96,6 +96,9 @@ private Q_SLOTS: void taskQTBUG_7902_contextMenuCrash(); #endif + void taskQTBUG_48157_dprPixmap(); + void taskQTBUG_48157_dprMovie(); + private: QLabel *testWidget; QPointer<Widget> test_box; @@ -541,5 +544,26 @@ void tst_QLabel::taskQTBUG_7902_contextMenuCrash() } #endif +void tst_QLabel::taskQTBUG_48157_dprPixmap() +{ + QLabel label; + QPixmap pixmap; + pixmap.load(QFINDTESTDATA(QStringLiteral("red@2x.png"))); + QCOMPARE(pixmap.devicePixelRatio(), 2.0); + label.setPixmap(pixmap); + QCOMPARE(label.sizeHint(), pixmap.rect().size() / pixmap.devicePixelRatio()); +} + +void tst_QLabel::taskQTBUG_48157_dprMovie() +{ + QLabel label; + QMovie movie; + movie.setFileName(QFINDTESTDATA(QStringLiteral("red@2x.png"))); + movie.start(); + QCOMPARE(movie.currentPixmap().devicePixelRatio(), 2.0); + label.setMovie(&movie); + QCOMPARE(label.sizeHint(), movie.currentPixmap().size() / movie.currentPixmap().devicePixelRatio()); +} + QTEST_MAIN(tst_QLabel) #include "tst_qlabel.moc" diff --git a/tests/manual/cocoa/menurama/mainwindow.cpp b/tests/manual/cocoa/menurama/mainwindow.cpp index db8fdafc21..f7762f57f5 100644 --- a/tests/manual/cocoa/menurama/mainwindow.cpp +++ b/tests/manual/cocoa/menurama/mainwindow.cpp @@ -56,7 +56,13 @@ MainWindow::MainWindow(QWidget *parent) : }); connect(ui->menuDynamic_Stuff, &QMenu::aboutToShow, [=] { - menuApp->addDynMenu(QLatin1String("Added After aboutToShow()"), ui->menuDynamic_Stuff); + menuApp->addDynMenu(QLatin1String("Menu Added After aboutToShow()"), ui->menuDynamic_Stuff); + + const QLatin1String itemTitle = QLatin1String("Disabled Item Added After aboutToShow()"); + if (QAction *a = menuApp->findAction(itemTitle, ui->menuDynamic_Stuff)) + ui->menuDynamic_Stuff->removeAction(a); + QAction *a = ui->menuDynamic_Stuff->addAction(itemTitle); + a->setEnabled(false); }); connect(ui->pushButton, &QPushButton::clicked, [=] { diff --git a/tests/manual/cocoa/menurama/mainwindow.ui b/tests/manual/cocoa/menurama/mainwindow.ui index f73b41b861..d3caa6c608 100644 --- a/tests/manual/cocoa/menurama/mainwindow.ui +++ b/tests/manual/cocoa/menurama/mainwindow.ui @@ -6,63 +6,71 @@ <rect> <x>0</x> <y>0</y> - <width>566</width> - <height>300</height> + <width>429</width> + <height>251</height> </rect> </property> <property name="windowTitle"> <string>MainWindow</string> </property> <widget class="QWidget" name="centralWidget"> - <widget class="QCheckBox" name="checkBox"> - <property name="geometry"> - <rect> - <x>10</x> - <y>40</y> - <width>151</width> - <height>20</height> - </rect> - </property> - <property name="text"> - <string>Enable "Stuff" Menu</string> - </property> - <property name="checked"> - <bool>true</bool> - </property> - </widget> - <widget class="QLabel" name="label"> - <property name="geometry"> - <rect> - <x>10</x> - <y>10</y> - <width>321</width> - <height>16</height> - </rect> - </property> - <property name="text"> - <string>The "Help" menu should NOT be visible.</string> - </property> - </widget> - <widget class="QPushButton" name="pushButton"> - <property name="geometry"> - <rect> - <x>10</x> - <y>80</y> - <width>211</width> - <height>32</height> - </rect> - </property> - <property name="text"> - <string>Populate Dynamic Submenu</string> - </property> - </widget> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QVBoxLayout" name="verticalLayout"> + <property name="spacing"> + <number>24</number> + </property> + <item> + <widget class="QLabel" name="label"> + <property name="text"> + <string>The "Help" menu should NOT be visible. + +Click on "Dynamic Stuff" then move left and right to other menus. Disabled items should remain that way.</string> + </property> + <property name="scaledContents"> + <bool>false</bool> + </property> + <property name="alignment"> + <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QCheckBox" name="checkBox"> + <property name="text"> + <string>Enable "Stuff" Menu</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="pushButton"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Maximum" vsizetype="Fixed"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="text"> + <string>Populate Dynamic Submenu</string> + </property> + </widget> + </item> + </layout> + </item> + </layout> </widget> <widget class="QMenuBar" name="menuBar"> <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>566</width> + <width>429</width> <height>22</height> </rect> </property> diff --git a/tests/manual/cocoa/menurama/menuramaapplication.cpp b/tests/manual/cocoa/menurama/menuramaapplication.cpp index 534d5fa371..13e457d7dd 100644 --- a/tests/manual/cocoa/menurama/menuramaapplication.cpp +++ b/tests/manual/cocoa/menurama/menuramaapplication.cpp @@ -69,13 +69,19 @@ void MenuramaApplication::populateMenu(QMenu *menu, bool clear) void MenuramaApplication::addDynMenu(QLatin1String title, QMenu *parentMenu) { - foreach (QAction *a, parentMenu->actions()) - if (a->text() == title) { - parentMenu->removeAction(a); - break; - } + if (QAction *a = findAction(title, parentMenu)) + parentMenu->removeAction(a); QMenu *subMenu = new QMenu(title, parentMenu); populateMenu(subMenu, false /*clear*/); parentMenu->addMenu(subMenu); } + +QAction *MenuramaApplication::findAction(QLatin1String title, QMenu *parentMenu) +{ + foreach (QAction *a, parentMenu->actions()) + if (a->text() == title) + return a; + + return Q_NULLPTR; +} diff --git a/tests/manual/cocoa/menurama/menuramaapplication.h b/tests/manual/cocoa/menurama/menuramaapplication.h index 07c8da27a1..b0670cc53b 100644 --- a/tests/manual/cocoa/menurama/menuramaapplication.h +++ b/tests/manual/cocoa/menurama/menuramaapplication.h @@ -50,6 +50,7 @@ class MenuramaApplication : public QApplication public: MenuramaApplication(int argc, char **argv); void addDynMenu(QLatin1String title, QMenu *parentMenu); + QAction *findAction(QLatin1String title, QMenu *parentMenu); public slots: void populateMenu(QMenu *menu, bool clear); diff --git a/tests/manual/dialogs/main.cpp b/tests/manual/dialogs/main.cpp index f0f4e437e9..3f7b33ee7a 100644 --- a/tests/manual/dialogs/main.cpp +++ b/tests/manual/dialogs/main.cpp @@ -80,12 +80,15 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) int main(int argc, char *argv[]) { +#if QT_VERSION >= 0x050700 for (int a = 1; a < argc; ++a) { if (!qstrcmp(argv[a], "-n")) { qDebug("AA_DontUseNativeDialogs"); QCoreApplication::setAttribute(Qt::AA_DontUseNativeDialogs); } } +#endif // Qt 5 + QApplication a(argc, argv); MainWindow w; w.move(500, 200); diff --git a/tests/manual/qcursor/childwidget/childwidget.pro b/tests/manual/qcursor/childwidget/childwidget.pro new file mode 100644 index 0000000000..9ca41c5b4f --- /dev/null +++ b/tests/manual/qcursor/childwidget/childwidget.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +TARGET = childwidget +INCLUDEPATH += . +QT += widgets + +SOURCES += main.cpp diff --git a/tests/manual/qcursor/childwidget/main.cpp b/tests/manual/qcursor/childwidget/main.cpp new file mode 100644 index 0000000000..4447c87210 --- /dev/null +++ b/tests/manual/qcursor/childwidget/main.cpp @@ -0,0 +1,92 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtWidgets> + +class CursorWidget : public QWidget +{ +public: + CursorWidget(QCursor cursor, QColor color) + :m_cursor(cursor) + ,m_color(color) + { + if (cursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(cursor); + } + + void paintEvent(QPaintEvent *e) + { + QPainter p(this); + p.fillRect(e->rect(), m_color); + } + + void mousePressEvent(QMouseEvent *) + { + // Toggle cursor + QCursor newCursor = (cursor().shape() == m_cursor.shape()) ? QCursor() : m_cursor; + if (newCursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(newCursor); + } + +private: + QCursor m_cursor; + QColor m_color; +}; + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + // Test child widgets (one of which is native) with set cursors. + // Click window to toggle cursor. + + CursorWidget w1((QCursor(Qt::SizeVerCursor)), QColor(Qt::blue).darker()); + w1.resize(200, 200); + w1.show(); + + CursorWidget w2((QCursor(Qt::OpenHandCursor)), QColor(Qt::red).darker()); + w2.setParent(&w1); + w2.setGeometry(0, 0, 100, 100); + w2.show(); + + CursorWidget w3((QCursor(Qt::IBeamCursor)), QColor(Qt::green).darker()); + w3.winId(); + w3.setParent(&w1); + w3.setGeometry(100, 100, 100, 100); + w3.show(); + + return app.exec(); +} diff --git a/tests/manual/qcursor/childwindow/childwindow.pro b/tests/manual/qcursor/childwindow/childwindow.pro new file mode 100644 index 0000000000..194536a91a --- /dev/null +++ b/tests/manual/qcursor/childwindow/childwindow.pro @@ -0,0 +1,5 @@ +TEMPLATE = app +TARGET = childwindow +INCLUDEPATH += . + +SOURCES += main.cpp diff --git a/tests/manual/qcursor/childwindow/main.cpp b/tests/manual/qcursor/childwindow/main.cpp new file mode 100644 index 0000000000..5fc293dfcf --- /dev/null +++ b/tests/manual/qcursor/childwindow/main.cpp @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtGui> + +class CursorWindow : public QRasterWindow +{ +public: + CursorWindow(QCursor cursor, QColor color) + :m_cursor(cursor) + ,m_color(color) + { + if (cursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(cursor); + } + + void paintEvent(QPaintEvent *e) + { + QPainter p(this); + p.fillRect(e->rect(), m_color); + } + + void mousePressEvent(QMouseEvent *) + { + // Toggle cursor + QCursor newCursor = (cursor().shape() == m_cursor.shape()) ? QCursor() : m_cursor; + if (newCursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(newCursor); + } + +private: + QCursor m_cursor; + QColor m_color; +}; + +int main(int argc, char **argv) +{ + QGuiApplication app(argc, argv); + + // Test child windows with set cursors. Create parent window and + // two child windows. Click window to toggle cursor. + + CursorWindow w1((QCursor(Qt::SizeVerCursor)), QColor(Qt::blue).darker()); + w1.resize(200, 200); + w1.show(); + + CursorWindow w2((QCursor(Qt::OpenHandCursor)), QColor(Qt::red).darker()); + w2.setParent(&w1); + w2.setGeometry(0, 0, 100, 100); + w2.show(); + + CursorWindow w3((QCursor(Qt::IBeamCursor)), QColor(Qt::green).darker()); + w3.setParent(&w1); + w3.setGeometry(100, 100, 100, 100); + w3.show(); + + return app.exec(); +} diff --git a/tests/manual/qcursor/childwindowcontainer/childwindowcontainer.pro b/tests/manual/qcursor/childwindowcontainer/childwindowcontainer.pro new file mode 100644 index 0000000000..2233ce4a63 --- /dev/null +++ b/tests/manual/qcursor/childwindowcontainer/childwindowcontainer.pro @@ -0,0 +1,6 @@ +TEMPLATE = app +TARGET = childwindowcontainer +INCLUDEPATH += . +QT += widgets + +SOURCES += main.cpp diff --git a/tests/manual/qcursor/childwindowcontainer/main.cpp b/tests/manual/qcursor/childwindowcontainer/main.cpp new file mode 100644 index 0000000000..d440133a42 --- /dev/null +++ b/tests/manual/qcursor/childwindowcontainer/main.cpp @@ -0,0 +1,138 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: http://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** 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 The Qt Company. For licensing terms +** and conditions see http://www.qt.io/terms-conditions. For further +** information use the contact form at http://www.qt.io/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 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** As a special exception, The Qt Company gives you certain additional +** rights. These rights are described in The Qt Company LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QtWidgets> + +class CursorWindow : public QRasterWindow +{ +public: + CursorWindow(QCursor cursor, QColor color) + :m_cursor(cursor) + ,m_color(color) + { + if (cursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(cursor); + } + + void paintEvent(QPaintEvent *e) + { + QPainter p(this); + p.fillRect(e->rect(), m_color); + } + + void mousePressEvent(QMouseEvent *) + { + // Toggle cursor + QCursor newCursor = (cursor().shape() == m_cursor.shape()) ? QCursor() : m_cursor; + if (newCursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(newCursor); + } + +private: + QCursor m_cursor; + QColor m_color; +}; + +class CursorWidget : public QWidget +{ +public: + CursorWidget(QCursor cursor, QColor color) + :m_cursor(cursor) + ,m_color(color) + { + if (cursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(cursor); + } + + void paintEvent(QPaintEvent *e) + { + QPainter p(this); + p.fillRect(e->rect(), m_color); + } + + void mousePressEvent(QMouseEvent *) + { + // Toggle cursor + QCursor newCursor = (cursor().shape() == m_cursor.shape()) ? QCursor() : m_cursor; + if (newCursor.shape() == Qt::ArrowCursor) + unsetCursor(); + else + setCursor(newCursor); + } + +private: + QCursor m_cursor; + QColor m_color; +}; + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + { + // Create top-level windowContainer with window. Setting the cursor + // for the container should set the cursor for the window as well. + // Setting the cursor for the window overrides the cursor for the + // container. The example starts out with a window cursor; click + // to fall back to the container cursor. + CursorWindow *w1 = new CursorWindow(QCursor(Qt::OpenHandCursor), QColor(Qt::red).darker()); + QWidget* container = QWidget::createWindowContainer(w1); + container->resize(200, 200); + container->setCursor(Qt::PointingHandCursor); + container->show(); + } + + { + // Similar to above, but with a top-level QWiget + CursorWidget *w1 = new CursorWidget(QCursor(Qt::IBeamCursor), QColor(Qt::green).darker()); + w1->resize(200, 200); + + CursorWindow *w2 = new CursorWindow(QCursor(Qt::OpenHandCursor), QColor(Qt::red).darker()); + QWidget* container = QWidget::createWindowContainer(w2); + container->winId(); // must make the container native, otherwise setCursor + // sets the cursor on a QWindowContainerClassWindow which + // is outside the QWindow hierarchy (macOS). + container->setParent(w1); + container->setCursor(Qt::PointingHandCursor); + container->setGeometry(0, 0, 100, 100); + + w1->show(); + } + + return app.exec(); +} diff --git a/tests/manual/qcursor/qcursor.pro b/tests/manual/qcursor/qcursor.pro index 0b5c2b1945..c6617b8e89 100644 --- a/tests/manual/qcursor/qcursor.pro +++ b/tests/manual/qcursor/qcursor.pro @@ -1,3 +1,3 @@ TEMPLATE = subdirs -SUBDIRS = allcursors grab_override qcursorhighdpi +SUBDIRS = allcursors childwidget childwindow childwindowcontainer grab_override qcursorhighdpi |