nss: upgrade to release 3.73
[LibreOffice.git] / sc / qa / unit / copy_paste_test.cxx
blob6c91afad30ea8cdd6a8ceff55d1baa6b2d955e8b
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 <sal/config.h>
11 #include <test/bootstrapfixture.hxx>
12 #include <comphelper/processfactory.hxx>
14 #include <docsh.hxx>
15 #include <docfunc.hxx>
16 #include <cellmergeoption.hxx>
17 #include <tabvwsh.hxx>
18 #include <impex.hxx>
19 #include <viewfunc.hxx>
20 #include <scitems.hxx>
21 #include <attrib.hxx>
22 #include <userlist.hxx>
24 #include <com/sun/star/frame/Desktop.hpp>
25 #include <com/sun/star/frame/XModel2.hpp>
27 #include "helper/qahelper.hxx"
29 using namespace ::com::sun::star;
30 using namespace ::com::sun::star::uno;
32 class ScCopyPasteTest : public ScBootstrapFixture
34 public:
35 ScCopyPasteTest();
37 virtual void setUp() override;
38 virtual void tearDown() override;
40 void testCopyPasteXLS();
41 void testTdf84411();
42 void testTdf124565();
43 void testTdf126421();
44 void testTdf107394();
45 void testTdf53431_fillOnAutofilter();
46 void testTdf40993_fillMergedCells();
47 void testTdf43958_clickSelectOnMergedCells();
48 void testTdf88782_autofillLinearNumbersInMergedCells();
49 void tdf137621_autofillMergedBool();
50 void tdf137205_autofillDatesInMergedCells();
51 void tdf137653_137654_autofillUserlist();
52 void tdf113500_autofillMixed();
53 void tdf137625_autofillMergedUserlist();
54 void tdf137624_autofillMergedMixed();
56 CPPUNIT_TEST_SUITE(ScCopyPasteTest);
57 CPPUNIT_TEST(testCopyPasteXLS);
58 CPPUNIT_TEST(testTdf84411);
59 CPPUNIT_TEST(testTdf124565);
60 CPPUNIT_TEST(testTdf126421);
61 CPPUNIT_TEST(testTdf107394);
62 CPPUNIT_TEST(testTdf53431_fillOnAutofilter);
63 CPPUNIT_TEST(testTdf40993_fillMergedCells);
64 CPPUNIT_TEST(testTdf43958_clickSelectOnMergedCells);
65 CPPUNIT_TEST(testTdf88782_autofillLinearNumbersInMergedCells);
66 CPPUNIT_TEST(tdf137621_autofillMergedBool);
67 CPPUNIT_TEST(tdf137205_autofillDatesInMergedCells);
68 CPPUNIT_TEST(tdf137653_137654_autofillUserlist);
69 CPPUNIT_TEST(tdf113500_autofillMixed);
70 CPPUNIT_TEST(tdf137625_autofillMergedUserlist);
71 CPPUNIT_TEST(tdf137624_autofillMergedMixed);
72 CPPUNIT_TEST_SUITE_END();
74 private:
76 ScDocShellRef loadDocAndSetupModelViewController(const OUString& rFileName, sal_Int32 nFormat, bool bReadWrite);
77 void addToUserList(const OUString& rStr);
78 uno::Reference<uno::XInterface> m_xCalcComponent;
81 // tdf#83366
82 void ScCopyPasteTest::testCopyPasteXLS()
84 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(::comphelper::getProcessComponentContext());
85 CPPUNIT_ASSERT( xDesktop.is() );
87 // create a frame
88 Reference< frame::XFrame > xTargetFrame = xDesktop->findFrame( "_blank", 0 );
89 CPPUNIT_ASSERT( xTargetFrame.is() );
91 // 1. Open the document
92 ScDocShellRef xDocSh = loadDoc("chartx2.", FORMAT_XLS);
93 CPPUNIT_ASSERT_MESSAGE("Failed to load chartx2.xls.", xDocSh.is());
95 uno::Reference< frame::XModel2 > xModel2 ( xDocSh->GetModel(), UNO_QUERY );
96 CPPUNIT_ASSERT( xModel2.is() );
98 Reference< frame::XController2 > xController = xModel2->createDefaultViewController( xTargetFrame );
99 CPPUNIT_ASSERT( xController.is() );
101 // introduce model/view/controller to each other
102 xController->attachModel( xModel2.get() );
103 xModel2->connectController( xController.get() );
104 xTargetFrame->setComponent( xController->getComponentWindow(), xController.get() );
105 xController->attachFrame( xTargetFrame );
106 xModel2->setCurrentController( xController.get() );
108 ScDocument& rDoc = xDocSh->GetDocument();
110 // Get the document controller
111 ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false);
112 CPPUNIT_ASSERT(pViewShell != nullptr);
114 // 2. Highlight B2:C5
115 ScRange aSrcRange;
116 ScRefFlags nRes = aSrcRange.Parse("B2:C5", rDoc, rDoc.GetAddressConvention());
117 CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & ScRefFlags::VALID));
119 ScMarkData aMark(rDoc.GetSheetLimits());
120 aMark.SetMarkArea(aSrcRange);
122 pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange);
124 // 3. Copy
125 ScDocument aClipDoc(SCDOCMODE_CLIP);
126 pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, false, false);
128 // 4. Close the document (Ctrl-W)
129 xDocSh->DoClose();
131 // 5. Create a new Spreadsheet
132 Sequence < beans::PropertyValue > args(1);
133 args[0].Name = "Hidden";
134 args[0].Value <<= true;
136 uno::Reference< lang::XComponent > xComponent = xDesktop->loadComponentFromURL(
137 "private:factory/scalc",
138 "_blank",
140 args );
141 CPPUNIT_ASSERT( xComponent.is() );
143 // Get the document model
144 SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
145 CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
147 xDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
148 CPPUNIT_ASSERT(xDocSh);
150 // Get the document controller
151 pViewShell = xDocSh->GetBestViewShell(false);
152 CPPUNIT_ASSERT(pViewShell != nullptr);
154 // 6. Paste
155 pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc);
157 xComponent->dispose();
160 namespace {
162 ScMarkData::MarkedTabsType TabsInRange(const ScRange& r)
164 ScMarkData::MarkedTabsType aResult;
165 for (SCTAB i = r.aStart.Tab(); i <= r.aEnd.Tab(); ++i)
166 aResult.insert(i);
167 return aResult;
170 void lcl_copy( const OUString& rSrcRange, const OUString& rDstRange, ScDocument& rDoc, ScTabViewShell* pViewShell )
172 ScDocument aClipDoc(SCDOCMODE_CLIP);
174 // 1. Copy
175 ScRange aSrcRange;
176 ScRefFlags nRes = aSrcRange.Parse(rSrcRange, rDoc, rDoc.GetAddressConvention());
177 CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & ScRefFlags::VALID));
178 pViewShell->GetViewData().GetMarkData().SetMarkArea(aSrcRange);
179 pViewShell->GetViewData().GetMarkData().SetSelectedTabs(TabsInRange(aSrcRange));
180 pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, false, false);
182 // 2. Paste
183 ScRange aDstRange;
184 nRes = aDstRange.Parse(rDstRange, rDoc, rDoc.GetAddressConvention());
185 CPPUNIT_ASSERT_MESSAGE("Failed to parse.", (nRes & ScRefFlags::VALID));
186 pViewShell->GetViewData().GetMarkData().SetMarkArea(aDstRange);
187 pViewShell->GetViewData().GetMarkData().SetSelectedTabs(TabsInRange(aDstRange));
188 pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc);
191 } // anonymous namespace
193 void ScCopyPasteTest::testTdf84411()
195 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(::comphelper::getProcessComponentContext());
196 CPPUNIT_ASSERT( xDesktop.is() );
198 // create a frame
199 Reference< frame::XFrame > xTargetFrame = xDesktop->findFrame( "_blank", 0 );
200 CPPUNIT_ASSERT( xTargetFrame.is() );
202 // 1. Create spreadsheet
203 uno::Sequence< beans::PropertyValue > aEmptyArgList;
204 uno::Reference< lang::XComponent > xComponent = xDesktop->loadComponentFromURL(
205 "private:factory/scalc",
206 "_blank",
208 aEmptyArgList );
209 CPPUNIT_ASSERT( xComponent.is() );
211 // Get the document model
212 SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
213 CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
215 ScDocShellRef xDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
216 CPPUNIT_ASSERT(xDocSh);
218 uno::Reference< frame::XModel2 > xModel2 ( xDocSh->GetModel(), UNO_QUERY );
219 CPPUNIT_ASSERT( xModel2.is() );
221 Reference< frame::XController2 > xController = xModel2->createDefaultViewController( xTargetFrame );
222 CPPUNIT_ASSERT( xController.is() );
224 // introduce model/view/controller to each other
225 xController->attachModel( xModel2.get() );
226 xModel2->connectController( xController.get() );
227 xTargetFrame->setComponent( xController->getComponentWindow(), xController.get() );
228 xController->attachFrame( xTargetFrame );
229 xModel2->setCurrentController( xController.get() );
231 ScDocument& rDoc = xDocSh->GetDocument();
233 // Get the document controller
234 ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false);
235 CPPUNIT_ASSERT(pViewShell != nullptr);
238 // 2. Setup data and formulas
239 for (unsigned int r = 0; r <= 4991; ++r)
240 for (unsigned int c = 0; c <= 14; ++c)
241 rDoc.SetValue( ScAddress(c,r,0), (r+1)*(c+1) );
243 rDoc.SetString(ScAddress(15,10000,0), "=AVERAGE(A10001:O10001)");
244 rDoc.SetString(ScAddress(16,10000,0), "=MIN(A10001:O10001)");
245 rDoc.SetString(ScAddress(17,10000,0), "=MAX(A10001:O10001)");
247 lcl_copy("P10001:R10001", "P10002:R12500", rDoc, pViewShell);
250 // 3. Disable OpenCL
251 ScModelObj* pModel = comphelper::getUnoTunnelImplementation<ScModelObj>(pFoundShell->GetModel());
252 CPPUNIT_ASSERT(pModel != nullptr);
253 bool bOpenCLState = ScCalcConfig::isOpenCLEnabled();
254 pModel->enableOpenCL(false);
255 CPPUNIT_ASSERT(!ScCalcConfig::isOpenCLEnabled() || ScCalcConfig::getForceCalculationType() == ForceCalculationOpenCL);
256 pModel->enableAutomaticCalculation(true);
259 // 4. Copy and Paste
260 lcl_copy("A1:O2500", "A10001:O12500", rDoc, pViewShell);
262 lcl_copy("A2501:O5000", "A12501:O15000", rDoc, pViewShell);
264 lcl_copy("P10001:R10001", "P12501:R15000", rDoc, pViewShell);
267 // 5. Close the document (Ctrl-W)
268 pModel->enableOpenCL(bOpenCLState);
269 xComponent->dispose();
272 void ScCopyPasteTest::testTdf124565()
274 // Create new document
275 ScDocShell* xDocSh = new ScDocShell(
276 SfxModelFlags::EMBEDDED_OBJECT |
277 SfxModelFlags::DISABLE_EMBEDDED_SCRIPTS |
278 SfxModelFlags::DISABLE_DOCUMENT_RECOVERY);
279 xDocSh->DoInitNew();
281 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(::comphelper::getProcessComponentContext());
282 CPPUNIT_ASSERT( xDesktop.is() );
284 Reference< frame::XFrame > xTargetFrame = xDesktop->findFrame( "_blank", 0 );
285 CPPUNIT_ASSERT( xTargetFrame.is() );
287 uno::Reference< frame::XModel2 > xModel2 ( xDocSh->GetModel(), UNO_QUERY );
288 CPPUNIT_ASSERT( xModel2.is() );
290 Reference< frame::XController2 > xController = xModel2->createDefaultViewController( xTargetFrame );
291 CPPUNIT_ASSERT( xController.is() );
293 // introduce model/view/controller to each other
294 xController->attachModel( xModel2.get() );
295 xModel2->connectController( xController.get() );
296 xTargetFrame->setComponent( xController->getComponentWindow(), xController.get() );
297 xController->attachFrame( xTargetFrame );
298 xModel2->setCurrentController( xController.get() );
300 ScDocument& rDoc = xDocSh->GetDocument();
301 ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false);
302 CPPUNIT_ASSERT(pViewShell != nullptr);
304 // Set content and height of first row
305 rDoc.SetString(ScAddress(0, 0, 0), "Test");
306 rDoc.SetRowHeight(0, 0, 500);
307 rDoc.SetManualHeight(0, 0, 0, true);
309 // Copy first row
310 ScDocument aClipDoc(SCDOCMODE_CLIP);
311 ScRange aCopyRange(0, 0, 0, aClipDoc.MaxCol(), 0, 0);
312 pViewShell->GetViewData().GetMarkData().SetMarkArea(aCopyRange);
313 pViewShell->GetViewData().GetView()->CopyToClip(&aClipDoc, false, false, false, false);
315 // Paste to second row
316 SCTAB nTab = 0;
317 SCCOL nCol = 0;
318 SCROW nRow = 1;
320 ScRange aPasteRange(nCol, nRow, nTab, aClipDoc.MaxCol(), nRow, nTab);
321 pViewShell->GetViewData().GetMarkData().SetMarkArea(aPasteRange);
322 pViewShell->GetViewData().GetView()->PasteFromClip(InsertDeleteFlags::ALL, &aClipDoc);
324 // Copy-pasted?
325 CPPUNIT_ASSERT_EQUAL_MESSAGE("String was not pasted!", OUString("Test"), rDoc.GetString(nCol, nRow, nTab));
327 // And height same as in source?
328 CPPUNIT_ASSERT_EQUAL_MESSAGE("Row#2 height is invalid!", sal_uInt16(500), rDoc.GetRowHeight(nRow, nTab));
330 CPPUNIT_ASSERT_MESSAGE("Row#2 must be manual height!", rDoc.IsManualRowHeight(nRow, nTab));
332 xDocSh->DoClose();
335 void ScCopyPasteTest::testTdf126421()
337 uno::Reference<frame::XDesktop2> xDesktop
338 = frame::Desktop::create(::comphelper::getProcessComponentContext());
339 CPPUNIT_ASSERT(xDesktop.is());
341 // create a frame
342 Reference<frame::XFrame> xTargetFrame = xDesktop->findFrame("_blank", 0);
343 CPPUNIT_ASSERT(xTargetFrame.is());
345 // 1. Create spreadsheet
346 uno::Sequence<beans::PropertyValue> aEmptyArgList;
347 uno::Reference<lang::XComponent> xComponent
348 = xDesktop->loadComponentFromURL("private:factory/scalc", "_blank", 0, aEmptyArgList);
349 CPPUNIT_ASSERT(xComponent.is());
351 // Get the document model
352 SfxObjectShell* pFoundShell = SfxObjectShell::GetShellFromComponent(xComponent);
353 CPPUNIT_ASSERT_MESSAGE("Failed to access document shell", pFoundShell);
355 ScDocShellRef xDocSh = dynamic_cast<ScDocShell*>(pFoundShell);
356 CPPUNIT_ASSERT(xDocSh);
358 uno::Reference<frame::XModel2> xModel2(xDocSh->GetModel(), UNO_QUERY);
359 CPPUNIT_ASSERT(xModel2.is());
361 Reference<frame::XController2> xController = xModel2->createDefaultViewController(xTargetFrame);
362 CPPUNIT_ASSERT(xController.is());
364 // introduce model/view/controller to each other
365 xController->attachModel(xModel2.get());
366 xModel2->connectController(xController.get());
367 xTargetFrame->setComponent(xController->getComponentWindow(), xController.get());
368 xController->attachFrame(xTargetFrame);
369 xModel2->setCurrentController(xController.get());
371 ScDocument& rDoc = xDocSh->GetDocument();
373 // Get the document controller
374 ScTabViewShell* pViewShell = xDocSh->GetBestViewShell(false);
375 CPPUNIT_ASSERT(pViewShell != nullptr);
377 // 2. Setup data
378 for (int r = 0; r < 2; ++r)
379 for (int c = 0; c < 1024; ++c)
380 rDoc.SetValue(c, r, 0, (c + 1) * 100 + (r + 1));
382 const SCTAB n2ndTab = rDoc.GetMaxTableNumber() + 1;
383 rDoc.MakeTable(n2ndTab);
384 const auto aTabNames = rDoc.GetAllTableNames();
386 lcl_copy(aTabNames[0] + ".A1:AMJ2", aTabNames[n2ndTab] + ".A1:AMJ2", rDoc, pViewShell);
388 // 3. Check all cells in destination table
389 for (int r = 0; r < 2; ++r)
390 for (int c = 0; c < 1024; ++c)
391 CPPUNIT_ASSERT_EQUAL(double((c + 1) * 100 + (r + 1)), rDoc.GetValue(c, r, n2ndTab));
393 xDocSh->DoClose();
396 void ScCopyPasteTest::testTdf107394()
398 uno::Reference<frame::XDesktop2> xDesktop
399 = frame::Desktop::create(::comphelper::getProcessComponentContext());
400 CPPUNIT_ASSERT(xDesktop.is());
402 uno::Reference<lang::XComponent> xComponent
403 = xDesktop->loadComponentFromURL("private:factory/scalc", "_blank", 0, {});
404 CPPUNIT_ASSERT(xComponent.is());
406 auto pModelObj = dynamic_cast<ScModelObj*>(xComponent.get());
407 CPPUNIT_ASSERT(pModelObj);
408 CPPUNIT_ASSERT(pModelObj->GetDocument());
410 ScDocument& rDoc = *pModelObj->GetDocument();
412 sal_uInt16 nFirstRowHeight = rDoc.GetRowHeight(0, 0);
413 sal_uInt16 nSecondRowHeight = rDoc.GetRowHeight(1, 0);
414 CPPUNIT_ASSERT_EQUAL(nFirstRowHeight, nSecondRowHeight);
416 // Import values to A1:A2.
417 ScImportExport aObj(rDoc, ScAddress(0,0,0));
418 aObj.SetImportBroadcast(true);
420 SvMemoryStream aStream;
421 aStream.WriteOString("<pre>First\nVery long sentence.</pre>");
422 aStream.Seek(0);
423 CPPUNIT_ASSERT(aObj.ImportStream(aStream, OUString(), SotClipboardFormatId::HTML));
425 CPPUNIT_ASSERT_EQUAL(OUString("First"), rDoc.GetString(ScAddress(0,0,0)));
426 CPPUNIT_ASSERT_EQUAL(OUString("Very long sentence."), rDoc.GetString(ScAddress(0,1,0)));
428 nFirstRowHeight = rDoc.GetRowHeight(0, 0);
429 nSecondRowHeight = rDoc.GetRowHeight(1, 0);
430 CPPUNIT_ASSERT_GREATER(nFirstRowHeight, nSecondRowHeight);
432 // Undo, and check the result.
433 SfxUndoManager* pUndoMgr = rDoc.GetUndoManager();
434 CPPUNIT_ASSERT_MESSAGE("Failed to get the undo manager.", pUndoMgr);
435 pUndoMgr->Undo();
437 CPPUNIT_ASSERT(rDoc.GetString(ScAddress(0,0,0)).isEmpty());
438 CPPUNIT_ASSERT(rDoc.GetString(ScAddress(0,1,0)).isEmpty());
440 nFirstRowHeight = rDoc.GetRowHeight(0, 0);
441 nSecondRowHeight = rDoc.GetRowHeight(1, 0);
442 // Without the accompanying fix in place, this test would have failed:
443 // - Expected: 256
444 // - Actual : 477
445 // i.e. the increased height of the second row remained after undo.
446 CPPUNIT_ASSERT_EQUAL(nFirstRowHeight, nSecondRowHeight);
448 xComponent->dispose();
451 static ScMF lcl_getMergeFlagOfCell(const ScDocument& rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab)
453 const SfxPoolItem& rPoolItem = rDoc.GetPattern(nCol, nRow, nTab)->GetItem(ATTR_MERGE_FLAG);
454 const ScMergeFlagAttr& rMergeFlag = static_cast<const ScMergeFlagAttr&>(rPoolItem);
455 return rMergeFlag.GetValue();
458 static ScAddress lcl_getMergeSizeOfCell(const ScDocument& rDoc, SCCOL nCol, SCROW nRow, SCTAB nTab)
460 const SfxPoolItem& rPoolItem = rDoc.GetPattern(nCol, nRow, nTab)->GetItem(ATTR_MERGE);
461 const ScMergeAttr& rMerge = static_cast<const ScMergeAttr&>(rPoolItem);
462 return ScAddress(rMerge.GetColMerge(), rMerge.GetRowMerge(), nTab);
465 ScDocShellRef ScCopyPasteTest::loadDocAndSetupModelViewController(const OUString& rFileName, sal_Int32 nFormat, bool bReadWrite)
467 uno::Reference< frame::XDesktop2 > xDesktop = frame::Desktop::create(::comphelper::getProcessComponentContext());
468 CPPUNIT_ASSERT(xDesktop.is());
470 // create a frame
471 Reference< frame::XFrame > xTargetFrame = xDesktop->findFrame("_blank", 0);
472 CPPUNIT_ASSERT(xTargetFrame.is());
474 // 1. Open the document
475 ScDocShellRef xDocSh = loadDoc(rFileName, nFormat, bReadWrite);
476 CPPUNIT_ASSERT_MESSAGE(OString("Failed to load " + OUStringToOString(rFileName, RTL_TEXTENCODING_UTF8)).getStr(), xDocSh.is());
478 uno::Reference< frame::XModel2 > xModel2(xDocSh->GetModel(), UNO_QUERY);
479 CPPUNIT_ASSERT(xModel2.is());
481 Reference< frame::XController2 > xController = xModel2->createDefaultViewController(xTargetFrame);
482 CPPUNIT_ASSERT(xController.is());
484 // introduce model/view/controller to each other
485 xController->attachModel(xModel2.get());
486 xModel2->connectController(xController.get());
487 xTargetFrame->setComponent(xController->getComponentWindow(), xController.get());
488 xController->attachFrame(xTargetFrame);
489 xModel2->setCurrentController(xController.get());
491 return xDocSh;
494 void ScCopyPasteTest::testTdf53431_fillOnAutofilter()
496 ScDocShellRef xDocSh = loadDocAndSetupModelViewController("tdf53431_autofilterFilldown.", FORMAT_ODS, true);
497 ScDocument& rDoc = xDocSh->GetDocument();
499 // Get the document controller
500 ScTabViewShell* pView = xDocSh->GetBestViewShell(false);
501 CPPUNIT_ASSERT(pView != nullptr);
503 //Fill should not clone Autofilter button
504 ScDocShell::GetViewData()->GetMarkData().SetMarkArea(ScRange(1, 1, 0, 2, 4, 0));
505 pView->FillSimple(FILL_TO_BOTTOM);
506 CPPUNIT_ASSERT((lcl_getMergeFlagOfCell(rDoc, 1, 1, 0) & ScMF::Auto));
507 CPPUNIT_ASSERT((lcl_getMergeFlagOfCell(rDoc, 2, 1, 0) & ScMF::Auto));
508 CPPUNIT_ASSERT(!(lcl_getMergeFlagOfCell(rDoc, 1, 4, 0) & ScMF::Auto));
510 ScDocShell::GetViewData()->GetMarkData().SetMarkArea(ScRange(1, 1, 0, 4, 4, 0));
511 pView->FillSimple(FILL_TO_RIGHT);
512 CPPUNIT_ASSERT((lcl_getMergeFlagOfCell(rDoc, 1, 1, 0) & ScMF::Auto));
513 CPPUNIT_ASSERT((lcl_getMergeFlagOfCell(rDoc, 2, 1, 0) & ScMF::Auto));
514 CPPUNIT_ASSERT(!(lcl_getMergeFlagOfCell(rDoc, 4, 1, 0) & ScMF::Auto));
515 CPPUNIT_ASSERT(!(lcl_getMergeFlagOfCell(rDoc, 1, 4, 0) & ScMF::Auto));
516 CPPUNIT_ASSERT(!(lcl_getMergeFlagOfCell(rDoc, 4, 4, 0) & ScMF::Auto));
518 //Fill should not delete Autofilter buttons
519 ScDocShell::GetViewData()->GetMarkData().SetMarkArea(ScRange(0, 0, 0, 2, 4, 0));
520 pView->FillSimple(FILL_TO_TOP);
521 CPPUNIT_ASSERT((lcl_getMergeFlagOfCell(rDoc, 1, 1, 0) & ScMF::Auto));
522 CPPUNIT_ASSERT((lcl_getMergeFlagOfCell(rDoc, 2, 1, 0) & ScMF::Auto));
523 CPPUNIT_ASSERT(!(lcl_getMergeFlagOfCell(rDoc, 1, 0, 0) & ScMF::Auto));
525 ScDocShell::GetViewData()->GetMarkData().SetMarkArea(ScRange(0, 0, 0, 4, 4, 0));
526 pView->FillSimple(FILL_TO_LEFT);
527 CPPUNIT_ASSERT((lcl_getMergeFlagOfCell(rDoc, 1, 1, 0) & ScMF::Auto));
528 CPPUNIT_ASSERT((lcl_getMergeFlagOfCell(rDoc, 2, 1, 0) & ScMF::Auto));
529 CPPUNIT_ASSERT(!(lcl_getMergeFlagOfCell(rDoc, 0, 1, 0) & ScMF::Auto));
532 void ScCopyPasteTest::testTdf40993_fillMergedCells()
534 ScDocShellRef xDocSh = loadDocAndSetupModelViewController("tdf40993_fillMergedCells.", FORMAT_ODS, true);
535 ScDocument& rDoc = xDocSh->GetDocument();
537 // Get the document controller
538 ScTabViewShell* pView = xDocSh->GetBestViewShell(false);
539 CPPUNIT_ASSERT(pView != nullptr);
541 // check content of the merged cell H11:I11
542 CPPUNIT_ASSERT_EQUAL(OUString("1.5"), rDoc.GetString(ScAddress(7, 10, 0)));
544 // fill operation on the merged cell should clone ATTR_MERGE and ATTR_MERGE_FLAG
545 // (as long as ATTR_MERGE_FLAG has only ScMF::Hor or ScMF::Ver)
547 // select merged cell
548 ScDocShell::GetViewData()->GetMarkData().SetMarkArea(ScRange(7, 10, 0, 8, 10, 0));
549 // copy its content in the next ten rows
550 pView->FillAuto(FILL_TO_BOTTOM, 7, 10, 8, 10, 10);
551 for (int i = 7; i < 9; i++)
553 ScMF nOriginFlag = lcl_getMergeFlagOfCell(rDoc, i, 10, 0);
554 ScAddress aOriginMerge = lcl_getMergeSizeOfCell(rDoc, i, 10, 0);
556 // ATTR_MERGE_FLAG: top left cell is NONE, the other cell shows horizontal overlapping
557 CPPUNIT_ASSERT_EQUAL(i == 7 ? ScMF::NONE : ScMF::Hor, nOriginFlag);
559 // ATTR_MERGE: top left cell contains the size of the
560 // merged area (2:1), the other cell doesn't
561 CPPUNIT_ASSERT_EQUAL(i == 7 ? ScAddress(2, 1, 0): ScAddress(0, 0, 0), aOriginMerge);
563 for (int j = 11; j < 21; j++)
565 // check copying of ATTR_MERGE and ATTR_MERGE_FLAG
566 CPPUNIT_ASSERT_EQUAL(lcl_getMergeFlagOfCell(rDoc, i, j, 0), nOriginFlag);
567 CPPUNIT_ASSERT_EQUAL(lcl_getMergeSizeOfCell(rDoc, i, j, 0), aOriginMerge);
571 CPPUNIT_ASSERT_EQUAL(lcl_getMergeFlagOfCell(rDoc, 7, 21, 0),
572 lcl_getMergeFlagOfCell(rDoc, 7, 10, 0));
573 CPPUNIT_ASSERT(lcl_getMergeSizeOfCell(rDoc, 7, 21, 0) !=
574 lcl_getMergeSizeOfCell(rDoc, 7, 10, 0));
575 CPPUNIT_ASSERT(lcl_getMergeFlagOfCell(rDoc, 8, 21, 0) !=
576 lcl_getMergeFlagOfCell(rDoc, 8, 10, 0));
577 CPPUNIT_ASSERT_EQUAL(lcl_getMergeSizeOfCell(rDoc, 8, 21, 0),
578 lcl_getMergeSizeOfCell(rDoc, 8, 10, 0));
580 // area A6:E9 with various merged cells copied vertically and horizontally
581 ScDocShell::GetViewData()->GetMarkData().SetMarkArea(ScRange(0, 5, 0, 4, 8, 0));
582 pView->FillAuto(FILL_TO_BOTTOM, 0, 5, 4, 8, 12);
583 ScDocShell::GetViewData()->GetMarkData().SetMarkArea(ScRange(0, 5, 0, 4, 8, 0));
584 pView->FillAuto(FILL_TO_RIGHT, 0, 5, 4, 8, 10);
585 for (int i = 0; i < 5; i++)
587 for (int j = 5; j < 9; j++)
589 ScMF nOriginFlag = lcl_getMergeFlagOfCell(rDoc, i, j, 0);
590 ScAddress aOriginMerge = lcl_getMergeSizeOfCell(rDoc, i, j, 0);
591 // copies contain the same ATTR_MERGE and ATTR_MERGE_FLAG
592 for (int k = 0; k < 12; k += 4)
594 CPPUNIT_ASSERT_EQUAL(lcl_getMergeFlagOfCell(rDoc, i, j + k, 0), nOriginFlag);
595 CPPUNIT_ASSERT_EQUAL(lcl_getMergeSizeOfCell(rDoc, i, j + k, 0), aOriginMerge);
597 for (int k = 0; k < 10; k += 5)
599 CPPUNIT_ASSERT_EQUAL(lcl_getMergeFlagOfCell(rDoc, i + k, j, 0), nOriginFlag);
600 CPPUNIT_ASSERT_EQUAL(lcl_getMergeSizeOfCell(rDoc, i + k, j, 0), aOriginMerge);
604 CPPUNIT_ASSERT_EQUAL(lcl_getMergeSizeOfCell(rDoc, 1, 5, 0), ScAddress(2, 4, 0));
605 CPPUNIT_ASSERT_EQUAL(lcl_getMergeSizeOfCell(rDoc, 0, 5, 0), ScAddress(1, 2, 0));
606 CPPUNIT_ASSERT_EQUAL(lcl_getMergeSizeOfCell(rDoc, 4, 6, 0), ScAddress(1, 2, 0));
607 CPPUNIT_ASSERT_EQUAL(lcl_getMergeSizeOfCell(rDoc, 3, 5, 0), ScAddress(2, 1, 0));
610 static void lcl_clickAndCheckCurrentArea(SCCOL nCol, SCROW nRow, SCCOL nCol2, SCROW nRow2)
612 ScRange aRange;
613 ScDocShell::GetViewData()->SetCurX(nCol);
614 ScDocShell::GetViewData()->SetCurY(nRow);
615 ScDocShell::GetViewData()->GetSimpleArea(aRange);
616 CPPUNIT_ASSERT_EQUAL(aRange, ScRange(nCol, nRow, 0, nCol2, nRow2, 0));
619 void ScCopyPasteTest::testTdf43958_clickSelectOnMergedCells()
621 loadDocAndSetupModelViewController("tdf40993_fillMergedCells.", FORMAT_ODS, true);
623 // select cell (e.g. by clicking on it) and check what is selected [but not marked]:
624 // if it is the top left cell of a merged area, the selection is enlarged to the area
625 lcl_clickAndCheckCurrentArea(1, 5, 2, 8); // B6 -> B6:C9
626 lcl_clickAndCheckCurrentArea(0, 5, 0, 6); // A6 -> A6:A7
627 lcl_clickAndCheckCurrentArea(3, 5, 4, 5); // D6 -> D6:E6
628 lcl_clickAndCheckCurrentArea(4, 6, 4, 7); // D7 -> D6:D7
629 lcl_clickAndCheckCurrentArea(7, 10, 8, 10); // H11 -> H11:I11
630 lcl_clickAndCheckCurrentArea(7, 13, 8, 13); // H14 -> H14:I14
632 // otherwise it remains the same
633 lcl_clickAndCheckCurrentArea(0, 7, 0, 7); // A8
634 lcl_clickAndCheckCurrentArea(0, 8, 0, 8); // A9
635 lcl_clickAndCheckCurrentArea(2, 6, 2, 6); // C7
636 lcl_clickAndCheckCurrentArea(2, 7, 2, 7); // C8
637 lcl_clickAndCheckCurrentArea(2, 8, 2, 8); // C9
640 void ScCopyPasteTest::testTdf88782_autofillLinearNumbersInMergedCells()
642 ScDocShellRef xDocSh = loadDocAndSetupModelViewController("tdf88782_AutofillLinearNumbersInMergedCells.", FORMAT_ODS, true);
643 ScDocument& rDoc = xDocSh->GetDocument();
645 // Get the document controller
646 ScTabViewShell* pView = xDocSh->GetBestViewShell(false);
647 CPPUNIT_ASSERT(pView != nullptr);
649 // merge the yellow cells
650 ScCellMergeOption aMergeOptions(9, 11, 10, 13); //J12:K14
651 aMergeOptions.maTabs.insert(0);
652 xDocSh->GetDocFunc().MergeCells(aMergeOptions, false, true, true, false);
654 // fillauto numbers, these areas contain mostly merged cells
655 pView->FillAuto(FILL_TO_BOTTOM, 1, 8, 3, 14, 7); // B9:D15 -> B9:D22
656 pView->FillAuto(FILL_TO_BOTTOM, 5, 8, 7, 17, 10); // F9:H18 -> F9:H28
657 pView->FillAuto(FILL_TO_BOTTOM, 9, 8, 10, 13, 6); // J9:K14 -> J9:K20
658 pView->FillAuto(FILL_TO_RIGHT, 9, 30, 16, 35, 8); //J31:Q36 -> J31:Y36
659 pView->FillAuto(FILL_TO_LEFT, 9, 30, 16, 35, 8); //J31:Q36 -> B31:Q36
661 // compare the results of fill-down with the reference stored in the test file
662 // this compares the whole area blindly, for specific test cases, check the test file
663 // the test file have instructions / explanations, so that is easy to understand
664 for (int nCol = 1; nCol <= 10; nCol++)
666 for (int nRow = 8; nRow <= 27; nRow++)
668 CellType nType1 = rDoc.GetCellType(ScAddress(nCol, nRow, 0));
669 CellType nType2 = rDoc.GetCellType(ScAddress(nCol + 22, nRow, 0));
670 double* pValue1 = rDoc.GetValueCell(ScAddress(nCol, nRow, 0));
671 double* pValue2 = rDoc.GetValueCell(ScAddress(nCol + 22, nRow, 0));
673 CPPUNIT_ASSERT_EQUAL(nType1, nType2);
674 if (pValue2 != nullptr)
675 CPPUNIT_ASSERT_EQUAL(*pValue1, *pValue2); //cells with number value
676 else
677 CPPUNIT_ASSERT_EQUAL(pValue1, pValue2); //empty cells
681 // compare the results of fill-right and left with the reference stored in the test file
682 for (int nCol = 1; nCol <= 24; nCol++)
684 for (int nRow = 30; nRow <= 35; nRow++)
686 CellType nType1 = rDoc.GetCellType(ScAddress(nCol, nRow, 0));
687 CellType nType2 = rDoc.GetCellType(ScAddress(nCol, nRow + 16, 0));
688 double* pValue1 = rDoc.GetValueCell(ScAddress(nCol, nRow, 0));
689 double* pValue2 = rDoc.GetValueCell(ScAddress(nCol, nRow + 16, 0));
691 CPPUNIT_ASSERT_EQUAL(nType1, nType2);
692 if (pValue2 != nullptr)
693 CPPUNIT_ASSERT_EQUAL(*pValue1, *pValue2);
694 else
695 CPPUNIT_ASSERT_EQUAL(pValue1, pValue2);
700 void ScCopyPasteTest::tdf137621_autofillMergedBool()
702 ScDocShellRef xDocSh = loadDocAndSetupModelViewController("tdf137621_autofillMergedBool.", FORMAT_ODS, true);
703 ScDocument& rDoc = xDocSh->GetDocument();
705 // Get the document controller
706 ScTabViewShell* pView = xDocSh->GetBestViewShell(false);
707 CPPUNIT_ASSERT(pView != nullptr);
709 // fillauto booleans, these areas contain only merged cells
710 pView->FillAuto(FILL_TO_RIGHT, 0, 4, 3, 5, 8); //A5:D6
712 // compare the results of fill-right with the reference stored in the test file
713 // this compares the whole area blindly, for specific test cases, check the test file
714 for (int nCol = 4; nCol <= 11; nCol++)
716 for (int nRow = 4; nRow <= 5; nRow++)
718 CellType nType1 = rDoc.GetCellType(ScAddress(nCol, nRow, 0));
719 CellType nType2 = rDoc.GetCellType(ScAddress(nCol, nRow + 3, 0));
720 double* pValue1 = rDoc.GetValueCell(ScAddress(nCol, nRow, 0));
721 double* pValue2 = rDoc.GetValueCell(ScAddress(nCol, nRow + 3, 0));
723 CPPUNIT_ASSERT_EQUAL(nType1, nType2);
724 if (pValue2 != nullptr)
725 CPPUNIT_ASSERT_EQUAL(*pValue1, *pValue2); //cells with boolean value
726 else
727 CPPUNIT_ASSERT_EQUAL(pValue1, pValue2); //empty cells
732 void ScCopyPasteTest::tdf137205_autofillDatesInMergedCells()
734 ScDocShellRef xDocSh = loadDocAndSetupModelViewController("tdf137205_AutofillDatesInMergedCells.", FORMAT_ODS, true);
735 ScDocument& rDoc = xDocSh->GetDocument();
737 // Get the document controller
738 ScTabViewShell* pView = xDocSh->GetBestViewShell(false);
739 CPPUNIT_ASSERT(pView != nullptr);
741 // fillauto dates, this areas contain only merged cells
742 pView->FillAuto(FILL_TO_RIGHT, 1, 5, 4, 7, 8); //B6:E8
744 // compare the results of fill-right with the reference stored in the test file
745 // this compares the whole area blindly, for specific test cases, check the test file
746 for (int nCol = 5; nCol <= 12; nCol++)
748 for (int nRow = 5; nRow <= 7; nRow++)
750 CellType nType1 = rDoc.GetCellType(ScAddress(nCol, nRow, 0));
751 CellType nType2 = rDoc.GetCellType(ScAddress(nCol, nRow + 5, 0));
752 double* pValue1 = rDoc.GetValueCell(ScAddress(nCol, nRow, 0));
753 double* pValue2 = rDoc.GetValueCell(ScAddress(nCol, nRow + 5, 0));
755 CPPUNIT_ASSERT_EQUAL(nType1, nType2);
756 if (pValue2 != nullptr)
757 CPPUNIT_ASSERT_EQUAL(*pValue1, *pValue2); //cells with number value
758 else
759 CPPUNIT_ASSERT_EQUAL(pValue1, pValue2); //empty cells
764 void ScCopyPasteTest::addToUserList(const OUString& rStr)
766 ScUserListData* aListData = new ScUserListData(rStr);
767 ScGlobal::GetUserList()->push_back(aListData);
770 void ScCopyPasteTest::tdf137653_137654_autofillUserlist()
772 ScDocShellRef xDocSh = loadDocAndSetupModelViewController("tdf137653_137654_autofillUserlist.", FORMAT_ODS, true);
773 ScDocument& rDoc = xDocSh->GetDocument();
775 // Get the document controller
776 ScTabViewShell* pView = xDocSh->GetBestViewShell(false);
777 CPPUNIT_ASSERT(pView != nullptr);
779 // delete every userlist to make sure there won't be any string that is in 2 different userlist
780 ScGlobal::GetUserList()->clear();
781 addToUserList({ "January,February,March,April,May,June,July,August,September,October,November,December" });
782 const ScUserListData* pListData = ScGlobal::GetUserList()->GetData("January");
783 sal_uInt16 nIdx1 = 0, nIdx2 = 0;
784 bool bHasIdx1, bHasIdx2;
785 bool bMatchCase = false;
787 // fillauto userlist, these areas contain only merged cells
788 pView->FillAuto(FILL_TO_RIGHT, 4, 5, 6, 7, 3); //E6:G8
789 pView->FillAuto(FILL_TO_LEFT, 4, 5, 6, 7, 3); //E6:G8
790 pView->FillAuto(FILL_TO_BOTTOM, 1, 18, 3, 19, 2); //B19:D20
791 pView->FillAuto(FILL_TO_TOP, 1, 18, 3, 19, 2); //B19:D20
793 // compare the results of fill-right / -left with the reference stored in the test file
794 // this compares the whole area blindly, for specific test cases, check the test file
795 for (int nCol = 1; nCol <= 9; nCol++)
797 for (int nRow = 5; nRow <= 7; nRow++)
799 CellType nType1 = rDoc.GetCellType(ScAddress(nCol, nRow, 0));
800 CellType nType2 = rDoc.GetCellType(ScAddress(nCol, nRow + 4, 0));
801 bHasIdx1 = pListData->GetSubIndex(rDoc.GetString(nCol, nRow, 0), nIdx1, bMatchCase);
802 bHasIdx2 = pListData->GetSubIndex(rDoc.GetString(nCol, nRow + 4, 0), nIdx2, bMatchCase);
804 CPPUNIT_ASSERT_EQUAL(nType1, nType2);
805 CPPUNIT_ASSERT(bHasIdx1 && bHasIdx2);
806 CPPUNIT_ASSERT_EQUAL(nIdx1, nIdx2); // userlist index value of cells
810 // compare the results of fill-up / -down
811 for (int nCol = 1; nCol <= 3; nCol++)
813 for (int nRow = 16; nRow <= 21; nRow++)
815 CellType nType1 = rDoc.GetCellType(ScAddress(nCol, nRow, 0));
816 CellType nType2 = rDoc.GetCellType(ScAddress(nCol + 4, nRow, 0));
817 bHasIdx1 = pListData->GetSubIndex(rDoc.GetString(nCol, nRow, 0), nIdx1, bMatchCase);
818 bHasIdx2 = pListData->GetSubIndex(rDoc.GetString(nCol + 4, nRow, 0), nIdx2, bMatchCase);
820 CPPUNIT_ASSERT_EQUAL(nType1, nType2);
821 CPPUNIT_ASSERT(bHasIdx1 && bHasIdx2);
822 CPPUNIT_ASSERT_EQUAL(nIdx1, nIdx2); // userlist index value of cells
827 void ScCopyPasteTest::tdf113500_autofillMixed()
829 ScDocShellRef xDocSh = loadDocAndSetupModelViewController("tdf113500_autofillMixed.", FORMAT_ODS, true);
830 ScDocument& rDoc = xDocSh->GetDocument();
832 // Get the document controller
833 ScTabViewShell* pView = xDocSh->GetBestViewShell(false);
834 CPPUNIT_ASSERT(pView != nullptr);
836 // fillauto userlist, these areas contain only merged cells
837 pView->FillAuto(FILL_TO_RIGHT, 4, 5, 6, 7, 3); //E6:G8
838 pView->FillAuto(FILL_TO_LEFT, 4, 5, 6, 7, 3); //E6:G8
839 pView->FillAuto(FILL_TO_BOTTOM, 1, 18, 3, 19, 2); //B19:D20
840 pView->FillAuto(FILL_TO_TOP, 1, 18, 3, 19, 2); //B19:D20
842 // compare the results of fill-right / -left with the reference stored in the test file
843 // this compares the whole area blindly, for specific test cases, check the test file
844 // do not check the 3. row: a1,b2,a3. It is another bug to fix
845 for (int nCol = 1; nCol <= 9; nCol++)
847 for (int nRow = 5; nRow <= 6; nRow++)
849 CellType nType1 = rDoc.GetCellType(ScAddress(nCol, nRow, 0));
850 CellType nType2 = rDoc.GetCellType(ScAddress(nCol, nRow + 4, 0));
851 OUString aStr1 = rDoc.GetString(nCol, nRow, 0);
852 OUString aStr2 = rDoc.GetString(nCol, nRow + 4, 0);
854 CPPUNIT_ASSERT_EQUAL(nType1, nType2);
855 CPPUNIT_ASSERT_EQUAL(aStr1, aStr2);
859 // compare the results of fill-up / -down
860 // do not check the 2. column: 1st,3st. It is another bug to fix
861 for (int nCol = 1; nCol <= 3; nCol+=2)
863 for (int nRow = 16; nRow <= 21; nRow++)
865 CellType nType1 = rDoc.GetCellType(ScAddress(nCol, nRow, 0));
866 CellType nType2 = rDoc.GetCellType(ScAddress(nCol + 4, nRow, 0));
867 OUString aStr1 = rDoc.GetString(nCol, nRow, 0);
868 OUString aStr2 = rDoc.GetString(nCol + 4, nRow, 0);
870 CPPUNIT_ASSERT_EQUAL(nType1, nType2);
871 CPPUNIT_ASSERT_EQUAL(aStr1, aStr2);
876 void ScCopyPasteTest::tdf137625_autofillMergedUserlist()
878 ScDocShellRef xDocSh = loadDocAndSetupModelViewController("tdf137625_autofillMergedUserlist.", FORMAT_ODS, true);
879 ScDocument& rDoc = xDocSh->GetDocument();
881 // Get the document controller
882 ScTabViewShell* pView = xDocSh->GetBestViewShell(false);
883 CPPUNIT_ASSERT(pView != nullptr);
885 // delete every userlist to make sure there won't be any string that is in 2 different userlist
886 ScGlobal::GetUserList()->clear();
887 addToUserList({ "January,February,March,April,May,June,July,August,September,October,November,December" });
888 const ScUserListData* pListData = ScGlobal::GetUserList()->GetData("January");
889 sal_uInt16 nIdx1 = 0, nIdx2 = 0;
890 bool bHasIdx1, bHasIdx2;
891 bool bMatchCase = false;
893 // fillauto userlist, these areas contain only merged cells
894 pView->FillAuto(FILL_TO_RIGHT, 7, 5, 12, 7, 6); //H6:M8
895 pView->FillAuto(FILL_TO_LEFT, 7, 5, 12, 7, 6); //H6:M8
896 pView->FillAuto(FILL_TO_BOTTOM, 1, 20, 3, 23, 4); //B21:D24
897 pView->FillAuto(FILL_TO_TOP, 1, 20, 3, 23, 4); //B21:D24
899 // compare the results of fill-right / -left with the reference stored in the test file
900 // this compares the whole area blindly, for specific test cases, check the test file
901 for (int nCol = 1; nCol <= 18; nCol++)
903 for (int nRow = 5; nRow <= 7; nRow++)
905 CellType nType1 = rDoc.GetCellType(ScAddress(nCol, nRow, 0));
906 CellType nType2 = rDoc.GetCellType(ScAddress(nCol, nRow + 4, 0));
907 bHasIdx1 = pListData->GetSubIndex(rDoc.GetString(nCol, nRow, 0), nIdx1, bMatchCase);
908 bHasIdx2 = pListData->GetSubIndex(rDoc.GetString(nCol, nRow + 4, 0), nIdx2, bMatchCase);
910 CPPUNIT_ASSERT_EQUAL(nType1, nType2);
911 CPPUNIT_ASSERT_EQUAL(bHasIdx1, bHasIdx2);
912 if (bHasIdx1)
913 CPPUNIT_ASSERT_EQUAL(nIdx1, nIdx2); //cells with userlist value
917 // compare the results of fill-up / -down
918 for (int nCol = 1; nCol <= 3; nCol++)
920 for (int nRow = 16; nRow <= 27; nRow++)
922 CellType nType1 = rDoc.GetCellType(ScAddress(nCol, nRow, 0));
923 CellType nType2 = rDoc.GetCellType(ScAddress(nCol + 4, nRow, 0));
924 bHasIdx1 = pListData->GetSubIndex(rDoc.GetString(nCol, nRow, 0), nIdx1, bMatchCase);
925 bHasIdx2 = pListData->GetSubIndex(rDoc.GetString(nCol + 4, nRow, 0), nIdx2, bMatchCase);
927 CPPUNIT_ASSERT_EQUAL(nType1, nType2);
928 CPPUNIT_ASSERT_EQUAL(bHasIdx1, bHasIdx2);
929 if (bHasIdx1)
930 CPPUNIT_ASSERT_EQUAL(nIdx1, nIdx2); //cells with userlist value
935 void ScCopyPasteTest::tdf137624_autofillMergedMixed()
937 ScDocShellRef xDocSh = loadDocAndSetupModelViewController("tdf137624_autofillMergedMixed.", FORMAT_ODS, true);
938 ScDocument& rDoc = xDocSh->GetDocument();
940 // Get the document controller
941 ScTabViewShell* pView = xDocSh->GetBestViewShell(false);
942 CPPUNIT_ASSERT(pView != nullptr);
944 // add 1aa,2bb,3cc,4dd,5ee,6ff to userlist, to test that autofill won't confuse it with 1aa,3aa
945 // delete every userlist to make sure there won't be any string that is in 2 different userlist
946 ScGlobal::GetUserList()->clear();
947 addToUserList({ "1aa,2bb,3cc,4dd,5ee,6ff" });
949 // fillauto mixed (string + number), these areas contain only merged cells
950 pView->FillAuto(FILL_TO_RIGHT, 7, 5, 12, 7, 6); //H6:M8
951 pView->FillAuto(FILL_TO_LEFT, 7, 5, 12, 7, 6); //H6:M8
952 pView->FillAuto(FILL_TO_BOTTOM, 1, 20, 3, 23, 4); //B21:D24
953 pView->FillAuto(FILL_TO_TOP, 1, 20, 3, 23, 4); //B21:D24
955 // compare the results of fill-right / -left with the reference stored in the test file
956 // this compares the whole area blindly, for specific test cases, check the test file
957 for (int nCol = 1; nCol <= 18; nCol++)
959 for (int nRow = 5; nRow <= 7; nRow++)
961 CellType nType1 = rDoc.GetCellType(ScAddress(nCol, nRow, 0));
962 CellType nType2 = rDoc.GetCellType(ScAddress(nCol, nRow + 4, 0));
963 OUString aStr1 = rDoc.GetString(nCol, nRow, 0);
964 OUString aStr2 = rDoc.GetString(nCol, nRow + 4, 0);
966 CPPUNIT_ASSERT_EQUAL(nType1, nType2);
967 CPPUNIT_ASSERT_EQUAL(aStr1, aStr2);
971 // compare the results of fill-up / -down
972 for (int nCol = 1; nCol <= 3; nCol++)
974 for (int nRow = 16; nRow <= 27; nRow++)
976 CellType nType1 = rDoc.GetCellType(ScAddress(nCol, nRow, 0));
977 CellType nType2 = rDoc.GetCellType(ScAddress(nCol + 4, nRow, 0));
978 OUString aStr1 = rDoc.GetString(nCol, nRow, 0);
979 OUString aStr2 = rDoc.GetString(nCol + 4, nRow, 0);
981 CPPUNIT_ASSERT_EQUAL(nType1, nType2);
982 CPPUNIT_ASSERT_EQUAL(aStr1, aStr2);
987 ScCopyPasteTest::ScCopyPasteTest()
988 : ScBootstrapFixture( "sc/qa/unit/data" )
992 void ScCopyPasteTest::setUp()
994 test::BootstrapFixture::setUp();
996 // This is a bit of a fudge, we do this to ensure that ScGlobals::ensure,
997 // which is a private symbol to us, gets called
998 m_xCalcComponent =
999 getMultiServiceFactory()->createInstance("com.sun.star.comp.Calc.SpreadsheetDocument");
1000 CPPUNIT_ASSERT_MESSAGE("no calc component!", m_xCalcComponent.is());
1003 void ScCopyPasteTest::tearDown()
1005 uno::Reference< lang::XComponent >( m_xCalcComponent, UNO_QUERY_THROW )->dispose();
1006 test::BootstrapFixture::tearDown();
1009 CPPUNIT_TEST_SUITE_REGISTRATION(ScCopyPasteTest);
1011 CPPUNIT_PLUGIN_IMPLEMENT();
1013 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */