1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <test/bootstrapfixture.hxx>
11 #include <unotest/macros_test.hxx>
13 #include <com/sun/star/frame/Desktop.hpp>
14 #include <com/sun/star/view/XSelectionSupplier.hpp>
15 #include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
17 #include <comphelper/propertyvalue.hxx>
18 #include <sfx2/objsh.hxx>
19 #include <sfx2/sfxbasemodel.hxx>
20 #include <osl/file.hxx>
22 using namespace com::sun::star
;
26 /// Covers sfx2/source/doc/ fixes.
27 class Test
: public test::BootstrapFixture
, public unotest::MacrosTest
30 uno::Reference
<lang::XComponent
> mxComponent
;
33 void setUp() override
;
34 void tearDown() override
;
35 uno::Reference
<lang::XComponent
>& getComponent() { return mxComponent
; }
40 test::BootstrapFixture::setUp();
42 mxDesktop
.set(frame::Desktop::create(mxComponentContext
));
48 mxComponent
->dispose();
50 test::BootstrapFixture::tearDown();
53 CPPUNIT_TEST_FIXTURE(Test
, testNoGrabBagShape
)
55 // Load a document and select the first shape.
56 css::uno::Sequence
<css::beans::PropertyValue
> aArgs
{ comphelper::makePropertyValue("ReadOnly",
58 getComponent() = loadFromDesktop("private:factory/simpress", "", aArgs
);
59 uno::Reference
<frame::XModel
> xModel(getComponent(), uno::UNO_QUERY
);
60 uno::Reference
<drawing::XDrawPagesSupplier
> xDrawPagesSupplier(xModel
, uno::UNO_QUERY
);
61 uno::Reference
<container::XIndexAccess
> xDrawPage(
62 xDrawPagesSupplier
->getDrawPages()->getByIndex(0), uno::UNO_QUERY
);
63 uno::Any aShape
= xDrawPage
->getByIndex(0);
64 uno::Reference
<view::XSelectionSupplier
> xController(xModel
->getCurrentController(),
66 xController
->select(aShape
);
68 // See if it has a signing certificate associated.
69 auto pBaseModel
= dynamic_cast<SfxBaseModel
*>(xModel
.get());
70 CPPUNIT_ASSERT(pBaseModel
);
71 SfxObjectShell
* pObjectShell
= pBaseModel
->GetObjectShell();
73 // Without the accompanying fix in place, this test would have failed with:
74 // An uncaught exception of type com.sun.star.beans.UnknownPropertyException
75 // which was not caught later, resulting in a crash.
76 pObjectShell
->GetSignPDFCertificate();
79 CPPUNIT_TEST_FIXTURE(Test
, testTempFilePath
)
81 // Create a test file in a directory that contains the URL-encoded "testÿ" string.
82 getComponent() = loadFromDesktop("private:factory/swriter");
83 auto pBaseModel
= dynamic_cast<SfxBaseModel
*>(getComponent().get());
84 CPPUNIT_ASSERT(pBaseModel
);
86 = m_directories
.getURLFromWorkdir(u
"CppunitTest/sfx2_doc.test.user/test%25C3%25Bf");
87 osl::Directory::create(aTargetDir
);
88 OUString aTargetFile
= aTargetDir
+ "/test.odt";
89 css::uno::Sequence
<css::beans::PropertyValue
> aArgs
{ comphelper::makePropertyValue(
90 "FilterName", OUString("writer8")) };
91 pBaseModel
->storeAsURL(aTargetFile
, aArgs
);
92 getComponent()->dispose();
94 // Load it and export to PDF.
95 getComponent() = loadFromDesktop(aTargetFile
);
96 pBaseModel
= dynamic_cast<SfxBaseModel
*>(getComponent().get());
97 OUString aPdfTarget
= aTargetDir
+ "/test.pdf";
98 css::uno::Sequence
<css::beans::PropertyValue
> aPdfArgs
{ comphelper::makePropertyValue(
99 "FilterName", OUString("writer_pdf_Export")) };
100 // Without the accompanying fix in place, this test would have failed on Windows with:
101 // An uncaught exception of type com.sun.star.io.IOException
102 // because we first tried to create a temp file next to test.odt in a directory named
103 // "test%25C3%25Bf" instead of a directory named "test%C3%Bf".
104 pBaseModel
->storeToURL(aPdfTarget
, aPdfArgs
);
108 CPPUNIT_PLUGIN_IMPLEMENT();
110 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */