summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-04-22 09:31:58 +0200
committerLiang Qi <liang.qi@qt.io>2016-04-25 14:03:45 +0200
commitbb4b86618dc930e0035c5829e336f2606d140ada (patch)
tree6e36808ca46244373bc70aabbb926cc114538beb /tests
parent276adc5a09914fd89d976bb90cc0cd67de9d3d6e (diff)
parentbbd1228b17ee3f3a5483f88b0a581d6a60c41cad (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: config.tests/unix/compile.test configure src/android/jar/src/org/qtproject/qt5/android/QtMessageDialogHelper.java src/corelib/global/qglobal.cpp src/widgets/kernel/qapplication.cpp src/widgets/styles/qwindowsvistastyle.cpp tests/auto/corelib/kernel/qobject/tst_qobject.cpp Change-Id: I067083f34e5290aa5f7565e40c30a069cc37b83a
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/corelib/io/qurl/tst_qurl.cpp32
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp19
-rw-r--r--tests/manual/qcursor/qcursorhighdpi/main.cpp69
-rw-r--r--tests/manual/widgets/styles/main.cpp232
-rw-r--r--tests/manual/widgets/styles/styles.pro7
-rw-r--r--tests/manual/widgets/widgets.pro2
6 files changed, 355 insertions, 6 deletions
diff --git a/tests/auto/corelib/io/qurl/tst_qurl.cpp b/tests/auto/corelib/io/qurl/tst_qurl.cpp
index 470d5b6434..73672f3572 100644
--- a/tests/auto/corelib/io/qurl/tst_qurl.cpp
+++ b/tests/auto/corelib/io/qurl/tst_qurl.cpp
@@ -143,6 +143,8 @@ private slots:
void hostFlags_data();
void hostFlags();
void setPort();
+ void port_data();
+ void port();
void toEncoded_data();
void toEncoded();
void setAuthority_data();
@@ -1742,6 +1744,9 @@ void tst_QUrl::symmetry()
QUrl url(QString::fromUtf8("http://www.räksmörgås.se/pub?a=b&a=dø&a=f#vræl"));
QCOMPARE(url.scheme(), QString::fromLatin1("http"));
QCOMPARE(url.host(), QString::fromUtf8("www.räksmörgås.se"));
+ QCOMPARE(url.host(QUrl::EncodeSpaces), QString::fromUtf8("www.räksmörgås.se"));
+ QCOMPARE(url.host(QUrl::EncodeUnicode), QString::fromUtf8("www.xn--rksmrgs-5wao1o.se"));
+ QCOMPARE(url.host(QUrl::EncodeUnicode | QUrl::EncodeSpaces), QString::fromUtf8("www.xn--rksmrgs-5wao1o.se"));
QCOMPARE(url.path(), QString::fromLatin1("/pub"));
// this will be encoded ...
QCOMPARE(url.encodedQuery().constData(), QString::fromLatin1("a=b&a=d%C3%B8&a=f").toLatin1().constData());
@@ -2200,8 +2205,6 @@ void tst_QUrl::strictParser_data()
// FIXME: add some tests for prohibited BiDi (RFC 3454 section 6)
// port errors happen in TolerantMode too
- QTest::newRow("empty-port-1") << "http://example.com:" << "Port field was empty";
- QTest::newRow("empty-port-2") << "http://example.com:/" << "Port field was empty";
QTest::newRow("invalid-port-1") << "http://example.com:-1" << "Invalid port";
QTest::newRow("invalid-port-2") << "http://example.com:abc" << "Invalid port";
QTest::newRow("invalid-port-3") << "http://example.com:9a" << "Invalid port";
@@ -2778,6 +2781,31 @@ void tst_QUrl::setPort()
}
}
+void tst_QUrl::port_data()
+{
+ QTest::addColumn<QString>("input");
+ QTest::addColumn<int>("port");
+
+ QTest::newRow("no-port-1") << "http://example.com" << -1;
+ QTest::newRow("no-port-2") << "http://example.com/" << -1;
+ QTest::newRow("empty-port-1") << "http://example.com:" << -1;
+ QTest::newRow("empty-port-2") << "http://example.com:/" << -1;
+ QTest::newRow("zero-port-1") << "http://example.com:0" << 0;
+ QTest::newRow("zero-port-2") << "http://example.com:0/" << 0;
+ QTest::newRow("set-port-1") << "http://example.com:80" << 80;
+ QTest::newRow("set-port-2") << "http://example.com:80/" << 80;
+}
+
+void tst_QUrl::port()
+{
+ QFETCH(QString, input);
+ QFETCH(int, port);
+
+ QUrl url(input);
+ QVERIFY(url.isValid());
+ QCOMPARE(url.port(), port);
+}
+
void tst_QUrl::toEncoded_data()
{
QTest::addColumn<QByteArray>("url");
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index 23f8ff5857..1902687eef 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -143,6 +143,7 @@ private slots:
void exceptions();
void noDeclarativeParentChangedOnDestruction();
void deleteLaterInAboutToBlockHandler();
+ void mutableFunctor();
};
struct QObjectCreatedOnShutdown
@@ -6512,6 +6513,24 @@ void tst_QObject::noDeclarativeParentChangedOnDestruction()
#endif
}
+struct MutableFunctor {
+ int count;
+ MutableFunctor() : count(0) {}
+ int operator()() { return ++count; }
+};
+
+void tst_QObject::mutableFunctor()
+{
+ ReturnValue o;
+ MutableFunctor functor;
+ QCOMPARE(functor.count, 0);
+ connect(&o, &ReturnValue::returnInt, functor);
+ QCOMPARE(emit o.returnInt(0), 1);
+ QCOMPARE(emit o.returnInt(0), 2); // each emit should increase the internal count
+
+ QCOMPARE(functor.count, 0); // but the original object should have been copied at connect time
+}
+
// Test for QtPrivate::HasQ_OBJECT_Macro
Q_STATIC_ASSERT(QtPrivate::HasQ_OBJECT_Macro<tst_QObject>::Value);
Q_STATIC_ASSERT(!QtPrivate::HasQ_OBJECT_Macro<SiblingDeleter>::Value);
diff --git a/tests/manual/qcursor/qcursorhighdpi/main.cpp b/tests/manual/qcursor/qcursorhighdpi/main.cpp
index 13c414fbbb..4a7646c39d 100644
--- a/tests/manual/qcursor/qcursorhighdpi/main.cpp
+++ b/tests/manual/qcursor/qcursorhighdpi/main.cpp
@@ -39,10 +39,12 @@
#include <QBitmap>
#include <QCursor>
+#include <QDrag>
#include <QPainter>
#include <QPixmap>
#include <QDebug>
+#include <QMimeData>
#include <QStringList>
#include <QTextStream>
@@ -63,6 +65,14 @@
#include <algorithm>
#include <iterator>
+#if QT_VERSION < 0x050000
+QDebug operator<<(QDebug d, const QPixmap &p)
+{
+ d.nospace() << "QPixmap(" << p.size() << ')';
+ return d;
+}
+#endif // Qt 4
+
// High DPI cursor test for testing cursor sizes in multi-screen setups.
// It creates one widget per screen with a grid of standard cursors,
// pixmap / bitmap cursors and pixmap / bitmap cursors with device pixel ratio 2.
@@ -154,6 +164,49 @@ static QCursor bitmapCursorDevicePixelRatio(int size, int dpr)
}
#endif // Qt 5
+// A label from which a pixmap can be dragged for testing drag with pixmaps/DPR.
+class DraggableLabel : public QLabel {
+public:
+ explicit DraggableLabel(const QPixmap &p, const QString &text, QWidget *parent = Q_NULLPTR)
+ : QLabel(text, parent), m_pixmap(p)
+ {
+ setToolTip(QLatin1String("Click to drag away the pixmap. Press Shift to set a circular mask."));
+ }
+
+protected:
+ void mousePressEvent(QMouseEvent *event) Q_DECL_OVERRIDE;
+
+private:
+ const QPixmap m_pixmap;
+};
+
+void DraggableLabel::mousePressEvent(QMouseEvent *)
+{
+ QMimeData *mimeData = new QMimeData;
+ mimeData->setImageData(qVariantFromValue(m_pixmap));
+ QDrag *drag = new QDrag(this);
+ QPixmap pixmap = m_pixmap;
+ if (QApplication::keyboardModifiers() & Qt::ShiftModifier) {
+ QBitmap mask(pixmap.width(), pixmap.height());
+ mask.clear();
+ QPainter painter(&mask);
+ painter.setBrush(Qt::color1);
+ const int hx = pixmap.width() / 2;
+ const int hy = pixmap.width() / 2;
+ painter.drawEllipse(QPoint(hx, hy), hx, hy);
+ pixmap.setMask(mask);
+ }
+ drag->setMimeData(mimeData);
+ drag->setPixmap(pixmap);
+ QPoint sizeP = QPoint(m_pixmap.width(), m_pixmap.height());
+#if QT_VERSION > 0x050000
+ sizeP /= int(m_pixmap.devicePixelRatio());
+#endif // Qt 5
+ drag->setHotSpot(sizeP / 2);
+ qDebug() << "Dragging:" << m_pixmap;
+ drag->exec(Qt::CopyAction | Qt::MoveAction, Qt::CopyAction);
+}
+
// Vertical ruler widget with 10 px marks
class VerticalRuler : public QWidget {
public:
@@ -205,8 +258,15 @@ static QLabel *createCursorLabel(const QCursor &cursor, const QString &additiona
#endif // Qt 5
if (!additionalText.isEmpty())
labelText += ' ' + additionalText;
- QLabel *result = new QLabel(labelText);
- result->setFrameShape(QFrame::Box);
+ const QPixmap cursorPixmap = cursor.pixmap();
+ QLabel *result = Q_NULLPTR;
+ if (cursorPixmap.size().isEmpty()) {
+ result = new QLabel(labelText);
+ result->setFrameShape(QFrame::Box);
+ } else {
+ result = new DraggableLabel(cursor.pixmap(), labelText);
+ result->setFrameShape(QFrame::StyledPanel);
+ }
result->setCursor(cursor);
return result;
}
@@ -299,7 +359,10 @@ int main(int argc, char *argv[])
QDesktopWidget *desktopWidget = app.desktop();
- for (int s = desktopWidget->screenCount() - 1; s >= 0; --s) {
+ const int lastScreen = arguments.contains("-p")
+ ? 0 // Primary screen only
+ : desktopWidget->screenCount() - 1; // All screens
+ for (int s = lastScreen; s >= 0; --s) {
MainWindowPtr window(new MainWindow(desktopWidget->screen(s)));
const QPoint pos = desktopWidget->screenGeometry(s).center() - QPoint(200, 100);
window->move(pos);
diff --git a/tests/manual/widgets/styles/main.cpp b/tests/manual/widgets/styles/main.cpp
new file mode 100644
index 0000000000..add9afd5b2
--- /dev/null
+++ b/tests/manual/widgets/styles/main.cpp
@@ -0,0 +1,232 @@
+/****************************************************************************
+**
+** Copyright (C) 2016 The Qt Company Ltd.
+** Contact: http://www.qt.io/licensing/
+**
+** This file is part of the test suite module 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 <QAction>
+#include <QApplication>
+#include <QDebug>
+#include <QGridLayout>
+#include <QLabel>
+#include <QMainWindow>
+#include <QMenu>
+#include <QMenuBar>
+#include <QPalette>
+#include <QPixmap>
+#include <QPlainTextEdit>
+#include <QStyle>
+#include <QTabWidget>
+#include <QTextStream>
+#include <QVBoxLayout>
+#include <QWindow>
+#include <QScreen>
+
+// Format enumeration value and strip off the class name
+// added by QDebug: "QStyle::StandardPixmap(SP_Icon)" -> "SP_Icon".
+template <typename Enum>
+static inline QString formatEnumValue(Enum value)
+{
+ QString result;
+ QDebug(&result) << value;
+ int index = result.indexOf(QLatin1Char('('));
+ if (index > 0) { // "QStyle::StandardPixmap(..)".
+ result.remove(0, index + 1);
+ index = result.lastIndexOf(QLatin1Char(')'));
+ if (index > 0)
+ result.truncate(index);
+ }
+ return result;
+}
+
+static QString pixmapDescription(QStyle::StandardPixmap sp, const QPixmap &pixmap)
+{
+ QString description = formatEnumValue(sp);
+ QTextStream str(&description);
+ str << '(' << int(sp) << ") ";
+ if (pixmap.isNull()) {
+ str << "(null)";
+ } else {
+ const qreal dpr = pixmap.devicePixelRatioF();
+ str << ' ' << pixmap.width() << 'x' << pixmap.height();
+ if (!qFuzzyCompare(dpr, qreal(1)))
+ str << " DPR=" << dpr;
+ }
+ return description;
+}
+
+// Display pixmaps returned by QStyle::standardPixmap() in a grid.
+static QWidget *createStandardPixmapPage(QWidget *parent)
+{
+ QWidget *result = new QWidget(parent);
+ QGridLayout *grid = new QGridLayout(result);
+ int row = 0;
+ int column = 0;
+ const int maxColumns = 6;
+ for (int i = 0; i <= int(QStyle::SP_LineEditClearButton); ++i) {
+ const QStyle::StandardPixmap sp = static_cast<QStyle::StandardPixmap>(i);
+ QPixmap pixmap = result->style()->standardPixmap(sp, Q_NULLPTR, result);
+ QLabel *descriptionLabel = new QLabel(pixmapDescription(sp, pixmap));
+ grid->addWidget(descriptionLabel, row, column++);
+ QLabel *displayLabel = new QLabel;
+ displayLabel->setPixmap(pixmap);
+ displayLabel->setFrameShape(QFrame::Box);
+ grid->addWidget(displayLabel, row, column++);
+ if (column >= maxColumns) {
+ ++row;
+ column = 0;
+ }
+ }
+ return result;
+}
+
+// Display values returned by QStyle::pixelMetric().
+static QWidget *createMetricsPage(QWidget *parent)
+{
+ QPlainTextEdit *result = new QPlainTextEdit(parent);
+ QString text;
+ QTextStream str(&text);
+ for (int i = 0; i <= int(QStyle::PM_HeaderDefaultSectionSizeVertical); ++i) {
+ const QStyle::PixelMetric m = static_cast<QStyle::PixelMetric>(i);
+ str << formatEnumValue(m) << '(' << int(m) << ")="
+ << result->style()->pixelMetric(m, Q_NULLPTR, result) << '\n';
+ }
+ result->setPlainText(text);
+ return result;
+}
+
+// Display values returned by QStyle::styleHint()
+static QWidget *createHintsPage(QWidget *parent)
+{
+ QPlainTextEdit *result = new QPlainTextEdit(parent);
+ QString text;
+ QTextStream str(&text);
+ for (int i = 0; i <= int(QStyle::SH_Menu_SubMenuDontStartSloppyOnLeave); ++i) {
+ const QStyle::StyleHint h = static_cast<QStyle::StyleHint>(i);
+ str << formatEnumValue(h) << '(' << int(h) << ")="
+ << result->style()->styleHint(h, Q_NULLPTR, result) << '\n';
+ }
+ result->setPlainText(text);
+ return result;
+}
+
+// Display palette colors
+static QWidget *createColorsPage(QWidget *parent)
+{
+ QWidget *result = new QWidget(parent);
+ QGridLayout *grid = new QGridLayout;
+ const QPalette palette = QGuiApplication::palette();
+ int row = 0;
+ for (int r = 0; r < int(QPalette::NColorRoles); ++r) {
+ const QPalette::ColorRole role = static_cast<QPalette::ColorRole>(r);
+ const QColor color = palette.color(QPalette::Active, role);
+ if (color.isValid()) {
+ const QString description =
+ formatEnumValue(role) + QLatin1Char('(') + QString::number(r)
+ + QLatin1String(") ") + color.name(QColor::HexArgb);
+ grid->addWidget(new QLabel(description), row, 0);
+ QLabel *displayLabel = new QLabel;
+ QPixmap pixmap(20, 20);
+ pixmap.fill(color);
+ displayLabel->setPixmap(pixmap);
+ displayLabel->setFrameShape(QFrame::Box);
+ grid->addWidget(displayLabel, row, 1);
+ ++row;
+ }
+ }
+ QHBoxLayout *hBox = new QHBoxLayout;
+ hBox->addLayout(grid);
+ hBox->addStretch();
+ QVBoxLayout *vBox = new QVBoxLayout(result);
+ vBox->addLayout(hBox);
+ vBox->addStretch();
+ return result;
+}
+
+class MainWindow : public QMainWindow {
+ Q_OBJECT
+public:
+ MainWindow();
+
+public slots:
+ void updateDescription();
+
+private:
+ QTabWidget *m_tabWidget;
+ QLabel *m_descriptionLabel;
+};
+
+MainWindow::MainWindow()
+ : m_tabWidget(new QTabWidget)
+ , m_descriptionLabel(new QLabel)
+{
+ QMenu *fileMenu = menuBar()->addMenu("&File");
+ QAction *a = fileMenu->addAction("Quit", this, &QWidget::close);
+ a->setShortcut(Qt::CTRL + Qt::Key_Q);
+
+ QWidget *central = new QWidget;
+ QVBoxLayout *mainLayout = new QVBoxLayout(central);
+ mainLayout->addWidget(m_descriptionLabel);
+ mainLayout->addWidget(m_tabWidget);
+ m_tabWidget->addTab(createStandardPixmapPage(m_tabWidget), "Standard Pixmaps");
+ m_tabWidget->addTab(createHintsPage(m_tabWidget), "Hints");
+ m_tabWidget->addTab(createMetricsPage(m_tabWidget), "Pixel Metrics");
+ m_tabWidget->addTab(createColorsPage(m_tabWidget), "Colors");
+ setCentralWidget(central);
+
+ setWindowTitle(QLatin1String("Style Tester (Qt") + QLatin1String(QT_VERSION_STR)
+ + QLatin1String(", ") + style()->objectName() + QLatin1Char(')'));
+}
+
+void MainWindow::updateDescription()
+{
+ QString text;
+ QTextStream str(&text);
+ str << "Qt " << QT_VERSION_STR << ", platform: " << QGuiApplication::platformName()
+ << ", Style: \"" << style()->objectName() << "\", DPR=" << devicePixelRatioF()
+ << ' ' << logicalDpiX() << ',' << logicalDpiY() << "DPI";
+ if (const QWindow *w = windowHandle())
+ str << ", Screen: \"" << w->screen()->name() << '"';
+ m_descriptionLabel->setText(text);
+}
+
+int main(int argc, char *argv[])
+{
+ QCoreApplication::setAttribute(Qt::AA_UseHighDpiPixmaps);
+ QApplication app(argc, argv);
+ MainWindow mw;
+ mw.show();
+ mw.updateDescription();
+ QObject::connect(mw.windowHandle(), &QWindow::screenChanged,
+ &mw, &MainWindow::updateDescription);
+ return app.exec();
+}
+
+#include "main.moc"
diff --git a/tests/manual/widgets/styles/styles.pro b/tests/manual/widgets/styles/styles.pro
new file mode 100644
index 0000000000..ef8217a9a3
--- /dev/null
+++ b/tests/manual/widgets/styles/styles.pro
@@ -0,0 +1,7 @@
+TEMPLATE = app
+QT = widgets
+CONFIG += console
+CONFIG -= app_bundle
+CONFIG += c++11
+
+SOURCES += main.cpp
diff --git a/tests/manual/widgets/widgets.pro b/tests/manual/widgets/widgets.pro
index e9dcdf39e7..3a128581cf 100644
--- a/tests/manual/widgets/widgets.pro
+++ b/tests/manual/widgets/widgets.pro
@@ -1,3 +1,3 @@
TEMPLATE = subdirs
SUBDIRS = itemviews qgraphicsview kernel
-
+greaterThan(QT_MAJOR_VERSION, 4): SUBDIRS += styles