Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / qa / extras / indexing / SearchResultLocatorTest.cxx
blobb953ea3e100a4c2828e859cac4003beaa529cb7c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 */
10 #include <swmodeltestbase.hxx>
11 #include <docsh.hxx>
12 #include <unotxdoc.hxx>
14 #include <SearchResultLocator.hxx>
16 class SearchResultLocatorTest : public SwModelTestBase
18 public:
19 SearchResultLocatorTest()
20 : SwModelTestBase("/sw/qa/extras/indexing/data/")
24 void testSearchResultLocator();
25 void testSearchResultLocatorUsingXmlPayload();
26 void testSearchResultLocatorUsingJsonPayload();
27 void testSearchResultLocatorForSdrObjects();
28 void testSearchResultLocatorForSdrObjectsUsingJsonPayload();
30 CPPUNIT_TEST_SUITE(SearchResultLocatorTest);
31 CPPUNIT_TEST(testSearchResultLocator);
32 CPPUNIT_TEST(testSearchResultLocatorUsingXmlPayload);
33 CPPUNIT_TEST(testSearchResultLocatorUsingJsonPayload);
34 CPPUNIT_TEST(testSearchResultLocatorForSdrObjects);
35 CPPUNIT_TEST(testSearchResultLocatorForSdrObjectsUsingJsonPayload);
36 CPPUNIT_TEST_SUITE_END();
39 void SearchResultLocatorTest::testSearchResultLocator()
41 if (!IsDefaultDPI())
42 return;
44 createSwDoc("IndexingExport_VariousParagraphs.odt");
45 SwDoc* pDoc = getSwDoc();
46 CPPUNIT_ASSERT(pDoc);
48 sw::search::SearchResultLocator aLocator(pDoc);
49 std::vector<sw::search::SearchIndexData> aDataVector;
50 aDataVector.emplace_back(sw::search::NodeType::WriterNode, SwNodeOffset(14));
52 sw::search::LocationResult aResult = aLocator.find(aDataVector);
53 CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size());
55 // skip asserting exact values for macOS and Windows because of
56 // inconsistent results
57 #if !defined(_WIN32) && !defined(MACOSX)
58 auto aRectangle = aResult.maRectangles[0];
59 CPPUNIT_ASSERT_DOUBLES_EQUAL(1418.0, aRectangle.getMinX(), 1e-4);
60 CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle.getMinY(), 1e-4);
62 CPPUNIT_ASSERT_DOUBLES_EQUAL(9638.0, aRectangle.getWidth(), 1e-4);
63 CPPUNIT_ASSERT_DOUBLES_EQUAL(276.0, aRectangle.getHeight(), 1e-4);
64 #endif
67 void SearchResultLocatorTest::testSearchResultLocatorUsingXmlPayload()
69 if (!IsDefaultDPI())
70 return;
72 createSwDoc("IndexingExport_VariousParagraphs.odt");
73 SwDoc* pDoc = getSwDoc();
74 CPPUNIT_ASSERT(pDoc);
76 sw::search::SearchResultLocator aLocator(pDoc);
77 OString payload = "<indexing>"
78 "<paragraph node_type=\"writer\" index=\"14\" />"
79 "</indexing>";
81 sw::search::LocationResult aResult = aLocator.findForPayload(payload.getStr());
82 CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size());
84 // skip asserting exact values for macOS and Windows because of
85 // inconsistent results
86 #if !defined(_WIN32) && !defined(MACOSX)
87 auto aRectangle = aResult.maRectangles[0];
88 CPPUNIT_ASSERT_DOUBLES_EQUAL(1418.0, aRectangle.getMinX(), 1e-4);
89 CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle.getMinY(), 1e-4);
91 CPPUNIT_ASSERT_DOUBLES_EQUAL(9638.0, aRectangle.getWidth(), 1e-4);
92 CPPUNIT_ASSERT_DOUBLES_EQUAL(276.0, aRectangle.getHeight(), 1e-4);
93 #endif
96 void SearchResultLocatorTest::testSearchResultLocatorUsingJsonPayload()
98 if (!IsDefaultDPI())
99 return;
101 createSwDoc("IndexingExport_VariousParagraphs.odt");
102 SwDoc* pDoc = getSwDoc();
103 CPPUNIT_ASSERT(pDoc);
105 sw::search::SearchResultLocator aLocator(pDoc);
106 OString payload = "["
107 "{ \"node_type\" : \"writer\", \"index\" : 14 }"
108 "]";
110 sw::search::LocationResult aResult = aLocator.findForPayload(payload.getStr());
111 CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size());
113 // skip asserting exact values for macOS and Windows because of
114 // inconsistent results
115 #if !defined(_WIN32) && !defined(MACOSX)
116 auto aRectangle = aResult.maRectangles[0];
117 CPPUNIT_ASSERT_DOUBLES_EQUAL(1418.0, aRectangle.getMinX(), 1e-4);
118 CPPUNIT_ASSERT_DOUBLES_EQUAL(4444.0, aRectangle.getMinY(), 1e-4);
120 CPPUNIT_ASSERT_DOUBLES_EQUAL(9638.0, aRectangle.getWidth(), 1e-4);
121 CPPUNIT_ASSERT_DOUBLES_EQUAL(276.0, aRectangle.getHeight(), 1e-4);
122 #endif
125 void SearchResultLocatorTest::testSearchResultLocatorForSdrObjects()
127 if (!IsDefaultDPI())
128 return;
130 createSwDoc("IndexingExport_Shapes.odt");
131 SwDoc* pDoc = getSwDoc();
132 CPPUNIT_ASSERT(pDoc);
134 sw::search::SearchResultLocator aLocator(pDoc);
135 std::vector<sw::search::SearchIndexData> aDataVector;
136 aDataVector.emplace_back(sw::search::NodeType::CommonNode, SwNodeOffset(1), u"Circle");
138 sw::search::LocationResult aResult = aLocator.find(aDataVector);
139 CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size());
141 // skip asserting exact values for macOS and Windows because of
142 // inconsistent results
143 #if !defined(_WIN32) && !defined(MACOSX)
144 auto aRectangle = aResult.maRectangles[0];
145 CPPUNIT_ASSERT_DOUBLES_EQUAL(2607.0, aRectangle.getMinX(), 1e-4);
146 CPPUNIT_ASSERT_DOUBLES_EQUAL(5685.0, aRectangle.getMinY(), 1e-4);
148 CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle.getWidth(), 1e-4);
149 CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle.getHeight(), 1e-4);
150 #endif
153 void SearchResultLocatorTest::testSearchResultLocatorForSdrObjectsUsingJsonPayload()
155 if (!IsDefaultDPI())
156 return;
158 createSwDoc("IndexingExport_Shapes.odt");
159 SwDoc* pDoc = getSwDoc();
160 CPPUNIT_ASSERT(pDoc);
162 sw::search::SearchResultLocator aLocator(pDoc);
163 OString payload = "["
164 "{ \"node_type\" : \"common\", \"index\" : 1, \"object_name\" : \"Circle\" }"
165 "]";
167 sw::search::LocationResult aResult = aLocator.findForPayload(payload.getStr());
168 CPPUNIT_ASSERT_EQUAL(size_t(1), aResult.maRectangles.size());
170 // skip asserting exact values for macOS and Windows because of
171 // inconsistent results
172 #if !defined(_WIN32) && !defined(MACOSX)
173 auto aRectangle = aResult.maRectangles[0];
174 CPPUNIT_ASSERT_DOUBLES_EQUAL(2607.0, aRectangle.getMinX(), 1e-4);
175 CPPUNIT_ASSERT_DOUBLES_EQUAL(5685.0, aRectangle.getMinY(), 1e-4);
177 CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle.getWidth(), 1e-4);
178 CPPUNIT_ASSERT_DOUBLES_EQUAL(3631.0, aRectangle.getHeight(), 1e-4);
179 #endif
182 CPPUNIT_TEST_SUITE_REGISTRATION(SearchResultLocatorTest);
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */