1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <unotest/filters-test.hxx>
#include <test/bootstrapfixture.hxx>
#include <LibreOfficeKit/LibreOfficeKitEnums.h>
#include <vcl/scheduler.hxx>
#include <vcl/keycodes.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/propertyvalue.hxx>
#include <test/xmltesttools.hxx>
#include <defaultsoptions.hxx>
#include <scmod.hxx>
#include <viewdata.hxx>
#include <tabvwsh.hxx>
#include <com/sun/star/frame/Desktop.hpp>
#include "helper/qahelper.hxx"
#include "helper/xpath.hxx"
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
/* Tests for sheets larger than 1024 columns and/or 1048576 rows. */
class ScJumboSheetsTest : public test::FiltersTest, public ScBootstrapFixture, public XmlTestTools
{
public:
ScJumboSheetsTest();
virtual bool load(const OUString& rFilter, const OUString& rURL, const OUString& rUserData,
SfxFilterFlags nFilterFlags, SotClipboardFormatId nClipboardID,
unsigned int nFilterVersion) override;
virtual void setUp() override;
virtual void tearDown() override;
void testRoundtripColumn2000Ods();
void testRoundtripColumn2000Xlsx();
void testRoundtripColumnRange();
void testTdf134392();
void testTdf133033();
void testTdf109061();
CPPUNIT_TEST_SUITE(ScJumboSheetsTest);
CPPUNIT_TEST(testRoundtripColumn2000Ods);
CPPUNIT_TEST(testRoundtripColumn2000Xlsx);
CPPUNIT_TEST(testRoundtripColumnRange);
CPPUNIT_TEST(testTdf134392);
CPPUNIT_TEST(testTdf133033);
CPPUNIT_TEST(testTdf109061);
CPPUNIT_TEST_SUITE_END();
protected:
virtual void registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx) override;
private:
void testRoundtripColumn2000(std::u16string_view name, int format);
uno::Reference<uno::XInterface> m_xCalcComponent;
};
bool ScJumboSheetsTest::load(const OUString& rFilter, const OUString& rURL,
const OUString& rUserData, SfxFilterFlags nFilterFlags,
SotClipboardFormatId nClipboardID, unsigned int nFilterVersion)
{
ScDocShellRef xDocShRef = ScBootstrapFixture::load(rURL, rFilter, rUserData, OUString(),
nFilterFlags, nClipboardID, nFilterVersion);
bool bLoaded = xDocShRef.is();
//reference counting of ScDocShellRef is very confused.
if (bLoaded)
xDocShRef->DoClose();
return bLoaded;
}
void ScJumboSheetsTest::testRoundtripColumn2000Ods()
{
testRoundtripColumn2000(u"value-in-column-2000.", FORMAT_ODS);
}
void ScJumboSheetsTest::testRoundtripColumn2000Xlsx()
{
testRoundtripColumn2000(u"value-in-column-2000.", FORMAT_XLSX);
}
void ScJumboSheetsTest::testRoundtripColumn2000(std::u16string_view name, int format)
{
ScDocShellRef xDocSh1 = loadDoc(name, format);
CPPUNIT_ASSERT(xDocSh1.is());
{
ScDocument& rDoc = xDocSh1->GetDocument();
// Check the value at BXX1 (2000th column).
CPPUNIT_ASSERT_EQUAL(-5.0, rDoc.GetValue(1999, 0, 0));
// Check the formula referencing the value.
CPPUNIT_ASSERT_EQUAL(OUString("=BXX1"), rDoc.GetFormula(0, 0, 0));
// Recalc and check value in the reference.
rDoc.CalcAll();
CPPUNIT_ASSERT_EQUAL(-5.0, rDoc.GetValue(0, 0, 0));
}
ScDocShellRef xDocSh2 = saveAndReload(*xDocSh1, format);
CPPUNIT_ASSERT(xDocSh2.is());
{
// Check again.
ScDocument& rDoc = xDocSh2->GetDocument();
CPPUNIT_ASSERT_EQUAL(-5.0, rDoc.GetValue(1999, 0, 0));
CPPUNIT_ASSERT_EQUAL(OUString("=BXX1"), rDoc.GetFormula(0, 0, 0));
rDoc.CalcAll();
CPPUNIT_ASSERT_EQUAL(-5.0, rDoc.GetValue(0, 0, 0));
}
xDocSh1->DoClose();
xDocSh2->DoClose();
}
void ScJumboSheetsTest::testRoundtripColumnRange()
{
ScDocShellRef xDocSh1 = loadDoc(u"sum-whole-column-row.", FORMAT_ODS);
CPPUNIT_ASSERT(xDocSh1.is());
{
ScDocument& rDoc = xDocSh1->GetDocument();
// Check the formula referencing the whole-row range.
CPPUNIT_ASSERT_EQUAL(OUString("=SUM(2:2)"), rDoc.GetFormula(0, 0, 0));
// Check the formula referencing the whole-column range.
CPPUNIT_ASSERT_EQUAL(OUString("=SUM(C:C)"), rDoc.GetFormula(1, 0, 0));
}
std::shared_ptr<utl::TempFile> exportedFile;
ScDocShellRef xDocSh2 = saveAndReloadNoClose(*xDocSh1, FORMAT_ODS, &exportedFile);
CPPUNIT_ASSERT(xDocSh2.is());
{
ScDocument& rDoc = xDocSh2->GetDocument();
CPPUNIT_ASSERT_EQUAL(OUString("=SUM(2:2)"), rDoc.GetFormula(0, 0, 0));
CPPUNIT_ASSERT_EQUAL(OUString("=SUM(C:C)"), rDoc.GetFormula(1, 0, 0));
xmlDocUniquePtr pDoc = XPathHelper::parseExport(exportedFile, m_xSFactory, "content.xml");
CPPUNIT_ASSERT(pDoc);
assertXPath(pDoc,
"/office:document-content/office:body/office:spreadsheet/table:table/"
"table:table-row[1]/table:table-cell[1]",
"formula", "of:=SUM([.2:.2])");
assertXPath(pDoc,
"/office:document-content/office:body/office:spreadsheet/table:table/"
"table:table-row[1]/table:table-cell[2]",
"formula", "of:=SUM([.C:.C])");
}
ScDocShellRef xDocSh3 = saveAndReloadNoClose(*xDocSh1, FORMAT_XLSX, &exportedFile);
CPPUNIT_ASSERT(xDocSh3.is());
{
ScDocument& rDoc = xDocSh3->GetDocument();
CPPUNIT_ASSERT_EQUAL(OUString("=SUM(2:2)"), rDoc.GetFormula(0, 0, 0));
CPPUNIT_ASSERT_EQUAL(OUString("=SUM(C:C)"), rDoc.GetFormula(1, 0, 0));
xmlDocUniquePtr pDoc
= XPathHelper::parseExport(exportedFile, m_xSFactory, "xl/worksheets/sheet1.xml");
CPPUNIT_ASSERT(pDoc);
assertXPathContent(pDoc, "/x:worksheet/x:sheetData/x:row[1]/x:c[1]/x:f", "SUM(2:2)");
assertXPathContent(pDoc, "/x:worksheet/x:sheetData/x:row[1]/x:c[2]/x:f", "SUM(C:C)");
}
xDocSh1->DoClose();
xDocSh2->DoClose();
xDocSh3->DoClose();
}
void ScJumboSheetsTest::testTdf134392()
{
// Without the fix in place, the file would have crashed
ScDocShellRef xDocSh = loadDoc(u"tdf134392.", FORMAT_XLSX);
CPPUNIT_ASSERT(xDocSh.is());
ScDocument& rDoc = xDocSh->GetDocument();
rDoc.CalcAll(); // perform hard re-calculation.
xDocSh->DoClose();
}
void ScJumboSheetsTest::testTdf133033()
{
// Create an empty document
uno::Reference<frame::XDesktop2> xDesktop
= frame::Desktop::create(::comphelper::getProcessComponentContext());
CPPUNIT_ASSERT(xDesktop.is());
Sequence<beans::PropertyValue> args{ comphelper::makePropertyValue("Hidden", true) };
m_xCalcComponent = xDesktop->loadComponentFromURL("private:factory/scalc", "_blank", 0, args);
CPPUNIT_ASSERT(m_xCalcComponent.is());
// Get the document model
SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(m_xCalcComponent);
CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
ScDocShellRef xDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
CPPUNIT_ASSERT(xDocSh);
ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false);
CPPUNIT_ASSERT(pViewShell);
ScModelObj* pModelObj = dynamic_cast<ScModelObj*>(m_xCalcComponent.get());
CPPUNIT_ASSERT(pModelObj);
pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN | KEY_MOD1);
Scheduler::ProcessEventsToIdle();
ScViewData& rViewData = pViewShell->GetViewData();
CPPUNIT_ASSERT_EQUAL(sal_Int16(0), rViewData.GetCurX());
CPPUNIT_ASSERT_EQUAL(sal_Int32(16777215), rViewData.GetCurY());
}
void ScJumboSheetsTest::testTdf109061()
{
// Without the fix in place, the file would have crashed
ScDocShellRef xDocSh = loadDoc(u"tdf109061.", FORMAT_XLSX);
CPPUNIT_ASSERT(xDocSh.is());
ScDocument& rDoc = xDocSh->GetDocument();
rDoc.CalcAll(); // perform hard re-calculation.
CPPUNIT_ASSERT_EQUAL(6.0, rDoc.GetValue(1, 3, 0));
xDocSh->DoClose();
}
ScJumboSheetsTest::ScJumboSheetsTest()
: ScBootstrapFixture("sc/qa/unit/data")
{
}
void ScJumboSheetsTest::setUp()
{
test::BootstrapFixture::setUp();
// This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
// which is a private symbol to us, gets called
m_xCalcComponent
= getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument");
CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is());
ScDefaultsOptions aDefaultsOption = SC_MOD()->GetDefaultsOptions();
aDefaultsOption.SetInitJumboSheets(true);
SC_MOD()->SetDefaultsOptions(aDefaultsOption);
}
void ScJumboSheetsTest::tearDown()
{
uno::Reference<lang::XComponent>(m_xCalcComponent, UNO_QUERY_THROW)->dispose();
test::BootstrapFixture::tearDown();
ScDefaultsOptions aDefaultsOption = SC_MOD()->GetDefaultsOptions();
aDefaultsOption.SetInitJumboSheets(false);
SC_MOD()->SetDefaultsOptions(aDefaultsOption);
}
void ScJumboSheetsTest::registerNamespaces(xmlXPathContextPtr& pXmlXPathCtx)
{
XmlTestTools::registerOOXMLNamespaces(pXmlXPathCtx);
XmlTestTools::registerODFNamespaces(pXmlXPathCtx);
}
CPPUNIT_TEST_SUITE_REGISTRATION(ScJumboSheetsTest);
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|