Avoid potential negative array index access to cached text.
[LibreOffice.git] / sc / qa / unit / subsequent_export_test3.cxx
blob1c4f5760bf06f78cb2986bfc514fe78db30a5e77
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <officecfg/Office/Common.hxx>
12 #include "helper/debughelper.hxx"
14 #include "helper/qahelper.hxx"
15 #include "helper/shared_test_impl.hxx"
17 #include <userdat.hxx>
18 #include <tokenstringcontext.hxx>
19 #include <chgtrack.hxx>
20 #include <scmod.hxx>
22 #include <svx/svdpage.hxx>
23 #include <svx/svdograf.hxx>
24 #include <svx/svdomeas.hxx>
25 #include <svl/zformat.hxx>
26 #include <svl/numformat.hxx>
27 #include <tabprotection.hxx>
28 #include <editeng/borderline.hxx>
29 #include <unotools/tempfile.hxx>
30 #include <unotools/useroptions.hxx>
31 #include <sfx2/docfile.hxx>
32 #include <tools/datetime.hxx>
34 #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
35 #include <com/sun/star/awt/XBitmap.hpp>
36 #include <com/sun/star/graphic/GraphicType.hpp>
38 using namespace ::com::sun::star;
39 using namespace ::com::sun::star::uno;
40 using ::std::cerr;
41 using ::std::endl;
43 class ScExportTest3 : public ScModelTestBase
45 public:
46 ScExportTest3()
47 : ScModelTestBase("sc/qa/unit/data")
51 protected:
52 void testCeilingFloor(const OUString& sFormatType);
53 void testFunctionsExcel2010(const OUString& sFormatType);
56 CPPUNIT_TEST_FIXTURE(ScExportTest3, testBordersExchangeXLSX)
58 // Document: sc/qa/unit/data/README.cellborders
60 // short name for the table
61 const SvxBorderLineStyle None = SvxBorderLineStyle::NONE;
62 const SvxBorderLineStyle Solid = SvxBorderLineStyle::SOLID;
63 const SvxBorderLineStyle Dotted = SvxBorderLineStyle::DOTTED;
64 const SvxBorderLineStyle Dashed = SvxBorderLineStyle::DASHED;
65 const SvxBorderLineStyle FineDash = SvxBorderLineStyle::FINE_DASHED;
66 const SvxBorderLineStyle DashDot = SvxBorderLineStyle::DASH_DOT;
67 const SvxBorderLineStyle DashDoDo = SvxBorderLineStyle::DASH_DOT_DOT;
68 const SvxBorderLineStyle DoubThin = SvxBorderLineStyle::DOUBLE_THIN;
70 const size_t nMaxCol = 18;
71 const size_t nMaxRow = 7;
73 static struct
75 SvxBorderLineStyle BorderStyleTop, BorderStyleBottom;
76 tools::Long WidthTop, WidthBottom;
77 } aCheckBorderWidth[nMaxCol][nMaxRow]
78 = { /* Width */
79 /* 0,05 */ { { Solid, Solid, 1, 1 }, // SOLID
80 { Dotted, Dotted, 15, 15 }, // DOTTED
81 { Dotted, Dotted, 15, 15 }, // DASHED
82 { FineDash, FineDash, 15, 15 }, // FINE_DASHED
83 { FineDash, FineDash, 15, 15 }, // DASH_DOT
84 { FineDash, FineDash, 15, 15 }, // DASH_DOT_DOT
85 { None, None, 0, 0 } }, // DOUBLE_THIN
86 /* 0,25 */
87 { { Solid, Solid, 1, 1 },
88 { Dotted, Dotted, 15, 15 },
89 { Dotted, Dotted, 15, 15 },
90 { FineDash, FineDash, 15, 15 },
91 { FineDash, FineDash, 15, 15 },
92 { FineDash, FineDash, 15, 15 },
93 { None, None, 0, 0 } },
94 /* 0,50 */
95 { { Solid, Solid, 1, 1 },
96 { Dotted, Dotted, 15, 15 },
97 { Dotted, Dotted, 15, 15 },
98 { FineDash, FineDash, 15, 15 },
99 { FineDash, FineDash, 15, 15 },
100 { FineDash, FineDash, 15, 15 },
101 { None, None, 0, 0 } },
102 /* 0,75 */
103 { { Solid, Solid, 15, 15 },
104 { Dotted, Dotted, 15, 15 },
105 { FineDash, FineDash, 15, 15 },
106 { FineDash, FineDash, 15, 15 },
107 { DashDot, DashDot, 15, 15 },
108 { DashDoDo, DashDoDo, 15, 15 },
109 { DoubThin, DoubThin, 35, 35 } },
110 /* 1,00 */
111 { { Solid, Solid, 15, 15 },
112 { Dotted, Dotted, 15, 15 },
113 { FineDash, FineDash, 15, 15 },
114 { FineDash, FineDash, 15, 15 },
115 { DashDot, DashDot, 15, 15 },
116 { DashDoDo, DashDoDo, 15, 15 },
117 { DoubThin, DoubThin, 35, 35 } },
118 /* 1,25 */
119 { { Solid, Solid, 15, 15 },
120 { Dotted, Dotted, 15, 15 },
121 { FineDash, FineDash, 15, 15 },
122 { FineDash, FineDash, 15, 15 },
123 { DashDot, DashDot, 15, 15 },
124 { DashDoDo, DashDoDo, 15, 15 },
125 { DoubThin, DoubThin, 35, 35 } },
126 /* 1,50 */
127 { { Solid, Solid, 15, 15 },
128 { Dotted, Dotted, 15, 15 },
129 { FineDash, FineDash, 15, 15 },
130 { FineDash, FineDash, 15, 15 },
131 { DashDot, DashDot, 15, 15 },
132 { DashDoDo, DashDoDo, 15, 15 },
133 { DoubThin, DoubThin, 35, 35 } },
135 /* 1,75 */
136 { { Solid, Solid, 35, 35 },
137 { FineDash, FineDash, 35, 35 },
138 { Dashed, Dashed, 35, 35 },
139 { FineDash, FineDash, 35, 35 },
140 { DashDot, DashDot, 35, 35 },
141 { DashDoDo, DashDoDo, 35, 35 },
142 { DoubThin, DoubThin, 35, 35 } },
143 /* 2,00 */
144 { { Solid, Solid, 35, 35 },
145 { FineDash, FineDash, 35, 35 },
146 { Dashed, Dashed, 35, 35 },
147 { FineDash, FineDash, 35, 35 },
148 { DashDot, DashDot, 35, 35 },
149 { DashDoDo, DashDoDo, 35, 35 },
150 { DoubThin, DoubThin, 35, 35 } },
151 /* 2,25 */
152 { { Solid, Solid, 35, 35 },
153 { FineDash, FineDash, 35, 35 },
154 { Dashed, Dashed, 35, 35 },
155 { FineDash, FineDash, 35, 35 },
156 { DashDot, DashDot, 35, 35 },
157 { DashDoDo, DashDoDo, 35, 35 },
158 { DoubThin, DoubThin, 35, 35 } },
160 /* 2,50 */
161 { { Solid, Solid, 50, 50 },
162 { FineDash, FineDash, 35, 35 },
163 { Dashed, Dashed, 35, 35 },
164 { FineDash, FineDash, 35, 35 },
165 { DashDot, DashDot, 35, 35 },
166 { DashDoDo, DashDoDo, 35, 35 },
167 { DoubThin, DoubThin, 35, 35 } },
168 /* 2,75 */
169 { { Solid, Solid, 50, 50 },
170 { FineDash, FineDash, 35, 35 },
171 { Dashed, Dashed, 35, 35 },
172 { FineDash, FineDash, 35, 35 },
173 { DashDot, DashDot, 35, 35 },
174 { DashDoDo, DashDoDo, 35, 35 },
175 { DoubThin, DoubThin, 35, 35 } },
176 /* 3,00 */
177 { { Solid, Solid, 50, 50 },
178 { FineDash, FineDash, 35, 35 },
179 { Dashed, Dashed, 35, 35 },
180 { FineDash, FineDash, 35, 35 },
181 { DashDot, DashDot, 35, 35 },
182 { DashDoDo, DashDoDo, 35, 35 },
183 { DoubThin, DoubThin, 35, 35 } },
184 /* 3,50 */
185 { { Solid, Solid, 50, 50 },
186 { FineDash, FineDash, 35, 35 },
187 { Dashed, Dashed, 35, 35 },
188 { FineDash, FineDash, 35, 35 },
189 { DashDot, DashDot, 35, 35 },
190 { DashDoDo, DashDoDo, 35, 35 },
191 { DoubThin, DoubThin, 35, 35 } },
192 /* 4,00 */
193 { { Solid, Solid, 50, 50 },
194 { FineDash, FineDash, 35, 35 },
195 { Dashed, Dashed, 35, 35 },
196 { FineDash, FineDash, 35, 35 },
197 { DashDot, DashDot, 35, 35 },
198 { DashDoDo, DashDoDo, 35, 35 },
199 { DoubThin, DoubThin, 35, 35 } },
200 /* 5,00 */
201 { { Solid, Solid, 50, 50 },
202 { FineDash, FineDash, 35, 35 },
203 { Dashed, Dashed, 35, 35 },
204 { FineDash, FineDash, 35, 35 },
205 { DashDot, DashDot, 35, 35 },
206 { DashDoDo, DashDoDo, 35, 35 },
207 { DoubThin, DoubThin, 35, 35 } },
208 /* 7,00 */
209 { { Solid, Solid, 50, 50 },
210 { FineDash, FineDash, 35, 35 },
211 { Dashed, Dashed, 35, 35 },
212 { FineDash, FineDash, 35, 35 },
213 { DashDot, DashDot, 35, 35 },
214 { DashDoDo, DashDoDo, 35, 35 },
215 { DoubThin, DoubThin, 35, 35 } },
216 /* 9,00 */
217 { { Solid, Solid, 50, 50 },
218 { FineDash, FineDash, 35, 35 },
219 { Dashed, Dashed, 35, 35 },
220 { FineDash, FineDash, 35, 35 },
221 { DashDot, DashDot, 35, 35 },
222 { DashDoDo, DashDoDo, 35, 35 },
223 { DoubThin, DoubThin, 35, 35 } }
226 createScDoc("ods/test_borders_export.ods");
228 saveAndReload("Calc Office Open XML");
229 ScDocument* pDoc = getScDoc();
231 for (size_t nCol = 0; nCol < nMaxCol; ++nCol)
233 for (size_t nRow = 0; nRow < nMaxRow; ++nRow)
235 const editeng::SvxBorderLine* pLineTop = nullptr;
236 const editeng::SvxBorderLine* pLineBottom = nullptr;
237 pDoc->GetBorderLines(nCol + 2, (nRow * 2) + 8, 0, nullptr, &pLineTop, nullptr,
238 &pLineBottom);
239 if ((nCol < 3) && (nRow == 6))
240 { // in this range no lines since minimum size to create a double is 0.5
241 CPPUNIT_ASSERT(!pLineTop);
242 CPPUNIT_ASSERT(!pLineBottom);
243 continue;
245 else
247 CPPUNIT_ASSERT(pLineTop);
248 CPPUNIT_ASSERT(pLineBottom);
251 CPPUNIT_ASSERT_EQUAL_MESSAGE("Top Border-Line-Style wrong",
252 aCheckBorderWidth[nCol][nRow].BorderStyleTop,
253 pLineTop->GetBorderLineStyle());
254 CPPUNIT_ASSERT_EQUAL_MESSAGE("Bottom Border-Line-Style wrong",
255 aCheckBorderWidth[nCol][nRow].BorderStyleBottom,
256 pLineBottom->GetBorderLineStyle());
257 CPPUNIT_ASSERT_EQUAL_MESSAGE("Top Width-Line wrong",
258 aCheckBorderWidth[nCol][nRow].WidthTop,
259 pLineTop->GetWidth());
260 CPPUNIT_ASSERT_EQUAL_MESSAGE("Bottom Width-Line wrong",
261 aCheckBorderWidth[nCol][nRow].WidthBottom,
262 pLineBottom->GetWidth());
267 static OUString toString(const ScBigRange& rRange)
269 return "(columns:" + OUString::number(rRange.aStart.Col()) + "-"
270 + OUString::number(rRange.aEnd.Col()) + ";rows:" + OUString::number(rRange.aStart.Row())
271 + "-" + OUString::number(rRange.aEnd.Row())
272 + ";sheets:" + OUString::number(rRange.aStart.Tab()) + "-"
273 + OUString::number(rRange.aEnd.Tab()) + ")";
276 CPPUNIT_TEST_FIXTURE(ScExportTest3, testTrackChangesSimpleXLSX)
278 struct CheckItem
280 sal_uLong mnActionId;
281 ScChangeActionType meType;
283 sal_Int32 mnStartCol;
284 sal_Int32 mnStartRow;
285 sal_Int32 mnStartTab;
286 sal_Int32 mnEndCol;
287 sal_Int32 mnEndRow;
288 sal_Int32 mnEndTab;
290 bool mbRowInsertedAtBottom;
293 struct
295 bool checkRange(ScChangeActionType eType, const ScBigRange& rExpected,
296 const ScBigRange& rActual)
298 ScBigRange aExpected(rExpected), aActual(rActual);
300 switch (eType)
302 case SC_CAT_INSERT_ROWS:
304 // Ignore columns.
305 aExpected.aStart.SetCol(0);
306 aExpected.aEnd.SetCol(0);
307 aActual.aStart.SetCol(0);
308 aActual.aEnd.SetCol(0);
310 break;
311 default:;
314 return aExpected == aActual;
317 bool check(ScDocument& rDoc)
319 static const CheckItem aChecks[] = {
320 { 1, SC_CAT_CONTENT, 1, 1, 0, 1, 1, 0, false },
321 { 2, SC_CAT_INSERT_ROWS, 0, 2, 0, 0, 2, 0, true },
322 { 3, SC_CAT_CONTENT, 1, 2, 0, 1, 2, 0, false },
323 { 4, SC_CAT_INSERT_ROWS, 0, 3, 0, 0, 3, 0, true },
324 { 5, SC_CAT_CONTENT, 1, 3, 0, 1, 3, 0, false },
325 { 6, SC_CAT_INSERT_ROWS, 0, 4, 0, 0, 4, 0, true },
326 { 7, SC_CAT_CONTENT, 1, 4, 0, 1, 4, 0, false },
327 { 8, SC_CAT_INSERT_ROWS, 0, 5, 0, 0, 5, 0, true },
328 { 9, SC_CAT_CONTENT, 1, 5, 0, 1, 5, 0, false },
329 { 10, SC_CAT_INSERT_ROWS, 0, 6, 0, 0, 6, 0, true },
330 { 11, SC_CAT_CONTENT, 1, 6, 0, 1, 6, 0, false },
331 { 12, SC_CAT_INSERT_ROWS, 0, 7, 0, 0, 7, 0, true },
332 { 13, SC_CAT_CONTENT, 1, 7, 0, 1, 7, 0, false },
335 ScChangeTrack* pCT = rDoc.GetChangeTrack();
336 if (!pCT)
338 cerr << "Change track instance doesn't exist." << endl;
339 return false;
342 sal_uLong nActionMax = pCT->GetActionMax();
343 if (nActionMax != 13)
345 cerr << "Unexpected highest action ID value." << endl;
346 return false;
349 for (size_t i = 0; i < SAL_N_ELEMENTS(aChecks); ++i)
351 sal_uInt16 nActId = aChecks[i].mnActionId;
352 const ScChangeAction* pAction = pCT->GetAction(nActId);
353 if (!pAction)
355 cerr << "No action for action number " << nActId << " found." << endl;
356 return false;
359 if (pAction->GetType() != aChecks[i].meType)
361 cerr << "Unexpected action type for action number " << nActId << "." << endl;
362 return false;
365 const ScBigRange& rRange = pAction->GetBigRange();
366 ScBigRange aCheck(aChecks[i].mnStartCol, aChecks[i].mnStartRow,
367 aChecks[i].mnStartTab, aChecks[i].mnEndCol, aChecks[i].mnEndRow,
368 aChecks[i].mnEndTab);
370 if (!checkRange(pAction->GetType(), aCheck, rRange))
372 cerr << "Unexpected range for action number " << nActId
373 << ": expected=" << toString(aCheck) << " actual=" << toString(rRange)
374 << endl;
375 return false;
378 switch (pAction->GetType())
380 case SC_CAT_INSERT_ROWS:
382 const ScChangeActionIns* p = static_cast<const ScChangeActionIns*>(pAction);
383 if (p->IsEndOfList() != aChecks[i].mbRowInsertedAtBottom)
385 cerr << "Unexpected end-of-list flag for action number " << nActId
386 << "." << endl;
387 return false;
390 break;
391 default:;
395 return true;
398 bool checkRevisionUserAndTime(ScDocument& rDoc, std::u16string_view rOwnerName)
400 ScChangeTrack* pCT = rDoc.GetChangeTrack();
401 if (!pCT)
403 cerr << "Change track instance doesn't exist." << endl;
404 return false;
407 ScChangeAction* pAction = pCT->GetLast();
408 if (pAction->GetUser() != "Kohei Yoshida")
410 cerr << "Wrong user name." << endl;
411 return false;
414 DateTime aDT = pAction->GetDateTime();
415 if (aDT.GetYear() != 2014 || aDT.GetMonth() != 7 || aDT.GetDay() != 11)
417 cerr << "Wrong time stamp." << endl;
418 return false;
421 // Insert a new record to make sure the user and date-time are correct.
422 rDoc.SetString(ScAddress(1, 8, 0), "New String");
423 ScCellValue aEmpty;
424 pCT->AppendContent(ScAddress(1, 8, 0), aEmpty);
425 pAction = pCT->GetLast();
426 if (!pAction)
428 cerr << "Failed to retrieve last revision." << endl;
429 return false;
432 if (rOwnerName != pAction->GetUser())
434 cerr << "Wrong user name." << endl;
435 return false;
438 DateTime aDTNew = pAction->GetDateTime();
439 if (aDTNew <= aDT)
441 cerr << "Time stamp of the new revision should be more recent than that of the "
442 "last revision."
443 << endl;
444 return false;
447 return true;
450 } aTest;
452 SvtUserOptions& rUserOpt = SC_MOD()->GetUserOptions();
453 rUserOpt.SetToken(UserOptToken::FirstName, "Export");
454 rUserOpt.SetToken(UserOptToken::LastName, "Test");
456 OUString aOwnerName = rUserOpt.GetFirstName() + " " + rUserOpt.GetLastName();
458 // First, test the xls variant.
460 createScDoc("xls/track-changes/simple-cell-changes.xls");
461 ScDocument* pDoc = getScDoc();
462 bool bGood = aTest.check(*pDoc);
463 CPPUNIT_ASSERT_MESSAGE("Initial check failed (xls).", bGood);
465 saveAndReload("MS Excel 97");
466 pDoc = getScDoc();
467 bGood = aTest.check(*pDoc);
468 CPPUNIT_ASSERT_MESSAGE("Check after reload failed (xls).", bGood);
470 // fdo#81445 : Check the blank value string to make sure it's "<empty>".
471 ScChangeTrack* pCT = pDoc->GetChangeTrack();
472 CPPUNIT_ASSERT(pCT);
473 ScChangeAction* pAction = pCT->GetAction(1);
474 CPPUNIT_ASSERT(pAction);
475 OUString aDesc = pAction->GetDescription(*pDoc);
476 CPPUNIT_ASSERT_EQUAL(OUString("Cell B2 changed from '<empty>' to '1'"), aDesc);
478 pDoc = getScDoc();
479 bGood = aTest.checkRevisionUserAndTime(*pDoc, aOwnerName);
480 CPPUNIT_ASSERT_MESSAGE("Check revision and time failed after reload (xls).", bGood);
482 // Now, test the xlsx variant the same way.
484 createScDoc("xlsx/track-changes/simple-cell-changes.xlsx");
485 pDoc = getScDoc();
486 aTest.check(*pDoc);
487 CPPUNIT_ASSERT_MESSAGE("Initial check failed (xlsx).", bGood);
489 saveAndReload("Calc Office Open XML");
490 pDoc = getScDoc();
491 bGood = aTest.check(*pDoc);
492 CPPUNIT_ASSERT_MESSAGE("Check after reload failed (xlsx).", bGood);
494 bGood = aTest.checkRevisionUserAndTime(*pDoc, aOwnerName);
495 CPPUNIT_ASSERT_MESSAGE("Check revision and time failed after reload (xlsx).", bGood);
498 CPPUNIT_TEST_FIXTURE(ScExportTest3, testSheetTabColorsXLSX)
500 struct
502 bool checkContent(ScDocument& rDoc)
504 std::vector<OUString> aTabNames = rDoc.GetAllTableNames();
506 // green, red, blue, yellow (from left to right).
507 if (aTabNames.size() != 4)
509 cerr << "There should be exactly 4 sheets." << endl;
510 return false;
513 const char* pNames[] = { "Green", "Red", "Blue", "Yellow" };
514 for (size_t i = 0; i < SAL_N_ELEMENTS(pNames); ++i)
516 OUString aExpected = OUString::createFromAscii(pNames[i]);
517 if (aExpected != aTabNames[i])
519 cerr << "incorrect sheet name: expected='" << aExpected << "', actual='"
520 << aTabNames[i] << "'" << endl;
521 return false;
525 static const Color aXclColors[] = {
526 0x0000B050, // green
527 0x00FF0000, // red
528 0x000070C0, // blue
529 0x00FFFF00, // yellow
532 for (size_t i = 0; i < SAL_N_ELEMENTS(aXclColors); ++i)
534 if (aXclColors[i] != rDoc.GetTabBgColor(i))
536 cerr << "wrong sheet color for sheet " << i << endl;
537 return false;
541 return true;
544 } aTest;
546 createScDoc("xlsx/sheet-tab-color.xlsx");
548 ScDocument* pDoc = getScDoc();
549 bool bRes = aTest.checkContent(*pDoc);
550 CPPUNIT_ASSERT_MESSAGE("Failed on the initial content check.", bRes);
553 saveAndReload("Calc Office Open XML");
554 ScDocument* pDoc = getScDoc();
555 bool bRes = aTest.checkContent(*pDoc);
556 CPPUNIT_ASSERT_MESSAGE("Failed on the content check after reload.", bRes);
559 CPPUNIT_TEST_FIXTURE(ScExportTest3, testTdf133487)
561 createScDoc("fods/shapes_foreground_background.fods");
563 save("calc8");
564 xmlDocUniquePtr pXmlDoc = parseExport("content.xml");
565 CPPUNIT_ASSERT(pXmlDoc);
567 // shape in background has lowest index
568 assertXPath(pXmlDoc,
569 "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
570 "table:table-row[1]/table:table-cell[1]/draw:custom-shape"_ostr,
571 "z-index"_ostr, "0");
572 assertXPath(pXmlDoc,
573 "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
574 "table:table-row[1]/table:table-cell[1]/draw:custom-shape"
575 "/attribute::table:table-background"_ostr,
577 assertXPath(pXmlDoc,
578 "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
579 "table:table-row[1]/table:table-cell[1]/draw:custom-shape"_ostr,
580 "table-background"_ostr, "true");
581 // shape in foreground, previously index 1
582 assertXPath(pXmlDoc,
583 "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
584 "table:table-row[1]/table:table-cell[2]/draw:custom-shape"_ostr,
585 "z-index"_ostr, "2");
586 // attribute is only written for value "true"
587 assertXPath(pXmlDoc,
588 "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
589 "table:table-row[1]/table:table-cell[2]/draw:custom-shape"
590 "/attribute::table:table-background"_ostr,
592 // shape in foreground, previously index 0
593 assertXPath(pXmlDoc,
594 "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
595 "table:table-row[3]/table:table-cell[1]/draw:custom-shape"_ostr,
596 "z-index"_ostr, "1");
597 // attribute is only written for value "true"
598 assertXPath(pXmlDoc,
599 "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
600 "table:table-row[3]/table:table-cell[1]/draw:custom-shape"
601 "/attribute::table:table-background"_ostr,
603 // shape in foreground, previously index 4
604 assertXPath(pXmlDoc,
605 "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
606 "table:shapes/draw:custom-shape"_ostr,
607 "z-index"_ostr, "3");
608 // attribute is only written for value "true"
609 assertXPath(pXmlDoc,
610 "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
611 "table:shapes/draw:custom-shape"
612 "/attribute::table:table-background"_ostr,
614 // form control, previously index 3
615 assertXPath(pXmlDoc,
616 "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
617 "table:shapes/draw:control"_ostr,
618 "z-index"_ostr, "4");
619 // attribute is only written for value "true"
620 assertXPath(pXmlDoc,
621 "/office:document-content/office:body/office:spreadsheet/table:table[1]/"
622 "table:shapes/draw:control"
623 "/attribute::table:table-background"_ostr,
627 CPPUNIT_TEST_FIXTURE(ScExportTest3, testSharedFormulaExportXLS)
629 struct
631 bool checkContent(ScDocument& rDoc)
633 formula::FormulaGrammar::Grammar eGram = formula::FormulaGrammar::GRAM_ENGLISH_XL_R1C1;
634 FormulaGrammarSwitch aFGSwitch(&rDoc, eGram);
635 sc::TokenStringContext aCxt(rDoc, eGram);
637 // Check the title row.
639 OUString aActual = rDoc.GetString(0, 1, 0);
640 OUString aExpected = "Response";
641 if (aActual != aExpected)
643 cerr << "Wrong content in A2: expected='" << aExpected << "', actual='" << aActual
644 << "'" << endl;
645 return false;
648 aActual = rDoc.GetString(1, 1, 0);
649 aExpected = "Response";
650 if (aActual != aExpected)
652 cerr << "Wrong content in B2: expected='" << aExpected << "', actual='" << aActual
653 << "'" << endl;
654 return false;
657 // A3:A12 and B3:B12 are numbers from 1 to 10.
658 for (SCROW i = 0; i <= 9; ++i)
660 double fExpected = i + 1.0;
661 ScAddress aPos(0, i + 2, 0);
662 double fActual = rDoc.GetValue(aPos);
663 if (fExpected != fActual)
665 cerr << "Wrong value in A" << (i + 2) << ": expected=" << fExpected
666 << ", actual=" << fActual << endl;
667 return false;
670 aPos.IncCol();
671 ScFormulaCell* pFC = rDoc.GetFormulaCell(aPos);
672 if (!pFC)
674 cerr << "B" << (i + 2) << " should be a formula cell." << endl;
675 return false;
678 OUString aFormula = pFC->GetCode()->CreateString(aCxt, aPos);
679 aExpected = "Coefficients!RC[-1]";
680 if (aFormula != aExpected)
682 cerr << "Wrong formula in B" << (i + 2) << ": expected='" << aExpected
683 << "', actual='" << aFormula << "'" << endl;
684 return false;
687 fActual = rDoc.GetValue(aPos);
688 if (fExpected != fActual)
690 cerr << "Wrong value in B" << (i + 2) << ": expected=" << fExpected
691 << ", actual=" << fActual << endl;
692 return false;
696 return true;
699 } aTest;
701 createScDoc("ods/shared-formula/3d-reference.ods");
703 // Check the content of the original.
704 ScDocument* pDoc = getScDoc();
705 bool bRes = aTest.checkContent(*pDoc);
706 CPPUNIT_ASSERT_MESSAGE("Content check on the original document failed.", bRes);
709 saveAndReload("MS Excel 97");
711 // Check the content of the reloaded. This should be identical.
712 ScDocument* pDoc = getScDoc();
713 bool bRes = aTest.checkContent(*pDoc);
714 CPPUNIT_ASSERT_MESSAGE("Content check on the reloaded document failed.", bRes);
717 CPPUNIT_TEST_FIXTURE(ScExportTest3, testSharedFormulaExportXLSX)
719 struct
721 bool checkContent(ScDocument& rDoc)
723 SCTAB nTabCount = rDoc.GetTableCount();
724 if (nTabCount != 2)
726 cerr << "Document should have exactly 2 sheets. " << nTabCount << " found."
727 << endl;
728 return false;
731 // Make sure the sheet tab colors are not set.
732 for (SCROW i = 0; i <= 1; ++i)
734 Color aTabBgColor = rDoc.GetTabBgColor(i);
735 if (aTabBgColor != COL_AUTO)
737 cerr << "The tab color of Sheet " << (i + 1) << " should not be explicitly set."
738 << endl;
739 return false;
743 // B2:B7 should show 1,2,3,4,5,6.
744 double fExpected = 1.0;
745 for (SCROW i = 1; i <= 6; ++i, ++fExpected)
747 ScAddress aPos(1, i, 0);
748 double fVal = rDoc.GetValue(aPos);
749 if (fVal != fExpected)
751 cerr << "Wrong value in B" << (i + 1) << ": expected=" << fExpected
752 << ", actual=" << fVal << endl;
753 return false;
757 // C2:C7 should show 10,20,...,60.
758 fExpected = 10.0;
759 for (SCROW i = 1; i <= 6; ++i, fExpected += 10.0)
761 ScAddress aPos(2, i, 0);
762 double fVal = rDoc.GetValue(aPos);
763 if (fVal != fExpected)
765 cerr << "Wrong value in C" << (i + 1) << ": expected=" << fExpected
766 << ", actual=" << fVal << endl;
767 return false;
771 // D2:D7 should show 1,2,...,6.
772 fExpected = 1.0;
773 for (SCROW i = 1; i <= 6; ++i, ++fExpected)
775 ScAddress aPos(3, i, 0);
776 double fVal = rDoc.GetValue(aPos);
777 if (fVal != fExpected)
779 cerr << "Wrong value in D" << (i + 1) << ": expected=" << fExpected
780 << ", actual=" << fVal << endl;
781 return false;
785 return true;
788 } aTest;
790 createScDoc("xlsx/shared-formula/3d-reference.xlsx");
792 ScDocument* pDoc = getScDoc();
793 bool bRes = aTest.checkContent(*pDoc);
794 CPPUNIT_ASSERT_MESSAGE("Content check on the initial document failed.", bRes);
796 pDoc->CalcAll(); // Recalculate to flush all cached results.
797 bRes = aTest.checkContent(*pDoc);
798 CPPUNIT_ASSERT_MESSAGE("Content check on the initial recalculated document failed.", bRes);
801 // Save and reload, and check the content again.
802 saveAndReload("Calc Office Open XML");
804 ScDocument* pDoc = getScDoc();
805 pDoc->CalcAll(); // Recalculate to flush all cached results.
807 bool bRes = aTest.checkContent(*pDoc);
808 CPPUNIT_ASSERT_MESSAGE("Content check on the reloaded document failed.", bRes);
811 CPPUNIT_TEST_FIXTURE(ScExportTest3, testSharedFormulaStringResultExportXLSX)
813 struct
815 bool checkContent(ScDocument& rDoc)
818 // B2:B7 should show A,B,...,F.
819 const char* const expected[] = { "A", "B", "C", "D", "E", "F" };
820 for (SCROW i = 0; i <= 5; ++i)
822 ScAddress aPos(1, i + 1, 0);
823 OUString aStr = rDoc.GetString(aPos);
824 OUString aExpected = OUString::createFromAscii(expected[i]);
825 if (aStr != aExpected)
827 cerr << "Wrong value in B" << (i + 2) << ": expected='" << aExpected
828 << "', actual='" << aStr << "'" << endl;
829 return false;
835 // C2:C7 should show AA,BB,...,FF.
836 const char* const expected[] = { "AA", "BB", "CC", "DD", "EE", "FF" };
837 for (SCROW i = 0; i <= 5; ++i)
839 ScAddress aPos(2, i + 1, 0);
840 OUString aStr = rDoc.GetString(aPos);
841 OUString aExpected = OUString::createFromAscii(expected[i]);
842 if (aStr != aExpected)
844 cerr << "Wrong value in C" << (i + 2) << ": expected='" << aExpected
845 << "', actual='" << aStr << "'" << endl;
846 return false;
851 return true;
854 } aTest;
856 createScDoc("xlsx/shared-formula/text-results.xlsx");
858 ScDocument* pDoc = getScDoc();
860 // Check content without re-calculation, to test cached formula results.
861 bool bRes = aTest.checkContent(*pDoc);
862 CPPUNIT_ASSERT_MESSAGE("Content check on the initial document failed.", bRes);
864 // Now, re-calculate and check the results.
865 pDoc->CalcAll();
866 bRes = aTest.checkContent(*pDoc);
867 CPPUNIT_ASSERT_MESSAGE("Content check on the initial recalculated document failed.", bRes);
869 // Reload and check again.
870 saveAndReload("Calc Office Open XML");
871 ScDocument* pDoc = getScDoc();
873 bool bRes = aTest.checkContent(*pDoc);
874 CPPUNIT_ASSERT_MESSAGE("Content check on the reloaded document failed.", bRes);
877 void ScExportTest3::testFunctionsExcel2010(const OUString& sFormatType)
879 createScDoc("xlsx/functions-excel-2010.xlsx");
881 saveAndReload(sFormatType);
882 ScDocument* pDoc = getScDoc();
883 pDoc->CalcAll(); // perform hard re-calculation.
885 testFunctionsExcel2010_Impl(*pDoc);
888 CPPUNIT_TEST_FIXTURE(ScExportTest3, testFunctionsExcel2010XLSX)
890 testFunctionsExcel2010("Calc Office Open XML");
893 CPPUNIT_TEST_FIXTURE(ScExportTest3, testFunctionsExcel2010XLS)
895 testFunctionsExcel2010("MS Excel 97");
898 void ScExportTest3::testCeilingFloor(const OUString& sFormatType)
900 createScDoc("xlsx/ceiling-floor.xlsx");
902 saveAndReload(sFormatType);
903 ScDocument* pDoc = getScDoc();
904 pDoc->CalcAll(); // perform hard re-calculation.
906 testCeilingFloor_Impl(*pDoc);
909 CPPUNIT_TEST_FIXTURE(ScExportTest3, testCeilingFloorXLSX)
911 testCeilingFloor("Calc Office Open XML");
914 CPPUNIT_TEST_FIXTURE(ScExportTest3, testCeilingFloorODSToXLSX)
916 // tdf#100011 - Cannot open sheet containing FLOOR/CEILING functions by MS Excel, after export to .xlsx
917 createScDoc("ods/ceiling-floor.ods");
919 save("Calc Office Open XML");
920 xmlDocUniquePtr pSheet = parseExport("xl/workbook.xml");
921 CPPUNIT_ASSERT(pSheet);
923 // there shouldn't be any defined names during export of FLOOR and CEILING functions to .xlsx
924 assertXPath(pSheet, "/x:workbook/x:definedNames"_ostr, 0);
927 CPPUNIT_TEST_FIXTURE(ScExportTest3, testCeilingFloorXLS) { testCeilingFloor("MS Excel 97"); }
929 CPPUNIT_TEST_FIXTURE(ScExportTest3, testCeilingFloorODS) { testCeilingFloor("calc8"); }
931 CPPUNIT_TEST_FIXTURE(ScExportTest3, testCustomXml)
933 // Load document and export it to a temporary file
934 createScDoc("xlsx/customxml.xlsx");
936 save("Calc Office Open XML");
937 xmlDocUniquePtr pXmlDoc = parseExport("customXml/item1.xml");
938 CPPUNIT_ASSERT(pXmlDoc);
939 xmlDocUniquePtr pRelsDoc = parseExport("customXml/_rels/item1.xml.rels");
940 CPPUNIT_ASSERT(pRelsDoc);
942 // Check there is a relation to itemProps1.xml.
943 assertXPath(pRelsDoc, "/rels:Relationships/rels:Relationship"_ostr, 1);
944 assertXPath(pRelsDoc, "/rels:Relationships/rels:Relationship[@Id='rId1']"_ostr, "Target"_ostr,
945 "itemProps1.xml");
947 std::unique_ptr<SvStream> pStream = parseExportStream(maTempFile.GetURL(), "ddp/ddpfile.xen");
948 CPPUNIT_ASSERT(pStream);
951 #ifdef _WIN32
952 static sal_Unicode lcl_getWindowsDrive(const OUString& aURL)
954 static const sal_Int32 nMinLen = strlen("file:///X:/");
955 if (aURL.getLength() <= nMinLen)
956 return 0;
957 const OUString aUrlStart = aURL.copy(0, nMinLen);
958 return (aUrlStart.startsWith("file:///") && aUrlStart.endsWith(":/")) ? aUrlStart[8] : 0;
960 #endif
962 CPPUNIT_TEST_FIXTURE(ScExportTest3, testRelativePathsODS)
964 createScDoc("ods/fdo79305.ods");
966 save("calc8");
967 xmlDocUniquePtr pDoc = parseExport("content.xml");
968 CPPUNIT_ASSERT(pDoc);
969 OUString aURL = getXPath(pDoc,
970 "/office:document-content/office:body/office:spreadsheet/table:table/"
971 "table:table-row[2]/table:table-cell[2]/text:p/text:a"_ostr,
972 "href"_ostr);
973 #ifdef _WIN32
974 // if the exported document is not on the same drive then the linked document,
975 // there is no way to get a relative URL for the link, because ../X:/ is undefined.
976 if (!aURL.startsWith(".."))
978 sal_Unicode aDocDrive = lcl_getWindowsDrive(maTempFile.GetURL());
979 sal_Unicode aLinkDrive = lcl_getWindowsDrive(aURL);
980 CPPUNIT_ASSERT_MESSAGE("document on the same drive but no relative link!", aDocDrive != 0);
981 CPPUNIT_ASSERT_MESSAGE("document on the same drive but no relative link!", aLinkDrive != 0);
982 CPPUNIT_ASSERT_MESSAGE("document on the same drive but no relative link!",
983 aDocDrive != aLinkDrive);
984 return;
986 #endif
987 // make sure that the URL is relative
988 CPPUNIT_ASSERT(aURL.startsWith(".."));
991 namespace
993 void testSheetProtection_Impl(ScDocument& rDoc)
995 CPPUNIT_ASSERT(rDoc.IsTabProtected(0));
996 const ScTableProtection* pTabProtection = rDoc.GetTabProtection(0);
997 CPPUNIT_ASSERT(pTabProtection);
998 CPPUNIT_ASSERT(pTabProtection->isOptionEnabled(ScTableProtection::SELECT_UNLOCKED_CELLS));
999 CPPUNIT_ASSERT(!pTabProtection->isOptionEnabled(ScTableProtection::SELECT_LOCKED_CELLS));
1003 CPPUNIT_TEST_FIXTURE(ScExportTest3, testSheetProtectionODS)
1005 createScDoc("ods/sheet-protection.ods");
1007 ScDocument* pDoc = getScDoc();
1009 testSheetProtection_Impl(*pDoc);
1011 saveAndReload("calc8");
1013 pDoc = getScDoc();
1015 testSheetProtection_Impl(*pDoc);
1018 CPPUNIT_TEST_FIXTURE(ScExportTest3, testFunctionsExcel2010ODS)
1020 //testFunctionsExcel2010("calc8");
1023 CPPUNIT_TEST_FIXTURE(ScExportTest3, testSwappedOutImageExport)
1025 std::vector<OUString> aFilterNames{ "calc8", "MS Excel 97", "Calc Office Open XML" };
1027 for (size_t i = 0; i < aFilterNames.size(); ++i)
1029 // Check whether the export code swaps in the image which was swapped out before.
1030 createScDoc("ods/document_with_two_images.ods");
1032 const OString sFailedMessage
1033 = OString::Concat("Failed on filter: ") + aFilterNames[i].toUtf8();
1035 // Export the document and import again for a check
1036 saveAndReload(aFilterNames[i]);
1038 // Check whether graphic exported well after it was swapped out
1039 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
1040 uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW);
1041 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xIA->getByIndex(0),
1042 UNO_QUERY_THROW);
1043 uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(),
1044 UNO_QUERY_THROW);
1045 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(2),
1046 xDraws->getCount());
1048 uno::Reference<drawing::XShape> xImage(xDraws->getByIndex(0), uno::UNO_QUERY);
1049 uno::Reference<beans::XPropertySet> XPropSet(xImage, uno::UNO_QUERY_THROW);
1051 // Check Graphic, Size
1053 uno::Reference<graphic::XGraphic> xGraphic;
1054 XPropSet->getPropertyValue("Graphic") >>= xGraphic;
1055 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
1056 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(),
1057 xGraphic->getType() != graphic::GraphicType::EMPTY);
1058 uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
1059 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
1060 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(610),
1061 xBitmap->getSize().Width);
1062 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(381),
1063 xBitmap->getSize().Height);
1065 // Second Image
1066 xImage.set(xDraws->getByIndex(1), uno::UNO_QUERY);
1067 XPropSet.set(xImage, uno::UNO_QUERY_THROW);
1069 // Check Graphic, Size
1071 uno::Reference<graphic::XGraphic> xGraphic;
1072 XPropSet->getPropertyValue("Graphic") >>= xGraphic;
1073 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
1074 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(),
1075 xGraphic->getType() != graphic::GraphicType::EMPTY);
1076 uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
1077 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
1078 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(900),
1079 xBitmap->getSize().Width);
1080 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(600),
1081 xBitmap->getSize().Height);
1086 CPPUNIT_TEST_FIXTURE(ScExportTest3, testSupBookVirtualPathXLS)
1088 createScDoc("xls/external-ref.xls");
1090 saveAndReload("MS Excel 97");
1092 ScDocument* pDoc = getScDoc();
1094 OUString aFormula = pDoc->GetFormula(0, 0, 0);
1095 #ifdef _WIN32
1096 aFormula = OUString::Concat(aFormula.subView(0, 9)) + aFormula.subView(12);
1097 // strip drive letter, e.g. 'C:/'
1098 #endif
1099 CPPUNIT_ASSERT_EQUAL_MESSAGE(
1100 "Wrong SupBook VirtualPath URL",
1101 OUString("='file:///home/timar/Documents/external.xls'#$Sheet1.A1"), aFormula);
1104 CPPUNIT_TEST_FIXTURE(ScExportTest3, testLinkedGraphicRT)
1106 // Problem was with linked images
1107 std::vector<OUString> aFilterNames{ "calc8", "MS Excel 97", "Calc Office Open XML" };
1109 for (size_t i = 0; i < aFilterNames.size(); ++i)
1111 // Load the original file with one image
1112 createScDoc("ods/document_with_linked_graphic.ods");
1113 const OString sFailedMessage
1114 = OString::Concat("Failed on filter: ") + aFilterNames[i].toUtf8();
1116 // Export the document and import again for a check
1117 saveAndReload(aFilterNames[i]);
1119 // Check whether graphic imported well after export
1120 ScDocument* pDoc = getScDoc();
1121 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1122 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pDrawLayer != nullptr);
1123 const SdrPage* pPage = pDrawLayer->GetPage(0);
1124 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pPage != nullptr);
1125 SdrGrafObj* pObject = dynamic_cast<SdrGrafObj*>(pPage->GetObj(0));
1126 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pObject != nullptr);
1127 if (aFilterNames[i] == "Calc Office Open XML")
1129 // FIXME: tdf#152036
1130 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), !pObject->IsLinkedGraphic());
1132 else
1133 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), pObject->IsLinkedGraphic());
1135 const GraphicObject& rGraphicObj = pObject->GetGraphicObject(true);
1136 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), int(GraphicType::Bitmap),
1137 int(rGraphicObj.GetGraphic().GetType()));
1138 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), sal_uLong(864900),
1139 rGraphicObj.GetGraphic().GetSizeBytes());
1143 CPPUNIT_TEST_FIXTURE(ScExportTest3, testImageWithSpecialID)
1145 std::vector<OUString> aFilterNames{ "calc8", "MS Excel 97", "Calc Office Open XML" };
1147 for (size_t i = 0; i < aFilterNames.size(); ++i)
1149 createScDoc("ods/images_with_special_IDs.ods");
1151 const OString sFailedMessage
1152 = OString::Concat("Failed on filter: ") + aFilterNames[i].toUtf8();
1154 // Export the document and import again for a check
1155 saveAndReload(aFilterNames[i]);
1157 // Check whether graphic was exported well
1158 uno::Reference<sheet::XSpreadsheetDocument> xDoc(mxComponent, UNO_QUERY_THROW);
1159 uno::Reference<container::XIndexAccess> xIA(xDoc->getSheets(), UNO_QUERY_THROW);
1160 uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xIA->getByIndex(0),
1161 UNO_QUERY_THROW);
1162 uno::Reference<container::XIndexAccess> xDraws(xDrawPageSupplier->getDrawPage(),
1163 UNO_QUERY_THROW);
1164 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(2),
1165 xDraws->getCount());
1167 uno::Reference<drawing::XShape> xImage(xDraws->getByIndex(0), uno::UNO_QUERY);
1168 uno::Reference<beans::XPropertySet> XPropSet(xImage, uno::UNO_QUERY_THROW);
1170 // Check Graphic, Size
1172 uno::Reference<graphic::XGraphic> xGraphic;
1173 XPropSet->getPropertyValue("Graphic") >>= xGraphic;
1174 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
1175 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(),
1176 xGraphic->getType() != graphic::GraphicType::EMPTY);
1177 uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
1178 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
1179 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(610),
1180 xBitmap->getSize().Width);
1181 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(381),
1182 xBitmap->getSize().Height);
1184 // Second Image
1185 xImage.set(xDraws->getByIndex(1), uno::UNO_QUERY);
1186 XPropSet.set(xImage, uno::UNO_QUERY_THROW);
1188 // Check Graphic, Size
1190 uno::Reference<graphic::XGraphic> xGraphic;
1191 XPropSet->getPropertyValue("Graphic") >>= xGraphic;
1192 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xGraphic.is());
1193 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(),
1194 xGraphic->getType() != graphic::GraphicType::EMPTY);
1195 uno::Reference<awt::XBitmap> xBitmap(xGraphic, uno::UNO_QUERY);
1196 CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
1197 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(900),
1198 xBitmap->getSize().Width);
1199 CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), static_cast<sal_Int32>(600),
1200 xBitmap->getSize().Height);
1205 CPPUNIT_TEST_FIXTURE(ScExportTest3, testAbsNamedRangeHTML)
1207 setImportFilterName("calc_HTML_WebQuery");
1208 createScDoc("html/numberformat.html");
1209 ScDocShell* pDocSh = getScDocShell();
1210 pDocSh->DoHardRecalc();
1212 //reset import filter
1213 setImportFilterName("calc8");
1214 saveAndReload("calc8");
1215 pDocSh = getScDocShell();
1216 pDocSh->DoHardRecalc();
1218 ScDocument* pDoc = getScDoc();
1219 ScRangeData* pRangeData = pDoc->GetRangeName()->findByUpperName(OUString("HTML_1"));
1220 ScSingleRefData* pRef = pRangeData->GetCode()->FirstToken()->GetSingleRef();
1221 // see tdf#119141 for the reason why this isn't Sheet1.HTML_1
1222 CPPUNIT_ASSERT_MESSAGE("HTML_1 is an absolute reference", !pRef->IsTabRel());
1225 CPPUNIT_TEST_FIXTURE(ScExportTest3, testTdf80149)
1227 createScDoc("csv/tdf80149.csv");
1228 ScDocShell* pDocSh = getScDocShell();
1229 pDocSh->DoHardRecalc();
1230 saveAndReload("Calc Office Open XML");
1231 pDocSh = getScDocShell();
1232 pDocSh->DoHardRecalc();
1234 ScDocument* pDoc = getScDoc();
1235 CPPUNIT_ASSERT_EQUAL(OUString("row 1"), pDoc->GetString(0, 0, 0));
1237 // Without the fix in place, this test would have failed with
1238 // - Expected: Character 0x16 is here ->>\x16<<--
1239 // - Actual :
1240 CPPUNIT_ASSERT_EQUAL(OUString("Character 0x16 is here ->>\x16<<--"), pDoc->GetString(1, 0, 0));
1241 CPPUNIT_ASSERT_EQUAL(OUString("File opens in libre office, but can't be saved as xlsx"),
1242 pDoc->GetString(2, 0, 0));
1243 CPPUNIT_ASSERT_EQUAL(OUString("row 2"), pDoc->GetString(0, 1, 0));
1244 CPPUNIT_ASSERT_EQUAL(OUString("Subsequent rows get truncated"), pDoc->GetString(1, 1, 0));
1245 CPPUNIT_ASSERT_EQUAL(OUString("This cell goes missing"), pDoc->GetString(2, 1, 0));
1246 CPPUNIT_ASSERT_EQUAL(OUString("row 3"), pDoc->GetString(0, 2, 0));
1247 CPPUNIT_ASSERT_EQUAL(OUString("Subsequent rows get truncated"), pDoc->GetString(1, 2, 0));
1248 CPPUNIT_ASSERT_EQUAL(OUString("This cell goes missing"), pDoc->GetString(2, 2, 0));
1251 CPPUNIT_TEST_FIXTURE(ScExportTest3, testSheetLocalRangeNameXLS)
1253 createScDoc("xls/named-ranges-local.xls");
1254 ScDocShell* pDocSh = getScDocShell();
1255 pDocSh->DoHardRecalc();
1256 saveAndReload("MS Excel 97");
1257 pDocSh = getScDocShell();
1258 pDocSh->DoHardRecalc();
1260 ScDocument* pDoc = getScDoc();
1261 ScRangeName* pRangeName = pDoc->GetRangeName(0);
1262 CPPUNIT_ASSERT(pRangeName);
1263 CPPUNIT_ASSERT_EQUAL(size_t(2), pRangeName->size());
1265 OUString aFormula = pDoc->GetFormula(3, 11, 0);
1266 CPPUNIT_ASSERT_EQUAL(OUString("=SUM(local_name2)"), aFormula);
1267 ASSERT_DOUBLES_EQUAL(14.0, pDoc->GetValue(3, 11, 0));
1269 aFormula = pDoc->GetFormula(6, 4, 0);
1270 CPPUNIT_ASSERT_EQUAL(OUString("=local_name1"), aFormula);
1273 CPPUNIT_TEST_FIXTURE(ScExportTest3, testRelativeNamedExpressionsXLS)
1275 createScDoc("ods/tdf113991_relativeNamedRanges.ods");
1276 ScDocShell* pDocSh = getScDocShell();
1277 pDocSh->DoHardRecalc();
1278 saveAndReload("MS Excel 97");
1279 pDocSh = getScDocShell();
1280 pDocSh->DoHardRecalc();
1282 ScDocument* pDoc = getScDoc();
1283 // Sheet1:G3
1284 ScAddress aPos(6, 2, 0);
1285 CPPUNIT_ASSERT_EQUAL(1.0, pDoc->GetValue(aPos));
1286 CPPUNIT_ASSERT_EQUAL(OUString("=single_cell_A3"),
1287 pDoc->GetFormula(aPos.Col(), aPos.Row(), aPos.Tab()));
1288 // Sheet2:F6
1289 aPos = ScAddress(5, 5, 1);
1290 CPPUNIT_ASSERT_EQUAL(18.0, pDoc->GetValue(aPos));
1291 CPPUNIT_ASSERT_EQUAL(OUString("=SUM(test_conflict)"),
1292 pDoc->GetFormula(aPos.Col(), aPos.Row(), aPos.Tab()));
1293 // Sheet2:H3
1294 aPos = ScAddress(7, 2, 1);
1295 CPPUNIT_ASSERT_EQUAL(10.0, pDoc->GetValue(aPos));
1296 CPPUNIT_ASSERT_EQUAL(OUString("=single_global_A3"),
1297 pDoc->GetFormula(aPos.Col(), aPos.Row(), aPos.Tab()));
1298 // Sheet2:H6
1299 aPos = ScAddress(7, 5, 1);
1300 CPPUNIT_ASSERT_EQUAL(75.0, pDoc->GetValue(aPos));
1301 CPPUNIT_ASSERT_EQUAL(OUString("=SUM(A6:F6)"),
1302 pDoc->GetFormula(aPos.Col(), aPos.Row(), aPos.Tab()));
1305 CPPUNIT_TEST_FIXTURE(ScExportTest3, testSheetTextBoxHyperlinkXLSX)
1307 createScDoc("xlsx/textbox-hyperlink.xlsx");
1309 save("Calc Office Open XML");
1310 xmlDocUniquePtr pDoc = parseExport("xl/drawings/drawing1.xml");
1311 CPPUNIT_ASSERT(pDoc);
1313 assertXPath(
1314 pDoc,
1315 "/xdr:wsDr[1]/xdr:twoCellAnchor[1]/xdr:sp[1]/xdr:nvSpPr[1]/xdr:cNvPr[1]/a:hlinkClick[1]"_ostr,
1319 CPPUNIT_TEST_FIXTURE(ScExportTest3, testFontSizeXLSX)
1321 createScDoc("xlsx/fontSize.xlsx");
1323 save("Calc Office Open XML");
1324 xmlDocUniquePtr pDoc = parseExport("xl/drawings/drawing1.xml");
1325 CPPUNIT_ASSERT(pDoc);
1326 OUString fontSize = getXPath(
1327 pDoc, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp[1]/xdr:txBody/a:p[1]/a:r[1]/a:rPr"_ostr,
1328 "sz"_ostr);
1329 // make sure that the font size is 18
1330 CPPUNIT_ASSERT_EQUAL(OUString("1800"), fontSize);
1333 CPPUNIT_TEST_FIXTURE(ScExportTest3, testSheetCharacterKerningSpaceXLSX)
1335 createScDoc("xlsx/textbox-CharKerningSpace.xlsx");
1337 saveAndReload("Calc Office Open XML");
1339 save("Calc Office Open XML");
1340 xmlDocUniquePtr pDoc = parseExport("xl/drawings/drawing1.xml");
1341 CPPUNIT_ASSERT(pDoc);
1343 OUString CharKerningSpace = getXPath(
1344 pDoc,
1345 "/xdr:wsDr[1]/xdr:twoCellAnchor[1]/xdr:sp[1]/xdr:txBody[1]/a:p[1]/a:r[1]/a:rPr[1]"_ostr,
1346 "spc"_ostr);
1348 // make sure that the CharKerning is 1997.
1349 CPPUNIT_ASSERT_EQUAL(OUString("1997"), CharKerningSpace);
1352 CPPUNIT_TEST_FIXTURE(ScExportTest3, testSheetCondensedCharacterSpaceXLSX)
1354 createScDoc("xlsx/textbox-CondensedCharacterSpace.xlsx");
1356 save("Calc Office Open XML");
1357 xmlDocUniquePtr pDoc = parseExport("xl/drawings/drawing1.xml");
1358 CPPUNIT_ASSERT(pDoc);
1360 OUString CondensedCharSpace = getXPath(
1361 pDoc,
1362 "/xdr:wsDr[1]/xdr:twoCellAnchor[1]/xdr:sp[1]/xdr:txBody[1]/a:p[1]/a:r[1]/a:rPr[1]"_ostr,
1363 "spc"_ostr);
1365 // make sure that the CondensedCharSpace is -1002.
1366 CPPUNIT_ASSERT_EQUAL(OUString("-1002"), CondensedCharSpace);
1369 CPPUNIT_TEST_FIXTURE(ScExportTest3, testTextUnderlineColorXLSX)
1371 createScDoc("xlsx/underlineColor.xlsx");
1373 save("Calc Office Open XML");
1374 xmlDocUniquePtr pDoc = parseExport("xl/drawings/drawing1.xml");
1375 CPPUNIT_ASSERT(pDoc);
1376 // Make sure the underline type is double line
1377 assertXPath(pDoc,
1378 "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:sp[1]/xdr:txBody/a:p[1]/a:r[1]/a:rPr"_ostr,
1379 "u"_ostr, "dbl");
1381 assertXPath(pDoc,
1382 "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:sp[1]/xdr:txBody/a:p[1]/a:r[1]/a:rPr"_ostr,
1383 "b"_ostr, "1");
1384 // Make sure that the underline color is RED
1385 assertXPath(pDoc,
1386 "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:sp[1]/xdr:txBody/a:p[1]/a:r[1]/a:rPr/a:uFill/"
1387 "a:solidFill/a:srgbClr"_ostr,
1388 "val"_ostr, "ff0000");
1390 // Make sure the underline type is drawn with heavy line
1391 assertXPath(pDoc,
1392 "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:sp[1]/xdr:txBody/a:p[1]/a:r[1]/a:rPr"_ostr,
1393 "u"_ostr, "heavy");
1394 // tdf#104219 Make sure that uFill is not existing and uFillTx is set.
1395 // It mean that color is automatic, should be the same color as the text.
1396 assertXPath(
1397 pDoc,
1398 "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:sp[1]/xdr:txBody/a:p[1]/a:r[1]/a:rPr/a:uFill"_ostr, 0);
1399 assertXPath(
1400 pDoc,
1401 "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:sp[1]/xdr:txBody/a:p[1]/a:r[1]/a:rPr/a:uFillTx"_ostr,
1405 CPPUNIT_TEST_FIXTURE(ScExportTest3, testSheetRunParagraphPropertyXLSX)
1407 createScDoc("xlsx/TextColor.xlsx");
1409 save("Calc Office Open XML");
1410 xmlDocUniquePtr pDoc = parseExport("xl/sharedStrings.xml");
1411 CPPUNIT_ASSERT(pDoc);
1413 OUString aColor = getXPath(pDoc, "/x:sst/x:si/x:r[1]/x:rPr[1]/x:color"_ostr, "rgb"_ostr);
1414 CPPUNIT_ASSERT_EQUAL(OUString("FFFF0000"), aColor);
1417 CPPUNIT_TEST_FIXTURE(ScExportTest3, testPreserveTextWhitespaceXLSX)
1419 createScDoc("xlsx/preserve-whitespace.xlsx");
1421 save("Calc Office Open XML");
1422 xmlDocUniquePtr pDoc = parseExport("xl/sharedStrings.xml");
1423 CPPUNIT_ASSERT(pDoc);
1424 assertXPath(pDoc, "/x:sst/x:si/x:t"_ostr, "space"_ostr, "preserve");
1427 CPPUNIT_TEST_FIXTURE(ScExportTest3, testPreserveTextWhitespace2XLSX)
1429 createScDoc("xlsx/preserve_space.xlsx");
1431 save("Calc Office Open XML");
1432 xmlDocUniquePtr pDoc = parseExport("xl/sharedStrings.xml");
1433 CPPUNIT_ASSERT(pDoc);
1434 assertXPath(pDoc, "/x:sst/x:si[1]/x:t"_ostr, "space"_ostr, "preserve");
1435 assertXPath(pDoc, "/x:sst/x:si[2]/x:t"_ostr, "space"_ostr, "preserve");
1438 CPPUNIT_TEST_FIXTURE(ScExportTest3, testHiddenShapeXLS)
1440 createScDoc("xls/hiddenShape.xls");
1442 ScDocument* pDoc = getScDoc();
1443 CPPUNIT_ASSERT(pDoc->GetTableCount() > 0);
1444 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1445 SdrPage* pPage = pDrawLayer->GetPage(0);
1446 CPPUNIT_ASSERT(pPage);
1447 SdrObject* pObj = pPage->GetObj(0);
1448 CPPUNIT_ASSERT(pObj);
1449 CPPUNIT_ASSERT_MESSAGE("Drawing object should not be visible.", !pObj->IsVisible());
1450 CPPUNIT_ASSERT_MESSAGE("Drawing object should not be printable.", !pObj->IsPrintable());
1453 CPPUNIT_TEST_FIXTURE(ScExportTest3, testHiddenShapeXLSX)
1455 createScDoc("xlsx/hiddenShape.xlsx");
1457 ScDocument* pDoc = getScDoc();
1458 CPPUNIT_ASSERT(pDoc->GetTableCount() > 0);
1459 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1460 SdrPage* pPage = pDrawLayer->GetPage(0);
1461 CPPUNIT_ASSERT(pPage);
1462 SdrObject* pObj = pPage->GetObj(0);
1463 CPPUNIT_ASSERT(pObj);
1464 CPPUNIT_ASSERT_MESSAGE("Drawing object should not be visible.", !pObj->IsVisible());
1465 CPPUNIT_ASSERT_MESSAGE("Drawing object should not be printable.", !pObj->IsPrintable());
1467 save("Calc Office Open XML");
1468 xmlDocUniquePtr pDocXml = parseExport("xl/drawings/drawing1.xml");
1469 CPPUNIT_ASSERT(pDocXml);
1470 assertXPath(pDocXml, "/xdr:wsDr/xdr:twoCellAnchor/xdr:sp[1]/xdr:nvSpPr/xdr:cNvPr"_ostr,
1471 "hidden"_ostr, "1");
1474 CPPUNIT_TEST_FIXTURE(ScExportTest3, testShapeAutofitXLSX)
1476 createScDoc("xlsx/testShapeAutofit.xlsx");
1478 save("Calc Office Open XML");
1479 xmlDocUniquePtr pDoc = parseExport("xl/drawings/drawing1.xml");
1480 CPPUNIT_ASSERT(pDoc);
1482 // TextAutoGrowHeight --> "Fit height to text" / "Resize shape to fit text" --> true
1483 assertXPath(pDoc, "/xdr:wsDr/xdr:twoCellAnchor[1]/xdr:sp/xdr:txBody/a:bodyPr/a:spAutoFit"_ostr,
1485 // TextAutoGrowHeight --> "Fit height to text" / "Resize shape to fit text" --> false
1486 assertXPath(pDoc, "/xdr:wsDr/xdr:twoCellAnchor[2]/xdr:sp/xdr:txBody/a:bodyPr/a:noAutofit"_ostr,
1490 CPPUNIT_TEST_FIXTURE(ScExportTest3, testHyperlinkXLSX)
1492 createScDoc("xlsx/hyperlink.xlsx");
1494 save("Calc Office Open XML");
1495 xmlDocUniquePtr pDoc = parseExport("xl/drawings/_rels/drawing1.xml.rels");
1496 CPPUNIT_ASSERT(pDoc);
1497 assertXPath(pDoc, "/rels:Relationships/rels:Relationship"_ostr, "Target"_ostr, "#Sheet2!A1");
1500 CPPUNIT_TEST_FIXTURE(ScExportTest3, testMoveCellAnchoredShapesODS)
1502 createScDoc("ods/move-cell-anchored-shapes.ods");
1504 // There are two cell-anchored objects on the first sheet.
1505 ScDocument* pDoc = getScDoc();
1507 CPPUNIT_ASSERT_MESSAGE("There should be at least one sheet.", pDoc->GetTableCount() > 0);
1509 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1510 SdrPage* pPage = pDrawLayer->GetPage(0);
1511 CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage);
1512 SdrObject* pObj = pPage->GetObj(0);
1513 CPPUNIT_ASSERT_MESSAGE("Failed to get drawing object.", pObj);
1515 // Check cell anchor state
1516 ScAnchorType oldType = ScDrawLayer::GetAnchorType(*pObj);
1517 CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to get anchor type", SCA_CELL_RESIZE, oldType);
1519 // Get anchor data
1520 ScDrawObjData* pData = ScDrawLayer::GetObjData(pObj);
1521 CPPUNIT_ASSERT_MESSAGE("Failed to retrieve user data for this object.", pData);
1522 CPPUNIT_ASSERT_MESSAGE("Bounding rectangle should have been calculated upon import.",
1523 !pData->getShapeRect().IsEmpty());
1525 ScAddress aDataStart = pData->maStart;
1526 ScAddress aDataEnd = pData->maEnd;
1528 // Get non rotated anchor data
1529 ScDrawObjData* pNData = ScDrawLayer::GetNonRotatedObjData(pObj);
1530 CPPUNIT_ASSERT_MESSAGE("Failed to retrieve non rotated user data for this object.", pNData);
1531 CPPUNIT_ASSERT_MESSAGE("Bounding rectangle should have been calculated upon import.",
1532 !pNData->getShapeRect().IsEmpty());
1534 ScAddress aNDataStart = pNData->maStart;
1535 ScAddress aNDataEnd = pNData->maEnd;
1536 CPPUNIT_ASSERT_EQUAL(aDataStart, aNDataStart);
1537 CPPUNIT_ASSERT_EQUAL(aDataEnd, aNDataEnd);
1539 // Insert 2 rows.
1540 pDoc->InsertRow(ScRange(0, aDataStart.Row() - 1, 0, pDoc->MaxCol(), aDataStart.Row(), 0));
1542 // Get anchor data
1543 pData = ScDrawLayer::GetObjData(pObj);
1544 CPPUNIT_ASSERT_MESSAGE("Failed to retrieve user data for this object.", pData);
1545 CPPUNIT_ASSERT_MESSAGE("Bounding rectangle should have been calculated upon import.",
1546 !pData->getShapeRect().IsEmpty());
1548 // Get non rotated anchor data
1549 pNData = ScDrawLayer::GetNonRotatedObjData(pObj);
1550 CPPUNIT_ASSERT_MESSAGE("Failed to retrieve non rotated user data for this object.", pNData);
1551 CPPUNIT_ASSERT_MESSAGE("Bounding rectangle should have been calculated upon import.",
1552 !pNData->getShapeRect().IsEmpty());
1554 // Check if data has moved to new rows
1555 CPPUNIT_ASSERT_EQUAL(pData->maStart.Row(), aDataStart.Row() + 2);
1556 CPPUNIT_ASSERT_EQUAL(pData->maEnd.Row(), aDataEnd.Row() + 2);
1558 CPPUNIT_ASSERT_EQUAL(pNData->maStart.Row(), aNDataStart.Row() + 2);
1559 CPPUNIT_ASSERT_EQUAL(pNData->maEnd.Row(), aNDataEnd.Row() + 2);
1561 // Save the anchor data
1562 aDataStart = pData->maStart;
1563 aDataEnd = pData->maEnd;
1564 aNDataStart = pNData->maStart;
1565 aNDataEnd = pNData->maEnd;
1567 // Save the document and load again to check anchor persist
1568 saveAndReload("calc8");
1570 // There are two cell-anchored objects on the first sheet.
1571 pDoc = getScDoc();
1573 CPPUNIT_ASSERT_MESSAGE("There should be at least one sheet.", pDoc->GetTableCount() > 0);
1575 pDrawLayer = pDoc->GetDrawLayer();
1576 pPage = pDrawLayer->GetPage(0);
1577 CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage);
1578 pObj = pPage->GetObj(0);
1579 CPPUNIT_ASSERT_MESSAGE("Failed to get drawing object.", pObj);
1581 // Check cell anchor state
1582 oldType = ScDrawLayer::GetAnchorType(*pObj);
1583 CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to get anchor type", SCA_CELL_RESIZE, oldType);
1585 // Get anchor data
1586 pData = ScDrawLayer::GetObjData(pObj);
1587 CPPUNIT_ASSERT_MESSAGE("Failed to retrieve user data for this object.", pData);
1588 CPPUNIT_ASSERT_MESSAGE("Bounding rectangle should have been calculated upon import.",
1589 !pData->getShapeRect().IsEmpty());
1591 // Get non rotated anchor data
1592 pNData = ScDrawLayer::GetNonRotatedObjData(pObj);
1593 CPPUNIT_ASSERT_MESSAGE("Failed to retrieve non rotated user data for this object.", pNData);
1594 CPPUNIT_ASSERT_MESSAGE("Bounding rectangle should have been calculated upon import.",
1595 !pNData->getShapeRect().IsEmpty());
1597 // Check if data after save it
1598 CPPUNIT_ASSERT_EQUAL(pData->maStart, aDataStart);
1599 CPPUNIT_ASSERT_EQUAL(pData->maEnd, aDataEnd);
1601 CPPUNIT_ASSERT_EQUAL(pNData->maStart, aNDataStart);
1602 CPPUNIT_ASSERT_EQUAL(pNData->maEnd, aNDataEnd);
1604 // Insert a column.
1605 pDoc->InsertCol(ScRange(aDataStart.Col(), 0, 0, aDataStart.Col(), pDoc->MaxRow(), 0));
1607 // Get anchor data
1608 pData = ScDrawLayer::GetObjData(pObj);
1609 CPPUNIT_ASSERT_MESSAGE("Failed to retrieve user data for this object.", pData);
1610 CPPUNIT_ASSERT_MESSAGE("Bounding rectangle should have been calculated upon import.",
1611 !pData->getShapeRect().IsEmpty());
1613 // Get non rotated anchor data
1614 pNData = ScDrawLayer::GetNonRotatedObjData(pObj);
1615 CPPUNIT_ASSERT_MESSAGE("Failed to retrieve non rotated user data for this object.", pNData);
1616 CPPUNIT_ASSERT_MESSAGE("Bounding rectangle should have been calculated upon import.",
1617 !pNData->getShapeRect().IsEmpty());
1619 // Check if data has moved to new rows
1620 CPPUNIT_ASSERT_EQUAL(pData->maStart.Col(), SCCOL(aDataStart.Col() + 1));
1621 CPPUNIT_ASSERT_EQUAL(pData->maEnd.Col(), SCCOL(aDataEnd.Col() + 1));
1623 CPPUNIT_ASSERT_EQUAL(pNData->maStart.Col(), SCCOL(aNDataStart.Col() + 1));
1624 CPPUNIT_ASSERT_EQUAL(pNData->maEnd.Col(), SCCOL(aNDataEnd.Col() + 1));
1626 // Save the anchor data
1627 aDataStart = pData->maStart;
1628 aDataEnd = pData->maEnd;
1629 aNDataStart = pNData->maStart;
1630 aNDataEnd = pNData->maEnd;
1632 // Save the document and load again to check anchor persist
1633 saveAndReload("calc8");
1635 // There are two cell-anchored objects on the first sheet.
1636 pDoc = getScDoc();
1638 CPPUNIT_ASSERT_MESSAGE("There should be at least one sheet.", pDoc->GetTableCount() > 0);
1640 pDrawLayer = pDoc->GetDrawLayer();
1641 pPage = pDrawLayer->GetPage(0);
1642 CPPUNIT_ASSERT_MESSAGE("draw page for sheet 1 should exist.", pPage);
1643 pObj = pPage->GetObj(0);
1644 CPPUNIT_ASSERT_MESSAGE("Failed to get drawing object.", pObj);
1646 // Check cell anchor state
1647 oldType = ScDrawLayer::GetAnchorType(*pObj);
1648 CPPUNIT_ASSERT_EQUAL_MESSAGE("Failed to get anchor type", SCA_CELL_RESIZE, oldType);
1650 // Get anchor data
1651 pData = ScDrawLayer::GetObjData(pObj);
1652 CPPUNIT_ASSERT_MESSAGE("Failed to retrieve user data for this object.", pData);
1653 CPPUNIT_ASSERT_MESSAGE("Bounding rectangle should have been calculated upon import.",
1654 !pData->getShapeRect().IsEmpty());
1656 // Get non rotated anchor data
1657 pNData = ScDrawLayer::GetNonRotatedObjData(pObj);
1658 CPPUNIT_ASSERT_MESSAGE("Failed to retrieve non rotated user data for this object.", pNData);
1659 CPPUNIT_ASSERT_MESSAGE("Bounding rectangle should have been calculated upon import.",
1660 !pNData->getShapeRect().IsEmpty());
1662 // Check if data after save it
1663 CPPUNIT_ASSERT_EQUAL(pData->maStart, aDataStart);
1664 CPPUNIT_ASSERT_EQUAL(pData->maEnd, aDataEnd);
1666 CPPUNIT_ASSERT_EQUAL(pNData->maStart, aNDataStart);
1667 CPPUNIT_ASSERT_EQUAL(pNData->maEnd, aNDataEnd);
1670 CPPUNIT_TEST_FIXTURE(ScExportTest3, testConditionalFormatRangeListXLSX)
1672 createScDoc("ods/conditionalformat_rangelist.ods");
1673 save("Calc Office Open XML");
1674 xmlDocUniquePtr pDoc = parseExport("xl/worksheets/sheet1.xml");
1675 CPPUNIT_ASSERT(pDoc);
1676 assertXPath(pDoc, "//x:conditionalFormatting"_ostr, "sqref"_ostr, "F4 F10");
1679 CPPUNIT_TEST_FIXTURE(ScExportTest3, testConditionalFormatContainsTextXLSX)
1681 createScDoc("ods/conditionalformat_containstext.ods");
1682 save("Calc Office Open XML");
1683 xmlDocUniquePtr pDoc = parseExport("xl/worksheets/sheet1.xml");
1684 CPPUNIT_ASSERT(pDoc);
1685 assertXPathContent(pDoc, "//x:conditionalFormatting/x:cfRule/x:formula"_ostr,
1686 "NOT(ISERROR(SEARCH(\"test\",A1)))");
1689 CPPUNIT_TEST_FIXTURE(ScExportTest3, testConditionalFormatPriorityCheckXLSX)
1691 createScDoc("xlsx/conditional_fmt_checkpriority.xlsx");
1692 save("Calc Office Open XML");
1693 xmlDocUniquePtr pDoc = parseExport("xl/worksheets/sheet1.xml");
1694 CPPUNIT_ASSERT(pDoc);
1695 constexpr bool bHighPriorityExtensionA1
1696 = true; // Should A1's extension cfRule has higher priority than normal cfRule ?
1697 constexpr bool bHighPriorityExtensionA3
1698 = false; // Should A3's extension cfRule has higher priority than normal cfRule ?
1699 size_t nA1NormalPriority = 0;
1700 size_t nA1ExtPriority = 0;
1701 size_t nA3NormalPriority = 0;
1702 size_t nA3ExtPriority = 0;
1703 for (size_t nIdx = 1; nIdx <= 2; ++nIdx)
1705 OString aIdx = OString::number(nIdx);
1706 OUString aCellAddr
1707 = getXPath(pDoc, "//x:conditionalFormatting[" + aIdx + "]", "sqref"_ostr);
1708 OUString aPriority
1709 = getXPath(pDoc, "//x:conditionalFormatting[" + aIdx + "]/x:cfRule", "priority"_ostr);
1710 CPPUNIT_ASSERT_MESSAGE("conditionalFormatting sqref must be either A1 or A3",
1711 aCellAddr == "A1" || aCellAddr == "A3");
1712 if (aCellAddr == "A1")
1713 nA1NormalPriority = aPriority.toUInt32();
1714 else
1715 nA3NormalPriority = aPriority.toUInt32();
1716 aCellAddr = getXPathContent(
1717 pDoc, "//x:extLst/x:ext[1]/x14:conditionalFormattings/x14:conditionalFormatting[" + aIdx
1718 + "]/xm:sqref");
1719 aPriority
1720 = getXPath(pDoc,
1721 "//x:extLst/x:ext[1]/x14:conditionalFormattings/x14:conditionalFormatting["
1722 + aIdx + "]/x14:cfRule",
1723 "priority"_ostr);
1724 CPPUNIT_ASSERT_MESSAGE("x14:conditionalFormatting sqref must be either A1 or A3",
1725 aCellAddr == "A1" || aCellAddr == "A3");
1726 if (aCellAddr == "A1")
1727 nA1ExtPriority = aPriority.toUInt32();
1728 else
1729 nA3ExtPriority = aPriority.toUInt32();
1731 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong priorities for A1", bHighPriorityExtensionA1,
1732 nA1ExtPriority < nA1NormalPriority);
1733 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong priorities for A3", bHighPriorityExtensionA3,
1734 nA3ExtPriority < nA3NormalPriority);
1737 CPPUNIT_TEST_FIXTURE(ScExportTest3, testConditionalFormatOriginXLSX)
1739 createScDoc("xlsx/conditional_fmt_origin.xlsx");
1740 save("Calc Office Open XML");
1741 xmlDocUniquePtr pDoc = parseExport("xl/worksheets/sheet1.xml");
1742 CPPUNIT_ASSERT(pDoc);
1743 // tdf#124953 : The range-list is B3:C6 F1:G2, origin address in the formula should be B1, not B3.
1744 OUString aFormula = getXPathContent(pDoc, "//x:conditionalFormatting/x:cfRule/x:formula"_ostr);
1745 CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong origin address in formula",
1746 OUString("NOT(ISERROR(SEARCH(\"BAC\",B1)))"), aFormula);
1749 // FILESAVE: XLSX export with long sheet names (length > 31 characters)
1750 CPPUNIT_TEST_FIXTURE(ScExportTest3, testTdf79998)
1752 // check: original document has tab name > 31 characters
1753 createScDoc("ods/tdf79998.ods");
1754 ScDocument* pDoc = getScDoc();
1755 const std::vector<OUString> aTabNames1 = pDoc->GetAllTableNames();
1756 CPPUNIT_ASSERT_EQUAL(OUString("Utilities (FX Kurse, Kreditkarten etc)"), aTabNames1[1]);
1758 // check: saved XLSX document has truncated tab name
1759 saveAndReload("Calc Office Open XML");
1760 pDoc = getScDoc();
1761 const std::vector<OUString> aTabNames2 = pDoc->GetAllTableNames();
1762 CPPUNIT_ASSERT_EQUAL(OUString("Utilities (FX Kurse, Kreditkart"), aTabNames2[1]);
1765 static void impl_testLegacyCellAnchoredRotatedShape(ScDocument& rDoc, const tools::Rectangle& aRect,
1766 const ScDrawObjData& aAnchor,
1767 tools::Long TOLERANCE = 30 /* 30 hmm */)
1769 ScDrawLayer* pDrawLayer = rDoc.GetDrawLayer();
1770 CPPUNIT_ASSERT_MESSAGE("No drawing layer.", pDrawLayer);
1771 SdrPage* pPage = pDrawLayer->GetPage(0);
1772 CPPUNIT_ASSERT_MESSAGE("No page instance for the 1st sheet.", pPage);
1773 CPPUNIT_ASSERT_EQUAL(static_cast<size_t>(1), pPage->GetObjCount());
1775 SdrObject* pObj = pPage->GetObj(0);
1776 const tools::Rectangle& aSnap = pObj->GetSnapRect();
1777 CPPUNIT_ASSERT_DOUBLES_EQUAL(aRect.GetHeight(), aSnap.GetHeight(), TOLERANCE);
1778 CPPUNIT_ASSERT_DOUBLES_EQUAL(aRect.GetWidth(), aSnap.GetWidth(), TOLERANCE);
1779 CPPUNIT_ASSERT_DOUBLES_EQUAL(aRect.Left(), aSnap.Left(), TOLERANCE);
1780 CPPUNIT_ASSERT_DOUBLES_EQUAL(aRect.Top(), aSnap.Top(), TOLERANCE);
1782 ScDrawObjData* pData = ScDrawLayer::GetObjData(pObj);
1783 CPPUNIT_ASSERT_MESSAGE("expected object meta data", pData);
1784 CPPUNIT_ASSERT_EQUAL(aAnchor.maStart.Row(), pData->maStart.Row());
1785 CPPUNIT_ASSERT_EQUAL(aAnchor.maStart.Col(), pData->maStart.Col());
1786 CPPUNIT_ASSERT_EQUAL(aAnchor.maEnd.Row(), pData->maEnd.Row());
1787 CPPUNIT_ASSERT_EQUAL(aAnchor.maEnd.Col(), pData->maEnd.Col());
1790 CPPUNIT_TEST_FIXTURE(ScExportTest3, testLegacyCellAnchoredRotatedShape)
1793 // This example doc contains cell anchored shape that is rotated, the
1794 // rotated shape is in fact clipped by the sheet boundaries (and thus
1795 // is a good edge case test to see if we import it still correctly)
1796 createScDoc("ods/legacycellanchoredrotatedclippedshape.ods");
1798 ScDocument* pDoc = getScDoc();
1799 // ensure the imported legacy rotated shape is in the expected position
1800 tools::Rectangle aRect(6000, -2000, 8000, 4000);
1801 // ensure the imported ( and converted ) anchor ( note we internally now store the anchor in
1802 // terms of the rotated shape ) is more or less contains the correct info
1803 ScDrawObjData aAnchor;
1804 aAnchor.maStart.SetRow(0);
1805 aAnchor.maStart.SetCol(5);
1806 aAnchor.maEnd.SetRow(3);
1807 aAnchor.maEnd.SetCol(7);
1808 impl_testLegacyCellAnchoredRotatedShape(*pDoc, aRect, aAnchor);
1809 // test save and reload
1810 // for some reason having this test in subsequent_export-test.cxx causes
1811 // a core dump in editeng ( so moved to here )
1812 saveAndReload("calc8");
1813 pDoc = getScDoc();
1814 impl_testLegacyCellAnchoredRotatedShape(*pDoc, aRect, aAnchor);
1817 // This example doc contains cell anchored shape that is rotated, the
1818 // rotated shape is in fact clipped by the sheet boundaries, additionally
1819 // the shape is completely hidden because the rows the shape occupies
1820 // are hidden
1821 createScDoc("ods/legacycellanchoredrotatedhiddenshape.ods");
1822 ScDocument* pDoc = getScDoc();
1823 // ensure the imported legacy rotated shape is in the expected position
1824 tools::Rectangle aRect(6000, -2000, 8000, 4000);
1826 // ensure the imported (and converted) anchor (note we internally now store the anchor in
1827 // terms of the rotated shape) is more or less contains the correct info
1828 ScDrawObjData aAnchor;
1829 aAnchor.maStart.SetRow(0);
1830 aAnchor.maStart.SetCol(5);
1831 aAnchor.maEnd.SetRow(3);
1832 aAnchor.maEnd.SetCol(7);
1833 pDoc->ShowRows(0, 9, 0, true); // show relevant rows
1834 pDoc->SetDrawPageSize(0); // trigger recalcpos
1835 impl_testLegacyCellAnchoredRotatedShape(*pDoc, aRect, aAnchor);
1836 // test save and reload
1837 saveAndReload("calc8");
1838 pDoc = getScDoc();
1839 impl_testLegacyCellAnchoredRotatedShape(*pDoc, aRect, aAnchor);
1842 // This example doc contains cell anchored shape that is rotated
1843 createScDoc("ods/legacycellanchoredrotatedshape.ods");
1845 ScDocument* pDoc = getScDoc();
1846 // ensure the imported legacy rotated shape is in the expected position
1847 tools::Rectangle aRect(6000, 3000, 8000, 9000);
1848 // ensure the imported (and converted) anchor (note we internally now store the anchor in
1849 // terms of the rotated shape) more or less contains the correct info
1851 ScDrawObjData aAnchor;
1852 aAnchor.maStart.SetRow(3);
1853 aAnchor.maStart.SetCol(6);
1854 aAnchor.maEnd.SetRow(9);
1855 aAnchor.maEnd.SetCol(8);
1856 // test import
1857 impl_testLegacyCellAnchoredRotatedShape(*pDoc, aRect, aAnchor);
1858 // test save and reload
1859 saveAndReload("calc8");
1860 pDoc = getScDoc();
1861 impl_testLegacyCellAnchoredRotatedShape(*pDoc, aRect, aAnchor);
1865 CPPUNIT_TEST_FIXTURE(ScExportTest3, testTdf113646)
1867 createScDoc("ods/tdf113646.ods");
1869 save("Calc Office Open XML");
1870 xmlDocUniquePtr pSheet = parseExport("xl/styles.xml");
1871 CPPUNIT_ASSERT(pSheet);
1873 assertXPath(pSheet, "/x:styleSheet/x:dxfs/x:dxf/x:font/x:sz"_ostr, "val"_ostr, "36");
1876 CPPUNIT_TEST_FIXTURE(ScExportTest3, testDateStandardfilterXLSX)
1878 // XLSX Roundtripping standard filter with date
1879 createScDoc("ods/tdf142607.ods");
1881 save("Calc Office Open XML");
1882 xmlDocUniquePtr pDoc = parseExport("xl/worksheets/sheet1.xml");
1883 CPPUNIT_ASSERT(pDoc);
1885 assertXPath(pDoc, "//x:autoFilter"_ostr, "ref"_ostr, "A1:B6");
1886 assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]"_ostr, "day"_ostr,
1887 "03");
1888 assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]"_ostr,
1889 "month"_ostr, "12");
1890 assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]"_ostr,
1891 "year"_ostr, "2011");
1892 assertXPath(pDoc, "//x:autoFilter/x:filterColumn/x:filters/x:dateGroupItem[1]"_ostr,
1893 "dateTimeGrouping"_ostr, "day");
1896 CPPUNIT_TEST_FIXTURE(ScExportTest3, testNumberFormatODS)
1898 createScDoc("ods/testNumberFormats.ods");
1899 saveAndReload("calc8");
1900 ScDocument* pDoc = getScDoc();
1901 sal_uInt32 nNumberFormat;
1902 const sal_Int32 nCountFormats = 18;
1903 const OUString aExpectedFormatStr[nCountFormats]
1904 = { "\"format=\"000000", "\"format=\"??????", "\"format=\"??0000",
1905 "\"format=\"000,000", "\"format=\"???,???", "\"format=\"??0,000",
1906 "\"format=\"000\" \"?/?", "\"format=\"???\" \"?/?", "\"format=\"?00\" \"?/?",
1907 "\"format=\"0,000\" \"?/?", "\"format=\"?,???\" \"?/?", "\"format=\"?,?00\" \"?/?",
1908 "\"format=\"0.000E+00", "\"format=\"?.###E+00", "\"format=\"?.0##E+00",
1909 "\"format=\"000E+00", "\"format=\"???E+00", "\"format=\"?00E+00" };
1910 for (sal_Int32 i = 0; i < nCountFormats; i++)
1912 nNumberFormat = pDoc->GetNumberFormat(i + 1, 2, 0);
1913 const SvNumberformat* pNumberFormat = pDoc->GetFormatTable()->GetEntry(nNumberFormat);
1914 const OUString& rFormatStr = pNumberFormat->GetFormatstring();
1915 CPPUNIT_ASSERT_EQUAL_MESSAGE("Number format modified during export/import",
1916 aExpectedFormatStr[i], rFormatStr);
1918 OUString aCSVPath = createFilePath(u"contentCSV/testNumberFormats.csv");
1919 testCondFile(aCSVPath, &*pDoc, 0,
1920 false); // comma is thousand separator and cannot be used as delimiter
1923 CPPUNIT_TEST_FIXTURE(ScExportTest3, testTdf137576_Measureline)
1925 // The document contains a vertical measure line, anchored "To Cell (resize with cell)" with
1926 // length 37mm. Save and reload had resulted in a line of 0mm length.
1928 // Get document
1929 createScDoc("ods/tdf137576_Measureline.ods");
1930 ScDocument* pDoc = getScDoc();
1932 // Get shape
1933 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1934 CPPUNIT_ASSERT_MESSAGE("Load: No ScDrawLayer", pDrawLayer);
1935 SdrPage* pPage = pDrawLayer->GetPage(0);
1936 CPPUNIT_ASSERT_MESSAGE("Load: No draw page", pPage);
1937 SdrMeasureObj* pObj = static_cast<SdrMeasureObj*>(pPage->GetObj(0));
1938 CPPUNIT_ASSERT_MESSAGE("Load: No measure object", pObj);
1940 // Check start and end point of measureline
1941 const Point aStart = pObj->GetPoint(0);
1942 CPPUNIT_ASSERT_POINT_EQUAL_WITH_TOLERANCE(Point(4800, 1500), aStart, 1);
1943 const Point aEnd = pObj->GetPoint(1);
1944 CPPUNIT_ASSERT_POINT_EQUAL_WITH_TOLERANCE(Point(4800, 5200), aEnd, 1);
1946 // Save and reload
1947 saveAndReload("calc8");
1948 pDoc = getScDoc();
1950 // Get shape
1951 pDrawLayer = pDoc->GetDrawLayer();
1952 CPPUNIT_ASSERT_MESSAGE("Reload: No ScDrawLayer", pDrawLayer);
1953 pPage = pDrawLayer->GetPage(0);
1954 CPPUNIT_ASSERT_MESSAGE("Reload: No draw page", pPage);
1955 pObj = static_cast<SdrMeasureObj*>(pPage->GetObj(0));
1956 CPPUNIT_ASSERT_MESSAGE("Reload: No measure object", pObj);
1958 // Check start and end point of measureline, should be unchanged
1959 const Point aStart2 = pObj->GetPoint(0);
1960 CPPUNIT_ASSERT_POINT_EQUAL_WITH_TOLERANCE(Point(4800, 1500), aStart2, 1);
1961 const Point aEnd2 = pObj->GetPoint(1);
1962 CPPUNIT_ASSERT_POINT_EQUAL_WITH_TOLERANCE(Point(4800, 5200), aEnd2, 1);
1965 CPPUNIT_TEST_FIXTURE(ScExportTest3, testTdf137044_CoverHiddenRows)
1967 // The document contains a shape anchored "To Cell (resize with cell)" with start in cell A4 and
1968 // end in cell A7. Row height is 30mm. Hiding rows 5 and 6, then saving and reload had resulted
1969 // in a wrong end cell offset and thus a wrong height of the shape.
1971 // Get document
1972 createScDoc("ods/tdf137044_CoverHiddenRows.ods");
1973 ScDocument* pDoc = getScDoc();
1975 // Get shape
1976 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
1977 CPPUNIT_ASSERT_MESSAGE("Load: No ScDrawLayer", pDrawLayer);
1978 SdrPage* pPage = pDrawLayer->GetPage(0);
1979 CPPUNIT_ASSERT_MESSAGE("Load: No draw page", pPage);
1980 SdrObject* pObj = pPage->GetObj(0);
1981 CPPUNIT_ASSERT_MESSAGE("Load: No object", pObj);
1983 // Get original object values
1984 tools::Rectangle aSnapRectOrig = pObj->GetSnapRect();
1985 Point aOriginalEndOffset = ScDrawLayer::GetObjData(pObj)->maEndOffset;
1986 CPPUNIT_ASSERT_RECTANGLE_EQUAL_WITH_TOLERANCE(
1987 tools::Rectangle(Point(500, 3500), Size(1501, 11001)), aSnapRectOrig, 1);
1988 CPPUNIT_ASSERT_POINT_EQUAL_WITH_TOLERANCE(Point(2000, 2499), aOriginalEndOffset, 1);
1990 // Hide rows 5 and 6 in UI = row index 4 to 5.
1991 pDoc->SetRowHidden(4, 5, 0, true);
1993 // Save and reload
1994 saveAndReload("calc8");
1995 pDoc = getScDoc();
1997 // Get shape
1998 pDrawLayer = pDoc->GetDrawLayer();
1999 CPPUNIT_ASSERT_MESSAGE("Reload: No ScDrawLayer", pDrawLayer);
2000 pPage = pDrawLayer->GetPage(0);
2001 CPPUNIT_ASSERT_MESSAGE("Reload: No draw page", pPage);
2002 pObj = pPage->GetObj(0);
2003 CPPUNIT_ASSERT_MESSAGE("Reload: No object", pObj);
2005 // Get new values and compare. End offset should be the same, height should be 6000 smaller.
2006 tools::Rectangle aSnapRectReload = pObj->GetSnapRect();
2007 Point aReloadEndOffset = ScDrawLayer::GetObjData(pObj)->maEndOffset;
2008 CPPUNIT_ASSERT_RECTANGLE_EQUAL_WITH_TOLERANCE(
2009 tools::Rectangle(Point(500, 3500), Size(1501, 5001)), aSnapRectReload, 1);
2010 CPPUNIT_ASSERT_POINT_EQUAL_WITH_TOLERANCE(Point(2000, 2499), aReloadEndOffset, 1);
2013 CPPUNIT_TEST_FIXTURE(ScExportTest3, testTdf137020_FlipVertical)
2015 // Get document
2016 createScDoc("ods/tdf137020_FlipVertical.ods");
2017 ScDocument* pDoc = getScDoc();
2019 // Get shape
2020 ScDrawLayer* pDrawLayer = pDoc->GetDrawLayer();
2021 CPPUNIT_ASSERT_MESSAGE("Load: No ScDrawLayer", pDrawLayer);
2022 SdrPage* pPage = pDrawLayer->GetPage(0);
2023 CPPUNIT_ASSERT_MESSAGE("Load: No draw page", pPage);
2024 SdrObject* pObj = pPage->GetObj(0);
2025 CPPUNIT_ASSERT_MESSAGE("Load: No object", pObj);
2027 const tools::Rectangle aSnapRectOrig = pObj->GetSnapRect();
2029 // Vertical mirror on center should not change the snap rect.
2030 pObj->Mirror(aSnapRectOrig.LeftCenter(), aSnapRectOrig.RightCenter());
2031 const tools::Rectangle aSnapRectFlip = pObj->GetSnapRect();
2032 CPPUNIT_ASSERT_RECTANGLE_EQUAL_WITH_TOLERANCE(aSnapRectOrig, aSnapRectFlip, 1);
2034 // Save and reload
2035 saveAndReload("calc8");
2036 pDoc = getScDoc();
2038 // Get shape
2039 pDrawLayer = pDoc->GetDrawLayer();
2040 CPPUNIT_ASSERT_MESSAGE("Reload: No ScDrawLayer", pDrawLayer);
2041 pPage = pDrawLayer->GetPage(0);
2042 CPPUNIT_ASSERT_MESSAGE("Reload: No draw page", pPage);
2043 pObj = pPage->GetObj(0);
2044 CPPUNIT_ASSERT_MESSAGE("Reload: No object", pObj);
2046 // Check pos and size of shape again, should be unchanged
2047 const tools::Rectangle aSnapRectReload = pObj->GetSnapRect();
2048 CPPUNIT_ASSERT_RECTANGLE_EQUAL_WITH_TOLERANCE(aSnapRectOrig, aSnapRectReload, 1);
2051 CPPUNIT_TEST_FIXTURE(ScExportTest3, testTdf82254_csv_bom)
2053 setImportFilterName(SC_TEXT_CSV_FILTER_NAME);
2054 createScDoc("csv/testTdf82254-csv-bom.csv");
2055 saveAndReload(SC_TEXT_CSV_FILTER_NAME);
2056 ScDocShell* pDocSh = getScDocShell();
2057 SvStream* pStream = pDocSh->GetMedium()->GetInStream();
2059 pStream->Seek(0);
2060 CPPUNIT_ASSERT_EQUAL(sal_uInt64(0), pStream->Tell());
2061 pStream->StartReadingUnicodeText(RTL_TEXTENCODING_UTF8);
2062 // Without the fix in place, this test would have failed with
2063 // - Expected: 3
2064 // - Actual : 0 (no byte order mark was read)
2065 CPPUNIT_ASSERT_EQUAL(sal_uInt64(3), pStream->Tell());
2068 CPPUNIT_PLUGIN_IMPLEMENT();
2070 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */