diff options
Diffstat (limited to 'sw/qa/extras/indexing')
-rw-r--r-- | sw/qa/extras/indexing/IndexingExportTest.cxx | 318 | ||||
-rw-r--r-- | sw/qa/extras/indexing/SearchResultLocatorTest.cxx | 184 | ||||
-rw-r--r-- | sw/qa/extras/indexing/data/IndexingExport_Fontwork.odt | bin | 0 -> 12090 bytes | |||
-rw-r--r-- | sw/qa/extras/indexing/data/IndexingExport_Header_Footer.odt | bin | 0 -> 9644 bytes | |||
-rw-r--r-- | sw/qa/extras/indexing/data/IndexingExport_Images.odt | bin | 0 -> 14607 bytes | |||
-rw-r--r-- | sw/qa/extras/indexing/data/IndexingExport_OLE.odt | bin | 0 -> 14358 bytes | |||
-rw-r--r-- | sw/qa/extras/indexing/data/IndexingExport_Sections.odt | bin | 0 -> 10245 bytes | |||
-rw-r--r-- | sw/qa/extras/indexing/data/IndexingExport_Shapes.odt | bin | 0 -> 11209 bytes | |||
-rw-r--r-- | sw/qa/extras/indexing/data/IndexingExport_Tables.odt | bin | 0 -> 10748 bytes | |||
-rw-r--r-- | sw/qa/extras/indexing/data/IndexingExport_VariousParagraphs.odt | bin | 0 -> 11111 bytes |
10 files changed, 502 insertions, 0 deletions
diff --git a/sw/qa/extras/indexing/IndexingExportTest.cxx b/sw/qa/extras/indexing/IndexingExportTest.cxx new file mode 100644 index 0000000000..ac32db4fb8 --- /dev/null +++ b/sw/qa/extras/indexing/IndexingExportTest.cxx @@ -0,0 +1,318 @@ +/* -*- 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 <swmodeltestbase.hxx> +#include <docsh.hxx> +#include <unotxdoc.hxx> + +#include <IndexingExport.hxx> + +class IndexingExportTest : public SwModelTestBase +{ +public: + IndexingExportTest() + : SwModelTestBase("/sw/qa/extras/indexing/data/") + { + } + + 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(); +}; + +void IndexingExportTest::testIndexingExport_Paragraphs() +{ + createSwDoc("IndexingExport_VariousParagraphs.odt"); + SwDoc* pDoc = getSwDoc(); + 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"_ostr); + assertXPathContent(pXmlDoc, "/indexing/paragraph[1]"_ostr, "Title"); + assertXPath(pXmlDoc, "/indexing/paragraph[1]"_ostr, "node_type"_ostr, "writer"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[2]"_ostr, "Heading 1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[3]"_ostr, "Heading 2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[4]"_ostr, "Paragraph 1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[5]"_ostr, "Paragraph 2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[6]"_ostr, "Bullet 1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[7]"_ostr, "Bullet 2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[8]"_ostr, "Bullet 3"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[9]"_ostr, "Paragraph 3"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[10]"_ostr, "Paragraph 4"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[11]"_ostr, "List 1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[12]"_ostr, "List 2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[13]"_ostr, "List 3"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[14]"_ostr, "Left"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[15]"_ostr, "Center"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[16]"_ostr, "Right"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[17]"_ostr, "Bold Italic Underline Strikeout"); + assertXPath(pXmlDoc, "/indexing/paragraph[17]"_ostr, "node_type"_ostr, "writer"); +} + +void IndexingExportTest::testIndexingExport_Images() +{ + createSwDoc("IndexingExport_Images.odt"); + SwDoc* pDoc = getSwDoc(); + 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"_ostr); + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "alt"_ostr, + "Image_NonCaption - Alternative text"); + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "name"_ostr, "Image_NonCaption"); + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "object_type"_ostr, "graphic"); + assertXPath(pXmlDoc, "/indexing/object[2]"_ostr, "alt"_ostr, + "Image_InCaption - Alternative text"); + assertXPath(pXmlDoc, "/indexing/object[2]"_ostr, "name"_ostr, "Image_InCaption"); + assertXPath(pXmlDoc, "/indexing/object[2]"_ostr, "object_type"_ostr, "graphic"); +} + +void IndexingExportTest::testIndexingExport_OLE() +{ + createSwDoc("IndexingExport_OLE.odt"); + SwDoc* pDoc = getSwDoc(); + 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"_ostr); + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "name"_ostr, "Object - Chart"); + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "alt"_ostr, "Alt Text"); + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "object_type"_ostr, "ole"); +} + +void IndexingExportTest::testIndexingExport_Shapes() +{ + createSwDoc("IndexingExport_Shapes.odt"); + SwDoc* pDoc = getSwDoc(); + 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"_ostr); + assertXPathContent(pXmlDoc, "/indexing/paragraph[1]"_ostr, "Drawing : Just a Diamond"); + assertXPath(pXmlDoc, "/indexing/paragraph[1]"_ostr, "node_type"_ostr, "writer"); + + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "name"_ostr, "Circle"); + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "object_type"_ostr, "shape"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[2]"_ostr, "This is a circle"); + assertXPath(pXmlDoc, "/indexing/paragraph[2]"_ostr, "node_type"_ostr, "common"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[3]"_ostr, "This is a second paragraph"); + assertXPath(pXmlDoc, "/indexing/paragraph[3]"_ostr, "node_type"_ostr, "common"); + + assertXPath(pXmlDoc, "/indexing/object[2]"_ostr, "name"_ostr, "Diamond"); + assertXPath(pXmlDoc, "/indexing/object[2]"_ostr, "object_type"_ostr, "shape"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[4]"_ostr, "This is a diamond"); + assertXPath(pXmlDoc, "/indexing/paragraph[4]"_ostr, "node_type"_ostr, "common"); + + assertXPath(pXmlDoc, "/indexing/object[3]"_ostr, "name"_ostr, "Text Frame 1"); + assertXPath(pXmlDoc, "/indexing/object[3]"_ostr, "object_type"_ostr, "shape"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[5]"_ostr, "This is a TextBox - Para1"); + assertXPath(pXmlDoc, "/indexing/paragraph[5]"_ostr, "node_type"_ostr, "common"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[6]"_ostr, "Para2"); + assertXPath(pXmlDoc, "/indexing/paragraph[6]"_ostr, "node_type"_ostr, "common"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[7]"_ostr, "Para3"); + assertXPath(pXmlDoc, "/indexing/paragraph[7]"_ostr, "node_type"_ostr, "common"); +} + +void IndexingExportTest::testIndexingExport_Tables() +{ + createSwDoc("IndexingExport_Tables.odt"); + SwDoc* pDoc = getSwDoc(); + 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"_ostr); + + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "name"_ostr, "Table1"); + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "object_type"_ostr, "table"); + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "index"_ostr, "9"); + // Search paragraph with parent_index = 9 + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][1]"_ostr, "A"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][2]"_ostr, "B"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][3]"_ostr, "1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=9][4]"_ostr, "2"); + + assertXPath(pXmlDoc, "/indexing/object[2]"_ostr, "name"_ostr, "Table2"); + assertXPath(pXmlDoc, "/indexing/object[2]"_ostr, "object_type"_ostr, "table"); + assertXPath(pXmlDoc, "/indexing/object[2]"_ostr, "index"_ostr, "24"); + // Search paragraph with parent_index = 24 + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][1]"_ostr, "A"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][2]"_ostr, "B"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][3]"_ostr, "C"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][4]"_ostr, "1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][5]"_ostr, "10"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][6]"_ostr, "100"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][7]"_ostr, "2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][8]"_ostr, "20"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][9]"_ostr, "200"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][10]"_ostr, "3"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][11]"_ostr, "30"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][12]"_ostr, "300"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][13]"_ostr, "4"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][14]"_ostr, "40"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=24][15]"_ostr, "400"); + + assertXPath(pXmlDoc, "/indexing/object[3]"_ostr, "name"_ostr, "WeirdTable"); + assertXPath(pXmlDoc, "/indexing/object[3]"_ostr, "object_type"_ostr, "table"); + assertXPath(pXmlDoc, "/indexing/object[3]"_ostr, "index"_ostr, "72"); + // Search paragraph with parent_index = 72 + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][1]"_ostr, "A1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][2]"_ostr, "B1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][3]"_ostr, "C1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][4]"_ostr, "D1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][5]"_ostr, "A2B2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][6]"_ostr, "C2D2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][7]"_ostr, "A3B3C3D3"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][8]"_ostr, "A4-1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][9]"_ostr, "A4-2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][10]"_ostr, "B4-1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][11]"_ostr, "C4-1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][12]"_ostr, "D4-1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][13]"_ostr, "D4-2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][14]"_ostr, "B4-2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][15]"_ostr, "C4-2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][16]"_ostr, "A5B5C5"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[@parent_index=72][17]"_ostr, "D5"); +} + +void IndexingExportTest::testIndexingExport_Sections() +{ + createSwDoc("IndexingExport_Sections.odt"); + SwDoc* pDoc = getSwDoc(); + 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"_ostr); + + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "name"_ostr, "Section1"); + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "object_type"_ostr, "section"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[1]"_ostr, "This is a paragraph in a Section1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[2]"_ostr, "Section1 - Paragraph 2"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[3]"_ostr, "Section1 - Paragraph 3"); + + assertXPathContent(pXmlDoc, "/indexing/paragraph[4]"_ostr, + "This is a paragraph outside sections"); + + assertXPath(pXmlDoc, "/indexing/object[2]"_ostr, "name"_ostr, "Section2"); + assertXPath(pXmlDoc, "/indexing/object[2]"_ostr, "object_type"_ostr, "section"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[5]"_ostr, "Section2 - Paragraph 1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[6]"_ostr, "Section2 - Paragraph 2"); + + assertXPathContent(pXmlDoc, "/indexing/paragraph[7]"_ostr, + "This is a paragraph outside sections"); +} + +void IndexingExportTest::testIndexingExport_Fontwork() +{ + createSwDoc("IndexingExport_Fontwork.odt"); + SwDoc* pDoc = getSwDoc(); + 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"_ostr); + + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "name"_ostr, "Gray"); + assertXPath(pXmlDoc, "/indexing/object[1]"_ostr, "object_type"_ostr, "shape"); + + assertXPath(pXmlDoc, "/indexing/paragraph[1]"_ostr, "object_name"_ostr, "Gray"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[1]"_ostr, "Fontwork Text 1"); + assertXPath(pXmlDoc, "/indexing/paragraph[2]"_ostr, "object_name"_ostr, "Gray"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[2]"_ostr, "Fontwork Text 2"); +} + +void IndexingExportTest::testIndexingExport_Header_Footer() +{ + createSwDoc("IndexingExport_Header_Footer.odt"); + SwDoc* pDoc = getSwDoc(); + 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"_ostr); + + assertXPathContent(pXmlDoc, "/indexing/paragraph[1]"_ostr, "Header Text"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[2]"_ostr, "Footer Text"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[3]"_ostr, "Paragraph 1"); + assertXPathContent(pXmlDoc, "/indexing/paragraph[4]"_ostr, "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 0000000000..3772456c1d --- /dev/null +++ b/sw/qa/extras/indexing/SearchResultLocatorTest.cxx @@ -0,0 +1,184 @@ +/* -*- 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 <swmodeltestbase.hxx> +#include <docsh.hxx> +#include <unotxdoc.hxx> + +#include <SearchResultLocator.hxx> + +class SearchResultLocatorTest : public SwModelTestBase +{ +public: + SearchResultLocatorTest() + : SwModelTestBase("/sw/qa/extras/indexing/data/") + { + } + + 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(); +}; + +void SearchResultLocatorTest::testSearchResultLocator() +{ + if (!IsDefaultDPI()) + return; + + createSwDoc("IndexingExport_VariousParagraphs.odt"); + SwDoc* pDoc = getSwDoc(); + CPPUNIT_ASSERT(pDoc); + + sw::search::SearchResultLocator aLocator(pDoc); + std::vector<sw::search::SearchIndexData> 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; + + createSwDoc("IndexingExport_VariousParagraphs.odt"); + SwDoc* pDoc = getSwDoc(); + CPPUNIT_ASSERT(pDoc); + + sw::search::SearchResultLocator aLocator(pDoc); + OString payload = "<indexing>" + "<paragraph node_type=\"writer\" index=\"14\" />" + "</indexing>"_ostr; + + 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; + + createSwDoc("IndexingExport_VariousParagraphs.odt"); + SwDoc* pDoc = getSwDoc(); + CPPUNIT_ASSERT(pDoc); + + sw::search::SearchResultLocator aLocator(pDoc); + OString payload = "[" + "{ \"node_type\" : \"writer\", \"index\" : 14 }" + "]"_ostr; + + 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; + + createSwDoc("IndexingExport_Shapes.odt"); + SwDoc* pDoc = getSwDoc(); + CPPUNIT_ASSERT(pDoc); + + sw::search::SearchResultLocator aLocator(pDoc); + std::vector<sw::search::SearchIndexData> aDataVector; + aDataVector.emplace_back(sw::search::NodeType::CommonNode, SwNodeOffset(1), u"Circle"_ustr); + + 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; + + createSwDoc("IndexingExport_Shapes.odt"); + SwDoc* pDoc = getSwDoc(); + CPPUNIT_ASSERT(pDoc); + + sw::search::SearchResultLocator aLocator(pDoc); + OString payload = "[" + "{ \"node_type\" : \"common\", \"index\" : 1, \"object_name\" : \"Circle\" }" + "]"_ostr; + + 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 Binary files differnew file mode 100644 index 0000000000..df1a7aef5d --- /dev/null +++ b/sw/qa/extras/indexing/data/IndexingExport_Fontwork.odt diff --git a/sw/qa/extras/indexing/data/IndexingExport_Header_Footer.odt b/sw/qa/extras/indexing/data/IndexingExport_Header_Footer.odt Binary files differnew file mode 100644 index 0000000000..744e6ade45 --- /dev/null +++ b/sw/qa/extras/indexing/data/IndexingExport_Header_Footer.odt diff --git a/sw/qa/extras/indexing/data/IndexingExport_Images.odt b/sw/qa/extras/indexing/data/IndexingExport_Images.odt Binary files differnew file mode 100644 index 0000000000..3bf4120e27 --- /dev/null +++ b/sw/qa/extras/indexing/data/IndexingExport_Images.odt diff --git a/sw/qa/extras/indexing/data/IndexingExport_OLE.odt b/sw/qa/extras/indexing/data/IndexingExport_OLE.odt Binary files differnew file mode 100644 index 0000000000..3da225368b --- /dev/null +++ b/sw/qa/extras/indexing/data/IndexingExport_OLE.odt diff --git a/sw/qa/extras/indexing/data/IndexingExport_Sections.odt b/sw/qa/extras/indexing/data/IndexingExport_Sections.odt Binary files differnew file mode 100644 index 0000000000..ef92c83efd --- /dev/null +++ b/sw/qa/extras/indexing/data/IndexingExport_Sections.odt diff --git a/sw/qa/extras/indexing/data/IndexingExport_Shapes.odt b/sw/qa/extras/indexing/data/IndexingExport_Shapes.odt Binary files differnew file mode 100644 index 0000000000..8d37145ea3 --- /dev/null +++ b/sw/qa/extras/indexing/data/IndexingExport_Shapes.odt diff --git a/sw/qa/extras/indexing/data/IndexingExport_Tables.odt b/sw/qa/extras/indexing/data/IndexingExport_Tables.odt Binary files differnew file mode 100644 index 0000000000..a15acc7de3 --- /dev/null +++ b/sw/qa/extras/indexing/data/IndexingExport_Tables.odt diff --git a/sw/qa/extras/indexing/data/IndexingExport_VariousParagraphs.odt b/sw/qa/extras/indexing/data/IndexingExport_VariousParagraphs.odt Binary files differnew file mode 100644 index 0000000000..eb8904720f --- /dev/null +++ b/sw/qa/extras/indexing/data/IndexingExport_VariousParagraphs.odt |