summaryrefslogtreecommitdiffstats
path: root/sd/qa
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-05-29 23:06:57 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2020-07-30 15:00:49 +0200
commit9fbe629bdb74324990b002c1a010ca58085040b9 (patch)
treea3c0f3694ea4d1e46792251baf2ec40342b49ae0 /sd/qa
parentsd: use b2DRectangleFromRectangle from canvastools.hxx (diff)
downloadcore-9fbe629bdb74324990b002c1a010ca58085040b9.tar.gz
core-9fbe629bdb74324990b002c1a010ca58085040b9.zip
sd: fix not found case in PDF search + add PDF Search tests
When searching the PDF and the search text is not found (anymore) in the current VectorGraphicSearch, we need to remove it and mark that we don't currently search in a vector graphic (PDF) anymore. This wasn't handled correctly and caused a crash. In addition add a LOKit test for search into a PDF document, to make sure the not-found case and usual searching case are working correctly. Change-Id: I663a6b2cf4879f11d62e440ea0c35ffcd205f81f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95380 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com> (cherry picked from commit a99aef3cf0a8ff3f04077d1530d1602505cecaae) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/95927 (cherry picked from commit fb81d3f064b24a4fa0585eaac4e5811443a45768)
Diffstat (limited to 'sd/qa')
-rw-r--r--sd/qa/unit/tiledrendering/LOKitSearchTest.cxx93
-rw-r--r--sd/qa/unit/tiledrendering/data/PDFSearch.pdfbin0 -> 14334 bytes
2 files changed, 87 insertions, 6 deletions
diff --git a/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx b/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx
index 4474bd8e4751..33257f12d4ab 100644
--- a/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx
+++ b/sd/qa/unit/tiledrendering/LOKitSearchTest.cxx
@@ -24,10 +24,14 @@
#include <sfx2/viewfrm.hxx>
#include <svl/srchitem.hxx>
#include <svl/stritem.hxx>
+#include <vcl/scheduler.hxx>
#include <ViewShellBase.hxx>
#include <ViewShell.hxx>
#include <unomodel.hxx>
+#include <sdpage.hxx>
+#include <svx/svdograf.hxx>
+
#include <com/sun/star/frame/Desktop.hpp>
using namespace css;
@@ -38,7 +42,7 @@ private:
static constexpr char DATA_DIRECTORY[] = "/sd/qa/unit/tiledrendering/data/";
public:
- LOKitSearchTest() {}
+ LOKitSearchTest() = default;
virtual void setUp() override;
virtual void tearDown() override;
@@ -49,6 +53,8 @@ public:
void testSearchAllNotifications();
void testSearchAllFollowedBySearch();
void testDontSearchInMasterPages();
+ void testSearchInPDFNonExisting();
+ void testSearchInPDF();
CPPUNIT_TEST_SUITE(LOKitSearchTest);
CPPUNIT_TEST(testSearch);
@@ -57,6 +63,8 @@ public:
CPPUNIT_TEST(testSearchAllNotifications);
CPPUNIT_TEST(testSearchAllFollowedBySearch);
CPPUNIT_TEST(testDontSearchInMasterPages);
+ CPPUNIT_TEST(testSearchInPDFNonExisting);
+ CPPUNIT_TEST(testSearchInPDF);
CPPUNIT_TEST_SUITE_END();
private:
@@ -96,9 +104,11 @@ LOKitSearchTest::createDoc(const char* pName, const uno::Sequence<beans::Propert
{
if (mxComponent.is())
mxComponent->dispose();
+
mxComponent = loadFromDesktop(m_directories.getURLFromSrc(DATA_DIRECTORY)
- + OUString::createFromAscii(pName),
- "com.sun.star.presentation.PresentationDocument");
+ + OUString::createFromAscii(pName));
+
+ CPPUNIT_ASSERT(mxComponent.is());
SdXImpressDocument* pImpressDocument = dynamic_cast<SdXImpressDocument*>(mxComponent.get());
CPPUNIT_ASSERT(pImpressDocument);
pImpressDocument->initializeForTiledRendering(rArguments);
@@ -109,15 +119,20 @@ namespace
{
void lcl_search(const OUString& rKey, bool bFindAll = false)
{
+ Scheduler::ProcessEventsToIdle();
+ SvxSearchCmd eSearch = bFindAll ? SvxSearchCmd::FIND_ALL : SvxSearchCmd::FIND;
+
uno::Sequence<beans::PropertyValue> aPropertyValues(comphelper::InitPropertySequence({
{ "SearchItem.SearchString", uno::makeAny(rKey) },
{ "SearchItem.Backward", uno::makeAny(false) },
- { "SearchItem.Command", uno::makeAny(static_cast<sal_uInt16>(
- bFindAll ? SvxSearchCmd::FIND_ALL : SvxSearchCmd::FIND)) },
+ { "SearchItem.Command", uno::makeAny(sal_uInt16(eSearch)) },
}));
+
comphelper::dispatchCommand(".uno:ExecuteSearch", aPropertyValues);
+ Scheduler::ProcessEventsToIdle();
}
-}
+
+} // end anonymous namespace
void LOKitSearchTest::testSearch()
{
@@ -228,6 +243,72 @@ void LOKitSearchTest::testDontSearchInMasterPages()
CPPUNIT_ASSERT_EQUAL(false, mpCallbackRecorder->m_bFound);
}
+void LOKitSearchTest::testSearchInPDFNonExisting()
+{
+ SdXImpressDocument* pXImpressDocument = createDoc("PDFSearch.pdf");
+ sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+ CPPUNIT_ASSERT(pViewShell);
+ mpCallbackRecorder->registerCallbacksFor(pViewShell->GetViewShellBase());
+
+ SdPage* pPage = pViewShell->GetActualPage();
+ CPPUNIT_ASSERT(pPage);
+
+ SdrObject* pObject = pPage->GetObj(0);
+ CPPUNIT_ASSERT(pObject);
+
+ SdrGrafObj* pGraphicObject = dynamic_cast<SdrGrafObj*>(pObject);
+ CPPUNIT_ASSERT(pGraphicObject);
+
+ Graphic aGraphic = pGraphicObject->GetGraphic();
+ auto const& pVectorGraphicData = aGraphic.getVectorGraphicData();
+ CPPUNIT_ASSERT(pVectorGraphicData);
+ CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf,
+ pVectorGraphicData->getVectorGraphicDataType());
+
+ lcl_search("NonExisting");
+
+ CPPUNIT_ASSERT_EQUAL(false, mpCallbackRecorder->m_bFound);
+}
+
+void LOKitSearchTest::testSearchInPDF()
+{
+ SdXImpressDocument* pXImpressDocument = createDoc("PDFSearch.pdf");
+ sd::ViewShell* pViewShell = pXImpressDocument->GetDocShell()->GetViewShell();
+ CPPUNIT_ASSERT(pViewShell);
+ mpCallbackRecorder->registerCallbacksFor(pViewShell->GetViewShellBase());
+
+ SdPage* pPage = pViewShell->GetActualPage();
+ CPPUNIT_ASSERT(pPage);
+
+ SdrObject* pObject = pPage->GetObj(0);
+ CPPUNIT_ASSERT(pObject);
+
+ SdrGrafObj* pGraphicObject = dynamic_cast<SdrGrafObj*>(pObject);
+ CPPUNIT_ASSERT(pGraphicObject);
+
+ Graphic aGraphic = pGraphicObject->GetGraphic();
+ auto const& pVectorGraphicData = aGraphic.getVectorGraphicData();
+ CPPUNIT_ASSERT(pVectorGraphicData);
+ CPPUNIT_ASSERT_EQUAL(VectorGraphicDataType::Pdf,
+ pVectorGraphicData->getVectorGraphicDataType());
+
+ lcl_search("ABC");
+
+ CPPUNIT_ASSERT_EQUAL(true, mpCallbackRecorder->m_bFound);
+
+ CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultSelection.size());
+
+ CPPUNIT_ASSERT_EQUAL(long(3763), mpCallbackRecorder->m_aSelection[0].Left());
+ CPPUNIT_ASSERT_EQUAL(long(1331), mpCallbackRecorder->m_aSelection[0].Top());
+ CPPUNIT_ASSERT_EQUAL(long(1433), mpCallbackRecorder->m_aSelection[0].GetWidth());
+ CPPUNIT_ASSERT_EQUAL(long(484), mpCallbackRecorder->m_aSelection[0].GetHeight());
+
+ lcl_search("ABC");
+ CPPUNIT_ASSERT_EQUAL(true, mpCallbackRecorder->m_bFound);
+
+ CPPUNIT_ASSERT_EQUAL(size_t(1), mpCallbackRecorder->m_aSearchResultSelection.size());
+}
+
CPPUNIT_TEST_SUITE_REGISTRATION(LOKitSearchTest);
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sd/qa/unit/tiledrendering/data/PDFSearch.pdf b/sd/qa/unit/tiledrendering/data/PDFSearch.pdf
new file mode 100644
index 000000000000..ea8a0919a4a1
--- /dev/null
+++ b/sd/qa/unit/tiledrendering/data/PDFSearch.pdf
Binary files differ