summaryrefslogtreecommitdiffstats
path: root/tests/auto/widgets/kernel/qboxlayout
diff options
context:
space:
mode:
authorThomas Fischer <fischer@unix-ag.uni-kl.de>2014-08-24 14:01:26 +0200
committerMarc Mutz <marc.mutz@kdab.com>2014-09-05 00:05:45 +0200
commit983dde1f2f3db76ab26e949d8c2f4f8b968b36be (patch)
treec092b9aa473e4ca41201ab1969f9139ff9db8585 /tests/auto/widgets/kernel/qboxlayout
parent8206a263ab9bca7fef191d299c05294a00ec1c8f (diff)
Avoid adding widget to its own layout
Widgets and layouts added or inserted to a layout are checked for: - Not being NULL - Not being the parent widget of a layout or the layout itself, respectively Without this commit, adding a widget to its own layout would result in a CPU-hogging infinite loop. Now, a warning is written to stderr and the add or insert function call is ignored. The checks are implemented as public functions of QLayoutPrivate and thus accessible in QLayout's descendants to be used in various "addWidget", "insertWidget", etc functions. Unlike 'classical' layouts like QGridLayout, QFormLayout does indeed accept widgets that are NULL. To not break this behavior, any call for the check functions first tests if the widget or layout, respectively, to test is NULL or not and calls the check only in the latter case. Automated tests for QBoxLayout, QGridLayout, and QFormLayout were added. For an unpatched Qt 5.3, each of those automated tests will freeze as explained in QTBUG-40609. For a fixed version, warning messages about invalid parameters to addWidget/addLayout/... calls will be read by QTest::ignoreMessage, resulting in a passed test. Change-Id: I1522d5727e643da3f7c025755975aca9f482676d Task-number: QTBUG-40609 Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Diffstat (limited to 'tests/auto/widgets/kernel/qboxlayout')
-rw-r--r--tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp
index 850bedd9cc..4167d633b0 100644
--- a/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp
+++ b/tests/auto/widgets/kernel/qboxlayout/tst_qboxlayout.cpp
@@ -79,6 +79,8 @@ private slots:
void taskQTBUG_7103_minMaxWidthNotRespected();
void taskQTBUG_27420_takeAtShouldUnparentLayout();
+ void taskQTBUG_40609_addingWidgetToItsOwnLayout();
+ void taskQTBUG_40609_addingLayoutToItself();
void replaceWidget();
};
@@ -329,6 +331,36 @@ void tst_QBoxLayout::taskQTBUG_27420_takeAtShouldUnparentLayout()
QVERIFY(!inner.isNull());
}
+void tst_QBoxLayout::taskQTBUG_40609_addingWidgetToItsOwnLayout(){
+ QWidget widget;
+ widget.setObjectName("347b469225a24a0ef05150a");
+ QVBoxLayout layout(&widget);
+ layout.setObjectName("ef9e2b42298e0e6420105bb");
+
+ QTest::ignoreMessage(QtWarningMsg, "QLayout: Cannot add a null widget to QVBoxLayout/ef9e2b42298e0e6420105bb");
+ layout.addWidget(Q_NULLPTR);
+ QCOMPARE(layout.count(), 0);
+
+ QTest::ignoreMessage(QtWarningMsg, "QLayout: Cannot add parent widget QWidget/347b469225a24a0ef05150a to its child layout QVBoxLayout/ef9e2b42298e0e6420105bb");
+ layout.addWidget(&widget);
+ QCOMPARE(layout.count(), 0);
+}
+
+void tst_QBoxLayout::taskQTBUG_40609_addingLayoutToItself(){
+ QWidget widget;
+ widget.setObjectName("fe44e5cb6c08006597126a");
+ QVBoxLayout layout(&widget);
+ layout.setObjectName("cc751dd0f50f62b05a62da");
+
+ QTest::ignoreMessage(QtWarningMsg, "QLayout: Cannot add a null layout to QVBoxLayout/cc751dd0f50f62b05a62da");
+ layout.addLayout(Q_NULLPTR);
+ QCOMPARE(layout.count(), 0);
+
+ QTest::ignoreMessage(QtWarningMsg, "QLayout: Cannot add layout QVBoxLayout/cc751dd0f50f62b05a62da to itself");
+ layout.addLayout(&layout);
+ QCOMPARE(layout.count(), 0);
+}
+
struct Descr
{
Descr(int min, int sh, int max = -1, bool exp= false, int _stretch = 0, bool _empty = false)