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>
|
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();
|
2014-12-31 13:30:00 +00:00
|
|
|
void testMultiDispose();
|
2014-12-22 20:47:47 +00:00
|
|
|
void testIsolatedWidgets();
|
|
|
|
void testParentedWidgets();
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE(LifecycleTest);
|
2015-01-05 14:01:17 +02:00
|
|
|
CPPUNIT_TEST(testCast);
|
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);
|
|
|
|
CPPUNIT_TEST_SUITE_END();
|
|
|
|
};
|
|
|
|
|
2015-01-01 09:42:15 +00:00
|
|
|
// A compile time sanity check
|
|
|
|
void LifecycleTest::testCast()
|
|
|
|
{
|
2015-01-06 10:29:11 +02:00
|
|
|
VclPtr<PushButton> xButton(new PushButton(NULL, 0));
|
|
|
|
VclPtr<vcl::Window> xWindow(xButton);
|
2015-01-01 09:42:15 +00:00
|
|
|
|
2015-01-06 10:29:11 +02:00
|
|
|
VclPtr<MetricField> xField(new MetricField(NULL, 0));
|
|
|
|
VclPtr<SpinField> xSpin(xField);
|
|
|
|
VclPtr<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
|
|
|
}
|
|
|
|
|
2014-12-31 13:30:00 +00:00
|
|
|
void LifecycleTest::testMultiDispose()
|
|
|
|
{
|
2015-01-06 10:29:11 +02:00
|
|
|
VclPtr<WorkWindow> xWin(new WorkWindow((vcl::Window *)NULL,
|
|
|
|
WB_APP|WB_STDWORK));
|
2014-12-31 13:30:00 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2014-12-22 20:47:47 +00:00
|
|
|
void LifecycleTest::testWidgets(vcl::Window *pParent)
|
|
|
|
{
|
2015-01-06 10:29:11 +02:00
|
|
|
{ VclPtr<PushButton> aPtr(new PushButton(pParent)); }
|
|
|
|
{ VclPtr<OKButton> aPtr(new OKButton(pParent)); }
|
|
|
|
{ VclPtr<CancelButton> aPtr(new CancelButton(pParent)); }
|
|
|
|
{ VclPtr<HelpButton> aPtr(new HelpButton(pParent)); }
|
2014-12-22 20:47:47 +00:00
|
|
|
|
|
|
|
// Some widgets really insist on adoption.
|
|
|
|
if (pParent)
|
|
|
|
{
|
2015-02-17 19:49:27 +00:00
|
|
|
{ VclPtr<CheckBox> aPtr(new CheckBox(pParent)); }
|
|
|
|
{ VclPtr<Edit> aPtr(new Edit(pParent)); }
|
|
|
|
{ VclPtr<ComboBox> aPtr(new ComboBox(pParent)); }
|
|
|
|
{ VclPtr<RadioButton> aPtr(new RadioButton(pParent)); }
|
2014-12-22 20:47:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LifecycleTest::testIsolatedWidgets()
|
|
|
|
{
|
|
|
|
testWidgets(NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
void LifecycleTest::testParentedWidgets()
|
|
|
|
{
|
2015-01-06 10:29:11 +02:00
|
|
|
VclPtr<WorkWindow> xWin(new WorkWindow((vcl::Window *)NULL,
|
2014-12-22 20:47:47 +00:00
|
|
|
WB_APP|WB_STDWORK));
|
|
|
|
CPPUNIT_ASSERT(xWin.get() != NULL);
|
2015-01-05 14:29:59 +02:00
|
|
|
testWidgets(xWin);
|
2014-12-22 20:47:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CPPUNIT_TEST_SUITE_REGISTRATION(LifecycleTest);
|
|
|
|
|
|
|
|
CPPUNIT_PLUGIN_IMPLEMENT();
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|