From ea1818b8ba34378b777b8706069d28fade2cc924 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 9 Jul 2021 19:36:58 +0900 Subject: indexing: add support for SdrObjects in SearchResultLocator MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also add (node) "type" parameter because we need to differentiate between Writer nodes and SdrObject nodes. Change-Id: I590695ae71781f64c22bdd7e1df01d69e3376e67 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118671 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- sw/qa/extras/indexing/SearchResultLocatorTest.cxx | 50 ++++++++++++++++++----- 1 file changed, 39 insertions(+), 11 deletions(-) (limited to 'sw/qa/extras/indexing') diff --git a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx index 9b8474911fbd..99f33422a065 100644 --- a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx +++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx @@ -17,27 +17,24 @@ namespace { -#if !defined MACOSX constexpr OUStringLiteral DATA_DIRECTORY = u"sw/qa/extras/indexing/data/"; -#endif } class SearchResultLocatorTest : public SwModelTestBase { private: -#if !defined MACOSX SwDoc* createDoc(const char* pName = nullptr); -#endif public: void testSearchResultLocator(); + void testSearchResultLocatorForSdrObjects(); CPPUNIT_TEST_SUITE(SearchResultLocatorTest); CPPUNIT_TEST(testSearchResultLocator); + CPPUNIT_TEST(testSearchResultLocatorForSdrObjects); CPPUNIT_TEST_SUITE_END(); }; -#if !defined MACOSX SwDoc* SearchResultLocatorTest::createDoc(const char* pName) { if (!pName) @@ -49,25 +46,27 @@ SwDoc* SearchResultLocatorTest::createDoc(const char* pName) CPPUNIT_ASSERT(pTextDoc); return pTextDoc->GetDocShell()->GetDoc(); } -#endif void SearchResultLocatorTest::testSearchResultLocator() { -#if !defined(_WIN32) && !defined(MACOSX) if (!IsDefaultDPI()) return; SwDoc* pDoc = createDoc("IndexingExport_VariousParagraphs.odt"); CPPUNIT_ASSERT(pDoc); - sw::SearchResultLocator aLocator(pDoc); - sw::SearchIndexData aData; + sw::search::SearchResultLocator aLocator(pDoc); + sw::search::SearchIndexData aData; + aData.eType = sw::search::NodeType::WriterNode; aData.nNodeIndex = 14; - sw::LocationResult aResult = aLocator.find(aData); + sw::search::LocationResult aResult = aLocator.find(aData); CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size()); - auto aRectangle = aResult.maRectangles[0]; + // skip asserting exact values for macOS and Windows because of + // inconsistent results +#if !defined(_WIN32) && !defined(MACOSX) + auto aRectangle = aResult.maRectangles[0]; CPPUNIT_ASSERT_DOUBLES_EQUAL(1418.0, aRectangle.getMinX(), 1e-4); CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle.getMinY(), 1e-4); @@ -76,6 +75,35 @@ void SearchResultLocatorTest::testSearchResultLocator() #endif } +void SearchResultLocatorTest::testSearchResultLocatorForSdrObjects() +{ + if (!IsDefaultDPI()) + return; + + SwDoc* pDoc = createDoc("IndexingExport_Shapes.odt"); + CPPUNIT_ASSERT(pDoc); + + sw::search::SearchResultLocator aLocator(pDoc); + sw::search::SearchIndexData aData; + aData.eType = sw::search::NodeType::SdrObject; + aData.aObjectName = u"Circle"; + aData.nNodeIndex = 1; + + sw::search::LocationResult aResult = aLocator.find(aData); + CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size()); + + // skip asserting exact values for macOS and Windows because of + // inconsistent results +#if !defined(_WIN32) && !defined(MACOSX) + auto aRectangle = aResult.maRectangles[0]; + CPPUNIT_ASSERT_DOUBLES_EQUAL(1478.0, aRectangle.getMinX(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3223.0, aRectangle.getMinY(), 1e-4); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(2059.0, aRectangle.getWidth(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(2059.0, aRectangle.getHeight(), 1e-4); +#endif +} + CPPUNIT_TEST_SUITE_REGISTRATION(SearchResultLocatorTest); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit