summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2014-12-31 13:30:00 +0000
committerMichael Meeks <michael.meeks@collabora.com>2015-04-09 19:51:11 +0100
commit99fc2f4e92711be9ac82f385519a23ed9d5badac (patch)
treee2e2d91b5b553c48fc54878c26464a740f9090b3 /vcl
parentf3add7029e5778818283d48803e46ac4ecf875f5 (diff)
vcl: double dispose protection & unit test.
Widgets must be able to tolerate multiple 'dispose' calls. Change-Id: I76069a10b83b8384ad84dd146766054cab5bd222
Diffstat (limited to 'vcl')
-rw-r--r--vcl/qa/cppunit/lifecycle.cxx15
-rw-r--r--vcl/source/window/stacking.cxx6
-rw-r--r--vcl/source/window/window.cxx3
3 files changed, 24 insertions, 0 deletions
diff --git a/vcl/qa/cppunit/lifecycle.cxx b/vcl/qa/cppunit/lifecycle.cxx
index d635dd6aea7e..1c887b9df00d 100644
--- a/vcl/qa/cppunit/lifecycle.cxx
+++ b/vcl/qa/cppunit/lifecycle.cxx
@@ -20,15 +20,30 @@ class LifecycleTest : public test::BootstrapFixture
public:
LifecycleTest() : BootstrapFixture(true, false) {}
+ void testMultiDispose();
void testIsolatedWidgets();
void testParentedWidgets();
CPPUNIT_TEST_SUITE(LifecycleTest);
+ CPPUNIT_TEST(testMultiDispose);
CPPUNIT_TEST(testIsolatedWidgets);
CPPUNIT_TEST(testParentedWidgets);
CPPUNIT_TEST_SUITE_END();
};
+void LifecycleTest::testMultiDispose()
+{
+ VclReference<WorkWindow> xWin(new WorkWindow((vcl::Window *)NULL,
+ WB_APP|WB_STDWORK));
+ CPPUNIT_ASSERT(xWin.get() != NULL);
+ xWin->dispose();
+ xWin->dispose();
+ xWin->dispose();
+ CPPUNIT_ASSERT(xWin->GetWindow(0) == NULL);
+ CPPUNIT_ASSERT(xWin->GetChild(0) == NULL);
+ CPPUNIT_ASSERT(xWin->GetChildCount() == 0);
+}
+
void LifecycleTest::testWidgets(vcl::Window *pParent)
{
{ PushButtonPtr aPtr(new PushButton(pParent)); }
diff --git a/vcl/source/window/stacking.cxx b/vcl/source/window/stacking.cxx
index ee29a8deabda..9d81501fa5c5 100644
--- a/vcl/source/window/stacking.cxx
+++ b/vcl/source/window/stacking.cxx
@@ -1023,6 +1023,8 @@ void Window::SetParent( vcl::Window* pNewParent )
sal_uInt16 Window::GetChildCount() const
{
+ if (!mpWindowImpl)
+ return 0;
sal_uInt16 nChildCount = 0;
vcl::Window* pChild = mpWindowImpl->mpFirstChild;
@@ -1037,6 +1039,8 @@ sal_uInt16 Window::GetChildCount() const
vcl::Window* Window::GetChild( sal_uInt16 nChild ) const
{
+ if (!mpWindowImpl)
+ return NULL;
sal_uInt16 nChildCount = 0;
vcl::Window* pChild = mpWindowImpl->mpFirstChild;
@@ -1053,6 +1057,8 @@ vcl::Window* Window::GetChild( sal_uInt16 nChild ) const
vcl::Window* Window::GetWindow( sal_uInt16 nType ) const
{
+ if (!mpWindowImpl)
+ return 0;
switch ( nType )
{
diff --git a/vcl/source/window/window.cxx b/vcl/source/window/window.cxx
index 122181df2a53..17b3ceab693d 100644
--- a/vcl/source/window/window.cxx
+++ b/vcl/source/window/window.cxx
@@ -133,6 +133,9 @@ namespace
void Window::dispose()
{
+ if (!mpWindowImpl)
+ return;
+
// remove Key and Mouse events issued by Application::PostKey/MouseEvent
Application::RemoveMouseAndKeyEvents( this );