summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel
diff options
context:
space:
mode:
authorLeander Beernaert <leander.beernaert@qt.io>2020-01-22 13:47:08 +0100
committerLeander Beernaert <leander.beernaert@qt.io>2020-01-24 13:17:33 +0100
commit502d3d6744913899da87acfda5ebdab42c40329e (patch)
tree16658a328503bfd5a62b4fd5d69ffb66e9854b18 /tests/auto/gui/kernel
parentd1be8b9ceb2c7b20bbe53a07154c79699540ea3d (diff)
parent06bb315beb6c2c398223cfe52cbc7f66e14a8557 (diff)
Merge remote-tracking branch 'origin/dev' into merge-dev
Diffstat (limited to 'tests/auto/gui/kernel')
-rw-r--r--tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp51
-rw-r--r--tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp21
-rw-r--r--tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro2
-rw-r--r--tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp2
-rw-r--r--tests/auto/gui/kernel/qpalette/tst_qpalette.cpp89
5 files changed, 151 insertions, 14 deletions
diff --git a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
index 5ee25677bf..a7881b6983 100644
--- a/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
+++ b/tests/auto/gui/kernel/qguiapplication/tst_qguiapplication.cpp
@@ -506,29 +506,67 @@ void tst_QGuiApplication::keyboardModifiers()
window->close();
}
+/*
+ Compare actual against expected but ignore unset roles.
+
+ Comparing palettes via operator== will compare all roles.
+*/
+static bool palettesMatch(const QPalette &actual, const QPalette &expected)
+{
+ if (actual.resolve() != expected.resolve())
+ return false;
+
+ for (int i = 0; i < QPalette::NColorGroups; i++) {
+ for (int j = 0; j < QPalette::NColorRoles; j++) {
+ const auto g = QPalette::ColorGroup(i);
+ const auto r = QPalette::ColorRole(j);
+ if (expected.isBrushSet(g, r)) {
+ if (actual.brush(g, r) != expected.brush(g, r))
+ return false;
+ }
+ }
+ }
+ return true;
+}
+
void tst_QGuiApplication::palette()
{
+ // Getting the palette before application construction should work
+ QPalette paletteBeforeAppConstruction = QGuiApplication::palette();
+ // And should be reflected in the default constructed palette
+ QCOMPARE(paletteBeforeAppConstruction, QPalette());
+
int argc = 1;
char *argv[] = { const_cast<char*>("tst_qguiapplication") };
QGuiApplication app(argc, argv);
+
+ // The same should be true after application construction
+ QCOMPARE(QGuiApplication::palette(), QPalette());
+
+ // The default application palette is not resolved
+ QVERIFY(!QGuiApplication::palette().resolve());
+
QSignalSpy signalSpy(&app, SIGNAL(paletteChanged(QPalette)));
QPalette oldPalette = QGuiApplication::palette();
QPalette newPalette = QPalette(Qt::red);
QGuiApplication::setPalette(newPalette);
- QCOMPARE(QGuiApplication::palette(), newPalette);
+ QVERIFY(palettesMatch(QGuiApplication::palette(), newPalette));
QCOMPARE(signalSpy.count(), 1);
- QCOMPARE(signalSpy.at(0).at(0), QVariant(newPalette));
+ QVERIFY(palettesMatch(signalSpy.at(0).at(0).value<QPalette>(), newPalette));
+ QCOMPARE(QGuiApplication::palette(), QPalette());
QGuiApplication::setPalette(oldPalette);
- QCOMPARE(QGuiApplication::palette(), oldPalette);
+ QVERIFY(palettesMatch(QGuiApplication::palette(), oldPalette));
QCOMPARE(signalSpy.count(), 2);
- QCOMPARE(signalSpy.at(1).at(0), QVariant(oldPalette));
+ QVERIFY(palettesMatch(signalSpy.at(1).at(0).value<QPalette>(), oldPalette));
+ QCOMPARE(QGuiApplication::palette(), QPalette());
QGuiApplication::setPalette(oldPalette);
- QCOMPARE(QGuiApplication::palette(), oldPalette);
+ QVERIFY(palettesMatch(QGuiApplication::palette(), oldPalette));
QCOMPARE(signalSpy.count(), 2);
+ QCOMPARE(QGuiApplication::palette(), QPalette());
}
void tst_QGuiApplication::font()
@@ -1073,6 +1111,9 @@ void tst_QGuiApplication::testSetPaletteAttribute()
QGuiApplication::setPalette(palette);
QVERIFY(QCoreApplication::testAttribute(Qt::AA_SetPalette));
+
+ QGuiApplication::setPalette(QPalette());
+ QVERIFY(!QCoreApplication::testAttribute(Qt::AA_SetPalette));
}
// Test that static functions do not crash if there is no application instance.
diff --git a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
index a057ec2207..0b9fc3c9ae 100644
--- a/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
+++ b/tests/auto/gui/kernel/qguivariant/test/tst_qguivariant.cpp
@@ -113,6 +113,7 @@ private slots:
void guiVariantAtExit();
void iconEquality();
+ void qt4QPolygonFDataStream();
};
void tst_QGuiVariant::constructor_invalid_data()
@@ -783,5 +784,25 @@ void tst_QGuiVariant::iconEquality()
QVERIFY(a != b);
}
+void tst_QGuiVariant::qt4QPolygonFDataStream()
+{
+ qRegisterMetaTypeStreamOperators<QPolygonF>();
+
+ QByteArray data;
+ QDataStream stream(&data, QIODevice::WriteOnly);
+ stream.setVersion(QDataStream::Qt_4_8);
+ QPolygonF polygon;
+ polygon.append(QPointF(2, 3));
+ stream << QVariant::fromValue(polygon);
+ const QByteArray qt4Data = QByteArray::fromHex("0000007f000000000a51506f6c79676f6e46000000000140000000000000004008000000000000");
+ QCOMPARE(data, qt4Data);
+
+ QDataStream input(&data, QIODevice::ReadOnly);
+ input.setVersion(QDataStream::Qt_4_8);
+ QVariant result;
+ input >> result;
+ QCOMPARE(result.value<QPolygonF>(), polygon);
+}
+
QTEST_MAIN(tst_QGuiVariant)
#include "tst_qguivariant.moc"
diff --git a/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro b/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro
index 759b608c93..28b12f0677 100644
--- a/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro
+++ b/tests/auto/gui/kernel/qopenglwindow/qopenglwindow.pro
@@ -1,6 +1,6 @@
CONFIG += testcase
TARGET = tst_qopenglwindow
-QT += core-private gui-private testlib
+QT += opengl core-private gui-private testlib
SOURCES += tst_qopenglwindow.cpp
diff --git a/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp b/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp
index 9c36b6898a..2785d57a42 100644
--- a/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp
+++ b/tests/auto/gui/kernel/qopenglwindow/tst_qopenglwindow.cpp
@@ -26,7 +26,7 @@
**
****************************************************************************/
-#include <QtGui/QOpenGLWindow>
+#include <QtOpenGL/QOpenGLWindow>
#include <QtTest/QtTest>
#include <QtGui/QOpenGLFunctions>
#include <QtGui/QOpenGLContext>
diff --git a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp
index 6ce6422f48..04343727bb 100644
--- a/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp
+++ b/tests/auto/gui/kernel/qpalette/tst_qpalette.cpp
@@ -41,6 +41,12 @@ private Q_SLOTS:
void copySemantics();
void moveSemantics();
void setBrush();
+
+ void isBrushSet();
+ void setAllPossibleBrushes();
+ void noBrushesSetForDefaultPalette();
+ void cannotCheckIfInvalidBrushSet();
+ void checkIfBrushForCurrentGroupSet();
};
void tst_QPalette::roleValues_data()
@@ -118,23 +124,35 @@ void tst_QPalette::resolve()
QVERIFY(p2ResolvedTo1 != p2);
}
+
+static void compareAllPaletteData(const QPalette &firstPalette, const QPalette &secondPalette)
+{
+ QCOMPARE(firstPalette, secondPalette);
+
+ // For historical reasons, operator== compares only brushes, but it's not enough for proper
+ // comparison after move/copy, because some additional data can also be moved/copied.
+ // Let's compare this data here.
+ QCOMPARE(firstPalette.resolve(), secondPalette.resolve());
+ QCOMPARE(firstPalette.currentColorGroup(), secondPalette.currentColorGroup());
+}
+
void tst_QPalette::copySemantics()
{
QPalette src(Qt::red), dst;
const QPalette control = src; // copy construction
QVERIFY(src != dst);
QVERIFY(!src.isCopyOf(dst));
- QCOMPARE(src, control);
+ compareAllPaletteData(src, control);
QVERIFY(src.isCopyOf(control));
dst = src; // copy assignment
- QCOMPARE(dst, src);
- QCOMPARE(dst, control);
+ compareAllPaletteData(dst, src);
+ compareAllPaletteData(dst, control);
QVERIFY(dst.isCopyOf(src));
dst = QPalette(Qt::green);
QVERIFY(dst != src);
QVERIFY(dst != control);
- QCOMPARE(src, control);
+ compareAllPaletteData(src, control);
QVERIFY(!dst.isCopyOf(src));
QVERIFY(src.isCopyOf(control));
}
@@ -144,13 +162,13 @@ void tst_QPalette::moveSemantics()
QPalette src(Qt::red), dst;
const QPalette control = src;
QVERIFY(src != dst);
- QCOMPARE(src, control);
+ compareAllPaletteData(src, control);
QVERIFY(!dst.isCopyOf(src));
QVERIFY(!dst.isCopyOf(control));
dst = std::move(src); // move assignment
QVERIFY(!dst.isCopyOf(src)); // isCopyOf() works on moved-from palettes, too
QVERIFY(dst.isCopyOf(control));
- QCOMPARE(dst, control);
+ compareAllPaletteData(dst, control);
src = control; // check moved-from 'src' can still be assigned to (doesn't crash)
QVERIFY(src.isCopyOf(dst));
QVERIFY(src.isCopyOf(control));
@@ -158,7 +176,7 @@ void tst_QPalette::moveSemantics()
QVERIFY(!src.isCopyOf(dst));
QVERIFY(!src.isCopyOf(dst2));
QVERIFY(!src.isCopyOf(control));
- QCOMPARE(dst2, control);
+ compareAllPaletteData(dst2, control);
QVERIFY(dst2.isCopyOf(dst));
QVERIFY(dst2.isCopyOf(control));
// check moved-from 'src' can still be destroyed (doesn't crash)
@@ -194,5 +212,62 @@ void tst_QPalette::setBrush()
QVERIFY(pp.isCopyOf(p));
}
+void tst_QPalette::isBrushSet()
+{
+ QPalette p;
+
+ // Set only one color group
+ p.setBrush(QPalette::Active, QPalette::Mid, QBrush(Qt::red));
+ QVERIFY(p.isBrushSet(QPalette::Active, QPalette::Mid));
+ QVERIFY(!p.isBrushSet(QPalette::Inactive, QPalette::Mid));
+ QVERIFY(!p.isBrushSet(QPalette::Disabled, QPalette::Mid));
+
+ // Set all color groups
+ p.setBrush(QPalette::LinkVisited, QBrush(Qt::green));
+ QVERIFY(p.isBrushSet(QPalette::Active, QPalette::LinkVisited));
+ QVERIFY(p.isBrushSet(QPalette::Inactive, QPalette::LinkVisited));
+ QVERIFY(p.isBrushSet(QPalette::Disabled, QPalette::LinkVisited));
+}
+
+void tst_QPalette::setAllPossibleBrushes()
+{
+ QPalette p;
+
+ QCOMPARE(p.resolve(), QPalette::ResolveMask(0));
+
+ for (int r = 0; r < QPalette::NColorRoles; ++r) {
+ p.setBrush(QPalette::All, QPalette::ColorRole(r), Qt::red);
+ }
+
+ for (int r = 0; r < QPalette::NColorRoles; ++r) {
+ for (int g = 0; g < QPalette::NColorGroups; ++g) {
+ QVERIFY(p.isBrushSet(QPalette::ColorGroup(g), QPalette::ColorRole(r)));
+ }
+ }
+}
+
+void tst_QPalette::noBrushesSetForDefaultPalette()
+{
+ QCOMPARE(QPalette().resolve(), QPalette::ResolveMask(0));
+}
+
+void tst_QPalette::cannotCheckIfInvalidBrushSet()
+{
+ QPalette p(Qt::red);
+
+ QVERIFY(!p.isBrushSet(QPalette::All, QPalette::LinkVisited));
+ QVERIFY(!p.isBrushSet(QPalette::Active, QPalette::NColorRoles));
+}
+
+void tst_QPalette::checkIfBrushForCurrentGroupSet()
+{
+ QPalette p;
+
+ p.setCurrentColorGroup(QPalette::Disabled);
+ p.setBrush(QPalette::Current, QPalette::Link, QBrush(Qt::yellow));
+
+ QVERIFY(p.isBrushSet(QPalette::Current, QPalette::Link));
+}
+
QTEST_MAIN(tst_QPalette)
#include "tst_qpalette.moc"