From ad1555be7fa2aa9da04509455f83f5d8faab6e3a Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 28 Sep 2016 10:49:57 +0200 Subject: Plug remaining leaks in tests/auto/widgets/util In tst_QCompleter, two completers were leaked because they had no parent and setCompleter() calls don't reparent. Fixed by giving them parents. In tst_QUndo*, fix lots of leaked QActions by storing them in a QScopedPointer. There were some half-hearted attempts to clean them up with manual deletes, but I ported these to scoped pointers, too, to make the code more robust in the face of failures. This fixes the remaining errors in GCC 6.1 Linux ASan runs of tests/auto/widgets/util. Change-Id: Icc5248cc9cf4514540915924df1c4d9e09c071fa Reviewed-by: Thiago Macieira Reviewed-by: Olivier Goffart (Woboq GmbH) --- .../widgets/util/qcompleter/tst_qcompleter.cpp | 4 +- .../widgets/util/qundogroup/tst_qundogroup.cpp | 11 ++--- .../widgets/util/qundostack/tst_qundostack.cpp | 53 +++++++++------------- 3 files changed, 28 insertions(+), 40 deletions(-) (limited to 'tests/auto/widgets/util') diff --git a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp index 86a0bdf901..2a14d752e1 100644 --- a/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp +++ b/tests/auto/widgets/util/qcompleter/tst_qcompleter.cpp @@ -1228,7 +1228,7 @@ void tst_QCompleter::task178797_activatedOnReturn() words << "foobar1" << "foobar2"; QLineEdit ledit; setFrameless(&ledit); - QCompleter *completer = new QCompleter(words); + QCompleter *completer = new QCompleter(words, &ledit); ledit.setCompleter(completer); QSignalSpy spy(completer, SIGNAL(activated(QString))); QCOMPARE(spy.count(), 0); @@ -1335,7 +1335,7 @@ public: task250064_TextEdit() { - completer = new QCompleter; + completer = new QCompleter(this); completer->setWidget(this); } diff --git a/tests/auto/widgets/util/qundogroup/tst_qundogroup.cpp b/tests/auto/widgets/util/qundogroup/tst_qundogroup.cpp index 464a42b4e8..2b82cbfd03 100644 --- a/tests/auto/widgets/util/qundogroup/tst_qundogroup.cpp +++ b/tests/auto/widgets/util/qundogroup/tst_qundogroup.cpp @@ -382,8 +382,8 @@ static QString glue(const QString &s1, const QString &s2) void tst_QUndoGroup::checkSignals() { QUndoGroup group; - QAction *undo_action = group.createUndoAction(0, QString("foo")); - QAction *redo_action = group.createRedoAction(0, QString("bar")); + const QScopedPointer undo_action(group.createUndoAction(0, QString("foo"))); + const QScopedPointer redo_action(group.createRedoAction(0, QString("bar"))); QSignalSpy indexChangedSpy(&group, SIGNAL(indexChanged(int))); QSignalSpy cleanChangedSpy(&group, SIGNAL(cleanChanged(bool))); QSignalSpy canUndoChangedSpy(&group, SIGNAL(canUndoChanged(bool))); @@ -595,9 +595,6 @@ void tst_QUndoGroup::checkSignals() true, // indexChanged true, // undoChanged true) // redoChanged - - delete undo_action; - delete redo_action; } void tst_QUndoGroup::addStackAndDie() @@ -634,8 +631,8 @@ void tst_QUndoGroup::commandTextFormat() qApp->installTranslator(&translator); QUndoGroup group; - QAction *undo_action = group.createUndoAction(0); - QAction *redo_action = group.createRedoAction(0); + const QScopedPointer undo_action(group.createUndoAction(0)); + const QScopedPointer redo_action(group.createRedoAction(0)); QCOMPARE(undo_action->text(), QString("Undo-default-text")); QCOMPARE(redo_action->text(), QString("Redo-default-text")); diff --git a/tests/auto/widgets/util/qundostack/tst_qundostack.cpp b/tests/auto/widgets/util/qundostack/tst_qundostack.cpp index 07c5be417a..22867aba7c 100644 --- a/tests/auto/widgets/util/qundostack/tst_qundostack.cpp +++ b/tests/auto/widgets/util/qundostack/tst_qundostack.cpp @@ -262,8 +262,8 @@ static QString glue(const QString &s1, const QString &s2) static void checkState(QSignalSpy &redoTextChangedSpy, QSignalSpy &canRedoChangedSpy, QSignalSpy &undoTextChangedSpy, - QAction *const redoAction, - QAction *const undoAction, + const QScopedPointer &redoAction, + const QScopedPointer &undoAction, QSignalSpy &canUndoChangedSpy, QSignalSpy &cleanChangedSpy, QSignalSpy &indexChangedSpy, @@ -332,8 +332,8 @@ static void checkState(QSignalSpy &redoTextChangedSpy, void tst_QUndoStack::undoRedo() { QUndoStack stack; - QAction *undoAction = stack.createUndoAction(0, QString("foo")); - QAction *redoAction = stack.createRedoAction(0, QString("bar")); + const QScopedPointer undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer redoAction(stack.createRedoAction(0, QString("bar"))); QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); @@ -693,8 +693,8 @@ void tst_QUndoStack::undoRedo() void tst_QUndoStack::setIndex() { QUndoStack stack; - QAction *undoAction = stack.createUndoAction(0, QString("foo")); - QAction *redoAction = stack.createRedoAction(0, QString("bar")); + const QScopedPointer undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer redoAction(stack.createRedoAction(0, QString("bar"))); QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); @@ -957,8 +957,8 @@ void tst_QUndoStack::setIndex() void tst_QUndoStack::setClean() { QUndoStack stack; - QAction *undoAction = stack.createUndoAction(0, QString("foo")); - QAction *redoAction = stack.createRedoAction(0, QString("bar")); + const QScopedPointer undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer redoAction(stack.createRedoAction(0, QString("bar"))); QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); @@ -1210,8 +1210,8 @@ void tst_QUndoStack::setClean() void tst_QUndoStack::clear() { QUndoStack stack; - QAction *undoAction = stack.createUndoAction(this, QString("foo")); - QAction *redoAction = stack.createRedoAction(this, QString("bar")); + const QScopedPointer undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer redoAction(stack.createRedoAction(0, QString("bar"))); QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); @@ -1408,8 +1408,8 @@ void tst_QUndoStack::clear() void tst_QUndoStack::childCommand() { QUndoStack stack; - QAction *undoAction = stack.createUndoAction(0, QString("foo")); - QAction *redoAction = stack.createRedoAction(0, QString("bar")); + const QScopedPointer undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer redoAction(stack.createRedoAction(0, QString("bar"))); QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); @@ -1513,16 +1513,13 @@ void tst_QUndoStack::childCommand() true, // indexChanged true, // undoChanged true); // redoChanged - - delete undoAction; - delete redoAction; } void tst_QUndoStack::macroBeginEnd() { QUndoStack stack; - QAction *undoAction = stack.createUndoAction(0, QString("foo")); - QAction *redoAction = stack.createRedoAction(0, QString("bar")); + const QScopedPointer undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer redoAction(stack.createRedoAction(0, QString("bar"))); QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); @@ -1983,16 +1980,13 @@ void tst_QUndoStack::macroBeginEnd() true, // indexChanged true, // undoChanged true); // redoChanged - - delete undoAction; - delete redoAction; } void tst_QUndoStack::compression() { QUndoStack stack; - QAction *undoAction = stack.createUndoAction(0, QString("foo")); - QAction *redoAction = stack.createRedoAction(0, QString("bar")); + const QScopedPointer undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer redoAction(stack.createRedoAction(0, QString("bar"))); QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); @@ -2428,16 +2422,13 @@ void tst_QUndoStack::compression() true, // indexChanged true, // undoChanged true); // redoChanged - - delete undoAction; - delete redoAction; } void tst_QUndoStack::undoLimit() { QUndoStack stack; - QAction *undoAction = stack.createUndoAction(0, QString("foo")); - QAction *redoAction = stack.createRedoAction(0, QString("bar")); + const QScopedPointer undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer redoAction(stack.createRedoAction(0, QString("bar"))); QSignalSpy indexChangedSpy(&stack, SIGNAL(indexChanged(int))); QSignalSpy cleanChangedSpy(&stack, SIGNAL(cleanChanged(bool))); QSignalSpy canUndoChangedSpy(&stack, SIGNAL(canUndoChanged(bool))); @@ -2977,8 +2968,8 @@ void tst_QUndoStack::commandTextFormat() qApp->installTranslator(&translator); QUndoStack stack; - QAction *undo_action = stack.createUndoAction(0); - QAction *redo_action = stack.createRedoAction(0); + const QScopedPointer undo_action(stack.createUndoAction(0)); + const QScopedPointer redo_action(stack.createRedoAction(0)); QCOMPARE(undo_action->text(), QString("Undo-default-text")); QCOMPARE(redo_action->text(), QString("Redo-default-text")); @@ -3005,8 +2996,8 @@ void tst_QUndoStack::commandTextFormat() void tst_QUndoStack::separateUndoText() { QUndoStack stack; - QAction *undo_action = stack.createUndoAction(0); - QAction *redo_action = stack.createRedoAction(0); + const QScopedPointer undo_action(stack.createUndoAction(0)); + const QScopedPointer redo_action(stack.createRedoAction(0)); QUndoCommand *command1 = new IdleCommand(); QUndoCommand *command2 = new IdleCommand(); -- cgit v1.2.3