[Libreoffice-commits] core.git: Branch 'libreoffice-5-0' - 2 commits - vcl/CppunitTest_vcl_lifecycle.mk vcl/Module_vcl.mk vcl/qa vcl/source
Michael Meeks
michael.meeks at collabora.com
Mon Jun 8 07:57:29 PDT 2015
vcl/CppunitTest_vcl_lifecycle.mk | 2
vcl/Module_vcl.mk | 2
vcl/qa/cppunit/lifecycle.cxx | 102 +++++++++++++++++++++++++++++++++++++++
vcl/source/app/svapp.cxx | 4 -
vcl/source/window/window.cxx | 6 +-
5 files changed, 112 insertions(+), 4 deletions(-)
New commits:
commit aeb50bc04085058715f60d96ac60885ee0bfdd52
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Fri Jun 5 16:37:49 2015 +0100
Clear VclPtr instance reference on removed UserEvents.
Also extend VclPtr lifecycle test.
Change-Id: I4d989375ca02327216eb1f37e466aefdb733579d
Reviewed-on: https://gerrit.libreoffice.org/16107
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
Tested-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/vcl/CppunitTest_vcl_lifecycle.mk b/vcl/CppunitTest_vcl_lifecycle.mk
index 54d4aff..ca79b00 100644
--- a/vcl/CppunitTest_vcl_lifecycle.mk
+++ b/vcl/CppunitTest_vcl_lifecycle.mk
@@ -45,6 +45,8 @@ $(eval $(call gb_CppunitTest_use_components,vcl_lifecycle,\
configmgr/source/configmgr \
i18npool/util/i18npool \
ucb/source/core/ucb1 \
+ ucb/source/ucp/file/ucpfile1 \
+ framework/util/fwk \
))
$(eval $(call gb_CppunitTest_use_configuration,vcl_lifecycle))
diff --git a/vcl/qa/cppunit/lifecycle.cxx b/vcl/qa/cppunit/lifecycle.cxx
index 149c54f..b1f4cf8 100644
--- a/vcl/qa/cppunit/lifecycle.cxx
+++ b/vcl/qa/cppunit/lifecycle.cxx
@@ -19,6 +19,7 @@
#include <vcl/tabctrl.hxx>
#include <vcl/dialog.hxx>
#include <vcl/layout.hxx>
+#include <vcl/svapp.hxx>
class LifecycleTest : public test::BootstrapFixture
{
@@ -248,6 +249,7 @@ void LifecycleTest::testLeakage()
// Create objects
aObjects.push_back(LeakTestObject::Create<WorkWindow>(nullptr, WB_APP|WB_STDWORK));
VclPtr<vcl::Window> xParent = aObjects.back()->getRef();
+
aObjects.push_back(LeakTestObject::Create<PushButton>(xParent));
aObjects.push_back(LeakTestObject::Create<OKButton>(xParent));
aObjects.push_back(LeakTestObject::Create<CancelButton>(xParent));
@@ -257,20 +259,18 @@ void LifecycleTest::testLeakage()
aObjects.push_back(LeakTestObject::Create<ComboBox>(xParent));
aObjects.push_back(LeakTestObject::Create<RadioButton>(xParent));
-#if 0
{ // something that looks like a dialog
aObjects.push_back(LeakTestObject::Create<Dialog>(xParent,WB_CLIPCHILDREN|WB_MOVEABLE|WB_3DLOOK|WB_CLOSEABLE|WB_SIZEABLE));
VclPtr<vcl::Window> xDlgParent = aObjects.back()->getRef();
-
aObjects.push_back(LeakTestObject::Create<VclVBox>(xDlgParent));
VclPtr<vcl::Window> xVBox = aObjects.back()->getRef();
-
aObjects.push_back(LeakTestObject::Create<VclVButtonBox>(xVBox));
}
+#if 0 // FIXME - would be good to get internal paths working.
aObjects.push_back(LeakTestObject::Create<ModelessDialog>(xParent, "PrintProgressDialog", "vcl/ui/printprogressdialog.ui"));
- aObjects.push_back(LeakTestObject::Create<ModalDialog>(xParent));
#endif
+ aObjects.push_back(LeakTestObject::Create<ModalDialog>(xParent));
xParent.clear();
for (auto i = aObjects.rbegin(); i != aObjects.rend(); ++i)
diff --git a/vcl/source/app/svapp.cxx b/vcl/source/app/svapp.cxx
index fc058ce..30decf3 100644
--- a/vcl/source/app/svapp.cxx
+++ b/vcl/source/app/svapp.cxx
@@ -939,9 +939,9 @@ void Application::RemoveUserEvent( ImplSVEvent * nUserEvent )
{
if( ! nUserEvent->maDelData.IsDead() )
nUserEvent->mpWindow->ImplRemoveDel( &(nUserEvent->maDelData) );
- nUserEvent->mpWindow = NULL;
+ nUserEvent->mpWindow.clear();
}
-
+ nUserEvent->mpInstanceRef.clear();
nUserEvent->mbCall = false;
}
}
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 17cb1c9..b93bf06 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -486,12 +486,14 @@ void Window::dispose()
if ( pSVData->maWinData.mpLastDeacWin == this )
pSVData->maWinData.mpLastDeacWin = NULL;
- if ( mpWindowImpl->mbFrame && mpWindowImpl->mpFrameData )
+ if ( mpWindowImpl->mpFrameData )
{
if ( mpWindowImpl->mpFrameData->mnFocusId )
Application::RemoveUserEvent( mpWindowImpl->mpFrameData->mnFocusId );
+ mpWindowImpl->mpFrameData->mnFocusId = NULL;
if ( mpWindowImpl->mpFrameData->mnMouseMoveId )
Application::RemoveUserEvent( mpWindowImpl->mpFrameData->mnMouseMoveId );
+ mpWindowImpl->mpFrameData->mnMouseMoveId = NULL;
}
// release SalGraphics
@@ -566,6 +568,8 @@ void Window::dispose()
}
mpWindowImpl->mpFrame->SetCallback( NULL, NULL );
pSVData->mpDefInst->DestroyFrame( mpWindowImpl->mpFrame );
+ assert (mpWindowImpl->mpFrameData->mnFocusId == NULL);
+ assert (mpWindowImpl->mpFrameData->mnMouseMoveId == NULL);
delete mpWindowImpl->mpFrameData;
}
commit deb994fbec421e4b82084c3f42ef8bc28b04fa8c
Author: Michael Meeks <michael.meeks at collabora.com>
Date: Fri Jun 5 12:49:05 2015 +0100
VclPtr - more extensive lifecycle tests.
Change-Id: Ifb5355b3a8f33601bcec0c11ce1afe1c735695b6
Reviewed-on: https://gerrit.libreoffice.org/16100
Tested-by: Jenkins <ci at libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
Tested-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/vcl/Module_vcl.mk b/vcl/Module_vcl.mk
index 8cb05ba..aa26183 100644
--- a/vcl/Module_vcl.mk
+++ b/vcl/Module_vcl.mk
@@ -99,11 +99,11 @@ $(eval $(call gb_Module_add_targets,vcl,\
endif
$(eval $(call gb_Module_add_check_targets,vcl,\
+ CppunitTest_vcl_lifecycle \
CppunitTest_vcl_bitmap_test \
CppunitTest_vcl_fontcharmap \
CppunitTest_vcl_complextext \
CppunitTest_vcl_filters_test \
- CppunitTest_vcl_lifecycle \
CppunitTest_vcl_outdev \
CppunitTest_vcl_app_test \
CppunitTest_vcl_wmf_test \
diff --git a/vcl/qa/cppunit/lifecycle.cxx b/vcl/qa/cppunit/lifecycle.cxx
index 2a63e79..149c54f 100644
--- a/vcl/qa/cppunit/lifecycle.cxx
+++ b/vcl/qa/cppunit/lifecycle.cxx
@@ -17,6 +17,8 @@
#include <vcl/field.hxx>
#include <vcl/virdev.hxx>
#include <vcl/tabctrl.hxx>
+#include <vcl/dialog.hxx>
+#include <vcl/layout.hxx>
class LifecycleTest : public test::BootstrapFixture
{
@@ -33,6 +35,7 @@ public:
void testChildDispose();
void testPostDispose();
void testFocus();
+ void testLeakage();
CPPUNIT_TEST_SUITE(LifecycleTest);
CPPUNIT_TEST(testCast);
@@ -43,6 +46,7 @@ public:
CPPUNIT_TEST(testChildDispose);
CPPUNIT_TEST(testPostDispose);
CPPUNIT_TEST(testFocus);
+ CPPUNIT_TEST(testLeakage);
CPPUNIT_TEST_SUITE_END();
};
@@ -184,6 +188,104 @@ void LifecycleTest::testFocus()
// CPPUNIT_ASSERT(xChild->HasFocus());
}
+template <class vcl_type>
+class LeakTestClass : public vcl_type
+{
+ bool &mrDeleted;
+public:
+ template<typename... Arg>
+ LeakTestClass(bool &bDeleted, Arg &&... arg) :
+ vcl_type(std::forward<Arg>(arg)...),
+ mrDeleted(bDeleted)
+ {
+ mrDeleted = false;
+ }
+ ~LeakTestClass()
+ {
+ mrDeleted = true;
+ }
+};
+
+class LeakTestObject
+{
+ bool mbDeleted;
+ VclPtr<vcl::Window> mxRef;
+ void *mpRef;
+ LeakTestObject() {}
+public:
+ template<typename vcl_type, typename... Arg> static LeakTestObject *
+ Create(Arg &&... arg)
+ {
+ LeakTestObject *pNew = new LeakTestObject();
+ pNew->mxRef = VclPtr< LeakTestClass< vcl_type > >::Create( pNew->mbDeleted,
+ std::forward<Arg>(arg)...);
+ pNew->mpRef = reinterpret_cast<void *>(static_cast<vcl::Window *>(pNew->mxRef));
+ return pNew;
+ }
+ VclPtr<vcl::Window> getRef() { return mxRef; }
+ void disposeAndClear()
+ {
+ mxRef.disposeAndClear();
+ }
+ void assertDeleted()
+ {
+ if (!mbDeleted)
+ {
+ OUStringBuffer aMsg = "Type '";
+ vcl::Window *pWin = reinterpret_cast<vcl::Window *>(mpRef);
+ aMsg.appendAscii(typeid(*pWin).name());
+ aMsg.append("' not freed after dispose");
+ CPPUNIT_FAIL(OUStringToOString(aMsg.makeStringAndClear(),
+ RTL_TEXTENCODING_UTF8).getStr());
+ }
+ }
+};
+
+void LifecycleTest::testLeakage()
+{
+ std::vector<LeakTestObject *> aObjects;
+
+ // Create objects
+ aObjects.push_back(LeakTestObject::Create<WorkWindow>(nullptr, WB_APP|WB_STDWORK));
+ VclPtr<vcl::Window> xParent = aObjects.back()->getRef();
+ aObjects.push_back(LeakTestObject::Create<PushButton>(xParent));
+ aObjects.push_back(LeakTestObject::Create<OKButton>(xParent));
+ aObjects.push_back(LeakTestObject::Create<CancelButton>(xParent));
+ aObjects.push_back(LeakTestObject::Create<HelpButton>(xParent));
+ aObjects.push_back(LeakTestObject::Create<CheckBox>(xParent));
+ aObjects.push_back(LeakTestObject::Create<Edit>(xParent));
+ aObjects.push_back(LeakTestObject::Create<ComboBox>(xParent));
+ aObjects.push_back(LeakTestObject::Create<RadioButton>(xParent));
+
+#if 0
+ { // something that looks like a dialog
+ aObjects.push_back(LeakTestObject::Create<Dialog>(xParent,WB_CLIPCHILDREN|WB_MOVEABLE|WB_3DLOOK|WB_CLOSEABLE|WB_SIZEABLE));
+ VclPtr<vcl::Window> xDlgParent = aObjects.back()->getRef();
+
+ aObjects.push_back(LeakTestObject::Create<VclVBox>(xDlgParent));
+ VclPtr<vcl::Window> xVBox = aObjects.back()->getRef();
+
+ aObjects.push_back(LeakTestObject::Create<VclVButtonBox>(xVBox));
+ }
+
+ aObjects.push_back(LeakTestObject::Create<ModelessDialog>(xParent, "PrintProgressDialog", "vcl/ui/printprogressdialog.ui"));
+ aObjects.push_back(LeakTestObject::Create<ModalDialog>(xParent));
+#endif
+ xParent.clear();
+
+ for (auto i = aObjects.rbegin(); i != aObjects.rend(); ++i)
+ (*i)->getRef()->Show();
+
+ for (auto i = aObjects.rbegin(); i != aObjects.rend(); ++i)
+ (*i)->disposeAndClear();
+
+ for (auto i = aObjects.begin(); i != aObjects.end(); ++i)
+ (*i)->assertDeleted();
+
+ for (auto i = aObjects.begin(); i != aObjects.end(); ++i)
+ delete *i;
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(LifecycleTest);
CPPUNIT_PLUGIN_IMPLEMENT();
More information about the Libreoffice-commits
mailing list