bump product version to 7.2.5.1
[LibreOffice.git] / sfx2 / qa / cppunit / view.cxx
blob70bb5fd4f54b5c314525c1d39af69fcab40e61e9
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 <test/bootstrapfixture.hxx>
11 #include <unotest/macros_test.hxx>
13 #include <com/sun/star/frame/Desktop.hpp>
14 #include <com/sun/star/drawing/XDrawView.hpp>
15 #include <com/sun/star/beans/XPropertySet.hpp>
17 #include <sfx2/app.hxx>
18 #include <sfx2/sfxsids.hrc>
19 #include <sfx2/viewfrm.hxx>
20 #include <svl/itemset.hxx>
21 #include <svl/intitem.hxx>
22 #include <sfx2/request.hxx>
23 #include <sfx2/bindings.hxx>
25 using namespace com::sun::star;
27 constexpr OUStringLiteral DATA_DIRECTORY = u"/sfx2/qa/cppunit/data/";
29 /// Covers sfx2/source/view/ fixes.
30 class Sfx2ViewTest : public test::BootstrapFixture, public unotest::MacrosTest
32 private:
33 uno::Reference<lang::XComponent> mxComponent;
35 public:
36 void setUp() override;
37 void tearDown() override;
38 uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
41 void Sfx2ViewTest::setUp()
43 test::BootstrapFixture::setUp();
45 mxDesktop.set(frame::Desktop::create(mxComponentContext));
48 void Sfx2ViewTest::tearDown()
50 if (mxComponent.is())
51 mxComponent->dispose();
53 test::BootstrapFixture::tearDown();
56 CPPUNIT_TEST_FIXTURE(Sfx2ViewTest, testReloadPage)
58 // Load a document, which has 2 pages.
59 OUString aURL = m_directories.getURLFromSrc(DATA_DIRECTORY) + "reload-page.odg";
60 getComponent() = loadFromDesktop(aURL);
62 // Reload, and request to start on page 2.
63 SfxViewFrame* pFrame = SfxViewFrame::Current();
64 SfxAllItemSet aSet(SfxGetpApp()->GetPool());
65 aSet.Put(SfxInt32Item(SID_PAGE_NUMBER, 1));
66 SfxRequest aReq(SID_RELOAD, SfxCallMode::SLOT, aSet);
67 pFrame->ExecReload_Impl(aReq);
68 uno::Reference<frame::XModel> xModel = SfxObjectShell::Current()->GetBaseModel();
69 getComponent() = xModel;
71 // Check the current page after reload.
72 uno::Reference<drawing::XDrawView> xController(xModel->getCurrentController(), uno::UNO_QUERY);
73 uno::Reference<beans::XPropertySet> xPage(xController->getCurrentPage(), uno::UNO_QUERY);
74 sal_Int32 nPage{};
75 xPage->getPropertyValue("Number") >>= nPage;
77 // Without the accompanying fix in place, this test would have failed with:
78 // - Expected: 2
79 // - Actual : 1
80 // i.e. the document was opened on page 1, not page 2, SID_PAGE_NUMBER was ignored.
81 CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(2), nPage);
84 CPPUNIT_PLUGIN_IMPLEMENT();
86 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */