summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorDennis Francis <dennis.francis@collabora.com>2021-05-05 15:30:32 +0530
committerDennis Francis <dennis.francis@collabora.com>2021-05-25 20:40:31 +0200
commit66833a391bf0b48d71d57ad884454d052c500732 (patch)
treef6276708c09e3c4258cf0c6caf9bc2c17a3aac76 /sc
parent7f36c9acc83d5e14a2db053839e0cb9f3968dcb2 (diff)
tdf#142214: unit-tests for new behaviour of auto-complete
Conflicts: sc/qa/unit/tiledrendering/tiledrendering.cxx Change-Id: I1255c50c33f4001a7d9932e0178b6539653eb61d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115133 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Luboš Luňák <l.lunak@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/115467 Tested-by: Jenkins Reviewed-by: Dennis Francis <dennis.francis@collabora.com> (cherry picked from commit 06c360d4d27ab0dadfdcd5f9d4f0c87288d3cb75) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116084
Diffstat (limited to 'sc')
-rw-r--r--sc/qa/unit/tiledrendering/tiledrendering.cxx101
1 files changed, 101 insertions, 0 deletions
diff --git a/sc/qa/unit/tiledrendering/tiledrendering.cxx b/sc/qa/unit/tiledrendering/tiledrendering.cxx
index 8e32f6e57b97..7b7e480ec6b2 100644
--- a/sc/qa/unit/tiledrendering/tiledrendering.cxx
+++ b/sc/qa/unit/tiledrendering/tiledrendering.cxx
@@ -51,6 +51,7 @@
#include <docuno.hxx>
#include <drwlayer.hxx>
#include <attrib.hxx>
+#include <editutil.hxx>
using namespace css;
@@ -117,6 +118,8 @@ public:
void testSpellOnlineRenderParameter();
void testPasteIntoWrapTextCell();
void testSortAscendingDescending();
+ void testAutoInputStringBlock();
+ void testAutoInputExactMatch();
CPPUNIT_TEST_SUITE(ScTiledRenderingTest);
@@ -166,6 +169,8 @@ public:
CPPUNIT_TEST(testSpellOnlineRenderParameter);
CPPUNIT_TEST(testPasteIntoWrapTextCell);
CPPUNIT_TEST(testSortAscendingDescending);
+ CPPUNIT_TEST(testAutoInputStringBlock);
+ CPPUNIT_TEST(testAutoInputExactMatch);
CPPUNIT_TEST_SUITE_END();
private:
@@ -2435,6 +2440,102 @@ void ScTiledRenderingTest::testSortAscendingDescending()
CPPUNIT_ASSERT_EQUAL(OString("rows"), aView.m_sInvalidateSheetGeometry);
}
+void lcl_typeCharsInCell(const std::string& aStr, SCCOL nCol, SCROW nRow, ScTabViewShell* pView, ScModelObj* pModelObj)
+{
+ pView->SetCursor(nCol, nRow);
+ for (const char& cChar : aStr)
+ {
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, cChar, 0);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, cChar, 0);
+ Scheduler::ProcessEventsToIdle();
+ }
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYINPUT, 0, awt::Key::RETURN);
+ pModelObj->postKeyEvent(LOK_KEYEVENT_KEYUP, 0, awt::Key::RETURN);
+ 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->SetString(ScAddress(0, 6, 0), "ZZZ"); // A7
+
+ 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:A7
+ 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 aA7(0, 6, 0); // Adjacent to the string "superblock" A4:A7
+ lcl_typeCharsInCell("X", aA7.Col(), aA7.Row(), pView, pModelObj); // Type 'X' in A7
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("A7 should autocomplete", OUString("XYZ"), pDoc->GetString(aA7));
+
+ ScAddress aA10(0, 9, 0);
+ lcl_typeCharsInCell("X", aA10.Col(), aA10.Row(), pView, pModelObj); // Type 'X' in A10
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("A10 should not autocomplete", OUString("X"), pDoc->GetString(aA10));
+}
+
+void ScTiledRenderingTest::testAutoInputExactMatch()
+{
+ 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, 1, 0), "Simple"); // A2
+ pDoc->SetString(ScAddress(0, 2, 0), "Simple"); // A3
+ pDoc->SetString(ScAddress(0, 3, 0), "Sing"); // A4
+ ScFieldEditEngine& rEE = pDoc->GetEditEngine();
+ rEE.SetText("Case");
+ pDoc->SetEditText(ScAddress(0, 4, 0), rEE.CreateTextObject()); // A5
+ pDoc->SetString(ScAddress(0, 5, 0), "Time"); // A6
+ pDoc->SetString(ScAddress(0, 6, 0), "Castle"); // A7
+
+ ScAddress aA8(0, 7, 0);
+ lcl_typeCharsInCell("S", aA8.Col(), aA8.Row(), pView, pModelObj); // Type "S" in A8
+ // Should not autocomplete as there are multiple matches starting with "S".
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("1: A8 should have just S (should not autocomplete)", OUString("S"), pDoc->GetString(aA8));
+
+ lcl_typeCharsInCell("Si", aA8.Col(), aA8.Row(), pView, pModelObj); // Type "Si" in A8
+ // Should not autocomplete as there are multiple matches starting with "Si".
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("2: A8 should not autocomplete", OUString("Si"), pDoc->GetString(aA8));
+
+ lcl_typeCharsInCell("Sim", aA8.Col(), aA8.Row(), pView, pModelObj); // Type "Sim" in A8
+ // Should autocomplete to "Simple" which is the only match.
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("3: A8 should autocomplete", OUString("Simple"), pDoc->GetString(aA8));
+
+ lcl_typeCharsInCell("Sin", aA8.Col(), aA8.Row(), pView, pModelObj); // Type "Sin" in A8
+ // Should autocomplete to "Sing" which is the only match.
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("4: A8 should autocomplete", OUString("Sing"), pDoc->GetString(aA8));
+
+ lcl_typeCharsInCell("Cas", aA8.Col(), aA8.Row(), pView, pModelObj); // Type "Cas" in A8
+ // Should not autocomplete as there are multiple matches starting with "Cas".
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("5: A8 should not autocomplete", OUString("Cas"), pDoc->GetString(aA8));
+
+ lcl_typeCharsInCell("Cast", aA8.Col(), aA8.Row(), pView, pModelObj); // Type "Cast" in A8
+ // Should autocomplete to "Castle" which is the only match.
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("6: A8 should autocomplete", OUString("Castle"), pDoc->GetString(aA8));
+
+ lcl_typeCharsInCell("T", aA8.Col(), aA8.Row(), pView, pModelObj); // Type "T" in A8
+ // Should autocomplete to "Time" which is the only match.
+ CPPUNIT_ASSERT_EQUAL_MESSAGE("7: A8 should autocomplete", OUString("Time"), pDoc->GetString(aA8));
+}
}