1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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/.
10 #include <test/unoapixml_test.hxx>
12 #include <com/sun/star/frame/Desktop.hpp>
13 #include <com/sun/star/embed/XStorage.hpp>
14 #include <com/sun/star/frame/XStorable.hpp>
15 #include <com/sun/star/util/XCloseable.hpp>
17 #include <comphelper/embeddedobjectcontainer.hxx>
18 #include <comphelper/propertyvalue.hxx>
19 #include <comphelper/scopeguard.hxx>
20 #include <comphelper/storagehelper.hxx>
21 #include <officecfg/Office/Common.hxx>
22 #include <unotools/tempfile.hxx>
23 #include <osl/thread.hxx>
24 #include <vcl/svapp.hxx>
25 #include <tools/debug.hxx>
26 #include <unotools/ucbstreamhelper.hxx>
27 #include <vcl/outdev.hxx>
30 #include <systools/win32/comtools.hxx>
33 using namespace ::com::sun::star
;
37 /// Covers embeddedobj/source/msole/ fixes.
38 class Test
: public UnoApiXmlTest
42 : UnoApiXmlTest("/embeddedobj/qa/cppunit/data/")
47 bool IsPaintClassNotRegistered()
50 sal::systools::CoInitializeGuard
g(0);
51 // Check if MS Paint's {0003000A-0000-0000-C000-000000000046} is registered
52 CLSID clsidPaint
{ 0x0003000A, 0000, 0000, { 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46 } };
53 LPOLESTR pProgId
= nullptr;
54 if (ProgIDFromCLSID(clsidPaint
, &pProgId
) == REGDB_E_CLASSNOTREG
)
56 CoTaskMemFree(pProgId
);
64 class OdtExportThread
: public osl::Thread
66 uno::Reference
<lang::XComponent
> mxComponent
;
70 OdtExportThread(const uno::Reference
<lang::XComponent
>& xComponent
, const OUString
& rURL
);
71 virtual void SAL_CALL
run() override
;
74 OdtExportThread::OdtExportThread(const uno::Reference
<lang::XComponent
>& xComponent
,
76 : mxComponent(xComponent
)
81 void OdtExportThread::run()
83 uno::Reference
<frame::XStorable
> xStorable(mxComponent
, uno::UNO_QUERY
);
84 uno::Sequence
<beans::PropertyValue
> aStoreProperties
= {
85 comphelper::makePropertyValue("FilterName", OUString("writer8")),
87 xStorable
->storeToURL(maURL
, aStoreProperties
);
91 CPPUNIT_TEST_FIXTURE(Test
, testSaveOnThread
)
93 // Given an embedded object which hosts mspaint data:
94 if (Application::GetDefaultDevice()->GetDPIX() != 96)
99 if (IsPaintClassNotRegistered())
102 DBG_TESTSOLARMUTEX();
103 OUString aURL
= createFileURL(u
"reqif-ole2.xhtml");
104 uno::Sequence
<beans::PropertyValue
> aLoadProperties
= {
105 comphelper::makePropertyValue("FilterName", OUString("HTML (StarWriter)")),
106 comphelper::makePropertyValue("FilterOptions", OUString("xhtmlns=reqif-xhtml")),
108 loadWithParams(aURL
, aLoadProperties
);
110 // When saving that document on a thread:
111 OdtExportThread
aThread(mxComponent
, maTempFile
.GetURL());
114 SolarMutexReleaser r
;
115 while (aThread
.isRunning())
118 Application::Reschedule(/*bHandleAllCurrentEvents=*/true);
122 // Then make sure its visible area's width is correct.
123 xmlDocUniquePtr pXmlDoc
= parseExport("content.xml");
124 // 16 pixels, assuming 96 DPI.
125 // Without the accompanying fix in place, this test would have failed with:
126 // - Expected: 0.1665in
127 // - Actual : 1.9685in
128 // i.e. we wrote a hardcoded 5cm width, not the real one.
129 assertXPath(pXmlDoc
, "//style:graphic-properties", "visible-area-width", u
"0.1665in");
132 CPPUNIT_PLUGIN_IMPLEMENT();
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */