diff options
Diffstat (limited to 'vcl/qa/cppunit')
-rw-r--r-- | vcl/qa/cppunit/complextext.cxx | 6 | ||||
-rw-r--r-- | vcl/qa/cppunit/lifecycle.cxx | 150 | ||||
-rw-r--r-- | vcl/qa/cppunit/outdev.cxx | 30 |
3 files changed, 168 insertions, 18 deletions
diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx index a6330e4880c8..0c666c356a93 100644 --- a/vcl/qa/cppunit/complextext.cxx +++ b/vcl/qa/cppunit/complextext.cxx @@ -43,10 +43,10 @@ void VclComplexTextTest::testArabic() OUString aOneTwoThree( reinterpret_cast<char const *>(pOneTwoThreeUTF8), SAL_N_ELEMENTS( pOneTwoThreeUTF8 ) - 1, RTL_TEXTENCODING_UTF8 ); - vcl::Window* pWin = new WorkWindow( (vcl::Window *)NULL ); - CPPUNIT_ASSERT( pWin != NULL ); + VclPtr<vcl::Window> pWin = VclPtr<WorkWindow>::Create( (vcl::Window *)nullptr ); + CPPUNIT_ASSERT( pWin ); - OutputDevice *pOutDev = static_cast< OutputDevice * >( pWin ); + OutputDevice *pOutDev = static_cast< OutputDevice * >( pWin.get() ); vcl::Font aFont = OutputDevice::GetDefaultFont( DEFAULTFONT_CTL_SPREADSHEET, diff --git a/vcl/qa/cppunit/lifecycle.cxx b/vcl/qa/cppunit/lifecycle.cxx new file mode 100644 index 000000000000..4a0bebff8d0c --- /dev/null +++ b/vcl/qa/cppunit/lifecycle.cxx @@ -0,0 +1,150 @@ +/* -*- 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> +#include <vcl/edit.hxx> +#include <vcl/combobox.hxx> +#include <vcl/field.hxx> +#include <vcl/virdev.hxx> + +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(); + + 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_SUITE_END(); +}; + +// A compile time sanity check +void LifecycleTest::testCast() +{ + ScopedVclPtrInstance< PushButton > xButton( nullptr, 0 ); + ScopedVclPtr<vcl::Window> xWindow(xButton); + + ScopedVclPtrInstance< MetricField > xField( nullptr, 0 ); + ScopedVclPtr<SpinField> xSpin(xField); + ScopedVclPtr<Edit> xEdit(xField); + +// the following line should NOT compile +// VclPtr<PushButton> xButton2(xWindow); +} + +void LifecycleTest::testVirtualDevice() +{ + VclPtr<VirtualDevice> pVDev = VclPtr< VirtualDevice >::Create(); + ScopedVclPtrInstance< VirtualDevice > pVDev2; + VclPtrInstance<VirtualDevice> pVDev3; + VclPtrInstance<VirtualDevice> pVDev4( 1 ); + CPPUNIT_ASSERT(!!pVDev && !!pVDev2 && !!pVDev3 && !!pVDev4); +} + +void LifecycleTest::testMultiDispose() +{ + VclPtrInstance<WorkWindow> xWin(nullptr, WB_APP|WB_STDWORK); + CPPUNIT_ASSERT(xWin.get() != NULL); + xWin->disposeOnce(); + xWin->disposeOnce(); + xWin->disposeOnce(); + CPPUNIT_ASSERT(xWin->GetWindow(0) == NULL); + CPPUNIT_ASSERT(xWin->GetChild(0) == NULL); + CPPUNIT_ASSERT(xWin->GetChildCount() == 0); +} + +void LifecycleTest::testWidgets(vcl::Window *pParent) +{ + { ScopedVclPtrInstance< PushButton > aPtr( pParent ); } + { ScopedVclPtrInstance< OKButton > aPtr( pParent ); } + { ScopedVclPtrInstance< CancelButton > aPtr( pParent ); } + { ScopedVclPtrInstance< HelpButton > aPtr( pParent ); } + + // Some widgets really insist on adoption. + if (pParent) + { + { ScopedVclPtrInstance< CheckBox > aPtr( pParent ); } + { ScopedVclPtrInstance< Edit > aPtr( pParent ); } + { ScopedVclPtrInstance< ComboBox > aPtr( pParent ); } + { ScopedVclPtrInstance< RadioButton > aPtr( pParent ); } + } +} + +void LifecycleTest::testIsolatedWidgets() +{ + testWidgets(NULL); +} + +void LifecycleTest::testParentedWidgets() +{ + ScopedVclPtrInstance<WorkWindow> xWin(nullptr, WB_APP|WB_STDWORK); + CPPUNIT_ASSERT(xWin.get() != NULL); + xWin->Show(); + testWidgets(xWin); +} + +class DisposableChild : public vcl::Window +{ +public: + DisposableChild(vcl::Window *pParent) : vcl::Window(pParent) {} + virtual ~DisposableChild() + { + disposeOnce(); + } +}; + +void LifecycleTest::testChildDispose() +{ + VclPtrInstance<WorkWindow> xWin(nullptr, WB_APP|WB_STDWORK); + CPPUNIT_ASSERT(xWin.get() != NULL); + VclPtrInstance< DisposableChild > xChild( xWin.get() ); + xWin->Show(); + xChild->disposeOnce(); + xWin->disposeOnce(); +} + +void LifecycleTest::testPostDispose() +{ + VclPtrInstance<WorkWindow> 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(0)); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(LifecycleTest); + +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/qa/cppunit/outdev.cxx b/vcl/qa/cppunit/outdev.cxx index 6ee359320931..a32ee7d3fd94 100644 --- a/vcl/qa/cppunit/outdev.cxx +++ b/vcl/qa/cppunit/outdev.cxx @@ -32,17 +32,17 @@ public: void VclOutdevTest::testVirtualDevice() { - VirtualDevice aVDev; - aVDev.SetOutputSizePixel(Size(32,32)); - aVDev.SetBackground(Wallpaper(COL_WHITE)); - aVDev.Erase(); - aVDev.DrawPixel(Point(1,2),COL_BLUE); - aVDev.DrawPixel(Point(31,30),COL_RED); - - Size aSize = aVDev.GetOutputSizePixel(); + ScopedVclPtrInstance< VirtualDevice > pVDev; + pVDev->SetOutputSizePixel(Size(32,32)); + pVDev->SetBackground(Wallpaper(COL_WHITE)); + pVDev->Erase(); + pVDev->DrawPixel(Point(1,2),COL_BLUE); + pVDev->DrawPixel(Point(31,30),COL_RED); + + Size aSize = pVDev->GetOutputSizePixel(); CPPUNIT_ASSERT(aSize == Size(32,32)); - Bitmap aBmp = aVDev.GetBitmap(Point(),aSize); + Bitmap aBmp = pVDev->GetBitmap(Point(),aSize); #if 0 OUString rFileName("/tmp/foo-unx.png"); @@ -56,12 +56,12 @@ void VclOutdevTest::testVirtualDevice() } #endif - CPPUNIT_ASSERT_EQUAL(COL_WHITE, aVDev.GetPixel(Point(0,0)).GetColor()); + CPPUNIT_ASSERT_EQUAL(COL_WHITE, pVDev->GetPixel(Point(0,0)).GetColor()); #if defined LINUX //TODO: various failures on Mac and Windows tinderboxes - CPPUNIT_ASSERT_EQUAL(COL_BLUE, aVDev.GetPixel(Point(1,2)).GetColor()); - CPPUNIT_ASSERT_EQUAL(COL_RED, aVDev.GetPixel(Point(31,30)).GetColor()); + CPPUNIT_ASSERT_EQUAL(COL_BLUE, pVDev->GetPixel(Point(1,2)).GetColor()); + CPPUNIT_ASSERT_EQUAL(COL_RED, pVDev->GetPixel(Point(31,30)).GetColor()); #endif - CPPUNIT_ASSERT_EQUAL(COL_WHITE, aVDev.GetPixel(Point(30,31)).GetColor()); + CPPUNIT_ASSERT_EQUAL(COL_WHITE, pVDev->GetPixel(Point(30,31)).GetColor()); // Gotcha: y and x swap for BitmapReadAccess: deep joy. Bitmap::ScopedReadAccess pAcc(aBmp); @@ -73,8 +73,8 @@ void VclOutdevTest::testVirtualDevice() CPPUNIT_ASSERT_EQUAL(COL_WHITE, Color(pAcc->GetPixel(31,30)).GetColor()); #if 0 - vcl::Window* pWin = new WorkWindow( (vcl::Window *)NULL ); - CPPUNIT_ASSERT( pWin != NULL ); + VclPtr<vcl::Window> pWin = VclPtr<WorkWindow>::Create( (vcl::Window *)nullptr ); + CPPUNIT_ASSERT( pWin ); OutputDevice *pOutDev = static_cast< OutputDevice * >( pWin ); #endif } |