Bump version to 6.4-15
[LibreOffice.git] / embeddedobj / qa / cppunit / general.cxx
blobba862d3a86f05c0e1eeba8b5d2514daeb52e1662
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/embed/XStorage.hpp>
16 #include <comphelper/embeddedobjectcontainer.hxx>
17 #include <comphelper/processfactory.hxx>
18 #include <comphelper/propertyvalue.hxx>
19 #include <comphelper/scopeguard.hxx>
20 #include <comphelper/storagehelper.hxx>
21 #include <officecfg/Office/Common.hxx>
23 using namespace ::com::sun::star;
25 /// embeddedobj general tests.
26 class EmbeddedobjGeneralTest : public test::BootstrapFixture, public unotest::MacrosTest
28 private:
29 uno::Reference<uno::XComponentContext> mxComponentContext;
30 uno::Reference<lang::XComponent> mxComponent;
32 public:
33 void setUp() override;
34 void tearDown() override;
35 uno::Reference<lang::XComponent>& getComponent() { return mxComponent; }
38 void EmbeddedobjGeneralTest::setUp()
40 test::BootstrapFixture::setUp();
42 mxComponentContext.set(comphelper::getComponentContext(getMultiServiceFactory()));
43 mxDesktop.set(frame::Desktop::create(mxComponentContext));
46 void EmbeddedobjGeneralTest::tearDown()
48 if (mxComponent.is())
49 mxComponent->dispose();
51 test::BootstrapFixture::tearDown();
54 CPPUNIT_TEST_FIXTURE(EmbeddedobjGeneralTest, testInsertFileConfig)
56 // Explicitly disable Word->Writer mapping for this test.
57 std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
58 comphelper::ConfigurationChanges::create());
59 officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::set(false, pBatch);
60 pBatch->commit();
61 comphelper::ScopeGuard g([]() {
62 std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset(
63 comphelper::ConfigurationChanges::create());
64 officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::set(true,
65 pBatchReset);
66 pBatchReset->commit();
67 });
68 getComponent().set(
69 loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"));
71 // Insert a file as an embedded object.
72 uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
73 comphelper::EmbeddedObjectContainer aContainer(xStorage);
74 OUString aFileName
75 = m_directories.getURLFromSrc("embeddedobj/qa/cppunit/data/insert-file-config.doc");
76 uno::Sequence<beans::PropertyValue> aMedium{ comphelper::makePropertyValue("URL", aFileName) };
77 OUString aName("Object 1");
78 uno::Reference<embed::XEmbeddedObject> xObject
79 = aContainer.InsertEmbeddedObject(aMedium, aName);
81 // Make sure that the insertion fails:
82 // 1) the user explicitly requested that the data is not loaded into Writer
83 // 2) this is non-Windows, so OLE embedding is not an option
84 // so silently still loading the data into Writer would be bad.
85 CPPUNIT_ASSERT(!xObject.is());
88 CPPUNIT_TEST_FIXTURE(EmbeddedobjGeneralTest, testInsertFileConfigVsdx)
90 // Explicitly disable Word->Writer mapping for this test.
91 std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
92 comphelper::ConfigurationChanges::create());
93 officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw::set(false, pBatch);
94 pBatch->commit();
95 comphelper::ScopeGuard g([]() {
96 std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset(
97 comphelper::ConfigurationChanges::create());
98 officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw::set(true, pBatchReset);
99 pBatchReset->commit();
101 getComponent().set(
102 loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"));
104 // Insert a file as an embedded object.
105 uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
106 comphelper::EmbeddedObjectContainer aContainer(xStorage);
107 OUString aFileName
108 = m_directories.getURLFromSrc("embeddedobj/qa/cppunit/data/insert-file-config.vsdx");
109 uno::Sequence<beans::PropertyValue> aMedium{ comphelper::makePropertyValue("URL", aFileName) };
110 OUString aName("Object 1");
111 uno::Reference<embed::XEmbeddedObject> xObject
112 = aContainer.InsertEmbeddedObject(aMedium, aName);
114 // Make sure that the insertion fails:
115 // 1) the user explicitly requested that the data is not loaded into Writer
116 // 2) this is non-Windows, so OLE embedding is not an option
117 // so silently still loading the data into Writer would be bad.
118 CPPUNIT_ASSERT(!xObject.is());
121 CPPUNIT_TEST_FIXTURE(EmbeddedobjGeneralTest, testInsertFileConfigPdf)
123 // Explicitly disable Word->Writer mapping for this test.
124 std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
125 comphelper::ConfigurationChanges::create());
126 officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(false, pBatch);
127 pBatch->commit();
128 comphelper::ScopeGuard g([]() {
129 std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset(
130 comphelper::ConfigurationChanges::create());
131 officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(true, pBatchReset);
132 pBatchReset->commit();
134 getComponent().set(
135 loadFromDesktop("private:factory/swriter", "com.sun.star.text.TextDocument"));
137 // Insert a PDF file as an embedded object.
138 uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
139 comphelper::EmbeddedObjectContainer aContainer(xStorage);
140 OUString aFileName
141 = m_directories.getURLFromSrc("embeddedobj/qa/cppunit/data/insert-file-config.pdf");
142 uno::Sequence<beans::PropertyValue> aMedium{ comphelper::makePropertyValue("URL", aFileName) };
143 OUString aName("Object 1");
144 uno::Reference<embed::XEmbeddedObject> xObject
145 = aContainer.InsertEmbeddedObject(aMedium, aName);
147 // Make sure that the insertion fails:
148 // 1) the user explicitly requested that the data is not loaded into Writer
149 // 2) this is non-Windows, so OLE embedding is not an option
150 // so silently still loading the data into Writer would be bad.
151 CPPUNIT_ASSERT(!xObject.is());
154 CPPUNIT_PLUGIN_IMPLEMENT();
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */