bump product version to 5.0.4.1
[LibreOffice.git] / vcl / qa / cppunit / outdev.cxx
bloba32ee7d3fd946a0ff97b4099ae83534c980562a8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <unotest/filters-test.hxx>
11 #include <test/bootstrapfixture.hxx>
13 #include <vcl/virdev.hxx>
14 #include <vcl/salbtype.hxx>
15 #include <vcl/bmpacc.hxx>
16 #include <vcl/wrkwin.hxx>
18 #include <tools/stream.hxx>
19 #include <vcl/pngwrite.hxx>
21 class VclOutdevTest : public test::BootstrapFixture
23 public:
24 VclOutdevTest() : BootstrapFixture(true, false) {}
26 void testVirtualDevice();
28 CPPUNIT_TEST_SUITE(VclOutdevTest);
29 CPPUNIT_TEST(testVirtualDevice);
30 CPPUNIT_TEST_SUITE_END();
33 void VclOutdevTest::testVirtualDevice()
35 ScopedVclPtrInstance< VirtualDevice > pVDev;
36 pVDev->SetOutputSizePixel(Size(32,32));
37 pVDev->SetBackground(Wallpaper(COL_WHITE));
38 pVDev->Erase();
39 pVDev->DrawPixel(Point(1,2),COL_BLUE);
40 pVDev->DrawPixel(Point(31,30),COL_RED);
42 Size aSize = pVDev->GetOutputSizePixel();
43 CPPUNIT_ASSERT(aSize == Size(32,32));
45 Bitmap aBmp = pVDev->GetBitmap(Point(),aSize);
47 #if 0
48 OUString rFileName("/tmp/foo-unx.png");
49 try {
50 vcl::PNGWriter aWriter( aBmp );
51 SvFileStream sOutput( rFileName, StreamMode::WRITE );
52 aWriter.Write( sOutput );
53 sOutput.Close();
54 } catch (...) {
55 SAL_WARN("vcl", "Error writing png to " << rFileName);
57 #endif
59 CPPUNIT_ASSERT_EQUAL(COL_WHITE, pVDev->GetPixel(Point(0,0)).GetColor());
60 #if defined LINUX //TODO: various failures on Mac and Windows tinderboxes
61 CPPUNIT_ASSERT_EQUAL(COL_BLUE, pVDev->GetPixel(Point(1,2)).GetColor());
62 CPPUNIT_ASSERT_EQUAL(COL_RED, pVDev->GetPixel(Point(31,30)).GetColor());
63 #endif
64 CPPUNIT_ASSERT_EQUAL(COL_WHITE, pVDev->GetPixel(Point(30,31)).GetColor());
66 // Gotcha: y and x swap for BitmapReadAccess: deep joy.
67 Bitmap::ScopedReadAccess pAcc(aBmp);
68 CPPUNIT_ASSERT_EQUAL(COL_WHITE, Color(pAcc->GetPixel(0,0)).GetColor());
69 #if defined LINUX //TODO: various failures on Mac and Windows tinderboxes
70 CPPUNIT_ASSERT_EQUAL(COL_BLUE, Color(pAcc->GetPixel(2,1)).GetColor());
71 CPPUNIT_ASSERT_EQUAL(COL_RED, Color(pAcc->GetPixel(30,31)).GetColor());
72 #endif
73 CPPUNIT_ASSERT_EQUAL(COL_WHITE, Color(pAcc->GetPixel(31,30)).GetColor());
75 #if 0
76 VclPtr<vcl::Window> pWin = VclPtr<WorkWindow>::Create( (vcl::Window *)nullptr );
77 CPPUNIT_ASSERT( pWin );
78 OutputDevice *pOutDev = static_cast< OutputDevice * >( pWin );
79 #endif
82 CPPUNIT_TEST_SUITE_REGISTRATION(VclOutdevTest);
84 CPPUNIT_PLUGIN_IMPLEMENT();
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */