Clean up tst_qqmlecmascript: don't leak on failure
Lots of tests were following the antipattern of deleting a pointer after the last QVERIFY() or QCOMPARE(), which leads to the pointer being leaked on failure. Use QScopedPointer consistently (it was already in use patchily). That changed one mis-use of QPointer (that was only checked for non-null immediately on creation, never referenced later, so being cleared on deletion wasn't relevant; and thus needed an overt delete, that QScopedPointer made redundant); but another appears to be deliberate, so documented that as such (to the best of my understanding, gc is meant to pick it up). This mostly arose with component.create() results, most of which were checked, albeit in inconsistent ways. Always check these before dereferencing, and use the same form for the check in all cases: use QScopedPointer's in-built cast-to-bool rather than !isNull(); and report the component.errorString(), using QVERIFY2(), on failure. In many cases the return from component.create() is passed through a qobject_cast<> before use; in principle, this could result in null even though create() returned a non-null pointer. Convert those to hold the return from create() in the QScopedPointer<> and cast its data() to get a plain pointer for subsequent use. Split assorted lines that got long (or longer) as a result. Removed a fatuous empty constructor. Change-Id: I88abba9e7ea72e30c92a11a5af5f17486f07f847 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
This commit is contained in:
parent
cb25a1d13d
commit
e8ea7a1262