2014-12-22 20:47:47 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unotest/filters-test.hxx>
|
|
|
|
#include <test/bootstrapfixture.hxx>
|
|
|
|
|
|
|
|
#include <vcl/wrkwin.hxx>
|
|
|
|
#include <vcl/button.hxx>
|
2015-01-01 09:42:15 +00:00
|
|
|
#include <vcl/edit.hxx>
|
|
|
|
#include <vcl/combobox.hxx>
|
|
|
|
#include <vcl/field.hxx>
|
2015-03-16 17:27:11 +00:00
|
|
|
#include <vcl/virdev.hxx>
|
2014-12-22 20:47:47 +00:00
|
|
|
|
|
|
|
class LifecycleTest : public test::BootstrapFixture
|
|
|
|
{
|
|
|
|
void testWidgets(vcl::Window *pParent);
|
|
|
|
|
|
|
|
public:
|
|
|
|
LifecycleTest() : BootstrapFixture(true, false) {}
|
|
|
|
|
2015-01-01 09:42:15 +00:00
|
|
|
void testCast();
|
2015-03-16 17:27:11 +00:00
|
|
|
void testVirtualDevice();
|
2014-12-31 13:30:00 +00:00
|
|
|
void testMultiDispose();
|
2014-12-22 20:47:47 +00:00
|
|
|
void testIsolatedWidgets();
|
|
|
|
void testParentedWidgets();
|
2015-02-26 16:09:06 +00:00
|
|
|
void testChildDispose();
|
2015-03-26 21:45:50 +00:00
|
|
|
void testPostDispose();
|
2014-12-22 20:47:47 +00:00
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(LifecycleTest);
|
2015-01-05 14:01:17 +02:00
|
|
|
CPPUNIT_TEST(testCast);
|
2015-03-16 17:27:11 +00:00
|
|
|
CPPUNIT_TEST(testVirtualDevice);
|
2014-12-31 13:30:00 +00:00
|
|
|
CPPUNIT_TEST(testMultiDispose);
|
2014-12-22 20:47:47 +00:00
|
|
|
CPPUNIT_TEST(testIsolatedWidgets);
|
|
|
|
CPPUNIT_TEST(testParentedWidgets);
|
2015-02-26 16:09:06 +00:00
|
|
|
CPPUNIT_TEST(testChildDispose);
|
2015-03-26 21:45:50 +00:00
|
|
|
CPPUNIT_TEST(testPostDispose);
|
2014-12-22 20:47:47 +00:00
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
};
|
|
|
|
|
2015-01-01 09:42:15 +00:00
|
|
|
// A compile time sanity check
|
|
|
|
void LifecycleTest::testCast()
|
|
|
|
{
|
2015-03-31 20:31:49 +01:00
|
|
|
ScopedVclPtrInstance< PushButton > xButton( nullptr, 0 );
|
|
|
|
ScopedVclPtr<vcl::Window> xWindow(xButton);
|
2015-01-01 09:42:15 +00:00
|
|
|
|
2015-03-31 20:31:49 +01:00
|
|
|
ScopedVclPtrInstance< MetricField > xField( nullptr, 0 );
|
|
|
|
ScopedVclPtr<SpinField> xSpin(xField);
|
|
|
|
ScopedVclPtr<Edit> xEdit(xField);
|
2015-01-05 14:01:17 +02:00
|
|
|
|
|
|
|
// the following line should NOT compile
|
2015-01-06 10:29:11 +02:00
|
|
|
// VclPtr<PushButton> xButton2(xWindow);
|
2015-01-01 09:42:15 +00:00
|
|
|
}
|
|
|
|
|
2015-03-16 17:27:11 +00:00
|
|
|
void LifecycleTest::testVirtualDevice()
|
|
|
|
{
|
2015-04-13 21:19:21 +01:00
|
|
|
VclPtr<VirtualDevice> pVDev = VclPtr< VirtualDevice >::Create();
|
2015-03-31 20:31:49 +01:00
|
|
|
ScopedVclPtrInstance< VirtualDevice > pVDev2;
|
2015-03-30 17:49:20 +01:00
|
|
|
VclPtrInstance<VirtualDevice> pVDev3;
|
|
|
|
VclPtrInstance<VirtualDevice> pVDev4( 1 );
|
|
|
|
CPPUNIT_ASSERT(!!pVDev && !!pVDev2 && !!pVDev3 && !!pVDev4);
|
2015-03-16 17:27:11 +00:00
|
|
|
}
|
|
|
|
|
2014-12-31 13:30:00 +00:00
|
|
|
void LifecycleTest::testMultiDispose()
|
|
|
|
{
|
2015-03-31 20:25:31 +01:00
|
|
|
VclPtrInstance<WorkWindow> xWin(nullptr, WB_APP|WB_STDWORK);
|
2014-12-31 13:30:00 +00:00
|
|
|
CPPUNIT_ASSERT(xWin.get() != NULL);
|
2015-03-13 21:18:16 +00:00
|
|
|
xWin->disposeOnce();
|
|
|
|
xWin->disposeOnce();
|
|
|
|
xWin->disposeOnce();
|
2014-12-31 13:30:00 +00:00
|
|
|
CPPUNIT_ASSERT(xWin->GetWindow(0) == NULL);
|
|
|
|
CPPUNIT_ASSERT(xWin->GetChild(0) == NULL);
|
|
|
|
CPPUNIT_ASSERT(xWin->GetChildCount() == 0);
|
|
|
|
}
|
|
|
|
|
2014-12-22 20:47:47 +00:00
|
|
|
void LifecycleTest::testWidgets(vcl::Window *pParent)
|
|
|
|
{
|
2015-03-31 20:31:49 +01:00
|
|
|
{ ScopedVclPtrInstance< PushButton > aPtr( pParent ); }
|
|
|
|
{ ScopedVclPtrInstance< OKButton > aPtr( pParent ); }
|
|
|
|
{ ScopedVclPtrInstance< CancelButton > aPtr( pParent ); }
|
|
|
|
{ ScopedVclPtrInstance< HelpButton > aPtr( pParent ); }
|
2014-12-22 20:47:47 +00:00
|
|
|
|
|
|
|
// Some widgets really insist on adoption.
|
|
|
|
if (pParent)
|
|
|
|
{
|
2015-03-31 20:31:49 +01:00
|
|
|
{ ScopedVclPtrInstance< CheckBox > aPtr( pParent ); }
|
|
|
|
{ ScopedVclPtrInstance< Edit > aPtr( pParent ); }
|
|
|
|
{ ScopedVclPtrInstance< ComboBox > aPtr( pParent ); }
|
|
|
|
{ ScopedVclPtrInstance< RadioButton > aPtr( pParent ); }
|
2014-12-22 20:47:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LifecycleTest::testIsolatedWidgets()
|
|
|
|
{
|
|
|
|
testWidgets(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LifecycleTest::testParentedWidgets()
|
|
|
|
{
|
2015-03-31 20:31:49 +01:00
|
|
|
ScopedVclPtrInstance<WorkWindow> xWin(nullptr, WB_APP|WB_STDWORK);
|
2014-12-22 20:47:47 +00:00
|
|
|
CPPUNIT_ASSERT(xWin.get() != NULL);
|
2015-02-17 22:03:11 +00:00
|
|
|
xWin->Show();
|
2015-01-05 14:29:59 +02:00
|
|
|
testWidgets(xWin);
|
2014-12-22 20:47:47 +00:00
|
|
|
}
|
|
|
|
|
2015-02-26 16:09:06 +00:00
|
|
|
class DisposableChild : public vcl::Window
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DisposableChild(vcl::Window *pParent) : vcl::Window(pParent) {}
|
|
|
|
virtual ~DisposableChild()
|
|
|
|
{
|
2015-03-10 09:07:06 +02:00
|
|
|
disposeOnce();
|
2015-02-26 16:09:06 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void LifecycleTest::testChildDispose()
|
|
|
|
{
|
2015-03-31 20:31:49 +01:00
|
|
|
VclPtrInstance<WorkWindow> xWin(nullptr, WB_APP|WB_STDWORK);
|
2015-02-26 16:09:06 +00:00
|
|
|
CPPUNIT_ASSERT(xWin.get() != NULL);
|
2015-03-31 20:31:49 +01:00
|
|
|
VclPtrInstance< DisposableChild > xChild( xWin.get() );
|
2015-02-26 16:09:06 +00:00
|
|
|
xWin->Show();
|
2015-03-13 21:18:16 +00:00
|
|
|
xChild->disposeOnce();
|
|
|
|
xWin->disposeOnce();
|
2015-02-26 16:09:06 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 21:45:50 +00:00
|
|
|
void LifecycleTest::testPostDispose()
|
|
|
|
{
|
2015-03-31 20:31:49 +01:00
|
|
|
VclPtrInstance<WorkWindow> xWin(nullptr, WB_APP|WB_STDWORK);
|
2015-03-26 21:45:50 +00:00
|
|
|
xWin->disposeOnce();
|
|
|
|
|
|
|
|
// check selected methods continue to work post-dispose
|
|
|
|
CPPUNIT_ASSERT(!xWin->GetParent());
|
|
|
|
xWin->Show();
|
|
|
|
CPPUNIT_ASSERT(!xWin->IsReallyShown());
|
|
|
|
CPPUNIT_ASSERT(!xWin->IsEnabled());
|
|
|
|
CPPUNIT_ASSERT(!xWin->IsInputEnabled());
|
|
|
|
CPPUNIT_ASSERT(!xWin->GetChild(0));
|
|
|
|
CPPUNIT_ASSERT(!xWin->GetWindow(0));
|
|
|
|
}
|
|
|
|
|
2014-12-22 20:47:47 +00:00
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(LifecycleTest);
|
|
|
|
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|