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