| 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/unoapi_test.hxx> |
| 11 |
|
| 12 |
#include <com/sun/star/frame/Desktop.hpp> |
| 13 |
#include <com/sun/star/frame/XFrame.hpp> |
| 14 |
|
| 15 |
#include <comphelper/processfactory.hxx> |
| 16 |
#include <vcl/scheduler.hxx> |
| 17 |
#include <vcl/svapp.hxx> |
| 18 |
|
| 19 |
using namespace ::com::sun::star; |
| 20 |
|
| 21 |
namespace |
| 22 |
{ |
| 23 |
/// Covers framework/source/loadenv/ fixes. |
| 24 |
class Test : public UnoApiTest |
| 25 |
{ |
| 26 |
public: |
| 27 |
Test() |
| 28 |
: UnoApiTest(u"/framework/qa/cppunit/data/"_ustr) |
| 29 |
{ |
| 30 |
} |
| 31 |
}; |
| 32 |
|
| 33 |
class DocumentOpener |
| 34 |
{ |
| 35 |
public: |
| 36 |
DECL_STATIC_LINK(DocumentOpener, OpenDocument, void*, void); |
| 37 |
}; |
| 38 |
|
| 39 |
IMPL_STATIC_LINK(DocumentOpener, OpenDocument, void*, pArg, void) |
| 40 |
{ |
| 41 |
CPPUNIT_ASSERT(pArg); |
| 42 |
auto pURL = static_cast<OUString*>(pArg); |
| 43 |
uno::Reference<uno::XComponentContext> xComponentContext |
| 44 |
= comphelper::getProcessComponentContext(); |
| 45 |
uno::Reference<frame::XDesktop2> xDesktop = frame::Desktop::create(xComponentContext); |
| 46 |
xDesktop->loadComponentFromURL(*pURL, u"_default"_ustr, 0, {}); |
| 47 |
delete pURL; |
| 48 |
} |
| 49 |
|
| 50 |
CPPUNIT_TEST_FIXTURE(Test, testDoubleLoading) |
| 51 |
{ |
| 52 |
// Try to load the same document twice. This is similar to trying to execute the soffice process |
| 53 |
// twice: in that case the 2nd instance forwards to the 1st instance and then uses the same code |
| 54 |
// path. |
| 55 |
for (int i = 0; i < 2; ++i) |
| 56 |
{ |
| 57 |
auto pURL = std::make_unique<OUString>(createFileURL(u"double-loading.odt")); |
| 58 |
Application::PostUserEvent(LINK(nullptr, DocumentOpener, OpenDocument), pURL.release()); |
| 59 |
} |
| 60 |
Scheduler::ProcessEventsToIdle(); |
| 61 |
|
| 62 |
// Verify that the 2nd load didn't happen, since it's the same document. |
| 63 |
uno::Reference<frame::XFrames> xFrames = mxDesktop->getFrames(); |
| 64 |
// Without the accompanying fix in place, this failed with: |
| 65 |
// - Expected: 1 |
| 66 |
// - Actual : 2 |
| 67 |
// i.e. the document was loaded twice, into two separate frames/windows. |
| 68 |
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(1), xFrames->getCount()); |
| 69 |
|
| 70 |
// Close the document, now that we know we have a single one. |
| 71 |
uno::Reference<frame::XFrame> xFrame(xFrames->getByIndex(0), uno::UNO_QUERY); |
| 72 |
xFrame->getController()->getModel()->dispose(); |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
CPPUNIT_PLUGIN_IMPLEMENT(); |
| 77 |
|
| 78 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |