Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * Version: MPL 1.1 / GPLv3+ / LGPLv3+
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License or as specified alternatively below. You may obtain a copy of
8 : * the License at http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * Major Contributor(s):
16 : * Copyright (C) 2010 Red Hat, Inc., Caolán McNamara <caolanm@redhat.com>
17 : * (initial developer)
18 : *
19 : * All Rights Reserved.
20 : *
21 : * For minor contributions see the git repository.
22 : *
23 : * Alternatively, the contents of this file may be used under the terms of
24 : * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
25 : * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
26 : * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
27 : * instead of those above.
28 : */
29 :
30 : #include <sal/config.h>
31 : #include <unotest/filters-test.hxx>
32 : #include <test/bootstrapfixture.hxx>
33 : #include <rtl/strbuf.hxx>
34 : #include <osl/file.hxx>
35 :
36 : #include <sfx2/app.hxx>
37 : #include <sfx2/docfilt.hxx>
38 : #include <sfx2/docfile.hxx>
39 : #include <sfx2/sfxmodelfactory.hxx>
40 : #include <svl/stritem.hxx>
41 : #include "svx/svdpage.hxx"
42 :
43 : #include <editeng/brshitem.hxx>
44 : #include <editeng/justifyitem.hxx>
45 : #include <editeng/borderline.hxx>
46 : #include <dbdata.hxx>
47 : #include "validat.hxx"
48 : #include "cell.hxx"
49 : #include "drwlayer.hxx"
50 : #include "userdat.hxx"
51 : #include "dpobject.hxx"
52 : #include "dpsave.hxx"
53 : #include "stlsheet.hxx"
54 :
55 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
56 : #include <com/sun/star/drawing/XControlShape.hpp>
57 : #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
58 : #include <com/sun/star/sheet/DataPilotFieldOrientation.hpp>
59 : #include <com/sun/star/sheet/GeneralFunction.hpp>
60 : #include <com/sun/star/container/XIndexAccess.hpp>
61 : #include <com/sun/star/frame/XModel.hpp>
62 :
63 : #define CALC_DEBUG_OUTPUT 0
64 : #define TEST_BUG_FILES 0
65 :
66 : #include "helper/qahelper.hxx"
67 :
68 : #define ODS_FORMAT_TYPE 50331943
69 : #define XLS_FORMAT_TYPE 318767171
70 : #define XLSX_FORMAT_TYPE 268959811
71 : #define CSV_FORMAT_TYPE (SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_USESOPTIONS)
72 : #define HTML_FORMAT_TYPE (SFX_FILTER_IMPORT | SFX_FILTER_EXPORT | SFX_FILTER_ALIEN | SFX_FILTER_USESOPTIONS)
73 :
74 : #define ODS 0
75 : #define XLS 1
76 : #define XLSX 2
77 : #define CSV 3
78 : #define HTML 4
79 :
80 : using namespace ::com::sun::star;
81 : using namespace ::com::sun::star::uno;
82 :
83 : namespace {
84 :
85 : struct FileFormat {
86 : const char* pName; const char* pFilterName; const char* pTypeName; unsigned int nFormatType;
87 : };
88 :
89 : FileFormat aFileFormats[] = {
90 : { "ods" , "calc8", "", ODS_FORMAT_TYPE },
91 : { "xls" , "MS Excel 97", "calc_MS_EXCEL_97", XLS_FORMAT_TYPE },
92 : { "xlsx", "Calc MS Excel 2007 XML" , "MS Excel 2007 XML", XLSX_FORMAT_TYPE },
93 : { "csv" , "Text - txt - csv (StarCalc)", "generic_Text", CSV_FORMAT_TYPE },
94 : { "html" , "calc_HTML_WebQuery", "generic_HTML", HTML_FORMAT_TYPE }
95 : };
96 :
97 : }
98 :
99 : /* Implementation of Filters test */
100 :
101 144 : class ScFiltersTest
102 : : public test::FiltersTest
103 : , public test::BootstrapFixture
104 : {
105 : public:
106 : ScFiltersTest();
107 :
108 : virtual bool load( const rtl::OUString &rFilter, const rtl::OUString &rURL,
109 : const rtl::OUString &rUserData, unsigned int nFilterFlags,
110 : unsigned int nClipboardID, unsigned int nFilterVersion);
111 :
112 : ScDocShellRef load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
113 : const rtl::OUString &rUserData, const rtl::OUString& rTypeName,
114 : unsigned int nFilterFlags, unsigned int nClipboardID, unsigned int nFilterVersion);
115 :
116 : void createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath);
117 : void createCSVPath(const rtl::OUString& aFileBase, rtl::OUString& rFilePath);
118 :
119 : virtual void setUp();
120 : virtual void tearDown();
121 :
122 : //ods, xls, xlsx filter tests
123 : void testRangeNameXLS();
124 : void testRangeNameXLSX();
125 : void testHardRecalcODS();
126 : void testFunctionsODS();
127 : void testCachedFormulaResultsODS();
128 : void testVolatileFunctionsODS();
129 : void testCachedMatrixFormulaResultsODS();
130 : void testDatabaseRangesODS();
131 : void testDatabaseRangesXLS();
132 : void testDatabaseRangesXLSX();
133 : void testFormatsODS();
134 : void testFormatsXLS();
135 : void testFormatsXLSX();
136 : void testMatrixODS();
137 : void testMatrixXLS();
138 : void testBorderODS();
139 : void testBorderXLS();
140 : void testBordersOoo33();
141 : void testBugFixesODS();
142 : void testBugFixesXLS();
143 : void testBugFixesXLSX();
144 : void testBrokenQuotesCSV();
145 : void testMergedCellsODS();
146 : void testRepeatedColumnsODS();
147 : void testDataValidityODS();
148 :
149 : void testColorScaleODS();
150 : void testColorScaleXLSX();
151 : void testDataBarODS();
152 : void testNewCondFormat();
153 :
154 : //change this test file only in excel and not in calc
155 : void testSharedFormulaXLSX();
156 : void testCellValueXLSX();
157 :
158 : //misc tests unrelated to the import filters
159 : void testPasswordNew();
160 : void testPasswordOld();
161 :
162 : //test shape import
163 : void testControlImport();
164 :
165 : void testNumberFormatHTML();
166 : void testNumberFormatCSV();
167 :
168 : void testCellAnchoredShapesODS();
169 :
170 : void testPivotTableBasicODS();
171 :
172 4 : CPPUNIT_TEST_SUITE(ScFiltersTest);
173 2 : CPPUNIT_TEST(testRangeNameXLS);
174 2 : CPPUNIT_TEST(testRangeNameXLSX);
175 2 : CPPUNIT_TEST(testHardRecalcODS);
176 2 : CPPUNIT_TEST(testFunctionsODS);
177 2 : CPPUNIT_TEST(testCachedFormulaResultsODS);
178 2 : CPPUNIT_TEST(testVolatileFunctionsODS);
179 2 : CPPUNIT_TEST(testCachedMatrixFormulaResultsODS);
180 2 : CPPUNIT_TEST(testDatabaseRangesODS);
181 2 : CPPUNIT_TEST(testDatabaseRangesXLS);
182 2 : CPPUNIT_TEST(testDatabaseRangesXLSX);
183 2 : CPPUNIT_TEST(testFormatsODS);
184 2 : CPPUNIT_TEST(testFormatsXLS);
185 2 : CPPUNIT_TEST(testFormatsXLSX);
186 2 : CPPUNIT_TEST(testMatrixODS);
187 2 : CPPUNIT_TEST(testMatrixXLS);
188 2 : CPPUNIT_TEST(testBorderODS);
189 2 : CPPUNIT_TEST(testBorderXLS);
190 2 : CPPUNIT_TEST(testBordersOoo33);
191 2 : CPPUNIT_TEST(testBugFixesODS);
192 2 : CPPUNIT_TEST(testBugFixesXLS);
193 2 : CPPUNIT_TEST(testBugFixesXLSX);
194 2 : CPPUNIT_TEST(testMergedCellsODS);
195 2 : CPPUNIT_TEST(testRepeatedColumnsODS);
196 2 : CPPUNIT_TEST(testDataValidityODS);
197 2 : CPPUNIT_TEST(testBrokenQuotesCSV);
198 2 : CPPUNIT_TEST(testSharedFormulaXLSX);
199 2 : CPPUNIT_TEST(testCellValueXLSX);
200 2 : CPPUNIT_TEST(testControlImport);
201 :
202 : //CPPUNIT_TEST(testColorScaleODS);
203 : //CPPUNIT_TEST(testColorScaleXLSX);
204 2 : CPPUNIT_TEST(testDataBarODS);
205 2 : CPPUNIT_TEST(testNewCondFormat);
206 :
207 2 : CPPUNIT_TEST(testNumberFormatHTML);
208 2 : CPPUNIT_TEST(testNumberFormatCSV);
209 :
210 2 : CPPUNIT_TEST(testCellAnchoredShapesODS);
211 :
212 2 : CPPUNIT_TEST(testPivotTableBasicODS);
213 :
214 : //disable testPassword on MacOSX due to problems with libsqlite3
215 : //also crashes on DragonFly due to problems with nss/nspr headers
216 : #if !defined(MACOSX) && !defined(DRAGONFLY) && !defined(WNT)
217 2 : CPPUNIT_TEST(testPasswordOld);
218 2 : CPPUNIT_TEST(testPasswordNew);
219 : #endif
220 :
221 : #if TEST_BUG_FILES
222 : CPPUNIT_TEST(testBugFiles);
223 : CPPUNIT_TEST(testBugFilesXLS);
224 : CPPUNIT_TEST(testBugFilesXLSX);
225 : #endif
226 4 : CPPUNIT_TEST_SUITE_END();
227 :
228 : private:
229 : void testPassword_Impl(const rtl::OUString& rFileNameBase);
230 : ScDocShellRef loadDoc(const rtl::OUString& rName, sal_Int32 nType);
231 :
232 : uno::Reference<uno::XInterface> m_xCalcComponent;
233 : ::rtl::OUString m_aBaseString;
234 : };
235 :
236 66 : ScDocShellRef ScFiltersTest::load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
237 : const rtl::OUString &rUserData, const rtl::OUString& rTypeName,
238 : unsigned int nFilterFlags, unsigned int nClipboardID, unsigned int nFilterVersion)
239 : {
240 : SfxFilter* pFilter = new SfxFilter(
241 : rFilter,
242 : rtl::OUString(), nFilterFlags, nClipboardID, rTypeName, 0, rtl::OUString(),
243 66 : rUserData, rtl::OUString("private:factory/scalc*") );
244 66 : pFilter->SetVersion(nFilterVersion);
245 :
246 66 : ScDocShellRef xDocShRef = new ScDocShell;
247 66 : xDocShRef->GetDocument()->EnableUserInteraction(false);
248 66 : SfxMedium* pSrcMed = new SfxMedium(rURL, STREAM_STD_READ);
249 66 : pSrcMed->UseInteractionHandler(false);
250 66 : pSrcMed->SetFilter(pFilter);
251 66 : if (!xDocShRef->DoLoad(pSrcMed))
252 : {
253 0 : xDocShRef->DoClose();
254 : // load failed.
255 0 : xDocShRef.Clear();
256 : }
257 :
258 66 : return xDocShRef;
259 : }
260 :
261 0 : bool ScFiltersTest::load(const rtl::OUString &rFilter, const rtl::OUString &rURL,
262 : const rtl::OUString &rUserData, unsigned int nFilterFlags,
263 : unsigned int nClipboardID, unsigned int nFilterVersion)
264 : {
265 : ScDocShellRef xDocShRef = load(rFilter, rURL, rUserData,
266 0 : rtl::OUString(), nFilterFlags, nClipboardID, nFilterVersion);
267 0 : bool bLoaded = xDocShRef.Is();
268 : //reference counting of ScDocShellRef is very confused.
269 0 : if (bLoaded)
270 0 : xDocShRef->DoClose();
271 0 : return bLoaded;
272 : }
273 :
274 42 : ScDocShellRef ScFiltersTest::loadDoc(const rtl::OUString& rName, sal_Int32 nFormat)
275 : {
276 42 : rtl::OUString aFileExtension(aFileFormats[nFormat].pName, strlen(aFileFormats[nFormat].pName), RTL_TEXTENCODING_UTF8 );
277 42 : rtl::OUString aFilterName(aFileFormats[nFormat].pFilterName, strlen(aFileFormats[nFormat].pFilterName), RTL_TEXTENCODING_UTF8) ;
278 42 : rtl::OUString aFileName;
279 42 : createFileURL( rName, aFileExtension, aFileName );
280 42 : rtl::OUString aFilterType(aFileFormats[nFormat].pTypeName, strlen(aFileFormats[nFormat].pTypeName), RTL_TEXTENCODING_UTF8);
281 42 : unsigned int nFormatType = aFileFormats[nFormat].nFormatType;
282 42 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
283 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
284 42 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
285 42 : CPPUNIT_ASSERT(xDocSh.Is());
286 42 : return xDocSh;
287 : }
288 :
289 70 : void ScFiltersTest::createFileURL(const rtl::OUString& aFileBase, const rtl::OUString& aFileExtension, rtl::OUString& rFilePath)
290 : {
291 70 : rtl::OUString aSep(RTL_CONSTASCII_USTRINGPARAM("/"));
292 70 : rtl::OUStringBuffer aBuffer( getSrcRootURL() );
293 70 : aBuffer.append(m_aBaseString).append(aSep).append(aFileExtension);
294 70 : aBuffer.append(aSep).append(aFileBase).append(aFileExtension);
295 70 : rFilePath = aBuffer.makeStringAndClear();
296 70 : }
297 :
298 60 : void ScFiltersTest::createCSVPath(const rtl::OUString& aFileBase, rtl::OUString& rCSVPath)
299 : {
300 60 : rtl::OUStringBuffer aBuffer(getSrcRootPath());
301 60 : aBuffer.append(m_aBaseString).append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/contentCSV/")));
302 60 : aBuffer.append(aFileBase).append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("csv")));
303 60 : rCSVPath = aBuffer.makeStringAndClear();
304 60 : }
305 :
306 : namespace {
307 :
308 4 : void testRangeNameImpl(ScDocument* pDoc)
309 : {
310 : //check one range data per sheet and one global more detailed
311 : //add some more checks here
312 4 : ScRangeData* pRangeData = pDoc->GetRangeName()->findByUpperName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("GLOBAL1")));
313 4 : CPPUNIT_ASSERT_MESSAGE("range name Global1 not found", pRangeData);
314 : double aValue;
315 4 : pDoc->GetValue(1,0,0,aValue);
316 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("range name Global1 should reference Sheet1.A1", 1.0, aValue);
317 4 : pRangeData = pDoc->GetRangeName(0)->findByUpperName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LOCAL1")));
318 4 : CPPUNIT_ASSERT_MESSAGE("range name Sheet1.Local1 not found", pRangeData);
319 4 : pDoc->GetValue(1,2,0,aValue);
320 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("range name Sheet1.Local1 should reference Sheet1.A3", 3.0, aValue);
321 4 : pRangeData = pDoc->GetRangeName(1)->findByUpperName(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("LOCAL2")));
322 4 : CPPUNIT_ASSERT_MESSAGE("range name Sheet2.Local2 not found", pRangeData);
323 4 : pDoc->GetValue(1,1,1,aValue);
324 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("range name Sheet2.Local2 should reference Sheet2.A2", 7.0, aValue);
325 : //check for correct results for the remaining formulas
326 4 : pDoc->GetValue(1,1,0, aValue);
327 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("=global2 should be 2", 2.0, aValue);
328 4 : pDoc->GetValue(1,3,0, aValue);
329 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("=local2 should be 4", 4.0, aValue);
330 4 : pDoc->GetValue(2,0,0, aValue);
331 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("=SUM(global3) should be 10", 10.0, aValue);
332 4 : pDoc->GetValue(1,0,1,aValue);
333 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("range name Sheet2.local1 should reference Sheet1.A5", 5.0, aValue);
334 : // Test if Global5 ( which depends on Global6 ) is evaluated
335 4 : pDoc->GetValue(0,5,1, aValue);
336 4 : CPPUNIT_ASSERT_EQUAL_MESSAGE("formula Global5 should reference Global6 ( which is evaluated as local1 )", 5.0, aValue);
337 4 : }
338 :
339 : }
340 :
341 2 : void ScFiltersTest::testRangeNameXLS()
342 : {
343 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("named-ranges-global."));
344 2 : ScDocShellRef xDocSh = loadDoc(aFileNameBase, XLS);
345 2 : xDocSh->DoHardRecalc(true);
346 :
347 2 : ScDocument* pDoc = xDocSh->GetDocument();
348 2 : testRangeNameImpl(pDoc);
349 :
350 2 : rtl::OUString aSheet2CSV(RTL_CONSTASCII_USTRINGPARAM("rangeExp_Sheet2."));
351 2 : rtl::OUString aCSVPath;
352 2 : createCSVPath( aSheet2CSV, aCSVPath );
353 : // fdo#44587
354 2 : testFile( aCSVPath, pDoc, 1);
355 :
356 2 : xDocSh->DoClose();
357 2 : }
358 :
359 2 : void ScFiltersTest::testRangeNameXLSX()
360 : {
361 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("named-ranges-global."));
362 2 : ScDocShellRef xDocSh = loadDoc(aFileNameBase, XLSX);
363 2 : xDocSh->DoHardRecalc(true);
364 :
365 2 : ScDocument* pDoc = xDocSh->GetDocument();
366 2 : testRangeNameImpl(pDoc);
367 :
368 2 : xDocSh->DoClose();
369 2 : }
370 :
371 2 : void ScFiltersTest::testHardRecalcODS()
372 : {
373 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("hard-recalc."));
374 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, ODS );
375 2 : xDocSh->DoHardRecalc(true);
376 :
377 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load hard-recalc.*", xDocSh.Is());
378 2 : ScDocument* pDoc = xDocSh->GetDocument();
379 2 : rtl::OUString aCSVFileName;
380 :
381 : //test hard recalc: document has an incorrect cached formula result
382 : //hard recalc should have updated to the correct result
383 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("hard-recalc.")), aCSVFileName);
384 2 : testFile(aCSVFileName, pDoc, 0);
385 :
386 2 : xDocSh->DoClose();
387 2 : }
388 :
389 2 : void ScFiltersTest::testFunctionsODS()
390 : {
391 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("functions."));
392 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, ODS );
393 2 : xDocSh->DoHardRecalc(true);
394 :
395 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load functions.*", xDocSh.Is());
396 2 : ScDocument* pDoc = xDocSh->GetDocument();
397 2 : rtl::OUString aCSVFileName;
398 :
399 : //test logical functions
400 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("logical-functions.")), aCSVFileName);
401 2 : testFile(aCSVFileName, pDoc, 0);
402 : //test spreadsheet functions
403 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("spreadsheet-functions.")), aCSVFileName);
404 2 : testFile(aCSVFileName, pDoc, 1);
405 : //test mathematical functions
406 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("mathematical-functions.")), aCSVFileName);
407 2 : testFile(aCSVFileName, pDoc, 2, PureString);
408 : //test informations functions
409 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("information-functions.")), aCSVFileName);
410 2 : testFile(aCSVFileName, pDoc, 3);
411 :
412 2 : xDocSh->DoClose();
413 2 : }
414 :
415 2 : void ScFiltersTest::testCachedFormulaResultsODS()
416 : {
417 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("functions."));
418 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, ODS );
419 :
420 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load functions.*", xDocSh.Is());
421 2 : ScDocument* pDoc = xDocSh->GetDocument();
422 2 : rtl::OUString aCSVFileName;
423 :
424 : //test cached formula results of logical functions
425 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("logical-functions.")), aCSVFileName);
426 2 : testFile(aCSVFileName, pDoc, 0);
427 : //test cached formula results of spreadsheet functions
428 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("spreadsheet-functions.")), aCSVFileName);
429 2 : testFile(aCSVFileName, pDoc, 1);
430 : //test cached formula results of mathematical functions
431 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("mathematical-functions.")), aCSVFileName);
432 2 : testFile(aCSVFileName, pDoc, 2, PureString);
433 : //test cached formula results of informations functions
434 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("information-functions.")), aCSVFileName);
435 2 : testFile(aCSVFileName, pDoc, 3);
436 :
437 2 : xDocSh->DoClose();
438 2 : }
439 :
440 2 : void ScFiltersTest::testVolatileFunctionsODS()
441 : {
442 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("volatile."));
443 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, ODS );
444 :
445 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load volatile.ods", xDocSh.Is());
446 2 : ScDocument* pDoc = xDocSh->GetDocument();
447 :
448 : //we want to me sure that volatile functions are always recalculated
449 : //regardless of cached results. if you update the ods file, you must
450 : //update the values here.
451 : //if NOW() is recacluated, then it should never equal sTodayCache
452 2 : OUString sTodayCache("07/11/12 12:28 AM");
453 2 : OUString sTodayRecalc(pDoc->GetString(0,1,0));
454 2 : CPPUNIT_ASSERT(sTodayCache != sTodayRecalc);
455 :
456 2 : OUString sTodayRecalcRef(pDoc->GetString(2,1,0));
457 2 : CPPUNIT_ASSERT(sTodayCache != sTodayRecalcRef);
458 :
459 2 : xDocSh->DoClose();
460 2 : }
461 :
462 2 : void ScFiltersTest::testCachedMatrixFormulaResultsODS()
463 : {
464 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("matrix."));
465 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, ODS);
466 :
467 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load matrix.*", xDocSh.Is());
468 2 : ScDocument* pDoc = xDocSh->GetDocument();
469 :
470 : //test matrix
471 2 : rtl::OUString aCSVFileName;
472 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("matrix.")), aCSVFileName);
473 2 : testFile(aCSVFileName, pDoc, 0);
474 : //test matrices with special cases
475 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("matrix2.")), aCSVFileName);
476 2 : testFile(aCSVFileName, pDoc, 1);
477 : //The above testFile() does not catch the below case.
478 : //If a matrix formula has a matrix reference cell that is intended to have
479 : //a blank text result, the matrix reference cell is actually saved(export)
480 : //as a float cell with 0 as the value and an empty <text:p/>.
481 : //Import works around this by setting these cells as text cells so that
482 : //the blank text is used for display instead of the number 0.
483 : //If this is working properly, the following cell should NOT have value data.
484 2 : CPPUNIT_ASSERT(!pDoc->GetCell(ScAddress(3,5,1))->HasValueData());
485 :
486 2 : xDocSh->DoClose();
487 2 : }
488 :
489 : namespace {
490 :
491 6 : void testDBRanges_Impl(ScDocument* pDoc, sal_Int32 nFormat)
492 : {
493 6 : ScDBCollection* pDBCollection = pDoc->GetDBCollection();
494 6 : CPPUNIT_ASSERT_MESSAGE("no database collection", pDBCollection);
495 :
496 6 : ScDBData* pAnonDBData = pDoc->GetAnonymousDBData(0);
497 6 : CPPUNIT_ASSERT_MESSAGE("missing anonymous DB data in sheet 1", pAnonDBData);
498 : //control hidden rows
499 : bool bHidden;
500 : SCROW nRow1, nRow2;
501 6 : bHidden = pDoc->RowHidden(0, 0, &nRow1, &nRow2);
502 6 : CPPUNIT_ASSERT_MESSAGE("Sheet1: row 0 should be visible", !bHidden && nRow1 == 0 && nRow2 == 0);
503 6 : bHidden = pDoc->RowHidden(1, 0, &nRow1, &nRow2);
504 6 : CPPUNIT_ASSERT_MESSAGE("Sheet1: rows 1-2 should be hidden", bHidden && nRow1 == 1 && nRow2 == 2);
505 6 : bHidden = pDoc->RowHidden(3, 0, &nRow1, &nRow2);
506 6 : CPPUNIT_ASSERT_MESSAGE("Sheet1: row 3 should be visible", !bHidden && nRow1 == 3 && nRow2 == 3);
507 6 : bHidden = pDoc->RowHidden(4, 0, &nRow1, &nRow2);
508 6 : CPPUNIT_ASSERT_MESSAGE("Sheet1: row 4-5 should be hidden", bHidden && nRow1 == 4 && nRow2 == 5);
509 6 : bHidden = pDoc->RowHidden(6, 0, &nRow1, &nRow2);
510 6 : CPPUNIT_ASSERT_MESSAGE("Sheet1: row 6-end should be visible", !bHidden && nRow1 == 6 && nRow2 == MAXROW);
511 6 : if(nFormat == ODS) //excel doesn't support named db ranges
512 : {
513 : double aValue;
514 2 : pDoc->GetValue(0,10,1, aValue);
515 2 : rtl::OUString aString;
516 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Sheet2: A11: formula result is incorrect", 4.0, aValue);
517 2 : pDoc->GetValue(1, 10, 1, aValue);
518 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Sheet2: B11: formula result is incorrect", 2.0, aValue);
519 : }
520 : double aValue;
521 6 : pDoc->GetValue(3,10,1, aValue);
522 6 : rtl::OUString aString;
523 6 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Sheet2: D11: formula result is incorrect", 4.0, aValue);
524 6 : pDoc->GetValue(4, 10, 1, aValue);
525 6 : CPPUNIT_ASSERT_EQUAL_MESSAGE("Sheet2: E11: formula result is incorrect", 2.0, aValue);
526 :
527 6 : }
528 :
529 : }
530 :
531 2 : void ScFiltersTest::testDatabaseRangesODS()
532 : {
533 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("database."));
534 2 : ScDocShellRef xDocSh = loadDoc(aFileNameBase, 0);
535 2 : xDocSh->DoHardRecalc(true);
536 :
537 2 : ScDocument* pDoc = xDocSh->GetDocument();
538 :
539 2 : testDBRanges_Impl(pDoc, ODS);
540 2 : xDocSh->DoClose();
541 2 : }
542 :
543 2 : void ScFiltersTest::testDatabaseRangesXLS()
544 : {
545 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("database."));
546 2 : ScDocShellRef xDocSh = loadDoc(aFileNameBase, 1);
547 2 : xDocSh->DoHardRecalc(true);
548 :
549 2 : ScDocument* pDoc = xDocSh->GetDocument();
550 :
551 2 : testDBRanges_Impl(pDoc, XLS);
552 2 : xDocSh->DoClose();
553 2 : }
554 :
555 2 : void ScFiltersTest::testDatabaseRangesXLSX()
556 : {
557 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("database."));
558 2 : ScDocShellRef xDocSh = loadDoc(aFileNameBase, 2);
559 2 : xDocSh->DoHardRecalc(true);
560 :
561 2 : ScDocument* pDoc = xDocSh->GetDocument();
562 :
563 2 : testDBRanges_Impl(pDoc, XLSX);
564 2 : xDocSh->DoClose();
565 2 : }
566 :
567 : namespace {
568 :
569 6 : void testFormats_Impl(ScFiltersTest* pFiltersTest, ScDocument* pDoc, sal_Int32 nFormat)
570 : {
571 : //test Sheet1 with csv file
572 6 : rtl::OUString aCSVFileName;
573 6 : pFiltersTest->createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("numberFormat.")), aCSVFileName);
574 6 : testFile(aCSVFileName, pDoc, 0, PureString);
575 : //need to test the color of B3
576 : //it's not a font color!
577 : //formatting for B5: # ??/100 gets lost during import
578 :
579 : //test Sheet2
580 6 : const ScPatternAttr* pPattern = NULL;
581 6 : pPattern = pDoc->GetPattern(0,0,1);
582 6 : Font aFont;
583 6 : pPattern->GetFont(aFont,SC_AUTOCOL_RAW);
584 6 : CPPUNIT_ASSERT_EQUAL_MESSAGE("font size should be 10", 200l, aFont.GetSize().getHeight());
585 6 : CPPUNIT_ASSERT_EQUAL_MESSAGE("font color should be black", COL_AUTO, aFont.GetColor().GetColor());
586 6 : pPattern = pDoc->GetPattern(0,1,1);
587 6 : pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
588 6 : CPPUNIT_ASSERT_EQUAL_MESSAGE("font size should be 12", 240l, aFont.GetSize().getHeight());
589 6 : pPattern = pDoc->GetPattern(0,2,1);
590 6 : pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
591 6 : CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be italic", ITALIC_NORMAL, aFont.GetItalic());
592 6 : pPattern = pDoc->GetPattern(0,4,1);
593 6 : pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
594 6 : CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be bold", WEIGHT_BOLD, aFont.GetWeight());
595 6 : pPattern = pDoc->GetPattern(1,0,1);
596 6 : pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
597 6 : CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be blue", COL_BLUE, aFont.GetColor().GetColor());
598 6 : pPattern = pDoc->GetPattern(1,1,1);
599 6 : pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
600 6 : CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be striked out with a single line", STRIKEOUT_SINGLE, aFont.GetStrikeout());
601 : //some tests on sheet2 only for ods
602 6 : if (nFormat == ODS)
603 : {
604 2 : pPattern = pDoc->GetPattern(1,2,1);
605 2 : pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
606 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be striked out with a double line", STRIKEOUT_DOUBLE, aFont.GetStrikeout());
607 2 : pPattern = pDoc->GetPattern(1,3,1);
608 2 : pPattern->GetFont(aFont, SC_AUTOCOL_RAW);
609 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("font should be underlined with a dotted line", UNDERLINE_DOTTED, aFont.GetUnderline());
610 : //check row height import
611 : //disable for now until we figure out cause of win tinderboxes test failures
612 : //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(256), pDoc->GetRowHeight(0,1) ); //0.178in
613 : //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(304), pDoc->GetRowHeight(1,1) ); //0.211in
614 : //CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(477), pDoc->GetRowHeight(5,1) ); //0.3311in
615 : //check column width import
616 2 : CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(555), pDoc->GetColWidth(4,1) ); //0.3854in
617 2 : CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(1280), pDoc->GetColWidth(5,1) ); //0.889in
618 2 : CPPUNIT_ASSERT_EQUAL( static_cast<sal_uInt16>(4153), pDoc->GetColWidth(6,1) ); //2.8839in
619 : //test case for i53253 where a cell has text with different styles and space between the text.
620 2 : rtl::OUString aTestStr;
621 2 : pDoc->GetString(3,0,1, aTestStr);
622 2 : rtl::OUString aKnownGoodStr("text14 space");
623 2 : CPPUNIT_ASSERT_EQUAL( aKnownGoodStr, aTestStr );
624 : //test case for cell text with line breaks.
625 2 : pDoc->GetString(3,5,1, aTestStr);
626 2 : aKnownGoodStr = "Hello,\nCalc!";
627 2 : CPPUNIT_ASSERT_EQUAL( aKnownGoodStr, aTestStr );
628 : }
629 6 : pPattern = pDoc->GetPattern(1,4,1);
630 6 : Color aColor = static_cast<const SvxBrushItem&>(pPattern->GetItem(ATTR_BACKGROUND)).GetColor();
631 6 : CPPUNIT_ASSERT_MESSAGE("background color should be green", aColor == COL_LIGHTGREEN);
632 6 : pPattern = pDoc->GetPattern(2,0,1);
633 6 : SvxCellHorJustify eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
634 6 : CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned centre horizontally", SVX_HOR_JUSTIFY_CENTER, eHorJustify);
635 : //test alignment
636 6 : pPattern = pDoc->GetPattern(2,1,1);
637 6 : eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
638 6 : CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned right horizontally", SVX_HOR_JUSTIFY_RIGHT, eHorJustify);
639 6 : pPattern = pDoc->GetPattern(2,2,1);
640 6 : eHorJustify = static_cast<SvxCellHorJustify>(static_cast<const SvxHorJustifyItem&>(pPattern->GetItem(ATTR_HOR_JUSTIFY)).GetValue());
641 6 : CPPUNIT_ASSERT_EQUAL_MESSAGE("cell content should be aligned block horizontally", SVX_HOR_JUSTIFY_BLOCK, eHorJustify);
642 :
643 : //test Sheet3 only for ods
644 6 : if ( nFormat == ODS || nFormat == XLSX )
645 : {
646 4 : rtl::OUString aCondString = getConditionalFormatString(pDoc, 3,0,2);
647 4 : pFiltersTest->createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("conditionalFormatting.")), aCSVFileName);
648 4 : testCondFile(aCSVFileName, pDoc, 2);
649 : // test parent cell style import ( fdo#55198 )
650 4 : if ( nFormat == XLSX )
651 : {
652 2 : pPattern = pDoc->GetPattern(1,1,3);
653 2 : ScStyleSheet* pStyleSheet = (ScStyleSheet*)pPattern->GetStyleSheet();
654 : // check parent style name
655 2 : rtl::OUString sExpected("Excel Built-in Date");
656 2 : rtl::OUString sResult = pStyleSheet->GetName();
657 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("parent style for Sheet4.B2 is 'Excel Built-in Date'", sExpected, sResult);
658 : // check align of style
659 2 : SfxItemSet& rItemSet = pStyleSheet->GetItemSet();
660 2 : eHorJustify = static_cast<SvxCellHorJustify>(static_cast< const SvxHorJustifyItem& >(rItemSet.Get( ATTR_HOR_JUSTIFY ) ).GetValue() );
661 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'Excel Built-in Date' style should be aligned centre horizontally", SVX_HOR_JUSTIFY_CENTER, eHorJustify);
662 : // check date format ( should be just month e.g. 29 )
663 2 : sResult =pDoc->GetString( 1,1,3 );
664 2 : sExpected = rtl::OUString("29");
665 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("'Excel Built-in Date' style should just display month", sExpected, sResult );
666 :
667 : // check actual align applied to cell, should be the same as
668 : // the style
669 2 : eHorJustify = static_cast<SvxCellHorJustify>(static_cast< const SvxHorJustifyItem& >(pPattern->GetItem( ATTR_HOR_JUSTIFY ) ).GetValue() );
670 2 : CPPUNIT_ASSERT_EQUAL_MESSAGE("cell with 'Excel Built-in Date' style should be aligned centre horizontally", SVX_HOR_JUSTIFY_CENTER, eHorJustify);
671 4 : }
672 : }
673 :
674 6 : ScConditionalFormat* pCondFormat = pDoc->GetCondFormat(0,0,2);
675 6 : const ScRangeList& rRange = pCondFormat->GetRange();
676 6 : CPPUNIT_ASSERT(rRange == ScRange(0,0,2,3,0,2));
677 :
678 6 : pCondFormat = pDoc->GetCondFormat(0,1,2);
679 6 : const ScRangeList& rRange2 = pCondFormat->GetRange();
680 6 : CPPUNIT_ASSERT(rRange2 == ScRange(0,1,2,0,1,2));
681 :
682 6 : pCondFormat = pDoc->GetCondFormat(1,1,2);
683 6 : const ScRangeList& rRange3 = pCondFormat->GetRange();
684 6 : CPPUNIT_ASSERT(rRange3 == ScRange(1,1,2,3,1,2));
685 6 : }
686 :
687 : }
688 :
689 2 : void ScFiltersTest::testFormatsODS()
690 : {
691 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("formats."));
692 2 : ScDocShellRef xDocSh = loadDoc(aFileNameBase, 0);
693 2 : xDocSh->DoHardRecalc(true);
694 :
695 2 : ScDocument* pDoc = xDocSh->GetDocument();
696 :
697 2 : testFormats_Impl(this, pDoc, ODS);
698 2 : xDocSh->DoClose();
699 2 : }
700 :
701 2 : void ScFiltersTest::testFormatsXLS()
702 : {
703 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("formats."));
704 2 : ScDocShellRef xDocSh = loadDoc(aFileNameBase, 1);
705 2 : xDocSh->DoHardRecalc(true);
706 :
707 2 : ScDocument* pDoc = xDocSh->GetDocument();
708 :
709 2 : testFormats_Impl(this, pDoc, XLS);
710 2 : xDocSh->DoClose();
711 2 : }
712 :
713 2 : void ScFiltersTest::testFormatsXLSX()
714 : {
715 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("formats."));
716 2 : ScDocShellRef xDocSh = loadDoc(aFileNameBase, 2);
717 2 : xDocSh->DoHardRecalc(true);
718 :
719 2 : ScDocument* pDoc = xDocSh->GetDocument();
720 :
721 2 : testFormats_Impl(this, pDoc, XLSX);
722 2 : xDocSh->DoClose();
723 2 : }
724 :
725 2 : void ScFiltersTest::testMatrixODS()
726 : {
727 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("matrix."));
728 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, 0);
729 2 : xDocSh->DoHardRecalc(true);
730 :
731 2 : ScDocument* pDoc = xDocSh->GetDocument();
732 :
733 2 : rtl::OUString aCSVFileName;
734 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("matrix.")), aCSVFileName);
735 2 : testFile(aCSVFileName, pDoc, 0);
736 :
737 2 : xDocSh->DoClose();
738 2 : }
739 :
740 2 : void ScFiltersTest::testMatrixXLS()
741 : {
742 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("matrix."));
743 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, 1);
744 2 : xDocSh->DoHardRecalc(true);
745 :
746 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load matrix.*", xDocSh.Is());
747 2 : ScDocument* pDoc = xDocSh->GetDocument();
748 :
749 2 : rtl::OUString aCSVFileName;
750 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("matrix.")), aCSVFileName);
751 2 : testFile(aCSVFileName, pDoc, 0);
752 :
753 2 : xDocSh->DoClose();
754 2 : }
755 :
756 2 : void ScFiltersTest::testBorderODS()
757 : {
758 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("border."));
759 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, 0);
760 :
761 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load border.*", xDocSh.Is());
762 2 : ScDocument* pDoc = xDocSh->GetDocument();
763 :
764 2 : const editeng::SvxBorderLine* pLeft = NULL;
765 2 : const editeng::SvxBorderLine* pTop = NULL;
766 2 : const editeng::SvxBorderLine* pRight = NULL;
767 2 : const editeng::SvxBorderLine* pBottom = NULL;
768 :
769 2 : pDoc->GetBorderLines( 0, 1, 0, &pLeft, &pTop, &pRight, &pBottom );
770 2 : CPPUNIT_ASSERT(!pLeft);
771 2 : CPPUNIT_ASSERT(!pTop);
772 2 : CPPUNIT_ASSERT(!pBottom);
773 2 : CPPUNIT_ASSERT(pRight);
774 4 : CPPUNIT_ASSERT_EQUAL(pRight->GetBorderLineStyle(),
775 2 : table::BorderLineStyle::SOLID);
776 :
777 2 : pDoc->GetBorderLines( 2, 1, 0, &pLeft, &pTop, &pRight, &pBottom );
778 2 : CPPUNIT_ASSERT(!pLeft);
779 2 : CPPUNIT_ASSERT(!pTop);
780 2 : CPPUNIT_ASSERT(!pBottom);
781 :
782 2 : CPPUNIT_ASSERT(pRight);
783 4 : CPPUNIT_ASSERT_EQUAL(pRight->GetBorderLineStyle(),
784 2 : table::BorderLineStyle::SOLID);
785 2 : CPPUNIT_ASSERT_EQUAL(pRight->GetWidth(),20L);
786 :
787 2 : pDoc->GetBorderLines( 2, 8, 0, &pLeft, &pTop, &pRight, &pBottom );
788 :
789 2 : CPPUNIT_ASSERT(pLeft);
790 2 : CPPUNIT_ASSERT(pTop);
791 2 : CPPUNIT_ASSERT(pBottom);
792 2 : CPPUNIT_ASSERT(pRight);
793 4 : CPPUNIT_ASSERT_EQUAL(pRight->GetBorderLineStyle(),
794 2 : table::BorderLineStyle::SOLID);
795 2 : CPPUNIT_ASSERT_EQUAL(pRight->GetWidth(),5L);
796 2 : CPPUNIT_ASSERT(pRight->GetColor() == Color(COL_BLUE));
797 :
798 2 : xDocSh->DoClose();
799 2 : }
800 :
801 2 : void ScFiltersTest::testBorderXLS()
802 : {
803 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("border."));
804 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, 1);
805 :
806 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load border.xls", xDocSh.Is());
807 2 : ScDocument* pDoc = xDocSh->GetDocument();
808 :
809 2 : const editeng::SvxBorderLine* pLeft = NULL;
810 2 : const editeng::SvxBorderLine* pTop = NULL;
811 2 : const editeng::SvxBorderLine* pRight = NULL;
812 2 : const editeng::SvxBorderLine* pBottom = NULL;
813 :
814 2 : pDoc->GetBorderLines( 2, 3, 0, &pLeft, &pTop, &pRight, &pBottom );
815 2 : CPPUNIT_ASSERT(pRight);
816 4 : CPPUNIT_ASSERT_EQUAL(pRight->GetBorderLineStyle(),
817 2 : table::BorderLineStyle::SOLID);
818 2 : CPPUNIT_ASSERT_EQUAL(pRight->GetWidth(),4L);
819 :
820 2 : pDoc->GetBorderLines( 3, 5, 0, &pLeft, &pTop, &pRight, &pBottom );
821 2 : CPPUNIT_ASSERT(pRight);
822 4 : CPPUNIT_ASSERT_EQUAL(pRight->GetBorderLineStyle(),
823 2 : table::BorderLineStyle::SOLID);
824 2 : CPPUNIT_ASSERT_EQUAL(pRight->GetWidth(),12L);
825 :
826 2 : pDoc->GetBorderLines( 5, 7, 0, &pLeft, &pTop, &pRight, &pBottom );
827 2 : CPPUNIT_ASSERT(pRight);
828 4 : CPPUNIT_ASSERT_EQUAL(pRight->GetBorderLineStyle(),
829 2 : table::BorderLineStyle::SOLID);
830 2 : CPPUNIT_ASSERT_EQUAL(pRight->GetWidth(),16L);
831 2 : }
832 : struct Border
833 : {
834 : sal_Int16 column;
835 : sal_Int32 row;
836 : long leftWidth;
837 : long topWidth;
838 : long rightWidth;
839 : long bottomWidth;
840 : sal_uInt16 lOutWidth;
841 : sal_uInt16 lInWidth;
842 : sal_uInt16 lDistance;
843 : sal_uInt16 tOutWidth;
844 : sal_uInt16 tInWidth;
845 : sal_uInt16 tDistance;
846 : sal_uInt16 rOutWidth;
847 : sal_uInt16 rInWidth;
848 : sal_uInt16 rDistance;
849 : sal_uInt16 bOutWidth;
850 : sal_uInt16 bInWidth;
851 : sal_uInt16 bDistance;
852 : sal_Int32 lStyle;
853 : sal_Int32 tStyle;
854 : sal_Int32 rStyle;
855 : sal_Int32 bStyle;
856 : // that's a monstrum
857 34 : Border(sal_Int16 col, sal_Int32 r, sal_Int32 lW, sal_Int32 tW, sal_Int32 rW, sal_Int32 bW, sal_uInt16 lOutW, sal_uInt16 lInW,
858 : sal_uInt16 lDist, sal_uInt16 tOutW, sal_uInt16 tInW, sal_uInt16 tDist, sal_uInt16 rOutW, sal_uInt16 rInW, sal_uInt16 rDist,
859 : sal_uInt16 bOutW, sal_uInt16 bInW, sal_uInt16 bDist, sal_Int32 lSt, sal_Int32 tSt, sal_Int32 rSt, sal_Int32 bSt):
860 : column(col), row(r), leftWidth(lW), topWidth(tW), rightWidth(rW), bottomWidth(bW), lOutWidth(lOutW), lInWidth(lInW), lDistance(lDist),
861 : tOutWidth(tOutW), tInWidth(tInW), tDistance(tDist), rOutWidth(rOutW), rInWidth(rInW), rDistance(rDist), bOutWidth(bOutW), bInWidth(bInW),
862 34 : bDistance(bDist), lStyle(lSt), tStyle(tSt), rStyle(rSt), bStyle(bSt) {};
863 : };
864 :
865 2 : void ScFiltersTest::testBordersOoo33()
866 : {
867 2 : std::vector<Border> borders;
868 2 : borders.push_back(Border(1, 1, 22, 22, 22, 22, 1, 1, 20, 1, 1, 20, 1, 1, 20, 1, 1, 20, 3, 3, 3, 3));
869 2 : borders.push_back(Border(1, 3, 52, 52, 52, 52, 1, 1, 50, 1, 1, 50, 1, 1, 50, 1, 1, 50, 3, 3, 3, 3));
870 2 : borders.push_back(Border(1, 5, 60, 60, 60, 60, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 3, 3, 3, 3));
871 2 : borders.push_back(Border(1, 7, 150, 150, 150, 150, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 3, 3, 3, 3));
872 2 : borders.push_back(Border(1, 9, 71, 71, 71, 71, 20, 1, 50, 20, 1, 50, 20, 1, 50, 20, 1, 50, 3, 3, 3, 3));
873 2 : borders.push_back(Border(1, 11, 101, 101, 101, 101, 50, 1, 50, 50, 1, 50, 50, 1, 50, 50, 1, 50, 3, 3, 3, 3));
874 2 : borders.push_back(Border(1, 13, 131, 131, 131, 131, 80, 1, 50, 80, 1, 50, 80, 1, 50, 80, 1, 50, 3, 3, 3, 3));
875 2 : borders.push_back(Border(1, 15, 120, 120, 120, 120, 50, 20, 50, 50, 20, 50, 50, 20, 50, 50, 20, 50, 3, 3, 3, 3));
876 2 : borders.push_back(Border(1, 17, 90, 90, 90, 90, 20, 50, 20, 20, 50, 20, 20, 50, 20, 20, 50, 20, 3, 3, 3, 3));
877 2 : borders.push_back(Border(1, 19, 180, 180, 180, 180, 80, 50, 50, 80, 50, 50, 80, 50, 50, 80, 50, 50, 3, 3, 3, 3));
878 2 : borders.push_back(Border(1, 21, 180, 180, 180, 180, 50, 80, 50, 50, 80, 50, 50, 80, 50, 50, 80, 50, 3, 3, 3, 3));
879 2 : borders.push_back(Border(4, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0));
880 2 : borders.push_back(Border(4, 3, 10, 10, 10, 10, 10, 0, 0, 10, 0, 0, 10, 0, 0, 10, 0, 0, 0, 0, 0, 0));
881 2 : borders.push_back(Border(4, 5, 20, 20, 20, 20, 20, 0, 0, 20, 0, 0, 20, 0, 0, 20, 0, 0, 0, 0, 0, 0));
882 2 : borders.push_back(Border(4, 7, 50, 50, 50, 50, 50, 0, 0, 50, 0, 0, 50, 0, 0, 50, 0, 0, 0, 0, 0, 0));
883 2 : borders.push_back(Border(4, 9, 80, 80, 80, 80, 80, 0, 0, 80, 0, 0, 80, 0, 0, 80, 0, 0, 0, 0, 0, 0));
884 2 : borders.push_back(Border(4, 11, 100, 100, 100, 100, 100, 0, 0, 100, 0, 0, 100, 0, 0, 100, 0, 0, 0, 0, 0, 0));
885 :
886 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("borders_ooo33."));
887 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, 0);
888 :
889 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load borders_ooo33.*", xDocSh.Is());
890 2 : ScDocument* pDoc = xDocSh->GetDocument();
891 :
892 2 : const editeng::SvxBorderLine* pLeft = NULL;
893 2 : const editeng::SvxBorderLine* pTop = NULL;
894 2 : const editeng::SvxBorderLine* pRight = NULL;
895 2 : const editeng::SvxBorderLine* pBottom = NULL;
896 2 : sal_Int16 temp = 0;
897 14 : for(sal_Int16 i = 0; i<6; ++i)
898 : {
899 276 : for(sal_Int32 j = 0; j<22; ++j)
900 : {
901 264 : pDoc->GetBorderLines( i, j, 0, &pLeft, &pTop, &pRight, &pBottom );
902 264 : if(pLeft!=NULL && pTop!=NULL && pRight!=NULL && pBottom!=NULL)
903 : {
904 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].column, i);
905 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].row, j);
906 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].leftWidth, pLeft->GetWidth());
907 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].topWidth, pTop->GetWidth());
908 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].rightWidth, pRight->GetWidth());
909 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].bottomWidth, pBottom->GetWidth());
910 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].lOutWidth, pLeft->GetOutWidth());
911 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].lInWidth, pLeft->GetInWidth());
912 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].lDistance, pLeft->GetDistance());
913 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].tOutWidth, pTop->GetOutWidth());
914 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].tInWidth, pTop->GetInWidth());
915 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].tDistance, pTop->GetDistance());
916 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].rOutWidth, pRight->GetOutWidth());
917 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].rInWidth, pRight->GetInWidth());
918 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].rDistance, pRight->GetDistance());
919 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].bOutWidth, pBottom->GetOutWidth());
920 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].bInWidth, pBottom->GetInWidth());
921 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].bDistance, pBottom->GetDistance());
922 34 : sal_Int32 tempStyle = pLeft->GetBorderLineStyle();
923 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].lStyle, tempStyle);
924 34 : tempStyle = pTop->GetBorderLineStyle();
925 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].tStyle, tempStyle);
926 34 : tempStyle = pRight->GetBorderLineStyle();
927 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].rStyle, tempStyle);
928 34 : tempStyle = pBottom->GetBorderLineStyle();
929 34 : CPPUNIT_ASSERT_EQUAL(borders[temp].bStyle, tempStyle);
930 34 : ++temp;
931 : }
932 : }
933 2 : }
934 2 : }
935 :
936 2 : void ScFiltersTest::testBugFixesODS()
937 : {
938 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("bug-fixes."));
939 2 : rtl::OUString aFileExtension(aFileFormats[0].pName, strlen(aFileFormats[0].pName), RTL_TEXTENCODING_UTF8 );
940 2 : rtl::OUString aFilterName(aFileFormats[0].pFilterName, strlen(aFileFormats[0].pFilterName), RTL_TEXTENCODING_UTF8) ;
941 2 : rtl::OUString aFileName;
942 2 : createFileURL(aFileNameBase, aFileExtension, aFileName);
943 2 : rtl::OUString aFilterType(aFileFormats[0].pTypeName, strlen(aFileFormats[0].pTypeName), RTL_TEXTENCODING_UTF8);
944 2 : std::cout << aFileFormats[0].pName << " Test" << std::endl;
945 2 : unsigned int nFormatType = aFileFormats[0].nFormatType;
946 2 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
947 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
948 2 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
949 2 : xDocSh->DoHardRecalc(true);
950 :
951 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load bugFixes.ods", xDocSh.Is());
952 2 : ScDocument* pDoc = xDocSh->GetDocument();
953 :
954 : {
955 : // fdo
956 2 : rtl::OUString aCSVFileName;
957 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("bugFix_Sheet2.")), aCSVFileName);
958 2 : testFile(aCSVFileName, pDoc, 1);
959 : }
960 :
961 : {
962 : // fdo#40426
963 2 : ScDBData* pDBData = pDoc->GetDBCollection()->getNamedDBs().findByUpperName("DBRANGE1");
964 2 : CPPUNIT_ASSERT(pDBData);
965 2 : CPPUNIT_ASSERT(pDBData->HasHeader());
966 : // no header
967 2 : pDBData = pDoc->GetDBCollection()->getNamedDBs().findByUpperName("DBRANGE2");
968 2 : CPPUNIT_ASSERT(pDBData);
969 2 : CPPUNIT_ASSERT(!pDBData->HasHeader());
970 : }
971 :
972 2 : xDocSh->DoClose();
973 2 : }
974 :
975 2 : void ScFiltersTest::testBugFixesXLS()
976 : {
977 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("bug-fixes."));
978 2 : rtl::OUString aFileExtension(aFileFormats[1].pName, strlen(aFileFormats[1].pName), RTL_TEXTENCODING_UTF8 );
979 2 : rtl::OUString aFilterName(aFileFormats[1].pFilterName, strlen(aFileFormats[1].pFilterName), RTL_TEXTENCODING_UTF8) ;
980 2 : rtl::OUString aFileName;
981 2 : createFileURL(aFileNameBase, aFileExtension, aFileName);
982 2 : rtl::OUString aFilterType(aFileFormats[1].pTypeName, strlen(aFileFormats[1].pTypeName), RTL_TEXTENCODING_UTF8);
983 2 : std::cout << aFileFormats[1].pName << " Test" << std::endl;
984 2 : unsigned int nFormatType = aFileFormats[1].nFormatType;
985 2 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
986 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
987 2 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
988 2 : xDocSh->DoHardRecalc(true);
989 :
990 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load bugFixes.xls", xDocSh.Is());
991 2 : ScDocument* pDoc = xDocSh->GetDocument();
992 2 : CPPUNIT_ASSERT_MESSAGE("No Document", pDoc); //remove with first test
993 2 : xDocSh->DoClose();
994 2 : }
995 :
996 2 : void ScFiltersTest::testBugFixesXLSX()
997 : {
998 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("bug-fixes."));
999 2 : rtl::OUString aFileExtension(aFileFormats[2].pName, strlen(aFileFormats[2].pName), RTL_TEXTENCODING_UTF8 );
1000 2 : rtl::OUString aFilterName(aFileFormats[2].pFilterName, strlen(aFileFormats[2].pFilterName), RTL_TEXTENCODING_UTF8) ;
1001 2 : rtl::OUString aFileName;
1002 2 : createFileURL(aFileNameBase, aFileExtension, aFileName);
1003 2 : rtl::OUString aFilterType(aFileFormats[2].pTypeName, strlen(aFileFormats[2].pTypeName), RTL_TEXTENCODING_UTF8);
1004 2 : std::cout << aFileFormats[2].pName << " Test" << std::endl;
1005 2 : unsigned int nFormatType = aFileFormats[2].nFormatType;
1006 2 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
1007 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
1008 2 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
1009 2 : xDocSh->DoHardRecalc(true);
1010 :
1011 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load bugFixes.xlsx", xDocSh.Is());
1012 2 : ScDocument* pDoc = xDocSh->GetDocument();
1013 2 : CPPUNIT_ASSERT_MESSAGE("No Document", pDoc); //remove with first test
1014 2 : xDocSh->DoClose();
1015 2 : }
1016 :
1017 : namespace {
1018 :
1019 8 : void checkMergedCells( ScDocument* pDoc, const ScAddress& rStartAddress,
1020 : const ScAddress& rExpectedEndAddress )
1021 : {
1022 8 : SCCOL nActualEndCol = rStartAddress.Col();
1023 8 : SCROW nActualEndRow = rStartAddress.Row();
1024 8 : pDoc->ExtendMerge( rStartAddress.Col(), rStartAddress.Row(),
1025 16 : nActualEndCol, nActualEndRow, rStartAddress.Tab(), false );
1026 8 : rtl::OString sTab = rtl::OString::valueOf( static_cast<sal_Int32>(rStartAddress.Tab() + 1) );
1027 8 : rtl::OString msg = "Merged cells are not correctly imported on sheet" + sTab;
1028 8 : rtl::OString msgCol = msg + "; end col";
1029 8 : rtl::OString msgRow = msg + "; end row";
1030 8 : CPPUNIT_ASSERT_EQUAL_MESSAGE( msgCol.pData->buffer, rExpectedEndAddress.Col(), nActualEndCol );
1031 8 : CPPUNIT_ASSERT_EQUAL_MESSAGE( msgRow.pData->buffer, rExpectedEndAddress.Row(), nActualEndRow );
1032 8 : }
1033 :
1034 : }
1035 :
1036 2 : void ScFiltersTest::testMergedCellsODS()
1037 : {
1038 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("merged."));
1039 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, 0);
1040 :
1041 2 : ScDocument* pDoc = xDocSh->GetDocument();
1042 :
1043 : //check sheet1 content
1044 2 : rtl::OUString aCSVFileName1;
1045 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("merged1.")), aCSVFileName1);
1046 2 : testFile(aCSVFileName1, pDoc, 0);
1047 :
1048 : //check sheet1 merged cells
1049 2 : checkMergedCells( pDoc, ScAddress( 0, 0, 0 ), ScAddress( 5, 11, 0 ) );
1050 2 : checkMergedCells( pDoc, ScAddress( 7, 2, 0 ), ScAddress( 9, 12, 0 ) );
1051 2 : checkMergedCells( pDoc, ScAddress( 3, 15, 0 ), ScAddress( 7, 23, 0 ) );
1052 :
1053 : //check sheet2 content
1054 2 : rtl::OUString aCSVFileName2;
1055 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("merged2.")), aCSVFileName2);
1056 2 : testFile(aCSVFileName2, pDoc, 1);
1057 :
1058 : //check sheet2 merged cells
1059 2 : checkMergedCells( pDoc, ScAddress( 4, 3, 1 ), ScAddress( 6, 15, 1 ) );
1060 :
1061 2 : xDocSh->DoClose();
1062 2 : }
1063 :
1064 2 : void ScFiltersTest::testRepeatedColumnsODS()
1065 : {
1066 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("repeatedColumns."));
1067 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, 0);
1068 :
1069 2 : ScDocument* pDoc = xDocSh->GetDocument();
1070 :
1071 : //text
1072 2 : rtl::OUString aCSVFileName1;
1073 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("repeatedColumns1.")), aCSVFileName1);
1074 2 : testFile(aCSVFileName1, pDoc, 0);
1075 :
1076 : //numbers
1077 2 : rtl::OUString aCSVFileName2;
1078 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("repeatedColumns2.")), aCSVFileName2);
1079 2 : testFile(aCSVFileName2, pDoc, 1);
1080 :
1081 2 : xDocSh->DoClose();
1082 2 : }
1083 :
1084 : namespace {
1085 :
1086 : //for cleaner passing of parameters
1087 4 : struct ValDataTestParams
1088 : {
1089 : ScValidationMode eValMode;
1090 : ScConditionMode eCondOp;
1091 : String aStrVal1, aStrVal2;
1092 : ScDocument* pDocument;
1093 : ScAddress aPosition;
1094 : String aErrorTitle, aErrorMessage;
1095 : ScValidErrorStyle eErrorStyle;
1096 : sal_uLong nExpectedIndex;
1097 :
1098 4 : ValDataTestParams( ScValidationMode eMode, ScConditionMode eOp,
1099 : String aExpr1, String aExpr2, ScDocument* pDoc,
1100 : ScAddress aPos, String aETitle, String aEMsg,
1101 : ScValidErrorStyle eEStyle, sal_uLong nIndex ):
1102 : eValMode(eMode), eCondOp(eOp), aStrVal1(aExpr1),
1103 : aStrVal2(aExpr2), pDocument(pDoc), aPosition(aPos),
1104 : aErrorTitle(aETitle), aErrorMessage(aEMsg),
1105 4 : eErrorStyle(eEStyle), nExpectedIndex(nIndex) { };
1106 : };
1107 :
1108 4 : void checkValiditationEntries( const ValDataTestParams& rVDTParams )
1109 : {
1110 4 : ScDocument* pDoc = rVDTParams.pDocument;
1111 :
1112 : //create expected data validation entry
1113 : ScValidationData aValData(
1114 : rVDTParams.eValMode, rVDTParams.eCondOp, rVDTParams.aStrVal1,
1115 4 : rVDTParams.aStrVal2, pDoc, rVDTParams.aPosition, EMPTY_STRING,
1116 4 : EMPTY_STRING, pDoc->GetStorageGrammar(), pDoc->GetStorageGrammar()
1117 8 : );
1118 4 : aValData.SetIgnoreBlank( true );
1119 4 : aValData.SetListType( 1 );
1120 4 : aValData.ResetInput();
1121 4 : aValData.SetError( rVDTParams.aErrorTitle, rVDTParams.aErrorMessage, rVDTParams.eErrorStyle );
1122 4 : aValData.SetSrcString( EMPTY_STRING );
1123 :
1124 : //get actual data validation entry from document
1125 4 : const ScValidationData* pValDataTest = pDoc->GetValidationEntry( rVDTParams.nExpectedIndex );
1126 :
1127 4 : sal_Int32 nCol( static_cast<sal_Int32>(rVDTParams.aPosition.Col()) );
1128 4 : sal_Int32 nRow( static_cast<sal_Int32>(rVDTParams.aPosition.Row()) );
1129 4 : sal_Int32 nTab( static_cast<sal_Int32>(rVDTParams.aPosition.Tab()) );
1130 4 : rtl::OStringBuffer sMsg("Data Validation Entry with base-cell-address: (");
1131 4 : sMsg.append(nCol).append(",").append(nRow).append(",").append(nTab).append(") was not imported correctly.");
1132 : //check if expected and actual data validation entries are equal
1133 4 : CPPUNIT_ASSERT_MESSAGE( sMsg.getStr(), pValDataTest && aValData.EqualEntries(*pValDataTest) );
1134 4 : }
1135 :
1136 4 : void checkCellValidity( const ScAddress& rValBaseAddr, const ScRange& rRange, const ScDocument* pDoc )
1137 : {
1138 4 : SCCOL nBCol( rValBaseAddr.Col() );
1139 4 : SCROW nBRow( rValBaseAddr.Row() );
1140 4 : SCTAB nTab( static_cast<const sal_Int32>(rValBaseAddr.Tab()) );
1141 : //get from the document the data validation entry we are checking against
1142 4 : const SfxUInt32Item* pItem = static_cast<const SfxUInt32Item*>(pDoc->GetAttr(nBCol, nBRow, nTab, ATTR_VALIDDATA) );
1143 4 : const ScValidationData* pValData = pDoc->GetValidationEntry( pItem->GetValue() );
1144 :
1145 : //check that each cell in the expected range is associated with the data validation entry
1146 16 : for(SCCOL i = rRange.aStart.Col(); i <= rRange.aEnd.Col(); ++i)
1147 : {
1148 72 : for(SCROW j = rRange.aStart.Row(); j <= rRange.aEnd.Row(); ++j)
1149 : {
1150 60 : const SfxUInt32Item* pItemTest = static_cast<const SfxUInt32Item*>( pDoc->GetAttr(i, j, nTab, ATTR_VALIDDATA) );
1151 60 : const ScValidationData* pValDataTest = pDoc->GetValidationEntry( pItemTest->GetValue() );
1152 : //prevent string operations for occurring unnecessarily
1153 60 : if(!(pValDataTest && pValData->GetKey() == pValDataTest->GetKey()))
1154 : {
1155 0 : sal_Int32 nCol = static_cast<const sal_Int32>(i);
1156 0 : sal_Int32 nRow = static_cast<const sal_Int32>(j);
1157 0 : sal_Int32 nTab32 = static_cast<const sal_Int32>(nTab);
1158 0 : rtl::OStringBuffer sMsg("\nData validation entry base-cell-address: (");
1159 0 : sMsg.append( static_cast<const sal_Int32>(nBCol) ).append(",");
1160 0 : sMsg.append( static_cast<const sal_Int32>(nBRow) ).append(",");
1161 0 : sMsg.append( nTab32 ).append(")\n");
1162 0 : sMsg.append("Cell: (").append(nCol).append(",").append(nRow).append(",").append(nTab32).append(")");
1163 0 : sal_uInt32 expectedKey(pValData->GetKey());
1164 0 : sal_uInt32 actualKey(-1);
1165 0 : if(pValDataTest)
1166 0 : actualKey = pValDataTest->GetKey();
1167 0 : CPPUNIT_ASSERT_EQUAL_MESSAGE(sMsg.getStr(), expectedKey, actualKey);
1168 : }
1169 : }
1170 : }
1171 4 : }
1172 :
1173 : }
1174 :
1175 2 : void ScFiltersTest::testDataValidityODS()
1176 : {
1177 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("dataValidity."));
1178 2 : ScDocShellRef xDocSh = loadDoc( aFileNameBase, 0);
1179 :
1180 2 : ScDocument* pDoc = xDocSh->GetDocument();
1181 :
1182 2 : ScAddress aValBaseAddr1( 2,6,0 ); //sheet1
1183 2 : ScAddress aValBaseAddr2( 2,3,1 ); //sheet2
1184 :
1185 : //sheet1's expected Data Validation Entry values
1186 : ValDataTestParams aVDTParams1(
1187 2 : SC_VALID_DECIMAL, SC_COND_GREATER, String("3.14"), EMPTY_STRING, pDoc,
1188 : aValBaseAddr1, String("Too small"),
1189 : String("The number you are trying to enter is not greater than 3.14! Are you sure you want to enter it anyway?"),
1190 : SC_VALERR_WARNING, 1
1191 4 : );
1192 : //sheet2's expected Data Validation Entry values
1193 : ValDataTestParams aVDTParams2(
1194 : SC_VALID_WHOLE, SC_COND_BETWEEN, String("1"), String("10"), pDoc,
1195 : aValBaseAddr2, String("Error sheet 2"),
1196 : String("Must be a whole number between 1 and 10."),
1197 : SC_VALERR_STOP, 2
1198 2 : );
1199 : //check each sheet's Data Validation Entries
1200 2 : checkValiditationEntries( aVDTParams1 );
1201 2 : checkValiditationEntries( aVDTParams2 );
1202 :
1203 : //expected ranges to be associated with data validity
1204 2 : ScRange aRange1( 2,2,0, 2,6,0 ); //sheet1
1205 2 : ScRange aRange2( 2,3,1, 6,7,1 ); //sheet2
1206 :
1207 : //check each sheet's cells for data validity
1208 2 : checkCellValidity( aValBaseAddr1, aRange1, pDoc );
1209 2 : checkCellValidity( aValBaseAddr2, aRange2, pDoc );
1210 :
1211 : //check each sheet's content
1212 2 : rtl::OUString aCSVFileName1;
1213 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("dataValidity1.")), aCSVFileName1);
1214 2 : testFile(aCSVFileName1, pDoc, 0);
1215 :
1216 2 : rtl::OUString aCSVFileName2;
1217 2 : createCSVPath(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("dataValidity2.")), aCSVFileName2);
1218 2 : testFile(aCSVFileName2, pDoc, 1);
1219 :
1220 2 : xDocSh->DoClose();
1221 2 : }
1222 :
1223 2 : void ScFiltersTest::testBrokenQuotesCSV()
1224 : {
1225 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("fdo48621_broken_quotes."));
1226 2 : rtl::OUString aFileExtension(aFileFormats[CSV].pName, strlen(aFileFormats[CSV].pName), RTL_TEXTENCODING_UTF8 );
1227 2 : rtl::OUString aFilterName(aFileFormats[CSV].pFilterName, strlen(aFileFormats[CSV].pFilterName), RTL_TEXTENCODING_UTF8) ;
1228 2 : rtl::OUString aFileName;
1229 2 : createFileURL(aFileNameBase, aFileExtension, aFileName);
1230 2 : rtl::OUString aFilterType(aFileFormats[CSV].pTypeName, strlen(aFileFormats[CSV].pTypeName), RTL_TEXTENCODING_UTF8);
1231 2 : std::cout << aFileFormats[CSV].pName << " Test" << std::endl;
1232 :
1233 2 : unsigned int nFormatType = aFileFormats[CSV].nFormatType;
1234 2 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
1235 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
1236 2 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
1237 :
1238 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load fdo48621_broken_quotes.csv", xDocSh.Is());
1239 2 : ScDocument* pDoc = xDocSh->GetDocument();
1240 2 : CPPUNIT_ASSERT_MESSAGE("No Document", pDoc); //remove with first test
1241 :
1242 2 : rtl::OUString aSheet2CSV(RTL_CONSTASCII_USTRINGPARAM("fdo48621_broken_quotes_exported."));
1243 2 : rtl::OUString aCSVPath;
1244 2 : createCSVPath( aSheet2CSV, aCSVPath );
1245 : // fdo#48621
1246 2 : testFile( aCSVPath, pDoc, 0, PureString);
1247 :
1248 2 : xDocSh->DoClose();
1249 2 : }
1250 :
1251 2 : void ScFiltersTest::testSharedFormulaXLSX()
1252 : {
1253 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("shared-formula."));
1254 2 : rtl::OUString aFileExtension(aFileFormats[XLSX].pName, strlen(aFileFormats[XLSX].pName), RTL_TEXTENCODING_UTF8 );
1255 2 : rtl::OUString aFilterName(aFileFormats[XLSX].pFilterName, strlen(aFileFormats[XLSX].pFilterName), RTL_TEXTENCODING_UTF8) ;
1256 2 : rtl::OUString aFileName;
1257 2 : createFileURL(aFileNameBase, aFileExtension, aFileName);
1258 2 : rtl::OUString aFilterType(aFileFormats[XLSX].pTypeName, strlen(aFileFormats[XLSX].pTypeName), RTL_TEXTENCODING_UTF8);
1259 2 : std::cout << aFileFormats[XLSX].pName << " Test" << std::endl;
1260 :
1261 2 : unsigned int nFormatType = aFileFormats[XLSX].nFormatType;
1262 2 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
1263 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
1264 2 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
1265 :
1266 2 : xDocSh->DoHardRecalc(true);
1267 :
1268 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load shared-formula.xlsx", xDocSh.Is());
1269 2 : ScDocument* pDoc = xDocSh->GetDocument();
1270 2 : CPPUNIT_ASSERT_MESSAGE("No Document", pDoc); //remove with first test
1271 :
1272 2 : rtl::OUString aCSVPath;
1273 2 : createCSVPath( aFileNameBase, aCSVPath );
1274 2 : testFile( aCSVPath, pDoc, 0 );
1275 :
1276 : //test some additional properties
1277 2 : ScRangeName* pName = pDoc->GetRangeName();
1278 4 : for (ScRangeName::iterator itr = pName->begin(); itr != pName->end(); ++itr)
1279 : {
1280 2 : CPPUNIT_ASSERT(itr->second->GetType() & RT_SHARED);
1281 : }
1282 :
1283 2 : xDocSh->DoClose();
1284 2 : }
1285 :
1286 2 : void ScFiltersTest::testCellValueXLSX()
1287 : {
1288 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("cell-value."));
1289 2 : rtl::OUString aFileExtension(aFileFormats[XLSX].pName, strlen(aFileFormats[XLSX].pName), RTL_TEXTENCODING_UTF8 );
1290 2 : rtl::OUString aFilterName(aFileFormats[XLSX].pFilterName, strlen(aFileFormats[XLSX].pFilterName), RTL_TEXTENCODING_UTF8) ;
1291 2 : rtl::OUString aFileName;
1292 2 : createFileURL(aFileNameBase, aFileExtension, aFileName);
1293 2 : rtl::OUString aFilterType(aFileFormats[XLSX].pTypeName, strlen(aFileFormats[XLSX].pTypeName), RTL_TEXTENCODING_UTF8);
1294 2 : std::cout << aFileFormats[XLSX].pName << " Test" << std::endl;
1295 :
1296 2 : unsigned int nFormatType = aFileFormats[XLSX].nFormatType;
1297 2 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
1298 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
1299 2 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
1300 :
1301 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load cell-value.xlsx", xDocSh.Is());
1302 2 : ScDocument* pDoc = xDocSh->GetDocument();
1303 2 : CPPUNIT_ASSERT_MESSAGE("No Document", pDoc); //remove with first test
1304 :
1305 2 : rtl::OUString aCSVPath;
1306 2 : createCSVPath( aFileNameBase, aCSVPath );
1307 2 : testFile( aCSVPath, pDoc, 0 );
1308 :
1309 2 : xDocSh->DoClose();
1310 2 : }
1311 :
1312 4 : void ScFiltersTest::testPassword_Impl(const rtl::OUString& aFileNameBase)
1313 : {
1314 4 : rtl::OUString aFileExtension(aFileFormats[0].pName, strlen(aFileFormats[0].pName), RTL_TEXTENCODING_UTF8 );
1315 4 : rtl::OUString aFilterName(aFileFormats[0].pFilterName, strlen(aFileFormats[0].pFilterName), RTL_TEXTENCODING_UTF8) ;
1316 4 : rtl::OUString aFileName;
1317 4 : createFileURL(aFileNameBase, aFileExtension, aFileName);
1318 4 : rtl::OUString aFilterType(aFileFormats[0].pTypeName, strlen(aFileFormats[0].pTypeName), RTL_TEXTENCODING_UTF8);
1319 :
1320 4 : sal_uInt32 nFormat = SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS;
1321 : SfxFilter* aFilter = new SfxFilter(
1322 : aFilterName,
1323 : rtl::OUString(), aFileFormats[0].nFormatType, nFormat, aFilterType, 0, rtl::OUString(),
1324 4 : rtl::OUString(), rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/scalc*")) );
1325 4 : aFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT);
1326 :
1327 4 : ScDocShellRef xDocSh = new ScDocShell;
1328 4 : SfxMedium* pMedium = new SfxMedium(aFileName, STREAM_STD_READWRITE);
1329 4 : SfxItemSet* pSet = pMedium->GetItemSet();
1330 4 : pSet->Put(SfxStringItem(SID_PASSWORD, rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("test"))));
1331 4 : pMedium->SetFilter(aFilter);
1332 4 : if (!xDocSh->DoLoad(pMedium))
1333 : {
1334 0 : xDocSh->DoClose();
1335 : // load failed.
1336 0 : xDocSh.Clear();
1337 : }
1338 :
1339 4 : CPPUNIT_ASSERT_MESSAGE("Failed to load password.ods", xDocSh.Is());
1340 4 : ScDocument* pDoc = xDocSh->GetDocument();
1341 4 : CPPUNIT_ASSERT_MESSAGE("No Document", pDoc); //remove with first test
1342 4 : xDocSh->DoClose();
1343 :
1344 4 : }
1345 :
1346 2 : void ScFiltersTest::testPasswordNew()
1347 : {
1348 : //tests opening a file with new password algorithm
1349 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("password."));
1350 2 : testPassword_Impl(aFileNameBase);
1351 2 : }
1352 :
1353 2 : void ScFiltersTest::testPasswordOld()
1354 : {
1355 : //tests opening a file with old password algorithm
1356 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("passwordOld."));
1357 2 : testPassword_Impl(aFileNameBase);
1358 2 : }
1359 :
1360 2 : void ScFiltersTest::testControlImport()
1361 : {
1362 2 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("singlecontrol."));
1363 2 : rtl::OUString aFileExtension(aFileFormats[XLSX].pName, strlen(aFileFormats[XLSX].pName), RTL_TEXTENCODING_UTF8 );
1364 2 : rtl::OUString aFilterName(aFileFormats[XLSX].pFilterName, strlen(aFileFormats[XLSX].pFilterName), RTL_TEXTENCODING_UTF8) ;
1365 2 : rtl::OUString aFileName;
1366 2 : createFileURL(aFileNameBase, aFileExtension, aFileName);
1367 2 : rtl::OUString aFilterType(aFileFormats[XLSX].pTypeName, strlen(aFileFormats[XLSX].pTypeName), RTL_TEXTENCODING_UTF8);
1368 2 : std::cout << aFileFormats[XLSX].pName << " Test" << std::endl;
1369 :
1370 2 : unsigned int nFormatType = aFileFormats[XLSX].nFormatType;
1371 2 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
1372 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
1373 2 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
1374 :
1375 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load cell-value.xlsx", xDocSh.Is());
1376 :
1377 2 : uno::Reference< frame::XModel > xModel = xDocSh->GetModel();
1378 2 : uno::Reference< sheet::XSpreadsheetDocument > xDoc(xModel, UNO_QUERY_THROW);
1379 2 : uno::Reference< container::XIndexAccess > xIA(xDoc->getSheets(), UNO_QUERY_THROW);
1380 2 : uno::Reference< drawing::XDrawPageSupplier > xDrawPageSupplier( xIA->getByIndex(0), UNO_QUERY_THROW);
1381 2 : uno::Reference< container::XIndexAccess > xIA_DrawPage(xDrawPageSupplier->getDrawPage(), UNO_QUERY_THROW);
1382 2 : uno::Reference< drawing::XControlShape > xControlShape(xIA_DrawPage->getByIndex(0), UNO_QUERY_THROW);
1383 :
1384 2 : CPPUNIT_ASSERT(xControlShape.is());
1385 2 : xDocSh->DoClose();
1386 2 : }
1387 :
1388 2 : void ScFiltersTest::testNumberFormatHTML()
1389 : {
1390 2 : OUString aFileNameBase("numberformat.");
1391 2 : OUString aFileExt = OUString::createFromAscii(aFileFormats[HTML].pName);
1392 2 : OUString aFilterName = OUString::createFromAscii(aFileFormats[HTML].pFilterName);
1393 2 : OUString aFilterType = OUString::createFromAscii(aFileFormats[HTML].pTypeName);
1394 :
1395 2 : rtl::OUString aFileName;
1396 2 : createFileURL(aFileNameBase, aFileExt, aFileName);
1397 :
1398 2 : unsigned int nFormatType = aFileFormats[HTML].nFormatType;
1399 2 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
1400 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
1401 2 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
1402 :
1403 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load numberformat.html", xDocSh.Is());
1404 :
1405 2 : ScDocument* pDoc = xDocSh->GetDocument();
1406 :
1407 : // Check the header just in case.
1408 2 : CPPUNIT_ASSERT_MESSAGE("Cell value is not as expected", pDoc->GetString(0, 0, 0) == "Product");
1409 2 : CPPUNIT_ASSERT_MESSAGE("Cell value is not as expected", pDoc->GetString(1, 0, 0) == "Price");
1410 2 : CPPUNIT_ASSERT_MESSAGE("Cell value is not as expected", pDoc->GetString(2, 0, 0) == "Note");
1411 :
1412 : // B2 should be imported as a value cell.
1413 2 : bool bHasValue = pDoc->HasValueData(1, 1, 0);
1414 2 : CPPUNIT_ASSERT_MESSAGE("Fail to import number as a value cell.", bHasValue);
1415 2 : CPPUNIT_ASSERT_MESSAGE("Incorrect value.", pDoc->GetValue(1, 1, 0) == 199.98);
1416 :
1417 2 : xDocSh->DoClose();
1418 2 : }
1419 :
1420 2 : void ScFiltersTest::testNumberFormatCSV()
1421 : {
1422 2 : OUString aFileNameBase("numberformat.");
1423 2 : OUString aFileExt = OUString::createFromAscii(aFileFormats[CSV].pName);
1424 2 : OUString aFilterName = OUString::createFromAscii(aFileFormats[CSV].pFilterName);
1425 2 : OUString aFilterType = OUString::createFromAscii(aFileFormats[CSV].pTypeName);
1426 :
1427 2 : rtl::OUString aFileName;
1428 2 : createFileURL(aFileNameBase, aFileExt, aFileName);
1429 :
1430 2 : unsigned int nFormatType = aFileFormats[CSV].nFormatType;
1431 2 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
1432 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
1433 2 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
1434 :
1435 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load numberformat.html", xDocSh.Is());
1436 :
1437 2 : ScDocument* pDoc = xDocSh->GetDocument();
1438 :
1439 : // Check the header just in case.
1440 2 : CPPUNIT_ASSERT_MESSAGE("Cell value is not as expected", pDoc->GetString(0, 0, 0) == "Product");
1441 2 : CPPUNIT_ASSERT_MESSAGE("Cell value is not as expected", pDoc->GetString(1, 0, 0) == "Price");
1442 2 : CPPUNIT_ASSERT_MESSAGE("Cell value is not as expected", pDoc->GetString(2, 0, 0) == "Note");
1443 :
1444 : // B2 should be imported as a value cell.
1445 2 : bool bHasValue = pDoc->HasValueData(1, 1, 0);
1446 2 : CPPUNIT_ASSERT_MESSAGE("Fail to import number as a value cell.", bHasValue);
1447 2 : CPPUNIT_ASSERT_MESSAGE("Incorrect value.", pDoc->GetValue(1, 1, 0) == 199.98);
1448 :
1449 2 : xDocSh->DoClose();
1450 2 : }
1451 :
1452 2 : void ScFiltersTest::testCellAnchoredShapesODS()
1453 : {
1454 2 : OUString aFileNameBase("cell-anchored-shapes.");
1455 2 : OUString aFileExt = OUString::createFromAscii(aFileFormats[ODS].pName);
1456 2 : OUString aFilterName = OUString::createFromAscii(aFileFormats[ODS].pFilterName);
1457 2 : OUString aFilterType = OUString::createFromAscii(aFileFormats[ODS].pTypeName);
1458 :
1459 2 : rtl::OUString aFileName;
1460 2 : createFileURL(aFileNameBase, aFileExt, aFileName);
1461 :
1462 2 : unsigned int nFormatType = aFileFormats[ODS].nFormatType;
1463 2 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
1464 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
1465 2 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
1466 :
1467 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load cell-anchored-shapes.ods", xDocSh.Is());
1468 :
1469 : // There are two cell-anchored objects on the first sheet.
1470 2 : ScDocument* pDoc = xDocSh->GetDocument();
1471 :
1472 2 : CPPUNIT_ASSERT_MESSAGE("There should be at least one sheet.", pDoc->GetTableCount() > 0);
1473 :
1474 2 : ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1475 2 : SdrPage* pPage = pDrawLayer->GetPage(0);
1476 2 : CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage);
1477 2 : sal_uIntPtr nCount = pPage->GetObjCount();
1478 2 : CPPUNIT_ASSERT_MESSAGE("There should be 2 objects.", nCount == 2);
1479 6 : for (sal_uIntPtr i = 0; i < nCount; ++i)
1480 : {
1481 4 : SdrObject* pObj = pPage->GetObj(i);
1482 4 : CPPUNIT_ASSERT_MESSAGE("Failed to get drawing object.", pObj);
1483 4 : ScDrawObjData* pData = ScDrawLayer::GetObjData(pObj, false);
1484 4 : CPPUNIT_ASSERT_MESSAGE("Failed to retrieve user data for this object.", pData);
1485 4 : CPPUNIT_ASSERT_MESSAGE("Bounding rectangle should have been calculated upon import.", !pData->maLastRect.IsEmpty());
1486 : }
1487 :
1488 2 : xDocSh->DoClose();
1489 2 : }
1490 :
1491 : namespace {
1492 :
1493 36 : class FindDimByName : std::unary_function<const ScDPSaveDimension*, bool>
1494 : {
1495 : OUString maName;
1496 : public:
1497 12 : FindDimByName(const OUString& rName) : maName(rName) {}
1498 :
1499 18 : bool operator() (const ScDPSaveDimension* p) const
1500 : {
1501 18 : return p && p->GetName() == maName;
1502 : }
1503 : };
1504 :
1505 12 : bool hasDimension(const std::vector<const ScDPSaveDimension*>& rDims, const OUString& aName)
1506 : {
1507 12 : return std::find_if(rDims.begin(), rDims.end(), FindDimByName(aName)) != rDims.end();
1508 : }
1509 :
1510 : }
1511 :
1512 2 : void ScFiltersTest::testPivotTableBasicODS()
1513 : {
1514 2 : OUString aFileNameBase("pivot-table-basic.");
1515 2 : OUString aFileExt = OUString::createFromAscii(aFileFormats[ODS].pName);
1516 2 : OUString aFilterName = OUString::createFromAscii(aFileFormats[ODS].pFilterName);
1517 2 : OUString aFilterType = OUString::createFromAscii(aFileFormats[ODS].pTypeName);
1518 :
1519 2 : rtl::OUString aFileName;
1520 2 : createFileURL(aFileNameBase, aFileExt, aFileName);
1521 :
1522 2 : unsigned int nFormatType = aFileFormats[ODS].nFormatType;
1523 2 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
1524 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
1525 2 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
1526 :
1527 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load pivot-table-basic.ods", xDocSh.Is());
1528 :
1529 2 : ScDocument* pDoc = xDocSh->GetDocument();
1530 2 : CPPUNIT_ASSERT_MESSAGE("There should be exactly two sheets.", pDoc->GetTableCount() == 2);
1531 :
1532 2 : ScDPCollection* pDPs = pDoc->GetDPCollection();
1533 2 : CPPUNIT_ASSERT_MESSAGE("Failed to get a live ScDPCollection instance.", pDPs);
1534 2 : CPPUNIT_ASSERT_MESSAGE("There should be exactly one pivot table instance.", pDPs->GetCount() == 1);
1535 :
1536 2 : const ScDPObject* pDPObj = (*pDPs)[0];
1537 2 : CPPUNIT_ASSERT_MESSAGE("Failed to get an pivot table object.", pDPObj);
1538 2 : const ScDPSaveData* pSaveData = pDPObj->GetSaveData();
1539 2 : CPPUNIT_ASSERT_MESSAGE("Failed to get ScDPSaveData instance.", pSaveData);
1540 2 : std::vector<const ScDPSaveDimension*> aDims;
1541 :
1542 : // Row fields
1543 2 : pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_ROW, aDims);
1544 2 : CPPUNIT_ASSERT_MESSAGE("There should be exactly 3 row fields (2 normal dimensions and 1 layout dimension).", aDims.size() == 3);
1545 2 : CPPUNIT_ASSERT_MESSAGE("Dimension expected, but not found.", hasDimension(aDims, "Row1"));
1546 2 : CPPUNIT_ASSERT_MESSAGE("Dimension expected, but not found.", hasDimension(aDims, "Row2"));
1547 2 : const ScDPSaveDimension* pDataLayout = pSaveData->GetExistingDataLayoutDimension();
1548 4 : CPPUNIT_ASSERT_MESSAGE("There should be a data layout field as a row field.",
1549 2 : pDataLayout && pDataLayout->GetOrientation() == sheet::DataPilotFieldOrientation_ROW);
1550 :
1551 : // Column fields
1552 2 : pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_COLUMN, aDims);
1553 2 : CPPUNIT_ASSERT_MESSAGE("There should be exactly 2 column fields.", aDims.size() == 2);
1554 2 : CPPUNIT_ASSERT_MESSAGE("Dimension expected, but not found.", hasDimension(aDims, "Col1"));
1555 2 : CPPUNIT_ASSERT_MESSAGE("Dimension expected, but not found.", hasDimension(aDims, "Col2"));
1556 :
1557 : // Page fields
1558 2 : pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_PAGE, aDims);
1559 2 : CPPUNIT_ASSERT_MESSAGE("There should be exactly 2 page fields.", aDims.size() == 2);
1560 2 : CPPUNIT_ASSERT_MESSAGE("Dimension expected, but not found.", hasDimension(aDims, "Page1"));
1561 2 : CPPUNIT_ASSERT_MESSAGE("Dimension expected, but not found.", hasDimension(aDims, "Page2"));
1562 :
1563 : // Check the data field.
1564 2 : pSaveData->GetAllDimensionsByOrientation(sheet::DataPilotFieldOrientation_DATA, aDims);
1565 2 : CPPUNIT_ASSERT_MESSAGE("There should be exactly 1 data field.", aDims.size() == 1);
1566 2 : const ScDPSaveDimension* pDim = aDims.back();
1567 2 : CPPUNIT_ASSERT_MESSAGE("Function for the data field should be COUNT.", pDim->GetFunction() == sheet::GeneralFunction_COUNT);
1568 :
1569 2 : xDocSh->DoClose();
1570 2 : }
1571 :
1572 : namespace {
1573 :
1574 0 : void testColorScaleFormat_Impl(const rtl::OUString& rFilePath, const ScConditionalFormat* pFormat)
1575 : {
1576 0 : rtl::OUStringBuffer aBuf;
1577 0 : CPPUNIT_ASSERT(pFormat);
1578 0 : pFormat->dumpInfo(aBuf);
1579 0 : rtl::OUString aString = aBuf.makeStringAndClear();
1580 0 : std::string aStdString;
1581 0 : loadFile(rFilePath, aStdString);
1582 0 : rtl::OUString aRefString = rtl::OUString::createFromAscii(aStdString.c_str());
1583 0 : CPPUNIT_ASSERT_EQUAL(aRefString, aString);
1584 0 : }
1585 :
1586 0 : void testColorScale_Impl(ScDocument* pDoc, const rtl::OUString& aBaseString)
1587 : {
1588 : // first color scale
1589 : {
1590 0 : const ScConditionalFormat* pFormat = pDoc->GetCondFormat(1,1,0);
1591 0 : rtl::OUString aFilePath = aBaseString + rtl::OUString("colorScale_1.txt");
1592 0 : testColorScaleFormat_Impl(aFilePath, pFormat);
1593 : }
1594 :
1595 : // second cond format
1596 : {
1597 0 : const ScConditionalFormat* pFormat = pDoc->GetCondFormat(4,1,0);
1598 0 : rtl::OUString aFilePath = aBaseString + rtl::OUString("colorScale_2.txt");
1599 0 : testColorScaleFormat_Impl(aFilePath, pFormat);
1600 : }
1601 :
1602 : // third cond format
1603 : {
1604 0 : const ScConditionalFormat* pFormat = pDoc->GetCondFormat(7,1,0);
1605 0 : rtl::OUString aFilePath = aBaseString + rtl::OUString("colorScale_3.txt");
1606 0 : testColorScaleFormat_Impl(aFilePath, pFormat);
1607 : }
1608 :
1609 : // forth cond format
1610 : {
1611 0 : const ScConditionalFormat* pFormat = pDoc->GetCondFormat(10,1,0);
1612 0 : rtl::OUString aFilePath = aBaseString + rtl::OUString("colorScale_4.txt");
1613 0 : testColorScaleFormat_Impl(aFilePath, pFormat);
1614 : }
1615 0 : }
1616 :
1617 : }
1618 :
1619 0 : void ScFiltersTest::testColorScaleODS()
1620 : {
1621 0 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("colorScale."));
1622 0 : rtl::OUString aFileExtension(aFileFormats[ODS].pName, strlen(aFileFormats[ODS].pName), RTL_TEXTENCODING_UTF8 );
1623 0 : rtl::OUString aFilterName(aFileFormats[ODS].pFilterName, strlen(aFileFormats[ODS].pFilterName), RTL_TEXTENCODING_UTF8) ;
1624 0 : rtl::OUString aFileName;
1625 0 : createFileURL(aFileNameBase, aFileExtension, aFileName);
1626 0 : rtl::OUString aFilterType(aFileFormats[ODS].pTypeName, strlen(aFileFormats[ODS].pTypeName), RTL_TEXTENCODING_UTF8);
1627 0 : std::cout << aFileFormats[ODS].pName << " Test" << std::endl;
1628 :
1629 0 : unsigned int nFormatType = aFileFormats[ODS].nFormatType;
1630 0 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
1631 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
1632 0 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
1633 :
1634 0 : CPPUNIT_ASSERT_MESSAGE("Failed to load colorScale.ods", xDocSh.Is());
1635 :
1636 0 : ScDocument* pDoc = xDocSh->GetDocument();
1637 :
1638 0 : rtl::OUStringBuffer aBuffer(getSrcRootPath());
1639 0 : aBuffer.append(m_aBaseString).append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/reference/")));
1640 0 : testColorScale_Impl(pDoc, aBuffer.makeStringAndClear());
1641 0 : }
1642 :
1643 0 : void ScFiltersTest::testColorScaleXLSX()
1644 : {
1645 0 : const rtl::OUString aFileNameBase(RTL_CONSTASCII_USTRINGPARAM("colorScale."));
1646 0 : rtl::OUString aFileExtension(aFileFormats[XLSX].pName, strlen(aFileFormats[XLSX].pName), RTL_TEXTENCODING_UTF8 );
1647 0 : rtl::OUString aFilterName(aFileFormats[XLSX].pFilterName, strlen(aFileFormats[XLSX].pFilterName), RTL_TEXTENCODING_UTF8) ;
1648 0 : rtl::OUString aFileName;
1649 0 : createFileURL(aFileNameBase, aFileExtension, aFileName);
1650 0 : rtl::OUString aFilterType(aFileFormats[XLSX].pTypeName, strlen(aFileFormats[XLSX].pTypeName), RTL_TEXTENCODING_UTF8);
1651 0 : std::cout << aFileFormats[XLSX].pName << " Test" << std::endl;
1652 :
1653 0 : unsigned int nFormatType = aFileFormats[XLSX].nFormatType;
1654 0 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
1655 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
1656 0 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
1657 :
1658 0 : CPPUNIT_ASSERT_MESSAGE("Failed to load colorScale.xlsx", xDocSh.Is());
1659 :
1660 0 : ScDocument* pDoc = xDocSh->GetDocument();
1661 :
1662 0 : rtl::OUStringBuffer aBuffer(getSrcRootPath());
1663 0 : aBuffer.append(m_aBaseString).append(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/reference/")));
1664 0 : testColorScale_Impl(pDoc, aBuffer.makeStringAndClear());
1665 0 : }
1666 :
1667 2 : void ScFiltersTest::testDataBarODS()
1668 : {
1669 2 : }
1670 :
1671 2 : void ScFiltersTest::testNewCondFormat()
1672 : {
1673 2 : const rtl::OUString aFileNameBase("new_cond_format_test.");
1674 2 : rtl::OUString aFileExtension(aFileFormats[XLSX].pName, strlen(aFileFormats[XLSX].pName), RTL_TEXTENCODING_UTF8 );
1675 2 : rtl::OUString aFilterName(aFileFormats[XLSX].pFilterName, strlen(aFileFormats[XLSX].pFilterName), RTL_TEXTENCODING_UTF8) ;
1676 2 : rtl::OUString aFileName;
1677 2 : createFileURL(aFileNameBase, aFileExtension, aFileName);
1678 2 : rtl::OUString aFilterType(aFileFormats[XLSX].pTypeName, strlen(aFileFormats[XLSX].pTypeName), RTL_TEXTENCODING_UTF8);
1679 2 : std::cout << aFileFormats[XLSX].pName << " Test" << std::endl;
1680 :
1681 2 : unsigned int nFormatType = aFileFormats[XLSX].nFormatType;
1682 2 : unsigned int nClipboardId = nFormatType ? SFX_FILTER_IMPORT | SFX_FILTER_USESOPTIONS : 0;
1683 : ScDocShellRef xDocSh = load(aFilterName, aFileName, rtl::OUString(), aFilterType,
1684 2 : nFormatType, nClipboardId, SOFFICE_FILEFORMAT_CURRENT);
1685 :
1686 2 : CPPUNIT_ASSERT_MESSAGE("Failed to load new_cond_format_test.xlsx", xDocSh.Is());
1687 :
1688 2 : ScDocument* pDoc = xDocSh->GetDocument();
1689 :
1690 2 : rtl::OUString aCSVFile("new_cond_format_test.");
1691 2 : rtl::OUString aCSVPath;
1692 2 : createCSVPath( aCSVFile, aCSVPath );
1693 2 : testCondFile(aCSVPath, pDoc, 0);
1694 2 : }
1695 :
1696 72 : ScFiltersTest::ScFiltersTest()
1697 72 : : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sc/qa/unit/data"))
1698 : {
1699 72 : }
1700 :
1701 72 : void ScFiltersTest::setUp()
1702 : {
1703 72 : test::BootstrapFixture::setUp();
1704 :
1705 : // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
1706 : // which is a private symbol to us, gets called
1707 : m_xCalcComponent =
1708 144 : getMultiServiceFactory()->createInstance(rtl::OUString(
1709 72 : RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Calc.SpreadsheetDocument")));
1710 72 : CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is());
1711 72 : }
1712 :
1713 72 : void ScFiltersTest::tearDown()
1714 : {
1715 72 : uno::Reference< lang::XComponent >( m_xCalcComponent, UNO_QUERY_THROW )->dispose();
1716 72 : test::BootstrapFixture::tearDown();
1717 72 : }
1718 :
1719 2 : CPPUNIT_TEST_SUITE_REGISTRATION(ScFiltersTest);
1720 :
1721 8 : CPPUNIT_PLUGIN_IMPLEMENT();
1722 :
1723 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|