summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2016-09-28 11:51:35 +0200
committerLiang Qi <liang.qi@qt.io>2016-09-28 11:51:35 +0200
commite918334045612ec2c7c6203845ad05c4a1972e87 (patch)
treeb59bf3a173c6bfa58c3ba9b5bb80df4a093247dc /tests/auto
parente3cbf0f1962958457f6e09fcfdc92d8cac4b6511 (diff)
parentcf0119bb69592d58ca7e6a75753799ebae61e4b5 (diff)
Merge remote-tracking branch 'origin/5.6' into 5.7
Conflicts: src/widgets/dialogs/qcolordialog.cpp src/widgets/dialogs/qfiledialog.cpp tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp Change-Id: I34bc8a990f8f526889a95a5c7099ef557b9681ad
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/corelib/kernel/qobject/tst_qobject.cpp76
-rw-r--r--tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp63
-rw-r--r--tests/auto/other/lancelot/tst_lancelot.cpp26
-rw-r--r--tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp25
-rw-r--r--tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp4
-rw-r--r--tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp8
-rw-r--r--tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp10
-rw-r--r--tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp8
8 files changed, 190 insertions, 30 deletions
diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
index b605b89f34..333305d603 100644
--- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
+++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp
@@ -6532,6 +6532,29 @@ signals:
CountedStruct mySignal(const CountedStruct &s1, CountedStruct s2);
};
+class CountedExceptionThrower : public QObject
+{
+ Q_OBJECT
+
+public:
+ explicit CountedExceptionThrower(bool throwException, QObject *parent = Q_NULLPTR)
+ : QObject(parent)
+ {
+ if (throwException)
+ throw ObjectException();
+ ++counter;
+ }
+
+ ~CountedExceptionThrower()
+ {
+ --counter;
+ }
+
+ static int counter;
+};
+
+int CountedExceptionThrower::counter = 0;
+
void tst_QObject::exceptions()
{
#ifndef QT_NO_EXCEPTIONS
@@ -6593,6 +6616,59 @@ void tst_QObject::exceptions()
}
QCOMPARE(countedStructObjectsCount, 0);
+ // Child object reaping in case of exceptions thrown by constructors
+ {
+ QCOMPARE(CountedExceptionThrower::counter, 0);
+
+ try {
+ class ParentObject : public QObject {
+ public:
+ explicit ParentObject(QObject *parent = Q_NULLPTR)
+ : QObject(parent)
+ {
+ new CountedExceptionThrower(false, this);
+ new CountedExceptionThrower(false, this);
+ new CountedExceptionThrower(true, this); // throws
+ }
+ };
+
+ ParentObject p;
+ QFAIL("Exception not thrown");
+ } catch (const ObjectException &) {
+ } catch (...) {
+ QFAIL("Wrong exception thrown");
+ }
+
+ QCOMPARE(CountedExceptionThrower::counter, 0);
+
+ try {
+ QObject o;
+ new CountedExceptionThrower(false, &o);
+ new CountedExceptionThrower(false, &o);
+ new CountedExceptionThrower(true, &o); // throws
+
+ QFAIL("Exception not thrown");
+ } catch (const ObjectException &) {
+ } catch (...) {
+ QFAIL("Wrong exception thrown");
+ }
+
+ QCOMPARE(CountedExceptionThrower::counter, 0);
+
+ try {
+ QObject o;
+ CountedExceptionThrower c1(false, &o);
+ CountedExceptionThrower c2(false, &o);
+ CountedExceptionThrower c3(true, &o); // throws
+
+ QFAIL("Exception not thrown");
+ } catch (const ObjectException &) {
+ } catch (...) {
+ QFAIL("Wrong exception thrown");
+ }
+
+ QCOMPARE(CountedExceptionThrower::counter, 0);
+ }
#else
QSKIP("Needs exceptions");
diff --git a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
index f36528f17d..00c3a41d88 100644
--- a/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
+++ b/tests/auto/network/ssl/qsslsocket/tst_qsslsocket.cpp
@@ -223,6 +223,7 @@ private slots:
void ecdhServer();
void verifyClientCertificate_data();
void verifyClientCertificate();
+ void readBufferMaxSize();
#ifndef QT_NO_OPENSSL
void simplePskConnect_data();
@@ -3037,6 +3038,68 @@ void tst_QSslSocket::verifyClientCertificate()
QCOMPARE(client->isEncrypted(), works);
}
+void tst_QSslSocket::readBufferMaxSize()
+{
+#ifdef QT_SECURETRANSPORT
+ // QTBUG-55170:
+ // SecureTransport back-end was ignoring read-buffer
+ // size limit, resulting (potentially) in a constantly
+ // growing internal buffer.
+ // The test's logic is: we set a small read buffer size on a client
+ // socket (to some ridiculously small value), server sends us
+ // a bunch of bytes , we ignore readReady signal so
+ // that socket's internal buffer size stays
+ // >= readBufferMaxSize, we wait for a quite long time
+ // (which previously would be enough to read completely)
+ // and we check socket's bytesAvaiable to be less than sent.
+ QFETCH_GLOBAL(bool, setProxy);
+ if (setProxy)
+ return;
+
+ SslServer server;
+ QVERIFY(server.listen());
+
+ QEventLoop loop;
+
+ QSslSocketPtr client(new QSslSocket);
+ socket = client.data();
+ connect(socket, SIGNAL(error(QAbstractSocket::SocketError)), &loop, SLOT(quit()));
+ connect(socket, SIGNAL(sslErrors(QList<QSslError>)), this, SLOT(ignoreErrorSlot()));
+ connect(socket, SIGNAL(encrypted()), &loop, SLOT(quit()));
+
+ client->connectToHostEncrypted(QHostAddress(QHostAddress::LocalHost).toString(),
+ server.serverPort());
+
+ // Wait for 'encrypted' first:
+ QTimer::singleShot(5000, &loop, SLOT(quit()));
+ loop.exec();
+
+ QCOMPARE(client->state(), QAbstractSocket::ConnectedState);
+ QCOMPARE(client->mode(), QSslSocket::SslClientMode);
+
+ client->setReadBufferSize(10);
+ const QByteArray message(int(0xffff), 'a');
+ server.socket->write(message);
+
+ QTimer::singleShot(5000, &loop, SLOT(quit()));
+ loop.exec();
+
+ int readSoFar = client->bytesAvailable();
+ QVERIFY(readSoFar > 0 && readSoFar < message.size());
+ // Now, let's check that we still can read the rest of it:
+ QCOMPARE(client->readAll().size(), readSoFar);
+
+ client->setReadBufferSize(0);
+
+ QTimer::singleShot(1500, &loop, SLOT(quit()));
+ loop.exec();
+
+ QCOMPARE(client->bytesAvailable() + readSoFar, message.size());
+#else
+ // Not needed, QSslSocket works correctly with other back-ends.
+#endif
+}
+
void tst_QSslSocket::setEmptyDefaultConfiguration() // this test should be last, as it has some side effects
{
// used to produce a crash in QSslConfigurationPrivate::deepCopyDefaultConfiguration, QTBUG-13265
diff --git a/tests/auto/other/lancelot/tst_lancelot.cpp b/tests/auto/other/lancelot/tst_lancelot.cpp
index 3f35712489..81c5926f3a 100644
--- a/tests/auto/other/lancelot/tst_lancelot.cpp
+++ b/tests/auto/other/lancelot/tst_lancelot.cpp
@@ -71,6 +71,10 @@ private slots:
void testRasterRGB32();
void testRasterRGB16_data();
void testRasterRGB16();
+ void testRasterARGB8565PM_data();
+ void testRasterARGB8565PM();
+ void testRasterGrayscale8_data();
+ void testRasterGrayscale8();
#ifndef QT_NO_OPENGL
void testOpenGL_data();
@@ -150,6 +154,28 @@ void tst_Lancelot::testRasterRGB16()
}
+void tst_Lancelot::testRasterARGB8565PM_data()
+{
+ setupTestSuite();
+}
+
+void tst_Lancelot::testRasterARGB8565PM()
+{
+ runTestSuite(Raster, QImage::Format_ARGB8565_Premultiplied);
+}
+
+
+void tst_Lancelot::testRasterGrayscale8_data()
+{
+ setupTestSuite();
+}
+
+void tst_Lancelot::testRasterGrayscale8()
+{
+ runTestSuite(Raster, QImage::Format_Grayscale8);
+}
+
+
#ifndef QT_NO_OPENGL
bool tst_Lancelot::checkSystemGLSupport()
{
diff --git a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
index b7e8cded7a..ab9729342c 100644
--- a/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
+++ b/tests/auto/widgets/kernel/qapplication/tst_qapplication.cpp
@@ -1755,25 +1755,6 @@ void tst_QApplication::focusOut()
QTest::qWait(2000);
}
-class SpontaneousEvent
-{
- Q_GADGET
- QDOC_PROPERTY(bool accepted READ isAccepted WRITE setAccepted)
- Q_ENUMS(Type)
-public:
- enum Type {
- Void
- };
-
- virtual ~SpontaneousEvent() {}
-
- QEventPrivate *d;
- ushort t;
-
- ushort posted : 1;
- ushort spont : 1;
-};
-
void tst_QApplication::focusMouseClick()
{
int argc = 1;
@@ -1791,14 +1772,14 @@ void tst_QApplication::focusMouseClick()
// now send a mouse button press event and check what happens with the focus
// it should be given to the parent widget
QMouseEvent ev(QEvent::MouseButtonPress, QPointF(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
- reinterpret_cast<SpontaneousEvent *>(&ev)->spont = 1;
+ QSpontaneKeyEvent::setSpontaneous(&ev);
QVERIFY(ev.spontaneous());
qApp->notify(&w2, &ev);
QCOMPARE(QApplication::focusWidget(), &w);
// then we give the inner widget strong focus -> it should get focus
w2.setFocusPolicy(Qt::StrongFocus);
- reinterpret_cast<SpontaneousEvent *>(&ev)->spont = 1;
+ QSpontaneKeyEvent::setSpontaneous(&ev);
QVERIFY(ev.spontaneous());
qApp->notify(&w2, &ev);
QTRY_COMPARE(QApplication::focusWidget(), &w2);
@@ -1806,7 +1787,7 @@ void tst_QApplication::focusMouseClick()
// now back to tab focus and click again (it already had focus) -> focus should stay
// (focus was revoked as of QTBUG-34042)
w2.setFocusPolicy(Qt::TabFocus);
- reinterpret_cast<SpontaneousEvent *>(&ev)->spont = 1;
+ QSpontaneKeyEvent::setSpontaneous(&ev);
QVERIFY(ev.spontaneous());
qApp->notify(&w2, &ev);
QCOMPARE(QApplication::focusWidget(), &w2);
diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp
index e87598617a..0b35db1b5f 100644
--- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp
+++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp
@@ -183,7 +183,7 @@ void tst_QBoxLayout::sizeConstraints()
window.show();
QTest::qWaitForWindowExposed(&window);
QSize sh = window.sizeHint();
- lay->takeAt(1);
+ delete lay->takeAt(1);
QVERIFY(sh.width() >= window.sizeHint().width() &&
sh.height() >= window.sizeHint().height());
@@ -512,7 +512,7 @@ void tst_QBoxLayout::replaceWidget()
QCOMPARE(boxLayout->indexOf(replaceFrom), 1);
QCOMPARE(boxLayout->indexOf(replaceTo), -1);
- boxLayout->replaceWidget(replaceFrom, replaceTo);
+ delete boxLayout->replaceWidget(replaceFrom, replaceTo);
QCOMPARE(boxLayout->indexOf(replaceFrom), -1);
QCOMPARE(boxLayout->indexOf(replaceTo), 1);
diff --git a/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp b/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp
index 07dcfca28f..e5da83ed37 100644
--- a/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp
+++ b/tests/auto/widgets/kernel/qgridlayout/tst_qgridlayout.cpp
@@ -348,6 +348,8 @@ void tst_QGridLayout::setMinAndMaxSize()
layout.removeItem(spacer);
+ delete spacer;
+ spacer = Q_NULLPTR;
rightChild.hide();
QApplication::sendPostedEvents(0, 0);
@@ -1598,10 +1600,10 @@ void tst_QGridLayout::contentsRect()
void tst_QGridLayout::distributeMultiCell()
{
QWidget w;
- Qt42Style *style = new Qt42Style();
- style->spacing = 9;
+ Qt42Style style;
+ style.spacing = 9;
- w.setStyle(style);
+ w.setStyle(&style);
QGridLayout grid;
w.setLayout(&grid);
diff --git a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
index bbff9f0e50..272e6ef02f 100644
--- a/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
+++ b/tests/auto/widgets/kernel/qwidget/tst_qwidget.cpp
@@ -5130,7 +5130,8 @@ void tst_QWidget::moveChild()
ColorWidget parent(0, Qt::Window | Qt::WindowStaysOnTopHint);
// prevent custom styles
- parent.setStyle(QStyleFactory::create(QLatin1String("Windows")));
+ const QScopedPointer<QStyle> style(QStyleFactory::create(QLatin1String("Windows")));
+ parent.setStyle(style.data());
ColorWidget child(&parent, Qt::Widget, Qt::blue);
#ifndef Q_OS_WINCE
@@ -5179,7 +5180,8 @@ void tst_QWidget::showAndMoveChild()
QSKIP("Wayland: This fails. Figure out why.");
QWidget parent(0, Qt::Window | Qt::WindowStaysOnTopHint);
// prevent custom styles
- parent.setStyle(QStyleFactory::create(QLatin1String("Windows")));
+ const QScopedPointer<QStyle> style(QStyleFactory::create(QLatin1String("Windows")));
+ parent.setStyle(style.data());
QDesktopWidget desktop;
QRect desktopDimensions = desktop.availableGeometry(&parent);
@@ -6675,7 +6677,9 @@ void tst_QWidget::renderWithPainter()
{
QWidget widget(0, Qt::Tool);
// prevent custom styles
- widget.setStyle(QStyleFactory::create(QLatin1String("Windows")));
+
+ const QScopedPointer<QStyle> style(QStyleFactory::create(QLatin1String("Windows")));
+ widget.setStyle(style.data());
widget.show();
widget.resize(70, 50);
widget.setAutoFillBackground(true);
diff --git a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
index 831d7257ba..31eb05a957 100644
--- a/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
+++ b/tests/auto/widgets/widgets/qdatetimeedit/tst_qdatetimeedit.cpp
@@ -245,6 +245,7 @@ private slots:
void timeSpec_data();
void timeSpec();
void timeSpecBug();
+ void timeSpecInit();
void monthEdgeCase();
void setLocale();
@@ -3200,6 +3201,13 @@ void tst_QDateTimeEdit::timeSpecBug()
QCOMPARE(oldText, testWidget->text());
}
+void tst_QDateTimeEdit::timeSpecInit()
+{
+ QDateTime utc(QDate(2000, 1, 1), QTime(12, 0, 0), Qt::UTC);
+ QDateTimeEdit widget(utc);
+ QCOMPARE(widget.dateTime(), utc);
+}
+
void tst_QDateTimeEdit::cachedDayTest()
{
testWidget->setDisplayFormat("MM/dd");