summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorJani Hautakangas <jani.hautakangas@nokia.com>2011-06-22 11:38:32 (GMT)
committerJani Hautakangas <jani.hautakangas@nokia.com>2011-06-22 11:38:32 (GMT)
commit14f10211e72f2d04fa7f4e0faa430eb94c1f8f83 (patch)
tree1e8d1e2f758c1090a15123cbcb8f615d867caa47 /tests
parente4cce8849bf45be9a111072e3fca7bdf67364e8a (diff)
parent5e80b137d195625c0d57c1c27e5e8464d1ccfa33 (diff)
downloadQt-14f10211e72f2d04fa7f4e0faa430eb94c1f8f83.zip
Qt-14f10211e72f2d04fa7f4e0faa430eb94c1f8f83.tar.gz
Qt-14f10211e72f2d04fa7f4e0faa430eb94c1f8f83.tar.bz2
Merge remote branch 'origin/4.7' into qt-4.8-from-4.7
Conflicts: src/opengl/qgl.cpp src/opengl/qpixmapdata_symbiangl.cpp src/opengl/qwindowsurface_gl.cpp
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp265
-rw-r--r--tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp41
-rw-r--r--tests/auto/qwidget/tst_qwidget.cpp14
3 files changed, 300 insertions, 20 deletions
diff --git a/tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp b/tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp
index d5d56fc..cd91008 100644
--- a/tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp
+++ b/tests/auto/qgraphicslayout/tst_qgraphicslayout.cpp
@@ -63,6 +63,14 @@ private slots:
void automaticReparenting();
void verifyActivate();
void invalidate();
+ void moveAndResize_data();
+ void moveAndResize();
+ void moveAndResizeWidgetInWidget_data();
+ void moveAndResizeWidgetInWidget();
+ void changingMinimumSize_data();
+ void changingMinimumSize();
+ void invalidateAndMove_data();
+ void invalidateAndMove();
void constructors();
void alternativeLayoutItems();
void ownership();
@@ -443,7 +451,7 @@ void tst_QGraphicsLayout::invalidate()
QCoreApplication::sendPostedEvents();
QCOMPARE(a->eventCount(QEvent::LayoutRequest), 1);
QCOMPARE(b->eventCount(QEvent::LayoutRequest), 0);
- QCOMPARE(c->eventCount(QEvent::LayoutRequest), 1);
+ QCOMPARE(c->eventCount(QEvent::GraphicsSceneResize), 1);
QCOMPARE(d->eventCount(QEvent::LayoutRequest), 0);
QCOMPARE(a->functionCount[SetGeometry], 1);
@@ -479,30 +487,18 @@ void tst_QGraphicsLayout::invalidate()
QCOMPARE(c->eventCount(QEvent::LayoutRequest), 0);
QCoreApplication::sendPostedEvents();
- QCOMPARE(a->eventCount(QEvent::LayoutRequest), 1);
+ QCOMPARE(a->eventCount(QEvent::GraphicsSceneResize), 1);
QCOMPARE(b->eventCount(QEvent::LayoutRequest), 0);
- QCOMPARE(c->eventCount(QEvent::LayoutRequest), 1);
+ QCOMPARE(c->eventCount(QEvent::GraphicsSceneResize), 1);
QCOMPARE(d->eventCount(QEvent::LayoutRequest), 0);
QCOMPARE(a->functionCount[SetGeometry], 1);
- /* well, ideally one call to setGeometry(), but it will currently
- * get two calls to setGeometry():
- * 1. The first LayoutRequest will call activate() - that will call
- * setGeometry() on the layout. This geometry will be based on
- * the widget geometry which is not correct at this moment.
- * (it is still 150 wide)
- * 2. Next, we check if the widget is top level, and then we call
- * parentWidget->resize(parentWidget->size());
- * This will be adjusted to be minimum 200 pixels wide.
- * The new size will then be propagated down to the layout
- *
- */
- QCOMPARE(alay->functionCount[SetGeometry], 2);
-
- QCOMPARE(b->functionCount[SetGeometry], 2);
- QCOMPARE(c->functionCount[SetGeometry], 2);
- QCOMPARE(d->functionCount[SetGeometry], 2);
+ QCOMPARE(alay->functionCount[SetGeometry], 1);
+
+ QCOMPARE(b->functionCount[SetGeometry], 1);
+ QCOMPARE(c->functionCount[SetGeometry], 1);
+ QCOMPARE(d->functionCount[SetGeometry], 1);
// f actually got wider, need to rearrange its siblings
QCOMPARE(blay->functionCount[SetGeometry], 1);
QCOMPARE(clay->functionCount[SetGeometry], 1);
@@ -555,7 +551,236 @@ void tst_QGraphicsLayout::invalidate()
QGraphicsLayout::setInstantInvalidatePropagation(false);
}
+void tst_QGraphicsLayout::changingMinimumSize_data()
+{
+ QTest::addColumn<bool>("instantInvalidatePropagation");
+ QTest::newRow("Without instantInvalidatePropagation") << false;
+ QTest::newRow("With instantInvalidatePropagation") << true;
+}
+void tst_QGraphicsLayout::changingMinimumSize()
+{
+ QFETCH(bool, instantInvalidatePropagation);
+ QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation);
+ QGraphicsWidget *widget = new QGraphicsWidget;
+ qApp->processEvents();
+ widget->setMinimumSize(300,300);
+ qApp->processEvents();
+ QCOMPARE(widget->size(), QSizeF(300,300));
+ QGraphicsLayout::setInstantInvalidatePropagation(false);
+}
+
+struct WidgetToTestResizeEvents : public QGraphicsWidget
+{
+ virtual void resizeEvent ( QGraphicsSceneResizeEvent * event )
+ {
+ QGraphicsWidget::resizeEvent(event);
+ resizeEventCalled = true;
+ }
+
+ bool resizeEventCalled;
+};
+
+void tst_QGraphicsLayout::moveAndResizeWidgetInWidget_data()
+{
+ QTest::addColumn<bool>("instantInvalidatePropagation");
+
+ QTest::newRow("Without instantInvalidatePropagation") << false;
+ QTest::newRow("With instantInvalidatePropagation") << true;
+}
+void tst_QGraphicsLayout::moveAndResizeWidgetInWidget()
+{
+ QFETCH(bool, instantInvalidatePropagation);
+ QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation);
+ QGraphicsScene scene;
+
+ QGraphicsWidget *widget = new QGraphicsWidget;
+ QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(widget);
+ layout->setContentsMargins(0,0,0,0);
+ WidgetToTestResizeEvents *innerWidget = new WidgetToTestResizeEvents;
+ QGraphicsLinearLayout *innerLayout = new QGraphicsLinearLayout(innerWidget);
+ innerLayout->setContentsMargins(0,0,0,0);
+ QCOMPARE(widget->maximumSize(), QSizeF(QWIDGETSIZE_MAX, QWIDGETSIZE_MAX));
+ layout->addItem(innerWidget);
+ widget->setMinimumSize(1,1);
+ widget->setPreferredSize(1000,1000);
+ widget->setMaximumSize(2000,2000);
+ widget->resize(widget->preferredSize());
+ innerWidget->setMinimumSize(1,1);
+ qApp->processEvents();
+ innerWidget->resizeEventCalled = false;
+
+ QCOMPARE(widget->size(), QSizeF(1000, 1000));
+ QCOMPARE(layout->geometry().size(), QSizeF(1000, 1000));
+ QCOMPARE(innerWidget->size(), QSizeF(1000, 1000));
+
+ innerLayout->invalidate();
+ widget->setMaximumHeight(500);
+ widget->setX(1);
+ qApp->processEvents();
+ QCOMPARE(widget->size(), QSizeF(1000, 500));
+ QCOMPARE(innerWidget->size(), QSizeF(1000, 500));
+ QVERIFY(innerWidget->resizeEventCalled);
+}
+void tst_QGraphicsLayout::moveAndResize_data()
+{
+ QTest::addColumn<bool>("instantInvalidatePropagation");
+ QTest::addColumn<bool>("insideLayout");
+ QTest::addColumn<bool>("insideLayoutInLayout");
+ QTest::addColumn<bool>("insideWidget");
+ QTest::newRow("Without instantInvalidatePropagation") << false << false << false << false;
+ QTest::newRow("With instantInvalidatePropagation") << true << false << false << false;
+ QTest::newRow("Without instantInvalidatePropagation, inside widget with no layout") << false << false << false << true;
+ QTest::newRow("With instantInvalidatePropagation, inside widget with no layout") << true << false << false << true;
+ QTest::newRow("Without instantInvalidatePropagation, inside widget with layout") << false << true << false << true;
+ QTest::newRow("With instantInvalidatePropagation, inside widget with layout") << true << true << false << true;
+ QTest::newRow("Without instantInvalidatePropagation, inside widget with layout in layout") << false << true << true << true;
+ QTest::newRow("With instantInvalidatePropagation, inside widget with layout in layout") << true << true << true << true;
+
+}
+void tst_QGraphicsLayout::moveAndResize()
+{
+ QFETCH(bool, instantInvalidatePropagation);
+ QFETCH(bool, insideLayout);
+ QFETCH(bool, insideLayoutInLayout);
+ QFETCH(bool, insideWidget);
+ QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation);
+ QGraphicsScene scene;
+
+ WidgetToTestResizeEvents *widget = new WidgetToTestResizeEvents;
+
+ /* Setup its parent if we want them */
+ QGraphicsWidget *parent = NULL;
+ if (insideWidget)
+ parent = new QGraphicsWidget;
+ if (insideLayout) {
+ QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(parent);
+ QGraphicsLinearLayout *innerLayout = NULL;
+ if (insideLayoutInLayout) {
+ innerLayout = new QGraphicsLinearLayout;
+ layout->addItem(innerLayout);
+ innerLayout->addItem(widget);
+ } else
+ layout->addItem(widget);
+ } else if (insideWidget) {
+ widget->setParentItem(parent);
+ }
+
+ new QGraphicsLinearLayout(widget);
+ widget->setGeometry(0,0,100,100);
+ qApp->processEvents();
+ widget->resizeEventCalled = false;
+
+ /* Force it grow by changing the minimum size */
+ widget->setMinimumSize(200,200);
+ qApp->processEvents();
+ qApp->processEvents();
+ qApp->processEvents();
+ QCOMPARE(widget->size(), QSizeF(200,200));
+ QVERIFY(widget->resizeEventCalled);
+ widget->resizeEventCalled = false;
+
+ /* Call setPos followed by a resize. We should get a resize event */
+ widget->setPos(10,10);
+ widget->resize(300,300);
+ qApp->processEvents();
+ QVERIFY(widget->resizeEventCalled);
+ widget->resizeEventCalled = false;
+
+ /* Check that just calling setGeometry gives us a resize event */
+ widget->setGeometry(10,10, 400, 400);
+ qApp->processEvents();
+ QVERIFY(widget->resizeEventCalled);
+ widget->resizeEventCalled = false;
+
+ /* Now call setPos followed by increasing the size using setGeometry,*/
+ widget->setPos(30,30);
+ widget->setGeometry(10,10, 500, 500);
+ qApp->processEvents();
+ QVERIFY(widget->resizeEventCalled);
+ widget->resizeEventCalled = false;
+
+ /* Now call setPos followed by increasing the minimum size, to force it to grow */
+ widget->setMinimumSize(600,600);
+ widget->setPos(30,30);
+ qApp->processEvents();
+ QCOMPARE(widget->size(), QSizeF(600,600));
+ QVERIFY(widget->resizeEventCalled);
+ widget->resizeEventCalled = false;
+
+ QGraphicsLayout::setInstantInvalidatePropagation(false);
+}
+void tst_QGraphicsLayout::invalidateAndMove_data()
+{
+ QTest::addColumn<bool>("instantInvalidatePropagation");
+ QTest::newRow("Without instantInvalidatePropagation") << false;
+ QTest::newRow("With instantInvalidatePropagation") << true;
+
+}
+void tst_QGraphicsLayout::invalidateAndMove()
+{
+ // Check that if we set the position of an item and invalidate its layout at the same
+ // time, the widget keeps its correct size
+ QFETCH(bool, instantInvalidatePropagation);
+ QGraphicsLayout::setInstantInvalidatePropagation(instantInvalidatePropagation);
+ QGraphicsScene scene;
+
+ QGraphicsWidget *widget = new QGraphicsWidget;
+ new QGraphicsLinearLayout(widget);
+
+ widget->setMinimumSize(1,1);
+ widget->setPreferredSize(34,34);
+ widget->setMaximumSize(100,100);
+ widget->resize(widget->preferredSize());
+
+ scene.addItem(widget);
+
+ qApp->processEvents();
+
+ /* Invalidate and reactivate. The size should not have changed */
+ widget->layout()->invalidate();
+ widget->layout()->activate();
+
+ QCOMPARE(widget->geometry().size(), widget->preferredSize());
+ QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());
+ qApp->processEvents();
+ QCOMPARE(widget->geometry().size(), widget->preferredSize());
+ QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());
+
+ widget->layout()->invalidate();
+ widget->setX(1); //Change just the position using setX
+ QCOMPARE(widget->geometry().size(), widget->preferredSize());
+ QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());
+ qApp->processEvents();
+ QCOMPARE(widget->geometry().size(), widget->preferredSize());
+ QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());
+
+ widget->layout()->invalidate();
+ widget->setGeometry(1,1,34,34); //Change just the position using setGeometry
+ QCOMPARE(widget->geometry().size(), widget->preferredSize());
+ QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());
+ qApp->processEvents();
+ QCOMPARE(widget->geometry().size(), widget->preferredSize());
+ QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());
+
+ widget->layout()->invalidate();
+ widget->setGeometry(1,1,60,60); //Change just the size using setGeometry
+ QCOMPARE(widget->geometry().size(), QSizeF(60,60));
+ QCOMPARE(widget->layout()->geometry().size(), QSizeF(60,60));
+ qApp->processEvents();
+ QCOMPARE(widget->geometry().size(), QSizeF(60,60));
+ QCOMPARE(widget->layout()->geometry().size(), QSizeF(60,60));
+
+ widget->layout()->invalidate();
+ widget->setGeometry(0,0,34,34); //Change the size and position using setGeometry
+ QCOMPARE(widget->geometry().size(), widget->preferredSize());
+ QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());
+ qApp->processEvents();
+ QCOMPARE(widget->geometry().size(), widget->preferredSize());
+ QCOMPARE(widget->layout()->geometry().size(), widget->preferredSize());
+
+ QGraphicsLayout::setInstantInvalidatePropagation(false);
+}
class Layout : public QGraphicsLayout
{
public:
diff --git a/tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp b/tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
index 1b4256b..d1c376a 100644
--- a/tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
+++ b/tests/auto/qnetworkcookiejar/tst_qnetworkcookiejar.cpp
@@ -52,6 +52,7 @@ private slots:
void getterSetter();
void setCookiesFromUrl_data();
void setCookiesFromUrl();
+ void setCookiesFromUrl_50CookiesLimitPerDomain();
void cookiesForUrl_data();
void cookiesForUrl();
void effectiveTLDs_data();
@@ -251,6 +252,46 @@ void tst_QNetworkCookieJar::setCookiesFromUrl()
QVERIFY2(result.isEmpty(), QTest::toString(result));
}
+static bool findCookieName(const QList<QNetworkCookie> &cookieList, const QString &name)
+{
+ foreach(QNetworkCookie cookie, cookieList)
+ if (cookie.name() == name)
+ return true;
+ return false;
+}
+
+void tst_QNetworkCookieJar::setCookiesFromUrl_50CookiesLimitPerDomain()
+{
+ QNetworkCookie cookie;
+ cookie.setValue("value");
+ MyCookieJar jar;
+ QUrl url("http://a.b.c.com");
+
+ for (int i = 0; i < 20; ++i) {
+ // Add a list of 3 domain-matched cookies on each iteration for a total of 60 cookies.
+ QList<QNetworkCookie> cookieList;
+ cookie.setName(QString("CookieNo%1").arg(i*3+1).toAscii());
+ cookie.setDomain("a.b.c.com");
+ cookieList += cookie;
+ cookie.setName(QString("CookieNo%1").arg(i*3+2).toAscii());
+ cookie.setDomain(".b.c.com");
+ cookieList += cookie;
+ cookie.setName(QString("CookieNo%1").arg(i*3+3).toAscii());
+ cookie.setDomain(".c.com");
+ cookieList += cookie;
+ jar.setCookiesFromUrl(cookieList, url);
+
+ int expectedNumCookies = std::min((i+1)*3, 50);
+ QCOMPARE(jar.allCookies().size(), expectedNumCookies);
+ }
+
+ // Verify that the oldest cookies were the ones overwritten.
+ QVERIFY(!findCookieName(jar.allCookies(), "CookieNo1"));
+ QVERIFY(!findCookieName(jar.allCookies(), "CookieNo10"));
+ QVERIFY(findCookieName(jar.allCookies(), "CookieNo11"));
+ QVERIFY(findCookieName(jar.allCookies(), "CookieNo60"));
+}
+
void tst_QNetworkCookieJar::cookiesForUrl_data()
{
QTest::addColumn<QList<QNetworkCookie> >("allCookies");
diff --git a/tests/auto/qwidget/tst_qwidget.cpp b/tests/auto/qwidget/tst_qwidget.cpp
index 5550fe8..86773ad 100644
--- a/tests/auto/qwidget/tst_qwidget.cpp
+++ b/tests/auto/qwidget/tst_qwidget.cpp
@@ -71,6 +71,7 @@
#include <QtGui/qpaintengine.h>
#include <private/qbackingstore_p.h>
#include <qmenubar.h>
+#include <qtableview.h>
#include <QtGui/QGraphicsView>
#include <QtGui/QGraphicsProxyWidget>
@@ -406,6 +407,7 @@ private slots:
void childAt();
#ifdef Q_WS_MAC
void childAt_unifiedToolBar();
+ void taskQTBUG_17333_ResizeInfiniteRecursion();
#ifdef QT_MAC_USE_COCOA
void taskQTBUG_11373();
#endif // QT_MAC_USE_COCOA
@@ -10572,6 +10574,18 @@ void tst_QWidget::childAt_unifiedToolBar()
QCOMPARE(mainWindow.childAt(labelTopLeft), static_cast<QWidget *>(label));
}
+void tst_QWidget::taskQTBUG_17333_ResizeInfiniteRecursion()
+{
+ QTableView tb;
+ const char *s = "border: 1px solid;";
+ tb.setStyleSheet(s);
+ tb.show();
+
+ QTest::qWaitForWindowShown(&tb);
+ tb.setGeometry(QRect(100, 100, 0, 100));
+ // No crash, it works.
+}
+
#ifdef QT_MAC_USE_COCOA
void tst_QWidget::taskQTBUG_11373()
{