diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2023-12-21 16:57:27 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2023-12-22 08:33:37 +0100 |
commit | 36b7ae36715cbf47b451e41e47aebe28cf594bd8 (patch) | |
tree | 575f512c78e1f8bdb845d7173e5d584071809413 /sc/qa/unit/uicalc/uicalc2.cxx | |
parent | 68d074fb910de7298cbefb6a3c3e192dae201837 (diff) |
tdf#154044: Also store default column data, when copying to Undo document
And restore from it un Undo.
Change-Id: I3e14b345cff25068d0555c5bceb4d6e97ce7cf76
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161127
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sc/qa/unit/uicalc/uicalc2.cxx')
-rw-r--r-- | sc/qa/unit/uicalc/uicalc2.cxx | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/sc/qa/unit/uicalc/uicalc2.cxx b/sc/qa/unit/uicalc/uicalc2.cxx index 1eaeb5cac4e3..9be6d83840bb 100644 --- a/sc/qa/unit/uicalc/uicalc2.cxx +++ b/sc/qa/unit/uicalc/uicalc2.cxx @@ -8,6 +8,7 @@ */ #include "../helper/qahelper.hxx" +#include <editeng/brushitem.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <svx/svdpage.hxx> #include <vcl/keycodes.hxx> @@ -26,8 +27,10 @@ #include <inputopt.hxx> #include <postit.hxx> #include <rangeutl.hxx> +#include <scitems.hxx> #include <scmod.hxx> #include <tabvwsh.hxx> +#include <undomanager.hxx> #include <viewdata.hxx> using namespace ::com::sun::star; @@ -1489,6 +1492,83 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testTdf156174) CPPUNIT_ASSERT(!pDBs->empty()); } +CPPUNIT_TEST_FIXTURE(ScUiCalcTest2, testTdf154044) +{ + createScDoc(); + ScDocument* pDoc = getScDoc(); + + auto getBackColor = [pDoc](SCCOL c) { + const ScPatternAttr* pattern = pDoc->GetPattern(c, 0, 0); + const SvxBrushItem& brush = pattern->GetItemSet().Get(ATTR_BACKGROUND); + return brush.GetColor(); + }; + + CPPUNIT_ASSERT_EQUAL(INITIALCOLCOUNT, pDoc->GetAllocatedColumnsCount(0)); + for (SCCOL i = 0; i <= pDoc->MaxCol(); ++i) + { + OString msg = "i=" + OString::number(i); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.getStr(), COL_AUTO, getBackColor(i)); + } + + // Set the background color of A1:CV1 + auto aColorArg( + comphelper::InitPropertySequence({ { "BackgroundColor", uno::Any(COL_LIGHTBLUE) } })); + goToCell("A1:CV1"); + dispatchCommand(mxComponent, ".uno:BackgroundColor", aColorArg); + + // Partial row range allocates necessary columns + CPPUNIT_ASSERT_EQUAL(SCCOL(100), pDoc->GetAllocatedColumnsCount(0)); + + // Check that settings are applied + for (SCCOL i = 0; i < 100; ++i) + { + OString msg = "i=" + OString::number(i); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.getStr(), COL_LIGHTBLUE, getBackColor(i)); + } + + // Undo + SfxUndoManager* pUndoMgr = pDoc->GetUndoManager(); + CPPUNIT_ASSERT(pUndoMgr); + pUndoMgr->Undo(); + + // Check that all the cells have restored the setting + for (SCCOL i = 0; i < 100; ++i) + { + OString msg = "i=" + OString::number(i); + // Without the fix in place, this would fail with + // - Expected: rgba[ffffff00] + // - Actual : rgba[0000ffff] + // - i=1 + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.getStr(), COL_AUTO, getBackColor(i)); + } + + // Also check the whole row selection case - it is handled specially: columns are not allocated. + // See commit 3db91487e57277f75d64d95d06d4ddcc29f1c4e0 (set properly attributes for cells in + // unallocated Calc columns, 2022-03-04). + goToCell("A1:" + pDoc->MaxColAsString() + "1"); + dispatchCommand(mxComponent, ".uno:BackgroundColor", aColorArg); + + // Check that settings are applied + for (SCCOL i = 0; i <= pDoc->MaxCol(); ++i) + { + OString msg = "i=" + OString::number(i); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.getStr(), COL_LIGHTBLUE, getBackColor(i)); + } + + // Undo + pUndoMgr->Undo(); + + // No additional columns have been allocated for whole-row range + CPPUNIT_ASSERT_EQUAL(SCCOL(100), pDoc->GetAllocatedColumnsCount(0)); + + // Check that all the cells have restored the setting + for (SCCOL i = 0; i <= pDoc->MaxCol(); ++i) + { + OString msg = "i=" + OString::number(i); + CPPUNIT_ASSERT_EQUAL_MESSAGE(msg.getStr(), COL_AUTO, getBackColor(i)); + } +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |