| 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 <test/unoapixml_test.hxx> |
| 11 |
|
| 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> |
| 16 |
|
| 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> |
| 28 |
|
| 29 |
#ifdef _WIN32 |
| 30 |
#include <systools/win32/comtools.hxx> |
| 31 |
#endif |
| 32 |
|
| 33 |
using namespace ::com::sun::star; |
| 34 |
|
| 35 |
namespace |
| 36 |
{ |
| 37 |
/// Covers embeddedobj/source/msole/ fixes. |
| 38 |
class Test : public UnoApiXmlTest |
| 39 |
{ |
| 40 |
public: |
| 41 |
Test() |
| 42 |
: UnoApiXmlTest("/embeddedobj/qa/cppunit/data/") |
| 43 |
{ |
| 44 |
} |
| 45 |
}; |
| 46 |
|
| 47 |
bool IsPaintClassNotRegistered() |
| 48 |
{ |
| 49 |
#ifdef _WIN32 |
| 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) |
| 55 |
return true; |
| 56 |
CoTaskMemFree(pProgId); |
| 57 |
#endif |
| 58 |
return false; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
namespace |
| 63 |
{ |
| 64 |
class OdtExportThread : public osl::Thread |
| 65 |
{ |
| 66 |
uno::Reference<lang::XComponent> mxComponent; |
| 67 |
OUString maURL; |
| 68 |
|
| 69 |
public: |
| 70 |
OdtExportThread(const uno::Reference<lang::XComponent>& xComponent, const OUString& rURL); |
| 71 |
virtual void SAL_CALL run() override; |
| 72 |
}; |
| 73 |
|
| 74 |
OdtExportThread::OdtExportThread(const uno::Reference<lang::XComponent>& xComponent, |
| 75 |
const OUString& rURL) |
| 76 |
: mxComponent(xComponent) |
| 77 |
, maURL(rURL) |
| 78 |
{ |
| 79 |
} |
| 80 |
|
| 81 |
void OdtExportThread::run() |
| 82 |
{ |
| 83 |
uno::Reference<frame::XStorable> xStorable(mxComponent, uno::UNO_QUERY); |
| 84 |
uno::Sequence<beans::PropertyValue> aStoreProperties = { |
| 85 |
comphelper::makePropertyValue("FilterName", OUString("writer8")), |
| 86 |
}; |
| 87 |
xStorable->storeToURL(maURL, aStoreProperties); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
CPPUNIT_TEST_FIXTURE(Test, testSaveOnThread) |
| 92 |
{ |
| 93 |
// Given an embedded object which hosts mspaint data: |
| 94 |
if (Application::GetDefaultDevice()->GetDPIX() != 96) |
| 95 |
{ |
| 96 |
return; |
| 97 |
} |
| 98 |
|
| 99 |
if (IsPaintClassNotRegistered()) |
| 100 |
return; |
| 101 |
|
| 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")), |
| 107 |
}; |
| 108 |
loadWithParams(aURL, aLoadProperties); |
| 109 |
|
| 110 |
// When saving that document on a thread: |
| 111 |
OdtExportThread aThread(mxComponent, maTempFile.GetURL()); |
| 112 |
aThread.create(); |
| 113 |
{ |
| 114 |
SolarMutexReleaser r; |
| 115 |
while (aThread.isRunning()) |
| 116 |
{ |
| 117 |
SolarMutexGuard g; |
| 118 |
Application::Reschedule(/*bHandleAllCurrentEvents=*/true); |
| 119 |
} |
| 120 |
} |
| 121 |
|
| 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"); |
| 130 |
} |
| 131 |
|
| 132 |
CPPUNIT_PLUGIN_IMPLEMENT(); |
| 133 |
|
| 134 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |