[Libreoffice-commits] core.git: sd/qa
Tomaž Vajngerl (via logerrit)
logerrit at kemper.freedesktop.org
Sat Aug 29 13:08:41 UTC 2020
sd/qa/unit/tiledrendering/LOKitSearchTest.cxx | 115 +++++++++++++++++++++++++
sd/qa/unit/tiledrendering/data/ReplaceTest.odp |binary
2 files changed, 115 insertions(+)
New commits:
commit ac11b1f0311289c43f9a2c68e311de02cd0b53cf
Author: Tomaž Vajngerl <tomaz.vajngerl at collabora.co.uk>
AuthorDate: Sun Aug 23 13:41:58 2020 +0200
Commit: Tomaž Vajngerl <quikee at gmail.com>
CommitDate: Sat Aug 29 15:07:56 2020 +0200
sd: test Replace and ReplaceAll using LOKit
Change-Id: I68a612d3fb277970870818d290096b2824f31057
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101635
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee at gmail.com>
diff --git a/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx b/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx
index ac2695441575..4890205d826e 100644
--- a/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx
+++ b/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx
@@ -62,6 +62,9 @@ public:
void testSearchInPDFInMultiplePagesBackwards();
void testSearchIn2MixedObjects();
void testSearchIn6MixedObjects();
+ void testReplace();
+ void testReplaceAll();
+ void testReplaceCombined();
CPPUNIT_TEST_SUITE(LOKitSearchTest);
CPPUNIT_TEST(testSearch);
@@ -77,6 +80,9 @@ public:
CPPUNIT_TEST(testSearchInPDFInMultiplePagesBackwards);
CPPUNIT_TEST(testSearchIn2MixedObjects);
CPPUNIT_TEST(testSearchIn6MixedObjects);
+ CPPUNIT_TEST(testReplace);
+ CPPUNIT_TEST(testReplaceAll);
+ CPPUNIT_TEST(testReplaceCombined);
CPPUNIT_TEST_SUITE_END();
private:
@@ -144,6 +150,22 @@ void lcl_search(const OUString& rKey, bool bFindAll = false, bool bBackwards = f
Scheduler::ProcessEventsToIdle();
}
+void lcl_replace(const OUString& rKey, const OUString& rReplace, bool bAll = false)
+{
+ Scheduler::ProcessEventsToIdle();
+
+ SvxSearchCmd eSearch = bAll ? SvxSearchCmd::REPLACE_ALL : SvxSearchCmd::REPLACE;
+
+ uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence({
+ { "SearchItem.SearchString", uno::makeAny(rKey) },
+ { "SearchItem.ReplaceString", uno::makeAny(rReplace) },
+ { "SearchItem.Command", uno::makeAny(sal_uInt16(eSearch)) },
+ }));
+
+ comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues);
+ Scheduler::ProcessEventsToIdle();
+}
+
#if HAVE_FEATURE_PDFIUM
SdrObject* lclGetSelectedObject(sd::ViewShell* pViewShell)
{
@@ -826,6 +848,99 @@ void LOKitSearchTest::testSearchIn6MixedObjects()
CPPUNIT_ASSERT_EQUAL(pPage->GetObj(0), lclGetSelectedObject(pViewShell));
#endif
}
+namespace
+{
+OUString getShapeText(SdXImpressDocument* pXImpressDocument, sal_uInt32 nPage, sal_uInt32 nShape)
+{
+ uno::Reference<container::XIndexAccess> xDrawPage;
+ xDrawPage.set(pXImpressDocument->getDrawPages()->getByIndex(nPage), uno::UNO_QUERY);
+
+ uno::Reference<text::XTextRange> xShape(xDrawPage->getByIndex(nShape), uno::UNO_QUERY);
+ return xShape->getString();
+}
+}
+
+void LOKitSearchTest::testReplace()
+{
+ SdXImpressDocument* pXImpressDocument = createDoc("ReplaceTest.odp");
+ sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+ mpCallbackRecorder->registerCallbacksFor(pViewShell->GetViewShellBase());
+
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Bbb bbb bbb bbb"), getShapeText(pXImpressDocument, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 4, 0));
+
+ lcl_replace("bbb", "aaa", false); // select
+
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Bbb bbb bbb bbb"), getShapeText(pXImpressDocument, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 4, 0));
+
+ lcl_replace("bbb", "aaa", false); // replace
+
+ CPPUNIT_ASSERT_EQUAL(OUString("aaa"), getShapeText(pXImpressDocument, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Bbb bbb bbb bbb"), getShapeText(pXImpressDocument, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 4, 0));
+}
+
+void LOKitSearchTest::testReplaceAll()
+{
+ SdXImpressDocument* pXImpressDocument = createDoc("ReplaceTest.odp");
+ sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+ mpCallbackRecorder->registerCallbacksFor(pViewShell->GetViewShellBase());
+
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Bbb bbb bbb bbb"), getShapeText(pXImpressDocument, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 4, 0));
+
+ lcl_replace("bbb", "ccc", true);
+
+ CPPUNIT_ASSERT_EQUAL(OUString("ccc"), getShapeText(pXImpressDocument, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("ccc ccc ccc ccc"), getShapeText(pXImpressDocument, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("ccc"), getShapeText(pXImpressDocument, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("ccc"), getShapeText(pXImpressDocument, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("ccc"), getShapeText(pXImpressDocument, 4, 0));
+
+ lcl_replace("ccc", "bbb", true);
+
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb bbb bbb bbb"), getShapeText(pXImpressDocument, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 4, 0));
+}
+
+void LOKitSearchTest::testReplaceCombined()
+{
+ SdXImpressDocument* pXImpressDocument = createDoc("ReplaceTest.odp");
+ sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+ mpCallbackRecorder->registerCallbacksFor(pViewShell->GetViewShellBase());
+
+ lcl_replace("bbb", "aaa", false); // select
+ lcl_replace("bbb", "aaa", false); // replace
+
+ CPPUNIT_ASSERT_EQUAL(OUString("aaa"), getShapeText(pXImpressDocument, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("Bbb bbb bbb bbb"), getShapeText(pXImpressDocument, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("bbb"), getShapeText(pXImpressDocument, 4, 0));
+
+ lcl_replace("bbb", "ccc", true);
+
+ CPPUNIT_ASSERT_EQUAL(OUString("aaa"), getShapeText(pXImpressDocument, 0, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("ccc ccc ccc ccc"), getShapeText(pXImpressDocument, 1, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("ccc"), getShapeText(pXImpressDocument, 2, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("ccc"), getShapeText(pXImpressDocument, 3, 0));
+ CPPUNIT_ASSERT_EQUAL(OUString("ccc"), getShapeText(pXImpressDocument, 4, 0));
+}
CPPUNIT_TEST_SUITE_REGISTRATION(LOKitSearchTest);
diff --git a/sd/qa/unit/tiledrendering/data/ReplaceTest.odp b/sd/qa/unit/tiledrendering/data/ReplaceTest.odp
new file mode 100644
index 000000000000..9b0fc61aaf38
Binary files /dev/null and b/sd/qa/unit/tiledrendering/data/ReplaceTest.odp differ
More information about the Libreoffice-commits
mailing list