tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / embeddedobj / qa / cppunit / general.cxx
blob1c681b3137a95fb68c2eb90d0611a3f67ae64eb7
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/unoapi_test.hxx>
12 #include <com/sun/star/embed/XStorage.hpp>
14 #include <comphelper/embeddedobjectcontainer.hxx>
15 #include <comphelper/propertyvalue.hxx>
16 #include <comphelper/scopeguard.hxx>
17 #include <comphelper/storagehelper.hxx>
18 #include <officecfg/Office/Common.hxx>
20 using namespace ::com::sun::star;
22 namespace
24 /// Covers embeddedobj/source/general/ fixes.
25 class Test : public UnoApiTest
27 public:
28 Test()
29 : UnoApiTest(u"/embeddedobj/qa/cppunit/data/"_ustr)
35 CPPUNIT_TEST_FIXTURE(Test, testInsertFileConfig)
37 // Explicitly disable Word->Writer mapping for this test.
38 std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
39 comphelper::ConfigurationChanges::create());
40 officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::set(false, pBatch);
41 pBatch->commit();
42 comphelper::ScopeGuard g([]() {
43 std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset(
44 comphelper::ConfigurationChanges::create());
45 officecfg::Office::Common::Filter::Microsoft::Import::WinWordToWriter::set(true,
46 pBatchReset);
47 pBatchReset->commit();
48 });
49 loadFromURL(u"private:factory/swriter"_ustr);
51 // Insert a file as an embedded object.
52 uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
53 comphelper::EmbeddedObjectContainer aContainer(xStorage);
54 OUString aFileName = createFileURL(u"insert-file-config.doc");
55 uno::Sequence<beans::PropertyValue> aMedium{ comphelper::makePropertyValue(u"URL"_ustr,
56 aFileName) };
57 OUString aName(u"Object 1"_ustr);
58 uno::Reference<embed::XEmbeddedObject> xObject
59 = aContainer.InsertEmbeddedObject(aMedium, aName);
61 // Make sure that the insertion fails:
62 // 1) the user explicitly requested that the data is not loaded into Writer
63 // 2) this is non-Windows, so OLE embedding is not an option
64 // so silently still loading the data into Writer would be bad.
65 CPPUNIT_ASSERT(!xObject.is());
68 CPPUNIT_TEST_FIXTURE(Test, testInsertFileConfigVsdx)
70 // Explicitly disable Word->Writer mapping for this test.
71 std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
72 comphelper::ConfigurationChanges::create());
73 officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw::set(false, pBatch);
74 pBatch->commit();
75 comphelper::ScopeGuard g([]() {
76 std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset(
77 comphelper::ConfigurationChanges::create());
78 officecfg::Office::Common::Filter::Microsoft::Import::VisioToDraw::set(true, pBatchReset);
79 pBatchReset->commit();
80 });
81 loadFromURL(u"private:factory/swriter"_ustr);
83 // Insert a file as an embedded object.
84 uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
85 comphelper::EmbeddedObjectContainer aContainer(xStorage);
86 OUString aFileName = createFileURL(u"insert-file-config.vsdx");
87 uno::Sequence<beans::PropertyValue> aMedium{ comphelper::makePropertyValue(u"URL"_ustr,
88 aFileName) };
89 OUString aName(u"Object 1"_ustr);
90 uno::Reference<embed::XEmbeddedObject> xObject
91 = aContainer.InsertEmbeddedObject(aMedium, aName);
93 // Make sure that the insertion fails:
94 // 1) the user explicitly requested that the data is not loaded into Writer
95 // 2) this is non-Windows, so OLE embedding is not an option
96 // so silently still loading the data into Writer would be bad.
97 CPPUNIT_ASSERT(!xObject.is());
100 CPPUNIT_TEST_FIXTURE(Test, testInsertFileConfigPdf)
102 // Explicitly disable Word->Writer mapping for this test.
103 std::shared_ptr<comphelper::ConfigurationChanges> pBatch(
104 comphelper::ConfigurationChanges::create());
105 officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(false, pBatch);
106 pBatch->commit();
107 comphelper::ScopeGuard g([]() {
108 std::shared_ptr<comphelper::ConfigurationChanges> pBatchReset(
109 comphelper::ConfigurationChanges::create());
110 officecfg::Office::Common::Filter::Adobe::Import::PDFToDraw::set(true, pBatchReset);
111 pBatchReset->commit();
113 loadFromURL(u"private:factory/swriter"_ustr);
115 // Insert a PDF file as an embedded object.
116 uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetTemporaryStorage();
117 comphelper::EmbeddedObjectContainer aContainer(xStorage);
118 OUString aFileName = createFileURL(u"insert-file-config.pdf");
119 uno::Sequence<beans::PropertyValue> aMedium{ comphelper::makePropertyValue(u"URL"_ustr,
120 aFileName) };
121 OUString aName(u"Object 1"_ustr);
122 uno::Reference<embed::XEmbeddedObject> xObject
123 = aContainer.InsertEmbeddedObject(aMedium, aName);
125 // Make sure that the insertion fails:
126 // 1) the user explicitly requested that the data is not loaded into Writer
127 // 2) this is non-Windows, so OLE embedding is not an option
128 // so silently still loading the data into Writer would be bad.
129 CPPUNIT_ASSERT(!xObject.is());
132 CPPUNIT_PLUGIN_IMPLEMENT();
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */