From ed5640d8b587fbcfed7dd7967f3de04b37a76f26 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:06:44 +0200 Subject: Adding upstream version 4:7.4.7. Signed-off-by: Daniel Baumann --- sw/qa/extras/indexing/IndexingExportTest.cxx | 321 +++++++++++++++++++++ sw/qa/extras/indexing/SearchResultLocatorTest.cxx | 194 +++++++++++++ .../indexing/data/IndexingExport_Fontwork.odt | Bin 0 -> 12090 bytes .../indexing/data/IndexingExport_Header_Footer.odt | Bin 0 -> 9644 bytes .../extras/indexing/data/IndexingExport_Images.odt | Bin 0 -> 14607 bytes sw/qa/extras/indexing/data/IndexingExport_OLE.odt | Bin 0 -> 14358 bytes .../indexing/data/IndexingExport_Sections.odt | Bin 0 -> 10245 bytes .../extras/indexing/data/IndexingExport_Shapes.odt | Bin 0 -> 11209 bytes .../extras/indexing/data/IndexingExport_Tables.odt | Bin 0 -> 10748 bytes .../data/IndexingExport_VariousParagraphs.odt | Bin 0 -> 11111 bytes 10 files changed, 515 insertions(+) create mode 100644 sw/qa/extras/indexing/IndexingExportTest.cxx create mode 100644 sw/qa/extras/indexing/SearchResultLocatorTest.cxx create mode 100644 sw/qa/extras/indexing/data/IndexingExport_Fontwork.odt create mode 100644 sw/qa/extras/indexing/data/IndexingExport_Header_Footer.odt create mode 100644 sw/qa/extras/indexing/data/IndexingExport_Images.odt create mode 100644 sw/qa/extras/indexing/data/IndexingExport_OLE.odt create mode 100644 sw/qa/extras/indexing/data/IndexingExport_Sections.odt create mode 100644 sw/qa/extras/indexing/data/IndexingExport_Shapes.odt create mode 100644 sw/qa/extras/indexing/data/IndexingExport_Tables.odt create mode 100644 sw/qa/extras/indexing/data/IndexingExport_VariousParagraphs.odt (limited to 'sw/qa/extras/indexing') diff --git a/sw/qa/extras/indexing/IndexingExportTest.cxx b/sw/qa/extras/indexing/IndexingExportTest.cxx new file mode 100644 index 000000000..445e20083 --- /dev/null +++ b/sw/qa/extras/indexing/IndexingExportTest.cxx @@ -0,0 +1,321 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include + +#include + +namespace +{ +constexpr OUStringLiteral DATA_DIRECTORY = u"sw/qa/extras/indexing/data/"; +} + +class IndexingExportTest : public SwModelTestBase +{ +private: + SwDoc* createDoc(const char* pName = nullptr); + +public: + void testIndexingExport_Paragraphs(); + void testIndexingExport_Images(); + void testIndexingExport_OLE(); + void testIndexingExport_Shapes(); + void testIndexingExport_Tables(); + void testIndexingExport_Sections(); + void testIndexingExport_Fontwork(); + void testIndexingExport_Header_Footer(); + + CPPUNIT_TEST_SUITE(IndexingExportTest); + CPPUNIT_TEST(testIndexingExport_Paragraphs); + CPPUNIT_TEST(testIndexingExport_Images); + CPPUNIT_TEST(testIndexingExport_OLE); + CPPUNIT_TEST(testIndexingExport_Shapes); + CPPUNIT_TEST(testIndexingExport_Tables); + CPPUNIT_TEST(testIndexingExport_Sections); + CPPUNIT_TEST(testIndexingExport_Fontwork); + CPPUNIT_TEST(testIndexingExport_Header_Footer); + CPPUNIT_TEST_SUITE_END(); +}; + +SwDoc* IndexingExportTest::createDoc(const char* pName) +{ + if (!pName) + loadURL("private:factory/swriter", nullptr); + else + load(DATA_DIRECTORY, pName); + + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + return pTextDoc->GetDocShell()->GetDoc(); +} + +void IndexingExportTest::testIndexingExport_Paragraphs() +{ + SwDoc* pDoc = createDoc("IndexingExport_VariousParagraphs.odt"); + CPPUNIT_ASSERT(pDoc); + + SvMemoryStream aMemoryStream; + sw::IndexingExport aIndexingExport(aMemoryStream, pDoc); + aIndexingExport.runExport(); + aMemoryStream.Seek(0); + + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/indexing"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Title"); + assertXPath(pXmlDoc, "/indexing/paragraph[1]", "node_type", "writer"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Heading 1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "Heading 2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "Paragraph 1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", "Paragraph 2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", "Bullet 1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", "Bullet 2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[8]", "Bullet 3"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[9]", "Paragraph 3"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[10]", "Paragraph 4"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[11]", "List 1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[12]", "List 2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[13]", "List 3"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[14]", "Left"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[15]", "Center"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[16]", "Right"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[17]", "Bold Italic Underline Strikeout"); + assertXPath(pXmlDoc, "/indexing/paragraph[17]", "node_type", "writer"); +} + +void IndexingExportTest::testIndexingExport_Images() +{ + SwDoc* pDoc = createDoc("IndexingExport_Images.odt"); + CPPUNIT_ASSERT(pDoc); + + SvMemoryStream aMemoryStream; + sw::IndexingExport aIndexingExport(aMemoryStream, pDoc); + aIndexingExport.runExport(); + aMemoryStream.Seek(0); + + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/indexing"); + assertXPath(pXmlDoc, "/indexing/object[1]", "alt", "Image_NonCaption - Alternative text"); + assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Image_NonCaption"); + assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "graphic"); + assertXPath(pXmlDoc, "/indexing/object[2]", "alt", "Image_InCaption - Alternative text"); + assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Image_InCaption"); + assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "graphic"); +} + +void IndexingExportTest::testIndexingExport_OLE() +{ + SwDoc* pDoc = createDoc("IndexingExport_OLE.odt"); + CPPUNIT_ASSERT(pDoc); + + SvMemoryStream aMemoryStream; + sw::IndexingExport aIndexingExport(aMemoryStream, pDoc); + aIndexingExport.runExport(); + aMemoryStream.Seek(0); + + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/indexing"); + assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Object - Chart"); + assertXPath(pXmlDoc, "/indexing/object[1]", "alt", "Alt Text"); + assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "ole"); +} + +void IndexingExportTest::testIndexingExport_Shapes() +{ + SwDoc* pDoc = createDoc("IndexingExport_Shapes.odt"); + CPPUNIT_ASSERT(pDoc); + + SvMemoryStream aMemoryStream; + sw::IndexingExport aIndexingExport(aMemoryStream, pDoc); + aIndexingExport.runExport(); + aMemoryStream.Seek(0); + + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/indexing"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Drawing : Just a Diamond"); + assertXPath(pXmlDoc, "/indexing/paragraph[1]", "node_type", "writer"); + + assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Circle"); + assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "shape"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "This is a circle"); + assertXPath(pXmlDoc, "/indexing/paragraph[2]", "node_type", "common"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "This is a second paragraph"); + assertXPath(pXmlDoc, "/indexing/paragraph[3]", "node_type", "common"); + + assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Diamond"); + assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "shape"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "This is a diamond"); + assertXPath(pXmlDoc, "/indexing/paragraph[4]", "node_type", "common"); + + assertXPath(pXmlDoc, "/indexing/object[3]", "name", "Text Frame 1"); + assertXPath(pXmlDoc, "/indexing/object[3]", "object_type", "shape"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", "This is a TextBox - Para1"); + assertXPath(pXmlDoc, "/indexing/paragraph[5]", "node_type", "common"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", "Para2"); + assertXPath(pXmlDoc, "/indexing/paragraph[6]", "node_type", "common"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", "Para3"); + assertXPath(pXmlDoc, "/indexing/paragraph[7]", "node_type", "common"); +} + +void IndexingExportTest::testIndexingExport_Tables() +{ + SwDoc* pDoc = createDoc("IndexingExport_Tables.odt"); + CPPUNIT_ASSERT(pDoc); + + SvMemoryStream aMemoryStream; + sw::IndexingExport aIndexingExport(aMemoryStream, pDoc); + aIndexingExport.runExport(); + aMemoryStream.Seek(0); + + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/indexing"); + + assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Table1"); + assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "table"); + assertXPath(pXmlDoc, "/indexing/object[1]", "index", "9"); + // Search paragraph with parent_index = 9 + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][1]", "A"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][2]", "B"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][3]", "1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][4]", "2"); + + assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Table2"); + assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "table"); + assertXPath(pXmlDoc, "/indexing/object[2]", "index", "24"); + // Search paragraph with parent_index = 24 + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][1]", "A"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][2]", "B"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][3]", "C"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][4]", "1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][5]", "10"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][6]", "100"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][7]", "2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][8]", "20"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][9]", "200"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][10]", "3"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][11]", "30"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][12]", "300"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][13]", "4"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][14]", "40"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][15]", "400"); + + assertXPath(pXmlDoc, "/indexing/object[3]", "name", "WeirdTable"); + assertXPath(pXmlDoc, "/indexing/object[3]", "object_type", "table"); + assertXPath(pXmlDoc, "/indexing/object[3]", "index", "72"); + // Search paragraph with parent_index = 72 + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][1]", "A1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][2]", "B1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][3]", "C1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][4]", "D1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][5]", "A2B2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][6]", "C2D2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][7]", "A3B3C3D3"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][8]", "A4-1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][9]", "A4-2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][10]", "B4-1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][11]", "C4-1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][12]", "D4-1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][13]", "D4-2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][14]", "B4-2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][15]", "C4-2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][16]", "A5B5C5"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][17]", "D5"); +} + +void IndexingExportTest::testIndexingExport_Sections() +{ + SwDoc* pDoc = createDoc("IndexingExport_Sections.odt"); + CPPUNIT_ASSERT(pDoc); + + SvMemoryStream aMemoryStream; + sw::IndexingExport aIndexingExport(aMemoryStream, pDoc); + aIndexingExport.runExport(); + aMemoryStream.Seek(0); + + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/indexing"); + + assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Section1"); + assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "section"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "This is a paragraph in a Section1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Section1 - Paragraph 2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "Section1 - Paragraph 3"); + + assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "This is a paragraph outside sections"); + + assertXPath(pXmlDoc, "/indexing/object[2]", "name", "Section2"); + assertXPath(pXmlDoc, "/indexing/object[2]", "object_type", "section"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[5]", "Section2 - Paragraph 1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[6]", "Section2 - Paragraph 2"); + + assertXPathContent(pXmlDoc, "/indexing/paragraph[7]", "This is a paragraph outside sections"); +} + +void IndexingExportTest::testIndexingExport_Fontwork() +{ + SwDoc* pDoc = createDoc("IndexingExport_Fontwork.odt"); + CPPUNIT_ASSERT(pDoc); + + SvMemoryStream aMemoryStream; + sw::IndexingExport aIndexingExport(aMemoryStream, pDoc); + aIndexingExport.runExport(); + aMemoryStream.Seek(0); + + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/indexing"); + + assertXPath(pXmlDoc, "/indexing/object[1]", "name", "Gray"); + assertXPath(pXmlDoc, "/indexing/object[1]", "object_type", "shape"); + + assertXPath(pXmlDoc, "/indexing/paragraph[1]", "object_name", "Gray"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Fontwork Text 1"); + assertXPath(pXmlDoc, "/indexing/paragraph[2]", "object_name", "Gray"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Fontwork Text 2"); +} + +void IndexingExportTest::testIndexingExport_Header_Footer() +{ + SwDoc* pDoc = createDoc("IndexingExport_Header_Footer.odt"); + CPPUNIT_ASSERT(pDoc); + + SvMemoryStream aMemoryStream; + sw::IndexingExport aIndexingExport(aMemoryStream, pDoc); + aIndexingExport.runExport(); + aMemoryStream.Seek(0); + + xmlDocUniquePtr pXmlDoc = parseXmlStream(&aMemoryStream); + CPPUNIT_ASSERT(pXmlDoc); + + assertXPath(pXmlDoc, "/indexing"); + + assertXPathContent(pXmlDoc, "/indexing/paragraph[1]", "Header Text"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[2]", "Footer Text"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[3]", "Paragraph 1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[4]", "Paragraph 2"); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(IndexingExportTest); +CPPUNIT_PLUGIN_IMPLEMENT(); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/indexing/SearchResultLocatorTest.cxx b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx new file mode 100644 index 000000000..98d4669da --- /dev/null +++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx @@ -0,0 +1,194 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include +#include +#include + +#include + +namespace +{ +constexpr OUStringLiteral DATA_DIRECTORY = u"sw/qa/extras/indexing/data/"; +} + +class SearchResultLocatorTest : public SwModelTestBase +{ +private: + SwDoc* createDoc(const char* pName = nullptr); + +public: + void testSearchResultLocator(); + void testSearchResultLocatorUsingXmlPayload(); + void testSearchResultLocatorUsingJsonPayload(); + void testSearchResultLocatorForSdrObjects(); + void testSearchResultLocatorForSdrObjectsUsingJsonPayload(); + + CPPUNIT_TEST_SUITE(SearchResultLocatorTest); + CPPUNIT_TEST(testSearchResultLocator); + CPPUNIT_TEST(testSearchResultLocatorUsingXmlPayload); + CPPUNIT_TEST(testSearchResultLocatorUsingJsonPayload); + CPPUNIT_TEST(testSearchResultLocatorForSdrObjects); + CPPUNIT_TEST(testSearchResultLocatorForSdrObjectsUsingJsonPayload); + CPPUNIT_TEST_SUITE_END(); +}; + +SwDoc* SearchResultLocatorTest::createDoc(const char* pName) +{ + if (!pName) + loadURL("private:factory/swriter", nullptr); + else + load(DATA_DIRECTORY, pName); + + SwXTextDocument* pTextDoc = dynamic_cast(mxComponent.get()); + CPPUNIT_ASSERT(pTextDoc); + return pTextDoc->GetDocShell()->GetDoc(); +} + +void SearchResultLocatorTest::testSearchResultLocator() +{ + if (!IsDefaultDPI()) + return; + + SwDoc* pDoc = createDoc("IndexingExport_VariousParagraphs.odt"); + CPPUNIT_ASSERT(pDoc); + + sw::search::SearchResultLocator aLocator(pDoc); + std::vector aDataVector; + aDataVector.emplace_back(sw::search::NodeType::WriterNode, SwNodeOffset(14)); + + sw::search::LocationResult aResult = aLocator.find(aDataVector); + 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(1418.0, aRectangle.getMinX(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle.getMinY(), 1e-4); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(9638.0, aRectangle.getWidth(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(276.0, aRectangle.getHeight(), 1e-4); +#endif +} + +void SearchResultLocatorTest::testSearchResultLocatorUsingXmlPayload() +{ + if (!IsDefaultDPI()) + return; + + SwDoc* pDoc = createDoc("IndexingExport_VariousParagraphs.odt"); + CPPUNIT_ASSERT(pDoc); + + sw::search::SearchResultLocator aLocator(pDoc); + OString payload = "" + "" + ""; + + sw::search::LocationResult aResult = aLocator.findForPayload(payload.getStr()); + 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(1418.0, aRectangle.getMinX(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle.getMinY(), 1e-4); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(9638.0, aRectangle.getWidth(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(276.0, aRectangle.getHeight(), 1e-4); +#endif +} + +void SearchResultLocatorTest::testSearchResultLocatorUsingJsonPayload() +{ + if (!IsDefaultDPI()) + return; + + SwDoc* pDoc = createDoc("IndexingExport_VariousParagraphs.odt"); + CPPUNIT_ASSERT(pDoc); + + sw::search::SearchResultLocator aLocator(pDoc); + OString payload = "[" + "{ \"node_type\" : \"writer\", \"index\" : 14 }" + "]"; + + sw::search::LocationResult aResult = aLocator.findForPayload(payload.getStr()); + 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(1418.0, aRectangle.getMinX(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle.getMinY(), 1e-4); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(9638.0, aRectangle.getWidth(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(276.0, aRectangle.getHeight(), 1e-4); +#endif +} + +void SearchResultLocatorTest::testSearchResultLocatorForSdrObjects() +{ + if (!IsDefaultDPI()) + return; + + SwDoc* pDoc = createDoc("IndexingExport_Shapes.odt"); + CPPUNIT_ASSERT(pDoc); + + sw::search::SearchResultLocator aLocator(pDoc); + std::vector aDataVector; + aDataVector.emplace_back(sw::search::NodeType::CommonNode, SwNodeOffset(1), u"Circle"); + + sw::search::LocationResult aResult = aLocator.find(aDataVector); + 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(2607.0, aRectangle.getMinX(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(5685.0, aRectangle.getMinY(), 1e-4); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle.getWidth(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle.getHeight(), 1e-4); +#endif +} + +void SearchResultLocatorTest::testSearchResultLocatorForSdrObjectsUsingJsonPayload() +{ + if (!IsDefaultDPI()) + return; + + SwDoc* pDoc = createDoc("IndexingExport_Shapes.odt"); + CPPUNIT_ASSERT(pDoc); + + sw::search::SearchResultLocator aLocator(pDoc); + OString payload = "[" + "{ \"node_type\" : \"common\", \"index\" : 1, \"object_name\" : \"Circle\" }" + "]"; + + sw::search::LocationResult aResult = aLocator.findForPayload(payload.getStr()); + 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(2607.0, aRectangle.getMinX(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(5685.0, aRectangle.getMinY(), 1e-4); + + CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle.getWidth(), 1e-4); + CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle.getHeight(), 1e-4); +#endif +} + +CPPUNIT_TEST_SUITE_REGISTRATION(SearchResultLocatorTest); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/extras/indexing/data/IndexingExport_Fontwork.odt b/sw/qa/extras/indexing/data/IndexingExport_Fontwork.odt new file mode 100644 index 000000000..df1a7aef5 Binary files /dev/null and b/sw/qa/extras/indexing/data/IndexingExport_Fontwork.odt differ diff --git a/sw/qa/extras/indexing/data/IndexingExport_Header_Footer.odt b/sw/qa/extras/indexing/data/IndexingExport_Header_Footer.odt new file mode 100644 index 000000000..744e6ade4 Binary files /dev/null and b/sw/qa/extras/indexing/data/IndexingExport_Header_Footer.odt differ diff --git a/sw/qa/extras/indexing/data/IndexingExport_Images.odt b/sw/qa/extras/indexing/data/IndexingExport_Images.odt new file mode 100644 index 000000000..3bf4120e2 Binary files /dev/null and b/sw/qa/extras/indexing/data/IndexingExport_Images.odt differ diff --git a/sw/qa/extras/indexing/data/IndexingExport_OLE.odt b/sw/qa/extras/indexing/data/IndexingExport_OLE.odt new file mode 100644 index 000000000..3da225368 Binary files /dev/null and b/sw/qa/extras/indexing/data/IndexingExport_OLE.odt differ diff --git a/sw/qa/extras/indexing/data/IndexingExport_Sections.odt b/sw/qa/extras/indexing/data/IndexingExport_Sections.odt new file mode 100644 index 000000000..ef92c83ef Binary files /dev/null and b/sw/qa/extras/indexing/data/IndexingExport_Sections.odt differ diff --git a/sw/qa/extras/indexing/data/IndexingExport_Shapes.odt b/sw/qa/extras/indexing/data/IndexingExport_Shapes.odt new file mode 100644 index 000000000..8d37145ea Binary files /dev/null and b/sw/qa/extras/indexing/data/IndexingExport_Shapes.odt differ diff --git a/sw/qa/extras/indexing/data/IndexingExport_Tables.odt b/sw/qa/extras/indexing/data/IndexingExport_Tables.odt new file mode 100644 index 000000000..a15acc7de Binary files /dev/null and b/sw/qa/extras/indexing/data/IndexingExport_Tables.odt differ diff --git a/sw/qa/extras/indexing/data/IndexingExport_VariousParagraphs.odt b/sw/qa/extras/indexing/data/IndexingExport_VariousParagraphs.odt new file mode 100644 index 000000000..eb8904720 Binary files /dev/null and b/sw/qa/extras/indexing/data/IndexingExport_VariousParagraphs.odt differ -- cgit v1.2.3