diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2016-09-28 10:49:57 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-10-02 11:28:23 +0000 |
commit | ad1555be7fa2aa9da04509455f83f5d8faab6e3a (patch) | |
tree | 847246ec5696c72b6811c6e8250b679cc48a6a0f /tests/auto/widgets/util/qundostack | |
parent | f43c9697bcae997be3eb6db9504f3d7b64601148 (diff) |
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 <thiago.macieira@intel.com>
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/auto/widgets/util/qundostack')
-rw-r--r-- | tests/auto/widgets/util/qundostack/tst_qundostack.cpp | 53 |
1 files changed, 22 insertions, 31 deletions
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<QAction> &redoAction, + const QScopedPointer<QAction> &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<QAction> undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer<QAction> 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<QAction> undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer<QAction> 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<QAction> undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer<QAction> 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<QAction> undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer<QAction> 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<QAction> undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer<QAction> 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<QAction> undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer<QAction> 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<QAction> undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer<QAction> 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<QAction> undoAction(stack.createUndoAction(0, QString("foo"))); + const QScopedPointer<QAction> 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<QAction> undo_action(stack.createUndoAction(0)); + const QScopedPointer<QAction> 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<QAction> undo_action(stack.createUndoAction(0)); + const QScopedPointer<QAction> redo_action(stack.createRedoAction(0)); QUndoCommand *command1 = new IdleCommand(); QUndoCommand *command2 = new IdleCommand(); |