/* -*- 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 #include #include #include #include #include #include #include #include #include #include #include #include #include class LifecycleTest : public test::BootstrapFixture { void testWidgets(vcl::Window *pParent); public: LifecycleTest() : BootstrapFixture(true, false) {} void testCast(); void testVirtualDevice(); void testMultiDispose(); void testIsolatedWidgets(); void testParentedWidgets(); void testChildDispose(); void testPostDispose(); void testLeakage(); void testToolkit(); CPPUNIT_TEST_SUITE(LifecycleTest); CPPUNIT_TEST(testCast); CPPUNIT_TEST(testVirtualDevice); CPPUNIT_TEST(testMultiDispose); CPPUNIT_TEST(testIsolatedWidgets); CPPUNIT_TEST(testParentedWidgets); CPPUNIT_TEST(testChildDispose); CPPUNIT_TEST(testPostDispose); CPPUNIT_TEST(testLeakage); CPPUNIT_TEST(testToolkit); CPPUNIT_TEST_SUITE_END(); }; // A compile time sanity check void LifecycleTest::testCast() { ScopedVclPtrInstance< PushButton > xButton( nullptr, 0 ); ScopedVclPtr xWindow(xButton); ScopedVclPtrInstance< MetricField > xField( nullptr, 0 ); ScopedVclPtr xSpin(xField); ScopedVclPtr xEdit(xField); // the following line should NOT compile // VclPtr xButton2(xWindow); } void LifecycleTest::testVirtualDevice() { VclPtr pVDev = VclPtr< VirtualDevice >::Create(); ScopedVclPtrInstance< VirtualDevice > pVDev2; VclPtrInstance pVDev3; VclPtrInstance pVDev4(DeviceFormat::WITHOUT_ALPHA); CPPUNIT_ASSERT(!!pVDev); CPPUNIT_ASSERT(!!pVDev2); CPPUNIT_ASSERT(!!pVDev3); CPPUNIT_ASSERT(!!pVDev4); pVDev.disposeAndClear(); pVDev4.disposeAndClear(); } void LifecycleTest::testMultiDispose() { VclPtrInstance xWin(nullptr, WB_APP|WB_STDWORK); CPPUNIT_ASSERT(xWin); xWin->disposeOnce(); xWin->disposeOnce(); xWin->disposeOnce(); CPPUNIT_ASSERT(!xWin->GetWindow(GetWindowType::Parent)); CPPUNIT_ASSERT(!xWin->GetChild(0)); CPPUNIT_ASSERT_EQUAL(static_cast(0), xWin->GetChildCount()); } void LifecycleTest::testWidgets(vcl::Window *pParent) { { ScopedVclPtrInstance< PushButton > aPtr( pParent ); (void)aPtr; // silence unused variable warning } { ScopedVclPtrInstance< OKButton > aPtr( pParent ); (void)aPtr; // silence unused variable warning } { ScopedVclPtrInstance< CancelButton > aPtr( pParent ); (void)aPtr; // silence unused variable warning } { ScopedVclPtrInstance< HelpButton > aPtr( pParent ); (void)aPtr; // silence unused variable warning } // Some widgets really insist on adoption. if (pParent) { { ScopedVclPtrInstance< CheckBox > aPtr( pParent ); (void)aPtr; // silence unused variable warning } { ScopedVclPtrInstance< Edit > aPtr( pParent ); (void)aPtr; // silence unused variable warning } { ScopedVclPtrInstance< ComboBox > aPtr( pParent ); (void)aPtr; // silence unused variable warning } { ScopedVclPtrInstance< RadioButton > aPtr( pParent, true, 0 ); (void)aPtr; // silence unused variable warning } } } void LifecycleTest::testIsolatedWidgets() { testWidgets(nullptr); } void LifecycleTest::testParentedWidgets() { ScopedVclPtrInstance xWin(nullptr, WB_APP|WB_STDWORK); CPPUNIT_ASSERT(xWin); xWin->Show(); testWidgets(xWin); } namespace { class DisposableChild : public vcl::Window { public: explicit DisposableChild(vcl::Window *pParent) : vcl::Window(pParent) {} virtual ~DisposableChild() override { disposeOnce(); } }; } void LifecycleTest::testChildDispose() { VclPtrInstance xWin(nullptr, WB_APP|WB_STDWORK); CPPUNIT_ASSERT(xWin); VclPtrInstance< DisposableChild > xChild( xWin.get() ); xWin->Show(); xChild->disposeOnce(); xWin->disposeOnce(); } void LifecycleTest::testPostDispose() { VclPtrInstance xWin(nullptr, WB_APP|WB_STDWORK); 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(GetWindowType::Parent)); } namespace { template class LeakTestClass : public vcl_type { bool &mrDeleted; public: template LeakTestClass(bool &bDeleted, Arg &&... arg) : vcl_type(std::forward(arg)...), mrDeleted(bDeleted) { mrDeleted = false; } ~LeakTestClass() { mrDeleted = true; } }; class LeakTestObject { bool mbDeleted; VclPtr mxRef; void *mpRef; LeakTestObject() : mbDeleted(false) , mpRef(nullptr) { } public: template static LeakTestObject * Create(Arg &&... arg) { LeakTestObject *pNew = new LeakTestObject(); pNew->mxRef = VclPtr< LeakTestClass< vcl_type > >::Create( pNew->mbDeleted, std::forward(arg)...); pNew->mpRef = static_cast(static_cast(pNew->mxRef)); return pNew; } const VclPtr& getRef() const { return mxRef; } void disposeAndClear() { mxRef.disposeAndClear(); } void assertDeleted() { if (!mbDeleted) { OUStringBuffer aMsg = "Type '"; vcl::Window *pWin = static_cast(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 aObjects; // Create objects aObjects.push_back(LeakTestObject::Create(nullptr, WB_APP|WB_STDWORK)); VclPtr xParent = aObjects.back()->getRef(); aObjects.push_back(LeakTestObject::Create(xParent)); aObjects.push_back(LeakTestObject::Create(xParent)); aObjects.push_back(LeakTestObject::Create(xParent)); aObjects.push_back(LeakTestObject::Create(xParent)); aObjects.push_back(LeakTestObject::Create(xParent, true, 0)); { // something that looks like a dialog aObjects.push_back(LeakTestObject::Create(xParent,WB_CLIPCHILDREN|WB_MOVEABLE|WB_3DLOOK|WB_CLOSEABLE|WB_SIZEABLE)); VclPtr xDlgParent = aObjects.back()->getRef(); aObjects.push_back(LeakTestObject::Create(xDlgParent)); VclPtr xVBox = aObjects.back()->getRef(); aObjects.push_back(LeakTestObject::Create(xVBox)); } aObjects.push_back(LeakTestObject::Create(xParent, u"PrintProgressDialog"_ustr, "vcl/ui/printprogressdialog.ui")); 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; } void LifecycleTest::testToolkit() { LeakTestObject *pVclWin = LeakTestObject::Create(nullptr, WB_APP|WB_STDWORK); css::uno::Reference xWindow(pVclWin->getRef()->GetComponentInterface(), css::uno::UNO_QUERY); CPPUNIT_ASSERT(xWindow.is()); // test UNO dispose css::uno::Reference xWinComponent = xWindow; CPPUNIT_ASSERT(xWinComponent.is()); CPPUNIT_ASSERT(!pVclWin->getRef()->isDisposed()); xWinComponent->dispose(); CPPUNIT_ASSERT(pVclWin->getRef()->isDisposed()); // test UNO cleanup xWinComponent.clear(); xWindow.clear(); pVclWin->disposeAndClear(); pVclWin->assertDeleted(); delete pVclWin; } CPPUNIT_TEST_SUITE_REGISTRATION(LifecycleTest); CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /vector-7.5.9-release'>distro/vector/vector-7.5.9-release LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
path: root/forms
AgeCommit message (Expand)Author
2024-09-16Fix typosAndrea Gelmini
2024-09-16use more concrete UNO types in formsNoel Grandin
2024-09-09tsan:lock-order-inversion in formsNoel Grandin
2024-09-09tsan:lock-order-inversion in formsNoel Grandin
2024-07-24tdf#161865 Base Table Design View not editableNoel Grandin
2024-07-23cid#1555167 COPY_INSTEAD_OF_MOVECaolán McNamara
2024-07-17cid#1608071 Out-of-bounds accessCaolán McNamara
2024-07-09Simplify comphelper::query_aggregationMike Kaganski
2024-06-27vcl: Remove graph. reader context from {Imp}Graph and GraphicReaderTomaž Vajngerl
2024-06-19Fix typoAndrea Gelmini
2024-06-18loplugin:ostr in variousNoel Grandin
2024-06-11Some missing "block untrusted referer links" for form controlsStephan Bergmann
2024-05-20don't need -I ... YaccTarget/connectivity/source/parse in formsCaolán McNamara
2024-05-16Drop unneeded 'using' instancesGabor Kelemen
2024-05-14createFromAscii -> OUString literals in OLimitedFormatsNoel Grandin
2024-05-11replace createFromAscii with OUString literals in ControlFeatureInterceptionNoel Grandin
2024-05-08tdf#160906 use SfxPoolItemHolderArmin Le Grand (allotropia)
2024-05-08loplugin:ostr in formsNoel Grandin
2024-05-02replace createFromAscii with OUString literals in formsNoel Grandin
2024-05-02WaE: C6011 Dereferencing NULL pointer warningsCaolán McNamara
2024-04-09Fix typo: compytibilityGabor Kelemen
2024-04-05tdf#146619 Drop unused 'using namespace' in: formsGabor Kelemen
2024-03-30tdf#42982 Add error messages to thrown exceptionsRMZeroFour
2024-03-28convert OXSDDataType to comphelper::WeakImplHelperBaseNoel Grandin
2024-02-18ITEM: Rename for more control over SlotID usagesArmin Le Grand (allotropia)
2024-02-12ITEM: ItemPool Rework (I)Armin Le Grand (allotropia)
2024-01-27ITEM: Cleanup some Pool stuff with DefaultsArmin Le Grand (allotropia)
2024-01-27Drop std::as_const from css::uno::Sequence iterationsMike Kaganski
2024-01-21editeng: change EditEngine getter to ref in {Imp}EditViewTomaž Vajngerl
2024-01-16loplugin:unusedmethodsNoel Grandin
2024-01-06cid#1560053 Missing move assignment operatorCaolán McNamara
2023-12-31cid#707862 Uninitialized pointer fieldCaolán McNamara
2023-12-31Replace "size() != 0 with !empty()" (forms)Julien Nabet
2023-12-31Remove duplicated includeAndrea Gelmini
2023-12-30no need to use SvLockBytes in OImageControlModelNoel Grandin
2023-12-30ImgProdLockBytes is unnecessaryNoel Grandin
2023-12-30no need to use SvLockBytes in formsNoel Grandin
2023-12-20cid#1545612 COPY_INSTEAD_OF_MOVECaolán McNamara
2023-12-07simplify and modernise ScopedBitmapAccessNoel Grandin
2023-12-04cid#1545597 Using invalid iteratorJulien Nabet
2023-11-23loplugin:fieldcast in BindingNoel Grandin
2023-10-23Extended loplugin:ostr: Rewrite some O[U]StringLiteral -> O[U]StringStephan Bergmann
2023-10-19Extended loplugin:ostr: Automatic rewrite O[U]StringLiteral: formsStephan Bergmann
2023-10-14Use exception ctors, instead of setting members laterMike Kaganski
2023-10-12Make NC_ constexpr-friendlyStephan Bergmann
2023-10-07loplugin:ostr: automatic rewriteStephan Bergmann
2023-10-05Replace useless lcl_throwIllegalArgumentException function (forms)Julien Nabet