summaryrefslogtreecommitdiff
path: root/desktop/qa
diff options
context:
space:
mode:
authorDennis Francis <dennis.francis@collabora.com>2021-06-28 13:32:48 +0530
committerDennis Francis <dennis.francis@collabora.com>2021-09-22 09:12:53 +0200
commitba0851926a9def7577dcf7b29919de0632ac31a9 (patch)
treed01d57b8c74bb2c9826adc6dd1081ea0175516b8 /desktop/qa
parent8dda0309871b371e056c0c0f308203e2a8a0306f (diff)
lok-desktop: unit tests for LOK_CALLBACK_TABLE_SELECTED
Conflicts: desktop/qa/desktop_lib/test_desktop_lib.cxx Change-Id: I4e07ffc6f8eebbbee284d19cd9c77df13dddff3a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118945 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Dennis Francis <dennis.francis@collabora.com> (cherry picked from commit 56795f50abad3de960f23e85b2ccfa1ba0181370) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122415 Tested-by: Jenkins
Diffstat (limited to 'desktop/qa')
-rw-r--r--desktop/qa/data/table-selection.odtbin0 -> 10324 bytes
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx121
2 files changed, 121 insertions, 0 deletions
diff --git a/desktop/qa/data/table-selection.odt b/desktop/qa/data/table-selection.odt
new file mode 100644
index 000000000000..c19f8c79fc3a
--- /dev/null
+++ b/desktop/qa/data/table-selection.odt
Binary files differ
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index c593eca12562..680e48228d10 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -209,6 +209,8 @@ public:
void testJumpCursor();
void testRenderSearchResult_WriterNode();
void testRenderSearchResult_CommonNode();
+ void testNoDuplicateTableSelection();
+ void testMultiViewTableSelection();
void testABI();
CPPUNIT_TEST_SUITE(DesktopLOKTest);
@@ -274,6 +276,8 @@ public:
CPPUNIT_TEST(testJumpCursor);
CPPUNIT_TEST(testRenderSearchResult_WriterNode);
CPPUNIT_TEST(testRenderSearchResult_CommonNode);
+ CPPUNIT_TEST(testNoDuplicateTableSelection);
+ CPPUNIT_TEST(testMultiViewTableSelection);
CPPUNIT_TEST(testABI);
CPPUNIT_TEST_SUITE_END();
@@ -1953,6 +1957,8 @@ class ViewCallback
int mnView;
public:
OString m_aCellFormula;
+ int m_nTableSelectionCount;
+ bool m_bEmptyTableSelection;
bool m_bTilesInvalidated;
bool m_bZeroCursor;
tools::Rectangle m_aOwnCursor;
@@ -1962,6 +1968,8 @@ public:
ViewCallback(LibLODocument_Impl* pDocument)
: mpDocument(pDocument),
+ m_nTableSelectionCount(0),
+ m_bEmptyTableSelection(false),
m_bTilesInvalidated(false),
m_bZeroCursor(false)
{
@@ -2029,6 +2037,12 @@ public:
m_aCellFormula = aPayload;
}
break;
+ case LOK_CALLBACK_TABLE_SELECTED:
+ {
+ m_bEmptyTableSelection = (std::string(pPayload).compare("{ }") == 0);
+ ++m_nTableSelectionCount;
+ }
+ break;
}
}
};
@@ -3199,6 +3213,113 @@ void DesktopLOKTest::testRenderSearchResult_CommonNode()
std::free(pBuffer);
}
+static void lcl_repeatKeyStroke(LibLODocument_Impl *pDocument, int nCharCode, int nKeyCode, size_t nCount)
+{
+ for (size_t nCtr = 0; nCtr < nCount; ++nCtr)
+ {
+ pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYINPUT, nCharCode, nKeyCode);
+ pDocument->m_pDocumentClass->postKeyEvent(pDocument, LOK_KEYEVENT_KEYUP, nCharCode, nKeyCode);
+ }
+}
+
+void DesktopLOKTest::testNoDuplicateTableSelection()
+{
+ comphelper::LibreOfficeKit::setActive();
+ LibLODocument_Impl* pDocument = loadDoc("table-selection.odt");
+
+ // Create view 1.
+ pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+ ViewCallback aView1(pDocument);
+
+ lcl_repeatKeyStroke(pDocument, 0, KEY_DOWN, 1);
+ Scheduler::ProcessEventsToIdle();
+ CPPUNIT_ASSERT_EQUAL(1, aView1.m_nTableSelectionCount);
+ CPPUNIT_ASSERT(aView1.m_bEmptyTableSelection);
+
+ aView1.m_nTableSelectionCount = 0;
+ // Go to Table1.
+ lcl_repeatKeyStroke(pDocument, 0, KEY_DOWN, 1);
+ Scheduler::ProcessEventsToIdle();
+ CPPUNIT_ASSERT_EQUAL(1, aView1.m_nTableSelectionCount);
+ CPPUNIT_ASSERT(!aView1.m_bEmptyTableSelection);
+
+ aView1.m_nTableSelectionCount = 0;
+ // Move to the last row in Table1.
+ lcl_repeatKeyStroke(pDocument, 0, KEY_DOWN, 2);
+ Scheduler::ProcessEventsToIdle();
+ CPPUNIT_ASSERT_EQUAL(0, aView1.m_nTableSelectionCount);
+
+ // Go outside Table1.
+ lcl_repeatKeyStroke(pDocument, 0, KEY_DOWN, 1);
+ Scheduler::ProcessEventsToIdle();
+ CPPUNIT_ASSERT_EQUAL(1, aView1.m_nTableSelectionCount);
+ CPPUNIT_ASSERT(aView1.m_bEmptyTableSelection);
+}
+
+void DesktopLOKTest::testMultiViewTableSelection()
+{
+ comphelper::LibreOfficeKit::setActive();
+ LibLODocument_Impl* pDocument = loadDoc("table-selection.odt");
+
+ // Create view 1.
+ pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+ ViewCallback aView1(pDocument);
+ int nView1 = pDocument->m_pDocumentClass->getView(pDocument);
+
+ // Create view 2.
+ pDocument->m_pDocumentClass->createView(pDocument);
+ pDocument->m_pDocumentClass->initializeForRendering(pDocument, "{}");
+ ViewCallback aView2(pDocument);
+ int nView2 = pDocument->m_pDocumentClass->getView(pDocument);
+
+ // switch to view 1.
+ pDocument->m_pDocumentClass->setView(pDocument, nView1);
+ lcl_repeatKeyStroke(pDocument, 0, KEY_DOWN, 1);
+ Scheduler::ProcessEventsToIdle();
+ CPPUNIT_ASSERT_EQUAL(1, aView1.m_nTableSelectionCount);
+ CPPUNIT_ASSERT_EQUAL(1, aView2.m_nTableSelectionCount);
+ CPPUNIT_ASSERT(aView1.m_bEmptyTableSelection);
+ CPPUNIT_ASSERT(aView2.m_bEmptyTableSelection);
+
+ aView1.m_nTableSelectionCount = 0;
+ aView2.m_nTableSelectionCount = 0;
+
+ pDocument->m_pDocumentClass->setView(pDocument, nView1);
+ // Go to Table1.
+ lcl_repeatKeyStroke(pDocument, 0, KEY_DOWN, 1);
+ Scheduler::ProcessEventsToIdle();
+ CPPUNIT_ASSERT_EQUAL(1, aView1.m_nTableSelectionCount);
+ CPPUNIT_ASSERT_EQUAL(0, aView2.m_nTableSelectionCount);
+
+ aView1.m_nTableSelectionCount = 0;
+ // Switch to view 2
+ pDocument->m_pDocumentClass->setView(pDocument, nView2);
+ // Go to Table2 in view 2.
+ lcl_repeatKeyStroke(pDocument, 0, KEY_DOWN, 7);
+ Scheduler::ProcessEventsToIdle();
+ // View1 should not get any table selection messages.
+ CPPUNIT_ASSERT_EQUAL(0, aView1.m_nTableSelectionCount);
+ // View2 will first get table selection of Table1, then emty selection, and finally on 7th down arrow keypress,
+ // it will get table-selection of Table2. So in total it should get 3 table selections.
+ CPPUNIT_ASSERT_EQUAL(3, aView2.m_nTableSelectionCount);
+ CPPUNIT_ASSERT(!aView2.m_bEmptyTableSelection);
+
+ aView1.m_nTableSelectionCount = 0;
+ aView2.m_nTableSelectionCount = 0;
+
+ // Switch to view 1
+ pDocument->m_pDocumentClass->setView(pDocument, nView1);
+ // Go out of Table1 and re-enter..
+ lcl_repeatKeyStroke(pDocument, 0, KEY_UP, 1);
+ lcl_repeatKeyStroke(pDocument, 0, KEY_DOWN, 1);
+ Scheduler::ProcessEventsToIdle();
+ // View1 should get one empty table selection, then get Table1 selection.
+ CPPUNIT_ASSERT_EQUAL(2, aView1.m_nTableSelectionCount);
+ // View2 should not get any table selection.
+ CPPUNIT_ASSERT_EQUAL(0, aView2.m_nTableSelectionCount);
+ CPPUNIT_ASSERT(!aView1.m_bEmptyTableSelection);
+}
+
namespace {
constexpr size_t classOffset(int i)