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 <validat.hxx>
11 #include <tabvwsh.hxx>
12 #include <com/sun/star/frame/Desktop.hpp>
13 #include "helper/qahelper.hxx"
14 #include <comphelper/processfactory.hxx>
16 using namespace ::com::sun::star
;
17 using namespace ::com::sun::star::uno
;
19 class ScFiltersTest
: public ScBootstrapFixture
25 virtual void setUp() override
;
26 virtual void tearDown() override
;
33 // void testTdf40110();
36 void testTdf88821_2();
38 void testRhbz1390776();
43 CPPUNIT_TEST_SUITE(ScFiltersTest
);
44 CPPUNIT_TEST(testTdf64229
);
45 CPPUNIT_TEST(testTdf36933
);
46 CPPUNIT_TEST(testTdf43700
);
47 CPPUNIT_TEST(testTdf43534
);
48 CPPUNIT_TEST(testTdf91979
);
49 // CPPUNIT_TEST(testTdf40110);
50 CPPUNIT_TEST(testTdf98657
);
51 CPPUNIT_TEST(testTdf88821
);
52 CPPUNIT_TEST(testTdf88821_2
);
53 CPPUNIT_TEST(testTdf103960
);
54 CPPUNIT_TEST(testRhbz1390776
);
55 CPPUNIT_TEST(testTdf104310
);
56 CPPUNIT_TEST(testTdf31231
);
57 CPPUNIT_TEST(testTdf128951
);
58 CPPUNIT_TEST_SUITE_END();
60 uno::Reference
<uno::XInterface
> m_xCalcComponent
;
63 void ScFiltersTest::testTdf64229()
65 ScDocShellRef xDocSh
= loadDoc("fdo64229b.", FORMAT_ODS
);
67 xDocSh
->DoHardRecalc();
69 CPPUNIT_ASSERT_MESSAGE("Failed to load fdo64229b.*", xDocSh
.is());
70 ScDocument
& rDoc
= xDocSh
->GetDocument();
71 OUString aCSVFileName
;
73 //test hard recalc: document has an incorrect cached formula result
74 //hard recalc should have updated to the correct result
75 createCSVPath("fdo64229b.", aCSVFileName
);
76 testFile(aCSVFileName
, rDoc
, 0);
81 void ScFiltersTest::testTdf36933()
83 ScDocShellRef xDocSh
= loadDoc("fdo36933test.", FORMAT_ODS
);
85 xDocSh
->DoHardRecalc();
87 CPPUNIT_ASSERT_MESSAGE("Failed to load fdo36933test.*", xDocSh
.is());
88 ScDocument
& rDoc
= xDocSh
->GetDocument();
89 OUString aCSVFileName
;
91 //test hard recalc: document has an incorrect cached formula result
92 //hard recalc should have updated to the correct result
93 createCSVPath("fdo36933test.", aCSVFileName
);
94 testFile(aCSVFileName
, rDoc
, 0);
99 void ScFiltersTest::testTdf43700()
101 ScDocShellRef xDocSh
= loadDoc("fdo43700test.", FORMAT_ODS
);
103 xDocSh
->DoHardRecalc();
105 CPPUNIT_ASSERT_MESSAGE("Failed to load fdo43700test.*", xDocSh
.is());
106 ScDocument
& rDoc
= xDocSh
->GetDocument();
107 OUString aCSVFileName
;
109 //test hard recalc: document has an incorrect cached formula result
110 //hard recalc should have updated to the correct result
111 createCSVPath("fdo43700test.", aCSVFileName
);
112 testFile(aCSVFileName
, rDoc
, 0);
117 void ScFiltersTest::testTdf43534()
119 ScDocShellRef xDocSh
= loadDoc("fdo43534test.", FORMAT_ODS
);
121 xDocSh
->DoHardRecalc();
123 CPPUNIT_ASSERT_MESSAGE("Failed to load fdo43534test.*", xDocSh
.is());
124 // ScDocument& rDoc = xDocSh->GetDocument();
125 OUString aCSVFileName
;
127 //test hard recalc: document has an incorrect cached formula result
128 //hard recalc should have updated to the correct result
129 createCSVPath("fdo43534test.", aCSVFileName
);
130 // testFile(aCSVFileName, rDoc, 0);
135 void ScFiltersTest::testTdf91979()
137 uno::Reference
< frame::XDesktop2
> xDesktop
= frame::Desktop::create(::comphelper::getProcessComponentContext());
138 CPPUNIT_ASSERT(xDesktop
.is());
140 Sequence
< beans::PropertyValue
> args(1);
141 args
[0].Name
= "Hidden";
142 args
[0].Value
<<= true;
144 uno::Reference
< lang::XComponent
> xComponent
= xDesktop
->loadComponentFromURL(
145 "private:factory/scalc",
149 CPPUNIT_ASSERT(xComponent
.is());
151 // Get the document model
152 SfxObjectShell
* pFoundShell
= SfxObjectShell::GetShellFromComponent(xComponent
);
153 CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell
);
155 ScDocShellRef xDocSh
= dynamic_cast<ScDocShell
*>(pFoundShell
);
156 CPPUNIT_ASSERT(xDocSh
.get() != nullptr);
158 // Get the document controller
159 ScTabViewShell
* pViewShell
= xDocSh
->GetBestViewShell(false);
160 CPPUNIT_ASSERT(pViewShell
!= nullptr);
161 auto& aViewData
= pViewShell
->GetViewData();
162 auto* pDoc
= aViewData
.GetDocument();
164 // Check coordinates of a distant cell
165 Point aPos
= aViewData
.GetScrPos(MAXCOL
- 1, 10000, SC_SPLIT_TOPLEFT
, true);
166 int nColWidth
= ScViewData::ToPixel(pDoc
->GetColWidth(0, 0), aViewData
.GetPPTX());
167 int nRowHeight
= ScViewData::ToPixel(pDoc
->GetRowHeight(0, 0), aViewData
.GetPPTY());
168 CPPUNIT_ASSERT_EQUAL(static_cast<long>((MAXCOL
- 1) * nColWidth
), aPos
.getX());
169 CPPUNIT_ASSERT_EQUAL(static_cast<long>(10000 * nRowHeight
), aPos
.getY());
171 xComponent
->dispose();
175 void ScFiltersTest::testTdf40110()
177 ScDocShellRef xDocSh = loadDoc("fdo40110test.", FORMAT_ODS);
179 CPPUNIT_ASSERT_MESSAGE("Failed to load fdo40110test.*", xDocSh.Is());
180 xDocSh->DoHardRecalc();
182 ScDocument& rDoc = xDocSh->GetDocument();
183 OUString aCSVFileName;
185 //test hard recalc: document has an incorrect cached formula result
186 //hard recalc should have updated to the correct result
187 createCSVPath(OUString("fdo40110test."), aCSVFileName);
188 testFile(aCSVFileName, rDoc, 0);
194 void ScFiltersTest::testTdf98657()
196 ScDocShellRef xDocSh
= loadDoc("tdf98657.", FORMAT_ODS
);
197 ScDocument
& rDoc
= xDocSh
->GetDocument();
199 xDocSh
->DoHardRecalc();
201 // this was a NaN before the fix
202 CPPUNIT_ASSERT_EQUAL(285.0, rDoc
.GetValue(ScAddress(1, 1, 0)));
207 void ScFiltersTest::testTdf88821()
209 ScDocShellRef xDocSh
= loadDoc("tdf88821.", FORMAT_HTML
);
210 ScDocument
& rDoc
= xDocSh
->GetDocument();
212 // B2 should be 'Périmètre', not 'Périmètre'
213 CPPUNIT_ASSERT_EQUAL(OStringToOUString("P\xC3\xA9rim\xC3\xA8tre", RTL_TEXTENCODING_UTF8
), rDoc
.GetString(1, 1, 0));
218 void ScFiltersTest::testTdf88821_2()
220 ScDocShellRef xDocSh
= loadDoc("tdf88821-2.", FORMAT_HTML
);
221 ScDocument
& rDoc
= xDocSh
->GetDocument();
223 // A2 should be 'ABCabcČŠŽčšž', not 'ABCabcČŠŽÄヘšž'
224 CPPUNIT_ASSERT_EQUAL(OStringToOUString("ABCabc\xC4\x8C\xC5\xA0\xC5\xBD\xC4\x8D\xC5\xA1\xC5\xBE", RTL_TEXTENCODING_UTF8
), rDoc
.GetString(0, 1, 0));
229 void ScFiltersTest::testTdf103960()
231 ScDocShellRef xDocSh
= loadDoc("tdf103960.", FORMAT_HTML
);
232 ScDocument
& rDoc
= xDocSh
->GetDocument();
234 // A1 should be 'Data', not the entire content of the file
235 CPPUNIT_ASSERT_EQUAL(OStringToOUString("Data", RTL_TEXTENCODING_UTF8
), rDoc
.GetString(0, 0, 0));
240 void ScFiltersTest::testRhbz1390776()
242 ScDocShellRef xDocSh
= loadDoc("rhbz1390776.", FORMAT_XLS_XML
);
243 ScDocument
& rDoc
= xDocSh
->GetDocument();
245 ASSERT_FORMULA_EQUAL(rDoc
, ScAddress(0, 27, 0), "SUM(A18:A23)", "Wrong range");
250 void ScFiltersTest::testTdf104310()
252 // 1. Test x14 extension
254 ScDocShellRef xDocSh
= loadDoc("tdf104310.", FORMAT_XLSX
);
255 ScDocument
& rDoc
= xDocSh
->GetDocument();
257 const ScValidationData
* pData
= rDoc
.GetValidationEntry(1);
258 CPPUNIT_ASSERT(pData
);
260 // Make sure the list is correct.
261 std::vector
<ScTypedStrData
> aList
;
262 pData
->FillSelectionList(aList
, ScAddress(0, 1, 0));
263 CPPUNIT_ASSERT_EQUAL(size_t(5), aList
.size());
264 for (size_t i
= 0; i
< 5; ++i
)
265 CPPUNIT_ASSERT_DOUBLES_EQUAL(double(i
+ 1), aList
[i
].GetValue(), 1e-8);
270 // 2. Test x12ac extension
272 ScDocShellRef xDocSh
= loadDoc("tdf104310-2.", FORMAT_XLSX
);
273 ScDocument
& rDoc
= xDocSh
->GetDocument();
275 const ScValidationData
* pData
= rDoc
.GetValidationEntry(1);
276 CPPUNIT_ASSERT(pData
);
278 // Make sure the list is correct.
279 std::vector
<ScTypedStrData
> aList
;
280 pData
->FillSelectionList(aList
, ScAddress(0, 1, 0));
281 CPPUNIT_ASSERT_EQUAL(size_t(3), aList
.size());
282 CPPUNIT_ASSERT_EQUAL(OUString("1"), aList
[0].GetString());
283 CPPUNIT_ASSERT_EQUAL(OUString("2,3"), aList
[1].GetString());
284 CPPUNIT_ASSERT_EQUAL(OUString("4"), aList
[2].GetString());
290 void ScFiltersTest::testTdf31231()
292 // We must open it read-write to allow setting modified flag
293 ScDocShellRef xDocSh
= loadDoc("tdf31231.", FORMAT_ODS
, true);
294 xDocSh
->DoHardRecalc();
296 CPPUNIT_ASSERT_MESSAGE("The spreadsheet must be allowed to set modified state", xDocSh
->IsEnableSetModified());
297 CPPUNIT_ASSERT_MESSAGE("The spreadsheet must not be modified on open", !xDocSh
->IsModified());
302 void ScFiltersTest::testTdf128951()
304 css::uno::Reference
<css::frame::XDesktop2
> xDesktop
305 = css::frame::Desktop::create(::comphelper::getProcessComponentContext());
306 CPPUNIT_ASSERT(xDesktop
.is());
308 // 1. Create spreadsheet
309 css::uno::Sequence
<css::beans::PropertyValue
> aHiddenArgList(1);
310 aHiddenArgList
[0].Name
= "Hidden";
311 aHiddenArgList
[0].Value
<<= true;
313 css::uno::Reference
<css::lang::XComponent
> xComponent
314 = xDesktop
->loadComponentFromURL("private:factory/scalc", "_blank", 0, aHiddenArgList
);
315 CPPUNIT_ASSERT(xComponent
.is());
317 // 2. Create a new sheet instance
318 css::uno::Reference
<css::lang::XMultiServiceFactory
> xFac(xComponent
,
319 css::uno::UNO_QUERY_THROW
);
320 auto xSheet
= xFac
->createInstance("com.sun.star.sheet.Spreadsheet");
322 // 3. Insert sheet into the spreadsheet (was throwing IllegalArgumentException)
323 css::uno::Reference
<css::sheet::XSpreadsheetDocument
> xDoc(xComponent
,
324 css::uno::UNO_QUERY_THROW
);
325 CPPUNIT_ASSERT_NO_THROW(xDoc
->getSheets()->insertByName("mustNotThrow", css::uno::Any(xSheet
)));
328 ScFiltersTest::ScFiltersTest()
329 : ScBootstrapFixture( "sc/qa/unit/data" )
333 void ScFiltersTest::setUp()
335 test::BootstrapFixture::setUp();
337 // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
338 // which is a private symbol to us, gets called
340 getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument");
341 CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent
.is());
344 void ScFiltersTest::tearDown()
346 uno::Reference
< lang::XComponent
>( m_xCalcComponent
, UNO_QUERY_THROW
)->dispose();
347 test::BootstrapFixture::tearDown();
350 CPPUNIT_TEST_SUITE_REGISTRATION(ScFiltersTest
);
352 CPPUNIT_PLUGIN_IMPLEMENT();
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */