summaryrefslogtreecommitdiff
path: root/sc/qa/unit/tiledrendering/tiledrendering.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'sc/qa/unit/tiledrendering/tiledrendering.cxx')
-rw-r--r--sc/qa/unit/tiledrendering/tiledrendering.cxx183
1 files changed, 145 insertions, 38 deletions
diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index fc3d675ba79a..9c5a19be2d42 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -39,6 +39,7 @@
#include <sc.hrc>
#include <comphelper/string.hxx>
#include <docoptio.hxx>
+#include <postit.hxx>
#include <chrono>
#include <cstddef>
@@ -116,12 +117,12 @@ public:
void testSpellOnlineRenderParameter();
void testPasteIntoWrapTextCell();
void testSortAscendingDescending();
- void testAutoInputStringBlock();
void testAutoInputExactMatch();
void testMoveShapeHandle();
void testEditCursorBounds();
void testTextSelectionBounds();
-
+ void testSheetViewDataCrash();
+ void testCommentCellCopyPaste();
CPPUNIT_TEST_SUITE(ScTiledRenderingTest);
CPPUNIT_TEST(testRowColumnHeaders);
@@ -170,11 +171,12 @@ public:
CPPUNIT_TEST(testSpellOnlineRenderParameter);
CPPUNIT_TEST(testPasteIntoWrapTextCell);
CPPUNIT_TEST(testSortAscendingDescending);
- CPPUNIT_TEST(testAutoInputStringBlock);
CPPUNIT_TEST(testAutoInputExactMatch);
CPPUNIT_TEST(testMoveShapeHandle);
CPPUNIT_TEST(testEditCursorBounds);
CPPUNIT_TEST(testTextSelectionBounds);
+ CPPUNIT_TEST(testSheetViewDataCrash);
+ CPPUNIT_TEST(testCommentCellCopyPaste);
CPPUNIT_TEST_SUITE_END();
private:
@@ -2639,41 +2641,6 @@ static void lcl_typeCharsInCell(const std::string& aStr, SCCOL nCol, SCROW nRow,
Scheduler::ProcessEventsToIdle();
}
-void ScTiledRenderingTest::testAutoInputStringBlock()
-{
- comphelper::LibreOfficeKit::setActive();
-
- ScModelObj* pModelObj = createDoc("empty.ods");
- CPPUNIT_ASSERT(pModelObj);
- ScTabViewShell* pView = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
- CPPUNIT_ASSERT(pView);
- ScDocument* pDoc = pModelObj->GetDocument();
-
- pDoc->SetString(ScAddress(0, 3, 0), "ABC"); // A4
- pDoc->SetString(ScAddress(0, 4, 0), "BAC"); // A5
- ScFieldEditEngine& rEE = pDoc->GetEditEngine();
- rEE.SetText("XYZ");
- pDoc->SetEditText(ScAddress(0, 5, 0), rEE.CreateTextObject()); // A6
- pDoc->SetValue(ScAddress(0, 6, 0), 123);
- pDoc->SetString(ScAddress(0, 7, 0), "ZZZ"); // A8
-
- ScAddress aA1(0, 0, 0);
- lcl_typeCharsInCell("X", aA1.Col(), aA1.Row(), pView, pModelObj); // Type 'X' in A1
- CPPUNIT_ASSERT_EQUAL_MESSAGE("A1 should not autocomplete", OUString("X"), pDoc->GetString(aA1));
-
- ScAddress aA3(0, 2, 0); // Adjacent to the string "superblock" A4:A8
- lcl_typeCharsInCell("X", aA3.Col(), aA3.Row(), pView, pModelObj); // Type 'X' in A3
- CPPUNIT_ASSERT_EQUAL_MESSAGE("A3 should autocomplete", OUString("XYZ"), pDoc->GetString(aA3));
-
- ScAddress aA9(0, 8, 0); // Adjacent to the string "superblock" A4:A8
- lcl_typeCharsInCell("X", aA9.Col(), aA9.Row(), pView, pModelObj); // Type 'X' in A9
- CPPUNIT_ASSERT_EQUAL_MESSAGE("A9 should autocomplete", OUString("XYZ"), pDoc->GetString(aA9));
-
- ScAddress aA11(0, 10, 0);
- lcl_typeCharsInCell("X", aA11.Col(), aA11.Row(), pView, pModelObj); // Type 'X' in A11
- CPPUNIT_ASSERT_EQUAL_MESSAGE("A11 should not autocomplete", OUString("X"), pDoc->GetString(aA11));
-}
-
void ScTiledRenderingTest::testAutoInputExactMatch()
{
comphelper::LibreOfficeKit::setActive();
@@ -2818,6 +2785,146 @@ void ScTiledRenderingTest::testTextSelectionBounds()
SfxViewShell::Current()->registerLibreOfficeKitViewCallback(nullptr, nullptr);
}
+void ScTiledRenderingTest::testSheetViewDataCrash()
+{
+ comphelper::LibreOfficeKit::setActive();
+
+ ScModelObj* pModelObj = createDoc("empty.ods");
+
+ // view #1
+ int nView1 = SfxLokHelper::getView();
+ SfxLokHelper::setView(nView1);
+
+ // Imitate online while creating a new sheet on empty.ods.
+ uno::Sequence<beans::PropertyValue> aArgs(
+ comphelper::InitPropertySequence({
+ { "Name", uno::Any(OUString("NewSheet")) },
+ { "Index", uno::Any(sal_Int32(2)) }
+ }));
+ comphelper::dispatchCommand(".uno:Insert", aArgs);
+ Scheduler::ProcessEventsToIdle();
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::PAGEDOWN | KEY_MOD1);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::PAGEDOWN | KEY_MOD1);
+ Scheduler::ProcessEventsToIdle();
+ ScTabViewShell* pView1 = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
+ CPPUNIT_ASSERT(pView1);
+
+ // view #2
+ SfxLokHelper::createView();
+ ScTabViewShell* pView2 = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
+ CPPUNIT_ASSERT(pView2);
+ Scheduler::ProcessEventsToIdle();
+
+ SfxLokHelper::setView(nView1);
+ // Delete a range.
+ pView1->SetCursor(1, 1);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::DOWN | KEY_SHIFT);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::DOWN | KEY_SHIFT);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::DELETE);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::DELETE);
+ // It will crash at this point without the fix.
+ Scheduler::ProcessEventsToIdle();
+}
+
+void ScTiledRenderingTest::testCommentCellCopyPaste()
+{
+ // Load a document
+ comphelper::LibreOfficeKit::setActive();
+ // Comments callback are emitted only if tiled annotations are off
+ comphelper::LibreOfficeKit::setTiledAnnotations(false);
+
+ // FIXME: Hack because previous tests do not destroy ScDocument(with annotations) on exit (?).
+ ScPostIt::mnLastPostItId = 1;
+
+ {
+ ScModelObj* pModelObj = createDoc("empty.ods");
+ ViewCallback aView;
+ int nView = SfxLokHelper::getView();
+
+ SfxLokHelper::setView(nView);
+
+ ScTabViewShell* pTabViewShell = dynamic_cast<ScTabViewShell*>(SfxViewShell::Current());
+ CPPUNIT_ASSERT(pTabViewShell);
+
+ lcl_typeCharsInCell("ABC", 0, 0, pTabViewShell, pModelObj); // Type "ABC" in A1
+
+ pTabViewShell->SetCursor(1, 1);
+
+ // Add a new comment
+ uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence(
+ {
+ {"Text", uno::makeAny(OUString("LOK Comment Cell B2"))},
+ {"Author", uno::makeAny(OUString("LOK Client"))},
+ }));
+ comphelper::dispatchCommand(".uno:InsertAnnotation", aArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ // We received a LOK_CALLBACK_COMMENT callback with comment 'Add' action
+ CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView.m_aCommentCallbackResult.get<std::string>("action"));
+ CPPUNIT_ASSERT_EQUAL(std::string("1"), aView.m_aCommentCallbackResult.get<std::string>("id"));
+ CPPUNIT_ASSERT_EQUAL(std::string("0"), aView.m_aCommentCallbackResult.get<std::string>("tab"));
+ CPPUNIT_ASSERT_EQUAL(std::string("LOK Client"), aView.m_aCommentCallbackResult.get<std::string>("author"));
+ CPPUNIT_ASSERT_EQUAL(std::string("LOK Comment Cell B2"), aView.m_aCommentCallbackResult.get<std::string>("text"));
+
+ uno::Sequence<beans::PropertyValue> aCopyPasteArgs;
+
+ // We need separate tests for single cell copy-paste and cell-range copy-paste
+ // since they hit different code paths in ScColumn methods.
+
+ // Single cell(with comment) copy paste test
+ {
+ comphelper::dispatchCommand(".uno:Copy", aCopyPasteArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ pTabViewShell->SetCursor(1, 49);
+ Scheduler::ProcessEventsToIdle();
+ comphelper::dispatchCommand(".uno:Paste", aCopyPasteArgs); // Paste to cell B50
+ Scheduler::ProcessEventsToIdle();
+
+ // We received a LOK_CALLBACK_COMMENT callback with comment 'Add' action
+ CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView.m_aCommentCallbackResult.get<std::string>("action"));
+ // Without the fix the id will be "1".
+ CPPUNIT_ASSERT_EQUAL(std::string("2"), aView.m_aCommentCallbackResult.get<std::string>("id"));
+ CPPUNIT_ASSERT_EQUAL(std::string("0"), aView.m_aCommentCallbackResult.get<std::string>("tab"));
+ CPPUNIT_ASSERT_EQUAL(std::string("LOK Client"), aView.m_aCommentCallbackResult.get<std::string>("author"));
+ CPPUNIT_ASSERT_EQUAL(std::string("LOK Comment Cell B2"), aView.m_aCommentCallbackResult.get<std::string>("text"));
+ }
+
+ // Cell range (with a comment) copy paste test
+ {
+ // Select range A1:C3
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_HOME | KEY_MOD1);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_HOME | KEY_MOD1);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN | KEY_SHIFT);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN | KEY_SHIFT);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_DOWN | KEY_SHIFT);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_DOWN | KEY_SHIFT);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RIGHT | KEY_SHIFT);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RIGHT | KEY_SHIFT);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, KEY_RIGHT | KEY_SHIFT);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, KEY_RIGHT | KEY_SHIFT);
+ Scheduler::ProcessEventsToIdle();
+
+ comphelper::dispatchCommand(".uno:Copy", aCopyPasteArgs);
+ Scheduler::ProcessEventsToIdle();
+
+ pTabViewShell->SetCursor(3, 49);
+ Scheduler::ProcessEventsToIdle();
+ comphelper::dispatchCommand(".uno:Paste", aCopyPasteArgs); // Paste to cell D50
+ Scheduler::ProcessEventsToIdle();
+
+ // We received a LOK_CALLBACK_COMMENT callback with comment 'Add' action
+ CPPUNIT_ASSERT_EQUAL(std::string("Add"), aView.m_aCommentCallbackResult.get<std::string>("action"));
+ // Without the fix the id will be "1".
+ CPPUNIT_ASSERT_EQUAL(std::string("3"), aView.m_aCommentCallbackResult.get<std::string>("id"));
+ CPPUNIT_ASSERT_EQUAL(std::string("0"), aView.m_aCommentCallbackResult.get<std::string>("tab"));
+ CPPUNIT_ASSERT_EQUAL(std::string("LOK Client"), aView.m_aCommentCallbackResult.get<std::string>("author"));
+ CPPUNIT_ASSERT_EQUAL(std::string("LOK Comment Cell B2"), aView.m_aCommentCallbackResult.get<std::string>("text"));
+ }
+ }
+ comphelper::LibreOfficeKit::setTiledAnnotations(true);
+}
+
}
CPPUNIT_TEST_SUITE_REGISTRATION(ScTiledRenderingTest);