android: Update app-specific/MIME type icons
[LibreOffice.git] / framework / qa / cppunit / loadenv.cxx
blobc9aa2789d9ca9ea4515e6ad3f6e3572d2184724c
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/frame/Desktop.hpp>
13 #include <com/sun/star/frame/XFrame.hpp>
15 #include <comphelper/processfactory.hxx>
16 #include <vcl/scheduler.hxx>
17 #include <vcl/svapp.hxx>
19 using namespace ::com::sun::star;
21 namespace
23 /// Covers framework/source/loadenv/ fixes.
24 class Test : public UnoApiTest
26 public:
27 Test()
28 : UnoApiTest("/framework/qa/cppunit/data/")
33 class DocumentOpener
35 public:
36 DECL_STATIC_LINK(DocumentOpener, OpenDocument, void*, void);
39 IMPL_STATIC_LINK(DocumentOpener, OpenDocument, void*, pArg, void)
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, "_default", 0, {});
47 delete pURL;
50 CPPUNIT_TEST_FIXTURE(Test, testDoubleLoading)
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)
57 auto pURL = std::make_unique<OUString>(createFileURL(u"double-loading.odt"));
58 Application::PostUserEvent(LINK(nullptr, DocumentOpener, OpenDocument), pURL.release());
60 Scheduler::ProcessEventsToIdle();
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());
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();
76 CPPUNIT_PLUGIN_IMPLEMENT();
78 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */