| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the LibreOffice project. |
| 4 |
* |
| 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 |
*/ |
| 9 |
|
| 10 |
#include <config_poppler.h> |
| 11 |
#include <test/unoapi_test.hxx> |
| 12 |
|
| 13 |
#include <com/sun/star/embed/XStorage.hpp> |
| 14 |
|
| 15 |
#include <comphelper/embeddedobjectcontainer.hxx> |
| 16 |
#include <comphelper/propertyvalue.hxx> |
| 17 |
#include <comphelper/scopeguard.hxx> |
| 18 |
#include <comphelper/storagehelper.hxx> |
| 19 |
#include <officecfg/Office/Common.hxx> |
| 20 |
|
| 21 |
using namespace ::com::sun::star; |
| 22 |
|
| 23 |
namespace |
| 24 |
{ |
| 25 |
/// Covers embeddedobj/source/general/ fixes. |
| 26 |
class Test : public UnoApiTest |
| 27 |
{ |
| 28 |
public: |
| 29 |
Test() |
| 30 |
: UnoApiTest(u"/embeddedobj/qa/cppunit/data/"_ustr) |
| 31 |
{ |
| 32 |
} |
| 33 |
}; |
| 34 |
} |
| 35 |
|
| 36 |
CPPUNIT_TEST_FIXTURE(Test, testInsertFileConfig) |
| 37 |
{ |
| 38 |
// Explicitly disable Word->Writer mapping for this test. |
| 39 |
std::shared_ptr<comphelper::ConfigurationChanges> pBatch( |
| 40 |
comphelper::ConfigurationChanges::create()); |
| 41 |
officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::set(false, pBatch); |
| 42 |
pBatch->commit(); |
| 43 |
comphelper::ScopeGuard g([]() { |
| 44 |
std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset( |
| 45 |
comphelper::ConfigurationChanges::create()); |
| 46 |
officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::set(true, |
| 47 |
pBatchReset); |
| 48 |
pBatchReset->commit(); |
| 49 |
}); |
| 50 |
loadFromURL(u"private:factory/swriter"_ustr); |
| 51 |
|
| 52 |
// Insert a file as an embedded object. |
| 53 |
uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage(); |
| 54 |
comphelper::EmbeddedObjectContainer aContainer(xStorage); |
| 55 |
OUString aFileName = createFileURL(u"insert-file-config.doc"); |
| 56 |
uno::Sequence<beans::PropertyValue> aMedium{ comphelper::makePropertyValue(u"URL"_ustr, |
| 57 |
aFileName) }; |
| 58 |
OUString aName(u"Object 1"_ustr); |
| 59 |
uno::Reference<embed::XEmbeddedObject> xObject |
| 60 |
= aContainer.InsertEmbeddedObject(aMedium, aName); |
| 61 |
|
| 62 |
// Make sure that the insertion fails: |
| 63 |
// 1) the user explicitly requested that the data is not loaded into Writer |
| 64 |
// 2) this is non-Windows, so OLE embedding is not an option |
| 65 |
// so silently still loading the data into Writer would be bad. |
| 66 |
CPPUNIT_ASSERT(!xObject.is()); |
| 67 |
} |
| 68 |
|
| 69 |
CPPUNIT_TEST_FIXTURE(Test, testInsertFileConfigVsdx) |
| 70 |
{ |
| 71 |
// Explicitly disable Word->Writer mapping for this test. |
| 72 |
std::shared_ptr<comphelper::ConfigurationChanges> pBatch( |
| 73 |
comphelper::ConfigurationChanges::create()); |
| 74 |
officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw::set(false, pBatch); |
| 75 |
pBatch->commit(); |
| 76 |
comphelper::ScopeGuard g([]() { |
| 77 |
std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset( |
| 78 |
comphelper::ConfigurationChanges::create()); |
| 79 |
officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw::set(true, pBatchReset); |
| 80 |
pBatchReset->commit(); |
| 81 |
}); |
| 82 |
loadFromURL(u"private:factory/swriter"_ustr); |
| 83 |
|
| 84 |
// Insert a file as an embedded object. |
| 85 |
uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage(); |
| 86 |
comphelper::EmbeddedObjectContainer aContainer(xStorage); |
| 87 |
OUString aFileName = createFileURL(u"insert-file-config.vsdx"); |
| 88 |
uno::Sequence<beans::PropertyValue> aMedium{ comphelper::makePropertyValue(u"URL"_ustr, |
| 89 |
aFileName) }; |
| 90 |
OUString aName(u"Object 1"_ustr); |
| 91 |
uno::Reference<embed::XEmbeddedObject> xObject |
| 92 |
= aContainer.InsertEmbeddedObject(aMedium, aName); |
| 93 |
|
| 94 |
// Make sure that the insertion fails: |
| 95 |
// 1) the user explicitly requested that the data is not loaded into Writer |
| 96 |
// 2) this is non-Windows, so OLE embedding is not an option |
| 97 |
// so silently still loading the data into Writer would be bad. |
| 98 |
CPPUNIT_ASSERT(!xObject.is()); |
| 99 |
} |
| 100 |
|
| 101 |
#if ENABLE_PDFIMPORT |
| 102 |
CPPUNIT_TEST_FIXTURE(Test, testInsertFileConfigPdf) |
| 103 |
{ |
| 104 |
// Explicitly disable Word->Writer mapping for this test. |
| 105 |
std::shared_ptr<comphelper::ConfigurationChanges> pBatch( |
| 106 |
comphelper::ConfigurationChanges::create()); |
| 107 |
officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(false, pBatch); |
| 108 |
pBatch->commit(); |
| 109 |
comphelper::ScopeGuard g([]() { |
| 110 |
std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset( |
| 111 |
comphelper::ConfigurationChanges::create()); |
| 112 |
officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(true, pBatchReset); |
| 113 |
pBatchReset->commit(); |
| 114 |
}); |
| 115 |
loadFromURL(u"private:factory/swriter"_ustr); |
| 116 |
|
| 117 |
// Insert a PDF file as an embedded object. |
| 118 |
uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage(); |
| 119 |
comphelper::EmbeddedObjectContainer aContainer(xStorage); |
| 120 |
OUString aFileName = createFileURL(u"insert-file-config.pdf"); |
| 121 |
uno::Sequence<beans::PropertyValue> aMedium{ comphelper::makePropertyValue(u"URL"_ustr, |
| 122 |
aFileName) }; |
| 123 |
OUString aName(u"Object 1"_ustr); |
| 124 |
uno::Reference<embed::XEmbeddedObject> xObject |
| 125 |
= aContainer.InsertEmbeddedObject(aMedium, aName); |
| 126 |
|
| 127 |
// Make sure that the insertion fails: |
| 128 |
// 1) the user explicitly requested that the data is not loaded into Writer |
| 129 |
// 2) this is non-Windows, so OLE embedding is not an option |
| 130 |
// so silently still loading the data into Writer would be bad. |
| 131 |
CPPUNIT_ASSERT(!xObject.is()); |
| 132 |
} |
| 133 |
#endif |
| 134 |
CPPUNIT_PLUGIN_IMPLEMENT(); |
| 135 |
|
| 136 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |