summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorOlivier Goffart <ogoffart@trolltech.com>2009-11-25 10:25:36 (GMT)
committerOlivier Goffart <ogoffart@trolltech.com>2009-11-25 10:26:02 (GMT)
commita90a5b09a8cd1017b3743175f15c4e548de180fb (patch)
tree990e64e1bf30a028338bc07550b4c529872dd7b1 /tests
parent447576ef99f57c6a03850a7ed5bf598f33a64802 (diff)
parent346887e731df4143699ce0c2310ded4fec849d30 (diff)
downloadQt-a90a5b09a8cd1017b3743175f15c4e548de180fb.zip
Qt-a90a5b09a8cd1017b3743175f15c4e548de180fb.tar.gz
Qt-a90a5b09a8cd1017b3743175f15c4e548de180fb.tar.bz2
Merge commit 'oslo-staging-2/4.6' into upstream/4.6
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp84
-rw-r--r--tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp24
-rw-r--r--tests/auto/qheaderview/tst_qheaderview.cpp46
-rw-r--r--tests/auto/qlineedit/tst_qlineedit.cpp38
-rw-r--r--tests/auto/qlistview/tst_qlistview.cpp2
-rw-r--r--tests/auto/qmenubar/tst_qmenubar.cpp22
-rw-r--r--tests/auto/qtreewidget/tst_qtreewidget.cpp53
7 files changed, 268 insertions, 1 deletions
diff --git a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
index 2ad024f..e2f87b8 100644
--- a/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
+++ b/tests/auto/qgraphicsanchorlayout/tst_qgraphicsanchorlayout.cpp
@@ -86,6 +86,8 @@ private slots:
void parallelSimplificationOfCenter();
void simplificationVsRedundance();
void spacingPersistency();
+ void snakeParallelWithLayout();
+ void parallelToHalfLayout();
};
class RectWidget : public QGraphicsWidget
@@ -1892,5 +1894,87 @@ void tst_QGraphicsAnchorLayout::spacingPersistency()
QCOMPARE(anchor->spacing(), 30.0);
}
+/*
+ Test whether a correct preferred size is set when a "snake" sequence is in parallel with the
+ layout or half of the layout. The tricky thing here is that all items on the snake should
+ keep their preferred sizes.
+*/
+void tst_QGraphicsAnchorLayout::snakeParallelWithLayout()
+{
+ QSizeF min(10, 20);
+ QSizeF pref(50, 20);
+ QSizeF max(100, 20);
+
+ QGraphicsWidget *a = createItem(max, max, max, "A");
+ QGraphicsWidget *b = createItem(min, pref, max, "B");
+ QGraphicsWidget *c = createItem(max, max, max, "C");
+
+ QGraphicsWidget parent;
+ QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&parent);
+ l->setContentsMargins(0, 0, 0, 0);
+ l->setSpacing(0);
+
+ // First we'll do the case in parallel with the entire layout...
+ l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
+ l->addAnchor(a, Qt::AnchorRight, b, Qt::AnchorRight);
+ l->addAnchor(b, Qt::AnchorLeft, c, Qt::AnchorLeft);
+ l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorRight);
+
+ l->addAnchor(l, Qt::AnchorTop, a, Qt::AnchorTop);
+ l->addAnchor(a, Qt::AnchorBottom, b, Qt::AnchorTop);
+ l->addAnchor(b, Qt::AnchorBottom, c, Qt::AnchorTop);
+ l->addAnchor(c, Qt::AnchorBottom, l, Qt::AnchorBottom);
+
+ parent.resize(l->effectiveSizeHint(Qt::PreferredSize));
+
+ // Note that A and C are fixed in the maximum size
+ QCOMPARE(l->geometry(), QRectF(QPointF(0, 0), QSizeF(150, 60)));
+ QCOMPARE(a->geometry(), QRectF(QPointF(0, 0), max));
+ QCOMPARE(b->geometry(), QRectF(QPointF(50, 20), pref));
+ QCOMPARE(c->geometry(), QRectF(QPointF(50, 40), max));
+
+ // Then, we change the "snake" to be in parallel with half of the layout
+ delete l->anchor(c, Qt::AnchorRight, l, Qt::AnchorRight);
+ l->addAnchor(c, Qt::AnchorRight, l, Qt::AnchorHorizontalCenter);
+
+ parent.resize(l->effectiveSizeHint(Qt::PreferredSize));
+
+ QCOMPARE(l->geometry(), QRectF(QPointF(0, 0), QSizeF(300, 60)));
+ QCOMPARE(a->geometry(), QRectF(QPointF(0, 0), max));
+ QCOMPARE(b->geometry(), QRectF(QPointF(50, 20), pref));
+ QCOMPARE(c->geometry(), QRectF(QPointF(50, 40), max));
+}
+
+/*
+ Avoid regression where the sizeHint constraints would not be
+ created for a parallel anchor that included the first layout half
+*/
+void tst_QGraphicsAnchorLayout::parallelToHalfLayout()
+{
+ QGraphicsWidget *a = createItem();
+
+ QGraphicsWidget w;
+ QGraphicsAnchorLayout *l = new QGraphicsAnchorLayout(&w);
+ l->setContentsMargins(10, 10, 10, 10);
+
+ l->addAnchors(l, a, Qt::Vertical);
+
+ QGraphicsAnchor *anchor;
+ anchor = l->addAnchor(l, Qt::AnchorLeft, a, Qt::AnchorLeft);
+ anchor->setSpacing(5);
+ anchor = l->addAnchor(l, Qt::AnchorHorizontalCenter, a, Qt::AnchorRight);
+ anchor->setSpacing(-5);
+
+ const QSizeF minimumSizeHint = w.effectiveSizeHint(Qt::MinimumSize);
+ const QSizeF preferredSizeHint = w.effectiveSizeHint(Qt::PreferredSize);
+ const QSizeF maximumSizeHint = w.effectiveSizeHint(Qt::MaximumSize);
+
+ const QSizeF overhead = QSizeF(10 + 5 + 5, 10) * 2;
+
+ QCOMPARE(minimumSizeHint, QSizeF(200, 100) + overhead);
+ QCOMPARE(preferredSizeHint, QSizeF(300, 100) + overhead);
+ QCOMPARE(maximumSizeHint, QSizeF(400, 100) + overhead);
+}
+
QTEST_MAIN(tst_QGraphicsAnchorLayout)
#include "tst_qgraphicsanchorlayout.moc"
diff --git a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
index 36ee22c..42d5268 100644
--- a/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
+++ b/tests/auto/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp
@@ -181,6 +181,7 @@ private slots:
void updateAndDelete();
void inputMethod();
void clickFocus();
+ void windowFrameMargins();
};
// Subclass that exposes the protected functions.
@@ -3506,6 +3507,29 @@ void tst_QGraphicsProxyWidget::clickFocus()
QVERIFY(!proxy->widget()->hasFocus());
}
+void tst_QGraphicsProxyWidget::windowFrameMargins()
+{
+ // Make sure the top margin is non-zero when passing Qt::Window.
+ QGraphicsProxyWidget *proxy = new QGraphicsProxyWidget(0, Qt::Window);
+
+ qreal left, top, right, bottom;
+ proxy->getWindowFrameMargins(&left, &top, &right, &bottom);
+ QVERIFY(top > 0);
+
+ proxy->setWidget(new QPushButton("testtest"));
+ proxy->getWindowFrameMargins(&left, &top, &right, &bottom);
+ QVERIFY(top > 0);
+
+ QGraphicsScene scene;
+ scene.addItem(proxy);
+ proxy->getWindowFrameMargins(&left, &top, &right, &bottom);
+ QVERIFY(top > 0);
+
+ proxy->unsetWindowFrameMargins();
+ proxy->getWindowFrameMargins(&left, &top, &right, &bottom);
+ QVERIFY(top > 0);
+}
+
QTEST_MAIN(tst_QGraphicsProxyWidget)
#include "tst_qgraphicsproxywidget.moc"
diff --git a/tests/auto/qheaderview/tst_qheaderview.cpp b/tests/auto/qheaderview/tst_qheaderview.cpp
index c13e829..a8e7461 100644
--- a/tests/auto/qheaderview/tst_qheaderview.cpp
+++ b/tests/auto/qheaderview/tst_qheaderview.cpp
@@ -43,6 +43,7 @@
#include <QtTest/QtTest>
#include <QStandardItemModel>
#include <QStringListModel>
+#include <QSortFilterProxyModel>
#include <qabstractitemmodel.h>
#include <qapplication.h>
@@ -188,6 +189,7 @@ private slots:
void task236450_hidden_data();
void task236450_hidden();
void task248050_hideRow();
+ void QTBUG6058_reset();
protected:
QHeaderView *view;
@@ -1947,5 +1949,49 @@ void tst_QHeaderView::task248050_hideRow()
}
+//returns 0 if everything is fine.
+static int checkHeaderViewOrder(QHeaderView *view, const QVector<int> &expected)
+{
+ if (view->count() != expected.count())
+ return 1;
+
+ for (int i = 0; i < expected.count(); i++) {
+ if (view->logicalIndex(i) != expected.at(i))
+ return i + 10;
+ if (view->visualIndex(expected.at(i)) != i)
+ return i + 100;
+ }
+ return 0;
+}
+
+
+void tst_QHeaderView::QTBUG6058_reset()
+{
+ QStringListModel model1( QStringList() << "0" << "1" << "2" << "3" << "4" << "5" );
+ QStringListModel model2( QStringList() << "a" << "b" << "c" );
+ QSortFilterProxyModel proxy;
+
+ QHeaderView view(Qt::Vertical);
+ view.setModel(&proxy);
+ view.show();
+ QTest::qWait(20);
+
+ proxy.setSourceModel(&model1);
+ QApplication::processEvents();
+ view.swapSections(0,2);
+ view.swapSections(1,4);
+ QApplication::processEvents();
+ QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 4 << 0 << 3 << 1 << 5) , 0);
+
+ proxy.setSourceModel(&model2);
+ QApplication::processEvents();
+ QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 0 << 1 ) , 0);
+
+ proxy.setSourceModel(&model1);
+ QApplication::processEvents();
+ QCOMPARE(checkHeaderViewOrder(&view, QVector<int>() << 2 << 0 << 1 << 3 << 4 << 5 ) , 0);
+}
+
+
QTEST_MAIN(tst_QHeaderView)
#include "tst_qheaderview.moc"
diff --git a/tests/auto/qlineedit/tst_qlineedit.cpp b/tests/auto/qlineedit/tst_qlineedit.cpp
index b4dfbba..dd5bb29 100644
--- a/tests/auto/qlineedit/tst_qlineedit.cpp
+++ b/tests/auto/qlineedit/tst_qlineedit.cpp
@@ -51,6 +51,10 @@
#include "qcompleter.h"
#include "qstandarditemmodel.h"
+#ifndef QT_NO_CLIPBOARD
+#include "qclipboard.h"
+#endif
+
#ifdef Q_WS_MAC
#include <Carbon/Carbon.h> // For the random function.
#include <cstdlib> // For the random function.
@@ -157,6 +161,10 @@ private slots:
void undo_keypressevents_data();
void undo_keypressevents();
+#ifndef QT_NO_CLIPBOARD
+ void QTBUG5786_undoPaste();
+#endif
+
void clear();
void text_data();
@@ -1406,6 +1414,36 @@ void tst_QLineEdit::undo_keypressevents()
QVERIFY(testWidget->text().isEmpty());
}
+#ifndef QT_NO_CLIPBOARD
+void tst_QLineEdit::QTBUG5786_undoPaste()
+{
+ QString initial("initial");
+ QString string("test");
+ QString additional("add");
+ QApplication::clipboard()->setText(string);
+ QLineEdit edit(initial);
+ QCOMPARE(edit.text(), initial);
+ edit.paste();
+ QCOMPARE(edit.text(), initial + string);
+ edit.paste();
+ QCOMPARE(edit.text(), initial + string + string);
+ edit.insert(additional);
+ QCOMPARE(edit.text(), initial + string + string + additional);
+ edit.undo();
+ QCOMPARE(edit.text(), initial + string + string);
+ edit.undo();
+ QCOMPARE(edit.text(), initial + string);
+ edit.undo();
+ QCOMPARE(edit.text(), initial);
+ edit.selectAll();
+ QApplication::clipboard()->setText(QString());
+ edit.paste();
+ QVERIFY(edit.text().isEmpty());
+
+}
+#endif
+
+
void tst_QLineEdit::clear()
{
// checking that clear of empty/nullstring doesn't add to undo history
diff --git a/tests/auto/qlistview/tst_qlistview.cpp b/tests/auto/qlistview/tst_qlistview.cpp
index 605b3e3..602da61 100644
--- a/tests/auto/qlistview/tst_qlistview.cpp
+++ b/tests/auto/qlistview/tst_qlistview.cpp
@@ -1898,7 +1898,7 @@ void tst_QListView::taskQTBUG_5877_skippingItemInPageDownUp()
QTest::qWaitForWindowShown(&vu);
int itemHeight = vu.visualRect(model.index(0, 0)).height();
- int visibleRowCount = vu.height() / itemHeight;
+ int visibleRowCount = vu.viewport()->height() / itemHeight;
int scrolledRowCount = visibleRowCount - 1;
for (int i = 0; i < currentItemIndexes.size(); ++i) {
diff --git a/tests/auto/qmenubar/tst_qmenubar.cpp b/tests/auto/qmenubar/tst_qmenubar.cpp
index 4291c3e..320cd8d 100644
--- a/tests/auto/qmenubar/tst_qmenubar.cpp
+++ b/tests/auto/qmenubar/tst_qmenubar.cpp
@@ -167,6 +167,7 @@ private slots:
void task223138_triggered();
void task256322_highlight();
void menubarSizeHint();
+ void taskQTBUG4965_escapeEaten();
#if defined(QT3_SUPPORT)
void indexBasedInsertion_data();
@@ -1664,6 +1665,27 @@ void tst_QMenuBar::menubarSizeHint()
QCOMPARE(resSize, mb.sizeHint());
}
+void tst_QMenuBar::taskQTBUG4965_escapeEaten()
+{
+ QMenuBar menubar;
+ QMenu menu("menu1");
+ QAction *first = menubar.addMenu(&menu);
+ menu.addAction("quit", &menubar, SLOT(close()), QKeySequence("ESC"));
+ menubar.show();
+ menubar.setActiveWindow();
+ QTest::qWaitForWindowShown(&menubar);
+ menubar.setActiveAction(first);
+ QTRY_VERIFY(menu.isVisible());
+ QCOMPARE(menubar.activeAction(), first);
+ QTest::keyClick(0, Qt::Key_Escape);
+ QVERIFY(!menu.isVisible());
+ QTRY_VERIFY(menubar.hasFocus());
+ QCOMPARE(menubar.activeAction(), first);
+ QTest::keyClick(0, Qt::Key_Escape);
+ QVERIFY(!menubar.activeAction());
+ QTest::keyClick(0, Qt::Key_Escape); //now the action should be triggered
+ QTRY_VERIFY(!menubar.isVisible());
+}
#if defined(QT3_SUPPORT)
void tst_QMenuBar::indexBasedInsertion_data()
diff --git a/tests/auto/qtreewidget/tst_qtreewidget.cpp b/tests/auto/qtreewidget/tst_qtreewidget.cpp
index 621072c..0c6df4f 100644
--- a/tests/auto/qtreewidget/tst_qtreewidget.cpp
+++ b/tests/auto/qtreewidget/tst_qtreewidget.cpp
@@ -168,6 +168,8 @@ private slots:
void task239150_editorWidth();
void setTextUpdate();
void taskQTBUG2844_visualItemRect();
+ void setChildIndicatorPolicy();
+
public slots:
void itemSelectionChanged();
@@ -3290,6 +3292,57 @@ void tst_QTreeWidget::taskQTBUG2844_visualItemRect()
QCOMPARE(tree.visualItemRect(&item), rectCol0 | rectCol1);
}
+void tst_QTreeWidget::setChildIndicatorPolicy()
+{
+ QTreeWidget treeWidget;
+ treeWidget.setColumnCount(1);
+
+ class MyItemDelegate : public QStyledItemDelegate
+ {
+ public:
+ MyItemDelegate() : numPaints(0), expectChildren(false) { }
+ void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
+ {
+ numPaints++;
+ QCOMPARE(!(option.state & QStyle::State_Children), !expectChildren);
+ QStyledItemDelegate::paint(painter, option, index);
+ }
+ mutable int numPaints;
+ bool expectChildren;
+ } delegate;
+
+ treeWidget.setItemDelegate(&delegate);
+ treeWidget.show();
+
+ QTreeWidgetItem *item = new QTreeWidgetItem(QStringList("Hello"));
+ treeWidget.insertTopLevelItem(0, item);
+ QTest::qWait(50);
+ QTRY_VERIFY(delegate.numPaints > 0);
+
+ delegate.numPaints = 0;
+ delegate.expectChildren = true;
+ item->setChildIndicatorPolicy(QTreeWidgetItem::ShowIndicator);
+ QApplication::processEvents();
+ QTRY_COMPARE(delegate.numPaints, 1);
+
+ delegate.numPaints = 0;
+ delegate.expectChildren = false;
+ item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
+ QApplication::processEvents();
+ QTRY_COMPARE(delegate.numPaints, 1);
+
+ delegate.numPaints = 0;
+ delegate.expectChildren = true;
+ new QTreeWidgetItem(item);
+ QApplication::processEvents();
+ QTRY_COMPARE(delegate.numPaints, 1);
+
+ delegate.numPaints = 0;
+ delegate.expectChildren = false;
+ item->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicator);
+ QApplication::processEvents();
+ QTRY_COMPARE(delegate.numPaints, 1);
+}