nss: upgrade to release 3.73
[LibreOffice.git] / sfx2 / qa / cppunit / doc.cxx
blob058bf4788d6726299aea925aad24b068ff64d0c1
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/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 <unotools/tempfile.hxx>
21 #include <sfx2/docfile.hxx>
22 #include <osl/file.hxx>
24 using namespace com::sun::star;
26 namespace
28 /// Covers sfx2/source/doc/ fixes.
29 class Test : public test::BootstrapFixture, public unotest::MacrosTest
31 private:
32 uno::Reference<lang::XComponent> mxComponent;
34 public:
35 void setUp() override;
36 void tearDown() override;
37 uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
40 void Test::setUp()
42 test::BootstrapFixture::setUp();
44 mxDesktop.set(frame::Desktop::create(mxComponentContext));
47 void Test::tearDown()
49 if (mxComponent.is())
50 mxComponent->dispose();
52 test::BootstrapFixture::tearDown();
55 CPPUNIT_TEST_FIXTURE(Test, testNoGrabBagShape)
57 // Load a document and select the first shape.
58 css::uno::Sequence<css::beans::PropertyValue> aArgs{ comphelper::makePropertyValue("ReadOnly",
59 true) };
60 getComponent() = loadFromDesktop("private:factory/simpress", "", aArgs);
61 uno::Reference<frame::XModel> xModel(getComponent(), uno::UNO_QUERY);
62 uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xModel, uno::UNO_QUERY);
63 uno::Reference<container::XIndexAccess> xDrawPage(
64 xDrawPagesSupplier->getDrawPages()->getByIndex(0), uno::UNO_QUERY);
65 uno::Any aShape = xDrawPage->getByIndex(0);
66 uno::Reference<view::XSelectionSupplier> xController(xModel->getCurrentController(),
67 uno::UNO_QUERY);
68 xController->select(aShape);
70 // See if it has a signing certificate associated.
71 auto pBaseModel = dynamic_cast<SfxBaseModel*>(xModel.get());
72 CPPUNIT_ASSERT(pBaseModel);
73 SfxObjectShell* pObjectShell = pBaseModel->GetObjectShell();
75 // Without the accompanying fix in place, this test would have failed with:
76 // An uncaught exception of type com.sun.star.beans.UnknownPropertyException
77 // which was not caught later, resulting in a crash.
78 pObjectShell->GetSignPDFCertificate();
81 CPPUNIT_TEST_FIXTURE(Test, testTempFilePath)
83 // Create a test file in a directory that contains the URL-encoded "testÿ" string.
84 getComponent() = loadFromDesktop("private:factory/swriter");
85 auto pBaseModel = dynamic_cast<SfxBaseModel*>(getComponent().get());
86 CPPUNIT_ASSERT(pBaseModel);
87 OUString aTargetDir
88 = m_directories.getURLFromWorkdir(u"CppunitTest/sfx2_doc.test.user/test%25C3%25Bf");
89 osl::Directory::create(aTargetDir);
90 OUString aTargetFile = aTargetDir + "/test.odt";
91 css::uno::Sequence<css::beans::PropertyValue> aArgs{ comphelper::makePropertyValue(
92 "FilterName", OUString("writer8")) };
93 pBaseModel->storeAsURL(aTargetFile, aArgs);
94 getComponent()->dispose();
96 // Load it and export to PDF.
97 getComponent() = loadFromDesktop(aTargetFile);
98 pBaseModel = dynamic_cast<SfxBaseModel*>(getComponent().get());
99 OUString aPdfTarget = aTargetDir + "/test.pdf";
100 css::uno::Sequence<css::beans::PropertyValue> aPdfArgs{ comphelper::makePropertyValue(
101 "FilterName", OUString("writer_pdf_Export")) };
102 // Without the accompanying fix in place, this test would have failed on Windows with:
103 // An uncaught exception of type com.sun.star.io.IOException
104 // because we first tried to create a temp file next to test.odt in a directory named
105 // "test%25C3%25Bf" instead of a directory named "test%C3%Bf".
106 pBaseModel->storeToURL(aPdfTarget, aPdfArgs);
110 CPPUNIT_PLUGIN_IMPLEMENT();
112 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */