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 <sal/config.h>
11 #include <unotest/filters-test.hxx>
12 #include <test/bootstrapfixture.hxx>
13 #include <LibreOfficeKit/LibreOfficeKitEnums.h>
14 #include <vcl/scheduler.hxx>
15 #include <vcl/keycodes.hxx>
16 #include <comphelper/processfactory.hxx>
17 #include <comphelper/propertyvalue.hxx>
19 #include <defaultsoptions.hxx>
21 #include <viewdata.hxx>
22 #include <tabvwsh.hxx>
23 #include <com/sun/star/frame/Desktop.hpp>
25 #include "helper/qahelper.hxx"
27 using namespace ::com::sun::star
;
28 using namespace ::com::sun::star::uno
;
30 /* Implementation of Filters test */
32 class ScFiltersTest
: public test::FiltersTest
, public ScBootstrapFixture
37 virtual bool load(const OUString
& rFilter
, const OUString
& rURL
, const OUString
& rUserData
,
38 SfxFilterFlags nFilterFlags
, SotClipboardFormatId nClipboardID
,
39 unsigned int nFilterVersion
) override
;
41 virtual void setUp() override
;
42 virtual void tearDown() override
;
47 CPPUNIT_TEST_SUITE(ScFiltersTest
);
49 CPPUNIT_TEST(testTdf134392
);
50 CPPUNIT_TEST(testTdf133033
);
52 CPPUNIT_TEST_SUITE_END();
55 uno::Reference
<uno::XInterface
> m_xCalcComponent
;
58 bool ScFiltersTest::load(const OUString
& rFilter
, const OUString
& rURL
, const OUString
& rUserData
,
59 SfxFilterFlags nFilterFlags
, SotClipboardFormatId nClipboardID
,
60 unsigned int nFilterVersion
)
62 ScDocShellRef xDocShRef
= ScBootstrapFixture::load(rURL
, rFilter
, rUserData
, OUString(),
63 nFilterFlags
, nClipboardID
, nFilterVersion
);
64 bool bLoaded
= xDocShRef
.is();
65 //reference counting of ScDocShellRef is very confused.
71 void ScFiltersTest::testTdf134392()
73 // Without the fix in place, the file would have crashed
74 ScDocShellRef xDocSh
= loadDoc(u
"tdf134392.", FORMAT_XLSX
);
75 CPPUNIT_ASSERT(xDocSh
.is());
77 ScDocument
& rDoc
= xDocSh
->GetDocument();
78 rDoc
.CalcAll(); // perform hard re-calculation.
82 void ScFiltersTest::testTdf133033()
84 // Create an empty document
85 uno::Reference
<frame::XDesktop2
> xDesktop
86 = frame::Desktop::create(::comphelper::getProcessComponentContext());
87 CPPUNIT_ASSERT(xDesktop
.is());
89 Sequence
<beans::PropertyValue
> args
{ comphelper::makePropertyValue("Hidden", true) };
91 m_xCalcComponent
= xDesktop
->loadComponentFromURL("private:factory/scalc", "_blank", 0, args
);
92 CPPUNIT_ASSERT(m_xCalcComponent
.is());
94 // Get the document model
95 SfxObjectShell
* pFoundShell
= SfxObjectShell::GetShellFromComponent(m_xCalcComponent
);
96 CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell
);
98 ScDocShellRef xDocSh
= dynamic_cast<ScDocShell
*>(pFoundShell
);
99 CPPUNIT_ASSERT(xDocSh
);
101 ScTabViewShell
* pViewShell
= xDocSh
->GetBestViewShell(false);
102 CPPUNIT_ASSERT(pViewShell
);
104 ScModelObj
* pModelObj
= dynamic_cast<ScModelObj
*>(m_xCalcComponent
.get());
105 CPPUNIT_ASSERT(pModelObj
);
107 pModelObj
->postKeyEvent(LOK_KEYEVENT_KEYINPUT
, 0, KEY_DOWN
| KEY_MOD1
);
108 Scheduler::ProcessEventsToIdle();
110 ScViewData
& rViewData
= pViewShell
->GetViewData();
112 CPPUNIT_ASSERT_EQUAL(sal_Int16(0), rViewData
.GetCurX());
113 CPPUNIT_ASSERT_EQUAL(sal_Int32(15999999), rViewData
.GetCurY());
116 ScFiltersTest::ScFiltersTest()
117 : ScBootstrapFixture("sc/qa/unit/data")
121 void ScFiltersTest::setUp()
123 test::BootstrapFixture::setUp();
125 // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
126 // which is a private symbol to us, gets called
128 = getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument");
129 CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent
.is());
131 ScDefaultsOptions aDefaultsOption
= SC_MOD()->GetDefaultsOptions();
132 aDefaultsOption
.SetInitJumboSheets(true);
133 SC_MOD()->SetDefaultsOptions(aDefaultsOption
);
136 void ScFiltersTest::tearDown()
138 uno::Reference
<lang::XComponent
>(m_xCalcComponent
, UNO_QUERY_THROW
)->dispose();
139 test::BootstrapFixture::tearDown();
141 ScDefaultsOptions aDefaultsOption
= SC_MOD()->GetDefaultsOptions();
142 aDefaultsOption
.SetInitJumboSheets(false);
143 SC_MOD()->SetDefaultsOptions(aDefaultsOption
);
146 CPPUNIT_TEST_SUITE_REGISTRATION(ScFiltersTest
);
148 CPPUNIT_PLUGIN_IMPLEMENT();
150 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */